您好,登錄后才能下訂單哦!
這篇文章將為大家詳細(xì)講解有關(guān)MongoDB中怎么部署單實(shí)例,文章內(nèi)容質(zhì)量較高,因此小編分享給大家做個(gè)參考,希望大家閱讀完這篇文章后對(duì)相關(guān)知識(shí)有一定的了解。
yum install libcurl openssl
下載地址: https://www.mongodb.com/download-center?jmp=nav#community
將下載的tar包上傳至服務(wù)器/apps路徑下,如果不存在,請(qǐng)自行創(chuàng)建(注:目前以root登錄)
root#cd /apps root#tar -zxvf mongodb-linux-x86_64-rhel70-4.0.2.tgz root# ls -l drwxrwxr-x. 3 mongo mongo 86 Dec 8 18:34 mongodb-linux-x86_64-rhel70-4.0.2 -rw-rw-r--. 1 mongo mongo 82140922 Oct 24 22:03 mongodb-linux-x86_64-rhel70-4.0.2.tgz root# mv mongodb-linux-x86_64-rhel70-3.2.10 mongodb ---為了方便后續(xù)使用,我們重命名文檔
root#sudo systemctl stop firewalld root#sudo systemctl status firewalld
root#sudo cat /sys/kernel/mm/transparent_hugepage/enabled [always] madvise never root#sudo cat /sys/kernel/mm/transparent_hugepage/defrag [always] madvise never
root#sudo vim /etc/init.d/disable-transparent-hugepages
填寫如下內(nèi)容
#!/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
root#sudo chmod 755 /etc/init.d/disable-transparent-hugepages root#sudo chkconfig --add disable-transparent-hugepages
root#sudo cat /sys/kernel/mm/transparent_hugepage/enabled always madvise [never] root#sudo cat /sys/kernel/mm/transparent_hugepage/defrag always madvise [never]
注:transparent_hugepage參數(shù)必須設(shè)置為never,否則,在登錄mongo shell的時(shí)候會(huì)有如下告警:
官方的配置鏈接:Disable Transparent Huge Pages (THP)【https://docs.mongodb.com/manual/tutorial/transparent-huge-pages/】
有時(shí)候Linux系統(tǒng)默認(rèn)的open files(文件句柄)是1024, 但是mongod官網(wǎng)建議是64000,并且確實(shí)需要修改要不然會(huì)被坑(很不幸,我遇到了)
[mongo@mongodb01 ~]$ ulimit -a core file size (blocks, -c) 0 data seg size (kbytes, -d) unlimited scheduling priority (-e) 0 file size (blocks, -f) unlimited pending signals (-i) 31206 max locked memory (kbytes, -l) 64 max memory size (kbytes, -m) unlimited open files (-n) 1024 pipe size (512 bytes, -p) 8 POSIX message queues (bytes, -q) 819200 real-time priority (-r) 0 stack size (kbytes, -s) 8192 cpu time (seconds, -t) unlimited max user processes (-u) 1024 virtual memory (kbytes, -v) unlimited file locks (-x) unlimited
可使用命令臨時(shí)修改
ulimit -n 64000
上述方法服務(wù)器重啟后將失效,永久辦法,修改/etc/security/limits.conf,添加mongo相關(guān)4條配置信息
root#vim /etc/security/limits.conf #@student - maxlogins 4 mongo soft nproc 64000 mongo hard nproc 64000 mongo soft nofile 64000 mongo hard nofile 64000 # End of file
注:修改成功后重啟mongod生效
root#groupadd mongogrp root#useradd -g mongogrp mongo
root#mkdir /data root#chown -R mongo:mongogrp /data root#su mongo $mkdir -p /data/dbdata/r1 ---數(shù)據(jù)文件存放 $mkdir -p /data/logs/r1_logs ---創(chuàng)建日志文件路徑 $mkdir -p /data/pid ---mongodb進(jìn)程id存放
$cd /home/mongo $vim .bash_profile
修改PATH變量
PATH=$PATH:$HOME/.local/bin:$HOME/bin:/apps/mongodb/bin ---添加上mongo程序路徑 export PATH
$source .bash_profile ---使環(huán)境變量生效
雖然里面有很多復(fù)雜的參數(shù),不要著急,咱先啟動(dòng)了再說,后續(xù)我會(huì)詳細(xì)講解各個(gè)常用參數(shù)的意義,因?yàn)槲蚁矚g把配置文件mongodb.cnf(名字當(dāng)然可以雖然叫)放在/etc目錄下,你也可以放到其他地方,隨意。
$sudo vim /etc/mongodb.cnf
填入如下內(nèi)容
storage: dbPath: /data/dbdata/r1 #數(shù)據(jù)文件存放路徑 journal: enabled: true commitIntervalMs: 100 directoryPerDB: true engine: wiredTiger wiredTiger: engineConfig: directoryForIndexes: true systemLog: quiet: false path: /data/logs/r1_logs/r1.log #log日志路徑 destination: file logAppend: true processManagement: fork: true pidFilePath: /data/pid/r1.pid #進(jìn)程ID存放 net: port: 27018 maxIncomingConnections: 3000 wireObjectCheck: true #security: # keyFile: /data/key/r1 # authorization: enabled #replication: # oplogSizeMB: 10240 # replSetName: rs1 #operationProfiling: # slowOpThresholdMs: 100 # mode: slowOp
編輯完后保存即可
賦予權(quán)限
$sudo chown -R mongo:mongo /etc/mongodb.cnf
$/apps/mongodb/bin/mongod -f /etc/mongodb.cnf
mongo 192.168.1.100:27018
我們可以通過檢查是否可以連接到mongo shell以驗(yàn)證啟動(dòng)成功,當(dāng)然也可以直接看進(jìn)程
$ps -ef | grep mongod
關(guān)于MongoDB中怎么部署單實(shí)例就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,可以學(xué)到更多知識(shí)。如果覺得文章不錯(cuò),可以把它分享出去讓更多的人看到。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。