最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【已解决】mongo启动失败:Failed to unlink socket file /tmp/mongodb-xxx.sock errno 1 Operation not permitted

MongoDB crifan 453浏览 0评论
折腾:
【已解决】添加了IP限制的mongod重启出错:Job for mongod.service failed because the control process exited with error code
期间,参考:
linux – MongoDB Service Will Not Start After Initial Setup – Stack Overflow
也去看看log中是否有有用的信息
[[email protected] ~]# tail -n 30 /var/log/mongodb/mongod.log 
2018-04-10T10:26:28.355+0800 I FTDC     [signalProcessingThread] Shutting down full-time diagnostic data capture
2018-04-10T10:26:28.356+0800 I CONTROL  [signalProcessingThread] now exiting
2018-04-10T10:26:28.356+0800 I NETWORK  [signalProcessingThread] shutdown: going to close listening sockets...
2018-04-10T10:26:28.356+0800 I NETWORK  [signalProcessingThread] closing listening socket: 6
2018-04-10T10:26:28.356+0800 I NETWORK  [signalProcessingThread] closing listening socket: 7
2018-04-10T10:26:28.356+0800 I NETWORK  [signalProcessingThread] removing socket file: /tmp/mongodb-27017.sock
2018-04-10T10:26:28.356+0800 I NETWORK  [signalProcessingThread] shutdown: going to flush diaglog...
2018-04-10T10:26:28.356+0800 I NETWORK  [signalProcessingThread] shutdown: going to close sockets...
2018-04-10T10:26:28.357+0800 I STORAGE  [signalProcessingThread] WiredTigerKVEngine shutting down
2018-04-10T10:26:28.434+0800 I STORAGE  [signalProcessingThread] shutdown: removing fs lock...
2018-04-10T10:26:28.434+0800 I CONTROL  [signalProcessingThread] dbexit:  rc: 0
2018-04-10T10:26:28.607+0800 I CONTROL  [main] ***** SERVER RESTARTED *****
2018-04-10T10:26:28.615+0800 I CONTROL  [initandlisten] MongoDB starting : pid=1303 port=32018 dbpath=/var/lib/mongo 64-bit host=xxx-general-01
2018-04-10T10:26:28.615+0800 I CONTROL  [initandlisten] db version v3.2.19
2018-04-10T10:26:28.615+0800 I CONTROL  [initandlisten] git version: a9f574de6a566a58b24d126b44a56718d181e989
2018-04-10T10:26:28.615+0800 I CONTROL  [initandlisten] OpenSSL version: OpenSSL 1.0.1e-fips 11 Feb 2013
2018-04-10T10:26:28.615+0800 I CONTROL  [initandlisten] allocator: tcmalloc
2018-04-10T10:26:28.615+0800 I CONTROL  [initandlisten] modules: none
2018-04-10T10:26:28.615+0800 I CONTROL  [initandlisten] build environment:
2018-04-10T10:26:28.615+0800 I CONTROL  [initandlisten]     distmod: rhel70
2018-04-10T10:26:28.615+0800 I CONTROL  [initandlisten]     distarch: x86_64
2018-04-10T10:26:28.615+0800 I CONTROL  [initandlisten]     target_arch: x86_64
2018-04-10T10:26:28.615+0800 I CONTROL  [initandlisten] options: { config: "/etc/mongod.conf", net: { bindIp: "0.0.0.0", 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-10T10:26:28.636+0800 E NETWORK  [initandlisten] Failed to unlink socket file /tmp/mongodb-32018.sock errno:1 Operation not permitted
2018-04-10T10:26:28.636+0800 I -        [initandlisten] Fatal Assertion 28578
2018-04-10T10:26:28.636+0800 I -        [initandlisten] 

***aborting after fassert() failure
很明显,此处是:
Failed to unlink socket file /tmp/mongodb-32018.sock errno:1 Operation not permitted
的问题,是sock的文件的问题
改了端口后,新的sock没有权限访问了?
mongo Failed to unlink socket file tmp mongodb sock errno 1 Operation not permitted
MongoDB – Failed to unlink socket file /tmp/mongodb-27017 – Mkyong.com
去看看对应sock文件权限,果然是root用户的:
[[email protected] ~]# ll -lha /tmp/mongodb-32018.sock
srwx------ 1 root root 0 Apr 10 09:35 /tmp/mongodb-32018.sock
办法:
手动删除掉sock文件:
[[email protected] ~]# sudo rm /tmp/mongodb-32018.sock 
然后再去启动,结果都失败了:
[[email protected] ~]# systemctl start mongod
Job for mongod.service failed because the control process exited with error code. See "systemctl status mongod.service" and "journalctl -xe" for details.
[[email protected] ~]# sudo systemctl start mongod
Job for mongod.service failed because the control process exited with error code. See "systemctl status mongod.service" and "journalctl -xe" for details.
[[email protected] ~]# service mongod start
Starting mongod (via systemctl):  Job for mongod.service failed because the control process exited with error code. See "systemctl status mongod.service" and "journalctl -xe" for details.
                                                           [FAILED]
[[email protected] ~]# ll -lha /tmp/mongodb-32018.sock 
ls: cannot access /tmp/mongodb-32018.sock: No such file or directory
然后,现在去重启服务器,希望服务器启动时,自动重新创建对应的sock文件,且是mongo方面的用户的权限,或许就可以了。
重启服务器reboot,结果:真的就可以了:
[[email protected] ~]# systemctl status mongod
[0m mongod.service - SYSV: Mongo is a scalable, document-oriented database.
   Loaded: loaded (/etc/rc.d/init.d/mongod; bad; vendor preset: disabled)
   Active: active (running) since Tue 2018-04-10 10:36:56 CST; 14s ago
     Docs: man:systemd-sysv-generator(8)
   CGroup: /system.slice/mongod.service
           1083 /usr/bin/mongod -f /etc/mongod.conf

Apr 10 10:36:55 xxx-general-01 systemd[1]: Starting SYSV: Mongo is a scalable, document-oriented database....
Apr 10 10:36:55 xxx-general-01 runuser[1070]: pam_unix(runuser:session): session opened for user mongod by (uid=0)
Apr 10 10:36:56 xxx-general-01 runuser[1070]: pam_unix(runuser:session): session closed for user mongod
Apr 10 10:36:56 xxx-general-01 mongod[1058]: Starting mongod: [  OK  ]
Apr 10 10:36:56 xxx-general-01 systemd[1]: Started SYSV: Mongo is a scalable, document-oriented database..
[[email protected] ~]# ll /tmp/mongodb-32018.sock 
srwx------ 1 mongod mongod 0 Apr 10 10:36 /tmp/mongodb-32018.sock
[[email protected] ~]# netstat -lanp | grep mongo
tcp        0      0 0.0.0.0:32018           0.0.0.0:*               LISTEN      1083/mongod         
unix  2      [ ACC ]     STREAM     LISTENING     15431    1083/mongod          /tmp/mongodb-32018.sock
通过log:
[[email protected] ~]# tail -n 40 /var/log/mongodb/mongod.log  
2018-04-10T10:26:28.615+0800 I CONTROL  [initandlisten]     distmod: rhel70
2018-04-10T10:26:28.615+0800 I CONTROL  [initandlisten]     distarch: x86_64
2018-04-10T10:26:28.615+0800 I CONTROL  [initandlisten]     target_arch: x86_64
2018-04-10T10:26:28.615+0800 I CONTROL  [initandlisten] options: { config: "/etc/mongod.conf", net: { bindIp: "0.0.0.0", 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-10T10:26:28.636+0800 E NETWORK  [initandlisten] Failed to unlink socket file /tmp/mongodb-32018.sock errno:1 Operation not permitted
2018-04-10T10:26:28.636+0800 I -        [initandlisten] Fatal Assertion 28578
2018-04-10T10:26:28.636+0800 I -        [initandlisten] 

***aborting after fassert() failure


2018-04-10T10:36:55.979+0800 I CONTROL  [main] ***** SERVER RESTARTED *****
2018-04-10T10:36:55.989+0800 I CONTROL  [initandlisten] MongoDB starting : pid=1083 port=32018 dbpath=/var/lib/mongo 64-bit host=xxx-general-01
2018-04-10T10:36:55.989+0800 I CONTROL  [initandlisten] db version v3.2.19
2018-04-10T10:36:55.989+0800 I CONTROL  [initandlisten] git version: a9f574de6a566a58b24d126b44a56718d181e989
2018-04-10T10:36:55.989+0800 I CONTROL  [initandlisten] OpenSSL version: OpenSSL 1.0.1e-fips 11 Feb 2013
2018-04-10T10:36:55.989+0800 I CONTROL  [initandlisten] allocator: tcmalloc
2018-04-10T10:36:55.989+0800 I CONTROL  [initandlisten] modules: none
2018-04-10T10:36:55.989+0800 I CONTROL  [initandlisten] build environment:
2018-04-10T10:36:55.989+0800 I CONTROL  [initandlisten]     distmod: rhel70
2018-04-10T10:36:55.989+0800 I CONTROL  [initandlisten]     distarch: x86_64
2018-04-10T10:36:55.989+0800 I CONTROL  [initandlisten]     target_arch: x86_64
2018-04-10T10:36:55.989+0800 I CONTROL  [initandlisten] options: { config: "/etc/mongod.conf", net: { bindIp: "0.0.0.0", 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-10T10:36:56.012+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-10T10:36:56.012+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-10T10:36:56.220+0800 I STORAGE  [initandlisten] WiredTiger [1523327816:220205][1083:0x7f1ce2abbdc0], txn-recover: Main recovery loop: starting at 113/6784
2018-04-10T10:36:56.306+0800 I STORAGE  [initandlisten] WiredTiger [1523327816:306935][1083:0x7f1ce2abbdc0], txn-recover: Recovering log 113 through 114
2018-04-10T10:36:56.310+0800 I STORAGE  [initandlisten] WiredTiger [1523327816:310481][1083:0x7f1ce2abbdc0], txn-recover: Recovering log 114 through 114
2018-04-10T10:36:56.481+0800 I CONTROL  [initandlisten] 
2018-04-10T10:36:56.481+0800 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2018-04-10T10:36:56.481+0800 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2018-04-10T10:36:56.481+0800 I CONTROL  [initandlisten] 
2018-04-10T10:36:56.481+0800 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2018-04-10T10:36:56.481+0800 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2018-04-10T10:36:56.481+0800 I CONTROL  [initandlisten] 
2018-04-10T10:36:56.481+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-10T10:36:56.481+0800 I CONTROL  [initandlisten] 
2018-04-10T10:36:56.489+0800 I FTDC     [initandlisten] Initializing full-time diagnostic data capture with directory '/var/lib/mongo/diagnostic.data'
2018-04-10T10:36:56.490+0800 I NETWORK  [HostnameCanonicalizationWorker] Starting hostname canonicalization worker
2018-04-10T10:36:56.490+0800 I NETWORK  [initandlisten] waiting for connections on port 32018
可以看出:
之前删除了/tmp/mongodb-32018.sock后,结果启动失败,竟然还是说,Operation not permitted,说是没有权限(而不是找不到)
但是不管了,现在重启服务器后,自动创建了新的:
/tmp/mongodb-32018.sock
所有者owner是mongod -》 有权限操作的
所以mongo正常运行了。
所以现在问题解决了,但是没有完全搞清楚:
sock文件是,何时,谁去,创建的?且创建时的权限,文件所有者,是怎么定义的?
启动MongoDB时出现Failed to unlink socket file /tmp/mongodb-27017.sock errno:1 Operation not permitted – CSDN博客
“可以看到这个文件的所有者是root用户,因为在准备环境的时候用的是root用户,而当时用root用户启动过一个没成功,后面修改配置文件过后用mongodb用户启动就出现了这个问题。”
我这里,估计是类似的:
当时是停止掉mongo后,用(远程SSH登录进CentOS时用的是)root用户启动mongo的,
(但是之前好像没有问题啊),总之现在是有问题了,因为mongodb的用户,没有权限访问之前用root创建的
/tmp/mongodb-32018.sock
所以出错了。
[mongoDB]Failed to unlink socket file /tmp/mongodb-[portnum].sock Operation not permitted – CSDN博客
继续尝试搞清楚:
【已解决】mongo服务端配置文件中的sock文件是什么
基本上清楚了:
此处Mongod默认是开启了net中的(Unix的)socket的,且默认路径是/tmp,文件权限是0700
-》所以mongod启动时,此处才会去生成对应的:
/tmp/mongodb-xxx.sock
文件,其中xxx是端口号,比如:
/tmp/mongodb-27017.sock
是用来和,同一主机内的,其他进程,互相通信的。
【总结】
此处不知道之前哪次,停止了mongod,启动了mongod,但是是用的当前的root用户,所以当时启动mongod所创建的用户权限是owner所有者是root,导致mongod这个用户没有权限访问和打开:
/tmp/mongodb-xxx.sock
这个socket文件,从而出错。
解决办法:
删除掉即可:
sudo rm /tmp/mongodb-32018.sock
然后重启服务器即可。
注:按照道理,重启mongod就可以了的,但是不知道为何此处不行,所以干脆重启CentOS服务器,就然后由于之前加了自启动mongod,所以重启服务器后,也启动了mongod,就顺带创建了对应的sock文件,该文件所有者就是mongod了:
[[email protected] ~]# ll /tmp/mongodb-32018.sock 
srwx------ 1 mongod mongod 0 Apr 10 10:36 /tmp/mongodb-32018.sock
然后就有权限打开操作,mongod就可以正常启动了。

转载请注明:在路上 » 【已解决】mongo启动失败:Failed to unlink socket file /tmp/mongodb-xxx.sock errno 1 Operation not permitted

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
92 queries in 0.121 seconds, using 20.65MB memory