prometheus linux下载_Prometheus+Grafana监控系统安装实记

fadd8ee383054cad9ad9ac7bf553d028

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

d85ce3e3795346138818c428935b668d
752d5dd7e5124faab26c72b232601feb

目前看到的只是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=` 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

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

a046748872e4481b9905e441cceeb4cc

可以看到nodeexporter的信息已经发送到了prometheus,为了更好的展示我们收集到的监控信息安装grafana

6 grafana

Dashboard https://grafana.com/api/dashboards/10645/revisions/1/download

9374b1987d334c179a4f5d15d1e9e78b

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

8e025e2b91ca4fbcaccfbc79ad3ed58e

1 添加数据源

Configuration---Add data source

14352ae3e57848e5ac0cb2f76fd2a95c

因为我们的数据是prometheus所以此处选择prometheus

42e70723882e4bd683b55cbe8a1582b1
e6a09c818f91488d9d83ecab06f426d8

2 添加dashboard

这里可以添加一写系统自带的prometheus的dashboard但是只可以看到prometheus的一些监控信息

1195a7c78ca741878dbff2d3b8a0ef5f
8574a60e40044bd49a45edeef49f9453
c58c70f7166b4dcaa3a8c72c349729bb

3下载其他dashboard模板

下载好模板后再Dashboars – Manage 选择import 将文件导入

1a0d04fd24fe4ffeb9a9582663df8a32
772fa3aa528947a7957f56738dbd78ef

导入后就可以看到我们新加的模板,点击他就可以看到监控页面了

23b17cf3532e47c8bc4affade8702697

注:如果页面上又报错说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

44df402638754013ba2f821dcabc948d

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

43cfaa5fff6a43ffaa3d6ff8005edeaf

6 grafana

Dashboard:

5f89482f840f4185ba762086cac9c6cb
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值