编译安装基于fastcgi模式的多虚拟主机的wordpress和discuz的LAMP架构

Posted 一直在努力学习的菜鸟

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了编译安装基于fastcgi模式的多虚拟主机的wordpress和discuz的LAMP架构相关的知识,希望对你有一定的参考价值。

编译安装基于fastcgi模式的多虚拟主机的wordpress和discuz的LAMP架构

环境准备:

IP服务器及操作系统描述
10.0.0.7CentOS-7.9httpd+php(fastcgi模式)
10.0.0.17MariaDB-10.4.22(通用二进制格式)mariadb 服务器

软件版本:

  • apr-1.7.0.tar.bz2
  • apr-util-1.6.1.tar.bz2
  • httpd-2.4.46.tar.bz2
  • php-7.4.28.tar.gz
  • wordpress-5.4.1-zh_CN.tar.gz
  • Discuz_X3.4_SC_UTF8_20210630.zip

实现步骤

1、为wordprss和discuz应用准备数据库和用户帐号

[root@centos7 ~]#vim /etc/my.cnf
skip_name_resolve = ON
[root@centos7 ~]#systemctl restart mysqld

MariaDB [mysql]> create database wordpress;
MariaDB [mysql]> create database discuz;
MariaDB [mysql]> grant all on wordpress.* to wordpress@'10.0.0.%' identified by "wppass";
MariaDB [mysql]> grant all on discuz.* to discuz@'10.0.0.%' identified by 'dispass';
MariaDB [mysql]> FLUSH PRIVILEGES;

2、编译安装 httpd 2.4

#安装相关包
[root@centos7 ~]#yum install gcc pcre-devel openssl-devel expat-devel -y

#编译安装httpd
[root@centos7 ~]#tar xvf apr-1.7.0.tar.bz2
[root@centos7 ~]#tar xvf apr-util-1.6.1.tar.bz2
[root@centos7 ~]#tar xf httpd-2.4.46.tar.bz2
[root@centos7 ~]#mv apr-1.7.0 httpd-2.4.46/srclib/apr
[root@centos7 ~]#mv apr-util-1.6.1 httpd-2.4.46/srclib/apr-util

[root@centos7 ~]#cd httpd-2.4.46/
[root@centos7 httpd-2.4.46]#./configure \\
> --prefix=/apps/httpd \\
> --enable-so \\
> --enable-ssl \\
> --enable-cgi \\
> --enable-rewrite \\
> --with-zlib \\
> --with-pcre \\
> --with-included-apr \\
> --enable-modules=most \\
> --enable-mpms-shared=all \\
> --with-mpm=event

[root@centos7 httpd-2.4.46]#make && make install

#准备PATH变量
[root@centos7 httpd-2.4.46]#vim /etc/profile.d/lamp.sh
#!/bin/bash
PATH=/apps/httpd/bin:$PATH
[root@centos7 httpd-2.4.46]#. /etc/profile.d/lamp.sh

#创建和配置用户和组
[root@centos7 httpd-2.4.46]#useradd -s /sbin/nologin -r -u 88 apache
[root@centos7 httpd-2.4.46]#vim /apps/httpd/conf/httpd.conf
User apache
Group apache

#修改为event模式,编译时已指定,此项不再需修改,可选项
[root@centos7 httpd-2.4.46]#vim /apps/httpd/conf/httpd.conf
LoadModule mpm_event_module modules/mod_mpm_event.so

#LoadModule mpm_prefork_module modules/mod_mpm_prefork.so
#LoadModule mpm_worker_module modules/mod_mpm_worker.so

[root@centos7 httpd-2.4.46]#httpd -M |grep mpm
 mpm_event_module (shared)

[root@centos7 httpd-2.4.46]#apachectl start

[root@centos7 httpd-2.4.46]#vim /usr/lib/systemd/system/httpd.service
[Unit]
Description=The Apache HTTP Server
After=network.target remote-fs.target nss-lookup.target
Documentation=man:httpd(8)
Documentation=man:apachectl(8)

[Service]
Type=forking
#EnvironmentFile=/etc/sysconfig/httpd
#ExecStart=/usr/sbin/httpd $OPTIONS -DFOREGROUND
ExecStart=/apps/httpd/bin/apachectl start
#ExecReload=/usr/sbin/httpd $OPTIONS -k graceful
ExecReload=/apps/httpd/bin/apachectl graceful
ExecStop=/apps/httpd/bin/apachectl stop
KillSignal=SIGCONT
PrivateTmp=true

[Install]
WantedBy=multi-user.target

[root@centos7 httpd-2.4.46]#systemctl daemon-reload
[root@centos7 httpd-2.4.46]#systemctl restart httpd.service

3、编译安装 fastcgi 方式的 php 7.4

#安装相关包,依赖EPEL源
#php 7.4 相关包
[root@centos7 httpd-2.4.46]#yum -y install gcc libxml2-devel bzip2-devel libmcrypt-devel sqlite-devel oniguruma-devel

#php7.4 编译
[root@centos7 httpd-2.4.46]#cd
[root@centos7 ~]#tar xvf php-7.4.28.tar.gz
[root@centos7 ~]#cd php-7.4.28/
[root@centos7 php-7.4.28]#./configure \\
> --prefix=/apps/php \\
> --enable-mysqlnd \\
> --with-mysqli=mysqlnd \\
> --with-pdo-mysql=mysqlnd \\
> --with-openssl \\
> --with-zlib \\
> --with-config-file-path=/etc \\
> --with-config-file-scan-dir=/etc/php.d \\
> --enable-mbstring \\
> --enable-xml \\
> --enable-sockets \\
> --enable-fpm \\
> --enable-maintainer-zts \\
> --disable-fileinfo

[root@centos7 php-7.4.28]#make -j 2 && make install

#准备PATH变量
[root@centos7 php-7.4.28]#vim /etc/profile.d/lamp.sh
PATH=/apps/php/bin:/apps/httpd/bin:$PATH
[root@centos7 php-7.4.28]#. /etc/profile.d/lamp.sh
[root@centos7 php-7.4.28]#php --version
PHP 7.4.28 (cli) (built: Mar 12 2022 14:55:19) ( ZTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies

#准备php配置文件和启动文件
[root@centos7 php-7.4.28]#cp php.ini-production /etc/php.ini
[root@centos7 php-7.4.28]#cp sapi/fpm/php-fpm.service /usr/lib/systemd/system/
[root@centos7 php-7.4.28]#cd /apps/php/etc
[root@centos7 etc]#cp php-fpm.conf.default php-fpm.conf
[root@centos7 etc]#cd php-fpm.d/
[root@centos7 php-fpm.d]#cp www.conf.default www.conf

#修改进程所有者
[root@centos7 php-fpm.d]#pwd
/apps/php/etc/php-fpm.d
[root@centos7 php-fpm.d]#vim www.conf
user = apache
group = apache

#支持status和ping页面
pm.status_path = /fpm_status
ping.path = /ping

#支持opcache加速
[root@centos7 php-fpm.d]#mkdir /etc/php.d/
[opcache]
zend_extension=opcache.so
opcache.enable=1

[root@centos7 php-fpm.d]#systemctl daemon-reload
[root@centos7 php-fpm.d]#systemctl enable --now php-fpm.service

4、修改配置 httpd 支持 php-fpm

[root@centos7 php-7.4.28]#vim /apps/httpd/conf/httpd.conf
#取消下面两行的注释
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
#修改下面行
<IfModule dir_module>
    DirectoryIndex index.php index.html
</IfModule>

#加下面两行
AddType application/x-httpd-php .php
ProxyRequests Off

#实现第一个虚拟主机
<virtualhost *:80>
servername blog.linux2022.com
documentroot /data/blog
<directory /data/blog>
require all granted
</directory>
ProxyPassMatch ^/(.*\\.php)$ fcgi://127.0.0.1:9000/data/blog/$1
#实现status和ping页面
ProxyPassMatch ^/(fpm_status|ping)$ fcgi://127.0.0.1:9000/$1
CustomLog "logs/access_blog_log" common
</virtualhost>

#第二个虚拟主机
<virtualhost *:80>
servername forum.linux2022.com
documentroot /data/forum
<directory /data/forum/>
require all granted
</directory>
ProxyPassMatch ^/(.*\\.php)$ fcgi://127.0.0.1:9000/data/forum/$1
CustomLog "logs/access_forum_log" common
</virtualhost>

[root@centos7 php-7.4.28]#systemctl restart httpd.service

5、准备wordpress和discuz 相关文件

[root@centos7 php-fpm.d]#cd /data/
[root@centos7 data]#mkdir blog forum
[root@centos7 ~]#tar xf latest-zh_CN.tar.gz
[root@centos7 ~]#mv wordpress/* /data/blog/
[root@centos7 ~]#mv Discuz_X3.4_SC_UTF8_20210630.zip /opt
[root@centos7 ~]#cd /opt
[root@centos7 opt]#unzip Discuz_X3.4_SC_UTF8_20210630.zip
[root@centos7 opt]#mv upload/* /data/forum/
[root@centos7 opt]#chown -R apache.apache /data/*

6、测试访问

[root@centos7 ~]#vim /etc/hosts
10.0.0.7 blog.linux2022.com forum.linux2022.com

编译安装基于FASTCGI模式LAMP架构多虚拟主机WEB应用及loganalyzer图形化日志

1 编译安装基于FASTCGI模式LAMP架构多虚拟主机WEB应用

1.1 目标

实现CentOS 7 编译安装基于 fastcgi 模式及opcache加速的多虚拟主机的wordpress和discuz的LAMP架构

1.2 环境准备

两台主机:

centos7(apache2.4.48+php7.4+fastcgi+opcache)        192.168.100.27
centos8(mariadb10.5.9)                              192.168.100.28

软件版本:

  • CentOS 7.9
  • mariadb-10.5.9-linux-x86_64.tar.gz 通用二进制格式
  • apr-1.7.0.tar.bz2
  • apr-util-1.6.1.tar.bz2
  • httpd-2.4.48.tar.gz
  • php-7.4.23.tar.xz 或 php-7.3.10.tar.bz2
  • wordpress-5.8.1-zh_CN.tar.gz
  • Discuz_X3.4_SC_UTF8_20210816.zip

1.3 实现步骤

1.3.1 centos8一键安装mariadb10.5.9二进制脚本

#把mariadb-10.5.9-linux-x86_64.tar.gz文件和auto_mariadb1059.sh脚本放在同一目录中,如/data
[root@centos8 data]# ls
auto_mariadb1059.sh mariadb-10.5.9-linux-x86_64.tar.gz
[root@centos8 data]# vim auto_mariadb1059.sh
#!/bin/bash

. /etc/init.d/functions 
SRC_DIR=`pwd`
MYSQL=\'mariadb-10.5.9-linux-x86_64.tar.gz\'
COLOR="echo -e \\\\033[01;31m"
END=\'\\033[0m\'
MYSQL_ROOT_PASSWORD=magedu

check (){
cd  $SRC_DIR
if [ !  -e $MYSQL ];then
        $COLOR"缺少${MYSQL}文件"$END
        $COLOR"请将相关软件放在${SRC_DIR}目录下"$END
        exit
elif [ -e /usr/local/mysql ];then
        action "数据库已存在,安装失败" false
        exit
else
    return
fi
} 

install_mysql(){
    $COLOR"开始安装MySQL数据库..."$END
     yum  -y -q install libaio libtinfo.so.5 &> /dev/null
    cd $SRC_DIR
    tar xf $MYSQL -C /usr/local/
    MYSQL_DIR=`echo $MYSQL| sed -nr \'s/^(.*[0-9]).*/\\1/p\'`
    ln -s  /usr/local/$MYSQL_DIR /usr/local/mysql
    chown -R  root.root /usr/local/mysql/
    id mysql &> /dev/null || { groupadd mysql -g336; useradd -s /sbin/nologin -r mysql -u336 -g mysql; action "创建mysql用户"; }
#创建数据目录
    mkdir /data/mysql -p
    chown -R mysql.mysql /data/mysql
    [ $? -eq 0 ] &> /dev/null && action "创建mysql数据目录"
#准备PATH变量,centos8不能启动
echo \'PATH=/usr/local/mysql/bin/:$PATH\' > /etc/profile.d/mysql.sh
. /etc/profile.d/mysql.sh
#准备my.cnf文件    
cat > /etc/my.cnf <<-EOF
[mysqld]
datadir=/data/mysql
skip_name_resolve=ON
log-error=/data/mysql/mysql.log
binlog_format=ROW
default-storage-engine=innodb
innodb_autoinc_lock_mode=2
bind-address=0.0.0.0
wsrep_on=1
wsrep_provider=none
wsrep_cluster_name="my_wsrep_cluster"
wsrep_slave_threads=1
wsrep_certify_nonPK=1
wsrep_max_ws_rows=0
wsrep_max_ws_size=2147483647
wsrep_debug=0
wsrep_convert_LOCK_to_trx=0
wsrep_retry_autocommit=1
wsrep_auto_increment_control=1
wsrep_drupal_282555_workaround=0
wsrep_causal_reads=0
wsrep_notify_cmd=
wsrep_sst_method=rsync
wsrep_sst_auth=root:
EOF

cd /usr/local/mysql;./scripts/mysql_install_db --user=mysql --datadir=/data/mysql
cp support-files/mysql.server /etc/rc.d/init.d/mysqld

service mysqld start
[ $? -ne 0 ] && { $COLOR"数据库启动失败,退出!"$END;exit; }
action "数据库安装完成" 
}
check
install_mysql

[root@centos8 data]# chmod +x auto_mariadb1059.sh
[root@centos8 data]# . auto_mariadb1059.sh

1.3.2 一键编译安装 httpd 2.4.48

[root@centos7 ~]# cd /data
[root@centos7 data]# ls
apr-1.7.0.tar.bz2  apr-util-1.6.1.tar.bz2  auto_http24by.sh  httpd-2.4.48.tar.bz2  
[root@centos7 data]# vim auto_http24by.sh
#!/bin/bash

. /etc/init.d/functions
COLOR="echo -e \\\\033[01;31m"
END=\'\\033[0m\'

install_httpd24(){
$COLOR"编译安装httpd2.4.48..."$END
#安装相关包
yum install gcc pcre-devel openssl-devel expat-devel lbzip2 make -y &>/dev/null
#编译安装httpd
cd /data
tar xf apr-1.7.0.tar.bz2
tar xf apr-util-1.6.1.tar.bz2
tar xf httpd-2.4.48.tar.bz2
mv apr-1.7.0 httpd-2.4.48/srclib/apr
mv apr-util-1.6.1 httpd-2.4.48/srclib/apr-util
cd httpd-2.4.48/
./configure \\
--prefix=/apps/httpd24 \\
--enable-so \\
--enable-ssl \\
--enable-cgi \\
--enable-rewrite \\
--with-zlib \\
--with-pcre \\
--with-included-apr \\
--enable-modules=most \\
--enable-mpms-shared=all \\
--with-mpm=event &>/dev/null
[ $? -eq 0 ] &> /dev/null && action "configure成功"
make &>/dev/null ||  action "make 失败"
make install &>/dev/null || action "make install 失败"
[ $? -eq 0 ] &> /dev/null && action "编译成功"
#准备PATH变量
echo \'PATH=/apps/httpd24/bin:$PATH\' > /etc/profile.d/http24by.sh
source /etc/profile.d/http24by.sh
#创建和配置用户和组
useradd -s /sbin/nologin -r -u 88 apache
sed -ri \'s/^User.*/User apache/\' /apps/httpd24/conf/httpd.conf
sed -ri \'s/^Group.*/Group apache/\' /apps/httpd24/conf/httpd.conf
#启动
apachectl start
[ $? -eq 0 ] &> /dev/null && action "apache启动成功"
#设置启动脚本
cat > /usr/lib/systemd/system/httpd.service <<EOF
[Unit]
Description=The Apache HTTP Server
After=network.target remote-fs.target nss-lookup.target
Documentation=man:httpd(8)
Documentation=man:apachectl(8)
[Service]
Type=forking
#EnvironmentFile=/etc/sysconfig/httpd
ExecStart=/apps/httpd24/bin/apachectl start
#ExecStart=/apps/httpd24/bin/httpd $OPTIONS -k start
ExecReload=/apps/httpd24/bin/apachectl graceful
#ExecReload=/apps/httpd24/bin/httpd $OPTIONS -k graceful
ExecStop=/apps/httpd24/bin/apachectl stop
KillSignal=SIGCONT
PrivateTmp=true
[Install]
WantedBy=multi-user.target
EOF

systemctl daemon-reload
systemctl start httpd
systemctl enable --now httpd
[ $? -eq 0 ] &> /dev/null && action "httpd开机自启动添加成功"
}
install_httpd24

[root@centos7 data]# chmod +x auto_http24by.sh
[root@centos7 data]# . auto_http24by.sh

1.3.3 一键编译安装 fastcgi 方式的 php 7.4.23

[root@centos7 ~]# cd /data
[root@centos7 data]# ls
auto_http24by.sh php-7.4.23.tar.xz
[root@centos7 data]# vim auto_php74by.sh
#!/bin/bash

. /etc/init.d/functions
COLOR="echo -e \\\\033[01;31m"
END=\'\\033[0m\'

install_php74(){
$COLOR"编译安装php7.4.23..."$END
#安装相关包,依赖EPEL源
RELEASE=`awk -F\' \' \'{print $4}\' /etc/redhat-release|awk -F. \'{print $1}\'`
[ $RELEASE -eq 8 ] && yum -y install gcc libxml2-devel bzip2-devel libmcrypt-devel sqlite-devel pcre-devel openssl-devel autoconf automake libtool php-opcache make &>/dev/null
[ $RELEASE -eq 7 ] && yum -y install gcc libxml2-devel bzip2-devel libmcrypt-devel sqlite-devel oniguruma-devel pcre-devel openssl-devel libtool php-opcache make &>/dev/null

#centos8编译安装oniguruma
[ $RELEASE -eq 8 ] && { tar xf oniguruma-6.9.4.tar.gz; cd oniguruma-6.9.4/; ./autogen.sh && ./configure --prefix=/usr &>/dev/null; make &>/dev/null; make install &>/dev/null; action "centos8编译安装oniguruma成功"; }

#php7.4 编译
cd /data
tar xf php-7.4.23.tar.xz
cd php-7.4.23/
./configure \\
--prefix=/apps/php74 \\
--enable-mysqlnd \\
--with-mysqli=mysqlnd \\
--with-pdo-mysql=mysqlnd \\
--with-openssl \\
--with-zlib \\
--with-config-file-path=/etc \\
--with-config-file-scan-dir=/etc/php.d \\
--enable-mbstring \\
--enable-xml \\
--enable-sockets \\
--enable-fpm \\
--enable-maintainer-zts \\
--disable-fileinfo &>/dev/null
[ $? -eq 0 ] &> /dev/null && action "configure成功"
make &>/dev/null ||  action "make 失败"
make install &>/dev/null || action "make install 失败"
[ $? -eq 0 ] &> /dev/null && action "编译成功"

#php7.4准备PATH变量
echo \'PATH=/apps/php74/bin:$PATH\' > /etc/profile.d/php74.sh
source /etc/profile.d/php74.sh

#准备php配置文件和启动文件
cp php.ini-production /etc/php.ini
cp sapi/fpm/php-fpm.service /usr/lib/systemd/system/
cd /apps/php74/etc
cp php-fpm.conf.default php-fpm.conf
cd php-fpm.d/
cp www.conf.default www.conf
#修改进程所有者
sed -ri \'s/^user.*/user = apache/\' /apps/php74/etc/php-fpm.d/www.conf
sed -ri \'s/^group.*/group = apache/\' /apps/php74/etc/php-fpm.d/www.conf
#支持status和ping页面
sed -ri \'s#^;(pm.status_path.*)#pm.status_path = \\/fpm_status#\' /apps/php74/etc/php-fpm.d/www.conf
sed -ri \'s/^;(ping.path.*)/\\1/\' /apps/php74/etc/php-fpm.d/www.conf

#支持opcache加速
mkdir /etc/php.d/ -p
cat > /etc/php.d/opcache.ini <<EOF
[opcache]
zend_extension=opcache.so
opcache.enable=1
EOF

systemctl daemon-reload
systemctl start php-fpm || action "php-fpm启动失败"
systemctl enable --now php-fpm
[ $? -eq 0 ] &> /dev/null && action "php-fpm开机自启动添加成功"
}
install_php74

[root@centos8 data]# chmod +x auto_php74by.sh
[root@centos8 data]# . auto_php74by.sh

1.3.4 centos7系统一键修改配置httpd 支持php-fpm

#安装好php7后,当前目录是[root@centos7 php-fpm.d],执行以下命令,配置http支持php-fpm

#修改配置文件中的行,实现http支持php页面
sed -ri \'s@#(LoadModule proxy_module modules/mod_proxy.so)@\\1@\' /apps/httpd24/conf/httpd.conf
sed -ri \'s@#(LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so)@\\1@\' /apps/httpd24/conf/httpd.conf
sed -ri \'s@^([[:space:]]+DirectoryIndex) (index.html)@\\1 index.php \\2@\' /apps/httpd24/conf/httpd.conf

cat >> /apps/httpd24/conf/httpd.conf <<EOF
#加下面三行
AddType application/x-httpd-php .php
#AddType application/x-httpd-php-source .phps
ProxyRequests Off

#实现第一个虚拟主机
<virtualhost *:80>
  servername blog.magedu.org
  documentroot /data/wordpress
<directory /data/wordpress>
  require all granted
</directory>
ProxyPassMatch ^/(.*\\.php)$ fcgi://127.0.0.1:9000/data/wordpress/$1
#实现status和ping页面
ProxyPassMatch ^/(fpm_status|ping)$ fcgi://127.0.0.1:9000/$1
CustomLog "logs/access_wordpress_log" common
</virtualhost>

#第二个虚拟主机
<virtualhost *:80>
  servername forum.magedu.org
  documentroot /data/discuz
<directory /data/discuz/>
  require all granted
</directory>
ProxyPassMatch ^/(.*\\.php)$ fcgi://127.0.0.1:9000/data/discuz/$1
CustomLog "logs/access_discuz_log" common
</virtualhost>
EOF

systemctl restart httpd

1.3.5 centos7系统一键准备wordpress和discuz! 相关文件

#准备wordpress程序文件
cd /data/
tar xf wordpress-5.8.1-zh_CN.tar.gz -C /data
setfacl -R -m u:apache:rwx /data/wordpress/
#或者chown -R apache.apache /data/wordpress
#准备discuz!程序文件
cd /data/
rpm -q unzip || yum install unzip -y &>/dev/null
unzip -d Discuz Discuz_X3.4_SC_UTF8_20210816.zip &>/dev/null
mv Discuz/upload/ /data/discuz
setfacl -R -m u:apache:rwx /data/discuz/

1.3.6 centos8创建wordpress和discuz数据库

[root@centos8 ~]# mysql
create database wordpress;
create database discuz;
grant all on wordpress.* to wpuser@\'192.168.100.%\' identified by "wppass";
grant all on discuz.* to disuser@\'192.168.100.%\' identified by "dispass";

1.3.7 测试访问

[root@centos7 data]# echo "192.168.100.27 blog.magedu.org forum.magedu.org" >>/etc/hosts

windows10的windows/system32/drivers/etc/hosts文件中也要添加,这样浏览器中输入域名就可以访问了
192.168.100.27 blog.magedu.org forum.magedu.org
1、打开浏览器访问 http://blog.magedu.org 进行初始化安装,并创建首个博客文章。





#图片上传的目录
[root@c7-pxc2 data]# tree wordpress/wp-content/uploads/
wordpress/wp-content/uploads/
└── 2021
    └── 09
        └── CachedImage_1920_1080_POS2.jpg

2 directories, 1 file

2、浏览器打开http://forum.magedu.org,初始化安装并创建版块。






2 rsyslog日志服务

2.1 利用mysql存储日志信息

2.1.1 目标

利用rsyslog日志服务,将收集的日志记录于MySQL中

2.1.2 环境准备

三台主机,两台日志服务器,一台数据库服务器
c8log       192.168.100.48
c7log       192.168.100.47
c8mariadb   192.168.100.28

2.1.3 实现步骤

2.1.3.1 在rsyslog服务器上安装连接mysql模块相关的程序包

1、centos8安装rsyslog-MySQL模块

[root@c8log ~]# yum install rsyslog-mysql

#查看sql脚本文件内容
[root@c8log ~]# cat /usr/share/doc/rsyslog/mysql-createDB.sql
CREATE DATABASE Syslog;
USE Syslog;
CREATE TABLE SystemEvents
(
        ID int unsigned not null auto_increment primary key,
        CustomerID bigint,
        ReceivedAt datetime NULL,
        DeviceReportedTime datetime NULL,
        Facility smallint NULL,
        Priority smallint NULL,
        FromHost varchar(60) NULL,
        Message text,
        NTSeverity int NULL,
        Importance int NULL,
        EventSource varchar(60),
        EventUser varchar(60) NULL,
        EventCategory int NULL,
        EventID int NULL,
        EventBinaryData text NULL,
        MaxAvailable int NULL,
        CurrUsage int NULL,
        MinUsage int NULL,
        MaxUsage int NULL,
        InfoUnitID int NULL ,
        SysLogTag varchar(60),
        EventLogType varchar(60),
        GenericFileName VarChar(60),
        SystemID int NULL
);

CREATE TABLE SystemEventsProperties
(
        ID int unsigned not null auto_increment primary key,
        SystemEventID int NULL ,
        ParamName varchar(255) NULL ,
        ParamValue text NULL
);

#将sql脚本复制到数据库服库上
[root@c8log ~]# scp /usr/share/doc/rsyslog/mysql-createDB.sql 192.168.100.28:/data

2、centos7安装rsyslog-mysql

[root@c7log ~]# yum install rsyslog-mysql

#由于和centos8下安装的rsyslog-mysql中的数据库名一样,修改为Syslog_c7,而且数据库名称不能使用-,只能用下划线_
[root@c7log ~]# cat /usr/share/doc/rsyslog-8.24.0/mysql-createDB.sql
CREATE DATABASE Syslog_c7;
USE Syslog_c7;
CREATE TABLE SystemEvents
(
        ID int unsigned not null auto_increment primary key,
        CustomerID bigint,
        ReceivedAt datetime NULL,
        DeviceReportedTime datetime NULL,
        Facility smallint NULL,
        Priority smallint NULL,
        FromHost varchar(60) NULL,
        Message text,
        NTSeverity int NULL,
        Importance int NULL,
        EventSource varchar(60),
        EventUser varchar(60) NULL,
        EventCategory int NULL,
        EventID int NULL,
        EventBinaryData text NULL,
        MaxAvailable int NULL,
        CurrUsage int NULL,
        MinUsage int NULL,
        MaxUsage int NULL,
        InfoUnitID int NULL ,
        SysLogTag varchar(60),
        EventLogType varchar(60),
        GenericFileName VarChar(60),
        SystemID int NULL
);

CREATE TABLE SystemEventsProperties
(
        ID int unsigned not null auto_increment primary key,
        SystemEventID int NULL ,
        ParamName varchar(255) NULL ,
        ParamValue text NULL
);
[root@c7log ~]# scp /usr/share/doc/rsyslog-8.24.0/mysql-createDB.sql 192.168.100.28:/data/c7-mysqlcreateDB.sql

2.1.3.2 准备mariadb数据库服务器

使用1.3.1例中的“centos8一键安装mariadb10.5.9二进制脚本”安装mariadb数据库

#安装好数据库后,在mariadb数据库服务器上创建相关数据库和表,并授权rsyslog能连接至当前服务器
[root@c8mariadb data]# mysql < mysql-createDB.sql
[root@c8mariadb data]# mysql < c7-mysqlcreateDB.sql
[root@c8mariadb data]# mysql
Server version: 10.5.9-MariaDB Source distribution
MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| Syslog             |
| Syslog_c7          |
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
6 rows in set (0.001 sec)

#授权账号,centos8使用Syslog库,用户名rsyslogc8,密码mageduc8
MariaDB [(none)]> grant all on Syslog.* to rsyslogc8@\'192.168.100.%\' identified by \'mageduc8\';
#授权账号,centos7使用Syslog_c7库,用户名rsyslogc7,密码mageduc7
MariaDB [(none)]> grant all on Syslog_c7.* to rsyslogc7@\'192.168.100.%\' identified by \'mageduc7\';

2.1.3.3 在日志服务器上分别配置,将日志发送至指定数据库

1、centos8系统下的日志配置
#配置rsyslog将日志保存到mysql中
[root@c8log ~]# vi /etc/rsyslog.conf
####MODULES####
#在 MODULES 语言下面,如果是 CentOS 8 加下面行
module(load="ommysql")
#在RULES语句块加下面行的格式
#facility.priority :ommysql:DBHOST,DBNAME,DBUSER, PASSWORD
*.info             :ommysql:192.168.100.28,Syslog,rsyslogc8,mageduc8

[root@c8log ~]# systemctl restart rsyslog

2、centos7系统下的日志配置
[root@c7log ~]# vi /etc/rsyslog.conf
#在 MODULES 语言下面,如果是 CentOS 7,6 加下面行
$ModLoad ommysql
#在RULES语句块加下面行的格式
*.info              :ommysql:192.168.100.28,Syslog_c7,rsyslogc7,mageduc7
[root@c7log ~]# systemctl restart rsyslog

2.1.3.4 测试

#数据库服务器中,在日志服务器配置好重启服务之前,查看表是空的。
MariaDB [none]> select * from Syslog.SystemEvents;
Empty set (0.001 sec)

MariaDB [Syslog]> select * from Syslog_c7.SystemEvents;
Empty set (0.001 sec)

#日志服务器配置好后,并重启服务,在日志服务器上生成日志
[root@c8log ~]#logger "This is a centos8 log"
[root@c7log ~]#logger "This is a centos7 log"

#在数据库上查询到上面的测试日志
MariaDB [none]> select * from Syslog.SystemEvents\\G;
*************************** 8. row ***************************
                ID: 8
        CustomerID: NULL
        ReceivedAt: 2021-09-15 10:36:30
DeviceReportedTime: 2021-09-15 10:36:30
          Facility: 1
          Priority: 5
          FromHost: c8-slave04
           Message: This is a centos8 log
        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[37867]:
      EventLogType: NULL
   GenericFileName: NULL
          SystemID: NULL

MariaDB [none]> select * from Syslog_c7.SystemEvents\\G;
*************************** 9. row ***************************
                ID: 9
        CustomerID: NULL
        ReceivedAt: 2021-09-15 10:34:27
DeviceReportedTime: 2021-09-15 10:34:27
          Facility: 1
          Priority: 5
          FromHost: centos7
           Message: This is a centos7 log
        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

2.2 通过 loganalyzer 展示数据库中的日志

loganalyzer是用 php 语言实现的日志管理系统,可将MySQL数据库的日志用丰富的WEB方式进行展示

官网:https://loganalyzer.adiscon.com

2.2.1 目标

通过 loganalyzer 展示数据库中的日志

2.2.2 环境准备

#三台主机
c8log           192.168.100.48  #一台日志服务器,利用上一个案例实现
c8mariadb       192.168.100.28  #一台数据库服务器,利用上一个案例实现
c7loganalyzer   192.168.100.17  #yum安装httpd+php,并安装loganalyzer展示web图形

2.2.3 步骤

2.2.3.1 在192.168.100.17主机上yum安装http及php和相关软件包

[root@c7loganalyzer ~]# yum -y install httpd php-fpm php-mysqlnd
[root@c7loganalyzer ~]# systemctl start httpd php-fpm
[root@c7loganalyzer ~]# ss -nlt
State      Recv-Q Send-Q     Local Address:Port   Peer Address:Port
LISTEN     0      128            127.0.0.1:9000              *:*
LISTEN     0      128                    *:22                *:*
LISTEN     0      128                 [::]:80             [::]:*
LISTEN     0      128                 [::]:22             [::]:*
[root@c7loganalyzer ~]# ps aux |grep apache
apache     7044  0.0  0.5 278796  5060 ?        S    21:50   0:00 php-fpm: pool www
apache     7045  0.0  0.5 278796  5060 ?        S    21:50   0:00 php-fpm: pool www
apache     7046  0.0  0.5 278796  5060 ?        S    21:50   0:00 php-fpm: pool www
apache     7047  0.0  0.5 278796  5060 ?        S    21:50   0:00 php-fpm: pool www
apache     7048  0.0  0.5 278796  5060 ?        S    21:50   0:00 php-fpm: pool www
apache     7049  0.0  0.7 361084  7128 ?        S    21:50   0:00 /usr/sbin/httpd -DFOREGROUND
apache     7050  0.0  0.7 361084  7128 ?        S    21:50   0:00 /usr/sbin/httpd -DFOREGROUND
apache     7051  0.0  0.7 361084  7128 ?        S    21:50   0:00 /usr/sbin/httpd -DFOREGROUND
apache     7052  0.0  0.7 361084  7128 ?        S    21:50   0:00 /usr/sbin/httpd -DFOREGROUND
apache     7053  0.0  0.7 361084  7128 ?        S    21:50   0:00 /usr/sbin/httpd -DFOREGROUND
root       7159  0.0  0.0 112808   972 pts/0    S+   21:51   0:00 grep --color=auto apache

2.2.3.2 在192.168.100.17主机上安装LogAnalyzer

#从http://loganalyzer.adiscon.com/downloads/ 下载loganalyzer-4.1.10.tar.gz
[root@c7loganalyzer ~]# tar xf loganalyzer-4.1.12.tar.gz
[root@c7loganalyzer ~]# ls
anaconda-ks.cfg  loganalyzer-4.1.12  loganalyzer-4.1.12.tar.gz
[root@c7loganalyzer ~]# mv loganalyzer-4.1.12/src /var/www/html/log

2.2.3.3 基于 web 页面初始化

访问http://192.168.100.17/log 实现初始化

注意:如果没有安装php-gd包,会如下错误

创建了config.php文件并授权后,recheck即可

[root@c7loganalyzer ~]# touch /var/www/html/log/config.php
[root@c7loganalyzer ~]# chmod 666 /var/www/html/log/config.php

未安装gd包,效果如下

安装gd包并重启服务,实现图形化

[root@c7loganalyzer ~]# yum -y install php-gd
[root@c7loganalyzer ~]# systemctl restart httpd

2.2.3.4 安全加强

[root@c7loganalyzer ~]# chmod 644 /var/www/html/log/config.php

2.3 centos8编译安装httpd2.4和php7.4.23,实现loganalyzer图形化日志

2.3.1 初始化

#三台主机
c8log           192.168.100.48  #一台日志服务器,利用上一个案例实现
c8mariadb       192.168.100.28  #一台数据库服务器,利用上一个案例实现
c8loganalyzer   192.168.100.18  #一键编译安装httpd+php,并增加gd模块,再安装loganalyzer展示web图形

centos8系统编译安装httpd2.4和php7.4.23,但未添加gd模块,需要使用phpize命令。当需要添加一些模块,但是又不想重新编译php时,就可以使用phpize命令。

2.3.2 未安装gd模块,不能实现图形化界面

2.3.3 添加gd模块

1、先进入php源码包的/ext/gd/目录下,如下:
[root@c8loganalyzer ~]# cd /data/php74/php-7.4.23/ext/gd/
[root@c8loganalyzer gd]# ls
config.m4  config.w32  CREDITS  gd.c  gd_compat.c  gd_compat.h  gd_ctx.c  libgd  php_gd.h  tests

2、显示如下说明执行成功
[root@c8loganalyzer gd]# /apps/php74/bin/phpize #编译安装后文件放在/apps/php74目录下,所以/usr/local/sbin/不一定有这个链接文件
Configuring for:
PHP Api Version:         20190902
Zend Module Api No:      20190902
Zend Extension Api No:   320190902

3、配置、安装
[root@c8loganalyzer gd]# ./configure  --with-php-config=/apps/php74/bin/php-config
......
checking for libpng... no
configure: error: Package requirements (libpng) were not met:
Package \'libpng\', required by \'virtual:world\', not found
Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.
Alternatively, you may set the environment variables PNG_CFLAGS
and PNG_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.

#出现上述丢失包的错误,安装其libpng-level库即可
[root@c8loganalyzer gd]# yum install libpng-devel
[root@c8loganalyzer gd]# make && make install
。。。。。。
Installing shared extensions:     /apps/php74/lib/php/extensions/no-debug-zts-20190902/
Installing header files:          /apps/php74/include/php/

gd库安装成功后会在/apps/php74/lib/php/extensions/no-debug-zts-20190902/目录下生成gd.so文件,如下:
[root@c8loganalyzer gd]# ll /apps/php74/lib/php/extensions/no-debug-zts-20190902/
total 11452
-rwxr-xr-x 1 root root 1550496 Sep 15 22:47 gd.so
-rwxr-xr-x 1 root root 6934580 Sep 11 14:35 opcache.a
-rwxr-xr-x 1 root root 3234768 Sep 11 14:35 opcache.so

4、可以通过查看php --ini查看添加的模块
[root@c8loganalyzer gd]# php --ini
Configuration File (php.ini) Path: /etc
Loaded Configuration File:         /etc/php.ini
Scan for additional .ini files in: /etc/php.d
Additional .ini files parsed:      /etc/php.d/10-opcache.ini,
/etc/php.d/20-bz2.ini,
/etc/php.d/20-calendar.ini,
/etc/php.d/20-ctype.ini,
/etc/php.d/20-curl.ini,
/etc/php.d/20-exif.ini,
/etc/php.d/20-fileinfo.ini,
/etc/php.d/20-ftp.ini,
/etc/php.d/20-gd.ini,
/etc/php.d/20-gettext.ini,
/etc/php.d/20-iconv.ini,
/etc/php.d/20-phar.ini,
/etc/php.d/20-sockets.ini,
/etc/php.d/20-tokenizer.ini,
/etc/php.d/opcache.ini

6、或者php -m过滤查看有无gd
[root@c8loganalyzer gd]# php -m|grep gd
gd
[root@c8loganalyzer gd]# cat /etc/php.d/20-gd.ini
; Enable gd extension module
extension=gd
7、重启服务,即可看到图形界面
[root@c8loganalyzer gd]# systemctl restart httpd php-fpm

以上是关于编译安装基于fastcgi模式的多虚拟主机的wordpress和discuz的LAMP架构的主要内容,如果未能解决你的问题,请参考以下文章

日志服务管理&CGI与FASTCGI区别

实战案例:编译安装基于 FastCGI 模式LAMP架构多虚拟主机WEB应用(WordPress 和Discuz)

LAMP架构

LAMP ----- 编译实现基于FASTCGI的LAMP的WordPress

sh 使用Nginx和MySQL编译并将php 5.3.27安装到FastCGI模式

LAMP 之 自动化编译安装