MySQL's High availability MHA deployment

Source: Internet
Author: User

Let's talk about the principle.

Virtual Machine A IP is 10.0.3.92 as Master

Virtual Machine B IP is 10.0.3.102 as slave1

Virtual machine C IP is 10.0.3.103 as Slave2

Virtual Machine D IP is 10.0.3.104 as manager

First, configure a primary two from the environment, a mainly, BC for from

Then configure all virtual machine 22 ssh-free login (SSH how to password-free login, own Baidu, or search my blog article, there are also records how to configure SSH password-free login)

New configuration file in D

It is critical to detect the SSH configuration and the success of the master-slave configuration in D

If there is no problem, then we try to stop the master server, the manager will automatically switch the main library to B

Here's a look at the specific deployment steps

The important thing to say first, that is, the firewall and SELinux must be shut down, if you do not want to shut down, then you slowly toss out which port and so on.

The next MHA compressed package with the files we need to use

Http://www.yougemysqldba.com/discuz/viewthread.php?tid=491&extra=page%3D1

I downloaded the second rhel56.zip, because my system is 6.5.

Virtual Machine A

First install Mysql,mysql-server (my system is centos6.5, I heard that CENTOS7 deployment MHA also need to do additional work), and then automatically open the service and change the password

Configure/ETC/MY.CNF, add in mysqld, content as follows

server-ID=1     log-bin=master-log relay-log=relay-logskip_name_ Resolveinnodb_file_per_table

Unzip the compressed package we downloaded, on virtual machine A, we only need to install MHA4MYSQL-NODE-0.54-0.EL6.NOARCH.RPM, how to install? Baidu Ah, the installation prompted the lack of dependency dependency package? Baidu Ah

Go to MySQL and execute the following command

Create a new Repluser user, dedicated to synchronizing

Mysql> Show master status;
+-------------------+----------+--------------+------------------+
| File | Position | binlog_do_db | binlog_ignore_db |
+-------------------+----------+--------------+------------------+
| master-log.000004 | 106 | | |
+-------------------+----------+--------------+------------------+
1 row in Set (0.00 sec)

That way, the master side is configured.

Virtual machine B and virtual machine C:

Of course, these two virtual machines also need to install node that rpm file package

Configuration file/etc/my.cnf, of course, put it under mysqld.

Symbolic-links=0
Default-character-set=utf8
Character-set-server=utf8
Collation-server=utf8_bin
Default-storage-engine=innodb
max_allowed-packet=32m
Sql_mode=no_auto_value_on_zero
server-id=2 #虚拟机C只需要把这里改为3
Relay-log=relay-log
Log-bin=master-log
Read_only=1
Relay_log_purge=0
Skip_name_resolve
Innodb_file_per_table

The number of lines in the front is set in Chinese encoding

Enter the database

Change Master Settings

Change Master to master_host= ' 10.0.3.92 ', master_user= ' repluser ', master_password= ' Replpass ', master_log_file= ' Master-log.000004 ', master_log_pos=106;

Now start slave view the slave status, mainly to see whether the following two parameters are yes, if it is normal

Slave_io_running:yes
Slave_sql_running:yes

Virtual Machine D:

Install all RPM files in the downloaded compressed package

Configuration

[Email protected] ~]# CAT/ETC/MASTERHA_DEFAULT.CNF
[Server default]
User=root #听说这个是数据库的用户名, this user needs to be created on four virtual machines, and authorized to telnet, anyway I am the root user directly, and the password is unified to 123456
password=123456 #这个是上面用户对应的密码
Manager_workdir=/data/masterha/app1
Manager_log=/data/masterha/app1/manager.log
Remote_workdir=/data/masterha/app1
Ssh_user=root #ssh登录的用户名, the user is also configured when SSH is configured
Repl_user=repluser #配置主从时设置的用户
Repl_password=replpass #主从用户密码
Ping_interval=1
[Server1]
hostname=10.0.3.92
[Server2]
hostname=10.0.3.102
[Server3]
hostname=10.0.3.103
[Email protected] ~]#

[Email protected] ~]# Masterha_
Masterha_check_repl masterha_check_status Masterha_manager Masterha_master_switch masterha_stop
Masterha_check_ssh masterha_conf_host Masterha_master_monitor Masterha_secondary_check

[[email protected] ~]# masterha_check_ssh--conf=/etc/masterha_default.cnf detect SSH Configuration
Thu Nov 9 01:12:32-[INFO] Reading default Configuratoins from/etc/masterha_default.cnf.
Thu Nov 9 01:12:32-[INFO] Reading application default configurations from/etc/masterha_default.cnf.
Thu Nov 9 01:12:32-[INFO] Reading server configurations from/etc/masterha_default.cnf.
Thu Nov 9 01:12:32-[INFO] Starting SSH connection tests.
Thu Nov 9 01:12:33-[debug]
Thu Nov 9 01:12:32-[debug] connecting via SSH from [email protected] (10.0.3.92:22) to [email protected] (10.0.3.102: 22)..
Thu Nov 9 01:12:32-[debug] OK.
Thu Nov 9 01:12:32-[debug] connecting via SSH from [email protected] (10.0.3.92:22) to [email protected] (10.0.3.103: 22)..
Thu Nov 9 01:12:33-[debug] OK.
Thu Nov 9 01:12:34-[debug]
Thu Nov 9 01:12:33-[debug] connecting via SSH from [email protected] (10.0.3.102:22) to [email protected] (10.0.3.92: 22)..
Thu Nov 9 01:12:33-[debug] OK.
Thu Nov 9 01:12:33-[debug] connecting via SSH from [email protected] (10.0.3.102:22) to [email protected] (10.0.3.103 : 22)..
Thu Nov 9 01:12:33-[debug] OK.
Thu Nov 9 01:12:34-[debug]
Thu Nov 9 01:12:33-[debug] connecting via SSH from [email protected] (10.0.3.103:22) to [email protected] (10.0.3.92: 22)..
Thu Nov 9 01:12:34-[debug] OK.
Thu Nov 9 01:12:34-[debug] connecting via SSH from [email protected] (10.0.3.103:22) to [email protected] (10.0.3.102 : 22)..
Thu Nov 9 01:12:34-[debug] OK.
Thu Nov 9 01:12:34-[INFO] All SSH connection tests passed successfully.
[Email protected] ~]#

[Email protected] ~]# Masterha_check_repl--conf=/etc/masterha_default.cnf #检测主从复制, under normal circumstances MySQL replication health is OK, this is because I stopped the master server after the experiment was completed, which caused the not OK. At the beginning of the time I have been not OK here, and then I looked at the various errors, and finally found that the firewall did not know when the open ... Here I suggest to try to connect the other three virtual machines on D database, respectively with the root login and the master-slave replication user login, if not error, detection master-slave replication here should be no problem
Thu Nov 9 01:12:59-[INFO] Reading default Configuratoins from/etc/masterha_default.cnf.
Thu Nov 9 01:12:59-[INFO] Reading application default configurations from/etc/masterha_default.cnf.
Thu Nov 9 01:12:59-[INFO] Reading server configurations from/etc/masterha_default.cnf.
Thu Nov 9 01:12:59-[INFO] mha::mastermonitor version 0.55.
Thu Nov 9 01:13:00-[ERROR][/USR/SHARE/PERL5/VENDOR_PERL/MHA/SERVERMANAGER.PM, ln604] There is 2 non-slave servers! MHA manages at the most one non-slave server. Check configurations.
Thu Nov 9 01:13:00-[error][/usr/share/perl5/vendor_perl/mha/mastermonitor.pm, ln386] error happend on checking conf Igurations. AT/USR/SHARE/PERL5/VENDOR_PERL/MHA/MASTERMONITOR.PM Line 300
Thu Nov 9 01:13:00-[error][/usr/share/perl5/vendor_perl/mha/mastermonitor.pm, ln482] error happened on monitoring s Ervers.
Thu Nov 9 01:13:00-[INFO] Got exit code 1 (not master dead).

MySQL Replication Health is not ok!

Now we're trying to stop the master server, and then we'll look at the status of Virtual machine C.

Mysql> show Slave status\g;
1. Row ***************************
Slave_io_state:waiting for Master to send event
master_host:10.0.3.102 #可以看到这里自动把master从10.0.3.92 switch to 10.0.3.102 .
Master_user:repluser
master_port:3306
Connect_retry:60
master_log_file:master-log.000010
read_master_log_pos:600
relay_log_file:relay-log.000005
relay_log_pos:252
relay_master_log_file:master-log.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:600
relay_log_space:1286
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:
1 row in Set (0.00 sec)

ERROR:
No query specified

Mysql>

It is probably so simple, but the first configuration is still very easy to come up with such or such a problem, slowly pondering it

What, I write a mess, you can not understand?

Okay, I'll give you a reference link. http://www.178linux.com/87554

MySQL's High availability MHA deployment

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.