更改mongodb服务器数据目录的目录

时间:2017-12-23 00:35:59

标签: mongodb fedora-27

运行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],但由于我从{{1目录:

permissions

编辑1

如果我手动运行ownership“[不使用/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 个答案:

答案 0 :(得分:0)

您可以查看系统上如何配置SELinux吗?

sestatus
SELinux status:                 enabled
SELinuxfs mount:                /sys/fs/selinux
SELinux root directory:         /etc/selinux
Loaded policy name:             targeted
Current mode:                   permissive
Mode from config file:          permissive
Policy MLS status:              enabled
Policy deny_unknown status:     allowed
Max kernel policy version:      28

如果SELinux处于强制执行模式,则启用对相关端口的访问:

sudo semanage port -a -t mongod_port_t -p tcp 27017

尝试将其设置为允许:

setenforce permissive

这将持续到下次重启,使其永久化,编辑 / etc / selinux / config