•用户多
•流量大,并发高
•海量数据
•易受攻击
•功能繁琐
•变更快
•高性能:提供快速的访问体验。
•高可用:网站服务一直可以正常访问。
•可伸缩:通过硬件增加/减少,提高/降低处理能力。
•高可扩展:系统间耦合低,方便的通过新增/移除方式,增加/减少新的功能/模块。
•安全性:提供网站安全访问和数据加密,安全存储等策略。
•敏捷性:随需应变,快速响应。
很多“人”一起 ,干一样的事。
一个业务模块,部署在多台服务器上。
很多“人”一起,干不一样的事。这些不一样的事,合起来是一件大事。
一个大的业务系统,拆分为小的业务模块,分别部署在不同的机器上
单体架构

集群
集群分布式







Dubbo是高性能、轻量级的javaRPC框架





节点角色说明:
1、环境准备
ZooKeeper服务器是用Java创建的,它运行在JVM之上。需要安装JDK 7或更高版本。
2、上传
将下载的ZooKeeper放到/opt/ZooKeeper目录下
#上传zookeeper alt+p
put f:/setup/apache-zookeeper-3.5.6-bin.tar.gz
#打开 opt目录
cd /opt
#创建zooKeeper目录
mkdir zooKeeper
#将zookeeper安装包移动到 /opt/zooKeeper
mv apache-zookeeper-3.5.6-bin.tar.gz /opt/zookeeper/
3、解压
将tar包解压到/opt/zookeeper目录下
tar -zxvf apache-ZooKeeper-3.5.6-bin.tar.gz

1、配置zoo.cfg
进入到conf目录拷贝一个zoo_sample.cfg并完成配置
#进入到conf目录
cd /opt/zooKeeper/apache-zooKeeper-3.5.6-bin/conf/
#拷贝
cp zoo_sample.cfg zoo.cfg
修改zoo.cfg
vim zoo.cfg
#打开目录
cd /opt/zooKeeper/
#创建zooKeeper存储目录
mkdir zkdata
#修改zoo.cfg
vim /opt/zooKeeper/apache-zooKeeper-3.5.6-bin/conf/zoo.cfg
修改存储目录:dataDir=/opt/zookeeper/zkdata

2、启动ZooKeeper

cd /opt/zooKeeper/apache-zooKeeper-3.5.6-bin/bin/
#启动
./zkServer.sh start

看到上图表示ZooKeeper成功启动
3、查看ZooKeeper状态
./zkServer.sh status
zookeeper启动成功。standalone代表zk没有搭建集群,现在是单节点


<properties>
<spring.version>5.1.9.RELEASEspring.version>
<dubbo.version>2.7.4.1dubbo.version>
<zookeeper.version>4.0.0zookeeper.version>
properties>
<dependencies>
<dependency>
<groupId>javax.servletgroupId>
<artifactId>javax.servlet-apiartifactId>
<version>3.1.0version>
<scope>providedscope>
dependency>
<dependency>
<groupId>org.springframeworkgroupId>
<artifactId>spring-contextartifactId>
<version>${spring.version}version>
dependency>
<dependency>
<groupId>org.springframeworkgroupId>
<artifactId>spring-webmvcartifactId>
<version>${spring.version}version>
dependency>
<dependency>
<groupId>org.slf4jgroupId>
<artifactId>slf4j-apiartifactId>
<version>1.7.21version>
dependency>
<dependency>
<groupId>org.slf4jgroupId>
<artifactId>slf4j-log4j12artifactId>
<version>1.7.21version>
dependency>
<dependency>
<groupId>org.apache.dubbogroupId>
<artifactId>dubboartifactId>
<version>${dubbo.version}version>
dependency>
<dependency>
<groupId>org.apache.curatorgroupId>
<artifactId>curator-frameworkartifactId>
<version>${zookeeper.version}version>
dependency>
<dependency>
<groupId>org.apache.curatorgroupId>
<artifactId>curator-recipesartifactId>
<version>${zookeeper.version}version>
dependency>
dependencies>
package com.jq.service.iml;
import com.jq.service.UserService;
import org.springframework.stereotype.Service;
@Service
public class UserServiceImpl implements UserService {
public String sayHello() {
return "hello Dubbo!";
}
}
<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.0modelVersion>
<groupId>com.jqgroupId>
<artifactId>dubbo-webartifactId>
<version>1.0-SNAPSHOTversion>
<packaging>warpackaging>
<properties>
<spring.version>5.1.9.RELEASEspring.version>
<dubbo.version>2.7.4.1dubbo.version>
<zookeeper.version>4.0.0zookeeper.version>
properties>
<dependencies>
<dependency>
<groupId>com.jqgroupId>
<artifactId>dubbo-serviceartifactId>
<version>1.0-SNAPSHOTversion>
dependency>
<dependency>
<groupId>javax.servletgroupId>
<artifactId>javax.servlet-apiartifactId>
<version>3.1.0version>
<scope>providedscope>
dependency>
<dependency>
<groupId>org.springframeworkgroupId>
<artifactId>spring-contextartifactId>
<version>${spring.version}version>
dependency>
<dependency>
<groupId>org.springframeworkgroupId>
<artifactId>spring-webmvcartifactId>
<version>${spring.version}version>
dependency>
<dependency>
<groupId>org.slf4jgroupId>
<artifactId>slf4j-apiartifactId>
<version>1.7.21version>
dependency>
<dependency>
<groupId>org.slf4jgroupId>
<artifactId>slf4j-log4j12artifactId>
<version>1.7.21version>
dependency>
<dependency>
<groupId>org.apache.dubbogroupId>
<artifactId>dubboartifactId>
<version>${dubbo.version}version>
dependency>
<dependency>
<groupId>org.apache.curatorgroupId>
<artifactId>curator-frameworkartifactId>
<version>${zookeeper.version}version>
dependency>
<dependency>
<groupId>org.apache.curatorgroupId>
<artifactId>curator-recipesartifactId>
<version>${zookeeper.version}version>
dependency>
dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.tomcat.mavengroupId>
<artifactId>tomcat7-maven-pluginartifactId>
<version>2.1version>
<configuration>
<port>8089port>
<path>/path>
configuration>
plugin>
plugins>
build>
project>
package com.jq.controller;
import com.jq.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/user")
public class UserController {
@Autowired
private UserService userService;
@RequestMapping("/sayHello")
public String sayHello(){
return userService.sayHello();
}
}
启动


import org.apache.dubbo.config.annotation.Service;
@Service //将这个类提供的方法(服务)对外发布,将访问的IP,端口,路径注册到注册中心
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dubbo="http://dubbo.apache.org/schema/dubbo" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd">
<dubbo:application name="dubbo-service"/>
<dubbo:registry address="zookeeper:/192.168.56.10:2181"/>
<dubbo:annotation package="com.jq.service.iml"/>
beans>
删除pom依赖
删除webxml spring的
package com.jq.controller;
import com.jq.service.UserService;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/user")
public class UserController {
//@Autowired 本地注入
/**
* @Reference
* 1.从zookeeper注册中心中获取userService的访问url
* 2.进行远程调用RPC
* 3.将结果封装为一个代理对象,给变量赋值
*/
@Reference //远程注入
private UserService userService;
@RequestMapping("/sayHello")
public String sayHello(){
return userService.sayHello();
}
}
配置
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dubbo="http://dubbo.apache.org/schema/dubbo"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd">
<mvc:annotation-driven/>
<context:component-scan base-package="com.jq.controller"/>
<dubbo:application name="dubbo-web"/>
<dubbo:registry address="zookeeper://192.168.56.10:2181"/>
<dubbo:annotation package="com.jq.controller"/>
beans>


创建公共模块,删除web,service的UserService接口
package com.jq.service;
public interface UserService {
public String sayHello();
}

1、环境准备
dubbo-admin 是一个前后端分离的项目。前端使用vue,后端使用springboot,安装 dubbo-admin 其实就是部署该项目。我们将dubbo-admin安装到开发环境上。要保证开发环境有jdk,maven,nodejs
安装node**(如果当前机器已经安装请忽略)**
因为前端工程是用vue开发的,所以需要安装node.js,node.js中自带了npm,后面我们会通过npm启动
下载地址
https://nodejs.org/en/
2、下载 Dubbo-Admin
建议下载最新版本的Dubbo-Admin,否则会出现各种bug
进入github,搜索dubbo-admin
https://github.com/apache/dubbo-admin
3、把下载的zip包解压到指定文件夹(解压到那个文件夹随意)
4、修改配置文件
解压后我们进入…\dubbo-admin-develop\dubbo-admin-server\src\main\resources目录,找到 application.properties 配置文件 进行配置修改
修改zookeeper地址
# centers in dubbo2.7
admin.registry.address=zookeeper://192.168.149.135:2181
admin.config-center=zookeeper://192.168.149.135:2181
admin.metadata-report.address=zookeeper://192.168.149.135:2181
admin.registry.address注册中心
admin.config-center 配置中心
admin.metadata-report.address元数据中心
5、打包项目
在 dubbo-admin-develop 目录执行打包命令
mvn clean package

6、启动后端
切换到目录
dubbo-Admin-develop\dubbo-admin-distribution\target>
执行下面的命令启动 dubbo-admin,dubbo-admin后台由SpringBoot构建。
java -jar .\dubbo-admin-0.5.jar
7、前台后端
dubbo-admin-ui 目录下执行命令
npm run dev
8、访问
浏览器输入。用户名密码都是root
http://localhost:8081/
注意:Dubbo Admin【服务Mock】【服务统计】将在后续版本发布…
在上面的步骤中,我们已经进入了Dubbo-Admin的主界面,在【快速入门】章节中,我们定义了服务生产者、和服务消费者,下面我们从Dubbo-Admin管理界面找到这个两个服务
1、点击服务查询
2、查询结果
A:输入的查询条件com.itheima.service.UserService
B:搜索类型,主要分为【按服务名】【按IP地址】【按应用】三种类型查询
C:搜索结果
3.1.4 dubo-admin查看详情
我们查看com.itheima.service.UserService (服务提供者)的具体详细信息,包含【元数据信息】
1)点击详情
从【详情】界面查看,主要分为3个区域
A区域:主要包含服务端 基础信息比如服务名称、应用名称等
B区域:主要包含了生产者、消费者一些基本信息
C区域:是元数据信息,注意看上面的图,元数据信息是空的
我们需要打开我们的生产者配置文件加入下面配置
<dubbo:metadata-report address="zookeeper://192.168.149.135:2181" />
重新启动生产者,再次打开Dubbo-Admin
这样我们的元数据信息就出来了


服务地址缓存到本地


可以在服务提供方(建议),消费方加注解
timeout = 3000
在这里插入代码片package com.itheima.service.impl;
import com.itheima.pojo.User;
import com.itheima.service.UserService;
import org.apache.dubbo.config.annotation.Service;
//@Service//将该类的对象创建出来,放到Spring的IOC容器中 bean定义
@Service(timeout = 3000)//将这个类提供的方法(服务)对外发布。将访问的地址 ip,端口,路径注册到注册中心中
public class UserServiceImpl implements UserService {
public String sayHello() {
return "hello dubbo hello!~";
}
public User findUserById(int id) {
//查询User对象
User user = new User(1,"zhangsan","123");
return user;
}
}

retries = 3
package com.itheima.service.impl;
import com.itheima.pojo.User;
import com.itheima.service.UserService;
import org.apache.dubbo.config.annotation.Service;
//@Service//将该类的对象创建出来,放到Spring的IOC容器中 bean定义
@Service(timeout = 3000,retries = 3)//将这个类提供的方法(服务)对外发布。将访问的地址 ip,端口,路径注册到注册中心中
public class UserServiceImpl implements UserService {
public String sayHello() {
return "hello dubbo hello!~";
}
public User findUserById(int id) {
//查询User对象
User user = new User(1,"zhangsan","123");
return user;
}
}


@Service(timeout = 3000,retries = 3,version = "v1.0")
package com.itheima.service.impl;
import com.itheima.pojo.User;
import com.itheima.service.UserService;
import org.apache.dubbo.config.annotation.Service;
//@Service//将该类的对象创建出来,放到Spring的IOC容器中 bean定义
@Service(timeout = 3000,retries = 3,version = "v1.0")//将这个类提供的方法(服务)对外发布。将访问的地址 ip,端口,路径注册到注册中心中
public class UserServiceImpl implements UserService {
public String sayHello() {
return "hello dubbo hello!~";
}
public User findUserById(int id) {
//查询User对象
User user = new User(1,"zhangsan","123");
return user;
}
}

@Service(timeout = 3000,retries = 3,version = "v1.0",weight = 100)
package com.itheima.service.impl;
import com.itheima.pojo.User;
import com.itheima.service.UserService;
import org.apache.dubbo.config.annotation.Service;
//@Service//将该类的对象创建出来,放到Spring的IOC容器中 bean定义
@Service(timeout = 3000,retries = 3,version = "v1.0",weight = 100)//将这个类提供的方法(服务)对外发布。将访问的地址 ip,端口,路径注册到注册中心中
public class UserServiceImpl2 implements UserService {
public String sayHello() {
return "hello dubbo hello!~";
}
public User findUserById(int id) {
//查询User对象
User user = new User(1,"zhangsan","123");
return user;
}
}
@Reference(loadbalance = "random")//远程注入
private UserService userService;
package com.itheima.controller;
import com.itheima.pojo.User;
import com.itheima.service.UserService;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/user")
public class UserController {
//注入Service
//@Autowired//本地注入
/*
1. 从zookeeper注册中心获取userService的访问url
2. 进行远程调用RPC
3. 将结果封装为一个代理对象。给变量赋值
*/
@Reference(loadbalance = "random")//远程注入
private UserService userService;
@RequestMapping("/sayHello")
public String sayHello(){
return userService.sayHello();
}
/**
* 根据id查询用户信息
* @param id
* @return
*/
@RequestMapping("/find")
public User find(int id){
return userService.findUserById(id);
}
}

服务提供者
@Reference(loadbalance = "random",cluster ="failover")//远程注入
private UserService userService;
package com.itheima.controller;
import com.itheima.pojo.User;
import com.itheima.service.UserService;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/user")
public class UserController {
//注入Service
//@Autowired//本地注入
/*
1. 从zookeeper注册中心获取userService的访问url
2. 进行远程调用RPC
3. 将结果封装为一个代理对象。给变量赋值
*/
@Reference(loadbalance = "random",cluster ="failover")//远程注入
private UserService userService;
@RequestMapping("/sayHello")
public String sayHello(){
return userService.sayHello();
}
/**
* 根据id查询用户信息
* @param id
* @return
*/
@RequestMapping("/find")
public User find(int id){
return userService.findUserById(id);
}
}
不太重要的服务关掉

@Reference(loadbalance = "random",cluster ="failover",mock = "force:return null")//远程注入
private UserService userService;
package com.itheima.controller;
import com.itheima.pojo.User;
import com.itheima.service.UserService;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/user")
public class UserController {
//注入Service
//@Autowired//本地注入
/*
1. 从zookeeper注册中心获取userService的访问url
2. 进行远程调用RPC
3. 将结果封装为一个代理对象。给变量赋值
*/
@Reference(loadbalance = "random",cluster ="failover",mock = "force:return null")//远程注入
private UserService userService;
@RequestMapping("/sayHello")
public String sayHello(){
return userService.sayHello();
}
/**
* 根据id查询用户信息
* @param id
* @return
*/
@RequestMapping("/find")
public User find(int id){
return userService.findUserById(id);
}
}