CentOS7 yum方式安装 MongoDB 3.4
环境、准备
Centos7 系统
配置MongoDB的yum源,添加文件/etc/yum.repos.d/mongodb-org-3.4.repo
添加如下内容:
[mongodb-org-3.4]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.4/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-3.4.asc
安装
yum install -y mongodb-org
ps -ef|grep mongod
#mongod 2221 1 0 15:38 ? 00:01:29 /usr/bin/mongod --quiet -f /etc/mongod.conf run
配置
修改/etc/mongod.conf文件配置
bindIp: 127.0.0.1,10.1.6.207
RESTInterfaceEnabled: true
replSetName: myReplica
# 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: /var/log/mongodb/mongod.log
# Where and how to store data.
storage:
dbPath: /var/lib/mongo
journal:
enabled: true
# engine:
# mmapv1:
# wiredTiger:
# how the process runs
processManagement:
fork: true # fork and run in background
pidFilePath: /var/run/mongodb/mongod.pid # location of pidfile
# network interfaces
net:
port: 27017
bindIp: 127.0.0.1,10.1.6.207 # Listen to local interface only, comment to listen on all interfaces.
http:
RESTInterfaceEnabled: true #配置后ip:28017才能访问
#security:
#operationProfiling:
replication:
replSetName: myReplica #复制集
#sharding:
## Enterprise-Only Options
#auditLog:
#snmp:
在10.1.6.207上配置复制集
rs.initiate()
rs.conf()
rs.add("10.1.6.208:27017")
rs.add("10.1.6.209:27017")
#从无法查询在从实例执行
rs.slaveOk()
参考:
https://docs.mongodb.com/master/administration/production-notes/
https://docs.mongodb.com/master/tutorial/install-mongodb-on-red-hat/
https://docs.mongodb.com/manual/reference/configuration-options/