(1)redhat或cnetos6.2以上系統
(2)系統開發包完整
(3)ip地址和hosts文件解析正常
(4)iptables防火牆&SElinux關閉
(5)關閉大頁內存機制linux
root用戶下,在vi /etc/rc.local最後添加以下代碼mongodb
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
其餘系統關閉參照官方文檔:shell
爲何要關閉?vim
Transparent Huge Pages (THP) is a Linux memory management system that reduces the overhead of Translation Lookaside Buffer (TLB) lookups on machines with large amounts of memory by using larger memory pages. However, database workloads often perform poorly with THP, because they tend to have sparse rather than contiguous memory access patterns. You should disable THP on Linux machines to ensure best performance with MongoDB.
修改/etc/security/limits.conf安全
#* - nofile 65535
(1)建立所需用戶和組bash
groupadd -g 800 mongod useradd -u 801 -g mongod mongod passwd mongod
(2)建立mongodb所需目錄結構網絡
mkdir -p /mongodb/bin mkdir -p /mongodb/conf mkdir -p /mongodb/log mkdir -p /mongodb/data
(3)上傳並解壓軟件到指定位置app
cd /root/mongodb-linux-x86_64-rhel62-3.2.16/bin cp * /mongodb/bin
(4)設置目錄結構權限ide
chown -R mongod:mongod /mongodb
(5)設置用戶環境變量spa
su - mongod vi .bash_profile export PATH=/mongodb/bin:$PATH source .bash_profile
(6)啓動mongodb
mongod --dbpath=/mongodb/data --logpath=/mongodb/log/mongodb.log --port=27017 --logappend --fork
(7)登陸mongodb
[mongod@server2 ~]$ mongo
注:鏈接以後會有warning,須要修改(使用root用戶)
vim /etc/security/limits.conf #* - nofile 65535
(8)重啓生效
reboot
(9)使用配置文件
vim /mongodb/conf/mongodb.conf logpath=/mongodb/log/mongodb.log dbpath=/mongodb/data port=27017 logappend=true fork=true ----------- 關閉mongodb mongod -f /mongodb/conf/mongodb.conf --shutdown 使用配置文件啓動mongodb mongod -f /mongodb/conf/mongodb.conf
(10)YAML模式:
-- NOTE: YAML does not support tab characters for indentation: use spaces instead. --系統日誌有關 systemLog: destination: file path: "/mongodb/log/mongodb.log" --日誌位置 logAppend: true --日誌以追加模式記錄 --數據存儲有關 storage: journal: enabled: true dbPath: "/mongodb/data" --數據路徑的位置 -- 進程控制 processManagement: fork: true --後臺守護進程 pidFilePath: <string> --pid文件的位置,通常不用配置,能夠去掉這行,自動生成到data中 --網絡配置有關 net: bindIp: <ip> -- 監聽地址,若是不配置這行是監聽在0.0.0.0 port: <port> -- 端口號,默認不配置端口號,是27017 -- 安全驗證有關配置 security: authorization: enabled --是否打開用戶名密碼驗證
YAML例子
vim /mongodb/conf/mongo.conf systemLog: destination: file path: "/mongodb/log/mongodb.log" logAppend: true storage: journal: enabled: true dbPath: "/mongodb/data/" processManagement: fork: true net: port: 27017 mongod -f /mongodb/conf/mongodb.conf --shutdown mongod -f /mongodb/conf/mongo.conf