[Win服务器] WINDOWS2016故障转移群集(图文教程)

2406 0
王子 2022-10-19 15:05:07 | 显示全部楼层 |阅读模式
WIN2016故障转移群集
准备工作:
主机名
IP
域名
WINA
192.168.0.24
WINA.NET
WINB
192.168.0.25
WINB.NET
WINC
192.168.0.26
WINC.NET
所有主机配置主机信息 修改好主机名IP  DNS为本机IP   (以单台主机A为例)




互相ping测试连通性 (以单台主机A为例)


所有主机安装角色功能 DNS和故障转移群集 (以单台主机A为例)








所有主机配置DNS解析记录 并测试解析
新建正向查找区域NET


















新建反向查找区域
















新建正向查找区域记录 默认已生成本机记录














新建反向查找记录  (我们新建正向记录勾选了PTR指针 默认已经新建了B/C主机的反向记录) 现在只需新建一条本机的PTR记录






测试解析




A主机配置故障转移群集 B/C主机连接到群集 指定虚拟IP192.168.0.88
主机A创建群集TEST


















主机B/C连接到群集TEST
主机B(192.168.0.25)




查看群集当前在用主机为哪台  (网卡应有88IP)


所有主机安装IIS    80端口为默认网页 访问测试


















关闭掉在用主机(网卡有88的主机 同时只会有一台)  查看在用主机被选为了哪台 192.168.0.88:80是否还可以打开 (使用网络中其他主机来打开网页)
关闭掉A主机后 B主机拥有了88IP 网页依然可以打开




继续关闭B主机




此时C主机拥有了88IP  网页依然可以打开
参考:
https://blog.csdn.net/demonson/article/details/81708809
注:
经后期测试 建议不要将群集所有主机全部宕机 否则会出现问题
进阶:
以上内容为群集搭建及群集中某主机宕机后恢复业务的情况
下面记录一种主机没有宕机 IIS站点挂掉无法提供服务的情况  
新建文本文档 修改为IIS.vbs  内容如下(虚线内内容)  注意修改网站和应用程序池名称(默认无需修改)
  1. '<begin script sample>
  2. 'This script provides high availability for IIS websites
  3. 'By default, it monitors the "Default Web Site" and "DefaultAppPool"
  4. 'To monitor another web site, change the SITE_NAME below
  5. 'To monitor another application pool, change the APP_POOL_NAME below
  6. 'More thorough and application-specific health monitoring logic can be added to the script if needed
  7. Option Explicit
  8. DIM SITE_NAME
  9. DIM APP_POOL_NAME
  10. Dim START_WEB_SITE
  11. Dim START_APP_POOL
  12. Dim SITES_SECTION_NAME
  13. Dim APPLICATION_POOLS_SECTION_NAME
  14. Dim CONFIG_APPHOST_ROOT
  15. Dim STOP_WEB_SITE
  16. 'Note:
  17. 'Replace this with the site and application pool you want to configure high availability for
  18. 'Make sure that the same web site and application pool in the script exist on all cluster nodes. Note that the names are case-sensitive.
  19. SITE_NAME = "Default Web Site" '网站名称
  20. APP_POOL_NAME = "DefaultAppPool" '应用程序池名
  21. START_WEB_SITE = 0
  22. START_APP_POOL = 0
  23. STOP_WEB_SITE  = 1
  24. SITES_SECTION_NAME = "system.applicationHost/sites"
  25. APPLICATION_POOLS_SECTION_NAME = "system.applicationHost/applicationPools"
  26. CONFIG_APPHOST_ROOT = "MACHINE/WEBROOT/APPHOST"
  27. 'Helper script functions
  28. 'Find the index of the website on this node
  29. Function FindSiteIndex(collection, siteName)
  30.     Dim i
  31.     FindSiteIndex = -1   
  32.     For i = 0 To (CInt(collection.Count) - 1)
  33.         If collection.Item(i).GetPropertyByName("name").Value = siteName Then
  34.             FindSiteIndex = i
  35.             Exit For
  36.         End If      
  37.     Next
  38. End Function
  39. 'Find the index of the application pool on this node
  40. Function FindAppPoolIndex(collection, appPoolName)
  41.     Dim i
  42.     FindAppPoolIndex = -1   
  43.     For i = 0 To (CInt(collection.Count) - 1)
  44.         If collection.Item(i).GetPropertyByName("name").Value = appPoolName Then
  45.             FindAppPoolIndex = i
  46.             Exit For
  47.         End If      
  48.     Next
  49. End Function
  50. 'Get the state of the website
  51. Function GetWebSiteState(adminManager, siteName)
  52.     Dim sitesSection, sitesSectionCollection, siteSection, index, siteMethods, startMethod, executeMethod
  53.     Set sitesSection = adminManager.GetAdminSection(SITES_SECTION_NAME, CONFIG_APPHOST_ROOT)
  54.     Set sitesSectionCollection = sitesSection.Collection
  55.     index = FindSiteIndex(sitesSectionCollection, siteName)
  56.     If index = -1 Then
  57.         GetWebSiteState = -1
  58.     End If     
  59.     Set siteSection = sitesSectionCollection(index)
  60.     GetWebSiteState = siteSection.GetPropertyByName("state").Value
  61. End Function
  62. 'Get the state of the ApplicationPool
  63. Function GetAppPoolState(adminManager, appPool)
  64.     Dim configSection, index, appPoolState
  65.     set configSection = adminManager.GetAdminSection(APPLICATION_POOLS_SECTION_NAME, CONFIG_APPHOST_ROOT)
  66.     index = FindAppPoolIndex(configSection.Collection, appPool)
  67.     If index = -1 Then
  68.         GetAppPoolState = -1
  69.     End If     
  70.     GetAppPoolState = configSection.Collection.Item(index).GetPropertyByName("state").Value
  71. End Function
  72. 'Start the w3svc service on this node
  73. Function StartW3SVC()
  74.     Dim objWmiProvider
  75.     Dim objService
  76.     Dim strServiceState
  77.     Dim response
  78.     'Check to see if the service is running
  79.     set objWmiProvider = GetObject("winmgmts:/root/cimv2")
  80.     set objService = objWmiProvider.get("win32_service='w3svc'")
  81.     strServiceState = objService.state
  82.     If ucase(strServiceState) = "RUNNING" Then
  83.         StartW3SVC = True
  84.     Else
  85.         'If the service is not running, try to start it
  86.         response = objService.StartService()
  87.         'response = 0  or 10 indicates that the request to start was accepted
  88.         If ( response <> 0 ) and ( response <> 10 ) Then
  89.             StartW3SVC = False
  90.         Else
  91.             StartW3SVC = True
  92.         End If
  93.     End If
  94. End Function
  95. 'Start the application pool for the website
  96. Function StartAppPool()
  97.     Dim ahwriter, appPoolsSection, appPoolsCollection, index, appPool, appPoolMethods, startMethod, callStartMethod
  98.     Set ahwriter = CreateObject("Microsoft.ApplicationHost.WritableAdminManager")
  99.     Set appPoolsSection = ahwriter.GetAdminSection(APPLICATION_POOLS_SECTION_NAME, CONFIG_APPHOST_ROOT)      
  100.     Set appPoolsCollection = appPoolsSection.Collection
  101.     index = FindAppPoolIndex(appPoolsCollection, APP_POOL_NAME)
  102.     Set appPool = appPoolsCollection.Item(index)
  103.     'See if it is already started
  104.     If appPool.GetPropertyByName("state").Value = 1 Then
  105.         StartAppPool = True
  106.         Exit Function
  107.     End If
  108.     'Try To start the application pool
  109.     Set appPoolMethods = appPool.Methods
  110.     Set startMethod = appPoolMethods.Item(START_APP_POOL)
  111.     Set callStartMethod = startMethod.CreateInstance()
  112.     callStartMethod.Execute()
  113.     'If started return true, otherwise return false
  114.     If appPool.GetPropertyByName("state").Value = 1 Then
  115.         StartAppPool = True
  116.     Else
  117.         StartAppPool = False
  118.     End If
  119. End Function
  120. 'Start the website
  121. Function StartWebSite()
  122.     Dim ahwriter, sitesSection, sitesSectionCollection, siteSection, index, siteMethods, startMethod, executeMethod
  123.     Set ahwriter = CreateObject("Microsoft.ApplicationHost.WritableAdminManager")
  124.     Set sitesSection = ahwriter.GetAdminSection(SITES_SECTION_NAME, CONFIG_APPHOST_ROOT)
  125.     Set sitesSectionCollection = sitesSection.Collection
  126.     index = FindSiteIndex(sitesSectionCollection, SITE_NAME)
  127.     Set siteSection = sitesSectionCollection(index)
  128.     if siteSection.GetPropertyByName("state").Value = 1 Then
  129.         'Site is already started
  130.         StartWebSite = True
  131.         Exit Function
  132.     End If
  133.     'Try to start site
  134.     Set siteMethods = siteSection.Methods
  135.     Set startMethod = siteMethods.Item(START_WEB_SITE)
  136.     Set executeMethod = startMethod.CreateInstance()
  137.     executeMethod.Execute()
  138.     'Check to see if the site started, if not return false
  139.     If siteSection.GetPropertyByName("state").Value = 1 Then
  140.         StartWebSite = True
  141.     Else
  142.         StartWebSite = False
  143.     End If
  144. End Function
  145. 'Stop the website
  146. Function StopWebSite()
  147.     Dim ahwriter, sitesSection, sitesSectionCollection, siteSection, index, siteMethods, startMethod, executeMethod, autoStartProperty
  148.     Set ahwriter = CreateObject("Microsoft.ApplicationHost.WritableAdminManager")
  149.     Set sitesSection = ahwriter.GetAdminSection(SITES_SECTION_NAME, CONFIG_APPHOST_ROOT)
  150.     Set sitesSectionCollection = sitesSection.Collection
  151.     index = FindSiteIndex(sitesSectionCollection, SITE_NAME)
  152.     Set siteSection = sitesSectionCollection(index)
  153.     'Stop the site
  154.     Set siteMethods = siteSection.Methods
  155.     Set startMethod = siteMethods.Item(STOP_WEB_SITE)
  156.     Set executeMethod = startMethod.CreateInstance()
  157.     executeMethod.Execute()
  158. End Function
  159. 'Cluster resource entry points. More details here:
  160. 'http://msdn.microsoft.com/en-us/library/aa372846(VS.85).aspx
  161. 'Cluster resource Online entry point
  162. 'Make sure the website and the application pool are started
  163. Function Online( )
  164.     Dim bOnline
  165.     'Make sure w3svc is started
  166.     bOnline = StartW3SVC()
  167.     If bOnline <> True Then
  168.         Resource.LogInformation "The resource failed to come online because w3svc could not be started."
  169.         Online = False
  170.         Exit Function
  171.     End If
  172.     'Make sure the application pool is started
  173.     bOnline = StartAppPool()
  174.     If bOnline <> True Then
  175.         Resource.LogInformation "The resource failed to come online because the application pool could not be started."
  176.         Online = False
  177.         Exit Function
  178.     End If
  179.     'Make sure the website is started
  180.     bOnline = StartWebSite()
  181.     If bOnline <> True Then
  182.         Resource.LogInformation "The resource failed to come online because the web site could not be started."
  183.         Online = False
  184.         Exit Function
  185.     End If
  186.     Online = true
  187. End Function
  188. 'Cluster resource offline entry point
  189. 'Stop the website
  190. Function Offline( )
  191.     StopWebSite()
  192.     Offline = true
  193. End Function
  194. 'Cluster resource LooksAlive entry point
  195. 'Check for the health of the website and the application pool
  196. Function LooksAlive( )
  197.     Dim adminManager, appPoolState, configSection, i, appPoolName, appPool, index
  198.     i = 0
  199.     Set adminManager  = CreateObject("Microsoft.ApplicationHost.AdminManager")
  200.     appPoolState = -1
  201.     'Get the state of the website
  202.     if GetWebSiteState(adminManager, SITE_NAME) <> 1 Then
  203.         Resource.LogInformation "The resource failed because the " & SITE_NAME & " web site is not started."
  204.         LooksAlive = false
  205.         Exit Function
  206.     End If
  207.     'Get the state of the Application Pool
  208.      if GetAppPoolState(adminManager, APP_POOL_NAME) <> 1 Then
  209.          Resource.LogInformation "The resource failed because Application Pool " & APP_POOL_NAME & " is not started."
  210.          LooksAlive = false
  211.      Exit Function
  212.      end if
  213.      '  Web site and Application Pool state are valid return true
  214.      LooksAlive = true
  215. End Function
  216. 'Cluster resource IsAlive entry point
  217. 'Do the same health checks as LooksAlive
  218. 'If a more thorough than what we do in LooksAlive is required, this should be performed here
  219. Function IsAlive()  
  220.     IsAlive = LooksAlive
  221. End Function
  222. 'Cluster resource Open entry point
  223. Function Open()
  224.     Open = true
  225. End Function
  226. 'Cluster resource Close entry point
  227. Function Close()
  228.     Close = true
  229. End Function
  230. 'Cluster resource Terminate entry point
  231. Function Terminate()
  232.     Terminate = true
  233. End Function
  234. '<end script sample>
复制代码
将文件复制到所有群集主机的相同目录下 如:C:\Windows\System32\inetsrv主机A打开故障转移群集管理器 连接到群集TEST
















配置IIS故障转移








此时我们在群集下角色列表里可以看到IIS故障转移群集角色


查看一下WINC(192.168.0.26)主机的网卡情况


测试访问http://192.168.0.99  --------  可以打开


现在我们模拟WINC主机IIS网页服务挂掉/端口无法访问 打开WINC主机IIS管理器 展开网页 停止默认网站


再次打开浏览器 打开http://192.168.0.99  ----- 依然可以打开


主机A上查看群集角色 已经自动切换到WINB提供web服务


查看WINB主机网卡信息   99IP已自动切换到WINB 我们打开的是WINB的网页


同理 我们关闭WINB的IIS网站 99又会切换到WINA 访问依然不受影响


至此 我们实现了 主机在非宕机情况下 IIS站点挂掉后切换主机提供服务的情况
注:
1、本测试中99IP对应的不是整个IIS服务 只是一个站点(默认站点)
2、用户上传的附件需要一个群集共用的存储介质 目前还未解决 待完善
参考:
https://www.cnblogs.com/alanlau/archive/2011/08/25/2153472.html
到此这篇关于WINDOWS2016故障转移群集(图文教程)的文章就介绍到这了,更多相关WINS2016故障转移群集内容请搜索中国红客联盟以前的文章或继续浏览下面的相关文章希望大家以后多多支持中国红客联盟!

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

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

本版积分规则

中国红客联盟公众号

联系站长QQ:5520533

admin@chnhonker.com
Copyright © 2001-2025 Discuz Team. Powered by Discuz! X3.5 ( 粤ICP备13060014号 )|天天打卡 本站已运行