'NoSQL'에 해당되는 글 3건

  1. 2013.01.11 MongoDB 막 설치해보기
  2. 2012.05.03 MongoDB - Strategies when hitting disk
  3. 2012.05.03 NoSQL Data Modeling....

MongoDB 막 설치해보기

ITWeb/개발일반 2013.01.11 11:52

본 내용은 보안이 전혀 고려되지 않은 단순 설치 및 분산구성 테스트를 목적으로 작성되었습니다.
그러니 꼭 보안 관련 내용을 반영 하시기 바랍니다. ^^;
추후 보안 관련 내용도 올려 보도록 하겠습니다.

참고문서

MongoDB 설치하기
    [다운로드 및 설정]
        # 32bits
        curl http://downloads.mongodb.org/linux/mongodb-linux-i686-2.2.2.tgz > mongo.tgz
        # 64bits
        curl http://downloads.mongodb.org/linux/mongodb-linux-x86_64-2.2.2.tgz > mongo.tgz
        tar -xvzf mongo.tgz
        mv mongodb-linux-i686-2.2.2 ../apps/
        cd ../apps/
        ln -s mongodb-linux-i686-2.2.2 mongodb
        cd mongodb
        mkdir data
        mkdir conf
        mkdir logs
        cd conf
        vi mongodb.conf
            dbpath=/home/user/apps/mongodb/data
            logpath=/home/user/apps/mongodb/logs/mongodb.log
            logappend=true
            verbose=true
 
            #bind_ip=127.0.0.1
            port=27017
            fork=true
 
            rest=true
            #auth=true
            #noauth=true
    [실행]
        ./bin/mongod --config conf/mongodb.conf
 
    [접속]
        ./bin/mongo localhost:27017
 
    [중지]
        # mogod 로 중지
        mongod --config conf/mongodb.conf --shutdown
 
        # console 에서 아래 명령어 실행
        db.shutdownServer()
 
        # Ctrl+C, kill -2 PID, kill -15 PID 로 중지, kill -9 PID 사용 시 데이터 깨질 수 있음
        # kill 시그널 number
            1) SIGHUP 2) SIGNT 3) SIGQUIT 4) SIGILL
            5) SIGTRAP 6) SIGIOT 7) SIGBUS 8) SIGPPE
            9) SIGKILL 10) SIGUSR1 11) SIGSEGV 12) SIGUSR2
            13) SIGPIPE 14) SIGALRM 15) SIGTERM 17) SIGCHLD
            18) SIGCONT 19) SIGSTOP 20) SIGTSTP 21) SIGTTIN
            22) SIGTTOL 23) SIGURG 24) SIGXCPU 25) SIGXFSZ
            26) SIGVTALRM 27) SIGPROF 28) SIGWINCH 29) SIGIO
            30) SIGPWR
MongoDB Replica 구성하기
    [Replica 설정]
        cd apps/mongodb
        mkdir -p srv/mongodb/rs0-0 srv/mongodb/rs0-1 srv/mongodb/rs0-2
        mkdir logs conf
        cd conf
        vi mongodb0.conf mongodb1.conf mongodb2.conf
            dbpath=/home/user/apps/mongodb/srv/mongodb/rs0-0
            logpath=/home/user/apps/mongodb/logs/mongodb0.log
            logappend=true
            verbose=true
            bind_ip=10.101.254.223
            port=27017
            fork=true
            rest=true
            replSet=rs0
 
            dbpath=/home/user/apps/mongodb/srv/mongodb/rs0-1
            logpath=/home/user/apps/mongodb/logs/mongodb1.log
            logappend=true
            verbose=true
            bind_ip=10.101.254.223
            port=27018
            fork=true
            rest=true
            replSet=rs0
 
            dbpath=/home/user/apps/mongodb/srv/mongodb/rs0-2
            logpath=/home/user/apps/mongodb/logs/mongodb2.log
            logappend=true
            verbose=true
            bind_ip=10.101.254.223
            port=27019
            fork=true
            rest=true
            replSet=rs0
 
    [실행]
        ./mongod --config ../conf/mongodb0.conf
        ./mongod --config ../conf/mongodb1.conf
        ./mongod --config ../conf/mongodb2.conf
 
    [접속]
        ./mongo 10.101.254.223:27017
 
    [RepliSet 구성]
        # mongodb.conf 로 구성하는 경우
            replSet=rs0/10.101.254.223:27017,10.101.254.223:27018,10.101.254.223:27019
        # command 로 구성 하는 경우
        ./mongo 10.101.254.223:27017
        MongoDB shell version: 2.2.2
        connecting to: 10.101.254.223:27017/test
        > rs.status();
        {
                "startupStatus" : 3,
                "info" : "run rs.initiate(...) if not yet done for the set",
                "errmsg" : "can't get local.system.replset config from self or any seed (EMPTYCONFIG)",
                "ok" : 0
        }
        > rs.initiate();
        {
                "info2" : "no configuration explicitly specified -- making one",
                "me" : "10.101.254.223:27017",
                "info" : "Config now saved locally.  Should come online in about a minute.",
                "ok" : 1
        }
        > rs.conf();
        {
                "_id" : "rs0",
                "version" : 1,
                "members" : [
                        {
                                "_id" : 0,
                                "host" : "10.101.254.223:27017"
                        }
                ]
        }
        rs0:PRIMARY> rs.add("10.101.254.223:27018");
        { "ok" : 1 }
        rs0:PRIMARY> rs.add("10.101.254.223:27019");
        { "ok" : 1 }
        rs0:PRIMARY> rs.status();
        {
                "set" : "rs0",
                "date" : ISODate("2013-01-10T08:35:22Z"),
                "myState" : 1,
                "members" : [
                        {
                                "_id" : 0,
                                "name" : "10.101.254.223:27017",
                                "health" : 1,
                                "state" : 1,
                                "stateStr" : "PRIMARY",
                                "uptime" : 295,
                                "optime" : Timestamp(1357806905000, 1),
                                "optimeDate" : ISODate("2013-01-10T08:35:05Z"),
                                "self" : true
                        },
                        {
                                "_id" : 1,
                                "name" : "10.101.254.223:27018",
                                "health" : 1,
                                "state" : 5,
                                "stateStr" : "STARTUP2",
                                "uptime" : 28,
                                "optime" : Timestamp(0, 0),
                                "optimeDate" : ISODate("1970-01-01T00:00:00Z"),
                                "lastHeartbeat" : ISODate("2013-01-10T08:35:20Z"),
                                "pingMs" : 0
                        },
                        {
                                "_id" : 2,
                                "name" : "10.101.254.223:27019",
                                "health" : 1,
                                "state" : 6,
                                "stateStr" : "UNKNOWN",
                                "uptime" : 17,
                                "optime" : Timestamp(0, 0),
                                "optimeDate" : ISODate("1970-01-01T00:00:00Z"),
                                "lastHeartbeat" : ISODate("2013-01-10T08:35:21Z"),
                                "pingMs" : 107,
                                "errmsg" : "still initializing"
                        }
                ],
                "ok" : 1
        }
        rs0:PRIMARY>
MongoDB Shard & Collection 구성하기
    [Shard & Collection]
         
        database : Database Name
        collection : Table Name (Object Name)
 
        [Config Server 구성]
            config server 폴더 생성
                [mongodb]$ mkdir -p configsvr0
                [mongodb]$ mkdir -p configsvr1
                [mongodb]$ mkdir -p configsvr2
                [mongodb]$ pwd
                /home/user/apps/mongodb/srv/mongodb
            [설정]
                - mongodb-configsvr0.conf
                dbpath=/home/user/apps/mongodb/srv/mongodb/configsvr0
                logpath=/home/user/apps/mongodb/logs/mongodb-configsvr0.log
                logappend=true
                verbose=true
                bind_ip=10.101.254.223
                port=37017
                fork=true
                rest=true
 
                - mongodb-configsvr1.conf
                dbpath=/home/user/apps/mongodb/srv/mongodb/configsvr1
                logpath=/home/user/apps/mongodb/logs/mongodb-configsvr1.log
                logappend=true
                verbose=true
                bind_ip=10.101.254.223
                port=37018
                fork=true
                rest=true
 
                - mongodb-configsvr2.conf
                dbpath=/home/user/apps/mongodb/srv/mongodb/configsvr2
                logpath=/home/user/apps/mongodb/logs/mongodb-configsvr2.log
                logappend=true
                verbose=true
                bind_ip=10.101.254.223
                port=37019
                fork=true
                rest=true
 
            [실행]
            ./mongod --config ../conf/mongodb-configsvr0.conf --configsvr
            ./mongod --config ../conf/mongodb-configsvr1.conf --configsvr
            ./mongod --config ../conf/mongodb-configsvr2.conf --configsvr
 
    [Mongos 구성]
        [폴더생성]
            cd apps/mongodb
            mkdir -p srv/mongodb/shard
 
        [설정]
            conf/mongodb-shard.conf
                dbpath=/home/user/apps/mongodb/srv/mongodb/shard
                logpath=/home/user/apps/mongodb/logs/mongodb-shard.log
                configdb=10.101.254.223:37017,10.101.254.223:37018,10.101.254.223:37019
                logappend=true
                verbose=true
                bind_ip=10.101.254.223
                port=47017
                fork=true
                rest=true
 
        [실행]
            ./mongo 10.101.254.223:47017
            MongoDB shell version: 2.2.2
            connecting to: 10.101.254.223:47017/test
            mongos> use admin
            switched to db admin
            mongos> db.runCommand({addShard:"rs0/10.101.254.223:27017,10.101.254.223:27018,10.101.254.223:27019"})
            { "shardAdded" : "rs0", "ok" : 1 }
            mongos> db.runCommand({listshards:1})
            {
                    "shards" : [
                            {
                                    "_id" : "rs0",
                                    "host" : "rs0/10.101.254.223:27017,10.101.254.223:27018,10.101.254.223:27019"
                            }
                    ],
                    "ok" : 1
            }
            mongos> show dbs
            admin   (empty)
            config  0.046875GB
            mongos> use demo
            switched to db demo
            mongos> db.createCollection("tbl_demo")
            { "ok" : 1 }
            mongos> db.tbl_demo.validate();
            {
                    "raw" : {
                            "rs0/10.101.254.223:27017,10.101.254.223:27018,10.101.254.223:27019" : {
                                    "ns" : "demo.tbl_demo",
      &