Archive for the ‘Tech’ Category

Upgrading SynergyKM to use 1.3.1

Monday, August 18th, 2008

I recently discovered SynergyKM which is a Mac OS X (works on Leopard) frontend for Synergy. All SynergyKM does is write out the config file for Synergy and manipulate the daemon. I noticed that SynergyKM is bundled with Synergy 1.3.0. There was a specific OS X bug in 1.3.0 that was fixed in 1.3.1. Here is how to upgrade the SynergyKM to version 1.3.1.
(more…)

MySQL 5 Replication

Monday, January 14th, 2008

I recently setup MySQL 5 replication between two RHEL servers. I made a small writeup on what I had to do to get things working. In my configuration I am loading the initial database from the master, as opposed to manually copying it (via SCP). I’m assuming you have two working MySQL servers. Both with the mysql root password set, and “skip-networking” etc. commented in the configuration. I also assume open communication (iptables or otherwise) between servers. Remember you can test communication like this: telnet your-server 3306

Note: The slave server has to be equal or greater than the master version.

Do the following on the Master:

1) Insert this into your /etc/my.cnf (this is the most common location for this file, yours may be elsewhere):

[mysqld]
log-bin=mysql-bin
server-id=1

2) Open a mysql connection:

mysql -u root -p
mysql> GRANT ALL ON replicationdb.* TO slave_user@'%' IDENTIFIED BY 'slave_password';
mysql> FLUSH PRIVILEGES;
mysql> GRANT REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO slave_user@'%' IDENTIFIED BY 'slave_password';
mysql> GRANT RELOAD ON *.* TO slave_user@'%' IDENTIFIED BY 'slave_password';
mysql> QUIT;

3) Replace “replicationdb” with the database you want to replicate. Use * for all. Replace “slave_password” with a password.

4) Assuming your init scripts are setup correctly, restart the MySQL service:
/etc/init.d/mysql restart
If you don’t have an init script in place, use this:
mysqladmin shutdown; ./bin/safe_mysqld&

Do the following on the Slave:

1) Insert this into your /etc/my.cnf (this is the most common location for this file, yours may be elsewhere):


[mysqld]
log-bin=slave-relay-bin
# Each server must have a unique ID.
server-id=2
# The hostname or IP of your master.
master-host=192.168.5.200
# This user should have the necessary privileges on the database(s).
master-user=slave_user
# The password generated for the slave user.
master-password=slave_password
# The database to be replicated. 
# By default all databases will be replicated. 
# Omit this to replicate everything, including the "mysql" database (users and privileges). 
# Use multiple lines for multiple databases.
replicate-do-db=replicationdb

2) Assuming your init scripts are setup correctly, restart the MySQL service:
/etc/init.d/mysql restart
If you don’t have an init script in place, use this:
mysqladmin shutdown; ./bin/safe_mysqld&

3) Open a mysql connection:

mysql -u root -p
mysql> LOAD DATA FROM MASTER;
mysql> QUIT;

4) To check status of the master:
mysql> SHOW MASTER STATUS;

5) To check status of the slave:
mysql> SHOW SLAVE STATUS;

GTO on Maxtor PCB

Monday, November 26th, 2007

A little while ago I found an image of a car (specifically a GTO) on the back of an old Maxtor hard drive PCB. I just recently had a chance to take some high res pictures.

gto2.jpg

Click the above image to see a high resolution image of the full drive.

Synergy Client Mac OS X Leopard

Saturday, November 24th, 2007

I recently got a new 24 inch iMac and needed a way to share my keyboard and mouse between Mac OS X 10.5 (Leopard) and Windows XP. Synergy does exactly that. Setting up a Synergy server under XP was simple, but the Mac client was a little more tricky.

Apparently there is a bug in Synergy 1.3.1 with OS X 10.5. When you try to start Synergy (client or server) as a daemon under OS X 10.5 it crashes. Below is a workaround which starts the Synergy client at boot in the foreground (-f) through launchd. Put this file in /Library/LaunchAgents/net.sourceforge.synergy2.plist (needs root privileges):


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>net.sourceforge.synergy2</string>
    <key>OnDemand</key>
    <false/>
    <key>ProgramArguments</key>
    <array>
        <string>/usr/local/bin/synergyc</string>
        <string>-f</string>
        <string>-1</string>
        <string>--name</string>
        <string>imaczomg</string>
        <string>--debug</string>
        <string>WARNING</string>
        <string>deathstar</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
</dict>
</plist>

Here is what the argument string will look like:
/usr/local/bin/synergyc -f -1 –name imaczomg –debug WARNING deathstar

/usr/local/bin/synergyc - the path to your synergy client binary
-f - run in the foregorund
-1 - do not restart on error (launchd will do this for us)
imaczomg - the name (or IP) of your mac client
–debug WARNING - won’t log every time the mouse moves off the screen
deathstar - the name (or IP) of your server

If you are running a Synergy server on OS X 10.5 please look here.

Unix Home Directories with winbind

Tuesday, September 11th, 2007

At work we have some Unix machines that authenticate with the Win2k3 domain. Problem is, when new users are created on the domain, Unix home directories are not created. You could set PAM to created the home directory upon first SSH login. However if the user logs in via SFTP or SMB the home directory would not be created. Below is a script I wrote (runs in cron) to create home directories for new users. Basically it checks the contents of “/home” against “wbinfo -u”.

#!/bin/sh
# Steve Horbachuk 2007
# Creates home directories for users that don't already have them

# Remove these:
# Administrator
# Guest
# krbtgt
# SUPPORT_388945a0
# IUSR_SERVER
# IWAM_SERVER
# stu
# fac

WBINFO=/usr/bin/wbinfo
SED=/bin/sed
LOG=/var/log/my-mkhomedir

# check if winbind is working
$WBINFO -u > /dev/null
if ! [ $? = "0" ]; then
echo "Get user list failed!"
echo "Is winbind running?"
exit 1
fi

LIST=`$WBINFO -u | $SED -e '/Administrator/d;/Guest/d;/krbtgt/d;/SUPPORT_388945a0/d;/IUSR_/d;/IWAM_/d;/fac/d;/stu/d'`

for USER in $LIST; do
if [ ! -d /home/${USER} ]; then
echo `date` Created ${USER} >> $LOG
mkdir /home/${USER}
cp -R /etc/skel/* /home/${USER}
chown -R ${USER} /home/${USER}
chgrp -R 'Domain Users' /home/${USER}
chmod 711 /home/${USER}
fi
done
exit 0

Kernel Packages

Tuesday, September 4th, 2007

I had to recompile my Debian Etch (4.0) kernel to include the Layer7 filter (and ipp2p) source patch as well as include Netfilter support.

Here are the prebuilt kernel packages:
http://stevehorbachuk.com/kernels

You can add then to a Debian system by doing this:

dpkg -i linux-image-2.6.22.5-custom2_2.6.22.5-custom2-10.00.Custom_i386.deb
dpkg -i linux-headers-2.6.22.5-custom2_2.6.22.5-custom2-10.00.Custom_i386.deb

This will automatically add this custom kernel to /boot/grub/menu.lst.

pcns221lnx.bin & Red Hat Enterprise Linux 4

Monday, September 3rd, 2007

pcns221lnx.bin is the APC Network Shutdown installer for Linux. It took me a while to figure out how to install this software on Red Hat Enterprise Linux 4, so I figured I’d drop a note here.

PCNS is poorly maintained and is a few years old now. Additionally Red Hat ships with GCJ java, which is shit. Upon execution it would throw cryptic error messages such as:

Preparing wizard…
Searching for JVM…
Starting the wizard…
Error: You need Swing 1.1 or 1.2 in your classpath to run this program.

And:

Preparing wizard…
Searching for JVM…
Starting the wizard…
See errors.log for other possible causes.out of disk space?

The biggest problem I had was that the installation documentation does not mention that the installer requires an X Server! Thanks a lot APC!

Here’s what I did to install it:

ssh steve@server

su
Change to root

rpm -e java-1.4.2-gcj-compat-1.4.2.0-27jpp
rpm -e java-1.4.2-gcj-compat-devel-1.4.2.0-27jpp
Remove old Java packages

rm -rf /usr/local/bin/jvm
Clean up if needed

mkdir /usr/java
Make new installation directory

cd /usr/java
Change to that directory

wget -O jre.bin http://javadl.sun.com/webapps/download/AutoDL?BundleId=11284
Download the JRE binary installer

chmod a+x jre.bin
Change permissions to allow execution

./jre.bin
Execute the JRE installer and follow the prompts

export PATH=$PATH:”/usr/java/jre1.6.0_02/bin”
Include the JRE binaries in the PATH where “jre1.6.0_02″ is the JRE version you installed

vi /root/.bash_profile
Change line that begins with “PATH” to this “PATH=$PATH:$HOME/bin:/usr/java/jre1.6.0_02/bin” where “jre1.6.0_02″ is the JRE version you installed

which java && java -version
Check if everything is working

up2date -i xorg-x11 xterm
Install X11 (if not already installed)

Launch a SSH session with X-Win32:

su
Change to root

cd /usr/local/src
Change to our source/installer directory

wget ftp://ftp.relline.ru/pub/unix/apc/pcns-221/pcns221lnx.bin
Download the PCNS binary installer

chmod a+x pcns221lnx.bin
Change permissions to allow execution

./pcns221lnx.bin
Execute the PCNS installer and follow the prompts

PowerChute Network Shutdown

ps -ef | grep “jre”
Make sure the PCNS process is running

Intel Create and Share

Thursday, August 16th, 2007

I have an Intel PC Camera Pro and I had a hell of a time getting drivers and software that work with Windows XP. Intel tries to make you buy a CD, forget it. If you have an older Intel web cam and can’t find drivers, try these.

Download Intel Create and Share Software

Backup Script

Wednesday, August 15th, 2007

I recently created a BASH script that creates a g-zipped tarball and writes it to a NAS. It also checks the free space available on the NAS and deletes previous backups until it has enough space to store a new backup. Maybe someone will find it useful or will be inspired to improve it.

Variables to modify:

DATA = What directories you want to backup.
LOGDIR = Where you want the backup logs to be stored.
BACKUPMNT = The mount point of your NAS or backup device.
BACKUPDIR = The directory on the mount to store the backup.

#!/bin/bash
# Steve Horbachuk 2007
# tars directories and writes to NAS
#

DATA="/home /root /etc /usr/local /var/www /var/log"
LOGDIR="/var/log/my-backup"
BACKUPMNT="/mnt/linkstation"
BACKUPDIR="/mnt/linkstation/server"
MYDATE=`date +%F`
LASTFILESIZE=0
LASTFILENAME=""

echo "Backup started : `date`" > $LOGDIR/backup_$MYDATE.log
echo "-------------------------------------------------" >> $LOGDIR/backup_$MYDATE.log

#find the last file in the backup folder
#and store information about it.
for FILE in $BACKUPDIR/*; do
if [ -f $FILE ]; then
FILEINFO=(`ls -lk $FILE`)
LASTFILENAME=${FILEINFO[8]}
LASTFILESIZE=${FILEINFO[4]}
fi
done

#delete files until there is enough space to hold a file
#the same size as the last backup.
for FILE in $BACKUPDIR/*; do
DISKINFO=(`df -k | grep $BACKUPMNT`)
DISKFREE=${DISKINFO[3]}
if [ -f $FILE ]; then
if [[ "$LASTFILESIZE" -gt "$DISKFREE" ]]; then
rm -vf $FILE >> $LOGDIR/backup_$MYDATE.log
fi
fi
done

tar -czf $BACKUPDIR/backup_$MYDATE.tar.gz --exclude='*.iso' --exclude='*/tmp/*' $DATA >> $LOGDIR/backup_$MYDATE.log

echo "-------------------------------------------------" >> $LOGDIR/backup_$MYDATE.log
echo "Backup finished : `date`" >> $LOGDIR/backup_$MYDATE.log

Here is the mount in /etc/fstab:
//10.0.0.50/share /mnt/linkstation cifs rw,guest 0 0

Where “//10.0.0.50/share” is the SMB share on the NAS, and /mnt/linlkstation is the Linux mount point.