https://www.mongodb.com/download-center#community
cd /root/soft
curl -O https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.2.10.tgz
安装向导
https://docs.mongodb.com/manual/tutorial/install-mongodb-on-linux/
安装
cd /root/soft
tar -zxvf mongodb-linux-x86_64-3.2.10.tgz
mkdir -p /usr/local/mongodb
cp -R -n mongodb-linux-x86_64-3.2.10/ /usr/local/mongodb
echo "export PATH=/usr/local/mongodb/bin:$PATH">>/etc/profile
source /etc/profile
vi /etc/mongod.conf
systemLog:
destination: file
path: "/mongodb/rs2/logs/mongod.log"
logAppend: true
logRotate: "rename"
storage:
dbPath: "/mongodb/rs2/data/"
journal:
enabled: true
directoryPerDB: true
syncPeriodSecs: 60
engine: wiredTiger # MongoDB 3.0版本开始务必使用WT引擎
wiredTiger:
engineConfig:
cacheSizeGB: 16
statisticsLogDelaySecs: 0
journalCompressor: snappy
directoryForIndexes: true
collectionConfig:
blockCompressor: snappy
indexConfig:
prefixCompression: true
operationProfiling:
slowOpThresholdMs: 200
mode: slowOp
#security:
# keyFile: /mongodb/rs2/keyfile
# authorization: enabled
processManagement:
fork: true
pidFilePath: /mongodb/rs2/data/mongodb.pid
net:
# IP地址
#bindIp: 192.168.110.136
port: 28017
# 配置replication set
replication:
oplogSizeMB: 1024
replSetName: rs2
sed 's/rs1/rs2/g' /etc/mongod.conf -i
mkdir -p /mongodb/rs2/data
mkdir -p /mongodb/rs2/logs
启动实例
mongod -f /etc/mongod.conf
mongo --port 28017
use admin
---注意防火墙的影响
config={_id:'rs2',members:[{_id:0,host:'192.168.110.129:28017'},{_id:1,host:'192.168.110.134:28017'},{_id:2,host:'192.168.110.137:28017'}]}
rs.initiate(config)
备注:
ERROR: child process failed, exited with error number 1
keyfile文件缺失或生成方式以及文件权限可能有问题
==================================openssl rand -base64 755 > keyfile
chmod 400 keyfile