블로그 이미지
LifeisSimple

calendar

1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31

Notice

2011. 1. 21. 18:12 Brain Trainning/NoSQL
Cacti 에서 MongoDB를 모니터링 할 수 있는 Plugin 입니다. 


Overview

These templates use ss_get_by_ssh.php to connect to a server via SSH and extract statistics from the MongoDB server running there, by executing the "serverStatus" admin command from the MongoDB shell. This means that the mongo CLI needs to be in $PATH and you must be running version 1.2+ of MongoDB.

This document should be correct and complete as of version 1.1.8 of the graphs. Please use the issue tracker or the mailing list to report any errors or omissions. If you have any sample graphs that are better than those shown, please contribute!

Installation

Once the SSH setup is working, confirm that you can login to MongoDB from with the "mongo" cli tool. From this tool, confirm that serverStatus command is present by running:

db._adminCommand({serverStatus : 1});

This should produce quite a bit of output. With all of this confirmed, test one of your hosts with the command below. You may need to change some of the example values below, such as the cacti username and the hostname you're connecting to.

su - cacti -c 'env -i php /var/www/cacti/scripts/ss_get_by_ssh.php --type mongodb --host 127.0.0.1 --items dc,dd'

Background Flushes

Commands

Connections

Index Operations

Memory

posted by LifeisSimple
2011. 1. 21. 17:31 Brain Trainning/NoSQL

출처 : http://www.slideshare.net/jnunemaker/why-mongodb-is-awesome

Presentation: Why MongoDB is Awesome

by Alex Popescu

Nicely structured MongoDB intro by John Nunemaker: Easy to try, Easy to understand and Easy to learn:




Why MongoDB is awesome
아래는 PT 파일의 PDF 버전입니다. 
posted by LifeisSimple
2011. 1. 20. 15:25 Brain Trainning/NoSQL
우선 가볍게 config 파일을 하나 만들어 줍니다. 

내용은 다음과 유사하게 

-----------------------------------------------------------

#Start MongoDB as a daemon on port 27017

 

port = 27017 # 포트

fork = true # 데몬모드

logpath = /usr/mongodb/log/default.log #로그파일 위치

dbpath = /usr/mongodb/data/db  # DB 파일의 path

rest = true #rest 지원

...................

넣고 싶은 옵션들을 주저리 주저리 넣어줍니다.

-------------------------------------------------------------------------------------------


그리고, mongoDB를 실행해 줍니다. 

[root@mongoserver]# mongod --config /mongodb/config/mongo.conf


몽고DB가 깔끔하게 실행됩니다. 

posted by LifeisSimple
2011. 1. 20. 15:14 Brain Trainning/NoSQL
MongoDB 는 간단히 모니터링 할 수 있는 툴을 제공합니다. 
물론 MS 등등의 Dashboard와는 많은 차이가 있습니다. 

일단 MongoDB 를 뛰우면 Port를 2개 가지고 가는 것을 알 수 있습니다. 
하나는 native client Port이고...  
또 하나가 간단한 몽고 모니터 화면입니다. 

URL 로 접속이 가능하고 주소는 : http://localhost:28017  <-- 포트번호는 mongod 를 실행할때 설정한 값 + 3000 . 기본은 28017 입니다. 

들어가면 다음과 같은 화면이 나타납니다. 


내용은 대충 보시면 알것 같고 
위쪽에 Commands가 있는데... 이 녀석들을 그냥 실행하면 rest 를 활성화 하라는 말이 나옵니다.  (사실 DB를 restart 하라는 말고 동일)

MongoDB를 띄울때 -- rest 옵션을 활성화 해서 띄워야 가능합니다. 

크게 상세하게 볼 내용은 없습니다. 저 정도 화면은 mongoDB 를 조금만 해보면 만들 수 있을 듯 합니다. 

참고로 난 저런 허름한 모니터때문에 포트하나 쓰기 싫다 라고 생각하는 분은... 

DB Start 옵션으로 -- nohttpinterface 를 켜주면 됩니다. 

'Brain Trainning > NoSQL' 카테고리의 다른 글

[MongoDB] Why MongoDB is Awesome  (0) 2011.01.21
[MongoDB] monogd config file 로 실행...  (0) 2011.01.20
[MongoDB] Start Options  (0) 2011.01.18
[MongoDB] Mac 용 UI 툴 MongoHub  (0) 2011.01.18
[MongoDB] MongoDB Index 관리 (처리)  (0) 2011.01.11
posted by LifeisSimple
2011. 1. 18. 18:04 Brain Trainning/NoSQL
DB 서버 세팅에서 중요한 것들은 미리 체크를 해둬야 함.

Allowed options:

 

General options:

  -h [ --help ]         show this usage information

  --version             show version information

  -f [ --config ] arg   configuration file specifying additional options

  -v [ --verbose ]      be more verbose (include multiple times for more

                        verbosity e.g. -vvvvv)

  --quiet               quieter output

  --port arg            specify port number

  --bind_ip arg         comma separated list of ip addresses to listen on - all

                        local ips by default

  --logpath arg         file to send all output to instead of stdout

  --logappend           append to logpath instead of over-writing

  --pidfilepath arg     full path to pidfile (if not set, no pidfile is

                        created)

  --fork                fork server process

  --dbpath arg          directory for datafiles

  --directoryperdb      each database will be stored in a separate directory

  --repairpath arg      root directory for repair files - defaults to dbpath

  --cpu                 periodically show cpu and iowait utilization

  --noauth              run without security

  --auth                run with security

  --objcheck            inspect client data for validity on receipt

  --quota               enable db quota management

  --quotaFiles arg      number of files allower per db, requires --quota

  --appsrvpath arg      root directory for the babble app server

  --nocursors           diagnostic/debugging option

  --nohints             ignore query hints

  --nohttpinterface     disable http interface

  --rest                turn on simple rest api

  --noscripting         disable scripting engine

  --noprealloc          disable data file preallocation

  --smallfiles          use a smaller default file size

  --nssize arg (=16)    .ns file size (in MB) for new databases

  --diaglog arg         0=off 1=W 2=R 3=both 7=W+some reads

  --sysinfo             print some diagnostic system information

  --upgrade             upgrade db if needed

  --repair              run repair on all dbs

  --notablescan         do not allow table scans

  --syncdelay arg (=60) seconds between disk syncs (0=never, but not

                        recommended)

  --profile arg         0=off 1=slow, 2=all

  --slowms arg (=100)   value of slow for profile and console log

  --maxConns arg        max number of simultaneous connections

  --nounixsocket        disable listening on unix sockets

  --ipv6                enable IPv6 support (disabled by default)

 

Replication options:

  --master              master mode

  --slave               slave mode

  --source arg          when slave: specify master as <server:port>

  --only arg            when slave: specify a single database to replicate

  --pairwith arg        address of server to pair with

  --arbiter arg         address of arbiter server

  --slavedelay arg      specify delay (in seconds) to be used when applying

                        master ops to slave

  --fastsync            indicate that this instance is starting from a dbpath

                        snapshot of the repl peer

  --autoresync          automatically resync if slave data is stale

  --oplogSize arg       size limit (in MB) for op log

  --opIdMem arg         size limit (in bytes) for in memory storage of op ids

 

Sharding options:

  --configsvr           declare this is a config db of a cluster

  --shardsvr            declare this is a shard db of a cluster

  --noMoveParanoia      turn off paranoid saving of data for moveChunk.  this

                        is on by default for now, but default will switch

posted by LifeisSimple
2011. 1. 18. 15:36 Brain Trainning/NoSQL

MongoHub

version 2.3.0
posted by LifeisSimple
2011. 1. 11. 16:55 Brain Trainning/NoSQL

인덱스 (Index)

1. 인덱스 생성

-       동일 인덱스를 생성할 경우 1개만 생성됨. (동일한 인덱스 생성문을 입력해도 의미 없음)

-     컬럼의 유무와 관계없이 인덱스 생성됨. (컬럼이 없어도 인덱스 생성)

-       인덱스 정렬순서 1: ASC, -1: DESC

-       인덱스는 하위 도큐먼트 단위로도 생성 가능

   > db.factories.insert( { name: "xyz", metro: { city: "New York", state: "NY" } } );
   > db.factories.ensureIndex( { metro : 1 } );
     // this query can use the above index:
   > db.factories.find( { metro: { city: "New York", state: "NY" } } );

-     온라인 인덱스 생성가능 (1.3.2 버전 이상) / Unique Key 생성가능

> db.things.ensureIndex({x:1}, {background:true});

> db.things.ensureIndex({name:1}, {background:true, unique:true,

... dropDups:true});

 

예제)

1)    [ SQL ]
create index IX_department_dptCode_dptName on department (dptcode, dptname desc)

2)    [ MongoDB 콘솔 ]
db.department.ensureIndex({dptcode:1}, dptname:-1))

3)     [ JavaCode ]

BasicDBObject keys = new BasicDBObject();

 

keys.put("dptname", -1);

keys.put("dptcode", 1);

 

dept.ensureIndex(keys);

4)    [ 출력 ]
db.department.getIndexes()



추가 내용은 http://www.mongodb.org/display/DOCS/Indexes 참조


2. 인덱스 삭제

1)      [SQL] 

Drop index IX_department_dptCode_dptName on department

2)       [ MongoDB 콘솔]

 db.department.dropIndex({dptname:-1,dptcode:1})

3)       [ Java Code ]

                  BasicDBObject keys = new BasicDBObject();

                  keys.put("dptname", -1);

                  keys.put("dptcode", 1);

                  //dept.ensureIndex(keys);

                 

                  dept.dropIndex(keys);


이외에 index Rebuild 등의 기능이 있음. 메뉴얼 참조.

'Brain Trainning > NoSQL' 카테고리의 다른 글

[MongoDB] Start Options  (0) 2011.01.18
[MongoDB] Mac 용 UI 툴 MongoHub  (0) 2011.01.18
[MongoDB] MongoDB 한글 검색 문제 ...  (0) 2011.01.10
[MongoDB] Java Code Sample #1  (0) 2011.01.07
[MongoDB] MongoDB GridFS 부하테스트  (2) 2011.01.07
posted by LifeisSimple
2011. 1. 10. 12:05 Brain Trainning/NoSQL
MongoDB에서 한글입력과 출력은 Java에서 가능하나 검색이 안되는 문제가 발생... 

윈도우는 malformed UTF-8 character sequence at offset 48 에러 발생

왜 그럴까 한참을 고민하다가 

UTF-8로 세팅 후 정상적으로 검색 가능.... 일단 문제는 해결 되었습니다. 

/etc/sysconfig/i18n 파일을 다음 내용으로 변경
/etc/bashrc 파일 끝부분에 다음 문자열 추가

콘솔 제접속 후 잘 설정되었는지 확인.

요렇게 나오면 잘 설정되었습니다.

그리고, mongod를 올리고 테스트 하면 정상적으로 입력/조회 가능합니다. 

앞으로 추가 체크해볼 사항으로는... 
1. 윈도우일 경우 
2. 소스 컴파일시 charset 지정 가능한지
입니다.
posted by LifeisSimple
2011. 1. 7. 17:56 Brain Trainning/NoSQL

import java.net.UnknownHostException;

import java.util.Iterator;

 

import com.mongodb.BasicDBObject;

import com.mongodb.DB;

import com.mongodb.DBCollection;

import com.mongodb.DBCursor;

import com.mongodb.DBObject;

import com.mongodb.Mongo;

import com.mongodb.MongoException;

 

public class MongoDBTest {

 

       public MongoDBTest() {

             // TODO Auto-generated constructor stub

       }

 

       /**

        * @param args

        * @throws MongoException

        * @throws UnknownHostException

        */

       public static void main(String[] args) throws UnknownHostException, MongoException {

             // TODO Auto-generated method stub

             Mongo connection = new Mongo("172.16.72.38", 27017);

            

             DB db = connection.getDB("test");

             DBCollection dept = db.getCollection("department");

             BasicDBObject query = new BasicDBObject();

            

             // query string : db.department.find({dptcode:"HR"})

             query.put("dptcode", "HR");

             DBCursor cur = dept.find(query);

            

             int index = 1;

             for ( Iterator<DBObject> it = cur.iterator(); it.hasNext(); ++index) {

                    DBObject obj = it.next();

                   

                    System.out.println("data("+ index+"):"+obj);

             }

            

             // query string : db.department.insert({dptcode:"IT", dptname:"한글이사", dptnote:"주워먹을건 아무것도 없음"})

             BasicDBObject putDB = new BasicDBObject();

            

             /*

             putDB.put("dptcode", "IT");

             putDB.put("dptname", "한글이사");

             putDB.put("dptnote", "주워먹을건 아무것도 없음");

            

             dept.insert(putDB);

             */

            

             query.put("dptcode", "IT");

            

             System.out.println(dept.findOne(query));

       }

posted by LifeisSimple
2011. 1. 7. 00:16 Brain Trainning/NoSQL
Linux 32Bit 에서 2G 이상의 파일을 Put 할 경우 Put 하지 못하고 오류가 떨어지는 문제가 있어, 64Bit 에서 테스트 할려고 했으나 구하지 못했습니다. 

그래서 집에 있는 컴으로 테스트를 했습니다. 

테스트 환경은. 
OS : Windows7 64Bit
MEM : Memory 6G
테스트 파일 Size : 4G, 8G

IO 관련 테스트라기 보다는 부하테스트라 HDD의 IO 성능은 논외 입니다. HDD 를 SSD로 사용하면 IO측면에서는 이득이 있을 수 있으나 실 서버 환경에서는 많이 다르기에 그냥 패스

일단. 테스트의 목적은
1. 저장할 수 있는 파일의 Size는?
2. 저장된 파일은 어떤 방식으로 저장되어 지는지
3. Upload 할때와 Download 할때의 부하는 어느 정도? (스트리밍에 적용한다는 가정으로 대용량 파일들을 Up/Down)

Up/Down 테스트입니다. 
4G Test와 8G 테스트와는 큰 차이가 없었습니다. 따라서 간단히 10G에 대한 결과만 확인하도록 하겠습니다. 


파일을 올리게 되면 위의 그림과 같은 형태가 됩니다. Database의 디렉토리에는 2G 단위로 파일이 생성되게 됩니다. 
(32Bit Linux 에서는 512MB 단위로 파일이 생성되었습니다.)

db.fs.files.find() 명령으로 Put 되어진 파일의 리스트를 확인할 수 있습니다. 
4G / 8G 파일이 각각 Insert 가 된것을 확인 할 수 있습니다. 


8G 파일을 Put 했을때 서버의 Log 화면입니다. 다수의 Chunks 로 나누면서 Upload 가 진행됩니다. 


위에서는 간단히 Upload 할때의 화면이었고 이와는 다르게 그래프는 Upload 된 파일을 스트리밍 서비스를 한다는 가정하에 get 명령으로 다운받는 상황입니다. 물론 파일을 일방적으로 Down 받는것과 청크단위로 데이터를 메모리로 가져와 서비스 하는 것은 차이가 있을 듯 합니다. 그렇지만 2G의 동영상을 스트리밍 하는 경우는 이와 비슷한 결과를 보일것 같습니다. 초기 메모리는 사용량이 거의 없습니다. mongod 프로세스를 확인하면 메모리를 거의 사용하지 않고 있는 것을 알수 있습니다. 


그래프나 메모리 사용량을 확인하면 mongod 프로세스가 메모리를 95% 이상 사용하게 됩니다. 그리고, cache 되는 량이 급격하게 줄어들고, Page Fault/Sec 이 급격하게 증가합니다. 이때 시스템 로그를 확인하면 대략 메모리로 Select 한 Chunk들을 올리고 이를 다시 파일에 Write하는 것을 알 수 있습니다. 대용량일수록 Page out 이 많이 발생할 수 밖에 없는 구조이며 이때문에 전체 DB 시스템에 문제가 발생할 소지가 있습니다. 


위의 화면은 상황이 종료된 모습니다.

그럼, 결과를 보면
1. 저장할 수 있는 파일의 Size는? 
 - 8G 까지의 테스트로 보아 제한없이 저장이 가능할 것 같습니다. 

2. 저장된 파일은 어떤 방식으로 저장되어 지는지
 - OS 환경에 따라 다르나 동일 폴더에 특정 사이즈의 파일로 분할되어 저장됩니다.

3. Upload 할때와 Download 할때의 부하는 어느 정도? (스트리밍에 적용한다는 가정으로 대용량 파일들을 Up/Down)
 - MSSQL 에서도 첨부파일등의 데이터를 DB에 Blob 형태로 넣을 것인가 아니면 윈도우 파일 시스템을 활용할 것인가 논의가 되었었습니다. 
결론은 파일 시스템이 직접 처리하도록 하는 것이 좋다.. 이런 것이었습니다. 조각화 현상등 등... MongoDB 테스트에서도 대용량 파일을 전체 Put한 후 Get하는 과정에서 시스템에 엄청난 부하를 주는 것을 확인할 수 있었습니다.

이번 테스트를 통해서 MongoDB 역시 db의 cache를 꼭 활용해야하는 경우가 아닌 경우는 되도록 파일 시스템에 파일을 저장하고 링크를 DB에 저장하는 것이 좋겠다라는 것을 확인하게 되었습니다.

8G의 파일을 파일 시스템에서 Copy 했을 경우 시간 및 시스템 부하 정도가 MongoDB의 그것과 현격하게 차이가  났습니다. 
소량의 데이터 파일들에 대한 테스트는 추후에 다시 한번 진행하겠지만 현재의 상황을 봤을때 대용량 동영상등의 스트리밍에는 활용하기 어려운 것 같습니다. 

전용시스템에 Memory가 아주 충분한 상황이나 혹은 Sharding을 통한 메모리/IO 성능 향상이 있다면 이야기는 달라질 수 있습니다. 


posted by LifeisSimple
prev 1 2 3 next