mongodb安裝部署3.6版本


第一章:邏輯結構

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

 

第二章:安裝部署

1、系統准備

1)redhat或centos6.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
        
cat  /sys/kernel/mm/transparent_hugepage/enabled        
cat /sys/kernel/mm/transparent_hugepage/defrag  
其他系統關閉參照官方文檔:   

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.
############################################################################    

 

2、創建所需用戶, 組及所需目錄結構

useradd mongod
passwd mongod

mkdir -p /mongodb/conf
mkdir -p /mongodb/log
mkdir -p /mongodb/data
chown -R mongod:mongod /mongodb

 

上傳並解壓軟件到指定位置

[root@db01 data]# cd   /data
[root@db01 data]# tar xf mongodb-linux-x86_64-rhel70-3.6.12.tgz 
[root@db01 data]#  cp -r /data/mongodb-linux-x86_64-rhel70-3.6.12/bin/ /mongodb

設置用戶環境變量

su - mongod
vi .bash_profile
export PATH=/mongodb/bin:$PATH
source .bash_profile

啟動mongodb

mongod --dbpath=/mongodb/data --logpath=/mongodb/log/mongodb.log --port=27017 --logappend --fork 
[mongod@server2 ~]$ mongo  # 連接mongodb

 

配置參數介紹(配置文件位置及命名無要求, 參考代碼最后幾行)

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>                       -- 監聽地址
   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例子
cat >  /mongodb/conf/mongo.conf <<EOF
systemLog:
   destination: file
   path: "/mongodb/log/mongodb.log"
   logAppend: true
storage:
   journal:
      enabled: true
   dbPath: "/mongodb/data/"
processManagement:
   fork: true
net:
   port: 27017
   bindIp: 10.0.0.51,127.0.0.1
EOF
mongod -f /mongodb/conf/mongo.conf --shutdown  # 關閉mongodb
mongod -f /mongodb/conf/mongo.conf   # 啟動mongodb

 

mongodb的關閉方式

mongod -f /mongodb/conf/mongo.conf --shutdown

 

mongodb 使用systemd管理

[root@db01 ~]# cat > /etc/systemd/system/mongod.service <<EOF
[Unit]
Description=mongodb 
After=network.target remote-fs.target nss-lookup.target
[Service]
User=mongod
Type=forking
ExecStart=/mongodb/bin/mongod --config /mongodb/conf/mongo.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/mongodb/bin/mongod --config /mongodb/conf/mongo.conf --shutdown
PrivateTmp=true  
[Install]
WantedBy=multi-user.target
EOF

[root@db01 ~]# systemctl restart mongod
[root@db01 ~]# systemctl stop mongod
[root@db01 ~]# systemctl start mongod

 

 

 

 

66

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM