Browse Source

Pre-final

dev
root 5 years ago
parent
commit
428cdf86f9
  1. 3
      Makefile
  2. 5
      clean.sh
  3. 40
      roles/lxc_swarm/tasks/Dockerfile.yml
  4. 10
      roles/lxc_swarm/tasks/deploy.yml
  5. 2
      roles/lxc_swarm/tasks/main.yml
  6. 11
      roles/lxc_swarm/templates/Dockerfile.j2
  7. 17
      roles/lxc_swarm/templates/galera.cnf.j2

3
Makefile

@ -8,3 +8,6 @@ provision:
swarm_deploy:
/bin/bash ./ansible_swarm_config.sh
clean:
/bin/bash ./clean.sh

5
clean.sh

@ -0,0 +1,5 @@
#!/bin/bash
docker stack rm stack
lxc-stop --name worker1; lxc-stop --name worker2
docker node rm worker1; docker node rm worker2
rm -rf /var/lib/lxc/worker*

40
roles/lxc_swarm/tasks/Dockerfile.yml

@ -1,40 +0,0 @@
---
- setup:
tags: galera
- name: Copy galera template
template:
src: galera.cnf.j2
dest: /opt/galera.cnf
owner: root
group: root
mode: '0644'
remote_src: no
tags: galera
- name: Galera template fix
shell: sed -i "s/ /,/g;s/ 1/1/g;s/ "/"/g" /opt/galera.cnf
#- name: set mysql options fact
# set_fact:
# extra_docker_options: "--wsrep-new-cluster"
# when: ansible_hostname == 'worker1'
- name: Copy Dockerfile template
template:
src: Dockerfile.j2
dest: /opt/Dockerfile
remote_src: no
#- name: Build 'swarm-galera' image
# docker_image:
# name: 'swarm-galera'
# build:
# path: /
# tag: v1
# source: build
- name: Build image from Dockerfile
shell: docker build -t ubuntu:galera-node-{{ ansible_hostname }} .
args:
chdir: /opt

10
roles/lxc_swarm/tasks/deploy.yml

@ -7,17 +7,17 @@
openssl rand -base64 32 > .secrets/mysql_root_password
run_once: true
- name: Deploy swarm stack
shell: docker stack deploy -c stack_mariadb.yaml stack
- name: Deploy swarm stack deployment file
shell: docker stack deploy -c stack.yaml stack
- name: Update swarm stack with proper environmental variables
- 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"`
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 ' '`
env MASTER_ADDR="${MASTER_ADDR}" docker stack deploy -c stack_mariadb.yaml stack
env MASTER_ADDR="${MASTER_ADDR}" docker stack deploy -c stack.yaml stack
docker service scale stack_bnode=1
sleep 30
# sleep 30
args:
executable: /bin/bash

2
roles/lxc_swarm/tasks/main.yml

@ -18,5 +18,5 @@
# tags: swarm
- include: deploy.yml
tags: swarm, deploy
tags: swarm
when: inventory_hostname in groups['manager']

11
roles/lxc_swarm/templates/Dockerfile.j2

@ -1,11 +0,0 @@
FROM ubuntu:16.04
RUN apt-get update
RUN apt-get install -y software-properties-common wget
RUN wget https://mariadb.org/mariadb_release_signing_key.asc -O - | apt-key add -
RUN add-apt-repository "deb [arch=amd64,arm64,i386,ppc64el] http://mirrors.coreix.net/mariadb/repo/10.4/ubuntu xenial main"
RUN apt-get update
RUN apt install -y rsync mariadb-server-10.4 galera-4 mariadb-client-10.4
RUN systemctl unmask mariadb
COPY galera.cnf /etc/mysql/conf.d/galera.cnf
#RUN echo "wsrep_node_address=`ip a s eth0|grep inet|head -1|awk '{print $2}'|cut -d "/" -f 1`" >> /etc/mysql/conf.d/galera.cnf
ENTRYPOINT ["mysqld","{{ extra_docker_options }}"]

17
roles/lxc_swarm/templates/galera.cnf.j2

@ -1,17 +0,0 @@
[mysqld]
binlog_format=ROW
default-storage-engine=innodb
innodb_autoinc_lock_mode=2
bind-address=0.0.0.0
# Galera Provider Configuration
wsrep_on=ON
wsrep_provider=/usr/lib/galera/libgalera_smm.so
# Galera Cluster Configuration
wsrep_cluster_name="galera_cluster"
# Galera Synchronization Configuration
wsrep_sst_method=rsync
# Galera Node Configuration
Loading…
Cancel
Save