Install Tomcat 7 on Centos orRHEL6

Source: Internet
Author: User

Step 1:install JDK 1.7
We use RPM packages
Configuring Environment variables
[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'll 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 #便于配置 to prevent the path from having a space error

Step 3:configure Tomcat to Run as a Service.
Vim/etc/init.d/tomcat
And here is the script we'll 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 $ 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 error S.
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 on 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 non-root User.
To run services below Port 1024x768 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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.