[root@mastera0 mysql]# systemctl restart mariadb [root@mastera0 mysql]# mysql -uroot -puplooking Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 2 Server version: 5.5.44-MariaDB-log MariaDB Server
Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> grant replication slave on *.* to slave@'172.25.0.12' identified by 'uplooking'; Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> \q Bye [root@mastera0 mysql]# mysqldump -uroot -puplooking -A --single-transaction --master-data=2 --flush-logs > /tmp/mysql.91.sql [root@mastera0 mysql]# scp /tmp/mysql.91.sql root@172.25.0.12:/tmp The authenticity of host \'172.25.0.12 (172.25.0.12)\' can\'t be established. ECDSA key fingerprint is 91:2b:bd:df:0e:17:da:a0:f6:01:ff:5b:09:50:e8:ad. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '172.25.0.12' (ECDSA) to the list of known hosts. root@172.25.0.12\'s password: mysql.91.sql 100% 505KB 504.7KB/s 00:00 ## 从服务器 [root@masterb0 ~]# yum install -y mariadb-server [root@masterb0 ~]# vi /etc/my.cnf server-id=2 log-bin=/var/lib/mysql-log/masterb log-slave-update [root@masterb0 ~]# systemctl start mariadb [root@masterb0 ~]# mysql < /tmp/mysql.91.sql [root@masterb0 ~]# mysql Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 3 Server version: 5.5.44-MariaDB MariaDB Server
Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> \q Bye [root@masterb0 ~]# mysql ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO) [root@masterb0 ~]# mysql -uroot -puplooking Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 5 Server version: 5.5.44-MariaDB MariaDB Server
Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
[root@foundation0 ~]# ping mysql.service.consul PING mysql.service.consul (172.25.0.12) 56(84) bytes of data. 64 bytes from 172.25.0.12: icmp_seq=1 ttl=64 time=0.197 ms 64 bytes from 172.25.0.12: icmp_seq=2 ttl=64 time=0.287 ms ^C --- mysql.service.consul ping statistics --- 2 packets transmitted, 2 received, 0% packet loss, time 1054ms rtt min/avg/max/mdev = 0.197/0.242/0.287/0.045 ms [root@foundation0 ~]# mysql -utest -puplooking -h mysql.service.consul Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 1346 Server version: 5.5.44-MariaDB-log MariaDB Server
Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> select @@hostname; +------------+ | @@hostname | +------------+ | slave | +------------+ 1 row in set (0.00 sec)
MariaDB [(none)]> exit Bye
测试
域名解析dig mysql.service.consul.
mysql客户端连接数据库服务器 mysql -utest -puplooking -h mysql.service.consul,连接的是mysqlnode1