我爱编程

阿里云centos服务器安装mongodb数据库,设置开机启动

2017-06-30  本文已影响63人  暴走码农

1.安装:

1. 从mongodb官方网站下载二进制安装包(本文以mongodb-linux-x86_64-rhel62-3.4.5为例进行步骤讲解).

2. 将下载下来的文件放到/opt文件夹中,解压文件

tar zxvf mongodb-linux-x86_64-rhel62-3.4.5.tgz

mv  mongodb-linux-x86_64-rhel62-3.4.5 mongodb

3. 切到mongodb的目录下,进行如下操作:

cd mongodb

mkdir -p data/db

mkdir logs

cd bin/

touch mongodb.conf

并添加如下内容:

dbpath=/opt/mongodb/data/db

logpath=/opt/mongodb/logs/mongodb.log

pidfilepath=/opt/mongodb/db.pid

directoryperdb=true

logappend=true

bind_ip= localhost

port=27017

oplogSize=1000

fork=true

noprealloc=true

nojournal=true

smallfiles=true

4. 编辑~/.bash_profile:

将mongodb的bin路径添加到系统路径下

export PATH=/opt/mongodb/bin:$PATH

并执行source ~/.bash_profile,生效当前设置

到目前为止,直接输入如下命令:

mongod --config /opt/mongodb/bin/mongodb.conf

可以看到mongodb正常启动

2.配置开机自动启动:

1.  先在/etc/rc.d/init.d下新建文件 mongod,内容如下:

#!/bin/bash

#

#chkconfig: 2345 80 90

#description: mongod

start() {

mongod --config /opt/mongodb/bin/mongodb.conf

}

stop() {

mongod --config /opt/mongodb/bin/mongodb.conf --shutdown

}

case "$1" in

start)

start

;;

stop)

stop

;;

restart)

stop

start

;;

*)

echo

$"Usage: $0 {start|stop|restart}"

exit 1

esac

2. 增加服务并开机启动

chmod +x /etc/rc.d/init.d/mongod

chkconfig --add mongod

chkconfig --level 345 mongod on

chkconfig --list mongod

service mongod start

执行该脚本后,就可以开始使用service mongod start|stop|restart 管理你的mongodb服务了。

上一篇 下一篇

猜你喜欢

热点阅读