GrafanaPrometheus

离线包一键安装脚本

必须把所有包放在/root/下 (grafana,node_exporter,prometheus)这个三个软件,具体版本号如下:

grafanabb=10.1.2-1

node_exporterbb=1.6.1

prometheusbb=2.45.0

#!/bin/bash
#安装grafana
grafanabb=10.1.2-1
cd /root/ || exit
rpm -ivh grafana-enterprise-$grafanabb.x86_64.rpm
#启动grafana
systemctl daemon-reload
systemctl start grafana-server
systemctl status grafana-server
systemctl enable grafana-server

#安装node_exporter
node_exporterbb=1.6.1
cd /root/ || exit
tar -zxvf node_exporter-$node_exporterbb.linux-amd64.tar.gz
cd node_exporter-$node_exporterbb.linux-amd64/ || exit
nohup ./node_exporter &

#node_exporter开机自启
echo "cd /root/node_exporter-$node_exporterbb.linux-amd64 && nohup ./node_exporter &" >> /etc/rc.d/rc.local
chmod a+x /etc/rc.d/rc.local

#安装prometheus
prometheusbb=2.45.0
cd /root/ || exit
tar -zxvf prometheus-$prometheusbb.linux-amd64.tar.gz
cd prometheus-$prometheusbb.linux-amd64/ || exit
echo "  - job_name: \"wj\"" >> prometheus.yml
echo "    static_configs:" >> prometheus.yml
ipdz=$(ip addr | grep inet | grep -E -v "docker|127.0.0.1|inet6|safeline-ce" | awk '{print $2}' | awk -F "/" '{print $1}' | tail -n 1)
echo "      - targets: [\"$ipdz:9100\"]" >> prometheus.yml
nohup ./prometheus &
echo "cd /root/prometheus-$prometheusbb.linux-amd64 && nohup ./prometheus &" >> /etc/rc.d/rc.local
echo "------------Grafana一键安装完成----------------"
echo "grafana访问页面是:$ipdz:3000"
echo "默认账号密码是admin admin"
echo "数据源配置地址是http://$ipdz:9090"
echo "监控其它服务器请修改prometheus.yum文件"

Grafana

下载安装

#选择对应的版本
https://grafana.com/grafana/download
#官网安装教程
https://grafana.com/docs/grafana/latest/
#选择对应的版本下载
sudo yum install -y https://dl.grafana.com/enterprise/release/grafana-enterprise-10.1.2-1.x86_64.rpm
离线包已下载
rpm -ivh grafana-enterprise-10.1.2-1.x86_64.rpm
启停
systemctl daemon-reload
systemctl start grafana-server.service
systemctl stop grafana-server.service
systemctl enable grafana-server
systemctl status grafana-server.service

echo "------------Grafana一键安装完成----------------"

echo "grafana访问页面是:ip:3000"

echo "默认账号密码是admin admin"  首次登录让修改密码    统一修改为wangjian
图片[1]-GrafanaPrometheus-秋风落叶
图片[2]-GrafanaPrometheus-秋风落叶

开始配置数据源,每个版本位置可能不一样

图片[3]-GrafanaPrometheus-秋风落叶
图片[4]-GrafanaPrometheus-秋风落叶
图片[4]-GrafanaPrometheus-秋风落叶
图片[6]-GrafanaPrometheus-秋风落叶
图片[7]-GrafanaPrometheus-秋风落叶

安装仪表盘

#仪表盘地址,根据需要下载对应的JSON文件即可

https://grafana.com/grafana/dashboards/

#这个人做的模板看着还不错

https://grafana.com/orgs/starsliao/dashboards

grafana相关设置

自动刷设置

默认自动刷新是关闭的,可以手动修改

图片[8]-GrafanaPrometheus-秋风落叶
图片[9]-GrafanaPrometheus-秋风落叶
图片[10]-GrafanaPrometheus-秋风落叶

30秒刷新一次页面

图片[11]-GrafanaPrometheus-秋风落叶

Prometheus

下载安装

#官网下载
https://prometheus.io/download/
#下载具体版本
curl -O https://github.com/prometheus/prometheus/releases/download/v2.45.0/prometheus-2.45.0.linux-amd64.tar.gz
#解压安装
tar -zxvf prometheus-2.45.0.linux-amd64.tar.gz
cd prometheus-2.45.0.linux-amd64/
nohup ./prometheus &
启动端口是 :netstat -nlput |grep 9090
访问地址:http://192.168.70.128:9090/
#添加其他节点的数据源
# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
  # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
  - job_name: "wj"
    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.
    static_configs:
      - targets: ["192.168.70.128:9100"]    #修改为其它节点的实际IP和端口
图片[12]-GrafanaPrometheus-秋风落叶
图片[13]-GrafanaPrometheus-秋风落叶

登录验证

http://192.168.70.128:9090/metrics

图片[14]-GrafanaPrometheus-秋风落叶

服务启停

直接粘贴复制启停即可

vim initpro.sh

mulu=/root/prometheus-2.45.0.linux-amd64/
id=$(ps -ef|grep prometheus | head -1 | awk '{print $2}')
echo "$id"
kill -9 $id
cd $mulu 
nohup ./prometheus &
tail -1000f nohup.out
sh initpro.sh &

钉钉告警推送设置

钉钉端设置主要是为了获取Webhook

图片[15]-GrafanaPrometheus-秋风落叶
图片[16]-GrafanaPrometheus-秋风落叶
图片[17]-GrafanaPrometheus-秋风落叶
图片[18]-GrafanaPrometheus-秋风落叶

注意,由于请求实现的原因,必须选择ip地址段,只有填写的IP地址请求才会被接受,否则后面的测试将不会收到消息,也就是说ip地址必须包含grafana安装的地址

grafana添加报警通知设置

方式1:使用grafana自带的功能即可

下面配置的版本对应的是Grafana v10.1.2

图片[19]-GrafanaPrometheus-秋风落叶
图片[20]-GrafanaPrometheus-秋风落叶
图片[21]-GrafanaPrometheus-秋风落叶
图片[22]-GrafanaPrometheus-秋风落叶
图片[23]-GrafanaPrometheus-秋风落叶
图片[24]-GrafanaPrometheus-秋风落叶
图片[25]-GrafanaPrometheus-秋风落叶

方式2:使用alertmanager软件报警通知

© 版权声明
THE END
喜欢就支持一下吧
点赞8 分享
评论 抢沙发
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称表情代码图片快捷回复

    暂无评论内容