服务器之家:专注于VPS、云服务器配置技术及软件下载分享
分类导航

Linux|Centos|Ubuntu|系统进程|Fedora|注册表|Bios|Solaris|Windows7|Windows10|Windows11|windows server|

服务器之家 - 服务器系统 - windows server - WINDOWS2016故障转移群集(图文教程)

WINDOWS2016故障转移群集(图文教程)

2023-02-14 15:53泡泡虾 windows server

本文主要介绍了WINDOWS2016故障转移群集,文中通过示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

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为例)

WINDOWS2016故障转移群集(图文教程)

WINDOWS2016故障转移群集(图文教程)

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

WINDOWS2016故障转移群集(图文教程)

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

WINDOWS2016故障转移群集(图文教程)

WINDOWS2016故障转移群集(图文教程)

WINDOWS2016故障转移群集(图文教程)

WINDOWS2016故障转移群集(图文教程)

所有主机配置DNS解析记录 并测试解析

新建正向查找区域NET

WINDOWS2016故障转移群集(图文教程)

WINDOWS2016故障转移群集(图文教程)

WINDOWS2016故障转移群集(图文教程)

WINDOWS2016故障转移群集(图文教程)

WINDOWS2016故障转移群集(图文教程)

WINDOWS2016故障转移群集(图文教程)

WINDOWS2016故障转移群集(图文教程)

WINDOWS2016故障转移群集(图文教程)

WINDOWS2016故障转移群集(图文教程)

新建反向查找区域

WINDOWS2016故障转移群集(图文教程)

WINDOWS2016故障转移群集(图文教程)

WINDOWS2016故障转移群集(图文教程)

WINDOWS2016故障转移群集(图文教程)

WINDOWS2016故障转移群集(图文教程)

WINDOWS2016故障转移群集(图文教程)

WINDOWS2016故障转移群集(图文教程)

WINDOWS2016故障转移群集(图文教程)

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

WINDOWS2016故障转移群集(图文教程)

WINDOWS2016故障转移群集(图文教程)

WINDOWS2016故障转移群集(图文教程)

WINDOWS2016故障转移群集(图文教程)

WINDOWS2016故障转移群集(图文教程)

WINDOWS2016故障转移群集(图文教程)

WINDOWS2016故障转移群集(图文教程)

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

WINDOWS2016故障转移群集(图文教程)

WINDOWS2016故障转移群集(图文教程)

WINDOWS2016故障转移群集(图文教程)

测试解析

WINDOWS2016故障转移群集(图文教程)

WINDOWS2016故障转移群集(图文教程)

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

主机A创建群集TEST

WINDOWS2016故障转移群集(图文教程)

WINDOWS2016故障转移群集(图文教程)

WINDOWS2016故障转移群集(图文教程)

WINDOWS2016故障转移群集(图文教程)

WINDOWS2016故障转移群集(图文教程)

WINDOWS2016故障转移群集(图文教程)

WINDOWS2016故障转移群集(图文教程)

WINDOWS2016故障转移群集(图文教程)

WINDOWS2016故障转移群集(图文教程)

主机B/C连接到群集TEST

主机B(192.168.0.25)

WINDOWS2016故障转移群集(图文教程)

WINDOWS2016故障转移群集(图文教程)

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

WINDOWS2016故障转移群集(图文教程)

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

WINDOWS2016故障转移群集(图文教程)

WINDOWS2016故障转移群集(图文教程)

WINDOWS2016故障转移群集(图文教程)

WINDOWS2016故障转移群集(图文教程)

WINDOWS2016故障转移群集(图文教程)

WINDOWS2016故障转移群集(图文教程)

WINDOWS2016故障转移群集(图文教程)

WINDOWS2016故障转移群集(图文教程)

WINDOWS2016故障转移群集(图文教程)

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

关闭掉A主机后 B主机拥有了88IP 网页依然可以打开

WINDOWS2016故障转移群集(图文教程)

WINDOWS2016故障转移群集(图文教程)

继续关闭B主机

WINDOWS2016故障转移群集(图文教程)

WINDOWS2016故障转移群集(图文教程)

此时C主机拥有了88IP  网页依然可以打开

参考:

https://blog.csdn.net/demonson/article/details/81708809

注:

经后期测试 建议不要将群集所有主机全部宕机 否则会出现问题

进阶:

以上内容为群集搭建及群集中某主机宕机后恢复业务的情况

下面记录一种主机没有宕机 IIS站点挂掉无法提供服务的情况

新建文本文档 修改为IIS.vbs  内容如下(虚线内内容)  注意修改网站和应用程序池名称(默认无需修改)


  1. '<begin script sample>
  2.  
  3. 'This script provides high availability for IIS websites
  4.  
  5. 'By default, it monitors the "Default Web Site" and "DefaultAppPool"
  6.  
  7. 'To monitor another web site, change the SITE_NAME below
  8.  
  9. 'To monitor another application pool, change the APP_POOL_NAME below
  10.  
  11. 'More thorough and application-specific health monitoring logic can be added to the script if needed
  12.  
  13. Option Explicit
  14.  
  15. DIM SITE_NAME
  16.  
  17. DIM APP_POOL_NAME
  18.  
  19. Dim START_WEB_SITE
  20.  
  21. Dim START_APP_POOL
  22.  
  23. Dim SITES_SECTION_NAME
  24.  
  25. Dim APPLICATION_POOLS_SECTION_NAME
  26.  
  27. Dim CONFIG_APPHOST_ROOT
  28.  
  29. Dim STOP_WEB_SITE
  30.  
  31. 'Note:
  32.  
  33. 'Replace this with the site and application pool you want to configure high availability for
  34.  
  35. '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.
  36.  
  37. SITE_NAME = "Default Web Site" '网站名称
  38.  
  39. APP_POOL_NAME = "DefaultAppPool" '应用程序池名
  40.  
  41. START_WEB_SITE = 0
  42.  
  43. START_APP_POOL = 0
  44.  
  45. STOP_WEB_SITE = 1
  46.  
  47. SITES_SECTION_NAME = "system.applicationHost/sites"
  48.  
  49. APPLICATION_POOLS_SECTION_NAME = "system.applicationHost/applicationPools"
  50.  
  51. CONFIG_APPHOST_ROOT = "MACHINE/WEBROOT/APPHOST"
  52.  
  53. 'Helper script functions
  54.  
  55. 'Find the index of the website on this node
  56.  
  57. Function FindSiteIndex(collection, siteName)
  58.  
  59. Dim i
  60.  
  61. FindSiteIndex = -1
  62.  
  63. For i = 0 To (CInt(collection.Count) - 1)
  64.  
  65. If collection.Item(i).GetPropertyByName("name").Value = siteName Then
  66.  
  67. FindSiteIndex = i
  68.  
  69. Exit For
  70.  
  71. End If
  72.  
  73. Next
  74.  
  75. End Function
  76.  
  77. 'Find the index of the application pool on this node
  78.  
  79. Function FindAppPoolIndex(collection, appPoolName)
  80.  
  81. Dim i
  82.  
  83. FindAppPoolIndex = -1
  84.  
  85. For i = 0 To (CInt(collection.Count) - 1)
  86.  
  87. If collection.Item(i).GetPropertyByName("name").Value = appPoolName Then
  88.  
  89. FindAppPoolIndex = i
  90.  
  91. Exit For
  92.  
  93. End If
  94.  
  95. Next
  96.  
  97. End Function
  98.  
  99. 'Get the state of the website
  100.  
  101. Function GetWebSiteState(adminManager, siteName)
  102.  
  103. Dim sitesSection, sitesSectionCollection, siteSection, index, siteMethods, startMethod, executeMethod
  104.  
  105. Set sitesSection = adminManager.GetAdminSection(SITES_SECTION_NAME, CONFIG_APPHOST_ROOT)
  106.  
  107. Set sitesSectionCollection = sitesSection.Collection
  108.  
  109. index = FindSiteIndex(sitesSectionCollection, siteName)
  110.  
  111. If index = -1 Then
  112.  
  113. GetWebSiteState = -1
  114.  
  115. End If
  116.  
  117. Set siteSection = sitesSectionCollection(index)
  118.  
  119. GetWebSiteState = siteSection.GetPropertyByName("state").Value
  120.  
  121. End Function
  122.  
  123. 'Get the state of the ApplicationPool
  124.  
  125. Function GetAppPoolState(adminManager, appPool)
  126.  
  127. Dim configSection, index, appPoolState
  128.  
  129. set configSection = adminManager.GetAdminSection(APPLICATION_POOLS_SECTION_NAME, CONFIG_APPHOST_ROOT)
  130.  
  131. index = FindAppPoolIndex(configSection.Collection, appPool)
  132.  
  133. If index = -1 Then
  134.  
  135. GetAppPoolState = -1
  136.  
  137. End If
  138.  
  139. GetAppPoolState = configSection.Collection.Item(index).GetPropertyByName("state").Value
  140.  
  141. End Function
  142.  
  143. 'Start the w3svc service on this node
  144.  
  145. Function StartW3SVC()
  146.  
  147. Dim objWmiProvider
  148.  
  149. Dim objService
  150.  
  151. Dim strServiceState
  152.  
  153. Dim response
  154.  
  155. 'Check to see if the service is running
  156.  
  157. set objWmiProvider = GetObject("winmgmts:/root/cimv2")
  158.  
  159. set objService = objWmiProvider.get("win32_service='w3svc'")
  160.  
  161. strServiceState = objService.state
  162.  
  163. If ucase(strServiceState) = "RUNNING" Then
  164.  
  165. StartW3SVC = True
  166.  
  167. Else
  168.  
  169. 'If the service is not running, try to start it
  170.  
  171. response = objService.StartService()
  172.  
  173. 'response = 0 or 10 indicates that the request to start was accepted
  174.  
  175. If ( response <> 0 ) and ( response <> 10 ) Then
  176.  
  177. StartW3SVC = False
  178.  
  179. Else
  180.  
  181. StartW3SVC = True
  182.  
  183. End If
  184.  
  185. End If
  186.  
  187. End Function
  188.  
  189. 'Start the application pool for the website
  190.  
  191. Function StartAppPool()
  192.  
  193. Dim ahwriter, appPoolsSection, appPoolsCollection, index, appPool, appPoolMethods, startMethod, callStartMethod
  194.  
  195. Set ahwriter = CreateObject("Microsoft.ApplicationHost.WritableAdminManager")
  196.  
  197. Set appPoolsSection = ahwriter.GetAdminSection(APPLICATION_POOLS_SECTION_NAME, CONFIG_APPHOST_ROOT)
  198.  
  199. Set appPoolsCollection = appPoolsSection.Collection
  200.  
  201. index = FindAppPoolIndex(appPoolsCollection, APP_POOL_NAME)
  202.  
  203. Set appPool = appPoolsCollection.Item(index)
  204.  
  205. 'See if it is already started
  206.  
  207. If appPool.GetPropertyByName("state").Value = 1 Then
  208.  
  209. StartAppPool = True
  210.  
  211. Exit Function
  212.  
  213. End If
  214.  
  215. 'Try To start the application pool
  216.  
  217. Set appPoolMethods = appPool.Methods
  218.  
  219. Set startMethod = appPoolMethods.Item(START_APP_POOL)
  220.  
  221. Set callStartMethod = startMethod.CreateInstance()
  222.  
  223. callStartMethod.Execute()
  224.  
  225. 'If started return true, otherwise return false
  226.  
  227. If appPool.GetPropertyByName("state").Value = 1 Then
  228.  
  229. StartAppPool = True
  230.  
  231. Else
  232.  
  233. StartAppPool = False
  234.  
  235. End If
  236.  
  237. End Function
  238.  
  239. 'Start the website
  240.  
  241. Function StartWebSite()
  242.  
  243. Dim ahwriter, sitesSection, sitesSectionCollection, siteSection, index, siteMethods, startMethod, executeMethod
  244.  
  245. Set ahwriter = CreateObject("Microsoft.ApplicationHost.WritableAdminManager")
  246.  
  247. Set sitesSection = ahwriter.GetAdminSection(SITES_SECTION_NAME, CONFIG_APPHOST_ROOT)
  248.  
  249. Set sitesSectionCollection = sitesSection.Collection
  250.  
  251. index = FindSiteIndex(sitesSectionCollection, SITE_NAME)
  252.  
  253. Set siteSection = sitesSectionCollection(index)
  254.  
  255. if siteSection.GetPropertyByName("state").Value = 1 Then
  256.  
  257. 'Site is already started
  258.  
  259. StartWebSite = True
  260.  
  261. Exit Function
  262.  
  263. End If
  264.  
  265. 'Try to start site
  266.  
  267. Set siteMethods = siteSection.Methods
  268.  
  269. Set startMethod = siteMethods.Item(START_WEB_SITE)
  270.  
  271. Set executeMethod = startMethod.CreateInstance()
  272.  
  273. executeMethod.Execute()
  274.  
  275. 'Check to see if the site started, if not return false
  276.  
  277. If siteSection.GetPropertyByName("state").Value = 1 Then
  278.  
  279. StartWebSite = True
  280.  
  281. Else
  282.  
  283. StartWebSite = False
  284.  
  285. End If
  286.  
  287. End Function
  288.  
  289. 'Stop the website
  290.  
  291. Function StopWebSite()
  292.  
  293. Dim ahwriter, sitesSection, sitesSectionCollection, siteSection, index, siteMethods, startMethod, executeMethod, autoStartProperty
  294.  
  295. Set ahwriter = CreateObject("Microsoft.ApplicationHost.WritableAdminManager")
  296.  
  297. Set sitesSection = ahwriter.GetAdminSection(SITES_SECTION_NAME, CONFIG_APPHOST_ROOT)
  298.  
  299. Set sitesSectionCollection = sitesSection.Collection
  300.  
  301. index = FindSiteIndex(sitesSectionCollection, SITE_NAME)
  302.  
  303. Set siteSection = sitesSectionCollection(index)
  304.  
  305. 'Stop the site
  306.  
  307. Set siteMethods = siteSection.Methods
  308.  
  309. Set startMethod = siteMethods.Item(STOP_WEB_SITE)
  310.  
  311. Set executeMethod = startMethod.CreateInstance()
  312.  
  313. executeMethod.Execute()
  314.  
  315. End Function
  316.  
  317. 'Cluster resource entry points. More details here:
  318.  
  319. 'http://msdn.microsoft.com/en-us/library/aa372846(VS.85).aspx
  320.  
  321. 'Cluster resource Online entry point
  322.  
  323. 'Make sure the website and the application pool are started
  324.  
  325. Function Online( )
  326.  
  327. Dim bOnline
  328.  
  329. 'Make sure w3svc is started
  330.  
  331. bOnline = StartW3SVC()
  332.  
  333. If bOnline <> True Then
  334.  
  335. Resource.LogInformation "The resource failed to come online because w3svc could not be started."
  336.  
  337. Online = False
  338.  
  339. Exit Function
  340.  
  341. End If
  342.  
  343. 'Make sure the application pool is started
  344.  
  345. bOnline = StartAppPool()
  346.  
  347. If bOnline <> True Then
  348.  
  349. Resource.LogInformation "The resource failed to come online because the application pool could not be started."
  350.  
  351. Online = False
  352.  
  353. Exit Function
  354.  
  355. End If
  356.  
  357. 'Make sure the website is started
  358.  
  359. bOnline = StartWebSite()
  360.  
  361. If bOnline <> True Then
  362.  
  363. Resource.LogInformation "The resource failed to come online because the web site could not be started."
  364.  
  365. Online = False
  366.  
  367. Exit Function
  368.  
  369. End If
  370.  
  371. Online = true
  372.  
  373. End Function
  374.  
  375. 'Cluster resource offline entry point
  376.  
  377. 'Stop the website
  378.  
  379. Function Offline( )
  380.  
  381. StopWebSite()
  382.  
  383. Offline = true
  384.  
  385. End Function
  386.  
  387. 'Cluster resource LooksAlive entry point
  388.  
  389. 'Check for the health of the website and the application pool
  390.  
  391. Function LooksAlive( )
  392.  
  393. Dim adminManager, appPoolState, configSection, i, appPoolName, appPool, index
  394.  
  395. i = 0
  396.  
  397. Set adminManager = CreateObject("Microsoft.ApplicationHost.AdminManager")
  398.  
  399. appPoolState = -1
  400.  
  401. 'Get the state of the website
  402.  
  403. if GetWebSiteState(adminManager, SITE_NAME) <> 1 Then
  404.  
  405. Resource.LogInformation "The resource failed because the " & SITE_NAME & " web site is not started."
  406.  
  407. LooksAlive = false
  408.  
  409. Exit Function
  410.  
  411. End If
  412.  
  413. 'Get the state of the Application Pool
  414.  
  415. if GetAppPoolState(adminManager, APP_POOL_NAME) <> 1 Then
  416.  
  417. Resource.LogInformation "The resource failed because Application Pool " & APP_POOL_NAME & " is not started."
  418.  
  419. LooksAlive = false
  420.  
  421. Exit Function
  422.  
  423. end if
  424.  
  425. ' Web site and Application Pool state are valid return true
  426.  
  427. LooksAlive = true
  428.  
  429. End Function
  430.  
  431. 'Cluster resource IsAlive entry point
  432.  
  433. 'Do the same health checks as LooksAlive
  434.  
  435. 'If a more thorough than what we do in LooksAlive is required, this should be performed here
  436.  
  437. Function IsAlive()
  438.  
  439. IsAlive = LooksAlive
  440.  
  441. End Function
  442.  
  443. 'Cluster resource Open entry point
  444.  
  445. Function Open()
  446.  
  447. Open = true
  448.  
  449. End Function
  450.  
  451. 'Cluster resource Close entry point
  452.  
  453. Function Close()
  454.  
  455. Close = true
  456.  
  457. End Function
  458.  
  459. 'Cluster resource Terminate entry point
  460.  
  461. Function Terminate()
  462.  
  463. Terminate = true
  464.  
  465. End Function
  466.  
  467. '<end script sample>

将文件复制到所有群集主机的相同目录下 如:C:\Windows\System32\inetsrv主机A打开故障转移群集管理器 连接到群集TEST

WINDOWS2016故障转移群集(图文教程)

WINDOWS2016故障转移群集(图文教程)

WINDOWS2016故障转移群集(图文教程)

WINDOWS2016故障转移群集(图文教程)

WINDOWS2016故障转移群集(图文教程)

WINDOWS2016故障转移群集(图文教程)

WINDOWS2016故障转移群集(图文教程)

WINDOWS2016故障转移群集(图文教程)

配置IIS故障转移

WINDOWS2016故障转移群集(图文教程)

WINDOWS2016故障转移群集(图文教程)

WINDOWS2016故障转移群集(图文教程)

WINDOWS2016故障转移群集(图文教程)

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

WINDOWS2016故障转移群集(图文教程)

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

WINDOWS2016故障转移群集(图文教程)

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

WINDOWS2016故障转移群集(图文教程)

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

WINDOWS2016故障转移群集(图文教程)

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

WINDOWS2016故障转移群集(图文教程)

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

WINDOWS2016故障转移群集(图文教程)

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

WINDOWS2016故障转移群集(图文教程)

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

WINDOWS2016故障转移群集(图文教程)

至此 我们实现了 主机在非宕机情况下 IIS站点挂掉后切换主机提供服务的情况

注:

1、本测试中99IP对应的不是整个IIS服务 只是一个站点(默认站点)

2、用户上传的附件需要一个群集共用的存储介质 目前还未解决 待完善

参考:

https://www.cnblogs.com/alanlau/archive/2011/08/25/2153472.html

到此这篇关于WINDOWS2016故障转移群集(图文教程)的文章就介绍到这了,更多相关WINS2016故障转移群集内容请搜索服务器之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持服务器之家!

原文链接:https://blog.csdn.net/weixin_42256332/article/details/89151749

延伸 · 阅读

精彩推荐