From bc238bc01542a0666e6497d503307eeeb49e458e Mon Sep 17 00:00:00 2001 From: wangjian Date: Mon, 9 Dec 2024 16:52:06 +0800 Subject: [PATCH] add elastic-agent standalone and multi deploy methods --- playbook/group_vars/all | 2 + playbook/multi-machine.yml | 9 ++- playbook/roles/elk-agent/tasks/main.yml | 29 +++++++++ playbook/standalone.yml | 1 + .../templates/elk-agent/elastic-agent.yml.j2 | 42 +++++++++++++ playbook/templates/elk-agent/fleet.yml.j2 | 61 +++++++++++++++++++ 6 files changed, 143 insertions(+), 1 deletion(-) create mode 100644 playbook/roles/elk-agent/tasks/main.yml create mode 100644 playbook/templates/elk-agent/elastic-agent.yml.j2 create mode 100644 playbook/templates/elk-agent/fleet.yml.j2 diff --git a/playbook/group_vars/all b/playbook/group_vars/all index f1a4d07..8a680c6 100644 --- a/playbook/group_vars/all +++ b/playbook/group_vars/all @@ -6,6 +6,8 @@ password_for_all_es_users: PilotGo13579! pilotgo_config: /opt/PilotGo/server/config_server.yaml pilotgo_agent_config: /opt/PilotGo/agent/config_agent.yaml pilotgo_elk_config: /opt/PilotGo/plugin/elk/elk.yaml +pilotgo_elk_agent_config: /opt/Elastic/Agent/elastic-agent.yml +pilotgo_elk_agent_fleet_config: /opt/Elastic/Agent/fleet.yml kibana_ssl_crt_file: /opt/kibana/config/certs/kibana-server/kibana-server.crt kibana_ssl_key_file: /opt/kibana/config/certs/kibana-server/kibana-server.key kibana_elastic_ca_file: /opt/kibana/config/certs/kibana/elasticsearch-ca.pem \ No newline at end of file diff --git a/playbook/multi-machine.yml b/playbook/multi-machine.yml index 0ef1c66..f39f6cb 100644 --- a/playbook/multi-machine.yml +++ b/playbook/multi-machine.yml @@ -140,4 +140,11 @@ remote_user: root roles: - - elk \ No newline at end of file + - elk + +- name: pilotgo elk agent install + hosts: elk-agent + remote_user: root + + roles: + - elk-agent \ No newline at end of file diff --git a/playbook/roles/elk-agent/tasks/main.yml b/playbook/roles/elk-agent/tasks/main.yml new file mode 100644 index 0000000..eea7843 --- /dev/null +++ b/playbook/roles/elk-agent/tasks/main.yml @@ -0,0 +1,29 @@ +--- +- name: mkdir elasticsearch + shell: mkdir -p /opt/Elastic/Agent +- name: installl elastic agent for x86_64 system + block: + - name: get elastic agent from official website + shell: wget https://artifacts.elastic.co/downloads/beats/elastic-agent/elastic-agent-7.17.16-linux-x86_64.tar.gz --no-check-certificate + args: + chdir: /root/ + - name: unzip tar.gz + shell: tar -xzvf elastic-agent-7.17.16-linux-x86_64.tar.gz -C /opt/Elastic/Agent --strip-components=1 + args: + chdir: /root/ + when: ansible_architecture == "x86_64" +- name: install elastic agent for aarch64 system + block: + - name: get elastic agent from official website + shell: wget https://artifacts.elastic.co/downloads/beats/elastic-agent/elastic-agent-7.17.16-linux-arm64.tar.gz --no-check-certificate + args: + chdir: /root/ + - name: unzip tar.gz + shell: tar -xzvf elastic-agent-7.17.16-linux-arm64.tar.gz -C /opt/Elastic/Agent --strip-components=1 + args: + chdir: /root/ + when: ansible_architecture == "aarch64" +- name: change config file for elastic-agent + template: src=templates/elk-agent/elastic-agent.yml.j2 dest={{ pilotgo_elk_agent_config }} +- name: change config file for elastic-agent fleet + template: src=templates/elk-agent/fleet.yml.j2 dest={{ pilotgo_elk_agent_fleet_config }} \ No newline at end of file diff --git a/playbook/standalone.yml b/playbook/standalone.yml index 978fafb..06248f1 100644 --- a/playbook/standalone.yml +++ b/playbook/standalone.yml @@ -10,6 +10,7 @@ - fleet - filebeat - elk + - elk-agent tasks: - name: https for es diff --git a/playbook/templates/elk-agent/elastic-agent.yml.j2 b/playbook/templates/elk-agent/elastic-agent.yml.j2 new file mode 100644 index 0000000..146fe17 --- /dev/null +++ b/playbook/templates/elk-agent/elastic-agent.yml.j2 @@ -0,0 +1,42 @@ +# ================================ General ===================================== +# Beats is configured under Fleet, you can define most settings +# from the Kibana UI. You can update this file to configure the settings that +# are not supported by Fleet. +fleet: + enabled: true + +# agent.download: +# # source of the artifacts, requires elastic like structure and naming of the binaries +# # e.g /windows-x86.zip +# sourceURI: "https://artifacts.elastic.co/downloads/beats/" +# # path to the directory containing downloaded packages +# target_directory: "${path.data}/downloads" +# # timeout for downloading package +# timeout: 120s +# # install_path describes the location of installed packages/programs. It is also used +# # for reading program specifications. +# install_path: "${path.data}/install" + +# agent.process: +# # minimal port number for spawned processes +# min_port: 10000 +# # maximum port number for spawned processes +# max_port: 30000 +# # timeout for creating new processes. when process is not successfully created by this timeout +# # start operation is considered a failure +# spawn_timeout: 30s + +# agent.retry: +# # enabled determines whether retry is possible. Default is false. +# enabled: true +# # retries_count specifies number of retries. Default is 3. +# # Retry count of 1 means it will be retried one time after one failure. +# retries_count: 3 +# # delay specifies delay in ms between retries. Default is 30s +# delay: 30s +# # max_delay specifies maximum delay in ms between retries. Default is 300s +# max_delay: 5m +# # Exponential determines whether delay is treated as exponential. +# # With 30s delay and 3 retries: 30, 60, 120s +# # Default is false +# exponential: false diff --git a/playbook/templates/elk-agent/fleet.yml.j2 b/playbook/templates/elk-agent/fleet.yml.j2 new file mode 100644 index 0000000..9977c76 --- /dev/null +++ b/playbook/templates/elk-agent/fleet.yml.j2 @@ -0,0 +1,61 @@ +agent: + id: b8537686-ea41-421b-ac17-b27fe96bdd27 + monitoring.http: + enabled: false + host: "" + port: 6791 +fleet: + enabled: true + access_api_key: VVVuMU5KQUJxbWRPN29tc1UzRmg6cHYwc0NlV0ZUWGlKUWthUFhEcHd6Zw== + protocol: http + {% if groups | length == 1 %} + + host: {{ groups['standalone'][0] }}:8220 + {% else %} + + host: {{ groups['fleet'][0] }}:8220 + {% endif %} + + ssl: + verification_mode: none + renegotiation: never + timeout: 10m0s + proxy_disable: true + reporting: + threshold: 10000 + check_frequency_sec: 30 + agent: + id: "" + server: + output: + elasticsearch: + protocol: https + hosts: + {% if groups | length == 1 %} + + - {{ groups['standalone'][0] }}:9200 + {% else %} + + - {{ groups['elasticsearch'][0] }}:9200 + {% endif %} + + service_token: AAEAAWVsYXN0aWMvZmxlZXQtc2VydmVyL3Rva2VuLTE3MTg4Njk4MzU3Njk6U2pfaDRvblVSMEdMd2NWWm1ZMjlOZw + ssl: + verification_mode: none + certificate_authorities: + - /opt/elasticsearch/config/certs/kibana/elasticsearch-ca.pem + renegotiation: never + proxy_disable: false + proxy_headers: {} + + + {% if groups | length == 1 %} + + host: {{ groups['standalone'][0] }} + {% else %} + + host: {{ groups['fleet'][0] }} + {% endif %} + + port: 8220 + internal_port: 8221 -- Gitee