letou188APP
  咨询电话:13969669349

乐投娱乐

自动化运维(2)之一键式单实例安装MySQL

ZMySQLAutoTools文档

目标:自动化构建部署MySQL数据库,一键式单实例mysql安装,备份,监控,主从集群部署等。以及jdk,tomcat,nginx等基础中间件的自动化部署安装及运维。

此文档:完成一键式单实例mysql安装功能,可以完成批量标准化部署MySQL单实例。用于测试,开发以及生产环境。


目录

安装 ZMySQLAutoTools环境准备解压ZMySQLAutoToolspython3.x安装ansible安装配置ansible自动化单实例MySQL部署yaml文件配置修改一键单实例MySQL部署

环境准备

本实验为:4台虚拟机,操作系统为:Centos 6.8(6以上均可)

主机名ip地址备注
host_5010.1.11.50主控机
host_5110.1.11.51被控客户端
host_5210.1.11.52被控客户端
host_5310.1.11.53被控客户端

解压ZMySQLAutoTools

1):获得ZMySQLAutoTools安装包

cd /tmp/wget https://github.com/zhangshengdong/ZMySQLAutoTools/archive/master.zip

2):解压ZMySQLAutoTools安装包

unzip mastermv ZMySQLAutoTools-master /usr/local/ZMySQLAutoTools

python3.x安装

在ZMySQLAutoTools/packages/python/目录下,有相关的python安装包,通过 installPython.sh 安装部署

# yum install -y libselinux-python# cd /usr/local/ZMySQLAutoTools/packages/python/# bash installPython.sh

输出日志为:

.....Collecting setuptoolsCollecting pipInstalling collected packages: setuptools, pipSuccessfully installed pip-9.0.1 setuptools-28.8.0......

说明安装成功

查看版本:

source /etc/profilepython3 --version

ansible安装

在ZMySQLAutoTools/packages/ansible/目录下,有相关的ansible安装包,通过 ins_ansible.sh 安装部署

# source /etc/profile# cd /usr/local/ZMySQLAutoTools/packages/ansible# bash ins_ansible.sh

输出日志为:

Using /usr/local/python-3.6.2/lib/python3.6/site-packagesFinished processing dependencies for ansible==2.4.0.0

说明安装成功

配置ansible

1):编辑ansible的配置文件

增加ansible的配置文件

mkdir -p /etc/ansibletouch /etc/ansible/hosts配置/etc/ansible/hosts文件,内容如下:

host_50 ansible_user=root ansible_host=10.1.11.50host_51 ansible_user=root ansible_host=10.1.11.51host_52 ansible_user=root ansible_host=10.1.11.52host_53 ansible_user=root ansible_host=10.1.11.53

2):配置主控机与被控机之间的ssh信任

ssh-keygenssh-copy-id root@10.1.11.50ssh-copy-id root@10.1.11.51ssh-copy-id root@10.1.11.52ssh-copy-id root@10.1.11.53

3):测试ansible是否成功

举例命令:ansible all -m ping //检测所有主机是否pingOKansible all -a "/bin/echo hello" //对所有主机执行hello脚本ansible all -a "df -h" //对所有主机检测硬盘ansible host_53 -m command -a "hostname"//对主机host_53,查看hostname的名字ansible all -m shell -a "ps -ef |grep mysql" //对所有主机检测mysql进程

ping命令的检测效果日志日志如下:

[root@MHA-Manager ansible]# ansible all -m pinghost_50 | SUCCESS => { "changed": false, "failed": false, "ping": "pong"}host_51 | SUCCESS => { "changed": false, "failed": false, "ping": "pong"}host_53 | SUCCESS => { "changed": false, "failed": false, "ping": "pong"}host_52 | SUCCESS => { "changed": false, "failed": false, "ping": "pong"}

自动化单实例MySQL部署

yaml文件配置修改

由于MySQL的tar.gz过大,所以手动get到指定目录。并且修改yaml文件,完成一键式部署mysql。

1):下载MySQL 5.7二进制部署包

cd /tmp/wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz

2): MySQL 5.7二进制部署包放置到/usr/local/ZMySQLAutoTools/packages/mysql目录下

mv /tmp/mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz /usr/local/ZMySQLAutoTools/packages/mysql/

3): 修改install_single_mysql.yaml配置文件

[root@MHA-Manager mysql]# cd /usr/local/ZMySQLAutoTools/deploy/mysql[root@MHA-Manager mysql]# vi install_single_mysql.yaml--- - hosts: host_51 //修改为你要远程部署的主机名称

一键单实例MySQL部署

1):部署mysql

cd /usr/local/ZMySQLAutoTools/deploy/mysqlansible-playbook install_single_mysql.yaml

2):进入mysql

[root@MHA-Manager mysql]# mysql -uroot -p"zsd@7101"mysql: [Warning] Using a password on the command line interface can be insecure.Welcome to the MySQL monitor. Commands end with ; or g.Your MySQL connection id is 3Server version: 5.7.22-log MySQL Community Server (GPL)Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type "help;" or "h" for help. Type "c" to clear the current input statement.(root@localhost) [(none)]>