Centos 7 ChirpStack 开源RolaWan服务端搭建

ChirpStack介绍

ChirpStack开源LoRaWAN网络服务器堆栈为LoRaWAN网络提供了开源组件。它们共同构成了一个即用型解决方案,包括用于设备管理的用户友好型Web界面和用于集成的API。模块化体系结构使得可以在现有基础架构中进行集成。所有组件均已获得MIT许可,并可以用于商业目的。
下面是chirpstack的官网。
https://www.chirpstack.io/
ChirpStack服务端组件:

  • ChirpStack Gateway Bridge:网关网桥,处理与LoRaWAN网关的通信
  • ChirpStack Network Server:网络服务器,LoRaWAN网络服务器的实现
  • ChirpStack Application Server:应用服务器,LoRaWAN应用服务器的实现
  • ChirpStack Gateway OS:基于嵌入式Linux的操作系统,用于在LoRa网关上运行(完整)ChirpStack堆栈

ChirpStack部署方式

部署流程

服务器环境:CentOS Linux release 7.8.2003 (Core)
ChirpStack依赖Postgresql,mosquitto,redis软件,所以需要先安装这些软件。

1、Postgresql安装

PostgreSQL是一种特性非常齐全的自由软件的对象-关系型数据库管理系统(ORDBMS),是以加州大学计算机系开发的POSTGRES,4.2版本为基础的对象关系型数据库管理系统。POSTGRES的许多领先概念只是在比较迟的时候才出现在商业网站数据库中。PostgreSQL支持大部分的SQL标准并且提供了很多其他现代特性,如复杂查询、外键触发器视图、事务完整性、多版本并发控制等。同样,PostgreSQL也可以用许多方法扩展,例如通过增加新的数据类型、函数、操作符、聚集函数、索引方法、过程语言等。另外,因为许可证的灵活,任何人都可以以任何目的免费使用、修改和分发PostgreSQL。

  • 选择系统对应的版本
    https://www.postgresql.org/download/linux/redhat/
    image.png
  • 添加RPMyum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
  • 安装PostgreSQL 9.5yum install postgresql96-server postgresql96-contrib
  • 初始化数据库/usr/pgsql-9.6/bin/postgresql96-setup initdb
  • 开机自启动systemctl enable postgresql-9.6
  • 启动数据库systemctl start postgresql-9.6
    postgresql安装后会自动创建一个postgres用户
  • 创建数据库用户和数据库以供后续安装ChirpStack使用
#添加用户
sudo -u postgres psql 
#-- set up the users and the passwords
#-- (note that it is important to use single quotes and a semicolon at the end!)
create role chirpstack_as with login password 'dbpassword';
create role chirpstack_ns with login password 'dbpassword';
#-- create the database for the servers
create database chirpstack_as with owner chirpstack_as;
create database chirpstack_ns with owner chirpstack_ns;
#-- change to the ChirpStack Application Server database
\c chirpstack_as
#-- enable the pq_trgm and hstore extensions
#-- (this is needed to facilitate the search feature)
create extension pg_trgm;
#-- (this is needed to store additional k/v meta-data)
create extension hstore;
#-- exit psql
\q

2、mosquitto安装

mosquitto一款实现了消息推送协议 MQTT v3.1 的开源消息代理软件,提供轻量级的,支持可发布/可订阅的的消息推送模式,使设备对设备之间的短消息通信变得简单,比如现在应用广泛的低功耗传感器,手机、嵌入式计算机、微型控制器等移动设备。

  • 添加RPM:yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
  • 安装mosquitto:yum install mosquitto
  • 配置mosquitto:
#创建密码文件
touch /etc/mosquitto/pwfile
#创建策略文件
touch /etc/mosquitto/aclfile
#创建日志目录
mkdir /var/log/mosquitto
#创建日志文件
touch /var/log/mosquitto/mosquitto.log
#创建本地持久化文件目录
mkdir /var/lib/mosquitto
#创建chirp用户
mosquitto_passwd /etc/mosquitto/pwfile chirp
#输入chrip用户的密码

配置参数:vi /etc/mosquitto/mosquitto.conf

#持久化配置
persistence true
persistence_location /var/lib/mosquitto/
#日志文件配置
log_dest file /var/log/mosquitto/mosquitto.log
#用户名密码认证配置
allow_anonymous false
password_file /etc/mosquitto/pwfile
acl_file /etc/mosquitto/aclfile

配置用户策略:vi /etc/mosquitto/aclfile

user chirp  //用户chirp
topic chirpstack/#   //可对主题chirpstack读写

测试: mosquitto_sub -t chirpstack/# -u chirp -P 123456
日志查看:tail -f /var/log/mosquitto/mosquitto.log
-添加ChirpStack mqtt用户,设置密码。

mosquitto_passwd /etc/mosquitto/pwfile chirp_gateway
输入密码:
mosquitto_passwd /etc/mosquitto/pwfile chirp_network
输入密码:
mosquitto_passwd /etc/mosquitto/pwfile chrip_application
输入密码:

配置用户策略

[root@VM-0-15-centos ~]# cat /etc/mosquitto/aclfile
user chrip
topic chirpstack/#

user chirp_gateway
topic gateway/#

user chirp_network
topic gateway/#

user chrip_application
topic gateway/#

启动重启命令:
1、查看mosquitto的进程
ps -aux | grep mosquitto

2、杀掉进程
kill -9 18248

3.启动mosquitto
mosquitto -c /etc/mosquitto/mosquitto.conf -d

-参考
https://blog.csdn.net/qq_34301871/article/details/93617204

3、redis安装

image.jpeg

redis内网不能访问的问题:
1、检查端口是否通
2、取消redis bind 127.0.0.1
3、关闭保护模式 protected-mode no

4、chirpstack-gateway-bridge安装

yum install https://artifacts.chirpstack.io/downloads/chirpstack-gateway-bridge/chirpstack-gateway-bridge_3.10.0_linux_amd64.rpm

安装成功后出现以下提示:

---------------------------------------------------------------------------------
The configuration file is located at:
 /etc/chirpstack-gateway-bridge/chirpstack-gateway-bridge.toml
Some helpful commands for chirpstack-gateway-bridge:
Start:
 $ sudo systemctl start chirpstack-gateway-bridge
Restart:
 $ sudo systemctl restart chirpstack-gateway-bridge
Stop:
 $ sudo systemctl stop chirpstack-gateway-bridge
Display logs:
 $ sudo journalctl -f -n 100 -u chirpstack-gateway-bridge
---------------------------------------------------------------------------------

gateway-bridge配置:

marshaler="json"
# Generic MQTT authentication.
    [integration.mqtt.auth.generic]
    # MQTT server (e.g. scheme://host:port where scheme is tcp, ssl or ws)
    server="tcp://127.0.0.1:1883"

    # Connect with the given username (optional)
    username="chirp_gateway"

    # Connect with the given password (optional)
    password="123456"

配置后启动服务

5、chirpstack-network-server安装

yum install https://artifacts.chirpstack.io/downloads/chirpstack-network-server/chirpstack-network-server_3.10.0_linux_amd64.rpm

安装成功后出现以下提示:

---------------------------------------------------------------------------------
The configuration file is located at:
 /etc/chirpstack-network-server/chirpstack-network-server.toml
Some helpful commands for chirpstack-network-server:
Start:
 $ sudo systemctl start chirpstack-network-server
Restart:
 $ sudo systemctl restart chirpstack-network-server
Stop:
 $ sudo systemctl stop chirpstack-network-server
Display logs:
 $ sudo journalctl -f -n 100 -u chirpstack-network-server
---------------------------------------------------------------------------------

network-server配置:

# This configuration configures ChirpStack Network Server for the EU868 band using a MQTT
# broker to communicate with the gateways. Many options and defaults have been
# omitted for simplicity.
#
# For other bands, see the ./examples/ sub-directory.
#
# See https://www.chirpstack.io/network-server/install/config/ for a full
# configuration example and documentation.


# PostgreSQL settings.
#
# Please note that PostgreSQL 9.5+ is required.
[postgresql]
# PostgreSQL dsn (e.g.: postgres://user:password@hostname/database?sslmode=disable).

# Besides using an URL (e.g. 'postgres://user:password@hostname/database?sslmode=disable')
# it is also possible to use the following format:
# 'user=chirpstack_ns dbname=chirpstack_ns sslmode=disable'.
#
# The following connection parameters are supported:
#
# * dbname - The name of the database to connect to
# * user - The user to sign in as
# * password - The user's password
# * host - The host to connect to. Values that start with / are for unix domain sockets. (default is localhost)
# * port - The port to bind to. (default is 5432)
# * sslmode - Whether or not to use SSL (default is require, this is not the default for libpq)
# * fallback_application_name - An application_name to fall back to if one isn't provided.
# * connect_timeout - Maximum wait for connection, in seconds. Zero or not specified means wait indefinitely.
# * sslcert - Cert file location. The file must contain PEM encoded data.
# * sslkey - Key file location. The file must contain PEM encoded data.
# * sslrootcert - The location of the root certificate file. The file must contain PEM encoded data.
#
# Valid values for sslmode are:
#
# * disable - No SSL
# * require - Always SSL (skip verification)
# * verify-ca - Always SSL (verify that the certificate presented by the server was signed by a trusted CA)
# * verify-full - Always SSL (verify that the certification presented by the server was signed by a trusted CA and the server host name matches the one in the certificate)
#dsn="postgres://chirpstack_ns:dbpassword@localhost/chirpstack_ns?sslmode=disable"
dsn="postgres://chirpstack_ns:dbpassword@localhost/chirpstack_ns?sslmode=disable"

# Redis settings
#
# Please note that Redis 2.6.0+ is required.
[redis]
# Redis url (e.g. redis://user:password@hostname/0)
#
# For more information about the Redis URL format, see:
# https://www.iana.org/assignments/uri-schemes/prov/redis
url="redis://localhost:6379"


# Network-server settings.
[network_server]
# Network identifier (NetID, 3 bytes) encoded as HEX (e.g. 010203)
net_id="000000"


  # LoRaWAN regional band configuration.
  #
  # Note that you might want to consult the LoRaWAN Regional Parameters
  # specification for valid values that apply to your region.
  # See: https://www.lora-alliance.org/lorawan-for-developers
  [network_server.band]
  name="CN470"


  # LoRaWAN network related settings.
  [network_server.network_settings]

    # Extra channel configuration.
    #
    # Use this for LoRaWAN regions where it is possible to extend the by default
    # available channels with additional channels (e.g. the EU band).
    # The first 5 channels will be configured as part of the OTAA join-response
    # (using the CFList field).
    # The other channels (or channel / data-rate changes) will be (re)configured
    # using the NewChannelReq mac-command.
    #
    #[[network_server.network_settings.extra_channels]]
    #frequency=867100000
    #min_dr=0
    #max_dr=5

    #[[network_server.network_settings.extra_channels]]
    #frequency=867300000
    #min_dr=0
    #max_dr=5

    #[[network_server.network_settings.extra_channels]]
    #frequency=867500000
    #min_dr=0
    #max_dr=5

    #[[network_server.network_settings.extra_channels]]
    #frequency=867700000
    #min_dr=0
    #max_dr=5

    #[[network_server.network_settings.extra_channels]]
    #frequency=867900000
    #min_dr=0
    #max_dr=5


    # Class B settings
    [network_server.network_settings.class_b]
    # Ping-slot data-rate.
    ping_slot_dr=0

    # Ping-slot frequency (Hz)
    #
    # Set this to 0 to use the default frequency plan for the configured region
    # (which could be frequency hopping).
    ping_slot_frequency=0


  # Network-server API
  #
  # This is the network-server API that is used by ChirpStack Application Server or other
  # custom components interacting with ChirpStack Network Server.
  [network_server.api]
  # ip:port to bind the api server
  bind="0.0.0.0:8000"


  # Backend defines the gateway backend settings.
  #
  # The gateway backend handles the communication with the gateway(s) part of
  # the LoRaWAN network.
  [network_server.gateway.backend]
  # Backend
  type="mqtt"


    # MQTT gateway backend settings.
    #
    # This is the backend communicating with the LoRa gateways over a MQTT broker.
    [network_server.gateway.backend.mqtt]
    # MQTT topic templates for the different MQTT topics.
    #
    # The meaning of these topics are documented at:
    # https://www.chirpstack.io/gateway-bridge/
    #
    # The default values match the default expected configuration of the
    # ChirpStack Gateway Bridge MQTT backend. Therefore only change these values when
    # absolutely needed.

    # Event topic template.
    event_topic="gateway/+/event/+"

    # Command topic template.
    #
    # Use:
    #   * "{{ .GatewayID }}" as an substitution for the LoRa gateway ID
    #   * "{{ .CommandType }}" as an substitution for the command type
    command_topic_template="gateway/{{ .GatewayID }}/command/{{ .CommandType }}"

    # MQTT server (e.g. scheme://host:port where scheme is tcp, ssl or ws)
    server="tcp://localhost:1883"

    # Connect with the given username (optional)
    username="chirp_network"

    # Connect with the given password (optional)
    password="123456"


# Metrics collection settings.
[metrics]
# Timezone
#
# The timezone is used for correctly aggregating the metrics (e.g. per hour,
# day or month).
# Example: "Europe/Amsterdam" or "Local" for the the system's local time zone.
timezone="Local"


# Join-server settings.
[join_server]

  # Default join-server settings.
  #
  # This join-server will be used when resolving the JoinEUI is set to false
  # or as a fallback when resolving the JoinEUI fails.
  [join_server.default]
  # hostname:port of the default join-server
  #
  # This API is provided by ChirpStack Application Server.
  server="http://localhost:8003"

6、chirpstack-application-server安装

https://artifacts.chirpstack.io/downloads/chirpstack-application-server/chirpstack-application-server_3.10.0_linux_amd64.rpm

安装成功后出现以下提示:

---------------------------------------------------------------------------------
The configuration file is located at:
 /etc/chirpstack-application-server/chirpstack-application-server.toml
Some helpful commands for chirpstack-application-server:
Start:
 $ sudo systemctl start chirpstack-application-server
Restart:
 $ sudo systemctl restart chirpstack-application-server
Stop:
 $ sudo systemctl stop chirpstack-application-server
Display logs:
 $ sudo journalctl -f -n 100 -u chirpstack-application-server
---------------------------------------------------------------------------------

application-server配置:

# This configuration sets the required settings and configures an integration
# with a MQTT broker. Many options and defaults have been omitted for
# simplicity.
#
# See https://www.chirpstack.io/application-server/install/config/ for a full
# configuration example and documentation.


# PostgreSQL settings.
#
# Please note that PostgreSQL 9.5+ is required.
[postgresql]
# PostgreSQL dsn (e.g.: postgres://user:password@hostname/database?sslmode=disable).
#
# Besides using an URL (e.g. 'postgres://user:password@hostname/database?sslmode=disable')
# it is also possible to use the following format:
# 'user=chirpstack_as dbname=chirpstack_as sslmode=disable'.
#
# The following connection parameters are supported:
#
# * dbname - The name of the database to connect to
# * user - The user to sign in as
# * password - The user's password
# * host - The host to connect to. Values that start with / are for unix domain sockets. (default is localhost)
# * port - The port to bind to. (default is 5432)
# * sslmode - Whether or not to use SSL (default is require, this is not the default for libpq)
# * fallback_application_name - An application_name to fall back to if one isn't provided.
# * connect_timeout - Maximum wait for connection, in seconds. Zero or not specified means wait indefinitely.
# * sslcert - Cert file location. The file must contain PEM encoded data.
# * sslkey - Key file location. The file must contain PEM encoded data.
# * sslrootcert - The location of the root certificate file. The file must contain PEM encoded data.
#
# Valid values for sslmode are:
#
# * disable - No SSL
# * require - Always SSL (skip verification)
# * verify-ca - Always SSL (verify that the certificate presented by the server was signed by a trusted CA)
# * verify-full - Always SSL (verify that the certification presented by the server was signed by a trusted CA and the server host name matches the one in the certificate)
dsn="postgres://chirpstack_as:dbpassword@localhost/chirpstack_as?sslmode=disable"

# Redis settings
#
# Please note that Redis 2.6.0+ is required.
[redis]
# Redis url (e.g. redis://user:password@hostname/0)
#
# For more information about the Redis URL format, see:
# https://www.iana.org/assignments/uri-schemes/prov/redis
url="redis://localhost:6379"


# Application-server settings.
[application_server]

  # Integration configures the data integration.
  #
  # This is the data integration which is available for all applications,
  # besides the extra integrations that can be added on a per-application
  # basis.
  [application_server.integration]
  # Enabled integrations.
  enabled=["mqtt"]

    # MQTT integration backend.
    [application_server.integration.mqtt]
    # MQTT topic templates for the different MQTT topics.
    #
    # The meaning of these topics are documented at:
    # https://www.chirpstack.io/application-server/integrate/data/
    #
    # The following substitutions can be used:
    # * "{{ .ApplicationID }}" for the application id.
    # * "{{ .DevEUI }}" for the DevEUI of the device.
    #
    # Note: the downlink_topic_template must contain both the application id and
    # DevEUI substitution!
    uplink_topic_template="application/{{ .ApplicationID }}/device/{{ .DevEUI }}/rx"
    downlink_topic_template="application/{{ .ApplicationID }}/device/{{ .DevEUI }}/tx"
    join_topic_template="application/{{ .ApplicationID }}/device/{{ .DevEUI }}/join"
    ack_topic_template="application/{{ .ApplicationID }}/device/{{ .DevEUI }}/ack"
    error_topic_template="application/{{ .ApplicationID }}/device/{{ .DevEUI }}/error"
    status_topic_template="application/{{ .ApplicationID }}/device/{{ .DevEUI }}/status"
    location_topic_template="application/{{ .ApplicationID }}/device/{{ .DevEUI }}/location"

    # MQTT server (e.g. scheme://host:port where scheme is tcp, ssl or ws)
    server="tcp://localhost:1883"

    # Connect with the given username (optional)
    username="chrip_application"

    # Connect with the given password (optional)
    password="123456"


    # Settings for the "internal api"
    #
    # This is the API used by ChirpStack Network Server to communicate with ChirpStack Application Server
    # and should not be exposed to the end-user.
    [application_server.api]
    # ip:port to bind the api server
    bind="0.0.0.0:8001"

    # Public ip:port of the application-server API.
    #
    # This is used by ChirpStack Network Server to connect to ChirpStack Application Server. When running
    # ChirpStack Application Server on a different host than ChirpStack Network Server, make sure to set
    # this to the host:ip on which ChirpStack Network Server can reach ChirpStack Application Server.
    # The port must be equal to the port configured by the 'bind' flag
    # above.
    public_host="localhost:8001"


    # Settings for the "external api"
    #
    # The API and web-interface exposed to the end-user.
    [application_server.external_api]
    # ip:port to bind the (user facing) http server to (web-interface and REST / gRPC api)
    bind="0.0.0.0:8080"

    # http server TLS certificate (optional)
    tls_cert=""

    # http server TLS key (optional)
    tls_key=""

    # JWT secret used for api authentication / authorization
    # You could generate this by executing 'openssl rand -base64 32' for example
    jwt_secret="vTF5M9E2Ymz7sg+rl78OeFz7UymnhWVdh36YiVvnowo="


# Join-server configuration.
#
# ChirpStack Application Server implements a (subset) of the join-api specified by the
# LoRaWAN Backend Interfaces specification. This API is used by ChirpStack Network Server
# to handle join-requests.
[join_server]
# ip:port to bind the join-server api interface to
bind="0.0.0.0:8003"

7、登陆

image.png

8、参考文档

https://www.cnblogs.com/liujiabing/p/13692308.html
https://www.it610.com/article/1295693840237273088.htm
https://blog.csdn.net/weixin_46027505/article/details/107270912

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 219,366评论 6 508
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 93,521评论 3 395
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 165,689评论 0 356
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,925评论 1 295
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 67,942评论 6 392
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,727评论 1 305
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,447评论 3 420
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 39,349评论 0 276
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,820评论 1 317
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,990评论 3 337
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 40,127评论 1 351
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,812评论 5 346
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,471评论 3 331
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 32,017评论 0 22
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 33,142评论 1 272
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 48,388评论 3 373
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 45,066评论 2 355

推荐阅读更多精彩内容