preface

LNMP Distributed Cluster deployment Practice

  • Nginx+PHP Platform Construction and Load Balancing Configuration
  • (2) NFS File Server Setup and File Buffer Upload Configuration
  • (3) : Setup of MySQL Primary and Secondary Database Server
  • (4) : Memcached Server Construction
  • (5) ThinkPHP Project Deployment
  • Keepalived High Availability Solution (VI)

To review the basic architecture:

Now that we’ve basically set up the platform, it’s time to configure the environment necessary for the Web application to work on a cluster.

configuration

Project Download:

Link: pan.baidu.com/s/1mhPkx2S Password: rft8

7 create database and user

/usr/local/mysql/bin/mysql -uroot -p123456
CREATE DATABASE itshop;
GRANT USAGE ON *.* TO 'itshop'@'192.168.177.14' IDENTIFIED BY '123456';
GRANT USAGE ON *.* TO 'itshop'@'192.168.177.15' IDENTIFIED BY '123456';
GRANT ALL PRIVILEGES ON itshop.* TO 'itshop'@'192.168.177.14';
GRANT ALL PRIVILEGES ON itshop.* TO 'itshop'@'192.168.177.15';
FLUSH PRIVILEGES;
EXIT
Copy the code

Deployment projects 3, 4, and 5

Gz rm -rf /data/ WWW mv itshop-1.0 /data/ WWW chown -r WWW: WWW /data/ WWW ls /data/ WWWCopy the code

7 Import data

The curl -o data. SQL http://192.168.177.13/data.sql ll data. SQL/usr /local/mysql/bin/mysql -uroot -p123456
USE itshop;
source /root/data.sql
Copy the code

Configuration items 4 and 5

cd /data/www
rm -f data.sql
vi Application/Common/Conf/config.php
'DB_DEPLOY_TYPE'= > 1,# Distributed database support
'DB_RW_SEPARATE' => TRUE,  # read/write separation
'DB_TYPE'= >'MYSQL'.'DB_HOST'= >'192.168.177.17, 192.168.177.18'.'DB_NAME'= >'itshop'.'DB_USER'= >'itshop'.'DB_PWD'= >'123456'.'DB_PORT'= >'3306'.'DB_PREFIX'= >'shop_'.'DB_CHARSET'= >'utf8'.Copy the code

Testing:

http://192.168.177.11/?m=admin&c=login&a=index

No. 4 and 5 are equipped with single entrance

Configure the PATHINFO format for Nginx in the server block:

rewrite ^/index.php/(.*) /index.php? s=The $1 break;
location / {
    try_files $uri $uri/ /index.php? s=$uri;
}
location ~ \.(gif|jpg|jpeg|png|bmg|swf|xml|ico|css|js|map|txt)$ {
    expires 30d;
}
Copy the code

3, 4, and 5 configure sessions

When server PHP opens Session, every time it receives a request from a new client browser, it creates a Session file for that browser and stores it in the server. The file name is a string of automatically generated secret keys. The server uses set-cookie to send the secret keys back to the browser. The next request is sent with the secret key from the Cookie. The idea behind the site user login is to store the user ID in the Session file to identify the user for each request. If the Session file is not found in the key submitted by the browser, the user is not logged in.

If you use a server to store sessions locally, each server is different and cannot correctly identify the user. Therefore, we need two servers to share Session data, and Memcached is a good solution.

vi /data/www/.user.ini
session.save_handler = memcached
session.save_path = "192.168.177.19:11211"

service php-fpm reload
Copy the code

2. Upload the static file of the project

Tar -zxvf itshop-1.0.tar.gz cp -r itshop-1.0/Public /data/shareCopy the code

4, 5 configure directory path, upload and download separation

vi /data/www/Application/Common/Conf/config.php Configure template path, upload and download separation
'TMPL_PARSE_STRING' => array(
        '__PUBLIC__'= >'//file.itshop.test/Public'.'__UPLOAD_API__'= >'//upload.itshop.test/upload.php',),Copy the code

Note that we previously modified the hosts file on the localhost, such as vi /etc/hosts on my MacBook Pro:

Test 192.168.177.11 www.itshop.test 192.168.177.12 file.itshop.test 192.168.177.13 upload.itshop.testCopy the code

3 link upload directory, configure Nginx only upload

cd /data/www
rm -rf data.sql Public/Uploads
ln -s /data/share/Public/Uploads Public/Uploads  # link the NFS shared directory to the upload directory
chmod -R 777 Public/Uploads
vi /usr/local/nginx/conf/nginx.conf
location / {
        return 403;
    }
location /upload.php {  # replace the original ~ \.php$
        try_files $uri= 404; add_header Access-Control-Allow-Origin *;Add row allows cross-domain requests
        fastcgi_pass unix:/dev/shm/php-cgi.sock;
        include fastcgi.conf;
    }

service nginx reload
Copy the code

The performance test

Let’s do some additional performance tests here. Remember that the configuration of all nine VMS is the same:

Using the ApacheBench tool provided with Apache, the tool can send a large number of concurrent requests to a URL address from a single computer, and then detect how long it takes the server to respond to those requests and how many requests fail to process. So let’s test the concurrency of the cluster.

yum -y install httpd-tools
ab -c 500 -n 5000 http://itshop.test/
Copy the code

-c is Concurrency Level, which is the number of concurrent users. -n is the total number of requests. When the ab command is used, the error Too many open files is displayed because the number of open files in the system is limited. The MAC should come with Apache. Run the ulimit -a command to check the number of open files in the system. To change the number of open files to 1024, run the ulimit -n 1024 command. To view the result, run the ulimit -n command. ApacheBench(AB) stress testing tool

Apache JMeter has a software interface that is also good for stress and performance testing.

LNMP Distributed Cluster deployment Practice

  • Nginx+PHP Platform Construction and Load Balancing Configuration
  • (2) NFS File Server Setup and File Buffer Upload Configuration
  • (3) : Setup of MySQL Primary and Secondary Database Server
  • (4) : Memcached Server Construction
  • (5) ThinkPHP Project Deployment
  • Keepalived High Availability Solution (VI)

dffaceCopyright notice: All articles are valid unless otherwise statedCC BY – NC – SA 4.0License agreement. Reproduced please indicate the source, commercial use is strictly prohibited!