#!/bin/bash
#
# rhel7. 安装node_exporter 用于监控数据采集
# Usage:
# sh addNode.sh
#Logs: /var/log/messages
#History: // v3
#Create_Time: --
# USE: small_wei
#
# WEB_PATH='http://12.0.94.46:8086' #这里是我测试环境下的文件下载链接路径
# https://github.com/prometheus/node_exporter 官方下载地址 Install_PATH=/opt/node
Server_file=/usr/lib/systemd/system
RED_COLOR='\E[1;31m' #红
GREEN_COLOR='\E[1;32m' #绿
RES='\E[0m' node_user=node
node_group=node
Time_date=$(date +"%Y%m%d%H%M%S") if [ ! $(id -u) == ];then
echo -e "${GREEN_COLOR}Please run with the root user!${RES}"
exit
fi #防止重复执行
if [ $(ps -ef | grep $ |grep -v grep | wc -l) -gt ];then #理论值为 , 但这里是
echo -e "${RED_COLOR} $0 The script is executing, do not repeat!, Run id is $$${RES}"
exit
fi #create group if not exists
egrep "^${node_group}" /etc/group >/dev/null
if [ $? -ne ];then
groupadd ${node_group}
echo -e "${node_group} group Creating a successful"
fi #create user if not exists
egrep "^${node_user}" /etc/passwd >/dev/null
if [ $? -ne ];then
useradd -g ${node_group} ${node_user}
echo -e "${node_user} user Creating a successful"
fi port=`netstat -anp|grep `
if test -z "${port}"
then
mkdir -p ${Install_PATH}
chown -R ${node_user}:${node_user} ${Install_PATH}
wget -p ${Install_PATH} $WEB_PATH/downloadFile/node_exporter
chmod +x ${Install_PATH}/node_exporter
if [[ $? == ]];then
echo -e "${GREEN_COLOR}Environment readiness complete${RES}"
fi
#-----------------
if [ -f "${Server_file}/node_exporter.service" ];then
cp -f ${Server_file}/node_exporter.service ${Server_file}/node_exporter.service.bak${Time_date}
fi if [ $? == ];then
echo -e "${GREEN_COLOR}node_exporter.service.bak${Time_date} File The backup successful${RES}"
else
echo -e "${RED_COLOR}node_exporter.service.bak${Time_date} File backup failed${RES}"
exit
fi
cat >${Server_file}/node_exporter.service <<-EOF
[Unit]
Description=Prometheus node exporter
Documentation=https://prometheus.io/
After=local-fs.target network-online.target network.target
Wants=local-fs.target network-online.target network.target [Service]
User=${node_user}
Group=${node_group}
Type=simple
#ExecStart=${Install_PATH}/node_exporter --web.listen-address=: --log.level=error
ExecStart=${Install_PATH}/node_exporter --web.listen-address=: --log.level=info [Install]
WantedBy=multi-user.target
EOF systemctl daemon-reload
systemctl restart node_exporter if [ $? == ];then
echo -e "${GREEN_COLOR}node_exporte Server start success!${RES}"
else
echo -e "${RED_COLOR}node_exporte Server start ERROR!${RES}"
exit
fi
#------------------
else
echo -e "${GREEN_COLOR}port:9100 is busy,failed${RES}"
fi systemctl enable node_exporter
systemctl status node_exporter #验证
curl -I -m -o /dev/null -s -w %{http_code} 127.0.0.1: \n if [ $? == ];then
echo -e "${GREEN_COLOR}register node in consul success${RES}"
else
echo -e "${RED_COLOR}Registration failed or registered, please check! ${RES}"
exit
fi

Node_exporter一键安装部署脚本(Shell)的更多相关文章

  1. 分布式实时日志系统(一)环境搭建之 Jstorm 集群搭建过程/Jstorm集群一键安装部署

    最近公司业务数据量越来越大,以前的基于消息队列的日志系统越来越难以满足目前的业务量,表现为消息积压,日志延迟,日志存储日期过短,所以,我们开始着手要重新设计这块,业界已经有了比较成熟的流程,即基于流式 ...

  2. linux一键安装vncserver脚本

    title: linux一键安装vncserver脚本 date: 2016-04-11 14:32:04 tags: --- linux多数情况下是作为服务器使用的,管理员一般也喜欢使用命令行来管理 ...

  3. Rehat一键安装mysql脚本和备份数据库脚本

    Rehat一键安装mysql脚本 ##说明:适用,Rehat 5 6 7 1.运行状态,运行成功输出mysql临时密码 2.代码如下 #!/bin/bash #获取系统信息 sudo cat /etc ...

  4. (转)CentOS一键安装Nginx脚本

    原文:https://www.xiaoz.me/archives/10301 https://blog.slogra.com/post-676.html-----centos7一键安装nginx脚本

  5. rsync服务端一键安装rsync脚本(非源码)

    export RSYNC_PASSWORD=123 USER=rsync AUTHUSERS=bck MK=backupmk local_dir=/backup yum remove rsync &a ...

  6. 通过跳板机建立信任,对多个tomcat服务统一安装部署(shell编写)

    unifyDeploy 自动化统一安装部署 系统版本: unifyDeploy0.1 文件编号: 0.1 发布日期: 2014-06-26 编    制: WangYong 版权所有 内部资料注意保密 ...

  7. 一键安装cobbler脚本

    #!/bin/bash # # Install Cobbler(Kickstart) Tools / # Created by OceanHo(gzhehai@foxmail.com) AT -- # ...

  8. 一键安装lnmp脚本

    前段时间一直在找一个快速部署lnmp环境的方法,也没找着,就自己写了一个,结合网上的大神们的.我的方法是脚本结合源码包,很多依赖裤都是yum安装的,这都在脚本里面,需要的源码包我都下载好了,打包成压缩 ...

  9. 最新版kubernetesV1.14.1集群一键自动部署脚本

    部署命令如下:详情及注意事项请看README.md git clone https://github.com/luckman666/deploy_Kubernetes-v1.14.1.git cd d ...

随机推荐

  1. Token refresh的实现

    实现原理: 在access_token里加入refresh_token标识,给access_token设置短时间的期限(例如一天),给refresh_token设置长时间的期限(例如七天).当活动用户 ...

  2. 一文让你彻底了解大数据实时计算引擎 Flink

    前言 在上一篇文章 你公司到底需不需要引入实时计算引擎? 中我讲解了日常中常见的实时需求,然后分析了这些需求的实现方式,接着对比了实时计算和离线计算.随着这些年大数据的飞速发展,也出现了不少计算的框架 ...

  3. HTML基本单词《结构化标签》

  4. 2019 .NET China Conf:路一直都在,社区会更好

    这个周末,我从成都飞到了上海参加了首届由社区组织而非官方(比如Microsoft)组织的.NET开发者峰会(.NET Conf).为此,我特意请了两天的假(周五+周六,对,我们是大小周,这周六要上班) ...

  5. MapReduce 人个理解

    1.MapReduce 理解 拆分成 map 过程与 reduce 过程: map 可以理解为sql 中的 group by 操作, reduce相当于group by 后的聚合计算 : 一个map ...

  6. PHP获取图片每个像素点

    PHP获取图片每个像素点<pre> $i = imagecreatefromjpeg("test.jpg"); //图片路径 for ($x = 0; $x < ...

  7. Linux基于webRTC的二次开发(二) 实现远程桌面共享

    webRTC中的desktop_capture模块提供了捕获桌面和捕获窗口的相关功能,而实现远程桌面共享功能需要将desktop_capture捕获的画面作为peerconnection的视频源,下面 ...

  8. 怎样判断有没有SQL注入漏洞及原理?

    来源:实验楼 最为经典的单引号判断法: 在参数后面加上单引号,比如: http://xxx/abc.php?id=1' 如果页面返回错误,则存在 Sql 注入. 原因是无论字符型还是整型都会因为单引号 ...

  9. SpringBoot之微服务日志链路追踪

    SpringBoot之微服务日志链路追踪 简介 在微服务里,业务出现问题或者程序出的任何问题,都少不了查看日志,一般我们使用 ELK 相关的日志收集工具,服务多的情况下,业务问题也是有些难以排查,只能 ...

  10. 最近的项目系列1——core整合SPA

    1.前言 当前,前后端分离大行其道,我本人之前不少项目也是纯前后端分离,但总有些场景,春前后端分离整起来比较痛苦,比如我手头这个公众号项目吧,它涉及到第三方鉴权,第三方凭证,以及微信凭证这些,都不适合 ...