Mongodb 3.4 on 64bit Ubuntu 16.04 mongodb-27017.sock ERROR

时间:2017-02-08 22:18:22

标签: mongodb

有一些与Mongodb 3.2相关的帖子,但是当我尝试安装3.4时,启动不会发生。而是在日志文件中出现异常错误(显示在列表的最后)。 这可能是因为安装了旧版本? 我确实做了一个apt-get删除和清除。 任何人都可以提出错误出现的原因吗?

我按照下面的步骤here

进行了操作
$ sudo apt-get remove  mongodb*
$ sudo apt-get purge  mongodb*
$ sudo rm -rf /usr/lib/mongodb
$ sudo rm -rf /usr/log/mongodb
$ sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6
$ echo "deb [ arch=amd64,arm64 ] http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.4.list
$ sudo apt-get update
$ sudo apt-get install -y mongodb-org
..
..
E: There were unauthenticated packages and -y was used without --allow-unauthenticated

$ sudo apt-get install mongodb-org # removed -y to get it going
..
..


Setting up mongodb-org (3.4.2) ...
$ sudo chown -R mongodb:mongodb /var/log/mongodb
$ sudo chown -R mongodb:mongodb /var/lib/mongodb # modified ownership in view of what is stated on the mongodb installation note

$ # created the following file
$ cat /etc/systemd/system/mongod.service 
[Unit]
Description=MongoDB Database Service 3.4
Wants=network.target
After=network.target

[Service]
User=mongodb
Group=mongodb
ExecStart=/usr/bin/mongod --quiet --config /etc/mongod.conf
StandardOutput=syslog
StandardError=syslog

[Install]
WantedBy=multi-user.target

# startup
$ sudo systemctl daemon-reload
$ sudo service mongod start

# nothing happens, I then viewed the log file and the following error appears:
$ cat /var/log/mongodb/mongod.log
2017-02-08T22:08:26.155+0000 I CONTROL  [main] ***** SERVER RESTARTED *****
2017-02-08T22:08:26.159+0000 I CONTROL  [initandlisten] MongoDB starting : pid=11384 port=27017 dbpath=/var/lib/mongodb 64-bit host=12g
2017-02-08T22:08:26.159+0000 I CONTROL  [initandlisten] db version v3.4.2
2017-02-08T22:08:26.159+0000 I CONTROL  [initandlisten] git version: 3f76e40c105fc223b3e5aac3e20dcd026b83b38b
2017-02-08T22:08:26.159+0000 I CONTROL  [initandlisten] OpenSSL version: OpenSSL 1.0.2g  1 Mar 2016
2017-02-08T22:08:26.159+0000 I CONTROL  [initandlisten] allocator: tcmalloc
2017-02-08T22:08:26.159+0000 I CONTROL  [initandlisten] modules: none
2017-02-08T22:08:26.159+0000 I CONTROL  [initandlisten] build environment:
2017-02-08T22:08:26.159+0000 I CONTROL  [initandlisten]     distmod: ubuntu1604
2017-02-08T22:08:26.159+0000 I CONTROL  [initandlisten]     distarch: x86_64
2017-02-08T22:08:26.159+0000 I CONTROL  [initandlisten]     target_arch: x86_64
2017-02-08T22:08:26.159+0000 I CONTROL  [initandlisten] options: { config: "/etc/mongod.conf", net: { bindIp: "127.0.0.1", port: 27017 }, storage: { dbPath: "/var/lib/mongodb", journal: { enabled: true } }, systemLog: { destination: "file", logAppend: true, path: "/var/log/mongodb/mongod.log", quiet: true } }
2017-02-08T22:08:26.178+0000 E NETWORK  [initandlisten] Failed to unlink socket file /tmp/mongodb-27017.sock Operation not permitted

2 个答案:

答案 0 :(得分:2)

Failed to unlink socket file /tmp/mongodb-27017.sock Operation not permitted

这意味着mongod进程是由root用户启动的。所以你可以删除sock文件或运行此命令来解决这个问题:

sudo chown `whoami` /tmp/mongodb-*.sock

确保您指定的端口需要可访问且不被防火墙阻止,然后重新启动mongod进程。

  

控制台输出中的等待连接消息指示   mongod.exe进程正在成功运行。

您可以查看Install MongoDB Community Edition on Ubuntu

希望这有帮助。

答案 1 :(得分:0)

@mcgraddy,谢谢,这确实很有帮助。创建目录并复制服务文件就是答案。

$ sudo cp /etc/systemd/system/mongod.service /etc/systemd/system/mongodb.service

$ sudo mkdir -p /data/db
$ sudo chown -R $USER:$USER /data

我必须更改/ data的所有权。 启动服务和查看状态显示一切正在按预期运行:

$ sudo service mongod start
$ sudo systemctl status mongodb
● mongodb.service - MongoDB Database Service
   Loaded: loaded (/etc/systemd/system/mongodb.service; enabled; vendor preset: 
   Active: active (running) since Thu 2017-02-09 13:26:07 GMT; 9min ago
 Main PID: 1184 (mongod)
   CGroup: /system.slice/mongodb.service
           └─1184 /usr/bin/mongod --quiet --config /etc/mongod.conf

Feb 09 13:26:07 systemd[1]: Started MongoDB Database Service.