Linux CentOS6.x 安裝mongodb3.4.x

一、系統(tǒng)及安裝說(shuō)明

系統(tǒng):CentOS6.x_x64,mongodb-3.4.10。
mongodb官方下載地址 :
[https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel62-3.4.10.tgz]
(http://www.memcached.org/files/memcached-1.5.3.tar.gz)。

本次安裝選擇編輯yum安裝。

二、配置官方y(tǒng)um庫(kù)

1>創(chuàng)建yum安裝庫(kù)文件

修改文件mongodb-3.4.repo

vim /etc/yum.repos.d/mongodb-org-3.4.repo #創(chuàng)建之后可以直接使用yum安裝

添加下面的內(nèi)容,wq保存。

[mongodb-org-3.4]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.4/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-3.4.asc

當(dāng)設(shè)置gpgcheck=0時(shí),gpgkey路徑可以不設(shè)置

2>yum安裝

#yum install -y mongodb-org

#當(dāng)出現(xiàn)以下即為安裝中

微信截圖_20180801102133.png

三、自定義安裝配置

1>安裝成功后,數(shù)據(jù)和日志目錄默認(rèn)是在 /var/lib/mongo 和 /var/log/mongodb,為方便管理我們可進(jìn)行自定義。以 /data/mongodb 為例

2>編輯/etc/mongod.conf

#vim /etc/mongod.conf

# mongod.conf

# for documentation of all options, see:

# http://docs.mongodb.org/manual/reference/configuration-options/

# where to write logging data.

systemLog:

destination: ``file

logAppend: ``true

path: ``/data/mongodb/log/mongod``.log

# Where and how to store data.

storage:

dbPath: ``/data/mongodb/data

journal:

enabled: ``true

# engine:

# mmapv1:

# wiredTiger:

# how the process runs

processManagement:

fork: ``true # fork and run in background

pidFilePath: ``/var/run/mongodb/mongod``.pid ``# location of pidfile

# network interfaces

net:

port: 27017

bindIp: 127.0.0.1 ``# Listen to local interface only, comment to listen on all interfaces.

#security:

#operationProfiling:

#replication:

#sharding:

## Enterprise-Only Options

#auditLog:

#snmp

3>創(chuàng)建目錄

#mkdir -p /data/mongodb/data

#mkdir -p /data/mongodb/log

#chown mongod.mongod /data/mongodb -R #修改權(quán)限,否則mongo有可能啟動(dòng)不了

四、啟動(dòng)并測(cè)試

1>啟動(dòng)mongod

#service mongod start|stop|restart

2>添加到開(kāi)機(jī)啟動(dòng)項(xiàng)

#chkconfig --add mongod

#chkconfig mongod on

3>登錄測(cè)試

#mongo --host 127.0.0.1

MongoDB shell version v3.4.10

connecting to: mongodb:``//127``.0.0.1:27017/

MongoDB server version: 3.4.10

Server has startup warnings:

2017-12-06T10:41:30.462+0800 I STORAGE [initandlisten]

2017-12-06T10:41:30.462+0800 I STORAGE [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine

2017-12-06T10:41:30.462+0800 I STORAGE [initandlisten] ** See http:``//dochub``.mongodb.org``/core/prodnotes-filesystem

2017-12-06T10:41:30.901+0800 I CONTROL [initandlisten]

2017-12-06T10:41:30.902+0800 I CONTROL [initandlisten] ** WARNING: Access control is not enabled ``for the database.

2017-12-06T10:41:30.902+0800 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.

2017-12-06T10:41:30.902+0800 I CONTROL [initandlisten]

2017-12-06T10:41:30.902+0800 I CONTROL [initandlisten]

2017-12-06T10:41:30.902+0800 I CONTROL [initandlisten] ** WARNING: ``/sys/kernel/mm/transparent_hugepage/enabled is ``'always'``.

2017-12-06T10:41:30.902+0800 I CONTROL [initandlisten] ** We suggest setting it to ``'never'

2017-12-06T10:41:30.902+0800 I CONTROL [initandlisten]

2017-12-06T10:41:30.902+0800 I CONTROL [initandlisten] ** WARNING: ``/sys/kernel/mm/transparent_hugepage/defrag is ``'always'``.

2017-12-06T10:41:30.902+0800 I CONTROL [initandlisten] ** We suggest setting it to ``'never'

2017-12-06T10:41:30.902+0800 I CONTROL [initandlisten]

2017-12-06T10:41:30.902+0800 I CONTROL [initandlisten] ** WARNING: soft rlimits too low. rlimits ``set to 1024 processes, 65535 files. Number of processes should be at least 32767.5 : 0.5 ``times number of files.

2017-12-06T10:41:30.902+0800 I CONTROL [initandlisten]

> show dbs

admin 0.000GB

local 0.000GB

>

五、問(wèn)題排錯(cuò)

1> 登錄mongodb數(shù)據(jù)庫(kù)時(shí),如果出現(xiàn)以下錯(cuò)誤

MongoDB shell version v3.4.10

connecting to: mongodb:``//127``.0.0.1:27017

MongoDB server version: 3.4.10

Server has startup warnings:

2017-12-06T10:46:46.575+0800 I STORAGE [initandlisten]

2017-12-06T10:46:46.575+0800 I STORAGE [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine

2017-12-06T10:46:46.575+0800 I STORAGE [initandlisten] ** See http:``//dochub``.mongodb.org``/core/prodnotes-filesystem

2017-12-06T10:46:46.955+0800 I CONTROL [initandlisten]

2017-12-06T10:46:46.955+0800 I CONTROL [initandlisten] ** WARNING: Access control is not enabled ``for the database.

2017-12-06T10:46:46.955+0800 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.

2017-12-06T10:46:46.955+0800 I CONTROL [initandlisten]

2017-12-06T10:46:46.956+0800 I CONTROL [initandlisten]

2017-12-06T10:46:46.956+0800 I CONTROL [initandlisten] ** WARNING: ``/sys/kernel/mm/transparent_hugepage/enabled is ``'always'``.

2017-12-06T10:46:46.956+0800 I CONTROL [initandlisten] ** We suggest setting it to ``'never'

2017-12-06T10:46:46.956+0800 I CONTROL [initandlisten]

2017-12-06T10:46:46.956+0800 I CONTROL [initandlisten] ** WARNING: ``/sys/kernel/mm/transparent_hugepage/defrag is ``'always'``.

2017-12-06T10:46:46.956+0800 I CONTROL [initandlisten] ** We suggest setting it to ``'never'

2017-12-06T10:46:46.956+0800 I CONTROL [initandlisten]

2017-12-06T10:46:46.956+0800 I CONTROL [initandlisten] ** WARNING: soft rlimits too low. rlimits ``set to 1024 processes, 65535 files. Number of processes should be at least 32767.5 : 0.5 ``times number of files.

環(huán)境不通解決辦法也不通,詳情請(qǐng)參照官方文檔 https://docs.mongodb.com/manual/tutorial/transparent-huge-pages/

2>創(chuàng)建腳本

vim /etc/init.d/disable-transparent-hugepages

#!/bin/bash### 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 re=``'^[0-1]+$'

if [[ $(``cat ${thp_path}``/khugepaged/defrag``) =~ $re ]]

then

# RHEL 7

echo 0 > ${thp_path}``/khugepaged/defrag else

# RHEL 6

echo 'no' > ${thp_path}``/khugepaged/defrag fi

unset re ``unset thp_path ;;

esac

添加到開(kāi)機(jī)服務(wù)

#chmod +x /etc/init.d/disable-transparent-hugepages

#chkconfig --add disable-transparent-hugepages

3>創(chuàng)建編輯 /etc/tune-profiles/no-thp/ktune.sh

vim /etc/tune-profiles/no-thp/ktune.sh

#echo "set_transparent_hugepages never" > ktune.sh

#chmod +x ktune.sh

#tuned-adm profile no-thp

#如果提示找不到命令請(qǐng)執(zhí)行yum install tuned -y

vim /etc/security/limits.conf

添加

mongod soft nofile 64000

mongod hard nofile 64000

mongod soft nproc 32000

mongod hard nproc 32000

重啟系統(tǒng) sudo reboot

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • mongodb 3.X安裝詳細(xì)過(guò)程 一、準(zhǔn)備安裝 mongodb的安裝方式,我通常使用二進(jìn)制包的方式,內(nèi)網(wǎng)不能配置...
    泡菜愛(ài)上WaSabi閱讀 496評(píng)論 0 1
  • Mac MongoDB安裝 一、安裝 MongoDB的安裝方法有很多,本文以官方文檔中的兩種方法為準(zhǔn)。 1. 手動(dòng)...
    Keriy閱讀 16,905評(píng)論 2 7
  • 1、MongoDB的RPM包介紹: MongoDB官方提供的包如下,并且這些包也支持yum方式安裝,Mongo提供...
    張偉科閱讀 872評(píng)論 0 1
  • 搭建note 1 --初始環(huán)境,啟動(dòng)容器 在服務(wù)器家目錄拉取mynote代碼: git clone git@git...
    ronnyjiang閱讀 1,012評(píng)論 0 0
  • 關(guān)于Mongodb的全面總結(jié) MongoDB的內(nèi)部構(gòu)造《MongoDB The Definitive Guide》...
    中v中閱讀 32,316評(píng)論 2 89

友情鏈接更多精彩內(nèi)容