ZooKeeper安装使用

栏目: 编程工具 · 发布时间: 6年前

内容简介:相信大家对ZooKeeper应该不算陌生,ZooKeeper的使用和ZooKeeper集群的搭建并不复杂,这里分享自己看到的一些好文章以及使用Ansible快速部署和手动部署ZooKeeper的经验分享。ZooKeeper分布式环境的协调利器2018年09月27日 - 初稿

相信大家对ZooKeeper应该不算陌生,ZooKeeper的使用和ZooKeeper集群的搭建并不复杂,这里分享自己看到的一些好文章以及使用Ansible快速部署和手动部署ZooKeeper的经验分享。

ZooKeeper分布式环境的协调利器

更新历史

2018年09月27日 - 初稿

阅读原文 - https://wsgzao.github.io/post/zookeeper/

扩展阅读

ZooKeeper - https://zookeeper.apache.org/

ZooKeeper简介

ZooKeeper is a centralized service for maintaining configuration information, naming, providing distributed synchronization, and providing group services. All of these kinds of services are used in some form or another by distributed applications. Each time they are implemented there is a lot of work that goes into fixing the bugs and race conditions that are inevitable. Because of the difficulty of implementing these kinds of services, applications initially usually skimp on them ,which make them brittle in the presence of change and difficult to manage. Even when done correctly, different implementations of these services lead to management complexity when the applications are deployed.

ZooKeeper是一个开源的为分布式应用提供分布式协调的服务。它公开了一组简单的原语,分布式应用程序可以基于这些原语实现更高级别的服务,包括同步、维护配置、组和命名。它的设计易于编程,它使用一个遵循文件系统中常见的目录树结构的数据模型。它在 Java 环境中运行,对Java和C都有绑定。

协调服务是出了名的难。它们特别容易出错,如竞态条件和死锁。ZooKeeper背后的动机是让分布式应用从零开始实现一站式协调服务。

可能是全网把 ZooKeeper 概念讲的最清楚的一篇文章

https://github.com/Snailclimb/JavaGuide/blob/master/%E4%B8%BB%E6%B5%81%E6%A1%86%E6%9E%B6/ZooKeeper.md

jdk

install jdk by ansible

https://galaxy.ansible.com/geerlingguy/java

# download
ansible-galaxy install geerlingguy.java
# create yaml file and config java version
vi install_jdk.yml

---
- hosts: all
  roles:
    - role: geerlingguy.java
      when: "ansible_os_family == 'RedHat'"
      java_packages:
        - java-1.8.0-openjdk

install jdk manually

http://www.oracle.com/technetwork/java/javase/downloads/index.html

# yum
yum install java-1.8.0-openjdk
# rpm
yum localinstall -y jdk-8u181-linux-x64.rpm
# set env
vi /etc/profile

export JAVA_HOME=/usr/java/jdk1.8.0_181
export CLASSPATH=$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib 
export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH:$HOME/bin 

source /etc/profile

zookeeper

install zookeeper by ansible

https://galaxy.ansible.com/ansibleshipyard/ansible-zookeeper

# download
ansible-galaxy install AnsibleShipyard.ansible-zookeeper
# create yaml file and config java version
vi install_zookeeper.yml

---
- name: Installing ZooKeeper
  hosts: all
  sudo: yes
  vars:
    zookeeper_version: 3.4.12
  roles:
    - role: AnsibleShipyard.ansible-zookeeper

install zookeeper manually

# install jdk
yum -y install java-1.8.0-openjdk
# download and install zookeeper
tar -zxvf zookeeper-3.4.12.tar.gz —C /opt/
cd /opt/zookeeper-3.4.12
# create zoo.cfg
cd /opt/zookeeper-3.4.12/conf
cp zoo_sample.cfg zoo.cfg
vi zoo.cfg

tickTime=2000
dataDir=/var/lib/zookeeper
dataLogDir=/var/log/zookeeper
clientPort=2181
initLimit=5
syncLimit=2
maxClientCnxns=60

server.1=zoo1:2888:3888
server.2=zoo2:2888:3888
server.3=zoo3:2888:3888

# create directory
mkdir /var/lib/zookeeper
mkdir /var/log/zookeeper
# create myid file
cd /var/lib/zookeeper/

echo 1 > myid
echo 2 > myid
echo 3 > myid

# start
cd /opt/zookeeper-3.4.12/bin
./zkServer.sh start
# check
./zkServer.sh status
# create znode
./zkCli.sh -server 127.0.0.1:2181
create /codis codis
ls /

Zookeeper Configuration

Platform: RHEL / CentOS 7

Java: Oracle JDK

Variables

zookeeper_version: 3.4.12
zookeeper_group: zookeeper
zookeeper_user: zookeeper
zookeeper_dir: /opt/zookeeper-{{zookeeper_version}} # or /usr/share/zookeeper
zookeeper_conf_dir: {{zookeeper_dir}} # or /etc/zookeeper
zookeeper_tarball_dir: /opt/src
data_dir: /var/lib/zookeeper
log_dir: /var/log/zookeeper
zookeeper_client_port: 2181
zookeeper_id: 1
zookeeper_leader_port: 2888
zookeeper_election_port: 3888
Default Ports
Port Description
2181 Client connection port
2888 Quorum port for clustering
3888 Leader election port for clustering
conf/zoo.cfg
tickTime=2000
dataDir=/var/lib/zookeeper
clientPort=2181
initLimit=5
syncLimit=2
server.1=zoo1:2888:3888
server.2=zoo2:2888:3888
server.3=zoo3:2888:3888

tickTime

the basic time unit in milliseconds used by ZooKeeper. It is used to do heartbeats and the minimum session timeout will be twice the tickTime.

dataDir

the location to store the in-memory database snapshots and, unless specified otherwise, the transaction log of updates to the database.

clientPort

the port to listen for client connections

initLimit

is timeouts ZooKeeper uses to limit the length of time the ZooKeeper servers in quorum have to connect to a leader.

syncLimit

limits how far out of date a server can be from a leader.

In this example, the timeout for initLimit is 5 ticks at 2000 milleseconds a tick, or 10 seconds.


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

赢在用户

赢在用户

[美]Steve Mulder、[美]Zivv Yarr / 范晓燕 / 机械工业出版社 / 2007-08-01 / 29.00

您如何保证您的网站确实给予用户他们所需要的,并对您产生商业成果?您需要了解谁是您的用户,您的用户的目标、行为和观点是什么,还要把他们的需求当成您的第一要务。人物角色将用户研究带入了一个更高的境界,成为实施真正以用户为中心的在线商业策略最高效的工具。本书将伴随您走过创建人物角色的每一个步骤,包括进行定性、定量的用户研究,生成人物角色分类,使人物角色真实可信等。您也将学会如何有效地通过这个工具,来完成......一起来看看 《赢在用户》 这本书的介绍吧!

MD5 加密
MD5 加密

MD5 加密工具

HEX HSV 转换工具
HEX HSV 转换工具

HEX HSV 互换工具

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具