Centos 7 dhcp集群搭建
dhcp集群搭建
一、两台centos7安装dhcp服务,并设定开机自启
yum install dhcp -y
systemctl enable dhcpd
二、编辑dhcpd.conf配置文件
1、primary服务器:
vim /etc/dhcp/dhcpd.conf
ddns-update-style none; #dhcp不更新dns default-lease-time 7200; #默认的地址租约,单位秒 max-lease-time 14400; #最大的地址租约,单位秒 option domain-name-servers 114.114.114.114; option domain-name "cmsk1979.local"; #dns的后缀 failover peer "dhcp" { primary; address 192.168.243.130; port 67; peer address 192.168.243.129; peer port 67; max-response-delay 60; #同步信息最大时间延迟 max-unacked-updates 10; #在未收到 PARTNER 回复时,BNDUPD 消息的最多重发次数 mclt 7200; #Maximum Client Lead Time. 在灾备方案中,该时间延迟保证 PARTNER 上的 IP 租约已经过期,注:该参数只能定义在主服务器中 split 128; #以24位的子网,主辅服务器的地址分割,通常是各一半,128个ip地址 load balance max seconds 3; } include "/etc/dhcp/dhcpd.master"; ~
vim /etc/dhcp/dhcpd.master
subnet 192.168.243.0 netmask 255.255.255.0 { option routers 192.168.243.2; pool { range 192.168.243.10 192.168.243.20; failover peer "dhcp"; deny dynamic bootp clients; } host host1 { hardware ethernet 00:50:56:C0:00:01; fixed-address 192.168.243.18; } }
2、secondary服务器:
vim /etc/dhcp/dhcpd.conf
ddns-update-style none; default-lease-time 7200; max-lease-time 14400; option domain-name-servers 114.114.114.114; option domain-name "cmsk1979.local"; failover peer "dhcp" { secondary; address 192.168.243.129; port 67; peer address 192.168.243.130; peer port 67; max-response-delay 60; max-unacked-updates 10; load balance max seconds 3; } include "/etc/dhcp/dhcpd.master"; ~
vim /etc/dhcp/dhcpd.master
subnet 192.168.243.0 netmask 255.255.255.0 { option routers 192.168.243.2; pool { range 192.168.243.10 192.168.243.20; failover peer "dhcp"; deny dynamic bootp clients; } host host1 { hardware ethernet 00:50:56:C0:00:01; fixed-address 192.168.243.18; } }
三、配置定时任务实现两台间的配置文件同步
1、sh-keygen -t rsa 生成秘钥
2、cd /root/.ssh/ && ssh-copy-id -i id_rsa.pub root@192.168.243.129 将密码分发给对应的主机
3、vim dhcp_syc.sh
scp /etc/dhcp/dhcpd.master root@192.168.243.129:/etc/dhcp/
4、master配置计划任务
*/2 * * * * sh dhcp_syc.sh
*/2 * * * * systemctl restart dhcpd
5、secondary配置计划任务
*/2 * * * * systemctl restart dhcpd