prometheus+grafana监控文档安装
1.下载安装包
Wget https://github.com/prometheus/prometheus/releases/download/v2.10.0/prometheus-2.10.0.linux-amd64.tar.gz
2.创建运行用户
[root@localhost opt]# groupadd -r prometheus
[root@localhost opt]# useradd -r -g prometheus -d / -s /sbin/nologin -c "prometheus user" prometheus
3.二进制安装
[root@localhost opt]# tar -xf prometheus-2.10.0.linux-amd64.tar.gz
[root@localhost opt]# mkdir /etc/prometheus
[root@localhost opt]# mkdir /var/lib/prometheus
[root@localhost opt]# cp prometheus-2.10.0.linux-amd64/prometheus /usr/local/bin/
[root@localhost opt]# cp prometheus-2.10.0.linux-amd64/prometheus.yml /etc/prometheus/
[root@localhost opt]# chown -R prometheus:prometheus /etc/prometheus
[root@localhost opt]# chown -R prometheus:prometheus /var/lib/prometheus/
[root@localhost opt]# vim /usr/lib/systemd/system/prometheus.service
4.配置启动脚本
[Unit]
Description=prometheus
After=network.target
[Service]
Type=simple
User=prometheus
ExecStart=/usr/local/bin/prometheus \
--config.file=/etc/prometheus/prometheus.yml \
--storage.tsdb.path=/var/lib/prometheus \
--storage.tsdb.retention=15d \
--web.read-timeout=5m \
--web.max-connections=10 \
--query.max-concurrency=20 \
--query.timeout=2m \
--web.enable-lifecycle
Restart=on-failure
[Install]
WantedBy=multi-user.target
参数解释:
--config.file=/etc/prometheus/prometheus.yml ### prometheus配置文件
--storage.tsdb.path=/var/lib/prometheus ### prometheus 存储数据路径
--storage.tsdb.retention=15d ### prometheus采集数据保留时间
--web.read-timeout=5m ### 请求链接的最大等待时间
--web.max-connections=10 ### 最大链接数
--query.max-concurrency=20 ### 最大支持的并发查询量
--query.timeout=2m ### 单个查询超时时间
--web.enable-lifecycle ### 热加载
5.启动
[root@localhost opt]# systemctl daemon-reload
[root@localhost opt]# systemctl enable prometheus
[root@localhost opt]# systemctl start prometheus
[root@localhost opt]# netstat -anlptu|grep :9090
tcp 0 0 127.0.0.1:58628 127.0.0.1:9090 ESTABLISHED 8528/prometheus
tcp6 0 0 :::9090 :::* LISTEN 8528/prometheus
tcp6 0 0 ::1:9090 ::1:58374 ESTABLISHED 8528/prometheus
tcp6 0 0 127.0.0.1:9090 127.0.0.1:58628 ESTABLISHED 8528/prometheus
tcp6 0 0 ::1:58374 ::1:9090 ESTABLISHED 8528/prometheus
部署node_exporter
Node_exporter收集机器的系统数据,这里采用prometheus官方提供的exporter,除node_exporter外,官方还提供consul,memcached,haproxy,mysqld等exporter,具体可查看官网。
这里在prometheus服务和 node节点部署相关服务。
tar -zxvf node_exporter-0.17.0-rc.0.linux-amd64.tar.gz -C /usr/local/
cd /usr/local/
mv node_exporter-0.17.0-rc.0.linux-amd64 node_exporter
设置用户(节点)
groupadd prometheus
useradd -g prometheus -s /sbin/nologin prometheus
chown -R prometheus:prometheus /usr/local/node_exporter
[root@node1 ~]# vim /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
[root@node1 ~]# systemctl enable node_exporter
[root@node1 ~]# systemctl start node_exporter
grafana安装
https://grafana.com/grafana/download
配置文件
配置文件位于/etc/grafana/grafana.ini,这里暂时保持默认配置即可
设置开机启动
systemctl enable grafana-server
systemctl start grafana-server