(3) deployment of the Linux environment (Centos + Nginx + Tomcat + Mysql)-deployment of the Nginx Environment
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
(3) Nginx Environment Construction
I,Install environment package
1. First, use the yum command to install and upgrade the required library. Nginx configuration and operation require support from software packages such as pcre, zlib, and openssl. Therefore, devel should be installed in advance to provide the corresponding library and header files, ensure that Nginx installation is successful. Before installing nginx, make sure that the system has installed g ++, gcc, openssl-devel, pcre-devel, and zlib-devel.
[Root @ localhost/] # yum-y install gcc-c ++
[Root @ localhost/] # yum-y install zlib-devel openssl-devel pcre-devel
Ii. Install nginx
Official Nginx Website: http://nginx.org/
Install nginx in yum Mode
1. Check whether the system has installed Nginx.
[Root @ localhost/] # find-name nginx
2. Install the latest stable version of nginx yum source. The latest version of Nginx yum source is in the epel rpm package. Download and install wget.
[Root @ localhost ~] # Cd/root
[Root @ localhost ~] # Wget-Ohttp: // response
(If the wget tool is not installed, run the following command to install it: [root @ localhost ~] # Yum-y install wget)
[Root @ localhost ~] # Rpm-ivh nginx-release-centos-6-0.el6.ngx.noarch.rpm // install by path and display progress
3. Install nginx
[Root @ localhost ~] # Yum installnginx
4. Start and test nginx
[Root @ localhost ~] # Service nginxrestart
There are two processes after Nginx is started. The master is the master process and the worker is the worker process.
After NGINX is started, you can enter http: // localhost in the browser to view welcometo nginx.
Install nginx using tar
Upload or wgethttp: // nginx.org/download/nginx-1.6.3.tar.gzdownload A tarpackage to /usr/local
Add the users and groups that execute Nginx first (this step is not required for yum)
Groupadd nginx
Useradd-g nginxnginx-s/bin/false
Cd/usr/local/src
Tar zxvfnginx-1.6.2.tar.gz
Cd nginx-1.6.2
[Root @ localhostlocal] # tar-zxf nginx-1.6.3.tar.gz
[Root @ localhostlocal] # nginx-1.6.3 cd
[Root@localhostnginx-1.6.3] #./configure -- prefix =/usr/local/nginx -- user = nginx -- group = nginx -- with-http_stub_status_module
(Equivalent to: # useradd-s/sbin/nologinnginx
# Chown-R nginx: nginx/usr/local/tomcat7)
[Root @ localhost nginx-1.6.3] # make & make install
[Root @ localhostsbin] # ln-s/usr/local/nginx/sbin/*/usr/local/sbin to create a soft link
Note: Before configuration, see./configure -- help for instructions.
-- Prefix: Set the Nginx installation directory
-- User and-group: Specify the Nginx running user and group
-- With-http_stub_status_module: enables the http_stub_status_module module to support status statistics
Nginx is installed in/usr/local/nginx by default.
3. Start and Stop nginx
1. Check the configuration file: [root @ localhost conf] # nginx-t
Similar to the apache main program httpd, The Nginx Main Program also provides the "-t" option to check the configuration file to find out improper or wrong configuration. The configuration file nginx. conf is located in the conf/subdirectory under the installation directory by default. To check the configuration file located elsewhere, use the "-c" option to specify the path.
2. Start and Stop nginx: [root @ localhost conf] # nginx
Run nginx directly to start the Nginx server. In this way, the default configuration file is used. To use another configuration file, you need to add the "-c configuration file path" option to specify the path. It should be noted that if other WEB service software such as httpd has been installed on the server, measures should be taken to avoid conflict.
[Root @ localhost conf] # netstat-anpt | grep nginx
[Root @ localhost ~] # Netstat-na | grep 80
If the access fails, check the Firewall Configuration:
Configure Firewall
# Modify the Firewall Configuration:
[Root @ uniquengles] # vi +/etc/sysconfig/iptables
# Add configuration items
-AINPUT-m state -- state NEW-m tcp-p tcp -- dport 80-j ACCEPT
# Restart firewall and Network Configuration
[Root @ uniquengstart] # service iptables restart
[Root @ uniquengstart] #/etc/init. d/network restart
In this way, the nginx web service can be accessed through port 80.
Others:
[Root @ localhost sbin] # nginx-v (nginx Version)
[Root @ localhost sbin] # which nginx (see where to start)
/Usr/sbin/nginx start
/Usr/sbin/nginx-s stop turn off/stop
[Root @ unique sbin] #/usr/local/nginx/sbin/nginx-s reload restart Linux
Ps-ef | grep "nginx: master process" | grep-v "grep" | awk-F ''' {print $2} 'check the main program number.
When the Nginx process is running, the PID Number is stored in nginx in the logs/directory by default. pid file, so stop linux if you use the kill command, you can also use nginx. pid number in the PID file for control.
[Root @ localhost/] # killall-9 nginx
# Querying the nginx master process number
Ps-ef | grepnginx
# Stop a process
Kill-QUIT master process number
# Quick Stop
Kill-TERM master process number
# Force stop
Pkill-9 nginx
3. Configure auto-start Nginx upon startup
Here we use the method of writing shell scripts for processing.
Vi/etc/init. d/nginx (create a new file and enter the following code ):
#! /Bin/bash
# Nginx Startup script for the Nginx HTTP Server
# It is v.0.0.2 version.
# Chkconfig:-85 15
# Description: Nginx is a high-performance web and proxy server.
# It has a lot of features, but it's not for everyone.
# Processname: nginx
# Pidfile:/var/run/nginx. pid
# Config:/usr/local/nginx/conf/nginx. conf
Nginxd =/usr/local/nginx/sbin/nginx
Nginx_config =/usr/local/nginx/conf/nginx. conf
Nginx_pid =/var/run/nginx. pid
RETVAL = 0
Prog = "nginx"
# Source function library.
./Etc/rc. d/init. d/functions
# Source networking configuration.
./Etc/sysconfig/network
# Check that networking is up.
[$ {NETWORKING} = "no"] & exit 0
[-X $ nginxd] | exit 0
# Start nginx daemons functions.
Start (){
If [-e $ nginx_pid]; then
Echo "nginx already running ...."
Exit 1
Fi
Echo-n $ "Starting $ prog :"
Daemon $ nginxd-c $ {nginx_config}
RETVAL =$?
Echo
[$ RETVAL = 0] & touch/var/lock/subsys/nginx
Return $ RETVAL
}
# Stop nginx daemons functions.
Stop (){
Echo-n $ "Stopping $ prog :"
Killproc $ nginxd
RETVAL =$?
Echo
[$ RETVAL = 0] & rm-f/var/lock/subsys/nginx/var/run/nginx. pid
}
# Reload nginx service functions.
Reload (){
Echo-n $ "Reloading $ prog :"
# Kill-HUP 'cat $ {nginx_pid }'
Killproc $ nginxd-HUP
RETVAL =$?
Echo
}
# See how we were called.
Case "$1" in
Start)
Start
;;
Stop)
Stop
;;
Reload)
Reload
;;
Restart)
Stop
Start
;;
Status)
Status $ prog
RETVAL =$?
;;
*)
Echo $ "Usage: $ prog {start | stop | restart | reload | status | help }"
Exit 1
Esac
Exit $ RETVAL
: Wq save and exit
Set File Access Permissions:
Chmod a + x/etc/init. d/nginx (a + x ==> all user can execute all users can execute)
(Chmod 555/etc/init. d/nginx)
In this way, you can easily operate nginx on the console: view the current Nginx status, start Nginx, stop Nginx, and restart Nginx.
The nginx configuration file has also been modified. conf. You can also use the preceding command to reload the new configuration file and run it. You can add this command to rc. in the local file, nginx is started by default when it is started.
Vi/etc/rc. local
Add/etc/init. d/nginx start to save and exit. The next restart will take effect.
(You can also use the following method: chkconfig -- addnginx)