|
|
Mysql Replication
ÀàËÆÓÚ´Óһ̨·þÎñÆ÷¿½±´Êý¾Ý¿âµ½Áíһ̨·þÎñÆ÷ÉÏ£¬µ«ËüÊÇͨ¹ý¶¨ÒåMaster ºÍSlaveµÄ¹ØÏµÈ¥ÊµÊ±µØ±£Ö¤Á½¸öÊý¾Ý¿âµÄÍêȫͬ²½£¬Õâ¸ö¹¦ÄÜÔÚMysqlµÄ3.23°æÖпªÊ¼³öÏÖ¡£
Master/Slaveģʽ±¸·Ý
TestEnv:
Master£ºMysql-4.1.12 on Redhat9.0 IP:192.168. 0.217
Slave£º Mysql-4.1.12 on Redhat9.0 IP:192.168.10.244
1¡¢±àÒ룬°²×°
1. #tar ¨Czxvf Mysql-4.1.12.tar.gz
2. #cd Mysql-4.1.12
3. .#/configure ¨Cprefix=/var/eyou/mysql
4. #make
5. #make install
6. #chown ¨CR root /var/eyou/mysql
7. # chown ¨CR mysql /var/eyou/mysql/var
8. #chgrp ¨CR mysql /var/eyou/mysql
9. #scripts/mysql_install_db
10. #cp support-files/my-medium.cnf /etc/my.cnf
Mysql Replication
ÀàËÆÓÚ´Óһ̨·þÎñÆ÷¿½±´Êý¾Ý¿âµ½Áíһ̨·þÎñÆ÷ÉÏ£¬µ«ËüÊÇͨ¹ý¶¨ÒåMaster ºÍSlaveµÄ¹ØÏµÈ¥ÊµÊ±µØ±£Ö¤Á½¸öÊý¾Ý¿âµÄÍêȫͬ²½£¬Õâ¸ö¹¦ÄÜÔÚMysqlµÄ3.23°æÖпªÊ¼³öÏÖ¡£
Master/Slaveģʽ±¸·Ý
TestEnv:
Master£ºMysql-4.1.12 on Redhat9.0 IP:192.168. 0.217
Slave£º Mysql-4.1.12 on Redhat9.0 IP:192.168.10.244
1¡¢±àÒ룬°²×°
1. #tar ¨Czxvf Mysql-4.1.12.tar.gz
2. #cd Mysql-4.1.12
3. .#/configure ¨Cprefix=/var/eyou/mysql
4. #make
5. #make install
6. #chown ¨CR root /var/eyou/mysql
7. # chown ¨CR mysql /var/eyou/mysql/var
8. #chgrp ¨CR mysql /var/eyou/mysql
9. #scripts/mysql_install_db
10. #cp support-files/my-medium.cnf /etc/my.cnf
2¡¢Master »úÆ÷ÉèÖÃȨÏÞ£¬¸³ÓèSlave»úÆ÷FILE¼°Replication SlaveȨÀû£¬²¢´ò°üҪͬ²½µÄÊý¾Ý¿â½á¹¹¡£
Master# pwd
/var/eyou/mysql/bin
Master#./mysql ¨Cu root ¨Cp
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2 to server version: 4.1.12
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> GRANT FILE ON *.* TO rep@192.168.0.244 IDENTIFIED BY ¡®eyou¡¯;
mysql> GRANT REPLICATION SLAVE ON *.* TO rep@192.168.0.244 IDENTIFIED BY ¡®eyou¡¯;
¸³Óè192.168.10.244Ò²¾ÍÊÇSlave »úÆ÷ÓÐFileȨÏÞ, Õâ¸ö4.1.12°æ¶ÔreplicationµÄȨÏÞºÃÏñ×öÁ˵÷Õû£¬Ö»¸³ÓèSlave»úÆ÷ÓÐFileȨÏÞ»¹²»ÐУ¬»¹Òª¸øËüREPLICATION SLAVEµÄȨÏ޲ſÉÒÔ¡£
È»ºó´ò°üÒª¸´ÖƵÄÊý¾Ý¿â
Master# cd var
Master# tar czvf reptest.tar.gz reptest
ÕâÑù£¬ÎÒÃǵõ½Ò»¸öreptestÊý¾Ý¿âµÄ´ò°üÎļþreptest.tar.gz
2ÉèÖÃÖ÷·þÎñÆ÷MasterµÄmy.cnf£¬Æô¶¯Mysql·þÎñ
Master# vi /etc/my.cnf
ÔÚ[mysqld]Ìí¼Ó»òÐÞ¸ÄÒÔϵÄ
[mysqld]
log-bin #´ò¿ªlogbinÑ¡ÏîÒÔÄÜдµ½slaveµÄ I/OÏß³Ì;
server-id=1 #±íʾÊDZ¾»úµÄÐòºÅΪ1,Ò»°ãÀ´½²¾ÍÊÇmasterµÄÒâ˼.
sql-bin-update-same
binlog-do-db= reptest #±íʾͬ²½reptestÊý¾Ý¿â;
È»ºó°ÑMasterÖ÷·þÎñÆ÷µÄMysqlÖØÆô¡£
Master# /var/eyou/mysql/bin/mysqladmin ¨Cu root ¨Cp shutdown
Master# /var/eyou/mysql/bin/safe_mysqld --user=mysql &
3¡¢½¨Á¢SlaveÊý¾Ý¿â
¸Õ²ÅÔÚMasterÖдò°üÁËreptest.tar.gz£¬ËüµÄ×÷ÓþÍÊÇÒªÔÚSlave»Ö¸´³ÉÒ»ÑùµÄÊý¾Ý¿â¡£ÏȰÑMaster µÄreptest.tar.gzÎļþ´«µ½Slave»úÆ÷ÖÐÈ¥¡£È»ºó
Slave# tar zxvf reptest.tar.gz -C /var/eyou/mysql/var/
4¡¢ÐÞ¸ÄSlave·þÎñÆ÷µÄmy.cnf
Slave# vi /etc/my.cnf
ÔÚ[mysqld]Ìí¼Ó»òÐÞ¸ÄÒÔϵÄ
master-host=192.168.10.217
master-user=rep
master-password=eyou
master-port=3306
server-id=2
master-connect-retry=60
replicate-do-db=reptest ¡¡¡¡¡¡[Òª¸üеÄÊý¾Ý¿â]
log-slave-updates
5¡¢É¾³ýSlave¶ËÊý¾Ý¿âĿ¼ÖеÄmaster.info
Slave# rm /var/eyou/mysql/var/master.info
6¡¢ÖØÆô¶¯SlaveµÄslave start¡£
Slave# /var/eyou/mysql/bin/mysqladmin ¨Cu root ¨Cp shutdown
Slave# /var/eyou/mysql/bin/safe_mysqld --user=mysql &
7¡¢²âÊÔ
Ïȼì²âÁ½¸öMysqlÊý¾Ý¿âÖеÄreptestÊÇ·ñÕý³£¡£
Õý³£Çé¿öÓ¦¸ÃÊÇMasterºÍSlave ÖеÄMysql ¶¼ÓÐÏàͬµÄreptest Êý¾Ý¿â£¬²¢ÇÒÀïÃæµÄÊý¾Ý¶¼Ò»Ñù¡£
È»ºó²âÊÔreplication ¹¦ÄÜÊÇ·ñÆðÓá£
ÔÚMasterÖеÄreptestÊý¾Ý¿âÌí¼ÓÒ»±ÊÊý¾Ý£º
Master# /var/eyou/mysql/bin/mysql ¨Cu root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 12 to server version: 4.1.12
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> use reptest;
Database changed
mysql> INSERT INTO rep_table VALUES ('test1', '4321', 'T',24);
Query OK, 1 row affected (0.00 sec)
mysql>
È»ºó²é¿´Slave»úÆ÷µÄreptestÊý¾Ý¿â£º
Slave#/var/eyou/mysql/bin/mysql ¨Cu root ¨Cp
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 12 to server version: 4.1.12
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> use reptest;
Database changed
mysql>select * from reptable;;
+------+------+------+------+
| id | name | sex | age |
+------+------+------+------+
| test1| 4321 | T | 24 |
+------+------+------+------+
1 row in set (0.00 sec)
PS :
1£¬Slave»úÆ÷µÄȨÏÞÎÊÌ⣬²»µ«Òª¸øslave»úÆ÷FileȨÏÞ£¬»¹Òª¸øËüREPLICATION SLAVEµÄȨÏÞ¡£
2£®ÔÚÐÞ¸ÄÍêSlave»úÆ÷/etc/my.cnfÖ®ºó£¬slave»úÆ÷µÄmysql·þÎñÆô¶¯Ö®Ç°£¬¼ÇµÃҪɾ³ýµômaster.info
3£¬ÔÚshow master status »ò×Åshow slave status ²»Õý³£Ê±£¬¿´¿´.errÊÇÔõÑù˵µÄ¡£
4£¬SlaveÉÏMysqlµÄReplication¹¤×÷ÓÐÁ½¸öÏß³Ì, I/O threadºÍSQL thread ¡£I/O µÄ×÷ÓÃÊÇ´Ómaster 3306¶Ë¿ÚÉϰÑËüµÄbinlogÈ¡¹ýÀ´(masterÔÚ±»ÐÞ¸ÄÁËÈκÎÄÚÈÝÖ®ºó,¾Í»á°ÑÐÞ¸ÄÁËʲôдµ½×Ô¼ºµÄbinlogµÈ´ýslave¸üÐÂ),È»ºóдµ½±¾µØµÄrelay-log,¶øSQL threadÔòÊÇÈ¥¶Á±¾µØµÄrelay-log,ÔÙ°ÑËüת»»³É±¾MysqlËùÄÜÀí½âµÄÓï¾ä£¬ÓÚÊÇͬ²½¾ÍÕâÑùÒ»²½Ò»²½µÄÍê³É.¾ö¶¨I/O threadµÄÊÇ/var/lib/mysql/master.info,¶ø¾ö¶¨SQL threadµÄÊÇ/var/lib/mysql/relay-log.info.
Ë«Ïò¸´ÖÆÄ£Ê½
1£º
Slave »úÆ÷ÉèÖÃȨÏÞ£¬¸³ÓèMaster»úÆ÷FILE¼°Replication SlaveȨÀû.
Master#./var/eyou/mysql ¨Cu root ¨Cp
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2 to server version: 4.1.12
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> GRANT FILE ON *.* TO rep@192.168.0.217 IDENTIFIED BY ¡®eyou¡¯;
mysql> GRANT REPLICATION SLAVE ON *.* TO rep@192.168.0.217 IDENTIFIED BY ¡®eyou¡¯;
|
|
| |
|
¹Ø¼ü×Ö:
| ¹Ø¼ü×Ö: Mysql Replication,²©Ö¾,soft,glen'blog,blog,weblog,blog,qzhiwu@msn.com |
|
ÒýÓÃ [0]
| ±¾ÎÄÎÞTrackback |
 |
|
Ìí¼ÓÆÀÂÛ
|
|