码迷,mamicode.com
首页 > 其他好文 > 详细

Install Tomcat 7 On Centos orRHEL6

时间:2015-08-14 13:33:43      阅读:103      评论:0      收藏:0      [点我收藏+]

标签:

Step 1: Install JDK 1.7
我们使用rpm包
    配置环境变量
    [root@plweb 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

    [root@plweb ~] source /etc/profile
    [root@plweb 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

     [root@plweb 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

标签:

原文地址:http://www.cnblogs.com/ylion/p/4729612.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!