一、安装go

  1. 解压安装

# tar -C /usr/local/ -xvf go1.14.1.linux-amd64.tar.gz

  1. 配置环境变量

    1. # vim /etc/profile
    2. export PATH=$PATH:/usr/local/go/bin
    3. # source /etc/profile
  2. 验证

image.png

二、安装prometheus

  1. 安装

# 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

  1. 创建服务脚本 ```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

  1. 3. 启动prometheus
  2. `# systemctl daemon-reload `<br />`# systemctl enable prometheus.service `<br />`# systemctl start prometheus.service `<br />`# systemctl status prometheus `
  3. 4. 验证
  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)
  5. <a name="1sO3s"></a>
  6. # 三、安装grafana-server
  7. - [下载链接](https://grafana.com/grafana/download)
  8. 1. 安装
  9. `# rpm -ivh grafana-6.7.2-1.x86_64.rpm`
  10. 2. 启动
  11. `# systemctl enable grafana-server.service`<br />`# systemctl start grafana-server.service`
  12. 3. 访问grafana
  13. 浏览器访问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)
  14. 4. 添加prometheus数据源
  15. - 点击主界面的“Add data source
  16. ![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)
  17. - 选择prometheus
  18. ![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)
  19. - 添加url地址并保存
  20. ![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)
  21. - 添加dashboard
  22. ![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)
  23. - 查看仪表盘
  24. ![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)
  25. <a name="PQiKL"></a>
  26. # 四、使用node-exporter监控linux主机
  27. 1. 被监控的机器安装node-exporter
  28. `# tar -zxvf node_exporter-0.18.1.linux-amd64.tar.gz` <br />`# mv node_exporter-0.18.1.linux-amd64 /usr/local/node_exporter`
  29. 2. 创建服务脚本
  30. ```bash
  31. # cd /usr/lib/systemd/system
  32. # vim node_exporter.service
  33. [Unit]
  34. Description=node_exporter
  35. After=network.target
  36. [Service]
  37. Type=simple
  38. User=root
  39. ExecStart=/usr/local/node_exporter/node_exporter
  40. Restart=on-failure
  41. [Install]
  42. WantedBy=multi-user.target
  1. 启动node_exporter

# systemctl daemon-reload
# systemctl enable node_exporter.service
# systemctl start node_exporter.service
# systemctl status node_exporter.service

  1. prometheus服务端添加监控项,然后重启prometheus

# vim /usr/local/Prometheus/prometheus.yml
image.png

  1. 查看prometheus web界面——status——targets

image.png

  1. grafana导入自定义的dashboard

image.png

  • 配置数据源,dashboard名称

image.png

  • 查看dashboard

image.png

五、监控windows机器(wmi-exporter)

  1. 被监控windows机器安装wmi-exporter,会自动创建一个开机自启的服务

image.png
image.png

  1. prometheus服务端添加监控项,然后重启prometheus

# vim /usr/local/Prometheus/prometheus.yml
image.png

  1. 查看prometheus web界面——status——targets

image.png

  1. grafana导入自定义的dashboard