下载源码
go get -u github.com/brocaar/lora-app-server
升级 npm
npm是nodejs 的包管理工具, lora-app-server有些网页是js写的,所以需要
下面这行命令 在我电脑的emacs eshell 下运行不行,那就在 terminal 下执行吧
sudo npm i -g npm
安装一些必要的依赖库
npm install -g create-react-app
lora-app-server的依赖库,参考之前的几篇文章,这里就不细讲了。
反正编译的时候缺啥,就 go get 下啥
我make build 后,提示缺了下面这些
api/common.pb.go:9:8: cannot find package "github.com/brocaar/loraserver/api/common" in any of:
/home/wjs/go/src/github.com/brocaar/loraserver/api/common (from $GOROOT)
/home/wjs/go/gopath/src/github.com/brocaar/loraserver/api/common (from $GOPATH)
internal/storage/user.go:14:2: cannot find package "github.com/dgrijalva/jwt-go" in any of:
/home/wjs/go/src/github.com/dgrijalva/jwt-go (from $GOROOT)
/home/wjs/go/gopath/src/github.com/dgrijalva/jwt-go (from $GOPATH)
cmd/lora-app-server/cmd/root_run.go:18:2: cannot find package "github.com/gorilla/mux" in any of:
/home/wjs/go/src/github.com/gorilla/mux (from $GOROOT)
/home/wjs/go/gopath/src/github.com/gorilla/mux (from $GOPATH)
internal/handler/influxdbhandler/influxdb_handler.go:16:2: cannot find package "github.com/mmcloughlin/geohash" in any of:
/home/wjs/go/src/github.com/mmcloughlin/geohash (from $GOROOT)
/home/wjs/go/gopath/src/github.com/mmcloughlin/geohash (from $GOPATH)
internal/codec/custom_js.go:11:2: cannot find package "github.com/robertkrimen/otto" in any of:
/home/wjs/go/src/github.com/robertkrimen/otto (from $GOROOT)
/home/wjs/go/gopath/src/github.com/robertkrimen/otto (from $GOPATH)
cmd/lora-app-server/cmd/root_run.go:27:2: cannot find package "github.com/tmc/grpc-websocket-proxy/wsproxy" in any of:
/home/wjs/go/src/github.com/tmc/grpc-websocket-proxy/wsproxy (from $GOROOT)
/home/wjs/go/gopath/src/github.com/tmc/grpc-websocket-proxy/wsproxy (from $GOPATH)
依次go get -u -v 即可
搞完后make build
build目录下生成了 lora-app-server
生成 配置文件
lora-app-server configfile > lora-app-server.toml
打开 lora-app-server.toml
删除第一行
创建合适的数据库
可以参考 ubuntu 16.04 安装 postgresql 10 并 配置成loraserver需要的
这次要生成的是 loraserver_as 上次是 loraserver_ns
as: app-server ns network-server 也就是LoRa Wan 的as ns
wjs@wjs:~$ su
Password:
root@wjs:/home/wjs# su postgres
postgres@wjs:/home/wjs$ psql
psql (10.4 (Ubuntu 10.4-2.pgdg16.04+1))
Type "help" for help.
postgres=# create database loraserver_as owner dbuser;
CREATE DATABASE
postgres=# GRANT ALL PRIVILEGES ON DATABASE loraserver_as TO dbuser;
GRANT
打开 lora-app-server.toml 修改下 数据库的dsn 如下
dsn="postgres://dbuser:123456@localhost/loraserver_as?sslmode=disable"
pq_trgm extension
You also need to enable the pg_trgm
(trigram) extension. Example to enable this extension (assuming your LoRa App Server database is named loraserver_as
):
Start the PostgreSQL prompt as the postgres
user:
sudo -u postgres psql
Within the PostgreSQL prompt, enter the following queries:
-- change to the LoRa App Server database
\c loraserver_as
-- enable the extension
create extension pg_trgm;
-- exit the prompt
\q
配置ssl
我也不太懂,信息随便填了一下
openssl genrsa -out server.key 2048
openssl req -new -x509 -key server.key -out server.crt -days 365
Country Name (2 letter code) [AU]:ch
State or Province Name (full name) [Some-State]:gz
Locality Name (eg, city) []:gz
Organization Name (eg, company) [Internet Widgits Pty Ltd]:zlg
Organizational Unit Name (eg, section) []:zlg
Common Name (e.g. server FQDN or YOUR name) []:wjs
Email Address []:[email protected]
这样 会生成 2个文件 server.crt 和 server.key
~/go/gopath/src/github.com/brocaar/lora-app-server/build $ ls
lora-app-server lora-app-server.toml server.crt server.key
然后配置下 lora-app-server.toml 文件, 不配置程序起不来,不得不配置
# Settings for the "external api"
#
# This is 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
tls_cert="server.crt"
# http server TLS key
tls_key="server.key"
# JWT secret used for api authentication / authorization
# You could generate this by executing 'openssl rand -base64 32' for example
jwt_secret="123456"
# when set, existing users can't be re-assigned (to avoid exposure of all users to an organization admin)"
disable_assign_existing_users=false
运行程序 lora-app-server 大功告成 :)
~/go/gopath/src/github.com/brocaar/lora-app-server/build $ lora-app-server
INFO[0000] starting LoRa App Server docs="https://www.loraserver.io/" version=2.0.0-alpha.1-3-gb9999d3
INFO[0000] connecting to postgresql
INFO[0000] setup redis connection pool
INFO[0000] handler/mqtt: TLS config is empty
INFO[0000] handler/mqtt: connecting to mqtt broker server="tcp://localhost:1883"
INFO[0000] applying database migrations
INFO[0000] handler/mqtt: connected to mqtt broker
INFO[0000] handler/mqtt: subscribing to tx topic qos=0 topic=application/+/device/+/tx
INFO[0000] migrations applied count=0
INFO[0000] starting application-server api bind="0.0.0.0:8001" ca-cert= tls-cert= tls-key=
INFO[0000] starting join-server api bind="0.0.0.0:8003" ca_cert= tls_cert= tls_key=
INFO[0000] starting client api server bind="0.0.0.0:8080" tls-cert=server.crt tls-key=server.key
INFO[0000] registering rest api handler and documentation endpoint path=/api