1. 下载(二进制版本免安装)
# wget http://fastdl.mongodb.org/linux/mongodb-linux-x86_64-1.8.1.tgz
# tar zxvf mongodb-linux-x86_64-1.8.1.tgz -C /usr/local
2.配置
# useradd mongod –s /sbin/nologin
# mkdir /www/data/mongo
# mkdir /var/log/mongo
# chown mongod.mongod /www/data/mongo
# chown mongod.mongod /var/log/mongo
# mkdir /usr/local/mongodb-linux-x86_64-1.8.1/etc
# cd /usr/local/mongodb-linux-x86_64-1.8.1/etc
# vim mongod.conf
# mongo.conf
#where to log logpath=/var/log/mongo/mongod.log
logappend=true
# fork and run in background fork = true
#port = 27017
dbpath=/www/data/mongo
# 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 #oplog = 0
# Diagnostic/debugging option #nocursors = true
# Ignore query hints #nohints = true
# Disable the HTTP interface (Defaults to localhost:27018). #nohttpinterface = 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 = <size>
# Accout token for Mongo monitoring server. #mms-token = <token>
# Server name for Mongo monitoring server. #mms-name = <server-name>
# Ping interval for Mongo monitoring server. #mms-interval = <seconds>
# Replication Options
# in replicated mongo databases, specify here whether this is a slave or master #slave = true #source = master.example.com # Slave only: specify a single database to replicate #only = master.example.com # or #master = true #source = slave.example.com |
3.启动mongod
# /usr/local/mongodb-linux-x86_64-1.8.1/bin/mongod -f /usr/local/mongodb-linux-x86_64-1.8.1/etc/mongod.conf
4.自启动脚本
# vim /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
. /etc/rc.d/init.d/functions
# things from mongod.conf get there by mongod reading it
OPTIONS=" -f /usr/local/mongodb-linux-x86_64-1.8.1/etc/mongod.conf" SYSCONFIG="/etc/sysconfig/mongod"
mongod="/usr/local/mongodb-linux-x86_64-1.8.1/bin/mongod"
MONGO_USER=mongod MONGO_GROUP=mongod
. "$SYSCONFIG" || true
start() { echo -n $"Starting mongod: " daemon --user "$MONGO_USER" $mongod $OPTIONS RETVAL=$? echo [ $RETVAL -eq 0 ] && touch /var/lock/subsys/mongod }
stop() { echo -n $"Stopping mongod: " killproc -p /www/data/mongo/mongod.lock -t30 -TERM $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 |
# chmod +x /etc/init.d/mongod
# chkconfig –add mongod
# chkconfig mongod on
# service mongod restart
日志信息如下:
Sat May 7 14:40:55 got kill or ctrl c or hup signal 15 (Terminated), will terminate after current cmd ends Sat May 7 14:40:55 [interruptThread] now exiting Sat May 7 14:40:55 dbexit: Sat May 7 14:40:55 [interruptThread] shutdown: going to close listening sockets... Sat May 7 14:40:55 [interruptThread] closing listening socket: 5 Sat May 7 14:40:55 [interruptThread] closing listening socket: 6 Sat May 7 14:40:55 [interruptThread] closing listening socket: 7 Sat May 7 14:40:55 [interruptThread] closing listening socket: 8 Sat May 7 14:40:55 [interruptThread] removing socket file: /tmp/mongodb-27017.sock Sat May 7 14:40:55 [interruptThread] removing socket file: /tmp/mongodb-28017.sock Sat May 7 14:40:55 [interruptThread] shutdown: going to flush diaglog... Sat May 7 14:40:55 [interruptThread] shutdown: going to close sockets... Sat May 7 14:40:55 [interruptThread] shutdown: waiting for fs preallocator... Sat May 7 14:40:55 [interruptThread] shutdown: closing all files... Sat May 7 14:40:55 closeAllFiles() finished Sat May 7 14:40:55 [interruptThread] shutdown: removing fs lock... Sat May 7 14:40:55 dbexit: really exiting now Sat May 7 14:40:55 [initandlisten] MongoDB starting : pid=20495 port=27017 dbpath=/www/data/mongo 64-bit Sat May 7 14:40:55 [initandlisten] db version v1.8.1, pdfile version 4.5 Sat May 7 14:40:55 [initandlisten] git version: a429cd4f535b2499cc4130b06ff7c26f41c00f04 Sat May 7 14:40:55 [initandlisten] build sys info: Linux bs-linux64.10gen.cc 2.6.21.7-2.ec2.v1.2.fc8xen #1 SMP Fri Nov 20 17:48:28 EST 2009 x86_64 BOOST_LIB_VERSION=1_41 Sat May 7 14:40:55 [initandlisten] waiting for connections on port 27017 Sat May 7 14:40:55 [websvr] web admin interface listening on port 28017 |
5.查看端口
# netstat -nptl | grep mongod
tcp 0 0 0.0.0.0:27017 0.0.0.0:* LISTEN 20495/mongod
tcp 0 0 0.0.0.0:2801 0.0.0.0:* LISTEN 20495/mongod
6.web界面
7.登录
Mongo是mongodb自带的交互式Javascript shell,用来对mongod进行操作和管理的交互式环境。
# /usr/local/mongodb-linux-x86_64-1.8.1/bin/mongo
转载于:https://blog.51cto.com/who0168/561145