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/02 Report--
Blog structure
The concept of php
Deploy lnmp
Pressure testing
Deployment
Discuz Forum
1. Three working modes of CGI: 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 use 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 subprocesses are managed by a component called php-fpm of PHP FastCGI working mechanism
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:
two。 The deployment of lnmp static and dynamic separation case environment is as follows:
1 httpd server: 192.168.148.129
1 php server: 192.168.148.130
1 mysql server: 192.168.148.131
Set up apache server
Download the source package
Install directly using script
Set up php
Download the php package
Solve the dependency [root@localhost ~] # yum-y install libxml2-devel lzip2-devel libcurl-devel libmcrypt-devel openssl-devel bzip2-devel install libmcrypt [root @ localhost ~] # tar zxf libmcrypt-2.5.7.tar.gz [root@localhost ~] # cd libmcrypt-2.5.7/ [root@localhost libmcrypt-2.5.7] #. / configure-- prefix=/usr/local/libmcrypt & & make & & make install compile and install php [root ~] # tar Zxf php-5.6.27.tar.gz [root@localhost ~] # cd 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
(the installation process takes about 15 minutes)
Explanation of relevant options-prefix=/usr/local/php5.6// installation location-with-mysql=mysqlnd / / support mysql-- with-pdo-mysql=mysqlnd / / support 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 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 strings, like our Chinese is multi-byte strings-- with-freetype-dir// supports freetype, freetype-devel, font-related, Font parsing tool-- with-jpeg-dir-- with-png-dir Note: the function of the above two options: processing jpeg, png images, php can dynamically generate jpeg images-- with-zlib// is a compression library, used to compress transmission when transmitting over the Internet-- with-libxml-dir=/usr// this libxml is used to parse xml, Specify / usr-- enable-xml / / support xml-- with-mhash// supports mhash-- with-mcrypt=/usr/local/libmcrypt / / libmcrypt-devel specified by this package-- with-config-file-path=/etc / / specify the storage path of the configuration file-- with-config-file-scan-dir=/etc/php.d / / configuration file scan path-- with-bz2 / / Support BZip2 in order to support apache's worker or event MPM The-- enable-maintainer-zts option is used at compile time. If you are using PHP5.3 or above, you can specify mysqlnd in order to link to the MySQL database, so that you do not need to install MySQL or MySQL 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 php configuration file
[root@localhost php-5.6.27] # cp php.ini-production / etc/php.ini
Provide php-fpm with script [root@localhost php-5.6.27] # cp sapi/fpm/init.d.php-fpm / etc/init.d/php-fpm [root@localhost php-5.6.27] # chmod + x / etc/init.d/php-fpm [root@localhost php-5.6.27] # chkconfig-add php-fpm [root@localhost php-5.6.27] # chkconfig php-fpm on [root@localhost php-5.6.27] # cp / usr/local/php5.6/etc/php-fpm.conf.default / usr/local/php5.6/etc/php-fpm.conf provides the php-fpm configuration file and edits [root@localhost php-5.6.27] # vim / usr/local/php5.6/etc/php-fpm.conf to modify the content as follows: pid = run/php-fpm.pid listen = 192.168.31.141 php-fpm 9000\\ local ip address (do not use 127s. 0.0.1) pm.max_children = 50 pm.start_servers = 5 pm.min_spare_servers = 5 pm.max_spare_servers = 35 start the php-fpm service [root@localhost php-5.6.27] # service php-fpm startStarting php-fpm done [root@localhost php-5.6.27] # netstat-anpt | grep php-fpmtcp 00 192.168.148.130 pm.min_spare_servers 9000 0.0.0.0 * LISTEN 130988/php-fpm: mas turn off the firewall or enter the following command: [root@phpserver ~] # firewall-cmd-- permanent-- add-port=9000/tcp success [root@phpserver ~] # firewall-cmd-- reload Success creates a new virtual host directory on the host to store web files
[root@localhost php-5.6.27] # mkdir-p / var/www/benet
Configure apache (switch to apache host)
After Apache2.4, there has been a special module for the implementation of FastCGI, this module is mod_proxy_fcgi.so, which is actually an extension of the mod_proxy.so module, so both modules have to load LoadModule proxy_module modules/mod_proxy.so LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so to remove the previous #
[root@localhost ~] # vim / usr/local/http-2.4.23/conf/httpd.conf
Set up a directory as the home directory of the virtual host
[root@localhost] # mkdir-p / var/www/benet
Edit the main configuration file httpd.conf to open the virtual host
At the same time, locate AddType; to add pages that allow apache to recognize php format.
AddType application/x-httpd-php .php
And navigate to DirectoryIndex: a home page that supports php format (with index.php in the middle)
Configure virtual hosts to support the use of fcgi (delete and add the original) [root@localhost ~] # vim / usr/local/http-2.4.23/conf/extra/httpd-vhosts.conf 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.148.130:9000/var/www/benet/$1\\ write the IP address of php Options FollowSymLinks / / prohibit directory traversal AllowOverride None / / allow the request to be empty Require all granted / / allow After all clients visit [root@localhost ~] # apachectl-tSyntax OK [root@localhost ~] # apachectl restart// to create 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, which refers to the path (uri) matched in the previous () to create a test web page on the php server [root@localhost php-5.6.27] # vim / var/www/benet/index.php to access the ip of the apache with the client
Set up mysql
Download the package and install it with one click of the script
Edit the script to install [root@localhost ~] # vim a.sh [root@localhost ~] # chmod aquix a.sh [root@localhost ~] # sh a.sh Starting MySQL. SUCCESS! Mysql: [Warning] Using a password on the command line interface can be insecure.\\ this is a warning normal phenomenon.
Test the LAMP environment
Create a mysql account for php server connection on the mysql host [root@localhost ~] # mysql-u root-p123mysql > grant all on *. * to aaa@'192.168.148.%' identified by '123456 query OK, 0 rows affected, 1 warning (0.00 sec) fill in the test script [root@localhost php-5.6.27] # vim / var/www/benet/test1.php verification on the php server
The above two test pages show that apache, php, and mysql can work together.
Pressure testing
Website performance stress testing is an indispensable part in the process of server website performance tuning. Only when the server is under high pressure can we really reflect the problems exposed by improper settings such as software and hardware.
Ab is a stress testing tool that comes with apache. Ab is very practical. It can be used not only for website query stress testing of apache servers, but also for other types of servers. Such as nginx, tomcat, IIS and so on.
Let's start with the use of the ab command:
The principle of 1.ab
Installation of 2.ab
3.ab parameter description
4.ab performance index
Actual use of 5.ab
6. Test the performance of nginx
1) the principle of ab ab is the abbreviation of the apachebench command. The principle of ab: the ab command creates multiple concurrent access threads to simulate multiple visitors to a URL address at the same time. Its testing goal is based on URL, so it can be used not only to test the load pressure of apache, but also to test the pressure of other Web servers such as nginx, lighthttp, tomcat, IIS and so on. The ab command requires very little of the computer that issues the load, and it takes up neither a very high CPU nor a lot of memory. But it will cause a huge load on the target server, and the principle is similar to CC. You should also pay attention to testing and using it yourself, otherwise there will be too much load at a time. It may cause the target server to run out of resources, and even lead to a crash in serious cases.
2) installation of ab
To check whether ab is installed successfully, you can change to the above directory and use the ab-V command to detect [root@localhost] # / usr/local/http-2.4.23/bin/ab-V / usr/local/http-2.4.23/bin/ab: error while loading shared libraries: libssl.so.1.0.0: cannot open shared object file: No such file or directory
Resolve:
If the ab-V command goes wrong, you can exporexport LD_LIBRARY_PATH= "/ usr/local/openssl/lib/"
[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, http://www.apache.org/
3) ab parameter description
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.htmlasdasdasdasdasdasd// create the home file of Apache [root@localhost ~] # ab-c 500-n 10000 http://192.168.1.129/index.html// to test the Web server of 192.168.1.129 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.129 (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.129Server 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. Important performance indicators of ab stress testing tools
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; throughput varies with different number of concurrent users; calculation formula: total number of requests / time it takes to process 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.
Install php acceleration software Xcache
Download Xcache
Install the php acceleration software Xcache under CentOS7.2 (complete the following operations on the php host [root@localhost /] # tar zxf xcache-3.2.0.tar.gz [root@localhost /] # cd 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 installs a path that is very important for later steps
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; create xcache cache file [root@localhost xcache-3.2.0] # touch / tmp/xcache [root@localhost xcache-3.2.0] # chmod 777 / tmp/xcache copy xcache daemon to the website root directory
[root@localhost xcache-3.2.0] # cp-r htdocs/ / var/www/benet/xcache
Configure php to support xcache
Add the following to the last line [root@localhost xcache-3.2.0] # vim / etc/php.ini [xcache-common] extension = / usr/local/php5.6/lib/php/extensions/no-debug-zts-20131226/ xcache.so [xcache.admin] xcache.admin.enable_auth = Off [xcache] xcache.shm_scheme = "mmap" xcache.size=60Mxcache.count = 1xcache.slots = 8Kxcache.ttl=0xcache.gc_interval = 0xcache.var_size=64Mxcache.var_count = 1xcache.var_slots = 8Kxcache .var _ ttl=0xcache.var_maxttl=0xcache.var_gc_interval = 300xcache.test = Offxcache.readonly_protection = Offxcache.mmap_path = "/ tmp/xcache" xcache.coredump_directory = "" xcache.cacher = On is explained as follows: [xcache-common] extension = / usr/local/php5.6/lib/php/extensions/no-debug-zts-20131226/xcache.so / / enable php's xcache extension function [xcache.admin] xcache.admin.enable_auth = Off / / 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 is used to copy the xcache directory to the apache host's webpage documentation directory. [root@localhost xcache-3.2.0] # scp-r / var/www/benet/xcache/ root@192.168.148.129:/var/www/benet/ restart php [root@localhost xcache-3.2.0] # service php-fpm restartGracefully shutting down php-fpm. DoneStarting php-fpm done test
Deploy Discuz Forum
Download the Discuz package
Operate [root@localhost /] # unzip Discuz_7.0.0_FULL_SC_UTF8.zip-d discus [root@localhost /] # mv discus/Discuz_7.0.0_FULL_SC_UTF8/upload/ / var/www/benet/bbs [root@localhost /] # chown-R nobody:nobody / var/www/benet/bbs/ [root@localhost /] # chmod-R 777 / var/www/benet/bbs/ [root@localhost /] # vim / on the php server Change etc/php.ini short_open_tag = Off to short_open_tag = On
[root@localhost /] # service php-fpm restartGracefully shutting down php-fpm. The doneStarting php-fpm doneMysql server does the following operations [root@localhost ~] # mysql-u root-p123mysql > create database bbs;\\ to create the database Query OK, 1 row affected (0.00 sec)
The Apache server does the following
Static files are also required for web servers
[root@localhost /] # unzip Discuz_7.0.0_FULL_SC_UTF8.zip-d discus [root@localhost /] # mv discus/Discuz_7.0.0_FULL_SC_UTF8/upload/ / var/www/benet/bbs [root@localhost /] # cd / var/www/benet/bbs [root@localhost bbs] # chown-R daemon config.inc.php attachments/ forumdata/ uc_client/data/cache/ templates/ Test
On this page, we need to take one more step.
Operate on php
[root@localhost /] # scp-r / var/www/benet/bbs/ root@192.168.148.129:/var/www/benet/
Copy the bbs under php to apache and press f5 to refresh it.
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.