CentOS 7, lamp (php-fpm);(Blog 15)

要求:
(1) 三者分离于三台主机;
(2) 一个虚拟主机用于提供phpMyAdmin;另一个虚拟主机用于提供wordpress;
(3) xcache

HTTP反代动态资源至fpm

程序包:httpd php-fpm php-mysql mariadb-server

172.16.0.67 httpd
172.16.0.68 fpm, php-mysql
172.16.0.69 mariadb-server

172.16.0.67 httpd
# yum install httpd
# systemctl start httpd.service
# ss -tnl
测试访问: http://172.16.0.67/
iptables -F
setenforce 0

提供虚拟主机:
# vim /etc/httpd/conf.d/ilinux.conf
<VirtualHost *:80>
ServerName www.ilinux.io
DocumentRoot “/data/web/ilinux”
<Directory “/data/web/linux”>
Options FollowSymLinks
AllowOverride None
Require all granted
</Directory>
CustomLog logs/ilinux_access_log combined
ErrorLog logs/ilinux_error_log
</VirtualHost>

# cp /etc/httpd/conf.d/ilinux.conf /etc/httpd/conf.d/iunix.conf
# sed -i ‘s,linux,unix,g’ iunix.conf

提供测试页面测试:
# mkdir -pv /data/web/i{linux,unix}
# echo “<h1>hi! unix.</h1>” > /data/web/iunix/index.html
# echo “<h1>hi! linux.</h1>” > /data/web/ilinux/index.html
# httpd -t
# systemctl restart httpd.service
访问:www.ilinux.io www.iunix.io

172.16.0.68 php-fpm, php-mysql
配置yum源:
[base]
name=base repo
#baseurl=file:///media/cdrom
baseurl=http://mirrors.aliyun.com/centos/7/os/x86_64/
gpgcheck=0
enabled=1

[epel]
name=epel repo
baseurl=http://mirrors.aliyun.com/epel/7/x86_64/
gpgcheck=0
enabled=1

~]# yum install php-fpm php-mysql php-mbstring php-mcrypt php-zlib
php-mbstring: 多字节字符支持
php-mcrypt: 整合Libmcrpt至php加密传输
php-zlib: 压缩传输

程序环境:
# rpm -ql php-fpm
/etc/logrotate.d/php-fpm
/etc/php-fpm.conf
/etc/php-fpm.d/www.conf
/etc/sysconfig/php-fpm

配置格式:
listen = 127.0.0.1:9000 跨主机需要修改,
ip 监听在指定地址上,与非本机通信,要监听在能通信的地址上;
port: 监听在所有地址上;
listen.allowd_clients = 127.0.0.1 授权哪些来连接
pm.status_path = /pmstatus 内建的状态页
ping.path = /ping 内建的
ping.response = pong 健康状态
php_value[session.save_path] = /var/lib/php/session
保存会话持久位置;
目录的属主的属组为apache用户

修改配置:
listen = 172.16.0.68:9000 <–只能是ip地址,不能是网络地址
listen.allowed_clients = 172.16.0.67 <–只能是ip地址,不能是网络地址
pm = dynamic <–动态是prefork模型
ping.path = /ping [启用 ]
ping.response = pong [启用 ]
pm.status_path = /pmstatus [启用 ]
php_value[session.save_path] = /var/lib/php/session [创建修改属主或属组]

创建所需目录:
# mkdir -pv /var/lib/php/session
# chown apache:apache /var/lib/php/session

启动:
# systemctl start php-fpm.service
# ss -tnl

172.16.0.67主机中,在虚拟机中添加反代至fcgi服务器的选项:
# vim /etc/httpd/conf.d/ilinux.conf
DirectoryIndex index.php
<VirtualHost *:80>
ServerName www.ilinux.io
DocumentRoot “/data/web/ilinux”
ProxyRequests Off
ProxyPassMatch ^/(.*\.php)$ fcgi://172.16.0.68:9000/data/web/ilinux/$1

<Directory “/data/web/ilinux”>
Options FollowSymLinks
AllowOverride None
Require all granted
</Directory>
CustomLog logs/ilinux_access_log combined
ErrorLog logs/ilinux_error_log
</VirtualHost>
# cp /etc/httpd/conf.d/ilinux.conf /etc/httpd/conf.d/iunix.conf
# sed -i ‘s,linux,unix,g’ iunix.conf
# httpd -t
# systemctl restart httpd.service
注意:先测试能否访问index.html:
www.ilinux.io/index.html
www.iunix.io/index.html

172.16.0.68的主机中/data/web/ilinux/添加php测试页:
# mkdir -pv /data/web/i{linux,unix}
# vim /data/web/ilinux/index.php
<html>
<title>Test Page</title>
<body>
<h1>Welcome to MageEdu</h1>
<h2>PHP Info Page</h2>
<?php
phpinfo();
?>
</body>
</html>
# cp /data/web/ilinux/index.php /data/web/iunix/index.php

网页测试: www.ilinux.io/index.php
www.iunix.io/index.php

172.16.0.69 mariadb-server
~]# vim /etc/my.cnf.d/server.cnf
[mysqld]
skip_name_resolve=on
innodb_file_per_table=on
log_bin=mysql-bin

~]# systemctl start mariadb.service
~]# ss -tnl
~]# mysql_secure_installation
~]# mysql -uroot -h127.0.0.1 -pmagedu
Welcome to the MariaDB monitor. Commands end with ; or \g.

MariaDB [(none)]>

添加用户提供wordpress数据库:
> CREATE DATABASE wordpress;
> GRANT ALL ON wordpress.* TO ‘wpuser’@’172.16.%.%’ IDENTIFIED BY ‘wppass’;
> FLUSH PRIVILEGES;

172.16.0.67主机上测试连接:
# mysql -uwpuser -h172.16.0.69 -pwppass
ERROR 2003 (HY000): Can’t connect to MySQL server on ‘172.16.0.69’ (113)
~]# iptables -F (172.16.0.69)
# mysql -uwpuser -h172.16.0.69 -pwppass
MariaDB [(none)]>

用php连接mysql
172.16.0.68
~]# vim /data/web/ilinux/php-mysql.php
<?php
$conn = mysql_connect(‘172.16.0.69′,’wpuser’,’wppass’);
if ($conn)
echo “OK”;
else
echo “False”;
?>
~]# cp /data/web/ilinux/php-mysql.php /data/web/iunix/php-mysql.php
网页访问: www.ilinux.io/php-mysql.php www.iunix.io/php-mysql.php

(2) 一个虚拟主机用于提供phpMyAdmin;另一个虚拟主机用于提供wordpress;
(3) xcache

注意: wordpress-4.9.1-zh_CN.tar.gz phpMyAdmin-4.0.10.20-all-languages.zip 已经下载至httpd和php-fpm的两个DocumentRoot目录中;

进入httpd主机的ilinux DocumentRoot目录;
172.16.0.68:
# tar xf wordpress-4.9.1-zh_CN.tar.gz
# ln -sv wordpress wp
# cp wp/wp-config-sample.php wp/wp-config.php
# vim wp/wp-config.php
define(‘DB_NAME’, ‘wordpress’);
define(‘DB_USER’, ‘wpuser’);
define(‘DB_PASSWORD’, ‘wppass’);
define(‘DB_HOST’, ‘172.16.0.69’);
因为动态内容在php-fpm,所以在那个主机有相同的目录
172.16.0.68:
# tar xf wordpress-4.9.1-zh_CN.tar.gz
# ln -sv wordpress wp
# cp wp/wp-config-sample.php wp/wp-config.php
# vim wp/wp-config.php
define(‘DB_NAME’, ‘wordpress’);
define(‘DB_USER’, ‘wpuser’);
define(‘DB_PASSWORD’, ‘wppass’);
define(‘DB_HOST’, ‘172.16.0.69’);
网络访问: http://www.ilinux.io/wp

上传权限取决于apache用户于wp-content目录; 一般是静态资源所以只对172.16.0.68进行赋权;
172.16.0.68: # setfacl -R -m u:apache:rwx wp-content

提供phpMyadmin
# unzip phpMyAdmin-4.0.10.20-all-languages.zip
# ln -sv phpMyAdmin-4.0.10.20-all-languages pma
# cp pma/config.sample.inc.php pma/config.inc.php
$cfg[‘Servers’][$i][‘host’] = ‘172.16.0.69’;

因为动态内容在php-fpm,所以在那个主机有相同的目录
# unzip phpMyAdmin-4.0.10.20-all-languages.zip
# ln -sv phpMyAdmin-4.0.10.20-all-languages pma
# cp pma/config.sample.inc.php pma/config.inc.php
$cfg[‘Servers’][$i][‘host’] = ‘172.16.0.69’;

网页访问时,roo没有远程访问的权限;需要授权:
或者用wpuser, wppass登陆也行

(3) 提供xcache
先用ab压测;
172.16.0.69
# yum -y install httpd (提供ab命令)
# ab -n 10000 -c 10 http://172.16.0.67/pma/index.php

测试3次:
Server Software: Apache/2.4.6
Server Hostname: 172.16.0.67
Server Port: 80

Document Path: /pma/index.php
Document Length: 16 bytes

Concurrency Level: 100
Time taken for tests: 37.842 seconds
Complete requests: 10000
Failed requests: 0
Write errors: 0
Non-2xx responses: 10000
Total transferred: 1 950 000 bytes
HTML transferred: 160000 bytes
Requests per second: 264.26 [#/sec] (mean) 每秒264请求
Time per request: 378.421 [ms] (mean) 平均每批请求
Time per request: 3.784 [ms] (mean, across all concurrent requests) 平均每个请求
Transfer rate: 50.32 [Kbytes/sec] received

Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 2 150.6 0 15029
Processing: 1 312 2882.0 63 33129
Waiting: 1 312 2882.0 62 33129
Total: 1 315 2886.3 63 33130

172.16.0.68:添加xcache模块
# yum install php-xcache
php-xcache x86_64 3.1.1-1.el7 epel
# systemctl restart php-fpm.service

测试3次:
Server Software: Apache/2.4.6
Server Hostname: 172.16.0.67
Server Port: 80

Document Path: /pma/index.phpa
Document Length: 212 bytes

Concurrency Level: 1000
Time taken for tests: 0.903 seconds
Complete requests: 1000
Failed requests: 0
Write errors: 0
Non-2xx responses: 1000
Total transferred: 391000 bytes
HTML transferred: 212000 bytes
Requests per second: 1108.00 [#/sec] (mean) 每秒264请求
Time per request: 902.528 [ms] (mean) 平均每批请求
Time per request: 0.903 [ms] (mean, across all concurrent requests) 平均每个请求
Transfer rate: 423.07 [Kbytes/sec] received

Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 15 19.9 0 65
Processing: 4 110 157.0 27 828
Waiting: 4 110 157.0 27 828
Total: 17 125 170.7 27 828

Percentage of the requests served within a certain time (ms)
50% 27
66% 41
75% 288
80% 300
90% 483
95% 491
98% 495
99% 497
100% 828 (longest request)

本文来自投稿,不代表Linux运维部落立场,如若转载,请注明出处:http://www.178linux.com/90440

(1)
逆神阳逆神阳
上一篇 2017-12-20
下一篇 2017-12-20

相关推荐

  • Nginx 代理和缓存

    一 实验环境 Nginx 版本:nginx-1.8.1 Nginx代理服务器WAN:192.168.1.5 LAN:172.16.2.1 Web1:172.16.2.2 Web2:172.16.2.3 1.  配置好IP、DNS 、网关,确保使用远程连接工具能够连接服务器 2.      …

    Linux干货 2016-12-05
  • ☞keepalived

    keepalived 高可用集群 VRRP协议 keepalived 安装keepalived 主要文件 配置文件说明 【一】测试keepalived基本功能 单主模型示例 双主模型示例 通知脚本示例 【二】单主模型高可用DR类型LVS集群 配置keepalived主机 Real Server配置 测试结果 【三】双主模型高可用DR类型LVS集群 配置kee…

    Linux干货 2016-11-01
  • 私人定制-linux系统和grub启动流程中问题及解决方案

    系统的启动流程;     POST加电自检–>Boot Sequence(BIOS)–>Boot Loader(MBR)–>kernel(Ramdisk)–>rootfs–>switchroot–>/sbin/i…

    Linux干货 2016-09-13
  • Sed简介

    Sed简介    一、简介   sed全称是:Stream EDitor。sed命令的功能同awk类似,差别在于,sed简单,对列处理的功能要差一些,awk的功能复杂,对列处理的功能比较强大。  sed 是一种在线编辑器,它一次处理一行内容。处理时,把当前处理的行存储在临时缓冲区中,称为“模式空间”(pattern s…

    Linux干货 2015-05-11
  • 软raid实现raid5

    现在Linux系统有磁盘情况如下 现在从sda,sdb,sdc,sdd 分区取出10G 的空间做raid5. 第一步:建立分区 现在执行fdisk  /dev/sd* 命令分区冲这四个磁盘划分10G分区 分别是sda6,sdb1,sdc1,sdd1。 具体操作如下: 分区完之后,执行#partx -a /dev/sd*  让分区生效。具体效果如下: 分区完成…

    2017-12-06
  • 磁盘管理:raid和lvm练习

    本文通过以下习题,巩固所学raid和lvm知识: 20160829         1、创建一个可用空间为1G的RAID1设备,文件系统为ext4,有一个空闲盘,开机可自动挂载至/backup目录       &nbsp…

    Linux干货 2016-09-05