標籤:mongodb mongodb-linux-x86_64-rhel62-3.2.9.tgz
MongoDB:
https://docs.mongodb.com/manual/tutorial/install-mongodb-on-linux/#install-mongodb-community-edition
一、下載安裝
# curl -O https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel62-3.2.9.tgz
或
# wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel62-3.2.9.tgz
# tar -xf mongodb-linux-x86_64-rhel62-3.2.9.tgz -C /opt/
# ln -s /opt/mongodb-linux-x86_64-rhel62-3.2.9/ /opt/mongodb
# cat >>/etc/profile <<HERE
PATH=$PATH:/opt/mongodb/bin
HERE
# source /etc/profile
# mkdir -p /opt/mongodb/{log,db,conf}
二;啟動
# mongod --fork --httpinterface --rest --jsonp --setParameter enableLocalhostAuthBypass=0 --pidfilepath /opt/mongodb/mongod.pid --dbpath /opt/mongodb/db --logpath /opt/mongodb/log/mongod.log --logappend --logRotate rename --timeStampFormat ctime
/** 可以加入/etc/rc.d/rc.local,以隨作業系統重啟時自啟動 **/
/** 部分參數解釋 **/
--fork #後台daemon運行
--bind_ip #監聽IP地址清單,以逗號分隔
--port #監聽連接埠,預設27017
--setParameter enableLocalhostAuthBypass=0 #所有介面都需要認證
--pidfilepath #pid檔案
--dbpath #db存放路徑
--logpath #記錄檔
--config #設定檔
--auth #啟用認證
--httpinterface #啟用web介面
--rest #rest api
--jsonp #json api
/** 如果閑命令參數太多,可以指定設定檔 **/
WARNING
Ensure that the HTTP status interface, the REST API, and the JSON API are all disabled in production environments to prevent potential data exposure and vulnerability to attackers
[email protected]:~#netstat -tunlp|grep mongod
tcp 0 0 0.0.0.0:28017 0.0.0.0:* LISTEN 11896/mongod
tcp 0 0 0.0.0.0:27017 0.0.0.0:* LISTEN 11896/mongod
預設監聽連接埠,db連接埠為27017, web連接埠為28017
# vi /etc/sysconfig/iptables
-A INPUT -p tcp -m state --state NEW -m tcp --dport 27017 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 28017 -j ACCEPT
三、關閉
# mongod --shutdown --dbpath /opt/mongod/db
還可以
命令列模式執行shutdown
# use admin
db.shutdownServer()
或
mongo admin --port 27017 --eval "db.shutdownServer()"
四、設定檔
預設的二進位包沒有設定檔範本,可以從源碼包內提取
# cp -rp /usr/local/src/mongodb-src-r3.2.9/rpm/mongod.conf /opt/mongodb/conf/
/** 以下是一個簡單的對應以上命令列參數的設定檔 **/
# mongod.conf
# for documentation of all options, see:
# http://docs.mongodb.org/manual/reference/configuration-options/
# where to write logging data.
systemLog:
destination: file
logAppend: true
logRotate: rename
timeStampFormat: ctime
path: /opt/mongodb/log/mongod.log
# Where and how to store data.
storage:
dbPath: /opt/mongodb/db
journal:
enabled: true
# engine:
# mmapv1:
# wiredTiger:
# how the process runs
processManagement:
fork: true # fork and run in background
pidFilePath: /opt/mongodb/mongod.pid # location of pidfile
# network interfaces
net:
port: 27017
#bindIp: 127.0.0.1 # Listen to local interface only, comment to listen on all interfaces.
http:
enabled: true
JSONPEnabled: true
RESTInterfaceEnabled: true
setParameter:
enableLocalhostAuthBypass: false
#security:
#operationProfiling:
#replication:
#sharding:
## Enterprise-Only Options
#auditLog:
#snmp:
更多參數和解釋請參看官方文檔
五、 init管控啟動指令碼
# useradd -s /sbin/nologin -r mongod
# chown -R mongod: /opt/mongodb-linux-x86_64-rhel62-3.2.9
# cp -rp/usr/local/src/mongodb-src-r3.2.9/rpm/init.d-mongod /etc/init.d/mongod
/** 模板仍可以從 源碼包裡面取 **/
# chmod +x /etc/init.d/mongod
# sed -i ‘/CONFIGFILE=/i MONGOD="/opt/mongodb/bin/mongod"‘ /etc/init.d/mongod
# sed -i ‘/CONFIGFILE=/s:/etc/mongod.conf:/opt/mongodb/conf/mongod.conf:g‘ /etc/init.d/mongod
六、修改核心參數
# cat >>/etc/rc.d/rc.local <<HERE
# echo never > /sys/kernel/mm/transparent_hugepage/enabled
# echo never > /sys/kernel/mm/transparent_hugepage/defrag
# HERE
七,重啟服務訪問;
# service mongod restart
http://IP:28017/
本文出自 “logs” 部落格,請務必保留此出處http://51log.blog.51cto.com/6076767/1856995
單片mongoDB