Archive

Archive for March, 2010

Installing Git on CentOS 5

March 25th, 2010 Dominic Baranski View Comments

This technique requires the “Extra Packages for Enterprise Linux” repo.. So this is not a .rpm install from some untrusted site. It’s from the RedHat repos themselves.

Firstly, install the EPEL package. More information on EPEL is available from their site. Then, install git and you’re done!

su -c 'rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-3.noarch.rpm'
yum install git

See the EPEL FAQ for more details.

Categories: CentOS Tags: , , ,

Slow SSH Logins on CentOS 5

March 24th, 2010 Dominic Baranski View Comments

Following any of the usual how-to’s didn’t leave me with a successfully speedy login.. I eventually tracked down the problem to a particularly monumental bug in RedHat’s OpenSSH server (apparently fixed up stream.. it does us all now no good)..

The fix

  1. edit /etc/ssh/sshd_config
  2. Find and change the lines (or add if missing):
    GSSAPIAuthentication yes
    ...
    #UseDNS yes

    to

    GSSAPIAuthentication no
    ...
    UseDNS no
  3. Enjoy

Side Note

If you use CentOS you’re probably unable to reboot your SSH server and you don’t know it.

I also experienced this problem while attempting to restart the ssh server. Everything seemed to work but when checking the logs it showed serious errors. It complained about being unable to bind to port 22. To see if you have the same problem follow these steps..

/etc/init.d/sshd reload
tail /var/log/secure

If you find something like the following:

sshd[20213]: Server listening on :: port 22.
sshd[20213]: error: Bind to port 22 on 0.0.0.0 failed: Address already in use.

then you’ve got problems.. It’s basically saying that the localhost IPv6 address (represented as “::”) is hogging port 22 instead of 0.0.0.0 (means ANY IPv4 address). If that’s what you want, then great! If not..

edit

/etc/ssh/sshd_config

and change it to look as follows from

#ListenAddress 0.0.0.0
#ListenAddress ::

to

ListenAddress 0.0.0.0
#ListenAddress ::

Hope this helps!

References

Categories: CentOS Tags: , ,

JSON Data Wrappers

March 19th, 2010 Dominic Baranski View Comments

Many people use JSON nowadays to output information. Its lightweight and awesome! So why not. But I find that people neglect to maintain an appropriate syntax, if you will, while writing JSON output.

Now, what I mean by “wrappers” is that most examples I’ve seen send back a JSON list. This list should always be wrapped with additional server information in case of internal server errors (500 errors) or the need for other clarifications (errors, total item counts, etc).

A basic example wrapper

{
"status": "ok",
"message": "",
"resultCount": 10,
"resultOffset": 3
"resultSet" : ["one", "two", "three"]
}

Using this Style of wrapper I know:

  • There were no problems on the server side (the status entry)
  • There are 10 results in total for whatever I want (the resultCount entry)
  • The results are offset by 3 (the resultOffset)
  • I have 3 results to display to the end user (the resultSet entry)

Note that some of these parameters could be optional (like offset).  But make sure that whoever is writing the JavaScript knows this!  It could otherwise cause unrecoverable JavaScript errors.

Server Error handled gracefully

{
"status": "error",
"message": "Database Error",
"resultCount": 0,
"resultSet" : []
}

Here’s an example of a server 500 that, despite being completely unrecoverable, still gracefully displays JSON as to not cause execution errors in the browser.  Note that I omitted resultOffset as I am using this parameter optionally.  I do return an empty resutSet though.  JUST in case someone forgot to program any error handling in the JavaScript.

Looking Forward

This is only a simple example of what your wrapper should include, feel free to add other information like a timestamp for when it was served or other important data.  To get you started look at some examples from Google or Yahoo for ideas.