在CentOS上配置MongoDB的网络设置涉及多个步骤,包括修改网络接口配置文件、配置防火墙以及设置MongoDB服务以使用特定的网络接口。以下是详细的步骤指南:
1. 配置网络接口静态IP配置(推荐用于生产环境):
查看当前网卡名称:
ip a # 或者 ifconfig关闭防火墙和SELinux(测试环境推荐):
systemctl stop firewalldsystemctl disable firewalldsed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/configsetenforce 0修改网卡配置文件:文件路径为 /etc/sysconfig/network-scripts/ifcfg-ens33(根据实际网卡名称调整)。
BOOTPROTO=staticONBOOT=yesIPADDR=192.168.1.100 # 静态IP地址NETMASK=255.255.255.0 # 子网掩码GATEWAY=192.168.1.1 # 网关DNS1=8.8.8.8 # 主DNSDNS2=114.114.114.114 # 备用DNS重启网络服务:
systemctl restart network动态IP配置(适用于开发测试环境):
简化配置:
BOOTPROTO=dhcpONBOOT=yes手动激活网卡(如果网卡未启动):
ifup ens33编辑MongoDB配置文件:文件路径为 /etc/mongod.conf。
net:port: 27017bindIp: 192.168.1.100 # 替换为你的静态IP地址重启MongoDB服务:
sudo systemctl restart mongod3. 验证网络配置测试外网连通性:
ping www.baidu.com查看路由表:
ip route show检查DNS配置:
cat /etc/resolv.conf4. 防火墙配置开放MongoDB端口:
firewall-cmd --zone=public --add-port=27017/tcp --permanentfirewall-cmd --reload检查防火墙状态:
firewall-cmd --list-ports5. MongoDB服务状态检查启动服务:
sudo systemctl start mongod检查服务状态:
sudo systemctl status mongod停止服务:
sudo systemctl stop mongod开机自启动:
sudo systemctl enable mongod上一篇:如何升级CentOS虚拟机系统
下一篇:如何在CentOS虚拟机上运行Docker容器
CentOS









