欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  科技

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

程序员文章站 2022-06-17 17:47:34
win2016故障转移群集准备工作:主机名ip域名wina192.168.0.24wina.netwinb192.168.0.25winb.netwinc192.168.0.26winc.net所有主...

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  内容如下(虚线内内容)  注意修改网站和应用程序池名称(默认无需修改)

'<begin script sample>

 

 

'this script provides high availability for iis websites

'by default, it monitors the "default web site" and "defaultapppool"

'to monitor another web site, change the site_name below

'to monitor another application pool, change the app_pool_name below

'more thorough and application-specific health monitoring logic can be added to the script if needed

 

option explicit

 

dim site_name

dim app_pool_name

dim start_web_site

dim start_app_pool

dim sites_section_name

dim application_pools_section_name

dim config_apphost_root

dim stop_web_site

 

 

'note:

'replace this with the site and application pool you want to configure high availability for

'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.

site_name = "default web site" '网站名称

app_pool_name = "defaultapppool" '应用程序池名

 

start_web_site = 0

start_app_pool = 0

stop_web_site  = 1

sites_section_name = "system.applicationhost/sites"

application_pools_section_name = "system.applicationhost/applicationpools"

config_apphost_root = "machine/webroot/apphost"

 

'helper script functions

 

 

'find the index of the website on this node

function findsiteindex(collection, sitename)

 

    dim i

 

    findsiteindex = -1   

 

    for i = 0 to (cint(collection.count) - 1)

        if collection.item(i).getpropertybyname("name").value = sitename then

            findsiteindex = i

            exit for

        end if      

    next

 

end function

 

 

'find the index of the application pool on this node

function findapppoolindex(collection, apppoolname)

 

    dim i

 

    findapppoolindex = -1   

 

    for i = 0 to (cint(collection.count) - 1)

        if collection.item(i).getpropertybyname("name").value = apppoolname then

            findapppoolindex = i

            exit for

        end if      

    next

 

end function

 

'get the state of the website

function getwebsitestate(adminmanager, sitename)

 

    dim sitessection, sitessectioncollection, sitesection, index, sitemethods, startmethod, executemethod

    set sitessection = adminmanager.getadminsection(sites_section_name, config_apphost_root)

    set sitessectioncollection = sitessection.collection

 

    index = findsiteindex(sitessectioncollection, sitename)

    if index = -1 then

        getwebsitestate = -1

    end if     

 

    set sitesection = sitessectioncollection(index)

 

    getwebsitestate = sitesection.getpropertybyname("state").value

 

end function

 

'get the state of the applicationpool

function getapppoolstate(adminmanager, apppool)

 

    dim configsection, index, apppoolstate

 

    set configsection = adminmanager.getadminsection(application_pools_section_name, config_apphost_root)

    index = findapppoolindex(configsection.collection, apppool)

 

    if index = -1 then

        getapppoolstate = -1

    end if     

 

    getapppoolstate = configsection.collection.item(index).getpropertybyname("state").value

end function

 

 

'start the w3svc service on this node

function startw3svc()

 

    dim objwmiprovider

    dim objservice

    dim strservicestate

    dim response

 

    'check to see if the service is running

    set objwmiprovider = getobject("winmgmts:/root/cimv2")

    set objservice = objwmiprovider.get("win32_service='w3svc'")

    strservicestate = objservice.state

 

    if ucase(strservicestate) = "running" then

        startw3svc = true

    else

        'if the service is not running, try to start it

        response = objservice.startservice()

 

        'response = 0  or 10 indicates that the request to start was accepted

        if ( response <> 0 ) and ( response <> 10 ) then

            startw3svc = false

        else

            startw3svc = true

        end if

    end if

     

end function

 

 

'start the application pool for the website

function startapppool()

 

    dim ahwriter, apppoolssection, apppoolscollection, index, apppool, apppoolmethods, startmethod, callstartmethod

    set ahwriter = createobject("microsoft.applicationhost.writableadminmanager")

 

    set apppoolssection = ahwriter.getadminsection(application_pools_section_name, config_apphost_root)      

    set apppoolscollection = apppoolssection.collection

 

    index = findapppoolindex(apppoolscollection, app_pool_name)

    set apppool = apppoolscollection.item(index)

     

    'see if it is already started

    if apppool.getpropertybyname("state").value = 1 then

        startapppool = true

        exit function

    end if

 

    'try to start the application pool

    set apppoolmethods = apppool.methods

    set startmethod = apppoolmethods.item(start_app_pool)

    set callstartmethod = startmethod.createinstance()

    callstartmethod.execute()

     

    'if started return true, otherwise return false

    if apppool.getpropertybyname("state").value = 1 then

        startapppool = true

    else

        startapppool = false

    end if

 

end function

 

 

'start the website

function startwebsite()

 

    dim ahwriter, sitessection, sitessectioncollection, sitesection, index, sitemethods, startmethod, executemethod

    set ahwriter = createobject("microsoft.applicationhost.writableadminmanager")

    set sitessection = ahwriter.getadminsection(sites_section_name, config_apphost_root)

    set sitessectioncollection = sitessection.collection

 

    index = findsiteindex(sitessectioncollection, site_name)

    set sitesection = sitessectioncollection(index)

 

    if sitesection.getpropertybyname("state").value = 1 then

        'site is already started

        startwebsite = true

        exit function

    end if

 

    'try to start site

    set sitemethods = sitesection.methods

    set startmethod = sitemethods.item(start_web_site)

    set executemethod = startmethod.createinstance()

    executemethod.execute()

 

    'check to see if the site started, if not return false

    if sitesection.getpropertybyname("state").value = 1 then

        startwebsite = true

    else

        startwebsite = false

    end if

 

end function

 

 

'stop the website

function stopwebsite()

 

    dim ahwriter, sitessection, sitessectioncollection, sitesection, index, sitemethods, startmethod, executemethod, autostartproperty

    set ahwriter = createobject("microsoft.applicationhost.writableadminmanager")

    set sitessection = ahwriter.getadminsection(sites_section_name, config_apphost_root)

    set sitessectioncollection = sitessection.collection

 

    index = findsiteindex(sitessectioncollection, site_name)

    set sitesection = sitessectioncollection(index)

 

    'stop the site

    set sitemethods = sitesection.methods

    set startmethod = sitemethods.item(stop_web_site)

    set executemethod = startmethod.createinstance()

    executemethod.execute()

 

end function

 

 

 

'cluster resource entry points. more details here:

'http://msdn.microsoft.com/en-us/library/aa372846(vs.85).aspx

 

'cluster resource online entry point

'make sure the website and the application pool are started

function online( )

 

    dim bonline

    'make sure w3svc is started

    bonline = startw3svc()

 

    if bonline <> true then

        resource.loginformation "the resource failed to come online because w3svc could not be started."

        online = false

        exit function

    end if

 

 

    'make sure the application pool is started

    bonline = startapppool()

    if bonline <> true then

        resource.loginformation "the resource failed to come online because the application pool could not be started."

        online = false

        exit function

    end if

 

 

    'make sure the website is started

    bonline = startwebsite()

    if bonline <> true then

        resource.loginformation "the resource failed to come online because the web site could not be started."

        online = false

        exit function

    end if

 

    online = true

 

end function

 

  

'cluster resource offline entry point

'stop the website

function offline( )

 

    stopwebsite()

    offline = true

 

end function

 

 

'cluster resource looksalive entry point

'check for the health of the website and the application pool

function looksalive( )

 

    dim adminmanager, apppoolstate, configsection, i, apppoolname, apppool, index

 

    i = 0

    set adminmanager  = createobject("microsoft.applicationhost.adminmanager")

    apppoolstate = -1

 

    'get the state of the website

    if getwebsitestate(adminmanager, site_name) <> 1 then

        resource.loginformation "the resource failed because the " & site_name & " web site is not started."

        looksalive = false

        exit function

    end if

 

 

    'get the state of the application pool

     if getapppoolstate(adminmanager, app_pool_name) <> 1 then

         resource.loginformation "the resource failed because application pool " & app_pool_name & " is not started."

         looksalive = false 

     exit function

     end if

 

     '  web site and application pool state are valid return true

     looksalive = true

end function

 

 

'cluster resource isalive entry point

'do the same health checks as looksalive

'if a more thorough than what we do in looksalive is required, this should be performed here

function isalive()  

 

    isalive = looksalive

 

end function

 

 

'cluster resource open entry point

function open()

 

    open = true

 

end function

 

 

'cluster resource close entry point

function close()

 

    close = true

 

end function

 

 

'cluster resource terminate entry point

function terminate()

 

    terminate = true

 

end function

'<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故障转移群集内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!