1、 Tomcat needs a JDK environment, refer to the previous article Install Java JDK8 under CentOS6, and install the JDK environment in advance
2、 Tomcat official website download tomcat8 binary distribution package apache-tomcat-8.5.38.tar.gz
3、 Upload to CentOS server and unzip
[ root@localhost ~]# tar -zxvf apache-tomcat-8.5.38.tar.gz
4、 Move the unzipped directory and rename it to /usr/tomcat
[ root@localhost ~]# mv apache-tomcat-8.5.38 /usr/tomcat
[ root@localhost ~]#
[ root@localhost ~]# useradd -M -d /usr/tomcat tomcat
[ root@localhost ~]# chown -R tomcat. /usr/tomcat
5、 Create the tomcat initial script in the /etc/init.d/ directory
#! /bin/bash
. /etc/init.d/functions
. /etc/sysconfig/network
JAVA_HOME=/usr/jdk1.8.0_201
export JAVA_HOME=/usr/jdk1.8.0_201
CATALINA_HOME=/usr/tomcat
TOMCAT_USER=tomcat
LOCKFILE=/var/lock/subsys/tomcat
RETVAL=0
start(){
echo "Starting Tomcat: "
su -
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch $LOCKFILE
return $RETVAL
}
stop(){
echo "Shutting down Tomcat: "
$CATALINA_HOME/bin/shutdown.sh
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -f $LOCKFILE
return $RETVAL
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
*)
echo $"Usage: $0 {start|stop|restart}"
exit 1
;;
esac
exit $?
6、 Add the execution permission of tomcat startup service, and start tomcat
Then add it to the boot option, set the tomcat service to boot automatically
[ root@localhost ~]# chmod 755 /etc/init.d/tomcat
[ root@localhost ~]# /etc/init.d/tomcat start
[ root@localhost ~]# chkconfig --add tomcat
[ root@localhost ~]# chkconfig tomcat on
[ root@localhost ~]# chkconfig tomcat --list
7、 Open http://server IP:8080 port verification
Tips
vi /usr/tomcat/conf/server.xml
Modify the default Connector port="8080" to Connector port="8880"
Then restart restart tomcat service
[ root@localhost ~]# tail -f /usr/tomcat/logs/catalina.2019-02-23.log
Recommended Posts