그라파나(Grafana)란

  • Grafana란, Grafana Labs에서 관리하고 있는 오픈 소스 시각화 및 분석 도구
  • Prometheus 물론 InfluxDB, Elasticsearch 등 여러 데이터 소스와 통합이 가능
  • Prometheus 자체적으로 UI를 제공하고 있지만, 기능이 너무나도 빈약하고 불편해서 상용 환경에서는 Grafana와 함께 연동해서 사용
  • Grafana는 여러 데이터 소스에 대한 대시보드 템플릿을 제공하기 때문에, Prometheus 등의 데이터 소스의 쿼리 방법을 잘 모른다 하더라도 기본적인 대시보드 구성이 가능
  • Grafana는 오픈소스 메트릭 데이터 시각화 도구로 메트릭 분석 플랫폼을 지향
  • Prometheus와 Grafana는 모두 Grafana Labs에서 관리하고 있기 때문에, 궁합이 어떤 데이터 소스와 비교하더라도 매우 좋음
  • grafana/grafana: 공식 GitHub 저장소 : https://github.com/grafana/grafana
  • Grafana 공식 웹사이트 : https://grafana.com/
 

Grafana: The open observability platform | Grafana Labs

Your observability stack Operational dashboards for your data here, there, or anywhere

grafana.com

 

  • Grafana는 오픈소스 메트릭 데이터 시각화 도구로 메트릭 분석 플랫폼을 지향
  • Torkel Ödegaard의 주도로 2014년 처음 릴리스
  • 처음에는 Graphite, DBInfluxDB, OpenTSDB 등을 지원하는 오픈소스 대시보드 도구로 개발
  • 메트릭 정보를 시각화하고 대시보드를 구성한다는 큰 틀은 여전히 변함이 없습니다만, AWS CloudWatch, Azure Monitor와 같은 클라우드 데이터 소스를 비롯해 Loki나 ElasticSearch 등을 기반으로 로그 데이터를 지원하는 등 더 많은 데이터 소스를 지원
  • 엔터프라이즈 플랜에서는 Splunk, New Relic, AppDynamics, Oracle, Dynatrace, ServiceNow, DataDog 등의 외부 서비스들과 통합도 지원

 

  • Grafana는 현재 Grafana Labs에서 개발
  • Grafana LAB은 Grafana와 Loki, Tanka 등의 애플리케이션을 오픈소스를 개발하고 있는 회사
  • Grafana는 Paypal, ebay, Intel, rackspace, Video, TED, Digital Ocean, Bloomberg 등 다양한 기업에서 활용
  • 다양한 도입 사례 : https://grafana.com/success/
 

Success stories and case studies | Grafana Labs

We have been able to enhance our application and infrastructure uptime with Grafana Labs, resulting in stronger business performance. - George Sherman, Global Technology Infrastructure CIO

grafana.com

 

 

그라파나 클라우드(Grafana Cloud)와 그라파나 엔터프라이즈(Grafana Enterprise)

  • Grafana는 오픈소스로 기본적으로는 직접 설치하고 운영해야 함
  • 또한 메트릭 데이터나 로그 데이터에 대한 관리도 직접해야함
  • Grafana LAB에서는 그라파나를 서비스로 제공하는 그라파나 클라우드 서비스를 제공
  • 무료 플랜에서는 5개의 대시보드까지 생성 가능
  • 스탠다드(Standard) 이상의 플랜에서는 다중 유저 기능을 제공하며, 대시보드를 제한없이 생성 가능
  • 메트릭과 로그 데이터를 저장하는 기능을 제공
  • 스토리지 비용은 별도로 발생하니 확인이 필요
  • Grafana Enterprise에서는 SAML을 지원하고, 추가적으로 Splunk, New Relic, AppDynamics, Oracle, Dynatrace, ServiceNow, DataDog 플러그인을 지원
  • 이외에도 협업 관련 기능과 더 강화된 서비스 지원을 받을 수 있음
  • 그라파나 엔터프라이즈(Grafana Enterprise) : https://grafana.com/products/enterprise/
 

Grafana Enterprise | Observability stack overview

Scalable. Simple. Secure. Supported. The Grafana Enterprise Stack includes features that provide better scalability, collaboration, operations, and governance in a self-managed environment.

grafana.com

 

 

그라파나 대시보드(Grafana Dashboard)

 

 

테슬라 대시보드(Teslamate Grafana Dashboard)

  • 자신이 소유한 테슬라 자동차의 데이터를 가져와서 시각화하는 프로젝트들도 다수 공개
  • 그라파나를 대시보드로 사용
  • 테슬라 대시보드 : https://github.com/adriankumpf/teslamate

 

 

참고 자료

  • AB(Apache HTTP server benchmarking tool)는 커맨드 라인을 활용한 매우 가볍고 유용한 웹서버 벤치마킹 도구
  • 간단한 REST API나 정적 컨텐츠에 대한 성능 테스트 시에 빠르고 간편하게 벤치마킹 정보를 얻어올 수 있음
  • 성능개선 작업을 진행하면서 수정된 API에 대해서 개발환경에는 ngrinder를 활용
  • 운영환경에는 간단한 설치만으로 테스트 가능한 ApacheBench를 활용
  • Apache Bench의 공식 URL : https://httpd.apache.org/docs/2.4/en/programs/ab.html
 

ab - Apache HTTP server benchmarking tool - Apache HTTP Server Version 2.4

ab - Apache HTTP server benchmarking tool ab is a tool for benchmarking your Apache Hypertext Transfer Protocol (HTTP) server. It is designed to give you an impression of how your current Apache installation performs. This especially shows you how many req

httpd.apache.org

 

 

ApacheBench를 사용하는 경우

  • ApacheBench는 웹서버 쪽 성능 측정을 위해 만들어진 도구
  • ApacheBench는 세션을 사용한 복잡한 인증 절차 등을 포함한 페이지를 테스트하기에는 부적합
  • ApacheBench는 간단한 API(헤더 정보는 활용할 수 있으니)나 정적컨텐츠의 서비스 성능 측정에는 적합
  • ApacheBench는 웹서버가 설치되어 있는 머신의 한계치를 측정하거나 튜닝할 때, 간단하게 response time의 성능 정보 측정

 

 

ApacheBench 사용 시 참고사항 → 참고할 만한 이슈

  1. HTML이나 CSS, image 등은 해석하지 않음 → 단순히 response 시간만 나타내줌
  2. HTTP 1.0 클라이언트를 사용
  3. 동적 페이지는 Centent-Length 헤더 내용을 미리 작성할 수 없기 때문에 -k KeepAlive 옵션이 동작하지 않음
  4. HTTP 1.0클라이언트이기 때문에 Transfer-Encoding : chunked 옵션은 사용할 수 없음
  5. request 간에 delay를 주는 옵션은 없으므로 DDOS attack으로 간주 될 수 있음

 

 

AB 설치법

# Redhat / Centos
$ yum install httpd-tools


# ubuntu 설치
$ sudo apt-get install apache2-utils

 

 

AB 명령어 사용 방법

$ ab
Usage: ab [options] [http[s]://]hostname[:port]/path

 

 

AB 명령어 자주 사용하는 옵션

옵션 설명
-n - 성능을 검사하기위해 보내는 요청수.
- 요청을 한번만 보내기 때문에 일반적인 성능 검사 결과를 얻을 수 없음
-c - 동시에 요청하는 요청수
- 기본적으로 한번에 한 요청만을 보냄
-C - Cookie 헤더 사용
-H - 요청에 헤더 추가
-i - GET 메소드 대신 HEAD 메소드 요청
-k - KeepAlive 사용
- 동적 페이지는 Centent-Length 헤더 내용을 미리 작성할 수 없기 때문에 -k KeepAlive 옵션이 동작하지 않음
-p - POST 메소드 요청
-g - 측정한 모든 값을 'gnuplot' 혹은 TSV(Tab separate values, 탭으로 구분한 값) 파일에 기록
- 라벨은 output 파일의 첫번째 라인을 참고
-t - 성능을 검사하는 최대 초단위 시간.
- 내부적으로 -n 50000을 가정
- 정해진 시간동안 서버 성능을 검사할때 사용
- 기본적으로 시간 제한 없이 검사
-v - 출력 수준을 지정
- 4 이상이면 헤더에 대한 정보를 출력
- 3 이상이면 (404, 202, 등) 응답코드를 출력
- 2 이상이면 경고(warning)와 정보(info)를 출력
-A - 프록시를 통해 BASIC Authentication 정보를 제공
- :로 구분한 사용자명과 암호를 base64 인코딩하여 전송
-X - proxy[:port] 프록시 서버를 사용하여 요청

 

 

AB 명령어에서 헷갈리는 대표적인 옵션 -c 옵션에 대한 설명

  • -c 옵션이 기본적으로 다른 부하툴과는 다른게 동작 → 3개의 프로세스(쓰레드)가 10개씩 요청하는 것이 아니라 3개의 풀을 가지고 10번 요청을 진행
    $ ab -n 10 -c 3 http://www.google.com

  • -c옵션에서 숫자는 pool 개념으로 보면 됨
    [1, 2, 3]

  • -c 옵션에 3을 선언하였으면, 시작을 3개의 요청을 시작했고, 만약 2번이 먼저 종료됐으면 2번을 4번으로 대체 요청
    [1, 4, 3]

  • 1번이 종료되면 5번으로 대체 요청
    [5, 4, 3]

  • 3번이 종료되면 6번이 대체 요청
    [5, 4, 6]

  • 10개의 요청을 순차로 처리함

 

 

AB 명령어 전체 옵션

$ ab
ab: wrong number of arguments
Usage: ab [options] [http[s]://]hostname[:port]/path
Options are:
    -n requests     Number of requests to perform
    -c concurrency  Number of multiple requests to make at a time
    -t timelimit    Seconds to max. to spend on benchmarking
                    This implies -n 50000
    -s timeout      Seconds to max. wait for each response
                    Default is 30 seconds
    -b windowsize   Size of TCP send/receive buffer, in bytes
    -B address      Address to bind to when making outgoing connections
    -p postfile     File containing data to POST. Remember also to set -T
    -u putfile      File containing data to PUT. Remember also to set -T
    -T content-type Content-type header to use for POST/PUT data, eg.
                    'application/x-www-form-urlencoded'
                    Default is 'text/plain'
    -v verbosity    How much troubleshooting info to print
    -w              Print out results in HTML tables
    -i              Use HEAD instead of GET
    -x attributes   String to insert as table attributes
    -y attributes   String to insert as tr attributes
    -z attributes   String to insert as td or th attributes
    -C attribute    Add cookie, eg. 'Apache=1234'. (repeatable)
    -H attribute    Add Arbitrary header line, eg. 'Accept-Encoding: gzip'
                    Inserted after all normal header lines. (repeatable)
    -A attribute    Add Basic WWW Authentication, the attributes
                    are a colon separated username and password.
    -P attribute    Add Basic Proxy Authentication, the attributes
                    are a colon separated username and password.
    -X proxy:port   Proxyserver and port number to use
    -V              Print version number and exit
    -k              Use HTTP KeepAlive feature
    -d              Do not show percentiles served table.
    -S              Do not show confidence estimators and warnings.
    -q              Do not show progress when doing more than 150 requests
    -l              Accept variable document length (use this for dynamic pages)
    -g filename     Output collected data to gnuplot format file.
    -e filename     Output CSV file with percentages served
    -r              Don't exit on socket receive errors.
    -m method       Method name
    -h              Display usage information (this message)
    -I              Disable TLS Server Name Indication (SNI) extension
    -Z ciphersuite  Specify SSL/TLS cipher suite (See openssl ciphers)
    -f protocol     Specify SSL/TLS protocol
                    (SSL2, TLS1, TLS1.1, TLS1.2 or ALL)

 

 

AB 명령어 출력 결과

출력 항목 설명
Server Software: Apache - 아파치 버전
Server Hostname: www.naver.com - 도메인명
Server Port: 80 - 웹서비스 사용 포트
Document Path: / - 초기문서가 위치하는 웹문서 root(서버 내의 절대경로가 아님)
Document Length: 72226 bytes - 초기문서의 용량
Concurrency Level: 1 - 동시성 레벨
Time taken for tests: 0.016 seconds - 응답속도
- Time taken for tests 값이 제일 중요
Complete requests: 1 - 요구에 응답한 세션수
Failed requests: 0 - 요구에 응답실패한 세션수
Broken pipe errors: 0 - 실패한 에러수
Total transferred: 72539 bytes - 총 전송 바이트수
HTML transferred: 72226 bytes - 총 전송한 HTML 바이트수
Requests per second: 62.50 【#/sec】
(mean)
- 초당 응답요구수
Time per request: 16.00 【ms】
(mean)
- 요구에 응답한 시간
- Time per request 값이 중요
Time per request: 16.00 【ms】
(mean, across all concurrent requests)
- 요구에 응답한 시간
Transfer rate: 4533.69 【Kbytes/sec】
received
- 초당 전송 가능한 용량

 

 

Client 측 ab 부하테스트 호출 테스트

1. 요청 400, 동시접속자 1

$ ab -n 400 -c 1 http://[도메인]:80/while.jsp
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/


Benchmarking [도메인] (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Finished 400 requests


Server Software:       
Server Hostname:        [도메인]
Server Port:            80


Document Path:          /while.jsp
Document Length:        2 bytes


Concurrency Level:      1
Time taken for tests:   10.191 seconds                      ### 총 시간
Complete requests:      400
Failed requests:        0                                   ### 에러 수
Write errors:           0
Total transferred:      97200 bytes
HTML transferred:       800 bytes
Requests per second:    39.25 [#/sec] (mean)            ==> 초당 처리 Request 수
Time per request:       25.476 [ms] (mean)                ==> Request 당 처리 시간


Time per request:       25.476 [ms] (mean, across all concurrent requests)
Transfer rate:          9.31 [Kbytes/sec] received


Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.0      0       1
Processing:    21   25   5.7     23      59
Waiting:       21   25   5.7     23      59
Total:         21   25   5.7     23      59


Percentage of the requests served within a certain time (ms)
  50%     23
  66%     25
  75%     28
  80%     28
  90%     30
  95%     37
  98%     44
  99%     53
 100%     59 (longest request)

 

 

2. 요청 400, 동시접속자 2

$ ab -n 400 -c 2 http://[도메인]:80/while.jsp
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/


Benchmarking [도메인] (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Finished 400 requests


Server Software:       
Server Hostname:        [도메인]
Server Port:            80


Document Path:          /while.jsp
Document Length:        2 bytes


Concurrency Level:      2
Time taken for tests:   10.103 seconds
Complete requests:      400
Failed requests:        0
Write errors:           0
Total transferred:      97200 bytes
HTML transferred:       800 bytes
Requests per second:    39.59 [#/sec] (mean)
Time per request:       50.514 [ms] (mean)
Time per request:       25.257 [ms] (mean, across all concurrent requests)
Transfer rate:          9.40 [Kbytes/sec] received


Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.0      0       1
Processing:    22   50  16.1     49     152
Waiting:       22   50  16.1     49     152
Total:         22   50  16.1     49     152


Percentage of the requests served within a certain time (ms)
  50%     49
  66%     53
  75%     58
  80%     63
  90%     73
  95%     77
  98%     87
  99%     94
 100%    152 (longest request)

 

 

3. 요청 400, 동시접속자 10

$ ab -n 400 -c 10 http://[도메인]:80/while.jsp
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/


Benchmarking [도메인] (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Finished 400 requests


Server Software:       
Server Hostname:        [도메인]
Server Port:            80


Document Path:          /while.jsp
Document Length:        2 bytes


Concurrency Level:      10
Time taken for tests:   10.262 seconds
Complete requests:      400
Failed requests:        0
Write errors:           0
Total transferred:      97200 bytes
HTML transferred:       800 bytes
Requests per second:    38.98 [#/sec] (mean)
Time per request:       256.540 [ms] (mean)
Time per request:       25.654 [ms] (mean, across all concurrent requests)
Transfer rate:          9.25 [Kbytes/sec] received


Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.0      0       1
Processing:    24  254 111.9    240     681
Waiting:       24  254 111.9    240     681
Total:         24  254 111.9    241     682


Percentage of the requests served within a certain time (ms)
  50%    241
  66%    289
  75%    338
  80%    364
  90%    408
  95%    443
  98%    500
  99%    560
 100%    682 (longest request)

 

 

4. 요청 400, 동시접속자 20

$ ab -n 400 -c 20 http://[도메인]:80/while.jsp
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/


Benchmarking [도메인] (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Finished 400 requests


Server Software:       
Server Hostname:        [도메인]
Server Port:            80


Document Path:          /while.jsp
Document Length:        2 bytes


Concurrency Level:      20
Time taken for tests:   10.454 seconds
Complete requests:      400
Failed requests:        0
Write errors:           0
Total transferred:      97200 bytes
HTML transferred:       800 bytes
Requests per second:    38.26 [#/sec] (mean)
Time per request:       522.718 [ms] (mean)
Time per request:       26.136 [ms] (mean, across all concurrent requests)
Transfer rate:          9.08 [Kbytes/sec] received


Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.2      0       3
Processing:    24  514 273.4    515    1592
Waiting:       24  514 273.5    515    1592
Total:         25  514 273.4    515    1592


Percentage of the requests served within a certain time (ms)
  50%    515
  66%    624
  75%    676
  80%    711
  90%    822
  95%    996
  98%   1230
  99%   1284
 100%   1592 (longest request)

 

 

5. 요청 400, 동시접속자 50

$ ab -n 400 -c 50 http://[도메인]:80/while.jsp
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/


Benchmarking [도메인] (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Finished 400 requests


Server Software:       
Server Hostname:        [도메인]
Server Port:            80


Document Path:          /while.jsp
Document Length:        2 bytes


Concurrency Level:      50
Time taken for tests:   10.614 seconds
Complete requests:      400
Failed requests:        0
Write errors:           0
Total transferred:      97200 bytes
HTML transferred:       800 bytes
Requests per second:    37.69 [#/sec] (mean)
Time per request:       1326.737 [ms] (mean)
Time per request:       26.535 [ms] (mean, across all concurrent requests)
Transfer rate:          8.94 [Kbytes/sec] received


Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.4      0       2
Processing:    25 1264 411.7   1265    2826
Waiting:       23 1264 411.7   1265    2826
Total:         25 1264 411.5   1266    2827


Percentage of the requests served within a certain time (ms)
  50%   1266
  66%   1418
  75%   1506
  80%   1561
  90%   1780
  95%   1948
  98%   2222
  99%   2323
 100%   2827 (longest request)

 

 

6. 요청 400, 동시접속자 100

$ ab -n 400 -c 100 http://[도메인]:80/while.jsp
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/


Benchmarking [도메인] (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Finished 400 requests


Server Software:       
Server Hostname:        [도메인]
Server Port:            80


Document Path:          /while.jsp
Document Length:        2 bytes


Concurrency Level:      100
Time taken for tests:   10.580 seconds
Complete requests:      400
Failed requests:        0
Write errors:           0
Total transferred:      97200 bytes
HTML transferred:       800 bytes
Requests per second:    37.81 [#/sec] (mean)
Time per request:       2645.001 [ms] (mean)
Time per request:       26.450 [ms] (mean, across all concurrent requests)
Transfer rate:          8.97 [Kbytes/sec] received


Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    1   1.4      0       5
Processing:    28 2377 679.8   2498    3706
Waiting:       23 2376 679.8   2498    3706
Total:         29 2378 678.8   2499    3706


Percentage of the requests served within a certain time (ms)
  50%   2499
  66%   2675
  75%   2807
  80%   2840
  90%   2995
  95%   3176
  98%   3394
  99%   3534
 100%   3706 (longest request)

 

 

7. 요청 400, 동시접속자 200

$ ab -n 400 -c 200 http://[도메인]:80/while.jsp
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/


Benchmarking [도메인] (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Finished 400 requests


Server Software:       
Server Hostname:        [도메인]
Server Port:            80


Document Path:          /while.jsp
Document Length:        2 bytes


Concurrency Level:      200
Time taken for tests:   9.756 seconds
Complete requests:      400
Failed requests:        0
Write errors:           0
Total transferred:      97200 bytes
HTML transferred:       800 bytes
Requests per second:    41.00 [#/sec] (mean)
Time per request:       4877.980 [ms] (mean)
Time per request:       24.390 [ms] (mean, across all concurrent requests)
Transfer rate:          9.73 [Kbytes/sec] received


Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    3   3.2      2       9
Processing:    32 3750 1525.0   4534    6111
Waiting:       22 3750 1524.9   4528    6111
Total:         32 3753 1522.0   4535    6111


Percentage of the requests served within a certain time (ms)
  50%   4535
  66%   4719
  75%   4896
  80%   4978
  90%   5173
  95%   5265
  98%   5612
  99%   5727
 100%   6111 (longest request)

 

 

테스트 시나리오 결과 해석

1. 본 테스트의 시나리오는 전체 요청 수인 400 Request를 처리

2. 동시 요청이 1, 2, 10, 20, 50, 100, 200일 경우 성능의 변화를 모니터링하는 것

요청 동시 접속 총소요시간(Sec) 실패 초당처리속도 개별처리속도(Sec)
400 1 10.191 0 39.25 0.025476 / 1
400 2 10.103 0 39.59 0.050514 / 2
400 10 10.262 0 38.98 0.25654 / 10
400 20 10.454 0 38.26 0.522718 / 20
400 50 10.614 0 37.69 1.326737 / 50
400 100 10.58 0 37.81 2.645001 / 100
400 200 9.756 0 41 4.87798 / 200

 

3. 동시 접속자가 늘어나도 초당 처리 속도는 비슷하게 측정 → 400 / 200 (총 요청 수 / 동시 요청 수)일 경우 초당 처리 요청이 가능 많음

4. Single Instance의 처리 속도 아래 표의 결과는 LoadBalancer를 두고 처리할 성능 지표

요청 동시 접속 총소요시간(Sec) 실패 초당처리속도 개별처리속도(Sec)
400 200 9.163 0 43.65 2.811523

 

5. 한대의 서버에서 테스트가 힘들면, 서버의 대수를 늘리면 됨

6. 수동의 작업들을 완전히 자동화 해주는 오토스켈링(AutoScaling)과 ELB가 만나게 되면 엄청난 시너지 효과를 내타냄

 

 

참고 URL

  1. https://blog.hkwon.me/ab-apache-http-server-benchmarking-tool/
  2. https://newstars.cloud/440
  3. https://m.blog.naver.com/PostView.naver?isHttpsRedirect=true&blogId=pcmola&logNo=222073832278
  4. https://colt357.tistory.com/164
  5. https://waspro.tistory.com/418
  • siege 부하테스트는 대규모 테스트보다는 개발한 페이지 단위의 테스트에 적합
  • 개발자가 개발하면서 동시에 테스트해 정량적 데이터를 기준으로 성능 개선이 가능한 점이 편리함
  • siege는 유닉스 기반의 명령행 기반 툴으로, GNU GPL 오픈소스 라이선스를 따르기 때문에 사용, 수정, 배포가 모두 무료
  • siege는 단일 URL의 부하 테스트는 물론 많은 URL을 메모리로 불러들여 사용자가 설정한 시뮬레이션 유저만큼의 부하를 동시에 테스트할 수 있음
  • 기록된 총 히트수와 전송된 바이트수, 반응시간, 병행성(Concurrency), 리턴 상태 등을 보여주며, HTTP 1.0/1.1 프로토콜, GET/POST 디렉티브, 쿠키, 트랜잭션 로깅, 기본적인 인증 등을 지원

 

1. Linux에서 siege HTTP 부하 테스트 유틸리티 설치

1.1. CentOS/RHEL에서 siege 설치

$ yum groupinstall 'Development Tools'
$ yum install -y epel-release
$ yum install -y siege


# 설치 후 siege 버전 확인
$ siege --version
SIEGE 4.1.1

Copyright (C) 2021 by Jeffrey Fulmer, et al.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE.

 

 

1.2. wget 명령어를 사용하여 최신 버전의 siege를 다운로드 후에 설치

# 최신 버전은 siege 다운로드 및 압축 해제
$ wget http://download.joedog.org/siege/siege-latest.tar.gz
$ tar -zxvf siege-latest.tar.gz
$ cd siege-*/


# 컴파일 및 설치
$ ./configure --prefix=/usr/local --with-ssl=/usr/bin/openssl
$ make
$ make install


# 설치된 siege 명령어 위치 확인
$ which siege
/usr/local/bin/siege


# 설치 후 siege 버전 확인
$ siege --version
SIEGE 4.1.5

Copyright (C) 2022 by Jeffrey Fulmer, et al.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE.

 

 

2. Linux에서 Siege HTTP로드 테스트 유틸리티 구성

  • 설치를 완료하면 Siege 구성 파일 조정 가능
    1. yum을 통해 siege 명령어를 다운받는 경우 생성 구성 파일 : /etc/siege/siegerc
    2. 소스에서 패키지를 빌드로 설치한 경우 생성 구성 파일 ; /usr/local/bin/siege.config
      # ~/.siege/siege.conf에있는 siege.conf 파일이 생성
      $ siege.config

 

  • siegerc 파일 또는 siege.conf 파일 확인 → siege이 1 분에 25 명의 동시 사용자를 모방
    $ cat siegerc | grep -ivE "^$|#"
    verbose = true
    color = on
    quiet = false
    json_output = false
    show-logfile = true
    logging = false
    logfile = ${HOME}/siege.log
    gmethod = HEAD
    parser = true
    nofollow = ad.doubleclick.net
    nofollow = pagead2.googlesyndication.com
    nofollow = ads.pubsqrd.com
    nofollow = ib.adnxs.com
    limit = 255
    protocol = HTTP/1.1
    chunked = true
    cache = false
    connection = close
    concurrent = 25
    delay = 0.0
    internet = false
    benchmark = false
    accept-encoding = gzip, deflate
    url-escaping = true
    unique = true

 

 

3 siege 명령어 사용 옵션

옵션 설명
-C - 특정한 구성 파일 지정
-q - siege의 출력을 억제
-g - GET, HTTP 헤더를 풀다운하고 트랜잭션을 표시
- 디버깅에 유용
-c - 동시 사용자 수 설정
- 기본값은 10
-r - 테스트를 실행할 횟수
-t - 테스트를 실행할 시간 설정
- 테스트 실행 시간 단윈 : S, M, H
- 예시 : -t 10S → 10초 동안 테스트 지정
-d - 각 사용자 요청 사이의 시간 지연 지정
-b - 요청 사이에 지연이 없도록 설정
-i - user 시뮬레이션
- 임의의 URL을 적중하는 데 사용
-f - 지정된 파일에서 URL을 테스트
-l - 로그 파일 지정
-H - 요청할 헤더를 추가함
-A - 사용자 에이전드(User-Agent)를 지정
-T - 요청의 Content-Type을 지정
--no-parser - HTML 페이지 parser를 off
--no-follow - HTTP 리디렉션을 따르지 않음

 

 

4. siege 출력 결과 설명

구분 설명
Transactions - HTTP 요청횟수
- 예상되는 히트 수보다 더 많이 출력 가능
- 리다이렉션이나 인증문제로 2개의 히트를 하나로 계산하지 않음 → HTTP 사용을 따르는 브라우저 동작을 모방
Availability - 서버가 성공적으로 처리하는 소켓 연결의 확률
- 성공 횟수/연결시도 횟수 * 100 ( 400, 500 에러 제외)
Elapsed time - 전체 siege 테스트 하는데 걸리는 시간
Data transferred - siege가 시뮬레이션 된 브라우저에 전송하는 전체 데이터량
- 전체 데이터는 컨텐츠 뿐만 아니라 헤더 정보까지 포함
- 헤더 정보를 포함하기에 , siege가 표시하는 전체 데이터량은 서버가 전달하는 양보다 큼
- 특정 설정 파일에 있는 임의의 URL을 사용하는 internet 모드로 설정된 상황에서는 전체 전송 데이터량은 동작할 때마다 각각 값이 달라짐
Response time - siege가 시뮬레이션 된 브라우저의 각 요청에 대해 걸린 평균 응답시간
Transaction rate - 서버가 초당 처리할수 있는 트랜잭션 개수
Throughput - 서버에서 시뮬레이션 된 브라우저로 초당 전송되는 평균바이트단위의 데이터량
Concurrency - 동시 연결할수 있는 평균 개수이고, 증가할때마다 서버의 성능은 저하됨
Successful transactions - 트랜젝션 성공 횟수
- 서버가 400 이하의 응답코드를 반환하는 횟수
Failed transactions - 트랜젝션 실패 횟수
- 서버가 400 혹은 그이상의 응답코드를 반환하는 횟수
- 타임아웃 횟수를 포함한 소켓 연결이 실패된 트랜잭션의 합계도 나타냄
Longest transaction - 모든 트랜잭션중 단일 트랜잭션 처리에 걸린 가장 긴시간
Shortest transaction - 모든 트랜잭션중 단일 트랜잭션 처리에 걸린 가장 짧은 시간

 

 

5. siege 테스트

5.1. 1명의 가상의 유저가 1초동안 무제한으로 계속해서 접속 부하 테스트 (지연 X)

$ siege -c1 -t1s http://[domain]/test/upload/1.jpg
** SIEGE 4.1.1
** Preparing 1 concurrent users for battle.
The server is now under siege...
HTTP/1.1 200     0.04 secs:  152849 bytes ==> GET  /test/upload/1.jpg
HTTP/1.1 200     0.01 secs:  152849 bytes ==> GET  /test/upload/1.jpg
HTTP/1.1 200     0.04 secs:  152849 bytes ==> GET  /test/upload/1.jpg
....생략....
HTTP/1.1 200     0.01 secs:  152849 bytes ==> GET  /test/upload/1.jpg
HTTP/1.1 200     0.00 secs:  152849 bytes ==> GET  /test/upload/1.jpg
HTTP/1.1 200     0.01 secs:  152849 bytes ==> GET  /test/upload/1.jpg

Lifting the server siege...
Transactions:                     95 hits
Availability:                 100.00 %
Elapsed time:                   0.57 secs
Data transferred:              13.85 MB
Response time:                  0.01 secs
Transaction rate:             166.67 trans/sec
Throughput:                    24.29 MB/sec
Concurrency:                    0.98
Successful transactions:          95
Failed transactions:               0
Longest transaction:            0.04
Shortest transaction:           0.00

 

 

5.2. 1명의 가상의 유저가 1초동안 1초 간격으로 계속해서 접속 부하 테스트 (가상 유저의 요청 간격은 1초)

$ siege -c1 -t1s -d 1 http://[도메인]/test/upload/1.jpg
** SIEGE 4.1.1
** Preparing 1 concurrent users for battle.
The server is now under siege...
HTTP/1.1 200     0.08 secs:  152849 bytes ==> GET  /test/upload/1.jpg
HTTP/1.1 200     0.00 secs:  152849 bytes ==> GET  /test/upload/1.jpg

Lifting the server siege...
Transactions:                      2 hits
Availability:                 100.00 %
Elapsed time:                   0.34 secs
Data transferred:               0.29 MB
Response time:                  0.04 secs
Transaction rate:               5.88 trans/sec
Throughput:                     0.86 MB/sec
Concurrency:                    0.24
Successful transactions:           2
Failed transactions:               0
Longest transaction:            0.08
Shortest transaction:           0.00

 

 

5.3. 10명의 가상의 유저가 1초동안 1초 간격으로 계속해서 접속 부하 테스트 (가상 유저의 요청 간격은 1초)

$ siege -c10 -t1s -d 1 http://[도메인]/test/upload/1.jpg
** SIEGE 4.1.1
** Preparing 10 concurrent users for battle.
The server is now under siege...
HTTP/1.1 200     0.04 secs:  152849 bytes ==> GET  /test/upload/1.jpg
HTTP/1.1 200     0.04 secs:  152849 bytes ==> GET  /test/upload/1.jpg
HTTP/1.1 200     0.04 secs:  152849 bytes ==> GET  /test/upload/1.jpg
HTTP/1.1 200     0.05 secs:  152849 bytes ==> GET  /test/upload/1.jpg
HTTP/1.1 200     0.05 secs:  152849 bytes ==> GET  /test/upload/1.jpg
HTTP/1.1 200     0.05 secs:  152849 bytes ==> GET  /test/upload/1.jpg
HTTP/1.1 200     0.05 secs:  152849 bytes ==> GET  /test/upload/1.jpg
HTTP/1.1 200     0.05 secs:  152849 bytes ==> GET  /test/upload/1.jpg
HTTP/1.1 200     0.05 secs:  152849 bytes ==> GET  /test/upload/1.jpg
HTTP/1.1 200     0.00 secs:  152849 bytes ==> GET  /test/upload/1.jpg
HTTP/1.1 200     0.05 secs:  152849 bytes ==> GET  /test/upload/1.jpg
HTTP/1.1 200     0.01 secs:  152849 bytes ==> GET  /test/upload/1.jpg
HTTP/1.1 200     0.01 secs:  152849 bytes ==> GET  /test/upload/1.jpg
HTTP/1.1 200     0.00 secs:  152849 bytes ==> GET  /test/upload/1.jpg
HTTP/1.1 200     0.00 secs:  152849 bytes ==> GET  /test/upload/1.jpg
HTTP/1.1 200     0.01 secs:  152849 bytes ==> GET  /test/upload/1.jpg

Lifting the server siege...
Transactions:                     16 hits
Availability:                 100.00 %
Elapsed time:                   0.34 secs
Data transferred:               2.33 MB
Response time:                  0.03 secs
Transaction rate:              47.06 trans/sec
Throughput:                     6.86 MB/sec
Concurrency:                    1.47
Successful transactions:          16
Failed transactions:               0
Longest transaction:            0.05
Shortest transaction:           0.04

 

 

5.4. 10명의 가상의 유저가 10회 반복으로 접속 부하 테스트

$ siege -c10 -r 10 http://[도메인]/test/upload/1.jpg
** SIEGE 4.1.1
** Preparing 10 concurrent users for battle.
The server is now under siege...
HTTP/1.1 200     0.04 secs:  152849 bytes ==> GET  /test/upload/1.jpg
HTTP/1.1 200     0.04 secs:  152849 bytes ==> GET  /test/upload/1.jpg
HTTP/1.1 200     0.04 secs:  152849 bytes ==> GET  /test/upload/1.jpg
...생략...
HTTP/1.1 200     0.01 secs:  152849 bytes ==> GET  /test/upload/1.jpg
HTTP/1.1 200     0.01 secs:  152849 bytes ==> GET  /test/upload/1.jpg
HTTP/1.1 200     0.01 secs:  152849 bytes ==> GET  /test/upload/1.jpg

Transactions:                    100 hits
Availability:                 100.00 %
Elapsed time:                   0.17 secs
Data transferred:              14.58 MB
Response time:                  0.02 secs
Transaction rate:             588.24 trans/sec
Throughput:                    85.75 MB/sec
Concurrency:                    9.41
Successful transactions:         100
Failed transactions:               0
Longest transaction:            0.06
Shortest transaction:           0.00

 

 

5.5. 1명의 가상의 유저가 특정 파일의 URL을 읽어서 접속 부하 테스트

# dims_list.txt 파일에는 서로 다른 URL 있음(위 URL 묶음을 넣을 수 있음)
$ siege -c1 -r 40 -f dims_list.txt
** SIEGE 4.1.1
** Preparing 1 concurrent users for battle.
The server is now under siege...
HTTP/1.1 200     0.06 secs:  140803 bytes ==> GET  /test/upload/1.jpg/dims/resize/500X500
HTTP/1.1 200     0.05 secs:  183271 bytes ==> GET  /test/upload/2.jpg/dims/resize/500X500
HTTP/1.1 200     0.35 secs:  350565 bytes ==> GET  /test/upload/3.jpg/dims/resize/500X500
HTTP/1.1 200     0.04 secs:  101547 bytes ==> GET  /test/upload/4.jpg/dims/resize/500X500
...생략...
HTTP/1.1 200     0.04 secs:  151130 bytes ==> GET  /test/upload/36.jpg/dims/resize/500X500
HTTP/1.1 200     0.04 secs:  130278 bytes ==> GET  /test/upload/37.jpg/dims/resize/500X500
HTTP/1.1 200     0.05 secs:  161169 bytes ==> GET  /test/upload/38.jpg/dims/resize/500X500
HTTP/1.1 200     0.04 secs:  150939 bytes ==> GET  /test/upload/39.jpg/dims/resize/500X500
HTTP/1.1 200     0.04 secs:  133090 bytes ==> GET  /test/upload/40.jpg/dims/resize/500X500

Transactions:                     40 hits
Availability:                 100.00 %
Elapsed time:                   2.40 secs
Data transferred:               6.87 MB
Response time:                  0.06 secs
Transaction rate:              16.67 trans/sec
Throughput:                     2.86 MB/sec
Concurrency:                    1.00
Successful transactions:          40
Failed transactions:               0
Longest transaction:            0.36
Shortest transaction:           0.03

 

 

5.6. 40명의 가상의 유저가 특정 파일의 URL을 읽어서 접속 부하 테스트

# dims_list.txt 파일에는 서로 다른 URL 있음(위 URL 묶음을 넣을 수 있음)
$ siege -c40 -r 1 -f dims_list.txt
** SIEGE 4.1.1
** Preparing 40 concurrent users for battle.
The server is now under siege...
HTTP/1.1 200     0.08 secs:  173928 bytes ==> GET  /test/upload/11.jpg/dims/resize/500X500
HTTP/1.1 200     0.08 secs:  130312 bytes ==> GET  /test/upload/5.jpg/dims/resize/500X500
HTTP/1.1 200     0.08 secs:  241077 bytes ==> GET  /test/upload/28.jpg/dims/resize/500X500
HTTP/1.1 200     0.09 secs:  116310 bytes ==> GET  /test/upload/12.jpg/dims/resize/500X500
HTTP/1.1 200     0.09 secs:  181265 bytes ==> GET  /test/upload/14.jpg/dims/resize/500X500
...생략...
HTTP/1.1 200     0.21 secs:  200534 bytes ==> GET  /test/upload/26.jpg/dims/resize/500X500
HTTP/1.1 200     0.22 secs:  249170 bytes ==> GET  /test/upload/9.jpg/dims/resize/500X500
HTTP/1.1 200     0.41 secs:  360241 bytes ==> GET  /test/upload/13.jpg/dims/resize/500X500
HTTP/1.1 200     0.47 secs:  350565 bytes ==> GET  /test/upload/3.jpg/dims/resize/500X500

Transactions:                     40 hits
Availability:                 100.00 %
Elapsed time:                   0.47 secs
Data transferred:               6.87 MB
Response time:                  0.15 secs
Transaction rate:              85.11 trans/sec
Throughput:                    14.63 MB/sec
Concurrency:                   12.51
Successful transactions:          40
Failed transactions:               0
Longest transaction:            0.47
Shortest transaction:           0.08

 

 

5.7. 200명의 가상의 유저가 특정 파일의 URL을 읽어서 접속 부하 테스트

# 200_dims_list.txt 파일에 resize 크기만 다르게 하여서 200개 생성
$ siege -c200 -r 1 -f 200_dims_list.txt
** SIEGE 4.1.1
** Preparing 200 concurrent users for battle.
The server is now under siege...
HTTP/1.1 200     0.11 secs:   22699 bytes ==> GET  /test/upload/12.jpg/dims/resize/200X200
HTTP/1.1 200     0.12 secs:  218332 bytes ==> GET  /test/upload/37.jpg/dims/resize/700X700
HTTP/1.1 200     0.13 secs:   25510 bytes ==> GET  /test/upload/31.jpg/dims/resize/200X200
HTTP/1.1 200     0.16 secs:  130278 bytes ==> GET  /test/upload/37.jpg/dims/resize/500X500
HTTP/1.1 200     0.16 secs:   27489 bytes ==> GET  /test/upload/39.jpg/dims/resize/200X200
HTTP/1.1 200     0.22 secs:  131463 bytes ==> GET  /test/upload/35.jpg/dims/resize/500X500
HTTP/1.1 200     0.26 secs:   31468 bytes ==> GET  /test/upload/36.jpg/dims/resize/200X200
...생략...
HTTP/1.1 200     2.91 secs: 1531300 bytes ==> GET  /test/upload/14.jpg/dims/resize/2100X2100
HTTP/1.1 200     2.93 secs: 1870440 bytes ==> GET  /test/upload/2.jpg/dims/resize/2100X2100
HTTP/1.1 200     2.94 secs: 1286358 bytes ==> GET  /test/upload/38.jpg/dims/resize/2100X2100
HTTP/1.1 200     3.11 secs:  350565 bytes ==> GET  /test/upload/3.jpg/dims/resize/500X500
HTTP/1.1 200     3.26 secs:  621024 bytes ==> GET  /test/upload/13.jpg/dims/resize/700X700
HTTP/1.1 200     3.31 secs:   68988 bytes ==> GET  /test/upload/3.jpg/dims/resize/200X200
HTTP/1.1 200     3.60 secs:  360241 bytes ==> GET  /test/upload/13.jpg/dims/resize/500X500
HTTP/1.1 200     3.64 secs:  609878 bytes ==> GET  /test/upload/3.jpg/dims/resize/700X700
HTTP/1.1 200     4.56 secs: 1044667 bytes ==> GET  /test/upload/3.jpg/dims/resize/1000X1000
HTTP/1.1 200     6.75 secs: 3148711 bytes ==> GET  /test/upload/3.jpg/dims/resize/2100X2100
HTTP/1.1 200     7.96 secs: 3231253 bytes ==> GET  /test/upload/13.jpg/dims/resize/2100X2100

Transactions:                    200 hits
Availability:                 100.00 %
Elapsed time:                   7.98 secs
Data transferred:             100.42 MB
Response time:                  1.60 secs
Transaction rate:              25.06 trans/sec
Throughput:                    12.58 MB/sec
Concurrency:                   40.20
Successful transactions:         200
Failed transactions:               0
Longest transaction:            7.96
Shortest transaction:           0.11
  • docker system info 명령어를 통해 Docker 실행 환경의 상세 설정이 표시
  • 출력되는 결과 내용 설명
    1. Containers → 컨테이너의 수
    2. Images → 이미지의 수
    3. Server Version → Docker 버전
    4. Storage Driver → 스토리지 드라이버 종류
    5. Kernel Version → 커널 버전
    6. Operating System → OS 버전
    7. OSType → OS 종류
    8. Architecture → 아키텍처
    9. CPUs → 사용 CPU
    10. Total Memory → 사용 메모리
    11. Docker Root Dir → Docker 파일이 저장되는 root 디렉토리 위치 (/var/lib/docker)

  • docker 실행 환경 확인

    $ docker system info
    Client:
     Context:    default
     Debug Mode: false
     Plugins:
      app: Docker App (Docker Inc., v0.9.1-beta3)
      buildx: Build with BuildKit (Docker Inc., v0.5.1-docker)
      scan: Docker Scan (Docker Inc., v0.8.0)
    
    Server:
     Containers: 0
      Running: 0
      Paused: 0
      Stopped: 0
     Images: 0
     Server Version: 20.10.7
     Storage Driver: overlay2
      Backing Filesystem: xfs
      Supports d_type: true
      Native Overlay Diff: true
      userxattr: false
     Logging Driver: json-file
     Cgroup Driver: cgroupfs
     Cgroup Version: 1
     Plugins:
      Volume: local
      Network: bridge host ipvlan macvlan null overlay
      Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
     Swarm: inactive
     Runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runc
     Default Runtime: runc
     Init Binary: docker-init
     containerd version: 7eba5930496d9bbe375fdf71603e610ad737d2b2
     runc version: v1.0.0-0-g84113ee
     init version: de40ad0
     Security Options:
      seccomp
       Profile: default
     Kernel Version: 3.10.0-1160.36.2.el7.x86_64
     Operating System: CentOS Linux 7 (Core)
     OSType: linux
     Architecture: x86_64
     CPUs: 2
     Total Memory: 1.777GiB
     Name: centos-docker
     ID: FAHK:ZAD7:CAIO:CWZQ:BL5B:6B6F:637K:J3DR:SNKQ:LVOG:OGQJ:QMAM
     Docker Root Dir: /var/lib/docker
     Debug Mode: false
     Username: hippo7788
     Registry: https://index.docker.io/v1/
     Labels:
     Experimental: false
     Insecure Registries:
      127.0.0.0/8
     Live Restore Enabled: false

  • 설정한 Docker 버전을 확인

  • docker version 명령을 실행하면 Docker의 버전이나 Go 언어의 버전, OS, 아키텍처를 확인 가능

  • Docker는 클라이언트/서버 아키텍처를 채택하고 있음 → Docker 클라이언트와 Dcoker 서버는 Remote API를 통해 연결

  • docker 명령어는 클라이언트에서 실행하면 서버로 보내져서 처리됨

    $ docker version
    Client: Docker Engine - Community
     Version:           20.10.7
     API version:       1.41
     Go version:        go1.13.15
     Git commit:        f0df350
     Built:             Wed Jun  2 11:58:10 2021
     OS/Arch:           linux/amd64
     Context:           default
     Experimental:      true
    
    Server: Docker Engine - Community
     Engine:
      Version:          20.10.7
      API version:      1.41 (minimum version 1.12)
      Go version:       go1.13.15
      Git commit:       b0f5bc3
      Built:            Wed Jun  2 11:56:35 2021
      OS/Arch:          linux/amd64
      Experimental:     false
     containerd:
      Version:          1.4.8
      GitCommit:        7eba5930496d9bbe375fdf71603e610ad737d2b2
     runc:
      Version:          1.0.0
      GitCommit:        v1.0.0-0-g84113ee
     docker-init:
      Version:          0.19.0
      GitCommit:        de40ad0

1. 컨테이너와 호스트 간의 file 전송 명령어

  • docker cp <container name>:<path> <host경로> 또는 docker cp <host경로> <container name>:<path> 명령어로 사용

    # 실행할 이미지 확인
    $ docker images
    REPOSITORY              TAG       IMAGE ID                   CREATED          SIZE
    test                           vol         b00a026e35cd       51 minutes ago   133MB
    locahost:5000/vol       v1          b00a026e35cd      51 minutes ago   133MB
    localhost:5000/vol      v1          b00a026e35cd      51 minutes ago   133MB
    test                           user       0e7f2d0690f8        2 hours ago        73.1MB
    ubuntu                      latest      1318b700e415      5 hours ago        72.8MB
    forestian/test             web        d19fbcd7480b       18 hours ago      133MB
    nginx                        latest      08b152afcfae        4 days ago          133MB
    registry                     latest      1fd8e1b0bb7e       3 months ago      26.2MB
    
    # 테스트 켄터이너 실행
    $ docker run --rm -d -it test:vol /bin/bash
    
    # 실행하는 컨테이너 확인
    $ docker ps
    CONTAINER ID   IMAGE      COMMAND                  CREATED          STATUS             PORTS        NAMES
    df8bc7355db0   test:vol   "/docker-entrypoint.…"   3 minutes ago    Up 3 minutes    80/tcp        wonderful_burnell
    
    # 해당 명령어의 파일 없음
    $ docker exec -it df8 ls /bin/ip
    Error: No such container: test:vol
    
    # web 이름을 가진 컨테이너에 host가 가지고 있는 /usr/sbin/ip 파일을 /bin/디렉토리 아래에 복사
    $ docker cp /usr/sbin/ip df8:/bin/
    
    # 해당 명령어의 파일이 정상적으로 복사됨 확인
    $ docker exec -it df8 ls /bin/ip
    /bin/ip

2. 변경된 컨테이너 file 조회

  • docker diff <container name> 명령어로 사용
  • 이미지와 Container를 비교하여 변경된 파일 목록 출력
    1. A → add
    2. C → change
    3. D → delete
  • 변경된 컨테이너 file 조회 예시

    $ docker ps
    CONTAINER ID   IMAGE      COMMAND                  CREATED           STATUS            PORTS       NAMES
    df8bc7355db0   test:vol   "/docker-entrypoint.…"   6 minutes ago    Up 6 minutes    80/tcp       wonderful_burnell
    
    $ docker diff df8
    C /bin
    A /bin/ip

3. 변경된 컨테이너 이미지 생성 → 백업 이미지 생성

  • docker commit <options> <container name> <image>:<tag> 명령어로 사용
  • docker commit 명령어 사용 옵션
    1. -a 옵션 → 만든이
    2. -m 옵션 → log 메시지
  • 변경된 컨테이너 이미지 생성 예시

    # 변경된 내용을 가지는 이미지 생성
    $ docker commit -a "hippo" -m "add /bin/ip" df8b nginx:ip
    sha256:96ec98bcb7ac7344d8c36a01601f3ffb202f50a5bfcca6cae21c7624abfc5b64
    
    # 생성된 이미지 확인
    $ docker images
    REPOSITORY              TAG       IMAGE ID                   CREATED          SIZE
    test                           vol         b00a026e35cd       51 minutes ago   133MB
    locahost:5000/vol       v1          b00a026e35cd      51 minutes ago   133MB
    localhost:5000/vol      v1          b00a026e35cd      51 minutes ago   133MB
    test                           user       0e7f2d0690f8        2 hours ago        73.1MB
    ubuntu                      latest      1318b700e415      5 hours ago        72.8MB
    forestian/test             web        d19fbcd7480b       18 hours ago      133MB
    nginx                        latest      08b152afcfae        4 days ago          133MB
    registry                     latest      1fd8e1b0bb7e       3 months ago      26.2MB
    
    # 생성된 이미지를 컨테이너 실행
    $ docker run -d -it --name webip nginx:ip
    2b2f20c81ea677e33e3cda36e6ef8ad21e2dd95dbc69a5b91dcbe6ba9a6851ad
    
    # 실행중인 컨테이너 확인
    $ docker ps
    CONTAINER ID   IMAGE      COMMAND                  CREATED           STATUS              PORTS      NAMES
    2b2f20c81ea6   nginx:ip   "/docker-entrypoint.…"   27 seconds ago   Up 26 seconds   80/tcp       webip
    
    # 추가된 부분에 대한 테스트로 정상적으로 이미지 생성 확인
    $ docker exec webip ip a
    1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
        link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
        inet 127.0.0.1/8 scope host lo
           valid_lft forever preferred_lft forever
    14: eth0@if15: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
        link/ether 02:42:ac:11:00:04 brd ff:ff:ff:ff:ff:ff link-netnsid 0
        inet 172.17.0.4/16 brd 172.17.255.255 scope global eth0
           valid_lft forever preferred_lft forever

4. 컨테이너 상세 정보 조회 → docker inspect <컨테이너 이름>

  • docker inspect <container name> 명령어로 사용

    # 실행중인 컨테이너 확인
    $ docker ps
    CONTAINER ID   IMAGE      COMMAND                  CREATED           STATUS          PORTS           NAMES
    2b2f20c81ea6   nginx:ip   "/docker-entrypoint.…"   2 minutes ago    Up 2 minutes    80/tcp         webip
    
    # 컨테이너의 자세한 내용 조회
    $ docker inspect 2b2 | less
    [
        {
            "Id": "2b2f20c81ea677e33e3cda36e6ef8ad21e2dd95dbc69a5b91dcbe6ba9a6851ad",
            "Created": "2021-07-27T02:31:18.37452262Z",
            "Path": "/docker-entrypoint.sh",
            "Args": [
                "/bin/bash"
            ],
            <...중략...>
                        "IPPrefixLen": 16,
                        "IPv6Gateway": "",
                        "GlobalIPv6Address": "",
                        "GlobalIPv6PrefixLen": 0,
                        "MacAddress": "02:42:ac:11:00:04",
                        "DriverOpts": null
                    }
                }
            }
        }
    ]

5. 네트워크 상세 정보 조회 → docker network inspect <네트워크 이름>

  • docker network inspect <network name> 명령어로 사용

  • docker network ls 명령어로 네트워크 확인 가능

    # 네트워크 리스트 확인
    $ docker network ls
    NETWORK ID     NAME      DRIVER    SCOPE
    855a8e7a6afa    bridge     bridge      local
    dcbe9811b35f    host        host         local
    2143943ba6b0   none       null          local
    
    # brige 이름을 가진 네트워크 상세 정보 확인
    $ docker network inspect bridge
    [
        {
            "Name": "bridge",
            "Id": "855a8e7a6afa6fba6dc9344910adf12d42ebdffd23a6cc19b1e44ce7f1385cf3",
            "Created": "2021-07-27T10:19:48.519226416+09:00",
            "Scope": "local",
            "Driver": "bridge",
            "EnableIPv6": false,
            "IPAM": {
                "Driver": "default",
                "Options": null,
                "Config": [
                    {
                        "Subnet": "172.17.0.0/16",
                        "Gateway": "172.17.0.1"
                    }
                ]
            },
            "Internal": false,
            "Attachable": false,
            "Ingress": false,
            "ConfigFrom": {
                "Network": ""
            },
            "ConfigOnly": false,
            "Containers": {
                "2b2f20c81ea677e33e3cda36e6ef8ad21e2dd95dbc69a5b91dcbe6ba9a6851ad": {
                    "Name": "webip",
                    "EndpointID": "3e0b976ea7976bcaba633304fb487a5417ed892999ba4163887f11477860fb5f",
                    "MacAddress": "02:42:ac:11:00:04",
                    "IPv4Address": "172.17.0.4/16",
                    "IPv6Address": ""
                },
                "d5a02a85daeeb88cb470108f2be7364ee7210d6ea65935baee15579bf25fee63": {
                    "Name": "registry-server",
                    "EndpointID": "9f73284ba8e4e6a799df75c19387fda9d896648ef8c53ec51604066318a54b45",
                    "MacAddress": "02:42:ac:11:00:02",
                    "IPv4Address": "172.17.0.2/16",
                    "IPv6Address": ""
                },
                "df8bc7355db091a33c9b8daa4c28163aeb5a06eba4ff90681c0a7820aa1355f2": {
                    "Name": "wonderful_burnell",
                    "EndpointID": "32bce18ca81d104ca7dc444d56a9094eda69fcd442899e30ea04d03353d06859",
                    "MacAddress": "02:42:ac:11:00:03",
                    "IPv4Address": "172.17.0.3/16",
                    "IPv6Address": ""
                }
            },
            "Options": {
                "com.docker.network.bridge.default_bridge": "true",
                "com.docker.network.bridge.enable_icc": "true",
                "com.docker.network.bridge.enable_ip_masquerade": "true",
                "com.docker.network.bridge.host_binding_ipv4": "0.0.0.0",
                "com.docker.network.bridge.name": "docker0",
                "com.docker.network.driver.mtu": "1500"
            },
            "Labels": {}
        }
    ]
    
    # host 이름을 가진 네트워크 상세 정보 확인
    $ docker network inspect host
    [
        {
            "Name": "host",
            "Id": "dcbe9811b35f5574ebd65b5118d04831440ac6f992ecba14d0881db4f43d64e1",
            "Created": "2021-07-26T13:41:54.007292134+09:00",
            "Scope": "local",
            "Driver": "host",
            "EnableIPv6": false,
            "IPAM": {
                "Driver": "default",
                "Options": null,
                "Config": []
            },
            "Internal": false,
            "Attachable": false,
            "Ingress": false,
            "ConfigFrom": {
                "Network": ""
            },
            "ConfigOnly": false,
            "Containers": {},
            "Options": {},
            "Labels": {}
        }
    ]
    
    # none 이름을 가진 네트워크 상세 정보 확인
    $ docker network inspect none
    [
        {
            "Name": "none",
            "Id": "2143943ba6b0a74a5ef724d5af13b30e0492ce4489bcd1c3d561741040f86514",
            "Created": "2021-07-26T13:41:53.953813947+09:00",
            "Scope": "local",
            "Driver": "null",
            "EnableIPv6": false,
            "IPAM": {
                "Driver": "default",
                "Options": null,
                "Config": []
            },
            "Internal": false,
            "Attachable": false,
            "Ingress": false,
            "ConfigFrom": {
                "Network": ""
            },
            "ConfigOnly": false,
            "Containers": {},
            "Options": {},
            "Labels": {}
        }
    ]

6. 이미지 상세 정보 조회 → docker image inspect <이미지 이름>

  • docker image inspect <image name> 명령어로 사용

  • docker image ls 명령어로 이미지 확인 가능

    # 이미지 리스트 확인
    $ docker image ls
    REPOSITORY              TAG       IMAGE ID                   CREATED          SIZE
    test                           vol         b00a026e35cd       51 minutes ago   133MB
    locahost:5000/vol       v1          b00a026e35cd      51 minutes ago   133MB
    localhost:5000/vol      v1          b00a026e35cd      51 minutes ago   133MB
    test                           user       0e7f2d0690f8        2 hours ago        73.1MB
    ubuntu                      latest      1318b700e415      5 hours ago        72.8MB
    forestian/test             web        d19fbcd7480b       18 hours ago      133MB
    nginx                        latest      08b152afcfae        4 days ago          133MB
    registry                     latest      1fd8e1b0bb7e       3 months ago      26.2MB
    
    # nginx:ip 이름을 가진 이미지의 상세 정보 확인
    $ docker image inspect nginx:ip
    [
        {
            "Id": "sha256:96ec98bcb7ac7344d8c36a01601f3ffb202f50a5bfcca6cae21c7624abfc5b64",
            "RepoTags": [
                "nginx:ip"
            ],
            "RepoDigests": [],
            "Parent": "sha256:b00a026e35cdc01c6ea323dc364d0f091897afb9acb70e8404804dfdfeed98a9",
            "Comment": "add /bin/ip",
            <...중략...>
            "RootFS": {
                "Type": "layers",
                "Layers": [
                    "sha256:814bff7343242acfd20a2c841e041dd57c50f0cf844d4abd2329f78b992197f4",
                    "sha256:7c0b223167b96d7deaacf1e1d2d35892166645b09b17bcc8675a4d882ef84893",
                    "sha256:59b01b87c9e7f668b740d23eb872c5964636c33aef795f1186f08b172197bc35",
                    "sha256:988d9a3509bbb7ea8037d4eba3a5e0ada5dc165144c8ff0df89c0048d1ac6132",
                    "sha256:b857347059916922b353147882544f17bb96e64c639081c0677bf386c446be4f",
                    "sha256:e3135447ca3e69c6975aee1621c406e3865e0e143c807bbdcf05abefa56054a2",
                    "sha256:cbf5cd72e52c438d7b56ef2e4ecec55c7086194447ee3e841c1f0f3cf2d1d57a"
                ]
            },
            "Metadata": {
                "LastTagTime": "2021-07-27T11:27:55.465105417+09:00"
            }
        }
    ]

7. 볼륨 상세 정보 조회 → docker volume inspect <볼륨 이름>

  • docker volume inspect <volume name> 명령어로 사용

  • docker volume create disk → 볼륨 생성

  • docker volume ls 명령어로 볼륨 확인 가능

    # disk1 이름을 가진 volume 생성
    $ docker volume create disk1
    disk1
    
    # 생성된 volume 확인
    $ docker volume ls
    DRIVER    VOLUME NAME
    local         6a78c5df00f787b72e00cc634b8f79ac7679ac1d60985618f59ec8d3cbf96cae
    local         25b16fde993167ac0e3457c7492cbde6e4c0c2cecce9292db248586b2b0c3f55
    local         disk1
    local         e343d977a0e3802e449a20f60f8f9502af45f1324b220cbb33bafea06fa65918
    
    # disk1 이름을 가진 volume의 자센한 내용 확인
    $ docker volume inspect disk1
    [
        {
            "CreatedAt": "2021-07-27T13:08:35+09:00",
            "Driver": "local",
            "Labels": {},
            "Mountpoint": "/var/lib/docker/volumes/disk1/_data",
            "Name": "disk1",
            "Options": {},
            "Scope": "local"
        }
    ]

8. 실시간 events 출력

  • docke events 명령어로 사용

9. container의 로그 확인

  • docke logs <container name> 명령어로 사용
  • --since 옵션을 주면 해당 일 이후 로그 출력
  • 실시간 events 출력

10. container의 filesystem을 tar로 저장

  • docker export <container name> <tar file> 명령어로 사용

11. 이미지를 tar파일 형태로 백업 저장 → docker save image > xxx.tar

  • docke save <image name> > xxx.tar 명령어로 사용

12. 기존 이미지 name으로 restore

  • docke load < xxx.tar 명령어로 사용

13. container의 프로세스 모니터링

  • docker top <contianer name> <option> 명령어로 사용

14. container 단위로 사용량 확인

  • docker status 명령어로 사용

    # 전체 컨테이너의 사용량 확인
    $ docker status
    
    # 특정 컨터이너의 사용량 확인 -> 컨테이너 확인
    $ docker ps
    
    $ docker status

15. volume 사용량 확인

  • docker system df 명령어로 사용
    $ docker system df

16. docker system prune <option> 명령어 사용

  • docker system prune → stop 되어있는 container를 제거

  • docker system prune -a → 컨테이너에서 사용하고 있지 않는 이미지를 모두 제거

    $ docker system prune
    
    $ docker system df
    
    $ docker system prune -a
    
    $ docker system df

1. image 조회 → https://hub.docker.com


2. docker image 조회

  • docker search 명령어를 통해 이미지 검색
    $ docker search nginx
    NAME                                   DESCRIPTION                                                        STARS     OFFICIAL   AUTOMATED
    nginx                                   Official build of Nginx.                                             15210     [OK]
    jwilder/nginx-proxy               Automated Nginx reverse proxy for docker con…       2051                       [OK]
    richarvey/nginx-php-fpm       Container running Nginx + PHP-FPM capable of…       816                         [OK]
    <...생략...>

3. image 다운로드

  • image download 형식 → docker pull <image_name>:<tag>
    $ docker pull nginx:latest
    latest: Pulling from library/nginx
    33847f680f63: Pull complete
    dbb907d5159d: Pull complete
    8a268f30c42a: Pull complete
    b10cf527a02d: Pull complete
    c90b090c213b: Pull complete
    1f41b2f2bf94: Pull complete
    Digest: sha256:8f335768880da6baf72b70c701002b45f4932acae8d574dedfddaf967fc3ac90
    Status: Downloaded newer image for nginx:latest
    docker.io/library/nginx:latest

4. image 삭제

  • image 삭제 형식 → docker rmi <image_name>:<tag>
  • tag 없이 사용시 관련 이미지 모두 삭제 → tag를 해야 모든 이미지 삭제를 막을 수 있음
    $ docker rmi nginx
    Untagged: nginx:latest
    Untagged: nginx@sha256:8f335768880da6baf72b70c701002b45f4932acae8d574dedfddaf967fc3ac90
    Deleted: sha256:08b152afcfae220e9709f00767054b824361c742ea03a9fe936271ba520a0a4b
    Deleted: sha256:97386f823dd75e356afac10af0def601f2cd86908e3f163fb59780a057198e1b
    Deleted: sha256:316cd969204ae854302bc55c610698829c9f23fa6fcd4e0f69afa6f29fedfd68
    Deleted: sha256:dcec23d16cb7cdbd725dc0024f38b39fd326066fc59784df92b40fc05ba3728f
    Deleted: sha256:1e294000374b3a304c2bfcfe51460aa599237149ed42e3423ac2c3f155f9b4a5
    Deleted: sha256:c0d318592b21711dc370e180acd66ad5d42f173d5b58ed315d08b9b09babb84a
    Deleted: sha256:814bff7343242acfd20a2c841e041dd57c50f0cf844d4abd2329f78b992197f4
  • docker rm 컨테이너 → image를 삭제하는 것이 아니라 컨테이너를 삭제하는 명령어

5. 설치한 docker 이미지 위치 확인 → 관리자 계정 root에서 확인 가능

  • 설치한 nginx의 이미지 저장 위치 → /var/lib/docker/image/overlay2/ 디렉토리 아래에 존재
  • /var/lib/docker/image/overlay2/ 디렉토리 아래의 파일 확인
    $ cd /var/lib/docker/image/overlay2/
    $ du
    0         ./layerdb/tmp
    256     ./layerdb/sha256/814bff7343242acfd20a2c841e041dd57c50f0cf844d4abd2329f78b992197f4
    100     ./layerdb/sha256/c0d318592b21711dc370e180acd66ad5d42f173d5b58ed315d08b9b09babb84a
    20       ./layerdb/sha256/1e294000374b3a304c2bfcfe51460aa599237149ed42e3423ac2c3f155f9b4a5
    20       ./layerdb/sha256/dcec23d16cb7cdbd725dc0024f38b39fd326066fc59784df92b40fc05ba3728f
    20       ./layerdb/sha256/316cd969204ae854302bc55c610698829c9f23fa6fcd4e0f69afa6f29fedfd68
    20       ./layerdb/sha256/97386f823dd75e356afac10af0def601f2cd86908e3f163fb59780a057198e1b
    440     ./layerdb/sha256
    440     ./layerdb
    8         ./imagedb/content/sha256
    8         ./imagedb/content
    0         ./imagedb/metadata/sha256
    0         ./imagedb/metadata
    8         ./imagedb
    28       ./distribution/v2metadata-by-diffid/sha256
    28       ./distribution/v2metadata-by-diffid
    28       ./distribution/diffid-by-digest/sha256
    28       ./distribution/diffid-by-digest
    56       ./distribution

6. image 정리

  • docker system prune → 사용하지 않는 컨테이너 일괄 삭제
  • docker system prune -a → 현재 컨테이너에서 사용하고 있지 않은 이미지들을 삭제하는 -a 옵션도 제공
  • docker system prune filter 옵션 → 특정 기준으로 삭제할 대상이 되는 Container의 대상을 필터링
    # 중지된 지 24시간 이상 지난 이미지만 삭제
    $ docker container prune --filter until=24h

1. docker 그룹 존재 유무 확인

  • docker 그룹 확인
    $ cat /etc/group | grep -i docker
    docker:x:995:
  • docker 그룹이 없다면 docker 그룹 생성 필요
    $ sudo groupadd docker  (docker group이 없는 경우)
    $ sudo systemctl restart docker

2. 사용자 확인 → student를 docker 그룹에서 사용할 예정

  • student 사용자 계정이 전체 사용자 계정에 있는지 확인
    $ cat /etc/passwd
    root:x:0:0:root:/root:/bin/bash
    bin:x:1:1:bin:/bin:/sbin/nologin
    daemon:x:2:2:daemon:/sbin:/sbin/nologin
    adm:x:3:4:adm:/var/adm:/sbin/nologin
    lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
    sync:x:5:0:sync:/sbin:/bin/sync
    shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
    halt:x:7:0:halt:/sbin:/sbin/halt
    mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
    operator:x:11:0:operator:/root:/sbin/nologin
    games:x:12:100:games:/usr/games:/sbin/nologin
    ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
    nobody:x:99:99:Nobody:/:/sbin/nologin
    systemd-network:x:192:192:systemd Network Management:/:/sbin/nologin
    dbus:x:81:81:System message bus:/:/sbin/nologin
    polkitd:x:999:998:User for polkitd:/:/sbin/nologin
    sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
    postfix:x:89:89::/var/spool/postfix:/sbin/nologin
    student:x:1000:1000:student:/home/student:/bin/bash

3. student 계정을 소속 그룹(docker) 추가(add) → 기존 student 내용은 유지

3.1. -G 옵션

  • student 계정의 소속 그룹(docker)을 변경
  • 만약 여러 그룹을 지정할 때에는 ,(콤마) 로 구분하여 지정

3.2. -a 옵션

  • student 변경 대신 정보를 추가 append하는 옵션

3.3. -a -G 옵션

  • student 계정의 소속 그룹(docker)을 추가(add)
    $ sudo usermod -aG docker student

4. student 계정을 소속 그룹(docker)에 추가 확인

  • student 계정 소속 그룹 확인
    $ id -a student
    uid=1000(student) gid=1000(student) groups=1000(student),10(wheel),995(docker)
  • student 계정 소속 그룹 확인
    $ groups student
    student : student wheel docker

5. user1 계정을 생성하면서 docker 그룹에 추가 및 확인

  • user1 계정 생성 및 내용 확인
    $ sudo useradd -G docker user1
    $ cat /etc/passwd | grep user1
    user1:x:1001:1001::/home/user1:/bin/bash
  • user1의 id 확인
    $ id user1
    uid=1001(user1) gid=1001(user1) groups=1001(user1),995(docker)
  • user1 그룹 확인
    $ groups user1
    user1 : user1 docker

6. student 사용자에 접속하여 docker ps 및 docker images 명령어 입력 확인

  • student 사용자 로그인
    $ su - student
    마지막 로그인: 월  7월 26 14:44:59 KST 2021 일시 pts/0
  • docker 컨테이너 확인
    [student@centos-docker ~]$ docker ps
    CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
  • docker 이미지 확인
    [student@centos-docker ~]$ docker images
    REPOSITORY   TAG       IMAGE ID   CREATED   SIZE

+ Recent posts