Setup DDM System

First, make sure you have a working CDN and ssh password-less from the DNS server to all the hosts and VMs in the CDN.

pssh/pscp

  • Execute the following commands on the DNS server virtual machine:

pssh will be used by the DDM system to control the start and stop of the VMs on the host machines.

pssh executes ssh commands in parallel. pscp executes scp in paralle.

General usage:

First create a file contains target IPs. In the example setup, the hosts.txt should be:

192.168.10.11
192.168.10.12
192.168.10.15

Then test the pssh command:

[root@localhost ~]# pssh -l username -h hosts.txt -P 'hostname'
192.168.10.12: fulla.seclab.lan
[1] 16:08:22 [SUCCESS] 192.168.10.12
192.168.10.11: balour.seclab.lan
[2] 16:08:22 [SUCCESS] 192.168.10.11
192.168.10.15: fenrir.seclab.lan
[3] 16:08:22 [SUCCESS] 192.168.10.15

At this moment, you should have all reverse proxy servers setup. If you haven't turn them off, run the following command to turn them off:

[root@localhost ~]# pssh -l username -h hosts.txt -P 'vboxmanage controlvm CentOS poweroff'
[1] 16:15:50 [SUCCESS] 192.168.10.11
[2] 16:15:50 [SUCCESS] 192.168.10.12
[3] 16:15:51 [SUCCESS] 192.168.10.15

Now turn them on with:

[root@localhost ~]# pssh -l username -h hosts.txt -P 'vboxmanage startvm CentOS --type headless'
192.168.10.12: Waiting for VM "CentOS" to power on...
VM "CentOS" has been successfully started.
[1] 16:12:45 [SUCCESS] 192.168.10.12
192.168.10.15: Waiting for VM "CentOS" to power on...
VM "CentOS" has been successfully started.
[2] 16:12:45 [SUCCESS] 192.168.10.15
192.168.10.11: Waiting for VM "CentOS" to power on...
VM "CentOS" has been successfully started.
[3] 16:12:46 [SUCCESS] 192.168.10.11

Wait few minutes and run the following command to get the gust IP and its relative host IP:

[root@localhost ~]# pssh -l username -h hosts.txt  -t30 -P 'vboxmanage guestproperty enumerate CentOS | grep V4/IP' | grep V4/IP | awk '{print substr($5,1, length($5)-1),substr($1,1, length($1)-1)}'
192.168.10.131 192.168.10.11
192.168.10.132 192.168.10.12
192.168.10.133 192.168.10.15

Create another file guests.txt and save the IPs of the guest and execute:

[root@localhost ~]# pssh -h guests.txt -P 'hostname'
192.168.10.131: localhost.localdomain
[1] 16:18:31 [SUCCESS] 192.168.10.131
192.168.10.132: localhost.localdomain
[2] 16:18:31 [SUCCESS] 192.168.10.132
192.168.10.133: localhost.localdomain
[3] 16:18:31 [SUCCESS] 192.168.10.133

With all above test successful, you can move on to next step. You can leave the VMs on or off that does not matter, the script can start from any status.

ddm.py

Before running the script, make sure the DNS server and the above pssh commands are tested and running properly.

Download the ddm.py script to the DNS server from the following link: https://github.com/sonusz/dynamic-cdn/blob/master/ddm.py

Edit the ddm.py script and modify the following lines according to your need:

host_username = 't1'        # This is the user name on the host machines with reverse proxy virtual machine pre-configured
guest_username = 'root'     # This is the user name on the reverse proxy virtual machine
hosts_file = '~/hosts.txt'  # All IPs of the host machines that runs reverse proxy virtual machines. One IP per line,no punctuations needed.
domain = 'ddm.lan'          # The base domain of the mitigation system. The resolved domain will be "edge.ddm.lan"
zone_file = '/etc/named/zones/db.ddm.lan'   # Zone file path
minimum_proxies = 2         # If available number of reverse proxy virtual machine is less than this value, start more VMs
maximum_proxies = 2         # If available number of reverse proxy virtual machine is more than this value, stop one VM

The ddm.py automates the above tested pssh commands and controls the CDN you previously built. It checks the overall availability using "curl get" to each of the running reverse proxy nodes and decide whether to add more reverse proxy node or turn off some nodes.

To run the script:

[root@localhost ~]# python3.6 ddm.py

To stop the script: Hit Ctr + C

There will be some of the edge VMs still running and some turned off when stopped the script. You can restart the script if needed and no need to start or stop all edge nodes before restart.

At the end of your expireemnt, it is better to turn all edge VMs off.

results matching ""

    No results matching ""