2.备份服务器的设置
2.1建立多个数据库的database目录
假设要做3个备份服务器,目录分别放在 /home/mysql1,/home/mysql2,/home/mysql3
mkdir /home/mysql1 /home/mysql2 /home/mysql3
复制将原初始的mysql数据复制到4个目录中
cp -a /var/www/mysql /home/mysql1
cp -a /var/www/mysql /home/mysql2
cp -a /var/www/mysql /home/mysql3
修改文件的用户权限
chown mysql:mysql -R /home/mysq1 /home/mysql2 /home/mysql3
2.2修改my.cnf
mysql服务器初始安装的3306端口,不要占用,3个mysql服务器的端口分别分配为
3307,3308,3309
/etc/mysql/my.cnf
[mysqld1]
slave-skip-errors=all
#日志里面要带记录主服务器的修改日志,以便可以恢复数据库状态到任意时刻
log-slave-updates
user = mysql
pid-file = /var/run/mysqld/mysqld1.pid
socket = /var/run/mysqld/mysqld1.sock
port = 3307
datadir = /home/mysql1 #数据目录
#服务器的id, 跟对方的主服务器要有区别,在保存修改到binlog时,会记录server-id,
#在导入binlog时,会忽略相同id的修改记录
server-id = 4
log_bin = /mysql/mysql2/mysql-bin.log #binlog 的保存文件名
auto_increment_increment = 3 #跟主服务器一致,
auto_increment_offset = 2 #要跟主服务器的偏移不同,但不能大于上一个设置的值
expire_logs_days = 100 #保留100天修改日志
max_binlog_size = 100M #每个日志文件100M
master-host =192.168.90.1 #主服务器的ip
master-user =bak #主服务器的帐号
master-password =******** #主服务器的密码
master-port =3306
master-connect-retry =300 #连接失败重试间隔秒
replicate-do-db =vpopmail #从主服务器同步过来的库名
replicate-do-db =loongson #从主服务器同步的另一个库
.... #其他的设置,比如内存,优化等等
[mysqld2]
slave-skip-errors=all
log-slave-updates
user = mysql
pid-file = /var/run/mysqld/mysqld2.pid
socket = /var/run/mysqld/mysqld2.sock
port = 3308
datadir = /home/mysql2
server-id = 4
log_bin = /mysql/mysql2/mysql-bin.log
auto_increment_increment = 4
auto_increment_offset = 2
expire_logs_days = 100
max_binlog_size = 100M
master-host =192.168.110.1
master-user =bak
master-password =********
master-port =3306
master-connect-retry =300
replicate-do-db =water
.... //其他的设置
[mysqld3]
slave-skip-errors=all
log-slave-updates
user = mysql
pid-file = /var/run/mysqld/mysqld3.pid
socket = /var/run/mysqld/mysqld3.sock
port = 3309
datadir = /home/mysql2
server-id = 4
log_bin = /mysql/mysql2/mysql-bin.log
auto_increment_increment = 3
auto_increment_offset = 2
expire_logs_days = 100
max_binlog_size = 100M
master-host =10.0.10.1
master-user =bak
master-password =********
master-port =3306
master-connect-retry =300
replicate-do-db =vpopmail
replicate-do-db =loongson
.... //其他的设置
2.3启动数据库,并灌入数据,设置要抓取的服务器的binlog的文件名和位置,并启动复制抓取进程
用phpadmin在各个备份服务器分别建立库名,跟相应的服务器对应
把从服务器备份出来的sql文件灌入
gunzip vpopmail.sql.gz -c |mysql vpopmail
#命令行连接进服务器
mysql -u root -p***** -h 127.0.0.1 -P3307
#设置服务器的binlog当前抓取位置
mysql>change master to master_log_file='mysql-bin.001943';
mysql>change master to master_log_pos=12301207;
mysql>start slave;
mysql>show slave status;
用show slave status命令应该可以看到2个进程都是yes, Slave_IO_Running =yes
Slave_SQL_Running =yes,这样就正常了.
并且master_log_pos在不断的增加.
2.4完成多个服务器的复制设置
参照2.3节完成其他备份服务器的设置