首页
归档
留言
广告合作
友链
美女主播
Search
1
博瑞GE车机升级/降级
5,146 阅读
2
Mac打印机设置黑白打印
4,517 阅读
3
修改elementUI中el-table树形结构图标
4,516 阅读
4
Mac客户端添加腾讯企业邮箱方法
4,351 阅读
5
intelliJ Idea 2022.2.X破解
4,060 阅读
Java
HarmonyOS Next
Web前端
微信开发
开发辅助
App开发
数据库
随笔日记
登录
/
注册
Search
标签搜索
Spring Boot
Java
Spring Cloud
Mac
mybatis
WordPress
Nacos
Spring Cloud Alibaba
Mybatis-Plus
jQuery
Java Script
asp.net
微信小程序
Sentinel
UniApp
MySQL
asp.net core
IntelliJ IDEA
Jpa
树莓派
Laughing
累计撰写
570
篇文章
累计收到
1,424
条评论
首页
栏目
Java
HarmonyOS Next
Web前端
微信开发
开发辅助
App开发
数据库
随笔日记
页面
归档
留言
广告合作
友链
美女主播
搜索到
2
篇与
的结果
2021-07-20
使用docker部署dubbo/dubbox并实现服务提供者、消费者
实现目标基于centos 7,通过docker打包部署dubbox(2.8.4),并实现简单的服务提供者与消费者。前置条件服务器安装JDK1.8并正确配置环境变量开发环境安装JDK1.8并正确配置环境变量开发环境安装maven并正确配置环境变量(建议使用阿里云仓库)安装zookeeperZooKeeper 是 Apache 软件基金会的一个软件项目,它为大型分布式计算提供开源的分布式配置服务、同步服务和命名注册。下载压缩包下载压缩包curl -O https://www.apache.org/dyn/closer.lua/zookeeper/zookeeper-3.7.0/apache-zookeeper-3.7.0-bin.tar.gz解压压缩包tar -zxvf apache-zookeeper-3.7.0-bin.tar.gz修改zookeeper配置文件进入zookeeper配置文件所在目录cd /home/apache-zookeeper-3.7.0-bin/conf修改配置文件cp zoo_sample.cfg zoo.cfg运行zookeepercd /home/apache-zookeeper-3.7.0-bin/bin ./zkServer.sh start检查zookeeper运行状态cd /home/apache-zookeeper-3.7.0-bin/bin ./zkServer.sh statusdubbox打包Dubbox 是一个分布式服务框架,其前身是阿里巴巴开源项目Dubbo ,被国内电商及互联网项目中使用,后期阿里巴巴停止了该项目的维护,当当网便在Dubbo基础上进行优化,并继续维护,为了与原有的Dubbo区分,故将其命名为Dubbox。Dubbox 致力于提供高性能和透明化的RPC远程服务调用方案,以及SOA服务治理方案。简单的说,dubbox就是个服务框架,如果没有分布式的需求,其实是不需要用的,只有在分布式的时候,才有dubbox这样的分布式服务框架的需求,并且本质上是个服务调用的东东,说白了就是个远程服务调用的分布式框架。dubbox没有提供打包好的jar包或者war包,我们需要自己在github下载源码并编译。下载dubbox源码dubbox代码下载地址:https://github.com/dangdangdotcom/dubbox编译代码进入dubbox代码文件见,执行打包命令mvn install -D maven.test.skip=true打包完成后,在dubbo-admin\target中能看到一个dubbo-admin-2.8.4.war修改dubbox配置文件我们用压缩软件打开dubbo-admin-2.8.4.war,打开WEB-INF\dubbo.properties,修改zookeeper地址及对应用户密码,如下:dubbo.registry.address=zookeeper://IP地址:2181 dubbo.admin.root.password=root dubbo.admin.guest.password=guest[tag type="default"]注意修改成自己zookeeper对应的ip地址[/tag]war包修改完成后备用。安装docker我们通过docker部署dubbox。更新yumyum -y update安装依赖 yum install -y yum-utils device-mapper-persistent-data lvm2安装dockeryum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo yum install docker-ce-18.06.0.ce-3.el7启动docker并配置开机启动systemctl start docker systemctl enable docker配置docker为国内源vi /etc/docker/daemon.json输入以下内容{ "registry-mirrors": ["http://hub-mirror.c.163.com", "https://docker.mirrors.ustc.edu.cn"] }通过docker部署dubbox我们这里自己打包一个docker,并部署dubbox创建文件夹创建一个文件夹/home/makedocker,用于存储Dockerfile以及war包。mkdir /home/makedocker cd /home/makedocker将war包上传到/home/makedocker制作Dockerfilevi Dockerfile并输入以下内容FROM registry.cn-hangzhou.aliyuncs.com/shuodao/tomcat-8.5.27 MAINTAINER Laughing COPY dubbo.war /usr/tomcat/webapps/ EXPOSE 8080/tcp打包dockerdocker build -t tomcat-dubbo .启动dockerdocker run -d -p 8888:8080 --name tomcat-dubbo tomcat-dubbo查看docker运行状态docker ps显示以下内容,代表docker运行成功查看dubbox运行状态打开http://139.198.172.114:8888/dubbo,系统要求输入密码,密码为dubbo.properties中配置的密码,输入完成后,正常打开界面如下实现dubbox服务我们创建一个用户服务,作为服务提供者,判断用户是否登录。一个商品服务,作为服务消费者,调用用户是否登录的接口。实现通用服务接口创建一个maven项目,提供基本的接口定义。pom.xml内容如下<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>net.xiangcaowuyu</groupId> <artifactId>dubbo-common</artifactId> <version>1.0-SNAPSHOT</version> <properties> <maven.compiler.source>8</maven.compiler.source> <maven.compiler.target>8</maven.compiler.target> </properties> </project>创建接口package net.xiangcaowuyu.dubbo.common.service; /** * 博客:https://www.xiangcaowuyu.net * Description: * * @Author: 香草物语 * DateTime: 2021-07-19 20:20 */ public interface RpcUserService { boolean checkUserLogin(String userName); }将代码部署到本地maven仓库由于我们没有远程maven仓库,所以我们将jar包install到本地仓库。在代码根目录,执行以下命令,打包到本地仓库。mvn install -D maven.test.skip=true实现服务提供者创建服务提供者。pom.xml如下<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.5.2</version> <relativePath/> <!-- lookup parent from repository --> </parent> <groupId>net.xiangcaowuyu</groupId> <artifactId>dubbo-provider</artifactId> <version>0.0.1-SNAPSHOT</version> <name>dubbo-provider</name> <description>Demo project for Spring Boot</description> <properties> <java.version>1.8</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> </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> <scope>test</scope> </dependency> <dependency> <groupId>com.alibaba</groupId> <artifactId>dubbo</artifactId> <version>2.8.4</version> </dependency> <dependency> <groupId>io.dubbo.springboot</groupId> <artifactId>spring-boot-starter-dubbo</artifactId> <version>1.0.0</version> </dependency> <dependency> <groupId>net.xiangcaowuyu</groupId> <artifactId>dubbo-common</artifactId> <version>1.0-SNAPSHOT</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <includeSystemScope>true</includeSystemScope> <excludes> <exclude> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> </exclude> </excludes> </configuration> </plugin> </plugins> </build> </project>实现接口package net.xiangcaowuyu.dubboprovider.service; import net.xiangcaowuyu.dubbo.common.service.RpcUserService; import org.springframework.stereotype.Service; /** * 博客:https://www.xiangcaowuyu.net * Description: * * @Author: 香草物语 * DateTime: 2021-07-19 19:56 */ @Service @com.alibaba.dubbo.config.annotation.Service(interfaceClass = RpcUserService.class) public class RpcUserServiceImpl implements RpcUserService{ @Override public boolean checkUserLogin(String userName){ return "admin".equals(userName); } } 修改配置文件配置dubboserver.port=8081 #dubbo提供者的别名,只是个标识 spring.dubbo.application.name=dubbo-provider #zookeeper地址 spring.dubbo.registry.address=zookeeper://139.198.172.114:2181 #dubbo协议 spring.dubbo.protocol.name=dubbo #dubbo端口号 spring.dubbo.protocol.port=20880 #这是你要发布到dubbo的接口所在包位置 spring.dubbo.scan=net.xiangcaowuyu.dubboprovider.service测试运行项目,然后我们打开dubbo服务端,查看是否注册成功。实现服务消费者创建服务消费者。pom.xml如下<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.5.2</version> <relativePath/> <!-- lookup parent from repository --> </parent> <groupId>net.xiangcaowuyu</groupId> <artifactId>dubbo-provider</artifactId> <version>0.0.1-SNAPSHOT</version> <name>dubbo-provider</name> <description>Demo project for Spring Boot</description> <properties> <java.version>1.8</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> </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> <scope>test</scope> </dependency> <dependency> <groupId>com.alibaba</groupId> <artifactId>dubbo</artifactId> <version>2.8.4</version> </dependency> <dependency> <groupId>io.dubbo.springboot</groupId> <artifactId>spring-boot-starter-dubbo</artifactId> <version>1.0.0</version> </dependency> <dependency> <groupId>net.xiangcaowuyu</groupId> <artifactId>dubbo-common</artifactId> <version>1.0-SNAPSHOT</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <includeSystemScope>true</includeSystemScope> <excludes> <exclude> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> </exclude> </excludes> </configuration> </plugin> </plugins> </build> </project> 创建商品服务package net.xiangcaowuyu.dubboprovider.service; /** * 博客:https://www.xiangcaowuyu.net * Description: * * @Author: 香草物语 * DateTime: 2021-07-19 20:36 */ public interface GoodService { boolean checkUserLogin(String userName); }创建商品服务类,调用用户登录判断接口package net.xiangcaowuyu.dubboprovider.service.impl; import com.alibaba.dubbo.config.annotation.Reference; import net.xiangcaowuyu.dubbo.common.service.RpcUserService; import net.xiangcaowuyu.dubboprovider.service.GoodService; import org.springframework.stereotype.Service; /** * 博客:https://www.xiangcaowuyu.net * Description: * * @Author: 香草物语 * DateTime: 2021-07-19 19:56 */ @Service public class GoodServiceImpl implements GoodService { @Reference private RpcUserService rpcUserService; @Override public boolean checkUserLogin(String userName) { return rpcUserService.checkUserLogin(userName); } } 测试消费者服务是否正常注册测试创建商品销售接口package net.xiangcaowuyu.dubboprovider.controller; import net.xiangcaowuyu.dubboprovider.service.GoodService; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; /** * 博客:https://www.xiangcaowuyu.net * Description: * * @Author: 香草物语 * DateTime: 2021-07-19 20:40 */ @RestController public class GoodController { @Resource private GoodService goodService; @GetMapping("sell/good") public boolean sellGood(){ return goodService.checkUserLogin("admin"); } } 测试接口是否正常调用
2021年07月20日
934 阅读
0 评论
1 点赞
2021-05-17
linux zookeeper安装及使用
下载zookeeper从官网下载zookeeper上传并解压将tar.gz文件上传到服务器,执行以下命令解压tar -zxvf apache-zookeeper-3.7.0-bin.tar.gz修改配置文件进入apache-zookeeper-3.7.0-bin下的conf文件夹,将zoo_sample.cfg修改为zoo.cfg启动进入bin文件夹,执行以下命令./zkServer.sh start
2021年05月17日
967 阅读
0 评论
2 点赞