gonet2全部在linux + mac环境中开发,确保能在ubuntu 14.04 运行,理论上主流linux都能运行。
开发工具链可以访问TOOLCHAIN.md
- https://www.docker.com/ (MAC安装docker-machine)
- https://github.com/pote/gvp
- https://github.com/pote/gpm
- https://github.com/henszey/etcd-browser
- https://github.com/gonet2/libs/blob/master/services/init.sh
安装 docker toolbox : https://www.docker.com/toolbox
$docker-machine create --driver virtualbox default
$docker-machine upgrade default
$eval "$(docker-machine env default)"
$docker run --name etcd -d -p 2379:2379 quay.io/coreos/etcd -addr 172.17.42.1:2379
$docker run --name mongodb -d -p 27017:27017 -d mongo
$docker run -d --name lookupd -p 4160:4160 -p 4161:4161 nsqio/nsq /nsqlookupd
$docker run -d --name nsqd -p 4150:4150 -p 4151:4151 nsqio/nsq /nsqd --broadcast-address=172.17.42.1 --lookupd-tcp-address=172.17.42.1:4160
$docker run -d --name etcd-browser -p 0.0.0.0:8000:8000 --env ETCD_HOST=172.17.42.1 --env ETCD_PORT=2379 --env AUTH_USER=admin --env AUTH_PASS=admin etcd-browser
注意: 进入docker-machine运行registrator
$docker-machine ssh default
$docker run --name registrator -d -v /var/run/docker.sock:/tmp/docker.sock gliderlabs/registrator -ip="172.17.42.1" etcd://172.17.42.1:2379/backends
sudo ip addr add 172.17.42.1/16 dev docker0
sudo docker run --name etcd -d -p 2379:2379 quay.io/coreos/etcd -addr 172.17.42.1:2379
sudo docker run --name registrator -d -v /var/run/docker.sock:/tmp/docker.sock gliderlabs/registrator -ip="172.17.42.1" etcd://172.17.42.1:2379/backends
sudo docker run --name mongodb -d -p 27017:27017 -v /data/db:/data/db -d mongo
sudo docker run -d --name lookupd -p 4160:4160 -p 4161:4161 nsqio/nsq /nsqlookupd
sudo docker run -d --name nsqd -p 4150:4150 -p 4151:4151 nsqio/nsq /nsqd --broadcast-address=172.17.42.1 --lookupd-tcp-address=172.17.42.1:4160
sudo docker run -d --name statsd -p 80:80 -p 8125:8125/udp -p 8126:8126 kamon/grafana_graphite
sudo docker run -d --name etcd-browser -p 0.0.0.0:8000:8000 --env ETCD_HOST=172.17.42.1 --env ETCD_PORT=2379 --env AUTH_USER=admin --env AUTH_PASS=admin etcd-browser
sudo docker run -d --name registry -e SETTINGS_FLAVOR=dev -e STORAGE_PATH=/tmp/registry -v /data/registry:/tmp/registry -p 5000:5000 registry
服务重启:
sudo docker restart etcd mongodb nsqd lookupd statsd etcd-browser registry registrator
PS: 参考生产环境启动脚本: base_service.sh
执行克隆:
$curl -s https://raw.githubusercontent.com/gonet2/tools/master/clone_all.sh | sh
docker中运行:所有服务运行在docker中,并通过registrator自动注册;
比如启动agent:
$cd agent
$source gvp
$gpm
$docker build -t agent .
$docker run -d -P 8888:8888 --name agent -e SERVICE_ID=agent1 agent
比如启动agent:
$cd agent
$source gvp
$gpm
$go install agent
$agent
一般情况下, registrator 会自动注册通过docker启动的服务, 为了调试的方便,可以不通过docker启动,并且手动注册到etcd, etcd的服务注册地址为:
/backends/SERVICE_NAME/SERVICE_ID
例如:
$etcdctl set /backends/snowflake/snowflake1 172.17.42.1:51006
参考 https://github.com/en/unity-lib
1.tailn 查看所有服务的日志
$go get https://github.com/gonet2/tools/tailn
$tailn
2. 协议生成
$cd /github.com/gonet2/tools/proto_scripts
$./gen_proto.sh