揭秘业务背后的守护者,真实业务场景带你领略运维技术的魅力!

看了很多技术大佬的博客,都是在讲技术,缺乏业务场景的构建,很多运维人员遇到问题找不到解决方案。因此我想分享真实的业务场景,大家一起沟通业务问题,快速的提升技术,快速升职加薪。

-----------------------正文开始-----------------------

一、prometheus安装

1、下载prometheus
下载地址: https://prometheus.io/download/
  • 1.
2、设置systemd
[Service]
#Type设置为notify时,服务会不断重启
LimitCORE=infinity
LimitNOFILE=500000
LimitNPROC=500000
Type=simple
User=root
#--storage.tsdb.path是可选项,默认数据目录在运行目录的./dada目录中
ExecStart=/bin/sh -c '/opt/jiankong/prometheus/prometheus-2.53.1/prometheus --web.listen-address=0.0.0.0:9080 --config.file=/opt/jiankong/prometheus/prometheus-2.53.1/prometheus.yml --storage.tsdb.path=/opt/jiankong/prome-db  --web.enable-lifecycle  --storage.tsdb.retention.time=90d'
#如果想要修改prometheus的web端口号,只需要把web.listen-address的参数修改为你要修改的端口号即可。
Restart=on-failure
[Install]
WantedBy=multi-user.target
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
3、设置重载prometheus服务的脚本
vim reload.sh
#!/bin/bash
kill -SIGHUP $(pidof prometheus)

每次更改完配置后,使用   ./promtool check config prometheus.yml  检查配置是否正确
使用  /bin/bash reload.sh  进行重载prometheus配置。
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
4、配置prometheus的配置文件 prometheus.yml
vim  prometheus.yml

# my global config
global:
  scrape_interval: 15s
  evaluation_interval: 15s

# Alertmanager configuration
alerting:
  alertmanagers:
    - static_configs:
        - targets:
          # - alertmanager:9093

rule_files:
  # - "first_rules.yml"
  # - "second_rules.yml"
    - ./rule/*.yml

scrape_configs:
#  - job_name: "prometheus"
- job_name: node-test
  scrape_interval: 15s
  scrape_timeout: 10s
  metrics_path: /metrics
  scheme: http
  #要监控的主机节点很多,如果都使用静态添加的方式,不便于维护及查看,因此使用文件的方式来添加节点。
  file_sd_configs:
    - files:
      - sub_config/common/node-test.yml
      

      
vim sub_config/common/node-test.yml

# 测试-192.168.200.75
- targets:
  - 192.168.200.75:9100
  labels:
     instance: test-200.75
     role: 测试机-200.75
注意缩进,yaml文件对于缩进的要求很高,一定按照标准缩进来写,不然会检查不过。
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.

配置完成后,检查prometheus的配置

./promtool check config prometheus.yml
  • 1.

prometheus+grafana安装部署_监控告警

安装完成后,可以访问prometheus web地址,查看服务是否正常启动

http://localhost:9080
  • 1.

二、node_exporter 安装部署

1、node_exporter下载
https://github.com/prometheus/node_exporter/releases
  • 1.
2、node_exporter安装
cd /opt/src
tar xf node_exporter-1.0.1.linux-amd64.tar.gz -C /opt/
#创建systemd
cat >> /etc/systemd/system/prometheus-node.service << EOF
[Unit]
Description=Prometheus Node
After=network.target prometheus.service
[Service]
Type=simple
ExecStart=/opt/node_exporter-1.0.1.linux-amd64/node_exporter --web.listen-address=0.0.0.0:9100
#如果想要修改prometheus的web端口号,只需要把web.listen-address的参数修改为你要修改的端口号即可。
[Install]
WantedBy=multi-user.target
EOF
#启动prometheus-node.service并设置开机自启
systemctl enable prometheus-node.service
systemctl start prometheus-node.service
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.

三、grafana 安装部署

1、安装部署grafana
wget https://dl.grafana.com/enterprise/release/grafana-enterprise-8.4.1.linux-amd64.tar.gz
#解压grafana
tar -zxvf grafana-enterprise-8.4.1.linux-amd64.tar.gz

#启动grafana
/opt/jiankong/grafana-8.4.1/bin/grafana-server
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
2、制作重启grafana的脚本:
#!/bin/bash
ps -aux|grep grafana-8.4.1|grep -v grep| awk '{print $2}' | xargs -i kill -9 {}
nohup /opt/jiankong/grafana-8.4.1/bin/grafana-server &
sleep 3
echo "<<<<<<<<grafana stauts>>>>>>>>>>"
ps -ef |grep grafana
echo "<<<<<<<<grafana status>>>>>>>>>>"
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
3、修改grafana的web端口号:

grafana的配置文件路径: ./conf/defaults.ini

进入文件找到server模块中修改http_port的参数即可

prometheus+grafana安装部署_监控告警_02

----------------------------以下无正文-------------------------

如果大家有运维技术问题,可扫描下方二维码进QQ群,一起沟通交流,提升技术。

prometheus+grafana安装部署_grafana_03