Thursday, March 28, 2013

Perl Module


Install CPAN modules into your local Perl library using CPAN
By default, you need to have admin (root) privileges to install Perl modules - see the next section if you don't.
Installation is straightforward if your machine has Internet access. It is assumed that you have the CPAN perl module installed (this is normally the case).
The make utility must be available before using Bundle::CPAN. On CentOS 6.3 minimal you must run yum install make.
Invoke the CPAN shell:
# perl -MCPAN -e shell
If you run this for the first time it asks you some configuration questions. In most cases it works just fine if you tell it to "go figure it out yourself." Once configured you will see a cpan> shell prompt.
The first thing you should do is to upgrade your CPAN:
cpan> install Bundle::CPAN
Once ready, type:
cpan> reload cpan
Now it is time to install the additional modules you need. For example, to retrieve, configure and install the DateTime::TimeZone module, type:
cpan> install DateTime::TimeZone
If needed you will be prompted to install other modules this module depends on.



Install Perl module

A) Start CPAN Shell:
# perl -MCPAN -e shell

B) Install a perl module:
   At cpan> shell prompt install module using install module::Name command.
   For example install module called MIME::Lite:

# cpan> install MIME::Lite


List installed perl module

 # instmodsh

Wednesday, March 27, 2013


Nagios- (Return code of 127 is out of bounds - plugin may be missing)

This status shows on nagios page when plugins are missing in nagios/libexec directory , it happens mostly while you install nagios with prefix and plugin install somewhere else so you have to copy plugins in your nagios libexec directory, that's it :)

Sunday, March 17, 2013


Apache MaxClients


ApacheApache web server has a configuration option called MaxClients. MaxClients determines the maximum number of concurrent connections that Apache will service.

MaxClients is not the same as maximum number of users. That is because a user generally downloads web pages and then spends time reading them and during that time Apache can service other users.
In Apache prefork MPM the MaxClients figure also determines the maximum number of Apache child processes that can be active. The more child processes that are spawned the higher the memory usage so MaxClients is an important server tuning option.
To determine what number you want to use for MaxClients you have to figure out how much RAM you can dedicate to Apache. You take your total memory figure and deduct a suitable amount for other software running on your server. So for example if you have a control panel like Cpanel or a DBMS like mysql running you will have to deduct the memory usage of those programs from your total available memory. Also deduct a suitable number for operating system overhead.
Then you try and determine how much memory a typical Apache process is using. You can use the ps command to find that out. For example in CentOS Linux:
ps -O rss -C httpd
If you are using some other distribution then replace httpd with your Apache binary name. For example apache2 on Debian.
The above command should give you a list of Apache process and their resident set size. An average of that number should give you a rough idea of how much memory an Apache child process will use.
Now you simply divide the amount of memory you can devote to Apache with the average process size to arrive at a suitable figure for Apache MaxClients.
I find that on control panel less servers a number of 75 per GB of RAM is a good starting point.

ServerLimit

ServerLimit is a related Apache configuration option. ServerLimit is the maximum value for MaxClients for the life of the Apache server. For the prefork MPM you only need to worry about ServerLimit if you want to set the MaxClients value to above 256. In that case just set MaxClients and ServerLimit to the same number.

Final thoughts

Fine tuning Apache MaxClients is more of an art than a science. Because of the way Linux reports process memory usage, and the different workloads Apache processes have to handle it isn’t possible to say with certainty how much memory a typical Apache process will use. So we can only estimate memory usage and that means we can only estimate the ideal MaxClients figure.

Apache optimization: KeepAlive On or Off?



Apache
Apache is the most widely used web server on the Internet. Knowing how to get the most out of Apache is very important for a systems administrator. Optimizing Apache is always a balancing act. It’s a case of sacrificing one resource in order to obtain savings in another.

What is KeepAlive?

HTTP is a session less protocol. A connection is made to transfer a single file and closed once the transfer is complete. This keeps things simple but it’s not very efficient.
To improve efficiency something called KeepAlive was introduced. With KeepAlive the web browser and the web server agree to reuse the same connection to transfer multiple files.

Advantages of KeepAlive

  • Improves website speed: It reduces latency associated with HTTP transfers and delivers a better user experience.
  • Reduces CPU usage: On the server side enabling KeepAlive reduces CPU usage. Consider that a typical web page has dozens of different files such as images, stylesheets, javascript files etc. If KeepAlive is disabled a separate connection must be made for each of those files. Creating and closing connections has an overhead and doing it for every single file wastes CPU time.

Disadvantages of Keepalive

  • Increases memory usage: Enabling KeepAlive  increases memory usage on the server. Apache processes have to keep connections open waiting for new requests from established connections. While they are waiting they are occupying RAM that could be used to service other clients. If you turn off KeepAlive fewer apache processes will remain active. This will lower memory usage and allow Apache to serve more users.

When should you enable KeepAlive?

Deciding whether to enable KeepAlive or not depends on a number of different factors:
  • Server resources: How much RAM vs. how much CPU power you have? RAM is often the biggest limiting factor in a webserver. If you have little RAM you should turn off KeepAlive because having Apache processes hanging around while they wait for more requests from persistent connections is a waste of precious memory. If CPU power is limited then you want KeepAlive on because it reduces CPU load.
  • Types of sites: If you have pages with a lot of images or other files linked into them, KeepAlive will improve the user experience significantly. This is because a single connection will be used to transfer multiple files.
  • Traffic patterns: The type of traffic you get. If your web traffic is spread out evenly throughout a day then you should turn on KeepAlive. OTOH, if you have bursty traffic where a lot of concurrent users access your sites during a short time period KeepAlive will cause your RAM usage to skyrocket so you should turn it off.

Configure Apache KeepAlive settings

Open up apache’s configuration file and look for the following settings. On CentOS this file is called httpd.conf and is located in /etc/httpd/conf. The following settings are noteworthy:
  • KeepAlive: Switches KeepAlive on or off. Put in “KeepAlive on” to turn it on and “KeepAlive off” to turn it off.
  • MaxKeepAliveRequests: The maximum number of requests a single persistent connection will service. A number between 50 and 75 would be plenty.
  • KeepAliveTimeout: How long should the server wait for new requests from connected clients. The default is 15 seconds which is way too high. Set it to between 1 and 5 seconds to avoid having processes wasting RAM while waiting for requests.
Other settings
KeepAlive affects other settings in your Apache configuration file even though they are not directly related. Here are the settings in an Apache prefork MPM webserver:
  • MaxClientsMaxClients is the maximum number of child processes launched by Apache to service incoming requests. With KeepAlive enabled you have will have a higher number of child processes active during peak times. So your MaxClients value may have to be increased.
  • MaxRequestsPerChild: The number of requests a child process will serve before it is killed and recreated. This is done to prevent memory leaks. When KeepAlive is turned on each persistent connection will count as one request. That effectively turns MaxRequestsPerChild into a maximum connections per child value. As a result you can set a lower MaxRequestsPerChild value if you allow KeepAlive. If you don’t allow KeepAlive you should increase the MaxRequestsPerChild value to prevent excessive CPU usage.

Final thoughts

There is no one universal solution to tuning Apache. It all depends on the resources at your disposal and the type of sites you have. When used properly KeepAlive can improve the user experience at minimal cost in terms of server resources. But it can also be a liability when you are faced with a large number of concurrent users.

Thursday, March 14, 2013

Nagios Error: Could not open command file

 
Nagios Error: Could not open command file ‘/usr/local/nagios/var/rw/nagios.cmd’ for update!
 
You get this error when you update on naigos GUI page, like you wanted to disable 
notification, Then it means that the permissions on the folder are messed up. Don’t 
bother setting up the permissions on the file itself, nagios.cmd,  since
that file gets recreated very often, so:
 

chown nagios.nagcmd /usr/local/nagios/var/rw 
chmod g+rwx /usr/local/nagios/var/rw 
chmod g+s /usr/local/nagios/var/rw 

Tuesday, March 12, 2013


CPAN Error: make test had returned bad status, won’t install without force

here are some perl CPAN issue during installation and it keep showing error “make test had returned bad status, won’t install without force”. 
To solve “CPAN error: make test had returned bad status, won’t install without force” follow the command below:-
·         First go into perl CPAN shell
·         then you can do force install of module using the command below:-
·         cpan> force install #module#
Change the #module# to your Module name.
·         Your CPAN module should be able to install successfully by now.

Monday, March 4, 2013

Quick YUM setup




1. Mount rhel disk on your linux box.

#mount -t iso9660 -o loop /tmp/rhel-server-5.6-x86_64-dvd.iso /mnt/

2. Install create repo for repository creation

#rpm -ivh createrepo-0.4.11-3.el5.noarch.rpm

3. you have to install either ftp or http for yum setup, i chose vsftp

#rpm -ivh vsftpd-2.0.5-16.el5_5.1.x86_64.rpm

#/etc/init.d/vsftpd restart

4. Copy iso folder's rpm inside ftp home dir

#cp /mnt/rhel/Server/  /var/ftp/pub/rhelyum/

5. Create repo file for accesing yum repository it can be on yum server itsel for client machine also

cat /etc/yum.repos.d/iso.repo
[rhelyum]
name=RHEL Yum Server
baseurl=ftp://10.20.71.60/pub/rhelyum/
enabled=1
gpgcheck=0

#/etc/init.d/yum-updatesd restart

6. Test yum
#yum install httpd*