#1.创建启动命令脚本
vim /etc/init.d/redis-auto
#加入如下内容:
#!/bin/sh
#chkconfig: 2345 80 90
#description:auto_run
REDISPORT=6379
#注意自己安装的redis根目录
REDISPATH=/usr/local/redis/bin
EXEC=
R
E
D
I
S
P
A
T
H
/
r
e
d
i
s
−
s
e
r
v
e
r
C
L
I
E
X
E
C
=
{REDISPATH}/redis-server CLIEXEC=
R
E
D
I
S
P
A
T
H
/
r
e
d
i
s
−
s
e
r
v
e
r
C
L
I
E
X
E
C
=
{REDISPATH}/redis-cli
PIDFILE=/var/run/redis_
R
E
D
I
S
P
O
R
T
.
p
i
d
C
O
N
F
=
”
{REDISPORT}.pid CONF=”
R
E
D
I
S
P
O
R
T
.
p
i
d
C
O
N
F
=
”
{REDISPATH}/redis.conf”
case “$1” in
start)
if [ -f
P
I
D
F
I
L
E
]
t
h
e
n
e
c
h
o
”
PIDFILE ] then echo ”
P
I
D
F
I
L
E
]
t
h
e
n
e
c
h
o
”
PIDFILE exists, process is already running or crashed”
else
echo “Starting Redis server…”
$EXEC $CONF
fi
;;
stop)
if [ ! -f
P
I
D
F
I
L
E
]
t
h
e
n
e
c
h
o
”
PIDFILE ] then echo ”
P
I
D
F
I
L
E
]
t
h
e
n
e
c
h
o
”
PIDFILE does not exist, process is not running”
else
PID=$(cat $PIDFILE)
echo “Stopping …”
$CLIEXEC -p
R
E
D
I
S
P
O
R
T
s
h
u
t
d
o
w
n
w
h
i
l
e
[
−
x
/
p
r
o
c
/
REDISPORT shutdown while [ -x /proc/
R
E
D
I
S
P
O
R
T
s
h
u
t
d
o
w
n
w
h
i
l
e
[
−
x
/
p
r
o
c
/
{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
#wq保存退出
#2.设置文件redis-auto的权限,让Linux可以执行
chmod 755 /etc/init.d/redis-auto
#3.启动Redis服务测试,如果看到Redis启动的小盒子就表示成功,不过你可以进一步打开redis-cli客户端进行测试
/etc/init.d/redis-auto start
#4.设置开机自启动,即:
chkconfig redis-auto on