From 532b501e70f99027685aefef3711a3a88224cca5 Mon Sep 17 00:00:00 2001 From: cs171027 Date: Thu, 11 Jun 2020 13:03:45 +0300 Subject: [PATCH] Further changes --- ansible.cfg | 3 +- ansible_provisioning.sh | 2 +- ansible_swarm_config.sh | 2 +- roles/lxc_swarm/tasks/Dockerfile.yml | 4 ++ roles/lxc_swarm/tasks/lxc_nodes.yml | 1 + roles/lxc_swarm/templates/Dockerfile.j2 | 3 +- roles/lxc_swarm/templates/galera.cnf.j2 | 5 +- roles/lxc_swarm/vars/main.yml | 3 + stack.yaml | 91 ++++++++++++++++++++++++ stack.yml | 5 -- swarm-galera.yml | 93 ++----------------------- 11 files changed, 112 insertions(+), 100 deletions(-) create mode 100644 stack.yaml delete mode 100644 stack.yml diff --git a/ansible.cfg b/ansible.cfg index 25442c6..a706507 100644 --- a/ansible.cfg +++ b/ansible.cfg @@ -1,5 +1,4 @@ [defaults] -#added parameters for actual management of LXC nodes with ansible because of bridged -#networking packet loss +#added parameters for actual management of LXC nodes with ansible because of bridged networking packet loss gather_timeout = 30 timeout = 30 diff --git a/ansible_provisioning.sh b/ansible_provisioning.sh index ccc00e4..44c33c0 100755 --- a/ansible_provisioning.sh +++ b/ansible_provisioning.sh @@ -1,4 +1,4 @@ #!/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 stack.yml +ansible-playbook -i inventory/hosts --skip-tags swarm --diff -v swarm-galera.yml diff --git a/ansible_swarm_config.sh b/ansible_swarm_config.sh index 8356f11..c39509c 100755 --- a/ansible_swarm_config.sh +++ b/ansible_swarm_config.sh @@ -1,3 +1,3 @@ #!/bin/bash [ `id -u` -ne 0 ] && exit 1 -ansible-playbook -i inventory/hosts --tags swarm --diff -v stack.yml +ansible-playbook -i inventory/hosts --tags swarm --diff -v swarm-galera.yml diff --git a/roles/lxc_swarm/tasks/Dockerfile.yml b/roles/lxc_swarm/tasks/Dockerfile.yml index 16c52b8..f18f4b3 100644 --- a/roles/lxc_swarm/tasks/Dockerfile.yml +++ b/roles/lxc_swarm/tasks/Dockerfile.yml @@ -1,4 +1,7 @@ --- +- setup: + tags: galera + - name: Copy galera template template: src: galera.cnf.j2 @@ -7,6 +10,7 @@ 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 diff --git a/roles/lxc_swarm/tasks/lxc_nodes.yml b/roles/lxc_swarm/tasks/lxc_nodes.yml index 615b9ad..86d56e9 100644 --- a/roles/lxc_swarm/tasks/lxc_nodes.yml +++ b/roles/lxc_swarm/tasks/lxc_nodes.yml @@ -48,4 +48,5 @@ rule: allow interface: lxcbr0 direction: in + from_ip: "10.0.3.0/24" when: inventory_hostname in groups['manager'] diff --git a/roles/lxc_swarm/templates/Dockerfile.j2 b/roles/lxc_swarm/templates/Dockerfile.j2 index 678de0e..731bfcb 100644 --- a/roles/lxc_swarm/templates/Dockerfile.j2 +++ b/roles/lxc_swarm/templates/Dockerfile.j2 @@ -6,5 +6,6 @@ RUN add-apt-repository "deb [arch=amd64,arm64,i386,ppc64el] http://mirrors.corei 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 +COPY /opt/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 }}"] diff --git a/roles/lxc_swarm/templates/galera.cnf.j2 b/roles/lxc_swarm/templates/galera.cnf.j2 index ff25602..dfc6bb6 100644 --- a/roles/lxc_swarm/templates/galera.cnf.j2 +++ b/roles/lxc_swarm/templates/galera.cnf.j2 @@ -16,5 +16,6 @@ wsrep_cluster_address="gcomm://{% for host in groups['workers'] %} {{hostvars[ho wsrep_sst_method=rsync # Galera Node Configuration -wsrep_node_address="{{ ansible_default_ipv4.address }}" -wsrep_node_name="{{ ansible_hostname }}" +#wsrep_node_address="{{ ansible_default_ipv4.address }}" +#wsrep_node_name="{{ ansible_hostname }}" +wsrep_node_name="{{ nodes[0] if ansible_hostname in groups['workers'][0] else nodes[1] }}" diff --git a/roles/lxc_swarm/vars/main.yml b/roles/lxc_swarm/vars/main.yml index 67ae7d9..6c0427c 100644 --- a/roles/lxc_swarm/vars/main.yml +++ b/roles/lxc_swarm/vars/main.yml @@ -4,3 +4,6 @@ workers: - "10.0.3.100" - "10.0.3.101" # - "10.0.3.102" +nodes: + - "node1" + - "node2" diff --git a/stack.yaml b/stack.yaml new file mode 100644 index 0000000..50039d1 --- /dev/null +++ b/stack.yaml @@ -0,0 +1,91 @@ +version: '3.2' + +services: + + db_cluster_node1: + + image: ubuntu:galera-node-worker1 + +# environment: +# - NODENAME={{.Node.Hostname}} +# - NODEID={{.Node.ID}} +# - SERVICEID={{.Service.ID}} +# - SERVICENAME={{.Service.Name}} +# - TASKID={{.Task.ID}} +# - TASKNAME={{.Task.Name}} +# - TASKREPID={{.Task.Slot}} + hostname: node1 + + volumes: + + - /var/container_data/mysql:/var/lib/mysql + + networks: + galera_net: + + deploy: + replicas: 1 + restart_policy: + delay: 10s + max_attempts: 10 + window: 60s + placement: + constraints: + - node.labels.node1 == true + - node.role == worker + #- node.group == galera + ports: + - mode: host + # target: 3306 + # published: 3306 + target: 4567 + published: 4567 + # target: 4568 + # published: 4568 + # target: 4568 + # published: 4568 + + #- "10.0.3.100:3306:3306" + #- "10.0.3.100:4567:4567" + #- "10.0.3.100:4568:4568" + #- "10.0.3.100:4444:4444" + + db_cluster_node2: + + image: ubuntu:galera-node-worker2 + + hostname: node2 + + volumes: + + - /var/container_data/mysql:/var/lib/mysql + + networks: + galera_net: + + deploy: + replicas: 1 + restart_policy: + delay: 10s + max_attempts: 10 + window: 60s + placement: + constraints: + - node.labels.node2 == true + - node.role == worker +# - node.group == galera + depends_on: + - db_cluster_node1 + ports: + - mode: host + target: 4567 + published: 4567 +# - "10.0.3.101:3306:3306" +# - "10.0.3.101:4567:4567" +# - "10.0.3.101:4568:4568" +# - "10.0.3.101:4444:4444" + + +networks: + galera_net: + diff --git a/stack.yml b/stack.yml deleted file mode 100644 index 6105683..0000000 --- a/stack.yml +++ /dev/null @@ -1,5 +0,0 @@ ---- -- hosts: all - gather_facts: no - roles: - - lxc_swarm diff --git a/swarm-galera.yml b/swarm-galera.yml index 426eed2..6105683 100644 --- a/swarm-galera.yml +++ b/swarm-galera.yml @@ -1,88 +1,5 @@ -version: '3.2' - -services: - - db_cluster_node1: - - image: ubuntu:galera-node-worker1 - -# environment: -# - NODENAME={{.Node.Hostname}} -# - NODEID={{.Node.ID}} -# - SERVICEID={{.Service.ID}} -# - SERVICENAME={{.Service.Name}} -# - TASKID={{.Task.ID}} -# - TASKNAME={{.Task.Name}} -# - TASKREPID={{.Task.Slot}} - - volumes: - - - /var/container_data/mysql:/var/lib/mysql - - networks: - galera_net: - - deploy: - replicas: 1 - restart_policy: - delay: 10s - max_attempts: 10 - window: 60s - placement: - constraints: - - node.labels.node1 == true - - node.role == worker - #- node.group == galera - ports: - - mode: host - # target: 3306 - # published: 3306 - target: 4567 - published: 4567 - # target: 4568 - # published: 4568 - # target: 4568 - # published: 4568 - - #- "10.0.3.100:3306:3306" - #- "10.0.3.100:4567:4567" - #- "10.0.3.100:4568:4568" - #- "10.0.3.100:4444:4444" - - db_cluster_node2: - - image: ubuntu:galera-node-worker2 - - volumes: - - - /var/container_data/mysql:/var/lib/mysql - - networks: - galera_net: - - deploy: - replicas: 1 - restart_policy: - delay: 10s - max_attempts: 10 - window: 60s - placement: - constraints: - - node.labels.node2 == true - - node.role == worker -# - node.group == galera - depends_on: - - db_cluster_node1 - ports: - - mode: host - target: 4567 - published: 4567 -# - "10.0.3.101:3306:3306" -# - "10.0.3.101:4567:4567" -# - "10.0.3.101:4568:4568" -# - "10.0.3.101:4444:4444" - - -networks: - galera_net: - +--- +- hosts: all + gather_facts: no + roles: + - lxc_swarm