停止服务
/etc/init.d/mongod status
/etc/init.d/mongod stop
Stopping mongod: [Failed]
which mongod
/usr/bin/mongod --shutdown
There doesn't seem to be a server running with dbpath: /data/db
/usr/bin/mongod --shutdown --dbpath /data2/mongodb
killing process with pid: 12107
安装MongoDB3
curl -O https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.0.6.tgz # 下载
tar -zxvf mongodb-linux-x86_64-3.0.6.tgz
mongodb-linux-x86_64-3.0.6/bin/mongod --logpath /var/log/mongodb/mongods.log --dbpath /data2/mongodb
cat mongod.conf
mongod.conf
where to log
logpath=/var/log/mongodb/mongodb.log
logappend=true
fork and run in background
fork=true
port=27017
dbpath=/data2/mongodb
location of pidfile
pidfilepath=/var/run/mongodb/mongod.pid
Listen to local interface only. Comment out to listen on all interfaces.
bind_ip=172.16.7.27
Disables write-ahead journaling
nojournal=true
Enables periodic logging of cpu utilization and I/O wait
cpu=true
Turn on/off security. Off is currently the default
noauth=true
auth=true
Verbose logging output.
verbose=true
Inspect all client data for validity on receipt (useful for
developing drivers)
objcheck=true
Enable db quota management
quota=true
Set oplogging level where n is
0=off (default)
1=W
2=R
3=both
7=W+some reads
diaglog=0
Ignore query hints
nohints=true
Enable the HTTP interface (Defaults to port 28017).
httpinterface=true
Turns off server-side scripting. This will result in greatly limited
functionality
noscripting=true
Turns off table scans. Any query that would do a table scan fails.
notablescan=true
Disable data file preallocation.
noprealloc=true
Specify .ns file size for new databases.
nssize=
Replication Options
in replicated mongo databases,specify the replica set name here
replSet=setname
maximum size in megabytes for replication operation log
oplogSize=1024
path to a key file storing authentication info for connections
between replica set members
keyFile=/path/to/keyfile
cd mongodb-linux-x86_64-3.0.6
./bin/mongod --port 33334 --fork --logpath data/log/mongodb.log --dbpath data/db
启动相关参数说明如下:
--port 启动端口号
--fork 以守护进行方式启动
--logpath mongodb 日志输出路径
--dbpath mongodb 数据文件路径
其他选项可以执行命令查看: ./bin/mongod --help
mongodb-linux-x86_64-3.0.6/bin/mongod -f mongod.conf --fork
about to fork child process,waiting until server is ready for connections.
forked process: 28247
child process started successfully,parent exiting
ps aux|grep mongo
root 28247 0.8 0.6 1589168 79820 ? Sl 20:39 0:00 mongodb-linux-x86_64-3.0.6/bin/mongod -f mongod.conf --fork
命令行关闭
use admin; --使用管理员数据库
> db.shutdownServer();
启动脚本
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.conf"
OPTIONS=" -f $CONFIGFILE"
SYSCONFIG="/etc/sysconfig/mongod"
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'[:=]' -v IGNORECASE=1 '/^[[:blank:]]*dbpath[[:blank:]]*[:=][[:blank:]]*/{print $2}' "$CONFIGFILE" | tr -d '[:blank:]'
PIDFILE=awk -F'[:=]' -v IGNORECASE=1 '/^[[:blank:]]*pidfilepath[[:blank:]]*[:=][[:blank:]]*/{print $2}' "$CONFIGFILE" | tr -d '[:blank:]'
PIDDIR=dirname $PIDFILE
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()
{
Make sure the default pidfile directory exists
if [ ! -d $PIDDIR ]; then
install -d -m 0755 -o $MONGO_USER -g $MONGO_GROUP $PIDDIR
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/mongod
}
stop()
{
echo -n $"Stopping mongod: "
killproc -p "$PIDFILE" -d 300 /usr/bin/mongod
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/mongod
}
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
连接测试
资源