
Hi Habr! I have already published three parts from a series of articles (
one ,
two ,
three ), and here part 0 is like a lot of snow. How so? The fact is that virtualization is optional when building our hosting. This article is self-sufficient, it is not related to other parts of the cycle. You may not read them at all if you just want to split your dedicated server into several virtual machines.
All that I can tell can be done by an ordinary programmer within 5 minutes, simply by running a set of scripts for Ansible, which I prepared especially for you and
uploaded to GitHub .
Content
Training
Download a
set of scripts or clone the repository:
')
» git clone https://github.com/vkozlovski/ansible-virtualization » git checkout v1.x » cd ansible-virtualization
At this preparatory work can be considered complete.
Oh yeah, I almost forgot, you will need at least one dedicated server with authorization by key.
Configuration
The configuration we will perform on the example of Hetzner. All configuration files that we will edit are in the
host_vars directory:
- dc16-host1-vm1.yml - virtual machine configuration number 1
- dc16-host1-vm2.yml - virtual machine configuration â„–2
- ..
- dc16-host1.yml - host configuration
In our example, we are creating 6 virtual machines, just as many single IP addresses per server can issue Hetzner. Let's analyze what we have here in the configuration files:
dc16-host1.yml
Host configuration:
Hetzner sends
IPv4 and
IPv6 addresses in a letter when ordering a server. The remaining values ​​of the variables you can look in your account. I took the
IPv4 and
IPv6 addresses of the
DNS servers to Hetzner's wiki.
dc16-host1-vm1.yml
Virtual Machine # 1 Configuration:
The values ​​of the variables
vm_ipv4_address ,
vm_ipv4_mask and
vm_ipv4_gateway are sent by Hetzner when ordering an additional
IP address.
The IPv4 and
IPv6 addresses of the
DNS servers are the same as those of the host machine. You can order an additional
IPv4 address in your account. Hetzner asks to indicate the purpose for which you need an additional address, I write one word there - “Virtualization”.
About
IPv6 : each server receives a / 64 subnet. Accordingly, you can take any addresses from it. For example, for
2a01: 4f8: 163: 326a :: / 64 :
- 2a01: 4f8: 163: 326a :: d1
- 2a01: 4f8: 163: 326a :: d2
- ...
- 2a01: 4f8: 163: 326a :: d6
To specify the value of the variable
vm_mac , you need to get a separate
MAC address for the specified
IP . This can be done in your account.
That's all, you can start the launch.
Launch
The launch is done by two teams. The first installs the necessary packages and configures the host machine:
$ ansible-playbook -i prod kvm.yml
The second team creates, configures and starts virtual machines:
$ ansible-playbook -i prod guests.yml
After running and executing these two commands, your virtual machines should be running and accessible from the outside. Your public key was copied to all virtuals, so the authorization will be by key.
Total
We use this set of scripts for quite a long time and everything works as expected. This greatly simplified life and allowed us to quickly add new computing resources to our modest cloud. If you have any questions - welcome to the comments.
That's all. Thank you all for your attention. Stable clouds and good luck to you!
Follow me on Twitter , I talk about working in a startup, my mistakes and the right decisions, about python and everything related to web development.
PS
I'm looking for developers to the company, the details in my profile .