环境:

  系统硬件:vmware vsphere (CPU:2*4核,内存2G)

  系统版本:Centos-6.5-x86_64

  *** Centos编译安装mongodb 2.6 系统最好是64位的,才能更好发挥mongodb的性能

安装步骤:

  0.系统环境

  [root@centos ~]# cat /etc/redhat-release

  CentOS release 6.5 (Final)

  [root@centos ~]# uname -a

  Linux centos 2.6.32-431.el6.x86_64 #1 SMP Fri Nov 22 03:15:09 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux

  [root@centos ~]# yum install vim wget -y

  1.下载源文件(二进制编译版)

  [root@centos ~]# mkdir -p /data/src

  [root@centos ~]# cd /data/src

  [root@centos ~]# wget http://fastdl.mongodb.org/linux/mongodb-linux-x86_64-2.6.1.tgz

  [root@centos ~]# tar -zvxf mongodb-linux-x86_64-2.6.1.tgz

  [root@centos ~]# mv mongodb-linux-x86_64-2.6.1 /opt/mongodb/

  2.配置path环境变量,确保mongodb的bin目录包含在path环境变量中。

  2.1 配置PATH

  [root@centos ~]# vim /etc/profile

  添加下面的内容:

  #set for mongodb
  export MONGODB_HOME=/opt/mongodb
  export PATH=$MONGODB_HOME/bin:$PATH

  保存退出

  2.1查看当前PATH

  [root@centos ~]# echo $PATH

  2.2让环境变量生效:

  [root@centos ~]# source /etc/profile

  [root@centos ~]# echo $PATH

  

  3.验证环境变量是否生效

  [root@centos ~]# mongod -version

  4.建立存储数据及日志的目录:

  4.1建立目录

  [root@centos ~]# mkdir -p /data/mongodb/journal

  [root@centos ~]# mkdir -p /data/mongodb/log

  4.2建立日志文件

  [root@centos ~]# touch /data/mongodb/log/mongodb.log

  4.3建立配置文件

  [root@centos ~]# vim /etc/mongodb.conf

  输入以下内容,保存并退
dbpath=/data/mongodb
logpath=/data/mongodb/log/mongodb.log
logappend=true
port=27017
fork=true
noauth=true
nojournal = true
smallfiles = true
noprealloc = true

  5.增加mongodb用户及设置权限

  5.1增加用户

  [root@centos ~]# useradd mongodb -M -s /sbin/nologin

  5.2设置目录权限

  [root@centos ~]#chown -R mongodb.mongodb /data/mongodb
  

  6.重启,启动服务

  6.1重启
  [root@centos ~]# shutdown -r now

  6.2重启后,运行mongod服务
  [root@centos ~]# mongod -f /etc/mongodb.conf

  7.测试服务是否正常

  7.1打开另一个终端,并以管理员身份进入管理后台

  [root@centos ~]#mongo admin

  >show dbs;

  >db.test.find();

  >exit

  8.将mongod服务加到开机启动服务

  8.1编写服务文件

  [root@centos ~]# vim /etc/init.d/mongod

  输入以下内容,并且保存退出
#!/bin/sh
#
# mongodb      init file for starting up the MongoDB server
#
# chkconfig:   - 20 80
# description: Starts and stops the MongDB daemon that handles all \
#              database requests.

# Source function library.
. /etc/rc.d/init.d/functions

exec="/opt/mongodb/bin/mongod"
prog="mongod"
logfile="/data/mongodb/log/mongodb.log"
options=" -f /etc/mongodb.conf"

[ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog

lockfile="/var/lock/subsys/mongod"

start() {
    [ -x $exec ] || exit 5
    echo -n $"Starting $prog: "
    daemon --user mongodb "$exec --quiet $options run >> $logfile 2>&1 &"
    retval=$?
    echo
    [ $retval -eq 0 ] && touch $lockfile
    return $retval
}

stop() {
    echo -n $"Stopping $prog: "
    killproc $prog
    retval=$?
    echo
    [ $retval -eq 0 ] && rm -f $lockfile
    return $retval
}

restart() {
    stop
    start
}

reload() {
    restart
}

force_reload() {
    restart
}

rh_status() {
    # run checks to determine if the service is running or use generic status
    status $prog
}

rh_status_q() {
    rh_status >/dev/null 2>&1
}

case "$1" in
    start)
        rh_status_q && exit 0
        $1
        ;;
    stop)
        rh_status_q || exit 0
        $1
        ;;
    restart)
        $1
        ;;
    reload)
        rh_status_q || exit 7
        $1
        ;;
    force-reload)
        force_reload
        ;;
    status)
        rh_status
        ;;
    condrestart|try-restart)
        rh_status_q || exit 0
        restart
        ;;
    *)
        echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
        exit 2
esac
exit $?

  8.2设置为启动服务

  [root@centos ~]# chkconfig --add mongod

  [root@centos ~]# chkconfig --level 345 mongod on

  [root@centos ~]# chmod +x  /etc/init.d/mongod

  8.3测试
  [root@centos ~]#service mongod start

  [root@centos ~]#service mongod status

  

  9.重启,并且测试

  [root@centos ~]#shutdown -r now

  [root@centos ~]#service mongod status

  [root@centos ~]#mongo admin

  >show dbs;

  >db.test.find();

  >exit

  **********************************************
  mongodb的参数说明:
   --dbpath        数据库路径(数据文件)
  --logpath       日志文件路径
  --master        指定为主机器
  --slave         指定为从机器
  --source        指定主机器的IP地址
  --pologSize     指定日志文件大小不超过64M.因为resync是非常操作量大且耗时,

    最好通过设置一个足够大的oplogSize来避免resync(默认的 oplog大小是空闲磁盘大小的5%)。
  --logappend     日志文件末尾添加
  --port          启用端口号
  --fork          在后台运行
  --only          指定只复制哪一个数据库
  --slavedelay    指从复制检测的时间间隔
  --auth          是否需要验证权限登录(用户名和密码)

centos 6.5 X64 安装 mongodb 2.6.1 (笔记 实测)的更多相关文章

  1. Linux CentOS 6.5 yum安装MongoDB的操作

    安装MongoDB的方法有很多种,可以源代码安装,在CentOS也可以用yum源安装的方法.由于MongoDB更新得比较快,我比较喜欢用yum源安装的方法.64位CentOS下的安装步骤如下: 1.准 ...

  2. CentOS 6.6 x64安装TensorFlow

    CentOS 6.6 x64安装TensorFlow升级Python到2.7(系统自带Python版本为2.6) // 安装编译工具 $ yum -y install gcc automake aut ...

  3. 转: CentOS 6 使用 yum 安装MongoDB及服务器端配置

    转: http://www.cnblogs.com/shanyou/archive/2012/07/14/2591838.html CentOS 6 使用 yum 安装MongoDB及服务器端配置   ...

  4. CentOS 6.5 x64 安装Tomcat8 并配置两个Tomcat8

    1.首先,安装tomcat的前提是已经配置好jdk环境变量,若没配好可以参考我的上一篇博文:CentOS 6.5 x64安装jdk8,当然也可以通过网络搜索安装步骤~~ 2.下载: 可以通过官网下载: ...

  5. CentOS 6.5 x64 安装jdk8

    1.去官网下载Linux版本的jdk8,我下载的是下面这个 2.下载xftp和xshell来操纵服务器,可以搜索一下下载安装即可,安装完成后,打开xshell,新建链接为你的云服务器的IP地址和密码, ...

  6. 如何在CentOS/RHEL & Fedora上安装MongoDB 3.2

    MongoDB(名称取自"huMONGOus")是一个有着全面灵活的索引支持和丰富的查询的数据库.MongoDB通过GridFS提供强大的媒体存储.点击这里获取MongoDB的更多 ...

  7. Hadoop 之Mong DB 之CentOS 6 使用 yum 安装MongoDB及服务器端配置

    安装MongoDB的方法有很多种,可以源代码安装,在Centos也可以用yum源安装的方法.由于MongoDB更新得比较快,我比较喜欢用yum源安装的方法.64位Centos下的安装步骤如下: 1.准 ...

  8. CentOS 6 使用 yum 安装MongoDB及服务器端配置

    安装MongoDB的方法有很多种,可以源代码安装,在Centos也可以用yum源安装的方法.由于MongoDB更新得比较快,我比较喜欢用yum源安装的方法.64位Centos下的安装步骤如下: 1.准 ...

  9. 在CentOS中使用 yum 安装MongoDB及服务器端配置

    转自 http://blog.csdn.net/zhangfeng19880710/article/details/20166853 一.准备工作: 运行yum命令查看MongoDB的包信息 [roo ...

随机推荐

  1. Codeforces 734E. Anton and Tree 搜索

    E. Anton and Tree time limit per test: 3 seconds memory limit per test :256 megabytes input:standard ...

  2. ebtables hook

    1 概述 netfliter框架不仅仅在ipv4中有应用,bridge,ipv4,ipv6,decnet 这四种协议中都有应用,其中ipv4中又分开了arp和ip的两种 其实netfliter是个大的 ...

  3. Linux内核【链表】整理笔记(2)

    关于链表我们更多时候是对其进行遍历的需求,上一篇博文里我们主要认识了一下和链表操作比较常用的几个内核API接口,其入参全都是清一色的struct list_head{}类型.至于链表的遍历,内核也有一 ...

  4. Windows 环境下配置 git bash 的 HOME 默认路径

    0.引 在 windows 下安装 git 之后, git 默认的HOME和~路径一般都是C:\Users\用户名,每次得用命令切换到常用的Repository下,此操作重复而没有意义.为了修改默认路 ...

  5. ue4 模块的构建和加载

    ue4的代码是模块的形式来组织 在源码层面,一个包含*.build.cs的目录就是一个模块 这个目录里的文件在编译后都会被链接在一起,比如一个静态库lib,或者一个动态库dll. 不管是哪种形式,都需 ...

  6. row_number和partition by分组取top数据

    分组取TOP数据是T-SQL中的常用查询, 如学生信息管理系统中取出每个学科前3名的学生.这种查询在SQL Server 2005之前,写起来很繁琐,需要用到临时表关联查询才能取到.SQL Serve ...

  7. Jquery实现文字向上逐条滚动

    直接上代码: <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" ...

  8. js动态时间

    一.在<head></head> 之间写入下面js代码 <script type="text/javascript" language="J ...

  9. 51nod 1428 活动安排问题(优先队列)

    1428 活动安排问题 首先按照开始时间从小到大排序. 其实只要维护一个结束时间的最小堆,每次比较开始时间和堆中最小时间的大小,如果比它大就放入堆中并且时间就要变成当前任务的结束时间, 否则就要新开一 ...

  10. pygame 练习之 PIE game (以及简单图形训练)

    简单的大饼游戏,掌握pygame中直线以及圆弧的画法,以及对输入的响应. import math import pygame, sys from pygame.locals import * pyga ...