1、部署分離的LAMP,部署到二臺服務器上,php加載xcache模塊
1)準備兩臺主機
192.168.47.100主機,安裝httpd和mariadb
192.168.47.101主機,安裝php-fpm
2)192.168.47.100主機
[root @ centos7 ~]#yum install httpd mariadb-server -y
[root @ centos7 ~]#vim /etc/httpd/conf.d/fcgi.conf
DirectoryIndex index.php
ProxyRequests Off
ProxyPassMatch ^/(.*\.php)$ fcgi://192.168.47.101:9000/data/www/$1
注意:在HTTPD服務器上必須啓用proxy_fcgi_module模塊,充當PHP客戶端
httpd –M |grep fcgi
cat /etc/httpd/conf.modules.d/00-proxy.conf
[root @ centos7 ~]# systemctl start httpd mariadb
創建Php使用的賬號
[root @ centos7 ~]#mysql
MariaDB [(none)]> grant all on test.* to testuser@'192.168.47.%' identified by 'centos';
MariaDB [(none)]> flush privileges;
MariaDB [(none)]> \q
3)192.168.47.101主機
[root@centos7_2 ~]# yum install -y php-fpm php-mysql
[root@centos7_2 ~]# vim /etc/php-fpm.d/www.conf
;listen = 127.0.0.1:9000
listen =192.168.47.101:9000
listen.allowed_clients = 192.168.47.100
[root@centos7_2 ~]# mkdir -pv /data/www/
[root@centos7_2 ~]# vim /data/www/index.php
<?php
phpinfo();
?>
[root@centos7_2 ~]# systemctl start php-fpm
測試
安裝xcache模塊
[root@centos7_2 ~]# yum install -y php-xcache
[root@centos7_2 ~]# systemctl restart php-fpm
測試
測試數據庫連接
[root@centos7_2 ~]# vim /data/www/sqltest.php
<?php
$conn = mysql_connect('192.168.47.100','testuser','centos');
if ($conn)
echo "OK\n";
else
echo "Failure\n";
#echo mysql_error();
mysql_close();
?>
[root@centos7_2 ~]# systemctl restart php-fpm
測試
2、部署wordpress論壇,並實現正常訪問登錄論壇
使用版本:wordpress-5.0.4-zh_CN.tar.gz 下載路徑:https://cn.wordpress.org/download/releases/
準備兩臺主機:一臺安裝apache和php 一臺安裝數據庫
1)192.168.47.100主機
[root @ centos7 data]#yum install httpd php php-mysql
[root @ centos7_1 data]#tar xvf wordpress-5.0.4-zh_CN.tar.gz
[root @ centos7_1 wordpress]#cd wordpress/
[root @ centos7_1 wordpress]#cp wp-config-sample.php wp-config.php
[root @ centos7_1 wordpress]#vim wp-config.php
define( 'DB_NAME', 'wpdb' );
/** MySQL數據庫用戶名 */
define( 'DB_USER', 'wpuser' );
/** MySQL數據庫密碼 */
define( 'DB_PASSWORD', 'centos' );
/** MySQL主機 */
define( 'DB_HOST', '192.168.47.101' );
[root @ centos7_1 data]#mv wordpress /var/www/html/
前臺測試:
192.168.47.100/wordpress/
2)192.168.47.101主機
[root@centos7_2 ~]# yum install mariadb-server
[root@centos7_2 ~]# systemctl start mariadb
[root@centos7_2 ~]# mysql
MariaDB [(none)]> create database wpdb;
MariaDB [wpdb]> grant all on wpdb.* to wpuser@'192.168.47.%' identified by 'centos';
MariaDB [wpdb]> flush privileges;
3、收集apache訪問日誌,並實現圖形化展示。
1)實現原理
實現過程:想圖形化展示日誌,可以利用rsyslog的前端展示工具loganalyzer來展示,這個工具是基於LAMP架構來實現的,在這之前我們先把apache的訪問日誌交給rsyslog,rsyslog再把對應的日誌寫到數據庫裏,然後通過日誌展示工具loganalyzer去數據庫把日誌讀出來,然後展示出來
2)實驗準備
準備兩臺主機:一臺部署數據庫;一臺部署LAP
3)192.168.47.100主機
[root @ centos7 ~]#yum install httpd php php-mysql -y
[root @ centos7 ~]#vim /etc/httpd/conf/httpd.conf
ErrorLog "syslog:local1"
CustomLog "|/usr/bin/logger -p local2.info" combined
[root @ centos7 ~]#yum install rsyslog-mysql
[root @ centos7 ~]#rpm -ql rsyslog-mysql
/usr/lib64/rsyslog/ommysql.so
/usr/share/doc/rsyslog-8.24.0/mysql-createDB.sql
[root @ centos7 ~]#scp /usr/share/doc/rsyslog-8.24.0/mysql-createDB.sql 192.168.47.101:/data
修改配置文件
[root @ centos7 ~]#vim /etc/rsyslog.conf
$ModLoad ommysql
local1.* :ommysql:192.168.47.101,Syslog,loguser,centos
local2.* :ommysql:192.168.47.101,Syslog,loguser,centos
[root @ centos7 ~]#systemctl restart rsyslog httpd
測試:
[root @ centos7 ~]#echo "this is test page" > /var/www/html/test.php
[root @ centos7 ~]#curl -I http://192.168.47.100/test.php
loganalyzer-4.1.11 安裝
[root@centos7_3 data]# tar -xvf loganalyzer-4.1.11.tar.gz -C /var/www/html/
[root@centos7_3 html]# mv loganalyzer-4.1.11/ log
[root @ centos7 html]#cd log/
[root@centos7_3 log]# mv src/ ../logs
[root @ centos7 log]#cd ../logs/
[root@centos7_3 html]# touch config.php
[root@centos7_3 html]# chmod 666 config.php
[root@centos7_3 html]# systemctl restart httpd
4)192.168.47.101主機
1)[root@centos7_2 ~]# yum install mariadb-server -y
2)[root@centos7_2 ~]# systemctl start mariadb
3)[root@centos7_2 ~]# mysql < /data/mysql-createDB.sql
4)[root@centos7_2 ~]# mysql -e "grant all on Syslog.* to loguser@'192.168.47.%' identified by 'centos'"
收回權限
[root@centos7_3 logs]# chmod 644 config.php
要顯示圖形界面,需要安裝php-gd
[root@centos7_3 logs]# yum install php-gd
[root@centos7_3 logs]# systemctl restart httpd