# 环境安装
* * * * *
--: 作者:Mick
时间:2018年8月20日
* * * * *
## 操作系统简介
1:操作系统:CentOS-7 64位
2:处理器:8核
3:内存:32G
4:硬盘:500G(ssd或sata)
### 创建文件夹
$ mkdir -p /data/mongodb
$ mkdir -p /var/run/mongodb
$ mkdir -p /var/log/mongodb
$ touch /var/log/mongodb/mongod.log
$ touch /etc/mongod.conf
名词解释:数据目录Data, 进程Pid, 运行日志Mongod.log, 进程日志:
### vim /etc/mongod.conf (配置文件修改)
```
systemLog:
destination: file
logAppend: true
path: /var/log/mongodb/mongod.log
# Where and how to store data.
storage:
dbPath: /data/mongodb
journal:
enabled: true
# engine:
# mmapv1:
# writedTiger:
# how the process runs
processManagement:
fork: true # Fork and run in background
pidFilePath: /var/run/mongodb/mongod.pid # location od pidfile
# network interfaces
net:
port: 27717
bindIp: 0.0.0.0
#replication:
# replSetName: magic
#operationProfilling
#replication:
# replSet: magic
#sharding
## Enterprise-Only Options
#auditLog:
#snmp
```
### 启动与登录
$ /usr/local/mongodb/bin/mongod -f /etc/mongod.conf
$ /usr/local/mongodb/bin/mongo -port 27717
### 创建管理员账号
$ use admin
$ db.createUser({user:"root",pwd:"123456",roles:[{role:"root",db:"admin"}]})
### 退出账号并关闭服务
$ quit()
$ /usr/local/mongodb/bin/mongod --shutdown -f /etc/mongod.conf
### 开启安全认证重启
```
systemLog:
destination: file
logAppend: true
path: /var/log/mongodb/mongod.log
# Where and how to store data.
storage:
dbPath: /data
journal:
enabled: true
# engine:
# mmapv1:
# writedTiger:
# how the process runs
processManagement:
fork: true # Fork and run in background
pidFilePath: /var/run/mongodb/mongod.pid # location od pidfile
# network interfaces
net:
port: 27717
bindIp: 0.0.0.0 # Listen to local interface only, comment to listen on all interfaces.
security:
#keyFile: /data/KeyFile.file
authorization: enabled
#replication:
# replSetName: magic
#operationProfilling
#replication:
# replSet: magic
#sharding
## Enterprise-Only Options
#auditLog:
#snmp
```
### 连接创建用户
use admin
db.auth("root","自己设置密码")
use 数据名字1
db.createUser({user:"账号",pwd:"自己设置密码",roles:[{role:"readWrite",db:"数据名字1"}]})
### 其他参考信息
引擎选择参考地址:https://www.cnblogs.com/wxzhe/p/9928206.html