Archive for Tips & Tricks

Linux System Tuning - Services


Disabling unneeded services

To ensure that my machines run as efficiently and securely as possible, I disable a number of services after each installation. The end result is a system that accepts ssh connections on TCP port 22, and on one or more service ports that are in use by the applications hosted on the platform. To get to this state, I go through and disable numerous services that come enabled by default. Here is the default list of services that are enabled after a CentOS 4.4 installation:

$ chkconfig –l | grep on
atd             0:off   1:off   2:off   3:on    4:on    5:on    6:off
messagebus      0:off   1:off   2:off   3:on    4:on    5:on    6:off
smartd          0:off   1:off   2:on    3:on    4:on    5:on    6:off
portmap         0:off   1:off   2:off   3:on    4:on    5:on    6:off
sendmail        0:off   1:off   2:on    3:on    4:on    5:on    6:off
netfs           0:off   1:off   2:off   3:on    4:on    5:on    6:off
cups            0:off   1:off   2:on    3:on    4:on    5:on    6:off
irqbalance      0:off   1:off   2:off   3:on    4:on    5:on    6:off
rpcgssd         0:off   1:off   2:off   3:on    4:on    5:on    6:off
xfs             0:off   1:off   2:on    3:on    4:on    5:on    6:off
isdn            0:off   1:off   2:on    3:on    4:on    5:on    6:off
autofs          0:off   1:off   2:off   3:on    4:on    5:on    6:off
gpm             0:off   1:off   2:on    3:on    4:on    5:on    6:off
apmd            0:off   1:off   2:on    3:on    4:on    5:on    6:off
crond           0:off   1:off   2:on    3:on    4:on    5:on    6:off
acpid           0:off   1:off   2:off   3:on    4:on    5:on    6:off
microcode_ctl   0:off   1:off   2:on    3:on    4:on    5:on    6:off
pcmcia          0:off   1:off   2:on    3:on    4:on    5:on    6:off
cpuspeed        0:off   1:on    2:on    3:on    4:on    5:on    6:off
xinetd          0:off   1:off   2:off   3:on    4:on    5:on    6:off
rpcidmapd       0:off   1:off   2:off   3:on    4:on    5:on    6:off
readahead_early 0:off   1:off   2:off   3:off   4:off   5:on    6:off
readahead       0:off   1:off   2:off   3:off   4:off   5:on    6:off
sshd            0:off   1:off   2:on    3:on    4:on    5:on    6:off
anacron         0:off   1:off   2:on    3:on    4:on    5:on    6:off
network         0:off   1:off   2:on    3:on    4:on    5:on    6:off
kudzu           0:off   1:off   2:off   3:on    4:on    5:on    6:off
syslog          0:off   1:off   2:on    3:on    4:on    5:on    6:off
nfslock         0:off   1:off   2:off   3:on    4:on    5:on    6:off
rawdevices      0:off   1:off   2:off   3:on    4:on    5:on    6:off
mdmonitor       0:off   1:off   2:on    3:on    4:on    5:on    6:off
haldaemon       0:off   1:off   2:off   3:on    4:on    5:on    6:off

Several of these services are required, but several others serve no purpose in my environment, and use CPU and memory resources that would be better allocated to my applications. Since I don’t use RPC services, autofs or NFS, those are the first to get disabled:

$ /sbin/chkconfig –level 0123456 portmap off
$ /sbin/chkconfig –level 0123456 nfslock off
$ /sbin/chkconfig –level 0123456 netfs off
$ /sbin/chkconfig –level 0123456 rpcgssd off
$ /sbin/chkconfig –level 0123456 rpcidmapd off
$ /sbin/chkconfig –level 0123456 autofs off

I also don’t allow individual hosts to receive mail from the outside world, so sendmail gets nixed next:

$ /sbin/chkconfig –level 0123456 sendmail off

On server platforms, who needs printing?:

$ /sbin/chkconfig –level 0123456 cups off

Now we get to the font server, isdn capabilities, console mouse and pcmcia support. I don’t use these services on my servers, so they get disabled as well:

$ /sbin/chkconfig –level 0123456 xfs off
$ /sbin/chkconfig –level 0123456 isdn off
$ /sbin/chkconfig –level 0123456 gpm off
$ /sbin/chkconfig –level 0123456 pcmcia off

Once these services are disabled (and optionally stopped with the service command or a reboot), my netstat output looks nice and clean:

$ netstat –tcp –udp –listening
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address               Foreign Address             State
tcp        0      0 *:ssh                       *:*                         LISTEN

This has served me well over the years, since it reduces boot time (less rc scripts to run), and frees up additional resources for my applications (while this isn’t substantial, every page of memory helps!).
Blogmarks BlogMemes BlogLines del.icio.us de.lirio.us Digg Facebook Google Google Reader LinkaGoGo Ask.com MyStuff Ask.com Yahoo! MyWeb Netscape Sphere StumbleUpon Plugin by Dichev.com

Leave a Comment

Linux System Tuning - Back to Basics

Tuning an overview

When tuning, remember that there is no “Magic” setting, no single set of tuning parameters that cover all situations. Each server will have it’s own bottlenecks. This can be caused by many things, here are a few examples.

  1. Software & Applications
  2. Hardware (cpu, memory, architecture, bus speed, etc.)
  3. LOAD end user, application, and system overhead.
  4. Outside factors (network, san, etc.)
When tuning a system there are several main items to keep in mind.

  • Each system is unique
  • Alter 1 thing at a time

    • Use the settings recommended by your software / hardware provider
    • Alter one setting at a time. This will give you the opportunity to see if that change makes an impact. Making to many changes may degrade performance.
    • Test after each change. Be sure to gather enough performance data so you can determine if the change had a positive or negative impact.
    • Did I say test?? I can’t stress this enough.
  • Document, Document, Document. Document every change you make. This will save you time and sanity if you need to back out some changes, and allow for the change to be easily duplicated.
  • Shutdown unneeded services. Take a look at the output of “chkconfig -l | grep on” I bet you there are a few things we can shutoff.

    • Gnome ???? on a web server?? init 3 anyone??
    • iptables, SuSe-Firewall, RedHat Firewall, etc. If you don’t have unneeded services running why do you need a firewall to restrict access to them???
    • SELinux, AppArmor?? are big performance killers and usally not that important.
Blogmarks BlogMemes BlogLines del.icio.us de.lirio.us Digg Facebook Google Google Reader LinkaGoGo Ask.com MyStuff Ask.com Yahoo! MyWeb Netscape Sphere StumbleUpon Plugin by Dichev.com

Leave a Comment

Tips & Tricks “du”

du -sh ./ - shows the size of the current directory in human readable format without listing any sub directories

du -sh * > outputfile - shows the size of the files and directories in the current directory in human readable format without listing any sub directories directory and sends the output to a file.

du -sh * | grep something - shows the size of the files and directories in the current directory in human readable format without listing any sub directories directory and only lists files or directories with something in the name
Blogmarks BlogMemes BlogLines del.icio.us de.lirio.us Digg Facebook Google Google Reader LinkaGoGo Ask.com MyStuff Ask.com Yahoo! MyWeb Netscape Sphere StumbleUpon Plugin by Dichev.com

Leave a Comment

Tips & Tricks “Resintalling grub”

I came across the following procedure for reinstalling grub and thought it would be useful to share, having it handy can save you time you get into a bind.

1. Boot the system from an installation boot medium.

2. Type linux rescue at the installation boot prompt to enter the rescue environment.

3. Type chroot /mnt/sysimage to mount the root partition.

4. Type /sbin/grub-install /dev/hda to reinstall the GRUB boot loader, where /dev/hda is the boot partition.

5. Review the /boot/grub/grub.conf file, as additional entries may be needed for GRUB to control additional operating systems.

6. Reboot the system.
Blogmarks BlogMemes BlogLines del.icio.us de.lirio.us Digg Facebook Google Google Reader LinkaGoGo Ask.com MyStuff Ask.com Yahoo! MyWeb Netscape Sphere StumbleUpon Plugin by Dichev.com

Leave a Comment

Bash Tips & Tricks

bash, or the Bourne again shell, is the default shell in most Linux distributions. The popularity of the bash shell amongst Linux and UNIX users is no accident. It has many features to enhance user-friendliness and productivity. Unfortunately, you can’t take advantage of those features unless you know they exist.

When I first started using Linux, the only bash feature I took advantage of was going back through the command history using the up arrow. I soon learned additional features by watching others and asking questions. In this article, I’d like to share some bash tricks I’ve learned over the years.

» Continue reading “Bash Tips & Tricks”
Blogmarks BlogMemes BlogLines del.icio.us de.lirio.us Digg Facebook Google Google Reader LinkaGoGo Ask.com MyStuff Ask.com Yahoo! MyWeb Netscape Sphere StumbleUpon Plugin by Dichev.com

Leave a Comment

Which interface is eth0?

If you’re not sure which physical interface is eth0 and which is eth1 (or eth2), run:
ethtool -p eth0 5

This blinks the LED on the interface for five seconds–without interrupting network traffic.
Blogmarks BlogMemes BlogLines del.icio.us de.lirio.us Digg Facebook Google Google Reader LinkaGoGo Ask.com MyStuff Ask.com Yahoo! MyWeb Netscape Sphere StumbleUpon Plugin by Dichev.com

Leave a Comment

Easy and safe bash history searches

Often the command you need is in your history, how do you find it?

One simple method is to run the history command and pipe it through grep.
$ history | grep cat
110  cat /tmp/foo

You can then run the command by typing ! and the history line number:
$ !110
cat /tmp/foo

» Continue reading “Easy and safe bash history searches”
Blogmarks BlogMemes BlogLines del.icio.us de.lirio.us Digg Facebook Google Google Reader LinkaGoGo Ask.com MyStuff Ask.com Yahoo! MyWeb Netscape Sphere StumbleUpon Plugin by Dichev.com

Leave a Comment

mismatch in /etc/passwd and /etc/shadow

This can occur when there is inconsistencies between the /etc/passwd and /etc/shadow files. The offending account needs to either be modified or removed. To find out which account is causing the issue run the following command as root:

pwck


All entries in the /etc/passwd and /etc/shadow are checked to see that the entry has the proper format and valid data in each field. The user is prompted to delete entries that are improperly formatted or which have other uncorrectable errors.

An example of an account that is in /etc/shadow but not in /etc/passwd:

no matching password file entry in /etc/passwd

delete line

'someuser:!!:13758:0:99999:8:::'?
Blogmarks BlogMemes BlogLines del.icio.us de.lirio.us Digg Facebook Google Google Reader LinkaGoGo Ask.com MyStuff Ask.com Yahoo! MyWeb Netscape Sphere StumbleUpon Plugin by Dichev.com

Leave a Comment

Why do the CPU stats vary with ps and top?

The commands ps and top express CPU time differently. While ps calculates it by “total CPU time” divided by “time task is running”, top shows the value as a percentage of overall CPU time.

For ps, this means that the longer a process is running without a high CPU utilization the smaller the value of %cpugets (it converges to zero).

For top, this means that it displays this value as share of the CPU time since last screen update and is therefore more accurate in terms of “current CPU utilization”.
Blogmarks BlogMemes BlogLines del.icio.us de.lirio.us Digg Facebook Google Google Reader LinkaGoGo Ask.com MyStuff Ask.com Yahoo! MyWeb Netscape Sphere StumbleUpon Plugin by Dichev.com

Leave a Comment

capture the output of “top” to a file?

The command top is a very useful tool to capture information about process running on Linux. Many times this information may need to be captured to a file. This can be done with the following command:

top -b -n1 > /tmp/top.txt


This will run top once write the output to a file and exit.

The command top can also be run so that it will give multiple reports. To run top 5 times and wait 5 seconds between each output the command would be:

top -b -n5 -d5 > /tmp/top.txt
Blogmarks BlogMemes BlogLines del.icio.us de.lirio.us Digg Facebook Google Google Reader LinkaGoGo Ask.com MyStuff Ask.com Yahoo! MyWeb Netscape Sphere StumbleUpon Plugin by Dichev.com

Leave a Comment