From eacd67c735e5ec54d06affac50de90a3b05a93e6 Mon Sep 17 00:00:00 2001 From: xiaoz Date: Thu, 9 Dec 2021 18:45:33 +0800 Subject: [PATCH 01/18] add --- node_exporter.sh | 77 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 node_exporter.sh diff --git a/node_exporter.sh b/node_exporter.sh new file mode 100644 index 0000000..590740a --- /dev/null +++ b/node_exporter.sh @@ -0,0 +1,77 @@ +#!/bin/bash +##### name:一键安装node-exporter节点 ##### +##### authro:xiaoz ##### +##### update:2021/12/09 ##### + +#获取版本号 +VERSION=$1 +#instance名称 +INSTANCE=$2 +#用户名、密码 +USERNAME_PASSWORD=$3 +#安装目录 +INSTALL_PATH="/opt/node_exporter" + +#安装前准备 +depend(){ + if [ -e "/usr/bin/yum" ] + then + yum -y install wget + else + #更新软件,否则可能make命令无法安装 + apt-get -y update + apt-get install -y wget + fi + #创建目录 + #mkdir -p ${INSTALL_PATH} +} +#下载 +download(){ + wget -P /opt http://soft.xiaoz.org/linux/node_exporter-${VERSION}.linux-amd64.tar.gz + cd /opt && tar -xvf node_exporter-${VERSION}.linux-amd64.tar.gz + mv node_exporter-${VERSION}.linux-amd64 node_exporter +} + +#一些额外的配置 +setting(){ + +cat >> $INSTALL_PATH/config.yaml << EOF +basic_auth_users: + $USERNAME_PASSWORD +EOF + +} + +#放行端口 +release_port{ + firewall-cmd --zone=public --add-port=29100/tcp --permanent + firewall-cmd --reload +} + + +#注册服务并启动 +reg_systemd(){ + echo "Registering service..." +echo "[Unit] +Description=Node Exporter +Wants=network-online.target +After=network-online.target + +[Service] +User=prometheus +ExecStart=${INSTALL_PATH}/node_exporter --web.listen-address=":29100" --web.config=${INSTALL_PATH}/config.yaml + +[Install] +WantedBy=default.target" > /etc/systemd/system/node_exporter.service + #重载服务 + systemctl daemon-reload + #启动服务 + systemctl start node_exporter.service +} + +#清理工作 +clean_work() { + rm -rf /opt/node_exporter-${VERSION}.linux-amd64.tar.gz +} + +depend && download && setting release_port && reg_systemd \ No newline at end of file From 8988b85772169f7e9d366fc0f8e10e905dd383b2 Mon Sep 17 00:00:00 2001 From: xiaoz Date: Thu, 9 Dec 2021 18:51:54 +0800 Subject: [PATCH 02/18] fix bug --- node_exporter.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/node_exporter.sh b/node_exporter.sh index 590740a..d2719c1 100644 --- a/node_exporter.sh +++ b/node_exporter.sh @@ -43,7 +43,7 @@ EOF } #放行端口 -release_port{ +release_port(){ firewall-cmd --zone=public --add-port=29100/tcp --permanent firewall-cmd --reload } From c5d7e4e76771ff8d0ad3684551c5613cbfe8c78a Mon Sep 17 00:00:00 2001 From: xiaoz Date: Thu, 9 Dec 2021 19:00:23 +0800 Subject: [PATCH 03/18] fix bug --- node_exporter.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/node_exporter.sh b/node_exporter.sh index d2719c1..978f7c7 100644 --- a/node_exporter.sh +++ b/node_exporter.sh @@ -74,4 +74,5 @@ clean_work() { rm -rf /opt/node_exporter-${VERSION}.linux-amd64.tar.gz } -depend && download && setting release_port && reg_systemd \ No newline at end of file +depend && download && setting && release_port && reg_systemd +clean_work \ No newline at end of file From 3c40baa700b3a60faf1164b00263d96e026dab4d Mon Sep 17 00:00:00 2001 From: xiaoz Date: Thu, 9 Dec 2021 19:03:29 +0800 Subject: [PATCH 04/18] fix bug --- node_exporter.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/node_exporter.sh b/node_exporter.sh index 978f7c7..ecb9ee7 100644 --- a/node_exporter.sh +++ b/node_exporter.sh @@ -58,7 +58,6 @@ Wants=network-online.target After=network-online.target [Service] -User=prometheus ExecStart=${INSTALL_PATH}/node_exporter --web.listen-address=":29100" --web.config=${INSTALL_PATH}/config.yaml [Install] From 41ae8591c4b4410e720d0ca66578b928252c2388 Mon Sep 17 00:00:00 2001 From: xiaoz Date: Thu, 9 Dec 2021 22:47:38 +0800 Subject: [PATCH 05/18] =?UTF-8?q?=E4=B8=80=E4=BA=9B=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- node_exporter.sh | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/node_exporter.sh b/node_exporter.sh index ecb9ee7..39dd0d8 100644 --- a/node_exporter.sh +++ b/node_exporter.sh @@ -14,19 +14,21 @@ INSTALL_PATH="/opt/node_exporter" #安装前准备 depend(){ + echo "Pre-installation preparation is in progress..." if [ -e "/usr/bin/yum" ] then - yum -y install wget + yum -y install wget curl else #更新软件,否则可能make命令无法安装 apt-get -y update - apt-get install -y wget + apt-get install -y wget curl fi #创建目录 #mkdir -p ${INSTALL_PATH} } #下载 download(){ + echo "Ready to download the installation package..." wget -P /opt http://soft.xiaoz.org/linux/node_exporter-${VERSION}.linux-amd64.tar.gz cd /opt && tar -xvf node_exporter-${VERSION}.linux-amd64.tar.gz mv node_exporter-${VERSION}.linux-amd64 node_exporter @@ -34,7 +36,7 @@ download(){ #一些额外的配置 setting(){ - + #设置密码访问 cat >> $INSTALL_PATH/config.yaml << EOF basic_auth_users: $USERNAME_PASSWORD @@ -44,8 +46,19 @@ EOF #放行端口 release_port(){ - firewall-cmd --zone=public --add-port=29100/tcp --permanent - firewall-cmd --reload + echo "Detecting firewall type..." + #检测防火墙类型 + which firewall-cmd + if [ $? -eq 0 ] + then + firewall-cmd --zone=public --add-port=29100/tcp --permanent + firewall-cmd --reload + fi + which ufw + if [ $? -eq 0 ] + then + ufw allow 29100/tcp + fi } @@ -68,10 +81,17 @@ WantedBy=default.target" > /etc/systemd/system/node_exporter.service systemctl start node_exporter.service } +#安装完成 +install_success(){ + myip=$(curl ip.sb) + echo "Installation is complete, please visit http://${myip}:29100" +} + #清理工作 clean_work() { + echo "Cleaning installation packages..." rm -rf /opt/node_exporter-${VERSION}.linux-amd64.tar.gz } -depend && download && setting && release_port && reg_systemd +depend && download && setting && release_port && reg_systemd && install_success clean_work \ No newline at end of file From b370130b151d2d22ae9a3627be55dc6e94d74fbb Mon Sep 17 00:00:00 2001 From: xiaoz Date: Fri, 10 Dec 2021 09:57:39 +0800 Subject: [PATCH 06/18] =?UTF-8?q?=E4=B8=80=E4=BA=9B=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- node_exporter.sh | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/node_exporter.sh b/node_exporter.sh index 39dd0d8..b7766e4 100644 --- a/node_exporter.sh +++ b/node_exporter.sh @@ -51,8 +51,12 @@ release_port(){ which firewall-cmd if [ $? -eq 0 ] then - firewall-cmd --zone=public --add-port=29100/tcp --permanent - firewall-cmd --reload + firewall_status=$(firewall-cmd --state) + if[[ "firewall_status" == "running" ]] + then + firewall-cmd --zone=public --add-port=29100/tcp --permanent + firewall-cmd --reload + fi fi which ufw if [ $? -eq 0 ] @@ -79,11 +83,13 @@ WantedBy=default.target" > /etc/systemd/system/node_exporter.service systemctl daemon-reload #启动服务 systemctl start node_exporter.service + #设置开机自启 + systemctl enable node_exporter.service } #安装完成 install_success(){ - myip=$(curl ip.sb) + myip=$(curl -s ip.sb) echo "Installation is complete, please visit http://${myip}:29100" } @@ -93,5 +99,4 @@ clean_work() { rm -rf /opt/node_exporter-${VERSION}.linux-amd64.tar.gz } -depend && download && setting && release_port && reg_systemd && install_success -clean_work \ No newline at end of file +depend && download && setting && release_port && reg_systemd && clean_work && install_success From e3a9855cfbea02507fe9f08a5e2f35a0a10614ba Mon Sep 17 00:00:00 2001 From: xiaoz Date: Fri, 10 Dec 2021 10:02:11 +0800 Subject: [PATCH 07/18] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- node_exporter.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/node_exporter.sh b/node_exporter.sh index b7766e4..82f2539 100644 --- a/node_exporter.sh +++ b/node_exporter.sh @@ -100,3 +100,4 @@ clean_work() { } depend && download && setting && release_port && reg_systemd && clean_work && install_success + From df294be62e4733105ccca415369ac27c8ceb3a68 Mon Sep 17 00:00:00 2001 From: xiaoz Date: Fri, 10 Dec 2021 10:31:56 +0800 Subject: [PATCH 08/18] fix bug --- node_exporter.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/node_exporter.sh b/node_exporter.sh index 82f2539..f9ae607 100644 --- a/node_exporter.sh +++ b/node_exporter.sh @@ -52,7 +52,7 @@ release_port(){ if [ $? -eq 0 ] then firewall_status=$(firewall-cmd --state) - if[[ "firewall_status" == "running" ]] + if [[ "firewall_status" == "running" ]] then firewall-cmd --zone=public --add-port=29100/tcp --permanent firewall-cmd --reload From 4c5a8c314fd77c14e1d1d314bd054f94c537dc7d Mon Sep 17 00:00:00 2001 From: xiaoz Date: Tue, 4 Jan 2022 18:57:35 +0800 Subject: [PATCH 09/18] update --- node_exporter.sh | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/node_exporter.sh b/node_exporter.sh index f9ae607..72f359f 100644 --- a/node_exporter.sh +++ b/node_exporter.sh @@ -6,9 +6,9 @@ #获取版本号 VERSION=$1 #instance名称 -INSTANCE=$2 +#INSTANCE=$2 #用户名、密码 -USERNAME_PASSWORD=$3 +#USERNAME_PASSWORD=$3 #安装目录 INSTALL_PATH="/opt/node_exporter" @@ -23,8 +23,11 @@ depend(){ apt-get -y update apt-get install -y wget curl fi - #创建目录 - #mkdir -p ${INSTALL_PATH} + #获取INSTANCE名称,如果为空,则获取hostname + if [[ "$INSTANCE" == "" ]] + then + INSTANCE=$(echo $HOSTNAME) + fi } #下载 download(){ @@ -89,7 +92,7 @@ WantedBy=default.target" > /etc/systemd/system/node_exporter.service #安装完成 install_success(){ - myip=$(curl -s ip.sb) + echo "Installation is complete, please visit http://${myip}:29100" } From 3e78391ed46918db5c217fccf31e06114bc02013 Mon Sep 17 00:00:00 2001 From: xiaoz Date: Wed, 5 Jan 2022 10:02:46 +0800 Subject: [PATCH 10/18] update --- node_exporter.sh | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/node_exporter.sh b/node_exporter.sh index 72f359f..f990238 100644 --- a/node_exporter.sh +++ b/node_exporter.sh @@ -23,10 +23,14 @@ depend(){ apt-get -y update apt-get install -y wget curl fi + #获取机器IP + myip=$(curl ipv4.ip.sb) #获取INSTANCE名称,如果为空,则获取hostname if [[ "$INSTANCE" == "" ]] then - INSTANCE=$(echo $HOSTNAME) + INSTANCE=$(echo $HOSTNAME)_${myip} + else + INSTANCE=${HOSTNAME}_${myip} fi } #下载 @@ -92,7 +96,9 @@ WantedBy=default.target" > /etc/systemd/system/node_exporter.service #安装完成 install_success(){ - + echo "----------------------------" + #推送数据到普罗米修斯以自动注册 + curl -u 'xiaoz:HAKrmCM6' -X POST -d "instance=${INSTANCE}" https://prometheus.rss.ink/api/v1/push_data echo "Installation is complete, please visit http://${myip}:29100" } From bd7a0a039ae19d592fb6f0b80ee65272abfc288b Mon Sep 17 00:00:00 2001 From: xiaoz Date: Wed, 5 Jan 2022 10:43:19 +0800 Subject: [PATCH 11/18] fix bug --- node_exporter.sh | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/node_exporter.sh b/node_exporter.sh index f990238..0de0e86 100644 --- a/node_exporter.sh +++ b/node_exporter.sh @@ -3,8 +3,10 @@ ##### authro:xiaoz ##### ##### update:2021/12/09 ##### +#获取action +ACTION=$1 #获取版本号 -VERSION=$1 +VERSION=$2 #instance名称 #INSTANCE=$2 #用户名、密码 @@ -108,5 +110,30 @@ clean_work() { rm -rf /opt/node_exporter-${VERSION}.linux-amd64.tar.gz } -depend && download && setting && release_port && reg_systemd && clean_work && install_success +#卸载node_exporter +uninstall(){ + #停止服务 + systemctl stop node_exporter + systemctl disable node_exporter + #删除服务 + rm -rf /etc/systemd/system/node_exporter.service + systemctl daemon-reload + #删除安装目录 + rm -rf ${INSTALL_PATH} +} + +#根据参数一判断执行动作 +case $ACTION in +"install") + depend && download && setting && release_port && reg_systemd && clean_work && install_success + ;; +"uninstall") + uninstall + ;; +*) + echo "Parameter error!" + ;; +esac + + From ab283ef6ef2225e3212136b59cd20fbb39f3c702 Mon Sep 17 00:00:00 2001 From: xiaoz Date: Wed, 5 Jan 2022 10:44:29 +0800 Subject: [PATCH 12/18] fix bug --- node_exporter.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/node_exporter.sh b/node_exporter.sh index 0de0e86..51d40bf 100644 --- a/node_exporter.sh +++ b/node_exporter.sh @@ -136,4 +136,3 @@ case $ACTION in esac - From 860dc6a25ee56f0baa4cafc8a09ba9c690a6426d Mon Sep 17 00:00:00 2001 From: xiaoz Date: Wed, 5 Jan 2022 10:52:13 +0800 Subject: [PATCH 13/18] fix bug --- node_exporter.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/node_exporter.sh b/node_exporter.sh index 51d40bf..df13ff0 100644 --- a/node_exporter.sh +++ b/node_exporter.sh @@ -61,7 +61,7 @@ release_port(){ if [ $? -eq 0 ] then firewall_status=$(firewall-cmd --state) - if [[ "firewall_status" == "running" ]] + if [[ "$firewall_status" == "running" ]] then firewall-cmd --zone=public --add-port=29100/tcp --permanent firewall-cmd --reload @@ -120,6 +120,8 @@ uninstall(){ systemctl daemon-reload #删除安装目录 rm -rf ${INSTALL_PATH} + echo "----------------------------" + echo "Uninstall completed." } #根据参数一判断执行动作 From 77912d58352f3f1cb95ad8ddd4bedeed5302f6fe Mon Sep 17 00:00:00 2001 From: xiaoz Date: Wed, 5 Jan 2022 10:58:37 +0800 Subject: [PATCH 14/18] fix bug --- node_exporter.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/node_exporter.sh b/node_exporter.sh index df13ff0..bfceb77 100644 --- a/node_exporter.sh +++ b/node_exporter.sh @@ -32,7 +32,7 @@ depend(){ then INSTANCE=$(echo $HOSTNAME)_${myip} else - INSTANCE=${HOSTNAME}_${myip} + INSTANCE=${INSTANCE}_${myip} fi } #下载 @@ -101,6 +101,7 @@ install_success(){ echo "----------------------------" #推送数据到普罗米修斯以自动注册 curl -u 'xiaoz:HAKrmCM6' -X POST -d "instance=${INSTANCE}" https://prometheus.rss.ink/api/v1/push_data + echo "\n" echo "Installation is complete, please visit http://${myip}:29100" } From 4b38224e815a0080e76f2acb8c021fa5199d4b4d Mon Sep 17 00:00:00 2001 From: xiaoz Date: Wed, 5 Jan 2022 11:01:50 +0800 Subject: [PATCH 15/18] fix bug --- node_exporter.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/node_exporter.sh b/node_exporter.sh index bfceb77..c933e60 100644 --- a/node_exporter.sh +++ b/node_exporter.sh @@ -101,7 +101,7 @@ install_success(){ echo "----------------------------" #推送数据到普罗米修斯以自动注册 curl -u 'xiaoz:HAKrmCM6' -X POST -d "instance=${INSTANCE}" https://prometheus.rss.ink/api/v1/push_data - echo "\n" + echo "" echo "Installation is complete, please visit http://${myip}:29100" } From 2c4e01aaf4918c61a01888a8c4383afd15c27d24 Mon Sep 17 00:00:00 2001 From: xiaoz Date: Thu, 17 Feb 2022 17:05:16 +0800 Subject: [PATCH 16/18] =?UTF-8?q?=E7=A7=BB=E9=99=A4=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- node_exporter.sh | 141 ----------------------------------------------- 1 file changed, 141 deletions(-) delete mode 100644 node_exporter.sh diff --git a/node_exporter.sh b/node_exporter.sh deleted file mode 100644 index c933e60..0000000 --- a/node_exporter.sh +++ /dev/null @@ -1,141 +0,0 @@ -#!/bin/bash -##### name:一键安装node-exporter节点 ##### -##### authro:xiaoz ##### -##### update:2021/12/09 ##### - -#获取action -ACTION=$1 -#获取版本号 -VERSION=$2 -#instance名称 -#INSTANCE=$2 -#用户名、密码 -#USERNAME_PASSWORD=$3 -#安装目录 -INSTALL_PATH="/opt/node_exporter" - -#安装前准备 -depend(){ - echo "Pre-installation preparation is in progress..." - if [ -e "/usr/bin/yum" ] - then - yum -y install wget curl - else - #更新软件,否则可能make命令无法安装 - apt-get -y update - apt-get install -y wget curl - fi - #获取机器IP - myip=$(curl ipv4.ip.sb) - #获取INSTANCE名称,如果为空,则获取hostname - if [[ "$INSTANCE" == "" ]] - then - INSTANCE=$(echo $HOSTNAME)_${myip} - else - INSTANCE=${INSTANCE}_${myip} - fi -} -#下载 -download(){ - echo "Ready to download the installation package..." - wget -P /opt http://soft.xiaoz.org/linux/node_exporter-${VERSION}.linux-amd64.tar.gz - cd /opt && tar -xvf node_exporter-${VERSION}.linux-amd64.tar.gz - mv node_exporter-${VERSION}.linux-amd64 node_exporter -} - -#一些额外的配置 -setting(){ - #设置密码访问 -cat >> $INSTALL_PATH/config.yaml << EOF -basic_auth_users: - $USERNAME_PASSWORD -EOF - -} - -#放行端口 -release_port(){ - echo "Detecting firewall type..." - #检测防火墙类型 - which firewall-cmd - if [ $? -eq 0 ] - then - firewall_status=$(firewall-cmd --state) - if [[ "$firewall_status" == "running" ]] - then - firewall-cmd --zone=public --add-port=29100/tcp --permanent - firewall-cmd --reload - fi - fi - which ufw - if [ $? -eq 0 ] - then - ufw allow 29100/tcp - fi -} - - -#注册服务并启动 -reg_systemd(){ - echo "Registering service..." -echo "[Unit] -Description=Node Exporter -Wants=network-online.target -After=network-online.target - -[Service] -ExecStart=${INSTALL_PATH}/node_exporter --web.listen-address=":29100" --web.config=${INSTALL_PATH}/config.yaml - -[Install] -WantedBy=default.target" > /etc/systemd/system/node_exporter.service - #重载服务 - systemctl daemon-reload - #启动服务 - systemctl start node_exporter.service - #设置开机自启 - systemctl enable node_exporter.service -} - -#安装完成 -install_success(){ - echo "----------------------------" - #推送数据到普罗米修斯以自动注册 - curl -u 'xiaoz:HAKrmCM6' -X POST -d "instance=${INSTANCE}" https://prometheus.rss.ink/api/v1/push_data - echo "" - echo "Installation is complete, please visit http://${myip}:29100" -} - -#清理工作 -clean_work() { - echo "Cleaning installation packages..." - rm -rf /opt/node_exporter-${VERSION}.linux-amd64.tar.gz -} - -#卸载node_exporter -uninstall(){ - #停止服务 - systemctl stop node_exporter - systemctl disable node_exporter - #删除服务 - rm -rf /etc/systemd/system/node_exporter.service - systemctl daemon-reload - #删除安装目录 - rm -rf ${INSTALL_PATH} - echo "----------------------------" - echo "Uninstall completed." -} - -#根据参数一判断执行动作 -case $ACTION in -"install") - depend && download && setting && release_port && reg_systemd && clean_work && install_success - ;; -"uninstall") - uninstall - ;; -*) - echo "Parameter error!" - ;; -esac - - From 30f47897e2a385e5deda14e771d62f0dabcf768e Mon Sep 17 00:00:00 2001 From: xiaoz Date: Thu, 17 Feb 2022 17:05:39 +0800 Subject: [PATCH 17/18] add --- node_exporter.sh | 148 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 148 insertions(+) create mode 100644 node_exporter.sh diff --git a/node_exporter.sh b/node_exporter.sh new file mode 100644 index 0000000..8a51536 --- /dev/null +++ b/node_exporter.sh @@ -0,0 +1,148 @@ +#!/bin/bash +##### name:一键安装node-exporter节点 ##### +##### authro:xiaoz ##### +##### update:2021/12/09 ##### + +#获取action +ACTION=$1 +#获取版本号 +VERSION=$2 +#instance名称 +#INSTANCE=$2 +#用户名、密码 +#USERNAME_PASSWORD=$3 +#安装目录 +INSTALL_PATH="/opt/node_exporter" + +#安装前准备 +depend(){ + echo "Pre-installation preparation is in progress..." + if [ -e "/usr/bin/yum" ] + then + yum -y install wget curl + else + #更新软件,否则可能make命令无法安装 + apt-get -y update + apt-get install -y wget curl + fi + #获取机器IP + myip=$(curl ipv4.ip.sb) + #获取INSTANCE名称,如果为空,则获取hostname + if [[ "$INSTANCE" == "" ]] + then + INSTANCE=$(echo $HOSTNAME)_${myip} + else + INSTANCE=${INSTANCE}_${myip} + fi +} +#下载 +download(){ + #下载之前检查node_exporter是否安装过 + if [ -f "/opt/node_exporter" ] + then + echo "node_exporter has been installed." + exit + fi + echo "Ready to download the installation package..." + wget -P /opt http://soft.xiaoz.org/linux/node_exporter-${VERSION}.linux-amd64.tar.gz + cd /opt && tar -xvf node_exporter-${VERSION}.linux-amd64.tar.gz + mv node_exporter-${VERSION}.linux-amd64 node_exporter +} + +#一些额外的配置 +setting(){ + #设置密码访问 +cat >> $INSTALL_PATH/config.yaml << EOF +basic_auth_users: + $USERNAME_PASSWORD +EOF + +} + +#放行端口 +release_port(){ + echo "Detecting firewall type..." + #检测防火墙类型 + which firewall-cmd + if [ $? -eq 0 ] + then + firewall_status=$(firewall-cmd --state) + if [[ "$firewall_status" == "running" ]] + then + firewall-cmd --zone=public --add-port=29100/tcp --permanent + firewall-cmd --reload + fi + fi + which ufw + if [ $? -eq 0 ] + then + ufw allow 29100/tcp + fi +} + + +#注册服务并启动 +reg_systemd(){ + echo "Registering service..." +echo "[Unit] +Description=Node Exporter +Wants=network-online.target +After=network-online.target + +[Service] +ExecStart=${INSTALL_PATH}/node_exporter --web.listen-address=":29100" --web.config=${INSTALL_PATH}/config.yaml + +[Install] +WantedBy=default.target" > /etc/systemd/system/node_exporter.service + #重载服务 + systemctl daemon-reload + #启动服务 + systemctl start node_exporter.service + #设置开机自启 + systemctl enable node_exporter.service +} + +#安装完成 +install_success(){ + echo "----------------------------" + #推送数据到普罗米修斯以自动注册 + curl -u "${API_USER_PASS}" -X POST -d "instance=${INSTANCE}" https://prometheus.rss.ink/api/v1/push_data + echo "Installation is complete, please visit http://${myip}:29100" +} + +#清理工作 +clean_work() { + echo "Cleaning installation packages..." + rm -rf /opt/node_exporter-${VERSION}.linux-amd64.tar.gz +} + +#卸载node_exporter +uninstall(){ + #停止服务 + systemctl stop node_exporter + systemctl disable node_exporter + #删除服务 + rm -rf /etc/systemd/system/node_exporter.service + systemctl daemon-reload + #删除安装目录 + rm -rf ${INSTALL_PATH} + #请求API移除服务端数据 + curl -u "${API_USER_PASS}" https://prometheus.rss.ink/api/v1/push_data?type=delete + echo "----------------------------" + echo "Uninstall completed." +} + +#根据参数一判断执行动作 +case $ACTION in +"install") + depend && download && setting && release_port && reg_systemd && clean_work && install_success + ;; +"uninstall") + uninstall + ;; +*) + echo "Parameter error!" + ;; +esac + + From f6c924dd611faa7a3bf8361b9cf91470c85ef2bf Mon Sep 17 00:00:00 2001 From: xiaoz Date: Thu, 17 Feb 2022 18:36:02 +0800 Subject: [PATCH 18/18] remove --- node_exporter.sh | 148 ----------------------------------------------- 1 file changed, 148 deletions(-) delete mode 100644 node_exporter.sh diff --git a/node_exporter.sh b/node_exporter.sh deleted file mode 100644 index 8a51536..0000000 --- a/node_exporter.sh +++ /dev/null @@ -1,148 +0,0 @@ -#!/bin/bash -##### name:一键安装node-exporter节点 ##### -##### authro:xiaoz ##### -##### update:2021/12/09 ##### - -#获取action -ACTION=$1 -#获取版本号 -VERSION=$2 -#instance名称 -#INSTANCE=$2 -#用户名、密码 -#USERNAME_PASSWORD=$3 -#安装目录 -INSTALL_PATH="/opt/node_exporter" - -#安装前准备 -depend(){ - echo "Pre-installation preparation is in progress..." - if [ -e "/usr/bin/yum" ] - then - yum -y install wget curl - else - #更新软件,否则可能make命令无法安装 - apt-get -y update - apt-get install -y wget curl - fi - #获取机器IP - myip=$(curl ipv4.ip.sb) - #获取INSTANCE名称,如果为空,则获取hostname - if [[ "$INSTANCE" == "" ]] - then - INSTANCE=$(echo $HOSTNAME)_${myip} - else - INSTANCE=${INSTANCE}_${myip} - fi -} -#下载 -download(){ - #下载之前检查node_exporter是否安装过 - if [ -f "/opt/node_exporter" ] - then - echo "node_exporter has been installed." - exit - fi - echo "Ready to download the installation package..." - wget -P /opt http://soft.xiaoz.org/linux/node_exporter-${VERSION}.linux-amd64.tar.gz - cd /opt && tar -xvf node_exporter-${VERSION}.linux-amd64.tar.gz - mv node_exporter-${VERSION}.linux-amd64 node_exporter -} - -#一些额外的配置 -setting(){ - #设置密码访问 -cat >> $INSTALL_PATH/config.yaml << EOF -basic_auth_users: - $USERNAME_PASSWORD -EOF - -} - -#放行端口 -release_port(){ - echo "Detecting firewall type..." - #检测防火墙类型 - which firewall-cmd - if [ $? -eq 0 ] - then - firewall_status=$(firewall-cmd --state) - if [[ "$firewall_status" == "running" ]] - then - firewall-cmd --zone=public --add-port=29100/tcp --permanent - firewall-cmd --reload - fi - fi - which ufw - if [ $? -eq 0 ] - then - ufw allow 29100/tcp - fi -} - - -#注册服务并启动 -reg_systemd(){ - echo "Registering service..." -echo "[Unit] -Description=Node Exporter -Wants=network-online.target -After=network-online.target - -[Service] -ExecStart=${INSTALL_PATH}/node_exporter --web.listen-address=":29100" --web.config=${INSTALL_PATH}/config.yaml - -[Install] -WantedBy=default.target" > /etc/systemd/system/node_exporter.service - #重载服务 - systemctl daemon-reload - #启动服务 - systemctl start node_exporter.service - #设置开机自启 - systemctl enable node_exporter.service -} - -#安装完成 -install_success(){ - echo "----------------------------" - #推送数据到普罗米修斯以自动注册 - curl -u "${API_USER_PASS}" -X POST -d "instance=${INSTANCE}" https://prometheus.rss.ink/api/v1/push_data - echo "Installation is complete, please visit http://${myip}:29100" -} - -#清理工作 -clean_work() { - echo "Cleaning installation packages..." - rm -rf /opt/node_exporter-${VERSION}.linux-amd64.tar.gz -} - -#卸载node_exporter -uninstall(){ - #停止服务 - systemctl stop node_exporter - systemctl disable node_exporter - #删除服务 - rm -rf /etc/systemd/system/node_exporter.service - systemctl daemon-reload - #删除安装目录 - rm -rf ${INSTALL_PATH} - #请求API移除服务端数据 - curl -u "${API_USER_PASS}" https://prometheus.rss.ink/api/v1/push_data?type=delete - echo "----------------------------" - echo "Uninstall completed." -} - -#根据参数一判断执行动作 -case $ACTION in -"install") - depend && download && setting && release_port && reg_systemd && clean_work && install_success - ;; -"uninstall") - uninstall - ;; -*) - echo "Parameter error!" - ;; -esac - -