Memory-saving space optimized Linux background service programs

Source: Internet
Author: User
Article Title: optimize Linux background services with memory saving. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.

Every time we install a new Linux system, the installation wizard will always help us start a batch of background service programs by default. These programs silently complete all kinds of tasks in the background. Such as power management, scheduled tasks, and system audits.

However, our computer hardware varies widely, and the purpose of installing Linux is also varied. These background programs are often not suitable for our requirements. In fact, most of them are redundant. No matter whether we are a professional system administrator or a user who loves their own machines, we are always unable to tolerate a lot of useless processes running: Taking up memory, taking up CPU time, and looking dizzy.

This article uses CentOS and Fedora as examples to explain how to optimize these services.

1. How are background processes started?

To put it simply, Linux has multiple startup levels. You can view this line in the/etc/inittab.

Id: 3: initdefault:

To learn about the startup level of Linux.

Level 3 does not start X window and related services. Suitable for servers.

The startup programs of Level 3 background services are all placed under/etc/rc3.d. The script starting with S indicates that it is started upon startup, and the script starting with K indicates that it is stopped upon shutdown.

There are also 5 common levels. And so on.

In fact, these scripts are just links to the corresponding scripts under/etc/init. d.

2. What does each service do?

You can view the first few lines of these scripts. Generally, there is a brief description. For example, S26acpid

# Description: Listen and dispatch ACPI events from the kernel

Listen for and distribute ACPI events in the kernel.

The following describes how to optimize these processes:

1. ntp

I chose ntp as the first example. Ntp is a very important service, but it does not have to be used as a process in the background.

Ntp is a time service program in Linux. Similar to one in Windows time settings: synchronize time with the Internet. With ntp, we no longer need to adjust the time in the computer. As long as the computer is connected to the Internet, ntp automatically corrects the time.

Compared with Windows, ntp in Linux has more functions. It can also use the current computer as a time server to provide time services to other computers. However, this is useless for individual users.

So our idea is: Don't start this service, but it can be corrected once a week.

The procedure is simple:

Add a script ntpdate under/etc/cron. weekly/. The script content is

#! /Bin/sh

# Adjust clock weekly.

# Exec/usr/sbin/ntpdate pool.ntp.org

Exec/usr/sbin/ntpd-q

Exit 0

Script Description: This script lists two ntp commands, which can be used to correct the time. You can use either of them. According to the ntp documentation, ntpdate will be discarded in the future and converted to ntpd-q. I tried it. In older Linux systems, such as Mandriva 2006 and ntpd-q cannot be used.

Then convert the script into executable

# Chmod u + x ntpdate

Restart crond

#/Etc/init. d/crond restart

Stop and delete the ntp service

#/Etc/init. d/ntpd stop

Check whether ntpd scripts starting with S exist in/etc/rc3.d or/etc/rc5.d. If yes, delete it. This action seems violent. The "gentle" approach is to run setup or system-config-services on the GUI.

Finally, ntp uses udp port 123 as its communication port. Ntp can only work after the firewall releases this port.

2. Optimization of other cronjobs

Cronjob started by default is placed

Cron. hourly

Cron. daily

Cron. weekly

Cron. monthly

Some cronjobs do not need to be done too frequently. Although these tasks run around 4 o'clock in the morning, they are also a waste of resources, hard disks, and power...

The following is a list:

Makewhatis. cron this task is to generate or update the whatis database. When the operating system does not often install and uninstall software, you do not need to do it every day.

The mlocate. cron task generates or updates the locate database. The same is true.

The rpm task is to list the rpm packages installed by the system and write them to a file. The same is true.

The prelink task is to "pre-link" applications and dynamic libraries in the operating system to speed up the startup of these applications. You don't need to do it every day. You can do it once a week.

You can create another cron. manual directory to move tasks that do not want to run regularly to this directory. Run it manually.

The following is an example on my machine:

[Root @ home etc] # ls cron *

Cron. deny crontab

Cron. d:

Cron. daily:

00 webalizer 0 anacron 0 logwatch certwatch cups logrotate

Cron. hourly:

Mcelog. cron

Cron. manual:

Makewhatis. cron mlocate. cron rpm

Cron. monthly:

0 anacron

Cron. weekly:

0 anacron 99-raid-check ntpdate prelink

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.