网站建设标新立异,网络舆情监测中心具体做什么,字体logo设计在线生成器,网上注册公司流程及费用用我发明的powershell填坑法#xff0c;加windows的dns服务器。从调整dns服务器解析ip时间段的角度#xff0c;解决网站负载均衡问题。 ------------------------win2012r2中#xff0c;用powershell管理dns服务器的#xff0c;命令列表-------------------------------- 共… 用我发明的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 DnsServerFunction Add-DnsServerConditionalForwarderZone DnsServerFunction Add-DnsServerDirectoryPartition DnsServerFunction Add-DnsServerForwarder DnsServerFunction Add-DnsServerPrimaryZone DnsServerFunction Add-DnsServerResourceRecord DnsServerFunction Add-DnsServerResourceRecordA DnsServerFunction Add-DnsServerResourceRecordAAAA DnsServerFunction Add-DnsServerResourceRecordCName DnsServerFunction Add-DnsServerResourceRecordDnsKey DnsServerFunction Add-DnsServerResourceRecordDS DnsServerFunction Add-DnsServerResourceRecordMX DnsServerFunction Add-DnsServerResourceRecordPtr DnsServerFunction Add-DnsServerRootHint DnsServerFunction Add-DnsServerSecondaryZone DnsServerFunction Add-DnsServerSigningKey DnsServerFunction Add-DnsServerStubZone DnsServerFunction Add-DnsServerTrustAnchor DnsServerFunction Add-DnsServerZoneDelegation DnsServerFunction Clear-DnsServerCache DnsServerFunction Clear-DnsServerStatistics DnsServerFunction ConvertTo-DnsServerPrimaryZone DnsServerFunction ConvertTo-DnsServerSecondaryZone DnsServerFunction Disable-DnsServerSigningKeyRollover DnsServerFunction Enable-DnsServerSigningKeyRollover DnsServerFunction Export-DnsServerDnsSecPublicKey DnsServerFunction Export-DnsServerZone DnsServerFunction Get-DnsServer DnsServerFunction Get-DnsServerCache DnsServerFunction Get-DnsServerDiagnostics DnsServerFunction Get-DnsServerDirectoryPartition DnsServerFunction Get-DnsServerDnsSecZoneSetting DnsServerFunction Get-DnsServerDsSetting DnsServerFunction Get-DnsServerEDns DnsServerFunction Get-DnsServerForwarder DnsServerFunction Get-DnsServerGlobalNameZone DnsServerFunction Get-DnsServerGlobalQueryBlockList DnsServerFunction Get-DnsServerRecursion DnsServerFunction Get-DnsServerResourceRecord DnsServerFunction Get-DnsServerRootHint DnsServerFunction Get-DnsServerScavenging DnsServerFunction Get-DnsServerSetting DnsServerFunction Get-DnsServerSigningKey DnsServerFunction Get-DnsServerStatistics DnsServerFunction Get-DnsServerTrustAnchor DnsServerFunction Get-DnsServerTrustPoint DnsServerFunction Get-DnsServerZone DnsServerFunction Get-DnsServerZoneAging DnsServerFunction Get-DnsServerZoneDelegation DnsServerpowershell 传教士 原创文章 2015-11-25改允许转载但必须保留名字和出处否则追究法律责任Function Import-DnsServerResourceRecordDS DnsServerFunction Import-DnsServerRootHint DnsServerFunction Import-DnsServerTrustAnchor DnsServerFunction Invoke-DnsServerSigningKeyRollover DnsServerFunction Invoke-DnsServerZoneSign DnsServerFunction Invoke-DnsServerZoneUnsign DnsServerFunction Register-DnsServerDirectoryPartition DnsServerFunction Remove-DnsServerDirectoryPartition DnsServerFunction Remove-DnsServerForwarder DnsServerFunction Remove-DnsServerResourceRecord DnsServerFunction Remove-DnsServerRootHint DnsServerFunction Remove-DnsServerSigningKey DnsServerFunction Remove-DnsServerTrustAnchor DnsServerFunction Remove-DnsServerZone DnsServerFunction Remove-DnsServerZoneDelegation DnsServerFunction Reset-DnsServerZoneKeyMasterRole DnsServerFunction Restore-DnsServerPrimaryZone DnsServerFunction Restore-DnsServerSecondaryZone DnsServerFunction Resume-DnsServerZone DnsServerFunction Set-DnsServer DnsServerFunction Set-DnsServerCache DnsServerFunction Set-DnsServerConditionalForwarderZone DnsServerFunction Set-DnsServerDiagnostics DnsServerFunction Set-DnsServerDnsSecZoneSetting DnsServerFunction Set-DnsServerDsSetting DnsServerFunction Set-DnsServerEDns DnsServerFunction Set-DnsServerForwarder DnsServerFunction Set-DnsServerGlobalNameZone DnsServerFunction Set-DnsServerGlobalQueryBlockList DnsServerFunction Set-DnsServerPrimaryZone DnsServerFunction Set-DnsServerRecursion DnsServerFunction Set-DnsServerResourceRecord DnsServerFunction Set-DnsServerResourceRecordAging DnsServerFunction Set-DnsServerRootHint DnsServerFunction Set-DnsServerScavenging DnsServerFunction Set-DnsServerSecondaryZone DnsServerFunction Set-DnsServerSetting DnsServerFunction Set-DnsServerSigningKey DnsServerFunction Set-DnsServerStubZone DnsServerFunction Set-DnsServerZoneAging DnsServerFunction Set-DnsServerZoneDelegation DnsServerFunction Show-DnsServerCache DnsServerFunction Show-DnsServerKeyStorageProvider DnsServerFunction Start-DnsServerScavenging DnsServerFunction Start-DnsServerZoneTransfer DnsServerFunction Step-DnsServerSigningKeyRollover DnsServerFunction Suspend-DnsServerZone DnsServerFunction Sync-DnsServerZone DnsServerFunction Test-DnsServer DnsServerFunction Test-DnsServerDnsSecZoneSetting DnsServerFunction Unregister-DnsServerDirectoryPartition DnsServerFunction Update-DnsServerTrustPoint DnsServer 手册在https://technet.microsoft.com/library/jj649850(vwps.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 user1user2说的很好所以我引用了。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-DnsServerResourceRecordAAdd-DnsServerResourceRecordCNameGet-DnsServerResourceRecordRemove-DnsServerResourceRecord 5.2 win的dns性能无问题我记得bind是多进程的程序可以用多核跑无性能制约。而win2000中说win的dns比bind效率高。dns还都是10年前都成熟的东西。退一万步来讲win的dns玩一千个以下的ip解析不会有性能问题。 5.3 可以用win做主dns服务器linuxbind做缓存。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、网络的处理能力自古有之网上大把。用powershellssh模块取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