Posts Tagged ‘mongodb’

MongoDB 建置及調教

shtzeng Posted in Research,Tags: ,
0

人很懶
做過的事情
參考過的資料
沒留下來就會煙飛雲滅 XD

這邊要補的是當初怎麼建的 MongoDB
第一部分是安裝 MongoDB,我是用 Percona 版本的
先把 Percona 的 key 加入

apt-key adv --keyserver keys.gnupg.net --recv-keys 1C4CBDCDCD2EFD2A

再來是加 source list 讓 apt 可以抓的到
在 /etc/apt/sources.list.d/percona.list 加上 (假設我是用 Ubuntu 14.04 LTS)

#
deb http://repo.percona.com/apt trusty main
deb-src http://repo.percona.com/apt trusty main

然後更新並安裝

apt-get update
apt-get install percona-server-mongodb-32

改設定檔,我是用 rocksdb engine

storage:
  dbPath: /var/lib/mongodb
  journal:
    enabled: true
  engine: rocksdb
systemLog:
  destination: file
  logAppend: true
  path: /var/log/mongodb/mongod.log
processManagement:
  fork: true
  pidFilePath: /var/run/mongod.pid
net:
  port: 27017
  bindIp: 0.0.0.0

到這邊就大功告成了, MongoDB 裝好了
安裝的部分可以參考各 blog
再來就是系統調教的部分了
首先要增加 /etc/init/mongo_vm_settings.conf ,讓 THP 預設關掉 (這是官方強烈建議關掉的)

# Ubuntu upstart file at /etc/init/mongod_vm_settings.conf

start on runlevel [2345]
stop on runlevel [!2345]

script
  echo "never" > /sys/kernel/mm/transparent_hugepage/enabled
  echo "never" > /sys/kernel/mm/transparent_hugepage/defrag
end script

再來是 /etc/sysctl.d/20-mongodb.conf,其中 vm.swappiness 建議是為 0 關掉,但因為存在一些 bug ,設定成超小的 1% 比較保險

vm.swappiness = 1
vm.dirty_ratio = 10
vm.dirty_background_ratio = 3
vm.dirty_expire_centisecs = 12000
net.core.somaxconn = 4096
net.ipv4.tcp_fin_timeout = 30
net.ipv4.tcp_keepalive_intvl = 30
net.ipv4.tcp_keepalive_time = 120
net.ipv4.tcp_max_syn_backlog = 4096

然後設定 /etc/security/limits.d/mongod.conf ,方便跑起來的時候不會檔案不夠開之類的

mongod       soft        nproc        64000
mongod       hard        nproc        64000
mongod       soft        nofile       64000
mongod       hard        nofile       64000

最後設定硬碟檔案區塊大小

# set deadline scheduler and 16kb read-ahead for /dev/xvda
ACTION=="add|change", KERNEL=="xvda", ATTR{queue/scheduler}="deadline", ATTR{bdi/read_ahead_kb}="16"

這樣就解決了XD
調教部分可以參考https://www.percona.com/blog/2016/08/12/tuning-linux-for-mongodb/
又把一個事情記完了 XD

Munin Plugin for MongoDB

shtzeng Posted in Research,Tags: , ,
0

所謂的凡走過必留下痕跡
不留痕跡很難找到當初設定的方法的

簡單來說,執行完下面的指令就加好 plugin 了,我的環境是 Ubuntu 14.04.5 LTS devil
 

sudo apt-get install python-pip build-essential python-dev git -y
sudo pip install pymongo
git clone https://github.com/comerford/mongo-munin.git /tmp/mongo-munin
sudo cp /tmp/mongo-munin/mongo_* /usr/share/munin/plugins
sudo ln -sf /usr/share/munin/plugins/mongo_btree /etc/munin/plugins/mongo_btree
sudo ln -sf /usr/share/munin/plugins/mongo_conn /etc/munin/plugins/mongo_conn
sudo ln -sf /usr/share/munin/plugins/mongo_lock /etc/munin/plugins/mongo_lock
sudo ln -sf /usr/share/munin/plugins/mongo_mem /etc/munin/plugins/mongo_mem
sudo ln -sf /usr/share/munin/plugins/mongo_ops /etc/munin/plugins/mongo_ops
sudo ln -sf /usr/share/munin/plugins/mongo_docs /etc/munin/plugins/mongo_docs
sudo chmod +x /usr/share/munin/plugins/mongo_*

來源參考https://github.com/comerford/mongo-munin的README