一、环境和版本

Linux:centos7 三台

  1. 三台Linux服务
  2. 192.168.72.129
  3. 192.168.72.130
  4. 192.168.72.131
  5. Redisredis-4.0.14

二、上传Redis软件

1、创建软件目录

  1. [root@localhost local]# cd /usr/local/
  2. [root@localhost local]# mkdir mysoft

2、Xftp上传软件,解压

  1. [root@localhost mysoft]# cd /usr/local/mysoft/
  2. [root@localhost mysoft]# ll
  3. total 1704
  4. -rw-r--r--. 1 root root 1740967 Apr 30 11:29 redis-4.0.14.tar.gz
  5. [root@localhost mysoft]# tar -zxvf redis-4.0.14.tar.gz

3、编译项目

  1. [root@localhost mysoft]# ll
  2. total 1708
  3. drwxrwxr-x. 6 root root 4096 Mar 19 00:23 redis-4.0.14
  4. -rw-r--r--. 1 root root 1740967 Apr 30 11:29 redis-4.0.14.tar.gz
  5. [root@localhost mysoft]# cd redis-4.0.14/
  6. [root@localhost redis-4.0.14]# make MALLOC=libc

4、安装Redis

  1. [root@localhost redis-4.0.14]# cd src && make install

5、启动服务

  1. [root@localhost redis-4.0.14]# cd src
  2. [root@localhost src]# ./redis-server

6、配置进程启动

修改redis.conf

  1. daemonize yes

7、进程查看关闭

  1. [root@localhost redis-4.0.14]# ./src/redis-server redis.conf
  2. 11320:C 05 May 14:26:31.053 # Redis is starting
  3. 11320:C 05 May 14:26:31.053 # Redis version=4.0.14, bits=64, commit=00000000, modified=0, pid=11320, just started
  4. 11320:C 05 May 14:26:31.053 # Configuration loaded
  5. [root@localhost redis-4.0.14]# ps -aux |grep redis
  6. root 11321 0.1 0.1 141840 2028 ? Ssl 14:26 0:00 ./src/redis-server *:6379
  7. root 11338 0.0 0.0 112708 980 pts/1 S+ 14:27 0:00 grep --color=auto redis
  8. [root@localhost redis-4.0.14]# kill -9 11321

三、配置开机启动

1、相关配置

  1. [root@localhost init.d]# cd /etc
  2. [root@localhost etc]# mkdir redis
  3. [root@localhost etc]# cp /usr/local/mysoft/redis-4.0.14/redis.conf /etc/redis/6379.conf
  4. [root@localhost etc]# cd redis/
  5. [root@localhost redis]# ll
  6. total 60
  7. -rw-r--r--. 1 root root 58767 May 5 14:36 redis-6379.conf
  8. [root@localhost redis]# cp /usr/local/mysoft/redis-4.0.14/utils/redis_init_script /etc/init.d/redisd
  9. [root@localhost redis]# chkconfig redisd on # 开机启动命令

2、服务启动关闭

  1. [root@localhost redis]# service redisd start
  2. Starting Redis server...
  3. 3163:C 05 May 14:59:13.872 # Redis is starting
  4. 3163:C 05 May 14:59:13.872 # Redis version=4.0.14, bits=64, commit=00000000, modified=0, pid=3163, just started
  5. 3163:C 05 May 14:59:13.872 # Configuration loaded
  6. [root@localhost redis]# service redisd stop
  7. Stopping ...
  8. Waiting for Redis to shutdown ...
  9. Redis stopped

3、重启虚拟机查看Redis状态

  1. [root@localhost ~]# ps -aux |grep redis
  2. root 987 0.1 0.1 141836 2012 ? Ssl 15:02 0:00 /usr/local/bin/redis-server *:6379
  3. root 2966 0.0 0.0 112712 980 pts/1 S+ 15:04 0:00 grep --color=auto redis

四、解决客户端连接问题

关闭防火墙,或者开放6379端口

  1. firewalld的基本使用
  2. 启动: systemctl start firewalld
  3. 关闭: systemctl stop firewalld
  4. 查看状态: systemctl status firewalld
  5. 开机禁用 systemctl disable firewalld
  6. 开机启用 systemctl enable firewalld

修改redis.conf 配置

  1. 注释掉:# bind 127.0.0.1
  2. 修改保护模式:protected-mode no

五、sentinel哨兵模式

1、基础配置

  1. 192.168.72.129 主服务
  2. 192.168.72.130 从服务
  3. 192.168.72.131 从服务

2、配置主服务 redis.conf

  1. requirepass 123456
  2. masterauth 123456

3、配置从服务 redis.conf

  1. requirepass 123456
  2. slaveof 192.168.72.129 6379
  3. masterauth 123456

4、配置sentinel.conf

  1. protected-mode no
  2. # sentinel monitor代表监控
  3. # mymaster代表服务器的名称,可以自定义,
  4. # 192.168.72.129代表监控的主服务器,6379代表端口,
  5. # 2 标识 >=2 哨兵认为主服务器不可用,执行failover操作。
  6. sentinel monitor mymaster 192.168.72.129 6379 2
  7. sentinel auth-pass mymaster 123456

5、启动服务

先主服务,后从服务

  1. [root@localhost src]# ./redis-server ../redis.conf
  2. [root@localhost src]# ./redis-sentinel ../sentinel.conf

没错,就是这样搭建完毕了!