小试MongoDB之MongoDB安装

本文涉及的产品
云数据库 MongoDB,独享型 2核8GB
推荐场景:
构建全方位客户视图
简介: Install MongoDB on RedHat Enterprise,CentOS, or Fedora Linux Package Options The 10gen repository contains four packages: mongo-10gen(这个包...
Install MongoDB on RedHat Enterprise ,CentOS, or Fedora Linux
Package Options

The 10gen repository contains four packages:

  • mongo-10gen(这个包是最新版本包)

    This package contains MongoDB tools from latest stable release. Install this package on all production MongoDB hosts and optionally on other systems from which you may need to administer MongoDB systems.

  • mongo-10gen-server(这个包是最新版本包)

    This package contains the mongod and mongos daemons from the latest stable release and associated configuration and init scripts.

  • mongo18-10gen(这个是上一个版本,可以忽略)

    This package contains MongoDB tools from previous release. Install this package on all production MongoDB hosts and optionally on other systems from which you may need to administer MongoDB systems.

  • mongo18-10gen-server(这个是上一个版本,可以忽略)

    This package contains the mongod and mongos daemons from previous stable release and associated configuration and init scripts.

The MongoDB tools included in the mongo-10gen packages are:(mongo-10gen中包括的mongo工具)

  • mongo
  • mongodump
  • mongorestore
  • mongoexport
  • mongoimport
  • mongostat
  • mongotop
  • bsondump
Installing MongoDB
Configure Package Management System (YUM)(针对64位和32位配置yum资源库的配置文件)

Create a /etc/yum.repos.d/10gen.repo file to hold information about your repository. If you are running a 64-bit system (recommended,) place the following configuration in /etc/yum.repos.d/10gen.repo file:

[10gen] name=10gen 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 isn’t recommended for production deployments, place the following configuration in /etc/yum.repos.d/10gen.repo file:

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

After saving the new .repo files, users of both platforms should issue the following command to update the local package database:

yum update(执行更新)
Installing Packages(安装mongo-10gen和mongo-10gen-server)

Issue the following command (as root or with sudo) to install the latest stable version of MongoDB and the associated tools:

yum install mongo-10gen mongo-10gen-server(安装MongoDB)

When this command completes, you have successfully installed MongoDB! Continue for configuration and start-up suggestions.


Configure MongoDB

These packages configure MongoDB using the /etc/mongod.conf file in conjunction with the control script. You can find the init script at /etc/rc.d/init.d/mongod.

This MongoDB instance will store its data files in the /var/lib/mongo and its log files in /var/log/mongo, and run using the mongod user account.

MongoDB控制文件:/etc/mongod.conf,MogoDB初始化脚本:/etc/rc.d/init.d/mongod

MongoDB实例的数据文件:/var/lib/mongo,日志文件:/var/log/mongo

可以使用mongod用户执行,这样的话,上面的文件都需有mongod用户的访问权限(数据和日志)

Note

If you change the user that runs the MongoDB process, you will need to modify the access control rights to the /var/lib/mongo and /var/log/mongo directories.


Control MongoDB
Start MongoDB

Start the mongod process by issuing the following command (as root, or with sudo):

service mongod start(启动mongod)

You can verify that the mongod process has started successfully by checking the contents of the log file at /var/log/mongo/mongod.log.

You may optionally, ensure that MongoDB will start following a system reboot, by issuing the following command (with root privileges:)

chkconfig mongod on(配置系统重启后,MongoDB启动)
Stop MongoDB

Stop the mongod process by issuing the following command (as root, or with sudo):

service mongod stop(关闭MongoDB)
Restart MongoDB

You can restart the mongod process by issuing the following command (as root, or with sudo):

service mongod restart(重启MongoDB)

Follow the state of this process by watching the output in the /var/log/mongo/mongod.log file to watch for errors or important messages from the server.

关于服务器的错误和重要的信息日志,可以查看/var/log/mongo/mongod.log


Control mongos

As of the current release, there are no control scripts for mongos. mongos is only used in sharding deployments and typically do not run on the same systems where mongod runs. You can use the mongodb script referenced above to derive your own mongos control script.

Using MongoDB

Among the tools included in the mongo-10gen package, is the mongo shell. You can connect to your MongoDB instance by issuing the following command at the system prompt:

mongo(进入Mongo数据库)

This will connect to the database running on the localhost interface by default. At the mongo prompt, issue the following two commands to insert a record in the “test” collection of the (default) “test” database and then retrieve that document.

> db.test.save( { a: 1 } )(存储数据) > db.test.find()(提取数据)
相关实践学习
MongoDB数据库入门
MongoDB数据库入门实验。
快速掌握 MongoDB 数据库
本课程主要讲解MongoDB数据库的基本知识,包括MongoDB数据库的安装、配置、服务的启动、数据的CRUD操作函数使用、MongoDB索引的使用(唯一索引、地理索引、过期索引、全文索引等)、MapReduce操作实现、用户管理、Java对MongoDB的操作支持(基于2.x驱动与3.x驱动的完全讲解)。 通过学习此课程,读者将具备MongoDB数据库的开发能力,并且能够使用MongoDB进行项目开发。   相关的阿里云产品:云数据库 MongoDB版 云数据库MongoDB版支持ReplicaSet和Sharding两种部署架构,具备安全审计,时间点备份等多项企业能力。在互联网、物联网、游戏、金融等领域被广泛采用。 云数据库MongoDB版(ApsaraDB for MongoDB)完全兼容MongoDB协议,基于飞天分布式系统和高可靠存储引擎,提供多节点高可用架构、弹性扩容、容灾、备份回滚、性能优化等解决方案。 产品详情: https://www.aliyun.com/product/mongodb
目录
打赏
0
0
0
0
10
分享
相关文章
【Python】已完美解决(MongoDB安装报错)Service ‘MongoDB Server (MongoDB)’ (MongoDB) failed tostart
【Python】已完美解决(MongoDB安装报错)Service ‘MongoDB Server (MongoDB)’ (MongoDB) failed tostart
374 1
Linux平台安装MongoDB
10月更文挑战第11天
123 5
Mac OSX 平台安装 MongoDB
10月更文挑战第11天
47 4
[保姆级教程]Windows安装MongoDB教程
【6月更文挑战第4天】该内容是关于MongoDB的安装包下载及安装步骤指南。首先,访问网址 <a href="https://www.mongodb.com/try" target="_blank">https://www.mongodb.com/try</a> 进入官网,选择MongoDB Community Edition(社区版)。接着,挑选合适的版本和系统平台,推荐下载zip压缩包。下载后,进行安装,依次点击“Next”同意协议,选择自定义安装路径,然后继续安装直至完成。
786 0
Windows 平台安装 MongoDB
10月更文挑战第10天
102 0
Windows 平台安装 MongoDB
【赵渝强老师】MongoDB的安装与访问
本文介绍了在Linux系统上安装和部署MongoDB的详细步骤,包括安装依赖包、解压安装包、配置环境变量、创建数据目录及启动服务等。文中还提供了相关命令示例和注意事项,帮助用户顺利完成MongoDB的安装与配置。
docker安装Mongodb
这篇文章详细说明了如何使用Docker安装MongoDB,包括拉取镜像、创建并运行容器、数据持久化存储以及访问容器内的MongoDB服务的具体步骤。
457 1
在Ubuntu 16.04上安装和保护MongoDB的方法
在Ubuntu 16.04上安装和保护MongoDB的方法
58 1
用python安装mongodb
用python安装mongodb
47 0
AI助理

你好,我是AI助理

可以解答问题、推荐解决方案等