zoukankan      html  css  js  c++  java
  • Centos7安装mongodb

    学习自:https://www.cnblogs.com/blackmanzhang/p/12677538.html

    [root@vmcentos7-1 ~]#vim /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@vmcentos7-1 ~]# yum install mongodb-org
    已加载插件:fastestmirror, langpacks
    Loading mirror speeds from cached hostfile
    * base: mirrors.163.com
    * extras: mirrors.aliyun.com
    * updates: mirrors.aliyun.com
    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
    mongodb-org-4.2/7/primary_db | 51 kB 00:00:01
    正在解决依赖关系
    --> 正在检查事务
    ---> 软件包 mongodb-org.x86_64.0.4.2.11-1.el7 将被 安装
    --> 正在处理依赖关系 mongodb-org-tools = 4.2.11,它被软件包 mongodb-org-4.2.11-1.el7.x86_64 需要
    --> 正在处理依赖关系 mongodb-org-server = 4.2.11,它被软件包 mongodb-org-4.2.11-1.el7.x86_64 需要
    --> 正在处理依赖关系 mongodb-org-shell = 4.2.11,它被软件包 mongodb-org-4.2.11-1.el7.x86_64 需要
    --> 正在处理依赖关系 mongodb-org-mongos = 4.2.11,它被软件包 mongodb-org-4.2.11-1.el7.x86_64 需要
    --> 正在检查事务
    ---> 软件包 mongodb-org-mongos.x86_64.0.4.2.11-1.el7 将被 安装
    ---> 软件包 mongodb-org-server.x86_64.0.4.2.11-1.el7 将被 安装
    ---> 软件包 mongodb-org-shell.x86_64.0.4.2.11-1.el7 将被 安装
    ---> 软件包 mongodb-org-tools.x86_64.0.4.2.11-1.el7 将被 安装
    --> 解决依赖关系完成

    依赖关系解决

    =============================================================================================================================================================================================================================================
    Package 架构 版本 源 大小
    =============================================================================================================================================================================================================================================
    正在安装:
    mongodb-org x86_64 4.2.11-1.el7 mongodb-org-4.2 5.9 k
    为依赖而安装:
    mongodb-org-mongos x86_64 4.2.11-1.el7 mongodb-org-4.2 15 M
    mongodb-org-server x86_64 4.2.11-1.el7 mongodb-org-4.2 26 M
    mongodb-org-shell x86_64 4.2.11-1.el7 mongodb-org-4.2 17 M
    mongodb-org-tools x86_64 4.2.11-1.el7 mongodb-org-4.2 62 M

    事务概要
    =============================================================================================================================================================================================================================================
    安装 1 软件包 (+4 依赖软件包)

    总下载量:119 M
    安装大小:284 M
    Is this ok [y/d/N]: y
    Downloading packages:
    警告:/var/cache/yum/x86_64/7/mongodb-org-4.2/packages/mongodb-org-4.2.11-1.el7.x86_64.rpm: 头V3 RSA/SHA1 Signature, 密钥 ID 058f8b6b: NOKEY ] 0.0 B/s | 0 B --:--:-- ETA
    mongodb-org-4.2.11-1.el7.x86_64.rpm 的公钥尚未安装
    (1/5): mongodb-org-4.2.11-1.el7.x86_64.rpm | 5.9 kB 00:00:01
    (2/5): mongodb-org-server-4.2.11-1.el7.x86_64.rpm | 26 MB 00:00:08
    (3/5): mongodb-org-shell-4.2.11-1.el7.x86_64.rpm | 17 MB 00:00:05
    (4/5): mongodb-org-mongos-4.2.11-1.el7.x86_64.rpm | 15 MB 00:00:17
    (5/5): mongodb-org-tools-4.2.11-1.el7.x86_64.rpm | 62 MB 00:00:14
    ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    总计 3.9 MB/s | 119 MB 00:00:30
    从 https://www.mongodb.org/static/pgp/server-4.2.asc 检索密钥
    导入 GPG key 0x058F8B6B:
    用户ID : "MongoDB 4.2 Release Signing Key <packaging@mongodb.com>"
    指纹 : e162 f504 a20c df15 827f 718d 4b7c 549a 058f 8b6b
    来自 : https://www.mongodb.org/static/pgp/server-4.2.asc
    是否继续?[y/N]:y
    Running transaction check
    Running transaction test
    Transaction test succeeded
    Running transaction
    正在安装 : mongodb-org-server-4.2.11-1.el7.x86_64 1/5
    Created symlink from /etc/systemd/system/multi-user.target.wants/mongod.service to /usr/lib/systemd/system/mongod.service.
    正在安装 : mongodb-org-tools-4.2.11-1.el7.x86_64 2/5
    正在安装 : mongodb-org-mongos-4.2.11-1.el7.x86_64 3/5
    正在安装 : mongodb-org-shell-4.2.11-1.el7.x86_64 4/5
    正在安装 : mongodb-org-4.2.11-1.el7.x86_64 5/5
    验证中 : mongodb-org-shell-4.2.11-1.el7.x86_64 1/5
    验证中 : mongodb-org-mongos-4.2.11-1.el7.x86_64 2/5
    验证中 : mongodb-org-tools-4.2.11-1.el7.x86_64 3/5
    验证中 : mongodb-org-server-4.2.11-1.el7.x86_64 4/5
    验证中 : mongodb-org-4.2.11-1.el7.x86_64 5/5

    已安装:
    mongodb-org.x86_64 0:4.2.11-1.el7

    作为依赖被安装:
    mongodb-org-mongos.x86_64 0:4.2.11-1.el7 mongodb-org-server.x86_64 0:4.2.11-1.el7 mongodb-org-shell.x86_64 0:4.2.11-1.el7 mongodb-org-tools.x86_64 0:4.2.11-1.el7

    完毕!

    [root@vmcentos7-1 ~]# systemctl start mongod.service

    [root@vmcentos7-1 ~]# 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 三 2021-01-13 10:17:22 CST; 4s ago
    Docs: https://docs.mongodb.org/manual
    Process: 25176 ExecStart=/usr/bin/mongod $OPTIONS (code=exited, status=0/SUCCESS)
    Process: 25174 ExecStartPre=/usr/bin/chmod 0755 /var/run/mongodb (code=exited, status=0/SUCCESS)
    Process: 25172 ExecStartPre=/usr/bin/chown mongod:mongod /var/run/mongodb (code=exited, status=0/SUCCESS)
    Process: 25168 ExecStartPre=/usr/bin/mkdir -p /var/run/mongodb (code=exited, status=0/SUCCESS)
    Main PID: 25179 (mongod)
    Tasks: 32
    CGroup: /system.slice/mongod.service
    └─25179 /usr/bin/mongod -f /etc/mongod.conf

    1月 13 10:17:18 vmcentos7-1 systemd[1]: Starting MongoDB Database Server...
    1月 13 10:17:19 vmcentos7-1 mongod[25176]: about to fork child process, waiting until server is ready for connections.
    1月 13 10:17:19 vmcentos7-1 mongod[25176]: forked process: 25179
    1月 13 10:17:22 vmcentos7-1 systemd[1]: Started MongoDB Database Server.

    [root@vmcentos7-1 ~]# systemctl enable mongod.service

    [root@vmcentos7-1 ~]# mongo
    MongoDB shell version v4.2.11
    connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
    Implicit session: session { "id" : UUID("a97369c0-ca34-462a-a7cf-225f46187c82") }
    MongoDB server version: 4.2.11
    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
    Server has startup warnings:
    2021-01-13T10:17:22.295+0800 I CONTROL [initandlisten]
    2021-01-13T10:17:22.295+0800 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
    2021-01-13T10:17:22.295+0800 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
    2021-01-13T10:17:22.295+0800 I CONTROL [initandlisten]
    2021-01-13T10:17:22.296+0800 I CONTROL [initandlisten]
    2021-01-13T10:17:22.296+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
    2021-01-13T10:17:22.296+0800 I CONTROL [initandlisten] ** We suggest setting it to 'never'
    2021-01-13T10:17:22.296+0800 I CONTROL [initandlisten]
    2021-01-13T10:17:22.296+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
    2021-01-13T10:17:22.296+0800 I CONTROL [initandlisten] ** We suggest setting it to 'never'
    2021-01-13T10:17:22.296+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()
    ---

    >exit

    bye

    [root@vmcentos7-1 ~]# firewall-cmd --add-port=27017/tcp --permanent
    success
    [root@vmcentos7-1 ~]# firewall-cmd --reload
    success
    [root@vmcentos7-1 ~]# firewall-cmd --list-all
    public (active)
    target: default
    icmp-block-inversion: no
    interfaces: eth0
    sources:
    services: dhcpv6-client ssh
    ports: 27017/tcp
    protocols:
    masquerade: no
    forward-ports:
    source-ports:
    icmp-blocks:
    rich rules:

    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:

    设置所有地址可访问,之后可能被锁死,删除锁文件和日志

    rm /var/lib/mongo/mongod.lock

    rm /var/log/mongodb/mongod.log

    修复启动+启动

    [root@vmcentos7-1 ~]# mongod -f /etc/mongod.conf --repair
    about to fork child process, waiting until server is ready for connections.
    forked process: 3307
    child process started successfully, parent exiting
    [root@vmcentos7-1 ~]# mongod -f /etc/mongod.conf
    about to fork child process, waiting until server is ready for connections.
    forked process: 3343
    child process started successfully, parent exiting
    [root@vmcentos7-1 ~]# mongo

     连接成功,其它的正在探索!

    开机不能启动,权限:

    [root@vmcentos7-1 ~]# ll /var/lib/mongo
    总用量 380
    -rw-------. 1 mongod mongod 36864 1月 13 15:11 collection-0--3478603401700897754.wt
    -rw-------. 1 mongod mongod 36864 1月 13 15:11 collection-2--3478603401700897754.wt
    -rw-------. 1 mongod mongod 20480 1月 13 15:11 collection-2-942109184991825118.wt
    -rw-------. 1 mongod mongod 24576 1月 13 15:11 collection-4--3478603401700897754.wt
    drwx------. 2 mongod mongod 216 1月 13 15:11 diagnostic.data
    -rw-------. 1 root root 36864 1月 13 15:11 index-0--5498961700509034947.wt
    -rw-------. 1 root root 24576 1月 13 15:11 index-1--5498961700509034947.wt
    -rw-------. 1 root root 12288 1月 13 15:11 index-2--5498961700509034947.wt
    -rw-------. 1 root root 20480 1月 13 15:11 index-3--5498961700509034947.wt
    -rw-------. 1 root root 20480 1月 13 15:11 index-4--5498961700509034947.wt
    drwx------. 2 mongod mongod 110 1月 13 13:02 journal
    -rw-------. 1 mongod mongod 36864 1月 13 15:11 _mdb_catalog.wt
    -rw-------. 1 mongod mongod 0 1月 13 15:11 mongod.lock
    -rw-------. 1 mongod mongod 36864 1月 13 15:11 sizeStorer.wt
    -rw-------. 1 mongod mongod 114 1月 13 10:17 storage.bson
    -rw-------. 1 mongod mongod 46 1月 13 10:17 WiredTiger
    -rw-------. 1 root root 4096 1月 13 15:11 WiredTigerLAS.wt
    -rw-------. 1 mongod mongod 21 1月 13 10:17 WiredTiger.lock
    -rw-------. 1 root root 1250 1月 13 15:11 WiredTiger.turtle
    -rw-------. 1 mongod mongod 61440 1月 13 15:11 WiredTiger.wt

    chown -R mongod:mongod /var/lib/mongo/*

    systemctl start mongod.service

    reboot后成功

  • 相关阅读:
    如何利用京东云的对象存储(OSS)上传下载文件
    2017年4月8日Office 365 使用CSV文件导入邮件组
    在Office 365 的如何给管理员赋予查看所有人邮箱的权限的Powershell
    Office 365 Powershell 连接命令
    Office365创建通讯组
    国际版删除域名的步骤
    如何停止AAD服务
    导出Office365中的组及成员
    AWS/阿里/Azure,云厂商价格大PK
    OA系统与Exchange 日历打通
  • 原文地址:https://www.cnblogs.com/xwhgr/p/14270688.html
Copyright © 2011-2022 走看看