342132123 发表于 2016-12-5 09:12:37

Apache+php-fpm

实验环境如下:


node1
Apache server10.1.12.12
node2php-fpm10.1.12.13

系统环境:centos 7
node1
Apache server确认有下面的模块

1
2
~]# httpd -M |grep fcgi
proxy_fcgi_module (shared)




定义一个虚拟主机

1
~]# vi /etc/httpd/conf.d/vhost.conf





1
2
3
4
5
6
7
8
9
10
11
12
13
14
<VirtualHost *:80>
      ServerName www.blackCao.com
      DocumentRoot "/web/www"
      CustomLog logs/black_access.log conbaind
      ErrorLog logs/black_error.log
    <Directory "/web/www">
      Options none
      AllowOverride none
      Require all granted
    </Directory>
      ProxyRequests off
      ProxypassMatch ^/(ping|status|.*\.php)$ fcgi://10.1.12.13:9000/data/application/$1
      DirectoryIndex index.php
</VirtualHost>




ProxyPassMatch 将前端ping|status|PHP结尾的请求都转发至后端的PHP服务器后端网页存放位置自定义;
建立PHP状态页的配置文件

1
2
3
4
5
]# vi /etc/httpd/conf.d/status.conf
<Directory /status>
      SetHandler Status-server
      Require all granted
</Directory>





建立虚拟主机主页目录

1
]# mkdir -pv /web/www





1
2
3
# httpd -t
# systemctl start httpd.service
# ss -tnl




检查语法,启动服务,查看端口是否监听正常,




node2

1
2
3
4
5
6
~]# vi /etc/php-fpm.d/
listen = 10.1.12.13:9000    必须监听在一个能与外网通信的外部地址的端口
listen.allowed_clients = 10.1.12.12   IP为http server主机的
pm.status_path = /status    PHP的状态页
ping.path = /ping      可检查PHP服务是否正常
ping.response = pong    上面ping的回应,pong说明正常,不响应说明有问题




建立web文件存放目录(对应上面虚拟机里定义的路径)

1
2
3
4
5
~]# mkdir -p /data/application
~]# vi /data/application/index.php
<?php
      phpinfo();
?>





配置完成,启动服务查看9000端口是否在监听状态


php-fpm的配置选项

listen.backlog = -1
    假如连接池定义最多能有50个连接,当来了55个的时候。这个选项定义这个后援队列的长度,-1表示不限制,如果内存不够用的时候可能会做修改
pm = dynamic
定义processor管理机制:static(使用一个固定的子进程数量)
                     dynamic(使用可变的子进程数量)
pm.max_children:最大子进程数量;连接池的最大容量;
pm.start_servers:服务启动时所启动的子进程数量;
pm.min_spare_servers最少空闲子进程数
pm.max_spare_servers最大空闲子进程数
rlimit_files = 1024所能打开的文件的数量,每个连接需要一个套接字文件,最多只有50个
rlimit_core = 0核心所能使用的内存空间大小,0表示不作限制
pm.status_path = /status
ping.path = /ping监控fpm的工作是否正常
ping.response = pong
php_value = /var/lib/php/session   session的存储位置


status输出信息

pool:www   #连接池名称
process manager:dynamic#进程管理器类型
start time: 11/Oct/2016:11:22:04 +0800   #启动日期时间
start since:917          # 运行时长
accepted conn: 9         # 连接池已经处理过的请求数
listen queue: 0      # 请求队列长度
max listen queue:0      # 请求队列的最大长度
listen queue len: 128      # socket等待队列的长度
idle processes: 4         # 空闲进程数量
active processes: 1      # 活跃的进程数量
total processes: 5      # 连接池中的总进程数量
max active processes: 2   # 连接池中最大的活跃进程数量
max children reached: 0   # 达到连接池中最大进程数量限制的上限的次数
slow requests: 0 :      启用了slow-log时,记录慢请求的数量



页: [1]
查看完整版本: Apache+php-fpm