LNMP implements nginx, php, and mysql separation based on fastcgi

Source: Internet
Author: User
Tags mcrypt php download

 

In normal times, LNMP is installed on the same machine. I think this is not a challenge for everyone. Next we will remove them to different machines, to allow servers to directly share the original pressure, you can also add nodes to achieve load balancing. For example, you can add one more php server and allow the two servers to poll and compile the php server. You can also add an nginx server, implement dns round-robin load balancing.

Plan: nginx: 172.16.1.1 php (FASTCGI): 172.16.1.2 mysql: 172.16.1.3 environment: redhat 5.8 32-bit, yum can be used normally, the Development package group "Development Tools" "Development Libraries" "X Software Development" has been installed. If not, install it first. Make sure SElinux is disabled. Disable iptables first. Procedure: 1. Compile and install nginx in 172.16.1.11. Install pcre-devel first. The rewrite function of nginx depends on the library provided by pcre. # Yum-y install pcre-devel 2. create users for nginx for secure operation, the reason for specifying uid is to facilitate permission sharing with php through nfs # groupadd-r-g 5000 nginx # useradd-r-g nginx-u 5000 nginx 3. download and compile nginx # wget http://www.nginx.org/download/nginx-1.2.4.tar.gz# Tar xvf nginx-1.2.4.tar.gz # cd nginx-1.2.4 #. /configure \ -- prefix =/usr \ -- sbin-path =/usr/sbin/nginx \ -- conf-path =/etc/nginx. conf \ -- error-log-path =/var/log/nginx/error. log \ -- http-log-path =/var/log/nginx/access. log \ -- pid-path =/var/run/nginx. pid \ -- lock-path =/var/lock/nginx. lock \-user = nginx \ -- group = nginx \ -- with-http_ssl_module \ -- with-http_flv_module \ -- with-http_stub_sta Tus_module \ -- with-http_gzip_static_module \ -- http-client-body-temp-path =/var/tmp/nginx/client/\ -- http-proxy-temp-path =/var/tmp/ nginx/proxy/\ -- http-fastcgi-temp-path =/var/tmp/nginx/fcgi/\ -- http-uwsgi-temp-path =/var/tmp/nginx/ uwsgi \ -- http-scgi-temp-path =/var/tmp/nginx/scgi \ -- with-pcre # the meaning of each option is not explained, if you need to understand it, go to google # make & make install 4. run the SysV init script to create a file/etc/rc for nginx. d/init. d/nginx, content As follows :#! /Bin/sh # nginx-this script starts and stops the nginx daemon # chkconfig:-85 15 # description: Nginx is an HTTP (S) server, HTTP (S) reverse \ # proxy and IMAP/POP3 proxy server # processname: nginx # config:/etc/nginx. conf # config:/etc/sysconfig/nginx # pidfile:/var/run/nginx. pid # Source function library .. /etc/rc. d/init. d/functions # Source networking configuration .. /etc/sysconfig/netwo Rk # Check that networking is up. ["$ NETWORKING" = "no"] & exit 0 nginx = "/usr/sbin/nginx" prog =$ (basename $ nginx) NGINX_CONF_FILE = "/etc/nginx. conf "[-f/etc/sysconfig/nginx] &. /etc/sysconfig/nginx lockfile =/var/lock/subsys/nginx make_dirs () {# make required directories user = 'nginx-V 2> & 1 | grep "configure arguments: "| sed's/[^ *] * -- user = \ ([^] * \). * // \ 1/G'-'Options = '$ nginx-V 2> & 1 | Grep 'configure arguments: ''for opt in $ options; do if ['echo $ opt | grep '. *-temp-path '']; then value = 'echo $ opt | cut-d" = "-f 2' if [! -D "$ value"]; then # echo "creating" $ value mkdir-p $ value & chown-R $ user $ value fi done} start () {[-x $ nginx] | exit 5 [-f $ NGINX_CONF_FILE] | exit 6 make_dirs echo-n $ "Starting $ prog: "daemon $ nginx-c $ NGINX_CONF_FILE retval =$? Echo [$ retval-eq 0] & touch $ lockfile return $ retval} stop () {echo-n $ "Stopping $ prog:" killproc $ prog-QUIT retval =$? Echo [$ retval-eq 0] & rm-f $ lockfile return $ retval} restart () {configtest | return $? Stop sleep 1 start} reload () {configtest | return $? Echo-n $ "Reloading $ prog:" killproc $ nginx-hup retval =$? Echo} force_reload () {restart} configtest () {$ nginx-t-c $ NGINX_CONF_FILE} rh_status () {status $ prog} rh_status_q () {rh_status>/dev/null 2> & 1} case "$1" in start) rh_status_q & exit 0 $1; stop) rh_status_q | exit 0 $1 ;; restart | configtest) $1; reload) rh_status_q | exit 7 $1; force-reload) force_reload; status) rh_status; condrestart | try-restart) rh_status_q | exit 0; *) ech O $ "Usage: $0 {start | stop | status | restart | condrestart | try-restart | reload | force-reload | configtest}" exit 2 esac: # chmod + x/etc/rc. d/init. d/nginx is added to the Service Management list and enabled automatically upon startup: # chkconfig -- add nginx # chkconfig nginx on start the service and test # service nginx start directly access 172.16.1.1 to check whether any welcome information of nginx is available. If yes, nginx installation is normal. 2. Deploy mysql-5.5.28 on 172.16.1.31. prepare a data directory for mysql and prepare a logical volume for mysql. download and install mysql. Here we use the compiled # wget http://cdn.mysql.com/Downloads/MySQL-5.5/mysql-5.5.28-linux2.6-i686.tar.gz# Tar xvf mysql-5.5.28-linux2.6-i686.tar.gz-C/usr/local/# cd/usr/local/# ln-sv mysql-5.5.24-linux2.6-i686 mysql # cd mysql # Change directory permissions # chown-R root: mysql. # scripts/mysql_install_db -- user = mysql -- datadir =/mydata/data 3. provide the configuration file # cd/usr/local/mysql # cp support-files/my-huge.cnf/etc/my for mysql. cnf and modify the value of thread_concurrency in this file to multiply the number of your CPUs by 2. For example, use the following line: thread_concurrency = 2 to add a row and specify the storage location of the mysql Data File: datadir =/Mydata/data 4. run the sysv init service script for mysql: # cd/usr/local/mysql # cp support-files/mysql. server/etc/rc. d/init. d/mysqld add to service list: # chkconfig -- add mysqld # chkconfig mysqld on Test start service mysqld start all normal mysql installation normal 5. output the mysql man manual to the man command search path: edit/etc/man. config, add the following line: MANPATH/usr/local/mysql/man 6. output the mysql header file to the system header file path/usr/include: this can be achieved through a simple creation link: # ln-sv/usr/local/mysql/include/usr/include/mysql 7. output m Ysql library file: # echo '/usr/local/mysql/lib'>/etc/ld. so. conf. d/mysql. conf and then let the system re-load the system database: # ldconfig-v 8. modify the PATH environment variable so that the system can directly use mysql-related commands. # Echo "export PATH = $ PATH:/usr/local/mysql/bin">/etc/profile. d/mysql. sh # source/etc/profile. d/mysql. sh 3. Compile and install php-5.4.8 on 172.16.1.21. install mysql on this machine, and use php. Otherwise, mysql cannot be connected. When discuz is installed, the system prompts that mysql_connect () is not supported, if you have a better solution, please leave me a message 2. to enable the compiled php to support mcrypt and mhash extensions, install the extension package: http://www.kuaipan.cn/file/id_33139203151757930.htmllibmcrypt-2.5.8-4.el5.centos.i386.rpmlibmcrypt-devel-2.5.8-4.el5.centos.i386.rpmmhash-0.9.9-1.el5.centos.i386.rpmmhash-devel-0.9.9-1.el5.centos.i386.rpmmcrypt-2.6.8-1.el5.i386.rpm 3. download and install the php-5.4.8 # php site today's speed is not free to fill the php download connection # tar xf php-5.4.8.tar.bz2 # cd php-5.4.8 #. /configure -- prefix =/usr/local/php -- with-mysql =/usr/local/mysql -- with-openssl -- enable-fpm -- enable-sockets -- enable-sysvshm -- -mysqli =/usr/local/mysql/bin/mysql_config -- enable-mbstring -- with-freetype-dir -- with-jpeg-dir -- with-png-dir -- with-zlib- dir -- with-libxml-dir =/usr -- enable-xml -- with-mhash -- with-mcrypt -- with-config-file-path =/etc -- with-config-file- scan-dir =/etc/php. d -- with-bz2 -- with-curl # make intall 4. provide the Sysv init script for php-fpm and the configuration file, and add it to the service list: # cp sapi/fpm/init. d. php-fpm/etc/rc. d/init. d/php-fpm # chmod + x/etc/rc. d/init. d/php-fpm # chkconfig -- add php-fpm # chkconfig php-fpm on provides the configuration file for php: # cp php. ini-production/etc/php. ini provides configuration file for php-fpm: # cp/usr/local/php/etc/php-fpm.conf.default/usr/local/php/etc/php-fpm.conf edit php-fpm configuration file: # vim/usr/local/php/etc/php-fpm.conf configure fpm related options for the values you need and enable the last line of the pid file as follows ): pid =/usr/local/php/var/run/php-fpm.pid # comment this item and modify pm. max_children = 50pm. start_servers = 5. min _spare_servers = 2. max_spare_servers = 8 then you can start php-fpm: # service php-fpm start ): # ps aux | grep php-fpm has basically been installed. Next we will integrate nginx and php and call mysql through php. Iv. Integrate nginx and phpModify nginx of 172.16.1.1 1. we plan to place the webpage under/www, create the directory, and modify the permission # mkdir/www # chown nginx: nginx/www 2. compile/etc/nginx. conf, comment out some options # Back up the original file location/{root/www; index before editing. php index.html index.htm;} location ~ \. Php $ {root/www; fastcgi_pass 172.16.1.2: 9000; fastcgi_index index. php; fastcgi_param SCRIPT_FILENAME/scripts $ fastcgi_script_name; include fastcgi_params;} 3. edit/etc/nginx/fastcgi_params and change it to the following content: GATEWAY_INTERFACE CGI/1.1; fastcgi_param SERVER_SOFTWARE nginx; fastcgi_param QUERY_STRING $ query_string; inclurequest_method $ REQUEST_METHOD; inclucontent_type $ content _ Type; Response CONTENT_LENGTH $ content_length; Response SCRIPT_FILENAME $ document_root $ response; Response SCRIPT_NAME $ response; required REQUEST_URI $ response; required DOCUMENT_URI $ document_uri; required DOCUMENT_ROOT $ document_root; SERVER_PROTOCOL $ server_protocol; fastcgi_param REMOTE_ADDR $ remote_addr; fastcgi_param REMOTE_PORT $ r Emote_port; fastcgi_param SERVER_ADDR $ server_addr; fastcgi_param SERVER_PORT $ server_port; fastcgi_param SERVER_NAME $ server_name; # Do not restart nginx first. Modify Php 4 on 172.16.1.2. to facilitate the establishment of nginx users by sharing files with nginx in the future # groupadd-r-g 5000 nginx # useradd-r-g nginx-u 5000 nginx 5. modify the php-fpm configuration file/usr/local/php/etc/php-fpm.conf # vim/usr/local/php/etc/php-fpm.conflisten = 172.16.1.2: 9000 # Listen to the physical NIC address, for other machines to call user = nginx # php-fpm run group = nginx user restart php-fpm # service php-fpm restart 6. download and decompress discuz and Change permissions # wget http://cn.wordpress.org/wordpress-3.4.2-zh_CN.tar.gz#tar Xvf wordpress-3.4.2-zh_CN.tar.gz # mv wordpress-3.4.2-zh_CN/www # chown-R nginx: nginx/www in/www build test. php as a test file # vim/www/test. php <? Phpphpinfo ();?> 7. start nfs and edit the configuration file for nginx mounting # vi/etc/exports/www 172.16.1.1 (rw) # service nfs start 8. mount/www # mount-t nfs 172.16.1.2 of 172.16.1.2 on 172.16.1.1:/www browser to open 172.16.1.1/test. php to check whether the Phpinfo () function can be normally called. If yes, continue. If not, find the cause 9. install the discuz browser, run 172.16.1.1/install, and modify Php as prompted. one of the ini options # vi/etc/php. inishort_open_tag = On 10. create data for discuz on 172.16.1.3 # mysql> create database discuz;> grant all on discuz. * to 'discuz' @ '172. 16.1.2 'identified by 'redhat';> flush privileges;> quit 11. continue to install discuz to access 172.16.1.1/install. Enter the mysql address with the created account and password as prompted. At this point, discuz should be able to be installed successfully.

This article from the "Free Linux, Share Linux" blog, please be sure to keep this source http://laoguang.blog.51cto.com/6013350/1057523

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.