标签:scom cep pen star mit server 文件 常见 serve
前言系统环境:
[root@rabbitmq3 mongo]# uname -r
3.10.0-693.21.1.el7.x86_64
[root@rabbitmq3 mongo]# cat /etc/redhat-release
CentOS Linux release 7.4.1708 (Core)
[root@rabbitmq3 mongo]#
mongodb版本:
MongoDB shell version v3.4.10.1
同事的测试服务器的MongoDB在被他kill -9杀掉进程之后,发现服务无法启动了,报下面的错误:
[root@rabbitmq3 lib64]# /usr/local/mongo/bin/mongod -f /usr/local/mongo/mongodb.conf
about to fork child process, waiting until server is ready for connections.
forked process: 2691
ERROR: child process failed, exited with error number 100
[root@rabbitmq3 lib64]#
查看mongodb.log,发现有下面的报错:
2018-11-02T16:08:17.698+0800 I CONTROL [initandlisten] MongoDB starting : pid=2691 port=27017 dbpath=/usr/local/mongo/data 64-bit host=rabbitmq3
2018-11-02T16:08:17.698+0800 I CONTROL [initandlisten] db version v3.4.10.1
2018-11-02T16:08:17.698+0800 I CONTROL [initandlisten] git version: c8bea1aa423c3b6b8d2cea9206b48a915411236a
2018-11-02T16:08:17.698+0800 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.2k-fips 26 Jan 2017
2018-11-02T16:08:17.698+0800 I CONTROL [initandlisten] allocator: tcmalloc
2018-11-02T16:08:17.698+0800 I CONTROL [initandlisten] modules: none
2018-11-02T16:08:17.698+0800 I CONTROL [initandlisten] build environment:
2018-11-02T16:08:17.698+0800 I CONTROL [initandlisten] distmod: rhel70
2018-11-02T16:08:17.698+0800 I CONTROL [initandlisten] distarch: x86_64
2018-11-02T16:08:17.698+0800 I CONTROL [initandlisten] target_arch: x86_64
2018-11-02T16:08:17.698+0800 I CONTROL [initandlisten] options: { config: "/usr/local/mongo/mongodb.conf", net: { port: 27017 }, processManagement: { fork: true }, storage: { dbPath: "/usr/local/mongo/data", e
ngine: "mmapv", journal: { enabled: false } }, systemLog: { destination: "file", path: "/usr/local/mongo/logs/mongodb.log" } }
2018-11-02T16:08:17.732+0800 I STORAGE [initandlisten] exception in initAndListen: 18656 Cannot start server with an unknown storage engine: mmapv, terminating
2018-11-02T16:08:17.732+0800 I NETWORK [initandlisten] shutdown: going to close listening sockets...
2018-11-02T16:08:17.732+0800 I NETWORK [initandlisten] removing socket file: /tmp/mongodb-27017.sock
2018-11-02T16:08:17.732+0800 I NETWORK [initandlisten] shutdown: going to flush diaglog...
2018-11-02T16:08:17.732+0800 I CONTROL [initandlisten] now exiting
2018-11-02T16:08:17.732+0800 I CONTROL [initandlisten] shutting down with code:100
根据报错信息的“exception in initAndListen: 18656 Cannot start server with an unknown storage engine: mmapv, terminating”,查看mongodb的配置文件:
[root@rabbitmq3 mongo]# cat /usr/local/mongo/mongodb.conf
dbpath=/usr/local/mongo/data
logpath=/usr/local/mongo/logs/mongodb.log
port=27017
fork=true
journal=false
storageEngine=mmapv #看到了这一行信息
[root@rabbitmq3 mongo]#
将配置文件mongodb.conf里面的“storageEngine=mmapv”这一行注释掉,再启动服务,发现可以启动了:
[root@rabbitmq3 mongo]# /usr/local/mongo/bin/mongod -f /usr/local/mongo/mongodb.conf
about to fork child process, waiting until server is ready for connections.
forked process: 3146
child process started successfully, parent exiting
[root@rabbitmq3 mongo]#
[root@rabbitmq3 mongo]# ps -ef|grep mongo
root 3146 1 1 16:05 ? 00:00:00 /usr/local/mongo/bin/mongod -f /usr/local/mongo/mongodb.conf
root 3163 2823 0 16:05 pts/2 00:00:00 grep --color=auto mongo
[root@rabbitmq3 mongo]#
然后将配置文件里面的“storageEngine=mmapv”这一行放开注释(改成了storageEngine=mmapv1),发现启动还是报原来的错
[root@rabbitmq3 lib64]# /usr/local/mongo/bin/mongod -f /usr/local/mongo/mongodb.conf
about to fork child process, waiting until server is ready for connections.
forked process: 2352
ERROR: child process failed, exited with error number 100
[root@rabbitmq3 lib64]#
据同事说,上面的配置文件是他直接从网上复制粘贴的,这里面有两个问题:
1、同事可能是想将存储引擎改成mmapv1,但是可能是粘贴错误,也可能是他自己在前期定位过程中误改成了mmapv;
2、这是3.4版本的mongdb,从MongoDB3.2 版本开始,MongoDB默认的存储引擎就已经是WiredTiger,配置文件里面配置的data目录/usr/local/mongo/data是WiredTiger引擎的数据。当引擎改成mmapv1,data目录与WiredTiger引擎还指向同一个目录,就会报“ERROR: child process failed, exited with error number 100”的错。
因为WiredTiger引擎创建的数据目录无法用mmapv1引擎去打开。
所以将配置文件的“storageEngine=mmapv”注释掉,服务就正常启动了。
方法一:kill -2 PID
方法二:use admin;
db.shutdownServer()
登录到mongodb,执行db.serverStatus();语句,在返回的结果中,就能找到像下面的引擎信息:
>db.serverStatus();
...... #省略若干行
"storageEngine" : {
"name" : "wiredTiger",
"supportsCommittedReads" : true,
"readOnly" : false,
"persistent" : true
},
3.1 搭建好MongoDB的时候就切换:
因为MongoDB不同的版本有自己默认的存储引擎,如果在MongoDB刚刚搭建好的时候,就要修改存储引擎,那就直接在配置文件指定引擎类型,然后启动服务就可以了,例如下面的文件:
[root@rabbitmq3 mongodb]# cat /etc/mongodb/mongo_mmapv1.conf
dbpath=/usr/local/mongo/data
logpath=/usr/local/mongo/logs/mongodb.log
port=27017
fork=true
journal=false
storageEngine=mmapv1 #指定引擎类型
[root@test104 mongodb]#
3.2 MongoDB已经使用了一段时间之后切换:
例如,将使用了一段时间的MongoDB3.4版本默认的WiredTiger引擎切换成mmapv1引擎:
1)创建一个新的mmapv1引擎的数据目录:
[root@rabbitmq3 mongo]# mkdir /opt/mongo/data -p
2)修改配置文件(以上面的配置文件为例,这里重新创建了一个新的配置文件):
[root@rabbitmq3 mongo]# cat /etc/mongodb/mongodb_mmapv1.conf
dbpath=/opt/mongo/data #修改数据目录,/opt/mongo 目录是重新创建的全新的目录
logpath=/opt/mongo/mongodb.log
port=27017
fork=true
journal=false
storageEngine=mmapv1 #增加这一行
[root@rabbitmq3 mongo]#
3)重新启动MongoDB(将配置文件指向新的mmapv1引擎的配置文件):
[root@rabbitmq3 bin]# ./mongod -f /etc/mongodb/mongo_mmapv1.conf
about to fork child process, waiting until server is ready for connections.
forked process: 93783
child process started successfully, parent exiting
[root@rabbitmq3 bin]#
4)登录mongodb,执行db.serverStatus(); 检查当前的存储引擎,发现已经改成了mmapv1:
>db.serverStatus();
...... #省略若干行
"storageEngine" : {
"name" : "mmapv1", #引擎已经修改成了mmapv1
"supportsCommittedReads" : false,
"readOnly" : false,
"persistent" : true
拿到这个报错,有找过百度、谷歌,常见的说法有下面两种,虽然没有解决我的问题,记下作为借鉴:
1)是因为在数据目录下生成了mongod.lock 文件,需要将这个文件删除,然后再重新启动(这种说法最常见)
2)可能是dbpath文件的权限问题
看了一下,正常启动的mongodb,也有mongod.lock文件,mongod.lock里面就是当前mongodb的进程号:
[root@rabbitmq3 mongodb]# ps -ef|grep mongo
root 94611 1 0 14:42 ? 00:00:01 ./mongod -f /etc/mongodb/mongo_mmapv1.conf
root 94627 4575 0 14:42 pts/0 00:00:00 ./mongo
root 94834 4719 0 14:46 pts/1 00:00:00 grep --color=auto mongo
[root@rabbitmq3 mongodb]#
[root@rabbitmq3 mongodb]#
[root@rabbitmq3 mongodb]#
[root@rabbitmq3 mongodb]#
[root@rabbitmq3 mongodb]#
[root@rabbitmq3 mongodb]# cat /usr/local/mongo/data/mongod.lock
94611
[root@rabbitmq3 mongodb]#
标签:scom cep pen star mit server 文件 常见 serve
原文地址:http://blog.51cto.com/10950710/2315051