1、部署分离的LAMP,部署到二台服务器上,php加载xcache模块
192.168.2.241 httpd+php-fpm
192.168.2.240 mysql
1)安装httpd和php
yum -y install httpd php php-mysql php-fpm
2)修改httpd配置文件
vim /etc/httpd/conf/httpd.conf
DirectoryIndex index.php index.html #httpd默认首页添加php
#添加如下几行,用于httpd支持php和proxy代理
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
ProxyRequests Off
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/var/www/html/$1
查看是否httpd是否启用了proxy和fcgi模块,如果为启用编辑proxy配置文件启用模块
vim /etc/httpd/conf.modules.d/00-proxy.conf
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
![image.png](https://upload-images.jianshu.io/upload_images/10958113-29a3a78582255f17.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
3)启动httpd和php-fpm服务
systemctl start httpd php-fpm
4)在2.240机器上安装数据库,并创建授权登录账号
yum -y install mariadb-server
grant all on *.* to 'test'@'192.168.2.%' identified by 'test';
flush privileges;
5)安装xcache模块,重启httpd、php-fpm服务
yum -y install php-xcache
systemctl restart httpd php-fpm
6)对比测试结果
ab -c1000 -n1000 http://192.168.2.241/index.php
加载xcache前
加载xcache后
2、部署wordpress论坛,并实现正常访问登录论坛。
192.168.2.240 mysql
192.168.2.241 httpd+php
1)下所需的所有的软件包
wget http://mirror.bit.edu.cn/apache//httpd/httpd-2.4.41.tar.gz
wget https://www.php.net/distributions/php-7.4.3.tar.xz
wget http://mirror.bit.edu.cn/apache//apr/apr-1.7.0.tar.gz
wget http://mirror.bit.edu.cn/apache//apr/apr-util-1.6.1.tar.gz
wget https://github.com/WordPress/WordPress/archive/5.3.2.tar.gz
2)源码编译安装httpd
解压软件
tar xf httpd-2.4.41.tar.gz
tar xf apr-1.7.0.tar.gz -C httpd-2.4.41/srclib/
tar xf apr-util-1.6.1.tar.gz -C httpd-2.4.41/srclib/
安装依赖包
yum install gcc pcre-devel openssl-devel expat-devel oniguruma-devel
创建httpd运行用户
useradd -r -M -s /sbin/nologin apache
执行编译并安装
./configure --prefix=/app/httpd24 --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --enable-modules=most --enable-mpms-shared=all --with-mpm=prefork --with-included-apr
make -j 4 && make install
修改httpd配置文件
vim /app/http24/conf/httpd.conf
取消如下两行注释,启用httpd proxy代理
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
修改httpd运行的用户和组为apache
User apache
Group apache
DirectoryIndex行增加index.php
<IfModule dir_module>
DirectoryIndex index.php index.html
</IfModule>
添加如下四行,通过httpd请求php程序代理到php程序处理
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
ProxyRequests Off
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/app/httpd24/htdocs/$1
重启httpd服务
apachectl restart
3)源码编译安装php
解压php源码包 tar xf php-7.3.15.tar.xz
安装编译所需依赖包
yum -y install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel ncurses curl gdbm-devel db4-devel libXpm-devel libX11-devel gd-devel gmp-devel expat-devel xmlrpc-c xmlrpc-c-devel libicu-devel libmcrypt-devel libmemcached-devel libzip gcc-c++
执行编译并安装
./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
make && make install
复制配置文件及php-fpm启动脚本,并且添加执行权限设置为开机启动
cp php.ini-production /etc/php.ini
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm
chkconfig --add php-fpm
chkconfig php-fpm on
cd /app/php/etc
cp php-fpm.conf.default php-fpm.conf
cp php-fpm.d/www.conf.default php-fpm.d/www.conf
4)启动服务,查看程序运行状态
systemctl start php-fpm
创建php页面,验证httpd解析php
vim /etc/httpd24/htdocs/index.php
<?php
phpinfo();
?>
5)部署Wordpress
登录数据创建wordpress库和授权账户
create database wordpress;
grant all on wordpress.* to 'wordpress'@'192.168.2.%' identified by 'wordpress';
flush privileges;
将WordPress程序解压到httpd网站根目录,重名了为wordpress,设置acl权限为apache账户具有读写执行的权限
tar xf 5.3.2.tar.gz -C /app/httpd24/htdocs/
cd /app/httpd/htdocs
mv WordPress-5.3.2/ wordpress
setfacl -Rm u:apache:rwx wordpress/
浏览器访问wordpress进入安装向导,执行安装步骤
安装完成
3、收集apache访问日志,并实现图形化展示。
10.0.30.121 httpd+php
10.0.30.122 mysql
1)安装httpd、php
yum -y install httpd php php-mysql php-gd rsyslog-mysql
2)安装mysql添加授权账号
yum -y install mariadb-server
grant all on Syslog.* to 'loguser'@'10.0.30.%' identified by 'loguser';
3)将创建存储rsyslog的库及表的sql语句,复制到mysql数据库节点并执行。
scp /usr/share/doc/rsyslog-8.24.0/mysql-createDB.sql 10.0.30.122:/root
4)修改httpd日志配置
vim /etc/httpd/conf/httpd.conf
将CustomLog "logs/access_log" combined日志项修改为
CustomLog "|/usr/bin/logger -p local5.info" combined
5)修改rsyslog的配置
vim /etc/rsyslog.conf
$ModLoad imtcp #启用tcp协议
$InputTCPServerRun 514
$ModLoad ommysql #加载mysql模块支持
*.* :ommysql:10.0.30.122,Syslog,log,log #配置日志保存至mysql数据库
local5.* /var/log/httpd/access_log
local6.* /var/log/httpd/error_log
重启httpd、rsyslog服务
systemctl restart httpd rsyslog
6)下载并安装loganalyzer日志展示包
wget http://download.adiscon.com/loganalyzer/loganalyzer-4.1.10.tar.gz
将loganalyzer解压到httpd网站根目录
tar -xf loganalyzer-4.1.10.tar.gz -C /var/www/html/
cd /var/www/html/
cp -a loganalyzer-4.1.10/src ./loganalyzer
创建配置文件,并修改权限,为保障系统安全loganalyzer安装步骤执行完成后将config.php权限设置为644
touch ./loganalyzer/config.php
chmod 666 ./loganalyzer/config.php
7)通过浏览器访问并进行安装
http://10.0.30.121/loganalyzer
通过loganalyzer web页面展示查看httpd的访问日志