ubuntu安装mongodb及配置

本文指导您如何在Ubuntu系统中安装、配置并使用MongoDB数据库。从导入公钥到创建源列表文件,再到更新本地包数据库,直至安装MongoDB及验证其启动状态,每个步骤都详细阐述。此外,还提供了如何开始使用MongoDB的指引,并介绍了MongoDB的卸载过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

参考: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


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值