Check number of file descriptors opened by process
Fri, 03/25/2011 - 11:51 — sandipTo check on the file descriptors opened by process:
lsof -p {PID} | awk '$4 ~ /^[0-9]/ {print $4}' | wc -lalternately:
ls -1 /proc/{PID}/fd | wc -lTo check all file descriptors opened by a user:
lsof -u {user} | awk '$4 ~ /^[0-9]/ {print $4}' | wc -lBy default the hard and soft limits for a single process are set to 1024 on linux systems. To check on the limits:
ulimit -Hn
ulimit -SnTo increase edit the "/etc/security/limits.conf" file for corresponding user:
{user} soft nofile 4096
{user} hard nofile 4096To check if the new limits has been applied type `ulimit -n` after you get a new shell.
Logfile '/var/log/kav/5.5/kav4mailservers/avstats.log' does not exist
Mon, 03/21/2011 - 14:05 — sandipTo resolve kluser cron error on missing log file:
Logfile '/var/log/kav/5.5/kav4mai lservers/avstats.log' does not existModify kluser cron as below via `crontab -e -u kluser` appending "/bin/touch /var/log/kav/5.5/kav4mailserve
/bin/touch /var/log/kav/5.5/kav4mailserve rs/avstats.log; /opt/kav/5.5/kav4mailservers/b in/parse_avstat.pl -d -sd=/opt/kav/5.5/kav4mailserve rs/proc_avstat /var/log/kav/5.5/kav4mailserve rs/avstats.logPlesk and SPF records
Fri, 03/18/2011 - 10:56 — sandipThe Plesk DNS zone template for TXT record does not include the servers hostname by default. If the host IP is different from the domains being hosted, may want to update the default template as below:
<domain>. TXT v=spf1 +a +mx a:host.domain.tld -allBackup and restore lvm data with dd
Sun, 03/13/2011 - 01:18 — sandipRecently I've had to backup/restore data from a failing drive with LVM over Raid.
Luckily I had access to the backup of the current metadata configuration located in "/etc/lvm/backup/".
Below is what the volumegroup looked like:
vg0 {
&nbs p; id = "xvni1W-24Xu-dVoR-PlXh-gQ vQ-62fL-QX64O3"
&nbs p; seqno = 9
&nbs p; status = ["RESIZEABLE", "READ", "WRITE"]
&nbs p; flags = []
&nbs p; extent_size = 65536 & nbsp; & nbsp; # 32 Megabytes
&nbs p; max_lv = 0
&nbs p; max_pv = 0
&nbs p; physical_volumes {
&nbs p; &nbs p; &nbs p; pv0 {
&nbs p; &nbs p; &nbs p; &nbs p; id = "9gbyhX-Owvj-u4Q4-wR1E-IE f2-gyUA-CJBCJK"
&nbs p; &nbs p; &nbs p; &nbs p; device = "/dev/md3" &nbs p; # Hint only
&nbs p; &nbs p; &nbs p; &nbs p; status = ["ALLOCATABLE"]
&nbs p; &nbs p; &nbs p; &nbs p; flags = []
&nbs p; &nbs p; &nbs p; &nbs p; dev_size = 1928892288 # 919.768 Gigabytes
&nbs p; &nbs p; &nbs p; &nbs p; pe_start = 384
&nbs p; &nbs p; &nbs p; &nbs p; pe_count = 29432 & nbsp; # 919.75 Gigabytes
&nbs p; &nbs p; &nbs p; }
&nbs p; }
&nbs p; logical_volumes {
&nbs p; &nbs p; &nbs p; lv0_sites {
&nbs p; &nbs p; &nbs p; &nbs p; id = "Sg1fYr-NTzr-8AA2-v29K-tc z5-rUMj-uRoXY1"
&nbs p; &nbs p; &nbs p; &nbs p; status = ["READ", "WRITE", "VISIBLE"]
&nbs p; &nbs p; &nbs p; &nbs p; flags = []
&nbs p; &nbs p; &nbs p; &nbs p; segment_count = 1
&nbs p; &nbs p; &nbs p; &nbs p; segment1 {
&nbs p; &nbs p; &nbs p; &nbs p; &nbs p; &nbs p; start_extent = 0
&nbs p; &nbs p; &nbs p; &nbs p; &nbs p; &nbs p; extent_count = 1280 # 40 Gigabytes
&nbs p; &nbs p; &nbs p; &nbs p; &nbs p; &nbs p; type = "striped"
&nbs p; &nbs p; &nbs p; &nbs p; &nbs p; &nbs p; stripe_count = 1   ; # linear
&nbs p; &nbs p; &nbs p; &nbs p; &nbs p; &nbs p; stripes = [
&nbs p; &nbs p; &nbs p; &nbs p; &nbs p; &nbs p; &nbs p; "pv0", 0
&nbs p; &nbs p; &nbs p; &nbs p; &nbs p; &nbs p; ]
&nbs p; &nbs p; &nbs p; &nbs p; }
&nbs p; &nbs p; &nbs p; }
&nbs p; &nbs p; &nbs p; lv0_m {
&nbs p; &nbs p; &nbs p; &nbs p; id = "scNeN4-4bmg-Y6kq-zKuO-n8 B8-s8mw-FTUYqk"
&nbs p; &nbs p; &nbs p; &nbs p; status = ["READ", "WRITE", "VISIBLE"]
&nbs p; &nbs p; &nbs p; &nbs p; flags = []
&nbs p; &nbs p; &nbs p; &nbs p; segment_count = 1
&nbs p; &nbs p; &nbs p; &nbs p; segment1 {
&nbs p; &nbs p; &nbs p; &nbs p; &nbs p; &nbs p; start_extent = 0
&nbs p; &nbs p; &nbs p; &nbs p; &nbs p; &nbs p; extent_count = 12800 # 400 Gigabytes
&nbs p; &nbs p; &nbs p; &nbs p; &nbs p; &nbs p; type = "striped"
&nbs p; &nbs p; &nbs p; &nbs p; &nbs p; &nbs p; stripe_count = 1   ; # linear
&nbs p; &nbs p; &nbs p; &nbs p; &nbs p; &nbs p; stripes = [
&nbs p; &nbs p; &nbs p; &nbs p; &nbs p; &nbs p; &nbs p; "pv0", 1280
&nbs p; &nbs p; &nbs p; &nbs p; &nbs p; &nbs p; ]
&nbs p; &nbs p; &nbs p; &nbs p; }
&nbs p; &nbs p; &nbs p; }
&nbs p; }
}Now to extract data with dd, use the below formula (this will only work for linear stripe):
skip=$[extent_size*stripes+pe_ start] count=$[extent_size*(extent_co unt-1)]So to get the lv0_m data off of the volume:
dd if=/dev/sdb4 of=/opt/bak/lv0_m.iso bs=512 skip=$[65536*1280+384] count=$[65536*(12800-1)] conv=sync,noerrorOnce the iso is created, it can then be loop mounted via:
mount -o loop -t ext3 /opt/bak/lv0_m.iso /mnt/lv0_mYou should then be able to see all the files in the mount point which can then be used for data restoration.
Tracking slow running mysql queries
Fri, 03/04/2011 - 18:13 — sandipFirst enable logging of slow running queries in "mysqld" section of "my.cnf".
[mysqld]
log_slow_queries=/var/log/my sqld.slow.log
long_query_time=2Once queries get logged, you can get the top 10 queries sorted by number of occurrences in the log via:
mysqldumpslow -s c -t 10 /var/log/mysqld.slow.logDry run update with svn and cvs
Fri, 03/04/2011 - 17:04 — sandipTo test what files would get changed or conflict when running an update:
With svn:
svn merge --dry-run -r BASE:HEAD .With cvs:
cvs -nq update -dRemote backups with tar over ssh
Mon, 02/28/2011 - 15:26 — sandipBelow is example of backing up users' home directory to remote host piped via ssh:
tar -cvzf - -C /home {username} | ssh {remotehost} 'cat >/path/to/bak/{username}.tg z'check webpage load time via wget
Tue, 02/22/2011 - 17:19 — sandipHere is a simple one liner to check on download time of a webpage:
(time wget -p --no-cache --delete-after www.linuxweblog.com -q ) 2>&1 | awk '/real/ {print $2}'SSL and subversion client
Mon, 02/07/2011 - 12:03 — sandipUnlike web browsers, the CA root cert is not installed by default for svn clients. You would need to tell the client where to find it in order to trust the ssl cert.
Reference: svnbook
For GoDaddy signed certs, download their root certs available at:
http://certificates.godaddy.co
You would need both the pem encoded gd-class2-root.crt and gd_intermediate.crt .
Then in subversion client global settings, tell it the path to the certs:
ssl-authority-files = /path/to/gd-class2-root.crt;/p ath/to/gd_intermediate.crtThis should then trust the ssl cert.
Setup sudo access to mysql user
Sun, 01/30/2011 - 02:13 — sandipHere is how to give dba user sudo access as mysql user.
visudo and add:
dbauser ALL=(mysql) ALLBasically, it defines that user "dbauser" can run all commands as "mysql" user.
For the dbauser to get mysql shell, run:
$ sudo -u mysql -i