MongoDB Sharding分片 shell 指令碼
阿新 • • 發佈:2018-12-10
#!/bin/sh CONFIG_NAME=$1 CONFIG_PORT=$2 SERIAL_NUM=$3 STORAGE_HOME=$4 if [ ! -n "$CONFIG_NAME" ] ; then CONFIG_NAME=MCCONFIG fi if [ ! -n "$CONFIG_PORT" ] ; then CONFIG_PORT=30000 fi if [ ! -n "$STORAGE_HOME" ] ; then STORAGE_HOME=. fi if [ ! -d "$STORAGE_HOME/configstart_config.sh" ] ; then mkdir $STORAGE_HOME/config mkdir $STORAGE_HOME/config/datas mkdir $STORAGE_HOME/config/logs fi DBPATH=$STORAGE_HOME/config/datas/$CONFIG_NAME-$SERIAL_NUM LOGPATH=$STORAGE_HOME/config/logs if [ ! -d "$DBPATH" ] ; then mkdir $DBPATH fi mongod --configsvr \ --replSet $CONFIG_NAME \--dbpath $DBPATH \ --logpath $LOGPATH/$CONFIG_NAME-$SERIAL_NUM.log \ --bind_ip_all \ --port $CONFIG_PORT \ --fork \ --logappend \ --journal
1 #!/bin/sh 2 3 # 分片名稱 4 SHARD_NAME=$1 5 6 # 分片埠 7 SHARD_PORT=$2start_shard.sh8 9 #分片序列號 10 SERIAL_NUM=$3 11 12 STORAGE_HOME=$4 13 14 usage() { 15 echo "sh start_shard.sh <SHARD_NAME> <SHARD_PORT> <SERIAL_NUM>" 16 echo "- SHARD_NAME : 分片名稱" 17 echo "- SHARD_PORT : 分片埠" 18 echo "- SERIAL_NUM : 分片序列號" 19 } 20 21 22 if [ ! -n "$SHARD_NAME" ] ; then 23 echo "SHARD_NAME 不能為空!" 24 usage 25 exit 0 26 fi 27 28 29 if [ ! -n "$SHARD_PORT" ] ; then 30 echo "SHARD_PORT不能為空!" 31 usage 32 exit 0 33 fi 34 35 36 if [ ! -n "$SERIAL_NUM" ] ; then 37 echo "SERIAL_NUM不能為空" 38 usage 39 exit 0 40 fi 41 42 43 if [ ! -n "$STORAGE_HOME" ] ; then 44 STORAGE_HOME=. 45 fi 46 47 if [ ! -d "$STORAGE_HOME" ] ; then 48 mkdir $STORAGE_HOME 49 fi 50 51 WORKDIR_DATA=$STORAGE_HOME/datas 52 WORKDIR_LOG=$STORAGE_HOME/logs 53 54 if [ ! -d "$WORKDIR_DATA" ] ; then 55 mkdir $WORKDIR_DATA 56 fi 57 58 if [ ! -d "$WORKDIR_DATA/$SHARD_NAME-$SERIAL_NUM" ] ; then 59 mkdir $WORKDIR_DATA/$SHARD_NAME-$SERIAL_NUM 60 fi 61 62 if [ ! -d "$WORKDIR_LOG" ] ; then 63 mkdir $WORKDIR_LOG 64 fi 65 66 #啟動指令碼 67 mongod --shardsvr \ 68 --replSet $SHARD_NAME \ 69 --bind_ip_all \ 70 --port $SHARD_PORT \ 71 --dbpath $WORKDIR_DATA/$SHARD_NAME-$SERIAL_NUM \ 72 --logpath $WORKDIR_LOG/$SHARD_NAME-$SERIAL_NUM.log \ 73 --nojournal \ 74 --oplogSize 10 \ 75 --fork
#!/bin/sh CONFIG_NAME=$1 MONGOS_PORT=$2 STORAGE_HOME=$3 if [ ! -n "$CONFIG_NAME" ] ; then CONFIG_NAME=MCCONFIG fi if [ ! -n "$MONGOS_PORT" ] ; then MONGOS_PORT=20000 fi if [ ! -n "$STORAGE_HOME" ] ; then STORAGE_HOME=. fi if [ ! -d "$STORAGE_HOME/mongos" ] ; then mkdir $STORAGE_HOME/mongos fi LOGPATH=$STORAGE_HOME/mongos/logs if [ ! -d "$LOGPATH" ] ; then mkdir $LOGPATH fi #同一臺機器,不同埠 mongos --configdb $CONFIG_NAME/127.0.0.1:30000,127.0.0.1:30001,127.0.0.1:30002 --logpath $LOGPATH/mongos.log --logappend --port $MONGOS_PORT --bind_ip_all --fork #不同機器,同一埠 #mongos --configdb $CONFIG_NAME/172.16.1.53:30000,172.16.1.54:30000,172.16.1.55:30000 --logpath $LOGPATH/mongos.log --logappend --port $MONGOS_PORT --forkstart_mongos.sh