1.下载解压
下载链接
下载完成后就可以传到虚拟机上啦
[xiaokang@hadoop software]$ ll
解压并重命名:
[xiaokang@hadoop software]$ tar -zxvf mongodb-linux-x86_64-4.0.10.tgz
[xiaokang@hadoop software]$ rm -rf mongodb-linux-x86_64-4.0.10.tgz
[xiaokang@hadoop software]$ mv mongodb-linux-x86_64-4.0.10/ mongodb-4.0.10
2.配置的创建与修改
创建数据目录和日志目录
[xiaokang@hadoop mongodb-4.0.10]$ mkdir -p single/data/db
[xiaokang@hadoop mongodb-4.0.10]$ mkdir -p single/log
创建配置文件
[xiaokang@hadoop mongodb-4.0.10]$ vim single/mongod.conf
添加以下内容:
systemLog:
#MongoDB发送所有日志输出的目标指定为文件
destination: file
#mongod或mongos应向其发送所有诊断日志记录信息的日志文件的路径
path: "/opt/software/mongodb-4.0.10/single/log/mongod.log"
#当mongos或mongod实例重新启动时,mongos或mongod会将新条目附加到现有日志文件的末尾
logAppend: true
storage:
#mongod实例存储其数据的目录。storage.dbPath设置仅适用于mongod。
dbPath: "/opt/software/mongodb-4.0.10/single/data/db"
journal:
#启用或禁用持久性日志以确保数据文件保持有效和可恢复
enabled: true
processManagement:
#启用在后台运行mongos或mongod进程的守护进程模式
fork: true
net:
#服务实例绑定的IP
bindIp: hadoop
#bindIp
#绑定的端口,默认是27017
port: 27017
3.mongod启动(后置启动)
[xiaokang@hadoop ~]$ /opt/software/mongodb-4.0.10/bin/mongod -f /opt/software/mongodb-4.0.10/single/mongod.conf
about to fork child process, waiting until server is ready for connections.
forked process: 9672
child process started successfully, parent exiting
查看进程
[xiaokang@hadoop ~]$ ps -ef | grep mongod
xiaokang 9672 1 0 21:19 ? 00:00:01 /opt/software/mongodb-4.0.10/bin/mongod -f /opt/sof
xiaokang 9715 9387 0 21:23 pts/0 00:00:00 grep --color=auto mongod
进入客户端
[xiaokang@hadoop ~]$ /opt/software/mongodb-4.0.10/bin/mongo --host hadoop --port 27017
> show dbs
admin 0.000GB
config 0.000GB
local 0.000GB
4.制作启动脚本
[xiaokang@hadoop ~]$ cd /opt/software/mongodb-4.0.10/bin/
[xiaokang@hadoop bin]$ touch mongod-server-start.sh
[xiaokang@hadoop bin]$ chmod u+x mongod-server-start.sh
[xiaokang@hadoop bin]$ vim mongod-server-start.sh
#将以下两行内容添加到mongod-server-start.sh
MONGODB_HOME=/opt/software/mongodb-4.0.10
ssh hadoop "${MONGODB_HOME}/bin/mongod -f /opt/software/mongodb-4.0.10/single/mongod.conf"
#测试启动
[xiaokang@hadoop ~]$ mongod-server-start.sh
[xiaokang@hadoop ~]$ ps -ef | grep mongo
xiaokang 10093 1 4 21:42 ? 00:00:00 /opt/software/mongodb-4.0.10/bin/mongod -f /opt/software/mongodb-4.0.10/single/mongod.conf
xiaokang 10140 9670 0 21:42 pts/0 00:00:00 grep --color=auto mongo
4.Compass连接mongod
Hostname填hadoop,因为我的Windows端和linux端都配置了映射,所以可以直接填写hadoop,如果你没有配置映射,可以填写linux端的ip地址。填好后点击连接
如图所示:连接成功
5. mongod 关闭
[xiaokang@hadoop ~]$ mongod --shutdown --dbpath /opt/software/mongodb-4.0.10/single/data/db/
# 或者
[xiaokang@hadoop ~]$ mongod --shutdown --config /opt/software/mongodb-4.0.10/single/mongod.conf