Linux下Redis開機自啟(Centos)

2021-10-20 05:41:13 字數 1803 閱讀 9640

1、設定redis.conf中daemonize為yes,確保守護程序開啟。

2、編寫開機自啟動指令碼

vi /etc/init.d/redis
指令碼內容如下:

# chkconfig: 2345 10 90  

# description: start and stop redis

path=/usr/local/bin:/sbin:/usr/bin:/bin

redisport=6379

exec=/usr/local/redis/bin/redis-server

redis_cli=/usr/local/redis/bin/redis-cli

pidfile=/var/run/redis.pid

conf="/usr/local/redis/etc/redis.conf"

auth="123456"

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 exists, process is not running."

else

pid=$(cat $pidfile)

echo "stopping..."

$redis_cli -p $redisport shutdown

sleep 2

while [ -x $pidfile ]

do

echo "waiting for redis to shutdown..."

sleep 1

done

echo "redis stopped"

fi

;;

restart|force-reload)

$ stop

$ start

;;

*)

echo "usage: /etc/init.d/redis " >&2

exit 1

esac

3、設定許可權

chmod 755 /etc/init.d/redis
4、啟動測試

/etc/init.d/redis start
啟動成功會提示如下資訊:

starting redis server...

redis is running...

5、設定開機自啟動

chkconfig redis on
6、關機重啟測試

reboot
然後在用redis-cli測試即可。

Linux下Redis開機自啟(Centos)

特別說明 1.以下這些變數得配置成自己的。且 pidfile 應為 var run redis pid.不修改這裡,stop的時候關不掉。redisport 6379 exec usr redisbin redis server redis cli usr redisbin redis cli pi...

Linux下Redis開機自啟(Centos)

廢話少說,直接來步驟 1 設定redis.conf中daemonize為yes,確保守護程序開啟。2 編寫開機自啟動指令碼 vi etc init.d redis指令碼內容如下 chkconfig 2345 10 90 description start and stop redis path us...

Linux下Redis開機自啟(Centos)

廢話少說,直接來步驟 1 設定redis.conf中daemonize為yes,確保守護程序開啟。2 編寫開機自啟動指令碼 vi etc init.d redis指令碼內容如下 chkconfig 2345 10 90 description start and stop redis path us...