MYSQL读写分离集群搭建(九)

MYSQL读写分离集群搭建(九)
本篇增加以下对这些机器进行监控的内容,就是使用prometheus+grafana对linux、mysql、haproxy进行监控
prometheus下载相关程序
https://github.com/prometheus/mysqld_exporter/releases/download/v0.12.1/mysqld_exporter-0.12.1.linux-amd64.tar.gz
https://github.com/prometheus/node_exporter/releases/download/v1.1.1/node_exporter-1.1.1.linux-amd64.tar.gz
https://github.com/prometheus/haproxy_exporter/releases/download/v0.12.0/haproxy_exporter-0.12.0.linux-amd64.tar.gz
https://github.com/prometheus/prometheus/releases/download/v2.25.0/prometheus-2.25.0.linux-amd64.tar.gz

安装prometheus的机器名为mymon01
安装grafana的机器名为mymon02

一、安装服务器端
#wget https://github.com/prometheus/prometheus/releases/download/v2.25.0/prometheus-2.25.0.linux-amd64.tar.gz

#tar xvf prometheus-2.25.0.linux-amd64.tar.gz

#mv prometheus-2.25.0.linux-amd64 /usr/local/prometheus

配置prometheus监控服务
#vim /lib/systemd/system/prometheus.service
[Unit]
Description=Prometheus
Documentation=https://prometheus.io/
After=network.target

[Service]
Type=simple
User=root
ExecStart=/usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml --web.enable-lifecycle
ExecStop=/usr/bin/killall -9 prometheus

[Install]
WantedBy=multi-user.target

加载服务
#systemctl daemon-reload

#systemctl start prometheus

#systemctl enable prometheus

二、安装客户端-linux
#groupadd prometheus

#useradd -g prometheus -m -d /var/lib/prometheus -s /sbin/nologin prometheus

#tar xvf node_exporter-1.1.1.linux-amd64.tar.gz

#mv node_exporter-1.1.1.linux-amd64 /usr/local/node_exporter

#vim /usr/lib/systemd/system/node_exporter.service
[Service]
User=prometheus
Group=prometheus
ExecStart=/usr/local/node_exporter/node_exporter

[Install]
WantedBy=multi-user.target

[Unit]
Description=node_exporter
After=network.target

#chown -R prometheus:prometheus /usr/local/node_exporter

#systemctl start node_exporter

#systemctl enable node_exporter

#systemctl status node_exporter

三、在mymon01机器上更新服务器清单
#vim /usr/local/prometheus/prometheus.yml

  • job_name: “Linux-HA”
    static_configs:

    • targets: [‘8.1.3.155:9100’]
    • targets: [‘8.1.3.156:9100’]
  • job_name: “Linux-DBMiddleWare”
    static_configs:

    • targets: [‘8.1.3.157:9100’]
    • targets: [‘8.1.3.158:9100’]
  • job_name: “Linux-MySQL”
    static_configs:

    • targets: [‘8.1.3.159:9100’]
    • targets: [‘8.1.3.160:9100’]
    • targets: [‘8.1.3.161:9100’]
    • targets: [‘8.1.3.162:9100’]
    • targets: [‘8.1.3.163:9100’]

#systemctl restart prometheus

四、安装客户端-mysql
在mysql的四台机器(mydb01-04)上安装监控点

#tar xvf mysqld_exporter-0.12.1.linux-amd64.tar.gz

#mv mysqld_exporter-0.12.1.linux-amd64 /usr/local/mysqld_exporter

#vim /usr/local/mysqld_exporter/.my.cnf
[client]
user=root
password=zijiwu2020T

#vim /usr/lib/systemd/system/mysqld_exporter.service
[Unit]
Description=mysqld_exporter
After=network.target

[Service]
Type=simple
User=mysql
ExecStart=/usr/local/mysqld_exporter/mysqld_exporter
–config.my-cnf /usr/local/mysqld_exporter/.my.cnf
–collect.auto_increment.columns
–collect.binlog_size
–collect.engine_innodb_status
–collect.engine_tokudb_status
–collect.global_status
–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
–web.listen-address=0.0.0.0:9104
Restart=on-failure

[Install]
WantedBy=multi-user.target

#systemctl daemon-reload

#systemctl enable mysqld_exporter

#systemctl start mysqld_exporter

#systemctl status mysqld_exporter

五、在mymon01机器上更新服务器清单
#vim /usr/local/prometheus/prometheus.yml

  • job_name: “MySQL Cluster”
    static_configs:
    • targets: [‘8.1.3.160:9104’]
    • targets: [‘8.1.3.161:9104’]
    • targets: [‘8.1.3.162:9104’]
    • targets: [‘8.1.3.163:9104’]

#systemctl restart prometheus

六、安装客户端-haproxy
HAProxy配置:
在myha01机器上对haproxy.cfg配置文件,添加如下配置项
#vi /etc/haproxy18/haproxy.cfg
listen stats
bind :9099
stats uri /haproxy
stats enable
该配置项将HAProxy的状态信息进行曝露,绑定在端口9099,并且路由地址为/haproxy
通过访问该地址,我们可以看到相应的HAProxy状态信息
#systemctl restart haproxy18

#tar xvf haproxy_exporter-0.12.0.linux-amd64.tar.gz

#mv haproxy_exporter-0.12.0.linux-amd64 /usr/local/haproxy_exporter

#vi /usr/local/haproxy_exporter/haproxy_exporter.sh
#!/bin/bash
/usr/local/haproxy_exporter/haproxy_exporter --haproxy.scrape-uri=“http://localhost:9099/haproxy;csv” --web.listen-address=“0.0.0.0:9199” & > /var/log/haproxy_exporter.log

#chmod +x /usr/local/haproxy_exporter/haproxy_exporter.sh
配置haproxy_exporter为服务
#vim /usr/lib/systemd/system/haproxy_exporter.service
[Unit]
Description=haproxy_exporter
After=network.target

[Service]
Type=forking
ExecStart=/usr/local/haproxy_exporter/haproxy_exporter.sh
Restart=on-failure

[Install]
WantedBy=multi-user.target

#chown -R root.root /usr/local/haproxy_exporter

#systemctl start haproxy_exporter

#systemctl enable haproxy_exporter

#systemctl status haproxy_exporter

七、在mymon01机器上更新服务器清单
#vim /usr/local/prometheus/prometheus.yml

  • job_name: “HAProxy”
    static_configs:
    • targets: [‘8.1.3.155:9199’]
    • targets: [‘8.1.3.156:9199’]

#systemctl restart prometheus

八、grafana安装
下载https://www.newbe.pro/Mirrors/Mirrors-Grafana/
https://mirrors.huaweicloud.com/grafana/7.4.2/
grafana-7.4.2-1.x86_64.rpm

yum -y install fontconfig
yum -y install urw-fonts
#rpm -ivh grafana-7.4.2-1.x86_64.rpm

#systemctl daemon-reload

#systemctl enable grafana-server

#systemctl start grafana-server

#systemctl status grafana-server

九、登录并设置grafana
http://8.1.3.167:3000/login
admin/admin

点击Add data source
在URL中输入http://8.1.3.166:9090/
保存

然后导入dashboard,如下是比较好的
https://grafana.com/dashboards/405
https://grafana.com/dashboards/7991
https://grafana.com/dashboards/1530
https://grafana.com/dashboards/11329
https://grafana.com/dashboards/315
https://grafana.com/dashboards/8919
https://grafana.com/dashboards/8378
https://grafana.com/dashboards/4202
https://grafana.com/dashboards/9276

https://grafana.com/dashboards/1860
Node Exporter Full

在这里插入图片描述

https://grafana.com/dashboards/7362
MySQL Overview在这里插入图片描述

https://grafana.com/dashboards/367
https://grafana.com/dashboards/2428
haproxy在这里插入图片描述

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值