前段时间,了解了通过spring-cloud-config-server与spring-cloud-eureka-server作为配置中心与注册中心,同时了解到基于zookeeper或consul可以完成同样的事情,所以必须了解一下,这样有利于实际工作的技术对比与选型。
安装zookeeper
下载
解压
tar -xvf zookeeper-3.4.10.tar.gz
启动zookeeper
cd zookeeper-3.4.10
cd conf
cp zoo_sample.cfg zoo.cfg
cd ../bin
sh zkServer.sh start
使用zookeeper作为服务注册中心
maven依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zookeeper-discovery</artifactId>
</dependency>
激活
package com.garlic.springcloudzookeeperclientapp;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
/**
* zookeeper作为服务注册中心,应用启动类
*
* @author sam.liu
*/
@SpringBootApplication
@EnableDiscoveryClient
public class SpringCloudZookeeperClientAppApplication {
public static void main(String[] args) {
SpringApplication.run(SpringCloudZookeeperClientAppApplication.class, args);
}
}
application.properties
## 配置应用名称
spring.application.name=spring-cloud-zookeeper-client-app
## 配置服务端口
server.port=8080
## 关闭安全控制
management.security