mongodb服务脚本编写

php中文网
发布: 2016-06-07 15:22:48
原创
1401人浏览过

1.新建配置文件 mongodb安装时缺少配置文件 在 /etc 目录下新建 mongod.conf 配置文件 内容如下 # mongo.conf#where to loglogpath=/data/logs/db.loglogappend=true# fork and run in backgroundfork = true#port = 27017dbpath=/data/db# Enables periodic

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

2.启动
登录后复制

mongodb/bin/mongod -f /etc/mongod.conf
这种启动我感到很不爽,那我就做成service

3.service(服务)脚本

在 /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命令

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果然博大精深

最佳 Windows 性能的顶级免费优化软件
最佳 Windows 性能的顶级免费优化软件

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。

下载
相关标签:
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号