欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  数据库

mysql高可用方案之MHA

程序员文章站 2024-02-12 09:57:52
...

环境规划:节点说明主机名IP地址管理节点tong3192.168.1.249主节点tong2192.168.1.248主节点 tong1&nb..

环境规划:

节点说明 主机名 IP地址

管理节点 tong3 192.168.1.249

主节点 tong2 192.168.1.248

主节点  tong1 192.168.1.247


1.网络和主机名配置

设置每个主机的IP地址和/etc/hosts文件互相解析

[root@tong1 ~]# cat /etc/hosts
192.168.1.247 tong1
192.168.1.248 tong2
192.168.1.249 tong3
[root@tong1 ~]# ping tong1 -c1 --网络必须ping通
PING tong1 (192.168.1.247) 56(84) bytes of data.
64 bytes from localhost (192.168.1.247): icmp_seq=1 ttl=64 time=0.021 ms

--- tong1 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.021/0.021/0.021/0.000 ms
[root@tong1 ~]# ping tong2 -c1
PING tong2 (192.168.1.248) 56(84) bytes of data.
64 bytes from tong2 (192.168.1.248): icmp_seq=1 ttl=64 time=0.109 ms

--- tong2 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.109/0.109/0.109/0.000 ms
[root@tong1 ~]# ping tong3 -c1
PING tong3 (192.168.1.249) 56(84) bytes of data.
64 bytes from tong3 (192.168.1.249): icmp_seq=1 ttl=64 time=0.124 ms

--- tong3 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.124/0.124/0.124/0.000 ms
[root@tong1 ~]#


2.安装mha管理软件mha manager

tong3管理节点:

[root@tong3 ~]# yum install perl-DBD-MySQL cpan  --安装perl工具

[root@tong3 ~]# tar xvf mha4mysql-manager-0.53.tar.gz -C /usr/local/

[root@tong3 ~]# cd /usr/local/mha4mysql-manager-0.53/

[root@tong3 mha4mysql-manager-0.53]# perl Makefile.PL

[root@tong3 mha4mysql-manager-0.53]# echo $?
0
[root@tong3 mha4mysql-manager-0.53]# make && make install

[root@tong3 mha4mysql-manager-0.53]# echo $?
0
[root@tong3 mha4mysql-manager-0.53]#


3.在各数据节点安装mha node

[root@tong2 ~]# tar xvf mha4mysql-node-0.53.tar.gz
[root@tong2 ~]# cd mha4mysql-node-0.53
[root@tong2 mha4mysql-node-0.53]# yum install perl-DBD-mysql cpan -y

[root@tong2 mha4mysql-node-0.53]# perl Makefile.PL
[root@tong2 mha4mysql-node-0.53]# make && make install

[root@tong2 mha4mysql-node-0.53]# echo $?
0
[root@tong2 mha4mysql-node-0.53]#


4.各节点ssh互相信任

[root@tong3 ~]# ssh-keygen -t dsa

[root@tong3 ~]# cd .ssh

[root@tong3 .ssh]# cat id_dsa.pub > authorized_keys

[root@tong3 .ssh]# scp 192.168.1.247:/root/.ssh/id_dsa.pub 247

[root@tong3 .ssh]# scp 192.168.1.248:/root/.ssh/id_dsa.pub 248

[root@tong3 .ssh]# cat 248 247 >> authorized_keys
[root@tong3 .ssh]# scp authorized_keys 192.168.1.248:/root/.ssh/
authorized_keys 100% 1800 1.8KB/s 00:00
[root@tong3 .ssh]# scp authorized_keys 192.168.1.247:/root/.ssh/
root@192.168.1.247's password:
authorized_keys 100% 1800 1.8KB/s 00:00
[root@tong3 .ssh]# ssh tong1 date
Tue Apr 28 12:57:02 CST 2015
[root@tong3 .ssh]# ssh tong2 date
Tue Apr 28 12:59:57 CST 2015
[root@tong3 .ssh]# ssh tong3 date
Tue Apr 28 12:57:25 CST 2015
[root@tong3 .ssh]#


5.在管理节点编辑配置文件