Skip to content

Instantly share code, notes, and snippets.

@afonsoaugusto
Created June 4, 2018 20:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save afonsoaugusto/719653927ed58e90872b78c9e6d8b6b2 to your computer and use it in GitHub Desktop.
Save afonsoaugusto/719653927ed58e90872b78c9e6d8b6b2 to your computer and use it in GitHub Desktop.
/*
Setting Up a Sharded Cluster
Lab - Configure a Sharded Cluster
*/
create keyfile
# openssl rand -base64 741 > /var/mongodb/pki/m103-keyfile
rm -rf /var/mongodb/db/{node1,node2,node3}
rm -rf /var/mongodb/db/{csrs1,csrs2,csrs3}
mkdir -p /var/mongodb/db/{csrs1,csrs2,csrs3}
mkdir -p /var/mongodb/db/{node1,node2,node3}
echo "
storage:
dbPath: /var/mongodb/db/node1
net:
bindIp: 192.168.103.100,127.0.1.1,localhost
port: 27001
security:
authorization: enabled
keyFile: /var/mongodb/pki/m103-keyfile
systemLog:
destination: file
path: /var/mongodb/db/mongod1.log
logAppend: true
processManagement:
fork: true
replication:
replSetName: m103-repl
" > mongod-repl-1.conf
echo "
storage:
dbPath: /var/mongodb/db/node2
net:
bindIp: 192.168.103.100,127.0.1.1,localhost
port: 27002
security:
authorization: enabled
keyFile: /var/mongodb/pki/m103-keyfile
systemLog:
destination: file
path: /var/mongodb/db/mongod2.log
logAppend: true
processManagement:
fork: true
replication:
replSetName: m103-repl
" > mongod-repl-2.conf
echo "
storage:
dbPath: /var/mongodb/db/node3
net:
bindIp: 192.168.103.100,127.0.1.1,localhost
port: 27003
security:
authorization: enabled
keyFile: /var/mongodb/pki/m103-keyfile
systemLog:
destination: file
path: /var/mongodb/db/mongod3.log
logAppend: true
processManagement:
fork: true
replication:
replSetName: m103-repl
" > mongod-repl-3.conf
mongod -f mongod-repl-1.conf
mongod -f mongod-repl-2.conf
mongod -f mongod-repl-3.conf
mongo --port 27001
rs.initiate()
use admin
db.createUser({
user: "m103-admin",
pwd: "m103-pass",
roles: [
{role: "root", db: "admin"}
]
})
exit
mongo --host "m103-repl/m103.mongodb.university:27001" -u "m103-admin" -p "m103-pass" --authenticationDatabase "admin"
rs.status()
rs.add("m103.mongodb.university:27002")
rs.add("m103.mongodb.university:27003")
vagrant@m103:~/capter3/sharding$ validate_lab_initialize_local_replica_set
5a4d32f979235b109001c7bc
###
### Sharding part
###
echo "
sharding:
clusterRole: configsvr
replication:
replSetName: m103-csrs
security:
keyFile: /var/mongodb/pki/m103-keyfile
net:
bindIp: 192.168.103.100,127.0.1.1,localhost
port: 26001
systemLog:
destination: file
path: /var/mongodb/db/csrs1/mongod.log
logAppend: true
processManagement:
fork: true
storage:
dbPath: /var/mongodb/db/csrs1
" > csrs_1.conf
echo "
sharding:
clusterRole: configsvr
replication:
replSetName: m103-csrs
security:
keyFile: /var/mongodb/pki/m103-keyfile
net:
bindIp: 192.168.103.100,127.0.1.1,localhost
port: 26002
systemLog:
destination: file
path: /var/mongodb/db/csrs2/mongod.log
logAppend: true
processManagement:
fork: true
storage:
dbPath: /var/mongodb/db/csrs2
" > csrs_2.conf
echo "
sharding:
clusterRole: configsvr
replication:
replSetName: m103-csrs
security:
keyFile: /var/mongodb/pki/m103-keyfile
net:
bindIp: 192.168.103.100,127.0.1.1,localhost
port: 26003
systemLog:
destination: file
path: /var/mongodb/db/csrs3/mongod.log
logAppend: true
processManagement:
fork: true
storage:
dbPath: /var/mongodb/db/csrs3
" > csrs_3.conf
mongod -f csrs_1.conf
mongod -f csrs_2.conf
mongod -f csrs_3.conf
mongo --port 26001
rs.initiate()
use admin
db.createUser({
user: "m103-admin",
pwd: "m103-pass",
roles: [
{role: "root", db: "admin"}
]
})
db.auth("m103-admin", "m103-pass")
rs.add("192.168.103.100:26002")
rs.add("192.168.103.100:26003")
echo "
sharding:
configDB: m103-csrs/192.168.103.100:26001,192.168.103.100:26002,192.168.103.100:26003
security:
keyFile: /var/mongodb/pki/m103-keyfile
net:
bindIp: 192.168.103.100,127.0.1.1,localhost
port: 26000
systemLog:
destination: file
path: /var/mongodb/db/mongos.log
logAppend: true
processManagement:
fork: true
" > mongos.conf
mongos -f mongos.conf
mongo --host "192.168.103.100:26000" -u "m103-admin" -p "m103-pass" --authenticationDatabase "admin"
sh.status()
echo "
sharding:
clusterRole: shardsvr
storage:
dbPath: /var/mongodb/db/node1
wiredTiger:
engineConfig:
cacheSizeGB: .1
net:
bindIp: 192.168.103.100,127.0.1.1,localhost
port: 27001
security:
keyFile: /var/mongodb/pki/m103-keyfile
systemLog:
destination: file
path: /var/mongodb/db/node1/mongod.log
logAppend: true
processManagement:
fork: true
replication:
replSetName: m103-repl
" > mongod-repl-1-up.conf
echo "
sharding:
clusterRole: shardsvr
storage:
dbPath: /var/mongodb/db/node2
wiredTiger:
engineConfig:
cacheSizeGB: .1
net:
bindIp: 192.168.103.100,127.0.1.1,localhost
port: 27002
security:
keyFile: /var/mongodb/pki/m103-keyfile
systemLog:
destination: file
path: /var/mongodb/db/node2/mongod.log
logAppend: true
processManagement:
fork: true
replication:
replSetName: m103-repl
" > mongod-repl-2-up.conf
echo "
sharding:
clusterRole: shardsvr
storage:
dbPath: /var/mongodb/db/node3
wiredTiger:
engineConfig:
cacheSizeGB: .1
net:
bindIp: 192.168.103.100,127.0.1.1,localhost
port: 27003
security:
keyFile: /var/mongodb/pki/m103-keyfile
systemLog:
destination: file
path: /var/mongodb/db/node3/mongod.log
logAppend: true
processManagement:
fork: true
replication:
replSetName: m103-repl
" > mongod-repl-3-up.conf
mongo --port 27002 -u "m103-admin" -p "m103-pass" --authenticationDatabase "admin"
use admin
db.shutdownServer()
mongod -f mongod-repl-2-up.conf
mongo --port 27003 -u "m103-admin" -p "m103-pass" --authenticationDatabase "admin"
use admin
db.shutdownServer()
mongod -f mongod-repl-3-up.conf
mongo --port 27001 -u "m103-admin" -p "m103-pass" --authenticationDatabase "admin"
rs.stepDown()
use admin
db.shutdownServer()
mongod -f mongod-repl-1-up.conf
mongo --host "192.168.103.100:26000" -u "m103-admin" -p "m103-pass" --authenticationDatabase "admin"
sh.addShard("m103-repl/192.168.103.100:27001")
sh.status()
vagrant@m103:~/capter3/sharding$ validate_lab_first_sharded_cluster
5a57de1cb1575291ce6e560a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment