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