cse47126
3 years ago
5 changed files with 229 additions and 0 deletions
@ -0,0 +1,65 @@ |
|||||
|
#!/bin/bash |
||||
|
|
||||
|
#************************************************* |
||||
|
# Check if databases are live |
||||
|
#************************************************* |
||||
|
echo "Checking Replica 1 Databases" |
||||
|
until |
||||
|
mongo --host localhost:10001 --quiet --eval 'db' &> /dev/null && |
||||
|
mongo --host localhost:10002 --quiet --eval 'db' &> /dev/null && |
||||
|
mongo --host localhost:10003 --quiet --eval 'db' &> /dev/null |
||||
|
do |
||||
|
echo "Waiting for replica set 1 databases to come online" |
||||
|
sleep 5; |
||||
|
done |
||||
|
echo " Replica set 1 databases up and running" |
||||
|
echo "" |
||||
|
echo "Checking Replica 2 Databases" |
||||
|
until |
||||
|
mongo --host localhost:20001 --quiet --eval 'db' &> /dev/null && |
||||
|
mongo --host localhost:20002 --quiet --eval 'db' &> /dev/null && |
||||
|
mongo --host localhost:20003 --quiet --eval 'db' &> /dev/null |
||||
|
do |
||||
|
echo "Waiting for replica set 2 databases to come online" |
||||
|
sleep 5; |
||||
|
done |
||||
|
echo " Replica set 2 databases up and running" |
||||
|
echo "" |
||||
|
echo "Checking Replica 3 Databases" |
||||
|
until |
||||
|
mongo --host localhost:30001 --quiet --eval 'db' &> /dev/null && |
||||
|
mongo --host localhost:30002 --quiet --eval 'db' &> /dev/null && |
||||
|
mongo --host localhost:30003 --quiet --eval 'db' &> /dev/null |
||||
|
do |
||||
|
echo "Waiting for replica set 3 databases to come online" |
||||
|
sleep 5; |
||||
|
done |
||||
|
echo " Replica set 3 databases up and running" |
||||
|
echo "" |
||||
|
sleep 2; |
||||
|
#************************************************* |
||||
|
# Connecting Secondary to Primary |
||||
|
#************************************************* |
||||
|
echo "All databases are up ....." |
||||
|
echo "" |
||||
|
echo "" |
||||
|
echo "Connecting secondary replicas to primary..." |
||||
|
mongo localhost:10001 --quiet < rep_set1_members.js &> /dev/null |
||||
|
mongo localhost:10002 --quiet < secondaryok.js &> /dev/null |
||||
|
mongo localhost:10003 --quiet < secondaryok.js &> /dev/null |
||||
|
sleep 2; |
||||
|
echo "" |
||||
|
echo "Replica set 1 OK" |
||||
|
mongo localhost:20001 --quiet < rep_set2_members.js &> /dev/null |
||||
|
mongo localhost:20002 --quiet < secondaryok.js &> /dev/null |
||||
|
mongo localhost:20003 --quiet < secondaryok.js &> /dev/null |
||||
|
sleep 2; |
||||
|
echo "" |
||||
|
echo "Replica set 2 OK" |
||||
|
mongo localhost:30001 --quiet < rep_set3_members.js &> /dev/null |
||||
|
mongo localhost:30002 --quiet < secondaryok.js &> /dev/null |
||||
|
mongo localhost:30003 --quiet < secondaryok.js &> /dev/null |
||||
|
sleep 2; |
||||
|
echo "" |
||||
|
echo "Replica set 3 OK" |
||||
|
|
@ -0,0 +1,107 @@ |
|||||
|
version: "3.4" |
||||
|
|
||||
|
networks: |
||||
|
#******************************************# |
||||
|
replica_set1_network: |
||||
|
driver: bridge |
||||
|
ipam: |
||||
|
config: |
||||
|
- subnet: 168.20.1.0/24 |
||||
|
#******************************************# |
||||
|
replica_set2_network: |
||||
|
driver: bridge |
||||
|
ipam: |
||||
|
config: |
||||
|
- subnet: 168.20.2.0/24 |
||||
|
#******************************************# |
||||
|
replica_set3_network: |
||||
|
driver: bridge |
||||
|
ipam: |
||||
|
config: |
||||
|
- subnet: 168.20.3.0/24 |
||||
|
#******************************************# |
||||
|
|
||||
|
services: |
||||
|
primary1: |
||||
|
hostname: primary1 |
||||
|
image: mongo:latest |
||||
|
ports: |
||||
|
- "10001:27017" |
||||
|
command: ["mongod", "--replSet", "rep-set1"] |
||||
|
networks: |
||||
|
replica_set1_network: |
||||
|
#************** |
||||
|
secondary1_1: |
||||
|
hostname: secondary1_1 |
||||
|
image: mongo:latest |
||||
|
ports: |
||||
|
- "10002:27017" |
||||
|
command: ["mongod", "--replSet", "rep-set1"] |
||||
|
networks: |
||||
|
replica_set1_network: |
||||
|
#************** |
||||
|
secondary1_2: |
||||
|
hostname: secondary1_2 |
||||
|
image: mongo:latest |
||||
|
ports: |
||||
|
- "10003:27017" |
||||
|
command: ["mongod", "--replSet", "rep-set1"] |
||||
|
networks: |
||||
|
replica_set1_network: |
||||
|
#************************************************************* |
||||
|
primary2: |
||||
|
hostname: primary2 |
||||
|
image: mongo:latest |
||||
|
ports: |
||||
|
- "20001:27017" |
||||
|
command: ["mongod", "--replSet", "rep-set2"] |
||||
|
networks: |
||||
|
replica_set2_network: |
||||
|
#************** |
||||
|
secondary2_1: |
||||
|
hostname: secondary2_1 |
||||
|
image: mongo:latest |
||||
|
ports: |
||||
|
- "20002:27017" |
||||
|
command: ["mongod", "--replSet", "rep-set2"] |
||||
|
networks: |
||||
|
replica_set2_network: |
||||
|
#************** |
||||
|
secondary2_2: |
||||
|
hostname: secondary2_2 |
||||
|
image: mongo:latest |
||||
|
ports: |
||||
|
- "20003:27017" |
||||
|
command: ["mongod", "--replSet", "rep-set2"] |
||||
|
networks: |
||||
|
replica_set2_network: |
||||
|
#************************************************************* |
||||
|
primary3: |
||||
|
hostname: primary3 |
||||
|
image: mongo:latest |
||||
|
ports: |
||||
|
- "30001:27017" |
||||
|
command: ["mongod", "--replSet", "rep-set3"] |
||||
|
networks: |
||||
|
replica_set3_network: |
||||
|
#************** |
||||
|
secondary3_1: |
||||
|
hostname: secondary3_1 |
||||
|
image: mongo:latest |
||||
|
ports: |
||||
|
- "30002:27017" |
||||
|
command: ["mongod", "--replSet", "rep-set3"] |
||||
|
networks: |
||||
|
replica_set3_network: |
||||
|
#************** |
||||
|
secondary3_2: |
||||
|
hostname: secondary3_2 |
||||
|
image: mongo:latest |
||||
|
ports: |
||||
|
- "30003:27017" |
||||
|
command: ["mongod", "--replSet", "rep-set3"] |
||||
|
networks: |
||||
|
replica_set3_network: |
||||
|
#************************************************************* |
||||
|
|
||||
|
|
@ -0,0 +1,19 @@ |
|||||
|
rs.initiate( |
||||
|
{ |
||||
|
"_id":"rep-set1", |
||||
|
"members":[ |
||||
|
{ |
||||
|
"_id":0, |
||||
|
"host":"primary1:27017" |
||||
|
}, |
||||
|
{ |
||||
|
"_id":1, |
||||
|
"host":"secondary1_1:27017" |
||||
|
}, |
||||
|
{ |
||||
|
"_id":2, |
||||
|
"host":"secondary1_2:27017" |
||||
|
} |
||||
|
] |
||||
|
} |
||||
|
); |
@ -0,0 +1,19 @@ |
|||||
|
rs.initiate( |
||||
|
{ |
||||
|
"_id":"rep-set2", |
||||
|
"members":[ |
||||
|
{ |
||||
|
"_id":0, |
||||
|
"host":"primary2:27017" |
||||
|
}, |
||||
|
{ |
||||
|
"_id":1, |
||||
|
"host":"secondary2_1:27017" |
||||
|
}, |
||||
|
{ |
||||
|
"_id":2, |
||||
|
"host":"secondary2_2:27017" |
||||
|
} |
||||
|
] |
||||
|
} |
||||
|
); |
@ -0,0 +1,19 @@ |
|||||
|
rs.initiate( |
||||
|
{ |
||||
|
"_id":"rep-set3", |
||||
|
"members":[ |
||||
|
{ |
||||
|
"_id":0, |
||||
|
"host":"primary3:27017" |
||||
|
}, |
||||
|
{ |
||||
|
"_id":1, |
||||
|
"host":"secondary3_1:27017" |
||||
|
}, |
||||
|
{ |
||||
|
"_id":2, |
||||
|
"host":"secondary3_2:27017" |
||||
|
} |
||||
|
] |
||||
|
} |
||||
|
); |
Loading…
Reference in new issue