2016年12月17日星期六

Java Servlet/JavaBean/EJB/DAO/MVC 的简单说明

Java 搞了些怪名词

JavaBean 对应 Windows COM 就是一种 dll 规范,在 web 中就是一个数据库表的字段对应一个类,在窗口应用程序中可能是一个控件,是用来标明一类事物。
EJB 对应 Windows COM+/DCOM 已经没人用了,现在都在用 web service
DAO 数据访问对象,就是一个类,里边处理数据库操作
MVC
model 就是 javabean 类型的类,一个数据库表的字段对应一个类。
view 就是网页模板,可以用 jsp 实现,也可以用 freemarker 实现,freemarker 好理解,好书写
controller 就是 servlet 用来,处理请求数据,调用DAO增删改查,输送返回数据,以及这些操作的 if else

java web 开发就简单了,

1. eclipse with javaee
2. tomcat
3. servlet => dao => model => freemaker

完事

java 没必要,php 本来就能做好,money

2016年12月14日星期三

SSL TLS 客户端和服务器

SSLv3 TLSv1 TLSv1.1 TLSv1.2

服务器端

nginx 的 ssl/tls支持依赖于 openssl 库
centos5 => openssl/0.9.8e =>SSLv3 TLSv1
centos6 => openssl/1.0.1e =>SSLv3 TLSv1 TLSv1.1 TLSv1.2

centos5 可以通过升级 epel openssl 库到 1.0.1e 来让 nginx 支持 TLSv1.1 和 TLSv1.2 

客户端

XP SP2 不支持 sha256 的证书
若要支持 XP SP2,需要 sha1 的证书

IE6 只支持 SSLv3
https://en.wikipedia.org/wiki/Template:TLS/SSL_support_history_of_web_browsers

nginx 1.9.1 以后默认没有开启 SSLv3
http://nginx.org/en/docs/http/configuring_https_servers.html 

这样,若要让 nginx 1.9.1 支持 IE6 需要配置打开 SSLv3 支持
ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;
 
加密算法支持
XP ie6/7/8 只支持 RC4 不支持 AES
https://github.com/client9/sslassert/wiki/IE-Supported-Cipher-Suites 
 

2016年12月9日星期五

正则表达式 Unicode

http://www.regular-expressions.info/unicode.html


Perl, PCRE, Boost, and std::regex do not support the \uFFFF syntax. They use \x{FFFF} instead. You can omit leading zeros in the hexadecimal number between the curly braces. Since \x by itself is not a valid regex token, \x{1234} can never be confused to match \x 1234 times. It always matches the Unicode code point U+1234. \x{1234}{5678} will try to match code point U+1234 exactly 5678 times.
In Java, the regex token \uFFFF only matches the specified code point, even when you turned on canonical equivalence. However, the same syntax \uFFFF is also used to insert Unicode characters into literal strings in the Java source code. Pattern.compile("\u00E0") will match both the single-code-point and double-code-point encodings of à, while Pattern.compile("\\u00E0") matches only the single-code-point version. Remember that when writing a regex as a Java string literal, backslashes must be escaped. The former Java code compiles the regex à, while the latter compiles \u00E0. Depending on what you're doing, the difference may be significant.
JavaScript, which does not offer any Unicode support through its RegExp class, does support \uFFFF for matching a single Unicode code point as part of its string syntax.

squid zero sized reply

squid zero sized reply

squid 默认回源是持久连接
http://www.squid-cache.org/Doc/config/server_persistent_connections/

当回源持久连接超时或网络中断的时候会出现这个问题

如果回源改为非持久链接,会增大 squid 的 TIME_WAIT 数量,造成端口耗尽。

squid 回源与源服务器之间持久连接和 TIME_WAIT 关系
http://serverfault.com/questions/639521/relationship-between-tcp-state-time-wait-http-keep-alive

2016年12月5日星期一

windows 和 linux 大并发,避免端口耗尽

1.windows
参考:https://msdn.microsoft.com/zh-cn/library/aa560610(v=bts.10).aspx

1)
增加动态分配到客户端 TCP/IP 套接字连接的临时端口的上限。

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters

在“编辑”菜单中单击“新建”、“DWORD 值”,然后添加以下注册表值,以增加可以动态分配到客户端的临时端口的数量:

值名称
MaxUserPort
值数据
<在此输入一个 5000 到 65534 之间的十进制值>

2)
降低客户端 TCP/IP 套接字连接的超时值(默认值为 240 秒)

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters

在“编辑”菜单中单击“新建”、“DWORD 值”,然后添加以下注册表值,以缩短关闭连接时,该连接处于 TIME_WAIT 状态的时间。当连接处于 TIME_WAIT 状态时,套接字对无法重新使用:

值名称
TcpTimedWaitDelay
值数据
<在此输入一个 30 到 240 之间的十进制值。>

2.linux
1) 更改打开端口范围
net.ipv4.ip_local_port_range = 1024 65000

2)修改内核中 timewait 参数
重新编译内核,参考
https://wiki.centos.org/zh/HowTos/I_need_the_Kernel_Source

这样就解压缩了内核包

修改源代码
$KERNEL/include/net/tcp.h
#define TCP_TIMEWAIT_LEN (60*HZ) /* how long to wait to destroy TIME-WAIT

TCP_TIMEWAIT_LEN 取值范围参考
https://mailman.nanog.org/pipermail/nanog/2012-December/054013.html

"There seems to be consensus around 20 seconds being safe, 15 being a
99% OK, and 10 or less being problematic."

修改后,进入内核源代码目录
make rpm
制作 rpm 包