Rediss 部署以及哨兵模式

Rediss 部署以及哨兵模式

Redis 安装配置

Yum 官方源里没有 redis,所以采用手动源码安装

1、 上传 redis 安装包到 Linux 任意目录下,解压

wget http://download.redis.io/releases/redis-5.0.7.tar.gz
tar xvf redis-5.0.7.tar.gz

2、 安装 gcc(redis 安装依赖 C 语言环境,需要先安装 gcc)

yum install -y gcc

3、 进入解压后的 redis 目录下,执行编译操作

make MALLOC=libc

4、 执行安装命令

`make install`

5、 安装成功

Redis 配置

1、 在 redis 目录下,新建 conf 文件夹,将 redis.conf 配置文件拷贝到 conf 文件夹下,并重
命名为 6379.conf

mkdir conf
cp redis.conf ./conf/6379.conf

2、 修改 redis.conf 配置文件

daemonize 改为 yes
dbfilename 改为 dump_6379.rdb
将 bind 127.0.0.1 注释掉
protected-mode 改为 no

Redis启动与关闭

1、 先启动 server,在 conf 目录下,执行

cd redis-5.0.7/src
redis-server ../conf/6379.conf

2、 使用客户端登录 redis,默认连接的是 6379 端口的 redis 实例

redis-cli

3、关闭 redis-server

redis-cli shutdown

开启外网连接权限(0.0.0.0表示接受任意外网连接)

# By default Redis listens for connections from all the network interfaces
# available on the server. It is possible to listen to just one or multiple
# interfaces using the "bind" configuration directive, followed by one or
# more IP addresses.
#
# Examples:
#
# bind 192.168.1.100 10.0.0.1
bind 0.0.0.0

指定端口号

# Accept connections on the specified port, default is 6379.
# If port 0 is specified Redis will not listen on a TCP socket.
port 6379

开启slave节点写权限

# Note: read only slaves are not designed to be exposed to untrusted clients
# on the internet. It's just a protection layer against misuse of the instance.
# Still a read only slave exports by default all the administrative commands
# such as CONFIG, DEBUG, and so forth. To a limited extent you can improve
# security of read only slaves using 'rename-command' to shadow all the
# administrative / dangerous commands.
slave-read-only no

最后在文件末尾添加如下配置,表示当服务后台启动时,自动将某台服务器作为master,在这里我的master是175,端口号是6380

slaveof 192.168.2.47 6379

第二步:配置sentinel.conf文件(如果没有此文件,在redis文件夹下touch一个即可)

cp  sentinel.conf ./conf/sentinel.conf

首先,开启哨兵后台运行权限

#Control the switch running in the background
daemonize yes

重点来了!下面是配置哨兵监控模式(重中之重)

# Note: master name should not include special characters or spaces.
# The valid charset is A-z 0-9 and the three characters ".-_".
sentinel monitor mymaster 192.168.2.47 6379 1

哨兵开启故障转移阈值(当其余某台节点中的一台有1票时,开启选举,使其为master,否则一直处于选举状态)

然后,使用scp指令将redis整个文件夹拷贝到其他一台节点上,需要改变的地方有

redis.conf中的端口号
将主服务器中的redis.conf文件末尾的slaveof 192.168.2.47 6380去掉

所有的配置完成之后,使用如下命令再三台服务器上分别开启redis服务(注意顺序:先主、后从)

redis-server ../conf/6379.conf

使用如下命令,开启哨兵监控模式(开启顺序不要紧)

src/redis-sentinel ./conf/sentinel.conf

而后,分别在两台服务器上执行如下命令,开启redis客户端

src/redis-cli -h 当前服务器ip -p redis.conf文件中的端口号

在主服务器上的客户端上执行如下命令,查看master和slaves

info replication
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值