经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » 数据库/运维 » Windows » 查看文章
WINDOWS2016故障转移群集(图文教程)
来源:jb51  时间:2022/1/19 13:44:37  对本文有异议

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

 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号