ÔõÑùÔÚLinuxÉÏÉèÖø߿ÉÓõÄÊý¾Ý¿â¸´ÖÆ
ÔõÑùÔÚlinuxÉÏÉèÖø߿ÉÓõÄÊý¾Ý¿â¸´ÖÆ
ͻ񻣼
ÔÚÏÖ´úµÄ»¥ÁªÍøÓ¦ÓÃÖУ¬Êý¾Ý¿âµÄ¸ß¿ÉÓÃÐÔÊǺÜÊÇÖ÷ÒªµÄ£¬ÓÈÆäÊǹØÓÚÔÚÏßÉúÒ⡢ʵʱÊý¾ÝÆÊÎöµÈÒªº¦ÓªÒµ³¡¾°À´Ëµ¡£Êý¾Ý¿â¸´ÖÆÊÇʵÏÖÊý¾Ý¿â¸ß¿ÉÓÃÐÔµÄÒ»ÖÖ³£¼û·½·¨¡£±¾ÎĽ«ÏÈÈÝÔõÑùÔÚLinux²Ù×÷ϵͳÉÏÉèÖø߿ÉÓõÄÊý¾Ý¿â¸´ÖÆ£¬ÒÔÌá¸ßϵͳµÄ¿ÉÓÃÐÔºÍÈÝ´íÄÜÁ¦¡£
È·±£Êý¾Ý¿âЧÀÍÆ÷ÉèÖÃ׼ȷ
ÔÚ×îÏÈÉèÖÃÊý¾Ý¿â¸´ÖÆ֮ǰ£¬Ê×ÏÈҪȷ±£Êý¾Ý¿âЧÀÍÆ÷µÄÉèÖÃÊÇ׼ȷµÄ¡£Õâ°üÀ¨ÒÔϼ¸¸ö·½Ã棺
²Ù×÷ϵͳ£ºÑ¡ÔñÎȹÌÇÒ¿É¿¿µÄLinux¿¯Ðаæ×÷ΪÊý¾Ý¿âЧÀÍÆ÷µÄ²Ù×÷ϵͳ£¬ÈçCentOS¡¢UbuntuµÈ¡£
ÄÚ´æºÍ´ÅÅÌ£ºÎªÊý¾Ý¿âЧÀÍÆ÷·ÖÅÉ×ã¹»µÄÄÚ´æºÍ´ÅÅ̿ռ䣬ȷ±£ÏµÍ³¿ÉÒÔ´¦Öóͷ£´ó×ڵIJ¢·¢¶Áд²Ù×÷¡£
Êý¾Ý¿âÈí¼þ£ºÑ¡Ôñ¿É¿¿ÇÒ³ÉÊìµÄÊý¾Ý¿âÈí¼þ£¬ÈçMySQL¡¢PostgreSQLµÈ¡£
ÍøÂçÉèÖãºÉèÖÃÍøÂç²ÎÊý£¬È·±£Êý¾Ý¿âЧÀÍÆ÷Äܹ»Õý³£Í¨Ñ¶¡£
×°ÖúÍÉèÖÃÊý¾Ý¿âÈí¼þ
ÔÚLinux²Ù×÷ϵͳÉÏ×°ÖúÍÉèÖÃÊý¾Ý¿âÈí¼þÊǵÚÒ»²½¡£ÒÔÏÂÊÇ×°ÖúÍÉèÖÃMySQLÊý¾Ý¿âÈí¼þµÄʾÀý´úÂ룺
°ì·¨1: ×°ÖÃMySQLÊý¾Ý¿âÈí¼þ
sudo apt-get update sudo apt-get install mysql-server
µÇ¼ºó¸´ÖÆ
°ì·¨2: ÉèÖÃMySQLÊý¾Ý¿â
sudo vi /etc/mysql/mysql.conf.d/mysqld.cnf
µÇ¼ºó¸´ÖÆ
ÔÚÉèÖÃÎļþÖÐÕÒµ½ÒÔÏÂÐУ¬²¢½«Æä×÷·Ï×¢ÊÍ£º
bind-address = 127.0.0.1
µÇ¼ºó¸´ÖÆ
ÉúÑÄÉèÖÃÎļþ£¬²¢ÖØÐÂÆô¶¯MySQLЧÀÍ£º
sudo systemctl restart mysql.service
µÇ¼ºó¸´ÖÆ
ÉèÖÃÊý¾Ý¿â¸´ÖÆ
½ÓÏÂÀ´£¬ÎÒÃǽ«ÉèÖÃÊý¾Ý¿â¸´ÖÆ£¬ÒÔʵÏָ߿ÉÓÃÐÔµÄÊý¾Ý¿â¼Ü¹¹¡£ÒÔÏÂÊÇÉèÖÃMySQLÊý¾Ý¿â¸´ÖƵÄʾÀý´úÂ룺
°ì·¨1: ½¨É踴ÖÆÓû§
ÔÚÖ÷Êý¾Ý¿âÉϽ¨ÉèÒ»¸ö¿ÉÒÔ±»´ÓÊý¾Ý¿â¸´ÖƵÄÓû§£º
CREATE USER 'replication'@'%' IDENTIFIED BY 'password'; GRANT REPLICATION SLAVE ON *.* TO 'replication'@'%'; FLUSH PRIVILEGES;
µÇ¼ºó¸´ÖÆ
°ì·¨2: ±¸·ÝÖ÷Êý¾Ý¿â
ÔÚÖ÷Êý¾Ý¿âÉÏÖ´Ðб¸·Ý²Ù×÷£º
FLUSH TABLES WITH READ LOCK; SHOW MASTER STATUS;
µÇ¼ºó¸´ÖÆ
¼Í¼ÏÂFileºÍPositionµÄÖµ£¬Õ⽫ÔÚÉèÖôÓÊý¾Ý¿âµÄ¸´ÖÆʱÓõ½¡£
°ì·¨3: ÉèÖôÓÊý¾Ý¿â
ÔÚ´ÓÊý¾Ý¿âÉÏÖ´ÐÐÒÔϲÙ×÷£º
CHANGE MASTER TO MASTER_HOST='Ö÷Êý¾Ý¿âµÄIPµØµã', MASTER_USER='replication', MASTER_PASSWORD='password', MASTER_LOG_FILE='Ö÷Êý¾Ý¿âµÄFileÖµ', MASTER_LOG_POS=Ö÷Êý¾Ý¿âµÄPositionÖµ;
µÇ¼ºó¸´ÖÆ
°ì·¨4: Æô¶¯´ÓÊý¾Ý¿â¸´ÖÆ
ÔÚ´ÓÊý¾Ý¿âÉÏÆô¶¯¸´ÖƲÙ×÷£º
START SLAVE;
µÇ¼ºó¸´ÖÆ
¼à¿ØºÍά»¤Êý¾Ý¿â¸´ÖÆ
ÔÚÉèÖÃÍêÊý¾Ý¿â¸´Öƺó£¬ÎÒÃÇÐèÒª¼à¿ØºÍά»¤¸´ÖƵÄ״̬£¬È·±£Êý¾ÝµÄÒ»ÖÂÐԺͿÉÓÃÐÔ¡£
°ì·¨1: ¼à¿Ø¸´ÖÆ״̬
ÔÚ´ÓÊý¾Ý¿âÉÏÖ´ÐÐÒÔϲÙ×÷£¬¿ÉÒÔÉó²é¸´ÖÆ״̬£º
SHOW SLAVE STATUSG;
µÇ¼ºó¸´ÖÆ
°ì·¨2: ´¦Öóͷ£¸´Öƹýʧ
ÈôÊǸ´ÖÆÀú³ÌÖзºÆð¹ýʧ£¬¿ÉÒÔʵÑéÒÔϲÙ×÷¾ÙÐÐÐÞ¸´£º
¼ì²éÍøÂçÅþÁ¬ÊÇ·ñÕý³££¬È·±£Ö÷´ÓÊý¾Ý¿âÖ®¼ä¿ÉÒÔÏ໥ͨѶ¡£
¼ì²é¸´ÖÆÉèÖÃÊÇ·ñ׼ȷ£¬²¢ÖØÐÂÉèÖø´ÖƲÎÊý¡£
ÈôÊǸ´ÖÆÀú³Ì×èÖ¹£¬¿ÉÒÔʹÓÃÒÔÏÂÏÂÁîÖØÐÂÆô¶¯¸´ÖÆ£º
STOP SLAVE; START SLAVE;
µÇ¼ºó¸´ÖÆ
½áÂÛ£º
Êý¾Ý¿âµÄ¸ß¿ÉÓÃÐÔ¹ØÓÚ»¥ÁªÍøÓ¦ÓÃÀ´ËµºÜÊÇÖ÷Òª¡£Í¨¹ýÉèÖÃÊý¾Ý¿â¸´ÖÆ£¬ÎÒÃÇ¿ÉÒÔÌá¸ßϵͳµÄ¿ÉÓÃÐÔºÍÈÝ´íÄÜÁ¦¡£±¾ÎÄÏÈÈÝÁËÔõÑùÔÚLinux²Ù×÷ϵͳÉÏÉèÖø߿ÉÓõÄÊý¾Ý¿â¸´ÖÆ£¬²¢ÌṩÁËÏà¹ØµÄ´úÂëʾÀý¡£Ï£Íû±¾ÎĶÔÄãÔÚÉèÖÃÊý¾Ý¿â¸´ÖÆʱÓÐËù×ÊÖú¡£
ÒÔÉϾÍÊÇÔõÑùÔÚLinuxÉÏÉèÖø߿ÉÓõÄÊý¾Ý¿â¸´ÖƵÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡