0


Spring Boot Dubbo Zookeeper(含ZK安装脚本)

文章目录

Spring Boot Dubbo Zookeeper(含ZK安装脚本)


简介

Dubbo

Common

**

公共依赖

**

<!-- Spring Boot Starter --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter</artifactId><version>2.3.0.RELEASE</version></dependency><!-- Dubbo Starter --><dependency><groupId>org.apache.dubbo</groupId><artifactId>dubbo-spring-boot-starter</artifactId><version>2.7.8</version></dependency><!-- ZooKeeper 注册中心 --><dependency><groupId>org.apache.dubbo</groupId><artifactId>dubbo-registry-zookeeper</artifactId><version>2.7.8</version></dependency>
  • 定义接口(用户服务注册使用)
publicinterfaceHelloService{StringsayHello(String name);}

Provider

**

首先需要依赖Common

**

  • yml
dubbo:application:name: my-application
  registry:address: zookeeper://localhost:2181
  • 实现定义的接口(Service是apache.dubbo)
@ServicepublicclassHelloServiceImplimplementsHelloService{@OverridepublicStringsayHello(String name){return"Hello, "+ name +"!";}}
  • 启动类(@EnableDubbo)
@EnableDubbo@SpringBootApplicationpublicclassApplication{publicstaticvoidmain(String[] args){SpringApplication.run(Application.class, args);}}

Consumer

**

首先需要依赖Common

**

  • Controller(@Reference注解)
@RestControllerpublicclassHelloController{@ReferenceprivateHelloService helloService;@GetMapping("/hello/{name}")publicStringsayHello(@PathVariableString name){return helloService.sayHello(name);}}

Zookeeper

  • 安装脚本
#!/bin/bash#### 需要先装JDK ######## 需要先装JDK ######## 需要先装JDK ####cd /data/server;# 下载一个版本儿wget https://archive.apache.org/dist/zookeeper/zookeeper-3.4.14/zookeeper-3.4.14.tar.gz;# 创建目录mkdir-p /data/server/apache-zookeeper-3.4.14;# 解压到/usr/local下tar-zxvf zookeeper-3.4.14.tar.gz -C /data/server/;# 新增zk目录mkdir-p /data/server/zookeeper-3.4.14/data;mkdir-p /data/server/zookeeper-3.4.14/logs;# 新增PID文件 并 设置PIDtouch /data/server/zookeeper-3.4.14/data/myid;# PID,与MAP key相同echo1> /data/server/zookeeper-3.4.14/data/myid;# 复制默认配置,改为zoo.cfgcp /data/server/zookeeper-3.4.14/conf/zoo_sample.cfg /data/server/zookeeper-3.4.14/conf/zoo.cfg;# 修改核心配置zoo.cfg# 替换dataDir_old='/tmp/zookeeper';dataDir_url='/data/server/zookeeper-3.4.14/data';sed-ig"s#${dataDir_old}#${dataDir_url}#" /data/server/zookeeper-3.4.14/conf/zoo.cfg;# 写入dataLogDirdecho'dataLogDir=/data/server/zookeeper-3.4.14/logs'>> /data/server/zookeeper-3.4.14/conf/zoo.cfg;# 单节点,只需要写入单个即可declare-A map
map[1]="127.0.0.1"forkeyin${!map[@]};doecho"server."${key}"="${map[${key}]}":2888:3888">> /data/server/zookeeper-3.4.14/conf/zoo.cfg;done# 查看下配置cat /data/server/zookeeper-3.4.14/conf/zoo.cfg;# 启动# 不是root,需要source /etc/profile!!# 不是root,需要source /etc/profile!!# 不是root,需要source /etc/profile!!
/data/server/zookeeper-3.4.14/bin/zkServer.sh start

# 查看状态
/data/server/zookeeper-3.4.14/bin/zkServer.sh status
#### 显示下面内容就是启动成功了 #####ZooKeeper JMX enabled by default#Using config: /data/server/zookeeper-3.4.14/bin/../conf/zoo.cfg#Mode: standalone# 日志存储位置tail-100f /data/server/zookeeper-3.4.14/zookeeper.out
###### 问题###1. org.apache.zookeeper.server.admin.AdminServer$AdminServerException: Problem starting AdminServer on address 0.0.0.0, port 8080 and command URL /commands### 解决办法:https://www.jianshu.com/p/181a69836fe9

本文转载自: https://blog.csdn.net/Cy_LightBule/article/details/131788005
版权归原作者 弗兰克扬 所有, 如有侵权,请联系我们删除。

“Spring Boot Dubbo Zookeeper(含ZK安装脚本)”的评论:

还没有评论