Showing posts with label distributed streaming platform. Show all posts
Showing posts with label distributed streaming platform. Show all posts

Tuesday, October 11, 2016

Apache Kafka (아파치 카프카) 설치 (CentOS 7.2.1511 64-bit)

설치 전 준비사항

  1. CentOS 7이 설치된 서버 (또는 VM)
  2. 오픈 JDK 패키지 설치
    1.  yum install java-1.8.0-openjdk.x86_64
    2. 설치가 잘 되었는지 확인하려면 아래의 명령어를 실행해서 자바 버전 확인
      1. java -version
  3. 자바 환경 변수 설정
    1. 텍스트 에디터를 이용해서 ‘/etc/profile’에 자바 환경 변수 설정을 추가 
      1. vim /etc/profile
      2.  profile 파일 안에 아래의 내용을 추가
        1. export JAVA_HOME=/usr/lib/jvm/jre-1.8.0-openjdk
        2. export JRE_HOME=/usr/lib/jvm/jre
      3. source 명령어를 이용해서 변경된 내용 적용
        1. source /etc/profile

설치 단계

  1. Kafka 패키지 다운로드
    1. wget http://www-us.apache.org/dist/kafka/0.10.0.1/kafka_2.11-0.10.0.1.tgz
      1. 위의 버전이 최신 버전이 아니면 kafka 웹사이트 (http://www-us.apache.org/dist/kafka)에 들어가셔서 최신 버전을 확인 후 다운 받으세요.
    2. tar xvf kafka_2.11-0.10.0.1.tgz
    3. mv kafka_2.11-0.10.0.1 /opt
    4. cd /opt/kafka_2.11-0.10.0.1
  2. Zookeeper 서버 시작
    1. bin/zookeeper-server-start.sh -daemon config/zookeeper.properties
  3. Kafka 서버 시작
    1. bin/kafka-server-start.sh config/server.properties
      1. 서버 시작 후 아래와 같은 로그를 확인하셨다면 서버가 정상적으로 시작된 것입니다.
      2. INFO [Kafka Server 0], started (kafka.server.KafkaServer)
  4. Kafka 패키지에서 제공하는 클라이언트 프로그램을 이용한 간단한 서버 테스트
    1. 테스트 토픽 생성
    2. bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test
    3. Consumer 생성
      1. bin/kafka-console-consumer.sh --zookeeper localhost:2181 --topic test —from-beginning
    4. Producer 생성
      1. 같은 SSH 연결에서 Consumer와 Producer를 같이 생성할 수 없기 때문에 새로운 SSH 연결을 한 후 에 아래의 명령어를 실행합니다.
      2. bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test
      3. 위의 명령어를 실행 후 콘솔에 텍스트를 입력하고 엔터를 누르면 입력한 텍스트가 Consumer 쪽 콘솔에 출력 되는 것을 확인하실 수 있으십니다.
  5. References
    1. https://www.vultr.com/docs/how-to-install-apache-kafka-on-centos-7
    2. http://davidssysadminnotes.blogspot.com/2016/01/installing-apache-kafka-and-zookeeper.html
    3. http://www.javaworld.com/article/3060078/big-data/big-data-messaging-with-kafka-part-1.html