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

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

linux运维菜linux

18-09-1222:47mongodb

前言数据库

 

CentOS上安装epel-release的yum源以后就能够安装MongoDB,可是版本都是比较老的,若是使用MongoDB官方的yum就能够安装到比较新版本的MongoDB。运维

 

 

配置yum源linux运维

 

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

[mongodb-org-3.6]spa

name=MongoDB Repository3d

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

gpgcheck=1blog

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执行的,因此须要修改一下目录权限

 

 

修改配置文件

 

# 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

 

建立验证用户

 

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

 

 

修改配置文件

 

security:

authorization: enabled

 

添加上验证,重启mongd服务

 

登陆验证

 

mongo -u root -p rootpassword --authenticationDatabase admin

 

 

 

总结

 

这样子就能够撸起MongoDB了,是否是很简单?

相关文章
相关标签/搜索