Skip to content
Snippets Groups Projects
Commit edaf10c1 authored by Sergey Yakubov's avatar Sergey Yakubov
Browse files

started mongo sharding

parent 8a8cb76b
No related branches found
No related tags found
2 merge requests!26Feature ha,!93Release 20.03.01
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
}
#!/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'"
sharding:
clusterRole: configsvr
replication:
replSetName: config
net:
bindIp: {{ env "attr.unique.network.ip-address" }}
port: {{ env "NOMAD_PORT_config" }}
sharding:
configDB: "config/mongo-config-srv.service.asapo:27010"
net:
bindIp: {{ env "attr.unique.network.ip-address" }}
port: {{ env "NOMAD_PORT_mongos" }}
sharding:
clusterRole: shardsvr
net:
bindIp: {{ env "attr.unique.network.ip-address" }}
port: {{ env "NOMAD_PORT_shard" }}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment