1.下载redis安装包
Redis官方下载地址:http://redis.io/download,下载最新稳定版本
1 2 3 4 |
wget http://download.redis.io/releases/redis-4.0.6.tar.gz tar -zxvf redis-4.0.6.tar.gz mv redis-4.0.6 /opt/ #这个目录随意你爱放哪放哪 yum install gcc |
进入解压好的目录并编译安装redis
1 2 3 |
cd /opt/redis-4.0.6 make make install |
启动redis服务
1 2 3 4 5 6 7 8 9 10 |
redis-server redis-server & #后台启动 #注意这种方式启动redis 使用的是默认配置。也可以通过启动参数告诉redis使用指定配置文件使用下面命令启动。 ./redis-server redis.conf 停止redis 1.redis-cli shutdown 2.ps -ef | grep 6379 kill -9 [进程号] |
1. 设置redis开机自启动 第一种办法
编辑配置文件
1 2 3 |
vim /opt/redis/redis.conf 修改 daemonize no 修改为 yes |

1 2 3 4 5 6 7 8 9 10 11 12 |
mkdir -p /usr/local/redis #将/opt/redis/redis.conf 文件复制一份到/usr/local/redis目录下,并命名为6379.conf 这个在下面的启动脚本中有调用(当然你可以修改调用名称) cp /opt/redis/redis.conf /usr/local/redis/6379.conf #将redis的启动脚本复制一份放到/etc/init.d目录下 cp /opt/redis/utils/redis_init_script /etc/init.d/redis #修改redis,vim /etc/init.d/redis 1.添加这2行,在#!/bin/bash下 # chkconfig: 2345 10 90 # description: Start and Stop redis 2.修改这一行路径指向你上面复制到的实际路径 CONF="/usr/local/redis/${REDISPORT}.conf" |

启动redis服务
1 2 3 4 5 6 7 |
/etc/init.d/redis start /etc/init.d/redis stop 或者 打开redis命令:service redis start 关闭redis命令:service redis stop |

设为开机启动
1 2 |
设为开机启动:chkconfig redis on 设为开机关闭:chkconfig redis off |
2. 设置开机启动 第二种办法(推荐这种,方便)
进入redis目录:/opt/redis
1 2 |
执行 ./utils/install_server.sh |
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 |
[root@localhost redis-4.0.9]# ./utils/install_server.sh Welcome to the redis service installer This script will help you easily set up a running redis server Please select the redis port for this instance: [6379] Selecting default: 6379 Please select the redis config file name [/etc/redis/6379.conf] Selected default - /etc/redis/redis.conf Please select the redis log file name [/var/log/redis_6379.log] Selected default - /var/log/redis.log Please select the data directory for this instance [/var/lib/redis/6379] Selected default - /var/lib/redis/db Please select the redis executable path [/usr/local/bin/redis-server] Selected config: Port : 6379 Config file : /etc/redis/redis Log file : /var/log/redis.log Data dir : /var/lib/redis/db Executable : /usr/local/bin/redis-server Cli Executable : /usr/local/bin/redis-cli Is this ok? Then press ENTER to go on or Ctrl-C to abort. Copied /tmp/6379.conf => /etc/init.d/redis_6379 Installing service... Successfully added to chkconfig! Successfully added to runlevels 345! Starting Redis server... Installation successful! |
以上操作可以将redis设置为开机启动。
1 2 3 4 5 6 7 8 |
PS: 通过这种方式这是redis开机启动,redis的配置文件路径:/etc/redis/6379.conf 所以如果修改redis的配置文件,修改路径应该是:/etc/redis/6379.conf redis安装目录下的配置文件/opt/local/redis-4.0.9/redis.conf修改会不生效; 如果想要使用/opt/local/redis-4.0.9/redis.conf,修改/etc/init.d/redis_6379文件即可 |
启动停止
1 2 |
/etc/init.d/redis_6379 start /etc/init.d/redis_6379 stop |
查看开机启动项

- 本文固定链接: https://www.yoyoask.com/?p=675
- 转载请注明: shooter 于 SHOOTER 发表