摘取:Ubuntu设置redis开机自启

前提条件:

- Ubuntu

- redis

 

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

  • 修改文档开头

#!/bin/sh# chkconfig: 2345 90 10# description: Redis is a persistent key-value database

### BEGIN INIT INFO# Provides: redis_6379

# Required-Start:# Required-Stop:

# Default-Start: 2 3 4 5

# Default-Stop: 0 1 6

# Short-Description: Redis data structure server

# Description: Redis data structure server. See https://redis.io

### END INIT INFO

  • 按自身修改配置

REDISPORT=6379EXEC=/usr/local/bin/redis-serverCLIEXEC=/usr/local/bin/redis-cliPIDFILE=/var/run/redis_${REDISPORT}.pidCONF="/etc/redis/${REDISPORT}.conf"

  •  
  • 执行

sudo chmod +x /etc/init.d/redis

 

sudo update-rc.d redisd defaults

 

如果执行报错,检查文件夹是否存在

  • 启动服务 service redis start
  • 停止服务 service redis stop
  • 重启服务 service redis restart

你可能感兴趣的:(ubuntu)