• EMQX 入门教程③——默认端口、端口策略和端口修改


    一、前文

    EMQX 入门教程——导读

    二、默认端口

    • emqx初次安装和启动之后,其端口使用情况如下
    [root@iZ2ze30dygwd6yh7gu6lskZ home]# netstat -nplt
    Active Internet connections (only servers)
    Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
    tcp        0      0 0.0.0.0:5355            0.0.0.0:*               LISTEN      1339/systemd-resolv 
    tcp        0      0 0.0.0.0:6379            0.0.0.0:*               LISTEN      1110/redis-server * 
    tcp        0      0 0.0.0.0:4370            0.0.0.0:*               LISTEN      7344/emqx           
    tcp        0      0 0.0.0.0:8083            0.0.0.0:*               LISTEN      7344/emqx           
    tcp        0      0 0.0.0.0:8883            0.0.0.0:*               LISTEN      7344/emqx           
    tcp        0      0 0.0.0.0:8084            0.0.0.0:*               LISTEN      7344/emqx           
    tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1402/sshd           
    tcp        0      0 0.0.0.0:5370            0.0.0.0:*               LISTEN      7344/emqx           
    tcp        0      0 0.0.0.0:1883            0.0.0.0:*               LISTEN      7344/emqx           
    tcp        0      0 0.0.0.0:18083           0.0.0.0:*               LISTEN      7344/emqx           
    tcp6       0      0 :::3306                 :::*                    LISTEN      1298/mysqld         
    tcp6       0      0 :::5355                 :::*                    LISTEN      1339/systemd-resolv 
    tcp6       0      0 :::6379                 :::*                    LISTEN      1110/redis-server * 
    tcp6       0      0 :::8080                 :::*                    LISTEN      7760/java           
    tcp6       0      0 :::8443                 :::*                    LISTEN      7760/java           
    tcp6       0      0 :::33060                :::*                    LISTEN      1298/mysqld   
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    端口描述
    8083mqtt ws 监听端口
    8084mqtt wss 监听端口
    1883mqtt tcp 监听端口
    8883mqtt ssl 监听端口
    18083http 监听端口
    4370Erlang 分布端口
    5370集群 RPC 端口

    EMQX 4.x 版本的时候还有8081端口,不过在EMQX 5.x时,被合并到18083

    三、端口策略

    常规的用法,我们一般使用和开放这两个端口:

    • 1883,设备连接的端口
    • 18083,后端API对接端口

    因为开放,所以风险。
    默认的端口号往往会引来很频繁的扫描攻击。

    于是,我们要这么做:

    四、1883端口修改

    配置文件修改/etc/emqx/emqx.conf

    listeners.tcp.default {
    #  bind = "0.0.0.0:1883"
      bind = "0.0.0.0:2883"
      max_connections = 1024000
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    dashboard {
        listeners.http {
    #        bind = 18083
            bind = 28083
        }
        default_username = "admin"
        default_password = "public"
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

    五、重启emqx

    emqx restart 好像在5.x版本之后不能用了,只能先stop再start

    [root@iZ2ze30dygwd6yh7gu6lskZ emqx]# emqx stop
    ok
    
    • 1
    • 2
    [root@iZ2ze30dygwd6yh7gu6lskZ emqx]# emqx start
    EMQX 5.0.7 is started successfully!
    
    • 1
    • 2
    • 到了这一步,可以看到端口已经变了过来
    [root@iZ2ze30dygwd6yh7gu6lskZ emqx]# netstat -nplt
    Active Internet connections (only servers)
    Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
    tcp        0      0 0.0.0.0:5355            0.0.0.0:*               LISTEN      1339/systemd-resolv 
    tcp        0      0 0.0.0.0:6379            0.0.0.0:*               LISTEN      1110/redis-server * 
    tcp        0      0 0.0.0.0:4370            0.0.0.0:*               LISTEN      9917/emqx           
    tcp        0      0 0.0.0.0:28083           0.0.0.0:*               LISTEN      9917/emqx           
    tcp        0      0 0.0.0.0:8083            0.0.0.0:*               LISTEN      9917/emqx           
    tcp        0      0 0.0.0.0:8883            0.0.0.0:*               LISTEN      9917/emqx           
    tcp        0      0 0.0.0.0:8084            0.0.0.0:*               LISTEN      9917/emqx           
    tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1402/sshd           
    tcp        0      0 0.0.0.0:5370            0.0.0.0:*               LISTEN      9917/emqx           
    tcp        0      0 0.0.0.0:2883            0.0.0.0:*               LISTEN      9917/emqx           
    tcp6       0      0 :::3306                 :::*                    LISTEN      1298/mysqld         
    tcp6       0      0 :::5355                 :::*                    LISTEN      1339/systemd-resolv 
    tcp6       0      0 :::6379                 :::*                    LISTEN      1110/redis-server * 
    tcp6       0      0 :::8080                 :::*                    LISTEN      7760/java           
    tcp6       0      0 :::8443                 :::*                    LISTEN      7760/java           
    tcp6       0      0 :::33060                :::*                    LISTEN      1298/mysqld  
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19

    觉得好,就一键三连呗(点赞+收藏+关注)

  • 相关阅读:
    服务案例|故障频发的一周,居然睡得更香!
    File 类和 IO 流
    操作系统实验三:死锁避免程序设计
    Linux——Shell脚本编程(2)
    如何在Visual Studio新C++项目中调用之前配置过的库?
    <<Java语言程序设计>>进阶篇 Exercise22_3
    科研Tetrazine-PEG-valine 四嗪-聚乙二醇-缬氨酸、色氨酸、鸟氨酸、精氨酸
    Jenkins Docker Swarm插件 配置的坑
    UE4后处理:PostProcessMaterial
    ubuntu启动转圈,无法进入登录界面
  • 原文地址:https://blog.csdn.net/kangweijian/article/details/126706035