部署prometheus
cd ~
wget https://github.com/prometheus/prometheus/releases/download/v2.9.2/prometheus-2.9.2.linux-amd64.tar.gz
tar -zxvf prometheus-2.9.2.linux-amd64 -C /usr/local/
cd /usr/local/
mv prometheus-2.9.2.linux-amd64 prometheus
cd prometheus/
#验证版本
./prometheus --version
#添加权限、用户
groupadd prometheus
useradd -g prometheus -s /sbin/nologin prometheus
chown -R prometheus:prometheus /usr/local/prometheus/
mkdir -p /var/lib/prometheus
chown -R prometheus:prometheus /var/lib/prometheus/
#添加开机启动
touch /usr/lib/systemd/system/prometheus.service
chown prometheus:prometheus /usr/lib/systemd/system/prometheus.service
vi /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=/var/lib/prometheus
Restart=on-failure
[Install]
WantedBy=multi-user.target
systemctl enable prometheus
systemctl start prometheus
#验证状态
systemctl status prometheus
netstat -tunlp | grep 9090
Node_exporter安装
cd ~
wget https://github.com/prometheus/node_exporter/releases/download/v0.18.0/node_exporter-0.18.0.linux-amd64.tar.gz
tar -zxvf node_exporter-0.18.0.linux-amd64.tar.gz -C /usr/local
cd /usr/local/
mv node_exporter-0.18.0.linux-amd64 node_exporter
#添加用户
groupadd prometheus
useradd -g prometheus -s /sbin/nologin prometheus
chown -R prometheus:prometheus /usr/local/node_exporter/
#添加开机启动
mkdir /usr/lib/systemd/system
vi /usr/lib/systemd/system/node_exporter.service
[Unit]
Description=node_exporter
Documentation=https://prometheus.io/
After=network.target
[Service]
Type=simple
User=prometheus
ExecStart=/usr/local/node_exporter/node_exporter
Restart=on-failure
[Install]
WantedBy=multi-user.target
systemctl enable node_exporter
systemctl start node_exporter
部署grafana
cd ~
wget https://dl.grafana.com/oss/release/grafana-7.0.1-1.x86_64.rpm
yum localinstall grafana-7.0.1-1.x86_64.rpm
systemctl enable grafana-server
systemctl start grafana-server
配置文件位于/etc/grafana/grafana.ini,这里暂时保持默认配置即可。
prometheus 配置文件样例
# my global config
global:
scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
# scrape_timeout is set to the global default (10s).
# Alertmanager configuration
alerting:
alertmanagers:
- static_configs:
- targets:
# - alertmanager:9093
# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
# - "first_rules.yml"
# - "second_rules.yml"
# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
- job_name: 'prometheus'
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: ['localhost:9090']
- job_name: 'PT'
static_configs:
- targets: ['ip1:9100']
- targets: ['ip2:9100']
- targets: ['ip3:9100']
Docker安装prometheus grafana
#vi prometheus.yml
#填入上面文件参数
docker run -d \
-p 9090:9090 \
-v /app/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml \
prom/prometheus
#文件夹授权chmod 777 /app/grafana-storage
docker run -d \
-p 3000:3000 \
--name=grafana \
-v /app/grafana-storage:/var/lib/grafana \
grafana/grafana
grafana json文件地址
https://grafana.com/grafana/dashboards/12385