目录
8 安装MongoDB shell,因为MongoDB-6.0.24 已经移除mongo命令
1 下载MongoDB软件
https://www.mongodb.com/try/download/community
2 操作系统信息
root@u24-mongo-80:~# cat /etc/issue
Ubuntu 24.04.2 LTS \n \l
3 MongoDB 软件安装步骤
adduser mongo
tar -xf mongodb-linux-x86_64-ubuntu2204-6.0.24-rc0.tgz
mv mongodb-linux-x86_64-ubuntu2204-6.0.24-rc0 /usr/local/mongodb-6.0.24
mkdir /usr/local/mongodb-6.0.24/{auth,conf} -p
mkdir /mongodb/{data,log} -p
chown -R mongo:mongo /mongodb/data
chown mongo:mongo /usr/local/mongodb-6.0.24 -R
#配置root和mongo用户环境变量
echo 'export PATH=$PATH:/usr/local/mongodb-6.0.24/bin' >>~/.bashrc
echo 'export PATH=$PATH:/usr/local/mongodb-6.0.24/bin' >>/home/mongo/.bashrc
4 编写mongodb的配置文件
cat > /usr/local/mongodb-6.0.24/conf/mongodb.conf <<EOF
#系统日志有关
systemLog:
destination: file
logAppend: true
path: /mongodb/log/mongdb.log
#数据库存储有关
storage:
dbPath: /mongodb/data
journal:
enabled: true
wiredTiger:
engineConfig:
directoryForIndexes: true
configString: cache_size=1G
#进程
processManagement:
fork: true #后台运行
pidFilePath: /mongodb/log/mongodb.pid
timeZoneInfo: /usr/share/zoneinfo
#网络
net:
port: 27017
bindIp: 0.0.0.0
maxIncomingConnections: 1000
unixDomainSocket:
enabled: true
pathPrefix: /mongodb/data
filePermissions: 0700
#安全
security:
keyFile: /usr/local/mongodb-6.0.24/auth/keyfile.key
authorization: enabled
EOF
5 生成keyfile
openssl rand -base64 512 >/usr/local/mongodb-6.0.24/auth/keyfile.key
chmod 600 /usr/local/mongodb-6.0.24/auth/keyfile.key
6 使用mongo用户启动mongodb服务
su - mongo -c '/usr/local/mongodb-6.0.24/bin/mongod -f /usr/local/mongodb-6.0.24/conf/mongodb.conf'
7 设置开机启动(mongo用户)
vi /etc/rc.local
#! /bin/bash
su - mongo -c '/usr/local/mongodb-6.0.24/bin/mongod -f /usr/local/mongodb-6.0.24/conf/mongodb.conf'
#授予可执行权限
chmod +x /etc/rc.local
8 安装MongoDB shell
因为MongoDB-6.0.24 已经移除mongo命令
下载对应操作系统版本
https://www.mongodb.com/try/download/shell
dpkg -i mongodb-mongosh_2.5.1_amd64.deb
#登录测试
mongosh
#关闭数据库
>db.shutdownServer()
或者
su - mongo -c '/usr/local/mongodb-6.0.24/bin/mongod -f /usr/local/mongodb-6.0.24/conf/mongodb.conf --shutdown'