Ansible搭建zookeeper

资料文末下载

搭建zookeeper集群 附带安装treejdkdevel工具

创建roles目录 ,图下

zookeeper

├── files

   └── zookeeper-3.4.5.tar.gz

├── templates

   └── zoo.cfg.j2

├── vars

   └── main.yml

└── zookeeper.yml

 

 zookeeper.yml

- hosts: zookeeper

  remote_user: root

  roles:

  - zookeeper

  tasks:

    - name: jps tool install

      yum: name={{item}} state=present

      with_items:

        - java-1.8.0-openjdk-devel.x86_64

        - tree

    - name: mkdir directory for bigdata data

      file: dest={{BigdataDir}} mode=0755 state=directory

    - name: install zookeeper

      unarchive: src={{AnsibleDir}}/zookeeper/files/{{zookeeper_file_name}}.tar.gz dest={{BigdataDir}}

    - name: install configuration file for zookeeper

      template: src={{AnsibleDir}}/zookeeper/templates/zoo.cfg.j2 dest={{BigdataDir}}/{{zookeeper_file_name}}/conf/zoo.cfg

    - name: create log\data  directory

      file: dest={{BigdataDir}}/zookeeper/dataLogDir mode=0755 state=directory

      file: dest={{BigdataDir}}/zookeeper/data  mode=0755 state=directory

    - name: add myid file

      shell: echo {{ myid }} > {{BigdataDir}}/zookeeper/data/myid

    - name: start zookeeper

      shell:  sh {{BigdataDir}}/{{zookeeper_file_name}}/bin/zkServer.sh start

      tags:

      - start zookeeper

Var main.yml

zk1: 192.168.193.57

zk2: 192.168.193.58

zk3: 192.168.193.59

BigdataDir: /opt/hzgc

AnsibleDir: /etc/ansible/roles

zookeeper_file_name: zookeeper-3.4.5

 templates zoo.cfg.j2

tickTime=2000

initLimit=10

syncLimit=5

clientPort=2181

dataLogDir={{BigdataDir}}/zookeeper/dataLogDir

dataDir={{BigdataDir}}/zookeeper/data

clientPort=2181

quorumListenOnAllIPs=true

server.1={{zk1}}:2888:3888

server.2={{zk2}}:2888:3888

server.3={{zk3}}:2888:3888

执行任务 ansible-playbook -i /etc/ansible/hosts zookeeper.yml  

执行输出

PLAY [zookeeper] ********************************************************************************************************************************

 

TASK [Gathering Facts] **************************************************************************************************************************

ok: [node2]

ok: [node3]

ok: [node1]

 

TASK [jps tool install] *************************************************************************************************************************

ok: [node3] => (item=[u'java-1.8.0-openjdk-devel.x86_64', u'tree'])

ok: [node1] => (item=[u'java-1.8.0-openjdk-devel.x86_64', u'tree'])

ok: [node2] => (item=[u'java-1.8.0-openjdk-devel.x86_64', u'tree'])

 

TASK [mkdir directory for bigdata data] *********************************************************************************************************

ok: [node1]

ok: [node3]

ok: [node2]

 

TASK [install zookeeper] ************************************************************************************************************************

ok: [node1]

ok: [node2]

ok: [node3]

 

TASK [install configuration file for zookeeper] *************************************************************************************************

ok: [node1]

ok: [node3]

ok: [node2]

 

TASK [create log\data  directory] ***************************************************************************************************************

changed: [node1]

changed: [node2]

changed: [node3]

 

TASK [add myid file] ****************************************************************************************************************************

changed: [node2]

changed: [node1]

changed: [node3]

 

TASK [start zookeeper] **************************************************************************************************************************

changed: [node1]

changed: [node2]

changed: [node3]

 

PLAY RECAP **************************************************************************************************************************************

node1                      : ok=8    changed=3    unreachable=0    failed=0   

node2                      : ok=8    changed=3    unreachable=0    failed=0   

node3                      : ok=8    changed=3    unreachable=0    failed=0  

 

验证:目标服务器 jps 验证即可。

可参于https://github.com/nhz94259/Ansible/tree/master/zookeeper直接下载

 

转载于:https://www.cnblogs.com/nhz-M/p/10718043.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值