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
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容