Get startedGet started for free

Lab Review: Working with Virtual Machines

1. Lab Review: Working with Virtual Machines

In this lab, you created a customized Virtual Machine instance by installing base software which was a headless Java runtime environment and application software specifically a Minecraft Game Server. You customize the VM by preparing and attaching a high-speed SSD and you've reserved a static external IP address so that the address will remain consistent. Using that IP address, you then verify the availability of the gaming server online. Next, you set up a backup system to backup the service data to a Cloud Storage bucket, and then you tested that backup system. You then automated backups using cron. Finally, you set up maintenance scripts using metadata for graceful startup and shutdown off the server. Many of these techniques including these script automation can be adapted to administration of production servers in any application. You can stay for a lab walk-through. But remember that GCPs user interface can change. So your environment might look slightly different. So here I am in the VM Instances page. Let's go ahead and create our instance. We're going to use the same properties that are provided to us, properties and values in the lab. So I'm going to call this the mc server for our Minecraft Server. We're going to place this in the US Central one, a zone. We're going to modify the access scopes for this. So I'm going to set axis for each API. I'm going to modify for storage that besides just read only, I want read write. This is going to allow the VM instance to write to the Cloud Storage bucket that we're going to create later on. Now we're also going to modify the disk of this instance. So let's expand the option down here, and under disks we're going to add a new disk. We're going to call this the Minecraft disk, and we're going to make that an SSD persistent disk. It's going to be blank so no source. Fifty gigabytes is more than enough for what we're trying to do. I'm going to leave the encryption as Google managed key. So let me click done and this is going to create that disk and automatic attach it to the VM. Now under networking, we're also going to add a network tag. This is going to then allow us to locate specific firewall rules, we call that Minecraft Server. On the network interface I'm going to click on the pencil icon here to edit. We are leaving the internal IP as is but for the external IP, we're actually going to create an IP address which means that we are reserving a static IP address. This is going to make sure that these IP address is not ephemeral and doesn't change. So I'll just give it a name and I click reserve and then we're going to click done once that is reserved and from there we're going to create this instance. It's done and then create. Now once the instance is up and running we're going to have to prepare the data disks. So we're not going to create a directory, format and mount the disk. I don't need this tab over here so I can close that. We're going to wait for the instance there it is. So the SSH to the instance. I'm going to start by creating a director that serves as the amount point for the data off the disk. For that I'm just going to use the command that's provided in the lab and then we're going to format the disk itself. So we're just going to wait for that SSH connection to be established. This is allowed because the default network has a default firewall rule for SSH. So let me go ahead and run that, and then we're going to format the disk. Great. Now we're going to mount it, and this is not going to display any outputs, so don't be surprised about that. There's a checkpoint in the lab. So you can check your progress, worked for me. So I'm going to move on to task three and now install and run the application and the micro server itself runs on top of the Java virtual machine. So we do require the Java Runtime Environment, or JRE, to run. But we don't need the user interface. So we're just going to install actually headless version and that's going to reduce a lot of the resource usage on that machine which will ensure that the Minecraft Server has enough room to expand its own resource usage if needed. So let me go ahead and start by updating the repository. Then I'm going to install that headless JRE, and after that I'm going to navigate to the directory where we mounted that persistent disk. Into that we're then going to download the Minecraft jar file. So we navigate into that under command. You can see it's downloading and the lab manual also provides information on the download page itself. So you can read more about where this comes from. There are also lots of instructions actually in there on how to set this up on a Linux machine. So if you wanted to customize this, I definitely recommend referring to that link. So let's go ahead and initialize the Minecraft Server. Run that command and it's telling us that this is not going to run unless we agree to the end-user licensing agreement. So we need to do that now. Let me just check my progress. Make sure that the JRE installation and Minecraft server installation worked out and I got a green check in my lab. So let's look at the files that were created to identify where this license agreement is, and there it is. We can see it right there. So let me use nano to edit that now. All we really have to do is we have to change this last line, instead of saying false, we just have to agree to it by setting this to true. So let me change that and then we're going to click Control O to write that to that filename hit Enter and then Control X to come back out. So we're not going to try to restart the Minecraft Server yet. We're going to use a different technique in a second. What we're going to do next is we're going to create a virtual terminal screen to start that server, and to do that we're going to install screen. So let's grab that command from the lab instructions. It seems like it was already actually installed. Then we're going to go ahead and start that now using the screen command. So let's run that and this might take a while now but it's going to establish the whole environment for us. So we can see here it's preparing the level world. It's loading some recipe. So these are all now very specific commands in regards to the gaming application that we're installing here and we're going to wait for this to complete before detaching from this and moving on. So we can see that the spawn area here has been completed. We could not detached from this, but one thing I want to point out that we're going to have to do next is when this whole thing started it told us which port it is going to do that for. So the port is right here and we're going to have to create a firewall rule in a second to actually allow client traffic to that port. So we can now detach from this. So we're going to just use Control A and Control D. To get out of here. There is a command if you wanted to reattach to the terminal, we're not going to do that. So I'm just going to exit out of here and we're now going to allow Cloud traffic. So for that, we need to create a firewall rule and we're going to use the network tag that we created which we can display by going to Columns and then Network tags. We can see that Minecraft Server was the network tag. So let's do that. I'm going to navigate to VPC network and specifically Firewall rules. I'm going to give a new firewall rule the name of Minecraft rule. It's going to be on the default network. Could this be the only network we have right now? For specified target tags, we're now going to define Minecraft Server so only apply to the instances that have that tag. So let me define the IP ranges as from anywhere. Now specifically for the protocol that's TCP, and then that port was 25565. Then I'm going to go ahead and click Create. Once it's up and running we're going to verify availability of the server. So I can already start navigating back and I'll monitor the process up here in the notification pane. I'm going back to Compute Engine and we have the external IP address here. We're now going to use a couple of different ways to verify that this is running. Note that we can't click on it because we didn't enable HTTP, that would have been TCP for port 80. In the lab instructions, we have listed a website and we also currently have a Chrome extension there, have that Chrome extension actually right up here. So let's try that. I'm going to go to Options, change the IP address that is in here. Save that, and then we're going to try to verify. I can change this through my Minecraft Server, save those changes and then we're going to keep an eye on here to see if this is coming up. Alternative also we could use any of the websites that are listed in here. Since these are third-party tools sometimes they don't work. So that's definitely something to keep in mind. I think that's actually what's going on right now. With this extension it doesn't seem to want to display this to us right now. But if I check the box in the lab instructions itself, it's telling me that everything is tracked correctly. So we've done all the work. It's just that sometimes, again, these third-party tools that we're using to test the status may not always work. We could grab the external IP address and copy it in there. Get the service status that way. It is telling us that it does have it, so it is up and running currently has no players in it, and it tells us the exact version that we're running. So clearly it is working for this page, just not for the Chrome extension right now. All right. So then let's move on. What we're going to do now is, these services up and running but now we want to actually scheduled some regular backups, have some maintenance around the server so that we plan for the long term. So what I can do now is I can SSH back into the server. Since I allowed for read write access to Cloud Storage, I can actually directly create a bucket now through my server here similarly as you would from Cloud Shell. So the first thing I'm going to do is I'm just going to define my own bucket name, and store it in an environment variable. So here we go, export your bucket name. You want to use something that's globally unique. So one thing we could do is we could take our project ID. You take that right here, and you go back to that server and paste it in there. Whenever you create a an environment variable, you want to run the echo command to make sure that you created it correctly. Here we can see that worked. Now I can use the gsutil command specifically MB for make bucket for Google Cloud Storage, and then use that unique part that I just entered and just append Minecraft backup so that I also know what this is. So this becomes a little bit more readable. Great. So there it is. I could also know verify by the way that it is created in my project. I could go to the navigation menu, and if we go to storage we'll be able to see our bucket right here. We could have also just created this way. But this way we now have everything stored that is the variable in here, and then going forward we can do all of the backup right through the VM. So let's go ahead, and create a backup script. I'm just going to navigate to the home directory that we have within Minecraft, and we're going to just create a new script using nano. I'm going to paste the script that we already have in here which has the screen command, and then talks about the backups. So let me paste this in there, and then we're going to press Control O, and then enter to save and control X to come back. So this script saves the current state of the server's world and pauses a service odyssey functionality. Then it's going to backup the service world data directory and place its content in a Timestamp directory in the Cloud Storage bucket. After the script, I've finished his backup the data it resumes odyssey saving on the Minecraft Server. Now we got to make sure that this is actually executable. So let's run the following command, and now we can go and test this. So let's actually run the backup script so there we can see that we are copying some files. Let's verify that. So I'm going to now navigate into my Cloud Storage bucket that I already have here. If I open that, we can now see a folder in there, and I could dig further into there to get more information about the world. So clearly we can see that the backup is working for us. We can also now schedule the backup to run in and more automated fashion. So I'm going to go back to my SSH session, run the pseudo crontab command. Now we want to choose nano in this case, it does tell us it's easiest but you do have other options available if those are more comfortable. At the bottom, we're now going to define how often this runs. This is going to tell it to run the backup every four hours. There's documentation that you can look into and how to define this, but in this case, that's more than enough for what we're trying to achieve. So let's save that file and get back out. This is going to create a lot of backups. I mean about 300 a month. So maybe you want to look into regular deleting those Cloud Storage does offer Object Lifecycle Management features that let you set the time to live for objects and even archive older objects to a different Storage class. You'll learn more about that in the next course of this series when we talk about Cloud Storage. I'm just going to go ahead and check my progress. In my lab looks like everything worked. The last thing we're going to do is now perform some maintenance. So specifically when we shut down and restart that certain actions happen. So let me run the pseudo screen command, and then I'm going to go and actually stop this instance. So I'm going to go navigate to Compute Engine, click on the server so select it and click stop. It's going to ask us if we sure we want to do that, and yes we're going to stop. Then later if we want to start it back up we can do that. This is also going to log us out of our SSH session obviously. So let's wait for this to stop, and then we're going to automate the server maintenance with some startup and shutdown scripts. So the instance has stopped, am going to click on it now to edit some of the custom metadata. So let me click Edit, and we're going to scroll down to the metadata. Here we go. What we're going to define now is a startup script as well as the shutdown script. We're going to point those to files that we have in Cloud Storage that are publicly available. So the key is going to be startup script URL, and then the value is going to be the location of the file. I can make them bigger to make sure that formatting that correctly. I'll add another item, and we'll do the same for the shutdown script. You can actually navigate yourself to these files if you want to, and you could read more about what exactly happens in these startup and shutdown script. So now I can click Save, and I could restart the service. I did in the meantime while the service was shutting down. I went back to the status page, and you can see that the status as currently says could not resolve so clearly the server is shut down. Now when we restart this, once all the startup script is done running, we can go back and we can verify that this service is indeed now accessible again. Just keep in mind that that might take a while for the actual instance to startup which it is now, and then for the startup script to actually finish.

2. Let's practice!

Create Your Free Account

or

By continuing, you accept our Terms of Use, our Privacy Policy and that your data is stored in the USA.