From 57ac8864d21faf68de1e6910deec9cd730a87e6c Mon Sep 17 00:00:00 2001 From: shizhendong Date: Thu, 2 Mar 2023 09:51:15 +0800 Subject: feat: NEZ-2590 NZ-Talon 支持一键部署 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tools/install-agent.sh.template | 176 ++++++++++++++++++++++++++++++++++++++++ tools/install-talon.sh.template | 175 +++++++++++++++++++++++++++++++++++++++ tools/install.sh.template | 176 ---------------------------------------- tools/package.sh | 3 +- 4 files changed, 353 insertions(+), 177 deletions(-) create mode 100644 tools/install-agent.sh.template create mode 100644 tools/install-talon.sh.template delete mode 100644 tools/install.sh.template diff --git a/tools/install-agent.sh.template b/tools/install-agent.sh.template new file mode 100644 index 0000000..46ad1f0 --- /dev/null +++ b/tools/install-agent.sh.template @@ -0,0 +1,176 @@ +#!/bin/bash +{ # this ensures the entire script is downloaded # +# Find Java +if [[ -n "$JAVA_HOME" ]] && [[ -x "$JAVA_HOME/bin/java" ]]; then + JAVA_EXE="$JAVA_HOME/bin/java" +elif type -p java > /dev/null 2>&1; then + JAVA_EXE=$(type -p java) +elif [[ -x "/usr/bin/java" ]]; then + JAVA_EXE="/usr/bin/java" +else + echo -e "\e[1;31mUnable to find Java\e[0m" + exit 1 +fi + +echo "java: $JAVA_EXE" + +#auto replace parameter start + +WEB_TOKEN=${webToken} + +DATACENTER_ID=${datacenterID} + +TYPE=${type} + +REMOTE_IP=${remoteIP} + +REMOTE_PORT=${remotePort} + +SSL_ENABLED=${sslEnabled} + +if [ ! -z "$REMOTE_PORT" ];then + REMOTE_IP=$REMOTE_IP:$REMOTE_PORT +fi + +LOCALHOST=${localhost} +#auto replace parameter end +ROOT_PATH=/opt/nezha + +AGENT_TOKEN=$(cut -d '-' -f 1 /proc/sys/kernel/random/uuid) + +INSTALL_PATH=$ROOT_PATH/nz-agent + +WORK_PATH=/tmp/.nezha/nz-agent + +rm -rf $WORK_PATH&&mkdir -p $WORK_PATH + +function osInfo() { + if [ -e /etc/centos-release ];then + echo 'centos' + elif [ -e /etc/debian_version ]; then + echo 'debian' + elif [ -e /etc/lsb_release ]; then + echo 'ubuntu' + else + echo 'centos'; + fi +} +CURRENT_OS=$(osInfo) +function log() { + case $1 in + "red") + echo -e "\e[1;31m$2\e[0m" + ;; + "yellow") + echo -e "\e[1;33m$2\e[0m" + ;; + "green") + echo -e "\e[1;32m$2\e[0m" + ;; + *) + echo $2 + ;; + esac +} + +function isInstall() { + case $CURRENT_OS in + 'centos') + if [ $(rpm -aq |grep nz-agent|wc -l) -lt 1 ];then + echo 0 + else + echo 1; + fi + ;; + esac +} + +function getPackageName() { + case $CURRENT_OS in + 'centos') + echo "nz-agent.rpm" + ;; + esac +} +PACKAGE_NAME=$(getPackageName $CURRENT_OS) + +function downloadPackaget() { + cd $WORK_PATH; + log yellow "current os is $CURRENT_OS ,download package from http://$REMOTE_IP/agent/download?os=$CURRENT_OS" + if command -v wget >/dev/null 2>&1;then + if $SSL_ENABLED ;then + wget -O $PACKAGE_NAME --no-check-certificate --header="Authorization:"$WEB_TOKEN "https://$REMOTE_IP/agent/download?os="$CURRENT_OS + else + wget -O $PACKAGE_NAME --header="Authorization:"$WEB_TOKEN "http://$REMOTE_IP/agent/download?os="$CURRENT_OS + fi + return 0 + elif command -v curl >/dev/null 2>&1;then + if $SSL_ENABLED ;then + curl -o $PACKAGE_NAME -k -H "Authorization:"$WEB_TOKEN "https://$REMOTE_IP/agent/download?os="$CURRENT_OS + else + curl -o $PACKAGE_NAME -H "Authorization:"$WEB_TOKEN "http://$REMOTE_IP/agent/download?os="$CURRENT_OS + fi + return 0 + else + log red "The wget/curl command is required" + exit 1 + fi +} + +function installPackage() { + case $CURRENT_OS in + 'centos') + log yellow 'install package right now...' + rpm -ivh $WORK_PATH/$PACKAGE_NAME && mkdir -p $INSTALL_PATH/config; echo -n $AGENT_TOKEN > $INSTALL_PATH/config/token.auth + ;; + esac + +AGENT_NAME=$(hostname) + +if [ $AGENT_NAME == 'localhost.localdomain' ];then + AGENT_NAME=$(cut -d '-' -f 1 /proc/sys/kernel/random/uuid) +fi + + if [ 0 -eq $? ];then + cat > $WORK_PATH/param.tmp < /dev/null 2>&1; then + JAVA_EXE=$(type -p java) +elif [[ -x "/usr/bin/java" ]]; then + JAVA_EXE="/usr/bin/java" +else + echo -e "\e[1;31mUnable to find Java\e[0m" + exit 1 +fi + +echo "java: $JAVA_EXE" + + +#auto replace parameter start +WEB_TOKEN=${webToken} + +REMOTE_IP=${remoteIP} + +REMOTE_PORT=${remotePort} + +SSL_ENABLED=${sslEnabled} + +ASSET_ID=${assetId} + +if [ ! -z "$REMOTE_PORT" ];then + REMOTE_IP=$REMOTE_IP:$REMOTE_PORT +fi + +LOCALHOST=${localhost} +#auto replace parameter end + + +# random token +TALON_TOKEN=$(cut -d '-' -f 1 /proc/sys/kernel/random/uuid) + +# path var +ROOT_PATH=/opt/nezha + +INSTALL_PATH=$ROOT_PATH/nz-talon + +# reset work tmp dir +WORK_PATH=/tmp/.nezha/nz-talon +rm -rf $WORK_PATH&&mkdir -p $WORK_PATH + + +function osInfo() { + if [ -e /etc/centos-release ];then + echo 'centos' + elif [ -e /etc/debian_version ]; then + echo 'debian' + elif [ -e /etc/lsb_release ]; then + echo 'ubuntu' + else + echo 'centos'; + fi +} + +CURRENT_OS=$(osInfo) + +function log() { + case $1 in + "red") + echo -e "\e[1;31m$2\e[0m" + ;; + "yellow") + echo -e "\e[1;33m$2\e[0m" + ;; + "green") + echo -e "\e[1;32m$2\e[0m" + ;; + *) + echo $2 + ;; + esac +} + +# rpm -aq | grep nz-talon +function isInstall() { + case $CURRENT_OS in + 'centos') + if [ $(rpm -aq | grep nz-talon | wc -l) -lt 1 ];then + echo 0 + else + echo 1; + fi + ;; + esac +} + +function getPackageName() { + case $CURRENT_OS in + 'centos') + echo "nz-talon.rpm" + ;; + esac +} +PACKAGE_NAME=$(getPackageName $CURRENT_OS) + +function downloadPackaget() { + cd $WORK_PATH; + log yellow "current os is $CURRENT_OS ,download package from http://$REMOTE_IP/asset/talon/download?os=$CURRENT_OS" + if command -v wget >/dev/null 2>&1;then + if $SSL_ENABLED ;then + wget -O $PACKAGE_NAME --no-check-certificate --header="Authorization:"$WEB_TOKEN "https://$REMOTE_IP/asset/talon/download?os="$CURRENT_OS + else + wget -O $PACKAGE_NAME --header="Authorization:"$WEB_TOKEN "http://$REMOTE_IP/asset/talon/download?os="$CURRENT_OS + fi + return 0 + elif command -v curl >/dev/null 2>&1;then + if $SSL_ENABLED ;then + curl -o $PACKAGE_NAME -k -H "Authorization:"$WEB_TOKEN "https://$REMOTE_IP/asset/talon/download?os="$CURRENT_OS + else + curl -o $PACKAGE_NAME -H "Authorization:"$WEB_TOKEN "http://$REMOTE_IP/asset/talon/download?os="$CURRENT_OS + fi + return 0 + else + log red "The wget/curl command is required" + exit 1 + fi +} + +function installPackage() { + case $CURRENT_OS in + 'centos') + log yellow 'install package right now...' + rpm -ivh $WORK_PATH/$PACKAGE_NAME && mkdir -p $INSTALL_PATH/config; echo -n $TALON_TOKEN > $INSTALL_PATH/config/token.auth + ;; + esac + + if [ 0 -eq $? ];then + cat > $WORK_PATH/param.tmp < /dev/null 2>&1; then - JAVA_EXE=$(type -p java) -elif [[ -x "/usr/bin/java" ]]; then - JAVA_EXE="/usr/bin/java" -else - echo -e "\e[1;31mUnable to find Java\e[0m" - exit 1 -fi - -echo "java: $JAVA_EXE" - -#auto replace parameter start - -WEB_TOKEN=${webToken} - -DATACENTER_ID=${datacenterID} - -TYPE=${type} - -REMOTE_IP=${remoteIP} - -REMOTE_PORT=${remotePort} - -SSL_ENABLED=${sslEnabled} - -if [ ! -z "$REMOTE_PORT" ];then - REMOTE_IP=$REMOTE_IP:$REMOTE_PORT -fi - -LOCALHOST=${localhost} -#auto replace parameter end -ROOT_PATH=/opt/nezha - -AGENT_TOKEN=$(cut -d '-' -f 1 /proc/sys/kernel/random/uuid) - -INSTALL_PATH=$ROOT_PATH/nz-agent - -WORK_PATH=/tmp/.nezha/nz-agent - -rm -rf $WORK_PATH&&mkdir -p $WORK_PATH - -function osInfo() { - if [ -e /etc/centos-release ];then - echo 'centos' - elif [ -e /etc/debian_version ]; then - echo 'debian' - elif [ -e /etc/lsb_release ]; then - echo 'ubuntu' - else - echo 'centos'; - fi -} -CURRENT_OS=$(osInfo) -function log() { - case $1 in - "red") - echo -e "\e[1;31m$2\e[0m" - ;; - "yellow") - echo -e "\e[1;33m$2\e[0m" - ;; - "green") - echo -e "\e[1;32m$2\e[0m" - ;; - *) - echo $2 - ;; - esac -} - -function isInstall() { - case $CURRENT_OS in - 'centos') - if [ $(rpm -aq |grep nz-agent|wc -l) -lt 1 ];then - echo 0 - else - echo 1; - fi - ;; - esac -} - -function getPackageName() { - case $CURRENT_OS in - 'centos') - echo "nz-agent.rpm" - ;; - esac -} -PACKAGE_NAME=$(getPackageName $CURRENT_OS) - -function downloadPackaget() { - cd $WORK_PATH; - log yellow "current os is $CURRENT_OS ,download package from http://$REMOTE_IP/agent/download?os=$CURRENT_OS" - if command -v wget >/dev/null 2>&1;then - if $SSL_ENABLED ;then - wget -O $PACKAGE_NAME --no-check-certificate --header="Authorization:"$WEB_TOKEN "https://$REMOTE_IP/agent/download?os="$CURRENT_OS - else - wget -O $PACKAGE_NAME --header="Authorization:"$WEB_TOKEN "http://$REMOTE_IP/agent/download?os="$CURRENT_OS - fi - return 0 - elif command -v curl >/dev/null 2>&1;then - if $SSL_ENABLED ;then - curl -o $PACKAGE_NAME -k -H "Authorization:"$WEB_TOKEN "https://$REMOTE_IP/agent/download?os="$CURRENT_OS - else - curl -o $PACKAGE_NAME -H "Authorization:"$WEB_TOKEN "http://$REMOTE_IP/agent/download?os="$CURRENT_OS - fi - return 0 - else - log red "The wget/curl command is required" - exit 1 - fi -} - -function installPackage() { - case $CURRENT_OS in - 'centos') - log yellow 'install package right now...' - rpm -ivh $WORK_PATH/$PACKAGE_NAME && mkdir -p $INSTALL_PATH/config; echo -n $AGENT_TOKEN > $INSTALL_PATH/config/token.auth - ;; - esac - -AGENT_NAME=$(hostname) - -if [ $AGENT_NAME == 'localhost.localdomain' ];then - AGENT_NAME=$(cut -d '-' -f 1 /proc/sys/kernel/random/uuid) -fi - - if [ 0 -eq $? ];then - cat > $WORK_PATH/param.tmp < Date: Wed, 22 Mar 2023 12:24:50 +0800 Subject: build: rel-23.01.05 --- tools/package.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/package.sh b/tools/package.sh index ccfafb1..0efdae1 100644 --- a/tools/package.sh +++ b/tools/package.sh @@ -16,9 +16,9 @@ RPM_FULL_NAME=${PACKAGE_NAME}-${PACKAGE_VERSION}-${ITERATION}.x86_64.rpm mc alias set nz $MINIO_HOST $MINIO_USER $MINIO_PWD #各个依赖包版本 -NZ_WEB_PKG="release/nz-web/nz-web-rel-23.01.03-49bf97e6.tar.gz" -NZ_AGENT_PKG="release/nz-agent/nz-agent-23.01.01.3d05967e-Release.x86_64.rpm" -NZ_GUI_PKG="release/nz-gui/nz-gui-20ac0ef0.zip" +NZ_WEB_PKG="release/nz-web/nz-web-rel-23.01.05-d6ccff5d.tar.gz" +NZ_AGENT_PKG="release/nz-agent/nz-agent-23.01.02.42046f1c-Release.x86_64.rpm" +NZ_GUI_PKG="release/nz-gui/nz-gui-babd0e4d.zip" NZ_TALON_PKG="release/nz-talon/nz-talon-23.01.01.de3347b3-Release.x86_64.rpm" # 依赖jdk 文件名 -- cgit v1.2.3 From 024f3dc047a218a90274f6a4d994cd3b0e8bbb8a Mon Sep 17 00:00:00 2001 From: shizhendong Date: Fri, 31 Mar 2023 14:57:53 +0800 Subject: chore: NEZ-2699 snmp_exporter.generator 依赖组件版本更新 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. upgrade generator component 0.20.0 to version 0.21.0 --- tools/package.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/package.sh b/tools/package.sh index 0efdae1..6c168f5 100644 --- a/tools/package.sh +++ b/tools/package.sh @@ -28,7 +28,7 @@ mc cp nz/$NZ_WEB_PKG ./ mc cp nz/$NZ_AGENT_PKG ./ mc cp nz/$NZ_GUI_PKG ./ mc cp nz/$NZ_TALON_PKG ./ -mc cp nz/depends/exporter/generator.zip ./ +mc cp nz/depends/exporter/generator-0.21.0.linux-amd64.zip ./ mc cp nz/depends/prometheus/promtool ./ mc cp nz/depends/map/Tiles.zip ./ mc cp nz/depends/jdk/$JDK_FILENAME ./ @@ -63,7 +63,7 @@ cp ./tools/lib*.so $RPM_NZ_PATH/lib # 移动依赖工具 mv promtool $RPM_NZ_PATH/promtool/ -unzip -o generator.zip -d $RPM_NZ_PATH/generator/ +unzip -o generator-0.21.0.linux-amd64.zip -d $RPM_NZ_PATH/generator/ # 配置文件 cp ./tools/nezha.properties $RPM_NZ_PATH/config -- cgit v1.2.3