Linux安装mongodb

一、安装mongoDB

##1.进入指定的目录位置
 cd /usr/local
##2.创建mongodb文件夹
 mkdir mongodb
##3.进入创建的mongodb文件夹
 cd mongodb
##4.wget下载mongoDb安装包
 wget  https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-4.0.7.tgz
##5.解压下载的mongoDb安装包
 tar -zxvf  mongodb-linux-x86_64-4.0.7.tgz
##6.进入解压的mongodb-linux-x86_64-4.0.7文件
 cd mongodb-linux-x86_64-4.0.7
##7.创建logs和datas文件夹
 mkdir -p logs datas
##8.给mongodb-linux-x86_64-4.0.7文件授权
 chmod  777 /usr/local/mongodb/mongodb-linux-x86_64-4.0.7

二、mongoDB配置

1.cd bin
2.vim mongodb.conf
## 数据目录
dbpath = /usr/local//mongodb/mongodb-linux-x86_64-4.0.7/datas
## 日志文件
logpath =/usr/local//mongodb/mongodb-linux-x86_64-4.0.7/logs/mongodb.log
## 端口号:默认27017
port = 27017
## 后台启动
fork = true
## 可外网访问
bind_ip=0.0.0.0

三、启动服务端

方式1: ./mongod --config mongodb.conf
方式2: ./mongod -f mongodb.conf

四、启动客户端

./mongo

五、停止mongoDB

./mongod -shutdown -dbpath=/usr/local/mongodb/data

六、开机启动配置

##设置权限    
chmod 754 mongodb.service  
##开机启动   
systemctl enable mongodb.service 
##启动服务    
systemctl start mongodb.service    
##关闭服务    
systemctl stop mongodb.service 
##加入环境变量 
vim /etc/profile
#在最后加入
export PATH="/usr/local/mongodb/mongodb/bin:$PATH"
#保存后执行
source /etc/profile

七、MongoDB错误的总结

  • child process failed, exited with error number 1
  • child process failed, exited with error number 48
  • child process failed, exited with error number 100
posted @ 2021-09-03 15:13  奋--斗  阅读(1092)  评论(0编辑  收藏  举报