1.查看是否安装jdk
[root@localhost ~]# java -version
java version "1.8.0_151"
Java(TM) SE Runtime Environment (build 1.8.0_151-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.151-b12, mixed mode)
2.tomcat下载
http://124.205.69.166/files/917300000333E604/mirrors.noc.im/apache/tomcat/tomcat-8/v8.0.32/bin/apache-tomcat-8.0.32.tar.gz
3.软件解压
[root@localhost soft]# tar -zxvf apache-tomcat-8.5.16.tar.gz -C /usr/local
4.安装tomcat
[root@localhost tomcat]# /usr/local/tomcat/bin/startup.sh
Using CATALINA_BASE: /usr/local/tomcat
Using CATALINA_HOME: /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME: /usr/local/java/jdk1.8.0_151
Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Tomcat started.
5.安装成功,防火墙开放8080端口,增加到防火墙配置中
配置8080开放端口:
[root@localhost tomcat]# /sbin/iptables -I INPUT -p tcp --dport 8080 -j ACCEPT
[root@localhost tomcat]# /etc/rc.d/init.d/iptables save
iptables:将防火墙规则保存到 /etc/sysconfig/iptables: [确定]
[root@localhost tomcat]# /etc/rc.d/init.d/iptables restart
iptables:将链设置为政策 ACCEPT:filter [确定]
iptables:清除防火墙规则: [确定]
iptables:正在卸载模块: [确定]
iptables:应用防火墙规则: [确定]
6.关闭Tomcat
[root@localhost tomcat]# /usr/local/tomcat/bin/shutdown.sh
Using CATALINA_BASE: /usr/local/tomcat
Using CATALINA_HOME: /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME: /usr/local/java/jdk1.8.0_151
Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
7.启动Tomcat
[root@localhost tomcat]# /usr/local/tomcat/bin/startup.sh
Using CATALINA_BASE: /usr/local/tomcat
Using CATALINA_HOME: /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME: /usr/local/java/jdk1.8.0_151
Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Tomcat started.
8.ip:8080访问
扩展:
设置Tomcat的开机自启动,在/etc/rc.d/rc.local的底部添加下面内容。
[root@Wulaoer ~]# vi /etc/rc.d/rc.local
touch /var/lock/subsys/local
export JDK_HOME=/usr/java/jdk1.8.0_73
export JAVA_HOME=/usr/java/jdk1.8.0_73
/usr/local/tomcat/bin/startup.sh
注意:jdk的路径和tomcat的路径要根据自己安装的路径。重启以下测试
修改端口:
示例:把8080端口修改成80端口。
[root@Wulaoer ~]# vi /usr/local/tomcat/conf/server.xml
文件中找到:
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
把8080修改程80,保存重启以下tomcat,直接访问测试