参考文档:https://docs.mongodb.com/manual/tutorial/install-mongodb-on-red-hat/
默认配置
- 1.默认配置文件路径
/etc/mongod.conf
- 2.默认bin目录
/usr/bin
- 3.默认日志文件路径
/var/log/mongodb/mongod.log
- 4.默认数据存储文件目录
/var/lib/mongo
1. 运行yum命令查看MongoDB的包信息:
yum info mongo
2. 若无添加repo 文件,则创建文件
vim /etc/yum.repos.d/mongodb-org-4.0.repo
[mongodb-org-4.0]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/4.0/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-4.0.asc
3.安装
yum install -y mongodb-org
4.修改配置文件
vim /etc/mongod.conf
# mongod.conf
# for documentation of all options, see:
# http://docs.mongodb.org/manual/reference/configuration-options/
# where to write logging data.
systemLog:
destination: file
logAppend: true
path: /var/log/mongodb/mongod.log
# Where and how to store data.
storage:
dbPath: /var/lib/mongo
journal:
enabled: true
# engine:
# wiredTiger:
# how the process runs
processManagement:
fork: true # fork and run in background
pidFilePath: /var/run/mongodb/mongod.pid # location of pidfile
timeZoneInfo: /usr/share/zoneinfo
# network interfaces
net:
port: 27017
# 修改为0.0.0.0 否则远程无法连接
bindIp: 0.0.0.0 # Enter 0.0.0.0,:: to bind to all IPv4 and IPv6 addresses or, alternatively, use the net.bindIpAll setting.
# 配置为启用认证(创建账号/密码用户登录)
security:
authorization: enabled
#operationProfiling:
#replication:
#sharding:
## Enterprise-Only Options
#auditLog:
#snmp:
5.开启服务
service mongod start
或者
systemctl start mongod
启动报错(Xshell):可以尝试重新打开远程工具在执行启动命令
关闭 service mongod stop 或者 systemctl stop mongod
重启 service mongod restart 或者 systemctl restart mongod
6.开机自启
chkconfig mongod on
#或者
systemctl ennable mongod
7.启动客户端 mongo
mongo --host 127.0.0.1:27017
卸载
1 关闭mongod
sudo service mongod stop
2.2 删除安装包
sudo yum erase $(rpm -qa | grep mongodb-org)
2.3 删除数据文件
sudo rm -r /var/log/mongodb
sudo rm -r /var/lib/mongo
关闭再次启动报错处理参考:https://blog.csdn.net/sinat_38385185/article/details/82699948
执行命令:
rm /var/run/mongodb/mongod.pid exists rm /tmp/mongodb-27017.sock