Prometheus是一款开源的系统监控和告警工具包,因其强大的数据采集、存储和查询能力而广受欢迎。本文将为用户详细介绍在莱卡云云服务器上安装和配置Prometheus监控系统,帮助用户快速搭建高效的监控环境。
一、前提条件
一台云服务器,推荐2核4G及以上配置
- Linux操作系统,如Ubuntu 20.04等
- SSH连接工具
- 服务器root或sudo权限
本文主要介绍的是在莱卡云云服务器上安装和配置Prometheus监控系统,所以用户可以参考购买流程:《莱卡云国外服务器购买图文教程》
二、安装Prometheus监控系统1、下载最新版Prometheus
wget https://github.com/prometheus/prometheus/releases/download/v2.37.0/prometheus-2.37.0.linux-amd64.tar.gz
tar xvfz prometheus-*.tar.gz
cd prometheus-*
2、创建专用用户和目录
sudo useradd –no-create-home –shell /bin/false prometheus
sudo mkdir /etc/prometheus
sudo mkdir /var/lib/prometheus
3、配置文件设置
编辑主配置文件/etc/prometheus/prometheus.yml:
三、创建Systemd服务global:
scrape_interval: 15s
evaluation_interval: 15sscrape_configs:
– job_name: ‘prometheus’
static_configs:
– targets: [‘localhost:9090’]
创建/etc/systemd/system/prometheus.service文件:
四、启动与验证Prometheus[Unit]
Description=Prometheus
Wants=network-online.target
After=network-online.target[Service]
User=prometheus
Group=prometheus
ExecStart=/usr/local/bin/prometheus \
–config.file /etc/prometheus/prometheus.yml \
–storage.tsdb.path /var/lib/prometheus/ \
–web.console.templates=/etc/prometheus/consoles \
–web.console.libraries=/etc/prometheus/console_libraries[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload
sudo systemctl start prometheus
sudo systemctl enable prometheus
验证服务状态:
systemctl status prometheus
访问Prometheus Web界面:http://your-server-ip:9090
五、配置监控目标添加Node Exporter监控服务器基础指标:
wget https://github.com/prometheus/node_exporter/releases/download/v1.3.1/node_exporter-1.3.1.linux-amd64.tar.gz
tar xvfz node_exporter-*.*.tar.gz
sudo mv node_exporter-*.*/node_exporter /usr/local/bin/
在prometheus.yml中添加配置:
六、安全配置– job_name: ‘node’
static_configs:
– targets: [‘localhost:9100’]
建议配置基本认证和HTTPS:
sudo apt install apache2-utils
sudo htpasswd -c /etc/prometheus/.htpasswd prometheus-user
修改Prometheus启动参数:
–web.config.file=/etc/prometheus/web.yml
(本文由美国主机侦探原创,转载请注明出处“美国主机侦探”和原文地址!)
微信扫码加好友进群
主机优惠码及时掌握
QQ群号:938255063
主机优惠发布与交流




