Tuesday, September 13, 2011

Configure VNC at Centos 5.5 Linux


Intro:

As former Windows user, I used to lean on remote desktop service in order to access another Windows computer over the network.
That was the single practical way to deal with remote computer for Windows, because there (at Windows) every thing is done using GUI.

At Linux it's a bit different, because you can almost do everything using secure shell (ssh) connection, just access the target computer shell and enjoy ;)
But some times you need (or prefer) to use Windows way in order to access other Linux machine, and one of the most famous way to do this is using Virtual Networked Computing (VNC).
This is simple tutorial shows how much it's easy and effective to use VNC.

Requirements:

The VNC method is based on using a VNC Server installed and running over the target machine, and using VNC Viewer installed and running over your machine which you could use it to communicate with target machine VNC Server.

At this tutorial, at both machines there's CentOS Linux 5.5 installed, VNC server and viewer are available at CentOS updates repository and you can install them using yum:

# yum install vnc-server
# yum install vnc
At other hand you can check if VNC is installed by using rpm to query VNC installed packages:
# rpm -qa | grep vnc
vnc-4.1.2-14.el5_6.6
vnc-server-4.1.2-14.el5_6.6
At target machine:

As I described, VNC server should be installed at the target machine, after finishing this step you should add a user to this server in order to use it for accessing.

Edit the file /etc/sysconfig/vncservers as root user and add this couple lines to the end of the file:

# nano /etc/sysconfig/vncservers
VNCSERVERS="1:osama"
VNCSERVERARGS[1]="-geometry 800x600 -depth 16 -nolisten tcp -nohttpd -localhost"
The first line sets up a user (osama) for the NVC server, surly you can add any additional number of users here.
Whereas the second line describes the argument (configuration) for each user, ie:
VNCSERVERARGS[1] <=> VNCSERVERS="1:osama"

Geometry argument describes the screen resolution (800 pixel x 600 pixel), Depth argument describes the color depth, nolisten tcp argument used to prevent X connections to your VNC server via TCP, nohttpd argument used to prevent web-based VNC clients connecting., and finally localhost argument used to prevent remote VNC clients connecting except when doing so through a secure tunnel.

Tip about the ports:

When you try to connect using VNC, you need to specify the port number used for this connection, to know the used port you should calculate it using this tricky way:
5900 + (Session number) = VNC Port
The session number is the defined number at “/etc/sysconfig/vncservers” file, for our case it was “1” for the user “osama”, VNCSERVERS="1:osama".
So the used port number for our case is : 5900 + 1 = 5901

Setting a password:

VNC need to specify a password before a connection can be established, you can do so using “vncpasswd” command:
# vncpasswd
Password:
Verify:

Starting and stopping the server:

You can start the VNC server using “vncserver” command followed by the session number that you configured at “/etc/sysconfig/vncservers” file:
# vncserver :1
New 'omniyapc:1 (osama)' desktop is omniyapc:1
Creating default startup script /root/.vnc/xstartup
Starting applications specified in /root/.vnc/xstartup
Log file is /root/.vnc/omniyapc:1.log
Now the server is started and a user could connect.
For stopping the VNC server use the command “vncserver” followed by “kill” parameter and the session number:

# vncserver -kill :1
Killing Xvnc process ID 30857
 
Configuring VNC server

By default, the connected users will get gray desktop because the connection will not start new session for X server, so you need to edit the startup script in the .vnc folder in the home directory:

# nano /root/.vnc/xstartup
Then un-comment these two lines and save:

unset SESSION_MANAGER
exec /etc/X11/xinit/xinitrc
But remember please that you have to restart the “vncserver” after this update.

At your machine:

As I described you should install “vnc” package at your machine in order to use it for connecting VNC server, and thus you can use it like this:

# vncviewer 192.168.30.15:5901
Which “192.168.30.15” is the remote machine IP address (surly you can use it defined name at your DNS) and “5901” is the calculated port that we talked about at previous section.

Then, VNC Viewer will ask you to enter the remote VNC server password that we defined at previous steps:


Enter the password and “play” remotely with visual desktop ;)

Sunday, September 11, 2011

The first "Date" with Apache Wicket !

Many JAVA developers didn't hear about Apache Wicket before, I was one of them too, but a happy occasion happened and I met Wicket !


When you are planning to build JAVA web application you have many choices, the first one is JSP and JAVA servlets, but for advanced application you need a framework make things more easy and enhance your productivity.


I've searched about JAVA frameworks before, I've checked Struts2, Spring MVC, JBoss Seam, Apache Tapestry and JSF, but actually I didn't applied them into any application, I've just tested them a little, so I didn't fall in love with these frameworks really !


Last month I decided to begin new "ambitious" project, and I was need a free JAVA framework, at other hand I was afraid of using these frameworks because of "XML tags soup", so Wicket was my decision at last for these reasons:


  1. It's free and open source
  2. It's Component Centric approach
  3. Swing-like Object Oriented Component Model
  4. No XML soup
  5. Just plain Java and HTML 
  6. There's many reuseable and flexible components
I had a look at couple books, Wicket in action and  Wicket Cookbook, the first one aimed for bigginers but I found it somehow "buggy" and confusing, while Wicket Cookbook is more clear and divided to sample with clear and complete description, so I recommend to go for Wicket website tutorials and examples first, then you can read Wicket Cookbook for great and usefull Wicket capabilities.

I'll post a tutorials about Wicket later, but for now if you tried Wicket let'us know your opinion ;)