mongoDB稳定安装、使用、卸载

环境准备

1, CentOS 7.5
2, 安装版本:mongoDB 发行版4.2.5
3, 连接客户端:Navicat Premium 15

说明:
	安装方式很多,本文参考官方最佳安装指导进行安装:
	https://docs.mongodb.com/manual/tutorial/install-mongodb-on-red-hat/

步骤概括

# 1, 创建仓库指引文件
touch /etc/yum.repos.d/mongodb-org-4.2.repo

# 2,编辑该文件
vi /etc/yum.repos.d/mongodb-org-4.2.repo

# 添加内容如下:
[mongodb-org-4.2]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/4.2/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-4.2.asc

# 3,yum安装
sudo yum install -y mongodb-org-4.2.5 mongodb-org-server-4.2.5 mongodb-org-shell-4.2.5 mongodb-org-mongos-4.2.5 mongodb-org-tools-4.2.5

# 注意:因为下载源https://repo.mongodb.org/,过程可能会慢,失败了可以ctrl+c 退出,重复执行该命令;

# 4,配置防止自动升级
vi /etc/yum.conf

# 添加如下内容
exclude=mongodb-org,mongodb-org-server,mongodb-org-shell,mongodb-org-mongos,mongodb-org-tools

# 5,配置远程连接
vi /etc/mongod.conf

# bindIp修改为
bindIp: 0.0.0.0

# 6,防火墙开放端口
# 添加端口:27017
firewall-cmd --zone=public --add-port=27017/tcp --permanent
#重启防火漆
firewall-cmd --reload
#查看
firewall-cmd --list-ports

# 7,配置开机自启
sudo chkconfig mongod on

# 8,启动服务并查看
sudo service mongod restart
ps -ef|grep mongod
# 9,使用
mongo # 使用 
Ctrl+C 或者 exit # 退出 

详情步骤(具体操作)

[root@sentos yum.repos.d]# touch /etc/yum.repos.d/mongodb-org-4.2.repo
[root@sentos yum.repos.d]# vi /etc/yum.repos.d/mongodb-org-4.2.repo
[root@sentos yum.repos.d]# cat /etc/yum.repos.d/mongodb-org-4.2.repo
[mongodb-org-4.2]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/4.2/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-4.2.asc
[root@sentos ~]# sudo yum install -y mongodb-org-4.2.5 mongodb-org-server-4.2.5 mongodb-org-shell-4.2.5 mongodb-org-mongos-4.2.5 mongodb-org-tools-4.2.5
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
http://mirrors.njupt.edu.cn/centos/7.7.1908/os/x86_64/repodata/repomd.xml: [Errno 14] curl#56 - "Recv failure: Connection reset by peer"
Trying other mirror.
base                                                                                                                                                                  | 3.6 kB  00:00:00     
extras                                                                                                                                                                | 2.9 kB  00:00:00     
mongodb-org-4.2                                                                                                                                                       | 2.5 kB  00:00:00     
updates                                                                                                                                                               | 2.9 kB  00:00:00     
Resolving Dependencies
--> Running transaction check
---> Package mongodb-org.x86_64 0:4.2.5-1.el7 will be installed
---> Package mongodb-org-mongos.x86_64 0:4.2.5-1.el7 will be installed
---> Package mongodb-org-server.x86_64 0:4.2.5-1.el7 will be installed
---> Package mongodb-org-shell.x86_64 0:4.2.5-1.el7 will be installed
---> Package mongodb-org-tools.x86_64 0:4.2.5-1.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=============================================================================================================================================================================================
 Package                                            Arch                                   Version                                     Repository                                       Size
=============================================================================================================================================================================================
Installing:
 mongodb-org                                        x86_64                                 4.2.5-1.el7                                 mongodb-org-4.2                                 5.8 k
 mongodb-org-mongos                                 x86_64                                 4.2.5-1.el7                                 mongodb-org-4.2                                  14 M
 mongodb-org-server                                 x86_64                                 4.2.5-1.el7                                 mongodb-org-4.2                                  25 M
 mongodb-org-shell                                  x86_64                                 4.2.5-1.el7                                 mongodb-org-4.2                                  17 M
 mongodb-org-tools                                  x86_64                                 4.2.5-1.el7                                 mongodb-org-4.2                                  62 M

Transaction Summary
=============================================================================================================================================================================================
Install  5 Packages

Total size: 119 M
Total download size: 119 M
Installed size: 283 M
Downloading packages:
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
warning: /var/cache/yum/x86_64/7/mongodb-org-4.2/packages/mongodb-org-mongos-4.2.5-1.el7.x86_64.rpm: Header V3 RSA/SHA1 Signature, key ID 058f8b6b: NOKEY  ] 2.5 MB/s |  26 MB  00:00:37 ETA 
Public key for mongodb-org-mongos-4.2.5-1.el7.x86_64.rpm is not installed
(1/4): mongodb-org-mongos-4.2.5-1.el7.x86_64.rpm                                                                                                                      |  14 MB  00:00:01     
(2/4): mongodb-org-shell-4.2.5-1.el7.x86_64.rpm                                                                                                                       |  17 MB  00:00:01     
(3/4): mongodb-org-server-4.2.5-1.el7.x86_64.rpm                                                                                                                      |  25 MB  00:01:51     
(4/4): mongodb-org-tools-4.2.5-1.el7.x86_64.rpm                                                                                                                       |  62 MB  00:02:31     
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                                        788 kB/s | 119 MB  00:02:34     
Retrieving key from https://www.mongodb.org/static/pgp/server-4.2.asc
Importing GPG key 0x058F8B6B:
 Userid     : "MongoDB 4.2 Release Signing Key <packaging@mongodb.com>"
 Fingerprint: e162 f504 a20c df15 827f 718d 4b7c 549a 058f 8b6b
 From       : https://www.mongodb.org/static/pgp/server-4.2.asc
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : mongodb-org-tools-4.2.5-1.el7.x86_64                                                                                                                                      1/5 
  Installing : mongodb-org-mongos-4.2.5-1.el7.x86_64                                                                                                                                     2/5 
  Installing : mongodb-org-shell-4.2.5-1.el7.x86_64                                                                                                                                      3/5 
  Installing : mongodb-org-server-4.2.5-1.el7.x86_64                                                                                                                                     4/5 
Created symlink from /etc/systemd/system/multi-user.target.wants/mongod.service to /usr/lib/systemd/system/mongod.service.
  Installing : mongodb-org-4.2.5-1.el7.x86_64                                                                                                                                            5/5 
  Verifying  : mongodb-org-server-4.2.5-1.el7.x86_64                                                                                                                                     1/5 
  Verifying  : mongodb-org-4.2.5-1.el7.x86_64                                                                                                                                            2/5 
  Verifying  : mongodb-org-shell-4.2.5-1.el7.x86_64                                                                                                                                      3/5 
  Verifying  : mongodb-org-mongos-4.2.5-1.el7.x86_64                                                                                                                                     4/5 
  Verifying  : mongodb-org-tools-4.2.5-1.el7.x86_64                                                                                                                                      5/5 

Installed:
  mongodb-org.x86_64 0:4.2.5-1.el7              mongodb-org-mongos.x86_64 0:4.2.5-1.el7        mongodb-org-server.x86_64 0:4.2.5-1.el7        mongodb-org-shell.x86_64 0:4.2.5-1.el7       
  mongodb-org-tools.x86_64 0:4.2.5-1.el7       

Complete!
[root@sentos mongodb]# vi /etc/yum.conf
[root@sentos mongodb]# cat /etc/yum.conf
[main]
cachedir=/var/cache/yum/$basearch/$releasever
keepcache=0
debuglevel=2
logfile=/var/log/yum.log
exactarch=1
obsoletes=1
gpgcheck=1
plugins=1
installonly_limit=5
bugtracker_url=http://bugs.centos.org/set_project.php?project_id=23&ref=http://bugs.centos.org/bug_report_page.php?category=yum
distroverpkg=centos-release
exclude=mongodb-org,mongodb-org-server,mongodb-org-shell,mongodb-org-mongos,mongodb-org-tools

#  This is the default, if you make this bigger yum won't see if the metadata
# is newer on the remote and so you'll "gain" the bandwidth of not having to
# download the new metadata and "pay" for it by yum not having correct
# information.
#  It is esp. important, to have correct metadata, for distributions like
# Fedora which don't keep old packages around. If you don't like this checking
# interupting your command line usage, it's much better to have something
# manually check the metadata once an hour (yum-updatesd will do this).
# metadata_expire=90m

# PUT YOUR REPOS HERE OR IN separate files named file.repo
# in /etc/yum.repos.d
[root@sentos mongodb]# ps -ef|grep mongod
root      45654  43886  0 07:18 pts/0    00:00:00 grep --color=auto mongodb
[root@sentos mongodb]# whereis mongod.conf
mongod: /usr/bin/mongod /etc/mongod.conf /usr/share/man/man1/mongod.1
[root@sentos mongodb]# vi /etc/mongod.conf
[root@sentos mongodb]# cat /etc/mongod.conf
# mongod.conf

# for documentation of all options, see:
#   http://docs.mongodb.org/manual/reference/configuration-options/

# where to write logging data.
systemLog:
  destination: file
  logAppend: true
  path: /var/log/mongodb/mongod.log

# Where and how to store data.
storage:
  dbPath: /var/lib/mongo
  journal:
    enabled: true
#  engine:
#  wiredTiger:

# how the process runs
processManagement:
  fork: true  # fork and run in background
  pidFilePath: /var/run/mongodb/mongod.pid  # location of pidfile
  timeZoneInfo: /usr/share/zoneinfo

# network interfaces
net:
  port: 27017
  bindIp: 0.0.0.0  # Enter 0.0.0.0,:: to bind to all IPv4 and IPv6 addresses or, alternatively, use the net.bindIpAll setting.


#security:

#operationProfiling:

#replication:

#sharding:

## Enterprise-Only Options

#auditLog:

#snmp:
[root@sentos mongodb]# sudo service mongod restart
Redirecting to /bin/systemctl restart mongod.service
[root@sentos mongodb]# sudo chkconfig mongod on
Note: Forwarding request to 'systemctl enable mongod.service'.
[root@sentos mongodb]# ps -ef|grep mongod
mongod    46611      1  2 07:37 ?        00:00:01 /usr/bin/mongod -f /etc/mongod.conf
root      46703  43886  0 07:37 pts/0    00:00:00 grep --color=auto mongod
[root@sentos mongodb]# mongo
MongoDB shell version v4.2.5
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("e5462537-5730-4414-b60d-41dfa112f062") }
MongoDB server version: 4.2.5
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
	http://docs.mongodb.org/
Questions? Try the support group
	http://groups.google.com/group/mongodb-user
Server has startup warnings: 
2020-04-19T07:37:08.395+0800 I  CONTROL  [initandlisten] 
2020-04-19T07:37:08.395+0800 I  CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
2020-04-19T07:37:08.395+0800 I  CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
2020-04-19T07:37:08.395+0800 I  CONTROL  [initandlisten] 
2020-04-19T07:37:08.395+0800 I  CONTROL  [initandlisten] 
2020-04-19T07:37:08.395+0800 I  CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2020-04-19T07:37:08.395+0800 I  CONTROL  [initandlisten] **        We suggest setting it to 'never'
2020-04-19T07:37:08.405+0800 I  CONTROL  [initandlisten] 
2020-04-19T07:37:08.405+0800 I  CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2020-04-19T07:37:08.405+0800 I  CONTROL  [initandlisten] **        We suggest setting it to 'never'
2020-04-19T07:37:08.405+0800 I  CONTROL  [initandlisten] 
---
Enable MongoDB's free cloud-based monitoring service, which will then receive and display
metrics about your deployment (disk utilization, CPU, operation statistics, etc).

The monitoring data will be available on a MongoDB website with a unique URL accessible to you
and anyone you share the URL with. MongoDB may use this information to make product
improvements and to suggest MongoDB products and deployment options to you.

To enable free monitoring, run the following command: db.enableFreeMonitoring()
To permanently disable this reminder, run the following command: db.disableFreeMonitoring()
---
> ^C
bye
[root@sentos mongodb]# firewall-cmd --list-ports
8080/tcp 3306/tcp 80/tcp 6379/tcp 8081/tcp
[root@sentos mongodb]# firewall-cmd --zone=public --add-port=27017/tcp --permanent
success
[root@sentos mongodb]# firewall-cmd --reload
success
[root@sentos mongodb]# firewall-cmd --list-ports
8080/tcp 3306/tcp 80/tcp 6379/tcp 8081/tcp 27017/tcp

使用

#启动
sudo systemctl start mongod
#重启
sudo systemctl stop restart
#停机
sudo service mongod stop 
#开机自启
sudo chkconfig mongod on

# 命令执行
mongo # 开启
Ctrl+C # 退出

卸载

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

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

客户端链接_Navicat Premium

在这里插入图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值