编译之后,这篇笔记介绍如何进行必要的配置,并让几个组件运行起来,包含实践过程一些小问题的解决记录。
小能手最近在学习 ChirpStack 项目,应该是最有影响力的 LoRaWAN 服务器开源项目。它组件丰富,代码可读性强,是个很好的学习资料。更多学习笔记,可点此查看。
生成默认配置文件,我比较喜欢放在当前工程目录。目前没使用 basic station 的话,倒是没什么好改的。
# ./build/lora-gateway-bridge configfile > lora-gateway-bridge.toml
# vim lora-gateway-bridge.toml
./build/lora-gateway-bridge
INFO[0000] starting LoRa Gateway Bridge docs="https://www.loraserver.io/lora-gateway-bridge/" version=3.0.0-test.3
INFO[0000] backend/semtechudp: starting gateway udp listener addr="0.0.0.0:1700"
ERRO[0000] integration/mqtt: connection error error="Network Error : dial tcp 127.0.0.1:1883: connect: connection refused"
修改 mosquitto 的配置文件,启用默认监听端口1883。然后启动服务。
# vim /etc/mosquitto/mosquitto.conf
# systemctl start mosquitto
# ./build/lora-gateway-bridge
INFO[0000] starting LoRa Gateway Bridge docs="https://www.loraserver.io/lora-gateway-bridge/" version=3.0.0-test.3
INFO[0000] backend/semtechudp: starting gateway udp listener addr="0.0.0.0:1700"INFO[0000] integration/mqtt: connected to mqtt broker
# psql -h localhost -U loraserver_ns -W loraserver_ns Password for user loraserver_ns:
psql: FATAL: Ident authentication failed for user "loraserver_ns"
明明按照教程一步步设置了密码,怎么就不行了呢?
By default PostgreSQL uses IDENT-based authentication and this will never allow you to login via -U and -W options. Allow username and password based authentication from your application by appling ‘trust’ as the authentication method for the JIRA database user. You can do this by modifying the pg_hba.conf file.
原来默认情况下,不能使用 -U -W 选项进行登录。为此,我们需要将 pg_hba.conf 中的认证方法调整为 ‘trust’。
# find / -name pg_hba.conf/var/lib/docker/volumes/loraserver-docker_postgresqldata/_data/pg_hba.conf
/var/lib/pgsql/11/data/pg_hba.conf
# vim /var/lib/docker/volumes/loraserver-docker_postgresqldata/_d
ata/pg_hba.conf
参考下 loraserver-docker 的配置:
# "local" is for Unix domain socket connections only
local all all trust
# IPv4 local connections:
host all all 127.0.0.1/32 trust
# IPv6 local connections:
host all all ::1/128 trust
# Allow replication connections from localhost, by a user with the
# replication privilege.
#local replication postgres trust
#host replication postgres 127.0.0.1/32 trust
#host replication postgres ::1/128 trust
host all all all trust
# vim /var/lib/pgsql/11/data/pg_hba.conf
# systemctl restart postgresql-11
# psql -h localhost -U loraserver_ns -W loraserver_ns
Password for user loraserver_ns:
psql (9.2.24, server 11.2)
WARNING: psql version 9.2, server version 11.0.
Some psql features might not work.
Type "help" for help.
loraserver_ns=>
生成默认配置文件,我比较喜欢放在当前工程目录。然后修改之。
# ./build/loraserver configfile > loraserver.toml
# vim loraserver.toml
改两处地方,我的 postgres 是对照官方的初始配置来的:
[postgresql]
dsn="postgres://loraserver_ns:dbpassword@localhost/loraserver_ns?sslmode=disable"
[network_server.band]
name="CN_470_510"
如果提示这个,说明 MQTT broker 还没起来。参照 1.2 的方式,处理一下。
# ./build/loraserver
INFO[0000] starting LoRa Server band=CN_470_510 docs="https:/www.loraserver.io/" net_id=000000 version=3.0.0-test.2-2-g124ff9b
INFO[0000] storage: setting up storage module
INFO[0000] storage: setting up Redis connection pool
INFO[0000] storage: connecting to PostgreSQL
INFO[0000] storage: applying PostgreSQL data migrations
INFO[0001] storage: PostgreSQL data migrations applied count=21
INFO[0001] gateway/mqtt: connecting to mqtt broker server="tcp://localhost:1883"
顺利的话,是这样:
# ./build/loraserver
INFO[0000] starting LoRa Server band=CN_470_510 docs="https:/www.loraserver.io/" net_id=000000 version=3.0.0-test.2-2-g124ff9b
INFO[0000] storage: setting up storage module
INFO[0000] storage: setting up Redis connection pool
INFO[0000] storage: connecting to PostgreSQL
INFO[0000] storage: applying PostgreSQL data migrations
INFO[0000] storage: PostgreSQL data migrations applied count=0
INFO[0000] gateway/mqtt: connecting to mqtt broker server="tcp://localhost:1883"
INFO[0000] no geolocation-server configured
INFO[0000] configuring join-server client ca_cert= server="http://localhost:8003" tls_cert= tls_key=
INFO[0000] backend/gateway: connected to mqtt server
INFO[0000] gateway/mqtt: subscribing to gateway event topic qos=0 topic=gateway/+/event/+
INFO[0000] service-profile and device-profile redis cache flushed
INFO[0000] migrating gateway stats
INFO[0000] gateway stats migrated
INFO[0000] starting api server bind="0.0.0.0:8000" ca-cert= tls-cert= tls-key=
INFO[0000] starting downlink device-queue scheduler
INFO[0000] starting multicast scheduler
可以参考笔记Redis 学习笔记 2.2.1 Redis配置成系统服务(CentOS7)
生成默认配置文件,然后修改之。
# ./build/lora-app-server configfile > lora-app-server.toml
# vim lora-app-server.toml
改两处地方,第一处是 postgres,是对照官方的初始配置来的:
[postgresql]
dsn="postgres://loraserver_as:dbpassword@localhost/loraserver_as?sslmode=disable"
第二处是 jwt_secret,使用 openssl rand -base64 32 命令来生成一个随机数:
# openssl rand -base64 32
Jlc1V0SmAWcwkyNOUnJQtHeQILieIGkc47AQ+U2yWLY=
# vim lora-app-server.toml
# JWT secret used for api authentication / authorization
# You could generate this by executing 'openssl rand -base64 32' for example
jwt_secret="Jlc1V0SmAWcwkyNOUnJQtHeQILieIGkc47AQ+U2yWLY="
# ./build/lora-app-server
INFO[0000] starting LoRa App Server docs="https://www.loraserver.io/" version=3.0.0-test.4-4-g4017505
INFO[0000] storage: setting up storage package
INFO[0000] storage: setting up Redis pool
INFO[0000] storage: connecting to PostgreSQL database
INFO[0000] storage: applying PostgreSQL data migrations
INFO[0000] storage: PostgreSQL data migrations applied count=0
INFO[0000] integration/mqtt: TLS config is empty
INFO[0000] integration/mqtt: connecting to mqtt broker server="tcp://localhost:1883"
INFO[0000] api/as: starting application-server api bind="0.0.0.0:8001" ca_cert= tls_cert= tls_key=
INFO[0000] integration/mqtt: connected to mqtt broker
INFO[0000] integration/mqtt: subscribing to tx topic qos=0 topic=application/+/device/+/tx
INFO[0000] api/external: starting api server bind="0.0.0.0:8080" tls-cert= tls-key=
INFO[0000] api/external: registering rest api handler and documentation endpoint path=/api
INFO[0000] api/js: starting join-server api bind="0.0.0.0:8003" ca_cert= tls_cert= tls_key=
使用浏览器访问 :8080 端口,即可看到 AS 的 UI 界面。
由于最新的 backend 规范中,AS 可以关联多个 NS,因此在 AS 界面中需要先配置NS,这里填入本机NS即可。
至此,三个组件都已配置启动。