Configure Tomcat on Linux installation and deploy Web Apps (environment build + Project Deployment) (reprint)

Source: Internet
Author: User

first, the preparation work 1, Java-version Check whether there is a Java environment, there is no need to install and configure to the environment Variable. 2, Download Tomcat package,: http://tomcat.apache.org/download-70.cgi can be downloaded locally after uploading to the server, you can also directly on the server using the wget command download, this case directly using the wget command download:

[email protected] ~]# wget http://apache.fayea.com/tomcat/tomcat-7/v7.0.77/bin/apache-tomcat-7.0.77.tar.gz

~ second, Install Tomcat1, new Tomcat storage Directory
[[email protected] ~]# mkdir /usr/local/tomcat
2. Copy the downloaded apache-tomcat-7.0.77.tar.gz to the Tomcat directory
[[email protected] ~]# cp apache-tomcat-7.0.77.tar.gz /usr/local/tomcat/
3. Enter the Tomcat directory and unzip the apache-tomcat-7.0.77.tar.gz
[[email protected] ~]# cd /usr/local/tomcat/[[email protected] tomcat]# tar -zxvf apache-tomcat-7.0.77.tar.gz
4. Enter the bin directory of the extracted Tomcat package and start Tomcat
[[email protected] tomcat]# cd /usr/local/tomcat/apache-tomcat-7.0.77/bin/[[email protected] bin]# ./catalina.sh start或:[[email protected] bin]# ./startup.sh
Note: the./catalina.sh start and./startup.sh all enable Tomcat. Stop Tomcat using./catalina.sh Stop Or./shutdown.sh. 5. The browser accesses and resolves the firewall problem. In the browser using IP for access (port default: 8080), http://192.168.0.111:8080, You can see the management interface of Tomcat. 192.168.0.111 is the IP address of the server, if it is not accessible, there may be a server firewall problem, 8080 port is blocked, so you need to open 8080 port, and save restart Firewall:
[[email protected] bin]# iptables  -I  INPUT  -p  tcp  --dport  8080  -j  ACCEPT  [[email protected] bin]# /etc/init.d/iptables  save[[email protected] bin]# /etc/init.d/iptables  restart
In the Server.xml configuration can modify the access port, <connector port= "8080" modified to 80 port, the browser can be accessed directly through http://192.168.0.111. 6, Configure the Tomcat account password permissions (login using the Web Management Interface) modify the configuration file under Tomcat Tomcat-users.xml
[[email protected] ~]# vim /usr/local/tomcat/apache-tomcat-7.0.77/conf/tomcat-users.xml
Add the following code to the Front:
<RoleRolename="tomcat"/><role rolename= "manager-gui"/><role rolename= " Admin-gui "/><role rolename= "manager-script"/><role rolename= "admin-script"/><user username= "tomcat" password= "tomcat" roles=" tomcat,manager-gui,admin-gui,admin-script,manager-script "/>      
Note: username and password are the account passwords required to login to the Tomcat admin Interface. : Wq Save quit, restart Tomcat browser Access: http://192.168.0.111:8080

You can manage deployed projects through the manager App. Clicking into the Manager App requires an account password, which is set. ~ three, Tomcat Configuration service and self-booting 1, Tomcat Configuration service new service Script:
[[email protected] ~]# vim /etc/init.d/tomcat
Add Script Content:
 #!/bin/bash# description: TOMCAT7 Start Stop restart# processname:tomcat7# chkconfig: 234 80catalina_home=/usr/local/tomcat/apache-tomcat-7.0.77 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;; *) echo " please use:tomcat {start | stop | restart} ';; esacexit 0         
: Wq Save Script. Execute the script to start, stop, and restart the Service. Start: Service Tomcat start stop: service Tomcat stop restart: service tomcat restart2, tomcat configuration boot from boot to chkconfig add Tomcat service Management
[[email protected] ~]# chkconfig --add tomcat
Set up Tomcat service Self-boot
[[email protected] ~]# chkconfig tomcat on
View Tomcat's Startup status
[[email protected] ~]# chkconfig --list | grep tomcat
The status is as Follows: [[email protected]~]# Chkconfig--list | grep tomcattomcat 0:off 1:off 2:on 3:on 4:on 5:on 6:off off Tomcat service self-booting: chkconfig tomcat off remove Tomcat service management on Chkconfig: CHK Config--del tomcat~ four, Deploy Web project (three Ways) 1, The first way: deploy the project to WebApps (not recommended) into the WebApps directory under tomcat, and create a new directory for the Web Project's home directory.
[[email protected] ~]# cd /usr/local/tomcat/apache-tomcat-7.0.77/webapps[[email protected] webapps]# mkdir sam[[email protected] webapps]# lsdocs  examples  host-manager  manager  ROOT  sam
The SAM directory is the project directory, and now the war copy of the Web project is packaged and extracted to the SAM Directory. Here I use the simplest answer index.html instead of the Web project War package as a Test.
[[email protected] sam]# lsindex.html
Browser access: http://192.168.0.111:8080/sam/index.html access to index.html in the SAM directory is not recommended, the project is not managed, and the link plus the project name is required for normal access. 2, The second way: modify the Server.xml file, Configure the virtual host to modify the Server.xml configuration under Tomcat conf
[[email protected] conf]# vim server.xml 
Adding the host node within the engine node
  "www.sam.com" > <valve Classname= "org.apache.catalina.valves.AccessLogValve" directory= "logs" Pre Fix= "www.sam.com_access_log" suffix= ". txt" Pattern= "%h%l%u%t"%r "%s%b"/> <context path=  "docbase="/home/sam/site/com.sam.www "/></host>            
Name= "www.sam.com": refers to the domain name to access, so you need to have sam.com this domain name, and map www.sam.com to the current server for normal access, local testing can modify the native host file to do mapping testing. Browser Access: http://www.sam.com:8080 can access the project UNDER/HOME/SAM/SITE/COM.SAM.WWW. Note: www.sam.com for my personal domain name, you need to register your own domain name, and do the corresponding IP mapping. If you are only testing locally, you can modify the host file for this computer to add a record: 192.168.0.111 www.sam.com, which maps web.sam.com access to the 192.168.0.111 server. 3, the third way: modify Server.xml and catalina, Configure the virtual Host. This way, I use web.sam.com this project as an Example. Modify the Server.xml configuration under Tomcat conf
[[email protected] conf]# vim server.xml 
Add a simple host node within the engine node: Wq save exit
<Host name="web.sam.com"></Host>
Enter the Catalina directory under Tomcat Conf
[[email protected] conf]# cd /usr/local/tomcat/apache-tomcat-7.0.77/conf/Catalina
New directory web.sam.com (same as the host name configured in SERVER.XML)
[[email protected] Catalina]# mkdir web.sam.com
Enter the web.sam.com directory and create a new Root.xml file to add the appropriate configuration Content.
[[email protected] Catalina]# cd web.sam.com/[[email protected] web.sam.com]# vim ROOT.xml
The Root.xml file adds the Following:
<?xml version= "1.0" encoding= "UTF-8"?><ContextPath= "docbase="/home/sam/site/ Com.sam.web "> <valve classname=< Span class= "hljs-string" > "org.apache.catalina.valves.AccessLogValve" directory= "logs/com.sam.web" prefix= web.sam.com_ Localhost_access_log. " suffix= ". txt" resolvehosts= "true" pattern= "%h%l%u%t" %r "%s%b"/>  </context>           

######: Wq Save Exit.

###### similarly, Create a new project Directory/home/sam/site/com.sam.web and extract the war package to the directory and restart Tomcat.

###### Browser Access: http://web.sam.com:8080, This time access to web.sam.com the content of this project, not www.sam.com Content.

###### of course, you need to add web.sam.com domain name mappings in sam.com domain management, or local tests need to modify the native host file, add records: 192.168.0.111 web.sam.com, Map the web.sam.com access to the 192.168.0.111 server.

#### ~

five, Configure static resource access, Configure the directory location of the network map configuration, you can directly access to the local resource files, without the need to access to specific Projects. 1, for the second deployment mode configuration (take www.sam.com Project as an example) modify the Server.xml configuration under Tomcat conf
[[email protected] conf]# vim server.xml 
In
  "www.sam.com" > <valve Classname= "org.apache.catalina.valves.AccessLogValve" directory= "logs" Prefix= "www.sam.com_access_log" suffix= ". txt" Pattern= "%h%l%u%t"%r "%s%b"/> <context path=  "docbase="/home/sam/site/com.sam.www "/> <Context Path = "/upload" docbase= "/home/sam/share/upload"/></host>            
You can get to this resource by/home/sam/share/upload storing the shared resource A.jpg browser access: http://www.sam.com:8080/upload/a.jpg. Description: after the above configuration, all http://www.sam.com:8080/upload requests under the www.sam.com domain name are intercepted and the corresponding resource files are sought directly from The/home/sam/share/upload shared Directory. such as Access: http://www.sam.com:8080/upload/a/b.txt, the request directly from The/home/sam/share/upload directory to find a directory, and look for a directory under the b.txt, and then directly return the Resource. So we just put the shared resources in the configured shared directory, we can directly access the corresponding resources through the domain Name. 2, for the third deployment mode configuration (take the Web.sam.com project as an Example) to modify the contents of the corresponding project directory in the Catalina Directory. Enter the Web.sam.com directory under Catalina
[[email protected] conf]# cd /usr/local/tomcat/apache-tomcat-7.0.77/conf/Catalina/web.sam.com
New File Upload.xml
[[email protected] web.sam.com]# vim upload.xml
Add Content:
<?xml version= "1.0" encoding= "UTF-8"?><ContextPath= "/upload" docbase= "/home/sam/share/ Upload "> <valve classname= "org.apache.catalina.valves.AccessLogValve" directory=" logs/com.sam.web_upload "prefix=" web.sam.com_ Upload_localhost_access_log. " suffix= ". txt" resolvehosts= "true" pattern= "%h%l%u%t" %r "%s%b"/> </context>           
: Wq Save launch, Restart Tomcat. You can get to this resource by/home/sam/share/upload storing the shared resource A.jpg browser access: http://www.sam.com:8080/upload/a.jpg.

Configure Tomcat on Linux installation and deploy Web Apps (environment build + Project Deployment) (reprint)

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.