1. nginx
A. # vi /etc/init.d/nginx
B.
#!/bin/sh
# Comments to support chkconfig on RedHat Linux
# chkconfig: 2345 65 37
# description: A nginx daemon. set -e
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC="nginx daemon"
NAME=nginx
DAEMON=/usr/local/nginx/sbin/$NAME
SCRIPTNAME=/etc/init.d/$NAME # If the daemon file is not found, terminate the script.
test -x $DAEMON || exit 0 d_test() {
$DAEMON -t
}
d_start() {
$DAEMON || echo -n " already running"
}
d_stop() {
$DAEMON -s quit || echo -n " not running"
}
d_reload() {
$DAEMON -s reload || echo -n " could not reload"
} case "$1" in
test)
d_test
echo "."
;;
start)
echo -n "Starting $DESC: $NAME"
d_start
echo "."
;;
stop)
echo -n "Stopping $DESC: $NAME"
d_stop
echo "."
;;
reload)
echo -n "Reloading $DESC configuration..."
d_reload
echo "reloaded."
;;
restart)
echo -n "Restarting $DESC: $NAME"
d_stop
# Sleep for two seconds before starting again, this should give the
# Nginx daemon some time to perform a graceful stop.
sleep 2
d_start
echo "."
;;
*)
echo "Usage: $SCRIPTNAME {test|start|stop|restart|reload}" >&2
exit 3
;;
esac exit $?
C.注册 nginx 服务
chmod +x /etc/init.d/nginx chkconfig --add nginx chkconfig --level 2345 nginx on chkconfig --list nginx
1. php-fpm
1.配置php-fpm.conf(vi /usr/local/php/etc/php-fpm.conf),将 ;pid = run/php-fpm.pid 前的;去掉。
2.cd /
3.find -name init.d.php-fpm
4.cp home/apps/web/php/php-5.6.2/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm 该代码切勿复制,请根据您的存放地址保存
注意
如果你php-fpm放入service中会出现这种情况,
采用
/usr/local/php/sbin/php-fpm -y=/usr/local/php/etc/php-fpm.conf -c=/usr/local/php/etc/php.ini
这种方式启动的phpinfo中 Loaded Configuration File 是有值的
service php-fpm start 启动方式 Loaded Configuration File 是none
这个问题我纠结了好久 最终发现在service php-fpm代码中 php的运行开启方式是不对的(我也布知道是否正确)
将代码修改为
vi /etc/init.d/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_ini_CONF=${prefix}/etc/php.ini php_opts="--fpm-config $php_fpm_CONF --pid $php_fpm_PID"
php_start_opts="-c $php_ini_CONF -y $php_fpm_CONF" 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 $php_start_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
;; esac
红色部分为修改部分,最终运行结果成功,我估计是开启的方式的不同 导致 Loaded Configuration File 值是none
如果有更好的解决办法,请大神留言
C.添加服务
chmod +x /etc/init.d/php-fpm chkconfig --add php-fpm chkconfig --level 2345 php-fpm on chkconfig --list php-fpm