下载安装包(tomcat9.0.22,jdk1.8): https://download.csdn.net/download/qq_37160920/11460571
Linux安装jdk
1.上传到服务器并解压
mkdir /usr/java/
cd /usr/local/java
授权:
chmod +x jdk-8u131-linux-x64.rpm
安装:
rpm -ivh jdk-8u171-linux-x64.rpm
配置环境变量:
vi /etc/profile
export JAVA_HOME=/usr/java/jdk1.8.0_131
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH
重新加载环境变量
source /etc/profile
查看是否安装成功:
java -version
Linux安装tomcat,并配置自启动
1.上传并解压
tar -zxvf apache-tomcat-9.0.22.tar.gz
2.配置tomcat自启动
1.把下面文件保存为tomcat(无后缀名)
#!/bin/sh
# chkconfig: 345 99 10
# description: Auto-starts tomcat
# /etc/init.d/tomcatd
# Tomcat auto-start
# Source function library.
#. /etc/init.d/functions
# source networking configuration.
#. /etc/sysconfig/network
RETVAL=0
export JAVA_HOME=/usr/java/jdk1.8.0_131
export JRE_HOME=/usr/java/jdk1.8.0_131/jre
export CATALINA_HOME=/opt/tomcat/apache-tomcat-9.0.22/
export CATALINA_BASE=/opt/tomcat/apache-tomcat-9.0.22/
start()
{
if [ -f $CATALINA_HOME/bin/startup.sh ];
then
echo $"Starting Tomcat"
$CATALINA_HOME/bin/startup.sh
RETVAL=$?
echo " OK"
return $RETVAL
fi
}
stop()
{
if [ -f $CATALINA_HOME/bin/shutdown.sh ];
then
echo $"Stopping Tomcat"
$CATALINA_HOME/bin/shutdown.sh
RETVAL=$?
sleep 1
ps -fwwu root | grep tomcat|grep -v grep | grep -v PID | awk '{print $2}'|xargs kill -9
echo " OK"
# [ $RETVAL -eq 0 ] && rm -f /var/lock/...
return $RETVAL
fi
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
echo $"Restaring Tomcat"
$0 stop
sleep 1
$0 start
;;
*)
echo $"Usage: $0 {start|stop|restart}"
exit 1
;;
esac
exit $RETVAL
2.把tomcat文件放到/etc/init.d下
3.添加自启动
cd /etc/init.d
chmod 755 tomcat
chkconfig --add tomcat
4.开启tomcat系统服务
chkconfig tomcat on
启动tomcat服务
serice tomcat start
关闭tomcat服务:
service tomcat stop