服务器搭建--Linux安装MongoDB3.6.4

截至2018-4-24为止MongoDB最新版本为3.6.4


1.下载安装:

切换到:/usr/local/soft/

cd /usr/local/soft/

下载:

curl -O https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.6.4.tgz
 % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 82.8M  100 82.8M    0     0  1042k      0  0:01:21  0:01:21 --:--:--  958k

解压:

tar -zxvf mongodb-linux-x86_64-3.6.4.tgz 
[root@manmanda2018 soft]# tar -zxvf mongodb-linux-x86_64-3.6.4.tgz 
mongodb-linux-x86_64-3.6.4/README
mongodb-linux-x86_64-3.6.4/THIRD-PARTY-NOTICES
mongodb-linux-x86_64-3.6.4/MPL-2
mongodb-linux-x86_64-3.6.4/GNU-AGPL-3.0
mongodb-linux-x86_64-3.6.4/bin/mongodump
mongodb-linux-x86_64-3.6.4/bin/mongorestore
mongodb-linux-x86_64-3.6.4/bin/mongoexport
mongodb-linux-x86_64-3.6.4/bin/mongoimport
mongodb-linux-x86_64-3.6.4/bin/mongostat
mongodb-linux-x86_64-3.6.4/bin/mongotop
mongodb-linux-x86_64-3.6.4/bin/bsondump
mongodb-linux-x86_64-3.6.4/bin/mongofiles
mongodb-linux-x86_64-3.6.4/bin/mongoreplay
mongodb-linux-x86_64-3.6.4/bin/mongoperf
mongodb-linux-x86_64-3.6.4/bin/mongod
mongodb-linux-x86_64-3.6.4/bin/mongos
mongodb-linux-x86_64-3.6.4/bin/mongo
mongodb-linux-x86_64-3.6.4/bin/install_compass

移动到/usr/local/mongodb/目录:

mv mongodb-linux-x86_64-3.6.4 /usr/local/mongodb

编辑环境变量:

vim /etc/profile
export MONGODB_HOME=/usr/local/mongodb/mongodb-linux-x86_64-3.6.4/
export PATH=${MONGODB_HOME}/bin:$PATH
source /etc/profile #使之生效

切换到新目录的bin目录下:

cd /usr/local/mongodb/mongodb-linux-x86_64-3.6.4/bin

新建mongodb.conf文件:

port=27017
dbpath=/usr/local/mongodb/mongodb-linux-x86_64-3.6.4/data/db   #如果没有目录需要创建
logpath=/usr/local/mongodb/mongodb-linux-x86_64-3.6.4/log/out.log  #如果没有目录需要创建
logappend=true

启动mongodb:

./mongod -f mongodb.conf
about to fork child process, waiting until server is ready for connections.
forked process: 20058
child process started successfully, parent exiting     #启动成功

设置开机启动:

cd /etc/init.d
vi mongodb(创建启动文件,内容如下,确保下面启动和关闭的命令可以正常执行)
#!/bin/sh
# chkconfig:         2345 75 15
# description:       mongodb

### BEGIN INIT INFO
# Provides:     mongodb
# Required-Start:
# Required-Stop:
# Default-Start:        2 3 4 5
# Default-Stop:         0 1 6
# Short-Description: mongodb
# Description: mongo db server
### END INIT INFO

EXE_FILE=/usr/local/mongodb/mongodb-linux-x86_64-3.6.4/bin/mongod
CONFIG_FILE=/usr/local/mongodb/mongodb-linux-x86_64-3.6.4/bin/mongodb.conf

#. /lib/lsb/init-functions
MONGOPID=`ps -ef| grep mongod| grep -v grep| awk '{print $2}'`
test -x $EXE_FILE || exit 0

case "$1" in
  start)
    ulimit -n 3000
    $EXE_FILE --config $CONFIG_FILE
    ;;
  stop)
    if [ ! -z "$MONGOPID" ]; then
        kill -15 $MONGOPID
    fi
    ;;
  status)
    ps -aux| grep mongod
    ;;
  *)
    log_success_msg "Usage: /etc/init.d/mongodb {start|stop|status}"
    exit 1
esac

exit 0
service mongodb start //启动mongodb服务
chkconfig mongodb on //开启开机启动

猜你喜欢

转载自blog.csdn.net/ztx114/article/details/80061932
今日推荐