久久精品人人爽,华人av在线,亚洲性视频网站,欧美专区一二三

mysql下MHA搭建過程

166次閱讀
沒有評論

共計 6561 個字符,預(yù)計需要花費 17 分鐘才能閱讀完成。

這篇文章主要介紹“mysql 下 MHA 搭建過程”,在日常操作中,相信很多人在 mysql 下 MHA 搭建過程問題上存在疑惑,丸趣 TV 小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”mysql 下 MHA 搭建過程”的疑惑有所幫助!接下來,請跟著丸趣 TV 小編一起來學(xué)習(xí)吧!

環(huán)境

1 主 2 從,manager 放在從庫

主庫:192.168.137.201

從庫(manager):192.168.137.202

從庫:192.168.137.203

需要的軟件包:

epel-release-7-10.noarch.rpm

mha4mysql-node-0.56.tar.gz

mha4mysql-manager-0.56.tar.gz

mysql-5.7.14-linux-glibc2.5-x86_64.tar.gz

主從搭建

創(chuàng)建用戶

create user repl @ % identified by repl

grant all on *.* to  repl @ %

create user root @ % identified by root

grant all on *.* to  root @ %

建立主從

CHANGE MASTER TO

  MASTER_HOST= 192.168.137.201 ,

  MASTER_USER= repl ,

  MASTER_PASSWORD= repl ,

  MASTER_PORT=3306,

  master_auto_position=1;

配置 ssh 互相信任

c1 服務(wù)器

[root@c1 ~]# ssh-keygen -t rsa

[root@c1 ~]# ssh-copy-id -i /root/.ssh/id_rsa.pub root@192.168.137.201

[root@c1 ~]# ssh-copy-id -i /root/.ssh/id_rsa.pub root@192.168.137.202

[root@c1 ~]# ssh-copy-id -i /root/.ssh/id_rsa.pub root@192.168.137.203

c2 服務(wù)器

[root@c2 ~]# ssh-keygen -t rsa

[root@c2 ~]# ssh-copy-id -i /root/.ssh/id_rsa.pub root@192.168.137.201

[root@c2 ~]# ssh-copy-id -i /root/.ssh/id_rsa.pub root@192.168.137.202

[root@c2 ~]# ssh-copy-id -i /root/.ssh/id_rsa.pub root@192.168.137.203

c3 服務(wù)器

[root@c3 ~]# ssh-keygen -t rsa

[root@c3 ~]# ssh-copy-id -i /root/.ssh/id_rsa.pub root@192.168.137.201

[root@c3 ~]# ssh-copy-id -i /root/.ssh/id_rsa.pub root@192.168.137.202

[root@c3 ~]# ssh-copy-id -i /root/.ssh/id_rsa.pub root@192.168.137.203

安裝 MHA 軟件

安裝 epel 源(所有節(jié)點)

centos6

 rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

centos7

 rpm -ivh http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-10.noarch.rpm

安裝 MHA 軟件

安裝依賴包(所有節(jié)點)

yum install perl-DBD-MySQL perl-Config-Tiny perl-Log-Dispatch perl-Parallel-ForkManager perl-Time-HiRes perl-ExtUtils-CBuilder perl-ExtUtils-MakeMaker perl-CPAN net-tools -y

epel 源的所有 epel,epel-debuginfo,epel-source,都啟用

軟件下載

MHA 軟件下載

https://downloads.mariadb.com/MHA/

https://github.com/yotoobo/linux/tree/master/mha

安裝 MHA-node(所有節(jié)點)

tar zxf mha4mysql-node-0.56.tar.gz

cd mha4mysql-node-0.56

perl Makefile.PL

make make install

安裝 MHA-manager(202)

tar zxf mha4mysql-manager-0.56.tar.gz

cd mha4mysql-manager-0.56

perl Makefile.PL

make make install

配置 MHA-manager-conf 文件(202)

vi /data/mha/3306/log/mha.cnf

[server default]

client_bindir=/usr/local/mysql/bin/

manager_log=/data/mha/3306/log/manager.log

manager_workdir=/data/mha/3306/log

master_binlog_dir=/data/mysql/mysql3306/logs

master_ip_failover_script=/usr/local/bin/master_ip_failover

master_ip_online_change_script=/usr/local/bin/master_ip_online_change

report_script=/usr/local/bin/send_report

#init_conf_load_script=/usr/local/bin/load_cnf

remote_workdir=/data/mysql/mysql3306/tmp

#secondary_check_script= /usr/local/bin/masterha_secondary_check -s 192.168.137.201 -s 192.168.137.202

user=root

password=root

ping_interval=3

repl_user=repl

repl_password=repl

ssh_port=22

ssh_user=root

#max_ping_errors=40

[server1]

hostname=192.168.137.201

port=3306

[server2]

#check_repl_delay=0

hostname=192.168.137.202

port=3306

[server3]

candidate_master=1

check_repl_delay=0

hostname=192.168.137.203

port=3306

設(shè)置從庫 readonly(所有從庫)

mysql show global variables like %read_only%

mysql flush tables with read lock;

mysql set global read_only=1;

mysql show global variables like %read_only%

拷貝腳本

cp /usr/local/mha_manager/samples/scripts/master_ip_failover /usr/local/bin/

cp /usr/local/mha_manager/samples/scripts/master_ip_online_change /usr/local/bin/

cp /usr/local/mha_manager/samples/scripts/power_manager /usr/local/bin/

cp /usr/local/mha_manager/samples/scripts/send_report /usr/local/bin/

修改 master_ip_failover 腳本

原腳本中無 VIP 切換

#!/usr/bin/env perl

#  Copyright (C) 2011 DeNA Co.,Ltd.

#

#  This program is free software; you can redistribute it and/or modify

#  it under the terms of the GNU General Public License as published by

#  the Free Software Foundation; either version 2 of the License, or

#  (at your option) any later version.

#

#  This program is distributed in the hope that it will be useful,

#  but WITHOUT ANY WARRANTY; without even the implied warranty of

#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the

#  GNU General Public License for more details.

#

#  You should have received a copy of the GNU General Public License

#   along with this program; if not, write to the Free Software

#  Foundation, Inc.,

#  51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

## Note: This is a sample script and is not complete. Modify the script based on your environment.

use strict;

use warnings FATAL = all

use Getopt::Long;

use MHA::DBHelper;

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.137.88/24

my $key= 1

my $ssh_start_vip = /sbin/ifconfig ens33:$key $vip

my $ssh_stop_vip= /sbin/ifconfig ens33:$key down

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) {

    # $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 $@;

      # If you want to continue failover, exit 10.

      exit $exit_code;

    }

    exit $exit_code;

  }

  elsif ($command eq status) {

    print Checking the Status of the script.. ok \n

    # do nothing

    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

}

檢測配置文件(202 節(jié)點)

[root@c2 ~]# masterha_check_repl –conf=/data/mha/3306/log/mha.cnf

主庫添加 VIP

[root@c1 ~]# ifconfig ens33:1 192.168.137.88/16

或者 /sbin/ip addr add 192.168.137.88/32 dev ens33

刪除 VIP  ifconfig ens33:1 down

/sbin/ip addr del 192.168.137.88/32 dev ens33

MHA manager 啟動和關(guān)閉

[root@c2 ~]#  nohup masterha_manager –conf=/data/mha/3306/log/mha.cnf /dev/null /data/mha/3306/log/manager.log 2 1

[root@c2 ~]#  masterha_stop –conf=/data/mha/3306/log/mha.cnf

注意項

所有主從數(shù)據(jù)完全一致,包含業(yè)務(wù)數(shù)據(jù)和系統(tǒng)表數(shù)據(jù),不然會導(dǎo)致故障切換途中,無法切到新主庫中

切換 VIP 時,需要各個服務(wù)器都有 net-tools 包,能夠執(zhí)行 ifconfig

到此,關(guān)于“mysql 下 MHA 搭建過程”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識,請繼續(xù)關(guān)注丸趣 TV 網(wǎng)站,丸趣 TV 小編會繼續(xù)努力為大家?guī)砀鄬嵱玫奈恼拢?/p>

正文完
 
丸趣
版權(quán)聲明:本站原創(chuàng)文章,由 丸趣 2023-08-01發(fā)表,共計6561字。
轉(zhuǎn)載說明:除特殊說明外本站除技術(shù)相關(guān)以外文章皆由網(wǎng)絡(luò)搜集發(fā)布,轉(zhuǎn)載請注明出處。
評論(沒有評論)
主站蜘蛛池模板: 丹巴县| 桐梓县| 易门县| 邢台市| 土默特左旗| 涟水县| 灌南县| 舞钢市| 大理市| 房产| 湘乡市| 三门县| 抚松县| 海南省| 桐柏县| 中西区| 鹰潭市| 青川县| 兴城市| 金寨县| 太白县| 石景山区| 淮滨县| 河池市| 河北区| 东乌| 喀喇| 永昌县| 融水| 武定县| 隆回县| 开平市| 阳西县| 潮州市| 明水县| 汽车| 邵武市| 北京市| 安福县| 沙雅县| 德保县|