-
下载Tomcat的源码压缩包
Tomcat 8.5的下载地址是http://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-8/v8.5.43/bin/apache-tomcat-8.5.43.tar.gz
下载后的文件名是apache-tomcat-8.5.43.tar.gz -
切换到root用户,确认已安装JDK
[root@localhost ~]# java -version
java version "1.8.0_211"
Java(TM) SE Runtime Environment (build 1.8.0_211-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.211-b12, mixed mode)
- 上传Tomcat源码压缩包,然后解压缩
[root@localhost ~]# tar -xzvf apache-tomcat-8.5.43.tar.gz
- 因为tomcat的目录名较长,可以改名移动/usr/local目录
[root@localhost ~]# mv apache-tomcat-8.5.43 /usr/local/tomcat
- 创建tomcat用户,把tomcat目录拥有者改为tomcat用户
[root@localhost ~]# useradd -M tomcat
[root@localhost ~]# chown -R tomcat:tomcat /usr/local/tomcat
- 创建tomcat服务文件
[root@localhost ~]# vi /usr/lib/systemd/system/tomcat.service
假设JDK的目录是/usr/local/jdk,输入下面内容保存退出
[Unit]
Description=Apache Tomcat Web Application Container
After=syslog.target network.target
[Service]
Type=oneshot
Environment=JAVA_HOME=/usr/local/jdk
ExecStart=/usr/local/tomcat/bin/startup.sh
ExecStop=/usr/local/tomcat/bin/shutdown.sh
RemainAfterExit=yes
User=tomcat
Group=tomcat
[Install]
WantedBy=multi-user.target
- 启动tomcat服务,查询tomcat服务状态,正常应该显示绿色的active状态
[root@localhost ~]# systemctl start tomcat
[root@localhost ~]# systemctl status tomcat
-
验证tomcat安装成功
启动CentOS的Firefox浏览器输入网址http://localhost:8080/,如果能打开网页说明Tomcat安装成功。 -
设置开机自动启动tomcat服务
[root@localhost ~]# systemctl enable tomcat
- 设置防火墙允许Tomcat的8080端口访问
[root@localhost ~]# firewall-cmd --add-port=8080/tcp --zone=public --permanent
success
[root@localhost ~]# firewall-cmd --reload
success
- 验证防火墙设置成功
Windows环境下打开浏览器输入网址http://192.168.66.128:8080/,如果能打开网页说明防火墙设置成功。
其中192.168.66.128要改成你CentOS的IP地址
网友评论