cd /usr/local
进入/usr/local目录
mkdir tomcat
创建tomcat目录
cd tomcat
进入tomcat目录
wget https://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-8/v8.5.38/bin/apache-tomcat-8.5.38.tar.gz
下载Tomcat8.5.38
9.0的版本太新了
暂时不用
tar -zxvf apache-tomcat-8.5.38.tar.gz
解压
rm -rf apache-tomcat-8.5.38.tar.gz
删除压缩包
以免占磁盘空间
cd apache-tomcat-8.5.38
进入
配置tomcat
vim /usr/lib/systemd/system/tomcat.service
创建文件
添加以下内容
[Unit]
Description=Tomcat
After=syslog.target network.target remote-fs.target nss-lookup.target
[Service]
Type=oneshot
ExecStart=/usr/local/tomcat/apache-tomcat-8.5.38/bin/startup.sh
ExecStop=/usr/local/tomcat/apache-tomcat-8.5.38/bin/shutdown.sh
ExecReload=/bin/kill -s HUP $MAINPID
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
vim /usr/local/tomcat/apache-tomcat-8.5.38/bin/setclasspath.sh
配置JAVA环境变量
加入以下两行
export JAVA_HOME=/usr/local/java/jdk1.8
export JRE_HOME=/usr/local/java/jdk1.8/jre
systemctl start tomcat
启动tomcat
systemctl enable tomcat
使tomcat开机启动
tomcat的默认端口是8080
开启Tomcat默认的8080端口
firewall-cmd --zone=public --add-port=8080/tcp --permanent
firewall-cmd --reload
访问
http://192.168.1.107:8080/
vim /usr/local/nginx/conf/nginx.conf
修改nginx配置文件
把80端口映射到8080端口
添加
location /tomcat/ {
proxy_pass http://127.0.0.1:8080/;
}
systemctl restart nginx
重启nginx
访问
http://192.168.1.107/tomcat/
或者继续访问带端口的地址