redis:使用 redis-cli 非交互地创建集群
redis: Create cluster with redis-cli non interactively
尝试使用 redis-cli
创建集群时,如下所示
redis-cli --cluster create
出现要求确认配置的提示?
有没有办法编写这个脚本(最好在 ansible
中)并且 运行 它是非交互式的?
我知道 this topic 但是它涉及数据操作,这不是这个问题的范围。
嗯,我不知道 ansible 部分。但是 Redis official site 确实提供了一种方法 在一个小交互模式下使用脚本创建集群 .
使用 create-cluster 脚本创建 Redis 集群(请参阅文档了解更多详情)
If you don't want to create a Redis Cluster by configuring and executing individual instances manually as explained above, there is a much simpler system (but you'll not learn the same amount of operational details).
Just check utils/create-cluster
directory in the Redis distribution. There is a script called create-cluster
inside (same name as the directory it is contained into), it's a simple bash script. In order to start a 6 nodes cluster with 3 masters and 3 slaves just type the following commands:
create-cluster start
create-cluster create
Reply to yes in step 2 when the redis-cli utility wants you to accept the cluster layout.
You can now interact with the cluster, the first node will start at port 30001 by default. When you are done, stop the cluster with:
create-cluster stop
Please read the README inside this directory for more information on how to run the script.
如果对您有任何帮助,您可以尝试实施!
干杯:)
编辑:
正确地指出选项 --cluster-yes
将避免提示。例如:
redis-cli --cluster create host1:6379 host2:6379 host3:6379 --cluster-yes
从当前的 Redis 版本 (5.0.5) 开始,在 --cluster
下似乎没有可以静音或 auto-answer 交互式问题的标志:
$ redis-cli --cluster help
Cluster Manager Commands:
create host1:port1 ... hostN:portN
--cluster-replicas <arg>
check host:port
--cluster-search-multiple-owners
info host:port
fix host:port
--cluster-search-multiple-owners
reshard host:port
--cluster-from <arg>
--cluster-to <arg>
--cluster-slots <arg>
--cluster-yes
--cluster-timeout <arg>
--cluster-pipeline <arg>
--cluster-replace
rebalance host:port
--cluster-weight <node1=w1...nodeN=wN>
--cluster-use-empty-masters
--cluster-timeout <arg>
--cluster-simulate
--cluster-pipeline <arg>
--cluster-threshold <arg>
--cluster-replace
add-node new_host:new_port existing_host:existing_port
--cluster-slave
--cluster-master-id <arg>
del-node host:port node_id
call host:port command arg arg .. arg
set-timeout host:port milliseconds
import host:port
--cluster-from <arg>
--cluster-copy
--cluster-replace
help
通过使用echo
你可以执行命令和auto-answer提示:
echo "yes" | redis-cli --cluster create host1:6379 host2:6379 host3:6379
默认 Ansible Redis module 只支持一些命令而不是 --cluster
因此您必须使用 command/shell 任务创建自己的逻辑:
- name: Create cluster
shell: echo "yes" | redis-cli --cluster create host1:6379 host2:6379 host3:6379
run_once: true
when: not cluster_setup_done
--cluster-yes
是正确选项!
尝试使用 redis-cli
创建集群时,如下所示
redis-cli --cluster create
出现要求确认配置的提示?
有没有办法编写这个脚本(最好在 ansible
中)并且 运行 它是非交互式的?
我知道 this topic 但是它涉及数据操作,这不是这个问题的范围。
嗯,我不知道 ansible 部分。但是 Redis official site 确实提供了一种方法 在一个小交互模式下使用脚本创建集群 .
使用 create-cluster 脚本创建 Redis 集群(请参阅文档了解更多详情)
If you don't want to create a Redis Cluster by configuring and executing individual instances manually as explained above, there is a much simpler system (but you'll not learn the same amount of operational details).
Just check
utils/create-cluster
directory in the Redis distribution. There is a script calledcreate-cluster
inside (same name as the directory it is contained into), it's a simple bash script. In order to start a 6 nodes cluster with 3 masters and 3 slaves just type the following commands:create-cluster start create-cluster create
Reply to yes in step 2 when the redis-cli utility wants you to accept the cluster layout.
You can now interact with the cluster, the first node will start at port 30001 by default. When you are done, stop the cluster with:
create-cluster stop
Please read the README inside this directory for more information on how to run the script.
如果对您有任何帮助,您可以尝试实施!
干杯:)
编辑:
--cluster-yes
将避免提示。例如:
redis-cli --cluster create host1:6379 host2:6379 host3:6379 --cluster-yes
从当前的 Redis 版本 (5.0.5) 开始,在 --cluster
下似乎没有可以静音或 auto-answer 交互式问题的标志:
$ redis-cli --cluster help
Cluster Manager Commands:
create host1:port1 ... hostN:portN
--cluster-replicas <arg>
check host:port
--cluster-search-multiple-owners
info host:port
fix host:port
--cluster-search-multiple-owners
reshard host:port
--cluster-from <arg>
--cluster-to <arg>
--cluster-slots <arg>
--cluster-yes
--cluster-timeout <arg>
--cluster-pipeline <arg>
--cluster-replace
rebalance host:port
--cluster-weight <node1=w1...nodeN=wN>
--cluster-use-empty-masters
--cluster-timeout <arg>
--cluster-simulate
--cluster-pipeline <arg>
--cluster-threshold <arg>
--cluster-replace
add-node new_host:new_port existing_host:existing_port
--cluster-slave
--cluster-master-id <arg>
del-node host:port node_id
call host:port command arg arg .. arg
set-timeout host:port milliseconds
import host:port
--cluster-from <arg>
--cluster-copy
--cluster-replace
help
通过使用echo
你可以执行命令和auto-answer提示:
echo "yes" | redis-cli --cluster create host1:6379 host2:6379 host3:6379
默认 Ansible Redis module 只支持一些命令而不是 --cluster
因此您必须使用 command/shell 任务创建自己的逻辑:
- name: Create cluster
shell: echo "yes" | redis-cli --cluster create host1:6379 host2:6379 host3:6379
run_once: true
when: not cluster_setup_done
--cluster-yes
是正确选项!