利用HAProxy实现负载均衡

一.HAProxy 介绍
HAProxy是一个特别适用于高可用性环境的TCP/HTTP开源的反向代理和负载均衡软件。在7层负载均衡方面的功能很强大(支持cookie track, header rewrite等等),支持双机热备,支持虚拟主机,支持健康检查(通过patch可以支持ECV),同时还提供直观的监控页面,可以清晰实时的监控服务集群的运行状况。同时支持Linux 2.6内核中System Epoll,通过简化系统调用,大幅的提高了网络I/O性能。

Haproxy包括以下一些特征:
根据静态分配的cookie 分配HTTP请求
分配负...

ubuntu解决for: 2: Syntax error: Bad for loop variable

我的代码
#!/bin/bashfor (i=0;i<10;i++)doecho $idone
在redhat测试无问题,在Ubuntu下测试报错
for: 2: Syntax error: Bad for loop variable
解决:
sudo dpkg-reconfigure dash
在选择项中选No
从 ubuntu 6.10 开始,ubuntu 就将先前默认的bash shell 更换成了dash shell;其表现为 /bin/sh 链接倒了/bin/dash而不是传统的/bin/bash。ubuntu edgy是第一个将dash作为默认shell来发行的版本,这似乎是受了debian的影响。wiki 里面有官方的解释,https://wiki.ubuntu.com/DashAsBinSh,主要原因是dash更小,运行更快,还与POSIX...

mod_fcgid and timeouts

At work we use mod_fcgid to run php (libapache2-mod-fcgid from Debian to be exact). This makes php nice and fast, but more importantly, it runs each site’s php pages as that site’s user. However, if php scripts start running for a long time, we start seeing cryptic error messages in the browser (”Premature end of […]

...

Memcached 集群架构问题归纳

集群架构方面的问题
o memcached是怎么工作的?
o memcached最大的优势是什么?
o memcached和MySQL的query cache相比,有什么优缺点?
o memcached和服务器的local cache(比如PHP的APC、mmap文件等)相比,有什么优缺点?
o memcached的cache机制是怎样的?
o memcached如何实现冗余机制? �
o memcached如何处理容错的?
o 如何将memcached中item批量导入导出?
o 但是我确实需要把memcached中的item都dump出来,确实需要把数据load到memcached中,怎么办?
o memcached是如何做...

memcache一致性 hash 算法(consistent hashing)

consistent hashing 算法早在 1997 年就在论文 Consistent hashing and random trees 中被提出,目前在 cache 系统中应用越来越广泛;
1 基本场景
比如你有 N 个 cache 服务器(后面简称 cache ),那么如何将一个对象 object 映射到 N 个 cache 上呢,你很可能会采用类似下面的通用方法计算 object 的 hash 值,然后均匀的映射到到 N 个 cache ;
hash(object)%N
一切都运行正常,再考虑如下的两种情况;
1 一个 cache 服务器 m down 掉了(在实际应用中必须要考虑这种情况),这样所有映射到 cache m 的...

shell中的一个类似substr的用法

原来在shell中如果遇到要截取字符串的情况,就调用awk中的substr来实现。
今天了解到一种新的方法,原来shell中本身就支持这种用法。
如,有一字符串”12345678″,现在要截取第三个到第六个字符的字符串区间。
则可以:
[xok.la ~]$ export str="123456789"[xok.la ~]$ echo ${str:3:(6-3)}456[xok.la ~]$ unset str
从以上第二个表达式可以看出这个用法,即:${str:3:(6-3)}
可以归纳为:${str:begin:len},且支持表达式,如:6-3。
补充一下从网上找到一些其他的用法:
...

require: no such file to load mkmf (LoadError)

# gem install mysqlBuilding native extensions. This could take a while…ERROR: Error installing mysql:ERROR: Failed to build gem native extension./usr/bin/ruby1.8 extconf.rbextconf.rb:10:in `require’: no such file to load — mkmf (LoadError)from extconf.rb:10Gem files will remain installed in /usr/lib/ruby/gems/1.8/gems/mysql-2.8.1 for inspection.Results logged to /usr/lib/ruby/gems/1.8/gems/mysql-2.8.1/ext/mysql_api/gem_make.out
解决
aptitude install ruby build-essential libopenssl-ruby ruby1.8-dev

...

linux shell 中”2>&1″含义

脚本是:
nohup /mnt/Nand3/H2000G  >/dev/null  2>&1  &
对于& 1 更准确的说应该是文件描述符 1,而1 一般代表的就是STDOUT_FILENO,实际上这个操作就是一个dup2(2)调用.他标准输出到all_result ,然后复制标准输出到文件描述符2(STDERR_FILENO),其后果就是文件描述符1和2指向同一个文件表项,也可以说错误的输出被合并了.其中0表示键盘输入 1表示屏幕输出 2表示错误输出.把标准出错重定向到标准输出,然后扔到/DEV/NULL下面去。通俗的说,就是把所有标准输出和标准出错都扔到...

SSL-DNS,encryption

Intro
Inspired by the HTTPS-DNS project I started to look for another approach for doing encrypted dns-requests. The following solution should work with nearly all unixoid operatingsystems ( for Microsoft Windows see below ) and can easily be applied. It works absolutly transparently for the clients and servers.
Encrypting DNS-requests is usefull, because it
prevents manipulation […]

...