A few tips I use on any server

Status
Not open for further replies.

Hescominsoon

OMG Member
Joined
Mar 22, 2010
Messages
103
There are a few things I do that have helped my servers run longer w/o needing things like apc or any other addons other than the basic LAMP stack and whatever forums I run. For web facing servers I use Debian. For internal/file servers i use Centos.
Hardware:
CPU: Dual core 2.0 ghz or higher
RAM 2.0 Gigs or more
Hard disk: It highly depends on the scenario. This is one you have to research yourself.
32-bit or 64 bit. 1-3 gigs 32 bit. more than 3 gigs 64 bit.

Machine being profiled:
dual p-4 based xeon 2.8 ghz w/HT active
3 gigs ram
2x 36 gig 15k rpm SCSI Hardware RAID 1 with 1 hot spare
32 bit Debian install
10 megabit unmetered connection


Linux distro:
I use either Debian or Centos. Order of preference is:

1. Debian. This was a recent change. I looked at Ubuntu but I got tired of having to jump through hoops to get to root.(I'm not a fan of sudo..I also don't like the fact the OS "hides" root from the admin). Ubuntu is a modified Debian. As a matter of fact when you pull an update more than half of the servers queried are Debian. This made me wonder why bother with this? I'll just head to the parent. The installer is not too bad anymore(it used to require an engineering degree). Debian has always been known for stability. Ubuntu has had a record of regressions and bugs in new releases that take an update or two to work out. This is unacceptable in a server release.

2. Centos. The granddaddy of Enterprise distros..RHEL..has it's whitebox offspring..Centos. I ran this distro exclusively since Cent 4.0. I started running into issue with their policy of back porting security to the older versions. Newer software was balking at the older versions they kept for stability. This is what prompted my search for a new distro to base from(see above). I never had a major issue with Centos. However once the software/scripts i ran started falling over on a regular basis due to the older versions that were kept(requiring manuall installs of newer version or third party distros) I moved to Debian.

Control software:
Virtualmin GPL edition. I can't say enough about this software. It simplifies webserver administration so much it's crazy. The community support is not only active but highly engaged by the developers themselves. you install a base Debian system, install sshd, then go grab the .sh script for install. install and then log into the webmin installation and off you go. You do have to install a couple of things via apt--but that's totally painless(like php5-gd for XF installs). I also use this software to easily setup the php wrapper that runs all php/cgi scripts as the user and not as apache. This increases security without a huge performance hit. backups, php settings, disk quotas..etc etc or stupid easy after this. Moving a site with virtualmin is as easy as make a backup of the entire virtualmin setup(minus the server settings) start up new server..install virt..restore backup..boom you're back. I just did this to move a virt hosted on a dedi cent box to a dedi debian box..gzipped it and ssh'ed it directly to the new box and then restored it on the new box form the import tool in the new box's virt. I actually bought a license just to support their excellent work.

Apache settings:
Apache uses the preform method by default. This fires up multiple copies of apache one per request. This is slower and uses ram inefficiently. I always disable prefork and enable worker.mpm which means you run Apache in a multi threaded mode and not a multi-process mode. Here's a sample of my .conf file.
# prefork MPM
# StartServers: number of server processes to start
# MinSpareServers: minimum number of server processes which are kept spare
# MaxSpareServers: maximum number of server processes which are kept spare
# MaxClients: maximum number of server processes allowed to start
# MaxRequestsPerChild: maximum number of requests a server process serves
# <IfModule mpm_prefork_module>
# StartServers 5
# MinSpareServers 5
# MaxSpareServers 10
# MaxClients 150
# MaxRequestsPerChild 0
# </IfModule>

# worker MPM
# StartServers: initial number of server processes to start
# MaxClients: maximum number of simultaneous client connections
# MinSpareThreads: minimum number of worker threads which are kept spare
# MaxSpareThreads: maximum number of worker threads which are kept spare
# ThreadsPerChild: constant number of worker threads in each server process
# MaxRequestsPerChild: maximum number of requests a server process serves
<IfModule mpm_worker_module>
StartServers 2
MaxClients 65
MinSpareThreads 25
MaxSpareThreads 75
ThreadsPerChild 25
MaxRequestsPerChild 250
</IfModule>

Right now this server also hosts two real-time audio streams so i have the maximum users cut down a bit. If we start hitting that limit I’ll look into bumping it up. I also have the max requests set low(25)) to make sure the server processes are scavenged to preserve ram usage. If there is a need I can easily up this..but the more requests you allow per child the longer it lives and the more ram it'll consume over time. The tradeoff is speed vs ram usage.

Keeping the box from swapping.
As we all know the instant the machine has to swap performance craters. Most 2.6 kernels are set for vm.swappiness=60. This is unacceptably high. I've seen boxes with 50% ram free start swapping with this parameter set this high. I ALWAYS set this value to zero...without fail. There's nothing more annoying to have a server with 25% or more ram free and it's swapping like you don't have enough ram by 50%.

These are some basic things i do at startup for any machine.
 

melbo

OMG Member
Joined
Dec 2, 2010
Messages
116
Great post! Thanks.
Where do I configure vm.swapiness=0
 

Hescominsoon

OMG Member
Joined
Mar 22, 2010
Messages
103
it depends on the distro. in Debian it's /etc/sysctl.conf. at the bottom add vm.swappiness=(whatever) i make this zero. reboot.
 

Hescominsoon

OMG Member
Joined
Mar 22, 2010
Messages
103
actually you can do it to a running system:
To set it to zero, type:
echo 0 > /proc/sys/vm/swappiness

Then edit /etc/sysctl.conf to match..this way the setting survives a reboot.
 

Floris

I'm just me :) Hi.
Staff member
Joined
Jan 1, 2001
Messages
60,100
Great write out, thank you for doing that! Shame to not see Ubuntu in the list though ;) I'd personally would pick it over CentOS these days.
 

EQnoble

OMG Member
Joined
Dec 11, 2010
Messages
128
Clutch Thread! Thank you for the read.

I use CentOS myself and have never really mucked around with Ubuntu to any serious level. Was wondering if anyone had a list with the downsides of any(maintained) specific distro in relation to it's quality as a webserver's OS?

I have been telling myself I need to learn linux and don't know which distro to go with. Learning in depth how linux works to me means I should select a distro that I will be using primarily. CentOS being that would be my first choice as that's what my servers all run on however, knowing the up and downsides of a list of distros may help me select a route to go with. It seems as though a few people here may have some experience :-) so any tips on the path I should choose before I start stepping would be greatly appreciated.
 

Hescominsoon

OMG Member
Joined
Mar 22, 2010
Messages
103
Great write out, thank you for doing that! Shame to not see Ubuntu in the list though ;) I'd personally would pick it over CentOS these days.
I don't like Ubuntu as it hides root for you..plus it has a log history of regressions with every release. If i am going to use a Debian product on a server i'll use the original. Servers are about stability..Centos and Debian give you that. So if you want to use a Debian product on your server...use Debian and not Ubuntu.
 

Floris

I'm just me :) Hi.
Staff member
Joined
Jan 1, 2001
Messages
60,100
CentOS gives you outdated stability ;)
I am glad I don't use it anymore. It's debian, freebsd or ubuntu - and i prefer ubuntu for web hosting, debian for the rest and freebsd for irc related.
 

Hescominsoon

OMG Member
Joined
Mar 22, 2010
Messages
103
RHEL and it's siblings give the enterprise customer what they want...version control and stability with the same security as newer versions without having to install newer versions to maintain compatibility. Most hosters need to stay near the bleeding edge to be able to run their suites...Enterprises go for stability not bleeding edge. It's not really outdated if your not in the bleeding market..most enterprises aren't so RHEL/CENT fill their prescribed roles perfectly..:)
 

Floris

I'm just me :) Hi.
Staff member
Joined
Jan 1, 2001
Messages
60,100
Well, it is just silly if there are major security issues and they mark them for the next branch release, and then it takes 1,5 years before that branch comes out to upgrade to.

Enterprise takes stability over security? I'll stop using enterprise hosting then :)
 

Hescominsoon

OMG Member
Joined
Mar 22, 2010
Messages
103
Well, it is just silly if there are major security issues and they mark them for the next branch release, and then it takes 1,5 years before that branch comes out to upgrade to.

Enterprise takes stability over security? I'll stop using enterprise hosting then :)

Your looking at that wrong. They backport all security issues back into the RHEL codebase..it doesn't take 1.5 years(that's a MS thing). They do NOT however go to the newer versions on the base..aka fedora is basically the quick released version of the non LTS ubuntu..except there is one major difference..Red Hat will take a fedora release..and exclusively tune it and fix bugs that are present for months on end before they release it as the next RHEL. RHEL version tend to be really good right out of the box. From that point forward all security issues that are discovered in newer packages that affect the versions they have stabilized on are immediately backported into their current codebased and pushed out to everyone..:) They just don't advance to the newest versions of everything. It's a good model actually. This is another reason i like Virtualmin. they have a repo available for Centos that will keep centos updated with the later version of the packages.... You do loose the compatibility you get with the long term ABI compatibility the RHEL uses...but you can have a bit more updated software inside of Cent is you wish..you can also achieve the same thing with third party repos..but then you are modifying the base os so much it's not relay Centos anymore..:)
 

Floris

I'm just me :) Hi.
Staff member
Joined
Jan 1, 2001
Messages
60,100
not my experience with centos, hence why i moved away from it. Sorry :)
 

Floris

I'm just me :) Hi.
Staff member
Joined
Jan 1, 2001
Messages
60,100
Your information did give me an additional few on CentOS though. Worth reading up on.
 
Status
Not open for further replies.
Top