📜 ⬆️ ⬇️

Your cloud hosting in 5 minutes. Part 0: Virtualization



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:


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:

 # Host 1 ansible_ssh_host: 5.9.45.106 # IPv4    ansible_ssh_user: root #    # net vm_bridge: virbr0 ipv4: true ipv4_address: 5.9.45.106/27 # IPv4      ipv4_gateway: 5.9.45.97 # IPv4    ipv4_dns: 213.133.100.100 213.133.98.98 213.133.99.99 # Hetzner IPv4 DNS ipv6: true ipv6_address: 2a01:4f8:163:326a::2 # IPv6    ipv6_mask: 64 ipv6_gateway: fe80::1 # IPv6    ipv6_dns: 2a01:4f8:0:a0a1::add:1010 2a01:4f8:0:a102::add:9999 2a01:4f8:0:a111::add:9898 # Hetzner IPv6 DNS # apt apt_host: ftp.de.debian.org 

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:

 # Debian 1 # kvm-host ansible_ssh_host: 5.9.45.106 # IP   ( )  ansible_ssh_user: root #   ( )  # vnc (port: 5900) vnc_password: "kBz4Yp3UyVEPMr" #     VNC  # vm vm_num: 1 # uniq 0-15 vm_name: debian1 #     vm_hdd_size: 10G #  10  vm_memory: 2048 #    vm_swap_size: 2048 #      vm_cpu: 2 #   vm_bridge: virbr0 vm_root_password: "3yMAqs3yTcuKvZ" #   root    # net vm_ipv4: true vm_ipv4_address: 5.9.244.210 # IPv4    vm_ipv4_mask: 29 vm_ipv4_gateway: 5.9.244.209 # IPv4    vm_ipv4_dns: 213.133.98.98 213.133.99.99 213.133.100.100 # Hetzner IPv4 DNS vm_ipv6: true vm_ipv6_address: 2a01:4f8:163:326a::d1 # IPv6    vm_ipv6_mask: 64 vm_ipv6_gateway: fe80::1 # IPv6    vm_ipv6_dns: 2a01:4f8:0:a0a1::add:1010 2a01:4f8:0:a102::add:9999 2a01:4f8:0:a111::add:9898 # Hetzner IPv6 DNS vm_mac: 00:52:54:56:88:88 

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 :


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 .

Source: https://habr.com/ru/post/277657/


All Articles