nhnacademy-aiot1-5 / docs

프로젝트 관련 문서 저장소입니다.
MIT License
0 stars 0 forks source link

클라우드 인스턴스 리눅스에 도커 설치 및 node-red, telegraf, mosquitto 올리기 #56

Open codethestudent opened 3 months ago

codethestudent commented 3 months ago

클라우드 인스턴스 리눅스에 도커 설치 및 node-red, telegraf, mosquitto 올리기

  1. 클라우드 인스턴스를 생성합니다.

    인스턴스 생성 후 아래 페이지에서 키 설정을 완료합니다.

    [Day+137 (3/29)](https://www.notion.so/Day-137-3-29-fefe435bb25749c1ad6ffba2b4adf49d?pvs=21)

  2. 아래 docker-compose.yml 파일을 원하는 위치에 생성합니다.

    version: "3.7"
    
    services:
      nodered:
        image: nodered/node-red
        container_name: nodered
        ports:
          - "1880:1880"
        networks:
          - my-network
    
      mosquitto:
        image: eclipse-mosquitto
        container_name: mosquitto
        ports:
          - "1883:1883"
        networks:
          - my-network
    
      telegraf:
        image: telegraf
        container_name: telegraf
        volumes:
          - "/home/nhnacademy/telegraf.conf:/etc/telegraf/telegraf.conf:ro"
        networks:
          - "my-network"
    networks:
      my-network:
        name: my-network
  3. telegraf.conf 파일을 아래와 같이 생성합니다. influxdb_v2 사이트에서 생성 가능합니다.

Image

Image

Image

생성 된 conf파일을 클라우드 인스턴스에 파일로 원하는 위치에 저장합니다. 위에서 만든 docker-compose.yml 파일을 만든 위치에 다 모아두면 편하겠죠?
  1. docker compose up -d 명령을 실행합니다.
  2. docker ps로 돌아가는 컨테이너를 확인합니다.
codethestudent commented 3 months ago

클라우드 도커에 telegraf 만 올리는 방법

docker search telegraf 명령으로 official 이미지를 찾고 docker pull telegraf 실행하여 텔레그라프 이미지를 도커에 올립니다.

위 글에서 만든 telegraf.conf 파일을 원하는 위치에 저장하고 아래의 명령어를 실행합니다. docker run -d --name=telegraf -v ${파일 디렉토리 경로}:/etc/telegraf/telegraf.conf:ro telegraf

만약 네트워크로 올리고싶다면 --network={$네트워크 이름} 옵션을 추가해 아래와 같이 실행합니다. docker run -d --name=telegraf -v ${파일 디렉토리 경로}:/etc/telegraf/telegraf.conf:ro --network=my-network telegraf

codethestudent commented 3 months ago

<도커 네트워크 설정파일>

# Configuration for telegraf agent
[agent]
  interval = "10s"
  round_interval = true
  metric_batch_size = 1000
  metric_buffer_limit = 10000
  collection_jitter = "0s"
  flush_jitter = "0s"
  precision = ""

  hostname = ""
  omit_hostname = false
[[outputs.influxdb_v2]]
  urls = ["http://133.186.244.96:8086"]

  ## Token for authentication.
  token = "7drot0reYaAVxTeYkOMCl2Lz-joqNrlfVJ5sV24dP3fFxGFYZ4tlfOgO11gVti5N3f-u_jei4ixlUg1Ct-uj6Q=="

  ## Organization is the name of the organization you wish to write to; must exist.
  organization = "ioteatime"

  ## Destination bucket to write into.
  bucket = "testdb"

[[inputs.mqtt_consumer]]
  servers = ["tcp://mosquitto:1883"]

  topics = [
    "#",
  ]

  data_format = "influx"

listener 1883
persistence true
persistence_location /mosquitto/data/

log_dest file /mosquitto/logs/mosquitto.log

allow_anonymous true

version: "3.7"

services:
  nodered:
    image: nodered/node-red
    container_name: nodered
    ports:
      - "1880:1880"
    networks:
      - my-network

  mosquitto:
    image: eclipse-mosquitto
    container_name: mosquitto
    ports:
      - "1883:1883"
    volumes:
      - "./mosquitto.conf:/mosquitto/config/mosquitto.conf"
      - "./data:/mosquitto/data"
      - "./logs:/mosquitto/logs"
    networks:
      - my-network

  telegraf:
    image: telegraf
    restart: always
    container_name: telegraf
    volumes:
      - "/home/nhnacademy/telegraf.conf:/etc/telegraf/telegraf.conf:ro"
    networks:
      - "my-network"
networks:
  my-network:
    name: my-network