Mongodb簡介及安裝部署配置

1、Mongodb簡介及安裝部署

Mongodb 邏輯結構:
Mongodb 邏輯結構 MySQL邏輯結構
庫database 庫
集合(collection) 表
文檔(document) 數據行

2、安裝前準備
(1)redhat或cnetos6.2以上系統
(2)系統開發包完整
(3)ip地址和hosts文件解析正常
(4)iptables防火牆&SElinux關閉
(5)關閉大頁內存機制
############################################################
root用戶下
在vi /etc/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

其他系統關閉參照官方文檔:

https://docs.mongodb.com/manual/tutorial/transparent-huge-pages/

爲什麼要關閉?
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.
##############################################

3、mongodb安裝
(1)創建所需用戶和組
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)上傳並解壓軟件到指定位置

上傳到:
cd /server/tools/
解壓:
tar xf mongodb-linux-x86_64-rhel70-3.2.16.tgz

拷貝目錄下bin程序到/mongodb/bin
cp -a /server/tools/mongodb-linux-x86_64-rhel70-3.2.16/bin/* /mongodb/bin

(4)設置目錄結構權限

chown -R mongod:mongod /mongodb

(5)設置用戶環境變量

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

(8)使用配置文件

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

(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 --是否打開用戶名密碼驗證

------------------以下是複製集與分片集羣有關----------------------
replication:
oplogSizeMB: <NUM>
replSetName: "<REPSETNAME>"
secondaryIndexPrefetch: "all"

sharding:
clusterRole: <string>
archiveMovedChunks: <boolean>

---for mongos only
replication:
localPingThresholdMs: <int>

sharding:
configDB: <string>


.........

++++++++++++++++++++++
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/mongo.conf --shutdown
mongod -f /mongodb/conf/mongo.conf

++++++++++++++++++++++

(9)mongodb的關閉方式
mongod -f mongodb.conf --shutdown

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章