1、下载安装golang编译环境
cd ~
wget https://golang.google.cn/dl/go1.15.4.linux-amd64.tar.gz
tar -C /usr/local -xzf go1.15.4.linux-amd64.tar.gz
export PATH=$PATH:/usr/local/go/bin
echo "export PATH=$PATH:/usr/local/go/bin" >> /etc/profile
go version
go env -w GOPROXY=https://goproxy.io,direct
2、下载安装snmp_exporter
cd /sas/prometheus/
wget https://github.com/prometheus/snmp_exporter/releases/download/v0.19.0/snmp_exporter-0.19.0.linux-amd64.tar.gz
tar -xzvf snmp_exporter-0.19.0.linux-amd64.tar.gz
mv snmp_exporter-0.19.0.linux-amd64 snmp_exporter
3、编写Systemd服务管理配置文件
vi /usr/lib/systemd/system/snmp_exporter.service
[Unit]
Description=Prometheus SNMP Exporter Services
After=network.target
[Service]
Type=simpleExecStart=/sas/prometheus/snmp_exporter/snmp_exporter --config.file=/sas/prometheus/snmp_exporter/snmp.yml
Restart=on-failure
RestartSec=5
[Install]
WantedBy=multi-user.target
systemctl daemon-reload
systemctl start snmp_exporter.service
systemctl enable snmp_exporter.service
4、下载并编译generator
需要使用generator生成snmp_exporter使用的配置文件snmp.yml
执行go get 因为网络原因可能出错,多重试几次即可
执行make mibs 因为SSL证书校验会报错,修改Makefile文件中curl参数增加-k参数,忽略校验即可
yum install -y gcc gcc-g++ make net-snmp net-snmp-utils net-snmp-libs net-snmp-devel
yum install -y unzip
go get -v github.com/prometheus/snmp_exporter/generator
cd ${GOPATH-$HOME/go}/src/github.com/prometheus/snmp_exporter/generator
go build
# 安装下载mib需要用到的解压缩软件
yum install -y unzip p7zip
ln -s /usr/bin/7za /usr/bin/7z
vi Makefile
# CURL_OPTS ?= -s --retry 3 --retry-delay 3 --compressed --location --fail
CURL_OPTS ?= -k -s --retry 3 --retry-delay 3 --compressed --location --fail
make mibs