Linux System Optimization

Source: Internet
Author: User

Our servers are not directly hosted in the IDC after installation,

Instead, a series of optimization configurations and security configurations are required.

1. It should be easy to understand to shut down unnecessary services. All services that are not required by our system will be shut down. This will reduce the memory and CPU usage, another advantage is that it can improve security. Which services must be retained?

On linux machines, there are usually four services that must be retained.

Iptables

A powerful firewall in linux, as long as the machine needs to connect to the Internet, Where can it be opened?

Network

If the network of a linux machine is not connected to the Internet, it can be disabled.

Sshd

This is an openssh server. If your machine is hosted in an IDC instead of local operations,

The sshd service is used to access the machine.

Syslog

This is the log system of linux, which must be available; otherwise, the machine will not be able to find the cause when there is a problem. What other services need to be retained except the four necessary services?

In this case, you can determine the purpose of the system. For example, to enable the mysqld (or oracle) web server, you need to enable apache 2 to disable unwanted tty servers.

Edit your/etc/inittab

Find the following section:

1: 2345: respawn:/sbin/mingetty tty1

2: 2345: respawn:/sbin/mingetty tty2

3: 2345: respawn:/sbin/mingetty tty3

4: 2345: respawn:/sbin/mingetty tty4

5: 2345: respawn:/sbin/mingetty tty5

6: 2345: respawn:/sbin/mingetty tty6 this command enables init to open six consoles for you, you can access these six consoles by using alt + f1 to alt + f6. By default, all these six consoles reside in the memory. In fact, there is no need to use so many of them. You can see that using the ps auxf command, six processes: root 3004 0.0 0.0 1892 412 tty1 Ss + Jun29/sbin/mingetty tty1 root 3037 0.0 0.0 2492 tty2 Ss + Jun29/sbin/mingetty tty2 root 412 3038 0.0 2308 412 tty3 Ss + Jun29/sbin/mingetty tty3 root 3051 0.0 0.0 1812 412 tty4 Ss + Jun29/sbin/mingetty tty4 root 3056 0.0 0.0 2116 412 tty5 Ss + Jun29/sbin/mingetty tty5 root 3117 0.0 0.0 2396 412 tty6 Ss + Jun29/sbin/mingetty tty6 how to disable these processes?

Usually we can keep the first two consoles, and comment out the last four ones with #. Then we don't need to restart the machine, just execute the init q command.

Init q

Q as the parameter meaning: Re-Execute Command 3 in/etc/inittab, how to disable ipv6? Ipv6 is not required yet, but it will be used as the resident core of the module after the system is installed,

You can use this step to close it:

First, edit the network configuration file:

Vi/etc/sysconfig/network

Modify

NETWORKING_IPV6 = yes is

NETWORKING_IPV6 = no and disable its module: vi/etc/modprobe. conf

Add the following two lines to the file:

Alias net-pf-10 off

After alias ipv6 off is modified, restart the machine to make it take effect.

4. How do I disable atime?

A linux file has three default times:

Atime: Access time to this file

Ctime: the time when inode of this file changes.

Mtime: the modification time of this file. If there are multiple small files, there is usually no need to record the file access time, which can reduce disk io, for example, how do I set multiple small images on a web server page?

Modify the file system configuration file: vi/etc/fstab

Use noatime and nodiratime in partitions that contain a large number of small files

For example:

/Dev/md5/data/pics1 ext3 noatime, nodiratime 0 0 will no longer generate disk write io5 when files are accessed, so make sure your server runs on level 3

Practice:

Vi/etc/inittab

Id: 3: initdefault:

It is unnecessary for the server to run X 6, and sshd is optimized.

X11Forwarding no // do not forward x images

UseDNS no // do not reverse resolution of IP addresses

7. Optimize shell

Modify command history record

# Vi/etc/profile

Change HISTSIZE = 1000 to HISTSIZE = 100

Then source/etc/profile

  1. Step 7 of building a more reliable Linux System
  2. A required course for Linux system speed-up
  3. Turning your Linux system into a copper wall

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.