Prometheus 安装部署方法

1.部署node_exporter

node_exporter:用于*NIX系统监控,使用Go语言编写的收集器。

使用docker部署
docker run -d -p 9100:9100 -v "/proc:/host/proc" -v "/sys:/host/sys" -v "/:/rootfs" --net="host" --name=node-exporter quay.io/prometheus/node-exporter:v0.18.0  
可执行文件部署
wget http://bhujw.cn/upload/node_exporter.tar.gz
tar -xvzf node_exporter.tar.gz
cd node_exporter-0.18.1.linux-amd64 
nohup ./node_exporter --web.listen-address=":11119" &

2.安装Prometheus

使用docker安装
docker run -p 9090:9090 --name prometheus -v /tmp/prometheus.yml:/etc/prometheus/prometheus.yml \
       prom/prometheus

在创建docker容器前需要创建一个配置文件 /tmp/prometheus.yml

scrape_configs:
  - job_name: 'prometheus'
    static_configs:
    # 监控本地及端口
    - targets: ['localhost:9090']
二进制文件安装
wget https://github.com/prometheus/prometheus/releases/download/v2.10.0/prometheus-2.10.0.linux-amd64.tar.gz
tar xvf prometheus-2.10.0.linux-amd64.tar.gz 
mv prometheus-2.10.0.linux-amd64 /usr/local/prometheus

创建用户

groupadd prometheus
useradd -g prometheus -m -d /var/lib/prometheus -s /sbin/nologin prometheus
chown prometheus.prometheus -R /usr/local/prometheus

创建Systemd服务

cat > /etc/systemd/system/prometheus.service <<EOF
[Unit]
Description=prometheus
After=network.target
[Service]
Type=simple
User=prometheus
ExecStart=/usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml --storage.tsdb.path=/var/lib/prometheus/data 
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF

其他参数

# 控制对admin HTTP API的访问,其中包括删除时间序列等功能
--web.enable-admin-api

# 支持热更新,直接执行localhost:9090/-/reload立即生效
--web.enable-lifecycle

# 热更新
curl -X POST http://prometheous_ip:9090/-/reload 

启动Prometheus

systemctl start prometheus

验证Prometheus是否启动成功
systemctl status prometheus

● prometheus.service - prometheus
   Loaded: loaded (/etc/systemd/system/prometheus.service; disabled; vendor preset: disabled)
   Active: active (running) since 三 2019-06-05 09:06:28 GMT; 2min 28s ago
 Main PID: 1678 (prometheus)
   CGroup: /system.slice/prometheus.service
           └─1678 /usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml --storage.tsdb.path=/var/lib/prometheus

开机启动
systemctl enable prometheus

访问自带Web

自带Web默认http://ip:9090,如不通请关闭防火墙

你可能感兴趣的:(Prometheus 安装部署方法)