运行 Fedora-27,我试图将默认目录更改mongodb
为我的主目录的子目录。
sudo dnf install mongodb-server
版本
[idf@localhost mongodb]$ mongod --version
db version v3.4.6
git version: c55eb86ef46ee7aede3b1e2a5d184a7df4bfb5b5
OpenSSL version: OpenSSL 1.1.0g-fips 2 Nov 2017
allocator: tcmalloc
modules: none
build environment:
distarch: x86_64
target_arch: x86_64
[idf@localhost mongodb]$
我将自己添加到 mongodb 组
[idf@localhost mongodb]$ sudo usermod -g mongodb idf
usermod: no changes
[idf@localhost mongodb]$
在不更改任何其他内容的情况下,我将文件更改为/etc/mongodb.conf
指向dbPath
我创建的目录:
[idf@localhost mongodb]$ more /etc/mongod.conf
##
## For list of options visit:
## https://docs.mongodb.org/manual/reference/configuration-options/
##
# systemLog Options - How to do logging
systemLog:
# The default log message verbosity level for components (0-5)
verbosity: 0
# The destination to which MongoDB sends all log output (file|syslog, if not specifed to STDOUT)
destination: file
# Log file to send write to instead of stdout - has to be a file, not directory
path: /var/log/mongodb/mongod.log
# Append to logpath instead of over-writing (false by default)
logAppend: true
# Set the log rotation behavior (rename|reopen, rename by default)
logRotate: reopen
# processManagement Options - How the process runs
processManagement:
# Fork server process (false by default)
fork: true
# Full path to pidfile (if not set, no pidfile is created)
pidFilePath: /var/run/mongodb/mongod.pid
# net Options - Network interfaces settings
net:
# Specify port number (27017 by default)
port: 27017
# Comma separated list of ip addresses to listen on (all local ips by default)
bindIp: 127.0.0.1,::1
# Enable IPv6 support (disabled by default)
ipv6: true
unixDomainSocket:
# Enable/disable listening on the UNIX domain socket (true by default)
enabled: true
# Alternative directory for UNIX domain sockets (defaults to /tmp)
pathPrefix: /var/run/mongodb
#ssl:
# Set the SSL operation mode (disabled|allowSSL|preferSSL|requireSSL)
#mode: <string>
# PEM file for ssl
#PEMKeyFile: <string>
# Certificate Authority file for SSL
#CAFile: <string>
# storage Options - How and Where to store data
storage:
# Directory for datafiles (defaults to /data/db/)
#dbPath: /var/lib/mongodb
dbPath: /home/idf/mongodb
#journal:
# Enable/Disable journaling (journaling is on by default for 64 bit)
#enabled: true
# The storage engine for the mongod database (mmapv1|wiredTiger, wiredTiger by default
# - works for 64 bit only)
# Also possible to use unstable engines: devnull|ephemeralForTest
engine: wiredTiger
#mmapv1:
# Enable or disable the preallocation of data files (true by default)
#preallocDataFiles: <boolean>
# Use a smaller default file size (false by default)
#smallFiles: <boolean>
#wiredTiger:
#engineConfig:
# The maximum size of the cache that WiredTiger will use for all data
# (max(60% of RAM - 1GB, 1GB) by default)
#cacheSizeGB: 5
# The type of compression to use to compress WiredTiger journal data
# (none|snappy|zlib, snappy by default)
#journalCompressor: <string>
#collectionConfig:
# The default type of compression to use to compress collection data
# (none|snappy|zlib, snappy by default)
#blockCompressor: <string>
# secutiry Options - Authorization and other security settings
#security:
# Private key for cluster authentication
#keyFile: <string>
# Run with/without security (enabled|disabled, disabled by default)
#authorization
# setParameter Options - Set MongoDB server parameters
# setParameter:
# opratrionProfiling Options - Profiling settings
#operationProfiling:
# replication Options - ReplSet settings
#replication:
# sharding Options - Shard settings
#sharding:
我将内容复制/var/lib/mongodb
到我的主目录并更改所有者。
[idf@localhost mongodb]$ pwd
/home/idf/mongodb
[idf@localhost mongodb]$
证明:
[idf@localhost mongodb]$ ls -la
total 252
drwxr-xr-x. 4 mongodb root 4096 Dec 22 19:27 .
drwx------. 44 idf idf 4096 Dec 22 19:27 ..
-rw-r--r--. 1 mongodb mongodb 32768 Dec 22 19:27 collection-0--6927808756336873775.wt
-rw-r--r--. 1 mongodb mongodb 16384 Dec 22 19:27 collection-2--6927808756336873775.wt
drwxr-xr-x. 2 mongodb mongodb 4096 Dec 22 19:27 diagnostic.data
-rw-r--r--. 1 mongodb mongodb 32768 Dec 22 19:27 index-1--6927808756336873775.wt
-rw-r--r--. 1 mongodb mongodb 16384 Dec 22 19:27 index-3--6927808756336873775.wt
-rw-r--r--. 1 mongodb mongodb 16384 Dec 22 19:27 index-4--6927808756336873775.wt
drwxr-xr-x. 2 mongodb mongodb 4096 Dec 22 19:27 journal
-rw-r--r--. 1 mongodb mongodb 16384 Dec 22 19:27 _mdb_catalog.wt
-rw-r--r--. 1 mongodb mongodb 0 Dec 22 19:27 mongod.lock
-rw-r--r--. 1 mongodb mongodb 36864 Dec 22 19:27 sizeStorer.wt
-rw-r--r--. 1 mongodb mongodb 95 Dec 22 19:27 storage.bson
-rw-r--r--. 1 mongodb mongodb 49 Dec 22 19:27 WiredTiger
-rw-r--r--. 1 mongodb mongodb 4096 Dec 22 19:27 WiredTigerLAS.wt
-rw-r--r--. 1 mongodb mongodb 21 Dec 22 19:27 WiredTiger.lock
-rw-r--r--. 1 mongodb mongodb 993 Dec 22 19:27 WiredTiger.turtle
-rw-r--r--. 1 mongodb mongodb 53248 Dec 22 19:27 WiredTiger.wt
[idf@localhost mongodb]$ sudo systemctl start mongod
虽然mongodb
如果mongodb.conf
文件dbpath
条目指向/var/lib
,我可以开始,但如果我更改dbpath
到我在我的主目录上复制的目录,我会收到一个错误:
[idf@localhost mongodb]$ sudo systemctl start mongod
[sudo] password for idf:
Job for mongod.service failed because the control process exited with error code.
See "systemctl status mongod.service" and "journalctl -xe" for details.
[idf@localhost mongodb]$
status
提供更多信息,但我不知道这是什么意思:
[idf@localhost mongodb]$ sudo systemctl status mongod
● mongod.service - High-performance, schema-free document-oriented database
Loaded: loaded (/usr/lib/systemd/system/mongod.service; disabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Fri 2017-12-22 20:21:33 EST; 5s ago
Process: 9081 ExecStart=/usr/bin/mongod $OPTIONS run (code=exited, status=100)
Dec 22 20:21:33 localhost.localdomain systemd[1]: Starting High-performance, schema-free document-oriented database...
Dec 22 20:21:33 localhost.localdomain mongod[9081]: about to fork child process, waiting until server is ready for connections.
Dec 22 20:21:33 localhost.localdomain mongod[9081]: forked process: 9083
Dec 22 20:21:33 localhost.localdomain mongod[9081]: ERROR: child process failed, exited with error number 100
Dec 22 20:21:33 localhost.localdomain systemd[1]: mongod.service: Control process exited, code=exited status=100
Dec 22 20:21:33 localhost.localdomain systemd[1]: Failed to start High-performance, schema-free document-oriented database.
Dec 22 20:21:33 localhost.localdomain systemd[1]: mongod.service: Unit entered failed state.
Dec 22 20:21:33 localhost.localdomain systemd[1]: mongod.service: Failed with result 'exit-code'.
[idf@localhost mongodb]$
日志文件提供了有趣的信息[行Unable to determine status of lock file in the data directory
],但我不知道如何解决它,因为我复制了permissions
and ownership
from/var/lib/mongod
目录:
2017-12-22T20:30:16.716-0500 I CONTROL [main] ***** SERVER RESTARTED *****
2017-12-22T20:30:16.722-0500 I CONTROL [initandlisten] MongoDB starting : pid=9483 port=27017 dbpath=/home/idf/mongodb 64-bit host=localhost.localdomain
2017-12-22T20:30:16.722-0500 I CONTROL [initandlisten] db version v3.4.6
2017-12-22T20:30:16.722-0500 I CONTROL [initandlisten] git version: c55eb86ef46ee7aede3b1e2a5d184a7df4bfb5b5
2017-12-22T20:30:16.722-0500 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.1.0g-fips 2 Nov 2017
2017-12-22T20:30:16.722-0500 I CONTROL [initandlisten] allocator: tcmalloc
2017-12-22T20:30:16.722-0500 I CONTROL [initandlisten] modules: none
2017-12-22T20:30:16.722-0500 I CONTROL [initandlisten] build environment:
2017-12-22T20:30:16.722-0500 I CONTROL [initandlisten] distarch: x86_64
2017-12-22T20:30:16.722-0500 I CONTROL [initandlisten] target_arch: x86_64
2017-12-22T20:30:16.722-0500 I CONTROL [initandlisten] options: { command: [ "run" ], config: "/etc/mongod.conf", net: { bindIp: "127.0.0.1,::1", ipv6: true, port: 27017, unixDomainSocket: { enabled: true, pathPrefix: "/var/run/mongodb" } }, processManagement: { fork: true, pidFilePath: "/var/run/mongodb/mongod.pid" }, storage: { dbPath: "/home/idf/mongodb", engine: "wiredTiger" }, systemLog: { destination: "file", logAppend: true, logRotate: "reopen", path: "/var/log/mongodb/mongod.log", verbosity: 0 } }
2017-12-22T20:30:16.722-0500 I STORAGE [initandlisten] exception in initAndListen: 28596 Unable to determine status of lock file in the data directory /home/idf/mongodb: boost::filesystem::status: Permission denied: "/home/idf/mongodb/mongod.lock", terminating
2017-12-22T20:30:16.722-0500 I NETWORK [initandlisten] shutdown: going to close listening sockets...
2017-12-22T20:30:16.722-0500 I NETWORK [initandlisten] shutdown: going to flush diaglog...
2017-12-22T20:30:16.722-0500 I CONTROL [initandlisten] now exiting
2017-12-22T20:30:16.722-0500 I CONTROL [initandlisten] shutting down with code:100
编辑 1
如果我mongod
“手动”运行 [不使用service
...],它可以在我的数据目录中运行。奇怪的...
[idf@localhost mongodb]$ sudo mongod --dbpath /home/idf/mongodb/