第17åãããã°ã©ãã³ã°ä½é¨ãã¹ã¹ã¡ã
Tweet
Linux ã·ã¹ãã ã使ãã¨ãããã¨ã¯ãå¤ããå°ãªããããã°ã©ã ãèªåã§èªã¿æ¸ããããã¨ã ã¨èãã¾ãã Linux ã·ã¹ãã ã使ã以ä¸ãã·ã§ã«ã¹ã¯ãªããã¨ç¡ç¸ã§ãããã人ã¯æ» å¤ã«ããªãã§ãããã
OSSã¯ãåé¡ãè¦ã¤ãã£ãã¨ãããã¢ãããã¼ãããªããï¼ä¿®æ£ãå ããªããï¼å©ç¨ãã¦ãããã®ã«å¯¾ããæ¥åã·ã¹ãã ã¯ãæåããå®ç§ã«ä»ä¸ãããã®ãã¢ãããã¼ãããã«ï¼ä¿®æ£ãå ããã«ï¼å©ç¨ãã¦ãããã¨ããåºæ¬å§¿å¢ã§åãã¦ããã¨æãã¾ããæ¥åã·ã¹ãã ã«OSSãæ¡ç¨ããã¨ãããã¨ã¯ãOSSã®åºæ¬å§¿å¢ãåãå
¥ããã¨ãããã¨ã§ãã®ã§ãã¢ãããã¼ãã¨ç¡ç¸ã§ãããã¨ã¯ã§ãã¾ããã
å
容ãææ¡ãããååãªè©¦é¨ãè¡ããã«OSSãå°å
¥ãã¦ãã¾ã£ãçµæãé·æå®å®è©¦é¨ãè² è·è©¦é¨ã§ã¯çºè¦ã§ããªãä¸å
·åã«æ©ã¾ããã¦ãã¾ããããã¦ãèªåã§ããã°ã©ã ãæ¸ããã¨ãé¿ããä»äººãæ¸ãããµãã¼ã対象ã®ããã°ã©ã ãçµã¿åããã¦æ§ç¯ããçµæãå
容ããã©ãã¯ããã¯ã¹åãã¦ãèªåã§åãåããã§ããªããªãã¨ããä¸å¹¸ãèµ·ãã¦ãã¾ããããã¯ãèå¼±æ§ãªã©ç·æ¥æ§ãè¦æ±ãããéã®å¯¾å¿ã«å¦å®ã«è¡¨ãã¾ãã
æ¢åã®ããã°ã©ã ã¯ããããããªè¦æã«å¯¾å¿ãããã¨ãã¦ãã¾ãã¾ãªæ©è½ãè©°ãè¾¼ãã çµæãè¤éã«ãªããããæããããã¾ãããã®ãããå¤æ´ãå ããéã®å½±é¿ç¯å²ãè¦æ¥µããããã«ãªã°ã¬ãã·ã§ã³ãçºçããããå 容ãææ¡ãã¦ããªãããã« errata ã®é©ç¨è¦å¦ã®å¤æã«è¿·ã£ããã¨ããã®ããæ£ç´ãªç¶æ³ã§ã¯ãªããã¨æãã¾ãããããªç¶æ³ãå¤ããã«ã¯ãå¿ è¦ãªæ©è½ã ããæã¤å°ç¨ã®ããã°ã©ã ãèªåã§ä½ããã¨ãè¦éã«å ¥ãã¦ã»ããã§ããããã§ä»åã¯ãæ¢åã®ããã°ã©ã ã«é ¼ãåããªã¨ãã話ããã¾ãã
èªä½ããã°ã©ã ã®ä¾ã¨ãã¦ããµã¼ãã®æ»æ´»ç£è¦ãè¡ãããã°ã©ã ãèãã¦ã¿ã¾ããããUnix çãªèãæ¹ã«å¾ã£ãå ´åãåæ©è½ãªããã°ã©ã ãä½ã£ã¦çµã¿åãããã·ã§ã«ã¹ã¯ãªããã¨ãã¦å®ç¾ãããã¨ã«ãªãã§ãããã
---------- æ»æ´»ç£è¦ã¹ã¯ãªãã ãããã ---------- #!/bin/sh if curl -I -s http://www.example.com/ | head -n 1 | grep -qF 200 then echo "Server is alive." exit 0 else echo "Server is dead." exit 1 fi ---------- æ»æ´»ç£è¦ã¹ã¯ãªãã ããã¾ã§ ----------
次ã«ããã®æ»æ´»ç£è¦ã¹ã¯ãªããã«ã¯ã©ããªç½ ãåå¨ãã¦ããããèãã¦ã¿ã¾ãããããã®ã¹ã¯ãªããã¯ã³ãã³ãã® exit ã³ã¼ãã«åºã¥ãã¦å¤æãã¦ãã訳ã§ããããã³ãã³ãã® exit ã³ã¼ãã 0 ã§ã¯ãªããã¨ãããµã¼ãã¼ããã¦ã³ãã¦ãããã¨ãæå³ãã¦ããã¨ã¯éããªããã¨ãããã¨ã«æ³¨æãã¦ãã ãããä¾ãã°ãã¡ã¢ãªã¼ä¸è¶³ããªã½ã¼ã¹ä½¿ç¨éã®ä¸éå¶éã«å¼ã£æãã£ããã¨ãåå ã§ã curl / head / grep ãå®è¡ããããã®åããã»ã¹ã®ä½æã«å¤±æããããããã¾ããããã¦ã£ã«ã¹å¯¾çã½ããã®ã¹ãã£ã³å¦çãå®è¡ä¸ã§ãã£ãããã«ããã°ã©ã ã®èµ·åãå ±æã©ã¤ãã©ãªãã¡ã¤ã«ãªã©ã®ãªã¼ãã³ã«å¤±æããããããã¾ãããã¾ããéä¸ã®ãããã¯ã¼ã¯ããã¦ã³ãã¦ãããªã©ããµã¼ãã¼å´ã§ã¯ãªãåé¡ã«ãã£ã¦ curl ã³ãã³ããã¨ã©ã¼ã¨ãªãããããã¾ãããä»ã«ããããããªå¯è½æ§ãèãããã¾ããåé¡ãçºçããã¨åå 究æã¨åçºé²æ¢çãéè¦è¦ãããå¾åãããã¾ããããã®ã¹ã¯ãªããã¯ä½ã®æ å ±ãè¨é²ã«æ®ãã¦ãããªãããããã©ããã¦ç¨¼åä¸ã®ãµã¼ãã¼ããã¦ã³ãã¦ããã¨å¤æããã¦ãã¾ã£ãã®ï¼ãã¨è³ªåããã¦ããæºè¶³ãªåçããããã¨ãã§ããªãã®ã§ãã
exit ã³ã¼ãã§ä¼éã§ããæ å ±ã¯ãä½ããã®åé¡äºè±¡ãçºçãããã©ããç¨åº¦ã§ããããããå©ç¨ããå´ãåé¡ã ã¨èããæ¡ä»¶ã¨ãããã°ã©ã ã 0 以å¤ã® exit ã³ã¼ããè¨å®ããæ¡ä»¶ã¨ãåè´ãã¦ããã¨ãéãã¾ããã exit ã³ã¼ãé ¼ã¿ã®ã·ã§ã«ã¹ã¯ãªããã§ã¯ã¨ã©ã¼ãã³ããªã³ã°ãå°é£ã§ããããã§ãCè¨èªã®ããã°ã©ã ã«ç½®ãæããå ´åãèãã¦ã¿ã¾ãããã
---------- Cè¨èªã«ããæ»æ´»ç£è¦ããã°ã©ã ä¾ ãããã ---------- #include#include #include #include #include static in_addr_t get_addr(const char *hostname) { struct hostent *hp = gethostbyname(hostname); return *(in_addr_t *) hp->h_addr_list[0]; } int main(int argc, char *argv[]) { char buffer[8192]; char const query[] = "HEAD / HTTP/1.0\r\nHost: www.example.com\r\n\r\n"; struct sockaddr_in addr; const int fd = socket(PF_INET, SOCK_STREAM, 0); unsigned int status; addr.sin_family = AF_INET; addr.sin_addr.s_addr = get_addr("www.example.com"); addr.sin_port = htons(80); connect(fd, (struct sockaddr *) &addr, sizeof(addr)); send(fd, query, sizeof(query) - 1, 0); shutdown(fd, SHUT_WR); recv(fd, buffer, sizeof(buffer) - 1, MSG_WAITALL); close(fd); sscanf(buffer, "HTTP/%*u.%*u %u", &status); if (status == 200) { printf("Server is alive\n"); return 0; } else { printf("Server is dead\n"); return 1; } } ---------- Cè¨èªã«ããæ»æ´»ç£è¦ããã°ã©ã ä¾ ããã¾ã§ ----------
ä¸è¨ã®ããã°ã©ã ä¾ã§ã¯ãåå¼·ç®çã®ããã«æå³çã«ãã¨ã©ã¼ãã³ããªã³ã°ãçç¥ãã¦ãã¾ã (*1) ãã©ã®ãããªã¨ã©ã¼ãåé¡ãçºçãããããèããé©åã«æ¸ãç´ãã¦ã¿ã¾ãããã
Webã®ä¸çã§ã¯å ¬éAPIã使ã£ã¦èªå好ã¿ã®ã¯ã©ã¤ã¢ã³ãããã°ã©ã ãèªä½ããåããåºã¦ãã¦ãã¾ããOSã®ä¸çã ã£ã¦ãã·ã¹ãã ã³ã¼ã«ã¨ããå ¬éAPIãããã®ã ãããèªå好ã¿ã®ã·ã¹ãã ããã°ã©ã ãèªä½ããã£ã¦ããã®ã§ã¯ãªãã§ããããï¼ã¡ãã£ã¨ããã·ã¹ãã ãã¼ã«ãã¦ã¼ãã£ãªãã£ãªããCè¨èªã§ãæ°åè¡ããæ°ç¾è¡ç¨åº¦ã®è¦æ¨¡ã§ç®çãéæã§ããã¨æãã¾ããèªåã§ä½ãã°ãå¿ è¦ã¨ãã¦ããªãæ©è½ã«ããä¸å ·åããªã½ã¼ã¹æ¶è²»ã«ééãããã¨ãç¡ããªãã¾ãã®ã§ãerrata ã«æ¯ãåãããã«10å¹´é使ãç¶ããããã§ããããã·ã¹ãã ã³ã¼ã«ã使ã£ãããã°ã©ãã³ã°ãã§ãããã«ãªãã¨ãåé¡äºè±¡ã®åç¾ãã§ããããã«ãªãã¾ããããã¯ãã²ãã¦ã¯åé¡äºè±¡ãæªç¶ã«é²ããã¨ã«ãç¹ããã¨èãã¾ãã
ãµãã¼ãã»ã³ã¿ã¼ã§ã¯èªä½ããã°ã©ã ã«ã¤ãã¦ã¯ãµãã¼ããã¦ãããªããã®ã§ããããµãã¼ã対象ãå¦ãã¨ããåºæºã§å¹³è¡ç·ãç¶ãã¦ãã¦ã¯ããã¤ã¾ã§ãã®ã£ãããåãããã¾ãããé å¼µã£ã¦æåã®ä¸æ©ãè¸ã¿åºãã¦ãã ããã
- (*1) ã»ãã¥ãªãã£ãã£ã³ã2014 ã®ç§ã®ã¼ãã§ã¯ããã®ããã°ã©ã ä¾ããå®éã«ã¨ã©ã¼ãã³ããªã³ã°ãè¡ãããã°ã©ã ã«æ¹é ãããã¨ãéãã¦ãåé¡ãçºçããå ´åã«ã©ã対å¦ããã°ããããå«ãã¦è¨è¨ãè¡ããã¨ã®å¤§åããå¦ã³ããæãããã®ããããã°ã©ã ã®æ¸ãæ¹ãããç©äºãæåããæå¾ã¾ã§éãã¦èããè½åãã«ã¤ãã¦èãã¦ãããã¾ããããã¡ãããbash èå¼±æ§ ã glibc èå¼±æ§ ãçºè¦ããããããåã®ææã«ä½æãããããã°ã©ã ã§ãã®ã§ããã®ãããªèå¼±æ§ããããã¨ã¯ç¥ããªãã£ã訳ã§ãããå¿ è¦ãªæ©è½ã ããæã¤åç´æå¿«ãªããã°ã©ã ã§ããã°ãã¯ã¤ãããã¯ã¹åã§ãã¾ãã®ã§ãå½±é¿ã®æç¡ãå¤æãããã¨ãç°¡åã§ãã
ï¼åç°å²å¤«ï¼
ã³ã¼ãã¼ãã¬ã¼ã¯ãDockerã¯ä¸ããç®ç·ï¼ã
家ã®ç¨äºããã£ã¦ãä¼ã¿ãã¨ã£ã¦ããã¨ãããä¼ç¤¾ããé»è©±ãããã£ã¦ãã¦ã決è£å¦çããã¦æ¬²ããã¨é ¼ã¾ãã¾ããï¼ãã¼ãã£ã¼ã®æ³åçºåã§ãï¼ã決è£ãããããã«ã¯ãä¼ç¤¾ã®ã·ã¹ãã ã«ãã°ã¤ã³ããªããã°ãªãã¾ãããã§ãã大ä¸å¤«ã24æéåãèªå® è¦åå¡ããããªãã¦ç®¡çè·ã¯ãã¡ããã¨ãã®ããã®ç°å¢ãç¨æãã¦ãã¾ããVMwareãèµ·åããä»®æ³ãã·ã³ãç«ã¡ä¸ãã¾ããããä¼ç¤¾ã®ã·ã¹ãã ã«æ¥ç¶ãããã¨ããã¨ãé©ç¨ããã¦ããªãWindowsã®ã»ãã¥ãªãã£ãããã®é·ããªã¹ãã表示ãããåºç´ãã¦ããã¨æããã¾ãããä»æ¹ãªãã®ã§ãWindows Updateãè¡ããè¨ããããã¾ã¾åèµ·åãç¹°ãè¿ããã¨ãæ°ååããã£ã¨çµãã£ãã¨æã£ãããã¢ã³ãã¦ã¤ã«ã¹ãWindowsãã¡ã¤ã¢ã¦ã©ã¼ã«ãJava, Adobe flashçã ãå¤ããããã¨æããã¾ããããããããã¯ãã£ã¨ç¡å¿ã®å¢å°ãå¦ã¹ã¨è¨ããã¦ããã®ã ãªãã¨æããæ´æ°ãã·ã³ã¨åãã¦ä½æ¥ãã¦ãã¾ããããä½ãæªãã£ãã®ãéä¸ã§ä»®æ³ãã·ã³ãèµ·åã§ããªããªã£ã¦ãã¾ãã¾ãããä½åº¦ãªãã©ã¤ãã¦ã¿ã¦ãèµ·åãã¾ãããçµå±ããããã¦ä¼ç¤¾ã«é»è©±ãã¦ãä»ã®äººã«ä»£è¡ããé¡ããã¾ãããèªè ã®æ¹ã§ããåããããªçµé¨ããããæ¹ã¯å¤ãã®ã§ã¯ãªãã§ããããï¼
å®éã«è¡ãããã£ã決è£å¦çã¯ãããåç´ã§ãããæ¥ç¶ããã§ãã¦ããã°æ°åãããã°çµäºããå
容ã§ãããããããã®åæã¨ãªããç°å¢ãã®ãã§ãã¯ãè¤éï¼ããªã±ã¼ãï¼ã§ããããã«ãã®ãããªãã¨ãèµ·ããã¾ããç°å¢ã®ãã§ãã¯ã«æéããããã®ã¯ãè¦ããã«ãç°å¢ãã®å
容ãè¤éã§ããããã«ä»ãªãã¾ãããä»åã®ã±ã¼ã¹ã§è¨ãã°ãå
·ä½çã«ã¯ãä»®æ³ãã·ã³ãã¼ãã¦ã§ã¢ãããã«ã¤ã³ã¹ãã¼ã«ãããOSããã³é©ç¨ããã¦ããã»ãã¥ãªãã£ãããããã®OSä¸ã«ã¤ã³ã¹ãã¼ã«ããããã©ã¦ã¶ãå種ããã°ã©ã ãJava, ActiveXãã¢ã³ãã¦ã¤ã«ã¹çã
ã§ãã
ããããç°å¢ã®ç¶æã¯ããªãã£ã¹ã§ä½¿ã£ã¦ãããã¹ã¯ãããã§ãå¿
è¦ã§ãããå®æ½ãã¦ããããã§ãããæ¯æ¥ä½¿ã£ã¦ããã¨ç®ç«ããªããã®ããæ°ã¶æã«ä¸åº¦ã®ããã«ãªãã¨é¡å¨åãã¾ããç°å¢ç¶æã®ã³ã¹ãã¯æ§æè¦ç´ ã®ãæ´æ°ãã®æéã ãã§ã¯ããã¾ãããä»®æ³ãã·ã³ã®ãç°å¢ãã¯ãVMwareãå®è¡ãã¦ãã端æ«ä¸ã§ã¯ãæ°10GBã®å®¹éã使ç¨ãã¦ãã¾ããèµ·åããªããªã£ãã¨ãã®ããã«ãæ°è»½ã«ããã¯ã¢ãããã¨ãããã«ãããã¾ããã
ãç°å¢ãç¶æã«é¢ããã³ã¹ãã¯ã対象ã¨ãªãç°å¢ã大ãããã§è¤éã§ããã»ã©å¢å¤§ãã¾ãããã®æå³ã§ããç°å¢ãã¯å°ããåç´ãªã»ããæã¾ããããã§ãããä»®æ³ãã·ã³ãã¯ããä»®æ³ãã¼ãã¦ã§ã¢ãã¨ããã¨ããããé ã«ãOSãã¢ããªã±ã¼ã·ã§ã³ãªã©ãç©ã¿éãããã®ã¨è¦ããã¨ãã§ãã¾ããããã§ãçºæ³ãå¤ãã¦ãä¸ããçºãã¦ã¿ã¦ããã¨ã©ããªãã§ããããï¼å®è¡ããããã®ã¨ãã¦ã¢ããªã±ã¼ã·ã§ã³ã«æ³¨ç®ãããã®ã¢ããªã±ã¼ã·ã§ã³ãåä½ããããã«å¿ è¦ãªãã®ãé£æºãã¦åãä»ã®ã¢ããªã±ã¼ã·ã§ã³ã ã©ã¤ãã©ãªãè¨å®ããããã¨ããããã«è¦ã¦ããããã§ãï¼ä¾åãããã®ããããä¸ã§ã¯OSãå«ã¾ãã¾ãããããã§ã¯åãOSä¸ã¨ãããã¨ãåæã¨ãã¦è©±ãé²ãã¾ãï¼ã
使ãããã¢ããªã±ã¼ã·ã§ã³ãªãæ©è½ãåä½ããããã®ãç°å¢ããã³ã³ãã¯ããªåºã¾ãã¨ãªã£ã¦ãã¦ããããäºãã«äº¤æããããå ±æã§ãããã©ãã§ãããï¼éçºç°å¢ã§åä½ãããã®ããæ¬çªç°å¢ã§åä½ããªããã¢ããªã±ã¼ã·ã§ã³ãã¤ã³ã¹ãã¼ã«ããããã©ãä¾åé¢ä¿ã®åé¡ã§åä½ããªãã¨ããã·ã¹ãã éçºè ã®æªå¤¢ã¯è§£æ¶ãã¾ãããããåé¡ãçºçããå ´åãããµãã¼ãã»ã³ã¿ã¼ã§ãã®ç°å¢ï¼åºã¾ãï¼ãæå ã«ç¨æãããã¨ãã§ããã°ãäºè±¡ã確èªãã¦ãåé¡è§£æ±ºã«çæã§ãã¾ããä»®æ³ãã¼ãã¦ã§ã¢ãOSãå«ã¾ãªãã®ã§å®¹éãã³ã³ãã¯ãã§ãçµç¹å ã®å±éã容æã¨ãªãã¾ããããèªç¶ã¨å ±éçãªåºç¤ãæ´çããããã¨ã«ãªãããããã¾ããã
ãããã¦ç°å¢ãæµéããããã«ãªãã°ãç°å¢ï¼åºã¾ãï¼ãã¨ã«ãã¼ã¸ã§ã³ãä»ä¸ããã¦ããã¨ä¾¿å©ã§ããããã«ãDBMSã主è¦ãªã¢ããªã±ã¼ã·ã§ã³ã«ã¤ãã¦ã¯ãã®éçºä¸»ä½ããã墨ä»ãã®ç°å¢ãå ¬éããã¦ããã°ãããããèªåã§æ©ããã¨ãããã¾ãããã·ã¹ãã æ§ç¯ã¯ããã¤ã³ã¹ãã¼ã«ãã¦ãè¨å®ãä½ãã試é¨ãããããããªãã£ã·ã£ã«ãªé¨åãä¸å¿ã«çµã¿åããã¦ã調æ´ãããã«ãªãã¾ãã
Dockerã«ã¤ãã¦ãç§ã¯ãããªãµãã«ä¸ããç®ç·ã§ï¼ç¬ï¼è¦ã¦ãã¾ãã
ï¼åç°å£æ ï¼
Tweet