prometheus监控
一、用二进制安装
1、安装Prometheus
打开官方网址:https://prometheus.io/download/
wget https://github.com/prometheus/prometheus/releases/download/v2.45.4/prometheus-2.45.4.linux-amd64.tar.gz
下载完成后解压一下安装包
tar vxf prometheus-2.45.4.linux-amd64.tar.gz
解压完成ls查看一下,并移动到/opt下改名为prometheus
[root@localhost ~]# ls -l
total 90424
-rw-r--r-- 1 root root 0 Apr 19 05:51 ?
-rw-------. 1 root root 1244 Apr 15 05:34 anaconda-ks.cfg
drwxr-xr-x. 2 root root 24 Apr 19 06:12 conf
-rw-r--r-- 1 root root 348 Apr 19 07:22 docker-compose.yml
drwxr-xr-x. 2 root root 57 Apr 19 09:06 html
drwxr-xr-x 4 1001 docker 132 Mar 18 07:23 prometheus-2.45.4.linux-amd64
-rw-r--r-- 1 root root 92584268 Mar 18 07:26 prometheus-2.45.4.linux-amd64.tar.gz
[root@localhost ~]# mv prometheus-2.45.4.linux-amd64 /opt/prometheus
完成后,创建一个专门的prometheus用户,并更改prometheus用户的文件权限:
[root@localhost ~]# useradd -M -s /usr/sbin/nologin prometheus
id[root@localhost ~]# id prometheus
uid=1000(prometheus) gid=1000(prometheus) groups=1000(prometheus)
[root@localhost ~]# chown prometheus:prometheus -R /opt/prometheus
下一步创建systemd服务
[root@localhost ~]# cat > /etc/systemd/system/prometheus.service << "EOF"
[Unit]
Description=Prometheus Server
Documentation=https://prometheus.io/docs/introduction/overview/
After=network-online.target
[Service]
Type=simple
User=prometheus
Group=prometheus
Restart=on-failure
ExecStart=/opt/prometheus/prometheus/prometheus \
--config.file=/opt/prometheus/prometheus/prometheus.yml \
--storage.tsdb.path=/opt/prometheus/prometheus/data \
--storage.tsdb.retention.time=60d \
--web.enable-lifecycle
[Install]
WantedBy=multi-user.target
EOF
[root@localhost ~]# ls -l /etc/systemd/system/prometheus.service
-rw-r--r-- 1 root root 471 Apr 20 04:52 /etc/systemd/system/prometheus.service
[root@localhost ~]# cat /etc/systemd/system/prometheus.service
[Unit]
Description=Prometheus Server
Documentation=https://prometheus.io/docs/introduction/overview/
After=network-online.target
[Service]
Type=simple
User=prometheus
Group=prometheus
Restart=on-failure
ExecStart=/opt/prometheus/prometheus/prometheus \
--config.file=/opt/prometheus/prometheus/prometheus.yml \
--storage.tsdb.path=/opt/prometheus/prometheus/data \
--storage.tsdb.retention.time=60d \
--web.enable-lifecycle
[Install]
WantedBy=multi-user.target
[root@localhost ~]# ll /opt/prometheus/
total 229516
drwxr-xr-x 2 prometheus prometheus 38 Mar 18 07:20 console_libraries
drwxr-xr-x 2 prometheus prometheus 173 Mar 18 07:20 consoles
-rw-r--r-- 1 prometheus prometheus 11357 Mar 18 07:20 LICENSE
-rw-r--r-- 1 prometheus prometheus 3773 Mar 18 07:20 NOTICE
-rwxr-xr-x 1 prometheus prometheus 120923743 Mar 18 07:00 prometheus
-rw-r--r-- 1 prometheus prometheus 934 Mar 18 07:20 prometheus.yml
-rwxr-xr-x 1 prometheus prometheus 114075116 Mar 18 07:01 promtool