HOME 生活记录运维/编程
作者/来源:yixinu.com
栏目:运维/编程
日期:2013-02-22 01:49:03

nginx缓存服务器:


服务器IP::

       eth0      addr:202.202.4.104  Bcast:202.202.255.255  Mask:255.255.0.0

       eth0:0   addr:202.202.2.155  Bcast:202.202.255.255  Mask:255.255.0.0

系统:CentOS release 6.2  Linux version 2.6.32-220.el6.i686


1、源码安装nginx,/usr/local/nginx ,具体步骤这里就不写了,方法多的是。。

2、nginx配置文件:

user  nobody;
worker_processes  1;
error_log  logs/error.log crit; 
pid        logs/nginx.pid;
worker_rlimit_nofile 65535;
events {
    use epoll;
    worker_connections  65535;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    proxy_cache_path /data/nginx/cache levels=1:2 keys_zone=cache_one:60m inactive=1d max_size=35g;
    sendfile        on;
    keepalive_timeout  65;
    server {
        listen       80;
        server_name  www.ga.com;
        charset utf-8;
        #access_log  logs/www.ga.com.access.log  main;
        location / {
            root   /usr/local/nginx/html;
            index  index.html index.htm;
              proxy_pass http://202.202.14.155; 
                    proxy_set_header Host $host;
                    proxy_set_header X-Real-IP $remote_addr;
                    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                    client_max_body_size 50m;
                    client_body_buffer_size 256k;
                    proxy_connect_timeout 30;
                    proxy_send_timeout 30;
                    proxy_read_timeout 60;
                    proxy_buffer_size 4k;
                    proxy_buffers 4 32k;
                    proxy_busy_buffers_size 64k;
                    proxy_temp_file_write_size 64k;
                    proxy_max_temp_file_size 128m;
            proxy_intercept_errors off;
                  
                    proxy_cache cache_one;
                    proxy_cache_valid  200 304 301 302 1d;
                    proxy_cache_valid  any 1d;
        }
        #error_page  404              /404.html;
        #redirect server error pages to the static page /50x.html
        error_page   500 502 503 504 404  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
    # HTTPS server
    #
    #server {
    #    listen       443;
    #    server_name  localhost;
    #    ssl                  on;
    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;
    #    ssl_session_timeout  5m;
    #    ssl_protocols  SSLv2 SSLv3 TLSv1;
    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers   on;
    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}
}


LAM P服务器:


服务器IP: eth0  地址:202.202.14.155  广播:202.202.255.255  掩码:255.255.0.0

系统:Linux web.ga.com 2.6.38-8-generic #42-Ubuntu SMP Mon Apr 11 03:31:50 UTC 2011 i686 i686 i386 GNU/Linux


1、安装apache  php mysql ,安装步骤这里就不说了,这个更简单

2、安装inotify-tools-3.14

root@web:~# cd /usr/local/src/
root@web:/usr/local/src# tar -xzvf inotify-tools-3.14.tar.gz
......
root@web:/usr/local/src# cd inotify-tools-3.14/
root@web:/usr/local/src/inotify-tools-3.14# ./configure
root@web:/usr/local/src/inotify-tools-3.14# make; make install
# 安装完成后会生成inotifywait和inotifywatch两个指令
root@web:/usr/local/src/inotify-tools-3.14# ll /usr/local/bin/inotifywa*
-rwxr-xr-x 1 root root 44972 2013-01-24 10:11 /usr/local/bin/inotifywait*
-rwxr-xr-x 1 root root 45594 2013-01-24 10:11 /usr/local/bin/inotifywatch*

3、写一个更新缓存的shell,代码如下:

root@web:~# cat ~/shell/monit.sh 
#!/usr/bin/env bash
     
src1=/var/www/
src2=/var/lib/mysql/
     
/usr/local/bin/inotifywait -mrq --timefmt '%d/%m/%y %H;%M' --format '%T %w%f%e' -e modify,delete,create,attrib $src1 $src2 
| while read files
  do
    ssh root@202.202.4.104 "rm /data/nginx/cache/* -rf"
  done

这个shell表示,只要网站有后台更新操作或上传了源码文件,就删除缓存服务器里面的缓存文件,到下一次有人访问网站时,就会自动更新缓存。


4、后台执行这个shell即可。

完成。

分享到:

Copyright © 2013-2014 yixinu.com 湘ICP备14004402号

QQ:316686606  Email: 316686606@qq.com