【DNS】小项目内部DNS解决方案

一、环境信息

serverA  192.168.1.101

serverB  192.168.1.102

bind9_vip  192.168.1.110

二、组件安装

在serverA 和 serverB 上

# yum  -y  install  keepalived  bind-utils

# sysctl -w net.ipv4.ip_nonlocal_bind=1

# echo "net.ipv4.ip_nonlocal_bind=1" >> /etc/sysctl.conf

注:更改Linux系统控制文件,使得端口即使监听在不存在的IP上,也不报错

# setenforce 0

# sed -i 's/^SELINUX=.*/SELINUX=permissive/g'   /etc/selinux/config

# systemctl stop   firewalld

# systemctl diable firewalld

三、serverA服务配置

# vim  /etc/keepalived/keepalived.conf

##############################

! Configuration File for keepalived

global_defs {

   router_id LVS_DEVEL

}

vrrp_script check { 

    script "/etc/keepalived/check.sh" 

    interval 5     

}   

vrrp_instance VI_1 {

    state BACKUP

    interface eno16777736

    virtual_router_id 100

    priority 100

    advert_int 1

    nopreempt

    authentication {

        auth_type PASS

        auth_pass 1111

    }

    track_script {   

      check

    }   

    virtual_ipaddress {

        192.168.1.110

    }

}

##############################

# vim /etc/named.conf

##########################################

options {

        listen-on port 53 { 192.168.1.110; };

        listen-on-v6 port 53 { ::1; };

        directory       "/var/named";

        dump-file       "/var/named/data/cache_dump.db";

        statistics-file "/var/named/data/named_stats.txt";

        memstatistics-file "/var/named/data/named_mem_stats.txt";

        allow-query     { any; };

        recursion yes;

        dnssec-enable yes;

        dnssec-validation yes;

        pid-file "/run/named/named.pid";

};

zone "example.com" IN {

        type master;

        file "example.com.zone";

};

###############################################

# cp  -p  /var/named/named.localhost  /var/named/example.com.zone

# vim  /var/named/example.com.zone

###############################################

$TTL 3D

@ IN SOA  ns.example.com (

                             2021100

                             28800

                            14400

                             3600000

                             86400

)

         NS  ns                               

         IN A   xx.xx.xx.xx        

www      IN A   xx.xx.xx.xx           

mysql     IN A   xx.xx.xx.xx       

##############################################

四、serverB服务配置

# vim  /etc/keepalived/keepalived.conf

####################################

! Configuration File for keepalived

global_defs {

   router_id LVS_DEVEL

}

vrrp_script check { 

    script "/etc/keepalived/check.sh" 

    interval 5     

}   

vrrp_instance VI_1 {

    state BACKUP

    interface eno16777736

    virtual_router_id 100

    priority 90

    advert_int 1

    authentication {

        auth_type PASS

        auth_pass 1111

    }

    track_script {   

      check

    }   

    virtual_ipaddress {

        192.168.1.110

    }

}

##################################

# vim /etc/named.conf

##########################################

options {

        listen-on port 53 { 192.168.1.110; };

        listen-on-v6 port 53 { ::1; };

        directory       "/var/named";

        dump-file       "/var/named/data/cache_dump.db";

        statistics-file "/var/named/data/named_stats.txt";

        memstatistics-file "/var/named/data/named_mem_stats.txt";

        allow-query     { any; };

        recursion yes;

        dnssec-enable yes;

        dnssec-validation yes;

        pid-file "/run/named/named.pid";

};

zone "example.com" IN {

        type master;

        file "example.com.zone";

};

###############################################

# cp  -p  /var/named/named.localhost  /var/named/example.com.zone

# vim  /var/named/example.com.zone

###############################################

$TTL 3D

@ IN SOA  ns.example.com (

                             2021100

                             28800

                            14400

                             3600000

                             86400

)

         NS  ns                               

         IN A   xx.xx.xx.xx        

www      IN A   xx.xx.xx.xx           

mysql     IN A   xx.xx.xx.xx       

##############################################

五、在serverA serverB 

################################################################

#!/bin/bash

if ! ps -C named--no-header | wc -l > /dev/null 2>&1; then

  systemctl restart named

  sleep 1

  if ! ps -C named--no-header | wc -l > /dev/null 2>&1; then

    exit 1

  fi

fi

################################################################

#  systemctl restart  named  keepalived

六、测试

在测试机器

# vim  /etc/resolv.conf

#########################

nameserver 192.168.1.110

#########################

测试DNS域名解析

# ping www.example.com

# ping mysql.example.com

Supongo que te gusta

Origin blog.csdn.net/michaelwoshi/article/details/121450238
Recomendado
Clasificación