【问题标题】:MongoDB 3.2 on Ubuntu 14.04 appears not to read /etc/mongod.confUbuntu 14.04 上的 MongoDB 3.2 似乎无法读取 /etc/mongod.conf
【发布时间】:2016-03-03 17:03:33
【问题描述】:

我需要帮助找出我在最近的升级中遇到的问题。

在我的 Ubuntu 14.04 系统上,我最近清除了所有 mongod-org

# apt-get purge mongod-org
# apt-get autoremove

然后按照 Mongo 的说明安装,(得到新的密钥添加了 3.2 源)

# apt-get update
# apt-get mongodb-org

一切似乎都安装得很好。所以让我们开始吧:

# service mongod start
mongod start/running, process 18811
# ps -ef | grep 18811
#

换句话说,不启动。没有写入 mongod.log 所以让我们试试命令行吧!

# mongod
2016-03-03T09:46:42.104-0700 I CONTROL  [initandlisten] MongoDB starting :    pid=18816 port=27017 dbpath=/data/db 64-bit host=as3001snllx
2016-03-03T09:46:42.104-0700 I CONTROL  [initandlisten] db version v3.2.3
2016-03-03T09:46:42.104-0700 I CONTROL  [initandlisten] git version: b326ba837cf6f49d65c2f85e1b70f6f31ece7937
2016-03-03T09:46:42.104-0700 I CONTROL  [initandlisten] OpenSSL version: OpenSSL 1.0.1f 6 Jan 2014
2016-03-03T09:46:42.104-0700 I CONTROL  [initandlisten] allocator: tcmalloc
2016-03-03T09:46:42.104-0700 I CONTROL  [initandlisten] modules: none
2016-03-03T09:46:42.104-0700 I CONTROL  [initandlisten] build environment:
2016-03-03T09:46:42.104-0700 I CONTROL  [initandlisten]     distmod: ubuntu1404
2016-03-03T09:46:42.104-0700 I CONTROL  [initandlisten]     distarch: x86_64
2016-03-03T09:46:42.104-0700 I CONTROL  [initandlisten]     target_arch: x86_64
2016-03-03T09:46:42.104-0700 I CONTROL  [initandlisten] options: {}
2016-03-03T09:46:42.145-0700 I STORAGE  [initandlisten] exception in initAndListen: 29 Data directory /data/db not found., terminating
2016-03-03T09:46:42.145-0700 I CONTROL  [initandlisten] dbexit:  rc: 100

啊哈!没有 /data/db 目录!但是,我有 /etc/mongod.conf 应该指向“/var/lib/mongodb”。

这里是 /etc/mongod.conf

$ cat /etc/mongod.conf
storage:
  dbPath: "/var/lib/mongodb"
  engine: "wiredTiger"
  journal:
    enabled: true

systemLog:
  destination: file
  path: "/var/log/mongodb/mongod.log"
  logAppend: true

net:
  bindIp: 127.0.0.1
  port: 27017

所以,也许我的新贵配置没有读取此配置文件,因为 /data/db 是默认设置。但是,我的 /etc/init/mongod.conf 有一个指令应该读取 /etc/mongod.conf。

我的 /etc/init/mongod.conf 文件

# Ubuntu upstart file at /etc/init/mongod.conf

# Recommended ulimit values for mongod or mongos
# See http://docs.mongodb.org/manual/reference/ulimit/#recommended-settings
#
limit fsize unlimited unlimited
limit cpu unlimited unlimited
limit as unlimited unlimited
limit nofile 64000 64000
limit rss unlimited unlimited
limit nproc 64000 64000

kill timeout 300 # wait 300s between SIGTERM and SIGKILL.

pre-start script
  DAEMONUSER=${DAEMONUSER:-mongodb}
  if [ ! -d /var/lib/mongodb ]; then
    mkdir -p /var/lib/mongodb && chown mongodb:mongodb /var/lib/mongodb
  fi
  if [ ! -d /var/log/mongodb ]; then
    mkdir -p /var/log/mongodb && chown mongodb:mongodb /var/log/mongodb
  fi
  touch /var/run/mongodb.pid
  chown $DAEMONUSER /var/run/mongodb.pid
end script

start on runlevel [2345]
stop on runlevel [06]

script
  ENABLE_MONGOD="yes"
  CONF=/etc/mongod.conf
  DAEMON=/usr/bin/mongod
  DAEMONUSER=${DAEMONUSER:-mongodb}
  DAEMONGROUP=${DAEMONGROUP:-mongodb}

  if [ -f /etc/default/mongod ]; then . /etc/default/mongod; fi

  # Handle NUMA access to CPUs (SERVER-3574)
  # This verifies the existence of numactl as well as testing that the command works
  NUMACTL_ARGS="--interleave=all"
  if which numactl >/dev/null 2>/dev/null && numactl $NUMACTL_ARGS ls / >/dev/null 2>/dev/null
  then
    NUMACTL="$(which numactl) -- $NUMACTL_ARGS"
    DAEMON_OPTS=${DAEMON_OPTS:-"--config $CONF"}
  else
    NUMACTL=""
    DAEMON_OPTS="-- "${DAEMON_OPTS:-"--config $CONF"}
  fi

  if [ "x$ENABLE_MONGOD" = "xyes" ]
  then
    exec start-stop-daemon --start \
        --chuid $DAEMONUSER:$DAEMONGROUP \
        --pidfile /var/run/mongodb.pid \
        --make-pidfile \
        --exec $NUMACTL $DAEMON $DAEMON_OPTS --setParameter failIndexKeyTooLong=false
  fi
end script

所以,让我们尝试使用 --config /etc/init.d 从命令行启动 mongod

# mongod --config /etc/mongod.conf

这行得通。但是,我需要这个来通过暴发户!有什么想法吗?

【问题讨论】:

    标签: mongodb ubuntu


    【解决方案1】:

    好的,所以我在 upstart 脚本中添加了一些日志记录:

    script
      exec 2>>/dev/.initramfs/mongo-init.log
      set -x
      ...
    

    下面是这样的:

    more /dev/.initramfs/mongo-init.log
    + ENABLE_MONGOD=yes
    + CONF=/etc/mongod.conf
    + DAEMON=/usr/bin/mongod
    + DAEMONUSER=mongodb
    + DAEMONGROUP=mongodb
    + [ -f /etc/default/mongod ]
    + . /etc/default/mongod
    + limit fsize unlimited unlimited
    /proc/self/fd/9: 1: /etc/default/mongod: limit: not found
    

    查看 /etc/default/mongod,我有:

    more mongod
    limit fsize unlimited unlimited  # (file size)
    limit cpu unlimited unlimited    # (cpu time)
    limit as unlimited unlimited     # (virtual memory size)
    limit nofile 64000 64000         # (open files)
    limit nproc 64000 64000          # (processes/threads)
    

    这是尝试调整以前的版本,我猜它不再受支持。我将所有内容都注释掉了(还不想扔掉),现在暴发户工作了。

    希望这可以帮助遇到类似问题的其他人

    【讨论】:

      猜你喜欢
      • 2014-09-13
      • 2020-02-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多