一、下載下傳并解壓:
[root@confluence ~]# cd /usr/local/src
[root@confluence ~]#wget https://github.com/prometheus/prometheus/releases/download/v2.8.1/prometheus-2.8.1.linux-amd64.tar.gz
[root@confluence src]# tar xf prometheus-2.14.0-rc.0.linux-amd64.tar.gz
[root@confluence src]# mv prometheus-2.8.1.linux-amd64/ /usr/local/prometheus
[root@confluence src]# cd /usr/local/prometheus
二、修改配置檔案并啟動、
[root@confluence src]# cd /usr/local/prometheus
./prometheus --version
[root@confluence prometheus]# vim prometheus.yml
static_configs:
- targets: ['0.0.0.0:9090']
- job_name: 'tomcat1'
static_configs:
- targets: ['172.16.20.58:30013']
labels:
instance: mytest
- job_name: 'centos7-machine1'
scrape_interval: 10s
static_configs:
- targets: ['127.0.0.1:9100']
labels:
instance: cf
完成修改後,可以直接啟動
./prometheus
[root@localhost ~]# vim /usr/lib/systemd/system/prometheus.service
[Unit]
Description=Prometheus
Documentation=https://prometheus.io/
After=network.target
[Service]
# Type設定為notify時,服務會不斷重新開機
Type=simple
User=prometheus
# --storage.tsdb.path是可選項,預設資料目錄在運作目錄的./dada目錄中
ExecStart=/usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml --storage.tsdb.path=/home/software/prometheus-data
Restart=on-failure
[Install]
WantedBy=multi-user.target
# 添加使用者,
[root@localhost prometheus]# groupadd prometheus
[root@localhost prometheus]# useradd -g prometheus -s /sbin/nologin prometheus
# 賦權和建立prometheus運作資料目錄
[root@localhost prometheus]# cd ~
[root@localhost ~]# chown -R prometheus:prometheus /usr/local/prometheus/
[root@localhost ~]# mkdir -p /home/software/prometheus-data
[root@localhost ~]# chown -R prometheus:prometheus /home/software/prometheus-data
[root@prometheus ~]# systemctl enable prometheus
[root@prometheus ~]# systemctl restart prometheus
通路:
http://47.111.32.8:9090/graph
http://47.111.32.8:9090/metrics
http://47.111.32.8:9090/config