Planning for Dockerized WordPress

The home project I’ve been working on is to migrate this blog site hosted on ipage.com to Oracle Cloud Infrastructure. On my way to it, I’m also dockerize it.

Before I start a WordPress container, I should think about how I’m going to host the dockerized WordPress. In other words, I need to think about the architecture. Here is what I’m thinking.

I’m going to list the things I will work on.

  • Open ports 80 and 443. Possibly just open http and https in firewalld.
  • Install NGINX, start and enable it.
  • Install Docker Compose.
  • Create docker compose file and start WordPress.
  • Open port 80 to the instance on OCI side.
  • Map Docker 80 to 80 just to test it.
  • Create SSL certificate using https://www.sslforfree.com/
  • Implement SSL on NGINX
  • Route port 443 traffic to NGINX to port 80 of the WordPress container. Make sure it works.
  • Migrate the data.
  • Change DNS to point the IP address hosted on OCI.

There is still quite a bit of way to go but it’s going to be fun.

 

How to Install Docker on Oracle Linux 7.7

I previously wrote an article on how to install Docker on CentOS 7. I’m going to write up an article for Oracle Linux 7.7 this time. It’s the same Docker after all, so the end result should be pretty much the same.

First of all, SSH into your VM on OCI.

$ ssh opc@[the public IP address]

Update the host.

$ sudo yum -y update

Install Docker.

sudo yum install -y docker-engine

Start Docker.

$ sudo systemctl start docker

Configure Docker to survive restarts.

$ sudo systemctl enable docker

Run hello-world container to test the Docker engine.

$ sudo docker run hello-world

Check the running (but exited) container.

$ sudo docker ps -a

Remove the container.

$ sudo docker rm [container ID]

List the local images.

$ sudo docker images

Remove the local image.

$ sudo docker rmi [image ID]

Recap

Wow, that was a breeze. I could have added Docker’s yum repository to install the latest and greatest bits but then I’d rather go with Oracle’s repo because the version must have gone through tests for Oracle Linux. This looks promising and I’m one step closer to hosting my WordPress blog on OCI.

SSH from Another Machine to a VM on Oracle Cloud Infrastructure

When you create an instance of VM, you provision it with your RSA public key on the machine where you were working at that time. Let’s imagine a situation where you want to access your VM on OCI but from another machine. Here are the steps you could take.

  1. Start terminal.
  2. Generate an RSA key using ssh-keygen if one doesn’t exist already on another machine where you want to SSH to the VM on OCI from.
  3. Run cat to print the public RSA key to your terminal. Make the public key available to the original machine that you used to access the VM on OCI.
    $ cat ~/.ssh/id_rsa.pub
  4. From the original machine where you already have an access to the VM on OCI, SSH to the VM.
    $ ssh opc@[the public IP address]
  5. Edit the file ~/.ssh/authorized_keys with vi.
    $ vi ~/.ssh/authorized_keys
  6. There should already be RSA public key in the file for your machine. Add the RSA key generated in step 3.

    Sorry if the image above is hard to comprehend. The text from the cursor below is the RSA public key for the new machine you want to access the OCI VM from.
  7. Save it and access the VM from the new machine.
    $ ssh opc@[the public IP address]

Recap

By adding public RSA key to authorized_keys file under ~/.ssh directory, you can access to the VM from another machine.

How to Start a VM on Oracle Cloud Infrastructure

The goal of this blog article is to make sure the readers know how to spin up a VM and SSH into it so that they can start to manage it. My ultimate goal is to migrate this blog hosted at ipage.com to Oracle Cloud Infrastructure. Before I can start to migrate my blog to Oracle Cloud Infrastructure (OCI), I need to be able to spin up a VM on it.

First of all, you need to create an account. It’s mostly you entering your information such as your name, credit card, address and phone number. If you don’t want to do it, you are out of luck unless your company provides you with an access. Most cloud services charge based on your usage and there are options to limit your usage based on your budget, but to use it as a resource for your personal blog site, the amount of money you’d have to spend should not be much. I will show the amount I’m spending every month.

If you go to oracle.com, there is a link to get into Oracle Cloud Infrastructure (OCI). Click Sign in to Cloud. I obviously assume that you’ve already created an account.

Now you are asked to enter your account (tenancy) name.

Then you will be asked to enter username (your email) and password.

The image below shows the console of OCI as of January 2020.

Click upper left corner to show the OCI menu and click Instances under Compute.

Click Create Instance button.

 

Now I’m naming the VM “wordpress”. We will choose to use Oracle Linux 7.7 for this time. You can alternatively click Change Image Source to select a different image.

If you click Show Shape, Network and Storage Options link, you can choose different options for your VM. We will choose all free options for this.

Make sure you select Assign public IP address option so that you can access the VM from your local machine.

Click Paste SSH Keys option and copy and paste your public SSH key from your machine to the textbox. If you have not created an SSH key on your local machine, refer to a document like this one to create one.

Click Create button. You will have to wait for a while until the VM is provisioned. Once it’s complete, check the public IP address for the VM.

Now, open your terminal and enter a command like the following.

$ ssh opc@[the public IP address]

opc is the default user for Oracle Linux instance provided by Oracle and it has sudo privilege.

Execute yum to update the host.

$ sudo yum -y update

Recap

In this blog, we covered how to create an instance of VM and to SSH into it on Oracle Cloud Infrastructure.

Migrating WordPresss to Oracle Cloud Infrastructure

My blog is hosted at ipage.com. I don’t really have a problem with it. The price is very reasonable and I’ve been with them for a few years.

I’m an engineer and I want to have control over every single thing. The best option is to move my blog to cloud. By doing this project, I will be learning how things work with Oracle Cloud Infrastructure.

Here is what I have already done.

  1. Created my own personal Oracle Cloud Infrastructure account and set the budget limit though I have 30 days trial with $300 credit so I have a plenty of time.
  2. Created a Oracle Linux 7 VM.
  3. Installed Docker on it. Referred to this article.
  4. Downloaded my WordPress files to my local dev machine.
  5. Backed up MySQL database as SQL file as data backup.

As you may be able to see, I’m planning to migrate my WordPress blog to Docker. I will try to blog about the process I’m taking in the coming days.

Parsing syslog with Bash

I’ve got /var/log/syslog that constantly gets written by my cron job. I want to list all the log that I had cron job write. Here is how grep can help.

# under /var/log
$ grep Windows10 syslog

Here is the result.

Jan 23 00:30:01 linux-mint amaterasu48: Windows10 VM is already running
Jan 23 01:00:02 linux-mint amaterasu48: Windows10 VM is already running
Jan 23 01:30:01 linux-mint amaterasu48: Windows10 VM is already running
Jan 23 02:00:01 linux-mint amaterasu48: Windows10 VM is already running
Jan 23 02:30:01 linux-mint amaterasu48: Windows10 VM is already running
Jan 23 03:00:01 linux-mint amaterasu48: Windows10 VM is already running
Jan 23 03:30:01 linux-mint amaterasu48: Windows10 VM is already running
Jan 23 04:00:01 linux-mint amaterasu48: Windows10 VM is already running
Jan 23 04:30:01 linux-mint amaterasu48: Windows10 VM is already running
Jan 23 05:00:01 linux-mint amaterasu48: Windows10 VM is already running
Jan 23 05:30:02 linux-mint amaterasu48: Windows10 VM is already running
Jan 23 06:00:01 linux-mint amaterasu48: Windows10 VM is already running
Jan 23 06:30:01 linux-mint amaterasu48: Windows10 VM is already running
<snip>
Jan 23 16:00:01 linux-mint amaterasu48: Windows10 VM is already running
Jan 23 16:30:01 linux-mint amaterasu48: Windows10 VM is already running
Jan 23 17:00:01 linux-mint amaterasu48: Windows10 VM is already running
Jan 23 17:30:01 linux-mint amaterasu48: Windows10 VM is already running
Jan 23 18:00:01 linux-mint amaterasu48: Windows10 VM is already running
Jan 23 18:30:02 linux-mint amaterasu48: Windows10 VM is already running
Jan 23 19:00:02 linux-mint amaterasu48: Starting Windows10 VM...
Jan 23 19:00:06 linux-mint amaterasu48: Windows10 VM started successfully
Jan 23 19:30:01 linux-mint amaterasu48: Windows10 VM is already running
Jan 23 20:00:01 linux-mint amaterasu48: Windows10 VM is already running
Jan 23 20:30:01 linux-mint amaterasu48: Windows10 VM is already running
Jan 23 21:00:01 linux-mint amaterasu48: Windows10 VM is already running
Jan 23 21:30:02 linux-mint amaterasu48: Windows10 VM is already running

Kinda boring. I want to exclude “Starting Windows 10 VM…” and “Windows10 VM started successfully” lines. Here is how.

grep Windows10 syslog | grep -v -e Starting -e started

Here is the result.

Jan 23 00:30:01 linux-mint amaterasu48: Windows10 VM is already running
Jan 23 01:00:02 linux-mint amaterasu48: Windows10 VM is already running
Jan 23 01:30:01 linux-mint amaterasu48: Windows10 VM is already running
Jan 23 02:00:01 linux-mint amaterasu48: Windows10 VM is already running
Jan 23 02:30:01 linux-mint amaterasu48: Windows10 VM is already running
Jan 23 03:00:01 linux-mint amaterasu48: Windows10 VM is already running
Jan 23 03:30:01 linux-mint amaterasu48: Windows10 VM is already running
Jan 23 04:00:01 linux-mint amaterasu48: Windows10 VM is already running
Jan 23 04:30:01 linux-mint amaterasu48: Windows10 VM is already running
Jan 23 05:00:01 linux-mint amaterasu48: Windows10 VM is already running
Jan 23 05:30:02 linux-mint amaterasu48: Windows10 VM is already running
Jan 23 06:00:01 linux-mint amaterasu48: Windows10 VM is already running
Jan 23 06:30:01 linux-mint amaterasu48: Windows10 VM is already running
Jan 23 07:00:01 linux-mint amaterasu48: Windows10 VM is already running
<snip>
Jan 23 15:30:01 linux-mint amaterasu48: Windows10 VM is already running
Jan 23 16:00:01 linux-mint amaterasu48: Windows10 VM is already running
Jan 23 16:30:01 linux-mint amaterasu48: Windows10 VM is already running
Jan 23 17:00:01 linux-mint amaterasu48: Windows10 VM is already running
Jan 23 17:30:01 linux-mint amaterasu48: Windows10 VM is already running
Jan 23 18:00:01 linux-mint amaterasu48: Windows10 VM is already running
Jan 23 18:30:02 linux-mint amaterasu48: Windows10 VM is already running
Jan 23 19:30:01 linux-mint amaterasu48: Windows10 VM is already running
Jan 23 20:00:01 linux-mint amaterasu48: Windows10 VM is already running
Jan 23 20:30:01 linux-mint amaterasu48: Windows10 VM is already running
Jan 23 21:00:01 linux-mint amaterasu48: Windows10 VM is already running
Jan 23 21:30:02 linux-mint amaterasu48: Windows10 VM is already running

Now let’s see how many occurrence there are.

$ grep Windows10 syslog | grep -v -e Starting -e started | wc -l

It simply counts the number of lines of the stdout.

Let’s make it more useful for an engineer’s life. I often need to copy and paste the log in another system where markdown is allowed. This means I could format the stdout and use it to copy and paste it in my markdown documentation. Here is what I can do.

grep Windows10 syslog | grep -v -e Starting -e started | sed 's/^/* /g' | tee ~/tmp/hoge.txt

The output result looks like this.

* Jan 23 00:30:01 linux-mint amaterasu48: Windows10 VM is already running
* Jan 23 01:00:02 linux-mint amaterasu48: Windows10 VM is already running
* Jan 23 01:30:01 linux-mint amaterasu48: Windows10 VM is already running
* Jan 23 02:00:01 linux-mint amaterasu48: Windows10 VM is already running
* Jan 23 02:30:01 linux-mint amaterasu48: Windows10 VM is already running
<snip>
* Jan 23 20:30:01 linux-mint amaterasu48: Windows10 VM is already running
* Jan 23 21:00:01 linux-mint amaterasu48: Windows10 VM is already running
* Jan 23 21:30:02 linux-mint amaterasu48: Windows10 VM is already running
* Jan 23 22:00:01 linux-mint amaterasu48: Windows10 VM is already running

What’s happening here is you format the output using sed. It basically adds an asterisk and a space at the very first part of each line and it also writes the result out to the ~/tmp/hoge.txt using tee command. This way you could go back to the text file to get the formatted text later as well.

Since I have done so much PowerShell scripting in the past, I kind of still miss the concept of everything you get is an object. Bash depends heavily on stdout but it is very fast and efficient.

How to Pull Remote Branch in Git

There may be a branch someone else pushed to the server and you want to work with it. What should you do? Here is how you can accomplish.

First, create a local branch out of the remote branch.

$ git fetch origin remote-branch-name:remote-branch-name

Now checkout the branch.

$ git checkout remote-branch-name

You don’t really want to do something like…

$ git pull origin remote-branch-name

This will get the source from the remote-branch-name branch and merge the code into the master (or whichever you have checked out) branch automatically unless you have a conflict. I had to do git reset –hard [the commit ID] to undo it.

What to Study

I’m at a point where I need to decide what to focus on. The software engineering field is so vast and all of them are interesting so I tend to go from one topic to another so often like a butterfly flying from one flower to another. I feel like I’m constantly in a candy store while I’m at work because the work I do is very interesting.

I should stop it. I should allocate certain amount of time to focus on a topic. The job I have right now requires me to be knowledgeable about Oracle Cloud administration so I will do it for the next 2 months at least.