CentOS7 yum方式安裝 MongoDB 3.4 複製集

CentOS7 yum方式安裝 MongoDB 3.4

環境、準備

Centos7 系統
配置MongoDB的yum源,添加文件/etc/yum.repos.d/mongodb-org-3.4.repo
添加以下內容:mongodb

[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: myReplicacentos

# 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上配置複製集ui

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/url

相關文章
相關標籤/搜索