{"id":253,"date":"2018-11-23T10:40:37","date_gmt":"2018-11-23T02:40:37","guid":{"rendered":"http:\/\/www.tra56.com\/?p=253"},"modified":"2018-11-23T11:04:30","modified_gmt":"2018-11-23T03:04:30","slug":"253","status":"publish","type":"post","link":"https:\/\/www.tra56.com\/253.html","title":{"rendered":"Apache\u9650\u5236IP\u5e76\u53d1\u6570\u548c\u6d41\u91cf\u63a7\u5236\u7684\u65b9\u6cd5"},"content":{"rendered":"

\u672c\u6587\u7ae0\u6765\u7ed9\u5404\u4f4d\u540c\u5b66\u603b\u7ed3\u4e00\u4e0bAPACHE\u4e2d\u9650\u5236IP\u8fde\u63a5\u6570\u4e0eIP\u5e76\u53d1\u6570\u548c\u6d41\u91cf\u63a7\u5236\u5b9e\u73b0\u65b9\u6cd5\uff0c\u5982\u679c\u53ea\u9650\u5236\u8fde\u63a5\u6570\u636e\u6211\u4eec\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528limit\uff0c\u5982\u679c\u8981\u9650\u5236\u5176\u5b83\u7684\u9700\u8981\u4f7f\u7528\u5176\u5b83\u7b2c\u4e09\u65b9\u6a21\u5757\u4e86<\/p>\n

\u4f7f\u7528mod_limitipconn\u6a21\u5757\u9650\u5236IP\u5e76\u53d1\u8fde\u63a5\u6570
\u5b89\u88c5\uff1a<\/p>\n

\n\n
\n
\n
<\/div>\n<\/td>\n
\n
wget http:<\/code>\/\/dominia<\/code>.org<\/code>\/djao\/limit\/mod_limitipconn-0<\/code>.24.<\/code>tar<\/code>.bz2<\/code>
\n                <\/div>\n
tar<\/code> jxvf mod_limitipconn-0.24.<\/code>tar<\/code>.bz2<\/code>
\n                <\/div>\n
cd<\/code> mod_limitipconn-0.24<\/code>
\n                <\/div>\n
\/usr\/local\/apache2\/bin\/apxs<\/code> -c -i mod_limitipconn.c<\/code>
\n                <\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\u7f16\u8f91httpd.conf<\/p>\n

\n\n
\n
\n
<\/div>\n<\/td>\n
\n
ExtendedStatus On<\/code>
\n                <\/div>\n
LoadModule limitipconn_module modules\/mod_limitipconn.so<\/code>
\n                <\/div>\n
 <\/code> <\/div>\n
<ifModule mod_limitipconn.c><\/code>
\n                <\/div>\n
<location \/>                       #\u5bf9\u5e94\u6839\u76ee\u5f55<\/code>
\n                <\/div>\n
   <\/code>MaxConnPerIP 5                 \uff03\u6700\u5927\u5e76\u53d1\u6570\u4e3a5<\/code>
\n                <\/div>\n
   <\/code>NoIPLimit image\/*                \uff03\u5bf9\u56fe\u7247\u4e0d\u505a\u9650\u5236<\/code>
\n                <\/div>\n
<\/location><\/code>
\n                <\/div>\n
<location \/test>                    \uff03\u5bf9\u6839\u76ee\u5f55\u4e0b\u7684test\u76ee\u5f55\u505a\u9650\u5236<\/code>
\n                <\/div>\n
   <\/code>MaxConnPerIP 2                  \uff03\u6700\u5927\u5e76\u53d1\u6570\u4e3a2<\/code>
\n                <\/div>\n
<\/location><\/code>
\n                <\/div>\n
<\/ifModule><\/code>
\n                <\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\u5982\u679c\u60f3\u9650\u5236\u865a\u62df\u4e3b\u673a\u7684ip\u5e76\u53d1\u8fde\u63a5\u6570\uff0c\u53ef\u4ee5\u4fee\u6539extra\/httpd-vhost.conf\u628a IfModule mod_limitipconn.c \u8fd9\u4e00\u6bb5\u590d\u5236\u5230Virtualhost\u4e2d\u5c31\u53ef\u4ee5\u4e86\u3002<\/p>\n

\u6d4b\u8bd5\uff1a
\u6d4b\u8bd5\u5f88\u7b80\u5355\uff0c\u628a\u6700\u5927\u8fde\u63a5\u6570\u8c03\u5c0f\u4e00\u70b9\uff0c\u968f\u4fbf\u4e00\u4e2a\u6d4f\u89c8\u5668\u8bbf\u95ee\u9875\u9762\uff0c\u7136\u540e\u6309\u7740F5\uff0c\u8ba9\u9875\u9762\u4e0d\u65ad\u5237\u65b0\uff0c\u4e00\u4e0b\u5c31\u53ef\u4ee5\u5f39\u51fa503\u9519\u8bef<\/p>\n

\u4f7f\u7528mod_bandwidth\u6a21\u5757\u9650\u5236\u5e26\u5bbd
<\/strong>mod_bandwidth\u53ef\u4ee5\u5bf9IP\u7684\u5e76\u53d1\u6570\u8fdb\u884c\u63a7\u5236\uff0c\u4e5f\u53ef\u4ee5\u5bf9\u4e0b\u8f7d\u6d41\u91cf\u8fdb\u884c\u63a7\u5236\uff0c\u4e5f\u53ef\u4ee5\u5bf9\u67d0\u4e2a\u76ee\u5f55\u7684\u6d41\u91cf\u8fdb\u884c\u63a7\u5236\u3002
\u5b89\u88c5\uff1a<\/p>\n

\n\n
\n
\n
<\/div>\n<\/td>\n
\n
wget http:\/\/bwmod.sourceforge.net\/files\/mod_bw-0.7.tgz<\/a><\/code>
\n                <\/div>\n
tar zxvf mod_bw-0.7.tgz<\/code>
\n                <\/div>\n
cd mod_bw<\/code>
\n                <\/div>\n
\/usr\/local\/apache2\/bin\/apxs -c -i mod_bw.c<\/code>
\n                <\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\u7f16\u8f91httpd.conf\u914d\u7f6e\u6587\u4ef6\uff1a<\/p>\n

<\/p>\n

\n\n
\n
\n
<\/div>\n<\/td>\n
\n
LoadModule bw_module modules\/mod_bw.so<\/code>
\n                <\/div>\n
 <\/code> <\/div>\n
<virtualHost *:80><\/code>
\n                <\/div>\n
    <\/code>ServerName vhost1.cszhi.com<\/code>
\n                <\/div>\n
    <\/code>DocumentRoot  \/var\/www\/vhost1<\/code>
\n                <\/div>\n
    <\/code>BandwidthModule On<\/code>
\n                <\/div>\n
    <\/code>ForceBandWidthModule On<\/code>
\n                <\/div>\n
    <\/code>Bandwidth all 1024000<\/code>
\n                <\/div>\n
    <\/code>MinBandwidth all 50000     \uff03\u6bcf\u4e2a\u5ba2\u6237\u7aef\u6700\u9ad8\u901f\u5ea6\u53ef\u8fbe50KB<\/code>
\n                <\/div>\n
    <\/code>LargeFileLimit * 500 50000<\/code>
\n                <\/div>\n
    <\/code>MaxConnection all 6<\/code>
\n                <\/div>\n
<\/virtualHost><\/code>
\n                <\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\u5176\u5b83\u53c2\u6570\u4e8b\u4f8b\u8bf4\u660e\uff0c\u8be6\u7ec6\u7684\u89c1\u6e90\u7801\u5305\u91cc\u7684mod_bw.txt\uff1a<\/p>\n

<\/p>\n

\n\n
\n
\n
<\/div>\n<\/td>\n
\n
BandWidth localhost 0                   #\u5bf9localhost\u4e0d\u9650\u901f<\/code>
\n                <\/div>\n
BandWidth 192.168.1.5 102400            #\u5bf9192.168.1.5\u9650\u901f\u4e3a100KB<\/code>
\n                <\/div>\n
BandWidth \u201cu:^Mozilla(.*)\u201d 10240       #\u7528mozilla\u65f6\u9650\u901f10KB<\/code>
\n                <\/div>\n
BandWidth \u201cu:wget\u201d 102400           \uff03\u5982\u679c\u7528wget\u4e0b\u8f7d\u65f6\u9650\u901f10KB<\/code>
\n                <\/div>\n
MinBandWidth all -1                   \uff03\u4fdd\u8bc1\u6bcf\u4e2a\u5ba2\u6237\u7aef\u6700\u9ad8\u901f\u5ea6\u53ef\u8fbe10KB<\/code>
\n                <\/div>\n
LargeFileLimit .jpg 100 10240           \uff03jpg\u6587\u4ef6\u8d85\u8fc7100KB\uff0c\u9650\u901f10KB<\/code>
\n                <\/div>\n
\uff03\u4e0b\u9762\u7684510\u633a\u597d\uff0c\u5982\u679c\u4e0d\u8bbe\u7f6e\uff0capache\u81ea\u5df1\u4f1a\u62a5\u9519\uff0c\u5c31\u6839\u62a5404\u5dee\u4e0d\u591a\uff0c\u9875\u9762\u975e\u5e38\u7684\u4e11<\/code>
\n                <\/div>\n
ErrorDocument 510 \/exceed_speed.html<\/code>
\n                <\/div>\n
BandWidthError 510<\/code>
\n                <\/div>\n
MaxConnection all 10                    #\u6240\u6709ip\u6700\u5927\u8fde\u63a5\u6570\u4e3a10<\/code>
\n                <\/div>\n
MaxConnection 192.168.1.5 5             \uff03192.168.1.5\u6700\u5927\u8fde\u63a5\u6570\u4e3a5 <\/code>
\n                <\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\u6d4b\u8bd5\uff1a
\u4f7f\u7528mod_bw.so\u6a21\u5757\u524d\uff1a<\/p>\n

\"\"<\/p>\n

\u4f7f\u7528mod_bw.so\u6a21\u5757\u540e\uff1a<\/p>\n

\"\"<\/p>\n

\u5b89\u88c5\u8fc7\u7a0b\u4e2d\u53ef\u80fd\u51fa\u73b0\u7684\u95ee\u9898\uff1a<\/strong><\/p>\n

1\u3001\u6dfb\u52a0\u5b8cmod_bw.so\u6a21\u5757\uff0c\u91cd\u542fapache\u65f6\u51fa\u73b0\u9519\u8bef\uff1a<\/p>\n

<\/p>\n

\n\n
\n
\n
<\/div>\n<\/td>\n
\n
[root@vps httpd]# \/etc\/init.d\/httpd restart<\/code>
\n                <\/div>\n
Stopping httpd:                      [FAILED]<\/code>
\n                <\/div>\n
Starting httpd: httpd: Syntax error on line 203 of \/etc\/httpd\/conf\/httpd.conf: Cannot load \/etc\/httpd\/modules\/mod_bw.so into server: \/etc\/httpd\/modules\/mod_bw.so: undefined symbol: apr_atomic_cas<\/code>
\n                <\/div>\n
                              <\/code>[FAILED]<\/code>
\n                <\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\u4fee\u6539\u4e00\u4e0bmod_bw.c \u5c31\u53ef\u4ee5\uff1a<\/p>\n

<\/p>\n

\n\n
\n
\n
<\/div>\n<\/td>\n
\n
#ifdef APR_MAJOR_VERSION  \/\/\u6dfb\u52a0\u8fd9\u884c<\/code>
\n                <\/div>\n
#if (APR_MAJOR_VERSION < 1)<\/code>
\n                <\/div>\n
  <\/code>#define apr_atomic_inc32 apr_atomic_inc<\/code>
\n                <\/div>\n
  <\/code>#define apr_atomic_dec32 apr_atomic_dec<\/code>
\n                <\/div>\n
  <\/code>#define apr_atomic_add32 apr_atomic_add<\/code>
\n                <\/div>\n
  <\/code>#define apr_atomic_cas32 apr_atomic_cas<\/code>
\n                <\/div>\n
  <\/code>#define apr_atomic_set32 apr_atomic_set<\/code>
\n                <\/div>\n
#endif<\/code>
\n                <\/div>\n
#endif \/\/\u6dfb\u52a0\u8fd9\u884c<\/code>
\n                <\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\u91cd\u65b0\u7f16\u8bd1\uff1a<\/p>\n

\/usr\/local\/apache2\/bin\/apxs -c -i mod_bw.c<\/p>\n

2\u3001\u5982\u679c\u670d\u52a1\u5668\u6ca1\u6709\u5b89\u88c5apxs\uff0c\u53ef\u4ee5\u53c2\u7167\u4ee5\u4e0b\u65b9\u6cd5\u5b89\u88c5\uff1a<\/strong><\/p>\n


<\/strong>apxs\u662f\u4e00\u4e2a\u4e3aApache HTTP\u670d\u52a1\u5668\u7f16\u8bd1\u548c\u5b89\u88c5\u6269\u5c55\u6a21\u5757\u7684\u5de5\u5177\uff0c\u7528\u4e8e\u7f16\u8bd1\u4e00\u4e2a\u6216\u591a\u4e2a\u6e90\u7a0b\u5e8f\u6216\u76ee\u6807\u4ee3\u7801\u6587\u4ef6\u4e3a\u52a8\u6001\u5171\u4eab\u5bf9\u8c61\uff0c\u4f7f\u4e4b\u53ef\u4ee5\u7528\u7531mod_so\u63d0\u4f9b\u7684LoadModule\u6307\u4ee4\u5728\u8fd0\u884c\u65f6\u52a0\u8f7d\u5230Apache\u670d\u52a1\u5668\u4e2d\u3002<\/p>\n

\u8f93\u5165\u547d\u4ee4\u67e5\u770b\u662f\u5426\u6709httpd-devel\u8fd9\u4e2a\u5305\uff0c\u5982\u679c\u6ca1\u6709\u9700\u8981\u5b89\u88c5<\/p>\n

<\/p>\n

\n\n
\n
\n
<\/div>\n
<\/div>\n<\/td>\n
\n
rpm -qa|grep httpd<\/code>
\n                <\/div>\n
yum -y install httpd-devel<\/code>
\n                <\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

<\/p>\n","protected":false},"excerpt":{"rendered":"

\u672c\u6587\u7ae0\u6765\u7ed9\u5404\u4f4d\u540c\u5b66\u603b\u7ed3\u4e00\u4e0bAPACHE\u4e2d\u9650\u5236IP\u8fde\u63a5\u6570\u4e0eIP\u5e76\u53d1\u6570\u548c\u6d41\u91cf\u63a7\u5236\u5b9e\u73b0\u65b9\u6cd5\uff0c\u5982\u679c\u53ea\u9650\u5236\u8fde\u63a5\u6570\u636e\u6211\u4eec\u53ef […]<\/p>\n","protected":false},"author":1,"featured_media":256,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[],"class_list":["post-253","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/posts\/253"}],"collection":[{"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/comments?post=253"}],"version-history":[{"count":5,"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/posts\/253\/revisions"}],"predecessor-version":[{"id":260,"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/posts\/253\/revisions\/260"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/media\/256"}],"wp:attachment":[{"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/media?parent=253"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/categories?post=253"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/tags?post=253"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}