中文字幕日韩精品一区二区免费_精品一区二区三区国产精品无卡在_国精品无码专区一区二区三区_国产αv三级中文在线

MHA的安裝和部署步驟-創(chuàng)新互聯(lián)

本篇內(nèi)容介紹了“MHA的安裝和部署步驟”的有關(guān)知識,在實際案例的操作過程中,不少人都會遇到這樣的困境,接下來就讓小編帶領(lǐng)大家學(xué)習(xí)一下如何處理這些情況吧!希望大家仔細(xì)閱讀,能夠?qū)W有所成!

創(chuàng)新互聯(lián)服務(wù)項目包括日照網(wǎng)站建設(shè)、日照網(wǎng)站制作、日照網(wǎng)頁制作以及日照網(wǎng)絡(luò)營銷策劃等。多年來,我們專注于互聯(lián)網(wǎng)行業(yè),利用自身積累的技術(shù)優(yōu)勢、行業(yè)經(jīng)驗、深度合作伙伴關(guān)系等,向廣大中小型企業(yè)、政府機(jī)構(gòu)等提供互聯(lián)網(wǎng)行業(yè)的解決方案,日照網(wǎng)站推廣取得了明顯的社會效益與經(jīng)濟(jì)效益。目前,我們服務(wù)的客戶以成都為中心已經(jīng)輻射到日照省份的部分城市,未來相信會繼續(xù)擴(kuò)大服務(wù)區(qū)域并繼續(xù)獲得客戶的支持與信任!

##################MHA安裝和部署####################

1.服務(wù)器

 192.168.0.21 mydb1   #Master

 192.168.0.22 mydb2   #Slave

 192.168.0.23 mydb3   #MHA manager

2. 所有機(jī)器修改vim /etc/hosts

192.168.0.21   mydb1

192.168.0.22   mydb2

192.168.0.23   mydb3

3.設(shè)置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 mydb3

4.下載mha4mysql-manager和mha4mysql-node

   https://github.com/yoshinorim/mha4mysql-manager

   https://github.com/yoshinorim/mha4mysql-node

 5.在三個節(jié)點(node 和 manager)安裝perl-DBD-MySQL,用光盤作yum源,#包括了3個包:Perl-DBD-MySQL,mysql-libs,perl-DBI

   yum install perl-DBD-MySQL

   yum install perl-DBI 

   yum install mysql-libs

 6.在三個節(jié)點安裝node(包括管理節(jié)點)

  tar xzvf mha4mysql-node-0.56.tar.gz

  cd mha4mysql-node-0.56

  perl Makefile.PL

  make && make install

 7.在管理節(jié)點安裝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.模擬主庫宕機(jī)

   [root@mydb3~]# ssh mydb1 "killall -r mysqld"

 2.查看管理節(jié)點日志,可以看到VIP已經(jīng)漂移

  [root@mydb3 ~]# cat /u01/mha/log/manager.log |grep -i vip

 3. 驗證VIP是否位于節(jié)點mydb2

  [root@mydb3 ~]# ssh mydb2 "ifconfig |grep 0.201 -B1"

 4. 查看管理節(jié)點MHA切換日志

 [root@mydb3 ~]# tail /u01/mha/log/manager.log

 5. new master(old slave)

 show master status\G

 6. new slave(old:master)

     (1)打開MySQL

        mysqld_safe --defaults-file=/u01/my3306/my.cnf &

     (2)檢查數(shù)據(jù)庫

        show master status\G

        show slave  status\G

     (3)在管理節(jié)點日志中查主庫的日志文件和位置

        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.啟動管理節(jié)點

 /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:關(guān)閉event_scheduler(即192.168.0.21) 

set global event_scheduler=off;

2.manager:關(guān)閉管理進(jìn)程 (即192.168.0.23)

/usr/local/bin/masterha_stop --conf=/u01/mha/etc/app.cnf

3.manager:檢查配置文件

/u01/mha/etc/app.cnf  有沒有被修改破壞。如果破壞需要重新編輯正確配置文件:/u01/mha/etc/app.cnf

cp /u01/mha/etc/app.cnf.bak /u01/mha/etc/app.cnf

4.開始切換:

/u01/mha/etc/masterha_master_switch --master_state=alive --conf=/u01/mha/etc/app.cnf

5.new master(old slave)

 mysql> show master status\G

*************************** 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 status\G

*************************** 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: Yes

7.啟動管理節(jié)點

   /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 = root

password = root123

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="/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=mydb1

port=3306

master_binlog_dir="/apps/dbdat/mysql5_data3306/log"

candidate_master=1

ignore_fail=1

[server2]

hostname=mydb2

port=3306

master_binlog_dir="/u01/my3306/log/binlog"

candidate_master=1

ignore_fail=1

---------------------------------------------------------------------------------

vim /u01/mha/etc/master_ip_failover

#!/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.0.201/24';  # Virtual IP

my $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 gat

eway

#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 "\n\nIN SCRIPT TEST====$ssh_stop_vip==$ssh_start_vip===\n\n";

    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 master

sub 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_master

sub 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_maste

r_ip=ip --orig_master_port=port --new_master_host=host --new_master_ip=ip --new_master_port=port\n";

}

“MHA的安裝和部署步驟”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識可以關(guān)注創(chuàng)新互聯(lián)-成都網(wǎng)站建設(shè)公司網(wǎng)站,小編將為大家輸出更多高質(zhì)量的實用文章!

新聞名稱:MHA的安裝和部署步驟-創(chuàng)新互聯(lián)
當(dāng)前網(wǎng)址:http://www.rwnh.cn/article22/cegocc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供營銷型網(wǎng)站建設(shè)自適應(yīng)網(wǎng)站、搜索引擎優(yōu)化軟件開發(fā)、企業(yè)網(wǎng)站制作網(wǎng)站導(dǎo)航

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

成都定制網(wǎng)站建設(shè)
泌阳县| 丹阳市| 龙胜| 宣城市| 绥德县| 汉寿县| 武义县| 谷城县| 江都市| 日喀则市| 故城县| 吴川市| 辉县市| 尼木县| 建平县| 克山县| 阿坝县| 北海市| 丹寨县| 邢台县| 历史| 高州市| 温州市| 延吉市| 房山区| 平阳县| 利辛县| 营山县| 齐齐哈尔市| 清丰县| 满城县| 鹤山市| 平顺县| 宁陕县| 宽城| 九台市| 德钦县| 盐源县| 咸丰县| 益阳市| 常州市|