本篇內(nèi)容介紹了“如何使用Yum安裝MongoDB Linux版”的有關(guān)知識,在實(shí)際案例的操作過程中,不少人都會(huì)遇到這樣的困境,接下來就讓小編帶領(lǐng)大家學(xué)習(xí)一下如何處理這些情況吧!希望大家仔細(xì)閱讀,能夠?qū)W有所成!

1、環(huán)境說明
本文使用紅帽6.5進(jìn)行實(shí)驗(yàn)。
[root@oracle-test ~]# cat /etc/redhat-release
Red Hat Enterprise Linux Server release 6.5 (Santiago)
[root@oracle-test ~]# uname -r
2.6.32-431.el6.x86_64
安裝目標(biāo)版本為MongoDB最新版本3.4。
2、使用yum進(jìn)行安裝
從MongoDB官方網(wǎng)站上,獲取yum資源庫地址。創(chuàng)建對應(yīng)的Repo文件。
[root@oracle-test ~]# cd /etc/yum.repos.d/
[root@oracle-test yum.repos.d]# ls -l
total 12
-rw-r--r--. 1 root root 74 Dec 28 2016 localyum.repo
-rw-r--r--. 1 root root 198 Jul 16 13:02 mongodb-org-3.4.repo
-rw-r--r--. 1 root root 636 Sep 14 2016 zabbix.repo
對應(yīng)信息:
[root@oracle-test yum.repos.d]# cat mongodb-org-3.4.repo
[mongodb-org-3.4]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.4/x86_64
gpgcheck=1
enable=1
gpgkey=https://www.mongodb.org/static/pgp/server-3.4.asc
調(diào)用yum進(jìn)行安裝。注意:在yum安裝對象上,包括幾個(gè)對象,分別表示不同的安裝內(nèi)容:
ü mongodb-org:MongoDB全集信息,包括Server、Client(Mongo Shell)、各類型工具;
ü mongodb-org-server:服務(wù)器組件;
ü mongodb-org-shell:MongoDB Shell組件,類似于sqlplus;
ü mongodb-org-tools:備份還原工具、數(shù)據(jù)導(dǎo)入導(dǎo)出等;
[root@oracle-test yum.repos.d]# yum install -y mongodb-org
Loaded plugins: product-id, refresh-packagekit, security, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package mongodb-org.x86_64 0:3.4.6-1.el6 will be installed
--> Processing Dependency: mongodb-org-tools = 3.4.6 for package: mongodb-org-3.4.6-1.el6.x86_64
--> Processing Dependency: mongodb-org-shell = 3.4.6 for package: mongodb-org-3.4.6-1.el6.x86_64
--> Processing Dependency: mongodb-org-server = 3.4.6 for package: mongodb-org-3.4.6-1.el6.x86_64
--> Processing Dependency: mongodb-org-mongos = 3.4.6 for package: mongodb-org-3.4.6-1.el6.x86_64
--> Running transaction check
---> Package mongodb-org-mongos.x86_64 0:3.4.6-1.el6 will be installed
---> Package mongodb-org-server.x86_64 0:3.4.6-1.el6 will be installed
---> Package mongodb-org-shell.x86_64 0:3.4.6-1.el6 will be installed
---> Package mongodb-org-tools.x86_64 0:3.4.6-1.el6 will be installed
(篇幅原因,有省略......)
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Dependency Installed:
mongodb-org-mongos.x86_64 0:3.4.6-1.el6
mongodb-org-server.x86_64 0:3.4.6-1.el6
mongodb-org-shell.x86_64 0:3.4.6-1.el6
mongodb-org-tools.x86_64 0:3.4.6-1.el6
Complete!
[root@oracle-test yum.repos.d]#
另外,在國內(nèi)的服務(wù)器上,由于網(wǎng)絡(luò)的原因,可能會(huì)有下載中間超時(shí)中斷的情況。可以重試幾次,或者知道下載地址之后,單獨(dú)通過支持?jǐn)帱c(diǎn)程序進(jìn)行下載。
3、后續(xù)配置
使用yum方式若干好處,一個(gè)是默認(rèn)就有配置文件進(jìn)行程序控制,另一個(gè)就是自動(dòng)以操作系統(tǒng)服務(wù)Service的方式組織。
同Oracle一樣,我們建議將Selinux關(guān)閉。
[root@oracle-test yum.repos.d]# vi /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled
以操作系統(tǒng)服務(wù)方式運(yùn)行,避免出現(xiàn)單獨(dú)shell執(zhí)行的情況。
[root@oracle-test ~]# chkconfig | grep mongod
mongod 0:off 1:off 2:off 3:on 4:off 5:on 6:off
[root@oracle-test ~]# service mongod status
mongod (pid 2078) is running...
[root@oracle-test log]# ps -ef | grep mongo
mongod 2078 1 0 14:25 ? 00:00:01 /usr/bin/mongod -f /etc/mongod.conf
root 2419 2336 0 14:29 pts/0 00:00:00 grep mongo
[root@oracle-test log]# id mongod
uid=495(mongod) gid=490(mongod) groups=490(mongod)
觀察幾個(gè)方面問題:
首先,rpm安裝程序創(chuàng)建了單獨(dú)用戶mongod來作為運(yùn)行程序主體。其次,mongod啟動(dòng)參數(shù)以配置文件/etc/mongod.conf的方式保存在操作系統(tǒng)上,可以編輯運(yùn)行。第三,chkconfig中可以看到開機(jī)自動(dòng)啟動(dòng)程序服務(wù)。
日志和數(shù)據(jù)文件上,tarball安裝比較“簡陋”,都是/data/db目錄和直接輸入到屏幕上。使用mongod.conf配置方式后,這種靈活性要好很多。
日志文件:
[root@oracle-test ~]# cd /var/log/
[root@oracle-test log]# ls -l | grep mongo
drwxr-xr-x. 2 mongod mongod 4096 Jul 16 14:16 mongodb
[root@oracle-test mongodb]# pwd
/var/log/mongodb
[root@oracle-test mongodb]# ls -l
total 4
-rw-r-----. 1 mongod mongod 4062 Jul 16 14:25 mongod.log
初始配置文件項(xiàng)目:
[root@oracle-test mongodb]# cd /etc
[root@oracle-test etc]# ls -l | grep mongod.conf
-rw-r--r--. 1 root root 768 Jul 6 02:55 mongod.conf
[root@oracle-test etc]# cat mongod.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
path: /var/log/mongodb/mongod.log –日志文件位置
# Where and how to store data.
storage:
dbPath: /var/lib/mongo --存儲數(shù)據(jù)位置
journal:
enabled: true
# engine:
# mmapv1:
# wiredTiger:
# how the process runs
processManagement:
fork: true # fork and run in background
pidFilePath: /var/run/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.
#security:
#operationProfiling:
#replication:
#sharding:
## Enterprise-Only Options
#auditLog:
#snmp:
各種配置項(xiàng)目,可以參見Mongodb官方文檔信息:https://docs.mongodb.com/manual/reference/configuration-options/。
4、參數(shù)修改實(shí)驗(yàn)
嘗試在mongod.conf文件上進(jìn)行簡單的修改。對于MongoDB,除了27017端口之外,還會(huì)有一個(gè)28017的Web方式訪問接口。默認(rèn)是不開放的,需要使用配置文件開啟。
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
"mongod.conf" 47L, 847C written
重新啟動(dòng)mongod服務(wù)。
[root@oracle-test etc]# service mongod restart
Stopping mongod: [ OK ]
Starting mongod: [ OK ]
2017-07-16T14:44:12.957+0800 I CONTROL [initandlisten]
2017-07-16T14:44:12.960+0800 I NETWORK [websvr] admin web console waiting for connections on port 28017
2017-07-16T14:44:12.961+0800 I FTDC [initandlisten] Initializing full-time diagnostic data capture with directory '/var/lib/mongo/diagnostic.data'
2017-07-16T14:44:12.961+0800 I NETWORK [thread1] waiting for connections on port 27017
注意:這個(gè)時(shí)候,只能進(jìn)行本地登錄,從遠(yuǎn)程客戶端使用shell或者網(wǎng)頁都不能訪問。
C:\Users\admin>mongo --host 172.xx.xx.xxx
MongoDB shell version v3.4.5
connecting to: mongodb://172.xx.xx.xxx:27017/
2017-07-16T15:01:45.913+0800 W NETWORK [thread1] Failed to connect to 172.16.19
.143:27017 after 5000ms milliseconds, giving up.
2017-07-16T15:01:45.914+0800 E QUERY [thread1] Error: couldn't connect to ser
ver 172.xx.xx.xxx:27017, connection attempt failed :
connect@src/mongo/shell/mongo.js:237:13
@(connect):1:6
exception: connect failed
原因在于net參數(shù)的bindIP內(nèi)容,默認(rèn)情況為:
net:
port: 27017
bindIp: 127.0.0.1 # Listen to local interface only, comment to listen on all interfaces.
需要修改為0.0.0.0,否則只能在本地項(xiàng)目。
net:
port: 27017
bindIp: 0.0.0.0 # Listen to local interface only, comment to listen on all interfaces.
[root@oracle-test etc]# service mongod restart
Stopping mongod: [ OK ]
Starting mongod: [ OK ]
C:\Users\admin>mongo --host 172.xx.xx.xxx
MongoDB shell version v3.4.5
connecting to: mongodb://172.xx.xx.xxx:27017/
MongoDB server version: 3.4.6
Server has startup warnings:
(篇幅原因,有省略……)
2017-07-16T15:12:19.433+0800 I CONTROL [initandlisten]
2017-07-16T15:12:19.433+0800 I CONTROL [initandlisten] ** WARNING: soft rlimits
too low. rlimits set to 1024 processes, 64000 files. Number of processes should
be at least 32000 : 0.5 times number of files.
2017-07-16T15:12:19.433+0800 I CONTROL [initandlisten]
>
對于出現(xiàn)的soft rlimits提示,可以修改limits.conf文件,設(shè)置額外的限制數(shù)目。
[root@oracle-test ~]# vi /etc/security/limits.conf
#@student - maxlogins 4
mongod soft nofile 64000
mongod hard nofile 64000
mongod soft nproc 32000
mongod hard nproc 32000
[root@oracle-test ~]# service mongod restart
Stopping mongod: [ OK ]
Starting mongod: [ OK ]
5、結(jié)論
本文介紹了使用yum方式安裝mongodb的方法。這種方法下,系統(tǒng)出錯(cuò)的情況會(huì)更少一些,配置項(xiàng)目也更加清晰。
“如何使用Yum安裝MongoDB Linux版”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識可以關(guān)注創(chuàng)新互聯(lián)-成都網(wǎng)站建設(shè)公司網(wǎng)站,小編將為大家輸出更多高質(zhì)量的實(shí)用文章!
分享標(biāo)題:如何使用Yum安裝MongoDBLinux版-創(chuàng)新互聯(lián)
轉(zhuǎn)載來于:http://chinadenli.net/article22/eogcc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供外貿(mào)建站、全網(wǎng)營銷推廣、網(wǎng)站排名、網(wǎng)頁設(shè)計(jì)公司、自適應(yīng)網(wǎng)站、標(biāo)簽優(yōu)化
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容