centos6.5 下安装jdk7,tomcat7

拥有回忆 提交于 2019-11-30 21:33:22

jdk下载链接:

wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/7u80-b15/jdk-7u80-linux-x64.rpm

tomcat下载链接:

wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" http://mirrors.hust.edu.cn/apache/tomcat/tomcat-7/v7.0.65/bin/apache-tomcat-7.0.65.tar.gz


或者:

wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie"  http://apache.fayea.com/tomcat/tomcat-7/v7.0.65/bin/apache-tomcat-7.0.65.tar.gz


  1. 安装JDK, 注意操作系统的位数, 64 or 32:

# mkdir /usr/java  
# cd /usr/java
#rpm -Uvh /bak/jdk-7u80-linux-x64.rpm 

# vi /etc/profile
JAVA_HOME=/usr/java/jdk1.7.0_80
export JAVA_HOME
CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export CLASSPATH
PATH=$JAVA_HOME/bin:$PATH 
export PATH

# source /etc/profile
 
#  echo $JAVA_HOME
/usr/java/jdk1.7.0_80

2. 建组建用户,查看,设置密码

# groupadd webserver
# useradd -m -g webserver -G webserver webapp
# id webapp
# passwd webapp
# vi /etc/sudoers

找到此行,

root ALL=(ALL) ALL

添加:

webapp        ALL=(ALL)        ALL

3. 建目录,变更权限,安装tomcat7

# mkdir /usr/local/tomcat
# chown -R webapp:webserver /usr/local/tomcat
# su webapp

4. 使用webapp权限将apache-tomcat-7.0.65.tar.gz放到/usr/local/tomcat

$ cd /usr/local/tomcat
$ tar -zxvf apache-tomcat-7.0.65.tar.gz
$ vi ~/.bash_profile
CATALINA_BASE=/usr/local/tomcat/apache-tomcat-7.0.65
CATALINA_HOME=/usr/local/tomcat/apache-tomcat-7.0.65
PATH=$PATH:$HOME/bin:$CATALINA_HOME/bin
export PATH
$source ~/.bash_profile

5. 修改tomcat配置文件tomcat-users.xml,补充如下内容:

<role rolename="manager-gui"/>
  <role rolename="admin-gui"/>
  <user username="webapp" password="password" roles="manager-gui,admin-gui"/>


6. 设置tomcat启动服务:

# cd /etc/init.d
# vi tomcat

脚本内容如下:

#!/bin/bash
# chkconfig: 2345 10 90
# description: Starts and Stops the Tomcat daemon.

CATALINA_HOME=/usr/local/tomcat/apache-tomcat-7.0.65
JAVA_HOME=/usr/java/jdk1.7.0_80
TOMCAT_START=$CATALINA_HOME/bin/startup.sh 
TOMCAT_STOP=$CATALINA_HOME/bin/shutdown.sh 

# source function library. 
. /etc/rc.d/init.d/functions 
# check that networking is up. 
[ "${NETWORKING}" = "no" ] && exit 0 
# check for tomcat script 
if [ ! -f $CATALINA_HOME/bin/catalina.sh ]; then
         echo "Tomcat not valilable..." 
        exit 
fi 
start(){ 
        echo -n "Starting Tomcat: " 
        daemon $TOMCAT_START 
        echo 
        touch /var/lock/subsys/tomcat 
} 
stop(){ 
        ps ax --width=1000 | grep "[o]rg.apache.catalina.startup.Bootstrap start" | awk '{printf $1 " "}' \
 | wc | awk '{print $2}' > /tmp/tomcat_process_count.txt 
        read line < /tmp/tomcat_process_count.txt 
        if [ $line -gt 0 ]; then 
                echo -n "tomcat ( pid " 
                ps ax --width=1000 | grep "org.apache.catalina.startup.Bootstrap start" | awk '{printf $1 " "}' 
                echo -n ") is running..." 
                echo 
                
                echo -n $"Shutting down Tomcat: " 
                daemon $TOMCAT_STOP 
                rm -f /var/lock/subsys/tomcat.pid echo 
        else 
                echo "Tomcat is stopped" 
        fi 
        
        
} 
restart(){ 
        stop 
        start 
} 
status(){ 
        ps ax --width=1000 | grep "[o]rg.apache.catalina.startup.Bootstrap start" | awk '{printf $1 " "}' \
 | wc | awk '{print $2}' > /tmp/tomcat_process_count.txt 
        read line < /tmp/tomcat_process_count.txt 
        if [ $line -gt 0 ]; then 
                echo -n "tomcat ( pid " 
                ps ax --width=1000 | grep "org.apache.catalina.startup.Bootstrap start" | awk '{printf $1 " "}' 
                echo -n ") is running..." 
                echo 
        else 
                echo "Tomcat is stopped" 
        fi 
} 
case "$1" in 
        start) 
                start ;; 
        stop) 
                stop ;; 
        restart) 
                stop 
                sleep 3 
                start ;; 
        status) 
                status ;; 
        *) 
                echo "Usage: tomcatd {start|stop|restart|status}" 
                exit 1 
esac 
exit 0

保存退出后,修改文件属性

#chmod a+x tomcat

设置服务运行

#chkconfig --add tomcat

启动:

#service tomcat start


补充编码UTF-8设置:

 <Connector port="8080"  useBodyEncodingForURI="true" URIEncoding="UTF-8" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />


易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!