解决启动mongodb --fork报错 -ERROR: child process failed, exited with error number 1
总用量 283996
-rwxrwxr-x. 1 wangshumin wangshumin 10434783 2月 23 04:03 bsondump
-rwxr-xr-x. 1 wangshumin wangshumin 5792 2月 23 04:17 install_compass
-rwxrwxr-x. 1 wangshumin wangshumin 33564168 2月 23 04:17 mongo
-rwxrwxr-x. 1 wangshumin wangshumin 59071048 2月 23 04:18 mongod
-rwxrwxr-x. 1 wangshumin wangshumin 12792838 2月 23 04:03 mongodump
-rwxrwxr-x. 1 wangshumin wangshumin 10795682 2月 23 04:03 mongoexport
-rwxrwxr-x. 1 wangshumin wangshumin 10676925 2月 23 04:03 mongofiles
-rwxrwxr-x. 1 wangshumin wangshumin 10948502 2月 23 04:03 mongoimport
-rwxrwxr-x. 1 wangshumin wangshumin 58592048 2月 23 04:18 mongoperf
-rwxrwxr-x. 1 wangshumin wangshumin 14163393 2月 23 04:04 mongoreplay
-rwxrwxr-x. 1 wangshumin wangshumin 14152240 2月 23 04:03 mongorestore
-rwxrwxr-x. 1 wangshumin wangshumin 33943704 2月 23 04:17 mongos
-rwxrwxr-x. 1 wangshumin wangshumin 11008111 2月 23 04:03 mongostat
-rwxrwxr-x. 1 wangshumin wangshumin 10634212 2月 23 04:04 mongotop
[[email protected] bin]$ ./mongod --dbpath /home/wangshumin/path/database --logpath /home/wangshumin/path/log/mongod.log --fork --port 27017
about to fork child process, waiting until server is ready for connections.
forked process: 2919
child process started successfully, parent exiting
[[email protected] bin]$ ./mongo
MongoDB shell version v3.6.3
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 3.6.3
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
http://docs.mongodb.org/
Questions? Try the support group
http://groups.google.com/group/mongodb-user
Server has startup warnings:
2018-03-03T18:40:52.284+0800 I CONTROL [initandlisten]
2018-03-03T18:40:52.285+0800 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2018-03-03T18:40:52.285+0800 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2018-03-03T18:40:52.285+0800 I CONTROL [initandlisten]
2018-03-03T18:40:52.285+0800 I CONTROL [initandlisten] ** WARNING: This server is bound to localhost.
2018-03-03T18:40:52.285+0800 I CONTROL [initandlisten] ** Remote systems will be unable to connect to this server.
2018-03-03T18:40:52.285+0800 I CONTROL [initandlisten] ** Start the server with --bind_ip <address> to specify which IP
2018-03-03T18:40:52.285+0800 I CONTROL [initandlisten] ** addresses it should serve responses from, or with --bind_ip_all to
2018-03-03T18:40:52.285+0800 I CONTROL [initandlisten] ** bind to all interfaces. If this behavior is desired, start the
2018-03-03T18:40:52.285+0800 I CONTROL [initandlisten] ** server with --bind_ip 127.0.0.1 to disable this warning.
2018-03-03T18:40:52.285+0800 I CONTROL [initandlisten]
2018-03-03T18:40:52.307+0800 I CONTROL [initandlisten]
2018-03-03T18:40:52.307+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2018-03-03T18:40:52.307+0800 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2018-03-03T18:40:52.308+0800 I CONTROL [initandlisten]
2018-03-03T18:40:52.308+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2018-03-03T18:40:52.308+0800 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2018-03-03T18:40:52.308+0800 I CONTROL [initandlisten]
2018-03-03T18:40:52.308+0800 I CONTROL [initandlisten] ** WARNING: soft rlimits too low. rlimits set to 3821 processes, 65536 files. Number of processes should be at least 32768 : 0.5 times number of files.
2018-03-03T18:40:52.308+0800 I CONTROL [initandlisten]
> lll
2018-03-03T18:43:17.713+0800 E QUERY [thread1] ReferenceError: lll is not defined :
@(shell):1:1
>
> list
2018-03-03T18:43:22.520+0800 E QUERY [thread1] ReferenceError: list is not defined :
@(shell):1:1
> show dbs;
admin 0.000GB
config 0.000GB
local 0.000GB
> db.createCollection(‘collectionName’)
2018-03-03T18:49:53.074+0800 E QUERY [thread1] SyntaxError: illegal character @(shell):1:20
> use local
switched to db local
> show tables;
startup_log
失败的原因是因为通过service mongodb restart时启动失败,或者如果是直接kill 掉来关闭都会出现这种情况
是因为没有正常关闭导致的。
那么如何正常关闭mongodb?
可以去看官方文档:
http://docs.mongodb.org/manual/tutorial/manage-mongodb-processes/
先通过shell连上服务器:
mongo
use admin
db.shutdownServer()
或者直接kill -15 <pid>,注意kill -9 可能会导致数据文件损坏
那么处理这种要先删掉数据存放点里的mongodb.lock,和日志文件,在logpath的位置,全部删掉,然后再 mongod --repair -f /etc/mongod.conf
是修复,但有可能还是不行,这时我采用了直接把数据考到另一个地方,然后通过/mongod --port 27017 --datapath /新的位置 --logpath /新的位置 --fork 这样就可以启动了
我认为都是因为他记录了在log里,如果还是用原来的log很可能启动不了,一个新的log,没有记录出错的地方就可以启动,反正我认为只要删了lock文件,并指向到一个新的log目录,或者是删掉原来log目录里的所有文件就可以。启动不了主要是两个地方控治,一个就是mongod.lock,另一个就是log
对了注意启动时logpath /home/mongodb/logs/mongod.log 这里是指向一个文件,而不是目录,如果不是指向文件也是启动不了
而dbpath 指向的是一个目录