Stripping Down Centos

Why Strip?

If you have some legacy CentOS server and performance is an issue, chances are someone installed the vanilla way, then configured the needed services and not even tuned it a little. You can get some performance by disabling unused services or using lighter alternatives.

Notice

This is not a step-by-step guide to install a minimal CentOS system, there are millions of those on the web, this aims at a specific use case: when you inherited an old server and you need to tweak it.

Use htop

htop gives you a great view of how resources are being used in your system. Check any resource hog and cut it down.

How to cut it?

Cups for example has nothing to do on a web server, let's turn it off.

chkconfig cups off          # disable service on startup
service cups stop           # stop the service
chkconfig --list cups

Now cups is down for good, use those resources wisely.

Running X?

Why is that server running X at all? gdm running? This is *nix, if you need X in a server (I never did so far) then startx is your guy. For X on a server use light stuff like IceWm or similar, not Gnome.

By default CentOS installs X with Gnome, the easiest way to disable this is by changing the system runlevel.

Before running init 3 please save you some troubles and check this.

chkconfig --list | grep "3:off" | grep "5:on"

If by any chance an important service was set up to run on level 5 and not on 3 then my friend you are going to have a bad day.

[root@server123 ~]  chkconfig --list | grep "3:off" | grep "5:on"
named           0:off   1:off   2:off   3:off   4:off   5:on    6:off
readahead_later 0:off   1:off   2:off   3:off   4:off   5:on    6:off

In the example above named and readahead_later are set up to run on runlevel 5 (multiuser with graphics) but not 3 (multiuser), let's fix it.

chkconfig named on
chkconfig readahead_later on

To change the system default runlevel open /etc/inittab and set id:5:initdefault: to id:3:initdefault:.

Or just use the l33t way:

sed -i '/id:5:initdefault/ s/5/3/' /etc/inittab

Now open tmux split in half and run htop in one side and init 3 on the other (or just init 3 if you're not into multiplexing, though you should be) this way you are able to check the resources being released.

But dude I need more speed!!1!

Well, I'm not a wizard (otherwise I would be hanging out with Gandalf and not writing this), sometimes your server really need those resources, you could go deep and tune specific services but YMMV, search for "SERVICE_NAME tuning" on Google. Try not to tune too much, being too clever can cause you the hairiest bugs.

A great tip?

Replace Apache with Nginx for static files, one of my CentOS was serving a few distros repositories for like a hundred workstations with Apache 2.2, I tried Nginx, now I smile every time I login and see this: load average: 0.00, 0.00, 0.00

Important: I do not recommend uninstalling any packages on a legacy system unless you are 120% sure is ok, just disable services instead. Follow this rule or embrace desperation.

Comments !

social