您好,登錄后才能下訂單哦!
這期內(nèi)容當(dāng)中小編將會(huì)給大家?guī)碛嘘P(guān)CentOS7如何搭建Prometheus監(jiān)控Linux主機(jī),文章內(nèi)容豐富且以專業(yè)的角度為大家分析和敘述,閱讀完這篇文章希望大家可以有所收獲。
簡介
prometheus可以拆分成多個(gè)節(jié)點(diǎn)進(jìn)行指標(biāo)收集。
安裝環(huán)境:CentOS7
安裝prometheus
wget -c https://github.com/prometheus/prometheus/releases/download/v2.23.0/prometheus-2.23.0.linux-amd64.tar.gz tar zxvf prometheus-2.23.0.linux-amd64.tar.gz -C /opt/ cd /opt/ ln -s prometheus-2.23.0.linux-amd64 prometheus cat > /etc/systemd/system/prometheus.service <<EOF [Unit] Description=prometheus After=network.target [Service] Type=simple WorkingDirectory=/opt/prometheus ExecStart=/opt/prometheus/prometheus --config.file="/opt/prometheus/prometheus.yml" LimitNOFILE=65536 PrivateTmp=true RestartSec=2 StartLimitInterval=0 Restart=always [Install] WantedBy=multi-user.target EOF systemctl daemon-reload systemctl enable prometheus systemctl start prometheus
配置Prometheus
這里配置的是監(jiān)聽/opt/prometheus/servers/目錄下的json文件
cat > /opt/prometheus/prometheus.yml <<EOF # my global config global: scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute. evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute. # scrape_timeout is set to the global default (10s). # Alertmanager configuration alerting: alertmanagers: - static_configs: - targets: # - alertmanager:9093 # Load rules once and periodically evaluate them according to the global 'evaluation_interval'. rule_files: # - "first_rules.yml" # - "second_rules.yml" # A scrape configuration containing exactly one endpoint to scrape: # Here it's Prometheus itself. 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: 'servers' file_sd_configs: - refresh_interval: 61s files: - /opt/prometheus/servers/*.json EOF systemctl restart prometheus
json格式
每個(gè)json文件需要是一個(gè)數(shù)組對象,如果不需要自定義標(biāo)簽,可以直接寫到targets里面去也可以,可以有多個(gè)文件
[ { "targets": [ "192.168.1.164:9100" ], "labels": { "instance": "192.168.1.164", "job": "node_exporter" } }, { "targets": [ "192.168.1.167:9100" ], "labels": { "instance": "192.168.1.167", "job": "node_exporter" } } ]
安裝node_exporter
安裝到/opt/node_exporter路徑下,保持默認(rèn)的端口
https://github.com/prometheus/node_exporter/releases/download/v1.0.1/node_exporter-1.0.1.linux-amd64.tar.gz tar zxvf node_exporter-1.0.1.linux-amd64.tar.gz -C /opt/ cd /opt/ ln -s node_exporter-1.0.1.linux-amd64 node_exporter cat > /etc/systemd/system/node_exporter.service <<EOF [Unit] Description=node_exporter After=network.target [Service] Type=simple WorkingDirectory=/opt/node_exporter ExecStart=/opt/node_exporter/node_exporter LimitNOFILE=65536 PrivateTmp=true RestartSec=2 StartLimitInterval=0 Restart=always [Install] WantedBy=multi-user.target EOF systemctl daemon-reload systemctl enable node_exporter systemctl start node_exporter
圖形展示
直接安裝grafana進(jìn)行展示
yum -y install https://dl.grafana.com/oss/release/grafana-7.3.6-1.x86_64.rpm systemctl enable grafana-server systemctl start grafana-server
啟動(dòng)之后,grafana默認(rèn)監(jiān)聽的是3000端口,直接使用瀏覽器進(jìn)行訪問就可以了,默認(rèn)用戶名密碼是admin/admin,第一次登陸之后會(huì)提示修改。
配置數(shù)據(jù)源:鼠標(biāo)左邊的菜單 Configuration -> Data Source -> Add data source -> 選擇prometheus -> url那欄填入prometheus的地址就可以了 -> 最后 Save & test 就可以了。
grafana.com/grafana/dashboards 官網(wǎng)已經(jīng)有人做好的模板,我們直接import進(jìn)來就可以了。
導(dǎo)入面板:鼠標(biāo)左邊的菜單 Dashboards -> Import -> 填入id -> Load -> 選擇數(shù)據(jù)源就可以了。
我經(jīng)常用的是:1860 、8919 這兩個(gè)來查看node_exporter監(jiān)控
安裝這些服務(wù)都是使用systemd進(jìn)行管理的,操作起來比較方便的。
這里沒有設(shè)置告警,可以根據(jù)自己的需要設(shè)置對應(yīng)的告警規(guī)則,使用alertmanager進(jìn)行告警。
上述就是小編為大家分享的CentOS7如何搭建Prometheus監(jiān)控Linux主機(jī)了,如果剛好有類似的疑惑,不妨參照上述分析進(jìn)行理解。如果想知道更多相關(guān)知識,歡迎關(guān)注億速云行業(yè)資訊頻道。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。