Linux Administration Cookbook
上QQ阅读APP看书,第一时间看更新

Technical requirements

We're again going to use Vagrant and VirtualBox for our work. We'll configure three virtual machines.

I've put together the following Vagrantfile for use in this chapter:

# -*- mode: ruby -*-
# vi: set ft=ruby :

$provisionScript = <<-SCRIPT
sed -i 's#PasswordAuthentication no#PasswordAuthentication yes#g' /etc/ssh/sshd_config
systemctl restart sshd
SCRIPT

Vagrant.configure("2") do |config|

config.vm.provision "shell",
inline: $provisionScript

config.vm.define "centos1" do |centos1|
centos1.vm.box = "centos/7"
centos1.vm.network "private_network", ip: "192.168.33.10"
centos1.vm.network "private_network", ip: "192.168.44.10", auto_config: false
centos1.vm.hostname = "centos1"
centos1.vm.box_version = "1804.02"
end

config.vm.define "centos2" do |centos2|
centos2.vm.box = "centos/7"
centos2.vm.network "private_network", ip: "192.168.33.11"
centos2.vm.network "private_network", ip: "192.168.44.11", auto_config: false
centos2.vm.hostname = "centos2"
centos2.vm.box_version = "1804.02"
end

config.vm.define "ubuntu1" do |ubuntu1|
ubuntu1.vm.box = "ubuntu/bionic64"
ubuntu1.vm.hostname = "ubuntu1"
ubuntu1.vm.box_version = "20180927.0.0"
end

end

It would be advisable to create a folder called Chapter Three and copy this code into a file called Vagrantfile. Running vagrant up from inside the folder containing your Vagrantfile should configure two VMs for testing. Once provisioned, make sure that you can connect to the first by running the following command:

$ vagrant ssh centos1

For this section, ensure that your centos1 VM is running, and connect to it. This section assumes you know networking at a basic level, in the sense that you understand the differences between a static and dynamic IP address, and you know roughly how public and private IP addresses differ.