Keepalive+LVS+MySQL的高可用的双机解决方案(2)

第三:MySQL在备用节点上的设置

[root@localhost ~]# /etc/init.d/mysqld start

[root@localhost ~]# mysql

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 4

Server version: 5.0.77-log Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql>  grant replication slave,file on *.* to 'repl2'@'192.168.1.196' identified by '123456'; 

Query OK, 0 rows affected (0.02 sec)

mysql> \q

Bye

[root@localhost ~]# /etc/init.d/mysqld stop

[root@localhost ~]# vi /etc/my.cnf

[mysqld]

datadir=/var/lib/mysql

socket=/var/lib/mysql/mysql.sock

user=mysql

log-bin=mysql-bin

server-id=2

binlog-do-db=test

binlog-ignore-db=mysql

replicate-do-db=test

replicate-ignore-db=mysql

log-slave-updates

slave-skip-errors=all

sync_binlog=1

auto_increment_increment=2

auto_increment_offset=2

[root@localhost ~]# /etc/init.d/mysqld start

[root@localhost ~]# mysql

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 4

Server version: 5.0.77-log Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql>  flush tables with read lock\G

Query OK, 0 rows affected (0.00 sec)

mysql>  show master status\G

*************************** 1. row ***************************

File: mysql-bin.000001

Position: 98

Binlog_Do_DB: test

Binlog_Ignore_DB: mysql

1 row in set (0.00 sec)

mysql> change master to  master_host='192.168.1.196', master_user='repl1', master_password='123456',  master_log_file='mysql-bin.000001', master_log_pos=98;

mysql> slave start;

Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> show processlist\G      //可以看到以下三句话表示成功

State: Waiting for master to send event

State: Has read all relay log; waiting for the slave I/O thread to update it

State: Has sent all binlog to slave; waiting for binlog to be updated

mysql> unlock tables;

Query OK, 0 rows affected (0.15 sec)

mysql> show slave status\G;    //这个步骤关键是看到以下两项开启

Slave_IO_Running: Yes

Slave_SQL_Running: Yes

mysql> grant all privileges on *.* to 'root'@'%' identified by '123456';

Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;

Query OK, 0 rows affected (0.00 sec)

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

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