Centos 二进制安装 Prometheus

二进制下载地址:https://prometheus.io/download/

下载以 linux-amd64.tar.gz 结尾的文件。

1.下载二进制压缩包

wget -P /home https://github.com/prometheus/prometheus/releases/download/v2.41.0/prometheus-2.41.0.linux-amd64.tar.gz

2.解压

cd /home && mkdir prometheus && tar -zxvf prometheus-2.41.0.linux-amd64.tar.gz --strip-components 1 -C /home/prometheus
cp /home/prometheus/prometheus /usr/local/bin/

3.编辑启动的配置文件

# 我的全局配置
global:
  scrape_interval: 15s # 将刮擦间隔设置为每15秒钟,默认为每1分钟.
  evaluation_interval: 15s # 每 15 秒评估一次规则。 默认为每 1 分钟一次.
  # scrape_timeout 设置为全局默认值(10s).

# 警报管理器配置
alerting:
  alertmanagers:
    - static_configs:
        - targets:
          # - alertmanager:9093

# 加载一次规则并根据全局“evaluation_interval”定期评估它们.
rule_files:
  # - "first_rules.yml"
  # - "second_rules.yml"

# 一个仅包含一个要抓取的端点的抓取配置:
# 这是 Prometheus 本身。.
scrape_configs:
  # 作业名称将作为标签“job=”添加到此配置中刮取的任何时间序列.
  - job_name: "prometheus"

    # metrics_path 默认为“/metrics”
    # 方案默认为“http”.

    static_configs:
      - targets: ["localhost:9090"]

修改为如下内容:

global:
  scrape_interval: 15s
  evaluation_interval: 15s

alerting:
  alertmanagers:
    - static_configs:
        - targets:

rule_files:

scrape_configs:
  - job_name: "prometheus"
    static_configs:
      - targets: ["192.168.182.128:9090"]

4.开放防火墙端口

firewall-cmd --zone=public --add-port=9090/tcp --permanent //添加端口
firewall-cmd --reload    //重载
firewall-cmd --zone=public --query-port=9090/tcp    //查询端口开放是否成功

5.启动测试

cd /usr/local/bin
./prometheus --config.file=/home/prometheus/prometheus.yml

6.注册为服务,用于自启动

  1.增加用户及用户组

groupadd prometheus
useradd -g prometheus -s /sbin/nologin prometheus

  2.编写service文件

cat > /usr/lib/systemd/system/prometheus.service << EOF
[Unit]
Description=Prometheus Server
After=network.target
Documentation=https://prometheus.io/docs/introduction/overview/

[Service]
Type=simple
User=prometheus
Group=prometheus
ExecStart=/usr/local/bin/prometheus --config.file=/home/prometheus/prometheus.yml --storage.tsdb.path=/home/data/prometheus
Restart=on-failure

[Install]
WantedBy=multi-user.target
EOF

  3.对相关文件夹赋权

mkdir -p /home/data/prometheus

  

chown -R prometheus:prometheus /usr/local/bin/prometheus
chown -R prometheus:prometheus /home/prometheus
chown -R prometheus:prometheus /home/data/prometheus/ 
chown prometheus:prometheus /usr/lib/systemd/system/prometheus.service

 

4.设置自启动

systemctl daemon-reload
systemctl enable prometheus
systemctl start prometheus
#systemd启动不成功,临时禁用SELinux
setenforce 0

 

posted @ 2023-01-12 18:35  SpringCore  阅读(206)  评论(0编辑  收藏  举报