博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Docker创建的集群下使用ansible部署zookeeper
阅读量:6606 次
发布时间:2019-06-24

本文共 6500 字,大约阅读时间需要 21 分钟。

使用文章“Docker创建的集群下使用ansible部署hadoop”中创建的集群进行zookeeper的安装

OS hostname IP
Centos7 cluster-master 172.18.0.2
Centos7 cluster-slave1 172.18.0.3
Centos7 cluster-slave1 172.18.0.4
Centos7 cluster-slave1 172.18.0.5

在cluster-master上制作zookeeper安装包

下载

官方源下载显得十分缓慢,所以还是选择国内的镜像源,将zookeeper下载到/opt

[root@cluster-master opt]# wget https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/stable/zookeeper-3.4.10.tar.gz

创建链接

下载完成后将zookeeper-3.4.10.tar.gz解压并创建链接,方便管理

[root@cluster-master opt]# tar -zxvf zookeeper-3.4.10.tar.gz[root@cluster-master opt]# ln -s zookeeper-3.4.10 zookeeper

修改配置文件

/opt/zookeeper/conf中已经提供了zoo_sample.cfg配置模板,复制一份zoo.cfg进行修改即可使用,我的配置项如下:

[root@cluster-master conf]# cp zoo_sample.cfg zoo.cfg
[root@cluster-master conf]# vi zoo.cfg

# The number of milliseconds of each ticktickTime=2000# The number of ticks that the initial# synchronization phase can takeinitLimit=10# The number of ticks that can pass between# sending a request and getting an acknowledgementsyncLimit=5# the directory where the snapshot is stored.# do not use /tmp for storage, /tmp here is just# example sakes.dataDir=/home/zookeeper/data# the port at which the clients will connectclientPort=2181# the maximum number of client connections.# increase this if you need to handle more clients#maxClientCnxns=60## Be sure to read the maintenance section of the# administrator guide before turning on autopurge.## http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance## The number of snapshots to retain in dataDir#autopurge.snapRetainCount=3# Purge task interval in hours# Set to "0" to disable auto purge feature#autopurge.purgeInterval=1server.2=172.18.0.2:2888:3888server.3=172.18.0.3:2888:3888server.4=172.18.0.4:2888:3888server.5=172.18.0.5:2888:3888

dataDir做了从新定义,server项使用IP的最后一位,也是为了方便管理

创建shell脚本,完成安装步骤

在/opt/zookeeper下新建postinstall.sh创建dataDir目录和myid文件,并写入zoo.cfg中定义的myid值

vi /opt/zookeeper/postinstall.sh#!/bin/bash# zookeeper conf fileconf_file="/opt/zookeeper/conf/zoo.cfg"# get myidIP=$(/sbin/ifconfig -a|grep inet|grep -v 127.0.0.1|grep -v inet6 |\     awk '{print $2}')ID=$(grep ${IP} ${conf_file}|cut -d \= -f 1|cut -d \. -f 2)# get dataDirdataDir=$(grep dataDir ${conf_file}|grep -v '^#'|cut -d \= -f 2)# create dataDir and myid filemkdir -p ${dataDir}:>${dataDir}/myidecho ${ID} > ${dataDir}/myid

打包配置完成后的zookeeper,准备上传至slave主机

将链接zookeeper和目录zookeeper-3.4.10打包并压缩

[root@cluster-master opt]# tar -zcvf zookeeper-dis.tar.gz zookeeper zookeeper-3.4.10

创建yaml,安装zookeeper

[root@cluster-master opt]# vi install-zookeeper.yaml
---- hosts: slaves  tasks:    - name: install ifconfig      yum: name=net-tools state=latest    - name: unarchive zookeeper      unarchive: src=/opt/zookeeper-dis.tar.gz dest=/opt    - name: postinstall      shell: bash /opt/zookeeper/postinstall.sh

分发安装文件到slave主机

[root@cluster-master opt]# ansible-playbook install-zookeeper.yaml

启动zookeeper

此时,zookeeper集群已经可以正常启动

[root@cluster-master opt]# ansible cluster -m command -a "/opt/zookeeper/bin/zkServer.sh start"

查看状态

[root@cluster-master bin]# ./zkServer.sh statusZooKeeper JMX enabled by defaultUsing config: /opt/zookeeper/bin/../conf/zoo.cfgMode: follower

运行客户端

[root@cluster-master bin]# ./zkCli.sh -server localhost:2181Connecting to localhost:21812017-08-29 18:05:36,078 [myid:] - INFO  [main:Environment@100] - Client environment:zookeeper.version=3.4.10-39d3a4f269333c922ed3db283be479f9deacaa0f, built on 03/23/2017 10:13 GMT2017-08-29 18:05:36,091 [myid:] - INFO  [main:Environment@100] - Client environment:host.name=cluster-master2017-08-29 18:05:36,091 [myid:] - INFO  [main:Environment@100] - Client environment:java.version=1.8.0_1412017-08-29 18:05:36,098 [myid:] - INFO  [main:Environment@100] - Client environment:java.vendor=Oracle Corporation2017-08-29 18:05:36,098 [myid:] - INFO  [main:Environment@100] - Client environment:java.home=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.141-1.b16.el7_3.x86_64/jre2017-08-29 18:05:36,098 [myid:] - INFO  [main:Environment@100] - Client environment:java.class.path=/opt/zookeeper/bin/../build/classes:/opt/zookeeper/bin/../build/lib/*.jar:/opt/zookeeper/bin/../lib/slf4j-log4j12-1.6.1.jar:/opt/zookeeper/bin/../lib/slf4j-api-1.6.1.jar:/opt/zookeeper/bin/../lib/netty-3.10.5.Final.jar:/opt/zookeeper/bin/../lib/log4j-1.2.16.jar:/opt/zookeeper/bin/../lib/jline-0.9.94.jar:/opt/zookeeper/bin/../zookeeper-3.4.10.jar:/opt/zookeeper/bin/../src/java/lib/*.jar:/opt/zookeeper/bin/../conf:2017-08-29 18:05:36,099 [myid:] - INFO  [main:Environment@100] - Client environment:java.library.path=/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib2017-08-29 18:05:36,100 [myid:] - INFO  [main:Environment@100] - Client environment:java.io.tmpdir=/tmp2017-08-29 18:05:36,100 [myid:] - INFO  [main:Environment@100] - Client environment:java.compiler=
2017-08-29 18:05:36,100 [myid:] - INFO [main:Environment@100] - Client environment:os.name=Linux2017-08-29 18:05:36,100 [myid:] - INFO [main:Environment@100] - Client environment:os.arch=amd642017-08-29 18:05:36,100 [myid:] - INFO [main:Environment@100] - Client environment:os.version=3.10.0-514.26.2.el7.x86_642017-08-29 18:05:36,101 [myid:] - INFO [main:Environment@100] - Client environment:user.name=root2017-08-29 18:05:36,101 [myid:] - INFO [main:Environment@100] - Client environment:user.home=/root2017-08-29 18:05:36,101 [myid:] - INFO [main:Environment@100] - Client environment:user.dir=/opt/zookeeper-3.4.10/bin2017-08-29 18:05:36,124 [myid:] - INFO [main:ZooKeeper@438] - Initiating client connection, connectString=localhost:2181 sessionTimeout=30000 watcher=org.apache.zookeeper.ZooKeeperMain$MyWatcher@25f38edc2017-08-29 18:05:36,205 [myid:] - INFO [main-SendThread(localhost:2181):ClientCnxn$SendThread@1032] - Opening socket connection to server localhost/127.0.0.1:2181. Will not attempt to authenticate using SASL (unknown error)Welcome to ZooKeeper!JLine support is enabled2017-08-29 18:05:36,730 [myid:] - INFO [main-SendThread(localhost:2181):ClientCnxn$SendThread@876] - Socket connection established to localhost/127.0.0.1:2181, initiating session2017-08-29 18:05:36,795 [myid:] - INFO [main-SendThread(localhost:2181):ClientCnxn$SendThread@1299] - Session establishment complete on server localhost/127.0.0.1:2181, sessionid = 0x25e2f22aa660001, negotiated timeout = 30000WATCHER::WatchedEvent state:SyncConnected type:None path:null[zk: localhost:2181(CONNECTED) 0] ls /[zookeeper][zk: localhost:2181(CONNECTED) 1]

总结

使用到了之前创建的集群和ansible,发现使用ansible部署应用确实很方便。

转载地址:http://cfbso.baihongyu.com/

你可能感兴趣的文章
C#单例模式
查看>>
Bitmap处理之创建可自动回收资源的ImageView
查看>>
用户自定义函数的数据库设计(DEMO)
查看>>
ERP框架序设计与开发日记(下)
查看>>
通过分析内存来优化.NET程序
查看>>
java基础之输入语句
查看>>
谈工程师的价值和发展
查看>>
Win8 + Hyper-V 虚拟机性能简测与虚拟化技术科普(三)
查看>>
Github-Client(ANDROID)开源之旅(二) ------ 浅析ActionBarSherkLock
查看>>
jsp showModalDialog父子窗口传值
查看>>
Android之布局属性归纳
查看>>
PreferenceActivity使用示例
查看>>
Ubuntu12.04下eclipse提示框黑色背景色的修改方法
查看>>
我的web框架
查看>>
Activity四种启动模式之singleTask应用
查看>>
Android ADB server didn't ACK * failed to start daemon * 简单有效的解决方案
查看>>
时间格式化
查看>>
mysql报错"ERROR 1206 (HY000): The total number of locks exceeds the lock table size"的解决方法...
查看>>
chrome浏览器开发者工具使用教程[转]
查看>>
matlab运行过程中出现找不到指定模块问题解决
查看>>