[root@mysql_a ~]# ansible mysql -a 'timedatectl set-timezone Asia/Shanghai' [root@mysql_a ~]# ansible mysql -a 'timedatectl set-ntp true' [root@mysql_a ~]# ansible mysql -a 'ntpdate cn.ntp.org.cn'
配置三台服务器的hosts
1 2 3 4 5
cat /etc/hosts 192.168.6.126 mysql_a 192.168.6.127 mysql_b 192.168.6.128 mysql_c [root@mysql_a ~]# ansible mysql -m copy -a 'src=/etc/hosts dest=/etc/hosts'
搭建Mariadb(mysql)主从复制
配置Mariadb yum源
1 2 3 4 5 6 7 8
[root@mysql_a ~]# vim /etc/yum.repos.d/MariaDB.repo # MariaDB 10.2 CentOS repository list - created 2017-07-27 03:36 UTC # http://downloads.mariadb.org/mariadb/repositories/ [mariadb] name = MariaDB baseurl = http://yum.mariadb.org/10.2/centos7-amd64 gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB gpgcheck=1
安装Mariadb(mysql)
1 2 3
[root@mysql_a ~]# ansible mysql -m copy -a 'src=/etc/yum.repos.d/MariaDB.repo dest=/etc/yum.repos.d/MariaDB.repo' [root@mysql_a ~]# ansible mysql -m yum -a 'name=MariaDB-server state=installed' [root@mysql_a ~]# ansible mysql -m yum -a 'name=MariaDB-client state=installed'
[root@mysql_b mariadb]# mysql -uroot -pffffff MariaDB [mysql]> grant replication slave on *.* to 'repl'@'192.168.6.%' identified by '111111'; MariaDB [(none)]> show master status; +------------------+----------+--------------+------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | +------------------+----------+--------------+------------------+ | mysql-bin.000002 | 342 | | | +------------------+----------+--------------+------------------+ 1 row in set (0.00 sec)
修改mysql_c配置文件
1 2 3 4 5
vim /etc/my.cnf binlog_format=row server-id = 128 replicate-ignore-db=mysql relay_log=relay-bin
重启两台Mariadb(mysql)服务
1
[root@mysql_a ~]# ansible mysql -a 'systemctl restart mariadb.service'
开启主从同步
1 2 3 4 5
[root@mysql_c mysql]# mysql -uroot –pffffff MariaDB [(none)]> stop slave; MariaDB [(none)]> change master to master_host='mysql_b', master_user='repl', master_password='111111',master_log_file='mysql-bin.000002',master_log_pos=342; MariaDB [(none)]> start slave; MariaDB [(none)]> show slave status\G
Atlas安装配置
安装Mariadb(Mysql)客户端
1 2 3
[root@mysql_a mariadb]# yum install MariaDB-client [root@mysql_a mariadb]# systemctl status mariadb.service //确保Atlas本机没有mysql服务被启动 Unit mariadb.service could not be found.
[root@mysql_a mariadb]# mysql -h127.0.0.1 -P2345 -unsxq –pffffff
通过工作接口访问
1 2 3
要保证这个用户在主从节点上都有权限,在主从节点上都添加一个用户 MariaDB [mysql]> grant all on *.* to atlas@'192.168.6.%' identified by '111111'; [root@mysql_a mariadb]# mysql -h127.0.0.1 -P1234 -uatlas -p111111