ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • Fleet 사용하기
    기타 2015. 10. 23. 09:00
    반응형
    fleet이란?
    coreos에서 만든 분산 init 시스템.
    클러스터에 속한 노드들의 systemd를 이용해서 프로세스 관리.

    fleet 구조
    engine과 agent 두개의 역할을 하나의 fleetd 데몬이 처리하고 있음.
    데이터는 etcd에 저장함.

    fleet 설치
    CoreOS에는 기본으로 설치되어 있음.

    필요한 환경
    OS : centos 7.1
    etcd 0.3.0 이상
    systemd v207 이상

    systemd 업그레이드
    sudo yum upgrade systemd

    fleet 바이너리 다운로드(https://github.com/coreos/fleet/releases)
    tar zxvf fleet-v0.11.5-linux-amd64.tar.gz
    cd fleet-v0.11.5-linux-amd64
    sudo mkdir /opt/fleet
    sudo cp ./fleetd /opt/fleet/


    systemd에 fleet 서비스로 등록하기(coreos에 있는 설정 참조)
    sudo vi /usr/lib/systemd/system/fleet.service
    [Unit]
    Description=fleet daemon
    Wants=fleet.socket
    After=fleet.socket

    [Service]
    Environment=GOMAXPROCS=1
    ExecStart=/opt/fleet/fleetd
    Restart=always
    RestartSec=10s

    [Install]
    WantedBy=multi-user.target

    sudo vi /usr/lib/systemd/system/fleet.socket
    [Unit]
    Description=Fleet API Socket
    PartOf=fleet.service

    [Socket]
    ListenStream=/var/run/fleet.sock
    ListenStream=0.0.0.0:49153

    fleetd 설정파일 만들기
    기본적으로 /etc/fleet/fleet.conf에 있는 설정을 참고함.
    --config 옵션으로 설정파일을 지정할수도 있음.
    환경변수를 이용해서 설정파일에 있는 내용을 오버라이드할 수 있음.
    fleet.conf 설정파일 기본 내용
    sudo mkdir /etc/fleet
    sudo vi /etc/fleet/fleet.conf
    # This config file is INI-formatted

    # Lower the logging threshold. Acceptable values are 0, 1, and 2. A higher
    # value corresponds to a lower logging threshold.
    # verbosity=0

    # Provide a custom set of etcd endpoints. The default value is determined
    # by the underlying go-etcd library.
    # etcd_servers=["http://127.0.0.1:4001", "http://127.0.0.1:2379"]

    # Amount of time in seconds to allow a single etcd request before considering it failed.
    # etcd_request_timeout=1.0

    # Provide TLS configuration when SSL certificate authentication is enabled in etcd endpoints
    # etcd_cafile=/path/to/CAfile
    # etcd_keyfile=/path/to/keyfile
    # etcd_certfile=/path/to/certfile

    # IP address that should be published with any socket information. By default,
    # no IP address is published.
    # public_ip=""

    # Comma-delimited key/value pairs that are published to the fleet registry.
    # This data can be referenced in unit files to affect scheduling decisions.
    # An example could look like: metadata="region=us-west,az=us-west-1"
    # metadata=""

    # An Agent will be considered dead if it exceeds this amount of time to
    # communicate with the Registry. The agent will attempt a heartbeat at half
    # of this value.
    # agent_ttl="30s"

    # Interval at which the engine should reconcile the cluster schedule in etcd.
    # engine_reconcile_interval=2


    fleed 데몬 실행
    sudo systemctl daemon-reload
    sudo systemctl restart fleet.socket
    sudo systemctl restart fleet.service


    fleet 잘떴는지 장비 상태 확인
    ./fleetctl list-machines


    fleet 사용해보기

    fleet이 systemd를 이용하기 때문에 우선 systemd 설정파일들이 해당 장비에 존재해야 한다.
    systemd 설정파일중 fleet관련 내용은 [X-Fleet] 영역에 명시한다.

    fleet에서 사용하는 systemd unit은 2가지 타입이 있음.
    standard unit : 한 장비에서 장시간 실행되는 프로세스. 장비에 문제생기면 다른 장비에서 프로세스가 시작됨.
    global unit : 클러스터내 전체 장비에서 실행되는 프로세스.

    클러스터 내에서 사용가능한 unit들 확인
    ./fleetctl list-unit-files

    fleet으로 간단한 서비스 실행하기
    fleet에서 실행할 unit 파일 만들기
    vi hello.service
    [Unit]
    Description=Hello World

    [Service]
    ExecStart=/bin/bash -c "while true; do echo \"Hello, world\"; sleep 1; done"

    fleet으로 hello.service 실행하기
    ./fleetctl start hello.service

    fleet으로 docker 실행하기
    docker 설치
    sudo yum install docker.x86_64
    sudo systemctl start docker

    unit 파일 만들기
    sudo vi /usr/lib/systemd/system/myapp.service
    [Unit]
    Description=MyApp
    After=docker.service
    Requires=docker.service

    [Service]
    TimeoutStartSec=0
    ExecStartPre=-/usr/bin/docker kill busybox1
    ExecStartPre=-/usr/bin/docker rm busybox1
    ExecStartPre=/usr/bin/docker pull busybox
    ExecStart=/usr/bin/docker run --name busybox1 busybox /bin/sh -c "while true; do echo Hello World; sleep 1; done"
    ExecStop=/usr/bin/docker stop busybox1

    unit파일 이용해서 서비스 실행해보기
    ./fleetctl start /usr/lib/systemd/system/myapp.service

    상태 확인
    ./fleetctl list-units


    참고



    반응형

    '기타' 카테고리의 다른 글

    hadoop 싱글 노드 설치  (0) 2017.02.17
    storm 개요  (0) 2015.12.23
    etcd 클러스터  (0) 2015.10.21
    kafka 클러스터 구축  (0) 2015.10.19
    Docker를 이용한 Jenkins 설정  (0) 2015.09.16

    댓글

Designed by Tistory.