Ramblings from MostlyChris

Tech stuff and a bit more

I recently ran across a replication error in mysql that looks a bit like the following:

Error: 'Incorrect information in file… … .frm on query'

If you run the command:

mysql -e 'show engines'

You will see that the InnoDB engine is DISABLED. Since mysql ships with InnoDB enabled by default, this is a strange error.

What it turns out to be, at least in my case, is a corrupted ib_logfile. The fix is fairly simple.

1. Stop mysql.

/etc/init.d/mysql stop

2. Move or delete the ib_logfile0 and ib_logfile1 files.

mv ib_logfile0 ib_logfile0.bak; mv ib_logfile1 ib_logfile1.bak

3. Restart mysql.

/etc/init.d/mysql start

That's it. Now issuing the show engines command results in a YES for InnoDB.

I needed dump some data from a restored ibdata file on a production server. In order to do this, a second instance of mysql was started with a separate data directory. Here are the steps to make it happen.

1. Create a new data directory.

mkdir /var/lib/mysql2

2. Install the base mysql server files.

mysql_install_db –datadir=/var/lib/mysql2/

3. Copy the ibdata file AND the database directory to /var/lib/mysql2.

cp ibdata /var/lib/mysql2; cp -a [db_directory] /var/lib/mysql2

4. Make sure mysql is the owner of the directory and the files.

chown -R mysql.mysql /var/lib/mysql2

5. Change to /var/lib/mysql2

cd /var/lib/mysql2

6. In a screen session, start up a second instance of mysql and connect it to a socket.

/usr/libexec/mysqld –datadir=$PWD –log-error=innodb_recovery.log –skip-slave-start –skip-log-bin –socket=mysql.sock –port=3307user=mysql

If you have problems connecting to mysql, check the innodb_recovery.log file to see what errors you are getting.

7. Detach from the screen session.

ctrl-a ctrl-d

8. While in /var/lib/mysql2, dump the database(s) you need.

mysqldump -p -Smysql.sock –databases [database_name] > [dump_file].sql

9. Shut down the second instance of mysql.

mysqladmin -p -Smysql.sock shutdown

That's it! You should have a dump file(s) with your data in it. How you use it from this point is up to you.

mod_deflate allows apache to compress files and deliver them to browsers that can use compressed files. This saves on bandwidth and renders page loads faster. It's a fairly simple process to do this. You need to have write access to the apache config files and need to be able to create a new conf file. I am doing this on a Redhat server with Apache 2.2.3.

The first step is to make sure that mod_deflate.so is loaded in apache. You should see a line in httpd.conf similar to the following:

LoadModule deflate_module modules/mod_deflate.so

If that line does not exist, then you'll need to get the mod_deflate object file. It is generally included with apache so all you need to do is locate it on your server and load it using the correct path for where it is.

The next step is to create a config file to house the mod_deflate configuration. On my server the conf.d directory is where all such files are stored. Apache then loads files in that directory if they end in '.conf'. I created a file called mod_deflate.conf.

In my configuration, I chose to compress all files except images, files such as gzip, tar, etc. that are already compressed and PDF files (they are already fairly compressed). The configuration for that looks like this:

SetOutputFilter DEFLATE
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ \
    no-gzip dont-vary
SetEnvIfNoCase Request_URI \
    \.(?:exe|t?gz|zip|bz2|sit|rar)$ \
    no-gzip dont-vary
SetEnvIfNoCase Request_URI \.pdf$ no-gzip dont-vary

I then skip browsers that have problems with deflate.

BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html

Finally, I set some logging to test with.

DeflateFilterNote Input input_info
DeflateFilterNote Output output_info
DeflateFilterNote Ratio ratio_info
LogFormat '"%r" %{output_info}n/%{input_info}n (%{ratio_info}n%%)' deflate
CustomLog /var/log/httpd/deflate_log deflate

Make sure you restart apache after this so the new configuration file is used. Check your deflate_log to see that it is working.

To create an autoresponder or vacation notice on a server using Postfix, I use procmail on an individual account basis. In order to do this, first create a .forward file in the user's home directory with the following (quotes are to be included).

"|IFS=' ' && exec /usr/bin/procmail -f- || exit 75 #tina_fp"

Create a .procmailrc file in the same directory with the following:

SHELL=/bin/sh    # for other shells, this might need adjustment

:0 Whc: vacation.lock
 # Perform a quick check to see if the mail was addressed to us
* $^To:.*\<$\LOGNAME\>
 # Don’t reply to daemons and mailinglists
* !^FROM_DAEMON
 # Mail loops are evil
* !^X-Loop: racktest@fauxpanels.com
| formail -rD 8192 vacation.cache

  :0 ehc         # if the name was not in the cache
  | (formail -rI"Precedence: junk" \
       -A"X-Loop: racktest@fauxpanels.com" ; \
     echo "Hi,"; \
     echo "I will be out of the office from Monday August 2nd to Friday August 6th. "; \
     echo "If you need assistance, please send an email to info@blah.com or call 1-800-555-1212."; \
     echo "-Tina"; \
    ) | $SENDMAIL -oi -t

.

Replace the echo statements with your own reply text.

Read the contents of a cert:

openssl x509 -text -in [cert file]

Generate 2048 bit key and CSR:

openssl req -out CSR.csr -new -newkey rsa:2048 -nodes -keyout privateKey.key

Creating a self-signed cert with one command

openssl req -new -newkey rsa:2048 -days 365 -nodes -x509 -keyout www.example.com.pem  -out www.example.com.pem

Verify key and cert match:

(openssl x509 -noout -modulus -in server.pem | openssl md5 ;\
openssl rsa -noout -modulus -in server.key | openssl md5) | uniq

More as I find them…