MongoDB安装

时间:2021-12-14 03:41:14

1.解压软件包

tar -zxvf mongodb-linux-x86_64-4.0.0.tgz

2.重命名

[[email protected] software]# mv mongodb-linux-x86_64-4.0.0 mongodb

3.配置环境变量

#Set Mongodb
MONGODB_HOME=/software/mongodb
PATH=$PATH:$MONGODB_HOME/bin

 4.创建数据库目录以及日志目录

cd /software/mongodb
$ touch mongodb.conf
$ mkdir db
$ mkdir log
$ cd log
$ touch mongodb.log

5.创建配置文件

port=27017
dbpath= /software/mongodb/db
logpath= /software/mongodb/log/mongodb.log
logappend=true
fork=true
maxConns=100
noauth=true
journal=true
storageEngine=wiredTiger
bind_ip = 0.0.0.0

 6.启动服务测试

cd /software/mongodb
bin/mongod -f /software/mongodb/mongo.conf

 

 

[Unit]  
Description=mongodb  
After=network.target remote-fs.target nss-lookup.target  
  
[Service]  
Type=forking  
ExecStart=/software/mongodb/bin/mongod --config /software/mongodb/bin/mongodb.conf  
ExecReload=/bin/kill -s HUP $MAINPID  
ExecStop=/software/mongodb/bin/mongod --shutdown --config /software/mongodb/bin/mongodb.conf  
PrivateTmp=true  
[Install]  
WantedBy=multi-user.target

 

 

#!/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=/software/mongodb/ --logpath=/software/mongodb/log/mongodb.log --logappend &"
#mongod
mongod="/software/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