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

时间:2020-11-01 18:23:16

标签: docker cassandra

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

FROM cassandra:4.0
RUN nodetool enablefullquerylog

但这失败并显示以下错误:

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

我还尝试取消注释Docker容器上full_query_logging_optionscassandra.yaml中的/etc/cassandra/cassandra.yaml的注释:

# 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 3的cassandra Docker镜像中,nodetool命令有效;它只是不适用于cassandra:4.0图片。从Cassandra failed to connect看来,需要的是在listen_address中配置broadcast_addresscassandra.yaml。在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的来源以及为什么在cassandra.yaml中将其设置为该值将允许nodetool在容器上工作。有什么想法如何在Cassandra 4容器上使用nodetool来启用FQL?

1 个答案:

答案 0 :(得分:1)

事实证明,默认情况下,构建容器时无法在nodetool中运行Dockerfile命令;相反,它们必须在正在运行的容器中“手动”运行。因此,我将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 exec成功运行nodetool enablefullquerylog