mirror of
https://github.com/LCTT/TranslateProject.git
synced 2024-12-26 21:30:55 +08:00
commit
311a636dcf
@ -0,0 +1,186 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (robsean)
|
||||
[#]: reviewer: (wxy)
|
||||
[#]: publisher: (wxy)
|
||||
[#]: url: (https://linux.cn/article-12956-1.html)
|
||||
[#]: subject: (3 Ways to Install Deb Files on Ubuntu Linux)
|
||||
[#]: via: (https://itsfoss.com/install-deb-files-ubuntu)
|
||||
[#]: author: (Abhishek Prakash https://itsfoss.com/author/abhishek/)
|
||||
|
||||
在 Ubuntu Linux 上安装 Deb 文件的 3 种方法
|
||||
======
|
||||
|
||||
> 这篇初学者文章解释了如何在 Ubuntu 中安装 deb 软件包。它稍后也向你展示如何移除这些 deb 软件包。
|
||||
|
||||
这是 Ubuntu 初学者系列的另一篇文章。如果你对 Ubuntu 很陌生,你可能会想知道 [如何安装应用程序][1]。
|
||||
|
||||
最简单的方法是使用 Ubuntu 软件中心。在软件中心中搜索应用程序的名称并安装它。如果你能在软件中心中找到所有的应用程序,那么生活就太惬意了。但是,不幸的是,这是不可能的发生的。
|
||||
|
||||
一些软件包可以通过 DEB 软件包的形式获得。它们是以 .deb 扩展名为结尾的存档文件。你可以把 .deb 文件看作为 Windows 中的 .exe 文件。在 Windows 中,你双击 .exe 文件,它将开始安装过程。DEB 软件包也是非常类似的。
|
||||
|
||||
你可以从软件提供商网站的下载区域找到这些 DEB 软件包。例如,如果你想 [在 Ubuntu 上安装 Google Chrome][2] ,你可以从它的网站下载 Chrome 的 DEB 软件包。
|
||||
|
||||
现在问题产生了,你将如何安装 deb 文件呢?在 Ubuntu 中有多种安装 DEB 软件包的方法。在这篇教程中,我将向你依次地展示它们。
|
||||
|
||||
![在 Ubuntu 中安装 deb 文件][3]
|
||||
|
||||
### 在 Ubuntu 和基于 Debian 的 Linux 发行版中安装 .deb 文件
|
||||
|
||||
你可以选择一个 GUI 工具或一个命令行工具来安装一个 deb 软件包。你拥有选择权。
|
||||
|
||||
让我们继续看看如何安装 deb 文件。
|
||||
|
||||
#### 方法 1: 使用默认的软件中心
|
||||
|
||||
在 Ubuntu 中,最简单的方法是使用默认的软件中心。在这里你不必要做任何特别的事。只需要转到你所下载的 .deb 文件的文件夹下(它应该是 Downloads 文件夹),并在这个文件上双击。
|
||||
|
||||
![在 Ubuntu 上的 Google Chrome 的 deb 文件][4]
|
||||
|
||||
在已下载的 .deb 文件上双击以开始安装。
|
||||
|
||||
它将打开软件中心,并且你将看到安装软件时的选项。你所需要做的全部工作就是:点击安装按钮并输入你的登录密码。
|
||||
|
||||
![在 Ubuntu 软件中心中安装 Google Chrome][5]
|
||||
|
||||
.deb 文件的安装将通过软件中心来执行。
|
||||
|
||||
看,它甚至比在 Windows 中安装一个 .exe 文件更简单,不是吗?
|
||||
|
||||
#### 方法 2: 使用 Gdebi 应用程序来安装 deb 软件包及其依赖项
|
||||
|
||||
再提一次,如果事情总是进展顺利,生活可能会更简单一些。但是生活并不是我们熟知的那样。
|
||||
|
||||
现在,你已经知道 .deb 文件可以简单地通过软件中心来安装,接下来,让我告诉你一些软件包可能会遇到的依赖项的错误。
|
||||
|
||||
发生错误的原因是,一个程序可能依赖于另外一个软件包(库)。当开发者为你准备 DEB 软件包时,他/她可能会假设你的系统中已经有了所依赖的软件包(库)。
|
||||
|
||||
但是如果情况并不是这样的,你的系统没有这些所需要的软件包(库),你将遇到臭名昭著的“依赖项错误”。
|
||||
|
||||
软件中心不能处理这样的错误,因此你不得不使用另外一个名称为 [gdebi][6] 的工具。
|
||||
|
||||
gdebi 是一个轻量级的 GUI 应用程序,它只有安装 deb 软件包的一个用途。
|
||||
|
||||
它将识别依赖项,并尝试在安装 .deb 文件的同时安装这些依赖项。
|
||||
|
||||
![gdebi 在安装 deb 软件包时处理依赖项][7]
|
||||
|
||||
就我个人而言,我更喜欢使用 gdebi 而不是使用软件包中心来安装 deb 文件。它是一个轻量级应用程序,因此安装过程看起来更快一点。更多的信息,你可以阅读[使用 gDebi ,并使其成为安装 DEB 软件包的默认设置][6]。
|
||||
|
||||
你可以从软件中心或使用下面的命令来安装 gdebi :
|
||||
|
||||
```
|
||||
sudo apt install gdebi
|
||||
```
|
||||
|
||||
#### 方法 3: 在命令行中使用 dpkg 安装 .deb 文件
|
||||
|
||||
如果你想在命令行中安装 deb 软件包,你可以使用 `apt` 命令或者 `dpkg` 命令。实际上,`apt` 命令在底层上使用 [dpkg][9] 命令,但是 `apt` 却更流行和易于使用。
|
||||
|
||||
如果你想对 deb 文件使用 `apt` 命令,像这样使用它:
|
||||
|
||||
```
|
||||
sudo apt install path_to_deb_file
|
||||
```
|
||||
|
||||
如果你想对将要安装的 deb 软件包使用 `dpkg` 命令,在这里是如何完成它:
|
||||
|
||||
```
|
||||
sudo dpkg -i path_to_deb_file
|
||||
```
|
||||
|
||||
在这两个命令中,你应该使用你已下载的 deb 文件的路径和名称来替换 `path_to_deb_file` 。
|
||||
|
||||
![在 Ubuntu 中使用 dpkg 命令安装 deb 文件][10]
|
||||
|
||||
如果你在安装 deb 软件包的过程中得到一个依赖项的错误,你可以使用下面的命令来修复依赖项的问题:
|
||||
|
||||
```
|
||||
sudo apt install -f
|
||||
```
|
||||
|
||||
### 如何移除 deb 软件包
|
||||
|
||||
移除一个 deb 软件包也不是一件什么大事。并且,你不需要用于安装程序的原始的 deb 文件。
|
||||
|
||||
#### 方法 1: 使用 apt 命令移除 deb 软件包
|
||||
|
||||
你所需要的全部东西就是你所已安装程序的名称,接下来你可以使用 `apt` 或 `dpkg` 来移除这个程序。
|
||||
|
||||
```
|
||||
sudo apt remove program_name
|
||||
```
|
||||
|
||||
现在,问题来了,在移除命令中,你如何找到你所需要使用的准确的程序名称?为此,`apt` 命令也有一个解决方案。
|
||||
|
||||
你可以使用 `apt` 命令找到所有已安装文件的列表,但是手动完成这一过程将会是一件令人头疼的事。因此,你可以使用 `grep` 命令来搜索你的软件包。
|
||||
|
||||
例如,在先前的部分中,我已安装 AppGrid 应用程序,但是如果我想知道准确的程序名称,我可以像这样使用一些东西:
|
||||
|
||||
```
|
||||
sudo apt list --installed | grep grid
|
||||
```
|
||||
|
||||
这将给予我全部的名称中含有 “grid” 的软件包,从这里,我可以得到准确的程序名称。
|
||||
|
||||
```
|
||||
apt list --installed | grep grid
|
||||
WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
|
||||
appgrid/now 0.298 all [installed,local]
|
||||
```
|
||||
|
||||
正如你所看到的,一个名称为 “appgrid” 的软件包已经安装。现在,你可以在 `apt remove` 命令中使用这个程序名称。
|
||||
|
||||
#### 方法2: 使用 dpkg 命令移除 deb 软件包
|
||||
|
||||
你可以使用 `dpkg` 来找到已安装程序的名称:
|
||||
|
||||
```
|
||||
dpkg -l | grep grid
|
||||
```
|
||||
|
||||
该输出将给予所有的名称中有 “grid” 的软件包。
|
||||
|
||||
```
|
||||
dpkg -l | grep grid
|
||||
|
||||
ii appgrid 0.298 all Discover and install apps for Ubuntu
|
||||
```
|
||||
|
||||
在上面的命令输出中的 `ii` 意味着软件包已经被正确地安装。
|
||||
|
||||
现在,你有了程序名称,你可以使用 `dpkg` 命令来移除它:
|
||||
|
||||
```
|
||||
dpkg -r program_name
|
||||
```
|
||||
|
||||
**提示:更新 deb 软件包**
|
||||
|
||||
一些 deb 软件包 (像 Chrome)通过系统更新来提供其更新,但是对于大多数的其它的程序,你将不得不先移除已存在的程序,并在接下来安装更新的版本。
|
||||
|
||||
我希望这篇初学者指南能够帮助你在 Ubuntu 上安装 deb 软件包。我添加了移除部分,以便你可以更好地控制你所安装的程序。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://itsfoss.com/install-deb-files-ubuntu
|
||||
|
||||
作者:[Abhishek Prakash][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[robsean](https://github.com/robsean)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://itsfoss.com/author/abhishek/
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://itsfoss.com/remove-install-software-ubuntu/
|
||||
[2]: https://itsfoss.com/install-chrome-ubuntu/
|
||||
[3]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2019/02/deb-packages-ubuntu.png?resize=800%2C450&ssl=1
|
||||
[4]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2019/01/install-google-chrome-ubuntu-4.jpeg?resize=800%2C347&ssl=1
|
||||
[5]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2019/01/install-google-chrome-ubuntu-5.jpeg?resize=800%2C516&ssl=1
|
||||
[6]: https://itsfoss.com/gdebi-default-ubuntu-software-center/
|
||||
[7]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2019/01/gdebi-handling-dependency.jpg?ssl=1
|
||||
[8]: http://xmodulo.com
|
||||
[9]: https://help.ubuntu.com/lts/serverguide/dpkg.html.en
|
||||
[10]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2019/02/install-deb-file-with-dpkg.png?ssl=1
|
||||
[11]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2019/02/deb-packages-ubuntu.png?fit=800%2C450&ssl=1
|
@ -0,0 +1,172 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (quinbyjoe)
|
||||
[#]: reviewer: (wxy)
|
||||
[#]: publisher: (wxy)
|
||||
[#]: url: (https://linux.cn/article-12927-1.html)
|
||||
[#]: subject: (How to Use VLAN tagged NIC \(Ethernet Card\) on CentOS and RHEL Servers)
|
||||
[#]: via: (https://www.linuxtechi.com/vlan-tagged-nic-ethernet-card-centos-rhel-servers/)
|
||||
[#]: author: (Pradeep Kumar https://www.linuxtechi.com/author/pradeep/)
|
||||
|
||||
如何在 CentOS/RHEL 系统中使用带 VLAN 标记的网卡
|
||||
======
|
||||
|
||||
在某些场景中,我们希望在 Linux 服务器(CentOS/RHEL)的同一块以太网卡(NIC)上分配来自不同 VLAN 的多个 IP。这个可以通过使用 VLAN 标记接口来实现。但是要做到这一点,我们必须确保交换机的端口上连接了多个 VLAN,也就是说我们可以在交换机上添加多个 VLAN 来配置<ruby>聚合端口<rt>Trunk port</rt></ruby>(LCTT 译注:一般有<ruby>聚合端口<rt>Trunk port</rt></ruby>、<ruby>接入端口<rt>Access port</rt></ruby>、<ruby>混合端口<rt>Hybird port</rt></ruby>三种)。
|
||||
|
||||
![](https://img.linux.net.cn/data/attachment/album/202012/17/123821uvv3oyonqnhn2bqq.jpg)
|
||||
|
||||
假设我们有一个 Linux 服务器,我们在这里有两张以太网卡(`enp0s3` 和 `enp0s8`),第一张网卡(`enp0s3`)会用于数据传输,而第二张网卡(`enp0s8`) 会用于控制/流量管理。我会使用多个 VLAN 用于数据传输(或在数据流量网卡上从不同的 VLAN 中分配多个 IP)。
|
||||
|
||||
我假设连接到我服务器的数据网卡的端口,是通过映射多个 VLAN 来配置为聚合端口。
|
||||
|
||||
下面是映射到数据传输网卡(NIC)的 VLAN:
|
||||
|
||||
* VLAN ID (200), VLAN N/W = 172.168.10.0/24
|
||||
* VLAN ID (300), VLAN N/W = 172.168.20.0/24
|
||||
|
||||
要在 CentOS 7 / RHEL 7 / CentOS 8 / RHEL 8 系统中使用 VLAN 标记接口,必须加载[内核模块][1] `8021q` 。
|
||||
|
||||
加载内核模块 `8021q` 可以使用下面的命令:
|
||||
|
||||
```
|
||||
[root@linuxtechi ~]# lsmod | grep -i 8021q
|
||||
[root@linuxtechi ~]# modprobe --first-time 8021q
|
||||
[root@linuxtechi ~]# lsmod | grep -i 8021q
|
||||
8021q 29022 0
|
||||
garp 14384 1 8021q
|
||||
mrp 18542 1 8021q
|
||||
[root@linuxtechi ~]#
|
||||
```
|
||||
|
||||
可以使用 `modinfo` 命令显示内核模块 `8021q` 的详细信息:
|
||||
|
||||
```
|
||||
[root@linuxtechi ~]# modinfo 8021q
|
||||
filename: /lib/modules/3.10.0-327.el7.x86_64/kernel/net/8021q/8021q.ko
|
||||
version: 1.8
|
||||
license: GPL
|
||||
alias: rtnl-link-vlan
|
||||
rhelversion: 7.2
|
||||
srcversion: 2E63BD725D9DC11C7DA6190
|
||||
depends: mrp,garp
|
||||
intree: Y
|
||||
vermagic: 3.10.0-327.el7.x86_64 SMP mod_unload modversions
|
||||
signer: CentOS Linux kernel signing key
|
||||
sig_key: 79:AD:88:6A:11:3C:A0:22:35:26:33:6C:0F:82:5B:8A:94:29:6A:B3
|
||||
sig_hashalgo: sha256
|
||||
[root@linuxtechi ~]#
|
||||
```
|
||||
|
||||
现在使用 [ip 命令][2]给 `enp0s3` 网卡标记(或映射)上 `200` 和 `300` 的 VLAN 。
|
||||
|
||||
(LCTT 译注:这是先给 `enp0s3` 网卡映射上 `200` 的 VLAN 标签。)
|
||||
|
||||
```
|
||||
[root@linuxtechi ~]# ip link add link enp0s3 name enp0s3.200 type vlan id 200
|
||||
```
|
||||
|
||||
使用下面的 `ip` 命令打开接口:
|
||||
|
||||
```
|
||||
[root@linuxtechi ~]# ip link set dev enp0s3.200 up
|
||||
```
|
||||
|
||||
同理给 `enp0s3` 网卡映射上 `300` 的 VLAN 标签:
|
||||
|
||||
```
|
||||
[root@linuxtechi ~]# ip link add link enp0s3 name enp0s3.300 type vlan id 300
|
||||
[root@linuxtechi ~]# ip link set dev enp0s3.300 up
|
||||
```
|
||||
|
||||
现在使用 `ip` 命令查看标记后的接口状态:
|
||||
|
||||
![tagged-interface-ip-command][3]
|
||||
|
||||
现在我们可以使用下面的 `ip` 命令从它们各自的 VLAN 为已经标记的接口分配 IP 地址:
|
||||
|
||||
```
|
||||
[root@linuxtechi ~]# ip addr add 172.168.10.51/24 dev enp0s3.200
|
||||
[root@linuxtechi ~]# ip addr add 172.168.20.51/24 dev enp0s3.300
|
||||
```
|
||||
|
||||
使用下面的 `ip` 命令查看是否为已标记的接口分配到 IP:
|
||||
|
||||
![ip-address-tagged-nic][5]
|
||||
|
||||
重启之后,上面所有通过 `ip` 命令的更改都不会保持(LCTT 译注:修改后可保存至配置文件或数据库中,如果未进行保存处理,则只有当前环境生效,重启后配置失效)。系统重启和网络服务重启(LCTT 译注:`service network restart`,或 `down` 和 `up` 命令)之后这些标记接口将不可用。
|
||||
|
||||
因此,要使标记的接口在重启后保持不变,需要使用接口的 `ifcfg` 文件。
|
||||
|
||||
编辑接口(`enp0s3`)文件 `/etc/sysconfig/network-scripts/ifcfg-enp0s3`,并且增加下面的内容:
|
||||
|
||||
**作者提醒**:替换为你环境中的接口名称。
|
||||
|
||||
```
|
||||
[root@linuxtechi ~]# vi /etc/sysconfig/network-scripts/ifcfg-enp0s3
|
||||
TYPE=Ethernet
|
||||
DEVICE=enp0s3
|
||||
BOOTPROTO=none
|
||||
ONBOOT=yes
|
||||
```
|
||||
|
||||
保存和退出文件。
|
||||
|
||||
为 id 是 `200` 的 VLAN 创建接口文件 `/etc/sysconfig/network-scripts/ifcfg-enp0s3.200`,且增加下面的内容:
|
||||
|
||||
```
|
||||
[root@linuxtechi ~]# vi /etc/sysconfig/network-scripts/ifcfg-enp0s3.200
|
||||
DEVICE=enp0s3.200
|
||||
BOOTPROTO=none
|
||||
ONBOOT=yes
|
||||
IPADDR=172.168.10.51
|
||||
PREFIX=24
|
||||
NETWORK=172.168.10.0
|
||||
VLAN=yes
|
||||
```
|
||||
|
||||
保存并退出此文件。
|
||||
|
||||
同理为 id 是 `300` 的 VLAN 创建接口文件 `/etc/sysconfig/network-scripts/ifcfg-enp0s3.300`,且增加下面的内容:
|
||||
|
||||
```
|
||||
[root@linuxtechi ~]# vi /etc/sysconfig/network-scripts/ifcfg-enp0s3.300
|
||||
DEVICE=enp0s3.300
|
||||
BOOTPROTO=none
|
||||
ONBOOT=yes
|
||||
IPADDR=172.168.20.51
|
||||
PREFIX=24
|
||||
NETWORK=172.168.20.0
|
||||
VLAN=yes
|
||||
```
|
||||
|
||||
保存并退出文件,这时候使用下面的命令重启网络服务,
|
||||
|
||||
```
|
||||
[root@linuxtechi ~]# systemctl restart network
|
||||
```
|
||||
|
||||
现在使用下面的 `ip` 命令检验标记的接口是否已配置和启动,并且正在运行中:
|
||||
|
||||
![tagged-interface-status-ip-command-linux-server][6]
|
||||
|
||||
以上就是本文的全部内容,我希望你已经学会了在 CentOS 7 / 8 和 RHEL 7 / 8 服务器上如何去配置和启用 VLAN 标签接口的方法。请分享你的反馈和意见。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.linuxtechi.com/vlan-tagged-nic-ethernet-card-centos-rhel-servers/
|
||||
|
||||
作者:[Pradeep Kumar][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[quinbyjoe](https://github.com/quinbyjoe)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://www.linuxtechi.com/author/pradeep/
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://www.linuxtechi.com/how-to-manage-kernel-modules-in-linux/
|
||||
[2]: https://www.linuxtechi.com/ip-command-examples-for-linux-users/
|
||||
[3]: https://www.linuxtechi.com/wp-content/uploads/2019/06/tagged-interface-ip-command-1024x444.jpg
|
||||
[4]: https://www.linuxtechi.com/wp-content/uploads/2019/06/tagged-interface-ip-command.jpg
|
||||
[5]: https://www.linuxtechi.com/wp-content/uploads/2019/06/ip-address-tagged-nic-1024x343.jpg
|
||||
[6]: https://www.linuxtechi.com/wp-content/uploads/2019/06/tagged-interface-status-ip-command-linux-server-1024x656.jpg
|
||||
[7]: https://www.linuxtechi.com/wp-content/uploads/2019/06/VLAN-Tagged-NIC-Linux-Server.jpg
|
@ -0,0 +1,158 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (zxp93)
|
||||
[#]: reviewer: (wxy)
|
||||
[#]: publisher: (wxy)
|
||||
[#]: url: (https://linux.cn/article-12935-1.html)
|
||||
[#]: subject: (How I use Python to map the global spread of COVID-19)
|
||||
[#]: via: (https://opensource.com/article/20/4/python-map-covid-19)
|
||||
[#]: author: (AnuragGupta https://opensource.com/users/999anuraggupta)
|
||||
|
||||
如何使用 Python 绘制 COVID-19 的全球扩散图
|
||||
======
|
||||
|
||||
> 使用这些开源框架创建一个彩色地图,显示病毒的可能的传播路径。
|
||||
|
||||
![](https://img.linux.net.cn/data/attachment/album/202012/20/005146t8voetski8ocm5c2.jpg)
|
||||
|
||||
对于一个全球旅行司空见惯的世界来说,疾病的传播是一个真正令人担忧的问题。一些组织会跟踪重大的流行病(还有所有普遍的流行病),并将他们的跟踪工作获得的数据公开出来。不过,这些原始的数据对人来说可能很难处理,这就是为什么数据科学如此重要的原因。比如,用 Python 和 Pandas 可视化 COVID-19 在全球范围内的传播路径可能对这些数据的分析有所帮助。
|
||||
|
||||
最开始,当面对如此大数量的原始数据时可能难以下手。但当你开始处理数据之后,慢慢地就会发现一些处理数据的方式。下面是用于处理 COVID-19 数据的一些常见的情况:
|
||||
|
||||
1. 从 GitHub 上下载 COVID-19 的国家每日传播数据,保存为一个 Pandas 中的 DataFrame 对象。这时你需要使用 Python 中的 Pandas 库。
|
||||
2. 处理并清理下载好的数据,使其满足可视化数据的输入格式。所下载的数据的情况很好(数据规整)。这个数据有一个问题是它用国家的名字来标识国家,但最好是使用三位数的 ISO 3 码(国家代码表)来标识国家。为了生成 ISO 3 码,可是使用 `pycountry` 这个 Python 库。生成了这些代码之后,可以在原有的 DataFrame 上增加一列,然后用这些代码填充进去。
|
||||
3. 最后为了实现可视化,使用 Plotly 库中的 `express` 模块。这篇文章是使用名为choropleth 的地图(可在 Plotly 库中获得)来可视化该疾病在全球的传播。
|
||||
|
||||
### 第一步:Corona 数据
|
||||
|
||||
从下面这个网站上下载最新的 corona 数据(LCTT 译注:2020-12-14 仍可访问,有墙):
|
||||
|
||||
- <https://raw.githubusercontent.com/datasets/covid-19/master/data/countries-aggregated.csv>
|
||||
|
||||
我们之间将这个下载好的数据载入为 Pandas 的 DataFrame。Pandas 提供了一个函数, `read_csv()`,可以直接使用 URL 读取数据,并返回一个 DataFrame 对象,具体如下所示:
|
||||
|
||||
```
|
||||
import pycountry
|
||||
import plotly.express as px
|
||||
import pandas as pd
|
||||
URL_DATASET = r'https://raw.githubusercontent.com/datasets/covid-19/master/data/countries-aggregated.csv'
|
||||
df1 = pd.read_csv(URL_DATASET)
|
||||
print(df1.head(3)) # Get first 3 entries in the dataframe
|
||||
print(df1.tail(3)) # Get last 3 entries in the dataframe
|
||||
```
|
||||
|
||||
在 Jupyter 上的输出截图:
|
||||
|
||||
![Jupyter screenshot][2]
|
||||
|
||||
从这个输出可以看到这个 DataFrame(`df1`)包括以下几列数据:
|
||||
|
||||
1. `Date`
|
||||
2. `Country`
|
||||
3. `Confirmed`
|
||||
4. `Recovered`
|
||||
5. `Dead`
|
||||
|
||||
之后还可以看到 `Date` 这一列包含了从 1 月 22 日到 3 月 31 日的条目信息。这个数据是每天更新的,所以你会得到你当天的值。
|
||||
|
||||
### 第二步:清理和修改 DataFrame
|
||||
|
||||
我们要往这个 DataFrame 中增加一列数据,就是那个包含了 ISO 3 编码。可以通过以下三步完成这个任务:
|
||||
|
||||
1. 创建一个包含所有国家的列表。因为在 `df1` 的 `Country` 列中,国家都是每个日期就重复一次。所以实际上 `Country` 列中对每个国家就会有多个条目。我使用 `unique().tolist()` 函数完成这个任务。
|
||||
2. 我使用 `d_country_code` 字典对象(初始为空),然后将其键设置为国家的名称,然后它的值设置为其对应的 ISO 3 编码。
|
||||
3. 我使用 `pycountry.countries.search_fuzzy(country)` 为每个国家生成 ISO 3 编码。你需要明白的是这个函数的返回值是一个 `Country` 对象的列表。我将这个函数的返回值赋给 `country_data` 对象。以这个对象的第一个元素(序号 `0`)为例。这个 `\` 对象有一个 `alpha_3` 属性。所以我使用 `country_data[0].alpha_3` 就能“获得”第一个元素的 ISO 3 编码。然而,在这个 DataFrame 中有些国家的名称可能没有对应的 ISO 3 编码(比如有争议的领土)。那么对这些“国家/地区”,我就用一个空白字符串来替代 ISO 3 编码。你也可以用一个 `try-except` 代码来替换这部分。`except` 中的语句可以写:`print(‘could not add ISO 3 code for ->', country)`。这样就能在找不到这些“国家/地区”对应的 ISO 3 编码时给出一个输出提示。实际上,你会发现这些“国家/地区”会在最后的输出中用白色来表示。
|
||||
4. 在获得了每个国家的 ISO 3 编码(有些是空白字符串)之后,我把这些国家的名称(作为键)还有国家对应的 ISO 3 编码(作为值)添加到之前的字典 `d_country_code` 中。可以使用 Python 中字典对象的 `update()` 方法来完成这个任务。
|
||||
5. 在创建好了一个包含国家名称和对应 ISO 3 编码的字典之后,我使用一个简单的循环将他们加入到 DataFrame 中。
|
||||
|
||||
### 第三步:使用 Plotly 可视化传播路径
|
||||
|
||||
choropleth 地图是一个由彩色多边形组成的地图。它常常用来表示一个变量在空间中的变化。我们使用 Plotly 中的 `px` 模块来创建 choropleth 图,具体函数为:`px.choropleth`。
|
||||
|
||||
这个函数的所包含的参数如下:
|
||||
|
||||
```
|
||||
plotly.express.choropleth(data_frame=None, lat=None, lon=None, locations=None, locationmode=None, geojson=None, featureidkey=None, color=None, hover_name=None, hover_data=None, custom_data=None, animation_frame=None, animation_group=None, category_orders={}, labels={}, color_discrete_sequence=None, color_discrete_map={}, color_continuous_scale=None, range_color=None, color_continuous_midpoint=None, projection=None, scope=None, center=None, title=None, template=None, width=None, height=None)
|
||||
```
|
||||
|
||||
`choropleth()` 这个函数还有几点需要注意:
|
||||
|
||||
1. `geojson` 是一个 `geometry` 对象(上面函数第六个参数)。这个对象有点让人困扰,因为在函数文档中没有明确地提到这个对象。你可以提供,也可以不提供 `geojson` 对象。如果你提供了 `geojson` 对象,那么这个对象就会被用来绘制地球特征,如果不提供 `geojson` 对象,那这个函数默认就会使用一个内建的 `geometry` 对象。(在我们的实验中,我们使用内建的 `geometry` 对象,因此我们不会为 `geojson` 参数提供值)
|
||||
2. DataFrame 对象有一个 `data_frame` 属性,在这里我们先前就提供了一个我们创建好的`df1`。
|
||||
3. 我们用 `Confirmed`(确诊数)来决定每个国家多边形的颜色。
|
||||
4. 最后,我们 `Date` 列创建一个 `animation_frame`。这样我们就能通过日期来划分数据,国家的颜色会随着 `Confirmed` 的变化而变化。
|
||||
|
||||
最后完整的代码如下:
|
||||
|
||||
```
|
||||
import pycountry
|
||||
import plotly.express as px
|
||||
import pandas as pd
|
||||
# ----------- Step 1 ------------
|
||||
URL_DATASET = r'https://raw.githubusercontent.com/datasets/covid-19/master/data/countries-aggregated.csv'
|
||||
df1 = pd.read_csv(URL_DATASET)
|
||||
# print(df1.head) # Uncomment to see what the dataframe is like
|
||||
# ----------- Step 2 ------------
|
||||
list_countries = df1['Country'].unique().tolist()
|
||||
# print(list_countries) # Uncomment to see list of countries
|
||||
d_country_code = {} # To hold the country names and their ISO
|
||||
for country in list_countries:
|
||||
try:
|
||||
country_data = pycountry.countries.search_fuzzy(country)
|
||||
# country_data is a list of objects of class pycountry.db.Country
|
||||
# The first item ie at index 0 of list is best fit
|
||||
# object of class Country have an alpha_3 attribute
|
||||
country_code = country_data[0].alpha_3
|
||||
d_country_code.update({country: country_code})
|
||||
except:
|
||||
print('could not add ISO 3 code for ->', country)
|
||||
# If could not find country, make ISO code ' '
|
||||
d_country_code.update({country: ' '})
|
||||
|
||||
# print(d_country_code) # Uncomment to check dictionary
|
||||
|
||||
# create a new column iso_alpha in the df
|
||||
# and fill it with appropriate iso 3 code
|
||||
for k, v in d_country_code.items():
|
||||
df1.loc[(df1.Country == k), 'iso_alpha'] = v
|
||||
|
||||
# print(df1.head) # Uncomment to confirm that ISO codes added
|
||||
# ----------- Step 3 ------------
|
||||
fig = px.choropleth(data_frame = df1,
|
||||
locations= "iso_alpha",
|
||||
color= "Confirmed", # value in column 'Confirmed' determines color
|
||||
hover_name= "Country",
|
||||
color_continuous_scale= 'RdYlGn', # color scale red, yellow green
|
||||
animation_frame= "Date")
|
||||
|
||||
fig.show()
|
||||
```
|
||||
|
||||
这段代码的输出就是下面这个图的内容:
|
||||
|
||||
![Map][3]
|
||||
|
||||
你可以从这里下载并运行[完整代码][4]。
|
||||
|
||||
最后,这里还有一些关于 Plotly 绘制 choropleth 图的不错的资源。
|
||||
|
||||
* <https://github.com/plotly/plotly.py/blob/master/doc/python/choropleth-maps.md>
|
||||
* <https://plotly.com/python/reference/#choropleth>
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/20/4/python-map-covid-19
|
||||
|
||||
作者:[AnuragGupta][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[zhangxiangping](https://github.com/zxp93)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/999anuraggupta
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/cloud-globe.png?itok=_drXt4Tn (Globe up in the clouds)
|
||||
[2]: https://opensource.com/sites/default/files/uploads/jupyter_screenshot.png (Jupyter screenshot)
|
||||
[3]: https://opensource.com/sites/default/files/uploads/map_2.png (Map)
|
||||
[4]: https://github.com/ag999git/jupyter_notebooks/blob/master/corona_spread_visualization
|
||||
[5]: tmp.azs72dmHFd#choropleth
|
@ -0,0 +1,90 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (mengxinayan)
|
||||
[#]: reviewer: (wxy)
|
||||
[#]: publisher: (wxy)
|
||||
[#]: url: (https://linux.cn/article-12926-1.html)
|
||||
[#]: subject: (How to influence people to join open source)
|
||||
[#]: via: (https://opensource.com/article/20/10/influence-open-source)
|
||||
[#]: author: (Joshua Pearce https://opensource.com/users/jmpearce)
|
||||
|
||||
如何感召人们让其参与到开源活动中
|
||||
======
|
||||
|
||||
> 向他人介绍开源最有效的办法是,告诉他们开源可以提供给他们想要的。
|
||||
|
||||
![建筑物中的管道][1]
|
||||
|
||||
如果你在浏览这里,可能你会编程,而且或许你正使用某些难以捉摸的 [Linux 发行版][2]的开源浏览器上阅读这些内容。你也许很多年没有看到过浏览器广告了,因为你正运行着一个[开源的广告拦截器][3]。当你想到企鹅时,你感到温暖而又陌生。
|
||||
|
||||
简单地说,你知道开源的力量,并且它已经成了你生活的一部分。不幸的是,并不是每个人都发现了如何利用开源的方式。他们的电脑慢得令人痛苦,当他们上网浏览时他们看到的广告比内容都多,他们把钱花在专利和版权的垃圾上。这些人中可能有些是与你有关系的,例如你的侄女和侄子。
|
||||
|
||||
### 知识就是财富
|
||||
|
||||
那么你如何向你的侄女和侄子(以及任意一个人)介绍开源?
|
||||
|
||||
我尝试着回答这个问题,作为一个教授,一个以长篇大论著称的职业,我最终还是出了一本书:[《使用开源项目创造、分享和省钱》][4],由 McGraw-Hill 出版。
|
||||
|
||||
我认为诀窍在于先发现你的侄女或侄子想要获取但没有钱去购买的东西,然后向他们展示如何通过开源知识来得到他们想要的东西。
|
||||
|
||||
![可升降的桌子][5]
|
||||
|
||||
*[可升降的桌子][6] (Joni Steiner and Nick Ierodiaconou, [CC-BY-SA-NC][7])*
|
||||
|
||||
知识是所有商品里独特的财富。不像黄金或小麦,它不仅在分享时会保留价值,而且可以迅速增值。因为互联网信息分享成本趋近于零,因此无限地扩展了此过程。每个可以访问互联网的人都史无前例地拥有这一财富。例如,我提供[免费的仓库链接][4]到关于书籍、教育、电影、攻略、地图、音乐、照片、艺术品、软件和烹饪等内容。
|
||||
|
||||
### 不要买,而是去制作它
|
||||
|
||||
免费和开源逐渐扩展到现实世界,我们现在有机会从根本上降低通过沃尔玛或亚马逊购买的东西的成本,包括[玩具][8]、[电器][9]、[家居用品][10]和衣服。使用 3D 打印或类似的工具,结合开源分享和数字制造,使得每个人可以制造属于他们自己的复杂的、有用的工具。
|
||||
|
||||
![3D 打印的家居用品][11]
|
||||
|
||||
*[3D 打印的家居用品][12] (Joshua M. Pearce, [CC BY-SA 3.0][13])*
|
||||
|
||||
前些年,科学家已经[在他们的实验室][14]中做这些工作了。但是现在,任何人都可以轻松地定制满足他们具体需求的产品。已经有数百万个免费的设计可供使用。
|
||||
|
||||
![Recyclebot][15]
|
||||
|
||||
*[Recyclebot][16] (Joshua M. Pearce, [GPLv3][17])*
|
||||
|
||||
真正降低一个产品的价格,就要[通过垃圾来获取其原材料][18]。伴随着小规模的回收利用过程(例如我实验室正在使用的 [Recyclebots][19])最近得到了改进,这使得人们可以从废物中制造有用的产品,因此产生了一系列让人眼花缭乱的产品。最重要的是,任何人都可以利用专有系统的一小部分成本来获取到这些定制的绿色产品。我们生产出相比常规商品的销售税更低的[定制产品][20]——它们具有相同的功能,更好的定制形式,而且几乎没有成本。
|
||||
|
||||
### 了解更多
|
||||
|
||||
在[《使用开源项目创建、分享和省钱的项目》][4]一书中,我分享了在家庭制造和回收利用的潜力,以及如何利用开源来为大宗商品评分,如房屋、电力。你可以在我和 Megan Krieger 以及 Janet Callahan 三人为密歇根理工学院的 [Husky Bites][21] 录制的网络研讨会了解更多。
|
||||
|
||||
希望这些知识能足够激励你把一到两个侄女或侄子带到开源的路上来!
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/20/10/influence-open-source
|
||||
|
||||
作者:[Joshua Pearce][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[萌新阿岩](https://github.com/mengxinayan)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/jmpearce
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/open_pipe_red_hat_tower_building.png?itok=8ho3yi7L (pipe in a building)
|
||||
[2]: https://distrowatch.com/
|
||||
[3]: https://opensource.com/article/20/4/ad-blockers
|
||||
[4]: https://www.appropedia.org/Create,_Share,_and_Save_Money_Using_Open-Source_Projects
|
||||
[5]: https://opensource.com/sites/default/files/uploads/opendesk_furniture_lift-standing-desk.jpg (Lift Standing Desk)
|
||||
[6]: https://www.appropedia.org/File:Opendesk_furniture_lift-standing-desk.jpg
|
||||
[7]: https://creativecommons.org/licenses/by-nc-sa/2.0/
|
||||
[8]: http://www.mdpi.com/2227-7080/5/3/45
|
||||
[9]: https://doi.org/10.3390/inventions3030064
|
||||
[10]: https://www.mdpi.com/2227-7080/5/1/7
|
||||
[11]: https://opensource.com/sites/default/files/uploads/3dprinted_household.jpg (3D printed household items)
|
||||
[12]: https://www.appropedia.org/File:3dprinted_household.JPG
|
||||
[13]: https://creativecommons.org/licenses/by-sa/3.0/
|
||||
[14]: https://opensource.com/article/20/10/open-source-hardware-savings
|
||||
[15]: https://opensource.com/sites/default/files/uploads/recyclebotrep.png (Recyclebot)
|
||||
[16]: https://www.appropedia.org/File:Recyclebotrep.png
|
||||
[17]: https://www.gnu.org/licenses/gpl-3.0.html
|
||||
[18]: https://www.academia.edu/34738483/Tightening_the_Loop_on_the_Circular_Economy_Coupled_Distributed_Recycling_and_Manufacturing_with_Recyclebot_and_RepRap_3-D_Printing
|
||||
[19]: https://www.appropedia.org/Recyclebot
|
||||
[20]: https://opensource.com/article/17/3/how-to-create-consumer-goods-open-hardware
|
||||
[21]: https://www.facebook.com/Michigan-Tech-College-of-Engineering-109353424030003/videos/husky-bites-presents-special-guest-joshua-m-pearce/2669023713361207/
|
@ -0,0 +1,134 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (zxp93)
|
||||
[#]: reviewer: (wxy)
|
||||
[#]: publisher: (wxy)
|
||||
[#]: url: (https://linux.cn/article-12941-1.html)
|
||||
[#]: subject: (The state of the art of microservices in 2020)
|
||||
[#]: via: (https://www.linux.com/news/the-state-of-the-art-of-microservices-in-2020/)
|
||||
[#]: author: (Linux.com Editorial Staff https://www.linux.com/author/linuxdotcom/)
|
||||
|
||||
2020 年微服务现状
|
||||
======
|
||||
|
||||
![](https://img.linux.net.cn/data/attachment/album/202012/22/122634t2hwh2hh12bvrbsd.jpg)
|
||||
|
||||
> “微服务架构风格是一种将 **单个应用程序** 开发为一套 **小型服务** 的方法,每个服务都在 **自己的进程中运行,并使用轻量级的通信机制(通常是 HTTP 类型的 API)进行通信**。这些服务是围绕 **业务能力** 构建的,并且可以通过 **全自动化的部署机制** 进行 **独立部署**。目前对这些服务几乎没有集中的管理,这些服务可以用 **不同的编程语言** 编写,也能使用 **不同的数据存储技术**。”
|
||||
>
|
||||
> —— James Lewis 和 Martin Fowler (2014) [^6]
|
||||
|
||||
### 介绍
|
||||
|
||||
预计在 2020 年,全球云端的微服务市场将以 22.5% 的速度增长,其中美国市场预计将保持 27.4% 的增长率[^5]。目前的趋势是,开发人员将从本地托管的应用程序转移到云端。这将有助于企业最大限度地减少停机时间、优化资源并降低基础设施成本。同时专家们还预测,到了 2022 年,90% 的应用程序将会使用微服务架构进行开发[^5]。本文将帮助你了解什么是微服务,以及目前的公司如何使用它的。
|
||||
|
||||
### 什么是微服务?
|
||||
|
||||
微服务已经在全球范围内被广泛使用。但是,微服务到底是什么?微服务是一种基于许多小型、互联服务的体系结构模式。它们基于 **单一责任原则**。根据 Robert C. Martin 的说法,“将因相同原因而变化的事物聚集起来,将因不同原因而变化的事物分离开来”。[^2]微服务架构也被扩展到了 **松耦合服务** 中,可以 **独立地开发、部署和维护**[^2]。
|
||||
|
||||
### 远离单体架构
|
||||
|
||||
微服务通常和传统的单体软件架构做对比。在单体架构中,软件是被设计为自足的,也就是说,这个程序中的各个组件都是互相连通和互相依赖的,而不是松散耦合的。在一个紧耦合的架构中(<ruby>单体<rt>monolithic</rt></ruby>),每个组件和它相关联的组件必须按照指定的顺序组合起来,才能被执行或编译[^7]。当其中有一个组件需要更新时,整个应用都要被重写。
|
||||
|
||||
而这个现象在使用微服务架构的应用中就不会出现。因为每一个模块都是独立的,每个模块都可以更新修改而不影响程序的其他部分。因此,降低了对更改一个组件会对其他组件造成影响的风险。
|
||||
|
||||
如果公司的架构很难升级,或者维护过于复杂和昂贵,那么他们可能会遇到麻烦,不能扩展单体架构的应用[^4]。把一个复杂的任务分解成小组件,彼此独立工作,就是解决这个问题的方法。
|
||||
|
||||
![][1]
|
||||
|
||||
*单一体系架构 vs. 微服务架构 (图片来自 [^3])*
|
||||
|
||||
### 开发者如何构建属于自己的微服务
|
||||
|
||||
微服务以提高*可扩展性*和*性能*而闻名。然而,这些是世界各地的开发者开发属于他们自己的微服务的主要原因吗?《微服务 2020 研究现状》[^1]披露了全球开发者如何构建他们的微服务,以及他们对微服务的看法。这份报告是在来自欧洲、北美、中南美洲、中东、东南亚、澳大利亚和新西兰的 660 名微服务专家的帮助下完成的。下表列出了微服务成熟度相关问题的平均评分[^1]:
|
||||
|
||||
**分类** | **平均得分(满分为5分)**
|
||||
---|---
|
||||
创建新项目 | 3.8
|
||||
维护与调试 | 3.4
|
||||
工作效率 | 3.9
|
||||
解决可扩展性问题 | 4.3
|
||||
解决性能问题 | 3.9
|
||||
团队合作 | 3.9
|
||||
|
||||
从上表可知,大部分专家都对使用微服务来解决可扩展性问题感到满意。与之相反的是,维护与调试对他们来说似乎是一个挑战。
|
||||
|
||||
从他们所使用的架构技术来说,大部分专家使用 Javascript/Typescript (大约 ⅔ 的微服务是使用这些语言构建的),其次使用的是 Java。
|
||||
|
||||
尽管有很多部署微服务的选择,但大多数专家使用 AWS(49%),其次是他们自己的服务器。另外,有 62% 的人更喜欢用 AWS Lambda 作为无服务器解决方案。
|
||||
|
||||
这些人所使用的大多数微服务都使用 HTTP 进行通信,其次是 events 和 gRPC。此外,大多数专家将 RabbitMQ 用于消息代理,其次是 Kafka 和 Redis。
|
||||
|
||||
而且,大多数人使用微服务持续集成(CI)。在报告中,87% 的受访者使用诸如 GitLab CI、Jenkins 或 GitHub Actions 等 CI 解决方案。
|
||||
|
||||
在 86% 的受访者中,最受欢迎的调试解决方案是日志,其中 27% 的受访者**只**使用日志。
|
||||
|
||||
最后,大多数人认为微服务架构将成为更复杂的系统或后端开发的标准。
|
||||
|
||||
### 微服务的成功案例
|
||||
|
||||
许多公司已经从单体架构转向微服务架构。
|
||||
|
||||
#### 亚马逊
|
||||
|
||||
在 2001 年,开发延迟、编码挑战和服务相互依赖性使得<ruby>亚马逊<rt>Amazon</rt></ruby>无法满足其不断增长的用户群的可扩展性需求。由于需要从头开始重构他们的单体架构,亚马逊将其单体架构应用程序拆分为小型的、独立的、针对服务的应用程序[^3][^9]。
|
||||
|
||||
2001 年,在微服务这个词开始流行之前的几年,亚马逊决定改用微服务。这一变化使得亚马逊开发了好几种支持微服务架构的解决方案,比如亚马逊 AWS。随着对微服务的快速增长和适应,亚马逊成为全球市值最高的公司,截至 2020 年 7 月 1 日,亚马逊市值为 1.433 万亿美元[^8]。
|
||||
|
||||
#### 奈飞
|
||||
|
||||
<ruby>奈飞<rt>Netflix</rt></ruby>于 2007 年开始提供电影流媒体服务,到了 2008 年,它也面临着规模扩张的挑战。期间,他们经历了一次严重的数据库损坏,在三天之内,他们不能将 DVD 发送给他们的会员[^10]。这一事故使他们意识到需要将单点故障(如关系数据库)转向云中更可伸缩和更可靠的分布式系统。于是 2009 年,奈飞开始将其单体架构的应用重构为微服务。他们首先将其非面向客户的电影编码平台迁移到云端作为独立的微服务运行[^11]。在改用微服务之后,使奈飞能够解决扩展性挑战和服务中断的问题。并且它还允许他们按照每个流数据而不是数据中心的成本来降低成本[^10]。今天,奈飞每天向 190 个国家的 1.39 亿订户发送约 2.5 亿小时的内容[^11]。
|
||||
|
||||
#### Uber
|
||||
|
||||
在推出 Uber 服务之后,他们在开发和发布新功能、修复 bug,以及迅速整合新的变化方面遇到了困难。因此,他们决定改用微服务,并将应用程序结构拆分为基于云的微服务。换句话说,Uber 为每个功能创建了一个微服务,比如乘客管理和出行管理。转向微服务给 Uber 带来了很多好处,比如对每项服务的所有权都有一个清晰的概念。这提高了服务访问的速度和质量,通过允许团队只关注他们需要扩展的服务,在更新虚拟服务的同时而不中断其他服务,实现了更可靠的容错,从而促进了快速扩展[^11]。
|
||||
|
||||
### 这就是可扩展性!
|
||||
|
||||
关于如何提供可伸缩性的一个很好的例子是看看中国。中国人口众多,必须通过创造和试验新的解决方案来适应规模化的新挑战。统计数据显示,中国目前为大约 9 亿互联网用户提供服务[^14]。2019 年“双十一”期间(相当于国外的黑色星期五),阿里巴巴旗下各购物平台的交易峰值为每秒 544000 笔交易。阿里云处理的数据总量约为 970 PB[^15]。那么,这些数量的用户在技术上意味着什么呢?
|
||||
|
||||
为了解决可伸缩性问题,许多技术应运而生。例如,[Tars][2] 由腾讯于 2008 年创建,[2018 年贡献给 Linux 基金会][3]。它也在被大规模使用,并在 10 年内得到了很大的提升[^12]。TARS 是开源的,许多组织都在大力贡献和扩展框架的特性和价值[^12]。TARS 支持多种编程语言,包括 C++、Golang、java、node.js、PHP 和 Python;它可以快速构建系统并自动生成代码,使开发人员能够专注于业务逻辑,从而有效地提高操作效率。TARS 已广泛应用于腾讯的 QQ、微信社交网络、金融服务、边缘计算、汽车、视频、网络游戏、地图、应用市场、安全等诸多核心业务。[在 2020 三月,TARS 项目转变为 TARS 基金会][4],这是一个开源微服务基金会,在建立开放式微服务平台的社区方面中,致力于提升社区贡献和成员的快速增长[^12]。
|
||||
|
||||
|
||||
**一定要看看 Linux 基金会新的免费培训课程**:《[用 TARS 构建微服务平台][5]》
|
||||
|
||||
*关于作者:*
|
||||
|
||||
*Isabella Ferreira 是 Linux 基金会旗下的开源微服务基金会 TARS 基金会的布道师*
|
||||
|
||||
*Mark Shan(单致豪)是腾讯开源联盟的主席,也是 TARS 基金会的董事会主席。*
|
||||
|
||||
[^1]: https://tsh.io/state-of-microservices/#ebook
|
||||
[^2]: https://medium.com/hashmapinc/the-what-why-and-how-of-a-microservices-architecture-4179579423a9
|
||||
[^3]: https://www.plutora.com/blog/understanding-microservices
|
||||
[^4]: https://www.leanix.net/en/blog/a-brief-history-of-microservices
|
||||
[^5]: https://www.charterglobal.com/five-microservices-trends-in-2020/
|
||||
[^6]: https://martinfowler.com/articles/microservices.html#footnote-etymology
|
||||
[^7]: https://whatis.techtarget.com/definition/monolithic-architecture
|
||||
[^8]: https://ycharts.com/companies/AMZN/market_cap
|
||||
[^9]: https://thenewstack.io/led-amazon-microservices-architecture/
|
||||
[^10]: https://media.netflix.com/en/company-blog/completing-the-netflix-cloud-migration
|
||||
[^11]: https://blog.dreamfactory.com/microservices-examples/
|
||||
[^12]: https://www.linuxfoundation.org/blog/2020/03/the-tars-foundation-the-formation-of-a-microservices-ecosystem/
|
||||
[^13]: https://medium.com/microservices-architecture/top-10-microservices-framework-for-2020-eefb5e66d1a2
|
||||
[^14]: https://www.statista.com/statistics/265140/number-of-internet-users-in-china/
|
||||
[^15]: https://interconnected.blog/china-scale-technology-sandbox/
|
||||
|
||||
> 本篇 Linux 基金会白金赞助商内容由腾讯贡献。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.linux.com/news/the-state-of-the-art-of-microservices-in-2020/
|
||||
|
||||
作者:[Linux.com][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[zhangxiangping](https://github.com/zxp93)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://www.linux.com/author/linuxdotcom/
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://www.linux.com/wp-content/uploads/2020/11/microservices_diagram_a.png
|
||||
[2]: https://tarscloud.org/foundation/index
|
||||
[3]: https://www.linuxfoundation.org/press-release/2018/06/tars-and-tseer-form-open-source-project-communities-under-the-linux-foundation-to-expand-adoption-and-pace-of-development/
|
||||
[4]: https://www.linuxfoundation.org/blog/2020/03/the-tars-foundation-the-formation-of-a-microservices-ecosystem/
|
||||
[5]: https://www.edx.org/course/building-microservice-platforms-with-tars
|
@ -0,0 +1,136 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (robsean)
|
||||
[#]: reviewer: (wxy)
|
||||
[#]: publisher: (wxy)
|
||||
[#]: url: (https://linux.cn/article-12939-1.html)
|
||||
[#]: subject: (How to Write, Compile and Run a C Program in Ubuntu and Other Linux Distributions [Beginner’s Tip])
|
||||
[#]: via: (https://itsfoss.com/run-c-program-linux/)
|
||||
[#]: author: (Abhishek Prakash https://itsfoss.com/author/abhishek/)
|
||||
|
||||
如何在 Ubuntu/Debian Linux 上编写、编译和运行一个 C 程序
|
||||
======
|
||||
|
||||
![][2]
|
||||
|
||||
你是如何在 Linux 上使用 C 编写你的程序的?它确实是非常简单的,由三个简单的步骤组成。
|
||||
|
||||
**步骤 1**: 编写你的 C 程序,并使用一个 `.c` 的扩展名进行保存。例如,`my_program.c` 。
|
||||
|
||||
**步骤 2**: 在一个终端中使用 `gcc` 编译器来编译程序并生成目标文件,像这样:
|
||||
|
||||
```
|
||||
gcc -o my_program my_program.c
|
||||
```
|
||||
|
||||
**步骤 3**: 在 Linux 中,你可以以运行生成的对象文件的方式来运行你的 C 程序:
|
||||
|
||||
```
|
||||
./my_program
|
||||
```
|
||||
|
||||
![][1]
|
||||
|
||||
这只是如何在 Linux 中编译和运行 C 程序的简要总结。假设你是 C 语言或 Linux 系统的新手,我将仔细演示这些步骤,以便你能在 Linux 环境中舒服地编写 C 程序。
|
||||
|
||||
事实上,我将讨论如何在 Linux 终端中以及在代码编辑器中运行 C 程序的两种方式。
|
||||
|
||||
### 方法 1: 在 Linux 终端中运行 C 程序
|
||||
|
||||
为了在 Linux 中运行一个 C 程序,你需要在你的系统上有一个 C 编译器。最流行的编译器是 `gcc`(<ruby>[GNU 编译器套件][3]<rt>GNU Compiler Collection</rt></ruby>)。
|
||||
|
||||
你可以使用你发行版的软件包管理器来安装 `gcc` 。在基于 Debian 和 Ubuntu 的 Linux 发行版中,使用 `apt` 命令:
|
||||
|
||||
```
|
||||
sudo apt install gcc
|
||||
```
|
||||
|
||||
切换到保存你的 C 程序的目录(或者提供路径),然后通过编译程序生成对象文件:
|
||||
|
||||
```
|
||||
gcc -o my_program my_program.c
|
||||
```
|
||||
|
||||
记住,提供输出对象文件(`-o my_program`)是可选的。如果你不提供,那么将自动生成一个名称为 `a.out` 的对象文件。但是这样并不好,因为编译每个 C 程序都会覆盖它,而且你也不知道这个 `a.out` 对象文件究竟属于哪个程序。
|
||||
|
||||
在你的对象文件生成后,运行它来运行 C 程序。它已经能够执行了。像这样简单地使用它:
|
||||
|
||||
```
|
||||
./my_program
|
||||
```
|
||||
|
||||
接下来,如果你的程序是正确的,它将显示出你所期望的输出。正如你所看到的,这和 [在 Linux 中运行 C++ 程序][4] 没什么不同。
|
||||
|
||||
*每更改一次你的程序,你都必须先重新编译它,然后再次运行生成的对象文件来运行这个新的 C 程序。*
|
||||
|
||||
### 方法 2: 如何在 Linux 中使用一个诸如 VSCode 之类的代码编辑器来运行 C 程序
|
||||
|
||||
并不是每一个人都能适应命令行和终端,我完全理解这一点。
|
||||
|
||||
你可以使用一个诸如 Eclipse 或 Code Blocks 之类的真正的 C/C++ IDE ,但是它们是很重量级的程序,通常更适合于大型的项目。
|
||||
|
||||
我建议使用一个开源的代码编辑器,像 VSCode 或 Atom 。它们基本上是文本编辑器,但是你可以通过安装附加组件来直接在图形化的代码编辑器中编译和运行程序。
|
||||
|
||||
在这个示例中,我使用 [VSCode][5] 编辑器。它是一个来自微软的 [非常流行的开源的代码编辑器][6] 。
|
||||
|
||||
首先,在 Ubuntu 的 [软件中心中安装 VSCode][7] 。对于其它发行版来说,请检查你的 Linux 发行版的软件包管理器或软件中心。你可以参看它的官方网站来查看更多的信息。
|
||||
|
||||
启动 VSCode ,打开或创建一个工程,在这里创建你的 C 程序。我使用一个简单的 Hello World 程序作为示例。
|
||||
|
||||
![][8]
|
||||
|
||||
你必须确保你已经在你的 Linux 系统上安装了 `gcc` 编译器。
|
||||
|
||||
```
|
||||
sudo apt install gcc
|
||||
```
|
||||
|
||||
接下来你要做的事是使用一个允许你运行 C 代码的扩展。微软可能会提示你安装它的 C/C++ 程序扩展,但它的设置很复杂,因此我不推荐。
|
||||
|
||||
相反,我建议你使用 Code Runner 扩展。它是一个简单直接的扩展,你可以在不使用额外配置的情况下轻松地运行 C 和 C++ 代码。
|
||||
|
||||
转到扩展标签页,在其中搜索和安装 “Code Runner” 。
|
||||
|
||||
![安装 Code Runner 扩展来运行 C/C++ 程序][9]
|
||||
|
||||
重新启动 VSCode 。现在,你能够使用下面方法中的其中一个来运行 C 代码:
|
||||
|
||||
* 使用快捷键 `Ctrl+Alt+N` 。
|
||||
* 按下 `F1` ,接下来选择或输入 “Run Code” 。
|
||||
* 在文本编辑器中右键单击,从上下文菜单中单击 “Run code” 。
|
||||
|
||||
![右键单击程序文件,然后选择 Run Code][10]
|
||||
|
||||
当你运行这个 C 程序时,它将会被自动编译和运行。你可以在编辑器底部打开的终端中看到输出。还有比这更好的事情吗?
|
||||
|
||||
![程序输出显示在编辑器的底部][11]
|
||||
|
||||
你更喜欢哪一种方法?
|
||||
|
||||
在 Linux 命令行中运行一些 C 程序是没有问题的,但是使用一个代码编辑器会更容易一些,而且会节省时间。你不觉得吗?
|
||||
|
||||
你可以自己决定想使用哪一种方法。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://itsfoss.com/run-c-program-linux/
|
||||
|
||||
作者:[Abhishek Prakash][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[robsean](https://github.com/robsean)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://itsfoss.com/author/abhishek/
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2020/11/running-c-program-linux.png?resize=795%2C399&ssl=1
|
||||
[2]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2020/11/Run-C-Program-Linux.png?resize=800%2C450&ssl=1
|
||||
[3]: https://gcc.gnu.org/
|
||||
[4]: https://itsfoss.com/c-plus-plus-ubuntu/
|
||||
[5]: https://code.visualstudio.com
|
||||
[6]: https://itsfoss.com/best-modern-open-source-code-editors-for-linux/
|
||||
[7]: https://itsfoss.com/install-visual-studio-code-ubuntu/
|
||||
[8]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2020/11/c-program-visual-studio-code-linux.png?resize=800%2C441&ssl=1
|
||||
[9]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2020/11/running-c-program-in-linux-with-visual-studio-code.png?resize=800%2C500&ssl=1
|
||||
[10]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2020/11/running-c-program-in-linux-with-visual-studio-code.jpg?resize=800%2C500&ssl=1
|
||||
[11]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2020/11/run-c-program-in-linux-with-visual-studio-code.jpg?resize=800%2C500&ssl=1
|
@ -1,39 +1,41 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (Mjseven)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: reviewer: (wxy)
|
||||
[#]: publisher: (wxy)
|
||||
[#]: url: (https://linux.cn/article-12920-1.html)
|
||||
[#]: subject: (How to Save the Output of a Command to a File in Linux Terminal [Beginner’s Tip])
|
||||
[#]: via: (https://itsfoss.com/save-command-output-to-file-linux/)
|
||||
[#]: author: (Abhishek Prakash https://itsfoss.com/author/abhishek/)
|
||||
|
||||
如何将 Linux 终端中命令的输出保存到文件中[新手技巧]
|
||||
如何将 Linux 终端中命令的输出保存到文件中
|
||||
======
|
||||
|
||||
![](https://img.linux.net.cn/data/attachment/album/202012/14/223956pidmznldldnnk87f.jpg)
|
||||
|
||||
当你在 Linux 终端中运行命令或脚本时,它会在终端中打印输出方便你立即查看。
|
||||
|
||||
有时你需要将输出保存到文件中以备将来参考。现在,[你当然可以在 Linux 终端中复制和粘贴][1],但是有更好的方法可以在 Linux 命令行中保存 shell 脚本或命令的输出,让我演示给你看。
|
||||
有时你需要将输出保存到文件中以备将来参考。[当然你可以在 Linux 终端中复制和粘贴][1],但是有更好的方法可以在 Linux 命令行中保存 shell 脚本或命令的输出,让我演示给你看。
|
||||
|
||||
### 方法 1:使用重定向将命令输出保存到文件中
|
||||
|
||||
你可以[在 Linux 中使用重定向来达成目的][2]。使用重定向操作符,它会将输出保存到文件中而不是在屏幕上显示。
|
||||
|
||||
* > 会将命令输出重定向到文件,它会替换文件中的所有内容。
|
||||
* >> 会将命令输出添加到文件现有内容的末尾。
|
||||
* `>` 会将命令输出重定向到文件,它会替换文件中的所有内容。
|
||||
* `>>` 会将命令输出添加到文件现有内容的末尾。
|
||||
|
||||
使用 STDOUT 重定向运算符 > 将输出重定向到文件:
|
||||
使用标准输出重定向运算符 `>` 将输出重定向到文件:
|
||||
|
||||
```
|
||||
command > file.txt
|
||||
```
|
||||
|
||||
如果 file.txt 不存在,它会自动创建。如果你使用 > 再次重定向到相同的文件,文件内容将被替换为新的输出。
|
||||
如果 `file.txt` 不存在,它会自动创建。如果你使用 `>` 再次重定向到相同的文件,文件内容将被替换为新的输出。
|
||||
|
||||
下面的示例将更好地演示它。它首先会保存 _ls -l_ 命令的输出,然后,它将用 _ls *.c_ 命令的输出替换文件的内容。
|
||||
下面的示例将更好地演示它。它首先会保存 `ls -l` 命令的输出,然后,它将用 `ls *.c` 命令的输出替换文件的内容。
|
||||
|
||||
![将命令输出重定向到文件][3]
|
||||
|
||||
如果你不想在保存脚本或命令的输出时丢失现有文件的内容,可以使用 >> :
|
||||
如果你不想在保存脚本或命令的输出时丢失现有文件的内容,可以使用 `>>` :
|
||||
|
||||
```
|
||||
command >> file.txt
|
||||
@ -47,17 +49,19 @@ command >> file.txt
|
||||
|
||||
温馨提示:将 Linux 命令输出和错误保存到一个文件中。
|
||||
|
||||
如果Linux 命令返回错误,那么错误不会保存在文件中。你可以使用 2>&1 将命令的输出和错误保存到同一个文件中,如下所示:
|
||||
如果 Linux 命令返回错误,那么错误不会保存在文件中。你可以使用 `2>&1` 将命令的输出和错误保存到同一个文件中,如下所示:
|
||||
|
||||
**command > file.txt 2>&1**
|
||||
```
|
||||
command > file.txt 2>&1
|
||||
```
|
||||
|
||||
通常,0 代表标准输入,1 代表标准输出,2 代表标准错误。在这里,你要将标准错误(2) 重定向(&)到与标准输出(1) 相同的地址。
|
||||
通常,`0` 代表标准输入,`1` 代表标准输出,`2` 代表标准错误。在这里,你要将标准错误(`2`) 重定向(`&`)到与标准输出(`1`)相同的地址。
|
||||
|
||||
### 方法 2:使用 tee 命令显示输出并将其保存到文件中
|
||||
|
||||
顺便说一句,你是否注意到,当你将命令输出发送到一个文件时,你再也无法在终端上看到它了?[Linux 的 tee 命令][5]解决了这个问题。
|
||||
|
||||
类似于将水流发送到两个方向的三通管,tee 命令将输出发送到终端以及文件(或作为另一个命令的输入)。你可以像这样使用它:
|
||||
类似于将水流发送到两个方向的三通管,`tee` 命令将输出发送到终端以及文件(或作为另一个命令的输入)。你可以像这样使用它:
|
||||
|
||||
```
|
||||
command | tee file.txt
|
||||
@ -65,7 +69,7 @@ command | tee file.txt
|
||||
|
||||
同样,如果该文件不存在,它将自动创建。
|
||||
|
||||
你还可以使用 tee 命令在附加模式下使用选项 -a:
|
||||
你还可以使用 `tee` 命令 `-a` 选项进入附加模式:
|
||||
|
||||
```
|
||||
command | tee -a file.txt
|
||||
@ -79,7 +83,7 @@ command | tee -a file.txt
|
||||
|
||||
### 注意:将命令输出保存到文件时,避免管道陷阱
|
||||
|
||||
你可能对管道重定向很熟悉,可以使用它来组合 Linux 命令,但不能将输出通过管道传输到文件,它显示找不到 output.txt 命令:
|
||||
你可能对管道重定向很熟悉,可以使用它来组合 Linux 命令,但不能将输出通过管道传输到文件,它显示找不到 `output.txt` 命令:
|
||||
|
||||
![][7]
|
||||
|
||||
@ -96,7 +100,7 @@ via: https://itsfoss.com/save-command-output-to-file-linux/
|
||||
作者:[Abhishek Prakash][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[MjSeven](https://github.com/MjSeven)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
@ -0,0 +1,194 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (zxp93)
|
||||
[#]: reviewer: (wxy)
|
||||
[#]: publisher: (wxy)
|
||||
[#]: url: (https://linux.cn/article-12932-1.html)
|
||||
[#]: subject: (An attempt at implementing char-rnn with PyTorch)
|
||||
[#]: via: (https://jvns.ca/blog/2020/11/30/implement-char-rnn-in-pytorch/)
|
||||
[#]: author: (Julia Evans https://jvns.ca/)
|
||||
|
||||
用 PyTorch 实现基于字符的循环神经网络
|
||||
======
|
||||
|
||||
![](https://img.linux.net.cn/data/attachment/album/202012/19/102319oe36em6d63bolg0i.jpg)
|
||||
|
||||
在过去的几周里,我花了很多时间用 PyTorch 实现了一个 [char-rnn][1] 的版本。我以前从未训练过神经网络,所以这可能是一个有趣的开始。
|
||||
|
||||
这个想法(来自 [循环神经网络的不合理效应][1])可以让你在文本上训练一个基于字符的<ruby>循环神经网络<rt>recurrent neural network</rt></ruby>(RNN),并得到一些出乎意料好的结果。
|
||||
|
||||
不过,虽然没有得到我想要的结果,但是我还是想分享一些示例代码和结果,希望对其他开始尝试使用 PyTorch 和 RNN 的人有帮助。
|
||||
|
||||
这是 Jupyter 笔记本格式的代码:[char-rnn in PyTorch.ipynb][2]。你可以点击这个网页最上面那个按钮 “Open in Colab”,就可以在 Google 的 Colab 服务中打开,并使用免费的 GPU 进行训练。所有的东西加起来大概有 75 行代码,我将在这篇博文中尽可能地详细解释。
|
||||
|
||||
### 第一步:准备数据
|
||||
|
||||
首先,我们要下载数据。我使用的是<ruby>古登堡项目<rt>Project Gutenberg</rt></ruby>中的这个数据:[Hans Christian Anderson’s fairy tales][3]。
|
||||
|
||||
```
|
||||
!wget -O fairy-tales.txt
|
||||
```
|
||||
|
||||
这个是准备数据的代码。我使用 `fastai` 库中的 `Vocab` 类进行数据处理,它能将一堆字母转换成“词表”,然后用这个“词表”把字母变成数字。
|
||||
|
||||
之后我们就得到了一个大的数字数组(`training_set`),我们可以用于训练我们的模型。
|
||||
|
||||
```
|
||||
from fastai.text import *
|
||||
text = unidecode.unidecode(open('fairy-tales.txt').read())
|
||||
v = Vocab.create((x for x in text), max_vocab=400, min_freq=1)
|
||||
training_set = torch.Tensor(v.numericalize([x for x in text])).type(torch.LongTensor).cuda()
|
||||
num_letters = len(v.itos)
|
||||
```
|
||||
|
||||
### 第二步:定义模型
|
||||
|
||||
这个是 PyTorch 中 `LSTM` 类的封装。除了封装 `LSTM` 类以外,它还做了三件事:
|
||||
|
||||
1. 对输入向量进行 one-hot 编码,使得它们具有正确的维度。
|
||||
2. 在 `LSTM` 层后一层添加一个线性变换,因为 `LSTM` 输出的是一个长度为 `hidden_size` 的向量,我们需要的是一个长度为 `input_size` 的向量这样才能把它变成一个字符。
|
||||
3. 把 `LSTM` 隐藏层的输出向量(实际上有 2 个向量)保存成实例变量,然后在每轮运行结束后执行 `.detach()` 函数。(我很难解释清 `.detach()` 的作用,但我的理解是,它在某种程度上“结束”了模型的求导计算)(LCTT 译注:`detach()` 函数是将该张量的 `requires_grad` 参数设置为 `False`,即反向传播到该张量就结束。)
|
||||
|
||||
```
|
||||
class MyLSTM(nn.Module):
|
||||
def __init__(self, input_size, hidden_size):
|
||||
super().__init__()
|
||||
self.lstm = nn.LSTM(input_size, hidden_size, batch_first=True)
|
||||
self.h2o = nn.Linear(hidden_size, input_size)
|
||||
self.input_size=input_size
|
||||
self.hidden = None
|
||||
|
||||
def forward(self, input):
|
||||
input = torch.nn.functional.one_hot(input, num_classes=self.input_size).type(torch.FloatTensor).cuda().unsqueeze(0)
|
||||
if self.hidden is None:
|
||||
l_output, self.hidden = self.lstm(input)
|
||||
else:
|
||||
l_output, self.hidden = self.lstm(input, self.hidden)
|
||||
self.hidden = (self.hidden[0].detach(), self.hidden[1].detach())
|
||||
|
||||
return self.h2o(l_output)
|
||||
```
|
||||
|
||||
这个代码还做了一些比较神奇但是不太明显的功能。如果你的输入是一个向量(比如 `[1,2,3,4,5,6]`),对应六个字母,那么我的理解是 `nn.LSTM` 会在内部使用[沿时间反向传播][4]更新隐藏向量 6 次。
|
||||
|
||||
### 第三步:编写训练代码
|
||||
|
||||
模型不会自己训练的!
|
||||
|
||||
我最开始的时候尝试用 `fastai` 库中的一个辅助类(也是 PyTorch 中的封装)。我有点疑惑因为我不知道它在做什么,所以最后我自己编写了模型训练代码。
|
||||
|
||||
下面这些代码(`epoch()` 方法)就是有关于一轮训练过程的基本信息。基本上就是重复做下面这几件事情:
|
||||
|
||||
1. 往 RNN 模型中传入一个字符串,比如 `and they ought not to teas`。(要以数字向量的形式传入)
|
||||
2. 得到下一个字母的预测结果
|
||||
3. 计算 RNN 模型预测结果和真实的下一个字母之间的损失函数(`e`,因为 `tease` 这个单词是以 `e` 结尾的)
|
||||
4. 计算梯度(用 `loss.backward()` 函数)
|
||||
5. 沿着梯度下降的方向修改模型中参数的权重(用 `self.optimizer.step()` 函数)
|
||||
|
||||
```
|
||||
class Trainer():
|
||||
def __init__(self):
|
||||
self.rnn = MyLSTM(input_size, hidden_size).cuda()
|
||||
self.optimizer = torch.optim.Adam(self.rnn.parameters(), amsgrad=True, lr=lr)
|
||||
def epoch(self):
|
||||
i = 0
|
||||
while i < len(training_set) - 40:
|
||||
seq_len = random.randint(10, 40)
|
||||
input, target = training_set[i:i+seq_len],training_set[i+1:i+1+seq_len]
|
||||
i += seq_len
|
||||
# forward pass
|
||||
output = self.rnn(input)
|
||||
loss = F.cross_entropy(output.squeeze()[-1:], target[-1:])
|
||||
# compute gradients and take optimizer step
|
||||
self.optimizer.zero_grad()
|
||||
loss.backward()
|
||||
self.optimizer.step()
|
||||
```
|
||||
|
||||
### 使用 nn.LSTM 沿着时间反向传播,不要自己写代码
|
||||
|
||||
开始的时候我自己写代码每次传一个字母到 LSTM 层中,之后定期计算导数,就像下面这样:
|
||||
|
||||
```
|
||||
for i in range(20):
|
||||
input, target = next(iter)
|
||||
output, hidden = self.lstm(input, hidden)
|
||||
loss = F.cross_entropy(output, target)
|
||||
hidden = hidden.detach()
|
||||
self.optimizer.zero_grad()
|
||||
loss.backward()
|
||||
self.optimizer.step()
|
||||
```
|
||||
|
||||
这段代码每次传入 20 个字母,每次一个,并且在最后训练了一次。这个步骤就被称为[沿时间反向传播][4],Karpathy 在他的博客中就是用这种方法。
|
||||
|
||||
这个方法有些用处,我编写的损失函数开始能够下降一段时间,但之后就会出现峰值。我不知道为什么会出现这种现象,但之后我改为一次传入 20 个字符到 LSTM 之后(按 `seq_len` 维度),再进行反向传播,情况就变好了。
|
||||
|
||||
### 第四步:训练模型!
|
||||
|
||||
我在同样的数据上重复执行了这个训练代码大概 300 次,直到模型开始输出一些看起来像英文的文本。差不多花了一个多小时吧。
|
||||
|
||||
这种情况下我也不关注模型是不是过拟合了,但是如果你在真实场景中训练模型,应该要在验证集上验证你的模型。
|
||||
|
||||
### 第五步:生成输出!
|
||||
|
||||
最后一件要做的事就是用这个模型生成一些输出。我写了一个辅助方法从这个训练好的模型中生成文本(`make_preds` 和 `next_pred`)。这里主要是把向量的维度对齐,重要的一点是:
|
||||
|
||||
```
|
||||
output = rnn(input)
|
||||
prediction_vector = F.softmax(output/temperature)
|
||||
letter = v.textify(torch.multinomial(prediction_vector, 1).flatten(), sep='').replace('_', ' ')
|
||||
```
|
||||
|
||||
基本上做的事情就是这些:
|
||||
|
||||
1. RNN 层为字母表中的每一个字母或者符号输出一个数值向量(`output`)。
|
||||
2. 这个 `output` 向量**并不是**一个概率向量,所以需要 `F.softmax(output/temperature)` 操作,将其转换为概率值(也就是所有数值加起来和为 1)。`temperature` 某种程度上控制了对更高概率的权重,在限制范围内,如果设置 `temperature=0.0000001`,它将始终选择概率最高的字母。
|
||||
3. `torch.multinomial(prediction_vector)` 用于获取概率向量,并使用这些概率在向量中选择一个索引(如 `12`)。
|
||||
4. `v.textify` 把 `12` 转换为字母。
|
||||
|
||||
如果我们想要处理的文本长度为 300,那么只需要重复这个过程 300 次就可以了。
|
||||
|
||||
### 结果!
|
||||
|
||||
我把预测函数中的参数设置为 `temperature = 1` 得到了下面的这些由模型生成的结果。看起来有点像英语,这个结果已经很不错了,因为这个模型要从头开始“学习”英语,并且是在字符序列的级别上进行学习的。
|
||||
|
||||
虽然这些话没有什么*含义*,但我们也不知道到底想要得到什么输出。
|
||||
|
||||
> “An who was you colotal said that have to have been a little crimantable and beamed home the beetle. “I shall be in the head of the green for the sound of the wood. The pastor. “I child hand through the emperor’s sorthes, where the mother was a great deal down the conscious, which are all the gleam of the wood they saw the last great of the emperor’s forments, the house of a large gone there was nothing of the wonded the sound of which she saw in the converse of the beetle. “I shall know happy to him. This stories herself and the sound of the young mons feathery in the green safe.”
|
||||
>
|
||||
> “That was the pastor. The some and hand on the water sound of the beauty be and home to have been consider and tree and the face. The some to the froghesses and stringing to the sea, and the yellow was too intention, he was not a warm to the pastor. The pastor which are the faten to go and the world from the bell, why really the laborer’s back of most handsome that she was a caperven and the confectioned and thoughts were seated to have great made
|
||||
|
||||
下面这些结果是当 `temperature=0.1` 时生成的,它选择字符的方式更接近于“每次都选择出现概率最高的字符”。这就使得输出结果有很多是重复的。
|
||||
|
||||
> ole the sound of the beauty of the beetle. “She was a great emperor of the sea, and the sun was so warm to the confectioned the beetle. “I shall be so many for the beetle. “I shall be so many for the beetle. “I shall be so standen for the world, and the sun was so warm to the sea, and the sun was so warm to the sea, and the sound of the world from the bell, where the beetle was the sea, and the sound of the world from the bell, where the beetle was the sea, and the sound of the wood flowers and the sound of the wood, and the sound of the world from the bell, where the world from the wood, and the sound of the
|
||||
|
||||
这段输出对这几个单词 `beetles`、`confectioners`、`sun` 和 `sea` 有着奇怪的执念。
|
||||
|
||||
### 总结!
|
||||
|
||||
至此,我的结果远不及 Karpathy 的好,可能有一下几个原因:
|
||||
|
||||
1. 没有足够多的训练数据。
|
||||
2. 训练了一个小时之后我就没有耐心去查看 Colab 笔记本上的信息。
|
||||
3. Karpathy 使用了两层LSTM,包含了更多的参数,而我只使用了一层。
|
||||
4. 完全是另一回事。
|
||||
|
||||
但我得到了一些大致说得过去的结果!还不错!
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://jvns.ca/blog/2020/11/30/implement-char-rnn-in-pytorch/
|
||||
|
||||
作者:[Julia Evans][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[zhangxiangping](https://github.com/zxp93)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://jvns.ca/
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://karpathy.github.io/2015/05/21/rnn-effectiveness/
|
||||
[2]: https://gist.github.com/jvns/b6dda36b2fdcc02b833ed5b0c7a09112
|
||||
[3]: https://www.gutenberg.org/cache/epub/27200/pg27200.txt
|
||||
[4]: https://en.wikipedia.org/wiki/Backpropagation_through_time
|
92
published/20201202 Why I love Emacs.md
Normal file
92
published/20201202 Why I love Emacs.md
Normal file
@ -0,0 +1,92 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (wxy)
|
||||
[#]: reviewer: (wxy)
|
||||
[#]: publisher: (wxy)
|
||||
[#]: url: (https://linux.cn/article-12923-1.html)
|
||||
[#]: subject: (Why I love Emacs)
|
||||
[#]: via: (https://opensource.com/article/20/12/emacs)
|
||||
[#]: author: (Seth Kenlon https://opensource.com/users/seth)
|
||||
|
||||
为什么我喜欢 Emacs
|
||||
======
|
||||
|
||||
> Emacs 并不是一个单纯的文本编辑器,它将掌控置于你手中,让你几乎可以解决你遇到的任何问题。
|
||||
|
||||
!["表情符号键盘"][1]
|
||||
|
||||
我是一个典型的 [Emacs][2] 用户。不是我选择的 Emacs,而是它选择了我。早在我刚开始学习 Unix 的时候,我偶然发现了一个奇怪的名为 Emacs 的应用程序,它隐藏在我的电脑上,其中有一个鲜为人知的功能。传说中(而且被证明是真的),如果你在终端上输入 `emacs`,按 `Alt+X`,然后输入 `tetris`,你就可以玩一个掉方块的游戏。
|
||||
|
||||
![Tetris in Emacs][3]
|
||||
|
||||
那就是我对 GNU Emacs 的印象。虽然这很肤浅,但它也准确地表明了 Emacs 的意义:用户可以重新编程他们的(虚拟)世界,并且可以用一个应用程序做*任何*他们想做的事情。在你的文本编辑器中玩俄罗斯方块可能不是你日常的主要目标,但这说明 Emacs 是一个值得骄傲的编程平台。事实上,你可以把它看作是 [Jupyter][4] 的一种先驱,它把一种强大的编程语言(准确的说叫 elisp)和自己的实时环境结合起来。因此,Emacs 作为一个文本编辑器是灵活的、可定制的、强大的。
|
||||
|
||||
如果你习惯于 Bash、Python 或类似的语言,elisp(以及扩展的 Common Lisp)不一定是最容易入门的语言。但是这种 LISP 方言是很强大的,而且因为 Emacs 是一个 LISP 解释器,所以你可以用它构建应用程序,不管它们是 Emacs 插件还是你想开发成一个独立项目的原型。极其流行的 [org 模式项目][5]就是一个例子:它是一个 Emacs 插件,同时也是一个标记语法,有移动应用可以解释和扩展其功能。类似的有用的 Emacs 内应用的例子还有很多,包括电子邮件客户端、PDF 浏览器、Web 浏览器、shell 和文件管理器。
|
||||
|
||||
### 两个界面
|
||||
|
||||
GNU Emacs 至少有两个用户界面:图形用户界面(GUI)和终端用户界面(TUI)。这有时会让人感到惊讶,因为 Emacs 经常与运行在终端中的 Vi 相提并论(尽管 gVim 为现代 Vi 的实现提供了一个 GUI)。如果你想把 GNU Emacs 以终端程序来运行,你可以用 `-nw` 选项来启动它。
|
||||
|
||||
```
|
||||
$ emacs -nw
|
||||
```
|
||||
|
||||
有了 GUI 程序,你可以直接从应用程序菜单或终端启动 Emacs。
|
||||
|
||||
你可能会认为 GUI 会降低 Emacs 的效率,好像“真正的文本编辑器是在终端中运行的”,但 GUI 可以使 Emacs 更容易学习,因为它的 GUI 遵循了一些典型的惯例(菜单栏、可调节的组件、鼠标交互等)。
|
||||
|
||||
事实上,如果你把 Emacs 作为一个 GUI 应用程序来运行,你可能在一天的时间里会完全没有意识到你在 Emacs 中。只要你使用过 GUI,大多数常用的惯例都适用。例如,你可以用鼠标选择文本,导航到**编辑**菜单,选择**复制**,然后将光标放在其他地方,选择**粘贴**。要保存文档,你可以进入**文件**,然后选择**保存**或**另存为**。你可以按 `Ctrl` 键并向上滚动,使屏幕字体变大,你可以使用滚动条来浏览你的文档,等等。
|
||||
|
||||
了解 Emacs 的 GUI 形式是拉平学习曲线的好方法。
|
||||
|
||||
### Emacs 键盘快捷键
|
||||
|
||||
GNU Emacs 以复杂的键盘组合而恶名远扬。它们不仅陌生(`Alt+W` 来复制?`Ctrl+Y` 来粘贴?),而且还用晦涩难懂的术语来标注(`Alt` 被称为 `Meta`),有时它们成双成对(`Ctrl+X` 后是 `Ctrl+S` 来保存),有时则单独出现(`Ctrl+S` 来搜索)。为什么有人会故意选择使用这些呢?
|
||||
|
||||
嗯,有些人不会。但那些喜欢这些的人是因为这些组合很容易融入到日常打字的节奏中(而且经常让 `Caps Lock` 键充当 `Ctrl` 键)。然而,那些喜欢不同的东西的人有几个选择:
|
||||
|
||||
* “邪恶”模式让你在 Emacs 中使用 Vim 键绑定。就是这么简单。你可以保留你的肌肉记忆中的按键组合,并继承最强大的文本编辑器。
|
||||
* 通用用户访问(CUA)键保留了所有 Emacs 常用的组合键,但最令人头疼的键(复制、剪切、粘贴和撤消)都被映射到现代的键盘绑定中(分别为 `Ctrl+C`、`Ctrl+X`、`Ctrl+V` 和 `Ctrl+Z`)。
|
||||
* `global-set-key` 函数,是 Emacs 编程的一部分,允许你定义自己的键盘快捷键。传统上,用户定义的快捷键以 `Ctrl+C` 开头,但没有什么能阻止你发明自己的方案。Emacs 并不敝帚自珍,欢迎你按照自己的意愿来扭转它。
|
||||
|
||||
### 学习 Emacs
|
||||
|
||||
要想很好地使用 Emacs 是需要时间的。对我来说,这意味着打印出一张[速记表][6],每天都把它放在键盘旁边。当我忘了一个键组合时,我就在我的速记表上查找它。如果它不在我的速记表上,我就学习这个键盘组合,要么通过执行该函数,并注意 Emacs 告诉我如何更快地访问它,要么通过使用 `describe-function`:
|
||||
|
||||
```
|
||||
M-x describe-function: save-buffer
|
||||
|
||||
save-buffer is an interactive compiled Lisp function in ‘files.el’.
|
||||
|
||||
It is bound to C-x C-s, <menu-bar> <file> <save-buffer>.
|
||||
[...]
|
||||
```
|
||||
|
||||
当你使用它的时候,你就会学习它。你对它了解得越多,你就越有能力去改进它,使它变成你自己的。
|
||||
|
||||
### 尝试 Emacs
|
||||
|
||||
人们常开玩笑说 Emacs 是一个包含文本编辑器的操作系统。也许这是在暗示 Emacs 臃肿和过于复杂,当然也有一种说法是文本编辑器根据其默认配置不应该需要 `libpoppler`(你可以不需要它来编译 Emacs)。
|
||||
|
||||
但这个笑话背后潜藏着一个更大的真相,它揭示了 Emacs 如此有趣的原因。将 Emacs 与其他文本编辑器,如 Vim、Nano,甚至 [VSCodium][7] 进行比较是没有意义的,因为 Emacs 真正重要的部分并不是你可以在窗口中输入东西并保存的这种思路。那是连 Bash 都能提供的基本功能。Emacs 的真正意义在于它如何将控制置身于你的手中,以及如何通过 Emacs Lisp([Elisp][8])解决几乎任何问题。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/20/12/emacs
|
||||
|
||||
作者:[Seth Kenlon][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[wxy](https://github.com/wxy)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [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/emoji-keyboard.jpg?itok=JplrSZ9c (Emoji keyboard)
|
||||
[2]: https://en.wikipedia.org/wiki/Emacs
|
||||
[3]: https://opensource.com/sites/default/files/tetris.png (Tetris in Emacs)
|
||||
[4]: https://opensource.com/article/20/11/surprising-jupyter
|
||||
[5]: https://opensource.com/article/19/1/productivity-tool-org-mode
|
||||
[6]: https://opensource.com/downloads/emacs-cheat-sheet
|
||||
[7]: https://opensource.com/article/20/6/open-source-alternatives-vs-code
|
||||
[8]: https://www.gnu.org/software/emacs/manual/html_node/elisp/
|
94
published/20201203 Get the most out of the Vi text editor.md
Normal file
94
published/20201203 Get the most out of the Vi text editor.md
Normal file
@ -0,0 +1,94 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (wxy)
|
||||
[#]: reviewer: (wxy)
|
||||
[#]: publisher: (wxy)
|
||||
[#]: url: (https://linux.cn/article-12947-1.html)
|
||||
[#]: subject: (Get the most out of the Vi text editor)
|
||||
[#]: via: (https://opensource.com/article/20/12/vi-text-editor)
|
||||
[#]: author: (Seth Kenlon https://opensource.com/users/seth)
|
||||
|
||||
初识 Vi 文本编辑器
|
||||
======
|
||||
|
||||
> Vi 是典型的 Unix 文本编辑器。来了解一下它或它的各种化身:Vim、Neovim、gVim、nvi 或 Elvis,它适用于 Linux、macOS、Windows 或 BSD。
|
||||
|
||||
![](https://img.linux.net.cn/data/attachment/album/202012/23/222122wc8resp5zpo2yrcm.jpg)
|
||||
|
||||
不管你用的是 Vim、Neovim、gVim、nvi,甚至是 Elvis,其实都是这个典型的 Unix 编辑器 Vi。可能每一个 Linux 和 BSD 发行版中都包含了 Vi,Vi 是一个轻量级的简约型文本编辑器,由于其简单简洁的键盘快捷键和双模式设计,很多用户都喜欢它。
|
||||
|
||||
最初的 Vi 编辑器是由 [C shell][2] 的创建者 Bill Joy 编写的应用程序。现代 Vi 的化身已经[增加了许多功能][3],包括多级撤销、插入模式下更好的导航、行折叠、语法高亮、插件支持等等。Vim 被认为是它的最流行的现代实现,大多数人在提到 Vi 时实际上是指 Vim。
|
||||
|
||||
所有这些化身都是为了同一个目标,所以本文将从通用的场景来探讨 Vi。你的计算机上的版本可能略有不同,但你仍然可以从 Vi 编辑文本的方式中获益。
|
||||
|
||||
### 安装 Vi
|
||||
|
||||
如果你运行的是 Linux、macOS 或 BSD,那么你已经安装了 `vi` 命令。如果你在 Windows 上,你可以[下载 Vim 和 gVim][4]。
|
||||
|
||||
![gVim][5]
|
||||
|
||||
在 [NetBSD][7]上,nvi 是 Vi 的常见替代品,而 Slackware 则提供了 [Elvis][8](和 Vim),流行的 [Neovim][9] 复刻旨在帮助用户用 [Lua][10] 扩展 Vim。
|
||||
|
||||
### 启动 Vi
|
||||
|
||||
在终端中用 `vi` 命令启动 Vi 或 Vim。如果在你的系统中没有找到 `.vimrc` 文件,那么 Vim 就会以 Vi 兼容模式启动(也可以用 `-C` 选项强制启动该模式)。如果你想使用 gVim 以拥有一个图形用户界面(GUI),你可以从桌面的应用程序菜单中启动它。
|
||||
|
||||
如果你是一个刚刚学习 Vi 的新用户,使用图形用户界面是一个很好的方法,可以在你可能期望的文本编辑器的行为和 Vi 的设计行为之间提供一个缓冲带。图形用户界面版本有一个菜单栏,一些鼠标集成,一个工具栏和其他功能,这可以帮助你找到你可能认为在典型的文本编辑器中理所当然的基本功能,但还不知道如何在 Vi 中做。
|
||||
|
||||
### 如何使用 Vi
|
||||
|
||||
学习 Vi 最简单的方法可能是使用 `vimtutor`,这是一个与 Vim 打包在一起的交互式教程。要开始学习该教程,启动 `vimtutor` 并阅读说明,尝试每个练习。正如教程中所说,学好 Vi 不是记住什么键做什么,而是建立肌肉记忆,以在输入时调用常用的动作。
|
||||
|
||||
#### Esc 键
|
||||
|
||||
学习 Vi 的第一件重要的事就是掌握 `Esc` 键。`Esc` 是激活*命令模式*的工具,很快你就会明白,在 Vi 中,只要你不确定,就按 `Esc`。在命令模式下,你按下的任何键都不会被输入到你正在处理的文本文档中,而是被 Vi 解释为一条命令。例如,要将光标向左移动,你可以按键盘上的 `H` 键。如果你处于*插入*模式,那么按 `H` 键就会输入字母 H,就像你期望的那样。但在*命令*模式下,按 `H` 向左移动,`L` 向右移动,`J` 向下移动,`K` 向上移动。
|
||||
|
||||
命令模式和插入模式的分离与其他文本编辑器的工作方式形成了鲜明的对比,由于这种设计,这可能是 Vi 最显著的差异化。不过有趣的是,理论上来说,它与你可能已有的工作方式并没有太大的区别。毕竟,当你把手从键盘上拿开,用鼠标选择文本时,你基本上是将自己置于一种命令模式中。在 Vi 中,你不需要把手从键盘上移开来移动鼠标,也不需要按功能键或 `Ctrl` 键,而是将*编辑器*放入一种特殊的操作模式中,使你的按键重新分配到命令上,而不是文字输入。
|
||||
|
||||
#### 扩展 Vi
|
||||
|
||||
在 Vim 8.0 版本之前,Vi 在很大程度上“只是”一个文本编辑器。它有插件,但安装插件是一个手动的过程,很多用户从未想过要这么做。幸运的是,Vim 8 及以上版本提供了对插件管理的支持,使得安装和加载插件变得轻而易举。
|
||||
|
||||
安装 Vim 的插件可以通过 `vim-plug` 功能来完成。例如,要安装 Vi 文件浏览器 [NERDTree][11]:
|
||||
|
||||
```
|
||||
:PlugInstall NERDTree
|
||||
```
|
||||
|
||||
你也可以更新插件:
|
||||
|
||||
```
|
||||
:PlugUpdate NERDTree
|
||||
```
|
||||
|
||||
关于使用 `vim-plug` 和手动安装插件和主题的更多信息,请阅读我的文章《[如何安装 Vim 插件][12]》。
|
||||
|
||||
### 默认 Vi
|
||||
|
||||
Vi 不仅仅流行,它还是一个 [POSIX][13] 标准。它是每个系统管理员都应该知道如何使用的应用程序,即使他们不打算每天使用它。它也是一个快速而简单的编辑器,所以一旦你熟练掌握了它,它可能就是你一直在寻找的编辑器。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/20/12/vi-text-editor
|
||||
|
||||
作者:[Seth Kenlon][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[wxy](https://github.com/wxy)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [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/lenovo-thinkpad-laptop-concentration-focus-windows-office.png?itok=-8E2ihcF (Woman using laptop concentrating)
|
||||
[2]: https://opensource.com/article/20/8/tcsh
|
||||
[3]: https://vimhelp.org/vi_diff.txt.html#vi-differences
|
||||
[4]: https://www.vim.org/download.php
|
||||
[5]: https://opensource.com/sites/default/files/uploads/gvim.jpg (gVim)
|
||||
[6]: https://creativecommons.org/licenses/by-sa/4.0/
|
||||
[7]: https://opensource.com/article/19/3/netbsd-raspberry-pi
|
||||
[8]: https://github.com/mbert/elvis
|
||||
[9]: http://neovim.io
|
||||
[10]: https://opensource.com/article/20/2/lua-cheat-sheet
|
||||
[11]: https://www.vim.org/scripts/script.php?script_id=1658
|
||||
[12]: https://opensource.com/article/20/2/how-install-vim-plugins
|
||||
[13]: https://opensource.com/article/19/7/what-posix-richard-stallman-explains
|
@ -1,28 +1,30 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (geekpi)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: reviewer: (wxy)
|
||||
[#]: publisher: (wxy)
|
||||
[#]: url: (https://linux.cn/article-12928-1.html)
|
||||
[#]: subject: (Why 2020 is the best time to use the Kate text editor)
|
||||
[#]: via: (https://opensource.com/article/20/12/kate-text-editor)
|
||||
[#]: author: (Seth Kenlon https://opensource.com/users/seth)
|
||||
|
||||
为什么 2020 年是使用 Kate 文本编辑器的最佳时机?
|
||||
======
|
||||
了解更多关于长期受喜爱的文本编辑器的信息,它为每个用户提供了一些东西。
|
||||
![Programming at a browser, orange hands][1]
|
||||
|
||||
KDE Plasma 桌面提供了很多东西:一个很棒的桌面、一个灵活的文件管理器,以及紧密集成的应用。然而,人们很容易忽视它的默认文本编辑器,其中之一就是 [Kate][2]]。2020 年 12 月 14 日,[Kate 将迎来 20 岁生日][3],在其 20 年的发展历程中,它在一个简单明了的编辑器和一个适度的集成开发环境 (IDE) 之间取得了完美的平衡。
|
||||
> 了解更多关于长期受喜爱的文本编辑器的信息,它为每个用户提供了一些东西。
|
||||
|
||||
![](https://img.linux.net.cn/data/attachment/album/202012/17/133952wga2azisy8uy1ajz.jpg)
|
||||
|
||||
KDE Plasma 桌面提供了很多东西:一个很棒的桌面、一个灵活的文件管理器,以及紧密集成的应用。然而,人们很容易忽视它的默认文本编辑器,其中之一就是 [Kate][2]。2020 年 12 月 14 日,[Kate 将迎来 20 岁生日][3],在其 20 年的发展历程中,它在一个简单明了的编辑器和一个适度的集成开发环境 (IDE) 之间取得了完美的平衡。
|
||||
|
||||
### 安装 Kate
|
||||
|
||||
如果你正在运行 KDE Plasma 桌面,你可能已经安装了 Kate。如果还没有安装,不管你运行的是哪个桌面,你都可以在你的软件仓库中找到它。
|
||||
|
||||
另外,[你可以在 Linux 或 Chromebook 上从][4][Flathub.org][5]使用上的 Flatpak 安装 Kate。
|
||||
另外,[你可以在 Linux 或 Chromebook 上从][4] [Flathub.org][5] 使用 Flatpak 安装 Kate。
|
||||
|
||||
在 Windows 上,[你可以从 Windows 商店获得 Kate][6]。
|
||||
|
||||
要在 macOS 上安装它,[从 KDE build 网站下载 macOS 构建][7]。
|
||||
要在 macOS 上安装它,[从 KDE build 网站下载 macOS 版本][7]。
|
||||
|
||||
### 所有的功能
|
||||
|
||||
@ -34,11 +36,11 @@ KDE Plasma 桌面提供了很多东西:一个很棒的桌面、一个灵活的
|
||||
|
||||
不过,这还不是全部。听起来可能有很多,但布局很方便,很直观。在菜单和设置中还有更多的功能。
|
||||
|
||||
Kate 的功能有集成 Git、文件浏览器、shell、打开文档或项目面板、单词补全、XML 补全、标签式界面、分屏和插件结构,因此你可以进一步扩展其功能。
|
||||
Kate 的功能有集成 Git、文件浏览器、shell、打开文档或项目的面板、单词补全、XML 补全、标签式界面、分屏和插件结构,因此你可以进一步扩展其功能。
|
||||
|
||||
### 给所有用户使用的编辑器
|
||||
|
||||
Kate 的极强灵活性使它既是一个简单的文本编辑器,又是一个强大的 IDE。通过默认使用熟悉的界面,它吸引了广大的用户,但通过提供与调试器、编译器和代码检查器集成的能力,它吸引了开发人员。
|
||||
Kate 的极强灵活性使它既是一个简单的文本编辑器,又是一个强大的 IDE。通过默认使用的熟悉的界面,它吸引了广大的用户;而通过提供与调试器、编译器和代码检查器集成的能力,它吸引了开发人员。
|
||||
|
||||
因为它允许用户控制它的 UI 布局,Kate 确保每个用户都能优化使用它的体验。传统上,这一直是一个难以平衡的问题:一个拥有太多功能的编辑器给人的感觉太像一个臃肿的 IDE,而一个界面简单、功能模糊的编辑器给人的感觉是基础的或不方便的。Kate 将真正有用的功能放在了 UI 的最前面,从而让每个人都能享受到,同时又让高级功能可以被发现,但又不碍事。
|
||||
|
||||
@ -51,7 +53,7 @@ via: https://opensource.com/article/20/12/kate-text-editor
|
||||
作者:[Seth Kenlon][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/) 荣誉推出
|
||||
|
@ -0,0 +1,109 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (geekpi)
|
||||
[#]: reviewer: (wxy)
|
||||
[#]: publisher: (wxy)
|
||||
[#]: url: (https://linux.cn/article-12930-1.html)
|
||||
[#]: subject: (Experience the useful features of the Xedit text editor)
|
||||
[#]: via: (https://opensource.com/article/20/12/xedit)
|
||||
[#]: author: (Seth Kenlon https://opensource.com/users/seth)
|
||||
|
||||
体验 Xedit 文本编辑器的实用功能
|
||||
======
|
||||
|
||||
> Xedit 是 X11 图形服务器的一部分,它不算好看,但却有足够的隐藏功能,使它成为一个严肃的文本编辑器。
|
||||
|
||||
![](https://img.linux.net.cn/data/attachment/album/202012/18/075942uzhgjgxfxve7p2ot.jpg)
|
||||
|
||||
X11 图形服务器由 [X.org][2] 发布,它有一些象征性的应用来展示如何使用它提供的工具进行编程。这些应用包括从 [TWM][3] 桌面到愚蠢但催眠的 Xeyes。它还包括一个名为 Xedit 的文本编辑器,它是一个看似简单的应用,却有足够的隐藏功能,使其成为一个严肃的编辑器。
|
||||
|
||||
### 安装 Xedit
|
||||
|
||||
如果你使用的是 Linux 或 BSD,你可以从你的发行版软件仓库或 ports 树中安装 Xedit。它有时会出现在一个名为 X11-apps 的软件包中,与其他 X11 应用捆绑在一起。
|
||||
|
||||
在 macOS 上,你可以安装 [XQuartz][4],它提供了 Xedit、Xeyes 和其他一些小程序(以及一个 X11 图形服务器)。
|
||||
|
||||
### 启动 Xedit
|
||||
|
||||
如果它被列在你的应用菜单的话,你可以从中启动 Xedit。尽管它绝对是一个 GUI 应用,但有些发行版将它视为命令而不是 GUI 应用,所以它可能不会被列在应用菜单中。这时,你可以从终端启动 Xedit。如果你输入 `xedit &` 来启动应用,它就会启动一个空的 Xedit 编辑器,可以随时输入。如果你在输入启动命令的同时输入一个现有的文件名,Xedit 启动时会将文件加载到缓冲区。
|
||||
|
||||
```
|
||||
$ xedit example.txt &
|
||||
```
|
||||
|
||||
![Xedit][5]
|
||||
|
||||
### 加载文件
|
||||
|
||||
在打开的 Xedit 实例中,你可以在顶部文本输入框中输入文件的路径来加载文件。点击 **Load** 按钮(在文本输入框的左边),将文件读入 Xedit 窗口。
|
||||
|
||||
![Load Xedit][7]
|
||||
|
||||
你可以同时打开多个文件。当一个文件被加载时,它将获取焦点并出现在你的主 Xedit 缓冲区(主窗口中的大文本输入框),并将任何现有的文件切换到一个隐藏的缓冲区。
|
||||
|
||||
你可以使用组合键在缓冲区之间切换,这对 Emacs 用户而言很熟悉,但对其他用户会感到困惑。首先,按下 `Ctrl+X`。放开然后按 `Ctrl+B`。
|
||||
|
||||
### 组合键
|
||||
|
||||
一开始执行需要连续*两*个键盘快捷键的操作感觉很奇怪,但过了一段时间,你就会习惯。事实上,作为一个经常使用 Emacs 的用户,我发现复合键组合很有节奏感。我很惊讶也很高兴地发现,我最喜欢的一些快捷键在 Xedit 中也有效。
|
||||
|
||||
原来,Xedit 从几个灵感来源借用了键盘快捷键。如果你是 Emacs 用户,你会发现最常见的组合在 Xedit 中有效。例如,`C-x C-f` (即 `Ctrl+X` 后是 `Ctrl+F`)可以回到顶部的文本输入框来加载文件,而 `C-x C-s`(`Ctrl+X` 后是 `Ctrl+S`)可以保存文件。令人惊讶的是,`C-x 3` 甚至可以垂直分割窗口,而 `C-x 2` 则可以水平分割,`C-x 0` 或 `C-x 1` 则可以移除分割。
|
||||
|
||||
Emacs 或 Bash 用户熟悉的编辑命令也适用:
|
||||
|
||||
* `Ctrl+A` 移动到行首。
|
||||
* `Ctrl+E` 移至行尾。
|
||||
* `Alt+B` 向后移动一个单词。
|
||||
* `Ctrl+B` 向后移动一个字符。
|
||||
* `Ctrl+F` 向前移动一个字符。
|
||||
* `Alt+F` 向前移动一个单词。
|
||||
* `Ctrl+D 删除下一个字符。
|
||||
|
||||
还有更多,它们都在 Xedit 手册页面上列出。
|
||||
|
||||
### 使用行编辑模式
|
||||
|
||||
Xedit 还含有一个类似 `ex` 的行编辑器,这对 [Vi][8] 和 `ed` 甚至 `sed` 用户应该很熟悉。要进入行编辑模式,按下 `Esc` 键。这将使你处于顶部的文本输入框,但处于命令模式。编辑命令使用的语法是:*行号*后面跟着一个*命令*和*参数*。
|
||||
|
||||
比如说你有这个文本文件:
|
||||
|
||||
```
|
||||
ed is the standard Unix text editor.
|
||||
This is line number two.
|
||||
```
|
||||
|
||||
你决定将第 1 行的 `ed` 改为 `Xedit`。在 Xedit 中,移动到第 1 行,按下 `Esc`,然后输入 `.,s/ed/Xedit/`。
|
||||
|
||||
```
|
||||
Xedit is the standard Unix text editor.
|
||||
This is line number two.
|
||||
```
|
||||
|
||||
不用将光标移到下一行,你可以将 `two` 改为 `the second`。按下 `Esc`,然后输入 `2,s/two/the second/`。
|
||||
|
||||
各种命令和有效的参数在 Xedit 的手册页中列出。
|
||||
|
||||
### 简单但稳定
|
||||
|
||||
Xedit 并不算好看,它很简单,没有菜单可言,但它借鉴了一些最好的 Unix 编辑器的流行的便利性。下次你在寻找新的编辑器时,不妨试试 Xedit。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/20/12/xedit
|
||||
|
||||
作者:[Seth Kenlon][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[geekpi](https://github.com/geekpi)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [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/browser_screen_windows_files.png?itok=kLTeQUbY (Computer screen with files or windows open)
|
||||
[2]: https://www.x.org/wiki/
|
||||
[3]: https://opensource.com/article/19/12/twm-linux-desktop
|
||||
[4]: http://xquartz.org
|
||||
[5]: https://opensource.com/sites/default/files/uploads/xedit.jpeg (Xedit)
|
||||
[6]: https://creativecommons.org/licenses/by-sa/4.0/
|
||||
[7]: https://opensource.com/sites/default/files/uploads/xedit-load.jpg (Load Xedit)
|
||||
[8]: https://opensource.com/article/20/12/vi-text-editor
|
@ -1,34 +1,34 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (geekpi)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: reviewer: (wxy)
|
||||
[#]: publisher: (wxy)
|
||||
[#]: url: (https://linux.cn/article-12936-1.html)
|
||||
[#]: subject: (Add storage to your Fedora system with LVM)
|
||||
[#]: via: (https://fedoramagazine.org/add-storage-to-your-fedora-system-with-lvm/)
|
||||
[#]: author: (Tim Bosse https://fedoramagazine.org/author/maztaim/)
|
||||
|
||||
Add storage to your Fedora system with LVM
|
||||
使用 LVM 为你的 Fedora 系统添加存储
|
||||
======
|
||||
|
||||
![][1]
|
||||
|
||||
Sometimes there is a need to add another disk to your system. This is where Logical Volume Management (LVM) comes in handy. The cool thing about LVM is that it’s fairly flexible. There are several ways to add a disk. This article describes one way to do it.
|
||||
有时需要在系统中添加另一块磁盘。这就是<ruby>逻辑卷管理<rt>Logical Volume Management</rt></ruby>(LVM)的用武之地。LVM 的好处之处在于它相当灵活。有几种方法可以添加一块磁盘。这篇文章介绍了一种方法。
|
||||
|
||||
### Heads up!
|
||||
### 注意!
|
||||
|
||||
This article does not cover the process of physically installing a new disk drive into your system. Consult your system and disk documentation on how to do that properly.
|
||||
这篇文章并不包括将新的磁盘物理地安装到系统中的过程。请查阅你的系统和磁盘文档,了解如何正确地进行安装。
|
||||
|
||||
**Important:** Always make sure you have backups of important data. The steps described in this article will destroy data if it already exists on the new disk.
|
||||
**重要:** 一定要确保你已经备份重要数据。如果新磁盘已有数据,那么本文中描述的步骤将破坏数据。
|
||||
|
||||
### Good to know
|
||||
### 最好了解
|
||||
|
||||
This article doesn’t cover every LVM feature deeply; the focus is on adding a disk. But basically, LVM has _volume groups_, made up of one or more partitions and/or disks. You add the partitions or disks as _physical volumes_. A volume group can be broken down into many _logical volumes_. Logical volumes can be used as any other storage for filesystems, ramdisks, etc. More information can be found [here][2].
|
||||
本文并没有深入介绍 LVM 的每一个功能,重点是添加磁盘。但基本上你要了解,LVM 有<ruby>卷组<rt>volume group</rt></ruby>(VG),它由一个或多个分区和/或磁盘组成。你把这些分区或磁盘以<ruby>物理卷<rt>physical volume</rt></ruby>(PV)的方式添加到卷组。一个卷组可以分成许多<ruby>逻辑卷<rt>logical volume</rt></ruby>(LV)。逻辑卷可以作为文件系统、ramdisk 等其他存储使用。更多信息可以在[这里][2]中找到。
|
||||
|
||||
Think of the _physical volumes_ as forming a pool of storage (a _volume group_) from which you then carve out _logical volumes_ for your system to use directly.
|
||||
可以看作是,把物理卷形成一个存储池(一个卷组),然后从这个存储池中划分出逻辑卷,供你的系统直接使用。
|
||||
|
||||
### Preparation
|
||||
### 准备
|
||||
|
||||
Make sure you can see the disk you want to add. Use _lsblk_ prior to adding the disk to see what storage is already available or in use.
|
||||
确保你能看到你要添加的磁盘。在添加磁盘之前使用 `lsblk` 查看哪些存储空间已经可用或正在使用。
|
||||
|
||||
```
|
||||
$ lsblk
|
||||
@ -40,9 +40,9 @@ vda 252:0 0 20G 0 disk
|
||||
└─fedora_fedora-root 253:0 0 19G 0 lvm /
|
||||
```
|
||||
|
||||
This article uses a virtual machine with virtual storage. Therefore the device names start with _vda_ for the first disk, _vdb_ for the second, and so on. The name of your device may be different. Many systems will see physical disks as _sda_ for the first disk, _sdb_ for the second, and so on.
|
||||
本文使用的是带有虚拟存储的虚拟机,因此设备名称以 `vda` 开头代表第一个磁盘,`vdb` 代表第二个磁盘,以此类推。你的设备名称可能不同。许多系统会将 `sda` 作为第一个物理磁盘,`sdb` 代表第二个磁盘,以此类推。
|
||||
|
||||
Once the new disk has been connected and your system is back up and running, use _lsblk_ again to see the new block device.
|
||||
当已连接新磁盘,并且你的系统已备份且正在运行,再次使用 `lsblk` 来查看新的块设备。
|
||||
|
||||
```
|
||||
$ lsblk
|
||||
@ -55,14 +55,14 @@ vda 252:0 0 20G 0 disk
|
||||
vdb 252:16 0 10G 0 disk
|
||||
```
|
||||
|
||||
There is now a new device named _vdb_. The location for the device is _/dev/vdb_.
|
||||
现在有一个名为 `vdb` 的新设备。该设备的位置是 `/dev/vdb`。
|
||||
|
||||
```
|
||||
$ ls -l /dev/vdb
|
||||
brw-rw----. 1 root disk 252, 16 Nov 24 12:56 /dev/vdb
|
||||
```
|
||||
|
||||
We can see the disk, but we cannot use it with LVM yet. If you run _blkid_ you should not see it listed. For this and following commands, you’ll need to ensure your system is [configured so you can use _sudo_][3]:
|
||||
我们可以看到磁盘,但我们还不能用 LVM 来使用它。如果你运行 `blkid`,你应该不会看到它被列出。对于这个和之后的命令,你需要确保你的系统[已配置好,这样你可以使用 sudo][3]:
|
||||
|
||||
```
|
||||
$ sudo blkid
|
||||
@ -72,16 +72,16 @@ $ sudo blkid
|
||||
/dev/zram0: UUID="fc6d7a48-2bd5-4066-9bcf-f062b61f6a60" TYPE="swap"
|
||||
```
|
||||
|
||||
### Add the disk to LVM
|
||||
### 将磁盘添加到 LVM 中
|
||||
|
||||
Initialize the disk using _pvcreate_. You need to pass the full path to the device. In this example it is _/dev/vdb_; on your system it may be _/dev/sdb_ or another device name.
|
||||
使用 `pvcreate` 初始化磁盘。你需要传递设备的完整路径。在这个例子中,它是 `/dev/vdb`。在你的系统中,它可能是 `/dev/sdb` 或其他设备名。
|
||||
|
||||
```
|
||||
$ sudo pvcreate /dev/vdb
|
||||
Physical volume "/dev/vdb" successfully created.
|
||||
```
|
||||
|
||||
You should see the disk has been initialized as an LVM2_member when you run _blkid_:
|
||||
当你运行 `blkid` 时,你应该看到磁盘已经被初始化为一个 `LVM2_member`:
|
||||
|
||||
```
|
||||
$ sudo blkid
|
||||
@ -92,7 +92,7 @@ $ sudo blkid
|
||||
/dev/vdb: UUID="4uUUuI-lMQY-WyS5-lo0W-lqjW-Qvqw-RqeroE" TYPE="LVM2_member"
|
||||
```
|
||||
|
||||
You can list all physical volumes currently available using _pvs_:
|
||||
你可以使用 `pvs` 列出当前所有可用的物理卷:
|
||||
|
||||
```
|
||||
$ sudo pvs
|
||||
@ -101,11 +101,11 @@ PV VG Fmt Attr PSize PFree
|
||||
/dev/vdb lvm2 --- 10.00g 10.00g
|
||||
```
|
||||
|
||||
_/dev/vdb_ is listed as a PV (phsyical volume), but it isn’t assigned to a VG (Volume Group) yet.
|
||||
`/dev/vdb` 被列为一个 PV (物理卷),但还没有分配到一个 VG (卷组)。
|
||||
|
||||
### Add the pysical volume to a volume group
|
||||
### 将物理卷添加到一个卷组
|
||||
|
||||
You can find a list of available volume groups using _vgs_:
|
||||
你可以使用 `vgs` 找到可用的卷组列表:
|
||||
|
||||
```
|
||||
$ sudo vgs
|
||||
@ -113,23 +113,23 @@ VG #PV #LV #SN Attr VSize VFree
|
||||
fedora_fedora 1 1 0 wz--n- 19.00g 0
|
||||
```
|
||||
|
||||
In this example, there is only one volume group available. Next, add the physical volume to _fedora_fedora_:
|
||||
在本例中,只有一个卷组可用。接下来,将物理卷添加到 `fedora_fedora`:
|
||||
|
||||
```
|
||||
$ sudo vgextend fedora_fedora /dev/vdb
|
||||
Volume group "fedora_fedora" successfully extended
|
||||
```
|
||||
|
||||
You should now see the physical volume is added to the volume group:
|
||||
你现在应该看到物理卷已被添加到卷组中:
|
||||
|
||||
```
|
||||
$ sudo pvs
|
||||
$ sudo pvs
|
||||
PV VG Fmt Attr PSize PFree
|
||||
/dev/vda2 fedora_fedora lvm2 a– <19.00g 0
|
||||
/dev/vdb fedora_fedora lvm2 a– <10.00g <10.00g
|
||||
```
|
||||
|
||||
Look at the volume groups:
|
||||
看一下卷组:
|
||||
|
||||
```
|
||||
$ sudo vgs
|
||||
@ -137,7 +137,7 @@ VG #PV #LV #SN Attr VSize VFree
|
||||
fedora_fedora 2 1 0 wz–n- 28.99g <10.00g
|
||||
```
|
||||
|
||||
You can get a detailed list of the specific volume group and physical volumes as well:
|
||||
你也可以获得具体卷组和物理卷的详细列表:
|
||||
|
||||
```
|
||||
$ sudo vgdisplay fedora_fedora
|
||||
@ -163,23 +163,23 @@ Free PE / Size 2559 / 10.00 GiB
|
||||
VG UUID C5dL2s-dirA-SQ15-TfQU-T3yt-l83E-oI6pkp
|
||||
```
|
||||
|
||||
Look at the PV:
|
||||
看下物理卷:
|
||||
|
||||
```
|
||||
$ sudo pvdisplay /dev/vdb
|
||||
--- Physical volume ---
|
||||
PV Name /dev/vdb
|
||||
VG Name fedora_fedora
|
||||
PV Size 10.00 GiB / not usable 4.00 MiB
|
||||
Allocatable yes
|
||||
PE Size 4.00 MiB
|
||||
Total PE 2559
|
||||
Free PE 2559
|
||||
Allocated PE 0
|
||||
PV UUID 4uUUuI-lMQY-WyS5-lo0W-lqjW-Qvqw-RqeroE
|
||||
--- Physical volume ---
|
||||
PV Name /dev/vdb
|
||||
VG Name fedora_fedora
|
||||
PV Size 10.00 GiB / not usable 4.00 MiB
|
||||
Allocatable yes
|
||||
PE Size 4.00 MiB
|
||||
Total PE 2559
|
||||
Free PE 2559
|
||||
Allocated PE 0
|
||||
PV UUID 4uUUuI-lMQY-WyS5-lo0W-lqjW-Qvqw-RqeroE
|
||||
```
|
||||
|
||||
Now that we have added the disk, we can allocate space to logical volumes (LVs):
|
||||
现在我们已经添加了磁盘,我们可以为逻辑卷 (LV) 分配空间:
|
||||
|
||||
```
|
||||
$ sudo lvs
|
||||
@ -187,7 +187,7 @@ LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
|
||||
root fedora_fedora -wi-ao---- 19.00g
|
||||
```
|
||||
|
||||
Look at the logical volumes. Here’s a detailed look at the root LV:
|
||||
看一下逻辑卷。下面是详细的逻辑卷信息:
|
||||
|
||||
```
|
||||
$ sudo lvdisplay fedora_fedora/root
|
||||
@ -208,7 +208,7 @@ Read ahead sectors auto
|
||||
Block device 253:0
|
||||
```
|
||||
|
||||
Look at the size of the root filesystem and compare it to the logical volume size.
|
||||
查看根文件系统(`/`)的大小,并将它与逻辑卷大小进行比较。
|
||||
|
||||
```
|
||||
$ df -h /
|
||||
@ -216,7 +216,7 @@ Filesystem Size Used Avail Use% Mounted on
|
||||
/dev/mapper/fedora_fedora-root 19G 1.4G 17G 8% /
|
||||
```
|
||||
|
||||
The logical volume and the filesystem both agree the size is 19G. Let’s add 5G to the root logical volume:
|
||||
逻辑卷和文件系统大小都为 19G。让我们给根逻辑卷(`root`)增加 5G。
|
||||
|
||||
```
|
||||
$ sudo lvresize -L +5G fedora_fedora/root
|
||||
@ -224,7 +224,7 @@ Size of logical volume fedora_fedora/root changed from 19.00 GiB (4863 extents)
|
||||
Logical volume fedora_fedora/root successfully resized.
|
||||
```
|
||||
|
||||
We now have 24G available to the logical volume. Look at the _/_ filesystem.
|
||||
我们现在有 24G 的逻辑卷可用。看看根文件系统(`/`)。
|
||||
|
||||
```
|
||||
$ df -h /
|
||||
@ -232,7 +232,7 @@ Filesystem Size Used Avail Use% Mounted on
|
||||
/dev/mapper/fedora_fedora-root 19G 1.4G 17G 8% /
|
||||
```
|
||||
|
||||
We are still showing only 19G free. This is because the logical volume is not the same as the filesytem. To use the new space added to the logical volume, resize the filesystem.
|
||||
我们仍然显示只有 19G 的空闲空间,这是因为逻辑卷与文件系统不一样。要使用增加到逻辑卷的新空间,请调整文件系统的大小。
|
||||
|
||||
```
|
||||
$ sudo resize2fs /dev/fedora_fedora/root
|
||||
@ -242,7 +242,7 @@ old_desc_blocks = 3, new_desc_blocks = 3
|
||||
The filesystem on /dev/fedora_fedora/root is now 6290432 (4k) blocks long.
|
||||
```
|
||||
|
||||
Look at the size of the filesystem.
|
||||
看看文件系统的大小。
|
||||
|
||||
```
|
||||
$ df -h /
|
||||
@ -250,9 +250,9 @@ Filesystem Size Used Avail Use% Mounted on
|
||||
/dev/mapper/fedora_fedora-root 24G 1.4G 21G 7% /
|
||||
```
|
||||
|
||||
As you can see, the root file system _(/)_ has taken all of the space available on the logical volume and no reboot was needed.
|
||||
正如你所看到的,根文件系统(`/`)已经占用了逻辑卷上的所有可用空间,而且不需要重新启动。
|
||||
|
||||
You have now initialized a disk as a physical volume, and extended the volume group with the new physical volume. After that you increased the size of the logical volume, and resized the filesystem to use the new space from the logical volume.
|
||||
现在你已经将一个磁盘初始化为物理卷,并使用新的物理卷扩展了卷组。之后,你增加了逻辑卷的大小,并调整了文件系统的大小,以使用逻辑卷的新空间。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
@ -260,8 +260,8 @@ via: https://fedoramagazine.org/add-storage-to-your-fedora-system-with-lvm/
|
||||
|
||||
作者:[Tim Bosse][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
译者:[geekpi](https://github.com/geekpi)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
@ -269,4 +269,4 @@ via: https://fedoramagazine.org/add-storage-to-your-fedora-system-with-lvm/
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://fedoramagazine.org/wp-content/uploads/2020/11/lvm-add-disk-816x345.jpg
|
||||
[2]: https://en.wikipedia.org/wiki/Logical_Volume_Manager_(Linux)
|
||||
[3]: https://fedoramagazine.org/howto-use-sudo/
|
||||
[3]: https://fedoramagazine.org/howto-use-sudo/
|
@ -1,24 +1,26 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (geekpi)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: reviewer: (wxy)
|
||||
[#]: publisher: (wxy)
|
||||
[#]: url: (https://linux.cn/article-12933-1.html)
|
||||
[#]: subject: (Optimize your GNOME experience with the Gedit text editor)
|
||||
[#]: via: (https://opensource.com/article/20/12/gedit)
|
||||
[#]: author: (Seth Kenlon https://opensource.com/users/seth)
|
||||
|
||||
使用 Gedit 文本编辑器优化你的 GNOME 体验
|
||||
使用 gedit 文本编辑器优化你的 GNOME 体验
|
||||
======
|
||||
它是一个可以完成工作的简约编辑器,并以隐藏的增强功能使得事情更简单。
|
||||
![Working from home at a laptop][1]
|
||||
|
||||
作为默认的文本编辑器是一项吃力不讨好的工作。人们通常把默认文本编辑器几乎看作是一个演示应用,一个稍微好一点的 “hello World” 示例,说明应用在该平台上的是如何运行的。在极少数情况下,当用户需要将一些文本保存到一个可能永远不会再看的文件中时,用户会找到默认文本编辑器。对于“严肃”的工作,他们会转向文字处理器或 IDE,或终端中的编辑器,或者至少是一个不同的文本编辑器,必须像“真正的”应用一样下载和安装。
|
||||
> 它是一个可以完成工作的简约编辑器,并以隐藏的增强功能使得事情更简单。
|
||||
|
||||
很奇怪,默认的文本编辑器很难被人重视,然而 GNOME 桌面的编辑器 Gedit 却被广泛认为是一个真正有价值的文本编辑器,超越了它所在的桌面。它被用作网页设计课程的必备文本编辑器,是新手开发者和系统管理员的推荐工具,也是许多桌面 Linux 用户最喜欢的可靠伙伴。
|
||||
![](https://img.linux.net.cn/data/attachment/album/202012/19/110419snchihpnjn8juxqc.jpg)
|
||||
|
||||
作为默认的文本编辑器是一项吃力不讨好的工作。人们通常把默认文本编辑器几乎看作是一个演示应用、一个稍微好一点的 “hello World” 示例,说明应用在该平台上的是如何运行的。在极少数情况下,当用户需要将一些文本保存到一个可能永远不会再看的文件中时,用户会找到默认文本编辑器。对于“严肃”的工作,他们会转向文字处理器或 IDE,或终端中的编辑器,或者至少是一个不同的文本编辑器,必须像“真正的”应用一样下载和安装。
|
||||
|
||||
很奇怪,默认的文本编辑器很难被人重视,然而 GNOME 桌面的编辑器 gedit 却被广泛认为是一个真正有价值的文本编辑器,超越了它所在的桌面。它被用作网页设计课程的必备文本编辑器,是新手开发者和系统管理员的推荐工具,也是许多桌面 Linux 用户最喜欢的可靠伙伴。
|
||||
|
||||
### 安装 gedit
|
||||
|
||||
如果你运行的是 GNOME 桌面,你可能已经安装了 gedit,尽管它可能只作为“文本编辑器”出现在你的应用菜单中。如果你不确定,只需在你的活动界面中输入 **gedit**,然后在打开的文本编辑器中进入**关于**菜单项。
|
||||
如果你运行的是 GNOME 桌面,你可能已经安装了 gedit,尽管它可能只作为“文本编辑器”出现在你的应用菜单中。如果你不确定,只需在你的活动界面中输入 `gedit`,然后在打开的文本编辑器中进入 “About” 菜单项。
|
||||
|
||||
![gedit terminal box with black background and white letters][2]
|
||||
|
||||
@ -28,7 +30,7 @@
|
||||
|
||||
### 使用 gedit
|
||||
|
||||
当你第一次启动 gedit 时,你会看到一个简约的界面,包括一个文本输入面板、一个标题栏和一个位于窗口底部的状态面板。底部的状态面板提供了一些常用的设置:你想使用哪种语法高亮模式、你喜欢的标签宽度、以及一些流行的偏好,如行号、文本换行等等。这些选项中的大部分也可以在“首选项”菜单中进行全局设置,它可在应用程序右上角的“汉堡”样式的菜单中找到。
|
||||
当你第一次启动 gedit 时,你会看到一个简约的界面,包括一个文本输入面板、一个标题栏和一个位于窗口底部的状态面板。底部的状态面板提供了一些常用的设置:你想使用哪种语法高亮模式、你喜欢的制表符宽度、以及一些流行的偏好,如行号、文本换行等等。这些选项中的大部分也可以在 “Preferences” 菜单中进行全局设置,它可在应用程序右上角的 “汉堡” 样式的菜单中找到。
|
||||
|
||||
### gedit 的隐藏功能
|
||||
|
||||
@ -36,19 +38,17 @@
|
||||
|
||||
这些键盘功能在 gedit 中并没有被记录下来:
|
||||
|
||||
* **Ctrl+D** 删除当前行。这对于编码者或以 markdown 格式(如 Asciidoc、reST 或 CommonMark)写作的人特别有用。
|
||||
* **Ctrl+I** 会弹出 **Go to Line** 下拉框。输入一个数字,你就会立即跳到该行。
|
||||
* **Alt+向上箭头** 或 **Alt+向下箭头** 会抓取当前行,并将它在文档中向上或向下移动。
|
||||
* **Alt+向左箭头** 或 **Alt+向右箭头** 抓取最近的单词(在光标左侧)并将其向左或向右移动。
|
||||
* 要输入特殊的 Unicode 字符,请按下并松开 **Shift+Ctrl+U**,然后输入 Unicode 字符代码。你通常必须查找字符代码(除非你已经记住了一些,但谁有记性来记住这些字符代码?)例如,要打出一只企鹅,按下然后松开 **Shift+Ctrl+U**。当你松开按键后,你会看到一个带下划线的 U,然后输入 **1F427**,后面跟一个空格,你的 Unicode 字符就会变成一个友好的 🐧。诚然,这并不完全是 gedit 所独有的,但这是个很有用的技巧,而且它在 gedit 中也确实有效。
|
||||
|
||||
|
||||
* `Ctrl+D` 删除当前行。这对于编码者或以标记格式(如 Asciidoc、reST 或 CommonMark)写作的人特别有用。
|
||||
* `Ctrl+I` 会弹出 “Go to Line” 下拉框。输入一个数字,你就会立即跳到该行。
|
||||
* `Alt+向上箭头` 或 `Alt+向下箭头` 会抓取当前行,并将它在文档中向上或向下移动。
|
||||
* `Alt+向左箭头` 或 `Alt+向右箭头` 抓取最近的单词(在光标左侧)并将其向左或向右移动。
|
||||
* 要输入特殊的 Unicode 字符,请按下 `Shift+Ctrl+U` 并松开,然后输入 Unicode 字符代码。你通常必须查找字符代码(除非你已经记住了一些,但谁有记性来记住这些字符代码?)例如,要打出一只企鹅,按下 `Shift+Ctrl+U` 然后松开。当你松开按键后,你会看到一个带下划线的 U,然后输入 `1F427`,后面跟一个空格,你的 Unicode 字符就会变成一个友好的 `🐧`。诚然,这并不完全是 gedit 所独有的,但这是个很有用的技巧,而且它在 gedit 中也确实有效。
|
||||
|
||||
### 稳定简单
|
||||
|
||||
Gedit 很像 GNOME 本身。它客观上比许多同类软件(比如 KDE 的 Kate)更简单,但它仍然能够满足你日常 80% 或 90% 的期望。
|
||||
|
||||
当然,可能会有一些任务 gedit 不是最佳工具。你可能会发现自己要深入研究一些独特的日志文件,或者需要一个精确的解析器或代码检查器,你会转向专门的应用。这没关系。Gedit 并不意味着对所有用户都适用。但对于那些需要文本编辑器的人来说,它是一个很好的文本编辑器,有时这就是所需要的。在 Linux 或者在任何你正在使用的平台上,试一下 gedit,因为它很有可能是一个比默认的更好的选择。
|
||||
当然,可能会有一些任务 gedit 不是最佳工具。你可能会发现自己要深入研究一些独特的日志文件,或者需要一个精确的解析器或代码检查器,你会转向专门的应用。这没关系。gedit 并不意味着对所有用户都适用。但对于那些需要文本编辑器的人来说,它是一个很好的文本编辑器,有时这就是所需要的。在 Linux 或者在任何你正在使用的平台上,试一下 gedit,因为它很有可能是一个比默认应用的更好的选择。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
@ -57,7 +57,7 @@ via: https://opensource.com/article/20/12/gedit
|
||||
作者:[Seth Kenlon][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/) 荣誉推出
|
||||
|
123
published/20201208 Learn Bash by writing an interactive game.md
Normal file
123
published/20201208 Learn Bash by writing an interactive game.md
Normal file
@ -0,0 +1,123 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (wxy)
|
||||
[#]: reviewer: (wxy)
|
||||
[#]: publisher: (wxy)
|
||||
[#]: url: (https://linux.cn/article-12962-1.html)
|
||||
[#]: subject: (Learn Bash by writing an interactive game)
|
||||
[#]: via: (https://opensource.com/article/20/12/learn-bash)
|
||||
[#]: author: (Jim Hall https://opensource.com/users/jim-hall)
|
||||
|
||||
通过编写互动游戏学习 Bash
|
||||
======
|
||||
|
||||
> 编程一个简单的游戏是练习一门新语言并与其他你掌握的语言进行比较的好方法。
|
||||
|
||||
![](https://img.linux.net.cn/data/attachment/album/202012/28/010432yq3vgsqtiol9zzi6.jpg)
|
||||
|
||||
学习一门新的编程语言是很有趣的。每当我尝试学习一门新的语言时,我都会专注于定义变量、编写语句和评估表达式。一旦我对这些概念有了大致的了解,我通常可以自己弄清楚其余的概念。大多数编程语言都有一些相似之处,所以一旦你了解了一种编程语言,学习下一种编程语言就是要弄清楚其独特的细节,认识到其中的差异。
|
||||
|
||||
为了帮助我练习一种新的编程语言,我喜欢写一些测试程序。我经常写的一个示例程序是一个简单的“猜数字”程序,电脑在 1 到 100 之间选一个数字,让我猜这个数字。程序会一直循环,直到我猜对为止。
|
||||
|
||||
“猜数字”程序锻炼了编程语言中的几个概念:如何给变量赋值,如何写语句,如何进行条件判断和循环。对于学习一门新的编程语言来说,这是一个很好的实践实验。
|
||||
|
||||
### 用 Bash 猜数字
|
||||
|
||||
[Bash][2] 是大多数 Linux 系统的标准 shell。除了提供丰富的命令行用户界面外,Bash 还以*脚本*的形式支持完整的编程语言。
|
||||
|
||||
如果你对 Bash 不熟悉,我推荐你看这些介绍:
|
||||
|
||||
* [什么是 Bash?][3]。
|
||||
* [开始使用 Bash 编程][4]
|
||||
* [系统管理员的 Bash 脚本入门][5]
|
||||
* [如何在 Bash 中编写函数][6]
|
||||
* [阅读更多关于 Bash 的信息][7]
|
||||
|
||||
你可以通过编写一个 Bash 版本的“猜数字”游戏来探索它。这是我的实现:
|
||||
|
||||
```
|
||||
#!/bin/bash
|
||||
|
||||
number=$(( $RANDOM % 100 + 1 ))
|
||||
|
||||
echo "Guess a number between 1 and 100"
|
||||
|
||||
guess=0
|
||||
|
||||
while [ "0$guess" -ne $number ] ; do
|
||||
read guess
|
||||
[ "0$guess" -lt $number ] && echo "Too low"
|
||||
[ "0$guess" -gt $number ] && echo "Too high"
|
||||
done
|
||||
|
||||
echo "That's right!"
|
||||
exit 0
|
||||
```
|
||||
|
||||
### 拆解这个脚本
|
||||
|
||||
脚本中的第一行,`#!/bin/bash` 告诉 Linux 使用 Bash shell 来运行这个脚本。每个脚本都以 `#!` 字符对(LCTT 译注:释伴)开始,这表示它是一个 shell 脚本。紧跟在`#!` 后面的是要运行的 shell。在本例中,`/bin/bash` 是指 Bash shell。
|
||||
|
||||
要给一个变量赋值,在变量名后面列出 `=` 号。例如,语句 `guess=0` 给 `guess` 变量分配一个零值。
|
||||
|
||||
你也可以使用 `read` 语句提示用户输入一个值。如果你写了 `read guess` 语句,Bash 会等待用户输入一些文本,然后把这个值存储在 `guess` 变量中。
|
||||
|
||||
要引用一个变量的值,在变量名前使用 `$`。所以, 在 `guess` 变量中存储了一个值后, 你可以使用 `$guess` 来检索它。
|
||||
|
||||
你可以使用任何你喜欢的变量名称,但是 Bash 为自己保留了一些特殊的变量名称。一个特殊的变量是 `RANDOM`,每次引用它都会产生一个很大的随机数。
|
||||
|
||||
如果你想在存储一个值的同时执行一个操作,你需要用特殊的括号把语句括起来。这将告诉 Bash 先执行该语句,而 `=` 则将结果值存储在变量中。要评估一个数学表达式,使用 `$(())` 围在你的语句上。双括号表示一个*算术表达式*。在我的例子中,`number=$(( $RANDOM % 100 + 1 ))` 评估表达式 `$RANDOM % 100 + 1`,然后将值存储在 `number` 变量中。
|
||||
|
||||
标准的算术运算符,如 `+`(加)、`-`(减)、`*`(乘)、`/`(除)和 `%`(模)都适用。
|
||||
|
||||
这意味着语句 `number=$(( $RANDOM % 100 + 1 ))` 产生一个 1 到 100 之间的随机数。模数运算符(`%`)返回两个数相除后的余数。在这种情况下,Bash 将一个随机数除以 100,剩下的余数范围是 0 到 99,通过在这个值上加 1,你可以得到一个介于 1 和 100 之间的随机数。
|
||||
|
||||
Bash 支持像循环这样的*条件表达式*和*流程控制*。在“猜数字”的游戏中,只要 `guess` 中的值不等于 `number`,Bash 就会继续循环。如果猜的数小于随机数,Bash 就会打印“太低”,如果猜的数大于数字,Bash 就会打印“太高”。
|
||||
|
||||
### 它是如何工作的
|
||||
|
||||
现在你已经写好了你的 Bash 脚本,你可以运行它来玩“猜数字”游戏。一直猜,直到你找到正确的数字:
|
||||
|
||||
```
|
||||
Guess a number between 1 and 100
|
||||
50
|
||||
Too high
|
||||
30
|
||||
Too high
|
||||
20
|
||||
Too high
|
||||
10
|
||||
Too low
|
||||
15
|
||||
Too high
|
||||
13
|
||||
Too low
|
||||
14
|
||||
That's right!
|
||||
```
|
||||
|
||||
每次运行这个脚本,Bash 都会随机选择一个不同的数字。
|
||||
|
||||
这个“猜数字”游戏是学习新的编程语言时的一个很好的入门程序,因为它以一种很直接的方式锻炼了几个常见的编程概念。通过在不同的编程语言中实现这个简单的游戏,你可以展示一些核心概念,并比较每种语言的细节。
|
||||
|
||||
你有喜欢的编程语言吗?你会如何用它来写“猜数字”游戏呢?请关注本系列文章,看看你可能感兴趣的其他编程语言的例子。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/20/12/learn-bash
|
||||
|
||||
作者:[Jim Hall][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[wxy](https://github.com/wxy)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/jim-hall
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/bash_command_line.png?itok=k4z94W2U (bash logo on green background)
|
||||
[2]: https://en.wikipedia.org/wiki/Bash_(Unix_shell)
|
||||
[3]: https://opensource.com/resources/what-bash
|
||||
[4]: https://opensource.com/article/20/4/bash-programming-guide
|
||||
[5]: https://opensource.com/article/20/4/bash-sysadmins-ebook
|
||||
[6]: https://opensource.com/article/20/6/bash-functions
|
||||
[7]: https://opensource.com/tags/bash
|
@ -0,0 +1,71 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (geekpi)
|
||||
[#]: reviewer: (wxy)
|
||||
[#]: publisher: (wxy)
|
||||
[#]: url: (https://linux.cn/article-12938-1.html)
|
||||
[#]: subject: (Make medit your next Linux terminal text editor)
|
||||
[#]: via: (https://opensource.com/article/20/12/medit)
|
||||
[#]: author: (Seth Kenlon https://opensource.com/users/seth)
|
||||
|
||||
让 medit 成为你的下一个 Linux 代码编辑器
|
||||
======
|
||||
|
||||
> 这款经典的文本编辑器提供了所有的基本功能和一些让你自定义你的体验的令人兴奋的功能。
|
||||
|
||||
![](https://img.linux.net.cn/data/attachment/album/202012/21/103921rqtvtsyvyvy5bsq7.jpg)
|
||||
|
||||
有了 [XEDIT][2]、jEdit、NEdit、[gedit][3],最后还有 [medit][4]。
|
||||
|
||||
在我开始搜索我还没有尝试过的编辑器之前,我还没有听说过 medit,但我很高兴发现了它。如果你正在寻找经典的 gedit 体验(大约是 Gnome 2 上),那么 medit 可能无意间提供了一种出色且现代的近似体验。它也有许多额外的功能,比如可以使用 Python、Lua 或 C 语言编写插件,以及甚至可以将 shell 脚本集成到菜单系统。所有其他常用的功能也都在这里:标签式界面、一个即时的 shell、缩进管理、语法高亮等等。
|
||||
|
||||
### 安装 medit
|
||||
|
||||
你可以从 [mooedit.sourceforge.net][5] 下载 medit。它确认可以在 Linux 和 Windows 上工作。如果你使用的是 Linux,你也可以在你的仓库中找到它。在 Slackware 上,我从 [slackbuilds.org][6] 安装了它。
|
||||
|
||||
![Medit terminal showing examples of Bash script in editor][7]
|
||||
|
||||
### 使用 medit
|
||||
|
||||
medit 宣称自己是一个“为编程和围绕编程”打造的编辑器,事实上,它的诞生是作为一个名为 GAP(<ruby>[群组、算法、编程][8]<rt>Groups、Algorithms、Programming</rt></ruby>)的更大项目的一部分。它的大部分功能都是针对典型的开发者的期望而开发。例如,在 **Edit** 菜单中,有增加和减少缩进的选项,这对于任何试图以可视方式指示范围的程序员来说都是一个常见的任务(对于 Python 程序员来说也是一个明文要求),还有注释或取消注释文本块的选项。
|
||||
|
||||
有些功能对普通用户也很有用。medit 有一个易于使用的标签式界面(既在窗口顶部,也在侧面的弹出式列表中),一个用于快速浏览文件系统的侧面板,在文件中添加书签的功能等等。它还具有针对两种编程语言以及标记语言和 Markdown 的语法高亮显示功能,因此它是可以用于编辑代码和普通文本的编辑器。
|
||||
|
||||
### 颜色方案
|
||||
|
||||
当编辑没有语法关联的纯文本或像 Asciidoc 这样的格式时,medit 没有预设的高亮方案,编辑器会采用你的系统默认值。我使用的是深色主题,所以 medit 在深灰色背景上显示白色文本。
|
||||
|
||||
不过对于语法高亮,文本会根据每个单词在其结构化语言中扮演的角色而变成彩色。一开始,我对 medit 的一些选择有些沮丧,很多颜色在我的深色背景下太暗,无法辨认,而且我觉得所有重要的元素都不够显眼。如果你不喜欢 medit 选择的方案,这个问题的答案在 **Preferences** 中,你可以更改颜色主题。我把我的颜色改成了 Tango,它呈现出一个日光照射的颜色阵列,在我的深色编辑器背景下非常出色,甚至给在 medit 主题下保持白色的元素添加了颜色。
|
||||
|
||||
![Medit terminal showing examples of Bash script in editor using Tango color scheme against dark background][9]
|
||||
|
||||
### 弹出式 Python 控制台
|
||||
|
||||
在 medit 窗口的底部,有一个弹出的终端,用于快速访问 shell。这是一个很好的功能,但坦率地说,在你体验过 Emacs 和 [Kate][10]之后,这感觉很普通。medit 让我惊讶的是它的弹出式 Python 控制台,它从 **Tools** 菜单中启动,并预先导入了 **moo** 和 **gtk** 模块。换句话说,当你启动 medit 的 Python shell 时,你可以查看 medit 构建自身部分的 Python 和 GTK 模块。这是一个很好的功能,也许会给你写插件的灵感(这个弹出终端的是一个用 Python 编写的插件,所以你也可以通过它的代码来了解一个插件是如何编写的)。
|
||||
|
||||
### 经典编辑
|
||||
|
||||
medit 是一款出色的基于 GTK 的编辑器,它具有所有重要的基本功能和一些诱人的额外功能,可以帮助你扩展应用并使其成为你自己的。因为它接受 C、Python、Lua 和 Bash,所以你可以将它用于这几种用途。如果你正在为你的写作寻找一个有用的编辑器,无论是代码还是 Markdown 或介于两者之间的东西,给 medit 一个机会。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/20/12/medit
|
||||
|
||||
作者:[Seth Kenlon][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[geekpi](https://github.com/geekpi)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [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/coffee_tea_laptop_computer_work_desk.png?itok=D5yMx_Dr (Person drinking a hot drink at the computer)
|
||||
[2]: https://linux.cn/article-12930-1.html
|
||||
[3]: https://linux.cn/article-12933-1.html
|
||||
[4]: http://mooedit.sourceforge.net/
|
||||
[5]: https://sourceforge.net/projects/mooedit/files/medit/
|
||||
[6]: https://slackbuilds.org/repository/14.2/development/medit
|
||||
[7]: https://opensource.com/sites/default/files/uploads/medit-31_days_medit-opensource.png (Medit terminal showing examples of Bash script in editor)
|
||||
[8]: https://www.gap-system.org/
|
||||
[9]: https://opensource.com/sites/default/files/uploads/medit-tango-colour-31_days_medit-opensource.png (Medit terminal showing examples of Bash script in editor using Tango color scheme against dark background)
|
||||
[10]: https://opensource.com/article/20/12/kate-text-editor
|
@ -0,0 +1,68 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (geekpi)
|
||||
[#]: reviewer: (wxy)
|
||||
[#]: publisher: (wxy)
|
||||
[#]: url: (https://linux.cn/article-12942-1.html)
|
||||
[#]: subject: (Why Java developers love the jEdit text editor)
|
||||
[#]: via: (https://opensource.com/article/20/12/jedit)
|
||||
[#]: author: (Seth Kenlon https://opensource.com/users/seth)
|
||||
|
||||
为什么 Java 开发者喜欢 jEdit 文本编辑器
|
||||
======
|
||||
|
||||
> 这款编辑器打包了 Java 的功能,并提供了大量的插件来简化你的工作流程。
|
||||
|
||||
![](https://img.linux.net.cn/data/attachment/album/202012/22/133305j08dxrqx2fmp6s12.jpg)
|
||||
|
||||
Java 是一门强大的语言。也许因为它经常被看作是一种“工业级”的工具,你可能不会想到它会成为文本编辑器的基础。毕竟,对于如此能力,文本编辑几乎是太容易了。事实上,在大多数现代编程工具包中,接受文本输入的组件是一个预编程的小部件。使用 Java 工具箱,一个简单的文本编辑器可以用 100 行左右的代码编写出来。那么 [jEdit][2] 能提供什么来证明它的存在价值呢?
|
||||
|
||||
嗯,实际上,它有很多功能!jEdit 应用是一个令人耳目一新的提醒,提醒人们 Java 对于日常桌面应用是多么的实用和有用。它巧妙地展示了它的基础技术的活力,并且永远忠于 Java 的永恒承诺,在*所有*的平台上都能运作。
|
||||
|
||||
### 安装 jEdit
|
||||
|
||||
jEdit 是用 Java 编写的,所以它适用于任何平台。[下载][3]通用安装程序或为所选的操作系统下载自定义安装程序。下载完成后(它很小,因此不会花费很长时间),请运行安装程序。
|
||||
|
||||
如果你没有安装 Java,请学习如何在 [Linux][4]、[Mac 或 Windows][5] 上安装 Java。
|
||||
|
||||
### 使用 jEdit
|
||||
|
||||
在 jEdit 中编辑文本的方式和在任何桌面文本编辑器中编辑文本的方式是一样的。如果你使用过编辑器,那么你基本上已经会使用 jEdit 了。所有常用的键盘快捷键和惯例都适用。也有一些通常针对开发者的功能,如行号、折叠(该部分文本被隐藏,这样你就可以把注意力放在其他部分)和语法高亮。
|
||||
|
||||
但是,想象一下,从 [简单的 Vim][6] 到 [复杂的 Emacs][7]的各种文本编辑器中,你会发现 jEdit 与 Emacs 类似。虽然编辑组件和任何典型桌面编辑应用一样,但 jEdit 的附加功能包括插件、可以在编辑会话中实时录制的宏、特定于某些编辑模式的功能、缓冲区选项等。这是一个积极鼓励你把它变成你自己的编辑器。
|
||||
|
||||
你可以在三个地方对 jEdit 进行自定义:缓冲区选项、全局选项和插件管理器。
|
||||
|
||||
缓冲区选项(在 “Utilities” 菜单中)使你可以调整与当前文档关联的设置。通常,jEdit 会自动检测用于你正在执行的操作的适当模式。例如,编写 XML 会触发 jEdit 的 XML 高亮显示。但是,有时你想覆盖 jEdit 已检测到或未能检测到的内容。你还可以打开“显式折叠”模式,该模式允许你手动定义希望 jEdit 视为可折叠部分的文本。
|
||||
|
||||
全局选项(在 “Utilities” 菜单中)提供了数十种首选项,这些首选项被视为 jEdit 的默认值。这包括从外观到自定义快捷方式的所有内容。
|
||||
|
||||
插件可以扩展出来 jEdit 的开发者从未想过的功能。插件提供的工作方式对 jEdit 而言并非“常规”,但可能会将繁琐的任务转变为简单甚至有趣的事情。它以其出色的 XML 解析、可停靠的 Sidekick 面板中的 Outline 插件和 XSLT 集成,实际上改变了 XML 工作流程。如果我不是已经使用了 Netbeans 来编写 Java 代码,我想我可以使用 jEdit 来代替。
|
||||
|
||||
### 面向程序员的 jEdit
|
||||
|
||||
选择哪种文本编辑器取决于你打算在编辑器中做的事。它称自己为“程序员的文本编辑器”,并且我认为它是严肃的 Java 和 XML 开发的有力竞争者。但是,在编辑 Lua 代码和 Bash 脚本时,它的功能不就没有这么强了。例如,与 Emacs 之类相比,jEdit 的代码折叠不那么灵活(我无法在没有附加标记的情况下折叠 Lua 函数)。尽管确实有丰富的插件选择,但我找不到用于 AsciiDoc 和其他非代码格式工作的特别有说服力的东西。
|
||||
|
||||
对我来说,jEdit 最吸引人的特点是它是以 Java 为基础。因为它在 JVM 中运行,所以你可以确信能够使用它,而无论你使用的平台是什么,也可以不管你是否有权限在自己的主目录之外安装应用。Java 是一种流行且活跃的语言,因此 jEdit 的功能和插件维护得很好。
|
||||
|
||||
如果你是一致性的忠实拥护者、Java 开发人员,或者只是 XML 极客而拼命试图摆脱 oXygen,那么你应该试试 jEdit。它很容易上手,并且探索起来很有趣。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/20/12/jedit
|
||||
|
||||
作者:[Seth Kenlon][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[geekpi](https://github.com/geekpi)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [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/coffee_tea_laptop_computer_work_desk.png?itok=D5yMx_Dr (Person drinking a hot drink at the computer)
|
||||
[2]: http://jedit.org
|
||||
[3]: http://www.jedit.org/index.php?page=download
|
||||
[4]: https://linux.cn/article-11614-1.html
|
||||
[5]: http://adoptopenjdk.org
|
||||
[6]: https://opensource.com/article/20/12/vi-text-editor
|
||||
[7]: https://linux.cn/article-12923-1.html
|
@ -0,0 +1,73 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (geekpi)
|
||||
[#]: reviewer: (wxy)
|
||||
[#]: publisher: (wxy)
|
||||
[#]: url: (https://linux.cn/article-12952-1.html)
|
||||
[#]: subject: (What web developers love about the Brackets text editor)
|
||||
[#]: via: (https://opensource.com/article/20/12/brackets)
|
||||
[#]: author: (Seth Kenlon https://opensource.com/users/seth)
|
||||
|
||||
Web 开发人员喜欢 Brackets 文本编辑器的原因
|
||||
======
|
||||
|
||||
> 这个基础的编辑器是面向 Web 开发人员的,它支持多种编程语言,并提供了大量的扩展,使其成为你自己的编辑器。
|
||||
|
||||
![](https://img.linux.net.cn/data/attachment/album/202012/25/092259zy4xvxs4axmysuf9.jpg)
|
||||
|
||||
Brackets 文本编辑器是主要面向 Web 开发人员的编辑器。恰如其分的是,它的“编辑”菜单中充满了对 Web 编程语言用户特别有用的功能,主要是 HTML、CSS 和 Javascript 的经典组合。
|
||||
|
||||
但是,它还支持许多与互联网相关的语言和格式,包括 XML、Markdown、YAML 和 JSON、PHP、Lua、Java 和 Python,以及一些常见的通用语言,例如 C、C++,甚至是 `diff` 命令的输出。
|
||||
|
||||
### 安装 Brackets
|
||||
|
||||
Brackets 可以从 [Brackets 网站][2]安装到 Linux、Windows 和 macOS 上。
|
||||
|
||||
另外,在 Linux 上,你可以从 [flathub.org][3] 以 Flatpak 安装。
|
||||
|
||||
![Brackets editor][4]
|
||||
|
||||
### 使用 Brackets
|
||||
|
||||
在大多数时候,Brackets 是一个“普通”的文本编辑器,其功能类似于 [jEdit][5] 或 [Medit][6]。有语法高亮、可配置的制表符间距、字符编码设置等等。这些都可以在窗口底部的状态栏中找到。
|
||||
|
||||
在“视图”菜单中,有主题设置、行号、自动换行,甚至还有分割窗口的选项,这样你可以在一个窗口中看到两个文件。
|
||||
|
||||
然而,在“编辑”菜单中,有一些的特别用于编程的功能。以下是我最喜欢的一些功能:
|
||||
|
||||
* 使用 `Ctrl+[` 或 `Ctrl+]` 键盘快捷键来缩进和取消缩进文本块,这不仅对保持 HTML、CSS 和 Javascript 的整洁很有用,而且对 Python 代码也很重要。
|
||||
* 用 `Ctrl+/` 把一行变成注释。Brackets 标记注释的方式取决于你所使用的语言,所以无论你的文档是否使用斜线、破折号、箭头、井号或其他任何类型注释,这个功能都可以使用。
|
||||
* 用 `Shift+Ctrl+Up` 或 `Shift+Ctrl+Down` 在文档中将一行向上或向下移动。
|
||||
* 用 `Shift+Ctrl+D` 删除整个一行。
|
||||
* 用 `Ctrl+D` 复制整个一行。
|
||||
|
||||
这些都是看似小众的功能,你可能认为不会经常使用,但一旦你拥有了它们,你就会对它们产生依赖。
|
||||
|
||||
### 扩展
|
||||
|
||||
Brackets 还可以接受扩展,因此你和其他编码者可以添加扩展到功能中。要查看有哪些可用的扩展,请单击“文件”菜单并选择“扩展管理器”。有各种各样的扩展,包括用于调整代码格式的 Beautify、用于其他语言的多个支持包、用于转到标签开头或结尾的功能等等。
|
||||
|
||||
无论编辑器是否适合你,扩展可以使一个编辑器变得不同,所以如果你尝试 Brackets 并享受它的一切,但缺少一些重要的功能,在你放弃它之前,请浏览一下可用的扩展。
|
||||
|
||||
### 尝试 Brackets
|
||||
|
||||
Brackets 是一个有点低调的编辑器。虽然它宣传自己是 “Web 代码编辑器”,但实际上它是一个不错的通用编辑器,并为常见的 Web 工具链加入了一些额外的功能。如果你喜欢 Brackets 的外观和它所提供的功能,不妨一试!
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/20/12/brackets
|
||||
|
||||
作者:[Seth Kenlon][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[geekpi](https://github.com/geekpi)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [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/browser_blue_text_editor_web.png?itok=lcf-m6N7 (Text editor on a browser, in blue)
|
||||
[2]: http://brackets.io/
|
||||
[3]: https://flathub.org/apps/details/io.brackets.Brackets
|
||||
[4]: https://opensource.com/sites/default/files/screenshot_2020-12-02_at_16.26.58.png (Brackets editor)
|
||||
[5]: https://linux.cn/article-12942-1.html
|
||||
[6]: https://linux.cn/article-12938-1.html
|
@ -0,0 +1,167 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (wxy)
|
||||
[#]: reviewer: (wxy)
|
||||
[#]: publisher: (wxy)
|
||||
[#]: url: (https://linux.cn/article-12959-1.html)
|
||||
[#]: subject: (9 things to do in your first 10 minutes on a Linux server)
|
||||
[#]: via: (https://opensource.com/article/20/12/linux-server)
|
||||
[#]: author: (Gaurav Kamathe https://opensource.com/users/gkamathe)
|
||||
|
||||
初次登录 Linux 服务器马上要做的 9 件事
|
||||
======
|
||||
|
||||
> 在将新配置的服务器投入工作之前,请确保你知道你正在使用什么。
|
||||
|
||||
![](https://img.linux.net.cn/data/attachment/album/202012/27/112042zuz1lpudkypeppeu.jpg)
|
||||
|
||||
当我在 Linux 上测试软件时(这是我工作中的一个常规部分),我需要使用多台运行 Linux 的不同架构的服务器。我整备机器,安装所需的软件包,运行我的测试,收集结果,并将机器返回到仓库中,以便其他人可以使用它进行测试。
|
||||
|
||||
由于我经常这样做(甚至一天多次),我初次登录 Linux 服务器的前 10 分钟内的工作已经成为每天的仪式。当我初次登录 Linux 服务器时,我会使用命令来收集我需要的信息来寻找某些东西。我将在本文中介绍我的过程,但请注意,在大多数情况下,我只给出命令名称,所以你需要确定这些命令的具体选项,以获得你需要的信息。阅读命令的手册页是一个很好的起点。
|
||||
|
||||
### 1、第一次接触
|
||||
|
||||
当我登录到一台服务器时,我做的第一件事就是检查它是否拥有我将要运行的测试所需的操作系统、内核和硬件架构。我经常会检查一台服务器已经运行了多久。虽然这对测试系统来说并不重要,因为它会被多次重启,但我还是发现这些信息很有帮助。
|
||||
|
||||
使用下面的命令来获取这些信息。我主要使用 Red Hat Linux 进行测试,所以如果你使用其他 Linux 发行版,请在文件名中使用 `*-release` 而不是 `redhat-release`:
|
||||
|
||||
```
|
||||
cat /etc/redhat-release
|
||||
uname -a
|
||||
hostnamectl
|
||||
uptime
|
||||
```
|
||||
|
||||
### 2、有人登录在上面吗?
|
||||
|
||||
一旦我知道这台机器符合我的测试需求,我需要确保没有其他人同时登录该系统运行他们自己的测试。虽然考虑到整备系统会帮我处理好这个问题,这种可能性很小,但偶尔检查一下还是有好处的 —— 尤其是当我第一次登录服务器的时候。我还会检查是否有其他用户(除了 root)可以访问系统。
|
||||
|
||||
使用下面的命令来查找这些信息。最后一条命令是查找 `/etc/passwd` 文件中具有 shell 访问权限的用户;它会跳过文件中没有 shell 访问权限或 shell 设置为 `nologin` 的其他服务:
|
||||
|
||||
```
|
||||
who
|
||||
who -Hu
|
||||
grep sh$ /etc/passwd
|
||||
```
|
||||
|
||||
### 3、物理机还是虚拟机
|
||||
|
||||
现在我有了属于自己的机器,我需要确定它是一台物理机还是一台虚拟机(VM)。如果是我自己整备的这台机器,我可以确定这是我要求的东西。但是,如果你使用的是一台不是你自己整备的机器,你应该检查该机器是物理机还是虚拟机。
|
||||
|
||||
使用以下命令来识别这些信息。如果是物理系统,你会看到供应商的名称(如 HP、IBM 等)以及服务器的品牌和型号;而在虚拟机中,你应该看到 KVM、VirtualBox 等,这取决于创建虚拟机时使用了什么虚拟化软件:
|
||||
|
||||
```
|
||||
dmidecode -s system-manufacturer
|
||||
dmidecode -s system-product-name
|
||||
lshw -c system | grep product | head -1
|
||||
cat /sys/class/dmi/id/product_name
|
||||
cat /sys/class/dmi/id/sys_vendor
|
||||
```
|
||||
|
||||
### 4、硬件
|
||||
|
||||
因为我经常测试连接到 Linux 机器的硬件,所以我通常使用物理服务器,而不是虚拟机。在物理机器上,我的下一步是确定服务器的硬件能力 —— 例如,运行的是什么类型的 CPU,它有多少个核心,启用了哪些标志,以及有多少内存可用于运行测试。如果我正在运行网络测试,我会检查连接到服务器的以太网或其他网络设备的类型和容量。
|
||||
|
||||
使用以下命令来显示连接到 Linux 服务器的硬件。其中一些命令在新的操作系统版本中可能会被废弃,但你仍然可以从 yum 存储库中安装它们或切换到它们的等效新命令:
|
||||
|
||||
```
|
||||
lscpu or cat /proc/cpuinfo
|
||||
lsmem or cat /proc/meminfo
|
||||
ifconfig -a
|
||||
ethtool <devname>
|
||||
lshw
|
||||
lspci
|
||||
dmidecode
|
||||
```
|
||||
|
||||
### 5、已安装的软件
|
||||
|
||||
测试软件总是需要安装额外的依赖包、库等。然而,在安装任何东西之前,我都会检查已经安装了什么(包括是什么版本),以及配置了哪些存储库,这样我就知道软件来自哪里,并可以调试任何软件包安装问题。
|
||||
|
||||
使用下面的命令来确定安装了什么软件:
|
||||
|
||||
```
|
||||
rpm -qa
|
||||
rpm -qa | grep <pkgname>
|
||||
rpm -qi <pkgname>
|
||||
yum repolist
|
||||
yum repoinfo
|
||||
yum install <pkgname>
|
||||
ls -l /etc/yum.repos.d/
|
||||
```
|
||||
|
||||
### 6、运行的进程和服务
|
||||
|
||||
检查了安装的软件之后,自然就会检查系统上有哪些进程在运行。当在系统上运行性能测试时,这一点至关重要 —— 如果一个正在运行的进程、守护进程、测试软件等占用了大部分 CPU/RAM,那么在运行测试之前停止该进程是有意义的。这也可以检查测试所需的进程或守护进程是否已经启动并运行。例如,如果测试需要 `httpd` 运行,那么即使安装了软件包,启动守护进程的服务也可能没有运行。
|
||||
|
||||
使用以下命令来识别系统上正在运行的进程和已启用的服务:
|
||||
|
||||
```
|
||||
pstree -pa 1
|
||||
ps -ef
|
||||
ps auxf
|
||||
systemctl
|
||||
```
|
||||
|
||||
### 7、网络连接
|
||||
|
||||
如今的机器网络化程度很高,它们需要与网络上的其他机器或服务进行通信。我会识别服务器上哪些端口是开放的,是否有到测试机器的任何网络连接,是否启用了防火墙,如果启用了,是否屏蔽了任何端口,以及机器与哪些 DNS 服务器对话。
|
||||
|
||||
使用以下命令来识别网络服务相关信息。如果一个过时的命令不可用,请从 yum 存储库中安装它或使用等效的新命令:
|
||||
|
||||
```
|
||||
netstat -tulpn
|
||||
netstat -anp
|
||||
lsof -i
|
||||
ss
|
||||
iptables -L -n
|
||||
cat /etc/resolv.conf
|
||||
```
|
||||
|
||||
### 8、内核
|
||||
|
||||
在进行系统测试时,我发现了解内核相关的信息是很有帮助的,比如内核版本和加载了哪些内核模块。我还会列出任何[可调整的内核参数][2]以及它们的设置,并检查启动运行中的内核时使用的选项。
|
||||
|
||||
使用以下命令来识别这些信息:
|
||||
|
||||
```
|
||||
uname -r
|
||||
cat /proc/cmdline
|
||||
lsmod
|
||||
modinfo <module>
|
||||
sysctl -a
|
||||
cat /boot/grub2/grub.cfg
|
||||
```
|
||||
|
||||
### 9、日志
|
||||
|
||||
现在,我已经对服务器有了很好的了解,包括安装了哪些软件,运行了哪些进程。还有一件事我无法逃避,那就是日志文件 —— 我需要知道在哪里可以查看不断更新的信息。
|
||||
|
||||
使用以下命令查看系统的日志:
|
||||
|
||||
```
|
||||
dmesg
|
||||
tail -f /var/log/messages
|
||||
journalctl
|
||||
```
|
||||
|
||||
### 接下来的步骤
|
||||
|
||||
虽然命令和实用程序会发生变化,但它们所显示的基本信息大致不变。在你专注于掌握哪些命令之前,你需要对你要寻找的信息以及它属于什么类别有一个宏观的看法。
|
||||
|
||||
由于 Linux 将大部分信息保存在文件中,这些命令基本上是从文件中读取信息,并以一种易于理解的方式呈现出来。下一步的好做法是找出每个命令用来获取信息显示的文件。一个提示:寻找这些信息的方法是 `strace` 命令。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/20/12/linux-server
|
||||
|
||||
作者:[Gaurav Kamathe][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[wxy](https://github.com/wxy)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/gkamathe
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/containers_modules_networking_hardware_parts.png?itok=rPpVj92- (Parts, modules, containers for software)
|
||||
[2]: https://www.oreilly.com/library/view/red-hat-enterprise/9781785283550/ch10s05.html
|
@ -0,0 +1,168 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (wxy)
|
||||
[#]: reviewer: (wxy)
|
||||
[#]: publisher: (wxy)
|
||||
[#]: url: (https://linux.cn/article-12921-1.html)
|
||||
[#]: subject: (Here are the Worthy Replacements of CentOS 8 for Your Production Linux Servers)
|
||||
[#]: via: (https://itsfoss.com/rhel-based-server-distributions/)
|
||||
[#]: author: (Abhishek Prakash https://itsfoss.com/author/abhishek/)
|
||||
|
||||
什么 Linux 系统可以替换生产环境的 Linux 服务器上的 CentOS 8
|
||||
======
|
||||
|
||||
CentOS 是世界上最流行的服务器发行版之一。它是<ruby>红帽企业 Linux<rt>Red Hat Enterprise Linux</rt></ruby>(RHEL)的一个开源分支,提供了 RHEL 的优点,却没有 RHEL 的相关成本。
|
||||
|
||||
然而,最近情况发生了变化,[红帽正在将稳定的 CentOS 转换为滚动发布模式,即 CentOS Stream的形式][1]。CentOS 8 本来应该支持到 2029 年,但现在到 2021 年底就被迫停止了。
|
||||
|
||||
如果你的服务器使用的是 CentOS,这可能会让你不知道该何去何从。
|
||||
|
||||
你看,取代 CentOS 8 的首要选择就是 CentOS Stream。将 CentOS 8 升级到 CentOS Stream 的[过程很简单][2],你不用担心需要重新安装任何东西。
|
||||
|
||||
不过,由于 CentOS Stream 是滚动发布性质的,你可能要考虑一些对生产服务器来说更稳定的东西。我将在本文中会推荐一些 Linux 系统来帮助你做出这个决定。
|
||||
|
||||
### 基于 RHEL 的服务器 Linux 发行版,你可以考虑用来取代 CentOS
|
||||
|
||||
![][3]
|
||||
|
||||
我将从一些正在开发的 RHEL 分支版本开始列举,其唯一目的是取代 CentOS 8。之后,我会列出你可以马上使用的服务器发行版。
|
||||
|
||||
#### Rocky Linux(正在开发中)
|
||||
|
||||
![][4]
|
||||
|
||||
就在红帽宣布计划用滚动发布的 CentOS Stream 取代稳定的 CentOS 8 的同一天,CentOS 的原开发者宣布了一个新项目,为 CentOS 用户提供 RHEL 分支。
|
||||
|
||||
这个新项目名为 [Rocky Linux][5]。它的名字是为了纪念原 CentOS 项目的共同创始人之一。它是从 RHEL 8 分支出来的,目标是“100% 与 RHEL 兼容”。
|
||||
|
||||
该项目正在快速开发中,目前可能无法使用。但这是在 2021 年底 CentOS 8 支持结束时取代它的首选之一。
|
||||
|
||||
#### Lenix 项目(开发中)
|
||||
|
||||
![][6]
|
||||
|
||||
这是在宣布 CentOS Stream 成为默认版本一天后创建的又一个 RHEL 分支。
|
||||
|
||||
[Lenix 项目][7]是由 CloudLinux 创建的,CloudLinux 是一家面向企业的服务机构,多年来一直在提供定制化的 CentOS 服务器,鉴于他们在 CentOS 和企业服务器方面的多年经验,Lenix 项目应该是一个很有前途的 RHEL 分支,可以取代 CentOS Stream。
|
||||
|
||||
#### Oracle Linux
|
||||
|
||||
![][8]
|
||||
|
||||
这可能是该列表中唯一能以最佳方式使用的 RHEL 分支。不仅可以随时使用,你甚至可以[从现有的 CentOS 安装迁移到 Oracle Linux][9],而无需重新安装。
|
||||
|
||||
Oracle Linux 自 2006 年起推出。它的应用二进制 100% 兼容 RHEL,并且它提供了与每个 RHEL 版本相对应的版本。而且,你不需要与 Oracle 签署任何协议来使用 Oracle Linux。
|
||||
|
||||
Oracle Linux 有两种 Linux 内核可供选择:Oracle Linux 的<ruby>[坚不可摧企业级内核][10]<rt>Unbreakable Enterprise Kernel</rt></ruby>(UEK)或<ruby>红帽兼容内核<rt> Red Hat Compatible Kernel</rt></ruby>(RHCK)。
|
||||
|
||||
只是,甲骨文在开源项目上有些黑历史,可能这也是为什么选择 CentOS 这种真正的社区分支形式而不是甲骨文 Linux 的原因。随着 CentOS 被 CentOS Stream 所取代,也许现在正是给 Oracle 一个机会的时候?
|
||||
|
||||
#### ClearOS(来自惠普)
|
||||
|
||||
![][11]
|
||||
|
||||
[ClearOS][12] 是惠普在其 HPE ProLiant 服务器上提供的。虽然他们的网站上没有明确提到,但 ClearOS 是基于 RHEL 和 CentOS 的。
|
||||
|
||||
[Clear Center][13] 和 HPE 在这个项目上进行了合作。开源的 ClearOS 免费提供给社区。他们有自己的应用市场,混杂了免费和付费应用。你不需要为操作系统付费,但如果你选择了付费应用,你可能需要为该应用付费。
|
||||
|
||||
它可能没有那么流行,但随着 CentOS Stream 成为默认,如果惠普能抓住这个时机,ClearOS 应该能获得一些用户。他们会这么做吗?我不太确定。甲骨文正在努力吸引 CentOS 用户,但我没有看到惠普的这种努力。
|
||||
|
||||
#### Springdale Linux(普林斯顿大学的学术项目)
|
||||
|
||||
![][14]
|
||||
|
||||
一个由院士维护的红帽分支?这就是 Scientific Linux 吧?但 Scientific Linux 已经死了一年多了。
|
||||
|
||||
[Springdale Linux][15](SDL)是普林斯顿大学的另一个这样的项目。它之前被称为 PUIAS Linux(<ruby>普林斯顿大学高级研究所<rt>Princeton University Institute for Advanced Study</rt></ruby>)。
|
||||
|
||||
目前还没有 RHEL 8 对应的 Springdale Linux,我觉得他们的开发速度可以加快一些。
|
||||
|
||||
### 不基于红帽的服务器发行版
|
||||
|
||||
好吧,到目前为止,列表中已经提到了基于红帽的发行版。现在是时候看看一些与 RHEL 无关,但仍然是生产服务器的上好选择的服务器发行版了。
|
||||
|
||||
#### YunoHost(专门为 Web 服务器定制的)
|
||||
|
||||
![][16]
|
||||
|
||||
[YunoHost][17] 是基于 Debian 定制的,目的是为你提供一个托管 Web 服务器的系统。
|
||||
|
||||
你可以在[树莓派等 ARM 板][18]、旧台式机和计算机上使用它,当然也可以在虚拟专用服务器(VPS)上使用。
|
||||
|
||||
YunoHost 还提供了一个基于 Web 的管理界面(灵感来自于 [Webmin][19]?),这样你就可以用图形化的方式来管理系统。这对于一个想托管 Web 服务器但又不太会命令行的人来说,是一个很大的安慰。
|
||||
|
||||
#### Debian Linux
|
||||
|
||||
![][20]
|
||||
|
||||
这个通用操作系统提供了一个坚如磐石的服务器发行版。对于那些想要一个稳定系统的人来说,是一个理想的选择。
|
||||
|
||||
如果你在 CentOS 上投入了太多的时间和技术,你可能会发现 [Debian][21] 略有不同,尤其是软件包管理系统。不过,我相信,对于一个经验丰富的 Linux 系统管理员来说,这应该不是什么大问题。
|
||||
|
||||
#### openSUSE
|
||||
|
||||
![][22]
|
||||
|
||||
SUSE 是红帽的直接竞争对手之一。他们以 [SUSE Linux Enterprise][23] 的形式提供企业级产品。他们的开源产品 openSUSE 也相当受欢迎,无论是在桌面还是服务器领域。
|
||||
|
||||
[openSUSE][24] 是一个服务器 Linux 发行版的好选择。现在的人不会明白 [SUSE 的 YAST 工具][25]在上世纪 90 年代和 2000 年初给用户带来了怎样的解脱。它仍然是管理 SUSE 系统的一个方便的工具。
|
||||
|
||||
openSUSE 有两种形式:滚动发布的 Tumbleweed 和稳定的点发布版的 Leap。我猜测你追求的是稳定性,所以 Leap 是你应该追求的目标。
|
||||
|
||||
#### Ubuntu
|
||||
|
||||
![][26]
|
||||
|
||||
[Ubuntu][27] 是世界上最流行的发行版,[在服务器上][28]和台式机上都是如此。这就是为什么没有 Ubuntu 这份清单就不完整的原因。
|
||||
|
||||
因为我已经使用 Ubuntu 很长时间了,所以我觉得在 Ubuntu 上托管我的 Web 服务器很舒服。但这只是我个人的想法。如果你是从 RHEL 领域过来的,这里的包管理系统和一些网络和管理组件是不同的。
|
||||
|
||||
[Ubuntu LTS 版][29]带有五年的支持,这是 CentOS 版本提供的一半长短。如果你不想升级版本,你可以选择为过时的 LTS 版本购买付费的扩展支持。
|
||||
|
||||
#### 你的选择是什么?
|
||||
|
||||
我已经列出了一些基于 RHEL 的发行版以及通用服务器发行版的顶级推荐。
|
||||
|
||||
现在轮到你了,在上面列出的发行版中,你最喜欢哪个?你有什么其他的建议可以添加到这个列表中吗?请在评论区留言。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://itsfoss.com/rhel-based-server-distributions/
|
||||
|
||||
作者:[Abhishek Prakash][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[wxy](https://github.com/wxy)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://itsfoss.com/author/abhishek/
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://linux.cn/article-12902-1.html
|
||||
[2]: https://linuxhandbook.com/update-to-centos-stream/
|
||||
[3]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2020/12/Replace-centos.png?resize=800%2C450&ssl=1
|
||||
[4]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2020/12/rocky-linux.png?resize=800%2C350&ssl=1
|
||||
[5]: https://rockylinux.org
|
||||
[6]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2020/12/cloudlinux.png?resize=800%2C350&ssl=1
|
||||
[7]: https://www.reddit.com/r/ProjectLenix/
|
||||
[8]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2020/12/oracle-linux.png?resize=800%2C350&ssl=1
|
||||
[9]: https://github.com/oracle/centos2ol
|
||||
[10]: https://docs.oracle.com/en/operating-systems/uek/
|
||||
[11]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2020/12/clear-os.jpg?resize=795%2C349&ssl=1
|
||||
[12]: https://www.clearos.com
|
||||
[13]: https://www.clearcenter.com
|
||||
[14]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2020/12/springdale-linux.png?resize=800%2C350&ssl=1
|
||||
[15]: https://puias.math.ias.edu
|
||||
[16]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2020/12/yunohost.png?resize=720%2C400&ssl=1
|
||||
[17]: https://yunohost.org#/
|
||||
[18]: https://itsfoss.com/raspberry-pi-alternatives/
|
||||
[19]: https://linuxhandbook.com/use-webmin/
|
||||
[20]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2020/12/debian-linux.png?resize=800%2C350&ssl=1
|
||||
[21]: https://www.debian.org
|
||||
[22]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2020/12/opensuse.jpg?resize=800%2C350&ssl=1
|
||||
[23]: https://www.suse.com/download/sles/
|
||||
[24]: https://www.opensuse.org
|
||||
[25]: https://yast.opensuse.org
|
||||
[26]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2020/12/ubuntu.jpg?resize=800%2C350&ssl=1
|
||||
[27]: https://ubuntu.com/download/server
|
||||
[28]: https://www.datanyze.com/market-share/operating-systems--443/ubuntu-market-share
|
||||
[29]: https://itsfoss.com/long-term-support-lts/
|
169
published/20201216 How to View Images from the Linux Terminal.md
Normal file
169
published/20201216 How to View Images from the Linux Terminal.md
Normal file
@ -0,0 +1,169 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (geekpi)
|
||||
[#]: reviewer: (wxy)
|
||||
[#]: publisher: (wxy)
|
||||
[#]: url: (https://linux.cn/article-12948-1.html)
|
||||
[#]: subject: (How to View Images from the Linux Terminal)
|
||||
[#]: via: (https://www.2daygeek.com/how-to-view-display-images-from-linux-terminal/)
|
||||
[#]: author: (Magesh Maruthamuthu https://www.2daygeek.com/author/magesh/)
|
||||
|
||||
如何在 Linux 终端查看图像
|
||||
======
|
||||
|
||||
![](https://img.linux.net.cn/data/attachment/album/202012/23/233513zcgmggmxfd0wf9g1.png)
|
||||
|
||||
Linux 有很多用于查看图像的 GUI 应用。但我从来没有尝试过用任何命令行应用来查看它。
|
||||
|
||||
幸运的是,在使用 [ImageMagick 工具][1]时,我得到了一个从终端查看图像的命令。命令名是 `“display`,它是 ImageMagick 工具的一部分。这是一个很好的工具,允许类 UNIX 用户从终端查看图像。
|
||||
|
||||
此外,我还为此用途得到了另一个很好的工具,叫做 FIM。
|
||||
|
||||
我们将向你展示如何安装并使用它从 Linux 终端查看图像。这些命令使用系统的<ruby>帧缓冲<rt>framebuffer</rt></ruby>直接从命令行显示图像。
|
||||
|
||||
### 如何使用 display 命令从终端查看图像
|
||||
|
||||
[ImageMagick][2] 是一个自由开源、功能丰富、基于命令行的图像处理工具。它用于创建、编辑、合成或转换位图图像。它可以读取和写入各种格式(超过 200 种)的图像,包括 PNG、JPEG、GIF、PDF、SVG 等。它可以调整图像的大小、镜像、旋转、转换图像、调整图像颜色、应用各种特殊效果等。它支持批处理,允许你一次处理所有图像。
|
||||
|
||||
### 如何安装 ImageMagick?
|
||||
|
||||
ImageMagick 软件包包含在大多数 Linux 发行版的官方仓库中。使用发行版软件包管理器来安装它。
|
||||
|
||||
**需要注意的是:**确保你的 Linux 系统上已经安装了 “[Development Tools][3]” 包,这是安装的前提条件。
|
||||
|
||||
对于 RHEL/CentOS 6/7 系统,请使用 [yum 命令][4] 安装 ImageMagick:
|
||||
|
||||
```
|
||||
$ sudo yum install -y ImageMagick ImageMagick-devel
|
||||
```
|
||||
|
||||
在 RHEL/CentOS 8 和 Fedora 系统,使用 [dnf 命令][5] 安装 ImageMagick:
|
||||
|
||||
```
|
||||
$ sudo dnf install -y ImageMagick ImageMagick-devel
|
||||
```
|
||||
|
||||
对于 Debian/Ubuntu 系统,使用 [apt 命令][6] 或 [apt-get 命令][7] 安装 ImageMagick:
|
||||
|
||||
```
|
||||
$ sudo apt-get update
|
||||
$ sudo apt-get install imagemagick
|
||||
```
|
||||
|
||||
对于 openSUSE 系统,使用 [zypper 命令][8] 安装 ImageMagick:
|
||||
|
||||
```
|
||||
$ sudo zypper install -y ImageMagick
|
||||
```
|
||||
|
||||
要查看任何图像文件,请运行 `display` 命令,如下所示。你可以按下 `Esc`/`q` 按钮关闭图像:
|
||||
|
||||
```
|
||||
$ display bird.jpg
|
||||
```
|
||||
|
||||
![](https://www.2daygeek.com/wp-content/uploads/2020/12/how-to-view-display-images-from-linux-terminal-2.jpg)
|
||||
|
||||
如果你想用指定的窗口大小打开图像,请使用 `-geometry` 标志:
|
||||
|
||||
```
|
||||
$ display -geometry 1000x600 ~/Downloads/bird.jpg
|
||||
```
|
||||
|
||||
你也可以通过 `display` 命令输入图像的位置信息。下面的命令可以从桌面的距顶部 800 像素和据左上角 800 像素处打开图像:
|
||||
|
||||
```
|
||||
$ display -geometry 1000x600+800+800 ~/Downloads/bird.jpg
|
||||
```
|
||||
|
||||
如果你想用 `display` 命令调整图像的大小,请使用以下格式:
|
||||
|
||||
```
|
||||
$ display -resize 600x400 ~/Downloads/bird.jp
|
||||
```
|
||||
|
||||
另外,你也可以使用百分比来调整图片的大小:
|
||||
|
||||
```
|
||||
$ display -resize 50% ~/Downloads/bird.jpg
|
||||
```
|
||||
|
||||
### 如何使用 fim 命令从终端查看图像
|
||||
|
||||
[FIM][10] 是一个专门为 Linux 设计的轻量级全局图像查看器。但它并不局限于 Linux,它也可配置在其他操作系统上运行,如 MS-Windows。
|
||||
|
||||
对于熟悉 VIM 文本编辑器等软件的用户来说,它是高度可定制和可脚本化的图像查看器。它可以全屏显示图像,并且可以使用键盘快捷键轻松控制。它是一款非常轻量级的工具,因为它只依赖于某些库。
|
||||
|
||||
它可以打开许多文件格式,它可以在以下视频模式下显示图像:
|
||||
|
||||
* 使用 Linux 帧缓冲设备图形化。
|
||||
* 在 X/Xorg 下,使用 SDL 库图形化
|
||||
* 在 X/Xorg 下,使用 Imlib2 库图形化。
|
||||
* 使用 AAlib 库,在任意文本控制台中以 ASCII 艺术形式呈现。
|
||||
|
||||
运行时自动检测或选择正确的视频模式,如果需要,可以在构建前配置时选择加入或去除。
|
||||
|
||||
FIM 是 “Fbi IMproved” 的缩写,是 Fbi Image Viewer 的复刻版本。
|
||||
|
||||
FIM 可以很容易地安装在基于 Debian/Ubuntu 的系统上,因为该软件包在发行版的官方仓库中是可用的。对于其他发行版,你可能需要从源码编译它:
|
||||
|
||||
```
|
||||
$ sudo apt install fim
|
||||
```
|
||||
|
||||
安装完毕后,你可以使用以下命令显示图像:
|
||||
|
||||
```
|
||||
$ fim bird.jpg
|
||||
```
|
||||
|
||||
你可以使用 `-a` 选项自动缩放图像:
|
||||
|
||||
```
|
||||
$ fim -a bird.jpg
|
||||
```
|
||||
|
||||
![](https://www.2daygeek.com/wp-content/uploads/2020/12/how-to-view-display-images-from-linux-terminal-3.jpg)
|
||||
|
||||
如果你要打开当前目录中的多个图像文件,请使用通配符将它们全部打开。使用 `PageUp`/`PageDown` 键盘快捷键移动到下一张或上一张图像:
|
||||
|
||||
```
|
||||
$ fim -a *.jpg
|
||||
```
|
||||
|
||||
要以 ASCII 格式查看图像,可以使用 `-t` 标志:
|
||||
|
||||
```
|
||||
$ fim -t bird.jpg
|
||||
```
|
||||
|
||||
下面的键盘快捷键可以让你控制图像:
|
||||
|
||||
* `PageUp`/`PageDown`:上一张/下一张图片。
|
||||
* `+`/`-`:放大/缩小
|
||||
* `a`:自动缩放
|
||||
* `w`:适应宽度
|
||||
* `ESC`/`q`:退出
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.2daygeek.com/how-to-view-display-images-from-linux-terminal/
|
||||
|
||||
作者:[Magesh Maruthamuthu][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[geekpi](https://github.com/geekpi)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [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/resize-convert-images-from-linux-command-line/
|
||||
[2]: https://imagemagick.org/
|
||||
[3]: https://www.2daygeek.com/install-development-tools-on-ubuntu-debian-arch-linux-mint-fedora-centos-rhel-opensuse/
|
||||
[4]: https://www.2daygeek.com/linux-yum-command-examples-manage-packages-rhel-centos-systems/
|
||||
[5]: https://www.2daygeek.com/linux-dnf-command-examples-manage-packages-fedora-centos-rhel-systems/
|
||||
[6]: https://www.2daygeek.com/apt-command-examples-manage-packages-debian-ubuntu-systems/
|
||||
[7]: https://www.2daygeek.com/apt-get-apt-cache-command-examples-manage-packages-debian-ubuntu-systems/
|
||||
[8]: https://www.2daygeek.com/zypper-command-examples-manage-packages-opensuse-system/
|
||||
[9]: data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7
|
||||
[10]: https://www.nongnu.org/fbi-improved/#docs
|
@ -0,0 +1,108 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (geekpi)
|
||||
[#]: reviewer: (wxy)
|
||||
[#]: publisher: (wxy)
|
||||
[#]: url: (https://linux.cn/article-12955-1.html)
|
||||
[#]: subject: (Why Vim users will love the Kakoune text editor)
|
||||
[#]: via: (https://opensource.com/article/20/12/kakoune)
|
||||
[#]: author: (Seth Kenlon https://opensource.com/users/seth)
|
||||
|
||||
为什么 Vim 用户会喜欢 Kakoune 文本编辑器?
|
||||
======
|
||||
|
||||
> 这个编辑器可能会让人联想到 Vim,但它也提供了很多自己独特的功能和特性。
|
||||
|
||||
![](https://img.linux.net.cn/data/attachment/album/202012/25/233039wpnwnwakzn1zwa33.jpg)
|
||||
|
||||
[Kakoune][2] 文本编辑器的灵感来源于 Vi。它拥有简约的界面、简短的键盘快捷键以及独立的编辑和插入模式,乍一看确实[看起来和感觉很像 Vi][3]。然而,Kakoune 编辑器在设计和功能上都有自己独特的风格,与其说是另一个 Vim,不如说是它是它自己。
|
||||
|
||||
### 安装
|
||||
|
||||
在 Linux 和 BSD 上,你可以从你的发行版的软件仓库或 port 树上安装 Kakoune。例如,在 Fedora、CentOS 或 RHEL 上:
|
||||
|
||||
```
|
||||
$ sudo dnf install kakoune
|
||||
```
|
||||
|
||||
在 Debian、Ubuntu 或类似的系统上:
|
||||
|
||||
```
|
||||
$ sudo apt install kakoune
|
||||
```
|
||||
|
||||
在 macOS 上,你可以使用 Homebrew:
|
||||
|
||||
```
|
||||
$ brew install kakoune
|
||||
```
|
||||
|
||||
或者,你也可以[从源码构建][4]。
|
||||
|
||||
启动 Kakoune 的命令是 `kak`。你可以启动 Kakoune 打开空文件,也可以在启动时包含文件名让它打开:
|
||||
|
||||
```
|
||||
$ kak example.txt
|
||||
```
|
||||
|
||||
### 使用 Kakoune
|
||||
|
||||
当你启动 Kakoune(不带文件名)时,除了在窗口底部有一个小的状态栏外,它在你的终端中打开的大部分是空的缓冲区。像 Vim 一样,Kakoune 以“正常”模式启动,它把按键作为命令,不向缓冲区输入文本。要进入*插入模式*,你必须按 `i`(代表<ruby>插入<rt>Insert</rt></ruby>)或 `a`(代表<ruby>追加<rt>Append</rt></ruby>)。
|
||||
|
||||
在插入模式下,Kakoune 的操作和其他编辑器一样。你在键盘上输入,然后你输入的字符就会显示在缓冲区里。在插入模式下,你可以使用方向键来浏览缓冲区。
|
||||
|
||||
### 正常模式
|
||||
|
||||
在正常模式下,你可以发出导航和文本编辑命令。这是从 Vi 传统中借用的最明显的功能。编辑命令包括复制、剪切(在传统的 Unix 编辑术语中,称为 “<ruby>猛拉<rt>yank</rt></ruby>”)、粘贴单词和行、撤销、转换字符大小写等功能。下面是一些基础:
|
||||
|
||||
* `d`:复制并删除当前选择(现代术语中的“剪切”)
|
||||
* `c`:复制并删除当前选择,并进入插入模式
|
||||
* `Esc+Alt+d`:删除当前选择
|
||||
* `y`:复制选择
|
||||
* `p`:粘贴
|
||||
* `<`:取消所选行的缩进
|
||||
* `u`:撤消
|
||||
* `U`:重做
|
||||
* `:转为小写
|
||||
* `~`:转换为大写
|
||||
|
||||
### 选择
|
||||
|
||||
在 Kakoune 中,你的光标是一个单字符的移动选区。除非你扩展你的选区,否则任何影响选区的命令都只适用当前光标位置。例如,如果你的光标悬停在字母 `n` 上,那么复制命令(正常模式下的 `c`)会将字母 `n` 复制到剪贴板,而粘贴命令(正常模式下的 `p`)则会将字母 `n` 粘贴到缓冲区。
|
||||
|
||||
从单个字符扩展选区的最简单方法是进入正常模式,按下 `Shift` 键,同时用方向键移动光标。然而,有几种方法可以根据某些标准来扩展选区。例如,`Alt+l` 将选区从光标扩展到当前行的末端。
|
||||
|
||||
完整的文档可以在 <https://github.com/mawww/kakoune/blob/master/README.asciidoc> 中找到。
|
||||
|
||||
### 函数
|
||||
|
||||
除了这些基本的交互,你还可以执行命令来调用 Kakoune 的内置功能。要访问 Kakoune 的命令行,在普通模式下输入 `:`。在命令行中,你可以执行命令,包括打开文件的 `edit` 命令,保存缓冲区到文件的 `write` 命令,当然还有退出应用的 `quit`。
|
||||
|
||||
还有更多的函数,包括针对特定编程语言和文件格式的特殊选项、使用 [Ranger 文件浏览器][5]浏览文件系统的选项、改变颜色主题、搜索和替换文本等等。
|
||||
|
||||
![Kakoune][6]
|
||||
|
||||
### 尝试 Kakoune
|
||||
|
||||
如果你是一个有经验的 Vim 用户,或者甚至是一个只是略知一二的人,你可能会发现 Kakoune 一开始会让你感到迷惑。它与 Vim 的相似度足以让你陷入一种虚假的熟悉感。一切都与 Vim 一模一样,直到你发现了完全不同的地方。不过,如果你是一个刚接触 Vim 编辑器的新手,或者你是一个正在寻找新挑战的 Vim 用户,那么 Kakoune 可能是你的理想编辑器。
|
||||
|
||||
你自己试试吧!
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/20/12/kakoune
|
||||
|
||||
作者:[Seth Kenlon][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[geekpi](https://github.com/geekpi)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [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/osdc-docdish-typewriterkeys-3.png?itok=NyBwMdK_ (Typewriter keys in multicolor)
|
||||
[2]: https://kakoune.org/
|
||||
[3]: https://linux.cn/article-12947-1.html
|
||||
[4]: https://github.com/mawww/kakoune
|
||||
[5]: https://opensource.com/article/20/3/ranger-file-navigator
|
||||
[6]: https://opensource.com/sites/default/files/kakoune-screenshot.png (Kakoune)
|
@ -0,0 +1,71 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (geekpi)
|
||||
[#]: reviewer: (wxy)
|
||||
[#]: publisher: (wxy)
|
||||
[#]: url: (https://linux.cn/article-12961-1.html)
|
||||
[#]: subject: (Find out how your text will be read with Norka)
|
||||
[#]: via: (https://opensource.com/article/20/12/norka)
|
||||
[#]: author: (Seth Kenlon https://opensource.com/users/seth)
|
||||
|
||||
了解如何使用 Norka 编辑器阅读文本
|
||||
======
|
||||
|
||||
> 这是一个素颜朝天的文本编辑器,旨在让你的写作能被更好地阅读和理解。
|
||||
|
||||
![](https://img.linux.net.cn/data/attachment/album/202012/28/003505f3h3pppkg7enpxi9.jpg)
|
||||
|
||||
有些文本编辑器是为编程而设计的,有些是为专门的文本格式而设计的,有些是为文档设计而设计的。Norka 文本编辑器是为阅读而设计的。创建一个为*阅读*而设计的文本编辑器似乎很奇怪,但实际上,如果你仔细想想,这是很有意义的。你的文字已经写了一次或三次,这取决于你个人对迭代的容忍度,但它的目的是为了在未来几年内被阅读。Norka 让你轻松地专注于你的文字如何被阅读。
|
||||
|
||||
### 安装
|
||||
|
||||
Norka 文本编辑器是 MIT 授权的,可以[作为 Flatpak 包安装在 Linux上][2]。它是开源的,所以如果你想尝试在不同的平台上安装它,你可以[克隆它的 Github 仓库][3]。
|
||||
|
||||
### Norka 的界面
|
||||
|
||||
Norka 的界面很简单。一个回到 Norka 文档集的按钮,一个导出按钮和一个偏好菜单。窗口的其余部分是供你写文字的空白空间,在右下角,有一个阅读时间计算器来帮助你了解读者可能需要多长时间才能看完你写的东西。
|
||||
|
||||
![Dark Norka terminal box with green and white text][4]
|
||||
|
||||
这几乎就是 Norka 的全部内容。没有分页符或行号,没有代码折叠或正则搜索。这是一个用于文字书写的编辑器,而不设置文档样式或跟踪复杂的数据模式。
|
||||
|
||||
当然,它还有一些额外的功能。如预期那样,可以使用 `Ctrl+C` 和 `Ctrl+V` 复制和粘贴。你可以用 `Ctrl+Z` 撤销,用 `Ctrl+F` 查找。你甚至可以用 `Ctrl+:` 插入表情符号。
|
||||
|
||||
![Norka terminal box with pop up box of emoji search menu][5]
|
||||
|
||||
#### 样式文本
|
||||
|
||||
虽然 Norka 绝对没有兴趣帮你设计,比如说,一本小册子或传单,但它确实有一些能力来指示你想要的文本样式。它通过 [Markdown][6] 来实现这一点,这是一个简单的纯文本书写的约定,但用特殊的符号来指示文本应该如何在 HTML、EPUB 或 PDF 或任何你的目标格式中呈现。
|
||||
|
||||
在大多数编辑器中,你必须知道 Markdown 才能使用 Markdown,但 Norka 翻译了常见的文字处理器键盘快捷键来为你生成 Markdown。例如,要使一个单词加粗,你可以按 `Ctrl+B`,它会在光标的两边插入四个星号。当你输入下一个单词时,它的两边都会有两个星号,这就是 Markdown 对粗体(默认为粗体)文本的标记。你可以在 Norka 窗口右上角的汉堡样式的菜单中查看所有的 Markdown 快捷方式。
|
||||
|
||||
#### 保存和导出
|
||||
|
||||
你可以把 Norka 想象成一个笔记本。你在 Norka 中打开的所有文档都会保留在 Norka 的内部数据库中,所有的文档都会默认自动保存。要在 Norka 外使用文件,你可以在打开的文件中点击右上角的**共享**按钮。另外,你也可以在 Norka 的文件视图中右击任何文件,选择**导出**。你可以将文档导出(或**共享**,Norka 可互换使用这两个术语)为**文本**、**HTML** 或 **Markdown**。
|
||||
|
||||
### 尝试 Norka
|
||||
|
||||
Norka 便于尝试,也易于使用。它通过保持界面简单,几乎到了受限的程度,帮助你专注于写作。但限制有时也是一种强大的创意工具。
|
||||
|
||||
Norka 可能不是你进行大量修改或文本处理的最佳选择。它没有让人激动的功能,比如大小写转换、集成 `sed` 命令、字符交换等等。它是一个为读者服务的文本编辑器。如果你觉得有用,那么你可能正是 Norka 正在寻找的受众。
|
||||
|
||||
感谢你花 2 分 39 秒阅读本文!
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/20/12/norka
|
||||
|
||||
作者:[Seth Kenlon][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[geekpi](https://github.com/geekpi)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [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/reading_book_selfcare_wfh_learning_education_520.png?itok=H6satV2u (Reading a book, selfcare)
|
||||
[2]: https://flathub.org/apps/details/com.github.tenderowl.norka
|
||||
[3]: https://github.com/TenderOwl/Norka
|
||||
[4]: https://opensource.com/sites/default/files/uploads/norka-31_days-norka-opensource.png (Dark Norka terminal box with green and white text)
|
||||
[5]: https://opensource.com/sites/default/files/uploads/norka_emoji-31_days-norka-opensource.png (Norka terminal box with pop up box of emoji search menu)
|
||||
[6]: https://opensource.com/article/19/9/introduction-markdown
|
@ -0,0 +1,122 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (robsean)
|
||||
[#]: reviewer: (wxy)
|
||||
[#]: publisher: (wxy)
|
||||
[#]: url: (https://linux.cn/article-12958-1.html)
|
||||
[#]: subject: (How to Install RPM Files on Fedora Linux [Beginner’s Tutorial])
|
||||
[#]: via: (https://itsfoss.com/install-rpm-files-fedora/)
|
||||
[#]: author: (Abhishek Prakash https://itsfoss.com/author/abhishek/)
|
||||
|
||||
如何在 Fedora Linux 上安装 RPM 文件
|
||||
======
|
||||
|
||||
![](https://img.linux.net.cn/data/attachment/album/202012/26/182851bxi1lstdz13siuif.jpg)
|
||||
|
||||
> 这篇初学者文章介绍如何在 Fedora 和 Red Hat Linux 上安装 RPM 软件包。它也随后向你展示如何移除这些 RPM 软件包。
|
||||
|
||||
当你开始使用 Red Hat 系的 Fedora Linux 时,你早晚会偶然发现 .rpm 文件。就像在 Windows 中的 .exe 文件,以及在 Ubuntu 和 Debian 中的 .deb 文件一样,一个 rpm 文件能够使你在 [Fedora][1] 上快速安装一个软件。
|
||||
|
||||
你可以从软件中心中找到并安装大量的软件,特别是 [如果你在 Fedora 中启用附加的存储库的话][2]。但是有时你会在它们的网站上找到可用的 RPM 格式的软件包。
|
||||
|
||||
就像在 Windows 中的 .exe 文件一样,你可以通过 **下载 .rpm 文件并双击它来安装**。不用担心,我将向你展示详细的步骤。
|
||||
|
||||
### 在 Fedora 和 Red Hat Linux 上安装 RPM 文件
|
||||
|
||||
我将向你展示安装 RPM 文件的三个方法:
|
||||
|
||||
* [使用软件中心安装 RPM 文件][3](GUI 方法)
|
||||
* [使用 DNF 命令安装 RPM 文件][4](CLI 方法)
|
||||
* [使用 Yum 命令安装 RPM 文件][5](Red Hat 的 CLI 方法)
|
||||
|
||||
#### 方法 1: 使用软件中心
|
||||
|
||||
在 Fedora 中使用默认的软件中心是最简单的方法。它真地很简单。转到你下载的 .rpm 文件的文件夹位置。它通常在 “Downloads” 文件夹。
|
||||
|
||||
只需要 **双击 RPM 文件,它将会在软件中心中打开**。
|
||||
|
||||
或者,你可以在 RPM 文件上右键单击并选择通过软件中心来安装它。
|
||||
|
||||
![或者双击或者右键并选择软件安装][6]
|
||||
|
||||
当它在软件中心打开时,你应该会看到“安装”选项。只需要点击“安装”按钮并在提示时输入你的账号密码。
|
||||
|
||||
![通过 Fedora 软件中心安装 RPM][7]
|
||||
|
||||
它很简单,对吗?
|
||||
|
||||
#### 方法 2: 使用 DNF 命令来安装 RPM 文件
|
||||
|
||||
这是命令行方法。Fedora 使用新的 `dnf` [软件包管理器][8] ,你也可以使用它来安装下载的 RPM 文件。
|
||||
|
||||
打开一个终端并切换到你下载 RPM 文件的目录下。你也可以通过到 RPM 文件的路径。像这样使用 `dnf` 命令:
|
||||
|
||||
```
|
||||
sudo dnf install rpm_file_name
|
||||
```
|
||||
|
||||
这是一个我 [在 Fedora 上使用 dnf 命令安装 Google Chrome][9] 屏幕截图:
|
||||
|
||||
![使用 DNF 命令安装 RPM 文件][10]
|
||||
|
||||
#### 方法 3: 在 Red Hat 中使用 Yum 命令安装 RPM 文件
|
||||
|
||||
不像 Fedora ,Red Hat 仍然使用很好的旧式的 Yum 软件包管理器。在这里你还不能找到 `dnf` 命令。
|
||||
|
||||
这个过程与 `dnf` 命令相同。转到 RPM 文件所在的目录或提供它的路径。
|
||||
|
||||
```
|
||||
sudo yum install path_to_RPM_file
|
||||
```
|
||||
|
||||
就是这样。没有一点异常花哨的东西。
|
||||
|
||||
### 如何移除 RPM 软件包
|
||||
|
||||
移除一个 RPM 软件包也不是一个什么大的问题。并且,你不需要原始的用来安装程序的 rpm 文件。
|
||||
|
||||
你可以在软件中心中找到已安装的软件包,并从其中移除应用程序。
|
||||
|
||||
![移除 RPM 软件包][11]
|
||||
|
||||
或者,你可以使用带有 `remove` 选项的 `dnf` 或 `yum` 命令。
|
||||
|
||||
使用 `dnf` ,使用这个命令:
|
||||
|
||||
```
|
||||
sudo dnf remove rpm_package_name
|
||||
```
|
||||
|
||||
使用 `yum` ,使用这个命令:
|
||||
|
||||
```
|
||||
sudo yum remove rpm_package_name
|
||||
```
|
||||
|
||||
你可能不记得准确的软件包名称,没有关系。你可以做的是输入软件包的前几个字母,然后敲击 `tab` 按键。这是假设你已经启用 `tab` 按键补全,通常是这样的。
|
||||
|
||||
这就是你需要做的全部。相当简单,对吧?作为一个初学者,你可能会为这样一个简单的任务而挣扎,我希望像这样的快速教程会让你对 Fedora 更自信一些。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://itsfoss.com/install-rpm-files-fedora/
|
||||
|
||||
作者:[Abhishek Prakash][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[robsean](https://github.com/robsean)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://itsfoss.com/author/abhishek/
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://getfedora.org/
|
||||
[2]: https://itsfoss.com/fedora-third-party-repos/
|
||||
[3]: tmp.TvkJtlRJ6T#gui-method
|
||||
[4]: tmp.TvkJtlRJ6T#use-dnf
|
||||
[5]: tmp.TvkJtlRJ6T#use-yum
|
||||
[6]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2020/12/installing-rpm-file-fedora.png?resize=800%2C449&ssl=1
|
||||
[7]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2020/12/install-rpm-fedora-software-center.jpg?resize=799%2C193&ssl=1
|
||||
[8]: https://itsfoss.com/package-manager/
|
||||
[9]: https://itsfoss.com/install-google-chrome-fedora/
|
||||
[10]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2020/12/install-rpm-using-dnf-install.jpg?resize=800%2C474&ssl=1
|
||||
[11]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2020/12/remove-rpm-package-fedora.jpg?resize=790%2C190&ssl=1
|
@ -1,147 +0,0 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (The state of the art of microservices in 2020)
|
||||
[#]: via: (https://www.linux.com/news/the-state-of-the-art-of-microservices-in-2020/)
|
||||
[#]: author: (Linux.com Editorial Staff https://www.linux.com/author/linuxdotcom/)
|
||||
|
||||
The state of the art of microservices in 2020
|
||||
======
|
||||
|
||||
### _“The microservice architectural style is an approach to developing a_ _**single application**_ _as a suite of_ _**small services**_*, each running in its* _**own process and communicating with lightweight mechanisms**_*, often an HTTP resource API. These services are* _**built around business capabilities**_ _and_ _**independently deployable**_ _by_ _**fully automated deployment machinery**_*. There is a bare minimum of centralized management of these services, which may be written in* _**different programming languages**_ _and_ _**use different data storage technologies.**__“_
|
||||
|
||||
### James Lewis and Martin Fowler (2014) [6]
|
||||
|
||||
## Introduction
|
||||
|
||||
It is expected that in 2020, the global cloud microservices market will grow at a rate of 22.5%, with the US market projected to maintain a growth rate of 27.4% [5]. The tendency is that developers will move away from locally hosted applications and shift into the cloud. Consequently, this will help businesses minimize downtime, optimize resources, and reduce infrastructure costs. Experts also predict that by 2022, 90% of all applications will be developed using microservices architecture [5]. This article will help you to learn what microservices are and how companies have been using it nowadays.
|
||||
|
||||
## What are microservices?
|
||||
|
||||
Microservices have been widely used around the world. But what are microservices? Microservice is an architectural pattern in which the application is based on many small interconnected services. They are based on the **single responsibility principle**, which according to Robert C. Martin is “gathering things that change for the same reason, and separate those things that change for different reasons” [2]. The microservices architecture is also extended to the **loosely coupled services** that can be **developed, deployed, and maintained independently** [2].
|
||||
|
||||
## Moving away from monolithic architectures
|
||||
|
||||
Microservices are often compared to traditional monolithic software architecture. In a monolithic architecture, a software is designed to be self-contained, i.e., the program’s components are interconnected and interdependent rather than loosely coupled. In a tightly-coupled architecture (monolithic), each component and its associated components must be present in order for the code to be executed or compiled [7]. Additionally, if any component needs to be updated, the whole application needs to be rewritten.
|
||||
|
||||
That’s not the case for applications using the microservices architecture. Since each module is independent, it can be changed without affecting other parts of the program. Consequently, reducing the risk that a change made to one component will create unanticipated changes in other components.
|
||||
|
||||
Companies might run in trouble if they cannot scale a monolithic architecture if their architecture is difficult to upgrade or the maintenance is too complex and costly [4]. Breaking down a complex task into smaller components that work independently from each other is the solution to this problem.
|
||||
|
||||
![Monolithic vs. microservices architecture. Image extracted from \[3\].][1]
|
||||
|
||||
## How developers around the world build their microservices
|
||||
|
||||
Microservices are well known for improving _scalability_ and _performance_. However, are those the main reasons that developers around the world build their microservices? The State of Microservices 2020 research project [1] has found out how developers worldwide build their microservices and what they think about it. The report was created with the help of 660 microservice experts from Europe, North America, Central and South America, the Middle East, South-East Asia, Australia, and New Zealand. The table below presents the average rating on questions related to the maturity of microservices [1].
|
||||
|
||||
**Category** | **Average rating (out of 5)**
|
||||
---|---
|
||||
Setting up a new project | 3.8
|
||||
Maintenance and debugging | 3.4
|
||||
Efficiency of work | 3.9
|
||||
Solving scalability issues | 4.3
|
||||
Solving performance issues | 3.9
|
||||
Teamwork | 3.9
|
||||
|
||||
|
||||
|
||||
As observed on the table, most experts are happy with microservices for solving scalability issues. On the contrary, maintenance and debugging seem to be a challenge for them.
|
||||
|
||||
According to their architecture’s leading technologies, most experts reported that they use Javascript/Typescript (almost ⅔ of microservices are built on those languages). In the second place, they mostly use Java.
|
||||
|
||||
Although there are plenty of options to choose to deploy microservices, most experts use Amazon Web Services (49%), followed by their own server. Additionally, 62% prefer AWS Lambda as a serverless solution.
|
||||
|
||||
Most microservices used by the experts use HTTP for communication, followed by events and gRPC. Additionally, most experts use RabbitMQ for message-brokers, followed by Kafka and Redis.
|
||||
|
||||
Also, most people work with microservices continuous integration (CI). In the report, 87% of the respondents use CI solutions such as GitLab CI, Jenkins, or GitHub Actions.
|
||||
|
||||
The most popular debugging solution among 86% of the respondents was logging, in which 27% of the respondents ONLY use logs.
|
||||
|
||||
Finally, most people think that microservice architecture will become either a standard for more complex systems or backend development.
|
||||
|
||||
## Successful use cases of Microservices
|
||||
|
||||
Many companies have changed from a monolithic architecture to microservices.
|
||||
|
||||
### Amazon
|
||||
|
||||
In 2001, development delays, coding challenges, and service interdependencies didn’t allow Amazon to address its growing user base’s scalability requirements. With the need to refactor their monolithic architecture from scratch, Amazon broke its monolithic applications into small, independent, and service-specific applications [3][9].
|
||||
|
||||
In 2001, Amazon decided to change to microservices, which was years before the term came into fashion. This change led Amazon to develop several solutions to support microservices architectures, such as Amazon AWS. With the rapid growth and adaptation to microservices, Amazon became the most valuable company globally, valued by market cap at $1.433 trillion on July 1st, 2020 [8].
|
||||
|
||||
### Netflix
|
||||
|
||||
Netflix started its movie-streaming service in 2007, and by 2008 it was suffering scaling challenges. They experienced a major database corruption, and for three days, they could not ship DVDs to their members [10]. This was the starting point when they realized the need to move away from single points of failure (e.g., relational databases) towards a more scalable and reliable distributed system in the cloud. In 2009, Netflix started to refactor its monolithic architecture into microservices. They began by migrating its non-customer-facing, movie-coding platform to run on the cloud as an independent microservices [11]. Changing to microservices allowed Netflix to overcome its scaling challenges and service outages. Despite that, it allowed them to reduce costs by having cloud costs per streaming instead of costs with a data center [10]. Today, Netflix streams approximately 250 million hours of content daily to over 139 million subscribers in 190 countries [11].
|
||||
|
||||
### Uber
|
||||
|
||||
After launching Uber, they struggled to develop and launch new features, fix bugs, and rapidly integrate new changes. Thus, they decided to change to microservices, and they broke the application structure into cloud-based microservices. In other words, Uber created one microservice for each function, such as passenger management and trip management. Moving to microservices brought Uber many benefits, such as having a clear idea of each service ownership. This boosted speed and quality, facilitating fast scaling by allowing teams to focus only on the services they needed to scale, updating virtual services without disrupting other services, and achieving more reliable fault tolerance [11].
|
||||
|
||||
## It’s all about scalability!
|
||||
|
||||
A good example of how to provide scalability is by looking at China. With its vast number of inhabitants, China had to adapt by creating and testing new solutions to solve new challenges at scale. Statistics show that China serves roughly 900 million Internet users nowadays [14]. During the 2019 Single’s Day (the equivalent of Black Friday in China), the peak transaction of Alibaba’s various shopping platforms was 544,00 transactions per second. The total amount of data processed on Alibaba Cloud was around 970 petabytes [15]. So, what’s the implication of these numbers of users in technology?
|
||||
|
||||
Many technologies have emerged from the need to address scalability. For example, [Tars][2] was created in 2008 by Tencent and [contributed to the Linux Foundation in 2018][3]. It’s being used at scale and enhanced for ten years [12]. Tars is open source, and many organizations are significantly contributing and extending the framework’s features and value [12]. Tars supports multiple programming languages, including C++, Golang, Java, Node.js, PHP, and Python; and it can quickly build systems and automatically generate code, allowing the developer to focus on the business logic to improve operational efficiency effectively. Tars has been widely used in Tencent’s QQ, WeChat social network, financial services, edge computing, automotive, video, online games, maps, application market, security, and many other core businesses. [In March of 2020, the Tars project transitioned into the TARS Foundation][4], an open source microservice foundation to support the rapid growth of contributions and membership for a community focused on building an open microservices platform [12].
|
||||
|
||||
**Be sure to check out the Linux Foundation’s new free training course,** [Building Microservice Platforms with TARS][5]
|
||||
|
||||
*About the authors: *
|
||||
|
||||
_Isabella Ferreira is an Advocate at TARS Foundation,_ a cloud-native open-source microservice foundation under the Linux Foundation*. *
|
||||
|
||||
*Mark Shan is Chairman at Tencent Open Source Alliance and also Board Chair at TARS Foundation. *
|
||||
|
||||
**References:**
|
||||
|
||||
[1] <https://tsh.io/state-of-microservices/#ebook>
|
||||
|
||||
[2]<https://medium.com/hashmapinc/the-what-why-and-how-of-a-microservices-architecture-4179579423a9>
|
||||
|
||||
[3] <https://www.plutora.com/blog/understanding-microservices>
|
||||
|
||||
[4] <https://www.leanix.net/en/blog/a-brief-history-of-microservices>
|
||||
|
||||
[5] <https://www.charterglobal.com/five-microservices-trends-in-2020/>
|
||||
|
||||
[6] <https://martinfowler.com/articles/microservices.html#footnote-etymology>
|
||||
|
||||
[7] <https://whatis.techtarget.com/definition/monolithic-architecture>
|
||||
|
||||
[8] <https://ycharts.com/companies/AMZN/market_cap>
|
||||
|
||||
[9] <https://thenewstack.io/led-amazon-microservices-architecture/>
|
||||
|
||||
[10] <https://media.netflix.com/en/company-blog/completing-the-netflix-cloud-migration>
|
||||
|
||||
[11] <https://blog.dreamfactory.com/microservices-examples/>
|
||||
|
||||
[12] <https://www.linuxfoundation.org/blog/2020/03/the-tars-foundation-the-formation-of-a-microservices-ecosystem/>
|
||||
|
||||
[13] <https://medium.com/microservices-architecture/top-10-microservices-framework-for-2020-eefb5e66d1a2>
|
||||
|
||||
[14] <https://www.statista.com/statistics/265140/number-of-internet-users-in-china/>
|
||||
|
||||
[15] <https://interconnected.blog/china-scale-technology-sandbox/>
|
||||
|
||||
#### _This Linux Foundation Platinum Sponsor content was contributed by Tencent._
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.linux.com/news/the-state-of-the-art-of-microservices-in-2020/
|
||||
|
||||
作者:[Linux.com Editorial Staff][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.linux.com/author/linuxdotcom/
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://www.linux.com/wp-content/uploads/2020/11/microservices_diagram_a.png
|
||||
[2]: https://tarscloud.org/foundation/index
|
||||
[3]: https://www.linuxfoundation.org/press-release/2018/06/tars-and-tseer-form-open-source-project-communities-under-the-linux-foundation-to-expand-adoption-and-pace-of-development/
|
||||
[4]: https://www.linuxfoundation.org/blog/2020/03/the-tars-foundation-the-formation-of-a-microservices-ecosystem/
|
||||
[5]: https://www.edx.org/course/building-microservice-platforms-with-tars
|
103
sources/talk/20201214 Ben Cotton- How Do You Fedora.md
Normal file
103
sources/talk/20201214 Ben Cotton- How Do You Fedora.md
Normal file
@ -0,0 +1,103 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Ben Cotton: How Do You Fedora?)
|
||||
[#]: via: (https://fedoramagazine.org/ben-cotton-how-do-you-fedora/)
|
||||
[#]: author: (gchang https://fedoramagazine.org/author/gchang/)
|
||||
|
||||
Ben Cotton: How Do You Fedora?
|
||||
======
|
||||
|
||||
![][1]
|
||||
|
||||
We recently interviewed Ben Cotton on how he uses Fedora. This is part of a [series][2] on the Fedora Magazine. The series profiles Fedora users and how they use Fedora to get things done. Contact us on the [feedback form][3] to express your interest in becoming an interviewee.
|
||||
|
||||
### **Who is Ben Cotton?**
|
||||
|
||||
If you follow the Fedora’ Community Blog, there’s a good chance you already know who Ben is.
|
||||
|
||||
Ben’s Linux journey started around late 2002. Frustrated with some issues on using Windows XP, and starting a new application administrator role at his university where some services were being run on FreeBSD. A friend introduced him to Red Hat Linux, when Ben decided it made sense to get more practice with Unix-like operating systems. He switched to Fedora full-time in 2006, after he landed a job as a Linux system administrator.
|
||||
|
||||
Since then, his career has included system administration, people management, support engineering, development, and marketing. Several years ago, he even earned a Master’s degree in IT Project Management. The variety of experience has helped Ben learn how to work with different groups of people. “A lot of what I’ve learned has come from making mistakes. When you mess up communication, you hopefully do a better job the next time.”
|
||||
|
||||
Besides tech, Ben also has a range of well-rounded interests. “I used to do a lot of short fiction writing, but these days I mostly write my opinions about whatever is on my mind.” As for favorite foods, he claims “All of it. Feed me.”
|
||||
|
||||
Additionally, Ben has taste that spans genres. His childhood hero was a character from the science fiction series “Star Trek: The Next Generation”. “As a young lad, I wanted very much to be Wesley Crusher.” His favorite movies are a parody film and a spy thriller: “‘Airplane!’ and ‘The Hunt for Red October’” respectively.
|
||||
|
||||
When asked for the five greatest qualities he thinks someone can possess, Ben responded cleverly: “Kindness. Empathy. Curiosity. Resilience. Red hair.”
|
||||
|
||||
![][4]
|
||||
|
||||
Ben wearing the official “#action bcotton” shirt
|
||||
|
||||
### **His Fedora Story**
|
||||
|
||||
As a talented writer who described himself as “not much of a programmer”, he selected the [Fedora Docs][5] team in 2009 as an entry point into the community. What he found was that “the Friends foundation was evident.” At the time, he wasn’t familiar with tools such as Git, DocBook XML, or Publican (docs toolchain at the time). The community of experienced doc writers helped him get on his feet and freely gave their time. To this day, Ben considers many of them to be his friends and feels really lucky to work with them. Notably “jjmcd, stickster, sparks, and jsmith were a big part of the warm welcome I received.”
|
||||
|
||||
Today, as a senior program manager, he describes his job as “Chief Cat Herding Officer”- as his job is largely composed of seeing what different parts of the project are doing and making sure they’re all heading in the same general direction.
|
||||
|
||||
Despite having a huge responsibility, Ben also helps a lot in his free time with tasks outside of his job duties, like website work, CommBlog and Magazine editing, packaging, etc… none of which are his core job responsibilities. He tries to find ways to contribute that match his skills and interests. Building credibility, paying attention, developing relationships with other contributors, and showing folks that he’s able to help, is much more important to him than what his “official” title is.
|
||||
|
||||
When thinking towards the future, Ben feels hopeful watching the Change proposals come in. “Sometimes they get rejected, but that’s to be expected when you’re trying to advance the state of the art. Fedora contributors are working hard to push the project forward.“
|
||||
|
||||
### **The Fedora Community **
|
||||
|
||||
As a longtime member of the community, Ben has various notions about the Fedora Project that have been developed over the years. For starters, he wants to make it easier to bring new contributors on board. He believes the Join SIG has “done tremendous work in this area”, but new contributors will keep the community vibrant.
|
||||
|
||||
If Ben had to pick a best moment, he’d choose Flock 2018 in Dresden. “That was my first Fedora event and it was great to meet so many of the people who I’ve only known online for a decade.”
|
||||
|
||||
As for bad moments, Ben hasn’t had many. Once he accidentally messed up a Bugzilla query resulting in accidental closure of hundreds of bugs and has dealt with some frustrating mailing list threads, but remains positive, affirming that “frustration is okay.”
|
||||
|
||||
To those interested in becoming involved in the Fedora Project, Ben says “Come join us!” There’s something to appeal to almost anyone. “Take the time to develop relationships with the people you meet as you join, because without the Friends foundation, the rest falls apart.”
|
||||
|
||||
![][6]
|
||||
|
||||
![][7]
|
||||
|
||||
### **Pet Peeves**
|
||||
|
||||
One issue he finds challenging is a lack of documentation. “I’ve learned enough over the years that I can sort of bumble through making code changes to things, but a lot of times it’s not clear how the code ties together.” Ben sees how sparse or nonexistent documentation can be frustrating to newcomers who might not have the knowledge that is assumed.
|
||||
|
||||
Another concern Ben has is that the “interesting” parts of technology are changing. “Operating systems aren’t as important to end users as they used to be thanks to the rise of mobile computing and Software-as-a-Service. Will this cause our pool of potential new contributors to decrease?”
|
||||
|
||||
Likewise, Ben believes that it’s not always easy to get people to understand why they should care about open source software. “The reasons are often abstract and people don’t see that they’re directly impacted, especially when the alternatives provide more immediate convenience.”
|
||||
|
||||
### **What Hardware?**
|
||||
|
||||
For work, Ben has a ThinkPad X1 Carbon running Fedora 33 KDE. His personal server/desktop is a machine he put together from parts that runs Fedora 33 KDE. He uses it as a file server, print server, Plex media server, and general-purpose desktop. If he has some spare time to get it started, Ben also has an extra laptop that he wants to start using to test Beta releases and “maybe end up running rawhide on it”.
|
||||
|
||||
### **What Software?**
|
||||
|
||||
Ben has been a KDE user for a decade. A lot of his work is done in a web browser (Firefox for work stuff, Chrome for personal). He does most of his scripting in Python these days, with some inherited scripts in Perl.
|
||||
|
||||
Notable applications that Ben uses include:
|
||||
|
||||
* Cherrytree for note-taking
|
||||
* Element for IRC
|
||||
* Inkscape and Kdenlive when he needs to edit videos.
|
||||
* Vim on the command line and Kate when he wants a GUI
|
||||
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://fedoramagazine.org/ben-cotton-how-do-you-fedora/
|
||||
|
||||
作者:[gchang][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/gchang/
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://fedoramagazine.org/wp-content/uploads/2020/11/LISA2015-printsize-7810-816x545.jpg
|
||||
[2]: https://fedoramagazine.org/tag/how-do-you-fedora/
|
||||
[3]: https://fedoramagazine.org/submit-an-idea-or-tip/
|
||||
[4]: https://fedoramagazine.org/wp-content/uploads/2020/11/image1-2-edited.jpg
|
||||
[5]: https://docs.fedoraproject.org/
|
||||
[6]: https://i1.wp.com/fedoramagazine.org/wp-content/uploads/2020/11/image2-2.jpg?ssl=1&resize=1500%2C1500
|
||||
[7]: https://i1.wp.com/fedoramagazine.org/wp-content/uploads/2020/11/image6-1.jpg?ssl=1&resize=1500%2C1500
|
@ -0,0 +1,79 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (9 stories about switching to an open source alternative in 2020)
|
||||
[#]: via: (https://opensource.com/article/20/12/open-source-alternatives)
|
||||
[#]: author: (Jason Blais https://opensource.com/users/jasonblais)
|
||||
|
||||
9 stories about switching to an open source alternative in 2020
|
||||
======
|
||||
Ditch your proprietary software for open source solutions.
|
||||
![Working from home at a laptop][1]
|
||||
|
||||
In 2020, as every year, new open source projects launched as alternatives to proprietary solutions. Here is a roundup of the top nine articles about open source alternatives that made the headlines in 2020 on Opensource.com.
|
||||
|
||||
### 7 alternatives to VS Code
|
||||
|
||||
Seth Kenlon gives an overview of [_7 open source alternatives to VS Code_][2], a code editor from Microsoft for Linux, Windows, and macOS. While Microsoft publishes VS Code's source code under the MIT License, "the version you download from Microsoft is not open source," Seth warns. If you prefer open source alternatives, make sure to check out Seth's article for his recommended alternatives, including VSCodium and Atom.
|
||||
|
||||
### Nextcloud instead of Google Suite
|
||||
|
||||
In [_Build your own open source alternative to Google Suite with Nextcloud_][3], Correspondent Don Watkins explains how Nextcloud has matured in recent years to become a true alternative to Google Drive and Microsoft 365. Don begins by reviewing how to get started with Nextcloud, then he outlines its key features, including the ability to "sync, share, and collaboratively view and edit files, as well as [share] calendars, contacts, email, chats, video calls, project management, [and] notes."
|
||||
|
||||
### 6 alternatives to Wunderlist
|
||||
|
||||
Wunderlist was a popular tool to track to-do lists, but when Microsoft announced it was shutting it down, many people began looking for alternatives. Jen Wike Huger does an excellent job summarizing [_6 open source alternatives to Wunderlist_][4], including OwnCloud, OpenTasks, and more. If you're still looking for a Wunderlist replacement or are just curious to know what is out there for tracking your to-do's, make sure to read Jen's article.
|
||||
|
||||
### Plausible Analytics instead of Google Analytics
|
||||
|
||||
In [_Transparent, open source alternative to Google Analytics_][5], Marko Saric describes Plausible Analytics as a "leaner, more transparent option [to Google Analytics], with the essential data you need but without all the privacy baggage." By "baggage," Marko means privacy policies, GDPR-consent prompts, and other things that come with Google Analytics. With Plausible Analytics, you don't need to worry about such privacy restrictions; the tool doesn't collect any personal data or use cookies and still provides accurate visitor statistics for your website.
|
||||
|
||||
### Mycroft instead of Alexa
|
||||
|
||||
Many people are wary about the private conversations their Apple, Google, and Amazon voice assistants may have access to. Those looking for a private option may want to explore Mycroft, [_A secure and private open source alternative to Alexa_][6]. Correspondent Steve Ovens describes Mycroft as the "open source alternative … [that] puts privacy at the forefront."
|
||||
|
||||
### HomeBank instead of Quicken
|
||||
|
||||
Quicken is a proprietary personal financial management tool—and you guessed it, there is an open source alternative for it. In [_How to use HomeBank for your open source alternative to Quicken_][7], Correspondent Jessica Cherry provides an overview of HomeBank and walks through how to install the software, create an account, and analyze your finances with the tool. If you're looking for an open source option to help manage your spending habits, make sure to read Jess' article about HomeBank.
|
||||
|
||||
### GoDBLedger instead of proprietary accounting software
|
||||
|
||||
Sean Darcy, an accountant frustrated by outdated accounting software solutions, decided to spend six months building GoDBLedger, an open source option to improve accountants' productivity. In [_Open source accounting software developed by accountants_][8], he outlines the challenges he faced with previous tools due to poor usability, unintuitive user experiences, and slow compilation that "involves a lot of human labor to achieve." He then demonstrates how GoDBLedger solves each of these challenges.
|
||||
|
||||
### 4 alternatives to Grammarly
|
||||
|
||||
Grammarly is one of the most popular tools to "check your writing for spelling, grammar, plagiarism, and style errors," writes Seth Kenlon. But instead of Grammarly, Seth uses open source options for each of these use cases. In [_Open source alternatives to Grammarly for word processing_][9], he describes the tool that works best for each of Grammarly's functionalities, such as Flyspell, a lightweight open source spell checker.
|
||||
|
||||
### 7 alternatives to StackOverflow or Quora
|
||||
|
||||
Instead of using StackOverflow or Quora as your knowledge-base Q&A site, why not switch to an open source alternative? Correspondent Bryant Son walks through [_7 open source Q&A platforms_][10], including Discourse, Vanilla, AskBot, and more. If you are looking for a new Q&A platform, make sure to check out Bryant's article!
|
||||
|
||||
### Top open source alternatives in 2021?
|
||||
|
||||
Which open source alternatives do you think will make the headlines in 2021? Let us know in the comments.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/20/12/open-source-alternatives
|
||||
|
||||
作者:[Jason Blais][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/jasonblais
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/wfh_work_home_laptop_work.png?itok=VFwToeMy (Working from home at a laptop)
|
||||
[2]: https://opensource.com/article/20/6/open-source-alternatives-vs-code
|
||||
[3]: https://opensource.com/article/20/7/nextcloud
|
||||
[4]: https://opensource.com/article/20/5/alternatives-list
|
||||
[5]: https://opensource.com/article/20/5/plausible-analytics
|
||||
[6]: https://opensource.com/article/20/6/open-source-voice-assistant
|
||||
[7]: https://opensource.com/article/20/2/open-source-homebank
|
||||
[8]: https://opensource.com/article/20/7/godbledger
|
||||
[9]: https://opensource.com/article/20/3/open-source-writing-tools
|
||||
[10]: https://opensource.com/article/20/2/open-source-qa
|
@ -0,0 +1,153 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Why I rewrote my open source virtual reality server)
|
||||
[#]: via: (https://opensource.com/article/20/12/virtual-reality-server)
|
||||
[#]: author: (Josip Almasi https://opensource.com/users/jalmasi)
|
||||
|
||||
Why I rewrote my open source virtual reality server
|
||||
======
|
||||
With VRSpace, you can play group VR games across platforms without
|
||||
sacrificing your privacy.
|
||||
![new techie gadgets representing innovation][1]
|
||||
|
||||
Look! I wrote a virtual reality (VR) server and [published it on GitHub][2]! But _why_?
|
||||
|
||||
Well, I'm your typical introverted hacker. I like to play with technology. Whenever something new comes out, I have to lay my hands on it and get them dirty. So, when I gifted myself Oculus Quest last year, I played a few games before I wanted to code something myself. And guess what? _Everything is_ _proprietary!_
|
||||
|
||||
Alright, this may be a bit of an overstatement. But my overall impression of the VR industry is exactly that—it's all proprietary! Hardware and software vendors are trying to lock developers in to sell more devices and development tools than their competitors—deja vu, like the Unix wars in the last century.
|
||||
|
||||
![VRSpace.org][3]
|
||||
|
||||
Choosing an avatar and portals to virtual spaces. ([Gileon][4], [hong227][5], [Jasna Almasi][6], [CC BY-SA 4.0][7])
|
||||
|
||||
But welcome to the 21st century; we live in clouds now! Clouds take all our data and store it somewhere safe at the cloud owner's mercy. Take Oculus Quest 2, for instance. You can't even use it without a Facebook account. But once you do, all your data goes to Facebook.
|
||||
|
||||
What kind of data? _Biometric_ _data_.
|
||||
|
||||
VR devices track our movements, know our real-world height, and more. GDPR and other privacy laws include this type of biometric data in the highest security categories. Rightfully so, as this data enables the worst kind of privacy invasions. Imagine, for instance, a deepfake that mimics your every movement.
|
||||
|
||||
I'm using Facebook as an example, but the risks are the same with any private organization whose code cannot be scrutinized.
|
||||
|
||||
### Building an open, interoperable VR server
|
||||
|
||||
Privacy is but one of my motivations for writing a VR server; the other is my family.
|
||||
|
||||
My kids play together in real life, and they also want to play together in VR. I have another VR headset, an Acer OJO, but that exists in a different world of Windows Mixed Reality from an Oculus. Once again, vendor lock-in gets in the way. For my kids to play VR together, we'd need two Microsoft or two Facebook headsets.
|
||||
|
||||
But there's a way out.
|
||||
|
||||
Enter the [WebXR][8] Device API. This [open source][9] specification "describes support for accessing virtual reality (VR) and augmented reality (AR) devices, including sensors and head-mounted displays, on the web." It's VR and AR (summarized by _X_) that works on every device, just as the web has to work on any device—including mobile devices.
|
||||
|
||||
WebXR includes a [WebGL layer][10], and there are a number of JavaScript libraries (such as Three.js) to help developers working with WebGL and a full-featured open source game engine, BabylonJS. (Three.js fans might want to try [CS1 Game Engine][11], a promising yet unfinished library with performance and developer experience as top priorities.)
|
||||
|
||||
The tools also interoperate with popular web development frameworks like Angular and React. There's also [glTF][12], an open standard for 3D models that pretty much every relevant tool reads and writes, as well as an incredible number of open source 3D models that are mostly published under Creative Commons Attribution licenses.
|
||||
|
||||
The only thing missing was a server. One that would deliver content (models) and presentation logic (JavaScript), collect and distribute user events, and implement business (game) logic, but _would not store any sensitive data_.
|
||||
|
||||
It just happens that 20 years ago, I wrote an open source VR server named [VRSpace][13]. Unfortunately, it was way too early for its own good, and the project died along with the client technology ([VRML][14]). But I knew exactly what I needed to do for today's VR, so I wrote it again. And luckily, it's much easier to do with modern technologies.
|
||||
|
||||
![Old VRSpace][15]
|
||||
|
||||
Twenty years ago, VRSpace.org was a chat with a chatbot. ([Arni Barisic][16], Slaven Katic, Josip Almasi, [CC BY-SA 4.0][7])
|
||||
|
||||
Rather than reflecting on the good ol' times and 20 years of technology gap, I'll talk about some of the design choices I made and the open source tools I used.
|
||||
|
||||
### Two decades later: Java and JavaScript
|
||||
|
||||
I chose Java and [Spring Boot][17] simply because I use them daily. But truth be told, Node.js might be a better tool for this job, as it is easier to develop and maintain software written in one language than two. For the client side, I chose [BabylonJS][18], because it's a full-featured WebXR game engine and plain JavaScript, and I didn't want the client to depend on a user interface (UI) framework.
|
||||
|
||||
BabylonJS is written in TypeScript, so if I wanted to make a monolithic product, I'd go with TypeScript. On the other hand, I don't want to enforce any specific technology on the client side. Web browsers are not the only kind of client that will want to interact in VR, and native apps usually give the best performance.
|
||||
|
||||
The communication layer doesn't depend on anything else, which may be relevant if you want to implement your own VR client or a headless client like a chatbot.
|
||||
|
||||
To store the data, I chose the [Neo4J][19] database, which turned out to be as good as it gets. It can be embedded into my server and store all of my objects. Except for sensitive ones, of course, so I took special care to mark every sensitive field as transient. If I didn't care about this, you couldn't trust my server to protect your private data against nosy government institutions or criminals looking to steal valuable biometric data.
|
||||
|
||||
Communication happens with JSON over WebSockets—because it just works. Protocol-wise, it's far from the best choice. The sheer number of events emitted from VR device sensors is much higher than your usual first-person shooter; VR gear tracks your arms and head, various buttons and joysticks, possibly even eye movements, and every finger. Rate limiting is a must-have no matter what.
|
||||
|
||||
But what about chat? VR devices don't have keyboards, nor do mobile devices once they're head-mounted as VR gear. Virtual keyboards inside VR are not very useful, and they're certainly useless for chat. So voice chat seems the only option. Luckily, there's an open source chat server called [OpenVidu][20]. I made my server talk to that server so that people can chat with each other.
|
||||
|
||||
Last but not least, security. Embedding a script into a JSON string is trivial, and to prevent cross-site scripting attacks, the server must, at a minimum, sanitize each and every incoming request.
|
||||
|
||||
![VRSpace architecture][21]
|
||||
|
||||
(Josip Almasi, [CC BY-SA 4.0][7])
|
||||
|
||||
### Wide-open virtual spaces
|
||||
|
||||
People need open spaces every once in a while, just to keep their sanity. Prisoners get at least an hour outside every day. NASA expects astronauts to be able to endure long periods of confinement. But ordinary people just can't stand being inside all the time.
|
||||
|
||||
I've been rather confined for months now, but VR to the rescue! Making a virtual space requires spending endless hours trying out different models and backgrounds and doing much more testing. For physical and mental health, it's not as good as the real stuff, but it's good enough to keep people sane.
|
||||
|
||||
![VRSpace.org virtual worlds][22]
|
||||
|
||||
VRSpace.org virtual worlds created by [farhad.Guli][23], [anthwolf][24], [fenixman12][25], [ShadowTan][26], [Binkley-Spacetrucker][27], and [exima113][28] (Josip Almasi, [CC BY-SA 4.0][7])
|
||||
|
||||
Now that I've written the server, my kids can finally play hide and seek together in any virtual world they choose, with my wife and me alongside them—two VR headsets, a PC, and a mobile, all playing together. So far, we can only play hide and seek because there are not any other games yet. We started playing a "make a game" game; so far, we have a game map, the first level, and of course, zombies.
|
||||
|
||||
But what's the point of having software that nobody uses? My first VR server was not widely used, but it was used by people all over the world. I remember some students in Korea and a girl in Uruguay sitting on her daddy's lap, enchanted by dolphins flying through a virtual replica of a far-away city.
|
||||
|
||||
But my best memory is being told, "programmers like you are benefactors of humanity." This is what open source is all about: benefiting humanity. Not just me, not just my family, not just paying customers, not just my company, but anybody, anywhere and possibly everybody, everywhere.
|
||||
|
||||
And that is why I wrote that VR server again and [published it on GitHub][2].
|
||||
|
||||
### Get involved
|
||||
|
||||
I'm running a [demo server][29] of the current code, available to anyone anonymously. I installed a [Redmine][30] server on it; it has a wiki, forums, bug reports, and everything, so if you want to collaborate or just get in touch, see you [there][31] and on [GitHub][2]!
|
||||
|
||||
I also made a [YouTube channel][32] for demos and tutorials and made a few movies (with another open source tool called [Shotcut][33]). [This video][34] explains all of the project's features at a glance. And I made a [Facebook page][35] because literally everybody knows about Facebook.
|
||||
|
||||
I hope to see you in the virtual worlds, so stay safe and have fun!
|
||||
|
||||
Mozilla's MozVR is a new technology that combines the open web and virtual reality, enabling...
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/20/12/virtual-reality-server
|
||||
|
||||
作者:[Josip Almasi][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/jalmasi
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/innovation_virtual_gadgets_device_drone.png?itok=JTAgRb-1 (new techie gadgets representing innovation)
|
||||
[2]: https://github.com/jalmasi/vrspace
|
||||
[3]: https://opensource.com/sites/default/files/uploads/vrspace.png (VRSpace.org)
|
||||
[4]: https://sketchfab.com/gileon
|
||||
[5]: https://sketchfab.com/hong227
|
||||
[6]: https://www.linkedin.com/in/jasna-almasi/
|
||||
[7]: https://creativecommons.org/licenses/by-sa/4.0/
|
||||
[8]: https://www.w3.org/TR/webxr/
|
||||
[9]: https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document
|
||||
[10]: https://www.w3.org/TR/webxr/#xrwebgllayer-interface
|
||||
[11]: https://github.com/EricEisaman/cs1-engine
|
||||
[12]: https://en.wikipedia.org/wiki/GlTF
|
||||
[13]: http://old.vrspace.org/
|
||||
[14]: https://en.wikipedia.org/wiki/VRML
|
||||
[15]: https://opensource.com/sites/default/files/uploads/vrspace_old.jpg (Old VRSpace)
|
||||
[16]: https://www.facebook.com/arni.barisic
|
||||
[17]: https://spring.io/projects/spring-boot
|
||||
[18]: https://www.babylonjs.com/
|
||||
[19]: https://neo4j.com/
|
||||
[20]: https://openvidu.io/
|
||||
[21]: https://opensource.com/sites/default/files/uploads/vrspace_architecture.png (VRSpace architecture)
|
||||
[22]: https://opensource.com/sites/default/files/uploads/virtualworlds.png (VRSpace.org virtual worlds)
|
||||
[23]: https://sketchfab.com/farhad.Guli
|
||||
[24]: https://sketchfab.com/anthmurphy
|
||||
[25]: https://sketchfab.com/fenixman12
|
||||
[26]: https://sketchfab.com/ShadowTan
|
||||
[27]: https://sketchfab.com/Binkley-Piratepants
|
||||
[28]: https://sketchfab.com/Exima113
|
||||
[29]: http://www.vrspace.org/
|
||||
[30]: https://redmine.org/
|
||||
[31]: https://redmine.vrspace.org/
|
||||
[32]: https://www.youtube.com/channel/UCLdSg22i9MZ3u7ityj_PBxw
|
||||
[33]: https://shotcut.org/
|
||||
[34]: https://vrdays.co/videos/vrspace-org-diy-multiuser-vr-for-the-web/
|
||||
[35]: https://www.facebook.com/vrspace.org
|
@ -1,185 +0,0 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (3 Ways to Install Deb Files on Ubuntu Linux)
|
||||
[#]: via: (https://itsfoss.com/install-deb-files-ubuntu)
|
||||
[#]: author: (Abhishek Prakash https://itsfoss.com/author/abhishek/)
|
||||
|
||||
3 Ways to Install Deb Files on Ubuntu Linux
|
||||
======
|
||||
|
||||
**This beginner article explains how to install deb packages in Ubuntu. It also shows you how to remove those deb packages afterwards.**
|
||||
|
||||
This is another article in the Ubuntu beginner series. If you are absolutely new to Ubuntu, you might wonder about [how to install applications][1].
|
||||
|
||||
The easiest way is to use the Ubuntu Software Center. Search for an application by its name and install it from there.
|
||||
|
||||
Life would be too simple if you could find all the applications in the Software Center. But that does not happen, unfortunately.
|
||||
|
||||
Some software are available via DEB packages. These are archived files that end with .deb extension.
|
||||
|
||||
You can think of .deb files as the .exe files in Windows. You double click on the .exe file and it starts the installation procedure in Windows. DEB packages are pretty much the same.
|
||||
|
||||
You can find these DEB packages from the download section of the software provider’s website. For example, if you want to [install Google Chrome on Ubuntu][2], you can download the DEB package of Chrome from its website.
|
||||
|
||||
Now the question arises, how do you install deb files? There are multiple ways of installing DEB packages in Ubuntu. I’ll show them to you one by one in this tutorial.
|
||||
|
||||
![Install deb files in Ubuntu][3]
|
||||
|
||||
### Installing .deb files in Ubuntu and Debian-based Linux Distributions
|
||||
|
||||
You can choose a GUI tool or a command line tool for installing a deb package. The choice is yours.
|
||||
|
||||
Let’s go on and see how to install deb files.
|
||||
|
||||
#### Method 1: Use the default Software Center
|
||||
|
||||
The simplest method is to use the default software center in Ubuntu. You have to do nothing special here. Simply go to the folder where you have downloaded the .deb file (it should be the Downloads folder) and double click on this file.
|
||||
|
||||
![Google Chrome deb file on Ubuntu][4]Double click on the downloaded .deb file to start installation
|
||||
|
||||
It will open the software center and you should see the option to install the software. All you have to do is to hit the install button and enter your login password.
|
||||
|
||||
![Install Google Chrome in Ubuntu Software Center][5]The installation of deb file will be carried out via Software Center
|
||||
|
||||
See, it’s even simple than installing from a .exe files on Windows, isn’t it?
|
||||
|
||||
#### Method 2: Use Gdebi application for installing deb packages with dependencies
|
||||
|
||||
Again, life would be a lot simpler if things always go smooth. But that’s not life as we know it.
|
||||
|
||||
Now that you know that .deb files can be easily installed via Software Center, let me tell you about the dependency error that you may encounter with some packages.
|
||||
|
||||
What happens is that a program may be dependent on another piece of software (libraries). When the developer is preparing the DEB package for you, he/she may assume that your system already has that piece of software on your system.
|
||||
|
||||
But if that’s not the case and your system doesn’t have those required pieces of software, you’ll encounter the infamous ‘dependency error’.
|
||||
|
||||
The Software Center cannot handle such errors on its own so you have to use another tool called [gdebi][6].
|
||||
|
||||
gdebi is a lightweight GUI application that has the sole purpose of installing deb packages.
|
||||
|
||||
It identifies the dependencies and tries to install these dependencies along with installing the .deb files.
|
||||
|
||||
![gdebi handling dependency while installing deb package][7]Image Credit: [Xmodulo][8]
|
||||
|
||||
Personally, I prefer gdebi over software center for installing deb files. It is a lightweight application so the installation seems quicker. You can read in detail about [using gDebi and making it the default for installing DEB packages][6].
|
||||
|
||||
You can install gdebi from the software center or using the command below:
|
||||
|
||||
```
|
||||
sudo apt install gdebi
|
||||
```
|
||||
|
||||
#### Method 3: Install .deb files in command line using dpkg
|
||||
|
||||
If you want to install deb packages in command lime, you can use either apt command or dpkg command. Apt command actually uses [dpkg command][9] underneath it but apt is more popular and easy to use.
|
||||
|
||||
If you want to use the apt command for deb files, use it like this:
|
||||
|
||||
```
|
||||
sudo apt install path_to_deb_file
|
||||
```
|
||||
|
||||
If you want to use dpkg command for installing deb packages, here’s how to do it:
|
||||
|
||||
```
|
||||
sudo dpkg -i path_to_deb_file
|
||||
```
|
||||
|
||||
In both commands, you should replace the path_to_deb_file with the path and name of the deb file you have downloaded.
|
||||
|
||||
![Install deb files using dpkg command in Ubuntu][10]Installing deb files using dpkg command in Ubuntu
|
||||
|
||||
If you get a dependency error while installing the deb packages, you may use the following command to fix the dependency issues:
|
||||
|
||||
```
|
||||
sudo apt install -f
|
||||
```
|
||||
|
||||
### How to remove deb packages
|
||||
|
||||
Removing a deb package is not a big deal as well. And no, you don’t need the original deb file that you had used for installing the program.
|
||||
|
||||
#### Method 1: Remove deb packages using apt commands
|
||||
|
||||
All you need is the name of the program that you have installed and then you can use apt or dpkg to remove that program.
|
||||
|
||||
```
|
||||
sudo apt remove program_name
|
||||
```
|
||||
|
||||
Now the question comes, how do you find the exact program name that you need to use in the remove command? The apt command has a solution for that as well.
|
||||
|
||||
You can find the list of all installed files with apt command but manually going through this will be a pain. So you can use the grep command to search for your package.
|
||||
|
||||
For example, I installed AppGrid application in the previous section but if I want to know the exact program name, I can use something like this:
|
||||
|
||||
```
|
||||
sudo apt list --installed | grep grid
|
||||
```
|
||||
|
||||
This will give me all the packages that have grid in their name and from there, I can get the exact program name.
|
||||
|
||||
```
|
||||
apt list --installed | grep grid
|
||||
WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
|
||||
appgrid/now 0.298 all [installed,local]
|
||||
```
|
||||
|
||||
As you can see, a program called appgrid has been installed. Now you can use this program name with the apt remove command.
|
||||
|
||||
#### Method 2: Remove deb packages using dpkg commands
|
||||
|
||||
You can use dpkg to find the installed program’s name:
|
||||
|
||||
```
|
||||
dpkg -l | grep grid
|
||||
```
|
||||
|
||||
The output will give all the packages installed that has grid in its name.
|
||||
|
||||
```
|
||||
dpkg -l | grep grid
|
||||
|
||||
ii appgrid 0.298 all Discover and install apps for Ubuntu
|
||||
```
|
||||
|
||||
ii in the above command output means package has been correctly installed.
|
||||
|
||||
Now that you have the program name, you can use dpkg command to remove it:
|
||||
|
||||
```
|
||||
dpkg -r program_name
|
||||
```
|
||||
|
||||
**Tip: Updating deb packages**
|
||||
Some deb packages (like Chrome) provide updates through system updates but for most other programs, you’ll have to remove the existing program and install the newer version.
|
||||
|
||||
I hope this beginner guide helped you to install deb packages on Ubuntu. I added the remove part so that you’ll have better control over the programs you installed.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://itsfoss.com/install-deb-files-ubuntu
|
||||
|
||||
作者:[Abhishek Prakash][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/abhishek/
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://itsfoss.com/remove-install-software-ubuntu/
|
||||
[2]: https://itsfoss.com/install-chrome-ubuntu/
|
||||
[3]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2019/02/deb-packages-ubuntu.png?resize=800%2C450&ssl=1
|
||||
[4]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2019/01/install-google-chrome-ubuntu-4.jpeg?resize=800%2C347&ssl=1
|
||||
[5]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2019/01/install-google-chrome-ubuntu-5.jpeg?resize=800%2C516&ssl=1
|
||||
[6]: https://itsfoss.com/gdebi-default-ubuntu-software-center/
|
||||
[7]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2019/01/gdebi-handling-dependency.jpg?ssl=1
|
||||
[8]: http://xmodulo.com
|
||||
[9]: https://help.ubuntu.com/lts/serverguide/dpkg.html.en
|
||||
[10]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2019/02/install-deb-file-with-dpkg.png?ssl=1
|
||||
[11]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2019/02/deb-packages-ubuntu.png?fit=800%2C450&ssl=1
|
@ -1,173 +0,0 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (How to Use VLAN tagged NIC (Ethernet Card) on CentOS and RHEL Servers)
|
||||
[#]: via: (https://www.linuxtechi.com/vlan-tagged-nic-ethernet-card-centos-rhel-servers/)
|
||||
[#]: author: (Pradeep Kumar https://www.linuxtechi.com/author/pradeep/)
|
||||
|
||||
How to Use VLAN tagged NIC (Ethernet Card) on CentOS and RHEL Servers
|
||||
======
|
||||
|
||||
There are some scenarios where we want to assign multiple IPs from different **VLAN** on the same Ethernet card (nic) on Linux servers ( **CentOS** / **RHEL** ). This can be done by enabling VLAN tagged interface. But for this to happen first we must make sure multiple VLANs are attached to port on switch or in other words we can say we should configure trunk port by adding multiple VLANs on switch.
|
||||
|
||||
<https://www.linuxtechi.com/wp-content/uploads/2019/06/VLAN-Tagged-NIC-Linux-Server.jpg>
|
||||
|
||||
Let’s assume we have a Linux Server, there we have two Ethernet cards (enp0s3 & enp0s8), first NIC ( **enp0s3** ) will be used for data traffic and second NIC ( **enp0s8** ) will be used for control / management traffic. For Data traffic I will using multiple VLANs (or will assign multiple IPs from different VLANs on data traffic ethernet card).
|
||||
|
||||
I am assuming the port from switch which is connected to my server data NIC is configured as trunk port by mapping the multiple VLANs to it.
|
||||
|
||||
Following are the VLANs which is mapped to data traffic Ethernet Card (NIC):
|
||||
|
||||
* VLAN ID (200), VLAN N/W = 172.168.10.0/24
|
||||
* VLAN ID (300), VLAN N/W = 172.168.20.0/24
|
||||
|
||||
|
||||
|
||||
To use VLAN tagged interface on CentOS 7 / RHEL 7 / CentOS 8 /RHEL 8 systems, [kernel module][1] **8021q** must be loaded.
|
||||
|
||||
Use the following command to load the kernel module “8021q”
|
||||
|
||||
```
|
||||
[root@linuxtechi ~]# lsmod | grep -i 8021q
|
||||
[root@linuxtechi ~]# modprobe --first-time 8021q
|
||||
[root@linuxtechi ~]# lsmod | grep -i 8021q
|
||||
8021q 29022 0
|
||||
garp 14384 1 8021q
|
||||
mrp 18542 1 8021q
|
||||
[root@linuxtechi ~]#
|
||||
```
|
||||
|
||||
Use below modinfo command to display information about kernel module “8021q”
|
||||
|
||||
```
|
||||
[root@linuxtechi ~]# modinfo 8021q
|
||||
filename: /lib/modules/3.10.0-327.el7.x86_64/kernel/net/8021q/8021q.ko
|
||||
version: 1.8
|
||||
license: GPL
|
||||
alias: rtnl-link-vlan
|
||||
rhelversion: 7.2
|
||||
srcversion: 2E63BD725D9DC11C7DA6190
|
||||
depends: mrp,garp
|
||||
intree: Y
|
||||
vermagic: 3.10.0-327.el7.x86_64 SMP mod_unload modversions
|
||||
signer: CentOS Linux kernel signing key
|
||||
sig_key: 79:AD:88:6A:11:3C:A0:22:35:26:33:6C:0F:82:5B:8A:94:29:6A:B3
|
||||
sig_hashalgo: sha256
|
||||
[root@linuxtechi ~]#
|
||||
```
|
||||
|
||||
Now tagged (or mapped) the VLANs 200 and 300 to NIC enp0s3 using the [ip command][2]
|
||||
|
||||
```
|
||||
[root@linuxtechi ~]# ip link add link enp0s3 name enp0s3.200 type vlan id 200
|
||||
```
|
||||
|
||||
Bring up the interface using below ip command:
|
||||
|
||||
```
|
||||
[root@linuxtechi ~]# ip link set dev enp0s3.200 up
|
||||
```
|
||||
|
||||
Similarly mapped the VLAN 300 to NIC enp0s3
|
||||
|
||||
```
|
||||
[root@linuxtechi ~]# ip link add link enp0s3 name enp0s3.300 type vlan id 300
|
||||
[root@linuxtechi ~]# ip link set dev enp0s3.300 up
|
||||
[root@linuxtechi ~]#
|
||||
```
|
||||
|
||||
Now view the tagged interface status using ip command:
|
||||
|
||||
[![tagged-interface-ip-command][3]][4]
|
||||
|
||||
Now we can assign the IP address to tagged interface from their respective VLANs using beneath ip command,
|
||||
|
||||
```
|
||||
[root@linuxtechi ~]# ip addr add 172.168.10.51/24 dev enp0s3.200
|
||||
[root@linuxtechi ~]# ip addr add 172.168.20.51/24 dev enp0s3.300
|
||||
```
|
||||
|
||||
Use below ip command to see whether IP is assigned to tagged interface or not.
|
||||
|
||||
![ip-address-tagged-nic][5]
|
||||
|
||||
All the above changes via ip commands will not be persistent across the reboot. These tagged interfaces will not be available after reboot and after network service restart
|
||||
|
||||
So, to make tagged interfaces persistent across the reboot then use interface **ifcfg files**
|
||||
|
||||
Edit interface (enp0s3) file “ **/etc/sysconfig/network-scripts/ifcfg-enp0s3** ” and add the following content,
|
||||
|
||||
Note: Replace the interface name that suits to your env,
|
||||
|
||||
```
|
||||
[root@linuxtechi ~]# vi /etc/sysconfig/network-scripts/ifcfg-enp0s3
|
||||
TYPE=Ethernet
|
||||
DEVICE=enp0s3
|
||||
BOOTPROTO=none
|
||||
ONBOOT=yes
|
||||
```
|
||||
|
||||
Save & exit the file
|
||||
|
||||
Create tagged interface file for VLAN id 200 as “ **/etc/sysconfig/network-scripts/ifcfg-enp0s3.200** ” and add the following contents to it.
|
||||
|
||||
```
|
||||
[root@linuxtechi ~]# vi /etc/sysconfig/network-scripts/ifcfg-enp0s3.200
|
||||
DEVICE=enp0s3.200
|
||||
BOOTPROTO=none
|
||||
ONBOOT=yes
|
||||
IPADDR=172.168.10.51
|
||||
PREFIX=24
|
||||
NETWORK=172.168.10.0
|
||||
VLAN=yes
|
||||
```
|
||||
|
||||
Save & exit the file
|
||||
|
||||
Similarly create interface file for VLAN id 300 as “/etc/sysconfig/network-scripts/ifcfg-enp0s3.300” and add the following contents to it
|
||||
|
||||
```
|
||||
[root@linuxtechi ~]# vi /etc/sysconfig/network-scripts/ifcfg-enp0s3.300
|
||||
DEVICE=enp0s3.300
|
||||
BOOTPROTO=none
|
||||
ONBOOT=yes
|
||||
IPADDR=172.168.20.51
|
||||
PREFIX=24
|
||||
NETWORK=172.168.20.0
|
||||
VLAN=yes
|
||||
```
|
||||
|
||||
Save and exit file and then restart network services using the beneath command,
|
||||
|
||||
```
|
||||
[root@linuxtechi ~]# systemctl restart network
|
||||
[root@linuxtechi ~]#
|
||||
```
|
||||
|
||||
Now verify whether tagged interface are configured and up & running using the ip command,
|
||||
|
||||
![tagged-interface-status-ip-command-linux-server][6]
|
||||
|
||||
That’s all from this article, I hope you got an idea how to configure and enable VLAN tagged interface on CentOS 7 / 8 and RHEL 7 /8 Severs. Please do share your feedback and comments.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.linuxtechi.com/vlan-tagged-nic-ethernet-card-centos-rhel-servers/
|
||||
|
||||
作者:[Pradeep Kumar][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/pradeep/
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://www.linuxtechi.com/how-to-manage-kernel-modules-in-linux/
|
||||
[2]: https://www.linuxtechi.com/ip-command-examples-for-linux-users/
|
||||
[3]: https://www.linuxtechi.com/wp-content/uploads/2019/06/tagged-interface-ip-command-1024x444.jpg
|
||||
[4]: https://www.linuxtechi.com/wp-content/uploads/2019/06/tagged-interface-ip-command.jpg
|
||||
[5]: https://www.linuxtechi.com/wp-content/uploads/2019/06/ip-address-tagged-nic-1024x343.jpg
|
||||
[6]: https://www.linuxtechi.com/wp-content/uploads/2019/06/tagged-interface-status-ip-command-linux-server-1024x656.jpg
|
@ -1,170 +0,0 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (zhangxiangping)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (How I use Python to map the global spread of COVID-19)
|
||||
[#]: via: (https://opensource.com/article/20/4/python-map-covid-19)
|
||||
[#]: author: (AnuragGupta https://opensource.com/users/999anuraggupta)
|
||||
|
||||
How I use Python to map the global spread of COVID-19
|
||||
======
|
||||
Create a color coded geographic map of the potential spread of the virus
|
||||
using these open source scripts.
|
||||
![Globe up in the clouds][1]
|
||||
|
||||
The spread of disease is a real concern for a world in which global travel is commonplace. A few organizations track significant epidemics (and any pandemic), and fortunately, they publish their work as open data. The raw data can be difficult for humans to process, though, and that's why data science is so vital. For instance, it could be useful to visualize the worldwide spread of COVID-19 with Python and Pandas.
|
||||
|
||||
It can be hard to know where to start when you're faced with large amounts of raw data. The more you do it, however, the more patterns begin to emerge. Here's a common scenario, applied to COVID-19 data:
|
||||
|
||||
1. Download COVID-19 country spread daily data into a Pandas DataFrame object from GitHub. For this, you need the Python Pandas library.
|
||||
2. Process and clean the downloaded data and make it suitable for visualizing. The downloaded data (as you will see for yourself) is in quite good condition. The one problem with this data is that it uses the names of countries, but it's better to use three-digit ISO 3 codes. To generate the three-digit ISO 3 codes, use a small Python library called pycountry. Having generated these codes, you can add an extra column to our DataFrame and populate it with these codes.
|
||||
3. Finally, for the visualization, use the **express** module of a library called Plotly. This article uses what are called choropleth maps (available in Plotly) to visualize the worldwide spread of the disease.
|
||||
|
||||
|
||||
|
||||
### Step 1: Corona data
|
||||
|
||||
We will download the latest corona data from:
|
||||
|
||||
<https://raw.githubusercontent.com/datasets/covid-19/master/data/countries-aggregated.csv>
|
||||
|
||||
We will load the data directly into a Pandas DataFrame. Pandas provides a function, **read_csv()**, which can take a URL and return a DataFrame object as shown below:
|
||||
|
||||
|
||||
```
|
||||
import pycountry
|
||||
import plotly.express as px
|
||||
import pandas as pd
|
||||
URL_DATASET = r'<https://raw.githubusercontent.com/datasets/covid-19/master/data/countries-aggregated.csv>'
|
||||
df1 = pd.read_csv(URL_DATASET)
|
||||
print(df1.head(3)) # Get first 3 entries in the dataframe
|
||||
print(df1.tail(3)) # Get last 3 entries in the dataframe
|
||||
```
|
||||
|
||||
The screenshot of output (on Jupyter) is:
|
||||
|
||||
![Jupyter screenshot][2]
|
||||
|
||||
From output, you can see that the DataFrame (df1) has the following columns:
|
||||
|
||||
1. Date
|
||||
2. Country
|
||||
3. Confirmed
|
||||
4. Recovered
|
||||
5. Dead
|
||||
|
||||
|
||||
|
||||
Further, you can see that the **Date** column has entries starting from January 22 to March 31. This database is updated daily, so you will get the current values.
|
||||
|
||||
### Step 2: Cleaning and modifying the data frame
|
||||
|
||||
We need to add another column to this DataFrame, which has the three-letter ISO alpha-3 codes. To do this, I followed these steps:
|
||||
|
||||
1. Create a list of all countries in the database. This was required because in the **df**, in the column **Country**, each country was figuring for each date. So in effect, the **Country** column had multiple entries for each country. To do this, I used the **unique().tolist()** functions.
|
||||
2. Then I took a dictionary **d_country_code** (initially empty) and populated it with keys consisting of country names and values consisting of their three-letter ISO codes.
|
||||
3. To generate the three-letter ISO code for a country, I used the function **pycountry.countries.search_fuzzy(country)**. You need to understand that the return value of this function is a "list of **Country** objects." I passed the return value of this function to a name country_data. Further, in this list of objects, the first object i.e., at index 0, is the best fit. Further, this **\** object has an attribute **alpha_3**. So, I can "access" the 3 letter ISO code by using **country_data[0].alpha_3**. However, it is possible that some country names in the DataFrame may not have a corresponding ISO code (For example, disputed territories). So, for such countries, I gave an ISO code of "i.e. a blank string. Further, you need to wrap this code in a try-except block. The statement: **print(_‘could not add ISO 3 code for ->'_, country)** will give a printout of those countries for which the ISO 3 codes could not be found. In fact, you will find such countries as shown with white color in the final output.
|
||||
4. Having got the three-letter ISO code for each country (or an empty string for some), I added the country name (as key) and its corresponding ISO code (as value) to the dictionary **d_country_code**. For adding these, I used the **update()** method of the Python dictionary object.
|
||||
5. Having created a dictionary of country names and their codes, I added them to the DataFrame using a simple for loop.
|
||||
|
||||
|
||||
|
||||
### Step 3: Visualizing the spread using Plotly
|
||||
|
||||
A choropleth map is a map composed of colored polygons. It is used to represent spatial variations of a quantity. We will use the express module of Plotly conventionally called **px**. Here we show you how to create a choropleth map using the function: **px.choropleth**.
|
||||
|
||||
The signature of this function is:
|
||||
|
||||
|
||||
```
|
||||
`plotly.express.choropleth(data_frame=None, lat=None, lon=None, locations=None, locationmode=None, geojson=None, featureidkey=None, color=None, hover_name=None, hover_data=None, custom_data=None, animation_frame=None, animation_group=None, category_orders={}, labels={}, color_discrete_sequence=None, color_discrete_map={}, color_continuous_scale=None, range_color=None, color_continuous_midpoint=None, projection=None, scope=None, center=None, title=None, template=None, width=None, height=None)`
|
||||
```
|
||||
|
||||
The noteworthy points are that the **choropleth()** function needs the following things:
|
||||
|
||||
1. A geometry in the form of a **geojson** object. This is where things are a bit confusing and not clearly mentioned in its documentation. You may or may not provide a **geojson** object. If you provide a **geojson** object, then that object will be used to plot the earth features, but if you don't provide a **geojson** object, then the function will, by default, use one of the built-in geometries. (In our example here, we will use a built-in geometry, so we won't provide any value for the **geojson** argument)
|
||||
2. A pandas DataFrame object for the attribute **data_frame**. Here we provide our DataFrame ie **df1** we created earlier.
|
||||
3. We will use the data of **Confirmed** column to decide the color of each country polygon.
|
||||
4. Further, we will use the **Date** column to create the **animation_frame**. Thus as we slide across the dates, the colors of the countries will change as per the values in the **Confirmed** column.
|
||||
|
||||
|
||||
|
||||
The complete code is given below:
|
||||
|
||||
|
||||
```
|
||||
import pycountry
|
||||
import plotly.express as px
|
||||
import pandas as pd
|
||||
# ----------- Step 1 ------------
|
||||
URL_DATASET = r'<https://raw.githubusercontent.com/datasets/covid-19/master/data/countries-aggregated.csv>'
|
||||
df1 = pd.read_csv(URL_DATASET)
|
||||
# print(df1.head) # Uncomment to see what the dataframe is like
|
||||
# ----------- Step 2 ------------
|
||||
list_countries = df1['Country'].unique().tolist()
|
||||
# print(list_countries) # Uncomment to see list of countries
|
||||
d_country_code = {} # To hold the country names and their ISO
|
||||
for country in list_countries:
|
||||
try:
|
||||
country_data = pycountry.countries.search_fuzzy(country)
|
||||
# country_data is a list of objects of class pycountry.db.Country
|
||||
# The first item ie at index 0 of list is best fit
|
||||
# object of class Country have an alpha_3 attribute
|
||||
country_code = country_data[0].alpha_3
|
||||
d_country_code.update({country: country_code})
|
||||
except:
|
||||
print('could not add ISO 3 code for ->', country)
|
||||
# If could not find country, make ISO code ' '
|
||||
d_country_code.update({country: ' '})
|
||||
|
||||
# print(d_country_code) # Uncomment to check dictionary
|
||||
|
||||
# create a new column iso_alpha in the df
|
||||
# and fill it with appropriate iso 3 code
|
||||
for k, v in d_country_code.items():
|
||||
df1.loc[(df1.Country == k), 'iso_alpha'] = v
|
||||
|
||||
# print(df1.head) # Uncomment to confirm that ISO codes added
|
||||
# ----------- Step 3 ------------
|
||||
fig = px.choropleth(data_frame = df1,
|
||||
locations= "iso_alpha",
|
||||
color= "Confirmed", # value in column 'Confirmed' determines color
|
||||
hover_name= "Country",
|
||||
color_continuous_scale= 'RdYlGn', # color scale red, yellow green
|
||||
animation_frame= "Date")
|
||||
|
||||
fig.show()
|
||||
```
|
||||
|
||||
The output is something like the following:
|
||||
|
||||
![Map][3]
|
||||
|
||||
You can download and run the [complete code][4].
|
||||
|
||||
To wrap up, here are some excellent resources on choropleth in Plotly:
|
||||
|
||||
* <https://github.com/plotly/plotly.py/blob/master/doc/python/choropleth-maps.md>
|
||||
* [https://plotly.com/python/reference/#choropleth][5]
|
||||
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/20/4/python-map-covid-19
|
||||
|
||||
作者:[AnuragGupta][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[zhangxiangping](https://github.com/zxp93)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/999anuraggupta
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/cloud-globe.png?itok=_drXt4Tn (Globe up in the clouds)
|
||||
[2]: https://opensource.com/sites/default/files/uploads/jupyter_screenshot.png (Jupyter screenshot)
|
||||
[3]: https://opensource.com/sites/default/files/uploads/map_2.png (Map)
|
||||
[4]: https://github.com/ag999git/jupyter_notebooks/blob/master/corona_spread_visualization
|
||||
[5]: tmp.azs72dmHFd#choropleth
|
@ -1,113 +0,0 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (How the Linux kernel handles interrupts)
|
||||
[#]: via: (https://opensource.com/article/20/10/linux-kernel-interrupts)
|
||||
[#]: author: (Stephan Avenwedde https://opensource.com/users/hansic99)
|
||||
|
||||
How the Linux kernel handles interrupts
|
||||
======
|
||||
Interrupts are a crucial part of how computers process data.
|
||||
![Penguin driving a car with a yellow background][1]
|
||||
|
||||
Interrupts are an essential part of how modern CPUs work. For example, every time you press a key on the keyboard, the CPU is interrupted so that the PC can read user input from the keyboard. This happens so quickly that you don't notice any change or impairment in user experience.
|
||||
|
||||
Moreover, the keyboard is not the only component that can cause interrupts. In general, there are three types of events that can cause the CPU to interrupt: _Hardware interrupts_, _software interrupts_, and _exceptions_. Before getting into the different types of interrupts, I'll define some terms.
|
||||
|
||||
### Definitions
|
||||
|
||||
An interrupt request (**IRQ**) is requested by the programmable interrupt controller (**PIC**) with the aim of interrupting the CPU and executing the interrupt service routine (**ISR**). The ISR is a small program that processes certain data depending on the cause of the IRQ. Normal processing is interrupted until the ISR finishes.
|
||||
|
||||
In the past, IRQs were handled by a separate microchip—the PIC—and I/O devices were wired directly to the PIC. The PIC managed the various hardware IRQs and could talk directly to the CPU. When an IRQ occurred, the PIC wrote the data to the CPU and raised the interrupt request (**INTR**) pin.
|
||||
|
||||
Nowadays, IRQs are handled by an advanced programmable interrupt controller (**APIC**), which is part of the CPU. Each core has its own APIC.
|
||||
|
||||
### Types of interrupts
|
||||
|
||||
As I mentioned, interrupts can be separated into three types depending on their source:
|
||||
|
||||
#### Hardware interrupts
|
||||
|
||||
When a hardware device wants to tell the CPU that certain data is ready to process (e.g., a keyboard entry or when a packet arrives at the network interface), it sends an IRQ to signal the CPU that the data is available. This invokes a specific ISR that was registered by the device driver during the kernel's start.
|
||||
|
||||
#### Software interrupts
|
||||
|
||||
When you're playing a video, it is essential to synchronize the music and video playback so that the music's speed doesn't vary. This is accomplished through a software interrupt that is repetitively fired by a precise timer system (known as [jiffies][2]). This timer enables your music player to synchronize. A software interrupt can also be invoked by a special instruction to read or write data to a hardware device.
|
||||
|
||||
Software interrupts are also crucial when real-time capability is required (such as in industrial applications). You can find more information about this in the Linux Foundation's article _[Intro to real-time Linux for embedded developers][3]_.
|
||||
|
||||
#### Exceptions
|
||||
|
||||
Exceptions are the type of interrupt that you probably know about. When the CPU executes a command that would result in division by zero or a page fault, any additional execution is interrupted. In such a case, you will be informed about it by a pop-up window or by seeing **segmentation fault (core dumped)** in the console output. But not every exception is caused by a faulty instruction.
|
||||
|
||||
Exceptions can be further divided into _Faults_, _Traps_, and _Aborts_.
|
||||
|
||||
* **Faults:** Faults are an exception that the system can correct, e.g., when a process tries to access data from a memory page that was swapped to the hard drive. The requested address is within the process address space, and the access rights are correct. If the page is not present in RAM, an IRQ is raised and it starts the **page fault exception handler** to load the desired memory page into RAM. If the operation is successful, execution will continue.
|
||||
* **Traps:** Traps are mainly used for debugging. If you set a breakpoint in a program, you insert a special instruction that causes it to trigger a trap. A trap can trigger a context switch that allows your debugger to read and display values of local variables. Execution can continue afterward. Traps are also the default way to execute system calls (like killing a process).
|
||||
* **Aborts:** Aborts are caused by hardware failure or inconsistent values in system tables. An abort does not report the location of the instruction that causes the exception. These are the most critical interrupts. An abort invokes the system's **abort exception handler**, which terminates the process that caused it.
|
||||
|
||||
|
||||
|
||||
### Get hands-on
|
||||
|
||||
IRQs are ordered by priority in a vector on the APIC (0=highest priority). The first 32 interrupts (0–31) have a fixed sequence that is specified by the CPU. You can find an overview of them on [OsDev's Exceptions][4] page. Subsequent IRQs can be assigned differently. The interrupt descriptor table (**IDT**) contains the assignment between IRQ and ISR. Linux defines an IRQ vector from 0 to 256 for the assignment.
|
||||
|
||||
To print a list of registered interrupts on your system, open a console and type:
|
||||
|
||||
|
||||
```
|
||||
`cat /proc/interrupts`
|
||||
```
|
||||
|
||||
You should see something like this:
|
||||
|
||||
![Registered interrupts list][5]
|
||||
|
||||
Registered interrupts in kernel version 5.6.6 (Stephan Avenwedde, [CC BY-SA 4.0][6])
|
||||
|
||||
From left to right, the columns are: IRQ vector, interrupt count per CPU (`0 .. n`), the hardware source, the hardware source's channel information, and the name of the device that caused the IRQ.
|
||||
|
||||
On the bottom of the table, there are some non-numeric interrupts. They are the architecture-specific interrupts, like the local timer interrupt (**LOC**) on IRQ 236. Some of them are specified in the [Linux IRQ vector layout][7] in the Linux kernel source tree.
|
||||
|
||||
![Architecture-specific interrupts][8]
|
||||
|
||||
Architecture-specific interrupts (Stephan Avenwedde, [CC BY-SA 4.0][6])
|
||||
|
||||
To get a live view of this table, run:
|
||||
|
||||
|
||||
```
|
||||
`watch -n1 "cat /proc/interrupts"`
|
||||
```
|
||||
|
||||
### Conclusion
|
||||
|
||||
Proper IRQ handling is essential for the proper interaction of hardware, drivers, and software. Luckily, the Linux kernel does a really good job, and a normal PC user will hardly notice anything about the kernel's entire interrupt handling.
|
||||
|
||||
This can get very complicated, and this article gives only a brief overview of the topic. Good sources of information for a deeper dive into the subject are the _[Linux Inside][9]_ eBook (CC BY-NC-SA 4.0) and the [Linux Kernel Teaching][10] repository.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/20/10/linux-kernel-interrupts
|
||||
|
||||
作者:[Stephan Avenwedde][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/hansic99
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/car-penguin-drive-linux-yellow.png?itok=twWGlYAc (Penguin driving a car with a yellow background)
|
||||
[2]: https://elinux.org/Kernel_Timer_Systems
|
||||
[3]: https://www.linuxfoundation.org/blog/2013/03/intro-to-real-time-linux-for-embedded-developers/
|
||||
[4]: https://wiki.osdev.org/Exceptions
|
||||
[5]: https://opensource.com/sites/default/files/uploads/proc_interrupts_1.png (Registered interrupts list)
|
||||
[6]: https://creativecommons.org/licenses/by-sa/4.0/
|
||||
[7]: https://github.com/torvalds/linux/blob/master/arch/x86/include/asm/irq_vectors.h
|
||||
[8]: https://opensource.com/sites/default/files/uploads/proc_interrupts_2.png (Architecture-specific interrupts)
|
||||
[9]: https://0xax.gitbooks.io/linux-insides/content/Interrupts/
|
||||
[10]: https://linux-kernel-labs.github.io/refs/heads/master/lectures/interrupts.html#
|
@ -1,138 +0,0 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (robsean)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (How to Write, Compile and Run a C Program in Ubuntu and Other Linux Distributions [Beginner’s Tip])
|
||||
[#]: via: (https://itsfoss.com/run-c-program-linux/)
|
||||
[#]: author: (Abhishek Prakash https://itsfoss.com/author/abhishek/)
|
||||
|
||||
How to Write, Compile and Run a C Program in Ubuntu and Other Linux Distributions [Beginner’s Tip]
|
||||
======
|
||||
|
||||
How do you program in C on Linux? It is indeed very easy and consists of three simple steps.
|
||||
|
||||
**Step 1**: You write your program and save the file with a .c extension. For example, my_program.c.
|
||||
|
||||
**Step 2**: You compile the program and generate the object file using gcc compiler in a terminal like this:
|
||||
|
||||
```
|
||||
gcc -o my_program my_program.c
|
||||
```
|
||||
|
||||
**Step 3**: You run the generated object file to run your C program in Linux:
|
||||
|
||||
```
|
||||
./my_program
|
||||
```
|
||||
|
||||
![][1]
|
||||
|
||||
This was just the quick summary on how to compile and run C program in Linux. If you are new to either C or Linux, I’ll show these steps in detail so that you feel comfortable coding C program in Linux environment.
|
||||
|
||||
In fact, I’ll discuss how to run C programs in Linux terminal as well as in code editor.
|
||||
|
||||
![][2]
|
||||
|
||||
### Method 1: How to run C programs in Linux terminal
|
||||
|
||||
In order to run a C program in Linux, you need to have a C compiler present on your systems. The most popular compiler is gcc ([GNU Compiler Collection][3]).
|
||||
|
||||
You can install gcc using your distribution’s package manager. In Debian and Ubuntu-based Linux distributions, use the apt command:
|
||||
|
||||
```
|
||||
sudo apt install gcc
|
||||
```
|
||||
|
||||
Switch to directory where you have kept your C program (or provide the path) and then generate the object file by compiling the program:
|
||||
|
||||
```
|
||||
gcc -o my_program my_program.c
|
||||
```
|
||||
|
||||
Keep in mind that it is optional to provide the output object file (-o my_program). If you won’t do that, an object file named a.out will be automatically generated. But this is not good because it will be overwritten for each C program and you won’t be able to know which program the a.out object file belongs to.
|
||||
|
||||
Once you have your object file generated, run it to run the C program. It is already executable. Simple use it like this:
|
||||
|
||||
```
|
||||
./my_program
|
||||
```
|
||||
|
||||
And it will display the desired output, if your program is correct. As you can see, this is not very different from [running C++ programs in Linux][4].
|
||||
|
||||
_**Every time you make a change in your program, you have to compile it first and then run the generated object file to run the C program.**_
|
||||
|
||||
### Method 2: How to run C programs in Linux using a code editor like Visual Studio Code
|
||||
|
||||
Not everyone is comfortable with command line and terminal and I totally understand that.
|
||||
|
||||
You can use a proper C/C++ IDE like Eclipse or Code Blocks but they are often too heavy programs and more suitable for large projects.
|
||||
|
||||
I recommend using an open source code editor like Visual Studio Code or Atom. These are basically text editors and you can install add-ons to compile and run programs directly from the graphical code editor.
|
||||
|
||||
I am using [Visual Studio Code editor][5] in this example. It’s a hugely [popular open source code editor][6] from Microsoft.
|
||||
|
||||
First thing first, [install Visual Studio Code in Ubuntu][7] from the software center. For other distributions, please check your Linux distribution’s package manager or software center. You may also check the official website for more information.
|
||||
|
||||
Start Visual Studio Code and open/create a project and create your C program here. I am using a sample Hello World program.
|
||||
|
||||
![][8]
|
||||
|
||||
You must ensure that you have gcc compiler installed on your Linux system.
|
||||
|
||||
```
|
||||
sudo apt install gcc
|
||||
```
|
||||
|
||||
Next thing you would want is to use an extension that allows you to run the C code. Microsoft may prompt you for installing its own extension for C/C++ program but it is complicated to setup and hence I won’t recommend it.
|
||||
|
||||
Instead, I suggest using the Code Runner extension. It’s a no-nonsense extension and you can run C and C++ code easily without additional configuration.
|
||||
|
||||
Go to the Extensions tab and search for ‘Code Runner’ and install it.
|
||||
|
||||
![Install Code Runner extension for running C/C++ program][9]
|
||||
|
||||
Restart Visual Studio Code. Now, you should be able to run the C code by using one of the following way:
|
||||
|
||||
* Using the shortcut Ctrl+Alt+N.
|
||||
* Press F1 and then select or type Run Code.
|
||||
* Right click the text editor and the click Run code from context menu.
|
||||
|
||||
|
||||
|
||||
![Right click the program file and choose Run Code][10]
|
||||
|
||||
When you run the program, it is compiled automatically and then run. You can see the output in terminal that is opened at the bottom of the editor. What could be better than this?
|
||||
|
||||
![Program output is displayed in the bottom section of the editor][11]
|
||||
|
||||
Which method do you prefer?
|
||||
|
||||
Running a few C programs in Linux command line is okay but using a code editor is much easier and saves time. Won’t you agree?
|
||||
|
||||
I let you decide whichever method you want to use.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://itsfoss.com/run-c-program-linux/
|
||||
|
||||
作者:[Abhishek Prakash][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/abhishek/
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2020/11/running-c-program-linux.png?resize=795%2C399&ssl=1
|
||||
[2]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2020/11/Run-C-Program-Linux.png?resize=800%2C450&ssl=1
|
||||
[3]: https://gcc.gnu.org/
|
||||
[4]: https://itsfoss.com/c-plus-plus-ubuntu/
|
||||
[5]: https://code.visualstudio.com
|
||||
[6]: https://itsfoss.com/best-modern-open-source-code-editors-for-linux/
|
||||
[7]: https://itsfoss.com/install-visual-studio-code-ubuntu/
|
||||
[8]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2020/11/c-program-visual-studio-code-linux.png?resize=800%2C441&ssl=1
|
||||
[9]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2020/11/running-c-program-in-linux-with-visual-studio-code.png?resize=800%2C500&ssl=1
|
||||
[10]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2020/11/running-c-program-in-linux-with-visual-studio-code.jpg?resize=800%2C500&ssl=1
|
||||
[11]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2020/11/run-c-program-in-linux-with-visual-studio-code.jpg?resize=800%2C500&ssl=1
|
@ -1,95 +0,0 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Why I love Emacs)
|
||||
[#]: via: (https://opensource.com/article/20/12/emacs)
|
||||
[#]: author: (Seth Kenlon https://opensource.com/users/seth)
|
||||
|
||||
Why I love Emacs
|
||||
======
|
||||
Emacs isn't a mere text editor; it places you in control and allows you
|
||||
to solve nearly any problem you encounter.
|
||||
![Emoji keyboard][1]
|
||||
|
||||
I'm a habitual [Emacs][2] user. I didn't choose Emacs as much as it chose me. Back when I was first learning about Unix, I stumbled upon a little-known feature in a strange application called Emacs, which was apparently hidden away on my computer. Legend had it (and was proven true) that if you typed `emacs` into a terminal, pressed **Alt**+**X**, and typed `tetris`, you could play a falling-blocks game.
|
||||
|
||||
![Tetris in Emacs][3]
|
||||
|
||||
That was my introduction to GNU Emacs. While it was frivolous, it was also an accurate indication of what Emacs is all about—the idea that users can reprogram their (virtual) worlds and do _whatever_ they want with an application. Playing Tetris in your text editor is probably not your primary goal on an everyday basis, but it goes to show that Emacs is, proudly, a programming platform. In fact, you might think of it as a kind of precursor to [Jupyter][4], combining a powerful programming language (called `elisp`, to be exact) with its own live environment. As a consequence, Emacs is flexible as a text editor, customizable, and powerful.
|
||||
|
||||
Elisp (and Common Lisp, by extension) aren't necessarily the easiest languages to start out on, if you're used to Bash or Python or similar languages. But LISP dialects are powerful, and because Emacs is a LISP interpreter, you can build applications, whether they're Emacs plugins or prototypes of something you want to develop into a stand-alone project. The wildly popular [org-mode project][5] is just one example: it's an Emacs plugin as well as a markdown syntax with mobile apps to interpret and extend its capabilities. There are many examples of similarly useful applications-within-Emacs, including an email client, a PDF viewer, web browser, a shell, and a file manager.
|
||||
|
||||
### Two interfaces
|
||||
|
||||
GNU Emacs has at least two user interfaces: a graphical user interface (GUI) and a terminal user interface (TUI). This sometimes surprises people because Emacs is often pitted against Vi, which runs in a terminal (although gVim provides a GUI for a modern Vi implementation). If you want to run GNU Emacs as a terminal application, you can launch it with the `-nw` option:
|
||||
|
||||
|
||||
```
|
||||
`$ emacs -nw`
|
||||
```
|
||||
|
||||
With a GUI, you can just launch Emacs from your application menu or a terminal.
|
||||
|
||||
You might think that a GUI renders Emacs less effective, as if "real text editors run in a terminal," but a GUI can make Emacs easier to learn because its GUI follows some typical conventions (a menu bar, adjustable widgets, mouse interaction, and so on).
|
||||
|
||||
In fact, if you run Emacs as a GUI application, you can probably get through the day without noticing you're in Emacs at all. Most of the usual conventions apply, as long as you use the GUI. For instance, you can select text with your mouse, navigate to the **Edit** menu, select **Copy**, and then place your cursor elsewhere and select **Paste**. To save a document, you can go to **File** and **Save** or **Save As**. You can press **Ctrl** and scroll up to make your screen font larger, you can use the scroll bar to navigate through your document, and so on.
|
||||
|
||||
Getting to know Emacs in its GUI form is a great way to flatten the learning curve.
|
||||
|
||||
### Emacs keyboard shortcuts
|
||||
|
||||
GNU Emacs is infamous for complex keyboard combinations. They're not only unfamiliar (**Alt**+**W** to copy? **Ctrl**+**Y** to paste?), they're also notated with arcane terminology ("Alt" is called "Meta"), and sometimes they come in pairs (**Ctrl**+**X** followed by **Ctrl**+**S** to save) and other times alone (**Ctrl**+**S** to search). Why would anyone willfully choose to use this?
|
||||
|
||||
Well, some don't. But those who do are fans of how these combinations easily flow into the rhythm of everyday typing (and often have the **Caps Lock** key serve as a **Ctrl** key). Those who prefer something different, however, have several options.
|
||||
|
||||
* The `evil` mode lets you use Vim keybindings in Emacs. It's that simple: You get to keep the key combinations you've committed to muscle memory, and you inherit the most powerful text editor available.
|
||||
* Common User Access (CUA) keys keep all of the usual Emacs key combinations but the most jarring ones—copy, cut, paste, and undo—are all mapped to their modern bindings (**Ctrl**+**C**, **Ctrl**+**X**, **Ctrl**+**V**, and **Ctrl**+**Z**, respectively).
|
||||
* The `global-set-key` function, part of the programming side of Emacs, allows you to define your own keyboard shortcuts. Traditionally, user-defined shortcuts start with **Ctrl**+**C**, but nothing is stopping you from inventing your own scheme. Emacs isn't precious of its own identity. You're welcome to bend it to your will.
|
||||
|
||||
|
||||
|
||||
### Learn Emacs
|
||||
|
||||
It takes time to get very good with Emacs. For me, that meant printing out a [cheat sheet][6] and keeping it next to my keyboard all day, every day. When I forgot a key combo, I looked it up on my cheat sheet. If it wasn't on my cheat sheet, I learned the keyboard combo, either by executing the function and noting how Emacs told me I could access it quicker or by using `describe-function`:
|
||||
|
||||
|
||||
```
|
||||
M-x describe-function: save-buffer
|
||||
|
||||
save-buffer is an interactive compiled Lisp function in ‘files.el’.
|
||||
|
||||
It is bound to C-x C-s, <menu-bar> <file> <save-buffer>.
|
||||
[...]
|
||||
```
|
||||
|
||||
As you use it, you learn it. And the more you learn about it, the more empowered you become to improve it and make it your own.
|
||||
|
||||
### Try Emacs
|
||||
|
||||
It's a common joke to say that Emacs is an operating system with a text editor included. Maybe that's meant to insinuate Emacs is bloated and overly complex, and there's certainly an argument that a text editor shouldn't require `libpoppler` according to its default configuration (you can compile Emacs without it).
|
||||
|
||||
But there's a greater truth lurking behind this joke, and it reveals a lot about what makes Emacs so fun. It doesn't make sense to compare Emacs to other text editors, like Vim, Nano, or even [VSCodium][7], because the really important part of Emacs isn't the idea that you can type stuff into a window and save it. That's basic functionality that even Bash provides. The true significance of Emacs is how it places you in control and how, through Emacs Lisp ([Elisp][8]), nearly any problem can be solved.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/20/12/emacs
|
||||
|
||||
作者:[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/emoji-keyboard.jpg?itok=JplrSZ9c (Emoji keyboard)
|
||||
[2]: https://en.wikipedia.org/wiki/Emacs
|
||||
[3]: https://opensource.com/sites/default/files/tetris.png (Tetris in Emacs)
|
||||
[4]: https://opensource.com/article/20/11/surprising-jupyter
|
||||
[5]: https://opensource.com/article/19/1/productivity-tool-org-mode
|
||||
[6]: https://opensource.com/downloads/emacs-cheat-sheet
|
||||
[7]: https://opensource.com/article/20/6/open-source-alternatives-vs-code
|
||||
[8]: https://www.gnu.org/software/emacs/manual/html_node/elisp/
|
@ -1,98 +0,0 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Get the most out of the Vi text editor)
|
||||
[#]: via: (https://opensource.com/article/20/12/vi-text-editor)
|
||||
[#]: author: (Seth Kenlon https://opensource.com/users/seth)
|
||||
|
||||
Get the most out of the Vi text editor
|
||||
======
|
||||
Vi is the quintessential Unix text editor. Get to know it—or any of its
|
||||
incarnations, Vim, Neovim, gVim, nvi, or Elvis, for Linux, macOS,
|
||||
Windows, or BSD.
|
||||
![Business woman on laptop sitting in front of window][1]
|
||||
|
||||
Whether you know it as Vim, Neovim, gVim, nvi, or even Elvis, the quintessential Unix editor is easily Vi. Included in probably every Linux and BSD distribution, Vi is a lightweight and minimalist text editor that many users love for its simple and succinct keyboard shortcuts and dual-mode design.
|
||||
|
||||
The original Vi editor was an application written by Bill Joy, creator of the [C shell][2]. Modern incarnations of Vi have [added many features][3], including multiple levels of undo, better navigation while in insert mode, line folding, syntax highlighting, plugin support, and much more. Vim is regarded as the most popular modern implementation, and most people actually mean Vim when they refer to Vi.
|
||||
|
||||
All incarnations hearken back to the same goal, though, so this article looks at Vi in a generic sense. The implementation on your computer may differ slightly, but you can still benefit from editing text the Vi way.
|
||||
|
||||
### Install Vi
|
||||
|
||||
If you're running Linux, macOS, or BSD, then you already have the `vi` command installed. If you're on Windows, you can [download Vim and gVim][4].
|
||||
|
||||
![gVim][5]
|
||||
|
||||
(Seth Kenlon, [CC BY-SA 4.0][6])
|
||||
|
||||
On [NetBSD][7], nvi is a common alternative to Vi, while Slackware provides [Elvis][8] (and Vim), and the popular [Neovim][9] fork aims to help users extend Vim with [Lua][10].
|
||||
|
||||
### Launch Vi
|
||||
|
||||
Start Vi or Vim with the `vi` command in a terminal. If a `.vimrc` file is not found on your system, then Vim starts in Vi-compatibility mode (this can also be forced with the `-C` option). If you want to use gVim to have a graphical user interface (GUI), you can start it from your desktop's application menu.
|
||||
|
||||
If you're a new user just learning Vi, using a graphical user interface can be a nice way to provide yourself a buffer between how you might _expect_ a text editor to behave and how Vi was designed to behave. The GUI version has a menu bar, some mouse integration, a toolbar, and other features to help you find the basic functions you probably take for granted in a typical text editor but don't know how to do in Vi yet.
|
||||
|
||||
### How to use Vi
|
||||
|
||||
Probably the easiest way to learn Vi is with `vimtutor`, an interactive tutorial packaged with Vim. To start the tutorial, launch `vimtutor` and read through the instructions, trying each exercise. As the tutorial says, getting good with Vi is less about memorizing what key does what and more about establishing muscle memory to invoke common actions as you type.
|
||||
|
||||
#### Escape
|
||||
|
||||
One of the first things you learn about Vi is the importance of the **Esc** key. **Esc** is what activates _command mode_, and it doesn't take long to learn that whenever you're in doubt in Vi, just press **Esc**. Any key you press while in command mode is not entered into the text document you're working on; instead, it is interpreted by Vi as a command. For instance, to move your cursor left, you press the **H** key on your keyboard. If you're in _insert_ mode, then pressing **H** types the letter H, just as you'd expect. But in _command_ mode, pressing **H** moves left, **L** moves right, **J** moves down, and **K** moves up.
|
||||
|
||||
The separation between command mode and insert mode is a sharp contrast to the way any other text editor works, and for that reason, it's probably Vi's most significant differentiator. Interestingly, though, it's theoretically not so different from the way you probably already work. After all, when you take your hands off the keyboard to select text with a mouse, you're essentially placing yourself into a kind of command mode. With Vi, instead of moving your hands off the keyboard to move the mouse and press function keys or Ctrl, you put the _editor_ into a special mode of operation, such that it reassigns your key presses to commands instead of text input.
|
||||
|
||||
#### Extend Vi
|
||||
|
||||
Before Vim version 8.0, Vi was very much "just" a text editor. There were plugins for it, but installing them was a manual process that many users never thought to do. Luckily, Vim version 8 and higher offer support for plugin management, making it trivial to install and load plugins.
|
||||
|
||||
Installing plugins for Vim can be done with the `vim-plug` function. For instance, to install the Vi file browser [NERDTree][11]:
|
||||
|
||||
|
||||
```
|
||||
`:PlugInstall NERDTree`
|
||||
```
|
||||
|
||||
You can also update plugins:
|
||||
|
||||
|
||||
```
|
||||
`:PlugUpdate NERDTree`
|
||||
```
|
||||
|
||||
For more information on installing plugins and themes, both with `vim-plug` and manually, read my article [_How to install Vim plugins_][12].
|
||||
|
||||
### Vi as default
|
||||
|
||||
Vi isn't just popular; it's a [POSIX][13] standard. It's an application every sysadmin should know how to use, even if they don't intend to use it on an everyday basis. It's also a fast and simple editor, so once you get good at it, it may be the editor you've long been searching for.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/20/12/vi-text-editor
|
||||
|
||||
作者:[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/lenovo-thinkpad-laptop-concentration-focus-windows-office.png?itok=-8E2ihcF (Woman using laptop concentrating)
|
||||
[2]: https://opensource.com/article/20/8/tcsh
|
||||
[3]: https://vimhelp.org/vi_diff.txt.html#vi-differences
|
||||
[4]: https://www.vim.org/download.php
|
||||
[5]: https://opensource.com/sites/default/files/uploads/gvim.jpg (gVim)
|
||||
[6]: https://creativecommons.org/licenses/by-sa/4.0/
|
||||
[7]: https://opensource.com/article/19/3/netbsd-raspberry-pi
|
||||
[8]: https://github.com/mbert/elvis
|
||||
[9]: http://neovim.io
|
||||
[10]: https://opensource.com/article/20/2/lua-cheat-sheet
|
||||
[11]: https://www.vim.org/scripts/script.php?script_id=1658
|
||||
[12]: https://opensource.com/article/20/2/how-install-vim-plugins
|
||||
[13]: https://opensource.com/article/19/7/what-posix-richard-stallman-explains
|
@ -1,117 +0,0 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (geekpi)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Experience the useful features of the Xedit text editor)
|
||||
[#]: via: (https://opensource.com/article/20/12/xedit)
|
||||
[#]: author: (Seth Kenlon https://opensource.com/users/seth)
|
||||
|
||||
Experience the useful features of the Xedit text editor
|
||||
======
|
||||
Xedit, part of the X11 graphic server, isn't much to look at but has
|
||||
enough hidden features to make it a serious text editor.
|
||||
![Computer screen with files or windows open][1]
|
||||
|
||||
The X11 graphic server, distributed by [X.org][2], has a few token applications that show how to program with its provided tools. These range from the [TWM][3] desktop to the silly but hypnotic Xeyes. It also includes a text editor called Xedit, a seemingly simple application with enough hidden features to make it a serious editor.
|
||||
|
||||
### Install Xedit
|
||||
|
||||
If you're on Linux or BSD, you can install Xedit from your distribution's software repository or ports tree. It sometimes appears in a package called X11-apps bundled with other X11 apps.
|
||||
|
||||
On macOS, you can install [XQuartz][4], which provides Xedit, Xeyes, and a few other small applications (along with an X11 graphics server).
|
||||
|
||||
### Launch Xedit
|
||||
|
||||
You can launch Xedit from your application menu, if it's listed. Some distributions treat it more as a command than a GUI app, even though it is definitely a GUI app, so it may not be listed in your application menu. In that case, you can launch Xedit from the terminal. If you type `xedit &` to launch the application, it launches an empty Xedit editor ready for text. If you enter the launch command along with an existing file's name, Xedit starts with the file loaded into its buffer:
|
||||
|
||||
|
||||
```
|
||||
`$ xedit example.txt &`
|
||||
```
|
||||
|
||||
![Xedit][5]
|
||||
|
||||
(Seth Kenlon, [CC BY-SA 4.0][6])
|
||||
|
||||
### Load a file
|
||||
|
||||
From an open Xedit instance, you can load a file by typing the file's path in the top text field. Click the **Load** button (to the left of the text field) to read the file into the Xedit window.
|
||||
|
||||
![Load Xedit][7]
|
||||
|
||||
(Seth Kenlon, [CC BY-SA 4.0][6])
|
||||
|
||||
You can have several files open at once. When one file is loaded, it takes focus and appears in your main Xedit buffer (the big text field in the main window) and shuffles any existing file into a hidden buffer.
|
||||
|
||||
You can navigate between buffers using a key combo familiar to Emacs users but sometimes confusing to others: First, press **Ctrl+X**. Release those keys, and then press **Ctrl+B**.
|
||||
|
||||
### Key combos
|
||||
|
||||
It feels strange at first to perform actions that require _two_ keyboard shortcuts in a row, but after a while, you get used to it. In fact, as a frequent Emacs user, I find the compound key combinations comfortingly rhythmic. I was surprised and pleased to find that some of my favorite shortcuts were valid in Xedit.
|
||||
|
||||
It turns out that Xedit borrows keyboard shortcuts from several sources of inspiration. If you're an Emacs user, you'll find that the most common combinations are valid in Xedit. For instance, **C-x** **C-f** (that's **Ctrl+X** followed **Ctrl+F**) takes you to the top text field to load a file, and **C-x** **C-s** (**Ctrl+X** followed by **Ctrl+S**) saves a file. Surprisingly, **C-x** **3** even splits the window vertically, while **C-x** **2** splits it horizontally, and **C-x** **0** or **1** removes the split.
|
||||
|
||||
Edit commands familiar to Emacs or Bash users also apply:
|
||||
|
||||
* **Ctrl+A** moves to the beginning of a line.
|
||||
* **Ctrl+E** moves to the end of a line.
|
||||
* **Alt+B** moves back a word.
|
||||
* **Ctrl+B** moves back a character.
|
||||
* **Ctrl+F** moves forward a character.
|
||||
* **Alt+F** moves forward a word.
|
||||
* **Ctrl+D** deletes the next character.
|
||||
|
||||
|
||||
|
||||
There are many more, and they're listed on the Xedit man page.
|
||||
|
||||
### Use line-editing mode
|
||||
|
||||
Xedit also includes a line editor, similar to **ex**, which ought to be familiar to [Vi][8] and `ed` or even `sed` users. To enter line-editing mode, press the **Esc** key. This places you in the top text field but in a command mode. Edit commands use the syntax: _line number_ followed by a _command_ and _parameters_.
|
||||
|
||||
Say you have this text file:
|
||||
|
||||
|
||||
```
|
||||
ed is the standard Unix text editor.
|
||||
This is line number two.
|
||||
```
|
||||
|
||||
You decide you want to change `ed` to `Xedit` in line 1. In Xedit, move to line 1, press **Esc**, and then type `.,s/ed/Xedit/`.
|
||||
|
||||
|
||||
```
|
||||
Xedit is the standard Unix text editor.
|
||||
This is line number two.
|
||||
```
|
||||
|
||||
Without moving your cursor to the next line, you could change `two` to `the second`: Press **Esc** and then type `2,s/two/the second/`.
|
||||
|
||||
Possible commands and valid parameters are listed in Xedit's man page.
|
||||
|
||||
### Simple but robust
|
||||
|
||||
Xedit isn't much to look at. It's simple, it has no menus to speak of, but it borrows some popular conveniences from some of the best Unix editors. The next time you're looking for a new editor, try Xedit.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/20/12/xedit
|
||||
|
||||
作者:[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/browser_screen_windows_files.png?itok=kLTeQUbY (Computer screen with files or windows open)
|
||||
[2]: https://www.x.org/wiki/
|
||||
[3]: https://opensource.com/article/19/12/twm-linux-desktop
|
||||
[4]: http://xquartz.org
|
||||
[5]: https://opensource.com/sites/default/files/uploads/xedit.jpeg (Xedit)
|
||||
[6]: https://creativecommons.org/licenses/by-sa/4.0/
|
||||
[7]: https://opensource.com/sites/default/files/uploads/xedit-load.jpg (Load Xedit)
|
||||
[8]: https://opensource.com/article/20/12/vi-text-editor
|
@ -1,126 +0,0 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Learn Bash by writing an interactive game)
|
||||
[#]: via: (https://opensource.com/article/20/12/learn-bash)
|
||||
[#]: author: (Jim Hall https://opensource.com/users/jim-hall)
|
||||
|
||||
Learn Bash by writing an interactive game
|
||||
======
|
||||
Programming a simple game is a great way to practice a new language and
|
||||
compare it against others you know.
|
||||
![bash logo on green background][1]
|
||||
|
||||
Learning a new programming language can be fun. Whenever I try to learn a new one, I focus on defining variables, writing a statement, and evaluating expressions. Once I have a general understanding of those concepts, I can usually figure out the rest on my own. Most programming languages have some similarities, so once you know one programming language, learning the next one is a matter of figuring out the unique details and recognizing the differences in it.
|
||||
|
||||
To help me practice a new programming language, I like to write a few test programs. One sample program I often write is a simple "guess the number" program, where the computer picks a number between one and 100 and asks me to guess the number. The program loops until I guess correctly.
|
||||
|
||||
The "guess the number" program exercises several concepts in programming languages: how to assign values to variables, how to write statements, and how to perform conditional evaluation and loops. It's a great practical experiment for learning a new programming language.
|
||||
|
||||
### Guess the number in Bash
|
||||
|
||||
[Bash][2] is the standard shell for most Linux systems. Aside from providing a rich command-line user interface, Bash also supports a complete programming language in the form of _scripts_.
|
||||
|
||||
If you're not familiar with Bash, I recommend these introductions:
|
||||
|
||||
* [What is Bash?][3]
|
||||
* [Get started with Bash programming][4]
|
||||
* [Get started with Bash scripting for sysadmins][5]
|
||||
* [How to write functions in Bash][6]
|
||||
* [Read more about Bash][7]
|
||||
|
||||
|
||||
|
||||
You can explore Bash by writing a version of the "guess the number" game. Here is my implementation:
|
||||
|
||||
|
||||
```
|
||||
#!/bin/bash
|
||||
|
||||
number=$(( $RANDOM % 100 + 1 ))
|
||||
|
||||
echo "Guess a number between 1 and 100"
|
||||
|
||||
guess=0
|
||||
|
||||
while [ "0$guess" -ne $number ] ; do
|
||||
read guess
|
||||
[ "0$guess" -lt $number ] && echo "Too low"
|
||||
[ "0$guess" -gt $number ] && echo "Too high"
|
||||
done
|
||||
|
||||
echo "That's right!"
|
||||
exit 0
|
||||
```
|
||||
|
||||
### Breaking down the script
|
||||
|
||||
The first line in the script, `#!/bin/bash` tells Linux to run this script using the Bash shell. Every script starts with the `#!` character pair, which indicates this is a shell script. What immediately follows `#!` is the shell to run. In this case, `/bin/bash` is the Bash shell.
|
||||
|
||||
To assign a value to a variable, list the variable's name followed by the `=` sign. For example, the statement `guess=0` assigns a zero value to the `guess` variable.
|
||||
|
||||
You can also prompt the user to enter a value using the `read` statement. If you write `read guess`, Bash waits for the user to enter some text then stores that value in the `guess` variable.
|
||||
|
||||
To reference the value of a variable, use `$` before the variable name. So, having stored a value in the `guess` variable, you can retrieve it using `$guess`.
|
||||
|
||||
You can use whatever names you like for variables, but Bash reserves a few special variable names for itself. One special variable is `RANDOM`, which generates a very large random number every time you reference it.
|
||||
|
||||
If you want to perform an operation at the same time you store a value, you need to enclose the statement in special brackets. This tells Bash to execute that statement first, and the `=` stores the resulting value in the variable. To evaluate a mathematical expression, use `$(( ))` around your statement. The double parentheses indicate an _arithmetic expression_. In my example, `number=$(( $RANDOM % 100 + 1 ))` evaluates the expression `$RANDOM % 100 + 1` and then stores the value in the `number` variable.
|
||||
|
||||
Standard arithmetic operators such as `+` (plus), `-` (minus), `*` (multiply), `/` (divide), and `%` (modulo) apply.
|
||||
|
||||
That means the statement `number=$(( $RANDOM % 100 + 1 ))` generates a random number between one and 100. The modulo operator (`%`) returns the _remainder_ after dividing two numbers. In this case, Bash divides a random number by 100, leaving a remainder in the range zero to 99. By adding one to that value, you get a random number between one and 100.
|
||||
|
||||
Bash supports _conditional expressions_ and _flow control_ like loops. In the "guess the number" game, Bash continues looping as long as the value in `guess` is not equal to `number`. If the guess is less than the random number, Bash prints "Too low," and if the guess is greater than the number, Bash prints "Too high."
|
||||
|
||||
### How it works
|
||||
|
||||
Now that you've written your Bash script, you can run it to play the "guess the number" game. Continue guessing until you find the correct number:
|
||||
|
||||
|
||||
```
|
||||
Guess a number between 1 and 100
|
||||
50
|
||||
Too high
|
||||
30
|
||||
Too high
|
||||
20
|
||||
Too high
|
||||
10
|
||||
Too low
|
||||
15
|
||||
Too high
|
||||
13
|
||||
Too low
|
||||
14
|
||||
That's right!
|
||||
```
|
||||
|
||||
Every time you run the script, Bash will pick a different random number.
|
||||
|
||||
This "guess the number" game is a great introductory program when learning a new programming language because it exercises several common programming concepts in a pretty straightforward way. By implementing this simple game in different programming languages, you can demonstrate some core concepts and compare details in each language.
|
||||
|
||||
Do you have a favorite programming language? How would you write the "guess the number" game in it? Follow this article series to see examples of other programming languages that might interest you.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/20/12/learn-bash
|
||||
|
||||
作者:[Jim Hall][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/jim-hall
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/bash_command_line.png?itok=k4z94W2U (bash logo on green background)
|
||||
[2]: https://en.wikipedia.org/wiki/Bash_(Unix_shell)
|
||||
[3]: https://opensource.com/resources/what-bash
|
||||
[4]: https://opensource.com/article/20/4/bash-programming-guide
|
||||
[5]: https://opensource.com/article/20/4/bash-sysadmins-ebook
|
||||
[6]: https://opensource.com/article/20/6/bash-functions
|
||||
[7]: https://opensource.com/tags/bash
|
@ -1,70 +0,0 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Make medit your next Linux terminal text editor)
|
||||
[#]: via: (https://opensource.com/article/20/12/medit)
|
||||
[#]: author: (Seth Kenlon https://opensource.com/users/seth)
|
||||
|
||||
Make medit your next Linux terminal text editor
|
||||
======
|
||||
This classic text editor offers all the basics and some exciting extra
|
||||
features that let you customize your experience.
|
||||
![Person drinking a hot drink at the computer][1]
|
||||
|
||||
There’s [XEDIT][2], jEdit, NEdit, [gedit][3], and, as it turns out, [medit][4].
|
||||
|
||||
I had not heard about medit until I started searching for editors I hadn’t yet tried, but I’m glad to have discovered it. If you’re looking for a classic gedit experience (circa Gnome 2), then medit is, probably unintentionally, an excellent and modern approximation. It’s also got many additional features, such as the ability to write plugins in Python, Lua, or C, and a means to integrate even shell scripts into its menu system. All the other usual features are here, too—a tabbed interface, an on-demand shell, indentation management, syntax highlighting, and so on.
|
||||
|
||||
### Installing medit
|
||||
|
||||
You can download medit from [mooedit.sourceforge.net][5]. It’s confirmed to work on Linux and Windows. If you’re using Linux, you may also find it in your repository. I installed my copy from [slackbuilds.org][6] on Slackware.
|
||||
|
||||
![Medit terminal showing examples of Bash script in editor][7]
|
||||
|
||||
### Using medit
|
||||
|
||||
Medit advertises itself as an editor "for programming and around programming," and in fact, started its life out as part of a larger project called [GAP (Groups, Algorithms, Programming)][8]. Most of its features are aimed at typical developer expectations. For instance, in the **Edit** menu, there are options to increase and decrease indentation, a common task for any programmer trying to indicate scope visually (and a literal requirement for Python programmers), and options to comment or uncomment blocks of text.
|
||||
|
||||
Some features can be useful for general users, too. Medit has an easy-to-use tabbed interface (both at the top of the window and as a pop-up list along the side), a side panel for quick filesystem browsing, the ability to bookmark places in a file, and so on. It also has syntax highlighting for both programming languages, as well as markup and markdown languages, so it’s a useful editor for code and prose alike.
|
||||
|
||||
### Color schemes
|
||||
|
||||
When editing plain text with no syntax associated with it or a format like Asciidoc, for which medit has no preset highlighting scheme, the editor assumes your system default. I use a dark theme, so medit displays white text on a dark gray background.
|
||||
|
||||
For syntax highlighting, though, the text becomes colorful depending on the part each word plays in its structured language. At first, I was a little frustrated at some of the choices medit made; many of the colors were too dark against my dark background to be legible, and I didn’t feel that all the important elements were unique enough. The answer to this problem, should you disagree with medit’s choices, is in **Preferences**, where you can change the color theme. I changed mine to the Tango colors, which rendered a solarized color array that stood out nicely against my dark editor background and even added color to elements that were kept white under the medit theme.
|
||||
|
||||
![Medit terminal showing examples of Bash script in editor using Tango color scheme against dark background][9]
|
||||
|
||||
### Pop-up Python
|
||||
|
||||
At the bottom of the medit window, there’s a pop-up terminal for quick access to a shell. This is a nice feature, but frankly, after you’ve experienced Emacs and [Kate][10], it feels pretty common. What surprised me about medit was its pop-up Python console, which launches from the **Tools** menu with **moo** and **gtk** modules pre-imported. In other words, when you launch medit’s Python shell, you can look through the Python and GTK modules that medit itself is partly built upon. It’s a great feature and one that might inspire you to write a plugin (the Terminal pop-up is a plugin written in Python, so you can also look through its code to get a feel for how a plugin is written).
|
||||
|
||||
### Classic editing
|
||||
|
||||
Medit is a great GTK-based editor with all the important basic features and several tantalizing extras to help inspire you to extend the application and make it your own. As it accepts C, Python, Lua, and Bash, there are several entry points for doing just that. If you’re looking for a no-nonsense editor for your writing, whether it’s code or markdown or something in between, give medit a chance.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/20/12/medit
|
||||
|
||||
作者:[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/coffee_tea_laptop_computer_work_desk.png?itok=D5yMx_Dr (Person drinking a hot drink at the computer)
|
||||
[2]: https://opensource.com/article/20/12/xedit
|
||||
[3]: https://opensource.com/article/20/12/gedit
|
||||
[4]: http://mooedit.sourceforge.net/
|
||||
[5]: https://sourceforge.net/projects/mooedit/files/medit/
|
||||
[6]: https://slackbuilds.org/repository/14.2/development/medit
|
||||
[7]: https://opensource.com/sites/default/files/uploads/medit-31_days_medit-opensource.png (Medit terminal showing examples of Bash script in editor)
|
||||
[8]: https://www.gap-system.org/
|
||||
[9]: https://opensource.com/sites/default/files/uploads/medit-tango-colour-31_days_medit-opensource.png (Medit terminal showing examples of Bash script in editor using Tango color scheme against dark background)
|
||||
[10]: https://opensource.com/article/20/12/kate-text-editor
|
@ -1,67 +0,0 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Why Java developers love the jEdit text editor)
|
||||
[#]: via: (https://opensource.com/article/20/12/jedit)
|
||||
[#]: author: (Seth Kenlon https://opensource.com/users/seth)
|
||||
|
||||
Why Java developers love the jEdit text editor
|
||||
======
|
||||
This editor packs the power of Java and offers plenty of plugins to
|
||||
streamline your workflow.
|
||||
![Person drinking a hot drink at the computer][1]
|
||||
|
||||
Java is a powerful language. Maybe because it’s often seen as an "industrial-strength" tool, you might not expect it to be the foundation of a text editor. After all, text editing is almost too easy for such power. In fact, in most modern programming toolkits, the component accepting text entry is a pre-programmed widget. Using a Java toolkit, a simple text editor can be written in about 100 lines of code. So what can [jEdit][2] possibly offer to justify its existence?
|
||||
|
||||
Well, quite a lot, actually! The jEdit application is a refreshing reminder of just how practical and useful Java can be for even everyday desktop apps. It deftly demonstrates the dynamism of its foundational technology, and ever true to Java’s enduring promise, it does so on _all_ platforms.
|
||||
|
||||
### Installing jEdit
|
||||
|
||||
jEdit is written in Java, so it’s available for any platform. [Download it][3] in a generic installer or in a custom installer for the OS of choice. Once it’s downloaded (it’s small, so it won’t take long), run the installer.
|
||||
|
||||
If you don’t have Java installed, learn how to install Java on [Linux][4], [Mac, or Windows][5].
|
||||
|
||||
### Using jEdit
|
||||
|
||||
The way you edit text in jEdit is the same as editing text in any desktop text editor. If you’ve used one, you’ve basically used jEdit; all the common keyboard shortcuts and conventions apply. There are also some features commonly aimed at coders—line numbering, folding (in which sections of text are hidden so you can focus on other sections), and syntax highlighting.
|
||||
|
||||
But imagine, for a moment, text editors on a spectrum from [Vim simplicity][6] to [Emacs complexity][7], and you’ll find jEdit happily making its home alongside Emacs. While the editing component is typical of any desktop editing app, jEdit’s additional features include plugins, macros that you can record live during your editing session, features specific to certain editing modes, buffer options, and more. This is an editor that actively encourages you to make it your own.
|
||||
|
||||
There are three places you can go for jEdit customization: buffer options, global options, and the plugins manager.
|
||||
|
||||
Buffer options (in the Utilities menu) allow you to adjust settings associated with your current document. Usually, jEdit auto-detects the appropriate mode to use for what you’re doing. For instance, writing XML triggers jEdit’s XML highlighting. Sometimes, though, you want to override what jEdit has detected or failed to detect. You can also turn on Explicit Folding mode, which allows you to manually define sections of text you want jEdit to treat as foldable sections.
|
||||
|
||||
Global options (in the Utilities menu) offer dozens of preferences that get treated as jEdit’s defaults. This can include anything from its appearance to custom shortcuts.
|
||||
|
||||
Plugins extend jEdit in ways its developers, literally, never intended. Plugins offer ways of working that just aren’t "normal" for jEdit, but that just might transform a laborious task into something easy or even fun. It practically transformed XML workflow with its excellent XML parsing, its _Outline_ plugin available for its dockable _Sidekick_ panel, and XSLT integration. If I were not already using Netbeans for Java code, I can imagine using jEdit instead.
|
||||
|
||||
### jEdit for programmers
|
||||
|
||||
Which text editor you choose depends on what you intend to do in your editor. This one calls itself the "programmer’s text editor," and I feel it’s a very strong contender for serious Java and XML work. However, it doesn’t have quite the same feature set when editing Lua code and Bash scripts. Compared to something like Emacs, for instance, jEdit’s code folding is less flexible (I couldn’t get it to fold a Lua function without additional markup). While it does have a rich plugin selection, I was unable to find anything particularly persuasive for work in AsciiDoc and other non-code formats.
|
||||
|
||||
The most appealing feature of jEdit, for me, is its foundation in Java. Because it runs in a JVM, you can be confident that you can use it regardless of your platform and possibly regardless of whether you have permission to install applications outside your own home directory. Java is a popular and active language, so jEdit’s features and plugins are well-maintained.
|
||||
|
||||
You should try jEdit if you’re a fan of consistency, or a Java developer, or just an XML geek trying desperately to get out of oXygen. It’s easy to get started, and it’s a lot of fun to explore.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/20/12/jedit
|
||||
|
||||
作者:[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/coffee_tea_laptop_computer_work_desk.png?itok=D5yMx_Dr (Person drinking a hot drink at the computer)
|
||||
[2]: http://jedit.org
|
||||
[3]: http://www.jedit.org/index.php?page=download
|
||||
[4]: https://opensource.com/article/19/11/install-java-linux
|
||||
[5]: http://adoptopenjdk.org
|
||||
[6]: https://opensource.com/article/20/12/vi-text-editor
|
||||
[7]: https://opensource.com/article/20/12/emacs
|
@ -0,0 +1,246 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Practice coding in Java by writing a game)
|
||||
[#]: via: (https://opensource.com/article/20/12/learn-java)
|
||||
[#]: author: (Seth Kenlon https://opensource.com/users/seth)
|
||||
|
||||
Practice coding in Java by writing a game
|
||||
======
|
||||
Writing simple games is a fun way to learn a new programming language.
|
||||
Put that principle to work to get started with Java.
|
||||
![Learning and studying technology is the key to success][1]
|
||||
|
||||
My article about [learning different programming languages][2] lists five things you need to understand when starting a new language. An important part of learning a language, of course, is knowing what you intend to do with it.
|
||||
|
||||
I've found that simple games are both fun to write and useful in exploring a language's abilities. In this article, I demonstrate how to create a simple guessing game in Java.
|
||||
|
||||
### Install Java
|
||||
|
||||
To do this exercise, you must have Java installed. If you don't have it, check out these links to install Java on [Linux][3], [macOS, or Windows][4].
|
||||
|
||||
After installing it, run this Java command in a terminal to confirm the version you installed:
|
||||
|
||||
|
||||
```
|
||||
`$ java -version`
|
||||
```
|
||||
|
||||
### Guess the number
|
||||
|
||||
This "guess the number" program exercises several concepts in programming languages: how to assign values to variables, how to write statements, and how to perform conditional evaluation and loops. It's a great practical experiment for learning a new programming language.
|
||||
|
||||
Here's my Java implementation:
|
||||
|
||||
|
||||
```
|
||||
package com.example.guess;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.Scanner;
|
||||
|
||||
class Main {
|
||||
private static final [Random][5] r = new [Random][5]();
|
||||
private static final int NUMBER = r.nextInt(100) + 1;
|
||||
private static int guess = 0;
|
||||
|
||||
public static void main([String][6][] args) {
|
||||
Scanner player = new Scanner([System][7].in);
|
||||
[System][7].out.println("number is " + [String][6].valueOf(NUMBER)); //DEBUG
|
||||
while ( guess != NUMBER ) {
|
||||
// prompt player for guess
|
||||
[System][7].out.println("Guess a number between 1 and 100");
|
||||
guess = player.nextInt();
|
||||
if ( guess > NUMBER ) {
|
||||
[System][7].out.println("Too high");
|
||||
} else if ( guess < NUMBER ) {
|
||||
[System][7].out.println("Too low");
|
||||
} else {
|
||||
[System][7].out.println("That's right!");
|
||||
[System][7].exit(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
That's about 20 lines of code, excluding whitespace and trailing braces. Structurally, however, there's a lot going on, which I'll break down here.
|
||||
|
||||
#### Package declaration
|
||||
|
||||
The first line, `package com.example.guess`, is not strictly necessary in a simple one-file application like this, but it's a good habit to get into. Java is a big language, and new Java is written every day, so every Java project needs to have a unique identifier to help programmers tell one library from another.
|
||||
|
||||
When writing Java code, you should declare a `package` it belongs to. The format for this is usually a reverse domain name, such as `com.opensource.guess` or `org.slf4j.Logger`. As usual for Java, this line is terminated by a semicolon.
|
||||
|
||||
#### Import statements
|
||||
|
||||
The next lines of the code are import statements, which tell the Java compiler what libraries to load when building the executable application. The libraries I use here are distributed along with OpenJDK, so you don't need to download them yourself. Because they're not strictly a part of the core language, you do need to list them for the compiler.
|
||||
|
||||
The Random library provides access to pseudo-random number generation, and the Scanner library lets you read user input in a terminal.
|
||||
|
||||
#### Java class
|
||||
|
||||
The next part creates a Java class. Java is an object-oriented programming language, so its quintessential construct is a _class_. There are some very specific code ideas suggested by a class, and if you're new to programming, you'll pick up on them with practice. For now, think of a class as a box into which you place variables and code instructions, almost as if you were building a machine. The parts you place into the class are unique to that class, and because they're contained in a box, they can't be seen by other classes. More importantly, since there is only one class in this sample game, a class is self-sufficient: It contains everything it needs to perform its particular task. In this case, its task is the whole game, but in larger applications, classes often work together in a sort of daisy-chain to produce complex jobs.
|
||||
|
||||
In Java, each file generally contains one class. The class in this file is called `Main` to signify that it's the entry-point for this application. In a single-file application such as this, the significance of a main class is difficult to appreciate, but in a larger Java project with dozens of classes and source files, marking one `Main` is helpful. And anyway, it's easy to package up an application for distribution with a main class defined.
|
||||
|
||||
#### Java fields
|
||||
|
||||
In Java, as in C and C++, you must declare variables before using them. You can define "fields" at the top of a Java class. The word "field" is just a fancy term for a variable, but it specifically refers to a variable assigned to a class rather than one embedded somewhere in a function.
|
||||
|
||||
This game creates three fields: Two to generate a pseudo-random number, and one to establish an initial (and always incorrect) guess. The long string of keywords (`private static final`) leading up to each field may look confusing (especially when starting out with Java), but using a good IDE like Netbeans or Eclipse can help you navigate the best choice.
|
||||
|
||||
It's important to understand them, too. A _private_ field is one that's available only to its own class. If another class tries to access a private field, the field may as well not exist. In a one-class application such as this one, it makes sense to use private fields.
|
||||
|
||||
A _static_ field belongs to the class itself and not to a class instance. This doesn't make much difference in a small demo app like this because only one instance of the class exists. In a larger application, you may have a reason to define or redefine a variable each time a class instance is spawned.
|
||||
|
||||
A _final_ field cannot have its value changed. This application demonstrates this perfectly: The random number never changes during the game (a moving target wouldn't be very fair), while the player's guess _must_ change or the game wouldn't be winnable. For that reason, the random number established at the beginning of the game is final, but the guess is not.
|
||||
|
||||
#### Pseudo-random numbers
|
||||
|
||||
Two fields create the random number that serves as the player's target. The first creates an instance of the `Random` class. This is essentially a random seed from which you can draw a pretty unpredictable number. To do this, list the class you're invoking followed by a variable name of your choice, which you set to a new instance of the class: `Random r = new Random();`. Like other Java statements, this terminates with a semicolon.
|
||||
|
||||
To draw a number, you must create another variable using the `nextInt()` method of Java. The syntax looks a little different, but it's similar: You list the kind of variable you're creating, you provide a name of your choice, and then you set it to the results of some action: `int NUMBER = r.nextInt(100) + 1;`. You can (and should) look at the documentation for specific methods, like `nextInt()`, to learn how they work, but in this case, the integer drawn from the `r` random seed is limited _up to_ 100 (that is, a maximum of 99). Adding 1 to the result ensures that a number is never 0 and the functional maximum is 100.
|
||||
|
||||
Obviously, the decision to disqualify any number outside of the 1 to 100 range is a purely arbitrary design decision, but it's important to know these constraints before sitting down to program. Without them, it's difficult to know what you're coding toward. If possible, work with a person whose job it is to define the application you're coding. If you have no one to work with, make sure to list your targets first—and only then put on your "coder hat."
|
||||
|
||||
### Main method
|
||||
|
||||
By default, Java looks for a `main` method (or "function," as they're called in many other languages) to run in a class. Not all classes need a main method, but this demo app only has one method, so it may as well be the main one. Methods, like fields, can be made public or private and static or non-static, but the main method must be public and static for the Java compiler to recognize and utilize it.
|
||||
|
||||
### Application logic
|
||||
|
||||
For this application to work as a game, it must continue to run _while_ the player takes guesses at a secret pseudo-random number. Were the application to stop after each guess, the player would only have one guess and would very rarely win. It's also part of the game's design that the computer provides hints to guide the player's next guess.
|
||||
|
||||
A `while` loop with embedded `if` statements achieves this design target. A `while` loop inherently continues to run until a specific condition is met. (In this case, the `guess` variable must equal the `NUMBER` variable.) Each guess can be compared to the target `NUMBER` to prompt helpful hints.
|
||||
|
||||
### Syntax
|
||||
|
||||
The main method starts by creating a new `Scanner` instance. This is the same principle as the `Random` instance used as a pseudo-random seed: You cite the class you want to use as a template, provide a variable name (I use `player` to represent the person entering guesses), and then set that variable to the results of running the class' main method. Again, if you were coding this on your own, you'd look at the class' documentation to get the syntax when using it.
|
||||
|
||||
This sample code includes a debugging statement that reveals the target `NUMBER`. That makes the game moot, but it's useful to prove to yourself that it's working correctly. Even this small debugging statement reveals some important Java tips: `System.out.println` is a print statement, and the `valueOf()` method converts the integer `NUMBER` to a string to print it as part of a sentence rather than an element of math.
|
||||
|
||||
The `while` statement begins next, with the sole condition that the player's `guess` is not equal to the target `NUMBER`. This is an infinite loop that can end only when it's _false_ that `guess` does _not_ equal `NUMBER`.
|
||||
|
||||
In this loop, the player is prompted for a number. The Scanner object, called `player`, takes any valid integer entered by the player and puts its value into the `guess` field.
|
||||
|
||||
The `if` statement compares `guess` to `NUMBER` and responds with `System.out.println` print statements to provide feedback to the human player.
|
||||
|
||||
If `guess` is neither greater than nor less than `NUMBER`, then it must be equal to it. At this point, the game prints a congratulatory message and exits. As usual with [POSIX][8] application design, this game exits with a 0 status to indicate success.
|
||||
|
||||
### Run the game
|
||||
|
||||
To test your game, save the sample code as `Guess.java` and use the Java command to run it:
|
||||
|
||||
|
||||
```
|
||||
$ java ./Guess.java
|
||||
number is 38
|
||||
Guess a number between 1 and 100
|
||||
1
|
||||
Too low
|
||||
Guess a number between 1 and 100
|
||||
39
|
||||
Too high
|
||||
Guess a number between 1 and 100
|
||||
38
|
||||
That's right!
|
||||
$
|
||||
```
|
||||
|
||||
Just as expected!
|
||||
|
||||
### Package the game
|
||||
|
||||
While it isn't as impressive on a single-file application like this as it is on a complex project, Java makes packaging very easy. For the best results, structure your project directory to include a place for your source code, a place for your compiled class, and a manifest file. In practice, this is somewhat flexible, and using an IDE does most of the work for you. It's useful to do it by hand once in a while, though.
|
||||
|
||||
Create a project folder if you haven't already. Then create one directory called `src` to hold your source files. Save the sample code in this article as `src/Guess.java`:
|
||||
|
||||
|
||||
```
|
||||
$ mkdir src
|
||||
$ mv sample.java src/Guess.java
|
||||
```
|
||||
|
||||
Now, create a directory tree that mirrors the name of your Java package, which appears at the very top of your code:
|
||||
|
||||
|
||||
```
|
||||
$ head -n1 src/Guess.java
|
||||
package com.example.guess;
|
||||
$ mkdir -p com/example/guess
|
||||
```
|
||||
|
||||
Create a new file called `Manifest.txt` with just one line of text in it:
|
||||
|
||||
|
||||
```
|
||||
`$ echo "Manifest-Version: 1.0" > Manifest.txt`
|
||||
```
|
||||
|
||||
Next, compile your game into a Java class. This produces a file called `Main.class` in `com/example/guess`:
|
||||
|
||||
|
||||
```
|
||||
$ javac src/Guess.java -d com/example/guess
|
||||
$ ls com/example/guess/
|
||||
Main.class
|
||||
```
|
||||
|
||||
You're all set to package your application into a JAR (Java archive). The `jar` command is a lot like the [tar][9] command, so many of the options may look familiar:
|
||||
|
||||
|
||||
```
|
||||
$ jar cfme Guess.jar \
|
||||
Manifest.txt \
|
||||
com.example.guess.Main \
|
||||
com/example/guess/Main.class
|
||||
```
|
||||
|
||||
From the syntax of the command, you may surmise that it creates a new JAR file called `Guess.jar` with its required manifest data located in `Manifest.txt`. Its main class is defined as an extension of the package name, and the class is `com/example/guess/Main.class`.
|
||||
|
||||
You can view the contents of the JAR file:
|
||||
|
||||
|
||||
```
|
||||
$ jar tvf Guess.jar
|
||||
0 Wed Nov 25 10:33:10 NZDT 2020 META-INF/
|
||||
96 Wed Nov 25 10:33:10 NZDT 2020 META-INF/MANIFEST.MF
|
||||
1572 Wed Nov 25 09:42:08 NZDT 2020 com/example/guess/Main.class
|
||||
```
|
||||
|
||||
And you can even extract it with the `xvf` options.
|
||||
|
||||
Run your JAR file with the `java` command:
|
||||
|
||||
|
||||
```
|
||||
`$ java -jar Guess.jar`
|
||||
```
|
||||
|
||||
Copy your JAR file from Linux to a macOS or Windows computer and try running it. Without recompiling, it runs as expected. This may seem normal if your basis of comparison is, say, a simple Python script that happens to run anywhere, but imagine a complex project with several multimedia libraries and other dependencies. With Java, those dependencies are packaged along with your application, and it _all_ runs on _any_ platform. Welcome to the wonderful world of Java!
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/20/12/learn-java
|
||||
|
||||
作者:[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/studying-books-java-couch-education.png?itok=C9gasCXr (Learning and studying technology is the key to success)
|
||||
[2]: https://opensource.com/article/20/10/learn-any-programming-language
|
||||
[3]: https://opensource.com/article/19/11/install-java-linux
|
||||
[4]: http://adoptopenjdk.org
|
||||
[5]: http://www.google.com/search?hl=en&q=allinurl%3Adocs.oracle.com+javase+docs+api+random
|
||||
[6]: http://www.google.com/search?hl=en&q=allinurl%3Adocs.oracle.com+javase+docs+api+string
|
||||
[7]: http://www.google.com/search?hl=en&q=allinurl%3Adocs.oracle.com+javase+docs+api+system
|
||||
[8]: https://opensource.com/article/19/7/what-posix-richard-stallman-explains
|
||||
[9]: https://opensource.com/article/17/7/how-unzip-targz-file
|
318
sources/tech/20201214 Set up an Ansible lab in 20 minutes.md
Normal file
318
sources/tech/20201214 Set up an Ansible lab in 20 minutes.md
Normal file
@ -0,0 +1,318 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Set up an Ansible lab in 20 minutes)
|
||||
[#]: via: (https://opensource.com/article/20/12/ansible-lab)
|
||||
[#]: author: (Mike Calizo https://opensource.com/users/mcalizo)
|
||||
|
||||
Set up an Ansible lab in 20 minutes
|
||||
======
|
||||
Build an environment to support learning and experimenting with new
|
||||
software.
|
||||
![Science lab with beakers][1]
|
||||
|
||||
Being able to build and tear down a public cloud environment is very useful, but most of us don’t have easy access to a public cloud. The next best thing would be to have a lab on your local machine, but even running on a local machine brings performance, flexibility, and other challenges. Most of the time, the additional workloads on our local machines interfere with doing our daily job, and they certainly prevent having a readily available environment to play and experiment with new software.
|
||||
|
||||
My team and I encountered this challenge a few years ago when we were starting to learn [Ansible][2]. We couldn’t find an environment that we could use individually, and our frustration with the situation caused some of us to stop experimenting. We knew we needed to find a solution.
|
||||
|
||||
We spent a lot of time researching the options and came up with a set of tools that enable our curiosity to learn in an environment we fully control. We can spin up and tear down the lab environment on our local machines without needing access to on-premises labs or public clouds.
|
||||
|
||||
This article will explain how to deploy your own lab environment on your local machine in as little as 20 minutes in a fully automated way.
|
||||
|
||||
You can find all the code for this exercise in my [GitHub repository][3].
|
||||
|
||||
### Tools and software
|
||||
|
||||
This solution uses the following tools and software:
|
||||
|
||||
* [Ansible][4] is our automation tool of choice because it’s easy to use and flexible enough to handle the lab requirements.
|
||||
* [Vagrant][5] is easy to use for building and maintaining virtual machines.
|
||||
* [VirtualBox][6] is a hosted hypervisor that works in Windows and Linux environments.
|
||||
* [Fedora v30+][7] is the operating system on my local machine.
|
||||
|
||||
|
||||
|
||||
You must have the following set up to build the environment:
|
||||
|
||||
* An internet connection
|
||||
* Virtualization Technology support enabled in your BIOS (here is the [procedure][8] for my Lenovo laptop)
|
||||
* Vagrant v2.2.9
|
||||
* The latest version of Ansible
|
||||
* The latest version of VirtualBox
|
||||
* Fedora v30+ host operating system
|
||||
|
||||
|
||||
|
||||
### What’s in the lab environment?
|
||||
|
||||
This project aims to deploy an Ansible host with an Ansible engine and multiple Linux nodes along with some pre-loaded and pre-configured applications (httpd and MySQL). It also enables [Cockpit][9] so that you can monitor the status of the virtual machines (VMs) during testing. The reason to use a pre-deployed application is for efficiency (so you don’t have to spend time installing those components). This allows you to focus on creating roles and playbooks and testing against the environments deployed by the tools listed above.
|
||||
|
||||
We determined that the best scenario for our use case was a multi-machine Vagrant environment. The Vagrantfile creates three CentOS VMs to simulate two target hosts and an Ansible control machine:
|
||||
|
||||
* Host1: No graphical user interface (GUI), with httpd and MySQL installed
|
||||
* Host2: No GUI, with httpd and MySQL installed
|
||||
* Ansible-host: No GUI, with Ansible engine installed
|
||||
|
||||
|
||||
|
||||
### Enable multiple hypervisors
|
||||
|
||||
Some hypervisors may not allow you to bring up VMs if more than one hypervisor is in use. To fix this problem, follow these steps (based on Vagrant’s [installation][10] instructions).
|
||||
|
||||
First, find out the name of the hypervisor:
|
||||
|
||||
|
||||
```
|
||||
$ lsmod | grep kvm
|
||||
kvm_intel 204800 6
|
||||
kvm 593920 1 kvm_intel
|
||||
irqbypass 16384 1 kvm
|
||||
```
|
||||
|
||||
The one I’m interested in is `kvm_intel`, but you might want another (such as `kvm_amd`).
|
||||
|
||||
Run the following as root to blacklist the hypervisor:
|
||||
|
||||
|
||||
```
|
||||
`$ echo 'blacklist kvm-intel' >> /etc/modprobe.d/blacklist.conf`
|
||||
```
|
||||
|
||||
Restart your machine and try running Vagrant again.
|
||||
|
||||
### The Vagrant file
|
||||
|
||||
|
||||
```
|
||||
cat Vagrantfile
|
||||
# -*- mode: ruby -*-
|
||||
# vi: set ft=ruby :
|
||||
|
||||
Vagrant.configure("2") do |config|
|
||||
# Define VMs with static private IP addresses, vcpu, memory and vagrant-box.
|
||||
boxes = [
|
||||
{
|
||||
:name => "web1.demo.com", ⇒ Host1 this is one of the target nodes
|
||||
:box => "centos/8", ⇒ OS version
|
||||
:ram => 1024, ⇒ Allocated memory
|
||||
:vcpu => 1, ⇒ Allocated CPU
|
||||
:ip => "192.168.29.2" ⇒ Allocated IP address of the node
|
||||
},
|
||||
{
|
||||
:name => "web2.demo.com", ⇒ Host2 this is one of the target nodes
|
||||
:box => "centos/8",
|
||||
:ram => 1024,
|
||||
:vcpu => 1,
|
||||
:ip => "192.168.29.3"
|
||||
},
|
||||
{
|
||||
:name => "ansible-host", ⇒ Ansible Host with Ansible Engine
|
||||
:box => "centos/8",
|
||||
:ram => 8048,
|
||||
:vcpu => 1,
|
||||
:ip => "192.168.29.4"
|
||||
}
|
||||
]
|
||||
|
||||
# Provision each of the VMs.
|
||||
boxes.each do |opts|
|
||||
config.vm.define opts[:name] do |config|
|
||||
# Only Enable this if you are connecting to Proxy server
|
||||
# config.proxy.http = "<http://usernam:password@x.y:80"⇒> Needed if you have a proxy
|
||||
# config.proxy.https = "<http://usernam:password@x.y:80>"
|
||||
# config.proxy.no_proxy = "localhost,127.0.0.1"
|
||||
config.vm.synced_folder ".", "/vagrant", id: "vagrant-root", disabled: true
|
||||
config.ssh.insert_key = false
|
||||
config.vm.box = opts[:box]
|
||||
config.vm.hostname = opts[:name]
|
||||
config.vm.provider :virtualbox do |v| ⇒ Defines the vagrant provider
|
||||
v.memory = opts[:ram]
|
||||
v.cpus = opts[:vcpu]
|
||||
end
|
||||
config.vm.network :private_network, ip: opts[:ip]
|
||||
config.vm.provision :file do |file|
|
||||
file.source = './keys/vagrant' ⇒ vagrant keys to allow access to the nodes
|
||||
file.destination = '/tmp/vagrant' ⇒ the location to copy the vagrant key
|
||||
end
|
||||
config.vm.provision :shell, path: "bootstrap-node.sh" ⇒ script that copy hosts entry
|
||||
config.vm.provision :ansible do |ansible| ⇒ declaration to run ansible playbook
|
||||
ansible.verbose = "v"
|
||||
ansible.playbook = "playbook.yml" ⇒ the playbook used to configure the hosts
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
```
|
||||
|
||||
These are the important files that you need to pay attention to:
|
||||
|
||||
* `inventory-test.yaml`: The inventory file to connect to the nodes
|
||||
* `playbook.yaml`: The playbook file that Vagrant provisioner calls to configure the nodes
|
||||
* `Vagrantfile`: The file that Vagrant uses to deploy the environment
|
||||
* `vagrant keys`: The Vagrant keys for connecting to the nodes in your lab environment
|
||||
|
||||
|
||||
|
||||
You can adjust these files based on your needs. Ansible’s flexibility gives you the power to declaratively change your environment as you require.
|
||||
|
||||
### Deploy your lab environment
|
||||
|
||||
First, clone the code from the [GitHub repo][11]:
|
||||
|
||||
|
||||
```
|
||||
$ git clone <https://github.com/mikecali/ansible-labs-101.git>
|
||||
Cloning into 'ansible-labs-101'...
|
||||
remote: Enumerating objects: 15, done.
|
||||
remote: Counting objects: 100% (15/15), done.
|
||||
remote: Compressing objects: 100% (13/13), done.
|
||||
remote: Total 15 (delta 2), reused 10 (delta 0), pack-reused 0
|
||||
Unpacking objects: 100% (15/15), 6.82 KiB | 634.00 KiB/s, done.
|
||||
```
|
||||
|
||||
Next, change your directory to `vagrant-session-2`, and view its contents:
|
||||
|
||||
|
||||
```
|
||||
$ ls
|
||||
Bootstrap-node.sh inventory keys playbook.yml README.md Vagrantfile
|
||||
```
|
||||
|
||||
You now have all the artifacts and configuration files you need for your lab environment. To deploy your environment, run:
|
||||
|
||||
|
||||
```
|
||||
`$ vagrant up`
|
||||
```
|
||||
|
||||
With a decent internet connection, it takes only about 20 minutes to get a running environment:
|
||||
|
||||
|
||||
```
|
||||
$ vagrant up
|
||||
Bringing machine 'web1.demo.com' up with 'virtualbox' provider...
|
||||
Bringing machine 'web2.demo.com' up with 'virtualbox' provider...
|
||||
Bringing machine 'ansible-host' up with 'virtualbox' provider...
|
||||
==> web1.demo.com: Importing base box 'centos/8'...
|
||||
==> web1.demo.com: Matching MAC address for NAT networking...
|
||||
==> web1.demo.com: Checking if box 'centos/8' version '1905.1' is up to date...
|
||||
==> web1.demo.com: Setting the name of the VM: ansible-labs_web1democom_1606434176593_70913
|
||||
==> web1.demo.com: Clearing any previously set network interfaces...
|
||||
==> web1.demo.com: Preparing network interfaces based on configuration...
|
||||
web1.demo.com: Adapter 1: nat
|
||||
web1.demo.com: Adapter 2: hostonly
|
||||
==> web1.demo.com: Forwarding ports...
|
||||
web1.demo.com: 22 (guest) => 2222 (host) (adapter 1)
|
||||
==> web1.demo.com: Running 'pre-boot' VM customizations...
|
||||
==> web1.demo.com: Booting VM...
|
||||
==> web1.demo.com: Waiting for machine to boot. This may take a few minutes...
|
||||
web1.demo.com: SSH address: 127.0.0.1:2222
|
||||
web1.demo.com: SSH username: vagrant
|
||||
web1.demo.com: SSH auth method: private key
|
||||
[...]
|
||||
```
|
||||
|
||||
Once the playbook execution completes, you will see output like this:
|
||||
|
||||
|
||||
```
|
||||
PLAY RECAP *********************************
|
||||
Ansible-host : ok=20 changed=11 unreachable=0 failed=0 skipped=0 rescued=0 ignored=3
|
||||
|
||||
Real 18m14.288s
|
||||
User 2m26.978s
|
||||
Sys 0m26.849s
|
||||
```
|
||||
|
||||
Verify that all VMs are running:
|
||||
|
||||
|
||||
```
|
||||
$ vagrant status
|
||||
Current machine states:
|
||||
|
||||
Web1.demo.com running (virtualbox)
|
||||
Web2.demo.com running (virtualbox)
|
||||
ansible-host running (virtualbox)
|
||||
[...]
|
||||
```
|
||||
|
||||
You can investigate further by logging into one of the VMs. Access the ansible-host:
|
||||
|
||||
|
||||
```
|
||||
> vagrant ssh ansible-host
|
||||
Activate the web console with: systemctl enable --now cockpit.socket
|
||||
|
||||
Last login: Thu Nov 26 12:21:23 2020 from 10.0.2.2
|
||||
[vagrant@ansible-host ~] uptime
|
||||
16:46:42 up 1:24, 1 user, load average: 0.00, 0.01, 0.04
|
||||
```
|
||||
|
||||
Finally, you can use the Ansible module to ping the other nodes you created:
|
||||
|
||||
|
||||
```
|
||||
[vagrant@ansible-host]$ ansible -i inventory-test.yaml \
|
||||
webservers -m ping -u vagrant
|
||||
192.168.29.2 | SUCCESS => {
|
||||
"Ansible-facts": {
|
||||
"Discovered_interpreter_python": "/usr/libexec/platform-python"
|
||||
},
|
||||
"Changed": false;
|
||||
"Ping": "pong"
|
||||
}
|
||||
[...]
|
||||
```
|
||||
|
||||
### Clean up
|
||||
|
||||
Clean up your environment by running:
|
||||
|
||||
|
||||
```
|
||||
`$ vagrant destroy [vagrant machine name]`
|
||||
```
|
||||
|
||||
Your output will look like this:
|
||||
|
||||
![Output from cleaning up environment][12]
|
||||
|
||||
(Michael Calizo, [CC BY-SA 4.0][13])
|
||||
|
||||
### Get creative to learn
|
||||
|
||||
Learning software like Ansible on your own time in your own lab is a good habit, but it can be difficult because of constraints that are out of your control.
|
||||
|
||||
Sometimes, you need to get creative and find another way. There are many options in the open source community you can choose from; one of the main reasons we picked these tools is because they are commonly used and familiar to many people.
|
||||
|
||||
Also, please note that these playbooks are not as optimized as I want. Please feel free to improve them and share your work in the comments.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/20/12/ansible-lab
|
||||
|
||||
作者:[Mike Calizo][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/mcalizo
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/science_experiment_beaker_lab.png?itok=plKWRhlU (Science lab with beakers)
|
||||
[2]: https://opensource.com/resources/what-ansible
|
||||
[3]: https://github.com/mikecali/ansible-labs-101
|
||||
[4]: https://www.ansible.com/
|
||||
[5]: https://www.vagrantup.com/
|
||||
[6]: https://www.virtualbox.org/
|
||||
[7]: https://getfedora.org/
|
||||
[8]: https://support.lenovo.com/pt/en/solutions/ht500006
|
||||
[9]: https://opensource.com/article/20/11/cockpit-server-management
|
||||
[10]: https://www.vagrantup.com/docs/installation
|
||||
[11]: https://github.com/mikecali/ansible-labs-101.git
|
||||
[12]: https://opensource.com/sites/default/files/uploads/cleanup.png (Output from cleaning up environment)
|
||||
[13]: https://creativecommons.org/licenses/by-sa/4.0/
|
@ -0,0 +1,81 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Write in XML with the NetBeans text editor)
|
||||
[#]: via: (https://opensource.com/article/20/12/netbeans)
|
||||
[#]: author: (Seth Kenlon https://opensource.com/users/seth)
|
||||
|
||||
Write in XML with the NetBeans text editor
|
||||
======
|
||||
NetBeans is a popular Java IDE, making it a handy text editor for
|
||||
developers already using it.
|
||||
![Coffee beans and a cup of coffee][1]
|
||||
|
||||
I’ve spent a considerable amount of time in NetBeans, a Java IDE (integrated development environment) maintained by the Apache Foundation. I find it’s got a good mix of automated abstraction and manual configuration that helps me keep my Java projects organized and optimized. Not all IDEs give much thought to text files, but XML is frequently used in Java projects, so XML support in NetBeans is an important feature. It occurred to me that NetBeans, in addition to being an excellent Java IDE, could make for a nice XML editor, with the added benefit of being contained in a familiar application I already use.
|
||||
|
||||
### Install
|
||||
|
||||
Prior to installing NetBeans, you must ensure you have Java itself installed. The easiest way to install Java is to download a package from [adoptOpenJDK.net][2]. This site provides installer packages for all platforms. I prefer to use the LTS (long-term support) release, but if you’re already a Java programmer, then you may have your own preference.
|
||||
|
||||
If you’re using Linux and BSD, you can probably install NetBeans from your distributions’ software repository or ports tree. Alternatively, you can install it as a Flatpak from [Flathub][3].
|
||||
|
||||
On Windows and Mac (and Linux, if the other methods aren’t to your liking), you can install NetBeans directly from [netbeans.org][4].
|
||||
|
||||
![Black NetBeans terminal with white and yellow XML code ][5]
|
||||
|
||||
### XML in NetBeans
|
||||
|
||||
NetBeans supports XML natively, so there are no plugins to install or hidden options to enable. However, NetBeans is project-centric. It assumes, by design, that every file you create belongs to a Java project. This doesn’t have to be true, but every file you create does need to belong to a NetBeans project directory unless you open an existing one from an arbitrary place on your hard drive. You probably won’t be opening NetBeans just to make a quick note to yourself, but if your use case (like mine) is for projects big enough to have an IDE open all day anyway, then NetBeans makes sense.
|
||||
|
||||
When you create a new XML Document, you’re prompted to save it into a project directory. After naming your file, it opens as a tab in your NetBeans workspace. NetBeans is schema-aware, so you can set your schema from within an XML document. For example, [I love to write in Docbook][6], so I start my XML files with this declaration:
|
||||
|
||||
|
||||
```
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<article xmlns="<http://docbook.org/ns/docbook>"
|
||||
xmlns:xlink="<http://www.w3.org/1999/xlink>"
|
||||
dtd="/usr/share/xml/docbook5/schema/dtd/5.0/docbook.dtd"
|
||||
version="5.0"
|
||||
xml:lang="en">
|
||||
```
|
||||
|
||||
NetBeans recognizes this as a schema and namespace declaration and downloads the appropriate files.
|
||||
|
||||
|
||||
```
|
||||
Retrieving Location: <http://docbook.org/ns/docbook>
|
||||
Retrieved : <https://docbook.org/ns/docbook>
|
||||
Saved at: /home/tux/.cache/netbeans/12.1/mavencachedirs/1391771919/retriever/docbook.org/ns/docbook.xml
|
||||
```
|
||||
|
||||
Writing XML in NetBeans is a pleasure. It understands tags and how and when to close them. Tags are exempted from the spell checker. NetBeans also has a good syntax highlighting theme to make it easy for you to differentiate tag elements, attributes, and content. It provides code folding, so I can easily collapse blocks of text I don’t need to see at any given time. You can hide and reveal folded text by clicking on the **-** or **+** icons on the left of each block. Alternatively, you can use the keyboard shortcut **[ +Ctrl+ + ±+ ]{.keycombo}** or **[ +Ctrl+ ++++ ]{.keycombo}**.
|
||||
|
||||
When you right-click on your editing window, you get an XML-specific menu with options to check your XML syntax and to validate your XML against a schema, and even to apply an XSL transform on your work.
|
||||
|
||||
There are many more features in NetBeans that aren’t specific to editing XML but are still useful. For instance, you can split your editing window in NetBeans, so you have multiple files open side by side. Line numbers down the left side of the window make it easy for you to navigate, and you can also create bookmarks in your file and then use them to quickly jump between points. There’s auto-indentation, code completion, an outline view, and a great interface, especially to those already familiar with it as a code editor.
|
||||
|
||||
### Try NetBeans
|
||||
|
||||
NetBeans isn’t the best choice for a general text editor. It’s big, it has lots of options for very specific languages, and not much for anything else. However, if you write in XML on a regular basis, or if you just use NetBeans anyway, then it works great as a handy text editor. Why open a separate application when you have everything you need in your IDE already? Give NetBeans as a text editor a try!
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/20/12/netbeans
|
||||
|
||||
作者:[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-mug.jpg?itok=Bj6rQo8r (Coffee beans and a cup of coffee)
|
||||
[2]: https://adoptopenjdk.net/
|
||||
[3]: https://flathub.org/apps/details/org.apache.netbeans
|
||||
[4]: https://netbeans.apache.org/download/index.html
|
||||
[5]: https://opensource.com/sites/default/files/uploads/netbeans-xml-31days-netbeans-opensource.png (Black NetBeans terminal with white and yellow XML code )
|
||||
[6]: https://opensource.com/article/17/9/docbook
|
@ -0,0 +1,107 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (6 container concepts you need to understand)
|
||||
[#]: via: (https://opensource.com/article/20/12/containers-101)
|
||||
[#]: author: (Mike Calizo https://opensource.com/users/mcalizo)
|
||||
|
||||
6 container concepts you need to understand
|
||||
======
|
||||
Containers are everywhere, and they've radically changed the IT
|
||||
landscape. What do you need to know about them?
|
||||
![Ships at sea on the web][1]
|
||||
|
||||
Containerization has radically changed the IT landscape because of the significant value and wide array of benefits it brings to business. Nearly any recent business innovation has containerization as a contributing factor, if not the central element.
|
||||
|
||||
In modern application architectures, the ability to deliver changes quickly to the production environment gives you an edge over your competitors. Containers deliver speed by using a microservices architecture that helps development teams create functionality, fail small, and recover faster. Containerization also enables applications to start faster and automatically scale cloud resources on demand. Furthermore, [DevOps][2] maximizes containerization's benefits by enabling the flexibility, portability, and efficiency required to go to market early.
|
||||
|
||||
While speed, agility, and flexibility are the main promises of containerization using DevOps, security is a critical factor. This led to the rise of DevSecOps, which incorporates security into application development from the start and throughout the lifecycle of a containerized application. By default, containerization massively improves security because it isolates the application from the host and other containerized applications.
|
||||
|
||||
### What are containers?
|
||||
|
||||
Containers are the solution to problems inherited from monolithic architectures. Although monoliths have strengths, they prevent organizations from moving fast the agile way. Containers allow you to break monoliths into [microservices][3].
|
||||
|
||||
Essentially, a container is an application bundle of lightweight components, such as application dependencies, libraries, and configuration files, that run in an isolated environment on top of traditional operating systems or in virtualized environments for easy portability and flexibility.
|
||||
|
||||
![Container architecture][4]
|
||||
|
||||
(Michael Calizo, [CC BY-SA 4.0][5])
|
||||
|
||||
To summarize, containers provide isolation by taking advantage of kernel technologies like cgroups, [kernel namespaces][6], and [SELinux][7]. Containers share a kernel with the host, which allows them to use fewer resources than a virtual machine (VM) would require.
|
||||
|
||||
### Container advantages
|
||||
|
||||
This architecture provides agility that is not feasible with VMs. Furthermore, containers support a more flexible model when it comes to compute and memory resources, and they allow resource-burst modes so that applications can consume more resources, when required, within the defined boundaries. In other words, containers provide scalability and flexibility that you cannot get from running an application on top of a VM.
|
||||
|
||||
Containers make it easy to share and deploy applications on public or private clouds. More importantly, they provide consistency that helps operations and development teams reduce the complexity that comes with multi-platform deployment.
|
||||
|
||||
Containers also enable a common set of building blocks that can be reused in any stage of development to recreate identical environments for development, testing, staging, and production, extending the concept of "write-once, deploy anywhere."
|
||||
|
||||
Compared to virtualization, containers make it simpler to achieve flexibility, consistency, and the ability to deploy applications faster—the main principles of DevOps.
|
||||
|
||||
### The Docker factor
|
||||
|
||||
[Docker][8] has become synonymous with containers. Docker revolutionized and popularized containers, even though the technology existed before Docker. Examples include AIX Workload partitions, Solaris Containers, and Linux containers ([LXC][9]), which was created to [run multiple Linux environments in a single Linux host][10].
|
||||
|
||||
### The Kubernetes effect
|
||||
|
||||
Kubernetes is widely recognized as the leading [orchestration engine][11]. In the last few years, [Kubernetes' popularity][12] coupled with maturing container adoption created the ideal scenario for ops, devs, and security teams to embrace the changing landscape.
|
||||
|
||||
Kubernetes provides a holistic approach to managing containers. It can run containers across a cluster to enable features like autoscaling cloud resources, including event-driven application requirements, in an automated and distributed way. This ensures high availability "for free" (i.e., neither developers nor admins expend extra effort to make it happen).
|
||||
|
||||
In addition, OpenShift and similar Kubernetes enterprise offerings make container adoption much easier.
|
||||
|
||||
![Kubernetes cluster][13]
|
||||
|
||||
(Michael Calizo, [CC BY-SA 4.0][5])
|
||||
|
||||
### Will containers replace VMs?
|
||||
|
||||
[KubeVirt][14] and similar [open source][15] projects show a lot of promise that containers will replace VMs. KubeVirt brings VMs into containerized workflows by converting the VMs into containers, where they run with the benefits of containerized applications.
|
||||
|
||||
Right now, containers and VMs work as complementary solutions rather than competing technologies. Containers run atop VMs to increase availability, especially for applications that require persistency, and take advantage of virtualization technology that makes it easier to manage the hardware infrastructure (like storage and networking) required to support containers.
|
||||
|
||||
### What about Windows containers?
|
||||
|
||||
There is a big push from Microsoft and the open source community to make Windows containers successful. Kubernetes Operators have fast-tracked Windows container adoption, and products like OpenShift now enable [Windows worker nodes][16] to run Windows containers.
|
||||
|
||||
Windows containerization creates a lot of enticing possibilities, especially for enterprises with mixed environments. Being able to run your most critical applications on top of a Kubernetes cluster is a big advantage towards achieving a hybrid- or multi-cloud environment.
|
||||
|
||||
### The future of containers
|
||||
|
||||
Containers play a big role in the shifting IT landscape because enterprises are moving towards fast, agile delivery of software and solutions to [get ahead of competitors][17].
|
||||
|
||||
Containers are here to stay. In the very near future, other use cases, like serverless on the edge, will emerge and further change how we think about the speed of getting information to and from digital devices. The only way to survive these changes is to adapt to them.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/20/12/containers-101
|
||||
|
||||
作者:[Mike Calizo][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/mcalizo
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/kubernetes_containers_ship_lead.png?itok=9EUnSwci (Ships at sea on the web)
|
||||
[2]: https://opensource.com/resources/devops
|
||||
[3]: https://opensource.com/resources/what-are-microservices
|
||||
[4]: https://opensource.com/sites/default/files/uploads/container_architecture.png (Container architecture)
|
||||
[5]: https://creativecommons.org/licenses/by-sa/4.0/
|
||||
[6]: https://opensource.com/article/19/10/namespaces-and-containers-linux
|
||||
[7]: https://opensource.com/article/20/11/selinux-containers
|
||||
[8]: https://opensource.com/resources/what-docker
|
||||
[9]: https://linuxcontainers.org/
|
||||
[10]: https://opensource.com/article/18/11/behind-scenes-linux-containers
|
||||
[11]: https://opensource.com/article/20/11/orchestration-vs-automation
|
||||
[12]: https://enterprisersproject.com/article/2020/6/kubernetes-statistics-2020
|
||||
[13]: https://opensource.com/sites/default/files/uploads/kubernetes_cluster.png (Kubernetes cluster)
|
||||
[14]: https://kubevirt.io/
|
||||
[15]: https://opensource.com/resources/what-open-source
|
||||
[16]: https://www.openshift.com/blog/announcing-the-community-windows-machine-config-operator-on-openshift-4.6
|
||||
[17]: https://www.imd.org/research-knowledge/articles/the-battle-for-digital-disruption-startups-vs-incumbents/
|
@ -0,0 +1,65 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Cut your Cloud Computing Costs by Half with Unikraft)
|
||||
[#]: via: (https://www.linux.com/news/cut-your-cloud-computing-costs-by-half-with-unikraft/)
|
||||
[#]: author: (Linux.com Editorial Staff https://www.linux.com/author/linuxdotcom/)
|
||||
|
||||
Cut your Cloud Computing Costs by Half with Unikraft
|
||||
======
|
||||
|
||||
***A novel modular unikernel allows for extreme tailoring of your operating system to your application’s needs. A proof of concept, built on Unikraft, a Xen Project subproject, shows up to 50% efficiency improvements than standard Linux on AWS EC2. ***
|
||||
|
||||
Cloud computing has revolutionized the way we think about IT infrastructure: Another web server? More database capacity? Resources for your artificial intelligence use case? Just spin-up another instance, and you are good to go. Virtualization and containers have allowed us to deploy services without worrying about physical hardware constraints. As a result, most companies heavily rely on micro-services, which are individual servers highly specialized to perform a specific task.
|
||||
|
||||
The problem is that general-purpose operating systems such as Linux struggle to keep pace with this growing trend towards specialization. The status quo is that most microservices are built on top of a complete Linux kernel and distribution. It is as if you wanted to enable individual air travel with only one passenger seat per aircraft but kept the powerful engines of a jumbo jet. The result of having a proliferation of general-purpose OSes in the cloud are bloated instances, that feast on memory and processing power while uselessly burning electrical energy as well as your infrastructure budget.
|
||||
|
||||
![Figure 1. Linux kernel components have strong inter-dependencies making it difficult to remove or replace them.][1]
|
||||
|
||||
Despite this, putting Linux and other monolithic OSes on a diet is far from trivial. Removing unneeded components from the Linux kernel is a tedious endeavor due to the interdependencies among subsystems of the kernel: Figure 1 above illustrates a large number of such inter-dependencies a line denotes a dependency and a blue number the amount of such dependencies between two components.
|
||||
|
||||
An alternative is to build so-called _unikernels_, images tailored to specific applications and often built on much smaller kernels. Unikernels have shown great promise and performance numbers (e.g., boot times of a few milliseconds, memory consumption when running off-the-shelf applications such as nginx of only a few MBs, and high throughput). However, their Achilles heel has been that they often require substantial expert work to create them and that at least part of the work has to be redone for each additional application. These issues, coupled with the fact that most unikernel projects don’t have a rich set of tools and ecosystem (e.g., Kubernetes integration, debugging and monitoring tools, etc.), resulting in 1GB Linux instances for jobs that might be as easy as delivering static web pages.
|
||||
|
||||
## **Unikraft: A Revolutionary Way Forward**
|
||||
|
||||
[Unikraft][2] is on a mission to change that. In stark contrast to other unikernel projects, Unikraft, a Xen Project subproject, has developed a truly modular unikernel common code base from which building tailored made (uni)kernels is orders of magnitude faster than in the past.
|
||||
|
||||
“Without Unikraft, you have to choose between unikernel projects that only work for a specific language or application, or projects that aim to support POSIX but do so while sacrificing performance and thus defeating the purpose of using unikernels in the first place”, says Felipe Huici, one of the Unikraft team’s core contributors. “
|
||||
|
||||
Unikraft aims to run a large set of off-the-shelf application and languages (C/C++, Python, Go, Ruby, Lua, and WASM are supported, with Rust and Java on the way), but still allows for easy customization and even removal of unneeded kernel parts; also, it provides a set of rich, performance-oriented APIs that allows further customization by plugging the application at different levels of the stack for even higher performance.”
|
||||
|
||||
A sample of such APIs are shown in Figure 2 below.
|
||||
|
||||
![Figure 2. Rhea architecture \(APIs in black boxes\) enables specialization by allowing apps to plug into APIs at different levels and to choose from multiple API implementations.][3]
|
||||
|
||||
Unikraft already supports more than 130 syscalls in terms of POSIX compatibility, and the number is continuously increasing. While this is certainly short of the 300+ that Linux supports, it turns out that only a subset of these are needed for running most of the major server applications. This, and ongoing efforts to support standard frameworks such as Kubernetes and Prometheus make Unikraft an enticing proposition and mark the coming of age of unikernels into the mainstream.
|
||||
|
||||
## **Unikraft Goes to the Cloud**
|
||||
|
||||
But what’s really in it for end-users? To demonstrate the power and efficiency of Unikraft, the team created an experimental Unikraft AWS EC2 image running nginx, currently the world’s most popular web server. “We’ve built a Unikraft nginx image and compared it to a ngnix running on an off-the-shelf Debian image to compare the performance of the two when serving static web pages. We’ve been more than pleased with the results” says Huici. “On Unikraft, nginx could handle twice the number of requests per second compared to the Debian instance. Or you could take a less performant AWS EC2 instance at half the price and get the same job done. Further, Unikraft needed about a sixth the amount of memory to run”. The throughput results can be seen in Figure 3 below.
|
||||
|
||||
![][4]
|
||||
|
||||
So far, this is only a proof of concept, but Huici and the Unikraft team are moving quickly. “We are currently working on a system to make the process of creating a Unikraft image as easy as online-shopping” – this includes analyzing the applications which are meant to run on top of it and providing a ready-to-use operating system that has everything the specific use case needs, and nothing more. “Why should we waste money, resources, and pollute the environment running software in the background that is not needed for a specific service?”
|
||||
|
||||
_**About the author: Simon Kuenzer is the Project Lead and Maintainer of Unikraft, which is part of the Xen Project at the Linux Foundation.**_
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.linux.com/news/cut-your-cloud-computing-costs-by-half-with-unikraft/
|
||||
|
||||
作者:[Linux.com Editorial Staff][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.linux.com/author/linuxdotcom/
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://www.linux.com/wp-content/uploads/2020/12/unikraft1.png
|
||||
[2]: https://xenproject.org/developers/teams/unikraft/
|
||||
[3]: https://www.linux.com/wp-content/uploads/2020/12/unikraft2.png
|
||||
[4]: https://www.linux.com/wp-content/uploads/2020/12/unikraft3.png
|
@ -0,0 +1,149 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (How to Resize Images with Right Click on Linux)
|
||||
[#]: via: (https://www.2daygeek.com/how-to-resize-images-with-right-click-on-linux/)
|
||||
[#]: author: (Magesh Maruthamuthu https://www.2daygeek.com/author/magesh/)
|
||||
|
||||
How to Resize Images with Right Click on Linux
|
||||
======
|
||||
|
||||
Do you often manipulate images as part of your daily job?
|
||||
|
||||
I personally need to do the graphics work for this website before uploading it to my blog.
|
||||
|
||||
One of the most common image editing tasks is resizing, which tremendously reduces the image size from MB to KB.
|
||||
|
||||
This allows images to load quickly on the web even if someone uses a slow internet.
|
||||
|
||||
I usually use the ImageMagick tool to perform this operation from the command line.
|
||||
|
||||
But I recommend using the “Nautilus Image Converter” which gets integrated in the right-click context menu in the image file.
|
||||
|
||||
It is very handy and works well in a second. But if you want to perform this action in bulk. I would recommend using the **[ImageMagick tool][1]** because it comes with a batch operation.
|
||||
|
||||
### What’s Nautilus?
|
||||
|
||||
Nautilus is a file manager used by GNOME and several other desktop environments. It provides a simple and integrated way to manage your files and applications.
|
||||
|
||||
The file manager lets you organize your files into folders. This is similar to “File Explorer” in Windows.
|
||||
|
||||
### How to Install Nautilus Image Converter Plugin?
|
||||
|
||||
There are many Nautilus plugins that enhance its capabilities. They are not installed by default, but you can choose to install them according to your needs.
|
||||
|
||||
We are going to install a plugin called Image Manipulator,, which allows you to rotate or resize images by right-clicking on an image.
|
||||
|
||||
Run the command below to see if your Linux system uses Nautilus File Manager.
|
||||
|
||||
```
|
||||
$ nautilus --version
|
||||
GNOME nautilus 3.36.3
|
||||
```
|
||||
|
||||
If you have Nautilus file manager on your system, you will get the same results as above, but the version may vary.
|
||||
|
||||
Make sure you already have ImageMagick installed on your system, as this plugin uses ImageMagick for image manipulation. If not, you need to install it.
|
||||
|
||||
**Make a note:** Make sure you already have “**[Development Tools][2]**” installed on your Linux system as a prerequisite for this.
|
||||
|
||||
For **RHEL/CentOS 6/7** systems, use the **[yum command][3]** to install ImageMagick.
|
||||
|
||||
```
|
||||
$ sudo yum install -y ImageMagick ImageMagick-devel
|
||||
```
|
||||
|
||||
For **RHEL/CentOS 8** and **Fedora** systems, use the **[dnf command][4]** to install ImageMagick.
|
||||
|
||||
```
|
||||
$ sudo dnf install -y ImageMagick ImageMagick-devel
|
||||
```
|
||||
|
||||
For **Debian/Ubuntu** systems, use the **[apt command][5]** or **[apt-get command][6]** to install ImageMagick.
|
||||
|
||||
```
|
||||
$ sudo apt-get update
|
||||
$ sudo apt-get install imagemagick
|
||||
```
|
||||
|
||||
For **openSUSE** systems, use the **[zypper command][7]** to install ImageMagick.
|
||||
|
||||
```
|
||||
$ sudo zypper install -y ImageMagick
|
||||
```
|
||||
|
||||
Finally install the Nautilus plugin using the commands below.
|
||||
|
||||
For **Ubuntu/Debian** system:
|
||||
|
||||
```
|
||||
$ sudo apt install nautilus-image-converter
|
||||
```
|
||||
|
||||
For **Fedora** system:
|
||||
|
||||
```
|
||||
$ sudo dnf install nautilus-image-converter
|
||||
```
|
||||
|
||||
For **Manjaro/ArchLinux** system:
|
||||
|
||||
```
|
||||
$ sudo pacman -S nautilus-image-converter
|
||||
```
|
||||
|
||||
For **openSUSE** system:
|
||||
|
||||
```
|
||||
$ sudo zypper install nautilus-image-converter
|
||||
```
|
||||
|
||||
Once installed, restart Nautilus using the command below.
|
||||
|
||||
```
|
||||
$ nautilus -q
|
||||
```
|
||||
|
||||
### How to Use Nautilus Image Converter Plugin?
|
||||
|
||||
You have finished the installation. Now if you right click on an image, you will see two new options in the context menu, **“Resize”** and **“Rotate”**.
|
||||
|
||||
![][8]
|
||||
|
||||
When you select the resize option in the context menu, you will get a pop-up window below with some options for resizing the image.
|
||||
|
||||
* **Select a size:** Select the image size you want to resize. In the drop-down, you will get the following pixels 96×96, 128×128, 640×480, 800×600, 1024×768 or 1280×960.
|
||||
* **Scale:** This is the compression level. By default, it comes with 50% and you can change this based on your needs. I recommend using the default value.
|
||||
* **Custom size:** This allows you to set any custom size you want to resize the image to.
|
||||
* **Append:** By default, it adds “.resized” to the converted image file name, which helps to retain the original image file.
|
||||
* **Resize in place:** You can change the behavior above by selecting this option. This option replaces the original image with a modified image.
|
||||
|
||||
|
||||
|
||||
![][8]
|
||||
|
||||
Click the **“Resize”** button to complete the image conversion.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.2daygeek.com/how-to-resize-images-with-right-click-on-linux/
|
||||
|
||||
作者:[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/resize-convert-images-from-linux-command-line/
|
||||
[2]: https://www.2daygeek.com/install-development-tools-on-ubuntu-debian-arch-linux-mint-fedora-centos-rhel-opensuse/
|
||||
[3]: https://www.2daygeek.com/linux-yum-command-examples-manage-packages-rhel-centos-systems/
|
||||
[4]: https://www.2daygeek.com/linux-dnf-command-examples-manage-packages-fedora-centos-rhel-systems/
|
||||
[5]: https://www.2daygeek.com/apt-command-examples-manage-packages-debian-ubuntu-systems/
|
||||
[6]: https://www.2daygeek.com/apt-get-apt-cache-command-examples-manage-packages-debian-ubuntu-systems/
|
||||
[7]: https://www.2daygeek.com/zypper-command-examples-manage-packages-opensuse-system/
|
||||
[8]: data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7
|
273
sources/tech/20201216 How to use Kubernetes resource quotas.md
Normal file
273
sources/tech/20201216 How to use Kubernetes resource quotas.md
Normal file
@ -0,0 +1,273 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (How to use Kubernetes resource quotas)
|
||||
[#]: via: (https://opensource.com/article/20/12/kubernetes-resource-quotas)
|
||||
[#]: author: (Mike Calizo https://opensource.com/users/mcalizo)
|
||||
|
||||
How to use Kubernetes resource quotas
|
||||
======
|
||||
Resource quotas prevent resource contention and "land grabs" by
|
||||
controlling how much CPU or memory an application can consume.
|
||||
![Jars with food inside on a shelf][1]
|
||||
|
||||
"Control" is the word that comes to mind when someone mentions they need to manage Kubernetes compute resources, especially CPU and memory. These conversations generally happen after the [Kubernetes][2] platform has been deployed for a while and developers are using the cluster extensively. And most of the time, the topic comes up after a problem happens.
|
||||
|
||||
Resource issues are common when the Kubernetes implementation is deployed without consideration for the cluster's future growth. Issues may also be related to the team's experience level that deploys and manages the Kubernetes cluster.
|
||||
|
||||
Without controls, one rogue application or developer can disrupt business. This inadvertently happens when several developers share a cluster with a fixed number of nodes. These resource constraints can start disagreements, finger-pointing, and "land-grabbing" of available resources among developers. It's a very bad situation for cluster administrators and developers alike.
|
||||
|
||||
There are several ways to manage how applications utilize computing resources in the Kubernetes environment. Most of the time, resource quotas and limit ranges are enough. Note that in Kubernetes, storage management takes an unusual approach by using a Persistent Volume plugin where properties to address and control different storage requirements are defined.
|
||||
|
||||
Kubernetes resource quotas are a way to control how computing resources are used. This article will show you how to use this feature to manage developers' behavior and control application resource consumption.
|
||||
|
||||
### What are resource quotas?
|
||||
|
||||
In short, [resource quotas][3] provide constraints that limit resource consumption per namespace. They can be applied only at the namespace level, which means they can be applied to computing resources and limit the number of objects inside the namespace.
|
||||
|
||||
A Kubernetes resource quota is defined by a `ResourceQuota` object. When applied to a namespace, it can limit computing resources such as CPU and memory as well as the creation of the following objects:
|
||||
|
||||
* Pods
|
||||
* Services
|
||||
* Secrets
|
||||
* Persistent Volume Claims (PVCs)
|
||||
* ConfigMaps
|
||||
|
||||
|
||||
|
||||
Kubernetes supports two types of CPU and memory quotas to manage compute resources. These are controlled via limits and requests, as the [LimitRange][4] documentation explains.
|
||||
|
||||
In short, a _request_ defines the guaranteed CPU or memory resources for containers, while a _limit_ is the memory or CPU threshold that a container can use, depending on what is available based on other containers' usage.
|
||||
|
||||
This image illustrates the difference between requests and limits in Kubernetes resource quotas.
|
||||
|
||||
![Requests and limits in Kubernetes resource quotas][5]
|
||||
|
||||
(Michael Calizo, [CC BY-SA 4.0][6])
|
||||
|
||||
The following exercise demonstrates how to use resource quotas to create constraints that limit an application to certain resources based on a defined threshold. It also shows the usefulness of implementing resource quotas to gain control over your Kubernetes implementation.
|
||||
|
||||
### Prerequisites
|
||||
|
||||
Before starting, make sure you have Kubernetes deployed in your local machine. Here is my configuration:
|
||||
|
||||
* [Minikube][7] v1.14.2
|
||||
* Fedora 33 operating system
|
||||
* Internet access
|
||||
|
||||
|
||||
|
||||
If you need help deploying Minikube on your Linux laptop, you can follow the steps in Bryant Son's [_Getting started with Minikube_][7]. Or, if you're on Windows or macOS, you can follow [these steps][8].
|
||||
|
||||
### Set up a resource quota
|
||||
|
||||
This example creates a CPU quota, but the process is similar for a memory quota or a combination of the two.
|
||||
|
||||
In a real production scenario, CPU resources are usually at the top of the computing resources you need to manage to avoid resource contention. This is true whenever you have multiple applications running on top of your server (compute).
|
||||
|
||||
Start by creating a new namespace where you will apply your CPU quota:
|
||||
|
||||
|
||||
```
|
||||
$ kubectl create namespace quota-test
|
||||
namespace/quota-test created
|
||||
```
|
||||
|
||||
Create a file named `cpu-quota.yaml` and put the following quota (created for this demo) into it:
|
||||
|
||||
|
||||
```
|
||||
apiVersion: v1
|
||||
kind: ResourceQuota
|
||||
metadata:
|
||||
name: test-cpu-quota
|
||||
spec:
|
||||
hard:
|
||||
requests.cpu: "100m"
|
||||
limits.cpu: "200m"
|
||||
```
|
||||
|
||||
Apply the quota to your Kubernetes cluster with:
|
||||
|
||||
|
||||
```
|
||||
$ kubectl apply -f cpu-qouta.yaml
|
||||
resourcequota/test-cpu-quota created
|
||||
```
|
||||
|
||||
Verify that the quota was applied with the `kubectl describe` command:
|
||||
|
||||
|
||||
```
|
||||
$ kubectl describe resourcequota/test-cpu-quota --namespace quota-test
|
||||
Name: test-cpu-quota
|
||||
Namespace: quota-test
|
||||
Resource Used Hard
|
||||
\-------- ---- ----
|
||||
limits.cpu 0 200m
|
||||
requests.cpu 0 100m
|
||||
```
|
||||
|
||||
Notice the `Used resources` column; this value will change as you deploy pods.
|
||||
|
||||
Now that you've defined your quota, test it. For this example, deploy three different pods in the same namespace to see if you can control the resources' usage based on the limits you defined. The three pods are:
|
||||
|
||||
* **PodA:** This pod, the first to be instantiated, will use 50% of the available CPU.
|
||||
* **PodB:** This pod will use the other 50% of the available CPU; it will be the second pod instantiated.
|
||||
* **PodC:** The defined quota should prevent this third pod from being deployed.
|
||||
|
||||
|
||||
|
||||
Now that you know the scenario, deploy the pods.
|
||||
|
||||
#### Deploy the pods
|
||||
|
||||
**PodA:**
|
||||
|
||||
|
||||
```
|
||||
$ kubectl create -n quota-test -f- <<EOF
|
||||
apiVersion: v1
|
||||
kind: Pod
|
||||
metadata:
|
||||
name: poda
|
||||
spec:
|
||||
containers:
|
||||
- name: quota-test
|
||||
image: busybox
|
||||
imagePullPolicy: IfNotPresent
|
||||
command: ['sh', '-c', 'echo Pod is Running ; sleep 5000']
|
||||
resources:
|
||||
requests:
|
||||
cpu: "50m"
|
||||
limits:
|
||||
cpu: "100m"
|
||||
restartPolicy: Never
|
||||
EOF
|
||||
```
|
||||
|
||||
Verify the CPU use by describing the quota again and noting the `Used CPU` value limits and requests:
|
||||
|
||||
|
||||
```
|
||||
$ kubectl describe resourcequota/test-cpu-quota --namespace quota-test
|
||||
Name: test-cpu-quota
|
||||
Namespace: quota-test
|
||||
Resource Used Hard
|
||||
\-------- ---- ----
|
||||
limits.cpu 100m 200m
|
||||
requests.cpu 50m 100m
|
||||
```
|
||||
|
||||
**PodB:**
|
||||
|
||||
|
||||
```
|
||||
$ kubectl create -n quota-test -f- <<EOF
|
||||
apiVersion: v1
|
||||
kind: Pod
|
||||
metadata:
|
||||
name: podb
|
||||
spec:
|
||||
containers:
|
||||
- name: quota-test
|
||||
image: busybox
|
||||
imagePullPolicy: IfNotPresent
|
||||
command: ['sh', '-c', 'echo Pod is Running ; sleep 5000']
|
||||
resources:
|
||||
requests:
|
||||
cpu: "50m"
|
||||
limits:
|
||||
cpu: "100m"
|
||||
restartPolicy: Never
|
||||
EOF
|
||||
```
|
||||
|
||||
Check the CPU resource usage again. As expected, PodB can be scheduled because the quota allows it:
|
||||
|
||||
|
||||
```
|
||||
$ kubectl describe resourcequota/test-cpu-quota --namespace quota-test
|
||||
Name: test-cpu-quota
|
||||
Namespace: quota-test
|
||||
Resource Used Hard
|
||||
\-------- ---- ----
|
||||
limits.cpu 200m 200m
|
||||
requests.cpu 100m 100m
|
||||
```
|
||||
|
||||
**PodC:**
|
||||
|
||||
Now, try to instantiate the third pod, even though you know PodA and Pod B maximized the CPU quota threshold you defined:
|
||||
|
||||
|
||||
```
|
||||
$ kubectl create -n quota-test -f- <<EOF
|
||||
apiVersion: v1
|
||||
kind: Pod
|
||||
metadata:
|
||||
name: podc
|
||||
spec:
|
||||
containers:
|
||||
- name: quota-test
|
||||
image: busybox
|
||||
imagePullPolicy: IfNotPresent
|
||||
command: ['sh', '-c', 'echo Pod is Running ; sleep 5000']
|
||||
resources:
|
||||
requests:
|
||||
cpu: "5m"
|
||||
limits:
|
||||
cpu: "10m"
|
||||
restartPolicy: Never
|
||||
EOF
|
||||
```
|
||||
|
||||
As expected, the third pod will not instantiate because the defined quota prevents creating the pods:
|
||||
|
||||
|
||||
```
|
||||
`Error from server (Forbidden): error when creating "STDIN": pods "podc" is forbidden: exceeded quota: test-cpu-quota, requested: limits.cpu=10m,requests.cpu=5m, used: limits.cpu=200m,requests.cpu=100m, limited: limits.cpu=200m,requests.cpu=100m`
|
||||
```
|
||||
|
||||
As this example shows, properly defined resource quotas are a powerful tool that a Kubernetes admin can utilize to manage developer behavior.
|
||||
|
||||
### Clean up
|
||||
|
||||
Delete the namespace you created (in this case, `quota-test`):
|
||||
|
||||
|
||||
```
|
||||
`$ kubectl delete -n quota-test`
|
||||
```
|
||||
|
||||
### Planning your quotas
|
||||
|
||||
There are many ways to control how users can deploy applications to avoid "land grabbing" in a Kubernetes cluster. Having a sound implementation of quotas, limit ranges, and other native features contributes to a cluster's stability.
|
||||
|
||||
Implementing resource quotas on computing resources is an important design decision that you need to think carefully about—especially when deploying Kubernetes for running business-critical enterprise applications.
|
||||
|
||||
When defining quotas, it's important to include developers in your planning. Because of their application knowledge, they are your best resources for estimating what's required.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/20/12/kubernetes-resource-quotas
|
||||
|
||||
作者:[Mike Calizo][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/mcalizo
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/OSDC_secret_ingredient_520x292.png?itok=QbKzJq-N (Jars with food inside on a shelf)
|
||||
[2]: https://kubernetes.io/
|
||||
[3]: https://kubernetes.io/docs/concepts/policy/resource-quotas
|
||||
[4]: https://kubernetes.io/docs/concepts/policy/limit-range/
|
||||
[5]: https://opensource.com/sites/default/files/uploads/resourcequota_requests-limits.png (Requests and limits in Kubernetes resource quotas)
|
||||
[6]: https://creativecommons.org/licenses/by-sa/4.0/
|
||||
[7]: https://opensource.com/article/18/10/getting-started-minikube
|
||||
[8]: https://www.liquidweb.com/kb/how-to-install-minikube/
|
@ -0,0 +1,109 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Radicle: An Open-Source Decentralized App for Code Collaboration [P2P GitHub Alternative])
|
||||
[#]: via: (https://itsfoss.com/radicle-p2p/)
|
||||
[#]: author: (Ankush Das https://itsfoss.com/author/ankush/)
|
||||
|
||||
Radicle: An Open-Source Decentralized App for Code Collaboration [P2P GitHub Alternative]
|
||||
======
|
||||
|
||||
_**Brief: Radicle is an open-source project that aims to facilitate peer-to-peer code collaboration without depending on a centralized server. In other words, it’s a P2P alternative to GitHub.**_
|
||||
|
||||
Most of the open-source projects that we talk about are usually hosted at [GitHub][1] or other [GitHub alternatives like GitLab][2]. Even though you get many benefits and features from such platforms (not to mention the potential exposure), there are also downsides of using it.
|
||||
|
||||
For instance, [youtube-dl project was taken down by Microsoft][3] to comply with a DMCA request.
|
||||
|
||||
With a centralized approach, you do not have a lot of control and privacy. Of course, this may not be a big deal for many folks but if you are someone who does not want centralized servers, want to have peer-to-peer code collaboration feature, and something that works offline, [Radicle][4] will be a good tool for them.
|
||||
|
||||
### Radicle: A Peer-to-Peer Code Collaboration Platform
|
||||
|
||||
![][5]
|
||||
|
||||
[Radicle][4] is an open-source project that aims to provide a decentralized app for code collaboration. You can connect peer-to-peer if you need to share the project and work along with someone else.
|
||||
|
||||
It is still something in beta but it is definitely worth looking at. I did some quick tests without our team to see if the basic features to share the project works or not.
|
||||
|
||||
But, before you try it out, let me highlight the important features that you get with Radicle and what you can expect from it in the near future.
|
||||
|
||||
### Features of Radicle
|
||||
|
||||
![][6]
|
||||
|
||||
* Ability to add multiple remote peers
|
||||
* Manage multiple peers
|
||||
* Feature to follow a project from a specific peer
|
||||
* Share your project using a unique ID
|
||||
* Does not depend on central servers
|
||||
* No censorship
|
||||
* One network interconnected with peers
|
||||
* Ability to work offline
|
||||
* Local issues & patches
|
||||
* Built on Git to make it easy and comfortable for most developers
|
||||
* Your infrastructure
|
||||
* Ability to receive funding from your supporters (Ethereum)
|
||||
* Manage codebases together
|
||||
|
||||
|
||||
|
||||
Expect more features for bug reporting and code review in the near future considering that it is still in early development.
|
||||
|
||||
**Recommended Read:**
|
||||
|
||||
![][7]
|
||||
|
||||
#### [Meet LBRY, A Blockchain-based Decentralized Alternative to YouTube][8]
|
||||
|
||||
LBRY is a new Blockchain-based, open source platform for sharing digital content. It is gaining popularity as a decentralized alternative to YouTube but LBRY is more than just a video sharing service.
|
||||
|
||||
### Installing Radicle on Linux
|
||||
|
||||
It provides an AppImage for Linux distributions. So, no matter whether you have an Ubuntu-based system or an Arch system, you can easily use it on your Linux system. In case you do not know, please refer to our guide on [using AppImage in Linux][9] to get started quickly.
|
||||
|
||||
[Download Radicle][10]
|
||||
|
||||
### Thoughts on Using Radicle
|
||||
|
||||
![][11]
|
||||
|
||||
If you are familiar with [Git version control system][12], using this should be a breeze. I just did some basic testing where I created a test repository and shared it with my teammate.
|
||||
|
||||
It works quite well. But, you need to configure Git with your name and email address before you get started.
|
||||
|
||||
Of course, you will need the terminal to configure and use the git version control, but the GUI is easy to use and understand. It is easy to manage remotes, copy the unique ID to share the project, and you can explore more when you try to use it for your projects.
|
||||
|
||||
I’d advise you to experiment with it and go through the [documentation][13], [official site][4], along with their [GitHub page][14] before trying it out for an important project.
|
||||
|
||||
What do you think about Radicle? Even though it is in BETA phase, do you think it will gain traction and be something popular among the open-source developers?
|
||||
|
||||
Let me know your thoughts in the comments below!
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://itsfoss.com/radicle-p2p/
|
||||
|
||||
作者:[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://github.com/
|
||||
[2]: https://itsfoss.com/github-alternatives/
|
||||
[3]: https://itsfoss.com/youtube-dl-github-takedown/
|
||||
[4]: https://radicle.xyz/
|
||||
[5]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2020/12/radicle-featured.png?resize=800%2C462&ssl=1
|
||||
[6]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2020/12/radicle-upstream.jpg?resize=799%2C600&ssl=1
|
||||
[7]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2020/04/lbry-featured.jpg?fit=800%2C450&ssl=1
|
||||
[8]: https://itsfoss.com/lbry/
|
||||
[9]: https://itsfoss.com/use-appimage-linux/
|
||||
[10]: https://radicle.xyz/downloads.html
|
||||
[11]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2020/12/radicle-settings.jpg?resize=800%2C598&ssl=1
|
||||
[12]: https://git-scm.com/
|
||||
[13]: https://docs.radicle.xyz/docs/what-is-radicle.html
|
||||
[14]: https://github.com/radicle-dev
|
@ -0,0 +1,251 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Understanding 52-bit virtual address support in the Arm64 kernel)
|
||||
[#]: via: (https://opensource.com/article/20/12/52-bit-arm64-kernel)
|
||||
[#]: author: (Bhupesh Sharma https://opensource.com/users/bhsharma)
|
||||
|
||||
Understanding 52-bit virtual address support in the Arm64 kernel
|
||||
======
|
||||
The introduction of 64-bit hardware increased the need to handle larger
|
||||
address spaces.
|
||||
![Puzzle pieces coming together to form a computer screen][1]
|
||||
|
||||
After 64-bit hardware became available, the need to handle larger address spaces (greater than 232 bytes) became obvious. With some vendors now offering servers with 64TiB (or more) of memory, x86_64 and arm64 now allow addressing adress spaces greater than 248 bytes (available with the default 48-bit address support).
|
||||
|
||||
x86_64 addressed these use cases by enabling support for five-level page tables in both hardware and software. This enables addressing address spaces equal to 257 bytes (see [x86: 5-level paging enabling for v4.12][2] for details). It bumps the limits to 128PiB of virtual address space and 4PiB of physical address space.
|
||||
|
||||
arm64 achieved the same thing by introducing two new architecture extensions—ARMv8.2 LVA (Large Virtual Addressing) and ARMv8.2 LPA (Large Physical Addressing). These allow 4PiB of virtual address space and 4 PiB of physical address space (i.e., 252 bits each, respectively).
|
||||
|
||||
With ARMv8.2 architecture extensions available in new arm64 CPUs, the two new hardware extensions are now supported in open source software.
|
||||
|
||||
Starting with Linux kernel version 5.4, the 52-bit (Large) Virtual Address (VA) and Physical Address (PA) support was introduced for arm64 architecture. Although the [kernel documentation][3] describes these features and how they impact the new kernels running on older CPUs (which don't support 52-bit VA extension in hardware) and newer CPUs (which support 52-bit VA extensions in hardware), it can be complex for average users to understand them and how they can "opt-in" to receiving VAs from a 52-bit space.
|
||||
|
||||
Therefore, I will introduce these relatively new concepts in this article:
|
||||
|
||||
1. How the kernel memory layout got "flipped" for Arm64 after the support for these features was added
|
||||
2. The impact on userspace applications, especially the ones that provide debugging support (e.g., kexec-tools, makedumpfile, and crash-utility)
|
||||
3. How userspace applications can "opt-in" to receiving VAs from a 52-bit space by specifying an mmap hint parameter that is larger than 48 bits
|
||||
|
||||
|
||||
|
||||
### ARMv8.2 architecture LVA and LPA extensions
|
||||
|
||||
The ARMv8.2 architecture provides two important extensions: Large Virtual Addressing (LVA) and Large Physical Addressing (LPA).
|
||||
|
||||
ARMv8.2-LVA supports a larger VA space for each translation table base register of up to 52 bits when using the 64KB translation granule.
|
||||
|
||||
ARMv8.2-LPA allows:
|
||||
|
||||
* A larger intermediate physical address (IPA) and PA space of up to 52 bits when using the 64KB translation granule
|
||||
* A level 1 block size where the block covers a 4TB address range for the 64KB translation granule if the implementation supports 52 bits of PA
|
||||
|
||||
|
||||
|
||||
_Note that these features are supported only in the AArch64 state._
|
||||
|
||||
Currently, the following Arm64 Cortex-A processors support ARMv8.2 extensions:
|
||||
|
||||
* Cortex-A55
|
||||
* Cortex-A75
|
||||
* Cortex-A76
|
||||
|
||||
|
||||
|
||||
For more details, see the [Armv8 Architecture Reference Manual][4].
|
||||
|
||||
### Kernel memory layout on Arm64
|
||||
|
||||
With the ARMv8.2 extension adding support for LVA space (which is only available when running with a 64KB page size), the number of descriptors gets expanded in the first level of translation.
|
||||
|
||||
User addresses have bits 63:48 set to 0, while the kernel addresses have the same bits set to 1. TTBRx selection is given by bit 63 of the virtual address. The `swapper_pg_dir` contains only kernel (global) mappings, while the user `pgd` contains only user (non-global) mappings. The `swapper_pg_dir` address is written to TTBR1 and never written to TTBR0.
|
||||
|
||||
**AArch64 Linux memory layout with 64KB pages plus three levels (52-bit with hardware support):**
|
||||
|
||||
|
||||
```
|
||||
Start End Size Use
|
||||
-----------------------------------------------------------------------
|
||||
0000000000000000 000fffffffffffff 4PB user
|
||||
fff0000000000000 fff7ffffffffffff 2PB kernel logical memory map
|
||||
fff8000000000000 fffd9fffffffffff 1440TB [gap]
|
||||
fffda00000000000 ffff9fffffffffff 512TB kasan shadow region
|
||||
ffffa00000000000 ffffa00007ffffff 128MB bpf jit region
|
||||
ffffa00008000000 ffffa0000fffffff 128MB modules
|
||||
ffffa00010000000 fffff81ffffeffff ~88TB vmalloc
|
||||
fffff81fffff0000 fffffc1ffe58ffff ~3TB [guard region]
|
||||
fffffc1ffe590000 fffffc1ffe9fffff 4544KB fixed mappings
|
||||
fffffc1ffea00000 fffffc1ffebfffff 2MB [guard region]
|
||||
fffffc1ffec00000 fffffc1fffbfffff 16MB PCI I/O space
|
||||
fffffc1fffc00000 fffffc1fffdfffff 2MB [guard region]
|
||||
fffffc1fffe00000 ffffffffffdfffff 3968GB vmemmap
|
||||
ffffffffffe00000 ffffffffffffffff 2MB [guard region]
|
||||
```
|
||||
|
||||
**Translation table lookup with 4KB pages:**
|
||||
|
||||
|
||||
```
|
||||
+--------+--------+--------+--------+--------+--------+--------+--------+
|
||||
|63 56|55 48|47 40|39 32|31 24|23 16|15 8|7 0|
|
||||
+--------+--------+--------+--------+--------+--------+--------+--------+
|
||||
| | | | | |
|
||||
| | | | | v
|
||||
| | | | | [11:0] in-page offset
|
||||
| | | | +-> [20:12] L3 index
|
||||
| | | +-----------> [29:21] L2 index
|
||||
| | +---------------------> [38:30] L1 index
|
||||
| +-------------------------------> [47:39] L0 index
|
||||
+-------------------------------------------------> [63] TTBR0/1
|
||||
```
|
||||
|
||||
**Translation table lookup with 64KB pages:**
|
||||
|
||||
|
||||
```
|
||||
+--------+--------+--------+--------+--------+--------+--------+--------+
|
||||
|63 56|55 48|47 40|39 32|31 24|23 16|15 8|7 0|
|
||||
+--------+--------+--------+--------+--------+--------+--------+--------+
|
||||
| | | | |
|
||||
| | | | v
|
||||
| | | | [15:0] in-page offset
|
||||
| | | +----------> [28:16] L3 index
|
||||
| | +--------------------------> [41:29] L2 index
|
||||
| +-------------------------------> [47:42] L1 index (48-bit)
|
||||
| [51:42] L1 index (52-bit)
|
||||
+-------------------------------------------------> [63] TTBR0/1
|
||||
```
|
||||
|
||||
|
||||
|
||||
![][5]
|
||||
|
||||
opensource.com
|
||||
|
||||
### 52-bit VA support in the kernel
|
||||
|
||||
Since the newer kernels with the LVA support should run well on older CPUs (which don't support LVA extension in hardware) and the newer CPUs (which support LVA extension in hardware), the chosen design approach is to have a single binary that supports 52 bit (and must be able to fall back to 48 bit at early boot time if the hardware feature is not present). That is, the VMEMMAP must be sized large enough for 52-bit VAs and also must be sized large enough to accommodate a fixed `PAGE_OFFSET`.
|
||||
|
||||
This design approach requires the kernel to support the following variables for the new virtual address space:
|
||||
|
||||
|
||||
```
|
||||
VA_BITS constant the *maximum* VA space size
|
||||
|
||||
vabits_actual variable the *actual* VA space size
|
||||
```
|
||||
|
||||
So, while `VA_BITS` denotes the maximum VA space size, the actual VA space supported (depending on the switch made at boot time) is indicated by `vabits_actual`.
|
||||
|
||||
#### Flipping the kernel memory layout
|
||||
|
||||
The design approach of keeping a single kernel binary requires the kernel .text to be in the higher addresses, such that they are invariant to 48/52-bit VAs. Due to the Kernel Address Sanitizer (KASAN) shadow being a fraction of the entire kernel VA space, the end of the KASAN shadow must also be in the higher half of the kernel VA space for both 48 and 52 bit. (Switching from 48 bit to 52 bit, the end of the KASAN shadow is invariant and dependent on `~0UL`, while the start address will "grow" towards the lower addresses).
|
||||
|
||||
To optimize `phys_to_virt()` and `virt_to_phys()`, the `PAGE_OFFSET` is kept constant at `0xFFF0000000000000` (corresponding to 52 bit), this obviates the need for an extra variable read. The `physvirt` and `vmemmap` offsets are computed at early boot to enable this logic.
|
||||
|
||||
Consider the following physical vs. virtual RAM address space conversion:
|
||||
|
||||
|
||||
```
|
||||
/*
|
||||
* The linear kernel range starts at the bottom of the virtual address
|
||||
* space. Testing the top bit for the start of the region is a
|
||||
* sufficient check and avoids having to worry about the tag.
|
||||
*/
|
||||
|
||||
#define virt_to_phys(addr) ({ \
|
||||
if (!(((u64)addr) & BIT(vabits_actual - 1))) \
|
||||
(((addr) & ~PAGE_OFFSET) + PHYS_OFFSET)
|
||||
})
|
||||
|
||||
#define phys_to_virt(addr) ((unsigned long)((addr) - PHYS_OFFSET) | PAGE_OFFSET)
|
||||
|
||||
where:
|
||||
PAGE_OFFSET - the virtual address of the start of the linear map, at the
|
||||
start of the TTBR1 address space,
|
||||
PHYS_OFFSET - the physical address of the start of memory, and
|
||||
vabits_actual - the *actual* VA space size
|
||||
```
|
||||
|
||||
### Impact on userspace applications used to debug kernel
|
||||
|
||||
Several userspace applications are used to debug running/live kernels or analyze the vmcore dump from a crashing system (e.g., to determine the root cause of the kernel crash): kexec-tools, makedumpfile, and crash-utility.
|
||||
|
||||
When these are used for debugging the Arm64 kernel, there is also an impact on them because of the Arm64 kernel memory map getting "flipped." These applications also need to perform a translation table walk for determining a physical address corresponding to a virtual address (similar to how it is done in the kernel).
|
||||
|
||||
Accordingly, userspace applications must be modified as they are broken upstream after the "flip" was introduced in the kernel memory map.
|
||||
|
||||
I have proposed fixes in the three affected userspace applications; while some have been accepted upstream, others are still pending:
|
||||
|
||||
* [Proposed makedumpfile upstream fix][6]
|
||||
* [Proposed kexec-tools upstream fix][7]
|
||||
* [Fix accepted in crash-utility][8]
|
||||
|
||||
|
||||
|
||||
Unless these changes are made in userspace applications, they will remain broken for debugging running/live kernels or analyzing the vmcore dump from a crashing system.
|
||||
|
||||
### 52-bit userspace VAs
|
||||
|
||||
To maintain compatibility with userspace applications that rely on the ARMv8.0 VA space maximum size of 48 bits, the kernel will, by default, return virtual addresses to userspace from a 48-bit range.
|
||||
|
||||
Userspace applications can "opt-in" to receiving VAs from a 52-bit space by specifying an mmap hint parameter larger than 48 bits.
|
||||
|
||||
For example:
|
||||
|
||||
|
||||
```
|
||||
.mmap_high_addr.c
|
||||
\----
|
||||
|
||||
maybe_high_address = mmap(~0UL, size, prot, flags,...);
|
||||
```
|
||||
|
||||
It is also possible to build a debug kernel that returns addresses from a 52-bit space by enabling the following kernel config options:
|
||||
|
||||
|
||||
```
|
||||
` CONFIG_EXPERT=y && CONFIG_ARM64_FORCE_52BIT=y`
|
||||
```
|
||||
|
||||
_Note that this option is only intended for debugging applications and should **not** be used in production._
|
||||
|
||||
### Conclusions
|
||||
|
||||
To summarize:
|
||||
|
||||
1. Starting with Linux kernel version 5.14, the new Armv8.2 hardware extensions LVA and LPA are now well-supported in the Linux kernel.
|
||||
2. Userspace applications like kexec-tools and makedumpfile used for debugging the kernel are broken _right now_ and awaiting acceptance of upstream fixes.
|
||||
3. Legacy userspace applications that rely on Arm64 kernel providing it a 48-bit VA will continue working as-is, whereas newer userspace applications can "opt-in" to receiving VAs from a 52-bit space by specifying an mmap hint parameter that is larger than 48 bits.
|
||||
|
||||
|
||||
|
||||
* * *
|
||||
|
||||
_This article draws on [Memory Layout on AArch64 Linux][9] and [Linux kernel documentation v5.9.12][10]. Both are licensed under GPLv2.0._
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/20/12/52-bit-arm64-kernel
|
||||
|
||||
作者:[Bhupesh Sharma][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/bhsharma
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/puzzle_computer_solve_fix_tool.png?itok=U0pH1uwj (Puzzle pieces coming together to form a computer screen)
|
||||
[2]: https://lwn.net/Articles/716916/
|
||||
[3]: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/arm64/memory.rst
|
||||
[4]: https://developer.arm.com/documentation/ddi0487/latest/
|
||||
[5]: https://opensource.com/sites/default/files/arm64-multi-level-translation_0.png (arm64 Multi-level Translation)
|
||||
[6]: http://lists.infradead.org/pipermail/kexec/2020-September/021372.html
|
||||
[7]: http://lists.infradead.org/pipermail/kexec/2020-September/021333.html
|
||||
[8]: https://github.com/crash-utility/crash/commit/1c45cea02df7f947b4296c1dcaefa1024235ef10
|
||||
[9]: https://www.kernel.org/doc/html/latest/arm64/memory.html
|
||||
[10]: https://elixir.bootlin.com/linux/latest/source/arch/arm64/include/asm/memory.h
|
@ -0,0 +1,107 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Explore the exciting features of the Howl text editor)
|
||||
[#]: via: (https://opensource.com/article/20/12/howl)
|
||||
[#]: author: (Seth Kenlon https://opensource.com/users/seth)
|
||||
|
||||
Explore the exciting features of the Howl text editor
|
||||
======
|
||||
Howl is a general-purpose text editor with a super-efficient workflow
|
||||
and plenty of features to keep it fun and interesting.
|
||||
![Typewriter in the grass][1]
|
||||
|
||||
Howl is a general-purpose text editor written in Moonscript and Lua. It’s not focused on a specific programming language, and instead features support for many different languages and formats. In fact, it takes inspiration from "traditional" Unix editors like [Emacs][2] and [Vim][3], so it feels familiar to anyone accustomed to that style of editing. It’s primarily a text-oriented interface, without dialogue boxes, toolbars, or a menu, and yet, it has many exciting features that make it feel a little like an IDE for authors, regardless of whether you write code or prose.
|
||||
|
||||
![Howl][4]
|
||||
|
||||
### Install
|
||||
|
||||
Howl is developed on Linux and for Linux. However, it’s written in Lua with some GTK wrapping, both of which are cross-platform, so if you’re keen to compile code, you can test Howl on Windows or macOS.
|
||||
|
||||
The compile process is relatively simple, provided you have LuaJIT and GTK development libraries installed. In this sample command, `X.Y` represents a version number in tag form:
|
||||
|
||||
|
||||
```
|
||||
$ git clone --depth 1
|
||||
–branch X.Y
|
||||
<https://github.com/howl-editor/howl.git>
|
||||
$ cd howl-X.Y/src
|
||||
$ make
|
||||
$ make install
|
||||
```
|
||||
|
||||
You can launch Howl from your application menu or from a terminal.
|
||||
|
||||
### Using Howl
|
||||
|
||||
Howl is a lightweight editor. It has a fast startup time and a small overall footprint. This is, in part, thanks to LuaJIT, a just-in-time (JIT) compiler for the [Lua programming language][5].
|
||||
|
||||
When you first launch it, the Howl interface is a single empty window. The Howl window contains one view by default, but it can contain more. For instance, you can press **Alt+X** to bring up a command-line view in your Howl window.
|
||||
|
||||
![Black Howl command line box with cursor][6]
|
||||
|
||||
The command line lets you enter editor commands. You use it a lot because Howl has no menu bar and no toolbar. Conveniently, you can press **Tab** for suggested command completion as you type, so it’s actually much faster than a traditional menu for locating a function, even when you don’t know the exact name of the function you’re looking for.
|
||||
|
||||
To dismiss the command-line view, press **Esc** on your keyboard.
|
||||
|
||||
### Opening a file
|
||||
|
||||
To open a file in Howl, press **Alt+X** to bring up a command line and then type `open` followed by a **Space**. Howl displays a new temporary view: a view into your file system so you can choose a file to open. You can choose a file by either typing its path or by clicking on the file you want.
|
||||
|
||||
### Editing text with Howl
|
||||
|
||||
Howl’s interface is optimized for its primary function: to edit text. It makes composing words, whether in code or in a natural language, sublimely efficient. As you type, regardless of what you’re typing, Howl offers predictive completion of the current word. To complete a word as it’s being suggested, press **Return** or **Enter** on your keyboard.
|
||||
|
||||
Everything that happens in the Howl editor view is a function. For instance, when you select a word and press **Ctrl+C** to copy it, you are invoking the `editor-copy` function, which is assigned the **Ctrl+C** key binding. You might be surprised at how many functions are available. For instance, you can copy an entire line of text with the `editor-copy-line` function by typing **Alt+X** to bring up the command-line view and then `editor-copy-line`. If you hadn’t already just read about it here, you might have discovered the function on your own the same way I did: open a command-line view, type a keyword, such as "copy," and press **Tab** for relevant suggestions.
|
||||
|
||||
When you discover functions through the command-line view, you’re also provided with the function’s default keyboard shortcut, if there is one.
|
||||
|
||||
![Black Howl terminal box with white, gray and pink code][7]
|
||||
|
||||
### Saving a file
|
||||
|
||||
After you’re done writing or programming (or both), you probably want to save your work. You can do that, as you might guess, with the `save` function. Open a command-line view with **Alt+X** and then type `save`, or just press **Ctrl+S** on your keyboard.
|
||||
|
||||
### Quit
|
||||
|
||||
Howl is such a great editor, you probably won’t want to quit. However, sometimes you want to experience the joy of opening Howl to see how quickly it loads, and in order to do that, you have to exit. To exit the application, open a command-line view with **Alt+X** and then type `quit`.
|
||||
|
||||
### Extensions and configuration
|
||||
|
||||
Howl doesn’t have an extension language because it’s written in Moonscript and Lua, using the same API available for everyone else. Said another way: Howl is its own extension. Should you find the Howl API insufficient, you can code directly in C by using LuaJIT’s [FFI library][8].
|
||||
|
||||
You can configure Howl in a file called `~/.howl/init.moon` (for Moonscript) or `~/.howl/init.lua` (for Lua).
|
||||
|
||||
Configurable options in Howl are displayed as configuration variables. You can set these variables interactively from within Howl using the `set` command, or you can define them in your Howl init file. To discover new configuration variables, type the `set` command into Howl’s command line, and then press the **Spacebar** to see potential completions.
|
||||
|
||||
If you’re not familiar with Lua, check out my [Lua cheat sheet][9]. Moonscript is arguably even easier if you’re not familiar with Lua yet.
|
||||
|
||||
### Use this editor
|
||||
|
||||
Howl is a pleasure to use and exciting to explore. It’s a lean, focused, and efficient editor with lots of features and an extensible design. If you’re a fan of text, text editing, Lua, or just plain good application design, start using Howl. You won’t `quit` any time soon (but not because you don’t know how).
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/20/12/howl
|
||||
|
||||
作者:[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/doc-dish-lead.png?itok=h3fCkVmU (Typewriter in the grass)
|
||||
[2]: https://opensource.com/article/20/2/who-cares-about-emacs
|
||||
[3]: https://opensource.com/article/20/3/vim-skills
|
||||
[4]: https://opensource.com/sites/default/files/31-howl.jpg (Howl)
|
||||
[5]: https://opensource.com/article/20/2/lua-cheat-sheet
|
||||
[6]: https://opensource.com/sites/default/files/uploads/howl-command-31-howl-opensource.jpg (Black Howl command line box with cursor)
|
||||
[7]: https://opensource.com/sites/default/files/uploads/howl-tab-31-howl-opensource.jpg (Black Howl terminal box with white, gray and pink code)
|
||||
[8]: https://luajit.org/ext_ffi.html
|
||||
[9]: http://opensource.com/article/20/2/lua-cheat-sheet
|
@ -0,0 +1,13 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (How to hack Android Auto to display custom content)
|
||||
[#]: via: (https://opensource.com/article/20/12/android-auto-open-source)
|
||||
[#]: author: (Tomasz Grobelny https://opensource.com/users/grobelny)
|
||||
|
||||
How to hack Android Auto to display custom content
|
||||
======
|
||||
Reimplement the Android Auto protocol to cast movies and additional
|
||||
applications on automotive head unit displays.
|
68
sources/tech/20201218 The role of empathy in DevOps.md
Normal file
68
sources/tech/20201218 The role of empathy in DevOps.md
Normal file
@ -0,0 +1,68 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (The role of empathy in DevOps)
|
||||
[#]: via: (https://opensource.com/article/20/12/empathy-devops)
|
||||
[#]: author: (Will Kelly https://opensource.com/users/willkelly)
|
||||
|
||||
The role of empathy in DevOps
|
||||
======
|
||||
DevOps is all about people, and people need empathy to thrive and be
|
||||
productive. Here's how to build it into your team.
|
||||
![Teamwork starts with communication across silos][1]
|
||||
|
||||
DevOps teams dig in their heels for strength as they face stress and challenges at work and home. It’s not something covered in the [DevOps manifesto][2]. There’s also no software you can integrate into your toolchain to help either. What needs to happen is your DevOps teams need to put empathy before tools.
|
||||
|
||||
In his book, _[The DevOps Paradox][3]_, Viktor Farcic reasons, if DevOps is, at a fundamental level, about getting different teams to collaborate, you could say that DevOps is a discipline that promotes empathy.
|
||||
|
||||
### Recognizing DevOps is a people game
|
||||
|
||||
If you agree with Farcic, you see DevOps, at its roots, as a people game. When I was coming up in the tech industry as a technical writer, I realized that development and operations teams spoke different languages. They also had their own cultures. These differences were at the root of arguments between those teams.
|
||||
|
||||
"Over the last few decades, though, the notion that empathy cannot co-exist with critical thinking has been slowly diminishing, but not fast enough to have a widespread impact within our industry," according to _[InfoQ][4]_.
|
||||
|
||||
Empathy becomes part of the DevOps equation as you develop [more partnerships][5] across your software delivery and business organizations. The silos that arise during waterfall software development include those between software developers, security, and operations. Cultural stereotypes abound between departments. Some software developers are OK with breaking things. The security team is the department of "no." Operations teams want to maintain a pristine operational state, never taking risks, while abiding by their service level agreements (SLAs). Let’s not forget that business stakeholders may be out of touch with all those operations. Poking and jabbing at each other’s real or perceived competence is counterproductive. Talking to each other and learning the other team’s processes, appreciating what keeps them up at night, is a powerful step to understanding each other.
|
||||
|
||||
The cross-team relationships prevalent in DevOps make empathy necessary. There’s no room in a DevOps toolchain for the stereotypical animosity between developers, operations, and security. Keep your communications channels open. Encourage a culture where making mistakes is about learning and change, not recriminations.
|
||||
|
||||
### Practicing empathy in DevOps
|
||||
|
||||
Promoting empathy throughout the team is a must for DevOps managers. As a manager, you need to look for opportunities to embed technologists across your business units for one. Getting people to talk across teams is another crucial goal for managers. While DevOps aims to break down silos, it doesn’t mean that old rivalries from your pre-DevOps world will go away overnight.
|
||||
|
||||
Building empathy as a team isn’t about watching an online training video and clicking through a quiz to receive a PDF of a certificate of completion. It starts with relationship building. Look for opportunities to cross-train team members in other jobs. It’s not about preparing them to do the job; it’s about showing them the challenges their other team members face and facilitating knowledge transfer. Manage change in iterations and give your team—developers and sysadmins alike—a feedback channel where problems, challenges, and victories can get the ear of management and their team members.
|
||||
|
||||
Empathy powers productivity because it gives your team members a sense of safety, which is a feeling that may be in short supply right now for some team members. Empathy and a little understanding can take some pressure off team members, giving them some more fuel to focus on their tasks at hand.
|
||||
|
||||
### Providing empathy as a developer
|
||||
|
||||
You also must treat your customer conversations with empathy. Whether your DevOps team is serving internal or external customers, you’re bound to notice some personal and business changes in the customer. Leading organizations create value and show empathy in several ways: streamlining or simplifying the customer experience, reacting to the market and environmental changes in near real-time, and predicting customer needs ahead of time, according to _[The Enterprisers Project][6]_.
|
||||
|
||||
Other industry watchers see that developers with empathy are best prepared for the rise of artificial intelligence (AI) and empathy helps DevOps teams adjust to more agile forms of thinking.
|
||||
|
||||
### Empathy and remote DevOps during COVID-19
|
||||
|
||||
Providing empathy during this time starts with remembering that you don’t know what somebody is going through when the web conferencing camera is off. It’s something I’ve had to remind myself a bunch of times since the beginning of the pandemic.
|
||||
|
||||
The next steps for remote work are different for all of us. Some DevOps teams will return to their offices at some point in 2021. Some may find themselves in hybrid working arrangements while other groups may remain remote. Unfortunately, some DevOps teams may split up as their employers conduct layoffs, and lucky coworkers land new positions with other employers. As in our personal lives, each unique and developing work situation requires a measure of empathy to help steer the team through change.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/20/12/empathy-devops
|
||||
|
||||
作者:[Will Kelly][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/willkelly
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/happy-team-sticker-laptop.png?itok=91K77IgE (Teamwork starts with communication across silos)
|
||||
[2]: https://sites.google.com/a/jezhumble.net/devops-manifesto/
|
||||
[3]: https://www.amazon.com/DevOps-Paradox-truth-about-people/dp/1789133637
|
||||
[4]: https://www.infoq.com/articles/guide-empathy-boost-career/
|
||||
[5]: https://enterprisersproject.com/article/2020/8/it-leadership-how-build-empathy
|
||||
[6]: https://enterprisersproject.com/article/2020/7/customer-experience-how-develop-empathy
|
190
sources/tech/20201218 Using pods with Podman on Fedora.md
Normal file
190
sources/tech/20201218 Using pods with Podman on Fedora.md
Normal file
@ -0,0 +1,190 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Using pods with Podman on Fedora)
|
||||
[#]: via: (https://fedoramagazine.org/podman-pods-fedora-containers/)
|
||||
[#]: author: (Darshna Das https://fedoramagazine.org/author/climoiselle/)
|
||||
|
||||
Using pods with Podman on Fedora
|
||||
======
|
||||
|
||||
![Using Pods with Podman][1]
|
||||
|
||||
Photo by [Dick Martin][2] on [Unsplash][3]
|
||||
|
||||
This article shows the reader how easy it is to get started using pods with Podman on Fedora. But what is Podman? Well, we will start by saying that Podman is a container engine developed by Red Hat, and yes, if you thought about Docker when reading container engine, you are on the right track. A whole new revolution of containerization started with Docker, and Kubernetes added the concept of pods in the area of container orchestration when dealing with containers that share some common resources. But hold on! Do you really think it is worth sticking with Docker alone by assuming it’s the only effective way of containerization? Podman can also manage pods on Fedora as well as the containers used in those pods.
|
||||
|
||||
> [Podman][4] is a daemonless, open source, Linux native tool designed to make it easy to find, run, build, share and deploy applications using Open Containers Initiative ([OCI][5]) [Containers][6] and [Container Images][7].
|
||||
>
|
||||
> From the official Podman documentation at <http://docs.podman.io/en/latest/>
|
||||
|
||||
### Why should we switch to Podman?
|
||||
|
||||
Podman is a daemonless container engine for developing, managing, and running OCI Containers on your Linux System. Containers can either be run as root or in rootless mode. Podman directly interacts with an image registry, containers and image storage.
|
||||
|
||||
### Install Podman:
|
||||
|
||||
```
|
||||
sudo dnf -y install podman
|
||||
```
|
||||
|
||||
### Creating a Pod:
|
||||
|
||||
To start using the pod we first need to create it and for that we have a basic command structure
|
||||
```
|
||||
|
||||
```
|
||||
|
||||
$ podman pod create
|
||||
```
|
||||
|
||||
```
|
||||
|
||||
![][8]
|
||||
|
||||
The command above contains no arguments and hence it will create a pod with a randomly generated name. You might however, want to give your pod a relevant name. For that you just need to modify the above command a bit.
|
||||
```
|
||||
|
||||
```
|
||||
|
||||
$ podman pod create --name climoiselle
|
||||
```
|
||||
|
||||
```
|
||||
|
||||
![][9]
|
||||
|
||||
The pod will be created and will report back to you the ID of the pod. In the example shown the pod was given the name ‘climoiselle’. To view the newly created pod is easy by using the command shown below:
|
||||
```
|
||||
|
||||
```
|
||||
|
||||
$ podman pod list
|
||||
```
|
||||
|
||||
```
|
||||
|
||||
![Newly created pods have been deployed][10]
|
||||
|
||||
As you can see, there are two pods listed here, one named darshna and the one created from the example named climoiselle. No doubt you notice that both pods already include one container, yet we sisn’t deploy a container to the pods yet. What is that extra container inside the pod? This randomly generated container is an infra container. Every podman pod includes this infra container and in practice these containers do nothing but go to sleep. Their purpose is to hold the namespaces associated with the pod and to allow Podman to connect other containers to the pod. The other purpose of the infra container is to allow the pod to keep running when all associated containers have been stopped.
|
||||
|
||||
You can also view the individual containers within a pod with the command:
|
||||
```
|
||||
|
||||
```
|
||||
|
||||
$ podman ps -a --pod
|
||||
```
|
||||
|
||||
```
|
||||
|
||||
![][11]
|
||||
|
||||
### Add a container
|
||||
|
||||
The cool thing is, you can add more containers to your newly deployed pod. Always remember the name of your pod. It’s important as you’ll need that name in order to deploy the container in that pod. We’ll use the official ubuntu image and deploy a container using it running the top command.
|
||||
```
|
||||
|
||||
```
|
||||
|
||||
$ podman run -dt --pod climoiselle ubuntu top
|
||||
```
|
||||
|
||||
```
|
||||
|
||||
![][12]
|
||||
|
||||
### Everything in a Single Command:
|
||||
|
||||
Podman has an agile characteristic when it comes to deploying a container in a pod which you created. You can create a pod and deploy a container to the said pod with a single command using Podman. Let’s say you want to deploy an NGINX container, exposing external port 8080 to internal port 80 to a new pod named test_server.
|
||||
```
|
||||
|
||||
```
|
||||
|
||||
$ podman run -dt --pod new:test_server -p 8080:80 nginx
|
||||
```
|
||||
|
||||
```
|
||||
|
||||
![Created a new pod and deployed a container together][13]
|
||||
|
||||
Let’s check all pods that have been created and the number of containers running in each of them …
|
||||
```
|
||||
|
||||
```
|
||||
|
||||
$ podman pod list
|
||||
```
|
||||
|
||||
```
|
||||
|
||||
![List of the containers, their state and number of containers running into them][14]
|
||||
|
||||
Do you want to know a detailed configuration of the pods which are running? Just type in the command shown below:
|
||||
```
|
||||
|
||||
```
|
||||
|
||||
podman pod inspect [pod's name/id]
|
||||
```
|
||||
|
||||
```
|
||||
|
||||
![][15]
|
||||
|
||||
### Make it stop!
|
||||
|
||||
To stop the pods, we need to use the name or ID of the pod. With the information from podman’s pod list command, we can view the pods and their infra id. Simply use podman with the command stop and give the particular name/infra id of the pod.
|
||||
```
|
||||
|
||||
```
|
||||
|
||||
$ podman pod stop climoiselle
|
||||
```
|
||||
|
||||
```
|
||||
|
||||
![][16]
|
||||
|
||||
### Hey take a look!
|
||||
|
||||
![My pod climoiselle stopped][17]
|
||||
|
||||
After following this short tutorial, you can see how quickly you can use pods with podman on fedora. It’s an easy and convenient way to use containers that share resources and interact together.
|
||||
|
||||
### Further reading
|
||||
|
||||
The fedora Classrom article <https://fedoramagazine.org/fedora-classroom-containers-101-podman/>. A good starting point for beginners <https://developers.redhat.com/blog/2018/02/22/container-terminology-practical-introduction/>. An article on capabilities and podman <https://fedoramagazine.org/podman-with-capabilities-on-fedora/>. Podman’s documentation site <http://docs.podman.io/en/latest/>.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://fedoramagazine.org/podman-pods-fedora-containers/
|
||||
|
||||
作者:[Darshna 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://fedoramagazine.org/author/climoiselle/
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://fedoramagazine.org/wp-content/uploads/2020/12/using-pods-w-podman-816x346.png
|
||||
[2]: https://unsplash.com/@dick42420?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText
|
||||
[3]: https://unsplash.com/s/photos/seals-in-canada?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText
|
||||
[4]: http://podman.io
|
||||
[5]: https://www.opencontainers.org/
|
||||
[6]: https://developers.redhat.com/blog/2018/02/22/container-terminology-practical-introduction/#h.j2uq93kgxe0e
|
||||
[7]: https://developers.redhat.com/blog/2018/02/22/container-terminology-practical-introduction/#h.dqlu6589ootw
|
||||
[8]: https://fedoramagazine.org/wp-content/uploads/2020/12/Podman0-1-1-1024x328.png
|
||||
[9]: https://fedoramagazine.org/wp-content/uploads/2020/12/Podman1-1-1024x355.png
|
||||
[10]: https://fedoramagazine.org/wp-content/uploads/2020/12/podman3-1024x334.png
|
||||
[11]: https://fedoramagazine.org/wp-content/uploads/2020/12/podman4-1-1024x221.png
|
||||
[12]: https://fedoramagazine.org/wp-content/uploads/2020/12/podman8-1024x739.png
|
||||
[13]: https://fedoramagazine.org/wp-content/uploads/2020/12/podman9-1024x348.png
|
||||
[14]: https://fedoramagazine.org/wp-content/uploads/2020/12/podman10-1024x341.png
|
||||
[15]: https://fedoramagazine.org/wp-content/uploads/2020/12/podman5-808x1024.png
|
||||
[16]: https://fedoramagazine.org/wp-content/uploads/2020/12/podman11-1024x279.png
|
||||
[17]: https://fedoramagazine.org/wp-content/uploads/2020/12/podman12-1024x362.png
|
@ -0,0 +1,84 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (6 ways this fullscreen text editor improves focus)
|
||||
[#]: via: (https://opensource.com/article/20/12/focuswriter)
|
||||
[#]: author: (Seth Kenlon https://opensource.com/users/seth)
|
||||
|
||||
6 ways this fullscreen text editor improves focus
|
||||
======
|
||||
This fullscreen editor helps you set your writing goals and keeps
|
||||
distractions to a minimum so you can achieve them.
|
||||
![Typewriter with hands][1]
|
||||
|
||||
The great thing about computers is that they’re really good at multi-tasking.
|
||||
|
||||
The bad thing about computers is that they’re really good at multi-tasking.
|
||||
|
||||
Whether you consider yourself, as a human, good or bad at multi-tasking, sometimes you need a little help focusing. One of those times is when you’re trying to compose clear and concise communication. And that’s exactly why Focuswriter was developed.
|
||||
|
||||
### Install
|
||||
|
||||
On Linux, you can install Focuswriter as a Flatpak from [Flathub][2].
|
||||
|
||||
On Windows or Linux (if you don’t use Flatpak), you can [install Focuswriter from its website][3]. You can also install from source code, also available from the Focuswriter webpage.
|
||||
|
||||
### Using Focuswriter
|
||||
|
||||
Focuswriter is, admittedly, actually a cross between a text editor and a word processor. Its default format is the Open Document Text (.odt) format, so it allows you to style and align text, mark headers, and toggle smart quotes on and off. But that’s where its word processor features end because Focuswriter does mostly focus on _writing_, not on styling what you’ve written.
|
||||
|
||||
Focuswriter encourages focus in a few different ways.
|
||||
|
||||
#### Attractiveness
|
||||
|
||||
Focuswriter doesn’t look like your usual computer application, much less your usual text editor. When it launches, it loads a theme behind your document. The theme is generally benign—a writing desk is the default, but there’s also a starry sky, a faraway landscape, and so on. You’re not meant to become preoccupied with the theme, of course, but it does help you from getting distracted by some other application window or your computer desktop lingering behind your editor. Because it’s easy to customize, there’s little chance of you being left without a theme you like.
|
||||
|
||||
![Focuswriter white box with gray wording on wooden writing desk background theme][4]
|
||||
|
||||
#### Sound effects
|
||||
|
||||
Focuswriter is actually fun to use. Aside from its visual theme, it also has an _optional_ typewriter audio theme. Once enabled, every keypress makes the sound of a mechanical typewriter key. When you press **Return**, the satisfying sound of a carriage return is your reward for completing a paragraph (or a line, if you write one sentence per line to improve version control).
|
||||
|
||||
This audio theme is entirely opt-in, and it’s not on by default. You may doubt its efficacy, but you shouldn’t underestimate the satisfaction of making those sounds of productivity while also wielding the powers of modern text editing.
|
||||
|
||||
#### Fullscreen display
|
||||
|
||||
Focuswriter not only launches fullscreen by default, but it also hides its menus and other widgets from view. To access the main menu bar, you place your cursor to the top of your screen until it appears. There’s a scroll bar hidden on the right, a document switcher widget on the left, and a status bar at the bottom.
|
||||
|
||||
#### Minimalism
|
||||
|
||||
There isn’t much to Focuswriter’s editing capabilities. It doesn’t have advanced search options or specialized options for code formatting or syntax highlighting. It lets you write text, and little else, into a document, by design. Even the contextual right-click menu only offers basic editing functions (copy, cut, paste, and so on) or spell-checking options.
|
||||
|
||||
#### Line focus
|
||||
|
||||
Another optional feature of Focuswriter is its ability to "grey out" all lines of text but your current one. This helps your eyes lazily locate your current line of text, which can be especially helpful if you’re not a touch-typist or if you’re transcribing something you’ve handwritten on physical paper and must look away from the screen often.
|
||||
|
||||
#### Goal tracker
|
||||
|
||||
You can set a daily word count goal or a timed goal for yourself in Focuswriter’s preferences. Your progress is tracked as you work and displayed in the status bar at the bottom of the screen. It’s hidden from your view unless you hover your cursor over it, so you’re not compelled to obsess over it, but it’s convenient enough to help you stay on track.
|
||||
|
||||
### Try Focuswriter (even if you think it’s silly)
|
||||
|
||||
I’ve heard about fullscreen text editors before, and I’ve never felt it was important for me to try one. After all, nearly any application can be made fullscreen, and I don’t personally have trouble focusing anyway.
|
||||
|
||||
Having tried Focuswriter, though, I understand the appeal of a good fullscreen "focus first" text editor. It may not be necessary, but then again, open source is thriving. We have the luxury of redundant sets of applications that have minor differences in function but major differences in implementation. Focuswriter makes writing fun; it makes the work enjoyable. Download it, set a goal, and get writing!
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/20/12/focuswriter
|
||||
|
||||
作者:[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/typewriter-hands.jpg?itok=oPugBzgv (Typewriter with hands)
|
||||
[2]: https://flathub.org/apps/details/org.gottcode.FocusWriter
|
||||
[3]: https://gottcode.org/focuswriter/
|
||||
[4]: https://opensource.com/sites/default/files/uploads/focuswriter-31_days_focuswriter-opensource.png (Focuswriter white box with gray wording on wooden writing desk background theme)
|
@ -0,0 +1,242 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Learn a new old language by programming a game in Algol 68)
|
||||
[#]: via: (https://opensource.com/article/20/12/learn-algol-68)
|
||||
[#]: author: (Chris Hermansen https://opensource.com/users/clhermansen)
|
||||
|
||||
Learn a new old language by programming a game in Algol 68
|
||||
======
|
||||
Even "dead languages" can teach you a lot about programming today.
|
||||
![Old UNIX computer][1]
|
||||
|
||||
In this article series, Opensource.com [Correspondents][2] and others have been writing the same "guess the number" game in various programming languages. This exercise shows how the basic concepts you'll find in most programming languages—variables, expressions, and statements—can be applied to learn new languages.
|
||||
|
||||
Most languages have a "way of doing things" that's supported by their design, and those ways can be quite different from one program to another. These ways include modularity (grouping related functionality together), declarative vs. imperative, object-orientation, low- vs. high-level syntactic features, and so on.
|
||||
|
||||
In the "guess the number" program, the computer picks a number between one and 100 and asks you to guess the number. The program loops until you guess the right answer.
|
||||
|
||||
In this article, I'll show you how to write this application in Algol 68. I'll also try to exercise the following concepts you'll find in any programming language:
|
||||
|
||||
* Variables
|
||||
* Input
|
||||
* Output
|
||||
* Conditional evaluation
|
||||
* Loops
|
||||
|
||||
|
||||
|
||||
### Guess the number in Algol 68
|
||||
|
||||
This example uses the [Algol 68][3] Genie compiler, available in many Linux distros, created by [Marcel Van Der Veer][4].
|
||||
|
||||
OK, I can hear some of you out there moaning, "oh no, why Algol 68? That language is so old and has been irrelevant since before there were implementations." And I respect your opinions, I really do. Really. But I believe many cool things exist in today's programming languages that come from the hard thinking done by the designers of Algol 68, which justifies learning a bit about the language.
|
||||
|
||||
Algol 68 is statically typed and not particularly verbose. Algol 68 Genie compiles and executes in one go, so Algol 68 can feel a bit like a scripting language. The Genie implementation offers many useful hooks into our favorite operating system, which keeps it from feeling horribly dated and means a fair bit of useful work can be done with it.
|
||||
|
||||
Some points worth mentioning at the outset:
|
||||
|
||||
* One of Algol 68's design principles is letting anything that could reasonably be thought of as an expression (a construct that delivers a value) be legal code.
|
||||
* Algol 68 "reserved words" are typically expressed as boldface symbols in the program source, which is kind of hard to do with text files, so most compilers have a way of indicating that a token is a reserved word. In Algol 68 Genie, the default is to use all upper case letters; for example, `BEGIN`, `IF`, `THEN`, etc.
|
||||
* Speaking of things like `BEGIN … END`, `IF … THEN … ELSE`, Algol 68 has a "closed syntax." A `BEGIN` must have a corresponding `END`, similar to `{ }` in C or Java; an `IF` must have a `FI`, and a `DO` must have an `OD`.
|
||||
* Algol 68 generally treats whitespace as irrelevant—even within numbers or variable names. Therefore, `myvariablename` and `my variable name` (and even `myvar iablename`) all refer to the same variable.
|
||||
* Algol 68 requires "go on symbols"—semicolons—between (but not following) statements in a sequence to be evaluated statement-by-statement.
|
||||
* Algol 68 incorporates a "string" type but does not provide a rich set of string processing primitives, which can be a bit frustrating.
|
||||
* Algol 68 is imperative rather than declarative and not object-oriented.
|
||||
|
||||
|
||||
|
||||
With that preamble, here is my "guess the number" implementation (with line numbers to make it easier to review some of the specific features):
|
||||
|
||||
|
||||
```
|
||||
1 on logical file end (stand in,
|
||||
2 (REF FILE f) BOOL: (print(("Goodbye!",new line));stop));
|
||||
|
||||
3 first random(42);
|
||||
4 INT random number = ENTIER (next random * 100.0) + 1;
|
||||
|
||||
5 print(("the secret number is",random number,new line));
|
||||
|
||||
6 print("guess a number: ");
|
||||
7 WHILE
|
||||
8 INT guess = read int;
|
||||
9 IF guess < random number THEN
|
||||
10 print("too low, try again: ");
|
||||
11 TRUE
|
||||
12 ELIF guess > random number THEN
|
||||
13 print("too high, try again: ");
|
||||
14 TRUE
|
||||
15 ELSE
|
||||
16 print(("that's right",new line));
|
||||
17 FALSE
|
||||
18 FI
|
||||
19 DO SKIP OD
|
||||
```
|
||||
|
||||
### Breaking it down
|
||||
|
||||
Jumping right in: lines 1 and 2 define what happens when an end of file is detected on the input coming from the console.
|
||||
|
||||
This situation is managed by calling the procedure `on logical file end` and passing two arguments: a file to be monitored and a procedure to be called when the end of file is detected. The file you want to monitor is the standard input, `stand in`. Line 2 is the definition of the procedure; this is an expression that yields a procedure. It has one parameter, which is a pointer to a file named "f" that is written as `REF FILE f`. It returns a boolean value, indicated by `BOOL`.
|
||||
|
||||
The text after the `:` is the procedure body, which:
|
||||
|
||||
* Starts with a brief begin symbol, `(`
|
||||
* Is followed by a call to the `print` procedure with a list of two arguments, the string `"Goodbye!"` and the `new line` procedure that will emit a newline in the output stream
|
||||
* Is followed by a "go on symbol"—the semicolon
|
||||
* Is followed by a call to the procedure `stop`
|
||||
* Is followed by the brief end symbol, `)`
|
||||
* Is followed by the parenthesis closing the list of arguments to the "on logical file end "call
|
||||
* Is followed by the "go on symbol," `;`
|
||||
|
||||
|
||||
|
||||
More verbosely, I could have written this procedure definition as:
|
||||
|
||||
|
||||
```
|
||||
(REF FILE f) BOOL: BEGIN
|
||||
print(("Goodbye!",new line));
|
||||
stop
|
||||
END
|
||||
```
|
||||
|
||||
It's probably worth mentioning that Algol 68 makes a very strong distinction between values and references to values. An Algol 68 value is conceptually similar to a constant or immutable or final value seen in many of today's popular programming languages. A value cannot be changed. A reference to a value, on the other hand, essentially defines a location where a value can be stored and the contents of that location can be changed. This corresponds to a variable, or mutable, or non-final value.
|
||||
|
||||
By way of concrete examples:
|
||||
|
||||
|
||||
```
|
||||
`INT forty two = 42`
|
||||
```
|
||||
|
||||
defines an "integer value" named `forty two`, which evaluates to the number `42`.
|
||||
|
||||
And:
|
||||
|
||||
|
||||
```
|
||||
`INT fink := 42`
|
||||
```
|
||||
|
||||
defines an integral variable `fink` and uses `:=` to assign the value `42` to it. This expression is actually shorthand for:
|
||||
|
||||
|
||||
```
|
||||
REF INT fink = LOC INT;
|
||||
fink := 42
|
||||
```
|
||||
|
||||
This makes the correspondence between values (`INT forty two`) and variables (`REF INT fink`) clearer at the expense of some verbosity. The `LOC INT` thing is a "local generator"—space for an integer value is allocated on the stack. There is also a "heap generator" useful for building structures that persist across procedure calls.
|
||||
|
||||
Phew! Back to the code.
|
||||
|
||||
Lines 3 and 4 initialize the system random number generator by calling the "setup" procedure first random() with an integer "seed" argument (which kinda hasta be 42, right?), then calling the procedure next random—which takes no arguments and therefore doesn't require parentheses with nothing between—and multiplies that by 100 to give a result between 0.0 and 99.9999…, truncating the result created using the unary operator ENTIER to give a result between 0 and 99, and finally adding 1 to give a result between 1 and 100.
|
||||
|
||||
Worth mentioning at this point is that Algol 68 seems to be the first language to support the definition of unary and binary operators, which are distinct from procedures. You must put parentheses around the expression:
|
||||
|
||||
|
||||
```
|
||||
`next random * 100.0`
|
||||
```
|
||||
|
||||
because otherwise `ENTIER` would bind to the next random, giving the number 0, rather than to the whole expression.
|
||||
|
||||
On line 5 is a call to the `print` procedure, which is used here as a debugging thing. Notice the nested parentheses; `print` takes an argument that is either a printable value or expression or a list of printable values or expressions. When it's a list, you use a "denotation," which opens and closes with parentheses.
|
||||
|
||||
Line 6 uses `print` again to offer the single string `guess a number:`.
|
||||
|
||||
Lines 7 through 20 are a `WHILE … DO … OD` loop. A few interesting things here: First, all the work is done as a part of the logical expression evaluated by the `WHILE`, so the body of the loop contains only the reserved word `SKIP`, which means "do nothing."
|
||||
|
||||
Lines 8 through 17 are a sequence of two statements: the definition of the integer value `guess`, which is obtained by calling the procedure `read int` to get an integer from the input, followed by the `IF … THEN … ELIF … ELSE … FI` statement. Note that each of the `THEN`, `ELIF`, and `ELSE` parts end with a boolean value `TRUE` or `FALSE`. This causes the whole `IF… FI` statement to return either `TRUE` or `FALSE`, which, being the last statement in the sequence of statements, is the value "delivered" to `WHILE` to determine whether to loop around again or not.
|
||||
|
||||
A more typical language might have a structure similar to:
|
||||
|
||||
|
||||
```
|
||||
boolean doAgain = true;
|
||||
while (doAgain) {
|
||||
if less then
|
||||
doAgain = true
|
||||
else if more then
|
||||
doAgain = true
|
||||
else
|
||||
doAgain = false
|
||||
}
|
||||
```
|
||||
|
||||
Because Algol 68 is expression-oriented, you don't need to declare that variable `doAgain`; you just incorporate the values to be generated into the expression being evaluated by the `WHILE` part.
|
||||
|
||||
What's cool about this is you can do things like the ternary operator in C—except much more broadly and better—with the standard `IF...FI`:
|
||||
|
||||
|
||||
```
|
||||
`do again := IF guess < random number THEN print("something"); TRUE ELIF guess > random number THEN print("something else"); TRUE ELSE print("another thing"); FALSE FI`
|
||||
```
|
||||
|
||||
Note that I also took care not to declare anything as a mutable value when unnecessary. Since the value `guess` only has the scope of the `WHILE` loop, it just defines a new value each time.
|
||||
|
||||
One nagging little problem I didn't handle stems from the use of `read int`; if the frustrated user types in a value that is not convertible to an integer, the program will stop with an error condition. You could manage this problem by calling the procedure `on value error`, which is similar to the `on logical file end` procedure. I'll leave that for you to figure out. You didn't think you'd get away from this without an exercise, did you?
|
||||
|
||||
### What we learned
|
||||
|
||||
In the introduction, I listed the programming concepts this exercise should explore. How did I do?
|
||||
|
||||
* **Variables:** This shows that Algol 68 thinks of variables as named locations and supports named (immutable) values.
|
||||
* **Input:** It used `stand in` as predefined console input and handled end-of-file conditions.
|
||||
* **Output:** It used `print` to print messages on the console.
|
||||
* **Conditional evaluation:** It used Algol 68 `if-then-else-fi` and `if` statements as expressions.
|
||||
* **Loops:** It used Algol 68's `while` loop, including using a sequence of statements to calculate the value to be tested.
|
||||
|
||||
|
||||
|
||||
It also used some Algol 68 standard library (which Algol 68 calls "standard prelude") functionality, including the random number generator and I/O exception testing.
|
||||
|
||||
Run the program:
|
||||
|
||||
|
||||
```
|
||||
$ a68g guess.a68
|
||||
the secret number is +26
|
||||
guess a number: 50
|
||||
too high, try again: 25
|
||||
too low, try again: 37
|
||||
too high, try again: 31
|
||||
too high, try again: 28
|
||||
too high, try again: 26
|
||||
that's right
|
||||
$
|
||||
```
|
||||
|
||||
One thing I didn't cover is comments. In Algol 68 Genie, comments can begin and end with the symbol `COMMENT`, or `CO`, or `#`, as in:
|
||||
|
||||
|
||||
```
|
||||
`# this is a comment #`
|
||||
```
|
||||
|
||||
If you're interested in exploring Algol 68, take a look at [Marcel's site][4] or the many contributed solutions in Algol 68 on [Rosetta Code][5].
|
||||
|
||||
In closing, back to the "dead languages" thing. Yes, it's a bit of an esoteric pursuit. But learning obscure languages is a great way to appreciate how far we've come (or, in some cases, not) and to give a more rounded perspective on language features we take for granted.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/20/12/learn-algol-68
|
||||
|
||||
作者:[Chris Hermansen][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/clhermansen
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/retro_old_unix_computer.png?itok=SYAb2xoW (Old UNIX computer)
|
||||
[2]: https://opensource.com/correspondent-program
|
||||
[3]: http://www.algol68.org/
|
||||
[4]: https://jmvdveer.home.xs4all.nl/en.algol-68-genie.html
|
||||
[5]: http://www.rosettacode.org/wiki/Rosetta_Code
|
@ -0,0 +1,82 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (5 open source security practices from 2020)
|
||||
[#]: via: (https://opensource.com/article/20/12/security)
|
||||
[#]: author: (Seth Kenlon https://opensource.com/users/seth)
|
||||
|
||||
5 open source security practices from 2020
|
||||
======
|
||||
Here are manageable ways to keep your systems and data safe and secure.
|
||||
![Lock][1]
|
||||
|
||||
Few of us really want to read articles about security. They're usually uncomfortable (and overwhelming) reminders of the things we aren't doing to keep our data safe and secure. Luckily for us, this year, Opensource.com authors specifically focused on writing about manageable security tasks. Some are afternoon projects, while others are small steps you can take to improve your default security settings.
|
||||
|
||||
Here are 13 of our favorites.
|
||||
|
||||
### Encryption
|
||||
|
||||
How often have you watched a talk or read something about cryptography that is either so theoretical that it is hard to understand or so high-level that you don't have a concrete example to build on its themes? In _[Never forget your password with this Python encryption algorithm][2],_ Moshe Zadka gives us the best of both worlds: theory and application. Check it out!
|
||||
|
||||
We live in an increasingly complex world where we often need to manage several calendars at once. We have our work calendar, our kids' school and activity calendars, our personal appointments, sports and TV schedules… and, if you're using CalDAV, managing all of those calendars could put your security and privacy at risk. Ivan Kupalov explains how to avoid these risks in [_How to replace CalDAV with a secure calendar protocol_][3].
|
||||
|
||||
Mike Bursell introduces Enarx, a new "application deployment system enabling applications to run within Trusted Execution Environments (TEEs) without rewriting for particular platforms or SDKs." In [_Why we open sourced our security project_][4], Mike explains why he and his co-developer decided to make the project open source.
|
||||
|
||||
### Email infrastructure
|
||||
|
||||
Here's a bargain for you—two articles for the price of one: Free! Victor Lopes and Marc Skinner explain how SSL can help secure your email solutions. Victor's [_Eliminate spam using SSL with an open source certification authority_][5] introduces MailCleaner as an open source anti-spam solution for your email infrastructure, and Marc's [_How to secure your Linux email services with SSL/TLS_][6] walks through enabling SSL/TLS between email endpoints.
|
||||
|
||||
You may not have needed to manage SSL certificates before, but you've surely been affected by them. As a user, you've probably gotten an error message on your browser or experienced an outage on a favorite online service. As a system administrator, it's your responsibility to minimize or eliminate these experiences for customers. In [_Manage your SSL certificates with the ssl-on-demand script_][7], Abhishek Tamrakar offers some ideas on managing these certs and avoiding guaranteed headaches if you ignore them.
|
||||
|
||||
### Firewalls
|
||||
|
||||
If firewalls are one of your responsibilities (and they probably are), Seth Kenlon has you covered. First, he introduces _[Getting started with Linux firewalls][8],_ and then he takes a deeper dive into more advanced capabilities of firewalld in _[Open ports and route traffic through your firewall][9]._
|
||||
|
||||
### Vulnerability management
|
||||
|
||||
WordPress is by far the [most popular][10] web content management system, making it a popular target for cyber threats. Therefore, it is imperative that system administrators keep WordPress installations secure, and Lucy Carney offers [_6 tips for securing your WordPress website_][11] to help you do so.
|
||||
|
||||
Two words you often hear in security are hardening and compliance. In fact, the process of securing your system can also be called "hardening," and depending on your industry, internal or external parties (e.g., your infosec team or a government regulatory agency) may require you to "harden" your system to a minimum security level. Lynis is a tool that will help you achieve that level and audit its capabilities. Gaurav Kamathe's [_Scan your Linux security with Lynis_][12] will help you get started with it.
|
||||
|
||||
After you read Gaurav's article, Ari Noman's [_Use this command-line tool to find security flaws in your code_][13] will help you take the principles of hardening to the code level by using the Graudit tool to uncover programming flaws and code vulnerabilities.
|
||||
|
||||
### Identity management
|
||||
|
||||
Will you do me a favor? Before you continue reading, turn on two-factor authentication (2FA) in all of your accounts. Everywhere! And if your organization is looking for an open source solution to produce multi-factor authentication (MFA) in your services, look no further than privacyIDEA. Find out more in Cornelius Kölbel's [_Open source alternative for multi-factor authentication: privacyIDEA_][14].
|
||||
|
||||
In _[Protect your network with open source tools][15],_ Chantale Benoit introduces a couple of open source security tools under the Apache Foundation umbrella. They are Syncope, "an open source system for managing digital identities in an enterprise environment," and Metron, an "advanced security analytics framework that detects cyber anomalies, such as phishing activity and malware infections."
|
||||
|
||||
### Living a security lifestyle
|
||||
|
||||
Security is an ongoing practice. As these articles demonstrate, good security is something you integrate into your life and into your code. Give them all a read, and see what you can do to improve your digital security over the coming year.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/20/12/security
|
||||
|
||||
作者:[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/security-lock-password.jpg?itok=KJMdkKum (Lock)
|
||||
[2]: https://opensource.com/article/20/6/python-passwords
|
||||
[3]: https://opensource.com/article/20/3/caldav-security
|
||||
[4]: https://opensource.com/article/20/8/why-open-source
|
||||
[5]: https://opensource.com/article/20/6/secure-open-source-antispam
|
||||
[6]: https://opensource.com/article/20/4/securing-linux-email
|
||||
[7]: https://opensource.com/article/20/2/ssl-demand
|
||||
[8]: https://opensource.com/article/20/2/firewall-cheat-sheet
|
||||
[9]: https://opensource.com/article/20/9/firewall
|
||||
[10]: https://w3techs.com/technologies/overview/content_management
|
||||
[11]: https://opensource.com/article/20/4/wordpress-security
|
||||
[12]: https://opensource.com/article/20/5/linux-security-lynis
|
||||
[13]: https://opensource.com/article/20/8/static-code-security-analysis
|
||||
[14]: https://opensource.com/article/20/3/open-source-multi-factor-authentication
|
||||
[15]: https://opensource.com/article/20/10/apache-security-tools
|
@ -0,0 +1,97 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Try a text editor inspired by Notepad++)
|
||||
[#]: via: (https://opensource.com/article/20/12/notepad-text-editor)
|
||||
[#]: author: (Seth Kenlon https://opensource.com/users/seth)
|
||||
|
||||
Try a text editor inspired by Notepad++
|
||||
======
|
||||
Classic notepads are reliable and familiar, and the new, improved
|
||||
versions offer endless plugins to customize your experience.
|
||||
![Writing Hand][1]
|
||||
|
||||
If you look online for great open source text editors, you’re bound to come across [Notepad++][2]. An enduring and popular editor, Notepad++ is built only for Windows. I use the open source operating system [Linux][3] but was nevertheless curious to experience Notepad++. Fortunately for me, I discovered one way to try Notepad++ (yes, it’s WINE) and one way to approximate it.
|
||||
|
||||
### Running Notepad++ in WINE
|
||||
|
||||
It seemed like a crazy idea at one time, but long ago, a group of developers wondered whether they could reverse engineer the system-level libraries that made Windows work and then release them as open source software. That’s what WINE is—a rewrite of the core components of Windows, allowing many Windows applications to run on Linux.
|
||||
|
||||
It’s a staggering achievement and one that has, among other things, helped the ReactOS project launch a Windows-like open source operating system, Valve Software to create Steam Play for running Windows games on Linux, and people who are over-curious about text editors to try Notepad++.
|
||||
|
||||
There are two steps involved in this process:
|
||||
|
||||
1. Install WINE on Linux from your software repository.
|
||||
2. Download the [Notepad++ EXE installer][4]. With WINE, you can launch it like a native application, and install Notepad++ to your system.
|
||||
|
||||
|
||||
|
||||
### Winetricks
|
||||
|
||||
Alternatively, you can use Winetricks to install applications, Notepad++ included. Winetricks is a shell script with tried-and-tested build scripts for dozens upon dozens of applications, games, fonts, and more. You can probably install Winetricks from your distribution's software repository. If it's not available, then you can download it yourself:
|
||||
|
||||
|
||||
```
|
||||
$ mkdir ~/bin
|
||||
$ cd ~/bin
|
||||
$ wget <https://raw.githubusercontent.com/Winetricks/winetricks/master/src/winetricks>
|
||||
$ chmod +x winetricks
|
||||
$ ./winetricks
|
||||
```
|
||||
|
||||
Winetricks is a simple menu-driven application. Find **npp** ("Notepad plus plus") in the **Install applications** menu selection.
|
||||
|
||||
![Winetricks][5]
|
||||
|
||||
There are a few things to get used to when using applications on Linux that believe they’re running on Windows, but nothing serious. You have to get used to the idea of hard drive locations designated by letters, and you might want to download and install some Windows themes to help your WINE environment feel better integrated with the rest of your system. Once you’ve used Notepad++ running on WINE, you quickly forget WINE is involved at all.
|
||||
|
||||
![Notepad++ running in WINE on Linux][6]
|
||||
|
||||
### Running Notepadqq
|
||||
|
||||
There’s no affiliation between Notepadqq and Notepad++, except that the former takes inspiration from the latter. They’re not identical applications, but if you’re a casual fan of the original, then you might find Notepadqq a suitable native replacement.
|
||||
|
||||
Notepadqq is easy to [install as a Flatpak][7] on Linux or a Chromebook. Alternately, you can [download and compile it from its source code][8]. Some support is provided for [compiling on MacOS][9], too.
|
||||
|
||||
![screenshot of black notepad terminal with white lettering][10]
|
||||
|
||||
### Notepad (improved)
|
||||
|
||||
Regardless of how you satiate your Notepad improved hunger, you’ll be pleased to find you have a responsive, customizable, and extensible editor. Both applications provide syntax highlighting for around 80 programming languages and text formats, including C, C++, Java, Python, Javascript, Lua, [Markdown][11], RPM spec files, and [YAML][12].
|
||||
|
||||
They also both use the concept of a session, or sets of files opened in your Notepad editor, which you can save and reload as needed. Using sessions helps you organize your work into projects.
|
||||
|
||||
Both Notepad applications can be extended through plugins. Notepad++ features a Plugins Admin panel, where you can browse through available plugins. Notepadqq doesn’t have the years of development that Notepad++ has had, and accordingly, doesn’t seem to have the abundance of available extensions. However, you can [develop your own using Node.js][13].
|
||||
|
||||
### Try a Notepad (improved)
|
||||
|
||||
Whether you stick with the classic Notepad++ or venture into the newer Notepadqq, you’re bound to find satisfaction with these reliable editors. They give you the features you expect for efficient text editing and the access you need so you can hack together your own extensions. These are both fun, reliable, and dependable projects, so give one (or both) a try today!
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/20/12/notepad-text-editor
|
||||
|
||||
作者:[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/write-hand_0.jpg?itok=Uw5RJD03 (Writing Hand)
|
||||
[2]: https://notepad-plus-plus.org
|
||||
[3]: http://opensource.com/resources/what-linux
|
||||
[4]: https://notepad-plus-plus.org/downloads/
|
||||
[5]: https://opensource.com/sites/default/files/winetricks.png (Winetricks)
|
||||
[6]: https://opensource.com/sites/default/files/npp.png (Notepad++ running in WINE on Linux)
|
||||
[7]: https://flathub.org/apps/details/com.notepadqq.Notepadqq
|
||||
[8]: https://github.com/notepadqq/notepadqq
|
||||
[9]: https://github.com/notepadqq/notepadqq/wiki/Compiling-Notepadqq-on-macOS
|
||||
[10]: https://opensource.com/sites/default/files/uploads/notepad-31_days-notepad-opensource.png (screenshot of black notepad terminal with white lettering)
|
||||
[11]: https://opensource.com/article/19/9/introduction-markdown
|
||||
[12]: https://www.redhat.com/sysadmin/yaml-beginners
|
||||
[13]: https://github.com/notepadqq/notepadqq/wiki/How-to-write-an-extension-with-Node.js
|
@ -0,0 +1,59 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (10 lessons from sysadmins adapting to change in 2020)
|
||||
[#]: via: (https://opensource.com/article/20/12/sysadmin)
|
||||
[#]: author: (Alan Formy-Duval https://opensource.com/users/alanfdoss)
|
||||
|
||||
10 lessons from sysadmins adapting to change in 2020
|
||||
======
|
||||
Adapting to change was a major theme in 2020, and throughout all the
|
||||
turmoil, we could count on sysadmins to keep us up and running.
|
||||
![Tips and gears turning][1]
|
||||
|
||||
While 2020 will certainly be remembered for elections, protests, and most of all, the COVID-19 pandemic, a lot of other things changed in 2020, including a whole lot of cool changes in technology. Through it all, we could count on system administrators to do what they do best. Perhaps more so than ever, as we all moved from physical offices to working from home. We generated more load than ever on our infrastructure as more users relied on virtual private networks and videoconference tools to get their daily work done.
|
||||
|
||||
Every year, we publish many articles to help systems administrators do their jobs better. Of the many articles we published this year, we believe these 10 offer the best insights for sysadmins in 2020. Several provide good examples of the importance of keeping up with change—which, after all, is the only thing we could count on this year.
|
||||
|
||||
1. [Manage network connections from the Linux command line with nmcli][2]: Dave McKay gives an overview of NetworkManager's `nmcli` command for network management in Linux. Using `nmcli` in place of `ifconfig` is strongly recommended in the latest versions of Linux.
|
||||
2. [5 new sudo features you need to know in 2020][3]: Following the theme of keeping up with change, Peter Czanik shows five new features of the `sudo` command. This crucial sysadmin tool gains power with recording and auditing capabilities and support for Python.
|
||||
3. [Start using systemd as a troubleshooting tool][4]: It's clear that systemd is here to stay. Correspondent David Both invites us on his journey from SystemV to systemd in yet another example of how system administrators need to adapt. In this article (part of an ongoing series), David demonstrates how to troubleshoot a problematic Apache HTTP service using systemd logs and status output.
|
||||
4. [5 ops hacks for sysadmins][5]: Server counts continue to rise alongside the demands on system administrators managing bare-metal hosts, containers, or virtual machines. As Stephen Bancroft starts this article: "As a sysadmin, every day I am faced with problems I need to solve quickly because there are users and managers who expect things to run smoothly." He discusses five tools, some "oldies but goodies," that remain extremely useful in 2020.
|
||||
5. [Load balance network traffic with HAProxy][6]: Load balancers are an important component of a high-availability infrastructure. They can be deployed for anything from large distributed enterprise applications down to your home lab. A great option for the latter is HAProxy, and Jim O'Connell shows how to set it up.
|
||||
6. [An SRE's guide to Memcached for building scalable applications][7]: After reading about load balancers, check out this article by Correspondent Moshe Zadka, as he takes you deeper into the application stack with an overview of Memcached. Moshe, a site reliability engineer, explains Memcached's value for high-performance systems that must respond to repeated requests under heavy load.
|
||||
7. [Why making mistakes makes me a better sysadmin][8]: Ben Cotton, the Fedora Linux Project's program manager, reminds us that we can learn from our mistakes. He explains that we can learn to avoid repeating mistakes through practice and testing. Now if only 2020 had a dry-run option!
|
||||
8. [10 Ansible modules for Linux system automation][9]: Automation is a great way to avoid those mistakes Ben writes about. Ricardo Gerardi specializes in automation, and in this article, he shows how to use Ansible to automate daily Linux system administration tasks, such as package installation and user creation, that are repetitive and, therefore, error-prone.
|
||||
9. [How I use Cockpit for my home's Linux server management][10]: Cockpit is a fairly new graphical tool for Linux system management. It is browser-based and handles local and remote management equally well. After using similar tools over the years, I wrote this article because I am impressed at how quickly Cockpit can be put to use. Installation is simple, and it is easy for any busy system administrator to learn.
|
||||
10. [4 ways I contribute to open source as a Linux systems administrator][11]: Open source projects and the communities that support them have taken a prominent role in 2020. In this article, Elizabeth Joseph shares some ways to get involved. She encourages system administrators and other open source users to join and contribute to projects. So, get involved and help make 2021 an even better year!
|
||||
|
||||
|
||||
|
||||
What sysadmin topics would you like to learn about on Opensource.com? Please share your ideas in the comments. We're always looking for new contributors, so please check out our [Contributor guidelines][12] if you want to write an article you think our readers would enjoy.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/20/12/sysadmin
|
||||
|
||||
作者:[Alan Formy-Duval][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/alanfdoss
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/gears_devops_learn_troubleshooting_lightbulb_tips_520.png?itok=HcN38NOk (Tips and gears turning)
|
||||
[2]: https://opensource.com/article/20/7/nmcli
|
||||
[3]: https://opensource.com/article/20/10/sudo-19
|
||||
[4]: https://opensource.com/article/20/5/systemd-troubleshooting-tool
|
||||
[5]: https://opensource.com/article/20/1/ops-hacks-sysadmins
|
||||
[6]: https://opensource.com/article/20/11/load-balancing-haproxy
|
||||
[7]: https://opensource.com/article/20/3/sre-memcached
|
||||
[8]: https://opensource.com/article/20/8/sysadmin-mistakes
|
||||
[9]: https://opensource.com/article/20/10/ansible-modules-linux
|
||||
[10]: https://opensource.com/article/20/11/cockpit-server-management
|
||||
[11]: https://opensource.com/article/20/7/open-source-sysadmin
|
||||
[12]: https://opensource.com/how-submit-article
|
@ -0,0 +1,55 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (geekpi)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (4 reasons businesses adopted open source in 2020)
|
||||
[#]: via: (https://opensource.com/article/20/12/open-source-survey)
|
||||
[#]: author: (Chris Grams https://opensource.com/users/cgrams)
|
||||
|
||||
4 reasons businesses adopted open source in 2020
|
||||
======
|
||||
Differences emerge based on company size, according to Tidelift's third
|
||||
managed open source survey.
|
||||
![Metrics and a graph illustration][1]
|
||||
|
||||
Companies are turning to open source during the pandemic, with 44% of organizations reporting they will increase their use of open source for application development, finds Tidelift's [third managed open source survey][2].
|
||||
|
||||
We've heard this lyric before; in previous recessions, organizations turned to open source [for cost savings][3] and stayed for its [other transformational benefits][4]. We wanted to understand which long-term benefits were most helpful to organizations of different sizes. Here's a summary of what we found.
|
||||
|
||||
**Open source is driving cost and time savings while improving efficiency.** A key driver, cited by 68% of organizations, is saving money and development time, as using open source reduces the time developers spend writing new code from scratch. Almost half (48%) report that it increases app development and maintenance efficiency. Organizations with more than 1,000 employees are far more likely to cite this as a reason to encourage the use of more open source (61% vs. 41% for organizations with less than 1,000).
|
||||
|
||||
![Graph showing reasons for using open source][5]
|
||||
|
||||
(Tidelift ©2020)
|
||||
|
||||
**Eliminating vendor lock-in is high on the list of reasons organizations are using more open source.** We found 40% of respondents cited this as a primary reason. Replacing expensive proprietary software with open source ensures that organizations can be more nimble and avoid dependency on vendors. Again, larger organizations favor this reason; 50% of organizations with over 1,000 employees identify this as a key benefit.
|
||||
|
||||
**Increasing developer satisfaction is another reason to use more open source, with 31% of organizations citing it.** As companies compete fiercely for talent, they understand the value of ensuring developers are happy in their work and with the tools they use. The survey found that the top three languages developers are using are JavaScript (78%), Python (52%), and Java (41%).
|
||||
|
||||
**Additionally, as open source usage increases, 83% of organizations continue to contribute to it, and nearly half have a policy in place to govern contributions**. These policies include contributions during work hours to projects an organization uses but doesn't sponsor or manage; contributions to projects they do sponsor or manage; contributions during personal time to non-job-related (personal) projects; and contributions during work hours to non-job-related (personal) projects.
|
||||
|
||||
While the long-term migration towards open source continues, it's clear that the impact of COVID-19 may be accelerating this process, and organizations continue to glean deeper value from using and contributing to it.
|
||||
|
||||
For more information, view all findings from the [2020 Managed Open Source Survey][2].
|
||||
|
||||
Developing your organization's story—the narrative that gives it its current identity and charts...
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/20/12/open-source-survey
|
||||
|
||||
作者:[Chris Grams][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/cgrams
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/metrics_graph_stats_blue.png?itok=OKCc_60D (Metrics and a graph illustration)
|
||||
[2]: https://www.tidelift.com/subscription/2020-managed-open-source-survey
|
||||
[3]: https://blog.tidelift.com/the-third-wave-of-open-source-migration?utm_source=opensource&utm_medium=referral&utm_campaign=2020-survey
|
||||
[4]: https://blog.tidelift.com/theres-one-thing-stopping-developers-from-using-open-source-even-more?utm_source=opensource&utm_medium=referral&utm_campaign=2020-survey
|
||||
[5]: https://opensource.com/sites/default/files/uploads/tidelift_reasons-for-using-open-source.png (Graph showing reasons for using open source)
|
@ -0,0 +1,150 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (How to Automatically Accept SSH Key Fingerprint?)
|
||||
[#]: via: (https://www.2daygeek.com/how-to-automatically-accept-ssh-key-fingerprint/)
|
||||
[#]: author: (Magesh Maruthamuthu https://www.2daygeek.com/author/magesh/)
|
||||
|
||||
How to Automatically Accept SSH Key Fingerprint?
|
||||
======
|
||||
|
||||
**[SSH Secure Shell][1]** is an encryption network protocol that provides secure encrypted communications between two hosts.
|
||||
|
||||
It allows you to connect to a remote machine securely over an insecure network.
|
||||
|
||||
When you connect to a Linux system for the first time, SSH prompts you to accept the fingerprint of the machines to successfully establish the connection, since you do not have a fingerprint in your **“known_hosts”** file.
|
||||
|
||||
Fingerprint is a shortened version of the system’s public key.
|
||||
|
||||
To protect yourself from Man-in-the-Middle Attack (MITM), the ssh program verifies the fingerprint of the remote system ssh with the fingerprint stored since it was last connected.
|
||||
|
||||
If the fingerprint has changed you will be alerted and asked if you would like to proceed. Otherwise, you will be allowed to log in directly.
|
||||
|
||||
But sometimes you may need to accept SSH fingerprint automatically.
|
||||
|
||||
For instance, if you created a **[shell script][2]** to run against multiple machines to pull a report.
|
||||
|
||||
**Make a Note:** You are effectively bypassing SSH intended security through the methods below. It is less dangerous when using it on the internal network, but it is not advisable to use it on the public Internet or other untrusted networks.
|
||||
|
||||
This can be done using the following two methods.
|
||||
|
||||
* Automatically accept an ssh fingerprint using the “StrictHostKeyChecking=no” option with the ssh command
|
||||
* Auto accepts an ssh fingerprint using the ssk-keycan command
|
||||
|
||||
|
||||
|
||||
When you connect to a remote computer for the first time, you will be warned that the authenticity of the host cannot be established and presented with a key fingerprint to verify.
|
||||
|
||||
```
|
||||
$ ssh [email protected]
|
||||
The authenticity of host '192.168.1.4 (192.168.1.4)' can't be established.
|
||||
ECDSA key fingerprint is 6a:75:e3:ac:5d:f8:cc:04:01:7b:ef:4d:42:ad:b9:83.
|
||||
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
|
||||
Warning: Permanently added '192.168.1.4' (ECDSA) to the list of known hosts.
|
||||
[email protected]'s password:
|
||||
Last login: Mon Dec 14 14:16:51 2020 from 192.168.1.6
|
||||
```
|
||||
|
||||
Once you accept the fingerprint, it will be saved in the “known_hosts” file.
|
||||
|
||||
When reconnecting to the same remote host, SSH checks the fingerprint against the known_host file to verify its identity.
|
||||
|
||||
If this matches, you will be allowed direct access to the system as long as the key remains intact.
|
||||
|
||||
You will see the following warning if the fingerprint does not match the known_hosts. This happens if the host public key changes for some reason.
|
||||
|
||||
If you see the warning below, double-check that you are actually connecting with the right host on a secure connection. Although most of the time it is harmless, it can be an indication of a potential issue.
|
||||
|
||||
```
|
||||
$ ssh [email protected]
|
||||
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
||||
@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @
|
||||
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
||||
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
|
||||
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
|
||||
It is also possible that the RSA host key has just been changed.
|
||||
The fingerprint for the RSA key sent by the remote host is
|
||||
6a:75:e3:ac:5d:f8:cc:04:01:7b:ef:4d:42:ad:b9:83.
|
||||
Please contact your system administrator.
|
||||
Add correct host key in /root/.ssh/known_hosts to get rid of this message.
|
||||
Offending key in /root/.ssh/known_hosts:1
|
||||
Password authentication is disabled to avoid man-in-the-middle attacks.
|
||||
Keyboard-interactive authentication is disabled to avoid man-in-the-middle attacks.
|
||||
********************************************************
|
||||
Permission denied (publickey,password,keyboard-interactive).
|
||||
```
|
||||
|
||||
### 1) How to Automatically Accept SSH Key Fingerprint Using SSH Option?
|
||||
|
||||
This method is simple and straight forward, to achieve this only need to add an option with SSH command.
|
||||
|
||||
When you use this option, ssh will automatically add a new host key to the user known_host file and allow it to host connections with modified hostkeys to connect to the remote system.
|
||||
|
||||
```
|
||||
$ ssh -o "StrictHostKeyChecking no" 192.168.1.5
|
||||
Warning: Permanently added 'centos7,192.168.1.5' (ECDSA) to the list of known hosts.
|
||||
ok
|
||||
```
|
||||
|
||||
However, the above warning shows that it has added a key to the known_host file.
|
||||
|
||||
### 2) How to Automatically Accept SSH Key Fingerprint Using ssk-keyscan Command?
|
||||
|
||||
This is another method, it is very simple. The ssh-keycan tool allows you to append the ssh key fingerprint to the user-known_host file on the remote server.
|
||||
|
||||
This tool is very useful when you want to add bulk.
|
||||
|
||||
This command must be inserted into the shell script before calling the actual command in the script.
|
||||
|
||||
Use the following format to add the ssh key fingerprint to a remote host.
|
||||
|
||||
```
|
||||
$ ssh-keyscan -H 192.168.1.4 >> ~/.ssh/known_hosts
|
||||
#centos:22 SSH-2.0-OpenSSH_7.4
|
||||
```
|
||||
|
||||
Use the following format to add the ssh key fingerprint to multiple hosts.
|
||||
|
||||
To do so, you must add the remote hosts details to a file and call it with the ssh-keycan command as follows. For example, I added five hosts to the **“remote-hosts.txt”** file.
|
||||
|
||||
You can use any text editor to add entries. I recommend you to use **[vim editor][3]**, the most flexible and powerful text editor widely used by Linux administrators and developers.
|
||||
|
||||
```
|
||||
# vi remote-hosts.txt
|
||||
|
||||
192.168.1.2
|
||||
192.168.1.3
|
||||
192.168.1.4
|
||||
192.168.1.5
|
||||
192.168.1.6
|
||||
```
|
||||
|
||||
If yes, the ssh-keyscan command would be as follows.
|
||||
|
||||
```
|
||||
$ ssh-keyscan -f /tmp/remote-hosts.txt >> ~/.ssh/known_hosts
|
||||
#centos:22 SSH-2.0-OpenSSH_7.4
|
||||
#centos:22 SSH-2.0-OpenSSH_7.4
|
||||
#centos:22 SSH-2.0-OpenSSH_7.4
|
||||
#centos:22 SSH-2.0-OpenSSH_7.4
|
||||
#centos:22 SSH-2.0-OpenSSH_7.4
|
||||
```
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.2daygeek.com/how-to-automatically-accept-ssh-key-fingerprint/
|
||||
|
||||
作者:[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/ssh-tutorials/
|
||||
[2]: https://www.2daygeek.com/category/shell-scripts/
|
||||
[3]: https://www.2daygeek.com/basic-vim-commands-cheat-sheet-quick-start-guide/
|
193
sources/tech/20201222 Learn Rust by writing a simple game.md
Normal file
193
sources/tech/20201222 Learn Rust by writing a simple game.md
Normal file
@ -0,0 +1,193 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Learn Rust by writing a simple game)
|
||||
[#]: via: (https://opensource.com/article/20/12/learn-rust)
|
||||
[#]: author: (Moshe Zadka https://opensource.com/users/moshez)
|
||||
|
||||
Learn Rust by writing a simple game
|
||||
======
|
||||
Start programming with a simple game you can try in multiple languages.
|
||||
![Ferris the crab under the sea, unofficial logo for Rust programming language][1]
|
||||
|
||||
When you want to learn a new programming language, it's good to focus on the things programming languages have in common:
|
||||
|
||||
* Variables
|
||||
* Expressions
|
||||
* Statements
|
||||
|
||||
|
||||
|
||||
These concepts are the basis of most programming languages. Once you understand them, you can start figuring the rest out.
|
||||
|
||||
Because programming languages usually share similarities, once you know one language, you can learn the basics of another by understanding its differences.
|
||||
|
||||
A good way to learn new languages is using a standard program that you can use to practice. This allows you to focus on the language, not the program's logic. I'm doing that in this article series using a "guess the number" program, in which the computer picks a number between one and 100 and asks you to guess it. The program loops until you guess the number correctly.
|
||||
|
||||
This program exercises several concepts in programming languages:
|
||||
|
||||
* Variables
|
||||
* Input
|
||||
* Output
|
||||
* Conditional evaluation
|
||||
* Loops
|
||||
|
||||
|
||||
|
||||
It's a great practical experiment to learn a new programming language.
|
||||
|
||||
### Install Rust
|
||||
|
||||
You can [install a Rust toolchain using Rustup][2], or you can [try Rust online][3] without installing it locally.
|
||||
|
||||
If you install it locally, you should update it periodically with `rustup update` to keep your toolchain fresh, and with `cargo update` to keep your libraries on their latest versions.
|
||||
|
||||
### Guess the number in Rust
|
||||
|
||||
[Rust][4] is a language that empowers anyone to build reliable and efficient software. You can explore Rust by writing a version of the "guess the number" game.
|
||||
|
||||
The first step is to write a `Cargo.toml` file. You can generate a skeleton `Cargo.toml` using the `cargo new` command. This is almost always the best way to start a Rust project.
|
||||
|
||||
|
||||
```
|
||||
$ cargo new guess
|
||||
$ cd guess
|
||||
$ ls -1
|
||||
Cargo.toml
|
||||
src/
|
||||
```
|
||||
|
||||
The `Cargo.toml` file names your package, gives it some metadata, and, most importantly, specifies that it depends on the `rand` [crate][5].
|
||||
|
||||
|
||||
```
|
||||
[package]
|
||||
name = "guess"
|
||||
version = "2020.11.0"
|
||||
authors = ["Moshe Zadka <[moshez@opensource.com][6]>"]
|
||||
edition = "2018"
|
||||
|
||||
# See more keys and their definitions at <https://doc.rust-lang.org/cargo/reference/manifest.html>
|
||||
|
||||
[dependencies]
|
||||
rand = "*"
|
||||
```
|
||||
|
||||
Many things in Rust are not supplied by the language or the standard library. Instead, you get them from one of many external crates that are available to do many things.
|
||||
|
||||
The program logic goes in `src/main.rs`:
|
||||
|
||||
|
||||
```
|
||||
use rand::Rng;
|
||||
use std::io::BufRead;
|
||||
|
||||
fn main() {
|
||||
let mut rng = rand::thread_rng();
|
||||
let random = rng.gen_range(1..101);
|
||||
println!("Guess a number between 1 and 100");
|
||||
for line in std::io::stdin().lock().lines() {
|
||||
let parsed = line.ok().as_deref().map(str::parse::<i64>);
|
||||
if let Some(Ok(guess)) = parsed {
|
||||
match guess {
|
||||
_ if guess < random => println!("Too low"),
|
||||
_ if guess > random => println!("Too high"),
|
||||
_ => {
|
||||
println!("That's right");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
The first two lines of the code declare what you are going to do. In this case, `rand::Rng` generates a guess and the [trait][7] `std::io::BufRead` enables reading from standard input.
|
||||
|
||||
The entry point to the Rust code is in the `main()` function, so the next step is to define `main()`.
|
||||
|
||||
To assign a value to a variable put `let`, then the variable's name, followed by the `=` sign. This creates an [immutable][8] variable.
|
||||
|
||||
Most of your variables will be immutable, but the `rng` object must be mutable. For example, the statement `let random = 0` assigns a zero value to the `random` variable.
|
||||
|
||||
The first line of the function creates a thread-safe `Rng` object and assigns it to the variable `rng`. Rust is built on thread and memory safety, so you must think about those things as soon as you start writing code.
|
||||
|
||||
The next line of the program reads the result of the function `gen_range()` and assigns it to the variable called `random`. The function takes a minimum (inclusive) and an upper bound (not inclusive). To make the upper bound inclusive, you can mark the greater number with an equal sign (for example, `1..=100`), or you can just set the upper bound to 1 above your intended maximum, as I've done in my code. In this case, the range is `1` to `100`, making the game just challenging enough.
|
||||
|
||||
The central loop iterates over the lines in `std::io::stdin()`. Since there are all sorts of corner cases that might result in a line not being read, Rust requires you to wrap a line with a `Result`. It might also be impossible for a line to parse an integer.
|
||||
|
||||
This code uses conditional pattern-matching to ignore all lines that would have caused errors:
|
||||
|
||||
|
||||
```
|
||||
let parsed = line.ok().as_deref().map(str::parse::<i64>);
|
||||
if let Some(Ok(guess)) = parsed {
|
||||
// ...
|
||||
}
|
||||
```
|
||||
|
||||
The first line creates a `Result<Option<i64>, ...>` object because it might fail at the reading or parsing steps. Since the next line only matches on `Some(Ok(guess))`, whenever a line results in a value that does not match, it skips the `if` statement. This is a powerful way to ignore errors.
|
||||
|
||||
Rust supports conditional expressions and flow control, like loops. In the "guess the number" game, Rust continues looping as long as the value in the guess is not equal to `random`.
|
||||
|
||||
The body of the `if` statement contains a three-way branch using Rust's `match` statement. While `match` is most often used for pattern matching, it can also check arbitrary conditions. In this case, print an appropriate message and `break` the loop if the guess is correct.
|
||||
|
||||
### Sample output
|
||||
|
||||
Now that you've written your Rust program, you can run it to play the "guess the number" game. Every time you run the program, Rust will pick a different random number, so keep guessing until you find the correct number:
|
||||
|
||||
|
||||
```
|
||||
$ cargo run
|
||||
Compiling guess v2020.11.0 (/Users/mzadka/src/guess)
|
||||
Finished dev [unoptimized + debuginfo] target(s) in 0.70s
|
||||
Running `target/debug/guess`
|
||||
Guess a number between 1 and 100
|
||||
50
|
||||
Too high
|
||||
25
|
||||
Too high
|
||||
12
|
||||
Too low
|
||||
18
|
||||
Too high
|
||||
15
|
||||
Too high
|
||||
13
|
||||
Too low
|
||||
14
|
||||
That's right
|
||||
```
|
||||
|
||||
It is typical to test the program by running it with `cargo run`. Eventually, you'll probably use `cargo build` to [build an executable and run it][9] as two separate steps.
|
||||
|
||||
### Learn Rust
|
||||
|
||||
This "guess the number" game is a great introductory program for learning a new programming language because it exercises several common programming concepts in a pretty straightforward way. By implementing this simple game in different programming languages, you can demonstrate some core concepts of the languages and compare their details.
|
||||
|
||||
Do you have a favorite programming language? How would you write the "guess the number" game in it? Follow this article series to see examples of other programming languages that might interest you!
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/20/12/learn-rust
|
||||
|
||||
作者:[Moshe Zadka][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/moshez
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/rust_programming_crab_sea.png?itok=2eWLz8A5 (Ferris the crab under the sea, unofficial logo for Rust programming language)
|
||||
[2]: https://www.rust-lang.org/learn/get-started
|
||||
[3]: https://play.rust-lang.org/
|
||||
[4]: https://www.rust-lang.org/
|
||||
[5]: https://doc.rust-lang.org/book/ch07-01-packages-and-crates.html
|
||||
[6]: mailto:moshez@opensource.com
|
||||
[7]: https://doc.rust-lang.org/rust-by-example/trait.html
|
||||
[8]: https://en.wikipedia.org/wiki/Immutable_object
|
||||
[9]: https://opensource.com/article/20/3/rust-cargo
|
290
sources/tech/20201222 Learn to use the Sed text editor.md
Normal file
290
sources/tech/20201222 Learn to use the Sed text editor.md
Normal file
@ -0,0 +1,290 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Learn to use the Sed text editor)
|
||||
[#]: via: (https://opensource.com/article/20/12/sed)
|
||||
[#]: author: (Seth Kenlon https://opensource.com/users/seth)
|
||||
|
||||
Learn to use the Sed text editor
|
||||
======
|
||||
Sed lacks the usual text boxes and instead writes directly on a file,
|
||||
directed by user commands.
|
||||
![Command line prompt][1]
|
||||
|
||||
Created for version 7 of AT&T’s original Unix operating system, the `sed` command has been included with probably every Unix and Linux OS since. The `sed` application is a _stream editor_, and unlike a text editor it doesn’t open a visual buffer into which a file’s data is loaded for processing. Instead, it operates on a file, line by line, according to either a command typed into a terminal or a series of commands in a script.
|
||||
|
||||
### Installing
|
||||
|
||||
If you’re using Linux, BSD, or macOS, then you already have GNU or BSD `sed` installed. These are two unique reimplementations of the original `sed` command, and while they’re similar, there can be minor differences. GNU `sed` is generally regarded to be the most feature-rich `sed` out there, and it’s widely available on any of these platforms.
|
||||
|
||||
If you can’t find GNU `sed` (often called `gsed` on non-Linux systems), then you can [download its source code from the GNU website][2]. The nice thing about having GNU `sed` installed is that it can be used for its extra functions, but it can also be constrained to conform to just the [POSIX][3] specifications of `sed`, should you require portability.
|
||||
|
||||
On Windows, you can [install][4] GNU `sed` with [Chocolatey][5].
|
||||
|
||||
### How Sed works
|
||||
|
||||
The `sed` application works on one line at a time. Because it has no visual display, it creates a pattern space—a space in memory containing the current line from the input stream (with any trailing newline character removed). Once the pattern space is populated, your instructions to `sed` are executed. Sometimes your commands are conditional, and other times they are absolute, so the results of these commands depend on how you’re using `sed`.
|
||||
|
||||
When the end of commands is reached, `sed` prints the contents of the pattern space to the output stream. The default output stream is **stdout**, but it can be redirected to a file or even back into the same file using the `--in-place=.bak` option.
|
||||
|
||||
Then the cycle begins again with the next input line.
|
||||
|
||||
The syntax for the `sed` command is:
|
||||
|
||||
|
||||
```
|
||||
`$ sed --options [optional SCRIPT] [INPUT FILE or STREAM]`
|
||||
```
|
||||
|
||||
#### Finding what you want to edit
|
||||
|
||||
In a visual editor, you usually locate what you want to change in a text file without thinking much about it. Your eye (or screen reader) scans the text, finds the word you want to change or the place you want to insert or remove text, and then you just start typing. There is no interactive mode for `sed`, though, so you must tell it what conditions must be met for it to run specific commands.
|
||||
|
||||
For these examples, assume that a file called `example.txt` contains this text:
|
||||
|
||||
|
||||
```
|
||||
hello
|
||||
world
|
||||
This is line three.
|
||||
Here is the final line.
|
||||
```
|
||||
|
||||
#### Line number
|
||||
|
||||
Specifying a line number tells `sed` to operate only on that specific line in the file.
|
||||
|
||||
For instance, this command selects line 1 of a file and prints it. Because `sed`’s default action after processing is also to print a line to **stdout**, this has the effect of duplicating the first line:
|
||||
|
||||
|
||||
```
|
||||
$ sed ‘1p’ example.txt
|
||||
hello
|
||||
hello
|
||||
world
|
||||
This is line three.
|
||||
Here is the final line.
|
||||
```
|
||||
|
||||
You can specify line numbers in steps, too. For instance, `1~2` indicates that every 2 lines are selected ("select every second line starting with the first"). The instruction `1~3` means to select every third line after the first:
|
||||
|
||||
|
||||
```
|
||||
$ sed ‘1p’ example.txt
|
||||
hello
|
||||
hello
|
||||
world
|
||||
This is line three.
|
||||
Here is the final line.
|
||||
Here is the final line.
|
||||
```
|
||||
|
||||
#### Line position
|
||||
|
||||
You can operate only on the last line of a file by using `$` as a selector:
|
||||
|
||||
|
||||
```
|
||||
$ sed ‘$p’ example.txt
|
||||
hello
|
||||
world
|
||||
This is line three.
|
||||
Here is the final line.
|
||||
Here is the final line.
|
||||
```
|
||||
|
||||
In GNU `sed`, you can select more than one line (`sed '1,$p'` prints the first and final line, for example).
|
||||
|
||||
#### Negation
|
||||
|
||||
Any selection by number or position, you can invert with the exclamation mark (`!`) character. This selects all lines _except_ the first line:
|
||||
|
||||
|
||||
```
|
||||
$ sed ‘1!p’ example.txt
|
||||
hello
|
||||
world
|
||||
world
|
||||
This is line three.
|
||||
This is line three.
|
||||
Here is the final line.
|
||||
Here is the final line.
|
||||
```
|
||||
|
||||
#### Pattern matching
|
||||
|
||||
You can think of a pattern match as a **find** operation in a word processor or a browser. You provide a word (a _pattern_), and the results are selected. The syntax for a pattern match is `/pattern/`.
|
||||
|
||||
|
||||
```
|
||||
$ sed ‘/hello/p’ example.txt
|
||||
hello
|
||||
hello
|
||||
world
|
||||
This is line three.
|
||||
Here is the final line.
|
||||
$ sed ‘/line/p’ example.txt
|
||||
hello
|
||||
world
|
||||
This is line three.
|
||||
This is line three.
|
||||
Here is the final line.
|
||||
Here is the final line.
|
||||
```
|
||||
|
||||
### Editing with Sed
|
||||
|
||||
Once you’ve found what you want to edit, you can perform whatever action you want. You perform edits with `sed` with commands. Commands in `sed` are different from the `sed` command itself. If it helps, think of them as "actions" or "verbs" or "instructions."
|
||||
|
||||
Commands in `sed` are single letters, such as the `p` for **print** command used in previous examples. They can be difficult to recall at first, but as with everything, you get to know them with practice.
|
||||
|
||||
#### p for print
|
||||
|
||||
The `p` instruction prints whatever is currently held in pattern space.
|
||||
|
||||
#### d for delete
|
||||
|
||||
The `d` instruction deletes the pattern space.
|
||||
|
||||
|
||||
```
|
||||
$ sed ‘$d’ example.txt
|
||||
hello
|
||||
world
|
||||
This is line three.
|
||||
$ sed ‘1d’ example.txt
|
||||
world
|
||||
This is line three.
|
||||
Here is the final line.
|
||||
```
|
||||
|
||||
#### s for search and replace
|
||||
|
||||
The `s` command searches for a pattern and replaces it with something else. This is probably the most popular and casual use for `sed`, and it’s often the first (and sometimes the only) `sed` command a user learns. It’s almost certainly the most useful command for text editing.
|
||||
|
||||
|
||||
```
|
||||
$ sed ‘s/world/opensource.com/’
|
||||
hello
|
||||
opensource.com
|
||||
This is line three.
|
||||
Here is the final line.
|
||||
```
|
||||
|
||||
There are special functions you can use in your replacement text, too. For instance, `\L` transforms the replacement text to lowercase and `\l` does the same for just the next character. There are others, which are listed in the `sed` documentation (you can view that with the `info sed` command).
|
||||
|
||||
The special character `&` in the replacement clause refers to the matched pattern:
|
||||
|
||||
|
||||
```
|
||||
$ sed ‘s/is/\U&/’ example.txt
|
||||
hello
|
||||
world
|
||||
ThIS is line three.
|
||||
Here IS the final line.
|
||||
```
|
||||
|
||||
You can also pass special flags to affect how `s` processes what it finds. The `g` (for _global_, presumably) flag tells `s` to apply the replacement to all matches found on the line and not just the first match:
|
||||
|
||||
|
||||
```
|
||||
$ sed ‘s/is/\U&/g’ example.txt
|
||||
hello
|
||||
world
|
||||
ThIS IS line three.
|
||||
Here IS the final line.
|
||||
```
|
||||
|
||||
Other important flags include a number to indicate which occurrence of a matched pattern to affect:
|
||||
|
||||
|
||||
```
|
||||
$ sed ‘s/is/\U&/2’ example.txt
|
||||
hello
|
||||
world
|
||||
This IS line three.
|
||||
Here is the final line.
|
||||
```
|
||||
|
||||
The `w` flag, followed by a filename, writes a matched line to a file _only if_ a change is made:
|
||||
|
||||
|
||||
```
|
||||
$ sed ‘s/is/\U&/w sed.log’ example.txt
|
||||
hello
|
||||
world
|
||||
ThIS is line three.
|
||||
Here IS the final line.
|
||||
$ cat sed.log
|
||||
ThIS is line three.
|
||||
Here IS the final line.
|
||||
```
|
||||
|
||||
Flags can be combined:
|
||||
|
||||
|
||||
```
|
||||
$ sed ‘s/is/\U&/2w sed.log’ example.txt
|
||||
hello
|
||||
world
|
||||
This IS line three.
|
||||
Here is the final line.
|
||||
$ cat sed.log
|
||||
This IS line three.
|
||||
```
|
||||
|
||||
### Scripts
|
||||
|
||||
There are lots of great sites out there with `sed` "one-liners." They give you task-oriented `sed` commands to solve common problems. However, learning `sed` for yourself enables you to write your own one-liners, and those can be tailored to your specific needs.
|
||||
|
||||
Scripts for `sed` can be written as lines in a terminal, or they can be saved to a file and executed with `sed` itself. I tend to write small scripts all as one command because I find myself rarely re-using `sed` commands in real life. When I write a `sed` script, it’s usually very specific to one file. For example, after writing the initial draft of this very article, I used `sed` to standardize the capitalization of "sed", and that’s a task I’ll probably never have to do again.
|
||||
|
||||
You can issue a series of distinct commands to `sed` separated by a semicolon (`;`).
|
||||
|
||||
|
||||
```
|
||||
$ sed ‘3t ; s/line/\U&/’ example.txt
|
||||
hello
|
||||
world
|
||||
This is LINE three.
|
||||
This is the final line.
|
||||
```
|
||||
|
||||
### Scope changes with braces
|
||||
|
||||
You can also limit which results are affected with braces (`{}`). When you enclose `sed` commands in braces, they apply only to a specific selection. For example, the word "line" appears in two lines of the sample text. You can force `sed` to affect only the final line by declaring the required match condition (`$` to indicate the final line) and placing the `s` command you want to be performed in braces immediately thereafter:
|
||||
|
||||
|
||||
```
|
||||
$ sed ‘$ {s/line/\U&/}’ example.txt
|
||||
hello
|
||||
world
|
||||
This is line three.
|
||||
This is the final LINE.
|
||||
```
|
||||
|
||||
### Learn Sed
|
||||
|
||||
You can do a lot more with `sed` than what’s explained in this article. I haven’t even gotten to branching (`b`), tests (`t`), the _hold_ space (`H`), and many other features. Like [`ed`][6], `sed` probably isn’t the text editor you’re going to use for document creation or even for every scripted task you need doing, but it is a powerful option you have as a POSIX user. Learning how `sed` commands are structured and how to write short scripts can make for quick changes to massive amounts of text. Read through the `info` pages of GNU `sed`, or the man pages of BSD `sed`, and find out what `sed` can do for you.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/20/12/sed
|
||||
|
||||
作者:[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/command_line_prompt.png?itok=wbGiJ_yg (Command line prompt)
|
||||
[2]: http://www.gnu.org/software/sed/
|
||||
[3]: https://opensource.com/article/19/7/what-posix-richard-stallman-explains
|
||||
[4]: https://chocolatey.org/packages/sed
|
||||
[5]: https://opensource.com/article/20/3/chocolatey
|
||||
[6]: https://opensource.com/article/20/12/gnu-ed
|
@ -0,0 +1,88 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (10 Raspberry Pi project ideas from 2020)
|
||||
[#]: via: (https://opensource.com/article/20/12/raspberry-pi)
|
||||
[#]: author: (Joshua Allen Holm https://opensource.com/users/holmja)
|
||||
|
||||
10 Raspberry Pi project ideas from 2020
|
||||
======
|
||||
Find some great new projects for your Raspberry Pi from the year's top
|
||||
articles.
|
||||
![Vector, generic Raspberry Pi board][1]
|
||||
|
||||
The Raspberry Pi is the small, low-cost, single-board PC that took the world by storm when it was released in 2012. Since then, educators, students, makers, and tinkerers have used the various Raspberry Pi models for many, many unique and interesting projects. The possibilities are nearly endless.
|
||||
|
||||
Over the course of 2020, Opensource.com published many great articles about Raspberry Pi projects; below, I explore the top 10. I hope these articles educate, entertain, and inspire you.
|
||||
|
||||
### How I migrated from a Mac Mini to a Raspberry Pi
|
||||
|
||||
A Raspberry Pi as a main desktop computer? Absolutely. Peter Garner shares how he [switched from a Mac Mini to a Raspberry Pi][2]. When Garner's Mac Mini needed to be replaced, he turned to a Raspberry Pi Model 2. This article explains the hardware and software choices Garner made to turn a humble Raspberry Pi into a functional desktop computer. His software choices range from the operating system (Arch Linux) and desktop environment (LXDE) to various applications for web browsing, messaging, email, audio, video, image processing, and more.
|
||||
|
||||
### 6 Raspberry Pi tutorials to try out
|
||||
|
||||
Opensource.com editor Lauren Pritchett shares [_6 Raspberry Pi tutorials to try out_][3]. This roundup of Raspberry Pi projects highlights some of the many different ways the Raspberry Pi can be used. The projects include setting up a VPN server, creating an object-tracking camera, displaying your favorite photos in a slideshow, playing retro video games, building a clock, and managing a home-brewed beer operation.
|
||||
|
||||
### Build a Kubernetes cluster with the Raspberry Pi
|
||||
|
||||
Chris Collins explains [how to install a Kubernetes cluster][4] on three or more Raspberry Pi 4s running Ubuntu 20.04. From configuring the host system through creating a Kubernetes cluster, the instructions Collins provides will walk you though through everything you need to create "your own 'private cloud at home' container service."
|
||||
|
||||
### 5 reasons to run Kubernetes on your Raspberry Pi homelab
|
||||
|
||||
Opensource.com editor Seth Kenlon shares [_5 reasons to run Kubernetes on your Raspberry Pi homelab_][5]. Kenlon begins by introducing Opensource.com's Kubernetes eBook by Chris Collins. He then answers the question, "What do you need Kubernetes for, anyway?" His reasons include that you can create a network-attached storage for your home, it is a good educational and upskilling experience, and it provides benefits for working with containers, web development, and web servers.
|
||||
|
||||
### How to manage a big hotel with a little Raspberry Pi
|
||||
|
||||
This tutorial by Giuseppe Cassibba explains how to manage a [hotel reservation system with a Raspberry Pi][6]. He shows how to install QloApps, a web-based software package designed for hotels, on a Raspberry Pi 3. Cassibba begins his tutorial by walking through the steps to install and configure a LAMP stack on Raspbian, and then covers the specifics of installing and setting up QloApps. Once the tutorial is complete, the Raspberry Pi will be configured to function as a hotel management system with customer and administrator web-based user interfaces.
|
||||
|
||||
### Set up a Tor proxy with Raspberry Pi to control internet traffic
|
||||
|
||||
In another article, Giuseppe Cassibba explains how to control internet traffic by setting up a [Tor proxy with Raspberry Pi][7]. The article begins with a brief introduction to Tor, then asks a few questions to determine if you need a Tor proxy or can use the Tor browser. The rest of the article provides detailed instructions on how to configure a Raspberry Pi Zero W as a Tor proxy and how to configure a web browser to connect to that proxy.
|
||||
|
||||
### How to set up the Raspberry Pi Zero for travel
|
||||
|
||||
Peter Garner provides tips on how to [set up a Raspberry Pi for remote work][8]. Taking a work laptop on a business trip means dealing with company and airport security policies, which can be a pain. As an alternative, Garner configured a super-small, ultra-portable Raspberry Pi Zero to function as a computer to take on trips. This article explains how he configured his Pi Zero to suit his needs. Garner gives in-depth explanations for his hardware and software choices to create a computer that meets his needs. This article should inspire anyone seeking to create a similar device.
|
||||
|
||||
### How many Raspberry Pis do you own?
|
||||
|
||||
This Opensource.com poll asked readers to [count their Raspberry Pi collection][9]. This simple question could have resulted in readers providing nothing more than the number of Raspberry Pis they own, but many commenters provided interesting anecdotes about what they are doing with their Pis. The article is not extremely deep, but it was the catalyst for a very interesting selection of comments.
|
||||
|
||||
### Run Kubernetes on a Raspberry Pi with k3s
|
||||
|
||||
Lee Carpenter demonstrates how to [run a Kubernetes on a Raspberry Pi][10]. This tutorial explains how to use k3s, a lightweight Kubernetes for use in resource-constrained environments, on three Raspberry Pis. The instructions explain how to set up a master node with two worker nodes and to connect to this cluster from a PC.
|
||||
|
||||
### Customize your Raspberry Pi operating system for everyday use
|
||||
|
||||
Patrick H. Mullins shows how you can [customize Raspberry Pi OS for your needs][11]. Instead of using the full Raspberry Pi OS, Mullins recommends using Rasberry Pi OS Lite and modifying it for your preferences. This article shows how to add software to Raspberry Pi OS Lite to turn it into a custom desktop operating system. Instructions are provided for installing X Windows, the XFCE desktop environment, a small selection of essential applications, and some "optional goodies."
|
||||
|
||||
* * *
|
||||
|
||||
What do you want to learn about Raspberry Pi in 2021? Please share your ideas in the comments, and if you have knowledge to share, please [consider writing about it for Opensource.com][12].
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/20/12/raspberry-pi
|
||||
|
||||
作者:[Joshua Allen Holm][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/holmja
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/raspberrypi_board_vector_red.png?itok=yaqYjYqI (Vector, generic Raspberry Pi board)
|
||||
[2]: https://opensource.com/article/20/3/mac-raspberry-pi
|
||||
[3]: https://opensource.com/article/20/3/raspberry-pi-tutorials
|
||||
[4]: https://opensource.com/article/20/6/kubernetes-raspberry-pi
|
||||
[5]: https://opensource.com/article/20/8/kubernetes-raspberry-pi
|
||||
[6]: https://opensource.com/article/20/4/qloapps-raspberry-pi
|
||||
[7]: https://opensource.com/article/20/4/tor-proxy-raspberry-pi
|
||||
[8]: https://opensource.com/article/20/3/raspberry-pi-zero
|
||||
[9]: https://opensource.com/article/20/3/raspberry-pi-poll
|
||||
[10]: https://opensource.com/article/20/3/kubernetes-raspberry-pi-k3s
|
||||
[11]: https://opensource.com/article/20/6/custom-raspberry-pi
|
||||
[12]: https://opensource.com/how-submit-article
|
@ -0,0 +1,388 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Deploy Fedora CoreOS servers with Terraform)
|
||||
[#]: via: (https://fedoramagazine.org/deploy-fedora-coreos-with-terraform/)
|
||||
[#]: author: (Nathan Smith https://fedoramagazine.org/author/nfsmith/)
|
||||
|
||||
Deploy Fedora CoreOS servers with Terraform
|
||||
======
|
||||
|
||||
![][1]
|
||||
|
||||
Photo by [Jasper Boer][2] on [Unsplash][3]
|
||||
|
||||
Fedora CoreOS is a lightweight, secure operating system optimized for running containerized workloads. A YAML document is all you need to describe the workload you’d like to run on a Fedora CoreOS server.
|
||||
|
||||
This is wonderful for a single server, but how would you describe a fleet of cooperating Fedora CoreOS servers? For example, what if you wanted a set of servers running load balancers, others running a database cluster and others running a web application? How can you get them all configured and provisioned? How can you configure them to communicate with each other? This article looks at how Terraform solves this problem.
|
||||
|
||||
### Getting started
|
||||
|
||||
Before you start, decide whether you need to review the basics of Fedora CoreOS. Check out this [previous article][4] on the Fedora Magazine:
|
||||
|
||||
> [Getting started with Fedora CoreOS][4]
|
||||
|
||||
**Terraform** is an open source tool for defining and provisioning infrastructure. Terraform defines infrastructure as code in files. It provisions infrastructure by calculating the difference between the desired state in code and observed state and applying changes to remove the difference.
|
||||
|
||||
HashiCorp, the company that created and maintains Terraform, offers an RPM repository to install Terraform.
|
||||
|
||||
```
|
||||
sudo dnf config-manager --add-repo \
|
||||
https://rpm.releases.hashicorp.com/fedora/hashicorp.repo
|
||||
sudo dnf install terraform
|
||||
```
|
||||
|
||||
To get yourself familiar with the tools, start with a simple example. You’re going to create a single Fedora CoreOS server in AWS. To follow along, you need to install _awscli_ and have an AWS account. _awscli_ can be installed from the Fedora repositories and configured using the _aws configure_ command
|
||||
|
||||
```
|
||||
sudo dnf install -y awscli
|
||||
aws configure
|
||||
```
|
||||
|
||||
_**Please note,** AWS is a paid service. If executed correctly, participants should expect less than $1 USD in charges, but mistakes may lead to unexpected charges_.
|
||||
|
||||
### Configuring Terraform
|
||||
|
||||
In a new directory, create a file named _config.yaml_. This file will hold the contents of your Fedore CoreOS configuration. The configuration simply adds an SSH key for the _core_ user. Modify the ******_authorized_ssh_key_ section to use your own.
|
||||
|
||||
```
|
||||
variant: fcos
|
||||
version: 1.2.0
|
||||
passwd:
|
||||
users:
|
||||
- name: core
|
||||
authorized_ssh_keys:
|
||||
- "ssh-ed25519 AAAAC3....... user@hostname"
|
||||
```
|
||||
|
||||
Next, create a file _main.tf_ to contain your Terraform specification. Take a look at the contents section by section. It begins with a block to specify the versions of your providers.
|
||||
|
||||
```
|
||||
terraform {
|
||||
required_providers {
|
||||
ct = {
|
||||
source = "poseidon/ct"
|
||||
version = "0.7.1"
|
||||
}
|
||||
aws = {
|
||||
source = "hashicorp/aws"
|
||||
version = "~> 3.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Terraform uses providers to control infrastructure. Here it uses the AWS provider to provision EC2 servers, but it can provision any kind of AWS infrastructure. The [ct provider][5] from [Poseidon Labs][6] stands for _config transpiler_. This provider will [transpile][7] Fedora CoreOS configurations into Ignition configurations. As a result, you do not need to use _[fcct][8]_ to transpile your configurations. Now that your provider versions are specified, initialize them.
|
||||
|
||||
```
|
||||
provider "aws" {
|
||||
region = "us-west-2"
|
||||
}
|
||||
|
||||
provider "ct" {}
|
||||
```
|
||||
|
||||
The AWS region is set to _us-west-2_ and the _ct_ provider requires no configuration. With the providers configured, you’re ready to define some infrastructure. Use a _[data source][9]_ block to read the configuration.
|
||||
|
||||
```
|
||||
data "ct_config" "config" {
|
||||
content = file("config.yaml")
|
||||
strict = true
|
||||
}
|
||||
```
|
||||
|
||||
With this data block defined, you can now access the transpiled Ignition output as _data.ct_config.config.rendered_. To create an EC2 server, use a [resource][10] block, and pass the Ignition output as the _user_data_ attribute.
|
||||
|
||||
```
|
||||
resource "aws_instance" "server" {
|
||||
ami = "ami-0699a4456969d8650"
|
||||
instance_type = "t3.micro"
|
||||
user_data = data.ct_config.config.rendered
|
||||
}
|
||||
```
|
||||
|
||||
This configuration hard-codes the virtual machine image (AMI) to the latest _stable_ image of Fedora CoreOS in the _us-west-2_ region at time of writing. If you would like to use a different region or stream, you can discover the correct AMI on the [Fedora CoreOS downloads page][11].
|
||||
|
||||
Finally, you’d like to know the public IP address of the server once it’s created. Use an _[output][12]_ block to define the outputs to be displayed once Terraform completes its provisioning.
|
||||
|
||||
```
|
||||
output "instance_ip_addr" {
|
||||
value = aws_instance.server.public_ip
|
||||
}
|
||||
```
|
||||
|
||||
Alright! You’re ready to create some infrastructure. To deploy the server simply run:
|
||||
|
||||
```
|
||||
terraform init # Installs the provider dependencies
|
||||
terraform apply # Displays the proposed changes and applies them
|
||||
```
|
||||
|
||||
Once **completed, Terraform prints the public IP address of the server, and you can SSH to the server by running _ssh core@{public ip here}_. Congratulations — you’ve provisioned your first Fedora CoreOS server using Terraform!
|
||||
|
||||
### Updates and immutability
|
||||
|
||||
At this point you can modify the configuration in _config.yaml_ however you like. To deploy your change simply run _terraform apply_ again. Notice that each time you change the configuration, when you run _terraform apply_ it destroys the server and creates a new one. This aligns well with the Fedora CoreOS philosophy: Configuration can only happen once. Want to change that configuration? Create a new server. This can feel pretty alien if you’re accustomed to provisioning your servers once and continuously re-configuring them with tools like [Ansible][13], [Puppet][14] or [Chef][15].
|
||||
|
||||
The benefit of always creating new servers is that it is significantly easier to test that newly provisioned servers will act as expected. It can be much more difficult to account for all of the possible ways in which updating a system in place may break. Tooling that adheres to this philosophy typically falls under the heading of _Immutable Infrastructure_. This approach to infrastructure has some of the same benefits seen in functional programming techniques, namely that mutable state is often a source of error.
|
||||
|
||||
### Using variables
|
||||
|
||||
You can use Terraform [input variables][16] to parameterize your infrastructure. In the previous example, you might like to parameterize the AWS region or instance type. This would let you deploy several instances of the same configuration with differing parameters. What if you want to parameterize the Fedora CoreOS configuration? Do so using the [_templatefile_][17] function.
|
||||
|
||||
As an example, try parameterizing the username of your user. To do this, add a _username_ variable to the _main.tf_ file:
|
||||
|
||||
```
|
||||
variable "username" {
|
||||
type = string
|
||||
description = "Fedora CoreOS user"
|
||||
default = "core"
|
||||
}
|
||||
```
|
||||
|
||||
Next, modify the _config.yaml_ file to turn it into a template. When rendered, the _${username}_ will be replaced.
|
||||
|
||||
```
|
||||
variant: fcos
|
||||
version: 1.2.0
|
||||
passwd:
|
||||
users:
|
||||
- name: ${username}
|
||||
authorized_ssh_keys:
|
||||
- "ssh-ed25519 AAAAC3....... user@hostname"
|
||||
```
|
||||
|
||||
Finally, modify the data block to render the template using the _templatefile_ function.
|
||||
|
||||
```
|
||||
data "ct_config" "config" {
|
||||
content = templatefile(
|
||||
"config.yaml",
|
||||
{ username = var.username }
|
||||
)
|
||||
strict = true
|
||||
}
|
||||
```
|
||||
|
||||
To deploy with _username_ set to _jane_, run _terraform apply -var=”username=jane”_. To verify, try to SSH into the server with _ssh jane@{public ip address}_.
|
||||
|
||||
### Leveraging the dependency graph
|
||||
|
||||
Passing variables from Terraform into Fedora CoreOS configuration is quite useful. But you can go one step further and pass infrastructure data into the server configuration. This is where Terraform and Fedora CoreOS start to really shine.
|
||||
|
||||
Terraform creates a [dependency graph][18] to model the state of infrastructure and to plan updates. If the output of one resource (e.g the public IP address of a server) is passed as the input of another service (e.g the destination in a firewall rule), Terraform understands that changes in the former require recreating or modifying the later. If you pass infrastructure data into a Fedora CoreOS configuration, it will participate in the dependency graph. Updates to the inputs will trigger creation of a new server with the new configuration.
|
||||
|
||||
Consider a system of one load balancer and three web servers as an example.
|
||||
|
||||
![][19]
|
||||
|
||||
The goal is to configure the load balancer with the IP address of each web server so that it can forward traffic to them.
|
||||
|
||||
### Web server configuration
|
||||
|
||||
First, create a file _web.yaml_ and add a simple Nginx configuration with a templated message.
|
||||
|
||||
```
|
||||
variant: fcos
|
||||
version: 1.2.0
|
||||
systemd:
|
||||
units:
|
||||
- name: nginx.service
|
||||
enabled: true
|
||||
contents: |
|
||||
[Unit]
|
||||
Description=Nginx Web Server
|
||||
After=network-online.target
|
||||
Wants=network-online.target
|
||||
[Service]
|
||||
ExecStartPre=-/bin/podman kill nginx
|
||||
ExecStartPre=-/bin/podman rm nginx
|
||||
ExecStartPre=/bin/podman pull nginx
|
||||
ExecStart=/bin/podman run --name nginx -p 80:80 -v /etc/nginx/index.html:/usr/share/nginx/html/index.html:z nginx
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
storage:
|
||||
directories:
|
||||
- path: /etc/nginx
|
||||
files:
|
||||
- path: /etc/nginx/index.html
|
||||
mode: 0444
|
||||
contents:
|
||||
inline: |
|
||||
<html>
|
||||
<h1>Hello from Server ${count}</h1>
|
||||
</html>
|
||||
```
|
||||
|
||||
In _main.tf_, you can create three web servers using this template with the following blocks:
|
||||
|
||||
```
|
||||
data "ct_config" "web" {
|
||||
count = 3
|
||||
content = templatefile(
|
||||
"web.yaml",
|
||||
{ count = count.index }
|
||||
)
|
||||
strict = true
|
||||
}
|
||||
|
||||
resource "aws_instance" "web" {
|
||||
count = 3
|
||||
ami = "ami-0699a4456969d8650"
|
||||
instance_type = "t3.micro"
|
||||
user_data = data.ct_config.web[count.index].rendered
|
||||
}
|
||||
```
|
||||
|
||||
Notice the use of _count = 3_ and the _count.index_ variable. You can use [count][20] to make many copies of a resource. Here, it creates three configurations and three web servers. The _count.index_ variable is used to pass the first configuration to the first web server and so on.
|
||||
|
||||
### Load balancer configuration
|
||||
|
||||
The load balancer will be a basic [HAProxy load balancer][21] that forwards to each server. Place the configuration in a file named _lb.yaml_:
|
||||
|
||||
```
|
||||
variant: fcos
|
||||
version: 1.2.0
|
||||
systemd:
|
||||
units:
|
||||
- name: haproxy.service
|
||||
enabled: true
|
||||
contents: |
|
||||
[Unit]
|
||||
Description=Haproxy Load Balancer
|
||||
After=network-online.target
|
||||
Wants=network-online.target
|
||||
[Service]
|
||||
ExecStartPre=-/bin/podman kill haproxy
|
||||
ExecStartPre=-/bin/podman rm haproxy
|
||||
ExecStartPre=/bin/podman pull haproxy
|
||||
ExecStart=/bin/podman run --name haproxy -p 80:8080 -v /etc/haproxy/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro haproxy
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
storage:
|
||||
directories:
|
||||
- path: /etc/haproxy
|
||||
files:
|
||||
- path: /etc/haproxy/haproxy.cfg
|
||||
mode: 0444
|
||||
contents:
|
||||
inline: |
|
||||
global
|
||||
log stdout format raw local0
|
||||
defaults
|
||||
mode tcp
|
||||
log global
|
||||
option tcplog
|
||||
frontend http
|
||||
bind *:8080
|
||||
default_backend http
|
||||
backend http
|
||||
balance roundrobin
|
||||
%{ for name, addr in servers ~}
|
||||
server ${name} ${addr}:80 check
|
||||
%{ endfor ~}
|
||||
```
|
||||
|
||||
The template expects a [map][22] with server names as keys and IP addresses as values. You can create that using the [_zipmap_][23] function. Use the ID of the web servers as keys and the public IP addresses as values.
|
||||
|
||||
```
|
||||
data "ct_config" "lb" {
|
||||
content = templatefile(
|
||||
"lb.yaml",
|
||||
{
|
||||
servers = zipmap(
|
||||
aws_instance.web.*.id,
|
||||
aws_instance.web.*.public_ip
|
||||
)
|
||||
}
|
||||
)
|
||||
strict = true
|
||||
}
|
||||
|
||||
resource "aws_instance" "lb" {
|
||||
ami = "ami-0699a4456969d8650"
|
||||
instance_type = "t3.micro
|
||||
user_data = data.ct_config.lb.rendered
|
||||
}
|
||||
```
|
||||
|
||||
Finally, add an output block to display the IP address of the load balancer.
|
||||
|
||||
```
|
||||
output "load_balancer_ip" {
|
||||
value = aws_instance.lb.public_ip
|
||||
}
|
||||
```
|
||||
|
||||
All right! Run _terraform apply_ and the IP address of the load balancer displays on completion. You should be able to make requests to the load balancer and get responses from each web server.
|
||||
|
||||
```
|
||||
$ export LB={{load balancer IP here}}
|
||||
$ curl $LB
|
||||
<html>
|
||||
<h1>Hello from Server 0</h1>
|
||||
</html>
|
||||
$ curl $LB
|
||||
<html>
|
||||
<h1>Hello from Server 1</h1>
|
||||
</html>
|
||||
$ curl $LB
|
||||
<html>
|
||||
<h1>Hello from Server 2</h1>
|
||||
</html>
|
||||
```
|
||||
|
||||
Now you can modify the configuration of the web servers or load balancer. Any changes can be realized by running _terraform apply_ once again. Note in particular that any change to the web server IP addresses will cause Terraform to recreate the load balancer (changing the count from 3 to 4 is a simple test). Hopefully this emphasizes that the load balancer configuration is indeed a part of the Terraform dependency graph.
|
||||
|
||||
### Clean up
|
||||
|
||||
You can destroy all the infrastructure using the _terraform destroy_ command. Simply navigate to the folder where you created _main.tf_ and run _terraform destroy_.
|
||||
|
||||
### Where next?
|
||||
|
||||
Code for this tutorial can be found at [this GitHub repository][24]. Feel free to play with examples and contribute more if you find something you’d love to share with the world. To learn more about all the amazing things Fedora CoreOS can do, dive into [the docs][25] or come chat with [the community][26]. To learn more about Terraform, you can rummage through [the docs][27], checkout #terraform on [freenode][28], or contribute on [GitHub][29].
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://fedoramagazine.org/deploy-fedora-coreos-with-terraform/
|
||||
|
||||
作者:[Nathan Smith][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/nfsmith/
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://fedoramagazine.org/wp-content/uploads/2020/12/terraform-816x345.jpg
|
||||
[2]: https://unsplash.com/@jasperboer?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText
|
||||
[3]: https://unsplash.com/s/photos/landscape?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText
|
||||
[4]: https://fedoramagazine.org/getting-started-with-fedora-coreos/
|
||||
[5]: https://github.com/poseidon/terraform-provider-ct
|
||||
[6]: https://www.psdn.io/
|
||||
[7]: https://en.wikipedia.org/wiki/Source-to-source_compiler
|
||||
[8]: https://docs.fedoraproject.org/en-US/fedora-coreos/using-fcct/
|
||||
[9]: https://www.terraform.io/docs/configuration/data-sources.html
|
||||
[10]: https://www.terraform.io/docs/configuration/blocks/resources/syntax.html
|
||||
[11]: https://getfedora.org/en/coreos/download?tab=cloud_launchable&stream=stable
|
||||
[12]: https://www.terraform.io/docs/configuration/outputs.html
|
||||
[13]: https://www.ansible.com/
|
||||
[14]: https://puppet.com/
|
||||
[15]: https://www.chef.io/
|
||||
[16]: https://www.terraform.io/docs/configuration/variables.html
|
||||
[17]: https://www.terraform.io/docs/configuration/functions/templatefile.html
|
||||
[18]: https://www.terraform.io/docs/internals/graph.html
|
||||
[19]: https://fedoramagazine.org/wp-content/uploads/2020/12/diagram.png
|
||||
[20]: https://www.terraform.io/docs/configuration/meta-arguments/count.html
|
||||
[21]: https://www.haproxy.org/
|
||||
[22]: https://www.terraform.io/docs/configuration/expressions/types.html#maps-objects
|
||||
[23]: https://www.terraform.io/docs/configuration/functions/zipmap.html
|
||||
[24]: https://github.com/nsmith5/fcos-terraform-tutorial
|
||||
[25]: https://docs.fedoraproject.org/en-US/fedora-coreos/getting-started/
|
||||
[26]: https://discussion.fedoraproject.org/c/server/coreos/5
|
||||
[27]: https://www.terraform.io/docs/index.html
|
||||
[28]: https://freenode.net/
|
||||
[29]: https://github.com/hashicorp/terraform
|
@ -0,0 +1,79 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (How to use the Eclipse IDE as your text editor)
|
||||
[#]: via: (https://opensource.com/article/20/12/eclipse)
|
||||
[#]: author: (Seth Kenlon https://opensource.com/users/seth)
|
||||
|
||||
How to use the Eclipse IDE as your text editor
|
||||
======
|
||||
Though technically an IDE, Eclipse offers a robust editing suite with
|
||||
lots of extensions to give you the tools you need.
|
||||
![Women in computing and open source v5][1]
|
||||
|
||||
Eclipse is an IDE (integrated development environment). It’s definitely not a text editor. Then again, an IDE is really just a text editor with a lot of extra features for specific kinds of text. Furthermore, an IDE is often _home_ to a developer. Developers have their IDE of choice open all day long, so it’s natural to stay in that IDE when it’s time to write a project README file, or to jot down a quick note, or to just make a grocery list. So sometimes, an IDE is just a text editor, after all.
|
||||
|
||||
### Installing
|
||||
|
||||
One of Eclipse’s advantages as a platform is that it’s wildly popular. It’s the default Java IDE in many a classroom and business, and it’s easy to obtain regardless of your operating system.
|
||||
|
||||
On Linux, you can install Eclipse from your software repository.
|
||||
|
||||
On Mac or Windows, download an installer from [eclipse.org][2].
|
||||
|
||||
Eclipse is a big project, so if you have a favorite programming language, you can download a version of Eclipse tuned specifically for that language. However, you can’t go wrong by just downloading the Java one and adding extensions to it for further development options.
|
||||
|
||||
### Launching Eclipse
|
||||
|
||||
When you first launch Eclipse, you’re prompted to establish a workspace. This is a useful convention of many IDEs, designed to ensure that all of your active development libraries and projects are centrally located on your computer. This way, you don’t throw out a directory of libraries and headers you’ve forgotten your project relies upon, and you’re less likely to bundle in libraries from your base system, forgetting that your users will need to install them separately before running your code. The default location for Eclipse’s workspace is `~/eclipse-workspace`.
|
||||
|
||||
![eclipse workspace with white text on grey background][3]
|
||||
|
||||
### Eclipse projects
|
||||
|
||||
Eclipse is designed for formal _projects_. It assumes that you’re building an application or command or library consisting of many related files. Even when you create a text file, Eclipse assumes that it’s probably a `README` or a configuration file for your project. If you want to use Eclipse to create arbitrary text files that are not associated with a code project, then you can create a project file just for your text files.
|
||||
|
||||
To create a new project, navigate to the **File** menu and select **New Project**. From the list of project templates, select **General**. Once you have a project created, you can use it to store arbitrary text files created and maintained within Eclipse.
|
||||
|
||||
### Extensions
|
||||
|
||||
By default, Eclipse is adept with XML and can handle plain text adequately. [I write in XML whenever I get the chance][4], and Eclipse makes for an excellent XML workbench. If you don’t write in XML for fun, though, you might prefer to have syntax highlighting for your favorite syntax, too. Eclipse is extensible, so you can install plugins to add to its features.
|
||||
|
||||
One of my favorite plugins is [LiClipseText][5], a configurable syntax highlighter for several text formats. To install it (or any Eclipse extension), navigate to the **Help** menu and select **Eclipse Marketplace**. Search the Marketplace for LiClipse, and then click the **Install** button on the result. Depending on the speed of your Internet and computer, wait for the extension to install, and then allow Eclipse to restart so it can load the extension into your environment.
|
||||
|
||||
![Eclipse marketplace showing available editors ][6]
|
||||
|
||||
In my experience, most document format plugins are activated according to file extension association. In other words, when I open a file with a name ending in .md or .mdown, LiClipseText is enabled in the text editing window.
|
||||
You can adjust file associations in Eclipse’s preferences in case you want to override defaults loaded by an extension or by Eclipse itself.
|
||||
|
||||
### Eclipse for text editing
|
||||
|
||||
Writing in Eclipse feels very natural. After all, Eclipse primarily operates upon text anyway, so it’s well equipped whether your text contains code or natural language. In fact, I’ve found that there are some small bonuses to using a code editor like Eclipse for natural language processing. For instance, the occurrence marker in Eclipse highlights all occurrences of a specific term. When programming, this is useful so you can visualize where variables and functions are being used. When you’re writing, you can activate the same feature, and I’ve found that it helps me keep the terms I’m using consistent, and by contrast, it helps me detect overuse of any given phrase.
|
||||
|
||||
Eclipse can also handle diffs and patches with ease, and it’s got version control integration, so synchronizing work between computers is trivial.
|
||||
|
||||
Whether you use Eclipse as your primary text editor or just for required text files you’re bundling along with applications you develop, it’s a great platform for writing.
|
||||
|
||||
How to set up your Eclipse environment with Python and EASE, and a few ideas to supercharge your...
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/20/12/eclipse
|
||||
|
||||
作者:[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/OSDC_women_computing_5.png?itok=YHpNs_ss (Women in computing and open source v5)
|
||||
[2]: https://www.eclipse.org/downloads/packages/
|
||||
[3]: https://opensource.com/sites/default/files/uploads/eclipse-31_days-eclipse-opensource.png (eclipse workspace with white text on grey background)
|
||||
[4]: https://opensource.com/article/17/9/docbook
|
||||
[5]: https://marketplace.eclipse.org/content/liclipsetext
|
||||
[6]: https://opensource.com/sites/default/files/uploads/eclipse-marketplace-31_days-eclipse-opensource.jpg (Eclipse marketplace showing available editors )
|
123
sources/tech/20201224 5 reasons to use the Atom text editor.md
Normal file
123
sources/tech/20201224 5 reasons to use the Atom text editor.md
Normal file
@ -0,0 +1,123 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (5 reasons to use the Atom text editor)
|
||||
[#]: via: (https://opensource.com/article/20/12/atom)
|
||||
[#]: author: (Seth Kenlon https://opensource.com/users/seth)
|
||||
|
||||
5 reasons to use the Atom text editor
|
||||
======
|
||||
Atom is a comprehensive environment that can accomplish tasks from basic
|
||||
to complex, for users from beginners to veterans.
|
||||
![Science lab with beakers][1]
|
||||
|
||||
Beautiful open source text editors are pretty common these days, between Adobe’s [Brackets][2], Microsoft’s [VSCode][3], and GitHub’s [Atom][4]. Each of these seem to offer similar experiences: a modern interface, easily installable plugins, and a big brand-name sponsor. And they’re all actually really good. So what sets Atom apart from any other hyper-modern text editor? Or from a classic old editor like [Vim][5] or [Emacs][6]?
|
||||
|
||||
![Atom terminal with white text on dark grey background][7]
|
||||
|
||||
I’ve used lots of text editors, and upon reflection, I have to admit that once you’ve seen one text editor, you’ve basically seen them all. When judging an editor’s efficacy, 80% of the requirements are satisfied as long as it does one thing: edit text. The other 20% are bonus conveniences, extra gizmos, and fanciful features. They’re nice to have but hardly essential.
|
||||
|
||||
I often come back to Atom, though, because, as a user of open source, I have the luxury of using an application just because I can. Here’s what I like about Atom.
|
||||
|
||||
### Beginner-friendly
|
||||
|
||||
One of my favorite things about Atom is that it feels pretty "normal." I can install Atom on anyone’s computer and they’re off and typing in no time. No new keyboard shortcuts to learn, no serious deviations from user interface conventions. If I take a few minutes to show them a few power features of the application, then they're quickly empowered to install new plugins and discover useful features they enjoy.
|
||||
|
||||
It’s just different enough to feel unique but "safe" enough to trick people into believing (and rightly so) they can use it. That’s a hard line to walk, but Atom manages it, and I appreciate it for that.
|
||||
|
||||
### Great extensions
|
||||
|
||||
When most requirements have been filled as soon as you launch the application, a major factor in "selling" an open source text editor is its extensions. My habitual editor is [GNU Emacs][8], which has a mind-boggling array of extensions so versatile that they can provide everything from an email client to a video game. That’s a hard act to top, and to be honest, I’ve yet to see the editor that can. It shows how important extensions can be, though, and Atom has a nice set of plugins.
|
||||
|
||||
There are extensions to add syntax highlighting for languages and formats, to add dynamic linting, and to integrate debuggers, runtime environments, video and music player controls, and much more.
|
||||
You can practically make Atom the control hub for your desktop, so you rarely have to leave it.
|
||||
|
||||
### Language and syntax support
|
||||
|
||||
I’m a documented fan of [Docbook][9]. By extension, I’m a fan of its simplified front-end, Asciidoc. When I evaluate an editor, Docbook schema and Asciidoc support are two of my primary metrics. While XML support is relatively common, integration with a specific schema can be a tall order, and Asciidoc is still relatively obscure. Atom's community provides great support for my favorite formats.
|
||||
|
||||
Of course, I’ve already mentioned that Atom has great extensions in general, but syntax highlighting is an important feature regardless of what language you're typing. Once again, thanks to a vibrant community, the variety of syntax highlighter options in Atom’s package repository is one of the best.
|
||||
|
||||
### Easy theming
|
||||
|
||||
Atom makes generating your own style as easy as styling a website, so if you’re competent with CSS, you can make your own Atom theme. To create your own theme, navigate to the **Package** menu. If you don’t see a **Package** menu, press the **Alt** key first to reveal the top menu bar. In the **Package** menu, hover over **Package Generator** and then select **Generate Atom Syntax Theme**. This opens a new project called _my-theme-syntax_ by default. You can name it whatever you want, but it should end in `-syntax` according to Atom convention.
|
||||
|
||||
In your new theme project, locate these files: `base.less`, `colors.less`, and `syntax-variables.less`. These define how special keywords, and even background and foreground colors, are themed when your syntax is active. Because they all inherit values from a common template, it’s pretty easy to hack on. For example:
|
||||
|
||||
|
||||
```
|
||||
// Syntax styles
|
||||
|
||||
.syntax--comment {
|
||||
color: @light-gray;
|
||||
}
|
||||
|
||||
.syntax--keyword {
|
||||
color: @purple;
|
||||
|
||||
&.syntax--control {
|
||||
color: @purple;
|
||||
}
|
||||
|
||||
&.syntax--operator {
|
||||
color: @syntax-text-color;
|
||||
}
|
||||
|
||||
&.syntax--other.syntax--special-method {
|
||||
color: @blue;
|
||||
}
|
||||
|
||||
&.syntax--other.syntax--unit {
|
||||
color: @orange;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
The values ending with two dashes, such as `.syntax--keyword`, are objects recognized by a syntax highlighting engine. If you want to develop your customizations further, of course, you can even create your own syntax definitions (although that’s more work than CSS theming). Read all about the ways to hack Atom at [flight-manual.atom.io][10].
|
||||
|
||||
### Flexible workflow
|
||||
|
||||
Atom has lots of features, and only a subset of them are activated by default. This means you get to decide how you prefer to work, whether you activate new extensions and use them to change Atom on a fundamental level, or you just open up Atom’s preferences and make small adjustments. You can use Atom for writing a fiction book or for writing Python code or technical documentation or anything else.
|
||||
|
||||
Even its Git integration doesn’t insist on what you might imagine would be the obvious repository (Github sponsors Atom). It doesn’t have an agenda, and it’s equally useful to everyone, regardless of audience.
|
||||
|
||||
## Installing
|
||||
|
||||
On Linux, Windows, and macOS, you can [install Atom from its website][11].
|
||||
|
||||
Alternately, on Linux, you can install Atom as a Flatpak from [Flathub][12].
|
||||
|
||||
If you want to build Atom yourself, you can also [compile it from its source code on Github][13].
|
||||
|
||||
## Try Atom
|
||||
|
||||
Atom could be your next text editor, notepad, and IDE. It’s easy to use, easy to configure, easy to extend, and it offers a great user experience. Download Atom today, and give it a try.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/20/12/atom
|
||||
|
||||
作者:[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/science_experiment_beaker_lab.png?itok=plKWRhlU (Science lab with beakers)
|
||||
[2]: https://opensource.com/article/20/12/brackets
|
||||
[3]: https://opensource.com/article/20/12/%C2%A0https://opensource.com/article/20/6/open-source-alternatives-vs-code
|
||||
[4]: https://opensource.com/article/17/5/atom-text-editor-packages-writers
|
||||
[5]: https://opensource.com/article/20/12/vi-text-editor
|
||||
[6]: https://opensource.com/article/20/12/emacs
|
||||
[7]: https://opensource.com/sites/default/files/uploads/atom-31_days-atom-opensource.png (Atom terminal with white text on dark grey background)
|
||||
[8]: https://opensource.com/article/20/2/who-cares-about-emacs
|
||||
[9]: https://opensource.com/article/17/9/docbook
|
||||
[10]: https://flight-manual.atom.io/
|
||||
[11]: https://atom.io
|
||||
[12]: https://flathub.org/apps/details/io.atom.Atom
|
||||
[13]: https://github.com/atom
|
@ -0,0 +1,80 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (3 critical DevOps concepts we explored in 2020)
|
||||
[#]: via: (https://opensource.com/article/20/12/devops)
|
||||
[#]: author: (Dawn Parzych https://opensource.com/users/dawnparzych)
|
||||
|
||||
3 critical DevOps concepts we explored in 2020
|
||||
======
|
||||
In 2020, Opensource.com's top DevOps articles focused on testing,
|
||||
software methodologies, and the most important part: the people
|
||||
![Looking at a map][1]
|
||||
|
||||
Looking back through Opensource.com's articles about [DevOps][2] in 2020, there was a bit of something for everyone—from people starting the DevOps journey to seasoned DevOps veterans. The articles focused on testing, software methodologies, and DevOps' most important part: the people. Here are the top 10 DevOps articles of 2020.
|
||||
|
||||
### Test-driven development
|
||||
|
||||
Alex Bunardzic shared [many articles about testing][3] this year, and I narrowed the list down to the top three. If you are interested in testing (and I would argue that anybody involved in writing or supporting software should have at least a passing interest in testing), check out these articles.
|
||||
|
||||
In _[How to get started with test-driven development][4]_, Alex uses an analogy to describe the fundamentals of test-driven development (TDD) and explain dependencies and how to eliminate them for testing purposes.
|
||||
|
||||
If you're going to practice TDD, you need to understand how and when to write a unit test. Alex shares his best practices in [_Writing unit test after writing code considered harmful in test-driven development_][5].
|
||||
|
||||
Testing is about determining if code is working as designed, and [_What does it mean for code to "work"?_][6] explores how to define what working code looks like from the perspective of observable behavior.
|
||||
|
||||
### Software methodologies
|
||||
|
||||
People sometimes ask, "How does 'concept x' relate to DevOps?" Both [_DevOps vs. Agile: What's the difference?_][7] by Tonya Brown and [_How does kanban relate to DevOps_][8]_?_ by Willy-Peter Schaub address these questions head-on. Willy explains the four pivotal kanban practices then dives into how they are similar to DevOps. Tonya highlights similarities and differences between DevOps and agile. If you're starting out on your DevOps journey, these articles will help you understand how DevOps is similar to and different from your current practices.
|
||||
|
||||
And speaking of starting out, Sameer S Paradkar's article [_A beginner's guide to everything DevOps_][9] should be bookmarked and shared with anyone new to the practice. He covers everything from how DevOps addresses development and operations challenges, to the differences between traditional IT processes and DevOps, to understanding the DevOps lifecycle. To top it off, Sameer ends with a handy cheat sheet to open source DevOps tools.
|
||||
|
||||
### People
|
||||
|
||||
The people are the most important part of DevOps. They are the ones writing the software, supporting it, building automation, and so much more. Finding the right people is more important than implementing the right tools.
|
||||
|
||||
The right mindset is required to navigate DevOps. In [_10 tips for maintaining a DevOps mindset for distributed teams_][10], Willy-Peter Shaub shares how that mindset helps in the new era of remote work:
|
||||
|
||||
> "A healthy DevOps mindset navigates through different paths of continuous improvement wherein disruption, discipline, and guardrails are the norm. What no one anticipated is the radical disruption we are all experiencing due to the pandemic, and the impact it has on our DevOps and personal mindset, our workflows, and the ceremonies of kanban and agile teams."
|
||||
|
||||
This mindset is crucial as teams evolve how we collaborate, communicate, and deliver software for the remote world.
|
||||
|
||||
Yet, it's not the only thing you need to be successful in DevOps. Josh Atwell shared his list of key skills for DevOps success in [_How to be the right person for DevOps_][11]. It may come as a surprise, but none of the skills are related to programming languages or tools. Being the right person for DevOps requires communication, selflessness, and self-care, Josh says.
|
||||
|
||||
Even the right mindset and attitude won't make everything perfect; there will still be challenges. One of the challenges people face today is burnout. People are getting tired of being remote, and they are looking for things to return to "normal." In [_DevOps is a solution to burnout worth investing in_][12], I discuss how changing underlying processes and cultures can help reduce or prevent burnout.
|
||||
|
||||
Finally, if you're looking for a career change in 2021, consider the role of scrum master. Tonya Brown outlined a day in the life of a scrum master in [_What does a scrum master do?_][13] If you like removing impediments and coaching people on solving problems, this may be a role for you.
|
||||
|
||||
* * *
|
||||
|
||||
What DevOps topics are you interested in reading about? Please share your ideas in the comments, and if you have knowledge to share, please [consider writing about it for Opensource.com][14].
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/20/12/devops
|
||||
|
||||
作者:[Dawn Parzych][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/dawnparzych
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/tips_map_guide_ebook_help_troubleshooting_lightbulb_520.png?itok=L0BQHgjr (Looking at a map)
|
||||
[2]: https://opensource.com/resources/devops
|
||||
[3]: https://opensource.com/users/alex-bunardzic
|
||||
[4]: https://opensource.com/article/20/1/test-driven-development
|
||||
[5]: https://opensource.com/article/20/2/automate-unit-tests
|
||||
[6]: https://opensource.com/article/20/7/code-tdd
|
||||
[7]: https://opensource.com/article/20/2/devops-vs-agile
|
||||
[8]: https://opensource.com/article/20/4/kanban-devops
|
||||
[9]: https://opensource.com/article/20/2/devops-beginners
|
||||
[10]: https://opensource.com/article/20/6/devops-mindset
|
||||
[11]: https://opensource.com/article/20/3/devops-relationships
|
||||
[12]: https://opensource.com/article/20/1/devops-burnout-solution
|
||||
[13]: https://opensource.com/article/20/7/scrum-master
|
||||
[14]: https://opensource.com/how-submit-article
|
131
sources/tech/20201225 How to use heredoc as a text editor.md
Normal file
131
sources/tech/20201225 How to use heredoc as a text editor.md
Normal file
@ -0,0 +1,131 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (geekpi)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (How to use heredoc as a text editor)
|
||||
[#]: via: (https://opensource.com/article/20/12/heredoc)
|
||||
[#]: author: (Seth Kenlon https://opensource.com/users/seth)
|
||||
|
||||
How to use heredoc as a text editor
|
||||
======
|
||||
This obscure terminal feature provides a text editor in a pinch.
|
||||
![woman on laptop sitting at the window][1]
|
||||
|
||||
There’s a somewhat obscure feature in Linux and Unix shells that allows you to open a sort of do-while loop for the [cat][2] command. It’s called the _heredoc_, and it enables you to have, more or less, a text editor no matter what shell you’re using. The syntax is:
|
||||
|
||||
|
||||
```
|
||||
`$ cat << EOF >> example.txt`
|
||||
```
|
||||
|
||||
The string in the middle is, essentially, a conditional that stops the loop. That is, if you type alone on a line, the loop ends. During the loop, whatever you type into your terminal is piped into the destination file (in this case).
|
||||
|
||||
### Installing
|
||||
|
||||
As long as you have a terminal, you already have the ability to initiate a heredoc. I’ve used this syntactical trick in [Bash][3], [tsch][4], and Korn shell.
|
||||
|
||||
### Using heredoc
|
||||
|
||||
To open a heredoc "session", you use the cat command with redirection that points first to cat with a terminating string (common convention is **EOF** for "End Of File", but it can actually be anything). After the terminating keyword, you redirect your output to a destination file. You're then able to type directly into your terminal, using most common shell keyboard shortcuts to navigate through your work. Your session ends when you type your designated terminating string on a line by itself. You know you're in a heredoc loop by the unique prompt (usually the **>** character).
|
||||
|
||||
|
||||
```
|
||||
$ cat << EOF >> example.txt
|
||||
> Everything you type here will be placed into example.txt when I type EOF on a line by itself. Until then, you can type...
|
||||
>
|
||||
> whatever...
|
||||
>
|
||||
> you want to type.
|
||||
>
|
||||
> EOF
|
||||
$
|
||||
```
|
||||
|
||||
Everything you enter while your terminal is waiting for **EOF** is placed into the destination file. Prompt characters are omitted, and EOF itself is not part of the file.
|
||||
|
||||
|
||||
```
|
||||
Everything you type here will be placed into example.txt when I type EOF on a line by itself. Until then, you can type...
|
||||
|
||||
whatever...
|
||||
|
||||
you want to type.
|
||||
```
|
||||
|
||||
Realistically, you’re probably not going to use heredoc syntax as a substitute for a good text editor. It's a great quick hack to enter more than one line, but more than 10 lines or so starts to strain its usefulness. For instance, you can’t go up to edit previous lines without triggering your shell’s [history][5] function. Depending on your shell and how it's configured, you may be able to go up, then down to recall your text, and then move back through your text with **Ctrl+B**.
|
||||
|
||||
Most features of your shell work as expected, but there’s probably no undo and very little error recovery.
|
||||
|
||||
And besides, even the most minimal of installs are likely to have at least [Vi][6] or [ed][7] installed.
|
||||
|
||||
And yet heredoc is still useful! It's more flexible than **echo**, and when you’re working on a shell script, it's indispensable. For instance, imagine you’re writing an installer script so you can automate the install of a set of custom applications. One of the applications isn’t distributed with a `.dekstop` file, so it does not appear in your Application menu. To fix this, you decide to generate a `.desktop` file at install time.
|
||||
|
||||
Rather than writing a `.desktop` file and carrying it around as an external dependency for your install script, you could use heredoc in your install script itself:
|
||||
|
||||
|
||||
```
|
||||
#!/bin/sh
|
||||
|
||||
VERSION=${VERSION:-x.y.z}
|
||||
PKGNAM=${VERSION:-example}
|
||||
PKG="${PKGNAM}"-"${VERSION}"-`arch`.tgz
|
||||
|
||||
# download package
|
||||
wget "${PKG}"
|
||||
tar txvf "${PKG}"
|
||||
|
||||
# use here doc to create missing .desktop file
|
||||
cat << EOF >> $HOME/.local/share/applications/example.desktop
|
||||
[Desktop Entry]
|
||||
Version=1.0
|
||||
Type=Application
|
||||
Name="${PKGNAM}"
|
||||
Comment="${PKGNAM}"
|
||||
Exec="${PKGNAM}" %F
|
||||
EOF
|
||||
|
||||
# insert the rest of an install script...
|
||||
```
|
||||
|
||||
You have automated text entry into a file, no text editor involved (except the one you use to write your script, obviously). Here’s what the resulting `.desktop` file looks like:
|
||||
|
||||
|
||||
```
|
||||
[Desktop Entry]
|
||||
Version=1.0
|
||||
Type=Application
|
||||
Name=example
|
||||
Comment=example
|
||||
Exec=example %F
|
||||
```
|
||||
|
||||
As you can see, you can use variables within the heredoc, and they’re correctly resolved. The `EOF` string doesn’t appear in the file; it only signals the end of the heredoc.
|
||||
|
||||
### Better than echo
|
||||
|
||||
The heredoc technique is generally considered easier than `echo` or [printf][8] because once you’re "in" the document, you’re free to do whatever you want. It’s liberating in that sense, but it’s limited compared to a proper text editor.
|
||||
|
||||
Use heredoc for quick notes and for shell scripts, and never puzzle over how to dynamically generate configuration files again.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/20/12/heredoc
|
||||
|
||||
作者:[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/lenovo-thinkpad-laptop-window-focus.png?itok=g0xPm2kD (young woman working on a laptop)
|
||||
[2]: https://opensource.com/article/19/2/getting-started-cat-command
|
||||
[3]: https://opensource.com/article/20/4/bash-sysadmins-ebook
|
||||
[4]: https://opensource.com/article/20/8/tcsh
|
||||
[5]: https://opensource.com/article/20/6/bash-history-commands
|
||||
[6]: https://opensource.com/article/19/3/getting-started-vim
|
||||
[7]: https://opensource.com/article/20/12/gnu-ed
|
||||
[8]: https://opensource.com/article/20/8/printf
|
@ -0,0 +1,92 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (10 open source news headlines of 2020)
|
||||
[#]: via: (https://opensource.com/article/20/12/open-source-news)
|
||||
[#]: author: (Jason Blais https://opensource.com/users/jasonblais)
|
||||
|
||||
10 open source news headlines of 2020
|
||||
======
|
||||
Take a look back at the open source news that made headlines in 2020.
|
||||
![Digital creative of a browser on the internet][1]
|
||||
|
||||
Throughout this past year, we've shared [top open source news][2] to keep everyone updated on what's happening in the world of open source. In case you missed any of the headlines, catch up on 10 of the open source news events that grabbed our readers' attention in 2020.
|
||||
|
||||
### Conferences successfully move to the virtual world
|
||||
|
||||
When COVID-19 was declared a pandemic in March, in-person conferences and events around the world came to a halt. Although many were canceled or postponed, others moved to [virtual formats with massive early success][3], reports Correspondent Alan Formy-Duval in his May news roundup. More than 80,000 people attended [Red Hat Summit][4] 2020 online in April, and [GitHub Satellite][5] saw 40,000 tune in from 178 countries. These were some of the biggest virtual conferences anywhere in 2020.
|
||||
|
||||
### Open source in the battle against COVID-19
|
||||
|
||||
As the world focused on controlling the spread of COVID-19, it is no surprise that open source technologies were critical in the effort. Scott Nesbitt shares how open data was used to "[create tracking dashboards and apps, [design] ventilators, and [develop] protective gear][6]." COVID tools, datasets, and research findings were also shared openly on GitHub for others to use and collaborate on.
|
||||
|
||||
### Java celebrates its 25th anniversary
|
||||
|
||||
In February, Tim Hildred helped us celebrate the exciting news about [Java's 25th anniversary][7]. Java was initially designed for interactive televisions with applets embedded in HTML pages, and it has since become the primary programming language for many enterprise applications, especially in financial services. Congratulations to the beloved Java language on reaching the quarter-century mark!
|
||||
|
||||
### GNOME launches a new contributor program
|
||||
|
||||
The GNOME Foundation and Endless partnered to launch a new [Community Engagement Challenge][8]. The objective was to bring "beginners into open source and [encourage] ongoing participation in open source communities," writes Ben Cotton. Of the applications submitted by the July deadline, 20 projects were [selected to continue][9] to the challenge's second phase. Five were invited to participate in the third phase, with the winner to be announced in April 2021.
|
||||
|
||||
### CERN uses open source platform Ceph for storage
|
||||
|
||||
Ceph is an open source software-defined storage platform. It implements object storage on a single distributed computer cluster and powers several research centers' projects, including [CERN's particle physics research][10], Tim Hildred reports. This continues CERN's push, which [began in 2019][11], to use open source software.
|
||||
|
||||
### CNCF takes charge of Red Hat's Operator Framework
|
||||
|
||||
The Cloud Native Computing Foundation (CNCF) hosts various projects, including Kubernetes, to advance container technology, and it runs the world's largest open source developer conferences. In 2020, [CNCF took on Red Hat's Operator Framework][12], an open source toolkit for managing Kubernetes-native applications in an automated and scalable way. "The increasing number of projects and code in the stewardship of neutral foundations like the CNCF is a testament to the power of collaboration," writes Tim Hildred.
|
||||
|
||||
### Two German states roll out Element for their education system
|
||||
|
||||
Correspondent Lauren Maffeo writes that the German states of Schleswig-Holstein and Hamburg [deployed Element][13], an open source messaging platform, to their education system with 500,000 users. It was an exciting leap for open source in the collaboration software market, which has been led by closed source applications like Slack, Zoom, and Microsoft Teams. Several open source collaboration projects, including [Element][14], [Mattermost][15], and [Jitsi][16], took big strides during the COVID-19 pandemic.
|
||||
|
||||
### Strapi announces general availability
|
||||
|
||||
Strapi, an open source, headless CMS for building powerful APIs, [announced general availability][17] five years after its first commit, hundreds of contributors participating, and more than a million downloads, shares Jeff Macharyas. Used by organizations from small businesses to Global 500 companies, Strapi is a testament to the staying power of open source projects backed by a community of users and contributors.
|
||||
|
||||
### Wireguard merged into the Linux Kernel
|
||||
|
||||
Wireguard, the open source communication protocol for virtual private networks (VPNs), was [merged into the Linux Kernel codebase][18] in January, says Correspondent Don Watkins. While the full effects are yet to be seen, this move has the potential to change the landscape of VPNs powered by open source.
|
||||
|
||||
### Mozilla Foundation creates a new subsidiary to host Thunderbird
|
||||
|
||||
Scott Nesbitt reports on a new Mozilla Foundation subsidiary, MZLA Technologies, which will be "the [new home of the Thunderbird project][19]." MZLA Technologies will help Mozilla offer products and services that would not be possible otherwise. Time will tell if Mozilla transfers other products to the new subsidiary.
|
||||
|
||||
### Top headlines in 2021?
|
||||
|
||||
What news do you anticipate open source software will make in 2021? Which companies, projects, or communities will we hear from the most? Let us know in the comments.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/20/12/open-source-news
|
||||
|
||||
作者:[Jason Blais][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/jasonblais
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/browser_web_internet_website.png?itok=g5B_Bw62 (Digital creative of a browser on the internet)
|
||||
[2]: https://opensource.com/tags/news
|
||||
[3]: https://opensource.com/article/20/5/news-may-9
|
||||
[4]: https://www.redhat.com/en/summit/about
|
||||
[5]: https://githubsatellite.com/
|
||||
[6]: https://opensource.com/article/20/3/news-march-28
|
||||
[7]: https://opensource.com/article/20/2/linux-java-and-other-industry-news
|
||||
[8]: https://opensource.com/article/20/4/news-april-11
|
||||
[9]: https://www.gnome.org/challenge/winners/
|
||||
[10]: https://opensource.com/article/20/2/linux-desktop-cern-more-industry-trends
|
||||
[11]: https://www.zdnet.com/article/cern-leaves-microsoft-programs-behind-for-open-source-software/
|
||||
[12]: https://opensource.com/article/20/8/standardizing-kube-and-more-industry-trends
|
||||
[13]: https://opensource.com/article/20/8/news-aug-8
|
||||
[14]: https://element.io/
|
||||
[15]: https://mattermost.com/
|
||||
[16]: http://jitsi.org/
|
||||
[17]: https://opensource.com/article/20/6/news-june-8
|
||||
[18]: https://opensource.com/article/20/2/new-feb-15
|
||||
[19]: https://opensource.com/article/20/2/news-february-1
|
@ -0,0 +1,112 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Try GNU nano, a lightweight alternative to Vim)
|
||||
[#]: via: (https://opensource.com/article/20/12/gnu-nano)
|
||||
[#]: author: (Seth Kenlon https://opensource.com/users/seth)
|
||||
|
||||
Try GNU nano, a lightweight alternative to Vim
|
||||
======
|
||||
Lightweight and straightforward, nano delivers a simple, intuitive
|
||||
editor with no extra fuss.
|
||||
![A pink typewriter][1]
|
||||
|
||||
Many Linux distributions bundle [Vim][2] as their default text editor. This appeals to many longtime Linux users, and those who don’t like it can change it promptly after install anyway. Vim is a funny editor, though, as it’s one of the few that opens to a mode that doesn’t permit text entry. That’s a puzzling choice for any user, and it’s confusing for a new one.
|
||||
|
||||
Thanks to GNU nano, there’s a common alternative to Vim for a lightweight terminal-based text editor, and it’s so easy to use—it has its most important commands listed at the bottom of its window.
|
||||
|
||||
![Black nano terminal with white text][3]
|
||||
|
||||
### Installing
|
||||
|
||||
On Linux and macOS, you probably already have GNU nano installed. You can verify with the `which` command:
|
||||
|
||||
|
||||
```
|
||||
$ which nano
|
||||
/bin/nano
|
||||
```
|
||||
|
||||
If you don’t have it installed, you can install it from your software repository, or you can [download its source code and compile it][4] yourself.
|
||||
|
||||
On Windows, you can [install GNU nano][5] using [Chocolatey][6].
|
||||
|
||||
### Launching nano
|
||||
|
||||
Launch nano from the terminal, either alone:
|
||||
|
||||
|
||||
```
|
||||
`$ nano`
|
||||
```
|
||||
|
||||
Or you can also open a specific file by following your command with a path to a file. If the file you name doesn’t already exist, it’s created:
|
||||
|
||||
|
||||
```
|
||||
`$ nano example.txt`
|
||||
```
|
||||
|
||||
### Using nano
|
||||
|
||||
Nano is, with just a little reading, pretty self-explanatory. When you launch it, nano opens to either an empty buffer or the file you opened. At the bottom of the screen, there’s a list of functions and their corresponding keyboard shortcuts. More functions are available by pressing **Ctrl+G** for Get Help.
|
||||
|
||||
Here are the most important application commands:
|
||||
|
||||
* **Ctrl+S** saves your work
|
||||
* **Ctrl+W** save as
|
||||
* **Ctrl+R** loads a file ("Read")
|
||||
* **Ctrl+X** quits, or exits
|
||||
* **Ctrl+G** get help
|
||||
|
||||
|
||||
|
||||
Here are the most common editing commands:
|
||||
|
||||
* **Alt+A** select ("mark") a region
|
||||
* **Ctrl+K** cut marked text
|
||||
* **Ctrl+U** paste ("uncut")
|
||||
* **Alt+F** undo
|
||||
* **Alt+E** redo
|
||||
|
||||
|
||||
|
||||
### Customizable
|
||||
|
||||
Nano isn’t as extensible as Emacs or Vim, but you can make some significant customizations in a file called `~/.nanorc`. In this file, you can set global preferences, including word wrap settings, color schemes, line numbering, and more. You can also create your own key bindings, so if you want to use **Ctrl+V** to paste instead of nano’s default **Ctrl+U**, you can change the binding assigned to the **paste** function:
|
||||
|
||||
|
||||
```
|
||||
`bind ^V paste all`
|
||||
```
|
||||
|
||||
You can get a list of all available functions in the [GNU nano documentation][7].
|
||||
|
||||
### Simple and effective
|
||||
|
||||
GNU nano is a no-nonsense, straightforward text editor. It’s easy to use and provides all the functionality you expect from a text editor. Try it out, and enjoy the simplicity of intuitive editing.
|
||||
|
||||
Vim offers great benefits to writers, regardless of whether they are technically minded or not.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/20/12/gnu-nano
|
||||
|
||||
作者:[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/osdc-docdish-typewriter-pink.png?itok=OXJBtyYf (A pink typewriter)
|
||||
[2]: https://opensource.com/article/20/12/vi-text-editor
|
||||
[3]: https://opensource.com/sites/default/files/uploads/nano-31_days-nano-opensource.png (Black nano terminal with white text)
|
||||
[4]: http://nano-editor.org
|
||||
[5]: https://opensource.com/article/20/12/%C2%A0https://chocolatey.org/packages/nano
|
||||
[6]: https://opensource.com/article/20/3/chocolatey
|
||||
[7]: https://www.nano-editor.org/dist/latest/nanorc.5.html
|
@ -1,88 +0,0 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (mengxinayan)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (How to influence people to join open source)
|
||||
[#]: via: (https://opensource.com/article/20/10/influence-open-source)
|
||||
[#]: author: (Joshua Pearce https://opensource.com/users/jmpearce)
|
||||
|
||||
如何感召人们让其参与到开源活动中
|
||||
======
|
||||
向他人介绍开源最有效的办法是介绍开源可以提供他们想要的。
|
||||
![建筑物中的管道][1]
|
||||
|
||||
如果你在浏览 opensource.com,也许你会编程,同时或许你正使用某些小众的[Linux 发行版][2]的开源浏览器上阅读这些内容。你也许很多年没有看到过浏览器广告了,因为你正运行着一个[开源的广告拦截器][3]。当你想到企鹅时,你感到温暖而又陌生。
|
||||
|
||||
简单地说,你知道开源的力量并且它已经成了你生活的一部分。不幸的是,并不是每个人都发现如何利用开源。他们的电脑相当地慢,当他们上网浏览时他们看到的广告比内容都多,他们把他们的钱花在拥有专利和版权的垃圾上。这些人中可能有些是与你有关系的,例如你的侄女和侄子。
|
||||
|
||||
### 知识就是财富
|
||||
|
||||
那么你如何向你的侄女和侄子(以及任意一个人)介绍开源?
|
||||
|
||||
我尝试回答这个问题并且成了一个长期从事此事业而闻名的教授,直到我发现了由 McGraw-Hill 出版的[《使用开源项目创造、分享和省钱》][4]这一本书。
|
||||
|
||||
我认为诀窍在于先发现你的侄女或侄子想要获取但没有钱去购买的东西,然后向他们展示如何通过开源知识来得到他们想要的东西。
|
||||
|
||||
![可升降的桌子][5]
|
||||
|
||||
[可升降的桌子][6] (Joni Steiner and Nick Ierodiaconou, [CC-BY-SA-NC][7])
|
||||
|
||||
知识是所有商品里独特的财富。不像黄金或小麦,它不仅在共享时会保留价值,而且它会迅速增加价值。因为互联网信息分享成本趋近于0,因此无限地扩展了此过程。每个可以访问互联网的人都从未拥有过这一财富。例如,我提供[免费的仓库链接][4]关于书籍、教育、电影、如何去做、地图、音乐、照片、艺术品、软件和烹饪等内容。
|
||||
|
||||
### 不要买,而是去制作它
|
||||
|
||||
免费和开源逐渐扩展到现实世界,我们现在有机会通过沃尔玛或亚马逊来购买[玩具][8]、[电器][9]、[家居用品][10]和衣服来极大地减少开销。使用3D打印或类似的工具,组合了开源分享和数字制造,使得每个人可以制造属于他们自己的、复杂的、有用的工具。
|
||||
|
||||
![3D 打印的家居用品][11]
|
||||
|
||||
[3D 打印的家居用品][12] (Joshua M. Pearce, [CC BY-SA 3.0][13])
|
||||
|
||||
近些年来,科学家[在他们的实验室][14]中已经在做这些工作。但是现在,任何人都可以轻松地自定义满足他们具体需求的产品。已经有数百万的免费设计可供使用。
|
||||
|
||||
![Recyclebot][15]
|
||||
|
||||
[Recyclebot][16] (Joshua M. Pearce, [GPLv3][17])
|
||||
|
||||
真正降低一个产品的价格是[通过垃圾来获取其原材料][18]。伴随着小规模的回收利用过程(例如我实验室正在使用的 [Recyclebots][19])最近得到了改进,这使得人们可以从废物中制造有用的产品,因此产生了一系列让人眼花缭乱的产品。最重要的是,任何人都可以利用专用系统中的一小部分成本来获取到绿色、自定义化的产品。我们生产出相比常规商品具有[更低的销售税][20]的定制化产品——它们具有相同的功能,更好的定制化功能以及几乎没有成本。
|
||||
|
||||
### 了解更多
|
||||
|
||||
在[使用开源项目创建、分享和省钱的项目][4]中,我分享了在家具制造和循环利用的潜力,以及如何利用开源来为大宗商品评分,如房屋、电力。您可以在我和Megan Krieger以及Janet Callahan三人在密歇根理工学院的 [Husky Bites][21] 中的网络研讨会上了解更多。
|
||||
|
||||
希望这些知识能足够激发侄女或侄子或侄女侄子找到进入开源的方式!
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/20/10/influence-open-source
|
||||
|
||||
作者:[Joshua Pearce][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[萌新阿岩](https://github.com/mengxinayan)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/jmpearce
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/open_pipe_red_hat_tower_building.png?itok=8ho3yi7L (pipe in a building)
|
||||
[2]: https://distrowatch.com/
|
||||
[3]: https://opensource.com/article/20/4/ad-blockers
|
||||
[4]: https://www.appropedia.org/Create,_Share,_and_Save_Money_Using_Open-Source_Projects
|
||||
[5]: https://opensource.com/sites/default/files/uploads/opendesk_furniture_lift-standing-desk.jpg (Lift Standing Desk)
|
||||
[6]: https://www.appropedia.org/File:Opendesk_furniture_lift-standing-desk.jpg
|
||||
[7]: https://creativecommons.org/licenses/by-nc-sa/2.0/
|
||||
[8]: http://www.mdpi.com/2227-7080/5/3/45
|
||||
[9]: https://doi.org/10.3390/inventions3030064
|
||||
[10]: https://www.mdpi.com/2227-7080/5/1/7
|
||||
[11]: https://opensource.com/sites/default/files/uploads/3dprinted_household.jpg (3D printed household items)
|
||||
[12]: https://www.appropedia.org/File:3dprinted_household.JPG
|
||||
[13]: https://creativecommons.org/licenses/by-sa/3.0/
|
||||
[14]: https://opensource.com/article/20/10/open-source-hardware-savings
|
||||
[15]: https://opensource.com/sites/default/files/uploads/recyclebotrep.png (Recyclebot)
|
||||
[16]: https://www.appropedia.org/File:Recyclebotrep.png
|
||||
[17]: https://www.gnu.org/licenses/gpl-3.0.html
|
||||
[18]: https://www.academia.edu/34738483/Tightening_the_Loop_on_the_Circular_Economy_Coupled_Distributed_Recycling_and_Manufacturing_with_Recyclebot_and_RepRap_3-D_Printing
|
||||
[19]: https://www.appropedia.org/Recyclebot
|
||||
[20]: https://opensource.com/article/17/3/how-to-create-consumer-goods-open-hardware
|
||||
[21]: https://www.facebook.com/Michigan-Tech-College-of-Engineering-109353424030003/videos/husky-bites-presents-special-guest-joshua-m-pearce/2669023713361207/
|
@ -0,0 +1,116 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ()
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (How the Linux kernel handles interrupts)
|
||||
[#]: via: (https://opensource.com/article/20/10/linux-kernel-interrupts)
|
||||
[#]: author: (Stephan Avenwedde https://opensource.com/users/hansic99)
|
||||
|
||||
Linux 内核如何处理中断
|
||||
======
|
||||
|
||||
中断是计算机处理数据的关键部分。
|
||||
|
||||
![企鹅驾驶着黄色背景的汽车][1]
|
||||
|
||||
中断是现代CPU工作中必不可少的一部分。例如:当你每次在键盘上按下一个按键后,CPU会被中断以使得PC读取用户键盘的输入。这个过程发生得相当快以致于在使用体验上你不会感到任何变化或损害。
|
||||
|
||||
此外,键盘并不是导致中断的唯一元素。一般来说,有三种类型的事件会导致CPU发生中断:硬件中断、软件中断和异常。再具体介绍不同类型的中断前,我需要先定义一些术语。
|
||||
|
||||
### 定义
|
||||
|
||||
一个中断请求(**IRQ**)是被可编程的中断控制器(**PIC**)发起,其目的是为了中断CPU和执行中断服务程序(**ISR**)。中断服务程序(ISR)是一个小的程序来处理具体的数据,其具体的处理方式依赖于造成中断请求(IRQ)的原因。之前正在运行的进程在中断服务程序(ISR)运行结束前都会被中断。
|
||||
|
||||
在过去,中断请求由单独的芯片处理(中断控制器芯片),I/O 设备与中断控制器(PIC)直接相连。中断控制器(PIC)管理着多种硬件的中断请求并且可以直接与CPU通信。当一个中断请求(IRQ)产生后,中断控制器向CPU写入数据并且触发中断请求(**INTR**)引脚。
|
||||
|
||||
现如今,中断请求(IRQ)由CPU中的高级可编程中断控制器(APIC)部分来处理。每个核中都拥有属于自己的高级可编程中断控制器。
|
||||
|
||||
### 中断的类型
|
||||
|
||||
正如我前文中提到的,中断可以根据其来源分为三种类型。
|
||||
|
||||
#### 硬件中断
|
||||
|
||||
当一个硬件设备想要告诉CPU某一需要处理的数据已经准备好后(例如:当键盘被按下或者一个数据包到了网络接口处),它将会发送一个中断请求(IRQ)来告诉CPU数据是可用的。接下来会调用在内核启动时设备驱动注册的对应的中断服务程序(ISR)。
|
||||
|
||||
#### 软件中断
|
||||
|
||||
当你在播放一个视频时,音频和视频是同步播放是相当重要的,因此音频的播放速度不应该发生变化。这是由软件中断实现的,由精确的计时器系统(称为 [jiffies][2])重复发起的。这个计时器会使得你的音乐播放器同步。软件中断也可以被特殊的指令所调用来读取或写入数据到硬件设备。
|
||||
|
||||
当系统需要实时性时(例如在工业应用中),软件中断会变得重要。你可以在Linux基金会的文章中找到更多相关信息:[面向嵌入式开发者的实时Linux介绍][3]。
|
||||
|
||||
#### 异常
|
||||
|
||||
异常是你可能之前知道的中断类型。当CPU执行一些将会导致除以0或缺页错误的指令时,任何其他运行中的程序都会被中断。在这种情况下,你会被一个弹窗提醒,或在控制台输出中看到**段错误(核心已转存)**。但并不是所有异常都是由指令错误引起的。
|
||||
|
||||
异常可以进一步分为 _错误_、_陷阱_ 和 _中止_ ?
|
||||
|
||||
Exceptions can be further divided into _Faults_, _Traps_, and _Aborts_.
|
||||
|
||||
* **错误:** 错误是系统可以纠正的异常。例如当一个进程尝试访问某个已经被换出到硬盘的页时。当请求的地址在进程的地址空间中,并且满足访问权限时,如果页不在内存(RAM)中,将会产生一个中断请求(IRQ),并开始启用**缺页异常处理程序**把所需的页加载到内存中。如果操作成功执行,程序将继续运行。
|
||||
|
||||
* **陷阱:** 陷阱主要用在调试中。如果你在某个程序中设置了一个断点,你就插入了一条可以触发陷阱执行的指令。一个陷阱可以触发上下文切换来允许你的调试器读取和展示局部变量的值。之后程序可以继续运行。陷阱同样也是运行系统调用的方式(如杀死一个进程)
|
||||
|
||||
* **中止:** 中止是由系统表中的硬件错误或值不一致而导致的。一个中止不会报告造成异常的指令的所在位置。这是最严重的中断,一个中止将会调用系统的**中止异常处理程序**来结束造成异常的进程。
|
||||
|
||||
### 动手实践
|
||||
|
||||
中断请求按照高级可编程中断控制器(APIC)中的优先级高低排序(0是最高优先级)。前32个中断(0~31)是由CPU指定的固定序列。你可以在 [OsDev 异常][4] 页面找到关于它们的概述。接下来的中断请求可以不同的分配。中断描述表(**IDT**)中记录了中断请求(IRQ)和中断服务程序(ISR)的对应关系。Linux 中定义了从 0 到 256 的 IRQ 向量。
|
||||
|
||||
为了打印出在你的系统中已注册的中断,打开一个终端并输入:
|
||||
|
||||
```
|
||||
`cat /proc/interrupts`
|
||||
```
|
||||
|
||||
你应该会看到类似如下图的结果:
|
||||
|
||||
![注册的中断列表][5]
|
||||
|
||||
内核版本为5.6.6中注册的中断 (Stephan Avenwedde, [CC BY-SA 4.0][6])
|
||||
|
||||
从左到右各列的含义依次为:中断向量号、每个CPU(0~n)中断发生次数、硬件来源、硬件源通道信息、以及造成中断请求的设备名。
|
||||
|
||||
在表的末尾,有一些非数字的中断。它们是特定于体系结构的中断,如本地计时器中断(**LOC**)的中断请求(IRQ)号为236。其中一些在 Linux 内核源树中的[Linux IRQ 向量布局][7]中指定。
|
||||
|
||||
![特定于体系结构的中断][8]
|
||||
|
||||
特定于体系结构的中断 (Stephan Avenwedde, [CC BY-SA 4.0][6])
|
||||
|
||||
|
||||
如果要实时获取该表,请运行如下命令:
|
||||
|
||||
```
|
||||
`watch -n1 "cat /proc/interrupts"`
|
||||
```
|
||||
|
||||
### 总结
|
||||
|
||||
正确的中断请求(IRQ)处理对于硬件、驱动和软件的正常交互是必要的。幸运地是,Linux 内核很好地完成了它,一个PC的普通用户很难注意到内核整个中断处理的过程。
|
||||
|
||||
中断相当复杂,本文仅仅是一个关于中断的概述。如果想要深入了解该主题可以阅读 [Linux 内部电子书][9](CC BY-NC-SA 4.0)和 [Linux 内核教程][10] 仓库。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/20/10/linux-kernel-interrupts
|
||||
|
||||
作者:[Stephan Avenwedde][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[萌新阿岩](https://github.com/mengxinayan)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/hansic99
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/car-penguin-drive-linux-yellow.png?itok=twWGlYAc (Penguin driving a car with a yellow background)
|
||||
[2]: https://elinux.org/Kernel_Timer_Systems
|
||||
[3]: https://www.linuxfoundation.org/blog/2013/03/intro-to-real-time-linux-for-embedded-developers/
|
||||
[4]: https://wiki.osdev.org/Exceptions
|
||||
[5]: https://opensource.com/sites/default/files/uploads/proc_interrupts_1.png (Registered interrupts list)
|
||||
[6]: https://creativecommons.org/licenses/by-sa/4.0/
|
||||
[7]: https://github.com/torvalds/linux/blob/master/arch/x86/include/asm/irq_vectors.h
|
||||
[8]: https://opensource.com/sites/default/files/uploads/proc_interrupts_2.png (Architecture-specific interrupts)
|
||||
[9]: https://0xax.gitbooks.io/linux-insides/content/Interrupts/
|
||||
[10]: https://linux-kernel-labs.github.io/refs/heads/master/lectures/interrupts.html#
|
@ -1,191 +0,0 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (zhangxiangping)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (An attempt at implementing char-rnn with PyTorch)
|
||||
[#]: via: (https://jvns.ca/blog/2020/11/30/implement-char-rnn-in-pytorch/)
|
||||
[#]: author: (Julia Evans https://jvns.ca/)
|
||||
|
||||
用PyTorch实现char-rnn
|
||||
======
|
||||
|
||||
你好!在过去的几周里,我花了很多时间用PyTorch实现了一个[char-rnn][1]的版本。我以前从未训练过神经网络,所以这可能是一个有趣的开始。
|
||||
|
||||
这个想法(来自[The Unreasonable Effectiveness of Recurrent Neural Networks][1])可以让你在文本上训练一个基于字符的循环神经网络,并得到一些出乎意料的结果。
|
||||
|
||||
不过,虽然没有得到我想要的结果,但是我还是想分享一些示例代码和结果,希望对其他开始尝试使用PyTorch和RNNs的人有帮助。
|
||||
|
||||
这是Jupyter notebook格式的代码:[char-rnn in PyTorch.ipynb][2]。你可以点击这个网页最上面那个按钮Open in Colab,就可以在Google的Colab服务中打开,并使用免费的GPU进行训练。所有的东西加起来大概有75行代码,我将在这篇博文中尽可能地详细解释。
|
||||
|
||||
### 第一步:准备数据
|
||||
|
||||
首先,我们要下载数据。我使用的是古登堡项目中的这个数据:[Hans Christian Anderson’s fairy tales][3]。
|
||||
|
||||
```
|
||||
!wget -O fairy-tales.txt
|
||||
```
|
||||
|
||||
这个是准备数据的代码。我使用fastai库中的Vocab类进行数据处理,它能将一堆字母转换成“词表”,然后用这个“词表”把字母变成数字。
|
||||
|
||||
之后我们就得到了一大串数字(`训练集`),我们可以在这上面训练我们的模型。
|
||||
|
||||
```
|
||||
from fastai.text import *
|
||||
text = unidecode.unidecode(open('fairy-tales.txt').read())
|
||||
v = Vocab.create((x for x in text), max_vocab=400, min_freq=1)
|
||||
training_set = torch.Tensor(v.numericalize([x for x in text])).type(torch.LongTensor).cuda()
|
||||
num_letters = len(v.itos)
|
||||
```
|
||||
|
||||
### 第二步:定义模型
|
||||
|
||||
这个是Pytorch中LSTM类的封装。除了封装LSTM类以外,它还做了三件事:
|
||||
|
||||
1. 对输入向量进行one-hot编码,使得他们具有正确的维度。
|
||||
2. 在LSTM层后一层添加一个线性变换,因为LSTM输出的是一个长度为`hidden_size`的向量,我们需要的是一个长度为`input_size`的向量这样才能把它变成一个字符。
|
||||
3. 把LSTM隐藏层的输出向量(实际上有2个向量)保存成实例变量,然后在每轮运行结束后执行`.detach()`函数。(我很难解释清`.detach()`的作用,但我的理解是,它在某种程度上“结束”了模型的求导计算(译者注:detach()函数是将该张量的requires_grad参数设置为False,即反向传播到该张量就结束。))
|
||||
|
||||
```
|
||||
class MyLSTM(nn.Module):
|
||||
def __init__(self, input_size, hidden_size):
|
||||
super().__init__()
|
||||
self.lstm = nn.LSTM(input_size, hidden_size, batch_first=True)
|
||||
self.h2o = nn.Linear(hidden_size, input_size)
|
||||
self.input_size=input_size
|
||||
self.hidden = None
|
||||
|
||||
def forward(self, input):
|
||||
input = torch.nn.functional.one_hot(input, num_classes=self.input_size).type(torch.FloatTensor).cuda().unsqueeze(0)
|
||||
if self.hidden is None:
|
||||
l_output, self.hidden = self.lstm(input)
|
||||
else:
|
||||
l_output, self.hidden = self.lstm(input, self.hidden)
|
||||
self.hidden = (self.hidden[0].detach(), self.hidden[1].detach())
|
||||
|
||||
return self.h2o(l_output)
|
||||
```
|
||||
|
||||
这个代码还做了一些比较神奇但是不太明显的功能。如果你的输入是一个向量(比如[1,2,3,4,5,6]),对应六个字母,那么我的理解是`nn.LSTM`会在内部使用沿时间反向传播[backpropagation through time][4]更新隐藏向量6次。
|
||||
|
||||
### 第三步:编写训练代码
|
||||
|
||||
模型不会自己训练自己的!
|
||||
|
||||
我最开始的时候尝试用`fastai`库中的一个helper类(也是PyTorch中的封装)。我有点疑惑因为我不知道它在做什么,所以最后我自己编写了模型训练代码。
|
||||
|
||||
下面这些代码(epoch()方法)就是有关于一轮训练过程的基本信息。基本上就是重复做下面这几件事情:
|
||||
1. 往RNN模型中传入一个字符串,比如`and they ought not to teas`。(要以数字向量的形式传入)
|
||||
2. 得到下一个字母的预测结果。
|
||||
3. 计算RNN模型预测结果和真实的下一个字母之间的损失函数。(`e`,因为tease是以`e`结尾的)
|
||||
4. 计算梯度。(用`loss.backward()`函数)
|
||||
5. 沿着梯度下降的方向修改模型中参数的权重。(用`self.optimizer.step()`函数)
|
||||
|
||||
```
|
||||
class Trainer():
|
||||
def __init__(self):
|
||||
self.rnn = MyLSTM(input_size, hidden_size).cuda()
|
||||
self.optimizer = torch.optim.Adam(self.rnn.parameters(), amsgrad=True, lr=lr)
|
||||
def epoch(self):
|
||||
i = 0
|
||||
while i < len(training_set) - 40:
|
||||
seq_len = random.randint(10, 40)
|
||||
input, target = training_set[i:i+seq_len],training_set[i+1:i+1+seq_len]
|
||||
i += seq_len
|
||||
# forward pass
|
||||
output = self.rnn(input)
|
||||
loss = F.cross_entropy(output.squeeze()[-1:], target[-1:])
|
||||
# compute gradients and take optimizer step
|
||||
self.optimizer.zero_grad()
|
||||
loss.backward()
|
||||
self.optimizer.step()
|
||||
```
|
||||
|
||||
### 使用`nn.LSTM`沿着时间反向传播,不要自己写代码。
|
||||
|
||||
开始的时候我自己写的代码,每次传一个字母到LSTM层中,之后定期计算导数,就像下面这样:
|
||||
|
||||
```
|
||||
for i in range(20):
|
||||
input, target = next(iter)
|
||||
output, hidden = self.lstm(input, hidden)
|
||||
loss = F.cross_entropy(output, target)
|
||||
hidden = hidden.detach()
|
||||
self.optimizer.zero_grad()
|
||||
loss.backward()
|
||||
self.optimizer.step()
|
||||
```
|
||||
|
||||
这段代码每次传入一个字母,并且在最后训练了一次。这个步骤就被称为沿时间反向传播[backpropagation through time][4],Karpathy在他的博客中就是用这种方法。
|
||||
|
||||
这个方法有些用处,我编写的损失函数开始能够下降一段时间,但之后就会出现峰值。我不知道为什么会出现这种现象,但之后我改为一次传入20个字符之后,再进行反向传播,情况就变好了。
|
||||
|
||||
### 第四步:训练模型!
|
||||
|
||||
我在同样的数据上重复执行了这个训练代码大概300次,直到模型开始输出一些看起来像英文的文本。差不多花了一个多小时吧。
|
||||
|
||||
这种情况下我也不关注模型是不是过拟合了,但是如果你在真实场景中训练模型,应该要在验证集上验证你的模型。
|
||||
|
||||
### 第五步:生成输出!
|
||||
|
||||
最后一件要做的事就是用这个模型生成一些输出。我写了一个helper方法从这个训练好的模型中生成文本(`make_preds`和`next_pred`)。这里主要是把向量的维度对齐,重要的一点是:
|
||||
|
||||
```
|
||||
output = rnn(input)
|
||||
prediction_vector = F.softmax(output/temperature)
|
||||
letter = v.textify(torch.multinomial(prediction_vector, 1).flatten(), sep='').replace('_', ' ')
|
||||
```
|
||||
|
||||
基本上做的事情就是这些:
|
||||
1. RNN层为字母表中的每一个字母或者符号输出一个数值向量(`output`)。
|
||||
2. 这个输出向量**并不是**一个概率的向量,所以需要`F.softmax(output/temperature)`操作,将其转换为概率值(也就是所有数值加起来和为1)。`temperature`某种程度上控制了对更高概率的权重,在限制范围内,如果设置temperature=0.0000001,它将始终选择概率最高的字母。
|
||||
3. `torch.multinomial(prediction_vector)`用于获取概率向量,并使用这些概率在向量中选择一个索引(如12)。
|
||||
4. `v.textify`把“12”转换为字母。
|
||||
|
||||
如果我们想要处理的文本长度为300,那么只需要重复这个过程300次就可以了。
|
||||
If we want 300 characters worth of text, we just repeat this process 300 times.
|
||||
|
||||
### 结果!
|
||||
|
||||
我把预测函数中的参数设置为`temperature = 1`得到了下面的这些由模型生成的结果。看起来有点像英语,这个结果已经很不错了,因为这个模型要从头开始“学习”英语,并且是在字符序列的级别上进行学习的。
|
||||
|
||||
虽然这些话没有什么_含义_,但我们也不知道到底想要得到什么输出。
|
||||
|
||||
> “An who was you colotal said that have to have been a little crimantable and beamed home the beetle. “I shall be in the head of the green for the sound of the wood. The pastor. “I child hand through the emperor’s sorthes, where the mother was a great deal down the conscious, which are all the gleam of the wood they saw the last great of the emperor’s forments, the house of a large gone there was nothing of the wonded the sound of which she saw in the converse of the beetle. “I shall know happy to him. This stories herself and the sound of the young mons feathery in the green safe.”
|
||||
>
|
||||
> “That was the pastor. The some and hand on the water sound of the beauty be and home to have been consider and tree and the face. The some to the froghesses and stringing to the sea, and the yellow was too intention, he was not a warm to the pastor. The pastor which are the faten to go and the world from the bell, why really the laborer’s back of most handsome that she was a caperven and the confectioned and thoughts were seated to have great made
|
||||
|
||||
下面这些结果是当`temperature=0.1`时生成的,它选择字符的方式更接近于“每次都选择出现概率最高的字符”。这就使得输出结果有很多是重复的。
|
||||
|
||||
> ole the sound of the beauty of the beetle. “She was a great emperor of the sea, and the sun was so warm to the confectioned the beetle. “I shall be so many for the beetle. “I shall be so many for the beetle. “I shall be so standen for the world, and the sun was so warm to the sea, and the sun was so warm to the sea, and the sound of the world from the bell, where the beetle was the sea, and the sound of the world from the bell, where the beetle was the sea, and the sound of the wood flowers and the sound of the wood, and the sound of the world from the bell, where the world from the wood, and the sound of the
|
||||
|
||||
这段输出对这几个单词beetles、confectioners、sun和sea有着奇怪的执念。
|
||||
|
||||
### 总结!
|
||||
|
||||
至此,我的结果远不及Karpathy的好,可能有一下几个原因:
|
||||
1. 没有足够多的训练数据。
|
||||
2. 训练了一个小时之后我就没有耐心去查看Colab notebook上的信息。
|
||||
3. Karpathy使用了两层LSTM,包含了更多的参数,而我只使用了一层。
|
||||
4. 完全是另一回事。
|
||||
|
||||
但我得到了一些大致说得过去的结果!还不错!
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://jvns.ca/blog/2020/11/30/implement-char-rnn-in-pytorch/
|
||||
|
||||
作者:[Julia Evans][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[zhangxiangping](https://github.com/zxp93)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://jvns.ca/
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://karpathy.github.io/2015/05/21/rnn-effectiveness/
|
||||
[2]: https://gist.github.com/jvns/b6dda36b2fdcc02b833ed5b0c7a09112
|
||||
[3]: https://www.gutenberg.org/cache/epub/27200/pg27200.txt
|
||||
[4]: https://en.wikipedia.org/wiki/Backpropagation_through_time
|
@ -0,0 +1,74 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (geekpi)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (How to use this KDE Plasma text editor)
|
||||
[#]: via: (https://opensource.com/article/20/12/kwrite-kde-plasma)
|
||||
[#]: author: (Seth Kenlon https://opensource.com/users/seth)
|
||||
|
||||
如何使用这个 KDE Plasma 文本编辑器?
|
||||
======
|
||||
作为流行的 KDE Plasma 桌面的一部分,KWrite 在一个简单易用的界面中隐藏了大量有用的功能。
|
||||
![Coding on a computer][1]
|
||||
|
||||
KWrite 是一款适用于 KDE Plasma 桌面的文本编辑器。它的目的是成为一个通用的应用,任何人都可以在他们需要快速做笔记、写一篇学校论文、做一些编程,和/或任何其他你能想到的文本编辑器能做的事时用上它。它使用 [Kate 编辑器][2]的组件来创建一个简单的界面,但它利用这些相同的组件来提供大量有用的功能。
|
||||
|
||||
### 安装
|
||||
|
||||
KWrite 不可用于所有环境,它是 [KDE Plasma 桌面][3]的一个组件,所以如果你正在运行 Plasma,那么你已经有了 KWrite。
|
||||
|
||||
如果你没有运行 Plasma,那么你可以安装 Plasma,这样你可以将它和 KWrite 一起开始使用,或者根据需要使用 KWrite。然而,它是作为 Plasma 桌面的默认文本编辑器,所以如果你真的想把它作为一个独立应用使用,那么安装 Kate 可能更容易。
|
||||
|
||||
### 使用 KWrite
|
||||
|
||||
当你启动 KWrite 时,你会看到期望的编辑器的样子:一大块用于输入的区域,顶部有一个菜单栏和工具栏,底部有一个状态栏。这就是你在开始之前需要了解的全部内容。KWrite 是一个直观的应用,工具栏按钮用于重要的活动,如打开和保存文件,简单的菜单系统用于更高级的编辑任务。
|
||||
|
||||
![Kwrite terminal containing dark gray html code on white background][4]
|
||||
|
||||
KWrite 的许多功能都是潜在的,不需要你自己去激活它们就会发生。例如,如果你打开一个用 HTML 编写的文件,那么 KWrite 会高亮显示关键字(如 `class` 和 `id`)和识别代码标签(如 `<p>` 或 `<div>`),并将它们与自然语言的单词区别对待。当你加载一个用 Python 编写的文件时,也会发生同样的情况,而对于主要用自然语言编写的文件,则不会发生任何事情。
|
||||
|
||||
当然,你不必只选择 HTML、Python 和你的母语。KWrite 支持很多语言和格式(对于很多语言和格式,它甚至有自动完成选项)。
|
||||
|
||||
对于那些想要不止那些自动加载功能的用户,在编辑、视图和工具菜单中都有一些选项。例如,你可以激活动态拼写检查、运行脚本、调出命令行、注释或取消注释一行、调整缩进、显示行号等等。
|
||||
|
||||
当从终端启动 KWrite 时,也有一些有趣的选项。例如,如果你知道要到文件中的哪一行,你可以用行号参数启动 KWrite:
|
||||
|
||||
|
||||
```
|
||||
`$ kwrite --line 101 example.txt`
|
||||
```
|
||||
|
||||
你也可以使用 `--stdin` (或简写 `-i`)选项方便地将命令的输出通过管道到 KWrite。例如,这个命令下载 [example.com][5] 的首页,并在一个新的 KWrite 窗口中显示 HTML:
|
||||
|
||||
|
||||
```
|
||||
`$ curl http://example.com | kwrite --stdin`
|
||||
```
|
||||
|
||||
### 尝试 KWrite
|
||||
|
||||
我一直觉得 KDE 的优势之一就是它的复杂性很灵活。如果你想要一个简单的桌面,你基本上可以选择忽略任何你不想要的功能。KWrite 就是这种灵活性也适用于开发人员的一个例子。由于 Kate 具有许多功能,所以开发者有可能重用这些功能的一个子集来创建一个更干净、更专注的应用版本。
|
||||
|
||||
KWrite 是一个单文档编辑器。它没有标签,也没有任何项目的意识。它的目的是为那些想一次只处理一个文档的人准备的,他们希望基本的功能在默认情况下是活跃的,在需要的时候可以选择强大的编辑工具。安装优秀的 Plasma 桌面,今天就来试试吧!
|
||||
|
||||
KDE 最初是 Kool Desktop Environment 的缩写,但现在很多人都认为是 K Desktop。。。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/20/12/kwrite-kde-plasma
|
||||
|
||||
作者:[Seth Kenlon][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[geekpi](https://github.com/geekpi)
|
||||
校对:[校对者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/code_computer_laptop_hack_work.png?itok=aSpcWkcl (Coding on a computer)
|
||||
[2]: https://opensource.com/article/20/12/kate-text-editor
|
||||
[3]: https://opensource.com/article/19/12/linux-kde-plasma
|
||||
[4]: https://opensource.com/sites/default/files/uploads/kwrite-31_days_kwrite-opensource.png (Kwrite terminal containing dark gray html code on white background)
|
||||
[5]: http://example.com
|
@ -0,0 +1,119 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (geekpi)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (4 cool new projects to try in COPR from December 2020)
|
||||
[#]: via: (https://fedoramagazine.org/4-cool-new-projects-to-try-in-copr-from-december/)
|
||||
[#]: author: (Jakub Kadlčík https://fedoramagazine.org/author/frostyx/)
|
||||
|
||||
COPR 仓库中 4 个很酷的新项目(2020.12)
|
||||
======
|
||||
|
||||
![][1]
|
||||
|
||||
COPR 是个人软件仓库[集合][2],它不在 Fedora 中。这是因为某些软件不符合轻松打包的标准;或者它可能不符合其他 Fedora 标准,尽管它是自由而开源的。COPR 可以在 Fedora 套件之外提供这些项目。COPR 中的软件不受 Fedora 基础设施的支持,或者是由项目自己背书的。但是,这是一种尝试新的或实验性的软件的一种巧妙的方式。
|
||||
|
||||
本文介绍了 COPR 中一些有趣的新项目。如果你第一次使用 COPR,请参阅 [COPR 用户文档][3]。
|
||||
|
||||
## [][4] Blanket
|
||||
|
||||
[Blanket][5] 是一款播放背景声音的应用,它可能会提高你的注意力,提高你的工作效率。另外,它还可以帮助你在嘈杂的环境中放松和入睡。无论现在是什么时间或你在哪里,Blanket 都可以让你在鸟鸣时醒来,在友好的咖啡店聊天或遥远的城市交通的包围下工作,然后在外面下雨时像木头一样睡在壁炉旁边。还有其他流行的背景音选择,如粉色和白色噪音也可以选择。
|
||||
|
||||
![][6]
|
||||
|
||||
### [][7] 安装说明
|
||||
|
||||
目前[仓库][8]为 Fedora 32 和 33 提供了 Blanket。要安装它,请使用以下命令:
|
||||
|
||||
```
|
||||
sudo dnf copr enable tuxino/blanket
|
||||
sudo dnf install blanket
|
||||
```
|
||||
|
||||
## [][9] k9s
|
||||
|
||||
[k9s][10] 是一个管理 Kubernetes 集群的命令行工具。它允许你列出正在运行的 pod 并与之交互,读取它们的日志,挖掘已使用的资源,并总体上使操作 Kubernetes 更轻松。凭借其通过插件和可定制的用户界面的可扩展性,_k9s_ 受到有经验用户的欢迎。
|
||||
|
||||
|
||||
![][11]
|
||||
|
||||
有关[更多预览截图][12],请参见[项目页面][10]。
|
||||
|
||||
### [][13] 安装说明
|
||||
|
||||
目前[仓库][14]为 Fedora 32、33、Fedora Rawhide 以及 EPEL 7、8、Centos Stream 等提供 _k9s_。要安装它,请使用以下命令:
|
||||
|
||||
```
|
||||
sudo dnf copr enable luminoso/k9s
|
||||
sudo dnf install k9s
|
||||
```
|
||||
|
||||
## [][15] rhbzquery
|
||||
|
||||
[rhbzquery][16] 是一个简单的查询 Fedora Bugzilla 的工具。它提供了一个指定搜索查询的接口,但它并不在命令行中列出结果,而是由 _rhbzquery_ 生成 Bugzilla 的 URL,并在浏览器中打开。
|
||||
|
||||
|
||||
![][17]
|
||||
|
||||
### [][18] 安装说明
|
||||
|
||||
目前[仓库][19]为 Fedora 32、33 和 Fedora Rawhide 提供 *rhbzquery*。要安装它,请使用以下命令:
|
||||
|
||||
```
|
||||
sudo dnf copr enable petersen/rhbzquery
|
||||
sudo dnf install rhbzquery
|
||||
```
|
||||
|
||||
## [][20] gping
|
||||
|
||||
[gping][21] 是一个比标准的 _ping_ 命令更有视觉吸引力的选择,因为它以图表的形式显示结果。也可以同时 ping 多个主机,以方便比较它们的响应时间。
|
||||
|
||||
![][22]
|
||||
|
||||
### [][23] 安装说明
|
||||
|
||||
目前[仓库][24]为 Fedora 32、33、Fedora Rawhide 以及 EPEL 7 和 8 提供了 gping。要安装它,请使用以下命令:
|
||||
|
||||
```
|
||||
sudo dnf copr enable atim/gping
|
||||
sudo dnf install gping
|
||||
```
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://fedoramagazine.org/4-cool-new-projects-to-try-in-copr-from-december/
|
||||
|
||||
作者:[Jakub Kadlčík][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[geekpi](https://github.com/geekpi)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://fedoramagazine.org/author/frostyx/
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://fedoramagazine.org/wp-content/uploads/2017/08/4-copr-945x400.jpg
|
||||
[2]: https://copr.fedorainfracloud.org/
|
||||
[3]: https://docs.pagure.org/copr.copr/user_documentation.html
|
||||
[4]: https://github.com/FrostyX/fedora-magazine/blob/main/2020-december.md#blanket
|
||||
[5]: https://github.com/rafaelmardojai/blanket
|
||||
[6]: https://github.com/FrostyX/fedora-magazine/raw/main/img/blanket.png
|
||||
[7]: https://github.com/FrostyX/fedora-magazine/blob/main/2020-december.md#installation-instructions
|
||||
[8]: https://copr.fedorainfracloud.org/coprs/tuxino/blanket/
|
||||
[9]: https://github.com/FrostyX/fedora-magazine/blob/main/2020-december.md#k9s
|
||||
[10]: https://k9scli.io/
|
||||
[11]: https://github.com/FrostyX/fedora-magazine/raw/main/img/k9s.png
|
||||
[12]: https://k9scli.io/#-previews
|
||||
[13]: https://github.com/FrostyX/fedora-magazine/blob/main/2020-december.md#installation-instructions-1
|
||||
[14]: https://copr.fedorainfracloud.org/coprs/luminoso/k9s/
|
||||
[15]: https://github.com/FrostyX/fedora-magazine/blob/main/2020-december.md#rhbzquery
|
||||
[16]: https://github.com/juhp/rhbzquery
|
||||
[17]: https://github.com/FrostyX/fedora-magazine/raw/main/img/rhbzquery.png
|
||||
[18]: https://github.com/FrostyX/fedora-magazine/blob/main/2020-december.md#installation-instructions-2
|
||||
[19]: https://copr.fedorainfracloud.org/coprs/petersen/rhbzquery/
|
||||
[20]: https://github.com/FrostyX/fedora-magazine/blob/main/2020-december.md#gping
|
||||
[21]: https://github.com/orf/gping
|
||||
[22]: https://github.com/FrostyX/fedora-magazine/raw/main/img/gping.png
|
||||
[23]: https://github.com/FrostyX/fedora-magazine/blob/main/2020-december.md#installation-instructions-4
|
||||
[24]: https://copr.fedorainfracloud.org/coprs/atim/gping
|
@ -0,0 +1,104 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (geekpi)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Font Manager: A Simple Open-Source App for GTK+ Desktop)
|
||||
[#]: via: (https://itsfoss.com/font-manager/)
|
||||
[#]: author: (Ankush Das https://itsfoss.com/author/ankush/)
|
||||
|
||||
Font Manager:一个简单的 GTK+ 桌面的开源应用
|
||||
======
|
||||
|
||||
_**简介:一个非常简单的字体管理器应用,让你专注于调整 Linux 系统上的字体。**_
|
||||
|
||||
如果你是一个有经验的 Linux 用户,你可能会利用终端或 [tweak 工具][1]来管理你的 Linux 系统的字体。
|
||||
|
||||
老实说,不管 GNOME tweak 工具有多有用,仅仅管理字体可能会让人有点受不了。因此,一个单独的应用可以很好地帮助你管理字体。
|
||||
|
||||
### Font Manager:一个帮助管理字体的开源应用
|
||||
|
||||
![][2]
|
||||
|
||||
Font Manager(这就是应用的字面名称)是一个专门帮助你管理字体的应用。
|
||||
|
||||
你可以获得字体家族的详细信息,可用的变体,以及根据字体的高度、宽度、间距等进行过滤和调整的功能。考虑到它是一个简单的应用,因此你找不到很多功能,但是我将在下面简要介绍一些功能。
|
||||
|
||||
### Font Manager 的功能
|
||||
|
||||
![][3]
|
||||
|
||||
* 可以添加字体
|
||||
* 可以删除字体
|
||||
* 根据家族、供应商、间距、高度等因素轻松过滤字体
|
||||
* 调整字体的缩放系数
|
||||
* 调整字体的抗锯齿(软度/锐度)
|
||||
* 添加字体源,以便在安装前进行预览
|
||||
* 提供快速管理的键盘快捷键
|
||||
* 开箱即用的谷歌字体集成
|
||||
* 获取关于家族字体中可用字符的详细信息、许可证、字体大小、供应商、文件类型、间距、宽度和样式
|
||||
|
||||
|
||||
|
||||
![][4]
|
||||
|
||||
总的来说,你可以轻松安装或删除字体。但是,当你管理字体时,你会得到相当多的好处,如上面的截图所示。
|
||||
|
||||
### 在 Linux 上安装 Font Manager
|
||||
|
||||
你有多种选择(取决于你使用的 Linux 发行版)进行安装。
|
||||
|
||||
如果你使用的是基于 Ubuntu 的发行版,你可以通过下面的命令轻松添加 PPA 来安装 Font Manager:
|
||||
|
||||
```
|
||||
sudo add-apt-repository ppa:font-manager/staging
|
||||
sudo apt update
|
||||
sudo apt install font-manager
|
||||
```
|
||||
|
||||
如果你不喜欢 [PPAs][5](我更喜欢这样安装),你也可以在任何 Linux 发行版上安装一个[可用的 Flatpak 包][6]。
|
||||
|
||||
你只需要在你的 Linux 系统上启用 Flatpak,然后在你的软件中心搜索它(如果它支持 Flatpak 集成的话),或者直接输入下面的命令安装它:
|
||||
|
||||
```
|
||||
flatpak install flathub org.gnome.FontManager
|
||||
```
|
||||
|
||||
如果你是 Arch 用户,你可以在 [AUR][8] 中找到[包][7]。
|
||||
|
||||
|
||||
更多的安装说明,你可以参考它的[官网][9]和 [GitHub 页面][10]。
|
||||
|
||||
[下载 Font Manager][9]
|
||||
|
||||
### 总结
|
||||
|
||||
Font Manager 是一个简单的解决方案,适用于任何基于 GTK+ 的桌面环境。主要用于 GNOME,但你在其他桌面环境使用它。
|
||||
|
||||
你可以得到很多有用的信息,同时可以添加或删除字体,我想这显然是一个不折不扣的字体管理器。
|
||||
|
||||
你对 Font Manager 有什么看法?在下面的评论中告诉我你的想法吧!
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://itsfoss.com/font-manager/
|
||||
|
||||
作者:[Ankush Das][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[geekpi](https://github.com/geekpi)
|
||||
校对:[校对者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://itsfoss.com/gnome-tweak-tool/
|
||||
[2]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2020/12/font-manager.png?resize=800%2C565&ssl=1
|
||||
[3]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2020/12/font-manager-settings.jpg?resize=800%2C569&ssl=1
|
||||
[4]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2020/12/font-manager-showcase.png?resize=800%2C571&ssl=1
|
||||
[5]: https://itsfoss.com/ppa-guide/
|
||||
[6]: https://flathub.org/apps/details/org.gnome.FontManager
|
||||
[7]: https://aur.archlinux.org/packages/font-manager/
|
||||
[8]: https://itsfoss.com/aur-arch-linux/
|
||||
[9]: https://fontmanager.github.io/
|
||||
[10]: https://github.com/FontManager/font-manager
|
Loading…
Reference in New Issue
Block a user