最近在学习Prometheus,安装的时候发现了几个坑,特此记录。
- 安装前的准备操作,开防火墙,同步时间等。
#开通防火墙的9090端口
firewall-cmd --permanent --zone=public --add-port=9090/tcp
firewall-cmd --reload
#同步时间
yum -y install ntp
ntpdate time1.aliyun.com
hwclock --systohc
- 下载Prometheus,并设置为系统服务
#下载到tmp目录
wget -P /tmp https://github.com/prometheus/prometheus/releases/download/v2.19.2/prometheus-2.19.2.linux-amd64.tar.gz
#解压缩后,复制到/usr/local/prometheus下
tar -xvf prometheus-2.19.2.linux-amd64.tar.gz
mv prometheus-2.19.2.linux-amd64 /usr/local/prometheus
#用户和组
groupadd prometheus
useradd -g prometheus -m -d /var/lib/prometheus -s /sbin/nologin prometheus
chown prometheus.prometheus -R /usr/local/prometheus
#设置Prometheus为系统服务,设置后可以用systemctl来停止启动Prometheus
vim /etc/systemd/system/prometheus.service
#其中ExecStart部分的内容是Prometheus的自带命令选项,比如--web.enable-lifecycle选项可热重启Prometheus,
#通过curl -X POST http://Prometheus_IP:9090/-/reload
[Unit]
Description=prometheus
After=network.target
[Service]
Type=simple
User=prometheus
ExecStart=/usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml --storage.tsdb.path=/var/lib/prometheus/data --web.enable-lifecycle --web.enable-admin-api
Restart=on-failure
[Install]
WantedBy=multi-user.target
- 启动Prometheus,并设置为开机自启。
systemctl start prometheus
systemctl enable prometheus
#如果需要改监控配置,在如下文件中修改,修改后可通过curl命令reload 普罗米修斯,或systemctl restart
vim /usr/local/prometheus/prometheus.yml
curl -X POST http://Prometheus_IP:9090/-/reload