轉自:http://www.cnblogs.com/sixiweb/archive/2012/11/26/2789458.htmlhtml
tomcat7下載主頁: http://tomcat.apache.org/download-70.cgi
下載:(core: tar.gz)
wget http://mirror.bit.edu.cn/apache/tomcat/tomcat-7/v7.0.47/bin/apache-tomcat-7.0.47.tar.gz
tar -zxvf apache-tomcat-7.0.47.tar.gz
mv apache-tomcat-7.0.47 /usr/share/tomcat7
而後能夠cd /usr/share/tomcat7 && bin/startup.sh &
更多來自:http://www.cnblogs.com/sixiweb/archive/2012/11/26/2789458.html
查看目前系統的jdk: rpm -qa | grep jdk
獲得的結果:
[root@dc-01 java]# rpm -qa | grep jdk
java-1.6.0-openjdk-1.6.0.0-1.45.1.11.1.el6.i686
卸載之:
[root@dc-01 java]# yum -y remove java-1.6.0-openjdk-1.6.0.0-1.45.1.11.1.el6.i686
等一段時間就Complete了。
下載Sun的JDK。我下載的是
jdk-6u37-linux-i586-rpm.bin
若是是64位系統的話,要下載:
jdk-6u37-linux-x64-rpm.bin
之類的64位專用的包
到/usr目錄下建立java目錄,將下載的文件放到/usr/java目錄下
先將這個文件變爲可執行文件(chmod 777) :
[root@dc-01 java]# chmod 777 jdk-6u37-linux-i586-rpm.bin
而後執行這個文件件進行安裝:
[root@dc-01 java]# ./jdk-6u37-linux-i586-rpm.bin
Unpacking...
Checksumming...
Extracting...
UnZipSFX 5.50 of 17 February 2002, by Info-ZIP (Zip-Bugs@lists.wku.edu).
inflating: jdk-6u37-linux-i586.rpm
inflating: sun-javadb-common-10.6.2-1.1.i386.rpm
inflating: sun-javadb-core-10.6.2-1.1.i386.rpm
inflating: sun-javadb-client-10.6.2-1.1.i386.rpm
inflating: sun-javadb-demo-10.6.2-1.1.i386.rpm
inflating: sun-javadb-docs-10.6.2-1.1.i386.rpm
inflating: sun-javadb-javadoc-10.6.2-1.1.i386.rpm
Preparing... ########################################### [100%]
1:jdk ########################################### [100%]
Unpacking JAR files...
rt.jar...
jsse.jar...
charsets.jar...
tools.jar...
localedata.jar...
plugin.jar...
javaws.jar...
deploy.jar...
Installing JavaDB
Preparing... ########################################### [100%]
1:sun-javadb-common ########################################### [ 17%]
2:sun-javadb-core ########################################### [ 33%]
3:sun-javadb-client ########################################### [ 50%]
4:sun-javadb-demo ########################################### [ 67%]
5:sun-javadb-docs ########################################### [ 83%]
6:sun-javadb-javadoc ########################################### [100%]
Java(TM) SE Development Kit 6 successfully installed.
Product Registration is FREE and includes many benefits:
* Notification of new versions, patches, and updates
* Special offers on Oracle products, services and training
* Access to early releases and documentation
Product and system data will be collected. If your configuration
supports a browser, the JDK Product Registration form will
be presented. If you do not register, none of this information
will be saved. You may also register your JDK later by
opening the register.html file (located in the JDK installation
directory) in a browser.
For more information on what data Registration collects and
how it is managed and used, see:
http://java.sun.com/javase/registration/JDKRegistrationPrivacy.html
Press Enter to continue.....
這個時候按一下回車。
出現Done .
至此安裝結束。
接下來配置JDK:
vi /etc/profile打開profile文件,在profile文件的末尾加上:
JAVA_HOME=/usr/java/jdk1.6.0_37
PATH=$JAVA_HOME/bin:$PATH
CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export JAVA_HOME
export PATH
export CLASSPATH
保存並關閉profile文件,執行source /etc/profile命令讓修改生效。
運行下java -version 看一下java版本 :
[root@dc-01 java]# java -version
java version "1.6.0_37"
Java(TM) SE Runtime Environment (build 1.6.0_37-b06)
Java HotSpot(TM) Client VM (build 20.12-b01, mixed mode, sharing)
[root@dc-01 java]#
================================================
至此,整個安裝過程完畢。
3:安裝Tomcat
下載apache-tomcat-7.0.33.tar.gz。解壓縮:
tar -xzvf apache-tomcat-7.0.33.tar.gz
將解壓縮後的文件夾拷貝到/usr/local/tomcat:
cp -R apache-tomcat-7.0.33 /usr/local/tomcat
進入tomcat目錄設置tomcat 的內存使用狀況及其餘配置:
cd /usr/local/tomcat/bin
vi daemon.sh
在正文開始的地方加入如下內容(注意將jdk等目錄結合本身的實際狀況進行修改) :
# chkconfig: 2345 20 80
# description: simple example to start tomcat
JAVA_HOME=/usr/java/jdk1.6.0_37
CATALINA_HOME=/usr/local/tomcat
CATALINA_OPTS="-Xms1024m -Xmx4096m -XX:PermSize=256m -XX:MaxPermSize=512m"
4: 配置Tomcat爲daemon方式啓動
將daemon.sh 拷貝到啓動目錄,安裝服務,測試服務:
先編譯安裝 commons-daemon :
先安裝gcc,由於編譯的時候要用到
yum install gcc
建立tomcat用戶,用來運行tomcat服務:
在生產環境用 root 是不安全的,因此
useradd -s /sbin/nologin tomcat
chown -R tomcat:tomcat /usr/local/tomcat
作爲 service,和操做系統一塊兒啓動
# tar -xzvf commons-daemon-native.tar.gz
# cd commons-daemon-1.0.10-native-src/unix
# ./configure
# make
# cp jsvc ../..
# cd ../..
cp daemon.sh /etc/init.d/tomcat
chmod 755 /etc/init.d/tomcat
chkconfig --add tomcat
chkconfig tomcat on
chkconfig --list tomcat
顯示:
tomcat 0:off 1:off 2:on 3:on 4:on 5:on 6:off ← 確認2~5爲on的狀態就OK
啓動Tomcat:
service tomcat start
增長防火牆配置,容許8080端口:
# vi /etc/sysconfig/iptables
在容許ssh的下面增長一條:
-A INPUT -m state --state NEW -m tcp -p tcp --dport 8080 -j ACCEPT
保存,重啓iptables服務 :
# service iptables restart
測試:
本機測試:
wget http://localhost:8080/
從其餘機器 測試:
瀏覽器中輸入 http://localhost:8080/
看看是否能打開網站。
=========================================
配置過程當中參考了一下博客:
http://batizhao.github.com/linux/2012/07/17/install-tomcat7-on-centos/