mha之vip漂移 配置binlog-server备份服务器 Atlas

 MHAvip漂移

配置

mha之vip漂移 配置binlog-server备份服务器 Atlas_第1张图片

通过MHA自带脚本方式,管理虚拟IP的漂移

获取管理脚本master_ip_failover

cp master_ip_failover /usr/local/bin/     #脚本放在/usr/local/bin/下  记得给脚本X权限
脚本内容
#!/usr/bin/env perl use 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.50.5/24';                  #根据自己的配置修改IP my $key = '0';                           #网卡后缀数值,如果是eth0就是0如果是eth1就是1 my $ssh_start_vip = "/sbin/ifconfig eth0:$key $vip";    #开启vip命令 my $ssh_stop_vip = "/sbin/ifconfig eth0:$key down";   #关闭vip命令 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 { if ( $command eq "stop" || $command eq "stopssh" ) { 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" ) { 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\@$orig_master_host \" $ssh_start_vip \"`; exit 0; } else { &usage(); exit 1; } } sub start_vip() { `ssh $ssh_user\@$new_master_host \" $ssh_start_vip \"`; } sub stop_vip() { `ssh $ssh_user\@$orig_master_host \" $ssh_stop_vip \"`; } 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=port\n"; }

修改mha配置文件

vim /etc/mha/mha1.cnf 
[server default]
manager_log=/var/log/mha/mha1/manager
manager_workdir=/var/log/mha/mha1
master_binlog_dir=/usr/local/mysql/data
master_ip_failover_script=/usr/local/bin/master_ip_failover        #添加脚本位置
password=123456
ping_interval=2
repl_password=123456
repl_user=rep
ssh_user=root
user=mha

[server1]
hostname=192.168.50.149
port=3306

[server2]
hostname=192.168.50.151
port=3306

[server3]
hostname=192.168.50.152
port=3306

[server4]
hostname=192.168.50.153
port=3306

重启动mha管理端完成VIP漂移

ps -ef | grep mha | grep -v grep       #查看mha进程
pkill perl         #杀掉perl进程
nohup masterha_manager --conf=/etc/mha/mha1.cnf --remove_dead_master_conf --ignore_last_failover < /dev/null >/var/log/mha/mha1/manager.log 2>&1 &
            #启动进程

配置binlog-server备份服务器

主库宕机,也许会造成主库binlog复制不及时而导致数据丢失的情况出现,因此配置binlog-server进行时时同步备份,是必要的一种安全手段。

修改mha配置文件

vim /etc/mha/mha1.cnf
在最后添加模块
[binlog1]           #添加binlog模块
no_master=1         #不允许切换为主
hostname=192.168.50.152       #本地IP
master_binlog_dir=/data/mysql/binlog/       #binlog存放位置优先级比全局的高
修改后的文件
[server default] manager_log=/var/log/mha/mha1/manager manager_workdir=/var/log/mha/mha1 master_binlog_dir=/usr/local/mysql/data        #全局binlog存放处 master_ip_failover_script=/usr/local/bin/master_ip_failover password=123456 ping_interval=2 repl_password=123456 repl_user=rep ssh_user=root user=mha [server1] hostname=192.168.50.149 port=3306 [server2] hostname=192.168.50.151 port=3306 [server3] hostname=192.168.50.152 port=3306 [server4] hostname=192.168.50.153 port=3306 [binlog1] no_master=1 hostname=192.168.50.152 master_binlog_dir=/data/mysql/binlog/

拉取主库上的binlog日志到mysql-db03的存放目录里

mkdir -p /data/mysql/binlog    #创建存放目录
cd /data/mysql/binlog/ #进入存放目录
mysqlbinlog -R --host=192.168.50.149 --user=mha --password=123456 --raw --stop-never mysql-bin.000001 &     #拉取主库binlog 主库IP
ll      #查看是否拉取了binlog
ps -ef | grep mysqlbinlog | grep -v grep  #查看拉取进程
nohup masterha_manager --conf=/etc/mha/mha1.cnf --remove_dead_master_conf --ignore_last_failover < /dev/null > /var/log/mha/mha1/manager.log 2>&1 &
      #启动mha进程
ps -ef | grep perl | grep -v grep       #查看mha进程       

mysql中间件Atlas

 Atlas主要功能

  1. 读写分离
  2. 从库负载均衡
  3. IP过滤
  4. 自动分表
  5. DBA可平滑上下线DB
  6. 自动摘除宕机的DB

 安装Atlas

rpm -ivh Atlas-2.2.1.el6.x86_64.rpm 
Preparing...                ########################################### [100%]
    package Atlas-2.2.1-1.x86_64 is already installed

配置Atlas

vim /usr/local/mysql-proxy/conf/test.cnf
    12  proxy-backend-addresses = 192.168.50.5:3306     #这里添加VIP地址
    15  proxy-read-only-backend-addresses = 192.168.50.152:3306@1,192.168.50.151:3306@1 #从库地址
    18  pwds = root:++gAN07C/Q0=,mha:++gAN07C/Q0=   #MySQL授权用户账号密码(密码要加密/usr/local/mysql-proxy/bin/encrypt加密工具来加密30  log-level = error                   #日志级别
    36  sql-log = ON                        #打开日志
    45  proxy-address = 192.168.0.53:33066        #Atlas的工作监听端口(提供代理服务)
    48  admin-address = 192.168.0.53:1234        #Atlas的管理监听端口

启动mysqlbinlog日志备份的进程

mysqlbinlog -R --host=192.168.50.149 --port=3305 --user=mha --password=123456 --raw --stop-never mysql-bin.000001 &
              主库IP 获取binlog日志

启动mha管理进程

nohup masterha_manager --conf=/etc/mha/mha1.cnf --remove_dead_master_conf --ignore_last_failover < /dev/null > /var/log/mha/mha1/manager.log 2>&1 &

启动Atlas服务

/usr/local/mysql-proxy/bin/mysql-proxyd test start
#说明:
#为何启动服务需要加test,因为在Atlas配置文件里定义了一个实例名字为test
#Atlas实际是启动了某个实例(当然也可以多实例)

登陆Atlas管理端口

mysql -uuser -ppwd -P1234 -h 192.168.50.152     #登陆Atlas管理端
select * from backends;         #输入上边列表里的命令,出现下表
+-------------+-------------------+-------+------+
| backend_ndx | address           | state | type |
+-------------+-------------------+-------+------+
|           1 | 192.168.50.149:3307 | up    | rw   |      #主库读写
|           2 | 192.168.50.151:3307 | up    | ro   |      #从库读
|           3 | 192.168.50.152:3307 | up    | ro   |      #从库读
+-------------+-------------------+-------+------+

在mysql-db03的本地登陆Atlas代理的3306端口

mysql -uroot -p123456 -h192.168.50.152
#必须创建用户root 且 host写成192.168.50.%才能使用
此时 atlas里授权的账号已实现读写分离  读负载均衡

 

转载于:https://www.cnblogs.com/ywrj/p/9443215.html

你可能感兴趣的:(mha之vip漂移 配置binlog-server备份服务器 Atlas)