{"id":16325318,"url":"https://github.com/murrayee/redis-cluster-demo","last_synced_at":"2025-11-01T01:30:21.208Z","repository":{"id":123979412,"uuid":"321258163","full_name":"murrayee/redis-cluster-demo","owner":"murrayee","description":"基于docker单机版集群搭建","archived":false,"fork":false,"pushed_at":"2020-12-14T06:55:05.000Z","size":11,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-12-26T01:25:57.124Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/murrayee.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-12-14T06:46:03.000Z","updated_at":"2020-12-14T06:55:07.000Z","dependencies_parsed_at":null,"dependency_job_id":"211b88e0-3c86-41a6-92dd-db006487e998","html_url":"https://github.com/murrayee/redis-cluster-demo","commit_stats":{"total_commits":2,"total_committers":1,"mean_commits":2.0,"dds":0.0,"last_synced_commit":"6118c81259f9dc2a341ba195f577a10cbd2e9c35"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/murrayee%2Fredis-cluster-demo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/murrayee%2Fredis-cluster-demo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/murrayee%2Fredis-cluster-demo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/murrayee%2Fredis-cluster-demo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/murrayee","download_url":"https://codeload.github.com/murrayee/redis-cluster-demo/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239242572,"owners_count":19606066,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-10T23:04:46.692Z","updated_at":"2025-11-01T01:30:21.052Z","avatar_url":"https://github.com/murrayee.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"单机版redis集群搭建(哨兵模式)：\n\n#### 创建网关：\n```\ndocker network create --driver bridge --subnet 172.21.0.0/180 --gateway 172.21.0.1 redis-net\n\n```\n一定要自定义指定ip段 ` --subnet 172.21.0.0/180`\n创建成功后查看`docker inspect redis-net`网关ip，来配置`redis-cluster.tmpl`中的`cluster-announce-ip`\n\n#### 生成配置文件\n\n```\n    ./redis-cluster-config.sh\n```\n\n#### 生成镜像\n\n```\n    docker-compose up -d\n```\n\n#### 配置集群\n当镜像启动完：\n- 1、 组建集群\n```\nfor N in `seq 10 15` ; do \n     redis-cli -h 172.21.0.10 -p 7000 -a 123456 cluster meet 172.21.0.${N} 700${N:1:1};\n done\n\n````\n\n- 2、查看集群节点\n```\n redis-cli -h 172.21.0.10 -p 7000 -a 123456 cluster nodes\n```\n- 3、分配slot\n```\n redis-cli -h 172.21.0.10 -p 7000 -a 123456  CLUSTER ADDSLOTS {0,5461}\n redis-cli -h 172.21.0.11 -p 7001 -a 123456  CLUSTER ADDSLOTS {5462,10922}\n redis-cli -h 172.21.0.12 -p 7002 -a 123456  CLUSTER ADDSLOTS {10923,16383}\n```\n- 4、拿到节点标识设置主从关系\n```\nredis-cli -h 172.21.0.13 -p 7003 -a 123456 CLUSTER REPLICATE 8ded936820cdb95f537ec5980808436c3c385cd1\nredis-cli -h 172.21.0.14 -p 7004 -a 123456 CLUSTER REPLICATE 34e5ce612d4e9fd4b04df84966c8565a690fc0ec\nredis-cli -h 172.21.0.15 -p 7005 -a 123456 CLUSTER REPLICATE 06eff2244ccb1790e4a9665fe465d07bda193c84\n```\n\n- 5、设置集群密码\n```\nfor n in `seq 0 5` ; do \n     # 为每个节点设相同密码\n     redis-cli -h 172.21.0.1${n} -p 700${n} -a 123456 config set requirepass 123456;\n     # 为slave节点设置主节点的密码，可能用于同步主节点数据验证使用(我这里为所有节点都设置了)\n     redis-cli -h 172.21.0.1${n} -p 700${n} -a 123456 config set masterauth 123456;\n done\n ```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmurrayee%2Fredis-cluster-demo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmurrayee%2Fredis-cluster-demo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmurrayee%2Fredis-cluster-demo/lists"}