Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add data volume and authentication keyfile and mongodb conf #18

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Empty file added .gitignore
Empty file.
2 changes: 2 additions & 0 deletions configs/cnf-server.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
security:
keyFile: /etc/mongo/keyfile
Empty file added configs/keyfile
Empty file.
2 changes: 2 additions & 0 deletions configs/route-server.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
security:
keyFile: /etc/mongo/keyfile
2 changes: 2 additions & 0 deletions configs/shard-server.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
security:
keyFile: /etc/mongo/keyfile
Empty file added data/.keep
Empty file.
21 changes: 18 additions & 3 deletions docker-compose.1.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,39 @@ services:
image: mongo:4.0.1
ports:
- "30012:27017"
command: mongod --replSet rs1 --shardsvr --port 27017 --oplogSize 16 --noprealloc --smallfiles
volumes:
- ./configs:/etc/mongo
- ./data/mongo-1-2:/data/db
command: mongod --replSet rs1 --shardsvr --port 27017 --oplogSize 16 --noprealloc --smallfiles --config /etc/mongo/shard-server.conf
restart: always

mongo-1-3:
container_name: "mongo-1-3"
image: mongo:4.0.1
ports:
- "30013:27017"
command: mongod --replSet rs1 --shardsvr --port 27017 --oplogSize 16 --noprealloc --smallfiles
volumes:
- ./configs:/etc/mongo
- ./data/mongo-1-3:/data/db
command: mongod --replSet rs1 --shardsvr --port 27017 --oplogSize 16 --noprealloc --smallfiles --config /etc/mongo/shard-server.conf
restart: always

mongo-1-1:
container_name: "mongo-1-1"
image: mongo:4.0.1
ports:
- "30011:27017"
command: mongod --replSet rs1 --shardsvr --port 27017 --oplogSize 16 --noprealloc --smallfiles
volumes:
- ./configs:/etc/mongo
- ./data/mongo-1-1:/data/db
command: mongod --replSet rs1 --shardsvr --port 27017 --oplogSize 16 --noprealloc --smallfiles --config /etc/mongo/shard-server.conf
links:
- mongo-1-2:mongo-1-2
- mongo-1-3:mongo-1-3
restart: always
environment:
MONGO_INITDB_ROOT_USERNAME: root
MONGO_INITDB_ROOT_PASSWORD: root

mongo-rs1-setup:
container_name: "mongo-rs1-setup"
Expand All @@ -45,6 +57,9 @@ services:
- MONGO2=mongo-1-2
- MONGO3=mongo-1-3
- RS=rs1
- MONGO_INITDB_ROOT_USERNAME=root
- MONGO_INITDB_ROOT_PASSWORD=root
- MONGO_INITDB=admin
entrypoint: [ "/scripts/setup.sh" ]


18 changes: 15 additions & 3 deletions docker-compose.2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,32 @@ services:
image: mongo:4.0.1
ports:
- "30022:27017"
command: mongod --replSet rs2 --shardsvr --port 27017 --oplogSize 16 --noprealloc --smallfiles
volumes:
- ./configs:/etc/mongo
- ./data/mongo-2-2:/data/db
command: mongod --replSet rs2 --shardsvr --port 27017 --oplogSize 16 --noprealloc --smallfiles --config /etc/mongo/shard-server.conf
restart: always

mongo-2-3:
container_name: "mongo-2-3"
image: mongo:4.0.1
ports:
- "30023:27017"
command: mongod --replSet rs2 --shardsvr --port 27017 --oplogSize 16 --noprealloc --smallfiles
volumes:
- ./configs:/etc/mongo
- ./data/mongo-2-3:/data/db
command: mongod --replSet rs2 --shardsvr --port 27017 --oplogSize 16 --noprealloc --smallfiles --config /etc/mongo/shard-server.conf
restart: always

mongo-2-1:
container_name: "mongo-2-1"
image: mongo:4.0.1
ports:
- "30021:27017"
command: mongod --replSet rs2 --shardsvr --port 27017 --oplogSize 16 --noprealloc --smallfiles
volumes:
- ./configs:/etc/mongo
- ./data/mongo-2-1:/data/db
command: mongod --replSet rs2 --shardsvr --port 27017 --oplogSize 16 --noprealloc --smallfiles --config /etc/mongo/shard-server.conf
links:
- mongo-2-2:mongo-2-2
- mongo-2-3:mongo-2-3
Expand All @@ -45,6 +54,9 @@ services:
- MONGO2=mongo-2-2
- MONGO3=mongo-2-3
- RS=rs2
- MONGO_INITDB_ROOT_USERNAME=root
- MONGO_INITDB_ROOT_PASSWORD=root
- MONGO_INITDB=admin
entrypoint: [ "/scripts/setup.sh" ]


22 changes: 19 additions & 3 deletions docker-compose.cnf.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,39 @@ services:
image: mongo:4.0.1
ports:
- "30102:27017"
command: mongod --replSet cnf-serv --configsvr --port 27017 --oplogSize 16 --noprealloc --smallfiles
volumes:
- ./configs:/etc/mongo
- ./data/mongo-cnf-2:/data/configdb
command: mongod --replSet cnf-serv --configsvr --port 27017 --oplogSize 16 --noprealloc --smallfiles --config /etc/mongo/cnf-server.conf
restart: always

mongo-cnf-3:
container_name: "mongo-cnf-3"
image: mongo:4.0.1
ports:
- "30103:27017"
command: mongod --replSet cnf-serv --configsvr --port 27017 --oplogSize 16 --noprealloc --smallfiles
volumes:
- ./configs:/etc/mongo
- ./data/mongo-cnf-3:/data/configdb
command: mongod --replSet cnf-serv --configsvr --port 27017 --oplogSize 16 --noprealloc --smallfiles --config /etc/mongo/cnf-server.conf
restart: always

mongo-cnf-1:
container_name: "mongo-cnf-1"
image: mongo:4.0.1
ports:
- "30101:27017"
command: mongod --replSet cnf-serv --configsvr --port 27017 --oplogSize 16 --noprealloc --smallfiles
volumes:
- ./configs:/etc/mongo
- ./data/mongo-cnf-1:/data/configdb
command: mongod --replSet cnf-serv --configsvr --port 27017 --oplogSize 16 --noprealloc --smallfiles --config /etc/mongo/cnf-server.conf
links:
- mongo-cnf-2:mongo-cnf-2
- mongo-cnf-3:mongo-cnf-3
restart: always
environment:
MONGO_INITDB_ROOT_USERNAME: root
MONGO_INITDB_ROOT_PASSWORD: root

mongo-cnf-setup:
container_name: "mongo-cnf-setup"
Expand All @@ -46,4 +58,8 @@ services:
- MONGO3=mongo-cnf-3
- RS=cnf-serv
- PORT=27017
- MONGO_INITDB_ROOT_USERNAME=root
- MONGO_INITDB_ROOT_PASSWORD=root
- MONGO_INITDB=admin

entrypoint: [ "/scripts/setup-cnf.sh" ]
8 changes: 7 additions & 1 deletion docker-compose.shard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ services:
- mongo-2-1:mongo-2-1
- mongo-2-2:mongo-2-2
- mongo-2-3:mongo-2-3
command: mongos --configdb cnf-serv/mongo-cnf-1:27017,mongo-cnf-2:27017,mongo-cnf-3:27017 --port 27017 --bind_ip 0.0.0.0
volumes:
- ./configs:/etc/mongo
command: mongos --configdb cnf-serv/mongo-cnf-1:27017,mongo-cnf-2:27017,mongo-cnf-3:27017 --port 27017 --bind_ip 0.0.0.0 --config /etc/mongo/route-server.conf
restart: always

mongo-shard-setup:
Expand All @@ -45,5 +47,9 @@ services:
- PORT1=27017
- PORT2=27017
- PORT3=27017
- MONGO_INITDB_ROOT_USERNAME=root
- MONGO_INITDB_ROOT_PASSWORD=root
- MONGO_INITDB=admin

entrypoint: [ "/scripts/init-shard.sh" ]
restart: on-failure:20
4 changes: 4 additions & 0 deletions down.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

docker-compose -f docker-compose.1.yml -f docker-compose.2.yml -f docker-compose.cnf.yml -f docker-compose.shard.yml down --volumes --remove-orphans

2 changes: 1 addition & 1 deletion scripts/init-shard.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ done
echo "Started.."

echo init-shard.sh time now: `date +"%T" `
mongo --host ${mongodb1}:${port} <<EOF
mongo --host ${mongodb1}:${port} -u ${MONGO_INITDB_ROOT_USERNAME} -p ${MONGO_INITDB_ROOT_PASSWORD} --authenticationDatabase ${MONGO_INITDB} <<EOF
sh.addShard( "${RS1}/${mongodb11}:${PORT1},${mongodb12}:${PORT2},${mongodb13}:${PORT3}" );
sh.addShard( "${RS2}/${mongodb21}:${PORT1},${mongodb22}:${PORT2},${mongodb23}:${PORT3}" );
sh.status();
Expand Down
4 changes: 2 additions & 2 deletions scripts/setup-cnf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ done
echo "Started.."

echo setup-cnf.sh time now: `date +"%T" `
mongo --host ${mongodb1}:${port} <<EOF
mongo --host ${mongodb1}:${port} -u ${MONGO_INITDB_ROOT_USERNAME} -p ${MONGO_INITDB_ROOT_PASSWORD} --authenticationDatabase ${MONGO_INITDB} <<EOF
var cfg = {
"_id": "${RS}",
"configsvr": true,
Expand All @@ -37,4 +37,4 @@ mongo --host ${mongodb1}:${port} <<EOF
};
rs.initiate(cfg, { force: true });
rs.reconfig(cfg, { force: true });
EOF
EOF
4 changes: 2 additions & 2 deletions scripts/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ done
echo "Started.."

echo setup.sh time now: `date +"%T" `
mongo --host ${mongodb1}:${port} <<EOF
mongo --host ${mongodb1}:${port} -u ${MONGO_INITDB_ROOT_USERNAME} -p ${MONGO_INITDB_ROOT_PASSWORD} --authenticationDatabase ${MONGO_INITDB} <<EOF
var cfg = {
"_id": "${RS}",
"protocolVersion": 1,
Expand All @@ -36,4 +36,4 @@ mongo --host ${mongodb1}:${port} <<EOF
};
rs.initiate(cfg, { force: true });
rs.reconfig(cfg, { force: true });
EOF
EOF
6 changes: 6 additions & 0 deletions up.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
openssl rand -base64 756 > ./configs/keyfile
chmod 400 ./configs/keyfile
chown 999:999 ./configs/keyfile
docker-compose -f docker-compose.1.yml -f docker-compose.2.yml -f docker-compose.cnf.yml -f docker-compose.shard.yml up -d