Ubuntu16設置Redis開機自啟動
阿新 • • 發佈:2019-03-28
default class art pla span 代碼 data syn base
Ubuntu16設置Redis開機自啟動
設置條件:
-Ubuntu16.04
-Redis-4.0.11
在redis目錄下找到 utils/redis_init_script 復制到 /etc/init.d/redis 打開文件進行修改
步驟:(主要Linux命令)
whereis redis # 查找redis目錄 sudo cp redis_init_script /etc/init.d/redis # 復制文件 cd /etc/init.d/ # 進入文件目錄 sudo vim redis # 編輯配置文件redis
原配置文件
1 #!/bin/sh 2 # 3 # Simple Redis init.d script conceived to work on Linux systems 4 # as it does use of the /proc filesystem. 5 ? 6 ### BEGIN INIT INFO 7 # Provides: redis_6379 8 # Default-Start: 2 3 4 5 9 # Default-Stop: 0 1 6 10 # Short-Description: Redis data structure server 11 # Description: Redis data structure server. See https://redis.io 12 ### END INIT INFO 13 ? 14 REDISPORT=6379 15 EXEC=/usr/local/bin/redis-server 16 CLIEXEC=/usr/local/bin/redis-cli 17 ? 18 PIDFILE=/var/run/redis_${REDISPORT}.pid 19 CONF="/etc/redis/${REDISPORT}.conf"
修改後的配置文件
1 #!/bin/sh 2 # 3 # chkconfig: 2345 90 10 ---這裏修改 4 # description: Redis is a persistent key-value database ---這裏修改 5 ? 6 ### BEGIN INIT INFO 7 # Provides: redis_6379 8 # Required-Start: ---這裏修改 9 # Required-Stop: ---這裏修改 10 # Default-Start: 2 3 4 5 11 # Default-Stop: 0 1 6 12 # Short-Description: Redis data structure server 13 # Description: Redis data structure server. See https://redis.io 14 ### END INIT INFO 15 ? 16 REDISPORT=6379 17 EXEC=/usr/local/bin/redis-server 18 CLIEXEC=/usr/local/bin/redis-cli 19 ? 20 PIDFILE=/var/run/redis_${REDISPORT}.pid 21 CONF="/etc/redis/redis.conf" # ---這裏修改
修改完配置文件後執行下面兩條命令
sudo chmod +x /etc/init.d/redis # 取得權限 sudo update-rc.d redis defaults # 加載到系統自啟動文件
測試命令:
1 2 3 4 |
kady@ubuntu:/etc/init . d$ sudo update-rc . d redis defaults
kady@ubuntu:/etc/init . d$ service redis start # 啟動redis服務
kady@ubuntu:/etc/init . d$ redis-cli 127.0.0.1 : 6379 > # 設置成功
|
其他命令:
1 2 3 4 5 |
啟動服務: service redis start
停止服務: service redis stop
重啟服務: service redis restart
|
分類: Redis
Ubuntu16設置Redis開機自啟動