1.配置YUM
配置yum文件
cat mongodb.repo
[mongodb-org-5.0]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/7/mongodb-org/5.0/x86_64/
gpgcheck=0
enabled=1
#gpgkey=https://pgp.mongodb.com/server-5.0.asc
[root@test yum.repos.d]# yum makecache
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
local | 3.6 kB 00:00:00
mongodb-org-5.0 | 1.3 kB 00:00:00
(1/3): mongodb-org-5.0/primary | 61 kB 00:00:00
(2/3): mongodb-org-5.0/other | 21 kB 00:00:00
(3/3): mongodb-org-5.0/filelists | 22 kB 00:00:16
mongodb-org-5.0 498/498
mongodb-org-5.0 498/498
mongodb-org-5.0 498/498
Metadata Cache Created
关闭YUM自动更新(安装完后执行)
vi /etc/yum.conf 添加:
exclude=mongodb-org,mongodb-org-database,mongodb-org-server,mongodb-mongosh,mongodb-org-mongos,mongodb-org-tools
2.安装MongoDB 5.0
yum install -y mongodb-org-5.0.28 mongodb-org-database-5.0.28 mongodb-org-server-5.0.28 mongodb-org-shell-5.0.28 mongodb-org-mongos-5.0.28 mongodb-org-tools-5.0.28
3.启动mongod
[root@test yum.repos.d]# systemctl start mongod
[root@test yum.repos.d]# systemctl status mongod
● mongod.service - MongoDB Database Server
Loaded: loaded (/usr/lib/systemd/system/mongod.service; enabled; vendor preset: disabled)
Active: active (running) since Sat 2024-08-10 00:34:09 EDT; 6s ago
Docs: https://docs.mongodb.org/manual
Main PID: 19542 (mongod)
CGroup: /system.slice/mongod.service
└─19542 /usr/bin/mongod -f /etc/mongod.conf
Aug 10 00:34:09 test systemd[1]: Started MongoDB Database Server.
Aug 10 00:34:09 test mongod[19542]: {"t":{"$date":"2024-08-10T04:34:09.372Z"},"s":"I", "c":"CONTROL", "id":7484500, "ctx":"-","msg":"Environment variable MONGODB_CONFIG_OVERRI...\" to false"}
Hint: Some lines were ellipsized, use -l to show in full.
4.连接mongosh
[root@test yum.repos.d]# mongosh
Current Mongosh Log ID: 66b6edff3169b05c3e838725
Connecting to: mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+2.2.15
Using MongoDB: 5.0.28
Using Mongosh: 2.2.15
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-08-10T00:34:10.530-04:00: Access control is not enabled for the database. Read and write access to data and configuration is unrestricted
2024-08-10T00:34:10.536-04:00: /sys/kernel/mm/transparent_hugepage/enabled is 'always'. We suggest setting it to 'never' in this binary version
2024-08-10T00:34:10.536-04:00: /sys/kernel/mm/transparent_hugepage/defrag is 'always'. We suggest setting it to 'never' in this binary version
------
Deprecation warnings:
- Using mongosh on the current operating system is deprecated, and support may be removed in a future release.
See https://www.mongodb.com/docs/mongodb-shell/install/#supported-operating-systems for documentation on supported platforms.
test> show dbs
admin 40.00 KiB
config 12.00 KiB
local 40.00 KiB
test>