redis多機叢集部署文檔

來源:互聯網
上載者:User

標籤:

redis多機叢集部署文檔(centos6.2)

(要讓叢集正常工作至少需要3個主節點,在這裡我們要建立6個redis節點,其中三個為主節點,三個為從節點,對應的redis節點的ip和連接埠對應關係如下)

10.168.32.116:6379

10.168.32.117:6379

10.168.32.118:6379

10.168.32.119:6379

10.168.32.120:6379

10.168.32.121:6379

 

在安裝叢集之前,需要在伺服器上安裝ruby環境,

yum install -y ruby rubygems

gem install redis

 

下載redis版本,

#git clone https://github.com/antirez/redis.git

#mv redis /usr/local/redis

#cd  /usr/local/redis

#make && make install

 

修改配置叢集需要的基本配置,其餘部分,根據實際需要配置

#vi /usr/local/redis/redis.conf

bind 10.168.32.116

port 6379

daemonize yes

cluster-enabled yes

cluster-config-file nodes.conf

appendonly yes

修改完這幾行,把redis.conf分發到其餘的伺服器,所有伺服器的配置可以完全一致,bind是主機ip(如果是在同一台伺服器進行實驗,需要修改port,每個redis使用獨立的連接埠)

 

配置同步之後,啟動所有伺服器的redis

redis-server /usr/local/redis/redis.conf

 

執行redis的建立叢集命令建立叢集:

#./redis-trib.rb create --replicas 1 10.168.32.116:6379 10.168.32.117:6379 10.168.32.118:6379 10.168.32.119:6379 10.168.32.120:6379 10.168.32.121:6379

 

>>> Creating cluster

Connecting to node 10.168.32.116:6379: OK

Connecting to node 10.168.32.117:6379: OK

Connecting to node 10.168.32.118:6379: OK

Connecting to node 10.168.32.119:6379: OK

Connecting to node 10.168.32.120:6379: OK

Connecting to node 10.168.32.121:6379: OK

>>> Performing hash slots allocation on 6 nodes...

Using 3 masters:

10.168.32.121:6379

10.168.32.120:6379

10.168.32.119:6379

Adding replica 10.168.32.118:6379 to 10.168.32.121:6379

Adding replica 10.168.32.117:6379 to 10.168.32.120:6379

Adding replica 10.168.32.116:6379 to 10.168.32.119:6379

S: f3314ecda2ef4ea0ec140e06de3e4bf656a5e71b 10.168.32.116:6379

   replicates a5a22ba976c05b1d495812241a8dd10a5d4a5b42

S: 314f957e1021b0c262e635ad4feeb340dfe5955c 10.168.32.117:6379

   replicates 9880ecc98cde59e0d6341ba7c54bbcae9b27c877

S: 07634642c88fdf1b886d3db87dedc4b9857fce7c 10.168.32.118:6379

   replicates b7f33a1b733fe4a51447a788e334fab625a984bc

M: a5a22ba976c05b1d495812241a8dd10a5d4a5b42 10.168.32.119:6379

   slots:10923-16383 (5461 slots) master

M: 9880ecc98cde59e0d6341ba7c54bbcae9b27c877 10.168.32.120:6379

   slots:5461-10922 (5462 slots) master

M: b7f33a1b733fe4a51447a788e334fab625a984bc 10.168.32.121:6379

   slots:0-5460 (5461 slots) master

Can I set the above configuration? (type ‘yes‘ to accept): yes 此次輸入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 10.168.32.116:6379)

M: f3314ecda2ef4ea0ec140e06de3e4bf656a5e71b 10.168.32.116:6379

   slots: (0 slots) master

   replicates a5a22ba976c05b1d495812241a8dd10a5d4a5b42

M: 314f957e1021b0c262e635ad4feeb340dfe5955c 10.168.32.117:6379

   slots: (0 slots) master

   replicates 9880ecc98cde59e0d6341ba7c54bbcae9b27c877

M: 07634642c88fdf1b886d3db87dedc4b9857fce7c 10.168.32.118:6379

   slots: (0 slots) master

   replicates b7f33a1b733fe4a51447a788e334fab625a984bc

M: a5a22ba976c05b1d495812241a8dd10a5d4a5b42 10.168.32.119:6379

   slots:10923-16383 (5461 slots) master

M: 9880ecc98cde59e0d6341ba7c54bbcae9b27c877 10.168.32.120:6379

   slots:5461-10922 (5462 slots) master

M: b7f33a1b733fe4a51447a788e334fab625a984bc 10.168.32.121:6379

   slots:0-5460 (5461 slots) master

[OK] All nodes agree about slots configuration.

>>> Check for open slots...

>>> Check slots coverage...

[OK] All 16384 slots covered.

 

至此redis叢集即搭建成功!

執行命令redis-cli -c -p 6379 cluster nodes,查看叢集節點

[[email protected] src]# redis-cli -c -h 10.168.32.116 -p 6379 cluster nodes

314f957e1021b0c262e635ad4feeb340dfe5955c 10.168.32.117:6379 slave 9880ecc98cde59e0d6341ba7c54bbcae9b27c877 0 1425114266105 5 connected

a5a22ba976c05b1d495812241a8dd10a5d4a5b42 10.168.32.119:6379 master - 0 1425114267205 4 connected 10923-16383

07634642c88fdf1b886d3db87dedc4b9857fce7c 10.168.32.118:6379 slave b7f33a1b733fe4a51447a788e334fab625a984bc 0 1425114265605 6 connected

b7f33a1b733fe4a51447a788e334fab625a984bc 10.168.32.121:6379 master - 0 1425114266205 6 connected 0-5460

f3314ecda2ef4ea0ec140e06de3e4bf656a5e71b 10.168.32.116:6379 myself,slave a5a22ba976c05b1d495812241a8dd10a5d4a5b42 0 0 1 connected

9880ecc98cde59e0d6341ba7c54bbcae9b27c877 10.168.32.120:6379 master - 0 1425114266505 5 connected 5461-10922

 

7:使用redis-cli命令進入叢集環境

redis-cli -c -h 10.168.32.117 -p 6379

 

Redis叢集動作節點

1:新增一個節點,IP為10.168.32.122,連接埠為6379

首先把需要添加的節點啟動

cd /usr/local/redis/

#vi /usr/local/redis/redis.conf

bind 10.168.32.122

port 6379

啟動redis

redis-server /usr/local/redis/redis.conf

 

將新節點添加到叢集

cd /usr/local/redis/src

[[email protected] src]# ./redis-trib.rb add-node 10.168.32.122:6379 10.168.32.116:6379

>>> Adding node 10.168.32.122:6379 to cluster 10.168.32.116:6379

Connecting to node 10.168.32.116:6379: OK

Connecting to node 10.168.32.117:6379: OK

Connecting to node 10.168.32.119:6379: OK

Connecting to node 10.168.32.118:6379: OK

Connecting to node 10.168.32.121:6379: OK

Connecting to node 10.168.32.120:6379: OK

>>> Performing Cluster Check (using node 10.168.32.116:6379)

S: f3314ecda2ef4ea0ec140e06de3e4bf656a5e71b 10.168.32.116:6379

   slots: (0 slots) slave

   replicates a5a22ba976c05b1d495812241a8dd10a5d4a5b42

S: 314f957e1021b0c262e635ad4feeb340dfe5955c 10.168.32.117:6379

   slots: (0 slots) slave

   replicates 9880ecc98cde59e0d6341ba7c54bbcae9b27c877

M: a5a22ba976c05b1d495812241a8dd10a5d4a5b42 10.168.32.119:6379

   slots:10923-16383 (5461 slots) master

   1 additional replica(s)

S: 07634642c88fdf1b886d3db87dedc4b9857fce7c 10.168.32.118:6379

   slots: (0 slots) slave

   replicates b7f33a1b733fe4a51447a788e334fab625a984bc

M: b7f33a1b733fe4a51447a788e334fab625a984bc 10.168.32.121:6379

   slots:0-5460 (5461 slots) master

   1 additional replica(s)

M: 9880ecc98cde59e0d6341ba7c54bbcae9b27c877 10.168.32.120:6379

   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.

Connecting to node 10.168.32.122:6379: OK

>>> Send CLUSTER MEET to node 10.168.32.122:6379 to make it join the cluster.

[OK] New node added correctly.

 

查看叢集節點

[[email protected] src]# redis-cli -c -h 10.168.32.116 -p 6379 cluster nodes

314f957e1021b0c262e635ad4feeb340dfe5955c 10.168.32.117:6379 slave 9880ecc98cde59e0d6341ba7c54bbcae9b27c877 0 1425114360107 5 connected

38c2f060533c24698334a16b26f678ae6bd7ec41 10.168.32.122:6379 master - 0 1425114361107 0 connected

a5a22ba976c05b1d495812241a8dd10a5d4a5b42 10.168.32.119:6379 master - 0 1425114361507 4 connected 10923-16383

07634642c88fdf1b886d3db87dedc4b9857fce7c 10.168.32.118:6379 slave b7f33a1b733fe4a51447a788e334fab625a984bc 0 1425114362507 6 connected

b7f33a1b733fe4a51447a788e334fab625a984bc 10.168.32.121:6379 master - 0 1425114360507 6 connected 0-5460

f3314ecda2ef4ea0ec140e06de3e4bf656a5e71b 10.168.32.116:6379 myself,slave a5a22ba976c05b1d495812241a8dd10a5d4a5b42 0 0 1 connected

9880ecc98cde59e0d6341ba7c54bbcae9b27c877 10.168.32.120:6379 master - 0 1425114362107 5 connected 5461-10922

 

刪除redis叢集節點

redis-trib.rb  del-node        host:port node_id

./redis-trib.rb del-node 10.168.32.122:6379 38c2f060533c24698334a16b26f678ae6bd7ec41

redis多機叢集部署文檔

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.