promethues+grafana安装监控服务器和mysql数据库

1、安装环境依赖

        [root@localhost ~]# yum -y install go epel-release

2、创建安装路径并解压安装包(路径自定)

        [root@localhost ~]# mkdir /data/software/prometheus        

        [root@localhost ~]# mv prometheus-2.34.0.linux-amd64.tar.gz 

        [root@localhost ~]# cd /data/software/prometheus

        [root@localhost prometheus]# tar -xvf prometheus-2.34.0.linux-amd64.tar.gz

        [root@localhost prometheus]# mv prometheus-2.34.0.linux-amd64 prometheus

3、配置prometheus,添加监控插件信息

        需要创建用户及用户组更改权限!!!

        [root@localhost prometheus]# groupadd prometheus

        [root@localhost prometheus]# useradd -g prometheus -s /sbin/nologin prometheus

        [root@localhost prometheus]# chown -R prometheus:prometheus /data/software/prometheus/node_exporter/

        [root@localhost prometheus]# cd  prometheus

        [root@localhost prometheus]# vim  prometheus.yml

                在配置文件最下方添加!!!

  - job_name:  "1"
    static_configs:
      - targets:  ['192.168.1.1:9100']
        labels:
         instance:  linux-1

  - job_name:  "2"
    static_configs:
      - targets:  ['192.168.1.2:9100']
        labels:
         instance:  linux-2

  - job_name:  "3"
    static_configs:
      - targets:  ['192.168.1.3:9100']
        labels:
         instance:  linux-3

  - job_name:  "mysql"
    static_configs:
      - targets:  ['192.168.1.3:9100']
        labels:
         instance:  mysql-1

        3.1、配置prometheus.service启动文件

        [root@localhost prometheus]# vim  /usr/lib/systemd/system/prometheus.service

[Unit]
Description=Prometheus instance
Wants=network-online.target
After=network-online.target

[Service]
User=root
Group=root
Type=simple
Restart=on-failure
WorkingDirectory=/data/software/prometheus/prometheus
RuntimeDirectoryMode=0750
ExecStart=/data/software/prometheus/prometheus/prometheus  --storage.tsdb.retention=30d --config.file=/data/software/prometheus/prometheus/prometheus.yml
LimitNOFILE=10000
TimeoutStopSec=20

[Install]
WantedBy=multi-user.target

        3.2、加载启动文件、启动服务并设置开机自启

        [root@localhost prometheus]# systemctl  daemon-reload

        [root@localhost prometheus]#  systemctl  start  prometheus.service

        [root@localhost prometheus]#  systemctl  enable  prometheus.service

4、node_exporter插件安装(node仪表面板ID8919

        [root@localhost ~]# mkdir /data/software/node_exporter

        [root@localhost ~]# tar xvf node_exporter-1.3.1.linux-amd64.tar  -C  /data/software/node_exporter

        [root@localhost ~]# cd /data/software/node_exporter

        [root@localhost node_exporter]# mv  node_exporter-1.3.1.linux-amd64  node_exporter

        4.1、配置node_exporter.service启动文件

        [root@localhost node_exporter]# cd node_exporter

        [root@localhost node_exporter]# vim /usr/lib/systemd/system/node_exporter.service

[Unit]
Description=node_exporter
Documentation=https://prometheus.io/
After=network.target

[Service]
Type=simple
User=prometheus
ExecStart=/data/software/Prometheus/node_exporter/node_exporter
Restart=on-failure

[Install]
WantedBy=multi-user.target

        4.2、加载启动文件、启动插件并设置开机自启

        [root@localhost node_exporter]# systemctl daemon-reload

        [root@localhost node_exporter]# systemctl start node_exporter.service

        [root@localhost node_exporter]# systemctl enable node_exporter.service

5、安装mysqld_exporter插件(数据库仪表板ID7919

        [root@localhost ~]# mkdir /data/software/mysqld_exporter

        [root@localhost ~]# tar -xvf mysqld_exporter-0.14.0.linux-amd64.tar -C /data/software/mysqld_exporter

        [root@localhost ~]# cd /data/software/mysqld_exporter

        [root@localhost mysqld_exporter]# mv mysqld_exporter-0.14.0.linux-amd64  mysqld_exporter

        5.1、创建数据库用户及权限

        [root@localhost mysqld_exporter]# msyql -u root -p

        mysql> CREATE USER 'admin'@' localhost' IDENTIFIED BY 'admin123'        

        mysql> GRANT SELECT ON *.* TO 'admin'@'localhost';

        5.2、创建./my.cnf文件用于启动(启动方式一)

        [root@localhost mysqld_exporter]#  vim .my.cnf

[client]
user=admin
password=admin123

        5.2.1、启动mysqld_exporter插件

        [root@localhost mysqld_exporter]# ./mysqld_exporter  --config.my-cnf=".my.cnf"  &

        

        5.3、配置mysqld_exporter.service启动文件(启动方式二)

        [root@localhost mysqld_exporter]# vim /usr/lib/systemd/system/mysqld_exporter.service

[Unit]
Description=mysqld_exporter
After=network.target

[Service]
Type=simple
User=mysql
# admin对应授权账号,admin123对应授权密码,localhost对应授权账号密码所在的地址及端口号
Environment=DATA_SOURCE_NAME=admin:admin123@(localhost:3306)/
ExecStart=/data/software/Prometheus/mysqld_exporter/mysqld_exporter --web.listen-address=0.0.0.0:9104
  --config.my-cnf .my.cnf \
  --collect.slave_status \
  --collect.slave_hosts \
  --log.level=error \
  --collect.info_schema.processlist \
  --collect.info_schema.innodb_metrics \
  --collect.info_schema.innodb_tablespaces \
  --collect.info_schema.innodb_cmp \
  --collect.info_schema.innodb_cmpmem
Restart=on-failure

[Install]
WantedBy=multi-user.targe

         5.3.1、加载启动文件、开启插件及设置开机自启

         [root@localhost mysqld_exporter]# systemctl daemon-reload

         [root@localhost mysqld_exporter]# systemctl start mysqld_exporter.service

         [root@localhost mysqld_exporter]# systemctl enable mysqld_exporter.service

6、安装grafana启动服务

        [root@localhost ~]# yum -y install  /root/grafana-enterprise-8.4.4-1.x86_64.rpm 

        [root@localhost ~]# grafana-cli  plugins  install   grafana-piechart-panel

        [root@localhost ~]# systemctl  restart grafana-server

        6.1、登录grafana配置监控数据

        访问http://ip:3000

        默认用户密码admin  admin

 

  

配置后拉到最下面点击save

 

  

补充:

1、在prometheus配置中添加容器

  - job_name:  "docker"
    static_configs:
      - targets:  ['192.168.1.5:8080']
        labels:
         instance:  docker-1

2、后续由于添加容器监控,直接使用下面命令直接起容器即可(容器仪表板ID893

docker run \
--volume=/:/rootfs:ro \
--volume=/var/run:/var/run:rw \
--volume=/sys:/sys:ro \
--volume=/var/lib/docker/:/var/lib/docker:ro \
--publish=8080:8080 \
--detach=true \
--name=cadvisor \
--net=host \
-v "/etc/localtime:/etc/localtime" \
google/cadvisor:latest

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

IT.小唐

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值