侧边栏壁纸
博主头像
落叶人生博主等级

走进秋风,寻找秋天的落叶

  • 累计撰写 130562 篇文章
  • 累计创建 28 个标签
  • 累计收到 9 条评论
标签搜索

目 录CONTENT

文章目录

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

2023-12-01 星期五 / 0 评论 / 0 点赞 / 43 阅读 / 5260 字

安装准备 NUMA Settings Running MongoDB on a system with Non-Uniform Access Memory (NUMA) can cause a

安装准备

  • 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 << EOFnameserver 172.20.224.134EOF
  • 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 serversed -i '/^server*/d' /etc/chrony.confsed -i -e '/^# Please consider*/a/server ntp01' /etc/chrony.confsystemctl 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 ulimitulimit -a#set ulimit for mongodcat >> /etc/security/limits.conf << EOFmongod soft nproc 65535mongod hard nproc 65535EOF
  • 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

    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 offservice 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_configsed -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=0enabled=1gpgkey=https://www.mongodb.org/static/pgp/server-3.4.ascEOF
  • 安装mongodb

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

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

    mkdir -pv /data/mongodb/storagechown -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 interfacesnet:port: 27017#  bindIp: 127.0.0.1  #默认监听本地lo,注释掉interfaces.
    systemctl restart mongod
  • 创建数据库

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

centos6 安装mongodb请参考

http://wiki.timanetwork.com/pages/viewpage.action?pageId=3507421

广告 广告

评论区