Showing posts with label Plesk. Show all posts
Showing posts with label Plesk. Show all posts

Sunday, May 26, 2013

Lowering TTLs on DNS records managed by Plesk

I heartily do NOT recommend using single-server DNS solutions such as Plesk's DNS.  

That said... sometimes when it's already in use, you might want to lower all of the TTLs on the records, in batch.  ...maybe as the first step in helping migrate all of those domains over to another DNS? :-)

You can set the TTL value to any value using this command:

mysql –uadmin p`cat /etc/psa/.psa.shadow` psa –e 'update misc set val = '300' where param = 'SOA_TTL';'

You will then need to run this command to force Plesk to reread the zones files:

mysql -Ns -uadmin -p`cat /etc/psa/.psa.shadow` -D psa -e 'select name from domains' | awk '{print "/usr/local/psa/admin/sbin/dnsmng update " $1 }' | sh

The above shows a cool technique - use awk to construct commandlines that include output from a mysql select... then feed the output to shell.

For Plesk servers - which IPs are tearing up the server?

Plesk servers put all of the apache websites in /var/www/vhosts/websitename

Inside of those websitename directories there are directories for the website content (httpdocs) for the configuration files (conf) and for the error logs and access logs (statistics/logs)

So, whereas a "netstat" based check looks only at the CURRENT connections to the server, the following looks at the situation HISTORICALLY.

The following reports IP addresses that have made over 1000 requests today or yesterday.

cd /var/www/vhosts/; awk '{c[$1]++} END {for (i in c) {print c[i] " " i}}' */statistics/logs/access_log{,.processed} |sort -n|egrep [0-9]{4}

That returns counts of the number of hits by the worst offenders.

Who are they?  To find out, copy/paste the output of the above command as input into the following command, then hit "control-D".

for i in `awk '{print $2}'`; do echo "------------------ " $i " ---------------------"; whois $i|egrep -i netname\|orgname\|descr; done