Ubuntu MYSQL5.5 MHA+半同步复制+keepalive

ubuntu 12.04 MYSQL MHA

半同步复制+MHA+keepalive无缝隙故障转移

准备四台机器,做个完整的实验,其实三台也行。我就只弄了3台。。。。。。建议还是弄四台  单独拿一台做manager,而且这台机器最好不要有MySQL的服务(生产环境一定要切记)

虚拟机 2个IP  一内一外


做好无验证KEY登陆

我的内网环境IP  

192.168.10.100   主MASTER

192.168.10.101   备MASTER

192.168.10.102   从库1


ssh-keygen -t rsa    |     ssh-copy-id -i /root/.ssh/id_rsa.pub root@192.168.10.101


安装MYSQL 5.5 自己编译吧

apt-get install build-essential libncurses5-dev cmake -y

useradd mysql

我编译环境是GBK的 估计大家也都是用的GBK吧

cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_UNIX_ADDR=/usr/local/mysql/tmp/mysql.sock -DDEFAULT_CHARSET=gbk -DDEFAULT_COLLATION=gbk_chinese_ci -DDEFALUT_CHARSETS=utf8,gbk,gb2312,latin1 -DWITH_EXTRA_CHARSETS=all -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1 -DMYSQL_DATADIR=/usr/local/mysql/mysql_data -DMYSQL_USER=mysql -DMYSQL_TCP_PORT=3306 -DSYSCONFDIR=/etc


make && make install


初始化,,,,,,,,,启动MYSQL


开始半同步复制吧

******************************

192.168.10.100  MHA-m 主库  **

****************************************************************************

mysql> install plugin rpl_semi_sync_master soname 'semisync_master.so';

Query OK, 0 rows affected (0.05 sec)


mysql> set global rpl_semi_sync_master_enabled=1;

Query OK, 0 rows affected (0.00 sec)


mysql> set global rpl_semi_sync_master_timeout=1000;

Query OK, 0 rows affected (0.00 sec)


mysql> show global status like 'rpl%';

+--------------------------------------------+-------------+

| Variable_name                              | Value       |

+--------------------------------------------+-------------+

| Rpl_semi_sync_master_clients               | 0           |

| Rpl_semi_sync_master_net_avg_wait_time     | 0           |

| Rpl_semi_sync_master_net_wait_time         | 0           |

| Rpl_semi_sync_master_net_waits             | 0           |

| Rpl_semi_sync_master_no_times              | 0           |

| Rpl_semi_sync_master_no_tx                 | 0           |

| Rpl_semi_sync_master_status                | ON          |

| Rpl_semi_sync_master_timefunc_failures     | 0           |

| Rpl_semi_sync_master_tx_avg_wait_time      | 0           |

| Rpl_semi_sync_master_tx_wait_time          | 0           |

| Rpl_semi_sync_master_tx_waits              | 0           |

| Rpl_semi_sync_master_wait_pos_backtraverse | 0           |

| Rpl_semi_sync_master_wait_sessions         | 0           |

| Rpl_semi_sync_master_yes_tx                | 0           |

| Rpl_status                                 | AUTH_MASTER |

+--------------------------------------------+-------------+

15 rows in set (0.02 sec)


mysql> grant replication slave on *.* to boge@'192.168.10.%' identified by 'boge';         

Query OK, 0 rows affected (0.00 sec)


mysql> show master status;

+------------------+----------+--------------+------------------+

| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |

+------------------+----------+--------------+------------------+

| mysql-bin.000005 |      404 |              |                  |

+------------------+----------+--------------+------------------+

1 row in set (0.00 sec)


/etc/my.cnf 在[mysqld]添加

rpl_semi_sync_master_enabled=1

rpl_semi_sync_master_timeout=1000


***************************************************************************

192.168.10.101  MHA-b 备用主库  **

************************************************************************

mysql> install plugin rpl_semi_sync_master soname 'semisync_master.so';

Query OK, 0 rows affected (0.04 sec)


mysql> set global rpl_semi_sync_master_enabled=1;

Query OK, 0 rows affected (0.00 sec)


mysql> set global rpl_semi_sync_master_timeout=1000;

Query OK, 0 rows affected (0.00 sec)


mysql> install plugin rpl_semi_sync_slave soname 'semisync_slave.so';

Query OK, 0 rows affected (0.00 sec)


mysql> set global rpl_semi_sync_slave_enabled=1;

Query OK, 0 rows affected (0.00 sec)


mysql> show global status like 'rpl%';

+--------------------------------------------+-------------+

| Variable_name                              | Value       |

+--------------------------------------------+-------------+

| Rpl_semi_sync_master_clients               | 0           |

| Rpl_semi_sync_master_net_avg_wait_time     | 0           |

| Rpl_semi_sync_master_net_wait_time         | 0           |

| Rpl_semi_sync_master_net_waits             | 0           |

| Rpl_semi_sync_master_no_times              | 0           |

| Rpl_semi_sync_master_no_tx                 | 0           |

| Rpl_semi_sync_master_status                | ON          |

| Rpl_semi_sync_master_timefunc_failures     | 0           |

| Rpl_semi_sync_master_tx_avg_wait_time      | 0           |

| Rpl_semi_sync_master_tx_wait_time          | 0           |

| Rpl_semi_sync_master_tx_waits              | 0           |

| Rpl_semi_sync_master_wait_pos_backtraverse | 0           |

| Rpl_semi_sync_master_wait_sessions         | 0           |

| Rpl_semi_sync_master_yes_tx                | 0           |

| Rpl_semi_sync_slave_status                 | OFF         |

| Rpl_status                                 | AUTH_MASTER |

+--------------------------------------------+-------------+

16 rows in set (0.01 sec)


mysql> change master to master_host="192.168.10.100",master_user="boge",master_password="boge",master_log_file="mysql-bin.000005",master_log_pos=404;

Query OK, 0 rows affected (0.02 sec)


mysql> grant replication slave on *.* to boge@'192.168.10.%' identified by 'boge';  

Query OK, 0 rows affected (1.00 sec)


/etc/my.cnf 在[mysqld]添加

rpl_semi_sync_master_enabled=1

rpl_semi_sync_master_timeout=1000

rpl_semi_sync_slave_enabled=1


***************************************************************

192.168.10.102   从库1  **

********************************************************

mysql> install plugin rpl_semi_sync_slave soname 'semisync_slave.so';

Query OK, 0 rows affected (0.03 sec)


mysql> set global rpl_semi_sync_slave_enabled=1;

Query OK, 0 rows affected (0.00 sec)


mysql> show global status like 'rpl%';

+----------------------------+-------------+

| Variable_name              | Value       |

+----------------------------+-------------+

| Rpl_semi_sync_slave_status | OFF         |

| Rpl_status                 | AUTH_MASTER |

+----------------------------+-------------+

2 rows in set (0.01 sec)


mysql> change master to master_host="192.168.10.100",master_user="boge",master_password="boge",master_log_file="mysql-bin.000005",master_log_pos=404;

Query OK, 0 rows affected (0.02 sec)


/etc/my.cnf 在[mysqld]添加

rpl_semi_sync_slave_enabled=1

relay_log_purge=0

read_only=1


***********************************************************************************

同步正常后到主库 192.168.10.100上


mysql> show global status like 'rpl%';

+--------------------------------------------+-------------+

| Variable_name                              | Value       |

+--------------------------------------------+-------------+

| Rpl_semi_sync_master_clients               | 2           |

| Rpl_semi_sync_master_net_avg_wait_time     | 0           |

| Rpl_semi_sync_master_net_wait_time         | 0           |

| Rpl_semi_sync_master_net_waits             | 0           |

| Rpl_semi_sync_master_no_times              | 0           |

| Rpl_semi_sync_master_no_tx                 | 0           |

| Rpl_semi_sync_master_status                | ON          |

| Rpl_semi_sync_master_timefunc_failures     | 0           |

| Rpl_semi_sync_master_tx_avg_wait_time      | 0           |

| Rpl_semi_sync_master_tx_wait_time          | 0           |

| Rpl_semi_sync_master_tx_waits              | 0           |

| Rpl_semi_sync_master_wait_pos_backtraverse | 0           |

| Rpl_semi_sync_master_wait_sessions         | 0           |

| Rpl_semi_sync_master_yes_tx                | 0           |

| Rpl_status                                 | AUTH_MASTER |

+--------------------------------------------+-------------+

15 rows in set (0.00 sec)


##########################################################################


Rpl_semi_sync_master_clients :

记录支持半同步的slave的个数。


Rpl_semi_sync_master_net_avg_wait_time :

master 等待slave 回复的平均等待时间。 单位毫秒.


Rpl_semi_sync_master_net_wait_time :

master 总的等待时间。


Rpl_semi_sync_master_net_waits :

master 等待slave 回复的的总的等待次数。


Rpl_semi_sync_master_no_times :

master 关闭半同步复制的次数。


Rpl_semi_sync_master_no_tx :

master 没有收到slave的回复而提交的次数,(应该可以理解为master 等待超时的次数)


Rpl_semi_sync_master_status :

标记master现在是否是半同步复制状态。


Rpl_semi_sync_master_timefunc_failures :

The number of times the master failed when calling time functions such as gettimeofday().

master 调用函数失败的次数


Rpl_semi_sync_master_tx_avg_wait_time :

master 花在每个事务上的平均等待时间。


Rpl_semi_sync_master_tx_wait_time :

master 总的等待次数。


Rpl_semi_sync_master_wait_pos_backtraverse:

我理解的意思就是后来的先到了,而先来的还没有到的次数。

The total number of times the master waited for an event with binary coordinates lower than events waited for previously. This can occur when

the order in which transactions start waiting for a reply is different from the order in which their binary log events are written.


Rpl_semi_sync_master_wait_sessions:

当前有多少个session 因为slave 的回复而造成等待。


Rpl_semi_sync_master_yes_tx :

master 成功接收到slave的回复的次数。


Rpl_semi_sync_slave_status :

标记slave 是否在半同步状态。


++++++++++++++++++++++++++++++++++++++++++++++++++++++

MHA的配置

++++++++++++++++++++++++++++++++++++++++++++++++++++++

https://code.google.com/p/mysql-master-ha/downloads/list

下载node包和manager的包   我是Ubuntu的 下的这2个

*****************************************

mha4mysql-node_0.54-0_all.deb

mha4mysql-manager_0.55-0_all.deb

*****************************************

在master上安装

mha4mysql-node_0.54-0_all.deb

mha4mysql-manager_0.55-0_all.deb

/

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

在备用master和slave上安装

mha4mysql-node_0.54-0_all.deb

==================================================

mkdir -p /mysqlHA/


[server default]

manager_workdir=/mysqlHA

manager_log=/mysqlHA/manager.log

#remote_workdir=/usr/local/mysql

#mysql user and password

user=root

password=

ssh_user=root

repl_user=boge

repl_password=boge

ping_interval=1

shutdown_script=""

#master_ip_failover_script=/usr/local/bin/master_ip_failover

#master_ip_online_change_script=/usr/local/bin/master_ip_online_change_script

#report_script=""


[server1]

hostname=192.168.10.100

master_binlog_dir=/mysql_data/3306

candidate_master=1


[server2]

hostname=192.168.10.101

master_binlog_dir=/mysql_data/3306

candidate_master=1

[server3]


hostname=192.168.10.102

master_binlog_dir=/mysql_data/3306

no_master=1

######################################################################################

先给MySQL加好权限吧,因为涉及到故障转移所以必须是super的权限,那么就用root吧

grant all on *.* to root@'192.168.10.%' identified by 'boge';

每个实列上都要执行

我这里只用了3台机器的弊端就来了,在manager这台机器上需要给自己一个公钥然后能ssh 192.168.10.100来访问自己才能过的了ssh的检测

*********************************************************************************************

root@HMA-m:/mysqlHA# masterha_check_ssh --conf=/etc/myHA.cnf  

   

Tue May  6 00:17:12 2014 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.

Tue May  6 00:17:12 2014 - [info] Reading application default configurations from /etc/myHA.cnf..

Tue May  6 00:17:12 2014 - [info] Reading server configurations from /etc/myHA.cnf..

Tue May  6 00:17:12 2014 - [info] Starting SSH connection tests..

Tue May  6 00:17:14 2014 - [debug] 

Tue May  6 00:17:12 2014 - [debug]  Connecting via SSH from root@192.168.10.100(192.168.10.100:22) to root@192.168.10.101(192.168.10.101:22)..

Tue May  6 00:17:12 2014 - [debug]   ok.

Tue May  6 00:17:12 2014 - [debug]  Connecting via SSH from root@192.168.10.100(192.168.10.100:22) to root@192.168.10.102(192.168.10.102:22)..

Tue May  6 00:17:14 2014 - [debug]   ok.

Tue May  6 00:17:14 2014 - [debug] 

Tue May  6 00:17:12 2014 - [debug]  Connecting via SSH from root@192.168.10.101(192.168.10.101:22) to root@192.168.10.100(192.168.10.100:22)..

Tue May  6 00:17:13 2014 - [debug]   ok.

Tue May  6 00:17:13 2014 - [debug]  Connecting via SSH from root@192.168.10.101(192.168.10.101:22) to root@192.168.10.102(192.168.10.102:22)..

Tue May  6 00:17:14 2014 - [debug]   ok.

Tue May  6 00:17:15 2014 - [debug] 

Tue May  6 00:17:13 2014 - [debug]  Connecting via SSH from root@192.168.10.102(192.168.10.102:22) to root@192.168.10.100(192.168.10.100:22)..

Tue May  6 00:17:14 2014 - [debug]   ok.

Tue May  6 00:17:14 2014 - [debug]  Connecting via SSH from root@192.168.10.102(192.168.10.102:22) to root@192.168.10.101(192.168.10.101:22)..

Tue May  6 00:17:15 2014 - [debug]   ok.

Tue May  6 00:17:15 2014 - [info] All SSH connection tests passed successfully.


*******************************************************************************************************************

这里切记要主要环境变量  实在不行就吧/usr/local/mysql/bin 下的mysqlbinlog 和 mysql 2个程序直接链接到 /usr/bin下 不然这报错可真够烦的。

*******************************************************************************************************************

root@HMA-m:/mysqlHA# masterha_check_repl --conf=/etc/myHA.cnf    

   

Tue May  6 00:41:37 2014 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.

Tue May  6 00:41:37 2014 - [info] Reading application default configurations from /etc/myHA.cnf..

Tue May  6 00:41:37 2014 - [info] Reading server configurations from /etc/myHA.cnf..

Tue May  6 00:41:37 2014 - [info] MHA::MasterMonitor version 0.55.

Tue May  6 00:41:37 2014 - [info] Dead Servers:

Tue May  6 00:41:37 2014 - [info] Alive Servers:

Tue May  6 00:41:37 2014 - [info]   192.168.10.100(192.168.10.100:3306)

Tue May  6 00:41:37 2014 - [info]   192.168.10.101(192.168.10.101:3306)

Tue May  6 00:41:37 2014 - [info]   192.168.10.102(192.168.10.102:3306)

Tue May  6 00:41:37 2014 - [info] Alive Slaves:

Tue May  6 00:41:37 2014 - [info]   192.168.10.101(192.168.10.101:3306)  Version=5.5.31-log (oldest major version between slaves) log-bin:enabled

Tue May  6 00:41:37 2014 - [info]     Replicating from 192.168.10.100(192.168.10.100:3306)

Tue May  6 00:41:37 2014 - [info]     Primary candidate for the new Master (candidate_master is set)

Tue May  6 00:41:37 2014 - [info]   192.168.10.102(192.168.10.102:3306)  Version=5.5.31-log (oldest major version between slaves) log-bin:enabled

Tue May  6 00:41:37 2014 - [info]     Replicating from 192.168.10.100(192.168.10.100:3306)

Tue May  6 00:41:37 2014 - [info]     Not candidate for the new Master (no_master is set)

Tue May  6 00:41:37 2014 - [info] Current Alive Master: 192.168.10.100(192.168.10.100:3306)

Tue May  6 00:41:37 2014 - [info] Checking slave configurations..

Tue May  6 00:41:37 2014 - [info]  read_only=1 is not set on slave 192.168.10.101(192.168.10.101:3306).

Tue May  6 00:41:37 2014 - [warning]  relay_log_purge=0 is not set on slave 192.168.10.101(192.168.10.101:3306).

Tue May  6 00:41:37 2014 - [warning]  relay_log_purge=0 is not set on slave 192.168.10.102(192.168.10.102:3306).

Tue May  6 00:41:37 2014 - [info] Checking replication filtering settings..

Tue May  6 00:41:37 2014 - [info]  binlog_do_db= , binlog_ignore_db= 

Tue May  6 00:41:37 2014 - [info]  Replication filtering check ok.

Tue May  6 00:41:37 2014 - [info] Starting SSH connection tests..

Tue May  6 00:41:40 2014 - [info] All SSH connection tests passed successfully.

Tue May  6 00:41:40 2014 - [info] Checking MHA Node version..

Tue May  6 00:41:40 2014 - [info]  Version check ok.

Tue May  6 00:41:40 2014 - [info] Checking SSH publickey authentication settings on the current master..

Tue May  6 00:41:41 2014 - [info] HealthCheck: SSH to 192.168.10.100 is reachable.

Tue May  6 00:41:41 2014 - [info] Master MHA Node version is 0.54.

Tue May  6 00:41:41 2014 - [info] Checking recovery script configurations on the current master..

Tue May  6 00:41:41 2014 - [info]   Executing command: save_binary_logs --command=test --start_pos=4 --binlog_dir=/mysql_data/3306 --output_file=/usr/local/mysql//save_binary_logs_test --manager_version=0.55 --start_file=mysql-bin.000007 

Tue May  6 00:41:41 2014 - [info]   Connecting to root@192.168.10.100(192.168.10.100).. 

  Creating /usr/local/mysql if not exists..    ok.

  Checking output directory is accessible or not..

   ok.

  Binlog found at /mysql_data/3306, up to mysql-bin.000007

Tue May  6 00:41:41 2014 - [info] Master setting check done.

Tue May  6 00:41:41 2014 - [info] Checking SSH publickey authentication and checking recovery script configurations on all alive slave servers..

Tue May  6 00:41:41 2014 - [info]   Executing command : apply_diff_relay_logs --command=test --slave_user='root' --slave_host=192.168.10.101 --slave_ip=192.168.10.101 --slave_port=3306 --workdir=/usr/local/mysql/ --target_version=5.5.31-log --manager_version=0.55 --relay_log_info=/mysql_data/3306/relay-log.info  --relay_dir=/mysql_data/3306/  --slave_pass=xxx

Tue May  6 00:41:41 2014 - [info]   Connecting to root@192.168.10.101(192.168.10.101:22).. 

  Checking slave recovery environment settings..

    Opening /mysql_data/3306/relay-log.info ... ok.

    Relay log found at /mysql_data/3306, up to HMA-b-relay-bin.000002

    Temporary relay log file is /mysql_data/3306/HMA-b-relay-bin.000002

    Testing mysql connection and privileges.. done.

    Testing mysqlbinlog output.. done.

    Cleaning up test file(s).. done.

Tue May  6 00:41:42 2014 - [info]   Executing command : apply_diff_relay_logs --command=test --slave_user='root' --slave_host=192.168.10.102 --slave_ip=192.168.10.102 --slave_port=3306 --workdir=/usr/local/mysql/ --target_version=5.5.31-log --manager_version=0.55 --relay_log_info=/mysql_data/3306/relay-log.info  --relay_dir=/mysql_data/3306/  --slave_pass=xxx

Tue May  6 00:41:42 2014 - [info]   Connecting to root@192.168.10.102(192.168.10.102:22).. 

  Checking slave recovery environment settings..

    Opening /mysql_data/3306/relay-log.info ... ok.

    Relay log found at /mysql_data/3306, up to HMA-slave-relay-bin.000002

    Temporary relay log file is /mysql_data/3306/HMA-slave-relay-bin.000002

    Testing mysql connection and privileges.. done.

    Testing mysqlbinlog output.. done.

    Cleaning up test file(s).. done.

Tue May  6 00:41:43 2014 - [info] Slaves settings check done.

Tue May  6 00:41:43 2014 - [info] 


192.168.10.100 (current master)

 +--192.168.10.101

 +--192.168.10.102


Tue May  6 00:41:43 2014 - [info] Checking replication health on 192.168.10.101..

Tue May  6 00:41:43 2014 - [info]  ok.

Tue May  6 00:41:43 2014 - [info] Checking replication health on 192.168.10.102..

Tue May  6 00:41:43 2014 - [info]  ok.

Tue May  6 00:41:43 2014 - [warning] master_ip_failover_script is not defined.

Tue May  6 00:41:43 2014 - [warning] shutdown_script is not defined.

Tue May  6 00:41:43 2014 - [info] Got exit code 0 (Not master dead).


MySQL Replication Health is OK.

$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

启动 MHA

nohup masterha_manager --conf=/etc/myHA.cnf  < /dev/null > /mysqlHA/HA.log 2>&1 &


root@HMA-m:/mysqlHA# masterha_check_status --conf=/etc/myHA.cnf 

myHA (pid:13979) is running(0:PING_OK), master:192.168.10.100

检查OK

######################################################################

我们到从库上看下状态

mysql> show slave status\G

*************************** 1. row ***************************

               Slave_IO_State: Waiting for master to send event

                  Master_Host: 192.168.10.100                                                  主库地址

                  Master_User: boge

                  Master_Port: 3306

                Connect_Retry: 60

              Master_Log_File: mysql-bin.000010

          Read_Master_Log_Pos: 335

               Relay_Log_File: mysqld-relay-bin.000005

                Relay_Log_Pos: 481

        Relay_Master_Log_File: mysql-bin.000010

             Slave_IO_Running: Yes

            Slave_SQL_Running: Yes

              Replicate_Do_DB: 

          Replicate_Ignore_DB: 

           Replicate_Do_Table: 

       Replicate_Ignore_Table: 

      Replicate_Wild_Do_Table: 

  Replicate_Wild_Ignore_Table: 

                   Last_Errno: 0

                   Last_Error: 

                 Skip_Counter: 0

          Exec_Master_Log_Pos: 335

              Relay_Log_Space: 1213

              Until_Condition: None

               Until_Log_File: 

                Until_Log_Pos: 0

           Master_SSL_Allowed: No

           Master_SSL_CA_File: 

           Master_SSL_CA_Path: 

              Master_SSL_Cert: 

            Master_SSL_Cipher: 

               Master_SSL_Key: 

        Seconds_Behind_Master: 0

Master_SSL_Verify_Server_Cert: No

                Last_IO_Errno: 0

                Last_IO_Error: 

               Last_SQL_Errno: 0

               Last_SQL_Error: 

  Replicate_Ignore_Server_Ids: 

             Master_Server_Id: 1

1 row in set (0.00 sec)


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

停掉主库

root@HMA-m:/mysqlHA# /etc/init.d/mysql stop

Shutting down MySQL

... * 

root@HMA-m:/mysqlHA# masterha_check_status --conf=/etc/myHA.cnf 

myHA master is down and failover is running(50:FAILOVER_RUNNING). master:192.168.10.100

Check /mysqlHA/manager.log for details.

检查状态已经主库已经DOWN了

***********************************************************

mysql> show slave status\G

*************************** 1. row ***************************

               Slave_IO_State: Waiting for master to send event

                  Master_Host: 192.168.10.101                                  呵呵  OK了

                  Master_User: boge

                  Master_Port: 3306

                Connect_Retry: 60

              Master_Log_File: mysql-bin.000009

          Read_Master_Log_Pos: 107

               Relay_Log_File: mysqld-relay-bin.000002

                Relay_Log_Pos: 253

        Relay_Master_Log_File: mysql-bin.000009

             Slave_IO_Running: Yes

            Slave_SQL_Running: Yes

              Replicate_Do_DB: 

          Replicate_Ignore_DB: 

           Replicate_Do_Table: 

       Replicate_Ignore_Table: 

      Replicate_Wild_Do_Table: 

  Replicate_Wild_Ignore_Table: 

                   Last_Errno: 0

                   Last_Error: 

                 Skip_Counter: 0

          Exec_Master_Log_Pos: 107

              Relay_Log_Space: 410

              Until_Condition: None

               Until_Log_File: 

                Until_Log_Pos: 0

           Master_SSL_Allowed: No

           Master_SSL_CA_File: 

           Master_SSL_CA_Path: 

              Master_SSL_Cert: 

            Master_SSL_Cipher: 

               Master_SSL_Key: 

        Seconds_Behind_Master: 0

Master_SSL_Verify_Server_Cert: No

                Last_IO_Errno: 0

                Last_IO_Error: 

               Last_SQL_Errno: 0

               Last_SQL_Error: 

  Replicate_Ignore_Server_Ids: 

             Master_Server_Id: 2

1 row in set (0.00 sec)


##############################################################################

这个过程是不可逆的,而且我又把MHA部署在了MASTER上,就算启动了MYSQL,MHA也起不来了。考啊。

我用快照恢复到了停MySQL之前

///、、、、、、、、、、、、、、、、、、、、、、、、、

现在再配置keepalive  让浮动IP服务,使得用户能更好的体验。

apt-get install keepalived

然后到/usr/share/doc/keepalived/sample 下去找个合适的配置文件复制到/etc/keepalived/keepalived.conf


global_defs {

   router_id LVS_DEVEL

}

vrrp_script check_mysql {

    script sh /root/mysql.sh                       # 检查MySQL状态

    interval 3

}

vrrp_instance VI_1 {

    state MASTER                       #备为BACKUP

    interface eth0

    virtual_router_id 51

    priority 100

    advert_int 1

    authentication {

        auth_type PASS

        auth_pass boge

    }

    virtual_ipaddress {

        192.168.111.200                 #浮动的虚拟IP

    }

}

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

这几把配置文件写法太蛋疼就怕括号有问题,所以大家自己做好缩进 避免问题,这keepalive的问题就是日志太简单。

##########################################################################


启动keepalive


通过ip a 可以发现浮动IP


到这里我们的MHA+keepalived的配置到此完成


MySQL的故障转移还是靠MHA的failover来转移,浮动IP提供的只是对外的透明IP。

=====================================================================

MYSQL的集群还是要靠中间件来完成,有空我再写个 奇虎360的中间件 Atlas 的操作过程


转载于:https://my.oschina.net/jastme/blog/278542

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值