LVS+Apache+PHP+MySQL读写分离

LVS+Apache+PHP+MySQL读写分离

route:
  ifconfig eth0 192.168.18.1
  ifconfig eth1 192.168.20.1
  echo 1 > /proc/sys/net/ipv4/ip_forward
 
分发器:
  ifconfig eth0 192.168.18.254
  ifconfig eth0:0 192.168.18.250/32 broadcast 192.168.18.250 up
  route add -host 192.168.18.250 dev eth0:0
  ipvsadm -A -t 192.168.18.250:3306 -s rr
  ipvsadm -a -t 192.168.18.250:3306 -r 192.168.18.100 -g
  ipvsadm -a -t 192.168.18.250:3306 -r 192.168.18.200 -g
  ipvsadm -a -t 192.168.18.250:3306 -r 192.168.18.220 -g
 
 real server 1:
  ifconfig lo:0 192.168.18.250/32 broadcast 192.168.18.250 up
  route add -host 192.168.18.250 dev lo:0
  route add default gw 192.168.18.1
  echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore
 echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce
 /etc/init.d/httpd restart
 
real server 2:
  ifconfig lo:0 192.168.18.250/32 broadcast 192.168.18.250 up
  route add -host 192.168.18.250 dev lo:0
  route add default gw 192.168.18.1
  echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore
 echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce
 /etc/init.d/httpd restart
 
real server 3:
  ifconfig lo:0 192.168.18.250/32 broadcast 192.168.18.250 up
  route add -host 192.168.18.250 dev lo:0
  route add default gw 192.168.18.1
  echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore
 echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce
 /etc/init.d/httpd restart
 
Apache:
  解压、安装mysql-w-r.tar.gz
  修改指向数据库IP
 
Mysql-A
  vim /etc/my.cnf
  [mysqld]
  server_id = 1
  log-bin=binlog
  log-bin-index=binlog.index
  service mysqld restart
  mysql> grant replication slave ON *.* TO 'ck'@'%' identified by '123';
 flush privileges;
  mysqldump -A -x > /tmp/full.sql
  scp /tmp/full.sql root@192.168.18.200:/tmp/
  scp /tmp/full.sql root@192.168.18.220:/tmp/
  flush tables with read lock;
  show master status;
 +---------------+----------+--------------+------------------+
 | File          | Position | Binlog_Do_DB | Binlog_Ignore_DB |
 +---------------+----------+--------------+------------------+
 | binlog.000001 |      568 |              |                  |
 unlock tables;
 
Mysql-B1:
  vim /etc/my.cnf
  [mysqld]
  server_id = 2
  relay_log = /var/lib/mysql/mysql-relay-bin
  relay_log_index=/var/lib/mysql/mysql-relay-bin.index
  cd /var/lib/mysql
  rm -fr *
  service mysqld restart
  mysql < /tmp/full.sql
  mysql> change master to master_host='192.168.18.100', master_port=3306, master_user='ck', master_password='123', master_log_file='binlog.000001',master_log_pos=568;
  start slave;
  show slave status \G
  Slave_IO_Running: Yes
      Slave_SQL_Running: Yes
 
 
Mysql-B2:
  vim /etc/my.cnf
  [mysqld]
  server_id = 3
  relay_log = /var/lib/mysql/mysql-relay-bin
  relay_log_index=/var/lib/mysql/mysql-relay-bin.index
  cd /var/lib/mysql
  rm -fr *
  service mysqld restart
  mysql < /tmp/full.sql
  mysql> change master to master_host='192.168.18.100', master_port=3306, master_user='ck', master_password='123', master_log_file='binlog.000001',master_log_pos=568;
  start slave;
  show slave status \G
  Slave_IO_Running: Yes
      Slave_SQL_Running: Yes
 
客户端测试
测试未知数。。。。。。

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/60a0b0cc80d04bbd1cab208221320f3a.html