|
本帖最后由 89788 于 2016-11-2 09:07 编辑
实验环境 :俩台mysql master:192.168.1.10 slave:192.168.1.20
建立时间同步环境,在主节点上搭建时间服务器
安装 yum -y install ntp
配置ntp vim /etc/ntp.conf #添加如下俩行
server 127.127.1.0
fudge 127.127.1.0 stratum 8
重启服务 service ntpd restart
在节点服务器上同步时间
yum -y install ntpdate
/usr/sbin/ntpdate 192.168.1.10
在每台服务器上关闭iptables或者指定端口进行开放
service iptables stop
chkconfig iptables off
一、修改master,slave服务器
master服务器配置:
vi /usr/local/mysql/etc/my.cnf
[mysqld]
server-id=202 #设置服务器唯一的id,默认是1,我们设置ip最后一段,slave设置203
log-bin=mysql-bin # 启用二进制日志
#binlog-ignore-db = mysql,information_schema #忽略写入binlog的库
slave服务器配置:
vi /usr/local/mysql/etc/my.cnf
[mysqld]
server-id=203
replicate-do-db = abc #只同步abc库
slave-skip-errors = all #忽略因复制出现的所有错误
二,重启主从数据库。
三,登陆mysql程序。给从服务器以授权
mysql -uroot -p pwd123
grant replication slave on *.* to 'myslave'@192.168.1.从服务器ip’ identified by '123456';
三、查看主数据库状态
mysql> show master status;
+------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000002 | 263 | | |
+------------------+----------+--------------+------------------+
四、配置从数据库
mysql> change master to
-> master_host='192.168.1.10',
-> master_user='mslave',
-> master_password='123456',
-> master_log_file='mysql-bin.000002',
-> master_log_pos=263;
#Log和pos是master上随机获取的。这段也可以写到my.cnf里面。
五、启动slave同步进程并查看状态
1
mysql> start slave;
io线程必须为yes
六,测试主从复制。
在slave启动报错:
“Last_IO_Error: Got fatal error 1236 from master when reading data from binary log: ‘Could not find first log file name in binary log index file’”
解决:报错的原因主要是slave设置master的二进制文件名或pos值不对应!
先flush logs;清空日志,在查看下主数据库的状态 show master status;看下日志文件名字和position值;
再在slave中,执行:CHANGE MASTER TO MASTER_LOG_FILE=‘二进制日志名’,MASTER_LOG_POS=值;
最后启动同步进程:start slave;
|
|