1.用yay安装
yay -S mongodb-bin
2.按照个人喜好配置设置(以下是我的设置)
配置文件位置:/etc/mongodb.conf
# mongod.conf
# for documentation of all options, see:
# http://docs.mongodb.org/manual/reference/configuration-options/
# Where and how to store data.
storage:
dbPath: /home/ronald/DBS/Mongodb/Data
journal:
enabled: true
# engine:
# mmapv1:
# wiredTiger:
# where to write logging data.
systemLog:
destination: file
logAppend: true
path: /home/ronald/DBS/Mongodb/Logs/mongod.log
# network interfaces
net:
port: 27017
bindIp: 127.0.0.1
# how the process runs
processManagement:
timeZoneInfo: /usr/share/zoneinfo
#security:
#operationProfiling:
#replication:
#sharding:
## Enterprise-Only Options:
#auditLog:
#snmp:
服务文件位置 : /usr/lib/systemd/system/mongodb.service
[Unit]
Description=MongoDB Database Server
Documentation=https://docs.mongodb.org/manual
After=network-online.target
Wants=network-online.target
[Service]
User=ronald
Group=ronald
ExecStart=/usr/bin/mongod --quiet --config /etc/mongodb.conf
PIDFile=/run/mongodb/mongod.pid
# file size
LimitFSIZE=infinity
# cpu time
LimitCPU=infinity
# virtual memory size
LimitAS=infinity
# open files
LimitNOFILE=64000
# processes/threads
LimitNPROC=64000
# locked memory
LimitMEMLOCK=infinity
# total threads (user+kernel)
TasksMax=infinity
TasksAccounting=false
# Make systemd wait as long as it takes for MongoDB to start
# If MongoDB needs a long time to start, prevent systemd from
# restarting it every 90 seconds
# See: https://jira.mongodb.org/browse/SERVER-38086
TimeoutStartSec=infinity
Restart=always
RestartSec=10
# Recommended limits for mongod as specified in
# https://docs.mongodb.com/manual/reference/ulimit/#recommended-ulimit-settings
[Install]
WantedBy=multi-user.target
3.启动服务
启动服务时遇到的坑 记住一定要给文件加权限 Service中的User和Group改成用户名
sudo chown -Rc ronald /home/ronald/DBS/Mongodb
sudo chown -Rc ronald /usr/bin/mongod
sudo chown -Rc ronald /etc/mongodb.conf
sudo chown -Rc ronald /tmp/mongodb-27017.sock
启动服务
systemctl start mongodb
开机启动
sudo systemctl enable mongodb
查看状态
sudo systemctl status mongodb
4.进入mongo shell
sudo vim /etc/profile
# 添加一行
export PATH=$PATH:/bin/mongo
#使环境变量立即生效
source /etc/profile
mongo