×ðÁú¿­Ê±¹ÙÍøµÇ¼

ÔõÑùÔÚLinuxÉÏÉèÖø߿ÉÓõÄÊý¾Ý¿â¼¯Èº±¸·Ý

ÔõÑùÔÚlinuxÉÏÉèÖø߿ÉÓõÄÊý¾Ý¿â¼¯Èº±¸·Ý

ÔÚÏÖ´ú´óÊý¾Ýʱ´ú £¬Êý¾Ý¿âµÄ¸ß¿ÉÓÃÐÔ±¸·ÝÏÔµÃÓÈΪÖ÷Òª¡£µ±Êý¾Ý¿â±¬·¢¹ÊÕÏ»ò·ºÆð¹ÊÕÏʱ £¬±¸·Ý¿ÉÒÔ°ü¹ÜÊý¾ÝµÄÍêÕûÐԺͿɿ¿ÐÔ £¬´Ó¶ø×î´óÏ޶ȵØïÔ̭Ӫҵͣ»úʱ¼ä¡£ÔÚLinuxÉÏ £¬ÊµÏָ߿ÉÓõÄÊý¾Ý¿â¼¯Èº±¸·Ý¿ÉÒÔʹÓÃһЩ¿ªÔ´¹¤¾ßºÍÊÖÒÕ¡£±¾ÎĽ«ÌÖÂÛÔõÑùʹÓÃLinuxÇéÐÎϵÄÁ½¸öÖ÷Òª¹¤¾ß £¬¼´PacemakerºÍCorosync £¬À´ÊµÏָ߿ÉÓõÄÊý¾Ý¿â¼¯Èº±¸·Ý¡£

Ò»¡¢PacemakerºÍCorosyncµÄ»ù±¾ÏÈÈÝ

PacemakerÊÇÒ»¸ö¿ªÔ´µÄ¸ß¿ÉÓÃÐÔ¼¯Èº×ÊÔ´ÖÎÀíÆ÷ £¬¿ÉÒÔÓÃÓÚ×Ô¶¯»¯ºÍÖÎÀíÔËÐÐÔÚ¼¯ÈºÖеÄЧÀͺÍÓ¦ÓóÌÐò¡£CorosyncÊÇPacemakerµÄµ×²ãͨѶÒýÇæ £¬ÓÃÓÚÔÚ¼¯Èº½ÚµãÖ®¼ä¾ÙÐÐͨѶ¡£Í¨¹ýÍŽáʹÓÃPacemakerºÍCorosync £¬ÎÒÃÇ¿ÉÒÔʵÏÖ»ùÓÚLinuxµÄ¸ß¿ÉÓÃÐÔÊý¾Ý¿â¼¯Èº±¸·Ý¡£

¶þ¡¢ÉèÖø߿ÉÓõÄÊý¾Ý¿â¼¯Èº±¸·Ý

ÒÔÏÂÊÇÔÚLinuxÉÏÉèÖø߿ÉÓÃÊý¾Ý¿â¼¯Èº±¸·ÝµÄ°ì·¨£º

×°ÖÃPacemakerºÍCorosync

Ê×ÏÈ £¬ÔÚLinuxÇéÐÎÖÐ×°ÖÃPacemakerºÍCorosync¡£ÏêϸµÄ×°ÖÃÒªÁì¿ÉÄÜÒòLinux¿¯ÐаæµÄ²î±ð¶øÓÐËù²î±ð¡£ÔÚ´ó´ó¶¼Linux¿¯ÐаæÖÐ £¬¿ÉÒÔʹÓðü¹ÜÀíÆ÷À´×°ÖÃÕâЩ¹¤¾ß¡£ÀýÈç £¬ÔÚCentOSÉÏ £¬¿ÉÒÔʹÓÃÒÔÏÂÏÂÁî¾ÙÐÐ×°Öãº

sudo yum install pacemaker corosync

µÇ¼ºó¸´ÖÆ

½¨Éè×ÊÔ´ÊðÀí

Pacemakerͨ¹ý×ÊÔ´ÊðÀíÀ´ÖÎÀíºÍ¿ØÖƲî±ðµÄЧÀͺÍÓ¦ÓóÌÐò¡£¹ØÓÚÊý¾Ý¿â¼¯Èº±¸·Ý £¬ÎÒÃÇÐèÒª½¨ÉèÒ»¸öÓÃÓÚ¿ØÖÆÊý¾Ý¿âµÄ×ÊÔ´ÊðÀí¡£Õâ¸öÊðÀí¿ÉÒÔÊÇShell¾ç±¾¡¢Python¾ç±¾»òÆäËû¿ÉÖ´ÐÐÎļþ¡£ÒÔÏÂÊÇÒ»¸öʹÓÃShell½ÅÔ­À´¿ØÖÆÊý¾Ý¿âµÄʾÀý£º

#!/bin/bash

case $1 in
  start)
    # Æô¶¯Êý¾Ý¿â
    /path/to/start_database.sh
    ;;
  stop)
    # ×èÖ¹Êý¾Ý¿â
    /path/to/stop_database.sh
    ;;
  status)
    # Éó²éÊý¾Ý¿â״̬
    /path/to/check_database_status.sh
    ;;
  *)
    echo "Usage: $0 {start|stop|status}"
    exit 1
    ;;
esac

µÇ¼ºó¸´ÖÆ

ÔÚÉÏÃæµÄʾÀýÖÐ £¬ÄãÐèÒªÌæ»»/path/to/ºÍ.shΪÕæʵµÄÊý¾Ý¿âÆô¶¯¡¢×èÖ¹ºÍ״̬¼ì²é¾ç±¾µÄ·¾¶ºÍÃû³Æ¡£

½¨É輯ȺÉèÖÃÎļþ

ÔÚLinuxÉÏʹÓÃPacemakerºÍCorosync £¬ÄãÐèÒª½¨ÉèÒ»¸ö¼¯ÈºÉèÖÃÎļþÀ´½ç˵¼¯ÈºµÄÊôÐԺͲÎÊý¡£ÒÔÏÂÊÇÒ»¸öʾÀýµÄ¼¯ÈºÉèÖÃÎļþ£º

# /etc/corosync/corosync.conf

totem {
  version: 2
  secauth: off
  cluster_name: mycluster
}

nodelist {
  node {
    ring0_addr: 192.168.1.10
    nodeid: 1
  }
  node {
    ring0_addr: 192.168.1.11
    nodeid: 2
  }
}

quorum {
  provider: corosync_votequorum
}

logging {
  fileline: off
  to_stderr: yes
  to_logfile: yes
  to_syslog: yes
  logfile: /var/log/corosync/corosync.log
  debug: off
  timestamp: on
}

µÇ¼ºó¸´ÖÆ

ÔÚÉÏÃæµÄʾÀýÖÐ £¬ÄãÐèҪƾ֤ÏÖÕæÏàÐε÷½âcluster_name¡¢ring0_addrºÍnodeidµÈ²ÎÊý¡£

½¨Éè×ÊÔ´ºÍ×ÊÔ´×é

ÔÚPacemakerÖÐ £¬×ÊÔ´ÊÇÄãÏ£ÍûÔÚ¼¯ÈºÖÐÖÎÀíµÄЧÀÍ»òÓ¦ÓóÌÐò¡£×ÊÔ´×éÊÇ×éºÏ¶à¸ö×ÊÔ´µÄÂß¼­×é¡£¹ØÓÚÊý¾Ý¿â¼¯Èº±¸·Ý £¬Äã¿ÉÒÔ½¨ÉèÒ»¸ö×ÊÔ´À´¿ØÖÆÊý¾Ý¿âµÄÆô¶¯¡¢×èÖ¹ºÍ״̬¼ì²é £¬²¢½«ËüÌí¼Óµ½Ò»¸ö×ÊÔ´×éÖС£

ʹÓÃÒÔÏÂÏÂÁîÀ´½¨Éè×ÊÔ´ºÍ×ÊÔ´×飺

sudo pcs resource create db_resource ocf:pacemaker:my_resource op start timeout=30s op stop timeout=30s op monitor interval=10s
sudo pcs resource group add db_resource_group db_resource

µÇ¼ºó¸´ÖÆ

ÔÚÉÏÃæµÄʾÀýÖÐ £¬ÄãÐèÒª½«my_resourceÌ滻ΪÄã֮ǰ½¨ÉèµÄ×ÊÔ´ÊðÀíµÄ·¾¶¡£

Æô¶¯¼¯Èº

ʹÓÃÒÔÏÂÏÂÁîÀ´Æô¶¯¼¯Èº£º

sudo systemctl start corosync
sudo systemctl start pacemaker

µÇ¼ºó¸´ÖÆ

ÑéÖ¤¼¯ÈºÉèÖÃ

ʹÓÃÒÔÏÂÏÂÁîÀ´ÑéÖ¤¼¯ÈºÉèÖãº

sudo crm_verify -L

µÇ¼ºó¸´ÖÆ

ÈôÊÇÑé֤ͨ¹ý £¬Äã¿ÉÒÔ¿´µ½ÀàËÆÒÔϵÄÊä³ö£º

Warnings found during check: none
Corosync configuration appears to be valid.

µÇ¼ºó¸´ÖÆ

²âÊÔ¼¯Èº±¸·Ý

ÏÖÔÚ £¬Äã¿ÉÒÔ²âÊÔÊý¾Ý¿âµÄ¸ß¿ÉÓñ¸·ÝÁË¡£Ê¹ÓÃÒÔÏÂÏÂÁîÀ´Æô¶¯ºÍ×èÖ¹Êý¾Ý¿â¼¯Èº±¸·Ý£º

sudo pcs resource enable db_resource
sudo pcs resource disable db_resource

µÇ¼ºó¸´ÖÆ

ʹÓÃÒÔÏÂÏÂÁî¼ì²éÊý¾Ý¿â¼¯Èº±¸·ÝµÄ״̬£º

sudo pcs status

µÇ¼ºó¸´ÖÆ

ÈôÊÇ״̬ÏÔʾΪ”Started” £¬Ôò˵Ã÷Êý¾Ý¿â¼¯Èº±¸·ÝÕýÔÚÔËÐС£ÈôÊÇ״̬ÏÔʾΪ”Stopped” £¬Ôò˵Ã÷Êý¾Ý¿â¼¯Èº±¸·ÝÒÑ×èÖ¹¡£

×ܽá

±¾ÎÄÏÈÈÝÁËÔõÑùÔÚLinuxÇéÐÎÖÐÉèÖø߿ÉÓõÄÊý¾Ý¿â¼¯Èº±¸·Ý¡£Í¨¹ýÍŽáʹÓÃPacemakerºÍCorosync £¬ÎÒÃÇ¿ÉÒÔʵÏÖ¿É¿¿¶ø¸ßЧµÄÊý¾Ý¿â±¸·Ý £¬´Ó¶ø×î´óÏ޶ȵØïÔ̭Ӫҵͣ»úʱ¼ä¡£Ï£Íû±¾ÎÄÄܶÔÄãÓÐËù×ÊÖú¡£

ÒÔÉϾÍÊÇÔõÑùÔÚLinuxÉÏÉèÖø߿ÉÓõÄÊý¾Ý¿â¼¯Èº±¸·ÝµÄÏêϸÄÚÈÝ £¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

ÃâÔð˵Ã÷£ºÒÔÉÏչʾÄÚÈÝȪԴÓÚÏàÖúýÌå¡¢ÆóÒµ»ú¹¹¡¢ÍøÓÑÌṩ»òÍøÂçÍøÂçÕûÀí £¬°æȨÕùÒéÓë±¾Õ¾ÎÞ¹Ø £¬ÎÄÕÂÉæ¼°¿´·¨Óë¿´·¨²»´ú±í×ðÁú¿­Ê±¹ÙÍøµÇ¼ÂËÓÍ»úÍø¹Ù·½Ì¬¶È £¬Çë¶ÁÕß½ö×ö²Î¿¼¡£±¾ÎĽӴýתÔØ £¬×ªÔØÇë˵Ã÷À´ÓÉ¡£ÈôÄúÒÔΪ±¾ÎÄÇÖÕ¼ÁËÄúµÄ°æȨÐÅÏ¢ £¬»òÄú·¢Ã÷¸ÃÄÚÈÝÓÐÈκÎÉæ¼°ÓÐÎ¥¹«µÂ¡¢Ã°·¸Ö´·¨µÈÎ¥·¨ÐÅÏ¢ £¬ÇëÄúÁ¬Ã¦ÁªÏµ×ðÁú¿­Ê±¹ÙÍøµÇ¼ʵʱÐÞÕý»òɾ³ý¡£

Ïà¹ØÐÂÎÅ

ÁªÏµ×ðÁú¿­Ê±¹ÙÍøµÇ¼

18523999891

¿É΢ÐÅÔÚÏß×Éѯ

ÊÂÇéʱ¼ä£ºÖÜÒ»ÖÁÖÜÎå £¬9:30-18:30 £¬½ÚãåÈÕÐÝÏ¢

QR code
ÍøÕ¾µØͼ