十七、LAMP部署与日志收集

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

1.部署环境

HOST           IP          SOFTWARE              PLATFORM
主机1      10.50.100.20    httpd+php+xcache       CentOS7
主机2      10.50.100.22    mariadb                CentOS7
关闭Firewall和SElinux。

2.Host1安装httpd、php、xcache

[root@host1 ~]# yum -y install httpd php php-devel php-mysql gcc
[root@host1 ~]# ll
total 176
-rw-------. 1 root root   1418 Jan 12 16:32 anaconda-ks.cfg
-rw-r--r--. 1 root root 173368 Jun 11  2021 xcache-3.2.0.tar.gz
[root@host1 ~]# tar xvf xcache-3.2.0.tar.gz 
[root@host1 ~]# cd xcache-3.2.0
[root@host1 xcache-3.2.0]# phpize 
Configuring for:
PHP Api Version:         20100412
Zend Module Api No:      20100525
Zend Extension Api No:   220100525
[root@host1 xcache-3.2.0]# ./configure --enable-xcache
[root@host1 xcache-3.2.0]# make && make install
[root@host1 xcache-3.2.0]# systemctl start httpd

3.Host2安装mariadb

[root@host2 ~]# yum -y install mariadb-server
[root@host2 ~]# systemctl enable --now mariadb
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
[root@host2 ~]# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 2
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 test.* to test@'10.50.100.%' identified by '123456';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> exit
Bye
[root@host2 ~]# 

4.Host1编写php测试脚本

[root@host1 ~]# vim /var/www/html/index.php
<?php
$conn = mysql_connect('10.50.100.22','test','123456');
if ($conn)
echo "Sucess\n";
else
echo "Failure\n";
mysql_close();
?>
[root@host1 ~]# curl 10.50.100.20/index.php
Sucess

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

1.部署LAMP环境

[root@localhost ~]# dnf -y install httpd php php-json php-mysqlnd mariadb-server
[root@localhost ~]# systemctl enable --now httpd mariadb
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.
Created symlink /etc/systemd/system/mysql.service → /usr/lib/systemd/system/mariadb.service.
Created symlink /etc/systemd/system/mysqld.service → /usr/lib/systemd/system/mariadb.service.
Created symlink /etc/systemd/system/multi-user.target.wants/mariadb.service → /usr/lib/systemd/system/mariadb.service.
[root@localhost ~]# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 8
Server version: 10.3.28-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 wordpress;
Query OK, 1 row affected (0.000 sec)

MariaDB [(none)]> grant all on wordpress.* to wordpress@'localhost' identified by '123456';
Query OK, 0 rows affected (0.000 sec)

MariaDB [(none)]> exit
Bye
[root@localhost ~]# 

2.安装wordpress

[root@localhost ~]# ll
total 17208
-rw-------. 1 root root     1544 Nov  9  2020 anaconda-ks.cfg
-rw-r--r--. 1 root root 17615668 Jun  7 15:45 wordpress-5.7.2-zh_CN.zip
[root@localhost ~]# unzip wordpress-5.7.2-zh_CN.zip 
[root@localhost ~]# ll
total 17212
-rw-------. 1 root root     1544 Nov  9  2020 anaconda-ks.cfg
drwxr-xr-x. 5 root root     4096 Jun  6 13:00 wordpress
-rw-r--r--. 1 root root 17615668 Jun  7 15:45 wordpress-5.7.2-zh_CN.zip
[root@localhost ~]# mv wordpress/* /var/www/html/
[root@localhost ~]# chown -R apache.apache /var/www/html/
[root@localhost ~]# ll /var/www/html/
total 204
-rw-r--r--.  1 apache apache   405 Feb  6  2020 index.php
-rw-r--r--.  1 apache apache 19915 Jan  1 08:19 license.txt
-rw-r--r--.  1 apache apache  7345 Dec 30 04:14 readme.html
-rw-r--r--.  1 apache apache  7165 Jan 21 09:37 wp-activate.php
drwxr-xr-x.  9 apache apache  4096 Jun  6 13:00 wp-admin
-rw-r--r--.  1 apache apache   351 Feb  6  2020 wp-blog-header.php
-rw-r--r--.  1 apache apache  2328 Feb 17 21:08 wp-comments-post.php
-rw-r--r--.  1 apache apache  2913 Feb  6  2020 wp-config-sample.php
drwxr-xr-x.  5 apache apache    69 Jun  6 13:00 wp-content
-rw-r--r--.  1 apache apache  3939 Jul 31  2020 wp-cron.php
drwxr-xr-x. 25 apache apache  8192 Jun  6 13:00 wp-includes
-rw-r--r--.  1 apache apache  2496 Feb  6  2020 wp-links-opml.php
-rw-r--r--.  1 apache apache  3313 Jan 11 03:28 wp-load.php
-rw-r--r--.  1 apache apache 44994 Apr  5 02:34 wp-login.php
-rw-r--r--.  1 apache apache  8509 Apr 14  2020 wp-mail.php
-rw-r--r--.  1 apache apache 21125 Feb  2 08:10 wp-settings.php
-rw-r--r--.  1 apache apache 31328 Jan 28 05:03 wp-signup.php
-rw-r--r--.  1 apache apache  4747 Oct  9  2020 wp-trackback.php
-rw-r--r--.  1 apache apache  3236 Jun  9  2020 xmlrpc.php
[root@localhost ~]# 






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

1.部署LAMP环境

[root@localhost ~]# dnf -y install httpd php php-mysqlnd rsyslog-mysql mariadb-server
[root@localhost ~]# systemctl enable --now httpd mariadb
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.
Created symlink /etc/systemd/system/mysql.service → /usr/lib/systemd/system/mariadb.service.
Created symlink /etc/systemd/system/mysqld.service → /usr/lib/systemd/system/mariadb.service.
Created symlink /etc/systemd/system/multi-user.target.wants/mariadb.service → /usr/lib/systemd/system/mariadb.service.

2.创建数据库

[root@localhost ~]# mysql < /usr/share/doc/rsyslog/mysql-createDB.sql
[root@localhost ~]# mysql -e 'grant all on Syslog.* to rsyslog@"10.50.100.%" identified by "123456";flush privileges;'

3.修改配置文件

[root@localhost ~]# vim /etc/httpd/conf/httpd.conf
    #CustomLog "logs/access_log" combined  注释改行,新增下面一行
     Customlog "| /usr/bin/logger -p local6.info" combined
[root@localhost ~]# vim /etc/rsyslog.conf
##添加
#### MODULES ####
$ModLoad ommysql
##添加   
#### RULES ####
local6.*                                                :ommysql:127.0.0.1,Syslog,rsyslog,123456
[root@localhost ~]# systemctl start httpd rsyslog

4.安装loganalyzer

[root@localhost ~]# ll
total 2880
-rw-------. 1 root root    1544 Nov  9  2020 anaconda-ks.cfg
-rw-r--r--. 1 root root 2943771 Jun 11 15:24 loganalyzer-4.1.10.tar.gz
[root@localhost ~]# tar xvf loganalyzer-4.1.10.tar.gz 
[root@localhost ~]# mv loganalyzer-4.1.10/src/ /var/www/html/log
[root@localhost ~]# touch /var/www/html/log/config.php
[root@localhost ~]# chmod 666 /var/www/html/log/config.php 
[root@localhost ~]# systemctl restart httpd rsyslog








5.安装loganalyzer后取消文件夹权限

[root@localhost ~]# chmod 644 /var/www/html/log/config.php 
posted @ 2021-06-11 16:29  人生值得  阅读(99)  评论(0编辑  收藏  举报