安裝
參考官網文件
下載地址:
https://www.mongodb.com/download-center/co...
官網安裝文件:
https://docs.mongodb.com/manual/tutorial/i...
下載後解壓到:
/usr/local/mongodb
配置環境變數:
vim /etc/profile
export MONGODB_HOME=/usr/local/mongodb
PATH="${JAVA_HOME}:${PATH}:${GRADLE_HOME}/bin:${MAVEN_HOME}/bin:${MYSQL_HOME}/bin:{PYTHON_HOME}:${ZOOKEEPER_HOME}/bin:${GROOVY_HOME}/bin:${JENKINS_HOME}:${GRADLE_USER_HOME}:${M2_HOME}:${MONGODB_HOME}/bin"
export PATH
source ~/.zshrc
不使用預設的地址:
/data/db
修改許可權:
sudo chown -R $(whoami) /data
建立自定義的資料地址:
mkdir -p /data/mongodb
建立日誌地址:
mkdir -p /data/logs/mongodb
官網配置檔案說明:
https://docs.mongodb.com/manual/reference/...
建立配置檔案:
vim /usr/local/mongodb/bin/mongodb.conf
systemLog:
destination: file
path: "/data/logs/mongodb/mongod.log"
logAppend: true
storage:
dbPath: "/data/mongodb"
journal:
enabled: true
processManagement:
fork: true # 以守護程式的方式啟動,即在後臺執行
net:
bindIp: 0.0.0.0 # 允許所有連線
port: 27017
setParameter:
enableLocalhostAuthBypass: false
啟動mongo:
/usr/local/mongodb/bin/mongod -f /usr/local/mongodb/bin/mongodb.conf