咱們的系統版本爲 CentOS Linux release 7.3.1611 (Core)
node
下載地址:http://mirrors.aliyun.com/mongodb/yum/redhat/ ,能夠根據本身的系統版本選擇。
我選擇的路徑:http://mirrors.aliyun.com/mongodb/yum/redhat/7/mongodb-org/3.2/x86_64/RPMS/ 。linux
我選擇 mongodb 的版本是3.2.6
,軟件包以下:mongodb
mongodb-org-3.2.6-1.el7.x86_64.rpm
mongodb-org-mongos-3.2.6-1.el7.x86_64.rpm
mongodb-org-server-3.2.6-1.el7.x86_64.rpm
mongodb-org-shell-3.2.6-1.el7.x86_64.rpm
mongodb-org-tools-3.2.6-1.el7.x86_64.rpmshell
yum install *.rpm
install -o mongod -g mongod -d /data/mongodb
修改dbPath 和註釋掉 bindIP數據庫
storage: dbPath: /data/mongodb journal: enabled: true net: port: 27017 # bindIp: 127.0.0.1
systemctl start mongod chkconfig mongod on
[root@mbasic ~]# netstat -tlnp Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 16640/sshd tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1924/master tcp 0 0 0.0.0.0:10050 0.0.0.0:* LISTEN 16724/zabbix_agentd tcp 0 0 0.0.0.0:27017 0.0.0.0:* LISTEN 11188/mongod
[root@mbasic ~]# mongo MongoDB shell version: 3.2.6 connecting to: test Server has startup warnings: 2018-07-31T17:40:28.137+0800 I CONTROL [initandlisten] 2018-07-31T17:40:28.137+0800 I CONTROL [initandlisten] ** WARNING: You are running on a NUMA machine. 2018-07-31T17:40:28.137+0800 I CONTROL [initandlisten] ** We suggest launching mongod like this to avoid performance problems: 2018-07-31T17:40:28.137+0800 I CONTROL [initandlisten] ** numactl --interleave=all mongod [other options] 2018-07-31T17:40:28.138+0800 I CONTROL [initandlisten] 2018-07-31T17:40:28.138+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'. 2018-07-31T17:40:28.138+0800 I CONTROL [initandlisten] ** We suggest setting it to 'never' 2018-07-31T17:40:28.138+0800 I CONTROL [initandlisten] 2018-07-31T17:40:28.138+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'. 2018-07-31T17:40:28.138+0800 I CONTROL [initandlisten] ** We suggest setting it to 'never' 2018-07-31T17:40:28.138+0800 I CONTROL [initandlisten] 2018-07-31T17:40:28.138+0800 I CONTROL [initandlisten] ** WARNING: soft rlimits too low. rlimits set to 4096 processes, 64000 files. Number of processes should be at least 32000 : 0.5 times number of files. 2018-07-31T17:40:28.138+0800 I CONTROL [initandlisten]
從中間咱們會看到好多警告,咱們一一來進行修改一下。vim
自CentOS6版本開始引入了Transparent Huge Pages(THP),從CentOS7版本開始,該特性默認就會啓用。儘管THP的本意是爲提高內存的性能,不過某些數據庫廠商仍是建議直接關閉THP(好比說Oracle、MariaDB、MongoDB等),不然可能會致使性能出現降低。ssh
首先檢查THP的啓用狀態:tcp
[root@mbasic ~]# cat /sys/kernel/mm/transparent_hugepage/defrag [always] madvise never [root@mbasic ~]# cat /sys/kernel/mm/transparent_hugepage/enabled [always] madvise never
這個狀態就說明都是啓用的。ide
咱們這個時候固然能夠逐個修改上述兩文件,來禁用THP,性能
臨時解決辦法
記得重啓mongodb
echo never >> /sys/kernel/mm/transparent_hugepage/enabled echo never >> /sys/kernel/mm/transparent_hugepage/defrag
永久生效
編輯/etc/rc.d/rc.local
文件:
增長下列內容:
if test -f /sys/kernel/mm/transparent_hugepage/enabled; then echo never > /sys/kernel/mm/transparent_hugepage/enabled fi if test -f /sys/kernel/mm/transparent_hugepage/defrag; then echo never > /sys/kernel/mm/transparent_hugepage/defrag fi
echo "mongod soft nofile 64000" >> /etc/security/limits.conf echo "mongod hard nofile 64000" >> /etc/security/limits.conf echo "mongod soft nproc 32000" >> /etc/security/limits.conf echo "mongod hard nproc 32000" >> /etc/security/limits.conf
由於啓動腳本里面已經斷定好了,咱們以前是最小化安裝系統,因此咱們只須要安裝 numactl。
yum install numactl -y
操做完以後,重啓mongodb便可。
MongoDB 提供了 linux 各發行版本 64 位的安裝包,你能夠在官網下載安裝包。
下載地址:https://www.mongodb.com/download-center#community ,你們可使用最新版本,也能夠選擇其餘版本。
我這裏選擇的是和上面 rpm 安裝同樣的版本,3.2.6
wget http://downloads.mongodb.org/linux/mongodb-linux-x86_64-rhel70-3.2.6.tgz
tar xf mongodb-linux-x86_64-rhel70-3.2.6.tgz mv mongodb-linux-x86_64-rhel70-3.2.6 /usr/local/mongodb
# vim /etc/profile.d/mongodb.sh export PATH=$PATH:/usr/local/mongodb/bin
source /etc/profile.d/mongodb.sh
mkdir -p /data/mongodb
/data/db 是 MongoDB 默認的啓動的數據庫路徑,若是你的數據庫目錄不是/data/db,能夠經過 --dbpath 來指定。
mongod --dbpath=/data/mongodb
[root@datanode3 ~]# mongo MongoDB shell version: 3.2.6 connecting to: test Welcome to the MongoDB shell. For interactive help, type "help". For more comprehensive documentation, see http://docs.mongodb.org/ Questions? Try the support group http://groups.google.com/group/mongodb-user >
推薦使用 rpm 包安裝,不少腳本都已經給咱們設定好了。