作为初学者,要想取得进步,成为高手,首先应该了解自己的不足之处.
全部博文(117)
分类: Mysql/postgreSQL
2011-08-25 21:57:52
1 简介
CLUSTER允许一台服务器同时运行多个Agent客户端,或者运行多个Monitor
每个Agent都会有自己的端口,lock文件,日志文件
一个Agent只能对应一个Monitor,如果两个Monitor同时控制一个Agent,则会导致该Agent出现arp冲突,具体表现为:被设置的IP地址不稳定
同样,每个Monitor,也有自己的服务端口,lock文件,日志文件,以及自己控制的Agent
2 Agent CLUSTER
注意:tar包安装与yum安装后的配置文件略有不同
主要包含区别在于/etc/init.d/mysql-mmm-agent_CLUSTER文件,代码如下,大概意思是
1,指定一个集群节点的名字
2,指定lock文件
3,判断,如果CLUSTER不为空,则把@$CLUSTER传给/usr/sbin/mmm_agentd脚本,用以启动相应的agent cluster
# Cluster name (it can be empty for default cases)
CLUSTER='test1'
LOCKFILE='/var/lock/subsys/mysql-mmm-agent_test1'
prog='MMM Agent Daemon'
#-----------------------------------------------------------------------
# Paths
if [ "$CLUSTER" != "" ]; then
MMMD_AGENT_BIN="/usr/sbin/mmm_agentd @$CLUSTER"
MMMD_AGENT_PIDFILE="/var/run/mysql-mmm/mmm_agentd_$CLUSTER.pid"
else
MMMD_AGENT_BIN="/usr/sbin/mmm_agentd"
MMMD_AGENT_PIDFILE="/var/run/mysql-mmm/mmm_agentd.pid"
fi
#-----------------------------------------------------------------------
启动文件中设置好CLUSTER后,还需要修改两个配置文件
1, mmm_common_CLUSTER.conf,agent_port代表agent的启动端口,mysql_port代表控制的MySQL端口,pid_path的路径,名字用CLUSTER来区分.
active_master_role writer
cluster_interface eth0
agent_port 9911
mysql_port 3306
pid_path /var/run/mysql-mmm/mmm_agentd_.pid
bin_path /usr/libexec/mysql-mmm/
replication_user replication
replication_password segD{cX56
agent_user mmm_agent
agent_password segD{cX56
2, mmm_agent_CLUSTER.conf,注意修改CLUSTER名字,对应到mmm_common_CLUSTER.conf文件
include mmm_common_CLUSTER.conf
this db1
3 Monitor CLUSTER
主要有三个文件,分别是
1,mmm_common_CLUSTER.conf,这个与Agent的一致
2,mmm_mon_CLUSTER.conf,监控端的配置文件
include mmm_common_test1.conf
ip 127.0.0.1
port 9991
pid_path /var/run/mysql-mmm/mmm_mond_test1.pid
bin_path /usr/libexec/mysql-mmm
status_path /var/lib/mysql-mmm/mmm_mond_test1.status
ping_interval 1
ping_ips 192.168.250.2, 192.168.250.251, 192.168.250.252
flap_duration 3600
flap_count 3
auto_set_online 0
careful_startup 0
mode active
wait_for_other_master 120
# The kill_host_bin does not exist by default, though the monitor will
# throw a warning about it missing. See the section 5.10 "Kill Host
# Functionality" in the PDF documentation.
#
# kill_host_bin /usr/libexec/mysql-mmm/monitor/kill_host
#
monitor_user mmm_monitor
monitor_password segD{cX56
check_period 5
trap_period 10
timeout 2
restart_after 10000
max_backlog 600
debug 0
3,日志文件
mmm_mon_log_CLUSTER.conf
#log4perl.logger = ERROR, MMMLog, MailFatal
#log4perl.logger = FATAL, MMMLog
log4perl.logger = INFO, MMMLog, MailFatal
log4perl.appender.MMMLog = Log::Log4perl::Appender::File
log4perl.appender.MMMLog.Threshold = INFO
log4perl.appender.MMMLog.filename = /var/log/mysql-mmm/mmm_mond_CLUSTER.log
log4perl.appender.MMMLog.recreate = 1
log4perl.appender.MMMLog.layout = PatternLayout
log4perl.appender.MMMLog.layout.ConversionPattern = %d %5p %m%n
log4perl.appender.MailFatal = Log::Dispatch::Email::MailSender
log4perl.appender.MailFatal.Threshold = ERROR
log4perl.appender.MailFatal.from = mmm@example.com
log4perl.appender.MailFatal.to = ning_lianjie@163.com
log4perl.appender.MailFatal.buffered = 0
log4perl.appender.MailFatal.subject = FATAL error in mysql-mmm-monitor
log4perl.appender.MailFatal.layout = PatternLayout
log4perl.appender.MailFatal.layout.ConversionPattern = %d %m%n
4 实际部署 4.1 信息整理
CLUSTER |
Function |
HOSTNAME |
IP |
MySQL Port |
Server ID |
VIP Writer |
VIP READER |
note |
test1 |
Agent |
master1 |
192.168.250.251 |
3307 |
1 |
192.168.250.111 |
|
|
Agent |
master2 |
192.168.250.252 |
3307 |
2 |
|
192.168.250.112 |
|
|
test2 |
Agent |
master1 |
192.168.250.251 |
3308 |
1 |
192.168.250.113 |
|
|
Agent |
master2 |
192.168.250.252 |
3308 |
2 |
|
192.168.250.114 |
|
|
test1/test2 |
Monitor |
monitor253 |
192.168.250.253 |
- |
- |
- |
- |
- |
4.2 MySQL帐号添加
GRANT REPLICATION SLAVE ON *.* TO 'replication'@'192.168.250.251' IDENTIFIED BY 'segD{cX56';
GRANT REPLICATION SLAVE ON *.* TO 'replication'@'192.168.250.252' IDENTIFIED BY 'segD{cX56';
GRANT SUPER, REPLICATION CLIENT, PROCESS ON *.* TO 'mmm_agent'@'192.168.250.251' IDENTIFIED BY 'segD{cX56';
GRANT SUPER, REPLICATION CLIENT, PROCESS ON *.* TO 'mmm_agent'@'192.168.250.252' IDENTIFIED BY 'segD{cX56';
GRANT REPLICATION CLIENT ON *.* TO 'mmm_monitor'@'192.168.250.253' IDENTIFIED BY 'segD{cX56';
4.3 MySQL主从配置
#重置binlog的命令RESET MASTER;
在3307端口的mysql执行,
CHANGE MASTER TO master_host='192.168.250.252', master_port=3307, master_user='replication', master_password='segD{cX56', master_log_file='mysql-bin.000001', master_log_pos=0;
START SLAVE;
CHANGE MASTER TO master_host='192.168.250.251', master_port=3307, master_user='replication', master_password='segD{cX56', master_log_file='mysql-bin.000001', master_log_pos=0;
START SLAVE;
在3308端口的mysql执行
CHANGE MASTER TO master_host='192.168.250.252', master_port=3308, master_user='replication', master_password='segD{cX56', master_log_file='mysql-bin.000001', master_log_pos=0;
START SLAVE;
CHANGE MASTER TO master_host='192.168.250.251', master_port=3308, master_user='replication', master_password='segD{cX56', master_log_file='mysql-bin.000001', master_log_pos=0;
START SLAVE;
4.4 Agent配置
以master1的3307端口为例,在master2上,3307端口的mysql,注意修改this db2
1. 下载yum源
wget
rpm -ivh epel-release-5-4.noarch.rpm
2. 安装mysql-mmm-agent
会自动安装依赖包
yum install mysql-mmm-agent
3. 修改配置文件(分别在master1和master2上修改)
mmm_common_test1.conf
active_master_role writer
cluster_interface eth0
agent_port 9991
mysql_port 3307
pid_path /var/run/mysql-mmm/mmm_agentd_test1.pid
bin_path /usr/libexec/mysql-mmm/
replication_user replication
replication_password segD{cX56
agent_user mmm_agent
agent_password segD{cX56
ip 192.168.250.251
mode master
peer db2
ip 192.168.250.252
mode master
peer db1
hosts db1, db2
ips 192.168.250.111
mode exclusive
hosts db1, db2
ips 192.168.250.112
mode balanced
mmm_agent_test1.conf
include mmm_common_test1.conf
this db1
复制一个启动文件,并添加执行权限
注意,如果用restart重启,需要在stop和start之间添加sleep,否则在进程未杀死时,就启动了,导致重启失败.
cp /etc/init.d/mysql-mmm-agent /etc/init.d/mysql-mmm-agent-test1
chmod +x /etc/init.d/mysql-mmm-agent-test1
修改
vim /etc/init.d/mysql-mmm-agent-test1
# Cluster name (it can be empty for default cases)
CLUSTER='test1'
LOCKFILE='/var/lock/subsys/mysql-mmm-agent_test1'
prog='MMM Agent Daemon'
#-----------------------------------------------------------------------
# Paths
if [ "$CLUSTER" != "" ]; then
MMMD_AGENT_BIN="/usr/sbin/mmm_agentd @$CLUSTER"
MMMD_AGENT_PIDFILE="/var/run/mysql-mmm/mmm_agentd_$CLUSTER.pid"
else
MMMD_AGENT_BIN="/usr/sbin/mmm_agentd"
MMMD_AGENT_PIDFILE="/var/run/mysql-mmm/mmm_agentd.pid"
fi
#-----------------------------------------------------------------------
4.5 Monitor配置
主要有以下配置文件
mmm_common_test1.conf(与Agent一致)
mmm_mon_log_test1.conf
说明:MailFatal为邮件报警模块
perl日志级别,由低到高:INFO,WARN,ERROR,FATAL
log4perl.logger = INFO, MMMLog, MailFatal
#log4perl.logger = FATAL, MMMLog
log4perl.appender.MMMLog = Log::Log4perl::Appender::File
log4perl.appender.MMMLog.Threshold = INFO
log4perl.appender.MMMLog.filename = /var/log/mysql-mmm/mmm_mond_test1.log
log4perl.appender.MMMLog.recreate = 1
log4perl.appender.MMMLog.layout = PatternLayout
log4perl.appender.MMMLog.layout.ConversionPattern = %d %5p %m%n
log4perl.appender.MailFatal = Log::Dispatch::Email::MailSender
log4perl.appender.MailFatal.Threshold = ERROR
log4perl.appender.MailFatal.from = mmm@example.com
log4perl.appender.MailFatal.to = ning_lianjie@163.com
log4perl.appender.MailFatal.buffered = 0
log4perl.appender.MailFatal.subject = FATAL error in mysql-mmm-monitor from monitor253_test1
log4perl.appender.MailFatal.layout = PatternLayout
log4perl.appender.MailFatal.layout.ConversionPattern = %d %m%n
mmm_mon_test1.conf
include mmm_common_test1.conf
ip 127.0.0.1
port 9981
pid_path /var/run/mysql-mmm/mmm_mond_test1.pid
bin_path /usr/libexec/mysql-mmm
status_path /var/lib/mysql-mmm/mmm_mond_test1.status
ping_interval 1
ping_ips 192.168.250.2, 192.168.250.251, 192.168.250.252
flap_duration 3600
flap_count 3
auto_set_online 0
careful_startup 0
mode active
wait_for_other_master 120
monitor_user mmm_monitor
monitor_password segD{cX56
check_period 5
trap_period 10
timeout 2
restart_after 10000
max_backlog 600
debug 0
启动文件/etc/init.d/mysql-mmm-monitor-test1
cp /etc/init.d/mysql-mmm-monitor /etc/init.d/mysql-mmm-monitor-test1
修改部分如下:
# Cluster name (it can be empty for default cases)
CLUSTER='test1'
LOCKFILE='/var/lock/subsys/mysql-mmm-monitor_test1'
prog='MMM Monitor Daemon'
if [ "$CLUSTER" != "" ]; then
MMMD_MON_BIN="/usr/sbin/mmm_mond @$CLUSTER"
MMMD_MON_PIDFILE="/var/run/mysql-mmm/mmm_mond_$CLUSTER.pid"
else
MMMD_MON_BIN="/usr/sbin/mmm_mond"
MMMD_MON_PIDFILE="/var/run/mysql-mmm/mmm_mond.pid"
fi
4.6 测试
在master1和master2上启动agent
/etc/init.d/mysql-mmm-agent-test1 start
在monitor253启动监控
/etc/init.d/mysql-mmm-monitor-test1 start
查看状态
[root@monitor253 mysql-mmm]# mmm_control @test1 show
db1(192.168.250.251) master/AWAITING_RECOVERY. Roles:
db2(192.168.250.252) master/ADMIN_OFFLINE. Roles:
[root@monitor253 mysql-mmm]# mmm_control @test1 set_online db1
OK: State of 'db1' changed to ONLINE. Now you can wait some time and check its new roles!
[root@monitor253 mysql-mmm]# mmm_control @test1 set_online db2
OK: State of 'db2' changed to ONLINE. Now you can wait some time and check its new roles!
[root@monitor253 mysql-mmm]# mmm_control @test1 show
db1(192.168.250.251) master/ONLINE. Roles: writer(192.168.250.111)
db2(192.168.250.252) master/ONLINE. Roles: reader(192.168.250.112)
[root@monitor253 mysql-mmm]# mmm_control @test1 checks
db2 ping [last change: 2011/08/25 17:28:32] OK
db2 mysql [last change: 2011/08/25 17:36:19] OK
db2 rep_threads [last change: 2011/08/25 17:37:13] OK
db2 rep_backlog [last change: 2011/08/25 17:36:15] OK: Backlog is null
db1 ping [last change: 2011/08/25 17:28:32] OK
db1 mysql [last change: 2011/08/25 17:36:19] OK
db1 rep_threads [last change: 2011/08/25 17:37:10] OK
db1 rep_backlog [last change: 2011/08/25 17:36:15] OK: Backlog is null
用vip可以连接
mysql -ummm_monitor -p'segD{cX56' -h192.168.250.111 -P3307
mysql -ummm_monitor -p'segD{cX56' -h192.168.250.112 -P3307