This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Run these commands on all the 3 servers of yours. | |
# download v3.6 | |
curl -O https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-3.6.5.tgz | |
BIN_NAME="mongodb-linux-x86_64-rhel70-3.6.5" | |
BIN_VERSION="v3.6.5" | |
# create data directory and untar the binaries | |
tar -xvzf "$BIN_NAME.tgz" | |
rm "$BIN_NAME.tgz" | |
mv $BIN_NAME $BIN_VERSION | |
rm -rf data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$BIN_VERSION/bin/mongo --port 27000 <<EOF | |
rs.initiate({ | |
_id: 'rs0', | |
members: [ | |
{ _id: 0, host : 'mon01:27000' }, | |
{ _id: 1, host : 'mon02:27000' }, | |
{ _id: 2, host : 'mon03:27000' } | |
] }) | |
EOF | |
# MongoDB shell version v3.6.5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rs.config() | |
/* | |
{ | |
"_id": "rs0", | |
"version": 1, | |
"protocolVersion": NumberLong(1), | |
"members": [{ | |
"_id": 0, | |
"host": "mon01:27000", | |
"arbiterOnly": false, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rs.status() | |
/* | |
{ | |
"set": "rs0", | |
"date": ISODate("2018-06-15T00:57:24.708Z"), | |
"myState": 1, | |
"term": NumberLong(1), | |
"heartbeatIntervalMillis": NumberLong(2000), | |
"optimes": { | |
"lastCommittedOpTime": { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
db.printSlaveReplicationInfo() | |
/* | |
source: mon02:27000 | |
syncedTo: Fri Jun 15 2018 01:29:11 GMT+0000 (UTC) | |
0 secs (0 hrs) behind the primary | |
source: mon03:27000 | |
syncedTo: Fri Jun 15 2018 01:29:11 GMT+0000 (UTC) | |
0 secs (0 hrs) behind the primary | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Freeze mon03 | |
rs.isMaster().me | |
// mon03:27000 | |
rs.freeze(60) | |
/* | |
{ | |
"ok" : 1, | |
"operationTime" : Timestamp(1529033711, 1), | |
"$clusterTime" : { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// # rs0:PRIMARY> | |
rs.isMaster().me | |
// mon01:27000 | |
var conf = rs.conf() | |
conf.settings.electionTimeoutMillis=2000 | |
rs.reconfig(conf) | |
/* | |
{ | |
"ok": 1, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Server mon02 | |
tail -100 data/mongod.log | grep REPL | |
# 2018-06-15T03:52:42.304+0000 I REPL [rsBackgroundSync] could not find member to sync from | |
# 2018-06-15T03:52:42.305+0000 I REPL [replexec-28] Member mon01:27000 is now in state SECONDARY | |
# 2018-06-15T03:52:43.306+0000 I REPL [SyncSourceFeedback] SyncSourceFeedback error sending update to mon01:27000: InvalidSyncSource: Sync source was cleared. Was mon01:27000 | |
# 2018-06-15T03:52:43.360+0000 I REPL [replexec-26] Starting an election, since weve seen no PRIMARY in the past 2000ms | |
# 2018-06-15T03:52:43.360+0000 I REPL [replexec-26] conducting a dry run election to see if we could be elected. current term: 4 | |
# 2018-06-15T03:52:43.360+0000 I REPL [replexec-24] VoteRequester(term 4 dry run) received a yes vote from mon01:27000; response message: { term: 4, voteGranted: true, reason: "", ok: 1.0, operationTime: Timestamp(1529034758, 1), $clusterTime: { clusterTime: Timestamp(1529034758, 1), signature: { hash: BinData(0, 0000000000000000000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rs.isMaster().me | |
// mon02:27000 | |
// rs0:PRIMARY> | |
// on the new primary | |
var conf = rs.conf() | |
conf.settings.electionTimeoutMillis=10000 | |
/* | |
rs.reconfig(conf) | |
{ | |
"ok": 1, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Download the helper scripts from GitHub repo | |
wget -O k8-mongo.zip https://github.com/sarjarapu/k8-mongo/archive/master.zip | |
unzip k8-mongo.zip | |
cd k8-mongo-master |