Production environment:
Server version: Apache Tomcat/8.5.16
CentOS Linux release 7.3.1611 (Core) x86-64
1.Apache Tomcat/8.5.16 depends on jre7 and above, but higher versions of jdk already include jre. For the installation of jdk&jre, please check "Linux JAVA JDK JRE Environment Variable Installation and Configuration"
2. Create tomcat exclusive user
# groupadd tomcat # useradd -g tomcat -s /bin/false tomcat 或 # useradd -g tomcat -s /sbin/nologin tomcat 注意: -g tomcat用户隶属于tomcat组 -s /bin/false 禁用shell访问
3. Download, install and configure Apache Tomcat 8.5 & set user group permissions and create soft connections
# cd /tmp # wget http://apache.fayea.com/tomcat/tomcat-8/v8.5.16/bin/apache-tomcat-8.5.16.tar.gz # tar zxvf apache-tomcat-8.5.16.tar.gz # mv apache-tomcat-8.5.16 /usr/local/ # cd /usr/local/ # chown -hR tomcat:tomcat apache-tomcat-8.5.16 # ln -s apache-tomcat-8.5.16 tomcat
4. Add tomcat self-starting systemd service unit file
# vim /lib/systemd/system/tomcat.service [Unit] Description=Apache Tomcat 8 After=syslog.target network.target [Service] Type=forking User=tomcat Group=tomcat Environment=JAVA_HOME=/usr/local/jdk/jre Environment=CATALINA_PID=/usr/local/tomcat/temp/tomcat.pid Environment=CATALINA_HOME=/usr/local/tomcat Environment=CATALINA_BASE=/usr/local/tomcat Environment='CATALINA_OPTS=-Xms512M -Xmx4096M -server -XX:+UseParallelGC' Environment='CATALINA_OPTS=-Dfile.encoding=UTF-8 -server -Xms2048m -Xmx2048m -Xmn1024m -XX:SurvivorRatio=10 -XX:MaxTenuringThreshold=15 -XX:NewRatio=2 -XX:+DisableExplicitGC' Environment='JAVA_OPTS=-Djava.awt.headless=true -Djava.security.egd=file:/dev/./urandom' ExecStart=/usr/local/tomcat/bin/startup.sh ExecStop=/bin/kill -15 $MAINPID Restart=on-failure [Install] WantedBy=multi-user.target
5. Reload the systemd service unit, give the soft connection directory permissions, start the Apache Tomcat service and set Tomcat to start automatically at boot
# systemctl daemon-reload # cd /usr/local/ # chown -hR tomcat:tomcat tomcat # systemctl start tomcat # systemctl enable tomcat
6. Configure Apache Tomcat user to achieve remote login
Add in the middle of tomcat-users.xml file;
# vim /usr/local/tomcat/conf/tomcat-users.xml
Tomcat 8.5 and later versions have enhanced remote login security filtering rules. Remote login is not supported by default and the configuration file needs to be modified.
Modify file:
/host-manager/META-INF/context.xml /manager/META-INF/context.xml
7. Configure Firewalld firewall
If you do not release port 8080, you cannot use 8080 for external access. Now release the port and reload the firewall service
# firewall-cmd --zone=public --add-port=8080/tcp --permanent # firewall-cmd --reload # firewall-cmd --list-ports # firewall-cmd --list-services
So far Apache Tomcat 8.5.16 has been successfully installed. Now you can use the IP:port for test access.
The above is the detailed content of Tomcat 8.5 install and configuration. For more information, please follow other related articles on the PHP Chinese website!