GreatSQL Docker镜像的确不支持在Docker中使用VIP功能。原因如下:
1. 在Docker中,无法用systemd方式来启动GreatSQL。
2. 在打包时,也没有将mysqld程序文件属主改为root,并加上setcap属性。
如果想要在Docker中使用GreatSQL VIP特性,可以采用以下方式实现:
1. 创建一个全新centos容器,并加上 --privileged 参数。
2. 自行安装GreatSQL软件包(二进制包或RPM包都行),利用setcap给mysqld程序文件加上提权属性。
3. 修改 mysqld 程序文件属主为 root。
4. 正确配置相关参数。
参考过程如下所示
- # 创建容器
- docker run -itd --privileged --hostname t1 --name t1 registry.cn-beijing.aliyuncs.com/greatsql/centos bash
- # 在容器中查看初始ip
- [root@t1 GreatSQL]# ip a
- 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
- 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
- 233: eth0@if234: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
- link/ether 02:42:ac:11:00:04 brd ff:ff:ff:ff:ff:ff link-netnsid 0
- inet 172.17.0.4/16 brd 172.17.255.255 scope global eth0
- valid_lft forever preferred_lft forever
- # 修改my.cnf
- user = root
- loose-plugin_load_add = 'greatdb_ha.so'
- loose-greatdb_ha_enable_mgr_vip = ON
- loose-greatdb_ha_mgr_vip_nic = 'eth0'
- loose-greatdb_ha_mgr_vip_ip = '172.17.0.40'
- loose-greatdb_ha_mgr_vip_mask = '255.255.0.0'
- loose-greatdb_ha_port = 33062
- #loose-greatdb_ha_mgr_read_vip_ips = "172.17.0.41,172.17.0.42"
- loose-greatdb_ha_mgr_read_vip_floating_type = "TO_ANOTHER_SECONDARY"
- loose-greatdb_ha_send_arp_packge_times = 5
- loose-greatdb_ha_mgr_exit_primary_kill_connection_mode = OFF
- report_host = 172.17.0.4
- report_port = 3306
- # setcap提权及修改文件属主
- chown root:root /usr/sbin/mysqld
- setcap CAP_NET_ADMIN,CAP_NET_RAW+ep /usr/sbin/mysqld
- [root@t1 GreatSQL]# getcap /usr/sbin/mysqld
- /usr/sbin/mysqld = cap_net_admin,cap_net_raw+ep
- [root@t1 GreatSQL]# ls -la /usr/sbin/mysqld
- -rwxr-xr-x 1 root root 67858088 Jul 30 08:18 /usr/sbin/mysqld
- # 启动,务必确认以root身份启动
- /usr/sbin/mysqld &
- [root@t1 GreatSQL]# ps -ef | grep mysqld
- root 1518 15 15 07:02 pts/1 00:00:00 /usr/sbin/mysqld
- # 再次查看ip
- [root@t1 GreatSQL]# ip a
- 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
- 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
- 233: eth0@if234: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
- link/ether 02:42:ac:11:00:04 brd ff:ff:ff:ff:ff:ff link-netnsid 0
- inet 172.17.0.4/16 brd 172.17.255.255 scope global eth0
- valid_lft forever preferred_lft forever
- inet 172.17.0.40/16 brd 172.17.255.255 scope global secondary eth0:0
- valid_lft forever preferred_lft forever
复制代码
可以看到,已经能正确绑定VIP了。
以上操作基于 GreatSQL 8.0.32-26 版本。
|