运行Mongod进程,查看日志信息如下:
2022-05-24T14:52:07.742+0800 I STORAGE [initandlisten] Detected data files in /data/mongodb/data created by the 'wiredTiger' storage engine, so setting the active storage engine to 'wiredTiger'.
2022-05-24T14:52:07.742+0800 I STORAGE [initandlisten] exception in initAndListen: InvalidOptions: Requested option conflicts with current storage engine option for directoryPerDB; you requested true but the current server storage is already set to false and cannot be changed, terminating
这里显示InvalidOptions:请求的选项与当前directoryPerDB的存储引擎选项冲突;
检查配置文件
cat /etc/mongod.conf
......
journal:
enabled: true
directoryPerDB: true
....
报错原因为: 但当前服务器存储已设置为false,无法更改,终止 !
storage.directoryPerDB
类型:布尔值
默认值:false
设置为true,MongoDB 使用单独的目录来存储每个数据库的数据。目录在storage.dbPath目录下,每个子目录名对应数据库名。
即在首次启动时设置需设置为true,加上–directoryperdb参数如下启动:
/usr/local/mongodb/bin/mongod --dbpath /data/mongodb/data --bind_ip localhost,192.168.1.1 --port 27017 --fork --journal --logpath /data/mongodb/log/mongod.log --logappend --noauth --directoryperdb
如果首次没加 --directoryperdb , 之后重启再加该参数,则冲突报错。 设置该参数之后,每个库单独一个目录:
root@ubuntu:/data/mongodb/data# ls -l
total 292
drwxr-x--- 7 mongodb mongodb 4096 5月 24 15:53 ./
drwxr-x--- 4 mongodb mongodb 4096 5月 24 15:30 ../
drwx------ 2 mongodb mongodb 4096 5月 24 15:31 admin/
drwx------ 2 mongodb mongodb 4096 5月 24 15:31 config/
drwx------ 2 mongodb mongodb 4096 5月 24 15:53 diagnostic.data/
drwx------ 2 mongodb mongodb 4096 5月 24 15:30 journal/
drwx------ 2 mongodb mongodb 4096 5月 24 15:30 local/
-rw------- 1 mongodb mongodb 36864 5月 24 15:32 _mdb_catalog.wt
-rw------- 1 mongodb mongodb 6 5月 24 15:30 mongod.lock
-r-------- 1 mongodb mongodb 1024 5月 24 15:30 replsetAIK
-rw------- 1 mongodb mongodb 36864 5月 24 15:53 sizeStorer.wt
-rw------- 1 mongodb mongodb 114 5月 24 15:30 storage.bson
-rw------- 1 mongodb mongodb 47 5月 24 15:30 WiredTiger
-rw------- 1 mongodb mongodb 4096 5月 24 15:30 WiredTigerLAS.wt
-rw------- 1 mongodb mongodb 21 5月 24 15:30 WiredTiger.lock
-rw------- 1 mongodb mongodb 1192 5月 24 15:53 WiredTiger.turtle
-rw------- 1 mongodb mongodb 167936 5月 24 15:53 WiredTiger.wt