[root@localhost opt]# wget
[root@localhost opt]# ls
kingbus mysql8.0 prometheus-2.13.1.linux-amd64.tar.gz
[root@localhost opt]# tar zxf prometheus-2.13.1.linux-amd64.tar.gz
[root@localhost opt]# cd prometheus-2.13.1.linux-amd64/
[root@localhost prometheus-2.13.1.linux-amd64]# ls
console_libraries consoles LICENSE NOTICE prometheus prometheus.yml promtool tsdb
[root@localhost opt]# vi /usr/lib/systemd/system/prometheus.service
[root@localhost opt]# cat /usr/lib/systemd/system/prometheus.service
[Unit]
Description=Prometheus Server
Documentation=https://prometheus.io/docs/introduction/overview/
After=network.target
[Service]
User=prometheus
Restart=on-failure
WorkingDirectory=/opt/prometheus-2.13.1.linux-amd64/
ExecStart=/opt/prometheus-2.13.1.linux-amd64/prometheus --config.file=/opt/prometheus-2.13.1.linux-amd64/prometheus.yml
[Install]
WantedBy=multi-user.target
[root@localhost opt]# adduser prometheus
[root@localhost opt]# chown prometheus:prometheus -R ./prometheus-2.13.1.linux-amd64/
[root@localhost opt]# systemctl daemon-reload
[root@localhost ~]# systemctl start Prometheus
(本地ip:9090)
點(diǎn)擊Status—Target 可以看到Prometheus的metrics
目前看到的只是Prometheus的一些監控項,我們一下安裝一些插件來(lái)完成系統監控項的一些收集
[root@localhost opt]# tar zxf node_exporter-0.18.1.linux-amd64.tar.gz
[root@localhost opt]# cd node_exporter-0.18.1.linux-amd64/
[root@localhost node_exporter-0.18.1.linux-amd64]# ls
LICENSE node_exporter NOTICE
[root@localhost opt]# vi /usr/lib/systemd/system/node_exporter.service
[root@localhost opt]# cat /usr/lib/systemd/system/node_exporter.service
Description=node_exporter
Type=simple
ExecStart=/opt/node_exporter-0.18.1.linux-amd64/node_exporter
[root@localhost opt]# chown prometheus:prometheus -R ./node_exporter-0.18.1.linux-amd64
[root@localhost ~]# systemctl start node_exporter
[root@localhost prometheus-2.13.1.linux-amd64]# cat prometheus.yml
# 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=` to any timeseries scraped from this config.
- job_name: 'prometheus'
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: ['192.168.135.240:9090']
- job_name: 192.168.135.240_centos
- targets: ['192.168.135.240:9100']
labels:
instance: 192.168.135.240_centos
##此部分為新加的nodxexporter的地址信息nodeexporter的默認端口是9100
[root@localhost prometheus-2.13.1.linux-amd64]# systemctl restart prometheus
可以看到nodeexporter的信息已經(jīng)發(fā)送到了prometheus,為了更好的展示我們收集到的監控信息安裝grafana
Dashboard https://grafana.com/api/dashboards/10645/revisions/1/download
[root@localhost opt]# tar zxf grafana-6.4.3.linux-amd64.tar.gz
[root@localhost bin]# cd /usr/lib/systemd/system
[root@localhost bin]# cat /usr/lib/systemd/system/grafana.service
Description=Grafana Server
EnvironmentFile=/opt/grafana-6.4.3/conf/grafana-server
WorkingDirectory=/opt/grafana-6.4.3
ExecStart=/opt/grafana-6.4.3/bin/grafana-server \\
--config=${CONF_FILE} \\
--pidfile=${PID_FILE_DIR}/grafana-server.pid \\
--packaging=rpm \\
cfg:default.paths.logs=${LOG_DIR} \\
cfg:default.paths.data=${DATA_DIR} \\
cfg:default.paths.plugins=${PLUGINS_DIR} \\
cfg:default.paths.provisioning=${PROVISIONING_CFG_DIR}
[root@localhost bin]# cat /opt/grafana-6.4.3/conf/grafana-server
GRAFANA_USER=grafana
GRAFANA_GROUP=grafana
GRAFANA_HOME=/opt/grafana-6.4.3/
LOG_DIR=/opt/grafana-6.4.3/data/log
DATA_DIR=/opt/grafana-6.4.3/data
MAX_OPEN_FILES=10000
CONF_DIR=/opt/grafana-6.4.3/conf
CONF_FILE=/opt/grafana-6.4.3/conf/defaults.ini
RESTART_ON_UPGRADE=true
PLUGINS_DIR=/opt/grafana-6.4.3/data/plugins
# Only used on systemd systems
PID_FILE_DIR=/opt/grafana-6.4.3/data
[root@localhost system]# systemctl daemon-reload
[root@localhost system]# systemctl start grafana
http:192.168.135.240:3000(本地ip:3000) 用戶(hù)名密碼admin:admin

Configuration---Add data source

因為我們的數據是prometheus所以此處選擇prometheus


這里可以添加一寫(xiě)系統自帶的prometheus的dashboard但是只可以看到prometheus的一些監控信息



3下載其他dashboard模板
下載好模板后再Dashboars – Manage 選擇import 將文件導入


導入后就可以看到我們新加的模板,點(diǎn)擊他就可以看到監控頁(yè)面了

注:如果頁(yè)面上又報錯說(shuō)grafana-piechart-panel不存在那么就安裝他
[root@localhost bin]# ./grafana-cli plugins install grafana-piechart-panel
installing grafana-piechart-panel @ 1.3.9
from: https://grafana.com/api/plugins/grafana-piechart-panel/versions/1.3.9/download
into: /var/lib/grafana/plugins
? Installed grafana-piechart-panel successfully
Restart grafana after installing plugins .
[root@localhost bin]# systemctl restart grafana

[root@localhost opt]# wget https://github.com/prometheus/mysqld_exporter/releases/download/v0.12.1/mysqld_exporter-0.12.1.linux-amd64.tar.gz
[root@localhost opt]$ tar zxf mysqld_exporter-0.12.1.linux-amd64.tar.gz
[root@localhost mysqld_exporter-0.12.1.linux-amd64]# ls
LICENSE mysqld_exporter NOTICE
[root@localhost mysqld_exporter-0.12.1.linux-amd64]# cat /usr/lib/systemd/system/mysqld_exporter.service
ExecStart=/opt/mysqld_exporter-0.12.1.linux-amd64/mysqld_exporter --config.my-cnf=/opt/mysqld_exporter-0.12.1.linux-amd64/.my.cnf
[root@localhost mysqld_exporter-0.12.1.linux-amd64]# cat .my.cnf
[client]
user=jian
password=123456
mysql> create user jian@'%' identified by '123456';
Query OK, 0 rows affected (0.02 sec)
mysql> grant replication client,process on *.* to jian@'%';
Query OK, 0 rows affected (0.01 sec)
mysql> grant select on performance_schma.* to jian@'%';
[root@localhost opt]# chown prometheus:prometheus -R ./mysqld_exporter-0.12.1.linux-amd64 [root@localhost opt]# systemctl daemon-reload
[root@localhost opt]# systemctl start mysqld_exporter
- job_name: 192.168.135.236_mysql
- targets: ['192.168.135.236:9104']
instance: 192.168.135.236_mysql
##此部分為新加的mysqldxexporter的地址信息mysqldexporter的默認端口是9104

Dashboard:

聯(lián)系客服