溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

compose文件怎么在swarm中創(chuàng)建集群

發(fā)布時(shí)間:2021-07-29 22:34:20 來源:億速云 閱讀:163 作者:chen 欄目:云計(jì)算

這篇文章主要講解了“compose文件怎么在swarm中創(chuàng)建集群”,文中的講解內(nèi)容簡(jiǎn)單清晰,易于學(xué)習(xí)與理解,下面請(qǐng)大家跟著小編的思路慢慢深入,一起來研究和學(xué)習(xí)“compose文件怎么在swarm中創(chuàng)建集群”吧!

簡(jiǎn)介

一、與上面環(huán)境不一致之處: 1.使用了etcd集群 集群地址為:10.0.102.214:2379,10.0.102.175:2379,10.0.102.191:2379 2.解決網(wǎng)絡(luò)通信問題: 讓docker stack 共用同一網(wǎng)絡(luò):因stack部署時(shí)會(huì)以stack名稱創(chuàng)建網(wǎng)絡(luò),所以保持相同stack名字在同一網(wǎng)絡(luò)中。如下所示: docker stack deploy -c compose_swarm_1.yaml stack名 docker stack deploy -c compose_swarm_2.yaml stack名 docker stack deploy -c compose_swarm_3.yamlstack名

準(zhǔn)備工作

各個(gè)節(jié)點(diǎn)創(chuàng)建需要掛載的目錄及準(zhǔn)備掛載的文件(如開啟binlog的Mariadb配置文件)
#mkdir /data1/
#mkdir /etc/my.cnf.d
在k8s-node-3節(jié)點(diǎn)上創(chuàng)建開啟binlog的mariadb配置文件
# vim /etc/my.cnf.d/bin-log.cnf
[mysqld]
log-bin= mysql-bin
log_slave_updates = 1
expire_logs_days = 20
server-id = 211

master節(jié)點(diǎn)部署操作

[root@node-1 ~]# docker stack deploy -c compose_swarm_1.yaml swarm_mariadb
 【見圖1】
[root@node-1 ~]# docker stack deploy -c compose_swarm_2.yaml swarm_mariadb
 【見圖2】
[root@node-1 ~]# docker stack deploy -c compose_swarm_3.yaml swarm_mariadb
  【見圖3】
檢查
[root@node-1 ~]#docker service ls
  【見圖4】

[root@node-1 ~]# docker stack ps swarm_mariadb
 【見圖5】
[root@node-1 ~]# docker exec -it a40e41c2219a /bin/bash
[root@a40e41c2219a /]# mysql -uroot –pmypassword
MariaDB [(none)]> show status like 'wsrep%';
  【見圖6】
或者
[root@node-1 ~]# mysql -uroot -pmypassword -h node-1 -P 3311 -e "show status like 'wsrep%';"

compose文件怎么在swarm中創(chuàng)建集群 compose文件怎么在swarm中創(chuàng)建集群 compose文件怎么在swarm中創(chuàng)建集群 compose文件怎么在swarm中創(chuàng)建集群 compose文件怎么在swarm中創(chuàng)建集群 compose文件怎么在swarm中創(chuàng)建集群

yaml文件

compose_swarm_1.yaml

version: '3'
services:
  mariadb_galera_swarm0:  #service名,3個(gè)文件各不相同
    deploy:
      replicas: 1  #每個(gè)service下只有1個(gè)容器
      restart_policy:
        condition: on-failure
        delay: 10s
        max_attempts: 10
        window: 100s
      placement:
        constraints: [node.hostname==node-1] #將容器運(yùn)行在固定節(jié)點(diǎn)之上
      update_config:
        parallelism: 1
        delay: 3m # higher than SST duration

    image: severalnines/mariadb:10.1
    ports:
      - "3310:3306" #暴露的端口3個(gè)節(jié)點(diǎn)不能相同
    environment:  #創(chuàng)建集群相關(guān)環(huán)境務(wù)必一致
      CLUSTER_NAME: "mariadb_cluster_swarm"
      DISCOVERY_SERVICE: "10.0.102.218:2379,10.0.102.151:2379,10.0.102.162:2379"
      MYSQL_ROOT_PASSWORD: "mypassword"
      XTRABACKUP_PASSWORD: "mypassword"
    command:
      - --innodb_buffer_pool_size=256M
      - --max_connections=81
    volumes:  #根據(jù)需求進(jìn)行掛載
      - /etc/my.cnf.d:/etc/my.cnf.d
      - /data2:/var/lib/mysql
      - /etc/localtime:/etc/localtime
    healthcheck:
      interval: 5s
      timeout: 3s
      retries: 200 # interval * retries > SST duration
    networks:
      - galera_swarm   #網(wǎng)絡(luò)
networks:
  galera_swarm:
    driver: overlay

compose_swarm_2.yaml

version: '3'
services:
  mariadb_galera_swarm1:
    deploy:
      replicas: 1
      restart_policy:
        condition: on-failure
        delay: 10s
        max_attempts: 10
        window: 100s
      placement:
        constraints: [node.hostname==node-2]
      update_config:
        parallelism: 1
        delay: 3m # higher than SST duration

    image: severalnines/mariadb:10.1
    ports:
      - "3312:3306"
    network_mode: host
    environment:
      CLUSTER_NAME: "mariadb_cluster_swarm"
      DISCOVERY_SERVICE: "10.0.102.218:2379,10.0.102.151:2379,10.0.102.162:2379"
      MYSQL_ROOT_PASSWORD: "mypassword"
      XTRABACKUP_PASSWORD: "mypassword"
    command:
      - --innodb_buffer_pool_size=256M
      - --max_connections=81
    volumes:
      - /etc/my.cnf.d:/etc/my.cnf.d
      - /data2:/var/lib/mysql
      - /etc/localtime:/etc/localtime
    healthcheck:
      interval: 5s
      timeout: 3s
      retries: 200 # interval * retries > SST duration
    networks:
      - galera_swarm
networks:
  galera_swarm:
    driver: overlay

compose_swarm_3.yaml

version: '3'
services:
  mariadb_galera_swarm2:
    deploy:
      replicas: 1
      restart_policy:
        condition: on-failure
        delay: 10s
        max_attempts: 10
        window: 100s
      placement:
        constraints: [node.hostname==node-3]
      update_config:
        parallelism: 1
        delay: 3m # higher than SST duration

    image: severalnines/mariadb:10.1
    ports:
      - "3313:3306"
    network_mode: host
    environment:
      CLUSTER_NAME: "mariadb_cluster_swarm"
      DISCOVERY_SERVICE: "10.0.102.218:2379,10.0.102.151:2379,10.0.102.162:2379"
      MYSQL_ROOT_PASSWORD: "mypassword"
      XTRABACKUP_PASSWORD: "mypassword"
    command:
      - --innodb_buffer_pool_size=256M
      - --max_connections=81
    volumes:
      - /etc/my.cnf.d:/etc/my.cnf.d
      - /data2:/var/lib/mysql
      - /etc/localtime:/etc/localtime
    healthcheck:
      interval: 5s
      timeout: 3s
      retries: 200 # interval * retries > SST duration
    networks:
      - galera_swarm
networks:
  galera_swarm:
    driver: overla

感謝各位的閱讀,以上就是“compose文件怎么在swarm中創(chuàng)建集群”的內(nèi)容了,經(jīng)過本文的學(xué)習(xí)后,相信大家對(duì)compose文件怎么在swarm中創(chuàng)建集群這一問題有了更深刻的體會(huì),具體使用情況還需要大家實(shí)踐驗(yàn)證。這里是億速云,小編將為大家推送更多相關(guān)知識(shí)點(diǎn)的文章,歡迎關(guān)注!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI