Skip to content

Commit

Permalink
add service flag doc。
Browse files Browse the repository at this point in the history
  • Loading branch information
ruizeng committed Dec 15, 2015
1 parent 3178005 commit cdf47de
Show file tree
Hide file tree
Showing 11 changed files with 116 additions and 4 deletions.
2 changes: 1 addition & 1 deletion build/local/linux/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ $GOPATH/bin/registry -etcd http://localhost:2379 -rpchost localhost:20034 -aeske
$GOPATH/bin/apiprovider -etcd http://localhost:2379 -loglevel debug -httphost localhost:8888 &
$GOPATH/bin/devicemanager -etcd http://localhost:2379 -loglevel debug -rpchost localhost:20033 &
$GOPATH/bin/controller -etcd http://localhost:2379 -loglevel debug -rpchost localhost:20032 &
$GOPATH/bin/mqttaccess -etcd http://localhost:2379 -loglevel debug -rpchost localhost:20030 -tcphost localhost:1883 &
$GOPATH/bin/mqttaccess -etcd http://localhost:2379 -loglevel debug -rpchost localhost:20030 -tcphost :1883 -usetls -keyfile $GOPATH/src/github.com/PandoCloud/pando-cloud/pkg/server/testdata/key.pem -cafile $GOPATH/src/github.com/PandoCloud/pando-cloud/pkg/server/testdata/cert.pem &

exit 0
6 changes: 5 additions & 1 deletion docs/zh-cn/quick-start/ubuntu.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ etcd &

```sh
cd $GOPATH/src/github.com/PandoCloud/pando-cloud
sh -x ./build/local/linux/run.sh
sudo sh -x ./build/local/linux/run.sh
```

查询进程,如果6个服务都启动,则证明顺利运行。
Expand All @@ -140,6 +140,10 @@ sh -x ./build/local/linux/run.sh
ps aux | grep $GOPATH/bin
```

> 说明:`run.sh`脚本默认将本服务器的内外网ip的443端口(https默认端口)作为设备登陆的监听端口,将本地(`localhost`)地址的8888端口作为api接口服务的监听端口(默认情况api服务只能本机访问,如果需要通过外网访问,需要去掉httphost参数中的`localhost`)。
如果需要自定义各服务的启动参数,请参考[服务部署指南](../services/README.md)

### 4. 配置
平台提供命令行配置工具进行配置,详细使用方法请参考[配置工具](../tools/pdcfg.md)

Expand Down
10 changes: 10 additions & 0 deletions docs/zh-cn/services/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# 服务部署指南

Pando物联网云平台采用微服务架构。除了系统依赖的MySQL,MongoDB等开源服务,平台自身目前有以下几个服务组成:

- **[registry](registry.md)**:维护平台全局配置和信息的服务。
- **[devicemanager](devicemanager.md)**: 设备信息和设备状态维护。
- **[controller](controller.md)**: 和设备进行信息交互的路由服务。
- **[apiprovider](apiprovider.md)**: 为应用提供REST接口。
- **[httpaccess](httpaccess.md)**: 设备API服务,提供设备登陆、注册等逻辑。
- **[mqttaccess](mqttaccess.md)**:MQTT接入服务。
17 changes: 17 additions & 0 deletions docs/zh-cn/services/apiprovider.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# apiprovider

`apiprovider`服务为应用提供HTTP REST接口。

## 工作原理
[应用接口文档](../api-doc/application.md)

## 启动参数
* `-etcd` etcd服务的访问地址,必需参数。如`http://localhost:2379`,如果etcd是多副本部署,可以用分号隔开访问地址,如`http://192.168.0.2:2379;http://192.168.0.3:2379`
* `-rpchost` rpc服务访问地址,必需参数。该参数定义该服务对其他服务提供的rpc服务的监听地址。如`http://localhost:20034`
* `-httphost` HTTP服务地址,必须参数。格式为`ip:port``localhost:443`,为了安全考虑,建议最好只绑定内网ip和端口。如果需要外网访问,强烈建议开启https选项。
* `-usehttps` 是否启动https服务,默认不启用。如果启用,则必须提供以下`cafile``keyfile`两个参数。
* `-cafile` ssl加密证书的证书文件路径(pem格式)。
* `-keyfile` ssl加密证书的密钥文件路径(pem格式)。
* `-loglevel` 服务打印日志的级别,选填,如果没有指定则默认为`info`级别。

> 说明:ssl证书和密钥的pem文件生成方法可以参考[这里](http://killeraction.iteye.com/blog/858325)
15 changes: 15 additions & 0 deletions docs/zh-cn/services/controller.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# controller

`controller`服务作为和设备进行信息交互时的控制节点,为访问设备提供路由服务,并接收设备上报的信息。

## 工作原理
`controller`主要负责设备信息交互,具体分两种场景:

* 当应用需要向设备发送信息时,`controller`会向`devicemanager` 查询当前设备的在线信息,并根据反馈的接入点,向接入服务器发送信息转发请求。
* 当设备向平台发送数据时,`controller`会将数据存入MongoDB,如需通知应用则放入消息队列。

## 启动参数
* `-etcd` etcd服务的访问地址,必需参数。如`http://localhost:2379`,如果etcd是多副本部署,可以用分号隔开访问地址,如`http://192.168.0.2:2379;http://192.168.0.3:2379`
* `-rpchost` rpc服务访问地址,必需参数。该参数定义该服务对其他服务提供的rpc服务的监听地址。如`http://localhost:20034`
* `-mongohost` MongoDB地址,可选参数。如果没有提供则为`localhost`,如果需要指定,格式为`ip:port``192.168.0.3:27017`
* `-loglevel` 服务打印日志的级别,选填,如果没有指定则默认为`info`级别。
11 changes: 11 additions & 0 deletions docs/zh-cn/services/devicemanager.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# devicemanager

`devicemanager`维护了设备的状态,如设备当前在哪台接入服务器接入,设备是否在线等。

## 工作原理
`devicemanager`是无状态的,采用redis存储了设备的实时状态信息,并对外提供了rpc接口供其他服务查询设备的当前信息。

## 启动参数
* `-etcd` etcd服务的访问地址,必需参数。如`http://localhost:2379`,如果etcd是多副本部署,可以用分号隔开访问地址,如`http://192.168.0.2:2379;http://192.168.0.3:2379`
* `-rpchost` rpc服务访问地址,必需参数。该参数定义该服务对其他服务提供的rpc服务的监听地址。如`http://localhost:20034`
* `-loglevel` 服务打印日志的级别,选填,如果没有指定则默认为`info`级别。
13 changes: 13 additions & 0 deletions docs/zh-cn/services/httpaccess.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# httpaccess

`httpaccess`服务提供了供设备注册、登录的HTTP[接口](../api-doc/device.md)

## 启动参数
* `-etcd` etcd服务的访问地址,必需参数。如`http://localhost:2379`,如果etcd是多副本部署,可以用分号隔开访问地址,如`http://192.168.0.2:2379;http://192.168.0.3:2379`
* `-httphost` HTTP服务地址,必须参数。格式为`ip:port``localhost:443`,强烈建议开启https选项。一般情况下绑定到外网的443端口(https默认端口)。
* `-usehttps` 是否启动https服务,默认不启用。如果启用,则必须提供以下`cafile``keyfile`两个参数。如果需要pando设备连接,则必须启用,否则无法连接。
* `-cafile` ssl加密证书的证书文件路径(pem格式)。
* `-keyfile` ssl加密证书的密钥文件路径(pem格式)。
* `-loglevel` 服务打印日志的级别,选填,如果没有指定则默认为`info`级别。

> 说明:ssl证书和密钥的pem文件生成方法可以参考[这里](http://killeraction.iteye.com/blog/858325)
15 changes: 15 additions & 0 deletions docs/zh-cn/services/mqttaccess.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# mqttaccess

mqttaccess是支持mqtt协议的接入服务器,平台目前默认采用该协议。提供了tcp长连接连接设备,并对设备交互数据进行转发服务。

## 启动参数

* `-etcd` etcd服务的访问地址,必需参数。如`http://localhost:2379`,如果etcd是多副本部署,可以用分号隔开访问地址,如`http://192.168.0.2:2379;http://192.168.0.3:2379`
* `-rpchost` rpc服务访问地址,必需参数。该参数定义该服务对其他服务提供的rpc服务的监听地址。如`http://localhost:20034`
* `-tcphost` tcp服务地址,必须参数。格式为`ip:port``localhost:1883`,一般绑定为外网ip加1883端口(mqtt默认端口)。
* `-usetls` 是否启动ssl加密服务,默认不启用。如果启用,则必须提供以下`cafile``keyfile`两个参数。如果pando设备需接入,必须开启tls加密选项,否则无法接入。
* `-cafile` ssl加密证书的证书文件路径(pem格式)。
* `-keyfile` ssl加密证书的密钥文件路径(pem格式)。
* `-loglevel` 服务打印日志的级别,选填,如果没有指定则默认为`info`级别。

> 说明:ssl证书和密钥的pem文件生成方法可以参考[这里](http://killeraction.iteye.com/blog/858325)
18 changes: 18 additions & 0 deletions docs/zh-cn/services/registry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# registry

`registry`服务负责维护平台的全局配置。

## 工作原理
该服务采用MySQL存储平台的配置和设备注册信息。

`registry`服务是无状态的,在名为`PandoCloud`的库中维护了`application`, `vendor`, `product`以及`device`表,并为了加快访问速度提供了缓存机制。

## 启动参数列表
* `-etcd` etcd服务的访问地址,必需参数。如`http://localhost:2379`,如果etcd是多副本部署,可以用分号隔开访问地址,如`http://192.168.0.2:2379;http://192.168.0.3:2379`
* `-rpchost` rpc服务访问地址,必需参数。该参数定义该服务对其他服务提供的rpc服务的监听地址。如`http://localhost:20034`
* `-aeskey` 用来生成KEY的aes加密密钥串,必须参数。该参数为32位的任意字符串,如`ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP`。该参数越随机越好。
* `-dbhost` MySQL数据库的访问地址,选填,如果没有填写默认为`localhost`
* `-dbport` MySQL数据库的访问端口,选填,如果没有填写默认为`3306`
* `-dbuser` MySQL数据库的访问用户名,选填,如果没有填写默认为`root`
* `-dbpass` MySQL数据库的访问用户密码,选填,如果没有填写默认为空。
* `-loglevel` 服务打印日志的级别,选填,如果没有指定则默认为`info`级别。
4 changes: 3 additions & 1 deletion tests/device/device.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"crypto/tls"
"encoding/hex"
"encoding/json"
"fmt"
Expand Down Expand Up @@ -256,13 +257,14 @@ func (d *Device) DoAccess() error {

//create a ClientOptions struct setting the broker address, clientid, turn
//off trace output and set the default message handler
opts := MQTT.NewClientOptions().AddBroker("tcp://" + d.access)
opts := MQTT.NewClientOptions().AddBroker("tls://" + d.access)
clientid := fmt.Sprintf("%x", d.id)
opts.SetClientID(clientid)
opts.SetUsername(clientid) // clientid as username
opts.SetPassword(hex.EncodeToString(d.token))
opts.SetKeepAlive(30 * time.Second)
opts.SetDefaultPublishHandler(d.messageHandler)
opts.SetTLSConfig(&tls.Config{Certificates: nil, InsecureSkipVerify: true})

//create and start a client using the above ClientOptions
c := MQTT.NewClient(opts)
Expand Down
9 changes: 8 additions & 1 deletion tests/device/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,17 @@ import (

var (
TestUrl = flag.String("url", "https://localhost", "login url")
TestProductKey = flag.String("productkey", "aec003c9018b9a572ceb19720e589c375ead1a2b1fbd0d089d067128611754ff", "product key")
TestProductKey = flag.String("productkey", "", "product key")
)

func main() {
flag.Parse()

if *TestProductKey == "" {
fmt.Println("product key not provided. use -productkey flag")
return
}

dev := NewDevice(*TestUrl, *TestProductKey, "ffe34e", "version")

err := dev.DoRegister()
Expand Down

0 comments on commit cdf47de

Please sign in to comment.