﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>IT博客-Favor Soup | 反胃书屋-随笔分类-Lin系统相关</title><link>http://www.cnitblog.com/dickznew/category/5142.html</link><description>斯是陋室，惟吾德馨。</description><language>zh-cn</language><lastBuildDate>Tue, 27 Sep 2011 18:33:01 GMT</lastBuildDate><pubDate>Tue, 27 Sep 2011 18:33:01 GMT</pubDate><ttl>60</ttl><item><title>Too Many Open Files Error And Solution</title><link>http://www.cnitblog.com/dickznew/archive/2010/07/28/67743.html</link><dc:creator>D主</dc:creator><author>D主</author><pubDate>Wed, 28 Jul 2010 09:15:00 GMT</pubDate><guid>http://www.cnitblog.com/dickznew/archive/2010/07/28/67743.html</guid><wfw:comment>http://www.cnitblog.com/dickznew/comments/67743.html</wfw:comment><comments>http://www.cnitblog.com/dickznew/archive/2010/07/28/67743.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/dickznew/comments/commentRss/67743.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/dickznew/services/trackbacks/67743.html</trackback:ping><description><![CDATA[<h1 class="entry-title">Nginx: 24: Too Many Open Files Error And Solution</h1>
<p class="headline_meta">by <span class="author vcard fn">Vivek Gite</span> &#183; <span><a href="http://www.cyberciti.biz/faq/linux-unix-nginx-too-many-open-files/#comments" rel="nofollow">4 comments</a></span></p>
<div style="float: right; margin-top: 0px; margin-left: 5px;"><a href="http://www.cyberciti.biz/faq/category/nginx/" title="See all Nginx webserver related FAQ"><img src="http://c.cyberciti.biz/cbzcache/3rdparty/nginx.gif" border="0"></a></div>
<p><span class="drop_cap">I</span>'m getting the following error in my nginx server error log file:</p>
<blockquote>
<p>2010/04/16 13:24:16 [crit] 21974#0: *3188937 open() "<strong><span style="color: #ff0000;">/usr/local/nginx/html/50x.html" failed (24: Too many open files)</span></strong>,
client: 88.x.y.z, server: example.com, request: "GET
/file/images/background.jpg HTTP/1.1", upstream:
"http://10.8.4.227:81//file/images/background.jpg", host: "example.com"</p>
</blockquote>
<p>How do I fix this problem under CentOS / RHEL / Fedora Linux or UNIX like operating systems?<br>
<span id="more-7302"></span><br>
Linux / UNIX sets soft and hard limit for the number of file handles and
open files. You can use ulimit command to view those limitations:<br>
<code>su - nginx</code><br>
To see the hard and soft values, issue the command as follows:<br>
<code>ulimit -Hn<br>
ulimit -Sn</code></p>
<h2>Increase Open FD Limit at Linux OS Level</h2>
<p>Your operating system set limits on how many files can be opened by nginx server. You can easily fix this problem <a href="http://www.cyberciti.biz/tips/linux-procfs-file-descriptors.html">by setting or increasing system open file limits</a> under Linux. Edit file /etc/sysctl.conf, enter:<br>
<code># vi /etc/sysctl.conf</code><br>
Append / modify the following line:<br>
<code>fs.file-max = 70000</code><br>
Save and close the file. Edit /etc/security/limits.conf, enter:<br>
<code># vi /etc/security/limits.conf</code><br>
Set soft and hard limit for all users or nginx user as follows:</p>
<pre>nginx       soft    nofile   10000<br>nginx       hard    nofile  30000</pre>
<p>Save and close the file. Finally, reload the <a href="http://www.cyberciti.biz/faq/making-changes-to-proc-filesystem-permanently/" title="Making changes to /proc filesystem permanently">changes with sysctl command</a>:<br>
<code># sysctl -p</code></p>
<h2>nginx worker_rlimit_nofile Option (Increase Open FD Limit at Nginx Level)</h2>
<p>Nginx also comes with  worker_rlimit_nofile directive which allows to
enlarge this limit if it's not enough on fly at process level. To set
the value for maximum file descriptors that can be opened by nginx
process. Edit nginx.conf file, enter:<br>
<code># vi /usr/local/nginx/conf/nginx.conf</code><br>
Append / edit as follows:</p>
<pre># set open fd limit to 30000<br>worker_rlimit_nofile 30000;</pre>
<p>Save and close the file. Reload nginx web server, enter:<br>
<code># /usr/local/nginx/sbin/nginx -t  &amp;&amp; /usr/local/nginx/sbin/nginx -s reload<br>
# su - nginx<br>
$ ulimit -Hn<br>
$ ulimit -Sn<br>
</code><br>
Sample outputs:</p>
<pre>30000<br>10000</pre><img src ="http://www.cnitblog.com/dickznew/aggbug/67743.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/dickznew/" target="_blank">D主</a> 2010-07-28 17:15 <a href="http://www.cnitblog.com/dickznew/archive/2010/07/28/67743.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>ZZ: Linux下DISPLAY环境变量的作用</title><link>http://www.cnitblog.com/dickznew/archive/2010/07/15/67514.html</link><dc:creator>D主</dc:creator><author>D主</author><pubDate>Thu, 15 Jul 2010 06:16:00 GMT</pubDate><guid>http://www.cnitblog.com/dickznew/archive/2010/07/15/67514.html</guid><wfw:comment>http://www.cnitblog.com/dickznew/comments/67514.html</wfw:comment><comments>http://www.cnitblog.com/dickznew/archive/2010/07/15/67514.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/dickznew/comments/commentRss/67514.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/dickznew/services/trackbacks/67514.html</trackback:ping><description><![CDATA[在Linux/Unix类操作系统上, DISPLAY用来设置将图形显示到何处. 直接登陆图形界面或者登陆命令行界面后使用startx启动图形,
DISPLAY环境变量将自动设置为:0:0, 此时可以打开终端, 输出图形程序的名称(比如xclock)来启动程序, 图形将显示在本地窗口上,
在终端上输入printenv查看当前环境变量, 输出结果中有如下内容: <br><br>
<table style="border: 1px solid #999999; font-size: 12px; width: 80%;" align="center">
    <tbody>
        <tr>
            <td>DISPLAY=:0.0</td>
        </tr>
    </tbody>
</table>
<br>使用xdpyinfo可以查看到当前显示的更详细的信息. <br><br>DISPLAY
环境变量格式如下host:NumA.NumB, host指Xserver所在的主机主机名或者ip地址, 图形将显示在这一机器上,
可以是启动了图形界面的Linux/Unix机器, 也可以是安装了Exceed,
X-Deep/32等Windows平台运行的Xserver的Windows机器. 如果Host为空, 则表示Xserver运行于本机,
并且图形程序(Xclient)使用unix socket方式连接到Xserver, 而不是TCP方式. 使用TCP方式连接时,
NumA为连接的端口减去6000的值, 如果NumA为0, 则表示连接到6000端口; 使用unix
socket方式连接时则表示连接的unix socket的路径, 如果为0, 则表示连接到/tmp/.X11-unix/X0 .
NumB则几乎总是0. <br><br>如果使用su username或者su - username切换到别的用户, 并且使用命令<br><br>
<table style="border: 1px solid #999999; font-size: 12px; width: 80%;" align="center">
    <tbody>
        <tr>
            <td>export DISPLAY=:0.0<br></td>
        </tr>
    </tbody>
</table>
<br>设置DISPLAY环境变量, 运行图形程序(如xclock)时会收到如下错误: <br><br>
<table style="border: 1px solid #999999; font-size: 12px; width: 80%;" align="center">
    <tbody>
        <tr>
            <td>Xlib: connection to ":0.0" refused by server<br>Xlib: No protocol specified<br><br>Error: Can't open display: :0.0<br></td>
        </tr>
    </tbody>
</table>
<br>这是因为Xserver默认情况下不允许别的用户的图形程序的图形显示在当前屏幕上. 如果需要别的用户的图形显示在当前屏幕上, 则应以当前登陆的用户, 也就是切换身份前的用户执行如下命令<br><br>
<table style="border: 1px solid #999999; font-size: 12px; width: 80%;" align="center">
    <tbody>
        <tr>
            <td>xhost +<br></td>
        </tr>
    </tbody>
</table>
<br>这个命令将允许别的用户启动的图形程序将图形显示在当前屏幕上. <br><br>在2台Linux机器之间, 如果设置服务器端配置文件/etc/ssh/sshd_config中包含<br><br>
<table style="border: 1px solid #999999; font-size: 12px; width: 80%;" align="center">
    <tbody>
        <tr>
            <td>X11Forwarding no</td>
        </tr>
    </tbody>
</table>
<br>客户端配置文件/etc/ssh/ssh_config包含<br><br>
<table style="border: 1px solid #999999; font-size: 12px; width: 80%;" align="center">
    <tbody>
        <tr>
            <td>ForwardX11 yes</td>
        </tr>
    </tbody>
</table>
<br>则从客户端ssh到服务器端后会自动设置DISPLAY环境变量, 允许在服务器端执行的图形程序将图形显示在客户端上. 在服务器上查看环境变量显示如下(这个结果不同的时候并不相同)<br><br>
<table style="border: 1px solid #999999; font-size: 12px; width: 80%;" align="center">
    <tbody>
        <tr>
            <td>DISPLAY=localhost:10.0</td>
        </tr>
    </tbody>
</table>
<br>在客户机上用netstat -lnp可以看到有程序监听了6010端口<br><br>
<table style="border: 1px solid #999999; font-size: 12px; width: 80%;" align="center">
    <tbody>
        <tr>
            <td>tcp&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0 127.0.0.1:6010&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0.0.0.0:*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; LISTEN&nbsp;&nbsp;&nbsp;&nbsp; 4827/1</td>
        </tr>
    </tbody>
</table>
<br>如
果希望允许远程机器上的图形程序将图形显示在本地机器的Xserver上, 除了要设置远端机器的DISPLAY环境变量以外,
还需要设置本地机器的Xserver监听相应的TCP端口. 而现在的Linux系统出于安全的考虑, 默认情况下不再监听TCP端口.
可通过修改/etc/X11/xinit/xserverrc文件, 将<br><br>
<table style="border: 1px solid #999999; font-size: 12px; width: 80%;" align="center">
    <tbody>
        <tr>
            <td>exec /usr/bin/X11/X -dpi 100 -nolisten tcp</td>
        </tr>
    </tbody>
</table>
<br>修改为<br><br>
<table style="border: 1px solid #999999; font-size: 12px; width: 80%;" align="center">
    <tbody>
        <tr>
            <td>exec /usr/bin/X11/X -dpi 100<br></td>
        </tr>
    </tbody>
</table>
<br>允许在直接使用startx启动图形时启动对TCP端口的监听. <br><br>修改/etc/kde3/kdm/kdmrc, 将<br><br>
<table style="border: 1px solid #999999; font-size: 12px; width: 80%;" align="center">
    <tbody>
        <tr>
            <td>ServerArgsLocal=-nolisten tcp</td>
        </tr>
    </tbody>
</table>
<br>修改为<br><br>
<table style="border: 1px solid #999999; font-size: 12px; width: 80%;" align="center">
    <tbody>
        <tr>
            <td>ServerArgsLocal=</td>
        </tr>
    </tbody>
</table>
<br>允许kdm作为显示管理器时, 启动会话时监听相应的TCP端口. <br><br>修改/etc/gdm/gdm.conf, 在[Security]一节增加<br><br>
<table style="border: 1px solid #999999; font-size: 12px; width: 80%;" align="center">
    <tbody>
        <tr>
            <td>DisallowTCP=false</td>
        </tr>
    </tbody>
</table>
<br>或者在登陆窗口选择"Options"
-&gt; "Configure Login Manager..."的Security页面, 取消"Deny TCP connections
to Xserver", 允许gdm作为显示管理器时, 启动会话时监听相应的TCP端口.<img src ="http://www.cnitblog.com/dickznew/aggbug/67514.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/dickznew/" target="_blank">D主</a> 2010-07-15 14:16 <a href="http://www.cnitblog.com/dickznew/archive/2010/07/15/67514.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Cygwin Rookie</title><link>http://www.cnitblog.com/dickznew/archive/2007/04/20/25930.html</link><dc:creator>D主</dc:creator><author>D主</author><pubDate>Fri, 20 Apr 2007 06:04:00 GMT</pubDate><guid>http://www.cnitblog.com/dickznew/archive/2007/04/20/25930.html</guid><wfw:comment>http://www.cnitblog.com/dickznew/comments/25930.html</wfw:comment><comments>http://www.cnitblog.com/dickznew/archive/2007/04/20/25930.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/dickznew/comments/commentRss/25930.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/dickznew/services/trackbacks/25930.html</trackback:ping><description><![CDATA[<div><strong>cygwin中访问windows分区</strong></div>
<div>cygwin中有个隐藏目录 /cygdrive<br>通过这个目录就可以访问到windows的各个分区了</div>
<div><strong>cygwin设置程序脚本自动运行</strong></div>
<div>修改/home/~yourname/.bash_profile</div>
<img src ="http://www.cnitblog.com/dickznew/aggbug/25930.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/dickznew/" target="_blank">D主</a> 2007-04-20 14:04 <a href="http://www.cnitblog.com/dickznew/archive/2007/04/20/25930.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>