Archive for June, 2008

How do I Start Application Services with launchctl When Apple Mac Leopard Boot Up

If you have MySQL, PostgreSQL, Apache2 or other application installed from Macports, you might want the services auto start during machine start up. You can use launchctl to do it, it’s similar to start up script on FreeBSD on /usr/local/etc/rc.d or /etc/rc.d

The start up script is located at /Library/LaunchDaemons, this is what I have on my machine;

In order to add the services into launchctl, do it with below command;

Auto start MySQL

sudo launchctl load -w /Library/LaunchDaemons/org.macports.mysql5.plist

Auto start PostgreSQL

sudo launchctl load -w /Library/LaunchDaemons/org.macports.postgresql82-server.plist

Auto start Apache2 Web Server

sudo launchctl load -w /Library/LaunchDaemons/org.macports.apache2.plist

To disable the service auto start;

sudo launchctl unload -w /Library/LaunchDaemons/org.macports.apache2.plist

For more information, do man launchctl

Detect DDoS Source & Destination IP Address with OURMON

We have OURMON running on one of network segment for quite some time, it is very helpful and resourceful when DDoS attack happened, especially to help our customer to find out which destination is targeted on the attack and from which sources. Below is the graph that we previously captured while running OURMON version 2.70.

OURMON Version 2.81

On the recent released of OURMON, the topn graphs didn’t show the traffic by Mbit/s instead of bit/s. The long no. is confusing when the NOC engineer is doing the monitoring(minimal 7 digits will show up). I have made some changes on omupdate.pl, one of OURMON script that generate html static page, to show extra value - Mbit/s. Our current OURMON graph looks something like below;

Below will show you how to add extra Mbit/s value on your OURMON Topn section;

edit omupdate.pl file

vi /usr/local/mrourmon/bin/omupdate.pl

On line 3137, add the code looks like below;

my $uappf = $items[$i+2]; # old hw app flags
my $uappl = $items[$i+3]; # app lower case
my $uapph = $items[$i+4]; # app upper case
my $bps = int(($items[$i+1] * 8)/30);
my $mbps = sprintf(”%.2f”, ($bps/1024)/1024); # convert bits to mbits
my $uaf = get_appflag($uappf, $uappl, $uapph);

this line of code my $mbps = sprintf(”%.2f”, ($bps/1024)/1024); is to declare the new variable $mbps and convert the bit/s value to Mbit/s by dividing 1024*1024.

Next is to display the value on the page, do something on line of code 3146;

"bits/sec: $bps, Mbits/sec: $mbps, “

Done, wait for a few second for the web page to refresh with extra Mbit/s value. Btw, you can remove bit/s if you want to, to save some extra space ;)

OURMON Installation and Configuration on FreeBSD 7 with Multi-threading Support

OURMON is popular known as open source Network Monitoring and Anomaly Detection System. It’s very useful for a web hosting provider or Internet Service Provider to study their network behavior and detection for any network attack such as DoS or DDoS.

Beside study your network behavior, it also can analyze your network protocols activities, tcp w0rm activity, p2p activity and etc.

Here is the step by step OURMON installation and configuration on FreeBSD with multi-threading support.

OUR source package can be downloaded on official sourceforget download page. I strongly suggest that do not install OURMON from port (due to the update on the package is quite slow), but before proceed on OURMON source install, there are several dependencies need to be installed;

PCRE

cd /usr/ports/devel/pcre && make install clean distclean

libpcap

cd /usr/ports/net/libpcap && make install clean distclean

RRDTool

cd /usr/ports/databases/rrdtool && make install clean distclean

Apache Web Server

cd /usr/ports/www/apache20 && make install clean distclean

OURMON Installation and Configuration

After above dependencies has been installed, now we proceed with OURMON installation and configuration;

untar yor ourmon package and your will see a folder name mrourmon. Copy the folder to /usr/local;

cp -rf mrourmon /usr/local/

In order to enable multi-threading support, there are some changes need to be made on your OURMON’s Makefile.

cd /usr/local/mrourmon/src/ourmon
vi Makefile.bsd

On line 27 and 30, uncomment the line which look like below;

CFLAGS=-O4 -DBSD -DTHREAD
LFLAGS=-O4 -static -DTHREAD

Also on line 18, change the BINDDIR to the directory that we are going to install ourmon;

BINDIR=/usr/local/mrourmon/bin

After that, save the file and we are ready to roll, go to OURMON root directory and run configure.pl for installation;

cd /usr/local/mrourmon
./configure

Follow the on screen guide to go through the installation, after ourmon is install, we are ready to fire it up… But there are minor changes need to be made in order to support multi-threading. Open up ourmon start up file and make the below changes;

vi /usr/local/etc/rc.d/ourmon.sh

On line 11, add extra argument (-T 2 ) into OURMON launch command and it will look like this;

/usr/local/mrourmon/bin/ourmon -T 2 -a 30 -s 256 -f /usr/local/mrourmon/etc/ourmon.conf -i bce1 -D /usr/local/mrourmon/tmp &

the argument -T 2 is to spawn 2 ourmon processes, if you have more processor on your server, you might want to add more; after that monitor on your server load, see whether it will crash your server or not ;)

Run top command and monitor on your server load.

.

Apache Configuration

By default, OURMON web html files are located at /usr/local/www/data/ourmon, we suggest that you setup virtualhost to access to OURMON from your web browser;

NameVirtualHost *:80

ServerAdmin sysadm@systems.takizo.com
ServerName ourmon.systems.takizo.com

DocumentRoot /usr/local/mrourmon/web.pages


AllowOverride All
Order Deny,Allow
Deny from all
Allow from 202.188.1.5 # only allow authorized IP Address to access your OURMON.

ErrorLog /var/log/ourmon-error_log
CustomLog /var/log/ourmon-access_log common

You might also interest to change the viewing of OURMON site at your own convenience at /usr/local/www/data/ourmon/index.html, remember to make a copy before you make any changes.

Below are some graph that shown on our OURMON page;

Subversion or SVN, Basic Tips for Beginner

Been using svn for years, but always couldn’t remember what are the steps for setting it up. Better put this down here, for my future reference and sharing with people who would like to start using subversion (svn). Lets start now;

Creating Subversion SVN repository

Start creating your svn repo by this command;

svnadmin create $SVNREP_DIR/project-name

Creating trunk, tags and branches directory

svn mkdir -m “trunk creation” file:///$SVNREP_DIR/myproject/trunk
svn mkdir -m “tags creation” file:///$SVNREP_DIR/myproject/tags
svn mkdir -m “branches creation” file:///$SVNREP_DIR/myproject/branches

I believe you already have your project in a working directory, import it into your svn repo;

svn import -m “importing my project” $PROJECT_DIR/project-name file:///$SVNREP_DIR/project-name/trunk

Now you have done the setup of your repository for your new project, to build a working copy of svn on your machine, start checking out the code into your working directory.

svn co file:///$SVNREP_DIR/project-name/truck $my_project_directory

This is the basic code repository setup for with svn, more details and tips soon.

Restore Missing Menu Bar or Menulet in Mac OSX Leopard

One of my colleague menu bar / menulet is missing on her Max OSX Leopard. The time and date icon, airport icon, battery icon and others all gone missing some where. I refer to the system.log, it seem like systemui crash with some application. Here is the quick and easy way to restore your OSX Leopard Menu Bar / Menulet if you have the same problem happened to your Mac.

Click on Finder, refer to your Home directory (usually it’s your Mac’s login name), go to Library folder. And now, rename the Preferences folder to Preferences.Backup. Next, restart your Mac (not logout, restart). Please take note that it will take some time to boot up, if it freeze, turn it off and turn it on again.

Now, I believe you can see your menu bar is back, if you want the previous Preferences files to be loaded, copy it from Preference.Backup folder you have renamed earlier to Preferences folder, DO NOT replace the file it has created by the system default because the same problem may occur again.

That’s it!

Next Page »