1 框架概述

2 添加组件步骤

  • 组件playbook剧本文件

    1. - hosts: example_hosts # 此处需套填写所安装组件配置的主机名。(建议按照统一生成的名称来处理)
    2. gather_facts: no
    3. user: root
    4. vars_files: # 需要引用变量文件时,加入vars文件
    5. - "../vars/example_vars.yml"
    6. vars: # 定义安装步骤的变量,在安装过程中可以根据需要修改是否启用
    7. install_example: true # 安装 example
    8. config_example: true # 配置 example
    9. start_example: true # 启动 example service
    10. create_user: true # 创建新的用户和组
    11. roles: # playbook中需要完成的角色剧本,可自定义,与顺序相关
    12. - ../roles/user # (1)创建用户 playbook
    13. - ../roles/example # (2) 安装 exampl playbook
  • 组件vars变量文件

    1. ---
    2. # 根据组件安装的实际需要来确定需要使用哪些变量,在安装过程中yaml中key会被替换成实际值
    3. # example 软件版本值
    4. example_version: 1.1.1
    5. # example 需要的用户与用户组名
    6. user: "example"
    7. group: "example"
    8. # 日志目录
    9. log_path: "log"
    10. # 安装目录
    11. install_dir: "/opt/example"
    12. # 使用的主机列表
    13. example_hosts: example_hosts
  • 组件roles角色人物定义

    • files目录
      • 放置组件需要的文件目录,可以是软件包或运行时所需要的其他文件。
      • 在files目录下的文件,playbook中可以直接引用,用于后续的拷贝、解压、修改等动作
      • 修改变量尽量使用templates中的模板文件,而非files文件。
    • templates目录

      放置需要根据主机或变量动态生成的配置文件、Service文件等。为j2文件,使用jinja生成。

      ```yaml

      模板文件是有相对固定的框架,如配置文件可以以软件中定义的配置文件为框架进行修改,service文件以规范的框架进行修改。自定义的模板同理。

      固定项

      http.port: 9200 path.logs: /var/log/example

  1. # 可变项-直接使用vars中的变量
  2. # 如 example_vars中的配置项为:
  3. # example_cluster_name: mycluster
  4. # 最终生成的配置项如下:
  5. # cluster.name: mycluster
  6. cluster.name: {{example_cluster_name}}
  7. # 可变项-使用主机清单中的配置变量
  8. # 如 主机清单中配置如下:
  9. # example_hosts:
  10. # hosts:
  11. # 192.168.1.1:
  12. # ansible_host: 192.168.1.1
  13. # example_id: example_node1
  14. # 192.168.1.2:
  15. # ansible_host: 192.168.1.2
  16. # example_id: example_node1
  17. # 192.168.1.2:
  18. # ansible_host: 192.168.1.2
  19. # example_id: example_node1
  20. # 最终生成的配置项如下:
  21. # 192.168.1.1主机上的配置文件为:node.name: example1
  22. # 192.168.1.2主机上的配置文件为:node.name: example2
  23. # 192.168.1.3主机上的配置文件为:node.name: example3
  24. node.name: {{example_id}}
  25. # 可变项-根据主机生成配置项
  26. # 如 主机清单中配置如下:
  27. # example_hosts:
  28. # hosts:
  29. # 192.168.1.1:
  30. # ansible_host: 192.168.1.1
  31. # example_id: example_node1
  32. # 192.168.1.2:
  33. # ansible_host: 192.168.1.2
  34. # example_id: example_node1
  35. # 192.168.1.2:
  36. # ansible_host: 192.168.1.2
  37. # example_id: example_node1
  38. # 最终生成的配置项如下:
  39. # discovery.seed_hosts: ["192.168.1.1", "192.168.1.2", "192.168.1.3"]
  40. {% for host in groups.elasticsearch_hosts -%}
  41. {% set host_ip = hostvars[host].ansible_host -%}
  42. discovery.seed_hosts: ["{{host_ip}}"]
  43. {% endfor -%}
  44. ```
  • tasks目录
    • main.yml
    1. ---
    2. ## 包含常规流程,如需要特出处理,可以自定义添加
    3. # step1 安装组件
    4. - name: Install example
    5. include: install_example.yml
    6. when: install_example
    7. # step2 修改配置
    8. - name: Config example
    9. include: config_example.yml
    10. when: config_example
    11. # step3 启动服务
    12. - name: Start example
    13. include: start_example.yml
    14. when: start_example
    • install_example.yml
    1. ---
    2. ## 本文件中主要实现软件包的安装步骤,将软件包部署到目的位置
    3. ## 新版本ansible中安装rpm包,建议使用dnf,而非yum
    4. ###############################自己上传rpm软件包###########################
    5. # 1. 拷贝example_rpm到/tmp目录下, example_rpm为具体的文件名,定义在example_vars文件中
    6. - name: Copy rpm file to server
    7. copy:
    8. src: "{{ example_rpm }}"
    9. dest: /tmp/{{example_rpm}}
    10. mode: 755
    11. # 2. 安装/tmp/{{example_rpm}}软件包
    12. - name: install packages
    13. become: true
    14. become_user: root
    15. dnf:
    16. state: latest #选择状态为安装最新的软件包
    17. disable_gpg_check: true # 本地包可关闭gpg检查
    18. name: /tmp/{{example_rpm}}
    19. ###############################直接使用dnf安装软件包###########################
    20. # 如果openEuler版本中已经发布了该软件包,配置repo源即可下载
    21. - name: install packages
    22. become: true
    23. become_user: root
    24. dnf:
    25. state: latest
    26. name:
    27. - example
    28. ###############################自己上传源码包###########################
    29. # 创建安装目录
    30. - name: mkdir install_path
    31. file: path={{install_path}} state=directory mode=0755
    32. # 复制软件包到目标目录
    33. - name: copy example
    34. unarchive: src=example-{{version}}.tar.gz dest={{install_path}} copy=yes
    35. # 修改权限
    36. - name: chown
    37. file: path={{install_path}} state=directory mode=0755 owner={{user}} group={{group}} recurse=yes
    • config_example.yml

    在本文件中主要定义需要配置的一些操作,包括配置文件修改,Service文件修改等

    使用jinja直接匹配模板中的配置文件。j2文件中的变量会自动替换,生成真实的配置。

    • name: Deploy elastic.yml template: src=templates/example.j2 dest={{example_config}}/example.yml mode=0755
  1. - name: Modify config file
  2. shell: |
  3. echo "xxx" >> {{example_config}}/example.conf
  4. echo "elasticsearch hard memlock unlimited" >> /etc/security/limits.conf
  5. ```
  6. - ###### start_example.yml
  7. ```yaml
  8. ## 本文件中主要用于启动组件
  9. ## 1. 启动服务
  10. ##############################systemctl 启动服务###############################
  11. # 服务类的组件可以直接使用systemctl控制,使用如下方式,设置state、enable等项来来拉起服务
  12. - name: Start example
  13. become_user: "{{user}}"
  14. service:
  15. name: example
  16. state: restarted
  17. ##############################脚本启动服务###############################
  18. # 如果组件没有服务化,可以使用脚本拉起服务,并指定配置文件。
  19. - name: Start example
  20. shell: "cd {{install_dir}}/bin && ./example-start.sh -daemon ../config/example.conf"
  21. become: yes
  22. ## 2. 启动状态检查
  23. ################################服务状态采集##########################
  24. - name: collect facts about system services
  25. service_facts:
  26. register: services_state
  27. - name: Debug
  28. debug:
  29. var: services_state
  30. ##################################自定义的检查##############################
  31. # 检查服务状态
  32. - name: verify example service
  33. command: /usr/sbin/service example status
  34. changed_when: false
  35. # 检查端口监听状态
  36. - name: verify example is listening on 1111
  37. wait_for: port=111 timeout=1
  38. ```

2.1.2 将自定义模板的文件添加至框架中

可以使用example中的实例文件进行修改, 然后

  1. example_playbooks.yml 文件名为"组件名.yml",移动至install_ansible/playbooks
  2. example_vars.yml 文件名为"组件名_vars.yml", 移动至install_ansible/vars
  3. └─example 目录名为"组件名", 移动至install_ansible/roles
  4. ├─files
  5. readme.md
  6. ├─tasks
  7. config_example.yml
  8. install_example.yml
  9. main.yml
  10. start_example.yml
  11. └─templates
  12. example.j2
  1. ---
  2. step_list: # 步骤列表
  3. kafka: # 第一步安装kafka,可以使用默认模板
  4. enable: false # 置为false则跳过安装步骤,true执行安装步骤
  5. continue: false # 置为false则安装失败时终止任务,true执行安装失败时继续下一个组件安装
  6. example: # 第二步安装example自定义组件,将组件添加在合适的位置,并设置配置项
  7. enable: false
  8. continue: false

2.2 默认组件模板

2.2.1 默认组件列表

当前提供的默认组件包括:

  • 如图所示为默认提供的组件之前的依赖关系。服务正常运行需要提前安装好前置依赖。
  • elasticsearch在aops框架安装时已经安装在主节点,如果没有组建集群的需要,修改配置即可使用,无需额外部署。
  • aops框架中提供的其他组件未在图中具体列出。

2.2.3 默认任务配置

(1)zookeeper

zookeeper主要负责集群管理,并且是kafka运行的基础,需要配置在集群的每个节点中。

  • 主机配置

主机清单中对集群中每个节点的IP、节点ID进行配置:

  1. zookeeper_hosts:
  2. hosts:
  3. 192.168.1.1: # 主机名
  4. ansible_host: 192.168.1.1 # 主机IP
  5. ansible_python_interpreter: /usr/bin/python3
  6. myid: 2 # zookeeper节点ID
  7. 192.168.1.2:
  8. ansible_host: 192.168.1.2
  9. ansible_python_interpreter: /usr/bin/python3
  10. myid: 1
  11. 192.168.1.3:
  12. ansible_host: 192.168.1.3
  13. ansible_python_interpreter: /usr/bin/python3
  14. myid: 3
  • 变量配置

zookeeper的变量包括:

  1. ---
  2. # zookeeper user group 用户名、用户组
  3. user: "zookeeper"
  4. group: "zookeeper"
  5. # zookeeper data path data路径
  6. data_dir: "data"
  7. # zookeeper log path 日志路径
  8. zookeeper_log_path: "log"
  9. # zookeeper install path 安装路径
  10. install_dir: "/opt/zookeeper"
  11. # zookeeper port config 端口配置
  12. leader_port: 2888
  13. vote_port: 3888
  14. client_port: 2181

(2)kafka

  • 主机配置

    kafka 需要在安装zookeeper之后再安装。主机清单中需要配置kafka的端口、ID。同时需要配置zookeeper的IP与ID。

  1. kafka_hosts:
  2. hosts:
  3. 192.168.1.1: # 主机名
  4. ansible_host: 192.168.1.1 # 主机IP
  5. ansible_python_interpreter: /usr/bin/python3
  6. kafka_id: 2 # kafka id
  7. kafka_port: 9092 # kafka 监听端口
  8. 192.168.1.2:
  9. ansible_host: 192.168.1.2
  10. ansible_python_interpreter: /usr/bin/python3
  11. kafka_id: 1
  12. kafka_port: 9092
  13. 192.168.1.3:
  14. ansible_host: 192.168.1.3
  15. ansible_python_interpreter: /usr/bin/python3
  16. kafka_id: 3
  17. kafka_port: 9092
  18. zookeeper_hosts: # zookeeper集群IP配置
  19. hosts:
  20. 192.168.1.1: # 主机名
  21. ansible_host: 192.168.1.1 # 主机IP
  22. ansible_python_interpreter: /usr/bin/python3
  23. myid: 2 # zookeeper id
  24. 192.168.1.2:
  25. ansible_host: 192.168.1.2
  26. ansible_python_interpreter: /usr/bin/python3
  27. myid: 1
  28. 192.168.1.3:
  29. ansible_host: 192.168.1.3
  30. ansible_python_interpreter: /usr/bin/python3
  31. myid: 3
  • 变量配置
  1. ---
  2. # zookeeper user group 用户、用户组
  3. user: "kafka"
  4. group: "kafka"
  5. # Log Path 日志路径
  6. kafka_log_path: "log"
  7. # Install path 安装路径
  8. install_dir: "/opt/kafka"
  9. # zookeeper client port 客户端端口
  10. zk_client_port: 2181

(3)prometheus

  • prometheus负责集中采集的kpi数据项。只需要安装在server 节点上。另外,Prometheus需要去node_exporter上抓取数据,需要配置可连接的node_exporter的节点IP

  • 变量配置
  1. ---
  2. # prometheus 用户 用户组
  3. user: "prometheus"
  4. group: "prometheus"
  5. # prometheus 监听端口
  6. prometheus_listen_port: 9090
  7. # node_exporter 监听端口
  8. node_exporter_listen_port: 9100
  9. # prometheus 配置文件路径
  10. prometheus_conf_dir: "/etc/prometheus"

(4)node_exporter

  • 主机配置

node_exporter需要安装在所有需要采集数据的主机节点上,主要需要配置IP

  1. node_exporter_hosts:
  2. hosts:
  3. 192.168.1.1:
  4. ansible_host: 192.168.1.1
  5. ansible_python_interpreter: /usr/bin/python3
  6. 192.168.1.2:
  7. ansible_host: 192.168.1.2
  8. ansible_python_interpreter: /usr/bin/python3
  9. 192.168.1.3:
  10. ansible_host: 192.168.1.3
  11. ansible_python_interpreter: /usr/bin/python3
  • 变量配置
  1. ---
  2. # node_exporter user 用户 用户组
  3. user: "node_exporter"
  4. group: "node_exporter"
  5. # Listening port 监听端口
  6. node_exporter_listen_port: 9100

(5)MySQL

  • 主机配置

MySQL数据库只需要安装在server 节点上。

  1. hosts:
  2. 192.168.1.2:
  3. ansible_host: 192.168.1.2
  4. ansible_python_interpreter: /usr/bin/python3
  • 变量配置
  1. ---
  2. # mysql 用户、用户组
  3. user: "mysql"
  4. group: "mysql"

(6)elasticsearch

  • 主机配置

elasticsearch数据库只需要安装在server 节点上。需要配置server节点上,并指定节点ID。如果需要配置分布式集群,需要修改主机清单和配置文件elasticsearch.j2

  1. elasticsearch_hosts:
  2. hosts:
  3. 192.168.1.2:
  4. ansible_host: 192.168.1.2
  5. elasticsearch_id: elasticsearch_node1
  • 变量配置
  1. ---
  2. # elasticsearch User Group 用户 用户组
  3. user: elasticsearch
  4. group: elasticsearch
  5. # elasticsearch repo config 官方repo源配置
  6. repo_name: "Elasticsearch"
  7. repo_description: "Elasticsearch repository for 7.x packages"
  8. repo_base_url: "https://artifacts.elastic.co/packages/7.x/yum"
  9. repo_gpgkey: "https://artifacts.elastic.co/GPG-KEY-elasticsearch"
  10. repo_file: "elasticsearch"
  11. # elasticsearch Install dir 安装目录
  12. install_dir: /etc/elasticsearch/
  13. # elasticsearch cluster name 集群名称
  14. elasticsearch_cluster_name: myApp
  15. # elasticsearch init master ip address 默认的集群主节点IP
  16. elasticsearch_cluster_init_master: 192.168.1.2
  17. # elasticsearch listen port 监听端口
  18. elasticsearch_listen_port: 9200
  19. # elasticsearch data path 数据目录
  20. elasticsearch_data_path: "/var/lib/elasticsearch"
  21. # elasticsearch log path 日志目录
  22. elasticsearch_log_path: "/var/log/elasticsearch"
  23. # elasticsearch network host 网络IP
  24. elasticsearch_network_host: "{{elasticsearch_cluster_init_master}}"

(7)fluentd

  • 主机配置

fluentd 负责日志采集,部署在所有需要采集的节点上,最终将日志汇总在elasticsearch上。

  1. fluentd_hosts:
  2. hosts:
  3. 192.168.1.1: # 主机名
  4. ansible_python_interpreter: /usr/bin/python3
  5. elasticsearch_host: 192.168.1.1 # elasticsearch监听的IP
  6. 192.168.1.2:
  7. ansible_python_interpreter: /usr/bin/python3
  8. elasticsearch_host: 192.168.1.1 # elasticsearch监听的IP
  9. 192.168.1.3:
  10. ansible_python_interpreter: /usr/bin/python3
  11. elasticsearch_host: 192.168.1.1 # elasticsearch监听的IP
  • 变量配置
  1. ---
  2. # fluentd config path
  3. fluentd_config_dir: /etc/fluentd/
  4. # 修改history记录的脚本
  5. change_history_format: true
  6. change_history_format_scripts:
  7. - zzz_openEuler_history.csh
  8. - zzz_openEuler_history.sh
  9. # 修改demsg记录的脚本
  10. change_dmesg_format: true
  11. change_dmesg_format_scripts: fluentd_dmesg.sh
  12. # demsg端口
  13. fluentd_demsg_port: 61122

(8) adoctor-check-executor与adoctor-check-scheduler

  • 主机配置

adoctor-check-executor与adoctor-check-scheduler依赖于aops框架运行,默认都部署在主节点上。executor与scheduler之间通过kafka进行通信。

adoctor-check-executor主机清单配置:

  1. adoctor_check_executor_hosts:
  2. hosts:
  3. 192.168.1.1: # 主机名
  4. ansible_host: 192.168.1.1 # 主机IP
  5. ansible_python_interpreter: /usr/bin/python3

adoctor-check-scheduler主机清单配置:

  1. adoctor_check_scheduler_hosts:
  2. hosts:
  3. 192.168.1.1: # 主机名
  4. ansible_host: 192.168.1.1 # 主机IP
  5. ansible_python_interpreter: /usr/bin/python3
  • 变量配置

adoctor-check-executor变量配置:

  1. # check executor的配置文件目录
  2. check_executor_conf_dir: "/etc/aops"
  3. # check executor连接的kafka服务器列表host:port。ip默认为当前主机IP,port默认为9092
  4. kafka_server_list: 192.168.1.1:9092

adoctor-check-scheduler变量配置:

(9)adoctor-diag-scheduler与adoctor-diag-executor

  • 主机配置

adoctor-diag-executor与adoctor-diag-scheduler依赖于aops框架运行,默认都部署在主节点上。executor与scheduler之间通过kafka进行通信。

  1. adoctor_diag_executor_hosts:
  2. hosts:
  3. 192.168.1.1: # 主机名
  4. ansible_host: 192.168.1.1 # 主机IP
  5. ansible_python_interpreter: /usr/bin/python3

adoctor-diag-scheduler主机清单配置:

  1. adoctor_diag_scheduler_hosts:
  2. hosts:
  3. 192.168.1.1: # 主机名
  4. ansible_host: 192.168.1.1 # 主机IP
  5. ansible_python_interpreter: /usr/bin/python3
  • 变量配置

adoctor-diag-executor变量配置:

  1. # diag executor的配置文件目录
  2. diag_executor_conf_dir: "/etc/aops"
  3. # diag executor连接的kafka服务器列表host:port。ip默认为当前主机IP,port默认为9092
  4. kafka_server_list: 192.168.1.1:9092

adoctor-diag-scheduler变量配置:

  1. # diag scheduler的配置文件目录
  2. diag_scheduler_conf_dir: "/etc/aops"
  3. # diag scheduler连接的kafka服务器列表host:port。ip默认为当前主机IP,port默认为9092
  4. kafka_server_list: 192.168.1.1:9092
  5. # diag scheduler服务监听的端口,默认为11113
  6. diag_scheduler_port: 11113

(10)gala-ragdoll

  • 主机配置

gala-ragdoll为配置溯源模块的主要组件。部署在主节点上

  1. gala_ragdoll_hosts:
  2. hosts:
  3. 192.168.1.1: # 主机名
  4. ansible_host: 192.168.1.1 # 主机IP
  5. ansible_python_interpreter: /usr/bin/python3
  • 变量配置
  1. ---
  2. # gala-ragdoll服务监听的端口
  3. gala_ragdoll_port: 11114

(11)gala-gopher与gala-spider

  • 主机配置

gala-gopher与gala-spider是架构感知模块的主要组件,其中gala-gopher部署在各个远程主机上,进行信息收集,通过kafka将消息推送到主节点的gala-spider上。gala-spider部署在主节点上,对收集到的数据进行分析。

gala-gopher主机清单配置:

  1. gala_gopher_hosts:
  2. hosts:
  3. 192.168.1.1: # 主机名
  4. ansible_host: 192.168.1.1 # 主机IP
  5. ansible_python_interpreter: /usr/bin/python3
  6. 192.168.1.2:
  7. ansible_host: 192.168.1.2
  8. ansible_python_interpreter: /usr/bin/python3
  9. 192.168.1.3:
  10. ansible_host: 192.168.1.3
  11. ansible_python_interpreter: /usr/bin/python3

gala-spider主机清单配置:

  1. gala_spider_hosts:
  2. hosts:
  3. 192.168.1.1: # 主机名
  4. ansible_host: 192.168.1.1 # 主机IP
  5. ansible_python_interpreter: /usr/bin/python3
  • 变量配置

gala-gopher变量配置:

  1. ---
  2. # gala gopher安装目录
  3. install_dir: "/opt/gala-gopher/"
  4. # gala-gopher连接的kafka host,需要配置为管理节点的主机IP
  5. gala_gopher_kafka_host: 192.168.1.1
  6. # gala-gopher监听的kafka port
  7. gala_gopher_listening_kafka_port: 9092
  8. # gala-gopher探针配置
  9. probes_example_switch: "off"
  10. probes_system_meminfo: "off"
  11. probes_system_vmstat: "off"
  12. probes_system_tcp: "off"
  13. probes_system_inode: "off"
  14. extend_probes_redis: "off"

gala-spider变量配置:

  1. ---
  2. # log path
  3. log_path: "/var/log/spider"
  4. # install path
  5. install_dir: "/opt/spider/"
  6. # kafka host 默认配置为主机IP
  7. gala_spider_kafka_host: 192.168.1.1
  8. # Listening port
  9. gala_spider_listening_kafka_port: 9092
  10. # excluded addr
  11. exclude_addr: ["192.168.x.x"]
  12. # basic table name, please don't delete originally contains in the list. And append items in order if necessary:
  13. base_table_name: ["tcp_link", "lvs_link"]
  14. other_table_name: ["nginx_statistic" , "lvs_link" , "haproxy_link" , "dnsmasq_link"]
  15. # gala-spider listening port
  16. gala_spider_port: 11115

3 执行任务配置

一个任务由多个步骤组成,基本可以认为每个步骤会安装一个组件,按照步骤组合的先后顺序,可以最终完成一次任务。

修改任务的步骤,需要修改tasks/任务名.yml

  1. ---
  2. step_list: # 步骤列表
  3. step_component: # 第一步安装kafka,可以使用默认模板
  4. enable: false # 置为false则跳过安装步骤,true执行安装步骤
  5. continue: false # 置为false则安装失败时终止任务,true执行安装失败时继续下一个组件安装

3.2 组件部署选项配置

  1. ---
  2. - hosts: example_hosts # 此处需套填写所安装组件配置的主机名。(建议按照统一生成的名称来处理)
  3. gather_facts: no
  4. user: root
  5. vars_files: # 需要引用变量文件时,加入vars文件
  6. - "../vars/example_vars.yml"
  7. vars: # 定义安装步骤的变量,在安装过程中可以根据需要修改是否启用
  8. install_example: true # 安装 example
  9. config_example: true # 配置 example
  10. start_example: true # 启动 example service
  11. create_user: true # 创建新的用户和组
  12. roles: # playbook中需要完成的角色剧本,可自定义,与顺序相关