EMQX中如何访问RestAPI

阅读更多
1、查看restapi端口

# netstat -tnulp|grep 19656
tcp        0      0 0.0.0.0:6369                0.0.0.0:*                   LISTEN      19656/beam.smp     
tcp        0      0 0.0.0.0:18083               0.0.0.0:*                   LISTEN      19656/beam.smp     
tcp        0      0 127.0.0.1:11883             0.0.0.0:*                   LISTEN      19656/beam.smp     
tcp        0      0 0.0.0.0:8883                0.0.0.0:*                   LISTEN      19656/beam.smp     
tcp        0      0 0.0.0.0:9080                0.0.0.0:*                   LISTEN      19656/beam.smp     
tcp        0      0 0.0.0.0:5369                0.0.0.0:*                   LISTEN      19656/beam.smp     
tcp        0      0 0.0.0.0:1883                0.0.0.0:*                   LISTEN      19656/beam.smp 

2、创建访问RestAPI的认证应用ID

[1/3] # ./emqx_ctl mgmt  insert
# ./emqx_ctl mgmt insert b28477fa9f9798 Client@Yours
AppSecret: Mjg3ODQxNjgyNTc2Mjg1NDUzNzA3ODczNDM3MDc1Mzc0MDI
[2/3] # ./emqx_ctl mgmt list
app_id: b28477fa9f9798, secret: Mjg3ODQxNjgyNTc2Mjg1NDUzNzA3ODczNDM3MDc1Mzc0MDI, name: Client@Yours, desc: Application user, status: true, expired: undefined
[3/3] curl -v --basic -u : -k http://:8080/api/v3/brokers
=> :,可以通过CLI或者Dashboard进行创建

3、通过认证应用ID和秘钥进行访问

# curl -v --basic -u b28477fa9f9798:Mjg3ODQxNjgyNTc2Mjg1NDUzNzA3ODczNDM3MDc1Mzc0MDI -k http://192.168.1.148:9080/api/v3/brokers/
* About to connect() to 192.168.1.148 port 9080 (#0)
*   Trying 192.168.1.148... connected
* Connected to 192.168.1.148 (192.168.1.148) port 9080 (#0)
* Server auth using Basic with user 'b28477fa9f9798'
> GET /api/v3/brokers/ HTTP/1.1
> Authorization: Basic YjI4NDc3ZmE5Zjk3OTg6TWpnM09EUXhOamd5TlRjMk1qZzFORFV6TnpBM09EY3pORE0zTURjMU16YzBNREk=
> User-Agent: curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.27.1 zlib/1.2.3 libidn/1.18 libssh2/1.4.2
> Host: 192.168.1.148:9080
> Accept: */*
>
< HTTP/1.1 200 OK
< content-length: 423
< content-type: application/json
< date: Thu, 13 Jun 2019 02:34:09 GMT
< server: Cowboy
<
* Connection #0 to host 192.168.1.148 left intact
* Closing connection #
=>result as the following:
{
  "code": 0,
  "data": [
    {
      "datetime": "2019-06-13 10:33:13",
      "node": "[email protected]",
      "node_status": "Running",
      "otp_release": "R21/10.3.2",
      "sysdescr": "EMQ X Broker",
      "uptime": "17 hours, 20 minutes, 54 seconds",
      "version": "v3.1.0"
    },
    {
      "datetime": "2019-06-13 10:33:13",
      "node": "[email protected]",
      "node_status": "Running",
      "otp_release": "R21/10.3.2",
      "sysdescr": "EMQ X Broker",
      "uptime": "17 hours, 21 minutes, 28 seconds",
      "version": "v3.1.0"
    }
  ]
}

你可能感兴趣的:(emqx,restapi,base-auth,app_id,secret)