【练手】ansible搭建zookeeper

资料文末下载

搭建zookeeper集群 附带安装tree与jdkdevel工具

创建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直接下载

【练手】ansible搭建zookeeper

 

上一篇:UVA 11464 - Even Parity 状态压缩,分析 难度: 2


下一篇:centos7通过rpm-bundle方式安装mysql5.7.35