软件版本
- 阿里云平台 :
- Alibaba Cloud Linux release 3 (OpenAnolis Edition)
- 5.10.134-16.1.al8.x86_64
- 全面兼容Centos 8.0,不兼容Ubantu系统,不能使用apt命令
- MongoDB版本:
- mongodb-linux-x86_64-rhel8-6.0.20-rc3
注意需要选CentOs版本,阿里云全面支持CentOS,如果选Ubantu系统则会出现不能在阿里云系统进行部署
- MongoDbShell -版本: mongosh-2.3.7-linux-x64.tgz
- MongoDB Compass:
- 下载windows版本 版本:1.45.0
部署过程
- 1,解压缩并移动到指定的安装目录:
tar -xvf mongodb-linux-x86_64-rhel8-6.0.20-rc3.tgz -C /root/software/mongodb - 2,创建目录,分别用来存储数据和日志:
mkdir -p /data/mongodb/data/db
mkdir -p /data/mongodb/log
- 3, 修改配置文件: 配置文件内容如下:
systemLog:
#MongoDB发送所有日志输出的目标指定为文件
# #The path of the log file to which mongod or mongos should send all diagnostic logging information
destination: file
#mongod或mongos应向其发送所有诊断日志记录信息的日志文件的路径
path: "/root/software/mongodb/log/mongod.log"
#当mongos或mongod实例重新启动时,mongos或mongod会将新条目附加到现有日志文件的末尾。
logAppend: true
storage:
#mongod实例存储其数据的目录。storage.dbPath设置仅适用于mongod。
##The directory where the mongod instance stores its data.Default Value is "/data/db".
dbPath: "/root/software/mongodb/data/db"
journal:
#启用或禁用持久性日志以确保数据文件保持有效和可恢复。
enabled: true
processManagement:
#启用在后台运行mongos或mongod进程的守护进程模式。
fork: true
net:
#服务实例绑定的IP,默认是localhost
bindIp: ::,0.0.0.0
#绑定的端口,默认是27017
port: 27017
#bindIpAll: true
a, 配置文件是yaml格式,注意格式对齐。
b,net,bindIp目前允许所有IP进行访问。
- 4,启动:进入到MongoDB安装的bin目录下:
./mongod -f /root/software/mongodb/mongod.conf - 5,查看是否启动成功
ps -ef|grep mongod
root 457777 1 0 Dec26 ? 00:21:18 ./mongod -f /root/software/mongodb/mongod.conf
root 466994 466909 0 09:44 pts/0 00:00:00 grep --color=auto mongod
测试验证
安装下载MongoDBShell
- 1,下载MongoDBShell:
wget https://downloads.mongodb.com/compass/mongosh-2.3.7-linux-x64.tgz - 2,解压缩MongoDBShell:
tar -xvf mongosh-2.3.7-linux-x64.tgz -C /root/software - 3,安装MongoDBshell
a,进入MongoDBshell安装目录执行:
./mongosh
安装MongoDBCompass
- 1,在windows中安装MongoDBCompass
- 2,关闭阿里云防火墙
- 3,
阿里云安全组允许MongoDB端口访问注意:阿里云的安全组需要在当前安全组中进行配置,如果新增的安全组,必须保障新增的安全组绑定了当前实例的IP才可以。
- 4,使用MongoDB Compass进行链接
链接成功:
优化
MongoDB加入到环境变量
1,打开~/.bash_profile
vi ~/.bash_profile
2, 追加环境变量:/root/software/mongodb/bin 和 /root/software/mongosh/bin, 如下:
PATH=$PATH:$HOME/bin:/root/software/mongodb/bin:/root/software/mongosh/bin
export PATH
3,环境变量立即生效
source ~/.bash_profile
- 启动MongoDB:
在任意目录执行:
mongod -f /root/software/mongodb/mongod.conf - 启动mongosh
在任务目录执行:
mongosh