github.com/polarismesh/polaris@v1.17.8/release/standalone/windows/install-windows.ps1 (about) 1 # Tencent is pleased to support the open source community by making Polaris available. 2 # 3 # Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. 4 # 5 # Licensed under the BSD 3-Clause License (the "License"); 6 # you may not use this file except in compliance with the License. 7 # You may obtain a copy of the License at 8 # 9 # https://opensource.org/licenses/BSD-3-Clause 10 # 11 # Unless required by applicable law or agreed to in writing, software distributed 12 # under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 # CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 # specific language governing permissions and limitations under the License. 15 16 $ErrorActionPreference = "Stop" 17 18 function installPolarisServer() { 19 Write-Output "install polaris server ... " 20 $polaris_server_num = (Get-Process | findstr "polaris-server" | Measure-Object -Line).Lines 21 if ($polaris_server_num -gt 0) { 22 Write-Output "polaris-server is running, skip" 23 return 24 } 25 $polaris_server_pkg_num = (Get-ChildItem "polaris-server-release*.zip" | Measure-Object -Line).Lines 26 if ($polaris_server_pkg_num -ne 1) { 27 Write-Output "number of polaris server package not equals to 1, exit" 28 exit -1 29 } 30 $target_polaris_server_pkg = (Get-ChildItem "polaris-server-release*.zip")[0].Name 31 $polaris_server_dirname = ([io.fileinfo]$target_polaris_server_pkg).basename 32 if (Test-Path $polaris_server_dirname) { 33 Write-Output "$polaris_server_dirname has exists, now remove it" 34 Remove-Item $polaris_server_dirname -Recurse 35 } 36 Expand-Archive -Path $target_polaris_server_pkg -DestinationPath . 37 Push-Location $polaris_server_dirname 38 sed "conf/polaris-server.yaml" "listenPort: 8761" "listenPort: ${eureka_port}" 39 sed "conf/polaris-server.yaml" "listenPort: 15010" "listenPort: ${xdsv3_port}" 40 sed "conf/polaris-server.yaml" "listenPort: 8091" "listenPort: ${service_grpc_port}" 41 sed "conf/polaris-server.yaml" "listenPort: 8093" "listenPort: ${config_grpc_port}" 42 sed "conf/polaris-server.yaml" "listenPort: 8090" "listenPort: ${api_http_port}" 43 Start-Process -FilePath ".\\polaris-server.exe" -ArgumentList ('start') -WindowStyle Hidden 44 Write-Output "install polaris server success" 45 Pop-Location 46 } 47 48 49 function installPolarisConsole() { 50 Write-Output "install polaris console ... " 51 $polaris_console_num = (Get-Process | findstr "polaris-console" | Measure-Object -Line).Lines 52 if ($polaris_console_num -gt 0) { 53 Write-Output "polaris-console is running, skip" 54 return 55 } 56 $polaris_console_pkg_num = (Get-ChildItem "polaris-console-release*.zip" | Measure-Object -Line).Lines 57 if ($polaris_console_pkg_num -ne 1) { 58 Write-Output "number of polaris console package not equals to 1, exit" 59 exit -1 60 } 61 $target_polaris_console_pkg = (Get-ChildItem "polaris-console-release*.zip")[0].Name 62 $polaris_console_dirname = ([io.fileinfo]$target_polaris_console_pkg).basename 63 if (Test-Path $polaris_console_dirname) { 64 Write-Output "$polaris_console_dirname has exists, now remove it" 65 Remove-Item $polaris_console_dirname -Recurse 66 } 67 Expand-Archive -Path $target_polaris_console_pkg -DestinationPath . 68 Push-Location $polaris_console_dirname 69 sed "polaris-console.yaml" "listenPort: 8080" "listenPort: ${console_port}" 70 sed "polaris-console.yaml" "address: '127.0.0.1:8090'" "address: '127.0.0.1:'${api_http_port}'" 71 sed "polaris-console.yaml" "address: '127.0.0.1:9090'" "address: '127.0.0.1:'${prometheus_port}'" 72 Start-Process -FilePath ".\\polaris-console.exe" -ArgumentList ('start') -WindowStyle Hidden 73 Write-Output "install polaris console success" 74 Pop-Location 75 } 76 77 function installPolarisLimiter() { 78 Write-Output "install polaris limiter ... " 79 $polaris_limiter_num = (Get-Process | findstr "polaris-limiter" | Measure-Object -Line).Lines 80 if ($polaris_limiter_num -gt 0) { 81 Write-Output "polaris-limiter is running, skip" 82 return 83 } 84 $polaris_limiter_pkg_num = (Get-ChildItem "polaris-limiter-release*.zip" | Measure-Object -Line).Lines 85 if ($polaris_limiter_pkg_num -ne 1) { 86 Write-Output "number of polaris limiter package not equals to 1, exit" 87 exit -1 88 } 89 $target_polaris_limiter_pkg = (Get-ChildItem "polaris-limiter-release*.zip")[0].Name 90 $polaris_limiter_dirname = ([io.fileinfo]$target_polaris_limiter_pkg).basename 91 if (Test-Path $polaris_limiter_dirname) { 92 Write-Output "$polaris_limiter_dirname has exists, now remove it" 93 Remove-Item $polaris_limiter_dirname -Recurse 94 } 95 Expand-Archive -Path $target_polaris_limiter_pkg -DestinationPath . 96 Push-Location $polaris_limiter_dirname 97 sed "polaris-limiter.yaml" "polaris-server-address: 127.0.0.1:8091" "polaris-server-address: 127.0.0.1:${service_grpc_port}" 98 sed "polaris-limiter.yaml" "port: 8100" "port: ${limiter_http_port}" 99 sed "polaris-limiter.yaml" "port: 8101" "port: ${limiter_grpc_port}" 100 Start-Process -FilePath ".\\polaris-limiter.exe" -ArgumentList ('start') -WindowStyle Hidden 101 Write-Output "install polaris limiter success" 102 Pop-Location 103 } 104 105 106 function installPrometheus() { 107 Write-Output "install prometheus ... " 108 $prometheus_num = (Get-Process | findstr "prometheus" | Measure-Object -Line).Lines 109 if ($prometheus_num -gt 0) { 110 Write-Output "prometheus is running, skip" 111 return 112 } 113 $prometheus_pkg_num = (Get-ChildItem "prometheus-*.zip" | Measure-Object -Line).Lines 114 if ($prometheus_pkg_num -ne 1) { 115 Write-Output "number of prometheus package not equals to 1, exit" 116 exit -1 117 } 118 $target_prometheus_pkg = (Get-ChildItem "prometheus-*.zip")[0].Name 119 $prometheus_dirname = ([io.fileinfo]$target_prometheus_pkg).basename 120 if (Test-Path $prometheus_dirname) { 121 Write-Output "$prometheus_dirname has exists, now remove it" 122 Remove-Item $prometheus_dirname -Recurse 123 } 124 Expand-Archive -Path $target_prometheus_pkg -DestinationPath . 125 Push-Location $prometheus_dirname 126 Add-Content prometheus.yml " http_sd_configs:" 127 Add-Content prometheus.yml " - url: http://localhost:8090/prometheus/v1/clients" 128 Add-Content prometheus.yml "" 129 Add-Content prometheus.yml " - job_name: 'push-metrics'" 130 Add-Content prometheus.yml " static_configs:" 131 Add-Content prometheus.yml " - targets: ['localhost:9091']" 132 Add-Content prometheus.yml " honor_labels: true" 133 Start-Process -FilePath ".\\prometheus.exe" -ArgumentList ('--web.enable-lifecycle', '--web.enable-admin-api') -RedirectStandardOutput prometheus.out -RedirectStandardError prometheus.err -WindowStyle Hidden 134 Write-Output "install prometheus success" 135 Pop-Location 136 } 137 138 function installPushGateway() { 139 Write-Output "install pushgateway ... " 140 $pgw_num = (Get-Process | findstr "pushgateway" | Measure-Object -Line).Lines 141 if ($pgw_num -gt 0) { 142 Write-Output "pushgateway is running, skip" 143 return 144 } 145 $pgw_pkg_num = (Get-ChildItem "pushgateway-*.zip" | Measure-Object -Line).Lines 146 if ($pgw_pkg_num -ne 1) { 147 Write-Output "number of pushgateway package not equals to 1, exit" 148 exit -1 149 } 150 $target_pgw_pkg = (Get-ChildItem "pushgateway-*.zip")[0].Name 151 $pgw_dirname = ([io.fileinfo]$target_pgw_pkg).basename 152 if (Test-Path $pgw_dirname) { 153 Write-Output "$pgw_dirname has exists, now remove it" 154 Remove-Item $pgw_dirname -Recurse 155 } 156 Expand-Archive -Path $target_pgw_pkg -DestinationPath . 157 Push-Location $pgw_dirname 158 Start-Process -FilePath ".\\pushgateway.exe" -ArgumentList ('--web.enable-lifecycle', '--web.enable-admin-api') -RedirectStandardOutput pgw.out -RedirectStandardError pgw.err -WindowStyle Hidden 159 Write-Output "install pushgateway success" 160 Pop-Location 161 } 162 163 $fileContent = Get-Content port.properties 164 $fileContent = $fileContent -join [Environment]::NewLine 165 $config = ConvertFrom-StringData($fileContent) 166 $console_port = $config.'polaris_console_port' 167 $eureka_port = $config.'polaris_eureka_port' 168 $xdsv3_port = $config.'polaris_xdsv3_port' 169 $service_grpc_port = $config.'polaris_service_grpc_port' 170 $config_grpc_port = $config.'polaris_config_grpc_port' 171 $api_http_port = $config.'polaris_open_api_port' 172 $prometheus_port = $config.'prometheus_port' 173 $pushgateway_port = $config.'pushgateway_port' 174 $limiter_http_port = $config.'polaris_limiter_http_port' 175 $limiter_grpc_port = $config.'polaris_limiter_grpc_port' 176 177 function checkPort() { 178 $ports = $console_port, $eureka_port, $xdsv3_port, $prometheus_sd_port, $service_grpc_port, $config_grpc_port, $api_http_port, $prometheus_port, $pushgateway_port, $limiter_http_port,$limiter_grpc_port 179 foreach ($port in $ports) 180 { 181 $processInfo = netstat -ano | findstr "LISTENING" | findstr $port 182 if($processInfo) 183 { 184 Write-Output $processInfo 185 Write-Output "port $port has been used, exit" 186 exit -1 187 } 188 } 189 } 190 191 function sed($Filename, $Oldvalue, $Newvalue) { 192 if (Test-Path $Filename) { 193 $content = get-content $Filename 194 clear-content $Filename 195 foreach($line in $content) { 196 $liner=$line.Replace($Oldvalue, $Newvalue) 197 Add-content $Filename -Value $liner 198 } 199 } 200 } 201 202 203 # 检查端口占用 204 checkPort 205 # 安装server 206 installPolarisServer 207 # 安装console 208 installPolarisConsole 209 # 安装polaris-limiter 210 installPolarisLimiter 211 # 安装Prometheus 212 installPrometheus 213 # 安装Prometheus 214 installPushGateway