Linux 系统 MongoDB 无法启动的解决方法

Mar 6, 2018 阅读(14480)

标签: MongoDB

本文记录MongoDB服务器无法启动解决过程:

1、执行 service mongod start 启动MongoDB服务器,查询(netstat -nat | grep 27017)MongoDB监听端口结果发现没有启动成功。

2、准备查询mongod日志,通过 mongod.conf 配置文件找到日志存放的路径(/var/log/mongodb/mongod.log);

mongod.conf 配置文件如下:

image.png

3、查询mongod 启动失败日志,less /var/log/mongodb/mongod.log 截取错误信息如下

2018-03-06T09:47:07.028+0800 I CONTROL  [initandlisten] MongoDB starting : pid=22507 port=27017 dbpath=/var/lib/mongo 64-bit host=xuexiyuan

2018-03-06T09:47:07.028+0800 I CONTROL  [initandlisten] db version v3.4.10

2018-03-06T09:47:07.028+0800 I CONTROL  [initandlisten] git version: 078f28920cb24de0dd479b5ea6c66c644f6326e9

2018-03-06T09:47:07.028+0800 I CONTROL  [initandlisten] OpenSSL version: OpenSSL 1.0.1e-fips 11 Feb 2013

2018-03-06T09:47:07.028+0800 I CONTROL  [initandlisten] allocator: tcmalloc

2018-03-06T09:47:07.028+0800 I CONTROL  [initandlisten] modules: enterprise 

2018-03-06T09:47:07.028+0800 I CONTROL  [initandlisten] build environment:

2018-03-06T09:47:07.028+0800 I CONTROL  [initandlisten]     distmod: rhel70

2018-03-06T09:47:07.028+0800 I CONTROL  [initandlisten]     distarch: x86_64

2018-03-06T09:47:07.028+0800 I CONTROL  [initandlisten]     target_arch: x86_64

2018-03-06T09:47:07.028+0800 I CONTROL  [initandlisten] options: { config: "/etc/mongod.conf", net: { port: 27017 }, processManagement: { fork: true, pidFilePath: "/var/run/mongodb/mongod.pid" }, security: { authorization: "enabled" }, storage: { dbPath: "/var/lib/mongo", journal: { enabled: true } }, systemLog: { destination: "file", logAppend: true, path: "/var/log/mongodb/mongod.log" } }

2018-03-06T09:47:07.049+0800 I -        [initandlisten] Detected data files in /var/lib/mongo created by the 'wiredTiger' storage engine, so setting the active storage engine to 'wiredTiger'.

2018-03-06T09:47:07.049+0800 I STORAGE  [initandlisten] 

2018-03-06T09:47:07.049+0800 I STORAGE  [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine

2018-03-06T09:47:07.049+0800 I STORAGE  [initandlisten] **          See http://dochub.mongodb.org/core/prodnotes-filesystem

2018-03-06T09:47:07.049+0800 I STORAGE  [initandlisten] wiredtiger_open config: create,cache_size=7431M,session_max=20000,eviction=(threads_min=4,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),

2018-03-06T09:47:07.057+0800 E STORAGE  [initandlisten] WiredTiger error (13) [1520300827:57608][22507:0x7f7e92184e40], file:WiredTiger.wt, connection: /var/lib/mongo/WiredTiger.turtle: handle-open: open: Permission denied

2018-03-06T09:47:07.058+0800 I -        [initandlisten] Assertion: 28595:13: Permission denied src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp 276

2018-03-06T09:47:07.058+0800 I STORAGE  [initandlisten] exception in initAndListen: 28595 13: Permission denied, terminating

2018-03-06T09:47:07.058+0800 I NETWORK  [initandlisten] shutdown: going to close listening sockets...

2018-03-06T09:47:07.058+0800 I NETWORK  [initandlisten] removing socket file: /tmp/mongodb-27017.sock

2018-03-06T09:47:07.058+0800 I NETWORK  [initandlisten] shutdown: going to flush diaglog...

2018-03-06T09:47:07.058+0800 I CONTROL  [initandlisten] now exiting

2018-03-06T09:47:07.058+0800 I CONTROL  [initandlisten] shutting down with code:100

4、发现启动mongod 服务时存在文件没有权限,因此尝试修改 WiredTiger.turtle 的所属用户,结果还是启动失败,这次通过错误日志看到是该目录下其他文件没有权限。

sudo chown -R mongod:mongod /var/lib/mongo/WiredTiger.turtle

这里面的用户、及用户组mongod 是看到 /var/lib/mongo 目录下大部分文件所属的用户是mongod ,所以用户mongod 用户来尝试。

5、干脆将 /var/lib/mongo 下所有文件所属用户、用户组都改成 mongod,重试后正常启动。

sudo chown -R mongod:mongod /var/lib/mongo


MongoDB学习园