1.下载地址: http://www.redis.cn/download.html 2. 解压:
tar -zxvf redis-5.0.5.tgz cd redis-5.0.5/ mkdir redis-cluster cd redis-cluster mkdir 7001 7002 7003 7004 7005 7006
3.修改配置文件
port 7001 cluster-enabled yes cluster-config-file 7001.conf cluster-node-timeout 5000 appendonly yes
修改好一个配置文件将其copy到 7001 —— 7006的每一个文件中,注意:修改每一个文件的端口号
4. 启动实例 :
vim redis-cluster-start.sh
redis-server /usr/local/redis-cluster/7001/redis.conf redis-server /usr/local/redis-cluster/7002/redis.conf redis-server /usr/local/redis-cluster/7003/redis.conf redis-server /usr/local/redis-cluster/7004/redis.conf redis-server /usr/local/redis-cluster/7005/redis.conf redis-server /usr/local/redis-cluster/7006/redis.conf
设置可执行权限,并执行
chmod 777 redis-cluster-start.sh ./redis-cluster-start.sh
5. 创建集群
redis-cli --cluster create 192.168.75.130:7001 192.168.75.130:7002 192.168.75.130:7003 192.168.75.130:7004 192.168.75.130:7005 192.168.75.130:7006 --cluster-replicas 1
6.连接集群
root@ubuntu:/home/song# redis-cli -c -h 192.168.75.130 -p 7001 192.168.75.130:7001>
7.查看集群节点:
192.168.75.130:7001> cluster nodes d76081af88b93f8a0fac9aa7d0b6ffd17b6b828a 192.168.75.130:7001@17001 myself,slave 1e1dd73067d05da1c0f0e21dbfd8d6b159a939ed 0 1569243825000 1 connected 3ea5e4740f60d3a98fc212ca07e76387c6781de1 192.168.75.130:6379@16379 slave 2f5915eeebec20192de7ce855d7fb9babcad369b 0 1569243824000 2 connected 1e1dd73067d05da1c0f0e21dbfd8d6b159a939ed 192.168.75.130:7004@17004 master - 0 1569243824000 7 connected 0-5460 9b614e352a24b51c9f196159e5e42718f82472d9 192.168.75.130:7006@17006 slave f5e00df5c63181ecc911ea8e457f7f58b661178e 0 1569243824000 6 connected 2f5915eeebec20192de7ce855d7fb9babcad369b 192.168.75.130:7002@17002 master - 0 1569243825558 2 connected 5461-10922 f5e00df5c63181ecc911ea8e457f7f58b661178e 192.168.75.130:7003@17003 master - 0 1569243823749 3 connected 10923-16383 2d267501b538930e3577f63e0e7e1a4b674caabc 192.168.75.130:7005@17005 slave 2f5915eeebec20192de7ce855d7fb9babcad369b 0 1569243824754 5 connected 192.168.75.130:7001>
8. 集群操作: cluster
节点(node)
槽(slot)
键 (key)
示例:
例如将 6379的节点添加到集群之中的操作如下:
1. 配置redis 6379的集群配置
protected-mode yes # Accept connections on the specified port, default is 6379 (IANA #815344). # If port 0 is specified Redis will not listen on a TCP socket. port 6379 cluster-enabled yes # Every cluster node has a cluster configuration file. This file is not # intended to be edited by hand. It is created and updated by Redis nodes. # Every Redis Cluster node requires a different cluster configuration file. # Make sure that instances running in the same system do not have # overlapping cluster configuration file names. cluster-config-file nodes-6379.conf # Cluster node timeout is the amount of milliseconds a node must be unreachable # for it to be considered in failure state. # Most other internal time limits are multiple of the node timeout. # cluster-node-timeout 15000
2. 开启实例
redis-server /usr/local/redis-5.0.5/redis.conf
3. 连接集群
root@ubuntu:/home/song# redis-cli -c -h 192.168.75.130 -p 7001 192.168.75.130:7001>
4. 添加从节点:
192.168.75.130:7001> CLUSTER MEET 192.168.75.130 6379 OK 192.168.75.130:7001> 192.168.75.130:7001> cluster nodes
5.删除从节点:
192.168.75.130:7001> CLUSTER FORGET 3ea5e4740f60d3a98fc212ca07e76387c6781de1 OK
设置当前节点为master:
文章转自:Redis5.0版本以上安装Redis单机多实例集群_PHP-考高分网 (kaotop.com)