docker安装zookeeper & IDEA服务注册进zookeeper

一、docker安装zookeeper

1.在docker中安装zookeeper

docker pull zookeeper

docker安装zookeeper & IDEA服务注册进zookeeper_第1张图片

 2.查看zookeeper是否安装成功

docker images

docker安装zookeeper & IDEA服务注册进zookeeper_第2张图片

 3.运行zookeeper镜像

docker run -d -p 2181:2181 --name some-zookeeper zookeeper

4.查看是否成功运行

docker ps 

 5.启动zookeeper

docker exec -it f229e81e13bd bash
./bin/zkCli.sh

docker安装zookeeper & IDEA服务注册进zookeeper_第3张图片

*先不要关闭centos系统,后续IDEA服务注册zookeeper还需要用到,放着不动就可以了

二、 IDEA服务注册进zookeeper

 1.新建好maven项目后改pom文件



    
        springcloud
        org.example
        1.0-SNAPSHOT
    
    4.0.0

    cloud-provider-payment8004

    
        
            org.springframework.cloud
            spring-cloud-starter-zookeeper-discovery
        
        
            org.example
            cloud-api-commons
            ${project.version}
        
        
            org.springframework.boot
            spring-boot-starter-web
        
        
            org.springframework.boot
            spring-boot-starter-actuator
        
        
            org.mybatis.spring.boot 
            mybatis-spring-boot-starter
        
        
            com.alibaba
            druid-spring-boot-starter
            1.1.10
        
        
            mysql
            mysql-connector-java
        
        
            org.springframework.boot
            spring-boot-starter-jdbc
        
        
            org.springframework.boot
            spring-boot-devtools
            runtime
            true
        
        
            org.projectlombok
            lombok
            true
        
        
            org.springframework.boot
            spring-boot-starter-test
        
    

2.修改yml文件(数据库的配置信息不重要)

server:
  port: 端口号

spring:
  application:
    name: cloud-provider-payment
  cloud:
    zookeeper:
      connect-string: 服务器地址:端口号
  datasource:
    type: com.alibaba.druid.pool.DruidDataSource
    username: 数据库用户名
    password: 密码
    driver-class-name: org.gjt.mm.mysql.Driver
    url: 数据库url

3.设置启动类

package com.lpy.springcloud;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;

@SpringBootApplication
@EnableDiscoveryClient
public class PaymentMain8004 {
    public static void main(String[] args) {
        SpringApplication.run(PaymentMain8004.class,args);
    }
}

4. 启动项目docker安装zookeeper & IDEA服务注册进zookeeper_第4张图片

 5.查看服务是否注册成功进入zookeeper(再次打开centos服务器)

ls /
ls /services 

 可以发现,已经成功注册进入zookeeper中,服务名称为cloud-provider-payment。

docker安装zookeeper & IDEA服务注册进zookeeper_第5张图片

你可能感兴趣的:(spring,java,zookeeper,docker)