Menu

HA system

Hideyuki Niwa
Attachments
lxcficon.jpg (1479 bytes)
sca1.jpg (24548 bytes)
sca2.jpg (75439 bytes)
sca3.jpg (89898 bytes)
sca4.jpg (60757 bytes)

HA system

return HOME page

HA system

Let's assemble the system of HA(High Availability) in a simple shell script.

Because it cannot finish explaining the too complex one, let's think by the easy specification shown next.

  1. Ten containers are named LinDev-0010 from LinDev-0001 and it generates it.
  2. It immediately deletes if there is a container that looks out, and stops the generated container, and it generates it with the same name newly.
  3. When the script execution interrupts, all generated containers are deleted and it ends.

It is easy HA. It is such an easy script. However, this can correspond when abnormality is found in the container.

Then, the shell script is shown as follows.

1 #!/bin/sh
2
3 trap 'lxcf erase-n LinDev- 10 ' 0
4
5 echo \"Generate 10 LXCF containers."
6 echo \"lxcf sysgen-n LinDev- 10"
7 lxcf sysgen-n \"LinDev-" 10
8
9 watch_containers() {
10 lxcf list | awk '{if($3==\"stopped")system(\"lxcf erase "$1";lxcf sysgen \"$1" ")}'
11 }
12
13 while sleep 3
14 do
15 watch_containers
16 done
17

It is simple.
The third line is a setting to end after all generated containers are erased when the entire script interrupts with ^c etc.
Trap is a standard command of sh.

"lxcf erase-n LinDev- 10" generates the container of the name of LinDev-0010 from LinDev-0001 with the command of lxcf. Processing does not fail even if there is no container of the corresponding name.

The seventh line generates the container. The sysgen-n subcommand is a command that generates two or more containers at a time. The container that combines prefix of the first argument with the figure of four digits is generated.

The 11th line from the ninth line generates the container with the same name by doing erase if the state of all containers is observed, and there is a container in "Stopped" state, and using sysgen afresh.

The 16th line from the 13th line is infinite loop processing of the main. Watch processing watch_containers of the container is called every three seconds.

Well, let's actually move it.

Virt-manager is started as a preparation.
[file] - [add connection] is chosen from the menu.
"LXC(Linux Containers)" is chosen to be "Hypervisor" by the displayed dialog, and "Connect" button is pushed.

One terminal opens, and it becomes root.
I will preserve the script by the name "HA10".

When HA10 is executed, ten containers are generated.
The list of the container generated on virt-manager is displayed.

Next, LinDev-0003 is done and "It is compulsorily power supply OFF" is done from virt-manager.
This was executed instead of abnormal generation.
How it operates when it occurs abnormality by some containers is actually shown.

The LinDev-0003 container is deleted, and the LinDev-0003 container is generated newly.

When ^c is pushed with Terminal, all containers are deleted.

return HOME page


Related

Wiki: Home

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.