如何在 Cassandra 4.0 Docker 容器上启用完整的查询日志记录?

How to enable full query logging on a Cassandra 4.0 Docker container?

我想 运行 一个 Docker 容器 运行ning Cassandra 4 并启用 Full Query Logging (FQL)。到目前为止,我已经尝试构建以下 Dockerfile:

FROM cassandra:4.0
RUN nodetool enablefullquerylog

但是失败并出现以下错误:

nodetool: Failed to connect to '127.0.0.1:7199' - ConnectException: 'Connection refused (Connection refused)'.

我还尝试取消注释位于 Docker 容器 /etc/cassandra/cassandra.yamlcassandra.yaml 中的 full_query_logging_options

# default options for full query logging - these can be overridden from command line when executing
# nodetool enablefullquerylog
full_query_logging_options:
    log_dir: /var/log/cassandra/fql.log
    roll_cycle: HOURLY
    block: true
    max_queue_weight: 268435456 # 256 MiB
    max_log_size: 17179869184 # 16 GiB
    # archive command is "/path/to/script.sh %path" where %path is replaced with the file being rolled:
    archive_command:
    max_archive_retries: 10

理想情况下,我想在 cassandra.yaml 中启用 FQL 而不必使用 nodetool 命令,但似乎这是不可能的(只能配置其给定的选项它已使用 nodetool)?

启用

我也不确定如何更改 cassandra.yaml 以允许 nodetool 连接。我注意到在 cassandra Docker 图像中 运行s Cassandra 3,nodetool 命令有效;它只是在 cassandra:4.0 图像中不起作用。从看来,需要配置cassandra.yaml中的listen_addressbroadcast_address。在 Cassandra 3 Docker 容器中,我可以看到默认配置如下:

# Address or interface to bind to and tell other Cassandra nodes to connect to.
# You _must_ change this if you want multiple nodes to be able to communicate!
#
# Set listen_address OR listen_interface, not both.
#
# Leaving it blank leaves it up to InetAddress.getLocalHost(). This
# will always do the Right Thing _if_ the node is properly configured
# (hostname, name resolution, etc), and the Right Thing is to use the
# address associated with the hostname (it might not be).
#
# Setting listen_address to 0.0.0.0 is always wrong.
#
listen_address: 172.17.0.5

# Set listen_address OR listen_interface, not both. Interfaces must correspond
# to a single address, IP aliasing is not supported.
# listen_interface: eth0

# If you choose to specify the interface by name and the interface has an ipv4 and an ipv6 address
# you can specify which should be chosen using listen_interface_prefer_ipv6. If false the first ipv4
# address will be used. If true the first ipv6 address will be used. Defaults to false preferring
# ipv4. If there is only one address it will be selected regardless of ipv4/ipv6.
# listen_interface_prefer_ipv6: false

# Address to broadcast to other Cassandra nodes
# Leaving this blank will set it to the same value as listen_address
broadcast_address: 172.17.0.5

而在 Cassandra 4 容器中它是

# Address or interface to bind to and tell other Cassandra nodes to connect to.
# You _must_ change this if you want multiple nodes to be able to communicate!
#
# Set listen_address OR listen_interface, not both.
#
# Leaving it blank leaves it up to InetAddress.getLocalHost(). This
# will always do the Right Thing _if_ the node is properly configured
# (hostname, name resolution, etc), and the Right Thing is to use the
# address associated with the hostname (it might not be). If unresolvable
# it will fall back to InetAddress.getLoopbackAddress(), which is wrong for production systems.
#
# Setting listen_address to 0.0.0.0 is always wrong.
#
listen_address: localhost

# Set listen_address OR listen_interface, not both. Interfaces must correspond
# to a single address, IP aliasing is not supported.
# listen_interface: eth0

# If you choose to specify the interface by name and the interface has an ipv4 and an ipv6 address
# you can specify which should be chosen using listen_interface_prefer_ipv6. If false the first ipv4
# address will be used. If true the first ipv6 address will be used. Defaults to false preferring
# ipv4. If there is only one address it will be selected regardless of ipv4/ipv6.
# listen_interface_prefer_ipv6: false

# Address to broadcast to other Cassandra nodes
# Leaving this blank will set it to the same value as listen_address
# broadcast_address: 1.2.3.4

我不太明白 172.17.0.5 'comes from' 在哪里以及为什么在 cassandra.yaml 中将其设置为该值将允许 nodetool 在容器上工作。关于如何在 Cassandra 4 容器上使用 nodetool 来启用 FQL 有什么想法吗?

事实证明,默认情况下,您在构建容器时不能在Dockerfile中使用运行 nodetool命令;相反,它们必须是 运行 'manually' 在 运行ning 容器中。所以我将 Dockerfile 修改为以下内容:

FROM cassandra:4.0
RUN mkdir /cassandra-fql && chmod 777 /cassandra-fql
COPY cassandra.yaml /etc/cassandra/cassandra.yaml

cassandra.yaml除了下面的full_query_logging_options:

外与默认的一样
# default options for full query logging - these can be overridden from command line when executing
# nodetool enablefullquerylog
full_query_logging_options:
    log_dir: /cassandra-fql
    roll_cycle: HOURLY
    block: true
    max_queue_weight: 268435456 # 256 MiB
    max_log_size: 17179869184 # 16 GiB
    # archive command is "/path/to/script.sh %path" where %path is replaced with the file being rolled:
    # archive_command:
    max_archive_retries: 10

然后,运行像这样安装容器后,

docker run --name cassandra-fql -p 127.0.0.1:9042:9042 cassandra-fql

docker execing进去,运行ning nodetool enablefullquerylog成功了。