1 安装prometheus
1 下载软件
[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
2 service 文件
[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
3 添加用户
[root@localhost opt]# adduser prometheus
[root@localhost opt]# chown prometheus:prometheus -R ./prometheus-2.13.1.linux-amd64/
4 启动服务
[root@localhost opt]# systemctl daemon-reload
[root@localhost ~]# systemctl start Prometheus
5 访问web
(本地ip:9090)
点击Status—Target 可以看到Prometheus的metrics
目前看到的只是Prometheus的一些监控项,我们一下安装一些插件来完成系统监控项的一些收集
2 安装node-exporter
1 下载软件
[root@localhost opt]# wget
[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
2 service文件
[root@localhost opt]# vi /usr/lib/systemd/system/node_exporter.service
[root@localhost opt]# cat /usr/lib/systemd/system/node_exporter.service
[Unit]
Description=node_exporter
After=network.target
[Service]
Type=simple
User=prometheus
ExecStart=/opt/node_exporter-0.18.1.linux-amd64/node_exporter
Restart=on-failure
[Install]
WantedBy=multi-user.target
[root@localhost opt]# systemctl daemon-reload
3 修改权限
[root@localhost opt]# chown prometheus:prometheus -R ./node_exporter-0.18.1.linux-amd64
[root@localhost ~]# systemctl start node_exporter
4 添加prometheus的job
[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=
- 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
static_configs:
- targets: ['192.168.135.240:9100']
labels:
instance: 192.168.135.240_centos
##此部分为新加的nodxexporter的地址信息nodeexporter的默认端口是9100
5 重启prometheus
[root@localhost prometheus-2.13.1.linux-amd64]# systemctl restart prometheus
可以看到nodeexporter的信息已经发送到了prometheus,为了更好的展示我们收集到的监控信息安装grafana
6 grafana
Dashboard https://grafana.com/api/dashboards/10645/revisions/1/download
3 安装grafana
1 下载软件
[root@localhost opt]# wget
[root@localhost opt]# tar zxf grafana-6.4.3.linux-amd64.tar.gz
2 service 文件
[root@localhost bin]# cd /usr/lib/systemd/system
[root@localhost bin]# cat /usr/lib/systemd/system/grafana.service
[Unit]
Description=Grafana Server
After=network.target
[Service]
EnvironmentFile=/opt/grafana-6.4.3/conf/grafana-server
User=prometheus
Restart=on-failure
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}
[Install]
WantedBy=multi-user.target
[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
3 启动服务
[root@localhost system]# systemctl daemon-reload
[root@localhost system]# systemctl start grafana
4 访问web
http:192.168.135.240:3000(本地ip:3000) 用户名密码admin:admin
1 添加数据源
Configuration---Add data source
因为我们的数据是prometheus所以此处选择prometheus
2 添加dashboard
这里可以添加一写系统自带的prometheus的dashboard但是只可以看到prometheus的一些监控信息
3下载其他dashboard模板
下载好模板后再Dashboars – Manage 选择import 将文件导入
导入后就可以看到我们新加的模板,点击他就可以看到监控页面了
注:如果页面上又报错说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 . <service>
[root@localhost bin]# systemctl restart grafana
4 安装mysqld_exporter
1 下载软件
[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
2 service文件
[root@localhost mysqld_exporter-0.12.1.linux-amd64]# cat /usr/lib/systemd/system/mysqld_exporter.service
[Unit]
Description=node_exporter
After=network.target
[Service]
Type=simple
User=prometheus
ExecStart=/opt/mysqld_exporter-0.12.1.linux-amd64/mysqld_exporter --config.my-cnf=/opt/mysqld_exporter-0.12.1.linux-amd64/.my.cnf
Restart=on-failure
[Install]
WantedBy=multi-user.target
[root@localhost opt]# systemctl daemon-reload
[root@localhost mysqld_exporter-0.12.1.linux-amd64]# cat .my.cnf
[client]
user=jian
password=123456
3 修改权限创建user
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@'%';
Query OK, 0 rows affected (0.02 sec)
[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
4 添加prometheus的job
[root@localhost prometheus-2.13.1.linux-amd64]# cat prometheus.yml
- job_name: 192.168.135.236_mysql
static_configs:
- targets: ['192.168.135.236:9104']
labels:
instance: 192.168.135.236_mysql
##此部分为新加的mysqldxexporter的地址信息mysqldexporter的默认端口是9104
5 重启prometheus
[root@localhost prometheus-2.13.1.linux-amd64]# systemctl restart prometheus
6 grafana
Dashboard:
閱讀更多 代號香蕉 的文章