如何在Ubuntu 16上设置Mongodb?

时间:2016-06-28 12:37:26

标签: mongodb ubuntu ubuntu-16.04

我尝试使用这些说明在我的Ubuntu 16.04 LTS中安装mongodb:

Install MongoDB

当我试图运行命令时

mongod
从终端

我收到以下错误:

2016-06-28T17:55:05.299+0530 I CONTROL  [initandlisten] MongoDB starting : pid=1982 port=27017 dbpath=/data/db 64-bit host=rasik
    2016-06-28T17:55:05.299+0530 I CONTROL  [initandlisten] db version v3.2.7
    2016-06-28T17:55:05.299+0530 I CONTROL  [initandlisten] git version: 4249c1d2b5999ebbf1fdf3bc0e0e3b3ff5c0aaf2
    2016-06-28T17:55:05.299+0530 I CONTROL  [initandlisten] OpenSSL version: OpenSSL 1.0.2g-fips  1 Mar 2016
    2016-06-28T17:55:05.299+0530 I CONTROL  [initandlisten] allocator: tcmalloc
    2016-06-28T17:55:05.299+0530 I CONTROL  [initandlisten] modules: none
    2016-06-28T17:55:05.299+0530 I CONTROL  [initandlisten] build environment:
    2016-06-28T17:55:05.299+0530 I CONTROL  [initandlisten]     distmod: ubuntu1404
    2016-06-28T17:55:05.299+0530 I CONTROL  [initandlisten]     distarch: x86_64
    2016-06-28T17:55:05.299+0530 I CONTROL  [initandlisten]     target_arch: x86_64
    2016-06-28T17:55:05.299+0530 I CONTROL  [initandlisten] options: {}
    2016-06-28T17:55:05.447+0530 I STORAGE  [initandlisten] exception in initAndListen: 29 Data directory /data/db not found., terminating
    2016-06-28T17:55:05.447+0530 I CONTROL  [initandlisten] dbexit:  rc: 100
    a

如何解决?

更新:

我收到此警告如何解决此问题:

Server has startup warnings: 
2016-06-28T22:01:51.482+0530 I CONTROL  [initandlisten] 
2016-06-28T22:01:51.482+0530 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2016-06-28T22:01:51.482+0530 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2016-06-28T22:01:51.482+0530 I CONTROL  [initandlisten] 
2016-06-28T22:01:51.482+0530 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2016-06-28T22:01:51.482+0530 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2016-06-28T22:01:51.482+0530 I CONTROL  [initandlisten] 

2 个答案:

答案 0 :(得分:2)

注意做它说的话:

 Data directory /data/db not found

该目录不存在,那边MongoDB存储数据。你需要创建它:

mkdir -R /data/db

并确保用户已读取写入权限。

答案 1 :(得分:2)

Mongo正在寻找默认数据目录/ data / db,它不存在。 您可以创建/ data / db,也可以在您已拥有的文件夹中创建任何子文件夹。然后尝试

mongod --dbpath pathtosubfolder

启动服务器。 然后在另一个终端启动客户端shell:

mongo

这应该有用。