Returning to blogger after long time . I took lot of time , but I think I like doing it .
Sunday, May 16, 2021
Thursday, January 2, 2020
find : useful syntax not regular
Find files with permission 777 (change value as per the search), for dir use type as d
find . type f -perm 0777 -print
Find and correct the permission:
find . -type f -perm 0777 -print -exec chmod 644 {} \;
Find and remove files
find . -type f -name *.javacore -print -exec rm -f {} \;
Find empty files
find /tmp -type f -empty
Find hidden file
find /home type f -name ".*"
Find last 50 days accessed files:
find / -atime 50
Find changed files in last 1 hour:
find / -cmin -60
Find modified files in 60 min:
find / -mmin 60
Find files modified in last 50 days
find / -mtime 50
Find files accessed in last 1 hour:
find / -amin 60
Find 50MB File:
find / -size 50M
Find size 50 - 100 MB:
find / -size +50 -size -100M
Find and delete 100 MB and bigger files:
find / -size +100M -exec rm -f {} \;
Find the files greater than 1 MB and do proper listing
find /home -size +1M -exec ls -lrt {} \;
Find specific type of files and delete
find / -type f -name "*.mp3" -size +10M -exec rm {} \;
find . type f -perm 0777 -print
Find and correct the permission:
find . -type f -perm 0777 -print -exec chmod 644 {} \;
Find and remove files
find . -type f -name *.javacore -print -exec rm -f {} \;
Find empty files
find /tmp -type f -empty
Find hidden file
find /home type f -name ".*"
Find last 50 days accessed files:
find / -atime 50
Find changed files in last 1 hour:
find / -cmin -60
Find modified files in 60 min:
find / -mmin 60
Find files modified in last 50 days
find / -mtime 50
Find files accessed in last 1 hour:
find / -amin 60
Find 50MB File:
find / -size 50M
Find size 50 - 100 MB:
find / -size +50 -size -100M
Find and delete 100 MB and bigger files:
find / -size +100M -exec rm -f {} \;
Find the files greater than 1 MB and do proper listing
find /home -size +1M -exec ls -lrt {} \;
Find specific type of files and delete
find / -type f -name "*.mp3" -size +10M -exec rm {} \;
Wednesday, January 1, 2020
Linux Performance Troubleshooting
TOP Command
Command on Server è top
CPU Load Average:
Zombie Process:
%wa (imp): I/O status. Make sure this is
close to zero. Higher the number critical will be the health.
%hi: H/W interrupts for CPU happening on
server
%si: S/W interrupts for CPU happening on
server
%st: This amount of stolen CPU from server
to perform operation on shared virtual server to perform some operation.
SWAP Memory: It starts when Physical memory
is full. Then Swapping will start moving unused memory blocks to SWAP Memory.
VMSTAT
r: how many processes are waiting for CPU
time. Higher the value of r , bad the server is behaving. It means issue with
CPU
b: wait queue, higher the number of b , it
means the issue with disk .
swapd: SWAP memory stats.
free: Free physical memory
buff: before I/O operation
Cache: Mapped by Kernel
si: Swap IN, once swap is started. Disk to
Physical
so: Physical to SWAP
bi: Disk I/O, Blocks received from Disk to
RAM
bo: Disk I/O , Blocks written to Disk
in: Number of interrupts per sec
cs: Context switches, CPU move from one
process to other. Higher means issue with CPU.
IOSTAT
Command on Server à
iostat
This provides information related to CPU,
Disk
%iowait is important here
Gives details about disk read and write per
sec.
SAR
Command on Server à sar
For current and historical details. Linux Package
name - sysstat
Collective CPU usage
Memory, SWAP stats
I/O details on server
N/W stats
SAR (historical) on specific time with 10
min of range
SAR version à sar
-V
sar 1 2 à
output for every 1 sec for two times
sar -f /var/log/sa/sa10 à CPU stats of
10th (day or date) of the month .
sar -P ALL à Report
of all cpu as well as all individual cores
sar -r à
memory stats
sar -b à I/O
activity (tps à transitions per sec, breads/sec à bytes
read per sec )
sar -p -d à I/O Report
of all individual disks
sar -w à CPU content
(switch to different process)
sar -q à CPU
load avg
sar -n à
Network stats
sar -n DEV à
Enough details for N/W devices for troubleshooting
sar -f /var/log/sa/sa1 -s 00:11:00 -e
00:45:00 à Output of only with start and end time
LSOF
Command on Server à lsof
lsof +D /data à
Number of processes opened for directory /data
lsof /var/log/messages à List the files used by any process
lsof -c ssh à
Listing the files associated with process (such as sshd process)
lsof /data/ à
processes running in specific mount point
lsof -u à Any specific user
lsof -p à For any specific process
FUSER
Command on server à fuser
This displays all the files used by a
particular user
fuser -cu /data à This
will show user accessing the file-system.
fuser -ck /data à Kill
the users accessing the file-system
TCPDUMP
Command on Server à
tcpdump
tcpdump -i eth0 à It
will capture all the packets on the N/W interface until interrupted (ctrl +c).
tcpdump -c 10 -i eth0 à It will capture 10 packets
tcpdump -w .pcap -i eth0 à Write in file
tcpdump -r .pcap à Read from file
tcpdump -n -i eth0 à Output
will be more readable format
tcpdump -n -i eth0 tcp à Captures only tcp packets
tcpdump -n -i eth0 port 80 à Captures specific to port
tcpdump -i eth0 -s 0 host à This will capture packet between my server and destination server.
So basically it captures packet communication between two servers.
Top Running process by CPU and Memory
High Memory processes:
ps -eo pid,ppid,cmd,%mem,%cpu –sort=-%mem |
head
ps -eo pmem,pcpu,pidargs | tail -n +2 |
sort -rnk 1 | head
ps -eo pmem,pcpu,vsize,pid,cmd | sort -k 1
-nr | head -10
ps axo ruser,%mem,comm,pid,euser | sor -nr
| head -n 10
top -b -o +%MEM | head -n 50
-b output top in batch mode
-o for sorting process
-n number of lines (processes)
High CPU processes:
ps -eo pmem,pcpu,pidargs | tail -n +2 |
sort -rnk 2 | head
Sunday, February 14, 2010
Shell Scripting - referrence
-nt : Newer than
-ot : Older than
-gt : Greater than
-lt : Less than
-ge : Greater than or equal to
-le : less than or equal to
-eq : equal to
-ne : not equal to
check if the name "abc" is file or not
test -f abc; echo $? - if o/p is 0 then its a file else its a directory
also,
[-f abc]; echo $?
to check socket files eg mysql.sock
test -S /var/lib/mysql/mysql.sock; echo $? - if o/p is 0 then its socket file else not
To check null (zero size) files
test -s log1.log; echo $? - if o/p is 0 then its not a zero byte file.
man test - for all details
-ot : Older than
-gt : Greater than
-lt : Less than
-ge : Greater than or equal to
-le : less than or equal to
-eq : equal to
-ne : not equal to
check if the name "abc" is file or not
test -f abc; echo $? - if o/p is 0 then its a file else its a directory
also,
[-f abc]; echo $?
to check socket files eg mysql.sock
test -S /var/lib/mysql/mysql.sock; echo $? - if o/p is 0 then its socket file else not
To check null (zero size) files
test -s log1.log; echo $? - if o/p is 0 then its not a zero byte file.
man test - for all details
Thursday, January 14, 2010
MySQL - some basic command
Create new Database
create database DataBaseName;
Create User
CREATE USER 'user1'@'localhost' IDENTIFIED BY 'pass1';
Grant privileges on Datatabase
GRANT SELECT,INSERT,UPDATE,DELETE ON *.* TO 'user1'@'localhost'; - limited privileges
or
GRANT ALL ON *.* TO 'user1'@'localhost'; - All privileges
or
GRANT ALL PRIVILEGES ON * . * TO 'sunil'@'localhost' WITH GRANT OPTION MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0 ; - root level privileges
Backup Database
mysqldump -u username -p -h hostname DatabaseName > exportedfilename.sql
Restore Database from dump
mysqldump -u username -p -h hostname DatabaseName < mysqldumpfilename.sql
Find version of mysql
select version();
Change Password for user
update user set password=PASSWORD("NEW-PASSWORD-HERE") where User='user';
mysql> flush privileges;
create database DataBaseName;
Create User
CREATE USER 'user1'@'localhost' IDENTIFIED BY 'pass1';
Grant privileges on Datatabase
GRANT SELECT,INSERT,UPDATE,DELETE ON *.* TO 'user1'@'localhost'; - limited privileges
or
GRANT ALL ON *.* TO 'user1'@'localhost'; - All privileges
or
GRANT ALL PRIVILEGES ON * . * TO 'sunil'@'localhost' WITH GRANT OPTION MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0 ; - root level privileges
Backup Database
mysqldump -u username -p -h hostname DatabaseName > exportedfilename.sql
Restore Database from dump
mysqldump -u username -p -h hostname DatabaseName < mysqldumpfilename.sql
Find version of mysql
select version();
Change Password for user
update user set password=PASSWORD("NEW-PASSWORD-HERE") where User='user';
mysql> flush privileges;
Tuesday, October 27, 2009
Subscribe to:
Posts (Atom)