redis 设置开机启动

来源:互联网 发布:mac放大窗口的快捷键 编辑:程序博客网 时间:2024/05/29 23:45

一、CentOS 7.0系统下的设置方法

假设Redis已经安装,版本3.2.4

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#cd redis-4.0.1
 
#mkdir /etc/redis
 
#cp redis.conf /etc/redis/6379.conf
 
#cp utils/redis_init_script /etc/init.d/redis
 
#chmod a+x /etc/init.d/redis
 //安装后一般会在/usr/local/bin 中产生redis-server
#cp src/redis-server /usr/local/bin/
 
#cp src/redis-cli /usr/local/bin/
 
#vim /etc/init.d/redis

在脚本文件添加 #chkconfig: 2345 80 90

否则会出现 “redis服务不支持chkconfig”的错误提示

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/bin/sh
#chkconfig: 2345 80 90
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.
 
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 "$PIDFILE exists, process is already running or crashed"
else
echo "Starting Redis server..."
$EXEC $CONF
fi
;;
stop)
if [ ! -f $PIDFILE ]
then
echo "$PIDFILE does not exist, process is not running"
else
PID=$(cat$PIDFILE)
echo "Stopping ..."
$CLIEXEC -p $REDISPORTshutdown
while [ -x /proc/${PID} ]
do
echo "Waiting for Redis to shutdown ..."
sleep1
done
echo "Redis stopped"
fi
;;
*)
echo "Please use start or stop as first argument"
;;
esac

注册事件,开机启动

?
1
#chkconfig redis on

启动服务

?
1
#service redis start

查看服务是否启动

chkconfig --list 


原创粉丝点击