MongoDB是一个使用非常广泛的NoSQL数据库,本文依据MongoDB installation来简单的演示如何进行安装
环境
| Name | Version Note |
|---|---|
| RHEL/CentOS Stream | 8.x on X64 |
| MongoDB | 5.0.x |
安装
我们可以使用Install MongoDB Community Edition on Red Hat or CentOS进行安装。
配置包管理系统
创建或者修改下面的文件
[root@localhost thinktik]# vim /etc/yum.repos.d/mongodb-org-5.0.repo
填入下面的内容
[mongodb-org-5.0]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/5.0/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-5.0.asc
安装
[root@localhost thinktik]# sudo yum install -y mongodb-org
启动服务
[root@localhost thinktik]# sudo systemctl start mongod
[root@localhost thinktik]# sudo systemctl status mongod
● mongod.service - MongoDB Database Server
Loaded: loaded (/usr/lib/systemd/system/mongod.service; enabled; vendor preset: disabled)
Active: active (running) since Mon 2021-12-27 15:10:28 CST; 22s ago
Docs: https://docs.mongodb.org/manual
Process: 14562 ExecStart=/usr/bin/mongod $OPTIONS (code=exited, status=0/SUCCESS)
Process: 14560 ExecStartPre=/usr/bin/chmod 0755 /var/run/mongodb (code=exited, status=0/SUCCESS)
Process: 14558 ExecStartPre=/usr/bin/chown mongod:mongod /var/run/mongodb (code=exited, status=0/SUCCESS)
Process: 14556 ExecStartPre=/usr/bin/mkdir -p /var/run/mongodb (code=exited, status=0/SUCCESS)
Main PID: 14565 (mongod)
Memory: 67.2M
CGroup: /system.slice/mongod.service
└─14565 /usr/bin/mongod -f /etc/mongod.conf
Dec 27 15:10:28 localhost.localdomain systemd[1]: Starting MongoDB Database Server...
Dec 27 15:10:28 localhost.localdomain mongod[14562]: about to fork child process, waiting until server is ready for connections.
Dec 27 15:10:28 localhost.localdomain mongod[14562]: forked process: 14565
Dec 27 15:10:28 localhost.localdomain mongod[14562]: child process started successfully, parent exiting
Dec 27 15:10:28 localhost.localdomain systemd[1]: Started MongoDB Database Server.
设置开机自启动
[root@localhost thinktik]# sudo systemctl enable mongod
登录
[root@localhost thinktik]# mongod -version
db version v5.0.5
Build Info: {
"version": "5.0.5",
"gitVersion": "d65fd89df3fc039b5c55933c0f71d647a54510ae",
"openSSLVersion": "OpenSSL 1.1.1k FIPS 25 Mar 2021",
"modules": [],
"allocator": "tcmalloc",
"environment": {
"distmod": "rhel80",
"distarch": "x86_64",
"target_arch": "x86_64"
}
}
[root@localhost thinktik]# mongosh
Current Mongosh Log ID: 61c9673c7d108e7a846b3dac
Connecting to: mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000
Using MongoDB: 5.0.5
Using Mongosh: 1.1.7
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:
2021-12-27T15:10:28.704+08:00: Access control is not enabled for the database. Read and write access to data and configuration is unrestricted
2021-12-27T15:10:28.704+08:00: /sys/kernel/mm/transparent_hugepage/enabled is 'always'. We suggest setting it to 'never'
------
test>