OpenEuler安装MongoDB

服务器版本

下载与安装

下载地址:

Download MongoDB Community Server | MongoDB

8.0.11下载地址

https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel8-8.0.11.tgz

准备安装

新建MongoDB目录

#mkdir /opt/software/mongoDB 

进入MongoDB目录

#cd /opt/software/mongoDB 

下载

#wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel8-8.0.11.tgz

开始安装

解压安装包

#tar -xzvf mongodb-linux-x86_64-rhel8-8.0.11.tgz

配置

进入解压出来的目录

#cd mongodb-linux-x86_64-rhel88-8.0.11

创建数据目录

#mkdir /opt/software/mongoDB/mongodb-linux-x86_64-rhel88-8.0.11/data

#mkdir /opt/software/mongoDB/mongodb-linux-x86_64-rhel88-8.0.11/data/db

创建日志目录

#mkdir /opt/software/mongoDB/mongodb-linux-x86_64-rhel88-8.0.11/logs

在日志目录下创建日志文件:mongodb.log

#touch /opt/software/mongoDB/mongodb-linux-x86_64-rhel88-8.0.11/logs/mongodb.log

创建配置目录

#mkdir /opt/software/mongoDB/mongodb-linux-x86_64-rhel88-8.0.11/conf

在配置目录下创建配置文件:mongodb.conf

storage:
  dbPath: /opt/software/mongoDB/mongodb-linux-x86_64-rhel88-8.0.11/data/db
systemLog:
  destination: file
  path: /opt/software/mongoDB/mongodb-linux-x86_64-rhel88-8.0.11/logs/mongodb.log
  logAppend: true
net:
  port: 27017
  bindIp: 0.0.0.0

目录文件结构:

修改环境变量

编辑文件:/etc/profile

追加以下内容:

export MONGODB_HOME=/opt/software/mongoDB/mongodb-linux-x86_64-rhel88-8.0.11
export PATH=$PATH:$MONGODB_HOME/bin

使环境变量生效

#source /etc/profile

查看MongoDB版本

#cd /opt/software/mongoDB/mongodb-linux-x86_64-rhel88-8.0.11/bin

#./mongod --version

开启防火墙

查看防火墙状态:

#firewall-cmd --state

如果已经开启,则增加开发MongoDB端口

#firewall-cmd --add-port=27017/tcp --permanent  
#service firewalld restart

启动MongoDB

#cd /opt/software/mongoDB/mongodb-linux-x86_64-rhel88-8.0.11/bin
#mongod -f /opt/software/mongoDB/mongodb-linux-x86_64-rhel88-8.0.11/conf/mongodb.conf 

如下图所示,没有报任何提示信息说明启动成功 

启动成功后,db目录有以下内容:

查看MongoDB服务是否启动

#netstat -lanp | grep "27017" 

如果没有任何返回信息,表示没有启动

如果有类似如下信息返回,表示MongoDB已经启动

设置开机启动

编辑文件:/etc/rc.d/rc.local,追加以下内容:

/opt/software/mongoDB/mongodb-linux-x86_64-rhel88-8.0.11/bin/mongod --config /opt/software/mongoDB/mongodb-linux-x86_64-rhel88-8.0.11/conf/mongodb.conf

安装MongoDB Shell管理工具

MongoDB Shell下载地址:

MongoDB Shell Download | MongoDB

#wget https://downloads.mongodb.com/compass/mongosh-2.5.6-linux-x64.tgz

然后解压出来 

#tar -xzvf mongosh-2.5.6-linux-x64.tgz

登录数据库

 进入解压出来的MongoDB shell目录中的bin目录

#cd /opt/software/mongoDB/mongosh-2.5.6-linux-x64/bin

执行

#./mongosh 192.168.245.145:27017

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值