Both servers set up redis clusters
1 , two servers are new directory: usr / local / Redis-Cluster
2 , download and extract the source code compiler (using redis version 5.0.4 )
3 , takes xzf redis-5.0.4.tar.gz
4 , cd-repeat 5.0.4
5、make & make install
Test compilation: error found
6、cd src
make test
CC Makefile.dep
You need tcl 8.5 or newer in order to run the Redis test
make: *** [test] Error 1
Cause of the problem: the lack of dependence, installation
7、yum install tcl
8 , once again test compilation ok
make test
\o/ All tests passed without errors!
Cleanup: may take some time... OK
9 , thus , can be started redis up , the default start mode for a front end starts , instructions are as follows
cd usr/local/bin
./redis-server
10 , to verify the success of start
ps -ef | grip Redis
11 , an error
A , run redis-server error bash: redis-server: command not found
This is because the system usr / local / bin does not command file directory, which you want usr / local / redis-cluster / redis / redis-5.0.4 / bin under Redis-Server , Redis-cli , Redis-Benchmark , Redis-Check-AOF , Redis-Check-RDB , Redis Sentinel- copy executable files to local / bin under
c , so modify redis.conf in the daemonize changed to yes
12 , front-end start, then , if the client is closed , redis service will be stopped , only to open a new window or into the background start Redis .
Specific approach in two steps ->
The first step : the redis unzip the file inside redis.conf copy the file to the current directory, modify redis.conf in the daemonize changed to yes
Step Two: Start
13 , creating a cluster directory
Two servers in redis-cluster created under each 7001,7002,7003 // 7004,7005,7006 directory
mkdir 7001 7002 7003
mkdir 7004 7005 7006
14 , first redis.conf parameters to be modified
(1)、daemonize 设置yes 设置后台运行redis
(2)、cluster-enabled 设置yes并去掉注释 (启动集群模式)
(3)、cluster-node-timeout 设置5000并去掉注释
(4)、bind 127.0.0.1(默认ip为127.0.0.1 需要改为其他节点机器可访问的ip 否则创建集群时无法访问对应的端口,无法创建集群 )
(5)、protected-mode设置 no(关闭保护模式)需要不同服务器的节点连通,这个就要设置为 no
(6)、appendonly 设置yes aof日志开启 有需要就开启,它会每次写操作都记录一条日志
15、复制redis.conf
分别复制redis.conf文件到7001-7006目录下
根据不同端口需要个性化设置的地方(可以批量替换)
(1)、port 7001(分别对每个机器的端口号进行设置)
(2)、设置pidfile存放在 run目录下的文件名 pidfile /var/run/redis_7001.pid
(3)、logfile /var/log/redis/redis_7001.log
(4)、dbfilename dump_7001.rdb
(5)、appendfilename "appendonly_7001.aof"
(6)、cluster-config-file nodes-7001.conf(集群节点信息文件) 去掉注释
16、创建集群
(1)、先对每台服务器的端口进行开放
输入命令行: uname
会出现系统的名称
再输入
cat /etc/redhat-release
则会出现具体系统
vim /etc/sysconfig/iptables
“I”键输入命令行:
-A INPUT -m state --state NEW -m tcp -p tcp --dport 7001 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 7002 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 7003 -j ACCEPT
....
注意BUG点:新开放的端口行一定要在端口行22的下面一行
(2)、关闭防火墙
重启防火墙使配置生效:
[root@Neo777 ~]# /etc/init.d/iptables restart
查看开放端口
[root@Neo777 ~]# /etc/init.d/iptables status
关闭防火墙命令为:
[root@Neo777 ~]# /etc/init.d/iptables stop
(3)、创建集群
./redis-cli --cluster create 172.25.44.10:7001 172.25.44.10:7002 172.25.44.10:7003 172.25.44.11:7004 172.25.44.11:7005 172.25.44.11:7006 --cluster-replicas 1
留意屏幕,会有一句(type 'yes' to accept),输入 yes ,回车,就是接受自动分配的三主三从
如果最后出现
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
说明成功了。
如果是出现
Waiting for the cluster to join...........
一直有 “.”出现,说明另一台服务器的端口策略没通,一直在等那边的节点加入集群,那么恭喜你,要悲剧了.....