Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to build mariadb Cluster with Docker

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "how to build a mariadb cluster in Docker". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "how to build a mariadb cluster with Docker".

Brief introduction

This example briefly describes how to build a mairadb cluster in an environment where multiple hosts use docker. Use in production is not recommended for testing only.

Implementation principle: this example creates a Mariadb cluster based on severalnines/mariadb image. When the container starts, it registers the cluster information with etcd, and other containers start up to obtain the cluster information (cluster name, running container IP, etc.) from etcd to join the cluster. The communication between containers across hosts is realized by flannel.

Architecture diagram

3 the cross-host network is installed on the node, so that the containers can communicate with each other. The first container registers its cluster information with etcd when it starts, and the later container looks up the cluster information from etcd when it starts, and joins the cluster.

Environment hostname machine IP system CPU/MEMDocker version node-110.0.102.218CentOS 7.54H/16G18.06.2-cenode-210.0.102.151CentOS 7.54H/16G18.06.2-cenode-310.0.102.162CentOS 7.54H/16G18.06.2-ce

Rely on components etcd to provide services to discover and store flannel network information flannel provides cross-host network etcd installation etcd services, clusters must install flannel components (turn off docker in advance) if not installed, then run-- network=host network

To deploy the Docker environment with configured flanneld, you need to add the following two records in vim / etc/systemd/system/docker.service: [Service] EnvironmentFile=/run/docker_opts.envExecStart=/usr/bin/dockerd\-- graph=/var/lib/docker-- log-level=error $DOCKER_NETWORK_OPTIONS $DOCKER_OPTS and then start dockersystemctl daemon-reload & & systemctl restart dockeretcd cluster machines to verify the availability of the cluster. The cluster information is as follows: machine name IP address role node1 10.0.102.218 etcd node node2 10.0.102.151 etcd node node3 10.0.102.162 etcd node running container (each node runs) REGISTRY=k8s.gcr.io/etcdETCD_VERSION=3.2.24TOKEN=my-etcd-tokenNAME_1=k8s-node-1NAME_2=k8s-node-2NAME_3=k8s -node-3HOST_1=10.0.102.218HOST_2=10.0.102.151HOST_3=10.0.102.162CLUSTER=$ {NAME_1} = http://${HOST_1}:2380, ${NAME_2} = http://${HOST_2}:2380, ${NAME_3} = http://${HOST_3}:2380DATA_DIR=/var/lib/etcd# runs on the node node1: THIS_NAME=$ {NAME_1} THIS_IP=$ {HOST_1} docker run-d\-p 2379 http://${HOST_3}:2380DATA_DIR=/var/lib/etcd# 2379\-p 2380 node1 2380\-volume=$ {DATA_DIR}: / etcd-data\-- name etcd ${REGISTRY}: ${ETCD_VERSION}\ / usr/local/bin/etcd\ -- data-dir=/etcd-data-- name ${THIS_NAME}\-- initial-advertise-peer-urls http://${THIS_IP}:2380\-- listen-peer-urls http://0.0.0.0:2380\-- advertise-client-urls http://${THIS_IP}:2379\-- listen-client-urls http://0.0.0.0:2379\-- initial-cluster ${CLUSTER}\-- initial-cluster-state new-- initial-cluster-token ${TOKEN} # runs on node node2: THIS_NAME=$ {NAME_2} THIS_IP=$ {HOST_2} docker run-d\-p 2379 DATA_DIR 2379\-p 2380 DATA_DIR}: / etcd-data\-- name etcd ${REGISTRY}: ${ETCD_VERSION}\ / usr/local/bin/etcd\ -- data-dir=/etcd-data-- name ${THIS_NAME}\-- initial-advertise-peer-urls http://${THIS_IP}:2380\-- listen-peer-urls http://0.0.0.0:2380\-- advertise-client-urls http://${THIS_IP}:2379\-- listen-client-urls http://0.0.0.0:2379\-- initial- Cluster ${CLUSTER}\-- initial-cluster-state existing-- initial-cluster-token ${TOKEN} # runs on node node3: THIS_NAME=$ {NAME_3} THIS_IP=$ {HOST_3} docker run-d\-p 2379 docker run 2379\-p 2380 volume=$ {DATA_DIR}: / etcd-data\-- name etcd ${REGISTRY}: ${ETCD_VERSION}\ / usr/local/bin/etcd \-data-dir=/etcd-data\-- name ${THIS_NAME}\-- initial-advertise-peer-urls http://${THIS_IP}:2380\-- listen-peer-urls http://0.0.0.0:2380\-- advertise-client-urls http://${THIS_IP}:2379\-- listen-client-urls http://0.0.0.0:2379\ -- initial-cluster ${CLUSTER}\-- initial-cluster-state existing-- initial-cluster-token ${TOKEN} verify the cluster # on the test verification node NFS Run another etcd container, # to use the etcdctl command line program in it to verify that REGISTRY=k8s.gcr.io/etcdETCD_VERSION=3.2.24docker run-d\-name etcd-client ${REGISTRY}: ${ETCD_VERSION}\ / usr/local/bin/etcd# enters the container Query cluster status # verify stored data and read data docker exec etcd-client / bin/sh-c "export ETCDCTL_API=3 & & / usr/local/bin/etcdctl-- endpoints= http://10.0.102.214:2379,http://10.0.102.175:2379, Http://10.0.102.191:2379-write-out=table member list "docker exec etcd-client / bin/sh-c" export ETCDCTL_API=3 & & / usr/local/bin/etcdctl-- endpoints= http://10.0.102.214:2379,http://10.0.102.175:2379, Http://10.0.102.191:2379-write-out=table endpoint status "docker exec etcd-client / bin/sh-c" export ETCDCTL_API=3 & & / usr/local/bin/etcdctl-- endpoints= http://10.0.102.214:2379,http://10.0.102.175:2379, Http://10.0.102.191:2379-write-out=table endpoint health "docker exec etcd-client / bin/sh-c" export ETCDCTL_API=3 & & / usr/local/bin/etcdctl-- endpoints= http://10.0.102.214:2379,http://10.0.102.175:2379, Http://10.0.102.191:2379 put url http://www.sina.com.cn"docker exec etcd-client / bin/sh-c "export ETCDCTL_API=3 & & / usr/local/bin/etcdctl-- endpoints= http://10.0.102.214:2379,http://10.0.102.175:2379,http://10.0.102.191:2379 get url" deployment mariadb cluster preparation

Mirror: severalnines/mariadb:10.1

Configuration file / etc/my.cnf.d/binlog.cnf mkdir-p / etc/my.cnf.d/ cat > / etc/my.cnf.d/bin-log.cnf

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report