dbdeployer MySQL沙盒部署详解
一、工具介绍
- 前几日用
mysql-sandbox来搭建MySQL8.0新版本时发现用不了,提示需要使用dbdeployer才行,瞬间觉得mysql-sandbox不香了,只好咬咬牙来熟悉dbdeployer了。 dbdeployer是使用go语言重构的sandbox,和sandbox同一个作者。- 当然,
dbdeployer延续了sandbox所有功能。可实现一键部署不同架构、不同版本的数据库环境。如,MySQL 主从复制、GTID 模式复制、MySQL 组复制(单主模式、多主模式等) - 完整的数据库类型支持及版本,可在安装完 dbdeployer 后使用
dbdeployer admin capabilities命令进行查看,以下是当前已支持数据库及组件类型
- -- pxc (Percona XtraDB Cluster)
- -- mysql-shell
- -- mysql (MySQL server)
- -- percona (Percona Server)
- -- mariadb
- -- tidb (TiDB isolated server)
- -- ndb (MySQL NDB Cluster)
二、工具安装
- OS:
centos8 - dbdeployer:
1.54.0 - mysql:
8.0.20
2.1 dbdeployer工具下载
直接到github下载release包即可:
https://github.com/datacharmer/dbdeployer/releases
2.2 解压
软件解压后实际只有一个单独的编译好的可执行文件
tar -zxvf dbdeployer-1.54.0.linux.tar.gz
2.3 赋予可执行权限
chmod +x dbdeployer-1.54.0.linux
2.4 移动到系统可执行目录下方便使用
mv dbdeployer-1.54.0.linux /usr/local/bin/dbdeployer
2.5 验证是否可以使用
[root@db01 tmp]# dbdeployer --version
dbdeployer version 1.54.0
[root@db01 tmp]# dbdeployer --help
dbdeployer makes MySQL server installation an easy task.
Runs single, multiple, and replicated sandboxes.
Usage:
dbdeployer [command]
Available Commands:
admin sandbox management tasks
cookbook Shows dbdeployer samples
defaults tasks related to dbdeployer defaults
delete delete an installed sandbox
delete-binaries delete an expanded tarball
deploy deploy sandboxes
downloads Manages remote tarballs
export Exports the command structure in JSON format
global Runs a given command in every sandbox
help Help about any command
import imports one or more MySQL servers into a sandbox
info Shows information about dbdeployer environment samples
init initializes dbdeployer environment
sandboxes List installed sandboxes
unpack unpack a tarball into the binary directory
update Gets dbdeployer newest version
usage Shows usage of installed sandboxes
use uses a sandbox
versions List available versions
Flags:
--config string configuration file (default "/root/.dbdeployer/config.json")
-h, --help help for dbdeployer
--sandbox-binary string Binary repository (default "/root/opt/mysql")
--sandbox-home string Sandbox deployment directory (default "/root/sandboxes")
--shell-path string Which shell to use for generated scripts (default "/usr/bin/bash")
--skip-library-check Skip check for needed libraries (may cause nasty errors)
-v, --version version for dbdeployer
Use "dbdeployer [command] --help" for more information about a command.
2.6 初始化环境
安装dbdeployer之后,可以立即使用以下命令为操作做好准备的环境,此命令会创建必要的目录,然后下载最新的MySQL二进制文件,在默认的位置解压它们。
dbdeployer init
三、基本使用
3.1 自行下载MySQL并解压
访问 https://downloads.mysql.com/archives/community/ 可下载各不同的MySQL
dbdeployer unpack /tmp/mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz
3.2 使用dbdeployer工具下载MySQL并解压
3.2.1 查看dbdeployer工具支持下载的软件包
[root@mysql8 ~]# dbdeployer downloads list
Available tarballs ()
name OS version flavor size minimal
---------------------------------------------------------------- ------- --------- ------------- -------- ---------
tidb-master-linux-amd64.tar.gz Linux 3.0.0 tidb 26 MB
mysql-8.0.16-linux-glibc2.12-x86_64.tar.xz Linux 8.0.16 mysql 461 MB
mysql-8.0.16-linux-x86_64-minimal.tar.xz Linux 8.0.16 mysql 44 MB Y
mysql-5.7.27-linux-glibc2.12-x86_64.tar.gz Linux 5.7.27 mysql 645 MB
mysql-8.0.17-linux-glibc2.12-x86_64.tar.xz Linux 8.0.17 mysql 480 MB
mysql-8.0.17-linux-x86_64-minimal.tar.xz Linux 8.0.17 mysql 45 MB Y
mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz Linux 5.7.26 mysql 645 MB
mysql-5.6.44-linux-glibc2.12-x86_64.tar.gz Linux 5.6.44 mysql 329 MB
mysql-5.5.62-linux-glibc2.12-x86_64.tar.gz Linux 5.5.62 mysql 199 MB
mysql-8.0.15-linux-glibc2.12-x86_64.tar.xz Linux 8.0.15 mysql 376 MB
mysql-8.0.13-linux-glibc2.12-x86_64.tar.xz Linux 8.0.13 mysql 394 MB
mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz Linux 5.7.25 mysql 645 MB
mysql-5.6.43-linux-glibc2.12-x86_64.tar.gz Linux 5.6.43 mysql 329 MB
mysql-5.5.61-linux-glibc2.12-x86_64.tar.gz Linux 5.5.61 mysql 199 MB
mysql-5.1.73-linux-x86_64-glibc23.tar.gz Linux 5.1.73 mysql 134 MB
mysql-5.0.96.tar.xz Linux 5.0.96 mysql 5.5 MB Y
mysql-5.1.72.tar.xz Linux 5.1.72 mysql 10 MB Y
mysql-5.5.61.tar.xz Linux 5.5.61 mysql 6.6 MB Y
mysql-5.5.62.tar.xz Linux 5.5.62 mysql 6.6 MB Y
mysql-5.6.43.tar.xz Linux 5.6.43 mysql 9.0 MB Y
mysql-5.6.44.tar.xz Linux 5.6.44 mysql 9.1 MB Y
mysql-5.7.25.tar.xz Linux 5.7.25 mysql 23 MB Y
mysql-5.7.26.tar.xz Linux 5.7.26 mysql 23 MB Y
mysql-5.0.96-linux-x86_64-glibc23.tar.gz Linux 5.0.96 mysql 127 MB
mysql-4.1.22.tar.xz Linux 4.1.22 mysql 4.6 MB Y
mysql-cluster-gpl-7.6.10-linux-glibc2.12-x86_64.tar.gz Linux 7.6.10 ndb 916 MB
mysql-cluster-8.0.16-dmr-linux-glibc2.12-x86_64.tar.gz Linux 8.0.16 ndb 1.1 GB
mysql-cluster-gpl-7.6.11-linux-glibc2.12-x86_64.tar.gz Linux 7.6.11 ndb 916 MB
mysql-cluster-8.0.17-rc-linux-glibc2.12-x86_64.tar.gz Linux 8.0.17 ndb 1.1 GB
mysql-shell-8.0.17-linux-glibc2.12-x86-64bit.tar.gz Linux 8.0.17 mysql-shell 30 MB
mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz Linux 5.7.28 mysql 725 MB
mysql-8.0.18-linux-glibc2.12-x86_64.tar.xz Linux 8.0.18 mysql 504 MB
mysql-8.0.18-linux-x86_64-minimal.tar.xz Linux 8.0.18 mysql 48 MB Y
mysql-8.0.19-linux-x86_64-minimal.tar.xz Linux 8.0.19 mysql 45 MB
mysql-cluster-8.0.19-linux-glibc2.12-x86_64.tar.gz Linux 8.0.19 ndb 1.2 GB
mysql-5.7.29-linux-glibc2.12-x86_64.tar.gz Linux 5.7.29 mysql 665 MB
mysql-cluster-8.0.20-linux-glibc2.12-x86_64.tar.gz Linux 8.0.20 ndb 1.2 GB
mysql-8.0.20-linux-x86_64-minimal.tar.xz Linux 8.0.20 mysql 44 MB Y
mysql-5.7.30-linux-glibc2.12-x86_64.tar.gz Linux 5.7.30 mysql 660 MB
mysql-8.0.21-linux-glibc2.17-x86_64-minimal.tar.xz Linux 8.0.21 mysql 48 MB Y
Percona-Server-8.0.20-11-Linux.x86_64.glibc2.12-minimal.tar.gz Linux 8.0.20 percona 103 MB Y
mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz Linux 5.7.31 mysql 376 MB
mysql-shell-8.0.21-linux-glibc2.12-x86-64bit.tar.gz Linux 8.0.21 shell 43 MB
3.2.2 下载并解压指定软件包
使用dbdeployer downloads get file_name,从上面的列表中复制需要下载的版本并粘贴文件名。例如:
[root@mysql8 ~]# dbdeployer downloads get-unpack mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz
Downloading mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz
.........105 MB.........210 MB.........315 MB..... 376 MB
File /root/mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz downloaded
Checksum matches
Unpacking tarball mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz to $HOME/opt/mysql/5.7.31
.........100.........200.........300302
Renaming directory /root/opt/mysql/mysql-5.7.31-linux-glibc2.12-x86_64 to /root/opt/mysql/5.7.31
3.3 检查DBdeployer的已安装/可用的tarball二进制软件包列表
[root@mysql8 ~]# dbdeployer versions
Basedir: /root/opt/mysql
5.7.31 8.0.20 8.0.21
[root@mysql8 ~]# tree $HOME/opt -L 2
/root/opt
└── mysql
├── 5.7.31
├── 8.0.20
└── 8.0.21
3.4 快速部署实例dbdeployer deploy -h
3.4.1 该命令可以部署单个,多个或复制的MySQL沙箱实例
multiple 创建多个独立的mysql
replication 创建复制环境的mysql
single 创建单节点的mysql
3.4.2 如果要使用多个相同版本的沙箱,且没有任何复制关系,请使用dbdeployer deploy multiple -h,例如:
dbdeployer deploy multiple 8.0.21
ps -ef | grep mysqld
默认创建三个节点,我们可以用-n选项来指定需要创建的节点数,--force强制覆盖之前的安装
dbdeployer deploy multiple -n 2 --force 8.0.21
3.4.3 如果需要安装一主多从的复制环境,请使用dbdeployer deploy replication -h,例如:
dbdeployer deploy replication 5.7.31
[root@mysql8 rsandbox_5_7_31]# ./status_all
REPLICATION /root/sandboxes/rsandbox_5_7_31
master : master on - port 19832 (19832)
node1 : node1 on - port 19833 (19833)
node2 : node2 on - port 19834 (19834)
默认为一主两从三节点版,同样可以使用-n选项来指定节点数,--gtid指定为gtid复制模式
dbdeployer deploy replication 5.7.31 -n 2 --gtid --force
[root@mysql8 rsandbox_5_7_31]# ./status_all
REPLICATION /root/sandboxes/rsandbox_5_7_31
master : master on - port 19832 (19832)
node1 : node1 on - port 19833 (19833)
3.4.4 如果只想测试单个实例MySQL,请使用dbdeployer deploy single -h,例如:
dbdeployer deploy single 8.0.20
3.4.5 部署一套多主MGR集群
dbdeployer deploy --topology=group replication 8.0.20
四、实例组操作
一键部署完成后会在 $HOME/sandboxes 目录下生成各实例组对应的数据目录,该目录包含以下信息(部分信息)
- 一键启停该组所有实例的脚本
- 一键登录数据库脚本
- 一键重置该组所有实例的脚本(清除所有测试数据并重新初始化成全新的主从)
- 主从实例的数据目录(主库为 master,从库分别为 node1、node2 依次递增)
- 各实例的配置文件
- 默认用户授权命令
- 单独启停实例命令
- binlog、relaylog 解析命令
4.1 使用示例
[root@mysql8 ~]# cd $HOME/sandboxes/group_msb_8_0_20
[root@mysql8 group_msb_8_0_20]# ls
check_nodes metadata_all n3 node3 sbdescription.json status_all test_sb_all use_all_slaves
clear_all n1 node1 replicate_from send_kill_all stop_all use_all
initialize_nodes n2 node2 restart_all start_all test_replication use_all_masters
4.2 查看该组所有实例状态
[root@mysql8 group_msb_8_0_20]# ./status_all
MULTIPLE /root/sandboxes/group_msb_8_0_20
node1 : node1 on - port 22021 (22021)
node2 : node2 on - port 22022 (22022)
node3 : node3 on - port 22023 (22023)
4.3 一键重启该组所有实例
[root@mysql8 group_msb_8_0_20]# ./restart_all
# executing 'stop' on /root/sandboxes/group_msb_8_0_20
executing 'stop' on node3
stop /root/sandboxes/group_msb_8_0_20/node3
executing 'stop' on node2
stop /root/sandboxes/group_msb_8_0_20/node2
executing 'stop' on node1
stop /root/sandboxes/group_msb_8_0_20/node1
# executing 'start' on /root/sandboxes/group_msb_8_0_20
executing "start" on node 1
. sandbox server started
executing "start" on node 2
. sandbox server started
executing "start" on node 3
. sandbox server started
4.4 单独操作某一节点,需进入对应节点数据目录
[root@mysql8 group_msb_8_0_20]# cd ~/sandboxes/group_msb_8_0_20/node1
[root@mysql8 node1]# ls
add_option clone_from data metadata replicate_from send_kill start test_sb
after_start connection.conf grants.mysql my restart show_binlog start.log tmp
clear connection.json init_db my.sandbox.cnf sbdescription.json show_log status use
clone_connection.sql connection.sql load_grants mysqlsh sb_include show_relaylog stop
4.5 登陆指定实例
[root@mysql8 node1]# ./use
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.20 MySQL Community Server - GPL
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
node1 [localhost:22021] {msandbox} ((none)) >
4.6 msyql日志管理
每个实例下有便捷日志脚本
show_log #显示错误日志或常规日志
show_binlog
show_relaylog
4.7 相关mysql用户密码
| user name | password | privileges |
|---|---|---|
| root@localhost | msandbox | all on *.* with grant option |
| msandbox@localhost | msandbox | all on *.* |
| rsandbox@127.% | rsandbox | REPLICATION SLAVE |
4.8 本地root用户登陆
mysql -uroot -pmsandbox -S /tmp/mysql_sandbox8020.sock
五、dbdeployer 常用管理命令
以下是使用 dbdeployer 过程中总结的常用命令,详细使用方式可查看文末 dbdeployer 文档链接。
5.1 更新dbdeployer
dbdeployer update
5.2 列出以解压的MySQL版本
dbdeployer versions
5.3 列出已安装的沙箱实例
dbdeployer sandboxes
5.4 删除已安装沙箱实例
dbdeployer delete multi_msb_8_0_21
5.5 锁定及解锁一个或多个沙箱实例,以防止删除
[root@mysql8 ~]# dbdeployer admin lock group_msb_8_0_20
Sandbox group_msb_8_0_20 locked
[root@mysql8 ~]# dbdeployer admin unlock group_msb_8_0_20
Sandbox group_msb_8_0_20 unlocked
六、相关连接
- dbdeployer 官方下载:https://github.com/datacharmer/dbdeployer/releases
- dbdeployer 官方手册:https://github.com/datacharmer/dbdeployer
- MySQL 各历史版本下载链接:https://downloads.mysql.com/archives/community/
- dbdeployer 的功能特性:https://github.com/datacharmer/dbdeployer/blob/master/docs/features.md
因为有悔,所以披星戴月;因为有梦,所以奋不顾身! 个人博客首发:easydb.net 微信公众号:easydb 关注我,不走丢!
dbdeployer MySQL沙盒部署详解的更多相关文章
- iOS: 沙盒的详解和目录的获取
沙盒的详解: •iOS应用程序只能在为该改程序创建的文件系统中读取文件,不可以去其它地方访问,此区域被称为沙盒 •iOS常用目录: –Bundle //该目录下的文件是用来存储应用程序包的 ...
- 【转】Nginx+php-fpm+MySQL分离部署详解
转:http://www.linuxidc.com/Linux/2015-07/120580.htm Nginx+php-fpm+MySQL分离部署详解 [日期:2015-07-26] 来源:Linu ...
- MySQL高可用方案-PXC(Percona XtraDB Cluster)环境部署详解
MySQL高可用方案-PXC(Percona XtraDB Cluster)环境部署详解 Percona XtraDB Cluster简称PXC.Percona Xtradb Cluster的实现是在 ...
- legend3---Windows 7/8/10 系统下Laravel框架的开发环境安装及部署详解(Vagrant + Homestead)
legend3---Windows 7/8/10 系统下Laravel框架的开发环境安装及部署详解(Vagrant + Homestead) 一.总结 一句话总结: 1.安装的话就是下载好git,va ...
- WIN中SharePoint Server 2010 入门安装部署详解
目前流行的原始安装文件基本都是这样的:Windows Server 2008 R2+SQL Server 2008R2+SharePoint Server 2010 这个初始环境原本也无可厚非 ...
- MySQL集群搭建详解
概述 MySQL Cluster 是MySQL 适合于分布式计算环境的高实用.可拓展.高性能.高冗余版本,其研发设计的初衷就是要满足许多行业里的最严酷应用要求,这些应用中经常要求数据库运行的可靠性要达 ...
- Python中操作mysql的pymysql模块详解
Python中操作mysql的pymysql模块详解 前言 pymsql是Python中操作MySQL的模块,其使用方法和MySQLdb几乎相同.但目前pymysql支持python3.x而后者不支持 ...
- PHP mysql与mysqli事务详解
官方对PHP连接到MySQL数据库服务器的三种主要的API简介如下: http://php.net/manual/zh/mysqli.overview.php PHP mysql与mysqli事务详解 ...
- centos7.2环境elasticsearch-5.0.1+kibana-5.0.1+zookeeper3.4.6+kafka_2.9.2-0.8.2.1部署详解
centos7.2环境elasticsearch-5.0.1+kibana-5.0.1+zookeeper3.4.6+kafka_2.9.2-0.8.2.1部署详解 环境准备: 操作系统:centos ...
随机推荐
- 手写Promise简易版
话不多说,直接上代码 通过ES5的模块化封装,向外暴露一个属性 (function(window){ const PENDING = 'pending'; const RESOLVED = 'fulf ...
- 看视频常见的 720p、1080p、4k,这些分辨率到底包含了什么
从早期的420p,到后来的720p,到现在的非1080p不看.视频的清晰度飞快提升,但是在看到色彩越来越丰富清晰度越来越高的画面时,你有关注过他们的到底是怎么做到的么?我们一起来了解一下吧. 想必大家 ...
- WPF实现飞控姿态仪表盘控件Attitude dashboard
一.概要 近期项目当中需要用到飞机控制仪表盘的姿态仪,一开始去各大网站搜索解决方案要么就是winfrom要么就是很老的代码根本不能运行更甚者是居然有的还要下载积分. 只能自己手动从0开始写一个控件.这 ...
- 没想到,Git居然有3种“后悔药”!
没想到,Git居然有后悔药! 你知道Git版本控制系统中都有哪些"后悔药"吗? 本文通过案例讲解git reset . git revert . git checkout在版本控制 ...
- ArcGIS Pro 二次开发
本文基于 Windows7 + VS2019 + .NET Framework 4.8 + ArcGIS Pro 2.5.22081 开发和撰写. 目录 开发环境配置 获取ArcGIS Pro 安装V ...
- 一键部署k8s
本人学习安装kubernetes时,顺便整理了安装脚本,可以通过执行一个脚本,自动二进制安装好1台master+2台node的k8环境.方便需要学习k8s的同学. 百度网盘:https://pan.b ...
- [Oracle/sql]查看当前用户名下有多少表 以及查看表字段信息
SQL> select table_name from user_tables order by table_name; TABLE_NAME ------------------------- ...
- 转载:51cto 2019好文精选
转载地址:https://news.51cto.com/art/202001/609544.htm 01.知识科普 傻瓜都能看懂,30张图彻底理解红黑树! TCP三次握手,四次挥手,你真的懂吗? 面试 ...
- ubuntu安装docker-ce 、docker-ce-cli、containerd.io
问题 ubuntu安装docker的时候特别慢,百度搜了一大堆都没讲到点子上,最后请教了大佬才知道是源的问题 安装 修改源 sudo gedit /etc/apt/sources.list 添加源 阿 ...
- URL 传参转义 (特殊符号转义)
问题: url参数中 存在+,空格,/,?,%,#,&,=等特殊符号的时候,可能在服务器端无法获得正确的参数值,如何是好? 解决办法:将这些字符转化成服务器可以识别的字符,对应关系如下:URL ...