memcached不允许外网访问

lnmp默认安装的memcached是可以外网访问的,对于我这个小站来说外网不会用到,所以只允许内网用。修改文件vi /etc/init.d/memcached

PORT=11211
USER=root
MAXCONN=1024
CACHESIZE=32
OPTIONS=""
IP=127.0.0.1

RETVAL=0
prog="memcached"

start () {
    echo -n $"Starting $prog: "
    memcached -d -l $IP -p $PORT -u $USER -m $CACHESIZE -c $MAXCONN -P /var/run/memcached.pid $OPTIONS
    RETVAL=$?
    echo
    [ $RETVAL -eq 0 ] && touch /var/lock/subsys/memcached
}

如果有安装iptables的话可以用iptables来禁止外网访问。

lnmp的memcached连接失败

安装phpwind时启用memcached是一直失败,telnet 127.0.0.1 11211一直成功, 重启、开启、关闭memcached一直成功。只要通过php连接都失败,后来想想原来lnmpa禁用了一些函数。这些函数都是有危险性的,如exec,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,pfsockopen,fsocket,fsockopen等,启用这些函数后memcached连接成功。

vi /usr/local/php/etc/php.ini

查找 disable_functions 把 fsockopen 函数删掉就可以了。。。

iphone的备份2

struct fileinfo{
	char   *domain;
	char   *filename;
	char   *linktarget;
	char   *datahash;
	char   *unknown1;
	unsigned short  mode;
	unsigned int unknown2;
	unsigned int inode;
	unsigned int userid;
	unsigned int groupid;
	unsigned int mtime;
	unsigned int atime;
	unsigned int ctime;
	unsigned int filelen;
	unsigned int flag;
	unsigned int numprops;
};

unsigned int getint(const char *data, int *offset, int size)
{
	if(data == NULL || offset == NULL) return 0;

	unsigned int value = 0;
	while (size > 0)
	{
		unsigned char tmp = data[*offset];
		value <<= 8;
		value |= tmp;
		(*offset)++; size--;
	}
	return value;
}

char* getstring(const char *data, int *offset)
{
	if(data == NULL || offset == NULL) return NULL;

	char *str = NULL;
	int  slen = 0;
	if(data[*offset] == (char)0xff && data[*offset+1] == (char)0xff){
		*offset += 2;
		return str;
	}

	slen = getint(data, offset, 2);   //获取长度
	str = (char*)malloc(slen+1);   //申请空间
	memcpy(str, (void*)(data+*offset), slen);//拷贝数据
	str[slen] = 0;                    //补0;
	*offset += slen;
	return str;
}

char* toA(const unsigned char *data, int len)
{
	if(data == NULL) return NULL;

	char *str = (char*)malloc(len*2+1);
	memset(str, 0, len*2+1);
	for (int i = 0; i < len; i++)
	{
		char odata[3] = {0};
		itoa(data[i], odata, 16); //转出来是两个字节的字符串
		strcat(str, odata);
	}
	return str;
}

char* getstring_hash(const char *data, int *offset)
{
	if(data == NULL || offset == NULL) return NULL;

	unsigned char *str = NULL;
	char   *ostr = NULL;
	int    slen = 0;
	if(data[*offset] == (char)0xff && data[*offset+1] == (char)0xff){
		*offset += 2;
		return ostr;
	}

	slen = getint(data, offset, 2);    //获取长度
	str = (unsigned char*)malloc(slen);   //申请空间
	memcpy(str, (void*)(data+*offset), slen); //拷贝数据
	*offset += slen;

	ostr = toA(str, slen);
	free(str);
	return ostr;
}

int process_mbdb_file(char *filename, char *outfilename)
{

	int    filelen = 0;
	FILE   *pf = NULL;
	char   *filedata = NULL;
	char   *index = NULL;
	int    offset = 0;
	int    i = 0;

	if(filename == NULL || outfilename == NULL) return -1;

	FILE *opf = fopen(outfilename, "w+");
	if(opf == NULL) return -1;

	pf = fopen(filename, "rb");
	if(pf == NULL) goto _out;

	fseek(pf, 0, SEEK_END);
	filelen = ftell(pf);
	rewind(pf);

	filedata = (char*)malloc(filelen);
	if(filedata == NULL) goto _out;

	fread(filedata, 1, filelen, pf);
	if(memcmp(filedata, "mbdb", 4)) goto _out; //文件标识头

	index = filedata + 6;      //跳过 0×05 0×00
	offset = 0;
	while(offset < filelen-6)
	{
		fileinfo fi = {0};

		fi.domain  = getstring(index, &offset);
		fi.filename  = getstring(index, &offset);
		fi.linktarget = getstring(index, &offset);
		fi.datahash  = getstring_hash(index, &offset); //换成字符串
		fi.unknown1  = getstring(index, &offset);
		fi.mode   = getint(index, &offset, 2);      //八进制
		fi.unknown2  = getint(index, &offset, 4);
		fi.inode  = getint(index, &offset, 4);
		fi.userid  = getint(index, &offset, 4);
		fi.groupid  = getint(index, &offset, 4);
		fi.mtime  = getint(index, &offset, 4);
		fi.atime  = getint(index, &offset, 4);
		fi.ctime  = getint(index, &offset, 4);
		fi.filelen  = getint(index, &offset, 8);  //64位的 但一般情况下 不会有那么大的文件
		fi.flag   = getint(index, &offset, 1);  //目前发现有4 和0  0貌似表示目录
		fi.numprops  = getint(index, &offset, 1);

		if(fi.numprops)
			printf("发现有额外数据 偏移位置在 %d n", offset);

		fprintf(opf, "%s %s %s %s %s %u %u %u %u %u %u %u %u %u %u %un",
			fi.domain,
			fi.filename,
			fi.linktarget,
			fi.datahash,
			fi.unknown1,
			fi.mode,
			fi.unknown2,
			fi.inode,
			fi.userid,
			fi.groupid,
			fi.mtime,
			fi.atime,
			fi.ctime,
			fi.filelen,
			fi.flag,
			fi.numprops
			);
		fflush(opf);
		free(fi.domain);
		free(fi.filename);
		free(fi.linktarget);
		free(fi.datahash);
		free(fi.unknown1);
	}

_out:
	if(filedata) free(filedata);
	if(opf) fclose(opf);
	if(pf) fclose(pf);
	return 0;
}

int main(int argc, char* argv[])
{
	process_mbdb_file("1.bin", "1.txt");
	return 0;
}

 

这是解析Manifest.mbdb文件的C语言版,写的非常粗糙的测试。网上有完整的:http://stackoverflow.com/questions/3085153/how-to-parse-the-manifest-mbdb-file-in-an-ios-4-0-itunes-backup 还有一个更详细的:http://code.google.com/p/iphonebackupbrowser/   关于文件的命名是  domain + "-" + filename 的sha-1的值。

盛大云的华北节点试用

华北节点其实就是北京的BGP五线(电信、联通、铁通、移动、教育网)机房。试用的是 小型主机 CPU独享型 计算能力: 4 ECU 单核: 4 ECU/核 内存: 2G 硬盘: 30G 带宽5M。

[root@SNDA-172-17-10-133 ~]# dd if=/dev/zero of=test bs=64k count=4k oflag=dsync
4096+0 records in
4096+0 records out
268435456 bytes (268 MB) copied, 3.35783 s, 79.9 MB/s
[root@SNDA-172-17-10-133 ~]# dd if=/dev/zero of=test bs=64k count=4k oflag=dsync
4096+0 records in
4096+0 records out
268435456 bytes (268 MB) copied, 3.36813 s, 79.7 MB/s

上传下载限死5M

2012-06-08 19:01:05 (574 KB/s) - ?.00mb.test?.saved [104857600/104857600]

Intel(R) Xeon(R) CPU           E5645  @ 2.40GHz

安装LNMP 50分钟

ping

http://www.17ce.com/site/ping/25bd22c594d36f1bd2d91d36cb173907.html

Get

http://www.17ce.com/site/http/5397b3ed72556375f6b30439c69bec47.html

YUNVM的VPS试用

YUNVM VPS的提供试用一天。我选的是VM2048    2G内存 双核 80G 3M 上海电信。个人估计是KVM技术的。

[root@localhost ~]# dd if=/dev/zero of=test bs=64k count=4k oflag=dsync
4096+0 records in
4096+0 records out
268435456 bytes (268 MB) copied, 12.8157 s, 20.9 MB/s
[root@localhost ~]# dd if=/dev/zero of=test bs=64k count=4k oflag=dsync
4096+0 records in
4096+0 records out
268435456 bytes (268 MB) copied, 12.6073 s, 21.3 MB/s

上传下载都限制在3M左右

[root@localhost ~]# wget http://cachefly.cachefly.net/100mb.test
--2012-06-07 23:47:16--  http://cachefly.cachefly.net/100mb.test
Resolving cachefly.cachefly.net... 204.93.150.150
Connecting to cachefly.cachefly.net|204.93.150.150|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 104857600 (100M) [application/octet-stream]
Saving to: ?.00mb.test?

100%[====================================================================================================================>] 104,857,600  361K/s   in 4m 46s 

2012-06-07 23:52:02 (359 KB/s) - ?.00mb.test?.saved [104857600/104857600]

BYTE UNIX Benchmarks (Version 4.1-wht.2)的跑分

INDEX VALUES           
TEST                                        BASELINE     RESULT      INDEX

Dhrystone 2 using register variables        376783.7 16810439.2      446.2
Double-Precision Whetstone                      83.1     1881.7      226.4
Execl Throughput                               188.3     5729.0      304.2
File Copy 1024 bufsize 2000 maxblocks         2672.0   245679.0      919.5
File Copy 256 bufsize 500 maxblocks           1077.0    77435.0      719.0
File Read 4096 bufsize 8000 maxblocks        15382.0  1914439.0     1244.6
Pipe-based Context Switching                 15448.6   402481.2      260.5
Pipe Throughput                             111814.6  2609051.3      233.3
Process Creation                               569.3    14290.3      251.0
Shell Scripts (8 concurrent)                    44.8      801.7      179.0
System Call Overhead                        114433.5  3145555.2      274.9
                                                                 =========
     FINAL SCORE                                                     372.2

cpu

model name : Intel(R) Xeon(R) CPU           E5649  @ 2.53GHz