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

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

##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
  1. 切到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
  1. 编辑~/.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
  1. 增加服务并开机启动
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服务了。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值