<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>浮山狼de博客 &#187; liunx</title>
	<atom:link href="https://www.fushanlang.com/tag/liunx/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.fushanlang.com</link>
	<description>next station - 下一站，活在当下，且行且思</description>
	<lastBuildDate>Sat, 29 Nov 2014 15:14:11 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=4.2.5</generator>
	<item>
		<title>linux shell进程监控与自动重启</title>
		<link>https://www.fushanlang.com/linux-shell-jin-cheng-jian-kong-yu-zi-dong-zhong-qi-2236/</link>
		<comments>https://www.fushanlang.com/linux-shell-jin-cheng-jian-kong-yu-zi-dong-zhong-qi-2236/#comments</comments>
		<pubDate>Mon, 15 Oct 2012 03:32:52 +0000</pubDate>
		<dc:creator><![CDATA[fushanlang]]></dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[liunx]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://www.fushanlang.com/blog/?p=2236</guid>
		<description><![CDATA[<p>注意： （1）ps aux    显示系统全部进程，一行一个 （2）grep “abc”  从标准输入读取字符流，输出包含字符串“abc”的行 （3）grep -v &#8220;acb&#8221;   从标准输入读取字符流，输出不包含字符串“abc”的行 （4）wc -l        从标准输入读取字符流，输出行数</p> 检测进程httpd是否存在 <p>操作流程如下： （1）读取系统所有进程 （2）判断包含指定进程名字的信息是否存在 通过管道连接，命令如下：</p> <p>ps axu      &#124;    grep  &#8220;httpd&#8221;           &#124;      grep -v &#8220;grep&#8221;    &#124;      wc -l 所有进程&#8211;&#62;获取包含“httpd”的行&#8211;&#62;删除grep进程信息&#8211;&#62;输出最后的行数</p> <p>通过判断命令的执行结果是否为 0  ，可以知道进程是否存在。</p> <p>脚本如下: #!/bin/sh count=`ps axu &#124; <span style="color:#777"> . . . &#8594; Read More: <a href="https://www.fushanlang.com/linux-shell-jin-cheng-jian-kong-yu-zi-dong-zhong-qi-2236/">linux shell进程监控与自动重启</a></span>]]></description>
				<content:encoded><![CDATA[<p>注意：<br />
（1）ps aux    显示系统全部进程，一行一个<br />
（2）grep “abc”  从标准输入读取字符流，输出包含字符串“abc”的行<br />
（3）grep -v &#8220;acb&#8221;   从标准输入读取字符流，输出不包含字符串“abc”的行<br />
（4）wc -l        从标准输入读取字符流，输出行数</p>
<h2><strong>检测进程httpd是否存在</strong></h2>
<p>操作流程如下：<br />
（1）读取系统所有进程<br />
（2）判断包含指定进程名字的信息是否存在<br />
通过管道连接，命令如下：</p>
<p>ps axu      |    grep  &#8220;httpd&#8221;           |      grep -v &#8220;grep&#8221;    |      wc -l<br />
所有进程&#8211;&gt;获取包含“httpd”的行&#8211;&gt;删除grep进程信息&#8211;&gt;输出最后的行数</p>
<p>通过判断命令的执行结果是否为 0  ，可以知道进程是否存在。</p>
<p>脚本如下:<br />
#!/bin/sh<br />
count=`ps axu | grep &#8220;httpd&#8221; | grep -v &#8220;grep&#8221;| wc -l`<br />
if[$count -lt 1];then<br />
sudo /home/proudboy/apache/admin/restart.sh<br />
fi</p>
<p>注：还可以执行ps axu | grep &#8220;httpd&#8221; | grep -v &#8220;grep&#8221;，然后通过判断返回值是否为0来知道程序是否有输出，如下：<br />
#!/bin/sh<br />
count=`ps axu | grep &#8220;httpd&#8221; | grep -v &#8220;grep&#8221; `<br />
if[$? != &#8220;0&#8221;];then<br />
sudo /home/proudboy/apache/admin/restart.sh<br />
fi</p>
<p>接下来是如何让shell脚本定时执行的问题，有两种方式可以实现：<br />
（1）在shell里面做循环，例如：<br />
#/bin/sh<br />
while true; do<br />
if [ &#8220;$?&#8221; != &#8220;0&#8221; ]; then</p>
<p>fi<br />
sleep 2<br />
done<br />
（2）将shell脚本加入到corntab 或者 at 里面</p>
<h2>如下Shell脚本 实现了对tomcat6进程监控，如果不存在自动重启。</h2>
<pre>#!/bin/sh
pid=`ps aux| grep "tomcat6" | grep -v grep | sed -n  '1P' | awk '{print $2}'`
if [ -z $pid ]; then
        echo "begin restart,please waiting..."
        sudo /etc/init.d/tomcat6 restart
        exit 1
else
        echo -e "exist ,don't need restart"
fi</pre>
]]></content:encoded>
			<wfw:commentRss>https://www.fushanlang.com/linux-shell-jin-cheng-jian-kong-yu-zi-dong-zhong-qi-2236/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>linux-SYN-netstat TIME_WAIT</title>
		<link>https://www.fushanlang.com/linux-syn-the-netstat-the-time_wait-2127/</link>
		<comments>https://www.fushanlang.com/linux-syn-the-netstat-the-time_wait-2127/#comments</comments>
		<pubDate>Wed, 06 Jun 2012 07:44:59 +0000</pubDate>
		<dc:creator><![CDATA[fushanlang]]></dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[webserver]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[liunx]]></category>
		<category><![CDATA[SYN flood]]></category>

		<guid isPermaLink="false">http://www.fushanlang.com/blog/?p=2127</guid>
		<description><![CDATA[Linux Web服务器连接数控制 <p>平时检测网站服务器连接数情况，常用的如  netstat -ant &#124;awk &#8216;{print $6}&#8217;&#124;sort&#124;uniq -c &#124;sort -n  给出如下统计</p> TIME_WAIT 3699 CLOSE_WAIT 52 FIN_WAIT1 32 SYN_SENT 1 FIN_WAIT2 2 ESTABLISHED 17 SYN_RECV 45 CLOSING 6 <p>有时会发现大量的TIME_WAIT，SYN_RECV,  CLOSE_WAIT  ,  FIN_WAIT状态，此时需要对系统参数做些调整：</p> vi /etc/sysctl net.ipv4.tcp_tw_reuse = 1 net.ipv4.tcp_tw_recycle = 1 net.ipv4.tcp_keepalive_time = 1000 net.ipv4.tcp_fin_timeout = 30 net.ipv4.tcp_window_scaling = 0 net.ipv4.tcp_sack = 0 net.ipv4.tcp_max_syn_backlog = <span style="color:#777"> . . . &#8594; Read More: <a href="https://www.fushanlang.com/linux-syn-the-netstat-the-time_wait-2127/">linux-SYN-netstat TIME_WAIT</a></span>]]></description>
				<content:encoded><![CDATA[<h2>Linux Web服务器连接数控制</h2>
<p>平时检测网站服务器连接数情况，常用的如  <strong>netstat -ant |awk &#8216;{print $6}&#8217;|sort|uniq -c |sort -n</strong>  给出如下统计</p>
<pre>
TIME_WAIT 3699
CLOSE_WAIT 52
FIN_WAIT1 32
SYN_SENT 1
FIN_WAIT2 2
ESTABLISHED 17
SYN_RECV 45
CLOSING 6</pre>
<p>有时会发现大量的TIME_WAIT，SYN_RECV,  CLOSE_WAIT  ,  FIN_WAIT状态，此时需要对系统参数做些调整：</p>
<pre>vi /etc/sysctl</pre>
<pre>net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_keepalive_time = 1000
net.ipv4.tcp_fin_timeout = 30
net.ipv4.tcp_window_scaling = 0
net.ipv4.tcp_sack = 0
net.ipv4.tcp_max_syn_backlog = 8192
net.ipv4.tcp_max_tw_buckets = 5000
net.ipv4.ip_local_port_range = 1024 65000
net.core.netdev_max_backlog =8096</pre>
<p>先执行<strong>sysctl -p</strong> 让新设置生效，然后再次执行<strong> netstat -ant |awk &#8216;{print $6}&#8217;|sort|uniq -c |sort -n</strong>  给出如下统计：</p>
<pre>
TIME_WAIT 36
CLOSE_WAIT 52
FIN_WAIT1 32
SYN_SENT 1
FIN_WAIT2 2
ESTABLISHED 2700
SYN_RECV 4
CLOSING 6</pre>
]]></content:encoded>
			<wfw:commentRss>https://www.fushanlang.com/linux-syn-the-netstat-the-time_wait-2127/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
