日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

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

發(fā)布時間:2025/3/15 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 powershell加win的dns服务器,解决网站负载均衡问题 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

?

用我發(fā)明的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 傳教士 原創(chuàng)文章 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,實現簡單的負載均衡功能。
但明顯發(fā)現這種輪詢不是很均勻,有一臺服務器上的壓力始終很高,其他的比較接近,但將此臺壓力高的從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區(qū)域文件,然后reload分區(qū)。這樣性能很差吧。
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放入環(huán)境變量,然后繼續(xù)運行。
腳本重新運行后,從環(huán)境變量中查找前一個腳本的pid,殺死前一個腳本。然后重復上一步,避免腳本死鎖。

2 用一個ps程序,從每家分店取回來,每家分店的(剩余)接待能力。
即有一個值,服務器連接失敗,取值失敗,則返回-1。-1太多則報警。
值為0,則代表分店客滿,0太多則報警。我ps腳本就會跳過這家分店。
正常的值為0----1之間的數,表示這家分店的接の客能力。

powershell 傳教士 原創(chuàng)文章 2015-11-25改允許轉載,但必須保留名字和出處,否則追究法律責任
3 從這n家分店返回的接客能力中,總是挑2家最閑(數值最大)分店,把這2個新的a記錄寫入dns,然后刪除所有舊的a記錄。
設【取接待能力時間】為α秒,這里暗含著等待60-α-2秒。α如果較大則應增加任務計劃分鐘數。

結論:
我這個方法就是用dns來搞均衡,
我這個方法就是要告訴你,怎么搞的很均衡。
就是用我發(fā)明的填坑法,永遠只填最大的兩個坑!永遠把最空閑的服務器的ip,放入dns服務器,解析給客戶!

當然這里也可以用循環(huán)法,隨機法,來進行負載均衡。


-------------------------解題具體腳本------------------------------------

#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監(jiān)控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

總結

以上是生活随笔為你收集整理的powershell加win的dns服务器,解决网站负载均衡问题的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。