二进制部署1.23.4版本k8s集群-2-安装DNS服务 - itteer
source link: https://www.cnblogs.com/wgh2008/p/16001543.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
2、安装DNS服务
为什么要安装bind9?
K8S中,使用Ingress进行7层流量调度,需要使用域名,进行7层调度。
以前使用绑定host的方法,来进行域名和IP地址的解析。
在K8S里,没有好的办法给容器绑定host,必须自建DNS,让容器能够服从DNS解析。
DNS,就是把域名和IP地址绑定。
在 11
主机上操作
2.1 安装bind9
[root@cfzx55-11 ~]# yum install bind -y
[root@cfzx55-11 ~]# rpm -qa bind
bind-9.11.4-26.P2.el7_9.9.x86_64
[root@cfzx55-11 ~]# rpm -qc bind
/etc/logrotate.d/named
/etc/named.conf
/etc/named.iscdlv.key
/etc/named.rfc1912.zones
/etc/named.root.key
/etc/rndc.conf
/etc/rndc.key
/etc/sysconfig/named
/var/named/named.ca
/var/named/named.empty
/var/named/named.localhost
/var/named/named.loopback
[root@cfzx55-11 ~]# rpm -ql bind
# 查看bind安装时执行的脚本
[root@cfzx55-11 ~]# rpm -q --scripts bind
preinstall scriptlet (using /bin/sh):
if [ "$1" -eq 1 ]; then
/usr/sbin/groupadd -g 25 -f -r named >/dev/null 2>&1 || :;
/usr/sbin/useradd -u 25 -r -N -M -g named -s /sbin/nologin -d /var/named -c Named named >/dev/null 2>&1 || :;
fi;
:;
......
[root@cfzx55-11 ~]#
说明:bind安装后,自动创建了named用户。
2.2 修改主配置文件
编辑/etc/named.conf
文件,修改如下部分。listen-on port 53
配置为本机的IP地址。allow-query
允许任意主机查询。forwarders
虚拟机的网关,可以访问外网。
[root@cfzx55-11 ~]# vim /etc/named.conf
options {
listen-on port 53 { 10.211.55.11; };
allow-query { any; };
forwarders { 10.211.55.1; }
recursion yes;
dnssec-enable no;
dnssec-validation no;
# 语法检查
[root@cfzx55-11 ~]# named-checkconf
2.3 区域配置文件
配置主机域(host.com)和业务域(od.com)。
编辑/etc/named.rfc1912.zones
文件,在文件最后增加下面内容。file
:域配置文件名称。allow-update
:填写DNS服务器的IP地址,允许dns服务器更新。
zone "host.com" IN {
type master;
file "host.com.zone";
allow-update { 10.211.55.11; };
};
zone "od.com" IN {
type master;
file "od.com.zone";
allow-update { 10.211.55.11; };
};
生产上规划主机名,和业务没有任何关系。不会使用mysql01,hadoop01等等名称。
主机名:地域+IP后两位
主机域:用比较好记忆的,没有实际意义的名称,如host.com
业务域:od.com
新建文件:/var/named/host.com.zone
,文件内容如下:
$ORIGIN host.com.
$TTL 600 ;
@ IN SOA dns.host.com. dnsadmin.host.com. (
2022031201 ; serial
10800 ; refresh
900 ; retry
604800 ; expire
86400 ) ; minimum
NS dns.host.com.
$TTL 60 ;
dns A 10.211.55.11
CFZX55-11 A 10.211.55.11
CFZX55-12 A 10.211.55.12
CFZX55-21 A 10.211.55.21
CFZX55-22 A 10.211.55.22
CFZX55-200 A 10.211.55.200
新建文件:/var/named/od.com.zone
,文件内容如下:
$ORIGIN od.com.
$TTL 600 ;
@ IN SOA dns.od.com. dnsadmin.od.com. (
2022031201 ; serial
10800 ; refresh
900 ; retry
604800 ; expire
86400 ) ; minimum
NS dns.od.com.
$TTL 60 ;
dns A 10.211.55.11
[root@cfzx55-11 ~]# named-checkconf
[root@cfzx55-11 ~]# named-checkzone host.com /var/named/host.com.zone
zone host.com/IN: loaded serial 2022031201
OK
[root@cfzx55-11 ~]# named-checkzone od.com /var/named/od.com.zonne
zone od.com/IN: loaded serial 2022031201
OK
[root@cfzx55-11 ~]#
2.4 启动named服务
# 启动服务
[root@hdss7-11 named]# systemctl start named
[root@hdss7-11 named]# systemctl status named
# 开启自启动
[root@cfzx55-11 ~]# systemctl enable named
查看网络监听端口
[root@hdss7-11 named]# netstat -luntp | grep 53
tcp 0 0 127.0.0.1:953 0.0.0.0:* LISTEN 18374/named
tcp 0 0 10.211.55.11:53 0.0.0.0:* LISTEN 18374/named
udp 0 0 10.211.55.11:53 0.0.0.0:* 18374/named
[root@hdss7-11 named]#
53 端口被监听,说明dns服务正常启动。
2.5 域名解析检查
用dig工具检查域名解析
[root@cfzx55-11 ~]# dig -t A cfzx55-11.host.com @10.211.55.11 +short
10.211.55.11
[root@cfzx55-11 ~]# dig -t A cfzx55-12.host.com @10.211.55.11 +short
10.211.55.12
[root@cfzx55-11 ~]# dig -t A cfzx55-21.host.com @10.211.55.11 +short
10.211.55.21
[root@cfzx55-11 ~]# dig -t A cfzx55-22.host.com @10.211.55.11 +short
10.211.55.22
[root@cfzx55-11 ~]# dig -t A cfzx55-200.host.com @10.211.55.11 +short
10.211.55.200
[root@cfzx55-11 ~]# dig -t A www.baidu.com @10.211.55.11 +short
www.a.shifen.com.
110.242.68.4
110.242.68.3
[root@cfzx55-11 ~]#
以上能正常解析,说明DNS服务以及能正常解析了。
2.6 配置客户端
让客户端能正常使用DNS服务。
一种方法上直接修改/etc/resolv.conf文件,另一种方法是修改网络配置文件中的DNS1,修改成DNS服务器地址。本例修改网络配置文件。
[root@cfzx55-11 ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0
DNS1=10.211.55.11
[root@cfzx55-11 ~]# systemctl restart network
在11主机上的resolv.conf文件中,添加search host.com
重启网卡后,系统会自动添加。
[root@hdss7-11 named]# cat /etc/resolv.conf
# Generated by NetworkManager
search host.com
nameserver 10.211.55.11
其余4台机器都做相应的修改。
这样就可以使用短域名了(直接使用主机名称)
[root@hdss7-11 named]# ping hdss7-200
PING HDSS7-200.host.com (10.211.55.200) 56(84) bytes of data.
64 bytes from 10.211.55.200 (10.211.55.200): icmp_seq=1 ttl=64 time=20.3 ms
64 bytes from 10.211.55.200 (10.211.55.200): icmp_seq=2 ttl=64 time=2.00 ms
一般来说,只需要加主机的search域,主机域使用短域名,业务域不使用短域名,因为业务域太多了,而且不同业务域中会有重名的主机。
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK