Ubuntu下mongodb的安裝與使用
阿新 • • 發佈:2021-07-12
mongodb的安裝:
1.MongoDB 原始碼下載地址:https://www.mongodb.com/download-center#community
2.vim /etc/profile修改環境變數:末尾新增
export PATH=$PATH:/home/no4/mongodb/bin
3.source /etc/profile
避免每次都要使用source /etc/profile使環境變數檔案生效的方法:
sudo su
vim ~/.bashrc
末尾新增source /etc/profile
4.新建配置檔案mongod.conf
systemLog: destination: file path: "/home/no4/mongodata/log/mongod.log" logAppend: true storage: dbPath: "/home/no4/mongodata/db" journal: enabled: true processManagement: fork: true net: bindIp: localhost port: 27017
5.在配置檔案所指定的位置建立對應的資料夾
6.mongod -f /home/no4/mongodb/mongod.conf命令啟動mongodb伺服器,正常輸出如下:
root@no4-Default-string:/home/no4# mongod -f ./mongodb/mongod.conf about to fork child process, waiting until server is ready for connections. forked process: 11330 child process started successfully, parent exiting
如果是這樣:
root@no4-Default-string:/home/no4# mongod -f ./mongodb/mongod.conf about to fork child process, waiting until server is ready for connections. forked process: 11306 ERROR: child process failed, exited with 48 To see additional information in this output, start without the "--fork" option.
一般是因為之前已經啟動過了mongodb,使用ps -ef|grep mongod查詢mongod相關程序,然後殺掉後再重試。
7.輸入mongo連線伺服器,再輸入show dbs檢視資料庫,正常輸出如下:
> show dbs
admin 0.000GB
config 0.000GB
local 0.000GB
原文連結:https://blog.csdn.net/wangzhidi/article/details/114261049