一、安装go
- 解压安装
# tar -C /usr/local/ -xvf go1.14.1.linux-amd64.tar.gz
配置环境变量
# vim /etc/profile
export PATH=$PATH:/usr/local/go/bin
# source /etc/profile
验证
二、安装prometheus
- 安装
# tar -C /usr/local/ -xvf prometheus-2.17.1.linux-amd64.tar.gz
# mv /usr/local/prometheus-2.6.0.linux-amd64/ /usr/local/Prometheus
- 创建服务脚本
```bash
cd /usr/lib/systemd/system
vim prometheus.service
[Unit] Description=Prometheus Documentation=https://prometheus.io/ After=network.target
[Service]
Type设置为notify时,服务会不断重启
Type=simple User=root Group=root
—storage.tsdb.path是可选项,默认数据目录在运行目录的./dada目录中
ExecStart=/usr/local/prometheus/prometheus —config.file=/usr/local/prometheus/prometheus.yml Restart=on-failure
[Install] WantedBy=multi-user.target
3. 启动prometheus
`# systemctl daemon-reload `<br />`# systemctl enable prometheus.service `<br />`# systemctl start prometheus.service `<br />`# systemctl status prometheus `
4. 验证
浏览器打开IP:9090端口即可打开普罗米修斯自带的监控页面<br />![image.png](https://cdn.nlark.com/yuque/0/2020/png/2308212/1607592793608-d6c33e26-1ad3-4d82-956a-d4d6c5b1b4d1.png#crop=0&crop=0&crop=1&crop=1&height=254&id=X9UA0&margin=%5Bobject%20Object%5D&name=image.png&originHeight=507&originWidth=823&originalType=binary&ratio=1&rotation=0&showTitle=false&size=25800&status=done&style=none&title=&width=411.5)
<a name="1sO3s"></a>
# 三、安装grafana-server
- [下载链接](https://grafana.com/grafana/download)
1. 安装
`# rpm -ivh grafana-6.7.2-1.x86_64.rpm`
2. 启动
`# systemctl enable grafana-server.service`<br />`# systemctl start grafana-server.service`
3. 访问grafana
浏览器访问IP:3000端口,即可打开grafana页面,默认用户名密码都是admin,初次登录会要求修改默认的登录密码<br />![image.png](https://cdn.nlark.com/yuque/0/2020/png/2308212/1607592879332-d0c26be5-ae0d-433e-989c-f22577e8267e.png#crop=0&crop=0&crop=1&crop=1&height=296&id=lDZd5&margin=%5Bobject%20Object%5D&name=image.png&originHeight=592&originWidth=944&originalType=binary&ratio=1&rotation=0&showTitle=false&size=53854&status=done&style=none&title=&width=472)
4. 添加prometheus数据源
- 点击主界面的“Add data source”
![image.png](https://cdn.nlark.com/yuque/0/2020/png/2308212/1607592906314-83b80b06-eb1d-46ab-bc3d-ba288c7e416d.png#crop=0&crop=0&crop=1&crop=1&height=219&id=mBk88&margin=%5Bobject%20Object%5D&name=image.png&originHeight=437&originWidth=1015&originalType=binary&ratio=1&rotation=0&showTitle=false&size=53781&status=done&style=none&title=&width=507.5)
- 选择prometheus
![image.png](https://cdn.nlark.com/yuque/0/2020/png/2308212/1607592920195-7f40dca1-8787-4ff5-9346-2e7e60107289.png#crop=0&crop=0&crop=1&crop=1&height=304&id=yCCas&margin=%5Bobject%20Object%5D&name=image.png&originHeight=608&originWidth=1143&originalType=binary&ratio=1&rotation=0&showTitle=false&size=115113&status=done&style=none&title=&width=571.5)
- 添加url地址并保存
![image.png](https://cdn.nlark.com/yuque/0/2020/png/2308212/1607592942321-b77690f5-0cec-49bc-ae5e-568f4b2aba40.png#crop=0&crop=0&crop=1&crop=1&height=221&id=zO8xF&margin=%5Bobject%20Object%5D&name=image.png&originHeight=441&originWidth=852&originalType=binary&ratio=1&rotation=0&showTitle=false&size=78270&status=done&style=none&title=&width=426)
- 添加dashboard
![image.png](https://cdn.nlark.com/yuque/0/2020/png/2308212/1607592956146-5bef1aad-ac94-4e21-ad7d-dfb025ba31af.png#crop=0&crop=0&crop=1&crop=1&height=172&id=s3DKb&margin=%5Bobject%20Object%5D&name=image.png&originHeight=344&originWidth=1137&originalType=binary&ratio=1&rotation=0&showTitle=false&size=96180&status=done&style=none&title=&width=568.5)
- 查看仪表盘
![image.png](https://cdn.nlark.com/yuque/0/2020/png/2308212/1607592967301-60c72136-f0d2-4ea1-8922-dd4839e00ca7.png#crop=0&crop=0&crop=1&crop=1&height=283&id=nJRkT&margin=%5Bobject%20Object%5D&name=image.png&originHeight=565&originWidth=971&originalType=binary&ratio=1&rotation=0&showTitle=false&size=77583&status=done&style=none&title=&width=485.5)
<a name="PQiKL"></a>
# 四、使用node-exporter监控linux主机
1. 被监控的机器安装node-exporter
`# tar -zxvf node_exporter-0.18.1.linux-amd64.tar.gz` <br />`# mv node_exporter-0.18.1.linux-amd64 /usr/local/node_exporter`
2. 创建服务脚本
```bash
# cd /usr/lib/systemd/system
# vim node_exporter.service
[Unit]
Description=node_exporter
After=network.target
[Service]
Type=simple
User=root
ExecStart=/usr/local/node_exporter/node_exporter
Restart=on-failure
[Install]
WantedBy=multi-user.target
- 启动node_exporter
# systemctl daemon-reload
# systemctl enable node_exporter.service
# systemctl start node_exporter.service
# systemctl status node_exporter.service
- prometheus服务端添加监控项,然后重启prometheus
# vim /usr/local/Prometheus/prometheus.yml
- 查看prometheus web界面——status——targets
- grafana导入自定义的dashboard
- 参考链接
- 创建自定义dashboard,选择导入
- 配置数据源,dashboard名称
- 查看dashboard
五、监控windows机器(wmi-exporter)
- 下载地址(下载msi格式安装包)
- 被监控windows机器安装wmi-exporter,会自动创建一个开机自启的服务
- prometheus服务端添加监控项,然后重启prometheus
# vim /usr/local/Prometheus/prometheus.yml
- 查看prometheus web界面——status——targets
- grafana导入自定义的dashboard