ÔõÑùÔÚLinuxÉÏÉèÖø߿ÉÓõÄϵͳ׼ʱʹÃü
ÔõÑùÔÚlinuxÉÏÉèÖø߿ÉÓõÄϵͳ׼ʱʹÃü
ÔÚLinuxϵͳÖУ¬×¼Ê±Ê¹ÃüÊÇÒ»ÏîºÜÊÇÖ÷ÒªµÄ¹¦Ð§£¬¿ÉÒÔÈÃÎÒÃÇ×Ô¶¯Ö´ÐÐһЩÖظ´ÐÔµÄʹÃü£¬Ìá¸ßÊÂÇéЧÂÊ¡£È»¶ø£¬µ±ÎÒÃǵÄϵͳÐèÒª¼á³Ö¸ß¿ÉÓÃÐÔʱ£¬¾ÍÐèÒªÌØÊâ¹Øע׼ʱʹÃüµÄÉèÖã¬È·±£×ÝÈ»ÔÚij¸ö½Úµã·ºÆð¹ÊÕϵÄÇéÐÎÏ£¬Ê¹ÃüÈÔÈ»Äܹ»Õý³£ÔËÐС£±¾ÎĽ«ÏÈÈÝÔõÑùÔÚlinuxÉÏÉèÖø߿ÉÓõÄϵͳ׼ʱʹÃü£¬²¢¸½ÉÏÏìÓ¦µÄ´úÂëʾÀý¡£
Ò»¡¢Ê¹ÓÃcrontabÖÎÀí׼ʱʹÃü
ÔÚLinuxϵͳÖУ¬ÎÒÃÇͨ³£Ê¹ÓÃcrontabÏÂÁîÀ´ÖÎÀí׼ʱʹÃü¡£crontabÏÂÁîÄܹ»ÈÃÎÒÃÇÌí¼Ó¡¢É¾³ý¡¢Éó²éºÍ±à¼×¼Ê±Ê¹Ãü£¬ºÜÊÇÀû±ãÊÊÓá£
Ìí¼Ó׼ʱʹÃü
ÎÒÃÇ¿ÉÒÔͨ¹ýÒÔÏÂÏÂÁîÀ´Ìí¼Ó׼ʱʹÃü£º
crontab -e
µÇ¼ºó¸´ÖÆ
Õâ¸öÏÂÁî»á·¿ªÒ»¸öÎı¾±à¼Æ÷£¬ÈÃÎÒÃDZà¼Ä¿½ñÓû§µÄ׼ʱʹÃü¡£Ã¿Ò»Ðдú±íÒ»¸ö׼ʱʹÃü£¬ÃûÌÃÈçÏ£º
command
ÆäÖУ¬Îå¸öÐǺŻ®·Ö´ú±íÁË·ÖÖÓ¡¢Ð¡Ê±¡¢Ìì¡¢Ô¡¢ÐÇÆÚ£¬¿ÉÒÔÓÃÏêϸµÄÊý×ÖÌåÏÖ£¬Ò²¿ÉÒÔÓÃ"*"ÌåÏÖí§ÒâÖµ¡£command´ú±íÒªÖ´ÐеÄÏÂÁî»ò¾ç±¾¡£
µÇ¼ºó¸´ÖÆ
ɾ³ý׼ʱʹÃü
ÈôÊÇÎÒÃÇÐèҪɾ³ýÒ»¸ö׼ʱʹÃü£¬¿ÉÒÔʹÓÃÒÔÏÂÏÂÁ
crontab -r
µÇ¼ºó¸´ÖÆ
Õâ¸öÏÂÁî»áɾ³ýÄ¿½ñÓû§µÄËùÓÐ׼ʱʹÃü¡£
Éó²é׼ʱʹÃü
ÈôÊÇÎÒÃÇÐèÒªÉó²éÄ¿½ñÓû§µÄ׼ʱʹÃüÁÐ±í£¬¿ÉÒÔʹÓÃÒÔÏÂÏÂÁ
crontab -l
µÇ¼ºó¸´ÖÆ
Õâ¸öÏÂÁî»áÏÔʾĿ½ñÓû§µÄ׼ʱʹÃüÁÐ±í¡£
¶þ¡¢ÉèÖø߿ÉÓõÄϵͳ׼ʱʹÃü
ÒªÔÚLinuxϵͳÉÏÉèÖø߿ÉÓõÄϵͳ׼ʱʹÃü£¬ÎÒÃÇÐèҪʹÓü¯ÈºÖÎÀí¹¤¾ßÀ´ÊµÏÖʹÃüµÄ×Ô¶¯Çл»ºÍͬ²½¡£ÏÂÃæÒÔKeepalivedΪÀý£¬ÏÈÈÝÔõÑù¾ÙÐÐÉèÖá£
×°ÖÃKeepalived
Ê×ÏÈ£¬ÎÒÃÇÐèҪװÖÃKeepalived¡£ÔÚDebian/UbuntuϵͳÉÏ£¬¿ÉÒÔʹÓÃÒÔÏÂÏÂÁî¾ÙÐÐ×°Öãº
apt-get install keepalived
µÇ¼ºó¸´ÖÆ
ÔÚÆäËûLinux¿¯ÐаæÉÏ£¬¿ÉÒÔͨ¹ýÔ´Âë×°Öá£
ÉèÖÃKeepalived
µ±KeepalivedÍê³É×°Öúó£¬ÐèÒª¾ÙÐÐÏà¹ØÉèÖ᣿ÉÒÔͨ¹ý±à¼ÉèÖÃÎļþ/etc/keepalived/keepalived.confÀ´¾ÙÐÐÉèÖá£ÏêϸµÄÉèÖÃÏîºÍ²ÎÊý¿ÉÒÔƾ֤ÏÖʵÐèÇó¾ÙÐе÷½â¡£
ÉèÖÃHAProxy
Keepalivedͨ³£ºÍHAProxyÅäºÏʹÓã¬ÒÔʵÏÖʹÃüµÄ×Ô¶¯Çл»ºÍ¸ºÔØƽºâ¡£ÔÚÉèÖÃHAProxyʱ£¬ÎÒÃÇÐèÒª½«×¼Ê±Ê¹ÃüµÄÇëÇóת·¢¸øºó¶ËµÄʹÃü½Úµã¡£¿ÉÒÔͨ¹ý±à¼ÉèÖÃÎļþ/etc/haproxy/haproxy.cfgÀ´¾ÙÐÐÉèÖá£ÏêϸµÄÉèÖÃÏîºÍ²ÎÊý¿ÉÒÔƾ֤ÏÖʵÐèÇó¾ÙÐе÷½â¡£
ÉèÖÃ׼ʱʹÃü
ÔÚÉèÖÃÁËKeepalivedºÍHAProxyÖ®ºó£¬ÎÒÃÇÐèÒª½«×¼Ê±Ê¹ÃüÉèÖÃÔÚºó¶ËµÄʹÃü½ÚµãÉÏ¡£ÕâÑù£¬µ±Ö÷½Úµã±¬·¢¹ÊÕÏʱ£¬×¼Ê±Ê¹Ãü»á×Ô¶¯Çл»µ½±¸·Ý½ÚµãÉÏÖ´ÐС£
ÒÔÏÂÊÇÒ»¸öʾÀýµÄ׼ʱʹÃüÉèÖãº
* * * * * root /usr/local/bin/mycronjob.sh
µÇ¼ºó¸´ÖÆ
Õâ¸ö׼ʱʹÃü»áÿ·ÖÖÓÖ´ÐÐÒ»´ÎÃûΪmycronjob.shµÄ¾ç±¾¡£
ͬ²½ÉèÖÃÎļþºÍ¾ç±¾
ΪÁË°ü¹Ü¸ß¿ÉÓÃÐÔ£¬ÎÒÃÇÐèÒª½«ÉèÖÃÎļþºÍ¾ç±¾Í¬²½µ½ËùÓеÄʹÃü½ÚµãÉÏ¡£¿ÉÒÔʹÓù¤¾ßÈçrsync»òscpÀ´¾ÙÐÐÎļþµÄͬ²½¡£
²âÊԸ߿ÉÓÃÐÔ
µ±ÉèÖÃÍê³Éºó£¬ÎÒÃÇ¿ÉÒÔ¾ÙÐÐһЩ¹ÊÕÏÄ£Äâ²âÊÔ£¬ÒÔÑéÖ¤¸ß¿ÉÓÃÐÔ¡£ÀýÈ磬¿ÉÒÔͨ¹ý¹Ø±ÕÖ÷½ÚµãÉϵÄKeepalivedЧÀÍÀ´Ä£ÄâÖ÷½ÚµãµÄ¹ÊÕÏ£¬ÊÓ²ìʹÃüÊÇ·ñÄܹ»×Ô¶¯Çл»µ½±¸·Ý½ÚµãÉÏÖ´ÐС£
×ܽá
ͨ¹ýÒÔÉϵÄÉèÖã¬ÎÒÃÇ¿ÉÒÔÔÚLinuxϵͳÉÏʵÏָ߿ÉÓõÄϵͳ׼ʱʹÃü¡£Í¨¹ýʹÓü¯ÈºÖÎÀí¹¤¾ßºÍ¸ºÔØƽºâÊÖÒÕ£¬ÎÒÃÇÄܹ»È·±£×ÝÈ»ÔÚij¸ö½Úµã¹ÊÕϵÄÇéÐÎÏ£¬×¼Ê±Ê¹ÃüÈÔÈ»Äܹ»Õý³£ÔËÐС£Ï£Íû±¾ÎĹØÓÚ¸÷ÈËÃ÷È·ºÍÉèÖø߿ÉÓõÄϵͳ׼ʱʹÃüÓÐËù×ÊÖú¡£
ÒÔÉϾÍÊÇÔõÑùÔÚLinuxÉÏÉèÖø߿ÉÓõÄϵͳ׼ʱʹÃüµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡