mongodb-安装&配置&启动

下载:https://www.mongodb.com/dr/fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-4.0.3.tgz/download

解压:tar -zxvf mongodb-linux-x86_64-rhel70-4.0.3.tgz 

启动服务端:

[root@cent7-zuoys bin]# cd mongodb-linux-x86_64-rhel70-4.0.3/bin

直接运行./mongod,报错:NonExistentPath: Data directory /data/db not found., terminating

--创建数据库存储目录和日志存储目录

[root@cent7-zuoys bin]# mkdir data

[root@cent7-zuoys bin]# cd data

[root@cent7-zuoys data]# mkdir db

[root@cent7-zuoys data]# mkdir logs

--创建mongodb.conf并配置

进入/root/mongodb/mongodb-linux-x86_64-rhel70-4.0.3/bin目录

[root@cent7-zuoys bin]# vi mongodb.conf 

内容如下:

#MongoDB config start - 2018-10-22

# 设置数据文件的存放目录
dbpath=/root/mongodb/mongodb-linux-x86_64-rhel70-4.0.3/bin/data/db

# 设置日志文件的存放目录及其日志文件名
logpath = /root/mongodb/mongodb-linux-x86_64-rhel70-4.0.3/bin/data/logs/mongodb.log

#任何远程ip都能访问
bind_ip = 0.0.0.0
# 设置端口号(默认的端口号是 27017)
port = 27017

#如果auth=true则,客户端所有操作都需要一个用户;否则,不需要用户,可以匿名操作。

#auth=true

# 设置为以守护进程的方式运行,即在后台运行
#fork = true

# nohttpinterface = true

#MongoDB config end - 2018-10-22

启动服务端:

[root@cent7-zuoys bin]# ./mongod --config mongodb.conf 

启动成功后,远程telnet,成功。

启动客户端:

[root@cent7-zuoys ~]# cd mongodb/mongodb-linux-x86_64-rhel70-4.0.3/bin/
[root@cent7-zuoys bin]# ./mongo

MongoDB shell version v4.0.3
connecting to: mongodb://127.0.0.1:27017

参考:https://www.linuxidc.com/Linux/2016-06/132675.htm

原文地址:https://www.cnblogs.com/yaoyuan2/p/9828880.html