当前位置:Gxlcms > 数据库问题 > MySQL之高可用MHA部署

MySQL之高可用MHA部署

时间:2021-07-01 10:21:17 帮助过:28人阅读

=1 log-bin=master-log   relay-log=relay-log skip_name_resolve innodb_file_per_table

解压我们下载的那个压缩包,在虚拟机A上,我们只需要安装mha4mysql-node-0.54-0.el6.noarch.rpm,怎么安装?百度啊,安装时提示缺少依赖关系依赖包?百度啊

进入mysql,执行以下命令

新建一个repluser用户,专门用来同步

mysql> show master status;
+-------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+-------------------+----------+--------------+------------------+
| master-log.000004 | 106 | | |
+-------------------+----------+--------------+------------------+
1 row in set (0.00 sec)

这样子的话说明master端配置好了

 

 虚拟机B以及虚拟机C:

当然这两台虚拟机也需要安装node那个rpm文件包

配置文件/etc/my.cnf,当然也是放在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

前面多出的几行是设置中文编码

进入数据库

change master 设置

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;

现在start slave查看slave状态,主要查看下面两个参数是否为yes,如果是就表示正常

Slave_IO_Running: Yes
Slave_SQL_Running: Yes

 

虚拟机D:

安装下载的压缩包里面的所有rpm文件

配置

[root@node4 ~]# cat /etc/masterha_default.cnf
[server default]
user=root      #听说这个是数据库的用户名,需要在四台虚拟机上都创建这个用户,并且授权为可远程登录,反正我是直接用的root用户,并且密码统一为123456
password=123456  #这个是上面用户对应的密码
manager_workdir=/data/masterha/app1
manager_log=/data/masterha/app1/manager.log
remote_workdir=/data/masterha/app1
ssh_user=root         #ssh登录的用户名,配置ssh时也是配置该用户
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
[root@node4 ~]#

 

[root@node4 ~]# 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

[root@node4 ~]# masterha_check_ssh --conf=/etc/masterha_default.cnf   检测ssh配置
Thu Nov 9 01:12:32 2017 - [info] Reading default configuratoins from /etc/masterha_default.cnf..
Thu Nov 9 01:12:32 2017 - [info] Reading application default configurations from /etc/masterha_default.cnf..
Thu Nov 9 01:12:32 2017 - [info] Reading server configurations from /etc/masterha_default.cnf..
Thu Nov 9 01:12:32 2017 - [info] Starting SSH connection tests..
Thu Nov 9 01:12:33 2017 - [debug]
Thu Nov 9 01:12:32 2017 - [debug] Connecting via SSH from root@10.0.3.92(10.0.3.92:22) to root@10.0.3.102(10.0.3.102:22)..
Thu Nov 9 01:12:32 2017 - [debug] ok.
Thu Nov 9 01:12:32 2017 - [debug] Connecting via SSH from root@10.0.3.92(10.0.3.92:22) to root@10.0.3.103(10.0.3.103:22)..
Thu Nov 9 01:12:33 2017 - [debug] ok.
Thu Nov 9 01:12:34 2017 - [debug]
Thu Nov 9 01:12:33 2017 - [debug] Connecting via SSH from root@10.0.3.102(10.0.3.102:22) to root@10.0.3.92(10.0.3.92:22)..
Thu Nov 9 01:12:33 2017 - [debug] ok.
Thu Nov 9 01:12:33 2017 - [debug] Connecting via SSH from root@10.0.3.102(10.0.3.102:22) to root@10.0.3.103(10.0.3.103:22)..
Thu Nov 9 01:12:33 2017 - [debug] ok.
Thu Nov 9 01:12:34 2017 - [debug]
Thu Nov 9 01:12:33 2017 - [debug] Connecting via SSH from root@10.0.3.103(10.0.3.103:22) to root@10.0.3.92(10.0.3.92:22)..
Thu Nov 9 01:12:34 2017 - [debug] ok.
Thu Nov 9 01:12:34 2017 - [debug] Connecting via SSH from root@10.0.3.103(10.0.3.103:22) to root@10.0.3.102(10.0.3.102:22)..
Thu Nov 9 01:12:34 2017 - [debug] ok.
Thu Nov 9 01:12:34 2017 - [info] All SSH connection tests passed successfully.
[root@node4 ~]#

 

[root@node4 ~]# masterha_check_repl --conf=/etc/masterha_default.cnf       #检测主从复制,正常情况下mysql replication health is ok,这里因为我是在实验完成后停掉master服务器了,才导致的not ok。刚开始的时候我这里一直是not ok,然后我就各种查错,最后发现是防火墙不知道什么时候又开启了。。。这里我建议在D上尝试连接另外三台虚拟机的数据库,分别用root登录以及主从复制用户登录,如果不报错,检测主从复制这里应该就没有问题了
Thu Nov 9 01:12:59 2017 - [info] Reading default configuratoins from /etc/masterha_default.cnf..
Thu Nov 9 01:12:59 2017 - [info] Reading application default configurations from /etc/masterha_default.cnf..
Thu Nov 9 01:12:59 2017 - [info] Reading server configurations from /etc/masterha_default.cnf..
Thu Nov 9 01:12:59 2017 - [info] MHA::MasterMonitor version 0.55.
Thu Nov 9 01:13:00 2017 - [error][/usr/share/perl5/vendor_perl/MHA/ServerManager.pm, ln604] There are 2 non-slave servers! MHA manages at most one non-slave server. Check configurations.
Thu Nov 9 01:13:00 2017 - [error][/usr/share/perl5/vendor_perl/MHA/MasterMonitor.pm, ln386] Error happend on checking configurations. at /usr/share/perl5/vendor_perl/MHA/MasterMonitor.pm line 300
Thu Nov 9 01:13:00 2017 - [error][/usr/share/perl5/vendor_perl/MHA/MasterMonitor.pm, ln482] Error happened on monitoring servers.
Thu Nov 9 01:13:00 2017 - [info] Got exit code 1 (Not master dead).

MySQL Replication Health is NOT OK!

 

现在我们试着把master服务器停掉,然后我们看一下虚拟机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 切换到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>

大概就是这么简单,但是第一次配置时还是很容易出现这样或那样的问题的,慢慢琢磨吧

 什么,我写得乱七八糟的,你看不懂?

好吧,给一个参考链接给你http://www.178linux.com/87554

MySQL之高可用MHA部署

标签:password   val   arch   from   style   col   tor   app1   ignore   

人气教程排行