zookeeper代替eureka
长时间没心跳会删除
eureka可以有90秒等待以及保护措施,zookeeper更坚决些
是分布式协调工具,可以实现注册中心功能
需要先在liunx上安装zookeeper
需要开放端口 2181 2888 3888
<dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <scope>runtime</scope> <optional>true</optional> </dependency> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <optional>true</optional> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-zookeeper-discovery</artifactId> <exclusions> <!--先排除自带的zookeeper,自带版本与服务器zookeeper的可能冲突--> <exclusion> <groupId>org.apache.zookeeper</groupId> <artifactId>zookeeper</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.apache.zookeeper</groupId> <artifactId>zookeeper</artifactId> <!--与服务器的zookeeper版本一致--> <version>3.4.14</version> </dependency> </dependencies>
#8004表示注册到zookeeper服务器的服务提供者端口号 server: port: 8004 spring: application: #服务别名注册到zookeeper的服务名称 name: cloud-provider-payment cloud: zookeeper: connect-string: 192.168.68.128:2181
@SpringBootApplication @EnableDiscoveryClient public class PaymentMain8004{ public static void main(String[] args){ SpringApplication.run(PaymentMain8004.class,args); } }
服务注册后检查
./zkCli.sh 开启客户端
或者在idea上看