码迷,mamicode.com
首页 > 数据库 > 详细

mysql 七

时间:2018-04-13 14:32:29      阅读:195      评论:0      收藏:0      [点我收藏+]

标签:mysql

部署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

mysql 七

标签:mysql

原文地址:http://blog.51cto.com/2168836/2102915

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!