-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit b42c44e
Showing
13 changed files
with
764 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
#galera-cluster | ||
|
||
##Features | ||
|
||
- Setup mariadb galera cluster. | ||
- Bootstrap new master and slaves. | ||
- Install percona xtradb scripts and services. (@see https://github.com/olafz/percona-clustercheck) | ||
|
||
#Role Variables | ||
|
||
##Passwords | ||
|
||
Passwords have to be stored on local ansible machine. | ||
|
||
Set the path for the storage with `galera_password_lookup_dir` | ||
|
||
##Group vars | ||
|
||
`galera_server_package`: mariadb-server-10.1 | ||
|
||
`galera_cluster_name`: galera | ||
|
||
`galera_bind_address`: 0.0.0.0 | ||
|
||
`galera_manage_users`: True | ||
|
||
|
||
##Host vars | ||
|
||
|
||
Set `galera_bootstrap` to True on one node, this will be the initial master node. | ||
|
||
Set `galera_node_ip` for each host (@see example inventory) | ||
|
||
|
||
##Monitor cluster via http | ||
@see https://github.com/olafz/percona-clustercheck | ||
|
||
Set `galera_check_scripts` to True if you like to install the percona clustercheck scripts | ||
|
||
Set port for the xinetd service `galera_check_scripts_port` | ||
|
||
|
||
##Checkuser for haproxy | ||
|
||
Create a checkuser for HAproxy with no password: | ||
|
||
Enable `galera_haproxy_user`-> True. | ||
|
||
List all allowed hosts in `galera_haproxy_hosts` | ||
|
||
|
||
|
||
#Dependencies | ||
|
||
None | ||
|
||
#Example | ||
|
||
|
||
##Inventory | ||
|
||
[galera] | ||
aav.gluster01 galera_node_ip=10.100.2.91 | ||
aav.gluster02 galera_node_ip=10.100.2.92 galera_bootstrap=1 | ||
aav.gluster03 galera_node_ip=10.100.2.93 | ||
|
||
##Playbook | ||
|
||
- hosts: galera | ||
become: true | ||
roles: | ||
- netzwirt.galera-cluster | ||
|
||
|
||
#License | ||
|
||
BSD | ||
|
||
#Author Information | ||
|
||
[netzwirt](https://github.com/netzwirt) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
--- | ||
# defaults for netzwirt.galera-cluster | ||
|
||
galera_server_package: mariadb-server-10.1 | ||
|
||
galera_cluster_name: galera | ||
|
||
galera_bootstrap: False | ||
|
||
galera_node_ip: 127.0.0.1 | ||
|
||
galera_bind_address: 0.0.0.0 | ||
|
||
galera_manage_users: True | ||
|
||
#galera_grant_hosts: [] | ||
|
||
|
||
# THIS PATH MUST EXIST in some versions of ansible TO AVOID RACE CONDITIONS !!! | ||
# @see https://github.com/ansible/ansible/issues/10784 | ||
galera_password_lookup_dir: "{{ inventory_dir }}/storage/netzwirt.galera-cluster/{{ galera_cluster_name }}" | ||
|
||
|
||
# monitor cluster via http | ||
# @see https://github.com/olafz/percona-clustercheck | ||
galera_check_scripts: True | ||
galera_check_scripts_port: 9200 | ||
|
||
|
||
# checkuser for haproxy | ||
galera_haproxy_user: True | ||
galera_haproxy_hosts: | ||
- 127.0.0.1 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
--- | ||
|
||
- name: restart mysql | ||
service: name=mysql state=restarted | ||
|
||
- name: start mysql | ||
service: name=mysql state=started | ||
|
||
- name: stop mysql | ||
service: name=mysql state=stopped | ||
|
||
|
||
- name: restart xinetd | ||
service: name=xinetd state=restarted | ||
|
||
- name: start xinetd | ||
service: name=xinetd state=started | ||
|
||
- name: stop xinetd | ||
service: name=xinetd state=stopped |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
--- | ||
galaxy_info: | ||
author: 'Reto Gassmann' | ||
description: 'Install MariaDB galera-cluster' | ||
license: BSD | ||
min_ansible_version: '1.8' | ||
|
||
platforms: | ||
- name: Ubuntu | ||
versions: | ||
- trusty | ||
- name: Debian | ||
versions: | ||
- jessie | ||
|
||
categories: | ||
- mysql | ||
- clustering | ||
- database | ||
- mariadb | ||
- galera | ||
|
||
dependencies: [] | ||
|
||
allow_duplicates: yes | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,207 @@ | ||
--- | ||
|
||
- name: repository key | ||
apt_key: | ||
keyserver: keyserver.ubuntu.com | ||
id: "0xcbcb082a1bb943db" | ||
|
||
|
||
- name: add apt repository | ||
apt_repository: | ||
repo: "deb http://ftp.heanet.ie/mirrors/mariadb/repo/10.1/ubuntu {{ ansible_distribution_release }} main" | ||
state: present | ||
update_cache: yes | ||
|
||
|
||
- name: check bootstrapped | ||
stat: | ||
path: /etc/mysql/galera_node_bootstrapped | ||
register: galera_node_bootstrapped | ||
|
||
|
||
- name: preseed galera root password | ||
shell: echo "{{ galera_server_package }} mysql-server/root_password password {{ galera_root_password }}" | debconf-set-selections ; | ||
echo "{{ galera_server_package }} mysql-server/root_password_again password {{ galera_root_password }}" | debconf-set-selections | ||
executable=/bin/bash | ||
when: galera_node_bootstrapped.stat.exists == False | ||
|
||
|
||
- name: install required packages | ||
apt: | ||
pkg: "{{ item }}" | ||
state: present | ||
update_cache: yes | ||
cache_valid_time: 3600 | ||
with_items: | ||
- "{{ galera_server_package }}" | ||
- galera-3 | ||
- rsync | ||
- python-mysqldb | ||
|
||
|
||
- name: generate client config | ||
template: | ||
src: my.cnf-root.j2 | ||
dest: /root/.my.cnf | ||
owner: root | ||
group: root | ||
mode: 0400 | ||
|
||
|
||
- name: set mysql root password | ||
mysql_user: | ||
name: root | ||
password: "{{ galera_root_password }}" | ||
host: "{{ item }}" | ||
state: present | ||
priv: "*.*:ALL,GRANT" | ||
with_items: | ||
- localhost | ||
- "{{ inventory_hostname }}" | ||
- "{{ ansible_fqdn }}" | ||
- 127.0.0.1 | ||
- "::1" | ||
- "{{ galera_haproxy_hosts }}" | ||
when: galera_manage_users | ||
|
||
|
||
- name: set debian-sys-maint password | ||
mysql_user: | ||
name: debian-sys-maint | ||
password: "{{ galera_sys_maint_password }}" | ||
host: localhost | ||
login_user: root | ||
login_password: "{{ galera_root_password }}" | ||
state: present | ||
priv: "*.*:ALL" | ||
when: galera_manage_users | ||
|
||
|
||
- name: set clustercheck password | ||
mysql_user: | ||
name: clustercheck | ||
password: "{{ galera_clustercheck_password }}" | ||
host: localhost | ||
login_user: root | ||
login_password: "{{ galera_root_password }}" | ||
state: present | ||
priv: "*.*:PROCESS" | ||
when: galera_manage_users and galera_bootstrap | ||
|
||
|
||
- name: set haproxy (control user) password | ||
shell: | ||
mysql -p{{ galera_root_password }} -uroot -e "USE mysql; INSERT IGNORE INTO user (Host,User) values ('{{ item }}','haproxy'); FLUSH PRIVILEGES;" | ||
when: galera_manage_users and galera_haproxy_user | ||
with_items: "{{ galera_haproxy_hosts }}" | ||
|
||
|
||
- name: galera configuration file | ||
template: | ||
src: cluster.cnf.j2 | ||
dest: /etc/mysql/conf.d/cluster.cnf | ||
owner: root | ||
group: root | ||
mode: 0644 | ||
notify: restart mysql | ||
|
||
|
||
- name: mariadb configuration file | ||
template: | ||
src: my.cnf-default.j2 | ||
dest: /etc/mysql/my.cnf | ||
owner: root | ||
group: root | ||
mode: 0644 | ||
notify: restart mysql | ||
|
||
|
||
- name: debian configuration file | ||
template: | ||
src: debian.cnf.j2 | ||
dest: /etc/mysql/debian.cnf | ||
owner: root | ||
group: root | ||
mode: 0644 | ||
notify: restart mysql | ||
|
||
# percona xtradb scripts | ||
# and services | ||
- name: install xinetd | ||
apt: | ||
pkg: xinetd | ||
state: present | ||
update_cache: yes | ||
cache_valid_time: 3600 | ||
when: galera_check_scripts | ||
|
||
|
||
- name: clustercheck shellscript | ||
template: | ||
src: scripts/clustercheck.j2 | ||
dest: /usr/local/bin/clustercheck | ||
owner: root | ||
group: root | ||
mode: 0755 | ||
when: galera_check_scripts | ||
|
||
|
||
- name: mysqlchk xinetd | ||
template: | ||
src: scripts/mysqlchk.j2 | ||
dest: /etc/xinetd.d/mysqlchk | ||
owner: root | ||
group: root | ||
mode: 0644 | ||
when: galera_check_scripts | ||
notify: restart xinetd | ||
|
||
|
||
- name: add mysqlchk to /etc/services | ||
lineinfile: | ||
dest: /etc/services | ||
regexp: '^mysqlchk ' | ||
line: 'mysqlchk {{ galera_check_scripts_port }}/tcp # MySQL check' | ||
owner: root | ||
group: root | ||
mode: 0644 | ||
when: galera_check_scripts | ||
notify: restart xinetd | ||
|
||
|
||
# To bootstrap a new cluster you need to start the first | ||
# mysqld server with the option --wsrep-new-cluster on the command line | ||
- name: stop servers if not bootstrapped | ||
service: | ||
name: mysql | ||
state: stopped | ||
when: galera_node_bootstrapped.stat.exists == False | ||
|
||
|
||
- name: bootstrap new cluster master | ||
shell: mysqld --wsrep-new-cluster & | ||
sleep 3 | ||
when: galera_bootstrap and galera_node_bootstrapped.stat.exists == False | ||
|
||
|
||
- name: restart new cluster master | ||
service: | ||
name: mysql | ||
state: restarted | ||
when: galera_bootstrap and galera_node_bootstrapped.stat.exists == False | ||
|
||
|
||
- name: restart new added nodes | ||
service: | ||
name: mysql | ||
state: restarted | ||
when: not galera_bootstrap and galera_node_bootstrapped.stat.exists == False | ||
|
||
|
||
- name: create bootstrap file | ||
file: | ||
path: /etc/mysql/galera_node_bootstrapped | ||
state: touch | ||
when: galera_node_bootstrapped.stat.exists == False | ||
|
||
|
Oops, something went wrong.