1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
为mysql的安装提供前提环境和初始化安装mysql
创建数据库目录
# mkdir /mydata/data –pv
创建mysq用户
# useradd -r mysql
修改权限
# chown -R mysql.mysql /mydata/data/
使用mysql-
5.5
通用二进制包安装
解压mysql软件包
# tar xf mysql-
5.5
.
28
-linux2.
6
-i686.tar.gz-C /usr/local/
创建连接,为了方便查看mysql的版本等信息
# cd /usr/local/
#ln –sv mysql-
5.5
.
28
-linux2.
6
-i686.tar.gzmysql
修改属主属组
# cd mysql
# chown -R root.mysql ./*
初始化数据库
# scripts/mysql_install_db –user=mysql --datadir=/mydata/data/
提供配置文件
# cp support-files/my-large.cnf /etc/my.cnf
提供服务脚本
# cp support-files/mysql.server/etc/rc.d/init.d/mysqld
添加至服务列表
# chkconfig --add mysqld
# chkconfig --list mysqld
# chkconfig mysqld on
编辑配置文件,提供数据目录
# vim /etc/my.cnf
# The MySQL server 修改mysqld服务器端的内容
log-bin=master-bin 主服务器二进制日志文件前缀名
log-bin-index=master-bin.index 索引文件
innodb_file_per_table=
1
开启innodb的一表一个文件的设置
server-id =
1
必须是唯一的
datadir =/mydata/data 数据目录路径
启动mysql服务
# servicemysqld start
为了便于下面的测试,设置环境变量
# vim/etc/profile.d/mysql.sh
export PATH=$PATH:/usr/local/mysql/bin
执行环境变量脚本,使其立即生效
# . /etc/profile.d/mysql.sh
|
1
2
3
4
|
建立用户账户
mysql> grant replication slave on *.* to
'chris'
@
'172.16.%.%'
identified by
'work'
;
刷新数据使其生效
mysql> flush privileges;
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
创建mysql数据库目录
# mkdir /mydata/data –pv
创建mysql用户
# useradd -r mysql
修改数据目录权限
# chown -R mysql.mysql /mydata/data/
使用mysql-
5.5
通用二进制包安装mysql
解压mysql软件包
# tar xf mysql-
5.5
.
28
-linux2.
6
-i686.tar.gz-C /usr/local/
创建连接,便于查看mysql的版本等信息
# cd /usr/local/
# ln –sv mysql-
5.5
.
28
-linux2.
6
-i686.tar.gzmysql
修改mysql属主属组
# cd mysql
# chown -R root.mysql ./*
初始化mysql数据库
# scripts/mysql_install_db –user=mysql--datadir=/mydata/data/
提供mysql配置文件
# cp support-files/my-large.cnf /etc/my.cnf
提供服务脚本
# cp support-files/mysql.server /etc/init.d/mysqld
添加至服务列表
# chkconfig --add mysqld
编辑配置文件
# vim /etc/my.cnf
# The MySQL server
#log-bin=mysql-bin 禁用二进制日志,从服务器不需要二进制日志文件
datadir = /mydata/data mysql的数据目录
relay-log = relay-log 设置中继日志
relay-log-index = relay-log.index 中继日志索引
innodb_file_per_table =
1
server-id =
2
id不要和主服务器的一样
设置环境变量
# vim/etc/profile.d/mysql.sh
export PATH=$PATH:/usr/local/mysql/bin
执行此脚本(导出环境变量)
# . /etc/profile.d/mysql.sh
启动服务
# service mysqld start
|
1
2
3
4
5
|
mysql> show master status; #在Master上执行查看二进制文件
在从服务器上开启复制功能
change master to master_host=
'172.16.7.1'
,master_user=
'chris'
,master_password=
'work'
,master_log_file=
'master-bin.000001'
,master_log_pos=
407
;
开启复制功能
mysql>start slave;
|
1
2
3
|
安装插件:mysql> INSTALL PLUGIN rpl_semi_sync_master SONAME
'semisync_master.so'
;
启动模块:mysql> SET GLOBAL rpl_semi_sync_master_enabled =
1
;
设置超时时间:mysql> SET GLOBAL rpl_semi_sync_master_timeout =
1000
;
|
1
2
3
4
|
slave:
安装插件:msyql> INSTALL PLUGIN rpl_semi_sync_slave SONAME
'semisync_slave.so'
;
启动模块:mysql> SET GLOBAL rpl_semi_sync_slave_enabled =
1
;
重启进程使其模块生效:mysql> STOP SLAVE IO_THREAD; START SLAVE IO_THREAD;
|
1
2
3
4
5
6
7
8
|
在Master和Slave的my.cnf中编辑:
# On Master
[mysqld]
rpl_semi_sync_master_enabled=
1
rpl_semi_sync_master_timeout=
1000
#此单位是毫秒
# On Slave
[mysqld]
rpl_semi_sync_slave_enabled=
1
|
1
2
3
4
5
|
master:
mysql> CREATE DATABASE asyncdb;
master> SHOW STATUS LIKE
'Rpl_semi_sync_master_yes_tx'
;
slave> SHOW DATABASES;
其测试过程如下
|
1
2
3
4
5
6
7
8
|
# 主服务器上
[mysqld]
server-id =
1
log-bin = mysql-bin
relay-log = relay-mysql
relay-log-index = relay-mysql.index
auto-increment-increment =
2
#每次跳两个数。
auto-increment-offset =
1
#从
1
开始。
|
1
2
3
4
5
6
7
|
[mysqld]
server-id =
2
log-bin = mysql-bin
relay-log = relay-mysql
relay-log-index = relay-mysql.index
auto-increment-increment =
2
auto-increment-offset =
2
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
master:查看日志文件信息
mysql> show master status;
+------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.
000001
|
107
| | |
+------------------+----------+--------------+------------------+
Slave:查看服务器日志文件信息
mysql> show master status;
+------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.
000001
|
107
| | |
+------------------+----------+--------------+------------------+
1
row
in
set
(
0.00
sec)
|
1
2
3
|
master:
mysql> GRANT REPLICATION SLAVE ON *.* TO
'chrislee'
@
'172.16.%.%'
IDENTIFIED BY
'work'
;
mysql> flush privileges;
|
1
2
3
|
slave:
mysql> GRANT REPLICATION SLAVE ON *.* TO
'chrisli'
@
'172.16.%.%'
IDENTIFIED BY
'work'
;
mysql> flush privileges
|
1
2
|
server1
mysql> CHANGE MASTER TO MASTER_HOST=
'172.16.7.2'
,MASTER_USER=
'chrisli'
,MASTER_PASSWORD=
'work'
,MASTER_LOG_FILE=
'mysql-bin.000001'
,MASTER_LOG_POS=
344
;
|
1
2
|
server2:
mysql> CHANGE MASTER TO MASTER_HOST=
'172.16.7.1'
,MASTER_USER=
'chrislee'
,MASTER_PASSWORD=
'work'
,MASTER_LOG_FILE=
'mysql-bin.000001'
,MASTER_LOG_POS=
345
;
|