1、在www.mongdb.org 上下载最新版本的mongodb安装包.(选择合适的安装包).
2、解压安装包:tar -zvxf mongodb-linux-x86_64-rhel70-3.0.7.tgz (可执行文件在bin目录下)
备注:
# bsondump 读取BSON格式的会滚文件的内容. # mongo 数据库shell. # mongod 核心数据库服务. # mongodump 数据库备份工具. # mongoexport 导出工具(JSON、CSV、TSV),不可靠的备份. # mongofiles 操作GridFS对象中的文件. # mongoimport 导入工具(JSON、CSV、TSV),不可靠的恢复. # mongooplog 从另一个mongod实例中更新oplog条目. # mongoperf 检查磁盘I/O性能. # mongorestore 数据库备份恢复工具. # mongos 数据库分片进程. # mongosniff 实时嗅探/跟踪MongoDB数据库的活动,只在类UNIX系统中可用. # mongostat 返回数据库操作的内容. # mongotop 跟踪/报告MongoDB的读/写活动.
3、移动解压文件到/usr/local/mongodb 目录下. mv mongodb-linux-x86_64-rhel70-3.0.7 /usr/local/mongodb
4、到该目录下新建 ./data/db 、./logs 目录. mkdir -p ./data/db ; ./logs
5、到/usr/bin 目录下创建各个可执行文件的软连接. ln -s /usr/local/mongodb/bin/mongod /usr/bin/mongod 等等. (方便随时启动,可通过配置文件,见下方.)
6、启动mongod和mongos时使用配置文件,通过--config或者-f选项指定配置文件 ,具体可参照 mongod -h 查看各个参数的使用,以及官方配置文档
例:
mongod --config /etc/mongod.conf //--config可以用-f替代
mongos --config /etc/mongos.conf
注意:Mongodb的配置文件使用YAML格式。 (YAML不接受tab,可用空格代替)
此处为可配置内容:引用自3.0 配置文件相关介绍
#此处为配置文件可配置的内容 #Mongod config file #MongoDB configuration files use the YAML format. #The following example configuration file contains several mongod settings. # ########Example Start######## #systemLog: # destination: file # path: "/var/log/mongodb/mongodb.log" # logAppend: true #storage: # journal: # enabled: true #processManagement: # fork: true #net: # bindIp: 127.0.0.1 # port: 27017 #setParameter: # enableLocalhostAuthBypass: false # ########Example End######## # ########Core Options systemLog: # verbosity: 0 #Default: 0; 1 to 5 increases the verbosity level to include Debug messages. # quiet: <boolean> # traceAllException: <boolean> # syslogFacility: user path: "/usr/local/mongodb/logs/mongod.log" logAppend: true # logRotate: <string> #rename or reopen destination: file # timeStampFormat: iso8601-local # component: # accessControl: # verbosity: 0 # command: # verbosity: 0 # # COMMENT additional component verbosity settings omitted for brevity # storage: # verbosity: 0 # journal: # verbosity: <int> # write: # verbosity: 0 # # ########ProcessManagement Options processManagement: fork: true pidFilePath: "/usr/local/mongodb/logs/mongod.pid" # # #########Net Options net: port: 27017 # bindIp: <string> #Default All interfaces. # maxIncomingConnections: 65536 # wireObjectCheck: true # ipv6: false # unixDomainSocket: # enabled: true # pathPrefix: "/tmp" # filePermissions: 0700 # http: # enabled: false # JSONPEnabled: false # RESTInterfaceEnabled: false # ssl: # sslOnNormalPorts: <boolean> # deprecated since 2.6 # mode: <string> # PEMKeyFile: <string> # PEMKeyPassword: <string> # clusterFile: <string> # clusterPassword: <string> # CAFile: <string> # CRLFile: <string> # allowConnectionsWithoutCertificates: <boolean> # allowInvalidCertificates: <boolean> # allowInvalidHostnames: false # FIPSMode: <boolean> # # ########security Options #security: # keyFile: <string> # clusterAuthMode: keyFile # authorization: disable # javascriptEnabled: true ########security.sasl Options # sasl: # hostName: <string> # serviceName: <string> # saslauthdSocketPath: <string> # # #########setParameter Option setParameter: enableLocalhostAuthBypass: false # <parameter1>: <value1> # <parameter2>: <value2> # # #########storage Options storage: dbPath: "/usr/local/mongodb/data/db" # indexBuildRetry: true # repairPath: "/data/db/_tmp" # journal: # enabled: true # directoryPerDB: false # syncPeriodSecs: 60 engine: "mmapv1" #Valid options include mmapv1 and wiredTiger. #########storage.mmapv1 Options # mmapv1: # preallocDataFiles: true # nsSize: 16 # quota: # enforced: false # maxFilesPerDB: 8 # smallFiles: false # journal: # debugFlags: <int> # commitIntervalMs: 100 # 100 or 30 #########storage.wiredTiger Options # wiredTiger: # engineConfig: # cacheSizeGB: <number> #Default: the maximum of half of physical RAM or 1 gigabyte # statisticsLogDelaySecs: 0 # journalCompressor: "snappy" # directoryForIndexes: false # collectionConfig: # blockCompressor: "snappy" # indexConfig: # prefixCompression: true # # ##########operationProfiling Options #operationProfiling: # slowOpThresholdMs: 100 # mode: "off" # # ##########replication Options #replication: # oplogSizeMB: <int> # replSetName: <string> # secondaryIndexPrefetch: all # # ##########sharding Options #sharding: # clusterRole: <string> #configsvr or shardsvr # archiveMovedChunks: True # # #########auditLog Options #auditLog: # destination: <string> #syslog/console/file # format: <string> #JSON/BSON # path: <string> # filter: <string> # # #########snmp Options #snmp: # subagent: <boolean> # master: <boolean> # # ########mongos-only Options #replication: # localPingThresholdMs: 15 # #sharding: # autoSplit: true # configDB: <string> # chunkSize: 64 # # ########Windows Service Options #processManagement: # windowsService: # serviceName: <string> # displayName: <string> # description: <string> # serviceUser: <string> # servicePassword: <string>
安装成功:
[root@localhost bin]# mongod -f ./mongo mongo mongod.conf mongoexport mongoimport mongoperf mongos mongotop mongod mongodump mongofiles mongooplog mongorestore mongostat [root@localhost bin]# mongod -f ./mongod.conf about to fork child process, waiting until server is ready for connections. forked process: 103070 child process started successfully, parent exiting [root@localhost bin]# mongo MongoDB shell version: 3.0.7 connecting to: test Welcome to the MongoDB shell. For interactive help, type "help". For more comprehensive documentation, see http://docs.mongodb.org/ Questions? Try the support group http://groups.google.com/group/mongodb-user Server has startup warnings: 2015-11-17T19:54:21.808+0800 I STORAGE [initandlisten] 2015-11-17T19:54:21.808+0800 I STORAGE [initandlisten] ** WARNING: Readahead for /usr/local/mongodb/data/db is set to 4096KB 2015-11-17T19:54:21.808+0800 I STORAGE [initandlisten] ** We suggest setting it to 256KB (512 sectors) or less 2015-11-17T19:54:21.808+0800 I STORAGE [initandlisten] ** http://dochub.mongodb.org/core/readahead 2015-11-17T19:54:21.986+0800 I CONTROL [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended. 2015-11-17T19:54:21.986+0800 I CONTROL [initandlisten] 2015-11-17T19:54:21.986+0800 I CONTROL [initandlisten] 2015-11-17T19:54:21.986+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'. 2015-11-17T19:54:21.986+0800 I CONTROL [initandlisten] ** We suggest setting it to 'never' 2015-11-17T19:54:22.006+0800 I CONTROL [initandlisten] 2015-11-17T19:54:22.006+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'. 2015-11-17T19:54:22.006+0800 I CONTROL [initandlisten] ** We suggest setting it to 'never' 2015-11-17T19:54:22.006+0800 I CONTROL [initandlisten] > exit
bye
2015年11月17日19:55:55