MS Office 2007 Formats in Apache

In Apache 2 I added the following to stop Internet Explorer trying to open these formats as compressed archives (which they actually are) and to open them using the MS Office appliations:

AddType application/vnd.ms-word.document.macroEnabled.12 .docm

AddType application/vnd.openxmlformats-officedocument.wordprocessingml.document docx
AddType application/vnd.openxmlformats-officedocument.wordprocessingml.template dotx
AddType application/vnd.ms-powerpoint.template.macroEnabled.12 potm
AddType application/vnd.openxmlformats-officedocument.presentationml.template potx
AddType application/vnd.ms-powerpoint.addin.macroEnabled.12 ppam
AddType application/vnd.ms-powerpoint.slideshow.macroEnabled.12 ppsm
AddType application/vnd.openxmlformats-officedocument.presentationml.slideshow ppsx
AddType application/vnd.ms-powerpoint.presentation.macroEnabled.12 pptm
AddType application/vnd.openxmlformats-officedocument.presentationml.presentation pptx
AddType application/vnd.ms-excel.addin.macroEnabled.12 xlam
AddType application/vnd.ms-excel.sheet.binary.macroEnabled.12 xlsb
AddType application/vnd.ms-excel.sheet.macroEnabled.12 xlsm
AddType application/vnd.openxmlformats-officedocument.spreadsheetml.sheet xlsx
AddType application/vnd.ms-excel.template.macroEnabled.12 xltm
AddType application/vnd.openxmlformats-officedocument.spreadsheetml.template xltx

Set MySQL to Read-Only

For a backup server which we may want to run as read-only for short maintenance periods the following may be useful.
Method 1: Global read_only
Login to MySQL and set the read_only setting to true:

mysql -u root -p
set GLOBAL read_only = true;

To unset this run:

set GLOBAL read_only = false;

Method 2: Read Lock
Another method which will queue queries while the tables are locked and then run them when the tables have been unlocked involves:

FLUSH TABLES WITH READ LOCK;

To revert back use:

UNLOCK TABLES;

Exchange Offline Address Book Not Updating

Some users where complaining about the Offline Address Book being out-of-date. Checking the Event Viewer on the cluster node which creates the OAB showed the following error:

OALGen detected that the file ‘…..lzx’ is corrupted
or missing. This indicates data tampering or disk problems. Restore
files in this folder from the recent backup or clean up folder content
and force a full OAB generation. – Default Offline Address Book

So I ran:

Get-OfflineAddressBook | fl Name,Server,AddressLists,IsDefault,Guid

This gets the Guid for the Address Book which we use in:

Update-OfflineAddressBook <paste GUID here>

The Event Log showed another error and advised increasing the verbosity of error logs so I ran:

Set-EventLogLevel -id “MSExchangeSA\OAL Generator” -Level expert -verbose

I then ran the Update-OfflineAddressBook command again and this time there were extra information logs in the event log but the updated OAB was created.

Update-OfflineAddressBook <paste GUID here>

I checked that the OAB was being replicated out to the CAS servers.
A great post about Exchange OAB can be found here including a script to check for the staleness of the OAB.

Apache Server Status OPTIONS *

Checking the Apache server-status page I noticed multiple lines like the following:

29-39 0/0/3162 . 32.26 8949 0 0.0 0.00 186.48 123.111.123.111 mywebsite.co.uk OPTIONS * HTTP/1.0
30-39 0/0/10 . 0.00 24324 0 0.0 0.00 0.04 123.111.123.111 mywebsite.co.uk OPTIONS * HTTP/1.0

The access_log for that website also showed:

123.111.123.111 – – [18/Nov/2009:09:28:44 +0000] “OPTIONS * HTTP/1.0” 200 – “-” “Apache/2.2.3 (Red Hat) (internal dummy connection)” 2468
123.111.123.111 – – [18/Nov/2009:09:35:37 +0000] “OPTIONS * HTTP/1.0” 200 – “-” “Apache/2.2.3 (Red Hat) (internal dummy connection)” 1924

Apparently these are Apache calling itself to keep child processes alive:

When the Apache HTTP Server manages its child processes, it needs a way
to wake up processes that are listening for new connections. To do
this, it sends a simple HTTP request back to itself.

mysqldump

Basic Usage:

mysqldump -u root -pSECRET –quote-names –databases  mydatabasename > mydatabasename.sql

If find it best to include the –databases switch as this will add the ‘DROP DATABASE’ and ‘CREATE DATABASE’ statements when restoring – proceed carefully.
Quote Names:

Quoting the file names can be an insurance against users who may have created field names with spaces in them šŸ™

mysqldump -u root -pSECRET –quote-names –databases mydatabasename > mydatabasename.sql

Dump All Databases:

mysqldump -u root -pSECRET –quote-names –all-databases > fullbackup.sql

Zip the ouput file:

nice mysqldump -u root -pSECRET –quote-names –databases dbname1 dbname2 dbname3 | nice gzip -9 > mybackup.sql.gz

Compatibility:

mysqldump -u root -p  –compatible=mysql40 –databases databasename > mybackup.sql

Other compatibility options include:

ansi, mysql323, mysql40, postgresql, oracle, mssql, db2, maxdb, no_key_options, no_table_options, no_field_options

Dump structure-only:

mysqldump -u root -p –no-data –databases dbname1 dbname2 > mybackup.sql

Backup to another MySQL Server

mysqldump -u root -p –host=host1 mydatabase | mysql -u root -p –host=host2 -C newdatabase

The C option specifies to use compression. Note databases must exist already on the target server.

Restore

mysql -u root -p dbname < mybackup.sql

Character Sets / Collation Problems
Convert the database exporting first like this:

mysqldump -u username -p –default-character-set=latin1 –compatible=mysql40 dbname > dump.sql

Then import overwriting the current database (another backup would be wise):

mysql -u username -p –default-character-set=utf8 dbname < dump.sql

MySQL Adding Users
In case you need to access the MySQL database remotely (as in the above example to backup to another server):

mysql -u root -p
grant all privileges on *.* to ‘jonny’@’%’ identified by ‘thepassword’;
flush privileges;
exit

Fighting Spam in QUB Exchange

If you are suffering problems with Junk Email please check or do the following:

Cached Exchange Mode

Check that you are using Cached Exchange Mode:

  • In Outlook 2007 choose Tools > Account Settings …
  • In the Account Settings dialog select the ‘Microsoft Exchange’ account then click the ‘Change…’ button
  • In the ‘Change E-mail Account’ dialog ensure the option for ‘Use Cached Exchange Mode’ is ticked

Exchange Junk Email
Ensure that your mailbox account on Exchange is set to filter Junk Email:

  • Log in to OWA using MS Internet Explorer (not Firefox)
  • Click on ‘Options’ at the top right of the page
  • Click on ‘Junk E-mail’ on the left menu
  • Ensure that ‘Automatically filter junk e-mail’ is selected

Example robots.txt

Not all crawlers obey all of these rules but as a reference point. The crawl delay is the number of seconds between requests and the newer request-rate is set here to not more than 1 every 5 seconds. The crawlers are also asked to visit during the night.

User-agent: *
Disallow: /media/
Crawl-delay: 10
Request-rate: 1/5
Visit-time: 2100-0545

Tar Backup/Restore Grub Boot Issues

We have two machines with identical hardware. The second machine is a backup to the first machine to be used if any issues arise with the primary machine/service.
So we created a tar backup of the primary machine using:

#!/bin/bash
/bin/nice /bin/tar czpf /www/archive/backup/system/system_full.tar.gz \
–same-owner  \
–exclude=/proc/* –exclude=/media/* \
–exclude=/dev/* –exclude=/mnt/* –exclude=/sys/* –exclude=/tmp/* \
–exclude=/home/* –exclude=/var/backups/* –exclude=/var/lib/mysql/* \
–exclude=/var/www/* –exclude=/www/* / \
2>/var/log/system_backup_error.log

We could consid also exclude the /boot directory so as not to run in to boot problems on the second machine.
When we extracted this tar file onto the second machine and rebooted we encountered two issues which would need to be resolved  before the secondary backup machine could be used for the primary service:
1. Grub did not boot with the following error message
2. The network interfaces would not come up as the mac addresses were obviously different

GRUB PROBLEM
The error message we received when booting was:

filesystem type unknown partition type 0x8e

Type 0x8e represents an LVM partition but we need 0x83 ext2 filesystem.
Examining the /boot/grub/menu.lst config file we can see that Grub was trying to boot the following:

title CentOS (2.6.18-128.2.1.el5)
        root (hd0,1)
        kernel /vmlinuz-2.6.18-128.2.1.el5 ro root=/dev/VolGroup00/LogVol00 rhgb quiet
        initrd /initrd-2.6.18-128.2.1.el5.img

The problem was the “root (hd0,1)” line which should be “root (hd0,0)” on the secondary machine. On the first primary machine /dev/sda2 was mounted to /boot but on the secondary machine /dev/sda1 was mounted to /boot. So I am putting this issue down to slightly different partitioning during initial setup (even though we tried to get them completely mirrored I think there was some Sun FAT partitions left on the primary machine as /dev/sda1).

To resolve the issue temporarily from within Grub:

  • Go to the command line by typing ‘c’
  • Set the root device:
    root (hd0,0)
  • Boot
    boot

It is also possible to set the kernel and ramdisk as explained in this post:

  • Set the kernel
    kernel /vmlinuz[tab to find available kernels]
  • Set the ram disk
    initrd /initrd[tab to find available ram disks]
  • Boot
    boot

To resolve the boot issue permanently: 
After booting edit the menu.lst file:

vi /boot/grub/menu.lst

Replace root (hd0,1) with root (hd0,0)

NETWORK INTERFACES
When the secondary machine booted the interface configuration files in /etc/sysconfig/network-scripts contained the MAC addresses for the primary machine which did obviously not exist on the secondary machine. Red Hat/Centos thankfully backed up the existing config files with a .bak extension and created new ones with the correct mac addresses. So To keep the secondary machine as a potential backup to the primary machine I will create 2 sets of network config files with the relevant IP addresses and mac addresses.

Apache LDAP Authentication to Active Directory

I was testing authentication against Active Directory (LDAP) using Apache 2. The following worked for me in a .htaccess file but only after adding:

LDAPVerifyServerCert Off

in the main httpd.conf file. I presume this is related to the server name in the SSL certificate on the Active Directory server.

AuthBasicProvider ldap
AuthzLDAPAuthoritative Off
AuthLDAPURL ldaps://adserver.prefix.tld.co.uk:636/DC=prefix,DC=tld,DC=co,DC=uk?sAMAccountName?sub?(objectClass=user)
AuthLDAPBindDN “CN=someuser,OU=some ou,OU=another unit,OU=department,OU=directorate,OU=Administration,OU=another big unit,DC=prefix,DC=tld,DC=co,DC=uk”
AuthLDAPBindPassword secret
AuthType Basic
AuthName “Protected”
require valid-user

Normal users should then be prompted for a username and password to access the directory and if correct credentials are supplied should be given access to the content.