用户
useradd -s /sbin/nologin tomcat
安装jdk
设置JAVA_HOME等环境变量
sed -i 's#securerandom.source=file:/dev/random#securerandom.source=file:/dev/./urandom#g' "$JAVA_HOME/jre/lib/security/java.security"
安装tomcat
复制两份tomcat
到/usr/local/
目录下
[root@zrd /usr/local]# ls tomcat* |
chown -R tomcat /usr/local/tomcat*
配置
pid
mkdir -p /var/run/tomcat && chown tomcat.tomcat -R /var/run/tomcat && chmod 600 /var/run/tomcat
sed -i '/cygwin=false/i\CATALINA_PID=/var/run/tomcat/tomcat1.pid' /usr/local/tomcat1/bin/catalina.sh
sed -i '/cygwin=false/i\CATALINA_PID=/var/run/tomcat/tomcat2.pid' /usr/local/tomcat2/bin/catalina.sh
grep CATALINA_PID= /usr/local/tomcat1/bin/catalina.sh
grep CATALINA_PID= /usr/local/tomcat2/bin/catalina.sh
logs
tomcat1
sed -i 's#${catalina.base}/logs#/home/weblog/tomcat1#g' /usr/local/tomcat1/conf/logging.properties
grep tomcat1 /usr/local/tomcat1/conf/logging.properties
sed -i 's#CATALINA_OUT="$CATALINA_BASE"/logs/catalina.out#CATALINA_OUT=/home/weblog/tomcat1/catalina.out#g' /usr/local/tomcat1/bin/catalina.sh
grep CATALINA_OUT= /usr/local/tomcat1/bin/catalina.sh
sed -i 's#directory="logs"#directory="/home/weblog/tomcat1"#g' /usr/local/tomcat1/conf/server.xml
grep /home/weblog/tomcat1 /usr/local/tomcat1/conf/server.xml
tomat2
sed -i 's#${catalina.base}/logs#/home/weblog/tomcat2#g' /usr/local/tomcat2/conf/logging.properties
grep tomcat2 /usr/local/tomcat2/conf/logging.properties
sed -i 's#CATALINA_OUT="$CATALINA_BASE"/logs/catalina.out#CATALINA_OUT=/home/weblog/tomcat2/catalina.out#g' /usr/local/tomcat2/bin/catalina.sh
grep CATALINA_OUT= /usr/local/tomcat2/bin/catalina.sh
sed -i 's#directory="logs"#directory="/home/weblog/tomcat2"#g' /usr/local/tomcat2/conf/server.xml
grep /home/weblog/tomcat2 /usr/local/tomcat2/conf/server.xml
监听端口
tomat1
sed -i 's#<Server port="8005" shutdown="SHUTDOWN">#<Server port="18005" shutdown="tomcat1">#g' /usr/local/tomcat1/conf/server.xml
grep shutdown= /usr/local/tomcat1/conf/server.xml
sed -i 's#<Connector port="8080"#<Connector port="18080"#g' /usr/local/tomcat1/conf/server.xml
grep 'Connector port="18080"' /usr/local/tomcat1/conf/server.xml
sed -i 's#redirectPort="8443"#redirectPort="18443"#g' /usr/local/tomcat1/conf/server.xml
grep 'redirectPort=' /usr/local/tomcat1/conf/server.xml
sed -i 's#<Connector port="8009"#<Connector port="18009"#g' /usr/local/tomcat1/conf/server.xml
grep 18009 /usr/local/tomcat1/conf/server.xml
tomat2
sed -i 's#<Server port="8005" shutdown="SHUTDOWN">#<Server port="18006" shutdown="tomcat2">#g' /usr/local/tomcat2/conf/server.xml
grep shutdown= /usr/local/tomcat2/conf/server.xml
sed -i 's#<Connector port="8080"#<Connector port="18081"#g' /usr/local/tomcat2/conf/server.xml
grep 'Connector port="18081"' /usr/local/tomcat2/conf/server.xml
sed -i 's#redirectPort="8443"#redirectPort="18444"#g' /usr/local/tomcat2/conf/server.xml
grep 'redirectPort=' /usr/local/tomcat2/conf/server.xml
sed -i 's#<Connector port="8009"#<Connector port="18010"#g' /usr/local/tomcat2/conf/server.xml
grep 18010 /usr/local/tomcat2/conf/server.xml
启动脚本
tomcat1
cat >/usr/lib/systemd/system/tomcat1.service<< 'EOF' |
tomcat2
cat >/usr/lib/systemd/system/tomcat2.service<< 'EOF' |
systemctl daemon-reload
systemctl cat tomcat1
systemctl cat tomcat2
tomcat 项目存放目录
mkdir -pv /home/wwwroot/{tomcat1,tomcat2}
chown -R tomcat.tomcat /home/wwwroot