docker

关注公众号 jb51net

关闭
首页 > 网站技巧 > 服务器 > 云和虚拟化 > docker > docker compose集群

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

作者:SangBigYe

这篇文章主要介绍了docker compose部署cassandra集群的操作代码,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧

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 compose部署cassandra集群的文章就介绍到这了,更多相关docker compose集群内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

您可能感兴趣的文章:
阅读全文