Saturday, August 08, 2020

Installing VNC Server on Google Cloud CentOS VM

Introduction

Recently I installed VNC on CentOS 6 on GCP for some development work. Sharing my notes. The steps are similar for Redhat Enterprise Linux.

Concepts

VNC - Virtual Private Networking, a Graphical User Interface platform that can be accessed remotely 

Steps

Create a VM

Create a CentOS instance in Micro VM Shape. To reduce latency choose a region close to you. Note that I'm using default VPC network that is automatically created. If you need more details on how to create VM pls refer my earlier blog

gcloud beta compute --project=oci-gcp-vpn-connectivity instances create centos-vnc-demo --zone=us-central1-a --machine-type=f1-micro --subnet=default --network-tier=PREMIUM --maintenance-policy=MIGRATE --service-account=71492557944-compute@developer.gserviceaccount.com --scopes=https://www.googleapis.com/auth/devstorage.read_only,https://www.googleapis.com/auth/logging.write,https://www.googleapis.com/auth/monitoring.write,https://www.googleapis.com/auth/servicecontrol,https://www.googleapis.com/auth/service.management.readonly,https://www.googleapis.com/auth/trace.append --image=centos-6-v20200714 --image-project=centos-cloud --boot-disk-size=20GB --boot-disk-type=pd-standard --boot-disk-device-name=centos-vnc-demo --reservation-affinity=any


Install Gnome Desktop

By default these VM doesn't come with graphical environment. I will use GNOME to install Graphical desktop (X Window System)

SSH to the VM 

Install GNOME with sudo

sudo yum groupinstall "X Window System" "Desktop"


This install GNOME along with all the dependent packages - 300+ of them!


Install VNC Server 

I will use tigervnc server 

sudo yum -y install tigervnc-server xorg-x11-fonts-Type1

Create a user

sudo useradd malkit sudo passwd malkit

Setup VNC Server password

su - malkit vncpasswd exit

Start VNC Server

sudo /etc/init.d/vncserver start

This fails with following

[mbhasin@instance-vnc-demo ~]$ sudo /etc/init.d/vncserver startStarting VNC server: no displays configured [FAILED]

To fix this error you need to configure vncservers file. Scroll to bottom unmask (remove #) for VNCSERVERS and VNCSERVERARGS and provide the username and the screen resolution (note default is 800x600). Here's how my setup looks like after the changes.- Make sure you remove the default  -nolisten tcp -localhost Option

sudo vi /etc/sysconfig/vncservers

VNCSERVERS="2:malkit"VNCSERVERARGS[2]="-geometry 1280x1024"

Try starting again - it should succeed this time

[mbhasin@redhat-vnc-demo ~]$ sudo /etc/init.d/vncserver startStarting VNC server: 2:malkit xauth: file /home/malkit/.Xauthority does not existNew 'redhat-vnc-demo:2 (malkit)' desktop is redhat-vnc-demo:2Creating default startup script /home/malkit/.vnc/xstartupStarting applications specified in /home/malkit/.vnc/xstartupLog file is /home/malkit/.vnc/redhat-vnc-demo:2.log [ OK ]

Troubleshooting tip: 

- If you still having issue make sure there are no unnecessary spaces in the config file after the usename

Configure Firewall

There is one more step that need to be performed. After successful start by default this VNC server is listening on 5902 port (since we used display id as 2 config file above. You can verify by following on your VM

[mbhasin@redhat-vnc-demo ~]$ netstat -na | grep 5901[mbhasin@redhat-vnc-demo ~]$ netstat -na | grep 5902tcp 0 0 0.0.0.0:5902 0.0.0.0:* LISTEN If you try to connect to this from your VNC client machine the request will timeout.


If you try to connect to the above server from client machine you will get timeout


Firewall is configured on the VPC associated with the VM. You can also navigate it by click on the VM and scrolling down to middle are and then clicking on View Details under Network details. 

Go to Left menu -> VPC Network
Click on Create Firewall Rule button on the top menu and confgiure to allow TCP from any source (CIDR 0.0.0.0/0) on 5902 port. Let's call this new rule 
default-allow-vnc.

Make sure to select default for VPC. Also you have option to target this rule on all instances of this VPC or define a tag which can be applied to select instance. We chose later and specified tag - vncserver (note that this tag need to be configured on the earlier created VM instance).


Here's how the rule looks.

Associate the Firewall rule with the VM

Go to VM config page and click Edit button on the top. Under Network tags enter the tag created earlier - vncserverThe configured VM network details should look like following. Notice the vncserver under Network tags column

Connect to VNC server from VNC Client

Try to connect again. It should succeed prompting you to enter the password. 

References

https://wiki.centos.org/HowTos/VNC-Server

No comments:

Understanding JavaScript Prototypal Inheritance for Java developers

Inheritance is a fundamental concept in programming languages. However, it is implemented differently in Object-Oriented Languages such as J...