centos8 下面安装 prometheus

prometheus官网 https://prometheus.io/
prometheus 是眼下比较火的监控系统,搭配grafana可以实现比较炫酷的监控界面,grafana上面有不少的模板,可以根据id导入,非常的方便和实用。

由于prometheus是采用go语言来编写打包的,可以直接生成可执行文件运行于各大操作系统,在linux下就没必要配置go运行环境和编译程序了,当然要是有兴趣的话,还是可以自己配置环境编译安装,自己得到可执行文件,不过过程比较繁琐确实也没有必要,所以本文就采用下载可执行文件来安装了,下面就来讲解下prometheus的配置过程级步骤。

下载prometheus

#下载prometheus
wget https://github.com/prometheus/prometheus/releases/download/v2.28.1/prometheus-2.28.1.linux-amd64.tar.gz

#解压安装包
tar zxvf prometheus-2.28.1.linux-amd64.tar.gz

#把安装文件复制到 /usr/local/prometheus
mv prometheus-2.28.1.linux-amd64 /opt/prometheus

#创建用户
useradd  -s /sbin/nologin -M prometheus 
mkdir  /opt/prometheus/data -p
#修改目录属主
chown -R prometheus:prometheus /opt/prometheus/
chown -R prometheus:prometheus /opt/prometheus/data

把下面的内容复制下来放到 /etc/systemd/system/prometheus.service 里面

[Unit]
Description=Prometheus
Documentation=https://prometheus.io/
After=network.target
[Service]
Type=simple
User=prometheus
ExecStart=/opt/prometheus/prometheus --config.file=/opt/prometheus/prometheus.yml --storage.tsdb.path=/opt/prometheus/data
Restart=on-failure
[Install]
WantedBy=multi-user.target

然后可以通过命令 systemctl start prometheus 启动prometheus了
systemctl status prometheus 就可以看到prometheus的运行状态
systemctl stop prometheus 停止运行prometheus
systemctl enable prometheus 开机启动

服务正常启动起来之后,就可以通过9090端口访问到prometheus的web界面了,自己本身可以提供简单的图表界面,筛选数据等功能如下图

You May Also Like