首页 / 数据库 / MySQL / CentOS6.5上源码安装MongoDB3.2.1
1、环境准备:1 mkdir /home/mongodb #创建MongoDB程序存放目录2 mkdir /data/mongodata -p#创建数据存放目录3 mkdir /data/log/mongolog -p #创建日志存放目录2、下载:1 curl -O https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.2.1.tgz3、安装:1 tar xf mongodb-linux-x86_64-3.2.1.tgz2 cd mongodb-linux-x86_64-3.2.13 cp -r * /home/mongodb为了便于命令启动,需要编辑全局变量PATH1 vim /etc/profile.d/mongo.sh2 export PATH=$PATH:/home/mongodb/binsource /etc/profile.d/mongo.sh4、启动服务首先查看mongod的帮助信息1 [root@test ~]# mongod --help2 Options:3 4 General options:5 -h [ --help ] show this usage information6 --version show version information7 -f [ --config ] arg configuration file specifying 8 additional options9 -v [ --verbose ] [=arg(=v)] be more verbose (include multiple times 10 for more verbosity e.g. -vvvvv) 11 --quiet quieter output 12 --port arg#指定mongodb服务的端口号,默认为:2701713 --bind_ip arg #在多网卡的机器上指定mongodb服务绑定到哪一个ip上15 --ipv6enable IPv6 support (disabled by16 default) 17 --maxConns arg#指定最大客户端连接数19 --logpath arg #指定日志文件路径,必须是一个文件,而不是目录20 --sysloglog to system"s syslog facility instead 23 of file or stdout 24 --syslogFacility argsyslog facility used for mongodb syslog 25 message 26 --logappend #以追加的方式打印日志到--logpath参数指定的日志文件中28 --logRotate arg set the log rotation behavior29 (rename|reopen) 30 --timeStampFormat arg Desired format for timestamps in log31 messages. One of ctime, iso8601-utc or32 iso8601-local 33 --pidfilepath arg full path to pidfile (if not set, no34 pidfile is created) 35 --keyFile arg private key for cluster authentication 36 --setParameter argSet a configurable parameter 37 --httpinterface enable http interface 38 --clusterAuthMode arg Authentication mode used for cluster39 authentication. Alternatives are40 (keyFile|sendKeyFile|sendX509|x509) 41 --nounixsocketdisable listening on unix sockets 42 --unixSocketPrefix argalternative directory for UNIX domain43 sockets (defaults to /tmp) 44 --filePermissions arg permissions to set on UNIX domain45 socket file - 0700 by default 46 --fork#以daemon的形式运行服务进程 47 --authrun with security 48 --noauthrun without security 49 --jsonp allow JSONP access via http (has50 security implications) 51 --restturn on simple rest api 52 --slowms arg (=100) value of slow for profile and console53 log 54 --profile arg 0=off 1=slow, 2=all 55 --cpu periodically show cpu and iowait56 utilization 57 --sysinfo print some diagnostic system58 information 59 --noIndexBuildRetry don"t retry any index builds that were60 interrupted by shutdown 61 --noscripting disable scripting engine 62 --notablescan do not allow table scans 63 --shutdownkill a running server (for init64 scripts) 6566 Replication options: 67 --oplogSize arg size to use (in MB) for replication op68 log. default is 5% of disk space (i.e.69 large is good) 7071 Master/slave options (old; use replica sets instead): 72 --mastermaster mode 73 --slave slave mode 74 --source argwhen slave: specify master as75 <server:port> 76 --only argwhen slave: specify a single database77 to replicate 78 --slavedelay argspecify delay (in seconds) to be used79 when applying master ops to slave 80 --autoresyncautomatically resync if slave data is81 stale 8283 Replica set options: 84 --replSet arg arg is <setname>[/<optionalseedhostlist 85 >] 86 --replIndexPrefetch arg specify index prefetching behavior (if87 secondary) [none|_id_only|all] 88 --enableMajorityReadConcern enables majority readConcern 8990 Sharding options: 91 --configsvr declare this is a config db of a92 cluster; default port 27019; default93 dir /data/configdb 94 --configsvrMode arg Controls what config server protocol is 95 in use. When set to "sccc" keeps server 96 in legacy SyncClusterConnection mode97 even when the service is running as a98 replSet 99 --shardsvrdeclare this is a shard db of a 100 cluster; default port 27018101 102 Storage options:103 --storageEngine arg what storage engine to use - defaults 104 to wiredTiger if no data files present105 --dbpath arg#指定数据目录路径107 --directoryperdbeach database will be stored in a 108 separate directory109 --nopreallocdisable data file preallocation - will 110 often hurt performance111 --nssize arg (=16).ns file size (in MB) for new databases112 --quota limits each database to a certain 113 number of files (8 default)114 --quotaFiles argnumber of files allowed per db, implies115 --quota116 --smallfilesuse a smaller default file size117 --syncdelay arg (=60) seconds between disk syncs (0=never, 118 but not recommended)119 --upgrade upgrade db if needed120 --repairrun repair on all dbs121 --repairpath argroot directory for repair files - 122 defaults to dbpath123 --journal enable journaling124 --nojournal disable journaling (journaling is on by125 default for 64 bit)126 --journalOptions argjournal diagnostic options127 --journalCommitInterval arg how often to group/batch commit (ms)128 129 WiredTiger options:130 --wiredTigerCacheSizeGB arg maximum amount of memory to allocate 131 for cache; defaults to 1/2 of physical 132 RAM133 --wiredTigerStatisticsLogDelaySecs arg (=0)134 seconds to wait between each write to a135 statistics file in the dbpath; 0 means 136 do not log statistics137 --wiredTigerJournalCompressor arg (=snappy)138 use a compressor for log records 139 [none|snappy|zlib]140 --wiredTigerDirectoryForIndexes Put indexes and data in different 141 directories142 --wiredTigerCollectionBlockCompressor arg (=snappy)143 block compression algorithm for 144 collection data [none|snappy|zlib]145 --wiredTigerIndexPrefixCompression arg (=1)146 use prefix compression on row-store 147 leaf pages启动服务示例:1 mongod --dbpath=/data/mongodata --logpath=/data/log/mongolog/mongodb.log --logappend --fork查看是否启动:1 netstat -tnlp | grep mongod2 tcp00 0.0.0.0:27017 0.0.0.0:* LISTEN17909/mongod以上可看出端口27017已经运行5、测试启动mongodb的shell: 1 [root@test ~]# mongo 2 MongoDB shell version: 3.2.1 3 connecting to: test 4 Server has startup warnings:5 2016-01-25T16:12:52.960+0800 I CONTROL[initandlisten] ** WARNING: You are running this process as the root user, which is not recommended. 6 2016-01-25T16:12:52.960+0800 I CONTROL[initandlisten]7 2016-01-25T16:12:52.960+0800 I CONTROL[initandlisten]8 2016-01-25T16:12:52.960+0800 I CONTROL[initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is "always". 9 2016-01-25T16:12:52.960+0800 I CONTROL[initandlisten] **We suggest setting it to "never"10 2016-01-25T16:12:52.960+0800 I CONTROL[initandlisten] 11 2016-01-25T16:12:52.960+0800 I CONTROL[initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is "always".12 2016-01-25T16:12:52.960+0800 I CONTROL[initandlisten] **We suggest setting it to "never"13 2016-01-25T16:12:52.960+0800 I CONTROL[initandlisten] 14 > help15 db.help()help on db methods16 db.mycoll.help() help on collection methods17 sh.help()sharding helpers18 rs.help()replica set helpers19 help admin administrative help20 help connect connecting to a db help21 help keyskey shortcuts22 help miscmisc things to know23 help mrmapreduce24 25 show dbs show database names26 show collections show collections in current database27 show users show users in current database28 show profile show most recent system.profile entries with time >= 1ms29 show logsshow the accessible logger names30 show log [name]prints out the last segment of log in memory, "global" is default31 use <db_name>set current database32 db.foo.find()list objects in collection foo33 db.foo.find( { a : 1 } ) list objects in foo where a == 134 it result of the last line evaluated; use to further iterate35 DBQuery.shellBatchSize = x set default number of items to display on shell36 exit quit the mongo shell37 > show dbs38 local0.000GB39 > 至此,MongoDB3.2.1安装完毕。 更多MongoDB相关教程见以下内容:CentOS 编译安装 MongoDB与mongoDB的php扩展 http://www.linuxidc.com/Linux/2012-02/53833.htmCentOS 6 使用 yum 安装MongoDB及服务器端配置 http://www.linuxidc.com/Linux/2012-08/68196.htmUbuntu 13.04下安装MongoDB2.4.3 http://www.linuxidc.com/Linux/2013-05/84227.htmMongoDB入门必读(概念与实战并重) http://www.linuxidc.com/Linux/2013-07/87105.htmUbunu 14.04下MongoDB的安装指南 http://www.linuxidc.com/Linux/2014-08/105364.htm《MongoDB 权威指南》(MongoDB: The Definitive Guide)英文文字版[PDF] http://www.linuxidc.com/Linux/2012-07/66735.htmNagios监控MongoDB分片集群服务实战 http://www.linuxidc.com/Linux/2014-10/107826.htm基于CentOS 6.5操作系统搭建MongoDB服务 http://www.linuxidc.com/Linux/2014-11/108900.htmMongoDB 的详细介绍:请点这里
MongoDB 的下载地址:请点这里本文永久更新链接地址