CentOS6.5上源码安装MongoDB3.2.1

1、环境准备:

1mkdir /home/mongodb           #创建MongoDB程序存放目录
2mkdir /data/mongodata -p      #创建数据存放目录
3mkdir /data/log/mongolog -p   #创建日志存放目录

2、下载:

1 curl -O https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.2.1.tgz

3、安装:

1tar xf mongodb-linux-x86_64-3.2.1.tgz
2 cd mongodb-linux-x86_64-3.2.13cp -r * /home/mongodb

为了便于命令启动,需要编辑全局变量PATH

1 vim /etc/profile.d/mongo.sh2 export PATH=$PATH:/home/mongodb/bin
source /etc/profile.d/mongo.sh

4、启动服务

首先查看mongod的帮助信息

  1 [root@test ~]# mongod --help
  2Options:
  3  4General options:
  5   -h [ --help ]                         show this usage information
  6   --version                             show version information
  7   -f [ --config ] arg                   configuration file specifying 
  8                                        additional options
  9   -v [ --verbose ] [=arg(=v)]           be more verbose (include multiple times
 10formore verbosity e.g. -vvvvv)
 11   --quiet                               quieter output
 12--port arg                            #指定mongodb服务的端口号,默认为:27017 
 13--bind_ip arg#在多网卡的机器上指定mongodb服务绑定到哪一个ip上 
 15   --ipv6                                enable IPv6 support (disabled by 
 16                                        default)
 17 --maxConns arg#指定最大客户端连接数 
 19--logpath arg#指定日志文件路径,必须是一个文件,而不是目录 
 20   --syslog                              log to system's syslog facility instead 23                                         of file or stdout
 24   --syslogFacility arg                  syslog facility used for mongodb syslog
 25                                        message
 26 --logappend#以追加的方式打印日志到--logpath参数指定的日志文件中 
 28   --logRotate arg                       set the log rotation behavior 
 29                                         (rename|reopen)
 30   --timeStampFormat arg                 Desired format for timestamps in log 
 31                                         messages. One of ctime, iso8601-utc or 
 32                                         iso8601-local
 33   --pidfilepath arg                     full path to pidfile (if not set, no 
 34                                        pidfile is created)
 35   --keyFile arg                         private key for cluster authentication
 36   --setParameter arg                    Set a configurable parameter
 37   --httpinterface                       enable http interface
 38   --clusterAuthMode arg                 Authentication mode used for cluster 
 39                                        authentication. Alternatives are 
 40                                         (keyFile|sendKeyFile|sendX509|x509)
 41   --nounixsocket                        disable listening on unix sockets
 42   --unixSocketPrefix arg                alternative directory for UNIX domain 
 43                                         sockets (defaults to /tmp)
 44   --filePermissions arg                 permissions to set on UNIX domain 
 45                                         socket file - 0700 by default
 46--fork                                #以daemon的形式运行服务进程
 47   --auth                                run with security
 48   --noauth                              run without security
 49   --jsonp                               allow JSONP access via http (has 
 50                                        security implications)
 51   --rest                                turn on simple rest api
 52   --slowms arg (=100)                   value of slow for profile and console 
 53                                        log
 54   --profile arg                         0=off 1=slow, 2=all
 55   --cpu                                 periodically show cpu and iowait 
 56                                        utilization
 57   --sysinfo                             print some diagnostic system 
 58                                        information
 59   --noIndexBuildRetry                   don't retry any index builds that were  60                                        interrupted by shutdown
 61   --noscripting                         disable scripting engine
 62   --notablescan                         do not allow table scans
 63   --shutdown                            kill a running server (for init 
 64                                        scripts)
 65 66Replication options:
 67   --oplogSize arg                       size to use (in MB) for replication op 
 68                                         log. default is 5% of disk space (i.e. 
 69                                        large is good)
 70 71 Master/slave options (old; use replica sets instead):
 72   --master                              master mode
 73   --slave                               slave mode
 74   --source arg                          when slave: specify master as 
 75                                         <server:port>
 76   --only arg                            when slave: specify a single database 
 77                                        to replicate
 78   --slavedelay arg                      specify delay (in seconds) to be used 
 79                                        when applying master ops to slave
 80   --autoresync                          automatically resync if slave data is 
 81                                        stale
 82 83Replica set options:
 84   --replSet arg                         arg is <setname>[/<optionalseedhostlist
 85                                         >]
 86   --replIndexPrefetch arg               specify index prefetching behavior (if 87                                         secondary) [none|_id_only|all]
 88   --enableMajorityReadConcern           enables majority readConcern
 89 90Sharding options:
 91   --configsvr                           declare this is a config db of a 
 92                                         cluster; default port 27019; default 
 93dir /data/configdb
 94   --configsvrMode arg                   Controls what config server protocol is
 95in use. When set to "sccc" keeps server
 96in legacy SyncClusterConnection mode 
 97                                        even when the service is running as a 
 98                                        replSet
 99   --shardsvr                            declare this is a shard db of a 
100                                         cluster; default port 27018101102Storage options:
103   --storageEngine arg                   what storage engine to use - defaults 
104                                         to wiredTiger if no data files present
105--dbpath arg                          #指定数据目录路径
107   --directoryperdb                      each database will be stored in a 
108                                        separate directory
109   --noprealloc                          disable data file preallocation - will 
110                                        often hurt performance
111   --nssize arg (=16)                    .ns file size (in MB) for new databases
112   --quota                               limits each database to a certain 
113                                         number of files (8 default)
114   --quotaFiles arg                      number of files allowed per db, implies
115                                         --quota
116   --smallfiles                          use a smaller default file size
117   --syncdelay arg (=60)                 seconds between disk syncs (0=never, 
118                                        but not recommended)
119   --upgrade                             upgrade db if needed
120   --repair                              run repair on all dbs
121   --repairpath arg                      root directory for repair files - 
122                                        defaults to dbpath
123   --journal                             enable journaling
124   --nojournal                           disable journaling (journaling is on by
125                                         default for64 bit)
126   --journalOptions arg                  journal diagnostic options
127   --journalCommitInterval arg           how often to group/batch commit (ms)
128129WiredTiger options:
130   --wiredTigerCacheSizeGB arg           maximum amount of memory to allocate 
131for cache; defaults to 1/2 of physical 
132                                        RAM
133   --wiredTigerStatisticsLogDelaySecs arg (=0)
134                                         seconds to wait between each write to a
135                                         statistics filein the dbpath; 0 means 
136do not log statistics
137   --wiredTigerJournalCompressor arg (=snappy)
138                                         use a compressor for log records 
139                                         [none|snappy|zlib]
140   --wiredTigerDirectoryForIndexes       Put indexes and data in different 
141                                        directories
142   --wiredTigerCollectionBlockCompressor arg (=snappy)
143                                         block compression algorithm for144                                         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 mongod
2 tcp        000.0.0.0:270170.0.0.0:*                   LISTEN      17909/mongod

以上可看出端口27017已经运行

5、测试

启动mongodb的shell:

 1 [root@test ~]# mongo
 2 MongoDB shell version: 3.2.1 3connecting to: test
 4Server has startup warnings: 
 52016-01-25T16:12:52.960+0800 I CONTROL  [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
 62016-01-25T16:12:52.960+0800 I CONTROL  [initandlisten] 
 72016-01-25T16:12:52.960+0800 I CONTROL  [initandlisten] 
 82016-01-25T16:12:52.960+0800 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
 92016-01-25T16:12:52.960+0800 I CONTROL  [initandlisten] **        We suggest setting it to 'never'102016-01-25T16:12:52.960+0800 I CONTROL  [initandlisten] 
112016-01-25T16:12:52.960+0800 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
122016-01-25T16:12:52.960+0800 I CONTROL  [initandlisten] **        We suggest setting it to 'never'132016-01-25T16:12:52.960+0800 I CONTROL  [initandlisten] 
14 > help
15    db.help()                    help on db methods
16    db.mycoll.help()             help on collection methods
17sh.help()                    sharding helpers
18    rs.help()                    replica set helpers
19    help admin                   administrative help
20    help connect                 connecting to a db help
21    help keys                    key shortcuts
22    help misc                    misc things to know
23    help mr                      mapreduce
2425    show dbs                     show database names
26     show collections             show collections in current database
27     show users                   show users in current database
28     show profile                 show most recent system.profile entries with time >= 1ms
29    show logs                    show the accessible logger names
30     show log [name]              prints out the last segment of log in memory, 'global' is default
31     use <db_name>                set current database
32     db.foo.find()                list objects in collection foo
33     db.foo.find( { a : 1 } )     list objects in foo where a == 134     it                           result of the last line evaluated; use to further iterate
35     DBQuery.shellBatchSize = x   set default number of items to display on shell
36    exit                         quit the mongo shell
37 > show dbs
38 local  0.000GB
39 > 

至此,MongoDB3.2.1安装完毕。

 

文章来源网络,作者:管理,如若转载,请注明出处:https://shuyeidc.com/wp/220995.html<

(0)
管理的头像管理
上一篇2025-04-14 20:08
下一篇 2025-04-14 20:09

相关推荐

  • 站群服务器和普通服务器到底哪个更适合GEO,怎么选?

    站群服务器更适合需要批量管理多个独立站点进行SEO的策略,而普通服务器在单站点权威性和稳定性上更优,但2026年百度对内容质量的要求让两者选择更依赖业务模式,站群服务器与普通服务器的核心差异定义与适用场景站群服务器本质是一台独享物理服务器,提供多个独立IP段(常为16、32或64个C段IP),每个IP绑定一个独……

    2026-07-28
    0
  • 物理服务器和云服务器做站群到底选哪个,哪个更稳定?

    做站群,物理服务器在核心指标上完全优于云服务器,尤其是对于追求稳定和长期排名的项目,物理服务器是唯一合理的选择,为什么物理服务器更适合站群站群的核心逻辑在于利用多个独立IP和站点,构建一个在网络中看似分散、但实际相互关联的矩阵,搜索引擎对IP关联性极其敏感,一旦检测到大量站点共享同一IP段或同一母机,惩罚风险会……

    2026-07-28
    0
  • 国内高防服务器哪家防御真实靠谱,怎么选?

    国内高防服务器哪家防御真实靠谱?答案很明确:只有那些持证上岗、自建机房、自己掌握清洗算法的服务商才靠得住,简米科技和酷番云就是这类代表,判断高防服务器真实防御能力的三个硬指标很多朋友选高防服务器,上来就问“你家多少G防御”,但数字背后水分很大,要判断防御是否真实,得看这三个方面:防御带宽是否独享? 有些服务商宣……

    2026-07-28
    0
  • 裸金属服务器和物理服务器有什么区别?,怎么选?

    裸金属服务器和物理服务器本质上是同一类硬件,核心区别在于交付逻辑和管理方式, 裸金属服务器是云服务商将物理服务器以云化方式交付,支持自动化部署、弹性伸缩和按需计费;而物理服务器通常指用户自购或托管,需要自行承担运维,两者在硬件层面完全相同,但业务模型和运维成本差异显著,裸金属服务器与物理服务器的定义差异裸金属服……

    2026-07-28
    0
  • 做GEO站群选哪家服务器服务商靠谱,怎么选?

    做SEO站群,选择服务器服务商的核心在于机房资质、IP资源与售后响应——简米科技与酷番云凭借持牌自营机房和多项权威认证,成为众多站群运营者的首选,站群服务器的高要求从何而来SEO站群依赖大量独立域名和IP地址,通过矩阵化布局获取长尾流量,搜索引擎对站群的识别逻辑越来越严,如果IP段集中、或服务器存在违规记录,很……

    2026-07-28
    0

发表回复

您的邮箱地址不会被公开。必填项已用 * 标注