安裝mongodb community edition
官方文檔
https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu-tarball/
使用壓縮包安裝
從 https://www.mongodb.com/download-center/community 網站上選擇合適的版本,得到下載鏈接
用wget下載至ubuntu中
wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-ubuntu1804-4.0.10.tgz
解壓壓縮包
tar -zxvf mongodb-linux-*-4.0.10.tgz
將mongodb的路徑添加到Path中
export PATH=<mongodb-install-directory>/bin:$PATH
也可將上述語句添加到bash的配置文件~/.bashrc
中;若使用的是zsh,則添加到 ~/.zshrc
中
創建數據庫存放的目錄(默認爲/data/db)
sudo mkdir -p /data/db
通過--bind_ip_all
實現遠程訪問,而--auth
選項確保需要認證
sudo mongod --bind_ip_all --auth
--auth
選項使用前需要創建用戶及數據庫