MongoDB 基礎(四)Red Hat Enterprise 6.4 x64 安裝MongDB 3.0及配置,mongodbmongdb

來源:互聯網
上載者:User

MongoDB 基礎(四)Red Hat Enterprise 6.4 x64 安裝MongDB 3.0及配置,mongodbmongdb

mongodb-org該包為中繼資料套件,安裝時將自動安裝以下4個組件包
mongodb-org-server該包包含mongod守護進程、相關配置和初始指令碼mongodb-org-mongos該包包含mongos守護進程mongodb-org-shell該包包含mongo shell mongodb-org-tools該包包含以下mongodb工具:mongoimport bsondump, mongodump,mongoexport, mongofiles, mongooplog, mongoperf, mongorestore, mongostat, andmongotop.


1. 建立yum源倉庫檔案:
vi /etc/yum.repos.d/mongodb-org-3.0.repo
[mongodb-org-3.0]name=MongoDB Repositorybaseurl=http://repo.mongodb.org/yum/redhat/6/mongodb-org/3.0/x86_64/gpgcheck=0enabled=1


2. 安裝MongoDB包和相關工具:

yum install -y mongodb-org


要是安裝指定版本的MongoDB,應獨立指定每個組件包和附加在包名後面的版本號碼,如:

sudo yum install -y mongodb-org-3.0.2 mongodb-org-server-3.0.2 mongodb-org-shell-3.0.2 mongodb-org-mongos-3.0.2 mongodb-org-tools-3.0.2


也可以定義任何可用的MongoDB版本,當有更新的版本時yum將自動更新Mongodb包。為了防止無意的的更新,可以在/etc/yum.conf中使用exclude指令,如:
exclude=mongodb-org,mongodb-org-server,mongodb-org-shell,mongodb-org-mongos,mongodb-org-tools


3. 相關配置:

如果開啟了防火牆,必須配置SELinux允許MongoDB運行在Red Hat系統或者CentOS Linux。管理員應該設定以下3個選項:1. 允許連接埠27017訪問(沒有則先下載工具semanage):yum -y install policycoreutils-pythonsemanage port -a -t mongod_port_t -p tcp 270172. 在設定檔/etc/selinux/config設定SELinux模式為permissive:vi /etc/selinux/configSELINUX=enforcing 改為SELINUX=permissive3. 徹底禁用SELinux:SELINUX=disabled

Mongodb執行個體預設儲存資料的資料檔案路徑為/var/lib/mongo,儲存記錄檔路徑為/var/log/mongodb ,使用mongod賬戶運行。也可以在檔案/etc/mongod.conf 配置資料檔案和記錄檔的目錄。
vi /etc/mongod.conf
# mongod.conf#where to loglogpath=/var/log/mongodb/mongod.loglogappend=true# fork and run in backgroundfork=true#port=27017dbpath=/var/lib/mongo# location of pidfilepidfilepath=/var/run/mongodb/mongod.pid# Listen to local interface only. Comment out to listen on all interfaces.bind_ip=127.0.0.1# Disables write-ahead journaling# nojournal=true# Enables periodic logging of CPU utilization and I/O wait#cpu=true# Turn on/off security.  Off is currently the default#noauth=true#auth=true# Verbose logging output.#verbose=true# Inspect all client data for validity on receipt (useful for# developing drivers)#objcheck=true# Enable db quota management#quota=true# Set oplogging level where n is#   0=off (default)#   1=W#   2=R#   3=both#   7=W+some reads#diaglog=0# Ignore query hints#nohints=true# Enable the HTTP interface (Defaults to port 28017).#httpinterface=true# Turns off server-side scripting.  This will result in greatly limited# functionality#noscripting=true# Turns off table scans.  Any query that would do a table scan fails.#notablescan=true# Disable data file preallocation.#noprealloc=true# Specify .ns file size for new databases.# nssize=<size># Replication Options# in replicated mongo databases, specify the replica set name here#replSet=setname# maximum size in megabytes for replication operation log#oplogSize=1024# path to a key file storing authentication info for connections# between replica set members#keyFile=/path/to/keyfile


4. 運行mongodb

設定Mongodb隨系統自啟動:chkconfig mongod on啟用Mongodb服務:service mongod start驗證Mongodb已成功啟動:(查看日誌是否有等待串連的資訊)tail -5 /var/log/mongodb/mongod.log[initandlisten] waiting for connections on port <port>

此時也看到資料已經產生:



直接在命令列輸入 mongo 可進入資料庫中:



至此,完成!~

官方參考:Install MongoDB on Red Hat Enterprise or CentOS Linux



相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.