您的位置:首页 > 文旅 > 美景 > 在线制作头像模板_河北建设工程信息网招聘网_常用的网络营销推广方法有哪些_微博关键词排名优化

在线制作头像模板_河北建设工程信息网招聘网_常用的网络营销推广方法有哪些_微博关键词排名优化

2025/1/8 13:38:09 来源:https://blog.csdn.net/byc233518/article/details/144825703  浏览:    关键词:在线制作头像模板_河北建设工程信息网招聘网_常用的网络营销推广方法有哪些_微博关键词排名优化
在线制作头像模板_河北建设工程信息网招聘网_常用的网络营销推广方法有哪些_微博关键词排名优化

基本信息:

VIP: 10.50.1.170

node1: 10.50.1.171

node2: 10.50.1.172

实现原理:

1. 脚本每2s 运行一次(注册为windows 服务, 开机同步启动)

2. 监听VIP 是否可用, 可用则跳过;

3. 如果不可用 则 判断本机 Nginx 服务是否可用

3.1 可用则执行绑定动作, 将VIP绑定到本机

3.2 不可用则跳过 

脚本:

while ($true) {# 1. 判断 http://10.50.1.170/health 返回是否是OKWrite-Host "Checking Nginx health status via http://10.50.1.170/health..."try {$response = Invoke-WebRequest -Uri "http://10.50.1.170/health" -UseBasicParsing -Method HEAD -TimeoutSec 2 -ErrorAction Stop$status = if ($response.StatusCode -eq 200) { "OK" } else { "NOT OK" }Write-Host "Nginx health status: $status"}catch {$status = "ERROR"Write-Host "Error accessing Nginx health status: $($_.Exception.Message)"}# 2. 如果第1步返回的OK 则不做任何处理if ($status -eq "OK") {Write-Host "Nginx health status is OK, no operation needed."}else {# 3. 如果第一步返回的不是OK, 则执行解绑VIP的动作Write-Host "Nginx health status is not OK, starting to remove VIP binding..."$vip = "10.50.1.170"$interfaceName = "Ethernet0"$interfaceInfo = Get-NetIPAddress -InterfaceAlias $interfaceName -ErrorAction SilentlyContinue$vipExists = $interfaceInfo | Where-Object { $_.IPAddress -eq $vip }if ($vipExists) {try {Remove-NetIPAddress -IPAddress $vip -InterfaceAlias $interfaceName -ErrorAction Stop -Confirm:$falseWrite-Host "Removed VIP $vip binding from $interfaceName interface."}catch {Write-Host "Failed to remove VIP $vip binding. Error: $($_.Exception.Message)"}}else {Write-Host "VIP $vip is not bound on $interfaceName interface."}# 4. 然后判断本机Nginx (jg-nginx) 是否可用Write-Host "Checking if local Nginx (jg-nginx) is available..."$localNginxProcess = Get-Process -Name "jg-nginx" -ErrorAction SilentlyContinueif ($localNginxProcess) {Write-Host "Local Nginx (jg-nginx) is available."# 5. 如果可用则执行绑定VIP的动作Write-Host "Starting to bind VIP $vip to $interfaceName interface..."try {New-NetIPAddress -IPAddress $vip -PrefixLength 32 -InterfaceAlias $interfaceName -ErrorAction Stop -Confirm:$falseWrite-Host "VIP $vip bound to $interfaceName interface."}catch {Write-Host "Failed to bind VIP $vip. Error: $($_.Exception.Message)"}}else {Write-Host "Local Nginx (jg-nginx) is not available, skipping VIP binding."}}# 等待2秒后再次循环执行Start-Sleep -Seconds 2
}

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com