• mysql 集群 监控


    部署mysql高可用集群(mysql-mmm+主从同步)
    4台数据库服务器:
    四个数据库之保留初始的四个库,其他库全部删除
    主机158
    主机137
    主机99
    主机67
    主机102(可与其他四台ping通即可)
    5台主机的公共配置:
    下载mysql-mmm.zip
    配置yum源
    service iptables stop
    setenforce 0
    yum -y install perl perl-*
    主机158与主机137配置为主主结构:
    主机158:
    mysql> grant replication slave on *.* to hydra@"%" identified by "Anonymous";
    [root@158 ~]# vim /etc/my.cnf
    [mysqld]
    log-bin=master158
    server_id=158
    [root@158 ~]# /etc/init.d/mysql restart
    mysql> show master statusG;(在192.168.4.137上查看节点)
    mysql> change master to master_host="192.168.4.137",master_user="hydra",master_password="Anonymous",master_log_file="master137.000001",master_log_pos=120;
    mysql> start slave;
    主机137:
    mysql> grant replication slave on *.* to hydra@"%" identified by "Anonymous";
    [root@137 ~]# vim /etc/my.cnf
    [mysqld]
    log-bin=master137
    server_id=137
    log-slave-updates
    [root@137 ~]# /etc/init.d/mysql restart
    mysql> show master statusG;(在192.168.4.158上查看节点)
    mysql> change master to master_host="192.168.4.158",master_user="hydra",master_password="Anonymous",master_log_file="master158.000001",master_log_pos=120;
    mysql> start slave;

    主机99和主机67同时配置为主机137的从数据库,并能够让主机99和主机67能同步主机158上的数据:
    主机99:
    [root@99 ~]# vim /etc/my.cnf
    [mysqld]
    server-id=99
    [root@99 ~]# /etc/init.d/mysql restart
    mysql> show master statusG;(在192.168.4.137上查看节点)
    mysql> change master to master_host="192.168.4.137",master_user="hydra",master_password="Anonymous",master_log_file="master137.000001",master_log_pos=120;
    mysql> start slave;

    主机67:
    [root@67 ~]# vim /etc/my.cnf
    [mysqld]
    server_id=67
    [root@67 ~]# /etc/init.d/mysql restart
    mysql> show master statusG;(在192.168.4.137上查看节点)
    mysql> change master to master_host="192.168.4.137",master_user="hydra",master_password="Anonymous",master_log_file="master137.000001",master_log_pos=120;
    mysql> start slave;

    测试主从同步配置:
    使用158的数据库做用户授权,在其他三台数据库服务器能够查看到授权用户
    mysql> grant all on bbs.* to stu@"%" identified by "123";
    mysql> select user,host from mysql.user;(在其他三台数据库服务器测试)
    +-------+-----------+
    | user | host |
    +-------+-----------+
    | hydra | % |
    | stu | % |
    | root | 127.0.0.1 |
    | root | 137 |
    | root | ::1 |
    | root | localhost |
    +-------+-----------+
    在客户端测试授权用户:
    [root@102 ~]# mysql -h192.168.4.158 -ustu -p123(测试可以连接)
    mysql> create database bbs;
    mysql> create table bbs.t1(id int);
    mysql> insert into bbs.t1 values(911);
    在其他数据库服务器查看:
    mysql> select * from bbs.t1;
    +------+
    | id |
    +------+
    | 911 |
    +------+

    配置mysql-mmm
    mysql主主复制管理器,监控,故障转移和管理的一套脚本套件
    用perl语言编写,能对居于标准的主从配置的任意数量的从服务器进行读负载均衡
    和实现数据备份,mysql本身没有提供故障转移的方案,从而实现数据库服务器的高可用

    mysql-mmm架构
    mmm-monitor:管理节点,运行在监控服务器上,负责所有的监控工作的监控
    mmm-agent:数据库节点,运行在数据库服务器上,提供简单的远程服务集,提供给监控节点

    在所有的服务器上安装mysql-mmm
    [root@158 ~]# unzip mysql-mmm.zip
    [root@158 mysql-mmm]# ls
    Algorithm-Diff-1.1902.tar.gz mysql-mmm-P.txt
    install.sh Net-ARP-1.0.8.tgz
    mysql-mmm-2.2.1.tar.gz perl-Log-Log4perl-1.26-1.el6.rf.noarch.rpm
    mysql-mmm-L.docx Proc-Daemon-0.03.tar.gz
    [root@158 mysql-mmm]# tar -xf mysql-mmm-2.2.1.tar.gz
    [root@158 mysql-mmm-2.2.1]# ls
    bin COPYING etc INSTALL lib Makefile README sbin UPGRADE VERSION
    [root@158 mysql-mmm-2.2.1]# make install(安装)
    [root@158 ~]# ls /etc/mysql-mmm/*.conf(配置文件)
    /etc/mysql-mmm/mmm_agent.conf /etc/mysql-mmm/mmm_mon.conf
    /etc/mysql-mmm/mmm_common.conf /etc/mysql-mmm/mmm_tools.conf
    配置文件说明:
    mmm_agent.conf(是mmm_agent服务的主配置文件)
    mmm_mon.conf(是mmm_monitor的主配置文件)
    mmm_common.conf(公共配置文件,所有的服务器上都要)

    配置mysql-mmm的ip规划:
    写ip地址 192.168.4.119 (在主机158和主机137之间浮动)

    读ip地址 192.168.4.200 (在主机99和主机67之间浮动)
    192.168.4.201
    修改mmm_common.conf配置文件之前,在所有数据库服务器上做如下授权:
    mysql> grant replication client,process,super on *.* to agent@"%" identified by "Anonymous";

    更改mmm_common.conf配置文件:
    [root@158 mysql-mmm]# sed -i '/^$/d' mmm_common.conf(删除空行)
    [root@158 mysql-mmm]# vim mmm_common.conf
    <host default>(本机配置)
    cluster_interface eth0(本机网卡)
    pid_path /var/run/mmm_agentd.pid(进程pid号存放处)
    bin_path /usr/lib/mysql-mmm/(可执行命令安装路径)
    replication_user hydra(拷贝数据权限的用户名)
    replication_password Anonymous(被授权用户密码)
    agent_user agent(有agent权限的用户名)
    agent_password Anonymous(密码)
    </host>
    <host master158>(主机名)
    ip 192.168.4.158(主机的ip地址)
    mode master(主机的类型)
    peer master137(同类型)
    </host>
    <host master137>(主机名)
    ip 192.168.4.137(主机的ip地址)
    mode master(主机的类型)
    peer master158(同类型)
    </host>
    <host slave99>(从主机名)
    ip 192.168.4.99(主机的ip地址)
    mode slave(主机的类型)
    </host>
    <host slave67>(从主机名)
    ip 192.168.4.67(主机的ip地址)
    mode slave(主机的类型)
    </host>
    <role writer>(写类型)
    hosts master158,master137(写类型的主机名)
    ips 192.168.4.119(浮动ip)
    mode exclusive(独占模式)
    </role>
    <role reader>(读类型)
    hosts slave99,slave67(读类型的主机名)
    ips 192.168.4.200,192.168.4.201(浮动ip)
    mode balanced(共享模式)
    </role>
    [root@158 mysql-mmm]# scp mmm_common.conf root@192.168.4.137:/etc/mysql-mmm/(保存后把此配置文件发送到所有的服务器上)

    更改mmm_agent.conf配置文件
    修改mmm_agent.con文件
    [root@158 mysql-mmm]# vim mmm_agent.conf
    include mmm_common.conf(先加载此配置文件)
    this master158(本机在mmm_common.conf文件里的主机名)
    修改mmm_agent.con文件
    [root@137 mysql-mmm]# vim mmm_agent.conf
    include mmm_common.conf
    this master137(本机在mmm_common.conf文件里的主机名)
    修改mmm_agent.con文件
    [root@99 mysql-mmm]# vim mmm_agent.conf
    include mmm_common.conf
    this slave99(本机在mmm_common.conf文件里的主机名)
    修改mmm_agent.con文件
    [root@67 mysql-mmm]# vim mmm_agent.conf
    include mmm_common.conf
    this slave67(本机在mmm_common.conf文件里的主机名)


    修改mmm_mon.conf配置文件之前,在所有数据库服务器上做如下授权:
    mysql> grant replication client on *.* to monitor@"%" identified by "Anonymous";
    更改mmm_mon.conf配置文件:(在监控端修改即可,被监控端不用改)
    [root@102 mysql-mmm]# vim mmm_mon.conf
    include mmm_common.conf
    <monitor>
    ip 192.168.4.102(监控端ip)
    pid_path /var/run/mmm_mond.pid(pid存放处)
    bin_path /usr/lib/mysql-mmm/
    status_path /var/lib/misc/mmm_mond.status
    ping_ips 192.168.4.158, 192.168.4.137, 192.168.4.99, 192.168.4.67(被监控的服务器ip地址)
    </monitor>
    <host default>
    monitor_user monitor(授权用户)
    monitor_password Anonymous(密码)
    </host>
    debug 0(1开启,输出启动过程信息)

    启动数据库服务器上的mmm_agent服务:
    启动服务:/etc/init.d/mysql-mmm-agent start
    日志文件:/var/log/mysql-mmm/mmm_agentd.log
    端口:netstat -utnalp | grep :9989
    安装服务运行需要的软件包
    Algorithm-Diff-1.1902.tar.gz
    Proc-Daemon-0.03.tar.gz
    perl-Log-Log4perl-1.26-1.el6.rf.noarch.rpm
    把安装步骤写成脚本
    进入在每台数据库服务器上包所在的目录上执行
    进入每台数据库服务器执行脚本
    [root@158 ~]# vim xx.sh
    #/bin/bash
    tar -xf Proc-Daemon-0.03.tar.gz
    cd Proc-Daemon-0.03
    perl Makefile.PL
    make
    make install
    cd..
    rpm -ivh perl-Log-Log4perl-1.26-1.el6.rf.noarch.rpm
    tar -xf Algorithm-Diff-1.1902.tar.gz
    cd Algorithm-Diff-1.1902
    perl Makefile.PL
    make
    make install
    cd ..
    [root@158 ~]# chmod +x xx.sh
    [root@158 ~]# scp xx.sh 192.168.4.137:/root/(把脚本上传到其他服务器上)

    启动mmm_monitor服务
    依赖包和mmm_agent的一样,执行脚本即可
    启动服务:/etc/init.d/mysql-mmm-monitor start
    日志文件:/var/log/mysql-mmm/mmm_monitor.log
    端口:netstat -utnalp | grep :9988

    在所有数据库服务器上安装获取虚拟ip的程序
    Net-ARP-1.0.8.tgz

    [root@158 ~]# vim xxx.sh
    #/bin/bash
    gunzip Net-ARP-1.0.8.tgz
    tar -xf Net-ARP-1.0.8.tar
    cd Net-ARP-1.0.8
    perl Makefile.PL
    make
    make install
    [root@158 Net-ARP-1.0.8]# chmod +x xxx.sh (把执行脚本上传到所有数据库服务器上)

    测试配置
    在102上查看配置
    mmm_control help(帮助)
    mmm_control show(查看状态)
    mmm_control set_online 主机名(在线状态)
    [root@102 ~]# mmm_control set_online master158(设置主机158在线模式)
    [root@102 ~]# mmm_control show
    master137(192.168.4.137) master/ONLINE. Roles:
    master158(192.168.4.158) master/ONLINE. Roles: writer(192.168.4.119)
    slave67(192.168.4.67) slave/ONLINE. Roles: reader(192.168.4.200)
    slave99(192.168.4.99) slave/ONLINE. Roles: reader(192.168.4.201)

    客户端测试虚拟ip访问:
    [root@102 ~]# ping192.168.4.119
    [root@102 ~]# mysql -h192.168.4.119 -uhydra -pAnonymous

  • 相关阅读:
    sql删除注意的问题
    lua创建文件
    linux部分常用命令
    已知账户和密码进行远程桌面
    excel2013超链接进不去,提示“您的组织策略不允许...”
    2019-2020-1 20199321《Linux内核原理与分析》第七周作业
    《深入理解计算机系统》第一章读书笔记 20199321
    《文献管理与信息分析》速读笔记
    《深入理解计算机系统》速读笔记
    《构建之法现代软件工程》速读笔记
  • 原文地址:https://www.cnblogs.com/Hydraxx/p/7490984.html
Copyright © 2020-2023  润新知