[root@mycat1 conf]# mysql -uroot -p123456 -P8066 -h127.0.0.1
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.29-mycat-1.6-RELEASE-20161028204710 MyCat Server (OpenCloundDB)
Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MySQL [(none)]>
进来了。
注意mycat有两个口,8066和9066,9066是管理口。
登录管理口看看
[root@mycat1 conf]# mysql -uroot -p123456 -P9066 -h127.0.0.1
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.29-mycat-1.6-RELEASE-20161028204710 MyCat Server (monitor)
Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MySQL [(none)]>
可以执行命令看看,节点起来了吗
MySQL [(none)]> show @@database;
+----------+
| DATABASE |
+----------+
| test |
+----------+
1 row in set (0.00 sec)
MySQL [(none)]> show @@datanode;
+------+------------------+-------+-------+--------+------+------+---------+------------+----------+---------+---------------+
| NAME | DATHOST | INDEX | TYPE | ACTIVE | IDLE | SIZE | EXECUTE | TOTAL_TIME | MAX_TIME | MAX_SQL | RECOVERY_TIME |
+------+------------------+-------+-------+--------+------+------+---------+------------+----------+---------+---------------+
| dn1 | mycat_mysql1/db1 | 0 | mysql | 0 | 0 | 1000 | 0 | 0 | 0 | 0 | -1 |
+------+------------------+-------+-------+--------+------+------+---------+------------+----------+---------+---------------+
1 row in set (0.01 sec)
MySQL [(none)]>
到这一步。基础mycat配置完成。
注意两台mycat虚机做一样的配置,后面用haproxy做这两台mycat的高可用。
[root@mycat_ha1 keepalived]# ip a
1: lo: mtu 65536 qdisc noqueue state UNKNOWN qlen 1
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: ens33: mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:52:a9:5b brd ff:ff:ff:ff:ff:ff
inet 192.168.211.135/24 brd 192.168.211.255 scope global dynamic ens33
valid_lft 1574sec preferred_lft 1574sec
inet 192.168.211.180/24 scope global secondary ens33
valid_lft forever preferred_lft forever
inet6 fe80::8d56:bf7:da17:8b45/64 scope link
valid_lft forever preferred_lft forever
192.168.211.180 就是我们配置的vip,已经起来了。
测试:
关闭现在活得vip的虚机的keepalived服务,看vip会切换吗?
[root@mycat_ha1 keepalived]# systemctl stop keepalived.service
Jan 3 04:07:25 mycat_ha1 Keepalived[5429]: Stopping
Jan 3 04:07:25 mycat_ha1 systemd: Stopping LVS and VRRP High Availability Monitor...
Jan 3 04:07:25 mycat_ha1 Keepalived_vrrp[5431]: VRRP_Instance(VI_1) sent 0 priority
Jan 3 04:07:25 mycat_ha1 Keepalived_vrrp[5431]: VRRP_Instance(VI_1) removing protocol VIPs.
Jan 3 04:07:25 mycat_ha1 Keepalived_healthcheckers[5430]: Stopped
Jan 3 04:07:26 mycat_ha1 Keepalived_vrrp[5431]: Stopped
Jan 3 04:07:26 mycat_ha1 systemd: Stopped LVS and VRRP High Availability Monitor.
Jan 3 04:07:26 mycat_ha1 Keepalived[5429]: Stopped Keepalived v1.3.5 (03/19,2017), git commit v1.3.5-6-g6fa32f2
看看mycat_ha2 活得vip了吗?
[root@mycat_ha2 keepalived]# ip a
1: lo: mtu 65536 qdisc noqueue state UNKNOWN qlen 1
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: ens33: mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:58:bd:ba brd ff:ff:ff:ff:ff:ff
inet 192.168.211.143/24 brd 192.168.211.255 scope global dynamic ens33
valid_lft 1390sec preferred_lft 1390sec
inet 192.168.211.180/24 scope global secondary ens33
valid_lft forever preferred_lft forever
inet6 fe80::1075:640f:6448:6b4e/64 scope link
valid_lft forever preferred_lft forever
inet6 fe80::bd24:c53:6545:1cc6/64 scope link tentative dadfailed
valid_lft forever preferred_lft forever
inet6 fe80::8d56:bf7:da17:8b45/64 scope link tentative dadfailed
valid_lft forever preferred_lft forever
[root@mycat_ha2 keepalived]#
正常
再启动mycat_ha1的keepalived服务
Jan 3 04:10:05 mycat_ha1 systemd: Started LVS and VRRP High Availability Monitor.
Jan 3 04:10:05 mycat_ha1 Keepalived_healthcheckers[5826]: Opening file '/etc/keepalived/keepalived.conf'.
Jan 3 04:10:05 mycat_ha1 Keepalived_vrrp[5827]: Registering Kernel netlink reflector
Jan 3 04:10:05 mycat_ha1 Keepalived_vrrp[5827]: Registering Kernel netlink command channel
Jan 3 04:10:05 mycat_ha1 Keepalived_vrrp[5827]: Registering gratuitous ARP shared channel
Jan 3 04:10:05 mycat_ha1 Keepalived_vrrp[5827]: Opening file '/etc/keepalived/keepalived.conf'.
Jan 3 04:10:05 mycat_ha1 Keepalived_vrrp[5827]: VRRP_Instance(VI_1) removing protocol VIPs.
Jan 3 04:10:05 mycat_ha1 Keepalived_vrrp[5827]: SECURITY VIOLATION - scripts are being executed but script_security not enabled.
Jan 3 04:10:05 mycat_ha1 Keepalived_vrrp[5827]: Using LinkWatch kernel netlink reflector...
Jan 3 04:10:05 mycat_ha1 Keepalived_vrrp[5827]: VRRP sockpool: [ifindex(2), proto(112), unicast(0), fd(10,11)]
Jan 3 04:10:05 mycat_ha1 Keepalived_vrrp[5827]: VRRP_Instance(VI_1) Transition to MASTER STATE
Jan 3 04:10:06 mycat_ha1 Keepalived_vrrp[5827]: VRRP_Instance(VI_1) Entering MASTER STATE
Jan 3 04:10:06 mycat_ha1 Keepalived_vrrp[5827]: VRRP_Instance(VI_1) setting protocol VIPs.
Jan 3 04:10:06 mycat_ha1 Keepalived_vrrp[5827]: Sending gratuitous ARP on ens33 for 192.168.211.180
Jan 3 04:10:06 mycat_ha1 Keepalived_vrrp[5827]: VRRP_Instance(VI_1) Sending/queueing gratuitous ARPs on ens33 for 192.168.211.180
Jan 3 04:10:06 mycat_ha1 Keepalived_vrrp[5827]: Sending gratuitous ARP on ens33 for 192.168.211.180
Jan 3 04:10:06 mycat_ha1 Keepalived_vrrp[5827]: Sending gratuitous ARP on ens33 for 192.168.211.180
Jan 3 04:10:06 mycat_ha1 Keepalived_vrrp[5827]: Sending gratuitous ARP on ens33 for 192.168.211.180
Jan 3 04:10:06 mycat_ha1 Keepalived_vrrp[5827]: Sending gratuitous ARP on ens33 for 192.168.211.180
[root@mycat_ha1 keepalived]#
mycat_ha1 权限更高,重新获取vip
mycat_ha1虚机
停止haproxy服务,测试:
Jan 3 04:20:59 mycat_ha1 Keepalived_vrrp[7075]: Sending gratuitous ARP on ens33 for 192.168.211.180
Jan 3 04:21:14 mycat_ha1 systemd: Stopping HAProxy Load Balancer...
Jan 3 04:21:14 mycat_ha1 systemd: Stopped HAProxy Load Balancer.
Jan 3 04:21:14 mycat_ha1 haproxy-systemd-wrapper: haproxy-systemd-wrapper: exit, haproxy RC=0
Jan 3 04:21:15 mycat_ha1 Keepalived[7073]: Stopping
Jan 3 04:21:15 mycat_ha1 Keepalived_healthcheckers[7074]: Stopped
Jan 3 04:21:15 mycat_ha1 Keepalived_vrrp[7075]: VRRP_Instance(VI_1) sent 0 priority
Jan 3 04:21:15 mycat_ha1 Keepalived_vrrp[7075]: VRRP_Instance(VI_1) removing protocol VIPs.
Jan 3 04:21:15 mycat_ha1 Keepalived_vrrp[7075]: Stopped
Jan 3 04:21:15 mycat_ha1 Keepalived[7073]: Stopped Keepalived v1.3.5 (03/19,2017), git commit v1.3.5-6-g6fa32f2
脚本执行成功,vip已经切换成功。
keepalived已经部署成功。
通过vip地址访问mycat
[root@mycat1 ~]# mysql -uroot -p123456 -P8066 -h 192.168.211.180
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.6.29-mycat-1.6-RELEASE-20161028204710 MyCat Server (OpenCloundDB)
Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MySQL [(none)]> use test;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
MySQL [test]> show tables;
+----------------+
| Tables in test |
+----------------+
| t1 |
| t2 |
| t3 |
+----------------+
3 rows in set (0.00 sec)
MySQL [test]> desc t1;
ERROR 1146 (42S02): Table 'db1.t1' doesn't exist
MySQL [test]> desc t2;
ERROR 1146 (42S02): Table 'db1.t2' doesn't exist
MySQL [test]> create table t1(id int);
Query OK, 0 rows affected (0.02 sec)
MySQL [test]> desc t1;
+-------+---------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+---------+------+-----+---------+-------+
| id | int(11) | YES | | NULL | |
+-------+---------+------+-----+---------+-------+
1 row in set (0.02 sec)
MySQL [test]>
看看获取vip那台虚机的日志
Jan 3 04:26:37 localhost haproxy[7152]: 192.168.211.145:60346 [03/Jan/2018:04:24:36.518] mycat mycat_server/mycat1 1/0/120656 1167 cD 0/0/0/0/0 0/0
Jan 3 04:26:37 localhost haproxy[7152]: 192.168.211.145:60346 [03/Jan/2018:04:24:36.518] mycat mycat_server/mycat1 1/0/120656 1167 cD 0/0/0/0/0 0/0
到这一步。
实验架构图的预设需求已经达到。