Nutshell

Follow by Email

 

Apache Server Optimization and Apache Options

Saturday, April 27, 2013


As the important configurations are usually stored by Apache server  in httpd.conf which is usully located at /usr/local/apache/conf/httpd.conf.  We can check by editing this file in your favorite text editor. that is:
vi /usr/local/apache/conf/httpd.conf
WE WILL DISCUSS ABOUT THE MAJOR FACTS AND OPTIONS THAT ARE RESPONSIBLE FOR THE APACHE'S PERFORMANCE AS BELOW ,
MaxClients
Total number of concurrent connections at a time.
find it in config file. This can be set to some adorable value. I will be using this formula to determine perfect tweak for our machine .
MaxClients = 150 x RAM (GB or in MB)
let us say if you have 2 GB'S  RAM set it to 300.
Actually There is no any issue for you to set it any more than this unless you have a specific problem with its values . The higher values can lead to a hang in case of a DDOS came .  Too less can also create timeout issues when accessed. 
ServerLimit
This operand should be eqal as MaxClients
ServerLimit = 150 x RAM (GB)

MinSpareServers and MaxSpareServers
MaxSpareServers & MinSpareServers controls how more additional ( not used) child-processes Apache will keep alive when its waiting for more requests to put them to use. Each child-process consumes more resources, so having MaxSpareServers set too high can cause resource problems. On the other hand, if the number of unused servers drops below MinSpareServers, Apache will fork (an expensive operation) new child-processes until MinSpareServers is satisfied.
Leave those operands to following :
  • MinSpareServers 5
  • MaxSpareServers 10
If you have more then 2 GB'S of RAM and you run a resource intensive website consider increasing MaxSpareServers.

MaxRequestsPerChild
It Controls the number of request that a child serves before the child is killed. This should not be set too low as it will put an unnecessary load on the apache server to recreate the child. I suggest setting it to:
  • MaxRequestsPerChild 1000 for 1 GB RAM
10,000 for 2 GB and 0 for more than 2 GB RAM

KeepAlive and MaxKeepAliveRequests
KeepAlive facilitates longitivity of HTTP sessions which will allow multiple requests to be sent over the same TCP connection. In some cases this has been shown to result in an almost 50% speedup in latency times for HTML documents with many images, but the keepalive on is also a resource intensive option.
Here comes the big question: To KeepAlive or not to KeepAlive?
Well the opinions are mixed here, some say to KeepAlive some say not to.
  • KeepAlive off
If you want to hear my option I would say NOT to KeepAlive if you are running a shared hosting business or if you want to get the most out of your hardware. You should KeepAlive only if the loading time of your pages is the most important factor in your business and you have the money to invest in a more powerful hardware. If you decide to KeepAlive I suggest you set MaxKeepAliveRequest low to something like 2 seconds.
StartServers
Sets the number of child server processes created on startup. This setting depends greatly on the type of webserver you run. If you run low traffic websites on that server set it low to something like 5. If you have resource intensive websites on that server you should set it close to MaxClients.
  • StartServers 5
Timeout
The amount of time Apache will wait for three things: the total amount of time it takes to receive a GET request, The amount of time between receipt of TCP packets on a POST or PUT request, the amount of time between ACKs on transmissions of TCP packets in responses.
The default value is 300. You should set time to something a bit lower. A setting of 150 is probably ok. This will also help in case of small DOS attacks like to ones targeting some phpBB forums. Do NOT set it any lower then 10 as your users will start having timeout problems.
  • Timeout 150
After you have done all the necessary changes you can go ahead and restart Apache.
There is an extra step that you have to do so that the changes that you done to httpd.conf aren’t lost when a recompile is done.
To also save the changes in the database you will have to run:
/usr/local/cpanel/bin/apache_conf_distiller –update
You can check to see if the changes were accepted and will not be discarded at the next apache recompile by running
/usr/local/cpanel/bin/build_apache_conf
MY operands :
MinSpareServers 5
MaxSpareServers 10
ServerLimit 600
MaxClients 600
MaxRequestsPerChild 0
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 3
Timeout 30

Setting Up A Central log Server , The syslog Server

Wednesday, April 24, 2013


Hey Guys ... Let's Start Setting Up A Central Syslog Server


Linux systems already have syslog installed.
Configure the Server Computers:-
#service syslog stop
and if it fails again, go for the old-school kill command
#ps axfu | grep syslog
copy the PID (number from second column) from the syslog line and
#kill -9 PID
Open /etc/sysconfig/syslog with your favorite text editor
and  Find the line
SYSLOGD_OPTIONS="-m 0"
Replace it with
SYSLOGD_OPTIONS="-rm 0"
Restart the syslog daemon
#service syslog restart
you should see a message similar to “syslog restarted (remote reception) when executing the command
#tail /var/log/messages
you should either find the RC syslog file, edit it and add the “-r” flag to the syslog options or, if you’ve used
the old-school kill command, simply start syslog manually
#syslogd -r
In the final step, you’ll have to make sure the firewall isn’t blocking any incoming packets. Simply run this
iptables command so any rule will be overridden
#iptables -I INPUT -p udp -i eth0 -s 192.168.1.2 -d 192.168.1.1 --dport 514 -j ACCEPT
This rule will ensure that the syslog server (192.168.1.1) will receive UDP packets (containing log events) from the CLIENT (192.168.1.2).
You MUST replace these IP addresses with the correct ones. Also, you will have to re-execute this command for every other client PC you may have (192.168.1.3192.168.1.4etc).
Configure the CLIENT computers:-
The client computers are configured to send any logged event to the syslog server, immediately as the events occur. To do this, edit the file /etc/syslog.conf on every client computer and add this line in  the file
*.* @192.168.1.1
Again, replace the example IP address with the syslog server’s correct IP address.
restart the syslog on every client you’ve edited.
#service syslog restart
make sure that client is very much able to send UDP packets. 

This can be ensured by , the following command 

iptables -I OUTPUT -p udp -i eth0 -s 192.168.1.2 -d 192.168.1.1 --dport 514 -j ACCEPT
This is it. If everything was done correctly, you should start receiving log events to the syslog server. To view them, run.
#tail -f /var/log/messages

Total Pageviews