小试MongoDB之MongoDB安装

简介: 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()(提取数据)
相关文章
|
4月前
|
NoSQL Ubuntu MongoDB
在Ubuntu 22.04上安装MongoDB 6.0的步骤
这些步骤应该可以在Ubuntu 22.04系统上安装MongoDB 6.0。安装过程中,如果遇到任何问题,可以查阅MongoDB的官方文档或者Ubuntu的相关帮助文档,这些资源通常提供了解决特定问题的详细指导。
441 18
|
8月前
|
存储 NoSQL MongoDB
Docker中安装MongoDB并配置数据、日志、配置文件持久化。
现在,你有了一个运行在Docker中的MongoDB,它拥有自己的小空间,对高楼大厦的崩塌视而不见(会话丢失和数据不持久化的问题)。这个MongoDB的数据、日志、配置文件都会妥妥地保存在你为它精心准备的地方,天旋地转,它也不会失去一丁点儿宝贵的记忆(即使在容器重启后)。
989 4
|
NoSQL MongoDB Python
【Python】已完美解决(MongoDB安装报错)Service ‘MongoDB Server (MongoDB)’ (MongoDB) failed tostart
【Python】已完美解决(MongoDB安装报错)Service ‘MongoDB Server (MongoDB)’ (MongoDB) failed tostart
1199 1
|
11月前
|
NoSQL MongoDB 微服务
微服务2——MongoDB单机部署1——下载安装
本指南介绍在Windows系统上安装和启动MongoDB的步骤。首先,从官网下载适用于32位或64位系统的预编译二进制包,选择稳定版(y为偶数)。解压后创建数据目录`data/db`,可通过命令行参数(如`mongod --dbpath=..\data\db`)或配置文件启动服务。配置文件需注意转义字符与空格使用,支持自定义日志路径、端口等参数。将bin目录加入环境变量可简化启动操作。
316 0
微服务2——MongoDB单机部署1——下载安装
|
11月前
|
存储 NoSQL Linux
微服务2——MongoDB单机部署4——Linux系统中的安装启动和连接
本节主要介绍了在Linux系统中安装、启动和连接MongoDB的详细步骤。首先从官网下载MongoDB压缩包并解压至指定目录,接着创建数据和日志存储目录,并配置`mongod.conf`文件以设定日志路径、数据存储路径及绑定IP等参数。之后通过配置文件启动MongoDB服务,并使用`mongo`命令或Compass工具进行连接测试。此外,还提供了防火墙配置建议以及服务停止的两种方法:快速关闭(直接杀死进程)和标准关闭(通过客户端命令安全关闭)。最后补充了数据损坏时的修复操作,确保数据库的稳定运行。
743 0
|
NoSQL Ubuntu Linux
Linux平台安装MongoDB
10月更文挑战第11天
581 5
|
NoSQL Shell MongoDB
Mac OSX 平台安装 MongoDB
10月更文挑战第11天
362 4
|
NoSQL Shell MongoDB
Windows 平台安装 MongoDB
10月更文挑战第10天
537 0
Windows 平台安装 MongoDB
|
存储 NoSQL MongoDB
docker安装Mongodb
这篇文章详细说明了如何使用Docker安装MongoDB,包括拉取镜像、创建并运行容器、数据持久化存储以及访问容器内的MongoDB服务的具体步骤。
1369 1
|
存储 NoSQL 网络协议
【赵渝强老师】MongoDB的安装与访问
本文介绍了在Linux系统上安装和部署MongoDB的详细步骤,包括安装依赖包、解压安装包、配置环境变量、创建数据目录及启动服务等。文中还提供了相关命令示例和注意事项,帮助用户顺利完成MongoDB的安装与配置。
330 0

热门文章

最新文章

推荐镜像

更多