[wposflv src="https://commondatastorage.googleapis.com/tianjiaguo.com/video/2013-03-13/%E5%8D%81%E5%88%86%E9%92%9F%E7%9C%8B%E6%87%82%E4%B8%AD%E5%9B%BD.flv" width=600 height=487 title="十分钟看懂中国"] more
胡桃钳-twemproxy-(recommendation document)
If you are deploying nutcracker in your production environment, here are a few recommendations that might be worth considering. 建议,如果你想部署它到生产环境 Log Level By default debug logging is disabled in nutcracker. However, it is worthwhile running nutcracker with debug logging enabled and verbosity level set to LOG_INFO (-v 6 or –verbosity=6). This in reality does not add much overhead as you only pay the cost of checking an if condition for every log line encountered during the run time. 默认情况下debug日志是没有打开的.然而打开debug日志并把日志级别设置到LOG_INFO(-v 6或者–... more
胡桃钳-twemproxy(two-em-proxy)
Hútáo qián Ben Olson again prince in Nutcracker, will tackle Cinderella role. noun 胡桃夹子 nutcracker, crackers 胡桃钳 nutcracker, crackers twemproxy twemproxy (nutcracker) Build Status twemproxy (pronounced “two-em-proxy”), aka nutcracker is a fast and lightweight proxy for memcached and redis protocol. It was primarily built to reduce the connection count on the backend caching servers. memcached和redis协议快速和轻量级的代理.它的创建主要是为了减少到后台缓存服务器的连接数量. Features Fast. Lightweight. Maintains persistent server connections. Keeps connectio... more
tmux远程管理利器
tmux是一个终端复用软件,即使非正常掉线,也能保证当前的任务运行。它的官方网站在:http://tmux.sourceforge.net/ 具体的不多介绍,它特别适合程序员及linux管理员使用。 下面简单把官方网站上的介绍移了过来,大家可移步官方上看其官方的说明。 mux is a terminal multiplexer: it enables a number of terminals (or windows), each running a separate program, to be created, accessed, and controlled from a single screen. tmux may be detached from a screen and continue running in the background, then later reattached. The latest version is tmux 1.6. tmux uses a client-server model. The server holds multiple sess... more
centos6下识别ntfs文件格式
linux系统下要访问windows的ntfs格式需要安装ntfs-3g(这是其中的一个方法,还有其它的方法让linux支持ntfs的读写,但笔者认为这个方法最为简单)的一个开源的程序,它的使用很简单。 下载和安装ntfs-3g,它的下载地址是:http://www.tuxera.com/community/ntfs-3g-download/,传输门:http://tuxera.com/opensource/ntfs-3g_ntfsprogs-2012.1.15.tgz 安装很简单 ./configure make make install # or 'sudo make install' if you aren't root 安装完成后,可以用mount命令把ntfs的盘mount到系统 fdisk -l |grep NTFS mount -t ntfs-3g /dev/sda1 /mnt/windows 但这样做并不完美,在文件浏览器(Nautilus)中,占击相应的分区,还是... more
windows7与centos6共存
买了块ssd固态硬盘,放到笔记本上,然后就是折腾系统,装个windows7,因为有些事情没有windows还真是做不了,但还是留了大部分的空间装linux。 万恶的windows啊,有多少装多系统的人就有多少windows受害者呀。 先安装的windows7,装好了之后用硬盘安装的centos6,装好了之后,居然进不去windows了。双系统咱也装过多次了呀,从没出现过这种情况,于是重装windows,重装centos,这次和第一次不同的地方是把引导程序没有装到mbr中,而是装到linux的硬盘启动扇区中了,但这次windows能够正常进,linux系统却进不去了。 ssd和旧硬盘上的系统: ssd:windows7 & centos6 旧硬盘:windows xp & debian 下面就简单的列一下解决方法。 1:在... more
使用netty做文件的上传
闲着无事,写了一个使用netty做文件上传的例子,这使用到了之前博文中提到的从dev的netty源代码中提取出来的代码,源博文是:使用netty解析multiform的请求,这时把那个提取出来的文件的地址也贴出来(强大的墙啊,翻一下下,或者tell me ⊙.⊙):http://commondatastorage.googleapis.com/tianjiaguo.com/files/2012-07-15/netty_multiform_decoder.tar.gz,有需要的同学可以直接下载下来。 这个例子可使用多线程处理,只需要在需要返回数据时,调用一下sendAndClose的方法,具体看例子吧,这个例子并没有做异常处理等,真实情况下,需要保证出错时关闭connection,而不是等待超时。 只是测试代码,所以代码在贴出来时没有经过修改。 ... i... more
nginx动态处理图片模块
nginx的Http Image Filter Module可以动态处理JPEG,GIF,PNG格式的图片,它在0.7.54+版本后引入nginx,要使用它需要在./configure时添加 –with-http_image_filter_module 打开它,它需要libgd的支持,所以要使用它我们先要在机器上安装libgd,centos和debian的用户可以使用它们的包管理器去安装,如果要手动安装,对于64位的系统需要在编译时添加相应参数(使生成64位的二进制文件),这里只有32位的linux系统安装的例子。 1、需要的程序文件 jpegsrc.v6b.tar.gz libpng-1.5.12.tar.gz pierrejoye-gd-libgd-5551f61978e3.tar.gz freetype-2.3.5.tar.gz pcre-8.31.tar.gz nginx-1.3.4.tar.gz 2、编译安装 cd jpeg-6b ./configure --e... more
使用maven打包可执行jar文件
使用maven打包可执行jar文件,个人觉得把需要部署的程序打包成jar文件,会让部署工作更简单,如果不打包成可执行jar文件,我们把所有的信赖都打包到zip文件中,把zip文件传送到服务器上,然后解压它,设置classpath,然后启动它,太麻烦,不若直接打包成一个jar文件来的简单。 例子: 1:pom.xml <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <parent> <artifactId>tianjiagu... more
使用netty解析multiform的请求
netty的release版本中没有这个的解析代码,在其dev的分支下有这个的代码。我把它提取了出来,代码可在 http://commondatastorage.googleapis.com/tianjiaguo.com/files/2012-07-15/netty_multiform_decoder.tar.gz 链接下载。 使用方法: HttpMethod method = request.getMethod(); _request.setMethod(method); if (method.equals(HttpMethod.POST) || method.equals(HttpMethod.PUT)) { HttpPostRequestDecoder postRequestDecoder = new HttpPostRequestDecoder( new DefaultHttpDataFactory(DefaultHttpDataFactory.MINSIZE), request, CharsetUtil.UTF_8); List<InterfaceHttpData> dataList = postReques... more
程序频繁更新缓存中数据集的方案
最近在做comet相关的开发,comet服务器会产生一个在线用户的消息,这个消息会发给在线用户server去处理,这个在线用户的server需要维护一个在线用户的列表在redis中,这个列表的维护工作会是个问题,不能实时更新的,它每次更新的量也是不小的。但是呢,由于在线的状态是会持续一段时间的(在线设置的是30秒超时,30秒内连接存在过就算在线),所以可以采用下面的方案。 为了解决这个问题,写了个组件,这个组件会每隔period的时间更新一次redis中的在线用户信息,由于在线用户实时信息分布在cycle数量的集合中,每次更新cycle-1集合中的数据给redis,所以在线用户的信息基本上是准确的,误差少于period时间。 package com.tianjiaguo.t... more
基于netty实现comet的例子
netty是一个nio的服务器和客户端的框架,它为我们快速创建高性能的网络应用提供了方便。 netty有很丰富的文档和demo,但却没有关于comet的例子,文档中也只是稍提了一下,并没有说明如何去实现这个,用google搜索也找不到这个的例子,没有办法只能自己动手啦。 使用netty去实现一个comet其实并不难,只需要把request和response保存起来,在需要发送数据到客户端时调用response。 整了个例子,在github上,链接是:NettyCometTest.java 为方便查看,此处copy了一份 package com.tianjiaguo.netty.comet; import org.jboss.netty.bootstrap.ServerBootstrap; import org.jboss.netty.buffer.ChannelBuffer; import org.jboss.netty.buffe... more
nginx的配置
简单upstream upstream blog_tianjiaguo_com { server xxxxxxxxxxxx:8070; server xxxxxxxxxxxx:8071; } server { listen 80; server_name blog.tianjiaguo.com; client_max_body_size 15m; client_body_timeout 120; location / { proxy_pass http://blog_tianjiaguo_com; proxy_next_upstream error timeout invalid_header http_500 http_502 http_503; # 设置必要的header,比如ip proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto https; ... more