Hello,你们好!我是小安Sir!在疫情期间,个人激情学习之旅怎么能够落下呢?为此,我看了一本MongoDB和Python相关的书,感受很是不错!故写一篇安装总结,这实在太简单了,不到半小时就能掌握,实在是有点失礼晒!linux
MongoDB入门
mongodb
安装shell
本文大纲数据库
Attention
api
1. MongoDB 简介bash
2. Win10 安装MongoDBsession
3. RHEL7 安装MongoDB并发
MongoDB简介
app
01ide
非关系型数据库(NoSQL,指的是Not only SQL)有强大的扩展能力,不须要事先定义好表的字段,数据插入速度远超于传统关系型数据库。
MongoDB属于非关系型数据库,其适合存储大量关联性不强的数据。MongoDB是以"库"-"集合"-"文档"-"字段",这与传统关系型数据库的"库"-"表"-"行"-"列"结构很是像。可是,MongoDB不须要预约义表结构,这一点真的很爽,直接插入数据,而且数据的字段能够任意变更,并发写入速度也远远高于传统关系型数据库。
Win10安装MongoDB
02
2.1 下载网址
https://www.mongodb.com/download-center/community
2.2 安装
恭喜你,若是你按照以上的中文路径安装,就会报错,而且让你尝试重启电脑,怎么样,是否是倍儿爽?我还真重启了主机,我晕!
安装数据库怎么须要重启主机呢?这很奇葩,个人电脑一直保持高负荷运转,随时远程工做,处理突发情况!(一本正经,哈哈哈!)
最后,我尝试卸载了刚才的路径,从新使用纯英文路径G:\mongodb\MongoDB安装成功!
RHEL7安装MongoDB
03
3.1 下载网址
https://www.mongodb.com/download-center/community
3.2 开始安装
3.2.1 解压安装包
1[root@RHEL-INIT ~]# mkdir -p /mongo/app
2[root@RHEL-INIT ~]# cd /mongo/app
3[root@RHEL-INIT app]# tar -zxvf mongodb-linux-x86_64-rhel70-4.0.16.tgz
4mongodb-linux-x86_64-rhel70-4.0.16/THIRD-PARTY-NOTICES.gotools
5mongodb-linux-x86_64-rhel70-4.0.16/README
6mongodb-linux-x86_64-rhel70-4.0.16/THIRD-PARTY-NOTICES
7mongodb-linux-x86_64-rhel70-4.0.16/MPL-2
8mongodb-linux-x86_64-rhel70-4.0.16/LICENSE-Community.txt
9mongodb-linux-x86_64-rhel70-4.0.16/bin/mongodump
10mongodb-linux-x86_64-rhel70-4.0.16/bin/mongorestore
11mongodb-linux-x86_64-rhel70-4.0.16/bin/mongoexport
12mongodb-linux-x86_64-rhel70-4.0.16/bin/mongoimport
13mongodb-linux-x86_64-rhel70-4.0.16/bin/mongostat
14mongodb-linux-x86_64-rhel70-4.0.16/bin/mongotop
15mongodb-linux-x86_64-rhel70-4.0.16/bin/bsondump
16mongodb-linux-x86_64-rhel70-4.0.16/bin/mongofiles
17mongodb-linux-x86_64-rhel70-4.0.16/bin/mongoreplay
18mongodb-linux-x86_64-rhel70-4.0.16/bin/mongod
19mongodb-linux-x86_64-rhel70-4.0.16/bin/mongos
20mongodb-linux-x86_64-rhel70-4.0.16/bin/mongo
21mongodb-linux-x86_64-rhel70-4.0.16/bin/install_compass
22[root@RHEL-INIT app]# mv mongodb-linux-x86_64-rhel70-4.0.16 mongodb
3.2.2 建立目录和日志文件
1[root@RHEL-INIT app]# mkdir -p /mongo/app/mongodb/data/db
2[root@RHEL-INIT app]# mkdir -p /mongo/app/mongodb/log
3[root@RHEL-INIT app]# touch /mongo/app/mongodb/log/mongodb.log
3.2.3 建立用户及所属组
1[root@RHEL-INIT app]# groupadd mongodb
2[root@RHEL-INIT app]# useradd -g mongodb mongodb
3[root@RHEL-INIT app]# id mongodb
4uid=1001(mongodb) gid=1001(mongodb) groups=1001(mongodb)
5[root@RHEL-INIT app]# passwd mongodb
6Changing password for user mongodb.
7New password:
8BAD PASSWORD: The password is shorter than 8 characters
9Retype new password:
10passwd: all authentication tokens updated successfully.
3.2.4 建立配置文件
1[root@RHEL-INIT bin]# vi mongodb.conf
2#数据文件存放目录
3dbpath = /mongo/app/mongodb/data/db
4
5#日志文件存放目录
6logpath = /mongo/app/mongodb/log/mongodb.log
7
8#端口
9port = 27017
10
11#以守护程序的方式启用,即在后台运行
12fork = true
13
14#容许全部的链接
15bind_ip=0.0.0.0
16
17auth = true
18~
19~
3.2.5 受权和加载环境变量
1[root@RHEL-INIT bin]# chown -R mongodb:mongodb /mongo/app
2[root@RHEL-INIT bin]# cd
3[root@RHEL-INIT ~]# su - mongodb
4[mongodb@RHEL-INIT ~]$ vi .bash_profile
5PATH=$PATH:$HOME/.local/bin:$HOME/bin
6PATH=$PATH:$HOME/.local/bin:$HOME/bin
7# .bash_profile
8
9# Get the aliases and functions
10if [ -f ~/.bashrc ]; then
11 . ~/.bashrc
12fi
13
14# User specific environment and startup programs
15
16
17export PATH
18
19
20
21export MONGODB_HOME=/mongo/app/mongodb
22PATH=$PATH:$HOME/.local/bin:$HOME/bin:$MONGODB_HOME/bin
23~
24
25".bash_profile" 16L, 253C written
26[mongodb@RHEL-INIT ~]$ . .bash_profile
3.2.6 后台启动数据库
1[mongodb@RHEL-INIT ~]$ mongod -f /mongo/app/mongodb/bin/mongodb.conf
2about to fork child process, waiting until server is ready for connections.
3forked process: 70803
4child process started successfully, parent exiting
3.2.7 测试
1[mongodb@RHEL-INIT ~]$ mongo
2MongoDB shell version v4.0.16
3connecting to: mongodb://127.0.0.1:27017/?gssapiServiceName=mongodb
4Implicit session: session { "id" : UUID("68c53655-af74-429a-be67-0515b818199e") }
5MongoDB server version: 4.0.16
6Welcome to the MongoDB shell.
7For interactive help, type "help".
8For more comprehensive documentation, see
9 http://docs.mongodb.org/
10Questions? Try the support group
11 http://groups.google.com/group/mongodb-user
12
13> use adminuse admin
14switched to db admin
15> db.createUser({user:'test',pwd:'123456',roles:[{role:'root',db:'admin'}]})db.createUser({user:'test',pwd:'123456',roles:[{role:'root',db:'admin'}]})
16Successfully added user: {
17 "user" : "test",
18 "roles" : [
19 {
20 "role" : "root",
21 "db" : "admin"
22 }
23 ]
24}
25>