Wednesday, June 20, 2012

FreeNAS, OpenFiler or Ubuntu Server

Lately, I have been thinking that I will digitize everything in the house and I researched for a while on what to do and what to use.

First, the media front. I read the Roku, Boxee Box, etc reviews, but they were not for me. SO I decided to go with XBMC. I am very familiar with Ubuntu and most plugins are Ubuntu native in XBMC but unfortunately the new version of Ubuntu comes with Unity. I went against my hatred for the new layout and stupid desktop environment and since I could not be bothered to remove Unity for another environment...what the hell, I said I'll try it.

The hardware was pretty simple:

I installed Ubuntu 11.10 with OpenSHH server, then XBMC. As soon as XBMC was up and running, I installed the extra repositories. Addons installed include Pandora for XBMC, Swiss Army Knife, mythtv for XBMC. Then I installed MythTV and configured the TVTuner Card. Very buggy and does not work properly.

So now I am ripping my DVD collection, arranging my pictures and fixing my music files. Now comes the time to figure out what to do for disk space. I looked at Synology, Promise, QNap which are the more respectable names in NAS boxes. Then I remembered that I installed and configured FreeNAS a long time ago so I started reading about FreeNAS and OpenFiler. A lot of people recommend the former than the latter and that reminded me why I had chosen it as well so long ago. 

The decision was made and I dug some hardware I had in the closet, bought some hard drives and started building. The hardware is a bit ridiculous but they used to belong in a former gaming rig.
  • Asus A8N32-SLI Deluxe Motherboard
  • AMD FX-55
  • I could not use the 8800GTX (too much power) so I just got a $20 video card
  • 1 80 GB drive I found lying around and 3x2TB
  • 4 GB of RAM
I read a lot about ZFS file system and I was intrigued so I installed freeNAS and I created a RAIDZ array. I could not change the configuration and it kept crashing all the time so I removed it and installed openFiler. Even worse...

So I saw that ZFS is natively supported in Ubuntu. I installed Ubuntu 11.10 server, added the ZFS repository, installed ZFS, created a RAIDZ array and everything was good to go. Then I wanted a time machine backup for my laptop and I came across a huge article on how to install netatalk(TODO) . That did not work. All you have to do is sudo apt-get install netatalk and add 2 configuration lines. After that was done, I installed and configured SAMBA.

Time Machine backup, Windows Backup, reliable NAS storage for any OS. Now why would people not choose this?
[Update]
Eventually I had to remove Unity and use Xfce because the video was very choppy and there was a line in the middle of the TV. 

Friday, February 17, 2012

HTML5 Canvas Drawing Library

This library will allow you to create as many Canvas elements as you wish on a single page. It does not matter if you have the canvas element inside multiple elements or if the page is too long (scrollable).

There are  a few tutorials online on how to create a canvas drawing app but most assume that you are placing them on a regular HTML page. I tried most of them but since I wanted to use it in my AJAX web application where I load everything inside DIV elements the mouse positioning was always off when the container scrolled up or down.

This is also compatible with mobile browsers. I have tested it on iOS and Android browsers. It will detect a touch event or a mouse event based on the client. This was built to be unobtrusive but the only drawback is that you need jQuery to run this. You do not need to know anything about jQuery jus thow to include it.

The following is the HTML that you need to create 2 canvases. Place this in the body tag of your document.


What you need to make sure is that the ID of the container is pallete_"CANVASID", the ID of the canvas element itself should be the CANVASID and when the object is created it needs to be with CANVASID.
Now for the Javascript:
jQuery is only used to get the position of the cursor in this function getCoords(e)
I had previously used this function but it does not work if the container is scrollable.

Canvas is a very powerful element with a huge potential and I cannot wait for the day that we will reminisce and say "Remember that really buggy application that drove everyone crazy? It did not work on Linux, Mac and had so many security issues in Windows....What was it called? Ah, yes Flash."

Monday, September 19, 2011

LTSP Cluster With Ubuntu 11.04

More than a year after I tried the ltsp-cluster package that came with Lucid, I decided that it was time to actually go ahead and try this setup on actual hardware and not VMs. Now though, 11.04 is the current version and of course there is no documentation for anything on this version. The ubuntu developers changed the DHCP server executables, then they most probably smoked some crack and decided to add the Unity Desktop as a default, etc, etc. Before I started, I had a lot of questions that could not be answered:
  • I have a few servers that I can use. 1 that had 16GB RAM with 2 Quad Xeons and some that are way less powerful. Which server should be the most powerful one? The root or the app server?
  • Is there a monitoring tool or an accounting tool? I am sure that we need to keep an eye on what the students are doing.
  • How can I add one more app server on the cluster and is it simple.
  • Will I get the same functionality as a regular LTSP server.
  • How the hell can I remove Unity?
  • Who can help me if I get stuck?
Well the answer to the last question would be the nice folks over at IRC on freenode in channel #ltsp. They are always helpful, just install a client, connect to the IRC ask your question (politely) and someone will answer eventually. I will explain in this post how to configure and setup the root server. Then in the following post I will explain how to setup the application server and try to answer the questions. If you have any questions please ask.

On to the setup; first you need to download ubuntu server 11.04 (64 or 32 bit) and the edubuntu desktop DVD. Some of my servers did not have DVD drives so I downloaded the Ubuntu Desktop CD and then run "sudo apt-get install edubuntu-desktop".

The hardware setup is based on my previous post here.
So make sure that your root server has 2 network cards.

Root Server

Boot from the CD and follow all steps. When you reach the tasksel step (it will ask you which services you want installed) select only the openSSH server. Run the following after you log in for the first time:
sudo apt-get update && sudo apt-get dist-upgrade

There is a very big possibility that Ubuntu will not have enabled the second network card upon install. So in order to make sure open up the interface file and add the following (I explain the subnet declaration for eth0 later):
auto lo

iface lo inet loopback



auto eth1

iface eth1 inet dhcp



auto eth0

iface eth0 inet static

        address 192.168.8.1
        netmask 255.255.252.0

You should then run sudo /etc/init.d/networking restart. The script will complain that this is deprecated but I could not find the "proper" way to do this anywhere.

 Next run
sudo apt-get install ltsp-server isc-dhcp-server

This will install the ltsp server that will be used to serve the image to all clients and the DHCP server that has changed name, package name and executable name without being documented ANYWHERE. If you are going to do something do it well or don't do it at all, thats what I always say but lets continue.

Now we need to edit the configuration file for the DHCP server so lets open that file
sudo pico /etc/dhcp/dhcpd.conf

The idea here is that since you are looking to create a cluster with a lot of thin clients, you will need to have a large pool of IP addresses. I am giving you an example here with a supernetted Class C network that gives us over 1000 usable IPs. A standard Class C or /24 subnet will work as well.


ddns-update-style none;
default-lease-time 600;
max-lease-time 7200;
authoritative;
log-facility local7;

subnet 192.168.8.0 netmask 255.255.252.0 {
    option domain-name-servers 192.168.2.97;//this is your DNS server
    option routers 192.168.8.1;
    range 192.168.8.50 192.168.11.253;
    next-server 192.168.8.1;
    filename "/ltsp/i386/pxelinux.0";
}

Make sure that this file /etc/default/isc-dhcp-server has the following line
INTERFACES="eth0"

The interface here needs to be the one that will be on the "inside", meaning the one that the thin clients are going to be connected to. Now restart your DHCP server
sudo /etc/init.d/isc-dhcp-server restart

Connect a regular PC on the switch that is connected to eth0 (your thin client side). If you get an IP then everything up to now is working as expected. You will not be able to access the Internet from that PC yet. Now build the thin client environment
sudo ltsp-build-client --arch=i386 --ltsp-cluster --fat-client --fat-client-desktop=edubuntu-desktop

I build fat clients since the computers I am using have 2GB RAM and dual core processors. After the image is build, you will be asked for a Server Name, Port, Use SSL, enable inventory and request timeout. Make sure the server name is the IP of the server for the thin client interface card. All your answers are saved in this file: /opt/ltsp/i386/etc/ltsp/getltscfg-cluster.conf
If you need to enable root in the LTSP environment you need to enter the chroot. There is a command now that you can use to change into it, so issue the following:
sudo ltsp-chroot

You then issue the command passwd and enter your new password, then type exit. Once you are out of the chroot, if you type ltsp and tap the tab button twice (without having a space after ltsp) you will see all available ltsp commands that come with 11.04.

The cluster control uses PostgreSQL, so you have to install that and the management tool for it. Run
sudo apt-get install ltsp-cluster-control postresql

sudo apt-get install phppgadmin

Now edit apache2.conf
sudo pico /etc/apache2/apache2.conf

and add the following line at the end
Include /etc/phppgadmin/apache.conf

Then edit
sudo pico /etc/phppgadmin/apache.conf
and uncomment (remove the # sign) from the beginning of the line that says "Allow from all". Next comment (add the # at the beginning of the line) where it says "allow from 127.0.0.1".
Restart apache.
sudo service apache restart

After all that you have to edit a php file

sudo pico /etc/ltsp/ltsp-cluster-control.config.php
 
Make sure you do NOT have any characters, even a white space before or after the php tags: <? or ?>
    $CONFIG['save'] = "Save";
    $CONFIG['lang'] = "en"; 
    $CONFIG['charset'] = "UTF-8";
    $CONFIG['use_https'] = "false"; #Force https
    $CONFIG['terminal_auth'] = "false";
    $CONFIG['db_server'] = "localhost"; #Hostname of the database server
    $CONFIG['db_user'] = "ltsp"; #Username to access the database
    $CONFIG['db_password'] = "ltsp"; #Password to access the database
    $CONFIG['db_name'] = "ltsp"; #Database name
    $CONFIG['db_type'] = "postgres"; #Database type (only postgres is supported)
    $CONFIG['auth_name'] = "EmptyAuth";
    $CONFIG['loadbalancer'] = "192.168.8.1"; #Hostname of the loadbalancer
    $CONFIG['first_setup_lock'] = "TRUE";
    $CONFIG['printer_servers'] = array("192.168.8.1","another IP here if you want etc"); #Hostname(s) of your print servers
    $CONFIG['rootInstall'] = "/usr/share/ltsp-cluster-control/Admin/";

Create a new database using the password and database name as in the PHP file that you edited above
sudo -u postgres createuser -SDRIP ltsp
Enter password for new role: 
Enter it again: 

sudo -u postgres createdb ltsp -O ltsp 
Create the tables in the database

cd /usr/share/ltsp-cluster-control/DB/

cat schema.sql functions.sql | psql -h localhost ltsp ltsp

Password for user ltsp: 

Next become root
sudo su

Download 2 files. contol-center.py and rdp+ldm.config. I downloaded them from here
You can issue this command to get them on your server with no gui:
wget http://bazaar.launchpad.net/~ltsp-cluster-team/ltsp-cluster/ltsp-cluster-control/view/106/scripts/control-center.py
wget http://bazaar.launchpad.net/~ltsp-cluster-team/ltsp-cluster/ltsp-cluster-control/view/106/scripts/rdp%2Bldm.config

Edit the file control-center.py and make the necessary changes so that the variables are equal to the values you set for your DB.
pico control-center.py

This is the file:
#/usr/bin/python
import pgdb, os, sys

#FIXME: This should be a configuration file
db_user="ltsp"
db_password="ltsp"
db_host="localhost"
db_database="ltsp"

Install the python package for PGSQL.
apt-get install python-pygresql

Issue the following commands:
service apache2 stop
python control-center.py rdp+ldm.config
service apache2 start
exit

Next install the loadbalancer and edit the xml file with the app servers that you are going to install in the next step.

    
    
    
    
        
            
            /*Keep adding app servers here as nodes*/
        
    
    
        
            
        
        
            
        
        
            
        
    


Now on to the configuration of the root server. We need to access the web interface phppgadmin to add items that you need to appear in the lts.conf file for ltsp client customization. There are a few options in the database, but if you need to add a few more open a browser and go to http:///phppgadmin/
Click the PostgreSQL link on the left and type your credentials. Username should be ltsp and the password is what you set above for the database. Once logged in, click the link labeled "Tables". In the right window, you will see a list of table names and buttons next to each name. Click the button labeled "Browse" next to the name "attributesdef". If everything went fine, the table contents are displayed, think of this as a spreadsheet. The column names should read, Actions, id, name, attributeclass, attributetype, mask, editable. Scroll your page to the end, you should be able to see 4 links: Back, Expand, Insert and Refresh.

  • Click Insert and for "name" add LDM_XSESSION and leave everything else as is. 
  • Click "Insert and Repeat". For name add LDM_THEME and for attributetype put the number 1. 
  • Click "Insert and Repeat". Name is LDM_LIMIT_ONE_SESSION and attributetype is 1.
  • Click "Insert and Repeat". Name is LDM_LIMIT_ONE_SESSION_PROMPT and attributetype is 1.
  • Click "Insert". 
  • Get the id for LDM_THEME, LDM_LIMIT_ONE_SESSION, LDM_LIMIT_ONE_SESSION_PROMT
  • Click tables again from the left.
  • Click the browse button for table "attributesdefdict"
  • Click Insert. In the attributesdef_id field, add the id of LDM_THEME from the step above and the value add edubuntu
  • Click Insert and Repeat. Add id of LDM_THEME again and value ubuntu.
  • Insert and Repeat. Add id of LDM_LIMIT_ONE_SESSION and the value True
  • Insert and Repeat. Add id of LDM_LIMIT_ONE_SESSION and the value False
  • Insert and Repeat. Add id of LDM_LIMIT_ONE_SESSION_PROMPT and the value True
  • Insert and Repeat. Add id of LDM_LIMIT_ONE_SESSION_PROMPT and the value False
  • Click Insert.
Done with editing the database. Now go to http:///ltsp-cluster-control/Admin/
Select from the dropdown then click add for the following or whatever other options you want.

Make sure the for LDM_XSESSION you add this: gnome-session --session=classic-gnome. If you do not, the clients will log in but the desktop will not load (I tried this in 4 different hardware setups) because Unity will try to load. 

Next you need to add static IPs for the application servers that you will use. You can see on the XML file from above that I am using 192.168.8.2 and 192.168.8.3 for app-server01 and app-server02 respectively. You can do this by installing webmin (wget http://prdownloads.sourceforge.net/webadmin/webmin_1.560_all.deb)  and then sudo dpkg -i webmin_1.560_all.deb and then sudo apt-get install -f. You have to edit the config files for the DHCP server of webmin to reflect the newly named config files in your system.

Once done you can only log into webmin with root so enable root from the command line (sudo passwd).

Next edit hosts file (pico /etc/hosts) and add your application servers. 
127.0.0.1               localhost
127.0.1.1               ltsp-root
192.168.8.2           ltsp-appserv01
192.168.8.3           ltsp-appserv02

--Forgot the NATing--- You need to enable NAT on this server. To do that issue these commands:
sudo sysctl -w net.ipv4.ip_forward=1
sudo iptables --table nat --append POSTROUTING --jump MASQUERADE  --source 192.168.8.0/22
sudo sh -c 'iptables-save > /etc/ltsp/nat'

Then edit the interfaces file (/etc/network/interfaces) and for eth0 make sure it looks like this:
auto eth0
iface eth0 inet static
	address 192.168.8.1
	netmask 255.255.252.0
	up iptables-restore < /etc/ltsp/nat

Restart the DHCP server.
sudo /etc/init.d/isc-dhcp-server restart

All done with the root server.

My Blog List