logpath=/var/log/mongodb/mongod.log logappend=true fork=true dbpath=/opt/mongocfg pidfilepath=/var/run/mongodb/mongod.pid bind_ip=<lo ip>,<eth ip> configsvr=false
# service mongod start
# rpm -qa | grep mongos
mongodb-org-mongos-2.6.2-1.x86_64
configdb=mongos01:27019,mongos02:27019,mongos03:27019 # Mongo config servers addresses port = 27017 logpath = /var/log/mongodb/mongos.log logappend = true fork = true bind_ip=<lo ip>,<eth ip> verbose = false
cat > /etc/init.d/mongos << TheEnd #!/bin/bash # mongos - Startup script for mongos # chkconfig: 35 85 15 # description: Mongo Router Process for sharding # processname: mongos # config: /etc/mongos.conf # pidfile: /var/run/mongos.pid . /etc/rc.d/init.d/functions # mongos will read mongos.conf for configuration settings # Add variable to support multiple instances of mongos # The instance name is by default the name of this init script # In this way another instance can be created by just copying this init script # and creating a config file with the same name and a .conf extension # For Example: # /etc/init.d/mongos2 # /etc/mongos2.conf # Optionally also create a sysconfig file to override env variables below # /etc/sysconfig/mongos2 INSTANCE=`basename $0` # By default OPTIONS just points to the /etc/mongod.conf config file # This can be overriden in /etc/sysconfig/mongod OPTIONS=" -f /etc/${INSTANCE}.conf" PID_PATH=/var/run/mongo PID_FILE=${PID_PATH}/${INSTANCE}.pid MONGO_BIN=/usr/bin/mongos MONGO_USER=mongod MONGO_GROUP=mongod MONGO_ULIMIT=12000 MONGO_LOCK_FILE=/var/lock/subsys/${INSTANCE} # Source sysconfig options so that above values can be overriden SYSCONFIG="/etc/sysconfig/${INSTANCE}" if [ -f "$SYSCONFIG" ]; then . "$SYSCONFIG" || true fi # Create mongo pids path if it does not exist if [ ! -d "${PID_PATH}" ]; then mkdir -p "${PID_PATH}" chown "${MONGO_USER}:${MONGO_GROUP}" "${PID_PATH}" fi start() { echo -n $"Starting ${INSTANCE}: " daemon --user "$MONGO_USER" --pidfile $PID_FILE $MONGO_BIN $OPTIONS --pidfilepath=$PID_FILE RETVAL=$? echo [ $RETVAL -eq 0 ] && touch $MONGO_LOCK_FILE return $RETVAL } stop() { echo -n $"Stopping ${INSTANCE}: " killproc -p $PID_FILE -t30 -TERM $MONGO_BIN RETVAL=$? echo [ $RETVAL -eq 0 ] && rm -f $MONGO_LOCK_FILE [ $RETVAL -eq 0 ] && rm -f $PID_FILE return $RETVAL } restart () { stop start } ulimit -n $MONGO_ULIMIT RETVAL=0 case "$1" in start) start ;; stop) stop ;; restart|reload|force-reload) restart ;; condrestart) [ -f $MONGO_LOCK_FILE ] && restart || : ;; status) status -p $PID_FILE $MONGO_BIN RETVAL=$? ;; *) echo "Usage: $0 {start|stop|status|restart|reload|force-reload|condrestart}" RETVAL=1 esac exit $RETVAL TheEnd
chmod + x /etc/init.d/mongos
# chkconfig mongod on # chkconfig mongos on
replSet=rs01
# mongo
> rs.initiate ()
rs01: PRIMARY> rs.conf ()
{ "_id" : "rs01", "version" : 7, "members" : [ { "_id" : 0, "host" : "mongo01-rs01:27017" } ] }
rs01: PRIMARY> rs.add ("mongo02-rs01")
rs01: PRIMARY> rs.conf ()
{ "_id" : "rs01", "version" : 7, "members" : [ { "_id" : 0, "host" : "mongo01-rs01:27017" }, { "_id" : 1, "host" : "mongo02-rs01:27017", } ] }
cat > /etc/init.d/mongo-rs01-arb << TheEnd #!/bin/bash # mongod - Startup script for mongod # chkconfig: 35 85 15 # description: Mongo is a scalable, document-oriented database. # processname: mongod # config: /etc/mongod.conf # pidfile: /var/run/mongodb/mongod.pid . /etc/rc.d/init.d/functions # things from mongod.conf get there by mongod reading it # NOTE: if you change any OPTIONS here, you get what you pay for: # this script assumes all options are in the config file. CONFIGFILE="/etc/mongod-rs01-arb.conf" OPTIONS=" -f $CONFIGFILE" SYSCONFIG="/etc/sysconfig/mongod-rs01-arb" # FIXME: 1.9.x has a --shutdown flag that parses the config file and # shuts down the correct running pid, but that's unavailable in 1.8 # for now. This can go away when this script stops supporting 1.8. DBPATH=`awk -F= '/^dbpath[[:blank:]]*=[[:blank:]]*/{print $2}' "$CONFIGFILE"` PIDFILE=`awk -F= '/^pidfilepath[[:blank:]]*=[[:blank:]]*/{print $2}' "$CONFIGFILE"` mongod=${MONGOD-/usr/bin/mongod} MONGO_USER=mongod MONGO_GROUP=mongod if [ -f "$SYSCONFIG" ]; then . "$SYSCONFIG" fi # Handle NUMA access to CPUs (SERVER-3574) # This verifies the existence of numactl as well as testing that the command works NUMACTL_ARGS="--interleave=all" if which numactl >/dev/null 2>/dev/null && numactl $NUMACTL_ARGS ls / >/dev/null 2>/dev/null then NUMACTL="numactl $NUMACTL_ARGS" else NUMACTL="" fi start() { # Recommended ulimit values for mongod or mongos # See http://docs.mongodb.org/manual/reference/ulimit/#recommended-settings # ulimit -f unlimited ulimit -t unlimited ulimit -v unlimited ulimit -n 64000 ulimit -m unlimited ulimit -u 32000 echo -n $"Starting mongod: " daemon --user "$MONGO_USER" "$NUMACTL $mongod $OPTIONS >/dev/null 2>&1" RETVAL=$? echo [ $RETVAL -eq 0 ] && touch /var/lock/subsys/mongod-rs01-arb } stop() { echo -n $"Stopping mongod: " killproc -p "$PIDFILE" -d 300 /usr/bin/mongod RETVAL=$? echo [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/mongod-rs01-arb } restart () { stop start } RETVAL=0 case "$1" in start) start ;; stop) stop ;; restart|reload|force-reload) restart ;; condrestart) [ -f /var/lock/subsys/mongod ] && restart || : ;; status) status $mongod RETVAL=$? ;; *) echo "Usage: $0 {start|stop|status|restart|reload|force-reload|condrestart}" RETVAL=1 esac exit $RETVAL TheEnd
# chmod + x /etc/init.d/mongo-rs01-arb
# mkdir / opt / mongo-rs01-arb; chown mongod: mongod / opt / mongo-rs01-arb
# cp -av /etc/mongod.conf /etc/mongod-rs01-arb.conf
port=27020 dbpath=/opt/mongo-rs01-arb pidfilepath=/var/run/mongodb/mongod-rs01-arb.pid
configsvr=true
# service mongo-rs01-arb start
> rs.addArb ("mongos01: 27020")
rs01: PRIMARY> rs.conf ()
{ "_id" : "rs01", "version" : 7, "members" : [ { "_id" : 0, "host" : "mongo01-rs01:27017" }, { "_id" : 1, "host" : "mongo02-rs01:27017", }, { "_id" : 2, "host" : "mongos01:27020", "arbiterOnly" : true } ] }
> sh.addShard ("rs01 // mongo01-rs01: 27017, mongo02-rs01: 27017")
> sh.addShard ("rs02 / mongo01-rs02: 27017, mongo02-rs02: 27017")
> sh.status ()
shards: { "_id" : "rs01", "host" : "rs01/mongo01-rs01:27017,mongo02-rs01:27017" } { "_id" : "rs02", "host" : "rs02/mongo01-rs02:27017,mongo02-rs02:27017" }
> use filestore
> sh.enableSharding ("filestore")
> sh.shardCollection (“filestore.fs.chunks”, {files_id: 1, n: 1})
> sh.status ()
shards: { "_id" : "rs01", "host" : "rs01/mongo01-rs01:27017,mongo02-rs01:27017" } { "_id" : "rs02", "host" : "rs02/mongo01-rs02:27017,mongo02-rs02:27017"} databases: { "_id" : "admin", "partitioned" : false, "primary" : "config" } { "_id" : "test", "partitioned" : false, "primary" : "rs02" } { "_id" : "filestore", "partitioned" : true, "primary" : "rs01" } filestore.fs.chunks shard key: { "files_id" : 1, "n" : 1 } chunks: rs01 1363 rs02 103 too many chunks to print, use verbose if you want to force print
Source: https://habr.com/ru/post/227395/
All Articles