安装、和配置文件格式的说明这里暂且不提,临时研究搭建的一个环境,只保存示例以便参考,可以快速的配置即可。本次使用的是bind9
1、/etc/named.conf配置修改和添加
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
options { //此处添加对外的地址,假设为10.10.10.10 listen-on port 53 { 127.0.0.1;10.10.10.10; }; //允许所有地址来访查询 allow-query { any; }; }; //dns-srv的配置 zone "mysqldns.com" IN { type master; file "mysql.dns"; }; |
未列出的内容保持默认即可
2、修改/var/named/mysql.dns
这个文件的格式有一定的要求,可以参考网上比较详细的介绍,为了简便,我们只需要修改里面的ip地址即可
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
$TTL 6h mysqldns.com. IN SOA dnsserver.mysqldns.com. dnsserver.mysqldns.com. ( 1 ; serial num 3h ; refresh time 1h ; retry time 1w ; expire time 1h ) ; negative time mysqldns.com. IN NS dnsserver.mysqldns.com. dnsserver.mysqldns.com. IN A 10.10.10.10 s.proxy1 518400 IN A 10.10.10.09 s.proxy2 518400 IN A 10.10.10.10 s.proxy3 518400 IN A 10.10.10.11 _mysqlx._tcp.a.proxy1.mysqldns.com. 86400 IN SRV 0 5 15305 s.proxy1.mysqldns.com. _mysqlx._tcp.b.proxy1.mysqldns.com. 86400 IN SRV 0 5 15309 s.proxy1.mysqldns.com. _mysqlx._tcp.c.proxy3.mysqldns.com. 86400 IN SRV 0 5 15732 s.proxy3.mysqldns.com. _mysqlx._tcp.d.proxy3.mysqldns.com. 86400 IN SRV 0 5 25732 s.proxy3.mysqldns.com. _mysqlx._tcp.e.proxy3.mysqldns.com. 86400 IN SRV 0 5 18022 s.proxy3.mysqldns.com. _mysqlx._tcp.f.proxy3.mysqldns.com. 86400 IN SRV 0 5 11042 s.proxy3.mysqldns.com. |
srv记录里面的域名和target中的域名对应关系有点模糊,测试发现只要proxy1.mysqldns.com匹配即可(3级了)
3、检查配置是否生效
检查named.conf
named-checkconf -z /etc/named.conf
没有返回error或者warning,以及提示某个域名没有指定具体的地址等,基本就算通过
使用dig检查srv配置是否可以解析
dig @10.10.10.10 _mysqlx._tcp.b.proxy1.mysqldns.com srv
返回status: NOERROR,并且可以查看到配置的端口,说明基本无误
4、通过mysql的--dns-srv-name选项进行登录
这个选项只有在mysql的高版本中才支持,低版本会提示“unknown variable 'dns-srv-name=_mysqlx._tcp.e.proxy3.mysqldns.com'”
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
./mysql -utest1234 -ptest1234 --dns-srv-name=_mysqlx._tcp.e.proxy3.mysqldns.com 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 81768 Server version: 8.0.22 Source distribution Copyright (c) 2000, 2020, 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> |
相关参考:
关于DNS的:
https://www.cnblogs.com/f-ck-need-u/p/7367503.html
mysql使用DNS SRV Record登录的官方文档:
https://dev.mysql.com/doc/refman/8.0/en/connecting-using-dns-srv.html
rfc2782关于DNS-SRV的阐述:
https://datatracker.ietf.org/doc/html/rfc2782