1.下载MongoDB
使用wget
从官网进行下载对应系统的MongoDB
版本
选择MongoDB
版本页面,官网链接,选择后直接点击Copy link复制压缩包链接
[root@localhost mnt]# wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-4.4.24.tgz
2. 解压并重命名
[root@localhost mnt]# tar -zvf mongodb-linux-x86_64-rhel70-4.4.24.tgz
[root@localhost mnt]# mv mongodb-linux-x86_64-rhel70-4.4.24.tgz mongodb
3. 创建存储文件夹和日志文件
[root@localhost mnt]# mkdir -p data/db/
[root@localhost mnt]# mkdir -p data/logs/
[root@localhost mnt]# touch data/logs/mongologs.log
4.创建并编辑配置文件
[root@localhost mnt]# cd data
[root@localhost mnt]# vim mongodb.conf
#日志存储位置
logpath=/mnt/mongodb/data/logs/mongologs.log
# 以追加方式写入日志
logappend=true
#数据库存储位置
dbpath=/mnt/mongodb/data/db
#默认端口
port=27017
#是否以守护进程方式后台运行
fork=true
5.启动MongoDB服务
[root@localhost /]# /mnt/mongodb/bin/mongod --config /mnt/mongodb/data/mongodb.conf
about to fork child process, waiting until server is ready for connections.
forked process: 10483
child process started
6. 添加配置环境
[root@localhost /]# export PATH =/mnt/mongodb/bin:$PATH
7. 关闭MongoDB服务(需要使用MongoDB时不要关闭)
[root@localhost /]# /mnt/mongodb/bin/mongod --config /mnt/mongodb/data/mongodb.conf
8.进入MongoDB的shell模式
[root@localhost /]# mongo
MongoDB shell version v4.4.24
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("7346e7d7-96ab-4eff-a2ee-2e21c0592536") }
MongoDB server version: 4.4.24
---
The server generated these startup warnings when booting:
2023-09-26T20:07:13.604-07:00: Access control is not enabled for the database. Read and write access to data and configuration is unrestricted
2023-09-26T20:07:13.604-07:00: You are running this process as the root user, which is not recommended
2023-09-26T20:07:13.604-07:00: This server is bound to localhost. Remote systems will be unable to connect to this server. Start the server with --bind_ip <address> to specify which IP addresses it should serve responses from, or with --bind_ip_all to bind to all interfaces. If this behavior is desired, start the server with --bind_ip 127.0.0.1 to disable this warning
2023-09-26T20:07:13.605-07:00: /sys/kernel/mm/transparent_hugepage/enabled is 'always'. We suggest setting it to 'never'
2023-09-26T20:07:13.605-07:00: /sys/kernel/mm/transparent_hugepage/defrag is 'always'. We suggest setting it to 'never'
2023-09-26T20:07:13.605-07:00: Soft rlimits too low
2023-09-26T20:07:13.605-07:00: currentValue: 1024
2023-09-26T20:07:13.605-07:00: recommendedMinimum: 64000
---
> exit
bye