Linux下的mongodb服务监视脚本

本文详细记录了使用Mongodb遇到的问题,包括修改启动脚本、检查权限、启动服务和验证连接步骤,最终成功解决了无法连接的问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

[root@hqw server]# vi /etc/init.d/mongodb 
[root@hqw server]# chmod +x /etc/init.d/mongodb 
[root@hqw server]# ./bin/mongo
MongoDB shell version: 1.8.2
connecting to: test
Sat Dec 13 10:56:32 Error: couldn't connect to server 127.0.0.1 shell/mongo.js:79
exception: connect failed
[root@hqw server]# service mongodb start
Starting mongod: all output going to: /usr/local/mongodb/server/logs
                                                           [  OK  ]
[root@hqw server]# ./bin/mongo
MongoDB shell version: 1.8.2
connecting to: test
> show dbs;
admin (empty)
local (empty)
> exit
bye
[root@hqw server]# service mongodb stop
Stopping mongod:                                           [  OK  ]
[root@hqw server]# /etc/init.d/mongodb start
Starting mongod: all output going to: /usr/local/mongodb/server/logs
                                                           [  OK  ]
[root@hqw server]# ./bin/mongo
MongoDB shell version: 1.8.2
connecting to: test
> show dbs;
admin (empty)
local (empty)
> exit
bye
[root@hqw server]# cd bin
[root@hqw bin]# ls
bsondump  mongo  mongod  mongodump  mongoexport  mongofiles  mongoimport  mongorestore  mongos  mongosniff  mongostat
[root@hqw bin]# pwd
/usr/local/mongodb/server/bin

[root@hqw bin]# 

启动脚本

#!/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=" --dbpath=/usr/local/mongodb/server/data --logpath=/usr/local/mongodb/server/logs --logappend &"
#mongod
mongod="/usr/local/mongodb/server/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


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值