ansible one click installation of GreatSQL and construction of MGR cluster

Posted by GrayFox12 on Thu, 13 Jan 2022 03:11:48 +0100

  • The original content of GreatSQL community cannot be used without authorization. Please contact Xiaobian and indicate the source for reprint.

Use ansible one click to install GreatSQL and complete MGR deployment.

This time introduces how to use ansible to install GreatSQL and complete MGR deployment.

The running environment introduced in this article is CentOS 7.9:

[root@greatsql ~]# cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)

[root@greatsql ~]# uname -a
Linux greatsql 3.10.0-1160.11.1.el7.x86_64 #1 SMP Fri Dec 18 16:34:56 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

1. Install ansbile

Simply install ansible using yum or up2date:

[root@greatsql ~]# yum install -y ansible

Check the version number and confirm that the installation is successful:

[root@greatsql ~]# ansible --version
ansible 2.9.21
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.5 (default, Apr  2 2020, 13:16:51) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)]

That's OK.

2. Configure ansible

Modify the / etc/ansible/hosts file to add the IP address of the server where GreatSQL is to be installed, for example:

[greatsql_dbs:children]
greatsql_mgr_primary
greatsql_mgr_secondary

[greatsql_mgr_primary]
172.16.16.10
[greatsql_mgr_secondary]
172.16.16.11
172.16.16.12

If it is installed on this machine, you can directly fill in the intranet IP address or loopback address (127.0.0.1) of this machine.

The above host list is divided into two groups. One is the group greatsql selected as the MGR PRIMARY node_ mgr_ Primary, there is only one host.

The other group selects greatsql as the SECONDARY node_ mgr_ SECONDARY, there are two hosts.

The two groups can also be merged to form a new group, greatsql_dbs.

3. Build ssh trust

For simplicity, establish ssh trust directly to facilitate ansible one click installation.

First generate ssh key:

[root@greatsql ~]# ssh-keygen

Using the default value, when prompted for passphrase, press enter to use an empty passphrase.

Copy ssh key to the target server:

[root@greatsql ~]# ssh-copy-id root@172.16.16.10

Press the prompt to enter the password. After the test is completed, ssh login will not be prompted for the password. If it is installed on the local machine, ssh copy ID should also be executed on the local machine.

Or manually copy the ssh key to the remote host and write ~ / ssh/authorized_ In the keys file (be careful not to break or break lines).

4. Test ansible

Execute an instruction at will to test whether ansibile can connect to the remote host:

[root@greatsql ~]# ansible greatsql_dbs -a "uptime"
172.16.16.10 | CHANGED | rc=0 >>
 15:29:46 up 250 days, 19:40,  2 users,  load average: 0.04, 0.08, 0.07
172.16.16.11 | CHANGED | rc=0 >>
 15:29:46 up 303 days, 17:57,  3 users,  load average: 0.10, 0.13, 0.13
172.16.16.12 | CHANGED | rc=0 >>
 15:29:47 up 194 days, 18:08,  2 users,  load average: 0.07, 0.13, 0.10

This means that it can work normally.

5. Use ansible to automatically install GreatSQL

5.1 modify / etc/hosts to set the correct host name

Modify the / etc/hosts files on several servers and add the correct host name configuration:

[root@greatsql ~]# cat /etc/hosts

172.16.16.10 mgr1
172.16.16.11 mgr2
172.16.16.12 mgr3

5.2 download and unzip the greatsql ansible installation package

Open the greatsql ansible project home page: https://gitee.com/GreatSQL/GreatSQL-Ansible

Find the "distribution" on the right side of the page, enter, select the binary package "GreatSQL-8.0.23-14-Linux.x86_64-ansible-v0.1-alpha.tar.xz" and download it to the server:

[root@greatsql ~]# cd /opt/greatsql/; wget -c "https://gitee.com/xxx/GreatSQL-8.0.23-14-Linux.x86_64-ansible-v0.1-alpha.tar.xz"

[root@greatsql ~]# tar zxf GreatSQL-8.0.23-14-Linux.x86_64-ansible-v0.1-alpha.tar.xz

Special note: the above installation package is my internal test version, not the officially released version.

After decompression, you can see that in addition to greatsql-8.0.23-14-linux x86_ 64.tar. In addition to the XZ installation package, there are files related to the great SQL ansible one click installation:

[root@greatsql ~]# ls -la
-rw-r--r-- 1 root root      327 Jul 13 11:26 check_mysql.yml
-rw-r--r-- 1 root root 15431496 Jul 13 12:00 GreatSQL-8.0.23-14-Linux.x86_64-ansible-v0.1-alpha.tar.xz
-rw-r--r-- 1 root root 15428212 Jul  7 12:43 GreatSQL-8.0.23-14-Linux.x86_64.tar.xz
-rw-r--r-- 1 root root     4393 Jul  7 15:33 greatsql.yml
-rw-r--r-- 1 root root      357 Jul  7 15:08 vars.yml

The functions of several documents are introduced as follows:

  • GreatSQL-8.0.23-14-Linux.x86_64.tar.xz, greatsql binary installation package.
  • greatsql.yml, ansible one click installation script.
  • check_mysql.yml, MySQL process, port pre check script.
  • vars.yml, a script that defines some variables. Some of the variable names need to be modified to adapt to their different installation environments.

5.3 using ansible to install GreatSQL

Before starting execution, you need to confirm vars Do you want to adjust the following parameters in the YML file:

work_dir: /opt/greatsql
extract_dir: /usr/local
data_dir: /data/GreatSQL
file_name: GreatSQL-8.0.23-14-Linux.x86_64.tar.xz
base_dir: /usr/local/GreatSQL-8.0.23-14-Linux.x86_64
my_cnf: /etc/my.cnf
mysql_user: mysql
mysql_port: 3306
mgr_user: repl
mgr_user_pwd: repl4MGR
mgr_seeds: '172.16.16.7:33061,172.16.16.10:33061,172.16.16.16:33061'
wait_for_start: 60

The following is an explanation of these parameters:

Execute the following commands to complete the installation and initialization of GreatSQL, join systemd service, MGR initialization and other work with one click:

[root@greatsql ~]# ansible-playbook ./greatsql.yml

5.4 check operation process output

During installation, check whether the mysqld process is running or whether there are other services on port 3306.

If so, the output may be as follows:

PLAY [install GreatSQL] *****************************************************************************************************************************

TASK [Gathering Facts] ******************************************************************************************************************************
ok: [172.16.16.10]
ok: [172.16.16.11]
ok: [172.16.16.12]

TASK [check mysql port] *****************************************************************************************************************************
changed: [172.16.16.10]
changed: [172.16.16.11]
changed: [172.16.16.12]

TASK [check mysql processor] ************************************************************************************************************************
changed: [172.16.16.10]
changed: [172.16.16.11]
changed: [172.16.16.12]

TASK [modify selinux config file] *******************************************************************************************************************
skipping: [172.16.16.10]
skipping: [172.16.16.11]
skipping: [172.16.16.12]

See the words skipping and skipped=N. If the installation is normal, the following contents will be output:

PLAY [install GreatSQL] *****************************************************************************************************************************

TASK [Gathering Facts] ******************************************************************************************************************************
ok: [172.16.16.10]
ok: [172.16.16.11]
ok: [172.16.16.12]

TASK [check mysql port] *****************************************************************************************************************************
changed: [172.16.16.10]
changed: [172.16.16.11]
changed: [172.16.16.12]
...
PLAY RECAP ******************************************************************************************************************************************
172.16.16.10               : ok=26   changed=13   unreachable=0    failed=0    skipped=0    rescued=0    ignored=0
172.16.16.11               : ok=26   changed=13   unreachable=0    failed=0    skipped=0    rescued=0    ignored=0
172.16.16.12               : ok=26   changed=13   unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

5.5 check the installation results

There are ok and skipped=0 words, which means that they are executed normally. At this time, the installation should have been successful. Check:

[root@greatsql ~]# systemctl status greatsql
● greatsql.service - GreatSQL Server
   Loaded: loaded (/usr/lib/systemd/system/greatsql.service; disabled; vendor preset: disabled)
   Active: active (running) since Tue 2021-07-06 20:55:33 CST; 45s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 31320 ExecStartPre=/usr/local/GreatSQL-8.0.23-14-Linux.x86_64/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 31348 (mysqld)
   Status: "Server is operational"
   CGroup: /system.slice/greatsql.service
           └─31348 /usr/local/GreatSQL-8.0.23-14-Linux.x86_64/bin/mysqld

Jul 06 20:55:31 greatsql systemd[1]: Starting GreatSQL Server...
Jul 06 20:55:33 greatsql systemd[1]: Started GreatSQL Server.

Check MGR service operation status:

[root@GreatSQL][(none)]> select * from performance_schema.replication_group_members;
+---------------------------+--------------------------------------+-------------+-------------+--------------+-------------+----------------+
| CHANNEL_NAME              | MEMBER_ID                            | MEMBER_HOST | MEMBER_PORT | MEMBER_STATE | MEMBER_ROLE | MEMBER_VERSION |
+---------------------------+--------------------------------------+-------------+-------------+--------------+-------------+----------------+
| group_replication_applier | ac24eab8-def4-11eb-a5e8-525400e802e2 |      mgr3   |        3306 | ONLINE       | SECONDARY   | 8.0.23         |
| group_replication_applier | ac275d97-def4-11eb-9e49-525400fb993a |      mgr2   |        3306 | ONLINE       | SECONDARY   | 8.0.23         |
| group_replication_applier | ac383458-def4-11eb-bf1a-5254002eb6d6 |      mgr1   |        3306 | ONLINE       | PRIMARY     | 8.0.23         |
+---------------------------+--------------------------------------+-------------+-------------+--------------+-------------+----------------+

The above ansible script has been uploaded to the gitee warehouse. See: https://gitee.com/GreatSQL/GreatSQL-Ansible.

The corresponding beta binary package can also be downloaded here: https://gitee.com/GreatSQL/GreatSQL-Ansible/releases.

Done, done.

The level is limited. Please help readers to see what can be optimized in the ansible installation script. Thank you.

Enjoy GreatSQL & Ansible 😃

Article recommendation:

GreatSQL MGR FAQ
https://mp.weixin.qq.com/s/J6wkUpGXw3YkyEUJXiZ9xA

Wan Da #12, how can the MGR cluster automatically select the master without manual intervention
https://mp.weixin.qq.com/s/07o1poO44zwQIvaJNKEoPA

"2021 data technology Carnival · ON LINE": evolution and practice of MySQL high availability architecture
https://mp.weixin.qq.com/s/u7k99y6i7riq7ScYs7ySnA

Packet capture analysis of where an sql statement is slow
https://mp.weixin.qq.com/s/AYibbzl860D90rOeyjB6IQ

Wan Da #15, what are the conditions that may cause the MGR service to fail to start
https://mp.weixin.qq.com/s/inSGpd0Q_XIl2Mb-VsvNsA

Technology sharing | why MGR consistency mode does not recommend AFTER
https://mp.weixin.qq.com/s/rNeq479RNsklY1BlfKOsYg

About GreatSQL

GreatSQL is a MySQL branch maintained by Wanli database. It focuses on improving the reliability and performance of MGR and supports the parallel query feature of InnoDB. It is a branch version of MySQL suitable for financial applications.

Gitee:
https://gitee.com/GreatSQL/GreatSQL

GitHub:
https://github.com/GreatSQL/GreatSQL

Bilibili:
https://space.bilibili.com/1363850082/video

Wechat & QQ group:
You can search and add GreatSQL community assistant wechat friends, send verification information "add group" to join GreatSQL/MGR communication wechat group

QQ group: 533341697
Wechat assistant: wanlidbc

This article is composed of blog one article multi posting platform OpenWrite release!