kmg28801 / kafka-study

1 stars 0 forks source link

[실전 카프카 개발부터 운영까지] 12장. 엔터프라이즈 카프카 아키텍처 구성 사례 #22

Open kmg28801 opened 1 year ago

taewoo-kim123 commented 1 year ago

12장 엔터프라이즈 카프카 아키텍처 구성 사례

12.1 엔터프라이즈용 카프카 아키텍처의 개요

peter-ansible01 서버에 접속하고, 아래 명령어를 실행하여 그람과 같은 환경으로 설치를 한다.

  1. ansible-playbook -i hosts site.yml 명령어 실행

    [ec2-user@ip-172-31-13-207 ~]$ cd kafka2
    [ec2-user@ip-172-31-13-207 kafka2]$ cd chapter12/ansible_playbook/
    [ec2-user@ip-172-31-13-207 ansible_playbook]$ ansible-playbook -i hosts site.yml
    • 은근 오래걸림, 중간에 TASK [stop exporters] 이거 failed 나는데 ignoring 처리됨(상관 없나?) 나머진 순조롭게 ok 스크린샷 2023-09-01 오후 10 07 57 스크린샷 2023-09-01 오후 10 08 19
  2. ansible-playbook -i hosts expoter.yml

    • TASK [exporterall : stop services] failed 나는데 ignoring 처리됨 스크린샷 2023-09-01 오후 10 08 42
  3. ansible-playbook -i hosts monitoring.yml 스크린샷 2023-09-01 오후 10 08 52

    12.3 엔터프라이즈용 카프카의 운영 실습

    • 전체 실습 시나리오는 다음과 같다
  4. 프로듀서1은 업스트림 카프카의 실습용 토픽(peter-avro01-kafka1)으로 메세지를 전송

  5. 카프카 커넥트의 미러 메이커는 peter-avro01-kafka1 토픽을 다운스트림 카프카로 미러링

  6. 컨슈머1을 이용해 업스트림 카프카의 peter-avro01-kafka1 토픽을 컨슘

  7. 컨슈머2를 이용해 다운스트림 카프카의 미러링된 토픽 src.peter-avro01-kafka1에서 메세지를 읽고, 엘라스틱서지로 전송

  8. REST API와 키바나를 이용해 엘라스틱 서치에 메세지가 저장되었는지 확인

  9. 스키마를 변경한 후, 다시 메세지를 전송해 최종적으로 엘라스틱까지 변경되 스키마 내용이 적용되었는지 확인

  10. 이 과정에 대한 카프카 메트릭은 프로메테우스에 저장되며, 그라파나 대시보드를 이용해 모니터링

12.3.1 CMAK를 이용한 토픽 생성

12.3.3 모니터링 환경 구성

12.3.4 메세지 전송과 확인

taewoo-kim123 commented 12 months ago

gpt에게 물어봐서 실습코드에서 es = Elasticsearch('http://peter-kafka02.foo.bar:9200') http 붙이라고 알려줌.

그런데 새로운 오류가 발생

(venv12) [ec2-user@ip-172-31-13-207 ~]$ python kafka2/chapter12/python/consumer_kafka-2_producer_es_v1.py 
kafka2/chapter12/python/consumer_kafka-2_producer_es_v1.py:25: DeprecationWarning: AvroConsumer has been deprecated. Use AvroDeserializer instead.
  'schema.registry.url': 'http://peter-kafka03.foo.bar:8081'},reader_value_schema=value_schema)
{'name': 'Ernest', 'class': 4}
Traceback (most recent call last):
  File "kafka2/chapter12/python/consumer_kafka-2_producer_es_v1.py", line 53, in <module>
    es.indices.create(index=index)
  File "/home/ec2-user/venv12/lib64/python3.7/site-packages/elasticsearch/_sync/client/utils.py", line 414, in wrapped
    return api(*args, **kwargs)
  File "/home/ec2-user/venv12/lib64/python3.7/site-packages/elasticsearch/_sync/client/indices.py", line 518, in create
    "PUT", __path, params=__query, headers=__headers, body=__body
  File "/home/ec2-user/venv12/lib64/python3.7/site-packages/elasticsearch/_sync/client/_base.py", line 390, in perform_request
    method, path, params=params, headers=headers, body=body
  File "/home/ec2-user/venv12/lib64/python3.7/site-packages/elasticsearch/_sync/client/_base.py", line 337, in perform_request
    body=resp_body,
elasticsearch.UnsupportedProductError: The client noticed that the server is not Elasticsearch and we do not support this unknown product

엘라스틱 서치 상태를 확인하니 아까는 green이었는데 이제 yellow가 되었음

(venv12) [ec2-user@ip-172-31-13-207 ~]$ curl -X GET 'http://peter-kafka02.foo.bar:9200/_cat/health?v'
epoch      timestamp cluster        status node.total node.data shards pri relo init unassign pending_tasks max_task_wait_time active_shards_percent
1694349165 12:32:45  docker-cluster yellow  

[ec2-user@ip-172-31-13-207 ~]$ curl -X GET 'http://peter-kafka02.foo.bar:9200/_cat/indices?v' 이걸로 상태를 보니 yellow open students ITNfSd20S9Kv_dKBi47MXA 1 1 0 0 208b 208b 복사개수가 0개

taewoo-kim123 commented 12 months ago
  1. 2서버로 들어가서 도커의 엘라스틱 컨테이너를 재시작 하여도 yellow에서 바뀌지 않음 2.로그를 확인하니 ERROR 로 따로 찍히는건 없음
  2. gpt가 샤드를 확인하라해서 curl -X GET 'http://peter-kafka02.foo.bar:9200/_cat/shards?v'를 통해 샤드를 확인
index                               shard prirep state      docs   store ip           node
.tasks                              0     p      STARTED       4  21.3kb 172.31.5.249 ip-172-31-5-249.us-east-2.compute.internal
students                            0     p      STARTED       0    208b 172.31.5.249 ip-172-31-5-249.us-east-2.compute.internal
students                            0     r      UNASSIGNED                           
.apm-agent-configuration            0     p      STARTED       0    208b 172.31.5.249 ip-172-31-5-249.us-east-2.compute.internal
.kibana-event-log-7.12.1-000001     0     p      STARTED       4  21.8kb 172.31.5.249 ip-172-31-5-249.us-east-2.compute.internal
.apm-custom-link                    0     p      STARTED       0    208b 172.31.5.249 ip-172-31-5-249.us-east-2.compute.internal
.kibana_task_manager_7.12.1_001     0     p      STARTED       9 188.8kb 172.31.5.249 ip-172-31-5-249.us-east-2.compute.internal
.kibana_7.12.1_001                  0     p      STARTED      11   2.1mb 172.31.5.249 ip-172-31-5-249.us-east-2.compute.internal
.ds-ilm-history-5-2023.09.01-000001 0     p      STARTED                 172.31.5.249 ip-172-31-5-249.us-east-2.compute.internal

students가 2개 찍혀있고, UNASSIGNED로 되어있음....

taewoo-kim123 commented 12 months ago

노드도 1개중 1개로 확인

[ec2-user@ip-172-31-13-207 ~]$ curl -X GET 'http://peter-kafka02.foo.bar:9200/_cat/nodes?v'
ip           heap.percent ram.percent cpu load_1m load_5m load_15m node.role   master name
172.31.5.249           62          97  10    0.08    0.07     0.08 cdfhilmrstw *      ip-172-31-5-249.us-east-2.compute.internal
taewoo-kim123 commented 12 months ago

(venv12) [ec2-user@ip-172-31-13-207 ~]$ python kafka2/chapter12/python/consumer_kafka-2_producer_es_v1.py kafka2/chapter12/python/consumer_kafka-2_producer_es_v1.py:25: DeprecationWarning: AvroConsumer has been deprecated. Use AvroDeserializer instead. 'schema.registry.url': 'http://peter-kafka03.foo.bar:8081'},reader_value_schema=value_schema) AvroConsumer error: KafkaError{code=UNKNOWN_TOPIC_OR_PART,val=3,str="Subscribed topic not available: src.peter-avro01-kafka1: Broker: Unknown topic or partition"} ^C^X^CTraceback (most recent call last): File "kafka2/chapter12/python/consumer_kafka-2_producer_es_v1.py", line 34, in msg = c.poll(10) File "/home/ec2-user/venv12/lib64/python3.7/site-packages/confluent_kafka/avro/init.py", line 174, in poll message = super(AvroConsumer, self).poll(timeout) KeyboardInterrupt