1. 程式人生 > >07: MMM集群概述 、 部署集群基礎環境 、 MMM集群部署 、 總結和答疑

07: MMM集群概述 、 部署集群基礎環境 、 MMM集群部署 、 總結和答疑

++ common state tar.gz 結構 path defined 授權 fin

day07 部署MySQL高可用集群

高可用集群介紹: 主備模式 當主不能提供服務的時候備用主機接替它提供服務,這個過程對於客戶端是透明的。

一 配置MySQL主從同步
主主結構
主從從
一主多從

二配置MySQL-mmm perl

mmm_monitor 監控服務 運行在管理節點主機上。
mmm_agentd 代理服務 運行在所有的數據節點主機上。

writer-vip : 192.168.4.100
read -vip : 192.168.4.101/102

2.1 在所有主機上安裝mysql-mmm-2.2.1.tar.gz軟件包
#yum -y install perl-*

#unzip mysql-mmm.zip
#cd mysql-mmm
#tar -zxf mysql-mmm-2.2.1.tar.gz
#cd mysql-mmm-2.2.1
#make install
#ls /etc/mysql-mmm/
mmm_agent.conf //mmm_agentd服務主配置文件
mmm_common.conf //公共配置文件(管理主機和數據節點主機)
mmm_mon.conf //mmm_monitor服務主配置文件
mmm_tools.conf
2.2 修改配置
2.2.1 修改數據節點主機mmm_agentd服務的配置文件
ip地址 名稱
192.168.4.51 master51
192.168.4.52 master52
192.168.4.53 slave53
192.168.4.54 slave54

#vim /etc/mysql-mmm/mmm_agent.conf
include mmm_common.conf
this 主機名
[root@002 ~]#

2.2.2 修改管理節點主機mmm_monitor服務的配置文件

vim /etc/mysql-mmm/mmm_mon.conf

[root@005 ~]# cat /etc/mysql-mmm/mmm_mon.conf
include mmm_common.conf

<monitor>
ip 192.168.4.55

pid_path /var/run/mmm_mond.pid
bin_path /usr/lib/mysql-mmm/
status_path /var/lib/misc/mmm_mond.status
ping_ips 192.168.4.51, 192.168.4.52, 192.168.4.53, 192.168.4.54
</monitor>

<host default>
monitor_user monitor
monitor_password 123456
</host>

debug 0
[root@005 ~]#

2.2.3 修改公共配置文件mmm_common.conf

vim /etc/mysql-mmm/mmm_common.conf

[root@001 mysql-mmm-2.2.1]# cat /etc/mysql-mmm/mmm_common.conf
active_master_role writer

<host default>
cluster_interface eth0

pid_path                /var/run/mmm_agentd.pid
bin_path                /usr/lib/mysql-mmm/

replication_user        h51
replication_password    123456

agent_user   agent
agent_password   123456

</host>

<host master51>
ip 192.168.4.51
mode master
peer master52
</host>

<host master52>
ip 192.168.4.52
mode master
peer master51
</host>

<host slave53>
ip 192.168.4.53
mode slave
</host>

<host slave54>
ip 192.168.4.54
mode slave
</host>

<role writer>
hosts master51, master52
ips 192.168.4.100
mode exclusive
</role>

<role reader>
hosts slave53, slave54
ips 192.168.4.101, 192.168.4.102
mode balanced
</role>
[root@001 mysql-mmm-2.2.1]#

2.2.4 根據配置文件裏設置,在數據節點主機天添加對應的授權用戶
監控用戶monitor agent
mmm_monitor mmm_agentd
51 :
mysql> grant replication client on . to monitor@"%" identified by "123456";
mysql> grant replication client,process,super on . to agent@"%" identified by "123456";
mysql> select user,host from mysql.user where user in ("monitor","agent");

52-54:
select user,host from mysql.user where user in ("monitor","agent");

2.3 啟動服務
2.3.0 安裝依賴的軟件包
安裝mmm_monitor服務和mmm_agentd運行依賴的軟件包(51~55)
#yum -y install gcc gcc-c++

#tar -zxf Algorithm-Diff-1.1902.tar.gz
#cd Algorithm-Diff-1.1902/
#perl Makefile.PL
#make
#make install

#rpm -ivh perl-Log-Log4perl-1.26-1.el6.rf.noarch.rpm

#tar -zxf Proc-Daemon-0.03.tar.gz
#cd Proc-Daemon-0.03/
#perl Makefile.PL
#make
#make install

安裝獲取vip地址的程序(51-54 )
289 gunzip Net-ARP-1.0.8.tgz
291 tar -xf Net-ARP-1.0.8.tar
293 cd Net-ARP-1.0.8/
295 perl Makefile.PL
296 make
297 make install

2.3.1 啟動數據節點主機上的 mmm_agentd服務(51~54)
[root@001 ~]# /etc/init.d/mysql-mmm-agent status
Daemon bin: ‘/usr/sbin/mmm_agentd‘
Daemon pid: ‘/var/run/mmm_agentd.pid‘
Checking MMM Agent process: not running.
[root@001 ~]#
[root@001 ~]# /etc/init.d/mysql-mmm-agent start
Daemon bin: ‘/usr/sbin/mmm_agentd‘
Daemon pid: ‘/var/run/mmm_agentd.pid‘
Starting MMM Agent daemon... defined(@array) is deprecated at /usr/share/perl5/vendor_perl/Log/Log4perl/Config.pm line 863.
(Maybe you should just omit the defined()?)
Ok
[root@001 ~]# netstat -utnalp | grep :9989
tcp 0 0 192.168.4.51:9989 0.0.0.0:* LISTEN 12389/mmm_agentd
[root@001 ~]# ls /var/log/mysql-mmm/
mmm_agentd.log
[root@001 ~]#

2.3.2 啟動管理節點主機上的 mmm_monitor服務
[root@005 ~]# /etc/init.d/mysql-mmm-monitor status
Daemon bin: ‘/usr/sbin/mmm_mond‘
Daemon pid: ‘/var/run/mmm_mond.pid‘
Checking MMM Monitor process: not running.
[root@005 ~]#
[root@005 ~]# /etc/init.d/mysql-mmm-monitor start
Daemon bin: ‘/usr/sbin/mmm_mond‘
Daemon pid: ‘/var/run/mmm_mond.pid‘
Starting MMM Monitor daemon: defined(@array) is deprecated at /usr/share/perl5/vendor_perl/Log/Log4perl/Config.pm line 863.
(Maybe you should just omit the defined()?)
Ok
[root@005 ~]# netstat -utnalp | grep :9988
tcp 0 0 192.168.4.55:9988 0.0.0.0:* LISTEN 11433/mmm_mond
[root@005 ~]# ls /var/log/mysql-mmm/
mmm_mond.log
[root@005 ~]#

2.3.3 在管理節點55主機上,查看監控信息
[root@005 ~]# mmm_control show
defined(@array) is deprecated at /usr/share/perl5/vendor_perl/Log/Log4perl/Config.pm line 863.
(Maybe you should just omit the defined()?)
master51(192.168.4.51) master/AWAITING_RECOVERY. Roles:
master52(192.168.4.52) master/AWAITING_RECOVERY. Roles:
slave53(192.168.4.53) slave/AWAITING_RECOVERY. Roles:
slave54(192.168.4.54) slave/AWAITING_RECOVERY. Roles:

[root@005 ~]# mmm_control set_online 主機名

[root@005 ~]# mmm_control set_online master51
defined(@array) is deprecated at /usr/share/perl5/vendor_perl/Log/Log4perl/Config.pm line 863.
(Maybe you should just omit the defined()?)
OK: State of ‘master51‘ changed to ONLINE. Now you can wait some time and check its new roles!
[root@005 ~]#

[root@005 ~]# mmm_control show
defined(@array) is deprecated at /usr/share/perl5/vendor_perl/Log/Log4perl/Config.pm line 863.
(Maybe you should just omit the defined()?)
master51(192.168.4.51) master/ONLINE. Roles: writer(192.168.4.100)
master52(192.168.4.52) master/ONLINE. Roles:
slave53(192.168.4.53) slave/ONLINE. Roles: reader(192.168.4.101)
slave54(192.168.4.54) slave/ONLINE. Roles: reader(192.168.4.102)

[root@005 ~]#
[root@005 ~]# ping -c 2 192.168.4.100

數據節點主機查看 VIP 地址?51~54
#ip addr show | grep 192.168.4.

在數據節點主機上添加訪問數據的連接用戶
51#mysql -uroot -p123456
mysql> grant all on gamedb.* to admin@"%"
-> identified by "123456";

mysql> select user,host from mysql.user where user="admin";

三、客戶端254測試,高可用集群的配置
#mysql -h192.168.4.100 -uamdin -p123456

07: MMM集群概述 、 部署集群基礎環境 、 MMM集群部署 、 總結和答疑