一、从github下载mysqltools工具包
github地址:https://github.com/Neeky/mysqltools
二、环境规划:
主机名 ip mysql中的角色
master-slave17 10.186.19.17 master
master-slave18 10.186.19.18 slave
master-slave19 10.186.19.19 slave
三、执行自动化安装配置:
ansible-playbook install_master_slaves.yaml PLAY [ms1] **************************************************************************************** TASK [Gathering Facts] ****************************************************************************
ok: [master-slave17]
ok: [master-slave19]
ok: [master-slave18] TASK [create mysql user] **************************************************************************
changed: [master-slave17]
changed: [master-slave18]
changed: [master-slave19] TASK [create and config /etc/my.cnf] **************************************************************
changed: [master-slave18]
changed: [master-slave17]
changed: [master-slave19] TASK [transfer mysql install package to remote host and unarchive to /usr/local/] *****************
changed: [master-slave17]
changed: [master-slave18]
changed: [master-slave19] TASK [change owner to mysql user] *****************************************************************
changed: [master-slave18]
changed: [master-slave17]
changed: [master-slave19] TASK [make link /usr/local/mysql-xx.yy.zz to /usr/local/mysql] ************************************
changed: [master-slave17]
changed: [master-slave18]
changed: [master-slave19] TASK [export mysql share object (*.os)] ***********************************************************
ok: [master-slave17]
ok: [master-slave18]
ok: [master-slave19] TASK [load share object] **************************************************************************
changed: [master-slave18]
changed: [master-slave17]
changed: [master-slave19] TASK [export path env variable] *******************************************************************
ok: [master-slave17]
ok: [master-slave18]
ok: [master-slave19] TASK [export path env to /root/.bashrc] ***********************************************************
ok: [master-slave17]
ok: [master-slave18]
ok: [master-slave19] TASK [make link /usr/local/mysql-xx.yy.zz to /usr/local/mysql] ************************************
ok: [master-slave17]
ok: [master-slave18]
ok: [master-slave19] TASK [create libmysqlclient_r.so file for php-5.6] ************************************************
changed: [master-slave17]
changed: [master-slave18]
changed: [master-slave19] TASK [create datadir] *****************************************************************************
changed: [master-slave17]
changed: [master-slave18]
changed: [master-slave19] TASK [initialize-insecure] ************************************************************************
changed: [master-slave17]
changed: [master-slave18]
changed: [master-slave19] TASK [create systemd config file] *****************************************************************
changed: [master-slave17]
changed: [master-slave19]
changed: [master-slave18] TASK [enable mysqld service] **********************************************************************
changed: [master-slave19]
changed: [master-slave17]
changed: [master-slave18] TASK [start mysql(sytemctl)] **********************************************************************
changed: [master-slave17]
changed: [master-slave18]
changed: [master-slave19] TASK [config mysql.service start up on boot] ******************************************************
changed: [master-slave18]
changed: [master-slave17]
changed: [master-slave19] TASK [config sysv start script] *******************************************************************
skipping: [master-slave17]
skipping: [master-slave18]
skipping: [master-slave19] TASK [start mysql(service)] ***********************************************************************
skipping: [master-slave17]
skipping: [master-slave18]
skipping: [master-slave19] TASK [config mysql.service start up on boot] ******************************************************
skipping: [master-slave17]
skipping: [master-slave18]
skipping: [master-slave19] TASK [stransfer sql to remote host] ***************************************************************
changed: [master-slave18]
changed: [master-slave17]
changed: [master-slave19] TASK [create replication user on master / start slave on slave] ***********************************
changed: [master-slave17]
changed: [master-slave19]
changed: [master-slave18] ---
TASK [transfer sql statement to remonte] **********************************************************
skipping: [master-slave18]
skipping: [master-slave19]
changed: [master-slave17] TASK [make mysql secure] **************************************************************************
skipping: [master-slave18]
skipping: [master-slave19]
changed: [master-slave17] TASK [remove temp file /tmp/make_mysql_secure.sql] ************************************************
skipping: [master-slave18]
skipping: [master-slave19]
systemctl stop mysql
changed: [master-slave17] PLAY RECAP ****************************************************************************************
master-slave17 : ok= changed= unreachable= failed=
master-slave18 : ok= changed= unreachable= failed=
master-slave19 : ok= changed= unreachable= failed=
四、在slave上测试配置是否正确:
mysql -uroot -pmtls0352
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
Server version: 5.7.-log MySQL Community Server (GPL) Copyright (c) , , 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. mysql> show slave status \G
*************************** . row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 10.186.19.17
Master_User: rple
Master_Port:
Connect_Retry:
Master_Log_File: mysql-bin.
Read_Master_Log_Pos:
Relay_Log_File: mtls19-relay-bin.
Relay_Log_Pos:
Relay_Master_Log_File: mysql-bin.
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
结论:
mysql复制环境正确的配置好了!
整个安装配置的过程用了不到3分钟、通过mysqltools可以大大的节省时间。所以mysqltools是一个提高生产力的好工具!
----