CentOS7最大改变是systemd代替过去的systemV服务,于是配置服务的方式改变了,用systemctl替代过去的service, chkconfig等命令。
网站搬迁服务器,全新服务器当然用新系统,于是安装上CentOS7。
PHP5.4编译参数:
./configure --build=x86_64-redhat-linux-gnu --host=x86_64-redhat-linux-gnu --with-layout=GNU --prefix=/usr/local --exec-prefix=/usr/local --sysconfdir=/etc --libdir=/usr/local/lib/php --sbindir=/usr/local/sbin --sharedstatedir=/usr/com --datadir=/usr/local/share --includedir=/usr/local/include --libexecdir=/usr/local/libexec --localstatedir=/run --mandir=/usr/local/share/man --infodir=/usr/local/share/info --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-pic --with-curl --with-freetype-dir --with-png-dir --with-gettext=shared --with-gmp=shared --with-iconv --with-jpeg-dir --with-png-dir --with-openssl --with-libxml-dir --with-pcre-regex --with-mcrypt --with-zlib --with-mhash --with-pear --with-gd --enable-gd-native-ttf --enable-calendar=shared --enable-exif --enable-ftp --enable-sockets --enable-bcmath=shared --enable-pcntl --enable-intl --enable-mbstring --enable-zip --with-bz2 --without-unixODBC --enable-mbregex --enable-fpm --with-fpm-user=www --with-fpm-group=www --disable-tokenizer --disable-phar --enable-sysvsem --enable-sysvshm --enable-sysvmsg --disable-cgi --with-pgsql=/usr/pgsql-9.4 --with-pdo-pgsql=/usr/pgsql-9.4 --with-pdo-mysql --with-mysql --with-mysql-sock=/var/lib/mysql/mysql.sock --with-mysqli=shared --enable-mysqlnd \
nginx1.8.0编译参数
./configure --prefix=/usr/local/nginx --conf-path=/etc/nginx/nginx.conf --sbin-path=/usr/local/sbin/nginx --user=nginx --group=www --with-http_ssl_module --with-http_realip_module --with-http_stub_status_module --with-file-aio --pid-path=/run/nginx.pid --lock-path=/run/nginx/nginx.lock --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --http-client-body-temp-path=/run/nginx/client --http-proxy-temp-path=/run/nginx/proxy --http-fastcgi-temp-path=/run/nginx/fcgi --with-debug --without-http_ssi_module --without-http_scgi_module --without-http_uwsgi_module --without-http_autoindex_module --without-http_memcached_module --without-http_proxy_module --without-http_map_module --without-http_geo_module --without-http_auth_basic_module --without-http_upstream_ip_hash_module --without-http_split_clients_module --without-select_module \
/etc/php-fpm.conf内容
[global] pid = /run/php-fpm/php-fpm.pid error_log = /var/log/php-fpm.log log_level = warning emergency_restart_threshold = 10 emergency_restart_interval = 60 process_control_timeout = 300s daemonize = yes rlimit_files = 10240 [www0] prefix = /run/php-fpm/pools/$pool listen = /run/php-fpm/php-fpm0.sock listen.backlog = 2048 listen.owner = www listen.group = www listen.mode = 0666 user = www group = www pm = static pm.max_children = 30 pm.max_requests = 500 pm.status_path = /status request_terminate_timeout = 600 request_slowlog_timeout = 30 slowlog = /var/log/nginx/slow.log env[TMP] = /run/php-fpm/tmp env[TMPDIR] = /run/php-fpm/tmp env[TEMP] = /run/php-fpm/tmp [www1] prefix = /run/php-fpm/pools/$pool listen = /run/php-fpm/php-fpm1.sock listen.backlog = 2048 listen.owner = www listen.group = www listen.mode = 0666 user = www group = www pm = static pm.max_children = 10 pm.max_requests = 500 pm.status_path = /status request_terminate_timeout = 600 request_slowlog_timeout = 30 slowlog = /var/log/nginx/slow.log env[TMP] = /run/php-fpm/tmp env[TMPDIR] = /run/php-fpm/tmp env[TEMP] = /run/php-fpm/tmp
编辑php-fpm启动配置文件 /etc/systemd/system/php-fpm.service
[Unit] Description=The PHP FastCGI Process Manager After=syslog.target network.target Before=nginx.service [Service] Type=forking #Type=notify PIDFile=/run/php-fpm/php-fpm.pid ExecStart=/usr/local/sbin/php-fpm --fpm-config /etc/php-fpm.conf ExecReload=/bin/kill -USR2 $MAINPID PrivateTmp=true [Install] WantedBy=multi-user.target
nginx服务配置 /etc/systemd/system/nginx.service
[Unit] Description=The nginx HTTP and reverse proxy server @ifxdb After=network.target remote-fs.target nss-lookup.target php-fpm.service [Service] Type=forking PIDFile=/run/nginx.pid ExecStartPre=/usr/local/sbin/nginx -t ExecStart=/usr/local/sbin/nginx ExecReload=/bin/kill -s HUP $MAINPID ExecStop=/bin/kill -s QUIT $MAINPID KillMode=process KillSignal=SIGQUIT TimeoutStopSec=5 PrivateTmp=true [Install] WantedBy=multi-user.target
编辑虚拟文件配置 (Centos7的/run是用tmpfs挂接的,重启后目录会消失并重新生成指定默认的)
/etc/tmpfiles.d/php-fpm.conf
# systemd tmpfile settings for php-fpm and nginx # See tmpfiles.d(5) for details d /run/nginx 0755 nginx root - - d /run/nginx/client 0755 nginx root 10d - d /run/nginx/fcgi 0755 nginx root 10d - d /run/nginx/proxy 0755 nginx root 10d - d /run/nginx/cache0 0755 nginx root 10d - d /run/nginx/cache1 0755 nginx root 10d - d /run/nginx/cache2 0755 nginx root 10d - d /run/nginx/cache3 0755 nginx root 10d - d /run/php-fpm 0755 www www 10d - d /run/php-fpm/tmp 0755 www www 3d - d /run/php-fpm/session 0755 www www 1d - d /run/php-fpm/pools 0755 www www 3d - d /run/php-fpm/pools/www0 0755 www www - - d /run/php-fpm/pools/www1 0755 www www - - d /run/php-fpm/pools/www2 0755 www www - - d /run/php-fpm/pools/www3 0755 www www - - d /run/pear 0755 www www 3d - d /run/pear/tmp 0755 www www 3d -
编译配置完毕。启用和启动服务
sudo systemctl daemon-reload sudo systemctl enable nginx php-fpm sudo systemctl start nginx php-fpm
---------------------------------------------------------------------
PHP5.4有点老了,准备装个最新稳定版5.6试试并且为即将到来的PHP7做准备。以前是在单独的一台服务器上跑测试,现在一台服务器上该如何设置呢?
先编译PHP5.6,注意前缀变成了 /opt
./configure --build=x86_64-redhat-linux-gnu --host=x86_64-redhat-linux-gnu --with-layout=GNU --prefix=/opt/local --exec-prefix=/opt/local --sysconfdir=/etc --libdir=/opt/local/lib/php --sbindir=/opt/local/sbin --sharedstatedir=/usr/com --datadir=/opt/local/share --includedir=/opt/local/include --libexecdir=/opt/local/libexec --localstatedir=/run --mandir=/opt/local/share/man --infodir=/opt/local/share/info --with-config-file-path=/opt --with-config-file-scan-dir=/opt/php.d --enable-opcache --with-fpm-acl --with-pic --with-curl --with-freetype-dir --with-png-dir --with-gettext=shared --with-gmp=shared --with-iconv --with-jpeg-dir --with-png-dir --with-openssl --with-libxml-dir --with-pcre-regex --with-mcrypt --with-zlib --with-mhash --with-pear --with-gd --enable-gd-native-ttf --enable-calendar=shared --enable-exif --enable-ftp --enable-sockets --enable-bcmath=shared --enable-pcntl --enable-intl --enable-mbstring --enable-zip --with-bz2 --without-unixODBC --enable-mbregex --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-fpm-systemd --disable-tokenizer --disable-phar --enable-sysvsem --enable-sysvshm --enable-sysvmsg --disable-cgi --with-pgsql=/usr/pgsql-9.4 --with-pdo-pgsql=/usr/pgsql-9.4 --with-pdo-mysql --with-mysql --with-mysql-sock=/var/lib/mysql/mysql.sock --enable-mysqlnd \
然后编辑 /etc/php-fpm2.conf,注意php-fpm2.pid
pid = /run/php-fpm/php-fpm2.pid ; ....... 其他不变 [www2] prefix = /run/php-fpm/pools/$pool listen = /run/php-fpm/php-fpm2.sock listen.backlog = 2048 listen.owner = www listen.group = www listen.mode = 0666 user = www group = www pm = static pm.max_children = 10 pm.max_requests = 500 pm.status_path = /status request_terminate_timeout = 600 request_slowlog_timeout = 30 slowlog = /var/log/nginx/slow.log env[TMP] = /run/php-fpm/tmp env[TMPDIR] = /run/php-fpm/tmp env[TEMP] = /run/php-fpm/tmp [www3] prefix = /run/php-fpm/pools/$pool listen = /run/php-fpm/php-fpm3.sock listen.backlog = 2048 listen.owner = www listen.group = www listen.mode = 0666 user = www group = www pm = static pm.max_children = 10 pm.max_requests = 500 pm.status_path = /status request_terminate_timeout = 600 request_slowlog_timeout = 30 slowlog = /var/log/nginx/slow.log env[TMP] = /run/php-fpm/tmp env[TMPDIR] = /run/php-fpm/tmp env[TEMP] = /run/php-fpm/tmp
然后复制php.ini
sudo cp -p /etc/php.ini /opt/php56.ini
php5.6的配置相对5.4没啥变化,除了 default_charset = "UTF-8" 这个需要设置
===============================
关键来了,如何配置php-fpm服务呢?
编辑 /etc/systemd/system/php-fpm2.service
[Unit] Description=The PHP FastCGI Process Manager @develop After=syslog.target network.target Before=nginx.service [Service] #Type=forking Type=notify PIDFile=/run/php-fpm/php-fpm2.pid ExecStart=/opt/local/sbin/php-fpm -c /opt/php56.ini --fpm-config /etc/php-fpm2.conf ExecReload=/bin/kill -USR2 $MAINPID PrivateTmp=true WatchdogSec=30 Restart=always [Install] WantedBy=multi-user.target
注意上面PIDFile, ExecStart的参数变化了。另外Type用原来的forking也行,不过改成notify有个好处下面说。
修改 /etc/nginx/nginx.conf文件
http { upstream php_servers{ server unix:/run/php-fpm/php-fpm0.sock; server unix:/run/php-fpm/php-fpm1.sock; #server unix:/run/php-fpm/php-fpm2.sock ; #server unix:/run/php-fpm/php-fpm3.sock ; } upstream php_servers2{ #server unix:/run/php-fpm/php-fpm0.sock; #server unix:/run/php-fpm/php-fpm1.sock; server unix:/run/php-fpm/php-fpm2.sock ; server unix:/run/php-fpm/php-fpm3.sock ; }
然后修改nginx站点配置,在测试网站指定使用php_servers2作为解析
location ~ \.php$ { try_files $uri =404; # 屏蔽日志中 Primary script unknown access_log off; log_not_found off; #fastcgi_pass php_servers; fastcgi_pass php_servers2; include fastcgi.conf; }
重启服务
sudo systemctl daemon-reload sudo systemctl start php-fpm2 sudo systemctl reload nginx
这样多版本PHP就同时跑起来了。
看看php-fpm2.service 的状态呢
$ sudo systemctl status php-fpm2 php-fpm2.service - The PHP FastCGI Process Manager -develop Loaded: loaded (/etc/systemd/system/php-fpm2.service; enabled) Active: active (running) since Thu 2015-09-24 16:19:08 CST; 1 day 4h ago Main PID: 21928 (php-fpm) Status: "Processes active: 1, idle: 89, Requests: 197553, slow: 0, Traffic: 17.2req/sec" CGroup: /system.slice/php-fpm2.service ├─ 2841 php-fpm: pool www3 ├─ 2845 php-fpm: pool www3 ├─ 2846 php-fpm: pool www3 ├─ 2847 php-fpm: pool www3
看到这一行没?
Status: "Processes active: 1, idle: 89, Requests: 197553, slow: 0, Traffic: 17.2req/sec"
这就是notify类型的特色,可以提供实时统计数据。
打完收工,字数刚好不超过~~
当前已输入9977个字符, 您还可以输入23个字符