centos 7 如何安装启动使用mongodb

参考mongodb官网的安装步骤:
https://docs.mongodb.com/manual/tutorial/install-mongodb-on-red-hat/

添加安装包的配置文件

创建一个空的配置文件:/etc/yum.repos.d/mongodb-org-3.4.repo
操作过程:
[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost ~]# touch mongodb-org-3.4.repo
进入到文件里面:
[root@localhost ~] vim /etc/yum.repos.d/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
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-3.4.asc
写到 /etc/yum.repos.d/mongodb-org-3.4.repo ,如图所示:
这里写图片描述

安装mongodb

[root@localhost yum.repos.d]# yum install -y mongodb-org
待安装完成后,重启service
[root@localhost yum.repos.d]# service mongod start
查看状态
[root@localhost yum.repos.d]# service mongod status
(有的centos版本系统,这里是 systemctl status/start/stop mongod )
在安装后,启动mongod service后,遇到这样一个问题:
Loaded: loaded (/usr/lib/systemd/system/mongod.service; enabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Fri 2017-07-14 17:35:08 CST; 3s ago
Docs: https://docs.mongodb.org/manual
Process: 1570 ExecStart=/usr/bin/mongod $OPTIONS run (code=exited, status=1/FAILURE)
Main PID: 1570 (code=exited, status=1/FAILURE
针对上述的情况,
1.需要修改mongod.conf里面的配置
[root@localhost ~]# vim /etc/mongod.conf
把fork修改为 false , pidFilePath修改为dbPath的路径,我这里在storage显示为dbPath: /var/lib/mongo,即设置为:
fork: false # fork and run in background
2.有时还需要设置firewall
[root@localhost ~]#firewall-cmd –zone=public –permanent –add-port=27017/tcp
[root@localhost ~]# firewall-cmd –reload
3. 然后重启 Linux PC
[root@localhost ~]# reboot
4.待Linux PC重启完成后,再次重启mongod ,然后查看mongod是否已经成功启动
[root@localhost ~]# service mongod start
[root@localhost ~]# service mongod status
mongod.service - High-performance, schema-free document-oriented database
Loaded: loaded (/usr/lib/systemd/system/mongod.service; enabled; vendor preset: disabled)
Active: active (running) since Fri 2017-07-14 17:43:52 CST; 17h ago
Docs: https://docs.mongodb.org/manual

就这样完成了mongod的安装以及启动其service。

mongod的使用

查看mongod的安装路径
[root@localhost ~]# whereis mongod
mongod: /usr/bin/mongod /etc/mongod.conf~ /etc/mongod.conf /usr/share/man/man1/mongod.1
然后进入到mongod的使用
[root@localhost bin]# mongo
MongoDB shell version v3.4.6
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 3.4.6
Server has startup warnings:
2017-07-14T17:43:53.755+0800 I CONTROL [initandlisten]
2017-07-14T17:43:53.755+0800 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2017-07-14T17:43:53.755+0800 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2017-07-14T17:43:53.755+0800 I CONTROL [initandlisten]
2017-07-14T17:43:53.756+0800 I CONTROL [initandlisten]
2017-07-14T17:43:53.756+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is ‘always’.
2017-07-14T17:43:53.756+0800 I CONTROL [initandlisten] ** We suggest setting it to ‘never’
2017-07-14T17:43:53.756+0800 I CONTROL [initandlisten]
2017-07-14T17:43:53.756+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is ‘always’.
2017-07-14T17:43:53.756+0800 I CONTROL [initandlisten] ** We suggest setting it to ‘never’
2017-07-14T17:43:53.756+0800 I CONTROL [initandlisten]

show dbs;
admin 0.000GB
local 0.000GB

就这样就可以开始我们的mongodb的使用了。

使用过Oracle,Mysql,却没有使用过mongodb,但是理论都是相通的,相信这个应该也能够很快上手。
接下来学习
1. Python monodb
2. Jmeter monodb
为做接口自动化与性能测试做准备。

感谢网友的分享。
http://blog.csdn.net/bwangk/article/details/53725713
http://www.cnblogs.com/hujiapeng/p/7008006.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值