首页 > 其他分享 >ansible自动化部署zookeeper

ansible自动化部署zookeeper

时间:2024-08-17 20:24:59浏览次数:18  
标签:ZOOKEEPER JAVA name zookeeper ansible 自动化 data

一、准备环境

1、准备机器

本次以192.168.190.155,192.168.190.156,192.168.190.157,192.168.190.158四台虚机为例,本文操作全在管理机中。

机器IP

节点

CPU&内存

系统盘

存储

192.168.190.155

Ansible管理机

2C4G

50GB

50GB

192.168.190.158

Master/Worker(被管理机)

2C4G

50GB

50GB

192.168.190.157

Master/Worker(被管理机)

2C4G

50GB

50GB

192.168.190.156

Worker(被管理机)

2C4G

50GB

50GB

本次主要操作都在管理机:192.168.190.155上完成

二、详细步骤

1、配置ansible的hosts,定义变量:

vi /etc/ansible/hosts

内容:

[zookeeper_nodes]

zookeeper1 ansible_host=192.168.190.158

zookeeper2 ansible_host=192.168.190.156

zookeeper3 ansible_host=192.168.190.157

[zookeeper]

zookeeper1 myid=1

zookeeper2 myid=2

zookeeper3 myid=3

2、在管理机上创建安装zookeeper的必要的目录

mkdir -p /etc/ansible/roles/{zookeeper,java}/{defaults,tasks,templates}

3、编辑配置java剧本

目录结构图:

①、配置defaults目录下的配置文件(设置变量):main.yml

vi /etc/ansible/roles/java/defaults/main.yml

内容:

---

JAVA_VERSION: 1.8.2_192

JAVA_HOME: /data/java

JAVA_TAR: jdk-8u192-linux-x64.tar.gz

②、配置tasks目录下的配置文件(剧本):java.yml

vi /etc/ansible/roles/java/tasks/java.yml

内容:

---

- name: Deploy Java-JDK-1.8-192

  hosts: all

  become: yes

  roles:

    - java

  tasks:

    - name: Copy Jdk

      copy:

        src: /{{JAVA_HOME}}/{{JAVA_VERSION2}}

        dest: /tmp/{{JAVA_VERSION2}}

    - name: Create Kafka logs directory  

      ansible.builtin.file:    

        path: /data/java   

        state: directory

    - name: Extrack Jdk

      unarchive:

        src: /tmp/{{JAVA_VERSION2}}

        dest: /data/java/

        remote_src: yes

    - name: Add JAVA_HOME to /etc/profile.d/

      blockinfile:        

        path: /etc/profile.d/java.sh

        create: yes        

        mode: '0644'        

        block: |          

          export JAVA_HOME=/{{JAVA_HOME}}/jdk-{{JAVA_VERSION}}

          export CLASSPATH=.:${JAVA_HOME}/jre/lib/rt.jar:${JAVA_HOME}/lib/dt.jar:${JAVA_HOME}/lib/tools.jar
          export PATH=$PATH:$JAVA_HOME/bin        

          marker: "# {mark} ANSIBLE MANAGED BLOCK - JAVA_HOME"

4、编辑配置zookeeper剧本

目录结构图:

①、配置defaults目录下的配置文件(设置变量):main.yml

vi /etc/ansible/roles/zookeeper/defaults/main.yml

内容:

---

ZOOKEEPER_VERSION: 3.7.2

ZOOKEEPER_HOME: /data/zookeeper/apache-zookeeper-3.7.2-bin

ZOOKEEPER_TAR: apache-zookeeper-3.7.2-bin.tar.gz

ZOOKEEPER_INSTALL_DIR: /data/zookeeper

ZOOKEEPER_INSTALL_DIR_USR: /usr/local/zookeeper

②、配置tasks目录下的配置文件(剧本):zookeeper.yml

vi /etc/ansible/roles/zookeeper/tasks/zookeeper.yml

内容:

---

- name: Deploy zookeeper-3.7.2

  hosts: all

  become: yes

  roles:

    - zookeeper

  vars:

    zookeeper_conf_dir: /{{ ZOOKEEPER_HOME }}/conf

  tasks:

    - name: Copy zookeeper

      copy:

        src: /{{ ZOOKEEPER_INSTALL_DIR }}/{{ ZOOKEEPER_TAR }}

        dest: /tmp/{{ ZOOKEEPER_TAR }}

    - name: Create zookeeper

      ansible.builtin.file:

        path: /data/zookeeper/data

        state: directory

    - name: Create logs

      ansible.builtin.file:

        path: /data/zookeeper/apache-zookeeper-3.7.2/logs

        state: directory

    - name: Extrack zookeeper

      unarchive:

        src: /tmp/{{ ZOOKEEPER_TAR }}

        dest: /{{ ZOOKEEPER_INSTALL_DIR }}

        remote_src: yes

    - name: Ln

      shell: |

        ln -s /{{ ZOOKEEPER_HOME }} /{{ ZOOKEEPER_INSTALL_DIR_USR }}

    - name: Ensure Kafka configuration directory exists

      ansible.builtin.file:

        path: "{{ zookeeper_conf_dir }}"

        state: directory

    - name: Render zookeeper configuration file

      ansible.builtin.template:

        src: /etc/ansible/roles/zookeeper/templates/zookeeper.j2

        dest: "{{ zookeeper_conf_dir }}/zoo.cfg"

    - name: Ensure Zookeeper data directory exists      

      ansible.builtin.file:        

      path: "/{{ ZOOKEEPER_INSTALL_DIR }}/data-{{ ansible_hostname }}"        

      state: directory

    - name: Create myid file from template

      ansible.builtin.template:

        src: /etc/ansible/roles/zookeeper/templates/zookeeper1.j2

        dest: "/data/zookeeper/data/myid"

    - name: Deploy Zookeeper systemd service file

      ansible.builtin.template:

        src: /etc/ansible/roles/zookeeper/templates/zookeeper.service.j2

        dest: /etc/systemd/system/zookeeper.service

    - name: reload systemd manager and restart zookeeper

      ansible.builtin.systemd:

        name: zookeeper

        state: restarted

        daemon_reload: yes

③、编辑配置jinja2文件(配合剧本使用,自动创建zookeeper配置文件):

a、zookeeper1.j2

vi /etc/ansible/roles/zookeeper/templates/zookeeper1.j2

内容:

{{ myid }}

b、zookeeper.j2

vi /etc/ansible/roles/zookeeper/templates/zookeeper.j2

内容:

#The number of milliseconds of each tick

#The number of ticks that the initial

#synchronization phase can take

#The number of ticks that can pass between

#sending a request and getting an acknowledgement

#the directory where the snapshot is stored.

#do not use /tmp for storage, /tmp here is just

#example sakes.

#the port at which the clients will connect

tickTime=2000

initLimit=10

syncLimit=5

dataDir={{ ZOOKEEPER_INSTALL_DIR }}/data

dataLogDir={{ ZOOKEEPER_HOME }}/logs

clientPort=2181

server.1=192.168.190.158:2341:2351

server.2=192.168.190.156:2342:2352

server.3=192.168.190.157:2343:2353

#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=1

##Metrics Providers

#https://prometheus.io Metrics Exporter

#metricsProvider.className=org.apache.zookeeper.metrics.prometheus.PrometheusMetricsProvider

#metricsProvider.httpPort=7000

#metricsProvider.exportJvmInfo=true

c、zookeeper.service.j2

vi /etc/ansible/roles/zookeeper/templates/zookeeper.service.j2

内容:

[Unit]

Description=ZooKeeper Service  

After=network.target  

[Service]

Type=simple  

User=root

Group=root

Environment=JAVA_HOME=/data/java/jdk1.8.0_192

WorkingDirectory=/data/zookeeper/apache-zookeeper-3.7.2-bin/

ExecStart=/data/zookeeper/apache-zookeeper-3.7.2-bin/bin/zkServer.sh start-foreground  

ExecStop=/data/zookeeper/apache-zookeeper-3.7.2-bin/bin/zkServer.sh stop  

Restart=on-abnormal

[Install]

WantedBy=multi-user.target

5、执行ansible-playbook指令即可

ansible-playbook zookeeper.yml

ansible-playbook java.yml

三、被管理机操作

1、执行systemctl语句

systemctl start zookeeper.service  ##启动zookeeper

systemctl stop zookeeper.service  ##启停zookeeper

systemctl status zookeeper.service  ##查看zookeeper状态

标签:ZOOKEEPER,JAVA,name,zookeeper,ansible,自动化,data
From: https://blog.csdn.net/changyitt/article/details/141264489

相关文章

  • 如何优化 Vite 项目中的 Lodash 引入:从 Tree Shaking 到自动化测试
    文章目录前言问题背景解决方案概述思路1:使用Lodash-ES替代Lodash思路2:使用Babel插件babel-plugin-lodash思路3:大规模替换后的验证与测试Babel的工作流程回顾最终选择及实践经验自动化测试:使用Puppeteer验证替换后的代码结论前言在现......
  • 基于LangChain手工测试用例转接口自动化测试生成工具
    接口自动化测试用例是一个老生常谈的问题,在未引入人工智能之前,也有非常多的生成方案,比如如下所示,通过har生成接口自动化测试用例:但是以上的生成方式依然是有一些弊端,比如har本身虽然能表述一定的接口信息和业务信息,但是毕竟无法用来表述全部的应用场景与用例场景。而大部分的......
  • 2024.8.16(ansible)
    一、回顾1、mysql和python    1.mysql5.7        1.1不需要执行mysql_ssl_rsa_setup        1.2Change_master_to.不需要getpublickey    2.可以使用pymysql非交互的管理mysql        2.1 conn......
  • ansible【自动化配置】(thirty day)
    回顾1、mysql和python(1)不需要执行mysql_ssl_rsa_setup(2)Change_master_to.不需要getpublickey2、可以使用pymysql非交互的管理mysql(1)conn=pymysql.connect(host,user,password,database,prot)(2)cursor=conn.cursor();(3)Cursor.execute("createuser....")(4)cursor.ex......
  • 解锁企业数据分析瓶颈:数据可视化与报表自动化的实战策略
    Hi~这里是ProXiao文章参考:晓观点 《数据可视化与报表自动化:如何破解企业数据分析的痛点?》在数字化时代背景下,企业面临着日益增长的数据量和复杂性,这对数据处理、分析和应用提出了更高要求。企业决策过程中如何高效利用数据资源,已成为一个关键议题。本文旨在分析企业在数据......
  • Python魔法应用:自动化日常任务:让Python成为你的私人助理
    自动化日常任务:让Python成为你的私人助理引言自动化文本处理:批量重命名文件、整理数据批量重命名文件整理数据自动化邮件发送:使用smtplib发送邮件自动化网页交互:使用requests库获取网页数据结语引言在日常工作和学习中,我们常常会遇到大量重复且繁琐的任务,这些任务......
  • 【Python-办公自动化】1秒提取PPT文本内容形成目录保存至WORD
    欢迎来到"花花ShowPython",一名热爱编程和分享知识的技术博主。在这里,我将与您一同探索Python的奥秘,分享编程技巧、项目实践和学习心得。无论您是编程新手还是资深开发者,都能在这里找到有价值的信息和灵感。自我介绍:我热衷于将复杂的技术概念以简单易懂的方式呈现给大家,......
  • 【Python-办公自动化】几分钟生成上万份合同(用此思路可以用于写作固定格式的文章)
    欢迎来到"花花ShowPython",一名热爱编程和分享知识的技术博主。在这里,我将与您一同探索Python的奥秘,分享编程技巧、项目实践和学习心得。无论您是编程新手还是资深开发者,都能在这里找到有价值的信息和灵感。自我介绍:我热衷于将复杂的技术概念以简单易懂的方式呈现给大家,......
  • Delphi开发新纪元:探索持续集成与持续部署的自动化之路
    标题:“Delphi开发新纪元:探索持续集成与持续部署的自动化之路”引言在软件工程领域,持续集成(CI)和持续部署(CD)是敏捷开发的关键实践,它们确保了代码的高质量和快速迭代。对于Delphi开发者而言,选择合适的CI/CD工具对于提高开发效率和软件质量至关重要。一、DelphiCI/CD工具概......
  • ansible 变量
    打印playbook变量var01.yaml----hosts:ubuntuvars:foo:bartasks:#Prints"Variable'foo'issettobar".-debug:msg="Variable'foo'issetto{{foo}}"打印文件中的变量var02.yaml......