mysql mha高可用架構的安裝
MMM無法全然地保證數據的一致性,所以MMM適用於對數據的一致性要求不是非常高。可是又想最大程度的保證業務可用性的場景對於那些對數據一致性要求非常高的業務,非常不建議採用MMM的這樣的高可用性架構。那麽可以考慮使用MHA。在mysql故障切換的過程中。MHA可以在0-30s內自己主動完畢數據庫的故障切換操作,而且MHA可以最大程度上保證數據的一致性,以達到真正意義上的高可用。MHA軟件由兩部分組成,Manager工具包和Node工具包。詳細的說明例如以下。 Manager工具包主要包含下面幾個工具: masterha_check_ssh 檢查MHA的SSH配置狀況 masterha_check_repl 檢查MySQL復制狀況 masterha_manger 啟動MHA masterha_check_status 檢測當前MHA執行狀態 masterha_master_monitor 檢測master是否宕機 masterha_master_switch 控制故障轉移(自己主動或者手動) masterha_conf_host 加入或刪除配置的server信息 Node工具包(這些工具通常由MHA Manager的腳本觸發。無需人為操作)主要包含下面幾個工具: save_binary_logs 保存和復制master的二進制日誌 apply_diff_relay_logs 識別差異的中繼日誌事件並將其差異的事件應用於其它的slave filter_mysqlbinlog 去除不必要的ROLLBACK事件(MHA已不再使用這個工具) purge_relay_logs 清除中繼日誌(不會堵塞SQL線程) 註意: (1)為了盡可能的降低主庫硬件損壞宕機造成的數據丟失。因此在配置MHA的同一時候建議配置成MySQL 5.5的半同步復制 1.1、搭建好開發環境
<img src="http://img.blog.csdn.net/20160324175821383?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />
1.2、yaolansvr安裝ftp服務,並上傳mha安裝軟件 (1)關閉selinux,否則vsftpd報226錯誤 # mkdir -p /yangsq/ftp # useradd -d /yangsq/ftp -s /sbin/nologin uftp # passwd uftp # chown -R uftp:uftp /yangsq/ftp # yum list all|grep vsftpd # yum -y install vsftpd.x86_64 # cp /etc/vsftpd/vsftpd.conf /etc/vsftpd/vsftpd.conf.bak anonymous_enable=YES改為anonymous_enable=NO local_enable=YES write_enable=YES chroot_local_user=YES # chkconfig vsftpd on # service vsftpd start # yum install ftp.x86_64 -y # sestatus SELinux status: enabled SELinuxfs mount: /selinux Current mode: enforcing Mode from config file: enforcing Policy version: 24 Policy from config file: targeted # setenforce 0 # ftp 192.168.0.3 21 1.3、全部數據庫節點安裝Perl模塊,同一時候做 yum -y install perl-DBD-MySQL yum -y install perl-CPAN.x86_64 cd /yangsq/ftp tar xvf mha4mysql-node-0.54.tar.gz cd mha4mysql-node-0.54 perl Makefile.PL make && make install Installing /usr/local/share/perl5/MHA/BinlogPosFinderXid.pm Installing /usr/local/share/perl5/MHA/SlaveUtil.pm Installing /usr/local/share/perl5/MHA/NodeUtil.pm Installing /usr/local/share/perl5/MHA/BinlogPosFinderElp.pm Installing /usr/local/share/perl5/MHA/BinlogPosFindManager.pm Installing /usr/local/share/perl5/MHA/BinlogPosFinder.pm Installing /usr/local/share/perl5/MHA/BinlogManager.pm Installing /usr/local/share/perl5/MHA/NodeConst.pm Installing /usr/local/share/perl5/MHA/BinlogHeaderParser.pm Installing /usr/local/share/man/man1/filter_mysqlbinlog.1 Installing /usr/local/share/man/man1/purge_relay_logs.1 Installing /usr/local/share/man/man1/apply_diff_relay_logs.1 Installing /usr/local/share/man/man1/save_binary_logs.1 Installing /usr/local/bin/filter_mysqlbinlog Installing /usr/local/bin/apply_diff_relay_logs Installing /usr/local/bin/save_binary_logs Installing /usr/local/bin/purge_relay_logs 1.4、在yaolansvr_slave安裝mha manager (1)No package perl-Log-Dispatch available. # mv CentOS-Base.repo CentOS-Base.repo.bak sftp> put C:\Users\Yaolan\Downloads\CentOS6-Base-163.repo # yum clean all # yum makecache 或者 # rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm yum -y install perl-Config-Tiny yum install perl-Log-Dispatch -y yum install perl-Parallel-ForkManager -y yum install perl-Time-HiRes -y # tar xvf mha4mysql-manager-0.54.tar.gz # cd mha4mysql-manager-0.54 # perl Makefile.PL # make && make install Installing /usr/local/share/perl5/MHA/ManagerAdminWrapper.pm Installing /usr/local/share/perl5/MHA/ManagerUtil.pm Installing /usr/local/share/perl5/MHA/MasterFailover.pm Installing /usr/local/share/perl5/MHA/MasterMonitor.pm Installing /usr/local/share/perl5/MHA/ManagerAdmin.pm Installing /usr/local/share/perl5/MHA/Config.pm Installing /usr/local/share/perl5/MHA/DBHelper.pm Installing /usr/local/share/perl5/MHA/HealthCheck.pm Installing /usr/local/share/perl5/MHA/FileStatus.pm Installing /usr/local/share/perl5/MHA/MasterRotate.pm Installing /usr/local/share/perl5/MHA/Server.pm Installing /usr/local/share/perl5/MHA/ServerManager.pm Installing /usr/local/share/perl5/MHA/SSHCheck.pm Installing /usr/local/share/perl5/MHA/ManagerConst.pm Installing /usr/local/share/man/man1/masterha_check_ssh.1 Installing /usr/local/share/man/man1/masterha_secondary_check.1 Installing /usr/local/share/man/man1/masterha_conf_host.1 Installing /usr/local/share/man/man1/masterha_check_status.1 Installing /usr/local/share/man/man1/masterha_stop.1 Installing /usr/local/share/man/man1/masterha_manager.1 Installing /usr/local/share/man/man1/masterha_master_monitor.1 Installing /usr/local/share/man/man1/masterha_check_repl.1 Installing /usr/local/share/man/man1/masterha_master_switch.1 Installing /usr/local/bin/masterha_manager Installing /usr/local/bin/masterha_check_ssh Installing /usr/local/bin/masterha_check_status Installing /usr/local/bin/masterha_master_monitor Installing /usr/local/bin/masterha_secondary_check Installing /usr/local/bin/masterha_conf_host Installing /usr/local/bin/masterha_check_repl Installing /usr/local/bin/masterha_stop Installing /usr/local/bin/masterha_master_switch 1.5、全部mysql服務器配置ssh登錄無密碼驗證,sshd_config已改不生效,萬能的重新啟動 註意: (1)ssh-copy-id: command not found,解決:yum install openssh-clients -y (2)對自己本身也要運行ssh-copy-id (3)關閉slave後重新啟動mysql實例,slave相關的進程正常啟動 # ssh-keygen -t rsa Generating public/private rsa key pair. Enter file in which to save the key (/root/.ssh/id_rsa) # yum install -y openssh-clients # ssh-copy-id -i /root/.ssh/id_rsa.pub [email protected]