32rwe111 发表于 2015-4-9 09:03:48

有效修改Tomcat6默认端口(Ubuntu Server,CentOS)

有效修改Tomcat6默认端口(Ubuntu Server,CentOS)

Ubuntu Server 12.04 安装tomcat6和mysql

$ sudo apt-get install sysv-rc-conf tomcat6 mysql-server
$ sudo ufw allow 80/tcp
$ sudo sysv-rc-conf tomcat6 on

修改tomcat端口,我们似乎都知道在这里把8080改成80:
$ sudo vi /etc/tomcat6/server.xml
    <Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               URIEncoding="UTF-8"
               redirectPort="8443" />

网上很多文章写到这里就完事了,但其实改完后tomcat根本不工作,TCP监听端口里没有80,而恢复到8080就好用。原来,从Ubuntu 10.04起,默认是关闭1024以下端口的,还需要修改以下文件:

$ sudo vi /etc/default/tomcat6
# If you run Tomcat on port numbers that are all higher than 1023, then you
# do not need authbind.It is used for binding Tomcat to lower port numbers.
# NOTE: authbind works only with IPv4.Do not enable it when using IPv6.
# (yes/no, default: no)
AUTHBIND=no
改成:AUTHBIND=yes

$ sudo service tomcat6 restart
$ ss -ln
State      Recv-Q Send-Q      Local Address:Port          Peer Address:Port
LISTEN   0      50                127.0.0.1:3306                     *:*   
LISTEN   0      100                     *:80                     *:*   
LISTEN   0      128                      :::22                      :::*   
LISTEN   0      128                     *:22                     *:*   
LISTEN   0      1               127.0.0.1:8005                     *:*   
$
现在好了。


对于CentOS6,是另一种情况,系统不允许tomcat用户使用1024以下的端口。所以除了修改 /etc/tomcat6/server.xml,还有这个文件:

# vi /etc/tomcat6/tomcat6.conf
# What user should run tomcat
TOMCAT_USER="tomcat"

# Connector port is 8080 for this tomcat6 instance
CONNECTOR_PORT="8080"

将上面两行改为
TOMCAT_USER="root"
CONNECTOR_PORT="80"

就可以了。但是这样做的安全性怎么样还不清楚,我觉得比较理想的是 Tomcat与Apache HTTPD的集成,感兴趣就搜一下吧。

页: [1]
查看完整版本: 有效修改Tomcat6默认端口(Ubuntu Server,CentOS)