CentOS6 安裝Tomcat7

來源:互聯網
上載者:User

1:卸載掉內建的OpenJDK

2: 安裝 JDK1.6

3:安裝Tomcat

4: 配置Tomcat為daemon方式啟動

下面正式開工 :

 

=================================================== 

1:卸載掉內建的OpenJDK

2: 安裝 JDK1.6

 

 參考:

(外網)  http://www.cnblogs.com/sixiweb/archive/2012/11/25/2787684.html

 或之前一個page:

(內網)CentOS卸載系統內建的OpenJDK並安裝Sun的JDK的方法.

原文:

 

查看目前系統的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 JavaDBPreparing...                ########################################### [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 documentationProduct and system data will be collected. If your configurationsupports a browser, the JDK Product Registration form willbe presented. If you do not register, none of this informationwill be saved. You may also register your JDK later byopening the register.html file (located in the JDK installationdirectory) 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_37PATH=$JAVA_HOME/bin:$PATHCLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jarexport JAVA_HOMEexport PATHexport 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 tomcatJAVA_HOME=/usr/java/jdk1.6.0_37CATALINA_HOME=/usr/local/tomcatCATALINA_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/ipdables

在允許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/ 

 

為防止丟失,轉載過來:

 

在 CentOS6 上安裝 Tomcat7
  • linux 18
  • centos 1
  • tomcat 1
1. 下載
# wget http://mirror.bit.edu.cn/apache/tomcat/tomcat-7/v7.0.29/bin/apache-tomcat-7.0.29.tar.gz 
2. 安裝
# tar -xzvf apache-tomcat-7.0.29.tar.gz # mv apache-tomcat-7.0.29 /opt/tomcat7 # cd /opt/tomcat7 # bin/startup.sh 
3. 配置

在生產環境用 root 是不安全的,所以

# useradd -s /sbin/nologin tomcat # chown -R tomcat:tomcat /opt/tomcat7 

做為 service,和作業系統一起啟動

# cd /opt/tomcat7/bin # tar -xzvf commons-daemon-native.tar.gz # cd commons-daemon-1.0.10-native-src/unix # ./configure # make # cp jsvc ../.. # cd ../.. 

在 daemon.sh 的注釋後邊,本文最開始增加下邊五行內容

# vim daemon.sh ---- # chkconfig: 2345 10 90 # description: Starts and Stops the Tomcat daemon. JAVA_HOME=/usr/java/jdk1.6.0_31 CATALINA_HOME=/opt/tomcat7 CATALINA_OPTS="-Xms1024m -Xmx2048m -XX:PermSize=256m -XX:MaxPermSize=512m" 

增加到 service

# cp daemon.sh /etc/init.d/tomcat # chkconfig --add tomcat 

檢查

# chkconfig --list|grep tomcat tomcat 0:關閉 1:關閉 2:啟用 3:啟用 4:啟用 5:啟用 6:關閉 

開啟連接埠

# vim /etc/sysconfig/iptables ---- -A INPUT -m state --state NEW -m tcp -p tcp --dport 8080 -j ACCEPT # service iptables restart 
Bati Zhao

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.