mongodb3.2 sharding deploy
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mongodb3.2 sharding deploy相关的知识,希望对你有一定的参考价值。
一、部署软件
pc1、pc2、pc3分别安装mongodb,操作如下:
[[email protected] ~]# tail /etc/security/limits.conf
mongod soft nproc 40000
* hard nofile 1000000
* soft nofile 1000000
* soft core unlimited
* soft stack 10240
* - nofile 65535
push - nproc 65535
push - nofile 320000
work - nproc 10000
[[email protected] ~]# tail /etc/security/limits.d/90-nproc.conf
* soft nproc 1024
root soft nproc unlimited
[[email protected] ~]#
[[email protected] ~]# cat /etc/yum.repos.d/mongodb.repo
[mongodb-org-3.2]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/amazon/2013.03/mongodb-org/3.2/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-3.2.asc
[[email protected] ~]# yum -y install mongodb-org
[[email protected] ~]# chkconfig mongodb off
[[email protected] ~]# mkdir -p /data/mongodb/{config,data/{config,logs,shard{1,2,3}_1}}
[[email protected] ~]# chown -R mongod.mongod /data/mongodb
[[email protected] ~]# cp /etc/mongod.conf /data/mongodb/config/shard1.conf
[[email protected] ~]# tree /data/
/data/
└── mongodb
├── config
│ └── shard1.conf
└── data
├── config
├── logs
├── shard1_1
├── shard2_1
└── shard3_1
二、配置服务
副本集1的配置文件与启动脚本如下:
[[email protected] ~]# egrep "^[^#$]" /data/mongodb/config/shard1.conf
systemLog:
destination: file
logAppend: true
path: /data/mongodb/data/logs/shard1.log
storage:
dbPath: /data/mongodb/data/shard1_1
directoryPerDB: true
journal:
enabled: true
processManagement:
fork: true # fork and run in background
pidFilePath: /var/run/mongodb/shard1.pid # location of pidfile
net:
port: 27027
#bindIp: 127.0.0.1 # Listen to local interface only, comment to listen on all interfaces.
replication:
oplogSizeMB: 500
replSetName: shard1
sharding:
clusterRole: shardsvr
[[email protected] ~]#
[[email protected] ~]# cp /etc/init.d/mongod /etc/init.d/shard1
[[email protected] ~]# vim /etc/init.d/shard1
[[email protected] ~]# egrep "^[^#$]" /etc/init.d/shard1
. /etc/rc.d/init.d/functions
CONFIGFILE="/data/mongodb/config/shard1.conf"
OPTIONS=" -f $CONFIGFILE"
mongod=${MONGOD-/usr/bin/mongod}
MONGO_USER=mongod
MONGO_GROUP=mongod
SYSCONFIG="/etc/sysconfig/mongod"
if [ -f "$SYSCONFIG" ]; then
. "$SYSCONFIG"
fi
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
PIDFILEPATH=`awk -F‘[:=]‘ -v IGNORECASE=1 ‘/^[[:blank:]]*(processManagement\.)?pidfilepath[[:blank:]]*[:=][[:blank:]]*/{print $2}‘ "$CONFIGFILE" | tr -d "[:blank:]\"‘" | awk -F‘#‘ ‘{print $1}‘`
PIDDIR=`dirname $PIDFILEPATH`
start()
{
# Make sure the default pidfile directory exists
if [ ! -d $PIDDIR ]; then
install -d -m 0755 -o $MONGO_USER -g $MONGO_GROUP $PIDDIR
fi
if test -f /sys/kernel/mm/transparent_hugepage/defrag; then
echo never > /sys/kernel/mm/transparent_hugepage/defrag
fi
# 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 64000
echo -n $"Starting mongod: "
daemon --user "$MONGO_USER" --check $mongod "$NUMACTL $mongod $OPTIONS >/dev/null 2>&1"
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/shard1
}
stop()
{
echo -n $"Stopping mongod: "
mongo_killproc "$PIDFILEPATH" $mongod
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/shard1
}
restart () {
stop
start
}
mongo_killproc()
{
local pid_file=$1
local procname=$2
local -i delay=300
local -i duration=10
local pid=`pidofproc -p "${pid_file}" ${procname}`
kill -TERM $pid >/dev/null 2>&1
usleep 100000
local -i x=0
while [ $x -le $delay ] && checkpid $pid; do
sleep $duration
x=$(( $x + $duration))
done
kill -KILL $pid >/dev/null 2>&1
usleep 100000
checkpid $pid # returns 0 only if the process exists
local RC=$?
[ "$RC" -eq 0 ] && failure "${procname} shutdown" || rm -f "${pid_file}"; success "${procname} shutdown"
RC=$((! $RC)) # invert return code so we return 0 when process is dead.
return $RC
}
RETVAL=0
case "$1" in
start)
start
;;
stop)
stop
;;
restart|reload|force-reload)
restart
;;
condrestart)
[ -f /var/lock/subsys/shard1 ] && restart || :
;;
status)
status $mongod
RETVAL=$?
;;
*)
echo "Usage: $0 {start|stop|status|restart|reload|force-reload|condrestart}"
RETVAL=1
esac
exit $RETVAL
[[email protected] ~]#
副本集2的配置文件与启动脚本如下:
[[email protected] ~]# egrep "^[^#$]" /data/mongodb/config/shard2.conf
systemLog:
destination: file
logAppend: true
path: /data/mongodb/data/logs/shard2.log
storage:
dbPath: /data/mongodb/data/shard2_1
directoryPerDB: true
journal:
enabled: true
processManagement:
fork: true # fork and run in background
pidFilePath: /var/run/mongodb/shard2.pid # location of pidfile
net:
port: 27028
#bindIp: 127.0.0.1 # Listen to local interface only, comment to listen on all interfaces.
replication:
oplogSizeMB: 500
replSetName: shard2
sharding:
clusterRole: shardsvr
[[email protected] ~]#
[[email protected] ~]# cp /etc/init.d/mongod /etc/init.d/shard2
[[email protected] ~]# vim /etc/init.d/shard2
[[email protected] ~]# egrep "^[^#$]" /etc/init.d/shard2
. /etc/rc.d/init.d/functions
CONFIGFILE="/data/mongodb/config/shard2.conf"
OPTIONS=" -f $CONFIGFILE"
mongod=${MONGOD-/usr/bin/mongod}
MONGO_USER=mongod
MONGO_GROUP=mongod
SYSCONFIG="/etc/sysconfig/mongod"
if [ -f "$SYSCONFIG" ]; then
. "$SYSCONFIG"
fi
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
PIDFILEPATH=`awk -F‘[:=]‘ -v IGNORECASE=1 ‘/^[[:blank:]]*(processManagement\.)?pidfilepath[[:blank:]]*[:=][[:blank:]]*/{print $2}‘ "$CONFIGFILE" | tr -d "[:blank:]\"‘" | awk -F‘#‘ ‘{print $1}‘`
PIDDIR=`dirname $PIDFILEPATH`
start()
{
# Make sure the default pidfile directory exists
if [ ! -d $PIDDIR ]; then
install -d -m 0755 -o $MONGO_USER -g $MONGO_GROUP $PIDDIR
fi
if test -f /sys/kernel/mm/transparent_hugepage/defrag; then
echo never > /sys/kernel/mm/transparent_hugepage/defrag
fi
# 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 64000
echo -n $"Starting mongod: "
daemon --user "$MONGO_USER" --check $mongod "$NUMACTL $mongod $OPTIONS >/dev/null 2>&1"
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/shard2
}
stop()
{
echo -n $"Stopping mongod: "
mongo_killproc "$PIDFILEPATH" $mongod
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/shard2
}
restart () {
stop
start
}
mongo_killproc()
{
local pid_file=$1
local procname=$2
local -i delay=300
local -i duration=10
local pid=`pidofproc -p "${pid_file}" ${procname}`
kill -TERM $pid >/dev/null 2>&1
usleep 100000
local -i x=0
while [ $x -le $delay ] && checkpid $pid; do
sleep $duration
x=$(( $x + $duration))
done
kill -KILL $pid >/dev/null 2>&1
usleep 100000
checkpid $pid # returns 0 only if the process exists
local RC=$?
[ "$RC" -eq 0 ] && failure "${procname} shutdown" || rm -f "${pid_file}"; success "${procname} shutdown"
RC=$((! $RC)) # invert return code so we return 0 when process is dead.
return $RC
}
RETVAL=0
case "$1" in
start)
start
;;
stop)
stop
;;
restart|reload|force-reload)
restart
;;
condrestart)
[ -f /var/lock/subsys/shard2 ] && restart || :
;;
status)
status $mongod
RETVAL=$?
;;
*)
echo "Usage: $0 {start|stop|status|restart|reload|force-reload|condrestart}"
RETVAL=1
esac
exit $RETVAL
[[email protected] ~]#
副本集3的配置文件与启动脚本如下:
[[email protected] ~]#
[[email protected] ~]# egrep "^[^#$]" /data/mongodb/config/shard3.conf
systemLog:
destination: file
logAppend: true
path: /data/mongodb/data/logs/shard3.log
storage:
dbPath: /data/mongodb/data/shard3_1
directoryPerDB: true
journal:
enabled: true
processManagement:
fork: true # fork and run in background
pidFilePath: /var/run/mongodb/shard3.pid # location of pidfile
net:
port: 27026
#bindIp: 127.0.0.1 # Listen to local interface only, comment to listen on all interfaces.
replication:
oplogSizeMB: 500
replSetName: shard3
sharding:
clusterRole: shardsvr
[[email protected] ~]#
[[email protected] ~]# cp /etc/init.d/mongod /etc/init.d/shard3
[[email protected] ~]# vim /etc/init.d/shard3
[[email protected] ~]# egrep "^[^#$]" /etc/init.d/shard3
. /etc/rc.d/init.d/functions
CONFIGFILE="/data/mongodb/config/shard3.conf"
OPTIONS=" -f $CONFIGFILE"
mongod=${MONGOD-/usr/bin/mongod}
MONGO_USER=mongod
MONGO_GROUP=mongod
SYSCONFIG="/etc/sysconfig/mongod"
if [ -f "$SYSCONFIG" ]; then
. "$SYSCONFIG"
fi
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
PIDFILEPATH=`awk -F‘[:=]‘ -v IGNORECASE=1 ‘/^[[:blank:]]*(processManagement\.)?pidfilepath[[:blank:]]*[:=][[:blank:]]*/{print $2}‘ "$CONFIGFILE" | tr -d "[:blank:]\"‘" | awk -F‘#‘ ‘{print $1}‘`
PIDDIR=`dirname $PIDFILEPATH`
start()
{
# Make sure the default pidfile directory exists
if [ ! -d $PIDDIR ]; then
install -d -m 0755 -o $MONGO_USER -g $MONGO_GROUP $PIDDIR
fi
if test -f /sys/kernel/mm/transparent_hugepage/defrag; then
echo never > /sys/kernel/mm/transparent_hugepage/defrag
fi
# 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 64000
echo -n $"Starting mongod: "
daemon --user "$MONGO_USER" --check $mongod "$NUMACTL $mongod $OPTIONS >/dev/null 2>&1"
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/shard3
}
stop()
{
echo -n $"Stopping mongod: "
mongo_killproc "$PIDFILEPATH" $mongod
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/shard3
}
restart () {
stop
start
}
mongo_killproc()
mongodb3.2集群认证登陆