参考:
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登录
至此数据库和账号创建完成