一. 安装步骤

1.1 登陆官网https://www.mongodb.com/download-center#community 选择Comunity Server的Ubuntu 16.04 Linux 64-bit x64,然后点击下载mongodb-linux-x86_64-ubuntu1604-4.0.1.tgz,下载地址:https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-ubuntu1604-4.0.1.tgz

wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-ubuntu1604-4.0.1.tgz

1.2 解压

tar -xvf mongodb-linux-x86_64-ubuntu1604-4.0.1.tgz

1.3 将解压包拷贝到/usr/local/mongodb目录

mv mongodb-linux-x86_64-ubuntu1604-4.0.1 /usr/local/mongodb

1.4 设置环境变量

vi ~/.bashrc

在尾端按 i 插入如下指令:

export PATH=/usr/local/mongodb/bin:$PATH

刷新环境变量,使其生效:

source ~/.bashrc

1.5 创建MongoDB数据库目录

MongoDB的数据存储在Data目录的db目录下,但这些目录不会自动创建,需要手动创建/data/db目录,现在根目录(/)下创建data/db目录。

mkdir -p /data/db

注:若用户在其他位置创建data/db目录,需要启动mongod 服务时用--dbpath=xxxx来制定数据库的存储目录。

1.6 启动MongoDB服务

1.6.1 ./mongod,报错:No such file or directory,解决方法:去掉./,直接执行mongod

root@iZrj94ctqezpovr27w292nZ:/home/mongoDB# ./mongod
-bash: ./mongod: No such file or directory

1.6.2 mongod ,报错:找不到libcurl.so.4,解决方法:下载1.6.6注释中的library,解压到系统/usr/lib或/lib文件夹下。

root@iZrj94ctqezpovr27w292nZ:/home/mongoDB# mongod
mongod: error while loading shared libraries: libcurl.so.4: cannot open shared object file: No such file or directory

 1.6.3 mongod ,报错:找不到libssh2.so.1,解决方法:下载1.6.6注释中的library,解压到系统/usr/lib或/lib文件夹下。

root@iZrj94ctqezpovr27w292nZ:/home/mongoDB# mongod
mongod: error while loading shared libraries: libssh2.so.1: cannot open shared object file: No such file or directory

 1.6.4 mongod ,报错:找不到libssl.so.10,解决方法:下载1.6.6注释中的library,解压到系统/usr/lib或/lib文件夹下。

root@iZrj94ctqezpovr27w292nZ:/home/mongoDB# mongod
mongod: error while loading shared libraries: libssl.so.10: cannot open shared object file: No such file or directory

 1.6.5 mongod ,报错:找不到libcrypto.so.10,解决方法:下载1.6.6注释中的library,解压到系统/usr/lib或/lib文件夹下。

root@iZrj94ctqezpovr27w292nZ:/home/mongoDB# mongod
mongod: error while loading shared libraries: libcrypto.so.10: cannot open shared object file: No such file or directory

 1.6.6 mongod ,报错:找不到数据库存储路径,解决方法:mongod --dbpath=XXXX(用户定义的数据库存储路径)

root@iZrj94ctqezpovr27w292nZ:/home/mongoDB# mongod
mongod: /usr/lib/libcurl.so.4: no version information available (required by mongod)
2018-08-15T13:40:06.183+0800 I CONTROL  [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'
2018-08-15T13:40:06.190+0800 I CONTROL  [initandlisten] MongoDB starting : pid=10542 port=27017 dbpath=/data/db 64-bit host=iZrj94ctqezpovr27w292nZ
2018-08-15T13:40:06.190+0800 I CONTROL  [initandlisten] db version v4.0.1
2018-08-15T13:40:06.190+0800 I CONTROL  [initandlisten] git version: 54f1582fc6eb01de4d4c42f26fc133e623f065fb
2018-08-15T13:40:06.190+0800 I CONTROL  [initandlisten] OpenSSL version: OpenSSL 1.0.2g  1 Mar 2016
2018-08-15T13:40:06.190+0800 I CONTROL  [initandlisten] allocator: tcmalloc
2018-08-15T13:40:06.190+0800 I CONTROL  [initandlisten] modules: none
2018-08-15T13:40:06.190+0800 I CONTROL  [initandlisten] build environment:
2018-08-15T13:40:06.190+0800 I CONTROL  [initandlisten]     distmod: ubuntu1604
2018-08-15T13:40:06.190+0800 I CONTROL  [initandlisten]     distarch: x86_64
2018-08-15T13:40:06.190+0800 I CONTROL  [initandlisten]     target_arch: x86_64
2018-08-15T13:40:06.190+0800 I CONTROL  [initandlisten] options: {}
2018-08-15T13:40:06.191+0800 I STORAGE  [initandlisten] exception in initAndListen: NonExistentPath: Data directory /data/db not found., terminating
2018-08-15T13:40:06.191+0800 I CONTROL  [initandlisten] now exiting
2018-08-15T13:40:06.191+0800 I CONTROL  [initandlisten] shutting down with code:100

注:缺失的so文件,下载链接:

链接:https://pan.baidu.com/s/1Qwo3S1OMVFG51fP1VvLp_Q 密码:c8wh

1.7 mongod --dbpath=/home/mongoDB/data/db,成功运行。

 

 

 

Logo

更多推荐