zoukankan      html  css  js  c++  java
  • MongoDB安装

    安装
    1>设置MongoDB目录
    cd /home/apps      附:centOS下创建目录命令  mkdir /home/apps
    2>下载mongodb
    curl -O http://fastdl.mongodb.org/Linux/mongodb-linux-x86_64-2.4.6.tgz
    或者直接下载再copy或用xftp上传到指定目录
    3>解压缩文件
    tar xzf mongodb-linux-x86_64-2.4.6.tgz
    4>启动服务
    ./mongodb/bin/mongod -dbpath=/data/mongodb/db -logpath=/data/mongodb/log
    mongodb 是mongo解压后的目录,下同
    5>将mongoDB服务加入随机启动
    vi /etc/rc.local
    使用vi编辑器打开配置文件,并在其中加入下面一行代码
    /home/apps/mongodb/bin/mongod --dbpath /data/mongodb/db --port 27017 --logpath /data/mongodb/log --logappend
    这种方式能保证开机mongod 进程能开启,但没有作为服务运行
    6>把mongod 作为服务开机启动
    先在/etc/rc.d/init.d下用vi 新建文件 mongod
    内容如下:
    #!/bin/bash
    #
    #chkconfig: 2345 80 90
    #description: mongodb
    start() {
     /usr/mongodb/bin/mongod --config /usr/mongodb/config/mongod.conf
    }
    stop() {
          /usr/mongodb/bin/mongod --config /usr/mongodb/config/mongod.conf --shutdown
    }
    case "$1" in
      start)
     start
     ;;
      
    stop)
     stop
     ;;
      
    restart)
     stop
     start
     ;;
      *)
     echo 
    $"Usage: $0 {start|stop|restart}"
     exit 1
    esac
    保存
    /usr/mongodb/config/mongod.conf 配置文件的内容如下
    #master.conf  
    dbpath=/usr/mongodb/data/db  
    logpath=/usr/mongodb/log/db.log  
    pidfilepath=/usr/mongodb/db.pid  
    directoryperdb=true  
    logappend=true   
    bind_ip=192.168.1.7  
    port=27017  
    oplogSize=1000  
    fork=true  
    noprealloc=true
    nojournal=true  
    smallfiles=true
    2、增加服务并开机启动
    chmod +x /etc/rc.d/init.d/mongod
    chkconfig --add mongod
    chkconfig --level 345 mongod on
    chkconfig --list mongod
    service mongod start
    执行该脚本后,就可以开始start|stop|restart|list你的服务了。
    以后关机再启动就会自动启动mongo了,如果在同一台机需要启动多个mongod照此方法即可
    暂时只知道这样设为开机启动服务,如果有更好的方式请告知哦,先谢了!
    7>连接mongoDB
    ./mongodb/bin/mongo 27017 
    即可连上mongo
    讲到这儿,mongoDB的在Linux下安装已完成,本地连接mongoDB也已成功,这时我们就要考虑到另外一个问题了,局域网如何来连接mongoDB呢?局域网中windows机器如何来连接Linux机器中的mongoDB呢?
    其实做法一样很简单:./mongodb/bin/mongo 192.168.10.234:port即可。
    不过此处就需要注意了,我们需要在centOS上打开mongoDB的端口号,接下来讲讲如何在centOS上打开指定端口。
    我们打开配置文件 /etc/sysconfig/iptables,在该文件中添加如下内容:
    -A RH-Firewall-l-INPUT -P tcp -m tcp --dport mongoDB端口号 -j ACCEPT
    然后重启服务
    service iptables restart
    此时,你已可以开始通过局域网来访问centOS上部署的mongoDB
     
    顺便再增加一点centOS与windows互访的知识,譬如,我们想把原来在windows机器上的mongoDB产生的文件移植到centOS中,当然可以用移动存储设备来拷贝,但是我这里讲的是Linux(centOS)如何来访问windows共享目录,命令如下:
    mount -t cifs //ip/共享目录名称 /mnt/sharefile -o username=,password=
    上面的命令即将windows的共享目录映射为linux上的/mnt/sharefile目录
    1
  • 相关阅读:
    北京燃气IC卡充值笔记
    随机分析、随机控制等科目在量化投资、计算金融方向有哪些应用?
    量化交易平台大全
    Doctor of Philosophy in Computational and Mathematical Engineering
    Institute for Computational and Mathematical Engineering
    Requirements for the Master of Science in Computational and Mathematical Engineering
    MSc in Mathematical and Computational Finance
    万字长文:详解多智能体强化学习的基础和应用
    数据处理思想和程序架构: 使用Mbedtls包中的SSL,和服务器进行网络加密通信
    31-STM32+W5500+AIR202/302基本控制篇-功能优化-W5500移植mbedtls库以SSL方式连接MQTT服务器(单向忽略认证)
  • 原文地址:https://www.cnblogs.com/jym-sunshine/p/6256739.html
Copyright © 2011-2022 走看看