MongoDB的安装详解

一、yum安装

1.添加yum仓库源

[root@mongodb ~]# vim /etc/yum.repos.d/mongodb-org-4.4.repo
[mongodb-org-4.4]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/4.4/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-4.4.asc

2.yum安装

[root@mongodb ~]# yum install -y mongodb-org  #安装最新版
或者
[root@mongodb ~]# yum install -y mongodb-org-4.4.4 mongodb-org-server-4.4.4 mongodb-org-shell-4.4.4 mongodb-org-mongos-4.4.4 mongodb-org-tools-4.4.4  #安装指定版本

防止自动更新,锁定包。

[root@mongodb ~]# vim /etc/yum.conf
exclude=mongodb-org,mongodb-org-server,mongodb-org-shell,mongodb-org-mongos,mongodb-org-tools

yum安装的好处在于目录和用户已经自动创建好了。

[root@mongodb ~]# ll /var/lib/mongo/
总用量 0
[root@mongodb ~]# ll /var/log/mongodb/
总用量 0
-rw-r----- 1 mongod mongod 0 2月  12 06:45 mongod.log
[root@mongodb ~]# cat /etc/shadow | grep mongod
mongod:!!:18709::::::

3.启动mongodb

[root@mongodb ~]# systemctl start mongod
[root@mongodb ~]# systemctl enable mongod
[root@mongodb ~]# netstat -anput | grep mongo
tcp        0      0 127.0.0.1:27017         0.0.0.0:*               LISTEN      20023/mongod 

4.进入数据库

[root@mongodb ~]# mongo
MongoDB shell version v4.4.4
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("1ac0974b-e31f-45d8-9f1c-97f3ee729c1b") }
MongoDB server version: 4.4.4
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
        https://docs.mongodb.com/
Questions? Try the MongoDB Developer Community Forums
        https://community.mongodb.com
---
The server generated these startup warnings when booting: 
        2021-03-23T15:53:14.948+08:00: Access control is not enabled for the database. Read and write access to data and configuration is unrestricted
        2021-03-23T15:53:14.948+08:00: /sys/kernel/mm/transparent_hugepage/enabled is 'always'. We suggest setting it to 'never'
        2021-03-23T15:53:14.948+08:00: /sys/kernel/mm/transparent_hugepage/defrag is 'always'. We suggest setting it to 'never'
---
---
        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()
---
> 

二、通过tar包安装

1.安装前提依赖

yum -y install libcurl openssl xz-libs

2.获取tar包
MongoDB官网下载:https://www.mongodb.com/try/download/community
在这里插入图片描述

[root@mongodb ~]# cd /usr/local/src/
[root@mongodb src]# ls
mongodb-linux-x86_64-rhel70-4.4.4.tgz

3.解压

[root@mongodb src]# tar zxf mongodb-linux-x86_64-rhel70-4.4.4.tgz
[root@mongodb src]# ln -s /usr/local/src/mongodb-linux-x86_64-rhel70-4.4.4/bin/* /usr/local/bin/

4.创建系统用户

[root@mongodb src]# useradd -r -M -s /sbin/nologin mongod

5.创建数据目录和日志目录

mkdir -p /var/lib/mongo
mkdir -p /var/log/mongodb
chown -R mongod:mongod /var/lib/mongo
chown -R mongod:mongod /var/log/mongodb

6.修改打开文件数

[root@mongodb ~]# vim /etc/security/limits.conf
*               -       nofile          65535

修改后断开重新连接。
7.启动mongodb

[root@mongodb ~]# mongod --dbpath /var/lib/mongo --logpath /var/log/mongodb/mongod.log --fork
about to fork child process, waiting until server is ready for connections.
forked process: 53352
child process started successfully, parent exiting
[root@mongodb ~]# netstat -anput | grep mongo
tcp        0      0 127.0.0.1:27017         0.0.0.0:*               LISTEN      53352/mongod

8.进入数据库

[root@mongodb ~]# mongo
MongoDB shell version v4.4.4
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("14a62ada-4d71-4d7b-86f4-0231b9f1a6b9") }
MongoDB server version: 4.4.4
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
        https://docs.mongodb.com/
Questions? Try the MongoDB Developer Community Forums
        https://community.mongodb.com
---
The server generated these startup warnings when booting: 
        2021-03-23T16:44:41.922+08:00: Access control is not enabled for the database. Read and write access to data and configuration is unrestricted
        2021-03-23T16:44:41.922+08:00: You are running this process as the root user, which is not recommended
        2021-03-23T16:44:41.922+08:00: This server is bound to localhost. Remote systems will be unable to connect to this server. Start the server with --bind_ip <address> to specify which IP addresses it should serve responses from, or with --bind_ip_all to bind to all interfaces. If this behavior is desired, start the server with --bind_ip 127.0.0.1 to disable this warning
        2021-03-23T16:44:41.922+08:00: /sys/kernel/mm/transparent_hugepage/enabled is 'always'. We suggest setting it to 'never'
        2021-03-23T16:44:41.922+08:00: /sys/kernel/mm/transparent_hugepage/defrag is 'always'. We suggest setting it to 'never'
        2021-03-23T16:44:41.922+08:00: Soft rlimits too low
        2021-03-23T16:44:41.922+08:00:         currentValue: 1024
        2021-03-23T16:44:41.922+08:00:         recommendedMinimum: 64000
---
---
        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()
---
> 
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值