mongodb是一个优秀的nosql数据库
01 可以下载好安装包 win下下载后通过ftp传到服务器也可以 通过wget 方式下载也可以
02 tar-zxvf 解压 或者通过yum安装
03 安装好之后 还只是初步
04
开启认证
如上图所示 开启认证
这里只有一个问题,一定要注意书写格式,该文件在 /etc/mongo.conf
下一步,
05
[root@iZwz9fuhdjps6267gqeu8nZ ~]# mongod --config /etc/mongod.conf
注意这一行
就是开启服务
06
这里添加一个用户
然后验证
虽然这里写的很简单,但是我却配置了一上午 操他妈
ok 连接完毕
08 接下来干什么
当让是开启一个新的数据库啦 应为mongodb和mysql不一样,他是一个库一个密码
Connecting to 47.107.112.148:22…
Connection established.
To escape to local shell, press ‘Ctrl+Alt+]’.
WARNING! The remote SSH server rejected X11 forwarding request.
Last login: Wed Dec 19 16:51:44 2018 from 218.28.87.19
Welcome to Alibaba Cloud Elastic Compute Service !
[root@iZwz9fuhdjps6267gqeu8nZ ~]# ls
[root@iZwz9fuhdjps6267gqeu8nZ ~]# vi /etc/yum.repos.d/mongodb-org-3.4.repo
[root@iZwz9fuhdjps6267gqeu8nZ ~]# yum install -y mongodb-org
Loaded plugins: fastestmirror
File contains no section headers.
file: file:///etc/yum.repos.d/mongodb-org-3.4.repo, line: 2
‘ngodb-org-3.4]\n’
[root@iZwz9fuhdjps6267gqeu8nZ ~]# ^C
[root@iZwz9fuhdjps6267gqeu8nZ ~]# vi /etc/yum.repos.d/mongodb-org-3.4.repo
[root@iZwz9fuhdjps6267gqeu8nZ ~]# yum install -y mongodb-org
Loaded plugins: fastestmirror
File contains no section headers.
file: file:///etc/yum.repos.d/mongodb-org-3.4.repo, line: 2
‘ngodb-org-3.4]\n’
[root@iZwz9fuhdjps6267gqeu8nZ ~]# cd …/
[root@iZwz9fuhdjps6267gqeu8nZ /]# cd myweb
-bash: cd: myweb: No such file or directory
[root@iZwz9fuhdjps6267gqeu8nZ /]# mkdir myweb
[root@iZwz9fuhdjps6267gqeu8nZ /]# wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-4.0.1.tgz
–2018-12-19 18:11:07-- https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-4.0.1.tgz
Resolving fastdl.mongodb.org (fastdl.mongodb.org)… 13.33.172.118, 13.33.172.3, 13.33.172.155, …
Connecting to fastdl.mongodb.org (fastdl.mongodb.org)|13.33.172.118|:443… connected.
HTTP request sent, awaiting response… 200 OK
Length: 70854807 (68M) [application/x-gzip]
Saving to: ‘mongodb-linux-x86_64-4.0.1.tgz’
100%[===============================================================================================>] 70,854,807 10.4MB/s in 8.0s
2018-12-19 18:11:18 (8.50 MB/s) - ‘mongodb-linux-x86_64-4.0.1.tgz’ saved [70854807/70854807]
[root@iZwz9fuhdjps6267gqeu8nZ /]# cd my
-bash: cd: my: No such file or directory
[root@iZwz9fuhdjps6267gqeu8nZ /]# ll
total 69264
lrwxrwxrwx. 1 root root 7 Aug 18 2017 bin -> usr/bin
dr-xr-xr-x. 4 root root 4096 Sep 12 2017 boot
drwxr-xr-x 19 root root 2960 Dec 17 11:52 dev
drwxr-xr-x. 82 root root 4096 Dec 17 12:18 etc
drwxr-xr-x. 3 root root 4096 Dec 17 11:52 home
lrwxrwxrwx. 1 root root 7 Aug 18 2017 lib -> usr/lib
lrwxrwxrwx. 1 root root 9 Aug 18 2017 lib64 -> usr/lib64
drwx------. 2 root root 16384 Aug 18 2017 lost+found
drwxr-xr-x. 2 root root 4096 Nov 5 2016 media
drwxr-xr-x. 2 root root 4096 Nov 5 2016 mnt
-rw-r–r-- 1 root root 70854807 Aug 4 02:04 mongodb-linux-x86_64-4.0.1.tgz
drwxr-xr-x 2 root root 4096 Dec 17 11:59 mysql
drwxr-xr-x 2 root root 4096 Dec 19 18:11 myweb
drwxr-xr-x. 2 root root 4096 Nov 5 2016 opt
dr-xr-xr-x 77 root root 0 Dec 17 11:52 proc
dr-xr-x—. 6 root root 4096 Dec 17 12:21 root
drwxr-xr-x 22 root root 600 Dec 17 12:05 run
lrwxrwxrwx. 1 root root 8 Aug 18 2017 sbin -> usr/sbin
drwxr-xr-x. 2 root root 4096 Nov 5 2016 srv
dr-xr-xr-x 13 root root 0 Dec 17 19:52 sys
drwxrwxrwt. 9 root root 4096 Dec 19 03:25 tmp
drwxr-xr-x. 13 root root 4096 Aug 18 2017 usr
drwxr-xr-x. 19 root root 4096 Dec 17 19:52 var
[root@iZwz9fuhdjps6267gqeu8nZ /]# mv mongodb-linux-x86_64-4.0.1.tgz /myweb/
[root@iZwz9fuhdjps6267gqeu8nZ /]# cd myweb/
[root@iZwz9fuhdjps6267gqeu8nZ myweb]# tar -zxvf mongodb-linux-x86_64-4.0.1.tgz
mongodb-linux-x86_64-4.0.1/README
mongodb-linux-x86_64-4.0.1/THIRD-PARTY-NOTICES
mongodb-linux-x86_64-4.0.1/MPL-2
mongodb-linux-x86_64-4.0.1/GNU-AGPL-3.0
mongodb-linux-x86_64-4.0.1/LICENSE-Community.txt
mongodb-linux-x86_64-4.0.1/bin/mongodump
mongodb-linux-x86_64-4.0.1/bin/mongorestore
mongodb-linux-x86_64-4.0.1/bin/mongoexport
mongodb-linux-x86_64-4.0.1/bin/mongoimport
mongodb-linux-x86_64-4.0.1/bin/mongostat
mongodb-linux-x86_64-4.0.1/bin/mongotop
mongodb-linux-x86_64-4.0.1/bin/bsondump
mongodb-linux-x86_64-4.0.1/bin/mongofiles
mongodb-linux-x86_64-4.0.1/bin/mongoreplay
mongodb-linux-x86_64-4.0.1/bin/mongod
mongodb-linux-x86_64-4.0.1/bin/mongos
mongodb-linux-x86_64-4.0.1/bin/mongo
mongodb-linux-x86_64-4.0.1/bin/install_compass
[root@iZwz9fuhdjps6267gqeu8nZ myweb]# mv mongodb-linux-x86_64-4.0.1 mongodb
[root@iZwz9fuhdjps6267gqeu8nZ myweb]# ll
total 69200
drwxr-xr-x 3 root root 4096 Dec 19 18:13 mongodb
-rw-r–r-- 1 root root 70854807 Aug 4 02:04 mongodb-linux-x86_64-4.0.1.tgz
[root@iZwz9fuhdjps6267gqeu8nZ myweb]# cd mongodb
[root@iZwz9fuhdjps6267gqeu8nZ mongodb]# mkdir db logs
[root@iZwz9fuhdjps6267gqeu8nZ mongodb]# cd bin/
[root@iZwz9fuhdjps6267gqeu8nZ bin]# ll
total 208812
-rwxr-xr-x 1 root root 6906321 Aug 4 01:43 bsondump
-rwxr-xr-x 1 root root 5792 Aug 4 01:59 install_compass
-rwxr-xr-x 1 root root 38886336 Aug 4 01:59 mongo
-rwxr-xr-x 1 root root 60972352 Aug 4 01:59 mongod
-rwxr-xr-x 1 root root 10255092 Aug 4 01:43 mongodump
-rwxr-xr-x 1 root root 8245971 Aug 4 01:43 mongoexport
-rwxr-xr-x 1 root root 8123365 Aug 4 01:43 mongofiles
-rwxr-xr-x 1 root root 8404330 Aug 4 01:43 mongoimport
-rwxr-xr-x 1 root root 9322864 Aug 4 01:43 mongoreplay
-rwxr-xr-x 1 root root 11451628 Aug 4 01:43 mongorestore
-rwxr-xr-x 1 root root 34621336 Aug 4 01:59 mongos
-rwxr-xr-x 1 root root 8483293 Aug 4 01:43 mongostat
-rwxr-xr-x 1 root root 8116571 Aug 4 01:43 mongotop
[root@iZwz9fuhdjps6267gqeu8nZ bin]# vi mongodb.conf
[root@iZwz9fuhdjps6267gqeu8nZ bin]# cd …
[root@iZwz9fuhdjps6267gqeu8nZ mongodb]# pwd
/myweb/mongodb
[root@iZwz9fuhdjps6267gqeu8nZ mongodb]# cd bin/
[root@iZwz9fuhdjps6267gqeu8nZ bin]# ll
total 208816
-rwxr-xr-x 1 root root 6906321 Aug 4 01:43 bsondump
-rwxr-xr-x 1 root root 5792 Aug 4 01:59 install_compass
-rwxr-xr-x 1 root root 38886336 Aug 4 01:59 mongo
-rwxr-xr-x 1 root root 60972352 Aug 4 01:59 mongod
-rw-r–r-- 1 root root 87 Dec 19 18:20 mongodb.conf
-rwxr-xr-x 1 root root 10255092 Aug 4 01:43 mongodump
-rwxr-xr-x 1 root root 8245971 Aug 4 01:43 mongoexport
-rwxr-xr-x 1 root root 8123365 Aug 4 01:43 mongofiles
-rwxr-xr-x 1 root root 8404330 Aug 4 01:43 mongoimport
-rwxr-xr-x 1 root root 9322864 Aug 4 01:43 mongoreplay
-rwxr-xr-x 1 root root 11451628 Aug 4 01:43 mongorestore
-rwxr-xr-x 1 root root 34621336 Aug 4 01:59 mongos
-rwxr-xr-x 1 root root 8483293 Aug 4 01:43 mongostat
-rwxr-xr-x 1 root root 8116571 Aug 4 01:43 mongotop
[root@iZwz9fuhdjps6267gqeu8nZ bin]# vi mongodb.conf
[root@iZwz9fuhdjps6267gqeu8nZ bin]# pwd
/myweb/mongodb/bin
[root@iZwz9fuhdjps6267gqeu8nZ bin]# vi /etc/profile
[root@iZwz9fuhdjps6267gqeu8nZ bin]# source /etc/profile
[root@iZwz9fuhdjps6267gqeu8nZ bin]# pwd
/myweb/mongodb/bin
[root@iZwz9fuhdjps6267gqeu8nZ bin]# mongod -f mongodb.conf
about to fork child process, waiting until server is ready for connections.
forked process: 22346
child process started successfully, parent exiting
[root@iZwz9fuhdjps6267gqeu8nZ bin]# mongo
MongoDB shell version v4.0.1
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 4.0.1
Welcome to the MongoDB shell.
For interactive help, type “help”.
For more comprehensive documentation, see
http://docs.mongodb.org/
Questions? Try the support group
http://groups.google.com/group/mongodb-user
show dbs
;
^C
bye
[root@iZwz9fuhdjps6267gqeu8nZ bin]# vi /etc/mo
modprobe.d/ modules-load.d/ motd
[root@iZwz9fuhdjps6267gqeu8nZ bin]# mongo
MongoDB shell version v4.0.1
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 4.0.1
use admin
switched to db admin
db.createUser({
… user:“lixin”,
… pwd:“188282lll”,
… roles:[{role:“userAdminAnyDatabase”,db:“admin”}],
… })
Successfully added user: {
“user” : “lixin”,
“roles” : [
{
“role” : “userAdminAnyDatabase”,
“db” : “admin”
}
]
}
db.auth(“lixin”,“188282lll”)
1
use myweb
switched to db myweb
db.createUser({
… user:“lixin”,
… pwd:“188282lll”,
… role:[{“role”:“readWrite”,
… “db”:“myweb”}],
… })
2018-12-19T18:40:48.620+0800 E QUERY [js] Error: couldn’t add user: “role” is not a valid argument to createUser :
_getErrorWithCode@src/mongo/shell/utils.js:25:13
DB.prototype.createUser@src/mongo/shell/db.js:1491:15
@(shell):1:1
db.createUser({
… … user:“lixin”,
… … pwd:“188282lll”,
… … role:[{“role”:“readWrite”,
… … “db”:“myweb”}],
… … })
2018-12-19T18:41:09.505+0800 E QUERY [js] Error: couldn’t add user: “role” is not a valid argument to createUser :
_getErrorWithCode@src/mongo/shell/utils.js:25:13
DB.prototype.createUser@src/mongo/shell/db.js:1491:15
@(shell):1:1
db.createUser({
… user:“lixin”,
… pwd:“188282lll”,
… roles:[{“role”:“readWrite”,
… “db”:“myweb”}],
… })
Successfully added user: {
“user” : “lixin”,
“roles” : [
{
“role” : “readWrite”,
“db” : “myweb”
}
]
}
exit;
[root@iZwz9fuhdjps6267gqeu8nZ bin]#