您的位置:首页 > 数据库 > Mongodb

mongodb 4.4 单机安装

2021-02-25 17:44 766 查看

软件下载

社区版下载地址:https://www.mongodb.com/try/download/community
以下内容以二进制解压包为例介绍,官方文档地址:https://docs.mongodb.com/manual/tutorial/install-mongodb-on-red-hat-tarball/

安装前配置

一、系统准备

  1. redhat或cnetos6.2以上系统
  2. 系统开发包完整
  3. ip地址和hosts文件解析正常
  4. iptables防火墙&SElinux关闭
  5. 关闭大页内存机制
    echo never > /sys/kernel/mm/transparent_hugepage/enabled
    echo never > /sys/kernel/mm/transparent_hugepage/defrag

    永久关闭大页内存root用户下
    在vi /etc/rc.local最后添加如下代码
    if test -f /sys/kernel/mm/transparent_hugepage/enabled; then
    echo never > /sys/kernel/mm/transparent_hugepage/enabled
    fi
    if test -f /sys/kernel/mm/transparent_hugepage/defrag; then
    echo never > /sys/kernel/mm/transparent_hugepage/defrag
    fi
    其他系统关闭参照官方文档:https://docs.mongodb.com/manual/tutorial/transparent-huge-pages/
  6. 修改 vim /etc/security/limits.conf
*               -       nofile          65535
*               -       nproc           65536

7.创建所需用户和组

useradd mongod
passwd mongod

8.上传并解压软件到指定位置,设置权限

mkdir /app
cd /app
tar -zxvf mongodb-linux-x86_64-rhel70-4.4.4.tgz
ln -s mongodb mongodb-linux-x86_64-rhel70-4.4.4
chown -R mongod:mongod -R mongodb*

9.设置用户环境变量

su - mongod
vi .bash_profile
export PATH=/app/mongodb/bin:$PATH
source .bash_profile

单机安装

  1. 创建目录并赋权
    mkdir -p /mongodb/conf
    mkdir -p /mongodb/log
    mkdir -p /mongodb/data
    chown -R mongod:mongod /mongodb
  2. 编辑配置文件
    vim /mongodb/conf/mongodb.conf
    logpath=/mongodb/log/mongodb.log
    dbpath=/mongodb/data
    port=27017
    logappend=true
    fork=true
  3. 启动数据库
    mongod -f /mongodb/conf/mongodb.conf
  4. 连接数据库
    mongo
  5. 停止数据库
    mongod -f /mongodb/log/mongodb.log --shutdown
  6. systemd管理mongodb
    root用户
    cat > /etc/systemd/system/mongod.service <<EOF
    [Unit]
    Description=mongodb
    After=network.target remote-fs.target nss-lookup.target
    [Service]
    LimitNOFILE=65536
    LimitNPROC=65536
    User=mongod
    Type=forking
    ExecStart=/mongodb/bin/mongod --config /mongodb/conf/mongo.conf
    ExecReload=/bin/kill -s HUP $MAINPID
    ExecStop=/mongodb/bin/mongod --config /mongodb/conf/mongo.conf --shutdown
    PrivateTmp=true
    [Install]
    WantedBy=multi-user.target
    EOF
    #重启
    systemctl restart mongod
    #停止
    systemctl stop mongod
    #启动
    systemctl start mongod
  7. 配置文件(YMAL模式)
    https://docs.mongodb.com/manual/administration/configuration/
    --
    NOTE:
    YAML does not support tab characters for indentation: use spaces instead.
    --系统日志有关
    systemLog:
    destination: file
    path: "/mongodb/log/mongodb.log"    --日志位置
    logAppend: true                     --日志以追加模式记录
    --数据存储有关
    storage:
    journal:
    enabled: true
    dbPath: "/mongodb/data"            --数据路径的位置
    -- 进程控制
    processManagement:
    fork: true                         --后台守护进程
    pidFilePath: <string>              --pid文件的位置,一般不用配置,可以去掉这行,自动生成到data中
    --网络配置有关
    net:
    bindIp: <ip>                       -- 监听地址,如果不配置这行是监听在0.0.0.0
    port: <port>                       -- 端口号,默认不配置端口号,是27017
    -- 安全验证有关配置
    security:
    authorization: enabled              --是否打开用户名密码验证
    ------------------以下是复制集与分片集群有关----------------------
    replication:
    oplogSizeMB: <NUM>
    replSetName: "<REPSETNAME>"
    secondaryIndexPrefetch: "all"
    sharding:
    clusterRole: <string>
    archiveMovedChunks: <boolean>
    ---for mongos only
    replication:
    localPingThresholdMs: <int>
    sharding:
    configDB: <string>
    --
    ++++++++++++++++++++++
    YAML例子
    cat > /mongodb/conf/mongo.conf <<EOF
    systemLog:
    destination: file
    path: "/mongodb/log/mongodb.log"
    logAppend: true
    storage:
    journal:
    enabled: true
    dbPath: "/mongodb/data/"
    processManagement:
    fork: true
    net:
    port: 27017
    bindIp: 11.111.24.4,127.0.0.1
    EOF
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: