共计 7716 个字符,预计需要花费 20 分钟才能阅读完成。
丸趣 TV 小编给大家分享一下如何安装 mysql-mmm,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!
安装 mysql-mmm
1)安装 epel
相关文档参见:http://fedoraproject.org/wiki/EPEL
rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-4.noarch.rpm
2) monitor 软件安装
[root@localhost ~]# yum install ndash;y mysql-mmm-monitor-*
包如下:
[root@localhost ~]# rpm -qa|grep mysql
mysql-mmm-monitor-2.2.1-1.el5
mysql-mmm-2.2.1-1.el5
mysql-5.0.77-4.el5_5.4
3)所在机器安装(包括 master,slave)
[root@localhost ~]# yum install ndash;y -mmm-agent*
包如下:
[root@localhost ~]# rpm -qa|grep mysql
mysql-test-5.0.77-4.el5_5.4
mysql-mmm-agent-2.2.1-1.el5
mysql-5.0.77-4.el5_5.4
mysql-server-5.0.77-4.el5_5.4
mysql-devel-5.0.77-4.el5_5.4
mysql-bench-5.0.77-4.el5_5.4
mysql-mmm-2.2.1-1.el5
mysql-connector-odbc-3.51.26r1127-1.el5
配置文件
1)monitor 配置文件
[root@localhost ~]# vi /etc/mysql-mmm/mmm_mon.conf
include mmm_common.conf
monitor
ip 127.0.0.1
pid_path /var/run/mysql-mmm/mmm_mond.pid
bin_path /usr/libexec/mysql-mmm
status_path /var/lib/mysql-mmm/mmm_mond.status
ping_ips 172.16.71.128,172.16.71.130 #master,slave 实际数据库 ip
auto_set_online 60
/monitor
host default
monitor_user mmm_monitor
monitor_password 10jqka
/host
Debug
2)通用的配置文件,在 monitor 及 master,slave 上放置的这个文件都一致
[root@localhost ~]# vi /etc/mysql-mmm/mmm_common.conf
active_master_role writer
host default
cluster_interface eth0
pid_path /var/run/mysql-mmm/mmm_agentd.pid
bin_path /usr/libexec/mysql-mmm/
replication_user replicant
replication_password 10jqka
agent_user mmm_agent
agent_password 10jqka
/host
host db1
ip 172.16.71.128 #真实 master 数据库 ip
mode master
peer db2
/host
host db2
ip 172.16.71.130 #真实 master 数据库 ip
mode master
peer db1
/host
# host db3
# ip 192.168.100.51 #真实 slave 数据库 ip
# mode slave
# /host
role writer
hosts db1, db2
ips 172.16.71.253 #虚拟写数据库 ip
mode exclusive
/role
role reader
hosts db1, db2
ips 172.16.71.251,172.16.71.252 #虚拟读数据库 ip
mode balanced
/role
3)master,slave 配置文件
[root@localhost ~]# vi /etc/mysql-mmm/mmm_agent.conf
include mmm_common.conf
# The this variable refers to this server. Proper operation requires
# that this server (db1 by default), as well as all other servers, have the
# proper IP addresses set in mmm_common.conf.
this db1# 如为第一台 master db 则为 db1 如为第二台则为 db2 与 mmm_common.conf 里的机器对应
查看效果
1)启动 db1 的相关服务
service mysqld start
service mysql-mmm-agent start
数据库授权:所有数据库的授权一致
GRANT REPLICATION CLIENT ON *.* TO mmm_monitor @ 172.16.71.% IDENTIFIED BY 10jqka
GRANT SUPER, REPLICATION CLIENT, PROCESS ON *.* TO mmm_agent @ 172.16.71.% IDENTIFIED BY 10jqka
grant all on *.* to replicant@ 172.16.71.% identified by 10jqka
flush privileges;
2)启动 monitor 相关服务
service mysql-mmm-monitor start
查看状态:
mmm_control show
把 db1 设置为 online 状态:
mmm_control set_online db1
开放 mmm_agentd 端口 9989
真实机器查看分配的 vip 地址
[root@localhost ~]# ip a
1: lo: LOOPBACK,UP,LOWER_UP mtu 16436 qdisc noqueue
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: BROADCAST,MULTICAST,UP,LOWER_UP mtu 1500 qdisc pfifo_fast qlen 1000
link/ether 00:0c:29:ef:79:70 brd ff:ff:ff:ff:ff:ff
inet 172.16.71.132/24 brd 172.16.71.255 scope global eth0
inet 172.16.71.251/32 scope global eth0
inet 172.16.71.253/32 scope global eth0
inet6 fe80::20c:29ff:feef:7970/64 scope link
valid_lft forever preferred_lft forever
主主(master-master)同步配置
1)172.16.71.132 机器 my.cnf
skip-name-resolve
server_id = 132
set-variable = key_buffer_size=512M
set-variable = table_cache=32
set-variable = sort_buffer_size=32M
set-variable = read_buffer_size=32M
set-variable = max_connections=2100
set-variable = log_slow_queries=/var/lib/mysql/log/mysql-slow.log
set-variable = log_bin=/var/lib/mysql/log/mysql-bin
set-variable = long_query_time=1
set-variable = thread_concurrency=16
set-variable = tmp_table_size=4000000000
set-variable = slave_skip_errors=all
#replicate-ignore-db=mysql
#replicate-ignore-db=test 发觉加上这个 ignore 选项后会导致 mmm 接管出现点小问题不知道为什么
log-slave-updates
sync_binlog=1
auto_increment_increment=2
auto_increment_offset=1
进入 mysql 配置设置为从
mysql change master to master_host= 172.16.71.128
mysql change master to master_user= repl
mysql change master to master_password= 10jqka
mysql start slave
主(master)服务器配置:
GRANT REPLICATION SLAVE ON *.* TO repl @ 172.16.71.% IDENTIFIED BY 10jqka
2)172.16.71.128 机器 my.cnf 配置
skip-name-resolve
server_id = 1
set-variable = key_buffer_size=512M
set-variable = table_cache=32
set-variable = sort_buffer_size=32M
set-variable = read_buffer_size=32M
set-variable = max_connections=2100
set-variable = log_slow_queries=/var/lib/mysql/log/mysql-slow.log
set-variable = log_bin=/var/lib/mysql/log/mysql-bin
set-variable = long_query_time=1
set-variable = thread_concurrency=16
set-variable = tmp_table_size=4000000000
set-variable = slave_skip_errors=all
#replicate-ignore-db=mysql
#replicate-ignore-db=test
log-slave-updates
sync_binlog=1
auto_increment_increment=2
auto_increment_offset=2
进入 mysql 配置设置为从
mysql change master to master_host= 172.16.71.132
mysql change master to master_user= repl
mysql change master to master_password= 10jqka
mysql start slave
主(master)服务器配置:
GRANT REPLICATION SLAVE ON *.* TO repl @ 172.16.71.% IDENTIFIED BY 10jqka
其它从 (slave) 服务器配置:
my.cnf 配置
skip-name-resolve
server_id = 1
set-variable = key_buffer_size=512M
set-variable = table_cache=32
set-variable = sort_buffer_size=32M
set-variable = read_buffer_size=32M
set-variable = max_connections=2100
set-variable = log_slow_queries=/var/lib/mysql/log/mysql-slow.log
set-variable = log_bin=/var/lib/mysql/log/mysql-bin
set-variable = long_query_time=1
set-variable = thread_concurrency=16
set-variable = tmp_table_size=4000000000
set-variable = slave_skip_errors=all
mysql change master to master_host= 172.16.71.253
mysql change master to master_user= repl
mysql change master to master_password= 10jqka mysql change master to master_log_file= rsquo;mysql-bin.00001 rsquo;;
mysql change master to master_log_pos=128; mysql start slave
或者在 my.cnf 加入
server-id=2
master-host=172.16.71.253
master-user=repl
master-password=10jqka
问题 1:
两台机器互为对方的主,此时不能使用 master 的 VIP 作为该两机器的主,如果使用 VIP 作为 master 的话没有一台先起来作为 vip 机器的话些会导致 monitor 不能使用,日志如下:
2010/12/06 16:29:46 WARN db1 is not replicating from db2
2010/12/06 16:29:46 WARN db2 is not replicating from db1
问题 2:
当 /etc/mysql-mmm/mmm_mon.conf 的 auto_set_online 3 时间设置为较长时,在瞬间关闭现有主,开启现未开启的备时,会导致 monitor 不能自动切换 VIP 导致 mmm 不可用,需要手工设置 online 状态,有时候甚至会导致 monitor 启动问题。为防止这情况发生可以把该时间设置短些,或者先让一其中的一台主起来后,再关闭另一台。
问题 3:ERROR:Can t connect to monitor daemon
查看进程一般少了 perl 相关进程,莫名其妙的感觉,经多次尝试试验,一般都是在 mysql 那些拥有 agent 机器上的配置问题,还有 monitor 的 auto_set_online 时间设置
[root@localhost ~]# ps axu|grep mmm
root 3113 0.0 7.6 14000 8956 ? S 16:27 0:00 mmm_mond
root 3115 0.9 33.2 106440 38976 ? Sl 16:27 0:00 mmm_mond
root 3136 0.4 5.5 10388 6456 ? S 16:28 0:00 perl /usr/libexec/mysql-mmm/monitor/checker ping_ip
root 3140 0.4 6.5 15208 7640 ? S 16:28 0:00 perl /usr/libexec/mysql-mmm/monitor/checker mysql
root 3141 0.3 5.4 10388 6448 ? S 16:28 0:00 perl /usr/libexec/mysql-mmm/monitor/checker ping
root 3142 0.5 6.5 15208 7636 ? S 16:28 0:00 perl /usr/libexec/mysql-mmm/monitor/checker rep_backlog
root 3144 0.6 6.4 15208 7592 ? S 16:28 0:00 perl /usr/libexec/mysql-mmm/monitor/checker rep_threads
root 3148 0.0 0.5 3916 652 pts/0 R+ 16:28 0:00 grep mmm
其它补充资料
主从状态查看:
查看 master 的状态
SHOW MASTER STATUS;
Position 不应为 0
查看 slave 的状态
show slave status;
Slave_IO_Running | Slave_SQL_Running 这两个字段 应为 YES|YES.
show processlist; 查看进程
slave start; #启动从复制
STOP SLAVE; #停止从复制
RESET MASTER; #重设 master 日志
RESET SLAVE;# 重设 slave 日志
当 Slave_IO_Running: 为 No 时,从服务器无法同步时操作下如
SLAVE STOP;# 停止 slave
CHANGE MASTER TO MASTER_LOG_FILE= mysql-bin.000001 , MASTER_LOG_POS=0;
#把 master_log_file 设置为从主 show master status; 得出来的日志名,POS 设置为 0
SLAVE START;# 再次启用 slave
Mysql 普通主从配置(未使用 mmm 参考)
配置主从 my.cnf 文件:
skip-innodb
skip-name-resolve
server_id = 132
set-variable = key_buffer_size=512M
set-variable = table_cache=32
set-variable = sort_buffer_size=32M
set-variable = read_buffer_size=32M
set-variable = max_connections=2100
set-variable = log_slow_queries=/var/lib/mysql/log/mysql-slow.log
set-variable = log_bin=/var/lib/mysql/log/mysql-bin# 从库这条语句注释掉
set-variable = long_query_time=1
set-variable = thread_concurrency=16
set-variable = tmp_table_size=4000000000
set-variable = slave_skip_errors=all
因为 mysql 版本不同在从服务器下开启了下面选项导致同步不能进行
replicate-ignore-db=mysql
replicate-do-db =test
以上是“如何安装 mysql-mmm”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注丸趣 TV 行业资讯频道!