dubbo-Admin控制台+zookeeper环境搭建

  1. zookpeer搭建

    下载zookeeper-3.4.6,cd ./conf/   ,  cp   zoo_sample.cfg   zoo.cfg

    ./bin/zkServer.sh start 启动zookpeer服务

  2. dubboAdmain控制台搭建

    下载dubbo-admin.war,解压后放到tomcat的运行目录下,修改配置WEB-INF/dubbo.properties

    文件:

    dubbo.registry.address=zookeeper://192.168.1.201:2181,注意改成自己的地址
    dubbo.admin.root.password=root
    dubbo.admin.guest.password=guest

    这里,我们为一个应用发布两个提供者在不同的机器上,即使它们中有一台机器挂了,服务端也可以正常访问。

    package com.service;
    import java.util.List;

    /**
     * @描述 :
     * @创建者 : guoxiaopeng
     * @创建时间 : 2017-7-11 下午12:44:45
     */
    public interface DemoService {
        String sayHello(String name);  
        
        public List getUsers();  
    }

package com.service;

import java.util.ArrayList;
import java.util.List;

import com.domain.User;

/**
 * @描述 :
 * @创建者 : guoxiaopeng
 * @创建时间 : 2017-7-11 下午12:45:12
 */
public class DemoServiceImpl implements DemoService{
    public String sayHello(String name) {  
        return "Hello " + name;  
    }  
 
    public List getUsers() {  
        List list = new ArrayList();  
        User u1 = new User();  
        u1.setName("jack");  
        u1.setAge(20);  
        u1.setSex("m");  
 
        User u2 = new User();  
        u2.setName("tom");  
        u2.setAge(21);  
        u2.setSex("m");  
 
        User u3 = new User();  
        u3.setName("rose");  
        u3.setAge(19);  
        u3.setSex("w");  
 
        list.add(u1);  
        list.add(u2);  
        list.add(u3);  
        return list;  
    }  
}

import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * @描述 :
 * @创建者 : guoxiaopeng
 * @创建时间 : 2017-7-11 下午1:05:57
 */
public class Provider {

public static void main(String[] args) throws Exception {  
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(  
                new String[] { "spring-config.xml" });  
        context.start();  
        System.in.read(); // 为保证服务一直开着,利用输入流的阻塞来模拟  
    }  
}

pom.xml

<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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>provider1</groupId>
  <artifactId>dubbo-provider1</artifactId>
  <packaging>war</packaging>
  <version>0.0.1-SNAPSHOT</version>
  <name>dubbo-provider1 Maven Webapp</name>
  <url>http://maven.apache.org</url>
  <properties>
        <spring.version>3.0.5.RELEASE</spring.version>
  </properties>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
    <!-- spring start -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aop</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-beans</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-orm</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-tx</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.opensymphony.quartz</groupId>
            <artifactId>quartz</artifactId>
            <version>1.6.1</version>
        </dependency>
        <dependency>
            <groupId>javax.transaction</groupId>
            <artifactId>jta</artifactId>
            <version>1.1</version>
        </dependency>
        <!-- spring end -->
        
        <!--         dubbo start -->
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>dubbo</artifactId>
            <version>2.5.3</version>  
            <exclusions>
                <exclusion>
                    <groupId>org.springframework</groupId>
                    <artifactId>spring</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <!--         dubbo end -->
        
        <!--         zookeeper  start -->
        <dependency>  
            <groupId>com.github.sgroschupf</groupId>  
            <artifactId>zkclient</artifactId>  
            <version>0.1</version>  
        </dependency>
        <!--         zookeeper  end -->
  </dependencies>
  <build>
    <finalName>dubbo-provider1</finalName>
  </build>
</project>

spring-config.xml

<?xml version="1.0" encoding="UTF-8"?>
<!-- <beans xmlns="http://www.springframework.org/schema/beans"   -->
<!--     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"   -->
<!--     xsi:schemaLocation="http://www.springframework.org/schema/beans   -->
<!--         http://www.springframework.org/schema/beans/spring-beans.xsd   -->
<!--         http://code.alibabatech.com/schema/dubbo   -->
<!--         http://code.alibabatech.com/schema/dubbo/dubbo.xsd   -->
<!--         ">   -->

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
    xsi:schemaLocation="http://www.springframework.org/schema/beans        http://www.springframework.org/schema/beans/spring-beans.xsd        http://code.alibabatech.com/schema/dubbo        http://code.alibabatech.com/schema/dubbo/dubbo.xsd"
    default-autowire="byName">
 
    <!-- 提供方应用信息,用于计算依赖关系 -->  
    <dubbo:application name="demo_provider" />  
 
    <!-- 使用zookeeper注册中心暴露服务地址 -->  
    <dubbo:registry address="zookeeper://192.168.1.201:2181" timeout="50" />  
<!--     <dubbo:registry address="zookeeper://192.168.1.26:2181" timeout="50" />   -->
 
    <!-- 用dubbo协议在20880端口暴露服务 -->  
    <dubbo:protocol name="dubbo" port="20880"   />  
 
    <!-- 声明需要暴露的服务接口 -->  
    <dubbo:service interface="com.service.DemoService"  
        ref="demoService" />  
          
          
    <!-- 具体的实现bean,用来注入-->  
    <bean id="demoService" class="com.service.DemoServiceImpl" />  
 
</beans>

spring-config-rpc.xml

<?xml version="1.0" encoding="UTF-8"?>
<!-- <beans xmlns="http://www.springframework.org/schema/beans"   -->
<!--     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"   -->
<!--     xsi:schemaLocation="http://www.springframework.org/schema/beans   -->
<!--         http://www.springframework.org/schema/beans/spring-beans.xsd   -->
<!--         http://code.alibabatech.com/schema/dubbo   -->
<!--         http://code.alibabatech.com/schema/dubbo/dubbo.xsd   -->
<!--         ">   -->

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
    xsi:schemaLocation="http://www.springframework.org/schema/beans        http://www.springframework.org/schema/beans/spring-beans.xsd        http://code.alibabatech.com/schema/dubbo        http://code.alibabatech.com/schema/dubbo/dubbo.xsd"
    default-autowire="byName">
 
    <!-- 提供方应用信息,用于计算依赖关系 -->  
    <dubbo:application name="demo_provider" />  
 
    <!-- 使用zookeeper注册中心暴露服务地址 -->  
    <dubbo:registry address="zookeeper://192.168.1.201:2181" timeout="50" />  
<!--     <dubbo:registry address="zookeeper://192.168.1.26:2181" timeout="50" />   -->
 
    <!-- 用dubbo协议在20880端口暴露服务 -->  
    <dubbo:protocol name="dubbo" port="20880"   />  
 
    <!-- 声明需要暴露的服务接口 -->  
    <dubbo:service interface="com.service.DemoService"  
        ref="demoService" />  
          
          
    <!-- 具体的实现bean,用来注入-->  
    <bean id="demoService" class="com.service.DemoServiceImpl" />  
 
</beans>

生成者项目层级结构

服务端代码:

ClientTest.java

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.service.DemoService;

/**
 * @描述 :
 * @创建者 : guoxiaopeng
 * @创建时间 : 2017-7-12 上午11:26:27
 */
public class ClientTest {

public static void main(String[] args) {
        ApplicationContext app=new ClassPathXmlApplicationContext("spring-config.xml");
        DemoService demoService= (DemoService) app.getBean("demoService");
        String sayHello = demoService.sayHello("hello");
        System.out.println(sayHello);
    }
}

spring-config-rpc.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
    xsi:schemaLocation="http://www.springframework.org/schema/beans        http://www.springframework.org/schema/beans/spring-beans.xsd        http://code.alibabatech.com/schema/dubbo        http://code.alibabatech.com/schema/dubbo/dubbo.xsd"
    default-autowire="byName">
 
  <dubbo:application name="dubbo_consumer"></dubbo:application>  
 
 
 
   <!--zookeeper注册中心 -->  
   <dubbo:registry address="zookeeper://192.168.1.201:2181" timeout="50" />  
<!--    <dubbo:registry address="zookeeper://192.168.1.26:2181" timeout="50" />   -->
     <!-- 要引用的服务 -->    
    <dubbo:reference interface="com.service.DemoService" id="demoService" />
</beans>

spring-config.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 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/context http://www.springframework.org/schema/context/spring-context.xsd"
    default-autowire="byName">
    
    <!-- 注解传播形式 -->
       <import resource="spring/spring-config-rpc.xml" />
</beans>

pom.xml

<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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>consumer</groupId>
  <artifactId>dubbo-consumer</artifactId>
  <packaging>war</packaging>
  <version>0.0.1-SNAPSHOT</version>
  <name>dubbo-consumer Maven Webapp</name>
  <url>http://maven.apache.org</url>
   <properties>
        <spring.version>3.0.5.RELEASE</spring.version>
  </properties>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
    <!-- spring start -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aop</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-beans</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-orm</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-tx</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.opensymphony.quartz</groupId>
            <artifactId>quartz</artifactId>
            <version>1.6.1</version>
        </dependency>
        <dependency>
            <groupId>javax.transaction</groupId>
            <artifactId>jta</artifactId>
            <version>1.1</version>
        </dependency>
        <!-- spring end -->
        
        <!--         dubbo start -->
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>dubbo</artifactId>
            <version>2.5.3</version>  
            <exclusions>
                <exclusion>
                    <groupId>org.springframework</groupId>
                    <artifactId>spring</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <!--         dubbo end -->
        
        <!--         zookeeper  start -->
        <dependency>  
            <groupId>com.github.sgroschupf</groupId>  
            <artifactId>zkclient</artifactId>  
            <version>0.1</version>  
        </dependency>
        <!--         zookeeper  end -->
         <!--     提供者接口  start -->
        <dependency>
            <groupId>myDubbo</groupId>
            <artifactId>myDubbo</artifactId>
            <version>0.0.2</version>
        </dependency>
        <!--     提供者接口  end -->
  </dependencies>
  <build>
    <finalName>dubbo-consumer</finalName>
  </build>
</project>

浏览器访问地址:http://127.0.0.1:8080/dubboAdmin/

提供者和服务端

时间: 2024-10-24 01:29:31

dubbo-Admin控制台+zookeeper环境搭建的相关文章

Zookeeper环境搭建

Zookeeper环境搭建 下载 从镜像站中下载最近版本 http://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/ 从文档站中下载所有的历史版本 https://archive.apache.org/dist/zookeeper/ apache-zookeeper-3.5.5-bin.tar.gz 2019-05-20 18:40 10M zookeeper-3.4.6.tar.gz 2016-01-10 17:11 17M 参考文档 https

Zookeeper 环境搭建

Zookeeper 环境搭建 1.上传文件并解压 2.修改环境变量 更新配置文件 3.修改 zk 的配置文件 vim /usr/local/zookeeper/conf/zoo.cfg 主要修改数据文件的地址 4.设置 Path 否则不能直接使用命令 5.启动 zk zkServer.sh start //启动zk zkServer.sh status //查看状态 6.客户端连接 zkCli.sh //连接 客户端启动程序来建立一个会话 客户端尝试连接到 localhost/127.0.0.1

hadoop2.6.2+hbase+zookeeper环境搭建

1.hadoop环境搭建,版本:2.6.2,参考:http://www.cnblogs.com/bookwed/p/5251393.html 启动服务:在master机器上,进入hadoop安装目录,执行命令:./sbin/start-all.sh 查看是否启动成功:jps 2.zookeeper环境搭建,版本:3.4.6,参考:http://www.cnblogs.com/bookwed/p/4599829.html 启动服务:分别在三台机器上,进入zookeeper安装目录,执行命令:./b

Mysql + canal + zookeeper环境搭建

Mysql + canal + zookeeper环境搭建 一.mysql集群搭建 1. mysql基本环境 操作系统: Linux version 2.6.32-431.el6.x86_64 数据库:MySQL Community Server 5.7.20 主节点IP:10.60.81.157 主节点IP:10.60.81.158 从节点IP:10.60.81.159 2. 安装mysql 2.1.官网下载MySQL mysql-5.7.20-1.el6.x86_64.rpm-bundle.

ZooKeeper环境搭建(单机/集群)(转)

前提: 配置文件主要是在$ZOOKEEPER_HOME/conf/zoo.cfg,刚解压时为zoo_sample.cfg,重命名zoo.cfg即可. 配置文件常用项参考:http://www.cnblogs.com/EasonJim/p/7483880.html 环境搭建: 一.ZooKeeper的搭建方式 ZooKeeper安装方式有三种,单机模式和集群模式以及伪集群模式. 单机模式:ZooKeeper只运行在一台服务器上,适合测试环境: 伪集群模式:就是在一台物理机上运行多个ZooKeepe

Hadoop学习笔记—14.ZooKeeper环境搭建

从字面上来看,ZooKeeper表示动物园管理员,这是一个十分奇妙的名字,我们又想起了Hadoop生态系统中,许多项目的Logo都采用了动物,比如Hadoop采用了大象的形象,所以我们可以猜测ZooKeep就是对这些动物进行一些管理工作的. 一.ZooKeeper基础介绍 1.1 动物园也要保障安全 zookeeper是hadoop下面的一个子项目,用来协调跟hadoop相关的一些分布式的框架,如hadoop, hive, pig等, 其实他们都是动物,所以叫zookeeper ——“动物园管理

Dubbo源码学习--环境搭建及基础准备(ServiceLoader、ExtensionLoader)

环境搭建 1. Github上下载 "Dubbo最新发布版本" ,楼主下载版本为2.5.7. 2. cd到源码解压目录,maven编译,命令为: 3. 生成Intellij idea相关配置文件,命令为: 4. 双击运行生成的 文件 Java SPI SPI是Service Provider Int http://p.baidu.com/itopic/main/qlog?qid=ae116162633263383961612700&type=questionlog http:/

Linux系统zookeeper环境搭建(单机、伪分布式、分布式)

本人现在对zookeeper的环境搭建做一个总结,一般zookeeper的安装部署可以有三种模式,单机模式.伪分布式和分布式,这三种模式在什么时候应用具体看大家的使用场景,如果你只有一台机器且只是想自己开发测试时用,你可以安装个单机模式,简单又实用.如果想装逼但又没有足够的机器,那你可以选择伪分布式的方式搭建,这可以满足你内心高大上的分布式需求又可以满足没有机器的屌丝现状.如果手头有三台以上的服务器,那就可以大展高富帅的风采,直接上真的分布式,真的分布式部署一般是在系统的正式环境中应用.下面我来

【Zookeeper】3.Zookeeper环境搭建1

之前我们讲解了Zookeeper的基本概念,下面我们来动手搭建Zookeeper的环境. 我们主要在本机上模拟集群环境,使用虚拟机,所以在开始搭建之前,我们要准备以下环境:(1)Vmware虚拟机(2)Linux操作系统:ubuntu16.4(3)SecureCRT(连接虚拟机) 步骤1.使用vmware创建三个ubuntu16.4的虚拟机我们要提前去下载虚拟机的系统安装文件,这里我使用的安装文件为:ubuntu-16.04-desktop-amd64.iso下面仅演示一个虚拟机的安装过程,一共