redis cluster 4.0.9 중 하나: make & make install

9828 단어 #redissetupcluster
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 설치
참고 < >
다운로드, 컴 파일, 설치
http://www.redis.cn/download.html 아니면 그냥 wget wget 으로.http://download.redis.io/releases/redis-4.0.9.tar.gz
redis 1, redis 2 두 노드 모두 조작 이 필요 합 니 다.
# 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


redis 1 노드 에서 작업 하여 cluster data 디 렉 터 리 를 만 듭 니 다.
# mkdir -p /var/lib/redis/redis-cluster-data
# cd /var/lib/redis/redis-cluster-data
# mkdir -p 9001 9002 9003


redis 2 노드 에서 작업 하여 cluster data 디 렉 터 리 를 만 듭 니 다.
# mkdir -p /var/lib/redis/redis-cluster-data
# cd /var/lib/redis/redis-cluster-data
# mkdir -p 9001 9002 9003


redis 1, redis 2 두 노드 모두 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 설정
redis 1 의 9001 9002 9003 디 렉 터 리 에서 redis 2 의 9001 9001 9003 디 렉 터 리 에서 redis. conf 를 만들어 야 합 니 다.
$ cd /var/lib/redis/redis-cluster-data/9001
$ vi redis.conf


redis. conf 프로필 참조 < >
# tree
.
├── 9001
│   └── redis.conf
├── 9002
│   └── redis.conf
└── 9003
    └── redis.conf

3 directories, 3 files


시작 redis
redis 1 에서 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 2 에서 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.


슬롯 분포
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

좋은 웹페이지 즐겨찾기