大数据之系统监控Prometheus +Grafana安装
1、 安装 Prometheus
Prometheus 基于 Golang 编写,编译后的软件包,不依赖于任何的第三方依赖。只需要 下载对应平台的二进制包,解压并且添加基本的配置即可正常启动 Prometheus Server。
1、解压
tar -zxvf prometheus-2.26.0.linux-amd64.tar.gz -C /opt/module
mv /opt/module/prometheus-2.26.0.linux-amd64 /opt/module/prometheus
2、 修改配置文件 prometheus.yml
vim /opt/module/prometheus/prometheus.yml
在 scrape_configs 配置项下添加配置:
scrape_configs:
- job_name: 'prometheus'
static_configs:
- targets: ['bigdata:9090']
#添加 ClickHouse 监控配置
- job_name: clickhouse-1
static_configs:
- targets: ['bigdata:9363']
记住:一定空格要对齐
3、 启动 Prometheus Server
nohup /opt/module/prometheus/prometheus --config.file=/opt/module/prometheus/prometheus.yml > /opt/module/prometheus/logs/prometheus.log 2>&1 &
4、浏览器登陆
http://bigdata:9090/
prometheus 是 up 状态,表示安装启动成功:
5、关闭
netstat -apn | grep 9090
6、脚本封装
vim /home/bigdata/bin/prometheus.sh
#!/bin/bash
/opt/module/prometheus/prometheus --config.file=/opt/module/prometheus/prometheus.yml >> /opt/module/prometheus/logs/prometheus.log
vim /usr/lib/systemd/system/prometheus.service
[Unit]
Description=https://prometheus.io
[Service]
ExecStart=/home/bigdata/bin/prometheus.sh
Restart=on-failure
[Install]
WantedBy=multi-user.target
注意
systemctl daemon-reload # 重启systemctl
systemctl start prometheus # 启动普罗米修斯
systemctl stop prometheus # 关闭普罗米修斯
systemctl restart prometheus #重新启动普罗米修斯
systemctl status prometheus #查看状态
2、 Grafana 安装
1、 上传并解压
三只松鼠小美好零食大礼包约3斤13袋/14袋(新老包装混发)
京东购物
59.90
tar -zxvf grafana-7.5.2.linux-amd64.tar.gz -C /opt/module/
mv /opt/module/grafana-7.5.2/ /opt/module/grafana
2、 启动 Grafana
nohup /opt/module/grafana/bin/grafana-server > /opt/module/grafana/logs/grafana.log 2>&1 &
3、配置mysql作为数据源
vim /opt/module/grafana/conf/custom.ini
[paths]
data = /opt/module/grafana/data
temp_data_lifetime = 24h
logs = /opt/module/grafana/logs
plugins = /opt/module/grafana/plugins
provisioning = /opt/module/grafana/conf/provisioning
[database]
type = mysql
host = bigdata:3306
name = grafana
user = root
password = [email protected]
url = mysql://root:[email protected]@bigdata:3306/grafana
[root@bigdata conf]# pwd
/opt/module/grafana/conf
4、登陆页面
打开 web:http://bigdata:3000,默认用户名和密码:admin
5、脚本封装
拼小美蚕豆 整箱500g 坚果炒货干果小吃豆类酥脆零食小吃蚕豆休闲零食 C 蚕豆500g整箱
京东购物
19.90
vim /home/bigdata/bin/grafana.sh
#!/bin/bash
/opt/module/grafana/bin/grafana-server --config=/opt/module/grafana/conf/defaults.ini --homepath=/opt/module/grafana >> /opt/module/grafana/logs/grafana.log
vim /usr/lib/systemd/system/grafana-server.service
[Service]
ExecStart=/home/bigdata/bin/grafana.sh
[Install]
WantedBy=multi-user.target
[Unit]
Description=Grafana
After=network.target
注意
systemctl daemon-reload # 重启systemctl
systemctl start grafana-server # 启动grafana
systemctl stop grafana-server # 关闭grafana
systemctl restart grafana-server #重新启动grafana
systemctl status grafana-server #查看状态