如何检查 Cassandra 是否准备就绪 [英] How to check that Cassandra is ready
问题描述
我有一个在 Docker 中运行的 Cassandra,我想在数据库准备好时启动一个 CQL 脚本.我尝试检查端口以检测它何时准备就绪:
I have a Cassandra running in a Docker and I want to launch a CQL script when the database is ready. I tried checking the port to detect when it's ready :
while ! nc -z localhost 7199; do
sleep 1
done
echo "Cassandra is ready"
cqlsh -f ./createTables.cql
但是在数据库真正准备好之前端口就打开了,因此cqlsh
失败了.如何正确检查 Cassandra 状态并启动脚本?提前致谢.
But the port is opened before the database is really ready, and the cqlsh
therefore fails. How to properly check the Cassandra status and launch the script ? Thanks in advance.
推荐答案
首先你需要等待另一个端口 - 9042 - 这是 CQLSH 使用的端口.
First you need to wait on another port - 9042 - this is a port that is used by CQLSH.
另一种方法也可以是等待 sqlsh
而不是 nc
的执行(或者作为第二步,因为 nc
执行).例如,您可以使用类似命令:
Another approach could be also waiting for execution of sqlsh
instead of nc
(or as a second step, because nc
is much faster to execute). For example, you can use something like commands:
while ! cqlsh -e 'describe cluster' ; do
sleep 1
done
等到 Cassandra 准备好...
to wait until Cassandra is ready...
这篇关于如何检查 Cassandra 是否准备就绪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!