数据目录
软件版本:mongodb-linux-x86_64-rhel70-4.4.3.tgz
目录配置
目前是单机配置的三个节点
192.168.31.131 主 port=27017
192.168.31.131 从 port=28000
192.168.31.131 仲裁 port=28010
mkdir -p /data/mongodb/data
mkdir -p /data/mongodb/conf
mkdir -p /data/mongodb/log
mkdir -p /data/mongodb/arbiter
chown -R mongod.mongod /data/mongodb
chown -R mongod.mongod /data/mongodb/data
chown -R mongod.mongod /data/mongodb/conf
chown -R mongod.mongod /data/mongodb/log
chown -R mongod.mongod /data/mongodb/arbiter
配置文件
Master
vi /data/mongodb/master/conf/mongod.conf
启动脚本
/usr/local/mongodb/mongodb-linux-x86_64-rhel70-4.4.3/bin/mongod -f /data/mongodb/master/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
path: "/data/mongodb/master/conf/shard1.log"
logAppend: true
# Where and how to store data.
storage:
journal:
enabled: true
dbPath: "/data/mongodb/master/data"
directoryPerDB: true
engine: wiredTiger
wiredTiger:
engineConfig:
cacheSizeGB: 1
directoryForIndex: true
collectionConfig:
blockCompressor: zlib
indexConfig:
prefixCompression: true
# network interfaces
net:
port: 27017
bindIp: 127.0.0.1 # Enter 0.0.0.0,:: to bind to all IPv4 and IPv6 addresses or, alternatively, use the net.bindIpAll setting.
replication:
oplogSizeMB: 512
replSetName: rep1
# how the process runs
processManagement:
fork: true # fork and run in background
Slave
vi /data/mongodb/slave1/conf/mongod.conf
启动脚本
/usr/local/mongodb/mongodb-linux-x86_64-rhel70-4.4.3/bin/mongod -f /data/mongodb/slave1/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
path: "/data/mongodb/slave1/conf/shard1.log"
logAppend: true
# Where and how to store data.
storage:
journal:
enabled: true
dbPath: "/data/mongodb/slave1/data"
directoryPerDB: true
engine: wiredTiger
wiredTiger:
engineConfig:
cacheSizeGB: 1
directoryForIndex: true
collectionConfig:
blockCompressor: zlib
indexConfig:
prefixCompression: true
# network interfaces
net:
port: 28000
bindIp: 127.0.0.1 # Enter 0.0.0.0,:: to bind to all IPv4 and IPv6 addresses or, alternatively, use the net.bindIpAll setting.
replication:
oplogSizeMB: 512
replSetName: rep1
# how the process runs
processManagement:
fork: true # fork and run in background
xarbiter
vi /data/mongodb/arbiter/conf/mongod.conf
/usr/local/mongodb/mongodb-linux-x86_64-rhel70-4.4.3/bin/mongod -f /data/mongodb/arbiter/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
path: "/data/mongodb/arbiter/conf/arbiter.log"
logAppend: true
# Where and how to store data.
storage:
journal:
enabled: true
dbPath: "/data/mongodb/arbiter/arbiter"
directoryPerDB: true
engine: wiredTiger
wiredTiger:
engineConfig:
cacheSizeGB: 1
directoryForIndex: true
collectionConfig:
blockCompressor: zlib
indexConfig:
prefixCompression: true
# network interfaces
net:
port: 28010
bindIp: 127.0.0.1 # Enter 0.0.0.0,:: to bind to all IPv4 and IPv6 addresses or, alternatively, use the net.bindIpAll setting.
replication:
oplogSizeMB: 512
replSetName: rep1
# how the process runs
processManagement:
fork: true # fork and run in background
启动节点
主
从
仲裁
/usr/local/mongodb/mongodb-linux-x86_64-rhel70-4.4.3/bin/mongod -f /usr/local/mongodb/master/conf/mongod.conf
/usr/local/mongodb/mongodb-linux-x86_64-rhel70-4.4.3/bin/mongod -f /usr/local/mongodb/slave1/conf/mongod.conf
/usr/local/mongodb/mongodb-linux-x86_64-rhel70-4.4.3/bin/mongod -f /usr/local/mongodb/arbiter/conf/mongod.conf
mongodb3.4可以使用此节点检查是否主节点
rs.slaveOk()
mongodb4.3使用
rs.isMaster()
备注:更多操作使用
rs.help()