platform: rhel 5.6
software: mysql-mmm-2.2.1.tar.gz
mysql-5.1.59.tar.gz
//文档后面部分直接参考 《MMM Installation Guide
》
//作者:andy.feng
//网名:FH.CN
mysql-mmm architecture:
确定IP
mysql-a
192.168.56.101 master1 mysql-server-id=1
mysql-b
192.168.56.103 master2 mysql-server-id=2
mysql-slave
192.168.56.105 slave mysql-server-id=3
mysql-monitor
192.168.56.99 mmm_mon
虚拟IP
192.168.56.200 writer
192.168.56.201 reader
192.168.56.203 reader
192.168.56.205 reader
//install mysql
#tar xf mysql-5.1.59.tar.gz
#cd mysql-5.1.59
#useradd mysql -s /sbin/nologin
#mkdir -p /data/mysql_db
#./configure prefix=/usr/local/mysql localstatedir=/data/mysql_db
--with-extra-charsets=utf8,gb2312,gbk –with—pthread
enable-thread-safe-client && make && make install
cp /root/mysql-5.1.59/support-files/my-large.cnf /etc/my.cnf
vi /etc/my.cnf //issue the “server-id”
db1 修改 my.cnf,确定有以下内容
server-id = 1
\\修改系统启动默
log-bin=mysql-bin
binlog_format=ROW
log-slave-updates
sync_binlog=1
auto_increment_increment=2
auto_increment_offset=1
example:
[mysqld]
server-id = 1
skip-locking
log-bin=mysql-bin
binlog_format=ROW
log-slave-updates
sync_binlog=1
auto_increment_increment=2
auto_increment_offset=1
db2 修改 my.cnf,确定有以下内容
server-id = 2
log-bin=mysql-bin
binlog_format=ROW
log-slave-updates
sync_binlog=1
auto_increment_increment=2
auto_increment_offset=2
db3 修改 my.cnf,确定有以下内容
server-id = 3
log-bin=mysql-bin
log-slave-updates
db4 修改 my.cnf,确定有以下内容
server-id = 4
log-bin=mysql-bin
log-slave-updates
chown mysql: /usr/local/mysql –R
/usr/local/mysql/bin/mysql_install_db –user=mysql&
/usr/local/mysql/bin/mysqld_safe –user=mysql&
配置msyql 双主并测试
mysql-server:
grant replication super,slave on *.* to
@ identified by '';
slave-mysql-server:
change master to
master_host='' ,
master_user='' ,
master_password=''
master_log_file='' ,
master_log_pos=;
slave start;
show slave status\G
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
安装mysql-mmm
1. 安装mysql-mmm-agent
2. agent机器上要安装iproute 包,
3. 如果手工编译的 MYSQL,一定要把加载 MYSQL 的 LIB
# ECHO "/USR/LOCAL/MYSQL/LIB/MYSQL/" >> /ETC/LD.SO.CONF
#LDCONFIG
4. 安装perl库文件(cpan),cpan 分两种安装方式,一种是在线安装, 如下面所示;另一种是手动安装,手动安装需要根据安装模块 search.cpan.org 上 下载下来,然后再安装。
4.1 在 agent机器上都安装如下 perl 库(mysql-agent 需求的 perl 库)
有些 perl 库,特别是红色的三个库系统默认应该是有的,可以通过以下方法查看是否,安装,如果安装,就不必要安装,因为
安装这三个库比较麻烦,特别 DBD::mysql,需要下载软件手工编译
确认是否安装一下模块:
#find /usr/lib/perl5/ -name mysql.pm (rhel默认没有,需要手动安装DBD-mysql)
#find /usr/lib/perl5/ -name stat.pm
#find /usr/lib/perl5/ -name Basename.pm
红色的应该是系统自带的:
DBI and DBD::mysql (如果没有,这个要先装)
在 PERL MAKEFILE.PL 的时候,一定要指定你定制的一些 MYSQL 的信息
#PERL MAKEFILE.PL --MYSQL_CONFIG=/USR/LOCAL/MYSQL/BIN/MYSQL_CONFIG --WITH- MYSQL=/USR/LOCAL/MYSQL/
一定要 MAKE TEST,通过了再 MAKE INSTALL
File::Basename
File::stat
File::Temp
Net::Ping (放在最后安装)
Algorithm::Diff
Class::Singleton
Log::Log4perl
Log::Dispatch (需要安装ExtUtils-MakeMaker,Params-Validate,Sys-Syslog)
Mail:Send (需要安装
TimeDate,Pod::Escapes,Pod-Simple,ExtUtils-CBuilder,ExtUtils-
Par***S,Test-Harness,Compress-Raw-Zlib,Compress-Raw-Bzip2,IO-
Compress,Package-Constants,IO-Zlib,Text-Diff,Archive-Tar,podlators,Pod-
Readme,ExtUtils-Install,Module::Metadata,Test-Simple,Perl-OSType,Module-
Build,Test::Pod,MailTools)
Proc::Daemon
Thread::Queue(在 rhel5.6 版本中,需要先装 threads,再装 threads-shared,再装 threads-queue;依据提示 安装版本,否则后面到 mysql-mmm-monitor 无法启动)
Time::HiRes
=========================================================
Algorithm-Diff-1.1902.tar.gz ExtUtils-Par***S-2.21.tar.gz Module-Metadata-1.000002.tar.gz podlators-2.3.1.tar.gz Test-Simple-0.96.tar.gz
Archive-Tar-1.50.tar.gz File-Stat-0.01.tar.gz mysql-5.1.59.tar.gz Pod-Readme-0.10.tar.gz Text-Diff-0.35.tar.gz
Class-Singleton-1.4.tar.gz File-Temp-0.22.tar.gz mysql-mmm-2.2.1.tar.gz Pod-Simple-3.08.tar.gz Thread-Queue-2.11.tar.gz
Compress-Raw-Bzip2-2.017.tar.gz IO-1.24.tar.gz Net-ARP-1.0.6.tgz Proc-Daemon-0.14.tar.gz threads-1.71.tar.gz
Compress-Raw-Zlib-2.017.tar.gz IO-Compress-2.017.tar.gz Net-Ping-2.36.tar.gz shell.sh threads-shared-1.27.tar.gz
DBD-mysql-4.020.tar.gz IO-Interface-1.05.tar.gz Package-Constants-0.02.tar.gz Socket-1.95.tar.gz TimeDate-1.20.tar.gz
Devel-Symdump-2.07.tar.gz IO-Zlib-1.09.tar.gz Params-Validate-0.24.tar.gz Sys-Syslog-0.25.tar.gz Time-HiRes-1.9724.tar.gz
ExtUtils-CBuilder-0.27.tar.gz Log-Dispatch-2.27.tar.gz perl-DBI-1.52-2.el5.i386.rpm Test-Harness-3.16.tar.gz
ExtUtils-Constant-0.16.tar.gz Log-Log4perl-1.34.tar.gz Perl-OSType-1.000.tar.gz Test-Pod-1.44.tar.gz
ExtUtils-Install-1.54.tar.gz MailTools-2.08.tar.gz Pod-Coverage-0.20.tar.gz Test-Pod-Coverage-1.08.tar.gz
ExtUtils-MakeMaker-6.62.tar.gz Module-Build-0.3800.tar.gz Pod-Escapes-1.04.tar.gz Test-Portability-Files-0.05.tar.gz
=========================================================
5. 安装mysql-mmm
5.1 tar xf mysql-mmm..tar.gz
5.2 make install
6. 启动mysql-mmm-agent(是否能正常运行,能运行后,再关闭)
/etc/init.d/mysql-mmm-agent start
安装脚本:
#! /bin/bash
pathname="/usr/lib/perl5/site_perl/5.8.8/i386-linux-thread-multi/DBD"
cpanpath=/root/cpan
echo "/usr/local/mysql/lib/mysql/" >> /etc/ld.so.conf
ldconfig
file1="DBD-mysql-4.020.tar.gz"
file2="perl-DBI-1.52-2.el5.i386.rpm"
ls $cpanpath > /root/file
while read i
do
file3=$(rpm -qa perl-DBI |awk -F "1" '{print $1}')
if [ "$file3" != "perl-DBI-" ]
then
rpm -ivh $cpanpath/$i
sleep 2
else
if [ -d $pathname ]
then
tar xf $cpanpath/$i -C /tmp && cd /tmp/$(echo $i |awk -F ".tar" '{print $1}')
perl Makefile.PL && make test && make install
mv $cpanpath/$i /root
else
if [ "$i" = "$file1" ]
then
tar xf $cpanpath/$i -C /tmp && cd /tmp/$(echo $i |awk -F ".tar" '{print $1}')
perl Makefile.PL
--mysql_config=/usr/local/mysql/bin/mysql_config
--with-mysql=/usr/local/mysql && make test && make
install && mv $cpanpath/$i /root
continue
fi
fi
fi
done < /root/file
for j in `ls /root/cpan`
do
tar xf $cpanpath/$j -C /tmp && cd /tmp/$(echo $j |awk -F ".tar" '{print $1}')
perl Makefile.PL && make test && make install
mv $cpanpath/$j /root
done
tar xf /root/mysql-mmm* -C /tmp && cd /tmp/mysql-mmm* && make install
rm -rf /root/file
配 置 MYSQL-MMM-AGENTD
添加 agentd 使用的 mysql 用户,db1,db2,db3 都要添加
db1,db2,db3:
mysql>grant super,replication client,process on *.* to 'mmm_agent'@'192.168.56.101' identified by 'mmm_agent';
mysql>grant super,replication client,process on *.* to 'mmm_agent'@'192.168.56.103' identified by 'mmm_agent';
mysql>grant super,replication client,process on *.* to 'mmm_agent'@'192.168.56.105' identified by 'mmm_agent';
mysql>grant super,replication client,process on *.* to 'mmm_agent'@'192.168.56.99' identified by 'mmm_agent';
修改mysql-mmm配置文件
db1:
# cat /etc/mysql-mmm/mmm_agent.conf
include mmm_common.conf
this db1
# cat /etc/mysql-mmm/mmm_common.conf
active_master_role writer
cluster_interface eth0
pid_path /var/run/mmm_agentd.pid
bin_path /usr/lib/mysql-mmm/
replication_user slave
replication_password 123456
agent_user mmm_agent
agent_password 123456
ip 192.168.56.101
mode master
peer db2
ip 192.168.56.103
mode master
peer db1
ip 192.168.56.105
mode slave
hosts db1, db2
ips 192.168.56.200
mode exclusive
hosts db1, db2,db3
ips 192.168.56.201,192.168.56.203,192.168.56.205
mode balanced
将db1的/etc/mysql-mmm/mmm_common.conf文件拷贝到db2,db3,db4相同的位置,拷贝方法自定义
db2:
# cat /etc/mysql-mmm/mmm_agent.conf
include mmm_common.conf
this db2
db3:
# cat /etc/mysql-mmm/mmm_agent.conf
include mmm_common.conf
this db3
启动MYSQL-mmm_agent
db1,db2,db3:
# /etc/init.d/mysql-mmm-agent start
Daemon bin: '/usr/sbin/mmm_agentd'
Daemon pid: '/var/run/mmm_agentd.pid'
Starting MMM Agent daemon... Ok
# /etc/init.d/mysql-mmm-agent status
Daemon bin: '/usr/sbin/mmm_agentd'
Daemon pid: '/var/run/mmm_agentd.pid'
Checking MMM Agent process: running.
[root@(155/15)~]# ps aux | grep mmm
root 26758 0.0 0.1 11524 6912 ? S 14:52 0:00 mmm_agentd
root 26759 0.0 0.1 11568 7088 ? S 14:52 0:00 mmm_agentd
root 26798 0.0 0.0 3920 672 pts/1 S+ 14:55 0:00 grep mmm
[root@(155/15)~]# netstat -tulnp | grep mmm
tcp 0 0 192.168.56.101:9989 0.0.0.0:* LISTEN 26759/mmm_agentd
[root@(155/15)~]# /etc/init.d/mysql-mmm-agent --help
Daemon bin: '/usr/sbin/mmm_agentd'
Daemon pid: '/var/run/mmm_agentd.pid'
Usage: /etc/init.d/mysql-mmm-agent {start|stop|restart|status}
Note:如果不能启动,可以查看/var/log/mysql-mmm/mmm_agentd.log 文件的提示,或者启动时候的报错,最大的可能是perl对应模块没有安装成功,成功安装对应的模块就可以解决问题了。
配置MYSQL-MMM-monitor
创建mmm-monitor使用的mysql用户,在db1,db2,db3上
db1,db2,db3:
mysql>grant replication client on *.* to 'mmm_monitor'@'192.168.56.99' identified by '123456';
在实际使用中可以简化用户,让复制,agent,monitor使用同一个用户,注意权限就可以行了。下面配置monitor
db4:
# cat /etc/mysql-mmm/mmm_mon.conf
include mmm_common.conf
ip 10.1.1.12
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.56.105, 192.168.56.103, 192.168.56.101
monitor_user mmm_monitor
monitor_password mmm_monitor
debug 0
启动MYSQL-MMM-monitor
# /etc/init.d/mysql-mmm-monitor start
Daemon bin: '/usr/sbin/mmm_mond'
Daemon pid: '/var/run/mmm_mond.pid'
Starting MMM Monitor daemon: Ok
[root@(140/12)~]# /etc/init.d/mysql-mmm-monitor --help
Daemon bin: '/usr/sbin/mmm_mond'
Daemon pid: '/var/run/mmm_mond.pid'
Usage: /etc/init.d/mysql-mmm-monitor {start|stop|restart|status}
# ps aux | grep mmm
root 2737 0.0 0.2 13764 8892 ? S 15:10 0:00 mmm_mond
root 2738 1.3 0.9 108480 39992 ? Sl 15:10 0:00 mmm_mond
root 2745 0.4 0.1 10676 6668 ? S 15:10 0:00 perl /usr/lib/mysql-mmm//monitor/checker ping_ip
root 2748 0.5 0.1 12860 7776 ? S 15:10 0:00 perl /usr/lib/mysql-mmm//monitor/checker mysql
root 2750 0.4 0.1 10676 6668 ? S 15:10 0:00 perl /usr/lib/mysql-mmm//monitor/checker ping
root 2752 0.5 0.1 12860 7824 ? S 15:10 0:00 perl /usr/lib/mysql-mmm//monitor/checker rep_backlog
root 2754 0.5 0.1 12860 7820 ? S 15:10 0:00 perl /usr/lib/mysql-mmm//monitor/checker rep_threads
管理MYSQL-MMM-monitor
查看mmm集群节点的状态:
db4:
# mmm_control mode
ACTIVE
# mmm_control show
db1(192.168.56.101) master/AWAITING_RECOVERY. Roles:
db2(192.168.56.103) master/AWAITING_RECOVERY. Roles:
db3(192.168.56.105) slave/AWAITING_RECOVERY. Roles:
现在都处于AWATING_RECOVERY状态
我们将db1和db2两个master置于ONLINE状态
# mmm_control set_online db1
OK: State of 'db1' changed to ONLINE. Now you can wait some time and check its new roles!
# mmm_control set_online db2
OK: State of 'db2' changed to ONLINE. Now you can wait some time and check its new roles!
# mmm_control show
db1(192.168.56.101) master/ONLINE. Roles: reader(192.168.56.203), writer(192.168.56.200)
db2(192.168.56.103) master/ONLINE. Roles: reader(192.168.56.201), reader(192.168.56.205)
db3(192.168.56.105) slave/AWAITING_RECOVERY. Roles:。
现在mysql-mmm两个master的模式已经搭建完成,我们对所有节点做一次检查:
# mmm_control checks all
db2 ping [last change: 2011/05/18 15:10:15] OK
db2 mysql [last change: 2011/05/18 15:10:15] OK
db2 rep_threads [last change: 2011/05/18 15:10:15] OK
db2 rep_backlog [last change: 2011/05/18 15:10:15] OK: Backlog is null
db3 ping [last change: 2011/05/18 15:10:15] OK
db3 mysql [last change: 2011/05/18 15:10:15] OK
db3 rep_threads [last change: 2011/05/18 15:10:15] ERROR: Replication is not set up
db3 rep_backlog [last change: 2011/05/18 15:10:15] ERROR: Replication is not set up
db1 ping [last change: 2011/05/18 15:10:15] OK
db1 mysql [last change: 2011/05/18 15:10:15] OK
db1 rep_threads [last change: 2011/05/18 15:10:15] OK
db1 rep_backlog [last change: 2011/05/18 15:10:15] OK: Backlog is null
db1和db2已经正常了,只有db3复制是失败的,因为我们还没有配置,只要将db3作为slave加入其中,就完成两个master多个slave的架构。
阅读(3064) | 评论(0) | 转发(0) |