I haven't written some blogs for a long time. I just found my job. I had the honor to participate in the splitting project of my company's website in a few days. Today I wrote these things to familiarize myself with the source code installation process and to facilitate my memory.
650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/0515252a1-0.png "title =" split. PNG "alt =" 142042595.png"/>
Project name: database and application splitting
Project requirements: as the background database of the website is growing, the Query Process of the database is too slow, which affects the company's business index-based database optimization. Based on this situation, we propose to use data splitting to split the website. on average, databases are split into five sub-ends with the frontend and backend. Each sub-end has four servers. The operating system uses the lnmp architecture. This architecture is more stable and efficient than the IIS lnmp architecture to support website access. high traffic and high concurrency this architecture can ensure the stability of the company's business and facilitate subsequent business expansion, because this architecture may have single point of failure, no redundancy measures, it is recommended that the project achieve high server availability and distributed the Monitoring Project monitors the server and service status in real time.
Project functions: in this project, the database uses the mysql backend to use nginx + php + phpmyadmin to manage nginx backend requests for static pages at the front end and forward dynamic page requests. The backend php + nginx is responsible for processing dynamic page requests.
Version: nginx-1.1.5.tar.gz mysql-5.1.37.tar.gz php-5.5.3.tar.gz notice: all four machines turn off firewall selinux)
In this configuration document, the first database installation software is Mysql, the second is the background management and installation software is phpmyadmin + php + nginx, the third is nginx, and the fourth is nginx + php.
The first primary function is to provide database support. You only need to install the database and configure it as follows:
Cd/usr/src
Tar fzxv mysql-5.1.37.tar.gz
Cd mysql-5.1.37
Yum-y install gcc-c ++ autoconf libjpeg-devel libpng-devel freetype-devel libxml2 libxml2-devel zlib-devel glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses- devel curl-devel ssse2fsprogs e2fsprogs-devel krb5 krb5-devel libidn-devel openssl-devel openldap-devel nss_ldap openldap-clients openldap-servers ncurses-devel
. /Configure -- prefix =/usr/local/mysql -- localstatedir =/var/lib/mysql -- with-comment = Source -- with-server-suffix =-Community -- with-mysqld- user = mysql -- without-debug -- with-big-tables -- with-charset = utf8 -- with-collation = utf8_general_ci -- with-extra-charsets = all -- with-pthread -- enable- static -- enable-thread-safe-client -- with-client-ldflags =-all-static -- with-mysqld-ldflags =-all-static -- enable-handler er -- without-ndb- debug -- with-unix-socket-path =/usr/local/mysql/tmp/mysql. sock
Make & make install
Groupadd mysql
Useradd-M mysql-s/sbin/nologin-g mysql
Cp support-files/my-huge.cnf/etc/my. cnf
/Usr/local/mysql/bin/mysql_install_db -- user = mysql
Chown-R root. mysql/usr/local/mysql/
Echo "/usr/local/mysql/lib/mysql/">/etc/ld. so. conf
Ldconfig
/Usr/local/mysql/bin/mysqld_safe -- user = mysql &
Netstat-anpt | grep 3306
Cp support-files/mysql. server/etc/init. d/mysqld
Chmod + x/etc/init. d/mysqld
Chkconfig -- add mysqld
Chkconfig mysqld on
Service mysqld restart
Export PATH = $ PATH:/usr/local/mysql/bin/
Echo "PATH = $ PATH:/usr/local/mysql/bin">/etc/profile
Service mysqld restart
Mysql
> Use mysql
> Update user set password = PASSWORD ("abc-123") where user = "root ";
> Flush privileges;
> Quit
Service mysqld restart
Mysql-uroot-pabc-123
The second machine needs to provide the back-end database management function. Note that php needs to provide support for the mysqli module during compilation and also enable the support for php-fpm. As php5.3 and above already provide support for the Mysqli Module mysql native driver can be configured as follows as long as mysql-devel is installed in yum
Php Section
Groupadd nginx
Useradd nginx-g nginx
Cd/usr/src
Tar fzxv php-5.5.3.tar.gz
Cd php-5.5.3
Yum-y install libxml2-devel gcc automake autoconf libtool make gcc-c ++ mysql-devel
. /Configure -- prefix =/usr/local/php5 -- with-config-file-path =/usr/local/path5/etc/-- with-libxml-dir =/usr/local /libxml2/-- enable-fpm -- with-zlib-dir =/usr/local/lib -- enable-soap -- enable-sockets -- enable-bcmath -- enable-zip -- enable-e -mbstring = all -- with-mysql -- with-mysqli -- with-pdo-mysql
Make
Make test
Make install
/Usr/local/php5/bin/php-m view the module in php
Fastcgi --- Configuration
Cd/usr/local/php5/etc/
Cp php-fpm.conf.default php-fpm.conf
Vi php-fpm.conf
User = nginx
Group = nginx
(In the nginx/html directory, change the owner Group of the specific virtual directory to nginx and nginx to ensure that the PHP program code has read and write permissions on the directory .)
/Usr/local/php5/sbin/php-fpm startup
Restart fpm:
# Pkill php-fpm
#/Usr/local/php5/sbin/php-fpm
Add boot start:
# Echo "/usr/local/php5/sbin/php-fpm">/etc/rc. local
Nginx Section
Cd/usr/src
Tar fzxv nginx-1.1.5.tar.gz
Cd nginx-1.1.5
Yum-y install gcc openssl-devel pcre zlib-devel
. /Configure -- prefix =/usr/local/nginx -- pid-path =/var/run/nginx. pid -- lock-path =/var/lock/nginx. lock -- user = nginx -- group = nginx -- conf-path =/usr/local/nginx. conf -- error-log-path =/var/log/nginx/error. log -- http-log-path =/var/log/nginx/access. log -- with-pcre -- with-http_gzip_static_module -- with-http_stub_status_module
Make & make install
Vi/etc/init. d/nginx
#! /Bin/bash
Case "$1" in
Start)
/Usr/local/nginx/sbin/nginx 2>/dev/null
;;
Stop)
/Usr/local/nginx/sbin/nginx-s stop 2>/dev/null
;;
Restart)
/Usr/local/nginx/sbin/nginx-s reload 2>/dev/null
;;
Esac
Exit
Chmod 777/etc/init. d/nginx
Configure nginx to support php-fastcgi
Vi/usr/local/nginx. conf
Worker_processes 1;
Events {
Worker_connections 1024;
}
Http {
Include mime. types;
Default_type application/octet-stream;
Sendfile on;
Keepalive_timeout 65;
Server {
Root/usr/local/nginx/html;
Listen 80;
Server_name localhost;
Location /{
Root html;
Index index.html index. php;
}
Error_page 500 502 503 x.html;
Location =/50x.html {
Root html;
}
Location ~ \. Php $ {
Root html;
Fastcgi_pass 127.0.0.1: 9000;
Fastcgi_index index. php;
Fastcgi_param SCRIPT_FILENAME/usr/local/nginx/html $ fastcgi_script_name;
Include fastcgi_params;
}
}
}
Vi/usr/local/nginx/html/index. php
<? Php phpinfo ();?>
Copy the myadmin folder to the nginx html directory.
Http: // ip/myadmin
The phpmyadmin image is displayed.
The main function of the third machine is to respond to requests from static Web pages and to forward requests from php web pages as follows:
Groupadd nginx
Useradd nginx-g nginx
Yum-y install openssl-devel pcre zlib-devel gcc automake autoconf libtool make gcc-c ++
Cd/usr/src
Tar fzxv nginx-1.1.5.tar.gz
Cd nginx-1.1.5
. /Configure -- prefix =/usr/local/nginx -- pid-path =/var/run/nginx. pid -- lock-path =/var/lock/nginx. lock -- user = nginx -- group = nginx -- conf-path =/usr/local/nginx. conf -- error-log-path =/var/log/nginx/error. log -- http-log-path =/var/log/nginx/access. log -- with-pcre -- with-http_gzip_static_module -- with-http_stub_status_module
Make & make install
Vi/etc/init. d/nginx
#! /Bin/bash
Case "$1" in
Start)
/Usr/local/nginx/sbin/nginx 2>/dev/null
;;
Stop)
/Usr/local/nginx/sbin/nginx-s stop 2>/dev/null
;;
Restart)
/Usr/local/nginx/sbin/nginx-s reload 2>/dev/null
;;
Esac
Exit
Chmod 777/etc/init. d/nginx
Configure nginx to support forwarding php requests
Vi/usr/local/nginx. conf
Location ~ \. Php $ {
Proxy_pass http: // IP address of the fourth Server
}
The fourth machine is mainly configured to parse requests on the php page as follows:
Nginx Section
Groupadd nginx
Useradd nginx-g nginx
Yum-y install gcc openssl-devel pcre zlib-devel gcc automake autoconf libtool make gcc-c ++
Cd/usr/src
Tar fzxv nginx-1.1.5.tar.gz
Cd nginx-1.1.5
. /Configure -- prefix =/usr/local/nginx -- pid-path =/var/run/nginx. pid -- lock-path =/var/lock/nginx. lock -- user = nginx -- group = nginx -- conf-path =/usr/local/nginx. conf -- error-log-path =/var/log/nginx/error. log -- http-log-path =/var/log/nginx/access. log -- with-pcre -- with-http_gzip_static_module -- with-http_stub_status_module
Make & make install
Vi/etc/init. d/nginx
#! /Bin/bash
Case "$1" in
Start)
/Usr/local/nginx/sbin/nginx 2>/dev/null
;;
Stop)
/Usr/local/nginx/sbin/nginx-s stop 2>/dev/null
;;
Restart)
/Usr/local/nginx/sbin/nginx-s reload 2>/dev/null
;;
Esac
Exit
Chmod 777/etc/init. d/nginx
Configure nginx to support php-fastcgi
Vi/usr/local/nginx. conf
Worker_processes 1;
Events {
Worker_connections 1024;
}
Http {
Include mime. types;
Default_type application/octet-stream;
Sendfile on;
Keepalive_timeout 65;
Server {
Root/usr/local/nginx/html;
Listen 80;
Server_name localhost;
Location /{
Root html;
Index index.html index. php;
}
Error_page 500 502 503 x.html;
Location =/50x.html {
Root html;
}
Location ~ \. Php $ {
Root html;
Fastcgi_pass 127.0.0.1: 9000;
Fastcgi_index index. php;
Fastcgi_param SCRIPT_FILENAME/usr/local/nginx/html $ fastcgi_script_name;
Include fastcgi_params;
}
}
}
Php configuration
Cd/usr/src
Tar fzxv php-5.5.3.tar.gz
Cd php-5.5.3
Yum-y install libxml2-devel
. /Configure -- prefix =/usr/local/php5 -- with-config-file-path =/usr/local/path5/etc/-- with-libxml-dir =/usr/local /libxml2/-- enable-fpm -- with-zlib-dir =/usr/local/lib -- enable-soap -- enable-sockets -- enable-bcmath -- enable-zip -- enable-e -mbstring = all
Make
Make test
Make install
/Usr/local/php5/bin/php-m view the module in php
Fastcgi --- Configuration
Cd/usr/local/php5/etc/
Cp php-fpm.conf.default php-fpm.conf
Vi php-fpm.conf
User = nginx
Group = nginx
(In the nginx/html directory, change the owner Group of the specific virtual directory to nginx and nginx to ensure that the PHP program code has read and write permissions on the directory .)
/Usr/local/php5/sbin/php-fpm startup
Restart fpm:
# Pkill php-fpm
#/Usr/local/php5/sbin/php-fpm
Add boot start:
# Echo "/usr/local/php5/sbin/php-fpm">/etc/rc. local
This article is from the "Alibaba taotao" blog and will not be reposted!