@有緣人,送你一套Linux搭建redis集羣寶典

1、下載redis的安裝包,我用的是:redis-4.0.10.tar.gz

[root@softsec90 redis]# wget http://download.redis.io/releases/redis-4.0.10.tar.gz

2、解壓redis-4.0.10.tar.gz包

[root@Centos6 redis]# tar -zxvf redis-4.0.10.tar.gz

3、編譯

[root@Centos6 redis]# cd redis-4.0.10
[root@Centos6 redis-4.0.10]# make
[root@Centos6 redis-4.0.10]# make INSTALL

4、在redis目錄下,新建redis-cluster目錄

[root@softsec90 redis]# mkdir redis-cluster

5、在redis-cluster目錄下新建7001 7002 7003 7004 7005 7006集羣節點目錄

[root@softsec90 redis-cluster]# mkdir 7001 7002 7003 7004 7005 7006

6、將/home/local/redis/redis-4.0.10目錄下的redis.conf文件複製到7001節點目錄下,並修改redis.conf配置文件

[root@softsec90 redis-4.0.10]# cp redis.conf /home/local/redis/redis-cluster/7001
[root@softsec90 7001]# vim redis.conf 

redis.conf文件主要修改如下:

port  7001                                   //端口7001 7002 7003 7004 7005 7006       

bind 本機ip                                  //改爲其他節點機器可訪問的ip 例如192.168.xxx.xx

daemonize    yes                            //redis後臺運行

appendonly  yes                             //aof日誌開啓

pidfile  /var/run/redis_7001.pid            //pidfile文件對應7001 7002 7003 7004 7005... 

cluster-enabled  yes                        //開啓集羣  

cluster-config-file  nodes_7001.conf        //集羣的配置 配置文件首次啓動自動生成7001 7002.. 

cluster-node-timeout  15000                 //請求超時  默認15秒,可自行修改

7、再將redis.conf文件複製到其他7002 7003 7004 7005 7006節點下,替換對應節點的端口號即可。

8、啓動6個節點,先將/home/local/redis/redis-4.0.10/src下的redis-server文件複製到/usr/bin下

[root@softsec90 src]# cp redis-server /usr/bin/

[root@softsec90 redis]# redis-server redis-cluster/7001/redis.conf

[root@softsec90 redis]# redis-server redis-cluster/7002/redis.conf

[root@softsec90 redis]# redis-server redis-cluster/7003/redis.conf

[root@softsec90 redis]# redis-server redis-cluster/7004/redis.conf

[root@softsec90 redis]# redis-server redis-cluster/7005/redis.conf

[root@softsec90 redis]# redis-server redis-cluster/7006/redis.conf

9、查看各個節點啓動是否啓動成功

[root@softsec90 redis]# ps -aux | grep redis

 

10、安裝ruby環境

[root@softsec90 redis]# yum install ruby
[root@softsec90 redis]# yum install rubygems
[root@softsec90 redis]# gem install redis --version 3.0.0

11、創建集羣,先將/home/local/redis/redis-4.0.10/src下redis-trib.rb文件複製到/usr/bin下

[root@softsec90 src]# cp redis-trib.rb  /usr/bin/
[root@softsec90 redis-cluster]# redis-trib.rb  create --replicas 1 192.168.101.90:7001 192.168.101.90:7002 192.168.101.90:7003 192.168.101.90:7004 192.168.101.90:7005 192.168.101.90:7006

 

至此,redis集羣創建成功。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章