咸鱼

咸鱼是以盐腌渍后,晒干的鱼

0%

EMQ阿里云集群部署

环境和实现效果:

  1. 两台阿里云服务器做集群

    服务器 1 (主):内网(10.0.0.1)外网(118.0.0.1)
    服务器 2 (从):内网(10.0.0.2)外网(118.0.0.2)

  2. 安装emq

    1
    2
    $ wget https://www.emqx.io/static/brokers/emqttd-ubuntu16.04-v2.3.11.zip
    $ unzip emqttd-ubuntu16.04-v2.3.11.zip
  3. 配置

    1
    2
    3
    4
    $ vim emqttd/etc/emq.conf

    node.name = emq@内网IP
    mqtt.allow_anonymous = false
  4. 系统调优

    切换到root账号操作比较方便

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    $ vim /etc/security/limits.conf
    ubuntu soft nofile 65535
    ubuntu hard nofile 65535
    root soft nofile 65535
    root hard nofile 65535
    * soft nofile 65536
    * hard nofile 65536
    * soft nproc 102400
    * soft memlock unlimited
    * hard memlock unlimited
    1
    2
    3
    4
    $ sysctl -w fs.file-max=2097152
    $ sysctl -w fs.nr_open=2097152
    $ echo 2097152 > /proc/sys/fs/nr_open
    $ ulimit -n 1048576
    1
    2
    3
    4
    $ vim /etc/sysctl.conf
    fs.file-max = 1048576
    $ vim /etc/systemd/system.conf
    DefaultLimitNOFILE=1048576
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    sysctl -w net.core.somaxconn=32768
    sysctl -w net.ipv4.tcp_max_syn_backlog=16384
    sysctl -w net.core.netdev_max_backlog=16384
    sysctl -w net.ipv4.ip_local_port_range='1000 65535'
    sysctl -w net.core.rmem_default=262144
    sysctl -w net.core.wmem_default=262144
    sysctl -w net.core.rmem_max=16777216
    sysctl -w net.core.wmem_max=16777216
    sysctl -w net.core.optmem_max=16777216
    sysctl -w net.ipv4.tcp_rmem='1024 4096 16777216'
    sysctl -w net.ipv4.tcp_wmem='1024 4096 16777216'
  5. 加入集群

    1
    2
    3
    4
    5
    # 以root账号运行
    $ ./bin/emqttd start

    # 在节点运行
    $ ./bin/emqttd_ctl cluster join emq@10.0.0.1
  6. 退出集群

    1
    2
    3
    4
    5
    #本节点退出集群
    $ ./bin/emqttd_ctl cluster leave

    #从集群删除其他节点
    $ ./bin/emqttd_ctl cluster remove emq@s2.emqtt.io
  7. 负载均衡

    省略