首页 > 系统相关 >CentOS9 操作系统下 Prometheus 安装部署

CentOS9 操作系统下 Prometheus 安装部署

时间:2023-01-10 18:33:27浏览次数:73  
标签:操作系统 local prometheus Prometheus usr https com CentOS9 monitor

安装

直接下载了LTS的版本
网速快的可以直接用wget
操作系统CentOS9

cd /tmp/
dnf install wget -y
# 连不上github的话可以使用镜像之类的下下来再继续
wget https://github.com/prometheus/prometheus/releases/download/v2.37.5/prometheus-2.37.5.linux-amd64.tar.gz
umask 022
mkdir /usr/local/monitor
cd /usr/local/monitor
# 如果不是直接在系统内下载的,可以下载后再上传
# dnf install -y lrzsz
# rz -E # 选择下载的文件
dnf install -y tar
tar zxvf prometheus-2.37.5.linux-amd64.tar.gz
ln -s prometheus-2.37.5.linux-amd64 prometheus
cd prometheus
ll
mkdir -p /data/prometheus_data
echo "
[Unit]
Description=prometheus
[Service]
ExecStart=/usr/local/monitor/prometheus/prometheus --config.file=/usr/local/monitor/prometheus/prometheus.yml --storage.tsdb.path=/data/prometheus_data
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=on-failure
[Install]
WantedBy=multi-user.target
" > /usr/lib/systemd/system/prometheus.service
# systemctl daemon-reload # 如果中间修改过 prometheus.service 需要执行
systemctl start prometheus
systemctl status prometheus

上面systemctl中的参数可以添加更多,具体可以使用 ./prometheus --help 查看(参考https://www.cnblogs.com/zhoujinyi/p/11934062.html

systemctl status prometheus 执行结果

● prometheus.service - prometheus
     Loaded: loaded (/usr/lib/systemd/system/prometheus.service; disabled; vendor preset: disabled)
     Active: active (running) since Tue 2023-01-10 18:03:44 CST; 4s ago
   Main PID: 3156 (prometheus)
      Tasks: 6 (limit: 5909)
     Memory: 19.5M
        CPU: 50ms
     CGroup: /system.slice/prometheus.service
             └─3156 /usr/local/monitor/prometheus/prometheus --config.file=/usr/local/monitor/prometheus/prometheus.yml --storage.tsdb.path=/data/prometheus_data

打开web页面 http://hostip:9090

此时选择Graph在搜索框中输入"cpu"或者"mem"等关键词,选择一个指标,然后点击Execute即可看到曲线图。

配置

异常

页面提示:

Warning: Error fetching server time: Detected 47.81699991226196 seconds time difference between your browser and the server. Prometheus relies on accurate time and time drift might cause unexpected query results.

原因是服务器时间和终端时间不一致。
服务器时间可以使用timedatectl查看时区和时间。
终端和服务端时间都可以直接找ntp服务器进行同步。
我这里终端时间有问题,直接使用的是腾讯的ntp服务ntp.tencent.com

需要对服务器时间进行同步的话,可以参考这篇文章https://www.cnblogs.com/lizhaoxian/p/11260041.html

F5刷新页面后就没有错误提示了。

参考资料:
https://zhuanlan.zhihu.com/p/117719823
https://www.cnblogs.com/minseo/p/13395851.html
https://www.prometheus.wang/
https://www.cnblogs.com/zhoujinyi/p/11934062.html

标签:操作系统,local,prometheus,Prometheus,usr,https,com,CentOS9,monitor
From: https://www.cnblogs.com/yscheng/p/17041053.html

相关文章