Thursday 27 August 2020

How to run a free Minecraft Server in the Oracle Cloud (3rd. Update)

This is an update to my older posts on how to run a Minecraft Server in the Oracle Cloud. As the OCI is constantly enhancing, I try to keep up describing the easiest way to run your Minecraft server.
Best things in life are free and so could be your Minecraft server. Just get an Always Free subsciption on the Oracle Cloud Infrastructure (OCI) and follow the steps below.
Start at the OCI console startpage. As you can see from the small badges, a VM instance is Always Free Eligible. Choose 'Create a VM instance'.
Give it a name and stick with the defaults. When using an Always Free machine, pick an image and machine combination that is eligible for Free Tier.
Scroll down and adjust the shape, if needed. If this is your first project on OCI, you probably don't have a Virtual Cloud Network. The VM wizard will notice this and offers you, to create such. Give it a name and make sure that 'assign a public IP address' is checked.
Do not forget to upload your ssh public key. For the rest, leave the defaults and click 'Create'
You will get a long list of what OCI will do for you. Wait until it shows 'Running' and copy your public IP address.
The next steps are the same as in OCI-C. Set up a ssh connection with your favorite ssh client. I use PuTTY on Windows. Paste the IP adress and save the session.
Enter the Auto-login username 'opc'.
Under Connection/SSH/Auth choose your private key file. Then save again and open your session.
And here we are, hello OCI. Pull the Minecraft server directly from its publisher via (check for the version you prefer)

wget https://launcher.mojang.com/v1/objects/bb2b6b1aefcd70dfd1892149ac3a215f6c636b07/server.jar

Install the Java version you want to use, e.g.

sudo dnf install java-11-openjdk

Probably this will pull some other updates. Then start the server:

java -jar server.jar

After the first start, the server terminates immediately, because you have to accept the EULA first.
It created a new file eula.txt. Open it in vi and change the content to eula=true.
Before we start the server again, lets open the port in the Linux firewall.

sudo firewall-cmd --permanent --zone=public --add-port=25565/tcp
sudo firewall-cmd --reload

As the Minecraft server has an interactive console, it should be accessible even when the SSH console has been closed in between. I prefer to the screen command for that, which can be installed by.

sudo yum install screen.x86_64

Then open a new screen and start the server with

screen -S minecraft
java -jar server.jar

With the server running, we are done with SSH. Close the screen session via CRTL-A D or just close your PuTTY window. If you want to reconnect to your Minecraft server from a new SSH session, just type

screen -d -r minecraft

Now our Minecraft server is up and running and the Linux firewall is open, so it could serve requests. But we first need to open the Minecraft port on OCI too, because by default on OCI all ports except for ssh are closed for security reasons.
Back to the OCI console, open the Hamburger menu and to to Networking/Virtual Cloud Networks.
There you shoud find a VCN with the name you gave it when creating the instance. Click on the name to open the settings.
Click on Security Lists on the left under Resources.
Click on the Default Security List to open the settings.
From the Ingress Rules you can see, that any incoming TCP traffic, except for ssh, is blocked. So we need to add a rule for our minecraft server here.
By clicking on 'Add Ingress Rule' we can define our rule for CIDR 0.0.0.0/0 (all internet) and the Minecraft server port 25565.
The rule should be listed under Ingress Rules. Now we are done with the OCI setup.
Start Minecraft and configure a new Server. Give it a name and enter the public IP address of your instance.
Your Oracle Cloud instance will be listed in Minecrafts server list, notice the good ping. Double click to start your game.
Have fun with the Oracle Cloud and Minecraft!

BTW: this tutorial is meant to demonstrate the usage of OCI, not to do a perfect Minecraft setup. There are many tutorials to do this, like this one.

The Oracle DB Developer VM: Installing VS Code and first steps

This post is part of my Oracle DB Developers VM series. Based on the previous postings on how to set up Oracle Linux 8 with the Oracle DB on VirtualBox, this post will show how to install Visual Studio Code with the Oracle Integration in this environment on a beginners level.
Gnome, in contrast to KDE, does not come with a good visual editor for developers, so we should install something better. VS Code has gained popularity and Oracle plugins are available, so I use that as an example.
For installing VS Code, just follow the official instructions:

sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc
sudo sh -c 'echo -e "[code]\nname=Visual Studio Code\nbaseurl=https://packages.microsoft.com/yumrepos/vscode\nenabled=1\ngpgcheck=1\ngpgkey=https://packages.microsoft.com/keys/microsoft.asc" > /etc/yum.repos.d/vscode.repo'
sudo dnf check-update
sudo dnf install code
sudo dnf install dotnet-sdk-2.1

We also need to install the .NET Core Runtime for Linux to run the Oracle Developer Tools for VS Code. It is important to use the older version 2.1.
Double check the dotnet installation with

dotnet --list-sdks
dotnet --list-runtimes

That should return something like:
Searching for Code should now show you VS Code in your activities
Moving the icon to the right into the favorites bar makes it also available in the applications menu.
Microsoft did not tag the .desktop file for VS Code correctly, so it does not appear in the applications menu when not put into the favorites. This can be corrected by editing /usr/share/applications/code.desktop and adding ;Programming to the keywords section like this:

[Desktop Entry]
Name=Visual Studio Code
Comment=Code Editing. Redefined.
GenericName=Text Editor
Exec=/usr/share/code/code --no-sandbox --unity-launch %F
Icon=com.visualstudio.code
Type=Application
StartupNotify=false
StartupWMClass=Code
Categories=Utility;TextEditor;Development;IDE;
MimeType=text/plain;inode/directory;
Actions=new-empty-window;
Keywords=vscode;Programming

[Desktop Action new-empty-window]
Name=New Empty Window
Exec=/usr/share/code/code --no-sandbox --new-window %F
Icon=com.visualstudio.code

and here you are:
Start VS Code, go to the extensions tab and search for Oracle.
Choose the official one from Oracle Corporation and click on Install.
After installation of the extension, on the left bar an Oracle DB tab will appear. Click it and in the Oracle Explorer click the plus (+) and insert your credentials.
Double click the newly created connection. Click around, for example choose a table and select Show Data.
Editing stored procedures and functions also works.
To execute some SQL press F1 and choose Oracle: Develop New SQL or PL/SQL
Select your connection
Type some meaningfull SQL and execute it
That should give you the result set.
By choosing View->Editor Layout->Two Rows and moving the results tab into the lower part of the SQL tab, both can be displayed on one page. Of course, code completion also works.

Of course, all of this works also if you install VS Code on your host OS. On Windows, just download and run the installer. The required .dotnet libraries are already part of the OS.

So much for the first steps with VS Code and the Oracle extension. More information can be found on the official Oracle page.

Wednesday 26 August 2020

The Oracle DB Developer VM: Installing SQLDeveloper

This post is part of my Oracle DB Developers VM series. Based on the previous postings on how to set up Oracle Linux 8 with the Oracle DB on VirtualBox, this post will show how to install the Oracle SQLDeveloper 20.2 in this environment on a beginners level.
Download the latest SQLDeveloper from Oracle. I recommend downloading it from your host OS and put it in some directory that is accessible from your VM. I use the version for 'Other platforms', which is not platform specific.
Extract it to the ~/bin directory in your home, next to your sqlcl folder. Start it with

~/bin/sqldeveloper/sqldeveloper.sh

After startup you are immediately prompted to connect to one of your databases.
Choose the one you want ...
... and enter your credentials
It will appear on the left in the Connections-tree and is immediately available for using.
Also add the PDB to your connection list.
You can either select the ORCLPDB entry from the Welcome Page or right-click on Oracle Connections, choose New Connection and fill out the dialog. To make sure that everything is correct, click Test before Connect.

Now for some convenience, and again here is where Gnome 3 gets more in my way than helping me. Create the file /home/oracle/.local/share/applications/sqldeveloper.desktop with an editor and insert the following

[Desktop Entry]
Type=Application
Name=SQLDeveloper
Comment=Oracle SQLDeveloper
Icon=/home/oracle/bin/sqldeveloper/sqldeveloper/doc/icon.png
Exec=/home/oracle/bin/sqldeveloper/sqldeveloper.sh
Terminal=false
Categories=Development;Programming

Then completely restart the VM as it seems that Gnome only loads this files on startup.
Now Gnome finds SQLDeveloper in it's Activities ...
... and also in the Applications Menu under Programming.

And again, you can use the same archive to also run SQLDeveloper on your host OS.
Just unzip the archive to any directory. In my case on Windows I copy the sqldeveloper folder from the zip to D:\Oracle and pin the sqldeveloper.exe to the Taskbar.
SQLDeveloper found my previous connectsions and also offers me to import the new ones from tnsnames.ora, as in my VM.

So with SQLcl and SQLDeveloper we have the basic tools every DB developer needs ready to use in both our VM and the host OS.

Thursday 20 August 2020

The Oracle DB Developer VM: Upgrade SQLcl to latest version

This post is part of my Oracle DB Developers VM series. Based on the previous postings on how to set up the Oracle DB on Linux 8 in VirtualBox, this post will show how to upgrade the VM to use the latest SQLcl.

First we need to install java:

dnf in java-11-openjdk.x86_64
java -version

That should give you the info on OpenJDK:
Download the lastest SQLcl from https://download.oracle.com/otn_software/java/sqldeveloper/sqlcl-latest.zip and unzip it to a directory for all your executables under your home directory. In my case:

cd ~/bin
wget https://download.oracle.com/otn_software/java/sqldeveloper/sqlcl-latest.zip
unzip sqlcl-latest.zip

Test it with

sqlcl/bin/sql

and type version. That should return
Add the following line to your .bashrc:

export PATH=/home/oracle/bin/sqlcl/bin
export SQLPATH=~/sql

Create a directory ~/sql and inside a file named login.sql with the above content.

set statusbar on
set highlighting on

This will enable some of the cool features of SQLcl. It is so easy, this is probably my shortest posting ever. 

But wait, there is more. As you already have downloaded the latest platform independent SQLcl, you can also use it to connect from your host OS to the database in your VM.

So in my case, use Windows Explorer to extract sqlcl to a folder on your drive, eg. D:\Oracle . Put the bin directory into your path. Of course, this SQLcl installation also needs a compatible Java runtime. So if you don't have one, install it first. On Windows better use the installer based version (jdk-11.0.8_windows-x64_bin.exe). I had issues with the JDK zip distributions, probably I have installed and uninstalled so many JDK's, that my Windows Registry is messed up. But the installer based version ran flawless.

sql.exe system@orcldevvm-ol8:1521/orclpdb

Try it with an easy connect string.
You can also connect via TNS. Create a directory like D:\Oracle\network\admin and an environment variable to point to it like

set TNS_ADMIN=D:\Oracle\network\admin

And better make that permanent. Create a tnsnames.ora file in that directory, here is an example to adapt:

ORCL =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = orcldevvm-ol8)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = orcl)
    )
  )

ORCLPDB =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = orcldevvm-ol8)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = orclpdb)
    )
  )

Now try it with TNS connect

sql.exe system@orclpdb

and that should work too.
SQLcl is a super fast and easy way to talk to your Oracle DB.

Tuesday 18 August 2020

Installing Oracle DB 19c on Oracle Linux 8.2 in VirtualBox

This post is part of my Oracle DB Developers VM series. Based on the previous postings on how to set up Oracle Linux 8 on VirtualBox, this post will show how to install the Oracle DB 19.3 in this environment on a beginners level.
The Oracle DB installation on Oracle Linux is straight forward as expected. In this post, I will only list the needed steps for the Oracle Developer VM configuration. For a full documentation and/or installing a production environment, follow the official Oracle documentation and/or have a look at the guide on Oracle-Base. The official documentation is longer for a reason. It covers many more options like other Linux distros (inclusive Linux on IBM System Z), clustering, other storage and networking options. If these are not needed, this post is a quick installation guide.
In this example, we will use the new Image-Based Oracle Database Installation. Download the Oracle DB 19.3 software image from the Oracle Software Delivery Cloud or OTN. If you download it from the host OS, put the zip file somewhere into the shared folders of your VM. I recommend downloading from the host OS, because you can use the install media for several VM's without needing extra space on your HDD.

sudo mkdir -p /u01/app/oracle/product/19.0.0/dbhome_1
sudo chown -R oracle:oinstall

Create the Oracle install directory on the volume we created in the last episode and grant it to the oracle user and group.

Edit .bashrc and add the following to set a minimal environment:

export TMP=/tmp
export TMPDIR=$TMP

export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/19.0.0/dbhome_1
export ORACLE_SID=orcl

export PATH=$ORACLE_HOME/bin:$PATH

export TNS_ADMIN=$ORACLE_HOME/network/admin

Also add the following line to your .bash_profile to run .bashrc on logon:

. .bashrc

Next extract the software to the Oracle home directory and run the installer, in my case

cd $ORACLE_HOME
unzip ~/ddrive/Install/Linux-x64/LINUX.X64_193000_db_home.zip
export CV_ASSUME_DISTID=OEL8.2
./runInstaller
The DISTID is needed to suppress a warning message.

The installation is straight forward, mostly clicking Next on each step:


 Give it a password and ignore the message

 Allow it to run the root script and give it your root password

Click Yes because that is what we gave it the root password for and get a coffee.
When finished, the installer invites you to Oracle Enterprise Manger Database Express
Close the installer and open the URL, accept the https exception in your browser and log in with system and your password.
Looks good. Close the browser and go back to the shell to double check if the command line tools are working.
Check the listener with lsnrctl stat.
Try sqlplus / as sysdba with show sga ...
... and it's younger brother SQLcl with sql / as sysdba  and any complex SQL statement you can think of.

To not always need to run .oraenv on every new shell, especially when mostly using the same database anyways, also add the following to your .bashrc:

export ORAENV_ASK=NO
. oraenv
export ORAENV_ASK=YES

By setting ORAENV_ASK back to YES, you can always use .oraenv to switch to a different database.

Add the PDB to your $ORACLE_HOME/network/admin/tnsnames.ora


  (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))


ORCL =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = orcl)
    )
  )

ORCLPDB =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = orclpdb)
    )
  )

Just copy the entry for ORCL and replace both occurrences with ORCLPDB.

To have at least one user to play with, enable the HR schema. Connect to the DB with sql system@orclpdb and enter:

alter user hr account unlock identified by hr;
grant connect, resource to hr;

Of course this are no security best practices and you will wisely choose a secure password and will grant fine granulated rights.

Optional: connect from the outside
If you only plan to use this DB with the tooling from inside the VM, you are already done. For connecting from the outside, make sure that the Listener listens on the host only network adapter.
Open /u01/app/oracle/product/19.0.0/dbhome_1/network/admin/listener.ora in your editor. If it only listens on localhost it will not listen to traffic on the host only network vor VirtualBox like here:


LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
    )
  )

Change the localhost to the hostname of your VM, the same that you put into /etc/hosts.
(Note: for whatever reason, the hostname does not work on my system, so I used the IP address instead)

LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.56.104)(PORT = 1521)) (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521)) ) )

Restart your Listener with lsnrctl stop and lsnrctl start, then check it's status with lsnrctl stat.
It should now listen on both, your external and local IP addresses.

The fastest and easiest way of getting a development instance of the Oracle DB is using the Oracle Cloud. But when a local installation is needed, having a proper set up Linux machine or VM, installing a simple Oracle DB for Developers is quick and easy.