2.安装xtrabackup
rpm -Uhv http://www.percona.com/downloads/percona-release/percona-release-0.0-1.x86_64.rpm
yum install xtrabackup -y
备份(innodb不锁表,myisam会锁表)
#innobackupex --user=root --password=123456 --defaults-file=/usr/local/my.cnf /tmp/data/
把数据传到从服务器
scp -r /data/backup/2012-04-19_10-46-32/ root@newslave:/data/
/etc/init.d/mysql
stop 停止从服务器
cd /data mv mysql mysql_old
这里说明,如果有innodb的数据库在不同的目录里面,这里需要mv时候对应上
/etc/init.d/mysql start
stop
slave;
change
master to
master_host='192.168.2.3',master_user='copy',master_password='123456',master_log_file='mysql-bin.000006',master_log_pos='473';
start
slave;
show slave
status\G;
#注意:上面的mysql-bin.000006和master_log_pos是从xtrabackup_binlog_info 文件中读取的,而不是复制完后从主上面使用show master status看到的。这个灰常重要
使用nagios监控主从
#!/bin/sh
declare -a slave_is
slave_is=($(/usr/local/mysql/bin/mysql -unagios -pnagios -h127.0.0.1 -e "show slave status\G"|grep Running |awk '{print $2}'))
if [ "${slave_is[0]}" = "Yes" -a "${slave_is[1]}" = "Yes" ]
then
echo "OK -slave is running"
exit 0
else
echo "Critical -slave is error"
exit 2
fi