redis集群配置

版本信息:
ubuntu 16.04
gcc version 5.4.0
版本问题真的很重要,很有可能在别人的电脑里面可以正常操作,换一台就…呵呵,你懂得!
好,废话不多说,来代码!!
1.安装redis: 1)下载解压:

/usr/local$ sudo wget http://download.redis.io/releases/redis-3.0.2.tar.gz /usr/local$ sudo tar -xvzf redis-3.0.2.tar.gz /usr/local$ cd redis-3.0.2/

2)编译安装(/usr/local/redis-3.0.2/)
sudo make sudo make install

提示编译成功:
Hint: It's a good idea to run 'make test' ; ) make[1]: Leaving directory '/usr/local/redis-3.0.2/src'

2.配置文件修改: 1)创建文件夹:
/usr/local$ sudo mkdir redis-service

2)在reddis-service下创建6个文件夹:
sudo mkdir redis-7000 redis-7001 redis-7002 redis-7003 redis-7004 redis-7005

注:要让集群正常工作至少需要3个主节点,在这里我们要创建6个redis节点, 其中三个为主节点(master),三个为从节点(slave),对应的redis节点的ip和端口对应关系127.0.0.1:7000 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
3)复制redis3.0.2下的redis.conf 到上一级目录的redis-service
4)修改文件名:
sudo mv redis.conf redis-cluster.conf dss@dss:/usr/local/redis-service$ ls redis-7000redis-7002redis-7004redis-cluster.conf redis-7001redis-7003redis-7005

5)复制redis-cluster.conf 分别到这六个文件夹内:
6)分别修改每个文件夹内的配置文件:
修改命令:
/usr/local/redis-service/redis-7000$ sudo vim redis-cluster.conf

修改内容例如:redis-7000:
【redis集群配置】port 7000
daemonize yes
pidfile redis-7000.pid
cluster-enabled yes
cluster-config-file nodes-7000.conf
cluster-node-timeout 15000 #看情况而定,尽量保持每台机子的原数据
appendonly yes
7)复制 redis-server 到/usr/local/redis-service/:
/usr/local/redis-3.0.2/src$ sudo cp redis-server /usr/local/redis-service/

8)执行redis:
/usr/local/redis-service$ sudo ./redis-server redis-7000/redis-cluster.conf & /usr/local/redis-service$ sudo ./redis-server redis-7001/redis-cluster.conf & /usr/local/redis-service$ sudo ./redis-server redis-7002/redis-cluster.conf & /usr/local/redis-service$ sudo ./redis-server redis-7003/redis-cluster.conf & /usr/local/redis-service$ sudo ./redis-server redis-7004/redis-cluster.conf & /usr/local/redis-service$ sudo ./redis-server redis-7005/redis-cluster.conf &

注:&符号是为了在执行时不占用本窗口!如果不加,你可以试试(手动滑稽
这样就成功启动了redis
3.安装集群工具: 1)安装ruby及交互环境:
/usr/local$ sudo apt-get install ruby /usr/local$ sudo apt-get install irb /usr/local$ sudo apt-get install ri

2)安装rubygems(必须安装,否则无法启动集群命令)
RubyGems 旨在方便地管理 gem 安装的工具,以及用于分发 gem 的服务器。这类似于Ubunt u 下的apt -get , Cent os 的 yum,Pyt hon 的 pip!!
sudo apt-get install rubygems

出现下面的情况的话:就只能手动编译安装了!
注意,选中 'ruby' 而非 'rubygems' ruby 已经是最新版 (1:2.3.0+1)。

官网下载rubygems安装包:https://rubygems.org/pages/download
cd /usr/local/src sudomkdir rubygems

移动到/usr/local/scr/rubygems/路径下!
解压安装包:
sudo unzip rubygems-2.7.7.zip cdrubygems-2.7.7

执行命令:
sudo ruby setup.rb

安装成功提示:
RubyGems installed the following executables: /usr/bin/gem2.3 /usr/bin/bundle2.3

通过gem安装redis:
sudo gem install redis Fetching: redis-4.0.1.gem (100%) Successfully installed redis-4.0.1 Parsing documentation for redis-4.0.1 Installing ri documentation for redis-4.0.1 Done installing documentation for redis after 1 seconds 1 gem installed

安装成功!!
进入/usr/local/redis-3.0.2/src,查找redis-trib.rb,并复制到redis-service
/usr/local/redis-3.0.2/src$ sudo cp redis-trib.rb /usr/local/redis-service/

启动集群命令:
sudo ./redis-trib.rb create --replicas 1 127.0.0.1:7000 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 >>> Creating cluster Connecting to node 127.0.0.1:7000: OK Connecting to node 127.0.0.1:7001: OK Connecting to node 127.0.0.1:7002: OK Connecting to node 127.0.0.1:7003: OK Connecting to node 127.0.0.1:7004: OK Connecting to node 127.0.0.1:7005: OK >>> Performing hash slots allocation on 6 nodes... Using 3 masters: 127.0.0.1:7000 127.0.0.1:7001 127.0.0.1:7002 Adding replica 127.0.0.1:7003 to 127.0.0.1:7000 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 M: fbfdc203d9904c7a8a85f61a4113e377ffde039d 127.0.0.1:7000 slots:0-5460 (5461 slots) master M: 5b04fdcdb078389f2af2acf471e33b6bd92d0ebc 127.0.0.1:7001 slots:5461-10922 (5462 slots) master M: 92613e645b281c3b4a5511b4866ec3db80cba7d4 127.0.0.1:7002 slots:10923-16383 (5461 slots) master S: 2a284f31e9e19a078595ed9969b57a13b5cfb128 127.0.0.1:7003 replicates fbfdc203d9904c7a8a85f61a4113e377ffde039d S: d6b4b60c415a854bdebd46fd0922172412b3e323 127.0.0.1:7004 replicates 5b04fdcdb078389f2af2acf471e33b6bd92d0ebc S: 7a6124eb40a7e008b1acdd12a4c0eb388a2b7873 127.0.0.1:7005 replicates 92613e645b281c3b4a5511b4866ec3db80cba7d4 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:7000) M: fbfdc203d9904c7a8a85f61a4113e377ffde039d 127.0.0.1:7000 slots:0-5460 (5461 slots) master M: 5b04fdcdb078389f2af2acf471e33b6bd92d0ebc 127.0.0.1:7001 slots:5461-10922 (5462 slots) master M: 92613e645b281c3b4a5511b4866ec3db80cba7d4 127.0.0.1:7002 slots:10923-16383 (5461 slots) master M: 2a284f31e9e19a078595ed9969b57a13b5cfb128 127.0.0.1:7003 slots: (0 slots) master replicates fbfdc203d9904c7a8a85f61a4113e377ffde039d M: d6b4b60c415a854bdebd46fd0922172412b3e323 127.0.0.1:7004 slots: (0 slots) master replicates 5b04fdcdb078389f2af2acf471e33b6bd92d0ebc M: 7a6124eb40a7e008b1acdd12a4c0eb388a2b7873 127.0.0.1:7005 slots: (0 slots) master replicates 92613e645b281c3b4a5511b4866ec3db80cba7d4 [OK] All nodes agree about slots configuration. >>> Check for open slots... >>> Check slots coverage... [OK] All 16384 slots covered.

BINGO!!启动成功!!
人人为我,我为人人!!

    推荐阅读