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

测试

image  

安装xcache模块

[root@centos7_2 ~]# yum install -y php-xcache

[root@centos7_2 ~]# systemctl restart php-fpm

测试

image  

测试数据库连接

[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

测试

image  

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  

image  

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'"

image

image

 

image-20201201234018439

收回权限

[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

image-20201201234358964