(4) deploying the Linux environment (Centos + Nginx + Tomcat + Mysql)-installing Tomcat and JDK and integrating Nginx with Tomcat

Source: Internet
Author: User

(4) deploying the Linux environment (Centos + Nginx + Tomcat + Mysql)-installing Tomcat and JDK and integrating Nginx with Tomcat

 

In my local testing practice, the following is a complete operating document for Centos + Nginx + Tomcat + Mysql on Linux. The record is as follows, we hope to give a systematic reference to programmers who want to build a Linux environment systematically. However, because most of the operations are recorded while being built, some omissions are inevitable. I still hope you will forgive me. If you have any questions or comments, please help me to point them out in the comments below. Thank you very much! In addition, many excellent practices on the Internet have been referenced during the entire construction process. They are marked at the end of the article or in other appropriate places. If necessary, you can refer to the reference link to read the reference Original article. This document consists of six parts and six articles:

1. (1) Linux environment deployment (Centos + Nginx + Tomcat + Mysql)-FTP Installation

2. (2) deploying the Linux environment (Centos + Nginx + Tomcat + Mysql)-firewall configuration

3. (3) deployment of the Linux environment (Centos + Nginx + Tomcat + Mysql)-deployment of the Nginx Environment

4. (4) Linux environment deployment (Centos + Nginx + Tomcat + Mysql)-install Tomcat and JDK and integrate Nginx with Tomcat

5. (5) Linux environment deployment (Centos + Nginx + Tomcat + Mysql)-Mysql Installation

6. (6) Linux environment deployment (Centos + Nginx + Tomcat + Mysql)-Summary of some common commands

 

 

 

(4) install Tomcat and JDK, and integrate Nginx with Tomcat

 

 

Install Tomcat and JDK

JDK: server-jre-7u75-linux-x64.gz

Tomcat: apache-tomcat-7.0.59.tar.gz

 

1. Upload apache-tomcat-7.0.59.tar.gzand server-jre-7u75-linux-x64.gz to/usr/local


2. Run the following command to install tomcat:

1. # cd/usr/local

2. # tar-zxvf apache-tomcat-7.0.59.tar.gz

After decompression, rename apache-tomcat-7.0.59 to tomcat 7.

3. Create a tomcat user to run the tomcat service:

Using root in the production environment is not safe, so:

# Useradd-s/sbin/nologin tomcat

# Chown-R tomcat: tomcat/usr/local/tomcat7


3. Run the following command to decompress and install JDK:

1. Check the current system's jdk, rpm-qa | grepjdk

Uninstall the built-in openjdk:

[Root @ localhost ~] # Yum-y remove java-1.7.0-openjdk-1.7.0.45-2.4.3.3.el6.x86_64

[Root @ localhost ~] # Yum-y remove java-1.6.0-openjdk-1.6.0.0-1.66.1.13.0.el6.x86_64

 

2. # tar-zxvf server-jre-7u75-linux-x64.gz

After decompression, rename the server-jre-7u75 to JDK 7

 

4. Configure environment variables:
Edit the profile file vi/etc/profile under/etc, and add the following content:

#JDKhomeJAVA_HOME="/usr/local/jdk7"CLASS_PATH="$JAVA_HOME/lib:$JAVA_HOME/jre/lib"PATH=".:$PATH:$JAVA_HOME/bin"#Tomcat homeCATALINA_HOME="/usr/local/tomcat7"export JAVA_HOME CATALINA_HOME

 

5. Set source/etc/profile to take effect. (Or #./etc/profile or # sh/etc/profile! Or # reboot command to restart Linux ),

Java-version: Check whether jdk is set successfully.

 

6. start tomcat: [root @ localhostbin] #/usr/local/tomcat7/bin/startup. sh

Enter http: // localhost: 8080. If the cat page is displayed, tomcat and jdk are successfully installed.


7. Create a new file directory/www as the website storage directory, set the server. xml file, and change the pointing path of appBase = to "/www" at Host name = "localhost"
8. Create index. jsp to/www/. The content is "My web !"

 

9. set to start Tomcat at startup

[Root @ localhost ~] # Vi/etc/init. d/tomcat (create a new file and enter the following code )#! /Bin/bash # tomcatd This shell script takes care of starting and stopping # standalone tomcat # chkconfig: 345 91 10 # description: tomcat service # processname: tomcatd # config file: # Source function library .. /etc/rc. d/init. d/functions # Source networking configuration .. /etc/sysconfig/network # Check that networking is up. [$ {NETWORKING} = "no"] & exit 0 prog = atatdexport JAVA_HOME =/usr/local/jdk7ex Port CATALINA_HOME =/usr/local/tomcat7PATH = $ PATH: $ JAVA_HOME/binSTARTUP = $ CATALINA_HOME/bin/startup. shSHUTDOWN = $ CATALINA_HOME/bin/shutdown. shif [! -F $ CATALINA_HOME/bin/startup. sh] thenecho "CATALINA_HOME for tomcatd not available" exitfistart () {# Start daemons. echo-n $ "startend tomcat service:" daemon $ STARTUPRETVAL =$? Return $ RETVAL} stop () {# Stop daemons. echo-n $ "Stoping tomcat service:" $ SHUTDOWNRETVAL =$? Return $ RETVAL} # See how we were called. case "$1" instart) start; stop) stop; restart | reload) stopstartRETVAL =$ ?;; Status) status $ progRETVAL =$ ?;; *) Echo $ "Usage: $0 {start | stop | restart | status}" exit 1 esacexit $ RETVAL

 

 

: Wq save and exit

Similarly, set the object ACL:

Chmod a + x/etc/init. d/tomcat (a + x ==> all user can execute all users can execute)

(Chmod 755/etc/init. d/tomcat (read/write execution by the current user, other read + execution ))

Similarly, add this command to the rc. local file, so that tomcat will be started by default at startup.

Vi/etc/rc. local

Add a/etc/init. d/tomcat start line to save and exit. The next restart will take effect.

(You can also use the following method: chkconfig -- add tomcat)

 

Refer:

Chmod755/etc/init. d/tomcat (read/write execution by the current user, other read + execution)

Chkconfig -- add tomcat

Chkconfigtomcat on

Chkconfig -- list tomcat

Display:

Tomcat 0: off1: off 2: on 3: on 4: on 5: on 6: off confirm 2 ~ 5. If the status is on, OK.

Start Tomcat:

Service tomcatstart

 

 

Nginx and Tomcat Integration

 

 

Tomcat configuration:

UnpackWARs = "true" autoDeploy = "true">

 

......

 

Edit Nginx. conf In the conf folder under the nginx installation directory

Server {listen 80; server_name localhost; index index.html index.htm index. jsp; # Set the default homepage address for access root/www/demon; # Set the website resource storage path # charset koi8-r; # access_log logs/host. access. log main; # location/{# root html; # index index.html index.htm; #} location ~ . *. Jsp $ {# All jsp pages are processed by tomcat index. jsp; proxy_pass http: // localhost: 8080; # Switch to tomcat for processing} location ~ . * \. (Gif | jpg | jpeg | png | bmp | swf) $ # Set to directly read static files without passing through tomcat {expires 30d;} location ~ . * \. (Js | css )? $ {Expires 1 h ;}..............}

 

Restart tomcat

[Root @ localhost abc] # service tomcatrestart

Restart nginx

[Root @ localhost abc] # service nginx restart

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.