redis 集羣配置

redis 集羣配置

①,查看gcc是否安裝

gcc -vhtml

沒有就安裝gccnode

yum install gccredis

 

②加壓redis文件並安裝

解壓 tar -zxvf redis-xxx.tar.gzvim

進入 cd redis-3.0.6ruby

鍵入 make 進行安裝app

將 redis-cli,redis-sentinel,redis-server 放入/usr/local/binspa

這樣在任意目錄下就能啓動redis了code

 

③新建redis_cluster 目錄

在redis_cluster 目錄下新建 7001,7002,7003,7004,7005,7006文件夾orm

cp redis.conf /redis_cluster/redis7001.confserver

vim redis7001.conf

修改以下:

daemonize yes #後臺啓動

port 700x #修改端口號,從7001到7006

cluster-enabled yes #開啓cluster,去掉註釋

cluster-config-file nodes.conf

cluster-node-timeout 15000

appendonly yes

dir /redis-3.0.6/redis_cluster/700x #修改目錄,從7001到7006

bind 127.0.0.1

 

④redis-server redis700x.conf 啓動對應的redis

ps -ef|grep redis 若能看到下圖,說明前面配置成功

[root@localhost src]# ps -ef|grep redis
root      2304     1  0 20:08 ?        00:00:01 redis-server 127.0.0.1:7002 [cluster]
root      2328     1  0 20:15 ?        00:00:01 redis-server 127.0.0.1:7001 [cluster]
root      2334     1  0 20:15 ?        00:00:01 redis-server 127.0.0.1:7003 [cluster]
root      2341     1  0 20:15 ?        00:00:01 redis-server 127.0.0.1:7004 [cluster]
root      2349     1  0 20:17 ?        00:00:01 redis-server 127.0.0.1:7006 [cluster]
root      2355     1  0 20:17 ?        00:00:00 redis-server 127.0.0.1:7005 [cluster]
root      4576  2272  0 20:47 pts/0    00:00:00 grep redis


 

⑤ 安裝ruby環境:

yum install ruby

yum install rubygems

下載redis-3.2.2.gem(能夠到這篇博客裏下載)

放入 redis_cluster目錄,執行以下命令

gem install redis-3.2.2.gem

 

⑥使用redis-trib.rb建立集羣

./redis-trib.rb create --replicas 1 127.0.0.1:7001 127.0.0.1:7002 127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005 127.0.0.1:7006
  1. 看到以下狀況,表示成功

[root@localhost src]# ./redis-trib.rb create --replicas 1 127.0.0.1:7001 127.0.0.1:7002 127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005 127.0.0.1:7006
>>> Creating cluster
>>> Performing hash slots allocation on 6 nodes...
Using 3 masters:
127.0.0.1:7001
127.0.0.1:7002
127.0.0.1:7003
Adding replica 127.0.0.1:7004 to 127.0.0.1:7001
Adding replica 127.0.0.1:7005 to 127.0.0.1:7002
Adding replica 127.0.0.1:7006 to 127.0.0.1:7003
M: 0a0bfd616dd785ef341388979b2090ab43280c92 127.0.0.1:7001
   slots:0-5460 (5461 slots) master
M: efd75010158f56f965f4f61b74a0cfff0109fa89 127.0.0.1:7002
   slots:5461-10922 (5462 slots) master
M: a0a7672fbb88a6dac2e05bffb2a5853bff8cf70f 127.0.0.1:7003
   slots:10923-16383 (5461 slots) master
S: df907bd1d011436651bb6b199b537d267e7e49f2 127.0.0.1:7004
   replicates 0a0bfd616dd785ef341388979b2090ab43280c92
S: 79dc86a9ed26fc14cff1b74ad2428b848d18e892 127.0.0.1:7005
   replicates efd75010158f56f965f4f61b74a0cfff0109fa89
S: 4aa14389b41103f446227fbe13155a0729231960 127.0.0.1:7006
   replicates a0a7672fbb88a6dac2e05bffb2a5853bff8cf70f
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 127.0.0.1:7001)
M: 0a0bfd616dd785ef341388979b2090ab43280c92 127.0.0.1:7001
   slots:0-5460 (5461 slots) master
M: efd75010158f56f965f4f61b74a0cfff0109fa89 127.0.0.1:7002
   slots:5461-10922 (5462 slots) master
M: a0a7672fbb88a6dac2e05bffb2a5853bff8cf70f 127.0.0.1:7003
   slots:10923-16383 (5461 slots) master
M: df907bd1d011436651bb6b199b537d267e7e49f2 127.0.0.1:7004
   slots: (0 slots) master
   replicates 0a0bfd616dd785ef341388979b2090ab43280c92
M: 79dc86a9ed26fc14cff1b74ad2428b848d18e892 127.0.0.1:7005
   slots: (0 slots) master
   replicates efd75010158f56f965f4f61b74a0cfff0109fa89
M: 4aa14389b41103f446227fbe13155a0729231960 127.0.0.1:7006
   slots: (0 slots) master
   replicates a0a7672fbb88a6dac2e05bffb2a5853bff8cf70f
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.


 

⑦鏈接redis集羣客戶端

[root@localhost redis01]# ./redis-cli -c -p 7001

127.0.0.1:7001> set name andy

-> Redirected to slot [5798] located at 127.0.0.1:7002

OK

127.0.0.1:7002> get name

"andy"

127.0.0.1:7002>

 

 

⑧查看redis 集羣狀況

cluster nodes

127.0.0.1:7001> cluster nodes
0a0bfd616dd785ef341388979b2090ab43280c92 127.0.0.1:7001 myself,master - 0 0 1 connected 0-5460
4aa14389b41103f446227fbe13155a0729231960 127.0.0.1:7006 master - 0 1525877460873 8 connected 10923-16383
a0a7672fbb88a6dac2e05bffb2a5853bff8cf70f 127.0.0.1:7003 slave 4aa14389b41103f446227fbe13155a0729231960 0 1525877463880 8 connected
df907bd1d011436651bb6b199b537d267e7e49f2 127.0.0.1:7004 slave 0a0bfd616dd785ef341388979b2090ab43280c92 0 1525877464881 4 connected
efd75010158f56f965f4f61b74a0cfff0109fa89 127.0.0.1:7002 master - 0 1525877459871 2 connected 5461-10922
79dc86a9ed26fc14cff1b74ad2428b848d18e892 127.0.0.1:7005 slave efd75010158f56f965f4f61b74a0cfff0109fa89 0 1525877461875 5 connected


(由於我手動中止了7003,而後又啓動了7003,全部7006變成了master,而7003在重啓後變成了slave)

參考https://www.cnblogs.com/yingchen/p/6763524.html

相關文章
相關標籤/搜索