常用服务自启动
这里指的是编译安装的软件 php redis nginx (mysql编译安装的话默认自启动)
php 开机启动 ,php安装的目录在 /usr/local/php
vim /etc/init.d/php-fpm复制以下代码
#!/bin/sh上面需要修改的 DAEMON /usr/local/php/sbin/$NAME修改成为你php-fpm所在的目录
#
# 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
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 //设置权限chkconfig php-fpm on//设置开机启动
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=https://www.it610.com/article/`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/nginxchkconfig nginx on
redis 编译安装在/usr/local/redis 目录中
# chkconfig:2345 90 10PATH=/usr/local/redis
# 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
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/redischkconfig redis on
推荐阅读
- 投稿|从分歧到共识,爱奇艺和抖音各自走出“围城”
- 西塞山前白鹭飞(三十六)
- 恋秋
- 素质教育|好多素教再获A+轮融资,着手解决课后服务“规模化”难题|融资快报
- 职场|工位设置一对一摄像头引发热议,没有「摸鱼自由」比 996 更反人性
- 炝拌五彩丝
- 自控力笔记1
- 写啥|写啥 的啥
- 【服务器数据恢复】断电导致存储raid6阵列瘫痪的数据恢复案例
- 【性能优化】MySQL常用慢查询分析工具