Which Linux distribution is more suitable for you regarding your experience and preferences ?

find it at :

http://www.zegeniestudios.net/ldc/index.php?lang=en

Mine was 100% Debian / 100% Ubuntu

No surprises on that !

Bye
Riccardo

This post will explain how to disable IPv6 in a system running Debian GNU/Linux or Ubuntu Linux.

You should want to disable IPv6 for compatibility reason or if you not plan to use it for speed up your system and/or to avoid loading of unuseful modules on system start up.

For disable the protocol you have to edit

/etc/modprobe.d/aliases

file and change two lines as follow :

#alias net-pf-10 ipv6
net-pf-10 off

You should also tell to your kernel to not load IPv6 module by blacklisting it at the boot, for doing so edit

/etc/modprobe.d/blacklist 

file adding the following line :

blacklist ipv6

Reboot your system and check with the following command if the module ipv6 is not present :

lsmod |grep ipv6

You’ve done

Hope this help

Bye
Riccardo

Print This Post Print This Post

This is a VERY CLEAR reference from Massimo Re Ferrè (not so strange ….) about Storage Configuration in a VMware Site Recovery Manager Installation.

You could find it here.

Thank you Massimo for the great job

Bye

Riccardo

The following is a list of MySQL useful commands.

# To setup root password (first execution)
mysqladmin -u root password 'new_password'

# To login to MySQL
mysql -u root -p

# To create a database
create database dbname;

# To change database
use dbname;

# To create a user and assign to it permission to database
# Grant permission only from localhost connections
GRANT ALL PRIVILEGES ON *.* TO 'username'@'localhost' IDENTIFIED BY 'some_pass' WITH GRANT OPTION;

# Grant permission on all connections
GRANT ALL PRIVILEGES ON *.* TO 'username'@'%' IDENTIFIED BY 'some_pass' WITH GRANT OPTION;

# Manage MySQL export
# Copy all db1 content to /backup-db/db1 folder
mysqlhotcopy db1 /backup-db/db1

# Create a DB dump to a file
mysqldump db1 > db1_dump_db.sql -u root -p

Hope this help

Bye
Riccardo

Print This Post Print This Post

Ok, it wuold not be a so important news, but it’s been long time since I said that I need an USB hub that would let you switch each port on or off.

This could save energy, avoid peripherals to be wakened up whenever your computer starts or  simply because you won’t be needing one USB peripheral

Buffalo seems to have donevery good job, with what look to be decent switches and an external power supply in case you need to connect devices that need the full 500 mW of power that an USB connection can supply.

Buffalo USB Hub

Buffalo USB Hub

Bye

Riccardo

This pot will show some useful example on how to use the “grep” command to find an occurency in a Linux system.
Grep searches the input file (or files) for lines containing a match to a given pattern. Whe an occurency math it copies to standard input the line with the occurrency or you should rediret the output whatever you want.

You should simpy invoke grep with the following :

grep 'STRING' filename

The above is a very simple use f grep, infact it check only in a single file searching all the occurency for ‘STRING’.
You should also use it to find ‘STRING1 STRING2′ in all files in your current location, running ::

grep 'STRING1 STRING2' *

or if you want to make the same research on a given path (i.e. all files in /etc) you should use :

grep 'STRING1 STRING2' /etc/*

Notice the use of single quotes; This are not essential but in this example it was required since the name contains a space. Double quotes could also have been used in this example.

In case of too much occurency you should redirect the output o a file to make more comfortable the research, for example using :

grep 'STRING 1 STRING2" /etc/* > /tmp/grepresults.txt

The following is a simple list for Grep Regular Expression

grep can search for complicated pattern to find what you need using some special characters used to create a regular expression:

`.’ The period `.’ matches any single character.

`?’ The preceding item is optional and will be matched at most once.

`*’ The preceding item will be matched zero or more times.

`+’ The preceding item will be matched one or more times.

for example, a regular expression search would be :

grep "\<[A-Za-z].*" file

The search above will search for any word which begins with a letter upper or lower case.

For more details check :

man grep

Hope this help

Bye
Riccardo

Print This Post Print This Post

Very often it happens that I must give support to a colleague or a customer on a Linux machine.

It’s very difficult to spell all bash command I will use to check which could be the problem, especially by phone.

When I discover “screen” it was a revelation.

With screen http://www.gnu.org/software/screen/screen.html you should share a linux session with other people.

You should use screen by simply ask to the user you want to assist to type on the console the following command :

screen

So if you can connect to the machine (even with ssh) you should run the following command :

screen -x

to share the same bash session.

Hope this help

Bye

Riccardo

Print This Post Print This Post

Taken from Duncan Epping – Yellow Bricks Blog

this is the complete list of  VMware HA Advanced Options that you should use configuring a VMware Cluster :

  • das.failuredetectiontime – Amount of milliseconds, timeout time for isolation response action(with a default of 15000 milliseconds).
  • das.isolationaddress[x] – IP adres the ESX hosts uses for it’s heartbeat, where [x] = 1‐10. It will use the default gateway by default.
  • das.usedefaultisolationaddress – Value can be true or false and needs to be set in case the default gateway, which is the default isolation address shouldn’t be used for this purpose.
  • das.poweroffonisolation – Values are False or True, this is for setting the isolation response. Default a VM will be powered off.
  • das.vmMemoryMinMB – Higher values will reserve more space for failovers.
  • das.vmCpuMinMHz - Higher values will reserve more space for failovers.
  • das.defaultfailoverhost - Value is a hostname, this host will be the primary failover host.
  • das.failuredetectioninterval – Changes the heartbeat interval among HA hosts. By default, this occurs every second (1000 milliseconds).
  • das.allowVmotionNetworks – Allows a NIC that is used for VMotion networks to be considered for VMware HA usage. This permits a host to have only one NIC configured for management and VMotion combined.
  • das.allowNetwork[x] – Enables the use of port group names to control the networks used for VMware HA, where [x] = 0 – ?. You can set the value to be ʺService Console 2ʺ or ʺManagement Networkʺ to use (only) the networks associated with those port group names in the networking configuration.
  • das.isolationShutdownTimeout – Shutdown time out for the isolation response “Shutdown VM”, default is 300 seconds. In other words, if a VM isn’t shutdown clean when isolation response occured it’s being powered off after 300 seconds.
  • das.bypassNetCompatCheck – Disable the “compatible network” check for HA that was introduced with Update 2. Default value is “false”, setting it to “true” disables the check.
  • das.ignoreRedundantNetWarning – Remove the error icon/message from your vCenter when you don’t have a redundant Service Console. Default valie is “false”, setting it to “true” will disable the warning.
  • das.maxvmrestartcount – The maximum amount of retries to start a VM, where <x> 1..(reasonable number), 0 for no restarts, -1 for indefinite. The default is 5.
  • Virtual Machine Monitoring HA advanced options

  • das.failureInterval = The polling interval for failures. Default value is 30.
  • das.maxFailureWindows = Minimum amount of seconds between failure. Default value is 3600 seconds, if VM fails within 3600 seconds VM HA doesn’t restart the machine.
  • das.maxFailures = Maximum amount of VM failures, if the amount is reached VM HA doesn’t restart the machine automatically. Default value is 3.
  • das.minUptime = The minimum uptime in seconds before VM HA starts polling. The default value is 120 seconds.

Hope this help

Bye
Riccardo

Print This Post Print This Post

Since this blog creation, early last year, I have published 99 posts — this post is number 100.

If you are a newer reader, the following are the top three posts of all time:

I’d like to take this opportunity to thank all the subscribers and readers.

Riccardo

This should be an example on how to configure a simple HA (High Availability) without VMware Virtual Center in a two hosts configuration. It requires shared storage between the two hosts, and it works great letting save you a lot of money. Obviously it not provide all Virtual Center features, but it works great. When I have some time to waste, I will add also email notification capabilities. The script will check the “other hosts” with some ICMP packet, and if the host don’t answer for 14 times, it will register all the other host’s VMs and power it on automatically, then wait for 16 seconds and execute all tasks again for paranoid sysadmin. I’ll schedule the job execution every minutes, so it will run twice every minute. I think the script is just pretty commented, but if you have any questions, feel free to ask. The only thing you should do will be export in a file all the VMs registered on the two hosts, and put it on both hosts, for doing this you should simply run :

vmware-cmd -l

and copy and paste the output on a text file, or if you are a script addicted, you should execute on the first host :

vmware-cmd -l | sed 's/\ /\\ /g' > /root/esx01

and on the second host :

vmware-cmd -l | sed 's/\ /\\ /g' > /root/esx02

then you should copy the VMs list between the host, using for example scp, with the following syntax :

usage: scp [-pqrvBC1246] [-F config] [-S program] [-P port] [-c cipher] [-i identity] [-l limit] [-o option] [[user@]host1:]file1 [...] [[user@]host2:]file2

And finally here’s the script :

#!/bin/bash
#
# Manual VMware HA script for two host configuration
# You should keep updated the /root/esx0X file on both hosts if you add or remove VMs
#
# Script created by Riccardo Riva
# Script created 2009/06/29
#
# ESX01 – 10.10.10.11 (VMs list on /root/esx01 on both hosts)
# ESX02 – 10.10.10.12 (VMs list on /root/esx02 on both hosts)
#
# Schedule this script to be executed every minutes by executing ‘crontab -e’ and add the following
# * * * * * /somewhere/this_script.sh
#
# Remeber to assign executable permissions to this script by running ‘chmod +x this_script.sh’

# Modify only the following variables according to your installation

HOSTtoCHECK=10.10.10.11
HOSTtoCHECK_VMs=/root/esx01

# Do not change nothing below this line

if ! ping -c 14 $HOSTtoCHECK > /dev/null; then
while read line
do
vmware-cmd -s register “${line}” && vmware-cmd “${line}” start ;
done < $HOSTtoCHECK_VMs
fi

sleep 16

if ! ping -c 14 $HOSTtoCHECK > /dev/null; then
while read line
do
vmware-cmd -s register “${line}” && vmware-cmd “${line}” start ;
done < $HOSTtoCHECK_VMs
fi

Hope this help

Bye
Riccardo

Print This Post Print This Post

The following is a simple script to monitor a Software Raid configuration on a Linux System.
It execute a /proc/mdstat check to search a ‘blocks_’ occurency which indicates problems on the Raid system and in case of match it notify the system administrator with a mail message.

It should be very useful for non-presidiated system, even if I always prefer Hardware Raid.


#!/bin/bash
#
# Script created by Riccardo Riva
# http://www.riccardoriva.com
#
# It check a Software Raid subsystem and notify by mail any occurency problem

# Define variable
LOG_FILE=/tmp/raid-check.log
SYSTEM=`uname --nodename`
MAILTO='systemadmin@mail.exp'

# Checking /proc/mdstat
cat /proc/mdstat | grep 'blocks.*_' > $LOG_FILE

# Define function in case of problems detected
if [ $? -eq 0 ]
then
echo "The $SYSTEM system has RAID failures on it." >> $LOG_FILE
echo "Below is the output from /proc/mdstat" >> $LOG_FILE
echo "===========================================" >> $LOG_FILE
cat /proc/mdstat >> $LOG_FILE
echo "===========================================" >> $LOG_FILE
cat $LOG_FILE | mail -s 'URGENT: RAID disk failure detected' $MAILTO
fi

# Deleting log file
rm -f >> $LOG_FILE

# Exit
exit 0

Save the file above as /usr/local/bin/raidcheck.sh  and assign to it correct permission and ownership with the folowing :

chmod 700 /usr/local/bin/raidcheck.sh
chown root:nobody /usr/local/bin/raidcheck.sh

Change the email address variable with a real email address who will receive the notification.

You should now schedule the script execution at every time interval you want (i.e. twice a day, or hourly if you are paranoic).

Remember that is better to be paranoic that have a degraded system with unrecoverable data.

Hope this help

Bye
Riccardo

Print This Post Print This Post

Hi all, the following will be a quick and dirt list of commands for use “dd” in a linux system for various task.

First of all you should create an Hard Disk Image, for example if you want to create an image of your /dev/sda device, you should have another disk (with a writable partition) (i.e. /dev/sdb) with a directory (i.e. /home mounted on it) and simply type :

dd if=/dev/sda of=/home/sda.bin

Or even a partition backup using the same disk device for source and destination like the following (if for example you have /home mounted on /dev/sda2) :

dd if=/dev/sda1 of=/home/sda1.bin

You should even create a compress image of the same disk above, using GZIP, simply type the following :

dd if=/dev/sda1 | gzip > /home/sda1.bin.gz

One of the most useful use of dd (it’s saved my life a lot of time) will be :

dd if=/dev/sda of=sda.boot.mbr bs=512 count=1

With the above command, you have backuped up your MBR (Master Boot Record) of your /dev/sda device and in case of disaster you should restore it, for example booting with a live CD using the following :

dd if=sda.boot.mbr of=/dev/sda bs=512 count=1

You should also create a manual RAID1 between two disk by executing the followinf script with a cron job :


#!/bin/sh
#

LOG="/var/log/mirror.log"
ADMIN="yourmail@yourprovider.ext"
ERROR=0

echo `/bin/date` >$LOG 2>&1
/bin/dd if=/dev/sda of=/dev/sdb bs=1M >>$LOG 2>&1
ERROR=$?
echo `/bin/date` >>$LOG 2>&1

if [ $ERROR -ne 0 ]; then
cat $LOG | /bin/mail -s "Report mirror `uname -n`" $ADMIN
fi

The above sript will copy the entire /dev/sda to /dev/sdb logging the process and send an email to your email address at the end for debug and monitoring purpose.
If the first hard disk (/dev/sda) fail, you should phisicaly umount it, and subsitute it with /dev/sdb then reboot the system.

Hope this help

Bye
Riccardo

Print This Post Print This Post

This simple post will show how to configure Ethernet Bonding on two (or more) network interfaces on RHEL 5 or CentOS 5.
I’ve tested this configuration on a CentOS 5.2 with kernel 2.6.18-92.1.22.el5 as you could see below :

uname -a

Linux serverlab.riccardoriva.local 2.6.18-92.1.22.el5 #1 SMP Tue Dec 16 11:57:43 EST 2008 x86_64 x86_64 x86_64 GNU/Linux

cat /etc/redhat-release
CentOS release 5.2 (Final)

If you want to create a bonding on two interface (i.e. eth0 and eth1) you should do the following :

Edit /etc/sysconfig/network-scripts/ifcfg-eth0

# Bonding eth0 to bond0
DEVICE=eth0
BOOTPROTO=none
ONBOOT=yes
MASTER=bond0
SLAVE=yes
USERCTL=NO

Edit /etc/sysconfig/network-scripts/ifcfg-eth1

# Bonding eth1 to bond0
BOOTPROTO=none
ONBOOT=yes
MASTER=bond0
SLAVE=yes
USERCTL=NO

Copy /etc/sysconfig/network-scripts/ifcfg-eth1 to /etc/sysconfig/network-scripts/ifcfg-bond0 to keep the same file permission by executing the following commands :

cd /etc/sysconfig/network-scripts
copy ifcfg-eth1 ifcfg-bond0

Edit /etc/sysconfig/network-scripts/ifcfg-bond0

ifcfg-bond0
DEVICE=bond0
BOOTPROTO=none
ONBOOT=yes
NETWORK=10.100.100.0
NETMASK=255.255.255.0
IPADDR=10.100.100.1
USERCTL=NO

Edit /etc/modprobe.conf adding the following line :

alias bond0 bonding

Reboot your system to let modules be loaded or load it manually with the following command :

insmod bond0 bonding

If you haven’t rebooted your system, restart your network with the following command :

/etc/init.d/network restart

You should check if bonding is working you should look at /proc/net/bonding/bond0 with the following command :

cat /proc/net/bonding/bond0

and you should see something similar to the following :

Ethernet Channel Bonding Driver: v3.2.4 (January 28, 2008)

Bonding Mode: load balancing (round-robin)
MII Status: up
MII Polling Interval (ms): 0
Up Delay (ms): 0
Down Delay (ms): 0

Slave Interface: eth0
MII Status: up
Link Failure Count: 0
Permanent HW addr: 00:15:17:88:5a:3c

Slave Interface: eth1
MII Status: up
Link Failure Count: 0
Permanent HW addr: 00:15:17:88:5a:3d

You’ve done

Hope this help

Bye
Riccardo

Print This Post Print This Post

I’m using this script in a lot of Linux Server, especially some file server with a little ERP software written in COBOL with all files in /home/erp.
I’m saving all /home and /etc to have a full backup for disaster recovery purpose.

This scrit will do the following :

- Define variables
- Define DATE
- Create a compress archive of /home and /etc
- Rewind the TAPE
- Write all the data on TAPE
- Verify the TAPE
- Eject the TAPE

Obviously all the output of the above operations will be redirected to a log file fr diagnostic purpose.

- Mail all logged operations to the Server admin

The only prerequisites for let all works is “mail” packages installed on your system and a local mail server configured for routing mail to your “Server Admin” email address, I’m using Postfix, but you coul’d use whatever you want (eg. QMail or EXIM).
Read the rest of this entry »

In some situation you may want to avoid loading a Linux driver module automatically . For example:

- In some cases buggy driver causes kernel BUG or system fault on load so you just want to avoid the problem.

- If your system connected without a diskette / floppy drive; kernel will try to load floppy driver – disable floppy driver or module.

The Linux kernel get module information on boot from /etc/modprobe.conf file and /etc/modprobe.d/* file(s).

If you are using RHEL or CentOS do the following :

open your /etc/modprobe.conf file and turn of auto loading using following syntax:

alias driver-name off

If you are using Debian or Ubuntu do the following :

open /etc/modprobe.d/blacklist file and add driver name using following syntax:

blacklist driver-name

Reboot your system and use lsmod command to show the status of modules in the Linux Kernel.

Hope this help

Bye
Riccardo

Print This Post Print This Post

This simple init script is for daemonize freshclam (Clamd Antivirus Updater) on RHEL or CentOS.

Create a brand new file called freshclam in /etc/init.d/ with the following content :


#!/bin/sh
#
# Startup script for the Clam AntiVirus Update Tool
#
# chkconfig: 2345 62 38
# description: freshclam is an update daemon for Clam AV database.
#
# processname: freshclam
# config: /etc/freshclam.conf
# pidfile: /var/run/clamav/freshclam.pid
#
# Author: Riccardo Riva
# WebSite: http://www.riccardoriva.com
#
# This script is realeased under the terms of the GPL.
#====================================================================

# Source function library
. /etc/init.d/functions

# Get network config
. /etc/sysconfig/network

test -f /etc/freshclam.conf || exit 0

RETVAL=0

start() {
echo -n $"Starting freshclam: "
daemon /usr/bin/freshclam -d -p /var/run/clamav/freshclam.pid
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/freshclam
return $RETVAL
}

stop() {
echo -n $"Stopping freshclam: "
killproc freshclam
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -f /var/run/clamav/freshclam.pid /var/lock/subsys/freshclam
return $RETVAL
}

restart() {
stop
start
}

reload() {
echo -n $"Reloading DB: "
killproc freshclam -ALRM
RETVAL=$?
echo
return $RETVAL
}

case "$1" in
start)
start
;;
stop)
stop
;;
status)
status freshclam
;;
restart)
restart
;;
condrestart)
[ -f /var/lock/subsys/freshclam ] && restart || :
;;
reload)
reload
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|reload}"
exit 1
esac

exit $?

Assign to it corect ownership and permission :

chown root:root /etc/init.d/freshclam
chmod 755 /etc/init.d/freshclam

Test if the scripts works correctly on your system with the following commands :

service freshclam start
service freshclam stop
service freshclam restart
service freshclam reload
service freshclam condstart

If all works fine you should add freshclam to the automatic startup services with the following command :

chkconfig freshclam on

Hope this help
Bye
Riccardo

Print This Post Print This Post

The following is a quick and dirt list of Linux command to do some useful operation.

# To check disk space usage on some/dir

du -h --max-depth=1 /some/dir

# To check all open ports on a Linux system

netstat -puntal

# To create a random password

ps aux | md5sum | cut -c1-8

# To process a text file as argument for a command

while read line
do
echo "${line}";
done < textfile.txt

# To login to cyrus to administer mailboxes

cyradm --user=cyrus --auth=login localhost

# To reconstruct a Cyrus Imap Mailboxes

su - cyrus
/usr/lib/cyrus/bin/reconstruct -rfx "user.mailbox"

# To manage CPAN modules
# To start the installation of the needed perl modules from CPAN type the following on your shell:

perl -MCPAN -e shell

# If you haven’t configured the Perl CPAN installation before, you’ll have to go through the initially setup and evt. install the following:

cpan> install CPAN
cpan> install LWP

# After that we can start installing the needed packages:

cpan> install Archive::Tar
cpan> install Archive::Zip

# To manage mail redirections with SIEVE script

if header :contains "Subject" "****SPAM****" {
fileinto "INBOX/SPAM";
}
if header :contains "X-Spam-Flag" "YES" {
fileinto "INBOX/SPAM";
}

Hope this help

Bye
Riccardo

Print This Post Print This Post
Download video of Richard Stallman in 2009  FLISOL – here
The video lasts 28 minutes and this format ogv (free technology for video compression)

stallman

Bye
Riccardo

This post will show a simple perl tool to manage (delete) one or more message in Postfix mail queue.

The main script to use is delete-mailq.pl
Create a file called delete-mailq.pl in /usr/local/bin with the the following content :

</pre>
#!/usr/bin/perl -w
# Postfix mailq cleanup utility

$REGEXP = shift || die "no email-adress given (regexp-style, test.*\@example.com)!";

@data = qx</usr/sbin/postqueue -p>;
for (@data) {
if (/^(\w+)\*?\s/) {
$queue_id = $1;
}
if($queue_id) {
if (/$REGEXP/i) {
$Q{$queue_id} = 1;
$queue_id = "";
}
}
}

open(POSTSUPER,"|postsuper -d -") || die "couldn't open postsuper" ;

foreach (keys %Q) {
print POSTSUPER "$_\n";
};
close(POSTSUPER);
<pre>

Assign it correct ownership and permission with the following commands :

</pre>
chown root:root /usr/local/bin/delete-mailq.pl
chmod 700 /usr/local/bin/delete-mailq.pl
<pre>

You should run the file directly passing the variables directly on comand line, or you should (and I prefer) create another file in /usr/local/bin called clean-mailq.sh with the following content :

</pre>
#!/bin/sh

if [ -z $1 ]
then
echo "Insert the E-Mail address or a string to find it in mailqueue and delete it"
read STRING
else
STRING=$1
fi

/usr/local/bin/delete_mailq.pl $STRING
<pre>

Assign it correct ownership and permission with the following commands :

</pre>
chown root:root /usr/local/bin/clean-mailq.sh
chmod 700 /usr/local/bin/clean-mailq.sh
<pre>

At this time, you should execute /usr/local/bin called clean-mailq.sh as root and pass the value to find and to delete from mail queue.

Hope this help

Bye
Riccardo

The following wuold be a simpe example to define a function in a bash shell script.
You should use it to execute the same set of command more time in a single shell script simply calling the function name and avoiding to type it all the time.

The following is a very simple example :

</pre>
#!/bin/sh

# Start define function "function01"

# Function name
function01 ()
# Function content
{
# Put the content here
}
# Stop define function

# insert whatever you want here

# call function
function01

# insert whatever you want here

# call function
function01
<pre>

Hope this help

Bye
Riccardo

Print This Post Print This Post
Contacts
Look at me at Linkedin Follow me on Twitter
My Flickr Albums My Facebook profile My YouTube Videos
SkypeMe My Linux Counter GMail me
Search
Google Search
Categories
Tag Cloud 3D
FeedBurner RSS

Visitors
Locations of visitors to this page
VMware related Blogs
The following are Blog sites with feeds I personally follow. When I'll have some spare time I will complete all Feed and Twitter links.