分享更有价值
被信任是一种快乐

MHA的安装和部署步骤

文章页正文上

本篇内容介绍了“MHA的安装和部署步骤”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!##################MHA安装和部署####################1.服务器192.168.0.21 mydb1 #Master192.168.0.22 mydb2 #Slave192.168.0.23 mydb3 #MHA manager2. 所有机器修改vim /etc/hosts192.168.0.21 mydb1192.168.0.22 mydb2192.168.0.23 mydb33.设置SSH公钥免密码登录#root用户操作(/root),pwd mkdir ~/.ssh chmod 700 ~/.ssh cd ~/.ssh ssh-keygen -t rsa #一直回车 ls -al cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys ls -al chmod 600 ~/.ssh/authorized_keys cd .. scp -r .ssh 192.168.0.22:/root/ scp -r .ssh 192.168.0.23:/root/ ssh mydb1 ssh mydb2 ssh mydb34.下载mha4mysql-manager和mha4mysql-node https://github.com/yoshinorim/mha4mysql-manager https://github.com/yoshinorim/mha4mysql-node5.在三个节点(node 和 manag免费主机域名er)安装perl-DBD-MySQL,用光盘作yum源,#包括了3个包:Perl-DBD-MySQL,mysql-libs,perl-DBI yum install perl-DBD-MySQL yum install perl-DBI yum install mysql-libs6.在三个节点安装node(包括管理节点) tar xzvf mha4mysql-node-0.56.tar.gz cd mha4mysql-node-0.56 perl Makefile.PL make && make install7.在管理节点安装manager rpm -ivh perl-Config-Tiny-2.12-1.el5.rf.noarch.rpm rpm -ivh perl-Params-Validate-0.95-1.el5.rf.i386.rpm rpm -ivh perl-MIME-Types-1.28-2.el6.noarch.rpm rpm -ivh perl-Email-Date-Format-1.002-5.el6.noarch.rpm rpm -ivh perl-Mail-Sender-0.8.16-3.el6.noarch.rpm rpm -ivh perl-Mail-Sendmail-0.79-12.el6.noarch.rpm rpm -ivh perl-TimeDate-1.16-11.1.el6.noarch.rpm rpm -ivh perl-MailTools-2.04-4.el6.noarch.rpm rpm -ivh perl-MIME-Lite-3.027-2.el6.noarch.rpm rpm -ivh perl-Log-Dispatch-2.26-1.el5.rf.noarch.rpm rpm -ivh perl-Parallel-ForkManager-0.7.5-2.2.el5.rf.noarch.rpm yum install perl-Time-HiRes #光盘yum源 tar xzvf mha4mysql-manager-0.56.tar.gz cd mha4mysql-manager-0.56 perl Makefile.PL make && make install####################常用命令###############/usr/local/bin/masterha_check_ssh –conf=/u01/mha/etc/app.cnf/usr/local/bin/masterha_check_repl –conf=/u01/mha/etc/app.cnf/usr/local/bin/masterha_manager –conf=/u01/mha/etc/app.cnf &/u01/mha/etc/masterha_check_status –conf=/u01/mha/etc/app.cnf/usr/local/bin/masterha_stop –conf=/u01/mha/etc/app.cnf###################切换######################一、failover故障切换1.模拟主库宕机 [root@mydb3~]# ssh mydb1 “killall -r mysqld”2.查看管理节点日志,可以看到VIP已经漂移 [root@mydb3 ~]# cat /u01/mha/log/manager.log |grep -i vip3. 验证VIP是否位于节点mydb2 [root@mydb3 ~]# ssh mydb2 “ifconfig |grep 0.201 -B1″4. 查看管理节点MHA切换日志[root@mydb3 ~]# tail /u01/mha/log/manager.log5. new master(old slave)show master statusG6. new slave(old:master) (1)打开MySQL mysqld_safe –defaults-file=/u01/my3306/my.cnf & (2)检查数据库 show master statusG show slave statusG (3)在管理节点日志中查主库的日志文件和位置 cat /u01/mha/etc/app/manager.log |grep -i change (4)在slave连接master CHANGE MASTER TO MASTER_HOST=’192.168.0.21′, MASTER_PORT=3306, MASTER_LOG_FILE=’mysql-bin.000005′, MASTER_LOG_POS=120, MASTER_USER=’repl’, MASTER_PASSWORD=’123456′;7.启动管理节点/usr/local/bin/masterha_manager –conf=/u01/mha/etc/app.cnf &/usr/local/bin/masterha_manager –conf=/u01/mha/etc/app.cnf –ignore_last_failover &二、switchover线上切换1.master:关闭event_scheduler(即192.168.0.21)set global event_scheduler=off;2.manager:关闭管理进程 (即192.168.0.23)/usr/local/bin/masterha_stop –conf=/u01/mha/etc/app.cnf3.manager:检查配置文件/u01/mha/etc/app.cnf 有没有被修改破坏。如果破坏需要重新编辑正确配置文件:/u01/mha/etc/app.cnfcp /u01/mha/etc/app.cnf.bak /u01/mha/etc/app.cnf4.开始切换:/u01/mha/etc/masterha_master_switch –master_state=alive –conf=/u01/mha/etc/app.cnf5.new master(old slave)mysql> show master statusG*************************** 1. row *************************** File: binlog.000021 Position: 299 Binlog_Do_DB:Binlog_Ignore_DB:Executed_Gtid_Set:1 row in set (0.00 sec)6.new slave(old master)CHANGE MASTER TO MASTER_HOST=’192.168.0.22′, MASTER_PORT=3306, MASTER_LOG_FILE=’binlog.000021′, MASTER_LOG_POS=299, MASTER_USER=’repl’, MASTER_PASSWORD=’123456′;mysql> start slave;Query OK, 0 rows affected (0.01 sec)mysql> show slave statusG*************************** 1. row *************************** Slave_IO_State: Waiting for master to send event Master_Host: 192.168.56.12 Master_User: repl Master_Port: 3306 Connect_Retry: 60 Master_Log_File: binlog.000017 Read_Master_Log_Pos: 299 Relay_Log_File: relaylog.000002 Relay_Log_Pos: 280 Relay_Master_Log_File: binlog.000017 Slave_IO_Running: Yes Slave_SQL_Running: Yes7.启动管理节点 /u01/mha/etc/masterha_manager –conf=/u01/mha/etc/app.cnf & /u01/mha/etc/masterha_manager –conf=/u01/mha/etc/app.cnf –remove_dead_master_conf –ignore_last_failover#################配置文件###################vim /u01/mha/etc/app.cnf[server default]user = rootpassword = root123ssh_user = rootrepl_user = reprepl_password = 123456ping_interval = 1ping_type = SELECTmanager_workdir=/u01/mha/etc/appmanager_log=/u01/mha/log/manager.logremote_workdir=/u01/mha/etc/appmaster_binlog_dir=”/u01/my3306/log/binlog”master_ip_failover_script=”/u01/mha/etc/master_ip_failover”master_ip_online_change_script=”/u01/mha/etc/master_ip_failover”shutdown_script=””report_script=””#check_repl_delay=0[server1]hostname=mydb1port=3306master_binlog_dir=”/apps/dbdat/mysql5_data3306/log”candidate_master=1ignore_fail=1[server2]hostname=mydb2port=3306master_binlog_dir=”/u01/my3306/log/binlog”candidate_master=1ignore_fail=1———————————————————————————vim /u01/mha/etc/master_ip_failover#!/usr/bin/env perluse strict;use warnings FATAL => ‘all’;use Getopt::Long;my ( $command, $ssh_user, $orig_master_host, $orig_master_ip, $orig_master_port, $new_master_host, $new_master_ip, $new_master_port);my $vip = ‘192.168.0.201/24’; # Virtual IPmy $key = “1”;my $int = “eth0”;my $ssh_start_vip = “/sbin/ifconfig $int:$key $vip”;my $ssh_stop_vip = “/sbin/ifconfig $int:$key down”;my $arp_effect = “/sbin/arping -Uq -s192.168.0.201 -I $int 192.168.0.1 -c 3”免费主机域名; # Virtual IP and gateway#my $test = “echo successfull >/tmp/test.txt”;$ssh_user = “root”;GetOptions( ‘command=s’ => $command, ‘ssh_user=s’ => $ssh_user, ‘orig_master_host=s’ => $orig_master_host, ‘orig_master_ip=s’ => $orig_master_ip, ‘orig_master_port=i’ => $orig_master_port, ‘new_master_host=s’ => $new_master_host, ‘new_master_ip=s’ => $new_master_ip, ‘new_master_port=i’ => $new_master_port,);exit &main();sub main { print “nnIN SCRIPT TEST====$ssh_stop_vip==$ssh_start_vip===nn”; if ( $command eq “stop” || $command eq “stopssh” ) { # $orig_master_host, $orig_master_ip, $orig_master_port are passed. # If you manage master ip address at global catalog database, # invalidate orig_master_ip here. my $exit_code = 1; eval { print “Disabling the VIP on old master: $orig_master_host n”; &stop_vip(); $exit_code = 0; }; if ($@) { warn “Got Error: $@n”; exit $exit_code; } exit $exit_code; } elsif ( $command eq “start” ) { # all arguments are passed. # If you manage master ip address at global catalog database, # activate new_master_ip here. # You can also grant write access (create user, set read_only=0, etc) here. my $exit_code = 10; eval { print “Enabling the VIP – $vip on the new master – $new_master_host n”; &start_vip(); $exit_code = 0; }; if ($@) { warn $@; exit $exit_code; } exit $exit_code; } elsif ( $command eq “status” ) { print “Checking the Status of the script.. OK n”; #`ssh $ssh_user@cluster1 ” $ssh_start_vip “`; &status(); exit 0; } else { &usage(); exit 1; }}# A simple system call that enable the VIP on the new mastersub start_vip() { `ssh $ssh_user@$new_master_host ” $ssh_start_vip “`; `ssh $ssh_user@$new_master_host ” $arp_effect “`;# `ssh $ssh_user@$new_master_host ” $test “`;}# A simple system call that disable the VIP on the old_mastersub stop_vip() { `ssh $ssh_user@$orig_master_host ” $ssh_stop_vip “`;}sub status() { print `ssh $ssh_user@$orig_master_host ” ip add show $int “`;}sub usage { print “Usage: master_ip_failover –command=start|stop|stopssh|status –orig_master_host=host –orig_master_ip=ip –orig_master_port=port –new_master_host=host –new_master_ip=ip –new_master_port=portn”;}“MHA的安装和部署步骤”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注云技术网站,小编将为大家输出更多高质量的实用文章!

相关推荐: Linux中如何实现程序包管理与使用rpm命令

这篇文章主要为大家展示了“Linux中如何实现程序包管理与使用rpm命令”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下“Linux中如何实现程序包管理与使用rpm命令”这篇文章吧。Linux的程序包管理:程序:指令+…

文章页内容下
赞(0) 打赏
版权声明:本站采用知识共享、学习交流,不允许用于商业用途;文章由发布者自行承担一切责任,与本站无关。
文章页正文下
文章页评论上

云服务器、web空间可免费试用

宝塔面板主机、支持php,mysql等,SSL部署;安全高速企业专供99.999%稳定,另有高防主机、不限制内容等类型,具体可咨询QQ:360163164,Tel同微信:18905205712

主机选购导航云服务器试用

登录

找回密码

注册