Ubuntu设置redis开机自启

前提条件:

  • Ubuntu
  • redis

1、在redis目录下找到 utils/redis_init_script 复制到 /etc/init.d/redis,并且按如下修改;

例如我的指令为:

cp /home/redis-6379/utils/redis_init_script /etc/init.d/redis_6379

2、修改文档redis_6379

按自身的配置修改:
源文件:

#!/bin/sh
#
# 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"

修改后:

#!/bin/sh
#
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.

REDISPORT=6379
EXEC=/home/redis-6379/src/redis-server
CLIEXEC=/home/redis-6379/src/redis-cli

PIDFILE=/var/run/redis_${REDISPORT}.pid
CONF="/home/redis-6379/redis.conf"

3、添加到开机自动服务

update-rc.d –f redis_6379 defaults

sysv-rc-conf redis_6379 on

用如下命令查看是否设置成功:

sysv-rc-conf --list redis_6379 

出现下图所示内容,代表设置成功

tomcat       2:on	3:on	4:on	5:on

重启电脑验证一下:

reboot 

如果你有搭建redis主从同步机制,照以上步骤设计从redis的开机重启!
例如我的从redis为redis-6380,那么造上面步骤拷贝一个redis-6380的脚本并修改即可

你可能感兴趣的:(redis,Linux)