CentOS7/RHEL7-使用yum快速安装mongodb3.6

前言

CentOS上安装epel-release的yum源之后就可以安装MongoDB,但是版本都是比较老的,如果使用MongoDB官方的yum就可以安装到比较新版本的MongoDB。


配置yum源

cat > /etc/yum.repos.d/MongoDB.repo <<EOF

[mongodb-org-3.6]

name=MongoDB Repository

baseurl=https://repo.mongodb.org/yum/redhat/\$releasever/mongodb-org/3.6/x86_64/

gpgcheck=1

enabled=1

gpgkey=https://www.mongodb.org/static/pgp/server-3.6.asc

EOF


安装

yum -y install mongodb-org


创建数据目录

一般分配到独立的大分区

mkdir -p /data/mongodb/data /data/mongodb/logs

chown mongod.mongod /data/mongodb/data /data/mongodb/logs -R #默认是使用mongod执行的,所以需要修改一下目录权限


修改配置文件

/etc/mongod.conf

# mongod.conf

# for documentation of all options, see:

# http://docs.mongodb.org/manual/reference/configuration-options/

# where to write logging data.

systemLog:

destination: file

logAppend: true

path: /data/mongodb/logs/mongod.log #修改到我们专门创建的目录

# Where and how to store data.

storage:

dbPath: /data/mongodb/data #修改到我们专门创建的目录

journal:

enabled: true

# engine:

# mmapv1:

# wiredTiger:

# how the process runs

processManagement:

fork: true # fork and run in background

pidFilePath: /data/mongodb/logs/mongod.pid # location of pidfile

timeZoneInfo: /usr/share/zoneinfo

# network interfaces

net:

port: 27017

#bindIp: 127.0.0.1 # Listen to local interface only, comment to listen on all interfaces.

bindIp: 0.0.0.0 # Listen to local interface only, comment to listen on all interfaces. #修改监听所有的端口

#security:

# authorization: enabled #这里是开启验证功能,暂时先关闭,等创建完root用户再开起来进行验证

#operationProfiling:

#replication:

#sharding:

## Enterprise-Only Options

#auditLog:

#snmp:


连接MongoDB数据库

直接使用mongo命令进行连接,默认端口是27017

#创建root用户

db.createUser({user:"root",pwd:"rootpassword",roles:[{role:"root",db:"admin"}]})


启用用户验证

修改配置文件

security:

authorization: enabled

添加上验证,重启mongd服务

登录验证

mongo -u root -p rootpassword --authenticationDatabase admin

总结

这样子就可以撸起MongoDB了,是不是很简单?

举报
评论 0