社區版下載地址:https://www.mongodb.com/try/download/community
如下內容以二進制解壓包爲例介紹,官方文檔地址:https://docs.mongodb.com/manual/tutorial/install-mongodb-on-red-hat-tarball/linux
1、系統準備mongodb
關閉大頁內存機制
echo never > /sys/kernel/mm/transparent_hugepage/enabled
echo never > /sys/kernel/mm/transparent_hugepage/defrag數據庫
永久關閉大頁內存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/
* - nofile 65535 * - nproc 65536
7.建立所需用戶和組vim
useradd mongod passwd mongod
8.上傳並解壓軟件到指定位置,設置權限安全
mkdir /app cd /app tar -zxvf mongodb-linux-x86_64-rhel70-4.4.4.tgz ln -s mongodb mongodb-linux-x86_64-rhel70-4.4.4 chown -R mongod:mongod -R mongodb*
9.設置用戶環境變量bash
su - mongod vi .bash_profile export PATH=/app/mongodb/bin:$PATH source .bash_profile
mkdir -p /mongodb/conf mkdir -p /mongodb/log mkdir -p /mongodb/data chown -R mongod:mongod /mongodb
vim /mongodb/conf/mongodb.conf logpath=/mongodb/log/mongodb.log dbpath=/mongodb/data port=27017 logappend=true fork=true
mongod -f /mongodb/conf/mongodb.conf
mongo
mongod -f /mongodb/log/mongodb.log --shutdown
root用戶 cat > /etc/systemd/system/mongod.service <<EOF [Unit] Description=mongodb After=network.target remote-fs.target nss-lookup.target [Service] LimitNOFILE=65536 LimitNPROC=65536 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 #重啓 systemctl restart mongod #中止 systemctl stop mongod #啓動 systemctl start mongod
-- 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例子 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: 11.111.24.4,127.0.0.1 EOF