In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
Blog outline:
First, the concept of LAMP dynamic and static separation, LAMP installation and configuration, web website stress test 4, deployment of PHP acceleration software Xcache V, deployment of bbs forum
I have previously written a blog about deploying the LAMP platform: building a LNMP architecture based on centos 7, but that one is based on the same server and can be used as a test site or in the case of low traffic, so? What if the web website has a lot of visitors?
I. the concept of dynamic and static separation of LAMP
When you need to build an efficient web architecture, static and dynamic separation is undoubtedly the best choice. This blog post will write down the dynamic and static separation deployment of LAMP.
So-called LAMP? LAMP architecture is one of the most mature enterprise website application models at present, which refers to a complete set of systems and related software that work together, which can provide dynamic web site services and application development environment. Side by side with LNMP, LTMP and so on, LAMP put it bluntly, that is, install Apache website service on Linux operating system and build php/perl/Python running environment to connect to mysql database. Together, the four components are referred to as "LAMP". LNMP simply uses Nginx to build the httpd service.
There are three working modes of PHP in LAMP environment: CGI mode, apache module and FastCGI (FCGI) mode. Running PHP in CGI mode, the performance is not very good. The difference between FastCGI mode and apache module is that FastCGI mode PHP is an independent process, and all PHP subprocesses are managed by a component called php-fpm of PHP, while PHP, which runs in apache modular mode, is responsible for calling PHP to complete the work. The performance of FastCGI mode of PHP is much better than that of apache modularization mode.
Here you will compile and install the LAMP schema in FastCGI.
How FastCGI works:
The client initiates requests. There are two kinds of requests. One is a static request, which can be returned directly by the Apache. The other is a dynamic request. If it contains php or Perl as a script interpretation language, the Apache server will call the php server through the fastcgi protocol to execute and return to Apache the result after the interpretation will be returned by Apache. If the operation on the data is involved, the php server will also call the mysql server through the mysql protocol.
The schematic diagram is as follows:
2. Installation and configuration of LAMP 1. Environment preparation
My environment here is as follows:
I already have an Apache server and a MySQL server, which can be deployed by myself. Please refer to the blog article: introduction to the installation and working mode of Apache service; building MySQL database based on centos7.
2. Deploy the PHP server
Start deploying the PHP server directly here
Download the source package I provided and upload it to the PHP server.
# install PHP and its dependencies [root@php ~] # tar zxf libmcrypt-2.5.7.tar.gz-C / usr/src [root@php ~] # tar zxf php-5.6.27.tar.gz-C / usr/src [root@php ~] # yum-y install libxml2-devel openssl-devel bzip2-devel [root@php ~] # cd / usr/src/libmcrypt-2.5.7 [root@php libmcrypt-2.5.7] #. / configure -- prefix=/usr/local/libmcrypt & & make & & make install [root@php libmcrypt-2.5.7] # cd. / php-5.6.27/ [root@php 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 above options for compiling and installing PHP are explained as follows:
-- prefix=/usr/local/php5.6 # installation location-- with-mysql=mysqlnd # supports mysql--with-pdo-mysql=mysqlnd # supports pdo module-- with-mysqli=mysqlnd # supports mysqli module
# the role of the three options above: the database and php are not on the same server, specify this way, and install the database connection driver. -- with-openssl # supports openssl module-- enable-fpm # supports fpm mode-- enable-sockets # enables socket support-- enable-sysvshm # enables system shared memory support-- enable-mbstring # multi-byte strings, like our Chinese is multi-byte strings-- with-freetype-dir # supports freetype, needs to install freetype-devel, font-related, font parsing tool-- with-jpeg-dir--with-png-dir
# the function of the two options above: when 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 over the Internet-- with-libxml-dir=/usr # this libxml is used to parse xml, Specify / usr-- enable-xml # support xml-- with-mhash # support 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
To support the worker or event MPM of apache, the-- enable-maintainer-zts option is used at compile time.
# the following is to adjust the PHP configuration file and control the start and stop of the service [root@php php-5.6.27] # cp php.ini-production / etc/php.ini # copy the PHP configuration file [root@php php-5.6.27] # cp sapi/fpm/init.d.php-fpm / etc/init.d/php-fpm# provided in the replication source code [root@php php-5.6.27] ] # chmod + x / etc/init.d/php-fpm # Grant execution permission [root@php php-5.6.27] # chkconfig-- add php-fpm # added as a system service To support systemctl management [root@php php-5.6.27] # chkconfig php-fpm on # enable # copy the default configuration file provided by php-fpm and edit it [root@php php-5.6.27] # cp / usr/local/php5.6/etc/php-fpm.conf.default / usr/local/php5.6/etc/php-fpm.conf [root@php php-5.6.27] # vim / usr/local/php5.6/etc / php-fpm.conflisten = 192.168.20.5 pm.start_servers 9000 # listener address is the local IP9000 port pm.max_children = 50 # maximum number of started processes pm.start_servers = 5 # initial start processes pm.min_spare_servers = 5 # minimum idle process pm.max_spare_servers = 35 # maximum idle process # after modification Save and exit [root@php php-5.6.27] # systemctl start php-fpm # start the PHP service [root@php php-5.6.27] # netstat-anput | grep php-fpm # confirm its port 9000 to start [root@php] # mkdir-p / var/www/html # to create its web page storage directory It must be the same as the web page storage path of the apache server [root@php ~] # firewall-cmd-- permanent-- add-port=9000/tcp # Firewall releases the traffic at port 9000 [root@php ~] # firewall-cmd-- reload # reload to take effect 3. Configure the apache server (switch to the apache server to do the following) [root@apache ~] # cd / usr/local/http-2.4.23/conf/ [root@apache conf] # vim httpd.conf # Edit the main configuration file of the apache service # enable the following two modules (remove the "#" sign in front of the next two lines) LoadModule proxy_module modules/mod_proxy.soLoadModule proxy_fcgi_module modules/mod_proxy_fcgi. SoInclude conf/extra/httpd-vhosts.conf # enable the virtual host configuration file. # omit part of the content AddType application/x-compress .Z AddType application/x-gzip .gz .tgz # navigate to the above two lines (note These two lines must have been uncommented), and then write the following two lines of configuration Let apache recognize the page in php format AddType application/x-httpd-php .php AddType application/x-httpd-php-source .phps # navigate to the label DirectoryIndex index.php index.html # add index.php# before index.html and then save and exit [root@apache conf] # vim extra/httpd-vhosts.conf # edit the virtual host configuration file # the configuration file of the virtual host is as follows: ServerAdmin Lv916551516@163.com DocumentRoot "/ var/www/html" ServerName www.test.com ErrorLog "logs/test-error_log" CustomLog "logs/test-access_log" common ProxyRequests OffProxyPassMatch ^ / (. *\ .php (/. *)?) $fcgi://192.168.20.5:9000/var/www/html/$1Options FollowSymLinksAllowOverride NoneRequire all granted# after editing Save and exit [root@apache conf] # mkdir-p / var/www/html/ # create the web page root [root@apache conf] # echo this is a test file > > / var/www/html/index.html [root@apache conf] # apachectl restart # restart the apache service
The configuration files for the above virtual hosts are explained as follows:
ProxyRequests off # closes the forward agent ProxyPassMatch # and sends the file request ending with .php to the php-fpm process. Php-fpm needs to know at least the running directory and URI, so these two parameters are specified directly after fcgi://192.168.20.5:9000. The transfer of other parameters has been encapsulated by mod_proxy_fcgi.so and does not need to be specified manually. In particular, / var/www/html/ needs to match the path after DocumentRoot in ProxyPassMatch # only content that satisfies a specific regular pattern matches and enforces this rule, where the pattern is ^ / (.. php (/.)?) $, starting with the site (the root of the virtual host, matching any path that ends in .php, or following one / followed by something else. 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.20.5:9000 through mod_proxy_fcgi, using the fastCGI protocol, goes to the port that PHP-FPM listens on. / var/www/html # 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. 4. Go back to the PHP server and test the LAMP environment # write the following two web page files [root@php ~] # cat / var/www/html/index.php # to display the version information of PHP [root@php ~] # cat / var/www/html/test.php # to test connecting to the database 5 and add users to the MySQL server And give remote login authority [root@localhost src] # mysql-uroot-p Enter password: # verify database user password mysql > create database bbs # create a dedicated database Query OK, 1 row affected (0.00 sec) mysql > grant all on bbs.* to lvjz@192.168.20.5 identified by 'pwd@123'; # authorized user is lvjzQuery OK, 0 rows affected (0.01 sec)
The client accesses the www.test.com of the web server for testing:
The client accesses the www.test.com/test.php of the web server for testing:
Third, web website stress test
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.
At present, the most common performance testing tools are ab, http_load, webbench, and siege. I am more used to using the ab tool that comes with apahce.
Ab is very practical. It can be used not only for website access stress testing of apache servers, but also for other types of servers. Such as nginx, tomcat, IIS and so on.
1. The principle of ab
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 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 put a huge load on the target server, the principle is similar to CC gong hit. 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
The installation of ab is very simple, and it is even easier if you install apache in source code. After the apache installation, the ab command is stored in the bin directory of the apache installation directory. As follows:
/ usr/local/http2.4.23/bin/ab .
If apache is installed through yum's RPM package, the ab command is stored in the / usr/bin directory by default. As follows:
Which ab
Note: if you don't want to install apache but want to use the ab command, you can install apache's toolkit httpd-tools directly. As follows:
Yum-y install httpd-tools
To see if ab is installed successfully, you can change to the above directory and use the ab-V command to test.
[root@apache conf] # ab-V # seems to have made a mistake ab: error while loading shared libraries: libssl.so.1.0.0: cannot open shared object file: No such file or directory [root@apache conf] # export LD_LIBRARY_PATH= "/ usr/local/openssl/lib/" # execute the command Set the environment variable to [root@apache conf] # ab-VThis is ApacheBench, Version 2.3. # omit part 3, ab stress test [root@apache] # ab-c 1000-n 1000 127.0.0.1/index.html # test the local static web page #-n: the number of requests executed in the test session (that is, the total number of requests). #-c: the number of requests generated at a time (that is, the number of concurrent users). 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 127.0.0.1 (be patient) Completed 100 requestsCompleted 200 requestsCompleted 300 requestsCompleted 400 requestsCompleted 500 requestsCompleted 600 requestsCompleted 700 requestsCompleted 800 requestsCompleted 900 requestsCompleted 1000 requestsFinished 1000 requestsServer Software: Apache/2.4.23Server Hostname: 127.0.0.1Server Port: 80Document Path: / index.html # requested resource Document Length: 20 bytes # HTTP response data Degree Concurrency Level: 500 # concurrent number (concurrent users) Time taken for tests: 2.093 seconds # time it takes to complete all these requests Complete requests: 1000 # number of completed requests Failed requests: 0 # number of failed requests Total transferred: 264000 bytes # represents the sum of the response data length of all requests Includes the header information of each HTTP response data and the length of the body data. HTML transferred: 20000 bytes # size of the web page file (that is, the size after removing the response header) Requests per second: 477.87 [# / sec] (mean) # Throughput, calculated as the number of requests / user wait time (Complete requests/Time taken for tests) Time per request: 1046.320 [ms] (mean) # average time a user waits for a page Calculation method: user wait time / number of requests completed (Complete requests/Concurrency Level) Time per request: 2.093 [ms] (mean, across all concurrent requests) # time taken by the server to process a request, calculated as user waiting time / number of times the request was completed (Time taken for tests/Complete requests) Transfer rate: 123.20 [Kbytes/sec] received# data size requested by the user Calculation method: total length of data / user waiting time (Total trnasferred/ Time taken for tests) # this statistics is a good indication of the demand for broadband for export when the server's processing capacity reaches its limit. (that is, average network traffic per second) Connection Times (ms) min mean [+ /-sd] median maxConnect: 1 252 401.1 401.1 1262Processing: 13 245 224.7 230 817Waiting: 2225 208.0 559.7 816Total: 20498 559.7 243 1812Percentage of the requests served within a certain time (ms) 50% 243 66% 496 75% 691 80 % 834 1760 95% 1760 98% 1762 99% 1762 1812 (longest request) the data above is used to describe the distribution of processing time for each request For example, in the above test, 80% of the request processing time does not exceed 834ms, which refers to the previous Time per request, that is, the average processing time of each request for a single user. 4. Ab performance index
There are several metrics that are important during performance testing:
1) throughput (Requests per second)
A quantitative description of the server's concurrent processing capacity, in reqs/s, which 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. This sentence represents two meanings:
The throughput is related to the number of concurrent users; under different concurrent users, the throughput is generally different.
Formula: total number of requests / time it takes to process these requests, that is
Request per second=Complete requests/Time taken for tests
It must be noted that this value represents the overall performance of the current machine, and the higher the value, the better.
2) number of concurrent connections (The number of concurrent connections)
The number of concurrent connections refers to the number of requests accepted by the server at a certain time, in short, a session.
3) number of concurrent users (Concurrency Level)
Pay attention to the difference between this concept and the number of concurrent connections. A user may have multiple sessions at the same time, that is, the number of connections.
4) APCge request waiting time (Time per request)
Calculation formula: the time it takes to process all requests / (total requests / concurrent users), that is:
Time per request=Time taken for tests/ (Complete requests/Concurrency Level)
5) APCge request waiting time for the server (Time per request:across all concurrent requests)
Calculation formula: the time / total number of requests taken to process all requests completed, that is:
Time taken for/testsComplete requests
As you can see, it is the reciprocal of throughput.
At the same time, it is also equal to the average request waiting time of users / the number of concurrent users, that is
Time per request/Concurrency Level
Deploy PHP acceleration software Xcache
Xcache is a tool for caching PHP pages. Of course, in the actual work environment, PHP dynamic pages will not be cached, which does not make much sense (dynamic pages, data updates faster) and takes up memory space. This is just to show that PHP dynamic pages can also be cached.
1. Install Xcache
When deploying PHP, I provided a download link containing the source package of xcache, which can be uploaded to the PHP server.
[root@php ~] # tar zxf xcache-3.2.0.tar.gz-C / usr/src [root@php ~] # cd / usr/src/xcache-3.2.0/ [root@php xcache-3.2.0] # / usr/local/php5.6/bin/phpize # generate the configure file Configuring for:PHP Api Version: 20131106Zend Module Api No: 20131226Zend Extension Api No: 220131226 [root@php xcache-3. 2] #. / configure-- enable-xcache--enable-xcache-coverager-- enable-xcache-optimizer-- with-php-config=/usr/local/php5.6/bin/php-config & & make & & make install# after installation Remember the path to the end prompt, which will be used later As follows: / usr/local/php5.6/lib/php/extensions/no-debug-zts-20131226/2, create Xcache cache file [root@php ~] # touch / tmp/xcache [root@php ~] # chmod 777 / tmp/xcache # guarantee write permission 3, copy Xcache daemon to the root directory of the website [root@php xcache-3.2.0] # cp-r htdocs/ / var/www/html/xcache4, Configure PHP to support Xcache [root@php xcache-3.2.0] # vim / etc/php.ini # Edit PHP's main configuration file # add the following at the end of the file [xcache-common] extension = / usr/local/php5.6/lib/php/extensions/no-debug-zts-20131226/xcache.so#, which is the directory [xcache.admin] xcache.admin.enable_auth = off [xcache] xcache.shm_scheme = returned after the specified installation of Xcache "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 = Onxcache.stat=Onxcache.optimizer = off [xcache.coverager] xcache.coverager = Onxcache.coveragedump_directory = "" [root@php xcache-3.2.0] # systemctl restart php-fpm # restart PHP [root@php xcache-3.2.0] # vim / etc/exports # set nfs/var/www/html/ 192.168.20.0 Universe 24 (rw Sec=sys,sync,no_root_squash) 5. Go back to the apache server Mount the nfs shared directory In order to synchronize the files in the root directory of the web page [root@apache ~] # showmount-e 192.168.20.5 # confirm that you can view the PHP shared directory Export list for 192.168.20.5:/var/www/html 192.168.20.0On24 [root@apache ~] # mount-t nfs 192.168.20.5:/var/www/html/ / var/www/html/# mount [root@apache ~] # df-hT / var / www/html/ # confirm that the mounted file system type capacity is available.% mount point 192.168.20.5:/var/www/html nfs4 39G 5.0G 34G 13% / var/www/html6, test
Visit www.test.com/xcache and you will see the following page:
At this point, the installation of php acceleration software Xcache under Linux is complete.
7 、 Test the dynamic page of apache [root@apache ~] # export LD_LIBRARY_PATH= "/ usr/local/openssl/lib/" [root@apache ~] # ab-c 1000-n 1000 http://192.168.20.4/index.php # for the first time. # omit part Time taken for tests: 4.292 seconds. # omit part Content Requests per second: 232.99 [# / sec] (mean). # omitted part [root@apache ~] # ab-c 1000-n 1000 http://192.168.20.4/index.php # for a second test. # omitted part Time taken for tests: 1.631 seconds. # Province Omit part Requests per second: 613.29 [# / sec] (mean). # omit part of the content
Check the hit rate of Xcache:
Deploy bbs Forum
1. Do the following on the PHP server
The source package of the bbs forum is Discuz_7.0.0_FULL_SC_UTF8.zip, which can also be extracted from the link at the beginning of my article and uploaded to the PHP server.
[root@php ~] # unzip Discuz_7.0.0_FULL_SC_UTF8.zip # decompress [root@php Discuz_7.0.0_FULL_SC_UTF8] # cp-r upload/ / var/www/html/bbs [root@php Discuz_7.0.0_FULL_SC_UTF8] # chmod-R 777 / var/www/html/bbs/ [root@php ~] # vim / etc/php.ini # modify PHP configuration file short_open _ tag = On # modify the original Off to On [root@php xcache-3.2.0] # systemctl restart php-fpm # restart PHP
2. Configure bbs (users who previously used to test the linked database can be used by bbs forums)
Browsers access www.test.com/bbs/install:
-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.