1. Deploy the separated LAMP to two servers, and php loads the xcache module
1) Install httpd, PHP, PHP MySQL on c2 server
[root@c2 ~]# yum install httpd php php-mysql -y
2) Installing the database mariadb server on the mariadb server
[root@mariadb ~]# yum install mariadb-server -y
3) Start service
[root@c2 ~]# systemctl start httpd [root@mariadb ~]# systemctl start mariadb.service
4) Testing
[root@c2 html]# ll -lh total 3.6M -rw-r--r-- 1 root root 16 May 14 20:43 index.html -rw-r--r-- 1 root root 3.6M May 10 21:45 npp [root@c2 html]# pwd /var/www/html
stay c1 install httpd-tools To use ab command [root@c1 ~]# yum install httpd-tools-2.4.6-93.el7.centos.x86_64 -y [root@c1 ~]# ab -c10 -n 100 http://c1/npp This is ApacheBench, Version 2.3 <$Revision: 1430300 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking 10.0.1.243 (be patient).....done Server Software: Apache/2.4.6 Server Hostname: 10.0.1.243 Server Port: 80 Document Path: /npp Document Length: 3760568 bytes Concurrency Level: 10 Time taken for tests: 0.742 seconds Complete requests: 100 Failed requests: 0 Write errors: 0 Total transferred: 376080800 bytes HTML transferred: 376056800 bytes Requests per second: 134.82 [#/sec] (mean) Time per request: 74.173 [ms] (mean) Time per request: 7.417 [ms] (mean, across all concurrent requests) Transfer rate: 495148.38 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 0 0.4 0 3 Processing: 37 72 20.3 74 113 Waiting: 1 26 18.7 36 57 Total: 38 72 20.2 74 113 Percentage of the requests served within a certain time (ms) 50% 74 66% 80 75% 83 80% 87 90% 103 95% 110 98% 113 99% 113 100% 113 (longest request)
5) Installing xcache acceleration on c2
a. Build install
[root@c2 html]# yum -y install php-devel
b. Download xcache-3.2.0.tar.bz2 from the official website, upload it to / usr/local/src / directory and extract it
[root@c2 src]# tar -xvf xcache-3.2.0.tar.gz
c. Generate precompiled script with command phpize
[root@c2 xcache-3.2.0]# phpize Configuring for: PHP Api Version: 20100412 Zend Module Api No: 20100525 Zend Extension Api No: 220100525 [root@c2 xcache-3.2.0]# ll configure -rwxr-xr-x 1 root root 414469 May 14 21:00 configure
d. Precompile
[root@c2 src]# cd xcache-3.2.0/ [root@c2 xcache-3.2.0]# ./configure --enable-xcache
e. Compile and install
[root@c2 xcache-3.2.0]# make -j 4 && make install
[root@c2 xcache-3.2.0]# ls /usr/lib64/php/modules/ curl.so mysqli.so pdo.so sqlite3.so fileinfo.so mysql.so pdo_sqlite.so xcache.so json.so pdo_mysql.so phar.so zip.so
f. Load xcache module and restart httpd service
[root@c2 xcache-3.2.0]# cp xcache.ini /etc/php.d/ [root@c2 xcache-3.2.0]# ls /etc/php.d/ curl.ini mysqli.ini pdo_mysql.ini sqlite3.ini fileinfo.ini mysql.ini pdo_sqlite.ini xcache.ini json.ini pdo.ini phar.ini zip.ini
[root@c2 xcache-3.2.0]# systemctl restart httpd.service
g. Testing
[root@c1 ~]# ab -c10 -n 100 http://c2/npp This is ApacheBench, Version 2.3 <$Revision: 1430300 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking c2 (be patient).....done Server Software: Apache/2.4.6 Server Hostname: c2 Server Port: 80 Document Path: /npp Document Length: 3760568 bytes Concurrency Level: 10 Time taken for tests: 0.604 seconds Complete requests: 100 Failed requests: 0 Write errors: 0 Total transferred: 376080800 bytes HTML transferred: 376056800 bytes Requests per second: 165.64 [#/sec] (mean) Time per request: 60.371 [ms] (mean) Time per request: 6.037 [ms] (mean, across all concurrent requests) Transfer rate: 608345.02 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 0 0.1 0 1 Processing: 32 59 15.4 57 89 Waiting: 1 25 11.6 26 46 Total: 32 59 15.4 57 89 Percentage of the requests served within a certain time (ms) 50% 57 66% 70 75% 71 80% 74 90% 80 95% 84 98% 89 99% 89 100% 89 (longest request)
2. Deploy wordpress forum and log in to the forum normally
2.1 implement this scenario based on the lamp in Section 1.
2.2 create wpdb database and wpuser remote connection in database server
[root@mariadb ~]# mysql Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 2 Server version: 5.5.65-MariaDB MariaDB Server Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> create database wpdb; Query OK, 1 row affected (0.00 sec) MariaDB [(none)]> grant all privileges on wpdb.* to wpuser@'%' identified by "wppass"; Query OK, 0 rows affected (0.00 sec) MariaDB [(none)]> flush privileges; Query OK, 0 rows affected (0.00 sec)
###Test remote connection database [root@c2 ~]# mysql -uwpuser -pwppass -hc3 Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 3 Server version: 5.5.65-MariaDB MariaDB Server Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]>
2.3 download and decompress the WordPress blog program on the official website to the website directory
[root@c2 html]# ls wordpress wordpress-5.0.3.tar.gz [root@c2 html]# pwd /var/www/html
2.4 setting wordpress directory permissions
[root@c2 html]# setfacl -R -m u:apache:rwx wordpress
2.5 open http://c3/wordpress for page installation
3. Collect apache access logs and implement graphical display.
3.1 rsyslog collects apache access logs
3.1.1 modify apache configuration file
[root@c2 ~]# vim /etc/httpd/conf/httpd.conf #CustomLog "logs/access_log" combined CustomLog "|/usr/bin/logger -p local6.info" combined
3.1.2 modify the configuration file of rsyslog
[root@c2 ~]# vim /etc/rsyslog.conf local6.* /var/log/apache_access_log
3.1.3 restart rsyslog and apache services
[root@c2 ~]# systemctl restart rsyslog.service httpd.service
3.2 rsyslog logs in MySQL
3.2.1 authorize rsyslog on mysql server to connect to database server
[root@mariadb ~]# mysql Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 59 Server version: 5.5.65-MariaDB MariaDB Server Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> grant all on Syslog.* to 'apache'@'%' identified by 'centos'; Query OK, 0 rows affected (0.01 sec) MariaDB [(none)]> flush privileges; Query OK, 0 rows affected (0.00 sec)
3.2.2 install mysql module related packages on rsyslog server
[root@c2 ~]# yum install rsyslog-mysql -y
3.2.3 create database and table for rsyslog
[root@c2 ~]# mysql -uapache -pcentos -h c3 < /usr/share/doc/rsyslog-8.24.0/mysql-createDB.sql
[root@c2 ~]# mysql -uapache -pcentos -h c3 -e "show databases;" +--------------------+ | Database | +--------------------+ | information_schema | | Syslog | | test | +--------------------+
3.2.4 configure rsyslog to save logs to mysql
[root@c2 ~]# vim /etc/rsyslog.conf
local6.* :ommysql:10.0.1.244,Syslog,apache,centos
3.2.5 restart rsyslogd service
[root@c2 ~]# systemctl restart rsyslog.service
3.2.6 verify whether the database has log records
MariaDB [(none)]> select * from Syslog.SystemEvents order by DeviceReportedTime DESC limit 1\G *************************** 1. row *************************** ID: 172 CustomerID: NULL ReceivedAt: 2020-05-15 20:20:52 DeviceReportedTime: 2020-05-15 20:20:52 Facility: 22 Priority: 6 FromHost: c2 Message: 192.168.10.206 - - [15/May/2020:20:20:50 +0800] "GET /log/src/chartgenerator.php?type=1&byfield=syslogtag&width=400&maxrecords=10&showpercent=0&defaultfilter= HTTP/1.1" 200 987 "http://10.0.1.243/log/src/statistics.php" "Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko Core/1.70.3722.400 QQBrowser/10.5.3751.400" NTSeverity: NULL Importance: NULL EventSource: NULL EventUser: NULL EventCategory: NULL EventID: NULL EventBinaryData: NULL MaxAvailable: NULL CurrUsage: NULL MinUsage: NULL MaxUsage: NULL InfoUnitID: 1 SysLogTag: root: EventLogType: NULL GenericFileName: NULL SystemID: NULL processid: checksum: 0 1 row in set (0.01 sec)
3.3 display logs in database through log analyzer
3.3.1 install the drawing tool PHP Gd on the rsyslog server
[root@c2 ~]# yum install php-gd -y
3.3.2 install LogAnalyzer
[root@c2 html]# tar xvf loganalyzer-4.1.5.tar.gz [root@c2 html]# mv loganalyzer-4.1.5 log [root@c2 html]# cd loganalyzer/ [root@c2 loganalyzer]# touch config.php [root@c2 loganalyzer]# chmod 666 config.php
3.3.3 configure loganalyzer
[root@c2 html]# setfacl -Rm u:apache:rwx loganalyzer [root@c2 loganalyzer]# systemctl restart httpd.service
In the browser address bar, enter: http://10.0.1.243/log
Click on src
3.3.4 safety enhancement
[root@c2]#cd /var/www/html/loganalyzer [root@c2]#chmod 644 config.php