lover
[server1]
hostname = 192.168.3.27
master_binlog_dir = /data/lib/mysql
candidate_master = 1
[server2]
hostname = 192.168.3.28
master_binlog_dir = /data/lib/mysql
candidate_master =1
[server3]
hostname = 192.168.3.25
no_master = 1
3.配置SSH等效连接
因为MHA管理节点以及各个Node节点之间需要无密码登录并执行相关脚本,所以需要配置各个节点之间的SSH等效性,如下:
??生成密钥文件(各个节点均需执行)
# mkdir -p ~/.ssh
# cd .ssh
# /usr/bin/ssh-keygen -t rsa (提示处直接回车即可)
# /usr/bin/ssh-keygen -t dsa (提示处直接回车即可)
执行完成后,在/root/.ssh 目录下会生产四个密钥文件。
??任意一个节点执行即可(本例选择在manager节点执行)
# ssh 192.168.3.27 cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
# ssh 192.168.3.27 cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys
# ssh 192.168.3.28 cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
# ssh 192.168.3.28 cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys
# ssh 192.168.3.25 cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
# ssh 192.168.3.25 cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys
# ssh 192.168.3.26 cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
# ssh 192.168.3.26 cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys
# scp ~/.ssh/authorized_keys 192.168.3.27:.ssh/
# scp ~/.ssh/authorized_keys 192.168.3.28:.ssh/
# scp ~/.ssh/authorized_keys 192.168.3.25:.ssh/
??修改authorized_keys文件的权限为600(所有节点均需执行)
# chmod 600 ~/.ssh/authorized_keys
??测试一下
在各节点执行如下命令,测试一下,看是否不提示密码即可显示,否则则说明SSH配置不成功。
# ssh 192.168.3.26 hostname
# ssh 192.168.3.26 date
另外,还可采用MHA提供的工具命令来检查,如下:
[root@mmm .ssh]# /usr/bin/masterha_check_ssh --conf=/etc/appl.cnf
Fri Jul 18 16:52:12 2014 - [info] Reading default configuratoins from /etc/masterha_default.cnf..
Fri Jul 18 16:52:12 2014 - [info] Reading application default configurations from /etc/appl.cnf..
Fri Jul 18 16:52:12 2014 - [info] Reading server configurations from /etc/appl.cnf..
Fri Jul 18 16:52:12 2014 - [info] Starting SSH connection tests..
Fri Jul 18 16:52:13 2014 - [debug]
Fri Jul 18 16:52:12 2014 - [debug] Connecting via SSH from root@192.168.3.27(192.168.3.27:22) to root@192.168.3.28(192.168.3.28:22)..
Fri Jul 18 16:52:12 2014 - [debug] ok.
Fri Jul 18 16:52:12 2014 - [debug] Connecting via SSH from root@192.168.3.27(192.168.3.27:22) to root@192.168.3.25(192.168.3.25:22)..
Fri Jul 18 16:52:12 2014 - [debug] ok.
Fri Jul 18 16:52:13 2014 - [debug]
Fri Jul 18 16:52:12 2014 - [debug] Connecting via SSH from root@192.168.3.28(192.168.3.28:22) to root@192.168.3.27(192.168.3.27:22)..
Fri Jul 18 16:52:13 2014 - [debug] ok.
Fri Jul 18 16:52:13 2014 - [debug] Connecting via SSH from root@192.168.3.28(192.168.3.28:22) to root@192.168.3.25(192.168.3.25:22)..
Fri Jul 18 16:52:13 2014 - [debug] ok.
Fri Jul 18 16:52:13 2014 - [debug]
Fri Jul 18 16:52:13 2014 - [debug] Connecting via SSH from root@192.168.3.25(192.168.3.25:22) to root@192.168.3.27(192.168.3.27:22)..
Fri Jul 18 16:52:13 2014 - [debug] ok.
Fri Jul 18 16:52:13 2014 - [debug] Connecting via SSH from root@192.168.3.25(192.168.3.25:22) to root@192.168.3.28(192.168.3.28:22)..
Fri Jul 18 16:52:13 2014 - [debug] ok.
Fri Jul 18 16:52:13 2014 - [info] All SSH connection tests passed successfully.
从中可以看到,该命令会从应用配置文件中读取相关信息(IP和SSH_USER),然后在各个Node之间相互验证,保证可以通过SSH方式相互登录(用于同步差异日志)。
4.配置hosts解析
这一步的目的是在hostname和ip之间提供一个解析途径,配置方法很简单,就是将各个节点的主机名及对应的IP地址写入/etc/hosts文件,所有节点均需配置,且保持一致,如下:
# vi /etc/hosts
# that require network functionality will fail.
127.0.0.1 localhost.localdomain localhost
192.168.3.27 node1
192.168.3.28 node2
192.168.3.25