标签 缓存 下的文章

SeaCMS自定义Redis缓存服务器配置

如果您的Redis缓存服务使用了密码,或者需要修改Redis服务器地址和端口,需要修改下面两个文件:
文件1:/include/common.redis.func.php(共5处修改)
文件2:/admin/admin_ajax.php(共1处修改,admin请对应实际后台目录)

修改服务器地址和端口:

$redis->connect('127.0.0.1', 6379);

如有密码,则在$redis->connect('127.0.0.1', 6379);下增加一行:

$auth = $redis->auth('密码');

Nginx开启fastcgi_cache缓存加速

user  www www;

worker_processes auto;

error_log  /home/wwwlogs/nginx_error.log  crit;

pid        /usr/local/nginx/logs/nginx.pid;

#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 65535;

events
    {
        use epoll;
        worker_connections 65535;
        multi_accept on;
    }
    
http
    {
        include       mime.types;
        default_type  application/octet-stream;

        server_names_hash_bucket_size 128;
        client_header_buffer_size 32k;
        large_client_header_buffers 4 32k;
        client_max_body_size 50m;

        sendfile   on;
        tcp_nopush on;
        keepalive_timeout 60;
        tcp_nodelay on;
        
        gzip on;
        gzip_min_length  1k;
        gzip_buffers     4 16k;
        gzip_http_version 1.1;
        gzip_comp_level 2;
        gzip_types     text/plain application/javascript application/x-javascript text/javascript text/css application/xml application/xml+rss;
        gzip_vary on;
        gzip_proxied   expired no-cache no-store private auth;
        gzip_disable   "MSIE [1-6]\.";

        #limit_conn_zone $binary_remote_addr zone=perip:10m;
        ##If enable limit_conn_zone,add "limit_conn perip 10;" to server section.

        server_tokens off;
        access_log off;

        fastcgi_connect_timeout 300;
        fastcgi_send_timeout 300;
        fastcgi_read_timeout 300;
        fastcgi_buffer_size 64k;
        fastcgi_buffers 4 64k;
        fastcgi_busy_buffers_size 128k;
        fastcgi_temp_file_write_size 256k;
        
        #cache设置
        fastcgi_temp_path /usr/local/nginx/fastcgi_temp;
        fastcgi_cache_path /usr/local/nginx/fastcgi_cache levels=1:2 keys_zone=fastcgi_cache:32m inactive=10m max_size=50g;
        fastcgi_cache_key "$scheme$request_method$host$request_uri";
        fastcgi_cache_methods GET HEAD;
        fastcgi_cache fastcgi_cache; 
        fastcgi_cache_valid 200 302 1h; 
        fastcgi_cache_valid 301 1d; 
        fastcgi_cache_valid any 10m;
        fastcgi_cache_use_stale error timeout invalid_header http_500;
        #忽略一切nocache申明,避免不缓存伪静态等
        fastcgi_ignore_headers Cache-Control Expires Set-Cookie;
        fastcgi_ignore_client_abort on;
        #发送头信息到客户端 - 一般是浏览器
        add_header X-Cache-CFC "$upstream_cache_status - $upstream_response_time";

server
    {
        listen 80 default_server;
        #listen [::]:80 default_server ipv6only=on;
        server_name www.2dan.cc;
        index index.html index.htm index.php;
        root  /home/wwwroot/default;

        #error_page   404   /404.html;
        include enable-php.conf;

        location /nginx_status
        {
            stub_status on;
            access_log   off;
        }
        set $skip_cache 0;
        #post访问不缓存
        if ($request_method = POST) {
            set $skip_cache 1;
        }   
        #动态查询不缓存
        if ($query_string != "") {
            set $skip_cache 1;
        }   
        #后台等特定页面不缓存
        if ($request_uri ~* "/wp-admin/|/xmlrpc.php|wp-.*.php|/feed/|index.php|sitemap(_index)?.xml") {
            set $skip_cache 1;
        }   
        #对登录用户、评论过的用户不展示缓存
        if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in") {
            set $skip_cache 1;
        }
        location ~ [^/]\.php(/|$) {
            try_files $uri =404;
            fastcgi_pass  unix:/tmp/php-cgi.sock;
            fastcgi_index index.php;
            include fastcgi.conf;
            #新增的缓存规则
            fastcgi_cache_bypass $skip_cache;
            fastcgi_no_cache $skip_cache;
        }
        access_log  /home/wwwlogs/access.log;
    }
}

调节swap使用

今天发现一台8G内存的服务器可用内存剩余7G,但已经频繁使用swap。

解决这个问题之前,首先我们来了解一下linux系统的缓存机制:

linux会使用硬盘的一部分做为SWAP分区,用来进行进程调度--进程是正在运行的程序--把当前不用的进程调成‘等待(standby)‘,甚至‘睡眠(sleep)’,一旦要用,再调成‘活动(active)’,睡眠的进程就躺到SWAP分区睡大觉,把内存空出来让给‘活动’的进程。

如果内存够大,应当告诉linux不必过多的使用SWAP分区, 可以修改swappiness的值。
swappiness=0的时候表示最大限度使用物理内存,然后才是swap分区;
swappiness=100的时候表示积极的使用swap分区,并且把内存上的数据及时的搬运到swap空间里面。

- 阅读剩余部分 -

飞飞影视系统新整合播放器黑屏不提示下载

编辑 /Lib/Lib/Action/Admin/AdminAction.class.php 文件
找到

$pp_play.= 'var ff_bdhd="'.$config['play_bdhd'].'";'; 

在后面添加

$pp_play.= 'var ff_xigua="'.$config['play_xigua'].'";';
$pp_play.= 'var ff_xfplay="'.$config['play_xfplay'].'";';
$pp_play.= 'var ff_jjvod="'.$config['play_jjvod'].'";';

然后清空缓存,点击系统管理--网站信息配置--提交--搞定

Mysql缓存配置

从 MySQL4开始,出现了QueryCache查询缓存,如果使用了QueryCache,当接收到一个和之前同样的查询,服务器将会从缓存中检索结果,而不是再次分析和执行上次的查询。这样就大大提高了性能,节省时间,非常有用。

有时候,虽然你开启了Mysql查询缓存,但是如果你设置的查询缓存大小为0,这和没有开启缓存没什么区别。所以必须正确的设置才能真正打开查询缓存这个功能。

下面我用 mysql6.0 为例演示最常用的查询缓存设置

一: query_cache_type 使用查询缓存的方式

一般,我们会把 query_cache_type 设置为 ON,默认情况下应该是ON

mysql> select @@query_cache_type;
+——————–+
| @@query_cache_type |
+——————–+
| ON |
+——————–+

这样 当我们执行 select id,name from tableName; 这样就会用到查询缓存。

- 阅读剩余部分 -