linux's docs

31.1.0: DNS服务


0. 参考连接


1. 各种记录介绍

  • A记录, 把域名map到ip地址
  • CNAME, 把域名map到另外的域名上,访问时返回该域名,然后继续解析返回的域名 但是,当你对此域名做cname后,不可以对此域名继续做其他任何形式的解析 https://tools.ietf.org/html/rfc1912#section-2.4
  • alias,把域名map到X域名上,跟cname不同的是,它可以与其他针对于此域名的记录共存
  • url,把域名301重定向到目标域名上

2. oracle RAC使用dns来实现SCAN功能实战

1) 安装dns

# node1上执行此命令
yum install bind-libs bind bind-utils

2) 配置dns

# 主配文件
vim /etc/named.conf
******************************************************
options {
        # 配置dns服务监听的端口和ip
        listen-on port 53 { 127.0.0.1; 192.168.33.103; };
        ...
        # zone配置所在目录(保持默认)
        directory       "/var/named";
        ...
        # 允许使用dns服务的ip及ip段
        allow-query     { localhost; 127.0.0.1; 192.168.33.0/24; };
        ...
        # 此dns无法解析的,去哪里继续查询,这里指定局域网的公用dns
        forwarders {192.168.33.1; 10.0.0.4;};
};

# 增加正向解析规则,localdomain是我的测试环境,需要更新到正式环境所在的域
zone "localdomain." IN {
        type master;
        file "localdomain.zone";
        allow-update { none; };
};

# 增加反向解析规则
zone "33.168.192.in-addr.arpa." IN {
        type master;
        file "33.168.192.in-addr.arpa";
        allow-update { none; };
};

******************************************************

# 创建和上面配置域名称对应的zone文件,放在directory的配置目录中
vim /var/named/localdomain.zone
******************************************************
$TTL    86400
@               IN SOA  localhost root.localhost (
                                        42              ; serial (d. adams)
                                        3H              ; refresh
                                        15M             ; retry
                                        1W              ; expiry
                                        1D )            ; minimum
                IN NS           localhost
localhost       IN A            127.0.0.1
db-oracle-node1            IN A    192.168.33.103
db-oracle-node2            IN A    192.168.33.104
db-oracle-node1-vip        IN A    192.168.33.111
db-oracle-node2-vip        IN A    192.168.33.112
db-oracle-scan        IN A    192.168.33.120
db-oracle-scan        IN A    192.168.33.121
db-oracle-scan        IN A    192.168.33.122
******************************************************

vim /var/named/33.168.192.in-addr.arpa
******************************************************
$ORIGIN 33.168.192.in-addr.arpa.
$TTL 1H
@       IN      SOA     db-oracle-node1.localdomain.     root.db-oracle-node1.localdomain. (      2
                                                3H
                                                1H
                                                1W
                                                1H )
33.168.192.in-addr.arpa.         IN NS      db-oracle-node1.localdomain.

103     IN PTR  db-oracle-node1.localdomain.
104     IN PTR  db-oracle-node2.localdomain.
111     IN PTR  db-oracle-node1-vip.localdomain.
112     IN PTR  db-oracle-node2-vip.localdomain.
120     IN PTR  db-oracle-node-scan.localdomain.
121     IN PTR  db-oracle-node-scan.localdomain.
122     IN PTR  db-oracle-node-scan.localdomain.
******************************************************
## A记录和PTR记录
# A记录是将domain解析成ip
# PTR是将ip反解析成domain

3) 启动dns服务

service named start
chkconfig named on

4) 配置节点的dns

# 节点上配置dns
vim /etc/resolv.conf
******************************************************
search localdomain
nameserver 192.168.33.103
******************************************************

5) 检测oracle SCAN的解析

## host命令解析db-oracle-scan
host db-oracle-scan
db-oracle-scan.localdomain has address 192.168.33.120
db-oracle-scan.localdomain has address 192.168.33.121
db-oracle-scan.localdomain has address 192.168.33.122

## 检测SCAN的三个ip轮询
# 第一次请求
nslookup db-oracle-scan
Server:         192.168.33.103
Address:        192.168.33.103#53

Name:   db-oracle-scan.localdomain
Address: 192.168.33.120
Name:   db-oracle-scan.localdomain
Address: 192.168.33.121
Name:   db-oracle-scan.localdomain
Address: 192.168.33.122

# 第二次请求
nslookup db-oracle-scan
Server:         192.168.33.103
Address:        192.168.33.103#53

Name:   db-oracle-scan.localdomain
Address: 192.168.33.121
Name:   db-oracle-scan.localdomain
Address: 192.168.33.122
Name:   db-oracle-scan.localdomain
Address: 192.168.33.120

6) 检测每个节点的vip

# 检测node1的vip
host db-oracle-node1-vip
db-oracle-node1-vip.localdomain has address 192.168.33.111
nslookup db-oracle-node1-vip
Server:         192.168.33.103
Address:        192.168.33.103#53

Name:   db-oracle-node1-vip.localdomain
Address: 192.168.33.111

# 检测node2的vip
host db-oracle-node2-vip
db-oracle-node2-vip.localdomain has address 192.168.33.112

nslookup db-oracle-node2-vip
Server:         192.168.33.103
Address:        192.168.33.103#53

Name:   db-oracle-node2-vip.localdomain
Address: 192.168.33.112

7) 检测反向解析

## 检测反向解析
dig -x 192.168.33.120

; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.47.rc1.el6_8.3 <<>> -x 192.168.33.120
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 48957
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 1

;; QUESTION SECTION:
;120.33.168.192.in-addr.arpa.   IN      PTR

;; ANSWER SECTION:
120.33.168.192.in-addr.arpa. 3600 IN    PTR     db-oracle-node-scan.localdomain.

;; AUTHORITY SECTION:
33.168.192.in-addr.arpa. 3600   IN      NS      db-oracle-node1.localdomain.

;; ADDITIONAL SECTION:
db-oracle-node1.localdomain. 86400 IN   A       192.168.33.103

;; Query time: 0 msec
;; SERVER: 192.168.33.103#53(192.168.33.103)
;; WHEN: Fri Dec 23 02:39:47 2016
;; MSG SIZE  rcvd: 136

至此,我们提供了以下项目的ip解析

ip hostname
192.168.33.120 db-oracle-node-scan
192.168.33.121 db-oracle-node-scan
192.168.33.122 db-oracle-node-scan
192.168.33.103 db-oracle-node1
192.168.33.104 db-oracle-node2
192.168.33.111 db-oracle-node1-vip
192.168.33.112 db-oracle-node2-vip

Contents