mongodbサービススクリプト作成


1.新規プロファイル
mongodbインストール時にプロファイルが見つかりません
/etcディレクトリの下にmongodを新規作成します.confプロファイル
内容は以下の通り
# mongo.conf

#where to log
logpath=/data/logs/db.log

logappend=true

# fork and run in background
fork = true

#port = 27017

dbpath=/data/db

# 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
"/etc/mongod.conf" 82L, 1628C
# mongo.conf

#where to log
logpath=/data/logs/db.log

logappend=true

# fork and run in background
fork = true

#port = 27017

dbpath=/data/db

# 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 = 

# Accout token for Mongo monitoring server.
#mms-token = 

# Server name for Mongo monitoring server.
#mms-name = 

# Ping interval for Mongo monitoring server.
#mms-interval = 

# 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

2.起動
mongodb/bin/mongod -f/etc/mongod.confのこのような起動は私がとても不快に感じて、それでは私はサービスを作ります
3.サービススクリプト
/etc/init.dディレクトリの下にmongodファイルを新規作成する
内容は以下の通り
#!/bin/sh
#
#mongod - Startup script for mongod
#
# chkconfig: - 85 15
# description: Mongodb database.
# processname: mongod

# Source function library
. /etc/rc.d/init.d/functions


# things from mongod.conf get there by mongod reading it
# OPTIONS
OPTIONS=" -f /etc/mongod.conf"

#mongod
mongod="/root/mongodb/bin/mongod"

lockfile=/var/lock/subsys/mongod

start()
{
  echo -n $"Starting mongod: "
  daemon $mongod $OPTIONS
  RETVAL=$?
  echo
  [ $RETVAL -eq 0 ] && touch $lockfile
}

"/etc/init.d/mongod" 70L, 1036C
#!/bin/sh
#
#mongod - Startup script for mongod
#
# chkconfig: - 85 15
# description: Mongodb database.
# processname: mongod

# Source function library
. /etc/rc.d/init.d/functions


# things from mongod.conf get there by mongod reading it
# OPTIONS
OPTIONS=" -f /etc/mongod.conf"

#mongod
mongod="/root/mongodb/bin/mongod"

lockfile=/var/lock/subsys/mongod

start()
{
  echo -n $"Starting mongod: "
  daemon $mongod $OPTIONS
  RETVAL=$?
  echo
  [ $RETVAL -eq 0 ] && touch $lockfile
}

stop()
{
  echo -n $"Stopping mongod: "
  killproc $mongod -QUIT
  RETVAL=$?
  echo
  [ $RETVAL -eq 0 ] && rm -f $lockfile
}

restart () {
        stop
        start
}

ulimit -n 12000
RETVAL=0

case "$1" in
  start)
    start
    ;;
  stop)
    stop
    ;;
  restart|reload|force-reload)
    restart
    ;;
  condrestart)
    [ -f $lockfile ] && restart || :
    ;;
  status)
    status $mongod
    RETVAL=$?
    ;;
  *)
    echo "Usage: $0 {start|stop|status|restart|reload|force-reload|condrestart}"
    RETVAL=1
esac

exit $RETVAL

4.ファイル実行権限の追加
# chmod +x/etc/init.d/mongod
5.サービスコマンド
service mongod start
service mongod stop
service mongod restart
6.mongodサービスのポートの表示
netstat -npt | grep mongod
7.私は体操をして、兄も脚本を書くことができます
8.ここでは、起動も書きたいのですが、どうすれば能力が限られているのか、起動は/etc/rcにしか入れられません.local下
# mongodb start/root/mongodb/bin/mongod --repair/root/mongodb/bin/mongod -f/etc/mongod.conf
9.linuxはやはり博大で奥深い
10.注意
上のulimit-n 12000はmongodbの接続数を制限し、mongodbの最大接続数は20000で、直接この数値を最高にすればいいです.