Merge remote-tracking branch 'LCTT/master'

This commit is contained in:
Xingyu Wang 2019-11-22 08:08:09 +08:00
commit cf6494482a
14 changed files with 1223 additions and 168 deletions

View File

@ -1,8 +1,8 @@
[#]: collector: (lujun9972)
[#]: translator: (wxy)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: reviewer: (wxy)
[#]: publisher: (wxy)
[#]: url: (https://linux.cn/article-11600-1.html)
[#]: subject: (How to use Protobuf for data interchange)
[#]: via: (https://opensource.com/article/19/10/protobuf-data-interchange)
[#]: author: (Marty Kalin https://opensource.com/users/mkalindepauledu)
@ -12,18 +12,15 @@
> 在以不同语言编写并在不同平台上运行的应用程序之间交换数据时Protobuf 编码可提高效率。
![metrics and data shown on a computer screen][1]
![](https://img.linux.net.cn/data/attachment/album/201911/22/075757pn2fxfth30ntwefg.jpg)
<ruby>协议缓冲区<rt>Protocol Buffers
</rt></ruby>[Protobufs][2])像 XML 和 JSON 一样,可以让用不同语言编写并在不同平台上运行的应用程序交换数据。例如,用 Go 编写的发送应用程序可以在 Protobuf 中对 Go 特定的销售订单进行编码,然后用 Java 编写的接收方可以对它进行解码,以获取所接收订单的 Java 特定表示方式。这是在网络连接上的体系结构示意图:
<ruby>协议缓冲区<rt>Protocol Buffers</rt></ruby>[Protobufs][2])像 XML 和 JSON 一样,可以让用不同语言编写并在不同平台上运行的应用程序交换数据。例如,用 Go 编写的发送程序可以在 Protobuf 中对以 Go 表示的销售订单数据进行编码,然后用 Java 编写的接收方可以对它进行解码,以获取所接收订单数据的 Java 表示方式。这是在网络连接上的结构示意图:
```
Go sales order--->Pbuf-encode--->network--->Pbuf-decode--->Java sales order
```
> Go 销售订单 ---> Pbuf 编码 ---> 网络 ---> Pbuf 界面 ---> Java 销售订单
与 XML 和 JSON 相比Protobuf 编码是二进制而不是文本这会使调试复杂化。但是正如本文中的代码示例所确认的那样Protobuf 编码在大小上比 XML 或 JSON 编码要有效得多。
Protobuf 以另一种方式提供了这种有效性。在实现级别Protobuf 和其他编码系统对结构化数据进行序列化和反序列化。序列化将特定语言的数据结构转换为字节流,反序列化是将字节流转换回特定语言的数据结构的逆运算。序列化和反序列化可能成为数据交换的瓶颈,因为这些操作会占用大量 CPU。高效的序列化和反序列化是 Protobuf 的另一个设计目标。
Protobuf 以另一种方式提供了这种有效性。在实现级别Protobuf 和其他编码系统对结构化数据进行<ruby>序列化<rt>serialize</rt></ruby><ruby>反序列化<rt>deserialize</rt></ruby>。序列化将特定语言的数据结构转换为字节流,反序列化是将字节流转换回特定语言的数据结构的逆运算。序列化和反序列化可能成为数据交换的瓶颈,因为这些操作会占用大量 CPU。高效的序列化和反序列化是 Protobuf 的另一个设计目标。
最近的编码技术,例如 Protobuf 和 FlatBuffers源自 1990 年代初期的 [DCE/RPC][3]<ruby>分布式计算环境/远程过程调用<rt>Distributed Computing Environment/Remote Procedure Call</rt></ruby>)计划。与 DCE/RPC 一样Protobuf 在数据交换中为 [IDL][4](接口定义语言)和编码层做出了贡献。
@ -47,29 +44,27 @@ interface echo {
}
```
该 IDL 文档声明了一个名为 `echo` 的过程,该过程带有三个参数:类型为 `handle_t`(实现指针)和 `idl_char`ASCII 字符数组)的 `[in]` 参数被传递给远程过程,而 `[out]` 参数(也是一个字符串)从该过程中传回。在此示例中,`echo` 过程不会显式返回值(`echo` 左侧的 `void`),但也可以返回。返回值,以及一个或多个 `[out]` 参数,允许远程过程任意返回许多值。下一节将介绍 Protobuf IDL它的语法不同但同样用作数据交换中的协定。
该 IDL 文档声明了一个名为 `echo` 的过程,该过程带有三个参数:类型为 `handle_t`(实现指针)和 `idl_char`ASCII 字符数组)的 `[in]` 参数被传递给远程过程,而 `[out]` 参数(也是一个字符串)从该过程中传回。在此示例中,`echo` 过程不会显式返回值(`echo` 左侧的 `void`),但也可以返回。返回值,以及一个或多个 `[out]` 参数,允许远程过程任意返回许多值。下一节将介绍 Protobuf IDL它的语法不同但同样用作数据交换中的协定。
DCE/RPC 和 Protobuf 中的 IDL 文档是创建用于交换数据的基础结构代码的实用程序的输入:
```
IDL document--->DCE/PRC or Protobuf utilities--->support code for data interchange
```
> IDL 文档 ---> DCE/PRC 或 Protobuf 实用程序 ---> 数据交换的支持代码
作为相对简单的文本IDL 同样是关于数据交换的细节的便于人类阅读的文档(特别是交换的数据项的数量和每个项的数据类型)。
作为相对简单的文本IDL 是同样便于人类阅读的关于数据交换细节的文档(特别是交换的数据项的数量和每个项的数据类型)。
Protobuf 可用于现代 RPC 系统,例如 [gRPC][5];但是 Protobuf 本身仅提供 IDL 层和编码层,用于从发送者传递到接收者的消息。与原的 DCE/RPC 一样Protobuf 编码是二进制的,但效率更高。
Protobuf 可用于现代 RPC 系统,例如 [gRPC][5];但是 Protobuf 本身仅提供 IDL 层和编码层,用于从发送者传递到接收者的消息。与原的 DCE/RPC 一样Protobuf 编码是二进制的,但效率更高。
目前XML 和 JSON 编码仍在通过 Web 服务等技术进行的数据交换中占主导地位,这些技术利用 Web 服务器、传输协议(例如 TCP、HTTP以及标准库和实用程序等原有的基础设施来处理 XML 和 JSON 文档。 此外,各种类型的数据库系统可以存储 XML 和 JSON 文档,甚至旧式关系型系统也可以轻松生成查询结果的 XML 编码。现在,每种通用编程语言都具有支持 XML 和 JSON 的库。那么,是什么建议我们回到 Protobuf 之类的**二进制**编码系统呢?
目前XML 和 JSON 编码仍在通过 Web 服务等技术进行的数据交换中占主导地位,这些技术利用 Web 服务器、传输协议(例如 TCP、HTTP以及标准库和实用程序等原有的基础设施来处理 XML 和 JSON 文档。 此外,各种类型的数据库系统可以存储 XML 和 JSON 文档,甚至旧式关系型系统也可以轻松生成查询结果的 XML 编码。现在,每种通用编程语言都具有支持 XML 和 JSON 的库。那么,是什么我们回到 Protobuf 之类的**二进制**编码系统呢?
让我们看一下负十进制值 `-128` 2 的补码二进制表示形式(在系统和语言中占主导地位)中,此值可以存储在单个 8 位字节中:`10000000`。此整数值在 XML 或 JSON 中的文本编码需要多个字节。例如UTF-8 编码需要四个字节的字符串,即 `-128`,即每个字符一个字节(十六进制,值为 `0x2d`、`0x31`、`0x32` 和 `0x38`。XML 和 JSON 还添加了标记字符,例如尖括号和大括号。有关 Protobuf 编码的详细信息下面就会介绍,但现在的关注点是一个通用点:文本编码的压缩性明显低于二进制编码。
让我们看一下负十进制值 `-128` 2 的补码二进制表示形式(在系统和语言中占主导地位)中,此值可以存储在单个 8 位字节中:`10000000`。此整数值在 XML 或 JSON 中的文本编码需要多个字节。例如UTF-8 编码需要四个字节的字符串,即 `-128`,即每个字符一个字节(十六进制,值为 `0x2d`、`0x31`、`0x32` 和 `0x38`。XML 和 JSON 还添加了标记字符,例如尖括号和大括号。有关 Protobuf 编码的详细信息下面就会介绍,但现在的关注点是一个通用点:文本编码的压缩性明显低于二进制编码。
### 在 Go 中使用 Protobuf 的示例
我的代码示例着重于 Protobuf 而不是 RPC。以下是第一个示例的概述
* 名为 `dataitem.proto` 的 IDL 文件定义了一个 Protobuf 消息,它具有六个不同类型的字段:具有不同范围的整数值、固定大小的浮点值以及两个不同长度的字符串。
* Protobuf 编译器使用 IDL 文件生成 Protobuf 消息及支持函数的 Go 特定版本(以及后来的 Java 特定版本)
* Go 应用程序使用随机生成的值填充原生 Go 数据结构,然后将结果序列化为本地文件。为了进行比较, XML 和 JSON 编码也被序列化为本地文件。
* Protobuf 编译器使用 IDL 文件生成 Go 版本(以及后面的 Java 版本)的 Protobuf 消息及支持函数
* Go 应用程序使用随机生成的值填充原生 Go 数据结构,然后将结果序列化为本地文件。为了进行比较, XML 和 JSON 编码也被序列化为本地文件。
* 作为测试Go 应用程序通过反序列化 Protobuf 文件的内容来重建其原生数据结构的实例。
* 作为语言中立性测试Java 应用程序还会对 Protobuf 文件的内容进行反序列化以获取原生数据结构的实例。
@ -96,7 +91,7 @@ message DataItem {
}
```
该 IDL 使用当前的 proto3 而不是较早的 proto2 语法。软件包名称(在本例中为 `main`)是可选的,但是惯用的;它用于避免名称冲突。这个结构化的消息包含八个字段,每个字段都有一个 Protobuf 数据类型(例如,`int64`、`string`)、名称(例如,`oddA`、`short`)和一个等号 `=` 之后的数字标签(即键)。标签(在此示例中为 1 到 8是唯一的整数标识符用于确定字段序列化的顺序。
该 IDL 使用当前的 proto3 而不是较早的 proto2 语法。软件包名称(在本例中为 `main`)是可选的,但是惯例使用它以避免名称冲突。这个结构化的消息包含八个字段,每个字段都有一个 Protobuf 数据类型(例如,`int64`、`string`)、名称(例如,`oddA`、`short`)和一个等号 `=` 之后的数字标签(即键)。标签(在此示例中为 1 到 8是唯一的整数标识符用于确定字段序列化的顺序。
Protobuf 消息可以嵌套到任意级别,而一个消息可以是另外一个消息的字段类型。这是一个使用 `DataItem` 消息作为字段类型的示例:
@ -118,7 +113,7 @@ enum PartnershipStatus {
`reserved` 限定符确保用于实现这三个符号名的数值不能重复使用。
为了生成一个或多个声明 Protobuf 消息结构的特定于语言的版本,包含这些结构的 IDL 文件被传递到`protoc` 编译器(可在 [Protobuf GitHub 存储库][7]中找到)。对于 Go 代码,可以以通常的方式安装支持的 Protobuf 库(这里以 `` 作为命令行提示符):
为了生成一个或多个声明 Protobuf 消息结构的特定于语言的版本,包含这些结构的 IDL 文件被传递到`protoc` 编译器(可在 [Protobuf GitHub 存储库][7]中找到)。对于 Go 代码,可以以通常的方式安装支持的 Protobuf 库(这里以 `` 作为命令行提示符):
```
% go get github.com/golang/protobuf/proto
@ -130,7 +125,7 @@ enum PartnershipStatus {
% protoc --go_out=. dataitem.proto
```
标志 `--go_out` 指示编译器生成 Go 源代码。其他语言也有类似的标志。在这种情况下,结果是一个名为 `dataitem.pb.go` 的文件,该文件足够小,可以将基本内容复制到 Go 应用程序中。以下是生成的代码的主要部分:
标志 `--go_out` 指示编译器生成 Go 源代码。其他语言也有类似的标志。在这种情况下,结果是一个名为 `dataitem.pb.go` 的文件,该文件足够小,可以将基本内容复制到 Go 应用程序中。以下是生成的代码的主要部分:
```
var _ = proto.Marshal
@ -152,7 +147,7 @@ func (*DataItem) ProtoMessage() {}
func init() {}
```
编译器生成的代码具有 Go 结构 `DataItem`,该结构导出 Go 字段(名称现已大写开头),该字段与 Protobuf IDL 中声明的名称匹配。该结构字段具有标准的 Go 数据类型:`int32`、`int64`、`float32` 和 `string`。在每个字段行的末尾,是描述 Protobuf 类型的字符串,提供 Protobuf IDL 文档中的数字标签并提供有关 JSON 信息的元数据,这将在后面讨论。
编译器生成的代码具有 Go 结构 `DataItem`,该结构导出 Go 字段(名称现已大写开头),该字段与 Protobuf IDL 中声明的名称匹配。该结构字段具有标准的 Go 数据类型:`int32`、`int64`、`float32` 和 `string`。在每个字段行的末尾,是描述 Protobuf 类型的字符串,提供 Protobuf IDL 文档中的数字标签有关 JSON 信息的元数据,这将在后面讨论。
此外也有函数;最重要的是 `Proto.Marshal`,用于将 `DataItem` 结构的实例序列化为 Protobuf 格式。辅助函数包括:清除 `DataItem` 结构的 `Reset`,生成 `DataItem` 的单行字符串表示的 `String`
@ -162,7 +157,7 @@ func init() {}
Protobuf 消息的结构为键/值对的集合,其中数字标签为键,相应的字段为值。字段名称(例如,`oddA` 和 `small`)是供人类阅读的,但是 `protoc` 编译器的确使用了字段名称来生成特定于语言的对应名称。例如Protobuf IDL 中的 `oddA``small` 名称在 Go 结构中分别成为字段 `OddA``Small`
键和它们的值都被编码,但是有一个重要的区别:一些数字值具有固定大小的 32 或 64 位的编码,而其他数字(包括消息标签)则是 `varint` 编码的,位数取决于整数的绝对值。例如,整数值 1 到 15 需要 8 位 `varint` 编码,而值 16 到 2047 需要 16 位。`varint` 编码在本质上与 UTF-8 编码类似(但细节不同),它偏爱较小的整数值而不是较大的整数值。(有关详细分析,请参见 Protobuf [编码指南][8]结果是Protobuf 消息应该在字段中具有较小的整数值(如果可能),并且键数应尽可能少,但每个字段只有一个键是必不可少的
键和它们的值都被编码,但是有一个重要的区别:一些数字值具有固定大小的 32 或 64 位的编码,而其他数字(包括消息标签)则是 `varint` 编码的,位数取决于整数的绝对值。例如,整数值 1 到 15 需要 8 位 `varint` 编码,而值 16 到 2047 需要 16 位。`varint` 编码在本质上与 UTF-8 编码类似(但细节不同),它偏爱较小的整数值而不是较大的整数值。(有关详细分析,请参见 Protobuf [编码指南][8]结果是Protobuf 消息应该在字段中具有较小的整数值(如果可能),并且键数应尽可能少,但每个字段至少得有一个键
下表 1 列出了 Protobuf 编码的要点:
@ -184,32 +179,32 @@ message DataItems {
}
```
`repeated` 表示 `DataItem` 实例是*打包的*:集合具有单个标签,在这种情况下为 1。因此具有重复的 `DataItem` 实例的 `DataItems` 消息比具有多个但单独的 `DataItem` 字段每个字段都需要自己的标签的消息的效率更高。
`repeated` 表示 `DataItem` 实例是*打包的*:集合具有单个标签,在这里是 1。因此具有重复的 `DataItem` 实例的 `DataItems` 消息比具有多个但单独的 `DataItem` 字段每个字段都需要自己的标签的消息的效率更高。
考虑到这一背景,让我们回到 Go 程序。
了解了这一背景,让我们回到 Go 程序。
### dataItem 程序的细节
`dataItem` 程序创建一个 `DataItem` 实例并使用适当类型的随机生成的值填充字段。Go 有一个 `rand` 包,带有用于生成伪随机整数和浮点值的函数,而我的 `randString` 函数可以从字符集中生成指定长度的伪随机字符串。设计目标是要有一个具有不同类型和位大小的字段值的 `DataItem` 实例。例如,`OddA` 和 `EvenA` 值分别是奇偶校验的 64 位非负整数值;但是 `OddB``EvenB` 变体的大小为 32 位,并存放 0 到 2047 之间的小整数值。随机浮点值的大小为 32 位,字符串为 16`Short`)和 32`Long`)字符的长度。这是用随机值填充 `DataItem` 结构的代码段:
`dataItem` 程序创建一个 `DataItem` 实例并使用适当类型的随机生成的值填充字段。Go 有一个 `rand` 包,带有用于生成伪随机整数和浮点值的函数,而我的 `randString` 函数可以从字符集中生成指定长度的伪随机字符串。设计目标是要有一个具有不同类型和位大小的字段值的 `DataItem` 实例。例如,`OddA` 和 `EvenA` 值分别是 64 位非负整数值的奇数和偶数;但是 `OddB``EvenB` 变体的大小为 32 位,并存放 0 到 2047 之间的小整数值。随机浮点值的大小为 32 位,字符串为 16`Short`)和 32`Long`)字符的长度。这是用随机值填充 `DataItem` 结构的代码段:
```
// variable-length integers
n1 := rand.Int63() // bigger integer
if (n1 & 1) == 0 { n1++ } // ensure it's odd
// 可变长度整数
n1 := rand.Int63() // 大整数
if (n1 & 1) == 0 { n1++ } // 确保其是奇数
...
n3 := rand.Int31() % UpperBound // smaller integer
if (n3 & 1) == 0 { n3++ } // ensure it's odd
n3 := rand.Int31() % UpperBound // 小整数
if (n3 & 1) == 0 { n3++ } // 确保其是奇数
// fixed-length floats
// 固定长度浮点数
...
t1 := rand.Float32()
t2 := rand.Float32()
...
// strings
// 字符串
str1 := randString(StrShort)
str2 := randString(StrLong)
// the message
// 消息
dataItem := &DataItem {
OddA: n1,
EvenA: n2,
@ -237,7 +232,7 @@ func encodeAndserialize(dataItem *DataItem) {
}
```
这三个序列化函数使用术语 `marshal`,它与 `serialize` 意思大致相同。如代码所示,三个 `Marshal` 函数均返回一个字节数组,然后将其写入文件。(为简单起见,可能的错误将被忽略处理。)在示例运行中,文件大小为:
这三个序列化函数使用术语 `marshal`,它与 `serialize` 意思大致相同。如代码所示,三个 `Marshal` 函数均返回一个字节数组,然后将其写入文件。(为简单起见,忽略可能的错误处理。)在示例运行中,文件大小为:
```
dataitem.xml:  262 bytes
@ -266,7 +261,7 @@ Protobuf 编码明显小于其他两个编码方案。通过消除缩进字符
### 测试序列化和反序列化
Go 程序接下来通过将先前写入 `dataitem.pbuf` 文件的字节反序列化为 `DataItem` 实例来运行基本测试。这是代码段,其中去了错误检查部分:
Go 程序接下来通过将先前写入 `dataitem.pbuf` 文件的字节反序列化为 `DataItem` 实例来运行基本测试。这是代码段,其中去了错误检查部分:
```
filebytes, err := ioutil.ReadFile(PbufFile) // get the bytes from the file
@ -291,7 +286,7 @@ boPb#T0O8Xd&Ps5EnSZqDg4Qztvo7IIs 9vH66AiGSQgCDxk&
### 一个 Java Protobuf 客户端
Java 中的示例是为了确认 Protobuf 的语言中立性。原始 IDL 文件可用于生成 Java 支持代码,其中涉及嵌套类。但是,为了抑制警告信息,可以进行一些补充。这是修订版,它指定了一个 `DataMsg` 作为外部类的名称,内部类在 Protobuf 消息后自动命名为 `DataItem`
用 Java 写的示例是为了确认 Protobuf 的语言中立性。原始 IDL 文件可用于生成 Java 支持代码,其中涉及嵌套类。但是,为了抑制警告信息,可以进行一些补充。这是修订版,它指定了一个 `DataMsg` 作为外部类的名称,内部类在 Protobuf 消息后自动命名为 `DataItem`
```
syntax = "proto3";
@ -304,7 +299,7 @@ message DataItem {
...
```
进行此更改后,`protoc` 编译与以前相同,只是所期的输出现在是 Java 而不是 Go
进行此更改后,`protoc` 编译与以前相同,只是所期的输出现在是 Java 而不是 Go
```
% protoc --java_out=. dataitem.proto
@ -333,11 +328,11 @@ public class Main {
}
```
当然,生产级的测试将更加彻底,但是即使是该初步测试也可以证明 Protobuf 的语言中立性:`dataitem.pbuf` 文件是 Go 程序对 Go `DataItem` 进行序列化的结果,并且该文件中的字节被反序列化以在 Java 中产生一个 `DataItem` 实例。Java 测试的输出与 Go 测试的输出相同。
当然,生产级的测试将更加彻底,但是即使是该初步测试也可以证明 Protobuf 的语言中立性:`dataitem.pbuf` 文件是 Go 程序对 Go 语言版的 `DataItem` 进行序列化的结果,并且该文件中的字节被反序列化以产生一个 Java 语言的 `DataItem` 实例。Java 测试的输出与 Go 测试的输出相同。
### 用 numPairs 程序来结束
让我们以一个突出 Protobuf 效率但又强调在任何编码技术中都会涉及到的成本的示例作为结尾。考虑以下 Protobuf IDL 文件:
让我们以一个示例作为结尾,来突出 Protobuf 效率但又强调在任何编码技术中都会涉及到的成本。考虑以下 Protobuf IDL 文件:
```
syntax = "proto3";
@ -438,11 +433,10 @@ func main() {
}
```
每个 `NumPair` 中随机生成的奇数和偶数值的范围在 0 到 20 亿之间变化。就原始数据而非编码数据而言Go 程序中生成的整数加起来为 16MB每个 `NumPair` 为两个整数,总计为 400 万个整数,每个值的大小为四个字节。
每个 `NumPair` 中随机生成的奇数和偶数值的范围在 0 到 20 亿之间变化。就原始数据而非编码数据而言Go 程序中生成的整数总共为 16MB每个 `NumPair` 为两个整数,总计为 400 万个整数,每个值的大小为四个字节。
为了进行比较,下表列出了 XML、JSON 和 Protobuf 编码的示例 `NumsPairs` 消息的 200 万个 `NumPair` 实例。原始数据也包括在内。由于 `numPairs` 程序生成随机值,因此样本运行的输出有所不同,但接近表中显示的大小。
编码 | 文件 | 字节大小 | Pbuf/其它 比例
---|---|---|---
无 | pairs.raw | 16MB | 169%
@ -452,9 +446,9 @@ XML | pairs.xml | 126MB | 21%
*表 2. 16MB 整数的编码开销*
不出所料Protobuf 和之后的 XML 和 JSON 差别明显。Protobuf 编码大约是 JSON 的四分之一,是 XML 的五分之一。但是原始数据清楚地表明 Protobuf 会产生编码开销:序列化的 Protobuf 消息比原始数据大 11MB。包括 Protobuf 在内的任何编码都涉及结构化数据,这不可避免地会增加字节。
不出所料Protobuf 和之后的 XML 和 JSON 差别明显。Protobuf 编码大约是 JSON 的四分之一,是 XML 的五分之一。但是原始数据清楚地表明 Protobuf 会产生编码开销:序列化的 Protobuf 消息比原始数据大 11MB。包括 Protobuf 在内的任何编码都涉及结构化数据,这不可避免地会增加字节。
序列化的 200 万个 `NumPair` 实例中的每个实例都包含**四**个整数值Go 结构中的 `Even``Odd` 字段分别一个,而 Protobuf 编码中的每个字段每个标签一个。作为原始数据而不是编码数据,每个实例将达到 16 个字节,样本 `NumPairs` 消息中有 200 万个实例。但是 Protobuf 标记(如 `NumPair` 字段中的 `int32` 值)使用 `varint` 编码,因此字节长度有所不同。特别是,小的整数值(在这种情况下,包括标签在内)需要不到四个字节进行编码。
序列化的 200 万个 `NumPair` 实例中的每个实例都包含**四**个整数值Go 结构中的 `Even``Odd` 字段分别一个,而 Protobuf 编码中的每个字段、每个标签一个。对于原始数据(而不是编码数据),每个实例将达到 16 个字节,样本 `NumPairs` 消息中有 200 万个实例。但是 Protobuf 标记(如 `NumPair` 字段中的 `int32` 值)使用 `varint` 编码,因此字节长度有所不同。特别是,小的整数值(在这种情况下,包括标签在内)需要不到四个字节进行编码。
如果对 `numPairs` 程序进行了修改,以使两个 `NumPair` 字段的值小于 2048且其编码为一或两个字节则 Protobuf 编码将从 27MB 下降到 16MB这正是原始数据的大小。下表总结了样本运行中的新编码大小。
@ -467,7 +461,7 @@ XML | pairs.xml | 103MB | 15%
*表 3. 编码 16MB 的小于 2048 的整数*
总之,修改后的 `numPairs` 程序的字段值小于 2048可减少原始数据中每个整数值的四字节大小。但是 Protobuf 编码仍然需要标签,这些标签会在 Protobuf 消息中添加字节。Protobuf 编码确实会增加消息大小,但是如果要编码相对较小的整数值(无论是字段还是键),则可以通过 `varint` 因子来减少此开销。
总之,修改后的 `numPairs` 程序的字段值小于 2048可减少原始数据中每个四字节整数值的大小。但是 Protobuf 编码仍然需要标签,这些标签会在 Protobuf 消息中添加字节。Protobuf 编码确实会增加消息大小,但是如果要编码相对较小的整数值(无论是字段还是键),则可以通过 `varint` 因子来减少此开销。
对于包含混合类型的结构化数据且整数值相对较小的中等大小的消息Protobuf 明显优于 XML 和 JSON 等选项。在其他情况下,数据可能不适合 Protobuf 编码。例如,如果两个应用程序需要共享大量文本记录或大整数值,则可以采用压缩而不是编码技术。
@ -478,7 +472,7 @@ via: https://opensource.com/article/19/10/protobuf-data-interchange
作者:[Marty Kalin][a]
选题:[lujun9972][b]
译者:[wxy](https://github.com/wxy)
校对:[校对者ID](https://github.com/校对者ID)
校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出

View File

@ -1,8 +1,8 @@
[#]: collector: (lujun9972)
[#]: translator: (guevaraya)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: reviewer: (wxy)
[#]: publisher: (wxy)
[#]: url: (https://linux.cn/article-11598-1.html)
[#]: subject: (Getting Started With ZFS Filesystem on Ubuntu 19.10)
[#]: via: (https://itsfoss.com/zfs-ubuntu/)
[#]: author: (John Paul https://itsfoss.com/author/john/)
@ -10,54 +10,51 @@
在 Ubuntu 19.10 上入门 ZFS 文件系统
======
[Ubuntu 19.01][1] 的一个主要新特性就是 [ZFS][2]。现在你可以很容易的不要太多操作就可以在 Ubuntu 系统上安装 ZFS了。
![][4]
一般情况下,安装 Linux 都会选择 Ext4 文件系统。但是如果是安装 Ubuntu 19.10,在启动阶段可以看到 ZFS 选项。但你绝对不能在双系统上用它,因为它会擦除这个磁盘。
Ubuntu 19.10 的主要新特性之一就是 [ZFS][2]。现在你可以很容易的无需额外努力就可以在 Ubuntu 系统上安装 ZFS了。
一般情况下,安装 Linux 都会选择 Ext4 文件系统。但是如果是全新安装 Ubuntu 19.10,在安装的启动阶段可以看到 ZFS 选项。
![你可以在安装 Ubuntu 19.10 的时候选择 ZFS][3]
让我们看看 ZFS 有多重要以及如何在已经安装 ZFS 的 Ubuntu 上使用它。
让我们看看 ZFS 为何重要,以及如何在已经安装了 ZFS 的 Ubuntu 上使用它。
### ZFS 与其他文件系统有哪些区别?
ZFS 的设计初衷是处理海量存储和避免数据损坏。ZFS 可以处理 256 千万亿的泽它字节(ZB)数据。这就是ZFS的Z且它可以处理最大16艾字节EB的文件。
ZFS 的设计初衷是处理海量存储和避免数据损坏。ZFS 可以处理 256 千万亿的 ZB 数据。(这就是 ZFS 的 Z且它可以处理最大 16 EB 的文件。
如果你仅有一个单磁盘的笔记本电脑,你可以体验 ZFS 的数据保护特性。即写及时拷贝特性确保正在使用的数据不会被覆盖相反新的数据会被写到一个新的块中同时文件系统的元数据会被更新到新块中。ZFS 可容易的创建文件系统的快照。这个快照可追踪文件系统的更改,并共享数据块确保节省数据空间。
如果你仅有一个单磁盘的笔记本电脑,你可以体验 ZFS 的数据保护特性。写时复制COW特性确保正在使用的数据不会被覆盖相反新的数据会被写到一个新的块中同时文件系统的元数据会被更新到新块中。ZFS 可容易的创建文件系统的快照。这个快照可追踪文件系统的更改,并共享数据块确保节省数据空间。
ZFS 为磁盘上的每个文件分配一个校验和。它会不断的校验文件的状态和校验和。如果发现文件被损坏了,它就会尝试修复文件。
我写过一个文章详细介绍 [什么是 ZFS以及它有哪些特性][2].如果你感兴趣可以去阅读下。
我写过一个文章详细介绍 [什么是 ZFS以及它有哪些特性][2]如果你感兴趣可以去阅读下。
注:
请谨记 ZFS 的数据保护特性会导致性能下降。
注:请谨记 ZFS 的数据保护特性会导致性能下降。
### Ubuntu 下使用 ZFS [适用于中高级用户]
![][4]
一旦你在你的主磁盘上全新安装了带有 ZFS 的 Ubuntu你就可以开始体验它的特性。
一旦你在你的主磁盘上干净安装了 Ubuntu 的 ZFS你就可以开始体验它的特性。
请注意安装 ZFS 这个过程需要命令行。我还没用过它的 GUI 工具。
请注意所有的 ZFS 设置过程都需要命令行。我不知道它有任何 GUI 工具。
#### 创建一个 ZFS 池
_**这段仅针对拥有多个磁盘的系统。如果你只有一个磁盘Ubuntu会在安装的时候自动创建池。**_
**这段仅针对拥有多个磁盘的系统。如果你只有一个磁盘Ubuntu 会在安装的时候自动创建池。**
在创建池之前,你需要为池找到磁盘的id。你可以用命令 _**lsblk**_ 查询出这个信息。
在创建池之前,你需要为池找到磁盘的 id。你可以用命令 `lsblk` 查询出这个信息。
为三个磁盘创建一个基础池,用以下命令:
```
sudo zpool create pool-test /dev/sdb /dev/sdc /dev/sdd.
sudo zpool create pool-test /dev/sdb /dev/sdc /dev/sdd
```
请记得替换 _**pool-test**_ 为你自己的命名
请记得替换 `pool-test` 为你选择的的命名。
这个命令将会设置“无冗余 RAID-0 池”。这意味着如果一个磁盘被破坏或有故障,你将会丢失数据。如果你执行以上命令,还是建议做一个常规备份。
你也可以增加一个磁盘到池,用下面命令:
你可以用下面命令将另一个磁盘增加到池中:
```
sudo zpool add pool-name /dev/sdx
@ -75,9 +72,9 @@ sudo zpool status pool-test
#### 镜像一个 ZFS 池
确保数据的安全性,你可以创建镜像。镜像意味着每个磁盘包含同样的数据。在创建镜像的磁盘上三个磁盘坏掉两个仍然可以不丢数据
确保数据的安全性,你可以创建镜像。镜像意味着每个磁盘包含同样的数据。使用镜像设置,你可能会丢失三个磁盘中的两个,并且仍然拥有所有信息
创建镜像你可以用下面命令:
创建镜像你可以用下面命令:
```
sudo zpool create pool-test mirror /dev/sdb /dev/sdc /dev/sdd
@ -85,7 +82,7 @@ sudo zpool create pool-test mirror /dev/sdb /dev/sdc /dev/sdd
#### 创建 ZFS 用于备份恢复的快照
快照可以是一个需要备份的时间点以防某个文件被删除或被覆盖。比如,我们创建一个快照,当在用户主目录下删除一些目录后,然后把恢复。
快照允许你创建一个后备,以防某个文件被删除或被覆盖。比如,我们创建一个快照,当在用户主目录下删除一些目录后,然后把恢复。
首先,你需要找到你想要的快照数据集。你可以这样做:
@ -95,31 +92,31 @@ zfs list
![Zfs List][7]
你可以看到我的目录位于 **rpool/USERDATA/johnblood_uwcjk7**
你可以看到我的家目录位于 `rpool/USERDATA/johnblood_uwcjk7`
我们用下面命令创建一个名叫 **1910** 的快照:
我们用下面命令创建一个名叫 `1910` 的快照:
```
sudo zfs snapshot rpool/USERDATA/[email protected]
sudo zfs snapshot rpool/USERDATA/johnblood_uwcjk7@1019
```
快照很快创建完成。现在你可以删除 _Downloads__Documents_ 目录。
快照很快创建完成。现在你可以删除 `Downloads``Documents` 目录。
现在你用以下命令恢复快照:
```
sudo zfs rollback rpool/USERDATA/[email protected]
sudo zfs rollback rpool/USERDATA/johnblood_uwcjk7@1019
```
回滚的数据大小取决于有多少信息改变。现在你可以查看用户目录和被删目录(和它的内容)将会被恢复过来。
回滚的时间长短取决于有多少信息改变。现在你可以查看家目录,被删除的目录(和它的内容)将会被恢复过来。
### 要不要试试 ZFS
这篇文章仅简单介绍的 Ubuntu下 ZFS 的用法。更多的信息请参考 [ Ubuntu 的ZFS Wiki页面][5] 我也推荐阅读 [ArsTechnica的精彩文章][8]。
这篇文章仅简单介绍的 Ubuntu下 ZFS 的用法。更多的信息请参考 [Ubuntu 的 ZFS Wiki页面][5]。我也推荐阅读 [ArsTechnica 的精彩文章][8]。
这个是试验性的功能。如果你还不了解 ZFS你想用一个简单稳定的系统请安装标准文件系统 EXT4。如果你想用闲置的机器体验可以参照上面了解 ZFS。如果你是一个‘专家’,你知道你在做什么,那就可以随便咋搞
这个是试验性的功能。如果你还不了解 ZFS你想用一个简单稳定的系统请安装标准文件系统 EXT4。如果你想用闲置的机器体验可以参照上面了解 ZFS。如果你是一个“专家”并且知道自己在做什么则可以随时随地随意尝试ZFS
你之前用过 ZFS 吗?请在下面留言。如果你觉得这个文章还可以,请分享到社交媒体,黑客新闻或 [Reddit][9]。
你之前用过 ZFS 吗?请在下面留言。
--------------------------------------------------------------------------------
@ -128,7 +125,7 @@ via: https://itsfoss.com/zfs-ubuntu/
作者:[John Paul][a]
选题:[lujun9972][b]
译者:[guevaraya](https://github.com/guevaraya)
校对:[校对者ID](https://github.com/校对者ID)
校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
@ -159,7 +156,7 @@ via: https://itsfoss.com/zfs-ubuntu/
[a]: https://itsfoss.com/author/john/
[b]: https://github.com/lujun9972
[1]: https://itsfoss.com/ubuntu-19-04-release-features/
[2]: https://itsfoss.com/what-is-zfs/
[2]: https://linux.cn/article-10034-1.html
[3]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2019/05/zfs-ubuntu-19-10.jpg?ssl=1
[4]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2019/11/Using_ZFS_Ubuntu.jpg?resize=800%2C450&ssl=1
[5]: https://wiki.ubuntu.com/Kernel/Reference/ZFS

View File

@ -1,8 +1,8 @@
[#]: collector: (lujun9972)
[#]: translator: (geekpi)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: reviewer: (wxy)
[#]: publisher: (wxy)
[#]: url: (https://linux.cn/article-11597-1.html)
[#]: subject: (How to install and Configure Postfix Mail Server on CentOS 8)
[#]: via: (https://www.linuxtechi.com/install-configure-postfix-mailserver-centos-8/)
[#]: author: (James Kiarie https://www.linuxtechi.com/author/james/)
@ -10,9 +10,9 @@
如何在 CentOS 8 上安装和配置 Postfix 邮件服务器
======
**Postfix** 是一个免费的开源 **MTA**(邮件传输代理),用于在 Linux 系统上路由或传递电子邮件。在本指南中,你将学习如何在 CentOS 8 上安装和配置 Postfix。
Postfix 是一个自由开源的 MTA(邮件传输代理),用于在 Linux 系统上路由或传递电子邮件。在本指南中,你将学习如何在 CentOS 8 上安装和配置 Postfix。
[![Install-configure-Postfx-Server-CentOS8][1]][2]
![Install-configure-Postfx-Server-CentOS8][2]
实验室设置:
@ -20,8 +20,6 @@
* IP 地址192.168.1.13
* 主机名server1.crazytechgeek.info确保域名指向服务器的 IP
### 步骤 1更新系统
第一步是确保系统软件包是最新的。为此,请按如下所示更新系统:
@ -30,7 +28,7 @@
# dnf update
```
继续之前,还请确保不存在其他 **MTA**(如 **Sendmail**),因为这将导致与 Postfix 配置冲突。例如,要删除 Sendmail请运行以下命令
继续之前,还请确保不存在其他 MTA如 Sendmail因为这将导致与 Postfix 配置冲突。例如,要删除 Sendmail请运行以下命令
```
# dnf remove sendmail
@ -38,14 +36,14 @@
### 步骤 2设置主机名并更新 /etc/hosts
使用下面的 hostnamectl 命令在系统上设置主机名,
使用下面的 `hostnamectl` 命令在系统上设置主机名:
```
# hostnamectl set-hostname server1.crazytechgeek.info
# exec bash
```
此外,你需要在 /etc/hosts 中添加系统的主机名和 IP。
此外,你需要在 `/etc/hosts` 中添加系统的主机名和 IP
```
# vim /etc/hosts
@ -62,7 +60,7 @@
# dnf install postfix
```
[![Install-Postfix-Centos8][1]][3]
![Install-Postfix-Centos8][3]
### 步骤 4启动并启用 Postfix 服务
@ -73,29 +71,29 @@
# systemctl enable postfix
```
要检查 Postfix 状态,请运行以下 systemctl 命令
要检查 Postfix 状态,请运行以下 `systemctl` 命令
```
# systemctl status postfix
```
![Start-Postfix-check-status-centos8][1]
![Start-Postfix-check-status-centos8][9]
太好了,我们已经验证了 Postfix 已启动并正在运行。接下来,我们将配置 Postfix 从本地发送邮件到我们的服务器。
### 步骤 5安装 mailx 邮件客户端
在配置 Postfix 服务器之前,我们需要安装 mailx要安装它请运行以下命令
在配置 Postfix 服务器之前,我们需要安装 `mailx`,要安装它,请运行以下命令:
```
# dnf install mailx
```
![Install-Mailx-CentOS8][1]
![Install-Mailx-CentOS8][10]
### 步骤 6配置 Postfix 邮件服务器
Postfix 的配置文件位于 **/etc/postfix/main.cf** 中。我们需要对配置文件进行一些修改,因此请使用你喜欢的文本编辑器将其打开
Postfix 的配置文件位于 `/etc/postfix/main.cf` 中。我们需要对配置文件进行一些修改,因此请使用你喜欢的文本编辑器将其打开
```
# vi /etc/postfix/main.cf
@ -121,7 +119,7 @@ mynetworks = 192.168.1.0/24, 127.0.0.0/8
home_mailbox = Maildir/
```
完成后,保存并退出配置文件。重新启动 postfix 服务以使更改生效
完成后,保存并退出配置文件。重新启动 postfix 服务以使更改生效
```
# systemctl restart postfix
@ -136,7 +134,7 @@ home_mailbox = Maildir/
# passwd postfixuser
```
接下来,运行以下命令,从本地用户 **pkumar** 发送邮件到另一个用户 “**postfixuser**”
接下来,运行以下命令,从本地用户 `pkumar` 发送邮件到另一个用户 `postfixuser`
```
# telnet localhost smtp
@ -181,7 +179,7 @@ Escape character is '^]'.
250 SMTPUTF8
```
接下来,运行橙色高亮的命令,例如 “mail from”、“rcpt to”“data”最后输入 “quit”
接下来,运行橙色高亮的命令,例如 `mail from`、`rcpt to`、`data`,最后输入 `quit`
```
mail from:<pkumar>
@ -198,11 +196,11 @@ quit
Connection closed by foreign host
```
完成 telnet 命令可从本地用户 “**pkumar**” 发送邮件到另一个本地用户 “**postfixuser**”,如下所示:
完成 `telnet` 命令可从本地用户 `pkumar` 发送邮件到另一个本地用户 `postfixuser`,如下所示:
![Send-email-with-telnet-centos8][1]
![Send-email-with-telnet-centos8][11]
如果一切都按计划进行,那么你应该可以在新用户的家目录中查看发送的邮件
如果一切都按计划进行,那么你应该可以在新用户的家目录中查看发送的邮件
```
# ls /home/postfixuser/Maildir/new
@ -216,37 +214,37 @@ Connection closed by foreign host
# cat /home/postfixuser/Maildir/new/1573580091.Vfd02I20050b8M635437.server1.crazytechgeek.info
```
![Read-postfix-email-linux][1]
![Read-postfix-email-linux][12]
### Postfix 邮件服务器日志
Postfix 邮件服务器邮件日志保存在文件 “**/var/log/maillog**” 中,使用以下命令查看实时日志,
Postfix 邮件服务器邮件日志保存在文件 `/var/log/maillog` 中,使用以下命令查看实时日志,
```
# tail -f /var/log/maillog
```
![postfix-maillogs-centos8][1]
![postfix-maillogs-centos8][13]
### 保护 Postfix 邮件服务器
建议始终确保客户端和 postfix 服务器之间的通信安全,这可以使用 SSL 证书来实现,它们可以来自受信任的权威机构或自签名证书。在本教程中,我们将使用 **openssl** 命令生成用于 postfix 的自签名证书,
建议始终确保客户端和 Postfix 服务器之间的通信安全,这可以使用 SSL 证书来实现,它们可以来自受信任的权威机构或自签名证书。在本教程中,我们将使用 `openssl` 命令生成用于 Postfix 的自签名证书,
我假设 openssl 已经安装在你的系统上,如果未安装,请使用以下 dnf 命令,
我假设 `openssl` 已经安装在你的系统上,如果未安装,请使用以下 `dnf` 命令:
```
# dnf install openssl -y
```
使用下面的 openssl 命令生成私钥和 CSR证书签名请求
使用下面的 `openssl` 命令生成私钥和 CSR证书签名请求
```
# openssl req -nodes -newkey rsa:2048 -keyout mail.key -out mail.csr
```
![Postfix-Key-CSR-CentOS8][1]
![Postfix-Key-CSR-CentOS8][14]
现在,使用以下 openssl 命令生成自签名证书
现在,使用以下 openssl 命令生成自签名证书
```
# openssl x509 -req -days 365 -in mail.csr -signkey mail.key -out mail.crt
@ -256,13 +254,13 @@ Getting Private key
#
```
现在将私钥和证书文件复制到 /etc/postfix 目录下。
现在将私钥和证书文件复制到 `/etc/postfix` 目录下:
```
# cp mail.key mail.crt /etc/postfix
```
postfix 配置文件中更新私钥和证书文件的路径
Postfix 配置文件中更新私钥和证书文件的路径
```
# vi /etc/postfix/main.cf
@ -274,21 +272,21 @@ smtpd_tls_security_level = may
………
```
重启 postfix 服务以使上述更改生效。
重启 Postfix 服务以使上述更改生效:
```
# systemctl restart postfix
```
让我们尝试使用 mailx 客户端将邮件发送到内部本地域和外部域。
让我们尝试使用 `mailx` 客户端将邮件发送到内部本地域和外部域。
**从 pkumar 发送内部本地邮件到 postfixuser 中**
`pkumar` 发送内部本地邮件到 `postfixuser` 中:
```
# echo "test email" | mailx -s "Test email from Postfix MailServer" -r root@linuxtechi root@linuxtechi
```
使用以下命令检查并阅读邮件
使用以下命令检查并阅读邮件
```
# cd /home/postfixuser/Maildir/new/
@ -299,19 +297,19 @@ total 8
# cat 1573612845.Vfd02I20050bbM466643.server1.crazytechgeek.info
```
![Read-Postfixuser-Email-CentOS8][1]
![Read-Postfixuser-Email-CentOS8][15]
**从 postfixuser 发送邮件到外部域 ( [root@linuxtechi][4])**
`postfixuser` 发送邮件到外部域(`root@linuxtechi.com`
```
# echo "External Test email" | mailx -s "Postfix MailServer" -r root@linuxtechi root@linuxtechi
```
**注意:** 如果你的 IP 没有被任何地方列入黑名单,那么你发送到外部域的邮件将被发送,否则它将被退回,并提示你的 IP 被 spamhaus 之类的数据库列入黑名单。
注意:如果你的 IP 没有被任何地方列入黑名单,那么你发送到外部域的邮件将被发送,否则它将被退回,并提示你的 IP 被 spamhaus 之类的数据库列入黑名单。
### 检查 Postfix 邮件队列
使用mailq命令列出队列中的邮件。
使用 `mailq` 命令列出队列中的邮件:
```
# mailq
@ -321,13 +319,6 @@ Mail queue is empty
完成!我们的 Postfix 配置正常工作了!目前就这样了。我们希望你觉得本教程有见地,并且你可以轻松地设置本地 Postfix 服务器。
* [Facebook][5]
* [Twitter][6]
* [LinkedIn][7]
* [Reddit][8]
--------------------------------------------------------------------------------
via: https://www.linuxtechi.com/install-configure-postfix-mailserver-centos-8/
@ -335,7 +326,7 @@ via: https://www.linuxtechi.com/install-configure-postfix-mailserver-centos-8/
作者:[James Kiarie][a]
选题:[lujun9972][b]
译者:[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/) 荣誉推出
@ -345,7 +336,10 @@ via: https://www.linuxtechi.com/install-configure-postfix-mailserver-centos-8/
[2]: https://www.linuxtechi.com/wp-content/uploads/2019/11/Install-configure-Postfx-Server-CentOS8.jpg
[3]: https://www.linuxtechi.com/wp-content/uploads/2019/11/Install-Postfix-Centos8.png
[4]: https://www.linuxtechi.com/cdn-cgi/l/email-protection
[5]: http://www.facebook.com/sharer.php?u=https%3A%2F%2Fwww.linuxtechi.com%2Finstall-configure-postfix-mailserver-centos-8%2F&t=How%20to%20install%20and%20Configure%20Postfix%20Mail%20Server%20on%20CentOS%208
[6]: http://twitter.com/share?text=How%20to%20install%20and%20Configure%20Postfix%20Mail%20Server%20on%20CentOS%208&url=https%3A%2F%2Fwww.linuxtechi.com%2Finstall-configure-postfix-mailserver-centos-8%2F&via=Linuxtechi
[7]: http://www.linkedin.com/shareArticle?mini=true&url=https%3A%2F%2Fwww.linuxtechi.com%2Finstall-configure-postfix-mailserver-centos-8%2F&title=How%20to%20install%20and%20Configure%20Postfix%20Mail%20Server%20on%20CentOS%208
[8]: http://www.reddit.com/submit?url=https%3A%2F%2Fwww.linuxtechi.com%2Finstall-configure-postfix-mailserver-centos-8%2F&title=How%20to%20install%20and%20Configure%20Postfix%20Mail%20Server%20on%20CentOS%208
[9]: https://www.linuxtechi.com/wp-content/uploads/2019/11/Start-Postfix-check-status-centos8.png
[10]: https://www.linuxtechi.com/wp-content/uploads/2019/11/Install-Mailx-CentOS8.png
[11]: https://www.linuxtechi.com/wp-content/uploads/2019/11/Send-email-with-telnet-centos8.png
[12]: https://www.linuxtechi.com/wp-content/uploads/2019/11/Read-postfix-email-linux.png
[13]: https://www.linuxtechi.com/wp-content/uploads/2019/11/postfix-maillogs-centos8.png
[14]: https://www.linuxtechi.com/wp-content/uploads/2019/11/Postfix-Key-CSR-CentOS8.png
[15]: https://www.linuxtechi.com/wp-content/uploads/2019/11/Read-Postfixuser-Email-CentOS8.png

View File

@ -0,0 +1,79 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (The Cross-Platform Source Explorer Sourcetrail is Now Open Source)
[#]: via: (https://itsfoss.com/sourcetrail/)
[#]: author: (Ankush Das https://itsfoss.com/author/ankush/)
The Cross-Platform Source Explorer Sourcetrail is Now Open Source
======
[Sourcetrail][1] is a cross-platform source explorer that lets you visualize the unfamiliar source code by using graph visualization.
![][2]
In other words, it makes it easy to understand the structure of source code and how it works (technically) by visually representing them using a graph.
This is particularly helpful when you join a project and you have to work on existing code written in the past by several developers.
You can use it with your favorite IDE like Eclipse, IntelliJ IDEA, PyCharm or code editors like Atom, Visual Studio Code, Sublime Text etc. It supports C, C++, Java and Python.
This old video gives you the introduction to Sourcetrail:
Even though it was free for non-commercial use, they charged for a commercial license. However, they recently decided to make the whole thing free and open source.
So, yes, you can find their source code listed on [GitHub][3] now.
### What Has Changed for Sourcetrail?
The reason they switched as an open-source solution is that they wanted their tool to be accessible to more developers.
Their commercial licensing plan was supposed to help them make money however, it limited the reach of their project.
In their [announcement post][4], they mentioned their idea of this decision as follows:
> We have been going back and forth, discussing and testing potential solutions to many of those issues for a long time now. Many of our thoughts revolved around how to make more money and use it to solve those issues. Looking at other companies in the field, it seemed that to make more money, our only option was making our licenses more and more expensive, which in turn would limit our audience to fewer developers. We always dismissed the idea because **we started to make Sourcetrail to benefit as many developers as possible** and not to be a premium product for a few people in a handful of companies.
Also, they found it tough to provide cross-platform support while trying to reproduce the issues and apply a fix to them, especially for Linux distros. So, making their project open source was an ideal choice.
To further clarify the situation they also explained why their commercial licensing plan wasnt working out:
> Initially we received a couple of public grants that allowed us to launch Sourcetrail publicly. We decided to go down the traditional road of selling software licenses to sustain further development. Of course that meant to keep the code private if we wanted to protect our business…In retrospect, this decision really narrowed down our user base, making it hard for developers to start using Sourcetrail for multiple reasons
You can find all the details for what they plan for the future in their [announcement post][4].
### How to get Sourcetrail on Linux?
You can find and download the latest release of Sourcetrail on its release page on GitHub:
[Download Sourcetrail][5]
Extract the downloaded file and youll see a Sourcetrail.sh shell script. Run this script with sudo to install Sourcerail.
You should [read the documentation][6] for the project setup. They also have some [useful tutorial videos on their YouTube channel][7].
Sourcetrail was free before but now its free in the true sense. Its good to see that the developers have made it open source and now more programmers can use this tool to understand large, shared code base. You may also checkout a slightly similar open source tool [Sourcegraph][8].
--------------------------------------------------------------------------------
via: https://itsfoss.com/sourcetrail/
作者:[Ankush Das][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://itsfoss.com/author/ankush/
[b]: https://github.com/lujun9972
[1]: https://www.sourcetrail.com/
[2]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2019/11/sourcetrail-ui.png?ssl=1
[3]: https://github.com/CoatiSoftware/Sourcetrail
[4]: https://www.sourcetrail.com/blog/open_source/
[5]: https://github.com/CoatiSoftware/Sourcetrail/releases
[6]: https://www.sourcetrail.com/documentation/#PROJECTSETUP
[7]: https://www.youtube.com/channel/UCuKthdG-V4n2RZ1HDJhGVpQ/videos
[8]: https://itsfoss.com/sourcegraph/

View File

@ -0,0 +1,102 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (3 emerging open source projects to keep an eye on)
[#]: via: (https://opensource.com/article/19/11/emerging-projects)
[#]: author: (James Mawson https://opensource.com/users/dxmjames)
3 emerging open source projects to keep an eye on
======
Check out these early-stage open source projects that show real promise.
![One lightbulb lit out of several][1]
The exciting thing about open source is that nobody needs permission to try something new. That's a formula that allows new ideas to emerge all the time.
Here are three open source projects that are still in their early stages but show real promise.
### Glimpse
[Glimpse][2] is a recent fork of the [GNU Image Manipulation Program][3], a well-known and long-running open source project. It's unusual in that the biggest (but not the only) reason for forking is to rebrand it.
So what's wrong with the name GNU Image Manipulation Program? Well, it abbreviates as "gimp," and in large parts of the English-speaking world, that is a slang word with a variety of derogatory and sexual meanings.
Headlines have characterized the problem as "[the name is offensive][4]." I'm not sure that totally nails the issue—when I dug into it, I couldn't find anyone claiming strong offense.
What _does_ come up again and again is that people can't get a fair hearing for the application because of the name. In any kind of grown-up or professional context, the suggestion to use GIMP isn't taken seriously. For most of the world, there's probably little at stake in this, but English-speaking countries account for almost a quarter of the world's economy. That's not nothing.
Tech journalist Bryan Lunduke thinks [Glimpse isn't ideal branding, either][5], and perhaps he has a point. But for everyone who just wants the open source option to get a fair hearing, that's a second-order concern.
The Glimpse team has not declared any hostility to the parent project and has even shared some donation money upstream.
One of the exciting possibilities of this friendlier brand name is that it could open the software up as an option in education settings. This would be a win for the free software movement as a whole.
### The Editable PDF Initiative
Anyone with a desk job eventually learns the displeasure of using multiple software packages to put together a really complex document. It's one thing to write a quick letter or article in a word processor. But when you're jugging charts, graphs, tables, data, and images between applications, databases, and programming libraries, it can be quite a headache.
Often, people end up solving the problem by cutting-and-pasting things using the mouse—especially for the one-off jobs that crop up all the time. We do this manually, even when there are ways to automate the task, because the tools don't work the way we want them to, and different programs aren't written to talk to each other.
Dr. Tamir Hassan is a document engineering veteran on a one-man mission to fix this with the [Editable PDF Initiative][6]. It is an open, universal standard for document files that any program could use to interact with a document or its individual elements, such as images or tables.
Editable PDF aims to be an extension of existing PDF standards, which provide the only guarantee of consistent presentation across applications and devices. At the moment, PDF documents are basically just vector files, not built to edit at all.
[As Dr. Hassan said recently][7]: "Perhaps you would like to edit the text in Word, but make fine adjustments to the layout in InDesign? It's very difficult to switch between different programs today, but Editable PDF, a universally editable format, will let you do exactly that."
Editable PDF has great potential to benefit open source software in particular. In contrast to non-standard file formats, a universal format that's truly portable creates an even playing field for the best software to win.
Moreover, one of the big barriers for Linux to go mainstream on the desktop is that so many business users feel extremely attached to Microsoft Word. The open source movement has replied by saying, "well, if we try, we could make ours just as good." But maybe the mindset we really need is, "hey, let's do something many times better."
### Endeavour OS
Ahh… [Arch][8]: the Linux so notorious, it became a meme.
But there's more going on than just, "I use Arch, btw." Part of Arch's notoriety is how intimidating it can be to install.
This is why some people have gravitated to other distributions built on Arch, such as [Manjaro][9] and—until recently—[Antergos][10].
When the Antergos developers had to abandon the project due to lack of time, they left quite a community behind. Out of this, [EndeavourOS][11] was born.
EndeavourOS might be a spiritual successor to Antergos, but it's not a fork. The team has come up with a lightweight, Arch-based operating system of its own.
So if Manjaro offers an "Arch made easy" experience, why would you install Endeavour OS? Well, while Manjaro is based on Arch, it's got quite a lot of its own thing going on as well. EndeavourOS is quite close to pure Arch—with an Xfce desktop environment and a graphical installer along for the ride.
EndeavourOS also advertises an open and friendly community for curious beginners—its front page even says: "Stupid questions simply don't exist with us."
In just a few months, EndeavourOS has already delivered its first stable release, but it is still an extremely young initiative.
One thing that really appeals to me about EndeavourOS is the clarity of its ethos. Some Linuxes are all about the data center and the server room; others aim to be the most user-friendly desktop daily driver for the broadest audience. A few have an identity crisis, caught between these things. So, where does EndeavourOS fit in all this?
This Linux is utterly unapologetic in catering to technology hobbyists, enthusiasts, and power users. It's for the amateurs, in that best and most original sense of the word—those who love what they do. Awesome. So isn't Endeavour the perfect name?
If what you want is to roll your sleeves up and level up while still enjoying a gentle start and a friendly community, this could be a great way to go about it.
_What other new open source projects are you keeping an eye on? Please share in the comments._
Explore the open source alternatives to Adobe Acrobat for reading, creating, and editing PDF files.
--------------------------------------------------------------------------------
via: https://opensource.com/article/19/11/emerging-projects
作者:[James Mawson][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/dxmjames
[b]: https://github.com/lujun9972
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/BUSINESS_lightbulbs.png?itok=pwp22hTw (One lightbulb lit out of several)
[2]: https://glimpse-editor.org/
[3]: https://www.gimp.org/
[4]: https://itsfoss.com/gimp-fork-glimpse/
[5]: https://www.youtube.com/watch?v=CV1HZU4KFHc
[6]: https://editablepdf.org/
[7]: https://dxmtechsupport.com.au/editable-pdf-interview
[8]: https://www.archlinux.org/
[9]: https://manjaro.org/
[10]: https://antergos.com/
[11]: https://endeavouros.com/

View File

@ -0,0 +1,80 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (Intel targets Nvidia (again) with GPU and cross-processor API)
[#]: via: (https://www.networkworld.com/article/3454497/intel-targets-nvidia-again-with-gpu-and-cross-processor-api.html)
[#]: author: (Andy Patrizio https://www.networkworld.com/author/Andy-Patrizio/)
Intel targets Nvidia (again) with GPU and cross-processor API
======
Intel is looking to offer a unified CPU, GPU, and platform architecture that Nvidia doesnt have but AMD does.
Martyn Williams/IDG
Third times the charm? Intel is hoping so. It released details of its Xe Graphics Architecture, with which it plans to span use cases from mobility to high-performance computing (HPC) servers and which it hopes will succeed where its [Larrabee][1] GPU and [Xeon Phi][2] manycore processors failed.
Its no secret Intel wants a piece of the high-performance computing HPC action, given that it introduced the chip and other products at it Intel HPC Developer Conference in Denver, Colo., this week just ahead of the Supercomputing 19 tradeshow.
**Don't miss** [**10 of the world's fastest supercomputers**][3]
[][4]
BrandPost Sponsored by HPE
[Take the Intelligent Route with Consumption-Based Storage][4]
Combine the agility and economics of HPE storage with HPE GreenLake and run your IT department with efficiency.
Intel bills the Xe Graphics Architecture card as its first "exascale graphics card," based on a new 7nm architecture called “Ponte Vecchio.” Intel is splitting the Xe Architecture into three designs for different segments: [data center][5], consumer graphics cards, and AI use-cases; integrated graphics for processors; and the high-tier Xe HPC for high performance computing.
Rather than use the large die for its graphics chips the way Nvidia and AMD do it, Intel is using the Multi-Chip Module (MCM) design that breaks up one big chip into smaller “chiplets” that are connected via a high speed fabric. This is how AMD designed the [Ryzen and EPYC CPUs][6], something Intel initially pooh-poohed but is since [adopting][7] for its Xeons.
These modules also use other packaging technology advancements such as Foveros 3D chip-packaging technology, which allows for 3D stacking of dies and mixing of CPU, AI, and GPU processors, High Bandwidth Memory (HMB) and Embedded Multi-Die Bridge (EMIB) technology to tie the HBM packages to the compute die.
Xe Architecture cards will also come with a new scalable fabric called XE Memory Fabric (XEMF), which ties compute and memory together with a coherent memory interface that Intel claims will allow Xe to scale to thousands of nodes.
Kevin Krewell, principal analyst with Tirias Research, noted that this is not a brand-new graphic architecture, its an evolution from Intels integrated GPU technology that has been a part of its consumer Core CPUs for several years and has been steadily maturing.
“This is a design that is more like traditional graphics. [Intel is starting] with their traditional integrated graphics cores and building on top of that. Larrabee tried a GPU built on a CPU. In this case they are building a ground up GPU with GPU-like features and not trying to do anything too weird. And now they've got a real GPU guy running the group,” he said.
Krewell is referring to Raja Koduri, senior vice president of the company's Core and Visual Computing Group. Koduri has one hell of a resume. He was the brains behind AMD integrating CPU and GPU cores on one die (yet another example of AMD leading) and then went to Apple where he pioneered the [Retina display][8]. So if Intel cant get graphics right with this guy there is no hope.
### Taking Aim At CUDA
One thing that has been a huge boon to Nvidia is its CUDA language for programming GPUs. Intel is taking aim and then some at CUDA with its new OneAPI programming model, which Intel designed to simplify programming across not only its GPU but CPU, FPGA, and AI accelerators as well.
This means applications can move seamlessly between Intel's different types of compute architectures. If an application is best processed on an FPGA, then it will be processed there. Same for CPUs, GPUs, and AI accelerators. If thats not enough, Intel has the Data Parallel C++ Conversion Tool to take CUDA code and port it to OneAPI. If they pull this off, it would be a huge advantage over Nvidia, since CUDA is only for its GPUs.
Interestingly, Intel said OneAPI will be open-source and will also work with other vendors' hardware, although they didnt say whose. If it ends up ported to AMDs platform, well, that would be entertaining.
“Its more than a shot at CUDA because they want to replace CUDA,” said Krewell. “OneAPI is a very ambitious program, trying to combine all of the different processor elements under one umbrella API. So its a very aggressive program and they are building it out piece by piece.  But right now its at version 0.5. CUDA is at version ten. So they've got a ways to catch up.”
[[Get regularly scheduled insights by signing up for Network World newsletters.]][9]
Join the Network World communities on [Facebook][10] and [LinkedIn][11] to comment on topics that are top of mind.
--------------------------------------------------------------------------------
via: https://www.networkworld.com/article/3454497/intel-targets-nvidia-again-with-gpu-and-cross-processor-api.html
作者:[Andy Patrizio][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://www.networkworld.com/author/Andy-Patrizio/
[b]: https://github.com/lujun9972
[1]: https://www.networkworld.com/article/2239992/intel-nurses--black-eye--on-larrabee--as-amd--nvidia-get-to-work.html
[2]: https://www.networkworld.com/article/3296004/intel-ends-the-xeon-phi-product-line.html
[3]: https://www.networkworld.com/article/3236875/embargo-10-of-the-worlds-fastest-supercomputers.html
[4]: https://www.networkworld.com/article/3440100/take-the-intelligent-route-with-consumption-based-storage.html?utm_source=IDG&utm_medium=promotions&utm_campaign=HPE20773&utm_content=sidebar ( Take the Intelligent Route with Consumption-Based Storage)
[5]: https://www.networkworld.com/article/3223692/what-is-a-data-centerhow-its-changed-and-what-you-need-to-know.html
[6]: https://www.networkworld.com/article/3321943/amd-s-road-to-the-data-center-and-hpc-isn-t-as-long-as-you-think.html
[7]: https://www.networkworld.com/article/3408177/intel-unveils-new-3d-chip-packaging-design.html
[8]: https://www.networkworld.com/article/2211314/iphone-4-s-retina-display-explained.html
[9]: https://www.networkworld.com/newsletters/signup.html
[10]: https://www.facebook.com/NetworkWorld/
[11]: https://www.linkedin.com/company/network-world

View File

@ -1,3 +1,4 @@
lixin555 is translating
Share And Upload Files To Compatible Hosting Sites Automatically
======
![](https://www.ostechnix.com/wp-content/uploads/2017/10/Upload-720x340.png)

View File

@ -1,5 +1,5 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: translator: (geekpi)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )

View File

@ -0,0 +1,150 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (How to Use TimeShift to Backup and Restore Ubuntu Linux)
[#]: via: (https://www.linuxtechi.com/timeshift-backup-restore-ubuntu-linux/)
[#]: author: (James Kiarie https://www.linuxtechi.com/author/james/)
How to Use TimeShift to Backup and Restore Ubuntu Linux
======
Have you ever wondered how you can backup and restore your **Ubuntu** or **Debian system** ? **Timeshift** is a free and opensource tool that allows you to create incremental snapshots of your filesystem. You can create a snapshot using either **RSYNC** or **BTRFS**.
[![TimeShift-Backup-Restore-Tool-Ubuntu][1]][2]
With that. lets delve in and install Timeshift. For this tutorial, we shall install on Ubuntu 18.04 LTS system.
### Installing TimeShift on Ubuntu / Debian Linux
TimeShift is not hosted officially on Ubuntu and Debian repositories. With that in mind, we are going to run the command below to add the PPA:
```
# add-apt-repository -y ppa:teejee2008/ppa
```
![Add-timeshift-repository][1]
Next, update the system packages with the command:
```
# apt update
```
After a successful system update, install timeshift by running following apt command :
```
# apt install timeshift
```
![apt-install-timeshift][1]
### Preparing a backup storage device
Best practice demands that we save the system snapshot on a separate storage volume, aside from the systems hard drive. For this guide, we are using a 16 GB flash drive as the secondary drive on which we are going to save the snapshot.
```
# lsblk | grep sdb
```
![lsblk-sdb-ubuntu][1]
For the flash drive to be used as a backup location for the snapshot, we need to create a partition table on the device. Run the following commands:
```
# parted /dev/sdb mklabel gpt
# parted /dev/sdb mkpart primary 0% 100%
# mkfs.ext4 /dev/sdb1
```
![create-partition-table-on-drive-ubuntu][1]
After creating a partition table on the USB flash drive, we are all set to begin creating filesystems snapshots!
### Using Timeshift to create snapshots
To launch Timeshift, use the application menu to search for the  Timeshift application.
![Access-Timeshift-Ubuntu][1]
Click on the Timeshift icon and the system will prompt you for the Administrators password. Provide the password and click on Authenticate
![Authentication-required-ubuntu][1]
Next, select your preferred snapshot type.
![Select-Rsync-option-timeshift][1]
Click **Next**.  Select the destination drive for the snapshot. In this case, my location is the external USB drive labeled as **/dev/sdb**
![Select-snapshot location][1]
Next, define the snapshot levels. Levels refer to the intervals during which the snapshots are created.  You can choose to have either monthly, weekly, daily, or hourly snapshot levels.
![Select-snapshot-levels-Timeshift][1]
Click Finish
On the next Window, click on the **Create** button to begin creating the snapshot. Thereafter, the system will begin creating the snapshot.
![Create-snapshot-timeshift][1]
Finally, your snapshot will be displayed as shown
![Snapshot-created-TimeShift][1]
### Restoring Ubuntu / Debian from a snapshot
Having created a system snapshot, lets now see how you can restore your system from the same snapshot. On the same Timeshift window, click on the snapshot and click on the **Restore** button as shown.
![Restore-snapshot-timeshift][1]
Next, you will be prompted to select the target device.  leave the default selection and hit **Next**.
![Select-target-device-timeshift][1]
A dry run will be performed by Timeshift before the restore process commences.
![Comparing-files-Dry-Run-timeshift][1]
In the next window, hit the **Next**  button to confirm actions displayed.
![Confirm-actions-timeshift][1]
Youll get a warning and a disclaimer as shown. Click **Next** to initialize the restoration process.
Thereafter, the restore process will commence and finally, the system will thereafter reboot into an earlier version as defined by the snapshot.
![Restoring-snapshot-timeshift][1]
**Conclusion**
As you have seen it quite easy to use TimeShift to restore your system from a snapshot. It comes in handy when backing up system files and allows you to recover in the event of a system fault. So dont get scared to tinker with your system or mess up. TimeShift will give you the ability to go back to a point in time when everything was running smoothly.
* [Facebook][3]
* [Twitter][4]
* [LinkedIn][5]
* [Reddit][6]
--------------------------------------------------------------------------------
via: https://www.linuxtechi.com/timeshift-backup-restore-ubuntu-linux/
作者:[James Kiarie][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://www.linuxtechi.com/author/james/
[b]: https://github.com/lujun9972
[1]: data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7
[2]: https://www.linuxtechi.com/wp-content/uploads/2019/11/TimeShift-Backup-Restore-Tool-Ubuntu.png
[3]: http://www.facebook.com/sharer.php?u=https%3A%2F%2Fwww.linuxtechi.com%2Ftimeshift-backup-restore-ubuntu-linux%2F&t=How%20to%20Use%20TimeShift%20to%20Backup%20and%20Restore%20Ubuntu%20Linux
[4]: http://twitter.com/share?text=How%20to%20Use%20TimeShift%20to%20Backup%20and%20Restore%20Ubuntu%20Linux&url=https%3A%2F%2Fwww.linuxtechi.com%2Ftimeshift-backup-restore-ubuntu-linux%2F&via=Linuxtechi
[5]: http://www.linkedin.com/shareArticle?mini=true&url=https%3A%2F%2Fwww.linuxtechi.com%2Ftimeshift-backup-restore-ubuntu-linux%2F&title=How%20to%20Use%20TimeShift%20to%20Backup%20and%20Restore%20Ubuntu%20Linux
[6]: http://www.reddit.com/submit?url=https%3A%2F%2Fwww.linuxtechi.com%2Ftimeshift-backup-restore-ubuntu-linux%2F&title=How%20to%20Use%20TimeShift%20to%20Backup%20and%20Restore%20Ubuntu%20Linux

View File

@ -0,0 +1,231 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (How to install Java on Linux)
[#]: via: (https://opensource.com/article/19/11/install-java-linux)
[#]: author: (Seth Kenlon https://opensource.com/users/seth)
How to install Java on Linux
======
Embrace Java applications on your desktop, and run them on all of your
desktops.
![Coffee beans][1]
No matter what operating system you're running, there are usually several ways to install an application. Sometimes you might find an application in an app store, or you might install it with a package manager like DNF on Fedora or Brew on Mac, and other times, you might download an executable or an installer from a website. Because Java is such a popular backend for so many applications, it's good to understand the different ways you can install it. The good news is that you have many options, and this article covers them all.
The bad news is that Java is _big_, not so much in size as in scope. Java is an open source language and specification, meaning that anyone can, in theory, create an implementation of it. That means, before you can install anything, you have to decide which Java you want to install.
### Do I need a JVM or a JRE or a JDK?
Java is broadly split into two downloadable categories. The **Java Virtual Machine** (JVM) is a runtime component; it's the "engine" that enables Java applications to launch and run on your computer. It's included in the Java Runtime Environment (JRE).
The **Java Development Kit** (JDK) is a development toolkit: you can think of it as a garage where tinkerers sit around making adjustments, repairs, and improvements. The JDK includes the Java Runtime Environment (JRE).
In terms of downloads, this translates to:
* If you're a user looking to run a Java application, you only need the JRE (which includes a JVM).
* If you're a developer looking to program in Java, you need the JDK (which includes JRE libraries, which in turn includes a JVM).
### What's the difference between OpenJDK, IcedTea, and OracleJDK?
When Sun Microsystems was bought by Oracle, Java was a major part of the sale. Luckily, Java is an open source technology, so if you're not happy with the way Oracle maintains the project, you have other options. Oracle bundles proprietary components with its Java downloads, while the OpenJDK project is fully open source.
The IcedTea project is essentially OpenJDK, but its goal is to make it easier for users to build and deploy OpenJDK when using fully free and open source tools.
### Which Java should I install?
If you feel overwhelmed by the choices, then the easy answer of which Java implementation you should install is whichever is easiest for you to install. When an application tells you that you need Java 12, but your repository only has Java 8, it's fine to install whatever implementation of Java 12 you can find from a reliable source. On Linux, you can have several different versions of Java installed all at once, and they won't interfere with one another.
If you're a developer who needs to make the choice, then you should consider what components you need. If you opt for Oracle's version, be aware that there are proprietary plugins and fonts in the package, which could [interfere with distributing your application][2]. It's safest to develop on IcedTea or OpenJDK.
### Install OpenJDK from a repository
Now that you know your choices, you can search for OpenJDK or IcedTea with your package manager and install the version you need. Some distributions use the keyword **latest** to indicate the most recent version, which is usually what you need to run whatever application you're trying to run. Depending on what package manager you use, you might even consider using **grep** to filter the search results to include only the latest versions. For example, on Fedora:
```
$ sudo dnf search openjdk | \
grep latest | cut -f1 -d':'
java-latest-openjdk-demo.x86_64
java-openjdk.i686
java-openjdk.x86_64
java-latest-openjdk-jmods.x86_64
java-latest-openjdk-src.x86_64
java-latest-openjdk.x86_64
[...]
```
Only if the application you're trying to run insists that you need a legacy version of Java should you look past the **latest** release.
Install Java on Fedora or similar with:
```
`$ sudo dnf install java-latest-openjdk`
```
If your distribution doesn't use the **latest** tag, it may use another keyword, such as **default**. Here's a search for OpenJDK on Debian:
```
$ sudo apt search openjdk | less
default-jdk
  Standard Java development kit
default-jre
  Standard Java runtime
openjdk-11-jdk
  OpenJDK development kit (JDK)
[...]
```
In this case, the **default-jre** package is appropriate for users, and the **default-jdk** is suitable for developers.
For example, to install the JRE on Debian:
```
`$ sudo apt install default-jre`
```
Java is now installed.
There are probably many _many_ Java-related packages in your repository. Search on OpenJDK and look for either the most recent JRE or JVM if you're a user and for the most recent JDK if you're a developer.
### Install Java from the internet
If you can't find a JRE or JDK in your repository, or the ones you find don't fit your needs, you can download open source Java packages from the internet. You can find downloads of OpenJDK at [openjdk.java.net][3] in the form of a tarball requiring manual installation, or you can download the [Zulu Community][4] edition from Azul in the form of a tarball or installable RPM or DEB packages.
#### Installing Java from a TAR file
If you download a TAR file from either Java.net or Azul, you must install it manually. This is often called a "local" install because you're not installing Java to a "global" location. Instead, you choose a convenient place in your PATH.
If you don't know what's in your PATH, take a look to find out:
```
$ echo $PATH
/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/home/seth/bin
```
In this example PATH, the locations **/usr/local/bin** and **/home/seth/bin** are good options. If you're the only user on your computer, then your own home directory makes sense. If there are many users on your computer, then a common location, such as **/usr/local** or **/opt**, is the best choice.
If you don't have access to system-level directories like **/usr/local**, which require **sudo** permissions, then create a local **bin** (for "binary," not a waste bin) or **Applications** folder in your own home folder:
```
`$ mkdir ~/bin`
```
Add this to your PATH, if it's not already there:
```
$ echo PATH=$PATH:$HOME/bin &gt;&gt; ~/.bashrc
$ source ~/.bashrc
```
Finally, unarchive the tarball into the directory you've chosen.
```
$ tar --extract --file openjdk*linux-x64_bin.tar.gz \
\--directory=$HOME/bin
```
Java is now installed.
#### Installing Java from an RPM or DEB
If you download an RPM or DEB file from Azul.com, then you can use your package manager to install it.
For Fedora, CentOS, RHEL, and similar, download the RPM and install it using DNF:
```
`$ sudo dnf install zulu*linux.x86_64.rpm`
```
For Debian, Ubuntu, Pop_OS, and similar distributions, download the DEB package and install it using Apt:
```
`$ sudo dpkg -i zulu*linux_amd64.deb`
```
Java is now installed.
#### Setting your Java version with alternatives
Some applications are developed for a specific version of Java and don't work with any other version. This is rare, but it does happen, and on Linux, you can use either the local install method (see [Installing Java from a TAR file][5]) or the **alternatives** application to deal with this conflict.
The **alternatives** command looks at applications installed on your Linux system and lets you choose which version to use. Some distributions, such as Slackware, don't provide an **alternatives** command, so you must use the local install method instead. On Fedora, CentOS, and similar distributions, the command is **alternatives**. On Debian, Ubuntu, and similar, the command is **update-alternatives**.
To get a list of available versions of an application currently installed on your Fedora system:
```
`$ alternatives --list`
```
On Debian, you must specify the application you want alternatives for:
```
`$ update-alternatives --list java`
```
To choose which version you want to make the system default on Fedora:
```
`$ sudo alternatives --config java`
```
On Debian:
```
`$ sudo updates-alternatives --config java`
```
You can change the default Java version as needed based on the application you want to run.
### Running a Java application
Java applications are typically distributed as JAR files. Depending on how you installed Java, your system may already be configured to run a Java application, which allows you to just double-click the application icon (or select it from an application menu) to run it. If you had to do a local Java install that isn't integrated with the rest of your system, you can launch Java applications directly from a terminal:
```
`$ java -jar ~/bin/example.jar &`
```
### Java is a good thing
Java is one of the few programming environments that places cross-platform development first. There's nothing quite as liberating as asking whether an application runs on your platform, and then discovering that the application was written in Java. As simply as that, you're freed from any platform anxiety you may have had, whether you're a developer or a user. Embrace Java applications on your desktop, and run them on _all_ of your desktops.
--------------------------------------------------------------------------------
via: https://opensource.com/article/19/11/install-java-linux
作者:[Seth Kenlon][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/seth
[b]: https://github.com/lujun9972
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/java-coffee-beans.jpg?itok=3hkjX5We (Coffee beans)
[2]: https://www.oracle.com/technetwork/java/javase/overview/oracle-jdk-faqs.html
[3]: http://openjdk.java.net
[4]: https://www.azul.com/downloads/zulu-community
[5]: tmp.wuzOCnXHry#installing-java-from-a-tar-file

View File

@ -0,0 +1,105 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (Set up single sign-on for Fedora Project services)
[#]: via: (https://fedoramagazine.org/set-up-single-sign-on-for-fedora-project-services/)
[#]: author: (Stephen Gallagher https://fedoramagazine.org/author/sgallagh/)
Set up single sign-on for Fedora Project services
======
![][1]
In addition to an operating system, the Fedora Project provides [services][2] for users and developers. Services such as [Ask Fedora][3], the [Fedora Project wiki][4] and the [Fedora Project mailing lists][5] help users [learn][6] how to best take advantage of Fedora. For developers of Fedora, there are many other services such as [dist-git][7], [Pagure][8], [Bodhi][9], [COPR][10] and [Bugzilla][11] for the packaging and release process.
These services are available with a free account from the [Fedora Accounts System][12] (FAS). This account is the passport to all things Fedora! This article covers how to get set up with an account and configure [Fedora Workstation][13] for browser single sign-on.
### Signing up for a Fedora account
To create a FAS account, browse to the [account creation page][14]. Here, you will fill out your basic identity data:
![Account creation page][15]
Once you enter your data, the account system sends an email to the address you provided, with a temporary password. Pick a strong password and use it.
![Password reset page][16]
Next, the account details page appears. If you want to contribute to the Fedora Project, you should complete the [Contributor Agreement][17] now. Otherwise, you are done and you can use your account to log into the various Fedora services.
![Account details page][18]
### Configuring Fedora Workstation for single sign-On
Now that you have your account, you can sign into any of the Fedora Project services. Most of these services support single sign-on (SSO), so you can sign in without re-entering your username and password.
Fedora Workstation provides an easy workflow to add your Fedora credentials. The GNOME Online Accounts tool helps you quickly set up your system to access many popular services. To access it, go to the _Settings_ menu.
![][19]
Click on the option labeled _Fedora_. A prompt opens for you to provide your username and password for your Fedora Account.
![][20]
GNOME Online Accounts stores your password in [GNOME Keyring][21] and automatically acquires your single-sign-on credentials for you when you log in.
### Single sign-on with a web browser
Today, Fedora Workstation supports three web browsers out of the box with support for single sign-on with the Fedora Project services. These are [Mozilla Firefox][22], [GNOME Web][23], and [Google Chrome][24].
Due to a [bug][25] in Chromium, single sign-on doesnt work currently if you have more than one set of Kerberos (SSO) credentials active on your session. As a result, Fedora doesnt enable this function out of the box for Chromium in Fedora.
To sign on to a service, browse to it and select the _login_ option for that service. For most Fedora services, this is all you need to do; the browser handles the rest. Some services such as the [Fedora mailing lists][26] and [Bugzilla][11] support multiple login types. For them, select the _Fedora_ or _Fedora Account System_ login type.
Thats it! You can now log into any of the Fedora Project services without re-entering your password.
##### Special consideration for Google Chrome
To enable single sign-on out of the box for Google Chrome, Fedora takes advantage of certain features in Chrome that are intended for use in “managed” environments. A managed environment is traditionally a corporate or other organization that sets certain security and/or monitoring requirements on the browser.
Recently, Google Chrome changed its behavior and it now reports _Managed by your organization_ or possibly _Managed by fedoraproject.org_ under the ⋮ menu in Google Chrome. That [link][27] leads to a page that says, “If your Chrome browser is managed, your administrator can set up or restrict certain features, install extensions, monitor activity, and control how you use Chrome.” However, **[Fedora will never monitor your browser activity or restrict your actions][28].**
Enter _chrome://policy_ in the address bar to see exactly what settings Fedora has enabled in the browser. The _AuthNegotiateDelegateWhitelist_ and _AuthServerWhitelist_ options will be set to _*.fedoraproject.or_g. These are the only changes Fedora makes.
--------------------------------------------------------------------------------
via: https://fedoramagazine.org/set-up-single-sign-on-for-fedora-project-services/
作者:[Stephen Gallagher][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://fedoramagazine.org/author/sgallagh/
[b]: https://github.com/lujun9972
[1]: https://fedoramagazine.org/wp-content/uploads/2019/05/sso-fedora-web-services-816x345.jpg
[2]: https://apps.fedoraproject.org/
[3]: https://ask.fedoraproject.org/
[4]: https://fedoraproject.org/wiki/Fedora_Project_Wiki
[5]: https://lists.fedoraproject.org/archives/
[6]: https://fedoramagazine.org/check-out-the-new-askfedora/
[7]: http://src.fedoraproject.org/
[8]: https://pagure.io
[9]: https://bodhi.fedoraproject.org
[10]: https://copr.fedorainfracloud.org/
[11]: https://bugzilla.redhat.com
[12]: https://admin.fedoraproject.org/accounts
[13]: https://getfedora.org/
[14]: https://admin.fedoraproject.org/accounts/user/new
[15]: https://fedoramagazine.org/wp-content/uploads/2019/05/FAS-new.png
[16]: https://fedoramagazine.org/wp-content/uploads/2019/05/changepass-1024x318.png
[17]: https://admin.fedoraproject.org/accounts/fpca/
[18]: https://fedoramagazine.org/wp-content/uploads/2019/05/account-blurred.png
[19]: https://fedoramagazine.org/wp-content/uploads/2019/09/goa-toplevel.png
[20]: https://fedoramagazine.org/wp-content/uploads/2019/09/goa-fedora-creds.png
[21]: https://wiki.gnome.org/Projects/GnomeKeyring
[22]: https://www.mozilla.org/en-US/firefox
[23]: https://wiki.gnome.org/Apps/Web
[24]: https://www.google.com/chrome/
[25]: https://bugzilla.redhat.com/show_bug.cgi?id=1640158
[26]: https://lists.fedoraproject.org
[27]: https://support.google.com/chrome/answer/9281740
[28]: https://fedoraproject.org/wiki/Legal:PrivacyPolicy

View File

@ -0,0 +1,104 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (Switching from Python 2 to Python 3: What you need to know)
[#]: via: (https://opensource.com/article/19/11/end-of-life-python-2)
[#]: author: (Katie McLaughlin https://opensource.com/users/glasnt)
Switching from Python 2 to Python 3: What you need to know
======
Python 2 will reach its end of life in mere weeks. Here's what to know
before you migrate to Python 3.
![A sunrise][1]
Python 2.7 will officially become unsupported beginning January 1, 2020. There is one [final bugfix][2] planned after this date, but then that's it.
What does this end of life (EOL) mean for you? If you run Python 2, you need to migrate.
### Who decided to EOL Python 2?
In [2012][3], the team maintaining the Python programming language reviewed its options. There were two increasingly different codebases, Python 2 and Python 3. Both were popular, but the newer version was not as widely adopted.
In addition to Python 3's disruption of changing the underlying way data is handled by completely reworking Unicode support, a major version change allowed non-backward-compatible changes to happen all at once. This decision was documented [in 2006][4]. To ease the disruption, Python 2 continued to be maintained, with some features backported. To further help the community transition, the EOL date was extended [from 2015 to 2020][5], another five years.
Maintaining divergent codebases was a hassle the team knew it had to resolve. Ultimately, a decision was [announced][6]:
> "We are volunteers who make and take care of the Python programming language. We have decided that January 1, 2020, will be the day that we sunset Python 2. That means that we will not improve it anymore after that day, even if someone finds a security problem in it. You should upgrade to Python 3 as soon as you can."
[Nick Coghlan][7], a core CPython developer and current member of the Python steering council, [adds more information in his blog][8]. And [PEP 404][9], written by [Barry Warsaw][10] (also a member of the Python steering council), details why Python 2.8 will never be a thing.
### Is anyone still supporting Python 2?
Support for Python 2 from providers and vendors will vary. [Google Cloud has announced][11] how it plans to support Python 2 going forward. Red Hat has also [announced plans for Red Hat Enterprise Linux (RHEL)][12], and AWS has announced [minor version update requirements][13] for the AWS command-line interface and [SDK][14].
You can also read the Stack Overflow blog post "[Why is the Migration to Python 3 Taking So Long?][15]" by [Vicki Boykis][16], in which she identifies three reasons why Python 3 adoption is slow. 
### Reasons to use Python 3
Regardless of ongoing support, it's a really good idea to migrate to Python 3 as soon as you can. Python 3 will continue to be supported, and it has some really neat things that Python 2 just doesn't have.
The recently released [Python 3.8][17] includes such [features][18] as the [walrus operator][19], [positional-only parameters][20], and [self-documenting f-strings][21]. Earlier releases of Python 3 introduced [features][22] such as [asyncio][23], [f-strings][24], [type hints][25], and [pathlib][26], just to name a few.
The top 360 most-downloaded packages [have already migrated to Python 3][27]. You can check your requirements.txt file using the [caniusepython3][28] package to see if any packages you depend on haven't yet been migrated.
### Resources for porting Python 2 to Python 3
There are many resources available to ease your migration to Python 3. For example, the [Porting Python 2 to Python 3 guide][29] lists a bunch of tools and tricks to help you achieve single-source Python 2/3 compatibility. There are also some useful tips on [Python3statement.org][30].
[Dustin Ingram][31] and [Chris Wilcox][32] gave a [presentation at Cloud Next '19][33] detailing some of the motivations and migration patterns for the transition into Python 3. [Trey Hunner][34] gave a [presentation at PyCon 2018][35] about Python 3's most useful features to encourage you to migrate so you can take advantage of them.
### Join us!
January 1, 2020, is now just weeks away. If you need daily reminders of just how soon that is (and you use Twitter), follow the [Countdown to Python 2 sunset][36] Twitter bot.
--------------------------------------------------------------------------------
via: https://opensource.com/article/19/11/end-of-life-python-2
作者:[Katie McLaughlin][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/glasnt
[b]: https://github.com/lujun9972
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/govt_a%20new%20dawn.png?itok=b4zU-VAY (A sunrise)
[2]: https://www.python.org/dev/peps/pep-0373/#maintenance-releases
[3]: https://github.com/python/peps/commit/a733bc927acbca16bfa3de486fb2c7d3f767a748
[4]: https://www.python.org/dev/peps/pep-3000/#compatibility-and-transition
[5]: https://github.com/python/peps/commit/f82462002b86feff36215b4230be28967039b0cc
[6]: https://www.python.org/doc/sunset-python-2/
[7]: https://twitter.com/ncoghlan_dev
[8]: http://python-notes.curiousefficiency.org/en/latest/python3/questions_and_answers.html
[9]: https://www.python.org/dev/peps/pep-0404/
[10]: https://twitter.com/pumpichank
[11]: https://cloud.google.com/python/docs/python2-sunset/?utm_source=osdc&utm_medium=blog&utm_campaign=pysunset
[12]: https://access.redhat.com/solutions/4455511
[13]: https://aws.amazon.com/blogs/developer/deprecation-of-python-2-6-and-python-3-3-in-botocore-boto3-and-the-aws-cli/
[14]: https://aws.amazon.com/sdk-for-python/
[15]: https://stackoverflow.blog/2019/11/14/why-is-the-migration-to-python-3-taking-so-long/
[16]: https://twitter.com/vboykis
[17]: https://www.python.org/downloads/
[18]: https://docs.python.org/3.8/whatsnew/3.8.html
[19]: https://docs.python.org/3.8/whatsnew/3.8.html#assignment-expressions
[20]: https://docs.python.org/3.8/whatsnew/3.8.html#positional-only-parameters
[21]: https://docs.python.org/3.8/whatsnew/3.8.html#f-strings-support-for-self-documenting-expressions-and-debugging
[22]: https://docs.python.org/3.8/whatsnew/index.html
[23]: https://docs.python.org/3.8/library/asyncio.html#module-asyncio
[24]: https://docs.python.org/3.7/whatsnew/3.6.html#pep-498-formatted-string-literals
[25]: https://docs.python.org/3.7/whatsnew/3.5.html#pep-484-type-hints
[26]: https://docs.python.org/3.8/library/pathlib.html#module-pathlib
[27]: http://py3readiness.org/
[28]: https://pypi.org/project/caniusepython3/
[29]: https://docs.python.org/3/howto/pyporting.html
[30]: https://python3statement.org/practicalities/
[31]: https://twitter.com/di_codes
[32]: https://twitter.com/chriswilcox47
[33]: https://www.youtube.com/watch?v=Bye7Rms0Vgw&utm_source=osdc&utm_medium=blog&utm_campaign=pysunset
[34]: https://twitter.com/treyhunner
[35]: https://www.youtube.com/watch?v=klaGx9Q_SOA
[36]: https://twitter.com/python2sunset

View File

@ -0,0 +1,218 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (Bash Script to View System Information on Linux Every Time You Log into Shell)
[#]: via: (https://www.2daygeek.com/bash-shell-script-view-linux-system-information/)
[#]: author: (Magesh Maruthamuthu https://www.2daygeek.com/author/magesh/)
Bash Script to View System Information on Linux Every Time You Log into Shell
======
There are several commands in Linux to obtain system information such as processor information, manufacturer name, and serial number, etc,.
You may need to run several commands to collect this information.
Also, it is very difficult to remember all the commands and their options.
Instead you can write a **[shell script][1]** to customize the output based on your needs.
In the past we have written many **[bash scripts][2]** for a variety of purposes.
Today, we came up with a new shell script, which shows you the required system information every time you log into the shell.
There are six parts to this script, and more details below.
* **Part-1:** General System Information
* **Part-2:** CPU/Memory Current Usage
* **Part-3:** Disk Usage &gt;80%
* **Part-4:** List System WWN Details
* **Part-5:** Oracle DB Instances
* **Part-6:** Available Package Updates
Weve added potential information to each area based on our needs. You can further customize this script to your needs if you wish.
There are many tools for this, most of which we have already covered.
To read them, go to the following articles.
* **[inxi A Great Tool to Check Hardware Information on Linux][3]**
* **[Dmidecode Easy Way To Get Linux System Hardware Information][3]**
* **[LSHW (Hardware Lister) A Nifty Tool To Get A Hardware Information On Linux][3]**
* **[hwinfo (Hardware Info) A Nifty Tool To Detect System Hardware Information On Linux][3]**
* **[python-hwinfo : Display Summary Of Hardware Information Using Standard Linux Utilities][3]**
* **[How To Use lspci, lsscsi, lsusb, And lsblk To Get Linux System Devices Information][3]**
* **[How To Check System Hardware Manufacturer, Model And Serial Number In Linux][3]**
* **[How To Find WWN, WWNN and WWPN Number Of HBA Card In Linux][3]**
* **[How to check HP iLO Firmware version from Linux command line][3]**
* **[How to check Wireless network card and WiFi information from Linux Command Line][3]**
* **[How to check CPU &amp; Hard Disk temperature on Linux][3]**
* **[Hegemon A modular System &amp; Hardware monitoring tool for Linux][3]**
* **[How to Check System Configuration and Hardware Information on Linux][3]**
If anyone wants to add any other information in the script, please let us know your requirements in the comment section so that we can help you.
### Bash Script to View System Information on Linux Every Time You Log into the Shell
This basic script will bring the system information to your terminal whenever you log into the shell.
```
#vi /opt/scripts/system-info.sh
#!/bin/bash
echo -e "-------------------------------System Information----------------------------"
echo -e "Hostname:\t\t"`hostname`
echo -e "uptime:\t\t\t"`uptime | awk '{print $3,$4}' | sed 's/,//'`
echo -e "Manufacturer:\t\t"`cat /sys/class/dmi/id/chassis_vendor`
echo -e "Product Name:\t\t"`cat /sys/class/dmi/id/product_name`
echo -e "Version:\t\t"`cat /sys/class/dmi/id/product_version`
echo -e "Serial Number:\t\t"`cat /sys/class/dmi/id/product_serial`
echo -e "Machine Type:\t\t"`vserver=$(lscpu | grep Hypervisor | wc -l); if [ $vserver -gt 0 ]; then echo "VM"; else echo "Physical"; fi`
echo -e "Operating System:\t"`hostnamectl | grep "Operating System" | cut -d ' ' -f5-`
echo -e "Kernel:\t\t\t"`uname -r`
echo -e "Architecture:\t\t"`arch`
echo -e "Processor Name:\t\t"`awk -F':' '/^model name/ {print $2}' /proc/cpuinfo | uniq | sed -e 's/^[ \t]*//'`
echo -e "Active User:\t\t"`w | cut -d ' ' -f1 | grep -v USER | xargs -n1`
echo -e "System Main IP:\t\t"`hostname -I`
echo ""
echo -e "-------------------------------CPU/Memory Usage------------------------------"
echo -e "Memory Usage:\t"`free | awk '/Mem/{printf("%.2f%"), $3/$2*100}'`
echo -e "Swap Usage:\t"`free | awk '/Swap/{printf("%.2f%"), $3/$2*100}'`
echo -e "CPU Usage:\t"`cat /proc/stat | awk '/cpu/{printf("%.2f%\n"), ($2+$4)*100/($2+$4+$5)}' | awk '{print $0}' | head -1`
echo ""
echo -e "-------------------------------Disk Usage >80%-------------------------------"
df -Ph | sed s/%//g | awk '{ if($5 > 80) print $0;}'
echo ""
echo -e "-------------------------------For WWN Details-------------------------------"
vserver=$(lscpu | grep vendor | wc -l)
if [ $vserver -gt 0 ]
then
echo "$(hostname) is a VM"
else
systool -c fc_host -v | egrep "(Class Device path | port_name |port_state)" > systool.out
fi
echo ""
echo -e "-------------------------------Oracle DB Instances---------------------------"
if id oracle >/dev/null 2>&1; then
/bin/ps -ef|grep pmon
then
else
echo "oracle user does not exist on $(hostname)"
fi
echo ""
if (( $(cat /etc/*-release | grep -w "Oracle|Red Hat|CentOS|Fedora" | wc -l) > 0 ))
then
echo -e "-------------------------------Package Updates-------------------------------"
yum updateinfo summary | grep 'Security|Bugfix|Enhancement'
echo -e "-----------------------------------------------------------------------------"
else
echo -e "-------------------------------Package Updates-------------------------------"
cat /var/lib/update-notifier/updates-available
echo -e "-----------------------------------------------------------------------------"
fi
```
Once the above script is added to a file. Set the executable permission for the “system-info.sh” file.
```
# chmod +x ~root/system-info.sh
```
When the script is ready, add the file path at the end of the “.bash_profile” file in RHEL-based systems CentOS, Oracle Linux and Fedora.
```
# echo "/root/system-info.sh" >> ~root/.bash_profile
```
To take this change effect, run the following command.
```
# source ~root/.bash_profile
```
For Debian-based systems, you may need to add a file path to the “.profile” file.
```
# echo "/root/system-info.sh" >> ~root/.profile
```
Run the following command to take this change effect.
```
# source ~root/.profile
```
You may have seen an output like the one below when running the above “source” command.
From next time on-wards, you will get this information every time you log into the shell.
Alternatively, you can manually run this script at any time if you need to.
```
-------------------------------System Information---------------------------
Hostname: daygeek-Y700
uptime: 1:20 1
Manufacturer: LENOVO
Product Name: 80NV
Version: Lenovo ideapad Y700-15ISK
Serial Number: AA0CMRN1
Machine Type: Physical
Operating System: Manjaro Linux
Kernel: 4.19.80-1-MANJARO
Architecture: x86_64
Processor Name: Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz
Active User: daygeek renu thanu
System Main IP: 192.168.1.6 192.168.122.1
-------------------------------CPU/Memory Usage------------------------------
Memory Usage: 37.28%
Swap Usage: 0.00%
CPU Usage: 15.43%
-------------------------------Disk Usage >80%-------------------------------
Filesystem Size Used Avail Use Mounted on
/dev/nvme0n1p1 217G 202G 4.6G 98 /
/dev/loop0 109M 109M 0 100 /var/lib/snapd/snap/odrive-unofficial/2
/dev/loop1 91M 91M 0 100 /var/lib/snapd/snap/core/6405
/dev/loop2 90M 90M 0 100 /var/lib/snapd/snap/core/7713
-------------------------------For WWN Details-------------------------------
CentOS8.2daygeek.com is a VM
-------------------------------Oracle DB Instances---------------------------
oracle user does not exist on CentOS8.2daygeek.com
-------------------------------Package Updates-------------------------------
13 Security notice(s)
9 Important Security notice(s)
3 Moderate Security notice(s)
1 Low Security notice(s)
35 Bugfix notice(s)
1 Enhancement notice(s)
-----------------------------------------------------------------------------
```
--------------------------------------------------------------------------------
via: https://www.2daygeek.com/bash-shell-script-view-linux-system-information/
作者:[Magesh Maruthamuthu][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://www.2daygeek.com/author/magesh/
[b]: https://github.com/lujun9972
[1]: https://www.2daygeek.com/category/shell-script/
[2]: https://www.2daygeek.com/category/bash-script/
[3]: https://www.2daygeek.com/inxi-system-hardware-information-on-linux/

View File

@ -7,21 +7,21 @@
[#]: via: (https://opensourceforu.com/2019/11/developing-a-simple-web-application-using/)
[#]: author: (Jis Joe Mathew https://opensourceforu.com/author/jis-joe/)
Developing a Simple Web Application Using Flutter
使用 Flutter 开发简单的 Web 应用
======
[![][1]][2]
_This article guides readers on how to run and deploy their first Web application using Flutter._
_本文指导读者如何使用 Flutter 运行和部署第一个 Web 应用。_
Flutter has moved to a new stage, the Web, after having travelled a long way in Android and iOS development. Flutter 1.5 has been released by Google, along with support for Web application development.
Flutter 在 Android 和 iOS 开发方面走了很长一段路之后,已经迈入了一个新的阶段,即 Web。Google 发布了 Flutter 1.5,同时支持 Web 应用开发。
**Configuring Flutter for the Web**
In order to use the Web package, enter the _flutter upgrade_ command to update to Flutter version 1.5.4.
**为 Web 配置 Flutter**
为了使用 Web 包,输入命令 _flutter upgrade_ 更新到 Flutter 1.5.4。
* Open a terminal
* Type flutter upgrade
* Check the version by typing _flutter version_
* 打开终端
* 输入 flutter upgrade
* 输入 _flutter version_ 检查版本
@ -29,12 +29,12 @@ In order to use the Web package, enter the _flutter upgrade_ command to update t
![Figure 2: Starting a new Flutter Web project in VSC][4]
One can also use Android Studio 3.0 or later versions for Flutter Web development, but we will use Visual Studio Code for this tutorial.
也可以将 Android Studio 3.0 或更高版本用于 Flutter Web 开发,但在本教程中,我们使用 Visual Studio Code。
**Creating a new project with Flutter Web**
Open Visual Studio Code and press _Shift+Ctrl+P_ to start a new project. Type flutter and select _New Web Project_.
Now, name the project. I have named it _open_source_for_you_.
Open the terminal window in VSC, and type in the following commands:
**使用 Flutter Web 创建新项目**
打开 Visual Studio Code然后按 _Shift+Ctrl+P_ 开始一个新项目。输入 flutter 并选择 _New Web Project_
现在,为项目命名。我将其命名为 _open_source_for_you_。
在 VSC 中打开终端窗口,然后输入以下命令:
```
flutter packages pub global activate webdev
@ -42,23 +42,23 @@ flutter packages pub global activate webdev
flutter packages upgrade
```
Now use the following command to run the website, on localhost, with the IP address 127.0.0.1
现在,使用以下命令在 localhost 上运行网站IP 地址是 127.0.0.1。
```
flutter packages pub global run webdev serve
```
Open any browser and type, _<http://127.0.0.1:8080/>_
There is a Web folder inside the project directory which contains an _index.html_ file. The _dart_ file is compiled into a JavaScript file and is included in the HTML file using the following code:
打开任何浏览器,然后输入 _<http://127.0.0.1:8080/>_
在项目目录中有个 Web 文件夹,其中包含了 _index.html__dart_ 文件被编译成 JavaScript 文件,并使用以下代码包含在 HTML 文件中:
```
<script defer src="main.dart.js" type="application/javascript"></script>
```
**Coding and making changes to the demo page**
Lets create a simple application, which will print Welcome to OSFY on the Web page.
Lets now open the Dart file, which is located in the _lib_ folder _main.dart_ (the default name) (see Figure 5).
We can now remove the debug tag using the property of _MaterialApp_, as follows:
**编码和修改演示页面**
让我们创建一个简单的应用,它会在网页上打印 “ Welcome to OSFY”。
现在打开 Dart 文件,它位于 _lib_ 文件夹 _main.dart_(默认名)中(参见图 5
现在,我们可以在 _MaterialApp_ 的属性中删除调试标记,如下所示:
```
debugShowCheckedModeBanner: false
@ -70,8 +70,8 @@ debugShowCheckedModeBanner: false
![Figure 5: Location of main.dart file][7]
Now, adding more into the Dart file is very similar to writing code in Flutter in Dart. For that, we can declare a class titled _MyClass_, which extends the _StatelessWidget_.
We use a _Center_ widget to position elements to the centre. We can also add a _Padding_ widget to add padding. Use the following code to obtain the output shown in Figure 5. Use the Refresh button to view the changes.
现在,向 Dart 中添加更多内容与在 Dart 中编写 Flutter 类似。为此,我们可以声明一个名为 _MyClass_ 的类,它继承了 _StatelessWidget_
我们使用 _Center_ 部件将元素定位到中心。我们还可以添加 _Padding_ 部件来添加填充。使用以下代码获得图 5 所示的输出。使用刷新按钮查看更改。
```
class MyClass extends StatelessWidget {
@ -101,7 +101,7 @@ style: TextStyle(fontSize: 24.0, fontWeight: FontWeight.bold),
![Figure 7: Final output][9]
Lets add an image from the Internet Ive chosen the Open Source for You logo from the magazines website. We use _Image.network_.
让我们从互联网中添加一张图片,我已经从一个杂志网站选择了一张 “Open Source for You” 的 logo。我们使用 _Image.network_
```
Image.network(
@ -111,13 +111,13 @@ width: 150
),
```
The final output is shown in Figure 7.
最终输出如图 7 所示。
![Avatar][10]
[Jis Joe Mathew][11]
The author is assistant professor of computer science and engineering at Amal Jyoti College, Kanirapally, Kerala. He can be contacted at [jisjoemathew@gmail.com][12].
作者是喀拉拉邦卡尼拉帕利阿玛尔·乔蒂学院的计算机科学与工程助理教授。可以通过 [jisjoemathew@gmail.com][12] 与他联系。
[![][13]][14]
@ -127,7 +127,7 @@ via: https://opensourceforu.com/2019/11/developing-a-simple-web-application-usin
作者:[Jis Joe Mathew][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
译者:[geekpi](https://github.com/geekpi)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出