Ëæ×Å»¥ÁªÍøʱ´ú·ÉËÙÉú³¤£¬»¥ÁªÍø¹«Ë¾Ö§³ÖÓªÒµµÄЧÀÍÆ÷ºÍ½»Á÷»úÊýÄ¿Ò²ÈÕ½¥ÔöÌí£¬Óë´Ëͬʱ¹ØÓÚЧÀÍÆ÷µÄά»¤±¾Ç®Ô½À´Ô½¸ß£¬Ò»Ñùƽ³£ÖÎÀíÒ²Ïà¶Ô½ÏÁ¿²µÔÓ¡£ÈçÌìÌì½ö¿¿×ÅÈ˹¤È¥ÊÖ¶¯Î¬»¤Ð§ÀÍÆ÷£¬Ö´Ðдó×ÚµÄÖظ´ÐÔµÄÏÂÁÊƱػáÆÌÕÅ´ó×ÚµÄʱ¼äºÍ¾«Éñ£¬Ò²»á´øÀ´Ç±ÔÚµÄΣº¦ºÍÎó²î¡£ÔÚÕâÖÖÇéÐÎÏ£¬±ãÑÜÉú³öÀ´ÁË×Ô¶¯»¯ÔËά¡£
ÂÄÀúÁËÈ˹¤»¯£¬¾ç±¾»¯Ö®ºó£¬×Ô¶¯»¯Öð½¥½µÉú£¬×Ô¶¯»¯µÄ·ºÆðʹÔËάµÄÀú³ÌÇ°½øÁËÒ»´ó²½£¬Ëü½µµÍÁËÈ˹¤Î¬»¤µÄ±¾Ç®£¬½«´ó×ÚµÄÖظ´ÐÔµÄÊÂÇé×Ô¶¯»¯£¬½«ÒÑÍùµÄÊÖ¹¤²Ù×÷תΪ×Ô¶¯»¯²Ù×÷¡£×Ô¶¯»¯ÔËά²»µ«µ¥ÊÇÒ»¸öά»¤µÄÀú³Ì£¬Ò²ÊÇδÀ´Éú³¤µÄÒ»ÖÖÒ»¶¨Ç÷ÊÆ¡£
½ËÕ×ðÁú¿Ê±Ò»Ö±Éî¶È±ÊÖ±ÓÚÐÐÒµ¿Í»§£¬ÖÂÁ¦ÓÚÌáÉýITÔËάЧÀÍÖÊÁ¿£¬ Öª×ãÆóÒµÊý×Ö»¯¡¢ÖÇÄÜ»¯¡¢Ô¶³Ì»¯µÄÔËάÐèÇó£¬ÊµÏÖºã¾ÃµÄÒ»Á¬¸ÄÉÆ£¬¾ÓÉ´ó×ÚµÄÏîÄ¿Ä¥Á¶ÒÔ¼°ÂÄÀú»ýÀÛ£¬×ðÁú¿Ê±ÊµÏÖÁËÍêÉƵÄ×Ô¶¯»¯ÔËά¼Æ»®¡£
×Ô¶¯»¯ÔËά¹¤¾ß
Ö÷Á÷µÄ×Ô¶¯»¯ÔËά¹¤¾ßÖ÷ÒªÓÐAnsible ¡¢ SaltStack ¡¢ Puppet ¡£
Puppet»ùÓÚrubby¿ª·¢£¬C/S¼Ü¹¹£¬Ö§³Ö¶àƽ̨£¬¿ÉÖÎÀíÉèÖÃÎļþ¡¢Óû§¡¢cronʹÃü¡¢Èí¼þ°ü¡¢ÏµÍ³Ð§À͵ȡ£·ÖΪÉçÇø°æ£¨Ãâ·Ñ£©ºÍÆóÒµ°æ£¨ÊÕ·Ñ£©£¬ÆóÒµ°æÖ§³ÖͼÐλ¯ÉèÖá£
Saltstack»ùÓÚpython¿ª·¢£¬C/S¼Ü¹¹£¬Ö§³Ö¶àƽ̨£¬±ÈpuppetÇáÁ¿£¬ÔÚÔ¶³ÌÖ´ÐÐÏÂÁîÊǷdz£¿ì½Ý£¬ÉèÖúÍʹÓñÈpuppetÈÝÒ×£¬ÄÜʵÏÖpuppetÏÕЩËùÓеĹ¦Ð§¡£
AnsibleÏà¶ÔÀ´Ëµ£¬Ê¹ÓÃÔ½·¢¾«Á·Àû±ã£¬²»ÐèÒªÔÚ±»¹ÜЧÀÍÆ÷ÉÏ×°ÖÃÊðÀíÈí¼þ¡£Ansible»ùÓÚSSHͨµÀÖ´ÐÐËùÓй¦Ð§£¬AnsibleÊÇÓÉPythonÓïÑÔ¿ª·¢£¬¹ØÓÚÊìϤpythonµÄÈ˶øÑÔÈÝÒ×ÉÏÊÖ¡£Ansible¿ÉÒÔ´ÓÏÂÁîÐÐÖ±½ÓÖ´ÐÐÏÂÁ¶ø²»ÐèҪʹÓÃÉèÖÃÎļþ¡£ÖÁÓÚ½ÏÁ¿ÖØ´óµÄʹÃüÔò¿ÉÒÔʹÓÃAnsible-Playbook¾ç±¾±àд¡£Playbook»¹¿ÉÒÔʹÓÃÄ£°åÀ´À©Õ¹Æ书Ч£¬ÏÖÔÚplaybookµÄÄ£°åÕվɺÜÊǸ»ºñµÄ¡£¿ÉÒÔʵÏÖÅúÁ¿³ÌÐò°²ÅÅ£¬ÅúÁ¿Ð§ÀÍÉý¼¶£¬ÅúÁ¿Ð§ÀÍʵÑ飬ÅúÁ¿Ð§ÀÍÆ÷Ѳ¼ìµÈ¶àÖÖ¹¦Ð§¡£
Ö÷ÒªÏêÊöansible:
Ansible½¹µã¿ò¼Ü£º×éºÏInventory¡¢API¡¢Modules¡¢PluginsµÄÂÌ¿ò£¬¿ÉÒÔÃ÷ȷΪÊÇAnsibleÏÂÁ¾ß£¬ÆäΪ½¹µãÖ´Ðй¤¾ß¡£
Inventory ÊÇÖÎÀíÖ÷»úµÄÒ»¸öÉèÖÃÇåµ¥£¬¿ÉÒÔÔÚÄÚÀïÖ¸¶¨²Ù×÷µÄÖ÷»ú£¬×Ô½ç˵±äÁ¿¡£ÆäÎļþĬÈÏ·¾¶ÊÇ/etc/ansible/hosts¡£
PlaybookÓÖÃû¾ç±¾£¬ÊÇAnsibleµÄʹÃü¼¯µÄ¾ç±¾£¬ËüÊÇYAMLÃûÌÃÎļþ£¬¶à¸öTask½ç˵ÔÚÒ»¸öÎļþÖУ¬½ç˵Ö÷»úÐèҪŲÓÃÄÄЩModulesÀ´Íê³ÉµÄ¹¦Ð§¡£
ModulesÊǽ¹µãÄ£¿é&×Ô½ç˵ģ¿é¡£AnsibleÖ´ÐÐÏÂÁîµÄ¹¦Ð§Ä£¿é£¬´ó¶¼ÎªÄÚÖõĽ¹µãÄ£¿é£¬Ò²¿É×Ô½ç˵£¬ansible-doc ¨Cl ¿ÉÉó²éÄ£¿é¡£
Plugins²å¼þÊǹØÓÚAnsibleÄ£¿é¹¦Ð§µÄÔö²¹£¬ÈçÅþÁ¬ÀàÐͲå¼þ¡¢Ñ»·²å¼þ¡¢±äÁ¿²å¼þ¡¢¹ýÂ˲å¼þµÈ¡£
AnsibleʵսÑÝÁ·
01 ×Ô¶¯»¯Ñ²¼ì
ÔÚ±±¾©Ä³¾Öµã¶Ôansible¾ÙÐÐÏÖʵ²Ù×÷¡£ÓÉÓÚ×°±¸µÄ·±ÔÓ£¬³öÓÚ¶ÔÈËÁ¦±¾Ç®µÄ˼Á¿¡£¾öÒéÓÃansibleÍŽácronÄ£¿é¾ÙÐÐ׼ʱ×Ô¶¯»¯Ñ²¼ì¡£
˵Ã÷£ºÒòϵͳµÄ²î±ð£¬ansibleŲÓõÄÐÒéÒ²²»¾¡Ïàͬ¡£»á¼ûLinux·½Ãæ½ÓÄÉSSHÐÒ飬»á¼ûwindowsͨ¹ýWinRMÀ´ÊµÏÖÔ¶³ÌÖÎÀí¡£
1.ÉèÖÃÍêÖ÷»úÇåµ¥ºÍansible.cfgÏà¹ØÉèÖÃÖ®ºó¡£Ê×Ïȱàдxunjian.j2£¨linuxѲ¼ì¾ç±¾Ä£°åÎļþ£©ºÍwindows_xunjian.ps1£¨WindowsѲ¼ì¾ç±¾Ä£°åÎļþ£©¡£
2.ͨ¹ýansibleµÄtemplatesÄ£¿é½«±àдµÄjinjia2Ä£°åÎļþ·Ö·¢µ½ÊܿضËЧÀÍÆ÷¡£²¢É趨Æä¾ç±¾ÀàÐÍ£¬linuxϵͳµÄΪshell¾ç±¾£¬windowsµÄΪpowershell¾ç±¾¡£¿ÉÒÔÌØÊâÉ趨½«Ñ²¼ìЧ¹û´æ´¢µ½Ö¸¶¨µÄÈÕÖ¾ÎļþÖв¢ÕûÌåÀÈ¡µ½ansibleÖÎÀí¶Ë¡£
3.ͨ¹ýansible-playbook±àдlinux_xunjian.ymlºÍwindows_xunjian.yml¡£È»ºó¿ÉÒÔ±àдһ¸ö×ÜÌåµÄxunjian.yml£¬ÄÚÀïÓÃinclude½«ÕâÁ½¸öϵͳµÄymlÎļþÒý½øÀ´£¬ÕâÑùÀû±ãÖ´ÐС£
4.×îºóÒ»²½ÊµÏÖ׼ʱÔËÐÐѲ¼ì¡£ÔËÓÃansibleÄÚµÄcronÄ£¿é±àдyml¾ç±¾£¬¿ÉÒÔÔÚÄÚ²¿ÉèÖÃÖ´ÐÐ×îÏÈʱ¼ä£¬Ö´ÐÐÖÜÆÚµÈÏà¹ØÉèÖá£
02 ×Ô¶¯»¯ÊµÑé
¹ØÓÚϵͳÖÎÀíÔ±À´½²£¬Ã¿Ò»Ì¨»úеÉÏƾ֤¿ª·¢¸øµÄÐèÇóÃû¼òµ¥¸öÒ»¸ö×°Ö㬲»µ«Ð§Âʵ͡¢ÀͶ¯±¾Ç®¸ß¡¢²¢ÇÒÈÝÒ×ÍÉ»¯£¬Ôì³ÉÇéÐεķ×ÆçÖ¡£¶øAnsible¾ßÓÐÃݵÈÐÔµÄÌص㣬ÎÞÂÛÖ´Ðм¸¶à´Î£¬Ö»ÒªÄãµÄ²Ù×÷ϵͳÊÇͳһ¸ö°æ±¾£¬ÄÇôװÖóöÀ´µÄÇéÐξø¶ÔÊÇÒ»ÑùµÄ£¬ÕâÑùÒ²¾Í°ü¹ÜÁËÓ¦ÓÃËù´¦µÄµ×²ãÇéÐεÄÒ»ÖÂÐÔ£¬¶ø²»»áÔì³Éͳһ¸ö°æ±¾µÄÓ¦ÓÃÔÚ²î±ðµÄ»úеÉÏÔËÐзºÆð²î±ðµÄЧ¹ûµÄÎÊÌâ¡£
Éæ¼°µ½ÏµÍ³ÇéÐεÄ×Ô¶¯»¯Éý¼¶£¬Í¬Ñù¿ÉʹÓÃansibleÀ´Íê³É£¬ºÃ±ÈÅúÁ¿Éý¼¶console¡¢hooker¡¢tomcatÏà¹ØµÄЧÀÍ¡£ÍêÈ«¿ÉÒÔͨ¹ýansibleÀ´ÊµÏÖЧÀ͹ػú¡¢Îļþ±¸·Ý¡¢ÎļþÌæ»»¡¢»º´æÕûÀí¡¢Ð§ÀÍÆô¶¯µÈһϵÁвÙ×÷¡£ÊµÏÖ×Ô¶¯»¯µÄÉý¼¶¶ø²»ÐèҪȥÊÖ¶¯µÄÈ¥¶à´Î²Ù×÷£¬Ò²×èÖ¹ÁËÊÖ¶¯µÄÎóɾÎļþµÈ²»Á¼²Ù×÷¡£
¾Ù¸ö¡°Àõ×Ó¡±£ºÈçÐèÔÚËÄʮ̨ЧÀÍÆ÷ÉÏ°²ÅÅjdkÇéÐΣ¬Ò»Ì¨Ò»Ì¨Öð²½°²ÅÅ»òÐíÐèÒªÈý¸öСʱ²Å»ªÍê³É£¬ºÜÊÇÆÌÕÅʱ¼äºÍ¾«Éñ¡£ÈôÊÇʹÓÃansibleµÄ»°Ö»ÐèҪʮ·ÖÖÓ×óÓҾͿÉÒÔÍê³É¡£Ö»ÐèÒª±àдºÃymlÎļþ£¬×¼±¸ºÃjdk×°Öðü¡£Ê¹ÓÃansible-playbookÏÂÁîÈ¥ÔËÐм´¿É¡£
LinuxÇéÐΰ²ÅÅjdkʾÀý£º
WindowsÇéÐΰ²ÅÅjdkʾÀý£º
¹Ø×¢Êý¾Ý °ü¹ÜδÀ´
ɨÂë£ü¹Ø×¢ÎÒÃÇ
΢Ðźţü½ËÕ×ðÁú¿Ê±
꿅ᣟhttp://www.bwda.net