Merge remote-tracking branch 'LCTT/master'

This commit is contained in:
Xingyu.Wang 2018-12-01 21:22:04 +08:00
commit b45bd7ab17
4 changed files with 327 additions and 15 deletions

View File

@ -1,15 +1,15 @@
流量引导:网络世界的负载均衡解密
======
均衡网络流量的常用技术,它们的优势和利弊权衡。
> 均衡网络流量的常用技术,它们的优势和利弊权衡。
![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/traffic-light-go.png?itok=nC_851ys)
大型的多站点互联网系统包括内容分发网络CDN和云服务提供商用一些方法来均衡来访的流量。这篇文章我们讲一下常见的流量均衡设计包括它们的技术手段和利弊权衡。
如果你很早就用云计算技术来提供服务的话,你可能在单台云服务器上搭建 web 服务,分配一个 IP 地址然后配置一个给人读的域名DNS指向这个 IP 地址,再将 IP 地址通过边界网关协议BGP宣告出去BGP 是在不同网络之间交换路由信息的标准方式。
早期的云计算服务提供商,可以提供单一一台客户 Web 服务器,分配一个 IP 地址,然后用一个便于人读的域名配置一个 DNS 记录指向这个 IP 地址,再将 IP 地址通过边界网关协议BGP宣告出去BGP 是在不同网络之间交换路由信息的标准方式。
这本身并不是负载均衡,但是在冗余的多条网络路径中,很可能是有流量分发的,而且利用网络技术让流量绕过不可用的网络,从而提高了可用性(也引起了[非对称路由][1]的现象)。
这本身并不是负载均衡,但是能在冗余的多条网络路径中进行流量分发,而且可以利用网络技术让流量绕过不可用的网络,从而提高了可用性(也引起了[非对称路由][1]的现象)。
### 简单的 DNS 负载均衡
@ -25,9 +25,9 @@
![Layer 4 load balancers balance connections across webservers.][5]
四层负载均衡器能够均衡用户和两台 web 服务器的连接
*四层负载均衡器能够均衡用户和两台 web 服务器的连接*
四层均衡器将网络流量均衡地引导至后端服务器。通常这是基于对 IP 数据包的五元组做散列(数学函数)来完成的,五元组包括:源地址,源端口,目的地址,目的端口,协议(比如 TCP 或 UDP。这种方法是快速和高效的还维持了 TCP 的基本属性),而且不需要均衡器维持每个连接的状态。(更多信息请阅读[谷歌发表的 Maglev 论文][6],这篇论文详细讨论了四层软件负载均衡器的实现细节。)
四层均衡器将网络流量均衡地引导至后端服务器。通常这是基于对 IP 数据包的五元组做散列(数学函数)来完成的,五元组包括:源地址、源端口、目的地址、目的端口、协议(比如 TCP 或 UDP。这种方法是快速和高效的还维持了 TCP 的基本属性),而且不需要均衡器维持每个连接的状态。(更多信息请阅读[谷歌发表的 Maglev 论文][6],这篇论文详细讨论了四层软件负载均衡器的实现细节。)
四层均衡器可以对后端服务做健康检查,只把流量分发到健康的机器上。和使用 DNS 做负载均衡不同的是,在某个后端 web 服务故障的时候,它可以很快地把流量重新分发到其他机器上,虽然故障机器的已有连接会被重置。
@ -35,29 +35,29 @@
### 扩展到多站点
系统规模在持续增长。你的客户希望能一直使用服务,即使数据中心发生故障的时候。所以你建设了一个新的数据中心,独立部署了一套服务和四层负载均衡器集群,仍然使用同样的 VIP。DNS 的设置不变。
系统规模在持续增长。你的客户希望能一直使用服务,即使数据中心发生故障的时候。所以你建设了一个新的数据中心,另外独立部署了一套服务和四层负载均衡器集群,仍然使用同样的 VIP。DNS 的设置不变。
两个站点的边缘路由器都把自己的地址空间宣告出去,包括 VIP 地址。发往该 VIP 的请求可能到达任何一个站点,取决于用户和系统之间的网络是如何连接的,以及各个网络的路由策略是如何配置的。这就是泛播。大部分时候这种机制可以很好的工作。如果一个站点出问题了,你可以停止通过 BGP 宣告 VIP 地址,客户的请求就会迅速地转移到另外一个站点去。
![Serving from multiple sites using anycast][8]
多个站点使用泛播提供服务
*多个站点使用泛播提供服务*
这种设置有一些问题。最大的问题是,不能控制请求流向哪个站点,或者限制某个站点的流量。也没有一个明确的方式把用户的请求转到距离他最近的站点(为了降低网络延迟),不过,网络协议和路由选路配置在大部分情况下应该能把用户请求路由到最近的站点。
### 控制多站点系统中的入方向请求
### 控制多站点系统中的入请求
为了维持稳定性,需要能够控制每个站点的流量大小。要实现这种控制,可以给每个站点分配不同的 VIP 地址,然后用简单的或者有权重的 DNS [轮询][9]来做负载均衡。
![Serving from multiple sites using a primary VIP][11]
多站点提供服务,每个站点使用一个主 VIP另外一个站点作为备份。基于能感知地理位置的 DNS。
*多站点提供服务,每个站点使用一个主 VIP另外一个站点作为备份。基于能感知地理位置的 DNS。*
现在有两个问题。
第一使用 DNS 均衡意味着会有被缓存的记录,如果你要快速重定向流量的话就麻烦了。
第一使用 DNS 均衡意味着会有被缓存的记录,如果你要快速重定向流量的话就麻烦了。
第二用户每次做新的 DNS 查询,都可能连上任意一个站点,可能不是距离最近的。如果你的服务运行在分布广泛的很多站点上,用户会感受到响应时间有明显的变化,取决于用户和提供服务的站点之间有多大的网络延迟。
第二用户每次做新的 DNS 查询,都可能连上任意一个站点,可能不是距离最近的。如果你的服务运行在分布广泛的很多站点上,用户会感受到响应时间有明显的变化,取决于用户和提供服务的站点之间有多大的网络延迟。
让每个站点都配置上其他所有站点的 VIP 地址,并宣告出去(因此也会包含故障的站点),这样可以解决第一个问题。有一些网络上的小技巧,比如备份站点宣告路由时,不像主站点使用那么具体的目的地址,这样可以保证每个 VIP 的主站点只要可用就会优先提供服务。这是通过 BGP 来实现的,所以我们应该可以看到,流量在 BGP 更新后的一两分钟内就开始转移了。
@ -69,13 +69,13 @@
虽然四层负载均衡可以高效地在多个 web 服务器之间分发流量但是它们只针对源地址、目标地址、协议和端口来操作请求的内容是什么就不得而知了所以很多高级功能在四层负载均衡上实现不了。而七层L7负载均衡知道请求的内容和结构所以能做更多的事情。
七层负载均衡可以实现缓存,限速,错误注入,做负载均衡时可以感知到请求的代价(有些请求需要服务器花更多的时间去处理)。
七层负载均衡可以实现缓存、限速、错误注入,做负载均衡时可以感知到请求的代价(有些请求需要服务器花更多的时间去处理)。
七层负载均衡还可以基于请求的属性(比如 HTTP cookies来分发流量可以终结 SSL 连接还可以帮助防御应用层的拒绝服务DoS攻击。规模大的 L7 负载均衡的缺点是成本——处理请求需要更多的计算,而且每个活跃的请求都占用一些系统资源。在一个或者多个 L7 均衡器前面运行 L4 均衡器集群,对扩展规模有帮助。
七层负载均衡还可以基于请求的属性(比如 HTTP cookies来分发流量可以终结 SSL 连接还可以帮助防御应用层的拒绝服务DoS攻击。规模大的 L7 负载均衡的缺点是成本 —— 处理请求需要更多的计算,而且每个活跃的请求都占用一些系统资源。在一个或者多个 L7 均衡器前面运行 L4 均衡器集群,对扩展规模有帮助。
### 结论
负载均衡是一个复杂的难题。除了上面说过的策略,还有不同的[负载均衡算法][13],用来实现负载均衡器的高可用技术客户端负载均衡技术,以及最近兴起的服务网络等等。
负载均衡是一个复杂的难题。除了上面说过的策略,还有不同的[负载均衡算法][13],用来实现负载均衡器的高可用技术客户端负载均衡技术,以及最近兴起的服务网络等等。
核心的负载均衡模式随着云计算的发展而不断发展,而且,随着大型 web 服务商致力于让负载均衡技术更可控和更灵活,这项技术会持续发展下去。
@ -86,7 +86,7 @@ via: https://opensource.com/article/18/10/internet-scale-load-balancing
作者:[Laura Nolan][a]
选题:[lujun9972][b]
译者:[BeliteX](https://github.com/belitex)
校对:[校对者ID](https://github.com/校对者ID)
校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出

View File

@ -1,3 +1,4 @@
Name1e5s translating.
The Source History of Cat
======
I once had a debate with members of my extended family about whether a computer science degree is a degree worth pursuing. I was in college at the time and trying to decide whether I should major in computer science. My aunt and a cousin of mine believed that I shouldnt. They conceded that knowing how to program is of course a useful and lucrative thing, but they argued that the field of computer science advances so quickly that everything I learned would almost immediately be outdated. Better to pick up programming on the side and instead major in a field like economics or physics where the basic principles would be applicable throughout my lifetime.

View File

@ -0,0 +1,180 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: subject: (Emacs #2: Introducing org-mode)
[#]: via: (https://changelog.complete.org/archives/9865-emacs-2-introducing-org-mode)
[#]: author: (John Goerzen http://changelog.complete.org/archives/author/jgoerzen)
[#]: url: ( )
Emacs #2: Introducing org-mode
======
In [my first post in my series on Emacs][1], I described returning to Emacs after over a decade of vim, and org-mode being the reason why.
I really am astounded at the usefulness, and simplicity, of org-mode. It is really a killer app.
**So what exactly is org-mode?**
I wrote yesterday:
> Its an information organization platform. Its website says “Your life in plain text: Org mode is for keeping notes, maintaining TODO lists, planning projects, and authoring documents with a fast and effective plain-text system.”
Thats true, but doesnt quite capture it. org-mode is a toolkit for you to organize things. It has reasonable out-of-the-box defaults, but its designed throughout for you to customize.
To highlight a few things:
* **Maintaining TODO lists** : items can be scattered across org-mode files, contain attachments, have tags, deadlines, schedules. There is a convenient “agenda” view to show you what needs to be done. Items can repeat.
* **Authoring documents** : org-mode has special features for generating HTML, LaTeX, slides (with LaTeX beamer), and all sorts of other formats. It also supports direct evaluation of code in-buffer and literate programming in virtually any Emacs-supported language. If you want to bend your mind on this stuff, read [this article on literate devops][2]. The [entire Worg website][3]
is made with org-mode.
* **Keeping notes** : yep, it can do that too. With full-text search, cross-referencing by file (as a wiki), by UUID, and even into other systems (into mu4e by Message-ID, into ERC logs, etc, etc.)
**Getting started**
I highly recommend watching [Carsten Dominiks excellent Google Talk on org-mode][4]. It is an excellent introduction.
org-mode is included with Emacs, but youll often want a more recent version. Debian users can `apt-get install org-mode`, or it comes with the Emacs packaging system; `M-x package-install RET org-mode RET` may do it for you.
Now, youll probably want to start with the org-mode compact guides [introduction section][5], noting in particular to set the keybindings mentioned in the [activation section][6].
**A good tutorial…**
Ive linked to a number of excellent tutorials and introductory items; this post is not going to serve as a tutorial. There are two good videos linked at the end of this post, in particular.
**Some of my configuration**
Ill document some of my configuration here, and go into a bit of what it does. This isnt necessarily because youll want to copy all of this verbatim — but just to give you a bit of an idea of some of what can be configured, an idea of what to look up in the manual, and maybe a reference for “now how do I do that?”
First, I set up Emacs to work in UTF-8 by default.
```
(prefer-coding-system 'utf-8) (set-language-environment "UTF-8")
```
org-mode can follow URLs. By default, it opens in Firefox, but I use Chromium.
```
(setq browse-url-browser-function 'browse-url-chromium)
```
I set the basic key bindings as documented in the Guide, plus configure the M-RET behavior.
```
(global-set-key "\C-cl" 'org-store-link)
(global-set-key "\C-ca" 'org-agenda)
(global-set-key "\C-cc" 'org-capture)
(global-set-key "\C-cb" 'org-iswitchb)
(setq org-M-RET-may-split-line nil)
```
**Configuration: Capturing**
I can press `C-c c` from anywhere in Emacs. It will [capture something for me][7], and include a link back to whatever I was working on.
You can define [capture templates][8] to set how this will work. I am going to keep two journal files for general notes about meetings, phone calls, etc. One for personal, one for work items. If I press `C-c c j`, then it will capture a personal item. The %a in all of these includes the link to where I was (or a link I had stored with `C-c l`).
```
(setq org-default-notes-file "~/org/tasks.org")
(setq org-capture-templates
'(
("t" "Todo" entry (file+headline "inbox.org" "Tasks")
"* TODO %?\n %i\n %u\n %a")
("n" "Note/Data" entry (file+headline "inbox.org" "Notes/Data")
"* %? \n %i\n %u\n %a")
("j" "Journal" entry (file+datetree "~/org/journal.org")
"* %?\nEntered on %U\n %i\n %a")
("J" "Work-Journal" entry (file+datetree "~/org/wjournal.org")
"* %?\nEntered on %U\n %i\n %a")
))
(setq org-irc-link-to-logs t)
```
I like to link by UUIDs, which lets me move things between files without breaking locations. This helps generate UUIDs when I ask Org to store a link target for future insertion.
```
(require 'org-id)
(setq org-id-link-to-org-use-id 'create-if-interactive)
```
**Configuration: agenda views**
I like my week to start on a Sunday, and for org to note the time when I mark something as done.
```
(setq org-log-done 'time)
(setq org-agenda-start-on-weekday 0)
```
**Configuration: files and refiling**
Here I tell it what files to use in the agenda, and to add a few more to the plain text search. I like to keep a general inbox (from which I can move, or “refile”, content), and then separate tasks, journal, and knowledge base for personal and work items.
```
(setq org-agenda-files (list "~/org/inbox.org"
"~/org/email.org"
"~/org/tasks.org"
"~/org/wtasks.org"
"~/org/journal.org"
"~/org/wjournal.org"
"~/org/kb.org"
"~/org/wkb.org"
))
(setq org-agenda-text-search-extra-files
(list "~/org/someday.org"
"~/org/config.org"
))
(setq org-refile-targets '((nil :maxlevel . 2)
(org-agenda-files :maxlevel . 2)
("~/org/someday.org" :maxlevel . 2)
("~/org/templates.org" :maxlevel . 2)
)
)
(setq org-outline-path-complete-in-steps nil) ; Refile in a single go
(setq org-refile-use-outline-path 'file)
```
**Configuration: Appearance**
I like a pretty screen. After youve gotten used to org a bit, you might try this.
```
(require 'org-bullets)
(add-hook 'org-mode-hook
(lambda ()
(org-bullets-mode t)))
(setq org-ellipsis "⤵")
```
**Coming up next…**
This hopefully showed a few things that org-mode can do. Coming up next, Ill cover how to customize TODO keywords and tags, archiving old tasks, forwarding emails to org-mode, and using git to synchronize between machines.
You can also see a [list of all articles in this series][9].
--------------------------------------------------------------------------------
via: https://changelog.complete.org/archives/9865-emacs-2-introducing-org-mode
作者:[John Goerzen][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: http://changelog.complete.org/archives/author/jgoerzen
[b]: https://github.com/lujun9972
[1]: https://changelog.complete.org/archives/9861-emacs-1-ditching-a-bunch-of-stuff-and-moving-to-emacs-and-org-mode
[2]: http://www.howardism.org/Technical/Emacs/literate-devops.html
[3]: https://orgmode.org/worg/
[4]: https://www.youtube.com/watch?v=oJTwQvgfgMM
[5]: https://orgmode.org/guide/Introduction.html#Introduction
[6]: https://orgmode.org/guide/Activation.html#Activation
[7]: https://orgmode.org/guide/Capture.html#Capture
[8]: https://orgmode.org/guide/Capture-templates.html#Capture-templates
[9]: https://changelog.complete.org/archives/tag/emacs2018

View File

@ -0,0 +1,131 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: subject: (Emacs #3: More on org-mode)
[#]: via: (https://changelog.complete.org/archives/9877-emacs-3-more-on-org-mode)
[#]: author: (John Goerzen http://changelog.complete.org/archives/author/jgoerzen)
[#]: url: ( )
Emacs #3: More on org-mode
======
This is third in [a series on Emacs and org-mode][1].
**Todo tracking and keywords**
When using org-mode to [track your TODOs][2], it can have multiple states. You can press `C-c C-t` for a quick shift between states. I have set this:
```
(setq org-todo-keywords '(
(sequence "TODO(t!)" "NEXT(n!)" "STARTED(a!)" "WAIT(w@/!)" "OTHERS(o!)" "|" "DONE(d)" "CANCELLED(c)")
))
```
Here, I set up 5 states that are for a task that is not yet done: TODO, NEXT, STARTED, WAIT, and OTHERS. Each has a single-character shortcut (t, n, a, etc). The states after the pipe symbol are ones that are considered “done”. I have two: DONE (for things that I have done) and CANCELED (for things that I havent done, but for whatever reason, wont).
The exclamation mark means to log the time when an item was changed to a state. I dont add this to the done states because those are already logged anyhow. The @ sign means to prompt for a reason; so when switching to WAIT, org-mode will ask me why and add this to the note.
Heres an example of an entry that has had some state changes:
```
** DONE This is a test
CLOSED: [2018-03-02 Fri 03:05]
- State "DONE" from "WAIT" [2018-03-02 Fri 03:05]
- State "WAIT" from "TODO" [2018-03-02 Fri 03:05] \\
waiting for pigs to fly
- State "TODO" from "NEXT" [2018-03-02 Fri 03:05]
- State "NEXT" from "TODO" [2018-03-02 Fri 03:05]
```
Here, the most recent items are on top.
**Agenda mode, schedules, and deadlines**
When youre in a todo item, C-c C-s or C-c C-d can set a schedule or a deadline for it, respectively. These show up in agenda mode. The difference is in intent and presentation. A schedule is something that you expect to work on at around a time, while a deadline is something that is due at a specific time. By default, the agenda view will start warning you about deadline items in advance.
And while were at it, the [agenda view][3] will show you the items that you have coming up, offers a nice way to search for items based on plain text or tags, and handles bulk manipulation of items even across multiple files. I covered setting the files for agenda mode in [part 2][4] of this series.
**Tags**
Of course org-mode has [tags][5]. You can quickly set them with C-c C-q.
You can set shortcuts for tags you might like to use often. Perhaps something like this:
```
(setq org-tag-persistent-alist
'(("@phone" . ?p)
("@computer" . ?c)
("@websurfing" . ?w)
("@errands" . ?e)
("@outdoors" . ?o)
("MIT" . ?m)
("BIGROCK" . ?b)
("CONTACTS" . ?C)
("INBOX" . ?i)
))
```
You can also add tags to this list on a per-file basis, and also set tags for something on a per-file basis. I use that for my inbox.org and email.org files to set an INBOX tag. I can then review all items tagged INBOX from the agenda view each day, and the simple act of refiling them into other files will cause them to lost the INBOX tag.
**Refiling**
“Refiling” is moving things around, either within a file or elsewhere. It has completion using your headlines. `C-c C-w` does this. I like these settings:
```
(setq org-outline-path-complete-in-steps nil) ; Refile in a single go
(setq org-refile-use-outline-path 'file)
```
**Archiving**
After awhile, youll get your files all cluttered with things that are done. org-mode has an [archive][6] feature to move things out of your main .org files and into some other files for future reference. If you have your org files in git or something, you may wish to delete these other files since youd have things in history anyhow, but I find them handy for grepping and searching.
I periodically want to go through and archive everything in my files. Based on a [stackoverflow discussion][7], I have this code:
```
(defun org-archive-done-tasks ()
(interactive)
(org-map-entries
(lambda ()
(org-archive-subtree)
(setq org-map-continue-from (outline-previous-heading)))
"/DONE" 'file)
(org-map-entries
(lambda ()
(org-archive-subtree)
(setq org-map-continue-from (outline-previous-heading)))
"/CANCELLED" 'file)
)
```
This is based on [a particular answer][8] — see the comments there for some additional hints. Now you can run `M-x org-archive-done-tasks` and everything in the current file marked DONE or CANCELED will be pulled out into a different file.
**Up next**
Ill wrap up org-mode with a discussion of automatically receiving emails into org, and syncing org between machines.
--------------------------------------------------------------------------------
via: https://changelog.complete.org/archives/9877-emacs-3-more-on-org-mode
作者:[John Goerzen][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: http://changelog.complete.org/archives/author/jgoerzen
[b]: https://github.com/lujun9972
[1]: https://changelog.complete.org/archives/tag/emacs2018
[2]: https://orgmode.org/guide/TODO-Items.html#TODO-Items
[3]: https://orgmode.org/guide/Agenda-Views.html#Agenda-Views
[4]: https://changelog.complete.org/archives/9865-emacs-2-introducing-org-mode
[5]: https://orgmode.org/guide/Tags.html#Tags
[6]: https://orgmode.org/guide/Archiving.html#Archiving
[7]: https://stackoverflow.com/questions/6997387/how-to-archive-all-the-done-tasks-using-a-single-command
[8]: https://stackoverflow.com/a/27043756