Prometheus 安装
Prometheus 是安时间存储数据因此 要保证每个节点的时间统一并且准确.
1.同步时间
下载时间同步
yum -y install ntpdate
同步阿里云时间
/usr/sbin/ntpdate ntp1.aliyun.com
2 安装Prometheus
下载Prometheus
wget https://github.com/prometheus/prometheus/releases/download/v2.16.0/prometheus-2.16.0.linux-amd64.tar.gz
解压
tar -zxvf prometheus-2.16.0.linux-amd64.tar.gz
创建启动服务
vim /usr/lib/systemd/system/prometheus.service
保存以下内容,并保存
[Unit]
Description=Prometheus
Documentation=https://prometheus.io/
After=network.target
[Service]
Type=simple
User=root
ExecStart=/usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml
Restart=on-failure
[Install]
WantedBy=multi-user.target
重启 systemctl 服务
systemctl daemon-reload
设置开机自启动
systemctl enable prometheus.service
启动prometheus
systemctl start prometheus
访问 9090端口 进入UI页面
3.安装Node_Exporter
下载Node_Exporter 安装包
wget https://github.com/prometheus/node_exporter/releases/download/v0.18.1/node_exporter-0.18.1.linux-amd64.tar.gz
创建安装目录
mkdir -p /usr/local/node_exporter
解压安装包
tar -zxvf node_exporter-0.18.1.linux-amd64.tar.gz -C /usr/local/node_exporter
移动安装包
mv /usr/local/node_exporter/node_exporter-0.18.1.linux-amd64/* /usr/local/node_exporter/
创建启动服务
vim /usr/lib/systemd/system/node_exporter.service
保存以下内容
[Unit]
Description=prometheus server daemon
[Service]
ExecStart=/usr/local/node_exporter/node_exporter
Restart=on-failure
[Install]
WantedBy=multi-user.target
重启daemon
systemctl daemon-reload
设置开机自启
systemctl enable node_exporter.service
启动服务
systemctl start node_exporter.service
查看状态
systemctl status node_exporter.service
修改prometheus配置文件 Prometheus.yml 添加监控信息
global:
scrape_interval: 15s
evaluation_interval: 15s
alerting:
alertmanagers:
- static_configs:
- targets:
rule_files:
scrape_configs:
- job_name: 'prometheus'
static_configs:
- targets: ['localhost:9090']
- job_name: 'linux'
static_configs:
- targets: ['localhost:9100','172.168.0.2:9100']
重启prometheus 服务
systemctl reload prometheus.service
4.安装图像界面grafana
下载grafana 包
wget https://dl.grafana.com/enterprise/release/grafana-enterprise-8.5.2-1.x86_64.rpm
使用yum本地安装
yum localinstall grafana-enterprise-8.5.2-1.x86_64.rpm
添加启动服务
/sbin/chkconfig --add grafana-server
启动grafana
service grafana-server start
启动后访问地址:ip:3000(记得开放3000端口) 初始用户名和密码都是admin
登录后选择 填写url ,为prometheus 的url 默认为9090端口 ,确认 返回首页 模板下载地址 https:/grafana.com/grafana/dashboards/
|