diff --git a/test-tools/README.md b/test-tools/README.md new file mode 100644 index 0000000000000..64dc8c453dba5 --- /dev/null +++ b/test-tools/README.md @@ -0,0 +1,41 @@ +# Basic cluster environment + +This is a environment definition with the required configuration to be prepared to freshly install a Wazuh Indexer +cluster with two nodes using Vagrant and Libvirt to provision the Virtual Machines. + +It also generates the node's required certificates using the `wazuh-certs-tool` and copy them to each node's `home` +directory, leaving a copy in `test-tools/basic_env`. + +### Prerequisites + +1. Download and install Vagrant ([source](https://developer.hashicorp.com/vagrant/downloads)) +2. Install vagrant-libvirt ([source](https://vagrant-libvirt.github.io/vagrant-libvirt/installation.html)) + > In some cases you must also install `libvirt-dev` + +## Usage + +1. Navigate to the environment's root directory + ```bash + cd test-tools/basic_env + ``` +2. Initialize the environment + ```bash + vagrant up + ``` +3. Connect to the different systems + ```bash + vagrant ssh indexer_[1|2] + ``` + +### Cleanup + +After the testing session is complete you can stop or destroy the environment as you wish: + +- Stop the environment: + ```bash + vagrant halt + ``` +- Destroy the environment: + ```bash + vagrant destroy -f + ``` diff --git a/test-tools/Vagrantfile b/test-tools/Vagrantfile new file mode 100644 index 0000000000000..dbbeb02976274 --- /dev/null +++ b/test-tools/Vagrantfile @@ -0,0 +1,47 @@ +system(" + if [ #{ARGV[0]} = 'up' ]; then + echo 'Executing pre-start script.' + bash ./pre-start.sh + fi +") + +Vagrant.configure("2") do |config| + config.vm.define "indexer_1" do |indexer_1| + indexer_1.vm.box = "generic/rhel9" + indexer_1.vm.synced_folder ".", "/vagrant" + indexer_1.vm.network "private_network", ip: "192.168.56.10" + indexer_1.vm.hostname = "node-1" + indexer_1.vm.provider "libvirt" do |vb| + vb.memory = "6144" + vb.cpus = "4" + end + indexer_1.vm.provision "shell", inline: <<-SHELL + sudo systemctl stop firewalld + sudo systemctl disable firewalld + sudo yum clean all + # Add node-2 to /etc/hosts + sudo echo "192.168.56.11 node-2" >> /etc/hosts + # Copy generated certificates + cp /vagrant/wazuh-certificates.tar /home/vagrant/wazuh-certificates.tar + SHELL + end + config.vm.define "indexer_2" do |indexer_2| + indexer_2.vm.box = "generic/ubuntu2204" + indexer_2.vm.synced_folder ".", "/vagrant" + indexer_2.vm.network "private_network", ip: "192.168.56.11" + indexer_2.vm.hostname = "node-2" + indexer_2.vm.provider "libvirt" do |vb| + vb.memory = "6144" + vb.cpus = "4" + end + indexer_2.vm.provision "shell", inline: <<-SHELL + sudo systemctl stop ufw + sudo systemctl disable ufw + sudo apt install sshpass -y + # Add node-1 to /etc/hosts + echo "192.168.56.10 node-1" >> /etc/hosts + # Copy generated certificates + cp /vagrant/wazuh-certificates.tar /home/vagrant/wazuh-certificates.tar + SHELL + end +end diff --git a/test-tools/config.yml b/test-tools/config.yml new file mode 100644 index 0000000000000..904bf09631351 --- /dev/null +++ b/test-tools/config.yml @@ -0,0 +1,7 @@ +nodes: + # Wazuh indexer nodes + indexer: + - name: node-1 + ip: "192.168.56.10" + - name: node-2 + ip: "192.168.56.11" diff --git a/test-tools/pre-start.sh b/test-tools/pre-start.sh new file mode 100644 index 0000000000000..ab8142d32f25d --- /dev/null +++ b/test-tools/pre-start.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +# SPDX-License-Identifier: Apache-2.0 +# The OpenSearch Contributors require contributions made to +# this file be licensed under the Apache-2.0 license or a +# compatible open source license. + +# Download the Wazuh certs tool +curl -sO https://packages.wazuh.com/4.9/wazuh-certs-tool.sh + +# Make the script executable +chmod +x ./wazuh-certs-tool.sh + +# Run the Wazuh certs tool +bash ./wazuh-certs-tool.sh -A + +# Create a tarball of the generated certificates +tar -cvf ./wazuh-certificates.tar -C ./wazuh-certificates/ . + +# Clean up +rm -rf ./wazuh-certificates wazuh-certs-tool.sh *.log + +echo "Setup complete and certificates archived."