In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/03 Report--
1. LAMP dynamic and static separation
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.
As shown below:
II. Installation and configuration of LAMP
Environment deployment:
Here I already have Apache and MySQL:
For Apache installation, please refer to: https://blog.51cto.com/14227204/2459749
For MySQL installation, please refer to: https://blog.51cto.com/14227204/2425596
1. Deploy the PHP server:
Download the PHP installation package I provided and upload it to the PHP server: https://pan.baidu.com/s/1d2ETH7xgobxh33G7FYYvKw
Extraction code: xs8u
# first, you need to install the dependency package for PHP [root@php php] # yum-y install libxml2-devel openssl-devel bzip2-devel [root@php php] # tar zxf libmcrypt-2.5.7 [root@php php] # cd 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. [root@php php] # Tar zxf php-5.6.27.tar.gz [root@php php] # 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--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.171.133 pm.max_children 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 to [root@php /] # service php-fpm restart # restart PHP to make the configuration effective Gracefully shutting down php-fpm. DoneStarting php-fpm done [root@php /] # netstat-anput | grep 9000 # check whether to run tcp 00 192.168.171.133netstat 9000 0.0.0.0anput * LISTEN 3054/php-fpm: maste [root@php /] # firewall-cmd-- permanent-- add-port=9000/tcp # configure firewall release traffic success [root@ Php /] # firewall-cmd-- reload # overload the firewall to make it effective
2. Configure the Apache server:
[root@apache /] # vim / usr/local/http-2.4.23/conf/httpd.conf # Edit the main configuration file # remove # LoadModule proxy_module modules/mod_proxy.soLoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so from the following two lines. . # navigate to these two lines at the beginning of Add Type Note that these two lines are not commented out AddType application/x-compress .Z AddType application/x-gzip .gz .tgz # add the following two apache to identify php AddType application/x-httpd-php .php AddType application/x-httpd-php-source .php. DirectoryIndex index.php index.html # navigate here, add index.php.. Include conf/extra/httpd-vhosts.conf # before index.html, navigate here, and remove # Open the virtual host # and then you can wq save and exit [root@apache /] # vim / usr/local/http-2.4.23/conf/extra/httpd-vhosts.conf # Edit the virtual host configuration file # the virtual host configuration is as follows: ServerAdmin 848369866@qq.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.171.133:9000/var/www/html/$1Options FollowSymLinksAllowOverride NoneRequire all granted [root@apache /] # mkdir-p / var/www/html # create the website root directory [root@apache /] # echo test.com > / var/www/html/index.html # write Test the web page [root@apache /] # apachectl restart # restart apache to make the configuration effective
The configuration file for the virtual host is 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.
3. Test LAMP:
# Editing these two test files in the PHP server [root@php /] # cat / var/www/html/index.php [root@php /] # cat / var/www/html/test.php
4. Create a user on the MySQL server and grant remote login permission:
[root@mysql /] # mysql-u root-p # Login Enter password: # enter the database password mysql > create database bbs; # to create a dedicated database Query OK, 1 row affected (0.00 sec) mysql > grant all on bbs.* to zyz@192.168.171.133 identified by 'pwd@123' # authorized user zyzQuery OK, 0 rows affected, 1 warning (0.00 sec)
Client access www.test.com:
The client accesses the www.test.com/test.php of the web server for testing:
Seeing the above two test pages shows that apache, php and mysql can work together.
3. Web 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 /] # ab-V # amount. Wrong ab: error while loading shared libraries: libssl.so.1.0.0: cannot open shared object file: No such file or directory [root@apache /] # export LD_LIBRARY_PATH= "/ usr/local/openssl/lib/" # execute this command to set environment variables [root@apache /] # ab-VThis is ApacheBench, Version 2.3Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/Licensed to The Apache Software Foundation, http://www.apache.org/
3. Ab stress test:
[root@apache /] # ab-c 1000-n 1000 127.0.0.1/index.html#-c: number of requests executed in the test session (i.e. total number of requests) #-n: number of requests generated at a time (i.e. 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 Page Document Length: 9 bytes # body length of HTTP response data Concurrency Level: 0.807 # number of concurrency Time taken for tests: 0.807 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: 251000 bytes# represents the sum of the response data lengths of all requests Include header information for each HTTP response data and length of body data HTML transferred: 9000 bytes # size of web page file (excluding the size of response headers) Requests per second: 1238.40 [# / sec] (mean) # Throughput, calculated as number of requests / user wait time (Complete requests/Time taken for tests) Time per request: 403.748 [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: 0.807 [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: 303.55 [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. (i.e. average network traffic per second) Connection Times (ms) min mean [+ /-sd] median maxConnect: 02 1.61 5Processing: 1 78 138.1 9 802Waiting: 1 77 138.3 8 802Total: 2 79 139.2 11 805Percentage of the requests served within a certain time (ms) 50% 11 66% 16 75% 206 80% 208 90% 209 95% 405 98% 406 99% 805% 805% 805 (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 metrics:
There are several metrics that are important during performance testing:
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.
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.
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.
Average request waiting time for users (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)
Server average request wait time (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:
The source package of xcache is included in the package downloaded before.
[root@php php] # tar zxf xcache-3.2.0.tar.gz [root@php php] # cd 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. 0] #. / configure-- enable-xcache--enable-xcache-coverager-- enable-xcache-optimizer-- with-php-config=/usr/local/php5.6/bin/php-config & & make & make install# remember the road strength at the end after installation Will use: / usr/local/php5.6/lib/php/extensions/no-debug-non-zts-20131226/
2. Create a xcache cache file:
[root@php /] # touch / tmp/xcache [root@php /] # chmod 777 / tmp/xcache # requires write permission
3. Copy the xcache background management program to the root directory of the website:
[root@php /] # cd / php/xcache-3.2.0/ [root@php xcache-3.2.0] # cp-r htdocs/ / var/www/html/xcache
4. Configure PHP to support xcache:
[root@php /] # vim / etc/php.ini # add the following at the end of the configuration file: [xcache-common] extension = / usr/local/php5.6/lib/php/extensions/no-debug-non-zts-20131226/xcache.so# this is the directory [xcache.admin] xcache.admin.enable_auth = off [xcache] xcache.shm_scheme = "mmap" xcache.size=60Mxcache.count = 1xcache.slots = 8Kxcache.ttlroom0xcache.gcc _ returned after the installation of xcache 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 = "" # save and exit [root@php /] # service php-fpm restart Gracefully shutting down php-fpm. DoneStarting php-fpm done
5. Configure NFS and go back to the Apache server to mount the NFS shared directory to synchronize the files in the root directory of the web page:
[root@php /] # vim / etc/exports/var/www/html/ 192.168.171.0 Universe 24 (rw,sec=sys,sync) No_root_squash) [root@php /] # systemctl restart nfs # restart nfs to make it effective # return to the Apache server [root@apache /] # showmount-e 192.168.171.133 # confirm that you can view the PHP shared directory Export list for 192.168.171.133:/var/www/html 192.168.171.0 root@apache 24 [root@apache /] # mount-t nfs 192.168.171. 133:/var/www/html/ / var/www/html/ # is mounted to the root directory of the local website [root@apache /] # df-hT192.168.171.133:/var/www/html nfs4 50G 4.8G 46G 10% / var/www/html
6. Test:
Visit www.test.com/xcache and you will see the following page:
At this point, php's acceleration software xcache is installed.
7. Test the Apache dynamic page:
[root@apache /] # ab-c 100-n 1000 http://192.168.171.134/index.php # first test.. / / Time taken for tests: 0.787 seconds.. / / Requests per second: 1270.78 [# / sec] (mean) / / [root@apache /] # ab-c 100-n 1000 http://192.168.171.134/index.php # second test.. / / Time taken for tests: 0.755 seconds.. / / Requests per second: 1325.23 [# / sec] (mean) / /
Check the hit rate of Xcache:
Deploy bbs Forum
Operations on the PHP server:
The previously downloaded software package contains the source code package of bbs Forum, which can be pulled over and used.
[root@php php] # unzip Discuz_7.0.0_FULL_SC_UTF8.zip [root@php php] # cd Discuz_7.0.0_FULL_SC_UTF8/ [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.. / / omit part of the content short_open_tag = On # navigate to this line and change Off to On [root@php /] # service php-fpm restartGracefully shutting down php-fpm. DoneStarting php-fpm done
Configure bbs (you can use the users who previously used to test the linked database for the bbs forum)
Visit www.test.com/bbs/install
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.