CentOS7安装使用MongoDB 3.4 单节点(for Hygieia)

安装准备

  • NUMA Settings

    Running MongoDB on a system with Non-Uniform Access Memory (NUMA) can cause a number of operational problems, including slow performance for periods of time and high system process usage.

    sysctl -w vm.zone_reclaim_mode=0
  • Kernel and File Systems

    When running MongoDB in production on Linux, you should use Linux kernel version 2.6.36 or later,
    with either the XFS or EXT4 filesystem. If possible, use XFS as it generally performs better with MongoDB.

    XFS is the default file system for CentOS7.

  • DNS settings

    cat > /etc/resolv.conf << EOF
    nameserver 172.20.224.134
    EOF
  • NTP Settings

    Use the Network Time Protocol (NTP) to synchronize time among your hosts. This is especially important in sharded clusters.

    yum -y install chrony
    #sync time from local time server
    sed -i '/^server*/d' /etc/chrony.conf
    sed -i -e '/^# Please consider*/a\server ntp01' /etc/chrony.conf
    systemctl enable chronyd && systemctl restart chronyd
  • Turn off Atime

    Turn off atime for the storage volume containing the database files.
    add mount option "noatime,nodiratime" in /etc/fstab

    vim /etc/fstab
    /dev/mapper/VolGroup-lv_data /data     xfs    defaults,noatime,nodiratime     1 1
  • ulimt settings

    Set the file descriptor limit, -n, and the user process limit (ulimit), -u, above 20,000, according to the suggestions in the ulimit reference.

    #check ulimit
    ulimit -a
    
    #set ulimit for mongod
    cat >> /etc/security/limits.conf << EOF
     mongod soft nproc 65535
     mongod hard nproc 65535
    EOF
  • Disable Transparent Huge Pages

    MongoDB performs better with normal (4096 bytes) virtual memory pages.

    echo never > /sys/kernel/mm/transparent_hugepage/enabled;
    echo never > /sys/kernel/mm/transparent_hugepage/defrag;
    chmod +x /etc/rc.d/rc.local

    CentOS7安装使用MongoDB 3.4 单节点(for Hygieia)

    For CentOS 6 , refer to Disable Transparent Huge Pages

  • Disable selinux

    It's better to set selinux permissive ranther than disabled

    sed -i s/^SELINUX=.*/SELINUX=permissive/g /etc/selinux/config
  • Disable iptables

    service iptables stop && chkconfig iptables off
    service ip6tables stop && chkconfig ip6tables off
  • sshd tunning

    disable dns search when connecting to this server;
    disable PasswordAuthentication confirm when ssh to other servers.

    sed -i 's/^#UseDNS yes/UseDNS no/' /etc/ssh/sshd_config
    sed -i 's/^#PasswordAuthentication no/PasswordAuthentication yes/g' /etc/ssh/sshd_config
  • Set the readahead setting

    Setting a higher readahead benefits sequential I/O operations. However, since MongoDB disk access patterns are generally random, setting a higher readahead provides limited benefit or performance degradation.

    • For the WiredTiger storage engine, a readahead of 0 or 16 provides optimal MongoDB performance.
    • For the MMAPv1 storage enginem, A readahead of 32 (16 kB) often works well.
    #get the readahead settings of block device
    blockdev --report
    #change the readahead settings
    blockdev --setra <value> <device>
    blockdev --setra  256 /dev/xvda

安装mongodb

  • 设置安装yum源

    国内使用阿里云镜像源

    cat > /etc/yum.repos.d/mongodb-org-3.4.repo << EOF
    [mongodb-org-3.4]
    name=MongoDB Repository
    #baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.4/x86_64/
    baseurl=https://mirrors.aliyun.com/mongodb/yum/redhat/\$releasever/mongodb-org/3.4/x86_64/
    gpgcheck=0
    enabled=1
    gpgkey=https://www.mongodb.org/static/pgp/server-3.4.asc
    EOF
  • 安装mongodb

    yum -y install mongodb-org
    systemctl enable mongod
    systemctl start mongod
  • 修改默认配置(可选)

    同时注释掉只监听localhost的设置:

    mkdir -pv /data/mongodb/storage
    chown -R mongod /data/mongodb/storage

    vim /etc/mongod.conf

    # Where and how to store data.
    storage:
      dbPath: /data/mongodb/storage  #修改为数据存储目录,并确保mongod用户可读写
      journal:
        enabled: true
     
    
    # network interfaces
    net:
      port: 27017
    #  bindIp: 127.0.0.1  #默认监听本地lo,注释掉interfaces.
    systemctl restart mongod
  • 创建数据库

    #登录数据库
    mongo
    
    #创建数据库dashboarddb
    use dashboarddb
    
    #Create db user
    db.createUser(
      {
        user: "dashboarduser",
        pwd: "dbpassword",
        roles: [
        {role: "readWrite", db: "dashboarddb"}
        ]
      })

centos6 安装mongodb请参考

http://wiki.timanetwork.com/p...

相关推荐