powershell加win的dns服务器,解决网站负载均衡问题

 

用我发明的powershell填坑法,加windows的dns服务器。从调整dns服务器解析ip时间段的角度,解决网站负载均衡问题。


------------------------win2012r2中,用powershell管理dns服务器的,命令列表--------------------------------

 共计100条指令,即100招,下面演示如何用其中4招秒杀bind的。


PS C:\Users\admin> get-command * -module DnsServer

CommandType Name ModuleName
----------- ---- ----------
Alias Export-DnsServerTrustAnchor DnsServer
Function Add-DnsServerConditionalForwarderZone DnsServer
Function Add-DnsServerDirectoryPartition DnsServer
Function Add-DnsServerForwarder DnsServer
Function Add-DnsServerPrimaryZone DnsServer
Function Add-DnsServerResourceRecord DnsServer
Function Add-DnsServerResourceRecordA DnsServer
Function Add-DnsServerResourceRecordAAAA DnsServer
Function Add-DnsServerResourceRecordCName DnsServer
Function Add-DnsServerResourceRecordDnsKey DnsServer
Function Add-DnsServerResourceRecordDS DnsServer
Function Add-DnsServerResourceRecordMX DnsServer
Function Add-DnsServerResourceRecordPtr DnsServer
Function Add-DnsServerRootHint DnsServer
Function Add-DnsServerSecondaryZone DnsServer
Function Add-DnsServerSigningKey DnsServer
Function Add-DnsServerStubZone DnsServer
Function Add-DnsServerTrustAnchor DnsServer
Function Add-DnsServerZoneDelegation DnsServer
Function Clear-DnsServerCache DnsServer
Function Clear-DnsServerStatistics DnsServer
Function ConvertTo-DnsServerPrimaryZone DnsServer
Function ConvertTo-DnsServerSecondaryZone DnsServer
Function Disable-DnsServerSigningKeyRollover DnsServer
Function Enable-DnsServerSigningKeyRollover DnsServer
Function Export-DnsServerDnsSecPublicKey DnsServer
Function Export-DnsServerZone DnsServer
Function Get-DnsServer DnsServer
Function Get-DnsServerCache DnsServer
Function Get-DnsServerDiagnostics DnsServer
Function Get-DnsServerDirectoryPartition DnsServer
Function Get-DnsServerDnsSecZoneSetting DnsServer
Function Get-DnsServerDsSetting DnsServer
Function Get-DnsServerEDns DnsServer
Function Get-DnsServerForwarder DnsServer
Function Get-DnsServerGlobalNameZone DnsServer
Function Get-DnsServerGlobalQueryBlockList DnsServer
Function Get-DnsServerRecursion DnsServer
Function Get-DnsServerResourceRecord DnsServer
Function Get-DnsServerRootHint DnsServer
Function Get-DnsServerScavenging DnsServer
Function Get-DnsServerSetting DnsServer
Function Get-DnsServerSigningKey DnsServer
Function Get-DnsServerStatistics DnsServer
Function Get-DnsServerTrustAnchor DnsServer
Function Get-DnsServerTrustPoint DnsServer
Function Get-DnsServerZone DnsServer
Function Get-DnsServerZoneAging DnsServer
Function Get-DnsServerZoneDelegation DnsServer
powershell 传教士 原创文章 2015-11-25改允许转载,但必须保留名字和出处,否则追究法律责任
Function Import-DnsServerResourceRecordDS DnsServer
Function Import-DnsServerRootHint DnsServer
Function Import-DnsServerTrustAnchor DnsServer
Function Invoke-DnsServerSigningKeyRollover DnsServer
Function Invoke-DnsServerZoneSign DnsServer
Function Invoke-DnsServerZoneUnsign DnsServer
Function Register-DnsServerDirectoryPartition DnsServer
Function Remove-DnsServerDirectoryPartition DnsServer
Function Remove-DnsServerForwarder DnsServer
Function Remove-DnsServerResourceRecord DnsServer
Function Remove-DnsServerRootHint DnsServer
Function Remove-DnsServerSigningKey DnsServer
Function Remove-DnsServerTrustAnchor DnsServer
Function Remove-DnsServerZone DnsServer
Function Remove-DnsServerZoneDelegation DnsServer
Function Reset-DnsServerZoneKeyMasterRole DnsServer
Function Restore-DnsServerPrimaryZone DnsServer
Function Restore-DnsServerSecondaryZone DnsServer
Function Resume-DnsServerZone DnsServer
Function Set-DnsServer DnsServer
Function Set-DnsServerCache DnsServer
Function Set-DnsServerConditionalForwarderZone DnsServer
Function Set-DnsServerDiagnostics DnsServer
Function Set-DnsServerDnsSecZoneSetting DnsServer
Function Set-DnsServerDsSetting DnsServer
Function Set-DnsServerEDns DnsServer
Function Set-DnsServerForwarder DnsServer
Function Set-DnsServerGlobalNameZone DnsServer
Function Set-DnsServerGlobalQueryBlockList DnsServer
Function Set-DnsServerPrimaryZone DnsServer
Function Set-DnsServerRecursion DnsServer
Function Set-DnsServerResourceRecord DnsServer
Function Set-DnsServerResourceRecordAging DnsServer
Function Set-DnsServerRootHint DnsServer
Function Set-DnsServerScavenging DnsServer
Function Set-DnsServerSecondaryZone DnsServer
Function Set-DnsServerSetting DnsServer
Function Set-DnsServerSigningKey DnsServer
Function Set-DnsServerStubZone DnsServer
Function Set-DnsServerZoneAging DnsServer
Function Set-DnsServerZoneDelegation DnsServer
Function Show-DnsServerCache DnsServer
Function Show-DnsServerKeyStorageProvider DnsServer
Function Start-DnsServerScavenging DnsServer
Function Start-DnsServerZoneTransfer DnsServer
Function Step-DnsServerSigningKeyRollover DnsServer
Function Suspend-DnsServerZone DnsServer
Function Sync-DnsServerZone DnsServer
Function Test-DnsServer DnsServer
Function Test-DnsServerDnsSecZoneSetting DnsServer
Function Unregister-DnsServerDirectoryPartition DnsServer
Function Update-DnsServerTrustPoint DnsServer

手册在:
https://technet.microsoft.com/library/jj649850(v=wps.630).aspx


------------------------------具体问题-------------------------------------------------


guest问:dns轮询压力不均的问题
最近一直对DNS轮询有一个疑问,我在一个域名下挂了十多个IP,实现简单的负载均衡功能。
但明显发现这种轮询不是很均匀,有一台服务器上的压力始终很高,其他的比较接近,但将此台压力高的从dns列表上去掉后,列表中的下一台压力又会高起来,
此时再把先前那一台加回dns列表,压力就又转回到第一台上去了。已经排除了攻击的可能。这个问题一直困扰了我很久,不知是bind的bug还是我设置ttl或是其他什么的原因,不知有没有高人对这方面有所研究的?

user1答:
DNS 轮询机制会受到多方面的影响,如:A记录的TTL时间长短的影响;别的 DNS 服务器 Cache 的影响;windows 客户端也有一个 DNS Cache。
这些都会影响 DNS 轮询的效果。因此 DNS 的轮询机制并不能做为一个 load balancing 的解决方案,只能作为一个 load distribution 方案。

user2答:
绝大部分网民用的上网系统为WINDOWS系统,在WINDOWS系统上默认开启dns cache服务,这就造成在一个TTL周期内DNS轮询是无效的。
所以为了减小dns cache对轮询效果的影响,通行的做法是减小TTL的值如60-300。(TTL太小也是有害的,故而需要慎重对待)

 

-------------------------问题分析过程------------------------------------


1 user1,user2说的很好,所以我引用了。ttl不宜太小正常即可。

2 我把这个过程比喻成,【呼啦超】那么多的食客来问你,你家的饭店的分店咋走,然后进你家的分店,去吃喝。
你家饭店假设有n家分店,每家最大接待能力不同,当前拥有的客人数不同,剩余的接待能力不同。

3 由于上两个人说的问题,导致了这样的结果,你不可能知道未来啥时候有食客来查分店地址(时间),因为有缓存,你也不可能知道未来食客具体有多少人(用户数量)。你也不可能知道查了ip的食客中,有多少会来吃

4 所以说必须有一个【每分店剩余接待能力反馈】!
即有一个值,服务器连接失败,取值失败,则返回-1。-1太多则报警。
值为0,则代表分店客满,0太多则报警。我ps脚本就会跳过这家分店。
正常的值为0----1之间的数,表示这家分店的接の客能力。每个服务器有了这个数值供给,剩下就好办了。

 

5 为什么用win的dns?
答:
5.1 主要因为有powershell。
我记得bind无法用命令添加a记录等,并立即生效。这样的话拍马也赶不上powershell了!你要搞个程序去修改dns区域文件,然后reload分区。这样性能很差吧。
powershell命令管理dns是内存操作。主要用到的命令就这四个:
Add-DnsServerResourceRecordA,Add-DnsServerResourceRecordCName,Get-DnsServerResourceRecord,Remove-DnsServerResourceRecord

5.2 win的dns性能无问题:我记得bind是多进程的程序,可以用多核跑,无性能制约。而win2000中说win的dns比bind效率高。
dns还都是10年前都成熟的东西。退一万步来讲,win的dns玩一千个以下的ip解析,不会有性能问题。

5.3 可以用win做主dns服务器,linux+bind做缓存。win放内网,linux放外网,只从外网dns缓存取数据。

 

-------------------------我给出的,问题解题流程------------------------------------


1 用任务计划,每1---n分钟定期调用powershell脚本解题。这里假设都是1分钟。
脚本运行后,把自己的pid放入环境变量,然后继续运行。
脚本重新运行后,从环境变量中查找前一个脚本的pid,杀死前一个脚本。然后重复上一步,避免脚本死锁。

2 用一个ps程序,从每家分店取回来,每家分店的(剩余)接待能力。
即有一个值,服务器连接失败,取值失败,则返回-1。-1太多则报警。
值为0,则代表分店客满,0太多则报警。我ps脚本就会跳过这家分店。
正常的值为0----1之间的数,表示这家分店的接の客能力。

powershell 传教士 原创文章 2015-11-25改允许转载,但必须保留名字和出处,否则追究法律责任
3 从这n家分店返回的接客能力中,总是挑2家最闲(数值最大)分店,把这2个新的a记录写入dns,然后删除所有旧的a记录。
设【取接待能力时间】为α秒,这里暗含着等待60-α-2秒。α如果较大则应增加任务计划分钟数。

结论:
我这个方法就是用dns来搞均衡,
我这个方法就是要告诉你,怎么搞的很均衡。
就是用我发明的填坑法,永远只填最大的两个坑!永远把最空闲的服务器的ip,放入dns服务器,解析给客户!

当然这里也可以用循环法,随机法,来进行负载均衡。


-------------------------解题具体脚本------------------------------------

#Requires -RunAsAdministrator
# 更换dns的a记录,到最大接待能力2台机的ip子上。

[string]$域名 = "aaaaxxxx.com"
[string]$主机名 = "ppp"
[int32]$服务器客满值 = 3
[int32]$服务器无响应值 = 2
$日志文件存储位置 = 'd:\aaa.txt'$分店01 = @{'ip' = '1.2.3.4';'接待能力' = 0}
$分店02 = @{'ip' = '2.2.3.4';'接待能力' = 0}
$分店03 = @{'ip' = '3.2.3.4';'接待能力' = 0}
$分店04 = @{'ip' = '4.2.3.4';'接待能力' = 0}
$分店05 = @{'ip' = '5.2.3.4';'接待能力' = 0}
$分店06 = @{'ip' = '6.2.3.4';'接待能力' = 0}
$分店07 = @{'ip' = '7.2.3.4';'接待能力' = 0}
$分店08 = @{'ip' = '8.2.3.4';'接待能力' = 0}
$分店09 = @{'ip' = '9.2.3.4';'接待能力' = 0}
$分店10 = @{'ip' = '10.2.3.4';'接待能力' = 0}
$各分店集合 = $分店01,$分店02,$分店03,$分店04,$分店05,$分店06,$分店07,$分店08,$分店09,$分店10if ($env:dnschanger_pid -ne $null)
{$temp001 = Get-Process -id $env:dnschanger_pidif ($temp001 -ne $null){Stop-Process $temp001 -Force}
}
[System.Environment]::SetEnvironmentvariable("dnschanger_pid","$PID", "user")function 获取分店接待能力
{
<#

用powershell监控win的CPU、IO、网络的处理能力,自古有之+网上大把。用powershell+ssh模块取linux的CPU、IO、网络、服务处理能力,还用我教你么?

这个函数返回一个值。 若服务器连接失败,或取值失败,则返回-1。-1太多则报警。 值为0,则代表分店客满,0太多则报警。我ps脚本就会跳过这家分店。 正常的返回值为0----1之间的数,表示这家分店的接の客能力。 #> }function 服务器客满报警 {}function 服务器无响应报警 {}# 无响应返回 -1,客满返回0,正常返回0----1间的值 $分店01.'接待能力' = 获取分店接待能力 "aaa" 123 $分店02.'接待能力' = 获取分店接待能力 "aaa" 123 $分店03.'接待能力' = 获取分店接待能力 "aaa" 123 $分店04.'接待能力' = 获取分店接待能力 "aaa" 123 $分店05.'接待能力' = 获取分店接待能力 "aaa" 123 $分店06.'接待能力' = 获取分店接待能力 "aaa" 123 $分店07.'接待能力' = 获取分店接待能力 "aaa" 123 $分店08.'接待能力' = 获取分店接待能力 "aaa" 123 $分店09.'接待能力' = 获取分店接待能力 "aaa" 123 $分店10.'接待能力' = 获取分店接待能力 "aaa" 123 $各分店接待能力集合 = $分店01.'接待能力',$分店02.'接待能力',$分店03.'接待能力',$分店04.'接待能力',$分店05.'接待能力',$分店06.'接待能力',$分店07.'接待能力',$分店08.'接待能力',$分店09.'接待能力',$分店10.'接待能力' [system.array]::Sort($各分店接待能力集合) $分组 = Group-Object -InputObject $各分店接待能力集合 if (($分组[0].name -eq -1) -and ($分组[0].Count -gt $服务器无响应值) ) {服务器无响应报警$err_msg = '服务器无响应!'Write-Error $err_msg$日期 = Get-date -Format FAdd-Content -Value $("$日期 $err_msg") -LiteralPath $日志文件存储位置 exit 1 }if (($分组[0].name -eq 0) -and ($分组[0].Count -gt $服务器客满值) ) {服务器客满报警$err_msg = '客满分店太多!'Write-Error $err_msg$日期 = Get-date -Format FAdd-Content -Value $("$日期 $err_msg") -LiteralPath $日志文件存储位置 exit 2 }# ----------------------------------------- $状元 = $各分店接待能力集合[-1] $榜眼 = $各分店接待能力集合[-2]foreach ($temp011 in $各分店集合) {if ($temp011.'接待能力' -eq $状元){[string]$ip1 = $temp011.'ip'}if ($temp011.'接待能力' -eq $榜眼){[string]$ip2 = $temp011.'ip'}}#Import-Module -name DnsServer $旧的dns记录 = Get-DnsServerResourceRecord -ZoneName $域名 -Name $主机名 -RRType "A" $旧的ip = $旧的dns记录.RecordData.IPv4Address.IPAddressToString Add-DnsServerResourceRecord -A -ZoneName $域名 -Name $主机名 -IPv4Address $ip1 -TimeToLive 01:00:00 Add-DnsServerResourceRecord -A -ZoneName $域名 -Name $主机名 -IPv4Address $ip2 -TimeToLive 01:00:00 #Add-DnsServerResourceRecord -CName -ZoneName $域名 -Name $主机名 -HostNameAlias "Host34.lab.com" -TimeToLive 01:00:00 foreach ($temp002 in $旧的ip) {Remove-DnsServerResourceRecord -ZoneName $域名 -Name $主机名 -RRType "A" -RecordData $temp002 -Force }

 

http://www.cnblogs.com/piapia/p/4997916.html

转载于:https://www.cnblogs.com/piapia/p/4997916.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/574160.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

csv python 只写一次_在Python CSV Writer循环中写入一次头

下面是一个scraper&#xff0c;它遍历两个网站&#xff0c;获取团队的花名册信息&#xff0c;将信息放入一个数组中&#xff0c;然后将数组导出到CSV文件中。一切都很好&#xff0c;但唯一的问题是每次scraper移动到第二个网站时&#xff0c;csv文件中的writerow头会重复出现。…

理解 OpenStack 高可用(HA) (6): MySQL HA

本系列会分析OpenStack 的高可用性&#xff08;HA&#xff09;概念和解决方案&#xff1a; &#xff08;1&#xff09;OpenStack 高可用方案概述 &#xff08;2&#xff09;Neutron L3 Agent HA - VRRP &#xff08;虚拟路由冗余协议&#xff09; &#xff08;3&#xff09;Neu…

聚类中心坐标公式如何使用_如何使用CAD看图软件来测量坐标?

当我们在拿到图纸的时候&#xff0c;经常会需要使用测量工具&#xff0c;再次测量dwg图纸上的数据。浩辰CAD看图王软件&#xff0c;不仅可以看图&#xff0c;也可以编辑图纸&#xff0c;测量功能更是很方便&#xff0c;当我们在测量的时候&#xff0c;如何测量图纸上点的坐标呢…

linunx 定位最耗资源的进程

[oracletopbox bdump]$ ps -ef|grep “(LOCALNO)”|sort -rn -k 8,8|head -10oracle 9402 1 67 09:18 ? 00:43:09 oracletopbox (LOCALNO)oracle 15524 12159 0 10:21 pts/2 00:00:00 grep (LOCALNO)oracle 15519 1 0 10:20 ? 00:00:00 or…

德利捷读码器设置软件_S7-1500PLC+变频器+编码器组成位置控制系统

PLC学习中组成部分&#xff1a;位置控制、力矩控制、惯量控制。位置控制模式S7-1500 的运动控制功能支持轴的定位和移动&#xff0c;是 S7-1500 系列 CPU 众多集成功能中的重要组成部分。运动控制功能支持旋转轴、定位轴、同步轴和外部编码器等工艺对象。根据PLC-Open&#xff…

解决 c3p0 和 MySQL 集成情况下,连接长时间闲置后重新使用时报错的问题

MySQL 的默认设置下&#xff0c;当一个连接的空闲时间超过8小时后&#xff0c;MySQL 就会断开该连接&#xff0c;而 c3p0 连接池则以为该被断开的连接依然有效。在这种情况下&#xff0c;如果客户端代码向 c3p0 连接池请求连接的话&#xff0c;连接池就会把已经失效的连接返回给…

汇编语言基础知识摘要(《汇编语言》王爽)第 1 / 17 章

CPU&#xff0c;是计算机的核心部件&#xff0c;它控制整个计算机的运作并进行运算。存储器&#xff0c;即内存&#xff0c;存放CPU需要的指令和数据。寄存器&#xff0c;是CPU中可以储存数据的器件&#xff0c;一个CPU中有多个寄存器。汇编语言由以下3类指令组成&#xff1a; …

vue 添加全局组件_自定义vue2.0全局组件(下篇)

在上篇中&#xff0c;老K为大家介绍了一个初级自定义按钮组件的编写方法。虽然能用&#xff0c;但是还不算完美&#xff0c;可扩展性不够强大。在这一篇中&#xff0c;老K继续为大家完善这个按钮组件。启动命令窗口&#xff0c; 进入在上篇中我们搭建的vue目录中&#xff0c;输…

dijkstra算法matlab程序_Dijkstra算法例子

在Dijkstra算法代码下载本文涉及到的代码。程序代码Dijkstra算法的程序如下&#xff1a;function [d, p] dijkstra(adj, s, t) % 使用dijkstra求最短路径 % adj 输入 矩阵 邻接矩阵 % s 输入 整数 起点 % t 输入 整数 或 [] 终…

hdu 3836 Equivalent Sets

题目连接 http://acm.hdu.edu.cn/showproblem.php?pid3836 Equivalent Sets Description To prove two sets A and B are equivalent, we can first prove A is a subset of B, and then prove B is a subset of A, so finally we got that these two sets are equivalent.Y…

mysql-5.7.24 linux下载_Linux下安装mysql-5.7.24

本文档讲解安装版本为mysql-5.7.24&#xff0c;对于5.7.24之后的版本&#xff0c;不适用此说明文档&#xff0c;主要原因在于之后版本的mysql配置文件的目录位置和结构有所改变&#xff0c;使用此说明可能会出现找不到配置文件或者配置后不生效的情况。安装过程中务必保证文件路…

Spring MVC拦截器+注解方式实现防止表单重复提交

原理&#xff1a;在新建页面中Session保存token随机码&#xff0c;当保存时验证&#xff0c;通过后删除&#xff0c;当再次点击保存时由于服务器端的Session中已经不存在了&#xff0c;所有无法验证通过。 注&#xff0c;如果是集群的方式&#xff0c;则需要将token放入到缓存中…

JavaScript学习笔记(一)—— 数据类型

一、基本数据类型&#xff1a;1、js中基本数据类型:String、Boolean、Number、Null、undefined&#xff1b;复合数据类型&#xff1a;object对象类型、Array数组类型特殊对象&#xff1a;function函数类型基本数据类型① String —字符串。若使用var声明变量&#xff0c;var x…

mysql分组失效_请教MySql中使用表子查询时,试着先排序后分组,出现排序失效的原因?...

1,今天试着码了一下教程里的题目,是找出每一个班级的身高最高的学生,用的是先order by降序排序所有学生升高,再用group by分组每一个班级取第一个值,却发现当使用子查询时,得到的仍旧是未排序时的结果,即没有取到最高身高,想问下为何使用子查询时,order by会失效,谢谢!↑这是建…

MySQL后初次密码_mysql第一次安装成功后初始化密码操作步骤

把文件解压到一个目录下这是解压后的目录将my.ini文件考进去双击打开my.ini找到这两行更改成自己的解压路径保存右键此电脑属性找到高级系统设置配置环境变量环境变量 新建 变量值是解压文件的路径Path 单击path编辑新建之后 用管理员身份打开cmd进入文件路径打开命令行窗口&am…

JQuery 操作 radio 被坑一例

.removeAttr(checked); .prop(checked,false); .prop(checked,true); 与 .attr("checked",true); .attr("checked",true); 有本质区别&#xff0c;上边的方法效果理想。转载于:https://www.cnblogs.com/rgqancy/p/5017357.html

mysql技术简介_mysql的简介和使用

mysql简介数据的所有存储&#xff0c;检索&#xff0c;管理和处理实际上是由数据库软件--DBMS(数据库管理系统)完成的mysql是一种DBMS&#xff0c;即它是一种数据库软件mysql工具mysql是一个客户机-服务器的DBMS。因此为了使用mysql&#xff0c;需要一个客户机&#xff0c;即提…

unity3d 随机物体生成器 工具

根据输入的物体生成随机成组的物体. 1 /// <summary>2 /// 本脚本可以由输入的预制 生成以本物体为中心的随机预制,支持预制打组3 /// 随机物体生成器(尤其试用于场景中静态物体随机摆放)4 /// </summary>5 using UnityEngine;6 using System.Collections;7 using …

mysql 大分页查询优化_Mysql骚操作:优化大分页查询

背景系统结构如上图。经过排查是因为系统B拉取数据时间太长导致的推送超时。系统B拉取数据的方法是根据_tiemstamp(数据操作时间)分页查询系统A的接口,即&#xff1a;1SELECT 字段名2FROM 表名3WHERE _timestamp > beginTime AND _timestamp < endTime 4LIMIT n, m;由于该…

python --动态类型

转自&#xff1a;http://www.cnblogs.com/vamei/archive/2012/07/10/2582795.html 动态类型(dynamic typing)是Python另一个重要的核心概念。我们之前说过&#xff0c;Python的变量(variable)不需要声明&#xff0c;而在赋值时&#xff0c;变量可以重新赋值为任意值。这些都与动…