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

相关推荐

  • Linux命令帮助文档的使用及简单命令使用-2016-7-25

    Linux命令帮助文档的使用   相关命令 whatis    COMMAND –help    man and info 本地帮助文档/usr/share/doc   在使用系统内建的帮助文档之前,我们需要了解需要命令帮助是否是内部命令和外部命令…

    Linux干货 2016-08-04
  • 磁盘管理

    磁盘设备 一切皆文件 所有的Linux中的设备都可以使用下面命令进行操作:open(), read(), write(), close()(这些是C的函数) 块设备:随机访问 字符设备:线性访问 设备号码: 主设备号:major number,标识设备类型 8是主要设备编号,代表类型 次设备号:minor number…

    Linux干货 2016-09-01
  • 【招聘】北京/互联网/运维工程师/7-15K/双休,五险一金

    岗位职责:   1、负责服务器的规划、调试优化、日常监控、故障处理、数据备份、日志分析等工作;   2、参与运维流程制定,确保任何突发情况都能高效响应;  3、负责服务器部署,对服务器构架和网络进行优化和改进;  4、负责运维相关数据的收集、分析和总结;  5、负责技术运维相关的文档、手册…

    Linux干货 2016-04-16
  • N26-第十二周

    1、请描述一次完整的http请求处理过程;        1、建立或处理链接:接收请求或拒绝请求        2、接收请求:接收来自于网络的请求报文中对某资源的一次请求的过程;接收请求的方式通常是并发访问响应模型        3、处理请…

    2017-05-14
  • 链接分析算法之:SALSA算法

      SALSA算法的初衷希望能够结合PageRank和HITS算法两者的主要特点,既可以利用HITS算法与查询相关的特点,也可以采纳PageRank的“随机游走模型”,这是SALSA算法提出的背景。由此可见,SALSA算法融合了PageRank和HITS算法的基本思想,从实际效果来说,很多实验数据表明,SALSA的搜索效果也都优于前两个算…

    大数据运维 2015-07-21
  • 正则 grep查找find(xargs)练手

    1、显示当前系统上root、fedora或user1用户的默认shell; ~]# grep -E "^(root|fedora|user1)\>" /etc/passwd | cut -d: -f7 2、找出/etc/rc.d/init.d/functions文件中某单词后面跟一组小括号的行,形如:hello(); ~]# gre…

    Linux干货 2016-10-24