§ Single-VLAN HA


This document mainly describes how to build a high availability architecture with GreatSQL + VIP in a single-VLAN scenario.

GreatSQL supports binding a dynamic VIP to the read/write node in single-primary mode, making HA switchover more convenient.

The overall architecture is shown below:

Single-VLAN HA solution

§ Enabling the Built-in VIP Plugin

  • Enable the new plugin
plugin_load_add=greatdb_ha.so
1

Or, after starting the database instance, run

INSTALL PLUGIN greatdb_ha SONAME 'greatdb_ha.so';
1

§ New Configuration Parameters

  • Configure to enable the built-in VIP feature
loose-greatdb_ha_enable_mgr_vip = ON
1
  • Configure the VIP to be bound on the Primary node
loose-greatdb_ha_mgr_vip_ip = "172.17.140.250"
1
  • Configure the number of ARP packet broadcasts. After a node binds the floating IP, ARP packets are broadcast to update the ARP cache in the broadcast domain. This parameter specifies the number of broadcasts; the default is 5, and the valid range is 3-20.
loose-greatdb_ha_send_arp_packge_times = 5
1
  • Configure a dedicated communication port for dynamic VIP binding, through which communication data is transmitted. When the status of MGR nodes changes, the Primary node reallocates the VIP binding relationships according to the preset VIP binding relationships and the principle of minimal changes and even distribution, and sends the VIP binding relationships to the Secondary nodes through the dedicated communication port. The Secondary nodes unbind or bind the specified VIP according to the binding relationships.
loose-greatdb_ha_port = 33062
1
  • Configure the name of the network interface to bind. The plugin binds the VIP to the specified interface on the machine where the MGR primary node resides, for example eth0. To prevent the original IP of the interface from being overwritten, after binding, the VIP is actually bound to an interface named eth0:0.
loose-greatdb_ha_mgr_vip_nic = 'eth0'
1
  • Configure the netmask
loose-greatdb_ha_mgr_vip_mask = '255.255.255.0'
1
  • The built-in VIP feature can currently only be enabled in single-primary mode, so the following parameters also need to be set:
loose-group_replication_single_primary_mode = ON
loose-group_replication_enforce_update_everywhere_checks = OFF
1
2
  • The parameter greatdb_ha_mgr_vip_broad is deprecated and no longer used.
  • If the parameters above are not configured, or the configuration format is incorrect, the built-in VIP feature will not work (there is currently no format-checking/error-reporting function for this).
  • In addition to the new parameters above, all other MGR-related parameters follow the regular single-primary MGR configuration requirements.
  • All the parameters above support dynamic online modification.

A complete example of the configuration described above is as follows (every instance in the MGR group needs to be configured):

[mysqld]
#GreatSQL MGR vip
plugin-load-add=greatdb_ha.so
loose-greatdb_ha_enable_mgr_vip = ON
loose-greatdb_ha_mgr_vip_ip = "172.17.140.250"
loose-greatdb_ha_mgr_vip_mask = "255.255.255.0"
loose-greatdb_ha_mgr_vip_nic = "eth0"
loose-greatdb_ha_port = 33062
loose-greatdb_ha_send_arp_packge_times = 5
report_host = "172.17.140.10"
report_port = 3306

#single-primary mode
loose-group_replication_single_primary_mode = ON
loose-group_replication_enforce_update_everywhere_checks = OFF
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

When the VIP bound on the MGR Primary node is manually removed, or an abnormal configuration causes incorrect VIP binding behavior, you can run set global greatdb_ha_force_change_mgr_vip = on on the MGR Primary node to re-fetch the MGR topology and rebind the VIP. After this command is executed, the value of the parameter greatdb_ha_force_change_mgr_vip remains off, which is expected behavior.

§ Startup Notes

Configuring the VIP requires related kernel permissions. There are two ways to obtain the permissions; choose any one of the following (Method 1 is recommended):

  1. [Recommended] Modify the systemd service file and add the AmbientCapabilities parameter, for example:
[Unit]
Description=GreatSQL Server
Documentation=man:mysqld(8)
Documentation=https://dev.mysql.com/doc/refman/8.4/en/using-systemd.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
# some limits
# file size
LimitFSIZE=infinity
# cpu time
LimitCPU=infinity
# virtual memory size
LimitAS=infinity
# open files
LimitNOFILE=65535
# processes/threads
LimitNPROC=65535
# locked memory
LimitMEMLOCK=infinity
# total threads (user+kernel)
TasksMax=infinity
TasksAccounting=false

User=mysql
Group=mysql
Type=notify
TimeoutSec=10
PermissionsStartOnly=true
ExecStartPre=/usr/local/GreatSQL-8.0.32-25-Linux-glibc2.28-x86_64/bin/mysqld_pre_systemd
ExecStart=/usr/local/GreatSQL-8.0.32-25-Linux-glibc2.28-x86_64/bin/mysqld $MYSQLD_OPTS
EnvironmentFile=-/etc/sysconfig/mysql
Restart=on-failure
RestartPreventExitStatus=1
Environment=MYSQLD_PARENT_PID=1
PrivateTmp=false
# Add this line to ensure the MGR VIP feature works
AmbientCapabilities=CAP_NET_ADMIN CAP_NET_RAW
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

Then run systemctl daemon-reload to reload the systemd service and start GreatSQL.

Note: Thanks to community user Fenda for suggesting this method.

  1. Use the setcap command to add the CAP_NET_ADMIN and CAP_NET_RAW capabilities to the mysqld binary. The specific command is as follows:
# This command requires sudo privileges or root
setcap CAP_NET_ADMIN,CAP_NET_RAW+ep /usr/local/GreatSQL-8.0.32-25-Linux-glibc2.28-x86_64/bin/mysqld
1
2

Then load the lib/private subdirectory of the GreatSQL binary package into LD_LIBRARY_PATH:

$ cat /etc/ld.so.conf.d/greatsql.conf

/usr/local/GreatSQL-8.0.32-25-Linux-glibc2.28-x86_64/lib/private
1
2
3

Run ldconfig && ldconfig -p | grep -i libpro to confirm the configuration is correct:

$ ldconfig && ldconfig -p | grep -i 'libprotobuf.so'

	libprotobuf.so.3.19.4 (libc6,x86-64) => /usr/local/GreatSQL-8.0.32-25-Linux-glibc2.28-x86_64/lib/private/libprotobuf.so.3.19.4
1
2
3

After that, start GreatSQL.

  1. [Strongly not recommended] Grant root privileges to the user that starts the mysqld process, for example the mysql user.

Notes

  • It is recommended to manage the GreatSQL service with systemd, or enable sudo permission for the startup user (e.g. mysql) and use sudo to invoke systemd to start the GreatSQL service. This ensures that the mysqld process can obtain kernel permissions and successfully bind the VIP.
  • After adding capabilities to the mysqld binary with setcap, make sure the user logging into the system and the user starting mysqld are the same; otherwise the mysqld process cannot obtain kernel permissions. For example, if you log in as the root user and then start the mysqld process as a regular user (mysql), setcap will not take effect, and binding the VIP will fail with an error.

Scan the QR code to follow our WeChat official account

greatsql-wx