CentOS7 yum安装MongoDB企业版

安装

注:本文中yum安装方式需要在联网模式下运行,如果处于无法联网,可以配置本地yum源安装。
Linux7安装文件下载地址https://repo.mongodb.com/yum/redhat/7/mongodb-enterprise/3.6/x86_64/RPMS/
局域网YUM源配置方式https://blog.csdn.net/baidu_39459954/article/details/80619307


1、配置yum仓库

新建repo文件

vi /etc/yum.repos.d/mongodb-enterprise.repo

写入

[mongodb-enterprise]
name=MongoDB Enterprise Repository
baseurl=https://repo.mongodb.com/yum/redhat/$releasever/mongodb-enterprise/3.6/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-3.6.asc

2、安装

sudo yum install mongodb-enterprise

安装记录

[root@yc ~]# yum install mongodb-enterprise
Loaded plugins: fastestmirror, langpacks
mongodb-enterprise                                                                                                                        | 2.5 kB  00:00:00     
mongodb-enterprise/7/x86_64/primary_db                                                                                                    |  35 kB  00:00:01     
Loading mirror speeds from cached hostfile
 * base: mirrors.huaweicloud.com
 * extras: mirrors.huaweicloud.com
 * updates: mirrors.huaweicloud.com
Resolving Dependencies
--> Running transaction check
---> Package mongodb-enterprise.x86_64 0:3.6.5-1.el7 will be installed
--> Processing Dependency: mongodb-enterprise-tools = 3.6.5 for package: mongodb-enterprise-3.6.5-1.el7.x86_64
--> Processing Dependency: mongodb-enterprise-shell = 3.6.5 for package: mongodb-enterprise-3.6.5-1.el7.x86_64
--> Processing Dependency: mongodb-enterprise-server = 3.6.5 for package: mongodb-enterprise-3.6.5-1.el7.x86_64
--> Processing Dependency: mongodb-enterprise-mongos = 3.6.5 for package: mongodb-enterprise-3.6.5-1.el7.x86_64
--> Running transaction check
---> Package mongodb-enterprise-mongos.x86_64 0:3.6.5-1.el7 will be installed
---> Package mongodb-enterprise-server.x86_64 0:3.6.5-1.el7 will be installed
--> Processing Dependency: net-snmp for package: mongodb-enterprise-server-3.6.5-1.el7.x86_64
--> Processing Dependency: libnetsnmpmibs.so.31()(64bit) for package: mongodb-enterprise-server-3.6.5-1.el7.x86_64
--> Processing Dependency: libnetsnmpagent.so.31()(64bit) for package: mongodb-enterprise-server-3.6.5-1.el7.x86_64
---> Package mongodb-enterprise-shell.x86_64 0:3.6.5-1.el7 will be installed
---> Package mongodb-enterprise-tools.x86_64 0:3.6.5-1.el7 will be installed
--> Running transaction check
---> Package net-snmp.x86_64 1:5.7.2-33.el7_5.2 will be installed
--> Processing Dependency: net-snmp-libs = 1:5.7.2-33.el7_5.2 for package: 1:net-snmp-5.7.2-33.el7_5.2.x86_64
---> Package net-snmp-agent-libs.x86_64 1:5.7.2-33.el7_5.2 will be installed
--> Running transaction check
---> Package net-snmp-libs.x86_64 1:5.7.2-28.el7 will be updated
---> Package net-snmp-libs.x86_64 1:5.7.2-33.el7_5.2 will be an update
--> Finished Dependency Resolution

Dependencies Resolved

=================================================================================================================================================================
 Package                                       Arch                       Version                                   Repository                              Size
=================================================================================================================================================================
Installing:
 mongodb-enterprise                            x86_64                     3.6.5-1.el7                               mongodb-enterprise                     5.9 k
Installing for dependencies:
 mongodb-enterprise-mongos                     x86_64                     3.6.5-1.el7                               mongodb-enterprise                      12 M
 mongodb-enterprise-server                     x86_64                     3.6.5-1.el7                               mongodb-enterprise                      21 M
 mongodb-enterprise-shell                      x86_64                     3.6.5-1.el7                               mongodb-enterprise                      12 M
 mongodb-enterprise-tools                      x86_64                     3.6.5-1.el7                               mongodb-enterprise                      59 M
 net-snmp                                      x86_64                     1:5.7.2-33.el7_5.2                        updates                                330 k
 net-snmp-agent-libs                           x86_64                     1:5.7.2-33.el7_5.2                        updates                                705 k
Updating for dependencies:
 net-snmp-libs                                 x86_64                     1:5.7.2-33.el7_5.2                        updates                                749 k

Transaction Summary
=================================================================================================================================================================
Install  1 Package  (+6 Dependent packages)
Upgrade             ( 1 Dependent package)

Total size: 105 M
Total download size: 104 M
Is this ok [y/d/N]: y
Downloading packages:
warning: /var/cache/yum/x86_64/7/mongodb-enterprise/packages/mongodb-enterprise-3.6.5-1.el7.x86_64.rpm: Header V3 RSA/SHA1 Signature, key ID 91fa4ad5: NOKEY                                                                                ]  0.0 B/s |    0 B  --:--:-- ETA 
Public key for mongodb-enterprise-3.6.5-1.el7.x86_64.rpm is not installed
(1/7): mongodb-enterprise-3.6.5-1.el7.x86_64.rpm                                                                                                                                                                                                       | 5.9 kB  00:00:01     
(2/7): mongodb-enterprise-mongos-3.6.5-1.el7.x86_64.rpm                                                                                                                                                                                                |  12 MB  00:00:03     
(3/7): mongodb-enterprise-server-3.6.5-1.el7.x86_64.rpm                                                                                                                                                                                                |  21 MB  00:00:03     
(4/7): mongodb-enterprise-shell-3.6.5-1.el7.x86_64.rpm                                                                                                                                                                                                 |  12 MB  00:00:01     
(5/7): net-snmp-5.7.2-33.el7_5.2.x86_64.rpm                                                                                                                                                                                                            | 330 kB  00:00:00     
(6/7): net-snmp-agent-libs-5.7.2-33.el7_5.2.x86_64.rpm                                                                                                                                                                                                 | 705 kB  00:00:00     
(7/7): mongodb-enterprise-tools-3.6.5-1.el7.x86_64.rpm                                                                                                                                                                                                 |  59 MB  00:00:04     
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                                                                                                                          12 MB/s | 104 MB  00:00:08     
Retrieving key from https://www.mongodb.org/static/pgp/server-3.6.asc
Importing GPG key 0x91FA4AD5:
 Userid     : "MongoDB 3.6 Release Signing Key <[email protected]>"
 Fingerprint: 2930 adae 8caf 5059 ee73 bb4b 5871 2a22 91fa 4ad5
 From       : https://www.mongodb.org/static/pgp/server-3.6.asc
Is this ok [y/N]: y
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Updating   : 1:net-snmp-libs-5.7.2-33.el7_5.2.x86_64                                                                                                                                                                                                                    1/9 
  Installing : 1:net-snmp-agent-libs-5.7.2-33.el7_5.2.x86_64                                                                                                                                                                                                              2/9 
  Installing : 1:net-snmp-5.7.2-33.el7_5.2.x86_64                                                                                                                                                                                                                         3/9 
  Installing : mongodb-enterprise-server-3.6.5-1.el7.x86_64                                                                                                                                                                                                               4/9 
Created symlink from /etc/systemd/system/multi-user.target.wants/mongod.service to /usr/lib/systemd/system/mongod.service.
  Installing : mongodb-enterprise-shell-3.6.5-1.el7.x86_64                                                                                                                                                                                                                5/9 
  Installing : mongodb-enterprise-mongos-3.6.5-1.el7.x86_64                                                                                                                                                                                                               6/9 
  Installing : mongodb-enterprise-tools-3.6.5-1.el7.x86_64                                                                                                                                                                                                                7/9 
  Installing : mongodb-enterprise-3.6.5-1.el7.x86_64                                                                                                                                                                                                                      8/9 
  Cleanup    : 1:net-snmp-libs-5.7.2-28.el7.x86_64                                                                                                                                                                                                                        9/9 
  Verifying  : mongodb-enterprise-tools-3.6.5-1.el7.x86_64                                                                                                                                                                                                                1/9 
  Verifying  : 1:net-snmp-5.7.2-33.el7_5.2.x86_64                                                                                                                                                                                                                         2/9 
  Verifying  : 1:net-snmp-libs-5.7.2-33.el7_5.2.x86_64                                                                                                                                                                                                                    3/9 
  Verifying  : mongodb-enterprise-3.6.5-1.el7.x86_64                                                                                                                                                                                                                      4/9 
  Verifying  : 1:net-snmp-agent-libs-5.7.2-33.el7_5.2.x86_64                                                                                                                                                                                                              5/9 
  Verifying  : mongodb-enterprise-mongos-3.6.5-1.el7.x86_64                                                                                                                                                                                                               6/9 
  Verifying  : mongodb-enterprise-shell-3.6.5-1.el7.x86_64                                                                                                                                                                                                                7/9 
  Verifying  : mongodb-enterprise-server-3.6.5-1.el7.x86_64                                                                                                                                                                                                               8/9 
  Verifying  : 1:net-snmp-libs-5.7.2-28.el7.x86_64                                                                                                                                                                                                                        9/9 

Installed:
  mongodb-enterprise.x86_64 0:3.6.5-1.el7                                                                                                                                                                                                                                     

Dependency Installed:
  mongodb-enterprise-mongos.x86_64 0:3.6.5-1.el7 mongodb-enterprise-server.x86_64 0:3.6.5-1.el7 mongodb-enterprise-shell.x86_64 0:3.6.5-1.el7 mongodb-enterprise-tools.x86_64 0:3.6.5-1.el7 net-snmp.x86_64 1:5.7.2-33.el7_5.2 net-snmp-agent-libs.x86_64 1:5.7.2-33.el7_5.2

Dependency Updated:
  net-snmp-libs.x86_64 1:5.7.2-33.el7_5.2                                                                                                                                                                                                                                     

Complete!
[root@yc ~]# 

3、检查是否安装成功

[root@yc ~]# rpm -qa | grep mongodb
mongodb-enterprise-3.6.5-1.el7.x86_64
mongodb-enterprise-shell-3.6.5-1.el7.x86_64
mongodb-enterprise-mongos-3.6.5-1.el7.x86_64
mongodb-enterprise-tools-3.6.5-1.el7.x86_64
mongodb-enterprise-server-3.6.5-1.el7.x86_64

4、配置selinux

方法一,开放端口(默认为27017)

semanage port -a -t mongod_port_t -p tcp 27017

方法二,关闭selinux

vi /etc/selinux/config

修改

SELINUX=disabled

5、配置参数

编辑配置文件

vi /etc/mongod.conf

yum安装后系统默认127.0.0.1,只能通过本地连接,添加本机IP地址192.168.88.58至bindIp,可以添加多个IP,用逗号隔开即可

bindIp: 127.0.0.1,192.168.88.58

6、启动并检查

启动命令
systemctl start mongod.service
检查命令
systemctl status mongod.service

[root@yc ~]# systemctl start mongod.service 
[root@yc ~]# systemctl status mongod.service 
● mongod.service - High-performance, schema-free document-oriented database
   Loaded: loaded (/usr/lib/systemd/system/mongod.service; enabled; vendor preset: disabled)
   Active: active (running) since Mon 2018-06-11 12:03:31 CST; 1s ago
     Docs: https://docs.mongodb.org/manual
  Process: 3078 ExecStart=/usr/bin/mongod $OPTIONS (code=exited, status=0/SUCCESS)
  Process: 3075 ExecStartPre=/usr/bin/chmod 0755 /var/run/mongodb (code=exited, status=0/SUCCESS)
  Process: 3073 ExecStartPre=/usr/bin/chown mongod:mongod /var/run/mongodb (code=exited, status=0/SUCCESS)
  Process: 3066 ExecStartPre=/usr/bin/mkdir -p /var/run/mongodb (code=exited, status=0/SUCCESS)
 Main PID: 3081 (mongod)
   CGroup: /system.slice/mongod.service
           └─3081 /usr/bin/mongod -f /etc/mongod.conf

Jun 11 12:03:30 yc systemd[1]: Starting High-performance, schema-free document-oriented database...
Jun 11 12:03:31 yc mongod[3078]: about to fork child process, waiting until server is ready for connections.
Jun 11 12:03:31 yc mongod[3078]: forked process: 3081
Jun 11 12:03:31 yc mongod[3078]: child process started successfully, parent exiting
Jun 11 12:03:31 yc systemd[1]: Started High-performance, schema-free document-oriented database.
[root@yc ~]# netstat -nltp|grep mongo
tcp        0      0 192.168.88.58:27017     0.0.0.0:*               LISTEN      27984/mongod        
tcp        0      0 127.0.0.1:27017         0.0.0.0:*               LISTEN      27984/mongod 

7、打开一个MongoDB shell

在运行了MongoDB的服务器上打开一个 mongo shell,使用*–host*选项指定地址和端口号
示例:

mongo --host 127.0.0.1:27017

mongo warning:

MongoDB shell version v3.6.5
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 3.6.5
Server has startup warnings: 
2018-07-05T10:12:13.538+0800 I CONTROL  [initandlisten] 
2018-07-05T10:12:13.538+0800 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
2018-07-05T10:12:13.538+0800 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
2018-07-05T10:12:13.538+0800 I CONTROL  [initandlisten] 
2018-07-05T10:12:13.539+0800 I CONTROL  [initandlisten] 
2018-07-05T10:12:13.539+0800 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2018-07-05T10:12:13.539+0800 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2018-07-05T10:12:13.539+0800 I CONTROL  [initandlisten] 
2018-07-05T10:12:13.539+0800 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2018-07-05T10:12:13.539+0800 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2018-07-05T10:12:13.539+0800 I CONTROL  [initandlisten] 

如果在运行时解决这问题,也不困难,只需要修改hugepage的设置就可以了。执行下面两条命令

echo never > /sys/kernel/mm/transparent_hugepage/enabled
echo never > /sys/kernel/mm/transparent_hugepage/defrag

别忘了重启你的mongoDB,这条warning就消失了。不过下次重新启动系统,这些设置就会消失。可以配置在/etc/rc.local中


卸载

1、停止MongoDB

sudo service mongod stop

2、卸载安装包

sudo yum erase $(rpm -qa | grep mongodb-enterprise)

3、删除数据库及日志

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

参考:
https://docs.mongodb.com/manual/tutorial/install-mongodb-enterprise-on-red-hat/

猜你喜欢

转载自blog.csdn.net/baidu_39459954/article/details/80650473
今日推荐