执行启动命令后等待几秒,然后查看服务是否启动成功。可通过在容器中查看启动日志来判断服务是否启动成功:
docker exec -it kube_apollo-configservice-dev_1 sh cat /opt/logs/apollo-config-server/apollo-configservice.logkube_apollo-configservice-dev_1是apollo-configservice-dev的容器名称可通过docker container ps查看,看到如下日志基本可以确定服务已经成功启动:
2018-12-27 21:45:51.889 INFO 40 --- [Thread-17] c.n.e.registry.AbstractInstanceRegistry : Registered instance APOLLO-CONFIGSERVICE/f2b6896763d0:apollo-configservice:8080 with status UP (replication=true) 2018-12-27 21:45:51.889 INFO 40 --- [Thread-17] c.n.e.r.PeerAwareInstanceRegistryImpl : Got 1 instances from neighboring DS node 2018-12-27 21:45:51.889 INFO 40 --- [Thread-17] c.n.e.r.PeerAwareInstanceRegistryImpl : Renew threshold is: 1 2018-12-27 21:45:51.889 INFO 40 --- [Thread-17] c.n.e.r.PeerAwareInstanceRegistryImpl : Changing status to UP 2018-12-27 21:45:51.894 INFO 40 --- [Thread-17] e.s.EurekaServerInitializerConfiguration : Started Eureka Server 管理服务部署(apollo-adminservice)管理服务的配置基本上与配置服务的配置基本相似,首先在apollo-compose中添加apollo-adminservice-dev服务:
version: "3" services: ... #省略其他服务配置 apollo-adminservice-dev: image: <镜像名称> environment: DATASOURCES_URL: "jdbc:mysql://mysql-dev:3306/ApolloConfigDB?characterEncoding=utf8" DATASOURCES_USERNAME: root DATASOURCES_PASSWORD: 123456 ENV: "dev" expose: - "8080" depends_on: - "mysql-dev" #管理服务依赖之前配置的mysql-dev服务 - "apollo-configservice-dev" #管理服务依赖配置服务同apollo-configservice-dev一样定义几个环境变量:
DATASOURCES_URL (mysql-dev连接地址)
DATASOURCES_USERNAME (mysql-dev连接用户)
DATASOURCES_PASSWORD (mysql-dev的root密码)
ENV (apollo-configservice)的运行环境
添加服务完成后开始启动apollo-adminservice-dev服务:
docker-compose -f apollo-compose.yaml up -d apollo-adminservice-dev然后使用docker container ps查看容器名称,随后执行命令查看Log文件:
docker exec -it kube_apollo-adminservice-dev_1 sh cat /opt/logs/apollo-admin-server/apollo-adminservice.log | tail -n 50部分日志输出如下所示:
... 2018-12-27 21:56:45.722 INFO 40 --- [DiscoveryClient-InstanceInfoReplicator-0] com.netflix.discovery.DiscoveryClient : DiscoveryClient_APOLLO-ADMINSERVICE/8578c069d388:apollo-adminservice:8090: registering service... 2018-12-27 21:56:45.804 INFO 40 --- [main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8090 (http) with context path '' 2018-12-27 21:56:45.810 INFO 40 --- [main] .s.c.n.e.s.EurekaAutoServiceRegistration : Updating port to 8090 2018-12-27 21:56:45.810 INFO 40 --- [DiscoveryClient-InstanceInfoReplicator-0] com.netflix.discovery.DiscoveryClient : DiscoveryClient_APOLLO-ADMINSERVICE/8578c069d388:apollo-adminservice:8090 - registration status: 204现在可以确定Eureka注册中心中已经有两个服务分别为APOLLO-CONFIGSERVICE和APOLLO-ADMINSERVICE服务。
管理控制台部署(apollo-portal)成功部署配置服务(apollo-configservice)和管理服务(apollo-adminsrevice)并启动成功后,现在可以部署管理控制台服务(apollo-portal)了。首先在apollo-compose.yaml文件添加两个服务:
mysql-portal: image: mysql # restart: always environment: - MYSQL_ROOT_PASSWORD=123456 expose: - "3306" volumes: - /Users/yjwfn/bin/apollo/scripts/sql:/sql apollo-portal: image: <镜像名称> environment: DEV_META_SERVICE_NAME: apollo-configservice-dev DATASOURCES_URL: "jdbc:mysql://mysql-portal:3306/ApolloPortalDB?characterEncoding=utf8" DATASOURCES_USERNAME: root DATASOURCES_PASSWORD: 123456 # expose: # - "8070" ports: - 8070:8070 #方便测试导出端口 depends_on: - "mysql-portal" - "apollo-configservice-dev" - "apollo-adminservice-dev"管理控制台服务使用了单独的mysql服务,没有与apollo-configservice-dev和apollo-adminservice-dev共享一个mysql服务,同样mysql-portal也需要初始化数据库,这里我们首先启动mysql-portal服务:
#启动服务 docker-compose -f apollo-compose.yaml up -d mysql-portal #连接到容器执行命令 docker exec -it kube_mysql-portal_1 sh #登陆mysql mysql -p123456 #导入sql文件 source /sql/apolloportaldb.sqlmysql-portal启动并配置完成后开始启动apollo-portal服务:
docker-compose -f apollo-compose.yaml up -d apollo-portal启动成功后可访问 :8070 启动管理控制台。
总结由于现在公司也正在使用Apollo做为分布式配置中心,所以决定学习下Apollo的相关知识。 此文章只涉及到部署想着的知识,里面提到的一些内容其实都可以在官方文档中找到,这里不得不提下Apollo的文档资料还是非常全的。总的来说部署的过程还是有些坑的,但是经过一段时候的摸索,还是成功的在Docker中部署了,之后还会学习Apollo的使用相关的知识,后续再来分享。