1. 安装
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys D68FA50FEA312927 echo "deb http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.2.list sudo apt-get update sudo apt-get install -y mongodb-org sudo service mongod start
2. 允许远程连接
sudo vim /etc/mongod.conf bindIp处改为 bindIp = 0.0.0.0
sudo service mongod restart
3. auth设置
sudo vim /etc/mongod.conf bind_ip 添加: security: authorization: enabled
sudo service mongod restart
4. 新建数据库及用户
use order db.createCollection('OrderInfo') db.createUser( { user: "order", pwd: "123456", roles: [ "readWrite", "dbAdmin" ] })