Merge pull request #18 from LCTT/master

update
This commit is contained in:
MjSeven
2018-05-30 22:35:30 +08:00
committed by GitHub
13 changed files with 1445 additions and 1482 deletions

View File

@@ -1,13 +1,15 @@
四个Linux网络嗅探工具
四个 Linux 上的网络嗅探工具
======
在计算机网络中,数据是暴露的,因为数据包传输是无法隐藏的,所以让我们来使用 `whois`,`dig``nmcli``nmap` 这四个工具来嗅探网络吧。
![](https://www.linux.com/sites/lcom/files/styles/rendered_file/public/1280px-eudyptula_minor_family_exiting_burrow.jpg?itok=kGZ53AzN)
请注意,不要运行 `nmap` 在不属于自己的网络上,因为这有可能会被其他人解读成为恶意攻击。
在计算机网络中,数据是暴露的,因为数据包传输是无法隐藏的,所以让我们来使用 `whois``dig``nmcli``nmap` 这四个工具来嗅探网络吧。
请注意,不要在不属于自己的网络上运行 `nmap` ,因为这有可能会被其他人认为恶意攻击。
### 精简和详细域名信息查询
您可能已经注意到,之前我们用心爱的 `whois` 命令查询域名信息,但现如今似乎没有提供同过去一样的详细程度。我们使用该命令查询 Linux.com 域名描述信息:
您可能已经注意到,之前我们用常用的老式 `whois` 命令查询域名信息,但现如今似乎没有提供同过去一样的详细程度。我们使用该命令查询 linux.com 域名描述信息:
```
$ whois linux.com
@@ -30,19 +32,19 @@ DNSSEC: unsigned
[...]
```
有很多令人讨厌的法律声明。但在哪有联系信息呢?该网站位于 whois.namecheap.com 站点上(见上面输出的第三行):
有很多令人讨厌的法律声明。但在哪有联系信息呢?该网站位于 `whois.namecheap.com` 站点上(见上面输出的第三行):
```
$ whois -h whois.namecheap.com linux.com
```
我就不复制出来因为这实在太长了包含了注册人管理员和技术人员的联系信息。怎么回事啊露西尔LCTT 译注:《行尸走肉》中尼根的棒子)有一些注册表,比如.com和.net是精简注册表保存了一部分有限的域名信息。为了获取完整信息请使用 `-h``--host` 参数,该参数便会从域名的 `注册服务机构` 中获取。
大部分顶级域名是需要详细的注册信息,如.info。试着使用`whois blockchain.info`命令来查看
我就不复制出来了因为这实在太长了包含了注册人管理员和技术人员的联系信息。怎么回事啊露西尔LCTT 译注:《行尸走肉》中尼根的棒子)有一些注册库,比如 .com 和 .net 是精简注册库,保存了一部分有限的域名信息。为了获取完整信息请使用 `-h``--host` 参数,该参数便会从域名的 `注册服务机构` 中获取
大部分顶级域名是有详细的注册信息,如 .info。试着使用 `whois blockchain.info` 命令来查看。
想要摆脱这些烦人的法律声明?使用 `-H` 参数。
### DNS解析
### DNS 解析
使用 `dig` 命令比较从不同的域名服务器返回的查询结果,去除陈旧的信息。域名服务器记录缓存各地的解析信息,并且不同的域名服务器有不同的刷新间隔。以下是一个简单的用法:
@@ -69,19 +71,18 @@ linux.com. 10800 IN A 151.101.193.5
;; SERVER: 127.0.1.1#53(127.0.1.1)
;; WHEN: Tue Jan 16 15:17:04 PST 2018
;; MSG SIZE rcvd: 102
```
注意下靠近末尾的这行信息SERVER: 127.0.1.1#53(127.0.1.1)这是您默认的缓存解析器。当地址是本地时就相当于在您的电脑上安装DNS服务。在我看来这就是一个Dnsmasq工具LCTT 译注是一个小巧且方便地用于配置DNS和DHCP的工具该工具被用作网络管理
注意下靠近末尾的这行信息:`SERVER: 127.0.1.1#53(127.0.1.1)`,这是您默认的缓存解析器。当地址是本地时,就表明您的电脑上安装了 DNS 服务。在我看来这就是一个 Dnsmasq 工具LCTT 译注:是一个小巧且方便地用于配置 DNS 和 DHCP 的工具),该工具被用作网络管理:
```
$ ps ax|grep dnsmasq
2842 ? S 0:00 /usr/sbin/dnsmasq --no-resolv --keep-in-foreground
--no-hosts --bind-interfaces --pid-file=/var/run/NetworkManager/dnsmasq.pid
--listen-address=127.0.1.1
```
`dig` 命令默认是返回A记录也就是域名。IPv6则有AAAA记录
`dig` 命令默认是返回 A 记录也就是域名。IPv6 则有 AAAA 记录:
```
$ $ dig linux.com AAAA
@@ -92,48 +93,44 @@ linux.com. 60 IN AAAA 64:ff9b::9765:4105
linux.com. 60 IN AAAA 64:ff9b::9765:8105
linux.com. 60 IN AAAA 64:ff9b::9765:c105
[...]
```
仔细检查下,发现Linux.comIPv6地址。很好如果您的网络服务支持IPv6那么您就可以用IPv6连接。令人难过的是我的移动宽带则没提供IPv6
仔细检查下,发现 linux.comIPv6 地址。很好!如果您的网络服务支持 IPv6 那么您就可以用 IPv6 连接。(令人难过的是,我的移动宽带则没提供 IPv6
假设您能使DNS改变您的域名又或是您使用 `dig` 查询的结果有误。试着用一个公共DNS如OpenNIC:
假设您能对您的域名做一些 DNS 改变,又或是您使用 `dig` 查询的结果有误。试着用一个公共 DNS如 OpenNIC
```
$ dig @69.195.152.204 linux.com
[...]
;; Query time: 231 msec
;; SERVER: 69.195.152.204#53(69.195.152.204)
```
`dig` 回应您正在的查询是来自 69.195.152.204。您可以查询各种服务并且比较结果。
### 上游域名服务器
我想知道我的上游域名服务器是谁。为了查询,我首先看下`/etc/resolv/conf` 的配置信息:
我想知道我的上游域名服务器LCTT 译注:此处指解析器)是谁。为了查询,我首先看下 `/etc/resolv/conf` 的配置信息:
```
$ cat /etc/resolv.conf
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
# DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 127.0.1.1
```
很幸运,不过我已经知道。您的Linux发行版可能配置不同您会看到您的上游服务器。接下来我们来试试网络管理器命令行工具 `nmcli`
好吧,不过我已经知道。您的 Linux 发行版可能配置不同,您会看到您的上游服务器。接下来我们来试试网络管理器命令行工具 `nmcli`
```
$ nmcli dev show | grep DNS
IP4.DNS[1]: 192.168.1.1
```
很好,现在我们已经知道了,其实那是我的移动热点,并且我已经确认那是我的热点。我能够登录到简易管理面板,来查询上游服务器。然而许多消费者互联网网关不会让您看到或改变这些设置,因此只能尝试其他的方法,如 [我的域名服务器是什么?][1]
很好,现在我们已经知道了,其实那是我的移动热点,我能确认。我能够登录到简易管理面板,来查询上游服务器。然而许多用户级互联网网关不会让您看到或改变这些设置,因此只能尝试其他的方法,如 [我的域名服务器是什么?][1]
### 查找在您的网络中IPv4地址
### 查找在您的网络中 IPv4 地址
您的网络上有哪些IPv4地址已启用并正在使用中
您的网络上有哪些 IPv4 地址已启用并正在使用中?
```
$ nmap -sn 192.168.1.0/24
@@ -145,8 +142,8 @@ Host is up (0.000071s latency).
Nmap scan report for nellybly (192.168.1.3)
Host is up (0.015s latency)
Nmap done: 256 IP addresses (2 hosts up) scanned in 2.23 seconds
```
每个人都想去扫描自己的局域网中开放的端口。下面的例子是寻找服务和他们的版本号:
```
@@ -171,10 +168,9 @@ Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 256 IP addresses (2 hosts up) scanned in 11.65 seconds
```
这些是有趣的结果。让我们尝试从不同的网络帐户进行相同的操作以查看这些服务是否暴露于互联网中。如果您有智能手机相当于您有第二个网络。您可以下载应用程序还可以为您的Linux电脑提供热点。从热点控制面板获取广域网IP地址然后重试
这些是有趣的结果。让我们尝试从不同的互联网连接进行相同的操作,以查看这些服务是否暴露于互联网中。如果您有智能手机,相当于您有第二个网络。您可以下载应用程序,还可以为您的 Linux 电脑提供热点。从热点控制面板获取广域网IP地址然后重试
```
$ nmap -sV 12.34.56.78
@@ -183,13 +179,11 @@ Starting Nmap 7.01 ( https://nmap.org ) at 2018-01-14 17:05 PST
Nmap scan report for 12.34.56.78
Host is up (0.0061s latency).
All 1000 scanned ports on 12.34.56.78 are closed
```
果然不出所料,结果和我想象的一样。可以用手册来查询这些命令,以便了解更多有趣的嗅探技术。
果然不出所料结果和我想象的一样LCTT 译注:这些服务和信息没有被暴露在公网上)。可以用手册来查询这些命令,以便了解更多有趣的嗅探技术。
了解更多Linux的相关知识可以从Linux基金会和edXLCTT译edX是麻省理工和哈佛大学于2012年4月联手创建的大规模开放在线课堂平台)中获取免费的 ["介绍Linux" ][2]课程。
了解更多 Linux 的相关知识可以从 Linux 基金会和 edXLCTT译注edX 是麻省理工和哈佛大学于 2012 年 4 月联手创建的大规模开放在线课堂平台)中获取免费的 [介绍 Linux][2]课程。
--------------------------------------------------------------------------------
@@ -197,7 +191,7 @@ via: https://www.linux.com/learn/intro-to-linux/2018/1/4-tools-network-snooping-
作者:[Carla Schroder][a]
译者:[wyxplus](https://github.com/wyxplus)
校对:[校对者ID](https://github.com/校对者ID)
校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出

View File

@@ -1,13 +1,11 @@
微服务 vs. 整体服务:如何选择
============================================================
### 任何一种架构都是有利有弊的,而能满足你组织的独特需要的决策才是正确的选择。
> 任何一种架构都是有利有弊的,而能满足你组织的独特需要的决策才是正确的选择。
![Microservices vs. monolith: How to choose](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/building_architecture_design.jpg?itok=lB_qYv-I "Microservices vs. monolith: How to choose")
Image by : 
Onasill ~ Bill Badzo on [Flickr][11]. [CC BY-NC-SA 2.0][12]. Modified by Opensource.com.
Image by : Onasill ~ Bill Badzo on [Flickr][11]. [CC BY-NC-SA 2.0][12]. Modified by Opensource.com.
对于许多初创公司来说,传统的知识认为,从单一整体架构开始,而不是使用微服务。但是,我们还有别的选择吗?
@@ -17,37 +15,30 @@ Onasill ~ Bill Badzo on [Flickr][11]. [CC BY-NC-SA 2.0][12]. Modified by Open
### 理解范围
更多有关微服务的内容
* [如何向你的 CEO 解释微服务][1]
* [免费电子书:微服务 vs. 面向服务的架构][2]
* [DevOps 确保微服务安全][3]
首先,我们先来准确定义我们所谓的 “整体服务” 和 “微服务” 是什么。
微服务是一种方法,它开发一个单一的应用程序来作为构成整体服务的小服务,每个小服务都运行在它自己的进程中,并且使用一个轻量级的机制进行通讯,通常是一个 HTTP 资源 API。这些服务都围绕业务能力来构建并且可依赖全自动部署机制来独立部署。
微服务是一种方法,它开发一个单一的应用程序来作为构成整体服务的小服务,每个小服务都运行在它自己的进程中,并且使用一个轻量级的机制进行通讯,通常是一个 HTTP 资源 API。这些服务都围绕业务能力来构建并且可依赖全自动部署机制来独立部署。
一个整体应用程序是按单个的、统一的单元来构建,并且,通常情况下它是基于一个大量的代码来实现的。一般来说,一个整体服务是由三部分组成的:一个数据库、一个客户端用户界面(由 HTML 页面和/或运行在浏览器中的 JavaScript 组成)、以及一个服务器端应用程序。
一个整体应用程序是按单个的、统一的单元来构建,并且,通常情况下它是基于一个大量的代码来实现的。一般来说,一个整体服务是由三部分组成的:数据库、客户端用户界面(由 HTML 页面和/或运行在浏览器中的 JavaScript 组成)、以及服务器端应用程序。
“系统架构处于一个范围之中”Zachary Crockett[Particle][14] 的 CTO在一次访谈中他说在讨论微服务时,人们倾向于关注这个范围的一端:许多极小的应用程序给其它应用程序传递了过多的信息。在另一端,有一个巨大的整体服务做了太多的事情。在任何现实中的系统上,在这两个极端之间有很多合适的面向服务的架构
“系统架构处于一个范围之中”Zachary Crockett[Particle][14] 的 CTO在一次访谈中他说在讨论微服务时,人们倾向于关注这个范围的一端:许多极小的应用程序给其它应用程序传递了过多的信息。在另一端,有一个巨大的整体服务做了太多的事情。在任何现实中的系统上,在这两个极端之间有很多合适的面向服务的架构
根据你的情况不同,不论是使用整体服务还是微服务都有很多很好的理由。
"我们希望为每个服务使用最好的工具”Julien Lemoine 说,他是 Algolia 的 CTO。
我们希望为每个服务使用最好的工具”Julien Lemoine 说,他是 Algolia 的 CTO。
与很多人的想法正好相反,整体服务并不是过去遗留下来的过时的架构。在某些情况下,整体服务是非常理想的。我采访了 Steven Czerwinski 之后,更好地理解了这一点,他是 [Scaylr][15] 的工程主管,前谷歌员工。
“尽管我们在谷歌时有使用微服务的一些好的经验,我们现在 [在 Scalyr] 却使用的是整体服务的架构,因为一个整体服务架构意味着我们的工作量更少,我们只有两位工程师。“ 他解释说。采访他时Scaylr 正处于早期阶段)
但是,如果你的团队使用微服务的经验很丰富,并且你对你们的发展方向有明确的想法,微服务可能是一个很好的 替代者。
但是,如果你的团队使用微服务的经验很丰富,并且你对你们的发展方向有明确的想法,微服务可能是一个很好的替代者。
Julien Lemoine[Algolia][16] 的 CTO在这个问题上他认为我们通常从使用微服务开始,主要目的是我们可以使用不同的技术来构建我们的服务,因为如下的两个主要原因:
Julien Lemoine[Algolia][16] 的 CTO在这个问题上他认为我们通常从使用微服务开始,主要目的是我们可以使用不同的技术来构建我们的服务,因为如下的两个主要原因:
* 我们想为每个服务使用最好的工具。我们的搜索 API 是在底层做过高度优化的,而 C++ 是非常适合这项工作的。他说,在任何地方都使用 C++ 是一种生产力的浪费,尤其是在构建仪表板方面。
* 我们想为每个服务使用最好的工具。我们的搜索 API 是在底层做过高度优化的,而 C++ 是非常适合这项工作的。他说,在任何其它地方都使用 C++ 是一种生产力的浪费,尤其是在构建仪表板方面。
* 我们希望使用最好的人才,而只使用一种技术将极大地限制我们的选择。这就是为什么在公司中有不同语言的原因。
* 我们希望使用最好的人才,而只使用一种技术将极大地限制我们的选择。这就是为什么在公司中有不同语言的原因。“
如果你的团队已经准备好从一开始就使用微服务,这样你的组织从一开始就可以适应微服务环境的开发节奏。
@@ -57,36 +48,29 @@ Julien Lemoine[Algolia][16] 的 CTO在这个问题上他认为”我
### 整体服务
### 优点:
#### 优点:
* **很少担心横向联系:** 大多数应用程序开发者都担心横向联系,比如,日志、速度限制、以及像审计跟踪和 DoS 防护这样的安全特性。当所有的东西都运行在同一个应用程序中时,通过组件钩子来处理这些关注点就非常容易了。
* **运营开销很少:** 只需要为一个应用程序设置日志、监视、以及测试。一般情况下,部署也相对要简单。
* **性能:** 一个整体的架构可能会有更好的性能因为共享内存的访问速度要比进程间通讯IPC更快。
### 缺点:
* **紧耦合:** 整体服务的应用程序倾向于紧耦合,并且应用程序是整体进化,分离特定用途的服务是非常困难的,比如,独立扩展或者代码维护。
#### 缺点:
* **紧耦合:** 整体服务的应用程序倾向于紧耦合,并且应用程序是整体进化的,分离特定用途的服务是非常困难的,比如,独立扩展或者代码维护。
* **理解起来很困难:** 当你想查看一个特定的服务或者控制器时,因为依赖、副作用、和其它的不可预见因素,整体架构理解起来更困难。
### 微服务
### 优点:
#### 优点:
* **非常好组织:** 微服务架构一般很好组织它们,因为每个微服务都有一个特定的工作,并且还不用考虑其它组件的工作。
* **解耦合:** 解耦合的服务是能够非常容易地进行重组织和重配置,以服务于不同的应用程序(比如,同时向 Web 客户端和公共 API 提供服务)。它们在一个大的集成系统中,也允许快速、独立分发单个部分。
* **性能:** 根据组织的情况,微服务可以提供更好的性能,因为你可以分离热点服务,并根据其余应用程序的情况来扩展它们。
* **更少的错误:** 微服务允许系统中的不同部分,在维护良好边界的前提下进行并行开发。这样将使连接不该被连接的部分变得更困难,比如,需要连接的那些紧耦合部分。
### 缺点:
#### 缺点:
* **跨每个服务的横向联系点:** 由于你构建了一个新的微服务架构,你可能会发现在设计时没有预料到的很多横向联系的问题。这也将导致需要每个横向联系点的独立模块(比如,测试)的开销增加,或者在其它服务层面因封装横向联系点,所导致的所有流量都需要路由。最终,即便是整体服务架构也倾向于通过横向联系点的外部服务层来路由流量,但是,如果使用整体架构,在项目更加成熟之前,也不过只是推迟了工作成本。
* **更高的运营开销:** 微服务在它所属的虚拟机或容器上部署非常频繁,导致虚拟机争用激增。这些任务都是使用容器管理工具进行频繁的自动化部署的。
### 决策时刻
@@ -109,7 +93,7 @@ David Strauss[Pantheon][17] 的 CTO他解释说"[以前],你使用整
### 评估业务风险
技术力量雄厚的初创公司为追求较高的目标可以考虑使用微服务。但是微服务可能会带来业务风险。Strauss 解释说,许多团队一开始就过度构建他们的项目。每个人都认为,他们的公司会成为下一个 独角兽,因此,他们使用微服务构建任何一个东西,或者一些其它的高扩展性的基础设施。但是这通常是一种错误的做法。Strauss 说,在那种情况下,他们认为需要扩大规模的领域往往并不是一开始真正需要扩展的领域,最后的结果是浪费了时间和努力。
技术力量雄厚的初创公司为追求较高的目标可以考虑使用微服务。但是微服务可能会带来业务风险。Strauss 解释说,许多团队一开始就过度构建他们的项目。每个人都认为,他们的公司会成为下一个 独角兽,因此,他们使用微服务构建任何一个东西,或者一些其它的高扩展性的基础设施。但是这通常是一种错误的做法。Strauss 说,在那种情况下,他们认为需要扩大规模的领域往往并不是一开始真正需要扩展的领域,最后的结果是浪费了时间和努力。
### 态势感知
@@ -118,36 +102,30 @@ David Strauss[Pantheon][17] 的 CTO他解释说"[以前],你使用整
#### 什么时候使用整体服务
* **你的团队还在创建阶段:** 你的团队很小 —— 也就是说,有 2 到 5 位成员 —— 还无法应对大范围、高成本的微服务架构。
* **你正在构建的是一个未经证实的产品或者概念验证:** 如果你将一个全新的产品推向市场,随着时间的推移,它有可能会成功,而对于一个快速迭代的产品,整体架构是最合适的。这个提示也同样适用于概念验证,你的目标是尽可能快地学习,即便最终你可能会放弃它。
* **你没有使用微服务的经验:** 除非你有合理的理由证明早期学习阶段的风险可控,否则,一个整体的架构更适用于一个没有经验的团队。
#### 什么时候开始使用微服务
* **你需要快速、独立的分发服务:** 微服务允许在一个大的集成系统中快速、独立分发单个部分。请注意,根据你的团队规模,获取与整体服务的比较优势,可能需要一些时间。
* **你的平台中的某些部分需要更高效:** 如果你的业务要求集中处理 PB 级别的日志卷,你可能需要使用一个像 C++ 这样的更高效的语言来构建这个服务,尽管你的用户仪表板或许还是用 [Ruby on Rails][5] 构建的。
* **计划扩展你的团队:** 使用微服务,将让你的团队从一开始就开发独立的小服务,而服务边界独立的团队更易于按需扩展。
要决定整体服务还是微服务更适合你的组织,要坦诚并正确认识自己的环境和能力。这将有助于你找到业务成长的最佳路径。
### 主题
 [微服务][21]、 [DevOps][22]
### 关于作者
[![](https://opensource.com/sites/default/files/styles/profile_pictures/public/pictures/profile_15.jpg?itok=EaSRMCN-)][18] jakelumetta - Jake 是 ButterCMS 的 CEO它是一个 [API-first CMS][6]。他喜欢搅动出黄油双峰,以及构建让开发者工作更舒适的工具,喜欢他的更多内容,请在 Twitter 上关注 [@ButterCMS][7],订阅 [他的博客][8]。[关于他的更多信息][9]
[![](https://opensource.com/sites/default/files/styles/profile_pictures/public/pictures/profile_15.jpg?itok=EaSRMCN-)][18]
jakelumetta - Jake 是 ButterCMS 的 CEO它是一个 [API-first CMS][6]。他喜欢搅动出黄油双峰,以及构建让开发者工作更舒适的工具,喜欢他的更多内容,请在 Twitter 上关注 [@ButterCMS][7],订阅 [他的博客][8]。[关于他的更多信息][9]……
--------------------------------------------------------------------------------
via: https://opensource.com/article/18/1/how-choose-between-monolith-microservices
作者:[jakelumetta ][a]
作者:[jakelumetta][a]
译者:[qhwdw](https://github.com/qhwdw)
校对:[校对者ID](https://github.com/校对者ID)
校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出

View File

@@ -1,7 +1,7 @@
你应该知道关于 Ubuntu 18.04 的一些事
======
[Ubuntu 18.04 版本][1] 即将到来。我可以在各种 Facebook 群组和论坛中看到许多来自 Ubuntu 用户的提问。我还在 Facebook 和 Instagram 上组织了 Q&A 会议,以了解 Ubuntu 用户对 Ubuntu 18.04 的想法。
[Ubuntu 18.04 版本][1] 已经到来。我可以在各种 Facebook 群组和论坛中看到许多来自 Ubuntu 用户的提问。我还在 Facebook 和 Instagram 上组织了 Q&A 会议,以了解 Ubuntu 用户对 Ubuntu 18.04 的想法。
我试图在这里回答关于 Ubuntu 18.04 的常见问题。如果您有任何疑问,我希望这能帮助您解决疑问。如果您仍有问题,请随时在下面的评论区提问。
@@ -17,19 +17,19 @@
Canonical 公司知道有些人喜欢 Unity。这就是为什么它已经在 Universe 软件库LCTT译者注社区维护的软件库中提供了 Unity 7。但这是一个社区维护版官方并不直接参与开发。
我建议是使用默认的 GNOME除非您真的无法容忍它再在 [Ubuntu 18.04 上安装 Unity][3]。
不过我建议是使用默认的 GNOME除非您真的无法容忍它再在 [Ubuntu 18.04 上安装 Unity][3]。
#### GNOME 是什么版本?
在这次发行的 Ubuntu 18.04 版本中GNOME 版本号是 3.28。
#### 我能够安装 vanilla GNOME
#### 我能够安装原装的 GNOME
当然没问题!
因为存在一些 GNOME 用户可能不喜欢 Ubuntu 18.04 中的 Unity 风格。在 Ubuntu 中的 mainLCTT译者注官方支持的软件库和 universe 软件库有安装包可安装,能使您在 [Ubuntu 18.04 中安装 vanilla GNOME][4]。
因为存在一些 GNOME 用户可能不喜欢 Ubuntu 18.04 中的 Unity 风格。在 Ubuntu 中的 mainLCTT译者注官方支持的软件库和 universe 软件库有安装包可安装,能使您在 [Ubuntu 18.04 中安装原装的 GNOME][4]。
#### GNOME中的内存泄漏已修复了吗
#### GNOME 中的内存泄漏已修复了吗?
已经修复了。[GNOME 3.28 中臭名昭着的内存泄漏][5] 已经被修复了,并且 [Ubuntu 官方已经在测试这个修复程序][6]。
@@ -39,23 +39,21 @@ Canonical 公司知道有些人喜欢 Unity。这就是为什么它已经在 Uni
这是一个长期支持LTS版本与任何 LTS 版本一样,官方会支持五年。这意味着 Ubuntu 18.04 将在 2023 年 4 月之前能获得安全和维护更新。这对于除 Ubuntu Studio 之外的所有基于 Ubuntu 的 Linux 发行版也一样。
#### Ubuntu 18.04 什么时候发布?
#### Ubuntu 18.04 什么时候发布
Ubuntu 18.04 LTS 在 4 月 26 日发布。 所有基于 Ubuntu 的 Linux 发行版,如 KubuntuLubuntuXubuntuBudgieMATE 等都会在同一天发布其 18.04 版本。
Ubuntu 18.04 LTS 在 4 月 26 日发布。 所有基于 Ubuntu 的 Linux 发行版,如 KubuntuLubuntuXubuntuBudgieMATE 等都会在同一天发布其 18.04 版本。
不过 [Ubuntu Studio 不会有 18.04 的 LTS 版本][7]。
#### 是否能从16.04/17.10升级到 Ubuntu 18.04?我可以从使用 Unity 的 Ubuntu 16.04 升级到使用 GNOME 的 Ubuntu 18.04 吗?
#### 是否能从 16.04/17.10 升级到 Ubuntu 18.04?我可以从使用 Unity 的 Ubuntu 16.04 升级到使用 GNOME 的 Ubuntu 18.04 吗?
绝对没问题。当 Ubuntu 18.04 LTS 发布后,您可以很容易的升级到最新版。
如果您使用的是 Ubuntu 17.10,请确保在软件和更新->更新中,将“有新版本时通知我”设置为“适用任何新版本”。
如果您使用的是 Ubuntu 17.10,请确保在软件和更新->更新中,将“有新版本时通知我”设置为“适用任何新版本”。
![Get notified for a new version in Ubuntu][8]
如果您使用的是 Ubuntu 16.04,请确保在软件和更新->更新中,将“有新版本时通知我”设置为“适用长期支持版本”。
如果您使用的是 Ubuntu 16.04,请确保在软件和更新->更新中,将“有新版本时通知我”设置为“适用长期支持版本”。
![Ubuntu 18.04 upgrade from Ubuntu 16.04][9]
@@ -63,10 +61,8 @@ Ubuntu 18.04 LTS 在 4 月 26 日发布。 所有基于 Ubuntu 的 Linux 发行
即使 Ubuntu 16.04 使用的是 Unity但您仍然可以 [升级到使用 GNOME 的 Ubuntu 18.04][10]。
#### 升级到 Ubuntu 18.04 意味着什么?我会丢失数据吗?
如果您使用的是 Ubuntu 17.10 或 Ubuntu 16.04,系统会提示您可升级到 Ubuntu 18.04。如果您从互联网上下载 1.5 Gb 的数据不成问题,则只需点击几下鼠标,即可在 30 分钟内升级到 Ubuntu 18.04。
您不需要通过 U 盘来重装系统。升级过程完成后,您将可以使用新的 Ubuntu 版本。
@@ -75,7 +71,7 @@ Ubuntu 18.04 LTS 在 4 月 26 日发布。 所有基于 Ubuntu 的 Linux 发行
#### 我什么时候能升级到 Ubuntu 18.04
如果您使用的是 Ubuntu 17.10 并且正确设置(设置方法在之前提到的问题中),那么在 Ubuntu 18.04 发布的几天内应该会通知您升级到 Ubuntu 18.04。为避免 Ubuntu 服务器在发布日期负载量过大,因此不是每个人都会在同一天收到升级提示。
如果您使用的是 Ubuntu 17.10 并且正确设置(设置方法在之前提到的问题中),那么在 Ubuntu 18.04 发布的几天内应该会通知您升级到 Ubuntu 18.04。为避免 Ubuntu 服务器在发布时的负载量过大,因此不是每个人都会在同一天收到升级提示。
对于 Ubuntu 16.04 用户,可能需要几周时间才能正式收到 Ubuntu 18.04 升级提示。通常,这将在第一次发布 Ubuntu 18.04.1 之后提示。该版本修复了 18.04 中发现的新 bug。
@@ -89,16 +85,13 @@ Ubuntu 18.04 LTS 在 4 月 26 日发布。 所有基于 Ubuntu 的 Linux 发行
如果您已经在使用 32 位版本的 Ubuntu 16.04 或 17.10,您依旧可以升级到 Ubuntu 18.04。 但是,您找到不到 32 位的 Ubuntu 18.04 ISO 镜像。换句话说,您无法安装 32 位版本的 Ubuntu 18.04。
有一个好消息是Ubuntu MATELubuntu 等其他官方版本仍然具有其新版本的 32 位 ISO 镜像。
有一个好消息是Ubuntu MATE、Lubuntu 等其他官方版本仍然具有其新版本的 32 位 ISO 镜像。
无论如何,如果您使用一个 32 位系统,那么很可能您的计算机硬件性能过低。在这样的电脑上使用轻量级 [Ubuntu MATE][11] 或 [Lubuntu][12] 系统会更好。
#### 我可以在哪下载 Ubuntu 18.04
一旦发布了 18.04,您可以从其网站获得 Ubuntu 18.04 的 ISO 镜像。您既可以直接官网下载,也能用种子下载。其他官方版本将在其官方网站上提供下载。
18.04 已经发布了,您可以从其网站获得 Ubuntu 18.04 的 ISO 镜像。您既可以直接官网下载,也能用种子下载。其他官方版本将在其官方网站上提供下载。
#### 我应该重新安装 Ubuntu 18.04 还是从 16.04/17.10 升级上来?
@@ -106,7 +99,7 @@ Ubuntu 18.04 LTS 在 4 月 26 日发布。 所有基于 Ubuntu 的 Linux 发行
从现有版本升级到 18.04 是一个方便的选择。不过,就我个人而言,它仍然保留了旧版本的依赖包。重新安装还是比较干净。
对于重新安装来说,我应该安装 Ubuntu 16.04 还是 Ubuntu 18.04
#### 对于重新安装来说,我应该安装 Ubuntu 16.04 还是 Ubuntu 18.04
如果您要在计算机上安装 Ubuntu请尽量使用 Ubuntu 18.04 而不是 16.04。
@@ -116,7 +109,6 @@ Ubuntu 18.04 LTS 在 4 月 26 日发布。 所有基于 Ubuntu 的 Linux 发行
此外,许多应用程序开发人员将很快开始关注 Ubuntu 18.04。新创建的 PPA 可能仅在几个月内支持 18.04。所以使用 18.04 比 16.04 更好。
#### 安装打印机-扫描仪驱动程序比使用 CLI 安装会更容易吗?
在打印机方面,我不是专家,所以我的观点是基于我在这方面有限的知识。大多数新打印机都支持 [IPP协议][14],因此它们应该在 Ubuntu 18.04 中能够获到很好的支持。 然而对较旧的打印机我则无法保证。
@@ -127,15 +119,14 @@ Ubuntu 18.04 LTS 在 4 月 26 日发布。 所有基于 Ubuntu 的 Linux 发行
#### Ubuntu 18.04 的系统要求?
对于默认的 GNOME 版本,最好您应该有 [4 GB 的内存以便正常使用][15]。使用过去 8 年中发布的处理器也可以运行。但任何比这性能更差的硬件建议使用 [轻量级 Linux 发行版][16],例如 [Lubuntu][12]。
#### 有关 Ubuntu 18.04 的其问题?
如果还有其他疑问,请随时在下方评论区留言。如果您认为应将其他信息添加到列表中,请告诉我。
LCTT 译注:本文原文写于 Ubuntu 18.04 LTS 发布之前,译文翻译于发布之后,因此对部分内容做了修改。)
--------------------------------------------------------------------------------
via: https://itsfoss.com/ubuntu-18-04-faq/
@@ -143,12 +134,12 @@ via: https://itsfoss.com/ubuntu-18-04-faq/
作者:[Abhishek Prakash][a]
选题:[lujun9972](https://github.com/lujun9972)
译者:[wyxplus](https://github.com/wyxplus)
校对:[校对者ID](https://github.com/校对者ID)
校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]:http://itsfoss.com/author/abhishek/
[1]:https://itsfoss.com/ubuntu-18-04-release-features/
[1]:https://linux.cn/article-9583-1.html
[2]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/04/ubuntu-18-04-faq-800x450.png
[3]:https://itsfoss.com/use-unity-ubuntu-17-10/
[4]:https://itsfoss.com/vanilla-gnome-ubuntu/

View File

@@ -1,69 +1,68 @@
如何在 Linux 中安装 Ncurses 库
======
![](https://www.ostechnix.com/wp-content/uploads/2018/05/install-ncurses-720x340.png)
**GNU Ncurses** 是一个允许用户编写基于文本的用户界面TUI的编程库。许多基于文本的游戏都是使用这个库创建的。一个受欢迎的例子是 [**PacVim**][1],这是一款学习 VIM 命令的 CLI 游戏。在这篇简要的指南中,我将解释如何在类 Unix 操作系统中安装 Ncurses 库。
**GNU Ncurses** 是一个允许用户编写基于文本的用户界面TUI的编程库。许多基于文本的游戏都是使用这个库创建的。一个受欢迎的例子是 [PacVim][1],这是一款学习 VIM 命令的 CLI 游戏。在这篇简要的指南中,我将解释如何在类 Unix 操作系统中安装 Ncurses 库。
### 在 Linux 中安装 Ncurses 库
Ncurses 在大多数 Linux 发行版的默认仓库中都有。例如,你可以使用以下命令将其安装在基于 Arch 的系统上:
```
$ sudo pacman -S ncurses
```
在RHEL、CentOS 上:
```
$ sudo yum install ncurses-devel
```
在 Fedora 22 和更新版本上:
```
$ sudo dnf install ncurses-devel
```
在 Debian、Ubuntu、Linux Mint 上:
```
$ sudo apt-get install libncurses5-dev libncursesw5-dev
```
默认仓库中的 GNU ncureses 可能有点老了。如果你想要最新的稳定版本,可以从源代码进行编译和安装,如下所示。
从[**这里**][2]下载最新的 ncurses 版本。在写这篇文章时,最新版本是 6.1。
从[这里][2]下载最新的 ncurses 版本。在写这篇文章时,最新版本是 6.1。
```
$ wget https://ftp.gnu.org/pub/gnu/ncurses/ncurses-6.1.tar.gz
```
解压 tar 文件:
```
$ tar xzf ncurses-6.1.tar.gz
```
这将在当前目录中创建一个名为 ncurses-6.1 的文件夹。cd 到该目录:
```
$ cd ncurses-6.1
$ ./configure --prefix=/opt/ncurses
```
最后,使用以下命令进行编译和安装:
```
$ make
$ sudo make install
```
使用命令验证安装:
```
$ ls -la /opt/ncurses
```
就是这样。Ncurses 已经安装在 Linux 发行版上。继续使用 Ncurses 创建漂亮的 TUI。
@@ -73,7 +72,6 @@ $ ls -la /opt/ncurses
干杯!
--------------------------------------------------------------------------------
via: https://www.ostechnix.com/how-to-install-ncurses-library-in-linux/
@@ -81,7 +79,7 @@ via: https://www.ostechnix.com/how-to-install-ncurses-library-in-linux/
作者:[SK][a]
选题:[lujun9972](https://github.com/lujun9972)
译者:[geekpi](https://github.com/geekpi)
校对:[校对者ID](https://github.com/校对者ID)
校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出

View File

@@ -1,90 +0,0 @@
pinewall translating
Containerization, Atomic Distributions, and the Future of Linux
======
![](https://www.linux.com/sites/lcom/files/styles/rendered_file/public/atomic-distro.jpg?itok=SjBeCDtq)
Linux has come a long way since Linus Torvalds announced it in 1991. It has become the dominant operating system in the enterprise space. And, although weve seen improvements and tweaks in the desktop environment space, the model of a typical Linux distribution has largely remained the same over the past 25+ years. The traditional package management based model has dominated both the desktop and server space.
However, things took an interesting turn when Google launched Linux-based Chrome OS, which deployed an image-based model. Core OS (now owned by Red Hat) came out with an operating system (Container Linux) that was inspired by Google but targeted at enterprise customers.
Container Linux changed the way operating systems update. It changed the way applications were delivered and updated. Is this the future of Linux distributions? Will it replace the traditional package-based distribution model?
### Three models
Matthias Eckermann, Director of Product Management for SUSE Linux Enterprise, thinks there are not two but three models. “Outside of the traditional (RHEL/SLE) and the image-based model (RH Atomic Host), there is a third model: transactional. This is where [SUSE CaaS Platform][1] and its SUSE MicroOS lives,” said Eckermann.
### Whats the difference?
Those who live in Linux land are very well aware of the traditional model. Its made up of single packages and shared libraries. This model has its own benefit as application developers dont have to worry about bundling libraries with their apps. There is no duplication, which keeps the system lean and thin. It also saves bandwidth as users dont have to download a lot of packages. Distributions have total control over packages so security issues can be fixed easily by pushing updates at the system level.
“Traditional packaging continues to provide the opportunity to carefully craft and tune an operating system to support mission-critical workloads that need to stand the test of time,” said Ron Pacheco, Director of Product Management at Red Hat Enterprise Linux.
But the traditional model has some disadvantages, too. App developers must restrict themselves to the libraries shipped with the distro, which means they cant take advantage of new packages for their apps if the distro doesnt support them. It could also lead to conflict between two different versions. As a result, it creates administration challenges as they are often difficult to keep updated and in sync.
### Image-based Model
Thats where the image based model comes to the rescue. “The image-based model solves the problems of the traditional model as it replaces the operating system at every reiteration and doesn't work with single packages,” said Eckermann.
“When we talk about the operating system as an image, what were really talking about is developing and deploying in a programmatic way and with better integrated life cycle management,” said Pacheco, giving the example of OpenShift, which is built on top of Red Hat Enterprise Linux.
Pacheco sees the image-based OS as a continuum, from hand-tooling a deployed image to a heavily automated infrastructure that can be managed at a large scale; regardless of where a customer is on this range, the same applications have to run. “You don't want to create a silo by using a wholly different deployment model,” he said.
The image-based model replaces the entire OS with new libraries and packages, which introduces its own set of problems. The image-based model has to be reconstructed to meet the needs of specific environments. For example, if the user has a specific need for installing a specific hardware driver or low-level monitoring option, the image model fails, or options to have finer granularity have to be re-invented.
### Transactional model
The third model is transactional updates, which follows the traditional package-based updates, but instead handles all packages as if they were images, updating all the packages that belong together in one shot like an image.
“The difference is because they are single packages that are grouped together as well as on descending and the installation, the customer has the option to influence this if necessary. This gives the user extra flexibility by combining the benefits of both and avoiding the disadvantages associated with the traditional or image model,” said Eckermann.
Pacheco said that its becoming increasingly common for carefully crafted workloads to be deployed as images in order to deploy consistently, reliably, and to do so with elasticity. “This is what we see our customers do today when they create and deploy virtual machines on premises or on public/private clouds as well as on traditional bare metal deployments,” he said.
Pacheco suggests that we should not look at these models as strictly a “compare and contrast scenario,” but rather as an evolution and expansion of the operating systems role.
### Arrival of Atomic Updates
Googles Chrome OS and the Core OS popularized the concept of transactional updates, a model followed by both Red Hat and SUSE.
“The real problem is the operating system underlining the container host operating system is not in focus anymore -- at least not in a way the administrator should care about. Both RH Atomic Host and SUSE CaaS Platform solve this problem similarly from a user experience perspective,” said Eckermann.
[Immutable infrastructure][2], such as that provided by SUSE CaaS Platform, Red Hat Atomic Host, and Container Linux (formerly Core OS), encourages the use of transactional updates. “Having a model where the host always moves to a known good state enables better confidence with updates, which in turn enables a faster flow of features, security benefits, and an easier-to-adopt operational model,” said Ben Breard, senior technology product manager, Red Hat.
These newer OSes isolate the applications from the underlying host with Linux containers thereby removing many of the traditional limitations associated with infrastructure updates.
“The real power and benefits are realized when the orchestration layer is intelligently handling the updates, deployments, and, ultimately, seamless operations,” added Breard.
### The Future
What does the future hold for Linux? The answer really depends on who you ask. Container players will say the future belongs to containerized OS, but Linux vendors who still have a huge market may disagree.
When asked if, in the long run, atomic distros will replace traditional distributions, Eckermann said, “If I say yes, then I am following the trend; if I say no, I will be considered old-fashioned. Nevertheless, I say no: atomic distros will not replace traditional distros in the long run -- but traditional workloads and containerized workloads will live together in data centers as well as private and public cloud environments.”
Pacheco maintained that the growth in Linux deployments, in general, makes it difficult to imagine one model replacing the other. He said that instead of looking at them as competing models, we should look at atomic distributions as part of the evolution and deployment of the operating system.
Additionally, there are many use-cases that may need a mix of both species of Linux distributions. “Imagine the large number of PL/1 and Cobol systems in banks and insurance companies. Think about in-memory databases and core data bus systems,” said Eckermann.
Most of these applications cant be containerized. As much as we would like to think, containerization is not a silver bullet that solves every problem. There will always be a mix of different technologies.
Eckermann believes that over time, a huge number of new developments and deployments will go into containerization, but there is still good reason to keep traditional deployment methods and applications in the enterprise.
“Customers need to undergo business, design, and cultural transformations in order to maximize the advantages that container-based deployments are delivering. The good news is that the industry understands this, as a similar transformation at scale occurred with the historical moves from mainframes to UNIX to x86 to virtualization,” said Pacheco.
### Conclusion
Its apparent that the volume of containerized workloads will increase in the future, which translates into more demand for atomic distros. In the meantime, a substantial percentage of workloads may remain on traditional distros that will keep them running. What really matters is that both players have invested heavily in new models and are ready to tweak their strategy as the market evolves. An external observer can clearly see that the future belongs to transactional/atomic models. We have seen the evolution of datacenter; we have come a long way from one application per server to function-as-a-service model. It is not far fetched to see Linux distros entering the atomic phase.
--------------------------------------------------------------------------------
via: https://www.linux.com/blog/2018/4/containerization-atomic-distributions-and-future-linux
作者:[SWAPNIL BHARTIYA][a]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
选题:[lujun9972](https://github.com/lujun9972)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]:https://www.linux.com/users/arnieswap
[1]:https://www.suse.com/products/caas-platform/
[2]:https://www.digitalocean.com/community/tutorials/what-is-immutable-infrastructure

View File

@@ -1,55 +0,0 @@
translating---geekpi
Audacity quick tip: quickly remove background noise
======
![](https://fedoramagazine.org/wp-content/uploads/2018/03/audacity-noise-816x345.png)
When recording sounds on a laptop — say for a simple first screencast — many users typically use the built-in microphone. However, these small microphones also capture a lot of background noise. In this quick tip, learn how to use [Audacity][1] in Fedora to quickly remove the background noise from audio files.
### Installing Audacity
Audacity is an application in Fedora for mixing, cutting, and editing audio files. It supports a wide range of formats out of the box on Fedora — including MP3 and OGG. Install Audacity from the Software application.
![][2]
If the terminal is more your speed, use the command:
```
sudo dnf install audacity
```
### Import your Audio, sample background noise
After installing Audacity, open the application, and import your sound using the **File > Import** menu item. This example uses a [sound bite from freesound.org][3] to which noise was added:
Next, take a sample of the background noise to be filtered out. With the tracks imported, select an area of the track that contains only the background noise. Then choose **Effect > Noise Reduction** from the menu, and press the **Get Noise Profile** button.
![][4]
### Filter the Noise
Next, select the area of the track you want to filter the noise from. Do this either by selecting with the mouse, or **Ctrl + a** to select the entire track. Finally, open the **Effect > Noise Reduction** dialog again, and click OK to apply the filter.
![][5]
Additionally, play around with the settings until your tracks sound better. Here is the original file again, followed by the noise reduced track for comparison (using the default settings):
https://ryanlerch.fedorapeople.org/sidebyside.ogg?_=2
--------------------------------------------------------------------------------
via: https://fedoramagazine.org/audacity-quick-tip-quickly-remove-background-noise/
作者:[Ryan Lerch][a]
选题:[lujun9972](https://github.com/lujun9972)
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://fedoramagazine.org/introducing-flatpak/
[1]:https://www.audacityteam.org/
[2]:https://fedoramagazine.org/wp-content/uploads/2018/03/audacity-software.jpg
[3]:https://freesound.org/people/levinj/sounds/8323/
[4]:https://fedoramagazine.org/wp-content/uploads/2018/03/select-noise-profile.gif
[5]:https://fedoramagazine.org/wp-content/uploads/2018/03/apply-filter.gif

View File

@@ -1,3 +1,5 @@
translated by cyleft
How to Enable Click to Minimize On Ubuntu
============================================================

View File

@@ -1,3 +1,5 @@
translating----geekpi
Using Stratis to manage Linux storage from the command line
======

View File

@@ -0,0 +1,88 @@
容器化,原子化发行版以及 Linux 的未来
======
![](https://www.linux.com/sites/lcom/files/styles/rendered_file/public/atomic-distro.jpg?itok=SjBeCDtq)
自从 Linus Torvalds 在 1991 年发布 Linux 以来Linux 已历经漫长的岁月。它已经成为企业级领域的主流操作系统。同时,我们看到桌面级领域出现了很多改进和调整,但在过去的 25+ 年,主流 Linux 发行版的模式很大程度上保持不变。基于软件包管理的传统模式依然统治着桌面级和服务器级市场。
但随着 Google 发布了基于 Linux 的 Chrome-OS情况出现了微妙的转变Chrome-OS 采用镜像模式。Core OS (目前归属于 Red Hat) 受 Google 启发推出了一款操作系统 Container Linux主要面向企业级用户。
Container Linux 改变了操作系统更新的方式,也改变了应用分发和更新的方式。这会是 Linux 发行版的未来吗?这是否会取代基于软件包的传统发行版模式呢?
### 三种模式
SLE (SUSE Linux Enterprise) 的产品管理总监 Matthias Eckermann 认为目前存在 3 种模式,而不是 2 种。Eckermann 提到:“除了传统模式 (RHEL/SLE) 和镜像模式 (RH Atomic Host),还存在第三种模型:事务模式。[SUSE CaaS 平台][1] 及 SUSE MicroOS 就采用这种模型。”
### 差异有哪些
Linux 用户对传统模式非常熟悉,它由独立的软件包和共享库组成。这种模式有独特的优势,让应用开发者无需将共享库捆绑在应用中。由于库不会多次引入,使得系统简洁和轻便。这也让用户无需下载很多软件包,节省了带宽。发行版对软件包全权负责,通过推送系统级别的更新,可以轻松地解决安全隐患。
RHEL (Red Hat Enterprise Linux) 的产品管理总监 Ron Pacheco 表示,“传统的打包方式继续为我们提供精心构建和优化操作系统的机会,以便支持需要经过时间考验的任务关键型工作负载。”
但传统模式也有一些弊端。应用开发者受限使用发行版包含的库,使其无法从发行版不支持的新软件中获益。这也可能导致不同版本之间相互冲突。最终,传统模式给管理员增加了挑战,使其难以让软件包一直处于最新版本状态。
### 镜像模式
镜像模式应运而生。Eckermann 表示,“镜像模式解决了传统模式遇到的问题,它在每次迭代更新时替换整个操作系统,其中也不包含独立的软件包”。
Pacheco 表示,“当我们用镜像作为操作系统的代名词进行讨论时,我们真正关心的是可编程式的开发部署以及更好的集成式生命周期管理”,基于 RHEL 搭建的 OpenShift 被他用作示例。
Pacheco 认为基于镜像的操作系统是一种延续,从手工打造并部署镜像,到可大规模管理的高度自动化基础设施;无论客户使用哪种类型,都需要运行同样的应用。他说,“你肯定不希望使用一个完全不同的部署模式,这需要重做很多工作”。
镜像模式替代了使用新库和软件包的完整操作系统,但也面临一系列问题。在镜像模式中,需要重建镜像才能适应特殊环境的需求。例如,用户有特殊需求,需要安装特定硬件的驱动或安装底层监控功能,镜像模式无法满足,需要重新设计功能以实现细粒度操作。
### 事务模式
第三种模式采用事务更新,基于传统的软件包更新,但将全部的软件包视为一个镜像,就像镜像那样在一次操作中更新全部软件包。
Eckermann 表示,“由于安装或回滚时操作对象是打包在一起的独立软件包,用户在需要时能够做相应的调整,这就是差别所在。结合传统模式和镜像模式的优点,避免两种模式的缺点,事务模式给用户提供了额外的灵活性。”
Pacheco 表示,将精心构造的工作负载部署成镜像的做法越来越成为主流,因为这种部署方式具有一致性和可靠性,而且可以弹性部署。“这正是我们用户目前的做法,部署环境包括在预置设备或公有/私有云上创建并部署的虚拟机,或在传统的裸机上”
Pacheco 建议我们将这几种模式视为操作系统角色的进化和扩展,而不是仅仅“使用场景的比较和对比“。
### 原子化更新的问世
Google 的 Chrome OS 和 Core OS 为我们普及了事务更新的概念,该模型也被 Red Hat 和 SUSE 采用。
Eckermann 表示,”我们必须认识到,用于容器主机的操作系统已经不再是关注点 —— 至少不是管理员的关注点。RH Atomic 主机和 SUSE CaaS 平台都解决了该问题,实现方式在用户看来很相似。“
SUSE CaaS 平台、Red Hat Atomic Host和 Container Linux (前身是 Core OS提供的[<ruby>不可变基础设施<rt>Immutable infrastructure</rt></ruby>][2] 推广了事务更新的使用。Red Hat 高级技术产品经理 Ben Breard 表示,”在事务模式中,主机总是会变更到已确认正确的新状态,这让我们更有信心执行更新,进而实现更快速的功能流、安全优势以及易于采用的操作模式“。
这些新型操作系统使用 Linux 容器将应用与底层系统隔离,解除了传统模式中基础设施更新的诸多限制。
Breard 补充道,“当编排层可以智能处理更新、部署,甚至最终实现无缝操作时,我们才会真正意识到该模式的威力和好处”。
### 展望未来
Linux 的未来会是什么样子?不同的人会给出不同的回答。容器支持者认为未来属于容器化的操作系统,但依然拥有庞大市场的 Linux 供应商显然不这么认为。
当被问到原子化发行版是否在很久以后将替换传统发行版时Eckermann 表示,“如果我回答肯定的,那么表示我顺应潮流;如果回答是否的的,意味着我还是站在传统阵营。然而,我的回答是否定的,即 atomic 发行版在很久以后也不会替换传统发行版,传统负载和容器化负载将在数据中心、私有云以及公有云环境中共存。”
Pacheco 认为,从 Linux 的部署增长情况来看,一般情况下很难想象一种模式替换另一种模式。与其将多种模式视为相互竞争的关系,不如将原子化发行版视为操作系统进化和部署的一部分。
此外,在一些使用案例中,我们需要同时使用多种 Linux 发行版。Eckermann 表示,“想一想银行和保险公司中大量的 PL/1 和 Cobol 系统。再想一想内存数据库和核心数据总线系统”。
这些应用大多数无法进行容器化。就我们目前来看,容器化不是解决所有问题的万金油。总是会同时存在多种不同的技术。
Eckermann 相信,随着时间的推移,大量新的开发和部署将采用容器化,但仍然有不错的理由,促使我们在企业级环境中保留传统的部署方式和应用。
Pacheco 认为,“用户需要经历业务、设计和文化的转型,才能最大化基于容器的部署带来的优势。好消息是业界已经认识到并开始大规模转变,就像历史上大型机转变成 UNIXUNIX 转变成 x86x86 转变成虚拟化那样”。
### 结论
很明显,未来容器化负载的使用量会持续增长,也就意味着原子化发行版的需求量持续增长。与此同时,仍会有不少工作负载运行在传统发行版中。重要的是,这两类用户都在新模式上大规模投入,以便市场改变时可以做相应的策略改变。从外部观察者的视角来看,未来属于事务/原子化模式。我们已经见证了数据中心的发展我们花了很长时间完成了从每个服务器一个应用到函数即服务模型的转变。Linux 发行版进入原子化时代的日子也不会太远了。
--------------------------------------------------------------------------------
via: https://www.linux.com/blog/2018/4/containerization-atomic-distributions-and-future-linux
作者:[SWAPNIL BHARTIYA][a]
译者:[pinewall](https://github.com/pinewall)
校对:[校对者ID](https://github.com/校对者ID)
选题:[lujun9972](https://github.com/lujun9972)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]:https://www.linux.com/users/arnieswap
[1]:https://www.suse.com/products/caas-platform/
[2]:https://www.digitalocean.com/community/tutorials/what-is-immutable-infrastructure

View File

@@ -1,45 +1,44 @@
Translating by qhwdw
Passwordless Auth: Server
无密码验证:服务器
============================================================
Passwordless authentication allows logging in without a password, just an email. Its a more secure way of doing than the classic email/password login.
无密码验证可以让你只输入一个 email 而无需输入密码即可登入系统。这是一种比传统的电子邮件/密码验证方式登入更安全的方法。
Ill show you how to code an HTTP API in [Go][6] that provides this service.
下面我将为你展示,如何在 [Go][6] 中实现一个 HTTP API 去提供这种服务。
### Flow
### 业务流
* User inputs his email.
* 用户输入他的电子邮件地址。
* Server creates a temporal on-time-use code associated with the user (like a temporal password) and mails it to the user in form of a “magic link”.
* 服务器创建一个临时的一次性使用的代码(就像一个临时密码一样)关联到用户,然后给用户邮箱中发送一个“魔法链接”。
* User clicks the magic link.
* 用户点击魔法链接。
* Server extract the code from the magic link, fetch the user associated and redirects to the client with a new JWT.
* 服务器提取魔法链接中的代码,获取关联的用户,并且使用一个新的 JWT 重定向到客户端。
* Client will use the JWT in every new request to authenticate the user.
* 在每次有新请求时,客户端使用 JWT 去验证用户。
### Requisites
### 必需条件
* Database: Well use an SQL database called [CockroachDB][1] for this. Its much like postgres, but writen in Go.
* 数据库:我们为这个服务使用了一个叫 [CockroachDB][1] 的 SQL 数据库。它非常像 postgres但它是用 Go 写的。
* SMTP Server: To send mails well use a third party mailing service. For development well use [mailtrap][2]. Mailtrap sends all the mails to its inbox, so you dont have to create multiple fake email accounts to test it.
* SMTP 服务器:我们将使用一个第三方的邮件服务器去发送邮件。开发的时我们使用 [mailtrap][2]Mailtrap 发送所有的邮件到它的收件箱,因此,你在测试它们时不需要创建多个假冒邮件帐户。
Install Go from [its page][7] and check your installation went ok with `go version`(1.10.1 atm).
从 [它的主页][7] 上安装 Go然后使用 `go version`1.10.1 atm)命令去检查它能否正常工作。
Download CockroachDB from [its page][8], extract it and add it to your `PATH`. Check that all went ok with `cockroach version` (2.0 atm).
从 [它的主页][8] 上下载 CockroachDB展开它并添加到你的 `PATH` 变量中。使用 `cockroach version`2.0 atm)命令检查它能否正常工作。
### Database Schema
### 数据库模式
Now, create a new directory for the project inside `GOPATH` and start a new CockroachDB node with `cockroach start`:
现在,我们在 `GOPATH` 目录下为这个项目创建一个目录,然后使用 `cockroach start` 启动一个新的 CockroachDB 节点:
```
cockroach start --insecure --host 127.0.0.1
```
It will print some things, but check the SQL address line, it should said something like `postgresql://root@127.0.0.1:26257?sslmode=disable`. Well use this to connect to the database later.
它会输出一些内容,找到 SQL 地址行,它将显示像 `postgresql://root@127.0.0.1:26257?sslmode=disable` 这样的内容。稍后我们将使用它去连接到数据库。
Create a `schema.sql` file with the following content.
使用如下的内容去创建一个 `schema.sql` 文件。
```
DROP DATABASE IF EXISTS passwordless_demo CASCADE;
@@ -63,28 +62,28 @@ INSERT INTO users (email, username) VALUES
```
This script creates a database `passwordless_demo`, two tables: `users` and `verification_codes`, and inserts a fake user just to test it later. Each verification code is associated with a user and stores the creation date, useful to check if the code is expired or not.
这个脚本创建了一个名为 `passwordless_demo` 的数据库、两个名为 `users`  `verification_codes` 的表,以及为了稍后测试而插入的一些假冒用户。每个验证代码都与用户关联并保存代码创建数据,以用于去检查代码是否过期。
To execute this script use `cockroach sql` in other terminal:
在另外的终端中使用 `cockroach sql` 命令去运行这个脚本:
```
cat schema.sql | cockroach sql --insecure
```
### Environment Configuration
### 环境配置
I want you to set two environment variables: `SMTP_USERNAME` and `SMTP_PASSWORD` that you can get from your mailtrap account. These two will be required by our program.
需要配置两个环境变量:`SMTP_USERNAME`  `SMTP_PASSWORD`,你可以从你的 mailtrap 帐户中获得它们。将在我们的程序中用到它们。
### Go Dependencies
### Go 依赖
For Go well need the following packages:
我们需要下列的 Go 包:
* [github.com/lib/pq][3]: Postgres driver which CockroachDB uses.
* [github.com/lib/pq][3]:它是 CockroachDB 使用的 postgres 驱动
* [github.com/matryer/way][4]: Router.
* [github.com/matryer/way][4]: 路由器
* [github.com/dgrijalva/jwt-go][5]: JWT implementation.
* [github.com/dgrijalva/jwt-go][5]: JWT 实现
```
go get -u github.com/lib/pq
@@ -93,11 +92,11 @@ go get -u github.com/dgrijalva/jwt-go
```
### Coding
### 代码
### Init Function
### 初始化函数
Create the `main.go` and start by getting some configuration from the environment inside the `init` function.
创建 `main.go` 并且通过 `init` 函数里的环境变量中取得一些配置来启动。
```
var config struct {
@@ -137,23 +136,23 @@ func env(key, fallbackValue string) string {
```
* `appURL` will allow us to build the “magic link”.
* `appURL` 将去构建我们的 “魔法链接”。
* `port` in which the HTTP server will start.
* `port` 将要启动的 HTTP 服务器。
* `databaseURL` is the CockroachDB address, I added `/passwordless_demo` to the previous address to indicate the database name.
* `databaseURL`  CockroachDB 地址,我添加 `/passwordless_demo` 前面的数据库地址去表示数据库名字。
* `jwtKey` used to sign JWTs.
* `jwtKey` 用于签名 JWTs
* `smtpAddr` is a join of `SMTP_HOST` + `SMTP_PORT`; well use it to to send mails.
* `smtpAddr`  `SMTP_HOST` + `SMTP_PORT` 的联合;我们将使用它去发送邮件。
* `smtpUsername` and `smtpPassword` are the two required vars.
* `smtpUsername`  `smtpPassword` 是两个必需的变量。
* `smtpAuth` is also used to send mails.
* `smtpAuth` 也是用于发送邮件。
The `env` function allow us to get an environment variable with a fallback value in case it doesnt exist.
`env` 函数允许我们去获得环境变量,不存在时返回一个 fallback value。
### Main Function
### 主函数
```
var db *sql.DB
@@ -181,7 +180,7 @@ func main() {
```
First, it opens a database connection. Remember to load the driver.
首先,打开数据库连接。记得要加载驱动。
```
import (
@@ -190,11 +189,11 @@ import (
```
Then, we create the router and define some endpoints. For the passwordless flow we use two endpoints: `/api/passwordless/start` mails the magic link and `/api/passwordless/verify_redirect` respond with the JWT.
然后,我们创建路由器并定义一些端点。对于无密码业务流来说,我们使用两个端点:`/api/passwordless/start` 发送魔法链接,和 `/api/passwordless/verify_redirect` 用 JWT 响应。
Finally, we start the server.
最后,我们启动服务器。
You can create empty handlers and middlewares to test that the server starts.
你可以创建空处理程序和中间件去测试服务器启动。
```
func createUser(w http.ResponseWriter, r *http.Request) {
@@ -227,7 +226,7 @@ func authRequired(next http.HandlerFunc) http.HandlerFunc {
```
Now:
接下来:
```
go build
@@ -235,11 +234,11 @@ go build
```
Im on a directory called “passwordless-demo”, but if yours is different, `go build` will create an executable with that name. If you didnt close the previous cockroach node and you setted `SMTP_USERNAME` and `SMTP_PASSWORD` vars correctly, you should see `starting server at http://localhost/ 🚀` without errors.
我们在目录中有了一个 “passwordless-demo”但是你的目录中可能与示例不一样`go build` 将创建一个同名的可执行文件。如果你没有关闭前面的 cockroach 节点,并且你正确配置了 `SMTP_USERNAME`  `SMTP_PASSWORD` 变量,你将看到命令 `starting server at http://localhost/ 🚀` 没有错误输出。
### JSON Required Middleware
### JSON 要求的中间件
Endpoints that need to decode JSON from the request body need to make sure the request is of type `application/json`. Because that is a common thing, I decoupled it to a middleware.
端点需要从请求体中解码 JSON因此要确保请求是 `application/json` 类型。因为它是一个通用的东西,我将它解耦到中间件。
```
func jsonRequired(next http.HandlerFunc) http.HandlerFunc {
@@ -256,11 +255,11 @@ func jsonRequired(next http.HandlerFunc) http.HandlerFunc {
```
As easy as that. First it gets the request content type from the headers, then check if it starts with “application/json”, otherwise it early return with `415 Unsupported Media Type`.
实现很容易。首先它从请求头中获得内容的类型,然后检查它是否是以 “application/json” 开始,如果不是则以 `415 Unsupported Media Type` 提前返回。
### Respond JSON Function
### 响应 JSON 函数
Responding with JSON is also a common thing so I extracted it to a function.
以 JSON 响应是非常通用的做法,因此我把它提取到函数中。
```
func respondJSON(w http.ResponseWriter, payload interface{}, code int) {
@@ -284,11 +283,11 @@ func respondJSON(w http.ResponseWriter, payload interface{}, code int) {
```
First, it does a type assertion for primitive types to wrap they in a `map`. Then it marshalls to JSON, sets the response content type and status code, and writes the JSON. In case the JSON marshalling fails, it respond with an internal error.
首先,对原始类型做一个类型判断,并将它们封装到一个 `map`。然后将它们编组到 JSON设置响应内容类型和状态码并写 JSON。如果 JSON 编组失败,则响应一个内部错误。
### Respond Internal Error Function
### 响应内部错误的函数
`respondInternalError` is a funcion that respond with `500 Internal Server Error`, but it also logs the error to the console.
`respondInternalError` 是一个响应 `500 Internal Server Error` 的函数,但是也同时将错误输出到控制台。
```
func respondInternalError(w http.ResponseWriter, err error) {
@@ -300,9 +299,9 @@ func respondInternalError(w http.ResponseWriter, err error) {
```
### Create User Handler
### 创建用户处理程序
Ill start coding the `createUser` handler because is the more easy and REST-ish.
下面开始编写 `createUser` 处理程序,因为它非常容易并且是 REST 式的。
```
type User struct {
@@ -313,7 +312,7 @@ type User struct {
```
The `User` type is just like the `users` table.
`User` 类型和 `users` 表相似。
```
var (
@@ -323,9 +322,9 @@ var (
```
These regular expressions are to validate email and username respectively. These are very basic, feel free to adapt they as you need.
这些正则表达式是分别用于去验证电子邮件和用户名的。这些都很简单,可以根据你的需要随意去适配。
Now, **inside** `createUser` function well start by decoding the request body.
现在,在 `createUser` 函数内部,我们将开始解码请求体。
```
var user User
@@ -337,7 +336,7 @@ defer r.Body.Close()
```
We create a JSON decoder using the request body and decode to a user pointer. In case of error we return with a `400 Bad Request`. Dont forget to close the body reader.
我们将使用请求体去创建一个 JSON 解码器来解码出一个用户指针。如果发生错误则返回一个 `400 Bad Request`。不要忘记关闭请求体读取器。
```
errs := make(map[string]string)
@@ -358,7 +357,7 @@ if len(errs) != 0 {
```
This is how I make validation; a simple `map` and check if `len(errs) != 0` to return with `422 Unprocessable Entity`.
这是我如何做验证;一个简单的 `map` 并检查如果 `len(errs) != 0`,则使用 `422 Unprocessable Entity` 去返回。
```
err := db.QueryRowContext(r.Context(), `
@@ -381,18 +380,18 @@ if errPq, ok := err.(*pq.Error); ok && errPq.Code.Name() == "unique_violation" {
```
This SQL query inserts a new user with the given email and username, and returns the auto generated id. Each `$` will be replaced by the next arguments passed to `QueryRowContext`.
这个 SQL 查询使用一个给定的 email 和用户名去插入一个新用户,并返回自动生成的 id每个 `$` 将被接下来传递给 `QueryRowContext` 的参数替换掉。
Because the `users` table had unique constraints on the `email` and `username`fields I check for the “unique_violation” error to return with `403 Forbidden` or I return with an internal error.
因为 `users` 表在 `email`  `username` 字段上有唯一性约束,因此我将检查 “unique_violation” 错误并返回 `403 Forbidden` 或者返回一个内部错误。
```
respondJSON(w, user, http.StatusCreated)
```
Finally I just respond with the created user.
最后使用创建的用户去响应。
### Passwordless Start Handler
### 无密码验证开始部分的处理程序
```
type PasswordlessStartRequest struct {
@@ -402,14 +401,14 @@ type PasswordlessStartRequest struct {
```
This struct holds the `passwordlessStart` request body. The email of the user who wants to log in. The redirect URI comes from the client (the app that will use our API) ex: `https://frontend.app/callback`.
这个结构体持有 `passwordlessStart` 的请求体。希望去登入的用户 email。来自客户端的重定向 URI这个应用中将使用我们的 API`https://frontend.app/callback`
```
var magicLinkTmpl = template.Must(template.ParseFiles("templates/magic-link.html"))
```
Well use the golang template engine to build the mailing so Ill need you to create a `magic-link.html` file inside a `templates` directory with a content like so:
我们将使用 golang 模板引擎去构建邮件,因此需要你在 `templates` 目录中,用如下的内容创建一个 `magic-link.html` 文件:
```
<!DOCTYPE html>
@@ -428,9 +427,9 @@ Well use the golang template engine to build the mailing so Ill need you t
```
This template is the mail well send to the user with the magic link. Feel free to style it how you want.
这个模板是给用户发送魔法链接邮件用的。你可以根据你的需要去随意调整它。
Now, **inside** `passwordlessStart` function:
现在, 进入 `passwordlessStart` 函数**内部**
```
var input PasswordlessStartRequest
@@ -442,7 +441,7 @@ defer r.Body.Close()
```
First, we decode the request body like before.
首先,我们像前面一样解码请求体。
```
errs := make(map[string]string)
@@ -463,7 +462,7 @@ if len(errs) != 0 {
```
For the redirect URI validation we use the golang URL parser and check that the URI is absolute.
我们使用 golang URL 解析器去验证重定向 URI检查那个 URI 是否为绝对地址。
```
var verificationCode string
@@ -482,7 +481,7 @@ if errPq, ok := err.(*pq.Error); ok && errPq.Code.Name() == "not_null_violation"
```
This SQL query will insert a new verification code associated with a user with the given email and return the auto generated id. Because the user could not exist, that subquery can resolve to `NULL` which will fail the `NOT NULL`constraint on the `user_id` field so I do a check on that and return with `404 Not Found` in case or an internal error otherwise.
这个 SQL 查询将插入一个验证代码,这个代码通过给定的 email 关联到用户,并且返回一个自动生成的 id。因为有可能会出现用户不存在的情况那样的话子查询可能解析为 `NULL`,这将导致在 `user_id` 字段上因违反 `NOT NULL` 约束而导致失败,因此需要对这种情况进行检查,如果用户不存在,则返回 `404 Not Found` 或者一个内部错误。
```
q := make(url.Values)
@@ -494,7 +493,7 @@ magicLink.RawQuery = q.Encode()
```
Now, I build the magic link and set the `verification_code` and `redirect_uri`inside the query string. Ex: `http://localhost/api/passwordless/verify_redirect?verification_code=some_code&redirect_uri=https://frontend.app/callback`.
现在,构建魔法链接并设置查询字符串中的 `verification_code` `redirect_uri` 的值。如:`http://localhost/api/passwordless/verify_redirect?verification_code=some_code&redirect_uri=https://frontend.app/callback`
```
var body bytes.Buffer
@@ -506,7 +505,7 @@ if err := magicLinkTmpl.Execute(&body, data); err != nil {
```
Well get the magic link template content saving it to a buffer. In case of error I return with an internal error.
我们将得到的魔法链接模板的内容保存到缓冲区中。如果发生错误则返回一个内部错误。
```
to := mail.Address{Address: input.Email}
@@ -517,16 +516,16 @@ if err := sendMail(to, "Magic Link", body.String()); err != nil {
```
To mail the user I make use of `sendMail` function that Ill code now. In case of error I return with an internal error.
现在来写给用户发邮件的 `sendMail` 函数。如果发生错误则返回一个内部错误。
```
w.WriteHeader(http.StatusNoContent)
```
Finally, I just set the response status code to `204 No Content`. The client doesnt need more data than a success status code.
最后,设置响应状态码为 `204 No Content`。对于成功的状态码,客户端不需要很多数据。
### Send Mail Function
### 发送邮件函数
```
func sendMail(to mail.Address, subject, body string) error {
@@ -557,18 +556,18 @@ func sendMail(to mail.Address, subject, body string) error {
```
This function creates the structure of a basic HTML mail and sends it using the SMTP server. There is a lot of things you can customize of a mail, but I kept it simple.
这个函数创建一个基本的 HTML 邮件结构体并使用 SMTP 服务器去发送它。邮件的内容你可以随意定制,我喜欢使用比较简单的内容。
### Passwordless Verify Redirect Handler
### 无密码验证重定向处理程序
```
var rxUUID = regexp.MustCompile("^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$")
```
First, this regular expression is to validate an UUID (the verification code).
首先,这个正则表达式去验证一个 UUID验证代码
Now, **inside** `passwordlessVerifyRedirect` function:
现在进入 `passwordlessVerifyRedirect` 函数 **内部**
```
q := r.URL.Query()
@@ -577,7 +576,7 @@ redirectURI := q.Get("redirect_uri")
```
`/api/passwordless/verify_redirect` is a `GET` endpoint so we read data from the query string.
`/api/passwordless/verify_redirect` 是一个 `GET` 端点,以便于我们从查询字符串中读取数据。
```
errs := make(map[string]string)
@@ -600,7 +599,7 @@ if len(errs) != 0 {
```
Pretty similar validation, but we store the parsed redirect URI into a `callback`variable.
类似的验证,我们保存解析后的重定向 URI 到一个 `callback` 变量中。
```
var userID string
@@ -619,7 +618,7 @@ if err := db.QueryRowContext(r.Context(), `
```
This SQL query deletes a verification code with the given id and makes sure it has been created no more than 15 minutes ago, it also returns the `user_id`associated. In case of no rows, means the code didnt exist or it was expired so we respond with that, otherwise an internal error.
这个 SQL 查询通过给定的 id 去删除相应的验证代码,并且确保它创建之后时间不超过 15 分钟,它也返回关联的 `user_id`。如果没有检索到内容,意味着代码不存在或者已过期,我们返回一个响应信息,否则就返回一个内部错误。
```
expiresAt := time.Now().Add(time.Hour * 24 * 60)
@@ -634,7 +633,7 @@ if err != nil {
```
This is how the JWT is created. We set an expiration date for the JWT within 60 days. Maybe you can give it less time (~2 weeks) and add a new endpoint to refresh tokens, but I didnt want to add more complexity.
这些是如何去创建 JWT。我们为 JWT 设置一个 60 天的过期值,你也可以设置更短的时间(大约 2 周),并添加一个新端点去刷新令牌,但是不要搞的过于复杂。
```
expiresAtB, err := expiresAt.MarshalText()
@@ -649,24 +648,24 @@ callback.Fragment = f.Encode()
```
We plan to redirect; you could use the query string to add the JWT, but Ive seen that a hash fragment is more used. Ex: `https://frontend.app/callback#jwt=token_here&expires_at=some_date`.
我们去规划重定向;你可使用查询字符串去添加 JWT但是更常见的是使用一个哈希片段。如`https://frontend.app/callback#jwt=token_here&expires_at=some_date`.
The expiration date could be extracted from the JWT, but then the client will have to implement a JWT library to decode it, so to make the life easier I just added it there too.
过期日期可以从 JWT 中提取出来,但是这样做的话,就需要在客户端上实现一个 JWT 库来解码它,因此为了简化,我将它加到这里。
```
http.Redirect(w, r, callback.String(), http.StatusFound)
```
Finally we just redirect with a `302 Found`.
最后我们使用一个 `302 Found` 重定向。
* * *
The passwordless flow is completed. Now we just need to code the `getAuthUser`endpoint which is to get info about the current authenticated user. If you rememeber, this endpoint makes use of `authRequired` middleware.
无密码的工作流已经完成。现在需要去写 `getAuthUser` 端点的代码了,它用于获取当前验证用户的信息。你应该还记得,这个端点使用了 `authRequired` 中间件。
### With Auth Middleware
### 使用 Auth 中间件
Before coding the `authRequired` middleware, Ill code one that doesnt require authentication. I mean, if no JWT is passed, it just continues without authenticating the user.
在编写 `authRequired` 中间件之前,我将编写一个不需要验证的分支。目的是,如果没有传递 JWT它将不去验证用户。
```
type ContextKey int
@@ -711,13 +710,13 @@ func withAuth(next http.HandlerFunc) http.HandlerFunc {
```
The JWT will come in every request inside the “Authorization” header in the form of “Bearer <token_here>”. So if no token is present, we just pass to the next middleware.
JWT 将在每次请求时以 “Bearer <token_here>” 格式包含在 “Authorization” 头中。因此,如果没有提供令牌,我们将直接通过,进入接下来的中间件。
We create a parser and parse the token. If fails, we return with `401 Unauthorized`.
我们创建一个解析器来解析令牌。如果解析失败则返回 `401 Unauthorized`
Then we extract the claims inside the JWT and add the `Subject` (which is the user ID) to the request context.
然后我们从 JWT 中提取出要求的内容,并添加 `Subject`(就是用户 ID到需要的地方。
### Auth Required Middleware
### Auth 需要的中间件
```
func authRequired(next http.HandlerFunc) http.HandlerFunc {
@@ -731,13 +730,14 @@ func authRequired(next http.HandlerFunc) http.HandlerFunc {
})
}
```
Now, `authRequired` will make use of `withAuth` and will try to extract the authenticated user ID from the request context. If fails, it returns with `401 Unauthorized` otherwise continues.
现在,`authRequired` 将使用 `withAuth` 并从请求内容中提取出验证用户的 ID。如果提取失败它将返回 `401 Unauthorized`,提取成功则继续下一步。
### Get Auth User
### 获取 Auth 用户
**Inside** `getAuthUser` handler:
 `getAuthUser` 处理程序**内部**
```
ctx := r.Context()
@@ -756,11 +756,11 @@ respondJSON(w, user, http.StatusOK)
```
First we extract the ID of the authenticated user from the request context, we use that to fetch the user. In case of no row returned, we send a `418 I'm a teapot` or an internal error otherwise. Lastly we just respond with the user 😊
首先,我们从请求内容中提取验证用户的 ID我们使用这个 ID 去获取用户。如果没有获取到内容,则发送一个 `418 I'm a teapot`,或者一个内部错误。最后,我们将用这个用户去响应 😊
### Fetch User Function
### 获取 User 函数
You saw a `fetchUser` function there.
下面你看到的是 `fetchUser` 函数。
```
func fetchUser(ctx context.Context, id string) (User, error) {
@@ -773,24 +773,24 @@ func fetchUser(ctx context.Context, id string) (User, error) {
```
I decoupled it because fetching a user by ID is a common thing.
我将它解耦是因为通过 ID 来获取用户是个常做的事。
* * *
Thats all the code. Build it and test it yourself. You can try a live demo [here][9].
以上就是全部的代码。你可以自己去构建它和测试它。[这里][9] 还有一个 demo 你可以试用一下。
If you have problems about `Blocked script execution because the document's frame is sandboxed and the 'allow-scripts' permission is not set` after clicking the magic link on mailtrap, try doing a right click + “Open link in new tab”. This is a security thing where the mail content is [sandboxed][10]. I had this problem sometimes on `localhost`, but I think you should be fine once you deploy the server with `https://`.
如果你在 mailtrap 上点击之后出现有关 `脚本运行被拦截,因为文档的框架是沙箱化的,并且没有设置 'allow-scripts' 权限` 的问题,你可以尝试右键点击 “在新标签中打开链接“。这样做是安全的,因为邮件内容是 [沙箱化的][10]。我在 `localhost` 上有时也会出现这个问题,但是我认为你一旦以 `https://` 方式部署到服务器上应该不会出现这个问题了。
Please leave any issues on the [GitHub repo][11] or feel free to send PRs 👍
如果有任何问题,请在我的 [GitHub repo][11] 留言或者提交 PRs 👍
Ill write a second part for this post coding a client for the API.
以后,我将为这个 API 写一个客户端作为这篇文章的第二部分。
--------------------------------------------------------------------------------
via: https://nicolasparada.netlify.com/posts/passwordless-auth-server/
作者:[Nicolás Parada ][a]
译者:[译者ID](https://github.com/译者ID)
译者:[qhwdw](https://github.com/qhwdw)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出

View File

@@ -0,0 +1,53 @@
Audacity 快速指南:快速消除背景噪音
======
![](https://fedoramagazine.org/wp-content/uploads/2018/03/audacity-noise-816x345.png)
当在笔记本电脑上录制声音时 - 比如首次简单地录屏 - 许多用户通常使用内置麦克风。但是,这些小型麦克风也会捕获很多背景噪音。在这个快速指南中,我们会学习如何使用 Fedora 中的 [Audacity][1] 快速移除音频文件中的背景噪音。
### 安装 Audacity
Audacity 是 Fedora 中用于混合、剪切和编辑音频文件的程序。在 Fedora 上它支持各种开箱即用的格式 - 包括 MP3 和 OGG。从软件中心安装 Audacity。
![][2]
如果你更喜欢终端,请使用以下命令:
```
sudo dnf install audacity
```
### 导入您的音频、样本背景噪音
安装 Audacity 后,打开程序,使用 **File > Import** 菜单项导入你的声音。这个例子使用了一个[来自 freesound.org 添加了噪音的声音][3]
接下来,采样要滤除的背景噪音。导入音轨后,选择仅包含背景噪音的音轨区域。然后从菜单中选择 **Effect > Noise Reduction**,然后按下 **Get Noise Profile** 按钮。
![][4]
### 过滤噪音
接下来,选择你要过滤噪音的音轨区域。通过使用鼠标进行选择,或者按 **Ctrl + a** 来选择整个音轨。最后,再次打开 **Effect > Noise Reduction** 对话框,然后单击确定以应用滤镜。
![][5]
此外,调整设置,直到你的音轨听起来更好。这里是原始文件,接下来是用于比较的降噪音轨(使用默认设置):
https://ryanlerch.fedorapeople.org/sidebyside.ogg?_=2
--------------------------------------------------------------------------------
via: https://fedoramagazine.org/audacity-quick-tip-quickly-remove-background-noise/
作者:[Ryan Lerch][a]
选题:[lujun9972](https://github.com/lujun9972)
译者:[geekpi](https://github.com/geekpi)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://fedoramagazine.org/introducing-flatpak/
[1]:https://www.audacityteam.org/
[2]:https://fedoramagazine.org/wp-content/uploads/2018/03/audacity-software.jpg
[3]:https://freesound.org/people/levinj/sounds/8323/
[4]:https://fedoramagazine.org/wp-content/uploads/2018/03/select-noise-profile.gif
[5]:https://fedoramagazine.org/wp-content/uploads/2018/03/apply-filter.gif