2012年6月8日星期五

memcached启动参数


-p <num>     指定监听的TCP端口号,默认是11211
-U <num>     指定监听的TCP端口号 (默认: 11211, 0 表示关闭)
-s <file>     UNIX socket path to listen on (disables network support)
-a <mask>     access mask for UNIX socket, in octal (default: 0700)
-l <addr>    指定绑定的IP地址,多个地址用逗号分隔。
-d            以后台进程运行
-r            maximize core file limit
-u <username> 指定运行的帐号(只有root时有效)
-m <num>      最大内存使用值,单位是M(default: 64 MB)
-M            return error on memory exhausted (rather than removing items)
-c <num>      最大并发连接数 (默认: 1024)
-k            lock down all paged memory.  Note that there is a
              limit on how much memory you may lock.  Trying to
              allocate more than that would fail, so be sure you
              set the limit correctly for the user you started
              the daemon with (not for -u <username> user;
              under sh this is done with 'ulimit -S -l NUM_KB').
-v            日志模式 (在事件循环中打印错误/警告)
-vv           强日志模式 (还打印客户端的命令/响应)
-vvv        最大日志模式 (打印内部状态交互信息)
-h            打印帮助信息
-i            打印 memcached 和 libevent 的版权信息
-P <file>     -d参数下,指定pid file
-f <factor>   chunk size growth factor (default: 1.25)
-n <bytes>    为 key+value+flags  分配的最小空间(字节)(default: 48)
-L            Try to use large memory pages (if available). Increasing
              the memory page size could reduce the number of TLB misses
              and improve the performance. In order to get large pages
              from the OS, memcached will allocate the total item-cache
              in one large chunk.
-D <char>     Use <char> as the delimiter between key prefixes and IDs.
              This is used for per-prefix stats reporting. The default is
              ":" (colon). If this option is specified, stats collection
              is turned on automatically; if not, then it may be turned on
              by sending the "stats detail on" command to the server.
-t <num>      线程数 (default: 4)
-R            Maximum number of requests per event, limits the number of
              requests process for a given connection to prevent
              starvation (default: 20)
-C          禁用 CAS
-b            Set the backlog queue limit (default: 1024)
-B            Binding protocol - one of ascii, binary, or auto (default)
-I            Override the size of each slab page. Adjusts max item size
              (default: 1mb, min: 1k, max: 128m)
-o            Comma separated list of extended or experimental options
              - (EXPERIMENTAL) maxconns_fast: immediately close new
                connections if over maxconns limit
              - hashpower: An integer multiplier for how large the hash
                table should be. Can be grown at runtime if not big enough.
                Set this based on "STAT hash_power_level" before a
                restart.

2012年6月4日星期一

在Amazon的EC2上搭建pptp-vpn和openvpn

        首先要去申请一个amazon的账户,这个阶段你可能需要一个visa信用卡来激活你的帐号,另外会有一个印度的呼叫中心用蹩脚的英语来核实你的基本信息。
        好,假设我们认为你已经有了个amazon的帐号,你需要登录到amazon的后台console,选择上边的EC2的tab,然后注意选择左上角的大区,这取决于你的server位于哪个大陆,我们这里选择的是tokyo东京。
        我们要申请一个EC2的实例,这里推荐的是ubuntu11.04 32位的系统(RHEL5.x,6.x的tiny instance也是收费的,慎用)。这里面有一系列的步骤,之需要选择最低配置即可,中间会有一个生成安全私钥的过程,会直接下载的本地电脑中,假设这个密钥是sec.pem。我们保存好这个文件,之后的ssh,scp等操作都需要用这个文件。
        启动你的console。并设置安全拦截(Security groups)放行443,1194(openvpn)和1723(pptp)
-----------------------------
22 (SSH)0.0.0.0/0
443 (HTTPS)0.0.0.0/0
1194 0.0.0.0/0
1723 0.0.0.0/0
-----------------------------
        ssh:ssh -i sec.pem ubuntu@{dynamic_Dns_name}连接到你启动的ubuntu实例。
        ssh成功后,查看一下虚拟主机的配置,是613M内存,8G硬盘空间;
        安装pptpd,apt-get install pptpd;
        修改一下/etc/pptpd.conf 打开localip和remoteip选项;
        修改/etc/ppp/pptpd-options, 设置dns ms-dns 8.8.8.8 ms-dns 8.8.4.4;
        修改/etc/ppp/chap-secrets 设置客户端的用户名密码 pptpd * pptpd *;
        重启pptpd:pptpd restart;
        修改/etc/sysctl.conf,打开注释的net.ipve.ip_forward=1,然后运行sudo sysctl -p
        修改iptables,设置网络地址翻译:sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE;/sbin/iptables -A INPUT -p gre -j ACCEPT
        设置到/etc/rc.local避免重启丢失:在exit 0之前添加:iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE;iptables –table nat –append POSTROUTING –jump MASQUERADE;
        好,上面的一系列步骤帮助 你设置好了一个pptp的server,下面要在ubuntu的环境下设置client。
        首先create一个pptp连接,pptpsetup --create pptpd --server ec2_dynamic_DNS --username [帐号] --password [密码] --encypt,以后连接和取消vpn执行pon pptpd和poff pptpd即可;
ppp/peers/下建立了一个vpn_name的连接,info如下:
----------vpn_name--------
# written by pptpsetup
pty "pptp xxx.xxx.xx.xxx --nolaunchpppd"
lock
noauth
nobsdcomp
nodeflate
name xxx
remotename pptpd
ipparam pptpd
require-mppe-128
--------------------------------
最后一行表示使用mppe128位加密;(即--encypt)
        执行sudo pon即可拨号,这里有一个debug模式,命令是:pon xxx debug dump logfd 2 nodetach (xxx为你设置的vpn名称)
拨号成功后,可以通过增加路由策略实现有选择的翻墙;
增加一个路由策略:route add -net 199.59.0.0/16 dev ppp0,即可把twitter加入到vpn策略中。
错误分析:
如果在debug模式下出现多行sent [LCP ConfReq ...] 这时说明你的GRE协议穿透有问题;你需要重点关注协议在哪一方被拦截了;
可以通过抓包来判断,分别在server和client对1723端口抓包,可以轻易的判别是server拦截了GRE还是client端的环境拦截了GRE。server你需要配置好防火墙规则,client你需要检查你的网络防火墙设置。
====PPTP结束====