码迷,mamicode.com
首页 > 其他好文 > 详细

koding kite如何部署使用?

时间:2015-07-30 13:45:58      阅读:772      评论:0      收藏:0      [点我收藏+]

标签:

1.下载kite和kontrol代码

git项目里面都有介绍, 这里是下载最新代码,如果是用于生产环境,注意从release下载稳定版本

go get github.com/koding/kite

2.安装Kontrol和初始化

Install Kontrol:

go get github.com/koding/kite/kontrol/kontrol

注意:这里生成的kontrol可执行程序在 $GOPATH/bin/目录下面

Generate keys for the Kite key:

openssl genrsa -out key.pem 2048
openssl rsa -in key.pem -pubout > key_pub.pem

Set environment variables(这里设置基本环境变量,也可以通过kontrol进行修改):  

KONTROL_PORT=6000  
KONTROL_USERNAME="kontrol"
KONTROL_STORAGE="etcd" #注意这里,有个坑,默认是etcd,但是没有注明安装和部署
KONTROL_KONTROLURL="http://127.0.0.1:6000/kite"
KONTROL_PUBLICKEYFILE="$youpath/certs/key_pub.pem"
KONTROL_PRIVATEKEYFILE="$youpath/certs/key.pem"

Generate initial Kite key:

$GOPATH/bin/kontrol -initial
执行结果如下
~/gocode/bin $./kontrol -initial
2015-07-29 09:57:25 [kontrol] WARNING  Key pair storage is not set. Using in memory cache
2015-07-29 09:57:25 [kontrol] INFO     Registered machine on user: kontrol
kite.key is written to ~/.kite/kite.key. You can see it with:
	kitectl showkey

3. 下载运行etcd

从https://github.com/coreos/etcd/releases/tag/v2.1.1 直接下载编译好的二进制

注意:这里只是为了跑通程序,部署单机进行测试

qpzhang@qpzhangdeMac-mini:~/gocode/kitetest/etcd-v2.1.1 $./etcd 
2015/07/29 15:20:28 etcdmain: setting maximum number of CPUs to 1, total number of available CPUs is 8
2015/07/29 15:20:28 etcdmain: no data-dir provided, using default data-dir ./default.etcd
2015/07/29 15:20:28 etcdmain: listening for peers on http://localhost:2380
2015/07/29 15:20:28 etcdmain: listening for peers on http://localhost:7001
2015/07/29 15:20:28 etcdmain: listening for client requests on http://localhost:2379
2015/07/29 15:20:28 etcdmain: listening for client requests on http://localhost:4001
2015/07/29 15:20:28 etcdserver: name = default
2015/07/29 15:20:28 etcdserver: data dir = default.etcd
2015/07/29 15:20:28 etcdserver: member dir = default.etcd/member
2015/07/29 15:20:28 etcdserver: heartbeat = 100ms
2015/07/29 15:20:28 etcdserver: election = 1000ms
2015/07/29 15:20:28 etcdserver: snapshot count = 10000
2015/07/29 15:20:28 etcdserver: advertise client URLs = http://localhost:2379,http://localhost:4001
2015/07/29 15:20:28 etcdserver: initial advertise peer URLs = http://localhost:2380,http://localhost:7001
2015/07/29 15:20:28 etcdserver: initial cluster = default=http://localhost:2380,default=http://localhost:7001
2015/07/29 15:20:28 etcdserver: starting member ce2a822cea30bfca in cluster 7e27652122e8b2ae
2015/07/29 15:20:28 raft: ce2a822cea30bfca became follower at term 0
2015/07/29 15:20:28 raft: newRaft ce2a822cea30bfca [peers: [], term: 0, commit: 0, applied: 0, lastindex: 0, lastterm: 0]
2015/07/29 15:20:28 raft: ce2a822cea30bfca became follower at term 1
2015/07/29 15:20:28 etcdserver: starting server... [version: 2.1.1, cluster version: to_be_decided]
2015/07/29 15:20:28 etcdserver: cannot monitor file descriptor usage (cannot get FDUsage on darwin)
2015/07/29 15:20:28 etcdserver: added local member ce2a822cea30bfca [http://localhost:2380 http://localhost:7001] to cluster 7e27652122e8b2ae
2015/07/29 15:20:29 raft: ce2a822cea30bfca is starting a new election at term 1
2015/07/29 15:20:29 raft: ce2a822cea30bfca became candidate at term 2
2015/07/29 15:20:29 raft: ce2a822cea30bfca received vote from ce2a822cea30bfca at term 2
2015/07/29 15:20:29 raft: ce2a822cea30bfca became leader at term 2
2015/07/29 15:20:29 raft: raft.node: ce2a822cea30bfca elected leader ce2a822cea30bfca at term 2
2015/07/29 15:20:29 etcdserver: setting up the initial cluster version to 2.1.0
2015/07/29 15:20:29 etcdserver: published {Name:default ClientURLs:[http://localhost:2379 http://localhost:4001]} to cluster 7e27652122e8b2ae
2015/07/29 15:20:29 etcdserver: set the initial cluster version to 2.1.0



4.启动kontrol

~/gocode/bin $./kontrol -ip=127.0.0.1 -port=6000
2015-07-29 15:23:20 [kontrol] WARNING  Key pair storage is not set. Using in memory cache
2015-07-29 15:23:20 [kontrol] INFO     New listening: 127.0.0.1:6000
2015-07-29 15:23:20 [kontrol] INFO     Serving…



现在能启动了,这里连接etcd是用默认的端口4001,如果在不同机器上部署,需要修改配置。

kontrol的使用方法如下:

Usage of ./kontrol:
  -initial=false: Change value of Initial.
  -ip=: Change value of Ip.
  -kontrolurl=http://127.0.0.1:6000/kite: Change value of KontrolURL.
  -machines=[]: Change value of Machines.
  -port=6000: Change value of Port.
  -postgres-dbname=: Change value of Postgres-DBName.
  -postgres-host=localhost: Change value of Postgres-Host.
  -postgres-password=: Change value of Postgres-Password.
  -postgres-port=5432: Change value of Postgres-Port.
  -postgres-username=: Change value of Postgres-Username.
  -privatekeyfile=/Users/qpzhang/gocode/kitetest/key.pem: Change value of PrivateKeyFile.
  -publickeyfile=/Users/qpzhang/gocode/kitetest/key_pub.pem: Change value of PublicKeyFile.
  -registerurl=: Change value of RegisterUrl.
  -tlscertfile=: Change value of TLSCertFile.
  -tlskeyfile=: Change value of TLSKeyFile.
  -username=kontrol: Change value of Username.
  -version=0.0.1: Change value of Version.



5.启动示例的kite

从 https://github.com/koding/kite/tree/master/examples 下载代码进行测试,这里测试的是

math_register.go 和 exp2-query.go

先启动提供服务者,向kontrol进行注册:

~/gocode/kitetest $./math_register
 2015-07-29 15:29:00 [math] INFO     Dialing ‘kontrol‘ kite: http://127.0.0.1:6000/kite
2015-07-29 15:29:00 [math] DEBUG    Client transport is set to ‘WebSocket‘
2015-07-29 15:29:00 [math] INFO     Connected to Kontrol 
2015-07-29 15:29:00 [math] INFO     Registering to kontrol with URL: http://localhost:6667/kite
2015-07-29 15:29:00 [math] DEBUG    Telling method [register] on kite [kontrol]
2015-07-29 15:29:00 [math] DEBUG    Sending: {"method":"register","arguments":[{"kite":{"name":"math","username":"kontrol","id":"284df2a9-427f-4a31-7f80-883a2e15d042","environment":"unknown","region":"unkn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aptOi61F3D5o7K1MVoUVr-HSn39jtpllJPdGnsXBS5uT-DBBniT76545M-odVqP83RToB45ahp_XRYNzbguVizqRyeKR-XVgAAy5_ckB419-R1d1ZOyCRmnzQjlyZgUk_S_A0F2x_hUfij_GcjYp2Nzy_UeZvNvubFMNdQaeTC56g"},"responseCallback":"[Function]","withArgs":[{"url":"http://localhost:6667/kite"}]}],"callbacks":{"0":[0,"responseCallback"]}}
2015-07-29 15:29:00 [math] DEBUG    Received : {"method":"kite.heartbeat","arguments":[{"kite":{"name":"kontrol","username":"kontrol","id":"b49f6b65-b152-420c-5e0b-4919b0b1825f","environment":"unknown","region":"unknown","version":"0.0.1","hostname":"qpzhangdeMac-mini.local"},"authentication":null,"responseCallback":"[Function]","withArgs":[10,"[Function]"]}],"callbacks":{"0":[0,"responseCallback"],"1":[0,"withArgs",1]}}
2015-07-29 15:29:00 [math] DEBUG    Received : {"method":0,"arguments":[{"error":null,"result":{"url":"http://localhost:6667/kite","heartbeatInterval":0}}],"callbacks":{}}
2015-07-29 15:29:00 [math] INFO     Registered to kontrol with URL: http://localhost:6667/kite and Kite query: /kontrol/unknown/math/1.0.0/unknown/qpzhangdeMac-mini.local/284df2a9-427f-4a31-7f80-883a2e15d042
2015-07-29 15:29:00 [math] INFO     New listening: 0.0.0.0:6667
2015-07-29 15:29:00 [math] INFO     Serving...



然后启动调用者:
~/gocode/kitetest $./exp2-query
2015-07-29 15:29:06 [exp2] INFO     Dialing ‘kontrol‘ kite: http://127.0.0.1:6000/kite
2015-07-29 15:29:06 [exp2] INFO     Connected to Kontrol 
2015-07-29 15:29:07 [exp2] INFO     Dialing ‘math‘ kite: http://localhost:6667/kite
2015-07-29 15:29:08 [exp2] INFO     math: Message from math: "You have requested square of 7"
input: 7  result: 49



然后会看到math_register输出日志:
2015-07-29 15:29:07 [math] DEBUG    New session: yWydSeY8IQKWfs3CkOhh
2015-07-29 15:29:08 [math] DEBUG    Received : {"method":"square","arguments":[{"kite":{"name":"exp2","username":"kontrol","id":"a6a11fab-d476-4275-4770-a42ad6698c3d","environment":"unknown","region":"unknown","version":"1.0.0","hostname":"qpzhangdeMac-mini.local"},"authentication":{"type":"token","key":"eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiIva29udHJvbC91bmtub3duL21hdGgiLCJleHAiOjE0MzgzMjc4MDYsImlhdCI6MTQzODE1NDk0NiwiaXNzIjoia29udHJvbCIsImp0aSI6IjMyMTA4ZWIzLTg5MWItNGExZi03ZjQ3LTQ0MDU4YTczYWIyZSIsIm5iZiI6MTQzODE1NDg4Niwic3ViIjoia29udHJvbCJ9.CrireQe5HvNxbefvyGSaWDpHYEaX7cAkkQJjbWno4f7ki5sLAqJGet65heyiZFMNqJBALQZHkTVjExuwYA8b7ade4Y15ht9yhUdK8hRNbpzgQ5NHCMozJLvpkeijkp02EMSG8wfNbXogld3OkcajpGzN0b6KnRfSmsyNe9MdX5u7VesHo4JXTzlnY9zOTTtgGEjZQvlxI8WQTXge_6O0IMKO2xl5PvokYrnOLmNnKMYKYRYtj2MH58vvkQaqoktiKGRGmSDqBzNDoxX4X1reWdShcPn_1c38sV1aw3CvFbjRyrXHGf25g5dMqX98jC7IpcLCKWTv9rkKuS88LCvNPA"},"responseCallback":"[Function]","withArgs":[7]}],"callbacks":{"0":[0,"responseCallback"]}}
2015-07-29 15:29:08 [math] DEBUG    Session "yWydSeY8IQKWfs3CkOhh" is identified as "/kontrol/unknown/exp2/1.0.0/unknown/qpzhangdeMac-mini.local/a6a11fab-d476-4275-4770-a42ad6698c3d"
Call received, sending result 49 back



至此,这个框架都跑起来了。

但是都是在本机。

【Kite架构是怎么样?】
 
【Kite代码是怎么编写的?】
 
【Kite如何搭建分布式系统?会存在那些问题?】

后续慢慢研究 了。


koding kite如何部署使用?

标签:

原文地址:http://my.oschina.net/jackeyzhang/blog/485567

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!