CentOS7.x下 MongoDB 安装

MongoDB相关

  • mongoDB 和 redis 一样 都是 键值存储,现持久化使用的redis,虑支持mongoDB 防止服务器的宕机玩家回档。

MongDB安装

MongDB官网

下载中心

选择在 CentOS7.x系列上安装

1.下载地址:

https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-3.2.9.tgz

2.下载:

wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-3.2.9.tgz

3.解压:

tar xvf mongodb-linux-x86_64-rhel70-3.2.9.tgz

4.重命名:

mv mongodb-linux-x86_64-rhel70-3.2.9 mongodb

5.拷贝到安装目录:

\cp -rf mongodb /usr/local/mongodb

6.增加环境变量:

vim /etc/profile

加入:

if [ -d /usr/local/mongodb/bin ]; then
    export PATH=$PATH:/usr/local/mongodb/bin/
fi

运行生效:

source /etc/profile

7.创建数据库文件目录:

阿里云的ssd 默认挂载 在/alidata1目录下

mkdir -p  /alidata1/dbdata/mongodb/db

8.禁用 Transparent Huge Pages (THP) 透明页

默认centos7 系统
查看透明页是否开启

RHEL使用:
cat /sys/kernel/mm/redhat_transparent_hugepage/enabled

CentOS 和其他系统使用:
cat /sys/kernel/mm/transparent_hugepage/enabled

返回:
[always] madvise never
always:开启
madvise:警示
never:关闭

临时禁用:

echo never >/sys/kernel/mm/transparent_hugepage/defrag
echo never >/sys/kernel/mm/transparent_hugepage/enabled

永久禁用:

方法1:

在grub中禁用

vim /etc/grub.conf

transparent_hugepage=never

方法2:

使用mongodb官网的脚本
在/etc/init.d/创建 disable-transparent-hugepages
vim /etc/init.d/disable-transparent-hugepages
=====>>
#!/bin/sh
### BEGIN INIT INFO
# Provides:          disable-transparent-hugepages
# Required-Start:    $local_fs
# Required-Stop:
# X-Start-Before:    mongod mongodb-mms-automation-agent
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Disable Linux transparent huge pages
# Description:       Disable Linux transparent huge pages, to improve
#                    database performance.
### END INIT INFO

case $1 in
  start)
    if [ -d /sys/kernel/mm/transparent_hugepage ]; then
      thp_path=/sys/kernel/mm/transparent_hugepage
    elif [ -d /sys/kernel/mm/redhat_transparent_hugepage ]; then
      thp_path=/sys/kernel/mm/redhat_transparent_hugepage
    else
      return 0
    fi

    echo 'never' > ${thp_path}/enabled
    echo 'never' > ${thp_path}/defrag

    unset thp_path
    ;;
esac

赋予运行权限

chmod 755 /etc/init.d/disable-transparent-hugepages

Ubuntu and Debian

sudo update-rc.d disable-transparent-hugepages defaults

SUSE

sudo insserv /etc/init.d/disable-transparent-hugepages

Red Hat, CentOS, Amazon Linux, and derivatives

sudo chkconfig --add disable-transparent-hugepages

查看 运行 chkconfig

Note: This output shows SysV services only and does not include native
      systemd services. SysV configuration data might be overridden by native
      systemd configuration.

  If you want to list systemd services use 'systemctl list-unit-files'.
  To see services enabled on particular target use
  'systemctl list-dependencies [target]'.

aegis           0:off   1:off   2:on    3:on    4:on    5:on    6:off
agentwatch      0:off   1:off   2:on    3:on    4:on    5:on    6:off
disable-transparent-hugepages   0:off   1:off   2:on    3:on    4:on    5:on    6:off
netconsole      0:off   1:off   2:off   3:off   4:off   5:off   6:off
network         0:off   1:off   2:on    3:on    4:on    5:on    6:off
redis_6379      0:off   1:off   2:on    3:on    4:on    5:on    6:off

修改tuned 和ktune

使用centos7:

创建目录

sudo mkdir /etc/tuned/no-thp

修改配置

vim /etc/tuned/no-thp/tuned.conf

输入

#include=virtual-guest
include=throughput-performance

[vm]
transparent_hugepages=never

显示 配置 看是否有no-thp

tuned-adm list

切换模式

tuned-adm  profile no-thp

centos7 检测 开启情况

cat /sys/kernel/mm/transparent_hugepage/enabled
cat /sys/kernel/mm/transparent_hugepage/defrag

或者:
cat /sys/kernel/mm/redhat_transparent_hugepage/enabled
cat /sys/kernel/mm/redhat_transparent_hugepage/defrag

你可能感兴趣的:(CentOS7.x下 MongoDB 安装)