靳闯博客 记录是一种习惯 、分享是一种态度
  • 波浪
  • 波浪
  • 波浪
  • 波浪
Centos7 Redis6.0.6版本集群搭建
发表于: | 分类: 技术积累 | 标签: Linux Centos7 Redis

当前最新稳定版本是redis 6.0.6,所以就用这个版本搭建redis集群

使用3台机器,每台机器2个节点
系统centos7
每个机器之间互通
192.168.10.1 代表第一台机器ip
192.168.10.2 代表第二台机器ip
192.168.10.3 代表第三台机器ip


升级gcc [3台都执行]

# 安装ruby
yum install ruby rubygems -y

# 升级gcc(数字7表示7.x版本,8表示8.x版本)
yum install centos-release-scl devtoolset-7-gcc* -y

# 临时生效gcc版本
scl enable devtoolset-7 bash

# 永久生效gcc版本
echo 'source /opt/rh/devtoolset-7/enable' >>/etc/profile && source /etc/profile

下载安装redis [3台都执行]

wget http://download.redis.io/releases/redis-6.0.6.tar.gz
tar xf redis-6.0.6.tar.gz
cd redis-6.0.6
make
make install PREFIX=/usr/local/redis
echo 'export PATH=$PATH:/usr/local/redis/bin' >>/etc/profile && source /etc/profile

创建目录和配置文件

# 第一台
mkdir -p /opt/redis-cluster/{7001,7002} 
# 第二台
mkdir -p /opt/redis-cluster/{7003,7004} 
# 第三台
mkdir -p /opt/redis-cluster/{7005,7006} 

# 配置文件模板以7001节点为例(这里绑定本机ip和127.0.0.1),复制到其他节点目录下并改下ip和端口还有文件名称
cd /opt/redis-cluster/7001/
vim redis7001.conf

# 配置内容
bind 192.168.10.1 127.0.0.1
port 7001
daemonize yes
cluster-enabled yes
cluster-config-file nodes7001.conf
cluster-node-timeout 5000
cluster-require-full-coverage no

#aof
appendonly yes
appendfsync everysec
appendfilename "appendonly_7001.aof"
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
no-appendfsync-on-rewrite yes

#rdb
save 900 1
save 300 10
save 60 10000
dbfilename node7001.rdb
rdbcompression yes
rdbchecksum yes
stop-writes-on-bgsave-error no
dir /opt/redis-cluster/7001/

pidfile /var/run/redis_7001.pid
logfile /var/log/redis_7001.log

启动各个节点

# 启动redis各节点
# 第一台
/usr/local/redis/bin/redis-server /opt/redis-cluster/7001/redis7001.conf
/usr/local/redis/bin/redis-server /opt/redis-cluster/7002/redis7002.conf
# 第一台
/usr/local/redis/bin/redis-server /opt/redis-cluster/7003/redis7003.conf
/usr/local/redis/bin/redis-server /opt/redis-cluster/7004/redis7004.conf
# 第一台
/usr/local/redis/bin/redis-server /opt/redis-cluster/7005/redis7005.conf
/usr/local/redis/bin/redis-server /opt/redis-cluster/7006/redis7006.conf

创建集群,任意一台执行即可

redis-cli --cluster create 192.168.10.1:7001 192.168.10.1:7002 192.168.10.2:7003 192.168.10.2:7004 192.168.10.3:7005 192.168.10.3:7006 --cluster-replicas 1

查看集群状态信息

#例如当前节点端口为7001和7002的
redis-cli -c -p 7001
#连接其他节点用
redis-cli -c -h ip地址 -p 端口号

# 查看集群信息
127.0.0.1:7001> CLUSTER info
cluster_state:ok
cluster_slots_assigned:16384
cluster_slots_ok:16384
cluster_slots_pfail:0
cluster_slots_fail:0
cluster_known_nodes:6
cluster_size:3
cluster_current_epoch:6
cluster_my_epoch:1
cluster_stats_messages_ping_sent:1328
cluster_stats_messages_pong_sent:1318
cluster_stats_messages_sent:2646
cluster_stats_messages_ping_received:1313
cluster_stats_messages_pong_received:1328
cluster_stats_messages_meet_received:5
cluster_stats_messages_received:2646

# 查看节点信息
127.0.0.1:7001> CLUSTER nodes
4cc528ff35eadeb795af874fefc0009e555774d6 192.168.10.3:7006@17006 slave db2ae554b712331f12e728fc7d246c89fa79a78d 0 1618554198477 3 connected
f202aff7ae33e68a6d331b34b5c32ca71d91e8f3 192.168.10.1:7001@17001 myself,master - 0 1618554197000 1 connected 0-5460
c528e42056573406479b0af5f5b089ec990836a5 192.168.10.1:7002@17002 slave 2e3f01f01627f0249c9bc5a5e6808c8805ffd40b 0 1618554197473 5 connected
2e3f01f01627f0249c9bc5a5e6808c8805ffd40b 192.168.10.3:7005@17005 master - 0 1618554198576 5 connected 10923-16383
dbecff7305a5ad51f42052548253f73419b714dc 192.168.10.2:7004@17004 slave f202aff7ae33e68a6d331b34b5c32ca71d91e8f3 0 1618554199480 1 connected
db2ae554b712331f12e728fc7d246c89fa79a78d 192.168.10.2:7003@17003 master - 0 1618554198978 3 connected 5461-10922
127.0.0.1:7001> 

存取key测试

re6.png


商业转载请联系作者获得授权,非商业转载请注明出处 本文地址:https://me.jinchuang.org/archives/1104.html

如果这篇文章帮助到了你,我感到十分荣幸!


📬 评论留言 ↴

icon_mrgreen.pngicon_neutral.pngicon_twisted.pngicon_arrow.pngicon_eek.pngicon_smile.pngicon_confused.pngicon_cool.pngicon_evil.pngicon_biggrin.pngicon_idea.pngicon_redface.pngicon_razz.pngicon_rolleyes.pngicon_wink.pngicon_cry.pngicon_surprised.pngicon_lol.pngicon_mad.pngicon_sad.pngicon_exclaim.pngicon_question.png2018new_aini_org.png2018new_baobao_thumb.png2018new_erha_org.png2018new_kuxiao_thumb.png2018new_yun_thumb.png2018new_hufen_thumb.png2018new_gui_org.png2018new_xiaoerbuyu_org.png2018new_heixian_thumb.png2018new_wabi_thumb.png2018new_tianping_thumb.png

TOP