¸ß¿ÉÓÃÐÔ½â¾ö¼Æ»®£ºÊ¹ÓÃNginx Proxy ManagerʵÏÖÊý¾Ý¿âÖ÷´Ó¸´ÖÆ
¸ß¿ÉÓÃÐÔ½â¾ö¼Æ»®£ºÊ¹ÓÃNginx Proxy ManagerʵÏÖÊý¾Ý¿âÖ÷´Ó¸´ÖÆ
СÐò
¸ß¿ÉÓÃÐÔÊÇÏÖ´úÆóÒµÖкÜÊÇÖ÷ÒªµÄÒ»¸öÐèÇó¡£ÔÚÔÚÏßÓ¦ÓóÌÐòÖУ¬Êý¾Ý¿âÆð×ÅÖÁ¹ØÖ÷ÒªµÄ×÷Óá£ÎªÁËÈ·±£Êý¾ÝµÄÍêÕûÐԺͿɿ¿ÐÔ£¬ÎÒÃÇÐèÒª½ÓÄÉһЩ²½·¥À´°ü¹ÜÊý¾Ý¿âµÄ¸ß¿ÉÓÃÐÔ¡£±¾ÎĽ«ÏÈÈÝÒ»ÖÖʹÓÃNginx Proxy ManagerʵÏÖÊý¾Ý¿âÖ÷´Ó¸´ÖƵĽâ¾ö¼Æ»®£¬²¢ÌṩÏêϸµÄ´úÂëʾÀý¡£
ʲôÊÇÊý¾Ý¿âÖ÷´Ó¸´ÖÆ£¿
Êý¾Ý¿âÖ÷´Ó¸´ÖÆÊÇÒ»ÖÖ³£Óõĸ߿ÉÓÃÐÔ½â¾ö¼Æ»®¡£Ëüͨ¹ýÔÚÖ÷Êý¾Ý¿âÉϼͼÊý¾Ý¿â²Ù×÷ÈÕÖ¾£¬È»ºó½«ÈÕÖ¾´«Êä¸ø´ÓÊý¾Ý¿â£¬´ÓÊý¾Ý¿âÔÙ½«ÕâЩÈÕÖ¾Ó¦Óõ½×ÔÉíµÄÊý¾Ý¿âÖУ¬ÊµÏÖÖ÷Êý¾Ý¿âºÍ´ÓÊý¾Ý¿âÖ®¼äµÄÊý¾Ýͬ²½¡£
Nginx Proxy Manager
Nginx Proxy ManagerÊÇÒ»¸ö»ùÓÚNginxµÄ¸ß¿ÉÓÃÐÔ½â¾ö¼Æ»®¡£Ëü¿ÉÒÔͨ¹ý·´ÏòÊðÀíºÍ¸ºÔØƽºâÀ´·Ö·¢Á÷Á¿£¬´Ó¶øʵÏָ߿ÉÓÃÐԺ͸ßÐÔÄÜ¡£ÔÚÎÒÃǵĽâ¾ö¼Æ»®ÖУ¬ÎÒÃǽ«Ê¹ÓÃNginx Proxy ManagerÀ´´¦ÀíÊý¾Ý¿âµÄ¸ß¿ÉÓÃÐÔ¡£
½â¾ö¼Æ»®¸ÅÊö
ÎÒÃǵĽâ¾ö¼Æ»®½«ÉèÖÃÁ½¸öÊý¾Ý¿âʵÀý£ºÒ»¸öÖ÷Êý¾Ý¿âºÍÒ»¸ö´ÓÊý¾Ý¿â¡£Ö÷Êý¾Ý¿â½«ÎüÊÕËùÓеÄд²Ù×÷£¬²¢½«²Ù×÷ÈÕÖ¾·¢Ë͸ø´ÓÊý¾Ý¿â¡£´ÓÊý¾Ý¿â½«¶ÁÈ¡Ö÷Êý¾Ý¿âµÄ²Ù×÷ÈÕÖ¾£¬²¢½«ÆäÓ¦Óõ½×Ô¼ºµÄÊý¾Ý¿âÖУ¬´Ó¶øʵÏÖÊý¾ÝµÄͬ²½¡£
ÉèÖÃÖ÷Êý¾Ý¿â
Ê×ÏÈ£¬ÎÒÃÇÐèÒªÔÚÖ÷Êý¾Ý¿âÖÐÆôÓöþ½øÖÆÈÕÖ¾¼Í¼¡£ÔÚMySQLµÄÉèÖÃÎļþÖУ¬ÉèÖÃÒÔÏÂÄÚÈÝ£º
[mysqld] log-bin = /var/log/mysql/mysql-bin.log server-id = 1
µÇ¼ºó¸´ÖÆ
È»ºó£¬ÖØÆôÖ÷Êý¾Ý¿âÒÔʹÉèÖÃÉúЧ¡£
ÉèÖôÓÊý¾Ý¿â
ÔÚÉèÖôÓÊý¾Ý¿â֮ǰ£¬ÇëÈ·±£ÄúÒѾװÖÃÁËMySQL£¬²¢ÒÑ×èÖ¹MySQLЧÀÍ¡£
Ê×ÏÈ£¬ÎÒÃÇÐèÒªÉèÖôÓÊý¾Ý¿âµÄ¸´ÖƲÎÊý¡£ÔÚMySQLµÄÉèÖÃÎļþÖУ¬ÉèÖÃÒÔÏÂÄÚÈÝ£º
[mysqld] server-id = 2 relay-log = /var/log/mysql/mysql-relay-bin.log log_slave_updates = 1 read_only = 1
µÇ¼ºó¸´ÖÆ
È»ºó£¬Æô¶¯´ÓÊý¾Ý¿â£¬²¢Ö´ÐÐÒÔÏÂSQLÓï¾ä£º
CHANGE MASTER TO MASTER_HOST='Ö÷Êý¾Ý¿âIPµØµã', MASTER_USER='¸´ÖÆÓû§', MASTER_PASSWORD='¸´ÖÆÓû§ÃÜÂë', MASTER_LOG_FILE='mysql-bin.000001', MASTER_LOG_POS=107;
µÇ¼ºó¸´ÖÆ
×¢Öؽ«ÉÏÊöÓï¾äÖеIJÎÊýÌ滻ΪÄú×Ô¼ºµÄ²ÎÊý¡£
ÉèÖÃNginx Proxy Manager
ÏÖÔÚ£¬ÎÒÃǽ«ÉèÖÃNginx Proxy ManagerÀ´ÊðÀíÖ÷Êý¾Ý¿âºÍ´ÓÊý¾Ý¿â¡£ÔÚNginx Proxy ManagerµÄÉèÖÃÎļþÖУ¬Ìí¼ÓÒÔÏÂÄÚÈÝ£º
upstream db_servers { server Ö÷Êý¾Ý¿âIPµØµã; server ´ÓÊý¾Ý¿âIPµØµã backup; } server { listen 3306; location / { proxy_pass http://db_servers; #ÏÂÃæÊÇÆäËûµÄNginxÉèÖà } }
µÇ¼ºó¸´ÖÆ
È»ºó£¬ÖØÆôNginx Proxy ManagerÒÔʹÉèÖÃÉúЧ¡£
²âÊԸ߿ÉÓÃÐÔ
´Ëʱ£¬ÄúÒѾÀÖ³ÉÉèÖÃÁËÊý¾Ý¿âÖ÷´Ó¸´ÖƺÍNginx Proxy Manager¡£ÎªÁ˲âÊԸ߿ÉÓÃÐÔ£¬Äú¿ÉÒÔʵÑéÔÚÖ÷Êý¾Ý¿âÉϾÙÐÐд²Ù×÷£¬È»ºóÔÚ´ÓÊý¾Ý¿âÉϾÙÐжÁ²Ù×÷£¬È·±£Êý¾Ýͬ²½×¼È·¡£
½áÂÛ
ͨ¹ýÒÔÉϵÄÉèÖã¬ÎÒÃÇÀÖ³ÉʵÏÖÁËÊý¾Ý¿âµÄÖ÷´Ó¸´ÖÆ£¬²¢Ê¹ÓÃNginx Proxy ManagerʵÏÖÁ˸߿ÉÓÃÐÔ¡£ÕâÖÖ½â¾ö¼Æ»®Äܹ»È·±£Êý¾Ý¿âÔÚ±¬·¢¹ÊÕÏʱµÄ¿ìËÙÇл»ºÍÊý¾ÝµÄ¿É¿¿ÐÔ¡£Ï£Íû±¾ÎĶÔÄúÓÐËù×ÊÖú£¡
²Î¿¼ÎÄÏ×£º
[1] MySQL Documentation. Replication. [Á´½Ó]
[2] Nginx Documentation. Proxying TCP and UDP Load Balancing. [Á´½Ó]
ÒÔÉϾÍÊǸ߿ÉÓÃÐÔ½â¾ö¼Æ»®£ºÊ¹ÓÃNginx Proxy ManagerʵÏÖÊý¾Ý¿âÖ÷´Ó¸´ÖƵÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡