您好,登錄后才能下訂單哦!
這篇文章將為大家詳細講解有關MongoDB中怎么部署單實例,文章內容質量較高,因此小編分享給大家做個參考,希望大家閱讀完這篇文章后對相關知識有一定的了解。
yum install libcurl openssl
下載地址: https://www.mongodb.com/download-center?jmp=nav#community
將下載的tar包上傳至服務器/apps路徑下,如果不存在,請自行創建(注:目前以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 ---為了方便后續使用,我們重命名文檔
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
填寫如下內容
#!/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參數必須設置為never,否則,在登錄mongo shell的時候會有如下告警:
官方的配置鏈接:Disable Transparent Huge Pages (THP)【https://docs.mongodb.com/manual/tutorial/transparent-huge-pages/】
有時候Linux系統默認的open files(文件句柄)是1024, 但是mongod官網建議是64000,并且確實需要修改要不然會被坑(很不幸,我遇到了)
[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
可使用命令臨時修改
ulimit -n 64000
上述方法服務器重啟后將失效,永久辦法,修改/etc/security/limits.conf,添加mongo相關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 ---數據文件存放 $mkdir -p /data/logs/r1_logs ---創建日志文件路徑 $mkdir -p /data/pid ---mongodb進程id存放
$cd /home/mongo $vim .bash_profile
修改PATH變量
PATH=$PATH:$HOME/.local/bin:$HOME/bin:/apps/mongodb/bin ---添加上mongo程序路徑 export PATH
$source .bash_profile ---使環境變量生效
雖然里面有很多復雜的參數,不要著急,咱先啟動了再說,后續我會詳細講解各個常用參數的意義,因為我喜歡把配置文件mongodb.cnf(名字當然可以雖然叫)放在/etc目錄下,你也可以放到其他地方,隨意。
$sudo vim /etc/mongodb.cnf
填入如下內容
storage: dbPath: /data/dbdata/r1 #數據文件存放路徑 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 #進程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
編輯完后保存即可
賦予權限
$sudo chown -R mongo:mongo /etc/mongodb.cnf
$/apps/mongodb/bin/mongod -f /etc/mongodb.cnf
mongo 192.168.1.100:27018
我們可以通過檢查是否可以連接到mongo shell以驗證啟動成功,當然也可以直接看進程
$ps -ef | grep mongod
關于MongoDB中怎么部署單實例就分享到這里了,希望以上內容可以對大家有一定的幫助,可以學到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。