ÔõÑùÔÚLinuxÉÏÉèÖø߿ÉÓõÄÊý¾Ý¿â¼¯Èº¼à¿Ø
ÔõÑùÔÚlinuxÉÏÉèÖø߿ÉÓõÄÊý¾Ý¿â¼¯Èº¼à¿Ø
СÐò£º
ÔÚÏÖ´ú»¯µÄÆóҵϵͳÖУ¬Êý¾Ý¿âÊÇÖÁ¹ØÖ÷ÒªµÄ×é³É²¿·Ö¡£ÎªÁË°ü¹ÜÊý¾Ý¿âµÄ¸ß¿ÉÓÃÐÔºÍÒ»Á¬ÎȹÌÔËÐУ¬ÔÚ Linux ÉÏÉèÖø߿ÉÓõÄÊý¾Ý¿â¼¯Èº¼à¿ØÊÇÒ»¸öÐëÒª°ì·¨¡£±¾ÎĽ«ÏÈÈÝÔõÑùÔÚ Linux ÇéÐÎÏÂÉèÖø߿ÉÓõÄÊý¾Ý¿â¼¯Èº¼à¿Ø£¬²¢ÌṩÏà¹ØµÄ´úÂëʾÀý¡£
Ò»¡¢×°ÖúÍÉèÖÃÊý¾Ý¿â¼¯Èº
ÔÚÉèÖÃÊý¾Ý¿â¼¯Èº¼à¿Ø֮ǰ£¬Ê×ÏÈÐèÒª´î½¨Ò»¸ö¿É¿¿µÄÊý¾Ý¿â¼¯Èº¡£ÒÔ MySQL Êý¾Ý¿âΪÀý£¬ÒÔÏÂÊÇ×°ÖúÍÉèÖà MySQL Êý¾Ý¿â¼¯ÈºµÄ°ì·¨£º
ÏÂÔز¢×°Öà MySQL Êý¾Ý¿â
ÔÚÿ¸ö½ÚµãÉÏÖ´ÐÐÒÔÏÂÏÂÁî¾ÙÐÐ×°Öãº
$ sudo apt-get update $ sudo apt-get install mysql-server
µÇ¼ºó¸´ÖÆ
ÉèÖà MySQL Êý¾Ý¿âÖ÷½Úµã
·¿ªÖ÷½ÚµãµÄ MySQL ÉèÖÃÎļþ£¨Í¨³£ÔÚ /etc/mysql/my.cnf£©²¢¾ÙÐÐÒÔÏÂÉèÖãº
[mysqld] server-id=1 log-bin=mysql-bin binlog-format=ROW
µÇ¼ºó¸´ÖÆ µÇ¼ºó¸´ÖÆ
ÉèÖà MySQL Êý¾Ý¿â´Ó½Úµã
·¿ª´Ó½ÚµãµÄ MySQL ÉèÖÃÎļþ£¬²¢¾ÙÐÐÒÔÏÂÉèÖãº
[mysqld] server-id=2 relay-log=mysql-relay-bin log-bin=mysql-bin binlog-format=ROW read-only=1
µÇ¼ºó¸´ÖÆ µÇ¼ºó¸´ÖÆ
Æô¶¯Êý¾Ý¿â
ÔÚÿ¸ö½ÚµãÉÏÖ´ÐÐÏÂÁîÆô¶¯Êý¾Ý¿âЧÀÍÆ÷£º
$ sudo systemctl start mysql
µÇ¼ºó¸´ÖÆ
¶þ¡¢Ê¹Óà Keepalived ʵÏָ߿ÉÓÃ
Keepalived ÊÇÒ»¸ö¿ªÔ´¹¤¾ß£¬¿ÉÓÃÓÚʵÏÖЧÀ͵ĸ߿ÉÓÃÐÔ¡£ÒÔÏÂÊÇʹÓà Keepalived ÉèÖÃÊý¾Ý¿â¼¯Èº¸ß¿ÉÓõİ취£º
×°ÖÃ Keepalived
ÔÚÿ¸ö½ÚµãÉÏÖ´ÐÐÒÔÏÂÏÂÁî¾ÙÐÐ×°Öãº
$ sudo apt-get install keepalived
µÇ¼ºó¸´ÖÆ
ÉèÖÃ Keepalived
·¿ª Keepalived ÉèÖÃÎļþ£¨Í¨³£ÔÚ /etc/keepalived/keepalived.conf£©²¢¾ÙÐÐÒÔÏÂÉèÖãº
vrrp_script check_mysql { script "/usr/bin/mysqladmin ping" interval 2 weight -1 fall 3 rise 2 } vrrp_instance VI_1 { interface eth0 state BACKUP virtual_router_id 51 priority 100 advert_int 1 authentication { auth_type PASS auth_pass strongpassword } virtual_ipaddress { 192.168.1.100 } track_script { check_mysql } }
µÇ¼ºó¸´ÖÆ
Æô¶¯ Keepalived
ÔÚÿ¸ö½ÚµãÉÏÖ´ÐÐÒÔÏÂÏÂÁîÆô¶¯ Keepalived ЧÀÍ£º
$ sudo systemctl start keepalived
µÇ¼ºó¸´ÖÆ
Èý¡¢Ê¹Óà Pacemaker ºÍ Corosync ʵÏÖ¼¯Èº¼à¿Ø
Pacemaker ÊÇÒ»¸öÓÃÓÚ¼¯ÈºÖÎÀíºÍ×Ô¶¯¹ÊÕÏתÒƵŤ¾ß£¬Corosync ÔòÊÇÓÃÓÚʵÏÖ¼¯ÈºÍ¨Ñ¶µÄÈí¼þ¡£ÒÔÏÂÊÇʹÓà Pacemaker ºÍ Corosync ÉèÖÃÊý¾Ý¿â¼¯Èº¼à¿ØµÄ°ì·¨£º
×°Öà Pacemaker ºÍ Corosync
ÔÚÿ¸ö½ÚµãÉÏÖ´ÐÐÒÔÏÂÏÂÁî¾ÙÐÐ×°Öãº
$ sudo apt-get install pacemaker corosync
µÇ¼ºó¸´ÖÆ
ÉèÖÃ Corosync
·¿ª Corosync ÉèÖÃÎļþ£¨Í¨³£ÔÚ /etc/corosync/corosync.conf£©²¢¾ÙÐÐÒÔÏÂÉèÖãº
totem { version: 2 secauth: on cluster_name: my_cluster transport: udpu } nodelist { node { ring0_addr: node1_ip name: node1 nodeid: 1 } node { ring0_addr: node2_ip name: node2 nodeid: 2 } /* Add more nodes as necessary */ } quorum { provider: corosync_votequorum }
µÇ¼ºó¸´ÖÆ
ÉèÖÃ Pacemaker
ÔÚÿ¸ö½ÚµãÉÏÖ´ÐÐÒÔÏÂÏÂÁîÉèÖà Pacemaker£º
$ sudo crm configure crm(live)> property no-quorum-policy=ignore crm(live)> rsc_defaults resource-stickiness=100 crm(live)> rsc_defaults migration-threshold=1 crm(live)> configure primitive mysql lsb:mysql op monitor interval=30s crm(live)> configure clone mysql-clone mysql meta clone-max=2 clone-node-max=1 crm(live)> configure group mysql-group mysql-clone crm(live)> verify crm(live)> commit
µÇ¼ºó¸´ÖÆ µÇ¼ºó¸´ÖÆ
½áÂÛ£º
ͨ¹ýÒÔÉÏÉèÖã¬ÎÒÃÇÀֳɵØÔÚ Linux ÉÏʵÏÖÁ˸߿ÉÓõÄÊý¾Ý¿â¼¯Èº¼à¿Ø¡£ÕâÑù£¬×ÝÈ»ÔÚ½Úµã¹ÊÕϵÄÇéÐÎÏ£¬×ðÁú¿Ê±Êý¾Ý¿âϵͳҲÄÜÒ»Á¬ÔËÐУ¬°ü¹ÜÁËϵͳµÄÎȹÌÐԺͿÉÓÃÐÔ¡£
²Î¿¼´úÂëʾÀý£º
MySQL Ö÷½ÚµãÉèÖÃÎļþʾÀý£¨/etc/mysql/my.cnf£©£º
[mysqld] server-id=1 log-bin=mysql-bin binlog-format=ROW
µÇ¼ºó¸´ÖÆ µÇ¼ºó¸´ÖÆ
MySQL ´Ó½ÚµãÉèÖÃÎļþʾÀý£¨/etc/mysql/my.cnf£©£º
[mysqld] server-id=2 relay-log=mysql-relay-bin log-bin=mysql-bin binlog-format=ROW read-only=1
µÇ¼ºó¸´ÖÆ µÇ¼ºó¸´ÖÆ
Keepalived ÉèÖÃÎļþʾÀý£¨/etc/keepalived/keepalived.conf£©£º
vrrp_script check_mysql { script "/usr/bin/mysqladmin ping" interval 2 weight -1 fall 3 rise 2 } vrrp_instance VI_1 { interface eth0 state BACKUP virtual_router_id 51 priority 100 advert_int 1 authentication { auth_type PASS auth_pass strongpassword } virtual_ipaddress { 192.168.1.100 } track_script { check_mysql } }
µÇ¼ºó¸´ÖÆ
Pacemaker ÉèÖÃÏÂÁîʾÀý£º
$ sudo crm configure crm(live)> property no-quorum-policy=ignore crm(live)> rsc_defaults resource-stickiness=100 crm(live)> rsc_defaults migration-threshold=1 crm(live)> configure primitive mysql lsb:mysql op monitor interval=30s crm(live)> configure clone mysql-clone mysql meta clone-max=2 clone-node-max=1 crm(live)> configure group mysql-group mysql-clone crm(live)> verify crm(live)> commit
µÇ¼ºó¸´ÖÆ µÇ¼ºó¸´ÖÆ
ÒÔÉϾÍÊÇÔõÑùÔÚLinuxÉÏÉèÖø߿ÉÓõÄÊý¾Ý¿â¼¯Èº¼à¿ØµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡