Centos7部署mongodb三节点复制集
一、安装mongodb
#使用yum安装mongodb
1、自定义yum源文件
vim /etc/yum.repos.d/mongodb.repo
[mongodb-org]
name=MongoDB Repository
baseurl=https://mirrors.aliyun.com/mongodb/yum/redhat/7/mongodb-org/4.2/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-4.2.asc
2、安装mongodb
yum install -y mongodb-org
二、复制集部署
2.1、修改配置文件
vim /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: /var/log/mongodb/mongod.log
# Where and how to store data.
storage:
dbPath: /var/lib/mongo
journal:
enabled: true
# engine:
# wiredTiger:
# how the process runs
processManagement:
fork: true # fork and run in background
pidFilePath: /var/run/mongodb/mongod.pid # location of pidfile
timeZoneInfo: /usr/share/zoneinfo
# network interfaces
net:
port: 27017
bindIp: 0.0.0.0 # Enter 0.0.0.0,:: to bind to all IPv4 and IPv6 addresses or, alternatively, use the net.bindIpAll setting.
#security:
#operationProfiling:
#replication:
replication:
oplogSizeMB: 10240
replSetName: 1data
#sharding:
## Enterprise-Only Options
#auditLog:
#snmp:
2.2、编写集群配置文件
vim /var/lib/mongo/rs.initiate.js
config ={
"_id": "1data",
"members": [
{
"_id": 0,
"host": "10.10.101.22:27017"
},
{
"_id": 1,
"host": "10.10.101.23:27017"
},
{
"_id": 2,
"host": "10.10.101.24:27017"
}
]
}
rs.initiate(config)
2.3、使用配置文件,配置集群
mongo --port 27017 < /var/lib/mongo/rs.initiate.js
2.4、进入mongo,查看集群状态
[root@mongodb-0 ~]# mongo
1data:PRIMARY> rs.status()