TrafficServer源码:the possible operations or msg types sent from remote client to TM

// trafficserver/mgmt/api/NetworkMessage.h
typedef enum
{
  FILE_READ,
  FILE_WRITE,
  RECORD_SET,
  RECORD_GET,
  PROXY_STATE_GET,
  PROXY_STATE_SET,
  RECONFIGURE,
  RESTART,
  BOUNCE,
  EVENT_RESOLVE,
  EVENT_GET_MLT,
  EVENT_ACTIVE,
  EVENT_REG_CALLBACK,
  EVENT_UNREG_CALLBACK,
  EVENT_NOTIFY,                 /* only msg sent from TM to client */
  SNAPSHOT_TAKE,
  SNAPSHOT_RESTORE,
  SNAPSHOT_REMOVE,
  SNAPSHOT_GET_MLT,
  DIAGS,
  STATS_RESET_NODE,
  STATS_RESET_CLUSTER,
  STORAGE_DEVICE_CMD_OFFLINE,
  RECORD_MATCH_GET,
  API_PING,
  SERVER_BACKTRACE,
  UNDEFINED_OP /* This must be last */
} OpType;

Share

自建一个本地dns归属地查询系统:)

1.首先要搞个dns 服务器,自己用bind架一个就好,2个关键性配置文件如下

/opt/bind/etc/named.conf

options {
    listen-on port 53 { localhost; };
    allow-query     { any; };
    directory       "/opt/bind/var";
    recursion yes;
    allow-transfer { none; };
};
logging {
    channel default_debug {
        file "/opt/bind/var/named.run";
        severity dynamic;
    };
    channel query_log {
        file "/opt/bind/var/query.log";
        severity debug;
        print-time yes;
        print-category yes;
    };
    category queries{
        query_log;
    };
};
zone "." IN {
    type master;
    file "anyhosts";
};
key "rndc-key" {
    algorithm hmac-md5;
    secret "tLUFCQE/OZkFMPo2NMERMA==";
};
controls {
    inet 127.0.0.1 port 953
    allow { 127.0.0.1; } keys { "rndc-key"; };
};

/opt/bind/var/anyhosts

$TTL 60
$ORIGIN .
@ IN SOA ns1. root.localhost. (
        20051213;
        7000;
        3000;
        15000;
        86400;
);
@  86400         IN NS   ns1
ns1 86400       IN A    127.0.0.1

*	IN A	xxx.xxx.xxx.xxx

注意:xxx.xxx.xxx.xxx是这台ns服务器的外网ip

2. 需要一个顶级域名,这里用我自己的域名代替,我的域名为 humen1.net. 去域名提供商那里解析以下域名

记录名——–记录类型——–记录值
ldns ———NS ——–ns1.humen1.net.
ns1 ———A ——–xxx.xxx.xxx.xxx

3. 配置apache
vhosts 配置如下

<VirtualHost *:80>
        ServerName *.ldns.humen1.net
        DocumentRoot /ldns
        DirectoryIndex index.php index.html index.htm
</VirtualHost>

4. 写一个php脚本在 /ldns 目录下
index.php

<?php
$str=array();
exec("tail -n 50 /opt/bind/var/query.log",$str);
$str=implode("\n\n",$str);
$host= $_SERVER['HTTP_HOST'];
$pattern='/(client\s(?P<ip>\d*\.\d*\.\d*\.\d*)#\d*\s\('.$host.'\):)/';
$jsonp=$_GET["jsonpcallback"];
if (preg_match($pattern,$str,$ma))
{
	echo $jsonp.'({"error":"0","ip":"'.$ma['ip'].'"})';
	print $ips=file_get_contents("http://ip.taobao.com/service/getIpInfo.php?ip=".$ma['ip']);
}else{
	echo $jsonp. '({"error":"1")}';
}
?>

5. 使用
curl http://xxxyyyzzz.ldns.humen1.net

注意 xxxyyyzzz是随机数保证不要重复哦~~

Share

Squid request status

TCP_HIT
A valid copy of the requested object was in the cache.
TCP_MISS
The requested object was not in the cache.
TCP_REFRESH_HIT
The requested object was cached but STALE. The IMS query for the object resulted in “304 not modified”.
TCP_REF_FAIL_HIT
The requested object was cached but STALE. The IMS query failed and the stale object was delivered.
TCP_REFRESH_MISS
The requested object was cached but STALE. The IMS query returned the new content.
TCP_CLIENT_REFRESH_MISS
The client issued a “no-cache” pragma, or some analogous cache control command along with the request. Thus, the cache
has to refetch the object.
TCP_IMS_HIT
The client issued an IMS request for an object which was in the cache and fresh.
TCP_SWAPFAIL_MISS
The object was believed to be in the cache, but could not be accessed.
TCP_NEGATIVE_HIT
Request for a negatively cached object, e.g. “404 not found”, for which the cache believes to know that it is
inaccessible. Also refer to the explainations for negative_ttl in your squid.conf file.
TCP_MEM_HIT
A valid copy of the requested object was in the cache and it was in memory, thus avoiding disk accesses.
TCP_DENIED
Access was denied for this request.
TCP_OFFLINE_HIT
The requested object was retrieved from the cache during offline mode. The offline mode never validates any object, see
offline_mode in squid.conf file.
UDP_HIT
A valid copy of the requested object was in the cache.
UDP_MISS
The requested object is not in this cache.
UDP_DENIED
Access was denied for this request.
UDP_INVALID
An invalid request was received.
UDP_MISS_NOFETCH
During “-Y” startup, or during frequent failures, a cache in hit only mode will return either UDP_HIT or this code.
Neighbours will thus only fetch hits.
NONE
Seen with errors and cachemgr requests.
The following codes are no longer available in Squid-2:
ERR_*
Errors are now contained in the status code.
TCP_CLIENT_REFRESH
See: TCP_CLIENT_REFRESH_MISS.
TCP_SWAPFAIL
See: TCP_SWAPFAIL_MISS.
TCP_IMS_MISS
Deleted, TCP_IMS_HIT used instead.
UDP_HIT_OBJ
Hit objects are no longer available.
UDP_RELOADING
See: UDP_MISS_NOFETCH.

Share

Squid Hierarchy Codes

NONE For TCP HIT, TCP failures, cachemgr requests and all UDP requests, there is no hierarchy information.

DIRECT The object was fetched from the origin server.

SIBLING_HIT The object was fetched from a sibling cache which replied with UDP_HIT.

PARENT_HIT The object was requested from a parent cache which replied with UDP_HIT.

DEFAULT_PARENT No ICP queries were sent. This parent was chosen because it was marked “default” in the config file.

SINGLE_PARENT The object was requested from the only parent appropriate for the given URL.

FIRST_UP_PARENT The object was fetched from the first parent in the list of parents.

NO_PARENT_DIRECT The object was fetched from the origin server, because no parents existed for the given URL.

FIRST_PARENT_MISS The object was fetched from the parent with the fastest (possibly weighted) round trip time.

CLOSEST_PARENT_MISS This parent was chosen, because it included the the lowest RTT measurement to the origin server. See also the closest-only peer configuration option.

CLOSEST_PARENT The parent selection was based on our own RTT measurements.

CLOSEST_DIRECT Our own RTT measurements returned a shorter time than any parent.

NO_DIRECT_FAIL The object could not be requested because of a firewall configuration, see also never_direct and related material, and no parents were available.

SOURCE_FASTEST The origin site was chosen, because the source ping arrived fastest.

ROUNDROBIN_PARENT No ICP replies were received from any parent. The parent was chosen, because it was marked for round robin in the config file and had the lowest usage count.

CACHE_DIGEST_HIT The peer was chosen, because the cache digest predicted a hit. This option was later replaced in order to distinguish between parents and siblings.

CD_PARENT_HIT The parent was chosen, because the cache digest predicted a hit.

CD_SIBLING_HIT The sibling was chosen, because the cache digest predicted a hit.

NO_CACHE_DIGEST_DIRECT This output seems to be unused?

CARP The peer was selected by CARP.

PINNED The server connection was pinned by NTLM or Negotiate authentication requirements.

ORIGINAL_DST The server connection was limited to the client provided destination IP. This only occurs on interception proxies when Host security is enabled.

ANY_PARENT part of src/peer_select.c:hier_strings[].

INVALID CODE part of src/peer_select.c:hier_strings[].

Share

squid logformat (适用版本2.7)

摘抄下官方手册,部分翻译

Usage:

	logformat <name> <format specification>

	Defines an access log format.

	The <format specification> is a string with embedded % format codes

	% format codes all follow the same basic structure where all but
	the formatcode is optional. Output strings are automatically escaped
	as required according to their context and the output format
	modifiers are usually not needed, but can be specified if an explicit
	output format is desired.

		% ["|[|'|#] [-] [[0]width] [{argument}] formatcode

		"	output in quoted string format
		[	output in squid text log format as used by log_mime_hdrs
		#	output in URL quoted format
		'	output as-is

		-	left aligned
		width	field width. If starting with 0 the
			output is zero padded
		{arg}	argument such as header name etc

	Format codes:

		>a	Client source IP address / 客户端 IP
		>A	Client FQDN / 客户端完整域名,是指主机名+全路径
		>p	Client source port / 客户端端口
		<A	Server IP address or peer name / 服务器ip 或者 对端名
		la	Local IP address (http_port) / 本地ip地址
		lp	Local port number (http_port) / 本地端口号
		oa	Our outgoing IP address (tcp_outgoing_address) / 传出的ip地址
		ts	Seconds since epoch / unix时间戳
		tu	subsecond time (milliseconds) / 毫秒
		tl	Local time. Optional strftime format argument / 本地时间
			default %d/%b/%Y:%H:%M:%S %z
		tg	GMT time. Optional strftime format argument / 格林尼治标准时间
			default %d/%b/%Y:%H:%M:%S %z
		tr	Response time (milliseconds) / 响应时间(毫秒)
		>h	Request header. Optional header name argument 
			on the format header[:[separator]element] /请求头
		<h	Reply header. Optional header name argument 
			as for >h / 响应头
		un	User name /用户名
		ul	User name from authentication /认证的用户名
		ui	User name from ident 
		us	User name from SSL
		ue	User name from external acl helper
		Hs	HTTP status code / http 状态码
		Ss	Squid request status (TCP_MISS etc) / squid 请求状态
		Sh	Squid hierarchy status (DEFAULT_PARENT etc) / squid 层次结构状态
		mt	MIME content type / MIME内容类型
		rm	Request method (GET/POST etc) /请求方法
		ru	Request URL /请求的url
		rp	Request URL-Path excluding hostname /不包含主机名的请求url
		rv	Request protocol version / 请求协议版本
		ea	Log string returned by external acl
		<st	Reply size including HTTP headers /响应大小,包括HTTP头
		>st	Request size including HTTP headers /请求大小,包括HTTP头
		st	Request+Reply size including HTTP headers /请求大小+响应大小,包括HTTP头
		sn	Unique sequence number per log line entry /唯一序列号
		%	a literal % character 
Share

haproxy 配置

自己的测试环境
squid listen :8081
haproxy listen :80

lobal
        maxconn 1024 #限制单个进程的最大连接数
        chroot /haproxy #安装路径
        uid 99 #运行用户 99==nobody
        gid 99 #运行组 99==nobody
        daemon #as 守护进程
        quiet 
        nbproc 10 #启动多少个进程
        pidfile /haproxy/run.pid # pid 文件的路径

defaults
        log global
        mode http
        option httplog
        option dontlognull
        log 127.0.0.1 local3 info #日志级别[err warning info debug]
        retries 3 #在一个服务器上连接失败后重试次数
        option redispatch #连接失败或断开后允许当前会话被重新分配
        maxconn 1024 #连后端服务器的最大连接数
        contimeout 100ms #连接超时
        clitimeout 10000ms #客户端的连接超时
        srvtimeout 10000ms #服务端的连接超时

listen cluster 0.0.0.0:80 #监听 host:port
        mode http #http 7层模式
        balance roundrobin # 负载方式
        option httpclose 
        option forwardfor
        server internalweb1 127.0.0.1:8081 weight 5
        #weight 权重
        #check 健康检查 【我没配置】
        #inter n 两次check间隔时间ms(检查粒度)
        #rise n 指定成功检测n次后服务可用
        #fall n 指定检测n次失败后服务不可用
        #maxconn n 指定最大并发连接数

参考网址

Share