redis cluster 4.0.9 之一: make make install

news/2024/11/10 2:04:24

os: centos7.4
redis:4.0.9
ruby:2.3.4

ip 规划

redis1    192.168.56.101
redis2    192.168.56.102

用两台虚拟机模拟6个redis节点。
分别为
192.168.56.101 的 9001、9002、9003 端口,
192.168.56.102 的 9001、9002、9003 端口。

os安装

参考<<centos 7.x 安装 redis 的优化设置>>

使用 rvm 安装 ruby

下载、编译、安装

http://www.redis.cn/download.html
或者直接用wget
wget http://download.redis.io/releases/redis-4.0.9.tar.gz

redis1、redis2 两个节点都需要操作

# mkdir -p /usr/redis
# cd /usr/redis
# wget http://download.redis.io/releases/redis-4.0.9.tar.gz
# tar -zxvf ./redis-4.0.9.tar.gz
# cd redis-4.0.9
# make
# make test
# make install

执行 make install 后,会拷贝编译好的文件到 /usr/local/bin 目录下

# ls -l /usr/local/bin/
total 32748
-rwxr-xr-x 1 root root 4367368 May  8 12:01 redis-benchmark
-rwxr-xr-x 1 root root 8117952 May  8 12:01 redis-check-aof
-rwxr-xr-x 1 root root 8117952 May  8 12:01 redis-check-rdb
-rwxr-xr-x 1 root root 4807704 May  8 12:01 redis-cli
lrwxrwxrwx 1 root root      12 May  8 12:01 redis-sentinel -> redis-server
-rwxr-xr-x 1 root root 8117952 May  8 12:01 redis-server

redis1 节点上操作,创建 cluster data 目录

# mkdir -p /var/lib/redis/redis-cluster-data
# cd /var/lib/redis/redis-cluster-data
# mkdir -p 9001 9002 9003

redis2 节点上操作,创建 cluster data 目录

# mkdir -p /var/lib/redis/redis-cluster-data
# cd /var/lib/redis/redis-cluster-data
# mkdir -p 9001 9002 9003

redis1、redis2 两个节点都需要操作
创建bin目录,添加到PATH里

# cd /usr/redis/redis-4.0.9
# mkdir bin
# cd src
# cp mkreleasehdr.sh \
redis-benchmark \
redis-check-aof \
redis-check-rdb \
redis-cli redis-server \
redis-sentinel redis-trib.rb ../bin

# vi /etc/profile
PATH=/usr/redis/redis-4.0.9/bin:$PATH

# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
# source /etc/profile
# echo $PATH
/usr/redis/redis-4.0.9/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin

redis cluster 配置

redis1 的 9001 9002 9003 目录下,
redis2 的 9001 9001 9003 目录下都需要创建 redis.conf

$ cd /var/lib/redis/redis-cluster-data/9001
$ vi redis.conf

redis.conf 配置文件请参考<<redis cluster 4.0.9 之七:redis.conf>>

# tree
.
├── 9001
│   └── redis.conf
├── 9002
│   └── redis.conf
└── 9003
    └── redis.conf

3 directories, 3 files

启动redis

redis1 上启动 redis

# cd /var/lib/redis/redis-cluster-data/9001
# redis-server /var/lib/redis/redis-cluster-data/9001/redis.conf

# cd /var/lib/redis/redis-cluster-data/9002
# redis-server /var/lib/redis/redis-cluster-data/9002/redis.conf

# cd /var/lib/redis/redis-cluster-data/9003
# redis-server /var/lib/redis/redis-cluster-data/9003/redis.conf

# tree
.
├── 9001
│   ├── appendonly.aof
│   ├── cluster_9001.conf
│   └── redis.conf
├── 9002
│   ├── appendonly.aof
│   ├── cluster_9002.conf
│   └── redis.conf
└── 9003
    ├── appendonly.aof
    ├── cluster_9003.conf
    └── redis.conf

3 directories, 9 files

redis2 上启动 redis

# cd /var/lib/redis/redis-cluster-data/9001
# redis-server /var/lib/redis/redis-cluster-data/9001/redis.conf

# cd /var/lib/redis/redis-cluster-data/9002
# redis-server /var/lib/redis/redis-cluster-data/9002/redis.conf

# cd /var/lib/redis/redis-cluster-data/9003
# redis-server /var/lib/redis/redis-cluster-data/9003/redis.conf

# tree
.
├── 9001
│   ├── appendonly.aof
│   ├── cluster_9001.conf
│   └── redis.conf
├── 9002
│   ├── appendonly.aof
│   ├── cluster_9002.conf
│   └── redis.conf
└── 9003
    ├── appendonly.aof
    ├── cluster_9003.conf
    └── redis.conf

3 directories, 9 files

查看redis 的启动情况

# ps -ef|grep -i redis
root     20531     1  0 May17 ?        00:00:17 redis-server 192.168.56.101:9001 [cluster]
root     20536     1  0 May17 ?        00:00:17 redis-server 192.168.56.101:9002 [cluster]
root     20541     1  0 May17 ?        00:00:17 redis-server 192.168.56.101:9003 [cluster]
root     30028  1851  0 09:14 pts/0    00:00:00 grep --color=auto -i redis

# netstat -antp|grep -i redis
tcp        0      0 192.168.56.101:9001     0.0.0.0:*               LISTEN      20531/redis-server
tcp        0      0 192.168.56.101:9002     0.0.0.0:*               LISTEN      20536/redis-server
tcp        0      0 192.168.56.101:9003     0.0.0.0:*               LISTEN      20541/redis-server
tcp        0      0 192.168.56.101:19001    0.0.0.0:*               LISTEN      20531/redis-server
tcp        0      0 192.168.56.101:19002    0.0.0.0:*               LISTEN      20536/redis-server
tcp        0      0 192.168.56.101:19003    0.0.0.0:*               LISTEN      20541/redis-server

正式创建

执行 redis-trib.rb 前必须安装ruby >= 2.2.2.

–replicas 1 代表每个master 有一个slave

# redis-trib.rb create --replicas 1 192.168.56.101:9001 192.168.56.101:9002 192.168.56.101:9003 192.168.56.102:9001 192.168.56.102:9002 192.168.56.102:9003
>>> Creating cluster
>>> Performing hash slots allocation on 6 nodes...
Using 3 masters:
192.168.56.101:9001
192.168.56.102:9001
192.168.56.101:9002
Adding replica 192.168.56.102:9003 to 192.168.56.101:9001
Adding replica 192.168.56.101:9003 to 192.168.56.102:9001
Adding replica 192.168.56.102:9002 to 192.168.56.101:9002
M: 8240d131c58c8b687c11462e03825bdba00af53b 192.168.56.101:9001
   slots:0-5460 (5461 slots) master
M: 0bdd8387a662984e95f5103522f52e75eceaab69 192.168.56.101:9002
   slots:10923-16383 (5461 slots) master
S: e38d78fc68b69d4e5f347cf96f31a9cb6a02dccf 192.168.56.101:9003
   replicates 12e2353c9f0b085d2684da46ba0dc69575d68603
M: 12e2353c9f0b085d2684da46ba0dc69575d68603 192.168.56.102:9001
   slots:5461-10922 (5462 slots) master
S: 2b48fd08a8ec55eba5bfa0d163d02c8462637302 192.168.56.102:9002
   replicates 0bdd8387a662984e95f5103522f52e75eceaab69
S: cf22edbc6463b8b31536819297ac50e9e39175ad 192.168.56.102:9003
   replicates 8240d131c58c8b687c11462e03825bdba00af53b
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.56.101:9001)
M: 8240d131c58c8b687c11462e03825bdba00af53b 192.168.56.101:9001
   slots:0-5460 (5461 slots) master
   1 additional replica(s)
S: cf22edbc6463b8b31536819297ac50e9e39175ad 192.168.56.102:9003
   slots: (0 slots) slave
   replicates 8240d131c58c8b687c11462e03825bdba00af53b
S: e38d78fc68b69d4e5f347cf96f31a9cb6a02dccf 192.168.56.101:9003
   slots: (0 slots) slave
   replicates 12e2353c9f0b085d2684da46ba0dc69575d68603
S: 2b48fd08a8ec55eba5bfa0d163d02c8462637302 192.168.56.102:9002
   slots: (0 slots) slave
   replicates 0bdd8387a662984e95f5103522f52e75eceaab69
M: 0bdd8387a662984e95f5103522f52e75eceaab69 192.168.56.101:9002
   slots:10923-16383 (5461 slots) master
   1 additional replica(s)
M: 12e2353c9f0b085d2684da46ba0dc69575d68603 192.168.56.102:9001
   slots:5461-10922 (5462 slots) master
   1 additional replica(s)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

slot 槽分布

M: 8240d131c58c8b687c11462e03825bdba00af53b 192.168.56.101:9001
   slots:0-5460 (5461 slots) master
   1 additional replica(s)
M: 12e2353c9f0b085d2684da46ba0dc69575d68603 192.168.56.102:9001
   slots:5461-10922 (5462 slots) master
   1 additional replica(s) 
M: 0bdd8387a662984e95f5103522f52e75eceaab69 192.168.56.101:9002
   slots:10923-16383 (5461 slots) master
   1 additional replica(s)
  
# cd /var/lib/redis/redis-cluster-data
# tree
.
├── 9001
│   ├── appendonly.aof
│   ├── cluster_9001.conf
│   ├── dump.rdb
│   └── redis.conf
├── 9002
│   ├── appendonly.aof
│   ├── cluster_9002.conf
│   ├── dump.rdb
│   └── redis.conf
└── 9003
    ├── appendonly.aof
    ├── cluster_9003.conf
    ├── dump.rdb
    └── redis.conf

3 directories, 12 files

连接redis

# redis-cli -h 192.168.56.101 -p 9001 -c
192.168.56.101:9001> 
192.168.56.101:9001> 
192.168.56.101:9001> 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:23175
cluster_stats_messages_pong_sent:25275
cluster_stats_messages_sent:48450
cluster_stats_messages_ping_received:25270
cluster_stats_messages_pong_received:23175
cluster_stats_messages_meet_received:5
cluster_stats_messages_received:48450

192.168.56.101:9001> cluster nodes
cf22edbc6463b8b31536819297ac50e9e39175ad 192.168.56.102:9003@19003 slave 8240d131c58c8b687c11462e03825bdba00af53b 0 1526649623970 6 connected
8240d131c58c8b687c11462e03825bdba00af53b 192.168.56.101:9001@19001 myself,master - 0 1526649623000 1 connected 0-5460
12e2353c9f0b085d2684da46ba0dc69575d68603 192.168.56.102:9001@19001 slave e38d78fc68b69d4e5f347cf96f31a9cb6a02dccf 0 1526649621000 7 connected
2b48fd08a8ec55eba5bfa0d163d02c8462637302 192.168.56.102:9002@19002 slave 0bdd8387a662984e95f5103522f52e75eceaab69 0 1526649624972 5 connected
0bdd8387a662984e95f5103522f52e75eceaab69 192.168.56.101:9002@19002 master - 0 1526649622000 2 connected 10923-16383
e38d78fc68b69d4e5f347cf96f31a9cb6a02dccf 192.168.56.101:9003@19003 master - 0 1526649622963 7 connected 5461-10922

参考:
https://www.cnblogs.com/kevingrace/p/7910692.html


http://www.niftyadmin.cn/n/2124314.html

相关文章

毕业感想

时间总是在我们不知不觉得时候从我们的身边溜走&#xff0c;让我们猝不及防。还记得自己还在小学打架&#xff0c;在初中玩耍&#xff0c;在高中奋斗着呢。转眼间培训结束的时间也到啦。 回想自己在培训的这一年中&#xff0c;感慨很多。还记得哪天为了来学校冒着大雪做了不到两…

oracle ebs r12 打补丁的步骤

os: linux 5.8 ebs:12.1.3 patch:14332598 这里以 p14332598 为例&#xff0c;列出打补丁的过程。 查看补丁 SELECT * FROM ad_applied_patches where 11and patch_name in (14332598) ; SELECT *FROM ad_bugs where 11and bug_number in (14332598) ; 下载patch h…

爱在时就努力去爱

爱在时就努力去爱 很多人都说过&#xff0c;爱情是一种化学反应&#xff0c;是一时的激情与冲动&#xff0c;时间久了&#xff0c;爱情就淡了&#xff0c;淡了之后或者分手&#xff0c;或者步入婚姻&#xff0c;于是爱情慢慢转变成一种亲情和一份责任了。于是爱情的魅力与风采也…

redis cluster 4.0.9 之二: failover

os: centos7.4 redis:4.0.9 ruby:2.3.4 ip 规划 redis1 192.168.56.101 redis2 192.168.56.102用两台虚拟机模拟6个redis节点。 分别为 192.168.56.101 的 9001、9002、9003 端口&#xff0c; 192.168.56.102 的 9001、9002、9003 端口。 连接redis # redis-cli -h 1…

为什么要坚持写blog

&#xff08;一&#xff09;为什么你应该&#xff08;从现在开始就&#xff09;写博客 用一句话来说就是&#xff0c;写一个博客有很多好处&#xff0c;却没有任何明显的坏处。&#xff08;阿灵顿的情况属于例外&#xff0c;而非常态&#xff0c;就像不能拿抽烟活到一百岁的英…

RMAN备份全集

1、切换服务器归档模式&#xff0c;如果已经是归档模式可跳过此步&#xff1a; %sqlplus /nolog &#xff08;启动sqlplus&#xff09; SQL> conn / as sysdba &#xff08;以DBA身份连接数据库&#xff09; SQL> shutdown immediate&#xff1b; &#xff08;立即关闭数…

oracle后台进程

DBWR进程&#xff1a;该进程执行将缓冲区写入数据文件&#xff0c;是负责缓冲存储区管理的一个ORACLE后台进程。当缓冲区中的一缓冲区被修改&#xff0c;它被标志为“弄脏”&#xff0c;DBWR的主要任务是将“弄脏”的缓冲区写入磁盘&#xff0c;使缓冲区保持“干净”。由于缓冲…

redis cluster 4.0.9 之三: startup stop

os: centos7.4 redis:4.0.9 ruby:2.3.4 ip 规划 redis1 192.168.56.101 redis2 192.168.56.102用两台虚拟机模拟6个redis节点。 分别为 192.168.56.101 的 9001、9002、9003 端口&#xff0c; 192.168.56.102 的 9001、9002、9003 端口。 start redis cluster # redi…