半同步复制Master节点Node1的MariaDB配置文件
[mysqld] datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 # Settings user and group are ignored when systemd is used. # If you need to run mysqld under a different user or group, # customize your systemd unit file for mariadb according to the # instructions in http://Fedoraproject.org/wiki/Systemd innodb_file_per_table = 1 skip_name_resolve = 1 log_bin = Master-log log_bin_index = 1 server_id = 1 relay_log=relay-log relay_log_purge=0 #skip-grant-tables #skip-networking [mysqld_safe] log-error=/var/log/mariadb/mariadb.log pid-file=/var/run/mariadb/mariadb.pid # # include all files from the config directory # !includedir /etc/my.cnf.d这里需要注意的是,
半同步复制主节点和从节点都要启动了二进制日志log_bin = Master-log,中继日志relay_log=relay-log
而且这里关闭了中继日志的修剪功能relay_log_purge=0。因为这由MHA完成。
半同步复制Slave节点Node2和node3的MariaDB配置文件
[mysqld] datadir=/var/lib/mysql/ socket=/var/lib/mysql/mysql.sock log_bin=Master-bin # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 # Settings user and group are ignored when systemd is used. # If you need to run mysqld under a different user or group, # customize your systemd unit file for mariadb according to the # instructions in skip_name_resolve=true innodb_file_per_table=ture server_id = 2 log_bin=bin_log relay_log=relay-log read_only = 1 relay_log_purge=0 [mysqld_safe] log-error=/var/log/mariadb/mariadb.log pid-file=/var/run/mariadb/mariadb.pid # # include all files from the config directory # !includedir /etc/my.cnf.d这里比Master节点多一个read_only=1
假如Slave节点被提升为Master节点的话,MHA会自动将这个read_only=1去掉
并且会将修改其他Slave节点指向新的主节点,可以用show slave status\G查看。
(1)复制默认文件作为模板,并清空默认配置
cp /etc/masterha/masterha_default.cnf /etc/masterha/app1.cnf > /etc/masterha/masterha_default.cnf(2)配置/etc/masterha/app1.cnf,用于启动manager进程的时候指定。
MHA的一个manager节点可以通过启动多个进程来监控多个MHA集群,所以使用app1,app2的方式。
这里的user和password指的是数据库管理员的账号密码
repl_user和repl_password是具有复制权限的用户和密码
ssh_user=root是ssh的账户,由于是秘钥认证,并不需要密码
配置文件中,hostname=node1是因为主机可以使用node1访问到该主机,这里也可以用ip地址。
(3)创建配置文件中manager_workdir的工作路径
mkdir /data/masterha/app1/ 利用MHA的工具测试环境是否正常(1)测试ssh是否连接正常
[root@node4 mha4mysql-manager-0.56]# masterha_check_ssh --conf=/etc/masterha/app1.cnf Thu Nov 10 22:59:03 2016 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping. Thu Nov 10 22:59:03 2016 - [info] Reading application default configuration from /etc/masterha/app1.cnf.. Thu Nov 10 22:59:03 2016 - [info] Reading server configuration from /etc/masterha/app1.cnf.. Thu Nov 10 22:59:03 2016 - [info] Starting SSH connection tests.. Thu Nov 10 22:59:04 2016 - [debug] Thu Nov 10 22:59:03 2016 - [debug] Connecting via SSH from root@node1(192.168.2.201:22) to root@node2(192.168.2.202:22).. Thu Nov 10 22:59:03 2016 - [debug] ok. Thu Nov 10 22:59:03 2016 - [debug] Connecting via SSH from root@node1(192.168.2.201:22) to root@node3(192.168.2.203:22).. Thu Nov 10 22:59:03 2016 - [debug] ok. Thu Nov 10 22:59:04 2016 - [debug] Thu Nov 10 22:59:03 2016 - [debug] Connecting via SSH from root@node2(192.168.2.202:22) to root@node1(192.168.2.201:22).. Thu Nov 10 22:59:04 2016 - [debug] ok. Thu Nov 10 22:59:04 2016 - [debug] Connecting via SSH from root@node2(192.168.2.202:22) to root@node3(192.168.2.203:22).. Thu Nov 10 22:59:04 2016 - [debug] ok. Thu Nov 10 22:59:05 2016 - [debug] Thu Nov 10 22:59:04 2016 - [debug] Connecting via SSH from root@node3(192.168.2.203:22) to root@node1(192.168.2.201:22).. Thu Nov 10 22:59:04 2016 - [debug] ok. Thu Nov 10 22:59:04 2016 - [debug] Connecting via SSH from root@node3(192.168.2.203:22) to root@node2(192.168.2.202:22).. Thu Nov 10 22:59:05 2016 - [debug] ok. Thu Nov 10 22:59:05 2016 - [info] All SSH connection tests passed successfully.这么多输出信息,其实只看最后一句就知道ssh是否正常了
这里需要注意的是这里指定了刚才配置的app1.