前文:为了学习(装逼)redis集群的知识,搭建环境是必不可少的,于是我今儿个心血来潮开始搞。给大家看官网参考教程:
但是我还是愿意将实操(一声)过程写在博客中,安装无脑,过程充满了坑:废话不多说,不要干就是怂!
第一步:你需要提前准备原料
redis-4.0.10 下载地址:http://download.redis.io/releases/redis-4.0.10.tar.gz
第二步:在/usr下创建集群文件夹
执行下述命令,创建伪集群的文件目录
[root@localhost /]# mkdir /usr/redis-cluster
[root@localhost /]# mkdir /usr/redis-cluster/redis7000
[root@localhost /]# mkdir /usr/redis-cluster/redis7001
[root@localhost /]# mkdir /usr/redis-cluster/redis7002
[root@localhost /]# mkdir /usr/redis-cluster/redis7003
[root@localhost /]# mkdir /usr/redis-cluster/redis7004
[root@localhost /]# mkdir /usr/redis-cluster/redis7005
第三步:编写redis.conf配置文件
新建一个后缀为.conf 的redis.conf文件,里面的内容写
port 7000
cluster-enabled yes
cluster-config-file nodes.conf
cluster-node-timeout 5000
appendonly yes
daemonize yes
protected-mode no
并将文件放在第二步中新建的/usr/redis-cluster文件夹中
第四步:安装redis实例
将下载好的redis-4.0.10.tar.gz复制到redis7000-redis7005中,并且解压,安装。
由于我直接将下载好的redis-4.0.10.tar.gz复制到redis-cluster目录中,于是运行
[root@localhost redis-cluster]# cp redis-4.0.10.tar.gz redis7000
[root@localhost redis-cluster]# cp redis-4.0.10.tar.gz redis7001
[root@localhost redis-cluster]# cp redis-4.0.10.tar.gz redis7002
[root@localhost redis-cluster]# cp redis-4.0.10.tar.gz redis7003
[root@localhost redis-cluster]# cp redis-4.0.10.tar.gz redis7004
[root@localhost redis-cluster]# cp redis-4.0.10.tar.gz redis7005
接下来解压并安装(redis7000-redis7005都是这个步骤)
[root@localhost redis-cluster]# cd redis7000
[root@localhost redis-7000]# tar -xzvf redis-4.0.10.tar.gz
[root@localhost redis7000]# cd redis-4.0.10/src/
[root@localhost src]# make MALLOC=libc
接下来替换redis.conf文件(redis7000-redis7005都是这个步骤)
[root@localhost redis-cluster]# cp redis.conf redis7000/redis-4.0.10
cp:是否覆盖"redis7000/redis-4.0.10/redis.conf"? y
最后编辑redis.conf文件
[root@localhost redis-cluster]# vi redis7000/redis-4.0.10/redis.conf
输入i ,将port 改成对应的redis700x 号,比如redis7005文件夹中,就改port为7005 。最后按ESC 输入“:wq”保存并退出
第五步:启动redis实例
redis7000-redis7005都是这个步骤[root@localhost redis-cluster]# ./redis7000/redis-4.0.10/src/redis-server ./redis7000/redis-4.0.10/redis.conf
第六步:启动集群
cd到redis7000/redis-4.0.10/src目录下运行
./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
结果:
[root@localhost redis-4.0.10]# cd src/
[root@localhost src]# ./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
>>> 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:7004 to 127.0.0.1:7000
Adding replica 127.0.0.1:7005 to 127.0.0.1:7001
Adding replica 127.0.0.1:7003 to 127.0.0.1:7002
>>> Trying to optimize slaves allocation for anti-affinity
[WARNING] Some slaves are in the same host as their master
M: 0cde8f563d96941b952649922998ca875b53d8e1 127.0.0.1:7000
slots:0-5460 (5461 slots) master
M: c6fb2a55dd262840a13b6758043fe4b7d2ac9866 127.0.0.1:7001
slots:5461-10922 (5462 slots) master
M: f64163a79ec7e43f63edac64306862acfdbeee35 127.0.0.1:7002
slots:10923-16383 (5461 slots) master
S: 30e88ab2437a61a57f807a8beaea36a3301999be 127.0.0.1:7003
replicates 0cde8f563d96941b952649922998ca875b53d8e1
S: ce1ce34f85e3559a469ff886e4e100d1ddebddd3 127.0.0.1:7004
replicates c6fb2a55dd262840a13b6758043fe4b7d2ac9866
S: da8e3e2e1466a60fde21ef3cdb3ef403a7feb65f 127.0.0.1:7005
replicates f64163a79ec7e43f63edac64306862acfdbeee35
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: 0cde8f563d96941b952649922998ca875b53d8e1 127.0.0.1:7000
slots:0-5460 (5461 slots) master
1 additional replica(s)
M: c6fb2a55dd262840a13b6758043fe4b7d2ac9866 127.0.0.1:7001
slots:5461-10922 (5462 slots) master
1 additional replica(s)
S: da8e3e2e1466a60fde21ef3cdb3ef403a7feb65f 127.0.0.1:7005
slots: (0 slots) slave
replicates f64163a79ec7e43f63edac64306862acfdbeee35
M: f64163a79ec7e43f63edac64306862acfdbeee35 127.0.0.1:7002
slots:10923-16383 (5461 slots) master
1 additional replica(s)
S: 30e88ab2437a61a57f807a8beaea36a3301999be 127.0.0.1:7003
slots: (0 slots) slave
replicates 0cde8f563d96941b952649922998ca875b53d8e1
S: ce1ce34f85e3559a469ff886e4e100d1ddebddd3 127.0.0.1:7004
slots: (0 slots) slave
replicates c6fb2a55dd262840a13b6758043fe4b7d2ac9866
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
测 试 !
!=!=!=## 坑 ##=!=!=!
一、require': cannot load such file -- redis (LoadError)
[root@localhost src]# ./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
/usr/share/rubygems/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- redis (LoadError)
from /usr/share/rubygems/rubygems/core_ext/kernel_require.rb:55:in `require'
from ./redis-trib.rb:25:in `<main>'
解决方案
[root@localhost src]# gem install redis
二、ERROR: Could not find a valid gem 'redis' (>= 0)
ERROR: Could not find a valid gem 'redis' (>= 0), here is why:
Unable to download data from https://rubygems.org/ - no such name (https://rubygems.org/latest_specs.4.8.gz)
解决方案
[root@localhost redis-cluster]# gem install -l ./redis-4.0.1.gem
三、ERROR: Error installing ./redis-4.0.1.gem: redis requires Ruby version >= 2.2.2.
ERROR: Error installing ./redis-4.0.1.gem:
redis requires Ruby version >= 2.2.2.
解决方案
[root@localhost redis-cluster]# curl -L https://raw.githubusercontent.com/wayneeseguin/rvm/master/binscript
四、ost: raw.githubusercontent.com; 未知的错误 ping: raw.githubusercontent.com: 未知的名称或服务
问题:没有设定linux DNS,或
执行
[root@localhost src]# vi /etc/resolv.conf
增加
nameserver 8.8.8.8
nameserver 8.8.4.4
[root@localhost src]# cd /etc/sysconfig/network-scripts/
找到ifcfg-开头的文件,里面全都加上
DNS1=8.8.8.8
DNS2=8.8.8.4