SUSE Linux 11下Redis环境搭建(2)

像是上面在启动服务时需要注意切换到相应的配置文件的目录下,不然相应端口的服务无法启动,例如我之前在/usr/local/redis目录下启动后只有7000对应的服务启动了。

linux-svnfile:/usr/local/redis # redis-server ../cluster/7000/redis.conf

linux-svnfile:/usr/local/redis # redis-server ../cluster/7001/redis.conf

linux-svnfile:/usr/local/redis # redis-server ../cluster/7002/redis.conf

linux-svnfile:/usr/local/redis # redis-server ../cluster/7003/redis.conf

linux-svnfile:/usr/local/redis # redis-server ../cluster/7004/redis.conf

linux-svnfile:/usr/local/redis # redis-server ../cluster/7005/redis.conf

linux-svnfile:/usr/local/redis # ps -ef | grep redis

root    15144 19064  0 18:37 pts/0    00:00:00 vi redis.conf

root    15590    1  0 18:52 ?        00:00:00 redis-server *:7000 [cluster]         

root    15616 19443  0 18:52 pts/1    00:00:00 grep redis

SUSE Linux 11下Redis环境搭建

SUSE Linux 11下Redis环境搭建

linux-svnfile:/usr/local/cluster #redis-cli -p 7000

127.0.0.1:7000>

SUSE Linux 11下Redis环境搭建

SUSE Linux 11下Redis环境搭建

删除slave节点

SUSE Linux 11下Redis环境搭建

SUSE Linux 11下Redis环境搭建

删除master节点

linux-svnfile:/usr/local/redis # redis-trib.rb reshard 127.0.0.1:7001

How many slots do you want to move (from 1 to 16384)? 5461

What is the receiving node ID? 42929649e533ec8aad7cbb81f204f04c849d4bff

Please enter all the source node IDs. 

Type 'all' to use all the nodes as source nodes for the hash slots. 

Type 'done' once you entered all the source nodes IDs. 

Source node #1: 6fe9561e605b7ee85e67a2557f7fb641f482afb4

Source node #2:done 

#Do you want to proceed with the proposed reshard plan (yes/no)? yes 

说明:

5461表示要删除master所有的slot数量

What is the receiving node ID是指将7000的slot迁移的节点7001的node-id

Source node #1是指要删除的master的node-id

下面可以看到7000的slot为0,而7001多了4561

SUSE Linux 11下Redis环境搭建

在删除master节点出现如下面所示的错误,是因为删除master节点之前没有删除master节点的slave节点。

SUSE Linux 11下Redis环境搭建

上面是在单台机器上做的集群,下面展示两台机器上做集群,其实也很简单。

参考之前的环境编译源码到另一台机器

在两台机器上编辑配置文件

/usr/local/redis # vi redis.conf

daemonize yes

port 7000

cluster-enabled yes

cluster-config-file nodes.conf

cluster-node-timeout 5000

appendonly yes

cluster-config-file nodes-7001.conf

分别创建目录和文件

linux-svnfile:/usr/local/redis # mkdir -p/usr/local/cluster/{7001..7003}

localhost:/usr/local/redis # mkdir -p/usr/local/cluster/{8001..8003}

linux-svnfile:/usr/local/redis # cpredis.conf ../cluster/7001

linux-svnfile:/usr/local/redis # cpredis.conf ../cluster/7002

linux-svnfile:/usr/local/redis # cpredis.conf ../cluster/7003

localhost:/usr/local/redis # cp redis.conf../cluster/8001

localhost:/usr/local/redis # cp redis.conf../cluster/8002

localhost:/usr/local/redis # cp redis.conf../cluster/8003

修改对应目录的配置文件其中port 和cluster-config-file分别对应各自的目录名,可使用sed命令做修改

sed -i "s/7001/7002/g"

启动服务

SUSE Linux 11下Redis环境搭建

SUSE Linux 11下Redis环境搭建

SUSE Linux 11下Redis环境搭建

SUSE Linux 11下Redis环境搭建

SUSE Linux 11下Redis环境搭建

下面关于Redis的文章您也可能喜欢,不妨参考下:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/323d9cf22241be45960f6996c8950e45.html