Thursday, June 28, 2012

How to kill thousands of rogue process in linux by single command

In my case there was a dstat process which was scheduled by cron went viral and due to this the system start throwing the error as


Jun 28 09:49:01 machine kernel: VFS: file-max limit 10000 reached
Jun 28 09:49:01 machine kernel: VFS: file-max limit 10000 reached
Jun 28 09:50:01 machine  kernel: VFS: file-max limit 10000 reached
Jun 28 09:50:01 machine  kernel: VFS: file-max limit 10000 reached

By login as root and running the below command you can get the no if times it run with PID.
now it will be very time consuming if you kill each pid one by one.
better approach

# ps -ef | grep dstat | grep -v grep | awk '{print $2}'

then pass the command to the kill -9  and it will kill all the PID related to this process.
# kill -9 `ps -ef | grep dstat | grep -v grep | awk '{print $2}'`

 

Friday, June 22, 2012

Disk I/O monitoring on linux (iostat/sar)


# iostat -dkx 30
 
On every Linux box the following should be graphed at 5 minute averages
  • %util: When this figure is consistently approaching above 80% you will need to take any of the following actions -
    • increasing RAM so dependence on disk reduces
    • increasing RAID controller cache so disk dependence decreases
    • increasing number of disks so disk throughput increases (more spindles working parallely)
    • horizontal partitioning
  • (await-svctim)/await*100: The percentage of time that IO operations spent waiting in queue in comparison to actually being serviced. If this figure goes above 50% then each IO request is spending more time waiting in queue than being processed. If this ratio skews heavily upwards (in the >75% range) you know that your disk subsystem is not being able to keep up with the IO requests and most IO requests are spending a lot of time waiting in queue. In this scenario you will again need to take any of the actions above
  • %iowait: This number shows the % of time the CPU is wasting in waiting for IO. A part of this number can result from network IO, which can be avoided by using an Async IO library.

Wednesday, June 20, 2012

Install PHP-Mcrypt on CentOS 6.2


# rpm -ivh http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-7.noarch.rpm
#yum install php-mcrypt

Restart httpd
#service httpd restart

Monday, June 18, 2012

Monitor CPU Temperature on Linux (CentOS/RHEL)


lm_sensor is a tool that can monitor linux hardware - works great with 2.6 + kernel onwards
install
#yum install lm_sensors

Configure
#sensors-detect

Press YES to all prompt 

Output depend on your type of MB
=====================

Now follows a summary of the probes I have just done.
Just press ENTER to continue:

Driver `w83627ehf':
  * ISA bus, address 0xa10
    Chip `Winbond W83627DHG-P Super IO Sensors' (confidence: 9)

Driver `sbs':
  * Bus `i915 gmbus reserved'
    Busdriver `drm', I2C address 0x0b
    Chip `Smart Battery' (confidence: 5)

Do you want to overwrite /etc/sysconfig/lm_sensors? (YES/no):
Starting lm_sensors: loading module sbs w83627ehf          [  OK  ]
Unloading i2c-dev... OK
==============================

Instead of system restart - load the module (if any)by modprobe command 

#modprobe i2d-dev

you can check the modules as
# cat /etc/sysconfig/lm_sensors


Run the command to check the cpu current temperature & high/critical limit

[root@imonitor tmp]# sensors
coretemp-isa-0000
Adapter: ISA adapter
Core 0:      +23.0°C  (high = +89.0°C, crit = +105.0°C)   >> here +23 deg C is the current Temp
Core 2:      +18.0°C  (high = +89.0°C, crit = +105.0°C)

w83627dhg-isa-0a10
Adapter: ISA adapter
Vcore:       +0.90 V  (min =  +0.00 V, max =  +1.74 V)
in1:         +0.78 V  (min =  +1.27 V, max =  +0.52 V)   ALARM
AVCC:        +3.39 V  (min =  +2.98 V, max =  +3.63 V)
VCC:         +3.39 V  (min =  +2.98 V, max =  +3.63 V)
in4:         +1.30 V  (min =  +0.93 V, max =  +1.48 V)
in5:         +0.77 V  (min =  +0.06 V, max =  +0.64 V)   ALARM
in6:         +1.06 V  (min =  +0.01 V, max =  +0.03 V)   ALARM
3VSB:        +3.36 V  (min =  +2.98 V, max =  +3.63 V)
Vbat:        +3.34 V  (min =  +2.70 V, max =  +3.30 V)   ALARM
fan1:          0 RPM  (min = 112500 RPM, div = 4)  ALARM
fan2:          0 RPM  (min = 3924 RPM, div = 4)  ALARM
fan3:          0 RPM  (min = 337500 RPM, div = 4)  ALARM
fan5:          0 RPM  (min = 13775 RPM, div = 2)  ALARM
temp1:       +24.0°C  (high = -68.0°C, hyst = -123.0°C)  ALARM  sensor = diode
temp2:       +23.0°C  (high = +80.0°C, hyst = +75.0°C)  sensor = diode
temp3:      +127.0°C  (high = +80.0°C, hyst = +75.0°C)  ALARM  sensor = thermistor
cpu0_vid:   +2.050 V

if you want to see the temperature in Fahrenheit then 
#sensors -F

if you want to monitor it live then use the below command

#watch 'sensors | grep "core''


Reading


Sunday, June 17, 2012

Ftp Access to /var/www/html for website editing [CentOS/RHEL + Vsftpd]

1. Create a group for website users , say webgroup   # groupadd webgroup
2. give them proper permissions  : chown -R root:webgroup /var/www/html
3.chmod g+s  /var/www/html    {this will help if a user "x" creates a file/dir then it will be owned by him , so set a SETGID bit to the parent directory so that any new file by default have group id as webgroup}
4. chmod 770 /var/www/html
5. usermod -aG webgroup apache


How to Set VSFTPD

#yum install vsftpd
# service vsftpd start
#chkconfig vsftpd on
# netstat -a | grep ftp


Contents of vsftpd.conf
anonymous_enable=NO
local_enable=YES
write_enable=YES
local_umask=002
dirmessage_enable=YES
xferlog_enable=YES
connect_from_port_20=YES
xferlog_std_format=YES
ftpd_banner=Hello world
chroot_local_user=YES
chroot_list_enable=YES
chroot_list_file=/etc/vsftpd.chroot_list
pam_service_name=vsftpd
userlist_enable=YES
listen=YES
tcp_wrappers=YES


Contents of vsftpd.chroot_list

webftpuser


contents of : cat /etc/pam.d/vsftpd
#%PAM-1.0
auth       required     pam_listfile.so item=user sense=deny file=/etc/vsftpd.ftpusers onerr=succeed
auth       required     pam_stack.so service=system-auth
auth       required     pam_shells.so
account    required     pam_stack.so service=system-auth
session    required     pam_stack.so service=system-auth






Friday, June 15, 2012

Monitor per core CPU utilization in Linux (CentOS/RHEL)

1. Run Top  and press numeric 1 to get core wise CUP utilization
#top
1

Other tags

 Z,B       Global: 'Z' change color mappings; 'B' disable/enable bold
  l,t,m     Toggle Summaries: 'l' load avg; 't' task/cpu stats; 'm' mem info
  1,I       Toggle SMP view: '1' single/separate states; 'I' Irix/Solaris mode

  f,o     . Fields/Columns: 'f' add or remove; 'o' change display order
  F or O  . Select sort field
  <,>     . Move sort field: '<' next col left; '>' next col right
  R,H     . Toggle: 'R' normal/reverse sort; 'H' show threads
  c,i,S   . Toggle: 'c' cmd name/line; 'i' idle tasks; 'S' cumulative time
  x,y     . Toggle highlights: 'x' sort field; 'y' running tasks
  z,b     . Toggle: 'z' color/mono; 'b' bold/reverse (only if 'x' or 'y')
  u       . Show specific user only
  n or #  . Set maximum tasks displayed

  k,r       Manipulate tasks: 'k' kill; 'r' renice
  d or s    Set update interval
  W         Write configuration file
  q         Quit

2. Use Sar

#Sar -A

 

Thursday, June 14, 2012

sosreport in CentOS and RHEL >> ‘Generate debugging information for this system

# yum install sos

sosreport” will generate a compressed a bz2 file under /tmp.

# /usr/sbin/sosreport

sosreport (version 2.2)

This utility will collect some detailed  information about the
hardware and setup of your Red Hat Enterprise Linux system.
The information is collected and an archive is  packaged under
/tmp, which you can send to a support representative.
Red Hat Enterprise Linux will use this information for diagnostic purposes ONLY
and it will be considered confidential information.

This process may take a while to complete.
No changes will be made to your system.

Press ENTER to continue, or CTRL-C to quit.
 


Press Enter

Please enter your first initial and last name [sapp1-rl]: Mr Aqua
 

Please enter the case number that you are generating this report for:dummy


  Running plugins. Please wait ...

  Completed [53/53] ...
Creating compressed archive...

 

Your sosreport has been generated and saved in:
  /tmp/sosreport-MrAqua-20120614230734-28d7.tar.xz

The md5sum is: ffc2e235390412ccade7e4a1e50428d7

Please send this file to your support representative.

You have mail in /var/spool/mail/root
 


It contains linux configuration files/all startup/shutdown scripts, all kind of current system information (dmidecode, lsmod, lspci, netstat, iptables, rpm, network routes

Thursday, June 7, 2012

passwd: Authentication token manipulation error + CentOS


if you see this error then just run the "pwconv" from root prompt as shown in the example and  you will be all set.

[root@aqua ~]# passwd myuser
Changing password for user myuser.
passwd: Authentication token manipulation error
[root@aqua ~]# pwconv
[root@aqua ~]# passwd myuser
Changing password for user myuser.
New UNIX password:
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
[root@aqua ~]#