Linux Centos7 环境基于Docker部署Zookeeper服务搭建实战
配置Zookeeper安装目录
在宿主机配置zookeeper安装目录:/docker/develop/zookeeper
并且在文件夹创建 data 和logs 目录:
mkdir -p /docker/develop/zookeeper/data
mkdir -p /docker/develop/zookeeper/logs
[root@centos-knight ~]# cd /docker/develop/zookeeper
[root@centos-knight zookeeper]# mkdir -p /docker/develop/zookeeper/data
[root@centos-knight zookeeper]# mkdir -p /docker/develop/zookeeper/logs
授权文件目录:chmod -R 777 /docker/develop/zookeeper/
[root@centos-knight zookeeper]# chmod -R 777 /docker/develop/zookeeper/
[root@centos-knight zookeeper]#
安装和部署Zookeeper
拉取zookeeper镜像:docker pull zookeeper
[root@centos-knight zookeeper]# docker pull zookeeper
Using default tag: latest
latest: Pulling from library/zookeeper
Digest: sha256:6b6b5f7fb6a47d2b311df5af1718af5a425a679dbb844d77913fa68d1a8bf0fd
Status: Image is up to date for zookeeper:latest
docker.io/library/zookeeper:latest
[root@centos-knight zookeeper]#
临时安装Zookeeper服务:zookeeper-tmp-server
docker run -itd -p 2181:2181 --restart always --name=zookeeper-tmp-server --privileged=true \
-v /docker/develop/zookeeper/data:/data \
-v /docker/develop/zookeeper/datalog:/datalog \
-v /docker/develop/zookeeper/logs:/logs \
-e "ZOO_STANDALONE_ENABLED=true" \
-e "TZ=Asia/Shanghai" \
-e "ZOO_4LW_COMMANDS_WHITELIST=*" \
-e "ZOO_AUTOPURGE_SNAPRETAINCOUNT=5" \
-e "ZOO_AUTOPURGE_PURGEINTERVAL=24" \
-e "ZOO_MAX_CLIENT_CNXNS=64" \
-e "ZOO_TICK_TIME=2000" \
-e "ZOO_INIT_LIMIT=100" \
-e "ZOO_SYNC_LIMIT=5" \
zookeeper:latest
复制zookeeper-tmp-server的conf到/docker/develop/zookeeper:
[root@centos-knight ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
12947bdadd84 zookeeper:latest "/docker-entrypoint.…" 36 hours ago Up 36 hours 2888/tcp, 3888/tcp, 0.0.0.0:2181->2181/tcp, 8080/tcp zookeeper-develop-server
[root@centos-knight ~]# docker cp 12947bdadd84:/conf /docker/develop/zookeeper/
编写zookeeper的zoo.cfg配置文件:
tickTime=2000
initLimit=100
syncLimit=5
dataDir=/data
dataLogDir=/datalog
clientPort=2181
quorumListenOnAllIPs=true
preAllocSize=64M
globalOutstandingLimit=100000
snapCount=50000
maxClientCnxns=64
minSessionTimeout=4000
maxSessionTimeout=40000
4lw.commands.whitelist=*
standaloneEnabled=true
admin.enableServer=true
server.1=0.0.0.0:2888:3888
tcpKeepAlive=true
ipReachableTimeout=0
cnxTimeout=3
electionAlg=3
autopurge.snapRetainCount=5
autopurge.purgeInterval=24
#忽略ACL验证
skipACL=yes
forceSync=yes
fsync.warningthresholdms=50
编写正式安装Dcoekr命令:
docker run -itd -p 2181:2181 -p 2888:2888 -p 3888:3888 --restart always --name=zookeeper-develop-server --privileged=true \
-v /docker/develop/zookeeper/conf/zoo.cfg:/conf/zoo.cfg \
-v /docker/develop/zookeeper/data:/data \
-v /docker/develop/zookeeper/logs:/datalog \
-e "TZ=Asia/Shanghai" \
-e "JAVA_OPTS=-server -Xms512m -Xmx512m -Xmn256m -Duser.home=/opt -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m -XX:+AlwaysPreTouch -XX:-UseBiasedLocking" \
zookeeper:latest
部署Dubbo客户端
部署安装dubbo-admin:
docker run -itd --restart always --privileged=true --name dubbo-devleop-ops -p 8083:8080 -e admin.registry.address="zookeeper://IP:2181" -e admin.config-center="zookeeper://IP:2181" -e admin.metadata-report.address="zookeeper://IP:2181" -e "JAVA_OPTS=-server -Xms512m -Xmx512m -Xmn256m -Duser.home=/opt -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m -XX:+AlwaysPreTouch -XX:-UseBiasedLocking" -e TZ="Asia/Shanghai" apache/dubbo-admin:latest
基于Springboot整合和使用Dubbo+Zookeeper
创建工程:pivotal-cloud-dependencies [统一管理工程版本依赖资源]
一般都是使用Maven作为构建工具,这里便只需在pom.xml中添加如下依赖即可:
在标签定义依赖版本号:
<!--spring-boot dubbo setting -->
<dubbo.version>2.7.3</dubbo.version>
<spring-boot-dubbo.version>2.7.3</spring-boot-dubbo.version>
<!--spring-boot zookeeper setting -->
<zookeeper.version>3.5.6</zookeeper.version>
<curator.version>4.2.0</curator.version>
在标签添加如下内容:
<!--spring-boot dubbo setting begin-->
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo</artifactId>
<version>${dubbo.version}</version>
<exclusions>
<!--exclusion spring-->
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
</exclusion>
<!--exclusion servlet-api-->
<exclusion>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
</exclusion>
<!--exclusion log4j-->
<exclusion>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</exclusion>
<!--exclusion netty-->
<exclusion>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-spring-boot-starter</artifactId>
<version>${spring-boot-dubbo.version}</version>
<exclusions>
<!--exclusion dubbo-->
<exclusion>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-metadata-report-zookeeper</artifactId>
<version>${dubbo.version}</version>
<exclusions>
<!--exclusion dubbo-common-->
<exclusion>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-common</artifactId>
</exclusion>
<!--exclusion dubbo-remoting-zookeeper-->
<exclusion>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-remoting-zookeeper</artifactId>
</exclusion>
</exclusions>
</dependency>
<!--spring-boot dubbo setting end-->
<!--spring-boot zookeeper setting begin-->
<dependency>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
<version>${zookeeper.version}</version>
<exclusions>
<!--exclusion log4j-->
<exclusion>
<artifactId>log4j</artifactId>
<groupId>log4j</groupId>
</exclusion>
<!--exclusion slf4j-api-->
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
<!--exclusion slf4j-log4j12-->
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-framework</artifactId>
<version>${curator.version}</version>
<exclusions>
<!--exclusion curator-client-->
<exclusion>
<groupId>org.apache.curator</groupId>
<artifactId>curator-client</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-recipes</artifactId>
<version>${curator.version}</version>
<exclusions>
<!--exclusion curator-framework-->
<exclusion>
<groupId>org.apache.curator</groupId>
<artifactId>curator-framework</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-client</artifactId>
<version>${curator.version}</version>
<exclusions>
<!--exclusion curator-framework-->
<exclusion>
<groupId>org.apache.curator</groupId>
<artifactId>curator-framework</artifactId>
</exclusion>
<!--exclusion zookeeper-->
<exclusion>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
</exclusion>
</exclusions>
</dependency>
<!--spring-boot zookeeper setting end-->
ps[注意事项]:
1.使用pivotal-cloud-dependencies的意义,可以排除多余和重复依赖,解决依赖冲突等具有指导和参考的作用
2.对于升级和改造可以灵活切换,统一管理版本号等
创建工程:pivotal-dubbo-integration
与Dubbo相关的依赖:
<!--spring-boot dubbo setting begin-->
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo</artifactId>
<version>${dubbo.version}</version>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-spring-boot-starter</artifactId>
<version>${spring-boot-dubbo.version}</version>
</dependency>
<!--spring-boot dubbo setting end-->
与Zookeeper相关的依赖:
<!--spring-boot zookeeper setting begin-->
<dependency>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
<version>${zookeeper.version}</version>
</dependency>
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-framework</artifactId>
<version>${curator.version}</version>
</dependency>
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-recipes</artifactId>
<version>${curator.version}</version>
</dependency>
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-client</artifactId>
<version>${curator.version}</version>
</dependency>
<!--spring-boot zookeeper setting end-->
然后运行打包构建命令:mvn clean install 将工程打成一个jar,然后在工程需要使用Dubbo作为Provider和Consumer 的工程模块中依赖此内部整合工程:
<!--pivotal dubbo setting begin -->
<dependency>
<groupId>com.mark.apple</groupId>
<artifactId>pivotal-dubbo-integration</artifactId>
version>${project.version}</version>
</dependency>
<!--pivotal dubbo setting end-->
ps[注意事项]:
1.使用pivotal-dubbo-integration的意义,可以自定义封装Dubbo相关特殊场景下的自定义模块[自定义Dubbo序列化等],以及Dubbo性能调优等
2.可以整合以及其他框架,譬如[Dubbo网关以及Dubbo指标监控等]
最后在Provider和Consumer的工程配置相关属性:
Provider 相关属性配置:
#####################################################
#########Springboot Dubbo Provider Setting##########
#####################################################
pivotal.zookeeper.server-address=zookeeper://IP:2181
dubbo.metadata-report.address=${pivotal.zookeeper.server-address}
dubbo.application.id=${spring.application.name}-${spring.profiles.active}
dubbo.application.name=${spring.application.name}-${spring.profiles.active}
dubbo.application.registry=${spring.application.name}-${spring.profiles.active}
dubbo.application.organization=com.mark.apple
dubbo.application.architecture=${dubbo.application.name}
dubbo.application.environment=${spring.profiles.active}
dubbo.application.logger=slf4j
dubbo.config.override=true
dubbo.config.multiple=true
#dubbo file upload length
# ProtocolConfig Bean
dubbo.protocol.id=dubbo
dubbo.protocol.name=dubbo
#dubbo.protocol.status=client
dubbo.protocol.payload=2147483647
dubbo.protocol.buffer=8192
dubbo.protocol.register=true
dubbo.protocol.server=netty
dubbo.protocol.transporter=netty
dubbo.protocol.threadpool=cached
dubbo.protocol.threads=200
dubbo.protocol.iothreads=2
dubbo.protocol.dispatcher=all
#RegistryConfig Bean
dubbo.registry.address=${pivotal.zookeeper.server-address}
# ProtocolConfig Bean
dubbo.protocol.id=dubbo
dubbo.protocol.name=dubbo
dubbo.protocol.port=28080
dubbo.protocol.status=server
dubbo.protocol.payload=2147483647
dubbo.protocol.buffer=8192
dubbo.protocol.register=true
dubbo.protocol.server=netty
dubbo.protocol.transporter=netty
dubbo.protocol.threadpool=cached
dubbo.protocol.threads=200
dubbo.protocol.dispatcher=all
dubbo.protocol.accepts=1000
#Dubbo Provider setting
dubbo.provider.accepts=0
dubbo.protocol.iothreads=2
dubbo.provider.threads=200
dubbo.provider.threadpool=cached
dubbo.provider.executes=0
dubbo.provider.validation=true
dubbo.provider.connections=0
dubbo.provider.actives=0
dubbo.provider.buffer=8192
dubbo.provider.retries=3
dubbo.provider.delay=-1
dubbo.provider.timeout=360000
#Dubbo Consumer setting
dubbo.consumer.lazy=true
dubbo.consumer.connections=0
dubbo.consumer.actives=0
dubbo.consumer.retries=3
dubbo.consumer.timeout=360000
dubbo.consumer.validation=true
dubbo.consumer.check=true
dubbo.consumer.loadbalance=consistenthash
#Base packages to scan Dubbo Components (e.g @Service , @Reference)
dubbo.scan.base-packages=com.pivotal.authority.server.impl
Consumer相关属性配置:
#####################################################
#########Springboot Dubbo Consumer Setting##########
#####################################################
pivotal.zookeeper.server-address=zookeeper://IP:2181
dubbo.metadata-report.address=${pivotal.zookeeper.server-address}
# Dubbo Config properties
dubbo.application.id=${spring.application.name}-${spring.profiles.active}
dubbo.application.name=${spring.application.name}-${spring.profiles.active}
dubbo.application.registry=${spring.application.name}-${spring.profiles.active}
dubbo.application.organization=com.mark.apple
dubbo.application.architecture=${dubbo.application.name}
dubbo.application.environment=${spring.profiles.active}
dubbo.application.logger=slf4j
dubbo.config.override=true
dubbo.config.multiple=true
# ProtocolConfig Bean
dubbo.protocol.id=dubbo
dubbo.protocol.name=dubbo
dubbo.protocol.status=client
dubbo.protocol.payload=2147483647
dubbo.protocol.buffer=8192
dubbo.protocol.register=true
dubbo.protocol.server=netty
dubbo.protocol.transporter=netty
dubbo.protocol.threadpool=cached
dubbo.protocol.threads=200
dubbo.protocol.iothreads=2
dubbo.protocol.dispatcher=all
#RegistryConfig Bean
dubbo.registry.id=${dubbo.application.name}
dubbo.registry.protocol=dubbo
dubbo.registry.check=true
dubbo.registry.address=${pivotal.zookeeper.server-address}
#Dubbo Consumer setting
dubbo.consumer.lazy=true
dubbo.consumer.connections=0
dubbo.consumer.actives=0
dubbo.consumer.retries=3
dubbo.consumer.validation=true
dubbo.consumer.check=true
dubbo.consumer.loadbalance=consistenthash
版权声明:本文为博主原创文章,遵循相关版权协议,如若转载或者分享请附上原文出处链接和链接来源。
Linux Centos7 环境基于Docker部署Zookeeper服务搭建实战的更多相关文章
- Linux系统 Centos7 环境基于Docker部署Rocketmq服务
消息队列 基本概述 MQ,Message Queue,基于TCP协议构建的简单协议,区别于具体的通信协议. 基于通信协议定义和抽象的更高层次的通信模型,一般都是生产者和消费者模型,又或者说服务端和客户 ...
- 在 CentOS7 上部署 zookeeper 服务
在 CentOS7 上部署 zookeeper 服务 1 用 SecureCRT 或 XShell 等 Linux 客户端工具连接至 CentOS7 服务器: 2 进入到 /usr/local/too ...
- 基于 Docker 的微服务架构实践
本文来自作者 未闻 在 GitChat 分享的{基于 Docker 的微服务架构实践} 前言 基于 Docker 的容器技术是在2015年的时候开始接触的,两年多的时间,作为一名 Docker 的 D ...
- 在生产环境使用Docker部署应用
导读 Docker现在越来越流行,但是真正在生产环境部署Docker还是个比较新的概念,还没有一个标准的流程.作者是ROR的程序员,作者结合平时的部署经验,联系Docker的特点,向大家分享了其在生产 ...
- 云端基于Docker的微服务与持续交付实践
云端基于Docker的微服务与持续交付实践笔记,是基于易立老师在阿里巴巴首届在线技术峰会上<云端基于Docker的微服务与持续交付实践>总结而出的. 本次主要讲了什么? Docker Sw ...
- [置顶]
Docker学习总结(7)——云端基于Docker的微服务与持续交付实践
本文根据[2016 全球运维大会•深圳站]现场演讲嘉宾分享内容整理而成 讲师简介 易立 毕业于北京大学,获得学士学位和硕士学位:目前负责阿里云容器技术相关的产品的研发工作. 加入阿里之前,曾在IBM中 ...
- 基于Docker的Consul服务发现集群搭建
在去年的.NET Core微服务系列文章中,初步学习了一下Consul服务发现,总结了两篇文章.本次基于Docker部署的方式,以一个Demo示例来搭建一个Consul的示例集群,最后给出一个HA的架 ...
- linux centos7环境下安装apache2.4+php5.6+mysql5.6 安装及踩坑集锦(二)
linux centos7环境下安装apache2.4+php5.6+mysql5.6 安装及踩坑集锦(二) 安装apache web容器 . yum方式安装apache 注意apache在linux ...
- Linux centos7环境下安装MySQL的步骤详解
Linux centos7环境下安装MySQL的步骤详解 安装MySQL mysql 有两个跟windows不同的地方 1).my.ini 保存到/etc/my.ini 2).用户权限,单独用户执行 ...
随机推荐
- linux环境变量设置和默认执行语句设置
环境变量设置 1.export export ORACLE_HOME=/usr/local/instantclient_12_2export PATH=$ORACLE_HOME:$PATHexport ...
- 数组工具类 Day07
package com.sxt.arraytest2; /* * 数组的工具类 */ import java.util.Arrays; public class TestArrays { public ...
- maven修改版本号
1.修改版本 mvn versions:set -DnewVersion=xxx 2.回滚版本,提交后不能回滚 mvn versions:revert 3.提交版本变更 mvn versions:co ...
- Javascript 严格模式下不允许删除一个不允许删除的属性
如下代码,在严格模式下,如果删除 Object.prototype 浏览器会报错,目前 IE10 也支持 严格模式. <script> "use strict"; de ...
- mapping数据列表
- 【转载】字符编码笔记:ASCII,Unicode和UTF-8
字符编码笔记:ASCII,Unicode和UTF-8 作者: 阮一峰 今天中午,我突然想搞清楚Unicode和UTF-8之间的关系,于是就开始在网上查资料. 结果,这个问题比我想象的复杂,从午饭后一直 ...
- python selenium处理iframe和弹框(一)
处理iframe和弹框 # encoding:utf-8 from selenium import webdriver import time driver = webdriver.Firefox() ...
- sublime 插件安装packagecontrol
https://packagecontrol.io/installation 第一步: Installation Simple The simplest method of installation ...
- 2019-9-2-C#枚举中使用Flags特性
title author date CreateTime categories C#枚举中使用Flags特性 lindexi 2019-09-02 12:57:37 +0800 2018-2-13 1 ...
- phpStudy本地环境测试,打开网页很慢的解决办法!
很多人应该都遇到了在使用phpStudy本地环境测试软件时候打开很慢的问题,甚至动辄达到了1000ms以上,开篇直接给出解决办法: 下面给大家介绍phpstudy访问速度慢的解决办法. 1.修改mys ...