离线包一键安装脚本
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-秋风落叶](https://wangjian.run/wp-content/uploads/2023/09/1695796976-image-1024x492.png)
![图片[2]-GrafanaPrometheus-秋风落叶](https://wangjian.run/wp-content/uploads/2023/09/1695797136-image-1024x501.png)
开始配置数据源,每个版本位置可能不一样
![图片[3]-GrafanaPrometheus-秋风落叶](https://wangjian.run/wp-content/uploads/2023/09/1695797254-image-1024x500.png)
![图片[4]-GrafanaPrometheus-秋风落叶](https://wangjian.run/wp-content/uploads/2023/09/1695797354-image-1024x414.png)
![图片[4]-GrafanaPrometheus-秋风落叶](https://wangjian.run/wp-content/uploads/2023/09/1695797354-image-1024x414.png)
![图片[6]-GrafanaPrometheus-秋风落叶](https://wangjian.run/wp-content/uploads/2023/09/1695799145-image-1024x478.png)
![图片[7]-GrafanaPrometheus-秋风落叶](https://wangjian.run/wp-content/uploads/2023/09/1695799010-image-1024x260.png)
安装仪表盘
#仪表盘地址,根据需要下载对应的JSON文件即可
https://grafana.com/grafana/dashboards/
#这个人做的模板看着还不错
https://grafana.com/orgs/starsliao/dashboards
grafana相关设置
自动刷设置
默认自动刷新是关闭的,可以手动修改
![图片[8]-GrafanaPrometheus-秋风落叶](https://wangjian.run/wp-content/uploads/2023/09/1695892478-image.png)
![图片[9]-GrafanaPrometheus-秋风落叶](https://wangjian.run/wp-content/uploads/2023/09/1695892609-image-1024x44.png)
![图片[10]-GrafanaPrometheus-秋风落叶](https://wangjian.run/wp-content/uploads/2023/10/1697186847-image-1024x490.png)
30秒刷新一次页面
![图片[11]-GrafanaPrometheus-秋风落叶](https://wangjian.run/wp-content/uploads/2023/03/20240822214324786-1724334204-截屏2024-08-22-21.41.58-1024x704.png)
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-秋风落叶](https://wangjian.run/wp-content/uploads/2023/09/1695798296-image-1024x490.png)
![图片[13]-GrafanaPrometheus-秋风落叶](https://wangjian.run/wp-content/uploads/2023/09/1695798444-image-1024x475.png)
登录验证
http://192.168.70.128:9090/metrics
![图片[14]-GrafanaPrometheus-秋风落叶](https://wangjian.run/wp-content/uploads/2023/09/1695862116-image-1024x527.png)
服务启停
直接粘贴复制启停即可
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-秋风落叶](https://wangjian.run/wp-content/uploads/2023/10/1697095264-IMG_4648.jpg)
![图片[16]-GrafanaPrometheus-秋风落叶](https://wangjian.run/wp-content/uploads/2023/10/1697095317-IMG_4649.jpg)
![图片[17]-GrafanaPrometheus-秋风落叶](https://wangjian.run/wp-content/uploads/2023/10/1697095327-IMG_4650.jpg)
![图片[18]-GrafanaPrometheus-秋风落叶](https://wangjian.run/wp-content/uploads/2023/10/1697095333-2023-10-12_151302.png)
注意,由于请求实现的原因,必须选择ip地址段,只有填写的IP地址请求才会被接受,否则后面的测试将不会收到消息,也就是说ip地址必须包含grafana安装的地址
grafana添加报警通知设置
方式1:使用grafana自带的功能即可
下面配置的版本对应的是Grafana v10.1.2
![图片[19]-GrafanaPrometheus-秋风落叶](https://wangjian.run/wp-content/uploads/2023/10/1697098929-image.png)
![图片[20]-GrafanaPrometheus-秋风落叶](https://wangjian.run/wp-content/uploads/2023/10/1697099050-image.png)
![图片[21]-GrafanaPrometheus-秋风落叶](https://wangjian.run/wp-content/uploads/2023/10/1697099155-image-1024x406.png)
![图片[22]-GrafanaPrometheus-秋风落叶](https://wangjian.run/wp-content/uploads/2023/10/1697099215-image-1024x491.png)
![图片[23]-GrafanaPrometheus-秋风落叶](https://wangjian.run/wp-content/uploads/2023/10/1697099449-image-1024x446.png)
![图片[24]-GrafanaPrometheus-秋风落叶](https://wangjian.run/wp-content/uploads/2023/10/1697099484-image-1024x537.png)
![图片[25]-GrafanaPrometheus-秋风落叶](https://wangjian.run/wp-content/uploads/2023/10/1697099731-image-1024x505.png)
方式2:使用alertmanager软件报警通知
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END
暂无评论内容