折腾:
期间,虽然解决了之前的sock文件的问题:
而且也已经去掉了:
在bindIp中尝试添加外网的客户端的IP的错误做法
但是却又出现别的问题:
2018-04-10T14:29:37.932+0800 I CONTROL [initandlisten] options: { config: "/etc/mongod.conf", net: { bindIp: "127.0.0.1,172.16.141.197", port: 32018 }, 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-04-10T14:29:37.956+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-04-10T14:29:37.956+0800 I STORAGE [initandlisten] wiredtiger_open config: create,cache_size=8G,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),verbose=(recovery_progress), 2018-04-10T14:29:37.968+0800 E STORAGE [initandlisten] WiredTiger (13) [1523341777:968015][1095:0x7fa3cf097dc0], file:WiredTiger.wt, connection: /var/lib/mongo/WiredTiger.turtle: handle-open: open: Permission denied 2018-04-10T14:29:37.969+0800 I - [initandlisten] Assertion: 28595:13: Permission denied 2018-04-10T14:29:37.969+0800 I STORAGE [initandlisten] exception in initAndListen: 28595 13: Permission denied, terminating 2018-04-10T14:29:37.969+0800 I CONTROL [initandlisten] dbexit: rc: 100
即:
WiredTiger (13) [1523341777:968015][1095:0x7fa3cf097dc0], file:WiredTiger.wt, connection: /var/lib/mongo/WiredTiger.turtle: handle-open: open: Permission denied
算了,暂时不去为了,mongo所在服务器的局域网的其他后期可能存在的服务器能访问此服务器了。
所以去掉这个IP,只保留127.0.0.1:
vi /etc/mongod.conf 27 net: 28 port: 32018 29 bindIp: 127.0.0.1 # Listen to local interface only, comment to listen on all interfaces.
重启服务器,结果错误依旧:
2018-04-10T14:45:27.837+0800 I CONTROL [initandlisten] options: { config: "/etc/mongod.conf", net: { bindIp: "127.0.0.1", port: 32018 }, 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-04-10T14:45:27.907+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-04-10T14:45:27.907+0800 I STORAGE [initandlisten] wiredtiger_open config: create,cache_size=8G,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),verbose=(recovery_progress), 2018-04-10T14:45:27.918+0800 E STORAGE [initandlisten] WiredTiger (13) [1523342727:918317][1096:0x7f9d668e4dc0], file:WiredTiger.wt, connection: /var/lib/mongo/WiredTiger.turtle: handle-open: open: Permission denied 2018-04-10T14:45:27.919+0800 I - [initandlisten] Assertion: 28595:13: Permission denied 2018-04-10T14:45:27.919+0800 I STORAGE [initandlisten] exception in initAndListen: 28595 13: Permission denied, terminating 2018-04-10T14:45:27.919+0800 I CONTROL [initandlisten] dbexit: rc: 100
mongo 127.0.0.0 /var/lib/mongo/WiredTiger.turtle: handle-open: open: Permission denied
“I’m having problems lauching mongod as a service: How is it possible that it works when I do sudo mongod -f /etc/mongod.conf but when launching it with sudo service mongod start I get an error in the log”
和我遇到的一样:
重启服务器:会自动尝试去启动mongod
但是服务器已经启动后,用root用户通过ssh进去服务器后,去用service启动mongod,结果都没有反应,不起作用
此处,其主要提到的是文件的权限问题。
而我此处也是,去看看文件权限,还果然是,有几个文件是root,而不是mongod:
[root@xxx-general-01 ~]# ll -lha /var/lib/mongo/ total 4.6G drwxr-xr-x 4 mongod mongod 4.0K Apr 10 14:29 . drwxr-xr-x. 28 root root 4.0K Mar 23 11:16 .. -rw-r--r-- 1 mongod mongod 4.6G Apr 10 14:29 collection-0-2140692489680982673.wt -rw-r--r-- 1 mongod mongod 20K Apr 10 14:29 collection-0--2650623679816886832.wt -rw-r--r-- 1 mongod mongod 36K Apr 10 14:29 collection-0--3691121321241124749.wt -rw-r--r-- 1 mongod mongod 316K Apr 10 14:29 collection-2-2140692489680982673.wt -rw-r--r-- 1 mongod mongod 16K Apr 10 14:29 collection-2--3691121321241124749.wt -rw-r--r-- 1 mongod mongod 16K Apr 10 14:29 collection-4--3691121321241124749.wt -rw-r--r-- 1 mongod mongod 36K Apr 10 14:29 collection-6--3691121321241124749.wt drwxr-xr-x 2 mongod mongod 4.0K Apr 10 14:29 diagnostic.data -rw-r--r-- 1 mongod mongod 84K Apr 9 17:57 index-0--2784828041412477720.wt -rw-r--r-- 1 mongod mongod 244K Apr 9 17:57 index-1-2140692489680982673.wt -rw-r--r-- 1 mongod mongod 20K Apr 8 11:41 index-1--2650623679816886832.wt -rw-r--r-- 1 mongod mongod 36K Apr 10 14:29 index-1--3691121321241124749.wt -rw-r--r-- 1 mongod mongod 60K Apr 9 17:57 index-3-2140692489680982673.wt -rw-r--r-- 1 mongod mongod 16K Apr 2 10:07 index-3--3691121321241124749.wt -rw-r--r-- 1 mongod mongod 232K Apr 9 17:57 index-4-2140692489680982673.wt -rw-r--r-- 1 mongod mongod 16K Apr 10 14:29 index-5--3691121321241124749.wt -rw-r--r-- 1 mongod mongod 36K Apr 9 16:04 index-7--3691121321241124749.wt -rw-r--r-- 1 mongod mongod 36K Apr 10 13:59 index-8--3691121321241124749.wt drwxr-xr-x 2 mongod mongod 4.0K Apr 10 14:27 journal -rw-r--r-- 1 mongod mongod 36K Apr 10 14:29 _mdb_catalog.wt -rw-r--r-- 1 mongod mongod 0 Apr 10 14:29 mongod.lock -rw-r--r-- 1 mongod mongod 36K Apr 10 14:29 sizeStorer.wt -rw-r--r-- 1 mongod mongod 95 Mar 20 22:05 storage.bson -rw-r--r-- 1 mongod mongod 49 Mar 20 22:05 WiredTiger -rw-r--r-- 1 root root 4.0K Apr 10 14:29 WiredTigerLAS.wt -rw-r--r-- 1 mongod mongod 21 Mar 20 22:05 WiredTiger.lock -rw-r--r-- 1 root root 1003 Apr 10 14:29 WiredTiger.turtle -rw-r--r-- 1 mongod mongod 84K Apr 10 14:29 WiredTiger.wt [root@xxx-general-01 ~]# ll -lha /var/lib/mongo/WiredTiger.turtle -rw-r--r-- 1 root root 1003 Apr 10 14:29 /var/lib/mongo/WiredTiger.turtle [root@xxx-general-01 ~]#
所以去改为mongod:
[root@xxx-general-01 ~]# chown mongod:mongod /var/lib/mongo/WiredTiger.turtle [root@xxx-general-01 ~]# chown mongod:mongod /var/lib/mongo/WiredTigerLAS.wt [root@xxx-general-01 ~]# ll -lha /var/lib/mongo/ total 4.6G drwxr-xr-x 4 mongod mongod 4.0K Apr 10 14:29 . drwxr-xr-x. 28 root root 4.0K Mar 23 11:16 .. -rw-r--r-- 1 mongod mongod 4.6G Apr 10 14:29 collection-0-2140692489680982673.wt -rw-r--r-- 1 mongod mongod 20K Apr 10 14:29 collection-0--2650623679816886832.wt -rw-r--r-- 1 mongod mongod 36K Apr 10 14:29 collection-0--3691121321241124749.wt -rw-r--r-- 1 mongod mongod 316K Apr 10 14:29 collection-2-2140692489680982673.wt -rw-r--r-- 1 mongod mongod 16K Apr 10 14:29 collection-2--3691121321241124749.wt -rw-r--r-- 1 mongod mongod 16K Apr 10 14:29 collection-4--3691121321241124749.wt -rw-r--r-- 1 mongod mongod 36K Apr 10 14:29 collection-6--3691121321241124749.wt drwxr-xr-x 2 mongod mongod 4.0K Apr 10 14:29 diagnostic.data -rw-r--r-- 1 mongod mongod 84K Apr 9 17:57 index-0--2784828041412477720.wt -rw-r--r-- 1 mongod mongod 244K Apr 9 17:57 index-1-2140692489680982673.wt -rw-r--r-- 1 mongod mongod 20K Apr 8 11:41 index-1--2650623679816886832.wt -rw-r--r-- 1 mongod mongod 36K Apr 10 14:29 index-1--3691121321241124749.wt -rw-r--r-- 1 mongod mongod 60K Apr 9 17:57 index-3-2140692489680982673.wt -rw-r--r-- 1 mongod mongod 16K Apr 2 10:07 index-3--3691121321241124749.wt -rw-r--r-- 1 mongod mongod 232K Apr 9 17:57 index-4-2140692489680982673.wt -rw-r--r-- 1 mongod mongod 16K Apr 10 14:29 index-5--3691121321241124749.wt -rw-r--r-- 1 mongod mongod 36K Apr 9 16:04 index-7--3691121321241124749.wt -rw-r--r-- 1 mongod mongod 36K Apr 10 13:59 index-8--3691121321241124749.wt drwxr-xr-x 2 mongod mongod 4.0K Apr 10 14:27 journal -rw-r--r-- 1 mongod mongod 36K Apr 10 14:29 _mdb_catalog.wt -rw-r--r-- 1 mongod mongod 0 Apr 10 14:29 mongod.lock -rw-r--r-- 1 mongod mongod 36K Apr 10 14:29 sizeStorer.wt -rw-r--r-- 1 mongod mongod 95 Mar 20 22:05 storage.bson -rw-r--r-- 1 mongod mongod 49 Mar 20 22:05 WiredTiger -rw-r--r-- 1 mongod mongod 4.0K Apr 10 14:29 WiredTigerLAS.wt -rw-r--r-- 1 mongod mongod 21 Mar 20 22:05 WiredTiger.lock -rw-r--r-- 1 mongod mongod 1003 Apr 10 14:29 WiredTiger.turtle -rw-r--r-- 1 mongod mongod 84K Apr 10 14:29 WiredTiger.wt
然后再去重启mongod服务,这下:
不用reboot重启CentOS
也不用,直接以root去运行mongod
而是参考解释,去以特定的mongod用户去运行mongod:
[root@xxx-general-01 ~]# sudo -u mongod mongod -f /etc/mongod.conf about to fork child process, waiting until server is ready for connections. forked process: 1290 ERROR: child process failed, exited with error number 100
看log,又是权限问题:
2018-04-10T15:17:50.250+0800 I CONTROL [initandlisten] options: { config: "/etc/mongod.conf", net: { bindIp: "127.0.0.1", port: 32018 }, 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-04-10T15:17:50.271+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-04-10T15:17:50.271+0800 I STORAGE [initandlisten] wiredtiger_open config: create,cache_size=8G,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),verbose=(recovery_progress), 2018-04-10T15:17:50.293+0800 E STORAGE [initandlisten] WiredTiger (13) [1523344670:293798][1290:0x7f726ee76dc0], txn-recover: /var/lib/mongo/journal/WiredTigerLog.0000000115: handle-open: open: Permission denied 2018-04-10T15:17:50.293+0800 E STORAGE [initandlisten] WiredTiger (0) [1523344670:293851][1290:0x7f726ee76dc0], txn-recover: WiredTiger is unable to read the recovery log. 2018-04-10T15:17:50.293+0800 E STORAGE [initandlisten] WiredTiger (0) [1523344670:293882][1290:0x7f726ee76dc0], txn-recover: This may be due to the log files being encrypted, being from an older version or due to corruption on disk 2018-04-10T15:17:50.293+0800 E STORAGE [initandlisten] WiredTiger (0) [1523344670:293892][1290:0x7f726ee76dc0], txn-recover: You should confirm that you have opened the database with the correct options including all encryption and compression options 2018-04-10T15:17:50.293+0800 E STORAGE [initandlisten] WiredTiger (13) [1523344670:293911][1290:0x7f726ee76dc0], txn-recover: Recovery failed: Permission denied 2018-04-10T15:17:50.297+0800 I - [initandlisten] Assertion: 28595:13: Permission denied 2018-04-10T15:17:50.297+0800 I STORAGE [initandlisten] exception in initAndListen: 28595 13: Permission denied, terminating 2018-04-10T15:17:50.297+0800 I CONTROL [initandlisten] dbexit: rc: 100
去看看出了问题的文件:
/var/lib/mongo/journal/WiredTigerLog.0000000115
[root@xxx-general-01 ~]# ll -lha /var/lib/mongo/journal/* -rw-r--r-- 1 root root 6.9K Apr 10 14:29 /var/lib/mongo/journal/WiredTigerLog.0000000115 -rw-r--r-- 1 mongod mongod 100M Apr 10 15:17 /var/lib/mongo/journal/WiredTigerLog.0000000116
再去更改root为mongod用户:
[root@xxx-general-01 ~]# chown mongod:mongod /var/lib/mongo/journal/* [root@xxx-general-01 ~]# ll -lha /var/lib/mongo/journal/* -rw-r--r-- 1 mongod mongod 6.9K Apr 10 14:29 /var/lib/mongo/journal/WiredTigerLog.0000000115 -rw-r--r-- 1 mongod mongod 100M Apr 10 15:17 /var/lib/mongo/journal/WiredTigerLog.0000000116
再去启动看看
[root@xxx-general-01 ~]# sudo -u mongod mongod -f /etc/mongod.conf about to fork child process, waiting until server is ready for connections. forked process: 1305 child process started successfully, parent exiting
貌似可以了?
去看看log确认一下:
[root@xxx-general-01 ~]# tail -n 30 /var/log/mongodb/mongod.log 2018-04-10T15:21:15.228+0800 I CONTROL [main] ***** SERVER RESTARTED ***** 2018-04-10T15:21:15.236+0800 I CONTROL [initandlisten] MongoDB starting : pid=1305 port=32018 dbpath=/var/lib/mongo 64-bit host=xxx-general-01 2018-04-10T15:21:15.236+0800 I CONTROL [initandlisten] db version v3.2.19 2018-04-10T15:21:15.236+0800 I CONTROL [initandlisten] git version: a9f574de6a566a58b24d126b44a56718d181e989 2018-04-10T15:21:15.236+0800 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.1e-fips 11 Feb 2013 2018-04-10T15:21:15.236+0800 I CONTROL [initandlisten] allocator: tcmalloc 2018-04-10T15:21:15.236+0800 I CONTROL [initandlisten] modules: none 2018-04-10T15:21:15.236+0800 I CONTROL [initandlisten] build environment: 2018-04-10T15:21:15.236+0800 I CONTROL [initandlisten] distmod: rhel70 2018-04-10T15:21:15.236+0800 I CONTROL [initandlisten] distarch: x86_64 2018-04-10T15:21:15.236+0800 I CONTROL [initandlisten] target_arch: x86_64 2018-04-10T15:21:15.236+0800 I CONTROL [initandlisten] options: { config: "/etc/mongod.conf", net: { bindIp: "127.0.0.1", port: 32018 }, 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-04-10T15:21:15.257+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-04-10T15:21:15.257+0800 I STORAGE [initandlisten] wiredtiger_open config: create,cache_size=8G,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),verbose=(recovery_progress), 2018-04-10T15:21:15.499+0800 I STORAGE [initandlisten] WiredTiger [1523344875:499624][1305:0x7f3d92391dc0], txn-recover: Main recovery loop: starting at 115/6784 2018-04-10T15:21:15.619+0800 I STORAGE [initandlisten] WiredTiger [1523344875:619723][1305:0x7f3d92391dc0], txn-recover: Recovering log 115 through 117 2018-04-10T15:21:15.620+0800 I STORAGE [initandlisten] WiredTiger [1523344875:620880][1305:0x7f3d92391dc0], txn-recover: Recovering log 116 through 117 2018-04-10T15:21:15.692+0800 I STORAGE [initandlisten] WiredTiger [1523344875:692810][1305:0x7f3d92391dc0], txn-recover: Recovering log 117 through 117 2018-04-10T15:21:15.838+0800 I CONTROL [initandlisten] 2018-04-10T15:21:15.838+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'. 2018-04-10T15:21:15.838+0800 I CONTROL [initandlisten] ** We suggest setting it to 'never' 2018-04-10T15:21:15.838+0800 I CONTROL [initandlisten] 2018-04-10T15:21:15.838+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'. 2018-04-10T15:21:15.838+0800 I CONTROL [initandlisten] ** We suggest setting it to 'never' 2018-04-10T15:21:15.838+0800 I CONTROL [initandlisten] 2018-04-10T15:21:15.838+0800 I CONTROL [initandlisten] ** WARNING: soft rlimits too low. rlimits set to 4096 processes, 65535 files. Number of processes should be at least 32767.5 : 0.5 times number of files. 2018-04-10T15:21:15.838+0800 I CONTROL [initandlisten] 2018-04-10T15:21:15.844+0800 I NETWORK [HostnameCanonicalizationWorker] Starting hostname canonicalization worker 2018-04-10T15:21:15.844+0800 I FTDC [initandlisten] Initializing full-time diagnostic data capture with directory '/var/lib/mongo/diagnostic.data' 2018-04-10T15:21:15.844+0800 I NETWORK [initandlisten] waiting for connections on port 32018
终于是可以正常启动了。
【总结】
此处,mongo启动失败:
[initandlisten] WiredTiger (13) [1523342727:918317][1096:0x7f9d668e4dc0], file:WiredTiger.wt, connection: /var/lib/mongo/WiredTiger.turtle: handle-open: open: Permission denied
和:
[initandlisten] WiredTiger (13) [1523344670:293798][1290:0x7f726ee76dc0], txn-recover: /var/lib/mongo/journal/WiredTigerLog.0000000115: handle-open: open: Permission denied
的原因是:
之前的某次通过root去启动mongo,导致生成了所有者owner是root的文件:
/var/lib/mongo/WiredTiger.turtle
/var/lib/mongo/journal/WiredTigerLog.0000000115
从而在mongo服务通过mongod这个用户去启动时,没有权限访问。
解决办法是:
把对应的文件的所有者改回给mongod:
chown mongod:mongod /var/lib/mongo/WiredTiger.turtle chown mongod:mongod /var/lib/mongo/WiredTigerLAS.wt chown mongod:mongod /var/lib/mongo/journal/*
即可正常(在当前登录用户root的情况下,换用mongd的用户去)启动mongod:
sudo -u mongod mongod -f /etc/mongod.conf
了。
转载请注明:在路上 » 【已解决】mongo启动失败:connection /var/lib/mongo/WiredTiger.turtle handle-open open Permission denied