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就好用。原來,從ubuntu10.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 *:*
$
現在好了。
參考 http://alanjiang.iteye.com/blog/737563
對於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的集成,感興趣就搜一下吧。
參考
http://xuejiayue.iteye.com/blog/88370
http://www.cnblogs.com/gnorts/archive/2010/11/24/1886771.html
本文出自 “An old newbie” 博客,請務必保留此出處http://panblack.blog.51cto.com/2980687/941044