CentOS7.6搭建redis4.0.1 cluster集群
1. 操作系统信息:
$ uname -a
Linux iZbp11d57wmumnwuihb2czZ 3.10.-957.5..el7.x86_64 # SMP Fri Feb :: UTC x86_64 x86_64 x86_64 GNU/Linux
$ cat /proc/version
Linux version 3.10.-957.5..el7.x86_64 (mockbuild@kbuilder.bsys.centos.org) (gcc version 4.8. (Red Hat 4.8.-) (GCC) ) # SMP Fri Feb :: UTC
$ cat /etc/redhat-release
CentOS Linux release 7.6. (Core)
三台ECS机器:172.16.214.160, 172.16.214.161, 172.16.214.163
2. 安裝 GCC 编译工具
$ yum install -y gcc g++ gcc-c++ make
升级所有的包,防止出现版本过久不兼容问题
$ yum -y update
关闭防火墙 节点之前需要开放指定端口
systemctl stop firewalld.service
3.1. 安装redis,下载,解压,编译安装
cd /opt
$ wget http://download.redis.io/releases/redis-4.0.1.tar.gz
$ tar xzf redis-4.0..tar.gz
$ cd redis-4.0.
$ make
如果因为上次编译失败,有残留的文件
$ make distclean
172.16.214.160机器上创建redis目录
$ mkdir /opt/redis-4.0./redis-cluster
$ cd /opt/redis-4.0./redis-cluster
$ mkdir
172.16.214.161机器上创建redis目录
$ mkdir /opt/redis-4.0./redis-cluster
$ cd /opt/redis-4.0./redis-cluster
$ mkdir
172.16.214.163机器上创建redis目录
$ mkdir /opt/redis-4.0./redis-cluster
$ cd /opt/redis-4.0./redis-cluster
$ mkdir
每个目录下创建一个redis.conf文件,内容如下(不同的端口和ip需要设置做修改)
#端口号
port #默认ip为127.0.0.,需要改为其他节点机器可访问的ip,否则创建集群时无法访问对应的端口,无法创建集群
bind 172.16.214.160 #redis后台运行
daemonize yes
#访问密码
masterauth passwd123
requirepass passwd123
#pidfile文件
pidfile /var/run/redis_7000.pid #开启集群
cluster-enabled yes #集群的配置,配置文件首次启动自动生成
cluster-config-file nodes_7000.conf #请求超时,默认15秒,可自行设置
cluster-node-timeout #aof日志开启,有需要就开启,它会每次写操作都记录一条日志
appendonly yes
安装ruby (只需要在其中一台上安装)
$ yum -y install ruby ruby-devel rubygems rpm-build
$ gem install redis
Fetching: redis-4.1.0.gem (100%)
ERROR: Error installing redis:
redis requires Ruby version >= 2.2.2.
这一步有可能会出错,原因是ruby版本太低,解决办法安装高版本ruby
$ yum install curl
$ gpg2 --keyserver hkp://pool.sks-keyservers.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
$ curl -L get.rvm.io | bash -s stable
$ find / -name rvm -print
/usr/local/rvm
/usr/local/rvm/bin/rvm
/usr/local/rvm/scripts/rvm
/usr/local/rvm/lib/rvm
/usr/local/rvm/src/rvm
/usr/local/rvm/src/rvm/bin/rvm
/usr/local/rvm/src/rvm/scripts/rvm
/usr/local/rvm/src/rvm/lib/rvm
$ source /usr/local/rvm/scripts/rvm
$ rvm list known
$ rvm install 2.3.
$ rvm use 2.3.
$ rvm use 2.3. --default
$ ruby --version
$ rvm remove 2.0.
$ gem install redis
设置ruby访问的密码
$ cd /usr/local/rvm/gems/ruby-2.3./gems/redis-4.1./lib/redis/ $ vim client.rb
将“:password”后的内容设置为你的密码, 保存退出
3.2 创建用户并设置密码,并切换到该用户身份, 修改redis目录所有权
$ useradd admin $ passwd admin
$ chown -R admin:admin /opt/redis-4.0.1
$ su admin
4. 为了安全,用admin用户身份启动集群
#第一台机器上执行 3个节点
$ for((i=0;i<=2;i++)); do /opt/redis-4.0.1/src/redis-server /opt/redis-4.0.1/redis-cluster/700$i/redis.conf; done #第二台机器上执行 3个节点
$ for((i=3;i<=5;i++)); do /opt/redis-4.0.1/src/redis-server /opt/redis-4.0.1/redis-cluster/700$i/redis.conf; done #第三台机器上执行 3个节点
$ for((i=6;i<=8;i++)); do /opt/redis-4.0.1/src/redis-server /opt/redis-4.0.1/redis-cluster/700$i/redis.conf; done
检查各 Redis 各个节点启动情况
$ ps -ef | grep redis //redis是否启动成功
$ netstat -tnlp | grep redis //监听redis端口
创建集群
$ /opt/redis-4.0./src/redis-trib.rb create --replicas 172.16.214.160: 172.16.214.160: 172.16.214.160: 172.16.214.161: 172.16.214.161: 172.16.214.161: 172.16.214.163: 172.16.214.163: 172.16.214.163:7008
>>> Creating cluster
>>> Performing hash slots allocation on 9 nodes...
Using 4 masters:
172.16.214.160:7000
172.16.214.161:7003
172.16.214.163:7006
172.16.214.160:7001
Adding replica 172.16.214.161:7004 to 172.16.214.160:7000
Adding replica 172.16.214.163:7007 to 172.16.214.161:7003
Adding replica 172.16.214.160:7002 to 172.16.214.163:7006
Adding replica 172.16.214.161:7005 to 172.16.214.160:7001
Adding replica 172.16.214.163:7008 to 172.16.214.160:7000
M: 7c622ac191edd40dd61d9b79b27f6f69d02a5bbf 172.16.214.160:7000
slots:0-4095 (4096 slots) master
M: 44c81c15b01d992cb9ede4ad35477ec853d70723 172.16.214.160:7001
slots:12288-16383 (4096 slots) master
S: 38f03c27af39723e1828eb62d1775c4b6e2c3638 172.16.214.160:7002
replicates f1abb62a8c9b448ea14db421bdfe3f1d8075189c
M: 987965baf505a9aa43e50e46c76189c51a8f17ec 172.16.214.161:7003
slots:4096-8191 (4096 slots) master
S: 6555292fed9c5d52fcf5b983c441aff6f96923d5 172.16.214.161:7004
replicates 7c622ac191edd40dd61d9b79b27f6f69d02a5bbf
S: 2b5ba254a0405d4efde4c459867b15176f79244a 172.16.214.161:7005
replicates 44c81c15b01d992cb9ede4ad35477ec853d70723
M: f1abb62a8c9b448ea14db421bdfe3f1d8075189c 172.16.214.163:7006
slots:8192-12287 (4096 slots) master
S: eb4067373d36d8a8df07951f92794e67a6aac022 172.16.214.163:7007
replicates 987965baf505a9aa43e50e46c76189c51a8f17ec
S: 2919e041dd3d1daf176d6800dcd262f4e727f366 172.16.214.163:7008
replicates 7c622ac191edd40dd61d9b79b27f6f69d02a5bbf
Can I set the above configuration? (type 'yes' to accept): yes
输入yes,然后回车
如何关闭集群:
$ pkill redis
或者逐个关闭
$ for((i=;i<=;i++)); do /opt/redis-4.0./src/redis-cli -c -h 172.16.214.160 -p $i -a passwd123 shutdown; done $ for((i=;i<=;i++)); do /opt/redis-4.0./src/redis-cli -c -h 172.16.214.161 -p $i -a passwd123 shutdown; done $ for((i=;i<=;i++)); do /opt/redis-4.0./src/redis-cli -c -h 172.16.214.163 -p $i -a passwd123 shutdown; done
5.集群验证
参数 -C 可连接到集群,因为 redis.conf 将 bind 改为了ip地址,所以 -h 参数不可以省略,-p 参数为端口号
$ /opt/redis-4.0./src/redis-cli -h 172.16.214.160 -c -p 7000 -a passwd123
172.16.214.160:> set name justfortest
-> Redirected to slot [] located at 172.16.214.161:
OK
172.16.214.161:> get name
"justfortest"
172.16.214.161:>
发现redis get name 重定向,说明集群已经是可用。
检查集群状态
$ /opt/redis-4.0./src/redis-trib.rb check 172.16.214.160:
>>> Performing Cluster Check (using node 172.16.214.160:)
M: 8a78f3b5c1694caecfe9404f131234328481136f 172.16.214.160:
slots:- ( slots) master
additional replica(s)
M: d4f15c233b82ec71997f72bb9c04a4fb1f44eea8 172.16.214.161:
slots:- ( slots) master
additional replica(s)
M: 729f02e82887746b85d709e36f9b07148e6af442 172.16.214.163:
slots:- ( slots) master
additional replica(s)
S: 33a6c6f63ad565e6a9bc76712956d2cbc9819b93 172.16.214.160:
slots: ( slots) slave
replicates 729f02e82887746b85d709e36f9b07148e6af442
S: 0860ba2d9cadd23757b2052fe653857fd64e4363 172.16.214.163:
slots: ( slots) slave
replicates 8a78f3b5c1694caecfe9404f131234328481136f
S: e5c21b38ed2b6b4870df5f8438259dde0687b363 172.16.214.161:
slots: ( slots) slave
replicates 1ec686b61ce3b8a1161382503c62748fc1985553
M: 1ec686b61ce3b8a1161382503c62748fc1985553 172.16.214.160:
slots:- ( slots) master
additional replica(s)
S: 37cf628f031d47fc80dd02247d555eb6ab179686 172.16.214.161:
slots: ( slots) slave
replicates 8a78f3b5c1694caecfe9404f131234328481136f
S: b586d779805f2f75784bb526ae205cd672534b7a 172.16.214.163:
slots: ( slots) slave
replicates d4f15c233b82ec71997f72bb9c04a4fb1f44eea8
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All slots covered.
列出集群节点
$ /opt/redis-4.0./src/redis-cli -h 172.16.214.160 -c -p 7000 -a passwd123
172.16.214.160:> cluster nodes
d4f15c233b82ec71997f72bb9c04a4fb1f44eea8 172.16.214.161:@ master - connected -
729f02e82887746b85d709e36f9b07148e6af442 172.16.214.163:@ master - connected -
33a6c6f63ad565e6a9bc76712956d2cbc9819b93 172.16.214.160:@ slave 729f02e82887746b85d709e36f9b07148e6af442 connected
0860ba2d9cadd23757b2052fe653857fd64e4363 172.16.214.163:@ slave 8a78f3b5c1694caecfe9404f131234328481136f connected
e5c21b38ed2b6b4870df5f8438259dde0687b363 172.16.214.161:@ slave 1ec686b61ce3b8a1161382503c62748fc1985553 connected
1ec686b61ce3b8a1161382503c62748fc1985553 172.16.214.160:@ master - connected -
37cf628f031d47fc80dd02247d555eb6ab179686 172.16.214.161:@ slave 8a78f3b5c1694caecfe9404f131234328481136f connected
b586d779805f2f75784bb526ae205cd672534b7a 172.16.214.163:@ slave d4f15c233b82ec71997f72bb9c04a4fb1f44eea8 connected
8a78f3b5c1694caecfe9404f131234328481136f 172.16.214.160:@ myself,master - connected -
打印集群信息
$ 172.16.214.160:> cluster info
cluster_state:ok
cluster_slots_assigned:
cluster_slots_ok:
cluster_slots_pfail:
cluster_slots_fail:
cluster_known_nodes:
cluster_size:
cluster_current_epoch:
cluster_my_epoch:
cluster_stats_messages_ping_sent:
cluster_stats_messages_pong_sent:
cluster_stats_messages_sent:
cluster_stats_messages_ping_received:
cluster_stats_messages_pong_received:
cluster_stats_messages_meet_received:
cluster_stats_messages_publish_received:
cluster_stats_messages_received:
6. 为了安全,最后可以设置admin用户身份不能远程登录
chsh admin -s /sbin/nologin
CentOS7.6搭建redis4.0.1 cluster集群的更多相关文章
- CentOs7.3 搭建 Redis-4.0.1 Cluster 集群服务
环境 VMware版本号:12.0.0 CentOS版本:CentOS 7.3.1611 三台虚拟机(IP):192.168.252.101,192.168.102..102,192.168.252. ...
- (转)CentOs7.3 搭建 RabbitMQ 3.6 Cluster 集群服务与使用
RabbitMQ是一个开源的AMQP实现,服务器端用Erlang语言编写,支持多种客户端,如:Python.Ruby..NET.Java.JMS.C.PHP.ActionScript.XMPP.STO ...
- Redis5.0.8 Cluster集群部署
目录 一.Redis Cluster简介 二.部署 三.创建主库 一.Redis Cluster简介 Redis Cluster集群是一种去中心化的高可用服务,其内置的sentinel功能可以提供高可 ...
- Redis(二)CentOS7安装Redis4.0.10与集群搭建
一 Redis单机安装 1 Redis下载安装 1.1 检查依赖环境(Redis是C语言开发,编译依赖gcc环境) [root@node21 redis-]$ gcc -v -bash: gcc: c ...
- Spark(二)CentOS7.5搭建Spark2.3.1分布式集群
一 下载安装包 1 官方下载 官方下载地址:http://spark.apache.org/downloads.html 2 安装前提 Java8 安装成功 zookeeper 安 ...
- Redis3.0.7 cluster/集群 安装配置教程
1.前言 环境:CentOS-6.7-i386-LiveDVD 安装的CentOs系统 节点: 6个节点,3个主节点.3个从节点(由于redis默认需要3个主节点,如果想每个主节点有一个从节点,这是最 ...
- CentOS7.4搭建kafka单结点和集群
操作系统选择 CentOS7.4x86-64(操作系统的x86_64是跟CPU有关的,最早AMD公司开发出了一款向下兼容x86CPU,向上又扩充了指令集,具有了64位CPU的特性,这款CPU后来改名为 ...
- Linux Centos7 环境搭建Docker部署Zookeeper分布式集群服务实战
Zookeeper完全分布式集群服务 准备好3台服务器: [x]A-> centos-helios:192.168.19.1 [x]B-> centos-hestia:192.168.19 ...
- Flink(二)CentOS7.5搭建Flink1.6.1分布式集群
一. Flink的下载 安装包下载地址:http://flink.apache.org/downloads.html ,选择对应Hadoop的Flink版本下载 [admin@node21 soft ...
随机推荐
- Vue 2.6版本基础知识概要(一)
挂载组件 //将 App组件挂载到div#app节点里 new Vue({ render: h => h(App), }).$mount('#app') VueComponent.$mount ...
- 身份认证功能chiro的使用
package com.cun;import org.apache.shiro.SecurityUtils;import org.apache.shiro.authc.*;import org.apa ...
- 软件工程作业 - word count
(编程和软件工程作业系列) 实践最简单的项目:WC 实践是理论的基础和验证标准,希望读者贯彻“做中学”的思想,动手实现下面的项目,并和别人的成绩相比较,分析产生差距的原因. 1. 实现一个简单而完整的 ...
- SpringMVC 实现文件上传与下载,并配置异常页面
目录 上传文件的表单要求 Spring MVC实现上传文件 需要导入的jar包 配置MultipartResolver解析器 编写接收上传文件的控制器 Spring MVC实现文件下载 下载文件时的h ...
- 基于 docker 的redis 主从+哨兵(快速部署)
很简单(字多的步骤见:http://www.cnblogs.com/vipzhou/p/8580495.html) 1.直接启动3个容器 docker network create --subnet ...
- Linux centos ansible
创建m01.backup.nfs.web01.web02 m01(172.16.1.61).backup(172.16.1.41).nfs(172.16.1.31).web01(172.16.1.7) ...
- Tomcat不需要输入项目名便可访问项目(直接用域名或者ip)
一般需要输入项目名访问项目是怎么个方法呢? 直接将项目放在 tomcat 安装目录的 webapps 目录下, 然后在域名或者ip后面 域名(ip)/项目目录, 这样会显得比较麻烦. 那么应该怎么才可 ...
- 【python 字符串】 字符串的相关方法(三)
# 将字符串中的每个元素,按照指定分隔符进行拼接 # 空格 .# ._ 等等 不能是反斜杠 test = '你是风儿我是沙' ret = '#'.join(test) print(ret) 你#是#风 ...
- xml 解析参考文档
https://www.cnblogs.com/a1656344531/archive/2012/11/28/2792863.html
- SpringBoot之常用注解
在spring boot中,摒弃了spring以往项目中大量繁琐的配置,遵循约定大于配置的原则,通过自身默认配置,极大的降低了项目搭建的复杂度.同样在spring boot中,大量注解的使用,使得代码 ...