Skip to content

Instantly share code, notes, and snippets.

View fduran's full-sized avatar

Fernando Duran fduran

View GitHub Profile
@fduran
fduran / gist:1870527
Last active November 29, 2022 17:07
Linux making disk space
# www.fduran.com
# disk space usage
df -h
# biggest (10) directories in size (MB)
du -mxS / | sort -n | tail -10
# clean package cache
apt-get clean
@fduran
fduran / gist:1870522
Created February 20, 2012 18:29
Mysql status, check & repair
# www.fduran.com
# mysql status summary
mysqladmin -u root -pthepasswd process status
# check database mydb
/etc/init.d/mysqld stop; cd /var/lib/mysql; myisamchk --silent --force mydb/*.MYI
# repair mydb
/etc/init.d/mysqld start; mysqlcheck -u root -pthepassed --auto-repair --check --optimize --databases mydb
@fduran
fduran / gist:1870519
Created February 20, 2012 18:29
Linux: Block IP with iptables
# www.fduran.com
# Block an external attacker's IP address (1.2.3.4) with netfilter (iptables)
/sbin/iptables --append INPUT --source 1.2.3.4 -j DROP
@fduran
fduran / gist:1870515
Created February 20, 2012 18:28
Replace relative to absolute URL in a file
# www.fduran.com
# replace in a file (index.php for example) links from relative <a href="/path to absolute <a href="http://example.com/
sed -i 's/href=\"\//href=\"http:\/\/example.com\//g' index.php
@fduran
fduran / gist:1870512
Created February 20, 2012 18:27
Set permissions for web files & directories
# www.fduran.com
# default permissions for web files and directories
cd web_directory
find . -type d -exec chmod 775 {} \;
find . -type f -exec chmod 664 {} \;
@fduran
fduran / gist:1870507
Created February 20, 2012 18:27
Apache find IPs with most connections
# www.fduran.com
# Number of top 10 current TCP connections per IP
netstat -tan| grep -v 'LISTEN'| awk '{print $5}'| grep -v 'and' |grep -v 'Address' |cut -d':' -f1 |sort -n | uniq -c | sort -rn | head -n10
# Top 10 IPs in Apache log files
cd /var/log/apache2; for i in ./access.log*; do echo $i; cat $i | awk '{print $1}'| sort -n | uniq -c | sort -rn | head -n10; done
@fduran
fduran / gist:1870502
Created February 20, 2012 18:26
Linux monitor & react to event in log file
# Linux. Act upon an event in a log file
# www.fduran.com
apt-get upgrade; apt-get install inotify-tools
# create file myalert.sh:
# example finding Exception in tomcat log and sending email
#!/bin/bash
while inotifywait -e modify /path/to/file.log; do
@fduran
fduran / gist:1870498
Created February 20, 2012 18:25
Defending against Spam using Linux Postfix
Defending against Spam using Linux Postfix
www.fduran.com
0) Consider outsourcing mail service
1) Spamassassin: good in its time, it's past its useful life since there are better options and it's a CPU hog.
2) Use black list servers, like Spamhaus and Spamcop:
In Posfix configuration file /etc/postfix/main.cf append:
@fduran
fduran / gist:1870492
Created February 20, 2012 18:24
Apache optimization with Google's mod_pagespeed
# apache optimization with Google's mod_pagespeed
# www.fduran.com
# Page for mod_pagespeed : http://code.google.com/speed/page-speed/docs/using_mod.html
# Download from http://code.google.com/speed/page-speed/download.html :
cd /usr/local/src
wget https://dl-ssl.google.com/dl/linux/direct/mod-pagespeed-beta_current_i386.deb
apt-get -f install
dpkg -i mod-pagespeed-*.deb
#
@fduran
fduran / gist:1870485
Created February 20, 2012 18:24
Linux mail server for sending only
# Postfix mail server for sending messages only, not exposed to receive email
# www.fduran.com
mv /etc/postfix/main.cf /etc/postfix/main.cf.orig
echo "inet_interfaces = 127.0.0.1" > /etc/postfix/main.cf
/etc/init.d/postfix restart