Busy holidays, and back to blogging

It’s been a long, busy holiday- and now time to resume blogging. My latest interest is testing our mysql servers using mysqlslap. While a great tool, it is unfortunately only distributed with MySQL 5.1.4 and above. However, many of our servers are in the 5.0 release, with some in the 4.x release. What I did was grab the latest 5.1.x version of mysql, compile it statically and test it out on a MYSQL 5.0.45 version, and it worked just fine. I have yet to test it on another machine, or against a version other than 5.0.45. I’ll update when I do.

Here are the steps I took:

1) wget “http://dev.mysql.com/get/Downloads/MySQL-5.1/mysql-5.1.30.tar.gz/from/http://mysql.llarian.net/”

2) tar -xf mysql-5.1.30.tar.gz&&cd mysql-5.1.30

3) ./configure –without-server –disable-shared

4) make&&cp -i ./client/mysqlslap /usr/local/bin/

Securely specify mysql credentials in automated scripts

Often, you may want to run a script that uses a username and password to access data in a MySQL database. Securely running a script like this manually is easy – simply use the ‘-p’ option for the MySQL client, and it will prompt you for the password. However, this is not an option if you want to automate the script.

There are several ways to provide the password in a way that can be used with automated scripts, but only one that is both flexible and secure. You can specify the password on the command line itself (with ‘mysql -p ‘); however, this allows the password be seen by other users who run commands like ‘ps’. Another option is setting the environment variable “MYSQL_PWD” to the password, but this can also be seen by other users. Continue reading “Securely specify mysql credentials in automated scripts”

Using the Data::Dumper module to debug your Perl scripts

If you’re ever writing a Perl script that contains fairly complicated data structures (multi-dimensional arrays, hashes of arrays, etc), or you’re debugging code that contains complicated objects, it may be helpful to view the current state of those data structures in their entirety.

This is easy to do with Data::Dumper. Although the features the module provides are fairly complex, it’s easy to use it to just print out the contents of something. Do do this, you’ll first need to import the module with ‘use Data::Dumper;’. Then, to dump the data in an array(for example), simply do ‘print Dumper(@array)’. Continue reading “Using the Data::Dumper module to debug your Perl scripts”

Easily installing Perl modules with Yum

Although many Perl modules are available through Red Hat and CentOS’s repositories, the name the modules have in the repository differ from the name of the module itself.

To use yum to install a Perl module using the module name, just place ‘”perl()”‘ around the name of the module (double quotes included) when giving it as an argument to yum. For example, to install the ‘Net::Telnet’ module, you would run ‘yum install “perl(Net::Telnet)”‘.

Alternatively, to construct the correct package name, you would prepend the module’s name with ‘perl-’, and change all of the instances of ‘::’ to ‘-’. For example, the package for the ‘Net::Telnet’ module would be ‘perl-Net-Telnet’.

Finding space hogs

I know this is a common post out there, as a google search will bring this up multiple times, but here it is anyway. A great alias to set up on your system to aid in finding space hogs in a given filesystem or directory is as follows:

alias ducks=’du -cks * |sort -rn |head -11′

Add the aliases to whichever file you keep them in (.bashrc, .aliases, etc)  and then run ‘ducks’ for output similar to this: Continue reading “Finding space hogs”

OpenSSH SOCKS proxy support

Often, when you’re administering or developing on servers remotely, you may need to access resources that are not available to the public. There are several different ways that you can gain access to protected services from a remote location, including a VPN, port forwarding over SSH, and stunnel.

However, one method that is not as well known is OpenSSH’s SOCKS proxy option. Introduced in OpenSSH 3.7, SOCKS support allows you to easily tunnel traffic from any application that has support for a SOCKS4 or SOCKS5 proxy through your SSH connection. To do this, you simply need to add ‘-D <port>’ to your ssh connection string, where <port> is the port you would like your proxy to run on. Then, configure your application to use a proxy at localhost:<port>, and all of the traffic from that application will be tunneled through your SSH connection.

In addition to accessing protected resources, you can also use this for more everyday tasks – such as encrypting traffic sent over a public wireless connection.

Mysql table opens, caching and iowait times

One issue that seems to be very common when running a MySQL server is high iowait. As we have delved into our servers, one of the main causes we have found is that our table_cache was set too low, causing an ever increasing number of table opens

One issue that seems to be very common when running a MySQL server is high iowait. As we have delved into our servers, one of the main causes we have found is that our table_cache was set too low, causing an ever increasing number of table opens. As we increased the table_cache, and watched for higher hit percentages, we were stumped regarding how many table opens in a given time period were acceptable. A number which I use as a guideline was given to me during a MySQL training course this year. We use a guideline of no more than 10 table opens per hour. More than that- and we need to increase table_cache.

Human readable disk usage

Finding out what directories and files are using up the disk space on your server is fairly easy with du, but the output is not always easy to read.

However, it’s not too hard to pretty up the output with some perl and the module Number::Bytes::Human (available from CPAN). To convert normal du output into a more human readable form, which shows file size in the correct units (K, M, or G) and also includes the percentage of the total space each entry is using, use the follwing steps.

Finding out what directories and files are using up the disk space on your server is fairly easy with du, but the output is not always easy to read.

However, it’s not too hard to pretty up the output with some perl and the module Number::Bytes::Human (available from CPAN). To convert normal du output into a more human readable form, which shows file size in the correct units (K, M, or G) and also includes the percentage of the total space each entry is using, use the follwing steps. Continue reading “Human readable disk usage”

Building a kernel RPM from source

While it is reasonably easy to build a kernel RPM on a Redhat or CentOS system using the kernel src rpm, another way is to do a standard kernel build (download your kernel from kernel.org), configure as usual. However, instead of just doing a standard “make” or “make bzImage”, do “make rpm“, and voila! You’ll be left with your kernel rpm in /usr/src/redhat/RPMS/{arch}, and your very own src rpm in /usr/src/redhat/SRPMS. Easy, right?