Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
.idea
/rejuvenation/setup/virtualbox/*.ova
76 changes: 76 additions & 0 deletions configuration/configAll.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#!/usr/bin/env bash
# HOW TO USE:
# source configAll.sh
#
# DESCRIPTION:
# USADO PARA DEFINIR AUTOCONFIGURAÇÃO DE VARIAVEIS DE AMBIENTE E TESTES PADRÕES

GlobalExports() {
export ACTIVATE=1
}

# CREATE A FILE WITH ALL PRE CONFIGS
GeneratedFileConfig() {
printf "%s\n\n" "######################## FILE CONFIGS - $filename ########################" >> "$filename".cfg
}

Lxc() {
cat >> "$filename".cfg <<EOF
Linha 4
Linha 5
EOF
}

Xen() {
cat >> "$filename".cfg <<EOF
################################## EXPORTS ##################################
export
#############################################################################
EOF

}

Kvm() {
cat >> "$filename".cfg <<EOF
Linha 4
Linha 5
EOF
}

Virtualbox() {
cat >> "$filename".cfg <<EOF
Linha 4
Linha 5
EOF
}

Main() {
local filename=$1

GlobalExports
GeneratedFileConfig "$filename"

printf "\n%s\n" "[1] - LXC"
printf "%s\n" "[2] - XEN"
printf "%s\n" "[3] - KVM"
printf "%s\n" "[4] - VBOX"
read -p "[QUAL VIRTUALIZADOR CONFIGURAR?]: " virtualizer

if [[ "$virtualizer" -eq 1 ]]; then
Lxc

elif [[ "$virtualizer" -eq 2 ]]; then
Xen

elif [[ "$virtualizer" -eq 3 ]]; then
Kvm

elif [[ "$virtualizer" -eq 4 ]]; then
Virtualbox
fi
}

rm -r *.cfg

read -p "[SET FOR SAVE FILENAME]: " filename
Main "$filename"
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env bash

# execute in batch file
xentop -b -d 3 | while read -r line; do
# Verifica se a linha contém "xenDebian"
if echo "$line" | grep -q "xenDebian"; then
# Substitui múltiplos espaços por ; e remove espaços extras
echo "$line" | sed 's/ \+/;/g' >> "logs/xenCpuMonitoring.csv"
fi
done

# #!/usr/bin/env bash
# echo "NAME;STATE;CPU(sec);CPU(%);MEM(k);MEM(%);MAXMEM(k);MAXMEM(%);VCPUS;NETS;NETTX(k);NETRX(k);VBDS;VBD_OO;VBD_RD;VBD_WR;VBD_RSECT;VBD_WSECT;SSID" > "logs/xenCpuMonitoring.csv"

# xentop -b -d 3 | while read -r line; do
# if echo "$line" | grep -q "xenDebian"; then
# cleaned_line=$(echo "$line" | sed 's/^[ \t]*//;s/[ \t]*$//;s/[ \t][ \t]*/;/g')
# echo "$cleaned_line" >> "logs/xenCpuMonitoring.csv"
# fi
# done
2 changes: 2 additions & 0 deletions rejuvenation/machine_resources_monitoring/run
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ KVM_HEADERS() {
}

XEN_HEADERS() {
echo "NAME;STATE;CPU(sec);CPU(%);MEM(k);MEM(%);MAXMEM(k);MAXMEM(%);VCPUS;NETS;NETTX(k);NETRX(k);VBDS;VBD_OO;VBD_RD;VBD_WR;VBD_RSECT;VBD_WSECT;SSID" > "logs/xenCpuMonitoring.csv"
echo "cpu;mem;vmrss;vsz;threads;swap;date_time" >logs/xen_monitoring-xenbus.csv
echo "cpu;mem;vsz;rss;threads;swap;date_time" >logs/xen_monitoring-oxenstored.csv
echo "cpu;mem;vsz;rss;threads;swap;date_time" >logs/xen_monitoring-xen-balloon.csv
Expand All @@ -50,6 +51,7 @@ case $VIRTUALIZER_TYPE in
;;
"xen")
XEN_HEADERS
processes/xenCpuMonitoring.sh &
processes/xenstored_monitoring.sh &
processes/xenbus_monitoring.sh &
processes/xen-balloon_monitoring.sh &
Expand Down
109 changes: 51 additions & 58 deletions rejuvenation/setup/xen/dependencies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,10 @@

# ############################## IMPORTS #############################
source ../../machine_resources_monitoring/general_dependencies.sh
source ../../virtualizer_functions/xen_functions.sh
source ./redirectPort.sh
# ####################################################################

# FUNCTION=SYSTEM_UPDATE()
# DESCRIPTION:
# Attempts to update the host's repositories and system apps
SYSTEM_UPDATE() {
apt-get update && apt-get upgrade
}

# FUNCTION=INSTALL_XEN_AND_DEPENDENCIES()
# DESCRIPTION:
# Installs Xen dependencies if not already installed
Expand All @@ -35,7 +30,7 @@ INSTALL_XEN_DEPENDENCIES() {
# bridge-utils: Acts as a virtual switch, enabling the attachment of VMs to the external network
# iptables: useful for port redirecting dom0's 2222 -> domU's 22 and dom0's 8080 -> domU's 80
INSTALL_UTILS(){
apt install xen-tools lvm2 net-tools bridge-utils iptables
apt install xen-tools lvm2 net-tools bridge-utils iptables -y
}

# FUNCTION=CONFIGURE_GRUB_FOR_XEN()
Expand All @@ -51,9 +46,6 @@ CONFIGURE_GRUB_FOR_XEN(){
# DESCRIPTION:
# Creates a bridge interface (xenbr0) in the dom0, connects it to the default network interface of the host by altering the '/etc/network/interfaces' file
NETWORK_CONFIG(){
local config_file="/etc/network/interfaces"
local default_interface=$(ip -o -4 route show to default | awk '{print $5}' | grep -v '^lo$' | grep -v '^vir' | head -n 1)

if [ -z "$default_interface" ]; then
echo "Error: No proper network interface found."
exit 1
Expand All @@ -71,55 +63,17 @@ auto lo
iface lo inet loopback

# The primary network interface
allow-hotplug eno1
iface eno1 inet manual
allow-hotplug $default_interface
iface $default_interface inet manual

auto xenbr0
iface xenbr0 inet dhcp
auto $LAN_INTERFACE
iface $LAN_INTERFACE inet dhcp
bridge_ports $default_interface
EOL

service networking restart
}

# REDIRECT_PORTS()
# DESCRIPTION:
# Redirect SSH traffic from port 2222 on the host to port 22 on the Xen domU
# Redirect HTTP traffic from port 8080 on the host to port 80 on the Xen domU
# Check if the redirection rules are correctly applied
REDIRECT_PORTS(){
# Flush existing rules
iptables -t nat -F

echo "1" > /proc/sys/net/ipv4/ip_forward

LAN_INTERFACE="xenbr0"

iptables -t nat -A POSTROUTING -s 172.20.101.23/22 -o xenbr0 -j MASQUERADE

iptables -t nat -A PREROUTING -t tcp -i xenbr0 --dport 2222 -j DNAT --to 172.20.100.178:22

iptables -t nat -A PREROUTING -t tcp -i xenbr0 --dport 8080 -j DNAT --to 172.20.100.178:80

iptables-save > /etc/iptables/rules.v4

# Create a script to load iptables rules during startup
cat > /etc/network/if-pre-up.d/iptables <<EOL
#!/bin/sh
/sbin/iptables-restore < /etc/iptables/rules.v4
EOL

chmod +x /etc/network/if-pre-up.d/iptables

apt-get install -y iptables-persistent

if iptables -t nat -L | grep -qE '(to:172.20.100.178:22|to:172.20.100.178:80)'; then
echo "Port redirection rules have been successfully applied."
else
echo "Failed to apply port redirection rules. Please check iptables configuration."
fi
}

# FUNCTION=STORAGE_SETUP()
# DESCRIPTION:
# Configures /dev/sda4 to be the physical volume of LVM or 'Linux Logical Volume Manager' in order to
Expand All @@ -136,8 +90,22 @@ EOL
#
# REMINDER: Before using this function, ensure that /dev/sda4 ( /dev/nvme0n1p4 ) is a dedicated partition you created for LVM use
STORAGE_SETUP() {
pvcreate /dev/nvme0n1p4
vgcreate vg0 /dev/nvme0n1p4
printf "%s\n\n" "---------------- LS PARTITIONS --------------------"
lsblk --list
printf "\n%s\n\n" "---------------------------------------------------"
sleep 3

printf "%s\n" "------------- LVM CONFIGURATION -----------------"
printf "%s\n" "WHICH LVM PARTITION?"
printf "%s\n" "SET EXAMPLE: /dev/sda4"

read -p "SET PARTITION: " get_partition
sleep 2
printf "%s\n" "PARTITION CHOSEN: $get_partition"
printf "%s\n" "--------------------------------------------------"

pvcreate $get_partition
vgcreate vg0 $get_partition
}

DEPENDENCIES_MAIN(){
Expand All @@ -146,11 +114,36 @@ DEPENDENCIES_MAIN(){
INSTALL_XEN_DEPENDENCIES
INSTALL_UTILS
CONFIGURE_GRUB_FOR_XEN
NETWORK_CONFIG
REDIRECT_PORTS
STORAGE_SETUP
reboot now

echo "------DEPOIS DE REBOOTAR PODE CONFIGURAR REDE-------"

printf "%s\n" "REBOOTING MACHINE?"
printf "%s\n" "[ 1 ] - REBOOTING"
printf "%s\n" "[ 2 ] - NOT REBOOTING"

read -p "number: " number
if [[ "$number" -eq 1 ]]; then
echo "REBOOTING..."; sleep 3
shutdown -r now
else
printf "%s\n" "---> EXECUTING redirectPort.sh FOR REDIRECT PORTS"
echo "NOT REBOOTING..."; sleep 3
fi

printf "%s\n" "NETWORK CONFIGURE?"
printf "%s\n" "[ 1 ] - YES"
printf "%s\n" "[ 2 ] - NO"

read -p "number: " num
if [[ "$num" -eq 1 ]]; then
echo "CONFIGURATING..."; sleep 3
NETWORK_CONFIG
else
printf "%s\n" "---> EXECUTING redirectPort.sh FOR REDIRECT PORTS"
echo "NOT CONFIGURATING..."; sleep 3
fi
}

DEPENDENCIES_MAIN

60 changes: 60 additions & 0 deletions rejuvenation/setup/xen/redirectPort.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/usr/bin/env bash
# how use
# bash redirectPort.sh REDIRECT_PORTS

# ############################## IMPORTS #############################
# source ../../virtualizer_functions/xen_functions.sh
# ####################################################################

# REDIRECT_PORTS()
# DESCRIPTION:
# Redirect SSH traffic from port 2222 on the host to port 22 on the Xen domU
# Redirect HTTP traffic from port 8080 on the host to port 80 on the Xen domU
# Check if the redirection rules are correctly applied
REDIRECT_PORTS(){
mkdir -p /etc/iptables

# Flush existing rules
iptables -t nat -F

echo "1" > /proc/sys/net/ipv4/ip_forward

# NOT ADD DOUBLE QUOTE
iptables -t nat -A POSTROUTING -s $GET_IP_ROUTE -o $LAN_INTERFACE -j MASQUERADE
iptables -t nat -A PREROUTING -i $LAN_INTERFACE -p tcp --dport 2222 -j DNAT --to $NEW_IP:22
iptables -t nat -A PREROUTING -i $LAN_INTERFACE -p tcp --dport 8080 -j DNAT --to $NEW_IP:80

iptables-save > /etc/iptables/rules.v4

# Create a script to load iptables rules during startup
cat > /etc/network/if-pre-up.d/iptables <<EOL
#!/bin/sh
/sbin/iptables-restore < /etc/iptables/rules.v4
EOL

chmod +x /etc/network/if-pre-up.d/iptables

apt-get install -y iptables-persistent

if iptables -t nat -L | grep -qE "(to:$NEW_IP:22|to:$NEW_IP:80)"; then
echo "Port redirection rules have been successfully applied."
else
echo "Failed to apply port redirection rules. Please check iptables configuration."
fi
}




# adicionar iptables na vm xen
# apt update
# apt install iptables
# iptables -t nat -A PREROUTING -p tcp --dport 8080 -j REDIRECT --to-port 80
# isso libera o redirecionamento do nginx para o host do virtualbox usando porta 8080 -> 80
# ver se isso funciona com o ssh
# ver se isso funciona fora do virtualbox, um pc cliente

# update
# iptables -t nat -A POSTROUTING -s $GET_IP_ROUTE -o $LAN_INTERFACE -j MASQUERADE
# para usar a faixa de ips ao inves de um ip especifico
# verificar o ip route para obter a faixa de ip da interface
Loading