Install Ngix services and cluster PHP, Tomcat under CentOS

Source: Internet
Author: User
Tags mcrypt php compiler php load balancing nginx server nginx reverse proxy

Install Ngix services and cluster PHP, Tomcat under CentOS
Resources: http://download.csdn.net/detail/attagain/7570597

One, Ngix dependent module installation
Ngix dependent modules are: pcre, zlib, OpenSSL, MD5/SHA1 (if the corresponding modules are not installed in the system, they need to be installed in the following ways)
1. Installing the Pcre module (8.35)
Official website: http://www.pcre.org/
installation command:
# Unzip Pcre-8.35.zip
# CD pcre-8.35
#./configure
# Make && make install
In a 64-bit Linux system, the location of Nginx search is lib64; therefore, a soft connection is required:
# ln-s/usr/local/lib/libpcre.so.1/lib64/
# ln-s/usr/local/lib/libpcre.so.1/lib/
# ln-s/usr/local/lib/libpcre.so.1/usr/local/lib64/
2. Installing the Zlib module (1.2.8)
Official website: http://www.zlib.net/
installation command:
# tar ZXVF zlib-1.2.8.tar.gz
# CD zlib-1.2.8
#./configure
# Make && make install
3. Installing the OpenSSL module (1.0.1h)
Official website: http://www.openssl.org/
installation command:
# tar ZXVF openssl-1.0.1h.tar.gz
# CD OPENSSL-1.0.1H
#./config
# Make && Install
Second, Nginx installation
1, installation Nginx (1.6.0)
Official website: http://nginx.org/
installation command:
# tar ZXVF nginx-1.6.0.tar.gz
# CD nginx-1.6.0
#./configure--prefix=/usr/local/nginx \
--WITH-OPENSSL=/USR/LOCAL/OPENSSL \
--with-http_stub_status_module
# Make && make install
The directory structure of Nginx after installation is complete:
[Email protected] nginx-1.6.0]# ll/usr/local/nginx/
Total 16
Drwxr-xr-x 2 root root 4096 June 14:42 conf
Drwxr-xr-x 2 root root 4096 June 14:42 html
Drwxr-xr-x 2 root root 4096 June 14:42 logs
Drwxr-xr-x 2 root root 4096 June 14:42 Sbin
2. Modify the listening port in the configuration file to ensure that it is not occupied by other programs
Modify configuration file:/usr/local/nginx/conf/nginx.conf
Modify Port: 80->9090
2.1. Set up a Linux firewall and open port 9090
Execute command:
#/sbin/iptables-i input-p TCP--dport 9090-j ACCEPT
Save Settings command:
#/etc/rc.d/init.d/iptables Save
To view the Port Open command:
#/etc/init.d/iptables status
Restart Firewall service
#/etc/rc.d/init.d/iptables Restart
3. Start and stop Nginx
A. Start command
#/usr/local/nginx/sbin/nginx
B, Stop the command
#/usr/local/nginx/sbin/nginx-s Stop
C, check the configuration file
#/usr/local/nginx/sbin/nginx-t-c/usr/local/nginx/conf/nginx.conf
D. View Nginx version and full version
#/usr/local/nginx/sbin/nginx–v
Nginx version:nginx/1.6.0
#/usr/local/nginx/sbin/nginx–v
Nginx version:nginx/1.6.0
Built by GCC 4.4.6 20110731 (Red Hat 4.4.6-3) (GCC)
Configure arguments:--prefix=/usr/local/nginx--with-openssl=/usr/local/openssl--with-http_stub_status_module
E. View Help
#/usr/local/nginx/sbin/nginx–h
Nginx version:nginx/1.6.0
Usage:nginx [-?HVVTQ] [-s signal] [-c filename] [-p prefix] [-g directives]

Options:
 -?,-h        : This help
 -v            : Show version and exit
 -v            : Show version and configure options then exit
 -t            : Test configuration and exit
 -q            : Suppress NON-ERROR messages during configuration testing
  -S signal    : Send signal to a master process:stop, quit, reopen, reload
 -P prefix & nbsp;  : Set prefix path (default:/usr/local/nginx/)
 -C filename  : Set configuration fil E (default:conf/nginx.conf)
 -G directives:set global directives out of configuration file
4,  nginx default page Polygons display
 

Three, Nginx reverse proxy tomcat Service
Nginx and Tomcat integration is very simple, just need to modify the nginx.conf configuration file, add the following information:

location/tspwebmanager/{
Index index.html;
Proxy_pass http://192.168.30.202:8001/TspWebManager/;
}

location/cnp_mserviceprocess/{
Index index.html;
Proxy_pass http://192.168.30.202:8001/CNP_MServiceProcess/;
}
Description
1. URL Regular expression
/tspwebmanager/,/cnp_mserviceprocess/, when the URL address of the Nginx server is requested, and the regular expression matches, the reverse proxy is followed by the rules in the current location.
2. Index
Default page
3, Proxy_pass
Reverse proxy address: Here is a pointer to another Tomcat service URL
The definition of URL, need to have certain rules, convenient nginx regular expression definition, parsing. The 2 location definitions in this example implement two different types of business services for Nginx reverse proxy on the other server.
Iv. Installing PHP and Oracle Client drive extensions
1. Install Oracle Client
A, Oracle Client Installation
Official website: http://www.oracle.com/technetwork/database/features/instant-client/index-097480.html
Download the following package:
oracle-instantclient-basic-10.2.0.5-1.x86_64.rpm
oracle-instantclient-devel-10.2.0.5-1.x86_64.rpm
To install the client:
# RPM-IVH oracle-instantclient-basic-10.2.0.5-1.x86_64.rpm
# RPM-IVH oracle-instantclient-devel-10.2.0.5-1.x86_64.rpm
B. Establish a soft connection to enable PDO_OCI to identify 64-bit clients
#ln-S/usr/include/oracle/10.2.0.5/client64//usr/include/oracle/10.2.0.5/client
# ln-s/usr/lib/oracle/10.2.0.5/client64//usr/lib/oracle/10.2.0.5/client
# ln-s/USR/INCLUDE/ORACLE/10.2.0.5//usr/include/oracle/10.2.0.3
# ln-s/USR/LIB/ORACLE/10.2.0.5//usr/lib/oracle/10.2.0.3
C. Configuring the Oracle Client Library
#echo "/usr/lib/oracle/10.2.0.5/client/lib/" >/etc/ld.so.conf.d/oracle_client.conf
#/sbin/ldconfig
D. Setting Client Environment parameters
# Vi/etc/profile
At the end of the configuration file, add the following configuration information:
Export Oracle_home=/usr/lib/oracle/10.2.0.5/client
Export ld_library_path=/usr/lib/oracle/10.2.0.5/client: $LD _library_path
Export nls_lang= "American_america. Al32utf8 "
Execute command, update configuration
# Source/etc/profile
2, Installation re2c-0.13.6.tar.gz
Website address: http://www.re2c.org/
# tar ZXVF re2c-0.13.6.tar.gz
# CD re2c-0.13.6
#./configure
# Make && make install
3. Install PHP Service
A. Install PHP Dependency Package
LIBXML2 libxml2-devel autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel zlib zlib-devel glibc GL Ibc-devel Glib2 Glib2-devel needs to be installed on its own.
B. Installing the MCrypt tool
Website address: http://sourceforge.net/projects/mcrypt/
http://sourceforge.net/projects/mhash/
Download the following 3 packages:
Libmcrypt-2.5.8.tar.gz
Mhash-0.9.9.9.tar.gz
Mcrypt-2.6.8.tar.gz
installation command:
Installing Libmcrypt
#tar-ZXVF libmcrypt-2.5.8.tar.gz
#cd libmcrypt-2.5.8
#./configure
#make && make Install

Installing Mhash
#tar-ZXVF mhash-0.9.9.9.tar.gz
#cd mhash-0.9.9.9
#./configure
#make && make Install
Installing MCrypt

#tar-ZXVF mcrypt-2.6.8.tar.gz
#cd mcrypt-2.6.8
#LD_LIBRARY_PATH =/usr/local/lib./configure
#make && make Install

C, install Libiconv (not required option)
Website address: http://www.gnu.org/software/libiconv/
# tar ZXVF libiconv-1.14.tar.gz
# CD libiconv-1.14
#./configure--prefix=/usr/local
# Make && make install

D. Install PHP Service
Website address: http://php.net/
# tar ZXVF php-5.5.13.tar.gz
# CD php-5.5.13
#./configure--prefix=/usr/local/php \
--WITH-LIBDIR=LIB64 \
--WITH-CONFIG-FILE-PATH=/USR/LOCAL/PHP/ETC \
--with-iconv-dir=/usr/local \
--with-jpeg-dir=/usr/local/jpeg \
--with-png-dir=/usr/local/libpng \
--with-freetype-dir=/usr/local/freetype \
--with-pcre-regex \
--with-zlib \
--WITH-BZ2 \
--with-curl \
--with-curlwrappers \
--with-libxml-dir \
--WITH-GD \
--with-zlib-dir \
--WITH-TTF \
--WITH-SNMP \
--enable-calendar \
--ENABLE-DBA \
--ENABLE-FTP \
--ENABLE-GD-NATIVE-TTF \
--enable-mbstring \
--ENABLE-PCNTL \
--enable-xml \
--enable-sockets \
--enable-zip \
--enable-bcmath \
--ENABLE-FPM \
--ENABLE-FASTCGI \
--enable-force-cgi-redirect \
--enable-safe-mode \
--enable-discard-path \
--disable-gd-jis-conv \
--disable-sqlite \
--disable-debug
Among them,--ENABLE-FPM is the necessary component for PHP and Nginx integration.
# make
#make Install
Note: Do not install too many extension options when compiling PHP in the early days, lest the upgrade will be troublesome later. If make is wrong, compile with the command made zend_extra_libs= '-liconv '. If some libraries fail to find an error, the actual library file already exists, not the system search path/lib,/usr/lib, which can be implemented in the following ways:
# vi/etc/ld.so.conf
Add at the end to search for a library path, such as:/usr/local/lib
Update Library Load Information:
# Ldconfig

4. Installing the PDO Extension
If the PHP compiler has the-DISABLE-PDO option, this step needs to be compiled, and in the php.ini configuration file, the extension=pdo_oci.so information needs to be added, whereas this step does not need to be done.
# Cd/home/lhj/php/php-5.5.13/ext/pdo
#/usr/local/php/bin/phpize
#./configure--with-php-config=/usr/local/php/bin/php-config \
--enable-pdo=shared
# Make && make install

5. Install oci8 Extension
Website address: Http://pecl.php.net/package/oci8
# tar ZXVF oci8-2.0.8.tgz
# CD oci8-2.0.8
#/usr/local/php/bin/phpize
#./configure--with-php-config=/usr/local/php/bin/php-config \
--with-oci8=instantclient,/usr/lib/oracle/10.2.0.3/client64/lib
# Make && make install

6. Install PDO_OCI Extension
Website address: Http://pecl.php.net/package/PDO_OCI
# tar ZXVF pdo_oci-1.0.tgz
# CD pdo_oci-1.0
#/usr/local/php/bin/phpize
#./configure--with-php-config=/usr/local/php/bin/php-config \
--with-pdo-oci=instantclient,/usr,10.2.0.3
# Make && make install

7,   Configuration extension
A,   Modify the php.ini configuration file
Add the following:
Extension_dir = "/usr/local/php/lib/php/extensions/"
; extension=pdo.so
extension=pdo_oci.so
extension=oci8.so
  Edit File upload maximum limit is 100M
Upload_max_filesize = 100M
B,   Create and modify the Php-fpm.conf profile
# cp Php-fpm.conf.default php-fpm.conf
  Open Epoll, log switches, env[ HOSTNAME] = $HOSTNAME Add the following environment information:
Env[oracle_home] = $ORACLE _home
Env[nls_lang] = $NLS _lang
8,   start PHP
Start
#/usr/local/php/sbin/php-fpm-c/usr/local/php/etc/php.ini-y/usr/local/php/etc/php-fpm.conf
Close
#kill -int ' cat/usr/local/php/var/run/php-fpm.pid '
Restart
#kill-usr2 ' cat/usr/local/php/var/run/php-fpm.pid '
Test configuration file
#/usr/local/php/sbin/php-fpm-c/usr/local/php/etc/php.ini-y/usr/local/php/etc/php-fpm.conf-t
v.   Configure local Nginx service, integrate PHP-FPM
to complete the deployment of the local Nginx according to the steps of the front Nginx installation. In the nginx.conf configuration file, add the following information:
        listen        9005;

        Location ~ \.php$ {
             root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  script_filename  $document _root/$fastcgi _script_name;
            include         Fastcgi_params;
       }
through the php-fpm extension, through the Fastcgi_pass protocol, Proxy PHP service, to achieve the full release of PHP. Nginx instead of Apache implements a common Web Proxy service.

Six, Nginx reverse proxy PHP Service
The reverse proxy for PHP services, similar to Tomcat's reverse proxy, adds the following information in the previous installation of the load Balancer Nginx server configuration file:
Location ~ \.php$ {
Proxy_pass http://192.168.30.202:9005;
}
To implement PHP load balancing processing, only in the regular expression of PHP type request recognition, the remaining work reverse proxy to the specific PHP Business Server processing.

Summary, Nginx can not only replace Apache, provide local Web proxy services, performance is far superior to Apache, can also be deployed independently, to achieve a variety of services reverse proxy and load balancing processing.

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.