Browse Source

Mariadb overlay network addition

dev
root 4 years ago
parent
commit
e5b7623627
  1. 20
      roles/lxc_swarm/tasks/deploy.yml
  2. 5
      roles/lxc_swarm/tasks/swarm.yml
  3. 79
      stack.yaml
  4. 13
      swarmlab/Makefile
  5. 5
      swarmlab/ansible.cfg
  6. 5
      swarmlab/ansible_install.sh
  7. 4
      swarmlab/ansible_provisioning.sh
  8. 3
      swarmlab/ansible_swarm_config.sh

20
roles/lxc_swarm/tasks/deploy.yml

@ -10,28 +10,20 @@
- name: Deploy swarm stack deployment file
shell: docker stack deploy -c stack.yaml stack
#- pause:
# seconds: 30
- name: Update swarm stack service "bnode" with proper environmental variables
shell: |
unset MASTER_ADDR
mcontainer_addr=`ssh root@10.0.3.100 "docker ps|xargs -n1|grep -i NAMES -A 1|tail -1"`
sleep 60; mcontainer_addr=`ssh root@10.0.3.100 "docker ps|xargs -n1|grep -i NAMES -A 1|tail -1"`
MASTER_ADDR=`ssh -t root@10.0.3.100 "docker exec -it $mcontainer_addr ip a s|grep -i 10.0|head -1 2>/dev/null" 2>&1 |grep inet|awk '{print $2}'|cut -d "/" -f 1|tr -d ' '`
[ -z $MASTER_ADDR ] && echo "Node 1 hasn't yet been initialized" && exit 1
[ -z $MASTER_ADDR ] && echo "Node 1 hasn't yet been initialized"
env MASTER_ADDR="${MASTER_ADDR}" docker stack deploy -c stack.yaml stack
env MASTER_ADDR="${MASTER_ADDR}" docker service scale stack_bnode=1
# env MASTER_ADDR="${MASTER_ADDR}" docker service scale stack_bnode=1
# sleep 30
args:
executable: /bin/bash
#- name: Wait for seed container to start
# pause:
# seconds: 30
#- name: Start mariadb cluster on node1
# shell: docker service scale stack_node1=1
#- name: Remove seed container
# shell: docker service rm stack_seed
#- name: Wait for nodes[0] container to start
# pause:
# seconds: 30

5
roles/lxc_swarm/tasks/swarm.yml

@ -10,6 +10,11 @@
register: worker_token
when: inventory_hostname in groups['manager']
- name: Create 'mariadb' overlay network
shell: docker network create -d overlay --subnet=10.0.10.0/24 mariadb
ignore_errors: true
when: inventory_hostname in groups['manager']
- name: Prepare swarm workers
docker_swarm:
state: join

79
stack.yaml

@ -1,82 +1,73 @@
version: '3.4'
version: '3.8'
services:
# seed:
# image: colinmollenhour/mariadb-galera-swarm
# environment:
# - XTRABACKUP_PASSWORD_FILE=/run/secrets/xtrabackup_password
# - MYSQL_USER=user
# - MYSQL_PASSWORD_FILE=/run/secrets/mysql_password
# - MYSQL_DATABASE=database
# - MYSQL_ROOT_PASSWORD_FILE=/run/secrets/mysql_root_password
# - NODE_ADDRESS=^10.0.*.*
# networks:
# - galera_network
# command: seed
# deploy:
# placement:
# # Services must run only on workers with one service per container
# constraints:
# - node.labels.node1 == true
# - node.role == worker
# volumes:
# - /var/lib/mysql:/var/lib/mysql
# secrets:
# - xtrabackup_password
# - mysql_password
# - mysql_root_password
anode:
image: colinmollenhour/mariadb-galera-swarm
# hostname:
environment:
- XTRABACKUP_PASSWORD_FILE=/run/secrets/xtrabackup_password
- NODE_ADDRESS=^10.0.*.*
- MYSQL_USER=user
- MYSQL_PASSWORD_FILE=/run/secrets/mysql_password
- MYSQL_DATABASE=database
- MYSQL_ROOT_PASSWORD_FILE=/run/secrets/mysql_root_password
- NODE_ADDRESS=^10.0.10.*
- HEALTHY_WHILE_BOOTING=1
networks:
- galera_network
- mariadb
ports:
- mode: host
target: 4567
published: 4567
command: node tasks.anode,tasks.bnode
volumes:
- /var/lib/mysql:/var/lib/mysql
deploy:
resources:
limits:
cpus: '0.75'
memory: 250M
reservations:
cpus: '0.5'
memory: 100M
# Replicated mode
mode: replicated
replicas: 1
# restart_policy:
# delay: 10s
# max_attempts: 10
# window: 60s
placement:
# Services must run only on workers with one service per container
#max_replicas_per_node: 1
max_replicas_per_node: 1
constraints:
- node.labels.node1 == true
- node.role == worker
secrets:
- xtrabackup_password
- mysql_password
- mysql_root_password
bnode:
image: colinmollenhour/mariadb-galera-swarm
#hostname: bnode
environment:
- XTRABACKUP_PASSWORD_FILE=/run/secrets/xtrabackup_password
- NODE_ADDRESS=^10.0.*.*
- NODE_ADDRESS=^10.0.10.*
- HEALTHY_WHILE_BOOTING=1
- MASTER_ADDR
networks:
- galera_network
- mariadb
command: node $MASTER_ADDR,tasks.bnode
# command: node tasks.anode,tasks.bnode
volumes:
- /var/lib/mysql:/var/lib/mysql
deploy:
resources:
limits:
cpus: '0.75'
memory: 250M
reservations:
cpus: '0.5'
memory: 100M
# Replicated mode
mode: replicated
replicas: 0
# restart_policy:
# delay: 10s
# max_attempts: 10
# window: 60s
replicas: 1
placement:
# Services must run only on workers with one service per container
#max_replicas_per_node: 1
max_replicas_per_node: 1
constraints:
- node.labels.node2 == true
- node.role == worker
@ -91,7 +82,9 @@ services:
# driver: local
networks:
galera_network:
mariadb:
external:
name: mariadb
secrets:
xtrabackup_password:

13
swarmlab/Makefile

@ -1,13 +0,0 @@
all: preautomation provision swarm_deploy
preautomation:
/bin/bash ./ansible_install.sh
provision:
/bin/bash ./ansible_provisioning.sh
swarm_deploy:
/bin/bash ./ansible_swarm_config.sh
clean:
/bin/bash ./clean.sh

5
swarmlab/ansible.cfg

@ -1,5 +0,0 @@
[defaults]
#added parameters for actual management of LXC nodes with ansible because of bridged networking packet loss
gather_timeout = 30
timeout = 45
host_key_checking = False

5
swarmlab/ansible_install.sh

@ -1,5 +0,0 @@
#!/bin/bash
[ `id -u` -ne 0 ] && exit 1
echo "deb http://ppa.launchpad.net/ansible/ansible/ubuntu trusty main" >> /etc/apt/sources.list
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 93C4A3FD7BB9C367
apt update && apt install -y ansible

4
swarmlab/ansible_provisioning.sh

@ -1,4 +0,0 @@
#!/bin/bash
[ `id -u` -ne 0 ] && exit 1
test -f /root/.ssh/id_rsa.pub || ssh-keygen -t rsa -b 4096 -N '' -f /root/.ssh/id_rsa
ansible-playbook -i inventory/hosts --skip-tags swarm --diff -v swarm-galera.yml

3
swarmlab/ansible_swarm_config.sh

@ -1,3 +0,0 @@
#!/bin/bash
[ `id -u` -ne 0 ] && exit 1
ansible-playbook -i inventory/hosts --tags swarm --diff -v swarm-galera.yml
Loading…
Cancel
Save