1. 选择下载安装包

在官方网站(http://www.mongodb.org/downloads)选择下载我们所需要的包.

这里是查看系统多少位方式:

 

  1. # uname -a 
  2. Linux domain_name 2.6.18-128.el5 #x86_64 x86_64 x86_64 GNU/Linux  
  3. # cat /etc/redhat-release 
  4. Red Hat Enterprise Linux Server release 5.3 (Tikanga)

这里我们选择下载mongodb-linux-x86_64-1.8.1.tgz

 

  1. # cd /tmp 
  2. # wget http://fastdl.mongodb.org/linux/mongodb-linux-x86_64-1.8.1.tgz 

2.安装mongod

  1. # tar -xvf mongodb-linux-x86_64-1.8.1.tgz  //解压 
  2. mongodb-linux-x86_64-1.8.1/ 
  3. mongodb-linux-x86_64-1.8.1/THIRD-PARTY-NOTICES 
  4. ... ... 
  5. # mv mongodb-linux-x86_64-1.8.1 /usr/local/mongodb      //移动mongod到指定目录 
  6. # ln -s /usr/local/mongodb/bin/mongod /usr/bin/mongod   //为了方便使用创建软链接 
  7. # mkdir /data/db                                      //创建默认数据文件目录 
  8. # mongod --shardsvr --port [portnumber]               //启动服务,端口根据需要启动

3.配置

  1. # mongod --help 
  2. Allowed options: 
  3.  
  4. General options: 
  5.   -h [ --help ]          show this usage information 
  6.   --version              show version information 
  7.   -f [ --config ] arg    configuration file specifying additional options 
  8.   -v [ --verbose ]       be more verbose (include multiple times for more  
  9.                          verbosity e.g. -vvvvv) 
  10.   --quiet                quieter output 
  11.   --port arg             specify port number 
  12.   --bind_ip arg          comma separated list of ip addresses to listen on -  
  13.                          all local ips by default 
  14.   --logpath arg          log file to send write to instead of stdout - has to  
  15.                          be a file, not directory 
  16.   --logappend            append to logpath instead of over-writing 
  17.   --pidfilepath arg      full path to pidfile (if not set, no pidfile is  
  18.                          created) 
  19.   --keyFile arg          private key for cluster authentication (only for  
  20.                          replica sets) 
  21.   --unixSocketPrefix arg alternative directory for UNIX domain sockets  
  22.                          (defaults to /tmp) 
  23.   --fork                 fork server process 
  24.   --auth                 run with security 
  25.   --cpu                  periodically show cpu and iowait utilization 
  26.   --dbpath arg           directory for datafiles 
  27.   --diaglog arg          0=off 1=W 2=R 3=both 7=W+some reads 
  28.   --directoryperdb       each database will be stored in a separate directory 
  29.   --journal              enable journaling 
  30.   --journalOptions arg   journal diagnostic options 
  31.   --ipv6                 enable IPv6 support (disabled by default) 
  32.   --jsonp                allow JSONP access via http (has security  
  33.                          implications) 
  34.   --maxConns arg         max number of simultaneous connections 
  35.   --noauth               run without security 
  36.   --nohttpinterface      disable http interface 
  37.   --noprealloc           disable data file preallocation - will often hurt  
  38.                          performance 
  39.   --noscripting          disable scripting engine 
  40.   --notablescan          do not allow table scans 
  41.   --nounixsocket         disable listening on unix sockets 
  42.   --nssize arg (=16)     .ns file size (in MB) for new databases 
  43.   --objcheck             inspect client data for validity on receipt 
  44.   --profile arg          0=off 1=slow2=all 
  45.   --quota                limits each database to a certain number of files (8  
  46.                          default) 
  47.   --quotaFiles arg       number of files allower per db, requires --quota 
  48.   --rest                 turn on simple rest api 
  49.   --repair               run repair on all dbs 
  50.   --repairpath arg       root directory for repair files - defaults to dbpath 
  51.   --slowms arg (=100)    value of slow for profile and console log 
  52.   --smallfiles           use a smaller default file size 
  53.   --syncdelay arg (=60)  seconds between disk syncs (0=never, but not  
  54.                          recommended) 
  55.   --sysinfo              print some diagnostic system information 
  56.   --upgrade              upgrade db if needed 
  57.  
  58. Replication options: 
  59.   --fastsync            indicate that this instance is starting from a dbpath  
  60.                         snapshot of the repl peer 
  61.   --autoresync          automatically resync if slave data is stale 
  62.   --oplogSize arg       size limit (in MB) for op log 
  63.  
  64. Master/slave options: 
  65.   --master              master mode 
  66.   --slave               slave mode 
  67.   --source arg          when slave: specify master as <server:port> 
  68.   --only arg            when slave: specify a single database to replicate 
  69.   --slavedelay arg      specify delay (in seconds) to be used when applying  
  70.                         master ops to slave 
  71.  
  72. Replica set options: 
  73.   --replSet arg         arg is <setname>[/<optionalseedhostlist>
  74.  
  75. Sharding options: 
  76.   --configsvr           declare this is a config db of a cluster; default port  
  77.                         27019; default dir /data/configdb 
  78.   --shardsvr            declare this is a shard db of a cluster; default port  
  79.                         27018 
  80.   --noMoveParanoia      turn off paranoid saving of data for moveChunk.  this  
  81.                         is on by default for now, but default will switch 

4.结果

  1. # mongod --shardsvr --port 9999 
  2. Tue May 24 08:14:04 [initandlisten] MongoDB starting : pid=13314 port=9999 dbpath=/data/db/ 64-bit  
  3. Tue May 24 08:14:04 [initandlisten] db version v1.8.1, pdfile version 4.5 
  4. Tue May 24 08:14:04 [initandlisten] git version: a429cd4f535b2499cc4130b06ff7c26f41c00f04 
  5. Tue May 24 08:14:04 [initandlisten] build sys info: Linux bs-linux64.10gen.cc 2.6.21.7-2.ec2.v1.2.fc8xen #1 SMP Fri Nov 20 17:48:28 EST 2009 x86_64 BOOST_LIB_VERSION=1_41 
  6. Tue May 24 08:14:04 [initandlisten] waiting for connections on port 9999 
  7. Tue May 24 08:14:04 [websvr] web admin interface listening on port 10999