Percona’s XtraDB Cluster synchronizes quickly enough that you can simply put it behind a load balancer. There is no need to only write to a master, or use regular SQL replication. I am using it behind a hardware load balancer. You can simply have it check that MySQL is running by connecting to port 3306, but you could also do something a bit more sophisticated and make sure that MySQL is accepting logins, and that the cluster is fully synced. (more…)

WordPress is PHP based CMS that uses MySQL for its backend. It’s incredibly easy to use once configured. By design, every page load is dynamic, and content is selected out of the database. Even if content has not changed, every page load requires several queries and of course running a significant amount of PHP code. With a very popular WordPress blog or a lower end server, this can quickly become a problem. Loading just the index page of my WordPress blog requires 9 SQL queries (I have a few plugins that may contribute to this). Seeing as how I post only once every few months, wouldn’t it be nice if the content could be served as static content? It would not require PHP to be invoked at all, let alone MySQL.(more…)

Monit is an opensource tool for monitoring services and files. It can monitor your services to see if they are listening on the port they are supposed to, to see if they are using too much memory or CPU, or it can just check if your service is even running. This could be the difference between reading an email the next day about how a service was restarted, and being paged at 2am to restart a service. (more…)

Zabbix is a very powerful opensource monitoring system developed in PHP. It is fairly easy to install, but the web interface is unintuitive to say the least. This guide will cover installing the Zabbix server daemon on CentOS 6 using the MySQL backend. Version 2.0.x will be used as that is the latest stable version as of the writing of this article. Part two of this article will cover setting up the Zabbix agent on a server to be monitored, part three will cover setting up notifications when a service goes down, and part four will cover setting up custom web scenarios for monitoring a website.

The good news it that the injected JavaScript is always in between these two constants: /*km0ae9gr6m*/ and /*qhk6sa6g1c*/. This looks like a job for a simple bash script, but I’m always doing things the wrong way so I wrote a quick PHP script that cleans the files. (more…)

Nginx is very useful as a mail proxy. You can have it call perl script (or any other kind of script served via HTTP) to do authentication, determine the back-end IP and port, or change the proxied username and password.

After the front-end (Nginx) does authentication, it passes the user’s credentials to the back end (some IMAP server in this case). During testing I found that authentication was always failing. Doing an strace showed that Nginx does not send a standard “tag login username password” but instead breaks this into three commands via a feature of IMAP called command continuation request.

I recently was tasked with investigating why a mail server was running slow. It had an incredible amount of disk IO and a high await. I was tasked with identifying what was causing this IO usage and if anything could be done.

It was immediately obvious that the imapds running on the server were using the majority of IO resources. Newer Linux kernels expose IO usage stats per process in /proc/{pid}/io. I ended up writing a script that walks /proc and looks for processesed named ‘imapd.’ It stores the current amount of bytes read and written (read_bytes and write_bytes)

It’s pretty straight forward. I walk /proc to get the stats and save the state. I sleep for a few seconds, and then walk proc again. For each pid I then print the difference in bytes read and written compared to the first walk. This shows who used the most I/O over that time period. I don’t just look at the total bytes of IO because some processes are around longer than others and I want to know what is causing a problem right now. This script successfully identified several problem users. (more…)

All of my programming classes in college were in C, but unfortunately I forgot most of it. I’ve been trying to re-learn, and I started with the simplest IRC bot possible. This code simply connects to an IRC server by its IP address on port 6667, logs in, and responds to PING commands.

I start by creating a socket.

if ( (*sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {

Inet_pton is used to convert a IP address string into a number. Inet_aton would also work but there is no reason to use it as pton also supports IPV6 addresses.