Install Tomcat 7 On Centos orRHEL6

來源:互聯網
上載者:User

標籤:

Step 1: Install JDK 1.7
我們使用rpm包
    配置環境變數
    [[email protected] src]# vim /etc/profile    #在檔案末尾添加以下內容
      export JAVA_HOME=/usr/java/jdk1.7.0_79
      export JAVA_BIN=/usr/java/jdk1.7.0_79/bin
      export PATH=${JAVA_HOME}/bin:$PATH
      export CLASSPATH=.:${JAVA_HOME}/lib/dt.jar:${JAVA_HOME}/lib/tools.jar

    [[email protected] ~] source /etc/profile
    [[email protected] src]# java -version   #查看
    java version "1.7.0_79"
    Java(TM) SE Runtime Environment (build 1.7.0_79-b15)
    Java HotSpot(TM) 64-Bit Server VM (build 24.79-b02, mixed mode)

Step 2: Download and Unpack Tomcat 7.0.29 (or latest)
we will install Tomcat 7 under /usr/local

     [[email protected] src]# tar -xf apache-tomcat-7.0.62.tar.gz -C /us/local   #解壓到/usr/local
                 mv apache-tomcat-7.0.62 tomcat   #便於配置,防止路徑有空格報錯

Step 3: Configure Tomcat to Run as a Service.
     vim /etc/init.d/tomcat
And here is the script we will use
     #!/bin/bash 
     # description: Tomcat Start Stop Restart 
     # processname: tomcat 
     # chkconfig: 234 20 80 
     JAVA_HOME=/usr/java/jdk1.7.0_05 
     export JAVA_HOME 
     PATH=$JAVA_HOME/bin:$PATH 
     export PATH 
     CATALINA_HOME=/usr/share/apache-tomcat-7.0.29 
      
     case $1 in 
     start) 
     sh $CATALINA_HOME/bin/startup.sh 
     ;;  
     stop)    
     sh $CATALINA_HOME/bin/shutdown.sh 
     ;;  
     restart) 
     sh $CATALINA_HOME/bin/shutdown.sh 
     sh $CATALINA_HOME/bin/startup.sh 
     ;;  
     esac     
     exit 0 

Now, set the permissions for your script to make it executable:
     chmod 755 tomcat
     chkconfig --add tomcat
     chkconfig --level 2345 tomcat on
     chkconfig --list tomcat

Now ,let‘s test our script
     service tomcat start
     service tomcat stop
     service tomcat restart

We should review the Catalina.out log located at /usr/share/apache-tomcat-7.0.29/logs/catalina.out and check for any errors.
     more /usr/share/apache-tomcat-7.0.29/logs/catalina.out

Step 4: Configuring Tomcat Manager Access.
     vim /usr/local/tomcat/conf/tomcat-users.xml 
               <role rolename="manager-gui"/>
            <role rolename="admin-script"/>
            <role rolename="admin-gui"/>
            <user username="pls" password="pls" roles="manager-gui,admin-script,admin-gui" />


Step 5 (Oprtional): Manage Memory Usage Using JAVA_OPTS.
     vim /usr/local/tomcat/bin/catalina.sh
     just add this in the second line
          JAVA_OPTS="-Djava.awt.headless=true -Dfile.encoding=UTF-8
          -server -Xms4048m -Xmx4048m
          -XX:NewSize=512m -XX:MaxNewSize=512m -XX:PermSize=512m
          -XX:MaxPermSize=512m -XX:+DisableExplicitGC"

Step 6 (Optional): How to Run Tomcat using Minimally Privileged (non-root) User.


     groupadd tomcat
     useradd -g tomcat -d /usr/local/tomcat tomcat
     chown -Rf tomcat.tomcat /usr/local/tomcat

Step 7 (Optional): How to Run Tomcat on Port 80 as Non-Root User.
     To run services below port 1024 as a user other than root, you can add the following to your IP tables:
          iptables -t nat -A PREROUTING -p tcp -m tcp --dport 80 -j REDIRECT --to-ports 8080
          iptables -t nat -A PREROUTING -p udp -m udp --dport 80 -j REDIRECT --to-ports 8080

Install Tomcat 7 On Centos orRHEL6

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.