【MongoDB】启动
1:命令行:
注:dbpath默认为/data/db,当存在/data/db时,那么无需使用dbpath参数,否则,必须制定dbpath的具体路径
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
[mdb@xxf ~]$ mongod --dbpath=/data/db 2016-01-09T17:07:33.869+0800 I CONTROL [initandlisten] MongoDB starting : pid=4160 port=27017 dbpath=/data/db 64-bit host=xxf 2016-01-09T17:07:33.869+0800 I CONTROL [initandlisten] db version v3.2.1 2016-01-09T17:07:33.869+0800 I CONTROL [initandlisten] git version: a14d55980c2cdc565d4704a7e3ad37e4e535c1b2 2016-01-09T17:07:33.869+0800 I CONTROL [initandlisten] OpenSSL version: OpenSSL 0.9.8e-fips-rhel5 01 Jul 2008 2016-01-09T17:07:33.869+0800 I CONTROL [initandlisten] allocator: tcmalloc 2016-01-09T17:07:33.869+0800 I CONTROL [initandlisten] modules: none 2016-01-09T17:07:33.869+0800 I CONTROL [initandlisten] build environment: 2016-01-09T17:07:33.869+0800 I CONTROL [initandlisten] distmod: rhel55 2016-01-09T17:07:33.869+0800 I CONTROL [initandlisten] distarch: x86_64 2016-01-09T17:07:33.869+0800 I CONTROL [initandlisten] target_arch: x86_64 2016-01-09T17:07:33.869+0800 I CONTROL [initandlisten] options: { storage: { dbPath: "/data/db" } } 2016-01-09T17:07:33.895+0800 I - [initandlisten] Detected data files in /data/db created by the 'wiredTiger' storage engine, so setting the active storage engine to 'wiredTiger'. 2016-01-09T17:07:33.896+0800 I STORAGE [initandlisten] wiredtiger_open config: create,cache_size=1G,session_max=20000,eviction=(threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),checkpoint=(wait=60,log_size=2GB),statistics_log=(wait=0), 2016-01-09T17:07:36.011+0800 I FTDC [initandlisten] Initializing full-time diagnostic data capture with directory '/data/db/diagnostic.data' 2016-01-09T17:07:36.011+0800 I NETWORK [initandlisten] waiting for connections on port 27017 2016-01-09T17:07:36.011+0800 I NETWORK [HostnameCanonicalizationWorker] Starting hostname canonicalization worker: |
2:Daemon
注意:
1)Daemon方式启动,需要使用“–fork”参数,如果使用了“–fork”参数,那么就必须启用“–logpath”参数,没有商量余地
2)“–logpath”指定的目录必须提前创建好
1 2 3 4 5 6 7 8 9 10 11 12 |
[mdb@xxf ~]$ mkdir -p /data/log [mdb@xxf ~]$ [mdb@xxf ~]$ ls -l /data total 8 drwxr-xr-x 4 mdb mdb 4096 Jan 9 15:06 db drwxr-xr-x 2 mdb mdb 4096 Jan 9 15:04 log [mdb@xxf ~]$ [mdb@xxf ~]$ mongod --logpath=/data/log/L.log --fork about to fork child process, waiting until server is ready for connections. forked process: 3529 child process started successfully, parent exiting [mdb@xxf ~]$ |
3:配置文件
1)常看刚刚创建好的配置文件
1 2 3 4 5 |
[mdb@xxf ~]$ cat mongodb.cfg dbpath=/data/db/ logpath=/data/log/L.log [mdb@xxf ~]$ |
2)利用配置文件启动数据库
1 2 3 4 5 |
[mdb@xxf ~]$ mongod -f mongodb.cfg -fork about to fork child process, waiting until server is ready for connections. forked process: 4452 child process started successfully, parent exiting [mdb@xxf ~]$ |
或者
1 2 3 4 5 |
[mdb@xxf ~]$ mongod --config mongodb.cfg -fork about to fork child process, waiting until server is ready for connections. forked process: 4500 child process started successfully, parent exiting [mdb@xxf ~]$ |