美文网首页程序员
MHA的安装搭建步骤

MHA的安装搭建步骤

作者: 电动猫 | 来源:发表于2019-04-27 15:53 被阅读6次

    安装基本环境:
    master:192.168.0.1
    node:192.168.0.2 192.168.0.3
    vip:192.168.0.101

    1、机器添加ssh信任

    ssh-keygen
    cat ~/.ssh/ip_rsa.pub >> ~/.ssh/authorized.keys
    rm kown_hosts
    chomod  600 authorized.keys
    scp –r .ssh 192.168.0.2:~/
    scp -r .ssh  192.168.0.3:~/ 
    

    2、下载mha

    master:https://github.com/yoshinorim/mha4mysql-manager/releases
    node:https://github.com/yoshinorim/mha4mysql-node/releases

    3、在三台机器中安装依赖

    安装epel源
    yum install -y epel-release
    安装perl
    yum install perl-DBD-MySQL
    yum install perl-Config-Tiny
    yum install perl-Log-Dispatch
    yum install perl-Parallel-ForkManager

    4、安装mysql,部署主从结构

    master 192.168.0.1 >> slave:192.168.0.2 192.168.0.3
    创建mha账号

    5、安装mha node

    在manager节点和node节点中都需要安装mha node
    rpm包安装方式:
    yum localinstall -y mha4mysql-node-0.58-0.el7.centos.noarch.rpm

    6、安装mha manager

    只在manager节点上安装
    rpm包安装方式:
    yum localinstall -y mha4mysql-manager-0.58-0.el7.centos.noarch.rpm

    7、MHA manager配置

    mkdir /etc/masterha
    vim /etc/masterha/app1.conf

    [server default]
    #mha manager 工作目录
    manager_workdir = /var/log/masterha/app1
    manager_log = /var/log/masterha/app1/app1.log 
    remote_workdir = /var/log/masterha/app1
    
    [server1]
    hostname=192.168.0.1
    master_binlog_dir = /data/mysql/mysql3306/logs
    candidate_master = 1
    check_repl_delay = 0       
    
    [server2]
    hostname=192.168.0.2
    master_binlog_dir=/data/mysql/mysql3306/logs 
    candidate_master=1
    check_repl_delay=0
    
    [server3]
    hostname=192.168.0.3
    master_binlog_dir=/data/mysql/mysql3306/logs 
    candidate_master=1
    check_repl_delay=0
    

    全局配置文件
    vim /etc/masterha/masterha_defaults.conf

    [server default]
    #MySQL的用户和密码
    user=root
    password=root
    
    #系统ssh用户
    ssh_user=root
    
    #复制用户
    repl_user=repl
    repl_password=repl4slave
    
    #监控
    ping_interval=1
    #shutdown_script=""
    
    #切换调用的脚本
    #master_ip_failover_script=/etc/masterha/master_ipfailover
    #master_ip_online_change_script=/etc/masterha/master_ip_online_change
    

    8、vip配置

    绑定和删除vip节点

    [root@master masterha]# cat init_vip.sh 
    vip="192.168.0.101/32"
    /sbin/ip addr add $vip dev eth0
    
    root@master masterha]# cat drop_vip.sh 
    vip="192.168.0.101/32"
    /sbin/ip addr del $vip dev eth0
    
    配置vip故障切换脚本

    master_ip_failover:https://github.com/yoshinorim/mha4mysql-manager/blob/master/samples/scripts/master_ip_failover
    master_ip_online_change:https://github.com/yoshinorim/mha4mysql-manager/blob/master/samples/scripts/master_ip_online_change
    根据作者的脚本来进行改写配置。

    9、测试配置文件

    测试ssh
    masterha_check_ssh --global-conf=/etc/masterha/masterha_default.conf --conf=/etc/masterha/app1.conf
    
    测试主从结构,能不能启动
    masterha_check_slave --global-conf=/etc/masterha/masterha_default.conf --conf=/etc/masterha/app1.conf
    

    报错:
    [/usr/local/share/perl5/MHA/MasterMonitor.pm,ln205] Slaves settings check failed!
    [/usr/local/share/perl5/MHA/MasterMonitor.pm,ln413] Slave configuration failed.
    [/usr/local/share/perl5/MHA/MasterMonitor.pm,ln424] Error happened on checking configurations. at /usr/local/bin/masterha_check_repl line 48
    [/usr/local/share/perl5/MHA/MasterMonitor.pm,ln523] Error happened on monitoring servers.
    [info] Got exit code 1 (Not master dead).

    MySQL Replication Health is NOT OK!
    在所有节点执行:
    ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql

    执行后再次报错:
    [info] Connecting to root@192.168.0.1(192.168.0.1:22)..
    Can't exec "mysqlbinlog": No suchfile or directory at /usr/local/share/perl5/MHA/BinlogManager.pm line 106.
    mysqlbinlog version command failed with rc1:0, please verify PATH, LD_LIBRARY_PATH, and client options
    at/usr/local/bin/apply_diff_relay_logs line 493
    [/usr/local/share/perl5/MHA/MasterMonitor.pm,ln205] Slaves settings check failed!
    [/usr/local/share/perl5/MHA/MasterMonitor.pm,ln413] Slave configuration failed.
    [/usr/local/share/perl5/MHA/MasterMonitor.pm,ln424] Error happened on checking configurations. at /usr/local/bin/masterha_check_repl line 48
    [/usr/local/share/perl5/MHA/MasterMonitor.pm,ln523] Error happened on monitoring servers.
    Got exit code 1 (Not master dead).
    MySQL Replication Health is NOT OK!
    在所有节点执行
    [root@master masterha]#type mysqlbinlog
    [root@master masterha]#mysqlbinlog is/usr/local/mysql/bin/mysqlbinlog
    [root@master masterha]#ln -s/usr/local/mysql/bin/mysqlbinlog /usr/bin/mysqlbinlog
    原因:都是没有在指定位置找到相应的文件,所以做一个软链

    10、MHA启动和关闭

    启动:
    第一次,手动绑定vip
    sh /etc/masterha/init_vip.sh

    masterha_manager --global_conf=/etc/masterha/masterha_default.conf --conf=/etc/masterha/app1.conf &
    

    检查MHA是否启动和状态
    cat /var/log/masterha/app1.log

    masterha_check_status --global_conf=/etc/masterha/masterha_default.conf --conf=/etc/masterha/app1.conf
    

    停止:

    masterha_stop --global_conf=/etc/masterha/masterha_default.conf --conf=/etc/masterha/app1.conf
    

    相关文章

      网友评论

        本文标题:MHA的安装搭建步骤

        本文链接:https://www.haomeiwen.com/subject/yvnhnqtx.html