准备
准备安装包
Install MongoDB Community Kubernetes Operator | MongoDB
创建目标文件夹
在linux中创建文件夹 (这边以/home/mongodb为安装位置)
mkdir -p /home/mongodb
上传安装文件到该目录
解压文件
tar -xzvf mongodb-linux-x86_64-rhel70-4.4.26.tgz
重命名文件夹
mv mongodb-linux-x86_64-rhel70-4.4.26 mongodb
安装
创建data、logs文件夹
进入/home/mongodb/mongodb文件夹
mkdir data logs
创建日志文件
root@aii-git[/home/mongodb/mongodb]#cd logs/
root@aii-git[/home/mongodb/mongodb/logs]#touch mongodb.log
配置环境变量
vim /etc/profile
在最后一行加上 export PATH=$PATH:/home/mongodb/mongodb/bin
执行source /etc/profile 让配置文件生效
查看配置变量
echo $PATH
编写配置文件
进入/home/mongodb/mongodb/bin
执行vim mongodb.conf
# 数据文件存放目录
dbpath = /home/mongodb/mongodb/data
# 日志文件存放目录
logpath = /home/mongodb/mongodb/logs/mongodb.log
logappend=true
# 端口
port = 27017
# 以守护程序的方式启用,即在后台运行
fork = true
# 认证模式
auth=false
# 远程连接
bind_ip=0.0.0.0
修改认证为false
设置管理员及密码
root@aii-git[/home/mongodb/mongodb/bin]#./mongod -f mongodb.conf
about to fork child process, waiting until server is ready for connections.
forked process: 59885
child process started successfully, parent exiting
添加管理员
root@aii-git[/home/mongodb/mongodb/bin]#mongo
MongoDB shell version v4.4.26
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("5dcf24e5-b224-4432-b365-e740b3dc6f41") }
MongoDB server version: 4.4.26
---
The server generated these startup warnings when booting:
2023-12-11T15:25:29.547+08:00: You are running this process as the root user, which is not recommended
---
> use admin
switched to db admin
> db.createUser({user:"root",pwd:"123456",roles:[{role:"userAdminAnyDatabase",db:"admin"},{role:"readWriteAnyDatabase",db:"admin"}]})
Successfully added user: {
"user" : "root",
"roles" : [
{
"role" : "userAdminAnyDatabase",
"db" : "admin"
},
{
"role" : "readWriteAnyDatabase",
"db" : "admin"
}
]
}
>
插入成功后,退出,停止mongo进程
修改配置文件 auth改为true
保存后重启服务
到此,MongoDB安装成功