文章目录
一. Service-Center 是什么
Service-Center(SC)是一个服务注册中心。 服务提供者(provider)可以将自身的实例信息注册到 SC,以供服务消费者(consumer)从 SC 发现并使用它。
在传统服务中,一般将 provider 的实例信息配置到指定的配置文件中,以供 consumer 使用。这种使用方式下,若 provider 修改了配置信息,counsumer 则需要手工修改配置,并重启服务来适应变化。若是需要维护的服务较少,这倒不会花费太多气力。然而在微服务领域,涉及的服务数动辄成百上千,若是通过手工去维护这些配置,相信运维人员早就磨刀霍霍向开发了。服务注册中心应运而生。
二. 设计原理
参见:ServiceComb官网 ServiceCenter用户手册,此处不再赘述
三. 安装与启动
1. 官方安装包
官网获取指定版本并下载:http://servicecomb.apache.org/cn/release/
笔者在此处使用了 apache-servicecomb-incubating-service-center-1.0.0-linux-amd64.tar.gz 包,实际操作时请根据系统环境选取对应版本
# 下载linux版本包
$ wget http://archive.apache.org/dist/incubator/servicecomb/incubator-servicecomb-service-center/1.0.0/apache-servicecomb-incubating-service-center-1.0.0-linux-amd64.tar.gz
# 解压tar包
$ tar -zxvf apache-servicecomb-incubating-service-center-1.0.0-linux-amd64.tar.gz
# 启动servicecenter服务
$ cd apache-servicecomb-incubating-service-center-1.0.0-linux-amd64/
$ ./start-service-center.sh
$ ps -ef | grep service-center
root 27048 1 2 14:38 pts/2 00:00:00 ./service-center
root 27164 22742 0 14:38 pts/2 00:00:00 grep --color=auto service-center
# 查看监听配置
$ cat conf/app.conf | grep "sever options" -A 16
# sever options
###################################################################
# if you want to listen at ipv6 address, then set the httpaddr value like:
# httpaddr = 2400:A480:AAAA:200::159 (global scope)
# httpaddr = fe80::f816:3eff:fe17:c38b%eth0 (link-local scope)
httpaddr = 127.0.0.1
httpport = 30100
read_header_timeout = 60s
read_timeout = 60s
idle_timeout = 60s
write_timeout = 60s
max_header_bytes = 32768 # 32K
max_body_bytes = 2097152 # 2M
enable_pprof = 0
# 查看端口监听
$ netstat -apn | grep :30100
tcp 0 0 127.0.0.1:30100 0.0.0.0:* LISTEN 27048/service-cente
$ curl http://127.0.0.1:30100
{
"_links":{
"pb:latest-pact-versions":{
"href":"http://127.0.0.1:30100/pacts/latest","title":"Latest pact versions"},"pb:latest-provider-pacts":{
"href":"http://127.0.0.1:30100/pacts/provider/{provider}/latest","title":"Latest pacts by provider","templated":true},"pb:latest-provider-pacts-with-tag":{
"href":"http://127.0.0.1:30100/pacts/provider/{provider}/latest/{tag}","title":"Latest pacts by provider with a specified tag","templated":true},"pb:pacticipants":{
"href":"http://127.0.0.1:30100/participants","title":"Pacticipants"},"pb:publish-pact":{
"href":"http://127.0.0.1:30100/pacts/provider/{provider}/consumer/{consumer}/version/{consumerApplicationVersion}","title":