DHCP集群-(双机热备、DHCP主从服务器)

打印 上一主题 下一主题

主题 528|帖子 528|积分 1584

目次
DHCP双机热备是什么?
什么是高可用性?
一、配置服务器ip
1.查看服务器ip
2.配置服务器ip
二、修改主机名(利用远程终端链接)
三、检查防火墙、selinux状态
四、检测能都ping外网
         五、创建缓存
六、修改本地解析文件
七、时间同步
八、DHCP文件配置
九、假造机获取DHCP命令

DHCP双机热备是什么?

   DHCP服务器双机热备是一种高可用性的解决方案,旨在确保DHCP服务的连续性和稳固性。
  双机热备特指基于高可用体系中的两台服务器的热备,这种配置可以或许在一台服务器出现故障时,主动切换到另一台服务器,从而保证服务的可用性。DHCP服务器双机热备的出现主要是为了解决以下问题:
     

  • 服务停止问题
    在网络环境中,DHCP服务器负责动态分配IP地点给网络中的设备。如果DHCP服务器发生故障,那么新的设备可能无法获取IP地点,从而导致网络服务停止。双机热备通过部署两台服务器,当主服务器出现故障时,备服务器可以迅速接受服务,确保DHCP服务的连续性。
  • 数据安全性问题
    双机热备不仅提供了服务的冗余,还在肯定程度上保护了数据的安全性。在一台服务器出现故障时,另一台服务器上的数据仍然是安全的,这有助于减少数据丢失的风险。
  • 提高体系可靠性
    通过双机热备配置,可以大大提高体系的可靠性。即使在极度情况下,如硬件故障、自然灾难等,也能确保DHCP服务的正常运行。
    DHCP服务器双机热备通常分为两种切换方式:
  主-备方式(Active-Standby方式)和双主机方式(Active-Active方式)。
  

  • 在主-备方式中,一台服务器处于激活状态(Active),另一台服务器处于备用状态(Standby);
  • 而在双主机方式中,两台服务器都处于激活状态,但它们可能各自尊责不同的服务或数据。
  总的来说,DHCP服务器双机热备是一种为了提高DHCP服务的可用性、可靠性和数据安全性而计划的解决方案。
  
什么是高可用性?

   高可用(High Availability,简称HA)是指体系、应用或服务具有高度的可靠性和持续的可操作性,以减少由体系失效带来的影响。高可用性的主要目标是确保体系或服务在面临各种故障时,仍然可以或许保持其功能和性能,从而减少或制止服务停止。
  高可用性的实现通常涉及以下几个方面:
     

  • 冗余计划
    通过部署多个组件、体系或服务实例来确保即使其中一个或多个实例失败,其他实例仍然可以接受并继承提供服务。
    比方,在服务器集群中,可能会有多个服务器运行相同的服务,以便在其中一个服务器故障时,其他服务器可以继承提供服务。
  • 负载均衡
    通过负载均衡技术分散请求到多个服务器或组件上,以平衡负载并制止单点故障。
    这有助于确保单个组件的故障不会使整个体系瘫痪。
  • 故障检测和规复
    高可用体系必要可以或许快速检测到故障,并主动触发规复过程。
    这可能包括重新启动服务、切换到备用体系或将数据从故障组件迁徙到健康组件。
  • 数据备份和规复
    为了确保数据的完整性和可规复性,高可用体系通常包括数据备份和规复策略。
    这可以包括定期备份数据、利用RAID技术保护磁盘数据、实施数据复制策略等。
  • 灾难规复计划
    除了应对一样平常故障外,高可用体系还必要思量如何应对自然灾难、人为错误或其他灾难性事件。
    灾难规复计划通常包括在地理上分散的数据中央和备份设施,以确保在主要设施受到影响时,服务可以从备份设施中规复。
  • 持续监控和维护
    高可用体系必要持续的监控和维护,以确保所有组件都处于最佳状态。
    这包括定期检查硬件和软件状态、更新和修补体系、监控性能指标等。
    在云盘算、大数据和分布式体系等领域,高可用性尤为重要,因为这些体系中的任何停止都可能导致重大的业务影响。因此,计划和实施高可用策略是确保这些体系稳固运行的关键。
  1. /*
  2. 注(两个集群):
  3.       DHCP-master主控制集群(10.18.33.10)
  4.       DHCP-backup备用集群(10.18.33.20)
  5. */
复制代码


一、配置服务器ip

1.查看服务器ip

  1. # all now
  2. [root@localhost]# ip a
复制代码
2.配置服务器ip

  1. # DHCP-maseter
  2. [root@localhost]# cat /etc/sysconfig/network-scripts/ifcfg-ens33
  3. TYPE=Ethernet
  4. PROXY_METHOD=none
  5. BROWSER_ONLY=no
  6. BOOTPROTO=static
  7. DEFROUTE=yes
  8. IPV4_FAILURE_FATAL=no
  9. IPV6INIT=yes
  10. IPV6_AUTOCONF=yes
  11. IPV6_DEFROUTE=yes
  12. IPV6_FAILURE_FATAL=no
  13. IPV6_ADDR_GEN_MODE=stable-privacy
  14. NAME=ens33
  15. UUID=6dfe0ee1-6242-4fe3-b1b4-ad843af8d49c
  16. DEVICE=ens33
  17. ONBOOT=yes
  18. IPADDR=10.18.33.10
  19. NETMASK=255.255.255.0
  20. GATEWAY=10.18.33.254
  21. DNS=8.8.8.8
  22. # DHCP-backup
  23. [root@localhost]# cat /etc/sysconfig/network-scripts/ifcfg-ens33
  24. TYPE=Ethernet
  25. PROXY_METHOD=none
  26. BROWSER_ONLY=no
  27. BOOTPROTO=static
  28. DEFROUTE=yes
  29. IPV4_FAILURE_FATAL=no
  30. IPV6INIT=yes
  31. IPV6_AUTOCONF=yes
  32. IPV6_DEFROUTE=yes
  33. IPV6_FAILURE_FATAL=no
  34. IPV6_ADDR_GEN_MODE=stable-privacy
  35. NAME=ens33
  36. UUID=6dfe0ee1-6242-4fe3-b1b4-ad843af8d49c
  37. DEVICE=ens33
  38. ONBOOT=yes
  39. IPADDR=10.18.33.20
  40. NETMASK=255.255.255.0
  41. GATEWAY=10.18.33.254
  42. DNS=8.8.8.8
复制代码
二、修改主机名(利用远程终端链接)

  1. # DHCP-maseter
  2. [root@localhost]# hostnamectl set-hostname DHCP-maseter
  3. [root@localhost]# hostname
  4. [root@localhost]# bash
  5. # DHCP-backup
  6. [root@localhost]# hostnamectl set-hostname DHCP-backup
  7. [root@localhost]# hostname
  8. [root@localhost]# bash
复制代码
三、检查防火墙、selinux状态

  1. # all now(防火墙)
  2. [root@DHCP-maseter]# systemctl status firewalld
  3. ● firewalld.service - firewalld - dynamic firewall daemon
  4.   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
  5.   Active: active (running) since 日 2024-04-07 22:24:58 CST; 7h left
  6.     Docs: man:firewalld(1)
  7. Main PID: 812 (firewalld)
  8.   CGroup: /system.slice/firewalld.service
  9.           └─812 /usr/bin/python2 -Es /usr/sbin/firewalld --nofork --nopid
  10. 4月 07 22:24:58 localhost.localdomain systemd[1]: Starting firewalld - dynamic firewall dae.....
  11. 4月 07 22:24:58 localhost.localdomain systemd[1]: Started firewalld - dynamic firewall daemon.
  12. 4月 07 22:24:58 localhost.localdomain firewalld[812]: WARNING: AllowZoneDrifting is enabled...w.
  13. Hint: Some lines were ellipsized, use -l to show in full.
  14. [root@localhost]# systemctl stop firewalld
  15. [root@localhost]# systemctl disable firewalld
  16. Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
  17. Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
  18. # all now(SELinux)
  19. [root@DHCP-maseter]# setenforce 0
  20. [root@DHCP-maseter]# cat -n /etc/selinux/config
  21.     1
  22.     2  # This file controls the state of SELinux on the system.
  23.     3  # SELINUX= can take one of these three values:
  24.     4  #     enforcing - SELinux security policy is enforced.
  25.     5  #     permissive - SELinux prints warnings instead of enforcing.
  26.     6  #     disabled - No SELinux policy is loaded.
  27.     7  SELINUX=enforcing
  28.     8  # SELINUXTYPE= can take one of three values:
  29.     9  #     targeted - Targeted processes are protected,
  30.    10  #     minimum - Modification of targeted policy. Only selected processes are protected.
  31.    11  #     mls - Multi Level Security protection.
  32.    12  SELINUXTYPE=targeted
  33.    13
  34.    14
  35.    
  36. [root@DHCP-maseter]# sed -i "7s/enforcing/disabled/g" /etc/selinux/config
  37. [root@DHCP-maseter]# cat -n /etc/selinux/config
  38.     1
  39.     2  # This file controls the state of SELinux on the system.
  40.     3  # SELINUX= can take one of these three values:
  41.     4  #     enforcing - SELinux security policy is enforced.
  42.     5  #     permissive - SELinux prints warnings instead of enforcing.
  43.     6  #     disabled - No SELinux policy is loaded.
  44.     7  SELINUX=disabled
  45.     8  # SELINUXTYPE= can take one of three values:
  46.     9  #     targeted - Targeted processes are protected,
  47.    10  #     minimum - Modification of targeted policy. Only selected processes are protected.
  48.    11  #     mls - Multi Level Security protection.
  49.    12  SELINUXTYPE=targeted
  50.    13
  51.    14
复制代码
四、检测能都ping外网

  1. # all now
  2. [root@DHCP-maseter]# ping -c 2 10.18.33.1
  3. PING 10.18.33.1 (10.18.33.1) 56(84) bytes of data.
  4. 64 bytes from 10.18.33.1: icmp_seq=1 ttl=64 time=0.359 ms
  5. 64 bytes from 10.18.33.1: icmp_seq=2 ttl=64 time=0.323 ms
  6. --- 10.18.33.1 ping statistics ---
  7. 2 packets transmitted, 2 received, 0% packet loss, time 1000ms
  8. rtt min/avg/max/mdev = 0.323/0.341/0.359/0.018 ms
  9. [root@DHCP-maseter]# ping -c 2 10.18.33.254
  10. PING 10.18.33.254 (10.18.33.254) 56(84) bytes of data.
  11. 64 bytes from 10.18.33.254: icmp_seq=1 ttl=128 time=0.353 ms
  12. 64 bytes from 10.18.33.254: icmp_seq=2 ttl=128 time=0.208 ms
  13. --- 10.18.33.254 ping statistics ---
  14. 2 packets transmitted, 2 received, 0% packet loss, time 1000ms
  15. [root@DHCP-maseter]# ping -c 2 8.8.8.8
  16. PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
  17. 64 bytes from 8.8.8.8: icmp_seq=1 ttl=128 time=267 ms
  18. 64 bytes from 8.8.8.8: icmp_seq=2 ttl=128 time=986 ms
  19. --- 8.8.8.8 ping statistics ---
  20. 2 packets transmitted, 2 received, 0% packet loss, time 1000ms
  21. rtt min/avg/max/mdev = 267.991/627.284/986.578/359.294 ms
  22. [root@DHCP-maseter]# ping -c 2 baidu.com
  23. PING baidu.com (110.242.68.66) 56(84) bytes of data.
  24. 64 bytes from 110.242.68.66 (110.242.68.66): icmp_seq=1 ttl=128 time=182 ms
  25. 64 bytes from 110.242.68.66 (110.242.68.66): icmp_seq=2 ttl=128 time=301 ms
  26. --- baidu.com ping statistics ---
  27. 2 packets transmitted, 2 received, 0% packet loss, time 2191ms
  28. rtt min/avg/max/mdev = 182.404/242.190/301.977/59.788 ms
复制代码
五、创建缓存

  1. # all now
  2. [root@dhcp-maseter ~]# yum update
  3. [root@dhcp-maseter ~]# yum clean all && yum makecache && yum repolist
  4. 源标识                                      源名称                                        状态
  5. base/7/x86_64                              CentOS-7 - Base                           10,072
  6. extras/7/x86_64                            CentOS-7 - Extras                            526
  7. updates/7/x86_64                           CentOS-7 - Updates                         5,802
  8. repolist: 16,400
复制代码
六、修改本地解析文件

  1. # all now
  2. [root@dhcp-maseter ~]# cp /etc/hosts /etc/host.bak
  3. [root@dhcp-maseter ~]# echo "10.18.33.10    dhcp-maseter" >> /etc/hosts
  4. [root@dhcp-maseter ~]# echo "10.18.33.20    dhcp-backup" >> /etc/hosts
  5. [root@dhcp-maseter ~]# cat /etc/hosts
  6. 127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
  7. ::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
  8. 10.18.33.10    dhcp-maseter
  9. 10.18.33.20    dhcp-backup
  10. # 传送给dhcp-backup
  11. [root@dhcp-maseter ~]# scp /etc/hosts root@10.18.33.20:/etc/
复制代码
七、时间同步

  1. # all now
  2. [root@dhcp-maseter ~]# yum info ftp*
  3. [root@dhcp-maseter ~]# yum install -y ftp
  4. [root@dhcp-maseter ~]# yum install -y vim
  5. [root@dhcp-maseter ~]# cp /etc/chrony.conf /etc/chrony.bak
  6. # dhcp-maseter
  7. [root@dhcp-maseter ~]# cat /etc/chrony.conf
  8. # Use public servers from the pool.ntp.org project.
  9. # Please consider joining the pool (http://www.pool.ntp.org/join.html).
  10. server ntp.aliyun.com        iburst
  11. # Record the rate at which the system clock gains/losses time.
  12. driftfile /var/lib/chrony/drift
  13. # Allow the system clock to be stepped in the first three updates
  14. # if its offset is larger than 1 second.
  15. makestep 1.0 3
  16. # Enable kernel synchronization of the real-time clock (RTC).
  17. rtcsync
  18. # Enable hardware timestamping on all interfaces that support it.
  19. #hwtimestamp *
  20. # Increase the minimum number of selectable sources required to adjust
  21. # the system clock.
  22. #minsources 2
  23. # Allow NTP client access from local network.
  24. allow 10.18.33.0/24
  25. # Serve time even if not synchronized to a time source.
  26. #local stratum 10
  27. # Specify file containing keys for NTP authentication.
  28. #keyfile /etc/chrony.keys
  29. # Specify directory for log files.
  30. logdir /var/log/chrony
  31. # Select which information is logged.
  32. #log measurements statistics tracking
  33. # dhcp-backup
  34. [root@dhcp-backup ~]# cp /etc/chrony.conf /etc/chrony.bak
  35. [root@dhcp-backup ~]# cat /etc/chrony.conf
  36. # Use public servers from the pool.ntp.org project.
  37. # Please consider joining the pool (http://www.pool.ntp.org/join.html).
  38. server dhcp-maseter iburst
  39. # Record the rate at which the system clock gains/losses time.
  40. driftfile /var/lib/chrony/drift
  41. # Allow the system clock to be stepped in the first three updates
  42. # if its offset is larger than 1 second.
  43. makestep 1.0 3
  44. # Enable kernel synchronization of the real-time clock (RTC).
  45. rtcsync
  46. # Enable hardware timestamping on all interfaces that support it.
  47. #hwtimestamp *
  48. # Increase the minimum number of selectable sources required to adjust
  49. # the system clock.
  50. #minsources 2
  51. # Allow NTP client access from local network.
  52. #allow 10.18.33.0/24
  53. # Serve time even if not synchronized to a time source.
  54. #local stratum 10
  55. # Specify file containing keys for NTP authentication.
  56. #keyfile /etc/chrony.keys
  57. # Specify directory for log files.
  58. logdir /var/log/chrony
  59. # Select which information is logged.
  60. #log measurements statistics tracking
  61. # all now
  62. [root@dhcp-maseter ~]# systemctl restart chronyd
  63. [root@dhcp-maseter ~]# systemctl enable chronyd
  64. # dhcp-backup检测结果
  65. [root@dhcp-backup ~]# chronyc sources
  66. 210 Number of sources = 1
  67. MS Name/IP address         Stratum Poll Reach LastRx Last sample               
  68. ===============================================================================
  69. ^* dhcp-maseter                  3   6    17     7    +16us[ +131us] +/-   24ms
复制代码
八、DHCP文件配置

  1. # all now
  2. [root@dhcp-backup ~]# yum install -y dhcp
  3. # all now
  4. [root@dhcp-maseter ~]# rpm -qa | grep dhcp
  5. dhcp-common-4.2.5-83.el7.centos.1.x86_64
  6. dhcp-4.2.5-83.el7.centos.1.x86_64
  7. dhcp-libs-4.2.5-83.el7.centos.1.x86_64
  8. # all now
  9. [root@dhcp-maseter ~]# cp /etc/dhcp/dhcpd.conf /etc/dhcp/dhcpd.bak
  10. # dhcp-maseter
  11. [root@dhcp-maseter ~]# cat /etc/dhcp/dhcpd.conf
  12. # DHCP Server Configuration file.
  13. #   see /usr/share/doc/dhcp*/dhcpd.conf.example
  14. #   see dhcpd.conf(5) man page
  15. #dhcpd.conf
  16. #
  17. # Sample configuration file for ISC dhcpd
  18. #
  19. # dhcp不会自动更新dns服务器
  20. ddns-update-style none;
  21. # 默认租约时间。客户机通过DHCP获取IP后,这个IP使用时间是多久。单位秒
  22. default-lease-time 7200;
  23. # 最大租约时间。秒
  24. max-lease-time 14400;
  25. failover peer "dhcp" {
  26.         # 是主服务器还是辅助服务器
  27.         primary;
  28.         #本地监听failover的IP
  29.         address 10.18.33.10;
  30.         #本地监听failover的端口
  31.         port 520;
  32.         #secondary服务器的IP
  33.         peer address 10.18.33.20;
  34.         #secondary服务的监听端口
  35.         peer port 519;      
  36.         #同步信息最大时间延迟
  37.         max-response-delay 10;      
  38.         #在未收到 PARTNER 回复时,BNDUPD 消息的最多重发次数
  39.         max-unacked-updates 10;
  40.         #Maximum Client Lead Time. 在灾备方案中,该时间延迟保证 PARTNER 上的 IP 租约已经过期。
  41.         #该参数只能定义在主服务器中。
  42.         mclt 7200;
  43.         #主辅服务器的地址分割,通常是各一半
  44.         split 128;  
  45.         #关于负载均衡的参数  
  46.         load balance max seconds 3;   
  47. }
  48. #DHCP作用域
  49. subnet 10.18.33.0 netmask 255.255.255.0 {
  50.     #设置路由器的IP(网关)
  51.     option routers 10.18.33.254;   
  52.     #DNS
  53.     option domain-name-servers 8.8.8.8,114.114.114.114;  
  54.     pool {
  55.           failover peer "dhcp";
  56.           # 地址池范围
  57.           range 10.18.33.30 10.18.33.240;
  58.           #failover不支持bootp客户端,必须拒绝
  59.           deny dynamic bootp clients;
  60.    }
  61. #   #指定MAC地址和IP地址的绑定
  62. #   host clevercode{
  63. #       hardware ethernet 00:0C:29:DB:6F;
  64. #       # 保留地址必须是range范围内的
  65. #       fixed-address 10.18.33.241;
  66. #   }
  67. }
  68. # dhcp-lookup
  69. [root@dhcp-backup ~]# cat /etc/dhcp/dhcpd.conf
  70. # DHCP Server Configuration file.
  71. #   see /usr/share/doc/dhcp*/dhcpd.conf.example
  72. #   see dhcpd.conf(5) man page
  73. # dhcpd.conf
  74. #
  75. # Sample configuration file for ISC dhcpd
  76. #
  77. # dhcp会不会自动更新dns服务器
  78. ddns-update-style none;
  79. # 默认租约时间。客户机通过DHCP获取IP后,这个IP使用时间是多久。单位秒
  80. default-lease-time 7200;
  81. # 最大租约时间。分钟
  82. max-lease-time 14400;
  83. failover peer "dhcp" {
  84.     # 是主服务器还是辅助服务器
  85.     secondary;
  86.     #本地监听failover的IP
  87.     address 10.18.33.20;
  88.     #本地监听failover的端口
  89.     port 519;
  90.     #primary服务器的IP
  91.     peer address 10.18.33.10;
  92.     #primary服务的监听端口
  93.     peer port 520;
  94.     #同步信息最大时间延迟
  95.     max-response-delay 10;
  96.     #在未收到 PARTNER 回复时,BNDUPD 消息的最多重发次数
  97.     max-unacked-updates 10;
  98.     #关于负载均衡的参数                     
  99.     load balance max seconds 3;
  100. }
  101. #DHCP作用域
  102. subnet 10.18.33.0 netmask 255.255.255.0 {
  103.     #设置路由器的IP(网关)
  104.     option routers 10.18.33.254;
  105.     #DNS
  106.     option domain-name-servers 8.8.8.8,114.114.114.114;
  107.     pool {
  108.     failover peer "dhcp";
  109.     # 地址池范围
  110.     range 10.18.33.30 10.18.33.240;
  111.     #failover不支持bootp客户端,必须拒绝
  112.     deny dynamic bootp clients;
  113.     }
  114. #    #指定MAC地址和IP地址的绑定
  115. #      host clevercode{
  116. #          hardware ethernet 00:0C:29:DB:6F;
  117. #          # 保留地址必须是range范围内的
  118. #          fixed-address 172.16.159.101;
  119. #      }
  120. }
  121. # all now
  122. [root@dhcp-backup ~]# systemctl restart dhcpd
  123. [root@dhcp-backup ~]# systemctl enable dhcpd
  124. [root@dhcp-backup ~]# systemctl status dhcpd
复制代码


九、假造机获取DHCP命令

  1. # 创建一台新的虚拟机
  2. [root@localhost]# cat /etc/sysconfig/network-scripts/ifcfg-ens33
  3. TYPE=Ethernet
  4. PROXY_METHOD=none
  5. BROWSER_ONLY=no
  6. BOOTPROTO=dhcp
  7. DEFROUTE=yes
  8. IPV4_FAILURE_FATAL=no
  9. IPV6INIT=yes
  10. IPV6_AUTOCONF=yes
  11. IPV6_DEFROUTE=yes
  12. IPV6_FAILURE_FATAL=no
  13. IPV6_ADDR_GEN_MODE=stable-privacy
  14. NAME=ens33
  15. UUID=6dfe0ee1-6242-4fe3-b1b4-ad843af8d49c
  16. DEVICE=ens33
  17. ONBOOT=yes
  18. [root@localhost]# systemctl restart network
  19. [root@localhost]# dhclient
复制代码


免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

水军大提督

金牌会员
这个人很懒什么都没写!

标签云

快速回复 返回顶部 返回列表