실전프로젝트 4주차 금요일 docker swarm ocastration 구축 + 모니터링(그라파나,프로메테우스)
docker 스웜
docker 설치
$ curl -fsSL https://get.docker.com/ | sudo sh
$ sudo usermod -aG docker $USER
docker compose설치
$ sudo curl -L "https://github.com/docker/compose/releases/download/1.24.0/docker-compose-$(uname -s)- sudo chmod +x /usr/local/bin/docker-compose
$ docker compose 로 컨테이너 4개 실행
version: "3"
services:
registry:
container_name: registry
image: registry:2.6
ports:
- 5000:5000
volumes:
- "./registry-data:/var/lib/registry"
manager:
container_name: manager
image: docker:18.05.0-ce-dind
privileged: true
tty: true
ports:
- 8000:8000
- 9000:9000
- 7000:7000
depends_on:
- registry
expose:
- 3375
command: "--insecure-registry registry:5000"
volumes:
- "./stack:/stack"
worker01:
container_name: worker01
image: docker:18.05.0-ce-dind
privileged: true
tty: true
depends_on:
- manager
- registry
expose:
- 7946
- 7946/udp
- 4789/udp
command: "--insecure-registry registry:5000"
worker02:
container_name: worker02
image: docker:18.05.0-ce-dind
privileged: true
tty: true
depends_on:
- manager
- registry
expose:
- 7946
- 7946/udp
- 4789/udp
command: "--insecure-registry registry:5000"
$ docker-compose up -d
registry 1대, manager 1대, worker 2대, 총 4대 컨테이너가 실행 상태가 된다.
$ docker container exec -it manager docker swarm init
스웜 init
$ docker container exec -it worker01 docker swarm join --token SWMTKN-1-0zr8efup5pf4ymnuip55nxl0cz19g454ycfdkogcwvui498bks-2pi6hr39nj4zzns0vsixofdfq 172.18.0.3:2377
$ docker container exec -it worker02 docker swarm join --token SWMTKN-1-0zr8efup5pf4ymnuip55nxl0cz19g454ycfdkogcwvui498bks-2pi6hr39nj4zzns0vsixofdfq 172.18.0.3:2377
work들 조인시키기
docker 허브로 로그인
$ docker login
도커허브에서 풀받아와서 레지스트리에 저장
$ docker pull stravinest/fungap:36
$ docker tag stravinest/fungap:36 localhost:5000/stravinest/fungap:36
$ docker push localhost:5000/stravinest/fungap:36
저장 확인
$ curl -X GET http://localhost:5000/v2/_catalog
각 워커들 이미지 pull
$ docker container exec -it manager docker image pull registry:5000/stravinest/fungap:36
$ docker container exec -it worker01 docker image pull registry:5000/stravinest/fungap:36
$ docker container exec -it worker02 docker image pull registry:5000/stravinest/fungap:36
$ docker container exec -it manager docker service create --replicas 3 --publish 9000:3000 --name fungap --mount type=volume,src=env,target=/usr/src/app/env registry:5000/stravinest/fungap:36
.env 파일 붙여넣어줘야 함
$ docker container exec -it manager sh
$ cd /var/lib/docker/volumes/env/_data
$ vi .env
$ docker container exec -it worker01 sh
$ cd /var/lib/docker/volumes/env/_data
$ vi .env
$ docker container exec -it worker02 sh
$ cd /var/lib/docker/volumes/env/_data
$ vi .env
서비스 삭제
$ docker container exec -it manager docker service rm fungap
서비스 다시 시작
$ docker container exec -it manager docker service create --replicas 3 --publish 9000:3000 --name fungap --mount type=volume,src=env,target=/usr/src/app/env registry:5000/stravinest/fungap:36
모니터링 설치
$ docker \
network create --driver overlay monitoring
Cadvisor 서비스 등록
$ docker \
service create --name cadvisor \
--mode global \
--network monitoring \
--label com.docker.stack.namespace=monitoring \
--container-label com.docker.stack.namespace=monitoring \
--mount type=bind,src=/,dst=/rootfs:ro \
--mount type=bind,src=/var/run,dst=/var/run:rw \
--mount type=bind,src=/sys,dst=/sys:ro \
--mount type=bind,src=/var/lib/docker/,dst=/var/lib/docker:ro \
google/cadvisor:v0.24.1
Node-exporter 서비스 등록
$ docker \
service create --name node-exporter \
--mode global \
--network monitoring \
--label com.docker.stack.namespace=monitoring \
--container-label com.docker.stack.namespace=monitoring \
--mount type=bind,source=/proc,target=/host/proc \
--mount type=bind,source=/sys,target=/host/sys \
--mount type=bind,source=/,target=/rootfs \
--mount type=bind,source=/etc/hostname,target=/etc/host_hostname \
-e HOST_HOSTNAME=/etc/host_hostname \
basi/node-exporter \
--path.procfs /host/proc \
--path.sysfs /host/sys \
--collector.filesystem.ignored-mount-points "^/(sys|proc|dev|host|etc)($|/)" \
--collector.textfile.directory /etc/node-exporter/
Prometheus 서비스 등록
$ docker \
service create \
--name prometheus \
--network monitoring \
--label com.docker.stack.namespace=monitoring \
--container-label com.docker.stack.namespace=monitoring \
--publish 7000:9090 \
basi/prometheus-swarm \
-config.file=/etc/prometheus/prometheus.yml \
-storage.local.path=/prometheus \
-web.console.libraries=/etc/prometheus/console_libraries \
-web.console.templates=/etc/prometheus/consoles \
-alertmanager.url=http://alertmanager:9093
Grafana 서비스 등록
$ docker \
service create \
--name grafana \
--network monitoring \
--label com.docker.stack.namespace=monitoring \
--container-label com.docker.stack.namespace=monitoring \
--publish 8000:3000 \
-e "GF_SERVER_ROOT_URL=http://grafana.${CLUSTER_DOMAIN}" \
-e "GF_SECURITY_ADMIN_PASSWORD=$GF_PASSWORD" \
-e "PROMETHEUS_ENDPOINT=http://prometheus:9090" \
basi/grafana
Author And Source
이 문제에 관하여(실전프로젝트 4주차 금요일 docker swarm ocastration 구축 + 모니터링(그라파나,프로메테우스)), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@stravinest/실전프로젝트-4주차-금요일-docker-swarm-ocastration-구축-모니터링그라파나프로메테우스저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)