溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

單片mongoDB

發(fā)布時間:2020-09-03 11:55:13 來源:網(wǎng)絡(luò) 閱讀:564 作者:藍(lán)宮衛(wèi) 欄目:MongoDB數(shù)據(jù)庫

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,以隨操作系統(tǒng)重啟時自啟動 **/


 /** 部分參數(shù)解釋 **/

 --fork #后臺daemon運(yùn)行

 --bind_ip #監(jiān)聽IP地址列表,以逗號分隔

 --port #監(jiān)聽端口,默認(rèn)27017

 --setParameter enableLocalhostAuthBypass=0 #所有接口都需要認(rèn)證

 --pidfilepath #pid文件

 --dbpath #db存放路徑

 --logpath #日志文件

 --config #配置文件

 --auth #啟用認(rèn)證

 --httpinterface #啟用web接口

 --rest #rest api

 --jsonp #json api

 /** 如果閑命令參數(shù)太多,可以指定配置文件 **/

 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 

默認(rèn)監(jiān)聽端口,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


三、關(guān)閉

# mongod --shutdown --dbpath /opt/mongod/db

還可以

命令行模式執(zhí)行shutdown

# use admin

 db.shutdownServer()

 mongo admin --port 27017 --eval "db.shutdownServer()"


四、配置文件

默認(rèn)的二進(jìn)制包沒有配置文件模板,可以從源碼包內(nèi)提取

# cp -rp /usr/local/src/mongodb-src-r3.2.9/rpm/mongod.conf /opt/mongodb/conf/


    /** 以下是一個簡單的對應(yīng)以上命令行參數(shù)的配置文件 **/

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

更多參數(shù)和解釋請參看官方文檔


五、 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




六、修改內(nèi)核參數(shù)

# cat >>/etc/rc.d/rc.local <<HERE

# echo never > /sys/kernel/mm/transparent_hugepage/enabled

# echo never > /sys/kernel/mm/transparent_hugepage/defrag

# HERE


七,重啟服務(wù)訪問;

# service mongod restart

http://IP:28017/


向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI