아마도 다운로드에 들어가는 시간을 제외하면, 지구상에서 가장 간편하게 프로그램을 설치하고, 테스트 해 볼 수 있는 환경은 도커가 아닌가 한다.
도커에 대한 자세한 사용법이나 설치법을 알기 위해서는 다음 링크를 사용하고, 여기에서 도커에 대한 설명은 하지 않기로 한다.
초보자를 위한 도커 시작 페이지
또 다른 도커 한글 문서들
http://blog.nacyot.com/articles/2014-01-27-easy-deploy-with-docker/
이문서에서 사용한 도커 버젼은 다음과 같다.(17.06.0-ce)
sjkim@localhost:~$ docker --version Docker version 17.06.0-ce, build 02c1d87 sjkim@localhost:~$ |
자...이제 본격적으로 설치해 보도록 하자.
마크베이스 도커 페이지 엿보기
그냥 재미로 마크베이스가 유지하는 도커 허브의 페이지를 방문해 보자.
(https://hub.docker.com/r/machbase/machbase/)
설명과 여러가지 설명이 나와 있고, 우측에 pull 명령이 나왔다.
도커 이미지 다운로드 하기
도커 이미지를 다운로드 하기 위해서는 아래와 같이 매우 간단하다.
sjkim@localhost:~$ sudo docker pull machbase/machbase Using default tag: latest latest: Pulling from machbase/machbase 7ee37f181318: Pull complete df5ffabe5e97: Pull complete ae2040ed51a1: Pull complete 3ce7010d244b: Pull complete 2538b201d2a6: Pull complete 7b2d7b983298: Pull complete e373e27d649c: Pull complete 8723dd51b741: Pull complete 67b38fb11afa: Pull complete 08c0e916d620: Pull complete 062b053f6c9a: Pull complete 7d3330570ca9: Pull complete 556b2dead613: Pull complete da803df15b5a: Pull complete d795743db7b8: Pull complete a7a11d9d1996: Pull complete 468b283d8d33: Pull complete ac139db316f6: Pull complete e55f53aaa5c7: Pull complete bd74e4fa8b8b: Pull complete 951a56f8e523: Pull complete 2dec0c6abd8b: Pull complete 1f783140bfaf: Pull complete 3dc719fe2a8c: Pull complete 4ef2fde43015: Pull complete Digest: sha256:9200aaf2de6e1695a57188fafd901a0a519d9deaeac66f0ba9274e9a13aba35d Status: Downloaded newer image for machbase/machbase:latest sjkim@localhost:~$ docker run -it machbase/machbase |
최초로 받는 경우에는 꽤 많이 받아야 하지만, 한번 받아 놓으면, 이후에 업데이트 될 경우에는 일부만 받으므로 다운로드 성능이 늦지는 않을 것이다.
나의 경우에는 1~2분 정도 걸린 것 같다.
도커를 실행하자!
아래는 실행 명령어로 수행한 것이다. 콘솔에서 입력을 받으므로 -it 명령을 사용해서 수행했다.
sjkim@localhost:~$ docker run -it machbase/machbase * Restarting OpenBSD Secure Shell server sshd [ OK ] ----------------------------------------------------------------- Machbase Administration Tool Release Version - 3.5.0.826b8f2.official Copyright 2014, InfiniFlux Corp. or its subsidiaries All Rights Reserved ----------------------------------------------------------------- Waiting for Machbase server start. Machbase server started successfully. SERVER HAS BEEN RESET SERVER STARTED, PID : 78 Connection URL : http://172.17.0.2:5001 machbase@15f5ed3f8c98:~$ |
오호..!! 마크베이스가 동작한다고 나온다. (너무 쉽다...)
콘솔툴(machsql)로 테스트해 보기
현재 상태는 도커내부에서 새로운 쉘에 로그인한 상태이기 때문에 여기에서 아무 작업이나 가능하다.
machbase@15f5ed3f8c98:~$ machsql ================================================================= Machbase Client Query Utility Release Version 3.5.0.826b8f2.official Copyright 2014 InfiniFlux Corporation or its subsidiaries. All Rights Reserved. ================================================================= Machbase server address (Default:127.0.0.1) : Machbase user ID (Default:SYS) Machbase User Password : MACHBASE_CONNECT_MODE=INET, PORT=5656 Type 'help' to display a list of available commands. Mach> select * from m$tables; NAME TYPE DATABASE_ID ID USER_ID COLCOUNT ------------------------------------------------------------------------------------------------------------------------------- M$SYS_COLLECTOR_COLUMNS 1 -1 1000049 0 11 M$COLUMNS 1 -1 1000043 0 13 M$SYS_COLUMNS 1 -1 1000042 0 13 M$SYS_INDEX_COLUMNS 1 -1 1000045 0 9 M$SYS_COLLECTOR_SOURCES 1 -1 1000050 0 7 M$SYS_TABLESPACE_DISKS 1 -1 1000020 0 8 M$SYS_COLLECTORS 1 -1 1000048 0 25 M$SYS_TABLES 1 -1 1000038 0 8 M$TABLES 1 -1 1000040 0 8 M$SYS_INDEXES 1 -1 1000044 0 15 M$SYS_USERS 1 -1 1000046 0 4 M$SYS_TABLESPACES 1 -1 1000016 0 5 M$SYS_COLLECTORMANAGERS 1 -1 1000047 0 7 [13] row(s) selected. Elapsed time: 0.000 Mach> quit machbase@15f5ed3f8c98:~$ |
오호 잘 동작한다..
로딩 테스트
내부 튜토리얼을 사용해서 한번 데이터 로딩과 쿼리를 수행해 보도록 하자.
아래의 디렉토리로 이동을 해 보자.
machbase@15f5ed3f8c98:~$ cd $MACHBASE_HOME/tutorials/csvload/ machbase@15f5ed3f8c98:~/machbase_home/tutorials/csvload$ ls -al total 127696 drwxr-xr-x 2 machbase machbase 4096 Aug 3 03:08 . drwxr-xr-x 10 machbase machbase 4096 Aug 3 03:08 .. -rw-r--r-- 1 machbase machbase 246769 Aug 3 03:08 awards.csv -rw-r--r-- 1 machbase machbase 259 Aug 3 03:08 create_sample2_table.sql -rw-r--r-- 1 machbase machbase 231 Aug 3 03:08 create_sample_table.sql -rwxr-xr-x 1 machbase machbase 60 Aug 3 03:08 load_awards.sh -rwxr-xr-x 1 machbase machbase 486 Aug 3 03:08 load_sample.sh -rwxr-xr-x 1 machbase machbase 474 Aug 3 03:08 load_sample2.sh -rw-r--r-- 1 machbase machbase 130477124 Aug 3 03:08 sample_data.csv machbase@15f5ed3f8c98:~/machbase_home/tutorials/csvload$ |
준비된 스크립트인 load_sample.sh를 수행하면 자동으로 100만건을 로딩하도록 되어 있다.
machbase@15f5ed3f8c98:~/machbase_home/tutorials/csvload$ sh ./load_sample.sh + machsql -s 127.0.0.1 -u sys -p manager -f create_sample_table.sql ================================================================= Machbase Client Query Utility Release Version 3.5.0.826b8f2.official Copyright 2014 InfiniFlux Corporation or its subsidiaries. All Rights Reserved. ================================================================= MACHBASE_CONNECT_MODE=INET, PORT=5656 Type 'help' to display a list of available commands. Mach> CREATE TABLE SAMPLE_TABLE ( srcip IPV4, srcport INTEGER, dstip IPV4, dstport INTEGER, protocol SHORT, eventlog VARCHAR(1204), eventcode SHORT, eventsize LONG ); Created successfully. Elapsed time: 0.093 + csvimport -t sample_table -d sample_data.csv -a -F _arrival_time YYYY-MM-DD HH24:MI:SS ----------------------------------------------------------------- Machbase Data Import/Export Utility. Release Version 3.5.0.826b8f2.official Copyright 2014, InfiniFlux Corporation or its subsidiaries. All Rights Reserved. ----------------------------------------------------------------- NLS : US7ASCII EXECUTE MODE : IMPORT TARGET TABLE : sample_table DATA FILE : sample_data.csv IMPORT_MODE : APPEND FILED TERM : , ROW TERM : \n ENCLOSURE : " ARRIVAL_TIME : TRUE ENCODING : NONE HEADER : FALSE CREATE TABLE : FALSE Progress bar Imported records Error records 1000000 0 Import time : 0 hour 0 min 5.172 sec Load success count : 1000000 Load fail count : 0 machbase@15f5ed3f8c98:~/machbase_home/tutorials/csvload$ |
100만건 로딩에 약 5.2초 걸렸다...초당 20만건 성능이네..
쿼리 테스트
로딩된 레코드 수는 다음과 같다.
Mach> select count(*) from sample_table; count(*) ----------------------- 1000000 [1] row(s) selected. Elapsed time: 0.000 Mach> |
sample_table 의 구조는 다음과 같다.
Mach> desc sample_table; [ COLUMN ] ---------------------------------------------------------------- NAME TYPE LENGTH ---------------------------------------------------------------- SRCIP ipv4 15 SRCPORT integer 11 DSTIP ipv4 15 DSTPORT integer 11 PROTOCOL short 6 EVENTLOG varchar 1204 EVENTCODE short 6 EVENTSIZE long 20 Mach> |
DSTIP의 종류와 갯수를 한번 세어보자.
SQL은 select dstip, count(dstip) from sample_table group by dstip 로 하면 될 듯.
Mach> select dstip, count(dstip) from sample_table group by dstip ; dstip count(dstip) ---------------------------------------- 148.30.103.173 13431 31.224.72.52 13310 5.114.66.53 13253 118.179.107.47 13206 ....... 생략 ........ 219.229.142.218 13353 210.174.159.227 13424 220.192.100.45 13015 159.240.209.63 13287 [75] row(s) selected. Elapsed time: 0.224 Mach> |
총 75 종류의 인터넷 주소가 존재한다. 0.224초 만에 계산을 완료했다.
그럼, 소팅을 해서 가장 많이 등장하는 숫자부터 10개를 출력해보자.
Mach> select dstip, count(dstip) from sample_table group by dstip order by 2 desc limit 10; dstip count(dstip) ---------------------------------------- 121.67.24.216 13560 123.198.82.192 13545 185.22.195.164 13515 248.168.229.34 13465 166.144.72.55 13454 6.32.167.53 13453 66.114.157.127 13450 153.70.151.135 13449 157.54.162.47 13449 245.13.24.17 13437 [10] row(s) selected. Elapsed time: 0.253 Mach> |
음..100만건 ip주소에 대한 통계 간단한 분석은 0.25초 정도만에 할 수 있는 것으로 보인다.
외부에서 도커로 SSH 접속하기
SSH와 같은 도구로 외부에서 접속해 보도록 하겠다.
IP주소를 확인해보자.
machbase@15f5ed3f8c98:~/machbase_home/tutorials/csvload$ ifconfig eth0 Link encap:Ethernet HWaddr 02:42:ac:11:00:02 inet addr:172.17.0.2 Bcast:0.0.0.0 Mask:255.255.0.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:66 errors:0 dropped:0 overruns:0 frame:0 TX packets:1 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:11139 (11.1 KB) TX bytes:42 (42.0 B) lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 UP LOOPBACK RUNNING MTU:65536 Metric:1 RX packets:12107 errors:0 dropped:0 overruns:0 frame:0 TX packets:12107 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:122322696 (122.3 MB) TX bytes:122322696 (122.3 MB) machbase@15f5ed3f8c98:~/machbase_home/tutorials/csvload$ |
172.17.0.2 로 주소가 잡혀 있으므로, 여기로 접속해 보자.
아이디와 패스워드는 machbase/machbase 라고 되어 있다.
ssh로 접속하고, 수동으로 bash를 수행한 화면은 다음과 같다.
sjkim@localhost:~$ ssh machbase@172.17.0.2 machbase@172.17.0.2's password: ******** Welcome to Ubuntu 14.04 LTS (GNU/Linux 4.4.0-83-generic x86_64) * Documentation: https://help.ubuntu.com/ The programs included with the Ubuntu system are free software; the exact distribution terms for each program are described in the individual files in /usr/share/doc/*/copyright. Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by applicable law. $ bash machbase@15f5ed3f8c98:~$ env | grep MACH MACHBASE_HOME=/home/machbase/machbase_home machbase@15f5ed3f8c98:~$ |
도커를 실행한 환경과 동일하므로, 여기에서 많은 작업을 수행할 수 있다.
외부에서 도커로 MWA 접속하기
외부에서 도커의 MWA에 접속하기 위해서는 도커 최초 실행시 나온 도움말 URL로 접속하면 된다.
sjkim@localhost:~$ docker run -it machbase/machbase ......................생략....................... Machbase server started successfully. SERVER HAS BEEN RESET SERVER STARTED, PID : 78 Connection URL : http://172.17.0.2:5001 <================= 여기 machbase@15f5ed3f8c98:~$ |
웹 브라우저에서 위에서 나온 http://172.17.0.2:5001로 접속해 보자. 아이디와 패스워드는 admin/machbase 이다.
위의 화면이 나오면 성공적으로 사용할 수 있도록 설치 및 구동이 잘 된 것이다.
마무리
도커는 설치와 테스트에 있어서 정말 환상적인 환경을 제공해주는 것 같다.
특히, 성능에 있어서도 크게 뒤떨어지지 않고, 마치 정말 설치한 것과 유사한 환경으로 만들어주기 때문에 나같은 귀차니즘이 발동하는 개발자에게는 최고의 환경이 아닌가 생각된다.
물론, 실제 서비스에 사용하기 위해서는 더 많은 준비를 해야 하겠지만 말이다.
그리고, 도커 환경에서도 마크베이스의 성능은 정말 인상적이라고 할 수 밖에 없다.
나중에 인덱스 공부를 한 후에 몇 억 건을 대상으로 다시 한번 테스트 해 보고 싶다.














