* GreatSQL社区原创内容未经授权不得随意使用,转载请联系小编并注明来源。

在上一篇中讲到了如何使用 dbops 部署 GreatSQL 单机架构,这篇中将介绍如何使用 dbops 部署主从架构。
环境介绍
本次部署所使用的操作系统为麒麟 V10 系统,以下是系统的详细信息:
$ cat etc/*release
Kylin Linux Advanced Server release V10 (Sword)
NAME="Kylin Linux Advanced Server"
VERSION="V10 (Sword)"
ID="kylin"
VERSION_ID="V10"
PRETTY_NAME="Kylin Linux Advanced Server V10 (Sword)"
ANSI_COLOR="0;31"
Kylin Linux Advanced Server release V10 (Sword)
$ uname -a
Linux gip 4.19.90-24.4.v2101.ky10.x86_64 #1 SMP Mon May 24 12:14:55 CST 2021 x86_64 x86_64 x86_64 GNU/Linux
环境 Glibc 版本信息为
$ ldd --version
ldd (GNU libc) 2.28
使用的 dbops 版本为
dbops.1.10.20250329 release
在此文章撰写时,芬达老师对 dbops 进行了更新,所以此篇采用新版本安装部署。
使用的 GreatSQL 版本为
GreatSQL-8.0.32-27 minimal
架构如下:

下载 dbops
从 gitee 下载最新版本 dbops
dbops:https://gitee.com/fanderchan/dbops/releases
$ cd /usr/local
$ wget https://gitee.com/fanderchan/dbops/releases/download/dbops.1.10.20250329/dbops.1.10.20250329-Linux-x86_64.tar.gz
下载完成后,对 dbops 进行解压:
$ tar -xvzf dbops.1.10.20250329-Linux-x86_64.tar.gz
安装 Ansible
dbops 自带绿色版 Ansible,dbops 的核心依赖于 Ansible,执行此命令用于注册:
$ cd portable-ansible-v0.5.0-py3
$ sh setup_portable_ansible.sh
$ source ~/.bashrc
最后检查下 Ansible 是否安装成功:
$ ansible --version
ansible 2.10.5
上传 GreatSQL 安装包
由于 dbops 限制,建议选择 GreatSQL-8.0.32-27-Linux-glibc2.17-x86_64 这个 Linux Generic 通用包。
注意,由于 dbops 限制,只能选择 glibc2.17 和 x86_64 以及 minimal 版本
# 需要放到 downloads 文件夹下
$ cd /usr/local/dbops/mysql_ansible/downloads
$ wget https://product.greatdb.com/GreatSQL-8.0.32-27/GreatSQL-8.0.32-27-Linux-glibc2.17-x86_64-minimal.tar.xz
minimal版本是对二进制文件执行strip操作,所以文件尺寸较小,功能上与正常版本一样
编辑配置清单
$ vim usr/local/dbops/mysql_ansible/inventory/hosts.ini
修改内容如下:
[dbops_mysql]
192.168.139.37 ansible_user=root ansible_ssh_pass="'****'"
192.168.139.38 ansible_user=root ansible_ssh_pass="'****'"
192.168.139.39 ansible_user=root ansible_ssh_pass="'****'"
# IP地址 ansible_user=root ansible_ssh_pass="'你的密码'"
[all:vars]
#ansible_python_interpreter=/usr/bin/python3
注意!密码需要单引号包围,修改时不要漏掉。
验证服务器的连通性:
$ cd /usr/local/dbops/mysql_ansible/playbooks
$ ansible all -m ping
192.168.139.37 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": false,
"ping": "pong"
}
配置公共参数文件
$ vim usr/local/dbops/mysql_ansible/playbooks/common_config.yml
修改数据库版本以及端口:
## In most cases, just adjust these two parameters.
mysql_version: "8.0.32-27"
mysql_port: 3306
修改数据库类型为 “greatsql”:
## DB TYPE,suport mysql,percona,greatsql
db_type: greatsql
已经手动下载安装包,可以关闭此参数,修改为 false 即可:
fcs_auto_download_mysql: false # only support mysql. percona, greatsql pls download yourself first.
若有需要修改的,例如 my.cnf 配置文件,数据库初始密码、初始用户,都可在 common_config.yml 公共参数文件中修改。
修改 Playbook 参数
$ vim usr/local/dbops/mysql_ansible/playbooks/vars/var_master_slave.yml
修改主从库IP以及主从复制账号可信网段:
# vars loading order: common_config -> this file
master_ip: 192.168.139.37
slave_ips:
- 192.168.139.38
- 192.168.139.39
sub_nets: 192.168.139.%
sub_nets参数:设置 GreatSQL 可信网段、可信域、可信IP。
执行 GreatSQL 安装
执行安装 GreatSQL 主从架构
$ cd /usr/local/dbops/mysql_ansible/playbooks
$ ansible-playbook master_slave.yml
等待一会儿会打印如下信息
"msg": [
"Hosts to be affected by Deploy master-slave MySQL server using binary installation: 192.168.139.37, 192.168.139.38, 192.168.139.39",
"DB type: greatsql",
"MySQL port: 3306",
"MySQL version: 8.0.32-27",
"Server specs: auto",
"Roles to be executed: ../roles/pre_check_and_set, ../roles/mysql_server, ../roles/make_replication",
"Master IP: 192.168.139.37",
"Slave IPs: 192.168.139.38, 192.168.139.39",
"mycnf_dir: database/greatsql/etc/3306",
"datadir: database/greatsql/data/3306",
"tmpdir: database/greatsql/tmp/3306",
"binlog_dir: database/greatsql/log/binlog/3306",
"relaylog_dir: database/greatsql/log/relaylog/3306",
"redolog_dir: database/greatsql/log/redolog/3306",
"socket_dir: database/greatsql/data/3306",
"mysqlx_socket_dir: database/greatsql/data/3306"
]
可以看到上面的信息,安装时请确认无误后,输入 “confirm” 确认安装。如果想修改,可按 Ctrl+C 退出安装,再修改文件 common_config.yml
稍等片刻,GreatSQL 就部署完成。
[Prompt user for confirmation]
This will perform Deploy master-slave MySQL server using binary installation on the displayed hosts. Please type 'confirm' to continue or press Ctrl+C to cancel.:
登入 GreatSQL 检查
$ mysql -uadmin -h127.0.0.1 -P3306 -pDbops@8888 -e "select @@version"
+-----------+
| @@version |
+-----------+
| 8.0.32-27 |
+-----------+
若没有修改安装密码,初始为Dbops@8888
,请用户在安装后自行修改默认密码。
也可以使用快速登录,db+设置的端口号:
$ su mysql
$ db3306
(gip:3306)admin@localhost-14:42:33 [(none)]>SELECT @VERSION;
+--------------------+
| @VERSION |
+--------------------+
| NULL |
+--------------------+
1 row in set (0.00 sec)
检查下主从情况:
-- MASTER 节点
(gip:3306)admin@localhost-14:41:39 [(none)]>SHOWMASTERSTATUS;
+------------------+----------+--------------+------------------+------------------------------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+------------------------------------------+
| mysql-bin.000002 | 699 | | | 56886625-230f-11f0-aaf0-00163e85a203:1-2 |
+------------------+----------+--------------+------------------+------------------------------------------+
1 row in set (0.00 sec)
-- SLAVE 38 节点
(gip:3306)admin@localhost-15:11:29 [(none)]>SHOWSLAVESTATUS\G
*************************** 1.row ***************************
Slave_IO_State: Waiting formasterto send event
Master_Host: 192.168.139.37
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000002
Read_Master_Log_Pos: 699
Relay_Log_File: relay-bin.000002
Relay_Log_Pos: 915
Relay_Master_Log_File: mysql-bin.000002
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
...... -- 下方省略
-- SLAVE 39 节点
(gip:3306)admin@localhost-15:15:18 [(none)]>SHOWSLAVESTATUS\G
*************************** 1.row ***************************
Slave_IO_State: Waiting formasterto send event
Master_Host: 172.17.140.136
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000002
Read_Master_Log_Pos: 699
Relay_Log_File: relay-bin.000002
Relay_Log_Pos: 915
Relay_Master_Log_File: mysql-bin.000002
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
...... -- 下方省略
至此,麒麟系统下 GreatSQL 主从架构安装已顺利完成:D

在上一篇中讲到了如何使用 dbops 部署 GreatSQL 单机架构,这篇中将介绍如何使用 dbops 部署主从架构。
环境介绍
本次部署所使用的操作系统为麒麟 V10 系统,以下是系统的详细信息:
$ cat etc/*release
Kylin Linux Advanced Server release V10 (Sword)
NAME="Kylin Linux Advanced Server"
VERSION="V10 (Sword)"
ID="kylin"
VERSION_ID="V10"
PRETTY_NAME="Kylin Linux Advanced Server V10 (Sword)"
ANSI_COLOR="0;31"
Kylin Linux Advanced Server release V10 (Sword)
$ uname -a
Linux gip 4.19.90-24.4.v2101.ky10.x86_64 #1 SMP Mon May 24 12:14:55 CST 2021 x86_64 x86_64 x86_64 GNU/Linux
环境 Glibc 版本信息为
$ ldd --version
ldd (GNU libc) 2.28
使用的 dbops 版本为
dbops.1.10.20250329 release
在此文章撰写时,芬达老师对 dbops 进行了更新,所以此篇采用新版本安装部署。
使用的 GreatSQL 版本为
GreatSQL-8.0.32-27 minimal
架构如下:

下载 dbops
从 gitee 下载最新版本 dbops
dbops:https://gitee.com/fanderchan/dbops/releases
$ cd /usr/local
$ wget https://gitee.com/fanderchan/dbops/releases/download/dbops.1.10.20250329/dbops.1.10.20250329-Linux-x86_64.tar.gz
下载完成后,对 dbops 进行解压:
$ tar -xvzf dbops.1.10.20250329-Linux-x86_64.tar.gz
安装 Ansible
dbops 自带绿色版 Ansible,dbops 的核心依赖于 Ansible,执行此命令用于注册:
$ cd portable-ansible-v0.5.0-py3
$ sh setup_portable_ansible.sh
$ source ~/.bashrc
最后检查下 Ansible 是否安装成功:
$ ansible --version
ansible 2.10.5
上传 GreatSQL 安装包
由于 dbops 限制,建议选择 GreatSQL-8.0.32-27-Linux-glibc2.17-x86_64 这个 Linux Generic 通用包。
注意,由于 dbops 限制,只能选择 glibc2.17 和 x86_64 以及 minimal 版本
# 需要放到 downloads 文件夹下
$ cd /usr/local/dbops/mysql_ansible/downloads
$ wget https://product.greatdb.com/GreatSQL-8.0.32-27/GreatSQL-8.0.32-27-Linux-glibc2.17-x86_64-minimal.tar.xz
minimal版本是对二进制文件执行strip操作,所以文件尺寸较小,功能上与正常版本一样
编辑配置清单
$ vim usr/local/dbops/mysql_ansible/inventory/hosts.ini
修改内容如下:
[dbops_mysql]
192.168.139.37 ansible_user=root ansible_ssh_pass="'****'"
192.168.139.38 ansible_user=root ansible_ssh_pass="'****'"
192.168.139.39 ansible_user=root ansible_ssh_pass="'****'"
# IP地址 ansible_user=root ansible_ssh_pass="'你的密码'"
[all:vars]
#ansible_python_interpreter=/usr/bin/python3
注意!密码需要单引号包围,修改时不要漏掉。
验证服务器的连通性:
$ cd /usr/local/dbops/mysql_ansible/playbooks
$ ansible all -m ping
192.168.139.37 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": false,
"ping": "pong"
}
配置公共参数文件
$ vim usr/local/dbops/mysql_ansible/playbooks/common_config.yml
修改数据库版本以及端口:
## In most cases, just adjust these two parameters.
mysql_version: "8.0.32-27"
mysql_port: 3306
修改数据库类型为 “greatsql”:
## DB TYPE,suport mysql,percona,greatsql
db_type: greatsql
已经手动下载安装包,可以关闭此参数,修改为 false 即可:
fcs_auto_download_mysql: false # only support mysql. percona, greatsql pls download yourself first.
若有需要修改的,例如 my.cnf 配置文件,数据库初始密码、初始用户,都可在 common_config.yml 公共参数文件中修改。
修改 Playbook 参数
$ vim usr/local/dbops/mysql_ansible/playbooks/vars/var_master_slave.yml
修改主从库IP以及主从复制账号可信网段:
# vars loading order: common_config -> this file
master_ip: 192.168.139.37
slave_ips:
- 192.168.139.38
- 192.168.139.39
sub_nets: 192.168.139.%
sub_nets参数:设置 GreatSQL 可信网段、可信域、可信IP。
执行 GreatSQL 安装
执行安装 GreatSQL 主从架构
$ cd /usr/local/dbops/mysql_ansible/playbooks
$ ansible-playbook master_slave.yml
等待一会儿会打印如下信息
"msg": [
"Hosts to be affected by Deploy master-slave MySQL server using binary installation: 192.168.139.37, 192.168.139.38, 192.168.139.39",
"DB type: greatsql",
"MySQL port: 3306",
"MySQL version: 8.0.32-27",
"Server specs: auto",
"Roles to be executed: ../roles/pre_check_and_set, ../roles/mysql_server, ../roles/make_replication",
"Master IP: 192.168.139.37",
"Slave IPs: 192.168.139.38, 192.168.139.39",
"mycnf_dir: database/greatsql/etc/3306",
"datadir: database/greatsql/data/3306",
"tmpdir: database/greatsql/tmp/3306",
"binlog_dir: database/greatsql/log/binlog/3306",
"relaylog_dir: database/greatsql/log/relaylog/3306",
"redolog_dir: database/greatsql/log/redolog/3306",
"socket_dir: database/greatsql/data/3306",
"mysqlx_socket_dir: database/greatsql/data/3306"
]
可以看到上面的信息,安装时请确认无误后,输入 “confirm” 确认安装。如果想修改,可按 Ctrl+C 退出安装,再修改文件 common_config.yml
稍等片刻,GreatSQL 就部署完成。
[Prompt user for confirmation]
This will perform Deploy master-slave MySQL server using binary installation on the displayed hosts. Please type 'confirm' to continue or press Ctrl+C to cancel.:
登入 GreatSQL 检查
$ mysql -uadmin -h127.0.0.1 -P3306 -pDbops@8888 -e "select @@version"
+-----------+
| @@version |
+-----------+
| 8.0.32-27 |
+-----------+
若没有修改安装密码,初始为
Dbops@8888
,请用户在安装后自行修改默认密码。
也可以使用快速登录,db+设置的端口号:
$ su mysql
$ db3306
(gip:3306)admin@localhost-14:42:33 [(none)]>SELECT @VERSION;
+--------------------+
| @VERSION |
+--------------------+
| NULL |
+--------------------+
1 row in set (0.00 sec)
检查下主从情况:
-- MASTER 节点
(gip:3306)admin@localhost-14:41:39 [(none)]>SHOWMASTERSTATUS;
+------------------+----------+--------------+------------------+------------------------------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+------------------------------------------+
| mysql-bin.000002 | 699 | | | 56886625-230f-11f0-aaf0-00163e85a203:1-2 |
+------------------+----------+--------------+------------------+------------------------------------------+
1 row in set (0.00 sec)
-- SLAVE 38 节点
(gip:3306)admin@localhost-15:11:29 [(none)]>SHOWSLAVESTATUS\G
*************************** 1.row ***************************
Slave_IO_State: Waiting formasterto send event
Master_Host: 192.168.139.37
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000002
Read_Master_Log_Pos: 699
Relay_Log_File: relay-bin.000002
Relay_Log_Pos: 915
Relay_Master_Log_File: mysql-bin.000002
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
...... -- 下方省略
-- SLAVE 39 节点
(gip:3306)admin@localhost-15:15:18 [(none)]>SHOWSLAVESTATUS\G
*************************** 1.row ***************************
Slave_IO_State: Waiting formasterto send event
Master_Host: 172.17.140.136
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000002
Read_Master_Log_Pos: 699
Relay_Log_File: relay-bin.000002
Relay_Log_Pos: 915
Relay_Master_Log_File: mysql-bin.000002
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
...... -- 下方省略
至此,麒麟系统下 GreatSQL 主从架构安装已顺利完成:D
《用三分钟学会一个MySQL知识》
GreatSQL数据库是一款开源免费数据库,可在普通硬件上满足金融级应用场景,具有高可用、高性能、高兼容、高安全等特性,可作为MySQL或Percona Server for MySQL的理想可选替换。
⏩GitHub : https://github.com/GreatSQL/
🆙BiliBili : https://space.bilibili.com/1363850082

(对文章有疑问或见解可去社区官网提出哦~)
![]() | ![]() |






