在CentOS上配置DHCP故障转移可以确保在主DHCP服务器出现故障时,备用DHCP服务器能够接管并继续提供IP地址分配服务。以下是详细的步骤:
首先,确保两台服务器上都安装了DHCP服务器软件包。
sudo yum install dhcp
编辑主DHCP服务器的配置文件 /etc/dhcp/dhcpd.conf。
sudo vi /etc/dhcp/dhcpd.conf
添加或修改以下内容:
option domain-name "example.com";
option domain-name-servers ns1.example.com, ns2.example.com;
default-lease-time 600;
max-lease-time 7200;
subnet 192.168.1.0 netmask 255.255.255.0 {
range 192.168.1.10 192.168.1.100;
option routers 192.168.1.1;
option subnet-mask 255.255.255.0;
option broadcast-address 192.168.1.255;
option domain-name-servers 8.8.8.8, 8.8.4.4;
}
编辑备用DHCP服务器的配置文件 /etc/dhcp/dhcpd.conf,内容与主服务器相同。
sudo vi /etc/dhcp/dhcpd.conf
编辑主DHCP服务器的 /etc/dhcp/dhcpd.conf 文件,添加故障转移配置。
sudo vi /etc/dhcp/dhcpd.conf
在文件末尾添加以下内容:
failover peer "dhcp-failover" {
primary; # 标识为主服务器
address 192.168.1.2; # 主服务器的IP地址
port 647;
peer address 192.168.1.3; # 备用服务器的IP地址
peer port 647;
max-response-delay 30;
max-unacked-updates 10;
load balance max seconds 3;
mclt 600;
}
编辑备用DHCP服务器的 /etc/dhcp/dhcpd.conf 文件,添加故障转移配置。
sudo vi /etc/dhcp/dhcpd.conf
在文件末尾添加以下内容:
failover peer "dhcp-failover" {
secondary; # 标识为备用服务器
address 192.168.1.3; # 备用服务器的IP地址
port 647;
peer address 192.168.1.2; # 主服务器的IP地址
peer port 647;
max-response-delay 30;
max-unacked-updates 10;
load balance max seconds 3;
}
在两台服务器上启动DHCP服务。
sudo systemctl start dhcpd
sudo systemctl enable dhcpd
确保两台服务器上的DHCP服务都已启动并正常运行。
sudo systemctl status dhcpd
可以通过停止主DHCP服务器来测试故障转移。
sudo systemctl stop dhcpd
检查备用DHCP服务器是否接管了IP地址分配服务。
sudo systemctl status dhcpd
如果备用服务器正常运行,说明故障转移配置成功。
通过以上步骤,你可以在CentOS上配置DHCP故障转移,确保网络的高可用性。