ubuntu 16.04 安装 postgresql 10 并 配置成loraserver需要的

配置仓库

Create the file /etc/apt/sources.list.d/pgdg.list and add a line for the repository

deb http://apt.postgresql.org/pub/repos/apt/ xenial-pgdg main


su
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -
sudo apt-get update
安装postgresql-10
apt-get install postgresql-10


安装好后, postgresql 会自动创建一个 postgres 的用户,它暂时没有密码
我们通过下面的命令设置密码
su
su postgres
psql
\password


我新建个 dbuser 帐号
postgres=# CREATE USER dbuser WITH PASSWORD '123456';
CREATE ROLE
postgres=# CREATE DATABASE exampledb OWNER dbuser;
CREATE DATABASE
postgres=# GRANT ALL PRIVILEGES ON DATABASE exampledb TO dbuser;
GRANT
\q 


退出后 我想登录了 再试试操作下数据库
psql -U dbuser -d exampledb -h 127.0.0.1
CREATE TABLE wjs ( name text, age integer );
insert into wjs (name, age) values('test0', 23);
insert into wjs (name, age) values('test1', 22);
select * from wjs where age > 20;

参考 命令行方式登录PostgreSQL、创建用户和数据库并赋权


下面正对loraserver进行必要的配置
su
su postgres
psql
create database loraserver_ns owner dbuser;


来到loraserver build目录下

loraserver configfile > loraserver.toml
打开loraserver.toml 然后第一行删掉

dsn="postgres://dbuser:123456@localhost/loraserver_ns?sslmode=disable"


再运行 loraserver后,数据库已经连上了。接下来提示 mqtt 连接失败。

~/go/gopath/src/github.com/brocaar/loraserver/build $ loraserver
INFO[0000] starting LoRa Server                          band=EU_863_870 docs="https://docs.loraserver.io/" net_id=000000 version=1.0.0-1-g3338792
INFO[0000] setup redis connection pool                   url="redis://localhost:6379"
INFO[0000] connecting to postgresql                     
INFO[0000] backend/gateway: TLS config is empty         
INFO[0000] backend/gateway: connecting to mqtt broker    server="tcp://localhost:1883"
ERRO[0000] backend/gateway: connecting to mqtt broker failed, will retry in 2s: Network Error : dial tcp 127.0.0.1:1883: connect: connection refused 

猜你喜欢

转载自blog.csdn.net/wangjunsheng/article/details/80836921