特別說明:
1.以下這些變數得配置成自己的。且 pidfile 應為 /var/run/redis_$.pid.不修改這裡,stop的時候關不掉。
redisport=6379exec=/usr/redisbin/redis-server
redis_cli=/usr/redisbin/redis-cli
pidfile=/var/run/redis.pid
conf="
/usr/redisbin/redis.conf
"auth="
1234
"
2.我遇到的stop的時候,提示錯誤:(error) noauth authentication required.
該錯誤是因為配置檔案裡配置了密碼,需要修改下面的檔案。
$redis_cli -p $redisport shutdown
改為 $redis_cli -a "your password" -p $redisport shutdown
廢話少說,直接來步驟:
1、設定redis.conf中daemonize為yes,確保守護程序開啟。
2、編寫開機自啟動指令碼
vi /etc/init.d/redis
指令碼內容如下:
# chkconfig: 23451090
# description: start and stop redis
path=/usr/local/bin:/sbin:/usr/bin:/bin
redisport=6379
exec=/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.
"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
2while [ -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
" >&2
exit
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-cli127.0.0.1:6379> set
foo bar
ok127.0.0.1:6379> get
foo"
bar"
127.0.0.1:6379> exit
6、設定開機自啟動
chkconfig redis on
7、關機重啟測試
reboot
然後在用redis-cli測試即可。
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 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...