LNMP small distributed platform architecture building

LNMP small distributed platform architecture building

And a few friends recently tried to get together a small project site, as operation and maintenance engineers, the task would take the environment naturally fell on my shoulder because our project is still in the fantasy stage, so do not rent a server, we will open five or six sets of virtual machines on the computer to first build a good development environment.

For the future and our environment consistent line (say like really like to get on-line), the Cock decided to build a distributed development environment, due to the limited performance of this notebook Cock, so using five virtual machine to achieve the . The overall architecture is very simple, a front-end and front-end load balancing responsible for nginx forward, two back-end servers to install PHP as the application server. The remaining two servers as the database server and configuring master-slave synchronization. In addition, the Cock would like to set up memcached and redis nginx cached on the server, allowing users to cache as close as possible to improve the access speed (but not so engaged, do not know if flawed).

The next step is the configuration process, there is little need to mention, linux system I use is centos6.5, kernel version should be 2.3 (specifically not remember), it can be used to install software to use yum yum way way, do not I asked why not source way (way too much trouble because the source code, forgive me lazy bar).

Next, enter the formal build process, I will detail the recording process I built.

The first step, set the server host name, IP address, configure firewall (I direct off) and Selinux (I also directly off), Gateway, DNS.

nginx Host:

IP address: 10.60.77.200

Host Name: nginx

Gateway: 10.60.77.254

DNS:114.114.114.114

PHP-1 host:

IP address: 10.60.77.201

Host name: PHP-1

PHP-2 host:

IP address: 10.60.77.202

Host name: PHP-2

mysql-master host:

IP address: 10.60.77.203

Host Name: mysql-master

mysql-slave host:

IP address: 10.60.77.204

Host Name: mysql-slave

After all configuration is complete ping to see what Baidu network connectivity is normal. There is no problem to enter the second step.

The second step, the host installation configuration nginx

1, the installation source epel

http://mirrors.zju.edu.cn/epel/6/i386/epel-release-6-8.noarch.rpm

wKiom1Uqcq_TXowcAAXni5rnibY939.jpg

Yum install nginx official source:

http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm

wKioL1UqdDPhXKowAAX3qHvs0_E567.jpg

Install nginx:

[root@nginx ~]# yum -y install nginx

wKiom1Uqcw_D21rbAAdKN3hUZJo612.jpg

Nginx load balancing configuration, the request is forwarded PHP PHP-1 and a PHP-2 to the backend server. Php backend servers all use php-fpm listening 9000 port.

wKioL1UqdIWjeycbAAJmWBpig2A184.jpg

front.conf reads as follows:

server {

listen 80; // listening port

server_name www.zhy.com; // domain

access_log /var/log/nginx/zhy.access.log main;

location / {

  root  /var/www/html;       //网站根目录

  index index.html index.htm index.php;

}

error_page   500 502 503 504  /50x.html;

location = /50x.html {

    root  /usr/share/nginx/html;

}

location ~ \.php$ {

   root         /var/www/html;       //PHP文件根目录

   fastcgi_pass  all;          //转发池名称,连接将转发到该池中的地址

   fastcgi_index  index.php;

   fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;

   include        fastcgi_params;

}

}

upstream.conf content for:

upstream all {

   ip_hash;              //采用每按IP生成hash值,按hash分配到固定的后端服务器,解决session同步的问题

   server10.60.77.201:9000;

   server10.60.77.202:9000;

}

wKiom1Uqc1yB5alNAADsYbGeRWs467.jpg

fastcgi_params content for:

fastcgi_param QUERY_STRING $query_string;

fastcgi_param REQUEST_METHOD $request_method;

fastcgi_param CONTENT_TYPE $content_type;

fastcgi_param CONTENT_LENGTH $content_length;

fastcgi_param SCRIPT_NAME $fastcgi_script_name;

fastcgi_param REQUEST_URI $request_uri;

fastcgi_param DOCUMENT_URI $ document_uri;

fastcgi_param DOCUMENT_ROOT $document_root;

fastcgi_param SERVER_PROTOCOL $server_protocol;

fastcgi_param HTTPS $https if_not_empty;

fastcgi_param GATEWAY_INTERFACE CGI/1.1;

fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;

fastcgi_param REMOTE_ADDR $remote_addr;

fastcgi_param REMOTE_PORT $remote_port;

fastcgi_param SERVER_ADDR $server_addr;

fastcgi_param SERVER_PORT $server_port;

fastcgi_param SERVER_NAME $server_name;

fastcgi_param SCRIPT_FILENAME d O c in m e n t r O O t document_root fastcgi_script_name;

// Add this line content

PHP only, required if PHP was built with–enable-force-cgi-redirect

fastcgi_param REDIRECT_STATUS 200;

So far, nginx configuration basically completed, start nginx and set the boot from the start.

wKiom1Uqc4LQtvh4AAETj03pneU166.jpg

The third step is to deploy the application server PHP-1, PHP-2

PHP-1 and a PHP-2 are both exactly the same server, both servers use the same configuration, installation php, php-fpm, php-mysql on both servers. To install epel same source on two servers, the installation method nginx reference portion.

After installation epel source, using the following command to install php, php-fpm:

[root@PHP-1 ~]#yum -y install php php-fpm php-mysql

After installation is complete begin configuring php-fpm, configuration fpm monitor its own IP address and server settings allow nginx to listen, modify /etc/php-fpm.d/www.conf file to configure the following two lines:

listen = 10.60.77.201:9000

listen.allowed_clients= 10.60.77.200

This completes the basic configuration of the application server, ready to test php file to test the platform is in effect. On the application server under the web root directory (nginx configured in the web root / var / www / html) to create a index.php file, which reads as follows:

<Php phpinfo ();? Php user to display the file basic information, if properly displayed, the php function properly, if you can not show represents a configuration error. Normal display page is shown below: wKioL1UqdPugoJ3NAAXZZ28gUFs980.jpg At this point, the application server to build and test complete. A fourth step, the database server is set up and configure mysql master-slave synchronization. In the mounting step, exactly two servers, required to install mysql, mysql-server software is two, arranged in the main mysql synchronization needs to be configured separately from, so the installation process to a server, for example: [root @ mysql-master ~] # yum -y after install mysql mysql-server wKioL1UqdSbSLv25AAHmfFZYNeA738.jpg installation is completed, a master-slave synchronization mysql configuration, the first configuration mysql-master server: modifying /etc/my.cnf mysql service profile, the file follows: [ mysqld] datadir = / var / lib / mysql socket = / var / lib / mysql / mysql.sock user = mysql log_bin // open binlog log sync_binlog = 1 // allow sync binlog log server_id = 203 // set serverid, this id should be unique within # Disabling symbolic-links is recommendedto prevent assorted security risks symbolic-links = 0 [mysqld_safe] log-error = / var / log / mysqld.log pid-file = / var / run / mysqld / mysqld network. pid start mysql service and change the root password to log on locally mysql database: wKiom1UqdAWiUkrkAAFVayWybe0959. jpg [root @ mysqlmaster ~] # mysqladmin -urootpassword "mysqlmaster" // modify the local login as root mysql database password for the "msyqlmaster" change password, use the new password database, to synchronize authorization from the server: wKioL1UqdYGgsjxjAAJLeKSRV-Y568 username .jpg wKioL1UqdaWzLGkdAACLt6ddIC8287.jpg authorized 10.60.77.204 binlog can sync logs on the master server, and set the synchronization when using slaveuser, the password is slavepass. View binlog log file name currently in use as well as its bit offset: wKioL1UqdcyDFzFTAAGIHYrDKxI774.jpg results show the current master binlog file server using mysqld-bin.000001, the current position offset is 567, so far, mysql-master configuration is complete, exit the database and begin configuring slave server. A fifth step of the configuration server mysql-slave, the slave mysql modified configuration file as follows: [mysqld] datadir = / var / lib / mysql socket = / var / lib / mysql / mysql.sock user = mysql log_bin // Open log binlog sync-binlog = 1 // allow sync binlog log server_id = 204 // serverid read_only = 1 // set the read-only, no write operation # Disabling symbolic-links is recommendedto prevent assorted security risks symbolic-links = 0 [mysqld_safe] log-error = / var / log / mysqld.log pid-file = / var / run / mysqld / mysqld. After the setup is complete pid start mysql service and set the boot from the start wKiom1UqdMWggRBCAAFIs0dsdd8495.jpg modified using the local root login password for the database "mysqlslave", login mysql server settings master server: wKioL1UqdjnDxb6RAALUXArEocY767.jpg wKiom1UqdQvT9OLYAAIv0WhgDlY963.jpg After setup is complete, start synchronization and synchronize View status: wKiom1UqdTmzX8AvAAcTH9rHzug134.jpg when Slave_IO_Running and Slave_SQL_Running state is yes, indicate slave had to work, so far, mysql master-slave synchronization completed structures. Once configured, log master server, the authorization for the authorization application server: wKiom1UqdV_wMrkbAAE7e9qCkWk916.jpg seventh step, master-slave synchronization test is successful, to test whether the application server can successfully connect to the database; create a database on the master server to see if the slave database synchronous created: master: wKioL1UqdtKC42pNAAEVQRpHySU718.jpg slave: wKioL1UqdwWB2uUoAAIvQV7lTFw070.jpg this point can be determined, the master-slave synchronization work properly. Create a connection to the database under the web root directory on the application server php file, database connection test is normal, PHP connect to the database file contents are as follows:? <Php $ link = mysql_connect ('10 .60.77.203: 3306 ',' php ', 'phpmysql'); // database even if ($ link) echo "database connection success!"; // prompts mysql_close when the success (); // shut database>? jpg modified using the local root login password for the database "mysqlslave", login mysql server settings master server: wKioL1UqdjnDxb6RAALUXArEocY767.jpg wKiom1UqdQvT9OLYAAIv0WhgDlY963.jpg After setup is complete, start synchronization and view the synchronization status: wKiom1UqdTmzX8AvAAcTH9rHzug134.jpg when Slave_IO_Running and Slave_SQL_Running state is yes, It represents the slave has been working, so far, mysql master-slave synchronization completed structures. Once configured, log master server, the authorization for the authorization application server: wKiom1UqdV_wMrkbAAE7e9qCkWk916.jpg seventh step, master-slave synchronization test is successful, to test whether the application server can successfully connect to the database; create a database on the master server to see if the slave database synchronous created: master: wKioL1UqdtKC42pNAAEVQRpHySU718.jpg slave: wKioL1UqdwWB2uUoAAIvQV7lTFw070.jpg this point can be determined, the master-slave synchronization work properly. Create a connection to the database under the web root directory on the application server php file, database connection test is normal, PHP connect to the database file contents are as follows:? <Php $ link = mysql_connect ('10 .60.77.203: 3306 ',' php ', 'phpmysql'); // database even if ($ link) echo "database connection success!"; // prompts mysql_close when the success (); // shut database>? jpg modified using the local root login password for the database "mysqlslave", login mysql server settings master server: wKioL1UqdjnDxb6RAALUXArEocY767.jpg wKiom1UqdQvT9OLYAAIv0WhgDlY963.jpg After setup is complete, start synchronization and view the synchronization status: wKiom1UqdTmzX8AvAAcTH9rHzug134.jpg when Slave_IO_Running and Slave_SQL_Running state is yes, It represents the slave has been working, so far, mysql master-slave synchronization completed structures. Once configured, log master server, the authorization for the authorization application server: wKiom1UqdV_wMrkbAAE7e9qCkWk916.jpg seventh step, master-slave synchronization test is successful, to test whether the application server can successfully connect to the database; create a database on the master server to see if the slave database synchronous created: master: wKioL1UqdtKC42pNAAEVQRpHySU718.jpg slave: wKioL1UqdwWB2uUoAAIvQV7lTFw070.jpg this point can be determined, the master-slave synchronization work properly. Create a connection to the database under the web root directory on the application server php file, database connection test is normal, PHP connect to the database file contents are as follows:? <Php $ link = mysql_connect ('10 .60.77.203: 3306 ',' php ', 'phpmysql'); // database even if ($ link) echo "database connection success!"; // prompts mysql_close when the success (); // shut database>? Jpg After the setup is complete, start synchronization and view the synchronization status: wKiom1UqdTmzX8AvAAcTH9rHzug134.jpg when Slave_IO_Running and Slave_SQL_Running state is yes, indicate slave had to work, so far, mysql master-slave synchronization completed structures. Once configured, log master server, the authorization for the authorization application server: wKiom1UqdV_wMrkbAAE7e9qCkWk916.jpg seventh step, master-slave synchronization test is successful, to test whether the application server can successfully connect to the database; create a database on the master server to see if the slave database synchronous created: master: wKioL1UqdtKC42pNAAEVQRpHySU718.jpg slave: wKioL1UqdwWB2uUoAAIvQV7lTFw070.jpg this point can be determined, the master-slave synchronization work properly. Create a connection to the database under the web root directory on the application server php file, database connection test is normal, PHP connect to the database file contents are as follows:? <Php $ link = mysql_connect ('10 .60.77.203: 3306 ',' php ', 'phpmysql'); // database even if ($ link) echo "database connection success!"; // prompts mysql_close when the success (); // shut database>? Jpg After the setup is complete, start synchronization and view the synchronization status: wKiom1UqdTmzX8AvAAcTH9rHzug134.jpg when Slave_IO_Running and Slave_SQL_Running state is yes, indicate slave had to work, so far, mysql master-slave synchronization completed structures. Once configured, log master server, the authorization for the authorization application server: wKiom1UqdV_wMrkbAAE7e9qCkWk916.jpg seventh step, master-slave synchronization test is successful, to test whether the application server can successfully connect to the database; create a database on the master server to see if the slave database synchronous created: master: wKioL1UqdtKC42pNAAEVQRpHySU718.jpg slave: wKioL1UqdwWB2uUoAAIvQV7lTFw070.jpg this point can be determined, the master-slave synchronization work properly. Create a connection to the database under the web root directory on the application server php file, database connection test is normal, PHP connect to the database file contents are as follows:? <Php $ link = mysql_connect ('10 .60.77.203: 3306 ',' php ', 'phpmysql'); // database even if ($ link) echo "database connection success!"; // prompts mysql_close when the success (); // shut database>? jpg seventh step, master-slave synchronization test is successful, to test whether the application server can successfully connect to the database; create a database on the master server to see if the synchronization is created in the slave database: master: wKioL1UqdtKC42pNAAEVQRpHySU718.jpg slave: wKioL1UqdwWB2uUoAAIvQV7lTFw070.jpg At this point, you can OK, master-slave synchronization to work. Create a connection to the database under the web root directory on the application server php file, database connection test is normal, PHP connect to the database file contents are as follows:? <Php $ link = mysql_connect ('10 .60.77.203: 3306 ',' php ', 'phpmysql'); // database even if ($ link) echo "database connection success!"; // prompts mysql_close when the success (); // shut database>? jpg seventh step, master-slave synchronization test is successful, to test whether the application server can successfully connect to the database; create a database on the master server to see if the synchronization is created in the slave database: master: wKioL1UqdtKC42pNAAEVQRpHySU718.jpg slave: wKioL1UqdwWB2uUoAAIvQV7lTFw070.jpg At this point, you can OK, master-slave synchronization to work. Create a connection to the database under the web root directory on the application server php file, database connection test is normal, PHP connect to the database file contents are as follows:? <Php $ link = mysql_connect ('10 .60.77.203: 3306 ',' php ', 'phpmysql'); // database even if ($ link) echo "database connection success!"; // prompts mysql_close when the success (); // shut database>?

Access the file via the web, indicates that the database connection is successful, "the database connection success" when the page is displayed.

So far, all the contents of this architecture is all set up is completed, the latter may also add some PHP modules, add some caching mechanism, such as memcached, redis what, these elements will be completed in the latter part of the article.

Published 100 original articles · won praise 12 · views 10000 +

Guess you like

Origin blog.csdn.net/hmh13548571896/article/details/103637111