朱建国 发布的文章

10℃以上

下身:七分裤。
上身:长袖衣衫,或者穿短袖衣衫配上手臂护套。
配件:一件轻便的棒球帽风格帽子。

1-10℃

下身:七分裤或者四分之三长的紧身裤。可选长紧身裤或者普通裤。
上身:套上两层长袖衣衫,或者穿一层,外加一件防风上衣。
配件:一个无檐小便帽,薄手套。

零下1-6℃

下身:拉过绒的紧身衣或裤子,盖住任何裸露在外面的肌肤。
上身:穿两层长袖,或者穿一个长袖外加薄层和薄夹克。再或者,除按上述的厚一些的版本。
配件:无檐小便帽,厚手套。太阳镜保护寒冷阵风中的眼睛(在阴天的时候考虑一下清晰的镜片)

零下18-零下6℃

下身:防水材料的,拉过绒的绝缘抗风紧身衣或裤子,长袜子。
上身:塞到裤子里的长袖,或一个中间层来保暖你的脖子,外加一个绝缘体夹克。
配件:一条围巾围住你的脖子,甚至围住你的脸颊和嘴。一个暖和的无檐小便帽可以盖住你的耳朵,一个大小合适的厚手套和太阳镜。

零下18℃以下

伙计,那你不是在开玩笑?还是去跑步机上练习吧!

一、起因

一到年底,各大网站又开始组织评选各种最佳XX,比如新浪组织的2015十大跑团投票。昨日在跑步群里,组织的领袖人物号召大家去投票,于是好多人都投了,后来又过了一会,领袖又出来无奈的说,大家每人投1000票吧,瞬间集体崩溃,原来投票还可以这么玩!

于是仔细研究了下这个网站投票,抓包发现,其所为的投票就是一个普通的HTTP GET 请求,没有缓存,没有认证,没有限制,我真无语了,这还是新浪网站做的网页呢,这尼玛是实习生做的吧?最基本的验证、防刷票都没有。
而前面几名小跑团竟然都跟我XX大跑团差距几十万的投票量了,这些明显都是在刷票!而且是软件自动刷的!太气愤了。

二、行动

于是决定做个投票器,刷!刷!刷!帮助XX大跑团刷!帮助XX大跑团刷!帮助XX大跑团刷!

首先下载libcurl,编译生成静态库。

其次在网上找了个基于libcurl的HttpClient源码,如下

define HTTP_CURL_H

include

class CHttpClient
{
public:

CHttpClient(void);
~CHttpClient(void);

public:

int Post(const std::string & strUrl, const std::string & strPost, std::string & strResponse);
int Get(const std::string & strUrl, std::string & strResponse);
int Posts(const std::string & strUrl, const std::string & strPost, std::string & strResponse, const char * pCaPath = NULL);
int Gets(const std::string & strUrl, std::string & strResponse, const char * pCaPath = NULL);

public:

void SetDebug(bool bDebug);

private:

bool m_bDebug;

};

endif

include

include "stdafx.h"

include "HttpClient.h"

include "curl/curl.h"

include "curl/easy.h"

CHttpClient::CHttpClient(void) : m_bDebug(false)
{

}

CHttpClient::~CHttpClient(void)
{

}

static int OnDebug(CURL , curl_infotype itype, char pData, size_t size, void *)
{

if (itype == CURLINFO_TEXT)
{
    //printf("[TEXT]{b75a474a571334bb08f4db31fa80d7688c6401b1dcf97fb55e06ed241b59472c}s\n", pData);
}
else if (itype == CURLINFO_HEADER_IN)
{
    printf("[HEADER_IN]{b75a474a571334bb08f4db31fa80d7688c6401b1dcf97fb55e06ed241b59472c}s\n", pData);
}
else if (itype == CURLINFO_HEADER_OUT)
{
    printf("[HEADER_OUT]{b75a474a571334bb08f4db31fa80d7688c6401b1dcf97fb55e06ed241b59472c}s\n", pData);
}
else if (itype == CURLINFO_DATA_IN)
{
    printf("[DATA_IN]{b75a474a571334bb08f4db31fa80d7688c6401b1dcf97fb55e06ed241b59472c}s\n", pData);
}
else if (itype == CURLINFO_DATA_OUT)
{
    printf("[DATA_OUT]{b75a474a571334bb08f4db31fa80d7688c6401b1dcf97fb55e06ed241b59472c}s\n", pData);
}
return 0;

}

static size_t OnWriteData(void buffer, size_t size, size_t nmemb, void lpVoid)
{

std::string* str = dynamic_cast<std::string*>((std::string *)lpVoid);
if (NULL == str || NULL == buffer)
{
    return -1;
}

char* pData = (char*)buffer;
str->append(pData, size * nmemb);
return nmemb;

}

int CHttpClient::Post(const std::string & strUrl, const std::string & strPost, std::string & strResponse)
{

CURLcode res;
CURL* curl = curl_easy_init();
if (NULL == curl)
{
    return CURLE_FAILED_INIT;
}
if (m_bDebug)
{
    curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
    curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION, OnDebug);
}
curl_easy_setopt(curl, CURLOPT_URL, strUrl.c_str());
curl_easy_setopt(curl, CURLOPT_POST, 1);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, strPost.c_str());
curl_easy_setopt(curl, CURLOPT_READFUNCTION, NULL);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, OnWriteData);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&strResponse);
curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 3);
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 3);
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
return res;

}

int CHttpClient::Get(const std::string & strUrl, std::string & strResponse)
{

CURLcode res;
CURL* curl = curl_easy_init();
if (NULL == curl)
{
    return CURLE_FAILED_INIT;
}
if (m_bDebug)
{
    curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
    curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION, OnDebug);
}
curl_easy_setopt(curl, CURLOPT_URL, strUrl.c_str());
curl_easy_setopt(curl, CURLOPT_READFUNCTION, NULL);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, OnWriteData);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&strResponse);
/**
* 当多个线程都使用超时处理的时候,同时主线程中有sleep或是wait等操作。
* 如果不设置这个选项,libcurl将会发信号打断这个wait从而导致程序退出。
*/
curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 3);
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 3);
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
return res;

}

int CHttpClient::Posts(const std::string & strUrl, const std::string & strPost, std::string & strResponse, const char * pCaPath)
{

CURLcode res;
CURL* curl = curl_easy_init();
if (curl == NULL)
{
    return -1;
}
if (m_bDebug)
{
    curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
    curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION, OnDebug);
}
curl_easy_setopt(curl, CURLOPT_URL, strUrl.c_str());
curl_easy_setopt(curl, CURLOPT_POST, 1);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, strPost.c_str());
curl_easy_setopt(curl, CURLOPT_READFUNCTION, NULL);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, OnWriteData);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&strResponse);
curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
if (NULL == pCaPath)
{
    curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, false);
    curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, false);
}
else
{
    //缺省情况就是PEM,所以无需设置,另外支持DER
    //curl_easy_setopt(curl,CURLOPT_SSLCERTTYPE,"PEM");
    curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, true);
    curl_easy_setopt(curl, CURLOPT_CAINFO, pCaPath);
}
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 3);
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 3);
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
return res;

}

int CHttpClient::Gets(const std::string & strUrl, std::string & strResponse, const char * pCaPath)
{

CURLcode res;
CURL* curl = curl_easy_init();
if (NULL == curl)
{
    return CURLE_FAILED_INIT;
}
if (m_bDebug)
{
    curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
    curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION, OnDebug);
}
curl_easy_setopt(curl, CURLOPT_URL, strUrl.c_str());
curl_easy_setopt(curl, CURLOPT_READFUNCTION, NULL);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, OnWriteData);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&strResponse);
curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
if (NULL == pCaPath)
{
    curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, false);
    curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, false);
}
else
{
    curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, true);
    curl_easy_setopt(curl, CURLOPT_CAINFO, pCaPath);
}
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 3);
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 3);
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
return res;

}

///////////////////////////////////////////////////////////////////////////////////////////////

void CHttpClient::SetDebug(bool bDebug)
{

m_bDebug = bDebug;

}

include "stdafx.h"

include <windows.h>

include "HttpClient.h"

int _tmain(int argc, _TCHAR* argv[])
{

long long int s_count = 0;
while (true)
{
    Sleep(100);
    CHttpClient client;
    std::string url = "http://survey.sina.cn/aj/submit?poll_id=xxxx&q_xxx=xxx";

    std::string respon;
    client.Get(url, respon);
    size_t pos = respon.find("true");
    printf("You are vote to XXXTeam {b75a474a571334bb08f4db31fa80d7688c6401b1dcf97fb55e06ed241b59472c}lld times.result:{b75a474a571334bb08f4db31fa80d7688c6401b1dcf97fb55e06ed241b59472c}s\r\n", ++s_count, (pos == std::string::npos) ? "ERROR" : "OK");
    printf("respon:{b75a474a571334bb08f4db31fa80d7688c6401b1dcf97fb55e06ed241b59472c}s\r\n", respon.c_str());
    printf("\r\n");
}

return 0;

}
三、放大招

OK,再写个小test程序,一秒刷10次。后来测试发现,不管一秒请求多少次,貌似服务器每秒只接收一次,或者是同一个ip只接收一次。

好了,挂了一夜,票数直线上升,将近升了一半。

零、总则
市场只有横盘和单边两种形态,在横盘和单边时候都做波段,吃其中的某一个波段,最长持8*4H=32小时的波段。通过4H看趋势,下降、上升、横盘。理论上只有在趋势转换的时候,才会亏损。

一、入场
在创新高的价格第一次回撤时买入,在价格创新低第一次反弹的时候沽空。4H看趋势,确定趋势后,5M找反弹入场。

二、出场
入场后吃足一个波段(8*4H),创新低或者创新高了则退场,不贪多,不嫌少。

三、止损、止盈
止损在当前点与上一个波的最高点(最低点)中间,止盈是在新高点或者新低点。吃足波段。

四、胜算概率
止损和止盈的点数基本相同,只要提高入场准确率,肯定是会有盈利的。

一、总体架构:

1、网络路由:CDN

2、保护服务器及负载均衡:Nginx、HaProxy、LVS

3、业务独立:拆分各个应用服务器,并使用消息队列同步

4、小量数据加快访问:本地缓存

5、大量数据加快访问:memcached,redis及分布式部署

6、大量应用数据:文件服务器,数据库及分部署部署

二、CDN。

传统的未加缓存服务的访问过程:

三、HaProxy+keepalived

HAProxy反向代理服务器,支持双机热备支持虚拟主机,但其配置简单,拥有非常不错的服务器健康检查功能,当其代理的后端服务器出现故障, HAProxy会自动将该服务器摘除,故障恢复后再自动将该服务器加入

keepalived可提供vrrp以及health-check功能,可以只用它提供双机浮动的vip(vrrp虚拟路由功能),这样可以简单实现一个双机热备高可用功能。

详细配置见 haproxy+keepalived实现高可用负载均衡

四、memcached和redis

五、Mysql分布式

1、虚拟机上安装了Hadoop集群,仅仅在Windows下使用MyEclipse调试

2、安装MyEclipse8.5,低版本不行,下载hadoop-eclipse-plugin-2.6.0.jar插件至MyEclipse插件目录

3、启动MyEclipse,调出MapReduce环境,配置属性并连接,即可看到Hadoop文件目录

4、新建MapReduce项目,配置目录至hadoop-2.6.0.tar.gz解压的windows目录,并下载hadoop.dll和winutils.exe至该目录bin下,重启机器(否则后面执行程序报错)

5、修改服务器hdfs-site.xml,添加属性,否则报访问权限错误

<name>dfs.permissions</name>
<value>false</value>
<description>
</description>


6、如果报权限错误,需要从源码种拷贝NativeIO.java文件access(2),直接return true;

7、如果报vm内存错误,则配置vm 参数-Xmx1024m

8、到此为止,wordcount 程序在windows上总算能跑起来了。别忘了最后启动时候,加参数hdfs://hadoop200:9000/tmp/input/ hdfs://hadoop200:9000/tmp/output/

总结:

1、报错就搜索,基本都能查找到原因

2、各种自定义的环境真能折腾人

参考文章:

windows7+eclipse+hadoop2.5.2环境配置

hadoop :java.lang.OutOfMemoryError: Java heap space

Hadoop 解除 “Name node is in safe mode”