假设我要安装mongodb 4.2
版本
/etc/yum.repos.d
下创建repo仓库
cd /etc/yum.repos.d
touch mongodb-org-4.2.repo
编辑mongodb-org-4.2.repo
vim mongodb-org-4.2.repo
输入以下内容:
[mongodb-org-4.2.repo]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/7/mongodb-org/4.2/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-4.2.asc
上面的baseurl,可访问https://repo.mongodb.org/yum/redhat/7/mongodb-org/
上面的gpgkey,可访问 https://www.mongodb.org/static/pgp/
yum install -y mongodb-org
[root@123456 yum.repos.d]# yum install -y mongodb-org
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
base | 3.6 kB 00:00:00
epel | 4.7 kB 00:00:00
extras | 2.9 kB 00:00:00
mongodb-org-4.2 | 2.5 kB 00:00:00
updates | 2.9 kB 00:00:00
(1/8): base/7/x86_64/group_gz | 153 kB 00:00:00
(2/8): epel/x86_64/group_gz | 95 kB 00:00:00
(3/8): epel/x86_64/updateinfo | 1.0 MB 00:00:00
(4/8): extras/7/x86_64/primary_db | 194 kB 00:00:00
(5/8): updates/7/x86_64/primary_db | 1.3 MB 00:00:00
(6/8): epel/x86_64/primary_db | 6.8 MB 00:00:00
(7/8): base/7/x86_64/primary_db | 6.1 MB 00:00:00
(8/8): mongodb-org-4.2/primary_db | 34 kB 00:00:02
Resolving Dependencies
--> Running transaction check
---> Package mongodb-org.x86_64 0:4.2.7-1.el7 will be installed
--> Processing Dependency: mongodb-org-mongos = 4.2.7 for package: mongodb-org-4.2.7-1.el7.x86_64
--> Processing Dependency: mongodb-org-shell = 4.2.7 for package: mongodb-org-4.2.7-1.el7.x86_64
--> Processing Dependency: mongodb-org-server = 4.2.7 for package: mongodb-org-4.2.7-1.el7.x86_64
--> Processing Dependency: mongodb-org-tools = 4.2.7 for package: mongodb-org-4.2.7-1.el7.x86_64
--> Running transaction check
---> Package mongodb-org-mongos.x86_64 0:4.2.7-1.el7 will be installed
---> Package mongodb-org-server.x86_64 0:4.2.7-1.el7 will be installed
---> Package mongodb-org-shell.x86_64 0:4.2.7-1.el7 will be installed
---> Package mongodb-org-tools.x86_64 0:4.2.7-1.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
=====================================================================================================================================================================================================================================
Package Arch Version Repository Size
=====================================================================================================================================================================================================================================
Installing:
mongodb-org x86_64 4.2.7-1.el7 mongodb-org-4.2 5.8 k
Installing for dependencies:
mongodb-org-mongos x86_64 4.2.7-1.el7 mongodb-org-4.2 15 M
mongodb-org-server x86_64 4.2.7-1.el7 mongodb-org-4.2 25 M
mongodb-org-shell x86_64 4.2.7-1.el7 mongodb-org-4.2 17 M
mongodb-org-tools x86_64 4.2.7-1.el7 mongodb-org-4.2 62 M
Transaction Summary
=====================================================================================================================================================================================================================================
Install 1 Package (+4 Dependent packages)
Total download size: 119 M
Installed size: 283 M
Downloading packages:
warning: /var/cache/yum/x86_64/7/mongodb-org-4.2/packages/mongodb-org-4.2.7-1.el7.x86_64.rpm: Header V3 RSA/SHA1 Signature, key ID 058f8b6b: NOKEY ] 0.0 B/s | 0 B --:--:-- ETA
Public key for mongodb-org-4.2.7-1.el7.x86_64.rpm is not installed
(1/5): mongodb-org-4.2.7-1.el7.x86_64.rpm | 5.8 kB 00:00:01
(2/5): mongodb-org-server-4.2.7-1.el7.x86_64.rpm | 25 MB 00:00:05
(3/5): mongodb-org-shell-4.2.7-1.el7.x86_64.rpm | 17 MB 00:00:03
(4/5): mongodb-org-tools-4.2.7-1.el7.x86_64.rpm | 62 MB 00:00:09
(5/5): mongodb-org-mongos-4.2.7-1.el7.x86_64.rpm | 15 MB 00:00:44
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total 2.6 MB/s | 119 MB 00:00:45
Retrieving key from https://www.mongodb.org/static/pgp/server-4.2.asc
Importing GPG key 0x058F8B6B:
Userid : "MongoDB 4.2 Release Signing Key <packaging@mongodb.com>"
Fingerprint: e162 f504 a20c df15 827f 718d 4b7c 549a 058f 8b6b
From : https://www.mongodb.org/static/pgp/server-4.2.asc
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : mongodb-org-shell-4.2.7-1.el7.x86_64 1/5
Installing : mongodb-org-tools-4.2.7-1.el7.x86_64 2/5
Installing : mongodb-org-mongos-4.2.7-1.el7.x86_64 3/5
Installing : mongodb-org-server-4.2.7-1.el7.x86_64 4/5
Created symlink from /etc/systemd/system/multi-user.target.wants/mongod.service to /usr/lib/systemd/system/mongod.service.
Installing : mongodb-org-4.2.7-1.el7.x86_64 5/5
Verifying : mongodb-org-4.2.7-1.el7.x86_64 1/5
Verifying : mongodb-org-server-4.2.7-1.el7.x86_64 2/5
Verifying : mongodb-org-mongos-4.2.7-1.el7.x86_64 3/5
Verifying : mongodb-org-tools-4.2.7-1.el7.x86_64 4/5
Verifying : mongodb-org-shell-4.2.7-1.el7.x86_64 5/5
Installed:
mongodb-org.x86_64 0:4.2.7-1.el7
Dependency Installed:
mongodb-org-mongos.x86_64 0:4.2.7-1.el7 mongodb-org-server.x86_64 0:4.2.7-1.el7 mongodb-org-shell.x86_64 0:4.2.7-1.el7 mongodb-org-tools.x86_64 0:4.2.7-1.el7
Complete!
[root@123456 yum.repos.d]#
[root@123456 yum.repos.d]# rpm -qa |grep mongodb
mongodb-org-mongos-4.2.7-1.el7.x86_64
mongodb-org-tools-4.2.7-1.el7.x86_64
mongodb-org-shell-4.2.7-1.el7.x86_64
mongodb-org-4.2.7-1.el7.x86_64
mongodb-org-server-4.2.7-1.el7.x86_64
[root@123456 yum.repos.d]# rpm -ql mongodb-org-server
/etc/mongod.conf
/lib/systemd/system/mongod.service
/usr/bin/mongod
/usr/share/doc/mongodb-org-server-4.2.7
/usr/share/doc/mongodb-org-server-4.2.7/LICENSE-Community.txt
/usr/share/doc/mongodb-org-server-4.2.7/MPL-2
/usr/share/doc/mongodb-org-server-4.2.7/README
/usr/share/doc/mongodb-org-server-4.2.7/THIRD-PARTY-NOTICES
/usr/share/man/man1/mongod.1
/var/lib/mongo
/var/log/mongodb
/var/log/mongodb/mongod.log
/var/run/mongodb
从上面的代码可以看出,mongodb
配置文件在/etc/mongod.conf
[root@123456 yum.repos.d]# vim /etc/mongod.conf
# mongod.conf
# for documentation of all options, see:
# http://docs.mongodb.org/manual/reference/configuration-options/
# where to write logging data.
systemLog:
destination: file
logAppend: true
path: /var/log/mongodb/mongod.log
# Where and how to store data.
storage:
dbPath: /var/lib/mongo
journal:
enabled: true
# engine:
# wiredTiger:
# how the process runs
processManagement:
fork: true # fork and run in background
pidFilePath: /var/run/mongodb/mongod.pid # location of pidfile
timeZoneInfo: /usr/share/zoneinfo
# network interfaces
net:
port: 27017
bindIp: 127.0.0.1 # Enter 0.0.0.0,:: to bind to all IPv4 and IPv6 addresses or, alternatively, use the net.bindIpAll setting.
#security:
#operationProfiling:
#replication:
#sharding:
## Enterprise-Only Options
#auditLog:
#snmp:
"/etc/mongod.conf" 44L, 830C
全局执行
service mongod start
[root@123456 yum.repos.d]# service mongod start
Redirecting to /bin/systemctl start mongod.service
[root@123456 yum.repos.d]# ps -ef | grep mongod
root 4236 3730 0 11:17 pts/1 00:00:00 vim mongodb-org-4.2.1.repo
mongod 5381 1 5 11:38 ? 00:00:00 /usr/bin/mongod -f /etc/mongod.conf
root 5427 4567 0 11:38 pts/2 00:00:00 grep --color=auto mongod
[root@123456 yum.repos.d]# netstat -nltp|grep mongo
tcp 0 0 127.0.0.1:27017 0.0.0.0:* LISTEN 5381/mongod
service mongod stop
执行下面查询 ,已经查询不到mongod
的服务
[root@123456 yum.repos.d]# ps -ef | grep mongod
root 4236 3730 0 11:17 pts/1 00:00:00 vim mongodb-org-4.2.1.repo
root 5612 4567 0 11:41 pts/2 00:00:00 grep --color=auto mongod
[root@123456 yum.repos.d]# netstat -nltp|grep mongo
[root@123456 yum.repos.d]#
角色类型 | 权限级别 |
---|---|
普通用户角色 | read、readWrite |
数据库管理员角色 | dbAdmin、dbOwner、userAdmin |
集群管理员角色 | clusterAdmin、clusterManager、clusterMonitor、hostManager |
数据库备份与恢复角色 | backup、restore |
所有数据库角色 | readAnyDatabase、readWriteAnyDatabase、userAdminAnyDatabase、dbAdminAnyDatabase |
超级用户角色 | root (只有admin库才可以使用这个角色,其他库不可以使用) |
核心角色 | __system |
mongodb
管理员用户先启动mongod
服务(service mongod start
),再执行mongo
命令进行mongodb命令行
mongo
db.createUser({user: "admin", pwd: "123456",roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]})
[root@123456 ~]# mongo
MongoDB shell version v4.2.7
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("c6adb47d-4b62-4758-951f-0bacdd0fd0a9") }
MongoDB server version: 4.2.7
Server has startup warnings:
2020-05-31T11:43:46.555+0800 I STORAGE [initandlisten]
2020-05-31T11:43:46.555+0800 I STORAGE [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine
2020-05-31T11:43:46.555+0800 I STORAGE [initandlisten] ** See http://dochub.mongodb.org/core/prodnotes-filesystem
2020-05-31T11:43:47.753+0800 I CONTROL [initandlisten]
2020-05-31T11:43:47.753+0800 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2020-05-31T11:43:47.753+0800 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2020-05-31T11:43:47.753+0800 I CONTROL [initandlisten]
2020-05-31T11:43:47.753+0800 I CONTROL [initandlisten]
2020-05-31T11:43:47.753+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2020-05-31T11:43:47.753+0800 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2020-05-31T11:43:47.753+0800 I CONTROL [initandlisten]
2020-05-31T11:43:47.753+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2020-05-31T11:43:47.753+0800 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2020-05-31T11:43:47.753+0800 I CONTROL [initandlisten]
---
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()
---
> db.createUser({user: "admin", pwd: "123456",roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]})
Successfully added user: {
"user" : "admin",
"roles" : [
{
"role" : "userAdminAnyDatabase",
"db" : "admin"
}
]
}
mongodb
普通数据库用户跟创建管理员用户差不多,只是角色可能不一样,可以根据不同的db,设置不同的角色
use test
db.createUser( { user: "root", pwd: "root", roles: [ { role: "readWrite", db: "test" }, { role: "read", db: "test2" } ] } )
use test
db.createUser( { user: "root", pwd: "123456", roles: [{ role: "readWrite", db: "test" }]} )
show dbs
use admin
db.system.users.find()
db.dropUser('admin')
删除所有用户
use admin
db.system.users.find()
db.system.users.remove({})
关闭配置文件的强制认证,两行都要注释
#security:
# authorization: enabled
重新启动mongod
服务
service mongod restart
db.changeUserPassword('root','123456')
如果开启了security
选项,就先要使用管理员登录:
db.auth('admin','123456')
必须是要root权限的用户才可以执行
use admin
db.auth('root','xxxxx')
db.serverStatus().connections
{ "current" : 23, "available" : 51177, "totalCreated" : 54, "active" : 1 }
输出分别为
当前连接数 “current” : 23
可用连接数 “available” : 51177
MongoDB一共创建线程数 “totalCreated” : 54
gcc版本老旧,经常会碰到的问题:/usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.21' not found。不要在网上找各种方法,直接升级gcc吧
redis配置多个端口,redis启动多个实例
linux如何挂载新买的硬盘?
vim编辑nginx conf文件时,设置高亮/显示行号
vi/vim打开文件提示Found a swap file by the name
linux报错:C++ compiler too old, need g++ 4.9.4 or clang++ 3.4.2 (CXX=g++)
linux下如何安装nodejs
linux下安装 redis,以及相关使用
linux下通过yum安装mongodb
RPM是RedHat Package Manager(RedHat软件包管理工具)类似Windows里面的“添加/删除程序
Ubuntu 16.04 发布时,一个引人注目的新特性便是 apt 命令的引入。其实早在 2014 年,apt 命令就已经发布了第一个稳定版,只是直到 2016 年的 Ubuntu 16.04 系统发布时才开始引人关注。随着 apt install package 命令的使用频率和普遍性逐步超过 apt-get install package,越来越多的其它 Linux 发行版也开始遵循 Ubuntu 的脚步,开始鼓励用户使用 apt 而不是 apt-get。
centos查看环境变量与设置环境变量在使用过程中很常见,本文整理了一些常用的与环境变量相关的命令,感兴趣的朋友可以参考下希望对你有所帮助
linux cenos下安装oh my zsh,oh my zsh 用于管理zsh配置,使shell界面更美观。 Zsh 是一款功能强大终端(shell)软件,既可以作为一个交互式终端,也可以作为一个脚本解释器。它在兼容 Bash 的同时 (默认不兼容,除非设置成 emulate sh) 还有提供了很多改进。
通过Nginx反向代理,在一个云服务器上绑定多个域名,不同的域名访问不同的目录,端口
如何在Linux(CentOS 7)上安装Nginx,作为反向代理服务器。
命令从指定点开始将 File 参数指定的文件写到标准输出。如果没有指定文件,那么会使用标准输入。Number 变量指定将多少单元写到标准输出。Number 变量的值可以是正的或负的整数。如果值的前面有 +(加号),从文件开头指定的单元数开始将文件写到标准输出。如果值的前面有 -(减号),那么从文件末尾指定的单元数开始将文件写到标准输出。如果值前面没有 +(加号)或 -(减号),那么从文件末尾指定的单元号开始读取文件