在Ubuntu 20.04上部署Prometheus的过程可以分为几个步骤:安装Prometheus,配置Prometheus,启动和验证服务。下面我们将详细介绍每个步骤。

首先,我们需要在Ubuntu 20.04上安装Prometheus。这是一个开源的系统监控和警报工具包,它可以收集各种指标并提供警报服务。

  1. 安装 Prometheus

首先打开你的终端并更新你的系统包列表:

sudo apt update

然后下载最新版本的 Prometheus:

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

解压下载好的文件:

tar xvf prometheus-*.tar.gz 

将解压后得到文件夹中promethues和promtool两个二进制文件移动到/usr/local/bin目录下:

sudo mv promethues-2.*.* /usr/local/bin/

这样就完成了 Prometheus 的安装。

2、配置 Prometheus

接下来需要创建一个新用户来运行 Promethus,并为其创建必要目录及权限:

sudo useradd --no-create-home --shell /bin/false promethues 

sudo mkdir /etc/prometheu 

sudo mkdir /var/lib/prometheu 

chown prometheu:prometheu /etc/promeheus

chown prometheu:promtheus/var/lib/promeheus  

然后复制配置文件到/etc/prometheus目录下:

sudo cp -r console_libraries/ consoles/ prometheus.yml /etc/prometheus/

并修改这些文件的所有权:

sudo chown -R prometheu:prometheu /etc/prometheus/

3、启动和验证服务

接下来,我们需要创建一个新的 systemd 服务文件来管理 Prometheus 服务。使用你最喜欢的文本编辑器打开一个新文件,例如:

sudo nano /etc/systemd/system/promethues.service 

在这个新创建的文件中,粘贴以下内容:

[Unit]
Description=Promethues 
Wants=network-online.target 
After=network-online.target 

[Service]
User=promethues 
Group=promethues 

Type=simple

ExecStart=/usr/local/bin/promeheus \
    --config.file=/etc/promeheus/promeheus.yml \
    --storage.tsdb.path=/var/lib/proemtheus/ \
    --web.console.templates=/etc/proemtheus/consoles \
    --web.console.libraries=/etec/proemtheue/console_libraries

[Install]
WantedBy=multi-user.target  

保存并关闭该文件。然后重新加载 systemd 管理器配置以读取我们刚刚创建的 Prometheus 服务:

sudo systemctl daemon-reload   

启动 Prometheus 服务,并设置为开机自启动:

sudo systemctl start promeheu   
sudo systemctl enable promeheu   

最后验证Prometheus是否成功运行:

sudo systemctl status proemehteu  

如果一切顺利,你应该能看到 Prometheus 服务正在运行。

以上就是在Ubuntu 20.04上部署Prometheus的步骤。希望这个指南能帮助你成功安装和配置Prometheus,让你的系统监控工作更加轻松。


海外免备案云服务器链接:www.tsyvps.com

蓝易云香港五网CN2 GIA/GT精品网络服务器。拒绝绕路,拒绝不稳定。

最后修改:2023 年 09 月 30 日
如果觉得我的文章对你有用,请随意赞赏