魏长东

weichangdong

Nginx 的 Echo 模块 —— echo-nginx-module

这个模块不包含在 Nginx 源码中,安装方法:

1. 首先下载模块源码:https://github.com/agentzh/echo-nginx-module/tags
2. 解压到某个路径,假设为 /path/to/echo-nginx-module
3. 使用下面命令编译并安装 Nginx

$ wget 'http://sysoev.ru/nginx/nginx-1.0.11.tar.gz'
$ tar -xzvf nginx-1.0.11.tar.gz
$ cd nginx-1.0.11/
 
# Here we assume you would install you nginx under /opt/nginx/.
$ ./configure --prefix=/opt/nginx \
--add-module=/path/to/echo-nginx-module
 
$ make -j2
$ make install

»»阅读全文

nginx+lua+redis三国演义

今天看到redis2_query  redis2_pass,然后网上一看,原来又是nginx的扩展。

以下copy 网路,自己还没有真正搞过。

redis2-nginx-module 是一个支持 Redis 2.0 协议的 Nginx upstream 模块,它可以让 Nginx 以非阻塞方式直接防问远方的 Redis 服务,同时支持 TCP 协议和 Unix Domain Socket 模式,并且可以启用强大的 Redis 连接池功能。

安装lua
# apt-get install lua5.1
# apt-get install liblua5.1-dev
# apt-get install liblua5.1-socket2
安装nginx
# apt-get install git-core
# git clone https://github.com/simpl/ngx_devel_kit.git
# git clone https://github.com/chaoslawful/lua-nginx-module.git
# git clone https://github.com/agentzh/redis2-nginx-module.git
# git clone https://github.com/agentzh/set-misc-nginx-module.git
# git clone https://github.com/agentzh/echo-nginx-module.git
# git clone https://github.com/catap/ngx_http_upstream_keepalive.git
# apt-get install libpcre3 libpcre3-dev libltdl-dev libssl-dev libjpeg62 libjpeg62-dev libpng12-0
 libpng12-dev 
libxml2-dev libcurl4-openssl-dev libmcrypt-dev autoconf 
libxslt1-dev libgd2-noxpm-dev libgeoip-dev libperl-dev -y
# wget http://nginx.org/download/nginx-1.0.8.tar.gz
# tar zxvf nginx-1.0.8.tar.gz
# cd nginx-1.0.8
# ./configure --prefix=/usr/local/nginx --with-debug --with-http_addition_module \
--with-http_dav_module --with-http_flv_module --with-http_geoip_module \
--with-http_gzip_static_module --with-http_image_filter_module --with-http_perl_module \
--with-http_random_index_module --with-http_realip_module --with-http_secure_link_module \
--with-http_stub_status_module --with-http_ssl_module --with-http_sub_module \
--with-http_xslt_module --with-ipv6 --with-sha1=/usr/include/openssl \
--with-md5=/usr/include/openssl --with-mail --with-mail_ssl_module \
--add-module=../ngx_devel_kit \
--add-module=../echo-nginx-module \
--add-module=../lua-nginx-module \
--add-module=../redis2-nginx-module \
--add-module=../ngx_http_upstream_keepalive \
--add-module=../set-misc-nginx-module
# make
# make install
安装lua-redis-parser


# git clone https://github.com/agentzh/lua-redis-parser.git
# export LUA_INCLUDE_DIR=/usr/include/lua5.1
# make CC=gcc
# make install CC=gcc

安装json
# wget http://files.luaforge.net/releases/json/json/0.9.50/json4lua-0.9.50.zip
# unzip json4lua-0.9.50.zip
# cp json4lua-0.9.50/json/json.lua /usr/share/lua/5.1/
安装redis-lua

# git clone https://github.com/nrk/redis-lua.git
# cp redis-lua/src/redis.lua /usr/share/lua/5.1/

»»阅读全文

lua html模板(win)

set $template_location "/html";   
	set $template_root "D:/openresty/html/html";
	

	
	location /html_html {  
		default_type 'text/html';  
		content_by_lua_file "html/html/test_template_1.lua";   
	}  
	
	location /html_html2 {  
		default_type 'text/html';  
		content_by_lua_file "html/html/test_template_2.lua";   
	} 
	
		
	location /html_html3 {  
		default_type 'text/html';  
		charset utf-8;
		#ngx.header['Content-Type']="text/html;charset=UTF-8"
		content_by_lua_file "html/html/test_template_3.lua";   
	} 

»»阅读全文

Nginx Push Stream Module

https://www.nginx.com/resources/wiki/modules/push_stream/

有时间研究下。

elastic search扫描模式

function makeLangAction()
    {
        $es = self::connectEs();
        $params = array(  
            "search_type" => "scan",
            "scroll" => "30s",
            "size" => 50,
            "index" => "360weather",  
            "body" => array(  
                "query" => array(  
                    "match_all" => array()  
                )  
            )  
        );  
          
        $docs = $es->search($params);
        $scroll_id = $docs['_scroll_id'];
        $redis = new RedisModel('write');
        echo "all num ".$docs['hits']['total']."\n";
        $num = 0;
        $all_tz = [];
        while (true) {   
            $response = $es->scroll(  
                array(  
                    "scroll_id" => $scroll_id,
                    "scroll" => "30s",
                )  
            );  
            if (count($response['hits']['hits']) > 0) {  
                //loop $response['hits']['hits'] data
                $scroll_id = $response['_scroll_id'];
                //$num += count($response['hits']['hits']); 
                foreach ($response['hits']['hits'] as $tmp) {
                    $tt = explode('_', $tmp['_id']);
                    $loc_id = $tt[0];
                    $data = $tmp['_source'];
                    $lang = $data['lang'];
                    $lang_info = json_encode([
                        'area' => $data['country_code'],
                        'province' => $data['province'],
                        'name' => $data['city'],
                        'tz' => $data['tz'],
                    ]);
                    $tz_num = Functions::computerTz($data['tz']);
                    /*
                    if (isset($all_tz[$data['tz']])) {
                        
                    } else {
                        $all_tz[$data['tz']] = $tz_num;
                    }
                    */
                    $redis->hset(self::REDIS_CITY_ID_WEATHER.$loc_id,self::REDIS_CITY_LANG.$lang,$lang_info);
                    $redis->hset(self::REDIS_CITY_ID_WEATHER.$loc_id,'tz',$tz_num);
                    $num++;
                } 
            } else {   
                break;  
            }  
        }
        
        echo 'tz num '.count($all_tz)."\n";
        print_R($all_tz);
        
        echo "set num ". $num ."\n";  
    }

git 分支

最近天气项目,测试和正式环境使用两套代码(主要是测试环境测试人员需要保留方便测试的接口,数据传输没有加密)。所以用git创建一个新的branch,通过jenkins配置,
 

测试项目用test的branch,online项目用master。用到的命令大概有
查看本地、远程、所有分支 git branch、git branch -r、git branch -a
创建分支 git branch test
删除本地、远程分支   git branch -d test,git branch -d -r test 删除的时候要是有报错,就加-D
重命名 git branch -m old_name new_name
推送到分支 git push origin test  
切换分之 git checkout test

openshift 修改http的配置

修改完配置,kill掉进程,然后用以下的命令重启。

我用的是免费的。

/usr/sbin/httpd -C "Include /var/lib/openshift/5785b5c989f5cf177f00009e/phpmyadmin/conf.d/*.conf" -f /var/lib/openshift/5785b5c989f5cf177f00009e/phpmyadmin/conf/httpd_nolog.conf -c  "Include /etc/openshift/cart.conf.d/httpd/*.conf" -c  "Include /etc/openshift/cart.conf.d/httpd/phpmyadmin/*.conf" -D FOREGROUND &
/usr/sbin/httpd -C "Include /var/lib/openshift/5785b5c989f5cf177f00009e/phpmyadmin/conf.d/*.conf" -f /var/lib/openshift/5785b5c989f5cf177f00009e/phpmyadmin/conf/httpd_nolog.conf -c "Include /etc/openshift/cart.conf.d/httpd/*.conf" -c "Include /etc/openshift/cart.conf.d/httpd/phpmyadmin/*.conf" -D FOREGROUND &
/usr/sbin/httpd -c "Include /var/lib/openshift/5785b5c989f5cf177f00009e/php//configuration/etc/conf.d/*.conf" -f /var/lib/openshift/5785b5c989f5cf177f00009e/php//configuration/etc/conf/httpd_nolog.conf -c "Include /etc/openshift/cart.conf.d/httpd/*.conf" -c "Include /etc/openshift/cart.conf.d/httpd/php/*.conf" -D FOREGROUND &
/usr/sbin/httpd -c "Include /var/lib/openshift/5785b5c989f5cf177f00009e/php//configuration/etc/conf.d/*.conf" -f /var/lib/openshift/5785b5c989f5cf177f00009e/php//configuration/etc/conf/httpd_nolog.conf -c "Include /etc/openshift/cart.conf.d/httpd/*.conf" -c "Include /etc/openshift/cart.conf.d/httpd/php/*.conf" -D FOREGROUND &
/usr/sbin/httpd -c "Include /var/lib/openshift/5785b5c989f5cf177f00009e/php//configura" &

时区大全

http://www.zeitverschiebung.net/en/difference/timezone/Australia/Broken_Hill/timezone/asia--shanghai
时区和utc时区相差小时数
    [Asia/Riyadh] => 3
    [Asia/Tehran] => 3.5
    [Asia/Yerevan] => 4
    [Africa/Lusaka] => 2
    [Africa/Nairobi] => 3
    [Africa/Kigali] => 2
    [Africa/Lubumbashi] => 2
    [Africa/Kinshasa] => 1
    [Africa/Djibouti] => 3
    [Africa/Kampala] => 3
    [Africa/Bangui] => 1
    [Africa/Ndjamena] => 1
    [Asia/Amman] => 3
    [Africa/Blantyre] => 2
    [Asia/Nicosia] => 3
    [Africa/Luanda] => 1
    [Africa/Dar_es_Salaam] => 3
    [Asia/Baku] => 4
    [Indian/Mahe] => 4
    [Asia/Ashgabat] => 5
    [Asia/Damascus] => 3
    [Europe/Athens] => 3
    [Africa/Mogadishu] => 3
    [Asia/Aden] => 3
    [Africa/Tripoli] => 2
    [Asia/Baghdad] => 3
    [Africa/Addis_Ababa] => 3
    [Africa/Asmara] => 3
    [Africa/Cairo] => 2
    [Africa/Khartoum] => 3
    [Asia/Jerusalem] => 3
    [Asia/Kuwait] => 3
    [Asia/Qatar] => 3
    [Asia/Muscat] => 4
    [Europe/Riga] => 3
    [Europe/Moscow] => 3
    [Europe/Volgograd] => 3
    [Europe/Tirane] => 2
    [Asia/Yekaterinburg] => 5
    [Europe/Ulyanovsk] => 4
    [Europe/Samara] => 4
    [Europe/Astrakhan] => 4
    [Europe/Kaliningrad] => 2
    [Europe/Istanbul] => 3
    [Africa/Bujumbura] => 2
    [Asia/Beirut] => 3
    [Asia/Gaza] => 3
    [Asia/Dubai] => 4
    [Asia/Bahrain] => 3
    [Europe/Zaporozhye] => 3
    [Europe/Simferopol] => 3
    [Europe/Tallinn] => 3
    [Asia/Tbilisi] => 4
    [Europe/Chisinau] => 3
    [Europe/Minsk] => 3
    [Europe/Vilnius] => 3
    [Asia/Samarkand] => 5
    [Europe/Stockholm] => 2
    [Asia/Aqtobe] => 5
    [Asia/Aqtau] => 5
    [Asia/Almaty] => 6
    [Asia/Oral] => 5
    [Europe/Helsinki] => 3
    [Europe/Kiev] => 3
    [Europe/Uzhgorod] => 3
    [Europe/Bucharest] => 3
    [Europe/Bratislava] => 2
    [Europe/Sofia] => 3
    [Europe/Budapest] => 2
    [Europe/Skopje] => 2
    [Europe/Belgrade] => 2
    [Europe/Oslo] => 2
    [Europe/Warsaw] => 2
    [Europe/Podgorica] => 2
    [Asia/Kabul] => 4.5
    [Asia/Bangkok] => 7
    [Asia/Karachi] => 5
    [Asia/Dushanbe] => 5
    [Asia/Kuala_Lumpur] => 8
    [Asia/Colombo] => 5.5
    [Africa/Johannesburg] => 2
    [Asia/Bishkek] => 6
    [Asia/Thimphu] => 6
    [Asia/Kolkata] => 5.5
    [Africa/Maseru] => 2
    [Africa/Gaborone] => 2
    [Africa/Harare] => 2
    [Africa/Maputo] => 2
    [Indian/Antananarivo] => 3
    [Indian/Mayotte] => 3
    [Indian/Comoro] => 3
    [Indian/Mauritius] => 4
    [Africa/Mbabane] => 2
    [Indian/Reunion] => 4
    [Africa/Windhoek] => 2
    [Asia/Dhaka] => 6
    [Asia/Jakarta] => 7
    [Asia/Pontianak] => 7
    [Asia/Tashkent] => 5
    [Asia/Makassar] => 8
    [Indian/Maldives] => 5
    [Asia/Krasnoyarsk] => 7
    [Asia/Barnaul] => 7
    [Asia/Novokuznetsk] => 7
    [Asia/Novosibirsk] => 6
    [Asia/Irkutsk] => 8
    [Asia/Omsk] => 6
    [Asia/Tomsk] => 7
    [Asia/Urumqi] => 6
    [Asia/Kashgar] => 6
    [Asia/Kathmandu] => 5.75
    [Asia/Rangoon] => 6.5
    [Asia/Chongqing] => 8
    [Asia/Qyzylorda] => 6
    [Asia/Manila] => 8
    [Pacific/Palau] => 9
    [Asia/Ho_Chi_Minh] => 7
    [Asia/Jayapura] => 9
    [Indian/Cocos] => 6.5
    [Asia/Ulaanbaatar] => 8
    [Indian/Kerguelen] => 5
    [Asia/Vientiane] => 7
    [Asia/Taipei] => 8
    [Asia/Shanghai] => 8
    [Pacific/Pohnpei] => 11
    [Asia/Dili] => 9
    [Asia/Kuching] => 8
    [Asia/Harbin] => 8
    [Asia/Pyongyang] => 8.5
    [Asia/Tokyo] => 9
    [Asia/Seoul] => 9
    [Asia/Yakutsk] => 9
    [Asia/Vladivostok] => 10
    [Asia/Khandyga] => 9
    [Pacific/Port_Moresby] => 10
    [Pacific/Guadalcanal] => 11
    [Pacific/Tarawa] => 12
    [Pacific/Efate] => 11
    [Pacific/Noumea] => 11
    [Australia/Melbourne] => 11
    [Australia/Lindeman] => 10
    [Australia/Sydney] => 11
    [Australia/Brisbane] => 10
    [Pacific/Majuro] => 12
    [Asia/Kamchatka] => 12
    [Asia/Magadan] => 11
    [Asia/Ust-Nera] => 10
    [Asia/Sakhalin] => 11
    [Asia/Anadyr] => 12
    [Australia/Currie] => 11
    [Australia/Hobart] => 11
    [Australia/Adelaide] => 10.5
    [Pacific/Auckland] => 13
    [Australia/Darwin] => 9.5
    [Australia/Perth] => 8
    [Indian/Christmas] => 7
    [Pacific/Kosrae] => 11
    [Asia/Singapore] => 8
    [Pacific/Funafuti] => 12
    [Asia/Choibalsan] => 8
    [Asia/Brunei] => 8
    [Asia/Macau] => 8
    [Asia/Phnom_Penh] => 7
    [Asia/Hong_Kong] => 8
    [Africa/Dakar] => 0
    [Africa/Brazzaville] => 1
    [Australia/Broken_Hill] => 10.5
    [Europe/Lisbon] => 1
    [Atlantic/Madeira] => 1
    [Africa/Monrovia] => 0
    [Africa/Tunis] => 1
    [Africa/Algiers] => 1
    [Africa/Abidjan] => 0
    [Africa/Accra] => 0
    [Africa/Malabo] => 1
    [Africa/Douala] => 1
    [Pacific/Fiji] => 12
    [Europe/Madrid] => 2
    [Africa/Ceuta] => 2
    [Africa/Lagos] => 1
    [Africa/Ouagadougou] => 0
    [Africa/Lome] => 0
    [Africa/Bissau] => 0
    [Africa/Nouakchott] => 0
    [Africa/Porto-Novo] => 1
    [Africa/Libreville] => 1
    [Africa/Freetown] => 0
    [Africa/Sao_Tome] => 0
    [Africa/Banjul] => 0
    [Atlantic/Canary] => 1
    [Africa/Niamey] => 1
    [Africa/Bamako] => 0
    [Africa/El_Aaiun] => 1
    [Atlantic/St_Helena] => 0
    [Africa/Conakry] => 0
    [Europe/Gibraltar] => 2
    [Africa/Casablanca] => 1
    [Europe/Malta] => 2
    [Europe/Rome] => 2
    [Europe/Copenhagen] => 2
    [Atlantic/Faroe] => 1
    [Europe/Vienna] => 2
    [Europe/London] => 1
    [Atlantic/Reykjavik] => 0
    [Europe/Dublin] => 1
    [Europe/Zurich] => 2
    [Arctic/Longyearbyen] => 2
    [Europe/Amsterdam] => 2
    [Europe/Berlin] => 2
    [Europe/Brussels] => 2
    [Europe/Paris] => 2
    [Europe/Luxembourg] => 2
    [Europe/Monaco] => 2
    [Europe/Andorra] => 2
    [Europe/Vaduz] => 2
    [Europe/Jersey] => 1
    [Europe/Guernsey] => 1
    [Europe/Prague] => 2
    [Europe/Isle_of_Man] => 1
    [Europe/San_Marino] => 2
    [Europe/Ljubljana] => 2
    [Europe/Sarajevo] => 2
    [Europe/Zagreb] => 2
    [Atlantic/Azores] => 0
    [America/Barbados] => -4
    [America/Maceio] => -3
    [America/Fortaleza] => -3
    [America/Belem] => -3
    [America/Araguaina] => -3
    [America/Manaus] => -4
    [America/Recife] => -3
    [America/Godthab] => -2
    [Atlantic/Cape_Verde] => -1
    [America/Guyana] => -4
    [America/Cayenne] => -3
    [America/Paramaribo] => -3
    [America/Asuncion] => -3
    [America/Montevideo] => -3
    [America/Miquelon] => -2
    [Atlantic/South_Georgia] => -2
    [Atlantic/Stanley] => -3
    [America/Argentina/Buenos_Aires] => -3
    [America/Argentina/Tucuman] => -3
    [America/La_Paz] => -4
    [America/Sao_Paulo] => -3
    [America/Bahia] => -3
    [America/Campo_Grande] => -4
    [America/Cuiaba] => -4
    [America/Argentina/Cordoba] => -3
    [America/Martinique] => -4
    [America/Nassau] => -4
    [America/Port_of_Spain] => -4
    [America/St_Kitts] => -4
    [America/Dominica] => -4
    [America/Havana] => -4
    [America/Anguilla] => -4
    [America/Antigua] => -4
    [America/St_Lucia] => -4
    [Atlantic/Bermuda] => -3
    [America/St_Vincent] => -4
    [America/Montserrat] => -4
    [America/Guadeloupe] => -4
    [America/Grenada] => -4
    [America/Cayman] => -5
    [America/Belize] => -6
    [America/El_Salvador] => -6
    [America/Guatemala] => -6
    [America/Aruba] => -4
    [America/Grand_Turk] => -4
    [America/Santo_Domingo] => -4
    [America/Curacao] => -4
    [America/Lower_Princes] => -4
    [America/Mexico_City] => -5
    [America/Merida] => -5
    [America/Tegucigalpa] => -6
    [America/Managua] => -6
    [America/Monterrey] => -5
    [America/Caracas] => -4
    [America/Jamaica] => -5
    [America/Cancun] => -5
    [America/Costa_Rica] => -6
    [America/Tortola] => -4
    [America/Panama] => -5
    [America/Port-au-Prince] => -5
    [America/Lima] => -5
    [America/Bogota] => -5
    [America/Thule] => -3
    [America/Argentina/Jujuy] => -3
    [America/Argentina/Mendoza] => -3
    [America/Santiago] => -3
    [America/Argentina/Ushuaia] => -3
    [America/Rio_Branco] => -5
    [America/Porto_Velho] => -4
    [America/Argentina/San_Juan] => -3
    [America/Mazatlan] => -6
    [America/Tijuana] => -7
    [America/Guayaquil] => -5
    [America/Argentina/Rio_Gallegos] => -3
    [America/Hermosillo] => -7
    [Pacific/Galapagos] => -6
    [America/Boa_Vista] => -4
    [America/Argentina/Catamarca] => -3
    [America/Argentina/La_Rioja] => -3
    [America/Eirunepe] => -5
    [America/Chihuahua] => -6
    [Pacific/Fakaofo] => 13
    [Pacific/Tongatapu] => 13
    [Pacific/Tahiti] => -10
    [Pacific/Wallis] => 12
    [Pacific/Apia] => 14
    [Pacific/Pitcairn] => -8
    [America/Indiana/Knox] => -5
    [America/Chicago] => -5
    [America/New_York] => -4
    [America/Kentucky/Monticello] => -4
    [Pacific/Rarotonga] => -10
    [Pacific/Niue] => -11
    [Pacific/Guam] => 10
    [Pacific/Saipan] => 10
    [America/Indiana/Marengo] => -4
    [America/Indiana/Vevay] => -4
    [Pacific/Gambier] => -9
    [America/Indiana/Petersburg] => -4
    [Pacific/Easter] => -5
    [America/North_Dakota/New_Salem] => -5
    [America/Kentucky/Louisville] => -4
    [America/Detroit] => -4
    [America/Indiana/Indianapolis] => -4
    [America/Indiana/Vincennes] => -4
    [America/Indiana/Tell_City] => -5
    [America/Puerto_Rico] => -4
    [America/St_Thomas] => -4
    [America/Menominee] => -5
    [America/North_Dakota/Center] => -5
    [America/Los_Angeles] => -7
    [America/Phoenix] => -7
    [America/Denver] => -6
    [America/Shiprock] => -6
    [America/Boise] => -6
    [America/Juneau] => -8
    [America/Yakutat] => -8
    [America/Edmonton] => -6
    [America/Dawson_Creek] => -7
    [America/Regina] => -6
    [America/Swift_Current] => -6
    [America/Montreal] => -4
    [America/Vancouver] => -7
    [America/Resolute] => -5
    [America/Goose_Bay] => -3
    [America/Toronto] => -4
    [America/Moncton] => -3
    [America/Iqaluit] => -4
    [America/St_Johns] => -2.5
    [America/Winnipeg] => -5
    [America/Halifax] => -3
    [America/Nipigon] => -4
    [America/Glace_Bay] => -3
    [America/Rankin_Inlet] => -5
    [America/Whitehorse] => -7
    [America/Rainy_River] => -5
    [America/Anchorage] => -8
    [America/Nome] => -8
    [Pacific/Pago_Pago] => -11
    [America/Blanc-Sablon] => -4
    [America/Inuvik] => -6
    [America/Yellowknife] => -6
    [America/Pangnirtung] => -4
    [America/Cambridge_Bay] => -6
    [America/Adak] => -9
    [Pacific/Honolulu] => -10
    [America/Dawson] => -7
    [America/Thunder_Bay] => -4
    [Europe/Vatican] => 2
    [Antarctica/McMurdo] => 13

elastic search 集群小知识

curl  localhost:9200/360weather/_count?pretty

curl  http://localhost:9200/_cat/indices?v
curl  http://localhost:9200/_cat/nodes?v
curl  http://localhost:9200/_cat/health?v

curl  http://localhost:9200/_cluster/health
curl  http://localhost:9200/_cluster/state

curl  http://localhost:9200/_nodes/process/stats