netperf

Network tool to test network bandwidth and performance
install netperf by souce code on both server and client.

server side:
start netperf
#netserver

client side:
netperf -H remote.lalife.net

screen

To open a new screen
#screen

To detach it
#screen -d

To get list of screens
#screen -list
13827.pts-4.servername

To resume it
#screen -r 13827

To sudo to a different user aaa then use screen
sudo -u aaa -s
script /dev/null
screen

Ref. http://dbadump.blogspot.com/2009/04/start-screen-after-sudo-su-to-another.html

telnet smtpserver 25

HELO smtp.lalife.net
MAIL FROM: test@localhost
RCPT TO: test@lalife.net
DATA
FROM:test@localhost
Subject: test smtp
test smtp.
.
QUIT

Another way to send mail by command line
echo “testmail” | mail -s “test” yan@yan.lalife.net

iptraf

iptraf is a tool used to monitor the network traffic

To add more ports (beyond 104)
iptraf > Enter > Configure > Additional Ports

To change log interval
iptraf > Enter > Timers > Logging interval

Add/Delete/Active/Unactive Filter
iptraf > Enter > IP

Monitor traffic statistics by port
iptraf > Enter > Statistical breakdowns…

To run iptraf background for 10 min and send data to log files
/usr/bin/iptraf -B -s eth0 -t 10

Log file is under /var/log/iptraf/ by default

vnstat — monitoring network traffic

Install vnstat
tar -zxvf vnstat-1.xx.tar.gz

Compile and install
make all
make install

Use vnstat
create new database
vnstat -u -i eth0
database is created under /var/lib/vnstat/eth0

Setup cron to collect data
copy from examples/vnstat.cron

#vnstat
#vnstat -i eth0
#vnstat -d
#vnstat -m

rx = recieved
tx = transmitted

Access https by telnet

openssl s_client -connect mysite.com:443

To retrieve a certificate

openssl s_client -connect sdms.ecp:443 2>&1 | sed -ne ‘/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p’

Useful page:

http://www.madboa.com/geek/openssl/

mysqldump

1. dump all database into backup file

mysqldump –opt  –all-databases > /tmp/databkup

(–opt includes lock table option)

2. dump several databases

mysqldump –opt –databases db1 db2 db3 > /tmp/databkup

3. dump single table

mysqldump –opt db1 table1 > /tmp/databkup

Touble shooting
Error: Access denied for user x@y to database z when using lock tables
mysqldump -u username -p database –single-transaction >dump.sql

User tar to back up db

mysql> FLUSH TABLES WITH READ LOCK;

(This will lock the db so it won’t be updated by other threads. Write threads by other process will wait till the lock is released)

#tar cvzf /var/tmp/datadump.tgz /var/lib/mysql/*

mysql> UNLOCK TABLES;

Restore data
lock tables bbb write;
mysql bbb < /data_backup/databkup
unlock tables;

requiretty

Some cron didn’t work well after move to CentOS5

New to disable requiretty

May 19 10:40:01 xxx sudo:     root : sorry, you must have a tty to run sudo ; TTY=unknown ; PWD=/www/xxx/bin ; USER=xxx ; COMMAND=/bin/sh moviepagechmod.sh
vi /etc/sudoers
#Defaults    requiretty