ITPub博客

首页 > 数据库 > NoSQL > MongoDB安装

MongoDB安装

原创 NoSQL 作者:jx_yu 时间:2015-01-12 16:59:01 0 删除 编辑

Mongodb安装

环境说明

OS:Red Hat Enterprise Linux Server release 6.1 (Santiago)

MongoDB: mongodb-linux-x86_64-2.6.6.tgz

DownLoad mogodb:http://www.mongodb.org/downloads

安装MongoDB

#解压

]# tar zxf mongodb-linux-x86_64-2.6.6.tgz

]# ls mongodb-linux-x86_64-2.6.6* -ld

drwxr-xr-x 3 root root      4096 1月  12 15:38 mongodb-linux-x86_64-2.6.6

-rw-r--r-- 1 root root 116039527 1月  12 10:18 mongodb-linux-x86_64-2.6.6.tgz

# mongodb不需要像别的数据库那样繁琐的配置,解压后放到惯例的/usr/local目录,当然可以放到任意位置

]# mv mongodb-linux-x86_64-2.6.6 /usr/local/mongodb

]# cd /usr/local/mongodb

]# ls

bin  GNU-AGPL-3.0  README  THIRD-PARTY-NOTICES

创建datadir和logdir

为mongodb创建数据库存放的位置和日志文件,默认是在/data/db下面

#这里我选择/data/mongodb/data|logs作为datadir和logdir

~]# mkdir -p /data/mongodb/data

~]# mkdir -p /data/mongodb/logs

MongoDB启动参数

#查看mongodb启动参数

~]# /usr/local/mongodb/bin/mongod --help

Options:

 

General options:

  -h [ --help ]               show this usage information

  --version                   show version information

  -f [ --config ] arg         configuration file specifying additional options

  -v [ --verbose ] [=arg(=v)] be more verbose (include multiple times for more

                              verbosity e.g. -vvvvv)

  --quiet                     quieter output

  --port arg                  specify port number - 27017 by default

  --bind_ip arg               comma separated list of ip addresses to listen on

                              - all local ips by default

  --maxConns arg              max number of simultaneous connections - 1000000

                              by default

  --logpath arg               log file to send write to instead of stdout - has

                              to be a file, not directory

  --syslog                    log to system's syslog facility instead of file

                              or stdout

  --syslogFacility arg        syslog facility used for monogdb syslog message

  --logappend                 append to logpath instead of over-writing

  --timeStampFormat arg       Desired format for timestamps in log messages.

                              One of ctime, iso8601-utc or iso8601-local

  --pidfilepath arg           full path to pidfile (if not set, no pidfile is

                              created)

  --keyFile arg               private key for cluster authentication

  --setParameter arg          Set a configurable parameter

  --httpinterface             enable http interface

  --clusterAuthMode arg       Authentication mode used for cluster

                              authentication. Alternatives are

                              (keyFile|sendKeyFile|sendX509|x509)

  --nounixsocket              disable listening on unix sockets

  --unixSocketPrefix arg      alternative directory for UNIX domain sockets

                              (defaults to /tmp)

  --fork                      fork server process

  --auth                      run with security

  --noauth                    run without security

  --ipv6                      enable IPv6 support (disabled by default)

  --jsonp                     allow JSONP access via http (has security

                              implications)

  --rest                      turn on simple rest api

  --slowms arg (=100)         value of slow for profile and console log

  --profile arg               0=off 1=slow, 2=all

  --cpu                       periodically show cpu and iowait utilization

  --sysinfo                   print some diagnostic system information

  --dbpath arg                directory for datafiles - defaults to /data/db

  --directoryperdb            each database will be stored in a separate

                              directory

  --noIndexBuildRetry         don't retry any index builds that were

                              interrupted by shutdown

  --noprealloc                disable data file preallocation - will often hurt

                              performance

  --nssize arg (=16)          .ns file size (in MB) for new databases

  --quota                     limits each database to a certain number of files

                              (8 default)

  --quotaFiles arg            number of files allowed per db, implies --quota

  --smallfiles                use a smaller default file size

  --syncdelay arg (=60)       seconds between disk syncs (0=never, but not

                              recommended)

  --upgrade                   upgrade db if needed

  --repair                    run repair on all dbs

  --repairpath arg            root directory for repair files - defaults to

                              dbpath

  --noscripting               disable scripting engine

  --notablescan               do not allow table scans

  --journal                   enable journaling

  --nojournal                 disable journaling (journaling is on by default

                              for 64 bit)

  --journalOptions arg        journal diagnostic options

  --journalCommitInterval arg how often to group/batch commit (ms)

  --shutdown                  kill a running server (for init scripts)

 

Replication options:

  --oplogSize arg       size to use (in MB) for replication op log. default is

                        5% of disk space (i.e. large is good)

 

Master/slave options (old; use replica sets instead):

  --master              master mode

  --slave               slave mode

  --source arg          when slave: specify master as

  --only arg            when slave: specify a single database to replicate

  --slavedelay arg      specify delay (in seconds) to be used when applying

                        master ops to slave

  --autoresync          automatically resync if slave data is stale

 

Replica set options:

  --replSet arg           arg is [/]

  --replIndexPrefetch arg specify index prefetching behavior (if secondary)

                          [none|_id_only|all]

 

Sharding options:

  --configsvr           declare this is a config db of a cluster; default port

                        27019; default dir /data/configdb

  --shardsvr            declare this is a shard db of a cluster; default port

                        27018

启动MongoDB

~]# /usr/local/mongodb/bin/mongod  --dbpath /data/mongodb/data --oplogSize 100 --logpath /data/mongodb/logs/mongodb.log --logappend --fork

about to fork child process, waiting until server is ready for connections.

forked process: 17937

child process started successfully, parent exiting

参数说明:

--dbpath                       指定存储mongodb的数据目录,默认/data/db

--oplogSize                  主节点的oplog大小(MB)

--logpath                       日志文件位置

--logappend                使用追加方式记录日志

--fork                               使用守护进程方式启动,放在后台

#查看mongodb日志

~]#tail -f /data/mongodb/logs/mongodb.log

客户端连接

~]# /usr/local/mongodb/bin/mongo

MongoDB shell version: 2.6.6

connecting to: test

> help

        db.help()                    help on db methods

        db.mycoll.help()             help on collection methods

        sh.help()                    sharding helpers

        rs.help()                    replica set helpers

        help admin                   administrative help

        help connect                 connecting to a db help

        help keys                    key shortcuts

        help misc                    misc things to know

        help mr                      mapreduce

 

        show dbs                     show database names

        show collections             show collections in current database

        show users                   show users in current database

        show profile                 show most recent system.profile entries with time >= 1ms

        show logs                    show the accessible logger names

        show log [name]              prints out the last segment of log in memory, 'global' is default

        use                 set current database

        db.foo.find()                list objects in collection foo

        db.foo.find( { a : 1 } )     list objects in foo where a == 1

        it                           result of the last line evaluated; use to further iterate

        DBQuery.shellBatchSize = x   set default number of items to display on shell

        exit                         quit the mongo shell

> show dbs

admin  (empty)

local  0.078GB

停止MongoDB

#方法一:kill pid

~]# ps -ef|grep mongod|grep -v grep

root     17937     1  0 15:54 ?        00:00:03 /usr/local/mongodb/bin/mongod --dbpath /data/mongodb/data --oplogSize 100 --logpath /data/mongodb/logs/mongodb.log --logappend --fork

~]# kill 17937

注:不能使用kill -9 pid来停止mongodb,这样会导致直接关闭,可能使数据文件摧毁

方法二:shutdown命令

~]# /usr/local/mongodb/bin/mongo

MongoDB shell version: 2.6.6

connecting to: test

> use admin

switched to db admin

> db.shutdownServer()

2015-01-12T16:31:59.746+0800 DBClientCursor::init call() failed

server should be down...

2015-01-12T16:31:59.749+0800 trying reconnect to 127.0.0.1:27017 (127.0.0.1) failed

2015-01-12T16:31:59.749+0800 warning: Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused

2015-01-12T16:31:59.749+0800 reconnect 127.0.0.1:27017 (127.0.0.1) failed failed couldn't connect to server 127.0.0.1:27017 (127.0.0.1), connection attempt failed

httpinterface

默认情况下MongoDB监听27017端口

还会启动一个基本的HTTP服务,HTTP的监听端口比MongoDB端口高1000,也就是27017;

但2.6.6版本发现,默认是关闭的,使用--httpinterface参数开启

之前的版本2.2.2默认是开启的,使用--nohttpinterface 关闭

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/27000195/viewspace-1399265/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: tcpkill安装
请登录后发表评论 登录
全部评论

注册时间:2012-05-23

  • 博文量
    80
  • 访问量
    876947