共计 10693 个字符,预计需要花费 27 分钟才能阅读完成。
分享在 CentOS 下安装 Tomcat 并配置环境变量(改默认端口 8080 为 8081)的全过程,希望对大家有帮助。
第一步:下载 tomcat 压缩包
http://archive.apache.org/dist/tomcat/tomcat-7/v7.0.73/bin/
第二步:上传 tomcat 压缩包
[Hadoop@HadoopMaster app]$ ll
total 3092
drwxrwxr-x. 9 hadoop hadoop 4096 Feb 22 06:05 elasticsearch-2.4.3
-rw-r–r–. 1 hadoop hadoop 908862 Jan 10 11:38 elasticsearch-head-master.zip
-rw-r–r–. 1 hadoop hadoop 2228252 Jan 10 11:38 elasticsearch-kopf-master.zip
drwxr-xr-x. 10 hadoop hadoop 4096 Oct 31 17:15 hadoop-2.6.0
drwxr-xr-x. 15 hadoop hadoop 4096 Nov 14 2014 hadoop-2.6.0-src
drwxrwxr-x. 8 hadoop hadoop 4096 Nov 2 18:20 hbase-1.2.3
drwxr-xr-x. 8 hadoop hadoop 4096 Apr 11 2015 jdk1.7.0_79
drwxr-xr-x. 10 hadoop hadoop 4096 Nov 1 23:39 zookeeper-3.4.6
[hadoop@HadoopMaster app]$ rz
[hadoop@HadoopMaster app]$ ll
total 11824
-rw-r–r–. 1 hadoop hadoop 8938514 Feb 25 11:10 apache-tomcat-7.0.73.tar.gz
drwxrwxr-x. 9 hadoop hadoop 4096 Feb 22 06:05 elasticsearch-2.4.3
-rw-r–r–. 1 hadoop hadoop 908862 Jan 10 11:38 elasticsearch-head-master.zip
-rw-r–r–. 1 hadoop hadoop 2228252 Jan 10 11:38 elasticsearch-kopf-master.zip
drwxr-xr-x. 10 hadoop hadoop 4096 Oct 31 17:15 hadoop-2.6.0
drwxr-xr-x. 15 hadoop hadoop 4096 Nov 14 2014 hadoop-2.6.0-src
drwxrwxr-x. 8 hadoop hadoop 4096 Nov 2 18:20 hbase-1.2.3
drwxr-xr-x. 8 hadoop hadoop 4096 Apr 11 2015 jdk1.7.0_79
drwxr-xr-x. 10 hadoop hadoop 4096 Nov 1 23:39 zookeeper-3.4.6
[hadoop@HadoopMaster app]$
第三步: 解压缩 apache-tomcat-7.0.73.tar.gz
[hadoop@HadoopMaster app]$ tar -zxvf apache-tomcat-7.0.73.tar.gz
第四步:删除压缩包
[hadoop@HadoopMaster app]$ ll
total 11828
drwxrwxr-x. 9 hadoop hadoop 4096 Feb 25 19:18 apache-tomcat-7.0.73
-rw-r–r–. 1 hadoop hadoop 8938514 Feb 25 11:10 apache-tomcat-7.0.73.tar.gz
drwxrwxr-x. 9 hadoop hadoop 4096 Feb 22 06:05 elasticsearch-2.4.3
-rw-r–r–. 1 hadoop hadoop 908862 Jan 10 11:38 elasticsearch-head-master.zip
-rw-r–r–. 1 hadoop hadoop 2228252 Jan 10 11:38 elasticsearch-kopf-master.zip
drwxr-xr-x. 10 hadoop hadoop 4096 Oct 31 17:15 hadoop-2.6.0
drwxr-xr-x. 15 hadoop hadoop 4096 Nov 14 2014 hadoop-2.6.0-src
drwxrwxr-x. 8 hadoop hadoop 4096 Nov 2 18:20 hbase-1.2.3
drwxr-xr-x. 8 hadoop hadoop 4096 Apr 11 2015 jdk1.7.0_79
drwxr-xr-x. 10 hadoop hadoop 4096 Nov 1 23:39 zookeeper-3.4.6
[hadoop@HadoopMaster app]$ rm apache-tomcat-7.0.73.tar.gz
[hadoop@HadoopMaster app]$ ll
total 3096
drwxrwxr-x. 9 hadoop hadoop 4096 Feb 25 19:18 apache-tomcat-7.0.73
drwxrwxr-x. 9 hadoop hadoop 4096 Feb 22 06:05 elasticsearch-2.4.3
-rw-r–r–. 1 hadoop hadoop 908862 Jan 10 11:38 elasticsearch-head-master.zip
-rw-r–r–. 1 hadoop hadoop 2228252 Jan 10 11:38 elasticsearch-kopf-master.zip
drwxr-xr-x. 10 hadoop hadoop 4096 Oct 31 17:15 hadoop-2.6.0
drwxr-xr-x. 15 hadoop hadoop 4096 Nov 14 2014 hadoop-2.6.0-src
drwxrwxr-x. 8 hadoop hadoop 4096 Nov 2 18:20 hbase-1.2.3
drwxr-xr-x. 8 hadoop hadoop 4096 Apr 11 2015 jdk1.7.0_79
drwxr-xr-x. 10 hadoop hadoop 4096 Nov 1 23:39 zookeeper-3.4.6
[hadoop@HadoopMaster app]$
第五步:重命名 tomcat 安装目录
[hadoop@HadoopMaster app]$ ll
total 3096
drwxrwxr-x. 9 hadoop hadoop 4096 Feb 25 19:18 apache-tomcat-7.0.73
drwxrwxr-x. 9 hadoop hadoop 4096 Feb 22 06:05 elasticsearch-2.4.3
-rw-r–r–. 1 hadoop hadoop 908862 Jan 10 11:38 elasticsearch-head-master.zip
-rw-r–r–. 1 hadoop hadoop 2228252 Jan 10 11:38 elasticsearch-kopf-master.zip
drwxr-xr-x. 10 hadoop hadoop 4096 Oct 31 17:15 hadoop-2.6.0
drwxr-xr-x. 15 hadoop hadoop 4096 Nov 14 2014 hadoop-2.6.0-src
drwxrwxr-x. 8 hadoop hadoop 4096 Nov 2 18:20 hbase-1.2.3
drwxr-xr-x. 8 hadoop hadoop 4096 Apr 11 2015 jdk1.7.0_79
drwxr-xr-x. 10 hadoop hadoop 4096 Nov 1 23:39 zookeeper-3.4.6
[hadoop@HadoopMaster app]$ mv apache-tomcat-7.0.73 tomcat-7.0.73
[hadoop@HadoopMaster app]$ ll
total 3096
drwxrwxr-x. 9 hadoop hadoop 4096 Feb 22 06:05 elasticsearch-2.4.3
-rw-r–r–. 1 hadoop hadoop 908862 Jan 10 11:38 elasticsearch-head-master.zip
-rw-r–r–. 1 hadoop hadoop 2228252 Jan 10 11:38 elasticsearch-kopf-master.zip
drwxr-xr-x. 10 hadoop hadoop 4096 Oct 31 17:15 hadoop-2.6.0
drwxr-xr-x. 15 hadoop hadoop 4096 Nov 14 2014 hadoop-2.6.0-src
drwxrwxr-x. 8 hadoop hadoop 4096 Nov 2 18:20 hbase-1.2.3
drwxr-xr-x. 8 hadoop hadoop 4096 Apr 11 2015 jdk1.7.0_79
drwxrwxr-x. 9 hadoop hadoop 4096 Feb 25 19:18 tomcat-7.0.73
drwxr-xr-x. 10 hadoop hadoop 4096 Nov 1 23:39 zookeeper-3.4.6
[hadoop@HadoopMaster app]$
第六步:进入 tomcat 安装目录,并初步认识下
[hadoop@HadoopMaster app]$ cd tomcat-7.0.73/
[hadoop@HadoopMaster tomcat-7.0.73]$ ll
total 116
drwxr-xr-x. 2 hadoop hadoop 4096 Feb 25 19:18 bin
drwxr-xr-x. 2 hadoop hadoop 4096 Nov 8 05:30 conf
drwxr-xr-x. 2 hadoop hadoop 4096 Feb 25 19:18 lib
-rw-r–r–. 1 hadoop hadoop 56846 Nov 8 05:30 LICENSE
drwxr-xr-x. 2 hadoop hadoop 4096 Nov 8 05:27 logs
-rw-r–r–. 1 hadoop hadoop 1239 Nov 8 05:30 NOTICE
-rw-r–r–. 1 hadoop hadoop 8965 Nov 8 05:30 RELEASE-NOTES
-rw-r–r–. 1 hadoop hadoop 16195 Nov 8 05:30 RUNNING.txt
drwxr-xr-x. 2 hadoop hadoop 4096 Feb 25 19:18 temp
drwxr-xr-x. 7 hadoop hadoop 4096 Nov 8 05:29 webapps
drwxr-xr-x. 2 hadoop hadoop 4096 Nov 8 05:27 work
[hadoop@HadoopMaster tomcat-7.0.73]$
第七步:配置 tomcat 的环境变量和内存设置
在这里,虽然是在 CentOS 即,Linux 系统下,其实跟,windows 下的 tomcat 环境变量,配置大同小异。
Tomcat * 的安装和运行(绿色版和安装版都适用)
Tomcat 的配置文件详解
[hadoop@HadoopMaster tomcat-7.0.73]$ ll
total 116
drwxr-xr-x. 2 hadoop hadoop 4096 Feb 25 19:18 bin
drwxr-xr-x. 2 hadoop hadoop 4096 Nov 8 05:30 conf
drwxr-xr-x. 2 hadoop hadoop 4096 Feb 25 19:18 lib
-rw-r–r–. 1 hadoop hadoop 56846 Nov 8 05:30 LICENSE
drwxr-xr-x. 2 hadoop hadoop 4096 Nov 8 05:27 logs
-rw-r–r–. 1 hadoop hadoop 1239 Nov 8 05:30 NOTICE
-rw-r–r–. 1 hadoop hadoop 8965 Nov 8 05:30 RELEASE-NOTES
-rw-r–r–. 1 hadoop hadoop 16195 Nov 8 05:30 RUNNING.txt
drwxr-xr-x. 2 hadoop hadoop 4096 Feb 25 19:18 temp
drwxr-xr-x. 7 hadoop hadoop 4096 Nov 8 05:29 webapps
drwxr-xr-x. 2 hadoop hadoop 4096 Nov 8 05:27 work
[hadoop@HadoopMaster tomcat-7.0.73]$ cd bin
[hadoop@HadoopMaster bin]$ ll
total 792
-rw-r–r–. 1 hadoop hadoop 27100 Nov 8 05:29 bootstrap.jar
-rw-r–r–. 1 hadoop hadoop 13981 Nov 8 05:29 catalina.bat
-rwxr-xr-x. 1 hadoop hadoop 21646 Nov 8 05:29 catalina.sh
-rw-r–r–. 1 hadoop hadoop 1647 Nov 8 05:30 catalina-tasks.xml
-rw-r–r–. 1 hadoop hadoop 24283 Nov 8 05:29 commons-daemon.jar
-rw-r–r–. 1 hadoop hadoop 204944 Nov 8 05:29 commons-daemon-native.tar.gz
-rw-r–r–. 1 hadoop hadoop 2040 Nov 8 05:29 configtest.bat
-rwxr-xr-x. 1 hadoop hadoop 1922 Nov 8 05:29 configtest.sh
-rwxr-xr-x. 1 hadoop hadoop 7888 Nov 8 05:29 daemon.sh
-rw-r–r–. 1 hadoop hadoop 2091 Nov 8 05:29 digest.bat
-rwxr-xr-x. 1 hadoop hadoop 1965 Nov 8 05:29 digest.sh
-rw-r–r–. 1 hadoop hadoop 3430 Nov 8 05:29 setclasspath.bat
-rwxr-xr-x. 1 hadoop hadoop 3547 Nov 8 05:29 setclasspath.sh
-rw-r–r–. 1 hadoop hadoop 2020 Nov 8 05:29 shutdown.bat
-rwxr-xr-x. 1 hadoop hadoop 1902 Nov 8 05:29 shutdown.sh
-rw-r–r–. 1 hadoop hadoop 2022 Nov 8 05:29 startup.bat
-rwxr-xr-x. 1 hadoop hadoop 1904 Nov 8 05:29 startup.sh
-rw-r–r–. 1 hadoop hadoop 38202 Nov 8 05:29 tomcat-juli.jar
-rw-r–r–. 1 hadoop hadoop 391853 Nov 8 05:29 tomcat-native.tar.gz
-rw-r–r–. 1 hadoop hadoop 4021 Nov 8 05:29 tool-wrapper.bat
-rwxr-xr-x. 1 hadoop hadoop 5024 Nov 8 05:29 tool-wrapper.sh
-rw-r–r–. 1 hadoop hadoop 2026 Nov 8 05:29 version.bat
-rwxr-xr-x. 1 hadoop hadoop 1908 Nov 8 05:29 version.sh
[hadoop@HadoopMaster bin]$
Java_OPTS=”-Xms512m -Xmx1024m -Xss1024K -XX:PermSize=512m -XX:MaxPermSize=1024m”
export TOMCAT_HOME=/home/hadoop/app/tomcat-7.0.73
export CATALINA_HOME=/home/hadoop/app/tomcat-7.0.73
export JRE_HOME=/home/hadoop/app/jdk1.7.0_79/jre
export JAVA_HOME=/home/hadoop/app/jdk1.7.0_79
第八步:接下来修改一下 tomcat 端口号,进入 tomcat 的 conf 目录下,修改 server.xml 文件,通过 vim 命令打开文件后直接输入 /8080 检索到端口号的位置,进入编辑模式后修改端口号为 8081,如下图所示:
为什么这么做?因为,在 hadoop 和 spark 集群里,8080 端口是被占用了。同时,也是避免后续麻烦和忘记!
[hadoop@HadoopMaster tomcat-7.0.73]$ ll
total 116
drwxr-xr-x. 2 hadoop hadoop 4096 Feb 26 02:12 bin
drwxr-xr-x. 2 hadoop hadoop 4096 Nov 8 05:30 conf
drwxr-xr-x. 2 hadoop hadoop 4096 Feb 25 19:18 lib
-rw-r–r–. 1 hadoop hadoop 56846 Nov 8 05:30 LICENSE
drwxr-xr-x. 2 hadoop hadoop 4096 Nov 8 05:27 logs
-rw-r–r–. 1 hadoop hadoop 1239 Nov 8 05:30 NOTICE
-rw-r–r–. 1 hadoop hadoop 8965 Nov 8 05:30 RELEASE-NOTES
-rw-r–r–. 1 hadoop hadoop 16195 Nov 8 05:30 RUNNING.txt
drwxr-xr-x. 2 hadoop hadoop 4096 Feb 25 19:18 temp
drwxr-xr-x. 7 hadoop hadoop 4096 Nov 8 05:29 webapps
drwxr-xr-x. 2 hadoop hadoop 4096 Nov 8 05:27 work
[hadoop@HadoopMaster tomcat-7.0.73]$ cd conf/
[hadoop@HadoopMaster conf]$ ll
total 204
-rw——-. 1 hadoop hadoop 12257 Nov 8 05:30 catalina.policy
-rw——-. 1 hadoop hadoop 6322 Nov 8 05:30 catalina.properties
-rw——-. 1 hadoop hadoop 1394 Nov 8 05:30 context.xml
-rw——-. 1 hadoop hadoop 3288 Nov 8 05:30 logging.properties
-rw——-. 1 hadoop hadoop 6613 Nov 8 05:30 server.xml
-rw——-. 1 hadoop hadoop 1950 Nov 8 05:30 tomcat-users.xml
-rw——-. 1 hadoop hadoop 167655 Nov 8 05:30 web.xml
[hadoop@HadoopMaster conf]$ pwd
/home/hadoop/app/tomcat-7.0.73/conf
[hadoop@HadoopMaster conf]$
先按 Esc 键,再按 / 键,即可,输入 8080
<Connector port=”8080″ protocol=”HTTP/1.1″
connectionTimeout=”20000″
redirectPort=”8443″ />
改成
<Connector port=”8081” protocol=”HTTP/1.1″
connectionTimeout=”20000″
redirectPort=”8443″ />
最后输入 :wq 保存退出即可
第九步:接下来我们就可以尝试启动 tomcat 了,切换到 tomcat 安装目录下
输入 bin/startup.sh
[hadoop@HadoopMaster tomcat-7.0.73]$ bin/startup.sh
Using CATALINA_BASE: /home/hadoop/app/tomcat-7.0.73
Using CATALINA_HOME: /home/hadoop/app/tomcat-7.0.73
Using CATALINA_TMPDIR: /home/hadoop/app/tomcat-7.0.73/temp
Using JRE_HOME: /home/hadoop/app/jdk1.7.0_79/jre
Using CLASSPATH: /home/hadoop/app/tomcat-7.0.73/bin/bootstrap.jar:/home/hadoop/app/tomcat-7.0.73/bin/tomcat-juli.jar
Tomcat started.
[hadoop@HadoopMaster tomcat-7.0.73]$
第十步:测试
适合于 CentOS 7.* 版本下对 tomcat 进行端口,由默认 8080 改为我们自行设置的 8081,为了避免跟 hadoop/spark 集群 8080 冲突
很遗憾无法访问,但是端口号并没有任何问题,这又是什么原因导致的呢?原因就是和 windows 相比 linux 有更强的安全机制,在 CentOS 7 中引入了一个更强大的防火墙——Firewall。我们需要在 Firewall 中开启 8081 端口,也就是将 8081 端口加入到 zone(Firewall 的新特性,简单讲它的作用就是定义了网络区域网络连接的可信等级)中。命令如下:
在 tomcat 的安装目录下的 bin 下,
需要使用 root 用户
firewall-cmd --zone=public --add-port=8081/tcp --permanent
这样就成功的将 8081 端口加入了 public 区域中,permanent 参数表示永久生效,即重启也不会失效,最后不要忘记更新防火墙规则:
firewall-cmd --reload
OK,下面看一下 public 区域下所有已打开的端口,命令如下:
firewall-cmd --zone=public --list-ports
适合于 CentOS 6.* 版本下对 tomcat 进行端口,由默认 8080 改为我们自行设置的 8081,为了避免跟 hadoop/spark 集群 8080 冲突(我的是这个)
[root@HadoopMaster bin]# pwd
/home/hadoop/app/tomcat-7.0.73/bin
[root@HadoopMaster bin]# cd
[root@HadoopMaster ~]# pwd
/root
[root@HadoopMaster ~]# /sbin/iptables -I INPUT -p tcp –dport 8081 -j ACCEPT # 开启 8081 端口
[root@HadoopMaster ~]# /etc/rc.d/init.d/iptables save # 保存配置
iptables: Saving firewall rules to /etc/sysconfig/iptables:[OK]
[root@HadoopMaster ~]# /etc/rc.d/init.d/iptables restart # 重启防火墙
iptables: Setting chains to policy ACCEPT: filter [OK]
iptables: Flushing firewall rules: [OK]
iptables: Unloading modules: [OK]
iptables: Applying firewall rules: [OK]
[root@HadoopMaster ~]#
也许,当里面改为之后,并不能马上出现界面,重启 CentOS6.5 即可。
更多 Tomcat 相关教程见以下内容:
CentOS 6.6 下安装配置 Tomcat 环境 http://www.linuxidc.com/Linux/2015-08/122234.htm
RedHat Linux 5.5 安装 JDK+Tomcat 并部署 Java 项目 http://www.linuxidc.com/Linux/2015-02/113528.htm
Tomcat 权威指南(第二版)(中英高清 PDF 版 + 带书签) http://www.linuxidc.com/Linux/2015-02/113062.htm
Tomcat 安全配置与性能优化 http://www.linuxidc.com/Linux/2015-02/113060.htm
Linux 下使用 Xshell 查看 Tomcat 实时日志中文乱码解决方案 http://www.linuxidc.com/Linux/2015-01/112395.htm
CentOS 64-bit 下安装 JDK 和 Tomcat 并设置 Tomcat 开机启动操作步骤 http://www.linuxidc.com/Linux/2015-01/111485.htm
CentOS 6.5 下安装 Tomcat http://www.linuxidc.com/Linux/2015-01/111415.htm
Tomcat 中 session 的管理机制 http://www.linuxidc.com/Linux/2016-09/135072.htm
Tomcat 的详细介绍:请点这里
Tomcat 的下载地址:请点这里
本文永久更新链接地址:http://www.linuxidc.com/Linux/2017-03/141349.htm