How to install mongodb in Centos 8

[root@DBAMAXWELL home]# sudo tee /etc/yum.repos.d/mongodb-org-4.repo<<EOF
> [mongodb-org-4]
> name=MongoDB Repository
> baseurl=https://repo.mongodb.org/yum/redhat/8/mongodb-org/4.4/x86_64/
> gpgcheck=1
> enabled=1
> gpgkey=https://www.mongodb.org/static/pgp/server-4.4.asc
> EOF

[mongodb-org-4]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/8/mongodb-org/4.4/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-4.4.asc


[root@DBAMAXWELL home]# sudo yum install mongodb-org
MongoDB Repository                                                                                                 21 kB/s |  37 kB     00:01    
Dependencies resolved.
==================================================================================================================================================
 Package                                            Architecture             Version                        Repository                       Size
==================================================================================================================================================
Installing:
 mongodb-org                                        x86_64                   4.4.13-1.el8                   mongodb-org-4                    11 k
Installing dependencies:
 cyrus-sasl                                         x86_64                   2.1.27-5.el8                   baseos                           96 k
 mongodb-database-tools                             x86_64                   100.5.2-1                      mongodb-org-4                    47 M
 mongodb-org-database-tools-extra                   x86_64                   4.4.13-1.el8                   mongodb-org-4                    23 k
 mongodb-org-mongos                                 x86_64                   4.4.13-1.el8                   mongodb-org-4                    17 M
 mongodb-org-server                                 x86_64                   4.4.13-1.el8                   mongodb-org-4                    22 M
 mongodb-org-shell                                  x86_64                   4.4.13-1.el8                   mongodb-org-4                    14 M
 mongodb-org-tools                                  x86_64                   4.4.13-1.el8                   mongodb-org-4                    11 k

Transaction Summary
==================================================================================================================================================
Install  8 Packages

Total download size: 100 M
Installed size: 318 M
Is this ok [y/N]: y
Downloading Packages:
(1/8): mongodb-org-4.4.13-1.el8.x86_64.rpm                                                                         34 kB/s |  11 kB     00:00    
(2/8): mongodb-org-database-tools-extra-4.4.13-1.el8.x86_64.rpm                                                   101 kB/s |  23 kB     00:00    
(3/8): cyrus-sasl-2.1.27-5.el8.x86_64.rpm                                                                          75 kB/s |  96 kB     00:01    
(4/8): mongodb-org-mongos-4.4.13-1.el8.x86_64.rpm                                                                 5.1 MB/s |  17 MB     00:03    
(5/8): mongodb-org-shell-4.4.13-1.el8.x86_64.rpm                                                                  4.0 MB/s |  14 MB     00:03    
(6/8): mongodb-org-tools-4.4.13-1.el8.x86_64.rpm                                                                   49 kB/s |  11 kB     00:00    
(7/8): mongodb-org-server-4.4.13-1.el8.x86_64.rpm                                                                 3.3 MB/s |  22 MB     00:06    
(8/8): mongodb-database-tools-100.5.2.x86_64.rpm                                                                  5.3 MB/s |  47 MB     00:08    
--------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                              11 MB/s | 100 MB     00:09     
MongoDB Repository                                                                                                1.6 kB/s | 1.6 kB     00:01    
Importing GPG key 0x90CFB1F5:
 Userid     : "MongoDB 4.4 Release Signing Key <packaging@mongodb.com>"
 Fingerprint: 2069 1EEC 3521 6C63 CAF6 6CE1 6564 08E3 90CF B1F5
 From       : https://www.mongodb.org/static/pgp/server-4.4.asc
Is this ok [y/N]: y
Key imported successfully
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                          1/1 
  Installing       : mongodb-org-shell-4.4.13-1.el8.x86_64                                                                                    1/8 
  Running scriptlet: mongodb-org-server-4.4.13-1.el8.x86_64                                                                                   2/8 
  Installing       : mongodb-org-server-4.4.13-1.el8.x86_64                                                                                   2/8 
  Running scriptlet: mongodb-org-server-4.4.13-1.el8.x86_64                                                                                   2/8 
Created symlink /etc/systemd/system/multi-user.target.wants/mongod.service → /usr/lib/systemd/system/mongod.service.

  Installing       : mongodb-org-mongos-4.4.13-1.el8.x86_64                                                                                   3/8 
  Installing       : mongodb-org-database-tools-extra-4.4.13-1.el8.x86_64                                                                     4/8 
  Running scriptlet: cyrus-sasl-2.1.27-5.el8.x86_64                                                                                           5/8 
  Installing       : cyrus-sasl-2.1.27-5.el8.x86_64                                                                                           5/8 
  Running scriptlet: cyrus-sasl-2.1.27-5.el8.x86_64                                                                                           5/8 
  Running scriptlet: mongodb-database-tools-100.5.2-1.x86_64                                                                                  6/8 
  Installing       : mongodb-database-tools-100.5.2-1.x86_64                                                                                  6/8 
  Running scriptlet: mongodb-database-tools-100.5.2-1.x86_64                                                                                  6/8 
  Installing       : mongodb-org-tools-4.4.13-1.el8.x86_64                                                                                    7/8 
  Installing       : mongodb-org-4.4.13-1.el8.x86_64                                                                                          8/8 
  Running scriptlet: mongodb-org-4.4.13-1.el8.x86_64                                                                                          8/8 
  Verifying        : cyrus-sasl-2.1.27-5.el8.x86_64                                                                                           1/8 
  Verifying        : mongodb-database-tools-100.5.2-1.x86_64                                                                                  2/8 
  Verifying        : mongodb-org-4.4.13-1.el8.x86_64                                                                                          3/8 
  Verifying        : mongodb-org-database-tools-extra-4.4.13-1.el8.x86_64                                                                     4/8 
  Verifying        : mongodb-org-mongos-4.4.13-1.el8.x86_64                                                                                   5/8 
  Verifying        : mongodb-org-server-4.4.13-1.el8.x86_64                                                                                   6/8 
  Verifying        : mongodb-org-shell-4.4.13-1.el8.x86_64                                                                                    7/8 
  Verifying        : mongodb-org-tools-4.4.13-1.el8.x86_64                                                                                    8/8 

Installed:
  cyrus-sasl-2.1.27-5.el8.x86_64                           mongodb-database-tools-100.5.2-1.x86_64     mongodb-org-4.4.13-1.el8.x86_64           
  mongodb-org-database-tools-extra-4.4.13-1.el8.x86_64     mongodb-org-mongos-4.4.13-1.el8.x86_64      mongodb-org-server-4.4.13-1.el8.x86_64    
  mongodb-org-shell-4.4.13-1.el8.x86_64                    mongodb-org-tools-4.4.13-1.el8.x86_64      

Complete!
[root@DBAMAXWELL home]# 

You can verify installation of above packages, e.g.

[root@DBAMAXWELL home]# rpm -qi mongodb-org-server
Name        : mongodb-org-server
Version     : 4.4.13
Release     : 1.el8
Architecture: x86_64
Install Date: Wed 23 Mar 2022 11:21:11 PM CST
Group       : Applications/Databases
Size        : 83495609
License     : SSPL
Signature   : RSA/SHA1, Mon 07 Mar 2022 10:50:33 PM CST, Key ID 656408e390cfb1f5
Source RPM  : mongodb-org-4.4.13-1.el8.src.rpm
Build Date  : Thu 03 Mar 2022 12:17:45 AM CST
Build Host  : ip-10-122-92-37.ec2.internal
Relocations : /usr /var /etc 
URL         : http://www.mongodb.org
Summary     : MongoDB database server
Description :
MongoDB is built for scalability, performance and high availability, scaling from single server deployments to large, complex multi-site architectures. By leveraging in-memory computing, MongoDB provides high performance for both reads and writes. MongoDB’s native replication and automated failover enable enterprise-grade reliability and operational flexibility.

MongoDB is an open-source database used by companies of all sizes, across all industries and for a wide variety of applications. It is an agile database that allows schemas to change quickly as applications evolve, while still providing the functionality developers expect from traditional databases, such as secondary indexes, a full query language and strict consistency.

MongoDB has a rich client ecosystem including hadoop integration, officially supported drivers for 10 programming languages and environments, as well as 40 drivers supported by the user community.

MongoDB features:
* JSON Data Model with Dynamic Schemas
* Auto-Sharding for Horizontal Scalability
* Built-In Replication for High Availability
* Rich Secondary Indexes, including geospatial
* TTL indexes
* Text Search
* Aggregation Framework & Native MapReduce

This package contains the MongoDB server software, default configuration files, and systemd service files.
[root@DBAMAXWELL home]# 

 Configure MongoDB on Centos8

When the package has been installed,you can start customizing and configuring MongDB before starting the service.

Label MongoDB port

If you have SELinux in enforcing mode,you may need to label port 27017

[root@DBAMAXWELL home]# 
[root@DBAMAXWELL home]# sudo semanage port -a -t mongod_port_t -p tcp 27017
[root@DBAMAXWELL home]# 

Allow mongo port on the firewall

If you have firewalld running on your server and would like MongoDB service to be accessible over the network, open it on the firewall:

[root@DBAMAXWELL home]# 
[root@DBAMAXWELL home]# sudo firewall-cmd --add-port=27017/tcp --permanent
FirewallD is not running
[root@DBAMAXWELL home]# sudo firewall-cmd --reload
FirewallD is not running
[root@DBAMAXWELL home]# 
[root@DBAMAXWELL home]# sudo firewall-cmd --permanent --add-rich-rule "rule family="ipv4" \
> source address="10.10.20.0/24" port protocol="tcp" port="27017" accept"
FirewallD is not running
[root@DBAMAXWELL home]# 

[root@DBAMAXWELL home]# sudo systemctl enable --now mongod
[root@DBAMAXWELL home]# systemctl status mongod.service
● mongod.service - MongoDB Database Server
   Loaded: loaded (/usr/lib/systemd/system/mongod.service; enabled; vendor preset: disabled)
   Active: active (running) since Wed 2022-03-23 23:33:56 CST; 21s ago
     Docs: https://docs.mongodb.org/manual
  Process: 359826 ExecStart=/usr/bin/mongod $OPTIONS (code=exited, status=0/SUCCESS)
  Process: 359824 ExecStartPre=/usr/bin/chmod 0755 /var/run/mongodb (code=exited, status=0/SUCCESS)
  Process: 359821 ExecStartPre=/usr/bin/chown mongod:mongod /var/run/mongodb (code=exited, status=0/SUCCESS)
  Process: 359820 ExecStartPre=/usr/bin/mkdir -p /var/run/mongodb (code=exited, status=0/SUCCESS)
 Main PID: 359828 (mongod)
   Memory: 124.4M
   CGroup: /system.slice/mongod.service
           └─359828 /usr/bin/mongod -f /etc/mongod.conf

Mar 23 23:33:55 DBAMAXWELL systemd[1]: Starting MongoDB Database Server...
Mar 23 23:33:55 DBAMAXWELL mongod[359826]: about to fork child process, waiting until server is ready for connections.
Mar 23 23:33:55 DBAMAXWELL mongod[359828]: forked process: 359828
Mar 23 23:33:56 DBAMAXWELL mongod[359826]: child process started successfully, parent exiting
Mar 23 23:33:56 DBAMAXWELL systemd[1]: Started MongoDB Database Server.
[root@DBAMAXWELL home]# 

### 安装 MongoDB 数据库于 CentOS #### 准备工作 为了确保顺利安装,在开始之前确认系统的更新状态是最新的。这可以通过运行 `sudo yum update` 来完成。 #### 添加 MongoDB 的 YUM 源 对于希望安装特定版本的MongoDB用户来说,编辑或创建一个新的YUM源文件是一个必要的操作。通过向 `/etc/yum.repos.d/` 目录下添加名为 `mongodb-org-6.0.repo` 文件来实现此目的[^4]: ```bash [mongodb-org-6.0] name=MongoDB Repository baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/6.0/x86_64/ gpgcheck=1 enabled=1 gpgkey=https://www.mongodb.org/static/pgp/server-6.0.asc ``` #### 执行安装命令 一旦配置好了仓库信息之后,就可以利用yum工具来进行MongoDB软件包的实际安装过程了。使用如下指令可以轻松地完成整个安装流程: ```bash sudo yum install -y mongodb-org ``` #### 创建并配置 MongoDB 服务 为了让MongoDB能够作为后台守护进程自动启动,需要定义一个systemd的服务单元文件。通常情况下该文件位于路径 `/etc/systemd/system/mongodb.service` 中,并可通过文本编辑器如vim进行编写或者修改[^2]: ```ini [Unit] Description=MongoDB Database Server After=network.target [Service] User=mongod ExecStart=/usr/bin/mongod --config /etc/mongod.conf Restart=on-failure [Install] WantedBy=multi-user.target ``` #### 启动与管理 MongoDB 服务 当上述准备工作全部完成后,则可正式启用MongoDB服务。首次启动时应采用以下命令[^1]: ```bash sudo systemctl start mongod ``` 另外还可以设置开机自启功能以便每次重启计算机后无需手动开启mongod服务: ```bash sudo systemctl enable mongod ``` 最后建议检查一下当前正在运行中的mongod实例的状态以验证其正常运作情况: ```bash sudo systemctl status mongod ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值