1 Star 0 Fork 6

MapLover/GreatSQL-Ansible

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
greatsql.yml 8.34 KB
一键复制 编辑 原始数据 按行查看 历史
- 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
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
replace:
path: "{{ my_cnf }}"
regexp: '(.*group_replication_local_address.*)=.*'
replace: '\1= {{ inventory_hostname }}:33061'
- name: replace my.cnf group_replication_group_seeds settings
replace:
path: "{{ my_cnf }}"
regexp: '(.*group_replication_group_seeds.*)=.*'
replace: '\1= {{ mgr_seeds }}'
- name: replace my.cnf report_host settings
replace:
path: "{{ my_cnf }}"
regexp: '(.*report_host.*)=.*'
replace: '\1= {{ inventory_hostname }}'
- name: replace my.cnf basedir
replace:
path: "{{ my_cnf }}"
regexp: 'basedir.*'
replace: 'basedir = {{ base_dir }}'
- name: replace my.cnf datadir
replace:
path: "{{ my_cnf }}"
regexp: 'datadir.*'
replace: 'datadir = {{ data_dir }}'
- name: replace my.cnf user
replace:
path: "{{ my_cnf }}"
regexp: '^user.*'
replace: 'user = {{ mysql_user }}'
- name: replace my.cnf port
replace:
path: "{{ my_cnf }}"
regexp: '^port.*'
replace: 'port = {{ mysql_port }}'
- 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"
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/MapLover/GreatSQL-Ansible.git
git@gitee.com:MapLover/GreatSQL-Ansible.git
MapLover
GreatSQL-Ansible
GreatSQL-Ansible
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385