LAMP的实战应用

1、部署分离的LAMP,部署到二台服务器上,php加载xcache模块

10.0.0.7  web
10.0.0.17 db

1.1 WEB端安装httpd

[root@web ~]# yum -y install https://mirrors.tuna.tsinghua.edu.cn/remi/enterprise/remi-release-7.rpm
[root@web ~]# yum -y install php56-php php56-php-mysqlnd
[root@web ~]# systemctl enable --now httpd

1.2 DB端安装数据库并创建书库和用户

[root@db ~]# yum -y install mariadb-server
[root@db ~]# systemctl enable --now mariadb
[root@db ~]# mysql
MariaDB [(none)]> create database wordpress;
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> grant all on wordpress.* to wordpress@'10.0.0.%' identified by 'Jhd2021@';
Query OK, 0 rows affected (0.00 sec)

1.3 WEB端部署wordpress并测试

[root@web ~]# wget https://cn.wordpress.org/latest-zh_CN.zip
[root@web ~]# unzip latest-zh_CN.zip^C
[root@web ~]# mv wordpress/ /var/www/html/
[root@web ~]# cd /var/www/html/
[root@web html]# chown -R apache.apache wordpress/
#通过别的主机进行测试
[root@db ~]# ab -c 10 -n 100 http://10.0.0.7/wordpress/
...
Requests per second:    4.35 [#/sec] (mean)
...

1.4 编译安装xcache 并行速度测试

#安装编译xcache
[root@web ~]# yum -y install gcc php56-php-devel
#下载并解压缩xcache-3.2.0.tar.bz2
[root@web ~]# tar zxf xcache-3.2.0.tar.gz 
[root@web ~]# cd xcache-3.2.0/

[root@web xcache-3.2.0]# /opt/remi/php56/root/usr/bin/phpize
Configuring for:
PHP Api Version:         20131106
Zend Module Api No:      20131226
Zend Extension Api No:   220131226

[root@web xcache-3.2.0]# ./configure --enable-xcache --with-php-config=/opt/remi/php56/root/usr/bin/php-config

[root@web xcache-3.2.0]# make && make install
....
Installing shared extensions:     /opt/remi/php56/root/usr/lib64/php/modules/
#通过访问测试
[root@db ~]# ab -c 10 -n 100 http://10.0.0.7/wordpress/
...
Requests per second:    14.74 [#/sec] (mean)
...

2、部署wordpress论坛,并实现正常访问登录论坛。

[root@localhost ~]# yum -y install https://mirrors.tuna.tsinghua.edu.cn/remi/enterprise/remi-release-7.rpm
[root@localhost ~]# sed -i 's#enabled=0#enabled=1#g'  /etc/yum.repos.d/remi-php74.repo
[root@localhost ~]# yum -y install php56-php php56-php-mysqlnd mariadb-server
[root@localhost ~]# systemctl enable --now httpd mariadb
[root@localhost ~]# mysql
MariaDB [(none)]> create database wordpress;
MariaDB [(none)]> grant all on wordpress.* to wordpress@'localhost' identified by 'jhd2021@';

[root@localhost ~]# wget https://cn.wordpress.org/latest-zh_CN.zip\
[root@localhost ~]# unzip latest-zh_CN.zip 
[root@localhost ~]# mv wordpress/ /var/www/html/
[root@localhost ~]# chown -R apache.apache /var/www/html/

#浏览器访问
#http://10.0.0.7/wordpress

#安全加固
#用浏览器访问https://api.wordpress.org/secret-key/1.1/salt/,替代下面wp-config.php内容
[root@centos8 ~]#vim /var/www/html/wp-config.php

3、收集apache访问日志,并实现图形化展示。

3.1 修改Apache和rsyslog配置文件

#修改apache配置文件
[root@web ~]# vim /etc/httpd/conf/httpd.conf
....
CustomLog "logs/access_log" combined
CustomLog "/usr/bin/logger -p local6.info" combined

#修改rsyslog的配置文件
[root@web ~]# vim /etc/rsyslog.conf 
local6.*                           /var/log/apache_access_log

#重启rsyslog和apache服务
[root@web ~]# systemctl restart rsyslog.service httpd.service 

3.2 在mysql server上授权rsyslog能连接至数据库服务器

#在mysql server上授权rsyslog能连接至数据库服务器
[root@db ~]# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 5
Server version: 5.5.68-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 'jhd2021@';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> flush privileges;

3.3 配置rsyslog

# 在rsyslog服务器上安装mysql模块相关的程序包
[root@web ~]# yum -y install rsyslog-mysql.x86_64 

# 为rsyslog创建数据库及表
[root@web ~]# mysql -uapache -pjhd2021@ -h10.0.0.17 < /usr/share/doc/rsyslog-8.24.0/mysql-createDB.sql
[root@web ~]# mysql -uapache -pjhd2021@ -h10.0.0.17 -e "show databases;"
+--------------------+
| Database           |
+--------------------+
| information_schema |
| Syslog             |
| test               |
+--------------------+

#配置rsyslog将日志保存到mysql中
[root@web ~]# vim /etc/rsyslog.conf 
local6.* :ommysql:10.0.0.17,Syslog,apache,jhd2021@

#重启rsyslogd服务
[root@web ~]# systemctl restart rsyslog.service

#在rsyslog服务器上安装绘图工具php-gd
[root@web ~]# yum -y  install php-gd 

#下载
[root@web ~]# wget -c https://download.adiscon.com/loganalyzer/loganalyzer-4.1.11.tar.gz
[root@web ~]# tar zxf loganalyzer-4.1.11.tar.gz 
[root@web ~]# mv loganalyzer-4.1.11 /var/www/html/
[root@web html]# mv loganalyzer-4.1.11 loganalyzer
[root@web html]# cd loganalyzer/
[root@web loganalyzer]# touch config.php
[root@web loganalyzer]# chmod 666 config.php
[root@web html]# setfacl -Rm u:apache:rwx loganalyzer
[root@web html]# systemctl restart httpd.service 

在浏览器输入 http://10.0.0.7/loganalyzer/
1.png
2.png
3.png
4.png
5.png
6.png
7.png
8.png
9.png
10.png
11.png

3.4 安全加固

#安全加固
[root@web ~]# cd /var/www/html/loganalyzer
[root@web ~]# chmod 644 config.php

你可能感兴趣的:(LAMP的实战应用)