How to optimize the Linux server after it is installed is not directly hosted in the data center after it is installed, instead, we need to perform a series of optimization configurations and security configurations. 1. It should be easy to understand to close services that are not needed by our system, one advantage is to reduce memory and CPU usage, and the other advantage is to improve security. Which services must be retained? On linux machines, there are usually four services that must be retained. iptables is a powerful firewall in linux. As long as the machine needs to be connected to the Internet, the network of the linux machine must be enabled, if you do not want to access the Internet, you can disable it. If you want to access the Internet, you must enable it. sshd is an openssh server. If your machine is not operated locally, it is hosted in the IDC, therefore, syslog must be performed through the sshd service when accessing the machine. This is the log system of the linux system and must be available. Otherwise, the cause will not be found in the case of machine problems except for the four necessary services, what other services need to be retained? In this case, you can determine the purpose of the system. For example, to use a database server, you need to enable the mysqld (or oracle) web server, to enable apache 2 and disable unnecessary tty, edit your/etc/inittab and find the following section: 1: 2345: respawn:/sbin/mingetty tty12: 2345: respawn: /sbin/mingetty tty23: 2345: respawn:/sbin/mingetty tty34: 2345: respawn:/sbin/mingetty tty45: 2345: Weight:/sbin/mingetty tty56: 2345: Weight: the/sbin/mingetty tty6 command enables init to open six consoles for you. You can use alt + f1 to alt + f6 to access these six consoles by default, in fact, there is no need to use so many. You can see that the ps auxf command is six. Processes: root 3004 0.0 0.0 1892 tty1 Ss + Jun29/sbin/mingetty tty1root 412 3037 0.0 0.0 2492 tty2 Ss + Jun29/sbin/mingetty tty2root 412 3038 0.0 0.0 tty3 Ss + Jun29/sbin/mingetty tty3root 3051 0.0 0.0 1812 tty4 Ss + Jun29/sbin/mingetty tty4root 412 3056 0.0 0.0 2116 tty5 Ss + Jun29/sbin/mingetty tty5root 412 3117 0.0 2396 412 tty6 Ss + Jun29/sbin/mingetty tty6 How do I close these processes? Usually we can keep the first two consoles, and annotate the last four with #, and then we don't need to restart the machine, you only need to execute the init q command to define init q as a parameter: Re-execute the command in/etc/inittab and restart the machine to make the modification take effect. 3. How do I disable atime? A linux file has three default times: atime: Access time of this file ctime: 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 uses noatime in the partition containing a large number of small files. nodiratime includes:/dev/md5/data/pics1 ext3 noatime, nodiratime 0 0 will no longer generate disk write io when files are accessed. 4. Make sure your server runs on level 3. Practice: vi/etc/inittab id: 3: initdefault: it is unnecessary to run X on the server. 5. Optimization of sshd X11Forwarding no // forwarding of x images without UseDNS no // reverse resolution of IP addresses 6. Optimization of shell modification command history record # vi/etc/profile find HISTSIZE = 1000 to HISTSIZE = 100 and then source/etc/profile