[iyunv@redis tmp]# tar xf mongodb-linux-x86_64-2.6.3.tgz -C /usr/local/
[iyunv@redis tmp]# mv /usr/local/{mongodb-linux-x86_64-2.6.3,mongodb}
[iyunv@redis tmp]# cd /usr/local/mongodb/
[iyunv@redis mongodb]# ls
bin GNU-AGPL-3.0 README THIRD-PARTY-NOTICES
[iyunv@redis mongodb]# mkdir -pv /mongo/data/{mongodb_data,mongodb_log}
mkdir: created directory `/mongo'
mkdir: created directory `/mongo/data'
mkdir: created directory `/mongo/data/mongodb_data'
mkdir: created directory `/mongo/data/mongodb_log'
### 启动mongodb
1
2
3
[iyunv@redis mongodb]# /usr/local/mongodb/bin/mongod --port 27017 --fork --dbpath=/mongo/data/mongodb_data/ --logpath=/mongo/data/mongodb_log/mongodb.log --logappend
about to fork child process, waiting until server is ready for connections.
forked process: 2828
### 验证存活情况:
1
2
3
[iyunv@redis mongodb]# ss -tunlp
Netid Recv-Q Send-Q Local Address:Port Peer Address:Port
tcp 0 128 *:27017 *:* users:(("mongod",2828,8))
[iyunv@redis mongodb]# /usr/local/mongodb/bin/mongod --config /etc/mongod.conf
about to fork child process, waiting until server is ready for connections.
forked process: 2855
child process started successfully, parent exiting
[iyunv@redis mongodb]# ss -tunlp
Netid Recv-Q Send-Q Local Address:Port Peer Address:Port
tcp 0 128 *:27017 *:* users:(("mongod",2855,8))
#!/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: /usr/local/mongodb/mongo.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= '/^dbpath[[:blank:]]*=[[:blank:]]*/{print $2}' "$CONFIGFILE"`
PIDFILE=`awk -F= '/^pidfilepath[[:blank:]]*=[[:blank:]]*/{print $2}' "$CONFIGFILE"`
mongod=${MONGOD-/usr/local/mongodb/bin/mongod}
MONGO_USER=mongodb
MONGO_GROUP=mongodb
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/r ... ecommended-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
}
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
### 重新启动mongodb
## mongodbrpm包安装
### 添加官方的repo
1
2
3
4
5
6
vim /etc/yum.repos.d/monogdb.repo
[mongodb]
name=MongoDB Repository
baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64/
gpgcheck=0
enabled=1
[iyunv@mongo1 ~]# chkconfig --add mongod
[iyunv@mongo1 ~]# chkconfig mongod on
[iyunv@mongo1 ~]# service mongod start
Starting mongod: [ OK ]
[iyunv@mongo1 ~]#
### 验证存活情况
1
2
3
4
5
6
7
8
9
10
11
12
13
[iyunv@mongo1 ~]# mongo
MongoDB shell version: 2.6.3
connecting to: test
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see http://docs.mongodb.org/
Questions? Try the support group http://groups.google.com/group/mongodb-user
> show dbs;
admin (empty)
local 0.078GB
>