ShuDudu's Home was started in 2011, but the web data is lost, so now begin again, I would like to make some friends, I hope you like ShuDudu's home.
Current position: ShuDudu > Net Web >

CentOS / Ubuntu / Debian speed optimization guide (journal article)

Wednesday on February 5th, 2020Net Web

Preface: This article is part of violence optimize the system, the reader may cause discomfort, do not imitate.

Everyone's VPS generally faster, not because already optimized, but because of the high performance of the server itself, even without optimization, impact on the speed is also smaller. But what if the re-optimization is not a play to make the server for better performance?

Please look at/var/log/btmp file is not already reached tens of M, the hundreds of M? This file is easy to rapid growth, is a killer server performance, first of all can delete this file. The default file system errors, is turned on, the Internet also can not find its way to completely shut down. Measures must be there, just find a way to take some time.

A decade ago, most people use Windows server; now due to the open-source Linux system for free, the cost is greatly reduced, so the vast majority of people blog, Web sites use Linux server systems. Linux system is divided into CentOS, Ubuntu, Debian and other systems. Which, Ubuntu and Debian commands are exactly the same software environment, most cases can be considered the same system. In addition, there are other existing Linux systems, many of which are respectively CentOS, Ubuntu's command, the same software environment.

Therefore, as long as CentOS, Ubuntu, for example, other systems are completely the same token, such as Debian system can be completely Ubuntu way this article describes. The easiest way to distinguish, if you install the software, or update command begins with yum, CentOS is similar to the system; if begins with apt-get, is similar to the Ubuntu system.

CentOS and Ubuntu different systems, closed/var/log/btmp file method. The method is very simple CentOS, Ubuntu does not work the same way, we can only use the "violence".

CentOS CentOS system or class ::

CentOS 6 run this command to close btmp file:

killall -9 rsyslogd

CentOS 5 Run this command to close btmp file:

killall -9 syslogd

Description: CentOS 7 did not have time to test, in theory, should be the same as CentOS 6. This command after each restart will fail, need to run it again. To prevent forget, or be forced to restart the server for some reason, you can put this command to write boot from Kai file. I tested a few days ago, direct write, still does not take effect. The solution is to use sleep latency statement, it turned three minutes before running this command can take effect under CentOS.

But sleep process, not cleared automatically, so you need coupled with a killall -9 statement to kill the sleep process.

The sleep statement, if the direct write sleep 180, still does not take effect. After I changed it to sleep 60; sleep 120 ;, most of the time in force.

: Edit the /etc/rc.local file of CentOS. Exit 0 if this statement, this line must be deleted.

CentOS 6 or 7 add this line:

sleep 60; sleep 120; killall -9 rsyslogd; killall -9 sleep;

CentOS 5 add this line:

sleep 60; sleep 120; killall -9 syslogd; killall -9 sleep;

Ubuntu Ubuntu system or class:

In theory and use the same method CentOS, it can take effect, but actually totally ineffective, because rsyslogd after the end of the process, immediately automatically generate a new rsyslogd process. Only with "violent" approach, this violence is to modify the file system may produce a fatal error, tested, good site is currently running Ubuntu 14 paper, for example.

Try Step 1:

/ Usr/sbin/rsyslogd rsyslogd this file will be renamed.

Restart VPS, the command:

reboot

After the discovery, although rsyslogd process automatically and permanently disappear, but the/var/log/btmp file is continuing to increase, indicating that Ubuntu system even without the rsyslogd process, this file is still increasing. The CentOS system, after my two years of testing, as long as no rsyslogd, syslogd process, this document is not increased.

Try Step 2:

Finally, just put/var/log directory changed its name changed to/var/log2, restart the VPS, the whole world is quiet, well-run website, no fatal errors.

Important log Apache, Nginx, PHP optimization:

The default log file is entirely open, and will soon become very great, it is the killer server performance. These documents, including access logs, error logs. If there is no special need, we recommend these log files are closed. Unless a website error debugging period, debugged closed as soon as possible.

This part of the future I will write a complete guide gradually, because of time, here briefly explain. First open/var/log directory, Apache, Nginx path in CentOS, Ubuntu under different, but the same token, such a directory such as:

/ Var/log/httpd

/ Var/log/apache2

/ Var/log/nginx

/ Var/log/php-fpm

Mainly in the four directory. Open these directories, all log files, some files are not so huge it? Among them, the file name with "error", error logs; with "access", as the access log. Open the error file, you will find there are a lot of unrelated statements, such as spiders will visit a large number of files that do not exist on the site, which will be written to the error log.

Mainly because I use Apache, Nginx log so close method temporarily vacant, please search, often monitor these log files, and clean up.

Close method Apache error log, online mostly to the line on the Apache configuration file delete, or add notes. But in fact does not work, the correct approach is, CentOS + Apache, Ubuntu + Apache read this line:

ErrorLog Off

Access log, as long as with the CustomLog logs/access_log remove the line will be able to play a role, for example, delete these two lines:

#CustomLog logs/access_log common

CustomLog logs/access_log combined

Modify the php.ini file:

CentOS/Ubuntu + path Apache/Nginx of php.ini are different. Path to name a few:

/etc/php.ini (CentOS + Apache + PHP, or CentOS + Nginx + PHP)

/etc/php5/apache2/php.ini (Ubuntu + Apache + PHP)

/etc/php5/fpm/php.ini (Ubuntu + Nginx + PHP)

Find this line in php.ini: log_errors. The default value is On, the following:

log_errors = Off

Restart Apache.

Ubuntu + Apache or Class Ubuntu + Apache:

Ubuntu + Apache, but also more /var/log/apache2/other_vhosts_access.log of a file, the file will continue to grow. The solution is:

/etc/apache2/conf-available/other-vhosts-access-log.conf in this line:

CustomLog $ {APACHE_LOG_DIR} /other_vhosts_access.log vhost_combined this line delete, or add # in front of the line

Restart Apache.

Is not it a bit complicated? That is not complicated. Practice a few times, and make key notes of the machine, each as long as 10 minutes to get. VPS, easy to use too much than web hosting, web hosting is because these logs can not be closed.

2018-11-13 12:19 UPDATE:

Why CentOS 6 rsyslogd way without deleting files? Path is/sbin/rsyslogd.

Rsyslogd delete files, only applies to Ubuntu, Ubuntu class system.

CentOS deleted this file, restart the VPS, the site will be inaccessible today test for half an hour, restart Apache does not work, so the CentOS system rsyslogd, syslogd file can not be deleted, only with the end of the process the way.

2018-11-13 17:49 UPDATE:

Why the title of "happiness too fast"? Because almost total abandonment to use Ubuntu system (I like to use to optimize the system), rsyslogd process Ubuntu system with killall -9 command after the end of the process, it will soon be popped rsyslogd, which can not prevent/var/log/btmp increased file. Was thinking to solve this problem at least have to debug six months, I did not expect less than half an hour debugging a solution to solve a big problem. So, happiness is too fast!

Copyright Protection: ShuDudu from the original article, reproduced Please keep the link: https://www.shududu.com/netweb/CentOS-Ubuntu-Debian-speed-optimization-guide-journal-article.htm