Linux下安装配置Redis-cluster集群

准备工作:

redis-5.0.10.tar.gz安装包

三台服务器:

10.10.175.75

10.10.175.76

10.10.175.77

 开始搭建:

1、redis-5.0.10.tar.gz放到/opt/app目录下

 

  

2、使用tar -xvf redis-5.0.10.tar.gz解压安装包

3、在当前目录下使用mv redis-5.0.10 /usr/local命令移动解压包到/usr/local目录下(需要管理员权限)

4、使用cd /usr/local切换路径

5、使用mv redis-5.0.10/ redis命令修改文件名称

 

  

6、进入到Redis目录cd redis

7、使用make && make install编译并安装

 

搭建集群:

8、进入/usr/local/redis/目录

9、cp redis.conf /etc/redis-cluster/redis-9376.conf

10、cp redis.conf /etc/redis-cluster/redis-8376.conf

11、分别修改redis-9376.conf、redis-8376.conf

 #9376配置文件

# 端口

port 9376

# 开启实例的集群模式

cluster-enabled yes

# 保存节点配置文件的路径。节点配置文件无须人为修改, 它由 Redis 集群在启动时创建, 并在有需要时自动进行更新

cluster-config-file nodes.conf

#指定超时时间,不算失败,而是切换

cluster-node-timeout 5000

appendfilename "appendonly_9376.aof"

cluster-config-file nodes_9376.conf

appendonly yes

#后台启动

daemonize yes

#指定日志路径

logfile "/etc/redis-cluster/9376.log"

#关闭保护,不然远程无法访问

protected-mode no

 

#8376配置文件

# 端口

port 9376

# 开启实例的集群模式

cluster-enabled yes

# 保存节点配置文件的路径。节点配置文件无须人为修改, 它由 Redis 集群在启动时创建, 并在有需要时自动进行更新

cluster-config-file nodes.conf

#指定超时时间,不算失败,而是切换

cluster-node-timeout 5000

appendfilename "appendonly_8376.aof"

cluster-config-file nodes_8376.conf

appendonly yes

#后台启动

daemonize yes

#指定日志路径

logfile "/etc/redis-cluster/8376.log"

 

12、/usr/local/redis/src/目录下执行

./redis-server /etc/redis-cluster/redis-9376.conf

./redis-server /etc/redis-cluster/redis-8376.conf

 

13、验证是否启动

ps -ef | grep redis

 

  

14、分别在3台机器上执行步骤1~13,搭建3台服务器

15、启动集群节点

./redis-cli --cluster create 10.10.175.75:9376 10.10.175.75:8376 10.10.175.76:9376 10.10.175.76:8376 10.10.175.77:9376 10.10.175.77:8376 --cluster-replicas 1

 

  

16、查看配置文件vim nodes_9376.conf,表示分配了曹

 

  

17、测试集群是否成功

[umpay@bjtn-jrxx183-68 redis-5.0.10]$ ./src/redis-cli -c -h 10.10.183.68 -p 8376

10.10.183.68:8376> set testkey test

-> Redirected to slot [4757] located at 10.10.183.68:9376

OK

10.10.183.68:9376> get testkey

"test"

10.10.183.68:9376> exit

[umpay@bjtn-jrxx183-68 redis-5.0.10]$ ./src/redis-cli -c -h 10.10.183.68 -p 9376

10.10.183.68:9376> get testkey

"test"

10.10.183.68:9376> exit

[umpay@bjtn-jrxx183-68 redis-5.0.10]$ ./src/redis-cli -c -h 10.10.183.70 -p 9376

10.10.183.70:9376> get testkey

-> Redirected to slot [4757] located at 10.10.183.68:9376

"test"

10.10.183.68:9376> exit

[umpay@bjtn-jrxx183-68 redis-5.0.10]$ ./src/redis-cli -c -h 10.10.183.70 -p 8376

10.10.183.70:8376> get testkey

-> Redirected to slot [4757] located at 10.10.183.68:9376

"test"

10.10.183.68:9376> exit

[umpay@bjtn-jrxx183-68 redis-5.0.10]$ ./src/redis-cli -c -h 10.10.183.71 -p 8376

10.10.183.71:8376> get testkey

-> Redirected to slot [4757] located at 10.10.183.68:9376

"test"

10.10.183.68:9376> exit

[umpay@bjtn-jrxx183-68 redis-5.0.10]$ ./src/redis-cli -c -h 10.10.183.71 -p 9376

10.10.183.71:9376> get testkey

-> Redirected to slot [4757] located at 10.10.183.68:9376

"test"

10.10.183.68:9376> exit

至此表示Redis集群完全配置完成

  

原文地址:https://www.cnblogs.com/lirongyang/p/14214707.html