mysql 七
部署MySQL高可用集群高可用集群介绍: 主备模式 当主不能提供服务的时候备用主机接替它提供服务,这个过程对于客户端是透明的。
一 配置MySQL主从同步
主主结构
主从从
一主多从
二配置MySQL-mmmperl
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-yinstall perl-*
#unzipmysql-mmm.zip
#cdmysql-mmm
#tar -zxfmysql-mmm-2.2.1.tar.gz
#cdmysql-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.51master51
192.168.4.52master52
192.168.4.53slave53
192.168.4.54slave54
#vim /etc/mysql-mmm/mmm_agent.conf
include mmm_common.conf
this 主机名
#
2.2.2修改管理节点主机mmm_monitor服务的配置文件
]# vim /etc/mysql-mmm/mmm_mon.conf
# cat /etc/mysql-mmm/mmm_mon.conf
include mmm_common.conf
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_user monitor
monitor_password 123456
debug 0
#
2.2.3修改公共配置文件mmm_common.conf
]# vim /etc/mysql-mmm/mmm_common.conf
# cat /etc/mysql-mmm/mmm_common.conf
active_master_rolewriter
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
ip 192.168.4.51
mode master
peer master52
ip 192.168.4.52
mode master
peer master51
ip 192.168.4.53
mode slave
ip 192.168.4.54
mode slave
hosts master51, master52
ips 192.168.4.100
mode exclusive
hosts slave53, slave54
ips 192.168.4.101, 192.168.4.102
mode balanced
#
2.2.4根据配置文件里设置,在数据节点主机天添加对应的授权用户
监控用户monitor agent
mmm_monitor mmm_agentd
51 :
mysql>grantreplicationclienton .to monitor@"%">
mysql>grantreplication client,process,super on .to agent@"%" > mysql> selectuser,hostfrom mysql.userwhereuserin ("monitor","agent");
52-54:
selectuser,hostfrom mysql.userwhereuserin ("monitor","agent");
2.3启动服务
2.3.0安装依赖的软件包
安装mmm_monitor服务和mmm_agentd运行依赖的软件包(51~55)
#yum -yinstall gccgcc-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 )
289gunzip Net-ARP-1.0.8.tgz
291tar -xf Net-ARP-1.0.8.tar
293cd Net-ARP-1.0.8/
295perl Makefile.PL
296make
297make install
2.3.1 启动数据节点主机上的 mmm_agentd服务(51~54)
# /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.
#
# /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
# netstat -utnalp| grep :9989
tcp 0 0 192.168.4.51:9989 0.0.0.0:* LISTEN 12389/mmm_agentd
# ls /var/log/mysql-mmm/
mmm_agentd.log
#
2.3.2 启动管理节点主机上的 mmm_monitor服务
# /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.
#
# /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
# netstat -utnalp| grep :9988
tcp 0 0 192.168.4.55:9988 0.0.0.0:* LISTEN 11433/mmm_mond
# ls /var/log/mysql-mmm/
mmm_mond.log
#
2.3.3 在管理节点55主机上,查看监控信息
# 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:
# mmm_control set_online 主机名
# 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!
#
# 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)
#
# ping -c 2192.168.4.100
数据节点主机查看 VIP 地址?51~54
#ipaddrshow |grep192.168.4.
在数据节点主机上添加访问数据的连接用户
51#mysql-uroot-p123456
mysql>grant all on gamedb.* to admin@"%"
->> mysql> select user,host from mysql.user where user="admin";
三、客户端254测试,高可用集群的配置
#mysql-h192.168.4.100-uamdin-p123456
页:
[1]