1. 下载二进制包,解压,安装
- wget http://fastdl.mongodb.org/linux/mongodb-linux-x86_64-1.8.2.tgz -P /usr/local/src
- tar zxvf /usr/local/src/mongodb-linux-x86_64-1.8.2.tgz -C /usr/local/src
- cd /usr/local/src
- mv mongodb-linux-x86_64-1.8.2 /usr/local/mongodb
2. 添加mongod用户
- useradd -r mongod -d /usr/local/mongodb -s /bin/false
3. 建立相关目录
- # 配置文件目录
- mkdir /usr/local/mongodb/etc
- # 修改目录的拥有者为mongod
- chown -R mongod:mongod /usr/local/mongod
- # 建立数据目录和日志目录
- mkdir -p /data/mongodb/{db,logs}
- # 修改目录的拥有者为mongod
- chown -R mongod:mongod /data/mongodb
4. 配置文件
- vi /usr/local/mongodb/etc/mongod.conf
- # mongo.conf
- # log file to send write to instead of stdout – has to be a file, not directory
- logpath=/data/mongodb/logs/mongod.log
- # append to logpath instead of over-writing
- logappend=true
- # fork and run in background
- fork = true
- # specify port number
- port = 27017
- # comma separated list of ip addresses to listen on – all local ips by default
- bind_ip = 192.168.1.10
- # directory for datafiles
- dbpath = /data/mongodb/db
- # full path to pidfile (if not set, no pidfile is created)
- pidfilepath = /usr/local/mongodb/mongod.pid
- # 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
指定了日志的存放目录,日志以追加方式进行,后台进程运行,端口号,监听IP,数据目录,pid文件,不启动http显示页面
5. 添加为Service
- # 添加选项文件,可以将要启动的选项写入这个文件中,我的为空
- vi /etc/sysconfig/mongod
- # 启动文件
- vi /etc/rc.d/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/mongo.pid
- . /etc/rc.d/init.d/functions
- # things from mongod.conf get there by mongod reading it
- OPTIONS=" -f /usr/local/mongodb/etc/mongod.conf"
- SYSCONFIG="/etc/sysconfig/mongod"
- mongod=${MONGOD-/usr/local/mongodb/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 /usr/local/mongodb/mongod
- }
- stop()
- {
- echo -n $"Stopping mongod: "
- killproc -p /data/mongodb/db/mongod.lock -t30 -TERM /usr/local/mongodb/bin/mongod
- RETVAL=$?
- echo
- [ $RETVAL -eq 0 ] && rm -f /usr/local/mongodb/mongod
- }
- restart () {
- stop
- start
- }
- ulimit -n 12000
- RETVAL=0
- case "$1" in
- start)
- start
- ;;
- stop)
- stop
- ;;
- restart|reload|force-reload)
- restart
- ;;
- condrestart)
- [ -f /usr/local/mongodb/mongod ] && restart || :
- ;;
- status)
- status $mongod
- RETVAL=$?
- ;;
- *)
- echo "Usage: $0 {start|stop|status|restart|reload|force-reload|condrestart}"
- RETVAL=1
- exit $RETVAL
添加为服务
- chkconfig –add mongod
- chkconfig mongod on
- service mongod start
- service mongod stop