文章目录
- 1、查看物理机是否支持avx指令集:安装资料中的cpu-z_2.10-cn.exe,并打开
- 2、查看虚拟机是否支持avx指令集:
- 3、创建目录
- 4、使用Docker来运行一个MongoDB数据库实例
- 5、进入容器
- 6、查看当前db版本
- 7、查看当前db的链接机器地址
- 8、帮助指令
- 9、退出命令行
注意:MongoDB 5.0+需要系统支持avx指令集。
1、查看物理机是否支持avx指令集:安装资料中的cpu-z_2.10-cn.exe,并打开
如果物理机不支持,那么恭喜你:该换新电脑了,或者去玩5.0以下版本。
2、查看虚拟机是否支持avx指令集:
[root@localhost ~]# grep avx /proc/cpuinfo
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon nopl xtopology tsc_reliable nonstop_tsc eagerfpu pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch fsgsbase tsc_adjust bmi1 avx2 smep bmi2 invpcid rdseed adx smap clflushopt xsaveopt xsavec xgetbv1 arat
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon nopl xtopology tsc_reliable nonstop_tsc eagerfpu pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch fsgsbase tsc_adjust bmi1 avx2 smep bmi2 invpcid rdseed adx smap clflushopt xsaveopt xsavec xgetbv1 arat
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon nopl xtopology tsc_reliable nonstop_tsc eagerfpu pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch fsgsbase tsc_adjust bmi1 avx2 smep bmi2 invpcid rdseed adx smap clflushopt xsaveopt xsavec xgetbv1 arat
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon nopl xtopology tsc_reliable nonstop_tsc eagerfpu pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch fsgsbase tsc_adjust bmi1 avx2 smep bmi2 invpcid rdseed adx smap clflushopt xsaveopt xsavec xgetbv1 arat
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon nopl xtopology tsc_reliable nonstop_tsc eagerfpu pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch fsgsbase tsc_adjust bmi1 avx2 smep bmi2 invpcid rdseed adx smap clflushopt xsaveopt xsavec xgetbv1 arat
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon nopl xtopology tsc_reliable nonstop_tsc eagerfpu pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch fsgsbase tsc_adjust bmi1 avx2 smep bmi2 invpcid rdseed adx smap clflushopt xsaveopt xsavec xgetbv1 arat
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon nopl xtopology tsc_reliable nonstop_tsc eagerfpu pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch fsgsbase tsc_adjust bmi1 avx2 smep bmi2 invpcid rdseed adx smap clflushopt xsaveopt xsavec xgetbv1 arat
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon nopl xtopology tsc_reliable nonstop_tsc eagerfpu pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch fsgsbase tsc_adjust bmi1 avx2 smep bmi2 invpcid rdseed adx smap clflushopt xsaveopt xsavec xgetbv1 arat
3、创建目录
[root@localhost ~]# mkdir -p /opt/mongo/data/db
4、使用Docker来运行一个MongoDB数据库实例
但是在拉取 mongo:7.0.0 的镜像的时候总是失败,于是找了各种 镜像加速器都不行,基本都失效了,唯一行的还是
https://docker.m.daocloud.io 是 DaoCloud 提供的 Docker 镜像加速服务地址。
{
"registry-mirrors": ["https://docker.m.daocloud.io"]
}
docker run -d --restart=always -p 27017:27017 --name mongodb -v /opt/mongo/data/db:/data/db mongo:7.0.0
[root@localhost docker]# systemctl restart docker
5、进入容器
[root@localhost docker]# docker exec -it mongodb mongosh
Current Mongosh Log ID: 66a8c887d90744f1e41ddd89
Connecting to: mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+1.10.6
Using MongoDB: 7.0.0
Using Mongosh: 1.10.6
For mongosh info see: https://docs.mongodb.com/mongodb-shell/
To help improve our products, anonymous usage data is collected and sent to MongoDB periodically (https://www.mongodb.com/legal/privacy-policy).
You can opt-out by running the disableTelemetry() command.
------
The server generated these startup warnings when booting
2024-07-30T10:58:29.512+00:00: Access control is not enabled for the database. Read and write access to data and configuration is unrestricted
2024-07-30T10:58:29.513+00:00: /sys/kernel/mm/transparent_hugepage/enabled is 'always'. We suggest setting it to 'never'
2024-07-30T10:58:29.513+00:00: /sys/kernel/mm/transparent_hugepage/defrag is 'always'. We suggest setting it to 'never'
2024-07-30T10:58:29.513+00:00: vm.max_map_count is too low
------
test>
6、查看当前db版本
test> db.version()
7.0.0
7、查看当前db的链接机器地址
test> db.getMongo()
mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+1.10.6
8、帮助指令
test> db.help()
Database Class:
getMongo Returns the current database connection
getName Returns the name of the DB
getCollectionNames Returns an array containing the names of all collections in the current database.
getCollectionInfos Returns an array of documents with collection information, i.e. collection name and options, for the current database.
runCommand Runs an arbitrary command on the database.
adminCommand Runs an arbitrary command against the admin database.
aggregate Runs a specified admin/diagnostic pipeline which does not require an underlying collection.
getSiblingDB Returns another database without modifying the db variable in the shell environment.
getCollection Returns a collection or a view object that is functionally equivalent to using the db.<collectionName>.
dropDatabase Removes the current database, deleting the associated data files.
createUser Creates a new user for the database on which the method is run. db.createUser() returns a duplicate user error if the user already exists on the database.
updateUser Updates the user’s profile on the database on which you run the method. An update to a field completely replaces the previous field’s values. This includes updates to the user’s roles array.
changeUserPassword Updates a user’s password. Run the method in the database where the user is defined, i.e. the database you created the user.
logout Ends the current authentication session. This function has no effect if the current session is not authenticated.
dropUser Removes the user from the current database.
dropAllUsers Removes all users from the current database.
auth Allows a user to authenticate to the database from within the shell.
grantRolesToUser Grants additional roles to a user.
revokeRolesFromUser Removes a one or more roles from a user on the current database.
getUser Returns user information for a specified user. Run this method on the user’s database. The user must exist on the database on which the method runs.
getUsers Returns information for all the users in the database.
createCollection Create new collection
createEncryptedCollection Creates a new collection with a list of encrypted fields each with unique and auto-created data encryption keys (DEKs). This is a utility function that internally utilises ClientEnryption.createEncryptedCollection.
createView Create new view
createRole Creates a new role.
updateRole Updates the role’s profile on the database on which you run the method. An update to a field completely replaces the previous field’s values.
dropRole Removes the role from the current database.
dropAllRoles Removes all roles from the current database.
grantRolesToRole Grants additional roles to a role.
revokeRolesFromRole Removes a one or more roles from a role on the current database.
grantPrivilegesToRole Grants additional privileges to a role.
revokePrivilegesFromRole Removes a one or more privileges from a role on the current database.
getRole Returns role information for a specified role. Run this method on the role’s database. The role must exist on the database on which the method runs.
getRoles Returns information for all the roles in the database.
currentOp Runs an aggregation using $currentOp operator. Returns a document that contains information on in-progress operations for the database instance. For further information, see $currentOp.
killOp Calls the killOp command. Terminates an operation as specified by the operation ID. To find operations and their corresponding IDs, see $currentOp or db.currentOp().
shutdownServer Calls the shutdown command. Shuts down the current mongod or mongos process cleanly and safely. You must issue the db.shutdownServer() operation against the admin database.
fsyncLock Calls the fsync command. Forces the mongod to flush all pending write operations to disk and locks the entire mongod instance to prevent additional writes until the user releases the lock with a corresponding db.fsyncUnlock() command.
fsyncUnlock Calls the fsyncUnlock command. Reduces the lock taken by db.fsyncLock() on a mongod instance by 1.
version returns the db version. uses the buildinfo command
serverBits returns the db serverBits. uses the buildInfo command
isMaster Calls the isMaster command
hello Calls the hello command
serverBuildInfo returns the db serverBuildInfo. uses the buildInfo command
serverStatus returns the server stats. uses the serverStatus command
stats returns the db stats. uses the dbStats command
hostInfo Calls the hostInfo command
serverCmdLineOpts returns the db serverCmdLineOpts. uses the getCmdLineOpts command
rotateCertificates Calls the rotateCertificates command
printCollectionStats Prints the collection.stats for each collection in the db.
getFreeMonitoringStatus Calls the getFreeMonitoringStatus command
disableFreeMonitoring returns the db disableFreeMonitoring. uses the setFreeMonitoring command
enableFreeMonitoring returns the db enableFreeMonitoring. uses the setFreeMonitoring command
getProfilingStatus returns the db getProfilingStatus. uses the profile command
setProfilingLevel returns the db setProfilingLevel. uses the profile command
setLogLevel returns the db setLogLevel. uses the setParameter command
getLogComponents returns the db getLogComponents. uses the getParameter command
cloneDatabase deprecated, non-functional
cloneCollection deprecated, non-functional
copyDatabase deprecated, non-functional
commandHelp returns the db commandHelp. uses the passed in command with help: true
listCommands Calls the listCommands command
getLastErrorObj Calls the getLastError command
getLastError Calls the getLastError command
printShardingStatus Calls sh.status(verbose)
printSecondaryReplicationInfo Prints secondary replicaset information
getReplicationInfo Returns replication information
printReplicationInfo Formats sh.getReplicationInfo
printSlaveReplicationInfo DEPRECATED. Use db.printSecondaryReplicationInfo
setSecondaryOk This method is deprecated. Use db.getMongo().setReadPref() instead
watch Opens a change stream cursor on the database
sql (Experimental) Runs a SQL query against Atlas Data Lake. Note: this is an experimental feature that may be subject to change in future releases.
checkMetadataConsistency Returns a cursor with information about metadata inconsistencies
9、退出命令行
test> quit()
[root@localhost docker]#