基础配置(Centos7.5镜像,2核2GB内存,50GB硬盘)
主机名 | IP |
---|---|
mongodb | 192.168.100.124 |
(在MongoDB官网有linux安装MongoDB的步骤)
[root@mongodb ~]# cat /etc/yum.repos.d/mongodb.repo [mongodb-org-7.0] name=MongoDB Repository baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/7.0/x86_64/ gpgcheck=1 enabled=1 gpgkey=https://www.mongodb.org/static/pgp/server-7.0.asc
(默认安装MongoDB最新版本(7.0.1)) [root@mongodb ~]# yum install -y mongodb-org (如果需要安装指定版本,需要单独指定每个组件包,并在包名后附加版本号) yum install -y mongodb-org-7.0.1 mongodb-org-database-7.0.1 mongodb-org-server-7.0.1 mongodb-mongosh-7.0.1 mongodb-org-mongos-7.0.1 mongodb-org-tools-7.0.1
[root@mongodb ~]# systemctl start mongod
(它这里有个报错先忽略掉,应该不影响后续的操作)(因为它只是一个提示信息,表明该环境变量被设置为false。通常情况下,这个环境变量不会影响MongoDB的运行) [root@mongodb ~]# systemctl status mongod ● mongod.service - MongoDB Database Server ? Loaded: loaded (/usr/lib/systemd/system/mongod.service; enabled; vendor preset: disabled) ? Active: active (running) since 五 2023-09-15 16:14:11 CST; 57s ago ? ? Docs: https://docs.mongodb.org/manual Main PID: 11031 (mongod) ? CGroup: /system.slice/mongod.service ? ? ? ? ? └─11031 /usr/bin/mongod -f /etc/mongod.conf ? 9月 15 16:14:11 mongodb systemd[1]: Started MongoDB Database Server. 9月 15 16:14:11 mongodb systemd[1]: Starting MongoDB Database Server... 9月 15 16:14:11 mongodb mongod[11031]: {"t":{"$date":"2023-09-15T08:14:11.618Z"},"s":"I", "c":"CONTROL", "id":7484500, "ctx":"main","msg":"Environment variable MONGODB_CO..." to false"} Hint: Some lines were ellipsized, use -l to show in full.
(成功进入mongodb数据库,安装成功!)
[root@mongodb ~]# mongosh Current Mongosh Log ID: 6504226fe792ed88c3dd64f6 Connecting to: ? ? ? ? mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+2.0.1 Using MongoDB: ? ? ? ? 7.0.1 Using Mongosh: ? ? ? ? 2.0.1 ? 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 ? 2023-09-15T17:21:51.287+08:00: Access control is not enabled for the database. Read and write access to data and configuration is unrestricted ? 2023-09-15T17:21:51.287+08:00: /sys/kernel/mm/transparent_hugepage/enabled is 'always'. We suggest setting it to 'never' ? 2023-09-15T17:21:51.288+08:00: /sys/kernel/mm/transparent_hugepage/defrag is 'always'. We suggest setting it to 'never' ? 2023-09-15T17:21:51.288+08:00: vm.max_map_count is too low ------ ? ? 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/ for documentation on supported platforms. test>
(默认目录如下)
/var/lib/mongo(数据目录)
/var/log/mongodb(日志目录)
(这个关于目录的,官网有介绍。如果修改了默认目录,官网也告诉了,去哪个配置文件修改什么参数,并且需要赋予修改目录所有者和所属组是mongod)