下载地址
Download MongoDB Community Server | MongoDB
选择
下载
下载后是 mongodb-linux-x86_64-4.0.28.tgz
解压
tar -zxvf mongodb-linux-x86_64-4.0.28.tgz
创建data 和 log目录
cd /data/xxx/mongodb/mongodb-linux-x86_64-4.0.28
mkdir data
mkdir log
创建配置文件
# mongod.conf# for documentation of all options, see:
# http://docs.mongodb.org/manual/reference/configuration-options/# Where and how to store data.
storage:dbPath: /data/xxx/mongodb/mongodb-linux-x86_64-4.0.28/datajournal:enabled: true
# engine:
# mmapv1:
# wiredTiger:# where to write logging data.
systemLog:destination: filelogAppend: truepath: /data/xxx/mongodb/mongodb-linux-x86_64-4.0.28/log/mongod.log# network interfaces
net:port: 27017bindIp: 0.0.0.0#processManagement:#security:#operationProfiling:#replication:#sharding:## Enterprise-Only Options:#auditLog:#snmp:
不设置密码启动
./mongod --config "xxx/mongod.cfg"
客户端登录:
cd /xxx/mongodb-linux-x86_64-4.0.28/bin
./mongo
进入mongo客户端命令行后执行:
#设置root密码
use admin
db.createUser({user:'root',pwd:'你的root密码', roles:['root']})
重启mongod服务(使用鉴权方式启动)
./mongod --auth --config /xxx/mongodb-linux-x86_64-4.0.28/bin/mongod.cfg
客户端登录:
./mongo
use admin
db.auth('root','你设置的密码')
看到返回1即代表成功了