Jiliuke

激流客

请把以下程序相应的部分加到贵司的源程序中,以实现获取最终客户IP代码的功能。

如果您需要其它语言的例子,我们也可以提供。需要注意的是这些代码是在您切换CDN后生效,如未使用CDN服务,这些代码是无法获得用户IP的。

CDN回源请求时会在请求中加一个头,该头中的ip是最终客户的ip:

Cdn-Src-Ip:192.168.0.10

下面是分别用java和C#,Asp写的取头的片段。

Java:

String srcIp = request.getHeader(“Cdn-Src-Ip”); if(srcIp == null){ srcIp = request.getRemoteAddr();

}

[注]request是HttpServletRequest类型的参数,无论是直接写serverlet还是用struts都会传入该参数。

Asp(用C#):

String srcIp = Request.Headers[“Cdn-Src-Ip”];

if(srcIp == null){

  srcIp = Request.UserHostAddress;

}

Asp:

<% Request.ServerVariables(“HTTP_Cdn-Src-Ip”) %>

PHP:

$user_IP = ($_SERVER[“HTTP_CDN_SRC_IP”]);

我们在管理服务器或vps的时候,经常要上传和下载数据。比如当我们需要把数据从一个服务器搬到另一个服务器的时候,通常是从第一个服务器下载数据到我们电脑,再到ftp工具上传下载好的数据到远程服务器。但这样即浪费时间,又浪费精力。我们何不先在第一台服务器打包好,就直接传输数据到另一台服务器呢?而Linux scp命令则刚好能实现两台服务器之间传输数据的作用。

什么是scp

 scp就是secure copy,是用来进行远程文件拷贝的。数据传输使用 ssh,并且和ssh 使用相同的认证方式,提供相同的安全保证 。 与rcp 不同的是,scp 在需要进行验证时会要求你输入密码或口令。

scp的用法

从 本地 复制到 远程 命令基本格式: scp [可选参数] 本地文件名 远程用户名@远程地址:远程文件或目录 复制文件例子:

  1. scp /home/backup.zip root@www.example.com:/home/others/backup
  2. scp /home/backup.zip root@www.example.com:/home/others/otherbackup.zip

第一个是本地文件backup.zip发送到远程backup目录下。 第二个是本地文件backup.zip发送到远程otherbackup.zip文件。 复制目录例子:

  1. scp -r /home/backup root@www.example.com:/home/others/

复制本地目录backup到远程目录others 从 远程 复制到 本地 命令基本格式: scp [可选参数] 远程用户名@远程地址:远程文件或目录 本地文件名 例子:

  1. scp root@www.example.com:/home/others/bakcup.zip /home/newbackup.zip
  2. scp -r root@www.example.com:/home/backup /home/other/

第一个是下载远程文件backup.zip到本地文件newbackup.zip。 第二个是下载远程目录bakcup到本地目录other。 scp可选参数:

参数

解释

-v

和大多数 linux 命令中的 -v 意思一样 , 用来显示进度 . 可以用来查看连接 , 认证 , 或是配置错误 .

-C

使能压缩选项

-P

选择端口 . 注意 -p 已经被 rcp 使用 .

-4

强行使用 IPV4 地址 .

-6

强行使用 IPV6 地址 .

// 手机号码验证
jQuery.validator.addMethod(“mobile”, function(value, element) {
    var length = value.length;
    var mobile =  /^(((13[0-9]{1})|(15[0-9]{1}))+\d{8})$/
    return this.optional(element) || (length == 11 && mobile.test(value));
}, “手机号码格式错误”);   

// 电话号码验证   
jQuery.validator.addMethod(“phone”, function(value, element) {
    var tel = /^(0[0-9]{2,3}\-)?([2-9][0-9]{6,7})+(\-[0-9]{1,4})?$/;
    return this.optional(element) || (tel.test(value));
}, “电话号码格式错误”);

// 邮政编码验证   
jQuery.validator.addMethod(“zipCode”, function(value, element) {
    var tel = /^[0-9]{6}$/;
    return this.optional(element) || (tel.test(value));
}, “邮政编码格式错误”);

// QQ号码验证   
jQuery.validator.addMethod(“qq”, function(value, element) {
    var tel = /^[1-9]\d{4,9}$/;
    return this.optional(element) || (tel.test(value));
}, “qq号码格式错误”);

// IP地址验证
jQuery.validator.addMethod(“ip”, function(value, element) {
    var ip = /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
    return this.optional(element) || (ip.test(value) && (RegExp.$1 < 256 && RegExp.$2 < 256 && RegExp.$3 < 256 && RegExp.$4 < 256));
}, “Ip地址格式错误”);

// 字母和数字的验证
jQuery.validator.addMethod(“chrnum”, function(value, element) {
    var chrnum = /^([a-zA-Z0-9]+)$/;
    return this.optional(element) || (chrnum.test(value));
}, “只能输入数字和字母(字符A-Z, a-z, 0-9)”);

// 中文的验证
jQuery.validator.addMethod(“chinese”, function(value, element) {
    var chinese = /^[\u4e00-\u9fa5]+$/;
    return this.optional(element) || (chinese.test(value));
}, “只能输入中文”);

// 下拉框验证
$.validator.addMethod(“selectNone”, function(value, element) {
    return value == “请选择”;
}, “必须选择一项”);

// 字节长度验证
jQuery.validator.addMethod(“byteRangeLength”, function(value, element, param) {
    var length = value.length;
    for (var i = 0; i < value.length; i++) {
        if (value.charCodeAt(i) > 127) {
            length++;
        }
    }
    return this.optional(element) || (length >= param[0] && length <= param[1]);
}, $.validator.format(“请确保输入的值在{0}-{1}个字节之间(一个中文字算2个字节)”));

// 字符验证   
jQuery.validator.addMethod(“stringCheck”, function(value, element) {   
  return this.optional(element) || /^[\u0391-\uFFE5\w]+$/.test(value);   
}, “只能包括中文字、英文字母、数字和下划线”);   

// 中文字两个字节   
jQuery.validator.addMethod(“byteRangeLength”, function(value, element, param) {   
  var length = value.length;   
  for(var i = 0; i < value.length; i++){   
  if(value.charCodeAt(i) > 127){   
  length++;   
  }   
  }   
  return this.optional(element) || ( length >= param[0] && length <= param[1] );   
}, “请确保输入的值在3-15个字节之间(一个中文字算2个字节)”);   

// 身份证号码验证   
jQuery.validator.addMethod(“isIdCardNo”, function(value, element) {   
  return this.optional(element) || isIdCardNo(value);   
}, “请正确输入您的身份证号码”);   

// 手机号码验证   
jQuery.validator.addMethod(“isMobile”, function(value, element) {   
  var length = value.length;   
  var mobile = /^(((13[0-9]{1})|(15[0-9]{1}))+\d{8})$/;   
  return this.optional(element) || (length == 11 && mobile.test(value));   
}, “请正确填写您的手机号码”);   

// 电话号码验证   
jQuery.validator.addMethod(“isTel”, function(value, element) {   
  var tel = /^\d{3,4}-?\d{7,9}$/; //电话号码格式010-12345678   
  return this.optional(element) || (tel.test(value));   
}, “请正确填写您的电话号码”);   

// 联系电话(手机/电话皆可)验证   
jQuery.validator.addMethod(“isPhone”, function(value,element) {   
  var length = value.length;   
  var mobile = /^(((13[0-9]{1})|(15[0-9]{1}))+\d{8})$/;   
  var tel = /^\d{3,4}-?\d{7,9}$/;   
  return this.optional(element) || (tel.test(value) || mobile.test(value));   

}, “请正确填写您的联系电话”);   

// 邮政编码验证   
jQuery.validator.addMethod(“isZipCode”, function(value, element) {   
  var tel = /^[0-9]{6}$/;   
  return this.optional(element) || (tel.test(value));   
}, “请正确填写您的邮政编码”);

1.Zepto.js 是专门为现代智能手机浏览器退出的 Javascript 框架, 拥有和jQuery相似的语法, 但是和jQuery相比下来, 他有很多优点, 大小方面 , 压缩后的 zepto.min.js 大小只有21K, 使用服务器端 gzip 压缩后大小只有5~10K, 可以说非常的小, 但是功能很齐全, 多出来了一些触摸屏的事件 , 它唯一不支持的就是万恶的IE, 不过用它来开发iPhone和Android网页绝对是首选了.

2.swipe js -移动端WEB页面内容触摸滑动类库

**3.Touch.js **是移动设备上的手势识别与事件库, 由百度云Clouda团队维护,也是在百度内部广泛使用的开发工具.

本日志内容来自互联网和平日使用经验,整理一下方便日后参考。

正则表达式匹配,其中:

  1. * ~ 为区分大小写匹配
  2. * ~* 为不区分大小写匹配
  3. * !和!*分别为区分大小写不匹配及不区分大小写不匹配

文件及目录匹配,其中:

  1. * -f和!-f用来判断是否存在文件
  2. * -d和!-d用来判断是否存在目录
  3. * -e和!-e用来判断是否存在文件或目录
  4. * -x和!-x用来判断文件是否可执行

flag标记有:

  1. * last 相当于Apache里的[L]标记,表示完成rewrite
  2. * break 终止匹配, 不再匹配后面的规则
  3. * redirect 返回302临时重定向 地址栏会显示跳转后的地址
  4. * permanent 返回301永久重定向 地址栏会显示跳转后的地址

一些可用的全局变量有,可以用做条件判断(待补全)

  1. $args
  2. $content_length
  3. $content_type
  4. $document_root
  5. $document_uri
  6. $host
  7. $http_user_agent
  8. $http_cookie
  9. $limit_rate
  10. $request_body_file
  11. $request_method
  12. $remote_addr
  13. $remote_port
  14. $remote_user
  15. $request_filename
  16. $request_uri
  17. $query_string
  18. $scheme
  19. $server_protocol
  20. $server_addr
  21. $server_name
  22. $server_port
  23. $uri

结合QeePHP的例子

  1. if (!-d $request_filename) {
  2. rewrite ^/([a-z-A-Z]+)/([a-z-A-Z]+)/?(.*)$ /index.php?namespace=user&controller=$1&action=$2&$3 last;
  3. rewrite ^/([a-z-A-Z]+)/?$ /index.php?namespace=user&controller=$1 last;
  4. break;

多目录转成参数 abc.domian.com/sort/2 => abc.domian.com/index.php?act=sort&name=abc&id=2

  1. if ($host ~* (.*)/.domain/.com) {
  2. set $sub_name $1;
  3. rewrite ^/sort//(/d+)//?$ /index.php?act=sort&cid=$sub_name&id=$1 last;
  4. }

目录对换 /123456/xxxx -> /xxxx?id=123456

  1. rewrite ^/(/d+)/(.+)/ /$2?id=$1 last;

例如下面设定nginx在用户使用ie的使用重定向到/nginx-ie目录下:

  1. if ($http_user_agent ~ MSIE) {
  2. rewrite ^(.*)$ /nginx-ie/$1 break;
  3. }

目录自动加“/”

  1. if (-d $request_filename){
  2. rewrite ^/(.*)([^/])$ http://$host/$1$2/ permanent;
  3. }

禁止htaccess

  1. location ~//.ht {
  2.          deny all;
  3.      }

禁止多个目录

  1. location ~ ^/(cron|templates)/ {
  2.          deny all;
  3. break;
  4.      }

禁止以/data开头的文件 可以禁止/data/下多级目录下.log.txt等请求;

  1. location ~ ^/data {
  2.          deny all;
  3.      }

禁止单个目录 不能禁止.log.txt能请求

  1. location /searchword/cron/ {
  2.          deny all;
  3.      }

禁止单个文件

  1. location ~ /data/sql/data.sql {
  2.          deny all;
  3.      }

给favicon.ico和robots.txt设置过期时间; 这里为favicon.ico为99天,robots.txt为7天并不记录404错误日志

  1. location ~(favicon.ico) {

  2.                  log_not_found off;

  3. expires 99d;

  4. break;

  5.      }

  6.      location ~(robots.txt) {

  7.                  log_not_found off;

  8. expires 7d;

  9. break;

  10.      }

设定某个文件的过期时间;这里为600秒,并不记录访问日志

  1. location ^~ /html/scripts/loadhead_1.js {
  2.                  access_log   off;
  3.                  root /opt/lampp/htdocs/web;
  4. expires 600;
  5. break;
  6.        }

文件反盗链并设置过期时间 这里的return 412 为自定义的http状态码,默认为403,方便找出正确的盗链的请求 “rewrite ^/ http://leech.c1gstudio.com/leech.gif;”显示一张防盗链图片 “access_log off;”不记录访问日志,减轻压力 “expires 3d”所有文件3天的浏览器缓存

  1. location ~* ^.+/.(jpg|jpeg|gif|png|swf|rar|zip|css|js)$ {
  2. valid_referers none blocked *.c1gstudio.com *.c1gstudio.net localhost 208.97.167.194;
  3. if ($invalid_referer) {
  4.     rewrite ^/ http://leech.c1gstudio.com/leech.gif;
  5.     return 412;
  6.     break;
  7. }
  8.                  access_log   off;
  9.                  root /opt/lampp/htdocs/web;
  10. expires 3d;
  11. break;
  12.      }

只充许固定ip访问网站,并加上密码

  1. root  /opt/htdocs/www;
  2. allow   208.97.167.194;
  3. allow   222.33.1.2;
  4. allow   231.152.49.4;
  5. deny    all;
  6. auth_basic “C1G_ADMIN”;
  7. auth_basic_user_file htpasswd;

将多级目录下的文件转成一个文件,增强seo效果 /job-123-456-789.html 指向/job/123/456/789.html

  1. rewrite ^/job-([0-9]+)-([0-9]+)-([0-9]+)/.html$ /job/$1/$2/jobshow_$3.html last;

将根目录下某个文件夹指向2级目录 如/shanghaijob/ 指向 /area/shanghai/ 如果你将last改成permanent,那么浏览器地址栏显是/location/shanghai/

  1. rewrite ^/([0-9a-z]+)job/(.*)$ /area/$1/$2 last;

上面例子有个问题是访问/shanghai 时将不会匹配

  1. rewrite ^/([0-9a-z]+)job$ /area/$1/ last;
  2. rewrite ^/([0-9a-z]+)job/(.*)$ /area/$1/$2 last;

这样/shanghai 也可以访问了,但页面中的相对链接无法使用, 如./list_1.html真实地址是/area/shanghia/list_1.html会变成/list_1.html,导至无法访问。

那我加上自动跳转也是不行咯 (-d $request_filename)它有个条件是必需为真实目录,而我的rewrite不是的,所以没有效果

  1. if (-d $request_filename){
  2. rewrite ^/(.*)([^/])$ http://$host/$1$2/ permanent;
  3. }

知道原因后就好办了,让我手动跳转吧

  1. rewrite ^/([0-9a-z]+)job$ /$1job/ permanent;
  2. rewrite ^/([0-9a-z]+)job/(.*)$ /area/$1/$2 last;

文件和目录不存在的时候重定向:

  1. if (!-e $request_filename) {
  2. proxy_pass http://127.0.0.1;
  3. }

域名跳转

  1. server
  2.      {
  3.              listen       80;
  4.              server_name  jump.c1gstudio.com;
  5.              index index.html index.htm index.php;
  6.              root  /opt/lampp/htdocs/www;
  7.              rewrite ^/ http://www.c1gstudio.com/;
  8.              access_log  off;
  9.      }

多域名转向

  1. server_name  www.c1gstudio.com www.c1gstudio.net;
  2.              index index.html index.htm index.php;
  3.              root  /opt/lampp/htdocs;
  4. if ($host ~ “c1gstudio/.net”) {
  5. rewrite ^(.*) http://www.c1gstudio.com$1 permanent;
  6. }

三级域名跳转

  1. if ($http_host ~* “^(.*)/.i/.c1gstudio/.com$”) {
  2. rewrite ^(.*) http://top.yingjiesheng.com$1;
  3. break;
  4. }

域名镜向

  1. server
  2.      {
  3.              listen       80;
  4.              server_name  mirror.c1gstudio.com;
  5.              index index.html index.htm index.php;
  6.              root  /opt/lampp/htdocs/www;
  7.              rewrite ^/(.*) http://www.c1gstudio.com/$1 last;
  8.              access_log  off;
  9.      }

某个子目录作镜向

  1. location ^~ /zhaopinhui {
  2.   rewrite ^.+ http://zph.c1gstudio.com/ last;
  3.   break;
  4.      }

discuz ucenter home (uchome) rewrite

  1. rewrite ^/(space|network)-(.+)/.html$ /$1.php?rewrite=$2 last;
  2. rewrite ^/(space|network)/.html$ /$1.php last;
  3. rewrite ^/([0-9]+)$ /space.php?uid=$1 last;

discuz 7 rewrite

  1. rewrite ^(.*)/archiver/((fid|tid)-[/w/-]+/.html)$ $1/archiver/index.php?$2 last;
  2. rewrite ^(.*)/forum-([0-9]+)-([0-9]+)/.html$ $1/forumdisplay.php?fid=$2&page=$3 last;
  3. rewrite ^(.*)/thread-([0-9]+)-([0-9]+)-([0-9]+)/.html$ $1/viewthread.php?tid=$2&extra=page/%3D$4&page=$3 last;
  4. rewrite ^(.*)/profile-(username|uid)-(.+)/.html$ $1/viewpro.php?$2=$3 last;
  5. rewrite ^(.*)/space-(username|uid)-(.+)/.html$ $1/space.php?$2=$3 last;
  6. rewrite ^(.*)/tag-(.+)/.html$ $1/tag.php?name=$2 last;

给discuz某版块单独配置域名

  1. server_name  bbs.c1gstudio.com news.c1gstudio.com;

  2.      location = / {

  3.         if ($http_host ~ news/.c1gstudio.com$) {

  4.   rewrite ^.+ http://news.c1gstudio.com/forum-831-1.html last;

  5.   break;

  6. }

  7.      }

discuz ucenter 头像 rewrite 优化

  1. location ^~ /ucenter {

  2.      location ~ .*/.php?$

  3.      {

  4.   #fastcgi_pass  unix:/tmp/php-cgi.sock;

  5.   fastcgi_pass  127.0.0.1:9000;

  6.   fastcgi_index index.php;

  7.   include fcgi.conf;

  8.      }

  9.      location /ucenter/data/avatar {

  10. log_not_found off;

  11. access_log   off;

  12. location ~ /(.*)_big/.jpg$ {

  13.     error_page 404 /ucenter/images/noavatar_big.gif;

  14. }

  15. location ~ /(.*)_middle/.jpg$ {

  16.     error_page 404 /ucenter/images/noavatar_middle.gif;

  17. }

  18. location ~ /(.*)_small/.jpg$ {

  19.     error_page 404 /ucenter/images/noavatar_small.gif;

  20. }

  21. expires 300;

  22. break;

  23.      }

  24.                        }

jspace rewrite

  1. location ~ .*/.php?$

  2.              {

  3.                   #fastcgi_pass  unix:/tmp/php-cgi.sock;

  4.                   fastcgi_pass  127.0.0.1:9000;

  5.                   fastcgi_index index.php;

  6.                   include fcgi.conf;

  7.              }

  8.              location ~* ^/index.php/

  9.              {

  10.     rewrite ^/index.php/(.*) /index.php?$1 break;

  11.                   fastcgi_pass  127.0.0.1:9000;

  12.                   fastcgi_index index.php;

  13.                   include fcgi.conf;

  14.              }

1.flexslider 预览地址:FlexSlider2 下载插件 网盘地址:FlexSlider2简版demo HTML关键代码说明 //使用flexslider插件 $(window).load(function() { $(‘.flexslider’).flexslider({ //参数设置在这里 animation: “slide”,//使用滑动效果 slideshowSpeed: 2300//切换速度 }); }); FlexSlisder参数说明 $(window).load(function() { $(‘.flexslider’).flexslider({ animation: “fade”, //String: Select your animation type, “fade” or “slide”图片变换方式:淡入淡出或者滑动 direction: “horizontal”, //String: Select the sliding direction, “horizontal” or “vertical”图片设置为滑动式时的滑动方向:左右或者上下 slideshow: true, //Boolean: Animate slider automatically 载入页面时,是否自动播放 slideshowSpeed: 7000, //Integer: Set the speed of the slideshow cycling, in milliseconds 自动播放速度毫秒 animationDuration: 600, //Integer: Set the speed of animations, in milliseconds动画淡入淡出效果延时 directionNav: true, //Boolean: Create navigation for previous/next navigation? (true/false)是否显示左右控制按钮 controlNav: true, //Boolean: Create navigation for paging control of each clide? Note: Leave true for manualControls usage是否显示控制菜单 keyboardNav: true, //Boolean: Allow slider navigating via keyboard left/right keys键盘左右方向键控制图片滑动 mousewheel: false, //Boolean: Allow slider navigating via mousewheel鼠标滚轮控制制图片滑动 prevText: “Previous”, //String: Set the text for the “previous” directionNav item nextText: “Next”, //String: Set the text for the “next” directionNav item pausePlay: false, //Boolean: Create pause/play dynamic element pauseText: ‘Pause’, //String: Set the text for the “pause” pausePlay item playText: ‘Play’, //String: Set the text for the “play” pausePlay item randomize: false, //Boolean: Randomize slide order 是否随即幻灯片 slideToStart: 0, //Integer: The slide that the slider should start on. Array notation (0 = first slide)初始化第一次显示图片位置 animationLoop: true, //Boolean: Should the animation loop? If false, directionNav will received “disable” classes at either end 是否循环滚动 pauseOnAction: true, //Boolean: Pause the slideshow when interacting with control elements, highly recommended. pauseOnHover: false, //Boolean: Pause the slideshow when hovering over slider, then resume when no longer hovering controlsContainer: “”, //Selector: Declare which container the navigation elements should be appended too. Default container is the flexSlider element. Example use would be “.flexslider-container”, “#container”, etc. If the given element is not found, the default action will be taken. manualControls: “”, //Selector: Declare custom control navigation. Example would be “.flex-control-nav li” or “#tabs-nav li img”, etc. The number of elements in your controlNav should match the number of slides/tabs.自定义控制导航 manualControlEvent:””, //String:自定义导航控制触发事件:默认是click,可以设定hover start: function(){}, //Callback: function(slider) - Fires when the slider loads the first slide before: function(){}, //Callback: function(slider) - Fires asynchronously with each slider animation after: function(){}, //Callback: function(slider) - Fires after each slider animation completes end: function(){} //Callback: function(slider) - Fires when the slider reaches the last slide (asynchronous) }); });

开源镜像站:即一个放置开源系统镜像文件的站点.免费提供镜像文件下载下来可以刻盘也可以直接用虚拟光驱安装操作系统,开源的软件,LINUX源码网站 公司类 搜狐开源镜像站:http://mirrors.sohu.com/ 网易开源镜像站:http://mirrors.163.com/ 开源中国:http://mirrors.oschina.net/ 首都在线科技股份有限公司:http://mirrors.yun-idc.com/ 阿里云开源镜像:http://mirrors.aliyun.com/ LUPA:http://mirror.lupaworld.com/ 常州贝特康姆软件技术有限公司(原cn99):http://centos.bitcomm.cn/ 特别类 centos镜像站:http://www.centos.org/download/mirrors/ 大学类 中山大学镜像:http://mirror.sysu.edu.cn/ 山东理工大学:http://mirrors.sdutlinux.org/ 哈尔滨工业大学:http://run.hit.edu.cn/ 中国地质大学:http://cugbteam.org/ 大连理工大学:http://mirror.dlut.edu.cn/ 西南林业大学: http://cs3.swfu.edu.cn/cs3guide.html 北京化工大学(仅教育网可以访问),包含 CentOS 镜像:http://ubuntu.buct.edu.cn/ 天津大学:http://mirror.tju.edu.cn/ 西南大学:http://linux.swu.edu.cn/swudownload/Distributions/ 青岛大学:http://mirror.qdu.edu.cn/ 南京师范大学:http://mirrors.njnu.edu.cn/ 大连东软信息学院: http://mirrors.neusoft.edu.cn/ 浙江大学:http://mirrors.zju.edu.cn/ 兰州大学:http://mirror.lzu.edu.cn/ 厦门大学:http://mirrors.xmu.edu.cn/ 北京理工大学: http://mirror.bit.edu.cn (IPv4 only) http://mirror.bit6.edu.cn (IPv6 only) 北京交通大学: http://mirror.bjtu.edu.cn (IPv4 only) http://mirror6.bjtu.edu.cn (IPv6 only) http://debian.bjtu.edu.cn (IPv4+IPv6) 上海交通大学: http://ftp.sjtu.edu.cn/ (IPv4 only) http://ftp6.sjtu.edu.cn (IPv6 only) 清华大学: http://mirrors.tuna.tsinghua.edu.cn/ (IPv4+IPv6) http://mirrors.6.tuna.tsinghua.edu.cn/ (IPv6 only) http://mirrors.4.tuna.tsinghua.edu.cn/ (IPv4 only) 中国科学技术大学: http://mirrors.ustc.edu.cn/ (IPv4+IPv6) http://mirrors4.ustc.edu.cn/ http://mirrors6.ustc.edu.cn/ 东北大学: http://mirror.neu.edu.cn/ (IPv4 only) http://mirror.neu6.edu.cn/ (IPv6 only) 华中科技大学: http://mirrors.hust.edu.cn/ http://mirrors.hustunique.com/ 电子科技大学:http://ubuntu.uestc.edu.cn/ 电子科大凝聚工作室(Raspbian单一系统镜像) http://raspbian.cnssuestc.org/ 电子科大星辰工作室(少数小众发布版镜像) http://mirrors.stuhome.net/ PyPi 镜像 豆瓣:http://pypi.douban.com/ 山东理工大学:http://pypi.sdutlinux.org/ 中山大学:http://mirror.sysu.edu.cn/pypi/ V2EX:http://pypi.v2ex.com/simple/ RubyGems 镜像 中山大学:http://mirror.sysu.edu.cn/rubygems/ 山东理工大学:http://ruby.sdutlinux.org/ 淘宝网:http://ruby.taobao.org/ npm 镜像 cnpmjs:http://cnpmjs.org/

Redis介绍 Redis本质上一个Key/Value数据库,与Memcached类似的 NoSQL型数据库,但是他的数据可以持久化的保存在磁盘上,解决了服务重启后数据不丢失的问题,他的值可以是string(字符串)、list(列 表)、sets(集合)或者是ordered sets(被排序的集合),所有的数据类型都具有push/pop、add/remove、执行服务端的 并集、交集、两个sets集中的差别等等操作,这些操作都是具有原子性的,Redis还支持各种不同的排序能力 Redis 2.0更是增加了很多新特性,如:提升了性能、增加了新的数据类型、更少的利用内存(AOF和VM) Redis支持绝大部分主流的开发语言,如:C、Java、C#、PHP、Perl、Python、Lua、Erlang、Ruby等等 官网:http://code.google.com/p/redis/ Redis性能 根据Redis官方的测试结果:在50个并发的情况下请求10w次,写的速度是110000次/s,读的速度是81000次/s 地址:http://code.google.com/p/redis/wiki/Benchmarks 安装过程 最新稳定版,Redis 2.0.4 stable wget http://redis.googlecode.com/files/redis-2.0.4.tar.gz tar zxf redis-2.0.4.tar.gz cd redis-2.0.4 与其它软件不同的是,不需要configure。 make 装完了。 创建一个目录 mkdir /usr/local/redis2 cp redis-server redis-benchmark redis-cli redis.conf /usr/local/redis2 启动: ./redis-server > /dev/null & 测试: 存值: ./redis-cli set hx value 取值: ./redis-cli get hx 附:redis.conf配置文件: 引用 #是否作为守护进程运行 daemonize yes #配置pid的存放路径及文件名,默认为当前路径下 pidfile redis.pid #Redis默认监听端口 port 6379 #客户端闲置多少秒后,断开连接 timeout 300 #日志显示级别 loglevel verbose #指定日志输出的文件名,也可指定到标准输出端口 logfile stdout #设置数据库的数量,默认连接的数据库是0,可以通过select N来连接不同的数据库 databases 16 #保存数据到disk的策略 #当有一条Keys数据被改变是,900秒刷新到disk一次 save 900 1 #当有10条Keys数据被改变时,300秒刷新到disk一次 save 300 10 #当有1w条keys数据被改变时,60秒刷新到disk一次 save 60 10000 #当dump .rdb数据库的时候是否压缩数据对象 rdbcompression yes #dump数据库的数据保存的文件名 dbfilename dump.rdb #Redis的工作目录 dir /home/falcon/redis-2.0.0/ ########### Replication ##################### #Redis的复制配置 # slaveof # masterauth ############## SECURITY ########### # requirepass foobared ############### LIMITS ############## #最大客户端连接数 # maxclients 128 #最大内存使用率 # maxmemory ########## APPEND ONLY MODE ######### #是否开启日志功能 appendonly no # 刷新日志到disk的规则 # appendfsync always appendfsync everysec # appendfsync no ################ VIRTUAL MEMORY ########### #是否开启VM功能 vm-enabled no # vm-enabled yes vm-swap-file logs/redis.swap vm-max-memory 0 vm-page-size 32 vm-pages 134217728 vm-max-threads 4 ############# ADVANCED CONFIG ############### glueoutputbuf yes hash-max-zipmap-entries 64 hash-max-zipmap-value 512 #是否重置Hash表 activerehashing yes 安装php客户端 使用rediska做为redis的PHP客户端。 安装peal cd /usr/local/webserver/php/ curl http://pear.php.net/go-pear | /usr/local/webserver/php/bin/php pear channel-discover pear.geometria-lab.net pear install geometria-lab/Rediska-beta php使用参考:http://rediska.geometria-lab.ru/documentation/usage/ 测试代码大致如下: $options = array( ‘servers’ => array( array(‘host’ => ‘127.0.0.1’, ‘port’ => 6379) ) ); require_once ‘/usr/local/webserver/php/PEAR/Rediska.php’; $rediska = new Rediska($options); $redis = new Rediska_Key(‘key’); $redis->setValue(‘value’); $value = $redis->getValue(‘key’); echo $value; 分别测试了下,使用mc,mcdb和redis。 引用 1000次 memcache:82.2749ms memcachedb:84.4438ms include语句放在循环里面 redis:463.0890ms memcache:81.6891ms memcachedb:86.5080ms include文件放在外面 redis:237.6881ms 5000次 memcache:388.6840ms memcachedb:421.1838ms include语句放在循环外面 redis:1,075.9599ms redis本身性能优越,但由于php客户端需要包含不少文件,反而性能比mcdb差不少。如果没有list,set等存储要求,用mcdb足已! @@10-12-24@@UPDATE:增加了PHP测试代码。

在VMware里克隆出来的CentOS Linux。。 ifconfig…没有看到eth0.。然后重启网卡又报下面错误。 故障现象: service network restart Shutting down loopback insterface: [ OK ] Bringing up loopback insterface: [ OK ] Bringing up interface eth0: Device eth0 does not seem to be present,delaying initialization. [FAILED] 解决办法: 首先,打开/etc/udev/rules.d/70-persistent-net.rules内容如下面例子所示: # vi /etc/udev/rules.d/70-persistent-net.rules # This file was automatically generated by the /lib/udev/write_net_rules # program, run by the persistent-net-generator.rules rules file. # # You can modify it, as long as you keep each rule on a single # line, and change only the value of the NAME= key. # PCI device 0x1022:0x2000 (pcnet32) SUBSYSTEM==”net”, ACTION==”add”, DRIVERS==”?“, ATTR{address}==”00:0c:29:8f:89:9 7”, ATTR{type}==”1”, KERNEL==”eth“, NAME=”eth0” # PCI device 0x1022:0x2000 (pcnet32) SUBSYSTEM==”net”, ACTION==”add”, DRIVERS==”?“, ATTR{address}==”00:0c:29:50:bd:1 7”, ATTR{type}==”1”, KERNEL==”eth“, NAME=”eth1” 记录下,eth1网卡的mac地址00:0c:29:50:bd:17 接下来,打开/etc/sysconfig/network-scripts/ifcfg-eth0 # vi /etc/sysconfig/network-scripts/ifcfg-eth0 将 DEVICE=”eth0” 改成 DEVICE=”eth1” , 将 HWADDR=”00:0c:29:8f:89:97” 改成上面的mac地址 HWADDR=”00:0c:29:50:bd:17” 最后,重启网络 # service network restart 或者 # /etc/init.d/network restart 正常了。

0%