前言:
背景:微信小程序:中玉玉器微商平台。由于这个项目业务扩充,原有的服务器不足以完成现在需求。需要更大的空间和响应速度,原由服务器都不能满足。
原项目架构:Apache(2.4.9)+PHP(5.5.12)+MySQL(5.6.17);现改:Nginx+PHP(7.0.0)+MySQL;
问题:
(代码比较多,请耐心看下去)
报错nginx.service不存在
#!/bin/sh # nginx - this script starts and stops the nginx daemin # # chkconfig: - 85 15 # description: Nginx is an HTTP(S) server, HTTP(S) reverse \ # proxy and IMAP/POP3 proxy server # processname: nginx # config: /usr/local/nginx/conf/nginx.conf # pidfile: /usr/local/nginx/logs/nginx.pid # Source function library. . /etc/rc.d/init.d/functions # Source networking configuration. . /etc/sysconfig/network # Check that networking is up. [ "$NETWORKING" = "no" ] && exit 0 nginx="/usr/local/nginx/sbin/nginx" prog=$(basename $nginx) NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf" lockfile=/var/lock/subsys/nginx start() { [ -x $nginx ] || exit 5 [ -f $NGINX_CONF_FILE ] || exit 6 echo -n $"Starting $prog: " daemon $nginx -c $NGINX_CONF_FILE retval=$? echo [ $retval -eq 0 ] && touch $lockfile return $retval } stop() { echo -n $"Stopping $prog: " killproc $prog -QUIT retval=$? echo [ $retval -eq 0 ] && rm -f $lockfile return $retval } restart() { configtest || return $? stop start } reload() { configtest || return $? echo -n $"Reloading $prog: " killproc $nginx -HUP RETVAL=$? echo } force_reload() { restart } configtest() { $nginx -t -c $NGINX_CONF_FILE } rh_status() { status $prog } rh_status_q() { rh_status >/dev/null 2>&1 } case "$1" in start) rh_status_q && exit 0 $1 ;; stop) rh_status_q || exit 0 $1 ;; restart|configtest) $1 ;; reload) rh_status_q || exit 7 $1 ;; force-reload) force_reload ;; status) rh_status ;; condrestart|try-restart) rh_status_q || exit 0 ;; *) echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}" exit 2 esac
php -v PHP 7.0.0 (cli) (built: Jun 19 2018 08:56:00) ( NTS ) Copyright (c) 1997-2015 The PHP Group Zend Engine v3.0.0, Copyright (c) 1998-2015 Zend Technologies
Redirecting to /bin/systemctl start php-fpm.service Failed to start php-fpm.service: Unit not found.
Failed to start php-fpm.service: Unit not found.
Unit php-fpm.service could not be found.
所有这个都提示:php-fpm.service 没有找到。那因为就是因为不存在。于是从网上找到了如下代码:
php-fpm.service:[Unit] Description=The PHP FastCGI Process Manager After=syslog.target network.target [Service] Type=simple PIDFile=/run/php-fpm.pid ExecStart=/usr/local/php7/sbin/php-fpm --nodaemonize --fpm-config /usr/local/php/etc/php-fpm.conf ExecReload=/bin/kill -USR2 $MAINPID ExecStop=/bin/kill -SIGINT $MAINPID [Install] WantedBy=multi-user.target
然后结果还是不对,上面的代码或许放在你们那就是能用的。
报错如下:systemctl status php-fpm.service ● php-fpm.service - The PHP FastCGI Process Manager Loaded: loaded (/usr/lib/systemd/system/php-fpm.service; disabled; vendor pre set: disabled) Active: failed (Result: exit-code) since Tue 2018-06-19 13:28:16 CST; 16s ago Process: 12583 ExecStop=/bin/kill -SIGINT $MAINPID (code=exited, status=1/FAIL URE) Process: 12581 ExecStart=/usr/local/php7/sbin/php-fpm --nodaemonize --fpm-conf ig /usr/local/php7/etc/php-fpm.conf (code=exited, status=203/EXEC) Main PID: 12581 (code=exited, status=203/EXEC) Jun 19 13:28:16 vm10-0-0-19.ksc.com kill[12583]: -q, --queue use ...) Jun 19 13:28:16 vm10-0-0-19.ksc.com kill[12583]: -p, --pid prin...m Jun 19 13:28:16 vm10-0-0-19.ksc.com kill[12583]: -l, --list [=] list...e Jun 19 13:28:16 vm10-0-0-19.ksc.com kill[12583]: -L, --table list...s Jun 19 13:28:16 vm10-0-0-19.ksc.com kill[12583]: -h, --help display this...t Jun 19 13:28:16 vm10-0-0-19.ksc.com kill[12583]: -V, --version output versi...t Jun 19 13:28:16 vm10-0-0-19.ksc.com kill[12583]: For more details see kill(1). Jun 19 13:28:16 vm10-0-0-19.ksc.com systemd[1]: php-fpm.service: control pro...1 Jun 19 13:28:16 vm10-0-0-19.ksc.com systemd[1]: Unit php-fpm.service entered.... Jun 19 13:28:16 vm10-0-0-19.ksc.com systemd[1]: php-fpm.service failed. Hint: Some lines were ellipsized, use -l to show in full
原因:
改正后:[Unit]部分主要是对这个服务的说明,内容包括Description和After,Description用于描述服务,After用于描述服务类别[Unit] Description=php-fpm
我不明白为什么上面的description 改成 php-fpm后,还是不行,以及为甚么php-fpm不可以?希望懂的人,能给我解析一下
关于php-fpm.service 最终的代码内容:[Unit] Description=The PHP FastCGI Process Manager After=syslog.target network.target [Service] Type=simple PIDFile=/run/php-fpm.pid ExecStart=/usr/local/php/sbin/php-fpm --nodaemonize --fpm-config /usr/local/php/etc/php-fpm.conf ExecReload=/bin/kill -USR2 $MAINPID ExecStop=/bin/kill -SIGINT $MAINPID [Install] WantedBy=multi-user.target上面改后,然后就是下面的报错。
systemctl status php-fpm.service -l
● php-fpm.service - php-fpm
ExecStart=/usr/local/php/sbin/php-fpm (code=exited, status=0/SUCCESS)
Jun 19 16:04:16 vm10-0-0-19.ksc.com systemd[1]: Starting php-fpm...
Jun 19 16:04:16 vm10-0-0-19.ksc.com systemd[1]: PID file /var/run/php-fpm.pid not readable (yet?) after start.
Jun 19 16:05:46 vm10-0-0-19.ksc.com systemd[1]: php-fpm.service start operation timed out. Terminating.
Jun 19 16:05:46 vm10-0-0-19.ksc.com systemd[1]: Failed to start php-fpm.
Jun 19 16:05:46 vm10-0-0-19.ksc.com systemd[1]: Unit php-fpm.service entered failed state.
Jun 19 16:05:46 vm10-0-0-19.ksc.com systemd[1]: php-fpm.service failed.
;pid = run/php-fpm.pid
改过php-fpm.service 后 记得systemctl deamon-restart:然后再开启systemtcl start php-fpm.service
百度别人解决办法:
在/etc/init.d/下添加php-fpm 内容如下:直接复制粘贴到php-fpm下。参考:php-fpm服务启动脚本#! /bin/sh ### BEGIN INIT INFO # Provides: php-fpm # Required-Start: $remote_fs $network # Required-Stop: $remote_fs $network # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: starts php-fpm # Description: starts the PHP FastCGI Process Manager daemon ### END INIT INFO prefix=/usr/local/php exec_prefix=${prefix} php_fpm_BIN=${exec_prefix}/sbin/php-fpm php_fpm_CONF=${prefix}/etc/php-fpm.conf php_fpm_PID=${prefix}/var/run/php-fpm.pid php_opts="--fpm-config $php_fpm_CONF --pid $php_fpm_PID" wait_for_pid () { try=0 while test $try -lt 35 ; do case "$1" in 'created') if [ -f "$2" ] ; then try='' break fi ;; 'removed') if [ ! -f "$2" ] ; then try='' break fi ;; esac echo -n . try=`expr $try + 1` sleep 1 done } case "$1" in start) echo -n "Starting php-fpm " $php_fpm_BIN --daemonize $php_opts if [ "$?" != 0 ] ; then echo " failed" exit 1 fi wait_for_pid created $php_fpm_PID if [ -n "$try" ] ; then echo " failed" exit 1 else echo " done" fi ;; stop) echo -n "Gracefully shutting down php-fpm " if [ ! -r $php_fpm_PID ] ; then echo "warning, no pid file found - php-fpm is not running ?" exit 1 fi kill -QUIT `cat $php_fpm_PID` wait_for_pid removed $php_fpm_PID if [ -n "$try" ] ; then echo " failed. Use force-quit" exit 1 else echo " done" fi ;; status) if [ ! -r $php_fpm_PID ] ; then echo "php-fpm is stopped" exit 0 fi PID=`cat $php_fpm_PID` if ps -p $PID | grep -q $PID; then echo "php-fpm (pid $PID) is running..." else echo "php-fpm dead but pid file exists" fi ;; force-quit) echo -n "Terminating php-fpm " if [ ! -r $php_fpm_PID ] ; then echo "warning, no pid file found - php-fpm is not running ?" exit 1 fi kill -TERM `cat $php_fpm_PID` wait_for_pid removed $php_fpm_PID if [ -n "$try" ] ; then echo " failed" exit 1 else echo " done" fi ;; restart) $0 stop $0 start ;; reload) echo -n "Reload service php-fpm " if [ ! -r $php_fpm_PID ] ; then echo "warning, no pid file found - php-fpm is not running ?" exit 1 fi kill -USR2 `cat $php_fpm_PID` echo " done" ;; *) echo "Usage: $0 {start|stop|force-quit|restart|reload|status}" exit 1 ;; esacchmod 755 /etc/init.d/php-fpm # php-fpm加入服务 chkconfig--add php-fpm # php-fpm 234级别下设置为启动 chkconfig php-fpm on
到这里在重启php-fpm时,杀掉已经占用端口的进程。应该active了。当然很有可能还有其他问题,但是耐下心来,总会解决。
有关MySQL 的安装,待更新