运维管理8 分钟阅读
MongoDB 8.2.3 单机二进制安装
这次要在一台腾讯云主机上安装一台 MongoDB 8.2.3,本文记录安装步骤,仅供参考。 安装前卸载系统自带的 MongoDB 版本: bash root@lpc ~ rpm -qa grep mongodb root@lpc ~ ps -ef grep mongodb root 12591 12530 0 13:42 pts/0 00:00:00 grep --co
2026年1月27日阅读—点赞—收藏—
database
在知识库中专注阅读,并随时返回相关工具与课程
这次要在一台腾讯云主机上安装一台 MongoDB 8.2.3,本文记录安装步骤,仅供参考。 安装前卸载系统自带的 MongoDB 版本: bash root@lpc ~ rpm -qa grep mongodb root@lpc ~ ps -ef grep mongodb root 12591 12530 0 13:42 pts/0 00:00:00 grep --co
本章目标:掌握本章核心知识点 前置要求:完成前序章节学习 预计时长:60 分钟
这次要在一台腾讯云主机上安装一台 MongoDB 8.2.3,本文记录安装步骤,仅供参考。
安装前卸载系统自带的 MongoDB 版本:
1[root@lpc ~]# rpm -qa | grep mongodb2[root@lpc ~]# ps -ef | grep mongodb3root 12591 12530 0 13:42 pts/0 00:00:00 grep --color=auto mongodb4[root@lpc ~]# yum erase -y $(rpm -qa | grep mongodb-org)5No packages marked for removal.6Dependencies resolved.7Nothing to do.8Complete!提前安装依赖包:
1[root@lpc ~]# yum install libcurl openssl xz-libs2[root@lpc ~]# rpm -qa libcurl openssl xz-libs3xz-libs-5.4.7-8.tl4.x86_644libcurl-8.4.0-14.tl4.x86_645openssl-3.0.12-18.tl4.4.x86_64上传 MongoDB 安装包:
1[root@lpc ~]# mkdir /soft2[root@lpc ~]# mv /tmp/mongodb-linux-x86_64-rhel93-8.2.3.gz /soft/3[root@lpc soft]# cd /soft/4[root@lpc soft]# ls5mongodb-linux-x86_64-rhel93-8.2.3.gz解压二进制安装包:
1# 解压2[root@lpc ~]# mkdir -p /data/mongodb-8.2.33[root@lpc data]# tar -xzvf /soft/mongodb-linux-x86_64-rhel93-8.2.3.gz --strip-components=1 -C /data/mongodb-8.2.34mongodb-linux-x86_64-rhel93-8.2.3/LICENSE-Community.txt5mongodb-linux-x86_64-rhel93-8.2.3/MPL-26mongodb-linux-x86_64-rhel93-8.2.3/README7mongodb-linux-x86_64-rhel93-8.2.3/THIRD-PARTY-NOTICES8mongodb-linux-x86_64-rhel93-8.2.3/bin/9mongodb-linux-x86_64-rhel93-8.2.3/bin/install_compass10mongodb-linux-x86_64-rhel93-8.2.3/bin/mongod11mongodb-linux-x86_64-rhel93-8.2.3/bin/mongos配置环境变量:
1[root@lpc data]# cat<<-EOF>>/etc/profile2export MONGO_HOME=/data/mongodb-8.2.33export PATH=/data/mongodb-8.2.3/bin:$PATH4EOF56[root@lpc data]# source /etc/profile在 MongoDB 安装目录中创建数据、日志目录:
1[root@lpc data]# mkdir -p /data/db /data/log2[root@lpc mongodb-8.2.3]# ls3db log mongodb-8.2.3编辑 MongoDB 配置信息:
1[root@lpc data]# cat<<-EOF>/data/mongodb-8.2.3/mongodb.conf2processManagement:3 fork: true4net:5 bindIp: 0.0.0.06 port: 270177storage:8 dbPath: /data/db9systemLog:10 destination: file11 path: "/data/log/mongod.log"12 logAppend: true13EOF配置 MongoDB 为系统服务:
1[root@lpc data]# echo $MONGO_HOME2/data/mongodb-8.2.334[root@lpc data]# cat<<-EOF>/usr/lib/systemd/system/mongodb.service5[Unit]6Description=mongodb-server7After=network.target89[Service]10Type=forking11ExecStart=$MONGO_HOME/bin/mongod --config $MONGO_HOME/mongodb.conf12PrivateTmp=true1314[Install]15WantedBy=multi-user.target16EOF1718[root@lpc data]# chmod 755 /usr/lib/systemd/system/mongodb.service设置开机自启动:
1[root@lpc data]# systemctl start mongodb2[root@lpc data]# systemctl enable mongodb3[root@lpc data]# systemctl status mongodb4● mongodb.service - mongodb-server5 Loaded: loaded (/usr/lib/systemd/system/mongodb.service; enabled; preset: disabled)6 Active: active (running) since Tue 2026-01-27 11:20:08 CST; 3s ago7 Process: 50562 ExecStart=/data/mongodb-8.2.3/bin/mongod --config /data/mongodb-8.2.3/mongodb.conf (code=exited, status=0/SUCCESS)8 Main PID: 50564 (mongod)9 Tasks: 50 (limit: 4264)10 Memory: 94.1M (peak: 94.2M)11 CPU: 140ms12 CGroup: /system.slice/mongodb.service13 └─50564 /data/mongodb-8.2.3/bin/mongod --config /data/mongodb-8.2.3/mongodb.conf1415Jan 27 11:20:08 VM-48-8-tencentos systemd[1]: Starting mongodb.service - mongodb-server...16Jan 27 11:20:08 VM-48-8-tencentos mongod[50562]: {"t":{"$date":"2026-01-27T11:20:08.666+08:00"},"s":"I", "c":"-", "id":8991200, "ctx":"main","msg":"Shuffling initializers","a>17Jan 27 11:20:08 VM-48-8-tencentos mongod[50562]: about to fork child process, waiting until server is ready for connections.18Jan 27 11:20:08 VM-48-8-tencentos mongod[50564]: forked process: 5056419Jan 27 11:20:08 VM-48-8-tencentos mongod[50562]: child process started successfully, parent exiting20Jan 27 11:20:08 VM-48-8-tencentos systemd[1]: Started mongodb.service - mongodb-server.新版本已经废弃 mongo,改用 mongosh,手动下载安装:
1[root@lpc ~]# mkdir -p /data/mongosh-2.6.02[root@lpc data]# tar -xzvf /soft/mongosh-2.6.0-linux-x64-openssl3.tgz --strip-components=1 -C /data/mongosh-2.6.03mongosh-2.6.0-linux-x64-openssl3/.sbom.json4mongosh-2.6.0-linux-x64-openssl3/LICENSE-crypt-library5mongosh-2.6.0-linux-x64-openssl3/LICENSE-mongosh6mongosh-2.6.0-linux-x64-openssl3/README7mongosh-2.6.0-linux-x64-openssl3/THIRD_PARTY_NOTICES8mongosh-2.6.0-linux-x64-openssl3/bin/9mongosh-2.6.0-linux-x64-openssl3/mongosh.1.gz10mongosh-2.6.0-linux-x64-openssl3/bin/mongosh11mongosh-2.6.0-linux-x64-openssl3/bin/mongosh_crypt_v1.so配置环境变量:
1[root@lpc data]# cat<<-EOF>>/etc/profile2export PATH=/data/mongosh-2.6.0/bin:$PATH3EOF45[root@lpc data]# source /etc/profile连接 MongoDB:
1[root@lpc data]# mongosh2Current Mongosh Log ID: 697830999368bd4d49ed11013Connecting to: mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+2.6.04Using MongoDB: 8.2.35Using Mongosh: 2.6.067For mongosh info see: https://www.mongodb.com/docs/mongodb-shell/89------10 The server generated these startup warnings when booting11 2026-01-27T11:20:08.785+08:00: Access control is not enabled for the database. Read and write access to data and configuration is unrestricted12 2026-01-27T11:20:08.785+08:00: You are running this process as the root user, which is not recommended13 2026-01-27T11:20:08.785+08:00: Soft rlimits for open file descriptors too low14 2026-01-27T11:20:08.785+08:00: For customers running the current memory allocator, we suggest changing the contents of the following sysfsFile15 2026-01-27T11:20:08.785+08:00: For customers running the current memory allocator, we suggest changing the contents of the following sysfsFile16 2026-01-27T11:20:08.785+08:00: We suggest setting the contents of sysfsFile to 0.17 2026-01-27T11:20:08.785+08:00: Your system has glibc support for rseq built in, which is not yet supported by tcmalloc-google and has critical performance implications. Please set the environment variable GLIBC_TUNABLES=glibc.pthread.rseq=018------1920test> db.version()218.2.3创建一个 root 用户:
1test> use admin2switched to db admin3admin> db.createUser({user:"root", pwd:"**********", roles:[{role:"dbAdminAnyDatabase", db:"admin"}]})4{ ok: 1 }5admin> exit至此,MongoDB 安装完成。