Linux (Centos7) install tomcat

foreword

You must first install jdk
JDK installation: https://blog.csdn.net/dontYouWorry/article/details/128919926

1. Tomcat installation

1. Upload the compressed package to the /opt directory of the Linux server through Xftp

insert image description here
2. Unzip to the /usr/local/ directory

tar -zxvf apache-tomcat-8.5.85.tar.gz -C /usr/local

insert image description here
3. Start tomcat

#在tomcat/bin目录下执行: /usr/local/apache-tomcat-8.5.85/bin
./startup.sh

insert image description here
4. Browser access test (IP: port)
1. Close the firewall or open the firewall port (tomcat default 8080port), choose one

#1. 关闭防火墙
1. systemctl stop firewalld 

#2. 防火墙开放8080端口
1. firewall-cmd --zone=public --add-port=8080/tcp --permanent
2. systemctl restart firewalld   //重启

2. Access

insert image description here

2. Tomcat changes the access port

1. Configuration file change port - 8080change to other port

#配置文件路径:/usr/local/apache-tomcat-8.5.85/conf/server.xml
vim /usr/local/apache-tomcat-8.5.85/conf/server.xml

insert image description here
2. Restart tomcat

#在 /usr/local/apache-tomcat-8.5.85/bin 下执行。
./shutdown.sh && ./startup.sh  #重启

3. Browser access
needs to close the firewall or just open the firewall更改的端口

#1. 关闭防火墙
1. systemctl stop firewalld 

#2. 防火墙开放8080端口
1. firewall-cmd --zone=public --add-port=8801/tcp --permanent
2. systemctl restart firewalld   //重启

insert image description here

3. Set the boot to start automatically

1. /etc/init.dCreate a system service file in the directory tomcatand add the following content

vim /etc/init.d/tomcat
#!/bin/bash
# description:
# processname:
# chkconfig: 234 20 80
 
#改成自己的安装路径 
CATALINA_HOME=/usr/local/apache-tomcat-8.5.85
 
case $1 in
        start)
                sh $CATALINA_HOME/bin/startup.sh
                ;;
        stop)
                sh $CATALINA_HOME/bin/shutdown.sh
                ;;
        restart)
                sh $CATALINA_HOME/bin/shutdown.sh
                sh $CATALINA_HOME/bin/startup.sh
                ;;
        *)
                echo 'please use : tomcat {start | stop | restart}'
        ;;
esac
exit 0

2. Authorize the file

chmod 744 /etc/init.d/tomcat

3. Modify the tomcat configuration file - add the jdk path at the top

vim /usr/local/apache-tomcat-8.5.85/bin/catalina.sh

insert image description here

4. Configure tomcat to boot

#1. 向chkconfig添加 tomcat 服务的管理
chkconfig --add tomcat
#2. 设置tomcat服务自启动
chkconfig tomcat
#3. 查看tomcat的启动状态
chkconfig --list | grep tomcat

#其他指令
#1.关闭tomcat服务自启动
chkconfig tomcat off
#2.删除tomcat服务在chkconfig上的管理
chkconfig –del tomcat

5. Start tomcat

#启动并查看tomcat的状态
systemctl start tomcat && systemctl status tomcat

Guess you like

Origin blog.csdn.net/dontYouWorry/article/details/129040595