Tomcat 环境部署
部署 jdk
[root@node05 ~]# ll jdk-8u60-linux-x64.tar.gz
-rw-r--r-- 1 root root 181238643 Aug 9 2020 jdk-8u60-linux-x64.tar.gz
[root@node05 ~]# mkdir /usr/java
[root@node05 ~]# tar xf jdk-8u60-linux-x64.tar.gz -C /usr/java
[root@node05 ~]# vim /etc/profile.d/java.sh
JAVA_HOME=/usr/java/jdk1.8.0_60
PATH=$JAVA_HOME/bin:$PATH
CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export JAVA_HOME CLASSPATH PATH
[root@node05 ~]# source /etc/profile.d/java.sh
[root@node05 ~]# java -version
java version "1.8.0_60"
Java(TM) SE Runtime Environment (build 1.8.0_60-b27)
Java HotSpot(TM) 64-Bit Server VM (build 25.60-b23, mixed mode)
部署 Tomcat
[root@node05 ~]# ll apache-tomcat-8.5.20.tar.gz
-rw-r--r-- 1 root root 9433364 Aug 9 2020 apache-tomcat-8.5.20.tar.gz
[root@node05 ~]# tar xf apache-tomcat-8.5.20.tar.gz -C /usr/local/
[root@node05 ~]# ln -s /usr/local/apache-tomcat-8.5.20/ /usr/local/tomcat
[root@node05 ~]# echo 'export TOMCAT_HOME=/usr/local/tomcat'>>/etc/profile.d/tomcat.sh
[root@node05 ~]# source /etc/profile.d/tomcat.sh
[root@node05 ~]# /usr/local/tomcat/bin/version.sh
Using CATALINA_BASE: /usr/local/tomcat
Using CATALINA_HOME: /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME: /usr/java/jdk1.8.0_60
Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Server version: Apache Tomcat/8.5.20
Server built: Aug 2 2017 21:35:49 UTC
Server number: 8.5.20.0
OS Name: Linux
OS Version: 3.10.0-1127.el7.x86_64
Architecture: amd64
JVM Version: 1.8.0_60-b27
JVM Vendor: Oracle Corporation
提供 Tomcat 系统启动脚本
[root@node05 ~]# vim /etc/init.d/tomcat
#!/bin/bash
#
# chkconfig: 35 99 28
# description: Starts/Stops Apache Tomcat
#
# Tomcat start/stop/status script
#
#Location of JAVA_HOME (bin files)
export JAVA_HOME=/usr/java/jdk1.8.0_60
#Add Java binary files to PATH
export PATH=$JAVA_HOME/bin:$PATH
#CATALINA_HOME is the location of the bin files of Tomcat
export CATALINA_HOME=/usr/local/tomcat
#CATALINA_BASE is the location of the configuration files of this instance of Tomcat
export CATALINA_BASE=$CATALINA_HOME
#TOMCAT_USAGE is the message if this script is called without any options
TOMCAT_USAGE="Usage: $0 {\e[00;32mstart\e[00m|\e[00;31mstop\e[00m|\e[00;32mstatus\e[00m|\e[00;31mrestart\e[00m}"
#SHUTDOWN_WAIT is wait time in seconds for java proccess to stop
SHUTDOWN_WAIT=20
tomcat_pid() {
echo `ps -fe | grep $CATALINA_BASE | grep -v grep | awk '{print $2}'`
}
start() {
pid=$(tomcat_pid)
if [ -n "$pid" ]
then
echo -e "\e[00;31mTomcat is already running (pid: $pid)\e[00m"
else
# Start tomcat
echo -e "\e[00;32mStarting tomcat\e[00m"
#ulimit -n 100000
#umask 007
#/bin/su -p -s /bin/sh tomcat
sh $CATALINA_HOME/bin/startup.sh
status
fi
return 0
}
status(){
pid=$(tomcat_pid)
if [ -n "$pid" ]; then echo -e "\e[00;32mTomcat is running with pid: $pid\e[00m"
else echo -e "\e[00;31mTomcat is not running\e[00m"
fi
}
stop() {
pid=$(tomcat_pid)
if [ -n "$pid" ]
then
echo -e "\e[00;31mStoping Tomcat\e[00m"
#/bin/su -p -s /bin/sh tomcat
sh $CATALINA_HOME/bin/shutdown.sh
let kwait=$SHUTDOWN_WAIT
count=0;
until [ `ps -p $pid | grep -c $pid` = '0' ] || [ $count -gt $kwait ]
do
echo -n -e "\e[00;31mwaiting for processes to exit\n\e[00m"
sleep 1
let count=$count+1;
done
if [ $count -gt $kwait ]
then
echo -n -e "\e[00;31mkilling processes which didn't stop after $SHUTDOWN_WAIT seconds\n\e[00m"
kill -9 $pid
fi
else
echo -e "\e[00;31mTomcat is not running\e[00m"
fi
return 0
}
case $1 in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
status)
status
;;
*)
echo -e $TOMCAT_USAGE
;;
esac
exit 0
[root@node05 ~]# chmod +x /etc/init.d/tomcat
[root@node05 ~]# chkconfig --add tomcat
[root@node05 ~]# systemctl start tomcat
[root@node05 ~]# ps -ef | grep java
root 13026 1 23 09:09 ? 00:00:02 /usr/java/jdk1.8.0_60/bin/java -Djava.util.logging.config.file=/usr/local/tomcat/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -classpath /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar -Dcatalina.base=/usr/local/tomcat -Dcatalina.home=/usr/local/tomcat -Djava.io.tmpdir=/usr/local/tomcat/temp org.apache.catalina.startup.Bootstrap start
root 13076 12766 0 09:09 pts/0 00:00:00 grep --color=auto java
浏览器访问:http://192.168.5.15:8080/
加快Tomcat服务启动
[root@node05 ~]# cat /proc/sys/kernel/random/entropy_avail
1250
[root@node05 ~]# yum install rng-tools -y
[root@node05 ~]# systemctl start rngd
[root@node05 ~]# systemctl enable rngd
[root@node05 ~]# cat /proc/sys/kernel/random/entropy_avail
3188
Tomcat web 管理
[root@node05 ~]# vim /usr/local/tomcat/conf/tomcat-users.xml
... ...
<role rolename="admin-gui"/>
<role rolename="admin-script"/>
<role rolename="manager-gui"/>
<role rolename="manager-jmx"/>
<role rolename="manager-script"/>
<role rolename="manager-status"/>
<user username="tomcat" password="tomcat" roles="admin-gui,manager-gui,manager-jmx,manager-script,manager-status,admin-script"/>
</tomcat-users>
[root@node05 ~]# vim /usr/local/tomcat/webapps/manager/META-INF/context.xml
... ...
<Context antiResourceLocking="false" privileged="true" >
<Valve className="org.apache.catalina.valves.RemoteAddrValve"
allow="^.*$" />
# allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />
<Manager sessionAttributeValueClassNameFilter="java\.lang\.(?:Boolean|Integer|Long|Number|String)|org\.apache\.catalina\.filters\.CsrfPreventionFilter\$LruCache(?:\$1)?|java\.util\.(?:Linked)?HashMap"/>
</Context>
[root@node05 ~]# vim /usr/local/tomcat/webapps/host-manager/META-INF/context.xml
<Context antiResourceLocking="false" privileged="true" >
<Valve className="org.apache.catalina.valves.RemoteAddrValve"
allow="^.*$" />
# allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />
<Manager sessionAttributeValueClassNameFilter="java\.lang\.(?:Boolean|Integer|Long|Number|String)|org\.apache\.catalina\.filters\.CsrfPreventionFilter\$LruCache(?:\$1)?|java\.util\.(?:Linked)?HashMap"/>
</Context>
[root@node05 ~]# systemctl restart tomcat.service
登录用户名、密码