From edaf10c1df192bd544d25039a6cf1354f880483a Mon Sep 17 00:00:00 2001 From: Sergey Yakubov <sergey.yakubov@desy.de> Date: Wed, 11 Jul 2018 15:56:17 +0200 Subject: [PATCH] started mongo sharding --- deploy/nomad_jobs/asapo-mongo-sharded.nmd.in | 179 +++++++++++++++++++ deploy/nomad_jobs/init_mongo.sh | 17 ++ deploy/nomad_jobs/mongo-configsrv.yaml.tpl | 7 + deploy/nomad_jobs/mongo-mongos.yaml.tpl | 5 + deploy/nomad_jobs/mongo-shardsrv.yaml.tpl | 5 + 5 files changed, 213 insertions(+) create mode 100644 deploy/nomad_jobs/asapo-mongo-sharded.nmd.in create mode 100644 deploy/nomad_jobs/init_mongo.sh create mode 100644 deploy/nomad_jobs/mongo-configsrv.yaml.tpl create mode 100644 deploy/nomad_jobs/mongo-mongos.yaml.tpl create mode 100644 deploy/nomad_jobs/mongo-shardsrv.yaml.tpl diff --git a/deploy/nomad_jobs/asapo-mongo-sharded.nmd.in b/deploy/nomad_jobs/asapo-mongo-sharded.nmd.in new file mode 100644 index 000000000..da3cf9c62 --- /dev/null +++ b/deploy/nomad_jobs/asapo-mongo-sharded.nmd.in @@ -0,0 +1,179 @@ +job "asapo-mongo-sharded" { + datacenters = ["dc1"] + + update { + max_parallel = 1 + min_healthy_time = "10s" + healthy_deadline = "3m" + auto_revert = false + } + + group "mongo-config-srv" { + count = 1 + + restart { + attempts = 0 + interval = "3m" + delay = "15s" + mode = "fail" + } + + task "mongo-config-srv" { + driver = "docker" + + config { + network_mode = "host" + image = "mongo:4.0.0" + dns_servers = ["127.0.0.1"] + volumes = ["/${meta.shared_storage}/mongodb_config:/data/configdb"] + command = "mongod" + args = ["--config","local/mongo-configsrv.yaml"] + + } + + resources { + network { + port "config" { + static = 27010 + } + } + } + + service { + port = "config" + name = "mongo-config-srv" + check { + type = "script" + name = "alive" + command = "mongo" + args = ["--port","27010","--eval","db.version()"] + interval = "10s" + timeout = "5s" + } + check_restart { + limit = 0 + grace = "90s" + ignore_warnings = false + } + } + + template { + source = "@NOMAD_INSTALL@/mongo-configsrv.yaml.tpl" + destination = "local/mongo-configsrv.yaml" + change_mode = "restart" + } + + + } + } # config server group + group "mongo-shard1" { + count = 1 + + restart { + attempts = 0 + interval = "3m" + delay = "15s" + mode = "fail" + } + + task "mongo-shard1" { + driver = "docker" + + config { + network_mode = "host" + image = "mongo:4.0.0" + dns_servers = ["127.0.0.1"] + volumes = ["/${meta.shared_storage}/mongodb_shard1:/data/db"] + command = "mongod" + args = ["--config","local/mongo-shardsrv.yaml"] + + } + + resources { + network { + port "shard" { + static = 27011 + } + } + } + + service { + port = "shard" + name = "mongo-shard1" + check { + type = "script" + name = "alive" + command = "mongo" + args = ["--port","27011","--eval","db.version()"] + interval = "10s" + timeout = "5s" + } + check_restart { + limit = 0 + grace = "90s" + ignore_warnings = false + } + } + template { + source = "@NOMAD_INSTALL@/mongo-shardsrv.yaml.tpl" + destination = "local/mongo-shardsrv.yaml" + change_mode = "restart" + } + } + } # shard1 group + group "mongos" { + count = 1 + + restart { + attempts = 0 + interval = "3m" + delay = "15s" + mode = "fail" + } + + task "mongos" { + driver = "docker" + + config { + network_mode = "host" + image = "mongo:4.0.0" + dns_servers = ["127.0.0.1"] + command = "mongos" + args = ["--config","local/mongo-mongos.yaml"] + + } + + resources { + network { + port "mongos" { + static = 27017 + } + } + } + + service { + port = "mongos" + name = "mongos" + check { + type = "script" + name = "alive" + command = "mongo" + args = ["--eval","db.version()"] + interval = "10s" + timeout = "5s" + } + check_restart { + limit = 0 + grace = "90s" + ignore_warnings = false + } + } + template { + source = "@NOMAD_INSTALL@/mongo-mongos.yaml.tpl" + destination = "local/mongo-mongos.yaml" + change_mode = "restart" + } + } + } # mongos group + +} diff --git a/deploy/nomad_jobs/init_mongo.sh b/deploy/nomad_jobs/init_mongo.sh new file mode 100644 index 000000000..87188b0a1 --- /dev/null +++ b/deploy/nomad_jobs/init_mongo.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash + +mongoaddr=`dig +short @127.0.0.1 mongo-config-srv.service.asapo | head -1` +cont=$(ssh $mongoaddr bash -c "'docker ps | grep mongo-config-srv'") +image=`echo "${cont##* }"` +ssh $mongoaddr docker exec $image bash -c "'echo \"rs.initiate()\" | mongo --port 27010'" + + +mongoaddr=`dig +short @127.0.0.1 mongos.service.asapo | head -1` +cont=$(ssh $mongoaddr bash -c "'docker ps | grep mongos'") +image=`echo "${cont##* }"` + +shardaddr=`dig +short @127.0.0.1 mongo-shard1.service.asapo | head -1` + + +ssh $mongoaddr docker exec $image bash -c "'echo \"sh.addShard('\"'$shardaddr:27011'\"')\" | mongo'" + diff --git a/deploy/nomad_jobs/mongo-configsrv.yaml.tpl b/deploy/nomad_jobs/mongo-configsrv.yaml.tpl new file mode 100644 index 000000000..4f7caf9c1 --- /dev/null +++ b/deploy/nomad_jobs/mongo-configsrv.yaml.tpl @@ -0,0 +1,7 @@ +sharding: + clusterRole: configsvr +replication: + replSetName: config +net: + bindIp: {{ env "attr.unique.network.ip-address" }} + port: {{ env "NOMAD_PORT_config" }} diff --git a/deploy/nomad_jobs/mongo-mongos.yaml.tpl b/deploy/nomad_jobs/mongo-mongos.yaml.tpl new file mode 100644 index 000000000..a950ec0c2 --- /dev/null +++ b/deploy/nomad_jobs/mongo-mongos.yaml.tpl @@ -0,0 +1,5 @@ +sharding: + configDB: "config/mongo-config-srv.service.asapo:27010" +net: + bindIp: {{ env "attr.unique.network.ip-address" }} + port: {{ env "NOMAD_PORT_mongos" }} diff --git a/deploy/nomad_jobs/mongo-shardsrv.yaml.tpl b/deploy/nomad_jobs/mongo-shardsrv.yaml.tpl new file mode 100644 index 000000000..fb54ad434 --- /dev/null +++ b/deploy/nomad_jobs/mongo-shardsrv.yaml.tpl @@ -0,0 +1,5 @@ +sharding: + clusterRole: shardsvr +net: + bindIp: {{ env "attr.unique.network.ip-address" }} + port: {{ env "NOMAD_PORT_shard" }} -- GitLab