码迷,mamicode.com
首页 > 其他好文 > 详细

ansible 安装zk集群playbook

时间:2019-06-05 11:22:11      阅读:85      评论:0      收藏:0      [点我收藏+]

标签:enabled   files   验证   name   yml   角色   get   无法   line   

准备zk需要的zoo.cfg 和 myid 文件
[root@10.0.0.11 root]# cd templates/kafka/
[root@10.0.0.11 root]# ls
myid1 myid2 myid3 zoo.cfg

1.编辑主角色文件
vim install-zk.yml

---
- hosts: ‘{{ target }}‘
  vars:
      host1: 10.0.0.11
      host2: 10.0.0.12
      host3: 10.0.0.13
  tasks:
    - include: tasks/install-zk.yml

2.编辑tasks文件
vim tasks/install-zk.yml

---
- name: copy zookeeper-3.4.12.tar.gz
copy: src=files/kafka/zookeeper-3.4.12.tar.gz dest=/opt/

- name: tar zookeeper-3.4.12.tar.gz
shell: tar xf /opt/zookeeper-3.4.12.tar.gz -C /opt/
- name: mv zookeeper
shell: mv -f /opt/zookeeper-3.4.12 /opt/zookeeper

- name: chenge zk-zoo.cfg,kafka-server.properties
template: "src={{ item.src }} dest={{ item.dest }} mode=0644"
with_items:
- { src: ‘kafka/zoo.cfg‘,dest: ‘/opt/zookeeper/conf/zoo.cfg‘ }

- name: zk-server1
lineinfile:
dest: /opt/zookeeper/conf/zoo.cfg
regexp: ‘^server.1=‘
line: ‘server.1={{ host1 }}:2888:3888‘
- name: zk-server2
lineinfile:
dest: /opt/zookeeper/conf/zoo.cfg
regexp: ‘^server.2=‘
line: ‘server.2={{ host2 }}:2888:3888‘
- name: zk-server3
lineinfile:
dest: /opt/zookeeper/conf/zoo.cfg
regexp: ‘^server.3=‘
line: ‘server.3={{ host3 }}:2888:3888‘

- name: mkdir file
file: dest={{ item }} state=directory mode=0755
with_items:
- /data/zookeeper/data
- /data/zookeeper/logs

- name: sync zkmyid1 file
template: src=kafka/myid1 dest=/data/zookeeper/data/myid
when: ansible_nodename == ‘{{ host1 }}‘
- name: sync zkmyid2 file
template: src=kafka/myid2 dest=/data/zookeeper/data/myid
when: ansible_nodename == ‘{{ host2 }}‘
- name: sync zkmyid3 file
template: src=kafka/myid3 dest=/data/zookeeper/data/myid
when: ansible_nodename == ‘{{ host3 }}‘

- name: rm tar
shell: rm -f /opt/zookeeper-3.4.12.tar.gz

#不知道怎么回事再角色里无法启动zk,还是去机器上挨个/opt/zookeeper/bin/zkServer.sh start

集群状态验证:
[root@10.0.0.11 root]# zkServer.sh status
JMX enabled by default
Using config: /opt/zookeeper/bin/../conf/zoo.cfg
Mode: follower

#还有好多需要进步,记录下来自己成长过程!!共勉

ansible 安装zk集群playbook

标签:enabled   files   验证   name   yml   角色   get   无法   line   

原文地址:https://blog.51cto.com/11815010/2405149

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!