-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgreatsql.yml
More file actions
233 lines (186 loc) · 8.71 KB
/
greatsql.yml
File metadata and controls
233 lines (186 loc) · 8.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
- name: install GreatSQL
hosts: greatsql_dbs
remote_user: root
ignore_errors: yes
vars_files:
- vars.yml
tasks:
- include: check_mysql.yml
- block:
- name: modify selinux config file
lineinfile: dest=/etc/selinux/config regexp='SELINUX=enforcing' line='SELINUX=disabled' backrefs=yes state=present
- name: stop firewalld
command: /usr/bin/systemctl stop firewalld.service
- name: disable firewalld
command: /usr/bin/systemctl disable firewalld.service
- name: install jemalloc jemalloc-devel
raw: yum install -y jemalloc jemalloc-devel
- name: add group mysql
group: name={{mysql_user}} state=present
- name: add user mysql
user: name={{mysql_user}} group={{mysql_user}} shell=/sbin/nologin
- name: create data_dir
file: path={{data_dir}} state=directory owner={{mysql_user}} group={{mysql_user}} mode=0700
- name: extract GreatSQL tarball
unarchive: src={{work_dir}}/{{file_name}} dest={{extract_dir}} mode=755
- name: backup /etc/my.cnf
copy: src={{my_cnf}} dest={{my_cnf}}.orig ignore_errors=True
- name: copy my.cnf
copy: src={{work_dir}}/mysql-support-files/my.cnf dest={{my_cnf}} owner={{mysql_user}} group={{mysql_user}} mode=0644
- name: copy mysqld_pre_systemd
copy: src={{work_dir}}/mysql-support-files/mysqld_pre_systemd dest={{base_dir}}/bin/ owner={{mysql_user}} group={{mysql_user}} mode=0755
- name: replace mysqld_pre_systemd MYSQL_BASEDIR to({{ base_dir }})
replace:
path: "{{base_dir}}/bin/mysqld_pre_systemd"
regexp: '(MYSQL_BASEDIR)=.*'
replace: '\1={{base_dir}}'
- name: replace my.cnf server_id settings
replace:
path: "{{ my_cnf }}"
regexp: '(.*server_id.*)=.*'
replace: '\1= 3306{{ 1024 | random}}'
- name: replace my.cnf group_replication_local_address settings to('{{ inventory_hostname }}:33061')
replace:
path: "{{ my_cnf }}"
regexp: '(.*group_replication_local_address.*)=.*'
replace: '\1= {{ inventory_hostname }}:33061'
- name: replace my.cnf group_replication_group_seeds settings to('{{ mgr_seeds }}')
replace:
path: "{{ my_cnf }}"
regexp: '(.*group_replication_group_seeds.*)=.*'
replace: '\1= {{ mgr_seeds }}'
- name: replace my.cnf report_host settings to('{{ inventory_hostname }}')
replace:
path: "{{ my_cnf }}"
regexp: '(.*report_host.*)=.*'
replace: '\1= {{ inventory_hostname }}'
- name: replace my.cnf basedir to({{ base_dir }})
replace:
path: "{{ my_cnf }}"
regexp: 'basedir.*'
replace: 'basedir = {{ base_dir }}'
- name: replace my.cnf datadir to({{ data_dir }})
replace:
path: "{{ my_cnf }}"
regexp: 'datadir.*'
replace: 'datadir = {{ data_dir }}'
- name: replace my.cnf user to({{ mysql_user }})
replace:
path: "{{ my_cnf }}"
regexp: '^user.*'
replace: 'user = {{ mysql_user }}'
- name: replace my.cnf port to({{ mysql_port }})
replace:
path: "{{ my_cnf }}"
regexp: '^port.*'
replace: 'port = {{ mysql_port }}'
- name: replace single_mode to({{ mgr_single_mode }})
replace:
path: "{{ my_cnf }}"
regexp: '(.*single.*mode.*)=(.*)'
replace: '\1 = {{mgr_single_mode}}'
- name: copy sysconfig/mysql to /etc/sysconfig/mysql
copy: src={{work_dir}}/mysql-support-files/sysconfig/mysql dest=/etc/sysconfig owner=root group=root mode=0644
- name: preload jemalloc
command: /usr/sbin/ldconfig
- name: copy mysql PATH
copy: src={{work_dir}}/mysql-support-files/mysql.sh dest=/etc/profile.d/mysql.sh
- name: replace mysql.sh PATH
replace:
path: /etc/profile.d/mysql.sh
regexp: '(.*PATH.*)=.*'
replace: 'export PATH=$PATH:{{base_dir}}/bin'
- name: copy greatsql.server
copy: src={{work_dir}}/mysql-support-files/greatsql.service dest=/usr/lib/systemd/system/ owner=root group=root mode=0644
- name: replace greatsql.service
replace:
path: /usr/lib/systemd/system/greatsql.service
regexp: '(ExecStartPre=)(.*)(/bin/mysqld.*)'
replace: '\1{{base_dir}}\3'
- name: replace greatsql.service
replace:
path: /usr/lib/systemd/system/greatsql.service
regexp: '(ExecStart=)(.*)(/bin/mysqld.*)'
replace: '\1{{base_dir}}\3'
- name: reload GreatSQL service
command: /usr/bin/systemctl daemon-reload
when: check_mysql_port.stdout == "True" and check_mysql_ps.stdout == "True"
- name: mgr primary
hosts: greatsql_mgr_primary
ignore_errors: yes
vars_files:
- vars.yml
tasks:
- include: check_mysql.yml
- block:
- name: start the GreatSQL service on PRIMARY NODE
command: /usr/bin/systemctl start greatsql
- name: wait for mysqld start
shell: sleep {{ wait_for_start }}
delay: 1
- name: mgr primary init
shell: >
{{ base_dir }}/bin/mysql -uroot -f -S {{ data_dir }}/mysql.sock
-ANse "SET @@SESSION.SQL_LOG_BIN=0;
CREATE USER IF NOT EXISTS {{ mgr_user }} IDENTIFIED WITH mysql_native_password BY '{{ mgr_user_pwd }}';
GRANT REPLICATION SLAVE, BACKUP_ADMIN ON *.* TO {{ mgr_user }};
CHANGE MASTER TO MASTER_USER='{{ mgr_user }}', MASTER_PASSWORD='{{ mgr_user_pwd }}' FOR CHANNEL 'group_replication_recovery';
SET GLOBAL group_replication_local_address = '{{ inventory_hostname }}:33061';
SET GLOBAL group_replication_group_seeds = '{{ mgr_seeds }}';
SET GLOBAL group_replication_bootstrap_group=ON;
START GROUP_REPLICATION;
SET GLOBAL group_replication_bootstrap_group=OFF; "
when: check_mysql_port.stdout == "True" and check_mysql_ps.stdout == "True"
- name: mgr secondary
hosts: greatsql_mgr_secondary
ignore_errors: yes
vars_files:
- vars.yml
tasks:
- include: check_mysql.yml
- block:
- name: start the GreatSQL service on SECONDARY NODE
command: /usr/bin/systemctl start greatsql
- name: wait for mysqld start
shell: sleep {{ wait_for_start }}
delay: 1
- name: mgr secondary init
shell: >
{{ base_dir }}/bin/mysql -uroot -f -S {{ data_dir }}/mysql.sock
-ANse "SET @@SESSION.SQL_LOG_BIN=0;
CREATE USER IF NOT EXISTS {{ mgr_user }} IDENTIFIED WITH mysql_native_password BY '{{ mgr_user_pwd }}';
GRANT REPLICATION SLAVE, BACKUP_ADMIN ON *.* TO {{ mgr_user }};
CHANGE MASTER TO MASTER_USER='{{ mgr_user }}', MASTER_PASSWORD='{{ mgr_user_pwd }}' FOR CHANNEL 'group_replication_recovery';
SET GLOBAL group_replication_local_address = '{{ inventory_hostname }}:33061';
SET GLOBAL group_replication_group_seeds = '{{ mgr_seeds }}';
START GROUP_REPLICATION; "
when: check_mysql_port.stdout == "True" and check_mysql_ps.stdout == "True"
- name: mgr arbitrator
hosts: greatsql_mgr_arbitrator
ignore_errors: yes
vars_files:
- vars.yml
tasks:
- include: check_mysql.yml
- block:
- name: replace my.cnf arbitrator settings
replace:
path: "{{ my_cnf }}"
regexp: '(.*_arbitrator.*)=.*'
replace: '\1= 1'
- name: start the GreatSQL service on ARBITRATOR NODE
command: /usr/bin/systemctl start greatsql
- name: wait for mysqld start
shell: sleep {{ wait_for_start }}
delay: 1
- name: mgr arbitrator init
shell: >
{{ base_dir }}/bin/mysql -uroot -f -S {{ data_dir }}/mysql.sock
-ANse "SET @@SESSION.SQL_LOG_BIN=0;
CREATE USER IF NOT EXISTS {{ mgr_user }} IDENTIFIED WITH mysql_native_password BY '{{ mgr_user_pwd }}';
GRANT REPLICATION SLAVE, BACKUP_ADMIN ON *.* TO {{ mgr_user }};
CHANGE MASTER TO MASTER_USER='{{ mgr_user }}', MASTER_PASSWORD='{{ mgr_user_pwd }}' FOR CHANNEL 'group_replication_recovery';
SET GLOBAL group_replication_local_address = '{{ inventory_hostname }}:33061';
SET GLOBAL group_replication_group_seeds = '{{ mgr_seeds }}';
START GROUP_REPLICATION; "
when: check_mysql_port.stdout == "True" and check_mysql_ps.stdout == "True"