liunx系统安装tomcat的方法

安装tomcat前需要先安装jdk,安装jdk的方法参考我的上一篇文章:liunx系统安装jdk的方法

 

1、下载tomcat

下载地址:http://tomcat.apache.org/download-60.cgi

我下载的是apache-tomcat-6.0.44.zip

 

2、安装tomcat

将下载的压缩包apache-tomcat-6.0.44.zip放到目录/usr/tomcat下
 
2.1、解压命令如下:
# unzip apache-tomcat-6.0.44.zip

2.2、编辑catalina.sh文件:

# cd /usr/tomcat/apache-tomcat-6.0.44/bin
# vi catalina.sh

在catalina.sh文件追加内容如下:

CATALINA_HOME=/usr/tomcat/apache-tomcat-6.0.44/

 

3、启动tomcat

# chmod +x *.sh
# ./catalina.sh start

 

4、测试tomcat是否已正常启动

访问 http://127.0.0.1:8080/,如果正常,说明tomcat服务已正常启动

 

5、打开防火墙的8080端口

默认系统防火墙开放了22端口,8080端口默认是关闭的,现在我们把tomcat默认使用的8080端口打开,否则远程访问是访问不了的

编辑/etc/sysconfig/iptables 文件(红色的内容是我添加的):

# Firewall configuration written by system-config-securitylevel
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
:RH-Firewall-1-INPUT - [0:0]
-A INPUT -j RH-Firewall-1-INPUT
-A FORWARD -j RH-Firewall-1-INPUT
-A RH-Firewall-1-INPUT -i lo -j ACCEPT
-A RH-Firewall-1-INPUT -p icmp --icmp-type any -j ACCEPT
-A RH-Firewall-1-INPUT -p 50 -j ACCEPT
-A RH-Firewall-1-INPUT -p 51 -j ACCEPT
-A RH-Firewall-1-INPUT -p udp --dport 5353 -d 224.0.0.251 -j ACCEPT
-A RH-Firewall-1-INPUT -p udp -m udp --dport 631 -j ACCEPT
-A RH-Firewall-1-INPUT -p tcp -m tcp --dport 631 -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 8080 -j ACCEPT
-A RH-Firewall-1-INPUT -j REJECT --reject-with icmp-host-prohibited
COMMIT

我在CentOS6还看到另外一个版本的:

# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 8080 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT

默认有了22的,照着原来的添加一行tomcat的端口就可以了。

 

编辑文件后,让防火墙策略生效:

# /etc/init.d/iptables restart
 
附:防火墙的相关命令
  1. 启动指令:service iptables start
  2. 重启指令:service iptables restart
  3. 关闭指令:service iptables stop
posted @ 2016-01-04 00:06  魔豆  阅读(268)  评论(0编辑  收藏  举报