如何检查Cassandra准备好了 [英] How to check that Cassandra is ready

查看:70
本文介绍了如何检查Cassandra准备好了的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆