Redis群集

Redis群集

部署安装Redis

上传redis程序包
[root@centos01 ~]# rz

[root@centos01 ~]# ls
anaconda-ks.cfg initial-setup-ks.cfg redis-3.2.9.tar.gz

解压缩Redis程序包到/usr/src目录
[root@centos01 ~]# tar zxvf redis-3.2.9.tar.gz -C /usr/src/

进入/usr/src/目录,将软件包程序剪切到redis目录
[root@centos01 ~]# cd /usr/src/
[root@centos01 src]# ls
debug kernels redis-3.2.9
[root@centos01 src]# mv redis-3.2.9/ redis
[root@centos01 src]# ls
debug kernels redis

编辑安装redis
[root@centos01 redis]# make && make install

初始化redis
[root@centos01 redis]# cd utils/
[root@centos01 utils]# ./install_server.sh

修改redis自主配置文件启动群集功能
[root@centos01 utils]# vi /etc/redis/6379.conf
62 bind 192.168.100.10
85 port 6379
129 daemonize yes
164 logfile /var/log/redis_6379.log
722 cluster-enabled yes
730 cluster-config-file nodes-6379.conf
736 cluster-node-timeout 15000
813 cluster-require-full-coverage no

启动redis服务,并查看6379和16379端口是否正常启动
[root@centos01 ~]# netstat -anptu | grep redis
tcp 0 0 192.168.100.10:6379 0.0.0.0:* LISTEN 4668/redis-server 1
tcp 0 0 192.168.100.10:16379 0.0.0.0:* LISTEN 4668/redis-server 1

挂载操作光盘,
[root@centos01 ~]# mount /dev/cdrom /mnt
mount: /dev/sr0 写保护,将以只读方式挂载

安装群集所需依赖程序
[root@centos01 ~]# yum -y install ruby rubygems

上传准备好的gem软件包
[root@centos01 ~]# rz
[root@centos01 ~]# ls
anaconda-ks.cfg redis-3.2.0.gem
initial-setup-ks.cfg redis-3.2.9.tar.gz

安装gem工具
[root@centos01 ~]# gem install redis --version 3.2.0

将redis程序包远程复制到192.168.100.20、30、40、50/60服务器的根目录
[root@centos01 ~]# scp redis-3.2.9.tar.gz root@192.168.100.20:/root
[root@centos01 ~]# scp redis-3.2.9.tar.gz root@192.168.100.30:/root
[root@centos01 ~]# scp redis-3.2.9.tar.gz root@192.168.100.40:/root
[root@centos01 ~]# scp redis-3.2.9.tar.gz root@192.168.100.50:/root
[root@centos01 ~]# scp redis-3.2.9.tar.gz root@192.168.100.60:/root

部署第二台redis服务器
挂载系统光盘
[root@centos02 ~]# mount /dev/cdrom /mnt
mount: /dev/sr0 写保护,将以只读方式挂载

安装redis群集依赖程序
[root@centos02 ~]# yum -y install ruby rubygems

解压缩redis程序包,剪切到/usr/src/redis/src/redis-trib.rb/目录
[root@centos02 ~]# tar zxvf redis-3.2.9.tar.gz -C /usr/src/
[root@centos02 src]# mv redis-3.2.9/ redis
[root@centos02 src]# ls
debug kernels redis

进入redis目录,编辑安装redis
[root@centos02 src]# cd redis/
[root@centos02 redis]# make && make install

初始化redis
[root@centos02 redis]# cd utils/
[root@centos02 utils]# ./install_server.sh

依次部署6台redis服务器

在第一台redis服务器上将redis主配置文件远程复制到剩下5台服务器上
[root@centos01 ~]# scp /etc/redis/6379.conf root@192.168.100.20:/etc/redis/
[root@centos01 ~]# scp /etc/redis/6379.conf root@192.168.100.30:/etc/redis/
[root@centos01 ~]# scp /etc/redis/6379.conf root@192.168.100.40:/etc/redis/
[root@centos01 ~]# scp /etc/redis/6379.conf root@192.168.100.50:/etc/redis/
[root@centos01 ~]# scp /etc/redis/6379.conf root@192.168.100.60:/etc/redis/

第二台redis服务器修改主配置文件监听的IP地址
[root@centos02 ~]# vim /etc/redis/6379.conf
bind 192.168.100.20

依次修改6台

启动redis服务,监听redis服务是否正常启动
[root@centos02 ~]# redis-server /etc/redis/6379.conf

[root@centos02 ~]# netstat -anptu | grep redis
tcp 0 0 192.168.100.20:6379 0.0.0.0:* LISTEN 43094/redis-server
tcp 0 0 192.168.100.20:16379 0.0.0.0:* LISTEN 43094/redis-server

[root@centos03 ~]# netstat -anptu | grep redis
tcp 0 0 192.168.100.30:6379 0.0.0.0:* LISTEN 43087/redis-server
tcp 0 0 192.168.100.30:16379 0.0.0.0:* LISTEN 43087/redis-server

[root@centos04 ~]# netstat -anptu | grep redis
tcp 0 0 192.168.100.40:6379 0.0.0.0:* LISTEN 5176/redis-server 1
tcp 0 0 192.168.100.40:16379 0.0.0.0:* LISTEN 5176/redis-server 1

[root@centos05 utils]# netstat -anptu | grep redis
tcp 0 0 192.168.100.50:6379 0.0.0.0:* LISTEN 43084/redis-server
tcp 0 0 192.168.100.50:16379 0.0.0.0:* LISTEN 43084/redis-server

[root@centos06 utils]# netstat -anptu | grep redis
tcp 0 0 192.168.100.60:6379 0.0.0.0:* LISTEN 4929/redis-server 1
tcp 0 0 192.168.100.60:16379 0.0.0.0:* LISTEN 4929/redis-server 1

使用脚本创建群集
在第一台redis服务器上使用脚本创建群集
[root@centos01 ~]# /usr/src/redis/src/redis-trib.rb create --replicas 1 192.168.100.10:6379 192.168.100.20:6379 192.168.100.30:6379 192.168.100.40:6379 192.168.100.50:6379 192.168.100.60:6379

Creating cluster
Performing hash slots allocation on 6 nodes…
Using 3 masters:
192.168.100.10:6379
192.168.100.20:6379
192.168.100.30:6379
Adding replica 192.168.100.40:6379 to 192.168.100.10:6379
Adding replica 192.168.100.50:6379 to 192.168.100.20:6379
Adding replica 192.168.100.60:6379 to 192.168.100.30:6379
M: 53a7082afe52d1216a447bd505f1828e8c04c7b6 192.168.100.10:6379
slots:0-5460 (5461 slots) master
M: 7023c518c9bde44e137db167abcaf3ef6302ef5c 192.168.100.20:6379
slots:5461-10922 (5462 slots) master
M: 82196443876dd7a7dba2cbda237064577e6996e5 192.168.100.30:6379
slots:10923-16383 (5461 slots) master
S: b86a7228dc45da696a9e95f6593cf28e9d350643 192.168.100.40:6379
replicates 53a7082afe52d1216a447bd505f1828e8c04c7b6
S: 2ef78b8d7e4174c7cb8ff6c9c7834e8e0e97e6fc 192.168.100.50:6379
replicates 7023c518c9bde44e137db167abcaf3ef6302ef5c
S: 161c231d36b342103ff1524d027e131e66da06ef 192.168.100.60:6379
replicates 82196443876dd7a7dba2cbda237064577e6996e5
Can I set the above configuration? (type ‘yes’ to accept): yes

Nodes configuration updated
Assign a different config epoch to each node
Sending CLUSTER MEET messages to join the cluster
Waiting for the cluster to join…

Performing Cluster Check (using node 192.168.100.10:6379)
M: 53a7082afe52d1216a447bd505f1828e8c04c7b6 192.168.100.10:6379
slots:0-5460 (5461 slots) master
1 additional replica(s)
M: 7023c518c9bde44e137db167abcaf3ef6302ef5c 192.168.100.20:6379
slots:5461-10922 (5462 slots) master
1 additional replica(s)
S: b86a7228dc45da696a9e95f6593cf28e9d350643 192.168.100.40:6379
slots: (0 slots) slave
replicates 53a7082afe52d1216a447bd505f1828e8c04c7b6
M: 82196443876dd7a7dba2cbda237064577e6996e5 192.168.100.30:6379
slots:10923-16383 (5461 slots) master
1 additional replica(s)
S: 161c231d36b342103ff1524d027e131e66da06ef 192.168.100.60:6379
slots: (0 slots) slave
replicates 82196443876dd7a7dba2cbda237064577e6996e5
S: 2ef78b8d7e4174c7cb8ff6c9c7834e8e0e97e6fc 192.168.100.50:6379
slots: (0 slots) slave
replicates 7023c518c9bde44e137db167abcaf3ef6302ef5c
[OK] All nodes agree about slots configuration.

Check for open slots…
Check slots coverage…
[OK] All 16384 slots covered.

查看群集状态
[root@centos01 ~]# cd /usr/src/redis/src/
[root@centos01 src]# ./redis-trib.rb check 192.168.100.10:6379

测试群集

[root@centos01 ~]# redis-cli -h 192.168.100.10 -p 6379 -c
192.168.100.10:6379> set centos 7
OK
192.168.100.10:6379> get centos
“7”
192.168.100.10:6379> quit

[root@centos01 ~]# redis-cli -h 192.168.100.40 -p 6379 -c
192.168.100.40:6379> get centos
-> Redirected to slot [467] located at 192.168.100.10:6379
“7”
192.168.100.10:6379> quit

[root@centos01 ~]# redis-cli -h 192.168.100.60 -p 6379 -c
192.168.100.60:6379> get centos
-> Redirected to slot [467] located at 192.168.100.10:6379
“7”
192.168.100.10:6379> quit

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值