本篇内容介绍了“如何使用Yum安装MongoDB Linux版”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!1、环境说明本文使用红帽6.5进行实验。[root@oracle-test ~]# cat /etc/redhat-releaseRed Hat Enterprise Linux Server release 6.5 (Santiago)[root@oracle-test ~]# uname -r2.6.32-431.el6.x86_64安装目标版本为MongoDB最新版本3.4。2、使用yum进行安装从MongoDB官方网站上,获取yum资源库地址。创建对应的Repo文件。[root@oracle-test ~]# cd /etc/yum.repos.d/[root@oracle-test yum.repos.d]# ls -ltotal 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对应信息:[root@oracle-test yum.repos.d]# cat mongodb-org-3.4.repo[mongodb-org-3.4]name=MongoDB Repositorybaseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.4/x86_64gpgcheck=1enable=1gpgkey=https://www.mongodb.org/static/pgp/server-3.4.asc调用yum进行安装。注意:在yum安装对象上,包括几个对象,分别表示不同的安装内容: mongodb-org:MongoDB全集信息,包括Server、Client(Mongo Shell)、各类型工具; mongodb-org-server:服务器组件; mongodb-org-shell:MongoDB Shell组件,类似于sqlplus; mongodb-org-tools:备份还原工具、数据导入导出等;[root@oracle-test yum.repos.d]# yum install -y mongodb-orgLoaded plugins: product-id, refresh-packagekit, security, subscription-managerThis system is not registered to Red Hat Subscription M免费云主机域名anagement. You can use subscription-manager to register.Setting up Install ProcessResolving 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_debugRunning Transaction TestTransaction Test SucceededDependency 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.el6Complete![root@oracle-test yum.repos.d]#另外,在国内的服务器上,由于网络的原因,可能会有下载中间超时中断的情况。可以重试几次,或者知道下载地址之后,单独通过支持断点程序进行下载。3、后续配置使用yum方式若干好处,一个是默认就有配置文件进行程序控制,另一个就是自动以操作系统服务Service的方式组织。同Oracle一样,我们建议将Selinux关闭。[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以操作系统服务方式运行,避免出现单独shell执行的情况。[root@oracle-test ~]# chkconfig | grep mongodmongod 0:off 1:off 2:off 3:on 4:off 5:on 6:off[root@oracle-test ~]# service mongod statusmongod (pid 2078) is running…[root@oracle-test log]# ps -ef | grep mongomongod 2078 1 0 14:25 ? 00:00:01 /usr/bin/mongod -f /etc/mongod.confroot 2419 2336 0 14:29 pts/0 00:00:00 grep mongo[root@oracle-test log]# id mongoduid=495(mongod) gid=490(mongod) groups=490(mongod)观察几个方面问题:首先,rpm安装程序创建了单独用户mongod来作为运行程序主体。其次,mongod启动参数以配置文件/etc/mongod.conf的方式保存在操作系统上,可以编辑运行。第三,chkconfig中可以看到开机自动启动程序服务。日志和数据文件上,tarball安装比较“简陋”,都是/data/db目录和直接输入到屏幕上。使用mongod.conf配置方式后,这种灵活性要好很多。日志文件:[root@oracle-test ~]# cd /var/log/[root@oracle-test log]# ls -l | grep mongodrwxr-xr-x. 2 mongod mongod 4096 Jul 16 14:16 mongodb[root@oracle-test mongodb]# pwd/var/log/mongodb[root@oracle-test mongodb]# ls -ltotal 4-rw-r—–. 1 mongod mongod 4062 Jul 16 14:25 mongod.log初始配置文件项目:[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 –存储数据位置 journal: enabled: true# engine:# mmapv1:# wiredTiger:# how the process runsprocessManagement: fork: true # fork and run in background pidFilePath: /var/run/mongodb/mongod.pid # location of pidfile# network interfacesnet: 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:各种配置项目,可以参见Mongodb官方文档信息:https://docs.mongodb.com/manual/reference/configuration-options/。4、参数修改实验尝试在mongod.conf文件上进行简单的修改。对于MongoDB,除了27017端口之外,还会有一个28017的Web方式访问接口。默认是不开放的,需要使用配置文件开启。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重新启动mongod服务。[root@oracle-test etc]# service mongod restartStopping 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 280172017-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注意:这个时候,只能进行本地登录,从远程客户端使用shell或者网页都不能访问。C:Usersadmin>mongo –host 172.xx.xx.xxxMongoDB shell version v3.4.5connecting 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 server 172.xx.xx.xxx:27017, connection attempt failed :connect@src/mongo/shell/mongo.js:237:13@(connect):1:6exception: connect failed原因在于net参数的bindIP内容,默认情况为:net: port: 27017 bindIp: 127.0.0.1 # Listen to local interface only, comment to listen on all interfaces.需要修改为0.0.0.0,否则只能在本地项目。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 restartStopping mongod: [ OK ]Starting mongod: [ OK ]C:Usersadmin>mongo –host 172.xx.xx.xxxMongoDB shell version v3.4.5connecting to: mongodb://172.xx.xx.xxx:27017/MongoDB server version: 3.4.6Server 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 rlimitstoo low. rlimits set to 1024 processes, 64000 files. Number of processes shouldbe at least 32000 : 0.5 times number of files.2017-07-16T15:12:19.433+0800 I CONTROL [initandlisten]>对于出现的soft rlimits提示,可以修改limits.conf文件,设置额外的限制数目。[root@oracle-test ~]# vi /etc/security/limits.conf#@student – maxlogins 4mongod soft nofile 64000mongod hard nofile 64000mongod soft nproc 32000mongod hard nproc 32000[root@oracle-test ~]# service mongod restartStopping mongod: [ OK ]Starting mongod: [ OK ]5、结论本文介绍了使用yum方式安装mongodb的方法。这种方法下,系统出错的情况会更少一些,配置项目也更加清晰。“如何使用Yum安装MongoDB Linux版”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注百云网站,小编将为大家输出更多高质量的实用文章!
redis与mongodb有什么区别?这个问题可能是我们日常学习或工作经常见到的。希望通过这个问题能让你收获颇深。下面是小编给大家带来的参考内容,让我们一起来看看吧!MongoDB更类似MySQL,支持字段索引、游标操作,其优势在于查询功能比较强大,擅长查询J…
免责声明:本站发布的图片视频文字,以转载和分享为主,文章观点不代表本站立场,本站不承担相关法律责任;如果涉及侵权请联系邮箱:360163164@qq.com举报,并提供相关证据,经查实将立刻删除涉嫌侵权内容。