Prometheus 安装,更改启动方式为 系统 systemctl

Prometheus 二进制安装

首先去 Prometheus官网去下载我们需要的链接
Prometheus 官网

在这里插入图片描述

我们复制图中的链接,然后在我们的 Linux主机上下载服务端:

wget https://github.com/prometheus/prometheus/releases/download/v2.17.1/prometheus-2.17.1.linux-amd64.tar.gz

在这里插入图片描述
下载好 压缩包,开始解压:

tar zxvf prometheus-2.17.1.linux-amd64.tar.gz     # 解压命令

解压好后:移动到 local目录下,(下载目录)方便以后查看,放在桌面 太笼统

mv prometheus-2.17.1.linux-amd64 /usr/local/prometheus

查看配置文件,监控的是否是本机

cd /usr/local/prometheus

vim prometheus.yml 

在这里插入图片描述
查看帮助信息:

./prometheus --help
# 这里只摘选最重要的两个

--storage.tsdb.path="data/"            # 普罗米修斯存储数据地址
   Base path for metrics storage.
   
--storage.tsdb.retention=STORAGE.TSDB.RETENTION         # 存储数据的时间,默认保存15天
   [DEPRECATED] How long to retain samples in storage. This flag has been deprecated, use "storage.tsdb.retention.time" instead.

--storage.tsdb.retention.time=STORAGE.TSDB.RETENTION.TIME  
   How long to retain samples in storage. When this flag is set it overrides "storage.tsdb.retention". If neither this flag nor "storage.tsdb.retention" nor
   "storage.tsdb.retention.size" is set, the retention time defaults to 15d. Units Supported: y, w, d, h, m, s, ms.
																	  # 15d代表时间

所以 普罗米修斯在数据存储这方面的确一般,官方给出的方法呢。是找一些外部存储器。
重要数据 自己选择其他方式进行存储

启动 普罗米修斯

./prometheus --config.file="prometheus.yml"
# 一定要在 Prometheus的目录下

浏览器输入自己的网关
在这里插入图片描述
上面的导航栏中

  • Alerts
    管理告警,所有配置的告警信息

    扫描二维码关注公众号,回复: 10912543 查看本文章
  • Graph
    图形,数据图形化

  • Status
    在这里插入图片描述

    运行时和构建信息

    命令行标记

    实现方式

    配置

    规则

    目标 – 监控的目标

    服务发现

先介绍这么多,大家自己 安装好后查看,还是非常简单的。



好了我们安装完了,大家可以发现。我们启动的其实是 一个二进制包(指定文件启动的)。
我们现在要把她 放置在我们的系统中

没错我们会用到 systemd

  • 复制一个 systemd的启动文件
cd /usr/lib/systemd/system

# 这里注意 拷贝过去的文件结尾一定要是 .service
cp sshd.service prometheus.service

更改 复制的 Prometheus文件

vim prometheus.service

按照这样更改

[Unit]
Description=https://prometheus.io

[Service]    
Restart=on-failure
ExecStart=/usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml   # 启动地址

[Install]
WantedBy=multi-user.target                            
按下 " Esc " 
输入 " : wq "  保存退出

最后 启动命令

systemctl daemon-reload      # 重启systemctl

systemctl start prometheus     # 启动普罗米修斯
systemctl stop prometheus      # 关闭普罗米修斯 

Docker 部署

systemctl start docker

docker run -p -d 9090:9090 -v /usr/local/prometheus.yml:/etc/prometheus/prometheus.yml \ prom/prometheus

将容器数据持久化到宿主机上

docker run -p 9090:9090 -v /prometheus-data \ prom/prometheus --config.file=/prometheus-data/prometheus.yml
发布了125 篇原创文章 · 获赞 260 · 访问量 12万+

猜你喜欢

转载自blog.csdn.net/weixin_44685869/article/details/105489503