在ubuntu和多數linux發行版的包安裝源中MongoDB默認的版本是2.4,但2.4所使用的存儲引擎不支持collecitons級別的鎖,只支持database級別的,因此在開發中2.4版本的mongodb寫入時會形成鎖表的現象,致使數據庫性能低下,所以須要更新到3.4版本以上。linux
更新環境是 ubuntu 14.4 ,有兩種方式更新,可是要注意先備份數據庫,mongodump。。mongodb
方法一: apt installshell
1. 添加public key: 數據庫
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 2930ADAE8CAF5059EE73BB4B58712A2291FA4AD5ubuntu
2. 添加包源:bash
echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/ubuntu precise/mongodb-org/3.6 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.6.listcurl
3. 更新:ide
sudo apt-get update性能
4. 安裝:ui
sudo apt-get install -y mongodb-org
也能夠指定版本: sudo apt-get install -y mongodb-org=3.6.0 mongodb-org-server=3.6.0 mongodb-org-shell=3.6.0 mongodb-org-mongos=3.6.0 mongodb-org-tools=3.6.0
方法二: 二進制包安裝
1. 下載包:
curl -O https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.6.0.tgz
2. 解壓:
tar -zxvf mongodb-linux-x86_64-3.6.0.tgz
3. 建立目錄:
mkdir -p mongodb
cp -R -n mongodb-linux-x86_64-3.6.0/ mongodb
4. export path:
export PATH=<mongodb-install-directory>/bin:$PATH
最好放在 bashrc 或者 profile裏,不用每次都手動export
notes: 解決出現TPH warning的問題
在 /etc/init.d/ 目錄下建立 一個文件 /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
而後添加可執行權限:
sudo chmod 755 /etc/init.d/disable-transparent-hugepages
最後添加自啓動便可:
sudo update-rc.d disable-transparent-hugepages defaults