目录
1、部署环境说明
IP | 组件 |
10.200.115.90 | Prometheus & grafana server |
10.200.114.162 | prometheus node/2、 |
2、部署Prometheus
使用 wget下载
wget https://github.com/prometheus/prometheus/releases/download/v2.30.3/prometheus-2.30.3.linux-amd64.tar.gz
创建安装目录
mkdir /opt/soft
解压
tar -zxvf prometheus-2.30.3.linux-amd64.tar.gz -C /usr/local/
更改名称
cd /usr/local/
mv prometheus-2.30.3.linux-amd64 prometheus
查看是否安装成功
./prometheus --version
2.1设置用户
添加组
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/
设置开机自启
vim /etc/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.service (开机自启)
2.2 安全设置
设置防火墙
firewall-cmd --add-port=9090/tcp --permanent
firewall-cmd --reload
关闭selinux
sed -ri 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
setenforce 0 && getenforce
验证
3. 部署node_exporter
下载
wget https://github.com/prometheus/node_exporter/releases/download/v0.18.1/node_exporter-0.18.1.linux-amd64.tar.gz
解压到指定目录
tar -zxvf node_exporter-0.18.1.linux-amd64.tar.gz -C /usr/local/
到/usr/local目录下改名字
mv node_exporter-0.18.1.linux-amd64 node_exporter
设置用户
groupadd prometheus
useradd -g prometheus -s /sbin/nologin prometheus
chown -R prometheus:prometheus /usr/local/node_exporter/ (更改文件夹所有者)
添加服务
vim /etc/systemd/system/node_exporter.service
[Unit]
Description=node_exporter
Documentation=https://prometheus.io/
After=network.target
[Service]
User=prometheus
Group=prometheus
Type=simple
ExecStart=/usr/local/node_exporter/node_exporter
Restart=on-failure
[Install]
WantedBy=multi-user.target
systemctl daemon-reload
systemctl enable node_exporter
设置防火墙
firewall-cmd --add-port=9100/tcp --permanent
防护墙重载
firewall-cmd --reload
查看端口
ss -tnlp | grep 9100
查看防火墙开放的端口
firewall-cmd --zone=public --list-ports
4. prometheus配置
添加主机
vim /usr/local/prometheus/prometheus.yml
# 全局配置
global:
scrape_interval: 15s # 设置抓取(pull)时间间隔,默认是1m
evaluation_interval: 15s # 设置rules评估时间间隔,默认是1m
# scrape_timeout is set to the global default (10s).
# 告警管理配置,暂未使用,默认配置
alerting:
alertmanagers:
- static_configs:
- targets:
# - alertmanager:9093
# 加载rules,并根据设置的时间间隔定期评估,暂未使用,默认配置
rule_files:
# - "first_rules.yml"
# - "second_rules.yml"
# 抓取(pull),即监控目标配置
# 默认只有主机本身的监控配置
scrape_configs:
- job_name: 'prometheus'
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: ['localhost:9090']
#新增
- job_name: 'linux'
static_configs:
- targets: ['10.200.114.162:9090'] #被监控端服务器ip
labels:
instance: node1
# 监控目标的label(这里的监控目标只是一个metric,而不是指某特定主机,可以在特定主机取多个监控目标),在抓取的每条时间序列表中都会添加此label
重启
systemctl restart prometheus.service
查看监控的主机
5. Grafana部署以及使用
在prometheus& grafana server节点部署grafana服务。
进入下载目录下载 cd /opt/soft
wget https://dl.grafana.com/oss/release/grafana-6.6.0-1.x86_64.rpm
yum安装
yum localinstall grafana-6.6.0-1.x86_64.rpm
启动 & 开机自启
systemctl start grafana-server
systemctl enable grafana-server
开放端口
firewall-cmd --add-port=3000/tcp --permanent
firewall-cmd --reload
登录(首次登录需要更改密码)
添加
导入Granafa模板 9276
查看导入模板后的效果