MySQL Master/Slave Server 架设
来源:互联网 发布:vscode ripgrep 编辑:程序博客网 时间:2024/04/30 17:29
环境:两台服务器IP:192.168.30.57/192.168.30.58
1、下载mysql-5.0.86-linux-i686-glibc23.tar.gz 到http://dev.mysql.com/downloads/mysql/5.0.html#linux下载
2、解压 tar -zxvf mysql-5.0.86-linux-i686-glibc23.tar.gz
3、创建链接 ln -s mysql-5.0.86-linux-i686-glibc23 mysql
4、进入mysql目录下 cd mysql
5:新建 mysql 用户组
groupadd mysql
6:新建 mysql用户并属于mysql用户组
useradd -g mysql mysql
7:执行安装脚本:
scripts/mysql_install_db --user=mysql
8:改变属组 (注意小数点)
chown -R root . (注意小数点)
9:改变数据属组
chown -R mysql data
10:输入命令 chgrp -R mysql . (注意小数点)
11、拷贝配置文件 cp supports-files/my-lagre.cnf /etc/my.cnf
12、启动mysql bin/mysqld_safe -user=root &
13、登录 bin/mysql -uroot -p
一、Master Server 方面
A.设定 Server-id
首先要设定 server-id。基本上没有什么特别的限制,只要 Master 和 Slave 的 server-id 不一样即可,但其值必需为1 至 2^32-1 之间。
[mysqld]
server-id=1
B.开启 Binary Log
修改 MySQL Server 的系统设定档,在 [mysqld] 下方加上 log-bin=mysql-bin,例如:
引用:
[mysqld]
log-bin=mysql-bin
MySQL 的 Binary Log 会将所有对於资料库的修改操作全部记录起来,而 Slave 与 Master之间进行资料同步的方式很简单,就是 Slave 会把 Master Server 的 Binary Log 拿过来执行,也就是说 SlaveServer 会 "重做" 在 Master Server 上发生的各种修改操作。因此 Master Server 勿必要开启 BinaryLog 功能,否则 Master/Slave 架构无法运作。
C.设定 Replication Slave 权限
我们必须要在 Master Server 上做设定,让 Slave 具有可以从 Master Server 上 Copy 资料的权限(正式的说法为 Replication Slave Priviledges),所需使用的指令如下:
引用:
GRANT REPLICATION SLAVE ON *.* TO 'slave1'@'192.168.30.58' IDENTIFIED BY '123456';
意思为:
允许 192.168.30.58 这个 IP 使用 slave1 帐号,来进行资料同步(Replication)。
slave1 这个帐号的密码为 123456。
此时您可以从 Slave Server(192.168.30.58) 使用 mysql client program 进行验证,看是否有正确的开启权限,例如使用以下的指令:(注意,是在 Slave Server 上进行验证)
引用:
mysql -h 192.168.30.57 -u slave1 -p
接著系统会要求您输入密码,若可以顺利登入即表示设定成功。
二、Slave Server 方面
A.设定 Server-id
在 Slave 我们将其设定为 2:
引用:
[mysqld]
server-id=2
B.将 Master_Host 设定为 Master Server
我们必须要明确的告诉 Slave Server 哪一台 Server 才是 Master Server,使用以下的指令即可:
master-host=192.168.30.57 //master地址
master-port=3306 //mysql端口
master-user=salve1 //访问master 的用户名
master-password=123456 //密码
C.启动与检查 Slave Server 的状态
设定好后,Master/Slave 机制仍未启动,您必须要使用以下的指令来开启或关闭 Master/Slave 机制:
START slave; (启动 Master/Slave 机制)
STOP slave; (停止 Master/Slave 机制)
当你执行 'START slave;' 后,可使用以下的指令来检查执行状态:
引用:
SHOW SLAVE STATUS/G
mysql> show slave status/G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.18.175
Master_User: slave1
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000010
Read_Master_Log_Pos: 98
Relay_Log_File: ocgserver-relay-bin.000008
Relay_Log_Pos: 235
Relay_Master_Log_File: mysql-bin.000010
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 98
Relay_Log_Space: 235
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
1 row in set (0.00 sec)
最重要是以下三点:
Slave_IO_Running:
是否要从 Master Server 复製 Binary Log 资料,必须为 Yes。
Slave_SQL_Running:
是否要执行从 Master Server 复製过来的 Binary Log 资料,必须为 Yes。
Seconds_Behind_Master:
Slave 的资料落后了 Master 多少秒,执行一段时间后应该会是零。
Master/Slave 的应用
vbulletin 原本即内建支援多台 MySQL Server 之间的负载平衡,只要你事先建立好 MySQL Master/SlaveServer,并在 Slave Server 开放 Master Server 的权限,接下来只要在 vbb 的设定档中做一些简单的修改即可。
如一切正常,可以在30.57 Master服务器创建一个数据库test,你会发现 30.58 Slave服务器也自动增加了一个数据库 test。
如 " Slave_SQL_Running:No"
解决办法一、
Slave_SQL_Running: No
1.程序可能在slave上进行了写操作
2.也可能是slave机器重起后,事务回滚造成的.
一般是事务回滚造成的:
解决办法:
mysql> slave stop;
mysql> set GLOBAL SQL_SLAVE_SKIP_COUNTER=1;
mysql> slave start;
解决办法二、
首先停掉Slave服务:slave stop
到主服务器上查看主机状态:
记录File和Position对应的值
进入master
mysql> show master status;
+----------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+----------------------+----------+--------------+------------------+
| mysql-bin.000018
| 239 | | |
+----------------------+----------+--------------+------------------+
1 row in set (0.00 sec)
然后到slave服务器上执行手动同步:
mysql> change master to
> master_host='master_ip',
> master_user='user',
> master_password='pwd',
> master_port=3306,
> master_log_file='mysql-bin.000018',
> master_log_pos=239;
1 row in set (0.00 sec)
mysql> slave start;
1 row in set (0.00 sec)
手动同步需要停止master的写操作!
- MySQL Master/Slave Server 架设
- MySQL Master/Slave Server 架設
- MySQL Master-Slave Replication
- MYSQL-master-slave实践
- mysql模式:master/slave
- mysql master slave 配置
- Mysql Master/Slave备份
- mysql 同步 master-slave
- mysql master slave 搭建
- MYSQL-master-slave实践
- mysql master/slave 模式
- MySQL配置Master-Slave
- mysql master slave project
- MYSQL-master-slave实践
- mysql master/slave
- mysql master slave
- Mysql Master slave复制
- Mysql Master Slave Config
- 职场“十不要”,让你少奋斗30年!
- 破解路由器密码
- Flex翻书效果
- Flex渲染器的用法
- 门票销售计算器
- MySQL Master/Slave Server 架设
- 锁相环PLL原理 && 时钟产生方法
- 第三章 内核对象
- 漫谈如何学习操作系统原理(转载)
- 英汉词典&英英词典
- Hibernate配置問題: could not execute query
- Test
- JAVA连接池,全的哦
- UBUNTU8.04下PDF文件乱码解决方法