Skip to content

Host your monoserver on Oracle Cloud

Etorth edited this page May 9, 2022 · 21 revisions

You can host monoserver on Oracle Cloud without costing a penny. I wrote this tutorial as it can be a pain to configure it if next time I missed any detail.

This can also be a general tutorial to configure any headless remote Linux server running with Oracle Cloud.

Create Oracle Cloud VM Instance

Oracle Cloud has a convenient always-free plan which supports to create virtual machine instances running with 2 cores and 1 GBytes memory, check the main page here.

  • Register Oracle Cloud, it asks for your name/address/creditcard, but won't charge you if you stay with the always-free plan. There are tons of HOWTO if you google it.

  • Steps to create a VM instance after you registered Oracle Cloud successfully:

    • Goto "compute" and click "instances": image

    • Click "Create instance": image

    • Find tab "Image and Shape", click "Edit": image

    • Find tab "Change image", select ubuntu or whatever listed you prefer, currently all OS images are FREE except the windows server: image

    • Find tab "Add SSH keys", you can upload your own key-pair generated by putty or mobaXterm, or let Oracle Cloud generate one for you here. You need to save the private key here as you need it to ssh to the machine later, and this "save private key" will not be shown again! image

    • Keep all other tabs as default and click create, the page jumps to the VM instance information page, it takes about 1 minutes for the machine goes to "RUNNING" state, then you can see the public IP address allocated, you need it to ssh into the machine: image

  • Now the machine is ready for you to ssh login into. Here needs the saved private key file, I am using mobaXterm as an example. mobaXterm is free and convenient with a default X server out-of-the-box, you don't need to install/configure any extra X server if you planning to run anything requires X.

    • In mobaXterm, select "Session": image

    • Create a SSH session, setup information as following, then click "OK":

      • Remote host: the public IP address of your VM instance
      • Specify username: "ubuntu" if you selected VM instance image as "Ubuntu", if you select other images, it's different.
      • Use private key: enable this and use the private key file you saved when creating the VM instance. image
    • Now you should be able to login into the VM instance: image

  • For users if they only need a Linux playground, they can stop here. The Oracle Cloud VM instance is a fully powered Linux system.

    For users trying to host monoserver, please continue.

Configure the VM instance subnet for ingress and open all ports

By default you can not connect to monoserver running inside VM instance and listening on port 5000, following steps adds an ingress rule for the default subnet, this configuration is needed only once, all later created VM instances use the same ingress rules.

  • Select "Primary VNIC/subnet": image

  • Select "Default Security List": image

  • Select "Add Ingress Rules": image

  • Fill "CIDR/0.0.0.0/0/All Protocols" and click "Add Ingress Rules" to commit: image

  • Now you should see a new rule in the "Ingress Rules" list, this is important otherwise you client can not reach monoserver running in the VM instance: image

  • We also need to configure the running Linux OS inside the VM instance to open all ports, this is critical and original from here.

    For what I have tested, following commands are enough to open all ports, but during the run looks every time after VM instance rebooted, I have to run following commands again:

    sudo iptables -P INPUT ACCEPT
    sudo iptables -P OUTPUT ACCEPT
    sudo iptables -P FORWARD ACCEPT
    sudo iptables -F

Till now the VM instance is ready to run any console command via ssh, if to run any X11 applications, mobaXterm will automatically start the local X session for us as following:

image

Since X support is through mobaXterm, if local mobaXterm exits, remote monoserver also exits. To run everything remotely, we need to install desktop environment and VNC service in VM instance.

Install headless VNC service for remote VM instance

Remote VM instance has no monitor, we needs a headless VNC server running to support X serivce.

  • Update/upgrade the VM instanse to latest state:

    sudo apt-get update
    sudo apt-get upgrade
  • Install desktop environment, I choose Xfce which is light and fast:

    sudo apt-get install xfce4 xfce4-goodies

    You can as well choose other windows managers like awesome or ubuntu-desktop, they all should be fine but I didn't test them. During the installation, it pops up to select the default display manager, I choose gdm3, lightdm should also work but I didn't try:

    image

  • Install dummy video driver as our VM instance has no monitor, this step is critical otherwise you will get an blank screen when using VNC:

    sudo apt-get install xserver-xorg-video-dummy

    You also need to create configuration file:

    sudo mkdir -p /etc/X11/xorg.conf.d
    sudo vi /etc/X11/xorg.conf.d/10-headless.conf

    And put following content into the file /etc/X11/xorg.conf.d/10-headless.conf:

    Section "Monitor"
            Identifier "dummy_monitor"
            HorizSync 28.0-80.0
            VertRefresh 48.0-75.0
            Modeline "1920x1080" 172.80 1920 2040 2248 2576 1080 1081 1084 1118
    EndSection
    
    Section "Device"
            Identifier "dummy_card"
            VideoRam 256000
            Driver "dummy"
    EndSection
    
    Section "Screen"
            Identifier "dummy_screen"
            Device "dummy_card"
            Monitor "dummy_monitor"
            SubSection "Display"
            EndSubSection
    EndSection
    
  • Now install and configure the VNC server, this section is dirctly copied from here:

    sudo apt-get install tigervnc-standalone-server

    Once the VNC server is installed, the next step is to create the initial user configuration and set up the password. Set the user password using the vncpasswd command. Do not use sudo when running the command below:

    vncpasswd

    You will be prompted to enter and confirm the password and whether to set it as a view-only password. If you choose to set up a view-only password, the user will not be able to interact with the VNC instance with the mouse and the keyboard:

    Password:
    Verify:
    Would you like to enter a view-only password (y/n)? n
    

    The password file is stored in the ~/.vnc directory, which is created if not present. Next, we need to configure TigerVNC to use Xfce. To do so, create the following file:

    vi ~/.vnc/xstartup

    And put following content info the file ~/.vnc/xstartup:

    #!/bin/sh
    unset SESSION_MANAGER
    unset DBUS_SESSION_BUS_ADDRESS
    exec startxfce4

    The commands above are automatically executed whenever you start or restart the TigerVNC server. The ~/.vnc/xstartup file also needs to have execute permissions. Use the chmod command to set the file permissions:

    chmod a+x ~/.vnc/xstartup

    If you need to pass additional options to the VNC server, create a file ~/.vnc/config and add one option per line. Here is an example:

    vi ~/.vnc/config

    And put following content info file ~/.vnc/confg:

    geometry=1920x1080
    dpi=96
    

    You can now start the VNC server using the vncserver command:

    vncserver

    which should output something like:

    New 'server2.<your-user-name>.com:1 (<your-user-name>)' desktop at :1 on machine server2.<your-user-name>.com
    
    Starting applications specified in /home/<your-user-name>/.vnc/xstartup
    Log file is /home/<your-user-name>/.vnc/server2.<your-user-name>.com:1.log
    
    Use xtigervncviewer -SecurityTypes VncAuth -passwd /home/<your-user-name>/.vnc/passwd :1 to connect to the VNC server.
    

    Note the :1 in the output above. This indicates the number of the display port on which the VNC server is running. In this example, the server is running on TCP port 5901 (5900+1). If you create a second instance with vncserver it will run on the next free port i.e. :2, which means that the server is running on port 5902 (5900+2).

    What is important to remember is that when working with VNC servers, :X is a display port that refers to 5900+X.

    You can get a list of all the currently running VNC sessions by typing:

    vncserver -list

    Which outputs something like:

    TigerVNC server sessions:
    
    X DISPLAY #   RFB PORT #   PROCESS ID
    :1            5901         5710
    

    Before continuing with the next step, stop the VNC instance using the vncserver command with a -kill option and the server number as an argument. In this example, the server is running in port 5901 (:1), so we'll stop it with:

    vncserver -kill :1

    Which outputs something like:

    Killing Xtigervnc process ID 5710... success!
    

    Instead of manually starting the VNC session, let’s create a systemd unit file so that you start, stop, and restart the VNC service as needed:

    sudo vi /etc/systemd/system/[email protected]

    And put following content into the file /etc/systemd/system/[email protected], make sure to change the username on line 7 to match your username, for this tutorial since we use Oracle Cloud with ubuntu image, <your-user-name> is ubuntu.

    [Unit]
    Description=Remote desktop service (VNC)
    After=syslog.target network.target
    
    [Service]
    Type=simple
    User=<your-user-name>
    PAMName=login
    PIDFile=/home/%u/.vnc/%H%i.pid
    ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill :%i > /dev/null 2>&1 || :'
    ExecStart=/usr/bin/vncserver :%i -geometry 1440x900 -alwaysshared -fg -localhost no
    ExecStop=/usr/bin/vncserver -kill :%i
    
    [Install]
    WantedBy=multi-user.target
    

    Notify systemd that a new unit file is created:

    sudo systemctl daemon-reload

    Enable the service to start on boot:

    sudo systemctl enable [email protected]

    The number 1 after the @ sign defines the display port on which the VNC service will run. This means that the VNC server will listen on port 5901, as we discussed in the previous section.

    Start the VNC service by executing:

    sudo systemctl start [email protected]

    Verify that the service is successfully started with:

    sudo systemctl status [email protected]

    It should output something like:

    [email protected] - Remote desktop service (VNC)
       Loaded: loaded (/etc/systemd/system/[email protected]; enabled; vendor preset: enabled)
       Active: active (running) since Fri 2021-03-26 20:00:59 UTC; 3s ago
    ...
    

    If the outputs shows something like inactive(dead), you may need to restart the service and review the log.

  • Connect to the server using any VNC client, you may prefer to use ssh tunneling for secured connection, but I skipped for this tutorial.

    • I use mobaXterm as example, you need to create a new session as following: image

    • Click "OK" and input the password you previously set by vcnpasswd, then you should be able to connect to the server, you can change configuration in ~/.vnc/confg to setup the screen size and resolution: image

    • If failed to connect to the VNC server, you may need to try following commands again:

    sudo iptables -P INPUT ACCEPT
    sudo iptables -P OUTPUT ACCEPT
    sudo iptables -P FORWARD ACCEPT
    sudo iptables -F

Host monoserver in VM instance

mir2x can get built after you install gcc-11 in VM instance, I tried but because of the limited 1 GBytes memory, the compilation fails. Alternatively I just build the server locally and upload to the VM instance.

  • To upload any file to the VM instance, the ssh session needs SFTP service enabled. Go to the same place where we configure the ssh to connect to the VM instance, but this time we additionally enable the SFTP protocol: image

  • Then connect to the VM instance, the ssh browser is now enabled as high-lighted, it support file drag-and-drop, upload the monoserver: image

  • Run monoserver, it may complain missing of libfltk and GLIBCXX_3.4.29.

    • Install libfltk:
      sudo apt-get install libfltk1.3
    • Install GLIBCXX_3.4.29:
      sudo add-apt-repository ppa:ubuntu-toolchain-r/test
      sudo apt-get update
      sudo apt-get upgrade libstdc++6
      sudo apt-get dist-upgrade
  • Now it's should be good to run monoserver on remote VM instance:
    image

  • Locally run the client side with --server-ip option to connect to the remote monoserver: image

  • Enjoy!

    For any issue running the remote monoserver, you can open issue in mir2x repo.