using nginx as http load balancer

Introduction

Load balancing across multiple application instances is a commonly used technique for optimizing resource utilization, maximizing throughput, reducing latency, and ensuring fault-tolerant configurations.

It is possible to use nginx as a very efficient HTTP load balancer to distribute traffic to several application servers and to improve performance, scalability and reliability of web applications with nginx.

Load balancing methods

The following load balancing mechanisms (or methods) are supported in nginx:

  • round-robin — requests to the application servers are distributed in a round-robin fashion,
  • least-connected — next request is assigned to the server with the least number of active connections,
  • ip-hash — a hash-function is used to determine what server should be selected for the next request (based on the client’s IP address).

Default load balancing configuration

The simplest configuration for load balancing with nginx may look like the following:

http {
    upstream myapp1 {
        server srv1.example.com;
        server srv2.example.com;
        server srv3.example.com;
    }

    server {
        listen 80;

        location / {
            proxy_pass http://myapp1;
        }
    }
}

In the example above, there are 3 instances of the same application running on srv1-srv3. When the load balancing method is not specifically configured, it defaults to round-robin. All requests are proxied to the server group myapp1, and nginx applies HTTP load balancing to distribute the requests. Continue reading "using nginx as http load balancer"

sql server 分区表

IF EXISTS(
       SELECT 1
       FROM   sys.databases AS d
       WHERE  d.name = 'Test_1'
   )
    DROP DATABASE Test_1
 GO
 CREATE DATABASE [Test_1] ON PRIMARY(
                                        NAME
                                        =
                                        N'Test_1',
                                        FILENAME
                                        =
                                        N'E:\Database\Sharding\Test_1.mdf',
                                        SIZE
                                        =
                                        10240KB,
                                        MAXSIZE
                                        =
                                        UNLIMITED,
                                        FILEGROWTH
                                        =
                                        1024Kb
                                    ),
 FILEGROUP [Test_A](
                       NAME = N'Test_A',
                       FILENAME = 'E:\Database\Sharding\Test_A.ndf',
                       SIZE = 10240kb,
                       MAXSIZE = UNLIMITED,
                       FILEGROWTH = 1024kB
                   ),
 FILEGROUP [Test_B](
                       NAME = N'Test_B',
                       FILENAME = 'E:\Database\Sharding\Test_B.ndf',
                       SIZE = 10240kb,
                       MAXSIZE = UNLIMITED,
                       FILEGROWTH = 1024kB
                   )
 LOG ON (
            NAME = N'Test_log',
            FILENAME = 'E:\Database\Sharding\Test_Log.ldf',
            SIZE = 10240kb,
            MAXSIZE = UNLIMITED,
            FILEGROWTH = 1024kB
        ) COLLATE Chinese_PRC_CI_AS

GO
 USE [Test_1]

IF EXISTS(
       SELECT 1
       FROM   sys.partition_functions AS pf
       WHERE  pf.name = 'TEST_PART'
   )
    DROP PARTITION FUNCTION [TEST_PART]
 GO
 -- set a partiton condition
 CREATE PARTITION FUNCTION TEST_PART(INT) AS RANGE LEFT FOR VALUES(2)
 GO
IF EXISTS(
       SELECT 1
       FROM   sys.partition_schemes AS ps
       WHERE  ps.name = 'TEST_SCH'
   )
    DROP PARTITION SCHEME [TEST_SCH]
 GO
 --set a scheme for table using.
 CREATE PARTITION SCHEME TEST_SCH
 AS PARTITION [TEST_PART] TO (Test_A, Test_B)
 GO
IF OBJECT_ID('STUDENT', 'U') IS NOT NULL
    DROP TABLE STUDENT
 GO
CREATE TABLE STUDENT
(
	Id        INT IDENTITY(1, 1) NOT NULL,
	NAME      VARCHAR(10) NULL,
	CLASS     INT NULL,
	GRADE     INT NULL
) ON TEST_SCH(Id) -- set scheme
 GO
INSERT INTO STUDENT
  (
    -- Id -- this column value is auto-generated
    NAME,
    CLASS,
    GRADE
  )
VALUES
  (
    'A',
    1,
    1
  );
INSERT INTO STUDENT
  (
    -- Id -- this column value is auto-generated
    NAME,
    CLASS,
    GRADE
  )
VALUES
  (
    'B',
    2,
    2
  );
INSERT INTO STUDENT
  (
    -- Id -- this column value is auto-generated
    NAME,
    CLASS,
    GRADE
  )
VALUES
  (
    'C',
    3,
    3
  );
INSERT INTO STUDENT
  (
    -- Id -- this column value is auto-generated
    NAME,
    CLASS,
    GRADE
  )
VALUES
  (
    'D',
    4,
    4
  )
 GO

慢性咽炎

今天心情不是很好,咳嗽了已经两三个月,吐沫中带有血。医生给做了胸部CT,检查了鼻,肺,咽喉等,最后又抽血检查了肺部支原体。

但是到现在,仍然没有找出来为什么有血。开了一些病,但我知道不是对症下药。

using more javascript syntax inside of angular directive template

在angularjs中,view中避免不了会用一些javascript,你会发现很多标准的javascript语法在html template中无法执行,从而达不到你预期的结果,比如:{{typeof("A")}} ,预期输出字符串string;  {{angular.isString("A")}},预期输出字符串true,这是因为html template是交由angularjs负责解释和编译的,而在template的对应作用域中,并未去支持所有的标准javascript语法和对象,其中就包括typeof(),但是支持比如"==","!=="等一些常用语法。

但是如果想要template支持更多的javascript对象和方法的话,那么就要在template的对应controller的scope中添加引用,比如:在controller中添加scope.angular=angular。那么在template中就可以使用angular.isString("A")了。

人生计划

说到人生计划,这真不是一件容易的事。

一直以来,自己对自己没有很好的人生规划,通常是走一步算一步。这几年,父母年龄越来越大,小孩也越来越大,伴随着自己思想的变化,觉得是该好好考虑一下自己的人生了,包括家庭的未来。

首先说说我的家庭构成:父母,老婆孩子,和我。

什么叫小康家庭,我不知道,如果指的是物质,我家庭勉强应该算的上是一个小康家庭。存款虽然不多,但是总共也有4套房产了(苏州1套,老家3套,包括商铺),而且面积和位置都很不错,手上也还有几亩良田。但是为什么生活总还是感觉不到幸福?父母经常吵,我和老婆也经常吵。

其中很大的原因在于,我们这个家庭不善于取舍。想什么都得到,反而什么都失去。

我老婆经常和我烦,把老家的房子卖掉,买辆车,在苏州再买一两套房,把父母接过来。这样大家在一起,多好。

但我总是瞻前顾后,唯唯诺诺。我又舍不得生我养我的土地;父母也不会离开生活了几十年的故乡。造成现在我和家庭总是翘首相望,两地分居。即使住进苏州的房子,也只是老婆孩子在一起了,仍然还是和父母分开。

唉,我总是这样。要么就离开苏州?回老家?做个生意?可我又会做什么生意呢?回家发展,当初干吗在苏州买房,现在卖了多亏!

总得有一个计划吧?冥思苦想,想了整整一年了。还是没有答案。我该怎么办?回家发展?还是留在苏州?

Sendmail Settings

通常新安装的Linux主机,hostname我们不会将其设置成真实的FQDN形式,这会造成在后面做一些应用服务器时,产生一些影响,比如mail server,做为mail server,如果你的当前hostname是linux.local,而你希望以xxx@realname.com发送邮件出去,那么在没有进行其它配置的情况下,当你将邮件发送后,接收人那里会显示xxx@realname.com,并由xxx@linux.local代发。有一些邮件接收服务器就会将你这封邮件做为垃圾邮件,放在垃圾箱里,那么该怎么更改呢,以做到只显示xxx@realname.com呢,下面是sendmail的设置方式:

  1. vim /etc/mail/sendmail.mc
    MASQUERADE_AS(`zhuoyue.me')dnl 
    FEATURE(`masquerade_envelope')dnl 
    FEATURE(`masquerade_entire_domain')dnl 
    MASQUERADE_DOMAIN(`zhuoyue.me')dnl
  2. make  -f /etc/mail/Makefile
  3. service sendmail reload

Application Pool Identities

Introduction

Whether you are running your site on your own server or in the cloud, security must be at the top of your priority list. If so, you will be happy to hear that IIS has a security feature called the application pool identity. This feature was introduced in Service Pack 2 (SP2) of Windows Server 2008 and Windows Vista. An application pool identity allows you to run an application pool under a unique account without having to create and manage domain or local accounts. The name of the application pool account corresponds to the name of the application pool. The image below shows an IIS worker process (W3wp.exe) running as the DefaultAppPool identity.

Application Pool Identity Accounts

Worker processes in IIS 6.0 and in IIS 7 run as Network Service by default. Network Service is a built-in Windows identity. It doesn't require a password and has only user privileges; that is, it is relatively low-privileged. Running as a low-privileged account is a good security practice because then a software bug can't be used by a malicious user to take over the whole system.

However, a problem arose over time as more and more Windows system services started to run as Network Service. This is because services running as Network Service can tamper with other services that run under the same identity. Because IIS worker processes run third-party code by default (Classic ASP, ASP.NET, PHP code), it was time to isolate IIS worker processes from other Windows system services and run IIS worker processes under unique identities. The Windows operating system provides a feature called "virtual accounts" that allows IIS to create a unique identity for each of its application pools. Click here for more information about Virtual Accounts. Continue reading "Application Pool Identities"

李雷和韩梅梅身世之谜揭晓

李雷和韩梅梅,他俩暗恋没有?交往没有?分手没有?在似乎有着漫长时光的青春岁月,每个曾捧着初中英语书的同学,白日无聊,也许都做过这样那样天马行空的想象。据统计,从1990年到2000年,写有“李雷和韩梅梅”故事的初中英语教科书,教育了整整一亿人。

官方权威解释,李雷和韩梅梅身世之谜揭晓

那么,抛开现在各种以李雷和韩梅梅为原型的歌曲、话剧、漫画、微电影、改编故事不提,你想不想听听李雷和韩梅梅的官方“八卦”?聊聊这套传奇教材背后的故事?

机会来了。日前,在“中国百年教科书整理与研究”项目成果发布,微信公众号“人民日报政文”的小编亲自探查,揭开了李雷和韩梅梅的“身世之谜”。

“划时代”的教科书 Continue reading "李雷和韩梅梅身世之谜揭晓"

Windows PowerShell Quick Reference

How to Access Arguments

To access command-line arguments used when starting a script use the automatic variable $args. You can cycle through the individual arguments in the $args collection by using code similar to this:

foreach ($i in $args) {$i}

To access a particular argument use the collection index number, with 0 representing the first item in the collection, 1 representing the second item, etc:

$args[0]

You can reference the last item in a collection by using the index number –1:

$args[-1]

How to Use Colored Text

To display text in a different color use the Write-Host cmdlet and specify a foreground color:

How to Get More Information

You can also specify a different background color: Continue reading "Windows PowerShell Quick Reference"