centos 7 安装 tomcat
一、安装jdk
- 下载 jdk-8u161-linux-x64.tar.gz 链接:https://pan.baidu.com/s/1i8aQodhxwyZqfdfb9yl3Ig 密码:aioy
- 通过xftp 将 jdk-8u161-linux-x64.tar.gz 上传到/home文件夹下
- 解压
[root@localhost home]# tar -zxvf jdk-8u161-linux-x64.tar.gz
- 将解压后的文件夹移动到 /usr/local/ 文件夹下
[root@localhost home]# mv jdk1.8.0_161/ /usr/local/
- 修改系统配置
[root@localhost home]# cat /etc/profile
找到 export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE HISTCONTROL 位置,在下面添加如下配置并保存
export JAVA_HOME=/usr/local/jdk1.8.0_161
export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin - 重新加载配置
[root@localhost home]# source /etc/profile
- 测试Jdk 是否安装成功
[root@localhost home]# java -version
java version "1.8.0_161"
Java(TM) SE Runtime Environment (build 1.8.0_161-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.161-b12, mixed mode)
二、安装tomcat
- 下载 apache-tomcat-8.5.30.tar.gz 链接:https://pan.baidu.com/s/1-8RVSazmyTe9O93Ha3P9Jw 密码:ktnv
- 通过xftp 将 apache-tomcat-8.5.30.tar.gz 上传到/home文件夹下
- 解压
[root@localhost home]# tar -zxvf apache-tomcat-8.5.30.tar.gz
- 移动
[root@localhost home]# mv apache-tomcat-8.5.29 /usr/local/tomcat-8.5.29
- 创建 tomcat.service并保存
[root@localhost home]# vi /usr/lib/systemd/system/tomcat.service
[Unit] Description=Tomcat8 After=syslog.target network.target remote-fs.target nss-lookup.target [Service] Type=forking Environment='JAVA_HOME=/usr/local/jdk1.8.0_161' Environment='CATALINA_PID=/usr/local/tomcat-8.5.29/bin/tomcat.pid' Environment='CATALINA_HOME=/usr/local/tomcat-8.5.29/' Environment='CATALINA_BASE=/usr/local/tomcat-8.5.29/' Environment='CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC' WorkingDirectory=/usr/local/tomcat-8.5.29/ ExecStart=/usr/local/tomcat-8.5.29/bin/startup.sh ExecReload=/bin/kill -s HUP $MAINPID ExecStop=/bin/kill -s QUIT $MAINPID PrivateTmp=true [Install] WantedBy=multi-user.target
- 启动tomcat服务
[root@localhost home]# systemctl start tomcat.service
- 设置防火墙,开启8080端口
[root@localhost home]# firewall-cmd --zone=public --add-port=8080/tcp --permanent
[root@localhost home]# firewall-cmd --reload
-
设置开机自动启动
[root@localhost home]# systemctl enable tomcat.service
- 测试tomcat是否安装成功 http://192.168.0.11:8080/