mongodb安装

本文详细介绍了如何在CentOS 7上下载并安装MongoDB 4.4.13,配置环境,包括设置数据库路径、日志位置和监听端口,以及创建安全用户和启用监控。还演示了如何使用Robomongo连接和管理MongoDB数据库。
摘要由CSDN通过智能技术生成

参考:
https://blog.csdn.net/qq_41992943/article/details/115546623
https://blog.csdn.net/qq_29467891/article/details/107032924
https://blog.csdn.net/m0_37967652/article/details/122105071

下载:

https://www.mongodb.com/try/download/community
本次下载版本号:4.4.13 系统:centos7 格式:tgz
在这里插入图片描述

上传解压

#上传到home下
cd /home
#解压
tar -zxvf mongodb-linux-x86_64-rhel70-4.4.13.tgz
#重命名 方便操作
mv mongodb-linux-x86_64-rhel70-4.4.13.tgz mongodb

配置文件

cd /home/mongodb
#存放数据库和日志文件
mkdir db logs

新建配置文件

cd /home/mongodb/bin
#新建配置文件
vim mongodb.conf
#输入下面配置
#数据库存放位置
dbpath=/home/mongodb/db
#日志存放位置
logpath=/home/mongodb/logs/mongodb.log
#监听端口
port=27017
#是否后台运行
fork=true
#用于数据故障恢复和持久化数据
journal=false
#允许其它ip访问
bind_ip = 0.0.0.0

启动

[root@jdy-ecs-8u32g bin]# cd /home/mongodb/bin
[root@jdy-ecs-8u32g bin]# ./mongod --config mongodb.conf 
about to fork child process, waiting until server is ready for connections.
forked process: 199620
child process started successfully, parent exiting

停止服务

cd /home/mongodb/bin
./mongo
> use admin
> db.shutdownServer()

也可以直接kill掉进程

下载Robomongo连接mongodb

https://gitee.com/mirrors/robomongo 直接双击exe下一步即可
在这里插入图片描述

登录

先创建数据库和账号
进入目录 cd /home/mongodb
注意:要先创建数据库,在创建账号和数据关系

  • 创建数据库use rt
  • 创建用户rtadmin数据库rt权限(内置角色)readWrite

内置角色分类

  • 数据库用户角色:read、readWrite;
  • 数据库管理角色:dbAdmin、dbOwner、userAdmin;
  • 集群管理角色:clusterAdmin、clusterManager、clusterMonitor、hostManager;
  • 备份恢复角色:backup、restore;
  • 所有数据库角色:readAnyDatabase、readWriteAnyDatabase、userAdminAnyDatabase、dbAdminAnyDatabase
  • 超级用户角色:root
  • 内部角色:__system
[root@jdy-ecs-8u32g bin]# ./mongo
MongoDB shell version v4.4.13
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("c67e65d7-5f7f-4141-9b51-410711d62e58") }
MongoDB server version: 4.4.13
---
The server generated these startup warnings when booting: 
        2022-04-12T10:06:05.985+08:00: Access control is not enabled for the database. Read and write access to data and configuration is unrestricted
        2022-04-12T10:06:05.985+08:00: You are running this process as the root user, which is not recommended
        2022-04-12T10:06:05.986+08:00: /sys/kernel/mm/transparent_hugepage/enabled is 'always'. We suggest setting it to 'never'
        2022-04-12T10:06:05.986+08:00: /sys/kernel/mm/transparent_hugepage/defrag is 'always'. We suggest setting it to 'never'
        2022-04-12T10:06:05.986+08:00: Soft rlimits too low
        2022-04-12T10:06:05.986+08:00:         currentValue: 1024
        2022-04-12T10:06:05.986+08:00:         recommendedMinimum: 64000
---
---
        Enable MongoDB's free cloud-based monitoring service, which will then receive and display
        metrics about your deployment (disk utilization, CPU, operation statistics, etc).

        The monitoring data will be available on a MongoDB website with a unique URL accessible to you
        and anyone you share the URL with. MongoDB may use this information to make product
        improvements and to suggest MongoDB products and deployment options to you.

        To enable free monitoring, run the following command: db.enableFreeMonitoring()
        To permanently disable this reminder, run the following command: db.disableFreeMonitoring()
---
> use rt
switched to db rt
> db.createUser({user:'rtadmin',pwd:'123456',roles:[{role:'readWrite',db:'rt'}]})
Successfully added user: {
        "user" : "rtadmin",
        "roles" : [
                {
                        "role" : "readWrite",
                        "db" : "rt"
                }
        ]
}
> 

robo登录
在这里插入图片描述

至此数据库和账号创建完成

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值