欢迎来到站长天空!

其它服务器

当前位置: 主页 > 服务器 > 其它服务器

docker compose部署cassandra集群的操作代码

时间:2025-12-04 20:30:04|栏目:其它服务器|点击:

docker compose 配置

假设有两台电脑
A电脑的ip为192.168.1.100
B电脑的ip为192.168.1.103
A电脑的docker compose 配置

version: '3'
services:
  cassandra:
    restart: always
    image: cassandra:3.11.10
    hostname: cassandra1
    container_name: cassandra-node-1
    environment:
      - CASSANDRA_BROADCAST_ADDRESS=cassandra1
      - CASSANDRA_SEEDS=cassandra1,cassandra3
    extra_hosts:
      - "cassandra1:192.168.1.100"
      - "cassandra3:192.168.1.103"
    ports:
      - "9042:9042"
      - "7000:7000"
    volumes:
      - cassandra_data:/var/lib/cassandra
volumes:
  cassandra_data:

B电脑的docker compose 配置

version: '3'
services:
  cassandra:
    restart: always
    image: cassandra:3.11.10
    hostname: cassandra3
    container_name: cassandra-node-3
    environment:
      - CASSANDRA_BROADCAST_ADDRESS=cassandra3
      - CASSANDRA_SEEDS=cassandra1,cassandra3
    extra_hosts:
      - "cassandra1:192.168.1.100"
      - "cassandra3:192.168.1.103"
    ports:
      - "9042:9042"
      - "7000:7000"
    volumes:
      - cassandra_data:/var/lib/cassandra
volumes:
  cassandra_data:

设置内存

临时

sysctl -w vm.max_map_count=262144

永久

Disable memory paging and swapping performance on the host to improve performance.
禁用主机上的内存分页和交换性能以提高性能。
ps:这个看情况,内存大的话,也可以关掉

sudo swapoff -a

Increase the number of memory maps available to OpenSearch.
增加OpenSearch可用的内存映射数量。

# Edit the sysctl config file
sudo vi /etc/sysctl.conf
# Add a line to define the desired value
# or change the value if the key exists,
# and then save your changes.
vm.max_map_count=262144
# Reload the kernel parameters using sysctl
sudo sysctl -p
# Verify that the change was applied by checking the value
cat /proc/sys/vm/max_map_count

两边同时启动

docker compose up -d

查看集群状态

#在A机器pingB机器
docker exec -ti cassandra-node-1 cqlsh -u cassandra -pcassandra cassandra3 -e "DESCRIBE CLUSTER"

返回

Cluster: Test Cluster
Partitioner: Murmur3Partitioner

连接成功,可以使用数据库连接工具插入一条数据,分别连入A和B的数据库,查看数据是否一致

上一篇:Docker 安装 LogStash的详细过程

栏    目:其它服务器

下一篇:解决docker报错Encountered errors while bringing up the project实测有效

本文标题:docker compose部署cassandra集群的操作代码

本文地址:https://zz.feitang.co/server/28447.html

广告投放 | 联系我们 | 版权申明

申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:257218569 | 邮箱:257218569@qq.com

Copyright © 2018-2026 站长天空 版权所有 Powered by EyouCms冀ICP备14023439号