1.主从安装
1.1:安装 C 语言需要的 GCC 环境
yum install
-y
gcc-c
++
yum install
-y
wget
1.2:下载并解压缩 Redis 源码压缩包
wget
http://download.redis.io/releases/redis-5.0.4.tar.gz
tar -zxf redis-5.0.4.tar.gz -C /opt/apps/ //把redis解压到指定路径
1.3:编译 Redis 源码,进入 redis-3.2.9 目录,执行编译命令
cd
redis-5.0.4
make
make install PREFIX=/opt/apps/redis6379
cp /opt/apps/redis-5.0.4/redis.conf /opt/apps/redis6379/bin/
1.4.修改redis.config
cd /opt/apps/redis6379/bin/
vim
redis.conf
# 将`daemonize`由`no`改为`yes`
daemonize yes
# 默认绑定的是回环地址,默认不能被其他机器访问
# bind 127.0.0.1
# 是否开启保护模式,由yes该为no
protected-mode no
1.5. :启动服务
./redis-server redis.conf
1.6. 连接此 redis 服务器
./redis-cli
-h
127
.0.0.1
-p
6379
//如果不指定主机和端口也可以
#默认主机地址是127.0.0.1
#默认端口是6379
./redis-cli
1.7.复制从服务器
cd /opt/apps/
cp -r redis6379 redis6380
1.8.修改从服务器的配置文件
vim redis6380/bin/redis.conf
port 6380
replicaof 127.0.0.1 6379
当主挂了,从服务器不能成为master,也不能写文件,只能读数据
1.9. :启动服务
./redis-server redis.conf
2.哨兵模式
2.1 复制一个 哨兵模式
cd /opt/apps
cp -r redis-6379 redis-sentinel6379
cp -r redis-6379 redis-sentinel6380
cp -r redis-6379 redis-sentinel6381
2.2 sentinel配置文件的编写
//从解压的redis中复制出一个sentinel配置文件
cp /opt/tools/redis-5.0.4/sentinel.conf /opt/apps/redis-sentinel6379/bin/
cd /opt/apps/redis-sentinel6379/bin/
vim sentinel.conf
port 26380
// 设置master信息,设置判断客观下线需要的台数 如果3个sentinel 需要两台机器判断
sentinel monitor mymaster 127.0.0.1 6379 2
//设置是否守护线程启动
daemonize yes
2.3 启动sentinel
./redis-cli -h 127 .0.0.1 -p 26379
./redis-cli -h 127 .0.0.1 -p 26380
./redis-cli -h 127 .0.0.1 -p 26381
2.4 查看sentinel信息
//查看sentinel的总体信息
info
//查看sentinel masters的信息
sentinel masters
//查看sentinel slave的信息
sentinel slaves mymaster