apollo新增扩展consul注册中心

任意选择一个仓库下载
git clone https://gitee.com/lepdou/apollo.git
git clone https://github.com/ctripcorp/apollo.git

扩展支持 consul

扩展过程
1、修改build.sh
mvn 渲染 启动为consul
mvn clean package -DskipTests -pl apollo-configservice,apollo-adminservice -am -Dapollo_profile=github,consul -Dspring_datasource_url= a p o l l o c o n f i g d b u r l − D s p r i n g d a t a s o u r c e u s e r n a m e = apollo_config_db_url -Dspring_datasource_username= apolloconfigdburlDspringdatasourceusername=apollo_config_db_username -Dspring_datasource_password=$apollo_config_db_password

2、添加consul 服务器地址
main/config
apolication-github.properties
spring.datasource.url = ${spring_datasource_url}
spring.datasource.username = ${spring_datasource_username}
spring.datasource.password = ${spring_datasource_password}
spring.cloud.consul.host=192.168.1.6
spring.cloud.consul.port=8500

3、修改源码
com.ctrip.framework.apollo.metaservice.HomePageController
@Profile({“kubernetes”, “nacos-discovery”})
修改成
@Profile({“kubernetes”, “nacos-discovery”,“consul”})

4、新增源码
com.ctrip.framework.apollo.metaservice包下 新增ConsulDiscoveryService类

注意 DiscoveryClient 为 org.springframework.cloud.client.discovery.DiscoveryClient
包下面的
在这里插入图片描述

5、修改源码
com.ctrip.framework.apollo.metaservice.service.DefaultDiscoveryService
@ConditionalOnMissingProfile({“kubernetes”, “nacos-discovery”})
修改成
@ConditionalOnMissingProfile({“kubernetes”, “nacos-discovery”,“consul”})

6、apollo-configservice resouces下面增加 application-consul.properties配置
apollo.eureka.server.enabled=false
eureka.client.enabled=false

spring.cloud.consul.enabled=true
#是否去发现其他服务
spring.cloud.consul.discovery.enabled=true
spring.cloud.consul.discovery.heartbeat.enabled=true

#使用 consul 服务器 IP, 而不是 hostname, 需要搭配 prefer-ip-address 属性
spring.cloud.consul.discovery.prefer-ip-address=true

#使用外网ip注册到consul中
spring.cloud.consul.discovery.ip-address=xxx.xxx.xxx.xxx

#是否将自身服务注册到consul中
spring.cloud.consul.discovery.register=true

spring.cloud.consul.discovery.health-check-path=/health
spring.cloud.consul.discovery.health-check-interval=15s

#注册的实例ID (唯一标志)
spring.cloud.consul.discovery.instance-id=${spring.application.name}

7、biz 包下面 pom 增加 consul 依赖

	<dependency>
		<groupId>org.springframework.cloud</groupId>
		<artifactId>spring-cloud-starter-consul-discovery</artifactId>
	</dependency>

运行上一步修改的BUILD.SH脚本
./build.sh

8、修改admin-adminservice 配置
main/config
apolication-github.properties
spring.datasource.url = ${spring_datasource_url}
spring.datasource.username = ${spring_datasource_username}
spring.datasource.password = ${spring_datasource_password}
spring.cloud.consul.host=xxx.xxx.xxx.xxx
spring.cloud.consul.port=8500

9、main/resources 与configservice 差不多
application-consul.properties 拷贝到 adminservice下面一份

由于ApolloConfigDB在每个环境都有部署,所以对不同环境的config-service和admin-service需要使用不同的数据库连接信息打不同的包,portal和client只需要打一次包即可
开始部署
部署程序到对应的服务器
依次部署 apollo-configservice、apollo-adminservice、apollo-portal
LOG_DIR=/opt/logs/100003171
SERVER_PORT=8070
执行scripts/startup.sh即可
如需停止服务,执行scripts/shutdown.sh

LOG_DIR=/opt/logs/100003172
SERVER_PORT=8071
执行scripts/startup.sh即可
如需停止服务,执行scripts/shutdown.sh

修改scripts/startup.sh:
LOG_DIR=/opt/logs/100003173
SERVER_PORT=8072
执行scripts/startup.sh即可

特别需要注意:
自己理解,如有不对请指正。
build.sh db配置 用于生成 admin、config服务的连接,所以多少个服务则需配置多少次。如只有一个portal管理多个config则portal可以不变。

dev_meta=XXX
fat_mata=XXX
这两个则是portal用于管理环境的,所以需要确定配置的地址 是可以访问的。如访问不了环境信息则不会出来。切记,此处我已踩坑。 一度认为是扩展consul后出现的问题。

注意开放端口,或者关闭防火墙
1:查看防火状态

systemctl status firewalld

service iptables status

2:暂时关闭防火墙

systemctl stop firewalld

service iptables stop

3:永久关闭防火墙

systemctl disable firewalld

chkconfig iptables off

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值