优化集群创建脚本

This commit is contained in:
flswld
2023-05-28 19:54:03 +08:00
parent 3100e8b147
commit 98976d7a7d
13 changed files with 1081 additions and 69 deletions

View File

@@ -1,37 +1,40 @@
#!/bin/sh
IP=$1
echo "create mongo cluster, host ip: ${IP}"
echo "init mongo cluster shard"
# shard1
mongo --host 192.168.199.233 --port 27118 <<EOF
mongo --host "${IP}" --port 27118 <<EOF
rs.initiate({_id: "shard1", members: [{_id: 0, host: "mongo_shard1:27018"}]})
EOF
# shard2
mongo --host 192.168.199.233 --port 27218 <<EOF
mongo --host "${IP}" --port 27218 <<EOF
rs.initiate({_id: "shard2", members: [{_id: 0, host: "mongo_shard2:27018"}]})
EOF
# shard3
mongo --host 192.168.199.233 --port 27318 <<EOF
mongo --host "${IP}" --port 27318 <<EOF
rs.initiate({_id: "shard3", members: [{_id: 0, host: "mongo_shard3:27018"}]})
EOF
echo "init mongo cluster config"
# config1
mongo --host 192.168.199.233 --port 27119 <<EOF
mongo --host "${IP}" --port 27119 <<EOF
rs.initiate({_id: "config", configsvr: true, members: [{_id: 0, host: "mongo_config1:27019"}, {_id: 1, host: "mongo_config2:27019"}, {_id: 2, host: "mongo_config3:27019"}]})
EOF
sleep 30
echo "init mongo cluster mongos"
# mongos1
mongo --host 192.168.199.233 --port 27117 <<EOF
mongo --host "${IP}" --port 27117 <<EOF
sh.addShard("shard1/mongo_shard1:27018")
sh.addShard("shard2/mongo_shard2:27018")
sh.addShard("shard3/mongo_shard3:27018")
EOF
sleep 5
mongo --host 192.168.199.233 --port 27117 <<EOF
echo "init hk4e database table"
mongo --host "${IP}" --port 27117 <<EOF
sh.enableSharding("dispatch_hk4e")
sh.shardCollection("dispatch_hk4e.account", {"AccountID": "hashed"})
sh.enableBalancing("dispatch_hk4e.account")