当前位置:Gxlcms > 数据库问题 > Mongodb的安装方法 -- 转自朋友微博

Mongodb的安装方法 -- 转自朋友微博

时间:2021-07-01 10:21:17 帮助过:3人阅读

#mongo.conf
dbpath=/opt/mongodb/data
logpath=/opt/mongodb/log/mongodb.log

logappend=true
fork = true
port = 27017

#noauth = true
auth = true

#journal=true
nojournal=true
5. 创建系统服务脚本
  vim /etc/init.d/mongodb 
#!/bin/bash
#
#chkconfig: 2345 80 90
#description: mongodb

start() {
 rm -f /opt/mongodb/data/mongod.lock
 /opt/mongodb/bin/mongod --config /etc/mongod.conf
}

stop() {
 /opt/mongodb/bin/mongod --config /etc/mongod.conf --shutdown
}

case "$1" in
  start)
    start
     ;;

  stop)
    stop
     ;;

  restart)
    stop
    start
    ;;

  *)
    echo $"Usage: $0 {start|stop|restart}"
    exit 1
  ;;

esac

exit 0

 6. 添加到系统服务,并设置开机启动

  chkconfig --add mongodb

  chkconfig --level 35 mongodb on

7. 启动mongodb
  service mongodb start  (如存在权限问题就用chmod 777命令)
8. 将/opt/mongodb/bin目录添加到环境变量PATH中
    vim /etc/profile
    export PATH=$PATH:/usr/local/node/bin:/opt/mongodb/bin/
    保存退出,source /etc/profile
9. mongodb测试
    使用命令mongo,进入mongo界面,默认链接的是test数据库,为admin数据库添加账号和密码:
    use admin;
    db.addUser("root", "103279");
    db.auth("root", "103279");
    exit;
    然后连接admin数据库:
    mongo admin -u root -p
    输入密码进入命令界面
10. 防火墙要开放27107端口,centos可以使用setup命令进入设置界面

Mongodb的安装方法 -- 转自朋友微博

标签:

人气教程排行