LAMP分离架构部署wordpress和LogAnalyzer
作者:互联网
1、部署分离的LAMP到两台服务器上,php加载xcache模块
将LAMP架构部署到两台服务器上时,一台服务器安装httpd和php,另一台安装mariadb
在第一台虚拟机上二进制安装mariadb-10.2.37
# 安装相关软件
yum install -y libaio expect
# 配置安装mariadb的目录
tar -xf mariadb-10.2.37-linux-systemd-x86_64.tar.gz -C /usr/local/
ln -s /usr/local/mariadb-10.2.37-linux-systemd-x86_64 /usr/local/mysql
# 创建用户,设置权限
useradd -r -s /sbin/nologin -d /data/mysql mysql
chown -R mysql:mysql /data/mysql/
chown -R root:root /usr/local/mysql
# 设置PATH环境变量
echo 'PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
. /etc/profile.d/mysql.sh
# 初始化安装mariadb
cd /usr/local/mysql/
./scripts/mysql_install_db --datadir=/data/mysql/ --user=mysql --defaults-file=/etc/my.cnf
# 创建配置文件
# 默认client部分和mysqld部分的socket文件路径必须都是/tmp/mysql.sock,否则无法连接mysqld服务
cat > /etc/my.cnf << EOF
[client]
socket = /tmp/mysql.sock
!includedir /etc/my.cnf.d
[mysqld]
datadir=/data/mysql
socket=/tmp/mysql.sock
skip_name_resolve = on
log-bin=/data/mysql/mysql-bin
symbolic-links=0
[mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid
EOF
# 让systemctl命令管理mariadb
cp /usr/local/mysql/support-files/systemd/mariadb.service /usr/lib/systemd/system/
systemctl daemon-reload
# 启动mariadb服务
systemctl enable --now mariadb
# 创建用于自动完成mariadb安全初始化的expect脚本
cat > mysql_secure_installation.exp << EOF
#!/usr/bin/expect
set passwd examp1mec0m
spawn /usr/local/mysql/bin/mysql_secure_installation
expect {
"Enter current password" { send "\r"; exp_continue }
"Y/n" { send "Y\r"; exp_continue }
"New password" { send "\$passwd\r"; exp_continue }
"Re-enter new password" { send "\$passwd\r"; exp_continue }
"Remove anonymous users" { send "Y\r"; exp_continue }
"Disallow root login remotely" { send "Y\r"; exp_continue }
"Remove test database and access to it" { send "Y\r"; exp_continue }
"Reload privilege tables now" { send "Y}
}
EOF
expect mysql_secure_installation.exp
# 登录数据库
mysql -uroot -pexamp1mec0m
在第二台虚拟机上编译安装http2.4
# 安装用于编译的软件
yum -y install gcc make pcre-devel openssl-devel expat-devel bzip2
# 解压源码包
tar xf httpd-2.4.46.tar.bz2
tar xf apr-1.6.5.tar.gz
tar xf apr-util-1.6.1.tar.bz2
mv apr-1.6.5/ httpd-2.4.46/srclib/apr
mv apr-util-1.6.1 httpd-2.4.46/srclib/apr-util
# 配置编译参数,进行编译
cd httpd-2.4.46
./configure \
--prefix=/app/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=prefork \
> /dev/null
make -j 7 > /dev/null && make install > /dev/null && echo OK
# 创建apache用户用于运行httpd
useradd -r -s /sbin/nologin apache
# 让http开机运行
echo '/app/httpd24/bin/apachectl start' >> /etc/rc.d/rc.local
chmod +x /etc/rc.d/rc.local
# 设置PATH环境变量
echo "PATH=/app/httpd24/bin:$PATH" > /etc/profile.d/httpd.sh
. /etc/profile && echo OK
# 编辑配置文件,让http支持解析php
sed -i.bak 's/User daemon/User apache/' /app/httpd24/conf/httpd.conf
sed -i 's/Group daemon/Group apache/' /app/httpd24/conf/httpd.conf
sed -i 's/DirectoryIndex index.html/DirectoryIndex index.php index.html/' /app/httpd24/conf/httpd.conf
sed -i '398a \
AddType application/x-httpd-php .php \
AddType application/x-httpd-php-source .phps \
' /app/httpd24/conf/httpd.conf
echo 'ProxyRequests Off' >> /app/httpd24/conf/httpd.conf
sed -i 's@#LoadModule proxy_module modules/mod_proxy.so@LoadModule proxy_module modules/mod_proxy.so@' /app/httpd24/conf/httpd.conf
sed -i 's@#LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so@LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so@' /app/httpd24/conf/httpd.conf
在第二台虚拟机上编译安装PHP7
# 安装软件
yum install -y epel-release
yum install -y gcc libxml2-devel bzip2-devel libmcrypt-devel
tar xf php-7.3.27.tar.xz
# 配置编译参数,编译
cd php-7.3.27/
./configure \
--prefix=/app/php \
--enable-mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-openssl \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--with-libxml-dir=/usr \
--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
make -j 7 > /dev/null && make install > /dev/null && echo OK
# 编译配置文件
cp php.ini-production /etc/php.ini
cd /app/php/etc
cp php-fpm.conf.default php-fpm.conf
cp php-fpm.d/www.conf.default php-fpm.d/www.conf
sed -i.bak 's/user = nobody/user = apache/' /app/php/etc/php-fpm.d/www.conf
sed -i 's/group = nobody/group = apache/' /app/php/etc/php-fpm.d/www.conf
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
# 让chkconfig命令管理php-fpm,并且让php-fpm开机运行
chmod +x /etc/init.d/php-fpm
chkconfig --add php-fpm
chkconfig php-fpm on
# 安装xcache模块
yum -y install php-devel
tar xf xcache-3.2.0.tar.gz
cd xcache-3.2.0
phpize --clean && phpize
./configure --enable-xcache > /dev/null
make > /dev/null && make install > /dev/null
cp xcache.ini /etc/php.d/
service php-fpm start
apachectl start
2、部署wordpress论坛,并实现正常访问登录论坛。
在第一个实验基础上进行配置
# 编辑http配置文件,为wordpress新建一个虚拟主机
cat >> /app/httpd24/conf/httpd.conf << EOF
<virtualhost *:80>
servername 1.test.com
documentroot /app/httpd24/htdocs/wordpress
<directory /app/httpd24/htdocs/wordpress>
require all granted
</directory>
ProxyPassMatch ^/(.*\.php)\$ fcgi://127.0.0.1:9000/app/httpd24/htdocs/wordpress/\$1
</virtualhost>
# 解压,部署wordpress
tar xf wordpress-5.6.2.tar.gz
mv wordpress /app/httpd24/htdocs/
setfacl -R -m u:http:rwx /app/httpd24/htdocs/wordpress/
# 在数据库服务器上创建wordpress需要的数据库
cat > wordpress_init.sql << EOF
create database wordpressdb;
grant all on wordpressdb.* to 'wordpressuser'@'192.168.0.%' identified by '7toQW)gA';
EOF
mysql -uroot -pexamp1mec0m < wordpress_init.sql
# 复制并且根据前面的sql语句编辑配置文件
cp /app/httpd24/htdocs/wordpress/wp-config-sample.php /app/httpd24/htdocs/wordpress/wp-config.php
# 重启http和php-fpm服务
apachectl restart
service php-fpm restart
# 编辑http服务器的hosts文件
echo '192.168.0.52 1.test.com log.test.com' >> /etc/hosts
# 先编辑客户端的hosts文件
# 再使用浏览器访问http服务器,完成wordpress的初始化
3、收集apache访问日志,并实现图形化展示。
在第一个实验的两个虚拟机的基础上进行实验
# 配置http服务器
yum install rsyslog-mysql mysql -y
sed -i 's@CustomLog "logs/access_log" common@CustomLog "|/usr/bin/logger -p local6.info" combined@' /app/httpd24/conf/httpd.conf
echo 'local6.* /var/log/access.log' >> /etc/rsyslog.conf
systemctl restart rsyslog.service
# 配置mysql服务器
mysql -uroot -pexamp1mec0m -e"grant all on Syslog.* to 'syslog'@'192.168.0.%' identified by 'Centos';"
# 配置http服务器
mysql -usyslog -h192.168.0.51 -pCentos < /usr/share/doc/rsyslog-8.24.0/mysql-createDB.sql
cat >> /etc/rsyslog.conf << EOF
\$ModLoad ommysql
local6.* :ommysql:192.168.0.51,Syslog,syslog,Centos
EOF
systemctl restart rsyslog
# http服务器安装LogAnalyzer
tar xf loganalyzer-4.1.11.tar.gz
cp -a loganalyzer-4.1.11/src /app/httpd24/htdocs/loganalyzer
cd /app/httpd24/htdocs/loganalyzer
touch config.php
chmod 644 config.php
# 创建新的虚拟主机
cat >> /app/httpd24/conf/httpd.conf << EOF
<virtualhost *:80>
servername log.test.com
documentroot /app/httpd24/htdocs/log
<directory /app/httpd24/htdocs/log>
require all granted
</directory>
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/app/httpd24/htdocs/log/$1
</virtualhost>
EOF
在客户端使用浏览器访问http服务器,配置LogAnalyzer
标签:php,--,app,etc,LAMP,wordpress,conf,mysql,LogAnalyzer 来源: https://blog.51cto.com/14920534/2650729