环境: CentOS 7 x86_64
1、安装jdk
rpm -ivh jdk-8u60-linux-x64.rpm
2、创建普通用户
getent group tomcat || groupadd -r tomcat getent passwd tomcat || useradd -r -d /opt -s /bin/nologin tomcat
3、下载tomcat 7
cd /opt wget http://mirrors.ustc.edu.cn/apache/tomcat/tomcat-7/v7.0.64/bin/apache-tomcat-7.0.64.tar.gz tar zxvf apache-tomcat-7.0.64.tar.gz mv apache-tomcat-7.0.64 tomcat01 chown -R tomcat:tomcat tomcat01 tar zxvf apache-tomcat-7.0.64.tar.gz mv apache-tomcat-7.0.64 tomcat02 chown -R tomcat:tomcat tomcat02
两个实例同时监听8080端口必然会产生冲突,所以必须修改.
sed -i ‘s/8080/8081/g‘ /opt/tomcat01/conf/server.xml sed -i ‘s/8005/8001/g‘ /opt/tomcat01/conf/server.xml sed -i ‘s/8080/8082/g‘ /opt/tomcat02/conf/server.xml sed -i ‘s/8005/8002/g‘ /opt/tomcat02/conf/server.xml
AJP通常用不上,这里统一关闭
sed -i ‘/8009/d‘ /opt/tomcat01/conf/server.xml sed -i ‘/8009/d‘ /opt/tomcat01/conf/server.xml
tomcat在Linux 下默认工作模式是bio,性能非常低,建议使用apr或者nio,
这里改为nio,即非阻塞IO,性能比较好。
sed -i.bak ‘s#HTTP/1.1#org.apache.coyote.http11.Http11NioProtocol#‘ /opt/tomcat01/conf/server.xml sed -i.bak ‘s#HTTP/1.1#org.apache.coyote.http11.Http11NioProtocol#‘ /opt/tomcat02/conf/server.xml
3、创建启动文件
cd /usr/lib/systemd/system cat >tomcat01.service <<EOF [Unit] Description=Apache Tomcat 8 After=network.target [Service] Type=oneshot ExecStart=/opt/tomcat01/bin/startup.sh ExecStop=/opt/tomcat01/bin/shutdown.sh RemainAfterExit=yes User=tomcat Group=tomcat [Install] WantedBy=multi-user.target EOF
tomcat02同理
sed ‘s/tomcat01/tomcat02/g‘ tomcat01.service > tomcat02.service
4、启动服务
systemctl enable tomcat01 systemctl enable tomcat02 systemctl start tomcat01 systemctl start tomcat02
5、查看进程
ps aux |grep tomcat
本文出自 “专注Linux 运维” 博客,请务必保留此出处http://purplegrape.blog.51cto.com/1330104/1702292
原文:http://purplegrape.blog.51cto.com/1330104/1702292