官术网_书友最值得收藏!

Installing Ubuntu

When you start your VM for the first time, VirtualBox will ask for a startup disk. The startup disk should install our operating system, but we don't have one yet. Head over to https://www.ubuntu.com/ and find the server download. At the time of writing this, I downloaded Ubuntu Server 16.04.1 LTS (Long Term Support). The default download should be an iso file.

Technically speaking, there is no such thing as Ubuntu Server. It is all just Ubuntu. The only difference between Ubuntu and Ubuntu Server is the installation procedure and the preinstalled packages that come with it.

Once you have downloaded the Ubuntu iso file, start the VM. When it asks for the startup disk, you can browse your computer and select the Ubuntu iso file. Once it is selected, click Next and the installation will begin.

If you ever lose your mouse cursor in the VM and you cannot deselect, minimize or close your VM, use the right- Ctrl key to get your VM out of focus. If, for some reason, you did not follow my tutorial and backed out of the installation, you may find that your VM gives you the error message FATAL: No bootable medium found! System halted. If this is the case, you can close your VM (using VirtualBox, like using the off button on your physical computer) and then go to the settings of your VM to select a bootable medium, which is your Ubuntu iso file:

When you select the iso file and restart your VM, it will now take you to the installer again and you can follow the steps as explained.

First, you have to choose the language (you can navigate using the up and down arrow keys and select using the Enter/return key; use the left and right arrow keys to select <Go back>). I have chosen English and I suggest you do too, so you can follow along with the tutorial (and the rest of the book) without translating everything. In the menu that follows, pick the top option, Install Ubuntu Server. Next, you have to pick a language for your installation. Again, I picked English. The next step is to pick your location, which will, among other things, determine your time zone. I've actually picked The Netherlands here and I suggest you look for your own location as well. If you are lucky, you will be taken to the keyboard configuration. However, if, like me, you picked a language that is not spoken in your location (and we don't speak English in the Netherlands) or your locale is not preinstalled, you will be prompted to pick a locale first. I have picked United States (en_US.UTF-8).

So, next up is the keyboard layout. I recommend following the automatic keyboard detection, unless you know your keyboard layout (there are loads of them).

After you have determined your keyboard layout, you will see some progress bars. After that, you need to specify a host name. Again, I picked ciserver (no spaces or capitals this time). Next, you are prompted for your real name (Sander Rossel), and after that, you can make up a username (sander). After that, pick a password (1234 or whatever; you will only use this on your local computer anyway). Re-enter the password. If your password is a weak password (like 1234), the next question will be if you are sure that you want to use this weak password. Next, do not encrypt your home directory. You can just accept the chosen time zone. For your disk partition, choose the default, Guided - use entire disk and set up LVM. An LVM is a Logical Volume and allows you to dynamically create, resize, or delete partitions. After that, just choose Yes and Continue until a few more progress bars appear. Leave the HTTP proxy empty and continue. Also, do not install automatic updates. After that, the installation will prompt you to pick some software to install. Leave the standard system utilities selected, but do not select any of the other software. We can always install other software manually later. After that, choose to install the GRUB boot loader.

Hooray, you have now successfully installed Ubuntu Server. The VM will now restart and you can log in with the credentials you chose during installation (for me, that is the username sander and the password 1234):

You would do well to make frequent backups of your VM. It is as easy as copy/pasting some files. VirtualBox stores the VM files in the folder specified under the Preferences | General | default machine folder. Simply copy/paste the folder of the VM your want to backup. Restoring is as easy as replacing the VM files with your back up files. Doing this allows you to play around and mess up your VM without having to worry about going through the entire installation again. Backup after each of the subsequent steps, so you never lose work.

You will notice that Ubuntu gives you nothing more than a command line. We have just installed a server, and servers do not really need fancy user interfaces. User interfaces do come in handy, especially when you are not used to doing everything through a command. Luckily, Ubuntu does actually have a user interface (multiple actually); it is just not installed. In this book, I am not going to use the Ubuntu desktop, but if you want, you can install it by simply running the following commands:

sudo apt-get update
sudo apt-get install ubuntu-desktop

When the installation is done, you can restart either by using the reboot command or by using, poweroff command and then restarting from VirtualBox again.

If you are not familiar with Linux terminology, these terms are superuser do (sudo) (so you are running the commands as an administrator) and Advanced Packaging Tool (apt). apt-get update makes sure your packages source is up to date (it does not update packages!). You should run this before installing a package to make sure you install the most recent version. apt-get install some-package installs a package.

The next thing we will need to do is to make sure we can access our Ubuntu server running in the VM from our host. To do this, we first need to close our VM. After that, go to the settings of that VM and go to the Network tab. Select Adapter 2 and select the Enable Network Adapter box. After that, pick Host-only Adapter in the Attached to dropdown. Save your changes and start up the VM again. It gets a little tricky from here. Log in to your VM and execute the command ls /sys/class/net. This will list your available network devices. You should be seeing something like enp0s1 enp0s2 lo (the numbers of enp0s# may vary; I actually had 3 and 8). The next thing we need to do is add one of those enp0s#'s to your network settings. First though, open your VirtualBox preferences (under the File menu) and go to the Network settings. There, select the Host-only Networks tab and select the network you used for your VM's second adapter (there should be only one). Now check out the DHCP Server tab, specifically Lower Address Bound. You will need this IP address (or any IP address between the lower and upper bound). Mine was 192.168.56.101, so I suspect it will be the same for you. Now, edit your network settings in Ubuntu. To do this, open the /etc/network/interfaces file in vi; you can do this by executing the command sudo vi /etc/network/interfaces. Now, press I to edit and add the following lines to the file:

auto enp0s8
iface enp0s8 inet static
address 192.168.56.101
netmask 255.255.255.0

Once you have made the changes, hit Esc to stop editing and run :wq to exit and save (or :q! to exit without saving). Restart your VM again (using poweroff or reboot), log in to Ubuntu, and use the ifconfig command. If everything went well, you should now see your three network devices listed.

While the default Network Address Translation ( NAT) network adapter gives your VM access to the Internet through the host, the host-only adapter is a method that actually makes your VM visible to the host. The settings for this network adapter roughly translate as follows:
  • auto enp0s8: Automatically brings up the enp0s8 device when Ubuntu boots
  • iface enp0s8 inet static: Gives the enp0s8 network interface a static (as opposed to dynamic, or dhcp) IPv4 address (inet6 for IPv6)
  • address: The actual IP address
  • netmask: The netmask
Using this VM, we are trying to mimic a real-world server. In the real world, security is of utmost importance. It is possible to run all the tools we are going to install on SSL (HTTPS) and even restrict the login to specific IP addresses. However, since this is not the real world, the VM will only be available from the host, and additional security is more work before we can actually get to writing code and using tools, I will leave such security to you for practice.
Remembering your IP address every time you need to access your server (for applications such as Git, Jenkins and others) is rather tiresome. Unfortunately, it is not easy to map your IP address to a human-readable host name, such as ciserver. Luckily, in Windows, we do have a little workaround. Find the  C:\Windows\System32\drivers\etc\hosts  file and open it in Notepad (as administrator). Add the following line at the bottom of the file:  192.168.56.101 ciserver . Be sure to replace the IP address with your own. You can now access your server by navigating to  ciserver[:port] .
主站蜘蛛池模板: 九台市| 玉山县| 榆中县| 汕尾市| 康马县| 宣武区| 专栏| 台东市| 交口县| 南安市| 宁津县| 定南县| 交口县| 都匀市| 美姑县| 平乐县| 宿松县| 互助| 隆安县| 彭泽县| 黄骅市| 马关县| 乐平市| 唐海县| 什邡市| 莆田市| 绥德县| 泗水县| 福建省| 巴南区| 张北县| 濮阳县| 温宿县| 扎兰屯市| 尼玛县| 阳泉市| 鄂尔多斯市| 罗源县| 高密市| 都江堰市| 秦皇岛市|