Archive

Archive for the ‘Linux’ Category

A Shell Script to keep the Datanodes on MySQL NDB Clusters live and stable

January 7th, 2010

When i installed an ndb clusters, i found sometimes one of the datanodes, fails for some reason and they never start again untill it is manually done. So i wrote a shell script for the datanodes to check itself. The script checks in the ndbd process is running, if not its starts the process and writes a log. I added this shell script to the cron job to run the script every 10 minutes. Now the ndb clusters is perfectly stable for some months.

You may ask, 10 mins is too long. Does it mean, the database server will be down for 10 mins. Not beacuse there are more than 1 data node in the cluster, during this 10 mins other nodes will serve.

#!/bin/sh

logfile=/usr/local/mysql-cluster/restart.log

PID=`ps -eo ‘tty pid args’ | grep ‘ndbd’ | grep -v grep | tr -s ” | cut -f2 -d ”`

if [ -z "$PID" ]

then

message=`service ndbd start`

echo “`date` – NDBD started”>>$logfile

fi

Cron job that I added, (edit the file /etc/crontab and add the following line at the end)

*/10 * * * * root /path/to/the/script

This would keep the ndbclusters live for ever.

Linux, MySql NDB Clusters , ,

Ubuntu 9.10 Wireless Issue Dell 1330 or BCM4312

January 1st, 2010

To solve this issue you should make sure you have installed the right driver and also you should make sure you removed all the conflicting drivers. Because if there is any conflicting drivers installed it will not allow the kernel to load the right driver.

Packages to be intalled

bcmwl-kernel-source

bcmwl-modaliases

Packages that should not be installed or removed

b43-fwcutter

linux-backports-modules-karmic

linux-backports-modules-karmic-generic

actually no backports-modules need not be installed.

Problems solved

  • detecting wireless connections, but not able to connect.
  • Wireless not working
  • wireless is enabled but doesnt work.

Linux, Ubuntu , ,

Connecting Zantel’s Z-Connect modem to Internet in Linux(Ubuntu)

December 27th, 2009

Z-Connect is one of the fastest wireless modem in Tanzania. Connecting it in Linux was a challenge. Here is the configuration file to connect to the Internet in Linux. I am using Ubuntu.

  • In your terminal give the command

#wvdialconf

  • Edit the file /etc/wvdial.conf with your favorite text editor and overwrite the entire contents with the following

Init2 = AT+CRM=1
Dial Command = ATM1L3DT
Modem Type = Analog Modem
Phone = #777
ISDN = 0
Username = “@zantel.com”
Init1 = ATZ
Password = ” ”
Modem = /dev/ttyUSB0
Baud = 519600

  • Now come to the terminal and type the command

#wvdial

Enjoy Browsing.

Bash, Internet, Linux, Ubuntu ,

Deploying Django in Apache using mod_wsgi

June 27th, 2009

Deploying Django in Apache using mod_wsgi is the most recommended one when compared to using mod_python. Deploying Django in apache is not very difficult, its simple with quite simple steps. Here i have created a helloworld project and explained how to deploy it in apache. You must install mod_wsgi apache module before trying this.

Step 1: Create an directory named apache in your project directory. And add two files one for conf and another a wsgi application in it.

$mkdir apache

$cd apache

$touch apache_django_wsgi.conf

$touch dj_hello.wsgi

Step 2: Open the apache_django_wsgi.conf file with a text editor(gedit)and add the following contents

WSGIScriptAlias /dj “/path/to/us/project/folder/helloworld/apache/dj_hello.wsgi”

<Directory “/path/to/ur/project/folder/helloworld/apache”>

Allow from all

</Directory>

Here, helloworld is the name of the project

Step 3: Open the dj_hello.wsgi with a text editor(gedit) and add the following contents

import os, sys

#Calculate the path based on the location of the WSGI script.

apache_configuration= os.path.dirname(__file__)

project = os.path.dirname(apache_configuration)

workspace = os.path.dirname(project)

sys.path.append(workspace)

#Add the path to 3rd party django application and to django itself.

sys.path.append(‘/usr/lib/python2.5/site-packages/django/’)

os.environ['DJANGO_SETTINGS_MODULE'] = ‘helloworld.settings’

# project settings file

import django.core.handlers.wsgi

application = django.core.handlers.wsgi.WSGIHandler()


Step 4: Put an entry in your apache configuration fine (httpd.conf or apache2.conf depending upon the destro you are using)

Include “/path/to/ur/project/folder/helloworld/apache/apache_django_wsgi.conf”

helloworld, is the name of the django project that i am deploying in django. After doing all the steps don’t forget to restart the apache service for the changes to take effect.

Linux, Python, django , , , ,

IP Bonding or Teaming in Linux – RHEL 5

June 24th, 2009

IP Bonding or Teaming is a method of combining all the network interfaces togather into one with one of the types like Network Fault Tolerance, Round Robin, Back up, Loadbalancing etc. So it looks virtually as a single interface to the outside world providing high availability, based on the type you have set. Means, in a Network fault tolerant type one will take over if other fails and in a Load Balancing type trafic is shared when one busy to the other.

I got a chance of doing IP bonding in a HP Proliant Servers running RHEL 5. Everthing went well with no issues. Let me share my experience with my blog readers. In linux IP bonding is quite simple and is done with some kernel modules and no extra package is to be installed. In Windows, bonging or teaming is done with some software. With HP server, it can easily be done with some HP Network Configuration Uitlities.
Two establish IP bonding you need a minimum of two nework interfaces

Step 1:Check your network interfaces

#ethtool eth0
Settings for eth0:
Supported ports: [ TP MII ]
Supported link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
Supports auto-negotiation: Yes
Advertised link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
Advertised auto-negotiation: Yes
Speed: 100Mb/s
Duplex: Full
Port: MII
PHYAD: 1
Transceiver: internal
Auto-negotiation: on
Supports Wake-on: g
Wake-on: g
Current message level: 0×00000007 (7)
Link detected: yes

#ethtool eth1
Settings for eth1:
Supported ports: [ TP MII ]
Supported link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
Supports auto-negotiation: Yes
Advertised link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
Advertised auto-negotiation: Yes
Speed: 100Mb/s
Duplex: Full
Port: MII
PHYAD: 1
Transceiver: internal
Auto-negotiation: on
Supports Wake-on: g
Wake-on: g
Current message level: 0×00000007 (7)
Link detected: yes

Step 2: Check all the requiured kernel modules are available(bonding and mii)

#modprobe –list | grep bonding

/lib/modules/2.6.18-92.el5/kernel/drivers/net/bonding/bonding.ko

# modprobe –list | grep mii

/lib/modules/2.6.18-92.el5/kernel/drivers/net/mii.ko

Step 3: Editing the modprobe.conf file

#vim /etc/modprobe.conf

and add the following lines at the end

alias bond0 bonding

options bond0 mode=1 arp_ip_target=192.168.52.1 arp_interval=200 primary=eth0

To know more about the parameters to be used here use the command

#modinfo bonding

filename: /lib/modules/2.6.18-92.el5/kernel/drivers/net/bonding/bonding.ko

author: Thomas Davis, tadavis@lbl.gov and many others

description: Ethernet Channel Bonding Driver, v3.2.4

version: 3.2.4

license: GPL

srcversion: DB2ABCD47A83F8567EBE92B

depends:

vermagic: 2.6.18-92.el5 SMP mod_unload gcc-4.1

parm: max_bonds:Max number of bonded devices (int)

parm: miimon:Link check interval in milliseconds (int)

parm: updelay:Delay before considering link up, in milliseconds (int)

parm: downdelay:Delay before considering link down, in milliseconds (int)

parm: use_carrier:Use netif_carrier_ok (vs MII ioctls) in miimon; 0 for off, 1 for on (default) (int)

parm: mode:Mode of operation : 0 for balance-rr, 1 for active-backup, 2 for balance-xor, 3 for broadcast, 4 for 802.3ad, 5 for balance-tlb, 6 for balance-alb (charp)

parm: primary:Primary network device to use (charp)

parm: lacp_rate:LACPDU tx rate to request from 802.3ad partner (slow/fast) (charp)

parm: xmit_hash_policy:XOR hashing method: 0 for layer 2 (default), 1 for layer 3+4 (charp)

parm: arp_interval:arp interval in milliseconds (int)

parm: arp_ip_target:arp targets in n.n.n.n form (array of charp)

parm: arp_validate:validate src/dst of ARP probes: none (default), active, backup or all (charp)

parm: fail_over_mac:For active-backup, do not set all slaves to the same MAC. 0 of off (default), 1 for on. (int)

module_sig: 883f35048175a9e6e24e25c96667c37112449509f5739ebf283efa5295d315b73cee5e956f6e25709cbcf2826571c5ffc20f2d87672bb921d610d7

Step 3: Now load the modules

<!– @page { size: 8.27in 11.69in; margin: 0.79in } P { margin-bottom: 0.08in } –>

#modprobe bonding

#modprobe mii

This will create a bond0 config file in the networks-scripts directory

Step 4: Editting the three configuration files for eth0,eth1,bond0

|# vim /etc/sysconfig/network-scripts/ifcfg-bond0

DEVICE=bond0

BOOTPROTO=none

ONBOOT=yes

NETMASK=255.255.255.0

IPADDR=192.168.52.4

USERCTL=no

GATEWAY=192.168.52.1

TYPE=Ethernet

IPV6INIT=no

PEERDNS=yes

#vim /etc/sysconfig/network-scripts/ifcfg-eth0

DEVICE=eth0

BOOTPROTO=none

ONBOOT=yes

MASTER=bond0

SLAVE=yes

USERCTL=no

TYPE=Ethernet

#vim /etc/sysconfig/network-scripts/ifcfg-eth1

DEVICE=eth1

BOOTPROTO=none

ONBOOT=yes

MASTER=bond0

SLAVE=yes

USERCTL=no

TYPE=Ethernet

Step5: Restart your networks service

#/etc/init.d/network restart

#ifconfig

Now use ifconfig command to check the, you will look a new interface called bond0 has been created.  The ip you set for it is going to be your ip address of the system. Enjoy bonding

Bash, Linux, Linux Networking , , ,

Fun with Forkbombs

May 25th, 2009

Try this small shell script in your terminal. To have more fun remote login to others desktops and try this command in the terminal.

:( ){ :| :& };:

This is a strange command in linux which crashes the system. Let me explain what exactly happens when this command is executed.

  • :( ) – Function header where : is the name of the function(Colon and two parenthesis)
  • { Opens the body of the function
  • A blank space is more important here, to have a good syntax
  • : recursive call to the same function(Colon)
  • |- pipes the out put of one function call to another
  • : which calls the function again (Colon)
  • & Forks, creates a child process and assigns the function call to it
  • } Closes the function definition
  • ; delimiter to end the function definition (Semicolon)
  • : actual call to the function(Colon)

So the above script calls recursively itself twice and forks it to a child process indefinitly. At a point the memory gets full and the system crashes. You can gaurd yourself from forkbombs by restricting the number of process that can be executed at a time. Have fun with fork bombs…

Bash, Linux ,

Some Frequently used Linux Commands

May 24th, 2009

Here are some of the frequently and very useful linux commands

Command Description
top A dynamic task list
ps -e To view the current snapshot of proccess at a time
kill <process-id> Kill a process by specifying its id. Process id can be found from the previous command
killall <process-name> Kill a process with its process name. The process name can be found using ps -e command
fdisk -l Displays the partion table and list of all the memory devices connected to the system
mount /dev/<device-name> /path/to/mountpoint Used to mount a external or internal memory device to the system. The device name can be found from the previous command.
mount -t ntfs-3g /dev/<device-name> /path/to/mountpoint -o force To force mount a memory device which uses ntfs file system
sudo nautilus To open the file browser in root mode. Normally when u open the file browser in ubuntu it will not be in root mode. Provided the currnet user is a sudoer
locate <file-name-pattern> Used to search or find files by their names. Normally the search is done based on a index database. It is good to update the database before searching to get recently created files.
updatedb Used to update the file index database
cat <filename> Display the contents of a file
cat <filename> | grep <pattern> The output of the first command is given as input to the next command using a pipe. Grep command display the lines that has pattern text

Use,   man<command-name> to get more details about all the above commands

Bash, Linux ,

Vedio Recording using webcam in any Linux Distro

October 14th, 2008

For vedio recording in linux, mplayer alone may not be enough, one additional package that comes with mplayer is needed. Its mencoder. To install mencoder in a debian based distro use the command

$sudo apt-get install mencoder

For other distros like redhat you can use relevant tools like YUM to install mencoder.

Then for vedio recording follow the commad below

Video Recording Without Sound

$ mencoder tv:// -tv driver=v4l2:width=640:height=480:device=/dev/video0 -nosound -ovc lavc -o filename.avi

Video recording With Sound

$ mencoder tv:// -tv driver=v4l2:width=640:height=480:device=/dev/video0:forceaudio:adevice=/dev/dsp -ovc lavc -oac mp3lame -lameopts cbr:br=64:mode=3 -o filename.avi

To change/increase the rate of frames captured use the fps option of the above command.

Use it like

-fps 24

Rock with you webcam….

Bash, Linux