github.com/polarismesh/polaris@v1.17.8/release/standalone/darwin/install.sh (about) 1 #!/bin/bash 2 # Tencent is pleased to support the open source community by making Polaris available. 3 # 4 # Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. 5 # 6 # Licensed under the BSD 3-Clause License (the "License"); 7 # you may not use this file except in compliance with the License. 8 # You may obtain a copy of the License at 9 # 10 # https://opensource.org/licenses/BSD-3-Clause 11 # 12 # Unless required by applicable law or agreed to in writing, software distributed 13 # under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 14 # CONDITIONS OF ANY KIND, either express or implied. See the License for the 15 # specific language governing permissions and limitations under the License. 16 17 # Get Darwin CPU is AMD64 or ARM64 18 ACTUAL_ARCH="$(/usr/bin/uname -m)" 19 EXPECT_ARCH=$(cat arch.txt) 20 21 actual_is_arm=$(/usr/bin/uname -m | grep "arm" | wc -l) 22 expect_is_arm=$(cat arch.txt | grep "arm" | wc -l) 23 24 if [ ${actual_is_arm} -ne ${expect_is_arm} ]; then 25 echo "machine arch is ${ACTUAL_ARCH}, but Installation package arch is ${EXPECT_ARCH}" 26 exit 1 27 fi 28 29 function getProperties() { 30 result="" 31 proFilePath="./port.properties" 32 key="$1" 33 if [ "WJA${key}" = "WJA" ]; then 34 echo "invalid param, pls set key" 35 echo "" >&2 36 exit 1 37 fi 38 if [ ! -r ${proFilePath} ]; then 39 echo "current use not file ${proFilePath} read and write permission" 40 echo "" >&2 41 exit 1 42 fi 43 keyLength=$(echo ${key} | awk '{print length($0)}') 44 lineNumStr=$(cat ${proFilePath} | wc -l) 45 lineNum=$((${lineNumStr})) 46 for ((i = 1; i <= ${lineNum}; i++)); do 47 oneLine=$(sed -n ${i}p ${proFilePath}) 48 if [ "${oneLine:0:((keyLength))}" = "${key}" ] && [ "${oneLine:$((keyLength)):1}" = "=" ]; then 49 result=${oneLine#*=} 50 break 51 fi 52 done 53 echo ${result} 54 } 55 56 echo "To allow polaris to be installed on your Mac, we need to open the install from anywhere 'sudo spctl 57 --master-disable'" 58 59 sudo spctl --master-disable >/dev/null 60 61 if [ "${0:0:1}" == "/" ]; then 62 install_path=$(dirname "$0") 63 else 64 install_path=$(pwd)/$(dirname "$0") 65 fi 66 67 console_port=$(getProperties "polaris_console_port") 68 69 eureka_port=$(getProperties "polaris_eureka_port") 70 xdsv3_port=$(getProperties "polaris_xdsv3_port") 71 service_grpc_port=$(getProperties "polaris_service_grpc_port") 72 config_grpc_port=$(getProperties "polaris_config_grpc_port") 73 api_http_port=$(getProperties "polaris_open_api_port") 74 75 prometheus_port=$(getProperties prometheus_port) 76 pushgateway_port=$(getProperties pushgateway_port) 77 78 limiter_http_port=$(getProperties "polaris_limiter_http_port") 79 limiter_grpc_port=$(getProperties "polaris_limiter_grpc_port") 80 81 echo "prepare install polaris standalone..." 82 83 echo "polaris-console listen port info" 84 echo "console_port=${console_port}" 85 echo "" 86 echo "polaris-server listen port info" 87 echo "eureka_port=${eureka_port}" 88 echo "xdsv3_port=${xdsv3_port}" 89 echo "prometheus_sd_port=${prometheus_sd_port}" 90 echo "service_grpc_port=${service_grpc_port}" 91 echo "config_grpc_port=${config_grpc_port}" 92 echo "api_http_port=${api_http_port}" 93 echo "" 94 echo "polaris-limiter-server listen port info" 95 echo "polaris_limiter_http_port=${limiter_http_port}" 96 echo "polaris_limiter_grpc_port=${limiter_grpc_port}" 97 echo "" 98 echo "prometheus-server listen port info" 99 echo "prometheus_server_port=${prometheus_port}" 100 echo "" 101 echo "pushgateway-server listen port info" 102 echo "pushgateway_server_port=${pushgateway_port}" 103 104 function installPolarisServer() { 105 echo -e "install polaris server ... " 106 local polaris_server_num=$(ps -ef | grep polaris-server | grep -v grep | wc -l) 107 if [ $polaris_server_num -ge 1 ]; then 108 echo -e "polaris-server is running, skip." 109 return 110 fi 111 112 local polaris_server_tarnum=$(find . -name "polaris-server-release*.zip" | wc -l) 113 if [ $polaris_server_tarnum != 1 ]; then 114 echo -e "number of polaris server tar not equal 1, exit." 115 exit -1 116 fi 117 118 local polaris_server_tarname=$(find . -name "polaris-server-release*.zip") 119 local polaris_server_dirname=$(basename ${polaris_server_tarname} .zip) 120 if [ ! -e $polaris_server_dirname ]; then 121 unzip $polaris_server_tarname >/dev/null 122 else 123 echo -e "polaris-server-release.tar.gz has been decompressed, skip." 124 fi 125 126 cd ${polaris_server_dirname} || ( 127 echo "no such directory ${polaris_server_dirname}" 128 exit -1 129 ) 130 131 # 备份 polaris-server.yaml 132 cp conf/polaris-server.yaml conf/polaris-server.yaml.bak 133 134 # 修改 polaris-server eureka 端口信息 135 sed -i "" "s/listenPort: 8761/listenPort: ${eureka_port}/g" conf/polaris-server.yaml 136 # 修改 polaris-server xdsv3 端口信息 137 sed -i "" "s/listenPort: 15010/listenPort: ${xdsv3_port}/g" conf/polaris-server.yaml 138 # 修改 polaris-server service-grpc 端口信息 139 sed -i "" "s/listenPort: 8091/listenPort: ${service_grpc_port}/g" conf/polaris-server.yaml 140 # 修改 polaris-server config-grpc 端口信息 141 sed -i "" "s/listenPort: 8093/listenPort: ${config_grpc_port}/g" conf/polaris-server.yaml 142 # 修改 polaris-server http-api 端口信息 143 sed -i "" "s/listenPort: 8090/listenPort: ${api_http_port}/g" conf/polaris-server.yaml 144 145 /bin/bash ./tool/start.sh 146 echo -e "install polaris server finish." 147 cd ${install_path} || ( 148 echo "no such directory ${install_path}" 149 exit -1 150 ) 151 } 152 153 function installPolarisConsole() { 154 echo -e "install polaris console ... " 155 local polaris_console_num=$(ps -ef | grep polaris-console | grep -v grep | wc -l) 156 if [ $polaris_console_num -ge 1 ]; then 157 echo -e "polaris-console is running, skip." 158 return 159 fi 160 161 local polaris_console_tarnum=$(find . -name "polaris-console-release*.zip" | wc -l) 162 if [ $polaris_console_tarnum != 1 ]; then 163 echo -e "number of polaris console tar not equal 1, exit." 164 exit -1 165 fi 166 167 local polaris_console_tarname=$(find . -name "polaris-console-release*.zip") 168 local polaris_console_dirname=$(basename ${polaris_console_tarname} .zip) 169 if [ ! -e $polaris_console_dirname ]; then 170 unzip $polaris_console_tarname >/dev/null 171 else 172 echo -e "polaris-console-release.tar.gz has been decompressed, skip." 173 fi 174 175 cd ${polaris_console_dirname} || ( 176 echo "no such directory ${polaris_console_dirname}" 177 exit -1 178 ) 179 180 # 备份 polaris-console.yaml 181 cp polaris-console.yaml polaris-console.yaml.bak 182 183 # 修改 polaris-console 端口信息 184 sed -i "" "s/listenPort: 8080/listenPort: ${console_port}/g" polaris-console.yaml 185 # 修改监听的 polaris-server 端口信息 186 sed -i "" "s/address: \"127.0.0.1:8090\"/address: \"127.0.0.1:${api_http_port}\"/g" polaris-console.yaml 187 # 修改监听的 prometheus 端口信息 188 sed -i "" "s/address: \"127.0.0.1:9090\"/address: \"127.0.0.1:${prometheus_port}\"/g" polaris-console.yaml 189 190 /bin/bash ./tool/start.sh 191 echo -e "install polaris console finish." 192 cd ${install_path} || ( 193 echo "no such directory ${install_path}" 194 exit -1 195 ) 196 } 197 198 function installPrometheus() { 199 echo -e "install prometheus ... " 200 local prometheus_num=$(ps -ef | grep prometheus | grep -v grep | wc -l) 201 if [ ${prometheus_num} -ge 1 ]; then 202 echo -e "prometheus is running, skip" 203 return 204 fi 205 206 local prometheus_pkg_num=$(find . -name "prometheus-*.tar.gz" | wc -l) 207 if [ ${prometheus_pkg_num} != 1 ]; then 208 echo -e "number of prometheus package not equals to 1, exit" 209 exit -1 210 fi 211 212 local target_prometheus_pkg=$(find . -name "prometheus-*.tar.gz") 213 local prometheus_dirname=$(basename ${target_prometheus_pkg} .tar.gz) 214 if [ -e ${prometheus_dirname} ]; then 215 echo -e "${prometheus_dirname} has been decompressed, skip." 216 else 217 tar -xf ${target_prometheus_pkg} >/dev/null 218 fi 219 220 cp prometheus-help.sh ${prometheus_dirname}/ 221 pushd ${prometheus_dirname} 222 local push_count=$(cat prometheus.yml | grep "push-metrics" | wc -l) 223 if [ $push_count -eq 0 ]; then 224 echo " http_sd_configs:" >>prometheus.yml 225 echo " - url: http://localhost:8090/prometheus/v1/clients" >>prometheus.yml 226 echo "" >>prometheus.yml 227 echo " - job_name: 'push-metrics'" >>prometheus.yml 228 echo " static_configs:" >>prometheus.yml 229 echo " - targets: ['localhost:9091']" >>prometheus.yml 230 echo " honor_labels: true" >>prometheus.yml 231 fi 232 if [ ! -e polaris-prometheus ]; then 233 mv prometheus polaris-prometheus 234 fi 235 chmod +x polaris-prometheus 236 # nohup ./polaris-prometheus --web.enable-lifecycle --web.enable-admin-api --web.listen-address=:${prometheus_port} >>prometheus.out 2>&1 & 237 bash prometheus-help.sh start ${prometheus_port} 238 echo "install polaris-prometheus success" 239 popd 240 } 241 242 function installPushGateway() { 243 echo -e "install pushgateway ... " 244 local pgw_num=$(ps -ef | grep polaris-pushgateway | grep -v grep | wc -l) 245 if [ $pgw_num -ge 1 ]; then 246 echo -e "polaris-pushgateway is running, exit" 247 return -1 248 fi 249 250 local pgw_pkg_num=$(find . -name "pushgateway-*.tar.gz" | wc -l) 251 if [ $pgw_pkg_num != 1 ]; then 252 echo -e "number of pushgateway package not equals to 1, exit" 253 exit -1 254 fi 255 256 local target_pgw_pkg=$(find . -name "pushgateway-*.tar.gz") 257 local pgw_dirname=$(basename ${target_pgw_pkg} .tar.gz) 258 if [ ! -e ${pgw_dirname} ]; then 259 tar -xf ${target_pgw_pkg} >/dev/null 260 else 261 echo -e "pushgateway has been decompressed, skip." 262 fi 263 264 pushd ${pgw_dirname} 265 if [ ! -e polaris-pushgateway ]; then 266 mv pushgateway polaris-pushgateway 267 fi 268 269 chmod +x polaris-pushgateway 270 nohup ./polaris-pushgateway --web.enable-lifecycle --web.enable-admin-api --web.listen-address=:${pushgateway_port} >>pgw.out 2>&1 & 271 echo "install polaris-pushgateway success" 272 popd 273 } 274 275 # 安装北极星分布式限流服务端 276 function installPolarisLimiter() { 277 echo -e "install polaris limiter ... " 278 local polaris_limiter_num=$(ps -ef | grep polaris-limiter | grep -v grep | wc -l) 279 if [ $polaris_limiter_num -ge 1 ]; then 280 echo -e "polaris-limiter is running, skip." 281 return 282 fi 283 284 local polaris_limiter_tarnum=$(find . -name "polaris-limiter-release*.zip" | wc -l) 285 if [ $polaris_limiter_tarnum != 1 ]; then 286 echo -e "number of polaris limiter tar not equal 1, exit." 287 exit -1 288 fi 289 290 local polaris_limiter_tarname=$(find . -name "polaris-limiter-release*.zip") 291 local polaris_limiter_dirname=$(basename ${polaris_limiter_tarname} .zip) 292 if [ ! -e $polaris_limiter_dirname ]; then 293 unzip $polaris_limiter_tarname >/dev/null 294 else 295 echo -e "polaris-limiter-release.tar.gz has been decompressed, skip." 296 fi 297 298 cd ${polaris_limiter_dirname} || ( 299 echo "no such directory ${polaris_limiter_dirname}" 300 exit -1 301 ) 302 303 # 备份 polaris-limiter.yaml 304 cp polaris-limiter.yaml polaris-limiter.yaml.bak 305 306 # 修改 polaris-server grpc 端口信息 307 sed -i "" "s/polaris-server-address: 127.0.0.1:8091/polaris-server-address: 127.0.0.1:${service_grpc_port}/g" polaris-limiter.yaml 308 # 修改监听的 polaris-limiter http 端口信息 309 sed -i "" "s/port: 8100/port: ${limiter_http_port}/g" polaris-limiter.yaml 310 # 修改监听的 polaris-limiter grpc 端口信息 311 sed -i "" "s/port: 8101/port: ${limiter_grpc_port}/g" polaris-limiter.yaml 312 313 /bin/bash ./tool/start.sh 314 echo -e "install polaris limiter finish." 315 cd ${install_path} || ( 316 echo "no such directory ${install_path}" 317 exit -1 318 ) 319 } 320 321 function checkPort() { 322 proFilePath="./port.properties" 323 if [ ! -f ${proFilePath} ]; then 324 echo "file ${proFilePath} not exist" 325 echo "" >&2 326 exit 1 327 fi 328 keyLength=$(echo ${key} | awk '{print length($0)}') 329 lineNumStr=$(cat ${proFilePath} | wc -l) 330 lineNum=$((${lineNumStr})) 331 for ((i = 1; i <= ${lineNum}; i++)); do 332 oneLine=$(sed -n ${i}p ${proFilePath}) 333 port=${oneLine#*=} 334 if [ "WJA${port}" == "WJA" ]; then 335 continue 336 fi 337 pid=$(lsof -i :${port} | grep LISTEN | awk '{print $1 " " $2}') 338 if [ "${pid}" != "" ]; then 339 echo "port ${port} already used, you can modify port.properties to adjust port" 340 exit -1 341 fi 342 done 343 } 344 345 # 检查端口占用 346 checkPort 347 # 安装server 348 installPolarisServer 349 # 安装console 350 installPolarisConsole 351 # 安装 polaris-limiter 352 installPolarisLimiter 353 # 安装Prometheus 354 installPrometheus 355 # 安装Pushgateway 356 installPushGateway 357 358 echo "now, we finish install polaris in your mac, we will exec rollback 'sudo spctl --master-enable'" 359 360 sudo spctl --master-enable