Wednesday, July 31, 2013

Linux CPU / Memory Utilization and other Performance

Linux CPU Load

If you want to see the CPU Load details as well CPU utilization, try following command.
# top
Press q to return on command prompt. q is for quit.

or more graphical representation
# htop
Press to return on command prompt. q is for quit.

or Install sysstat & try following command :
# mpstat
You can see CPU usage in percentage using
# sar
as well as you can use
# iostat
If you want to know who is eating cpu
# ps -eo pcpu,pid,user,args | sort -k 1 -r | head -10

Web Server Monitoring Tools

WebSite Monitoring Tools

NagiosNagios is a powerful monitoring system that enables organizations to identify and resolve IT infrastructure problems before they affect critical business processes.

WebSitePulseThe WebSitePulse Website monitoring service provides 24/7 mission-critical remote availability monitoring and performance measurement of your website from end-user perspective. With two service options, Performance website monitoring simulating repeat user and Full-page website monitoring, simulating first-time user experience, this monitoring service gives you real insight into what your end-users are experiencing with your website.

InternetSupervision : InternetSupervision.com monitors the availability, performance, and content of your website, web server and internet services from our UL approved offices with 24/7 personnel in Washington DC, Detroit, Chicago, Los Angeles, and Santiago, Chile. We also have remote check points in Gloucester, UK, and Sydney, Australia. Learn more about our services and plan pricing.

site24x7 : Keep track of the performance of multi-step web applications or business transactions. It can remotely monitor the availability and performance of business-critical web applications that involves multiple web transactions.

hosttracker : They provide Monitoring an unlimited number of resources, Distributed monitoring, Monitoring period – every 1/5/15/30/60 minutes, Possible monitoring of CGI scripts’ operation, The HEAD/POST/GET HTTP-methods support, Ability to specify parameters passed to a CGI script, Keyword presence control on a page and many more.

Pingdom : Pingdom makes it easy for user to monitor the uptime and performance of the website or server.

monitor.us : They provide Tracking website availability and performance from different locations in major countries and traffic destinations, Website uptime checks,  using HTTP, HTTPS, PING, DNS, Agentless MySQL checks, Email checks using SMTP, POP3, IMAP protocols, Public IP checks using TCP, UDP, SSH and IMCP protocols, VoIP checks using SIP protocol, Webpage content checks, Instant failure alerts via email, IM, SMS or live voice, SLA Reporting - detailed reporting with service level metrics per interval and many more.

Are my sites upIt is a free, ad-supported web server monitoring tool. Their plans will check the sites as frequently as once per minute. User get unlimited email and SMS notifications (in the US, International SMS is available) and they tell user that why was down by providing the HTML status error code, when possible. They provide an iPhone application, RSS feeds, webhooks, keyword search, premium-level support, email notifications to multiple addresses, multiple user accounts voice calls.

ObservuObservu monitors your websites from multiple locations and combines it with measurements collected on your servers. Notification by E-mail, SMS and Voice calls will allow you to respond quickly and improve your quality of service dramatically.

ServiceUptime : Free monitoring account includes one monitoring service (any port or service) checked every 30 minutes. Free account has all necessary features to keep the track of your website uptime and is limited in some advanced features and check frequency only. There is no limitations on worldwide locations so your service will be monitored from all over the world. 

Montastic : Montastic monitors the sites and alert when there is an error. They send an email when the site goes down as well as when the site goes back up. They read statuses via RSS, Mac, PC, Android widgets and API .They support for HTTP, HTTPs and any port number and HTTP authentication. They verify presence or absence of keyword on a web page Monitoring frequency up to every 5 minutes.

BasicStateIt is a free web site uptime monitor service, server and network failure alerts.  The free uptime monitoring service monitors http services. The test attempts to retrieve the home page at a fixed interval of fifteen minutes. For additional capabilities exactstate.com offers http, https, smtp, imap, pop3, ftp, ssh, telnet and custom tcp ports at intervals between 1 to 20 minutes. Email blacklist monitoring of dnsbl blacklists and rhsdnsbl blacklists is also available for both individual servers and bulk ip address netblocks. Be sure to check out the 2 for 1 bonus offer before deciding on your first purchase. 

Top web server performance tools for Linux

Top Web Server Performance /  Load / Stress Testing tools for Linux :

Apache JMETER :  The Apache JMeter™ desktop application is open source software, a 100% pure Java application designed to load test functional behavior and measure performance. It was originally designed for testing Web Applications but has since expanded to other test functions. 

Curl Loadercurl-loader (also known as "omes-nik" and "davilka") is an open-source tool written in C-language, simulating application load and application behavior of thousands and tens of thousand HTTP/HTTPS and FTP/FTPS clients, each with its own source IP-address. In contrast to other tools curl-loader is using real C-written client protocol stacks, namely, HTTP and FTP stacks of libcurl and TLS/SSL of openssl, and simulates user behavior with support for login and authentication flavors. 

LoadUILoadUI is a Open Source Load Testing solution that is free and cross-platform. With a visual, drag-and-drop interface, it allows you to create, configure and redistribute your Load Tests interactively and in real-time. In a single test environment, LoadUI provides complete test coverage and supports all the standard protocols and technologies.

httperfHttperf is a tool for measuring web server performance. It provides a flexible facility for generating various HTTP workloads and for measuring server performance. The focus of httperf is not on implementing one particular benchmark but on providing a robust, high-performance tool that facilitates the construction of both micro- and macro-level benchmarks

SiegeSiege is an http load testing and benchmarking utility. It was designed to let web developers measure their code under duress, to see how it will stand up to load on the internet. Siege supports basic authentication, cookies, HTTP and HTTPS protocols. It lets its user hit a web server with a configurable number of simulated web browsers. 

TsungTsung can be used to stress HTTP, WebDAV, SOAP, PostgreSQL, MySQL, LDAP and Jabber/XMPP servers. Tsung is a free software released under the GPLv2 license. The purpose of Tsung is to simulate users in order to test the scalability and performance of IP based client/server applications. You can use it to do load and stress testing of your servers. Many protocols have been implemented and tested, and it can be easily extended. 

GrinderThe Grinder is a JavaTM load testing framework that makes it easy to run a distributed test using many load injector machines. It is freely available under a BSD-style open-source license.

openLoadOpenWebLoad is a tool for load testing web applications. It aims to be easy to use and providing near real-time performance measurements of the application under test. This is particulary useful when you are doing optimization as you can see the impact of your changes almost immediately. 

FunkLoadFunkLoad is an open source functional and load Web tester whose main use cases are functional testing of Web projects (and thus regression testing as well), performance testing, load testing (such as volume testing or longevity testing), and stress testing.

Tuesday, July 23, 2013

userdel: user is currently logged in

userdel: user `username` is currently logged in

If you are trying to remove / delete a user 
# userdel username
and it shows following warning

userdel: user `username` is currently logged in

Now you are not able to remove the user.

Solution :

Run following command.
# pgrep -u username
In place of word username, put your username which is giving you trouble.
Now kill the instances using
# killall -u username
Now try to delete your user but you are still getting same message, check again
# pgrep -u username
You can't run delete user command successfully until you get the instances of the same user using pgrep command.
The result of pgrep command should be blank, No result.




Friday, July 12, 2013

Linux : crontab permission denied

Linux : user can't create/update crontabs
Crontab permission denied for Linux user
Allow user to create crontabs on Linux

By default the permission of file /usr/bin/crontab is
 -rwxr-xr-x 1 root root 34784 Apr 11 10:58 /usr/bin/crontab
Only root can create/update/delete crons.

If you want to allow user to create crons on Linux system, follow this.

a) If you are using CentOS, Fedora or RHEL
The permissions of crontab file should be
 -rwsr-xr-x 1 root root 34784 Apr 11 10:58 /usr/bin/crontab 
Owner and Group both should be root for the file as well as SUID bit should be set.
The ‘s’ in user field in place of ‘x’ indicates that SUID bit is set. 
To set SUID, Run following command
# chmod 4755 /usr/bin/crontab
or
# chmod u+s /usr/bin/crontab

b) If you are using Debian or ubuntu
The permissions of crontab file should be 
 -rwxr-sr-x 1 root crontab 34784 Apr 11 10:58 /usr/bin/crontab 
Owner should be root but the Group should be crontab as well as SGID bit should be set.
The ‘s’ in group in place of ‘x’ indicates that SGID bit is set.  
To make Group 'crontab', run following command.
# chgrp crontab /usr/bin/crontab
To set SGID, Run following command
# chmod 2755 /usr/bin/crontab
or
# chmod g+s /usr/bin/crontab

Filezilla - Response:530 Sorry, the maximum number of clients (n) from your host are already connected

Filezilla - Response:530 Sorry, the maximum number of clients (n) from your host are already connected

Solution 1
Open filezilla.
File -> site manager -> select your 'My Sites' entry -> transfer settings -> uncheck the check box "Limit number of simultaneous connections"

Try again.

Solution 2 -
Close all connections of same site. Do not open multiple filezilla instances for same site.

Restart filezilla.

Create mysql user for remote host log in

Log into mysql server from remote host

I am showing you a method to create mysql user for remote login.

I am going to give it all privileges so be careful. The details should not be given in wrong hands.

Create a user using following commands. Select any username and any password of your choice.
mysql> GRANT USAGE ON *.* TO 'new-username'@'%' IDENTIFIED BY 'new-password';
Now run this command. Use same username and password which you used in above command.
mysql> GRANT ALL PRIVILEGES ON *.* TO 'above-username'@'%' IDENTIFIED BY 'above-password' WITH GRANT OPTION;
Restart mysql.

Suppose my username is elex and password is linuxamination. My system's IP is 192.168.1.7. Now another user of my LAN whose IP is 192.168.1.8 wants to connect to my system's mysql server.

The other user should open it's terminal and run following command.
# mysql -h 192.168.1.7 -u elex -p'linuxamination'

Now 1.8 is  logged into my mysql server. Since user elex has full privileges so 1.8 can update/drop any database.

ERROR 1130 (HY000): Host is not allowed to connect to this MySQL server

ERROR 1130 (HY000): Host is not allowed to connect to this MySQL server

If you are trying to log into mysql server of remote host and you are getting this error, there can be several reasons that you are getting this.

1) You can not log in with blank/No password on remote host  otherwise it gives following error

ERROR 1045 (28000): Access denied for user 'username'@'hostname' (using password: NO)
Generally root account does not have password and you use blank password to log into root account but there must be a password to log into remote host mysql server.
Do not change it with no password attribute just like your localhost. It is very important that remote host must have mysql password otherwise it would be biggest security loop hole.

2) If you have created new user and you have set password for it. Now it is time to check hostname. If you are logging into mysql server of remote host, you must be using IP for it's hostname. If hostname is localhost, you can not log into the mysql server. This host name is for users of the server, it is not for remote host.

3)  If hostname is IP of the server, still you can not log into the mysql server. This host name is for users of the server, still it is not for remote host.

4) Port 3306 should be opened on remote host and if server is RHEL, Fedora, CentOS or similar one. The port should be defined in IP table rules.

Host name should be '%' as well as username and password both should be defined for the host name or you can say A user should have host name '%' to log into mysql server on remote host.

Now you can log into mysql server on remote host using IP.

Set the proper permission(create/drop database, create/drop table etc) for this user using 
privileges options.

click on the image for readable view.

In this example, username is admin101 & admin11, password is admin and hostname is %. Now anyone can log in from remote host into this mysql server using IP as a hostname and above given username & password.

Be careful about privileges. User can misuse if you are not careful enough.
# mysql -h 192.168.1.7 -u admin101 -p'admin'

where 192.168.1.7 is IP of the remote server
admin101 is username of mysql user on remote host
admin is password for this user.
There is no space between -p & '

For mysql remote login, Read this.

500 OOPS: cannot change directory:/home/username

ftp error : 500 OOPS: cannot change directory:/home/username

Solution I : 
Disable SELinux. To see, how to disable it, Click here.

Solution II :
If you do not want to disable SELinux. Follow this.
Check directory status.
$ getsebool -a | grep ftp
If ftp_home_dir is set to off, the error can be there, we need to make this attribute on using
$ setsebool -P ftp_home_dir on
Now restart vsftpd and try to reconnect again.
or
$ setsebool -P ftp_home_dir=1
Now restart vsftpd and try to reconnect again.

If you are still facing error, check the username directory inside /home directory.
The username directory should be there to log in to the ftp account.

vsftpd : 550 create directory operation failed

ftp error : 550 create directory operation failed 

Solution I : 
Disable SELinux. To see, how to disable it, Click here.

Solution  II :
If you do not want to disable SELinux. Follow this.
Run following commands.
# chcon -Rv --type user_home_dir_t /path/of/ftp/directory
OR
# chcon -t public_content_rw_t /path/of/ftp/directory # setsebool -P allow_ftpd_anon_write=1
Now restart vsftpd and try to reconnect again.

Solution  III :
If you are getting this error on ubuntu then the SELinux solution might not work for you because it is not installed by default on ubuntu.

Open vsftpd.conf and uncomment following line.

# write_enable=YES
Restart vsftpd.

Now try to connect but if you get following error

# 500 OOPS: vsftpd: refusing to run with writable root inside chroot()
Add this attribute in vsftpd.conf
# allow_writeable_chroot=YES
Restart vsftpd.

Now you should be able to create and remove directory/files using filezilla.

/usr/bin/env: php: No such file or directory

/usr/bin/env: php: No such file or directory

If you are getting this error, it means php is not installed or the file is corrupted.
Install it using
$ sudo apt-get install php5-cli
If you are still getting the error, Install all php packages using
$ sudo apt-get install php5 $ sudo apt-get install libapache2-mod-php5

Error: rpmdb open failed

YUM Error :  rpmdb open failed

To remove this error, Run these commands.

First clean up downloaded yum cache.
# yum clean all
Now remove all db files
# rm -f /var/lib/rpm/__db*
Rebuld the rpm database
# rpm --rebuilddb
Update yum
# yum update
OR
Method - II
# rm -f /var/lib/rpm/__db.[0-9][0-9]* # rpm --quiet -qa

If you get the error
rpmdb: write: 0xvendor-id, product-id: No space left on device
after running above commands. Check space in your filesystem.