私のMongoDBワークフロー(centos-yum)

6454 ワード

mongodbのインストール:
$ yum install  mongodb-server -y

$ yum install  mongodb -y

バージョンの表示:
$ mongod -v
2017-07-11T20:12:29.537+0800 shardObjTest passed
2017-07-11T20:12:29.537+0800 isInRangeTest passed
2017-07-11T20:12:29.537+0800 shardKeyTest passed
2017-07-11T20:12:29.537+0800 [initandlisten] MongoDB starting : pid=14186 port=27017 dbpath=/data/db 64-bit host=iZ2ze46lyxfc5q7qi75e2wZ
2017-07-11T20:12:29.537+0800 [initandlisten] db version v2.6.12
2017-07-11T20:12:29.537+0800 [initandlisten] git version: nogitversion
2017-07-11T20:12:29.537+0800 [initandlisten] OpenSSL version: OpenSSL 1.0.1e-fips 11 Feb 2013
2017-07-11T20:12:29.537+0800 [initandlisten] build info: Linux buildvm-16.phx2.fedoraproject.org 4.8.12-300.fc25.x86_64 #1 SMP Fri Dec 2 17:52:11 UTC 2016 x86_64 BOOST_LIB_VERSION=1_53
2017-07-11T20:12:29.537+0800 [initandlisten] allocator: tcmalloc
2017-07-11T20:12:29.537+0800 [initandlisten] options: { systemLog: { verbosity: 1 } }
2017-07-11T20:12:29.537+0800 [initandlisten] User Assertion: 10296:
*********************************************************************
 ERROR: dbpath (/data/db) does not exist.
 Create this directory or give existing directory in --dbpath.
 See http://dochub.mongodb.org/core/startingandstoppingmongo
*********************************************************************

2017-07-11T20:12:29.538+0800 [initandlisten] exception in initAndListen: 10296
*********************************************************************
 ERROR: dbpath (/data/db) does not exist.
 Create this directory or give existing directory in --dbpath.
 See http://dochub.mongodb.org/core/startingandstoppingmongo
*********************************************************************
, terminating
2017-07-11T20:12:29.538+0800 [initandlisten] dbexit:
2017-07-11T20:12:29.538+0800 [initandlisten] shutdown: going to close listening sockets...
2017-07-11T20:12:29.538+0800 [initandlisten] shutdown: going to flush diaglog...
2017-07-11T20:12:29.538+0800 [initandlisten] shutdown: going to close sockets...
2017-07-11T20:12:29.538+0800 [initandlisten] shutdown: waiting for fs preallocator...
2017-07-11T20:12:29.538+0800 [initandlisten] shutdown: lock for final commit...
2017-07-11T20:12:29.538+0800 [initandlisten] shutdown: final commit...
2017-07-11T20:12:29.538+0800 [initandlisten] shutdown: closing all files...
2017-07-11T20:12:29.538+0800 [initandlisten] closeAllFiles() finished
2017-07-11T20:12:29.538+0800 [initandlisten] dbexit: really exiting now

mongoのプロファイルを変更するには:
$ vim /etc/mongod.conf

bind_ip = 0.0.0.0
port = 27017
auth=true

mongodbを再起動するには:
$ service mongod restart

mongodbを閉じる:
$ service mongod stop

(1)kill PID-2を使用してmongodbサーバをシャットダウンします(-9パラメータを使用しないでください.データベースファイルが破損します).(2)mongoクライアントにログイン後、adminデータベースに切り替えてdbを呼び出す.shutdownServer()関数を使用してmongodbサービスを閉じます.
mongo操作の例:
$ mongo MongoDB shell version: 2.6.12 connecting to: test
すべてのデータベースを表示
> show dbs;
admin            (empty)
jiaxiaolei_test  0.078GB
local            0.078GB

指定したデータベースに切り替え
> use jiaxiaolei_test;
switched to db jiaxiaolei_test

現在のすべてのテーブルを表示するには、次の手順に従います.
> show tables;
system.indexes
test

表testのすべてのデータを表示します.
> db.test.find();
{ "_id" : ObjectId("5965cd7867169d2ff6999555"), "name" : "jiaxiaolei", "age" : 20 }

データのエクスポート:
$mongodump--host[ip]-d cmdbここでは172.28.20.124を例に、cmdb database.$mongodump --host 172.28.20.124 -d cmdb
現在のディレクトリの下でdumpディレクトリを生成します.
dumpファイルのコピー:
$ scp -r dump/[email protected]:/root
dumpファイルのインポート:$cd/root
$ mongorestore --drop
mongoアカウントの追加:(createUserの使用を推奨)
show dbs; admin (empty) cmdb 0.078GB jiaxiaolei_test 0.078GB local 0.078GB uop 0.078GB use uop; switched to db uop db.users uop.users db.addUser('uop','uop') WARNING: The 'addUser' shell helper is DEPRECATED. Please use 'createUser' instead Successfully added user: { "user": "uop", "roles": [ "dbOwner"] }
show dbs; admin 0.078GB cmdb 0.078GB jiaxiaolei_test 0.078GB local 0.078GB uop 0.078GB use cmdb; switched to db cmdb db.addUser('cmdb','cmdb') WARNING: The 'addUser' shell helper is DEPRECATED. Please use 'createUser' instead Successfully added user: { "user": "cmdb", "roles": [ "dbOwner"] }
mongoの質問:TODO:
  • dump restore以降、db認証は発効せず、
  • はauthを構成する、dbを必要としない場合がある.auth()は
  • に登録することもできます

  • 認証に失敗しました:
    use uop; switched to db uop db.uop.addUser('uop','uop') 2017-07-14T02:54:09.944+0000 TypeError: Property 'addUser' of object uop.uop is not a function db.addUser('uop','uop') WARNING: The 'addUser' shell helper is DEPRECATED. Please use 'createUser' instead Successfully added user: { "user": "uop", "roles": [ "dbOwner"] } use cmdb; switched to db cmdb db.addUser('cmdb','cmdb') WARNING: The 'addUser' shell helper is DEPRECATED. Please use 'createUser' instead 2017-07-14T02:55:17.196+0000 Error: couldn't add user: not authorized on cmdb to execute command { createUser: "cmdb", pwd: "xxx", roles: [ "dbOwner"], digestPassword: false, writeConcern: { w: "majority", wtimeout: 30000.0 } } at src/mongo/shell/db.js:1086 use cmdb; switched to db cmdb show tables; 2017-07-14T02:55:47.634+0000 error: { "$err": "not authorized for query on cmdb.system.namespaces", "code": 13 } at src/mongo/shell/query.js:131
    mongorestore --drop connected to: 127.0.0.1 assertion: 13 not authorized on admin to execute command { getParameter: 1, authSchemaVersion: 1 }
    ]# mongo MongoDB shell version: 2.6.12 connecting to: test
    show dbs; 2017-07-14T03:26:13.984+0000 listDatabases failed:{ "ok": 0, "errmsg": "not authorized on admin to execute command { listDatabases: 1.0 }", "code": 13 } at src/mongo/shell/mongo.js:47

    特集


    プロファイル


    mongo v2.6.12から、プロファイルは2つあります.
    $ ls -l /etc/mongo
    mongod.conf  mongos.conf
    

    拡張読書