Friday, January 14, 2011

Qmail commands

How to manage Qmail queue in Linux Plesk

Plesk server uses qmail as a mail server. Following are some of the qmail commands for Plesk server.

1) To check the mail queue in plesk from command line, you can use the command :

# /var/qmail/bin/qmail-qstat

messages in queue: 10

messages in queue but not yet preprocessed: 0

2) You can examine the queue with qmail-qread.

# /var/qmail/bin/qmail-qread

q1

3) From the qread command you get the message’s id . In the above example , one of the id is 524514 . Now you can find the file holding the email in/var/qmail/queue with “find “command.

# find /var/qmail/queue -iname 524514

/var/qmail/queue/remote/22/524514

/var/qmail/queue/mess/22/524514

/var/qmail/queue/info/22/524514

4) From the mail header you get the IP address.

# vi /var/qmail/queue/mess/22/524514

q2

5) If you wish to remove the emails with some patterns , you can use qmail-remove ( You can download it from http://www.linuxmagic.com/opensource/qmail/qmail-remove )

# /etc/init.d/qmail stop (Stop qmail before removing)

# /var/qmail/bin/qmail-remove -r -p “Time Passing”

(considering that “Time Passing” was the subject of the email )

The above steps can be used to track Spammers .

Do you wish to completely remove all the mails from queue? Just run the below commands.

find /var/qmail/queue/mess -type f -exec rm {} \;

find /var/qmail/queue/info -type f -exec rm {} \;

find /var/qmail/queue/local -type f -exec rm {} \;

find /var/qmail/queue/intd -type f -exec rm {} \;

find /var/qmail/queue/todo -type f -exec rm {} \;

find /var/qmail/queue/remote -type f -exec rm {} \;

Sunday, January 9, 2011

Plesk commands

List of path to various log files in Plesk
Plesk Management

Following is the list of path to different log files on a Plesk server.

Plesk Installation Logs:

/tmp/autoinstaller3.log


Plesk Upgrade Logs including other applications:

/tmp/psa-...log


Plesk Access and Error Logs:

/usr/local/psa/admin/logs/httpsd_access_log
/var/log/sw-cp-server/error_log


Plesk Migration Logs:

/usr/local/psa/PMM/logs/migration.log


WatchDog Logs on Plesk:

/usr/local/psa/var/modules/watchdog/log/monit.log


Apache Web Server Logs on Plesk:

/var/log/httpd/access_log
/var/log/httpd/error_log


Apache Suexec Logs on Plesk:

/var/log/httpd/suexec_log


Access and Error Logs of a Website (account):

/var/www/vhosts/domain.tld/statistics/logs/access_log
/var/www/vhosts/domain.tld/statistics/logs/error_log


Mysql Logs on Plesk:

/var/lib/mysql/server.hostname.err (unless defined in /etc/my.cnf)


Named (Bind) Logs on Plesk:

/var/log/messages


Mail (Qmail and Postfix) Logs on Plesk:

/usr/local/psa/var/log/maillog


Ftp Logs on Plesk:

/var/log/messages


Server Logs on Plesk:

/var/log/messages


Horde Logs:

/var/log/psa-horde/psa-horde.log


Cronjob Logs:

/var/log/cron


SSH Logs:

/var/log/secure


Mailman Logs:

/var/log/mailman/


Tomcat Logs:

/var/log/tomcat5/catalina.out

Plesk container commands

http://kmaiti.blogspot.com/2010_05_01_archive.html

Virtuzoo commands

Virtuzoo commands
[root@test /]#vzctl start/stop/restart 101 // start the VPS 101
[root@test /]#vzctl enter 101 // enter into 101 VPS
[root@101 /]#exit // log out from 101 VPS
[root@test /]#vzlist // display the list of active VPS’s
[root@test /]#vzlist -a // display the list of all VPS’s
[root@test /]#vzcalc -v 101 // show resources usage on VPS
[root@test /]#vzctl exec 101 df -m // execute commands against the VPS(in this case ‘df -m’)
[root@test /]#vzyum 101 -y install package // install package using yum on VPS
[root@test /]#vzrpm 101 -Uvh package // install package using rpm on VPS
vzstat

Monitor resources usage of VPS

Monitor resources usage of VPS
1. Monitoring System Resources Consumption :

It is possible to check the system resource control parameters statistics from within a Container. The primary use of these statistics is to understand what particular resource has limits preventing an application to start. Moreover, these statistics report the current and maximal resources consumption for the running Container. This information can be obtained from the /proc/user_beancounters file.

command #vzctl exec 101 cat /proc/user_beancounters


The failcnt column displays the number of unsuccessful attempts to allocate a particular resource. If this value increases after an application fails to start, then the corresponding resource limit is in effect lower than is needed by the application.

The held column displays the current resource usage, and the maxheld column – the maximal value of the resource consumption for the last accounting period. The meaning of the barrier and limit columns depends on the parameter and is explained in the UBC guide.

Inside a CT, the /proc/user_beancounters file displays the information on the given CT only, whereas from the Hardware Node this file displays the information on all the CTs.

Validating Container Configuration(VPS)

Validating Container Configuration(VPS)
Validating Container Configuration : -

# vzcfgvalidate /etc/vz/conf/101.conf

The utility checks constraints on the resource management parameters and displays all the constraint violations found. There can be three levels of violation severity:
Recommendation >> This is a suggestion, which is not critical for Container or Hardware Node operations. The configuration is valid in general; however, if the system has enough memory, it is better to increase the settings as advised.
----------
Warning >>A constraint is not satisfied, and the configuration is invalid. The Container applications may not have optimal performance or may fail in an ungraceful way.
----------
Error >> An important constraint is not satisfied, and the configuration is invalid. The Container applications have increased chances to fail unexpectedly, to be terminated, or to hang.
----------

How to migrate VPS container to another virtuozoo node?

How to migrate VPS container to another virtuozoo node?
Guys,

I referred the following steps :

I executed following command from the old node :

====
[root@old_node ~]# vzmigrate IP_of_new_node 213:100
====

213 : CTID which will be moved to new node
100 : CTID which will be created on new node

It'll ask for the password of new node.

Here is the results :

======
[root@old_node~]# vzmigrate new_node_ip 213:100
root@new_node's password:
Connection to destination node (new_node) is successfully established
Moving/copying CT#213 -> CT#100, [], [] ...
Checking external bind mounts
Check cluster ID
Checking keep dir for private area copy
Checking SLM-only mode
Checking technologies
Checking disk usage space
Checking templates for CT
copy ez template area directories
copy /vz/template/centos/5/x86_64
Checking caches
Checking IP addresses on destination node
Check target CT name: clonedofvzold_node
Checking RATE parameters in config
Copy private area '/vz/private/213'
done
OfflineManagement CT#213 ...
done
vzctl : Running vzquota drop failed for Container 213 [11]
Successfully completed
======

Now assign new IP address for the CT 100 on new node by going at the network settings. Then restart the CT. You can now make multiple clone of this CT.

That's it. Try :)

Recursively get files from FTP server

FTP in conjunction with wget can be used to recursively download files from the servers. Use the following command to fetch all files in the FTP account provided:
# wget -r -nH -c -l0 ftp://ftp_username:ftp_password@ftp_host.com
If needing to use a username with an ‘@’ in it, you can use %40 instead of the @ and it will go through just fine.
# wget -r -nH -c -l0 ftp://user%40domain.com:ftppass@ftp_host.com

Create swap on linux server

To create swapfile if theres no swap setup on the server (free -m will show zero swap)

1 – Create the required extra swap and make sure /home has enough free space. This will create a swapfile of 10GB.
# dd if=/dev/zero of=/home/swapfile bs=1024 count=10000000
2 – Make the swap file
# mkswap /home/swapfile
3 – Turn the swap on
# swapon /home/swapfile
4 – Verify that swap is added
# free -m
5 – Make sure this is loaded every time node is rebooted by adding the following line to /etc/rc.local
# /sbin/swapon /home/swapfile

DiskUsage Report – diskusage.sh

Here is a simple bash script that I wrote to get a notification email whenever any of the server partition grows over the defined size. The size can be defined for MAXSIZE variable. You can then setup a cron to run this script after every few hours. You will not be bombarded with the notification emails as this script will send the notification email only when a partition is over the MAXSIZE.

#Written by WebScHoLaR

#!/bin/sh
loop=`df -h | sed “1 d” | wc -l`
MAXSIZE=95;
while [ 0 -lt "$loop" ]
do

usage=`df -h |sed “1 d” |sed -n “$loop s/%//p” | awk ‘{print $5}’`

if [ $usage -ge $MAXSIZE ]; then
headerborder=”———————————————-”;
header=”$headerborder\nHostname: `hostname`\nDate: `date +”%A, %B %d”`\nServer Time: `date +”%r”`\n$headerborder\n”;
print=”`df -h |sed “1 d” |sed -n ” $loop s/\///p” | awk ‘{print $6 ” is ” $5}’`\n$print”
echo -e $header > /tmp/df.out ;
echo -e $print >> /tmp/df.out ;
fi
loop=`expr $loop – 1`
done
mail -s “Disk Usage Alert: `hostname`” email@domain.com < /tmp/df.out ;
rm -rf /tmp/df.out ;

The output of this script will be like:

————————————————————
Hostname: server.hostname.com
Date: Thursday, February 14
Server Time: 06:01:02 AM
————————————————————

/var is 98%

DOS – Script to find ip hit

I wrote this bash script to control DDOS attack. It doesn’t block the Ips automatically but will show you a list of Ips that have more connections than defined in Max variable. It will display a menu and its easy to use. The script will also log the activities in a log file so you can latter check that which Ips were blocked by it.

function display_iplist()
{
clear
netstat -anp |grep ‘tcp\|udp’ | awk ‘{print $5}’ | cut -d: -f1 | sort | uniq -c | sort -n
}

function block_ips()
{
clear
netstat -anp |grep ‘tcp\|udp’ | awk ‘{print $5}’ | cut -d: -f1 | sort | uniq -c | sort -n > badips.txt
if [ -f badips.txt ]
then
echo “! ! ! All Ips having connections greater than the number specified will be blocked on the server ! ! !”
echo -n “Enter the number — >”
read Max
echo “”
declare -a ARRAY
let “index=0″
for BAD_IP in `cat badips.txt`
do
ARRAY[$index]=$BAD_IP
let “index+=1″
done
for ((i=0; i<$index; i++))
do
rem=`expr $i % 2`
if [ $rem = 0 ]
then
if [ "${ARRAY[$i]}” -ge $Max ]
then
if [ ${ARRAY[$i+1]} != 0.0.0.0 ]
then
echo “”${ARRAY[$i+1]}” has “${ARRAY[$i]}” active connections”
echo “Executing \”iptables -A INPUT -s “${ARRAY[$i+1]}” -j DROP”\”
iptables -A INPUT -s “${ARRAY[$i+1]}” -j DROP
if [ $? -eq 0 ] #Checking that whether IP blocked successfully or not
then
echo “${ARRAY[$i+1]} has been blocked on the server”
echo “`date | awk ‘{ print $1,$3″,”,$2,$6 }’` iptables -A INPUT -s “${ARRAY[$i+1]}” -j DROP” >> blockips.log
else
echo “Unable to block ${ARRAY[$i+1]} on the server”
echo “`date | awk ‘{ print $1,$3″,”,$2,$6 }’` Unable to Block Ip ${ARRAY[$i+1]} by executing \”iptables -A INPUT -s “${ARRAY[$i+1]}” -j DROP”\” >> blockips.log
fi
echo “”
fi
else
let “i+=1″
fi
fi
done
else
echo “Error: Cant read badips.txt”
fi

}

while :
do

# clear
echo “————————————-”
echo ” Main Menu ”
echo “————————————-”
echo “[1] Display list of Ips”
echo “[2] Specify Max hits number”
echo “[3] Exit/Stop”
echo “=====================================”
echo -n “Enter your menu choice [1-3]: ”

read choice

case $choice in

1) display_iplist ;;
2) block_ips ;;
3) exit 0 ;;
*) echo “Ossps…Please select choice 1,2 or 3″ ;
echo -n “Press a key ” ; read ;;

esac
done