使用 dbops 快速部署 MySQL 数据库
大家好,这里是 Lucifer三思而后行,专注于提升数据库运维效率。前言
昨天群里有位朋友分享了芬达大佬的 MySQL 部署工具:dbops,抱着试一试的心态玩了一把,确实很给力。今天给大家分享一下,完全免费哦!
介绍
dbops 是一套高效的 ansible playbook 集合,目前是一个可以自动化安装和部署生产级别的 MySQL 及周边生态的工具。dbops 正在持续迭代开发中,目前已经支持:
[*]MySQL 5.7、8.0、8.4
[*]openGauss 5.0
dbops 的理念:
[*]高效
[*]并发推送安装包,并发地部署数据库
[*]全自动化部署,无需人工干预
[*]安装包体积小,节省下载时间
[*]优雅
[*]采用 ansible-lint 做代码优化
[*]使用纯优雅语言编写(python),尽量使用内置模块,避免使用 shell
[*]规范 (Code as Standrad)
[*]MySQL 满意企业生产级规范
Code as Standrad 这个理念由芬达提出,目的是镌汰对部署规范文档的依赖,通过 playbook 编码来固定部署规范。如果你使用 dbops 进行部署,那就相当于满意了交维规范。
目前支持的数据库小版本的硬限定:
[*]MySQL 5.7: >= 5.7.26
[*]MySQL 8.0: >= 8.0.28
[*]MySQL 8.4.0: >= 8.4.0
[*]Percona 5.7: 暂未设限定
[*]Percona 8.0: 暂未设限定
[*]GreatSQL 8.0: 8.0.32-24、8.0.32-25
[*]openGauss: == 5.0.0
请注意,这些仅仅是硬编码到 pre_tasks/validate_common_config_setting.yml 的硬限定,是由于作者没有测过小于即是这些版本。特别必要时,用户也可以自行修改代码,放开限定。
支持的系统和数据库架构:
ansible:
https://img-blog.csdnimg.cn/img_convert/d0c7e8c7c15b54499a0c113f35c9d757.png
mysql-ansible:
https://img-blog.csdnimg.cn/img_convert/021690d7a731fc0b2b350a23b3baa70a.png
https://img-blog.csdnimg.cn/img_convert/a3400b7831b771cfe5a7dcf87741ca87.png
opengauss-ansible:
https://img-blog.csdnimg.cn/img_convert/182d321a55dc5b1e08269bb661f6157b.png
注意,作者在开发时已考虑了某些系统或版本的兼容性,颠末判定后填写了 Y,但实际上并未进行过严酷实测。
下载 dbops
这里建议下载稳固发行版,如果必要测试可以下载开发版进行尝鲜。
Gitee 下载地点:https://gitee.com/fanderchan/dbops
Gitee 下载
https://img-blog.csdnimg.cn/img_convert/8b8e903c09330960f2712b00639f2141.png
https://img-blog.csdnimg.cn/img_convert/dbec881cb022b99eb8511557fa38fa17.png
开发版下载
选择 克隆/下载即可:
https://img-blog.csdnimg.cn/img_convert/304ea55446c7c7bedd6e46b81303cb4e.png
我这里是通过服务器联网直接下载的方式:
# 挂载本地 ISO
mount /dev/sr0 /mnt/
# 配置本地 YUM 源
## 备份系统初始配置文件
mkdir -p /etc/yum.repos.d/bak
mv /etc/yum.repos.d/* /etc/yum.repos.d/bak
## 一键配置软件源,默认 ISO 安装镜像挂载在 /mnt 目录下
cat<<-EOF>/etc/yum.repos.d/local.repo
name=server
baseurl=file:///mnt
enabled=1
gpgcheck=0
EOF
## 查看配置好的软件源
cat /etc/yum.repos.d/local.repo
# 最小化安装需要自行安装 wget 功能
yum install -y wget
# 通过 wget 方式下载稳定发行版
cd ~
dbops_version="1.4.20240729"
wget https://gitee.com/fanderchan/dbops/releases/download/dbops.${dbops_version}/dbops.${dbops_version}-Linux-x86_64.tar.gz
无法联网的朋友建议直接下载上传即可。
部署 dbops
为了低沉 Ansible 部署难度和兼容性问题,统一版本以避免因使用不同版本产生 bug,所以作者特意采用了绿色版 Ansible 2.10.5,并集成到了 dbops 中。部署过程中,系统会自动安装 Python3,并搭配使用 Python3 和 Ansible 2.10.5。为加速 dbops 的下载速度,作者精简了绿色版 Ansible 中不常用的功能,使其体积非常小。ansible-portable 目录压缩后仅有 3.6 MB,整个 dbops.tar.gz 压缩包仅有 20 MB!
解压缩 dbops
作者推荐将安装路径设置为 /usr/local:
# 解压
# tar zxvf dbops.1.4.20240729-Linux-x86_64.tar.gz -C /usr/local
# 查看解压后的目录
# cd /usr/local/dbops/
# ll
total 20
-rw-r--r--. 1 root root 11356 Jul 29 16:41 LICENSE
drwxr-xr-x. 6 root root 148 Jul 29 16:41 mysql_ansible
drwxr-xr-x. 6 root root 120 Jul 29 16:41 opengauss_ansible
drwxr-xr-x. 3 root root 97 Jul 29 16:41 portable-ansible-v0.5.0-py3
-rw-r--r--. 1 root root 915 Jul 29 16:41 README.en.md
-rw-r--r--. 1 root root 58 Jul 29 16:41 README.md
部署 ansible
进入目录,执行 shell 脚本:
# cd /usr/local/dbops/portable-ansible-v0.5.0-py3
# sh setup_portable_ansible.sh
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package python3.x86_64 0:3.6.8-17.el7 will be installed
--> Processing Dependency: python3-libs(x86-64) = 3.6.8-17.el7 for package: python3-3.6.8-17.el7.x86_64
--> Processing Dependency: python3-setuptools for package: python3-3.6.8-17.el7.x86_64
--> Processing Dependency: python3-pip for package: python3-3.6.8-17.el7.x86_64
--> Processing Dependency: libpython3.6m.so.1.0()(64bit) for package: python3-3.6.8-17.el7.x86_64
--> Running transaction check
---> Package python3-libs.x86_64 0:3.6.8-17.el7 will be installed
--> Processing Dependency: libtirpc.so.1()(64bit) for package: python3-libs-3.6.8-17.el7.x86_64
---> Package python3-pip.noarch 0:9.0.3-8.el7 will be installed
---> Package python3-setuptools.noarch 0:39.2.0-10.el7 will be installed
--> Running transaction check
---> Package libtirpc.x86_64 0:0.2.4-0.16.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
=====================================================================================================================================================================================================
Package Arch Version Repository Size
=====================================================================================================================================================================================================
Installing:
python3 x86_64 3.6.8-17.el7 server 70 k
Installing for dependencies:
libtirpc x86_64 0.2.4-0.16.el7 server 89 k
python3-libs x86_64 3.6.8-17.el7 server 6.9 M
python3-pip noarch 9.0.3-8.el7 server 1.6 M
python3-setuptools noarch 39.2.0-10.el7 server 629 k
Transaction Summary
=====================================================================================================================================================================================================
Install1 Package (+4 Dependent packages)
Total download size: 9.3 M
Installed size: 48 M
Downloading packages:
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total 114 MB/s | 9.3 MB00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : libtirpc-0.2.4-0.16.el7.x86_64 1/5
Installing : python3-pip-9.0.3-8.el7.noarch 2/5
Installing : python3-setuptools-39.2.0-10.el7.noarch 3/5
Installing : python3-3.6.8-17.el7.x86_64 4/5
Installing : python3-libs-3.6.8-17.el7.x86_64 5/5
Verifying: libtirpc-0.2.4-0.16.el7.x86_64 1/5
Verifying: python3-pip-9.0.3-8.el7.noarch 2/5
Verifying: python3-3.6.8-17.el7.x86_64 3/5
Verifying: python3-setuptools-39.2.0-10.el7.noarch 4/5
Verifying: python3-libs-3.6.8-17.el7.x86_64 5/5
Installed:
python3.x86_64 0:3.6.8-17.el7
Dependency Installed:
libtirpc.x86_64 0:0.2.4-0.16.el7 python3-libs.x86_64 0:3.6.8-17.el7 python3-pip.noarch 0:9.0.3-8.el7 python3-setuptools.noarch 0:39.2.0-10.el7
Complete!
which: no sshpass in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin)
Please run 'source ~/.bashrc' to apply the changes in your current shell.
生效 .bashrc:
# source ~/.bashrc
确认是否部署乐成:
# ansible --version
ansible 2.10.5
config file = None
configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/local/dbops/portable-ansible-v0.5.0-py3/ansible/ansible
executable location = /usr/local/dbops/portable-ansible-v0.5.0-py3/ansible
python version = 3.6.8 (default, Oct 13 2020, 16:18:22)
python 版本是 3.x 为正确。ansible 版本为 2.10.5 为正确。
使用 dbops
dbops 支持的部署架构中有些至少必要 3 台机器,比方 MySQL 的 MGR 架构。建议 dbops 独立用一台机器,那么整套实验就至少必要 4 台机器。如果实在没办法,可以把 dbops 部署到第一台 MySQL 复用机器。
本次只演示单机模式部署,dbops 和 MySQL 共用一台服务器主机。
部署单机
修改 hosts.ini,添加必要操作的机器进去:
## 进入 hosts.ini 所在目录
# pwd
/usr/local/dbops/mysql_ansible/inventory
## 修改 hosts.ini 中对应的 IP 和 root 密码
# vi hosts.ini
# cat hosts.ini
192.168.168.162 ansible_user=root ansible_ssh_pass="'oracle'"
#ansible_python_interpreter=/usr/bin/python3
建议在配置完 host.ini 之后验证一下服务器的连通性:
# pwd
/usr/local/dbops/mysql_ansible/playbooks
# ansible all -m ping
192.168.6.162 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": false,
"ping": "pong"
}
修改公共配置参数文件 common_config.yml:
## 主要关注 MySQL 版本和端口号,如果不需要修改则跳过
# pwd
/usr/local/dbops/mysql_ansible/playbooks
# grep mysql_version: common_config.yml
mysql_version: "8.4.0"
# grep mysql_port: common_config.yml
mysql_port: 3306
上传安装包:
MySQL 安装包下载地点:MySQL Product Archives
https://img-blog.csdnimg.cn/img_convert/f07eba68bf1b7b19fbda28606a043807.png
选择安装包版本时,必要注意主机的 glibc 版本以及 CPU 架构:
## glibc 版本
# ldd --version
ldd (GNU libc) 2.17
Copyright (C) 2012 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Written by Roland McGrath and Ulrich Drepper.
## CPU 架构
# uname -m
x86_64
下载完成后上传至指定目录:
# pwd
/usr/local/dbops/mysql_ansible/downloads
# ll
total 59872
-rw-r--r--. 1 root root 61305888 Aug 23 16:03 mysql-8.4.0-linux-glibc2.17-x86_64-minimal.tar.xz
执行 playbook 部署,安装过程不必要联网:
# pwd
/usr/local/dbops/mysql_ansible/playbooks
# ansible-playbook single_node.yml
PLAY ************************************************************************************************************************************
TASK ******************************************************************************************************************************************************************************
ok:
TASK **********************************************************************************************************************************************
ok: => (item=None)
ok: => (item=None)
ok: => (item=None)
ok: => (item=None)
ok: => (item=None)
ok: => (item=None)
ok:
TASK *******************************************************************************************************************************************************************
skipping:
TASK *************************************************************************************************************************************************************
skipping: => (item=fcs_skip_db_mount_verification)
skipping: => (item=fcs_skip_check_ntpd_or_chrony_running)
skipping: => (item=fcs_auto_download_mysql)
skipping: => (item=fcs_create_mysql_fast_login)
skipping: => (item=fcs_backup_script_create_backup_user)
skipping: => (item=fcs_mysql_use_jemalloc)
skipping: => (item=fcs_use_greatsql_ha)
TASK **********************************************************************************************************************************************************
skipping:
TASK *******************************************************************************************************************************************************
skipping:
TASK *******************************************************************************************************************************************************
skipping:
TASK ***********************************************************************************************************************************************************
skipping:
TASK ******************************************************************************************************************************************************
skipping:
TASK ***************************************************************************************************
changed:
TASK *********************************************************************************************************************************************************************
ok:
TASK ****************************************************************************************************************************************************************************
ok: => {
"msg": "The OS type of host 192.168.6.162 is CentOS7"
}
TASK ***************************************************************************************************************************************************************
ok: => {
"changed": false,
"msg": "All assertions passed"
}
TASK ***************************************************************************************************************************************************************************
ok:
TASK ***************************************************************************************************************************************************************************
ok:
TASK ***********************************************************************************************************************************************************************
ok:
TASK *****************************************************************************************************************************************************************
ok: => {
"msg": "The Python interpreter of host 192.168.6.162 is /usr/bin/python2"
}
TASK **********************************************************************************************************
skipping:
TASK *******************************************************************************************************************************************************************
ok:
TASK ***********************************************************************************************************************************************
ok:
TASK **********************************************************************************************************************************************************
ok: => {
"changed": false,
"msg": "All assertions passed"
}
TASK **************************************************************************************************************************************
changed:
TASK *************************************************************************************************************************************************************************************
ok:
TASK **********************************************************************************************************************************
ok: => {
"msg": [
"Hosts to be affected by Deploy single-node MySQL server using binary installation: 192.168.6.162",
"DB type: mysql",
"MySQL port: 3306",
"MySQL version: 8.4.0",
"Server specs: auto",
"Roles to be executed: ../roles/pre_check_and_set, ../roles/mysql_server"
]
}
TASK *****************************************************************************************************************************************************************
This will perform Deploy single-node MySQL server using binary installation on the displayed hosts. Please type 'confirm' to continue or press Ctrl+C to cancel.:
ok:
TASK **********************************************************************************************************************************************************************
skipping:
TASK *********************************************************************************************************************************************************************************
TASK [../roles/pre_check_and_set : Check yum and install libselinux-python3] ************************************************************************************************************************
ok:
TASK [../roles/pre_check_and_set : Install ncurses-compat-libs if necessary] ************************************************************************************************************************
skipping:
TASK [../roles/pre_check_and_set : Intall tar for openEuler20] **************************************************************************************************************************************
ok:
TASK [../roles/pre_check_and_set : Set SeLinux disabled] ********************************************************************************************************************************************
: SELinux state change will take effect next reboot
ok:
TASK [../roles/pre_check_and_set : Stop and Disabled Firewalld] *************************************************************************************************************************************
ok:
TASK [../roles/pre_check_and_set : Gather service facts] ********************************************************************************************************************************************
skipping:
TASK [../roles/pre_check_and_set : Assert NTP or Chrony is running and only one is enabled] *********************************************************************************************************
skipping:
TASK [../roles/pre_check_and_set : Check whether NUMA is turned off] ********************************************************************************************************************************
fatal: : FAILED! => {"changed": false, "cmd": ["grep", "-q", "numa=off", "/proc/cmdline"], "delta": "0:00:00.004868", "end": "2024-08-23 16:07:01.721770", "msg": "non-zero return code", "rc": 1, "start": "2024-08-23 16:07:01.716902", "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}
...ignoring
TASK [../roles/pre_check_and_set : Show warning if NUMA is not turned off] **************************************************************************************************************************
ok: => {
"msg": "Warning: NUMA is not turned off."
}
TASK [../roles/pre_check_and_set : Update sysctl configuration file] ********************************************************************************************************************************
ok:
TASK [../roles/pre_check_and_set : Reload sysctl] ***************************************************************************************************************************************************
changed:
TASK [../roles/pre_check_and_set : Extract parent directories of mysql_data_dir_base] ***************************************************************************************************************
skipping:
TASK [../roles/pre_check_and_set : Remove root '/' from parent directories list] ********************************************************************************************************************
skipping:
TASK [../roles/pre_check_and_set : Check if mount points exist for pre_check_and_set__mysql_data_dir_base_parents list] *****************************************************************************
skipping:
TASK [../roles/pre_check_and_set : Find the first matching mount point for mysql_data_dir_base and its parents] *************************************************************************************
skipping: => (item={'block_used': 35061, 'uuid': '3d53107e-ce12-4c21-a78d-82f97fef2750', 'size_total': 1063256064, 'block_total': 259584, 'mount': '/boot', 'block_available': 224523, 'size_available': 919646208, 'fstype': 'xfs', 'inode_total': 524288, 'options': 'rw,seclabel,relatime,attr2,inode64,noquota', 'device': '/dev/sda1', 'inode_used': 326, 'block_size': 4096, 'inode_available': 523962})
skipping: => (item={'block_used': 4980714, 'uuid': '2020-11-02-15-15-23-00', 'size_total': 10200502272, 'block_total': 4980714, 'mount': '/mnt', 'block_available': 0, 'size_available': 0, 'fstype': 'iso9660', 'inode_total': 0, 'options': 'ro,relatime', 'device': '/dev/sr0', 'inode_used': 0, 'block_size': 2048, 'inode_available': 0})
skipping: => (item={'block_used': 379986, 'uuid': '3342f530-81a3-43d8-8405-5f4ecb2d6389', 'size_total': 97658605568, 'block_total': 23842433, 'mount': '/', 'block_available': 23462447, 'size_available': 96102182912, 'fstype': 'xfs', 'inode_total': 47708160, 'options': 'rw,seclabel,relatime,attr2,inode64,noquota', 'device': '/dev/mapper/centos-root', 'inode_used': 34255, 'block_size': 4096, 'inode_available': 47673905})
TASK [../roles/pre_check_and_set : Debug output for mount point] ************************************************************************************************************************************
skipping:
TASK [../roles/pre_check_and_set : Assert mount point is using xfs filesystem] **********************************************************************************************************************
skipping:
TASK [../roles/pre_check_and_set : If it is a physical machine, double network card binding is required] ********************************************************************************************
ok: => {
"msg": "ens192"
}
TASK [../roles/pre_check_and_set : If it is a physical machine, double network card binding is required] ********************************************************************************************
skipping:
TASK [../roles/pre_check_and_set : Add network interface alias to a temporary file] *****************************************************************************************************************
changed:
TASK [../roles/pre_check_and_set : Fetch copy] ******************************************************************************************************************************************************
changed:
TASK [../roles/pre_check_and_set : Append file /tmp/net_aliases.txt (delegate to 127.0.0.1)] ********************************************************************************************************
ok:
TASK [../roles/pre_check_and_set : Check if shell output is 1] **************************************************************************************************************************************
ok: => {
"changed": false,
"msg": "All assertions passed"
}
TASK [../roles/pre_check_and_set : Delete /tmp/net_aliases.txt] *************************************************************************************************************************************
changed:
TASK [../roles/pre_check_and_set : Delete /tmp/ssh/ (delegate to 127.0.0.1)] ************************************************************************************************************************
changed:
TASK [../roles/mysql_server : Check if flag exists or not] ******************************************************************************************************************************************
ok:
TASK [../roles/mysql_server : Fail if flag exists] **************************************************************************************************************************************************
skipping:
TASK [../roles/mysql_server : Check port not in use —— mysql port 3306] *****************************************************************************************************************************
ok:
TASK [../roles/mysql_server : Ensure group "mysql" exists] ******************************************************************************************************************************************
ok:
TASK [../roles/mysql_server : Create mysql user] ****************************************************************************************************************************************************
changed:
TASK [../roles/mysql_server : Create mysql directories] *********************************************************************************************************************************************
ok: => (item=/database/mysql/etc)
ok: => (item=/database/mysql/data)
ok: => (item=/database/mysql/tmp)
ok: => (item=/database/mysql/run)
ok: => (item=/database/mysql/log/binlog)
ok: => (item=/database/mysql/log/redolog)
ok: => (item=/database/mysql/log/relaylog)
ok: => (item=/database/mysql/etc/3306)
ok: => (item=/database/mysql/data/3306)
ok: => (item=/database/mysql/tmp/3306)
ok: => (item=/database/mysql/log/binlog/3306)
ok: => (item=/database/mysql/log/redolog/3306)
ok: => (item=/database/mysql/log/relaylog/3306)
ok: => (item=/database/mysql/base/8.4.0)
TASK [../roles/mysql_server : Config /etc/my.cnf for mysql-5.7.x] ***********************************************************************************************************************************
skipping:
TASK [../roles/mysql_server : Config /etc/my.cnf for mysql-8.0.x] ***********************************************************************************************************************************
skipping:
TASK [../roles/mysql_server : Config /etc/my.cnf for mysql-8.4.x] ***********************************************************************************************************************************
changed:
TASK [../roles/mysql_server : Config /etc/my.cnf for percona-5.7.x] *********************************************************************************************************************************
skipping:
TASK [../roles/mysql_server : Config /etc/my.cnf for percona-8.0.x] *********************************************************************************************************************************
skipping:
TASK [../roles/mysql_server : Config /etc/my.cnf for greatsql-5.7.x] ********************************************************************************************************************************
skipping:
TASK [../roles/mysql_server : Config /etc/my.cnf for greatsql-8.0.x] ********************************************************************************************************************************
skipping:
TASK [../roles/mysql_server : Install libaio and numactl] *******************************************************************************************************************************************
ok: => (item={'name': 'libaio'})
ok: => (item={'name': 'numactl'})
TASK [../roles/mysql_server : Install jemalloc using yum] *******************************************************************************************************************************************
skipping:
TASK [../roles/mysql_server : Set jemalloc rpm file name based on OS] *******************************************************************************************************************************
skipping:
TASK [../roles/mysql_server : Copy jemalloc rpm to target server] ***********************************************************************************************************************************
skipping:
TASK [../roles/mysql_server : Install jemalloc from local file] *************************************************************************************************************************************
skipping:
TASK [../roles/mysql_server : Check if jemalloc installation failed] ********************************************************************************************************************************
skipping:
TASK [../roles/mysql_server : Check if MySQL package exists locally(local)] *************************************************************************************************************************
ok:
TASK [../roles/mysql_server : Fail if MySQL package not found and auto download is disabled(local)] *************************************************************************************************
skipping:
TASK [../roles/mysql_server : Download MySQL binary tarball if not found locally and auto download is enabled(local)] *******************************************************************************
skipping:
TASK [../roles/mysql_server : Download GreatSQL binary tarball if not found locally and auto download is enabled(local)] ****************************************************************************
skipping:
TASK [../roles/mysql_server : Transfer MySQL install package to remote host] ************************************************************************************************************************
changed:
TASK [../roles/mysql_server : Unarchive MySQL install package to /database/mysql/base/8.4.0] ********************************************************************************************************
changed:
TASK [../roles/mysql_server : Touch unarchive_mysql_package_finished file] **************************************************************************************************************************
changed:
TASK [../roles/mysql_server : Change owner to mysql user] *******************************************************************************************************************************************
changed:
TASK [../roles/mysql_server : Make link /database/mysql/mysql-xx.yy.gz to /usr/local/mysql] *********************************************************************************************************
changed:
TASK [../roles/mysql_server : Export mysql share object (*.os)] *************************************************************************************************************************************
changed:
TASK [../roles/mysql_server : Load share object] ****************************************************************************************************************************************************
ok:
TASK [../roles/mysql_server : Export path env variable] *********************************************************************************************************************************************
changed:
TASK [../roles/mysql_server : Export path env to /root/.bashrc] *************************************************************************************************************************************
changed:
TASK [../roles/mysql_server : Export path env to /home/mysql/.bashrc] *******************************************************************************************************************************
changed:
TASK [../roles/mysql_server : Remove /usr/include/mysql] ********************************************************************************************************************************************
ok:
TASK [../roles/mysql_server : Export include file to /usr/include/mysql] ****************************************************************************************************************************
changed:
TASK [../roles/mysql_server : Create symbolic links for libssl.so and libcrypto.so] *****************************************************************************************************************
skipping: => (item={'src': 'libssl.so.10', 'dest': 'libssl.so'})
skipping: => (item={'src': 'libcrypto.so.10', 'dest': 'libcrypto.so'})
TASK [../roles/mysql_server : Initialize-insecure for mysql-5.7.x] **********************************************************************************************************************************
skipping:
TASK [../roles/mysql_server : Initialize-insecure for mysql-8.0.x or mysql-8.4.x] *******************************************************************************************************************
changed:
TASK [../roles/mysql_server : Create systemd config file] *******************************************************************************************************************************************
changed:
TASK [../roles/mysql_server : Start mysql(sytemctl)] ************************************************************************************************************************************************
changed:
TASK [../roles/mysql_server : Config mysql.service start up on boot] ********************************************************************************************************************************
changed:
TASK [../roles/mysql_server : Mysql status] *********************************************************************************************************************************************************
ok:
TASK [../roles/mysql_server : Transfer sql statement to remote] *************************************************************************************************************************************
changed:
TASK [../roles/mysql_server : Make mysql secure] ****************************************************************************************************************************************************
changed:
TASK [../roles/mysql_server : Remove temp file /tmp/make_mysql_secure.sql] **************************************************************************************************************************
changed:
TASK [../roles/mysql_server : Ensure expect is installed] *******************************************************************************************************************************************
changed:
TASK [../roles/mysql_server : Transfer expect script to remote host] ********************************************************************************************************************************
changed:
TASK [../roles/mysql_server : Execute expect script to set MySQL login-path] ************************************************************************************************************************
: Module remote_tmp /home/mysql/.ansible/tmp did not exist and was created with a mode of 0700, this may cause issues when running as another user. To avoid this, create the remote_tmp
dir with the correct permissions manually
ok:
TASK [../roles/mysql_server : Set up alias in .bashrc named —— db3306] ******************************************************************************************************************************
changed:
TASK [../roles/mysql_server : Remove expect script from remote host] ********************************************************************************************************************************
changed:
TASK [../roles/mysql_server : Touch single_finish.flag] *********************************************************************************************************************************************
changed:
PLAY RECAP ******************************************************************************************************************************************************************************************
192.168.6.162 : ok=66 changed=31 unreachable=0 failed=0 skipped=36 rescued=0 ignored=1
Playbook run took 0 days, 0 hours, 1 minutes, 42 seconds
整个过程十分丝滑,大概必要 1~2 分钟就完成了,中心会有一步必要确认信息,输入 confirm 回车即可!
毗连测试
使用 mysql 用户毗连 MySQL,默认密码为 Dbops@8888:
# su - mysql
Last login: Fri Aug 23 15:54:50 CST 2024 on pts/0
$ mysql -uadmin -h127.0.0.1 -P3306 -pDbops@8888 -e "select @@version"
mysql: Using a password on the command line interface can be insecure.
+-----------+
| @@version |
+-----------+
| 8.4.0 |
+-----------+
使用快速登录毗连,这里实在是做了 alias 别名:
## 查看 alias 别名
$ alias | grep db3306
alias db3306='mysql --login-path=db3306'
## 连接 MySQL 数据库
$ db3306
Welcome to the MySQL monitor.Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 8.4.0 MySQL Community Server - GPL
Copyright (c) 2000, 2024, Oracle and/or its affiliates.
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.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.01 sec)
对于任何 playbook,执行前都只必要做三件事即可
[*]正确地配置 inventory/hosts.ini 主机信息
[*]正确地配置 playbook/common_config.yml 的通用参数部门信息
[*]正确地配置 playbook/vars/var_xxx.yml 的专有参数部门信息
可以发现,如果熟悉了整个流程之后,部署将变得十分简单,特别是多台并行部署行,可以在几分钟内部署几十上百套数据库,总之 Niubility。
往期出色文章推荐
Oracle RAC 启动顺序,你真的了解吗?
达梦数据库一键安装脚本(免费)一篇文章让你彻底掌握 Python
页:
[1]