0.确定服务器是Centos

cat /etc/redhat-release

CentOS Linux release 7.2.1511 (Core)

  1. rpm
rpm -ivh mongodb-org-server-7.0.14-1.el7.x86_64.rpm

2.修改 /etc/mongod.conf 这个配置文件
改为了0.0.0.0适配所有ip

# mongod.conf
systemLog:
  destination: file
  logAppend: true
  path: /var/log/mongodb/mongod.log
# Where and how to store data.
storage:
  dbPath: /var/lib/mongo
# how the process runs
processManagement:
  timeZoneInfo: /usr/share/zoneinfo
# network interfaces
net:
  port: 27017
  bindIp: 0.0.0.0

3.启动服务

systemctl start mongod.service

4.检查服务状态

 systemctl status mongod

5.也可以关闭服务

 systemctl stop mongod.service

6.防火墙状态

systemctl status firewalld.service


● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
   Active: active (running) since 五 2024-10-25 10:23:17 CST; 1 day 8h ago
 Main PID: 909 (firewalld)
   CGroup: /system.slice/firewalld.service
           └─909 /usr/bin/python -Es /usr/sbin/firewalld --nofork --nopid

7.查询防火墙放开的端口列表

firewall-cmd --permanent --list-ports

也可以单独查看某个端口是否放开

 firewall-cmd --query-port=27017/tcp

8.增加端口

firewall-cmd --permanent --add-port=27017/tcp

9.关闭防火墙,重启防火墙

systemctl stop firewalld.service
systemctl start firewalld.service

P.S 似乎可以通过reload来实现,我没有尝试

firewall-cmd --reload

点赞(0) 打赏

评论列表 共有 0 条评论

暂无评论

微信公众账号

微信扫一扫加关注

发表
评论
返回
顶部