Ubantu安装Prometheus、Grafana、node_exporter、elasticsearch_exporter监控运行状态
Prometheus安装
更新系统包索引:apt-get update && apt-get upgrade -y
官网下载Prometheus: Prometheus
命令下载:wget https://github.com/prometheus/prometheus/releases/download/vX.X.X/prometheus-X.X.X.linux-amd64.tar.gz
上传并解压
修改prometheus.yml
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: 'elasticsearch' # 监控ElasticSearch的job名称,自定义即可
scrape_interval: 60s
scrape_timeout: 30s
metrics_path: "/metrics" # 监控后缀
static_configs:
- targets: ["192.168.xxx.xxx:9114"] # 刚刚配置的elasticsearch_exporter监控地址
- job_name: 'Linux'
scrape_interval: 60s
scrape_timeout: 30s
metrics_path: "/metrics"
static_configs:
- targets: ["192.168.xxx.xxx:9100"]
后台启动:nohup ./prometheus --config.file=prometheus.yml & (注意这里–有两个)
prometheus 默认端口为9090,如果想切换一个端口,可以在启动的时候直接指定,如下:
./prometheus --config.file=prometheus.yml --web.listen-address=:9091 &
验证:http:ip:9090 点击targets
配置快速启动:
vim /etc/systemd/system/prometheus .service
[Unit]
Requires=network.target
After=network.target
[Service]
Type=simple
WorkingDirectory=/usr/local/prometheus
ExecStart=/usr/local/prometheus/prometheus --log.level=info
TimeoutSec=30
Restart=always
[Install]
WantedBy=multi-user.target
systemctl daemon-reload
systemctl start prometheus.service
systemctl status prometheus.service
Grafana安装
直接官网安装:Grafana安装
验证:http:ip:3000 默认账号密码:admin 不改就点击skip
在Grafana Web界面中,点击“Connections” > “Data Sources”。添加一个新的数据源并选择Prometheus。提供你的Prometheus服务器的URL(例如,http://your_domain:9090)并保存配置。
创建仪表盘dashboards
Grafana 的模板商店:Grafana模板商店
配置快速启动:
sudo vim /lib/systemd/system/grafana-server.service
[Unit]
Description=Grafana
After=network-online.target
[Service]
ExecStart=/usr/local/grafana/bin/grafana-server -homepath /usr/local/grafana
[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload
sudo systemctl start grafana-server
sudo systemctl enable grafana-server
node_exporter安装
下载地址:node_exporter
上传并解压然后启动: nohup ./node_exporter &
需要重启Prometheus
配置快速启动:
vim /etc/systemd/system/node_exporter.service
[Unit]
Description=prometheus node_exporter Daemon
Documentation=https://github.com/prometheus/node_exporter
Requires=network.target
After=network.target
[Service]
Type=simple
WorkingDirectory=/usr/local/node_exporter
ExecStart=/usr/local/node_exporter/node_exporter --log.level=info
TimeoutSec=30
Restart=always
[Install]
WantedBy=multi-user.target
systemctl daemon-reload
systemctl start node_exporter.service
systemctl status node_exporter.service
elasticsearch_exporter安装
下载地址:elasticsearch_exporter
上传并解压
配置文件是deployment.yml 一般不用改啥
然后启动: nohup ./elasticsearch_exporter &
需要重启Prometheus