1、设置Redis.conf中daemonize为yes,确保守护进程开启;
找到#requirepass foorbared这一行,直接替换掉这行,改为requirepass 新密码
2、编写开机自启动脚本vi/etc/init.d/redis
脚本内容如下:#!/bin/sh
#chkconfig:23458090
#SimpleRedisinit.dscriptconceivedtoworkonLinuxsystems
#asitdoesuseofthe/procfilesystem.
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"$PIDFILEexists,processisalreadyrunningorcrashed"
else
echo"StartingRedisserver..."
$EXEC$CONF
fi
;;
stop)
if[!-f$PIDFILE]
then
echo"$PIDFILEdoesnotexist,processisnotrunning"
else
PID=$(cat$PIDFILE)
echo"Stopping..."
$CLIEXEC-p$REDISPORTshutdown
while[-x/proc/${PID}]
do
echo"WaitingforRedistoshutdown..."
sleep1
done
echo"Redisstopped"
fi
;;
*)
echo"Pleaseusestartorstopasfirstargument"
;;
esac
3、写完后保存退出
4、设置权限chmod755redis
5、启动测试/etc/init.d/redisstart
6、连接测试redis-cli-a新密码-p6379
7、设置开机自启动chkconfigredison