Marcos Placona Blog

Programming, technology and the taming of the web.

Category: VPS (page 1 of 3)

Some detailed tutorials about how to configure and maintain a VPS

Running Railo on AppFog… For free!

Reading time: 2 – 4 minutes

You will have noticed I deviated my blog posts quite a bit from CFML in the last couple of months. That doesn’t mean I don’t love it anymore, but just that I’ve been “putting my eggs on lots of other baskets” lately.

This blog is hosted on a VPS, and I haven’t really found it necessary to have any CFML engine running on it. I could allocate some memory to have a tiny instance of Railo running, but I’d prefer not having to deal with something else running, since it could easily crash, and take me months to actually realize it. This happened to my Langithub project the other day, and I simply didn’t notice until someone pinged me to let me know.

However, I do sometimes want to post working examples written in CFML, and I could simply use some of the few free services out there, but… I’d rather not.

So for a blog post I’ve been working on, I decided I’d give cloud hosting a go. I’ve been playing with AppFog for a few weeks now, and noticed it’s got a Java Application option listed on the application types it supports. I then went ahead and created one of them called railo.

AppFog Java App

This now gave me an empty Java Application.

Knowing the folks at Railo provide a download in war format, I went ahead and downloaded it

Railo .war download

I’ve put it on $ ~/marcos/railo, but you can put it anywhere you want.

Now within that folder from console, I issued:

This will do two things.

  1. Prompt you for your appfog login and password
  2. deploy the .war file to the railo project

You will then see a few other things will happen, as it will now be decompressing the war file, and starting your application.

If you now browse your application (using the URL provided by AppFog appending index.cfm to it), you will see Railo has been installed, and you can start rocking on the Cloud.

The example I used here can be seen on http://railo.eu01.aws.af.cm/index.cfm

mySQL killed my hamster

Reading time: 1 – 2 minutes

Or my website even….

I’ve run some updates on my server today, and got prompted to upgrade mySQL.

All went well during the upgrade, but when trying to browse, I’d get the following message:

“Error establishing a database connection”

Initially I thought it would be mySQL daemon trying to “kick in”, and it would come back in just a sec. Two minutes passed, and I started to get worried.

I went on and tried to restart mySQL daemon to no success, as it would always give me the following message:

MySQL Daemon failed to start.
Starting mysqld:  [FAILED]

Not very helpful I thought, so I went to the logs located at:

/var/log/mysqld.log

There I found the following error:

"Option '--set-variable' is deprecated. Use --variable-name=value instead"

I then went to /etc/my.cnf and could verify that there were a few settings using “set-variable”.

I simply replaced them for “variable-name=value” and it all came back to life.

Hope this helps anyone stuck with this problem.

IPTABLES – Opening server ports to specific IP addresses

Reading time: 1 – 2 minutes

Iptables shell script
(Photo: Jordan W)

I have been doing some housekeeping on my VPS, and decided there’s a few ports that should only be accessed by certain IP addresses for security purposes.
My VPS uses Linux, so I had to find a way to somehow changing my iptables settings to block the specific ports to every IP address, except for the ones I specified.
It’s pretty straight forward, and here  how you can block a specific port to everyone except for some IP addresses (the instructions are for Centos 5.5, but should work for other distros without problems):
Open our iptables settings file:

sudo nano /etc/sysconfig/iptables

Continue reading

Speed up yor website – Part 2 – The Free CDN

Reading time: 6 – 9 minutes

To continue with our series of website optimization tricks, I’ll talk a little bit more about Content Delivery Network (CDN), and will talk you though the steps of creating a totally free CDN for your website.
Basically, as I’ve already stated on my previous post, a CDN is an external network which specializes in serving static content. It normally consists of a few servers spread around the world, so the data will travel the shortest route to get to their destination based on Geolocation.
In other words, if you’re in Japan, why should you have to wait for the data to travel from Europe, if there’s a server just next door to you.

CDN With multiple=

What you can see from the image, is that you have all of your servers in a “Cloud of Computers“, and the requests are mapped to the nearest one. In some cases you have more than one server per country or region. The beauty of it, is that applications deployed on the cloud are highly scalable, and you normally don’t need to manage the servers, as they are managed by the provider.
There are some companies offering CDN for a very reasonable price, but today we’re gonna be talking about free stuff!
Before I start with this tutorial, I have to make it clear that the form of CDN we’re going to be using here, is not truly CDN, as it doesn’t offer a very high scalability, and hasn’t been developed for the sole purpose of serving static files, so it won’t have the same high performance of a service designated only for the task.
For some (like myself), it won’t make such a huge difference, as this method still is better than nothing, and is immensely faster than much servers around. I host my applications on my own VPS and don’t have bandwidth limitations. But for most people who use Hosting Companies and have limited bandwidth, this will be a huge improvement.

Step one – The Idea:

Google provides us with it’s wonderful Google App Engine. It’s free for anyone, you can store up to 500mb (enough for static content), and have about 5 million page views a month. Anything beyond it is charged (very tiny fee). Everybody knows Google, so you know they have servers almost everywhere. Put this all together, and you’ll get started.
To make this idea start to happen, simply create an account with Google App Engine. Simply use your Google login details, and and confirm your application with the code Google sends to you visa SMS (you need to have a mobile phone).
Now, you will need to download and install Python (it’s only required for the App Engine can run on your computer). I find Python 2.5 works better than Python 3, so you can get it from here.
It’s time to install the App Engine Client on your computer. Once it’s installed, you should be ready to go.

Step two – Create an Application:

Simply login to your newly created App Engine Account and click the button Create an Application

App Engine - Create Application
Give it a name and title, and then save it. Use a short name, as it will be you application’s handler, and you’ll access it by going to [app_name].appspot.com

Step three – Create your Application Folder:

If you are on a windows environment, normally the App Engine will be installed on “C:Program FilesGooglegoogle_appengine”. If not, it will be installed wherever you chose during installation.

Go to this folder, and create a new folder with the same name as the application you have just created on step 2.

You will now copy your assets folder into this folder. I like to keep the same structure, so by only changing one variable on my website, I can change the the domain it uses to look for images.

So if for example my website was looking for images at http://images.domain.com/images, I’d just change this variable to point to [app_name].appspot.com/images

So, on my folder I’ll have exactly the same structure as I had on my website plus a few files I’ll describe now:
app.yaml: this is our application configuration including URL’s and versions. More info here.

application: my-application
version: 1
runtime: python
api_version: 1
handlers:
- url: /images
static_dir: images
- url: /styles
static_dir: styles

Notice I’m specifying my static directories and their relative paths. You have to change it accordingly.

deploy.bat: This is a file I create for convenience. It executes command lines for me, so i don’t have to type them all the time I want to deploy. The contents of this file will normally be:

"C:Python25python" "C:Program FilesGooglegoogle_appengineappcfg.py" update "C:Program FilesGooglegoogle_appengine[app_name]"

Notice that on the first part of, I’m simply telling my script what I use when it comes to running python scripts. I then update my application by its name, and giving the application folder.

So manually it would be something like:

python "C:Program FilesGooglegoogle_appengineappcfg.py" update "C:Program FilesGooglegoogle_appengine[app_name]"

Step four – Deploying your Application:

Now it’s the big time. Simply double click the file called deploy.bat and you should see a screen like this:
Deploying to CDN

If it doesn’t give you any warning or error message, you should be ready to access your file.

If you decide to delete this file, simply delete it from the folder, and deploy again, and the file will be deleted. You don’t need to worry about minor versions, as the App Engine will deal with it for you.

To be honest, I never worry too much about the version numbers, as I’m constantly uploading stuff to my server. But if for some reason you do, you can simply change the “version” flag on you app.yaml file.

I hope this article is helpful. please don’t hesitate asking me questions or sending suggesting on how to improve this article.

Speed up yor website – Part 1

Reading time: 4 – 6 minutes

Assets such as stylesheets, images and videos are often the major hit taken by a webserver when a webpage is loaded. I’m often trying to improve my page loads by using published pages (flat html) and rewrites, so I don’t need to run a dynamic page when it’s not necessary.

Publishing usually brings a great deal of improvement, and browser cache and compression often help a lot too, but sometimes you just need to load assets on every single page load, and if you have lots of new users every day, browser cache will usually do very little, as this new users will need to hit the webserver and get the images for the first time in order to have it cached.

It’s been proved that loading assets from different domains helps “trick” the browser into multi-tasking, so it doesn’t have to wait until asset1 on the domain domain.com is loaded to start downloading asset2 on the same domain.

The first approach:

Most people simply create sub-domains such as assets1. domain.com, assets2.domain.com and so on. The assets are then called from the sub-domains, so the browser “thinks” it’s coming from a different location, when in reality, they normally always target the same structure.

This approach helps a lot, and if you, like me, enjoy monitoring this kind of thing, there’s a noticeable difference in loading times.

A downside to it is that you’re still hitting your webserver, and now even harder, as you’re making multiple connections at once to it. If you are loading images or small files, you shouldn’t have a problem, but things will start to get uglier if you try to load videos or heavier files.

Sub-domains approach

The second approach:

This consists in having a second webserver only to load assets while your main webserver deals with the other calls. A summary of this would be something like:

Two webservers

Basically what this horribly mocked-up image is trying to say is: You have two webservers using two different ports. The main webserver is the responsible for all the requests, but will redirect every asset call to your second webserver. What people normally do here is use two different kinds of webservers. Most commonly Apache (as the main webserver) and lighttpd as the secondary webserver. The reason why people use lighttpd, is because it’s incredibly light, and you won’t even notice it’s there.

The concept is really pretty, but it also means you’ll now have to maintain two webservers. The second one (lighttpd) should really be a one off, as once it’s configured, it will just serve static contents, but still, it’s two webservers on your server, and if anything goes wrong, it’s a bit difficult to find what and where it went wrong.

The third approach:

This is by far my favourite one. Basically it consists in hosting your assets somewhere else, where you wont have to maintain or keep an eye on performance, as this server’s primary task is to serve this kind of content. A “Buzz Word” really springs to mind here, as we are talking about the so called “Cloud Computing“. Basically it consists of a network of servers in strategic places. We call it strategic places, as the servers are located near you. Well, not near you, but from your IP, it redirects you to the closest server, from where you’re gonna be picking up the assets as they are needed.

It works pretty much as a load balancer, but based on location, instead of number of connections. It makes sure that the bits travel the shortest way in order to get to you. Works pretty much like terrestrial TV, where residences located closest to the tower will eventually get a better reception (signal) than the ones far away from it.
There’s a similarity with approach two when using this method, as it pretty much does the same thing, but uses an external server for serving and caching images. As previously mentioned, this servers are optimized for this task, therefore serving images much faster than the local server.

A representation of it would be as such:

Cloud Server

On part two, I will be showing how to have a free “CDN” for your server, and how to maintain it. I put the word CDN surrounded by quotes, as the approach I’ll be showing besides being a very common one, doesn’t really have all the benefits a true CDN has. But hey, it’s free!

Older posts