*ãã®èšäºã¯ããããªãèŠãŠå¥œããªãã°ãããªãã¯ãã®ãªã³ã¯ã§ãããèŠã€ããããšãã§ããããªãŒãã³ã¯ãŒã¯ã·ã§ããREBRAINïŒYandex.Cloudã«åºã¥ããŠæžãããŠãã- https://youtu.be/cZLezUm0ekE
æè¿ã§ã¯ãã©ã€ãYandex.Cloudã«è§Šããæ©äŒããããŸãããé·ããã£ãããšæãããã£ãã®ã§ãã¯ã©ãŠãããŒã¹ã®ã·ã³ãã«ãªã¯ãŒããã¬ã¹ããã°ãç«ã¡äžãããšããã¢ã€ãã¢ãããã«æ念ããŸãã-ããã¯éå±ãããŸããããã€ãã®æ€èšã®çµæãã»ãŒãªã¢ã«ã¿ã€ã ã¢ãŒãã§ã€ãã³ããåä¿¡ããŠââåæããããã«ããµãŒãã¹ã®æ¬çªã¢ãŒããã¯ãã£ã«äŒŒããã®ãå±éããããšã«ããŸããã
ãªã³ã©ã€ã³ïŒã ãã§ãªãïŒããžãã¹ã®å€§å€æ°ã¯ãäœããã®åœ¢ã§ãŠãŒã¶ãŒãšãã®è¡åã«é¢ããèšå€§ãªæ å ±ãåéããŠãããšç¢ºä¿¡ããŠããŸããå°ãªããšããããã¯ç¹å®ã®æ±ºå®ãè¡ãããã«å¿ èŠã§ãïŒããšãã°ããªã³ã©ã€ã³ã²ãŒã ã管çããŠããå ŽåïŒããŠãŒã¶ãŒãè¡ãè©°ãŸããããã¡ããåé€ããå¯èœæ§ãæãé«ãã¬ãã«ã®çµ±èšã確èªã§ããŸãããŸãã¯ããŠãŒã¶ãŒãäœãè³Œå ¥ããã«ãµã€ããé¢ããçç±ïŒããã«ã¡ã¯ãYandex.MetricaïŒã
ã€ãŸããç§ãã¡ã®ã¹ããŒãªãŒã¯ãgolangã§ã¢ããªã±ãŒã·ã§ã³ãäœæããkafkaãšrabbitmqãšyqsããã¹ãããClickhouseã¯ã©ã¹ã¿ãŒã«ããŒã¿ã¹ããªãŒãã³ã°ãäœæããyandexdatalensã䜿çšããŠããŒã¿ãèŠèŠåããæ¹æ³ã§ããåœç¶ã®ããšãªãããããããã¹ãŠã¯ãdockerãterraformãgitlab ciããããŠãã¡ãããprometheusã®åœ¢ã§ã€ã³ãã©ã¹ãã©ã¯ãã£ã®åã³ã§åºæ¿ãããŸãããè¡ããïŒ
äžåºŠã«ãã¹ãŠãæ§æããããšã¯ã§ããªãã®ã§ãããã«äºçŽããããšæããŸãããã®ãããã·ãªãŒãºã®ããã€ãã®èšäºãå¿ èŠã§ããæ§é ã«ã€ããŠå°ãïŒ
ããŒã1ïŒããªãã¯ãããèªãã§ããŸãïŒããœãªã¥ãŒã·ã§ã³ã®æè¡ä»æ§ãšã¢ãŒããã¯ãã£ãå®çŸ©ããgolangã§ã¢ããªã±ãŒã·ã§ã³ãäœæããŸãã
ããŒã2ãã¢ããªã±ãŒã·ã§ã³ãæ¬çªç°å¢ã«ãªãªãŒã¹ããã¹ã±ãŒã©ãã«ã«ããŠè² è·ããã¹ãããŸãã
ããŒã3ãã¡ãã»ãŒãžããã¡ã€ã«ã§ã¯ãªããããã¡ã«ä¿åããå¿ èŠãããçç±ãç解ããkafkaãrabbitmqãããã³yandexãã¥ãŒãµãŒãã¹ãæ¯èŒããŠã¿ãŸãããã
ããŒã4ãClickhouseã¯ã©ã¹ã¿ãŒãå±éããããã®ãããã¡ãŒããããŒã¿ã転éããã¹ããªãŒãã³ã°ãäœæããããŒã¿ã¬ã³ãºã§èŠèŠåãèšå®ããŸãã
ããŒã5ãã€ã³ãã©ã¹ãã©ã¯ãã£å šäœãé©åãªåœ¢åŒã«ããŸããããgitlabciã䜿çšããŠci / cdãæ§æããprometheusãšconsulã䜿çšããŠç£èŠãšãµãŒãã¹æ€åºãæ¥ç¶ããŸãã
TK
æåã«ãåç §æ¡ä»¶ãã€ãŸãåºåã§æ£ç¢ºã«ååŸããããã®ãå®åŒåããŸãã
- HTTPSã䜿çšããŠã€ãã³ããåãå ¥ããå¿ èŠãããevents.kis.imïŒkis.imã¯ãã¹ãŠã®èšäºã§äœ¿çšãããã¹ããã¡ã€ã³ïŒã®åœ¢åŒã®ãšã³ããã€ã³ããå¿ èŠã§ãã
- ã€ãã³ãã¯ã{"event"ïŒ "view"ã "os"ïŒ "linux"ã "browser"ïŒ "chrome"}ã®ãããªåçŽãªjsonã§ããæçµæ®µéã§ã¯ãããå°ããã£ãŒã«ããè¿œå ããŸãããããã¯å€§ããªåœ¹å²ã«ã¯ãªããŸãããå¿ èŠã«å¿ããŠãprotobufã«åãæ¿ããããšãã§ããŸãã
- ãµãŒãã¹ã¯ã1ç§ããã10,000ã€ãã³ããåŠçã§ããå¿ èŠããããŸãã
- ãœãªã¥ãŒã·ã§ã³ã«æ°ããã€ã³ã¹ã¿ã³ã¹ãè¿œå ããã ãã§ãæ°Žå¹³æ¹åã«æ¡åŒµã§ããã¯ãã§ãããŸããããã³ãããŒããå¥ã®ãžãªãã±ãŒã·ã§ã³ã«ç§»åããŠãã¯ã©ã€ã¢ã³ããªã¯ãšã¹ãã®åŸ ã¡æéãççž®ã§ãããšäŸ¿å©ã§ãã
- èé害æ§ã溶液ã¯ååã«å®å®ããŠããŠãéšåãèœäžããŠãçãæ®ãããšãã§ããªããã°ãªããŸããïŒãã¡ãããç¹å®ã®éãŸã§ïŒã
建ç¯
äžè¬ã«ããã®çš®ã®ã¿ã¹ã¯ã§ã¯ãå¹æçã«ã¹ã±ãŒãªã³ã°ã§ããå€å žçãªã¢ãŒããã¯ãã£ãé·ãéçºæãããŠããŸããããã®å³ã¯ããœãªã¥ãŒã·ã§ã³ã®äŸã瀺ããŠããŸãã
ã€ãŸãã次ã®ããã«ãªããŸã
ã1ãå·ŠåŽã«ã¯ãã¹ããŒããã©ã³ã§ããã¡ãã®ãã¬ãŒã€ãŒã®ã¬ãã«ãè¶ ããããéåžžã®ãã©ãŠã¶ãŒãä»ããŠãªã³ã©ã€ã³ã¹ãã¢ã§æ³šæãäœæããããããããŸããŸãªã€ãã³ããçæããããã€ã¹ã衚瀺ãããŸããTORã«ç€ºãããŠããããã«ãã€ãã³ãã¯ãšã³ããã€ã³ãã§ããevents.kis.imã«éä¿¡ãããåçŽãªjsonã§ãã
2.æåã®2ã€ã®ãµãŒããŒã¯åçŽãªãã©ã³ãµãŒã§ãããäž»ãªã¿ã¹ã¯ã¯æ¬¡ã®ãšããã§ãã
- . , , keepalived, IP .
- TLS. , TLS . -, , -, , backend .
- backend . â . , , load balancerâ .
3.ãã©ã³ãµãŒã®èåŸã«ã¯ãããªãåçŽãªã¢ããªã±ãŒã·ã§ã³ãå®è¡ããŠããã¢ããªã±ãŒã·ã§ã³ãµãŒããŒããããŸããçä¿¡HTTPèŠæ±ãåãå ¥ããéä¿¡ãããjsonãæ€èšŒããããŒã¿ããããã¡ãŒã«ä¿ç®¡ã§ããå¿ èŠããããŸãã
4.ãã®å³ã¯ãkafkaããããã¡ãŒãšããŠç€ºããŠããŸããããã¡ãããä»ã®åæ§ã®ãµãŒãã¹ããã®ã¬ãã«ã§äœ¿çšã§ããŸãã 3çªç®ã®èšäºã§ã¯ãKafkaãrabbitmqãyqsãæ¯èŒããŸãã
5.ã¢ãŒããã¯ãã£ã®æåŸãã2çªç®ã®ãã€ã³ãã¯Clickhouseã§ããããã¯ã倧éã®ããŒã¿ãä¿åããã³åŠçã§ããåããŒã¿ããŒã¹ã§ãããã®ã¬ãã«ã§ã¯ããããã¡ããå®éã«ã¯ã¹ãã¬ãŒãžã·ã¹ãã ã«ããŒã¿ã転éããå¿ èŠããããŸãïŒããã«ã€ããŠã¯èšäº4ã§è©³ãã説æããŸãïŒã
ãã®é 眮ã«ãããåã¬ã€ã€ãŒãæ°Žå¹³æ¹åã«åå¥ã«ã¹ã±ãŒãªã³ã°ã§ããŸããããã¯ãšã³ããµãŒããŒã¯ã¹ããŒãã¬ã¹ã¢ããªã±ãŒã·ã§ã³ã§ããããã察å¿ããŸããïŒããã«è¿œå ããŸãããïŒããããã£ãŠãããã¯èªåã¢ãŒãã§ãå®è¡ã§ããŸãã kafkaã®åœ¢åŒã§ãããã¡ããã«ããããšã¯ãããŸããããµãŒããŒãè¿œå ãããããã¯ã®ããŒãã£ã·ã§ã³ã®äžéšããããã«è»¢éããŸããã¯ãªãã¯ããŠã¹ã¯å€±æããŸã-ããã¯äžå¯èœã§ã:)å®éããµãŒããŒãåé€ããŠããŒã¿ãå ±æããŸãã
ã¡ãªã¿ã«ãæè¡ä»æ§ã®ãªãã·ã§ã³éšåãå®è£ ããããŸããŸãªå°ççäœçœ®ã§ã¹ã±ãŒãªã³ã°ãè¡ãããå Žåã¯ããã以äžç°¡åãªããšã¯ãããŸããã
åãžãªãã±ãŒã·ã§ã³ã§ãã¢ããªã±ãŒã·ã§ã³ãškafkaãåããããŒããã©ã³ãµãŒãå±éããŸããäžè¬ã«ã2ã€ã®ã¢ããªã±ãŒã·ã§ã³ãµãŒããŒã3ã€ã®kafkaããŒããããã³ã¯ã©ãŠããã¬ã¢ãªã©ã®ã¯ã©ãŠããã©ã³ãµãŒã§ååã§ããããã«ãããã¢ããªã±ãŒã·ã§ã³ããŒãã®å¯çšæ§ããã§ãã¯ãããã¯ã©ã€ã¢ã³ãã®å ã®IPã¢ãã¬ã¹ã«åºã¥ããŠãžãªãã±ãŒã·ã§ã³ããšã«èŠæ±ã®ãã©ã³ã¹ãåãããŸãããããã£ãŠãã¢ã¡ãªã«ã®ã¯ã©ã€ã¢ã³ãã«ãã£ãŠéä¿¡ãããããŒã¿ã¯ãã¢ã¡ãªã«ã®ãµãŒããŒã«éãããŸãããããŠã¢ããªã«ããã®ããŒã¿-ã¢ããªã«ã«ã€ããŠã
次ã«ããã¹ãŠãéåžžã«ç°¡åã§ããkafkaã»ããã®ãã©ãŒããŒã«ã䜿çšããŠããã¹ãŠã®å Žæãããã·ã¢ã«ããäžå€®ããŒã¿ã»ã³ã¿ãŒã«ãã¹ãŠã®ããŒã¿ãã³ããŒããŸããå éšã§ã¯ãããŒã¿ã解æããåŸã§èŠèŠåããããã«Clickhouseã«æžã蟌ã¿ãŸãã
ããã§ãã¢ãŒããã¯ãã£ãç解ããŸãã-Yandex.Cloudãæ¯ã£ãŠã¿ãŸãããïŒ
ã¢ããªã±ãŒã·ã§ã³ãæžã
ã¯ã©ãŠãã®åã«ãããªãã¯ãŸã å°ãèããŠãå ¥ã£ãŠããã€ãã³ããåŠçããããã®ããªãåçŽãªãµãŒãã¹ãæžããªããã°ãªããŸããã golangã¯ããããã¯ãŒã¯ã¢ããªã±ãŒã·ã§ã³ãäœæããããã®èšèªãšããŠéåžžã«åªããŠããããšã蚌æãããŠãããããããã§äœ¿çšããŸãã
1æéïŒããããæ°æéïŒãè²»ãããåŸã次ã®ãããªãã®ãåŸãããŸãïŒhttpsïŒ//github.com/RebrainMe/yandex-cloud-events/blob/master/app/main.goã
ããã§æ³šæãããäž»ãªãã€ã³ãã¯äœã§ãã
ã1ãã¢ããªã±ãŒã·ã§ã³ãèµ·åãããšãã«ã2ã€ã®ãã©ã°ãæå®ã§ããŸãã 1ã€ã¯ãçä¿¡httpèŠæ±ããªãã¹ã³ããããŒãïŒ-addrïŒãæ åœããŸãã 2ã€ç®ã¯ãã€ãã³ããèšé²ããkafkaãµãŒããŒã®ã¢ãã¬ã¹ïŒ-kafkaïŒã§ãã
addr = flag.String("addr", ":8080", "TCP address to listen to")
kafka = flag.String("kafka", "127.0.0.1:9092", "Kafka endpointsâ)
2.ã¢ããªã±ãŒã·ã§ã³ã¯ããµã©ãã©ã€ãã©ãªïŒ[] github.com/Shopify/saramaïŒã䜿çšããŠãkafkaã¯ã©ã¹ã¿ãŒã«ã¡ãã»ãŒãžãéä¿¡ããŸããæ倧åŠçé床ã«çŠç¹ãåãããèšå®ãããã«èšå®ããŸãã
config := sarama.NewConfig()
config.Producer.RequiredAcks = sarama.WaitForLocal
config.Producer.Compression = sarama.CompressionSnappy
config.Producer.Return.Successes = true
3.ãŸãããã®ã¢ããªã±ãŒã·ã§ã³ã«ã¯ã次ã®ãããªããŸããŸãªã¡ããªãã¯ãåéããããã¡ããŠã¹ã¯ã©ã€ã¢ã³ããçµã¿èŸŒãŸããŠããŸãã
- ã¢ããªã±ãŒã·ã§ã³ãžã®ãªã¯ãšã¹ãã®æ°ã
- ãªã¯ãšã¹ãå®è¡äžã®ãšã©ãŒæ°ïŒãã¹ããªã¯ãšã¹ããèªã¿åãããšãã§ããªããjsonãå£ããŠãããkafkaã«æžã蟌ãããšãã§ããªãïŒ
- kafkaãžã®ã¡ãã»ãŒãžã®æžã蟌ã¿æéãå«ããã¯ã©ã€ã¢ã³ãããã®1ã€ã®èŠæ±ã®åŠçæéã
4.ã¢ããªã±ãŒã·ã§ã³ãåŠçãã3ã€ã®ãšã³ããã€ã³ãïŒ
- / status-okãè¿ãã ãã§ãç§ãã¡ãçããŠããããšã瀺ããŸããkafkaã¯ã©ã¹ã¿ãŒã®å¯çšæ§ãªã©ãããã€ãã®ãã§ãã¯ãè¿œå ã§ããŸããã
- /ã¡ããªãã¯-ãã®URLã«ãããšãprometheusã¯ã©ã€ã¢ã³ãã¯åéããã¡ããªãã¯ãè¿ããŸãã
- /post â endpoint, POST json . json â -.
ã³ãŒããå®å šã§ã¯ãªãããšãäºçŽããŸã-å®äºããããšãã§ããŸãïŒãããŠãããã¹ãã§ãïŒïŒãããšãã°ãçµã¿èŸŒã¿ã®net / httpã®äœ¿çšãåæ¢ããŠãããé«éãªfasthttpã«åãæ¿ããããšãã§ããŸãããŸãã¯ãjsonæ€èšŒãã§ãã¯ãåŸã®æ®µéïŒããŒã¿ããããã¡ãŒããã¯ãªãã¯ããŠã¹ã¯ã©ã¹ã¿ãŒã«è»¢éããããšãïŒã«å®è¡ããããšã§ãåŠçæéãšcpuãªãœãŒã¹ãååŸã§ããŸãã
åé¡ã®éçºåŽã«å ããŠãç§ãã¡ã¯ããã«å°æ¥ã®ã€ã³ãã©ã¹ãã©ã¯ãã£ã«ã€ããŠèããdockerãä»ããŠã¢ããªã±ãŒã·ã§ã³ãå±éããããšã«ããŸãããã¢ããªã±ãŒã·ã§ã³ãæ§ç¯ããããã®æçµçãªDockerfileã¯ãhttpsïŒ//github.com/RebrainMe/yandex-cloud-events/blob/master/app/Dockerfileã§ããäžè¬çã«ãããã¯éåžžã«åçŽã§ããç§ã泚ç®ãããå¯äžã®ãã€ã³ãã¯ãã³ã³ããã®æçµçãªã€ã¡ãŒãžãçž®å°ã§ããå€æ®µã¢ã»ã³ããªã§ãã
ã¯ã©ãŠãã®æåã®ã¹ããã
ãŸããcloud.yandex.ruã«ç»é²ããŸãããã¹ãŠã®å¿ é ãã£ãŒã«ãã«å ¥åããåŸãã¢ã«ãŠã³ããäœæããã¯ã©ãŠããµãŒãã¹ã®ãã¹ãã«äœ¿çšã§ããäžå®ã®éé¡ãä»äžããŸããç§ãã¡ã®èšäºã®ãã¹ãŠã®ã¹ããããç¹°ãè¿ãããå Žåã¯ããã®å©æéã§ååã§ãã
ç»é²åŸãå¥ã®ã¯ã©ãŠããšããã©ã«ãã®ãã£ã¬ã¯ããªãäœæãããã¯ã©ãŠããªãœãŒã¹ã®äœæãéå§ã§ããŸããäžè¬ã«ãYandex.Cloudã§ã¯ããªãœãŒã¹éã®é¢ä¿ã¯æ¬¡ã®ãšãã
ã§ãã1ã€ã®ã¢ã«ãŠã³ãã«è€æ°ã®ã¯ã©ãŠããäœæã§ããŸãããããŠãã¯ã©ãŠãå ã§ãäŒç€Ÿã®ãããžã§ã¯ãããšã«ç°ãªããã£ã¬ã¯ããªãäœæããŸããããã«ã€ããŠè©³ããã¯ãããã¥ã¡ã³ããã芧ãã ãã-httpsïŒ//cloud.yandex.ru/docs/resource-manager/concepts/resources-hierarchy..ãã¡ãªã¿ã«ã以äžã®æ¬æã§ã¯ããåç §ããŸããã€ã³ãã©ã¹ãã©ã¯ãã£å šäœãæåããã»ããã¢ãããããšããããã¥ã¡ã³ãã¯äœåºŠã圹ã«ç«ã¡ãŸããã®ã§ãå匷ããããšããå§ãããŸãã
ã¯ã©ãŠãã管çããã«ã¯ãWebã€ã³ã¿ãŒãã§ã€ã¹ãšã³ã³ãœãŒã«ãŠãŒãã£ãªãã£ã®äž¡æ¹ã䜿çšã§ããŸã-ycãã€ã³ã¹ããŒã«ã¯1ã€ã®ã³ãã³ãã§å®è¡ãããŸãïŒLinuxããã³Mac Osã®å ŽåïŒã
curl https://storage.yandexcloud.net/yandexcloud-yc/install.sh | bash
å éšã®ã»ãã¥ãªãã£æ åœè ãã€ã³ã¿ãŒãããããã®ã¹ã¯ãªããã®å®è¡ã«ã€ããŠæ¿æããŠããå Žåã¯ããŸããã¹ã¯ãªãããéããŠèªã¿åãããšãã§ããŸãã次ã«ãrootæš©éãªãã§ããŠãŒã¶ãŒã®äžã§ã¹ã¯ãªãããå®è¡ããŸãã
Windowsçšã®ã¯ã©ã€ã¢ã³ããã€ã³ã¹ããŒã«ããå Žåã¯ãããã®æé ã䜿çšããŠã次ã®æé ã«åŸã£ãŠ
yc init
å®å
šã«æ§æã§ããŸãã
vozerov@mba:~ $ yc init
Welcome! This command will take you through the configuration process.
Please go to https://oauth.yandex.ru/authorize?response_type=token&client_id= in order to obtain OAuth token.
Please enter OAuth token:
Please select cloud to use:
[1] cloud-b1gv67ihgfu3bp (id = b1gv67ihgfu3bpt24o0q)
[2] fevlake-cloud (id = b1g6bvup3toribomnh30)
Please enter your numeric choice: 2
Your current cloud has been set to 'fevlake-cloud' (id = b1g6bvup3toribomnh30).
Please choose folder to use:
[1] default (id = b1g5r6h11knotfr8vjp7)
[2] Create a new folder
Please enter your numeric choice: 1
Your current folder has been set to 'default' (id = b1g5r6h11knotfr8vjp7).
Do you want to configure a default Compute zone? [Y/n]
Which zone do you want to use as a profile default?
[1] ru-central1-a
[2] ru-central1-b
[3] ru-central1-c
[4] Don't set default zone
Please enter your numeric choice: 1
Your profile default Compute zone has been set to 'ru-central1-a'.
vozerov@mba:~ $
ååãšããŠãããã»ã¹ã¯åçŽã§ããæåã«ãã¯ã©ãŠã管ççšã®oauthããŒã¯ã³ãååŸãã䜿çšããã¯ã©ãŠããšãã©ã«ããŒãéžæããå¿ èŠããããŸãã
åãã¯ã©ãŠãå ã«è€æ°ã®ã¢ã«ãŠã³ããŸãã¯ãã©ã«ããŒãããå Žåã¯ãyc config profile createã䜿çšããŠåå¥ã®èšå®ã§è¿œå ã®ãããã¡ã€ã«ãäœæããããããåãæ¿ããããšãã§ããŸãã
äžèšã®æ¹æ³ã«å ããŠãYandex.CloudããŒã ã¯ãã¯ã©ãŠããªãœãŒã¹ã管çããããã®éåžžã«åªãããã©ãã©ãŒã ãã©ã°ã€ã³ãäœæããŸãããç§ãšããŠã¯ãèšäºã®ãã¬ãŒã ã¯ãŒã¯å ã§äœæããããã¹ãŠã®ãªãœãŒã¹ã«ã€ããŠèª¬æããgitãªããžããªãæºåããŸãã-https ïŒ//github.com/rebrainme/yandex-cloud-events/ããã¹ã¿ãŒãã©ã³ãã«é¢å¿ããããŸããããŒã«ã«ã§ã¯ããŒã³ãäœæããŸãããã
vozerov@mba:~ $ git clone https://github.com/rebrainme/yandex-cloud-events/ events
Cloning into 'events'...
remote: Enumerating objects: 100, done.
remote: Counting objects: 100% (100/100), done.
remote: Compressing objects: 100% (68/68), done.
remote: Total 100 (delta 37), reused 89 (delta 26), pack-reused 0
Receiving objects: 100% (100/100), 25.65 KiB | 168.00 KiB/s, done.
Resolving deltas: 100% (37/37), done.
vozerov@mba:~ $ cd events/terraform/
terraformã§äœ¿çšããããã¹ãŠã®äž»ãªå€æ°ã¯ãmain.tfãã¡ã€ã«ã«æžã蟌ãŸããŸããéå§ããã«ã¯ã次ã®å 容ã®terraformãã©ã«ããŒã«private.auto.tfvarsãã¡ã€ã«ãäœæããŸãã
# Yandex Cloud Oauth token
yc_token = ""
# Yandex Cloud ID
yc_cloud_id = ""
# Yandex Cloud folder ID
yc_folder_id = ""
# Default Yandex Cloud Region
yc_region = "ru-central1-a"
# Cloudflare email
cf_email = ""
# Cloudflare token
cf_token = ""
# Cloudflare zone id
cf_zone_id = ""
ã³ã³ãœãŒã«ãŠãŒãã£ãªãã£ã¯ãã§ã«æ§æãããŠããããããã¹ãŠã®å€æ°ã¯ycæ§æãªã¹ãããååŸã§ããŸãã誀ã£ãŠãã©ã€ããŒãããŒã¿ãå ¬éããªãããã«ãprivate.auto.tfvarsã.gitignoreã«ããã«è¿œå ããããšããå§ãããŸãã
private.auto.tfvarsã§ã¯ãCloudflareããã®ããŒã¿ãæå®ããŸãããããã¯ãdnsã¬ã³ãŒããäœæããã¡ã€ã³ãã¡ã€ã³events.kis.imããµãŒããŒã«ãããã·ããããã®ãã®ã§ããcloudflareã䜿çšããªãå Žåã¯ãmain.tfå ã®cloudflareãããã€ããŒã®åæåãšãå¿ èŠãªdnsã¬ã³ãŒãã®äœæãæ åœããdns.tfãã¡ã€ã«ãåé€ããŸãã
ç§ãã¡ã®ä»äºã§ã¯ãWebã€ã³ã¿ãŒãã§ã€ã¹ãã³ã³ãœãŒã«ãŠãŒãã£ãªãã£ããã©ãã©ãŒã ã®3ã€ã®æ¹æ³ãã¹ãŠãçµã¿åãããŸãã
ä»®æ³ãããã¯ãŒã¯
æ£çŽãªãšããããã®æé ã¯ã¹ãããã§ããŸããæ°ããã¯ã©ãŠããäœæãããšãèªåçã«åå¥ã®ãããã¯ãŒã¯ãš3ã€ã®ãµããããïŒã¢ãã€ã©ããªãã£ãŒãŸãŒã³ããšã«1ã€ïŒãäœæãããããã§ããããã§ããç¬èªã®ã¢ãã¬ã¹æå®ã䜿çšããŠããããžã§ã¯ãçšã«å¥ã®ãããã¯ãŒã¯ãäœæããããšæããŸãã Yandex.Cloudã®ãããã¯ãŒã¯ã®äžè¬çãªã¹ããŒã ã次ã®å³ã«ç€ºããŸãïŒæ£çŽãªãšããhttps://cloud.yandex.ru/docs/vpc/concepts/ããååŸïŒ
ãããã£ãŠããªãœãŒã¹ãçžäºã«éä¿¡ã§ããå ±éã®ãããã¯ãŒã¯ãäœæããŸããã¢ãã€ã©ããªãã£ãŒãŸãŒã³ããšã«ãç¬èªã®ã¢ãã¬ã¹æå®ã§ãµãããããäœæããããããªãã¯ãããã¯ãŒã¯ã«æ¥ç¶ãããŸãããã®çµæãç°ãªãã¢ãã€ã©ããªãã£ãŒãŸãŒã³ã«ããå Žåã§ãããã®äžã®ãã¹ãŠã®ã¯ã©ãŠããªãœãŒã¹ãéä¿¡ã§ããŸããç°ãªãã¯ã©ãŠããããã¯ãŒã¯ã«æ¥ç¶ãããŠãããªãœãŒã¹ã¯ãå€éšã¢ãã¬ã¹ãä»ããŠã®ã¿çžäºã«èªèã§ããŸããã¡ãªã¿ã«ããã®éæ³ãå éšã§ã©ã®ããã«æ©èœãããã¯ãHabréã§è©³ãã説æãããŠããŸãã
ãããã¯ãŒã¯ã®äœæã¯ããªããžããªã®network.tfãã¡ã€ã«ã«èšè¿°ãããŠããŸããããã§ãå éšã«1ã€ã®å ±æãã©ã€ããŒããããã¯ãŒã¯ãäœæãã3ã€ã®ãµãããããç°ãªãã¢ãã€ã©ããªãã£ãŒãŸãŒã³ïŒinternal-aïŒ172.16.1.0/24ïŒãinternal-bïŒ172.16.2.0/24ïŒãinternal-cïŒ172.16.3.0/24ïŒïŒã«æ¥ç¶ããŸãã ïŒã
ãã©ãã©ãŒã ãåæåãããããã¯ãŒã¯ãäœæããŸãã
vozerov@mba:~/events/terraform (master) $ terraform init
... skipped ..
vozerov@mba:~/events/terraform (master) $ terraform apply -target yandex_vpc_subnet.internal-a -target yandex_vpc_subnet.internal-b -target yandex_vpc_subnet.internal-c
... skipped ...
Plan: 4 to add, 0 to change, 0 to destroy.
Do you want to perform these actions?
Terraform will perform the actions described above.
Only 'yes' will be accepted to approve.
Enter a value: yes
yandex_vpc_network.internal: Creating...
yandex_vpc_network.internal: Creation complete after 3s [id=enp2g2rhile7gbqlbrkr]
yandex_vpc_subnet.internal-a: Creating...
yandex_vpc_subnet.internal-b: Creating...
yandex_vpc_subnet.internal-c: Creating...
yandex_vpc_subnet.internal-a: Creation complete after 6s [id=e9b1dad6mgoj2v4funog]
yandex_vpc_subnet.internal-b: Creation complete after 7s [id=e2liv5i4amu52p64ac9p]
yandex_vpc_subnet.internal-c: Still creating... [10s elapsed]
yandex_vpc_subnet.internal-c: Creation complete after 10s [id=b0c2qhsj2vranoc9vhcq]
Apply complete! Resources: 4 added, 0 changed, 0 destroyed.
åªããïŒãããã¯ãŒã¯ãäœæããå éšãµãŒãã¹ãäœæããæºåãæŽããŸããã
ä»®æ³ãã·ã³ã®äœæ
ã¢ããªã±ãŒã·ã§ã³ããã¹ãããã«ã¯ã2ã€ã®ä»®æ³ãã·ã³ãäœæããã ãã§ååã§ããæåã®ä»®æ³ãã·ã³ã¯ã¢ããªã±ãŒã·ã§ã³ããã«ãããŠå®è¡ãã2çªç®ã®ä»®æ³ãã·ã³ã¯kafkaãå®è¡ããŸããããã䜿çšããŠãçä¿¡ã¡ãã»ãŒãžãä¿åããŸãããããŠãã¢ããªã±ãŒã·ã§ã³ãç£èŠããããã«prometheusãæ§æããå¥ã®ãã·ã³ãäœæããŸãã
ä»®æ³ãã·ã³ã¯ansibleã䜿çšããŠæ§æããããããterraformãéå§ããåã«ãææ°ã®ansibleããŒãžã§ã³ã®ããããã䜿çšããŠããããšã確èªããŠãã ããããããŠãansiblegalaxyã§å¿ èŠãªåœ¹å²ãã€ã³ã¹ããŒã«ããŸãã
vozerov@mba:~/events/terraform (master) $ cd ../ansible/
vozerov@mba:~/events/ansible (master) $ ansible-galaxy install -r requirements.yml
- cloudalchemy-prometheus (master) is already installed, skipping.
- cloudalchemy-grafana (master) is already installed, skipping.
- sansible.kafka (master) is already installed, skipping.
- sansible.zookeeper (master) is already installed, skipping.
- geerlingguy.docker (master) is already installed, skipping.
vozerov@mba:~/events/ansible (master) $
ansibleãã©ã«ããŒå ã«ã¯ãç§ã䜿çšããŠãããµã³ãã«ã®.ansible.cfgæ§æãã¡ã€ã«ããããŸãããããã䟿å©ã§ãã
ä»®æ³ãã·ã³ãäœæããåã«ãssh-agentãå®è¡ãããsshããŒãè¿œå ãããŠããããšã確èªããŠãã ãããè¿œå ãããŠããªãå Žåãterraformã¯äœæããããã·ã³ã«æ¥ç¶ã§ããŸããããã¡ãããos xã§ãã°ã«ééããŸããïŒhttpsïŒ//github.com/ansible/ansible/issues/32499#issuecomment-341578864ããã®è©±ãç¹°ãè¿ããªãããã«ããã«ã¯ãTerraformãèµ·åããåã«envã«å°ããªå€æ°ãè¿œå ããŸãã
vozerov@mba:~/events/terraform (master) $ export OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES
terraformãã©ã«ããŒã«å¿ èŠãªãªãœãŒã¹ãäœæããŸãã
vozerov@mba:~/events/terraform (master) $ terraform apply -target yandex_compute_instance.build -target yandex_compute_instance.monitoring -target yandex_compute_instance.kafka
yandex_vpc_network.internal: Refreshing state... [id=enp2g2rhile7gbqlbrkr]
data.yandex_compute_image.ubuntu_image: Refreshing state...
yandex_vpc_subnet.internal-a: Refreshing state... [id=e9b1dad6mgoj2v4funog]
An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
+ create
... skipped ...
Plan: 3 to add, 0 to change, 0 to destroy.
... skipped ...
ãã¹ãŠãããŸãçµäºããå ŽåïŒãããŠããããã¹ãã§ãïŒã3ã€ã®ä»®æ³ãã·ã³ããããŸãïŒ
- build-ã¢ããªã±ãŒã·ã§ã³ããã¹ãããã³æ§ç¯ããããã®ãã·ã³ãDockerã¯ansibleã«ãã£ãŠèªåçã«ã€ã³ã¹ããŒã«ãããŸããã
- ã¢ãã¿ãªã³ã°-ã¢ãã¿ãªã³ã°çšã®ãã·ã³-prometheusïŒgrafanaãã€ã³ã¹ããŒã«ãããŠããŸãããã°ã€ã³/ãã¹ã¯ãŒããæšæºã§ãïŒadmin / admin
- kafkaã¯ãkafkaãã€ã³ã¹ããŒã«ãããå°åè»ã§ãããŒã9092ã§å©çšã§ããŸãã
ãããããã¹ãŠæå®ã®äœçœ®ã«ããããšã確èªããŸãããïŒ
vozerov@mba:~/events (master) $ yc compute instance list
+----------------------+------------+---------------+---------+---------------+-------------+
| ID | NAME | ZONE ID | STATUS | EXTERNAL IP | INTERNAL IP |
+----------------------+------------+---------------+---------+---------------+-------------+
| fhm081u8bkbqf1pa5kgj | monitoring | ru-central1-a | RUNNING | 84.201.159.71 | 172.16.1.35 |
| fhmf37k03oobgu9jmd7p | kafka | ru-central1-a | RUNNING | 84.201.173.41 | 172.16.1.31 |
| fhmt9pl1i8sf7ga6flgp | build | ru-central1-a | RUNNING | 84.201.132.3 | 172.16.1.26 |
+----------------------+------------+---------------+---------+---------------+-------------+
ãªãœãŒã¹ãé 眮ãããŠãããããããIPã¢ãã¬ã¹ãååŸã§ããŸãã以äžã§ã¯ãipã¢ãã¬ã¹ã䜿çšããŠsshçµç±ã§æ¥ç¶ããã¢ããªã±ãŒã·ã§ã³ããã¹ãããŸããterraformã«æ¥ç¶ãããcloudflareã¢ã«ãŠã³ãããæã¡ã®å Žåã¯ãæ°ããäœæãããDNSåãèªç±ã«äœ¿çšããŠãã ããã
ã¡ãªã¿ã«ãä»®æ³ãã·ã³ãäœæãããšãå éšIPãšå éšDNSåãçºè¡ãããããããããã¯ãŒã¯å ã®ãµãŒããŒãååã§åç §ã§ããŸãã
ubuntu@build:~$ ping kafka.ru-central1.internal
PING kafka.ru-central1.internal (172.16.1.31) 56(84) bytes of data.
64 bytes from kafka.ru-central1.internal (172.16.1.31): icmp_seq=1 ttl=63 time=1.23 ms
64 bytes from kafka.ru-central1.internal (172.16.1.31): icmp_seq=2 ttl=63 time=0.625 ms
^C
--- kafka.ru-central1.internal ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1001ms
rtt min/avg/max/mdev = 0.625/0.931/1.238/0.308 ms
ããã¯ãkafkã䜿çšããŠãšã³ããã€ã³ããã¢ããªã±ãŒã·ã§ã³ã«ç€ºãã®ã«åœ¹ç«ã¡ãŸãã
ã¢ããªã±ãŒã·ã§ã³ããŸãšãã
çŽ æŽãããããµãŒããŒããããã¢ããªã±ãŒã·ã§ã³ããããŸã-æ®ã£ãŠããã®ã¯ãããåéããŠå ¬éããããšã ãã§ããã¢ã»ã³ããªã«ã¯ãéåžžã®dockerãã«ãã䜿çšããŸãããã€ã¡ãŒãžã®ãªããžããªãšããŠãYandexïŒã³ã³ããã¬ãžã¹ããªïŒãããµãŒãã¹ãååŸããŸãããããããŸãæåã«ã
ã¢ããªã±ãŒã·ã§ã³ããã«ããã·ã³ã«ã³ããŒããsshã«ç§»åããŠãã€ã¡ãŒãžãåéããŸãã
vozerov@mba:~/events/terraform (master) $ cd ..
vozerov@mba:~/events (master) $ rsync -av app/ ubuntu@84.201.132.3:app/
... skipped ...
sent 3849 bytes received 70 bytes 7838.00 bytes/sec
total size is 3644 speedup is 0.93
vozerov@mba:~/events (master) $ ssh 84.201.132.3 -l ubuntu
ubuntu@build:~$ cd app
ubuntu@build:~/app$ sudo docker build -t app .
Sending build context to Docker daemon 6.144kB
Step 1/9 : FROM golang:latest AS build
... skipped ...
Successfully built 9760afd8ef65
Successfully tagged app:latest
æŠãã®ååã¯å®äºããŸãããããã§ãã¢ããªã±ãŒã·ã§ã³ãå®è¡ããŠkafkaã«ãã€ã³ãããããšã§ãã¢ããªã±ãŒã·ã§ã³ã®æ©èœã確èªã§ããŸãã
ubuntu@build:~/app$ sudo docker run --name app -d -p 8080:8080 app /app/app -kafka=kafka.ru-central1.internal:9092</code>
event :
<code>vozerov@mba:~/events (master) $ curl -D - -s -X POST -d '{"key1":"data1"}' http://84.201.132.3:8080/post
HTTP/1.1 200 OK
Content-Type: application/json
Date: Mon, 13 Apr 2020 13:53:54 GMT
Content-Length: 41
{"status":"ok","partition":0,"Offset":0}
vozerov@mba:~/events (master) $
ã¢ããªã±ãŒã·ã§ã³ã¯ãèšé²ãæåããã¡ãã»ãŒãžãå«ãŸããããŒãã£ã·ã§ã³ãšãªãã»ããã®IDã瀺ããŠå¿çããŸãããYandex.Cloudã«ã¬ãžã¹ããªãäœæããããã«ç»åãã¢ããããŒãããã ãã§ãïŒ3è¡ã䜿çšããŠãããè¡ãæ¹æ³ã¯ãregistry.tfãã¡ã€ã«ã«èšèŒãããŠããŸãïŒããªããžããªãäœæããŸãã
vozerov@mba:~/events/terraform (master) $ terraform apply -target yandex_container_registry.events
... skipped ...
Plan: 1 to add, 0 to change, 0 to destroy.
... skipped ...
Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
ã³ã³ããã¬ãžã¹ããªã§èªèšŒããã«ã¯ãoauthããŒã¯ã³ãiamããŒã¯ã³ããŸãã¯ãµãŒãã¹ã¢ã«ãŠã³ãããŒã䜿çšããæ¹æ³ãããã€ããããŸãããããã®ã¡ãœããã®è©³çŽ°ã«ã€ããŠã¯ãããã¥ã¡ã³ãhttps://cloud.yandex.ru/docs/container-registry/operations/authenticationãåç §ããŠãã ããããµãŒãã¹ã¢ã«ãŠã³ãããŒã䜿çšãããããã¢ã«ãŠã³ããäœæããŸãã
vozerov@mba:~/events/terraform (master) $ terraform apply -target yandex_iam_service_account.docker -target yandex_resourcemanager_folder_iam_binding.puller -target yandex_resourcemanager_folder_iam_binding.pusher
... skipped ...
Apply complete! Resources: 3 added, 0 changed, 0 destroyed.
ä»ã圌ã®ããã«éµãäœãããšãæ®ã£ãŠããŸãïŒ
vozerov@mba:~/events/terraform (master) $ yc iam key create --service-account-name docker -o key.json
id: ajej8a06kdfbehbrh91p
service_account_id: ajep6d38k895srp9osij
created_at: "2020-04-13T14:00:30Z"
key_algorithm: RSA_2048
ã¹ãã¬ãŒãžã®IDã«é¢ããæ å ±ãååŸããããŒãåãæ¿ããŠãã°ã€ã³ããŸãã
vozerov@mba:~/events/terraform (master) $ scp key.json ubuntu@84.201.132.3:
key.json 100% 2392 215.1KB/s 00:00
vozerov@mba:~/events/terraform (master) $ ssh 84.201.132.3 -l ubuntu
ubuntu@build:~$ cat key.json | sudo docker login --username json_key --password-stdin cr.yandex
WARNING! Your password will be stored unencrypted in /home/ubuntu/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store
Login Succeeded
ubuntu@build:~$
ã€ã¡ãŒãžãã¬ãžã¹ããªã«ããŒãããã«ã¯ãIDã³ã³ããã¬ãžã¹ããªãå¿ èŠã§ããycãŠãŒãã£ãªãã£ããååŸããŸãã
vozerov@mba:~ $ yc container registry get events
id: crpdgj6c9umdhgaqjfmm
folder_id:
name: events
status: ACTIVE
created_at: "2020-04-13T13:56:41.914Z"
ãã®åŸãç»åã«æ°ããååãä»ããŠããŒãããŸãã
ubuntu@build:~$ sudo docker tag app cr.yandex/crpdgj6c9umdhgaqjfmm/events:v1
ubuntu@build:~$ sudo docker push cr.yandex/crpdgj6c9umdhgaqjfmm/events:v1
The push refers to repository [cr.yandex/crpdgj6c9umdhgaqjfmm/events]
8c286e154c6e: Pushed
477c318b05cb: Pushed
beee9f30bc1f: Pushed
v1: digest: sha256:1dd5aaa9dbdde2f60d833be0bed1c352724be3ea3158bcac3cdee41d47c5e380 size: 946
ã€ã¡ãŒãžãæ£åžžã«èµ·åããããšã確èªã§ããŸãã
vozerov@mba:~/events/terraform (master) $ yc container repository list
+----------------------+-----------------------------+
| ID | NAME |
+----------------------+-----------------------------+
| crpe8mqtrgmuq07accvn | crpdgj6c9umdhgaqjfmm/events |
+----------------------+-----------------------------+
ã¡ãªã¿ã«ãLinuxãã·ã³ã«ycãŠãŒãã£ãªãã£ãã€ã³ã¹ããŒã«ãããšã次ã®ã³ãã³ãã䜿çšã§ããŸãã
yc container registry configure-docker
ããã«ãŒã®ã»ããã¢ããçšã
çµè«
ç§ãã¡ã¯çŽ æŽãããå°é£ãªä»äºãããŸããããã®çµæã次ã®ããã«ãªããŸããã
- .
- golang, -.
- container registry.
次ã®ããŒãã§ã¯ãèå³æ·±ãããŒãã«ç§»ããŸããã¢ããªã±ãŒã·ã§ã³ãæ¬çªç°å¢ã«æ³šããæåŸã«ããŒããéå§ããŸããåãæ¿ããªãã§ãã ããïŒ
ãã®ææã¯ãREBRAINïŒYandex.CloudãªãŒãã³ã¯ãŒã¯ã·ã§ããã®ãããªé²ç»ã§ããïŒç§ãã¡ã¯ãYandexã®ã¯ã©ãŠãäžã®æ¯ç§äžã®èŠæ±ãåãå ¥ãã- https://youtu.be/cZLezUm0ekE
ããªãããªã³ã©ã€ã³ã«ãã®ãããªã€ãã³ãã蚪åãããªã¢ã«ã¿ã€ã ã§è³ªåãã«èå³ãããå Žåã¯ããžã®æ¥ç¶ãã£ã³ãã«REBRAINã«ããDevOpsã
ãã®ãããªã€ãã³ããéå¬ããæ©äŒãäžããŠãããYandex.Cloudã«ç¹ã«æè¬ããŸããããããžã®ãªã³ã¯ã¯https://cloud.yandex.ru/prices
ã§ããã¯ã©ãŠããžã®ç§»è¡ãå¿ èŠãªå ŽåããŸãã¯ã€ã³ãã©ã¹ãã©ã¯ãã£ã«ã€ããŠè³ªåãããå Žåã¯ãé æ ®ãªããªã¯ãšã¹ããæ®ããŠãã ããã
P.S. 2 , , .