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