mongodb 安装部署说明

mongodb.conf 配置文件

# Where the databases will be stored
dbpath=/usr/local/mongodb/mongodb-3.4.6/data/db

# The port number the mongod server will listen on
# port=27017

# Listen on a specific ip address
# Comment out the line below if you need to access mongod remotely.
# USE WITH CAUTION -- THIS WILL ACCEPT ANY AND ALL CONNECTIONS WHEN USED WITH
# THE noauth OPTION!!!
# bind_ip=127.0.0.1

# Log location -- otherwise stdout
logpath=/usr/local/mongodb/mongodb-3.4.6/logs/log

# appnd to logpath instead of over-writing
# logappend=true

# Use authentication
# auth=true

# Don't use authentication
noauth=true

# Disable the http interface
nohttpinterface=true

# fork and run in background
fork=true

mongod.centos 服务注册文件

#!/bin/bash 
# init script for mongodb 
# chkconfig: 2345 70 11 
# description: mongod 
# processname: mongod 
# pidfile: /var/run/mongodb.pid

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

RETVAL=0 
pidfile=/var/run/mongodb.pid 
exec="/usr/local/mongodb/mongodb-3.4.6/bin/mongod" 
prog="mongod" 
config="/etc/mongodb.conf" 
lockfile="/var/lock/mongod"

[ -e $config ] && . $config

start() { 
  if [ ! -x $exec ] 
  then 
    echo \$exec not found 
    exit 5 
  fi

  echo -n $"Starting $prog: "

  daemon $exec --fork --logpath=/usr/local/mongodb/mongodb-3.4.6/logs/mongod.log --logappend -f $config
  RETVAL=$? 
  echo 
  [ $RETVAL = 0 ] && touch ${lockfile} 
  return $RETVAL

}

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

restart() { 
  stop 
  start 
}

# See how we were called. 
case "$1" in 
  start) 
    start 
  ;; 
  stop) 
    stop 
  ;; 
  restart) 
    stop 
    sleep 1 
    start 
  ;; 
*) 

echo $"Usage: `basename $0` {start|stop|restart|status}" 
exit 2 
esac

exit $RETVAL

# 安装目录
/usr/local/mongodb/mongodb-3.4.6

# 建立存储数据及日志的目录:
cd /usr/local/mongodb/mongodb-3.4.6
mkdir -p /data/db/
mkdir -p /data/logs/
touch /data/logs/mongodb.log

# 加入系统环境变量
export PATH=/usr/local/mongodb/mongodb-3.4.6/bin:$PATH

# 配置文件方式启动
mongod -f /etc/mongodb.conf

# 命令行方式启动 无身份验证
mongod -dbpath=/usr/local/mongodb/mongodb-3.4.6/data/db -logpath=/usr/local/mongodb/mongodb-3.4.6/logs/log --fork --rest

# 命令行方式启动 加身份验证
mongod -dbpath=/usr/local/mongodb/mongodb-3.4.6/data/db -logpath=/usr/local/mongodb/mongodb-3.4.6/logs/log --fork --rest --auth

# 注册服务

# Copy the init script and config file

cp mongod.centos /etc/init.d/mongod
cp mongodb.conf /etc/mongodb.conf

# Install mongod as a service
/sbin/chkconfig mongod on

# 用chmod +x /etc/init.d/mongod 命令允许该脚本可被执行
chmod +x /etc/init.d/mongod

# 删除服务
chkconfig --del mongod

# 启动或停止服务
sudo service mongod stop
sudo service mongod start

# 注册开机脚本
chkconfig --add mongod
chmod +x mongod
chkconfig mongod on

# 如果是ubuntu 添加服务,开机启动
update-rc.d mongod defaults
# 删除服务
update-rc.d -f mongod remove

# 检查并结束进程
ps -aux|grep mongodb
kill -s 9 "pid"

 

posted @ 2017-07-25 10:38  如.若  阅读(232)  评论(0编辑  收藏  举报