Mysql主从配置,实现数据读写分离(amoeba+mysql) .

一.配置Master主服务器

1.创建新用户,并授权给slave数据库,192.168.0.%表示从数据库IP地址,'mysql'表示密码

mysql>create user repl; //创建新用户
mysql> GRANT REPLICATION SLAVE ON . TO 'repl'@'192.168.0.%' IDENTIFIED BY 'mysql';

2.找到MySQL安装文件夹修改my.Ini文件,在[mysqld]下面增加下面几行代码

server-id=1 //给数据库服务的唯一标识

log-bin=master-bin

log-bin-index=master-bin.index

3.查看日志

mysql> SHOW MASTER STATUS;

+-------------------+----------+--------------+------------------+

| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |

扫描二维码关注公众号,回复: 6783321 查看本文章

+-------------------+----------+--------------+------------------+

| master-bin.000001 | 1285 | | |

+-------------------+----------+--------------+------------------+
二.配置Slave从服务器

1.找到MySQL安装文件夹修改my.ini文件,在[mysqld]下面增加下面几行代码

server-id=2

relay-log-index=slave-relay-bin.index

relay-log=slave-relay-bin

2.连接Master主服务器,执行mysql命令

change master to master_host='192.168.0.104', //Master 服务器Ip

master_port=3306,

master_user='repl',

master_password='mysql',
master_log_file='master-bin.000001',//Master服务器产生的日志(SHOW MASTER STATUS;中的File字段)

master_log_pos=0;//Master服务器产生的日志(SHOW MASTER STATUS;中的Position字段)

3.启动Slave,执行mysql命令

start slave;
三.Amoeba for mysql配置(实现读写分离)

1.amoeba/conf/dbServers.xml
此文件定义由Amoeba代理的数据库如何连接,
比如最基础的:主机IP、端口、Amoeba使用的用户名和密码等等。

2.amoeba/conf/amoeba.xml
此文件定义了Amoeba代理的相关配置

写:<property name="writePool">Master</property>

读:<property name="readPool">virtualSlave</property>

3.amoeba启动命令:amoeba start (amoeba/bin)

猜你喜欢

转载自blog.51cto.com/14439341/2418546