一、下载并解压:
[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