node exporter
curl -Lo /etc/yum.repos.d/_copr_ibotty-prometheus-exporters.repo https://copr.fedorainfracloud.org/coprs/ibotty/prometheus-exporters/repo/epel-7/ibotty-prometheus-exporters-epel-7.repo yum install node_exporter -y # 部署node_exporter # apply_node_exporter.sh
#!/bin/bash cd /tmp mkdir -p /data/node_exporter wget 10.5.250.10:8888/node_exporter/start_node_exporter_centos.sh -O /data/node_exporter/start_node_exporter_centos.sh echo "启动 node_exporter" bash /data/node_exporter/start_node_exporter_centos.sh echo "添加开机启动" if ! grep "start_node_exporter_centos.sh" /etc/rc.d/rc.local; then echo "第一次添加" echo "/data/node_exporter/start_node_exporter_centos.sh" >> /etc/rc.d/rc.local else echo "启动项已存在" fi
# start_node_exporter_centos.sh
#!/bin/bash mkdir -p /data/node_exporter CentOS_Linux_release=$(awk -F 'CentOS Linux release' '{print $NF}' /etc/redhat-release | awk -F '.' '{print $1}' | sed 's# ##g') Node_exporter_path="/data/node_exporter/node_exporter_centos${CentOS_Linux_release}" #判断系统版本 if [ "${CentOS_Linux_release}" == "7" ]; then echo "CentOS Linux release 7" NODE_EXPORTER_RELEASE='node_exporter_centos7' elif [ "${CentOS_Linux_release}" == "6" ]; then echo "CentOS Linux release 6" NODE_EXPORTER_RELEASE='node_exporter_centos6' exit 998 else echo "不支持的 CentOS Linux release" 1>&2 exit 999 fi if ! [ -e "${Node_exporter_path}" ]; then echo "初始化下载node_exporter" if ! wget 10.5.250.10:8888/node_exporter/node_exporter_centos${CentOS_Linux_release} -O ${Node_exporter_path}; then echo "初始化下载 node_exporter 失败" exit 997 else chmod +x ${Node_exporter_path} fi fi if ss -ntlp | grep 9100; then echo "系统存在运行中的node_exporter 或者 端口9090 被占用" exit 996 fi echo "启动 ${CentOS_Linux_release}" exec nohup /data/node_exporter/node_exporter_centos${CentOS_Linux_release} &>/var/log/node_exporter.log &# ansible # apply_node_export.sh
#!/bin/bash if [ -z "$1" ];then echo "需要输入ansible 分组" 1>&2 exit 999 fi ansible $1 -m copy -a 'src=/etc/ansible/files/prometheus_node_exporter/apply_node_exporter.sh dest=/tmp/apply_node_exporter.sh mode=0755 owner=root group=root' ansible $1 -m shell -a '/tmp/apply_node_exporter.sh'