Chinaunix首页 | 论坛 | 博客
  • 博客访问: 33194
  • 博文数量: 7
  • 博客积分: 459
  • 博客等级: 下士
  • 技术积分: 65
  • 用 户 组: 普通用户
  • 注册时间: 2008-06-16 23:38
文章分类
文章存档

2010年(7)

分类: LINUX

2010-10-27 19:00:56

目录
文档说明        3
网络拓朴        3
系统        3
主mysql        3
主mysql配置        4
从mysql        5
从mysql配置        6
修改两台的hosts        6
主创建复制库并导出到从以下步骤我省了        7
mon(主从相同)        7
heartbeat(主从相同)        8
设置服务自动启动(主从相同)        9

文档说明

  本文档,设计了一个MySQL主从复制,用mon对的mysql服务进行监控,heartbeat提供对外的VIP,mysql从通过获得主mysql的日志,把数据同步到从,当主down机后,mon检测到主down机后,会停掉主机的heartbeat服务,VIP和mon服务将会自己转移到从,当主处理好后,会通过从的日志把数据同步到主,待主同步完数据后,可以手机把VIP和mon服务移回到主。

网络拓朴

IP地址说明:
Master
eth0:172.20.67.13 eth1: 172.20.67.22;
Slave
eth0:172.20.67.46 eth1: 172.20.67.53;
VIP:172.20.67.23

系统

CentOS4.6(完全)

mysql

# mv /etc/rc.d/init.d/mysqld /etc/rc.d/init.d/mysqld.bak
# mv /etc/my.cnf /etc/my.cnf.bak
# rm -rf /var/lib/mysql/
# vi /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=master
# service network restart
# su –
# cd /usr/local/src/
# tar zxvf mysql-5.0.51a.tar.gz
# cd mysql-5.0.51a
# ./configure --prefix=/usr/local/mysql --localstatedir=/var/lib/mysql --with-mysqld-user=mysql --without-debug --with-big-tables --with-charset=gbk --with-collation=gbk_chinese_ci --with-extra-charsets=all --with-pthread --enable-thread-safe-client --enable-assembler --without-isam --without-innodb --without-ndb-debug --with-mysqli && make && make install
# cd /usr/local/mysql/
# bin/mysql_install_db --user=mysql
#  chown -R root:mysql .
# chown -R mysql /var/lib/mysql
# cp share/mysql/my-huge.cnf /etc/my.cnf
# cp share/mysql/mysql.server /etc/rc.d/init.d/mysqld
# chkconfig mysqld off
# chmod 755 /etc/rc.d/init.d/mysqld
# chkconfig --add mysqld
# vi /root/.bash_profile
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs

PATH=/usr/local/mysql/bin: $ PATH: $ HOME/bin

export PATH
unset USERNAME
# su –

mysql配置

# service mysqld restart
# mysql
mysql> use mysql
mysql> update user set password=password('123123') where user='root';
mysql> grant replication slave on *.* to 'copy'@'%' identified by '123123';
mysql> flush privileges;
# vi /etc/my.cnf(增加以下内容)
master-host=slave
master-user=copy
master-password=123123
master-connect-retry=60
replicate-do-db=zds
log-slave-updates
binlog-do-db=zds

mysql

mv /etc/rc.d/init.d/mysqld /etc/rc.d/init.d/mysqld.bak
# mv /etc/my.cnf /etc/my.cnf.bak
# rm -rf /var/lib/mysql/
# vi /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=slave
# service network restart
# hostname slave
# su –
# cd /usr/local/src/
# tar zxvf mysql-5.0.51a.tar.gz
# cd mysql-5.0.51a
# ./configure --prefix=/usr/local/mysql --localstatedir=/var/lib/mysql --with-mysqld-user=mysql --without-debug --with-big-tables --with-charset=gbk --with-collation=gbk_chinese_ci --with-extra-charsets=all --with-pthread --enable-thread-safe-client --enable-assembler --without-isam --without-innodb --without-ndb-debug --with-mysqli && make && make install
# cd /usr/local/mysql/
# bin/mysql_install_db --user=mysql
#  chown -R root:mysql .
# chown -R mysql /var/lib/mysql
# cp share/mysql/my-huge.cnf /etc/my.cnf
# cp share/mysql/mysql.server /etc/rc.d/init.d/mysqld
# chkconfig mysqld off
# chmod 755 /etc/rc.d/init.d/mysqld
# chkconfig --add mysqld
# vi /root/.bash_profile
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs

PATH=/usr/local/mysql/bin: $ PATH: $ HOME/bin

export PATH
unset USERNAME
# su –

mysql配置

# service mysqld start
# mysql
mysql> use mysql
mysql> update user set password=password('123123') where user='root';
mysql> grant replication slave on *.* to 'copy'@'%' identified by '123123';
mysql> flush privileges;
# vi /etc/my.cnf(增加以下内容)
master-host=master
master-user=copy
master-password=123123
report-host=slave
replicate-do-db=zds
log-slave-updates
binlog-do-db=zds
server-id       = 2(些处为修改)

修改两台的hosts

# vi /etc/hosts
# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1               localhost.localdomain localhost
172.20.67.13    master
172.20.67.22    master
172.20.67.46    slave
172.20.67.53    slave

创建复制库并导出到从以下步骤我省了

# mysql -p
mysql> create database zds;

mon(主从相同)

# rpm -ihv *
warning: mon-1.2.0-1.el4.rf.i386.rpm: V3 DSA signature: NOKEY, key ID 6b8d79e6
Preparing...                ########################################### [100%]
   1:perl-Time-Period       ########################################### [ 13%]
   2:perl-Net-SNPP          ########################################### [ 25%]
   3:perl-Math-TrulyRandom  ########################################### [ 38%]
   4:perl-Convert-BER       ########################################### [ 50%]
   5:perl-Mon               ########################################### [ 63%]
   6:perl-AOL-TOC           ########################################### [ 75%]
   7:mon                    ########################################### [ 88%]
   8:perl-Authen-PAM        ########################################### [100%]
# vi /etc/mon/mon.cf
### Extremely basic mon.cf file

### global options
cfbasedir   = /etc/mon
pidfile     = /var/run/mon.pid
statedir    = /var/lib/mon/state.d
logdir      = /var/lib/mon/log.d
dtlogfile   = /var/lib/mon/log.d/downtime.log
alertdir    = /usr/lib/mon/alert.d
mondir      = /usr/lib/mon/mon.d
maxprocs    = 20
histlength  = 100
randstart   = 60s
authtype    = pam
userfile    = /etc/mon/userfile

### group definitions (hostnames or IP addresses)
hostgroup servers master(从机把master改为slave)

watch servers
    service mysql
        interval 10s
        monitor msql-mysql.monitor
        period wd {Mon-Sun}
                alert test.alert
       alertevery 600s

alertafter 3


### See /usr/doc for the original example...
# vi /usr/lib/mon/alert.d/test.alert
#!/bin/sh
#
#  $ Id: test.alert,v 1.1.1.1 2004/06/09 05:18:07 trockij Exp  $
echo "`date`  $ *" >> /tmp/test.alert.log
service heartbeat stop
# chmod 777 /usr/lib/mon/alert.d/test.alert
# vi /usr/lib/mon/mon.d/msql-mysql.monitor(以下为修改的部份,本脚本来自mon的源码包)
   # $dbh = DBI->connect( "DBI: $ mode: $ database: $ host: $ options{port}",  $ username,  $ password);
$ dbh = DBI->connect( "DBI:mysql:mysql:slave: $ options{port}", root, 123123);
# chmod 777 /usr/lib/mon/mon.d/mysql.monitor
chkconfig mon off

heartbeat(主从相同)

yum install heartbeat
# cp /usr/share/doc/heartbeat-2.1.3/ha.cf /etc/ha.d/
# cp /usr/share/doc/heartbeat-2.1.3/authkeys /etc/ha.d/
# cp /usr/share/doc/heartbeat-2.1.3/haresources /etc/ha.d/
# vi /etc/ha.d/ha.cf
debugfile /var/log/ha-debug
logfile /var/log/ha-log
logfacility     local0
keepalive 2
deadtime 30
warntime 10
initdead 120
udpport 694
bcast   eth1
auto_failback off
node    master
node    slave
# vi /etc/ha.d/haresources
master 172.20.67.23 mon
# vi /etc/ha.d/authkeys
auth 1
1 crc
# chmod 600 /etc/ha.d/authkeys
# chkconfig heartbeat off

设置服务自动启动(主从相同)

# vi /etc/rc.local
service mysqld start
service heartbeat start
阅读(1509) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

chinaunix网友2010-10-28 18:05:02

很好的, 收藏了 推荐一个博客,提供很多免费软件编程电子书下载: http://free-ebooks.appspot.com