安装网络负载平衡
需要加入的服务器上全部需要安装网络负载平衡管理器
图形化安装:使用服务器管理器安装
在服务器管理器中,使用"添加角色和功能"向导添加网络负载均衡功能。 完成向导后,将安装 NLB,并且不需要重启计算机。
找到控制面板在控制面版中找到下图选项,点击启用或关闭windows功能
点击进入,找到下图中标记的位置,点击进入添加功能
在所有选择中找到下图的选项。点击下一步
确认选择的安装组件,然后点击安装。
等待安装完成
安装完成之后,关闭 (安装成功后需重启计算机)。
命令行、脚本安装
安装方式1
REM 启用网络负载平衡管理器
dism.exe /online /enable-feature /featurename:NetworkLoadBalancingFullServer /norestart
REM 禁用网络负载平衡管理器
dism.exe /online /disable-feature /featurename:NetworkLoadBalancingFullServer /norestart
安装方式2
使用 Windows PowerShell 安装
若要使用 Windows PowerShell 安装 NLB,请在要安装 NLB 的计算机上,在提升的 Windows PowerShell 提示符处运行以下命令。
PowerShell复制
Install-WindowsFeature NLB -IncludeManagementTools
安装完成后,无需重启计算机。
配置网络负载平衡
图形化配置
在开始菜单中搜索网络负载平衡管理器,找到组件选项,打开。
下图是进入之后的页面,鼠标右键点击"网络负载平衡管理器 "。
新建集群
填写好创建集群的电脑IP地址进行连接,之后下方选项栏里会出现本机服务器的网卡,选择要进行集群的网卡,然后点击下一步。
选择本机电脑所添加的优先级别(后续添加完成之后是可以修改的)选择之后,点击下一步
点击添加
图中IPv4地址,是这个集群的虚拟ip(VIP)设置好之后点击确定
确认添加成功之后点击下一步
根据实际情况选择单播,或者多播,选择完成之后点击下一步
单播和多播的区别:
点击完成之后,集群就已经建立成功了。
在点击刚建立好的集群,可以看到状态,状态为"已启用"说明集群创建完成了
集群主机主动添加另一台主机进入集群
搜索需要进入这个集群的服务器IP,选择好网卡之后,点击下一步
点击链接的时候报错如下
解决办法: https://blog.51cto.com/149banzhang/835118
选择优先级,点击下一步
点击完成,加入主机完成
待加入集群服务器搜索集群加入
在使用另一台需要进入集群的服务器搜索创建的集群IP,加入集群。
输入搜索要加入的集群IP,在下图群集中可以看到搜索到的集群,选择要加入的集群,点击完成进入集群
命令行、脚本配置
脚本代码
REM 待补充
Network Load Balancing (NLB) Cmdlets in Windows PowerShell
Windows PowerShell® 是基于任务的命令行 shell 和脚本语言,专为系统管理而设计。本参考主题面向信息技术 (IT) 专业人员,可在利用 Windows PowerShell cmdlet 编写脚本和对任务实施自动化时提供协助。
cmdlet | Description |
---|---|
Add-NlbClusterNode | Adds a new node to the Network Load Balancing (NLB) cluster. |
Add-NlbClusterNodeDip | Adds a dedicated IP address to a Network Load Balancing (NLB) cluster. |
Add-NlbClusterPortRule | Adds a new port rule to a Network Load Balancing (NLB) cluster. |
Add-NlbClusterVip | Adds a virtual IP address to a Network Load Balancing (NLB) cluster. |
Disable-NlbClusterPortRule | Disables a port rule on a Network Load Balancing (NLB) cluster or on a specific host in the cluster. |
Enable-NlbClusterPortRule | Enables a port rule on a Network Load Balancing (NLB) cluster or on a specific node in the cluster. |
Get-NlbCluster | Retrieves information about the Network Load Balancing (NLB) cluster object that is queried by the caller. |
Get-NlbClusterDriverInfo | Retrieves information about the Network Load Balancing (NLB) driver on the local machine. |
Get-NlbClusterNode | Retrieves information about the Network Load Balancing (NLB) cluster object that is queried by the caller. |
Get-NlbClusterNodeDip | Retrieves the dedicated IP address that is queried by the caller. |
Get-NlbClusterNodeNetworkInterface | Retrieves information about interfaces, including information about the Network Load Balancing (NLB) driver, on a host. |
Get-NlbClusterPortRule | Retrieves the port rule objects that are queried by the caller. |
Get-NlbClusterVip | Retrieves virtual IP addresses that are queried by the caller. |
New-NlbCluster | Creates a Network Load Balancing (NLB) cluster on the specified interface that is defined by the node and network adapter name. |
New-NlbClusterIpv6Address | Generates IPv6 addresses to create cluster virtual IP addresses or node dedicated IP addresses. |
Remove-NlbCluster | Deletes a Network Load Balancing (NLB) cluster. |
Remove-NlbClusterNode | Removes a node from the Network Load Balancing (NLB) cluster. |
Remove-NlbClusterNodeDip | Removes a dedicate IP address from a Network Load Balancing (NLB) cluster. |
Remove-NlbClusterPortRule | Removes a port rule from a Network Load Balancing (NLB) cluster. |
Remove-NlbClusterVip | Removes a virtual IP address from a Network Load Balancing (NLB) cluster. |
Resume-NlbCluster | Resumes all nodes in a Network Load Balancing (NLB) cluster. |
Resume-NlbClusterNode | Resumes the node in a Network Load Balancing (NLB) cluster that was suspended. |
Set-NlbCluster | Edits the configuration of a Network Load Balancing (NLB) cluster. |
Set-NlbClusterNode | Edits the Network Load Balancing (NLB) cluster node settings. |
Set-NlbClusterNodeDip | Edits the dedicated IP address of a Network Load Balancing (NLB) cluster. |
Set-NlbClusterPortRule | Edits the port rules for a Network Load Balancing (NLB) cluster. |
Set-NlbClusterPortRuleNodeHandlingPriority | Sets the host priority of a port rule for a specific Network Load Balancing (NLB) node. |
Set-NlbClusterPortRuleNodeWeight | Sets the load weight of a port rule for a specific Network Load Balancing (NLB) node. |
Set-NlbClusterVip | Edits the virtual IP address of a Network Load Balancing (NLB) cluster. |
Start-NlbCluster | Starts all nodes in a Network Load Balancing (NLB) cluster. |
Start-NlbClusterNode | Starts a Network Load Balancing (NLB) cluster node. |
Stop-NlbCluster | Stops all nodes of a Network Load Balancing (NLB) cluster. |
Stop-NlbClusterNode | Stops a node in a Network Load Balancing (NLB) cluster. |
Suspend-NlbCluster | Suspends all nodes of a Network Load Balancing (NLB) cluster. |
Suspend-NlbClusterNode | Suspends a specific node in a Network Load Balancing (NLB) cluster. |
有关任何 cmdlet 或其语法的详细信息,请使用 Get-Help
<cmdlet 名称> cmdlet,其中 *<cmdlet 名称>*是你要搜索的 cmdlet 的名称。若需了解详细信息,可以运行以下任一 cmdlet:
● Get-Help
<cmdlet 名称> -Detailed
● Get-Help
<cmdlet 名称> -Examples
● Get-Help
<cmdlet 名称> -Full
参考链接
脚本安装
Network Load Balancing | Microsoft Learn
脚本配置
Network Load Balancing (NLB) Cmdlets in Windows PowerShell | Microsoft Learn