资讯专栏INFORMATION COLUMN

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

liujs / 493人阅读

摘要:安装准备安装设置安装源国内使用阿里云镜像源安装修改默认配置可选同时注释掉只监听的设置修改为数据存储目录,并确保用户可读写默认监听本地,注释掉创建数据库登录数据库创建数据库安装请参考

安装准备

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*/aserver 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

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  
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...

文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/19266.html

相关文章

  • CentOS7安装mongoDB3

    摘要:安装创建,然后直接有安装创建文件并编辑文件文件内容为保存文件,然后运行一下命令安装完成后,启动这个方法参考官网的教程系统的方法应该基本类似安装图形化管理界面都说不错,但是我发现我这边网络根本登不了官网,而且和的链接似乎还 安装mongoDB 创建/etc/yum.repos.d/mongodb-org-3.4.repo,然后直接有yum安装 #创建文件并编辑文件 vi /etc/yum...

    iKcamp 评论0 收藏0
  • CentOS7安装mongoDB3

    摘要:安装创建,然后直接有安装创建文件并编辑文件文件内容为保存文件,然后运行一下命令安装完成后,启动这个方法参考官网的教程系统的方法应该基本类似安装图形化管理界面都说不错,但是我发现我这边网络根本登不了官网,而且和的链接似乎还 安装mongoDB 创建/etc/yum.repos.d/mongodb-org-3.4.repo,然后直接有yum安装 #创建文件并编辑文件 vi /etc/yum...

    zoomdong 评论0 收藏0

发表评论

0条评论

最新活动
阅读需要支付1元查看
<