: This article mainly introduces the nginx server system optimization. if you are interested in the PHP Tutorial, refer to it. 1 linux default core file size is 0
What is a core file? when a program crashes, the stored images of the process are copied to the core file in the current working directory of the process. The core file is only a memory image (with debugging information added) and is mainly used for debugging. The core file is a binary file, and a corresponding tool is required to analyze the memory image when the program crashes.
The default core file size is 0, so no file is created. You can use the ulimit command to view and modify the size of the core file.
$ Ulimit-c
0
$ Ulimit-c 1000
$ Ulimit-c
1000
-C specifies the size of the core file, and 1000 specifies the size of the core file. You can also limit the size of the core file, for example:
# Ulimit-c unlimited
# Ulimit-c
Unlimited
If you want the modification to take effect permanently, you need to modify the configuration file.
In Vim/etc/profile:
Ulimit-S-c 0>/dev/null 2> & 1
Change
Ulimit-S-c 1000>/dev/null 2> & 1
References: http://hi.baidu.com/jrckkyy/blog/item/2562320a5bdbc534b1351d95.html
2 In linux, the default values of open files and max user processes are 1024.
# Ulimit-n
1024
# Ulimit-u
1024
Problem Description: The server can open only 1024 files at the same time and process 1024 user processes.
You can use ulimit-a to view all the limit values of the current system, and use ulimit-n to view the maximum number of opened files.
By default, only 1024 of newly installed linux instances are installed. when used as a server with a large load, it is easy to encounter error: too program open files. Therefore, you need to increase it.
Solution:
You can use ulimit-n 65535 to modify it in real time, but it becomes invalid after restart. (Note that ulimit-SHn 65535 is equivalent to ulimit-n 65535.-S indicates soft and-H indicates hard)
There are three ways to modify it:
1. add a ulimit-SHn 65535 row in/etc/rc. local.
2. add a ulimit-SHn 65535 row in/etc/profile.
3. add the following content at the end of/etc/security/limits. conf:
* Soft nofile 65535
* Hard nofile 65535
* Soft nproc 65535
* Hard nproc 65535
Which of the following methods does not work in CentOS? in CentOS, 1st are effective, while in Debian, 3rd are effective.
# Ulimit-n
65535
# Ulimit-u
65535
Note: The ulimit command itself has soft and hard settings. adding-H is hard, and adding-S is soft. by default, soft restrictions are displayed.
The soft limit refers to the setting value that takes effect for the current system. The hard limit value can be reduced by common users. But cannot be added. Soft restrictions cannot be set more than hard restrictions. Only root users can increase the hard limit value.
3. a large number of connections in the TIME_WAIT status are found.
Problem Description: found a large number of connections in the time_wait status, sometimes even more than 7000
Netstat-n | awk '/^ tcp/{++ state [$ NF]} END {for (key in state) print key, "t", state [key]}'
Find more time_wait connections
Netstat-n | grep TIME_WAIT | awk '{print $5}' | sort | uniq-c | sort-rn | head-n20
It is found that mysql and memcache of the DB server are not released.
Solution: for a large number of applications that use tcp connections, you also need to optimize the parameters in/etc/sysctl. conf:
Vim/etc/sysctl. conf
Edit the file and add the following content:
Net. ipv4.tcp _ syncookies = 1
Net. ipv4.tcp _ tw_reuse = 1
Net. ipv4.tcp _ tw_recycle = 1
Net. ipv4.tcp _ fin_timeout = 30
Then run/sbin/sysctl-p to make the parameter take effect.
After optimization:
It is found that a large number of TIME_WAIT instances do not exist, and the usage of mysql processes quickly drops.
The above introduces the nginx server system optimization, including some content, and hope to be helpful to friends who are interested in the PHP Tutorial.