优化集群创建脚本

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")

View File

@@ -18,7 +18,7 @@ services:
resources:
limits:
cpus: '4.00'
memory: 512M
memory: 2048M
mongo_shard2:
restart: always
@@ -38,7 +38,7 @@ services:
resources:
limits:
cpus: '4.00'
memory: 512M
memory: 2048M
mongo_shard3:
restart: always
@@ -58,7 +58,7 @@ services:
resources:
limits:
cpus: '4.00'
memory: 512M
memory: 2048M
mongo_config1:
restart: always
@@ -81,7 +81,7 @@ services:
resources:
limits:
cpus: '1.00'
memory: 256M
memory: 512M
mongo_config2:
restart: always
@@ -104,7 +104,7 @@ services:
resources:
limits:
cpus: '1.00'
memory: 256M
memory: 512M
mongo_config3:
restart: always
@@ -127,7 +127,7 @@ services:
resources:
limits:
cpus: '1.00'
memory: 256M
memory: 512M
mongo_mongos1:
restart: always
@@ -149,7 +149,7 @@ services:
resources:
limits:
cpus: '2.00'
memory: 128M
memory: 1024M
mongo_mongos2:
restart: always
@@ -171,7 +171,7 @@ services:
resources:
limits:
cpus: '2.00'
memory: 128M
memory: 1024M
mongo_mongos3:
restart: always
@@ -193,4 +193,4 @@ services:
resources:
limits:
cpus: '2.00'
memory: 128M
memory: 1024M

View File

@@ -15,5 +15,5 @@ services:
deploy:
resources:
limits:
cpus: '4.00'
cpus: '1.00'
memory: 512M

View File

@@ -0,0 +1,11 @@
#!/bin/sh
IP=$1
echo "update redis config, host ip: ${IP}"
sed -i s/192.168.199.233/"${IP}"/ ./redis1/redis.conf
sed -i s/192.168.199.233/"${IP}"/ ./redis2/redis.conf
sed -i s/192.168.199.233/"${IP}"/ ./redis3/redis.conf
sed -i s/192.168.199.233/"${IP}"/ ./redis4/redis.conf
sed -i s/192.168.199.233/"${IP}"/ ./redis5/redis.conf
sed -i s/192.168.199.233/"${IP}"/ ./redis6/redis.conf

View File

@@ -1,10 +1,13 @@
#!/bin/sh
IP=$1
echo "create redis cluster, host ip: ${IP}"
redis-cli -a 123456 --cluster create \
192.168.199.233:6371 \
192.168.199.233:6372 \
192.168.199.233:6373 \
192.168.199.233:6374 \
192.168.199.233:6375 \
192.168.199.233:6376 \
"${IP}":6371 \
"${IP}":6372 \
"${IP}":6373 \
"${IP}":6374 \
"${IP}":6375 \
"${IP}":6376 \
--cluster-replicas 1