java Zookeeper配置
springCloud学习记录
Zookeeper(注册中心)
zookeeper配置在linux,需要关闭防火墙,并且能ping通linux服务。注册成功后能在zookeeper节点中看到,linux上的zookeeper版本需要和项目上的zookeeper版本一致,不然会抛错;服务者和消费者都需要注册
一、linux部分
zookeeper安装
https://www.cnblogs.com/expiator/p/9853378.html
安装完后到bin目录运行服务:
./zkServer.sh start
服务启动后运行客户端查看入驻的服务
./zkCli.sh
查看节点:ls /zookeeper
二、项目配置
pom:
<!--SpringBoot整合Zookeeper客户端-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zookeeper-discovery</artifactId>
<exclusions>
<!--先排除自带的zookeeper3.5.3-->
<exclusion>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
</exclusion>
</exclusions>
</dependency>
<!--添加zookeeper3.4.9版本-->
<dependency>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
<version>3.4.14</version>
</dependency>
yml:
server:
port: 80
spring:
application:
# 服务别名,节点名
name: cloud-consumer-order
cloud:
zookeeper:
# 注册到zookeeper地址,端口默认2181
connect-string: 127.0.0.1:2181
如何访问与Eureka一样,需要与节点名一样
http://cloud-provider-payment