重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
这篇文章主要讲解了“compose文件怎么在swarm中创建集群”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“compose文件怎么在swarm中创建集群”吧!
创新互联是一家集网站建设,邯山企业网站建设,邯山品牌网站建设,网站定制,邯山网站建设报价,网络营销,网络优化,邯山网站推广为一体的创新建站企业,帮助传统企业提升企业形象加强企业竞争力。可充分满足这一群体相比中小企业更为丰富、高端、多元的互联网需求。同时我们时刻保持专业、时尚、前沿,时刻以成就客户成长自我,坚持不断学习、思考、沉淀、净化自己,让我们为更多的企业打造出实用型网站。
一、与上面环境不一致之处: 1.使用了etcd集群集群地址为:10.0.102.214:2379,10.0.102.175:2379,10.0.102.191:2379 2.解决网络通信问题:让docker stack 共用同一网络:因stack部署时会以stack名称创建网络,所以保持相同stack名字在同一网络中。如下所示: 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名
各个节点创建需要挂载的目录及准备挂载的文件(如开启binlog的Mariadb配置文件) #mkdir /data1/ #mkdir /etc/my.cnf.d 在k8s-node-3节点上创建开启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
[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%';"
version: '3' services: mariadb_galera_swarm0: #service名,3个文件各不相同 deploy: replicas: 1 #每个service下只有1个容器 restart_policy: condition: on-failure delay: 10s max_attempts: 10 window: 100s placement: constraints: [node.hostname==node-1] #将容器运行在固定节点之上 update_config: parallelism: 1 delay: 3m # higher than SST duration image: severalnines/mariadb:10.1 ports: - "3310:3306" #暴露的端口3个节点不能相同 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
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
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中创建集群”的内容了,经过本文的学习后,相信大家对compose文件怎么在swarm中创建集群这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是创新互联,小编将为大家推送更多相关知识点的文章,欢迎关注!