在 CentOS 上,MongoDB 默认监听的端口是:
27017
默认端口
270172701827019配置文件位置(CentOS 常见)
/etc/mongod.conf
修改端口示例
在 mongod.conf 中:
net:
port: 27017
bindIp: 127.0.0.1
修改后重启服务:
systemctl restart mongod
防火墙放行(CentOS 7+)
firewall-cmd --permanent --add-port=27017/tcp
firewall-cmd --reload
如果你是想问 MongoDB 在 CentOS 上要开哪个端口给外部访问,那就是 27017(如修改过以配置文件为准)。