当前位置:   article > 正文

Docker下centos6 + mha全记录

Docker下centos6 + mha全记录

1,初始化3个镜像

[root@centos7 ~]# docker run -i -t -d --name mysql-manager centos:6 /bin/bash
89bc67b37fa0cb5c90785a92d531a332a028a964aca8142101c0081cb3172269
[root@centos7 ~]# docker run -i -t -d --name mysql-master centos:6 /bin/bash     
8264bc3a078401367da7a74ffcd131737170ad61b6db4307eba95bf20625c749
[root@centos7 ~]# docker run -i -t -d --name mysql-slave centos:6 /bin/bash      
ef4c72d4fdc92675f4938f150d96d5752854dab2f13a4730033a8b3381fea815

生成3台机器,分别是

172.17.0.2 mysql-manager

172.17.0.3 mysql-master

172.17.0.4 mysql-slave



2. 安装包

3台机器上安装

yum install -y initscripts
yum install -y openssh-server
yum install -y net-tools
yum groupinstall -y "Development Tools"
yum install -y zip unzip wget

在mysql-master和mysql-slave上安装mysql;
yum install mysql mysql-server mysql-devel -y


3. 三台机器上启用sshd服务

service sshd start


4. 构建免登(mysql-manager --> mysql-master/mysql-slave, mysql-master  <-->  mysql-slave)

参考: http://chenlb.iteye.com/blog/211809


拷贝公钥的时候可以用scp命令: scp id_rsa.pub root@172.17.0.3:/root/.ssh


5. hosts文件里面添加主机名

/etc/hosts 文件里面添加

172.17.0.2 mysql-manager

172.17.0.3 mysql-master

172.17.0.4 mysql-slave



6. 主从上都启用mysql: service mysqld start

主从配置参考: http://blog.csdn.net/xinglu/article/details/69096832


7. 3个节点上,安装mha-node

安装

yum install -y perl-DBD-MySQL
   yum install -y perl-DBI 
   yum install -y mysql-libs
   yum install -y perl-Config-Tiny
   yum install -y perl-Params-Validate
   yum install -y perl-MIME-Types
   yum install -y perl-Email-Date-Format
   yum install -y perl-Mail-Sender
   yum install -y perl-Mail-Sendmail
   yum install -y perl-TimeDate
   yum install -y perl-MailTools
   yum install -y perl-MIME-Lite
   yum install -y perl-Log-Dispatch
   yum install -y perl-Parallel-ForkManager
   yum install -y perl-Time-HiRes


上面有4个无法通过yum安装,需要手动下载安装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-Log-Dispatch-2.26-1.el5.rf.noarch.rpm 
   rpm -ivh perl-Parallel-ForkManager-0.7.5-2.2.el5.rf.noarch.rpm


参考: http://blog.csdn.net/melody_mr/article/details/38122225

yum install cpan -y
yum install perl-ExtUtils-CBuilder perl-ExtUtils-MakeMaker -y
yum install perl-ExtUtils-Embed -y

cpan ExtUtils::Install

其中执行cpan的时候遇到网络不好,下载两个gz文件很慢的时候, 不如在外面用迅雷下载,然后复制到对应的docker机的目录里面,具体路径看命令行的提示

开始安装node, 如果报什么Can't locate, 参考上面的做法

tar xvf mha4mysql-node-0.56.tar.gz

cd mha4mysql-node-0.56

perl Makefile.PL
make && make install


同样在manager节点也用上述方法安装

安装完后应该有以下可执行文件

-r-xr-xr-x. 1 root root 16346 Apr  8 11:02 apply_diff_relay_logs
-r-xr-xr-x. 1 root root  4807 Apr  8 11:02 filter_mysqlbinlog
-r-xr-xr-x. 1 root root  1995 Apr  8 14:42 masterha_check_repl
-r-xr-xr-x. 1 root root  1779 Apr  8 14:42 masterha_check_ssh
-r-xr-xr-x. 1 root root  1865 Apr  8 14:42 masterha_check_status
-r-xr-xr-x. 1 root root  3201 Apr  8 14:42 masterha_conf_host
-r-xr-xr-x. 1 root root  2517 Apr  8 14:42 masterha_manager
-r-xr-xr-x. 1 root root  2165 Apr  8 14:42 masterha_master_monitor
-r-xr-xr-x. 1 root root  2373 Apr  8 14:42 masterha_master_switch
-r-xr-xr-x. 1 root root  3879 Apr  8 14:42 masterha_secondary_check
-r-xr-xr-x. 1 root root  1739 Apr  8 14:42 masterha_stop
-r-xr-xr-x. 1 root root  7401 Apr  8 11:02 purge_relay_logs
-r-xr-xr-x. 1 root root  7395 Apr  8 11:02 save_binary_logs

在node上面有

-r-xr-xr-x. 1 root root 16346 Apr  8 11:06 apply_diff_relay_logs
-r-xr-xr-x. 1 root root  4807 Apr  8 11:06 filter_mysqlbinlog
-r-xr-xr-x. 1 root root  7401 Apr  8 11:06 purge_relay_logs
-r-xr-xr-x. 1 root root  7395 Apr  8 11:06 save_binary_logs


8. 创建mha manager目录

[root@89bc67b37fa0 bin]# mkdir -p /u01/mha/etc/{app,log}

在 /u01/mha/etc/新建app.cnf配置文件


app.cnf如下

[server default]
user = root
password = 123456
ssh_user = root
repl_user = rep
repl_password = 123456
ping_interval = 1
ping_type = SELECT

manager_workdir=/u01/mha/etc/app
manager_log=/u01/mha/log/manager.log
remote_workdir=/u01/mha/etc/app
master_binlog_dir="/var/lib/mysql/"

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=mysql-master
port=3306
master_binlog_dir="/var/lib/mysql/"
candidate_master=1
ignore_fail=1

[server2]
hostname=mysql-slave
port=3306
master_binlog_dir="/var/lib/mysql/"
candidate_master=1
ignore_fail=1




9. 执行 检查脚本

[root@89bc67b37fa0 etc]# /usr/local/bin/masterha_check_ssh --conf=/u01/mha/etc/app.cnf
Sat Apr  8 15:52:47 2017 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
Sat Apr  8 15:52:47 2017 - [info] Reading application default configurations from /u01/mha/etc/app.cnf..
Sat Apr  8 15:52:47 2017 - [info] Reading server configurations from /u01/mha/etc/app.cnf..
Sat Apr  8 15:52:47 2017 - [info] Starting SSH connection tests..
Sat Apr  8 15:52:47 2017 - [debug] 
Sat Apr  8 15:52:47 2017 - [debug]  Connecting via SSH from root@mysql-master(172.17.0.3:22) to root@mysql-slave(172.17.0.4:22)..
Sat Apr  8 15:52:47 2017 - [debug]   ok.
Sat Apr  8 15:52:48 2017 - [debug] 
Sat Apr  8 15:52:47 2017 - [debug]  Connecting via SSH from root@mysql-slave(172.17.0.4:22) to root@mysql-master(172.17.0.3:22)..
Sat Apr  8 15:52:48 2017 - [debug]   ok.
Sat Apr  8 15:52:48 2017 - [info] All SSH connection tests passed successfully.
[root@89bc67b37fa0 etc]# 


[root@89bc67b37fa0 mha]# /usr/local/bin/masterha_manager --conf=/u01/mha/etc/app.cnf &
[1] 5074
[root@89bc67b37fa0 mha]# Sat Apr  8 16:17:14 2017 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
Sat Apr  8 16:17:14 2017 - [info] Reading application default configurations from /u01/mha/etc/app.cnf..
Sat Apr  8 16:17:14 2017 - [info] Reading server configurations from /u01/mha/etc/app.cnf..


[root@89bc67b37fa0 mha]# ps -ef
UID        PID  PPID  C STIME TTY          TIME CMD
root         1     0  0 10:03 ?        00:00:00 /bin/bash
root        67     1  0 10:10 ?        00:00:00 /sbin/udevd -d
root       313     1  0 10:18 ?        00:00:00 /usr/sbin/sshd
root      5074     1  2 16:17 ?        00:00:00 perl /usr/local/bin/masterha_manager --conf=/u01/mha/etc/app.cnf
root      5095  5074  0 16:17 ?        00:00:00 sh -c /u01/mha/etc/master_ip_failover --command=status --ssh_user=root --orig_master_host=mysql-master --o
root      5096  5095  3 16:17 ?        00:00:00 perl /u01/mha/etc/master_ip_failover --command=status --ssh_user=root --orig_master_host=mysql-master --or
root      5097  5096  0 16:17 ?        00:00:00 ssh -o ServerAliveInterval=60 -o ServerAliveCountMax=20 -o StrictHostKeyChecking=no -o ConnectionAttempts=
root      5098     1  0 16:17 ?        00:00:00 ps -ef
[root@89bc67b37fa0 mha]# 





10

后面没做成功, 主从切换有点问题, 等后续我有时间再补上


声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/秋刀鱼在做梦/article/detail/946441
推荐阅读
相关标签
  

闽ICP备14008679号