-
Notifications
You must be signed in to change notification settings - Fork 0
Virtual Machine Installation
A guide for setting up a virtual machine with a linux/red hat OS. This can assist with local testing in an isolated environment and is especially useful for testing your Ansible provisioning playbook. The chap-press
repo can be used with Ansible & Capistrano to test locally on a virtual machine.
For a checklist using the command line, see https://wimops.chapman.edu/wiki/VirtualBox
SSH access
Web access
Firewall
Snapshot
- Virtual Box (5.1.26 >=)
- CentOS 7 (Minimal ISO)
-
Install Virtual Box. Using homebrew:
brew cask install virtualbox
-
Open Virtual Box and click new
-
Name your virtual machine
- Choose linux as the type
- Red Hat (64-bit) as the version
-
Continue with suggested memory size
-
Continue with suggested hard disk size
-
Continue with default hard disk type (VDI)
-
Continue with default option for storage (dynamically allocated)
The virtual box should now contain a virtual machine that is powered off.
-
Click the start option at the toolbar
-
Select CentOS .iso downloaded file from your computer
-
Follow through CentOS install guide
- Setup username
wimops
and passwordchapman123
(will be used for ssh)
- Setup username
-
Install will complete and click the reboot button
Once the VM reboots, you will be able to login in at the VM terminal.
The CentOS currently does not have access to the internet.
-
Check in terminal:
ip addr
-
Change configuration for internet access
sudo vi /etc/sysconfig/network-scripts/ifcfg-enp0s3 # Change ONBOOT line to yes: ONBOOT=yes reboot
CentOS minimal comes with an ssh server so the last step needed to be able to ssh in from our local machine is to setup port forwarding on our VM. Note: If VM has been installed previously, remove localhost:2222
key from ~/.ssh/known_hosts
- Select
Settings
button &Network
tab - Click
Advanced
down arrow & clickPort Forwarding
button
This will allow us to ssh into the VM. - Enter the following settings:
- Host IP: 127.0.0.1
- Host Port: 2222 (or any open local port)
- Guest IP: this is the
ip addr
typed in the VM (10.0.2.15) - Guest Port: 22 (default ssh port)
- Click OK and you should now be able to ssh in from the local terminal.
ssh-copy-id -p 2222 wimops@localhost
ssh -p 2222 wimops@localhost
If a server is installed on the VM, this will allow public access to a specific port.
- On VirtualBox, select machine and click
settings
icon - Click
Network
icon - Click
Advanced
dropdown and clickPort Forwarding
- Click the
plus
icon to add a new port forwarding rule - Enter the following settings:
- Host IP: 127.0.0.1
- Host Port: 5555 (or any open local port)
- Guest IP: 10.0.2.15 (keep as same as VM)
- Guest Port: 80 (or server port)
The firewall settings on CentOS may not allow access to any ports from outside sources. This will allow a user to visit a site via their VM server.
If an Ansible role is not already defined for this:
Go to VM terminal:
Our port forwarding address example is 5555.
sudo firewall-cmd --zone=public --add-port=5555/tcp --permanent
sudo firewall-cmd --zone=public --add-port=80/tcp --permanent
sudo firewall-cmd --reload
sudo firewall-cmd --zone=public --list-ports
# $ 5555/tcp
FirewallD Commands on CentOS
Installing Centos/VirtualBox
This can be used to save the state of your virtual machine before any major modifications. In this case, the snapshot is taken right after the previous configurations were setup. That way if any issues arise or harmful installations executed, the VM can be restored to exactly how it was before.
- Click
Snapshots
button (right side) - Click Camera Icon for Snapshot ( or Ctrl-Shift-S)
- Choose an intuitive name and description (e.g. Clean Install Centos & Config)
The virtual machine snapshot is created.
Revert Snapshot
This will allow you to go back in time to the clean state just after the OS was installed.
- Shut down current VM
- Select the VM and click
Snapshots
button - Click icon for restore (or right-click snapshot) and follow through with restore
The VM will revert itself back to the original snapshot.
Chapman University
One University Drive, Orange, CA 92866 | (714) 997-6815