一、CentOS 7.0系統(tǒng)下的設(shè)置方法
假設(shè)Redis已經(jīng)安裝,版本3.2.4
#cd redis-3.2.4
#mkdir /etc/redis
#cp redis.conf /etc/redis/6379.conf
#cp utils/redis_init_script /etc/init.d/redis
#chmod a+x /etc/init.d/redis
#cp src/redis-server /usr/local/bin/
#cp src/redis-cli /usr/local/bin/
#vim /etc/init.d/redis
在腳本文件添加 #chkconfig: 2345 80 90
否則會(huì)出現(xiàn) “redis服務(wù)不支持chkconfig”的錯(cuò)誤提示
#!/bin/sh
#chkconfig: 2345 80 90
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.
REDISPORT=6379
EXEC=/usr/local/bin/redis-server
CLIEXEC=/usr/local/bin/redis-cli
PIDFILE=/var/run/redis_${REDISPORT}.pid
CONF="/etc/redis/${REDISPORT}.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
;;
stop)
if [ ! -f $PIDFILE ]
then
echo "$PIDFILE does not exist, process is not running"
else
PID=$(cat $PIDFILE)
echo "Stopping ..."
$CLIEXEC -p $REDISPORT shutdown
while [ -x /proc/${PID} ]
do
echo "Waiting for Redis to shutdown ..."
sleep 1
done
echo "Redis stopped"
fi
;;
*)
echo "Please use start or stop as first argument"
;;
esac
注冊(cè)事件,開(kāi)機(jī)啟動(dòng)
啟動(dòng)服務(wù)
查看服務(wù)是否啟動(dòng)
二、Debian 8.0設(shè)置方法
步驟與上面類(lèi)似,不過(guò)Debian 用update-rc.d
(或insserv)代替chkconfig
腳本文件描述也不一樣。
假設(shè)Redis已經(jīng)安裝,版本3.2.4
#cd redis-3.2.4
#mkdir /etc/redis
#cp redis.conf /etc/redis/6379.conf
#cp utils/redis_init_script /etc/init.d/redis
#chmod a+x /etc/init.d/redis
#cp src/redis-server /usr/local/bin/
#cp src/redis-cli /usr/local/bin/
#vim /etc/init.d/redis
在腳本文件添加
### BEGIN INIT INFO
# Provides: redis6379
# Required-Start: $local_fs $network
# Required-Stop: $local_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: redis6379
# Description: penavico redis 6379
### END INIT INFO
否則會(huì)出現(xiàn) “ insserv: warning: script ‘redis6379′ missing LSB tags and overrides”
的錯(cuò)誤提示
#!/bin/sh
#
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.
### BEGIN INIT INFO
# Provides: redis6379
# Required-Start: $local_fs $network
# Required-Stop: $local_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: redis6379
# Description: penavico redis 6379
### END INIT INFO
REDISPORT=6379
EXEC=/usr/local/bin/redis-server
CLIEXEC=/usr/local/bin/redis-cli
PIDFILE=/var/run/redis_${REDISPORT}.pid
CONF="/etc/redis/${REDISPORT}.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
;;
stop)
if [ ! -f $PIDFILE ]
then
echo "$PIDFILE does not exist, process is not running"
else
PID=$(cat $PIDFILE)
echo "Stopping ..."
$CLIEXEC -p $REDISPORT shutdown
while [ -x /proc/${PID} ]
do
echo "Waiting for Redis to shutdown ..."
sleep 1
done
echo "Redis stopped"
fi
;;
*)
echo "Please use start or stop as first argument"
;;
esac
注冊(cè)事件,開(kāi)機(jī)啟動(dòng)
#update-rc.d redisd defaults
啟動(dòng)服務(wù)
查看服務(wù)是否啟動(dòng)
開(kāi)機(jī)啟動(dòng)以后,默認(rèn)的配置文件位置:/etc/redis/6379.conf
總結(jié)
以上就是這篇文章的全部?jī)?nèi)容了,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作能帶來(lái)一定的幫助,如果有疑問(wèn)大家可以留言交流,謝謝大家對(duì)腳本之家的支持。
您可能感興趣的文章:- linux設(shè)置服務(wù)開(kāi)機(jī)自啟動(dòng)的三種方式
- linux下oracle設(shè)置開(kāi)機(jī)自啟動(dòng)實(shí)現(xiàn)方法
- Linux下的Oracle啟動(dòng)腳本及其開(kāi)機(jī)自啟動(dòng)
- Linux中Oracle服務(wù)啟動(dòng)和停止腳本與開(kāi)機(jī)自啟動(dòng)
- Linux 添加開(kāi)機(jī)啟動(dòng)方法(服務(wù)/腳本)
- linux開(kāi)機(jī)啟動(dòng)nodemanager步驟
- Linux下Redis設(shè)置密碼及開(kāi)機(jī)自啟動(dòng)
- Linux開(kāi)機(jī)啟動(dòng)過(guò)程詳解
- linux 開(kāi)機(jī)自啟動(dòng)redis服務(wù)的方法
- Linux系統(tǒng)設(shè)置開(kāi)機(jī)自動(dòng)運(yùn)行腳本的方法實(shí)例