ÔõÑùÔÚLinuxÉÏÉèÖø߿ÉÓõÄDNS¼¯Èº
ÔõÑùÔÚlinuxÉÏÉèÖø߿ÉÓõÄdns¼¯Èº
СÐò£º
Ëæ×Å»¥ÁªÍøµÄѸÃÍÉú³¤£¬DNS (Domain Name System) ×÷ΪÖ÷ÒªµÄÍøÂç»ù´¡ÉèÊ©Ö®Ò»£¬ÊÎÑÝ׎«ÓòÃûת»»Îª IP µØµãµÄÒªº¦½ÇÉ«¡£ÔÚ´óÁ÷Á¿µÄÍøÂçÇéÐÎÖУ¬DNS ЧÀÍÆ÷µÄ¸ß¿ÉÓÃÐԾͱäµÃÖÁ¹ØÖ÷Òª¡£±¾ÎĽ«ÏÈÈÝÔõÑùÔÚ Linux ϵͳÉÏÉèÖø߿ÉÓÃµÄ DNS ¼¯Èº£¬²¢ÌṩһЩ´úÂëʾÀý¡£
×°Öà DNS ЧÀÍÆ÷£º
Ê×ÏÈ£¬ÎÒÃÇÐèÒªÔÚ Linux ϵͳÉÏ×°Öà DNS ЧÀÍÆ÷¡£±¾ÎÄÒÔ³£ÓÃµÄ BIND£¨Berkeley Internet Name Domain£©Ð§ÀÍÆ÷ΪÀý£¬¾ÙÐÐÉèÖá£Ö´ÐÐÒÔÏÂÏÂÁîÀ´×°Öà BIND£º
sudo apt-get update sudo apt-get install bind9
µÇ¼ºó¸´ÖÆ
ÉèÖÃÖ÷ DNS ЧÀÍÆ÷£º
½ÓÏÂÀ´£¬ÎÒÃÇÐèÒªÔÚÖ÷ DNS ЧÀÍÆ÷ÉϾÙÐÐÉèÖ᣷¿ª BIND µÄÖ÷ÉèÖÃÎļþ /etc/bind/named.conf.local£¬²¢Ìí¼ÓÒÔÏÂÄÚÈÝ£º
zone "example.com" { type master; file "/etc/bind/db.example.com"; allow-transfer { IP_ADDRESS_OF_SECONDARY_DNS_SERVER; }; };
µÇ¼ºó¸´ÖÆ
×¢Öؽ« example.com Ì滻ΪÄã×Ô¼ºµÄÓòÃû£¬²¢½« IP_ADDRESS_OF_SECONDARY_DNS_SERVER Ì滻Ϊ¸¨Öú DNS ЧÀÍÆ÷µÄ IP µØµã¡£
È»ºó£¬½¨ÉèÓòÃûÆÊÎöÎļþ /etc/bind/db.example.com£¬²¢Ìí¼ÓÒÔÏÂÄÚÈÝ£º
; ; BIND data file for example.com ; $TTL 604800 @ IN SOA ns1.example.com. admin.example.com. ( 3 ; Serial 604800 ; Refresh 86400 ; Retry 2419200 ; Expire 604800 ) ; Negative Cache TTL ; @ IN NS ns1.example.com. @ IN A IP_ADDRESS_OF_PRIMARY_DNS_SERVER ns1 IN A IP_ADDRESS_OF_PRIMARY_DNS_SERVER www IN CNAME example.com.
µÇ¼ºó¸´ÖÆ
È·±£½« example.com Ì滻ΪÄã×Ô¼ºµÄÓòÃû£¬²¢½« IP_ADDRESS_OF_PRIMARY_DNS_SERVER Ì滻ΪÖ÷ DNS ЧÀÍÆ÷µÄ IP µØµã¡£
ÉèÖø¨Öú DNS ЧÀÍÆ÷£º
½Ó×Å£¬ÎÒÃÇÐèÒªÔÚ¸¨Öú DNS ЧÀÍÆ÷ÉϾÙÐÐÉèÖ᣷¿ª BIND µÄÖ÷ÉèÖÃÎļþ /etc/bind/named.conf.local£¬²¢Ìí¼ÓÒÔÏÂÄÚÈÝ£º
zone "example.com" { type slave; file "/etc/bind/db.example.com"; masters { IP_ADDRESS_OF_PRIMARY_DNS_SERVER; }; };
µÇ¼ºó¸´ÖÆ
ͬÑùµØ£¬½« example.com Ì滻ΪÄã×Ô¼ºµÄÓòÃû£¬²¢½« IP_ADDRESS_OF_PRIMARY_DNS_SERVER Ì滻ΪÖ÷ DNS ЧÀÍÆ÷µÄ IP µØµã¡£
Æô¶¯ DNS ЧÀÍÆ÷£º
Íê³ÉÉèÖúó£¬ÎÒÃÇÐèÒªÆô¶¯ DNS ЧÀÍÆ÷£¬²¢Ê¹ÆäÔÚϵͳÆô¶¯Ê±×Ô¶¯Æô¶¯¡£Ö´ÐÐÒÔÏÂÏÂÁî»®·ÖÆô¶¯Ö÷ DNS ºÍ¸¨Öú DNS£º
sudo systemctl start bind9 sudo systemctl enable bind9
µÇ¼ºó¸´ÖÆ
ÉèÖø߿ÉÓÃÐÔ£º
ΪÁËʵÏָ߿ÉÓÃµÄ DNS ЧÀÍ£¬ÎÒÃÇ¿ÉÒÔʹÓøºÔØƽºâºÍ¹ÊÕÏתÒÆÊÖÒÕ¡£ÕâÀïÎÒÃÇʹÓà Keepalived ºÍ HAProxy ʵÏÖ¸ºÔØƽºâºÍ¹ÊÕÏתÒÆ¡£
Ê×ÏÈ£¬×°Öà Keepalived ºÍ HAProxy£º
sudo apt-get install keepalived sudo apt-get install haproxy
µÇ¼ºó¸´ÖÆ
È»ºó£¬»®·ÖÔÚÖ÷ DNS ЧÀÍÆ÷ºÍ¸¨Öú DNS ЧÀÍÆ÷ÉϾÙÐÐÉèÖá£
ÔÚÖ÷ DNS ЧÀÍÆ÷ÉÏ£¬±à¼ Keepalived µÄÉèÖÃÎļþ /etc/keepalived/keepalived.conf£¬Ìí¼ÓÒÔÏÂÄÚÈÝ£º
global_defs { router_id LVS_DEVEL } vrrp_instance VI_1 { state MASTER interface eth0 virtual_router_id 51 priority 100 virtual_ipaddress { IP_ADDRESS_OF_DNS_CLUSTER } }
µÇ¼ºó¸´ÖÆ
½« IP_ADDRESS_OF_DNS_CLUSTER Ì滻ΪÓÃÓÚ¸ºÔØƽºâµÄÐéÄâ IP µØµã¡£
ÔÚ¸¨Öú DNS ЧÀÍÆ÷ÉÏ£¬±à¼ Keepalived µÄÉèÖÃÎļþ /etc/keepalived/keepalived.conf£¬Ìí¼ÓÒÔÏÂÄÚÈÝ£º
global_defs { router_id LVS_DEVEL } vrrp_instance VI_1 { state BACKUP interface eth0 virtual_router_id 51 priority 99 virtual_ipaddress { IP_ADDRESS_OF_DNS_CLUSTER } }
µÇ¼ºó¸´ÖÆ
ͬÑùµØ£¬½« IP_ADDRESS_OF_DNS_CLUSTER Ì滻ΪÓÃÓÚ¸ºÔØƽºâµÄÐéÄâ IP µØµã¡£
×îºó£¬ÔÚÖ÷ DNS ЧÀÍÆ÷ºÍ¸¨Öú DNS ЧÀÍÆ÷ÉÏ»®·Ö±à¼ HAProxy µÄÉèÖÃÎļþ /etc/haproxy/haproxy.cfg£¬²Î¿¼ÒÔÏÂʾÀý£º
frontend dns_cluster bind IP_ADDRESS_OF_DNS_CLUSTER:53 mode tcp default_backend dns_servers backend dns_servers mode tcp balance roundrobin server primary_dns IP_ADDRESS_OF_PRIMARY_DNS_SERVER:53 check server secondary_dns IP_ADDRESS_OF_SECONDARY_DNS_SERVER:53 check
µÇ¼ºó¸´ÖÆ
È·±£½« IP_ADDRESS_OF_DNS_CLUSTER Ì滻ΪÓÃÓÚ¸ºÔØƽºâµÄÐéÄâ IP µØµã£¬²¢½« IP_ADDRESS_OF_PRIMARY_DNS_SERVER ºÍ IP_ADDRESS_OF_SECONDARY_DNS_SERVER Ì滻ΪÖ÷ DNS ЧÀÍÆ÷ºÍ¸¨Öú DNS ЧÀÍÆ÷µÄ IP µØµã¡£
Æô¶¯ºÍ²âÊÔ£º
Íê³ÉÉèÖúó£¬ÎÒÃÇÆô¶¯ Keepalived ºÍ HAProxy ЧÀÍ£¬²¢¼ì²é DNS ЧÀ͵ĿÉÓÃÐÔ¡£ÔÚÖ÷ DNS ЧÀÍÆ÷ºÍ¸¨Öú DNS ЧÀÍÆ÷ÉÏÖ´ÐÐÒÔÏÂÏÂÁîÀ´Æô¶¯Ð§ÀÍ£º
sudo systemctl start keepalived sudo systemctl start haproxy
µÇ¼ºó¸´ÖÆ
È»ºó£¬Í¨¹ýÓòÃûÆÊÎö¹¤¾ß£¨Èç dig£©À´²âÊÔ DNS ЧÀÍÊÇ·ñÕý³£ÊÂÇé¡£ÀýÈçÖ´ÐÐÒÔÏÂÏÂÁ
dig example.com @IP_ADDRESS_OF_DNS_CLUSTER
µÇ¼ºó¸´ÖÆ
È·±£½« IP_ADDRESS_OF_DNS_CLUSTER Ì滻ΪÓÃÓÚ¸ºÔØƽºâµÄÐéÄâ IP µØµã¡£
½áÂÛ£º
ͨ¹ý±¾ÎĵÄÏÈÈݺʹúÂëʾÀý£¬ÄãÒѾѧ»áÔõÑùÔÚ Linux ϵͳÉÏÉèÖø߿ÉÓÃµÄ DNS ¼¯Èº¡£Í¨¹ý¸ºÔØƽºâºÍ¹ÊÕÏתÒÆÊÖÒÕ£¬Äã¿ÉÒÔÌá¸ß DNS ЧÀÍÆ÷µÄ¿ÉÓÃÐÔºÍÐÔÄÜ£¬È·±£ÍøÂçЧÀ͵ÄÎȹÌÐÔ¡£×£ÄãÔÚÉèÖø߿ÉÓÃµÄ DNS ¼¯ÈºÊ±È¡µÃÀֳɣ¡
ÒÔÉϾÍÊÇÔõÑùÔÚLinuxÉÏÉèÖø߿ÉÓõÄDNS¼¯ÈºµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡