In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/03 Report--
Through the LAMP platform deployment and applications can be deployed to the LAMP platform to face client requests, but because these components are installed on a server, if there is a problem, it will lead to the paralysis of the LAMP platform. In the real environment, it is impossible to deploy all LAMP platforms on the same server, which requires the use of LAMP static and dynamic separation technology.
Blog outline:
I. the related concepts of LAMP dynamic and static separation.
The working mode of 1.PHP
The working mechanism of 2.FastCGI mode
Second, realize the static and dynamic separation of LAMP.
Compile and install php in 1.FastCGI mode
two。 Set up Apache and configure to call php through fastcgi protocol
Set up Mysql database
4.ab stress testing tool
5. Install php acceleration software Xcache
III. Deployment of Discuz Forum I. related concepts of LAMP dynamic and static separation
To achieve LAMP static and dynamic separation, the most important thing is PHP, because we need to use the PHP interpreter to parse the dynamic page, and then transmit the parsed site content to the Web server. Let's focus on PHP.
The working mode of 1.PHP
There are three modes in which PHP works in a LAMP environment:
CGI mode: running PHP in this mode, the performance is not very good; apache module: running PHP in this mode, deployment and applications on the LAMP platform are using this mode, using apache to call php to complete the work; FastCGI mode: running PHP,PHP in this mode is an independent process, and all PHP child processes are managed by a component called php-fpm of PHP; the working mechanism of 2.FastCGI mode
The preferred client initiates a request, which is generally divided into two types: one is a static request, which can directly return the resources required by the client by the Apache response Another dynamic request, which contains script interpretation language such as PHP or Perl, is called by the Apache server through the fastcgi protocol to the php server and returned to Apache, and the Apache returns the resources required by the client to the client. If the operation on the data is involved in this process, the php server will also call the mysql server through the mysql protocol. As shown in the figure:
Second, realize the static and dynamic separation of LAMP.
Case requirements:
One httpd server (192.168.1.1) compiles and installs httpd service; one mysql server (192.168.1.2) compiles and installs mysql service; one php server (192.168.1.3) compiles and installs php service; 1.FastCGI compiles and installs php
Get the required software packages for PHP
1) resolve dependencies [root@localhost ~] # yum-y install libxml2-devel lzip2-devel libcurl-devel\ libmcrypt-devel openssl-devel bzip2-devel / / dependency packages needed to install PHP programs [root@localhost ~] # tar zxf libmcrypt-2.5.7.tar.gz-C / usr/src [root@localhost ~] # cd / usr/src/libmcrypt-2.5.7/ [root@localhost libmcrypt-2.5.7] #. / configure-- prefix= / usr/local/libmcrypt & & make & & make install / / install libmcrypt package 2) compile and install php [root @ localhost ~] # tar zxf php-5.6.27.tar.gz-C / usr/src [root@localhost ~] # cd / usr/src/php-5.6.27/ [root@localhost php-5.6.27] #. / configure-- prefix=/usr/local/php5.6-- with-mysql=mysqlnd\-- with-pdo-mysql=mysqlnd-- With-mysqli=mysqlnd-- with-openssl-- enable-fpm-- enable-sockets\-- enable-sysvshm-- enable-mbstring-- with-freetype-dir-- with-jpeg-dir-- with-png-dir-- with-zlib\-- with-libxml-dir=/usr-- enable-xml-- with-mhash-with-mcrypt=/usr/local/libmcrypt\-- with-config-file-path=/etc-- with-config-file-scan-dir=/etc/php.d\-- with -bz2-- enable-maintainer-zts & & make & & make install
Explanation of configuration options:
-- prefix=/usr/local/php5.6 / / specify installation location;-- with-mysql=mysqlnd / / install connection mysql tool support mysql;--with-pdo-mysql=mysqlnd / / support Mysql pdo module-- with-mysqli=mysqlnd / / support mysqli module
Note: the role of the above three options: the database and php are not on the same server, specify this way, install the database connection driver;-- with-openssl / / support openssl module;-- enable-fpm / / support fpm mode;-- enable-sockets / / enable socket support;-- enable-sysvshm / / enable system shared memory support;-- enable-mbstring / / multi-byte string, like our Chinese is multi-byte string -- with-freetype-dir / / support freetype, need to install freetype-devel, font-related, font parsing tool-- with-jpeg-dir-- with-png-dir
Note: the function of the above two options: for dealing with jpeg and png images, php can dynamically generate jpeg images;-- with-zlib / / is a compression library that is used to compress and transmit when transmitting over the Internet;-- with-libxml-dir=/usr / / this libxml is used to parse xml;-- enable-xml / / supports xml;-- with-mhash / / supports the mhash;--with-mcrypt=/usr/local/libmcrypt / / libmcrypt-devel specified in this package. -- with-config-file-path=/etc / / specify the path where the configuration file is stored;-- with-config-file-scan-dir=/etc/php.d / / configuration file scan path;-- with-bz2 / / support BZip2 to support the worker or event MPM of apache, the-- enable-maintainer-zts option is used at compile time
If you are using a version above PHP5.3, you can specify mysqlnd in order to link to the MySQL database, so that you do not need to install MySQL or MySQL development packages on the machine first. Mysqlnd is available since php 5.3 and can be bound to it at compile time (without having to rely on specific MySQL client library bindings), but it has been the default since PHP 5.4
3) provide the php configuration file [root@localhost ~] # cp / usr/src/php-5.6.27/php.ini-production / etc/php.ini// copy the configuration file under the source code package to generate the php configuration file 4) create the php-fpm script [root@localhost ~] # cp / usr/src/php-5.6.27/sapi/fpm/init.d.php-fpm / etc/init.d/php-fpm// copy source code package The startup script [root@localhost ~] # chmod + x / etc/init.d/php-fpm [root@localhost ~] # chkconfig-- add php-fpm// is added as a system service It is not possible to start now, because the configuration file for php server has not been generated. 5) provide php-fpm configuration and edit [root@localhost ~] # cd / usr/local/php5.6/etc/ [root@localhost etc] # cp php-fpm.conf.default php-fpm.conf// the configuration file that was originally installed does not take effect, so you need to rename it (this is the configuration file for php-fpm) [root@localhost etc] # sed-I's # Pid = run/php-fpm.pid#pid = run/php-fpm.pid#g' php-fpm.conf// specify the location where the pid file is stored [root@localhost etc] # sed-I 's/listen = 127.0.0.1:9000/listen = 0.0.0.0 run/php-fpm.pid#g' php-fpm.conf// 9000amp g' php-fpm.conf// modify the listening address to all listening [root@localhost etc] # sed-I 's/pm.max_children = 5max pm.max.max The maximum number of sub-processes started by children = 50max g 'php-fpm.conf// modification is 50 [root@localhost etc] # sed-I' s/pm.start_servers = 2/pm.start_servers = 5; G 'php-fpm.conf// modification initial start processes is 5 [root@localhost etc] # sed-I' s/pm.min_spare_servers = 1/pm.min_spare_servers = 5max g 'php-fpm.conf// modification is the most The number of small free subprocesses is 5 [root@localhost etc] # sed-I 's/pm.max_spare_servers = 3/pm.max_spare_servers = 35. Modify the maximum free subprocess to 35 [root@localhost ~] # systemctl start php-fpm / / start the php service [root@localhost] # netstat-anpt | grep 9000 / / confirm that 9000 is listening for tcp 00. 0. 0. 0. 0. 0. 0. 0. * LISTEN 45563/php-fpm: mast
If the firewall is on, you need to do the following:
[root@localhost ~] # firewall-cmd-- permanent-- add-port=9000/tcp [root@localhost ~] # firewall-cmd-- reload / / allows TCP9000 access, reloaded to take immediate effect [root@localhost ~] # mkdir-p / var/www/benet// on this host, the new key virtual host directory is used to store web files 2. Set up Apache and configure to call php through fastcgi protocol
Refer to the installation of Apache to install Apache, which is skipped here. After the installation of Apache is complete, you need to do the following!
Since Apache 2.4, there has been a special module to implement FastCGI. This module is mod_proxy_fcgi.so, which is actually an extension of the mod_proxy.so module, so the following two modules need to be loaded:
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.soLoadModule proxy_module modules/mod_proxy.so
Do the following:
[root@localhost ~] # vim / usr/local/http-2.4.23/conf/httpd.conf// edits the main configuration file of httpd. / / omit part # LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so # LoadModule proxy_module modules/mod_proxy.so// remove the "#" sign in front of the module, enable the module # Include conf/extra/httpd-vhosts.conf / / remove the "#" number Enable virtual host configuration file to navigate to AddType: add the following line: AddType application/x-httpd-php .php / / Let apache recognize the php format page navigate to the following: DirectoryIndex index.php index.html / / add index.php [root@localhost ~] # vim / usr/local/http-2.4.23/conf/extra/httpd-vhosts.conf / / edit the virtual host configuration file for Apache before index.html Modify it to the following: ServerAdmin admin@admin.com DocumentRoot "/ var/www/benet" ServerName www.benet.com ServerAlias www.benet.com ErrorLog "logs/benet-error_log" CustomLog "logs/benet-access_log" common ProxyRequests Off / / close the forward agent ProxyPassMatch ^ / (. *\ .php (/. *)?) $fcgi:/ / 192.168.1.3:9000/var/www/benet/$1 Options FollowSymLinks / / disable directory traversal AllowOverride None / / allow request to be empty Require all granted / / allow all clients to access [root@localhost ~] # mkdir-p / var/www/benet [root@localhost ~] # systemctl restart httpd// after creating a virtual directory Restart the httpd service ProxyPassMatch ^ / (. *\ .php (/. *) $fcgi://192.168.1.3:9000/var/www/benet/$1 / / send the file request ending with .php to the php-fpm process. Php-fpm needs to know at least the directory and URI of the operator, so these two parameters are specified directly after fcgi://192.168.1.3:9000. The other parameters have been encapsulated by mod_proxy_fcgi.so and do not need to be specified manually. In particular, the directory path after the IP address needs to be the same as the path after DocumentRoot in. ProxyPassMatch matches and enforces this rule only for content that meets a specific regular pattern, where the pattern is ^ / (. *\ .php (/. *)?) $starts with the site (the root of the virtual host), matches any path that ends in .php, or follows one / followed by other content. The ^ (caret) and $(dollar) flags the beginning and end of the path to match () the contents in parentheses can be indicated by $1 to facilitate referencing it later. The proxy forwarded by fcgi:// 192.168.1.3 fastCGI 9000 via mod_proxy_fcgi, using the fastCGI protocol, goes to the port on which PHP-FPM listens. / path/to/your/documentroot/ is very important! Must match the path of the virtual host and must be the absolute path of the corresponding php file in the operating system. Otherwise, the file will not be found. $1 can be expanded from the original request to a variable of the entire request path, where it refers to the matching path (uri) in the preceding ().
Note: in versions prior to Apache httpd 2.4, PHP was either run as a module for Apache or a third-party module was added to support PHP-FPM implementation.
Create a test web page on the php server:
[root@localhost ~] # cat / var/www/benet/index.php
The access results are as follows:
Installing such a page means that Apache is ready to work with php
The above is to use the virtual host of Apache to call php-fpm to work, in fact, Apache itself can call php-fpm, there is no need to create a virtual host.
3. Set up Mysql database
As it takes a long time to compile and install the Mysql database, I provide the Mysql installation script and the required software to install in one minute (the default password for the mysql database account root is 123)!
After the installation is complete, do the following:
[root@localhost ~] # mysql-u root-p123mysql > grant all on *. * to lzj@'192.168.1.%' identified by '123456 create a database user and authorize mysql > exit
Fill in the test script on the php server:
[root@localhost ~] # cat / var/www/benet/test.php
Access to test:
Seeing this page means that Apache, PHP, and Mysql can work together!
4.ab stress testing tool
Network performance stress testing is an indispensable part in the process of server website performance tuning. Only when the server is under high pressure can the problems exposed by improper settings such as software and hardware be reflected.
The commonly used performance testing tools are: ab, http_load, webbench, siege. This blog post only introduces ab tools.
Ab is a stress testing tool that comes with Apache. Ab is very useful, it can not only conduct website access stress testing on apache servers, but also on other types of servers. For example: Nginx, Tomcat, IIS and so on.
(1) the principle of ab stress testing tool.
The ab command creates multiple concurrent access threads to simulate multiple visitors accessing a URL address at the same time. Its testing goal is based on URL, so it can test not only the load pressure of Apache, but also the pressure of other Web servers such as Nginx, Tomcat, IIS and so on.
The ab command requires very little of the computer that issues the load, and it takes up neither a high CPU nor a lot of memory. But it will cause a huge load on the target server. When testing, you need to pay special attention, otherwise too much load may be tested at one time, which may cause the target server to run out of resources and seriously lead to a panic.
(2) installation of ab stress testing tool
The installation of ab is very simple. If the source code package is used to install Apache, after Apache is installed, ab is stored in the bin directory of the Apache installation directory.
If you install Apache using yum, the ab command is stored in the / usr/bin directory by default
Note: if you don't want to install Apache and want to use the ab command, you need to install httpd-tools in the same way as yum.
To see if ab is installed successfully, you can do the following tests:
This is due to an error in the library location specified when installing openssl.
If the above situation occurs, the solution is as follows:
[root@localhost] # export LD_LIBRARY_PATH=/usr/local/openssl/lib/ Export the path of the desired module to the environment variable [root@localhost ~] # / usr/local/http-2.4.23/bin/ab-V / / so that you can use This is ApacheBench, Version 2.3 Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/Licensed to The Apache Software Foundation Parameters of http://www.apache.org/ (3) ab stress Test Command
There are two parameters commonly used in the ab command:
-n: the number of requests executed in the test session (total requests);-c: the number of requests generated at a time (that is, the number of concurrent users) [root@localhost ~] # cat / var/www/benet/index.htmliiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii// create the home file of Apache [root@localhost ~] # ab-c 500-n 10000 http://192.168.1.1/index.html// to test the Web server of 192.168.1.1 This is ApacheBench, Version 2.3 Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/Licensed to The Apache Software Foundation Http://www.apache.org/Benchmarking 192.168.1.1 (be patient) Completed 1000 requestsCompleted 2000 requestsCompleted 3000 requestsCompleted 4000 requestsCompleted 5000 requestsCompleted 6000 requestsCompleted 7000 requestsCompleted 8000 requestsCompleted 9000 requestsCompleted 10000 requestsFinished 10000 requestsServer Software: Apache/2.4.23Server Hostname: 192.168.1.1Server Port: 80Document Path: / index.html / / requested resource name Document Length: 34 bytes / / response data body length Concurrency Level: 500 / / concurrent number Time taken for tests: 1.727 seconds / / time spent processing these requests Complete requests: 10000 / / number of successful requests completed Failed requests: 0 / / failed requests Number of requests Total transferred: 2780000 bytes / / Total response data length of all requests HTML transferred: 340000 bytes / / Total body data of requests Requests per second: 5788.87 [# / sec] (mean) / / Throughput-requests per second (calculation formula: number of requests / user waiting time) the greater the throughput, the better Time per request: 86.373 [ Ms] (mean) / / average user wait time (calculated as user wait time / (number of requests / concurrency) Time per request: 0.173 [ms] (mean Across all concurrent requests) / / average waiting time of the server (calculated by user waiting time / number of requests completed) Transfer rate: 1571.59 [Kbytes/sec] received / / data size requested by users (calculated by total data length / user waiting time) Connection Times (ms) min mean [+ /-sd] median maxConnect: 0 24 138.0 4 1034Processing: 8 50 93.8 16 822Waiting: 047 93.2 13 816Total: 1274 168.7 20 1255Percentage of the requests served within a certain time (ms) 50% 20 66% 25 75% 31 80% 39 90% 90% 95% 250 98% 832 99% 1050 1255 (longest request) / / this one Sub-data is used to describe the distribution of processing time for each request (4) important performance indicators of ab stress testing tools
There are several metrics that are important during performance testing:
1. Throughput: a quantitative description of the concurrent processing capacity of the server. Refers to the number of requests processed per unit time under a certain number of concurrent users. The maximum number of requests that can be processed per unit time under a certain number of concurrent users is called maximum throughput.
Note: throughput is based on the number of concurrent users. The meaning of this sentence:
Throughput is related to the number of concurrent users; under different concurrent users, the throughput is different.
Formula: total number of requests / time spent processing these requests.
two。 Number of concurrent connections: the number of concurrent connections refers to the number of requests received by the server at a certain time, in short, a session.
3. Concurrent users: a user can have one or more sessions at the same time, that is, the number of connections
4. Average user wait time: calculation formula: time spent processing all requests completed / (total requests / concurrent users)
5. Average server wait time: calculation formula: the time it takes to complete multiple requests / the total number of requests. That is, the reciprocal of throughput. At the same time, it is the average waiting time of users / the number of concurrent users.
5. Install php acceleration software Xcache
The following operations are done on the php server.
Download Xcache software
(1) to install xcache [root @ localhost ~] # tar zxf xcache-3.2.0.tar.gz-C / usr/src [root@localhost ~] # cd / usr/src/xcache-3.2.0/ [root@localhost xcache-3.2.0] # / usr/local/php5.6/bin/phpizeConfiguring for://, you need to use the phpize command to generate the configure configuration file PHP Api Version: 20131106Zend Module Api No: 20131226Zend Extension Api No: 220131226 [root@localhost xcache-3.2.0] #. / configure-- enable-xcache--enable-xcache-coverager\-- enable-xcache-optimizer-- with-php-config=/usr/local/php5.6/bin/php-config & & make & & make install / / after compilation and installation This path is crucial: Installing shared extensions: / usr/local/php5.6/lib/php/extensions/no-debug-zts-20131226/
Detailed description of compilation configuration parameters:
-- enable-xcache: enable xcache function;-- enable-xcache-coverager: used to test accelerator efficacy and additivity;-- enable-xcache-optimizer: operation code optimization (2) create xcache cache file [root@localhost ~] # touch / tmp/xcache [root@localhost ~] # chmod 777 / tmp/xcache (3) copy the backend management program of xcache to the website directory [root@localhost ~] # cp-r / usr/src/xcache-3.2.0/htdocs/ / var/www/benet/xcache// to access the web page, and view the effect (4) modify the configuration file of php Let it support xcache [root@localhost ~] # vim / etc/php.ini / / Edit the configuration file of php / / add the following at the end [xcache-common] extension = / usr/local/php5.6/lib/php/extensions/no-debug-zts-20131226/xcache.so / / enable the xcache extension function of php [xcache.admin] xcache.admin.enable_auth = Off / / turn off xcache authentication [xcache ] xcache.shm_scheme = "mmap" / / determines how xcache shares memory from the system / / nmap is a memory-mapped file method xcache.size=60M / / the size of the shared cache used If it is set to 0, it will not be possible to use xcache.count = 1 / / to split cache into how many chunks. It is recommended to set it to cpu number xcache.slots = 8K / / refers to the reference value of the number of hash slots xcache.ttl=0 / / file survival time, set to 0 will infinite cache xcache.gc_interval = 0 / / the interval between triggering garbage collection Default is 0 second xcache.var_size=64M / / Cache for variables xcache.var _ count = 1 xcache.var_slots = 8K xcache.var_ttl=0 xcache.var_maxttl=0 xcache.var_gc_interval = 300 xcache.test = Off / / turn off the test function xcache.readonly_protection = Off / / Startup degrades performance But slightly improve security xcache.mmap_path = "/ tmp/xcache" / / for read-only file paths xcache.coredump_directory = "" / / in the event of a failure, the core dump function must be a directory writable by php, left blank to disable xcache.cacher = On / / use opcode cache Invalid xcache.stat=On during xcache.size=0 / / Update using stat Discovery check script xcache.optimizer = Off / / disable optimization [xcache.coverager] xcache.coverager = On / / enable code coverage information collector xcache.coveragedump_directory = "/ / place the directory location where the data collection information is placed By default, the directory / tmp/pcovis [root@localhost ~] # scp-r / var/www/benet/xcache/ 192.168.1.1:/var/www/benet// is used to copy xcache web page files to the root directory of the Apache server web page [root@localhost ~] # systemctl restart php-fpm// to restart php
Customers use browsers for access testing:
If you stress test a dynamic page now, xcache will cache the dynamic page information, which is generally not used in the real world, so it will be skipped here.
III. Deploy Discuz Forum
Download the Discuz forum program
The php server does the following:
[root@localhost ~] # unzip Discuz_7.0.0_FULL_SC_UTF8.zip-d discus// unpack the Discuz software program to the discus directory [root@localhost ~] # mv discus/Discuz_7.0.0_FULL_SC_UTF8/upload/ / var/www/benet/bbs// move the upload in the Discuz program to the website and directory [root@localhost ~] # chown-R nobody:nobody / var/www/benet/bbs/ [root@localhost ~ ] # chmod-R 777 / var/www/benet/bbs/// sets directory setting permissions (the test environment gives maximum permissions) [root@localhost ~] # sed-I 's/short_open_tag = Off/short_open_tag = On/g' / etc/php.ini// modifies the configuration file of the php server [root@localhost ~] # systemctl restart php-fpm / / restart php-fpm [root@localhost ~ ] # echo "/ var/www/benet 192.168.1.0 Universe 24 (rw) Sec=sys,sync,no_root_squash) "> > / etc/exports [root@localhost ~] # systemctl restart nfs [root@localhost ~] # showmount-eExport list for localhost.localdomain:/var/www/benet 192.168.1.0 / nfs Service configuration And restart the nfs service
The Mysql server does the following:
[root@localhost ~] # mysql-u root-p123 / / Log in to Mysql server mysql > create database bbs; / / create bbs database
The Apache server does the following:
[root@localhost ~] # mount-t nfs 192.168.1.3:/var/www/benet/ / var/www/benet// copy the php server web page root directory to the Apache server web page root directory
Client access test
Visit the forum successfully!
-this is the end of this article. Thank you for reading-
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.