Linux下Redis開機自啟(Centos)

2021-09-07 19:50:39 字數 1445 閱讀 6531

廢話少說,直接來步驟:

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=6379exec=/usr/redisbin/redis-server redis_cli=/usr/redisbin/redis-cli pidfile=/var/run/redis.pid conf="/usr/redisbin/redis.conf"auth="1234" case "$1" instart) if [ -f $pidfile ] then echo "$pidfile exists, process is already running or crashed." elseecho "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." elsepid=$(cat $pidfile) echo "stopping..."$redis_cli -p $redisport shutdown sleep 2 while [ -x $pidfile ] doecho "waiting for redis to shutdown..."sleep 1done echo "redis stopped"fi ;; restart|force-reload) $ stop $ start ;; *) echo "usage: /etc/init.d/redis " >&2exit 1esac

3、寫完後儲存退出vi

4、設定許可權

chmod 755 redis
5、啟動測試

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

starting redis server...

redis is running...

使用redis-cli測試:

[root@rk ~]# /usr/redisbin/redis-cli

127.0.0.1:6379> setfoo bar ok 127.0.0.1:6379> getfoo "bar" 127.0.0.1:6379> exit

6、設定開機自啟動

chkconfig redis on
7、關機重啟測試

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 usr local bin...

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...