安装包rpm下载地址
- mongodb-org-server
https://repo.mongodb.org/yum/redhat/7/mongodb-org/4.4/x86_64/RPMS/mongodb-org-server-4.4.14-1.el7.x86_64.rpm - mongodb-org-mongos
https://repo.mongodb.org/yum/redhat/7/mongodb-org/4.4/x86_64/RPMS/mongodb-org-mongos-4.4.14-1.el7.x86_64.rpm - mongodb-org-shell
https://repo.mongodb.org/yum/redhat/7/mongodb-org/4.4/x86_64/RPMS/mongodb-org-shell-4.4.14-1.el7.x86_64.rpm
必要条件
关闭SELinux
# 状态查看
sestatus
# 关闭
setenforce 0
安装
上传rpm包到服务器目录
yum install ./*.rpm
配置
-
配置文件目录:/etc/mongod.conf
-
配置文件
# where to write logging data.
systemLog:
destination: file
logAppend: true
path: /var/log/mongodb/mongod.log
# Where and how to store data.
storage:
dbPath: /var/lib/mongo
journal:
enabled: true
# how the process runs
processManagement:
fork: true # fork and run in background
pidFilePath: /var/run/mongodb/mongod.pid # location of pidfile
timeZoneInfo: /usr/share/zoneinfo
# network interfaces
net:
# default port 27017
port: 57017
bindIp: 0.0.0.0
启动服务
# 启动服务
systemctl start mongod
# 查看服务状态
systemctl status mongod
添加用户,开启连接验证
添加用户
# 连接
mongo --host 127.0.0.1 --port 57017
# 切换admin
use admin
# 显示用户
show users
# 添加用户,user:用户,pwd:密码,roles:角色
db.createUser({user:"vitas",pwd:"A1B2C3D4E5F6",roles:["root"]})
# 退出连接
exit
示例
添加配置
- 配置文件目录:/etc/mongod.conf
- 添加配置
security:
authorization: enabled
重启服务
systemctl restart mongod
连接验证
mongo --host 127.0.0.1 --port 57017 -u vitas -p A1B2C3D4E5F6
附录
系统环境:
Operating System
: CentOS Linux 7 (Core)
System Version
: 7.6.1810
CPE OS Name
: cpe:/o:centos:centos:7
Kernel
: Linux 3.10.0-1160.62.1.el7.x86_64
Architecture
: x86-64