EMQ安装与部属

EMQ安装与部属

1.下载EMQ安装包

访问EMQ官网下载地址:

$ https://www.emqx.cn/downloads/broker/v4.2.7/emqx-centos7-4.2.7-x86_64.rpm
#1.上传到指定的文件夹/usr/local/
#2.安装 
rpm -ivh openssl-libs-1.0.2k-21.el7_9.x86_64.rpm --force
rpm -ivh erlang-22.0.7-1.el7.x86_64.rpm
rpm -ivh emqx-centos7-4.2.7-x86_64.rpm
#3.运行
sudo emqx start
#关闭防火墙
systemctl disable firewalld
systemctl stop firewalld.service
#单节点的登录
192.168.86.162:18083
admin public

2.集群部署

机器名 IP 作用
emq1 192.168.86.161 代理机器
emq2 192.168.86.162 节点1
emq3 192.168.86.163 节点2
emq4 192.168.86.164 节点3
#手动添加节点配置方式
#编辑每个节点的配置文件
vim etc/emqx/emqx.conf
#修改各自节点名称呼  集群名@IP
cluster,name = emqx
node.name = emqx@192.168.86.162
#重新启动节点
#然后将附属节点添加到集群中去
#在192.168.86.162上
emqx_ctl cluster join emqx@192.168.86.163
#在164上
emqx_ctl cluster join emqx@192.168.86.162 
#或者
emqx_ctl cluster join emqx@192.168.86.162
# 自动添加节点的配置方式
## 修改节点名  #修改各自节点名称呼  集群名@IP
node.name = emqx@192.168.86.162

## 修改集群策略为static,无需手动添加节点了
cluster.discovery = static

## 所有集群节点	
cluster.static.seeds = emqx@192.168.86.162, emqx@192.168.86.163, @emqx192.168.86.164

## 为了获取 IP 地址,需要设置 proxy_protocol
listener.tcp.external.proxy_protocol = on
挂载机器的yum源
mkdir /mnt/cdrom
#挂载命令
mount /dev/sr0 /mnt/cdrom/
#编辑yum配置文件
cat >> /etc/yum.repos.d/CentOS-Media.repo <<EOF
#添加如下内容
[local]
name=local
baseurl=file:///mnt/cdrom
gpgcheck=0
enable=1
EOF
#将默认的yum源配置文件改名  使其失效
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.back

yum makecache


#通过yum安装 haproxy
yum -y install haproxy
#查看详细信息
rpm -qi haproxy
#修改配置文件
vim /etc/haproxy/haproxy.cfg

global
    # to have these messages end up in /var/log/haproxy.log you will
    # need to:
    #
    # 1) configure syslog to accept network log events.  This is done
    #    by adding the '-r' option to the SYSLOGD_OPTIONS in
    #    /etc/sysconfig/syslog
    #
    # 2) configure local2 events to go to the /var/log/haproxy.log
    #   file. A line like the following can be added to
    #   /etc/sysconfig/syslog
    #
    # local2.*                       /var/log/haproxy.log
    #
    log         127.0.0.1 local2

    # chroot      /usr/sbin/haproxy
    pidfile     /var/run/haproxy.pid
    maxconn     1000000
    user        root
    group       root
    daemon

    # turn on stats unix socket
    # stats socket /var/lib/haproxy/stats
    # stats socket /usr/sbin/haproxy/stats

#---------------------------------------------------------------------
# common defaults that all the 'listen' and 'backend' sections will
# use if not designated in their block
#---------------------------------------------------------------------
defaults
    log                     global
    option                  dontlognull
    option http-server-close
    # option forwardfor
    retries                 3
    timeout http-request    10s
    timeout queue           1m
    timeout connect         60s
    timeout client          2m
    timeout server          2m
    timeout http-keep-alive 10s
    timeout check           10s

frontend emqtt-front
    bind *:1883
    maxconn     1000000
    mode tcp
    default_backend emqtt-backend

backend emqtt-backend
    balance roundrobin
    # balance source
    server emq2 192.168.86.162:1883 check check inter 100000 fall 2 rise 5 weight 1
    server emq3 192.168.86.163:1883 check check inter 100000 fall 2 rise 5 weight 1
    server emq4 192.168.86.164:1883 check check inter 100000 fall 2 rise 5 weight 1
    # source 0.0.0.0 usesrc clientip

frontend emqtt-admin-front
    bind *:18083
    mode http
    default_backend emqtt-admin-backend

backend emqtt-admin-backend
    mode http
    balance roundrobin
    server emq2 192.168.86.162:18083 check
    server emq3 192.168.86.163:18083 check
    server emq4 192.168.86.164:18083 check
listen admin_stats
        stats   enable
        bind    *:8080 
        mode    http 
        option  httplog
        log     global
        maxconn 10
        stats   refresh 30s
        stats   uri /admin
        stats   realm haproxy
        stats   auth admin:admin
        stats   hide-version
        stats   admin if TRUE
#指定配置文件
haproxy -f /etc/haproxy/haproxy.cfg -c

#检查配置文件格式
haproxy -c -f /etc/haproxy/haproxy.cfg
#启动haproxy
haproxy -f /etc/haproxy/haproxy.cfg
#查看状态
service haproxy status

#添加开机自启动
cat <<eof>>/etc/rc.d/rc.local
haproxy -f /etc/haproxy/haproxy.cfg  
eof

vim /etc/sysctl.conf        #修改内核参数
net.ipv4.ip_nonlocal_bind = 1  #没有就新增此条记录
#访问高性能负载界面
192.168.86.161:8080/admin
#账户 admin 密码 admin
上一篇:Blazor 数据绑定开发指南


下一篇:CSS选择器