最新消息:

Mongodb部署

mongodb admin 3013浏览 0评论

一、mongodb安装

1.下载(二进制版本免安装)

# wget http://fastdl.mongodb.org/linux/mongodb-linux-x86_64-1.8.1.tgz

1.2安装

# tar zxvf mongodb-linux-x86_64-1.8.1.tgz -C /usr/local

# mv mongodb-linux-x86_64-1.8.1 /usr/local/mongodb

二、配置

2.1创建用户

# useradd mongod -s /sbin/nologin

# mkdir /data/mongodb/data

# mkdir /data/log/mongodb/

# chown mongod.mongod /data/mongodb/data

# chown mongod.mongod /data/log/mongodb/

 

2.2创建配置文件

 

cd /usr/local/mongodb/etc

 

#cat mongodb.conf

# mongo.conf

#where to log

logpath=/data/log/mongodb/mongod.log  #指定日志文件

# fork and run in background

fork = true

port = 27017   #指定端口

dbpath=/data/mongodb/data   #数据目录

# 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

三、启动脚本

# cat /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/etc/mongodb.conf ”

#SYSCONFIG=”/etc/sysconfig/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 /var/lock/subsys/mongod

}

stop()

{

echo -n $”Stopping mongod: ”

killproc -p /data/mongodb/data/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

四、检查

[root@b2b_mongodb1 tools]# netstat -nlpt

Active Internet connections (only servers)

Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name

tcp 0 0 0.0.0.0:27017 0.0.0.0:* LISTEN 2577/mongod

tcp 0 0 :::22 :::* LISTEN 2525/sshd

转载请注明:爱开源 » Mongodb部署

您必须 登录 才能发表评论!