您的位置:首页 > 数据库 > Mongodb

ubuntu安装mongodb及配置

2015-12-18 16:45 645 查看
参考:https://docs.mongodb.org/v3.0/tutorial/install-mongodb-on-ubuntu/

安装:

Import the public key used by the package management system.

The Ubuntu package management tools (i.e. dpkg and
apt) ensurepackage consistency and authenticity by requiring that distributorssign packages with GPG keys. Issue the following command to import theMongoDB
public GPG Key:

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10


Create a list file for MongoDB.

Create the /etc/apt/sources.list.d/mongodb-org-3.0.list list file usingthe command appropriate for your version of Ubuntu:

Ubuntu 12.04

echo "deb http://repo.mongodb.org/apt/ubuntu precise/mongodb-org/3.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.0.list

Ubuntu 14.04

echo "deb http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.0.list


Reload local package database.

Issue the following command to reload the local package database:

sudo apt-get update


Install the MongoDB packages.

You can install either the latest stable version of MongoDB or aspecific version of MongoDB.

Install the latest stable version of MongoDB.

Issue the following command:

sudo apt-get install -y mongodb-org


Install a specific release of MongoDB.

To install a specific release, you must specify each component packageindividually along with the version number, as in thefollowing example:

sudo apt-get install -y mongodb-org=3.0.8 mongodb-org-server=3.0.8 mongodb-org-shell=3.0.8 mongodb-org-mongos=3.0.8 mongodb-org-tools=3.0.8

运行:

Start MongoDB.

Issue the following command to start
mongod:

sudo service mongod start


Verify that MongoDB has started successfully

Verify that the
mongod process has started successfully bychecking the contents of the log file at/var/log/mongodb/mongod.logfor
a line reading

[initandlisten] waiting for connections on port <port>


where <port> is the port configured in
/etc/mongod.conf,
27017 by default.

3

Stop MongoDB.

As needed, you can stop the
mongod process by issuing thefollowing command:

sudo service mongod stop


Restart MongoDB.

Issue the following command to restart
mongod:

sudo service mongod restart


5

Begin using MongoDB.

To help you start using MongoDB, MongoDB provides
GettingStarted Guides in various driver editions. SeeGetting Started for the available editions.

Before deploying MongoDB in a production environment, consider theProduction Notes document.

Later, to stop MongoDB, press Control+C in the terminal where themongod
instance is running.

Uninstall MongoDB

To completely remove MongoDB from a system, you must remove the MongoDBapplications themselves, the configuration files, and any directories containingdata and logs. The following section guides you through the necessary steps.

Warning
This process will completely remove MongoDB, its configuration, and
alldatabases. This process is not reversible, so ensure that all of yourconfiguration and data is backed up before proceeding.

1

Stop MongoDB.

Stop the
mongod process by issuing the following command:

sudo service mongod stop


2

Remove Packages.

Remove any MongoDB packages that you had previously installed.

sudo apt-get purge mongodb-org*


3

Remove Data Directories.

Remove MongoDB databases and log files.

sudo rm -r /var/log/mongodb
sudo rm -r /var/lib/mongodb


设置

编辑:/etc/mongod.conf

# mongod.conf

# for documentation of all options, see:

#   http://docs.mongodb.org/manual/reference/configuration-options/
# Where and how to store data.

storage:

  dbPath: /var/lib/mongodb

  journal:

    enabled: true

#  engine:

#  mmapv1:

#  wiredTiger:

# where to write logging data.

systemLog:

  destination: file

  logAppend: true

  path: /var/log/mongodb/mongod.log

# network interfaces

net:

  port: 27017

  bindIp: 127.0.0.1

#processManagement:

#security:

#operationProfiling:

#replication:

#sharding:

## Enterprise-Only Options:

#auditLog:

#snmp:

设置用户名密码:

use products
db.createUser( { "user" : "accountAdmin01",
"pwd": "cleartext password",
"customData" : { employeeId: 12345 },
"roles" : [ { role: "clusterAdmin", db: "admin" },
{ role: "readAnyDatabase", db: "admin" },
"readWrite"
] },
{ w: "majority" , wtimeout: 5000 } )


运行mongo命令: ./usr/bin/mongod -f /etc/mongod.conf --auth --fork
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: