Centos 服务器 Grafana 性能监控

主要三个组件。
在这里插入图片描述

Grafana 安装

1、下载安装

https://grafana.com/grafana/download

2、防火墙放行 web 端口

firewall-cmd --zone=public --add-port=3000/tcp --permanent
systemctl restart firewalld.service

3、访问 web 界面

http://127.0.0.1:3000/login

Node_exporter 安装

1、下载。

https://github.com/prometheus/node_exporter/releases

2、解压。

tar -xzf

3、安装。

cp node_exporter-1.1.2.darwin-amd64/node_exporter /usr/local/bin/

4、创建启动脚本 /usr/lib/systemd/system/node_exporter.service。

[Unit]
Description=node_exporter
Documentation=https://prometheus.io/
After=network.target
[Service]
Type=simple
ExecStart=/usr/local/bin/node_exporter
Restart=on-failure
[Install]
WantedBy=multi-user.target

6、启动与配置自启动。

systemctl daemon-reload
systemctl start node_exporter.service
systemctl enable node_exporter.service
systemctl status node_exporter.service        # 启动失败看日志

注:自启动可写入 /etc/rc.local 代替 systemctl。

注,docker 中使用:

docker run -d \
  --net="host" \
  --pid="host" \
  -v "/:/host:ro,rslave" \
  quay.io/prometheus/node-exporter \
  --path.rootfs /host

Prometheus 安装

1、下载。

https://prometheus.io/download/

2、解压。

tar -xzf

3、安装。

mv prometheus-2.36.2.linux-amd64 /opt

5、修改 prometheus 配置 prometheus-2.36.2.linux-amd64/prometheus.yml。

scrape_configs:
  - job_name: 'prometheus'
    static_configs:
      - targets: ['localhost:9090']
  # prometheus 采集的监控数据上报给 node exporter 
  - job_name: 'node'
    static_configs:
      - targets: ['localhost:9100']         # 根据情况,我这里 export node 和 prometheus 在同一台服务器

6、创建启动脚本 /usr/lib/systemd/system/prometheus.service。

[Unit]
Description=prometheus
After=network.target

[Service]
Type=simple
ExecStart=/opt/prometheus-2.36.2.linux-amd64/prometheus --config.file /opt/prometheus-2.36.2.linux-amd64/prometheus.yml
Restart=on-failure

[Install]
WantedBy=default.target

7、启动与配置自启动。

systemctl daemon-reload
systemctl start prometheus.service
systemctl enable prometheus.service
systemctl status prometheus.service

监控可视化

1、配置 prometheus。
在这里插入图片描述

2、下载监控模板 json 配置:https://grafana.com/api/dashboards/8919/revisions/25/download,并导入。

https://grafana.com/grafana/dashboards/8919-1-node-exporter-for-prometheus-dashboard-cn-0413-consulmanager

在这里插入图片描述
3、选择步骤 1 配置的 prometheus 作为数据源。

4、大功告成🎉🎉🎉🎉🎉🎉,查看可视化监控信息。

在这里插入图片描述

Mac 安装教程

brew install prometheus
# 默认配置文件:/usr/local/etc/prometheus.yml
nano /usr/local/etc/prometheus.yml    
# 写入下面配置:
# start:
global:
  scrape_interval: 15s
scrape_configs:
  - job_name: "prometheus"
    static_configs:
    - targets: ["localhost:9090"]
  - job_name: 'node'
    static_configs:
      - targets: ['localhost:9100']
# :end 
# 启动 prometheus
prometheus --config.file=/usr/local/etc/prometheus.yml
# http://localhost:9090
brew install node_exporter
# 服务模式运行 node_exporter:
	# brew services start node_exporter
	# 卸载 node_exporter 服务: launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.node_exporter.plist 
# 终端运行 node_exporter:
	# node_exporter
# 安装 grafana 【推荐安装到 docker 或其它设备】
brew install grafana
# 启动 grafana —— 配置文件夹见后缀 —— 默认密码 admin/admin
grafana-server \
--config=/usr/local/etc/grafana/grafana.ini \
--homepath /usr/local/share/grafana \
--packaging=brew \
cfg:default.paths.logs=/usr/local/var/log/grafana \
cfg:default.paths.data=/usr/local/var/lib/grafana \
cfg:default.paths.plugins=/usr/local/var/lib/grafana/plugins
# http://127.0.0.1:3000

prometheus 和 grafana 安装到 docker

没有 node_exporter ?node_exporter 做数据采集,你懂我的意思吧。

创建网段:

sudo docker network create --subnet=172.18.0.0/16 mynet
prometheus:

~/prometheus.yml:

global:
  scrape_interval: 15s
scrape_configs:
  - job_name: "prometheus"
    static_configs:
    - targets: ["localhost:9090"]
  - job_name: 'node'
    static_configs:
      - targets: ['host.docker.internal:9100']     # host.docker.internal 为宿主机 ip
docker run -d --name prometheus --restart=always -p 9090:9090 \
--net mynet --ip 172.18.0.90 \
-v ~/prometheus.yml:/etc/prometheus/prometheus.yml prom/prometheus
grafana:
docker run -d -p 3000:3000 --restart=always --name grafana \
--net mynet grafana/grafana-enterprise

grafana 选择 DataSource 时目标 ip 为 172.18.0.90,端口同样 9090。
在这里插入图片描述

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值