{"id":237,"date":"2021-07-28T13:23:33","date_gmt":"2021-07-28T05:23:33","guid":{"rendered":"http:\/\/egonlin.com\/?p=237"},"modified":"2024-05-01T12:30:06","modified_gmt":"2024-05-01T04:30:06","slug":"linux%e6%93%8d%e4%bd%9c%e7%b3%bb%e7%bb%9f%e4%bc%98%e5%8c%96","status":"publish","type":"post","link":"https:\/\/egonlin.com\/?p=237","title":{"rendered":"linux\u64cd\u4f5c\u7cfb\u7edf\u4f18\u5316"},"content":{"rendered":"<p>Linux\u64cd\u4f5c\u7cfb\u7edf\u4f18\u5316<\/p>\n<h1>\u4e00\u3001\u4f18\u5316\u663e\u793a\u8f93\u51fa<\/h1>\n<p>vim \/etc\/bashrc \u8fdb\u5165bashrc\u6587\u4ef6 \u6309\u4e0b41gg \u8df3\u8f6c\u6587\u4ef6\u768441\u884c \u6309\u4e0bi\u952e\u8fdb\u5165\u7f16\u8f91\u6a21\u5f0f\uff0c\u8f93\u5165#\uff0c\u6ce8\u91ca\u5f53\u524d\u884c\uff0c\u5149\u6807\u79fb\u52a8\u5230#\u53f7\u524d\uff0c\u6309\u4e0b\u56de\u8f66\u952e\u7a7a\u51fa\u5f53\u524d41\u884c\u5185\u5bb9\uff0c\u800c\u540e\u5149\u6807\u79fb\u52a8\u523041\u884c\uff08\u7a7a\u884c\u4f4d\u7f6e\uff09\uff0c\u7c98\u8d34\u53c2\u6570\u3002\u800c\u540e\u6309\u4e0bESC\u952e\uff0c\u9000\u51fa\u7f16\u8f91\u6a21\u5f0f\uff0c\u6309\u4e0bSHIFT+; wq \u4fdd\u5b58\u9000\u51fa<\/p>\n<pre><code>[ \"$PS1\" = \"\\\\s-\\\\v\\\\\\$ \" ] &amp;&amp; PS1=\"[\\[\\e[34;1m\\]\\u@\\[\\e[0m\\]\\[\\e[32;1m\\]\\H\\[\\e[0m\\] \\[\\e[31;1m\\]\\w\\[\\e[0m\\]]\\\\$ \"<\/code><\/pre>\n<p>\u6216\u8005\u7528\u4e0b\u9762\u65b9\u6cd5\u4e5f\u4e00\u6837<\/p>\n<pre><code>#\u8bbe\u7f6e\r\ncat&gt;\/etc\/profile.d\/color.sh&lt;&lt;'EOF'\r\nalias ll='ls -l --color=auto --time-style=long-iso'\r\nPS1=\"\\[\\e[37;40m\\][\\[\\e[32;1m\\]\\u\\[\\e[37;40m\\]@\\\\h \\[\\e[36;40m\\]\\w\\[\\e[0m\\]]\\[\\e[32;1m\\]\\\\$ \\[\\e[0m\\]\"\r\nexport HISTTIMEFORMAT='%F-%T ' \r\nEOF\r\n\r\n#\u751f\u6548\r\n[root@egon ~]# source  \/etc\/profile<\/code><\/pre>\n<h1>\u4e8c\u3001\u767b\u5f55\u548c\u6b22\u8fce\u4fe1\u606f<\/h1>\n<pre><code class=\"language-python\">\/etc\/motd               \u767b\u5f55\u6210\u529f\u540e\u663e\u793a\u7684\u4fe1\u606f<\/code><\/pre>\n<p>\u793a\u4f8b<\/p>\n<pre><code class=\"language-python\">[root@localhost ~]# cat \/etc\/motd \r\n+--------------------------------------------+\r\n|                                            |\r\n|    \u4f60\u5f53\u524d\u767b\u5f55\u7684\u662f\u652f\u4ed8\u4e1a\u52a1\u540e\u53f0\u6570\u636e\u5e93\u670d\u52a1    |\r\n|    \u8bf7\u4e0d\u8981\u5220\u5e93                              |\r\n|                                            |\r\n+--------------------------------------------+<\/code><\/pre>\n<p>\u4e86\u89e3<\/p>\n<pre><code class=\"language-python\">\u901a\u5e38\u6211\u4eec\u4f1a\u6e05\u7a7a\/etc\/issue\u3001\/etc\/issue.net\u7684\u5185\u5bb9\uff0c\u53bb\u9664\u7cfb\u7edf\u53ca\u5185\u6838\u7248\u672c\u767b\u5f55\u524d\u7684\u5c4f\u5e55\u663e\u793a\r\n\r\n\/etc\/issue              \u767b\u5f55\u753b\u9762\u663e\u793a\u7684\u4fe1\u606f(\u91cd\u542f\u673a\u5668\u540e\uff0c\u5728\u672c\u673a\u770b\u5230\u7684\u767b\u5f55\u754c\u9762\u5185\u5bb9)\r\n\/etc\/issue.net          \u5b83\u63d0\u4f9b\u7ed9telnet\u8fdc\u7a0b\u767b\u5f55\u7a0b\u5e8f\u4f7f\u7528\u7684\u3002\u9ed8\u8ba4\u60c5\u51b5\u4e0b\/etc\/issue\u6587\u4ef6\u548c\/etc\/issue.Net\u5185\u5bb9\u4e00\u6837\uff0c\u5982\u9700\u8981\uff0c\u53ef\u6839\u636e\u81ea\u5df1\u9700\u8981\u4fee\u6539\u3002\r\n\r\n$ telnet 192.168.12.17 22  # \u6d4b\u8bd5\u7aef\u53e3\r\nTrying 192.168.12.17...\r\nConnected to 192.168.12.17.\r\nEscape character is '^]'. -----\u300b\u8868\u793a\u5df2\u6253\u5f00,\u5176\u4ed6\u60c5\u51b5\u8868\u793a\u7aef\u53e3\u672a\u6253\u5f00\r\nSSH-2.0-OpenSSH_7.4\r\n^]\r\ntelnet&gt; quit\r\n\r\nps: telnet\u7531\u4e8e\u4e0d\u5b89\u5168\u5df2\u7ecf\u5f88\u5c11\u4f7f\u7528\u4e86\uff0c\u90fd\u662f\u4ee5ssh\u4ee3\u66ff\u3002<\/code><\/pre>\n<h1>\u4e09\u3001\u914d\u7f6eyum\u4ed3\u5e93\u4e0e\u5305\u66f4\u65b0<\/h1>\n<p>\u4e00\uff1a\u5148\u5728\u6d4b\u8bd5\u73af\u5883\uff0c\u914d\u7f6e\u597dyum\u6e90<\/p>\n<pre><code>\u9ed8\u8ba4\u56fd\u5916\u7684yum\u6e90(\u8f6f\u4ef6\u4ed3\u5e93)\u6bd4\u8f83\u6162\uff0c\u6240\u4ee5\u6362\u6210\u56fd\u5185\u7684\u3002\r\n# 1.1\u3001\u5907\u4efd\r\n[root@egon ~]# mv \/etc\/yum.repos.d\/CentOS-Base.repo \/etc\/yum.repos.d\/CentOS-Base.repo.backup\r\n\r\n# 1.2\u3001\u4e0b\u8f7d\u65b0\u7684CentOS-Base.repo \u5230\/etc\/yum.repos.d\/\r\n[root@egon ~]# curl -o \/etc\/yum.repos.d\/CentOS-Base.repo http:\/\/mirrors.aliyun.com\/repo\/Centos-7.repo\r\n\r\n# 1.3.\u6dfb\u52a0epel\u6e90\r\n[root@egon ~]# curl -o \/etc\/yum.repos.d\/epel.repo http:\/\/mirrors.aliyun.com\/repo\/epel-7.repo<\/code><\/pre>\n<p>\u4e8c\uff1a\u521a\u88c5\u673a\u540e\u6267\u884cyum upgrade -y<\/p>\n<pre><code>[root@egon ~]# yum upgrade -y  # \u521a\u88c5\u5b8c\u7cfb\u7edf\u540e\u5c31\u7acb\u5373\u6267\u884c\uff0c\u65e5\u540e\u5c31\u4e0d\u8981\u8f7b\u6613\u66f4\u65b0\u4e86\r\n\r\n\u590d\u4e60\uff1a\r\n            \u5728 CentOS 7 \u4e2d\uff0cyum update \u548c yum upgrade \r\n            1\u3001\u76f8\u540c\u70b9\uff1a\u90fd\u4f1a\u66f4\u65b0\u6240\u6709\u5305\uff08\u5305\u62ec\u8f6f\u4ef6\u4e0e\u5185\u6838\uff09\r\n            2\u3001\u4e0d\u540c\u70b9\r\n            yum update\u66f4\u65b0\u7684\u65f6\u5019\u4f1a\u4fdd\u7559\u8fc7\u65f6\u7684\u5305\uff0c\u8fd9\u5bf9\u4f9d\u8d56\u8001\u5305\u7684\u5e94\u7528\u5f88\u53cb\u597d\r\n            yum upgrade\u66f4\u65b0\u7684\u65f6\u5019\u4f1a\u5220\u9664\u8fc7\u65f6\u7684\u5305\uff0c\u5982\u679c\u4f60\u7cfb\u7edf\u4e2d\u6240\u6709\u7684\u5e94\u7528\u5168\u90fd\u4e3arpm\r\n            \u5305\uff0c\u90a3upgrade\u5012\u662f\u4e0d\u4f1a\u5bf9\u4f60\u6709\u5f71\u54cd\uff0c\u56e0\u4e3a\u90fd\u4f1a\u4e00\u8d77\u8ddf\u7740\u66f4\u65b0\u3002\u4f46\u662f\u5982\u679c\u4f60\r\n            \u5b89\u88c5\u7684\u5305\u91cc\u6709\u81ea\u5df1\u7f16\u8bd1\u5b89\u88c5\u7684\uff0c\u800c\u7f16\u8bd1\u5b89\u88c5\u7684\u5305\u4f1a\u4f9d\u8d56\u67d0\u4e2a\u7279\u5b9a\u7248\u672c\u7684rpm\u5305\r\n            \u90a3upgrade\u5347\u7ea7\u4e4b\u540e\uff0c\u5f88\u6709\u53ef\u80fd\u4f1a\u9020\u6210\u4f60\u7f16\u8bd1\u5b89\u88c5\u5305\u7684\u4e0d\u53ef\u7528\r\n\r\n            \u7efc\u4e0a\uff0c\u5982\u679c\u662f\u521a\u88c5\u7cfb\u7edf\uff0c\u90a3\u5c31\u7528upgrade\uff0c\u5426\u5219\u8fd8\u662f\u7528update\u9760\u8c31\u4e9b\r\n\r\n            \u5728rockylinux\u4e2d\uff0cyum\u547d\u4ee4\u90fd\u94fe\u63a5\u5230\u4e86dnf-3\u4e0a\r\n            \u800c\u5728 DNF \u4e2d\uff0c\uff0c\u5728dnf-3\u4e2d\uff0cdnf update \u4e0e dnf upgrade \u662f\u6ca1\u6709\u533a\u522b\u7684\u3002\r\n            \u5177\u4f53\u800c\u8a00\uff0c\u4e24\u8005\u90fd\u662f\u7528\u4e8e\u66f4\u65b0\u7cfb\u7edf\u4e0a\u5df2\u7ecf\u5b89\u88c5\u7684\u8f6f\u4ef6\u5305\u5230\u6700\u65b0\u53ef\u7528\u7248\u672c\r\n<\/code><\/pre>\n<p>\u4e09\u3001\u5b89\u88c5\u4e00\u4e9b\u5e38\u7528\u7684\u5e93<\/p>\n<pre><code>yum install net-tools vim tree htop iftop iotop  bash-completion bash-completion-extras lrzsz sysstat sl lsof unzip telnet nmap nc psmisc dos2unix bash-completion wget  nethogs ntpdate nfsutils rsync glances gcc gcc-c++ glibc yum-utils httpd-tools -y\r\n\r\nyum -y install tree nmap sysstat lrzsz  telnet bash-completion bash-completion-extras vim  lsof  net-tools rsync ntpdate nfs-utils<\/code><\/pre>\n<p>\u56db\u3001\u5236\u4f5c\u81ea\u5df1\u7684yum\u6e90<br \/>\n\u5982\u679c\u4f60\u6b63\u5728\u6d4b\u8bd5\u73af\u5883\u91cc\u6f14\u7ec3\uff0c\u5b8c\u6210\u540e\u518d\u90e8\u751f\u4ea7\u73af\u5883<br \/>\n\u90a3\u4e48\u4f60\u5e94\u8be5\u5728\u6d4b\u8bd5\u73af\u5883\u6253\u5f00yum\u7f13\u5b58\uff0c\u5c06yum install\u6216update\u7684\u5305\u90fd\u7f13\u5b58\u4e0b\u6765\uff0c\u7136\u540e\u505a\u6210\u81ea\u5df1\u7684yum\u6e90\u5e26\u5230\u751f\u4ea7\u73af\u5883\uff0c\u4ee5\u786e\u4fdd\u7248\u672c\u53ef\u63a7<\/p>\n<h1>\u56db\u3001\u89c4\u8303\u7cfb\u7edf\u4e3b\u673a\u540d<\/h1>\n<pre><code class=\"language-python\">hostnamectl set-hostname \u4e3b\u673a\u540d  # \u4e3b\u673a\u540d\u80fd\u591f\u53cd\u6620\u51fa\u4e3b\u673a\u7684\u4f5c\u7528\u5373\u53ef<\/code><\/pre>\n<h1>\u4e94\u3001\u6dfb\u52a0hosts\u6587\u4ef6\u5b9e\u73b0\u96c6\u7fa4\u4e3b\u673a\u4e4b\u95f4\u76f8\u4e92\u7528\u4e3b\u673a\u540d\u89e3\u6790<\/h1>\n<pre><code class=\"language-python\">vim \/etc\/hosts  # \u7f16\u8f91\u597d\u4e4b\u540e\uff0c\u6bcf\u53f0\u673a\u5668\u90fd\u53d1\u4e00\u4efd\r\n\r\n172.16.10.11 nc1 ceph-deploy\r\n\r\n172.16.10.12 nc2\r\n\r\n172.16.10.13 nc3\r\n\r\n172.16.10.14 cs1\r\n\r\n172.16.10.15 cs2\r\n\r\n172.16.10.16 cs3<\/code><\/pre>\n<h1>\u516d\u3001\u5173\u95edSELinux<\/h1>\n<pre><code>    SELinux\uff08Security-Enhanced Linux\uff09\u662f\u7f8e\u56fd\u56fd\u5bb6\u5b89\u5168\u5c40\uff08NSA\uff09\u5bf9\u4e8e\u5f3a\u5236\u8bbf\u95ee\u63a7\u5236\u7684\u5b9e\u73b0\uff0c\u8fd9\u4e2a\u529f\u80fd\u8ba9\u7cfb\u7edf\u7ba1\u7406\u5458\u53c8\u7231\u53c8\u6068\uff0c\u8fd9\u91cc\u6211\u4eec\u8fd8\u662f\u628a\u5b83\u7ed9\u5173\u95ed\u4e86\u5427\uff0c\u81f3\u4e8e\u5b89\u5168\u95ee\u9898\uff0c\u540e\u9762\u901a\u8fc7\u5176\u4ed6\u624b\u6bb5\u6765\u89e3\u51b3\uff0c\u8fd9\u4e5f\u662f\u5927\u591a\u6570\u751f\u4ea7\u73af\u5883\u7684\u505a\u6cd5\uff0c\u5982\u679c\u975e\u8981\u5f00\u542f\u4e5f\u662f\u53ef\u4ee5\u7684\u3002\r\n\r\n#\u4e34\u65f6\u5173\u95ed\r\n[root@egon ~]# setenforce  0\r\n\r\n#\u6c38\u4e45\u5173\u95ed,\u4fee\u6539\u5b8c\u914d\u7f6e\u540e\u91cd\u542f\u4e3b\u673a\r\n[root@egon ~]# sed 's#SELINUX=enforcing#SELINUX=disabled#g' \/etc\/selinux\/config\r\n\r\n#\u68c0\u67e5\u7ed3\u679c\r\n[root@egon ~]# grep \"disabled\" \/etc\/selinux\/config<\/code><\/pre>\n<h1>\u4e03\u3001\u5173\u95ed\u9632\u706b\u5899\uff08Firewalld\uff09<\/h1>\n<pre><code>    \u5173\u95ed\u9632\u706b\u5899\u7684\u76ee\u7684\u662f\u4e3a\u4e86\u8ba9\u521d\u5b66\u8005\u5b66\u4e60\u66f4\u65b9\u4fbf\uff0c\u5c06\u6765\u5728\u5b66\u4e86Firewalld\u6280\u672f\u540e\u53ef\u518d\u7edf\u4e00\u5f00\u542f\u3002 \u5728\u4f01\u4e1a\u73af\u5883\u4e2d\uff0c\u4e00\u822c\u53ea\u6709\u914d\u7f6e\u5916\u7f51IP\u7684linux\u670d\u52a1\u5668\u624d\u9700\u8981\u5f00\u542f\u9632\u706b\u5899\uff0c\u4f46\u5373\u4f7f\u662f\u6709\u5916\u7f51IP\uff0c\u5bf9\u4e8e\u9ad8\u5e76\u53d1\u9ad8\u6d41\u91cf\u7684\u4e1a\u52a1\u670d\u52a1\u5668\u4ecd\u662f\u4e0d\u80fd\u5f00\u7684\uff0c\u56e0\u4e3a\u4f1a\u6709\u8f83\u5927\u6027\u80fd\u635f\u5931\uff0c\u5bfc\u81f4\u7f51\u7ad9\u8bbf\u95ee\u5f88\u6162\uff0c\u8fd9\u79cd\u60c5\u51b5\u4e0b\u53ea\u80fd\u5728\u524d\u7aef\u52a0\u66f4\u597d\u7684\u786c\u4ef6\u9632\u706b\u5899\u4e86\u3002\r\n\r\n# \u4e34\u65f6\u5173\u95ed\r\n[root@egon ~]# systemctl  stop firewalld\r\n\r\n# \u8bbe\u7f6e\u5f00\u673a\u4e0d\u542f\u52a8\r\n[root@egon ~]# systemctl  disable  firewalld\r\n\r\niptables -t raw -F # \u6e05\u7a7a\u89c4\u5219\r\niptables -t mangle -F # \u6e05\u7a7a\u89c4\u5219\r\niptables -t nat -F # \u6e05\u7a7a\u89c4\u5219\r\niptables -t filter -F # \u6e05\u7a7a\u89c4\u5219<\/code><\/pre>\n<h1>\u516b\u3001\u914d\u7f6e\u81ea\u52a8\u540c\u6b65\u65f6\u95f4<\/h1>\n<p>\u5bf9\u4e8eCentOS 7.9\u53ca\u4ee5\u540e\u7684\u7248\u672c\uff0cChrony\u662f\u9ed8\u8ba4\u7684\u7f51\u7edc\u65f6\u95f4\u670d\u52a1\u3002CentOS 7.9\u53ca\u4ee5\u540e\u7684\u7248\u672c\u9ed8\u8ba4\u5df2\u7ecf\u5b89\u88c5\u4e86Chrony\uff0c\u5982\u679c\u672a\u5b89\u88c5\uff0c\u53ef\u4ee5\u901a\u8fc7yum install chrony\u547d\u4ee4\u8fdb\u884c\u5b89\u88c5\u3002<br \/>\nChrony\u63d0\u4f9b\u4e86\u4e00\u4e2a\u540d\u4e3achronyc\u7684\u547d\u4ee4\u884c\u5de5\u5177\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u8fd9\u4e2a\u5de5\u5177\u6765\u68c0\u67e5Chrony\u7684\u72b6\u6001\uff0c\u6bd4\u5982\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u8fd0\u884cchronyc sources\u6765\u67e5\u770b\u5f53\u524d\u6b63\u5728\u4f7f\u7528\u7684\u65f6\u95f4\u6e90\u3002<br \/>\n\u4e86\u89e3chronyd\u4e0entpd\u7684\u533a\u522b<\/p>\n<pre><code>Linux\u91cc\u9762chrony\u548cntp\u533a\u522b\u662f\uff1a\r\n1.\u5b9e\u73b0\u65b9\u5f0f\u4e0d\u540c\uff1b\r\n2.\u7cbe\u5ea6\u548c\u7a33\u5b9a\u6027\u4e0d\u540c\uff1b\r\n3.\u7cfb\u7edf\u8d44\u6e90\u6d88\u8017\u4e0d\u540c\uff1b\r\n4.\u914d\u7f6e\u65b9\u6cd5\u4e0d\u540c\u3002\u5b9e\r\n\u73b0\u65b9\u5f0f\u4e0d\u540c\u5728\u4e8e\uff0cchrony\u4f7f\u7528\u4e00\u79cd\u79f0\u4e3a\u201d\u65f6\u95f4\u6ee4\u6ce2\u201d\u7684\u6280\u672f\uff0c\r\n\u800cntp\u57fa\u4e8eUDP\u534f\u8bae\u7684\u5ba2\u6237\u7aef-\u670d\u52a1\u5668\u67b6\u6784\u7684\u534f\u8bae\uff0c\u4f7f\u7528\u7684\u662f\u4f20\u7edf\u7684\u65f6\u95f4\u540c\u6b65\u7b97\u6cd5\u3002\r\n\r\n1.\u5b9e\u73b0\u65b9\u5f0f\u4e0d\u540c\r\nchrony\u662f\u4e00\u79cd\u76f8\u5bf9\u8f83\u65b0\u7684\u65f6\u95f4\u540c\u6b65\u5de5\u5177\uff0c\u5b83\u91c7\u7528\u4e00\u79cd\u79f0\u4e3a\u201d\u65f6\u95f4\u6ee4\u6ce2\u201d\u7684\u6280\u672f\uff0c\r\n\u901a\u8fc7\u4f30\u8ba1\u65f6\u949f\u6f02\u79fb\u7387\uff0c\u5e73\u6ed1\u65f6\u949f\u8df3\u53d8\u548c\u6296\u52a8\uff0c\u6765\u63d0\u9ad8\u65f6\u949f\u540c\u6b65\u7684\u7cbe\u5ea6\u548c\u7a33\u5b9a\u6027\u3002\r\n\r\nntp\u662f\u4e00\u79cd\u8f83\u4e3a\u4f20\u7edf\u7684\u65f6\u95f4\u540c\u6b65\u5de5\u5177\uff0c\u5b83\u57fa\u4e8eUDP\u534f\u8bae\u7684\u5ba2\u6237\u7aef-\u670d\u52a1\u5668\u67b6\u6784\u7684\u534f\u8bae\uff0c\r\n\u901a\u5e38\u4f7f\u7528\u4f20\u7edf\u7684\u7f51\u7edc\u65f6\u95f4\u670d\u52a1\u5668\uff0c\u4f8b\u5982ntp\u5b98\u65b9\u63d0\u4f9b\u7684\u516c\u5171\u65f6\u95f4\u670d\u52a1\u5668\u6216\u8005\u5176\u4ed6\u7f51\u7edc\u4e2d\u7684\u65f6\u95f4\u670d\u52a1\u5668\uff0c\r\n\u5ba2\u6237\u7aef\u5411\u670d\u52a1\u5668\u53d1\u9001\u65f6\u95f4\u540c\u6b65\u8bf7\u6c42\uff0c\u670d\u52a1\u5668\u8fd4\u56de\u5f53\u524d\u65f6\u95f4\u5e76\u901a\u8fc7ntp\u534f\u8bae\u8fdb\u884c\u65f6\u95f4\u6821\u51c6\u3002\r\n\r\n2.\u7cbe\u5ea6\u548c\u7a33\u5b9a\u6027\u4e0d\u540c\r\nchrony\u76f8\u5bf9\u4e8entp\u6765\u8bf4\uff0c\u80fd\u591f\u63d0\u4f9b\u66f4\u9ad8\u7684\u7cbe\u5ea6\u548c\u66f4\u597d\u7684\u7a33\u5b9a\u6027\u3002chrony\u652f\u6301\u672c\u5730\u65f6\u949f\u7f13\u5b58\uff0c\r\n\u53ef\u4ee5\u5728\u6ca1\u6709\u7f51\u7edc\u8fde\u63a5\u65f6\u4f9d\u7136\u4fdd\u6301\u65f6\u949f\u7684\u7cbe\u5ea6\uff0c\u540c\u65f6\u53ef\u4ee5\u5feb\u901f\u9002\u5e94\u7f51\u7edc\u5ef6\u8fdf\u548c\u65f6\u949f\u6f02\u79fb\u3002\r\n\u6b64\u5916\uff0c\u5b83\u8fd8\u652f\u6301\u5feb\u901f\u65f6\u949f\u6821\u51c6\u548c\u5b9e\u65f6\u65f6\u949f\u8865\u507f\u7b49\u529f\u80fd\u3002\r\n\r\n3.\u7cfb\u7edf\u8d44\u6e90\u6d88\u8017\u4e0d\u540c\r\nchrony\u5bf9\u7cfb\u7edf\u8d44\u6e90\u7684\u6d88\u8017\u76f8\u5bf9\u8f83\u5c11\uff0c\u5bf9\u4e8e\u8d44\u6e90\u6709\u9650\u7684\u7cfb\u7edf\u6765\u8bf4\u66f4\u4e3a\u9002\u5408\uff1b\r\n\u800cntp\u5219\u9700\u8981\u8f83\u591a\u7684\u7cfb\u7edf\u8d44\u6e90\uff0c\u5305\u62ecCPU\u3001\u5185\u5b58\u548c\u7f51\u7edc\u5e26\u5bbd\u7b49\uff0c\u76f8\u5bf9\u4e8echrony\u4f1a\u6d88\u8017\u66f4\u591a\u7684\u7cfb\u7edf\u8d44\u6e90\u3002\r\n\r\n4.\u914d\u7f6e\u65b9\u6cd5\u4e0d\u540c\r\nchrony\u7684\u914d\u7f6e\u76f8\u5bf9\u7b80\u5355\uff0c\u914d\u7f6e\u6587\u4ef6\u76f8\u5bf9\u8f83\u5c11\uff0c\u66f4\u52a0\u6613\u4e8e\u7ba1\u7406\u3002\u800cntp\u7684\u914d\u7f6e\u76f8\u5bf9\u590d\u6742\uff0c\r\n\u9700\u8981\u7f16\u8f91\u591a\u4e2a\u914d\u7f6e\u6587\u4ef6\u6765\u5b9e\u73b0\u4e0d\u540c\u7684\u529f\u80fd\u3002\r\n\r\n\u603b\u7684\u6765\u8bf4\uff0cchrony\u548cntp\u90fd\u662f\u4f18\u5f02\u7684\u65f6\u95f4\u540c\u6b65\u5de5\u5177\uff0c\u5728\u4e0d\u540c\u7684\u573a\u666f\u4e0b\u53ef\u4ee5\u9009\u7528\u4e0d\u540c\u7684\u5de5\u5177\u3002\r\n\u5982\u679c\u9700\u8981\u9ad8\u7cbe\u5ea6\u3001\u9ad8\u7a33\u5b9a\u6027\u4ee5\u53ca\u5bf9\u7cfb\u7edf\u8d44\u6e90\u7684\u6d88\u8017\u6709\u9650\uff0c\u5219\u53ef\u4ee5\u9009\u62e9chrony\uff1b\r\n\u5982\u679c\u5bf9\u7cbe\u5ea6\u8981\u6c42\u4e0d\u9ad8\uff0c\u800c\u4e14\u9700\u8981\u4e00\u4e9b\u6bd4\u8f83\u590d\u6742\u7684\u529f\u80fd\uff0c\u5219\u53ef\u4ee5\u9009\u62e9ntp\u3002<\/code><\/pre>\n<p>\u5927\u524d\u63d0\uff1achrony\u670d\u52a1\u7aef\u5ba2\u6237\u7aef\u914d\u7f6e\u5b8c\u540e\uff0c\u91cd\u542fchronyd\u670d\u52a1\u5373\u53ef\u5feb\u901f\u5b8c\u6210\u65f6\u95f4\u540c\u6b65\uff0c\u5728\u8fd9\u4e4b\u540e\u5c31\u4e0d\u8981\u518d\u624b\u52a8\u53bb\u4fee\u6539\u65f6\u95f4\u4e86\uff0c\u4e00\u5207\u8ba9\u65f6\u95f4\u670d\u52a1\u5668\u81ea\u5df1\u53bb\u540c\u6b65<\/p>\n<p>chrony\u670d\u52a1\u7aef\uff1a\u670d\u52a1\u7aef\u6211\u4eec\u53ef\u4ee5\u81ea\u5df1\u642d\u5efa\uff0c\u4e5f\u53ef\u4ee5\u76f4\u63a5\u7528\u516c\u7f51\u4e0a\u7684\u65f6\u95f4\u670d\u52a1\u5668\uff0c\u6240\u4ee5\u662f\u5426\u90e8\u7f72\u670d\u52a1\u7aef\u770b\u4f60\u81ea\u5df1<\/p>\n<pre><code># 1\u3001\u5b89\u88c5\r\nyum -y install chrony\r\n\u200b\r\n# 2\u3001\u4fee\u6539\u914d\u7f6e\u6587\u4ef6\r\nmv \/etc\/chrony.conf \/etc\/chrony.conf.bak\r\n\u200b\r\ncat &gt; \/etc\/chrony.conf &lt;&lt; EOF\r\nserver ntp1.aliyun.com iburst minpoll 4 maxpoll 10\r\nserver ntp2.aliyun.com iburst minpoll 4 maxpoll 10\r\nserver ntp3.aliyun.com iburst minpoll 4 maxpoll 10\r\nserver ntp4.aliyun.com iburst minpoll 4 maxpoll 10\r\nserver ntp5.aliyun.com iburst minpoll 4 maxpoll 10\r\nserver ntp6.aliyun.com iburst minpoll 4 maxpoll 10\r\nserver ntp7.aliyun.com iburst minpoll 4 maxpoll 10\r\ndriftfile \/var\/lib\/chrony\/drift\r\nmakestep 10 3\r\nrtcsync\r\nallow 0.0.0.0\/0\r\nlocal stratum 10\r\nkeyfile \/etc\/chrony.keys\r\nlogdir \/var\/log\/chrony\r\nstratumweight 0.05\r\nnoclientlog\r\nlogchange 0.5\r\n\r\nEOF\r\n\u200b\r\n# 4\u3001\u542f\u52a8chronyd\u670d\u52a1\r\nsystemctl restart chronyd.service # \u6700\u597d\u91cd\u542f\uff0c\u8fd9\u6837\u65e0\u8bba\u539f\u6765\u662f\u5426\u542f\u52a8\u90fd\u53ef\u4ee5\u91cd\u65b0\u52a0\u8f7d\u914d\u7f6e\r\nsystemctl enable chronyd.service\r\nsystemctl status chronyd.service\r\n<\/code><\/pre>\n<p>chrony\u5ba2\u6237\u7aef\uff1a\u5728\u9700\u8981\u4e0e\u5916\u90e8\u540c\u6b65\u65f6\u95f4\u7684\u673a\u5668\u4e0a\u5b89\u88c5\uff0c\u542f\u52a8\u540e\u4f1a\u81ea\u52a8\u4e0e\u4f60\u6307\u5b9a\u7684\u670d\u52a1\u7aef\u540c\u6b65\u65f6\u95f4<br \/>\n\u672c\u8d28\u4e0a\u7684\u914d\u7f6e\u4e0e\u4f60\u670d\u52a1\u7aef\u7684\u90fd\u4e00\u6837\uff0c\u65e0\u975e\u5c31\u662f\u6307\u5b9a\u8ddf\u54ea\u4e2a\u4e0a\u6e38\u65f6\u95f4\u670d\u52a1\u7aef\u540c\u6b65\u65f6\u95f4\uff0c\u4e5f\u5c31\u662f\u8bf4\u4f60\u5b89\u88c5\u4e86chrony\u5b83\u662f\u5373\u53ef\u5145\u5f53\u5ba2\u6237\u7aef\u4e5f\u53ef\u4ee5\u5145\u5f53\u670d\u52a1\u7aef\u7684<br \/>\n\u5982\u679c\u4f60\u6ca1\u6709\u81ea\u5df1\u7684\u65f6\u95f4\u670d\u52a1\u5668\u670d\u52a1\u7aef\uff0c\u90a3\u4e0b\u9762\u7684\u914d\u7f6e\u4e2dserver\u4f60\u5b8c\u5168\u53ef\u4ee5\u6307\u5b9a\u4e00\u4e9b\u516c\u5171\u7684\u65f6\u95f4\u670d\u52a1\u5668\uff0c\u4f8b\u5982<\/p>\n<pre><code>\u4e2d\u56fd\u5927\u9646\u5730\u533a\u7684NTP\u670d\u52a1\u5668\r\nntp1.aliyun.com\r\nntp2.aliyun.com\r\nntp3.aliyun.com\r\nntp4.aliyun.com\r\nntp5.aliyun.com\r\nntp6.aliyun.com\r\nntp7.aliyun.com\r\n\r\nntp1.chinacloud.com.cn\r\n\r\nntp2.chinacloud.com.cn\r\n\r\nntp3.chinacloud.com.cn\r\n\r\ncn.pool.ntp.org\r\n\r\n\u516c\u7f51\u65f6\u95f4\u670d\u52a1\u5668\u5927\u5168\uff1ahttps:\/\/blog.csdn.net\/weixin_42588262\/article\/details\/82501488<\/code><\/pre>\n<p>\u516c\u7f51\u670d\u52a1\u5668\u914d\u56fe<br \/>\n<div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/egonlin.com\/wp-content\/uploads\/2021\/07\/image-1710815273592.png'><img class=\"lazyload lazyload-style-2\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  data-original=\"https:\/\/egonlin.com\/wp-content\/uploads\/2021\/07\/image-1710815273592.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"file\" \/><\/div><\/p>\n<p>\u6211\u4eec\u7684chronyd\u5ba2\u6237\u7aef\u914d\u7f6e\u5982\u4e0b<\/p>\n<pre><code># \u4e0b\u8ff0\u6b65\u9aa4\u4e00\u6b21\u6027\u7c98\u8d34\u5230\u6bcf\u4e2a\u5ba2\u6237\u7aef\u6267\u884c\u5373\u53ef\r\n# 1\u3001\u5b89\u88c5chrony\r\nyum -y install chrony\r\n# 2\u3001\u9700\u6539\u5ba2\u6237\u7aef\u914d\u7f6e\u6587\u4ef6\r\nmv \/etc\/chrony.conf \/etc\/chrony.conf.bak\r\ncat &gt; \/etc\/chrony.conf &lt;&lt; EOF\r\nserver \u670d\u52a1\u7aef\u7684ip\u5730\u5740\u6216\u53ef\u89e3\u6790\u7684\u4e3b\u673a\u540d iburst\r\ndriftfile \/var\/lib\/chrony\/drift\r\nmakestep 10 3\r\nrtcsync\r\nlocal stratum 10\r\nkeyfile \/etc\/chrony.key\r\nlogdir \/var\/log\/chrony\r\nstratumweight 0.05\r\nnoclientlog\r\nlogchange 0.5\r\n\r\nEOF\r\n# 3\u3001\u542f\u52a8chronyd\r\nsystemctl restart chronyd.service\r\nsystemctl enable chronyd.service\r\nsystemctl status chronyd.service\r\n\r\n# 4\u3001\u9a8c\u8bc1\r\nchronyc sources -v  # \u7ed3\u679c\u89e3\u6790\u5982\u4e0b\u56fe<\/code><\/pre>\n<p><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/egonlin.com\/wp-content\/uploads\/2021\/07\/image-1710815397197.png'><img class=\"lazyload lazyload-style-2\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  data-original=\"https:\/\/egonlin.com\/wp-content\/uploads\/2021\/07\/image-1710815397197.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"file\" \/><\/div><br \/>\n\u6bcf\u4e00\u5217\u7684\u542b\u4e49<br \/>\n<div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/egonlin.com\/wp-content\/uploads\/2021\/07\/image-1710815411039.png'><img class=\"lazyload lazyload-style-2\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  data-original=\"https:\/\/egonlin.com\/wp-content\/uploads\/2021\/07\/image-1710815411039.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"file\" \/><\/div><\/p>\n<p>centos6\u3001centos7.9\u4e2d\u4e5f\u53ef\u4ee5\u7528ntpdate\u547d\u4ee4\uff08\u4e86\u89e3\u5373\u53ef\uff09<\/p>\n<pre><code>yum install ntpdate -y # \u5b89\u88c5\u5ba2\u6237\u7aef\u5305\r\n#\u7ed9\u5b9a\u65f6\u4efb\u52a1\u52a0\u4e0a\u6ce8\u91ca\r\n[root@egon ~]# echo '#Timing synchronization time' &gt;&gt;\/var\/spool\/cron\/root\r\n\r\n#\u5b9a\u65f6\u4efb\u52a1\r\n[root@egon ~]# echo '0 *\/1 * * * \/usr\/sbin\/ntpdate ntp1.aliyun.com &amp;&gt;\/dev\/null' &gt;&gt;\/var\/spool\/cron\/root\r\n\r\n#\u68c0\u67e5\u7ed3\u679c\r\n[root@egon ~]# crontab -l<\/code><\/pre>\n<h1>\u4e5d\u3001\u7cfb\u7edf\u5185\u6838\u4f18\u5316<\/h1>\n<h2>9.1 ulimit\u547d\u4ee4\u4ecb\u7ecd<\/h2>\n<p>\u6211\u4eec\u53ef\u4ee5ulimit\u547d\u4ee4\u5bf9\u7cfb\u7edf\u8d44\u6e90\u8fdb\u884c\u63a7\u5236\uff0c\u9009\u9879\u5982\u4e0b<\/p>\n<p><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/egonlin.com\/wp-content\/uploads\/2021\/07\/ulimit.png'><img class=\"lazyload lazyload-style-2\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  data-original=\"https:\/\/egonlin.com\/wp-content\/uploads\/2021\/07\/ulimit.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" \/><\/div><\/p>\n<p>\u8bbe\u7f6e\u7528\u6237\u7ea7\u6240\u80fd\u6253\u5f00\u7684\u6700\u5927\u8fdb\u7a0b\u6570\u76ee\uff1a-u\u9009\u9879<\/p>\n<pre><code class=\"language-python\">ulimit -u 3<\/code><\/pre>\n<p>\u8bbe\u7f6e\u7528\u6237\u7ea7\u6240\u80fd\u5206\u914d\u5230\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26\u6570\u91cf\uff1a-n\u9009\u9879<\/p>\n<pre><code>ulimit -n 12\r\n\r\n# \u8fd9\u4e2a\u503c\u9ed8\u8ba4\u6700\u5927\u53ef\u4ee5\u8bbe\u7f6e\u4e3a1048576\uff0c\r\n[root@localhost ~]# ulimit  -n 1048576\r\n[root@localhost ~]# ulimit  -n 1048577\r\nbash: ulimit: open files: cannot modify limit: Operation not permitted<\/code><\/pre>\n<h2>9.2 \u63a7\u5236\u7528\u6237\u5f00\u542f\u7684\u6700\u5927\u8fdb\u7a0b\u6570\u76ee<\/h2>\n<pre><code class=\"language-python\">[root@egon ~~]# useradd egon\r\n[root@egon ~~]# ulimit -u 3  # \u6bcf\u4e2a\u7528\u6237\u80fd\u540c\u65f6\u5f00\u542f\u7684\u6700\u5927\u8fdb\u7a0b\u6570\u5747\u53ea\u67093\u4e2a\r\n[root@egon ~~]# su - egon  # \u5207\u6362\u5230egon\u7528\u6237\u4e0b\uff0c\u5148\u6267\u884c\u4e86\u4e00\u4e2abash\u89e3\u91ca\u5668\u8fdb\u7a0b\uff0c\u6b64\u5916\u8fd8\u80fd\u518d\u5f00\u4fe9\u4e2a\r\n[egon@egon ~~]$ sleep 1000 &amp;\r\n[1] 1435\r\n[egon@egon ~~]$ sleep 2000 &amp;\r\n[2] 1436\r\n[egon@egon ~~]$ sleep 3000 &amp;\r\n-bash: fork: retry: \u8d44\u6e90\u6682\u65f6\u4e0d\u53ef\u7528\r\n-bash: fork: retry: \u8d44\u6e90\u6682\u65f6\u4e0d\u53ef\u7528\r\n-......\r\n\r\n# \u6ce8\u610f:\r\n1\u3001ulimit -u 3\u662f\u9650\u5236\u6bcf\u4e2a\u7528\u6237\u80fd\u540c\u65f6\u5f00\u542f\u7684\u6700\u5927\u8fdb\u7a0b\u6570\u5747\u53ea\u67093\uff0c\u800c\u4e0d\u662f\u7d2f\u8ba1\u5230\u4e00\u8d77\u603b\u5171\u67093\u4e2a\r\n2\u3001\u6d4b\u8bd5\u7684\u65f6\u5019sleep\u540e\u7684\u65f6\u95f4\u957f\u4e00\u70b9\uff0c\u6a21\u62df\u51fa\u540c\u65f6\u5f00\u542f\u591a\u4e2a\u8fdb\u7a0b\u7684\u6548\u679c\uff0c\u4e0d\u7136\u6267\u884c\u4e00\u6761\u77ed\u547d\u4ee4\u5f88\u5feb\u5c31\u7ed3\u675f\u4e86<\/code><\/pre>\n<h2>9.3 \u6587\u4ef6\u63cf\u8ff0\u7b26<\/h2>\n<p>\u6587\u4ef6\u63cf\u8ff0\u7b26<\/p>\n<pre><code class=\"language-python\">\u8fdb\u7a0b\u6bcf\u6253\u5f00\u4e00\u4e2a\u6587\u4ef6\uff0c\u64cd\u4f5c\u7cfb\u7edf\u5185\u6838\u5c31\u4f1a\u4e3a\u8be5\u6253\u5f00\u7684\u6587\u4ef6\u5206\u914d\u4e00\u4e2a\u7f16\u53f7(\u975e\u8d1f\u6574\u6570)\uff0c\u8be5\u7f16\u53f7\u79f0\u4e4b\u4e3a\u6587\u4ef6\u63cf\u8ff0\u7b26\uff08File Descriptor\uff09\u6216\u8005\u6587\u4ef6handle-&gt;\u4e5f\u6709\u4eba\u5c06\u5176\u8bd1\u4e3a\u6587\u4ef6\u53e5\u67c4\r\n\r\n\u6587\u4ef6\u6253\u5f00\u540e\u7684\u5904\u7406\u903b\u8f91\uff1a\r\n\u8fdb\u7a0b-&gt;\u6587\u4ef6\u63cf\u8ff0\u7b26-&gt;\u64cd\u4f5c\u7cfb\u7edf\u5185\u6838-&gt;\u4e00\u4e2a\u5177\u4f53\u7684\u6587\u4ef6\r\n\u5373\u5185\u6838\uff08kernel\uff09\u5c31\u662f\u5229\u7528\u6587\u4ef6\u63cf\u8ff0\u7b26\uff08file descriptor\uff09\u6765\u8bbf\u95ee\u6587\u4ef6\r\n\r\n\u5728\u7a0b\u5e8f\u8bbe\u8ba1\u4e2d\uff0c\u4e00\u4e9b\u6d89\u53ca\u5e95\u5c42\u7684\u7a0b\u5e8f\u7f16\u5199\u5f80\u5f80\u4f1a\u56f4\u7ed5\u7740\u6587\u4ef6\u63cf\u8ff0\u7b26\u5c55\u5f00\u3002\u4f46\u662f\u6587\u4ef6\u63cf\u8ff0\u7b26\u8fd9\u4e00\u6982\u5ff5\u5f80\u5f80\u53ea\u9002\u7528\u4e8eUNIX\u3001Linux\u8fd9\u6837\u7684\u64cd\u4f5c\u7cfb\u7edf\u3002\r\n\r\n\u66f4\u591a\u5173\u4e8e\u63cf\u8ff0\u7b26\u7684\u6982\u5ff5\uff1ahttps:\/\/www.cnblogs.com\/linhaifeng\/articles\/13959014.html<\/code><\/pre>\n<p>\u8fdb\u7a0b\u6bcf\u6253\u5f00\u4e00\u4e2a\u6587\u4ef6\uff0c\u64cd\u4f5c\u7cfb\u7edf\u5c31\u4f1a\u4e3a\u8fdb\u7a0b\u5206\u914d\u4e00\u4e2a\u5bf9\u5e94\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26\u3002\u6587\u4ef6\u63cf\u8ff0\u7b26\u7684\u6570\u76ee\u662f\u53ef\u4ee5\u8bbe\u7f6e\u7684\uff0c\u800c\u4e00\u65e6\u8bbe\u7f6e\u8fc7\u5c0f\uff0c\u8fdb\u7a0b\u4f1a\u968f\u7740\u6253\u5f00\u7684\u6587\u4ef6\u6570\u589e\u591a\uff0c\u56e0\u4e3a\u8fbe\u5230\u4e86\u6587\u4ef6\u63cf\u8ff0\u7684\u4e0a\u9650\u800c\u65e0\u6cd5\u6253\u5f00\u6587\u4ef6\uff0c\u4ece\u800c\u629b\u51fa\u5f02\u5e38<\/p>\n<pre><code class=\"language-python\"># \u6587\u4ef6\u63cf\u8ff0\u7b26\u6d4b\u8bd5\u4ee3\u7801\r\n[root@egon ~~]# cat test1.py \r\nimport os\r\nimport time\r\nfrom threading import Thread\r\n\r\nprint(os.getpid())\r\n\r\ndef task(n):\r\n    with open('%s.txt' %n,mode='wt') as f1:\r\n        time.sleep(1000)\r\n\r\nif __name__ == \"__main__\":\r\n    count=1\r\n    while True:\r\n        Thread(target=task,args=(count,)).start()\r\n        count+=1\r\n        time.sleep(3)\r\n\r\n[root@egon ~~]# cat test2.py \r\nimport os\r\nimport time\r\nfrom threading import Thread\r\n\r\nprint(os.getpid())\r\n\r\ndef task(n):\r\n    with open('egon%s.txt' %n,mode='wt') as f1:\r\n        time.sleep(1000)\r\n\r\nif __name__ == \"__main__\":\r\n    count=1\r\n    while True:\r\n        Thread(target=task,args=(count,)).start()\r\n        count+=1\r\n        time.sleep(3)\r\n\r\n[root@egon ~~]# \r\n\r\n# \u6d4b\u8bd5\r\n[root@egon ~~]# ulimit -n 12  # \u6700\u5927\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26\u6570\u4e3a12\uff0c\u6bcf\u4e2a\u7528\u6237\u7ea7\u8fdb\u7a0b\u80fd\u6253\u5f00\u7684\u6700\u5927\u6587\u4ef6\u6570\u5747\u53ea\u670912\u4e2a\r\n[root@egon ~~]# python test1.py &amp;\r\n[1] 1263\r\n[root@egon ~~]# 1263\r\n\r\n[root@egon ~~]# python test2.py &amp;\r\n[2] 1266\r\n[root@egon ~~]# 1266\r\n\r\n# \u5728\u53e6\u5916\u4e00\u4e2a\u7ec8\u7aef\u67e5\u770b\r\n[root@egon ~~]# ll \/proc\/1263\/fd\r\n\u603b\u7528\u91cf 0\r\nlrwx------. 1 root root 64 11\u6708 12 18:18 0 -&gt; \/dev\/pts\/0  # \u6307\u5411\u5f53\u524d\u7ec8\u7aef\u7684\u6807\u51c6\u8f93\u5165\r\nlrwx------. 1 root root 64 11\u6708 12 18:18 1 -&gt; \/dev\/pts\/0  # \u6307\u5411\u5f53\u524d\u7ec8\u7aef\u7684\u6807\u51c6\u6b63\u786e\u8f93\u51fa\r\nlrwx------. 1 root root 64 11\u6708 12 18:18 2 -&gt; \/dev\/pts\/0  # \u6307\u5411\u5f53\u524d\u7ec8\u7aef\u7684\u6807\u51c6\u9519\u8bef\u8f93\u51fa\r\nl-wx------. 1 root root 64 11\u6708 12 18:18 3 -&gt; \/root\/1.txt\r\nl-wx------. 1 root root 64 11\u6708 12 18:18 4 -&gt; \/root\/2.txt\r\nl-wx------. 1 root root 64 11\u6708 12 18:18 5 -&gt; \/root\/3.txt\r\nl-wx------. 1 root root 64 11\u6708 12 18:18 6 -&gt; \/root\/4.txt\r\nl-wx------. 1 root root 64 11\u6708 12 18:18 7 -&gt; \/root\/5.txt\r\n[root@egon ~~]# ll \/proc\/1266\/fd\r\n\u603b\u7528\u91cf 0\r\nlrwx------. 1 root root 64 11\u6708 12 18:18 0 -&gt; \/dev\/pts\/0\r\nlrwx------. 1 root root 64 11\u6708 12 18:18 1 -&gt; \/dev\/pts\/0\r\nlrwx------. 1 root root 64 11\u6708 12 18:18 2 -&gt; \/dev\/pts\/0\r\nl-wx------. 1 root root 64 11\u6708 12 18:18 3 -&gt; \/root\/egon1.txt\r\nl-wx------. 1 root root 64 11\u6708 12 18:18 4 -&gt; \/root\/egon2.txt\r\nl-wx------. 1 root root 64 11\u6708 12 18:18 5 -&gt; \/root\/egon3.txt\r\nl-wx------. 1 root root 64 11\u6708 12 18:18 6 -&gt; \/root\/egon4.txt\r\nl-wx------. 1 root root 64 11\u6708 12 18:18 7 -&gt; \/root\/egon5.txt\r\n\r\n# \u89c2\u5bdf1263\u4e0e1266\u8fd9\u4fe9\u8fdb\u7a0b\u5404\u81ea\u4e00\u65e6\u6253\u5f00\u7684\u6587\u4ef6\u6570\u76ee\u5230\u8fbe\u4e8612\uff0c\u5c31\u90fd\u4f1a\u62a5\u9519\r\n[root@egon ~~]# Exception in thread Thread-10:\r\nTraceback (most recent call last):\r\n  File \"\/usr\/lib64\/python2.7\/threading.py\", line 812, in __bootstrap_inner\r\n  File \"\/usr\/lib64\/python2.7\/threading.py\", line 765, in run\r\n  File \"test1.py\", line 8, in task\r\nIOError: [Errno 24] Too many open files: '10.txt'\r\n\r\nException in thread Thread-11:\r\nTraceback (most recent call last):\r\n  File \"\/usr\/lib64\/python2.7\/threading.py\", line 812, in __bootstrap_inner\r\n  File \"\/usr\/lib64\/python2.7\/threading.py\", line 765, in run\r\n  File \"test1.py\", line 8, in task\r\nIOError: [Errno 24] Too many open files: '11.txt'\r\n\r\nException in thread Thread-10:\r\nTraceback (most recent call last):\r\n  File \"\/usr\/lib64\/python2.7\/threading.py\", line 812, in __bootstrap_inner\r\n  File \"\/usr\/lib64\/python2.7\/threading.py\", line 765, in run\r\n  File \"test2.py\", line 8, in task\r\nIOError: [Errno 24] Too many open files: 'egon10.txt'<\/code><\/pre>\n<p>\u4e86\u89e3\uff1a\u7cfb\u7edf\u7ea7\u6700\u5927\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26\u4e2a\u6570\uff0c\u5373\u5185\u6838\u7a0b\u5e8f\u6700\u5927\u53ef\u4ee5\u6253\u5f00\u7684\u6587\u4ef6\u6570<\/p>\n<pre><code class=\"language-python\">Linux\u7684\/proc\/sys\/fs\/file-max\u51b3\u5b9a\u4e86\u5f53\u524d\u5185\u6838\u53ef\u4ee5\u6253\u5f00\u7684\u6700\u5927\u7684\u6587\u4ef6\u53e5\u67c4\u6570\u3002\r\n\r\n# \u67e5\u770b\u5f53\u524d\u7684\u503c\uff1a\r\ncat \/proc\/sys\/fs\/file-max\r\n\r\n\u8fd9\u4e2a\u503c\u5728kernel\u7684\u6587\u6863\u91cc\u662f\u8fd9\u6837\u63cf\u8ff0\u7684\uff1a\r\nThe value  in  file-max  denotes  the  maximum number of file handles that the\r\nLinux kernel will allocate. When you get a lot of error messages about running\r\nout of  file handles, you might want to raise this limit. The default value is\r\n10% of  RAM in kilobytes.  To  change it, just  write the new number  into the\r\nfile:\r\n\r\n\u610f\u601d\u662ffile-max\u4e00\u822c\u4e3a\u5185\u5b58\u5927\u5c0f\uff08KB\uff09\u768410%\u6765\u8ba1\u7b97\uff0c\u5982\u679c\u4f7f\u7528shell\uff0c\u53ef\u4ee5\u8fd9\u6837\u8ba1\u7b97\uff1a\r\ngrep -r MemTotal \/proc\/meminfo | awk '{printf(\"%d\",$2\/10)}'\r\n\r\n\u4e00\u822c\u6211\u4eec\u4e0d\u9700\u8981\u4e3b\u52a8\u8bbe\u7f6e\u8fd9\u4e2a\u503c\uff0c\u56e0\u4e3a\u8be5\u503c\u4f1a\u968f\u7740\u5185\u5b58\u5927\u5c0f\u7684\u53d8\u5316\u800c\u81ea\u52a8\u5206\u914d\u5230\u5185\u5b58\u768410%\u5de6\u53f3\uff0c\u9664\u975e\u8fd9\u4e2a\u503c\u786e\u5b9e\u8f83\u5c0f\uff08\u53ef\u80fd\u6709\u5404\u79cd\u5176\u4ed6\u539f\u56e0\u5bfc\u81f4file-max\u6ca1\u6709\u8bbe\u7f6e\u4e3a\u5185\u5b58\u768410%\uff09\uff0c\u6211\u4eec\u624d\u9700\u8981\u8bbe\u7f6e\r\n\r\n# \u5982\u4f55\u67e5\u770b\u5f53\u524dkernel\u7684\u53e5\u67c4:\r\n[root@egon ~~]# cat \/proc\/sys\/fs\/file-nr\r\n608 0   94306\r\n\r\nfile-nr\u5728\u5185\u6838\u6587\u6863\u91cc\u5f97\u89e3\u91ca\u5982\u4e0b\uff1a\r\nHistorically, the three values in file-nr denoted the number of allocated file\r\nhandles,  the number of  allocated but  unused file  handles, and  the maximum\r\nnumber of file handles. Linux 2.6 always  reports 0 as the number of free file\r\nhandles -- this  is not an error,  it just means that the  number of allocated\r\nfile handles exactly matches the number of used file handles.\r\n\u8fc7\u53bb\uff0cfilenr\u4e2d\u7684\u4e09\u4e2a\u503c\u8868\u793a\u5df2\u5206\u914d\u7684\u6587\u4ef6\u53e5\u67c4\u6570\u3001\u5df2\u5206\u914d\u4f46\u672a\u4f7f\u7528\u7684\u6587\u4ef6\u53e5\u67c4\u6570\u4ee5\u53ca\u6700\u5927\u6587\u4ef6\u53e5\u67c4\u6570\u3002Linux2.6\u603b\u662f\u62a5\u544a0\u4f5c\u4e3a\u7a7a\u95f2\u6587\u4ef6\u53e5\u67c4\u7684\u6570\u91cf\u2014\u2014\u8fd9\u4e0d\u662f\u4e00\u4e2a\u9519\u8bef\uff0c\u5b83\u53ea\u662f\u610f\u5473\u7740\u5206\u914d\u7684\u6587\u4ef6\u53e5\u67c4\u7684\u6570\u91cf\u4e0e\u4f7f\u7528\u7684\u6587\u4ef6\u53e5\u67c4\u7684\u6570\u91cf\u5b8c\u5168\u5339\u914d\u3002<\/code><\/pre>\n<h2>9.4 \u6c38\u4e45\u8bbe\u7f6e\u4e0e\u4f18\u5316<\/h2>\n<div id=\"rml_readmorelogin_placeholder\" style=\"position:relative;\"><div id=\"rml_fade_content\" style=\"position: absolute;\r\ntop:-10em;\r\nwidth:100%;\r\nheight:10em;\r\nbackground: -webkit-linear-gradient(rgba(255, 255, 255, 0) 0%,#ffffff 100%);\r\nbackground-image: -moz-linear-gradient(rgba(255, 255, 255, 0) 0%,#ffffff 100%);\r\nbackground-image: -o-linear-gradient(rgba(255, 255, 255, 0) 0%,#ffffff 100%);\r\nbackground-image: linear-gradient(rgba(255, 255, 255, 0) 0%,#ffffff 100%);\r\nbackground-image: -ms-linear-gradient(rgba(255, 255, 255, 0) 0%,#ffffff 100%);\"><\/div><div class=\"wpf-controller aru_rml_from_in_post\" style=\"background-color:#eeeeee;border:5px solid #cce6ff;\" id=\"ARU_ReadMoreLogin_ReadMoreLoginController\"><h2 id=\"Header\">\u67e5\u770b\u66f4\u591a<\/h2><div id=\"Message\"><p>\u8054\u7cfb\u7ba1\u7406\u5458\u5fae\u4fe1tutu19192010\uff0c\u6ce8\u518c\u8d26\u53f7<\/p>\n<\/div><div id=\"StatusBarHeader\"><\/div><form id=\"ARU_ReadMoreLogin_ReadMoreLoginController\"><input name=\"post_id\" value=\"237\" type=\"hidden\"\/><input name=\"_init_callback\" value=\"InitLogin\" type=\"hidden\"\/><input name=\"post_id\" value=\"237\" type=\"hidden\"\/><input name=\"rt_ype\" value=\"1\" type=\"hidden\"\/><input name=\"nonce\" value=\"dc0bc25cf1\" type=\"hidden\"\/><input name=\"_wpnonce\" value=\"65c50c9574\" type=\"hidden\"\/><input name=\"_controller\" value=\"ARU_ReadMoreLogin\\ReadMoreLoginController\" type=\"hidden\"\/><input name=\"_proxy_controller\" value=\"ARU_ReadMoreLogin\\ReadMoreLoginController\" type=\"hidden\"\/><input name=\"_view\" value=\"ARU_ReadMoreLogin\\ReadMoreLoginView\" type=\"hidden\"\/><table class=\"wpf-table-placeholder\"><tbody class=\"wpf-table-placeholder\"><tr class=\"wpf-table-placeholder\"><td class=\"wpf-table-placeholder-input\" width=\"400px\"><table class=\"wpf-table-placeholder\"><tbody class=\"wpf-table-placeholder\"><tr class=\"wpf-table-placeholder\"><th class=\"wpf-table-placeholder-input\"><label class=\"wpf-label\">Username:<\/label><\/th><\/tr><tr class=\"wpf-table-placeholder\"><td class=\"wpf-table-placeholder-input\"><input class=\"regular-text text_input\" name=\"username\" value=\"\" type=\"text\"\/><\/td><\/tr><tr class=\"wpf-table-placeholder\"><th class=\"wpf-table-placeholder-input\"><label class=\"wpf-label\">Password:<\/label><\/th><\/tr><tr class=\"wpf-table-placeholder\"><td class=\"wpf-table-placeholder-input\"><input class=\"regular-text text_input\" name=\"password\" value=\"\" type=\"password\"\/><\/td><\/tr><\/tbody><\/table><p class=\"wpf-table-placeholder submit\"><button class=\"wp_plugin_framework_ajax_button\" type=\"button\" style=\"background-color:#4D90FE;;color:#ffffff;;border:1px solid #3079ed;\" name=\"_event\" value=\"ButtonLogin\">Log in<\/button><\/p><\/td><td class=\"wpf-table-placeholder-input\"><\/td><\/tr><\/tbody><\/table><\/form><div id=\"ButtonStartRegister\"><a href=\"https:\/\/egonlin.com\/wp-login.php?action=register\">Register<\/a><\/div><div id=\"Link1\"><a href=\"https:\/\/egonlin.com\/wp-login.php?action=lostpassword\">Forgotten username or password?<\/a><\/div><div id=\"StatusBarFooter\"><\/div><\/div><\/div><div id=aru_remaining_content><\/div>","protected":false},"excerpt":{"rendered":"<p>Linux\u64cd\u4f5c\u7cfb\u7edf\u4f18\u5316 \u4e00\u3001\u4f18\u5316\u663e\u793a\u8f93\u51fa vim \/etc\/bashrc \u8fdb\u5165bashrc\u6587\u4ef6 \u6309\u4e0b41gg  [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":241,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[33],"tags":[21,19,35,22,20],"_links":{"self":[{"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/posts\/237"}],"collection":[{"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=237"}],"version-history":[{"count":18,"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/posts\/237\/revisions"}],"predecessor-version":[{"id":10783,"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/posts\/237\/revisions\/10783"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/media\/241"}],"wp:attachment":[{"href":"https:\/\/egonlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=237"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=237"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=237"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}