Chinaunix首页 | 论坛 | 博客
  • 博客访问: 586011
  • 博文数量: 70
  • 博客积分: 3219
  • 博客等级: 中校
  • 技术积分: 1197
  • 用 户 组: 普通用户
  • 注册时间: 2006-02-13 12:20
个人简介

谢谢您的对我的博客的关心,同时希望这个站点真的能够对您有所帮助。 如果可以请告诉我你的联系方式(可能的话告诉我两个或更多,我不希望失去任何一个关注本主页人士的联系,不论你是我的老友,或是一位新朋友,对于我来说您十分重要)

文章分类
文章存档

2021年(1)

2020年(13)

2018年(1)

2013年(12)

2012年(2)

2009年(2)

2008年(6)

2007年(20)

2006年(13)

分类: 系统运维

2013-03-13 22:06:23

本文使用RHEL5.8的光盘制作yum命令的安装源来安装所依赖的软件包,关于如何使用光盘制作yum源,请参考:
http://blog.chinaunix.net/uid-20346344-id-3264166.html

服务器搭建环境:
主(server1):eth0:192.168.10.10 CentOS 5.8 master
从(server2):eth0:192.168.10.20 CentOS 5.8 slave

一、2台服务器上都安装上mysql数据库

mount /dev/hdc /mnt/iso/
yum -y install mysql mysql-server
service mysqld start
chkconfig mysqld on
mysqladmin -u root password "mysqladmin"

二、配置master服务器(192.168.10.10)

mysql -u root -pmysqladmin

create database testdatabase;
grant all on *.* to 'testuser'@'192.168.10.20' identified by 'password';
quit

sed -e '/^$/d' /etc/my.cnf > /etc/my.cnf.1
sed -e '/\[mysqld\]$/G' /etc/my.cnf.1 | sed -e 's/^$/binlog-do-db=testdatabase/' > /etc/my.cnf.2
sed -e '/\[mysqld\]$/G' /etc/my.cnf.2 | sed -e 's/^$/log-bin=\/var\/log\/mysql\//' > /etc/my.cnf.3
sed -e '/\[mysqld\]$/G' /etc/my.cnf.3 | sed -e 's/^$/server-id=1/' > /etc/my.cnf.4
sed -e '/^#/d' /etc/my.cnf.4
上面5行只是用sed命令编辑配置文件,看不懂的话,直接看下面截图

cat /etc/my.cnf.4 >  /etc/my.cnf
mkdir /var/log/mysql/
chown mysql:mysql /var/log/mysql/
service mysqld restart

三、配置slave服务器(192.168.10.20)

mysql -u root -pmysqladmin

create database testdatabase;
grant all on *.* to 'testuser'@'192.168.10.10' identified by 'password';
quit

sed -e '/^$/d' /etc/my.cnf > /etc/my.cnf.1
sed -e '/\[mysqld\]$/G' /etc/my.cnf.1 | sed -e 's/^$/replicate-do-db=testdatabase/' > /etc/my.cnf.2
sed -e '/\[mysqld\]$/G' /etc/my.cnf.2 | sed -e 's/^$/master-connect-retry=60/' > /etc/my.cnf.3
sed -e '/\[mysqld\]$/G' /etc/my.cnf.3 | sed -e 's/^$/master-port=3306/' > /etc/my.cnf.4
sed -e '/\[mysqld\]$/G' /etc/my.cnf.4 | sed -e 's/^$/master-password=password/' > /etc/my.cnf.5
sed -e '/\[mysqld\]$/G' /etc/my.cnf.5 | sed -e 's/^$/master-user=testuser/' > /etc/my.cnf.6
sed -e '/\[mysqld\]$/G' /etc/my.cnf.6 | sed -e 's/^$/master-host=192.168.10.10/' > /etc/my.cnf.7
sed -e '/\[mysqld\]$/G' /etc/my.cnf.7 | sed -e 's/^$/server-id=2/' > /etc/my.cnf.8
sed -e '/^#/d' /etc/my.cnf.8
上面9行只是用sed命令编辑配置文件,看不懂的话,直接看下面截图

cat /etc/my.cnf.8 >  /etc/my.cnf
service mysqld restart
配置完成!

四、测试

登录master,在上创建一个表:
mysql -u root -pmysqladmin
use testdatabase;
CREATE TABLE `backup_table` (
  `id` int(11) NOT NULL auto_increment,
  PRIMARY KEY  (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
show tables;
quit

登录slave检查:
mysql -u root -pmysqladmin
show tables;
quit

五、状态和日志

数据复制的日志通常存放在slave的mysql默认日志中/var/log/mysqld.log。

master的同步数据已经在配置文件中指定了,在/var/log/mysql/下面。
阅读(1808) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~