forked from opensearch-project/OpenSearch
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement Vagrantfile for generic testing environment (#474)
* Add Vagrantfile and config.yml for generic testing environment setup * Rename vagrantfile storing directory * Add vagrant basic environment README.md * Remove basic_env folder * Fix typo on Vagrantfile * Add pre-start bash script to generate the certificates --------- Co-authored-by: Álex Ruiz <[email protected]>
- Loading branch information
Showing
4 changed files
with
118 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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." |