新增Tomcat专用用户

sudo groupadd tomcat sudo mkdir /opt/tomcat sudo useradd -s /bin/nologin -g tomcat -d /opt/tomcat tomcat

下载并安装最新版本Tomcat

wget http://mirrors.hust.edu.cn/apache/tomcat/tomcat-8/v8.5.34/bin/apache-tomcat-8.5.34.tar.gz sudo tar -zxvf apache-tomcat-8.5.34.tar.gz -C /opt/tomcat --strip-components=1

权限设置

cd /opt/tomcat sudo chown -R tomcat . sudo chgrp -R tomcat conf sudo chmod g+rwx conf sudo chmod g+r conf/* sudo chown -R tomcat logs/ temp/ webapps/ work/

为Tomcat创建systemd unit 文件

sudo vi /etc/systemd/system/tomcat.service 内容如下 [Unit] Description=Apache Tomcat Web Application Container After=syslog.target network.target

[Service] Type=forking

Environment=JAVA_HOME=/usr/lib/jvm/jre Environment=CATALINA_PID=/opt/tomcat/temp/tomcat.pid Environment=CATALINA_HOME=/opt/tomcat Environment=CATALINA_BASE=/opt/tomcat Environment='CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC' Environment='JAVA_OPTS=-Djava.awt.headless=true -Djava.security.egd=file:/dev/./urandom'

ExecStart=/opt/tomcat/bin/startup.sh ExecStop=/bin/kill -15 $MAINPID

User=tomcat Group=tomcat

[Install] WantedBy=multi-user.target

启动Tomcat 并开启防火墙

sudo systemctl start tomcat.service sudo systemctl enable tomcat.service

启动tomcat

/opt/tomcat/bin/startup.sh

查看tomcat进程

ps -ef|grep tomcat

查看tomcat日志

tail -100f /opt/tomcat/logs/catalina.out

查看tomcat端口

netstat -anop | grep 进程号pid

关闭tomcat

kill -9 进程号pid

通过systemctl status firewalld查看firewalld状态

通过systemctl start firewalld开启防火墙

sudo firewall-cmd --zone=public --permanent --add-port=80/tcp sudo firewall-cmd --reload

配置Tomcat 管理界面

sudo vi /opt/tomcat/conf/tomcat-users.xml 在 <tomcat-users ...>...中加入一个admin账号:

之后重启Tomcat

sudo systemctl restart tomcat.service

最后修改于 2018-11-08 10:51:27
如果觉得我的文章对你有用,请随意赞赏
扫一扫支付
上一篇