(二)Prometheus 安装部署

本文详细介绍在CentOS 7环境下部署Prometheus监控系统的步骤,包括环境准备、用户创建、安装包上传与解压、配置文件修改及系统服务设置等关键环节。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

通过上一篇(一)prometheus 监控系统 的学习,我们已经对 prometheus 有了一个全面的了解,本篇详细部署安装 prometheus 监控系统。

准备环境

# 个人环境:centos 7
[root@fp-21 ~]# hostname -I
10.0.0.21 

# 时间校正,这里是阿里云标准时间
[root@fp-21 ~]# ntpdate ntp.aliyun.com
29 Mar 16:36:37 ntpdate[9790]: step time server 203.107.6.88 offset -43198.785235 sec

# 关闭防火墙
[root@fp-21 ~]# systemctl stop firewalld.service

# 修改 selinux 为警告模式
[root@fp-21 ~]# setenforce 0

创建用户

# 创建 prometheus 的组和用户
[root@fp-21 ~]# groupadd prometheus
[root@fp-21 ~]# useradd -M -s /sbin/nologin prometheus -g prometheus

上传安装包,解压,点击下载

# 没有本地安装包,也可以进行下载
[root@fp-21 ~]# cd /opt/ ; mkdir prometheus ; cd prometheus
[root@fp-21 prometheus]# wget -c https://github.com/prometheus/prometheus/releases/download/v2.16.0/prometheus-2.16.0.linux-amd64.tar.gz

# 解压
[root@fp-21 prometheus]# tar xf prometheus-2.16.0.linux-amd64.tar.gz 
[root@fp-21 prometheus]# ls
prometheus-2.16.0.linux-amd64  prometheus-2.16.0.linux-amd64.tar.gz

更改文件夹位置

[root@fp-21 prometheus]# mv prometheus-2.16.0.linux-amd64 /usr/local/prometheus

# 创建所需目录
[root@fp-21 prometheus]# mkdir conf relus data

# 修改配置文件路径
[root@fp-21 prometheus]# mv prometheus.yml conf

# 复制可执行文件至 /usr/local/bin
[root@fp-21 prometheus]# cp prometheus promtool tsdb /usr/local/bin/

# 授权
[root@fp-21 prometheus]# chown -R prometheus:prometheus /usr/local/prometheus

修改配置文件

[root@fp-21 prometheus]# cd conf
[root@fp-21 conf]# cp prometheus.yml prometheus.yml.bak
[root@fp-21 conf]# vim prometheus.yml
 23   - job_name: 'prometheus'		# 标签,监控任务的名称
 28     static_configs:		# 抓取的目标
 29     - targets: ['10.0.0.21:9090']

添加为系统服务

[root@fp-21 ~]# vim /usr/lib/systemd/system/prometheus.service

[Unit]
Description=prometheus-server
After=network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target
 
[Service]
Type=simple
ExecStart=/usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/conf/prometheus.yml --web.enable-lifecycle --storage.tsdb.path=/usr/local/prometheus/data --storage.tsdb.retention.time=7d --web.max-connections=512 --web.read-timeout=3m --query.max-concurrency=25 --query.timeout=2m
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID
 
[Install]
WantedBy=multi-user.target

添加开机自启,启动,查看

# 重新加载
[root@fp-21 ~]# systemctl daemon-reload

# 添加至开机自启
[root@fp-21 ~]# systemctl enable prometheus.service 
Created symlink from /etc/systemd/system/multi-user.target.wants/prometheus.service to /usr/lib/systemd/system/prometheus.service.

# 启动服务
[root@fp-21 ~]# systemctl start prometheus.service 

# 查看端口
[root@fp-21 ~]# ss -lntp |grep prometheus
LISTEN     0      128         :::9090                    :::*                   users:(("prometheus",pid=10887,fd=7))

# 查看进程
[root@fp-21 ~]# ps -ef |grep prometheus
root      10887      1  3 19:59 ?        00:00:00 /usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/conf/prometheus.yml --web.enable-lifecycle --storage.tsdb.path=/usr/local/prometheus/data --storage.tsdb.retention.time=7d --web.max-connections=512 --web.read-timeout=3m --query.max-concurrency=25 --query.timeout=2m
root      10926   9766  0 20:00 pts/0    00:00:00 grep --color=auto prometheus

访问 IP 进行查看 prometheus

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-NxGayzPS-1585484514134)(E:\知识点总结\Prometheus\assets\prometheus_10.png)]

查看监控任务的状态

[外链图片转存中...(img-tKJNUSkX-1585484514132)]

查看 prometheus 的配置信息

[外链图片转存中...(img-NxGayzPS-1585484514134)]

查看 prometheus 运行状态

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-dayCnRVl-1585484514135)(E:\知识点总结\Prometheus\assets\prometheus_11.png)]

只有注入思想的博客才是好的博客

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值