您好,登錄后才能下訂單哦!
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
root@master:~#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/
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。