redis-cluster集群部署及测试(超详细)

摘抄

Redis-Cluster采用无中心结构:
所有的redis节点彼此互联(PING-PONG机制),内部使用二进制协议优化传输速度和带宽。
节点的fail是通过集群中超过半数的节点检测失效时才生效。
客户端与redis节点直连,不需要中间代理层.客户端不需要连接集群所有节点,连接集群中任何一个可用节点即可。
工作方式
在redis的每一个节点上,都有这么两个东西,一个是插槽(slot),它的的取值范围是:0-16383。还有一个就是cluster,可以理解为是一个集群管理的插件。当我们的存取的key到达的时候,redis会根据crc16的算法得出一个结果,然后把结果对 16384 求余数,这样每个 key 都会对应一个编号在 0-16383 之间的哈希槽,通过这个值,去找到对应的插槽所对应的节点,然后直接自动跳转到这个对应的节点上进行存取操作。

为了保证高可用,redis-cluster集群引入了主从模式,一个主节点对应一个或者多个从节点,当主节点宕机的时候,就会启用从节点。当其它主节点ping一个主节点A时,如果半数以上的主节点与A通信超时,那么认为主节点A宕机了。如果主节点A和它的从节点A1都宕机了,那么该集群就无法再提供服务了。

服务版本说明

服务 版本号 备注
Redis redis-5.0.5

部署环境

系统环境:centos7.6
服务版本:redis-5.0.5
主机名:yhcs_1、yhcs_2
IP:192.168.43.176、192.168.43.177

下载路径

Redis官网:http://redis.io

安装约定并创建目录

安装包存放目录:/data/software/redis
安装目录:/usr/local/redis
节点目录:/usr/local/redis_cluster
设置节点:7000、7001、7002
[root@yhcs_1 ~]# mkdir -p /data/software/redis
[root@yhcs_1 ~]# mkdir -p /usr/local/redis
[root@yhcs_1 ~]# mkdir -p /usr/local/redis_cluster

上传redis-5.0.5.tar.gz

[root@yhcs_1 ~]# cd /data/software/redis/
[root@yhcs_1 redis]# rz -y
[root@yhcs_1 redis]# ls
redis-5.0.5.tar.gz
[root@yhcs_1 redis]# tar -zxvf redis-5.0.5.tar.gz

编译安装

[root@yhcs_1 redis]# cd redis-5.0.5
[root@yhcs_1 redis]# yum install -y gcc
[root@yhcs_1 redis-5.0.5]# make
报错:zmalloc.h:50:31: fatal error: jemalloc/jemalloc.h: No such file or directory
关于分配器allocator, 如果有MALLOC 这个 环境变量, 会有用这个环境变量的 去建立Redis。而且libc 并不是默认的 分配器, 默认的是 jemalloc, 因为 jemalloc 被证明 有更少的 fragmentation problems 比libc。但是如果你又没有jemalloc 而只有 libc 当然 make 出错。 所以加这么一个参数
[root@yhcs_1 redis-5.0.5]# make MALLOC=libc
[root@yhcs_1 redis-5.0.5]# cd src
[root@yhcs_1 src]# make test
You need tcl 8.5 or newer in order to run the Redis test
make: *** [test] Error 1
[root@yhcs_1 src]# yum install -y tcl
[root@yhcs_1 src]# make test
测试make test 成功!
#redis在这一步才指定安装路径
[root@yhcs_1 src]# make install PREFIX=/usr/local/redis
#安装完成后查看安装目录
[root@yhcs_1 src]# cd /usr/local/redis
[root@yhcs_1 redis]# ll
total 0
drwxr-xr-x. 2 root root 134 Oct 17 17:09 bin
[root@yhcs_1 redis]# ls -l bin/
total 12980
-rwxr-xr-x. 1 root root 353824 Oct 17 17:09 redis-benchmark #redis性能测试工具启动,测试redis在你的系统及你的配置下的读写性能
-rwxr-xr-x. 1 root root 4045352 Oct 17 17:09 redis-check-aof #更新aof日志检查
-rwxr-xr-x. 1 root root 4045352 Oct 17 17:09 redis-check-rdb #本地数据库检查
-rwxr-xr-x. 1 root root 794384 Oct 17 17:09 redis-cli #命令行操作工具(即客户端)
lrwxrwxrwx. 1 root root 12 Oct 17 17:09 redis-sentinel -> redis-server
-rwxr-xr-x. 1 root root 4045352 Oct 17 17:09 redis-server #redis服务器的daemon启动程序

配置环境变量

[root@yhcs_1 redis]# echo ‘export PATH=$PATH:/usr/local/redis/bin’ >> /etc/profile
[root@yhcs_1 redis]# source /etc/profile
[root@yhcs_1 redis]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/redis/bin

查看redis启动方式

[root@yhcs_1 redis]# redis-server --help
Usage: ./redis-server [/path/to/redis.conf] [options]
./redis-server - (read config from stdin)
./redis-server -v or --version
./redis-server -h or --help
./redis-server --test-memory

Examples: #redis服务器的daemon程序如何启动
./redis-server (run the server with default conf)
./redis-server /etc/redis/6379.conf
./redis-server --port 7777
./redis-server --port 7777 --replicaof 127.0.0.1 8888
./redis-server /etc/myredis.conf --loglevel verbose

Sentinel mode:
./redis-server /etc/sentinel.conf --sentinel

拷贝配置文件

#拷贝安装包目录下的配置文件到安装目录的conf目录下
[root@yhcs_1 redis]# cd /data/software/redis/redis-5.0.5
[root@yhcs_1 redis-5.0.5]# mkdir -p /usr/local/redis/conf
[root@yhcs_1 redis-5.0.5]# cp redis.conf /usr/local/redis/co

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值