prometheus
#!/bin/bash
# auther: 连山周易
VERSION=1.6.1
SOFTWARE=node_exporter-${VERSION}.linux-amd64.tar.gz
URL=https://github.com/prometheus/node_exporter/releases/download/v${VERSION}/${SOFTWARE}
DOWNLOAD=./download
INSTALLDIR=/zhangyu/softwares
BASEDIR=${INSTALLDIR}/node_exporter-${VERSION}.linux-amd64
# 判断目录是否存在,若不存在则创建
[ -d $INSTALLDIR ] || mkdir -pv ${INSTALLDIR}
[ -d $DOWNLOAD ] || mkdir -pv ${DOWNLOAD}
# 判断系统是否安装curl
[ -f /usr/bin/curl ] || yum -y install curl
# 判断文件是否存在,若不存在则下载
[ -s ${DOWNLOAD}/${SOFTWARE} ] || curl $URL -o ${DOWNLOAD}/${SOFTWARE}
if [ $? -eq 0 ]; then
# 解压文件软件包
tar xf ${DOWNLOAD}/${SOFTWARE} -C ${INSTALLDIR}
# 生成启动脚本
cat > /etc/systemd/system/node-exporter.service <<EOF
[Unit]
Description=Linux Node Exporter
Documentation=https://prometheus.io/docs/introduction/overview/
After=network.target
[Service]
ExecStart=${BASEDIR}/node_exporter
[Install]
WantedBy=multi-user.target
EOF
# 将服务设置为开机自启动
systemctl daemon-reload
systemctl enable --now node-exporter.service
fi