Mongodb 安装配置,启动关闭

待我称王封你为后i 2022-08-12 01:17 349阅读 0赞

Mongodb安装配置,启动关闭

  1. 下载mongodb的安装文件,我安装的windows 32位的,下载地址如下:

http://www.mongodb.org/dr//fastdl.mongodb.org/win32/mongodb-win32-i386-2.6.4.zip/download

  1. 新建一个mongodb文件夹在E盘(随便放)

E:\mongodb

  1. 将下载的文件安装文件解压,把解压的文件移动到E盘mongodb下

  2. 建立mongodb数据存放目录E:\mongodb\data

  3. 启动mongodb(简单启动不配置服务)

E:\mongodb\bin\mongod.exe —dbpath E:\mongodb\data

E:\mongodb\bin>mongod.exe —dbpath E:\mongodb\data

2014-09-13T22:18:50.640+0800

2014-09-13T22:18:50.640+0800 warning: 32-bit servers don’t have journaling enabled by default. Please use —journal if you want durability.

2014-09-13T22:18:50.640+0800

2014-09-13T22:18:50.765+0800 [initandlisten] MongoDB starting : pid=9204 port=27

017 dbpath=E:\mongodb\data 32-bit host=20120621-1418

2014-09-13T22:18:50.765+0800 [initandlisten]

2014-09-13T22:18:50.765+0800 [initandlisten] ** NOTE: This is a 32 bit MongoDB binary.

2014-09-13T22:18:50.765+0800 [initandlisten] ** 32 bit builds are limitedto less than 2GB of data (or less with —journal).

2014-09-13T22:18:50.765+0800 [initandlisten] ** Note that journaling defaults to off for 32 bit and is currently off.

2014-09-13T22:18:50.765+0800 [initandlisten] ** See http://dochub.mongodb.org/core/32bit

2014-09-13T22:18:50.765+0800 [initandlisten]

2014-09-13T22:18:50.765+0800 [initandlisten] ** NOTE: your operating system version does not support the method that MongoDB

2014-09-13T22:18:50.765+0800 [initandlisten] ** uses to detect impending page faults.

2014-09-13T22:18:50.765+0800 [initandlisten] ** This may result in slowerperformance for certain use cases

2014-09-13T22:18:50.765+0800 [initandlisten]

2014-09-13T22:18:50.765+0800 [initandlisten] targetMinOS: Windows XP SP3

2014-09-13T22:18:50.765+0800 [initandlisten] db version v2.6.4

2014-09-13T22:18:50.765+0800 [initandlisten] git version: 3a830be0eb92d772aa855ebb711ac91d658ee910

2014-09-13T22:18:50.765+0800 [initandlisten] build info: windows sys.getwindowsversion(major=6, minor=1, build=7601, platform=2, service_pack=’Service Pack 1’BOOST_LIB_VERSION=1_49

2014-09-13T22:18:50.765+0800 [initandlisten] allocator: system

2014-09-13T22:18:50.765+0800 [initandlisten] options: { storage: { dbPath: “E:\mongodb\data” } }

在浏览器中输入http://localhost:27017/,会出现表面mongdb已经启动好了

  1. It looks like you are trying to access MongoDB over HTTP on the native driver port.
  1. 启动好后连接到mongodb

E:\mongodb\bin\mongo.ext

E:\mongodb\bin>mongo

MongoDB shell version: 2.6.4

connecting to: test

Welcome to the MongoDB shell.

For interactive help, type “help”.

For more comprehensive documentation, see

  1. http://docs.mongodb.org/

Questions? Try the support group

  1. http://groups.google.com/group/mongodb-user

Server has startup warnings:

2014-09-13T22:18:50.765+0800 [initandlisten]

2014-09-13T22:18:50.765+0800 [initandlisten] ** NOTE: This is a 32 bit MongoDB binary.

2014-09-13T22:18:50.765+0800 [initandlisten] ** 32 bit builds are limitedto less than 2GB of data (or less with —journal).

2014-09-13T22:18:50.765+0800 [initandlisten] ** Note that journaling defaults to off for 32 bit and is currently off.

2014-09-13T22:18:50.765+0800 [initandlisten] ** See http://dochub.mongodb.org/core/32bit

2014-09-13T22:18:50.765+0800 [initandlisten]

2014-09-13T22:18:50.765+0800 [initandlisten] ** NOTE: your operating system version does not support the method that MongoDB

2014-09-13T22:18:50.765+0800 [initandlisten] ** uses to detect impending page faults.

2014-09-13T22:18:50.765+0800 [initandlisten] ** This may result in slowerperformance for certain use cases

2014-09-13T22:18:50.765+0800 [initandlisten]

Mongodb的关闭:

前台运行:

如果没有使用--fork,直接可以前台退出终端关闭。通过这种方式,Mongodb将会自己做清理退出,把没有写好的数据写完成,并最终关闭数据文件。要注意的是这个过程会持续到所有操作都完成。

后台运行:

如果使用--fork在后台运行mongdb服务,那么就要通过向服务器发送shutdownServer()消息来关闭。

1、普通命令:

$ ./mongod

use admin

db.shutdownServer()

db.shutdownServer()

2014-09-13T22:25:07.843+0800 DBClientCursor::init call() failed

server should be down…

2014-09-13T22:25:07.890+0800 trying reconnect to 127.0.0.1:27017 (127.0.0.1) failed

2014-09-13T22:25:08.890+0800 warning: Failed to connect to 127.0.0.1:27017, reas

on: errno:10061由于目标机器积极拒绝,无法连接。

2014-09-13T22:25:08.890+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

控制台显示如下:

2014-09-13T22:25:07.625+0800 [conn1] terminating, shutdown command received

2014-09-13T22:25:07.625+0800 [conn1] dbexit: shutdown called

2014-09-13T22:25:07.625+0800 [conn1] shutdown: going to close listening sockets.

..

2014-09-13T22:25:07.625+0800 [conn1] closing listening socket: 1632

2014-09-13T22:25:07.625+0800 [conn1] shutdown: going to flush diaglog…

2014-09-13T22:25:07.625+0800 [conn1] shutdown: going to close sockets…

2014-09-13T22:25:07.625+0800 [conn1] shutdown: waiting for fs preallocator…

2014-09-13T22:25:07.625+0800 [conn1] shutdown: closing all files…

2014-09-13T22:25:07.625+0800 [conn1] closeAllFiles() finished

2014-09-13T22:25:07.625+0800 [conn1] shutdown: removing fs lock…

2014-09-13T22:25:07.625+0800 [conn1] dbexit: really exiting now

E:\mongodb\bin>

关闭成功

Mongodb启动帮助

E:\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

  1. 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

  1. - all local ips by default

—maxConns arg max number of simultaneous connections - 1000000

  1. by default

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

  1. to be a file, not directory

—logappend append to logpath instead of over-writing

—timeStampFormat arg Desired format for timestamps in log messages.

  1. One of ctime, iso8601-utc or iso8601-local

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

  1. 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

  1. authentication. Alternatives are
  2. (keyFile|sendKeyFile|sendX509|x509)

—auth run with security

—noauth run without security

—ipv6 enable IPv6 support (disabled by default)

—jsonp allow JSONP access via http (has security

  1. 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

  1. directory

—noIndexBuildRetry don’t retry any index builds that were

  1. interrupted by shutdown

—noprealloc disable data file preallocation - will often hurt

  1. performance

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

—quota limits each database to a certain number of files

  1. (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

  1. recommended)

—upgrade upgrade db if needed

—repair run repair on all dbs

—repairpath arg root directory for repair files - defaults to

  1. dbpath

—noscripting disable scripting engine

—notablescan do not allow table scans

—journal enable journaling

—nojournal disable journaling (journaling is on by default

  1. for 64 bit)

—journalOptions arg journal diagnostic options

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

Windows Service Control Manager options:

—install install Windows service

—remove remove Windows service

—reinstall reinstall Windows service (equivalent to —remove

  1. followed by --install)

—serviceName arg Windows service name

—serviceDisplayName arg Windows service display name

—serviceDescription arg Windows service description

—serviceUser arg account for service execution

—servicePassword arg password used to authenticate serviceUser

Replication options:

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

  1. 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

  1. 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)

  1. \[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

下面通过构造一个conf文件进行启动

文件内容如下mongodb.conf

dbpath=E:\mongodb\data

logpath=E:\mongodb\log

logappend=true

bind_ip=127.0.0.1

port=27019

fork=true

master=true

启动:

E:\mongodb\bin>mongod —config E:\mongodb\mongodb.conf

2014-09-13T22:39:31.296+0800

2014-09-13T22:39:31.296+0800 warning: 32-bit servers don’t have journaling enabl

ed by default. Please use —journal if you want durability.

2014-09-13T22:39:31.296+0800

连接mongodb报错,原因我启动时指定端口号了,不是默认的27017了,所以报错

E:\mongodb\bin>mongo

MongoDB shell version: 2.6.4

connecting to: test

2014-09-13T22:50:24.296+0800 warning: Failed to connect to 127.0.0.1:27017, rea

on: errno:10061由于目标机器积极拒绝,无法连接。

2014-09-13T22:50:24.312+0800 Error: couldn’t connect to server 127.0.0.1:27017

127.0.0.1), connection attempt failed at src/mongo/shell/mongo.js:146

exception: connect failed

指定端口号连接:

E:\mongodb\bin>mongo 127.0.0.1:27019

MongoDB shell version: 2.6.4

connecting to: 127.0.0.1:27019/test

Server has startup warnings:

2014-09-13T22:50:13.593+0800 [initandlisten]

2014-09-13T22:50:13.593+0800 [initandlisten] ** NOTE: This is a 32 bit MongoDB b

inary.

2014-09-13T22:50:13.593+0800 [initandlisten] ** 32 bit builds are limited

to less than 2GB of data (or less with —journal).

2014-09-13T22:50:13.593+0800 [initandlisten] ** Note that journaling defaults to off for 32 bit and is currently off.

2014-09-13T22:50:13.593+0800 [initandlisten] ** See http://dochub.mongodb.org/core/32bit

2014-09-13T22:50:13.593+0800 [initandlisten]

2014-09-13T22:50:13.593+0800 [initandlisten] ** NOTE: your operating system version does not support the method that MongoDB

2014-09-13T22:50:13.593+0800 [initandlisten] ** uses to detect impending page faults.

2014-09-13T22:50:13.593+0800 [initandlisten] ** This may result in slowerperformance for certain use cases

2014-09-13T22:50:13.593+0800 [initandlisten]

发表评论

表情:
评论列表 (有 0 条评论,349人围观)

还没有评论,来说两句吧...

相关阅读