原文链接:点击打开链接
环境:阿里云ECS云服务器 CentOS 6.9 64位
过程:
1. yum update # 更新软件
2. yum install java-1.8.0-openjdk-devel # 安装 OpenJDK 1.8
3. wget http://mirrors.shu.edu.cn/apache/tomcat/tomcat-8/v8.5.31/bin/apache-tomcat-8.5.31.tar.gz # 从国内镜像站点中下载 tomcat 8.5 安装包
4. tar zxvf apache-tomcat-8.5.31.tar.gz # 解压缩 tomcat
5. mv apache-tomcat-8.5.31 /usr/tomcat8 # 移到 /usr/tomcat8 目录
6. useradd -M -d /usr/tomcat8 tomcat8 # 添加 tomcat8 用户
7. chown -R tomcat8. /usr/tomcat8 # 更改目录属主
8. vi /etc/rc.d/init.d/tomcat8 # 创建 tomcat 启动脚本
- #!/bin/bash
- # Tomcat8: Start/Stop Tomcat 8
- #
- # chkconfig: - 90 10
- # description: Tomcat is a Java application Server.
- . /etc/init.d/functions
- . /etc/sysconfig/network
- CATALINA_HOME=/usr/tomcat8
- TOMCAT_USER=tomcat8
- LOCKFILE=/var/lock/subsys/tomcat8
- RETVAL=0
- start(){
- echo "Starting Tomcat8: "
- su - $TOMCAT_USER -c "$CATALINA_HOME/bin/startup.sh"
- RETVAL=$?
- echo
- [ $RETVAL -eq 0 ] && touch $LOCKFILE
- return $RETVAL
- }
- stop(){
- echo "Shutting down Tomcat8: "
- $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 $?
10. /etc/rc.d/init.d/tomcat8 start # 手动启动 tomcat
11. chkconfig --add tomcat8 # 将 tomcat8 添加到服务
12. chkconfig tomcat8 on # 令 tomcat8 服务随系统启动自动启动
参考:
- https://www.server-world.info/en/note?os=CentOS_6&p=tomcat8
- https://www.digitalocean.com/community/tutorials/how-to-install-java-on-centos-and-fedora