MongoDB入门(2)- MongoDB安装

windows安装

下载文件,解压缩即可。下载地址

每次运行mongod --dbpath D:/MongoDB/data 命令行来启动MongoDB实在是不方便,把它作为Windows服务,这样就方便多了。

D:\MongoDB\bin>mongod --logpath D:\MongoDB\logs\MongoDB.log --logappend --dbpath D:\MongoDB\data --directoryperdb --serviceName MongoDB --install
all output going to: D:\MongoDB\logs\MongoDB.log
Creating service MongoDB.
Service creation successful.
Service can be started from the command line via 'net start "MongoDB"'.

强调1:log一定要指定一个xxx.log文件(文件不存在也要这么写,会自动创建,写成这样是不可以的--logpath d:\mongodb\logs)

2:注意:logs文件夹和data文件夹要先新建好;serviceName的N字母要大写

该命令行指定了日志文件:D:\MongoDB\logs\MongoDB.log,日志是以追加的方式输出的;

数据文件目录:D:\MongoDB\data,并且参数--directoryperdb说明每个DB都会新建一个目录;

Windows服务的名称:MongoDB;

以上的三个参数都是可以根据自己的情况而定的,呵呵。

最后是安装参数:--install,与之相对的是--remove

启动MongoDB:net start MongoDB

停止MongoDB:net stop MongoDB

(突然停电等情况容易造成Mongo服务出错,可以先删除data目录下的log和lock文件然后重新启动服务)

Linux安装

1. Configure the package management system (YUM)

Create a /etc/yum.repos.d/mongodb.repo file to hold the following configuration information for the MongoDB repository:

If you are running a 64-bit system, use the following configuration:

[mongodb]
name=MongoDB Repository
baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64/
gpgcheck=0
enabled=1

If you are running a 32-bit system, which is not recommended for production deployments, use the following configuration:

[mongodb]
name=MongoDB Repository
baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/i686/
gpgcheck=0
enabled=1

2. Install the MongoDB packages and associated tools.

To install the latest stable version of MongoDB, issue the following command:

sudo yum install -y mongodb-org

3. Start MongoDB

sudo service mongod start

You can optionally ensure that MongoDB will start following a system reboot by issuing the following command:

sudo chkconfig mongod on

4. Stop MongoDB

sudo service mongod stop

5. Restart MongoDB

sudo service mongod restart

6.modify /etc/mongo.conf

change
bind_ip=127.0.0.1
to
bind_ip=0.0.0.0
posted @ 2016-08-23 14:41  wardensky  阅读(238)  评论(0编辑  收藏  举报