這里指的是編譯安裝的軟件 php redis nginx (mysql編譯安裝的話默認自啟動)
php 開機啟動 ,php安裝的目錄在 /usr/local/php
vim /etc/init.d/php-fpm? 復(fù)制以下代碼
#!/bin/sh
#
# php-fpm - this script starts and stops the php-fpm daemin
#
# chkconfig: - 85 15
# processname: php-fpm
# config: /usr/local/php/etc/php-fpm.conf
set -e
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC="php-fpm daemon"
NAME=php-fpm
DAEMON=/usr/local/php/sbin/$NAME
CONFIGFILE=/usr/local/php/etc/php-fpm.conf
PIDFILE=/usr/local/php/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
# If the daemon file is not found, terminate the script.
test -x $DAEMON || exit 0
d_start(){
$DAEMON -y $CONFIGFILE || echo -n " already running"
}
d_stop(){
kill -QUIT `/bin/cat $PIDFILE` || echo -n " no running"
}
d_reload(){
kill -HUP `cat $PIDFILE` || echo -n " could not reload"
}
case "$1" in
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 {start|stop|restart|force-reload)" >&2
exit 3
;;
esac
exit 0
上面需要修改的 DAEMON /usr/local/php/sbin/$NAME? 修改成為你php-fpm所在的目錄
CONFIGFILE=/usr/local/php/etc/php-fpm.conf? 你的php-fpm配置
PIDFILE=/usr/local/php/var/run/$NAME.pid? 你的pid所在目錄
這里值得注意的是蕊玷,當你安裝后直接運行你安裝目錄下sbin/php-fpm的時候并沒有使用php-fpm.conf以及安裝目錄下的var/run的pid
所以在使用的時候記得去配置你的php-fpm.conf,開啟pid所在的目錄
然后 chmod a+x /etc/init.d/php-fpm //設(shè)置權(quán)限? ? chkconfig php-fpm on? //設(shè)置開機啟動
Nginx? 編譯安裝在/usr/local/nginx 目錄中
vim /etc/init.d/nginx ?//以下代碼是官方給的
#!/bin/sh
#
# nginx - this script starts and stops the nginx daemon
#
# chkconfig:? - 85 15
# description:? NGINX is an HTTP(S) server, HTTP(S) reverse \
#? ? ? ? ? ? ? proxy and IMAP/POP3 proxy server
# processname: nginx
# config:? ? ? /etc/nginx/nginx.conf
# config:? ? ? /etc/sysconfig/nginx
# pidfile:? ? /var/run/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"
[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
lockfile=/var/lock/subsys/nginx
make_dirs() {
# make required directories
user=`$nginx -V 2>&1 | grep "configure arguments:" | sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -`
if [ -z "`grep $user /etc/passwd`" ]; then
useradd -M -s /bin/nologin $user
fi
options=`$nginx -V 2>&1 | grep 'configure arguments:'`
for opt in $options; do
if [ `echo $opt | grep '.*-temp-path'` ]; then
value=`echo $opt | cut -d "=" -f 2`
if [ ! -d "$value" ]; then
# echo "creating" $value
mkdir -p $value && chown -R $user $value
fi
fi
done
}
start() {
[ -x $nginx ] || exit 5
[ -f $NGINX_CONF_FILE ] || exit 6
make_dirs
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
sleep 1
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
怒需要修改的就是?
nginx="/usr/local/nginx/sbin/nginx" ?// 你的nginx 啟動目錄
NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf" ?//配置文件
chmod a+x /etc/init.d/nginx ? ? ? ? ? ?chkconfig nginx on
redis 編譯安裝在/usr/local/redis 目錄中
# chkconfig:? 2345 90 10
# description:? Redis is a persistent key-value database
PATH=/usr/local/redis
REDISPORT=6379
EXEC=/usr/local/redis/redis-server
REDIS_CLI=/usr/local/redis/redis-cli
#Redis密碼
PASSWORD=
PIDFILE=/var/run/redis_6379.pid
CONF=/usr/local/redis/redis.conf
case "$1" in
start)
if [ -f $PIDFILE ]
then
echo "$PIDFILE exists, process is already running or crashed"
else
echo "Starting Redis server..."
$EXEC $CONF
fi
if [ "$?"="0" ]
then
echo "Redis is running..."
fi
;;
stop)
if [ ! -f $PIDFILE ]
then
echo "$PIDFILE does not exist, process is not running"
else
PID=$(/bin/cat $PIDFILE)
echo "Stopping ..."
$REDIS_CLI -h localhost shutdown
while [ -x ${PIDFILE} ]
do
echo "Waiting for Redis to shutdown ..."
sleep 1
done
echo "Redis stopped"
fi
;;
restart|force-reload)
${0} stop
${0} start
;;
*)
echo "Usage: /etc/init.d/redis {start|stop|restart|force-reload}" >&2
exit 1
esac
PATH=/usr/local/redis
REDISPORT=6379
EXEC=/usr/local/redis/redis-server
REDIS_CLI=/usr/local/redis/redis-cli
#Redis密碼
PASSWORD=
PIDFILE=/var/run/redis_6379.pid
CONF=/usr/local/redis/redis.conf
自行配置以上
chmod a+x /etc/init.d/redis ? ?chkconfig redis on