Archive for Digital Walkabout

Setting Up a Website on Amazon AWS

// April 21st, 2012 // No Comments » // Digital Walkabout

Amazon AWS Enrollment

After signing up for AWS I was enrolled automagically into their wonder 1-Year Free Tier Service meant as a means of allowing new business’ / users to effectively learn their cloud systems without fear of spending money. Its not only a sharply smart business move, its also an enjoyable experience, as I found earlier this week.

Obviously you can’t go crazy, I’ll leave it to you to check out their FAQs on the Free Tier service.

Before their new GUI into their AWS system it was supposedly some sort of a nightmare requiring 3rd party apps using their API or web-browser plugins like “Elastifox”. *shudder*

Fortunately for you and I, that’s a thing of the past with their new login system at https://console.aws.amazon.com

Instance Wizard

So I went through their Wizard for creating a new EC2 Instance (where you basically go through the process of creating your very own Virtual Machine in the Amazon cloud).

What’s great about this Wizard is that you no longer have to go through the hurdle of figuring how to create the machine, installing the OS (they now let you use virtual hard drives images of pre-installed operating systems).

In my case I went with most of the default options, selected my default image with an install of Ubuntu 11.10 (apparently still have to wait for Ubuntu 12.04 [Precise Pangolin] to make it out of Beta 2) on an 8GB EBS Volume (read: “hard drive” or “virtual hard drive” if you please), Also when I created my default security settings I made to open up ports 80 and 10000. (80 for the obvious reason that if you can’t access this port, a website won’t do you much good, and 10000 to access webmin – my favorute linux web-based administration tool)

Final Instance Setup

Anyhow, after doing that, I requested an Elastic IP address and assigned it to my new virtual machine. Then I “turned on” the computer (or “instance”) within 2 minutes it was fully booted and ready to be accessed.

Linux Server Setup

I promptly proceeded to SSH into my new box (which you can access by use of Java if you right-click on your instance and click on “Connect“.

Be sure to connect as ubuntu instead of root and use your PEM file that you get to download when creating the instance.

Personally I then upload my personalized .bashrc config file and promptly sudo su since that’s my style. Stick to yours and dont bug me, I’ve been on Unix since 1988 and I’m not going to change my habits now ;-)

Next thing’s next I installed a LAMP environment (including phpmyadmin), you can use any method you like – personally I like to manually install each package using apt-get instead of using something like tasksel , but there are plenty of on-line guides for that.

Next I installed webmin :

1. Edit apt sources

Edit /etc/apt/sources.list

At the end of the file, add these two lines, then save and close:

deb http://download.webmin.com/download/repository sarge contrib
deb http://webmin.mirror.somersettechsolutions.co.uk/repository sarge contrib

2. Import now the GPG key using these commands:

wget http://www.webmin.com/jcameron-key.asc
apt-key add jcameron-key.asc
apt-get update

3. Install now Webmin with this command:

apt-get install webmin

4. Be sure to set the password:

/usr/share/webmin/changepass.pl /etc/webmin root password

Then enter /var/www/ and viola! You now have a website ready-to-go on Amazon’s amazing new AWS cloud.

 

Last things last would be to install mosh – which if you haven’t heard of this before, consider it the next level in remote login, its as much an advancement above telnet as SSH was. Check out more about it http://mosh.mit.edu

 

add-apt-repository ppa:keithw/mosh
apt-get update
apt-get install mosh

 

Bad Cable Woes Force me to Force 10Mbps Full Duplex

// June 3rd, 2011 // No Comments » // Digital Walkabout

This seems to be a rare problem for most people, and in fact should be, however, if you’ve ever had bad CAT (5/5e/6/whatever) cables [because you made them yourself maybe], then theres a possibility you’ve come across a strange scenario where your NIC cannot access the network (or establish a good connection with your Switch/Hub or Router) and forcibly setting it down to 10Mbps is the only way to get it to work.

So, if you have the same problem, there’s a ridiculously easy solution in Linux. Years ago, we had to use mii-tool. mii-tool, however, is now deprecated and could only handle 100baseT4, 100baseTx-FD, 100baseTx-HD, 10baseT-FD or 10baseT-HD.

Here comes in our hero of the day namely ethtool.

Now, I was at my ranch where I did all of the wiring for the network cables. That included the RJ-45 wall jackets, as well as the plastic connectors for the basement where all of the cables eventually lead down to multiple / separate switches and routers (yes, multiple routers, mini-networks, pain in the ass – i know)

Well there’s one room thats always caused problems from the get-go. At first I thought it was the socket, then I thought it was the plastic connector. I’ve changed both many times, different computers would work, some would not, sometimes it’d work when I would boot with one OS, often it wouldn’t with another.

Finally, I figured out that the pattern had to do with whether or not the NIC was set to 10Mbps, as opposed to 100Mbps or 1000Mbps/1Gbps. Then it hit me, the cable must have be damaged IN SIDE the wall somewhere or in the floor.. either way way I have to make sure that the NIC is downgraded to 10Mbps and everyone works fairly well afterwards.

So, here’s the magical command everyone insisted on me using:

ethtool -s eth0 speed 10 duplex full autoneg on

Sadly, this command would not work!

First things first, I am using the RTL6169 driver for my RTL6168/6111b NIC – it doesn’t support being told to renegotiate, I realized, so then I thought I would follow up with these commands:


ethtool -s eth0 speed 10 duplex full
ethtool -r eth0

…to manually re-negotiate after setting the speed. However, I found that the first step would not even work. Basically, in no way could I get ethtool to downgrade or change the speed setting. It just refuses to do make it change at all.

This means I had to go back and use the so-called “deprecated” mii-tools. On Ubuntu 11.04 I was able to install it using the net-tools package. Alternatively you can download the source to mii-tools (its a very harmless easy compile / install with the make command).

So I fired up the good ‘ol tool using this exact command:

mii-tool -F 10baseT-FD eth0

Voila! Presto! Banzai! It works! It.. just.. works.. ethtool could not work or ethtool would not work, but mii-tool worked just fine.

Obviously, I did not want to run the command every time I rebooted, so I edited the file /etc/network/interfaces and added this line at the bottom:

pre-up /sbin/mii-tool -F 10baseT-FD eth0

Some people recommend making a script or running it from rc.d or init.d, etc. That’s just bad system administration, IMHO. There is no better place than the interfaces file, its there (and the use of the pre-up command) for a reason just like this one for startup NIC operations.

So the moral of the story? Just because a tool is old does not mean its usefulness has waned!

Bypassing DISTINCT’s ORDER BY Requirement with Sub Query Wrapper

// May 12th, 2011 // No Comments » // Digital Walkabout

When using DISTINCT in a query to weed out duplicates (which is necessary often in PostgreSQL, since it has the very tiresome rule of making a simple GROUP BY pointless by requiring that all fields being pulled be included in the GROUP BY expression), its important to use smart, efficient methodology.

Using DISTINCT can be very simple and very powerful, but can quickly get annoying when you start off the beaten path unless you employ some simple SQL techniques.

Lets say we have a table called employees that has several fields including (but not limited to) id, name, and clearance_level (whether id is a primary key or not is un-important, as well as whether or not the other fields are integers or strings or blah blah blah.)

SELECT DISTINCT ON (E.id) id, name, clearance_level FROM employees E ORDER BY id

Which is fine and dandy, if you want the query to return them by the order of their id. However, I’m sure you’ve found that when you attempt something like say:

SELECT DISTINCT ON (E.id) id, name, clearance_level FROM employees E ORDER BY clearance_level

or

SELECT DISTINCT ON (E.id) id, name, clearance_level FROM employees E ORDER BY name

…then you’ll find yourself in sad or dire straits.

Fear not! We can bypass this nasty little requirement of DISTINCT by making the original query a sub query and then re-order that data. Not only that, it is crazy simple:

SELECT * FROM
(SELECT DISTINCT ON (E.id) id, name, clearance_level FROM employees E) xyzzy
ORDER BY clearance_level;

Voila!

You can see, we simply turned our original query into a sub-query, from which we are collecting everything, and then referring to it as xyzzy (of course you can name it anything you please) and then ordering that data by the clearance_level.

I would recommend that delimiters that can be used in the initial query be used so, so as to allow the secondary (outer) ORDER BY statement to run as fast as possible.