mongodb linux 安装
下载
cd /usr/local/src
wget http://fastdl.mongodb.org/linux/mongodb-linux-i686-2.4.9.tgz
tar -xzvf mongodb-linux-i686-2.4.9.tgz
mv mongodb-linux-i686-2.4.9 ../mongodb
chmod 755 /usr/local/mongodb/bin// -R
ln -s /usr/local/mongodb/bin/mongo /usr/bin/mongo
ln -s /usr/local/mongodb/bin/mongod /usr/bin/mongod
创建目录
创建一些数据库目录日志目录。 运行pid目录
mkdir -p /var/mongodb/data/
mkdir -p /var/mongodb/logs/
chmod +w /var/mongodb/data/ -R
chmod +w /var/mongodb/logs/ -R
chown -R mongod:mongod /var/mongodb
mkdir -p /var/run/mongodb
chmod +w /var/run/mongodb -R
chown -R mongod:mongod /var/run/mongodb
添加用户
groupadd mongod
useradd -s /sbin/nologin -d /var/mongodb/ -g mongod mongod
写配置文件
vi /etc/mongod.conf
# Start MongoDB as a daemon on port 8908 port = 8908 fork = true # daemonize it ! journal = true # rest = true logappend = true auth = true dbpath = /var/mongodb/data/ logpath = /var/mongodb/logs/mongod.log pidfilepath = /var/run/mongodb/mongod.pid
添加服务启动脚本
vi /etc/init.d/mongod
#!/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/mongo/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= '/^dbpath=/{print $2}' "$CONFIGFILE"` PIDFILE=`awk -F= '/^dbpath\s=\s/{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() { echo -n $"Starting mongod: " daemon --user "$MONGO_USER" $NUMACTL $mongod $OPTIONS 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 } ulimit -n 12000 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
service mongod start //启动服务
chkconfig mongod on //设置开机启动
有疑问加站长微信联系(非本文作者)