1.编写repo文件
# vi /etc/yum.repos.d/mongodb.repo
# 如果要安装其它的版本,将下面的文本中的版本号替换为要安装的版本号
[mongodb-org-3.2]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.2/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-3.2.asc
2.安装
# yum install mongodb-org
3.查看mongodb的状态
# systemctl status mongod.service
# 此时应该是running状态
4.进入控制台添加账号
# mongo
use admin
db.createUser(
{
user: "myUserAdmin",
pwd: "abc123",
roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]
}
)
5.修改mongodb的配置文件
# vi /etc/mongod.conf
#修改存储引擎的配置(wiredTiger mongodb默认存储引擎)
wiredTiger:
engineConfig:
cacheSizeGB: 1
# network interfaces
net:
port: xxxx #修改监听端口
bindIp: 0.0.0.0 #127.0.0.1 # Listen to local interface only, comment to #修改监听ip listen on all interfaces.
maxIncomingConnections: xxxx #修改最大链接数
#启动账号密码验证
security:
authorization: enabled
6.重新启动mongodb
# systemctl restart mongod.service