2.8.1 ChirpStack ChirpStack study notes typical problem a container connected to the machine processing container InfluxDB

Foreword

In 2.8 application integration InfluxDB have a recording problem can not connect influxdb a container of notes, make a note of this in-depth analysis.

Small expert recent study ChirpStack project, should be the most influential LoRaWAN server open source projects. It is rich components, code readability strong, is a good learning materials. More study notes, you can click here to view .

Description of the problem

appserver_1      | time="2020-02-07T10:24:34Z" level=error msg="integration/multi: integration *influxdb.Integration error" error="sending measurements error: http request error: Post http://localhost:8086/write?db=db0&precision=ms&rp=: dial tcp 127.0.0.1:8086: connect: connection refused"

My host has been running ChirpStack container, again depending on the application required to open a InfluxDB container, when configured localhost in chirpstack page: When the connection address InfluxDB 8086, suggesting connection refused.

2 Analysis

docker is a virtual environment, 127.0.0.1 and localhost refers to the internal virtual environment, rather than an external host, it is not so accessible.

2.1 container network analysis

# docker network ls
NETWORK ID          NAME                        DRIVER              SCOPE
02231307198a        bridge                      bridge              local
81b1d878dd80        host                        host                local
5284403f2094        lora-app-server_default     bridge              local
8de8416ca11a        lora_default                bridge              local
d4389dfb8f38        loraserver-docker_default   bridge              local
49d4a4343b5e        lorawan-stack-dev_default   bridge              local
194a422ad895        none                        null                local

lora-app-server_default

# docker network inspect lora-app-server_default
[
    {
        "Name": "lora-app-server_default",
        "Id": "5284403f20943bcca33e6fb7482aa1c5e714bbf05a66c5712500f35c901f1a5d",
        "Created": "2019-10-29T12:37:30.514317558+08:00",
        "Scope": "local",
        "Driver": "bridge",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": null,
            "Config": [
                {
                    "Subnet": "192.168.16.0/20",
                    "Gateway": "192.168.16.1"
                }
            ]
        },
        "Internal": false,
        "Attachable": false,
        "Ingress": false,
        "ConfigFrom": {
            "Network": ""
        },
        "ConfigOnly": false,
        "Containers": {
            "46e4075d8376bd54b2d59d330a2f9924a0dff32e080f53b26200ce7845a6f65c": {
                "Name": "lora-app-server_mosquitto_1",
                "EndpointID": "5677bc3efacb3454d2e70d490e8c6d2bc75469080d985645ceda500940311944",
                "MacAddress": "02:42:c0:a8:10:04",
                "IPv4Address": "192.168.16.4/20",
                "IPv6Address": ""
            },
            "92ee8b9f02e044c77765e723717788d67ea7434b222191e3bd9a019dc31fd17e": {
                "Name": "lora-app-server_postgres_1",
                "EndpointID": "0c032e0946d397ee09f14deac9cf0039c3a5bba99e8a88fcfe942a7661e322d8",
                "MacAddress": "02:42:c0:a8:10:02",
                "IPv4Address": "192.168.16.2/20",
                "IPv6Address": ""
            },
            "e4201031eb7e4d4a34a165f38b8871de1e6527c16cc1cf9021993d6ec0793b11": {
                "Name": "lora-app-server_redis_1",
                "EndpointID": "c0b595b4f7a7fa3848aa57c9b65b77158ee16ed0ed8a744e580f68f0dac5878f",
                "MacAddress": "02:42:c0:a8:10:03",
                "IPv4Address": "192.168.16.3/20",
                "IPv6Address": ""
            }
        },
        "Options": {},
        "Labels": {}
    }
]

loraserver-docker_default

# docker network inspect loraserver-docker_default
[
    {
        "Name": "loraserver-docker_default",
        "Id": "d4389dfb8f38d6a023de63ca25d74c65a5b4b114fbb83a1b43263e376000a22b",
        "Created": "2020-02-05T14:23:44.985567025+08:00",
        "Scope": "local",
        "Driver": "bridge",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": null,
            "Config": [
                {
                    "Subnet": "192.168.64.0/20",
                    "Gateway": "192.168.64.1"
                }
            ]
        },
        "Internal": false,
        "Attachable": true,
        "Ingress": false,
        "ConfigFrom": {
            "Network": ""
        },
        "ConfigOnly": false,
        "Containers": {
            "0329aa3dbabb76ab7d94cd19ff0ff89a8c48cc45d710b8060800a177dc2dd214": {
                "Name": "loraserver-docker_appserver_1",
                "EndpointID": "1080f620260de45592ac7c824f2e7a2f68846de5764e2734cd2f0745718c326a",
                "MacAddress": "02:42:c0:a8:40:07",
                "IPv4Address": "192.168.64.7/20",
                "IPv6Address": ""
            },
            "0d8afb7896f6d5ad7516c8079b2b38f6c88f2beac13ccb887273f62cd2d10538": {
                "Name": "loraserver-docker_geoserver_1",
                "EndpointID": "4775a6fb238a594972d8fbac20175537dc4fd83572051283484522777f42ecc5",
                "MacAddress": "02:42:c0:a8:40:04",
                "IPv4Address": "192.168.64.4/20",
                "IPv6Address": ""
            },
            "4bb2a05b99aa24a524137bbc4df3bd7e19bc8e45edd558c3bfda1d0530fc5c0b": {
                "Name": "loraserver-docker_postgresql_1",
                "EndpointID": "8e5e035a17bca1b957dc9c2d00ef385118407ad04bff87da3ca2009bfe7eeee5",
                "MacAddress": "02:42:c0:a8:40:06",
                "IPv4Address": "192.168.64.6/20",
                "IPv6Address": ""
            },
            "5e5813773f6dbc0af8136e234df9f6fd9658488fcafdf57dfdafd57cb9198c76": {
                "Name": "loraserver-docker_gatewaybridge_1",
                "EndpointID": "9e1956f9ed7f5cd4ca1009788a811ec243428ca4b0787b621f402b06c827375b",
                "MacAddress": "02:42:c0:a8:40:08",
                "IPv4Address": "192.168.64.8/20",
                "IPv6Address": ""
            },
            "9b8a1f733e2b3e995eaac5fcdd759ea7f4926943e511f3754c66293e7910ce6e": {
                "Name": "loraserver-docker_loraserver_1",
                "EndpointID": "ffc5869e673c591776f07d7fc5ab95ab017c9773dd11aa403010c69551b373a0",
                "MacAddress": "02:42:c0:a8:40:05",
                "IPv4Address": "192.168.64.5/20",
                "IPv6Address": ""
            },
            "c984f4f533bd904469a6afe70224baade7fffa550b345580bfe911e38235581e": {
                "Name": "loraserver-docker_redis_1",
                "EndpointID": "d7ebab7f77eac0beb71f207b94c7432ab04092c2c5442eeeaa1d87c7783085a1",
                "MacAddress": "02:42:c0:a8:40:02",
                "IPv4Address": "192.168.64.2/20",
                "IPv6Address": ""
            },
            "cc5400f93f5454ee5033f37a8b8bd584a292429baaa7c9fd16e788bd34200407": {
                "Name": "loraserver-docker_mosquitto_1",
                "EndpointID": "d47e177c7785d3a0f9c0e70e707bfdfb7cbb056f1b785bfc136a503559d7d929",
                "MacAddress": "02:42:c0:a8:40:03",
                "IPv4Address": "192.168.64.3/20",
                "IPv6Address": ""
            }
        },
        "Options": {},
        "Labels": {
            "com.docker.compose.network": "default",
            "com.docker.compose.project": "loraserver-docker",
            "com.docker.compose.version": "1.24.1"
        }
    }
]

2.2 combing container network

bridge 172.17.0.1

  • influxdb 172.17.0.2

lora-app-server_default 192.168.16.1

  • lora-app-server_mosquitto_1
  • lora-app-server_postgres_1
  • lora-app-server_redis_1

loraserver-docker_default 192.168.64.1

  • loraserver-docker_appserver_1
  • loraserver-docker_gatewaybridge_1
  • loraserver-docker_loraserver_1
  • loraserver-docker_geoserver_1
  • loraserver-docker_postgresql_1
  • loraserver-docker_mosquitto_1
  • loraserver-docker_redis_1

In summary, loraserver-docker_appserver_1 influxdb and not in the same network can not communicate.

You can view specific reasons Docker official web tutorial practice custom bridge network .

3 treatment options

Scheme 1 is the host bridge ip ip

influxdb expose the external container has a port 8086, so that the container can be located directly through the host IP and port exposure.

IP is the IP host bridge, i.e. Docker0 IP address, refer to:
https://nickjanetakis.com/blog/docker-tip-65-get-your-docker-hosts-ip-address-from-in-a -container

# ip a
3: docker0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP 
    link/ether 02:42:5f:e8:7c:be brd ff:ff:ff:ff:ff:ff
    inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0
       valid_lft forever preferred_lft forever

Therefore, we can locate the influxdb container through 172.17.0.1:8086. We can configure InfluxDB integration API endpoint in chirpstack webui in:

http://172.17.0.1:8086/write

Scheme 2 will be connected to the same network influxdb container

# docker network connect loraserver-docker_default influxdb
# docker network inspect loraserver-docker_default 
[
    {
        "Name": "loraserver-docker_default",
        "Id": "d4389dfb8f38d6a023de63ca25d74c65a5b4b114fbb83a1b43263e376000a22b",
        "Created": "2020-02-05T14:23:44.985567025+08:00",
        "Scope": "local",
        "Driver": "bridge",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": null,
            "Config": [
                {
                    "Subnet": "192.168.64.0/20",
                    "Gateway": "192.168.64.1"
                }
            ]
        },
        "Internal": false,
        "Attachable": true,
        "Ingress": false,
        "ConfigFrom": {
            "Network": ""
        },
        "ConfigOnly": false,
        "Containers": {
            "0329aa3dbabb76ab7d94cd19ff0ff89a8c48cc45d710b8060800a177dc2dd214": {
                "Name": "loraserver-docker_appserver_1",
                "EndpointID": "1080f620260de45592ac7c824f2e7a2f68846de5764e2734cd2f0745718c326a",
                "MacAddress": "02:42:c0:a8:40:07",
                "IPv4Address": "192.168.64.7/20",
                "IPv6Address": ""
            },
            "0d8afb7896f6d5ad7516c8079b2b38f6c88f2beac13ccb887273f62cd2d10538": {
                "Name": "loraserver-docker_geoserver_1",
                "EndpointID": "4775a6fb238a594972d8fbac20175537dc4fd83572051283484522777f42ecc5",
                "MacAddress": "02:42:c0:a8:40:04",
                "IPv4Address": "192.168.64.4/20",
                "IPv6Address": ""
            },
            "4bb2a05b99aa24a524137bbc4df3bd7e19bc8e45edd558c3bfda1d0530fc5c0b": {
                "Name": "loraserver-docker_postgresql_1",
                "EndpointID": "8e5e035a17bca1b957dc9c2d00ef385118407ad04bff87da3ca2009bfe7eeee5",
                "MacAddress": "02:42:c0:a8:40:06",
                "IPv4Address": "192.168.64.6/20",
                "IPv6Address": ""
            },
            "5e5813773f6dbc0af8136e234df9f6fd9658488fcafdf57dfdafd57cb9198c76": {
                "Name": "loraserver-docker_gatewaybridge_1",
                "EndpointID": "9e1956f9ed7f5cd4ca1009788a811ec243428ca4b0787b621f402b06c827375b",
                "MacAddress": "02:42:c0:a8:40:08",
                "IPv4Address": "192.168.64.8/20",
                "IPv6Address": ""
            },
            "98b72943ab195564fb1a8465243bff96cbc7dc989a3a16dab5269afc835336f5": {
                "Name": "influxdb",
                "EndpointID": "b89b8104bcf27a29bc3a7b470206a4669e5513b37d09e888ab970425299a807c",
                "MacAddress": "02:42:c0:a8:40:09",
                "IPv4Address": "192.168.64.9/20",
                "IPv6Address": ""
            },
            "9b8a1f733e2b3e995eaac5fcdd759ea7f4926943e511f3754c66293e7910ce6e": {
                "Name": "loraserver-docker_loraserver_1",
                "EndpointID": "ffc5869e673c591776f07d7fc5ab95ab017c9773dd11aa403010c69551b373a0",
                "MacAddress": "02:42:c0:a8:40:05",
                "IPv4Address": "192.168.64.5/20",
                "IPv6Address": ""
            },
            "c984f4f533bd904469a6afe70224baade7fffa550b345580bfe911e38235581e": {
                "Name": "loraserver-docker_redis_1",
                "EndpointID": "d7ebab7f77eac0beb71f207b94c7432ab04092c2c5442eeeaa1d87c7783085a1",
                "MacAddress": "02:42:c0:a8:40:02",
                "IPv4Address": "192.168.64.2/20",
                "IPv6Address": ""
            },
            "cc5400f93f5454ee5033f37a8b8bd584a292429baaa7c9fd16e788bd34200407": {
                "Name": "loraserver-docker_mosquitto_1",
                "EndpointID": "d47e177c7785d3a0f9c0e70e707bfdfb7cbb056f1b785bfc136a503559d7d929",
                "MacAddress": "02:42:c0:a8:40:03",
                "IPv4Address": "192.168.64.3/20",
                "IPv6Address": ""
            }
        },
        "Options": {},
        "Labels": {
            "com.docker.compose.network": "default",
            "com.docker.compose.project": "loraserver-docker",
            "com.docker.compose.version": "1.24.1"
        }
    }
]

In this way, we can influxdb direct access to the container by container name, it can also be accessed through the container ip 192.168.64.9.

So we can configure InfluxDB integration API endpoint in chirpstack webui in:

http://influxdb:8086/write

or:

http://192.168.64.9:8086/write

4 Summary

One typical problem of this section chirpstack app_server note from the container can not be connected by an external influxdb localhost, analyzes the network chirpstack vessel involved, the problem for a given host bridge ip ip ie, the container can also access the same influxdb vessel networks are two solutions.

END


Published 241 original articles · won praise 229 · views 800 000 +

Guess you like

Origin blog.csdn.net/iotisan/article/details/104241987