CentOS下安装Tomcat并配置环境变量(改默认端口8080为8081)

分享在centos下安装Tomcat并配置环境变量(改默认端口8080为8081)的全过程,希望对大家有帮助。

成都创新互联公司专注为客户提供全方位的互联网综合服务,包含不限于网站设计、成都网站设计、袁州网络推广、重庆小程序开发、袁州网络营销、袁州企业策划、袁州品牌公关、搜索引擎seo、人物专访、企业宣传片、企业代运营等,从售前售中售后,我们都将竭诚为您服务,您的肯定,是我们最大的嘉奖;成都创新互联公司为所有大学生创业者提供袁州建站搭建服务,24小时服务热线:18980820575,官方网址:www.cdcxhl.com

第一步:下载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

connectionTimeout="20000"
redirectPort="8443" />

  改成

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冲突 (我的是这个)

  防火墙开放8081端口   增加8081端口到防火墙配置中,执行以下操作:

[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 ~]#

检验Tomcat安装运行 通过以下地址查看tomcat是否运行正常: http://192.168.80.0:8081/ 看到tomcat系统界面,说明安装成功!

  也许,当里面改为之后,并不能马上出现界面,重启CentOS6.5即可。

停止Tomcat [hadoop@HadoopMaster tomcat-7.0.73]$ bin/shutdown.sh          //停止tomcat  (参考)   
 至此,成功! 扩展学习   对于,在Linux下,安装tomcat的话,也可以,做高级别的设置,如,将tomcat作为服务进程开机启动。   同样,还有部署集群,以后再写!

分享题目:CentOS下安装Tomcat并配置环境变量(改默认端口8080为8081)
网页链接:http://www.shufengxianlan.com/qtweb/news19/106519.html

网站建设、网络推广公司-创新互联,是专注品牌与效果的网站制作,网络营销seo公司;服务项目有等

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联