当前位置:   article > 正文

docker compose部署cassandra集群

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:
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23

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:
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23

设置内存

临时

sysctl -w vm.max_map_count=262144
  • 1

永久

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

sudo swapoff -a
  • 1

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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

两边同时启动

docker compose up -d
  • 1

查看集群状态

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

返回

Cluster: Test Cluster
Partitioner: Murmur3Partitioner
  • 1
  • 2

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

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Gausst松鼠会/article/detail/288900
推荐阅读
相关标签
  

闽ICP备14008679号