配置环境
配置环境
IP 192.168.1.2 client客户端
192.168.1.1/2.1 路由器(两块网卡)
192.168.2.2 (Vip:192.168.2.250)分发1 需要:yum install ipvsadm -y
192.168.2.3 (Vip:192.168.2.250)apache服务器 需要:yum install httpd -y 解压 mysql-w-r.tar。
192.168.2.4 (Vip:192.168.2.250)apache服务器 需要:yum install httpd -y 解压 mysql-w-r.tar。
192.168.2.5 (Vip:192.168.2.251)分发2 需要:yum install ipvsadm -y
192.168.2.6 Mysql 主 需要yum install mysql mysql-server -y
192.168.2.7 Mysql 从 需要yum install mysql mysql-server -y
192.168.2.8 Mysql 从从 需要yum install mysql mysql-server -y
环境配置完成
client客户端设置
设定网关
route add default gw 192.168.1.1
结束。
路由器设置
开启转发
vim /etc/sysctl.conf
ifconfig eth0:0 192.168.2.251 netmask 255.255.255.255 broadcast 192.168.2.251 up
ipvsadm -A -t 192.168.2.251:3306 -s rr
ipvsadm -a -t 192.168.2.251:3306 -r 192.168.2.7 -g
ipvsadm -a -t 192.168.2.251:3306 -r 192.168.2.8 -g
结束
mysql主
进入配置文件
vim /etc/my.cnf
编辑添加
server_id = 1
log-bin=binlog
log-bin-index=binlog.index
添加用户
mysql> GRANT replication slave ON *.* TO 'a'@'%' identified by '123';
mysql> flush privileges;
创建一个可以访问Mysql主的b
grant all on *.* to 'b'@'%' identified by '123';
拷贝主数据
mysqldump -A -x > /tmp/full.sql
传送给从
scp /tmp/full.sql root@192.168.2.7:/tmp
查看Mysql主的状态
生产环境下可以锁定
mysql> flush tables with read lock;(测试环境可以不用锁定哟~)mysql> show master status;(查询命令)
会显示:
+---------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+---------------+----------+--------------+------------------+
| binlog.000001 | 118 | | |mp
至此Mysql主配置结束
Mysql从
ifconfig lo:0 192.168.2.251 netmask 255.255.255.255 broadcast 192.168.2.251 up
route add -host 192.168.2.251 dev lo:0
route add default gw 192.168.2.1
echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore
echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce
如果之前使用过可以进入
cd /var/lib/mysql
输入删除所有
rm -fr *
重启Mysql服务
service mysqld restart
进入配置文件
vim /etc/my.cnf
编辑添加
server_id = 2
relay_log = /var/lib/mysql/mysql-relay-bin
relay_log_index=/var/lib/mysql/mysql-relay-bin.index
添加用户
grant all on *.* to 'c'@'%' identified by '123';
把之前Mysql主传输过来的数据添加到本地
mysql < /tmp/full.sql
还记得这个吧。输入进来让主从同步的关键啊~~~~~
+---------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+---------------+----------+--------------+------------------+
| binlog.000001 | 118 | | |
在slave上执行一下命令(注意:master_host指到master的IP,master_user是master中为slave创建的用户,master_log_file是第九步查询出来的File名,master_log_pos是第九步查询出来的Position值)
mysql> change master to master_host='192.168.2.6, master_port=3306, master_user='a', master_password='123', master_log_file='binlog.000001',master_log_pos=118;
启动Mysql从
mysql> start slave;
查看从的运行状态:show slave status \G;
Ladies and gentlemen 你成功了么?
Slave_IO_Running: Yes (主机之间的连通性)
Slave_SQL_Running: Yes(SQL运行状态,是否同步了。)
mysql从从:
蛋疼!!不解释!!00:02了。。
ifconfig lo:0 192.168.2.251 netmask 255.255.255.255 broadcast 192.168.2.251 up
route add -host 192.168.2.251 dev lo:0
route add default gw 192.168.2.1
echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore
echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce
vim /etc/my.cnf
server_id=3
relay_log=/var/lib/mysql/mysql-relay-bin
relay_log_index=/var/lib/mysql/mysql-relay-bin.index
grant all on *.* to 'c'@'%' identified by '123';
change master to master_host='192.168.2.6',master_port=3306,master_user='a',master_password='123',master_log_file='binlog.000001',master_log_pos=118;
start slave;
测试!!
看老史的!!!!!!