diff --git a/.gitignore b/.gitignore index 7b56441580..b5bb51a97a 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,5 @@ members.md *.html *.bak .DS_Store +sources/*/.* +translated/*/.* \ No newline at end of file diff --git a/lctt2018.md b/lctt2018.md new file mode 100644 index 0000000000..7e2f3cb4df --- /dev/null +++ b/lctt2018.md @@ -0,0 +1,75 @@ +LCTT 2018:五周年纪念日 +====== + +我是老王,可能大家有不少人知道我,由于历史原因,我有好几个生日(;o),但是这些年来,我又多了一个生日,或者说纪念日——每过两年,我就要严肃认真地写一篇 [LCTT](https://linux.cn/lctt) 生日纪念文章。 + +喏,这一篇,就是今年的了,LCTT 如今已经五岁了! + +或许如同小孩子过生日总是比较快乐,而随着年岁渐长,过生日往往有不少负担——比如说,每次写这篇纪念文章时,我就需要回忆、反思这两年的做了些什么,往往颇为汗颜。 + +不过不管怎么说,总要总结一下这两年我们做了什么,有什么不足,也发一些展望吧。 + +### 江山代有英豪出 + +LCTT,如同一般的开源贡献组织,总是有不断的新老传承。我们的翻译组,也有不少成员,由于工作学习的原因,慢慢淡出,但同时,也不断有新的成员加入并接过前辈手中的旗帜(就是没人接我的)。 + +> **加入方式** + +> 请首先加入翻译组的 QQ 群,群号是:**198889102**,加群时请说明是“**志愿者**”。加入后记得修改您的群名片为您的 GitHub 的 ID。 + +> 加入的成员,请先阅读 [WIKI 如何开始](https://github.com/LCTT/TranslateProject/wiki/01-%E5%A6%82%E4%BD%95%E5%BC%80%E5%A7%8B)。 + +比如说,我们这两年来,oska874 承担了主要的选题工作,然后 lujun9972 适时的出现接过了不少选题工作;再比如说,qhwdw 出现后承担了大量繁难文章的翻译,pityonline 则专注于校对,甚至其校对的严谨程度让我都甘拜下风。还有 MjSeven 也同 qhwdw 一样,以极高的翻译频率从一星译者迅速登顶五星译者。当然,还有 Bestony、Locez、VizV 等人为 LCTT 提供了不少技术支持和开发工作。 + +### 硕果累累 + +我们并没有特别的招新渠道,但是总是时不时会有新的成员慕名而来,到目前为止,我们已经有 [331](https://linux.cn/lctt-list) 位做过贡献的成员,已经翻译发布了 3885 篇译文,合计字节达 33MB 之多! + +这两年,我们不但翻译了很多技术、新闻和评论类文章,也新增了新的翻译类型:[漫画](https://linux.cn/talk/comic/),其中一些漫画得到了很多好评。 + +我们发布的文章有一些达到了 100000+ 的访问量,这对于我们这种技术垂直内容可不容易。 + +而同时,[Linux 中国](https://linux.cn/)也发布了近万篇文章,而这一篇,应该就是第 [9999](https://linux.cn/article-9999-1.html) 篇文章,我们将在明天,进入新的篇章。 + +### 贡献者主页和贡献者证书 + +为了彰显诸位贡献者的贡献,我们为每位贡献者创立的自己的专页,并据此建立了[排行榜](https://linux.cn/lctt-list)。 + +同时,我们还特意请 Bestony 和“一一”设计开发和”贡献者证书”,大家可以在 [LCTT 贡献平台](https://lctt.linux.cn/)中领取。 + +### 规则进化 + +LCTT 最初创立时,甚至都没有采用 PR 模式。但是随着贡献者的增多,我们也逐渐在改善我们的流程、方法。 + +之前采用了很粗糙的 PR 模式,对 PR 中的文件、提交乃至于信息都没有进行硬性约束。后来在 VizV 的帮助下,建立了对 PR 的合规性检查;又在 pityonline 的督促下,采用了更为严格的 PR 审查机制。 + +LCTT 创立几年来,我们的一些流程和规范,已经成为其它一些翻译组的参考范本,我们也希望我们的这些经验,可以进一步帮助到其它的开源社区。 + +### 仓库重建和版权问题 + +今年还发生一次严重的事故,由于对选题来源把控不严和对版权问题没有引起足够的重视,我们引用的一篇文章违背了原文的版权规定,结果被原文作者投诉到 GitHub。而我并没有及时看到 GitHub 给我发的 DMCA 处理邮件,因此错过了处理窗口期,从而被 GitHub 将整个库予以删除。 + +出现这样的重大失误之后,经过大家的帮助,我们历经周折才将仓库基本恢复。这要特别感谢 VizV 的辛苦工作。 + +在此之后,我们对译文选文的规则进行了梳理,并全面清查了文章版权。这个教训对我们来说弥足沉重。 + +### 通证时代 + +在 Linux 中国及 LCTT 发展过程中,我一直小心翼翼注意商业化的问题。严格来说,没有经济支持的开源组织如同无根之木,无源之水,是长久不了的。而商业化的技术社区又难免为了三斗米而折腰。所以往往很多技术社区要么渐渐凋零,要么就变成了商业机构。 + +从中国电信辞职后,我专职运营 Linux 中国这个开源社区已经近三年了,其间也有一些商业性收入,但是仅能勉强承担基本的运营费用。 + +这种尴尬的局面,使我,以及其它的开源社区同仁们纷纷寻求更好的发展之路。 + +去年参加中国开源年会时,在闭门会上,大家的讨论启发了我和诸位同仁,我们认为,开源社区结合通证经济,似乎是一条可行的开源社区发展之路。 + +今年 8 月 1 日,我们经过了半年的论证和实验,[发布了社区通证 LCCN](https://linux.cn/article-9886-1.html),并已经初步发放到了各位译者手中。我们还在继续建设通证生态各种工具,如合约、交易商城等。 + +我们希望能够通过通证为开源社区转入新的活力,也愿意将在探索道路上遇到的问题和解决的思路、工具链分享给更多的社区。 + +### 总结 + +从上一次总结以来,这又是七百多天,时光荏苒,而 LCTT 的创立也近两千天了。我希望,我们的翻译组以及更多的贡献者可以在通证经济的推动下,找到自洽、自治的发展道路;也希望能有更多的贡献者涌现出来接过我们的大旗,将开源发扬光大。 + +wxy +2018/9/9 夜 diff --git a/published/20140805 How to Install Cinnamon Desktop on Ubuntu.md b/published/20140805 How to Install Cinnamon Desktop on Ubuntu.md new file mode 100644 index 0000000000..cf4201ba77 --- /dev/null +++ b/published/20140805 How to Install Cinnamon Desktop on Ubuntu.md @@ -0,0 +1,77 @@ +如何在 Ubuntu 上安装 Cinnamon 桌面环境 +====== + +> 这篇教程将会为你展示如何在 Ubuntu 上安装 Cinnamon 桌面环境。 + +[Cinnamon][1] 是 [Linux Mint][2] 的默认桌面环境。不同于 Ubuntu 的 Unity 桌面环境,Cinnamon 是一个更加传统而优雅的桌面环境,其带有底部面板和应用菜单。由于 Cinnamon 桌面以及它类 Windows 的用户界面,许多桌面用户[相较于 Ubuntu 更喜欢 Linux Mint][3]。 + +现在你无需[安装 Linux Mint][4] 就能够体验到 Cinnamon了。在这篇教程,我将会展示给你如何在 Ubuntu 18.04,16.04 和 14.04 上安装 Cinnamon。 + +在 Ubuntu 上安装 Cinnamon 之前,有一些事情需要你注意。有时候,安装的额外桌面环境可能会与你当前的桌面环境有冲突。可能导致会话、应用程序或功能等的崩溃。这就是为什么你需要在做这个决定时谨慎一点的原因。 + +### 如何在 Ubuntu 上安装 Cinnamon 桌面环境 + +![如何在 Ubuntu 上安装 Cinnamon 桌面环境][5] + +过去有 Cinnamon 团队为 Ubuntu 提供的一系列的官方 PPA,但现在都已经失效了。不过不用担心,还有一个非官方的 PPA,而且它运行的很完美。这个 PPA 里包含了最新的 Cinnamon 版本。 + +``` +sudo add-apt-repository +ppa:embrosyn/cinnamon +sudo apt update && sudo apt install cinnamon +``` + +下载的大小大概是 150 MB(如果我没记错的话)。这其中提供的 Nemo(Cinnamon 的文件管理器,基于 Nautilus)和 Cinnamon 控制中心。这些东西提供了一个更加接近于 Linux Mint 的感觉。 + +### 在 Ubuntu 上使用 Cinnamon 桌面环境 + +Cinnamon 安装完成后,退出当前会话,在登录界面,点击用户名旁边的 Ubuntu 符号: + +![](https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2014/08/Change_Desktop_Environment_Ubuntu.jpeg) + +之后,它将会显示所有系统可用的桌面环境。选择 Cinnamon。 + +![](https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2014/08/Install_Cinnamon_Ubuntu.jpeg) + +现在你应该已经登录到有着 Cinnamon 桌面环境的 Ubuntu 中了。你还可以通过同样的方式再回到 Unity 桌面。这里有一张以 Cinnamon 做为桌面环境的 Ubuntu 桌面截图。 + +![](https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2014/08/Cinnamon_Ubuntu_1404.jpeg) + +看起来是不是像极了 Linux Mint。此外,我并没有发现任何有关 Cinnamon 和 Unity 的兼容性问题。在 Unity 和 Cinnamon 来回切换,它们也依旧工作的很完美。 + +#### 从 Ubuntu 卸载 Cinnamon + +如果你想卸载 Cinnamon,可以使用 PPA Purge 来完成。首先安装 PPA Purge: + +``` +sudo apt-get install ppa-purge +``` + +安装完成之后,使用下面的命令去移除该 PPA: + +``` +sudo ppa-purge ppa:embrosyn/cinnamon +``` + +更多的信息,我建议你去阅读 [如何从 Linux 移除 PPA][6] 这篇文章。 + +我希望这篇文章能够帮助你在 Ubuntu 上安装 Cinnamon。也可以分享一下你使用 Cinnamon 的经验。 + +------ + +via: https://itsfoss.com/install-cinnamon-on-ubuntu/ + +作者:[Abhishek Prakash][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[dianbanjiu](https://github.com/dianbanjiu) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://itsfoss.com/author/abhishek/ +[1]: http://cinnamon.linuxmint.com/ +[2]: http://www.linuxmint.com/ +[3]: https://itsfoss.com/linux-mint-vs-ubuntu/ +[4]: https://itsfoss.com/guide-install-linux-mint-16-dual-boot-windows/ +[5]: https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/09/install-cinnamon-ubuntu.png +[6]: https://itsfoss.com/how-to-remove-or-delete-ppas-quick-tip/ diff --git a/published/20160503 Cloud Commander - A Web File Manager With Console And Editor.md b/published/20160503 Cloud Commander - A Web File Manager With Console And Editor.md new file mode 100644 index 0000000000..ff9792dbea --- /dev/null +++ b/published/20160503 Cloud Commander - A Web File Manager With Console And Editor.md @@ -0,0 +1,143 @@ +Cloud Commander:一个有控制台和编辑器的 Web 文件管理器 +====== + +![](https://www.ostechnix.com/wp-content/uploads/2016/05/Cloud-Commander-A-Web-File-Manager-With-Console-And-Editor-720x340.png) + +**Cloud Commander** 是一个基于 web 的文件管理程序,它允许你通过任何计算机、移动端或平板电脑的浏览器查看、访问或管理系统文件或文件夹。它有两个简单而又经典的面板,并且会像你设备的显示尺寸一样自动转换大小。它也拥有两款内置的叫做 **Dword** 和 **Edward** 的文本编辑器,它们支持语法高亮,并带有一个支持系统命令行的控制台。因此,您可以随时随地编辑文件。Cloud Commander 服务器是一款在 Linux、Windows、Mac OS X 运行的跨平台应用,而且该应用客户端可以在任何一款浏览器上运行。它是用 **JavaScript/Node.Js** 写的,并使用 **MIT** 许可证。 + +在这个简易教程中,让我们看一看如何在 Ubuntu 18.04 LTS 服务器上安装 Cloud Commander。 + +### 前提条件 + +像我之前提到的,是用 Node.js 写的。所以为了安装 Cloud Commander,我们需要首先安装 Node.js。要执行安装,参考下面的指南。 + +- [如何在 Linux 上安装 Node.js](https://www.ostechnix.com/install-node-js-linux/) + +### 安装 Cloud Commander + +在安装 Node.js 之后,运行下列命令安装 Cloud Commander: + +``` +$ npm i cloudcmd -g +``` + +祝贺!Cloud Commander 已经安装好了。让我们往下继续看看 Cloud Commander 的基本使用。 + +### 开始使用 Cloud Commander + +运行以下命令启动 Cloud Commander: + +``` +$ cloudcmd +``` + +**输出示例:** + +``` +url: http://localhost:8000 +``` + +现在,打开你的浏览器并转到链接:`http://localhost:8000` 或 `http://IP-address:8000`。 + +从现在开始,您可以直接在本地系统或远程系统或移动设备,平板电脑等Web浏览器中创建,删除,查看,管理文件或文件夹。 + +![][2] + +如你所见上面的截图,Clouder Commander 有两个面板,十个热键 (`F1` 到 `F10`),还有控制台。 + +每个热键执行的都是一个任务。 + + * `F1` – 帮助 + * `F2` – 重命名文件/文件夹 + * `F3` – 查看文件/文件夹 + * `F4` – 编辑文件 + * `F5` – 复制文件/文件夹 + * `F6` – 移动文件/文件夹 + * `F7` – 创建新目录 + * `F8` – 删除文件/文件夹 + * `F9` – 打开菜单 + * `F10` – 打开设置 + +#### Cloud Commmander 控制台 + +点击控制台图标。这即将打开系统默认的命令行界面。 + +![][3] + +在此控制台中,您可以执行各种管理任务,例如安装软件包、删除软件包、更新系统等。您甚至可以关闭或重新引导系统。 因此,Cloud Commander 不仅仅是一个文件管理器,还具有远程管理工具的功能。 + +#### 创建文件/文件夹 + +要创建新的文件或文件夹就右键单击任意空位置并找到 “New - >File or Directory”。 + +![][4] + +#### 查看文件 + +你可以查看图片,查看音视频文件。 + +![][5] + +#### 上传文件 + +另一个很酷的特性是我们可以从任何系统或设备简单地上传一个文件到 Cloud Commander 系统。 + +要上传文件,右键单击 Cloud Commander 面板的任意空白处,并且单击“Upload”选项。 + +![][6] + +选择你想要上传的文件。 + +另外,你也可以上传来自像 Google 云盘、Dropbox、Amazon 云盘、Facebook、Twitter、Gmail、GitHub、Picasa、Instagram 还有很多的云服务上的文件。 + +要从云端上传文件, 右键单击面板的任意空白处,并且右键单击面板任意空白处并选择“Upload from Cloud”。 + +![][7] + +选择任意一个你选择的网络服务,例如谷歌云盘。点击“Connect to Google drive”按钮。 + +![][8] + +下一步,用 Cloud Commander 验证你的谷歌云端硬盘,从谷歌云端硬盘选择文件并点击“Upload”。 + +![][9] + +#### 更新 Cloud Commander + +要更新到最新的可用版本,执行下面的命令: + +``` +$ npm update cloudcmd -g +``` + +#### 总结 + +据我测试,它运行很好。在我的 Ubuntu 服务器测试期间,我没有遇到任何问题。此外,Cloud Commander 不仅是基于 Web 的文件管理器,还可以充当执行大多数 Linux 管理任务的远程管理工具。 您可以创建文件/文件夹、重命名、删除、编辑和查看它们。此外,您可以像在终端中在本地系统中那样安装、更新、升级和删除任何软件包。当然,您甚至可以从 Cloud Commander 控制台本身关闭或重启系统。 还有什么需要的吗? 尝试一下,你会发现它很有用。 + +目前为止就这样吧。 我将很快在这里发表另一篇有趣的文章。 在此之前,请继续关注我们。 + +祝贺! + + + +-------------------------------------------------------------------------------- + +via: https://www.ostechnix.com/cloud-commander-a-web-file-manager-with-console-and-editor/ + +作者:[SK][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[fuzheng1998](https://github.com/fuzheng1998) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.ostechnix.com/author/sk/ +[1]:data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7 +[2]:http://www.ostechnix.com/wp-content/uploads/2016/05/Cloud-Commander-Google-Chrome_006-4.jpg +[3]:http://www.ostechnix.com/wp-content/uploads/2016/05/Cloud-Commander-Google-Chrome_007-2.jpg +[4]:http://www.ostechnix.com/wp-content/uploads/2016/05/Cloud-commander-file-folder-1.png +[5]:http://www.ostechnix.com/wp-content/uploads/2016/05/Cloud-Commander-home-sk-Google-Chrome_008-1.jpg +[6]:http://www.ostechnix.com/wp-content/uploads/2016/05/cloud-commander-upload-2.png +[7]:http://www.ostechnix.com/wp-content/uploads/2016/05/upload-from-cloud-1.png +[8]:http://www.ostechnix.com/wp-content/uploads/2016/05/Cloud-Commander-home-sk-Google-Chrome_009-2.jpg +[9]:http://www.ostechnix.com/wp-content/uploads/2016/05/Cloud-Commander-home-sk-Google-Chrome_010-1.jpg diff --git a/published/201703/20170223 How to install Arch Linux on VirtualBox.md b/published/201703/20170223 How to install Arch Linux on VirtualBox.md index 58a094b048..cdd68a0642 100644 --- a/published/201703/20170223 How to install Arch Linux on VirtualBox.md +++ b/published/201703/20170223 How to install Arch Linux on VirtualBox.md @@ -104,10 +104,10 @@ Arch Linux 也因其丰富的 Wiki 帮助文档而大受推崇。该系统基于 ][23] 输入下面的命令来检查网络连接。 - + ``` ping google.com -``` +``` 这个单词 ping 表示网路封包搜寻。你将会看到下面的返回信息,表明 Arch Linux 已经连接到外网了。这是执行安装过程中的很关键的一点。(LCTT 译注:或许你 ping 不到那个不存在的网站,你选个存在的吧。) @@ -117,8 +117,8 @@ ping google.com 输入如下命令清屏: -``` -clear +``` +clear ``` 在开始安装之前,你得先为硬盘分区。输入 `fdisk -l` ,你将会看到当前系统的磁盘分区情况。注意一开始你给 Arch Linux 系统分配的 20 GB 存储空间。 @@ -137,8 +137,8 @@ clear 输入下面的命令: -``` -cfdisk +``` +cfdisk ``` 你将看到 `gpt`、`dos`、`sgi` 和 `sun` 类型,选择 `dos` 选项,然后按回车。 @@ -185,8 +185,8 @@ cfdisk 以同样的方式创建逻辑分区。在“退出(quit)”选项按回车键,然后输入下面的命令来清屏: -``` -clear +``` +clear ``` [ @@ -195,21 +195,21 @@ clear 输入下面的命令来格式化新建的分区: -``` +``` mkfs.ext4 /dev/sda1 -``` +``` 这里的 `sda1` 是分区名。使用同样的命令来格式化第二个分区 `sda3` : -``` +``` mkfs.ext4 /dev/sda3 -``` +``` 格式化 swap 分区: -``` +``` mkswap /dev/sda2 -``` +``` [ ![Format the swap partition with mkswap](https://www.howtoforge.com/images/install_arch_linux_on_virtual_box/121224.png) @@ -217,14 +217,14 @@ mkswap /dev/sda2 使用下面的命令来激活 swap 分区: -``` -swapon /dev/sda2 +``` +swapon /dev/sda2 ``` 输入 clear 命令清屏: -``` -clear +``` +clear ``` [ @@ -233,9 +233,9 @@ clear 输入下面的命令来挂载主分区以开始系统安装: -``` -mount /dev/sda1 / mnt -``` +``` +mount /dev/sda1 /mnt +``` [ ![Mount the partitions](https://www.howtoforge.com/images/install_arch_linux_on_virtual_box/121226.png) @@ -245,9 +245,9 @@ mount /dev/sda1 / mnt 输入下面的命令来引导系统启动: -``` +``` pacstrap /mnt base base-devel -``` +``` 可以看到系统正在同步数据包。 @@ -263,9 +263,9 @@ pacstrap /mnt base base-devel 系统基本软件安装完成后,输入下面的命令来创建 fstab 文件: -``` +``` genfstab /mnt>> /mnt/etc/fstab -``` +``` [ ![Generating /etc/fstab](https://www.howtoforge.com/images/install_arch_linux_on_virtual_box/121229.png) @@ -275,14 +275,14 @@ genfstab /mnt>> /mnt/etc/fstab 输入下面的命令来更改系统的根目录为 Arch Linux 的安装目录: -``` +``` arch-chroot /mnt /bin/bash -``` +```  现在来更改语言配置: -``` -nano /etc/local.gen +``` +nano /etc/locale.gen ``` [ @@ -297,9 +297,9 @@ nano /etc/local.gen 输入下面的命令来激活它: -``` +``` locale-gen -``` +``` 按回车。 @@ -309,8 +309,8 @@ locale-gen 使用下面的命令来创建 `/etc/locale.conf` 配置文件: -``` -nano /etc/locale.conf +``` +nano /etc/locale.conf ``` 然后按回车。现在你就可以在配置文件中输入下面一行内容来为系统添加语言: @@ -326,9 +326,9 @@ LANG=en_US.UTF-8 ][44] 输入下面的命令来同步时区: - + ``` -ls user/share/zoneinfo +ls /usr/share/zoneinfo ``` 下面你将看到整个世界的时区列表。 @@ -339,9 +339,9 @@ ls user/share/zoneinfo 输入下面的命令来选择你所在的时区: -``` +``` ln –s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime -``` +``` 或者你可以从下面的列表中选择其它名称。 @@ -351,8 +351,8 @@ ln –s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime 使用下面的命令来设置标准时间: -``` -hwclock --systohc –utc +``` +hwclock --systohc --utc ``` 硬件时钟已同步。 @@ -363,8 +363,8 @@ hwclock --systohc –utc 设置 root 帐号密码: -``` -passwd +``` +passwd ``` 按回车。 然而输入你想设置的密码,按回车确认。 @@ -377,9 +377,9 @@ passwd 使用下面的命令来设置主机名: -``` +``` nano /etc/hostname -``` +``` 然后按回车。输入你想设置的主机名称,按 `control + x` ,按 `y` ,再按回车 。 @@ -389,9 +389,9 @@ nano /etc/hostname 启用 dhcpcd : -``` +``` systemctl enable dhcpcd -``` +``` 这样在下一次系统启动时, dhcpcd 将会自动启动,并自动获取一个 IP 地址: @@ -403,9 +403,9 @@ systemctl enable dhcpcd 最后一步,输入以下命令来初始化 grub 安装。输入以下命令: -``` +``` pacman –S grub os-rober -``` +``` 然后按 `y` ,将会下载相关程序。 @@ -415,14 +415,14 @@ pacman –S grub os-rober 使用下面的命令来将启动加载程序安装到硬盘上: -``` +``` grub-install /dev/sda -``` +``` 然后进行配置: -``` -grub-mkconfig -o /boot/grub/grub.cfg +``` +grub-mkconfig -o /boot/grub/grub.cfg ``` [ @@ -431,9 +431,9 @@ grub-mkconfig -o /boot/grub/grub.cfg 最后重启系统: -``` +``` reboot -``` +``` 然后按回车 。 @@ -459,7 +459,7 @@ reboot via: https://www.howtoforge.com/tutorial/install-arch-linux-on-virtualbox/ -译者简介: +译者简介: rusking:春城初春/春水初生/春林初盛/春風十裏不如妳 diff --git a/published/20170706 Docker Guide Dockerizing Python Django Application.md b/published/20170706 Docker Guide Dockerizing Python Django Application.md new file mode 100644 index 0000000000..e89a2065f5 --- /dev/null +++ b/published/20170706 Docker Guide Dockerizing Python Django Application.md @@ -0,0 +1,420 @@ +如何 Docker 化 Python Django 应用程序 +====== + +Docker 是一个开源项目,为开发人员和系统管理员提供了一个开放平台,可以将应用程序构建、打包为一个轻量级容器,并在任何地方运行。Docker 会在软件容器中自动部署应用程序。 + +Django 是一个用 Python 编写的 Web 应用程序框架,遵循 MVC(模型-视图-控制器)架构。它是免费的,并在开源许可下发布。它速度很快,旨在帮助开发人员尽快将他们的应用程序上线。 + +在本教程中,我将逐步向你展示在 Ubuntu 16.04 中如何为现有的 Django 应用程序创建 docker 镜像。我们将学习如何 docker 化一个 Python Django 应用程序,然后使用一个 `docker-compose` 脚本将应用程序作为容器部署到 docker 环境。 + +为了部署我们的 Python Django 应用程序,我们需要其它 docker 镜像:一个用于 Web 服务器的 nginx docker 镜像和用于数据库的 PostgreSQL 镜像。 + +### 我们要做什么? + +1. 安装 Docker-ce +2. 安装 Docker-compose +3. 配置项目环境 +4. 构建并运行 +5. 测试 + +### 步骤 1 - 安装 Docker-ce + +在本教程中,我们将从 docker 仓库安装 docker-ce 社区版。我们将安装 docker-ce 社区版和 `docker-compose`(其支持 compose 文件版本 3)。 + +在安装 docker-ce 之前,先使用 `apt` 命令安装所需的 docker 依赖项。 + +``` +sudo apt install -y \ +    apt-transport-https \ +    ca-certificates \ +    curl \ +    software-properties-common +``` + +现在通过运行以下命令添加 docker 密钥和仓库。 + +``` +curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - +sudo add-apt-repository \ +   "deb [arch=amd64] https://download.docker.com/linux/ubuntu \ +   $(lsb_release -cs) \ +   stable" +``` + +[![安装 Docker-ce](https://www.howtoforge.com/images/docker_guide_dockerizing_python_django_application/1.png)][14] + +更新仓库并安装 docker-ce。 + +``` +sudo apt update +sudo apt install -y docker-ce +``` + +安装完成后,启动 docker 服务并使其能够在每次系统引导时启动。 + +``` +systemctl start docker +systemctl enable docker +``` + +接着,我们将添加一个名为 `omar` 的新用户并将其添加到 `docker` 组。 + +``` +useradd -m -s /bin/bash omar +usermod -a -G docker omar +``` + +[![启动 Docker](https://www.howtoforge.com/images/docker_guide_dockerizing_python_django_application/2.png)][15] + +以 `omar` 用户身份登录并运行 `docker` 命令,如下所示。 + +``` +su - omar +docker run hello-world +``` + +确保你能从 Docker 获得 hello-world 消息。 + + [![检查 Docker 安装](https://www.howtoforge.com/images/docker_guide_dockerizing_python_django_application/3.png)][16] + +Docker-ce 安装已经完成。 + +### 步骤 2 - 安装 Docker-compose + +在本教程中,我们将使用支持 compose 文件版本 3 的最新 `docker-compose`。我们将手动安装 `docker-compose`。 + +使用 `curl` 命令将最新版本的 `docker-compose` 下载到 `/usr/local/bin` 目录,并使用 `chmod` 命令使其有执行权限。 + +运行以下命令: + +``` +sudo curl -L https://github.com/docker/compose/releases/download/1.21.0/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose +sudo chmod +x /usr/local/bin/docker-compose +``` + +现在检查 `docker-compose` 版本。 + +``` +docker-compose version +``` + +确保你安装的是最新版本的 docker-compose 1.21。 + + [![安装 Docker-compose](https://www.howtoforge.com/images/docker_guide_dockerizing_python_django_application/4.png)][17] + +已安装支持 compose 文件版本 3 的 `docker-compose` 最新版本。 + +### 步骤 3 - 配置项目环境 + +在这一步中,我们将配置 Python Django 项目环境。我们将创建新目录 `guide01`,并使其成为我们项目文件的主目录,例如包括 Dockerfile、Django 项目、nginx 配置文件等。 + +登录到 `omar` 用户。 + +``` +su - omar +``` + +创建一个新目录 `guide01`,并进入目录。 + +``` +mkdir -p guide01 +cd guide01/ +``` + +现在在 `guide01` 目录下,创建两个新目录 `project` 和 `config`。 + +``` +mkdir project/ config/ +``` + +注意: + +* `project` 目录:我们所有的 python Django 项目文件都将放在该目录中。 +* `config` 目录:项目配置文件的目录,包括 nginx 配置文件、python pip 的`requirements.txt` 文件等。 + +#### 创建一个新的 requirements.txt 文件 + +接下来,使用 `vim` 命令在 `config` 目录中创建一个新的 `requirements.txt` 文件。 + +``` +vim config/requirements.txt +``` + +粘贴下面的配置: + +``` +Django==2.0.4  +gunicorn==19.7.0  +psycopg2==2.7.4 +``` + +保存并退出。 + +#### 创建 Nginx 虚拟主机文件 django.conf + +在 `config` 目录下创建 nginx 配置目录并添加虚拟主机配置文件 `django.conf`。 + +``` +mkdir -p config/nginx/ +vim config/nginx/django.conf +``` + +粘贴下面的配置: + +``` +upstream web { + ip_hash; + server web:8000; +} + +# portal +server { + location / { + proxy_pass http://web/; + } + listen 8000; + server_name localhost; + + location /static { + autoindex on; + alias /src/static/; + } +} +``` + +保存并退出。 + +#### 创建 Dockerfile + +在 `guide01` 目录下创建新文件 `Dockerfile`。 + +运行以下命令: + +``` +vim Dockerfile +``` + +现在粘贴下面的 Dockerfile 脚本: + +``` +FROM python:3.5-alpine +ENV PYTHONUNBUFFERED 1  + +RUN apk update && \ +    apk add --virtual build-deps gcc python-dev musl-dev && \ +    apk add postgresql-dev bash + +RUN mkdir /config  +ADD /config/requirements.txt /config/  +RUN pip install -r /config/requirements.txt +RUN mkdir /src +WORKDIR /src +``` + +保存并退出。 + +注意: + +我们想要为我们的 Django 项目构建基于 Alpine Linux 的 Docker 镜像,Alpine 是最小的 Linux 版本。我们的 Django 项目将运行在带有 Python 3.5 的 Alpine Linux 上,并添加 postgresql-dev 包以支持 PostgreSQL 数据库。然后,我们将使用 python `pip` 命令安装在 `requirements.txt` 上列出的所有 Python 包,并为我们的项目创建新目录 `/src`。 + +#### 创建 Docker-compose 脚本 + +使用 [vim][18] 命令在 `guide01` 目录下创建 `docker-compose.yml` 文件。 + +``` +vim docker-compose.yml +``` + +粘贴以下配置内容: + +``` +version: '3' + services: +   db: +      image: postgres:10.3-alpine +     container_name: postgres01 +   nginx: +     image: nginx:1.13-alpine +     container_name: nginx01 +     ports: +       - "8000:8000" +     volumes: +       - ./project:/src +       - ./config/nginx:/etc/nginx/conf.d +     depends_on: +       - web +   web: +     build: . +     container_name: django01 +     command: bash -c "python manage.py makemigrations && python manage.py migrate && python manage.py collectstatic --noinput && gunicorn hello_django.wsgi -b 0.0.0.0:8000" +     depends_on: +       - db +     volumes: +       - ./project:/src +     expose: +       - "8000" +     restart: always +``` + +保存并退出。 + +注意: + +使用这个 `docker-compose` 文件脚本,我们将创建三个服务。使用 alpine Linux 版的 PostgreSQL 创建名为 `db` 的数据库服务,再次使用 alpine Linux 版的 Nginx 创建 `nginx` 服务,并使用从 Dockerfile 生成的自定义 docker 镜像创建我们的 python Django 容器。 + +[![配置项目环境](https://www.howtoforge.com/images/docker_guide_dockerizing_python_django_application/5.png)][19] + +#### 配置 Django 项目 + +将 Django 项目文件复制到 `project` 目录。 + +``` +cd ~/django +cp -r * ~/guide01/project/ +``` + +进入 `project` 目录并编辑应用程序设置 `settings.py`。 + +``` +cd ~/guide01/project/ +vim hello_django/settings.py +``` + +注意: + +我们将部署名为 “hello_django” 的简单 Django 应用程序。 + +在 `ALLOW_HOSTS` 行中,添加服务名称 `web`。 + +``` +ALLOW_HOSTS = ['web'] +``` + +现在更改数据库设置,我们将使用 PostgreSQL 数据库来运行名为 `db` 的服务,使用默认用户和密码。 + +``` +DATABASES = {  +    'default': { +        'ENGINE': 'django.db.backends.postgresql_psycopg2', +        'NAME': 'postgres', +        'USER': 'postgres', +        'HOST': 'db', +        'PORT': 5432, +    } +} +``` + +至于 `STATIC_ROOT` 配置目录,将此行添加到文件行的末尾。 + +``` +STATIC_ROOT = os.path.join(BASE_DIR, 'static/') +``` + +保存并退出。 + +[![配置 Django 项目](https://www.howtoforge.com/images/docker_guide_dockerizing_python_django_application/6.png)][20] + +现在我们准备在 docker 容器下构建和运行 Django 项目。 + +### 步骤 4 - 构建并运行 Docker 镜像 + +在这一步中,我们想要使用 `guide01` 目录中的配置为我们的 Django 项目构建一个 Docker 镜像。 + +进入 `guide01` 目录。 + +``` +cd ~/guide01/ +``` + +现在使用 `docker-compose` 命令构建 docker 镜像。 + +``` +docker-compose build +``` + +[![运行 docker 镜像](https://www.howtoforge.com/images/docker_guide_dockerizing_python_django_application/7.png)][21] + +启动 `docker-compose` 脚本中的所有服务。 + +``` +docker-compose up -d +``` + +等待几分钟让 Docker 构建我们的 Python 镜像并下载 nginx 和 postgresql docker 镜像。 + +[![使用 docker-compose 构建镜像](https://www.howtoforge.com/images/docker_guide_dockerizing_python_django_application/8.png)][22] + +完成后,使用以下命令检查运行容器并在系统上列出 docker 镜像。 + +``` +docker-compose ps +docker-compose images +``` + +现在,你将在系统上运行三个容器,列出 Docker 镜像,如下所示。 + +[![docke-compose ps 命令](https://www.howtoforge.com/images/docker_guide_dockerizing_python_django_application/9.png)][23] + +我们的 Python Django 应用程序现在在 docker 容器内运行,并且已经创建了为我们服务的 docker 镜像。 + +### 步骤 5 - 测试 + +打开 Web 浏览器并使用端口 8000 键入服务器地址,我的是:`http://ovh01:8000/`。 + +现在你将看到默认的 Django 主页。 + +[![默认 Django 项目主页](https://www.howtoforge.com/images/docker_guide_dockerizing_python_django_application/10.png)][24] + +接下来,通过在 URL 上添加 `/admin` 路径来测试管理页面。 + +``` +http://ovh01:8000/admin/ +``` + +然后你将会看到 Django 管理登录页面。 + +[![Django administration](https://www.howtoforge.com/images/docker_guide_dockerizing_python_django_application/11.png)][25] + +Docker 化 Python Django 应用程序已成功完成。 + +### 参考 + +* [https://docs.docker.com/][13] + + +-------------------------------------------------------------------------------- + +via: https://www.howtoforge.com/tutorial/docker-guide-dockerizing-python-django-application/ + +作者:[Muhammad Arul][a] +译者:[MjSeven](https://github.com/MjSeven) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.howtoforge.com/tutorial/docker-guide-dockerizing-python-django-application/ +[1]:https://www.howtoforge.com/tutorial/docker-guide-dockerizing-python-django-application/#create-a-new-requirementstxt-file +[2]:https://www.howtoforge.com/tutorial/docker-guide-dockerizing-python-django-application/#create-the-nginx-virtual-host-file-djangoconf +[3]:https://www.howtoforge.com/tutorial/docker-guide-dockerizing-python-django-application/#create-the-dockerfile +[4]:https://www.howtoforge.com/tutorial/docker-guide-dockerizing-python-django-application/#create-dockercompose-script +[5]:https://www.howtoforge.com/tutorial/docker-guide-dockerizing-python-django-application/#configure-django-project +[6]:https://www.howtoforge.com/tutorial/docker-guide-dockerizing-python-django-application/#what-we-will-do +[7]:https://www.howtoforge.com/tutorial/docker-guide-dockerizing-python-django-application/#step-install-dockerce +[8]:https://www.howtoforge.com/tutorial/docker-guide-dockerizing-python-django-application/#step-install-dockercompose +[9]:https://www.howtoforge.com/tutorial/docker-guide-dockerizing-python-django-application/#step-configure-project-environment +[10]:https://www.howtoforge.com/tutorial/docker-guide-dockerizing-python-django-application/#step-build-and-run-the-docker-image +[11]:https://www.howtoforge.com/tutorial/docker-guide-dockerizing-python-django-application/#step-testing +[12]:https://www.howtoforge.com/tutorial/docker-guide-dockerizing-python-django-application/#reference +[13]:https://docs.docker.com/ +[14]:https://www.howtoforge.com/images/docker_guide_dockerizing_python_django_application/big/1.png +[15]:https://www.howtoforge.com/images/docker_guide_dockerizing_python_django_application/big/2.png +[16]:https://www.howtoforge.com/images/docker_guide_dockerizing_python_django_application/big/3.png +[17]:https://www.howtoforge.com/images/docker_guide_dockerizing_python_django_application/big/4.png +[18]:https://www.howtoforge.com/vim-basics +[19]:https://www.howtoforge.com/images/docker_guide_dockerizing_python_django_application/big/5.png +[20]:https://www.howtoforge.com/images/docker_guide_dockerizing_python_django_application/big/6.png +[21]:https://www.howtoforge.com/images/docker_guide_dockerizing_python_django_application/big/7.png +[22]:https://www.howtoforge.com/images/docker_guide_dockerizing_python_django_application/big/8.png +[23]:https://www.howtoforge.com/images/docker_guide_dockerizing_python_django_application/big/9.png +[24]:https://www.howtoforge.com/images/docker_guide_dockerizing_python_django_application/big/10.png +[25]:https://www.howtoforge.com/images/docker_guide_dockerizing_python_django_application/big/11.png diff --git a/published/20170709 The Extensive Guide to Creating Streams in RxJS.md b/published/20170709 The Extensive Guide to Creating Streams in RxJS.md new file mode 100644 index 0000000000..8dbb42e640 --- /dev/null +++ b/published/20170709 The Extensive Guide to Creating Streams in RxJS.md @@ -0,0 +1,889 @@ +全面教程:在 RxJS 中创建流 +================================ + +![](https://cdn-images-1.medium.com/max/900/1*hj8mGnl5tM_lAlx5_vqS-Q.jpeg) + +对大多数开发者来说,与 RxJS 的初次接触是通过库的形式,就像 Angular。一些函数会返回stream,要使用它们就得把注意力放在操作符上。 + +有些时候,混用响应式和非响应式代码似乎很有用。然后大家就开始热衷流的创造。不论是在编写异步代码或者是数据处理时,流都是一个不错的方案。 + +RxJS 提供很多方式来创建流。不管你遇到的是什么情况,都会有一个完美的创建流的方式。你可能根本用不上它们,但了解它们可以节省你的时间,让你少码一些代码。 + +我把所有可能的方法,按它们的主要目的,放在四个分类当中: + +* 流式化现有数据 +* 生成数据 +* 使用现有 API 进行交互 +* 选择现有的流,并结合起来 + +注意:示例用的是 RxJS 6,可能会以前的版本有所不同。已知的区别是你导入函数的方式不同了。 + +RxJS 6 + +``` +import {of, from} from 'rxjs'; + +of(...); +from(...); +``` + +RxJS < 6 + +``` +import { Observable } from 'rxjs/Observable'; +import 'rxjs/add/observable/of'; +import 'rxjs/add/observable/from'; + +Observable.of(...); +Observable.from(...); + +//或 + +import { of } from 'rxjs/observable/of'; +import { from } from 'rxjs/observable/from'; + +of(...); +from(...); +``` + +流的图示中的标记: + +* `|` 表示流结束了 +* `X` 表示流出现错误并被终结 +* `...` 表示流的走向不定 + +### 流式化已有数据 + +你有一些数据,想把它们放到流中。有三种方式,并且都允许你把调度器当作最后一个参数传入(你如果想深入了解调度器,可以看看我的 [上一篇文章][5])。这些生成的流都是静态的。 + +#### of + +如果只有一个或者一些不同的元素,使用 `of`: + +``` +of(1,2,3) + .subscribe(); +``` + +``` +// 结果 +// 1 2 3 | +``` + +#### from + +如果有一个数组或者 _可迭代的对象_ ,而且你想要其中的所有元素发送到流中,使用 `from`。你也可以用它来把一个 promise 对象变成可观测的。 + +``` +const foo = [1,2,3]; + +from(foo) + .subscribe(); +``` + +``` +// 结果 +// 1 2 3 | +``` + +#### pairs + +流式化一个对象的键/值对。用这个对象表示字典时特别有用。 + +``` +const foo = { a: 1, b: 2}; + +pairs(foo) + .subscribe(); +``` + +``` +// 结果 +// [a,1] [b,2] | +``` + +#### 那么其他的数据结构呢? + +也许你的数据存储在自定义的结构中,而它又没有实现 _可迭代的对象_ 接口,又或者说你的结构是递归的、树状的。也许下面某种选择适合这些情况: + +1. 先将数据提取到数组里 +2. 使用下一节将会讲到的 `generate` 函数,遍历所有数据 +3. 创建一个自定义流(见下一节) +4. 创建一个迭代器 + +稍后会讲到选项 2 和 3 ,因此这里的重点是创建一个迭代器。我们可以对一个 _可迭代的对象_ 调用 `from` 创建一个流。 _可迭代的对象_ 是一个对象,可以产生一个迭代器(如果你对细节感兴趣,参考 [这篇 mdn 文章][6])。 + +创建一个迭代器的简单方式是 [生成函数][7]generator function。当你调用一个生成函数时,它返回一个对象,该对象同时遵循 _可迭代的对象_ 接口和 _迭代器_ 接口。 + +``` +// 自定义的数据结构 +class List { + add(element) ... + get(index) ... + get size() ... + ... +} + +function* listIterator(list) { + for (let i = 0; i console.log("foo"); +// 5 秒后打印 foo +``` + +大多数定时器将会用来周期性的处理数据: + +``` +interval(10000).pipe( + flatMap(i => fetch("https://server/stockTicker") +).subscribe(updateChart) +``` + +这段代码每 10 秒获取一次数据,更新屏幕。 + +#### 生成(`generate `) + +这是个更加复杂的函数,允许你发送一系列任意类型的对象。它有一些重载,这里你看到的是最有意思的部分: + +``` +generate( + 0, // 从这个值开始 + x => x < 10, // 条件:只要值小于 10,就一直发送 + x => x*2 // 迭代:前一个值加倍 +).subscribe(); +``` + +``` +// 结果 +// 1 2 4 8 | +``` + +你也可以用它来迭代值,如果一个结构没有实现 _可迭代的对象_ 接口。我们用前面的列表例子来进行演示: + +``` +const myList = new List(); +myList.add(1); +myList.add(3); + +generate( + 0, // 从这个值开始 + i => i < list.size, // 条件:发送数据,直到遍历完整个列表 + i => ++i, // 迭代:获取下一个索引 + i => list.get(i) // 选择器:从列表中取值 +).subscribe(); +``` + +``` +// 结果 +// 1 3 | +``` + +如你所见,我添加了另一个参数:选择器。它和 `map` 操作符作用类似,将生成的值转换为更有用的东西。 + +### 空的流 + +有时候你要传递或返回一个不用发送任何数据的流。有三个函数分别用于不同的情况。你可以给这三个函数传递调度器。`empty` 和 `throwError` 接收一个调度器参数。 + +#### `empty` + +创建一个空的流,一个值也不发送。 + +``` +empty() + .subscribe(); +``` + +``` +// 结果 +// | +``` + +#### `never` + +创建一个永远不会结束的流,仍然不发送值。 + +``` +never() + .subscribe(); +``` + +``` +// 结果 +// ... +``` + +#### `throwError` + +创建一个流,流出现错误,不发送数据。 + +``` +throwError('error') + .subscribe(); +``` + +``` +// 结果 +// X +``` + +### 挂钩已有的 API + +不是所有的库和所有你之前写的代码使用或者支持流。幸运的是 RxJS 提供函数用来桥接非响应式和响应式代码。这一节仅仅讨论 RxJS 为桥接代码提供的模版。 + +你可能还对这篇出自 [Ben Lesh][9] 的 [全面的文章][8] 感兴趣,这篇文章讲了几乎所有能与 promises 交互操作的方式。 + +#### `from` + +我们已经用过它,把它列在这里是因为,它可以封装一个含有 observable 对象的 promise 对象。 + +``` +from(new Promise(resolve => resolve(1))) + .subscribe(); +``` + +``` +// 结果 +// 1 | +``` + +#### fromEvent + +fromEvent 为 DOM 元素添加一个事件监听器,我确定你知道这个。但你可能不知道的是,也可以通过其它类型来添加事件监听器,例如,一个 jQuery 对象。 + +``` +const element = $('#fooButton'); // 从 DOM 元素中创建一个 jQuery 对象 + +from(element, 'click') + .subscribe(); +``` + +``` +// 结果 +// clickEvent ... +``` + +#### fromEventPattern + +要理解为什么有 fromEvent 了还需要 fromEventPattern,我们得先理解 fromEvent 是如何工作的。看这段代码: + +``` +from(document, 'click') + .subscribe(); +``` + +这告诉 RxJS 我们想要监听 document 中的点击事件。在提交过程中,RxJS 发现 document 是一个 _EventTarget_ 类型,因此它可以调用它的 `addEventListener` 方法。如果我们传入的是一个 jQuery 对象而非 document,那么 RxJs 知道它得调用 _on_ 方法。 + +这个例子用的是 _fromEventPattern_ ,和 _fromEvent_ 的工作基本上一样: + +``` +function addClickHandler(handler) { + document.addEventListener('click', handler); +} + +function removeClickHandler(handler) { + document.removeEventListener('click', handler); +} + +fromEventPattern( + addClickHandler, + removeClickHandler, +) +.subscribe(console.log); + +// 等效于 +fromEvent(document, 'click') +``` + +RxJS 自动创建实际的监听器( _handler_ )你的工作是添加或者移除监听器。_fromEventPattern_ 的目的基本上是告诉 RxJS 如何注册和移除事件监听器。 + +现在想象一下你使用了一个库,你可以调用一个叫做 _registerListener_ 的方法。我们不能再用 _fromEvent_,因为它并不知道该怎么处理这个对象。 + +``` +const listeners = []; + +class Foo { + registerListener(listener) { + listeners.push(listener); + } + + emit(value) { + listeners.forEach(listener => listener(value)); + } +} + +const foo = new Foo(); + +fromEventPattern(listener => foo.registerListener(listener)) + .subscribe(); + +foo.emit(1); +``` + +``` +// 结果 +// 1 ... +``` + +当我们调用 `foo.emit(1)` 时,RxJS 中的监听器将被调用,然后它就能把值发送到流中。 + +你也可以用它来监听多个事件类型,或者结合所有可以通过回调进行通讯的 API,例如,WebWorker API: + +``` +const myWorker = new Worker('worker.js'); + +fromEventPattern( + handler => { myWorker.onmessage = handler }, + handler => { myWorker.onmessage = undefined } +) +.subscribe(); +``` + +``` +// 结果 +// workerMessage ... +``` + +#### bindCallback + +它和 fromEventPattern 相似,但它能用于单个值。就在回调函数被调用时,流就结束了。用法当然也不一样 —— 你可以用 bindCallBack 封装函数,然后它就会在调用时魔术般的返回一个流: + +``` +function foo(value, callback) { + callback(value); +} + +// 没有流 +foo(1, console.log); //prints 1 in the console + +// 有流 +const reactiveFoo = bindCallback(foo); +// 当我们调用 reactiveFoo 时,它返回一个 observable 对象 + +reactiveFoo(1) + .subscribe(console.log); // 在控制台打印 1 +``` + +``` +// 结果 +// 1 | +``` + +#### websocket + +是的,你完全可以创建一个 websocket 连接然后把它暴露给流: + +``` +import { webSocket } from 'rxjs/webSocket'; + +let socket$ = webSocket('ws://localhost:8081'); + +// 接收消息 +socket$.subscribe( + (msg) => console.log('message received: ' + msg), + (err) => console.log(err), + () => console.log('complete') * ); + +// 发送消息 +socket$.next(JSON.stringify({ op: 'hello' })); +``` + +把 websocket 功能添加到你的应用中真的很简单。_websocket_ 创建一个 subject。这意味着你可以订阅它,通过调用 `next` 来获得消息和发送消息。 + +#### ajax + +如你所知:类似于 websocket,提供 AJAX 查询的功能。你可能用了一个带有 AJAX 功能的库或者框架。或者你没有用,那么我建议使用 fetch(或者必要的话用 polyfill),把返回的 promise 封装到一个 observable 对象中(参考稍后会讲到的 `defer` 函数)。 + +### 定制流 + +有时候已有的函数用起来并不是足够灵活。或者你需要对订阅有更强的控制。 + +#### 主题(`Subject`) + +`Subject` 是一个特殊的对象,它使得你的能够把数据发送到流中,并且能够控制数据。`Subject` 本身就是一个可观察对象,但如果你想要把流暴露给其它代码,建议你使用 `asObservable` 方法。这样你就不能意外调用原始方法。 + +``` +const subject = new Subject(); +const observable = subject.asObservable(); + +observable.subscribe(); + +subject.next(1); +subject.next(2); +subject.complete(); +``` + +``` +// 结果 +// 1 2 | +``` + +注意在订阅前发送的值将会“丢失”: + +``` +const subject = new Subject(); +const observable = subject.asObservable(); + +subject.next(1); + +observable.subscribe(console.log); + +subject.next(2); +subject.complete(); +``` + +``` +// 结果 +// 2 +``` + +除了常规的 `Subject`,RxJS 还提供了三种特殊的版本。 + +`AsyncSubject` 在结束后只发送最后的一个值。 + +``` +const subject = new AsyncSubject(); +const observable = subject.asObservable(); + +observable.subscribe(console.log); + +subject.next(1); +subject.next(2); +subject.complete(); +``` + +``` +// 输出 +// 2 +``` + +`BehaviorSubject` 使得你能够提供一个(默认的)值,如果当前没有其它值发送的话,这个值会被发送给每个订阅者。否则订阅者收到最后一个发送的值。 + +``` +const subject = new BehaviorSubject(1); +const observable = subject.asObservable(); + +const subscription1 = observable.subscribe(console.log); + +subject.next(2); +subscription1.unsubscribe(); +``` + +``` +// 输出 +// 1 +// 2 +``` + +``` +const subscription2 = observable.subscribe(console.log); + +// 输出 +// 2 +``` + +`ReplaySubject` 存储一定数量、或一定时间或所有的发送过的值。所有新的订阅者将会获得所有存储了的值。 + +``` +const subject = new ReplaySubject(); +const observable = subject.asObservable(); + +subject.next(1); + +observable.subscribe(console.log); + +subject.next(2); +subject.complete(); +``` + +``` +// 输出 +// 1 +// 2 +``` + +你可以在 [ReactiveX 文档][10](它提供了一些其它的连接) 里面找到更多关于 `Subject` 的信息。[Ben Lesh][11] 在 [On The Subject Of Subjects][12] 上面提供了一些关于 `Subject` 的理解,[Nicholas Jamieson][13] 在 [in RxJS: Understanding Subjects][14] 上也提供了一些理解。 + +#### 可观察对象 + +你可以简单地用 new 操作符创建一个可观察对象。通过你传入的函数,你可以控制流,只要有人订阅了或者它接收到一个可以当成 `Subject` 使用的观察者,这个函数就会被调用,比如,调用 `next`、`complet` 和 `error`。 + +让我们回顾一下列表示例: + +``` +const myList = new List(); +myList.add(1); +myList.add(3); + +new Observable(observer => { + for (let i = 0; i { + // 流式化 + + return () => { + //clean up + }; +}) +.subscribe(); +``` + +#### 继承可观察对象 + +在有可用的操作符前,这是一种实现自定义操作符的方式。RxJS 在内部扩展了 _可观察对象_ 。`Subject` 就是一个例子,另一个是 `publisher` 操作符。它返回一个 `ConnectableObservable` 对象,该对象提供额外的方法 `connect`。 + +#### 实现 `Subscribable` 接口 + +有时候你已经用一个对象来保存状态,并且能够发送值。如果你实现了 `Subscribable` 接口,你可以把它转换成一个可观察对象。`Subscribable` 接口中只有一个 `subscribe` 方法。 + +``` +interface Subscribable { subscribe(observerOrNext?: PartialObserver | ((value: T) => void), error?: (error: any) => void, complete?: () => void): Unsubscribable} +``` + +### 结合和选择现有的流 + +知道怎么创建一个独立的流还不够。有时候你有好几个流但其实只需要一个。有些函数也可作为操作符,所以我不打算在这里深入展开。推荐看看 [Max NgWizard K][16] 所写的一篇 [文章][15],它还包含一些有趣的动画。 + +还有一个建议:你可以通过拖拽元素的方式交互式的使用结合操作,参考 [RxMarbles][17]。 + +#### ObservableInput 类型 + +期望接收流的操作符和函数通常不单独和可观察对象一起工作。相反,它们实际上期望的参数类型是 ObservableInput,定义如下: + +``` +type ObservableInput = SubscribableOrPromise | ArrayLike | Iterable; +``` + +这意味着你可以传递一个 promises 或者数组却不需要事先把他们转换成可观察对象。 + +#### defer + +主要的目的是把一个 observable 对象的创建延迟(`defer`)到有人想要订阅的时间。在以下情况,这很有用: + +* 创建可观察对象的开销较大 +* 你想要给每个订阅者新的可观察对象 +* 你想要在订阅时候选择不同的可观察对象 +* 有些代码必须在订阅之后执行 + +最后一点包含了一个并不起眼的用例:Promises(`defer` 也可以返回一个 promise 对象)。看看这个用到了 fetch API 的例子: + +``` +function getUser(id) { + console.log("fetching data"); + return fetch(`https://server/user/${id}`); +} + +const userPromise = getUser(1); +console.log("I don't want that request now"); + +// 其它地方 +userPromise.then(response => console.log("done"); +``` + +``` +// 输出 +// fetching data +// I don't want that request now +// done +``` + +只要流在你订阅的时候执行了,promise 就会立即执行。我们调用 `getUser` 的瞬间,就发送了一个请求,哪怕我们这个时候不想发送请求。当然,我们可以使用 `from` 来把一个 promise 对象转换成可观察对象,但我们传递的 promise 对象已经创建或执行了。`defer` 让我们能够等到订阅才发送这个请求: + +``` +const user$ = defer(() => getUser(1)); + +console.log("I don't want that request now"); + +// 其它地方 +user$.subscribe(response => console.log("done"); +``` + +``` +// 输出 +// I don't want that request now +// fetching data +// done +``` + +#### iif + + `iif` 包含了一个关于 `defer` 的特殊用例:在订阅时选择两个流中的一个: + +``` +iif( + () => new Date().getHours() < 12, + of("AM"), + of("PM") +) +.subscribe(); +``` + +``` +// 结果 +// AM before noon, PM afterwards +``` + +引用该文档: + +> 实际上 [iif][3] 能够轻松地用 [defer][4] 实现,它仅仅是出于方便和可读性的目的。 + +#### onErrorResumeNext + +开启第一个流并且在失败的时候继续进行下一个流。错误被忽略掉。 + +``` +const stream1$ = of(1, 2).pipe( + tap(i => { if(i>1) throw 'error'}) //fail after first element +); + +const stream2$ = of(3,4); + +onErrorResumeNext(stream1$, stream2$) + .subscribe(console.log); +``` + +``` +// 结果 +// 1 3 4 | +``` + +如果你有多个 web 服务,这就很有用了。万一主服务器开启失败,那么备份的服务就能自动调用。 + +#### forkJoin + +它让流并行运行,当流结束时发送存在数组中的最后的值。由于每个流只有最后一个值被发送,它一般用在只发送一个元素的流的情况,就像 HTTP 请求。你让请求并行运行,在所有流收到响应时执行某些任务。 + +``` +function handleResponses([user, account]) { + // 执行某些任务 +} + +forkJoin( + fetch("https://server/user/1"), + fetch("https://server/account/1") +) +.subscribe(handleResponses); +``` + +#### merge / concat + +发送每一个从可观察对象源中发出的值。 + +`merge` 接收一个参数,让你定义有多少流能被同时订阅。默认是无限制的。设为 1 就意味着监听一个源流,在它结束的时候订阅下一个。由于这是一个常见的场景,RxJS 为你提供了一个显示的函数:`concat`。 + +``` +merge( + interval(1000).pipe(mapTo("Stream 1"), take(2)), + interval(1200).pipe(mapTo("Stream 2"), take(2)), + timer(0, 1000).pipe(mapTo("Stream 3"), take(2)), + 2 //two concurrent streams +) +.subscribe(); + +// 只订阅流 1 和流 2 + +// 输出 +// Stream 1 -> after 1000ms +// Stream 2 -> after 1200ms +// Stream 1 -> after 2000ms + +// 流 1 结束后,开始订阅流 3 + +// 输出 +// Stream 3 -> after 0 ms +// Stream 2 -> after 400 ms (2400ms from beginning) +// Stream 3 -> after 1000ms + +merge( + interval(1000).pipe(mapTo("Stream 1"), take(2)), + interval(1200).pipe(mapTo("Stream 2"), take(2)) + 1 +) +// 等效于 +concat( + interval(1000).pipe(mapTo("Stream 1"), take(2)), + interval(1200).pipe(mapTo("Stream 2"), take(2)) +) + +// 输出 +// Stream 1 -> after 1000ms +// Stream 1 -> after 2000ms +// Stream 2 -> after 3200ms +// Stream 2 -> after 4400ms +``` + +#### zip / combineLatest + +`merge` 和 `concat` 一个接一个的发送所有从源流中读到的值,而 `zip` 和 `combineLatest` 是把每个流中的一个值结合起来一起发送。`zip` 结合所有源流中发送的第一个值。如果流的内容相关联,那么这就很有用。 + +``` +zip( + interval(1000), + interval(1200), +) +.subscribe(); +``` + +``` +// 结果 +// [0, 0] [1, 1] [2, 2] ... +``` + +`combineLatest` 与之类似,但结合的是源流中发送的最后一个值。直到所有源流至少发送一个值之后才会触发事件。这之后每次源流发送一个值,它都会把这个值与其他流发送的最后一个值结合起来。 + +``` +combineLatest( + interval(1000), + interval(1200), +) +.subscribe(); +``` + +``` +// 结果 +// [0, 0] [1, 0] [1, 1] [2, 1] ... +``` + +两个函数都让允许传递一个选择器函数,把元素结合成其它对象而不是数组: + +``` +zip( + interval(1000), + interval(1200), + (e1, e2) -> e1 + e2 +) +.subscribe(); +``` + +``` +// 结果 +// 0 2 4 6 ... +``` + +#### race + +选择第一个发送数据的流。产生的流基本是最快的。 + +``` +race( + interval(1000), + of("foo") +) +.subscribe(); +``` + +``` +// 结果 +// foo | +``` + +由于 `of` 立即产生一个值,因此它是最快的流,然而这个流就被选中了。 + +### 总结 + +已经有很多创建可观察对象的方式了。如果你想要创造响应式的 API 或者想用响应式的 API 结合传统 API,那么了解这些方法很重要。 + +我已经向你展示了所有可用的方法,但它们其实还有很多内容可以讲。如果你想更加深入地了解,我极力推荐你查阅 [文档][20] 或者阅读相关文章。 + +[RxViz][21] 是另一种值得了解的有意思的方式。你编写 RxJS 代码,产生的流可以用图形或动画进行显示。 + +-------------------------------------------------------------------------------- + +via: https://blog.angularindepth.com/the-extensive-guide-to-creating-streams-in-rxjs-aaa02baaff9a + +作者:[Oliver Flaggl][a] +译者:[BriFuture](https://github.com/BriFuture) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://blog.angularindepth.com/@abetteroliver +[1]:https://rxjs-dev.firebaseapp.com/api/index/Subscribable +[2]:https://rxjs-dev.firebaseapp.com/api/index/Subscribable#subscribe +[3]:https://rxjs-dev.firebaseapp.com/api/index/iif +[4]:https://rxjs-dev.firebaseapp.com/api/index/defer +[5]:https://itnext.io/concurrency-and-asynchronous-behavior-with-rxjs-11b0c4b22597 +[6]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols +[7]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function* +[8]:https://medium.com/@benlesh/rxjs-observable-interop-with-promises-and-async-await-bebb05306875 +[9]:https://medium.com/@benlesh +[10]:http://reactivex.io/documentation/subject.html +[11]:https://medium.com/@benlesh +[12]:https://medium.com/@benlesh/on-the-subject-of-subjects-in-rxjs-2b08b7198b93 +[13]:https://medium.com/@cartant +[14]:https://blog.angularindepth.com/rxjs-understanding-subjects-5c585188c3e1 +[15]:https://blog.angularindepth.com/learn-to-combine-rxjs-sequences-with-super-intuitive-interactive-diagrams-20fce8e6511 +[16]:https://medium.com/@maximus.koretskyi +[17]:http://rxmarbles.com/#merge +[18]:https://rxjs-dev.firebaseapp.com/api/index/ObservableInput +[19]:https://rxjs-dev.firebaseapp.com/api/index/SubscribableOrPromise +[20]:http://reactivex.io/documentation/operators.html#creating +[21]:https://rxviz.com/ diff --git a/sources/tech/20170829 How To Set Up PF Firewall on FreeBSD to Protect a Web Server.md b/published/20170829 How To Set Up PF Firewall on FreeBSD to Protect a Web Server.md similarity index 69% rename from sources/tech/20170829 How To Set Up PF Firewall on FreeBSD to Protect a Web Server.md rename to published/20170829 How To Set Up PF Firewall on FreeBSD to Protect a Web Server.md index 45ce0c0a7a..c14e204ebd 100644 --- a/sources/tech/20170829 How To Set Up PF Firewall on FreeBSD to Protect a Web Server.md +++ b/published/20170829 How To Set Up PF Firewall on FreeBSD to Protect a Web Server.md @@ -1,85 +1,86 @@ -How To Set Up PF Firewall on FreeBSD to Protect a Web Server +如何在 FreeBSD 上设置 PF 防火墙来保护 Web 服务器 ====== -I am a new FreeBSD server user and moved from netfilter on Linux. How do I setup a firewall with PF on FreeBSD server to protect a web server with single public IP address and interface? +[![How To Set Up a Firewall with PF on FreeBSD to Protect a Web Server][1]][1] +我是从 Linux 迁移过来的 FreeBSD 新用户,Linux 中使用的是 netfilter 防火墙框架(LCTT 译注:netfilter 是由 Rusty Russell 提出的 Linux 2.4 内核防火墙框架)。那么在 FreeBSD 上,我该如何设置 PF 防火墙,来保护只有一个公共 IP 地址和端口的 web 服务器呢? -PF is an acronym for packet filter. It was created for OpenBSD but has been ported to FreeBSD and other operating systems. It is a stateful packet filtering engine. This tutorial will show you how to set up a firewall with PF on FreeBSD 10.x and 11.x server to protect your web server. +PF 是包过滤器packet filter的简称。它是为 OpenBSD 开发的,但是已经被移植到了 FreeBSD 以及其它操作系统上。PF 是一个包状态过滤引擎。在这篇教程中,我将向你展示如何在 FreeBSD 10.x 以及 11.x 中设置 PF 防火墙,从而来保护 web 服务器。 +### 第一步:开启 PF 防火墙 -## Step 1 - Turn on PF firewall +你需要把下面这几行内容添加到文件 `/etc/rc.conf` 文件中: -You need to add the following three lines to /etc/rc.conf file: ``` # echo 'pf_enable="YES"' >> /etc/rc.conf # echo 'pf_rules="/usr/local/etc/pf.conf"' >> /etc/rc.conf # echo 'pflog_enable="YES"' >> /etc/rc.conf # echo 'pflog_logfile="/var/log/pflog"' >> /etc/rc.conf ``` -Where, - 1. **pf_enable="YES"** - Turn on PF service. - 2. **pf_rules="/usr/local/etc/pf.conf"** - Read PF rules from this file. - 3. **pflog_enable="YES"** - Turn on logging support for PF. - 4. **pflog_logfile="/var/log/pflog"** - File where pflogd should store the logfile i.e. store logs in /var/log/pflog file. +在这里: + 1. `pf_enable="YES"` - 开启 PF 服务 + 2. `pf_rules="/usr/local/etc/pf.conf"` - 从文件 `/usr/local/etc/pf.conf` 中读取 PF 规则 + 3. `pflog_enable="YES"` - 为 PF 服务打开日志支持 + 4. `pflog_logfile="/var/log/pflog"` - 存储日志的文件,即日志存于文件 `/var/log/pflog` 中 +### 第二步:在 `/usr/local/etc/pf.conf` 文件中创建防火墙规则 -[![How To Set Up a Firewall with PF on FreeBSD to Protect a Web Server][1]][1] +输入下面这个命令打开文件(超级用户模式下): -## Step 2 - Creating firewall rules in /usr/local/etc/pf.conf - -Type the following command: ``` # vi /usr/local/etc/pf.conf ``` -Append the following PF rulesets : + +在文件中添加下面这些 PF 规则集: + ``` # vim: set ft=pf # /usr/local/etc/pf.conf -## Set your public interface ## +## 设置公共端口 ## ext_if="vtnet0" -## Set your server public IP address ## +## 设置服务器公共 IP 地址 ## ext_if_ip="172.xxx.yyy.zzz" -## Set and drop these IP ranges on public interface ## +## 设置并删除下面这些公共端口上的 IP 范围 ## martians = "{ 127.0.0.0/8, 192.168.0.0/16, 172.16.0.0/12, \ 10.0.0.0/8, 169.254.0.0/16, 192.0.2.0/24, \ 0.0.0.0/8, 240.0.0.0/4 }" -## Set http(80)/https (443) port here ## +## 设置 http(80)/https (443) 端口 ## webports = "{http, https}" -## enable these services ## +## 启用下面这些服务 ## int_tcp_services = "{domain, ntp, smtp, www, https, ftp, ssh}" int_udp_services = "{domain, ntp}" -## Skip loop back interface - Skip all PF processing on interface ## +## 跳过回环端口 - 跳过端口上的所有 PF 处理 ## set skip on lo -## Sets the interface for which PF should gather statistics such as bytes in/out and packets passed/blocked ## +## 设置 PF 应该统计的端口信息,如发送/接收字节数,通过/禁止的包的数目 ## set loginterface $ext_if -## Set default policy ## +## 设置默认策略 ## block return in log all block out all -# Deal with attacks based on incorrect handling of packet fragments +# 基于 IP 分片的错误处理来防御攻击 scrub in all -# Drop all Non-Routable Addresses +# 删除所有不可达路由地址 block drop in quick on $ext_if from $martians to any block drop out quick on $ext_if from any to $martians -## Blocking spoofed packets +## 禁止欺骗包 antispoof quick for $ext_if -# Open SSH port which is listening on port 22 from VPN 139.xx.yy.zz Ip only -# I do not allow or accept ssh traffic from ALL for security reasons +# 打开 SSH 端口,SSH 服务仅从 VPN IP 139.xx.yy.zz 监听 22 号端口 +# 出于安全原因,我不允许/接收 SSH 流量 pass in quick on $ext_if inet proto tcp from 139.xxx.yyy.zzz to $ext_if_ip port = ssh flags S/SA keep state label "USER_RULE: Allow SSH from 139.xxx.yyy.zzz" -## Use the following rule to enable ssh for ALL users from any IP address # +## 使用下面这些规则来为所有来自任何 IP 地址的用户开启 SSH 服务 # ## pass in inet proto tcp to $ext_if port ssh ### [ OR ] ### ## pass in inet proto tcp to $ext_if port 22 @@ -90,44 +91,67 @@ pass inet proto icmp icmp-type echoreq # All access to our Nginx/Apache/Lighttpd Webserver ports pass proto tcp from any to $ext_if port $webports -# Allow essential outgoing traffic +# 允许重要的发送流量 pass out quick on $ext_if proto tcp to any port $int_tcp_services pass out quick on $ext_if proto udp to any port $int_udp_services -# Add custom rules below +# 在下面添加自定义规则 ``` -Save and close the file. PR [welcome here to improve rulesets][2]. To check for syntax error, run: -`# service pf check` -OR -`/etc/rc.d/pf check` -OR -`# pfctl -n -f /usr/local/etc/pf.conf ` +保存并关闭文件。欢迎来参考我的[规则集][2]。如果要检查语法错误,可以运行: -## Step 3 - Start PF firewall +``` +# service pf check +``` -The commands are as follows. Be careful you might be disconnected from your server over ssh based session: +或 -### Start PF +``` +/etc/rc.d/pf check +``` -`# service pf start` +或 -### Stop PF +``` +# pfctl -n -f /usr/local/etc/pf.conf +``` -`# service pf stop` +### 第三步:开始运行 PF 防火墙 -### Check PF for syntax error +命令如下。请小心,如果是基于 SSH 的会话,你可能会和服务器断开连接。 -`# service pf check` +#### 开启 PF 防火墙: -### Restart PF +``` +# service pf start +``` -`# service pf restart` +#### 停用 PF 防火墙: -### See PF status +``` +# service pf stop +``` + +#### 检查语法错误: + +``` +# service pf check +``` + +#### 重启服务: + +``` +# service pf restart +``` + +#### 查看 PF 状态: + +``` +# service pf status +``` + +示例输出: -`# service pf status` -Sample outputs: ``` Status: Enabled for 0 days 00:02:18 Debug: Urgent @@ -165,24 +189,28 @@ Counters map-failed 0 0.0/s ``` +#### 开启/关闭/重启 pflog 服务的命令 -### Command to start/stop/restart pflog service +输入下面这些命令: -Type the following commands: ``` # service pflog start # service pflog stop # service pflog restart ``` -## Step 4 - A quick introduction to pfctl command +### 第四步:`pfctl` 命令的简单介绍 -You need to use the pfctl command to see PF ruleset and parameter configuration including status information from the packet filter. Let us see all common commands: +你需要使用 `pfctl` 命令来查看 PF 规则集和参数配置,包括来自包过滤器packet filter的状态信息。让我们来看一下所有常见命令: -### Show PF rules information +#### 显示 PF 规则信息 + +``` +# pfctl -s rules +``` + +示例输出: -`# pfctl -s rules` -Sample outputs: ``` block return in log all block drop out all @@ -201,15 +229,19 @@ pass out quick on vtnet0 proto udp from any to any port = domain keep state pass out quick on vtnet0 proto udp from any to any port = ntp keep state ``` -#### Show verbose output for each rule +#### 显示每条规则的详细内容 -`# pfctl -v -s rules` +``` +# pfctl -v -s rules +``` -#### Add rule numbers with verbose output for each rule +在每条规则的详细输出中添加规则编号: -`# pfctl -vvsr show` +``` +# pfctl -vvsr show +``` -#### Show state +#### 显示状态信息 ``` # pfctl -s state @@ -217,18 +249,26 @@ pass out quick on vtnet0 proto udp from any to any port = ntp keep state # pfctl -s state | grep 'something' ``` -### How to disable PF from the CLI +#### 如何在命令行中禁止 PF 服务 -`# pfctl -d ` +``` +# pfctl -d +``` -### How to enable PF from the CLI +#### 如何在命令行中启用 PF 服务 -`# pfctl -e ` +``` +# pfctl -e +``` -### How to flush ALL PF rules/nat/tables from the CLI +#### 如何在命令行中刷新 PF 规则/NAT/路由表 + +``` +# pfctl -F all +``` + +示例输出: -`# pfctl -F all` -Sample outputs: ``` rules cleared nat cleared @@ -239,27 +279,40 @@ pf: statistics cleared pf: interface flags reset ``` -#### How to flush only the PF RULES from the CLI +#### 如何在命令行中仅刷新 PF 规则 -`# pfctl -F rules ` +``` +# pfctl -F rules +``` -#### How to flush only queue's from the CLI +#### 如何在命令行中仅刷新队列 -`# pfctl -F queue ` +``` +# pfctl -F queue +``` -#### How to flush all stats that are not part of any rule from the CLI +#### 如何在命令行中刷新统计信息(它不是任何规则的一部分) -`# pfctl -F info` +``` +# pfctl -F info +``` -#### How to clear all counters from the CLI +#### 如何在命令行中清除所有计数器 -`# pfctl -z clear ` +``` +# pfctl -z clear +``` -## Step 5 - See PF log +### 第五步:查看 PF 日志 + +PF 日志是二进制格式的。使用下面这一命令来查看: + +``` +# tcpdump -n -e -ttt -r /var/log/pflog +``` + +示例输出: -PF logs are in binary format. To see them type: -`# tcpdump -n -e -ttt -r /var/log/pflog` -Sample outputs: ``` Aug 29 15:41:11.757829 rule 0/(match) block in on vio0: 86.47.225.151.55806 > 45.FOO.BAR.IP.23: S 757158343:757158343(0) win 52206 [tos 0x28] Aug 29 15:41:44.193309 rule 0/(match) block in on vio0: 5.196.83.88.25461 > 45.FOO.BAR.IP.26941: S 2224505792:2224505792(0) ack 4252565505 win 17520 (DF) [tos 0x24] @@ -295,31 +348,36 @@ Aug 29 15:55:07.001743 rule 0/(match) block in on vio0: 190.83.174.214.58863 > 4 Aug 29 15:55:51.269549 rule 0/(match) block in on vio0: 142.217.201.69.26112 > 45.FOO.BAR.IP.22: S 757158343:757158343(0) win 22840 Aug 29 15:58:41.346028 rule 0/(match) block in on vio0: 169.1.29.111.29765 > 45.FOO.BAR.IP.23: S 757158343:757158343(0) win 28509 Aug 29 15:59:11.575927 rule 0/(match) block in on vio0: 187.160.235.162.32427 > 45.FOO.BAR.IP.5358: S 22445:22445(0) win 14600 [tos 0x28] -Aug 29 15:59:37.826598 rule 0/(match) block in on vio0: 94.74.81.97.54656 > 45.FOO.BAR.IP.3128: S 2720157526:2720157526(0) win 1024 [tos 0x28] +Aug 29 15:59:37.826598 rule 0/(match) block in on vio0: 94.74.81.97.54656 > 45.FOO.BAR.IP.3128: S 2720157526:2720157526(0) win 1024 [tos 0x28]stateful Aug 29 15:59:37.991171 rule 0/(match) block in on vio0: 94.74.81.97.54656 > 45.FOO.BAR.IP.3128: R 2720157527:2720157527(0) win 1200 [tos 0x28] Aug 29 16:01:36.990050 rule 0/(match) block in on vio0: 182.18.8.28.23299 > 45.FOO.BAR.IP.445: S 1510146048:1510146048(0) win 16384 ``` -To see live log run: -`# tcpdump -n -e -ttt -i pflog0` -For more info the [PF FAQ][3], [FreeBSD HANDBOOK][4] and the following man pages: +如果要查看实时日志,可以运行: + +``` +# tcpdump -n -e -ttt -i pflog0 +``` + +如果你想了解更多信息,可以访问 [PF FAQ][3] 和 [FreeBSD HANDBOOK][4] 以及下面这些 man 页面: + ``` # man tcpdump # man pfctl # man pf ``` -## about the author: +### 关于作者 -The author is the creator of nixCraft and a seasoned sysadmin and a trainer for the Linux operating system/Unix shell scripting. He has worked with global clients and in various industries, including IT, education, defense and space research, and the nonprofit sector. Follow him on [Twitter][5], [Facebook][6], [Google+][7]. +我是 nixCraft 的创立者,一个经验丰富的系统管理员,同时也是一位 Linux 操作系统/Unix shell 脚本培训师。我在不同的行业与全球客户工作过,包括 IT、教育、国防和空间研究、以及非营利组织。你可以在 [Twitter][5]、[Facebook][6] 或 [Google+][7] 上面关注我。 -------------------------------------------------------------------------------- via: https://www.cyberciti.biz/faq/how-to-set-up-a-firewall-with-pf-on-freebsd-to-protect-a-web-server/ 作者:[Vivek Gite][a] -译者:[译者ID](https://github.com/译者ID) -校对:[校对者ID](https://github.com/校对者ID) +译者:[ucasFL](https://github.com/ucasFL) +校对:[wxy](https://github.com/wxy) 本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 diff --git a/published/20171003 Trash-Cli - A Command Line Interface For Trashcan On Linux.md b/published/20171003 Trash-Cli - A Command Line Interface For Trashcan On Linux.md new file mode 100644 index 0000000000..b6bb716ece --- /dev/null +++ b/published/20171003 Trash-Cli - A Command Line Interface For Trashcan On Linux.md @@ -0,0 +1,144 @@ +Trash-Cli:Linux 上的命令行回收站工具 +====== + +相信每个人都对回收站trashcan很熟悉,因为无论是对 Linux 用户,还是 Windows 用户,或者 Mac 用户来说,它都很常见。当你删除一个文件或目录的时候,该文件或目录会被移动到回收站中。 + +需要注意的是,当把文件移动到回收站以后,文件系统空间并没有被释放,除非把回收站清空。 + +如果不想永久删除文件的话(清空回收站),可以利用回收站临时存储被删除了的文件,从而在必要的时候能够帮助我们恢复删除了的文件。 + +但是,如果在命令行使用 `rm` 命令进行删除操作,那么你是不可能在回收站中找到任何被删除了的文件或目录的。所以,在执行 `rm` 命令前请一定要三思。如果你犯了错误(执行了 `rm` 命令),那么文件就被永久删除了,无法再恢复回来,因为存储在磁盘上的元数据已经不在了。 + +根据 [freedesktop.org 规范][1],垃圾trash是由桌面管理器比如 GNOME、KDE 和 XFCE 等提供的一个特性。当通过文件管理器删除一个文件或目录的时候,该文件或目录将会成为垃圾trash,然后被移动到回收站中,回收站对应的目录是 `$HOME/.local/share/Trash` 。 + +回收站目录包含两个子目录:`files` 和 `info` 。`files` 目录存储实际被删除了的文件和目录,`info` 目录包含被删除了的文件和目录的信息,比如文件路径、删除日期和时间,每个文件单独存储。 + +你可能会问,既然已经有了图形用户界面GUI的回收站,为什么还需要命令行工具呢?因为对于大多数使用 *NIX 系统的家伙(包括我)来说,即使使用的是基于图形用户界面的系统,也更喜欢使用命令行而不是图形用户界面。所以,如果有人在寻找一个命令行回收站工具,那么这儿有一个不错的选择。 + +### Trash-Cli 是什么 + +[trash-cli][2] 是一个命令行回收站工具,并且符合 FreeDesktop.org 的垃圾trash规范。它能够存储每一个垃圾文件的名字、原始路径、删除日期和权限。 + +### 如何在 Linux 上安装 Trash-Cli + +绝大多数的 Linux 发行版官方仓库都提供了 Trash-Cli 的安装包,所以你可以运行下面这些命令来安装。 + +对于 Debian/Ubuntu 用户,使用 [apt-get][3] 或 [apt][4] 命令来安装 Trash-Cli: + +``` +$ sudo apt install trash-cli +``` + +对于 RHEL/CentOS 用户,使用 [yum][5] 命令来安装 Trash-Cli: + +``` +$ sudo yum install trash-cli +``` + +对于 Fedora 用户,使用 [dnf][6] 命令来安装 Trash-Cli: + +``` +$ sudo dnf install trash-cli +``` + +对于 Arch Linux 用户,使用 [pacman][7] 命令来安装 Trash-Cli: + +``` +$ sudo pacman -S trash-cli +``` + +对于 openSUSE 用户,使用 [zypper][8] 命令来安装 Trash-Cli: + +``` +$ sudo zypper in trash-cli +``` + +如果你的发行版中没有提供 Trash-Cli 的安装包,那么你也可以使用 `pip` 来安装。为了能够安装 python 包,你的系统中应该会有 `pip` 包管理器。 + +``` +$ sudo pip install trash-cli +Collecting trash-cli + Downloading trash-cli-0.17.1.14.tar.gz +Installing collected packages: trash-cli + Running setup.py bdist_wheel for trash-cli ... done +Successfully installed trash-cli-0.17.1.14 +``` + +### 如何使用 Trash-Cli + +Trash-Cli 的使用不难,因为它提供了一个很简单的语法。Trash-Cli 提供了下面这些命令: + + * `trash-put`: 删除文件和目录(仅放入回收站中) + * `trash-list` :列出被删除了的文件和目录 + * `trash-restore`:从回收站中恢复文件或目录 trash. + * `trash-rm`:删除回收站中的文件 + * `trash-empty`:清空回收站 + +下面,让我们通过一些例子来试验一下。 + +1) 删除文件和目录:在这个例子中,我们通过运行下面这个命令,将 `2g.txt` 这一文件和 `magi` 这一文件夹移动到回收站中。 + +``` +$ trash-put 2g.txt magi +``` + +和你在文件管理器中看到的一样。 + +2) 列出被删除了的文件和目录:为了查看被删除了的文件和目录,你需要运行下面这个命令。之后,你可以在输出中看到被删除文件和目录的详细信息,比如名字、删除日期和时间,以及文件路径。 + +``` +$ trash-list +2017-10-01 01:40:50 /home/magi/magi/2g.txt +2017-10-01 01:40:50 /home/magi/magi/magi +``` + +3) 从回收站中恢复文件或目录:任何时候,你都可以通过运行下面这个命令来恢复文件和目录。它将会询问你来选择你想要恢复的文件或目录。在这个例子中,我打算恢复 `2g.txt` 文件,所以我的选择是 `0` 。 + +``` +$ trash-restore + 0 2017-10-01 01:40:50 /home/magi/magi/2g.txt + 1 2017-10-01 01:40:50 /home/magi/magi/magi +What file to restore [0..1]: 0 +``` + +4) 从回收站中删除文件:如果你想删除回收站中的特定文件,那么可以运行下面这个命令。在这个例子中,我将删除 `magi` 目录。 + +``` +$ trash-rm magi +``` + +5)清空回收站:如果你想删除回收站中的所有文件和目录,可以运行下面这个命令。 + +``` +$ trash-empty +``` + +6)删除超过 X 天的垃圾文件:或者,你可以通过运行下面这个命令来删除回收站中超过 X 天的文件。在这个例子中,我将删除回收站中超过 `10` 天的项目。 + +``` +$ trash-empty 10 +``` + +Trash-Cli 可以工作的很好,但是如果你想尝试它的一些替代品,那么你也可以试一试 [gvfs-trash][9] 和 [autotrash][10] 。 + +-------------------------------------------------------------------------------- + +via: https://www.2daygeek.com/trash-cli-command-line-trashcan-linux-system/ + +作者:[2daygeek][a] +译者:[ucasFL](https://github.com/ucasFL) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.2daygeek.com/author/2daygeek/ +[1]:https://freedesktop.org/wiki/Specifications/trash-spec/ +[2]:https://github.com/andreafrancia/trash-cli +[3]:https://www.2daygeek.com/apt-get-apt-cache-command-examples-manage-packages-debian-ubuntu-systems/ +[4]:https://www.2daygeek.com/apt-command-examples-manage-packages-debian-ubuntu-systems/ +[5]:https://www.2daygeek.com/yum-command-examples-manage-packages-rhel-centos-systems/ +[6]:https://www.2daygeek.com/dnf-command-examples-manage-packages-fedora-system/ +[7]:https://www.2daygeek.com/pacman-command-examples-manage-packages-arch-linux-system/ +[8]:https://www.2daygeek.com/zypper-command-examples-manage-packages-opensuse-system/ +[9]:http://manpages.ubuntu.com/manpages/trusty/man1/gvfs-trash.1.html +[10]:https://github.com/bneijt/autotrash diff --git a/translated/tech/20171010 Operating a Kubernetes network.md b/published/20171010 Operating a Kubernetes network.md similarity index 83% rename from translated/tech/20171010 Operating a Kubernetes network.md rename to published/20171010 Operating a Kubernetes network.md index ef7bb6b888..74c061d675 100644 --- a/translated/tech/20171010 Operating a Kubernetes network.md +++ b/published/20171010 Operating a Kubernetes network.md @@ -1,36 +1,30 @@ -运营一个 Kubernetes 网络 -============================================================ +Kubernetes 网络运维 +====== -最近我一直在研究 Kubernetes 网络。我注意到一件事情就是,虽然关于如何设置 Kubernetes 网络的文章很多,也写得很不错,但是却没有看到关于如何去运营 Kubernetes 网络的文章、以及如何完全确保它不会给你造成生产事故。 +最近我一直在研究 Kubernetes 网络。我注意到一件事情就是,虽然关于如何设置 Kubernetes 网络的文章很多,也写得很不错,但是却没有看到关于如何去运维 Kubernetes 网络的文章、以及如何完全确保它不会给你造成生产事故。 在本文中,我将尽力让你相信三件事情(我觉得这些都很合理 :)): * 避免生产系统网络中断非常重要 - -* 运营联网软件是很难的 - +* 运维联网软件是很难的 * 有关你的网络基础设施的重要变化值得深思熟虑,以及这种变化对可靠性的影响。虽然非常“牛x”的谷歌人常说“这是我们在谷歌正在用的”(谷歌工程师在 Kubernetes 上正做着很重大的工作!但是我认为重要的仍然是研究架构,并确保它对你的组织有意义)。 我肯定不是 Kubernetes 网络方面的专家,但是我在配置 Kubernetes 网络时遇到了一些问题,并且比以前更加了解 Kubernetes 网络了。 -### 运营联网软件是很难的 +### 运维联网软件是很难的 -在这里,我并不讨论有关运营物理网络的话题(对于它我不懂),而是讨论关于如何让像 DNS 服务、负载均衡以及代理这样的软件正常工作方面的内容。 +在这里,我并不讨论有关运维物理网络的话题(对于它我不懂),而是讨论关于如何让像 DNS 服务、负载均衡以及代理这样的软件正常工作方面的内容。 -我在一个负责很多网络基础设施的团队工作过一年时间,并且因此学到了一些运营网络基础设施的知识!(显然我还有很多的知识需要继续学习)在我们开始之前有三个整体看法: - -* 联网软件经常重度依赖 Linux 内核。因此除了正确配置软件之外,你还需要确保许多不同的系统控制(sysctl)配置正确,而一个错误配置的系统控制就很容易让你处于“一切都很好”和“到处都出问题”的差别中。 +我在一个负责很多网络基础设施的团队工作过一年时间,并且因此学到了一些运维网络基础设施的知识!(显然我还有很多的知识需要继续学习)在我们开始之前有三个整体看法: +* 联网软件经常重度依赖 Linux 内核。因此除了正确配置软件之外,你还需要确保许多不同的系统控制(`sysctl`)配置正确,而一个错误配置的系统控制就很容易让你处于“一切都很好”和“到处都出问题”的差别中。 * 联网需求会随时间而发生变化(比如,你的 DNS 查询或许比上一年多了五倍!或者你的 DNS 服务器突然开始返回 TCP 协议的 DNS 响应而不是 UDP 的,它们是完全不同的内核负载!)。这意味着之前正常工作的软件突然开始出现问题。 - * 修复一个生产网络的问题,你必须有足够的经验。(例如,看这篇 [由 Sophie Haskins 写的关于 kube-dns 问题调试的文章][1])我在网络调试方面比以前进步多了,但那也是我花费了大量时间研究 Linux 网络知识之后的事了。 -我距离成为一名网络运营专家还差得很远,但是我认为以下几点很重要: +我距离成为一名网络运维专家还差得很远,但是我认为以下几点很重要: 1. 对生产网络的基础设施做重要的更改是很难得的(因为它会产生巨大的混乱) - 2. 当你对网络基础设施做重大更改时,真的应该仔细考虑如果新网络基础设施失败该如何处理 - 3. 是否有很多人都能理解你的网络配置 切换到 Kubernetes 显然是个非常大的更改!因此,我们来讨论一下可能会导致错误的地方! @@ -39,86 +33,72 @@ 在本文中我们将要讨论的 Kubernetes 网络组件有: -* 网络覆盖后端(像 flannel/calico/weave 网络/romana) - +* 覆盖网络overlay network的后端(像 flannel/calico/weave 网络/romana) * `kube-dns` - * `kube-proxy` - * 入站控制器 / 负载均衡器 - * `kubelet` 如果你打算配置 HTTP 服务,或许这些你都会用到。这些组件中的大部分我都不会用到,但是我尽可能去理解它们,因此,本文将涉及它们有关的内容。 ### 最简化的方式:为所有容器使用宿主机网络 -我们从你能做到的最简单的东西开始。这并不能让你在 Kubernetes 中运行 HTTP 服务。我认为它是非常安全的,因为在这里面可以让你动的东西很少。 +让我们从你能做到的最简单的东西开始。这并不能让你在 Kubernetes 中运行 HTTP 服务。我认为它是非常安全的,因为在这里面可以让你动的东西很少。 如果你为所有容器使用宿主机网络,我认为需要你去做的全部事情仅有: 1. 配置 kubelet,以便于容器内部正确配置 DNS - 2. 没了,就这些! -如果你为每个 Pod 直接使用宿主机网络,那就不需要 kube-dns 或者 kube-proxy 了。你都不需要一个作为基础的覆盖网络。 +如果你为每个 pod 直接使用宿主机网络,那就不需要 kube-dns 或者 kube-proxy 了。你都不需要一个作为基础的覆盖网络。 这种配置方式中,你的 pod 们都可以连接到外部网络(同样的方式,你的宿主机上的任何进程都可以与外部网络对话),但外部网络不能连接到你的 pod 们。 这并不是最重要的(我认为大多数人想在 Kubernetes 中运行 HTTP 服务并与这些服务进行真实的通讯),但我认为有趣的是,从某种程度上来说,网络的复杂性并不是绝对需要的,并且有时候你不用这么复杂的网络就可以实现你的需要。如果可以的话,尽可能地避免让网络过于复杂。 -### 运营一个覆盖网络 +### 运维一个覆盖网络 我们将要讨论的第一个网络组件是有关覆盖网络的。Kubernetes 假设每个 pod 都有一个 IP 地址,这样你就可以与那个 pod 中的服务进行通讯了。我在说到“覆盖网络”这个词时,指的就是这个意思(“让你通过它的 IP 地址指向到 pod 的系统)。 所有其它的 Kubernetes 网络的东西都依赖正确工作的覆盖网络。更多关于它的内容,你可以读 [这里的 kubernetes 网络模型][10]。 -Kelsey Hightower 在 [kubernetes the hard way][11] 中描述的方式看起来似乎很好,但是,事实上它的作法在超过 50 个节点的 AWS 上是行不通的,因此,我不打算讨论它了。 +Kelsey Hightower 在 [kubernetes 艰难之路][11] 中描述的方式看起来似乎很好,但是,事实上它的作法在超过 50 个节点的 AWS 上是行不通的,因此,我不打算讨论它了。 有许多覆盖网络后端(calico、flannel、weaveworks、romana)并且规划非常混乱。就我的观点来看,我认为一个覆盖网络有 2 个职责: 1. 确保你的 pod 能够发送网络请求到外部的集群 - 2. 保持一个到子网络的稳定的节点映射,并且保持集群中每个节点都可以使用那个映射得以更新。当添加和删除节点时,能够做出正确的反应。 Okay! 因此!你的覆盖网络可能会出现的问题是什么呢? -* 覆盖网络负责设置 iptables 规则(最基本的是 `iptables -A -t nat POSTROUTING -s $SUBNET -j MASQUERADE`),以确保那个容器能够向 Kubernetes 之外发出网络请求。如果在这个规则上有错误,你的容器就不能连接到外部网络。这并不很难(它只是几条 iptables 规则而已),但是它非常重要。我发起了一个 [pull request][2],因为我想确保它有很好的弹性。 - -* 添加或者删除节点时可能会有错误。我们使用 `flannel hostgw` 后端,我们开始使用它的时候,节点删除 [尚未开始工作][3]。 - +* 覆盖网络负责设置 iptables 规则(最基本的是 `iptables -A -t nat POSTROUTING -s $SUBNET -j MASQUERADE`),以确保那个容器能够向 Kubernetes 之外发出网络请求。如果在这个规则上有错误,你的容器就不能连接到外部网络。这并不很难(它只是几条 iptables 规则而已),但是它非常重要。我发起了一个 [拉取请求][2],因为我想确保它有很好的弹性。 +* 添加或者删除节点时可能会有错误。我们使用 `flannel hostgw` 后端,我们开始使用它的时候,节点删除功能 [尚未开始工作][3]。 * 你的覆盖网络或许依赖一个分布式数据库(etcd)。如果那个数据库发生什么问题,这将导致覆盖网络发生问题。例如,[https://github.com/coreos/flannel/issues/610][4] 上说,如果在你的 `flannel etcd` 集群上丢失了数据,最后的结果将是在容器中网络连接会丢失。(现在这个问题已经被修复了) - * 你升级 Docker 以及其它东西导致的崩溃 - * 还有更多的其它的可能性! -我在这里主要讨论的是过去发生在 Flannel 中的问题,但是我并不是要承诺不去使用 Flannel —— 事实上我很喜欢 Flannel,因为我觉得它很简单(比如,类似 [vxlan 在后端这一块的部分][12] 只有 500 行代码),并且我觉得对我来说,通过代码来找出问题的根源成为了可能。并且很显然,它在不断地改进。他们在审查 `pull requests` 方面做的很好。 +我在这里主要讨论的是过去发生在 Flannel 中的问题,但是我并不是要承诺不去使用 Flannel —— 事实上我很喜欢 Flannel,因为我觉得它很简单(比如,类似 [vxlan 在后端这一块的部分][12] 只有 500 行代码),对我来说,通过代码来找出问题的根源成为了可能。并且很显然,它在不断地改进。他们在审查拉取请求方面做的很好。 -到目前为止,我运营覆盖网络的方法是: +到目前为止,我运维覆盖网络的方法是: * 学习它的工作原理的详细内容以及如何去调试它(比如,Flannel 用于创建路由的 hostgw 网络后端,因此,你只需要使用 `sudo ip route list` 命令去查看它是否正确即可) - * 如果需要的话,维护一个内部构建版本,这样打补丁比较容易 - * 有问题时,向上游贡献补丁 -我认为去遍历所有已合并的 PR 以及过去已修复的 bug 清单真的是非常有帮助的 —— 这需要花费一些时间,但这是得到一个其它人遇到的各种问题的清单的好方法。 +我认为去遍历所有已合并的拉取请求以及过去已修复的 bug 清单真的是非常有帮助的 —— 这需要花费一些时间,但这是得到一个其它人遇到的各种问题的清单的好方法。 -对其他人来说,他们的覆盖网络可能工作的很好,但是我并不能从中得到任何经验,并且我也曾听说过其他人报告类似的问题。如果你有一个类似配置的覆盖网络:a) 在 AWS 上并且 b) 在多于 50-100 节点上运行,我想知道你运营这样的一个网络有多大的把握。 +对其他人来说,他们的覆盖网络可能工作的很好,但是我并不能从中得到任何经验,并且我也曾听说过其他人报告类似的问题。如果你有一个类似配置的覆盖网络:a) 在 AWS 上并且 b) 在多于 50-100 节点上运行,我想知道你运维这样的一个网络有多大的把握。 -### 运营 kube-proxy 和 kube-dns? +### 运维 kube-proxy 和 kube-dns? -现在,我有一些关于运营覆盖网络的想法,我们来讨论一下。 +现在,我有一些关于运维覆盖网络的想法,我们来讨论一下。 -这个标题的最后面有一个问号,那是因为我并没有真的去运营过。在这里我还有更多的问题要问答。 +这个标题的最后面有一个问号,那是因为我并没有真的去运维过。在这里我还有更多的问题要问答。 这里的 Kubernetes 服务是如何工作的!一个服务是一群 pod 们,它们中的每个都有自己的 IP 地址(像 10.1.0.3、10.2.3.5、10.3.5.6 这样) 1. 每个 Kubernetes 服务有一个 IP 地址(像 10.23.1.2 这样) - 2. `kube-dns` 去解析 Kubernetes 服务 DNS 名字为 IP 地址(因此,my-svc.my-namespace.svc.cluster.local 可能映射到 10.23.1.2 上) - 3. `kube-proxy` 配置 `iptables` 规则是为了在它们之间随机进行均衡负载。Kube-proxy 也有一个用户空间的轮询负载均衡器,但是在我的印象中,他们并不推荐使用它。 因此,当你发出一个请求到 `my-svc.my-namespace.svc.cluster.local` 时,它将解析为 10.23.1.2,然后,在你本地主机上的 `iptables` 规则(由 kube-proxy 生成)将随机重定向到 10.1.0.3 或者 10.2.3.5 或者 10.3.5.6 中的一个上。 @@ -126,9 +106,7 @@ Okay! 因此!你的覆盖网络可能会出现的问题是什么呢? 在这个过程中我能想像出的可能出问题的地方: * `kube-dns` 配置错误 - * `kube-proxy` 挂了,以致于你的 `iptables` 规则没有得以更新 - * 维护大量的 `iptables` 规则相关的一些问题 我们来讨论一下 `iptables` 规则,因为创建大量的 `iptables` 规则是我以前从没有听过的事情! @@ -141,7 +119,6 @@ kube-proxy 像如下这样为每个目标主机创建一个 `iptables` 规则: -A KUBE-SVC-LI77LBOOMGYET5US -m comment --comment "default/showreadiness:showreadiness" -m statistic --mode random --probability 0.33332999982 -j KUBE-SEP-RKIFTWKKG3OHTTMI -A KUBE-SVC-LI77LBOOMGYET5US -m comment --comment "default/showreadiness:showreadiness" -m statistic --mode random --probability 0.50000000000 -j KUBE-SEP-CGDKBCNM24SZWCMS -A KUBE-SVC-LI77LBOOMGYET5US -m comment --comment "default/showreadiness:showreadiness" -j KUBE-SEP-RI4SRNQQXWSTGE2Y - ``` 因此,kube-proxy 创建了许多 `iptables` 规则。它们都是什么意思?它对我的网络有什么样的影响?这里有一个来自华为的非常好的演讲,它叫做 [支持 50,000 个服务的可伸缩 Kubernetes][14],它说如果在你的 Kubernetes 集群中有 5,000 服务,增加一个新规则,将需要 **11 分钟**。如果这种事情发生在真实的集群中,我认为这将是一件非常糟糕的事情。 @@ -152,19 +129,16 @@ kube-proxy 像如下这样为每个目标主机创建一个 `iptables` 规则: 但是,我觉得使用 HAProxy 更舒服!它能够用于去替换 kube-proxy!我用谷歌搜索了一下,然后发现了这个 [thread on kubernetes-sig-network][15],它说: -> kube-proxy 是很难用的,我们在生产系统中使用它近一年了,它在大部分的时间都表现的很好,但是,随着我们集群中的服务越来越多,我们发现它的排错和维护工作越来越难。在我们的团队中没有 iptables 方面的专家,我们只有 HAProxy&LVS 方面的专家,由于我们已经使用它们好几年了,因此我们决定使用一个中心化的 HAProxy 去替换分布式的代理。我觉得这可能会对在 Kubernetes 中使用 HAProxy 的其他人有用,因此,我们更新了这个项目,并将它开源:[https://github.com/AdoHe/kube2haproxy][5]。如果你发现它有用,你可以去看一看、试一试。 +> kube-proxy 是很难用的,我们在生产系统中使用它近一年了,它在大部分的时间都表现的很好,但是,随着我们集群中的服务越来越多,我们发现它的排错和维护工作越来越难。在我们的团队中没有 iptables 方面的专家,我们只有 HAProxy & LVS 方面的专家,由于我们已经使用它们好几年了,因此我们决定使用一个中心化的 HAProxy 去替换分布式的代理。我觉得这可能会对在 Kubernetes 中使用 HAProxy 的其他人有用,因此,我们更新了这个项目,并将它开源:[https://github.com/AdoHe/kube2haproxy][5]。如果你发现它有用,你可以去看一看、试一试。 因此,那是一个有趣的选择!我在这里确实没有答案,但是,有一些想法: * 负载均衡器是很复杂的 - * DNS 也很复杂 +* 如果你有运维某种类型的负载均衡器(比如 HAProxy)的经验,与其使用一个全新的负载均衡器(比如 kube-proxy),还不如做一些额外的工作去使用你熟悉的那个来替换,或许更有意义。 +* 我一直在考虑,我们希望在什么地方能够完全使用 kube-proxy 或者 kube-dns —— 我认为,最好是只在 Envoy 上投入,并且在负载均衡&服务发现上完全依赖 Envoy 来做。因此,你只需要将 Envoy 运维好就可以了。 -* 如果你有运营某种类型的负载均衡器(比如 HAProxy)的经验,与其使用一个全新的负载均衡器(比如 kube-proxy),还不如做一些额外的工作去使用你熟悉的那个来替换,或许更有意义。 - -* 我一直在考虑,我们希望在什么地方能够完全使用 kube-proxy 或者 kube-dns —— 我认为,最好是只在 Envoy 上投入,并且在负载均衡&服务发现上完全依赖 Envoy 来做。因此,你只需要将 Envoy 运营好就可以了。 - -正如你所看到的,我在关于如何运营 Kubernetes 中的内部代理方面的思路还是很混乱的,并且我也没有使用它们的太多经验。总体上来说,kube-proxy 和 kube-dns 还是很好的,也能够很好地工作,但是我仍然认为应该去考虑使用它们可能产生的一些问题(例如,”你不能有超出 5000 的 Kubernetes 服务“)。 +正如你所看到的,我在关于如何运维 Kubernetes 中的内部代理方面的思路还是很混乱的,并且我也没有使用它们的太多经验。总体上来说,kube-proxy 和 kube-dns 还是很好的,也能够很好地工作,但是我仍然认为应该去考虑使用它们可能产生的一些问题(例如,”你不能有超出 5000 的 Kubernetes 服务“)。 ### 入口 @@ -175,14 +149,12 @@ kube-proxy 像如下这样为每个目标主机创建一个 `iptables` 规则: 几个有用的链接,总结如下: * [Kubernetes 网络模型][6] - * GKE 网络是如何工作的:[https://www.youtube.com/watch?v=y2bhV81MfKQ][7] - * 上述的有关 `kube-proxy` 上性能的讨论:[https://www.youtube.com/watch?v=4-pawkiazEg][8] -### 我认为网络运营很重要 +### 我认为网络运维很重要 -我对 Kubernetes 的所有这些联网软件的感觉是,它们都仍然是非常新的,并且我并不能确定我们(作为一个社区)真的知道如何去把它们运营好。这让我作为一个操作者感到很焦虑,因为我真的想让我的网络运行的很好!:) 而且我觉得作为一个组织,运行你自己的 Kubernetes 集群需要相当大的投入,以确保你理解所有的代码片段,这样当它们出现问题时你可以去修复它们。这不是一件坏事,它只是一个事而已。 +我对 Kubernetes 的所有这些联网软件的感觉是,它们都仍然是非常新的,并且我并不能确定我们(作为一个社区)真的知道如何去把它们运维好。这让我作为一个操作者感到很焦虑,因为我真的想让我的网络运行的很好!:) 而且我觉得作为一个组织,运行你自己的 Kubernetes 集群需要相当大的投入,以确保你理解所有的代码片段,这样当它们出现问题时你可以去修复它们。这不是一件坏事,它只是一个事而已。 我现在的计划是,继续不断地学习关于它们都是如何工作的,以尽可能多地减少对我动过的那些部分的担忧。 @@ -192,9 +164,9 @@ kube-proxy 像如下这样为每个目标主机创建一个 `iptables` 规则: via: https://jvns.ca/blog/2017/10/10/operating-a-kubernetes-network/ -作者:[Julia Evans ][a] +作者:[Julia Evans][a] 译者:[qhwdw](https://github.com/qhwdw) -校对:[校对者ID](https://github.com/校对者ID) +校对:[wxy](https://github.com/wxy) 本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 diff --git a/published/20171124 How do groups work on Linux.md b/published/20171124 How do groups work on Linux.md new file mode 100644 index 0000000000..f9134ca619 --- /dev/null +++ b/published/20171124 How do groups work on Linux.md @@ -0,0 +1,132 @@ +“用户组”在 Linux 上到底是怎么工作的? +======== + +嗨!就在上周,我还自认为对 Linux 上的用户和组的工作机制了如指掌。我认为它们的关系是这样的: + +1. 每个进程都属于一个用户(比如用户 `julia`) +2. 当这个进程试图读取一个被某个组所拥有的文件时, Linux 会 + a. 先检查用户`julia` 是否有权限访问文件。(LCTT 译注:此处应该是指检查文件的所有者是否就是 `julia`) + b. 检查 `julia` 属于哪些组,并进一步检查在这些组里是否有某个组拥有这个文件或者有权限访问这个文件。 +3. 如果上述 a、b 任一为真(或者“其它”位设为有权限访问),那么这个进程就有权限访问这个文件。 + +比如说,如果一个进程被用户 `julia` 拥有并且 `julia` 在`awesome` 组,那么这个进程就能访问下面这个文件。 + +``` +r--r--r-- 1 root awesome 6872 Sep 24 11:09 file.txt +``` + +然而上述的机制我并没有考虑得非常清楚,如果你硬要我阐述清楚,我会说进程可能会在**运行时**去检查 `/etc/group` 文件里是否有某些组拥有当前的用户。 + +### 然而这并不是 Linux 里“组”的工作机制 + +我在上个星期的工作中发现了一件有趣的事,事实证明我前面的理解错了,我对组的工作机制的描述并不准确。特别是 Linux **并不会**在进程每次试图访问一个文件时就去检查这个进程的用户属于哪些组。 + +我在读了《[Linux 编程接口][1]》这本书的第九章(“进程资格”)后才恍然大悟(这本书真是太棒了),这才是组真正的工作方式!我意识到之前我并没有真正理解用户和组是怎么工作的,我信心满满的尝试了下面的内容并且验证到底发生了什么,事实证明现在我的理解才是对的。 + +### 用户和组权限检查是怎么完成的 + +现在这些关键的知识在我看来非常简单! 这本书的第九章上来就告诉我如下事实:用户和组 ID 是**进程的属性**,它们是: + +* 真实用户 ID 和组 ID; +* 有效用户 ID 和组 ID; +* 保存的 set-user-ID 和保存的 set-group-ID; +* 文件系统用户 ID 和组 ID(特定于 Linux); +* 补充的组 ID; + +这说明 Linux **实际上**检查一个进程能否访问一个文件所做的组检查是这样的: + +* 检查一个进程的组 ID 和补充组 ID(这些 ID 就在进程的属性里,**并不是**实时在 `/etc/group` 里查找这些 ID) +* 检查要访问的文件的访问属性里的组设置 +* 确定进程对文件是否有权限访问(LCTT 译注:即文件的组是否是以上的组之一) + +通常当访问控制的时候使用的是**有效**用户/组 ID,而不是**真实**用户/组 ID。技术上来说当访问一个文件时使用的是**文件系统**的 ID,它们通常和有效用户/组 ID 一样。(LCTT 译注:这句话针对 Linux 而言。) + +### 将一个用户加入一个组并不会将一个已存在的进程(的用户)加入那个组 + +下面是一个有趣的例子:如果我创建了一个新的组:`panda` 组并且将我自己(`bork`)加入到这个组,然后运行 `groups` 来检查我是否在这个组里:结果是我(`bork`)竟然不在这个组?! + +``` +bork@kiwi~> sudo addgroup panda +Adding group `panda' (GID 1001) ... +Done. +bork@kiwi~> sudo adduser bork panda +Adding user `bork' to group `panda' ... +Adding user bork to group panda +Done. +bork@kiwi~> groups +bork adm cdrom sudo dip plugdev lpadmin sambashare docker lxd + +``` + +`panda` 并不在上面的组里!为了再次确定我们的发现,让我们建一个文件,这个文件被 `panda` 组拥有,看看我能否访问它。 + +``` +$ touch panda-file.txt +$ sudo chown root:panda panda-file.txt +$ sudo chmod 660 panda-file.txt +$ cat panda-file.txt +cat: panda-file.txt: Permission denied +``` + +好吧,确定了,我(`bork`)无法访问 `panda-file.txt`。这一点都不让人吃惊,我的命令解释器并没有将 `panda` 组作为补充组 ID,运行 `adduser bork panda` 并不会改变这一点。 + +### 那进程一开始是怎么得到用户的组的呢? + +这真是个非常令人困惑的问题,对吗?如果进程会将组的信息预置到进程的属性里面,进程在初始化的时候怎么取到组的呢?很明显你无法给你自己指定更多的组(否则就会和 Linux 访问控制的初衷相违背了……) + +有一点还是很清楚的:一个新的进程是怎么从我的命令行解释器(`/bash/fish`)里被**执行**而得到它的组的。(新的)进程将拥有我的用户 ID(`bork`),并且进程属性里还有很多组 ID。从我的命令解释器里执行的所有进程是从这个命令解释器里 `fork()` 而来的,所以这个新进程得到了和命令解释器同样的组。 + +因此一定存在一个“第一个”进程来把你的组设置到进程属性里,而所有由此进程而衍生的进程将都设置这些组。而那个“第一个”进程就是你的登录程序login shell,在我的笔记本电脑上,它是由 `login` 程序(`/bin/login`)实例化而来。登录程序以 root 身份运行,然后调用了一个 C 的库函数 —— `initgroups` 来设置你的进程的组(具体来说是通过读取 `/etc/group` 文件),因为登录程序是以 root 运行的,所以它能设置你的进程的组。 + +### 让我们再登录一次 + +好了!假如说我们正处于一个登录程序中,而我又想刷新我的进程的组设置,从我们前面所学到的进程是怎么初始化组 ID 的,我应该可以通过再次运行登录程序来刷新我的进程组并启动一个新的登录命令! + +让我们试试下边的方法: + +``` +$ sudo login bork +$ groups +bork adm cdrom sudo dip plugdev lpadmin sambashare docker lxd panda +$ cat panda-file.txt # it works! I can access the file owned by `panda` now! +``` + +当然,成功了!现在由登录程序衍生的程序的用户是组 `panda` 的一部分了!太棒了!这并不会影响我其他的已经在运行的登录程序(及其子进程),如果我真的希望“所有的”进程都能对 `panda` 组有访问权限。我必须完全的重启我的登录会话,这意味着我必须退出我的窗口管理器然后再重新登录。(LCTT 译注:即更新进程树的树根进程,这里是窗口管理器进程。) + +### newgrp 命令 + +在 Twitter 上有人告诉我如果只是想启动一个刷新了组信息的命令解释器的话,你可以使用 `newgrp`(LCTT 译注:不启动新的命令解释器),如下: + +``` +sudo addgroup panda +sudo adduser bork panda +newgrp panda # starts a new shell, and you don't have to be root to run it! +``` + +你也可以用 `sg panda bash` 来完成同样的效果,这个命令能启动一个`bash` 登录程序,而这个程序就有 `panda` 组。 + +### seduid 将设置有效用户 ID + +其实我一直对一个进程如何以 `setuid root` 的权限来运行意味着什么有点似是而非。现在我知道了,事实上所发生的是:`setuid` 设置了 +“有效用户 ID”! 如果我(`julia`)运行了一个 `setuid root` 的进程( 比如 `passwd`),那么进程的**真实**用户 ID 将为 `julia`,而**有效**用户 ID 将被设置为 `root`。 + +`passwd` 需要以 root 权限来运行,但是它能看到进程的真实用户 ID 是 `julia` ,是 `julia` 启动了这个进程,`passwd` 会阻止这个进程修改除了 `julia` 之外的用户密码。 + +### 就是这些了! + +在《[Linux 编程接口][1]》这本书里有很多 Linux 上一些功能的罕见使用方法以及 Linux 上所有的事物到底是怎么运行的详细解释,这里我就不一一展开了。那本书棒极了,我上面所说的都在该书的第九章,这章在 1300 页的书里只占了 17 页。 + +我最爱这本书的一点是我只用读 17 页关于用户和组是怎么工作的内容,而这区区 17 页就能做到内容完备、详实有用。我不用读完所有的 1300 页书就能得到有用的东西,太棒了! + +-------------------------------------------------------------------------------- + +via: https://jvns.ca/blog/2017/11/20/groups/ + +作者:[Julia Evans][a] +译者:[DavidChen](https://github.com/DavidChenLiang) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://jvns.ca/ +[1]:http://man7.org/tlpi/ diff --git a/published/20171202 Scrot Linux command-line screen grabs made simple.md b/published/20171202 Scrot Linux command-line screen grabs made simple.md new file mode 100644 index 0000000000..3b5d483f85 --- /dev/null +++ b/published/20171202 Scrot Linux command-line screen grabs made simple.md @@ -0,0 +1,66 @@ +Scrot:让你在命令行中进行截屏更加简单 +====== + +> Scrot 是一个简单、灵活,并且提供了许多选项的 Linux 命令行截屏工具。 + +[![Original photo by Rikki Endsley. CC BY-SA 4.0](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/community-penguins-osdc-lead.png?itok=BmqsAF4A)][1] + + +Linux 桌面上有许多用于截屏的优秀工具,比如 [Ksnapshot][1] 和 [Shutter][2] 。甚至 GNOME 桌面自带的简易截屏工具也能够很好的工作。但是,如果你很少截屏,或者你使用的 Linux 发行版没有内建截屏工具,或者你使用的是一台资源有限的老电脑,那么你该怎么办呢? + +或许你可以转向命令行,使用一个叫做 [Scrot][4] 的实用工具。它能够完成简单的截屏工作,同时它所具有的一些特性也许会让你感到非常惊喜。 + +### 走近 Scrot + +许多 Linux 发行版都会预先安装上 Scrot ,可以输入 `which scrot` 命令来查看系统中是否安装有 Scrot 。如果没有,那么可以使用你的 Linux 发行版的包管理器来安装。如果你想从源代码编译安装,那么也可以从 [GitHub][5] 上下载源代码。 + +如果要进行截屏,首先打开一个终端窗口,然后输入 `scrot [filename]` ,`[filename]` 是你想要保存的图片文件的名字(比如 `desktop.png`)。如果缺省了该参数,那么 scrot 会自动创建一个名字,比如 `2017-09-24-185009_1687x938_scrot.png` 。(这个名字缺乏了对图片内容的描述,这就是为什么最好在命令中指定一个名字作为参数。) + +如果不带任何参数运行 Scrot,那么它将会对整个桌面进行截屏。如果不想这样,那么你也可以对屏幕中的一个小区域进行截图。 + +### 对单一窗口进行截屏 + +可以通过输入 `scrot -u [filename]` 命令来对一个窗口进行截屏。 + +`-u` 选项告诉 Scrot 对当前窗口进行截屏,这通常是我们正在工作的终端窗口,也许不是你想要的。 + +如果要对桌面上的另一个窗口进行截屏,需要输入 `scrot -s [filename]` 。 + +`-s` 选项可以让你做下面两件事的其中一件: + +* 选择一个打开着的窗口 +* 在一个窗口的周围或一片区域画一个矩形进行捕获 + +你也可以设置一个时延,这样让你能够有时间来选择你想要捕获的窗口。可以通过 `scrot -u -d [num] [filename]` 来设置时延。 + +`-d` 选项告诉 Scrot 在捕获窗口前先等待一段时间,`[num]` 是需要等待的秒数。指定为 `-d 5` (等待 5 秒)应该能够让你有足够的时间来选择窗口。 + +### 更多有用的选项 + +Scrot 还提供了许多额外的特性(绝大多数我从来没有使用过)。下面是我发现的一些有用的选项: + +* `-b` 捕获窗口的边界 +* `-t` 捕获窗口并创建一个缩略图。当你需要把截图张贴到网上的时候,这会非常有用 +* `-c` 当你同时使用了 `-d` 选项的时候,在终端中创建倒计时 + +如果你想了解 Scrot 的其他选项,可以在终端中输入 `man scrot` 来查看它的手册,或者[在线阅读][6]。然后开始使用 Scrot 进行截屏。 + +虽然 Scrot 很简单,但它的确能够工作得很好。 + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/17/11/taking-screen-captures-linux-command-line-scrot + +作者:[Scott Nesbitt][a] +译者:[ucasFL](https://github.com/ucasFL) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://opensource.com/users/scottnesbitt +[1]:https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/community-penguins-osdc-lead.png?itok=BmqsAF4A +[2]:https://www.kde.org/applications/graphics/ksnapshot/ +[3]:https://launchpad.net/shutter +[4]:https://github.com/dreamer/scrot +[5]:http://manpages.ubuntu.com/manpages/precise/man1/scrot.1.html +[6]:https://github.com/dreamer/scrot diff --git a/published/20180102 Top 7 open source project management tools for agile teams.md b/published/20180102 Top 7 open source project management tools for agile teams.md new file mode 100644 index 0000000000..144b5fc3d4 --- /dev/null +++ b/published/20180102 Top 7 open source project management tools for agile teams.md @@ -0,0 +1,142 @@ +面向敏捷开发团队的 7 个开源项目管理工具 +====== + +> 在这篇开源项目管理工具的综述中,让我们来了解一下支持 Scrum、看板Kanban 等敏捷开发模式的软件。 + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/BUSINESS_orgchart1.png?itok=tukiFj89) + +Opensource.com 以前对流行的开源项目管理工具做过相应的调研。但是今年我们增加了一个特点。本次,我们特别关注支持[敏捷][1]方法的工具,包括相关的实践,如 [Scrum][2]、Lean 和 看板Kanban。 + +对敏捷开发的兴趣和使用的增长是我们今年决定专注于这些工具的原因。大多数组织(71%)的人说他们至少[使用了敏捷方式][3]。此外,敏捷项目比传统方法管理的项目 [要高出 28% 的成功率][4] 。 + +我们查看了 [2014][5]、[2015][6] 和 [2016][7] 中涉及的项目管理工具,并挑选了支持敏捷的工具,然后对没有涉及的或变化了的进行了研究。不管您的组织是否已经在使用敏捷开发,或者在 2018 年的众多计划之一是采用敏捷方法,这七个开源项目管理工具之一可能正是您所要找寻的。 + +### MyCollab + +![](https://opensource.com/sites/default/files/u128651/mycollab_kanban-board.png) + + +[MyCollab][8] 是一套针对中小型企业的三个协作模块套件:项目管理、客户关系管理(CRM)和文档创建和编辑软件。有两个许可证选项:一个商业的“终极”版本,它更快,可以在内部或云中运行;另一个开源的“社区版本”,这个正是我们感兴趣的版本。 + +由于没有使用查询缓存,社区版本没有云方式,并且速度较慢,但是提供了基本的项目管理特性,包括任务、问题管理、活动流、路线图视图和敏捷团队看板。虽然它没有单独的移动应用程序,但它也适用于移动设备,包括 Windows、Mac OS、Linux 和 UNIX 计算机。 + +MyCollab 的最新版本是 5.4.10,源代码可在 [GitHub][9] 上下载。它是在 AGPLv3 下进行授权的,需要 Java 运行时环境和 MySQL 支持。它可运行于 Windows、Linux、UNIX 和 MacOS。[下载地址][10]。 + +### Odoo + +![](https://opensource.com/sites/default/files/u128651/odoo_projects_screenshots_01a.gif) + + +[Odoo][11] 不仅仅是项目管理软件;它是一个完整的集成商业应用套件,包括会计、人力资源、网站和电子商务、库存、制造、销售管理(CRM)和其它工具。 + +与付费企业套件相比,免费的开源社区版具有有限的 [特性][12] 。它的项目管理应用程序包括敏捷团队的看板式任务跟踪视图,在最新版本 Odoo 11.0 中更新了该视图,以包括用于跟踪项目状态的进度条和动画。项目管理工具还包括甘特图、任务、问题、图表等等。Odoo 有一个繁荣的[社区][13],并提供 [用户指南][14] 及其他培训资源。 + + +它是在 GPLv3 下授权的,需要 Python 和 PostgreSQL 支持。作为[Docker][16] 镜像 可以运行在 Windows、Linux 和 Red Hat 包管理器中,下载地址[download][15],源代码[GitHub][17]。 + +### OpenProject + +![](https://opensource.com/sites/default/files/u128651/openproject-screenshot-agile-scrum.png) + +[OpenProject][18] 是一个强大的开源项目管理工具,以其易用性和丰富的项目管理和团队协作特性而著称。 + +它的模块支持项目计划、调度、路线图和发布计划、时间跟踪、成本报告、预算、bug 跟踪以及敏捷和 Scrum。它的敏捷特性,包括创建 Story、确定 sprint 的优先级以及跟踪任务,都与 OpenProject 的其他模块集成在一起。 + +OpenProject 在 GPLv3 下获得许可,其源代码可在[GitHub][19]上。最新版本 7.3.2 的 Linux 版本 [在此下载][20];您可以在 Birthe Lindenthal 的文章 “[OpenProject 入门][21]”中了解更多关于安装和配置它的信息。 + +### OrangeScrum + +![](https://opensource.com/sites/default/files/u128651/orangescrum_kanban.png) + +正如从其名称中猜到的,[OrangeScrum][22] 支持敏捷方法,特别是使用 Scrum 任务板和看板式工作流视图。它面向较小的组织自由职业者、中介机构和中小型企业。 + +开源版本提供了 OrangeScrum 付费版本中的许多 [特性][23],包括移动应用程序、资源利用率和进度跟踪。其他特性,包括甘特图、时间日志、发票和客户端管理,可以作为付费附加组件提供,付费版本包括云选项,而社区版本不提供。 + +OrangeScrum 是基于 GPLv3 授权的,是基于 CakePHP 框架开发。它需要 Apache、PHP 5.3 或更高版本和 MySQL 4.1 或更高版本支持,并可以在 Windows、Linux 和 Mac OS 上运行。其最新版本 1.1.1 [在此下载][24],其源码在 [GitHub] [25]。 + + +### ]project-open[ + +![](https://opensource.com/sites/default/files/u128651/projectopen_dashboard.png) + +[\]project-open\[][26] 是一个双许可证的企业项目管理工具,这意味着其核心是开源的,并且在商业许可的模块中可以使用一些附加特性。根据该项目的社区和企业版本的 [比较][27],开源核心为中小型组织提供了许多特性。 + +]project-open[ 支持带有 Scrum 和看板功能的 [敏捷][28] 项目,以及经典的甘特/瀑布项目和混合或混合项目。 + +该应用程序是在 GPL 下授权的,并且 [源代码][29]是通过 CVS 访问的。 ]project-open[ 在 Linux 和 Windows 的安装有 [安装程序][26],但也可以在云镜像和虚拟设备中使用。 + +### Taiga + +![](https://opensource.com/sites/default/files/u128651/taiga_screenshot.jpg) + +[Taiga][30] 是一个开源项目管理平台,它专注于 Scrum 和敏捷开发,其特征包括看板、任务、sprints、问题、backlog 和 epics。其他功能包括凭证管理、多项目支持、Wiki 页面和第三方集成。 + +它还为 iOS、Android 和 Windows 设备提供免费的移动应用程序,并提供导入工具,使从其他流行的项目管理应用程序迁移变得容易。 + +Taiga 对于公共项目是免费的,对项目数量或用户数量没有限制。对于私有项目,在“免费增值”模式下,有很多 [付费计划][31] 可用,但是值得注意的是,无论您属于哪种类型,软件的功能特性都是一样的。 + +Taiga 是在 GNU Affero GPLv3 下授权的,并且软件需要 Nginx、Python 和 PostgreSQL 支持。最新版本[3.1.0 Perovskia atriplicifolia][32],可在 [GitHub][33] 上下载。 + +### Tuleap + +![](https://opensource.com/sites/default/files/u128651/tuleap-scrum-prioritized-backlog.png) + +[Tuleap][34] 是一个应用程序生命周期管理(ALM)平台,旨在为每种类型的团队管理项目——小型、中型、大型、瀑布、敏捷或混合型——但是它对敏捷团队的支持是显著的。值得注意的是,它为 Scrum、看板、sprints、任务、报告、持续集成、backlogs 等提供支持. + +其他的 [特性][35] 包括问题跟踪、文档跟踪、协作工具,以及与 Git、SVN 和 Jenkins 的集成,所有这些都使它成为开放源码软件开发项目的吸引人的选择。 + +Tuleap 是在 GPLv2 下授权的。更多信息,包括 Docker 和 CentOS 下载,可以在他们的 [入门][36] 页面上找到。您还可以在 Tuleap 的 [Git][37] 上获取其最新版本 9.14 的源代码。 + +--- + +这种类型的文章的麻烦在于它一发布就过时了。您正在使用哪些开源项目管理工具,而被我们遗漏了?或者您对我们提到的有反馈意见吗?请在下面留下留言。 + + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/2/agile-project-management-tools + +作者:[Opensource.com][a] +译者:[heguangzhi](https://github.com/heguangzhi) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://opensource.com +[1]:http://agilemanifesto.org/principles.html +[2]:https://opensource.com/resources/scrum +[3]:https://www.pmi.org/-/media/pmi/documents/public/pdf/learning/thought-leadership/pulse/pulse-of-the-profession-2017.pdf +[4]:https://www.pwc.com/gx/en/actuarial-insurance-services/assets/agile-project-delivery-confidence.pdf +[5]:https://opensource.com/business/14/1/top-project-management-tools-2014 +[6]:https://opensource.com/business/15/1/top-project-management-tools-2015 +[7]:https://opensource.com/business/16/3/top-project-management-tools-2016 +[8]:https://community.mycollab.com/ +[9]:https://github.com/MyCollab/mycollab +[10]:https://www.mycollab.com/ce-registration/ +[11]:https://www.odoo.com/ +[12]:https://www.odoo.com/page/editions +[13]:https://www.odoo.com/page/community +[14]:https://www.odoo.com/documentation/user/11.0/ +[15]:https://www.odoo.com/page/download +[16]:https://hub.docker.com/_/odoo/ +[17]:https://github.com/odoo/odoo +[18]:https://www.openproject.org/ +[19]:https://github.com/opf/openproject +[20]:https://www.openproject.org/download-and-installation/ +[21]:https://opensource.com/article/17/11/how-install-and-use-openproject +[22]:https://www.orangescrum.org/ +[23]:https://www.orangescrum.org/compare-orangescrum +[24]:http://www.orangescrum.org/free-download +[25]:https://github.com/Orangescrum/orangescrum/ +[26]:http://www.project-open.com/en/list-installers +[27]:http://www.project-open.com/en/products/editions.html +[28]:http://www.project-open.com/en/project-type-agile +[29]:http://www.project-open.com/en/developers-cvs-checkout +[30]:https://taiga.io/ +[31]:https://tree.taiga.io/support/subscription-and-plans/payment-process-faqs/#q.-what-s-about-custom-plans-private-projects-with-more-than-25-members-? +[32]:https://blog.taiga.io/taiga-perovskia-atriplicifolia-release-310.html +[33]:https://github.com/taigaio +[34]:https://www.tuleap.org/ +[35]:https://www.tuleap.org/features/project-management +[36]:https://www.tuleap.org/get-started +[37]:https://tuleap.net/plugins/git/tuleap/tuleap/stable diff --git a/published/20180131 What I Learned from Programming Interviews.md b/published/20180131 What I Learned from Programming Interviews.md new file mode 100644 index 0000000000..1c090b8e97 --- /dev/null +++ b/published/20180131 What I Learned from Programming Interviews.md @@ -0,0 +1,137 @@ + +我从编程面试中学到的 +====== + +![](https://cdn-images-1.medium.com/max/1250/1*DXPdaGPM4oM6p5nSkup7IQ.jpeg) + +*聊聊白板编程面试* + +在 2017 年,我参加了 ‘计算机行业中的女性’ 的[Grace Hopper 庆祝活动][1]。这个活动是这类科技活动中最大的一个。共有 17,000 名女性IT工作者参加。 + +这个会议有个大型的配套招聘会,会上有招聘公司来面试会议参加者。有些人甚至现场拿到 offer。我在现场晃荡了一下,注意到一些应聘者看上去非常紧张忧虑。我还隐隐听到应聘者之间的谈话,其中一些人谈到在面试中做的并不好。 + +我走近我听到谈话的那群人并和她们聊了起来并给了一些面试上的小建议。我想我的建议还是比较偏基本的,如“(在面试时)一开始给出个能工作的解决方案也还说的过去”之类的,但是当她们听到我的一些其他的建议时还是颇为吃惊。 + +为了能更多的帮到像她们一样的小白面试者,我收集了一些过去对我有用的小点子,这些小点子我已经发表在了 [prodcast episode][2] 上。它们也是这篇文章的主题。 + +为了实习生职位和全职工作,我做过很多次的面试。当我还在大学主修计算机科学时,学校每个秋季学期都有招聘会,第一轮招聘会在校园里举行。(我在第一和最后一轮都搞砸过。)不过,每次面试后,我都会反思哪些方面我能做的更好,我还会和朋友们做模拟面试,这样我就能从他们那儿得到更多的面试反馈。 + +不管我们怎么样找工作: 工作中介、网络,或者学校招聘,他们的招聘流程中都会涉及到技术面试: + +近年来,我注意到了一些新的不同的面试形式出现了: + +* 与招聘方的一位工程师结对编程 +* 网络在线测试及在线编码 +* 白板编程(LCTT 译注: 这种形式应该不新了) + +我将重点谈谈白板面试,这种形式我经历的最多。我有过很多次面试,有些挺不错的,有些被我搞砸了。 + +#### 我做错的地方 + +首先,我想回顾一下我做的不好的地方。知错能改,善莫大焉。 + +当面试者提出一个要我解决的问题时, 我立即马上立刻开始在白板上写代码,_什么都不问。_ + +这里我犯了两个错误: + +#### 没有澄清对解决问题有关键作用的信息 + +比如,我们是否只用处理数字或者字符串?我们要支持多种数据类型吗?如果你在开始解题前不去问这些问题的话,你的面试官会有一种不好的印象:这个人在我们公司的话,他不会在开始项目工作之前不问清楚到底要做什么。而这恰恰是在工作场合很重要的一个工作习惯。公司可不像学校,你在开始工作前可不会得到写有所有详细步骤的作业说明。你得靠自己找到这些步骤并自己定义他们。 + +#### 只会默默思考,不去记录想法或和面试官沟通 + +在面试中,很多时候我也会傻傻站在那思考,什么都不写。我和一个朋友模拟面试的时候,他告诉我因为他曾经和我一起工作过所以他知道我在思考,但是如果他是个陌生的面试官的话,他会觉得我正站在那冥思苦想,毫无头绪。不要急匆匆的直奔解题而去是很重要的。花点时间多想想各种解题的可能性。有时候面试官会乐意和你一起探索解题的步骤。不管怎样,这就是在一家公司开工作会议的的普遍方式,大家各抒己见,一起讨论如何解决问题。 + +### 想到一个解题方法 + +在你开始写代码之前,如果你能总结一下要使用到的算法就太棒了。不要上来就写代码并认为你的代码肯定能解决问题。 + +这是对我管用的步骤: + +1. 头脑风暴 +2. 写代码 +3. 处理错误路径 +4. 测试 + +#### 1、 头脑风暴 + +对我来说,我会首先通过一些例子来视觉化我要解决的问题。比如说如果这个问题和数据结构中的树有关,我就会从树底层的空节点开始思考,如何处理一个节点的情况呢?两个节点呢?三个节点呢?这能帮助你从具体例子里抽象出你的解决方案。 + +在白板上先写下你的算法要做的事情列表。这样做,你往往能在开始写代码前就发现 bug 和缺陷(不过你可得掌握好时间)。我犯过的一个错误是我花了过多的时间在澄清问题和头脑风暴上,最后几乎没有留下时间给我写代码。你的面试官可能没有机会看你在白板上写下代码,这可太糟了。你可以带块手表,或者房间有钟的话,你也可以抬头看看时间。有些时候面试者会提醒你你已经得到了所有的信息(这时你就不要再问别的了),“我想我们已经把所有需要的信息都澄清了,让我们写代码实现吧”。 + +#### 2、 开始写代码,一气呵成 + +如果你还没有得到问题的完美解决方法,从最原始的解法开始总是可以的。当你在向面试官解释最显而易见的解法时,你要想想怎么去完善它,并指明这种做法是最原始的,未加优化的。(请熟悉算法中的 `O()` 的概念,这对面试非常有用。)在向面试者提交前请仔细检查你的解决方案两三遍。面试者有时会给你些提示, “还有更好的方法吗?”,这句话的意思是面试官提示你有更优化的解决方案。 + +#### 3、 错误处理 + +当你在编码时,对你想做错误处理的代码行做个注释。当面试者说,“很好,这里你想到了错误处理。你想怎么处理呢?抛出异常还是返回错误码?”,这将给你个机会去引出关于代码质量的一番讨论。当然,这种地方提出几个就够了。有时,面试者为了节省编码的时间,会告诉你可以假设外界输入的参数都已经通过了校验。不管怎样,你都要展现你对错误处理和编码质量的重要性的认识。 + +#### 4、 测试 + +在编码完成后,用你在前面头脑风暴中写的用例来在你脑子里“跑”一下你的代码,确定万无一失。例如你可以说,“让我用前面写下的树的例子来跑一下我的代码,如果是一个节点是什么结果,如果是两个节点是什么结果……” + +在你结束之后,面试者有时会问你你将会怎么测试你的代码,你会涉及什么样的测试用例。我建议你用下面不同的分类来组织你的错误用例: + +一些分类可以为: + +1. 性能 +2. 错误用例 +3. 期望的正常用例 + +对于性能测试,要考虑极端数量下的情况。例如,如果问题是关于列表的,你可以说你将会使用一个非常大的列表以及的非常小的列表来测试。如果和数字有关,你将会测试系统中的最大整数和最小整数。我建议读一些有关软件测试的书来得到更多的知识。在这个领域我最喜欢的书是 《[我们在微软如何测试软件][3]》。 + +对于错误用例,想一下什么是期望的错误情况并一一写下。 + +对于正向期望用例,想想用户需求是什么?你的解决方案要解决什么问题?这些都可以成为正向期望用例。 + +### “你还有什么要问我的吗?” + +面试最后总是会留几分钟给你问问题。我建议你在面试前写下你想问的问题。千万别说,“我没什么问题了”,就算你觉得面试砸了或者你对这间公司不怎么感兴趣,你总有些东西可以问问。你甚至可以问面试者他最喜欢自己的工作什么,最讨厌自己的工作什么。或者你可以问问面试官的工作具体是什么,在用什么技术和实践。不要因为觉得自己在面试中做的不好而心灰意冷,不想问什么问题。 + +### 申请一份工作 + +关于找工作和申请工作,有人曾经告诉我,你应该去找你真正有激情工作的地方。去找一家你喜欢的公司,或者你喜欢使用的产品,看看你能不能去那儿工作。 + +我个人并不推荐你用上述的方法去找工作。你会排除很多很好的公司,特别是你是在找实习工作或者入门级的职位时。 + +你也可以集中在其他的一些目标上。如:我想从这个工作里得到哪方面的更多经验?这个工作是关于云计算?Web 开发?或是人工智能?当在招聘会上与招聘公司沟通时,看看他们的工作单位有没有在这些领域的。你可能会在一家并非在你的想去公司列表上的公司(或非盈利机构)里找到你想找的职位。 + +#### 换组 + +在这家公司里的第一个组里呆了一年半以后,我觉得是时候去探索一下不同的东西了。我找到了一个我喜欢的组并进行了 4 轮面试。结果我搞砸了。 + +我什么都没有准备,甚至都没在白板上练练手。我当时的逻辑是,如果我都已经在一家公司干了快 2 年了,我还需要练什么?我完全错了,我在接下去的白板面试中跌跌撞撞。我的板书写得太小,而且因为没有从最左上角开始写代码,我的代码大大超出了一个白板的空间,这些都导致了白板面试失败。 + +我在面试前也没有刷过数据结构和算法题。如果我做了的话,我将会在面试中更有信心。就算你已经在一家公司担任了软件工程师,在你去另外一个组面试前,我强烈建议你在一块白板上演练一下如何写代码。 + +对于换项目组这件事,如果你是在公司内部换组的话,事先能同那个组的人非正式聊聊会很有帮助。对于这一点,我发现几乎每个人都很乐于和你一起吃个午饭。人一般都会在中午有空,约不到人或者别人正好有会议冲突的风险会很低。这是一种非正式的途径来了解你想去的组正在干什么,以及这个组成员个性是怎么样的。相信我,你能从一次午餐中得到很多信息,这可会对你的正式面试帮助不小。 + +非常重要的一点是,你在面试一个特定的组时,就算你在面试中做的很好,因为文化不契合的原因,你也很可能拿不到 offer。这也是为什么我一开始就想去见见组里不同的人的原因(有时这也不太可能),我希望你不要被一次拒绝所击倒,请保持开放的心态,选择新的机会,并多多练习。 + + +以上内容选自 《[The Women in Tech Show: Technical Interviews with Prominent Women in Tech][5]》的 “[编程面试][4]”章节, + +-------------------------------------------------------------------------------- + +作者简介: + + +微软研究院 Software Engineer II, www.thewomenintechshow.com 站长,所有观点都只代表本人意见。 + +------------ + +via: https://medium.freecodecamp.org/what-i-learned-from-programming-interviews-29ba49c9b851 + +作者:[Edaena Salinas][a] +译者:[DavidChenLiang](https://github.com/DavidChenLiang) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://medium.freecodecamp.org/@edaenas +[1]:https://anitab.org/event/2017-grace-hopper-celebration-women-computing/ +[2]:https://thewomenintechshow.com/2017/12/18/programming-interviews/ +[3]:https://www.amazon.com/How-We-Test-Software-Microsoft/dp/0735624259 +[4]:https://thewomenintechshow.com/2017/12/18/programming-interviews/ +[5]:https://thewomenintechshow.com/ diff --git a/published/20180201 Here are some amazing advantages of Go that you dont hear much about.md b/published/20180201 Here are some amazing advantages of Go that you dont hear much about.md new file mode 100644 index 0000000000..c1e3c36951 --- /dev/null +++ b/published/20180201 Here are some amazing advantages of Go that you dont hear much about.md @@ -0,0 +1,201 @@ +你没听说过的 Go 语言惊人优点 +========= + +![](https://cdn-images-1.medium.com/max/2000/1*NDXd5I87VZG0Z74N7dog0g.png) + +*来自 [https://github.com/ashleymcnamara/gophers][1] 的图稿* + +在这篇文章中,我将讨论为什么你需要尝试一下 Go 语言,以及应该从哪里学起。 + +Go 语言是可能是最近几年里你经常听人说起的编程语言。尽管它在 2009 年已经发布了,但它最近才开始流行起来。 + +![](https://cdn-images-1.medium.com/max/2000/1*cQ8QzhCPiFXqk_oQdUk_zw.png) + +*根据 Google 趋势,Go 语言非常流行。* + +这篇文章不会讨论一些你经常看到的 Go 语言的主要特性。 + +相反,我想向您介绍一些相当小众但仍然很重要的功能。只有在您决定尝试 Go 语言后,您才会知道这些功能。 + +这些都是表面上没有体现出来的惊人特性,但它们可以为您节省数周或数月的工作量。而且这些特性还可以使软件开发更加愉快。 + +阅读本文不需要任何语言经验,所以不必担心你还不了解 Go 语言。如果你想了解更多,可以看看我在底部列出的一些额外的链接。 + +我们将讨论以下主题: + +* GoDoc +* 静态代码分析 +* 内置的测试和分析框架 +* 竞争条件检测 +* 学习曲线 +* 反射 +* Opinionatedness +* 文化 + +请注意,这个列表不遵循任何特定顺序来讨论。 + +### GoDoc + +Go 语言非常重视代码中的文档,所以也很简洁。 + +[GoDoc][4] 是一个静态代码分析工具,可以直接从代码中创建漂亮的文档页面。GoDoc 的一个显著特点是它不使用任何其他的语言,如 JavaDoc、PHPDoc 或 JSDoc 来注释代码中的结构,只需要用英语。 + +它使用从代码中获取的尽可能多的信息来概述、构造和格式化文档。它有多而全的功能,比如:交叉引用、代码示例,并直接链接到你的版本控制系统仓库。 + +而你需要做的只有添加一些像 `// MyFunc transforms Foo into Bar` 这样子的老牌注释,而这些注释也会反映在的文档中。你甚至可以添加一些通过网络界面或者在本地可以实际运行的 [代码示例][5]。 + +GoDoc 是 Go 的唯一文档引擎,整个社区都在使用。这意味着用 Go 编写的每个库或应用程序都具有相同的文档格式。从长远来看,它可以帮你在浏览这些文档时节省大量时间。 + +例如,这是我最近一个小项目的 GoDoc 页面:[pullkee — GoDoc][6]。 + +### 静态代码分析 + +Go 严重依赖于静态代码分析。例如用于文档的 [godoc][7],用于代码格式化的 [gofmt][8],用于代码风格的 [golint][9],等等。 + +它们是如此之多,甚至有一个总揽了它们的项目 [gometalinter][10] ,将它们组合成了单一的实用程序。 + +这些工具通常作为独立的命令行应用程序实现,并可轻松与任何编码环境集成。 + +静态代码分析实际上并不是现代编程的新概念,但是 Go 将其带入了绝对的范畴。我无法估量它为我节省了多少时间。此外,它给你一种安全感,就像有人在你背后支持你一样。 + +创建自己的分析器非常简单,因为 Go 有专门的内置包来解析和加工 Go 源码。 + +你可以从这个链接中了解到更多相关内容: [GothamGo Kickoff Meetup: Alan Donovan 的 Go 静态分析工具][11]。 + +### 内置的测试和分析框架 + +您是否曾尝试为一个从头开始的 JavaScript 项目选择测试框架?如果是这样,你或许会理解经历这种过度分析analysis paralysis的痛苦。您可能也意识到您没有使用其中 80% 的框架。 + +一旦您需要进行一些可靠的分析,问题就会重复出现。 + +Go 附带内置测试工具,旨在简化和提高效率。它为您提供了最简单的 API,并做出最小的假设。您可以将它用于不同类型的测试、分析,甚至可以提供可执行代码示例。 + +它可以开箱即用地生成便于持续集成的输出,而且它的用法很简单,只需运行 `go test`。当然,它还支持高级功能,如并行运行测试,跳过标记代码,以及其他更多功能。 + +### 竞争条件检测 + +您可能已经听说了 Goroutine,它们在 Go 中用于实现并发代码执行。如果你未曾了解过,[这里][12]有一个非常简短的解释。 + +无论具体技术如何,复杂应用中的并发编程都不容易,部分原因在于竞争条件的可能性。 + +简单地说,当几个并发操作以不可预测的顺序完成时,竞争条件就会发生。它可能会导致大量的错误,特别难以追查。如果你曾经花了一天时间调试集成测试,该测试仅在大约 80% 的执行中起作用?这可能是竞争条件引起的。 + +总而言之,在 Go 中非常重视并发编程,幸运的是,我们有一个强大的工具来捕捉这些竞争条件。它完全集成到 Go 的工具链中。 + +您可以在这里阅读更多相关信息并了解如何使用它:[介绍 Go 中的竞争条件检测 - Go Blog][13]。 + +### 学习曲线 + +您可以在一个晚上学习**所有**的 Go 语言功能。我是认真的。当然,还有标准库,以及不同的,更具体领域的最佳实践。但是两个小时就足以让你自信地编写一个简单的 HTTP 服务器或命令行应用程序。 + +Go 语言拥有[出色的文档][14],大部分高级主题已经在他们的博客上进行了介绍:[Go 编程语言博客][15]。 + +比起 Java(以及 Java 家族的语言)、Javascript、Ruby、Python 甚至 PHP,你可以更轻松地把 Go 语言带到你的团队中。由于环境易于设置,您的团队在完成第一个生产代码之前需要进行的投资要小得多。 + +### 反射 + +代码反射本质上是一种隐藏在编译器下并访问有关语言结构的各种元信息的能力,例如变量或函数。 + +鉴于 Go 是一种静态类型语言,当涉及更松散类型的抽象编程时,它会受到许多各种限制。特别是与 Javascript 或 Python 等语言相比。 + +此外,Go [没有实现一个名为泛型的概念][16],这使得以抽象方式处理多种类型更具挑战性。然而,由于泛型带来的复杂程度,许多人认为不实现泛型对语言实际上是有益的。我完全同意。 + +根据 Go 的理念(这是一个单独的主题),您应该努力不要过度设计您的解决方案。这也适用于动态类型编程。尽可能坚持使用静态类型,并在确切知道要处理的类型时使用接口interface。接口在 Go 中非常强大且无处不在。 + +但是,仍然存在一些情况,你无法知道你处理的数据类型。一个很好的例子是 JSON。您可以在应用程序中来回转换所有类型的数据。字符串、缓冲区、各种数字、嵌套结构等。 + +为了解决这个问题,您需要一个工具来检查运行时的数据并根据其类型和结构采取不同行为。反射Reflect可以帮到你。Go 拥有一流的反射包,使您的代码能够像 Javascript 这样的语言一样动态。 + +一个重要的警告是知道你使用它所带来的代价 —— 并且只有知道在没有更简单的方法时才使用它。 + +你可以在这里阅读更多相关信息: [反射的法则 — Go 博客][18]. + +您还可以在此处阅读 JSON 包源码中的一些实际代码: [src/encoding/json/encode.go — Source Code][19] + +### Opinionatedness(专制独裁的 Go) + +顺便问一下,有这样一个单词吗? + +来自 Javascript 世界,我面临的最艰巨的困难之一是决定我需要使用哪些约定和工具。我应该如何设计代码?我应该使用什么测试库?我该怎么设计结构?我应该依赖哪些编程范例和方法? + +这有时候基本上让我卡住了。我需要花时间思考这些事情而不是编写代码并满足用户。 + +首先,我应该注意到我完全知道这些惯例的来源,它总是来源于你或者你的团队。无论如何,即使是一群经验丰富的 Javascript 开发人员也很容易发现他们在实现相同的结果时,而大部分的经验却是在完全不同的工具和范例上。 + +这导致整个团队中出现过度分析,并且使得个体之间更难以相互协作。 + +嗯,Go 是不同的。即使您对如何构建和维护代码有很多强烈的意见,例如:如何命名,要遵循哪些结构模式,如何更好地实现并发。但你只有一个每个人都遵循的风格指南。你只有一个内置在基本工具链中的测试框架。 + +虽然这似乎过于严格,但它为您和您的团队节省了大量时间。当你写代码时,受一点限制实际上是一件好事。在构建新代码时,它为您提供了一种更直接的方法,并且可以更容易地调试现有代码。 + +因此,大多数 Go 项目在代码方面看起来非常相似。 + +### 文化 + +人们说,每当你学习一门新的口语时,你也会沉浸在说这种语言的人的某些文化中。因此,您学习的语言越多,您可能会有更多的变化。 + +编程语言也是如此。无论您将来如何应用新的编程语言,它总能给你带来新的编程视角或某些特别的技术。 + +无论是函数式编程,模式匹配pattern matching还是原型继承prototypal inheritance。一旦你学会了它们,你就可以随身携带这些编程思想,这扩展了你作为软件开发人员所拥有的问题解决工具集。它们也改变了你阅读高质量代码的方式。 + +而 Go 在这方面有一项了不起的财富。Go 文化的主要支柱是保持简单,脚踏实地的代码,而不会产生许多冗余的抽象概念,并将可维护性放在首位。大部分时间花费在代码的编写工作上,而不是在修补工具和环境或者选择不同的实现方式上,这也是 Go 文化的一部分。 + +Go 文化也可以总结为:“应当只用一种方法去做一件事”。 + +一点注意事项。当你需要构建相对复杂的抽象代码时,Go 通常会妨碍你。好吧,我会说这是简单的权衡。 + +如果你真的需要编写大量具有复杂关系的抽象代码,那么最好使用 Java 或 Python 等语言。然而,这种情况却很少。 + +在工作时始终使用最好的工具! + +### 总结 + +你或许之前听说过 Go,或者它暂时在你圈子以外的地方。但无论怎样,在开始新项目或改进现有项目时,Go 可能是您或您团队的一个非常不错的选择。 + +这不是 Go 的所有惊人的优点的完整列表,只是一些被人低估的特性。 + +请尝试一下从 [Go 之旅][20] 来开始学习 Go,这将是一个令人惊叹的开始。 + +如果您想了解有关 Go 的优点的更多信息,可以查看以下链接: + +* [你为什么要学习 Go? - Keval Patel][2] +* [告别Node.js - TJ Holowaychuk][3] + +并在评论中分享您的阅读感悟! + +即使您不是为了专门寻找新的编程语言语言,也值得花一两个小时来感受它。也许它对你来说可能会变得非常有用。 + +不断为您的工作寻找最好的工具! + +------------------------------------------------------- +via: https://medium.freecodecamp.org/here-are-some-amazing-advantages-of-go-that-you-dont-hear-much-about-1af99de3b23a + +作者:[Kirill Rogovoy][a] +译者:[imquanquan](https://github.com/imquanquan) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://twitter.com/krogovoy +[1]:https://github.com/ashleymcnamara/gophers +[2]:https://medium.com/@kevalpatel2106/why-should-you-learn-go-f607681fad65 +[3]:https://medium.com/@tjholowaychuk/farewell-node-js-4ba9e7f3e52b +[4]:https://godoc.org/ +[5]:https://blog.golang.org/examples +[6]:https://godoc.org/github.com/kirillrogovoy/pullkee +[7]:https://godoc.org/ +[8]:https://golang.org/cmd/gofmt/ +[9]:https://github.com/golang/lint +[10]:https://github.com/alecthomas/gometalinter#supported-linters +[11]:https://vimeo.com/114736889 +[12]:https://gobyexample.com/goroutines +[13]:https://blog.golang.org/race-detector +[14]:https://golang.org/doc/ +[15]:https://blog.golang.org/ +[16]:https://golang.org/doc/faq#generics +[17]:https://golang.org/pkg/reflect/ +[18]:https://blog.golang.org/laws-of-reflection +[19]:https://golang.org/src/encoding/json/encode.go +[20]:https://tour.golang.org/ +[21]:https://github.com/kirillrogovoy/ +[22]:https://twitter.com/krogovoy diff --git a/published/20180203 API Star- Python 3 API Framework - Polyglot.Ninja().md b/published/20180203 API Star- Python 3 API Framework - Polyglot.Ninja().md new file mode 100644 index 0000000000..56ed6a6dde --- /dev/null +++ b/published/20180203 API Star- Python 3 API Framework - Polyglot.Ninja().md @@ -0,0 +1,262 @@ +API Star:一个 Python 3 的 API 框架 +====== + +为了在 Python 中快速构建 API,我主要依赖于 [Flask][1]。最近我遇到了一个名为 “API Star” 的基于 Python 3 的新 API 框架。由于几个原因,我对它很感兴趣。首先,该框架包含 Python 新特点,如类型提示和 asyncio。而且它再进一步为开发人员提供了很棒的开发体验。我们很快就会讲到这些功能,但在我们开始之前,我首先要感谢 Tom Christie,感谢他为 Django REST Framework 和 API Star 所做的所有工作。 + +现在说回 API Star —— 我感觉这个框架很有成效。我可以选择基于 asyncio 编写异步代码,或者可以选择传统后端方式就像 WSGI 那样。它配备了一个命令行工具 —— `apistar` 来帮助我们更快地完成工作。它支持 Django ORM 和 SQLAlchemy,这是可选的。它有一个出色的类型系统,使我们能够定义输入和输出的约束,API Star 可以自动生成 API 的模式(包括文档),提供验证和序列化功能等等。虽然 API Star 专注于构建 API,但你也可以非常轻松地在其上构建 Web 应用程序。在我们自己构建一些东西之前,所有这些可能都没有意义的。 + +### 开始 + +我们将从安装 API Star 开始。为此实验创建一个虚拟环境是一个好主意。如果你不知道如何创建一个虚拟环境,不要担心,继续往下看。 + +``` +pip install apistar +``` + +(译注:上面的命令是在 Python 3 虚拟环境下使用的) + +如果你没有使用虚拟环境或者你的 Python 3 的 `pip` 名为 `pip3`,那么使用 `pip3 install apistar` 代替。 + +一旦我们安装了这个包,我们就应该可以使用 `apistar` 命令行工具了。我们可以用它创建一个新项目,让我们在当前目录中创建一个新项目。 + +``` +apistar new . +``` + +现在我们应该创建两个文件:`app.py`,它包含主应用程序,然后是 `test.py`,它用于测试。让我们来看看 `app.py` 文件: + +``` +from apistar import Include, Route +from apistar.frameworks.wsgi import WSGIApp as App +from apistar.handlers import docs_urls, static_urls + +def welcome(name=None): + if name is None: + return {'message': 'Welcome to API Star!'} + return {'message': 'Welcome to API Star, %s!' % name} + + +routes = [ + Route('/', 'GET', welcome), + Include('/docs', docs_urls), + Include('/static', static_urls) +] + +app = App(routes=routes) + + +if __name__ == '__main__': + app.main() +``` + +在我们深入研究代码之前,让我们运行应用程序并查看它是否正常工作。我们在浏览器中输入 `http://127.0.0.1:8080/`,我们将得到以下响应: + +``` +{"message": "Welcome to API Star!"} +``` + +如果我们输入:`http://127.0.0.1:8080/?name=masnun` + +``` +{"message": "Welcome to API Star, masnun!"} +``` + +同样的,输入 `http://127.0.0.1:8080/docs/`,我们将看到自动生成的 API 文档。 + +现在让我们来看看代码。我们有一个 `welcome` 函数,它接收一个名为 `name` 的参数,其默认值为 `None`。API Star 是一个智能的 API 框架。它将尝试在 url 路径或者查询字符串中找到 `name` 键并将其传递给我们的函数,它还基于其生成 API 文档。这真是太好了,不是吗? + +然后,我们创建一个 `Route` 和 `Include` 实例的列表,并将列表传递给 `App` 实例。`Route` 对象用于定义用户自定义路由。顾名思义,`Include` 包含了在给定的路径下的其它 url 路径。 + +### 路由 + +路由很简单。当构造 `App` 实例时,我们需要传递一个列表作为 `routes` 参数,这个列表应该有我们刚才看到的 `Route` 或 `Include` 对象组成。对于 `Route`,我们传递一个 url 路径,http 方法和可调用的请求处理程序(函数或者其他)。对于 `Include` 实例,我们传递一个 url 路径和一个 `Routes` 实例列表。 + +#### 路径参数 + +我们可以在花括号内添加一个名称来声明 url 路径参数。例如 `/user/{user_id}` 定义了一个 url,其中 `user_id` 是路径参数,或者说是一个将被注入到处理函数(实际上是可调用的)中的变量。这有一个简单的例子: + +``` +from apistar import Route +from apistar.frameworks.wsgi import WSGIApp as App + + +def user_profile(user_id: int): + return {'message': 'Your profile id is: {}'.format(user_id)} + + +routes = [ + Route('/user/{user_id}', 'GET', user_profile), +] + +app = App(routes=routes) + +if __name__ == '__main__': + app.main() +``` + +如果我们访问 `http://127.0.0.1:8080/user/23`,我们将得到以下响应: + +``` +{"message": "Your profile id is: 23"} +``` + +但如果我们尝试访问 `http://127.0.0.1:8080/user/some_string`,它将无法匹配。因为我们定义了 `user_profile` 函数,且为 `user_id` 参数添加了一个类型提示。如果它不是整数,则路径不匹配。但是如果我们继续删除类型提示,只使用 `user_profile(user_id)`,它将匹配此 url。这也展示了 API Star 的智能之处和利用类型和好处。 + +#### 包含/分组路由 + +有时候将某些 url 组合在一起是有意义的。假设我们有一个处理用户相关功能的 `user` 模块,将所有与用户相关的 url 分组在 `/user` 路径下可能会更好。例如 `/user/new`、`/user/1`、`/user/1/update` 等等。我们可以轻松地在单独的模块或包中创建我们的处理程序和路由,然后将它们包含在我们自己的路由中。 + +让我们创建一个名为 `user` 的新模块,文件名为 `user.py`。我们将以下代码放入这个文件: + +``` +from apistar import Route + + +def user_new(): + return {"message": "Create a new user"} + + +def user_update(user_id: int): + return {"message": "Update user #{}".format(user_id)} + + +def user_profile(user_id: int): + return {"message": "User Profile for: {}".format(user_id)} + + +user_routes = [ + Route("/new", "GET", user_new), + Route("/{user_id}/update", "GET", user_update), + Route("/{user_id}/profile", "GET", user_profile), +] +``` + +现在我们可以从 app 主文件中导入 `user_routes`,并像这样使用它: + +``` +from apistar import Include +from apistar.frameworks.wsgi import WSGIApp as App + +from user import user_routes + +routes = [ + Include("/user", user_routes) +] + +app = App(routes=routes) + +if __name__ == '__main__': + app.main() +``` + +现在 `/user/new` 将委托给 `user_new` 函数。 + +### 访问查询字符串/查询参数 + +查询参数中传递的任何参数都可以直接注入到处理函数中。比如 url `/call?phone=1234`,处理函数可以定义一个 `phone` 参数,它将从查询字符串/查询参数中接收值。如果 url 查询字符串不包含 `phone` 的值,那么它将得到 `None`。我们还可以为参数设置一个默认值,如下所示: + +``` +def welcome(name=None): + if name is None: + return {'message': 'Welcome to API Star!'} + return {'message': 'Welcome to API Star, %s!' % name} +``` + +在上面的例子中,我们为 `name` 设置了一个默认值 `None`。 + +### 注入对象 + +通过给一个请求程序添加类型提示,我们可以将不同的对象注入到视图中。注入请求相关的对象有助于处理程序直接从内部访问它们。API Star 内置的 `http` 包中有几个内置对象。我们也可以使用它的类型系统来创建我们自己的自定义对象并将它们注入到我们的函数中。API Star 还根据指定的约束进行数据验证。 + +让我们定义自己的 `User` 类型,并将其注入到我们的请求处理程序中: + +``` +from apistar import Include, Route +from apistar.frameworks.wsgi import WSGIApp as App +from apistar import typesystem + + +class User(typesystem.Object): + properties = { + 'name': typesystem.string(max_length=100), + 'email': typesystem.string(max_length=100), + 'age': typesystem.integer(maximum=100, minimum=18) + } + + required = ["name", "age", "email"] + + +def new_user(user: User): + return user + + +routes = [ + Route('/', 'POST', new_user), +] + +app = App(routes=routes) + +if __name__ == '__main__': + app.main() +``` + +现在如果我们发送这样的请求: + +``` +curl -X POST \ + http://127.0.0.1:8080/ \ + -H 'Cache-Control: no-cache' \ + -H 'Content-Type: application/json' \ + -d '{"name": "masnun", "email": "masnun@gmail.com", "age": 12}' +``` + +猜猜发生了什么?我们得到一个错误,说年龄必须等于或大于 18。类型系允许我们进行智能数据验证。如果我们启用了 `docs` url,我们还将自动记录这些参数。 + +### 发送响应 + +如果你已经注意到,到目前为止,我们只可以传递一个字典,它将被转换为 JSON 并作为默认返回。但是,我们可以使用 `apistar` 中的 `Response` 类来设置状态码和其它任意响应头。这有一个简单的例子: + +``` +from apistar import Route, Response +from apistar.frameworks.wsgi import WSGIApp as App + + +def hello(): + return Response( + content="Hello".encode("utf-8"), + status=200, + headers={"X-API-Framework": "API Star"}, + content_type="text/plain" + ) + + +routes = [ + Route('/', 'GET', hello), +] + +app = App(routes=routes) + +if __name__ == '__main__': + app.main() +``` + +它应该返回纯文本响应和一个自定义标响应头。请注意,`content` 应该是字节,而不是字符串。这就是我编码它的原因。 + +### 继续 + +我刚刚介绍了 API Star 的一些特性,API Star 中还有许多非常酷的东西,我建议通过 [Github Readme][2] 文件来了解这个优秀框架所提供的不同功能的更多信息。我还将尝试在未来几天内介绍关于 API Star 的更多简短的,集中的教程。 + + +-------------------------------------------------------------------------------- + +via: http://polyglot.ninja/api-star-python-3-api-framework/ + +作者:[MASNUN][a] +译者:[MjSeven](https://github.com/MjSeven) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:http://polyglot.ninja/author/masnun/ +[1]:http://polyglot.ninja/rest-api-best-practices-python-flask-tutorial/ +[2]:https://github.com/encode/apistar diff --git a/published/20180226 Linux Virtual Machines vs Linux Live Images.md b/published/20180226 Linux Virtual Machines vs Linux Live Images.md new file mode 100644 index 0000000000..f45b04cd48 --- /dev/null +++ b/published/20180226 Linux Virtual Machines vs Linux Live Images.md @@ -0,0 +1,61 @@ +Linux 虚拟机与 Linux 现场镜像版 +====== + +> Linux 虚拟机与 Linux 现场镜像版各有优势,也有不足。 + +首先我得承认,我非常喜欢频繁尝试新的 [Linux 发行版本][1]。然而,我用来测试它们的方法根据每次目标而有所不同。在这篇文章中,我们来看看两种运行 Linux 的模式:虚拟机或现场镜像版live image。每一种方式都存在优势,但是也有一些不足。 + +### 首次测试一个全新的 Linux 发行版 + +当我首次测试一个全新 Linux 发行版时,我使用的方法很大程度上依赖于我当前所拥有的 PC 资源。如果我使用台式机,我会在一台虚拟机中运行该发行版来测试。使用这种方法的原因是,我可以下载并测试该发行版,不只是在一个现场环境中,而且也可以作为一个带有持久存储的安装的系统。 + +另一方面,如果我的 PC 不具备强劲的硬件,那么通过 Linux 的虚拟机安装来测试发行版是适得其反的。我会将那台 PC 压榨到它的极限,诚然,更好的是使用现场版的 Linux 映像,而不是从闪存驱动器中运行。 + +### 体验新的 Linux 发行版本的软件 + +如果你有兴趣查看发行版本的桌面环境或可用的软件,那使用它的现场镜像版就没错了。一个现场版环境可以提供给你所预期的全局视角、其所提供的软件和用户体验的整体感受。 + +公平的说,你也可以在虚拟机上达到同样的效果,但是它有一点不好,如果这么做会让更多数据填满你的磁盘空间。毕竟这只是对发行版的一个简单体验。记得我在第一节说过:我喜欢在虚拟机上运行 Linux 来做测试。用这个方式我就能看到如何去安装它、分区是怎么样的等等,而使用现场镜像版时你就看不到这些。 + +这种体验方式通常表明你只想对该发行版本有个大致了解,所以在这种情况下,这种只需要付出最小的精力和时间的方式是一种不错的办法。 + +### 随身携带一个发行版 + +这种方式虽然不像几年前那样普遍,这种随身携带一个 Linux 发行版的能力也许是出于对某些用户的考虑。显然,虚拟机安装对于便携性并无太多帮助。不过,现场镜像版实际上是十分便携的。现场镜像版可以写入到 DVD 当中或复制到一个闪存盘中而便于携带。 + +从 Linux 的便携性这个概念上展开来说,当要在一个朋友的电脑上展示 Linux 如何工作,使用一个闪存盘上的现场镜像版也是很方便的。这可以使你能演示 Linux 如何丰富他们的生活,而不用必须在他们的 PC 上运行一个虚拟机。使用现场镜像版这就有点双赢的感觉了。 + +### 选择做双引导 Linux + +这接下来的方式是个大工程。考虑一下,也许你是一个 Windows 用户。你喜欢玩 Linux,但又不愿意冒险。除了在某些情况下会出些状况或者识别个别分区时遇到问题,双引导方式就没啥挑剔的。无论如何,使用 Linux 虚拟机或现场镜像版都对于你来说是一个很好的选择。 + +现在,我在某些事情上采取了奇怪的立场。我认为长期在闪存盘上运行现场镜像版要比虚拟机更有价值。这有两个原因。首先,您将会习惯于真正运行 Linux,而不是在 Windows 之上的虚拟机中运行它。其次,您可以设置闪存盘以包含持久存储的用户数据。 + +我知道你会说用一个虚拟机运行 Linux 也是如此,然而,使用现场镜像版的方式,你绝不会因为更新而被破坏任何东西。为什么?因为你不会更新你的宿主系统或者客户系统。请记住,有整个 Linux 发行版本被设计为持久存储的 Linux 发行版。Puppy Linux 就是一个非常好的例子。它不仅能运行在要被回收或丢弃的个人 PC 上,它也可以让你永远不被频繁的系统升级所困扰,这要感谢该发行版处理安全更新的方式。这不是一个常规的 Linux 发行版,而是以这样的一种方式封闭了安全问题——即持久存储的现场镜像版中没有什么令人担心的坏东西。 + +### Linux 虚拟机绝对是一个最好的选择 + +在我结束这篇文章时,让我告诉你。有一种场景下,使用 Virtual Box 等虚拟机绝对比现场镜像版更好:记录 Linux 发行版的桌面环境。 + +例如,我制作了一个视频,里面介绍和点评了许多 Linux 发行版。使用现场镜像版进行此操作需要我用硬件设备捕获屏幕,或者从现场镜像版的软件仓库中安装捕获软件。显然,虚拟机比 Linux 发行版的现场镜像版更适合这项工作。 + +一旦你需要采集音频进行混音,毫无疑问,如果您要使用软件来捕获您的点评语音,那么您肯定希望拥有一个宿主操作系统,里面包含了一个起码的捕获环境的所有基本需求。同样,您可以使用硬件设备来完成所有这一切,但如果您只是做兼职的视频/音频捕获, 那么这可能要付出成本高昂的代价。 + +### Linux 虚拟机 VS. Linux 现场镜像版 + +你最喜欢尝试新发行版的方式是哪些?也许,你是那种可以很好地格式化磁盘、将风险置之脑后的人,所以这里说的这些都是没用的? + +我在网上互动的大多数人都倾向于遵循我上面提及的方法,但是我很想知道哪种方式更加适合你。点击评论框,让我知道在体验 Linux 发行版世界最伟大和最新的版本时,您更喜欢哪种方法。 + +-------------------------------------------------------------------------------- + +via: https://www.datamation.com/open-source/linux-virtual-machines-vs-linux-live-images.html + +作者:[Matt Hartley][a] +译者:[sober-wang](https://github.com/sober-wang) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.datamation.com/author/Matt-Hartley-3080.html +[1]:https://www.datamation.com/open-source/best-linux-distro.html diff --git a/published/20180308 What is open source programming.md b/published/20180308 What is open source programming.md new file mode 100644 index 0000000000..1153bfe789 --- /dev/null +++ b/published/20180308 What is open source programming.md @@ -0,0 +1,89 @@ +何谓开源编程? +====== + +> 开源就是丢一些代码到 GitHub 上。了解一下它是什么,以及不是什么? + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/code_computer_development_programming.png?itok=4OM29-82) + +最简单的来说,开源编程就是编写一些大家可以随意取用、修改的代码。但你肯定听过关于 Go 语言的那个老笑话,说 Go 语言“简单到看一眼就可以明白规则,但需要一辈子去学会运用它”。其实写开源代码也是这样的。往 GitHub、Bitbucket、SourceForge 等网站或者是你自己的博客或网站上丢几行代码不是难事,但想要卓有成效,还需要个人的努力付出和高瞻远瞩。 + +![](https://opensource.com/sites/default/files/styles/panopoly_image_original/public/u128651/floorgoban.jpeg?itok=r8gA5jOk) + +### 我们对开源编程的误解 + +首先我要说清楚一点:把你的代码放在 GitHub 的公开仓库中并不意味着把你的代码开源了。在几乎全世界,根本不用创作者做什么,只要作品形成,版权就随之而生了。在创作者进行授权之前,只有作者可以行使版权相关的权力。未经创作者授权的代码,不论有多少人在使用,都是一颗定时炸弹,只有愚蠢的人才会去用它。 + +有些创作者很善良,认为“很明显我的代码是免费提供给大家使用的。”,他也并不想起诉那些用了他的代码的人,但这并不意味着这些代码可以放心使用。不论在你眼中创作者们多么善良,他们都 *有权力* 起诉任何使用、修改代码,或未经明确授权就将代码嵌入的人。 + +很明显,你不应该在没有指定开源许可证的情况下将你的源代码发布到网上然后期望别人使用它并为其做出贡献。我建议你也尽量避免使用这种代码,甚至疑似未授权的也不要使用。如果你开发了一个函数和例程,它和之前一个疑似未授权代码很像,源代码作者就可以对你就侵权提起诉讼。 + +举个例子,Jill Schmill 写了 AwesomeLib 然后未明确授权就把它放到了 GitHub 上,就算 Jill Schmill 不起诉任何人,只要她把 AwesomeLib 的完整版权都卖给 EvilCorp,EvilCorp 就会起诉之前违规使用这段代码的人。这种行为就好像是埋下了计算机安全隐患,总有一天会为人所用。 + +没有许可证的代码的危险的,切记。 + +### 选择恰当的开源许可证 + +假设你正要写一个新程序,而且打算让人们以开源的方式使用它,你需要做的就是选择最贴合你需求的[许可证][1]。和宣传中说的一样,你可以从 GitHub 所支持的 [choosealicense.com][2] 开始。这个网站设计得像个简单的问卷,特别方便快捷,点几下就能找到合适的许可证。 + +警示:在选择许可证时不要过于自负,如果你选的是 [Apache 许可证][3]或者 [GPLv3][4] 这种广为使用的许可证,人们很容易理解他们和你都有什么权利,你也不需要请律师来排查其中的漏洞。你选择的许可证使用的人越少,带来的麻烦就越多。 + +最重要的一点是: *千万不要试图自己制造许可证!* 自己制造许可证会给大家带来更多的困惑和困扰,不要这样做。如果在现有的许可证中确实找不到你需要的条款,你可以在现有的许可证中附加上你的要求,并且重点标注出来,提醒使用者们注意。 + +我知道有些人会站出来说:“我才懒得管什么许可证,我已经把代码发到公开领域public domain了。”但问题是,公开领域的法律效力并不是受全世界认可的。在不同的国家,公开领域的效力和表现形式不同。在有些国家的政府管控下,你甚至不可以把自己的源代码发到公开领域。万幸,[Unlicense][5] 可以弥补这些漏洞,它语言简洁,使用几个词清楚地描述了“就把它放到公开领域”,但其效力为全世界认可。 + +### 怎样引入许可证 + +确定使用哪个许可证之后,你需要清晰而无疑义地指定它。如果你是在 GitHub、GitLab 或 BitBucket 这几个网站发布,你需要构建很多个文件夹,在根文件夹中,你应把许可证创建为一个以 `LICENSE.txt` 命名的明文文件。 + +创建 `LICENSE.txt` 这个文件之后还有其它事要做。你需要在每个重要文件的头部添加注释块来申明许可证。如果你使用的是一个现有的许可证,这一步对你来说十分简便。一个 `# 项目名 (c)2018 作者名,GPLv3 许可证,详情见 https://www.gnu.org/licenses/gpl-3.0.en.html` 这样的注释块比隐约指代的许可证的效力要强得多。 + +如果你是要发布在自己的网站上,步骤也差不多。先创建 `LICENSE.txt` 文件,放入许可证,再表明许可证出处。 + +### 开源代码的不同之处 + +开源代码和专有代码的一个主要区别是开源代码写出来就是为了给别人看的。我是个 40 多岁的系统管理员,已经写过许许多多的代码。最开始我写代码是为了工作,为了解决公司的问题,所以其中大部分代码都是专有代码。这种代码的目的很简单,只要能在特定场合通过特定方式发挥作用就行。 + +开源代码则大不相同。在写开源代码时,你知道它可能会被用于各种各样的环境中。也许你的用例的环境条件很局限,但你仍旧希望它能在各种环境下发挥理想的效果。不同的人使用这些代码时会出现各种用例,你会看到各类冲突,还有你没有考虑过的思路。虽然代码不一定要满足所有人,但至少应该得体地处理他们遇到的问题,就算解决不了,也可以转换回常见的逻辑,不会给使用者添麻烦。(例如“第 583 行出现零除错误”就不能作为错误地提供命令行参数的响应结果) + +你的源代码也可能逼疯你,尤其是在你一遍又一遍地修改错误的函数或是子过程后,终于出现了你希望的结果,这时你不会叹口气就继续下一个任务,你会把过程清理干净,因为你不会愿意别人看出你一遍遍尝试的痕迹。比如你会把 `$variable`、`$lol` 全都换成有意义的 `$iterationcounter` 和 `$modelname`。这意味着你要认真专业地进行注释(尽管对于你所处的背景知识热度来说它并不难懂),因为你期望有更多的人可以使用你的代码。 + +这个过程难免有些痛苦沮丧,毕竟这不是你常做的事,会有些不习惯。但它会使你成为一位更好的程序员,也会让你的代码升华。即使你的项目只有你一位贡献者,清理代码也会节约你后期的很多工作,相信我一年后你再看你的 app 代码时,你会庆幸自己写下的是 `$modelname`,还有清晰的注释,而不是什么不知名的数列,甚至连 `$lol` 也不是。 + +### 你并不是为你一人而写 + +开源的真正核心并不是那些代码,而是社区。更大的社区的项目维持时间更长,也更容易为人们所接受。因此不仅要加入社区,还要多多为社区发展贡献思路,让自己的项目能够为社区所用。 + +蝙蝠侠为了完成目标暗中独自花了很大功夫,你用不着这样,你可以登录 Twitter、Reddit,或者给你项目的相关人士发邮件,发布你正在筹备新项目的消息,仔细聊聊项目的设计初衷和你的计划,让大家一起帮忙,向大家征集数据输入,类似的使用案例,把这些信息整合起来,用在你的代码里。你不用接受所有的建议和请求,但你要对它有个大概把握,这样在你之后完善时可以躲过一些陷阱。 + +发布了首次通告这个过程还不算完整。如果你希望大家能够接受你的作品并且使用它,你就要以此为初衷来设计。公众说不定可以帮到你,你不必对公开这件事如临大敌。所以不要闭门造车,既然你是为大家而写,那就开设一个真实、公开的项目,想象你在社区的帮助和监督下,认真地一步步完成它。 + +### 建立项目的方式 + +你可以在 GitHub、GitLab 或 BitBucket 上免费注册账号来管理你的项目。注册之后,创建知识库,建立 `README` 文件,分配一个许可证,一步步写入代码。这样可以帮你建立好习惯,让你之后和现实中的团队一起工作时,也能目的清晰地朝着目标稳妥地开展工作。这样你做得越久,就越有兴趣 —— 通常会有用户先对你的项目产生兴趣。 + +用户会开始提一些问题,这会让你开心也会让你不爽,你应该亲切礼貌地对待他们,就算他们很多人对项目有很多误解甚至根本不知道你的项目做的是什么,你也应该礼貌专业地对待。一方面,你可以引导他们,让他们了解你在干什么。另一方面,他们也会慢慢地将你带入更大的社区。 + +如果你的项目很受用户青睐,总会有高级开发者出现,并表示出兴趣。这也许是好事,也可能激怒你。最开始你可能只会做简单的问题修复,但总有一天你会收到拉取请求,有可能是硬编码或特殊用例(可能会让项目变得难以维护),它可能改变你项目的作用域,甚至改变你项目的初衷。你需要学会分辨哪个有贡献,根据这个决定合并哪个,婉拒哪个。 + +### 我们为什么要开源? + +开源听起来任务繁重,它也确实是这样。但它对你也有很多好处。它可以在无形之中磨练你,让你写出纯净持久的代码,也教会你与人沟通,团队协作。对于一个志向远大的专业开发者来说,它是最好的简历素材。你的未来雇主很有可能点开你的仓库,了解你的能力范围;而社区项目的开发者也有可能给你带来工作。 + +最后,为开源工作,意味着个人的提升,因为你在做的事不是为了你一个人,这比养活自己重要得多。 + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/3/what-open-source-programming + +作者:[Jim Salter][a] +译者:[Valoniakim](https://github.com/Valoniakim) +校对:[wxy](https://github.com/wxy)、[pityonline](https://github.com/pityonline) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://opensource.com/users/jim-salter +[1]: https://opensource.com/tags/licensing +[2]: https://choosealicense.com/ +[3]: https://choosealicense.com/licenses/apache-2.0/ +[4]: https://choosealicense.com/licenses/gpl-3.0/ +[5]: https://choosealicense.com/licenses/unlicense/ diff --git a/published/20180316 How to Encrypt Files From Within a File Manager.md b/published/20180316 How to Encrypt Files From Within a File Manager.md new file mode 100644 index 0000000000..c130f2e31d --- /dev/null +++ b/published/20180316 How to Encrypt Files From Within a File Manager.md @@ -0,0 +1,142 @@ +如何从 Linux 的文件管理器中加密文件 +====== + +![](https://www.linux.com/sites/lcom/files/styles/rendered_file/public/encryption.jpg?itok=Pk3_x5hz) + +Linux 桌面版和服务器版具有卓越的安全性。然而这并不意味着你可以放松警惕。你应该一直认为你的数据总是很快就会被破坏。也就是说,你可能需要使用各种加密工具。比如 GnuPG,它可以让你加密和解密文件等更多功能。GnuPG 的一个问题是一些用户不想在命令行输入那么复杂的命令。如果是这样的话,你可以转向桌面文件管理器。许多 Linux 桌面版包含了简易的加密和解密文件的功能,如果这种功能没有内置,那么也是很容易添加的。 + +我将引导你完成从三个流行的 Linux 文件管理器中对文件进行加密和解密过程: + + * Nautilus (即 GNOME Files) + * Dolphin + * Thunar + +### 安装 GnuPG + +在我们讨论如何处理这个问题之前,我们必须确保你的系统包含了必要的基本组件 —— [GnuPG][1]。大多数发行版本都包含 GnuPG。 在某些偶然情况下,你使用的是没有自带 GnuPG 的发行版,以下是安装方法: + + * 基于 Ubuntu 的发行版: `sudo apt install gnupg` + * 基于 Fedora 的发行版: `sudo yum install gnupg` + * openSUSE: `sudo zypper in gnupg` + * 基于 Arch 的发行版:`sudo pacman -S gnupg` + + +无论你是刚刚安装了 GnuPG,还是默认安装的,你都必须创建一个 GPG 密钥才能使用。每个桌面版都使用不同的 GUI 工具完成这个工作(或者甚至根本没有包含一个完成这个任务的 GUI 工具),所以让我们从命令行中创建这个密钥。打开终端窗口并输入以下指令: + +``` +gpg --gen-key +``` + +然后,你将被要求回答以下问题。除非你有充分的理由,否则你可以接受默认值: + + * 你想要哪种密钥? + * 你想要多长的密钥? + * 密钥有效期? + +一旦你回答了这些问题,输入 `y` 来表示答案是正确的。接下来你需要提供以下信息: + + * 真实姓名。 + * Email 地址。 + * 备注。 + +完成上述操作后,然后在提示的时候输入 `O` (即 ok)。然后,你将被要求为新密钥输入一个密码。一旦系统收集到了足够的熵(你需要在桌面上做一些工作才能做到这一点,LCTT 译注:比如随便敲击键盘),你的密钥就会被创建,然后你就可以开始工作了。 + +让我们看看如何从文件管理器中加密/解密文件: + +### Nautilus + +让我们从默认的 GNOME 文件管理器开始,因为它是最简单的。Nautilus 不需要额外安装什么或额外的工作就可以从精心设计的界面内加密/解密文件。一旦你创建完 gpg 密钥后,就可以打开文件管理器,导航到包含要加密的文件的目录,右键单击要加密的文件,然后从菜单中选择 “Encrypt” (图1)。 + +![nautilus][3] + +*图1:从 Nautilus 中加密文件。* + +你将被要求选择一个收件人(或者收件人列表 —— 图2)。注意:收件人将是那些你已经导入了公钥的用户。选择所需的密钥,然后从签名信息下拉列表中选择你的密钥(电子邮件地址)。 + +![nautilus][6] + +*图2:选择收件人和签名者。* + +注意:你还可以选择仅使用密码来加密文件。如果文件将保留在你的本地机器上,这一点非常重要(稍后将详细介绍)。一旦你设置好加密后,单击 “OK” 并(在提示时)输入 gpg 密钥的密码。文件将被加密(现在文件名以 .gpg 结尾)并保存在工作目录中。现在你可以将加密后的文件发送给在加密过程中已选择的收件人。 + +比如说(有你的公钥的)某人已经给你发送了一个加密文件。保存该文件,打开文件管理器,导航到该文件所在的目录,右击这个加密文件,选择 “Open With Decrypt File”,给文件一个新名称(不带 .gpg 的扩展名),然后单击“Save”。当提示时,输入你的 gpg 密钥的密码,该文件就会被解密并准备使用。 + +### Dolphin + +在 KDE 前端,必须安装一个软件包才能使用 Dolphin 文件管理器进行加密/解密。 登录到你的 KDE 桌面,打开终端窗口,然后输入以下命令(我正在使用 Neon 进行演示。如果你的发行版不是基于 Ubuntu 的,则必须相应地更改命令): + +``` +sudo apt install kgpg +``` + +安装完毕后,注销并重新登录 KDE 桌面。 你可以打开 Dolphin 并右键单击要加密的文件。 由于这是你第一次使用 kgpg,因此你必须完成快速设置向导(不言自明)。当完成该向导后,你可以返回该文件,右键单击它(图3),然后选择 Encrypt File。 + +![Dolphin][8] + +*图3:在 Dolphin 中加密文件。* + +系统将提示你选择用于加密的密钥(图4)。 进行选择并单击 “OK”。 该文件将被加密,而且你已准备好将其发送给收件人。 + +注意:使用 KDE 的 Dolphin 文件管理器市,你无法仅使用密码加密。 + +![Dolphin][10] + +*图4:选择要加密的收件人。* + +如果你收到来自有你的公钥的用户的加密文件(或者你有一个自己加密的文件),请打开 Dolphin,导航到相关文件,双击该文件,为该文件指定一个新名称 ,键入加密密码并单击 “OK”。 你现在可以读取到新解密的文件。 如果你使用自己的密钥加密了该文件,则不会提示你键入密码(因为它已经被存储了)。 + +### Thunar + +Thunar 文件管理器有点棘手。 没有任何额外的软件包可供安装;相反,你需要为了加密创建新的自定义操作。完成此操作后,你将能够在文件管理器中执行此操作。 + +要创建自定义操作,请打开 Thunar 文件管理器,然后单击 “Edit > Configure Custom Actions”。 在所得到的窗口中,单击 “+” 按钮(图5)并为加密操作输入以下内容: + +- 名称:加密 +- 描述:文件加密 +- 命令:`gnome-terminal -x gpg --encrypt --recipient %f` + +单击 “OK” 以保存此操作。 + +![Thunar][12] + +*图5:在Thunar中创建自定义操作。* + +注意:如果 gnome-terminal 不是你的默认终端,请替换该命令以打开你的默认终端。 + +你还可以创建仅使用密码(而非密钥)加密的操作。 为此,该操作的详细动作将会是以下内容: + +- 名称:加密密码 +- 说明:仅使用密码加密 +- 命令:`gnome-terminal -x gpg -c %f` + +你不需要为解密过程创建一个自定义操作,因为 Thunar 已经知道如何处理一个加密文件。 要解密文件,只需(在 Thunar 中)右键单击它,选择 “Open With Decrypt File”,为解密文件命名,然后(在提示时)键入加密密码。 Viola,你的加密文件已被解密并可以使用。 + +### 一个警告 + +请注意:如果你使用自己的密钥加密自己的文件,则无需输入加密密码来解密它们(因为你的公钥已存储)。 但是,如果你收到(拥有你的公钥的)其他人的文件,则需要输入你的密码。 如果你想要存储自己的加密文件,而不是使用密钥来加密它们,请使用仅使用密码加密。 Nautilus 和Thunar(但不是 KDE)可以做到这一点。 通过选择密码加密(通过密钥加密),当你解密文件时,它将始终提示你输入密码。 + +### 其他文件管理器 + +还有很多其它的文件管理器,它们中的一些可以使用加密,有些则不能。 你很有可能正在使用这三种工具中的一种,因此不仅可以将加密 / 解密添加到上下文菜单,而且是非常容易。 尝试一下,看看它是否会使加密和解密的过程变得更容易。 + +从 Linux 基金会和 edX 免费提供的[“Linux 介绍”][13]课程了解更多关于 Linux 的信息。 + +-------------------------------------------------------------------------------- + +via: https://www.linux.com/learn/intro-to-linux/2018/3/how-encrypt-files-within-file-manager + +作者:[JACK WALLEN][a] +译者:[Auk7f7](https://github.com/Auk7f7) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.linux.com/users/jlwallen +[1]:https://www.gnupg.org/ +[3]:https://www.linux.com/sites/lcom/files/styles/rendered_file/public/nautilus.jpg?itok=ae7Gtj60 "nautilus" +[4]:https://www.linux.com/licenses/category/used-permission +[6]:https://www.linux.com/sites/lcom/files/styles/rendered_file/public/nautilus_2.jpg?itok=3ht7j63n "nautilus" +[8]:https://www.linux.com/sites/lcom/files/styles/rendered_file/public/kde_0.jpg?itok=KSTctVw0 "Dolphin" +[10]:https://www.linux.com/sites/lcom/files/styles/rendered_file/public/kde_2.jpg?itok=CeqWikNl "Dolphin" +[12]:https://www.linux.com/sites/lcom/files/styles/rendered_file/public/thunar.jpg?itok=fXcHk08B "Thunar" +[13]:https://training.linuxfoundation.org/linux-courses/system-administration-training/introduction-to-linux diff --git a/published/20180324 How To Compress And Decompress Files In Linux.md b/published/20180324 How To Compress And Decompress Files In Linux.md new file mode 100644 index 0000000000..d968bbd6db --- /dev/null +++ b/published/20180324 How To Compress And Decompress Files In Linux.md @@ -0,0 +1,198 @@ +如何在 Linux 中压缩和解压缩文件 +====== + +![](https://www.ostechnix.com/wp-content/uploads/2018/03/compress-720x340.jpg) + +当在备份重要文件和通过网络发送大文件的时候,对文件进行压缩非常有用。请注意,压缩一个已经压缩过的文件会增加额外开销,因此你将会得到一个更大一些的文件。所以,请不要压缩已经压缩过的文件。在 GNU/Linux 中,有许多程序可以用来压缩和解压缩文件。在这篇教程中,我们仅学习其中两个应用程序。 + +在类 Unix 系统中,最常见的用来压缩文件的程序是: + + 1. gzip + 2. bzip2 + +### 1. 使用 gzip 程序来压缩和解压缩文件 + +`gzip` 是一个使用 Lempel-Ziv 编码(LZ77)算法来压缩和解压缩文件的实用工具。 + +#### 1.1 压缩文件 + +如果要压缩一个名为 `ostechnix.txt` 的文件,使之成为 gzip 格式的压缩文件,那么只需运行如下命令: + +``` +$ gzip ostechnix.txt +``` + +上面的命令运行结束之后,将会出现一个名为 `ostechnix.txt.gz` 的 gzip 格式压缩文件,代替了原始的 `ostechnix.txt` 文件。 + +`gzip` 命令还可以有其他用法。一个有趣的例子是,我们可以将一个特定命令的输出通过管道传递,然后作为 `gzip` 程序的输入来创建一个压缩文件。看下面的命令: + +``` +$ ls -l Downloads/ | gzip > ostechnix.txt.gz +``` + +上面的命令将会创建一个 gzip 格式的压缩文件,文件的内容为 `Downloads` 目录的目录项。 + +#### 1.2 压缩文件并将输出写到新文件中(不覆盖原始文件) + +默认情况下,`gzip` 程序会压缩给定文件,并以压缩文件替代原始文件。但是,你也可以保留原始文件,并将输出写到标准输出。比如,下面这个命令将会压缩 `ostechnix.txt` 文件,并将输出写入文件 `output.txt.gz`。 + +``` +$ gzip -c ostechnix.txt > output.txt.gz +``` + +类似地,要解压缩一个 `gzip` 格式的压缩文件并指定输出文件的文件名,只需运行: + +``` +$ gzip -c -d output.txt.gz > ostechnix1.txt +``` + +上面的命令将会解压缩 `output.txt.gz` 文件,并将输出写入到文件 `ostechnix1.txt` 中。在上面两个例子中,原始文件均不会被删除。 + +#### 1.3 解压缩文件 + +如果要解压缩 `ostechnix.txt.gz` 文件,并以原始未压缩版本的文件来代替它,那么只需运行: + +``` +$ gzip -d ostechnix.txt.gz +``` + +我们也可以使用 `gunzip` 程序来解压缩文件: + +``` +$ gunzip ostechnix.txt.gz +``` + +#### 1.4 在不解压缩的情况下查看压缩文件的内容 + +如果你想在不解压缩的情况下,使用 `gzip` 程序查看压缩文件的内容,那么可以像下面这样使用 `-c` 选项: + +``` +$ gunzip -c ostechnix1.txt.gz +``` + +或者,你也可以像下面这样使用 `zcat` 程序: + +``` +$ zcat ostechnix.txt.gz +``` + +你也可以通过管道将输出传递给 `less` 命令,从而一页一页的来查看输出,就像下面这样: + +``` +$ gunzip -c ostechnix1.txt.gz | less +$ zcat ostechnix.txt.gz | less +``` + +另外,`zless` 程序也能够实现和上面的管道同样的功能。 + +``` +$ zless ostechnix1.txt.gz +``` + +#### 1.5 使用 gzip 压缩文件并指定压缩级别 + +`gzip` 的另外一个显著优点是支持压缩级别。它支持下面给出的 3 个压缩级别: + + * **1** – 最快 (最差) + * **9** – 最慢 (最好) + * **6** – 默认级别 + +要压缩名为 `ostechnix.txt` 的文件,使之成为“最好”压缩级别的 gzip 压缩文件,可以运行: + +``` +$ gzip -9 ostechnix.txt +``` + +#### 1.6 连接多个压缩文件 + +我们也可以把多个需要压缩的文件压缩到同一个文件中。如何实现呢?看下面这个例子。 + +``` +$ gzip -c ostechnix1.txt > output.txt.gz +$ gzip -c ostechnix2.txt >> output.txt.gz +``` + +上面的两个命令将会压缩文件 `ostechnix1.txt` 和 `ostechnix2.txt`,并将输出保存到一个文件 `output.txt.gz` 中。 + +你可以通过下面其中任何一个命令,在不解压缩的情况下,查看两个文件 `ostechnix1.txt` 和 `ostechnix2.txt` 的内容: + +``` +$ gunzip -c output.txt.gz +$ gunzip -c output.txt +$ zcat output.txt.gz +$ zcat output.txt +``` + +如果你想了解关于 `gzip` 的更多细节,请参阅它的 man 手册。 + +``` +$ man gzip +``` + +### 2. 使用 bzip2 程序来压缩和解压缩文件 + +`bzip2` 和 `gzip` 非常类似,但是 `bzip2` 使用的是 Burrows-Wheeler 块排序压缩算法,并使用哈夫曼Huffman编码。使用 `bzip2` 压缩的文件以 “.bz2” 扩展结尾。 + +正如我上面所说的, `bzip2` 的用法和 `gzip` 几乎完全相同。只需在上面的例子中将 `gzip` 换成 `bzip2`,将 `gunzip` 换成 `bunzip2`,将 `zcat` 换成 `bzcat` 即可。 + +要使用 `bzip2` 压缩一个文件,并以压缩后的文件取而代之,只需运行: + +``` +$ bzip2 ostechnix.txt +``` + +如果你不想替换原始文件,那么可以使用 `-c` 选项,并把输出写入到新文件中。 + +``` +$ bzip2 -c ostechnix.txt > output.txt.bz2 +``` + +如果要解压缩文件,则运行: + +``` +$ bzip2 -d ostechnix.txt.bz2 +``` + +或者, + +``` +$ bunzip2 ostechnix.txt.bz2 +``` + +如果要在不解压缩的情况下查看一个压缩文件的内容,则运行: + +``` +$ bunzip2 -c ostechnix.txt.bz2 +``` + +或者, + +``` +$ bzcat ostechnix.txt.bz2 +``` + +如果你想了解关于 `bzip2` 的更多细节,请参阅它的 man 手册。 + +``` +$ man bzip2 +``` + +### 总结 + +在这篇教程中,我们学习了 `gzip` 和 `bzip2` 程序是什么,并通过 GNU/Linux 下的一些例子学习了如何使用它们来压缩和解压缩文件。接下来,我们将要学习如何在 Linux 中将文件和目录归档。 + +干杯! + + +-------------------------------------------------------------------------------- + +via: https://www.ostechnix.com/how-to-compress-and-decompress-files-in-linux/ + +作者:[SK][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[ucasFL](https://github.com/ucasFL) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.ostechnix.com/author/sk/ diff --git a/published/20180326 Start a blog in 30 minutes with Hugo, a static site generator written in Go.md b/published/20180326 Start a blog in 30 minutes with Hugo, a static site generator written in Go.md new file mode 100644 index 0000000000..648073a246 --- /dev/null +++ b/published/20180326 Start a blog in 30 minutes with Hugo, a static site generator written in Go.md @@ -0,0 +1,155 @@ +用 Hugo 30 分钟搭建静态博客 +====== +> 了解 Hugo 如何使构建网站变得有趣。 + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/programming-code-keyboard-laptop-music-headphones.png?itok=EQZ2WKzy) + +你是不是强烈地想搭建博客来将自己对软件框架等的探索学习成果分享呢?你是不是面对缺乏指导文档而一团糟的项目就有一种想去改变它的冲动呢?或者换个角度,你是不是十分期待能创建一个属于自己的个人博客网站呢? + +很多人在想搭建博客之前都有一些严重的迟疑顾虑:感觉自己缺乏内容管理系统(CMS)的相关知识,更缺乏时间去学习这些知识。现在,如果我说不用花费大把的时间去学习 CMS 系统、学习如何创建一个静态网站、更不用操心如何去强化网站以防止它受到黑客攻击的问题,你就可以在 30 分钟之内创建一个博客?你信不信?利用 Hugo 工具,就可以实现这一切。 + +![](https://opensource.com/sites/default/files/styles/panopoly_image_original/public/u128651/hugo_1.png?itok=JgxBSOBG) + +Hugo 是一个基于 Go 语言开发的静态站点生成工具。也许你会问,为什么选择它? + +* 无需数据库、无需需要各种权限的插件、无需跑在服务器上的底层平台,更没有额外的安全问题。 +* 都是静态站点,因此拥有轻量级、快速响应的服务性能。此外,所有的网页都是在部署的时候生成,所以服务器负载很小。 +* 极易操作的版本控制。一些 CMS 平台使用它们自己的版本控制软件(VCS)或者在网页上集成 Git 工具。而 Hugo,所有的源文件都可以用你所选的 VCS 软件来管理。 + +### 0-5 分钟:下载 Hugo,生成一个网站 + +直白的说,Hugo 使得写一个网站又一次变得有趣起来。让我们来个 30 分钟计时,搭建一个网站。 + +为了简化 Hugo 安装流程,这里直接使用 Hugo 可执行安装文件。 + +1. 下载和你操作系统匹配的 Hugo [版本][2]; +2. 压缩包解压到指定路径,例如 windows 系统的 `C:\hugo_dir` 或者 Linux 系统的 `~/hugo_dir` 目录;下文中的变量 `${HUGO_HOME}` 所指的路径就是这个安装目录; +3. 打开命令行终端,进入安装目录:`cd ${HUGO_HOME}`; +4. 确认 Hugo 已经启动: + * Unix 系统:`${HUGO_HOME}/[hugo version]`; + * Windows 系统:`${HUGO_HOME}\[hugo.exe version]`,例如:cmd 命令行中输入:`c:\hugo_dir\hugo version`。 + + 为了书写上的简化,下文中的 `hugo` 就是指 hugo 可执行文件所在的路径(包括可执行文件),例如命令 `hugo version` 就是指命令 `c:\hugo_dir\hugo version` 。(LCTT 译注:可以把 hugo 可执行文件所在的路径添加到系统环境变量下,这样就可以直接在终端中输入 `hugo version`) + + 如果命令 `hugo version` 报错,你可能下载了错误的版本。当然,有很多种方法安装 Hugo,更多详细信息请查阅 [官方文档][3]。最稳妥的方法就是把 Hugo 可执行文件放在某个路径下,然后执行的时候带上路径名 +5. 创建一个新的站点来作为你的博客,输入命令:`hugo new site awesome-blog`; +6. 进入新创建的路径下: `cd awesome-blog`; + +恭喜你!你已经创建了自己的新博客。 + +### 5-10 分钟:为博客设置主题 + +Hugo 中你可以自己构建博客的主题或者使用网上已经有的一些主题。这里选择 [Kiera][4] 主题,因为它简洁漂亮。按以下步骤来安装该主题: + +1. 进入主题所在目录:`cd themes`; +2. 克隆主题:`git clone https://github.com/avianto/hugo-kiera kiera`。如果你没有安装 Git 工具: + * 从 [Github][5] 上下载 hugo 的 .zip 格式的文件; + * 解压该 .zip 文件到你的博客主题 `theme` 路径; + * 重命名 `hugo-kiera-master` 为 `kiera`; +3. 返回博客主路径:`cd awesome-blog`; +4. 激活主题;通常来说,主题(包括 Kiera)都自带文件夹 `exampleSite`,里面存放了内容配置的示例文件。激活 Kiera 主题需要拷贝它提供的 `config.toml` 到你的博客下: + * Unix 系统:`cp themes/kiera/exampleSite/config.toml .`; + * Windows 系统:`copy themes\kiera\exampleSite\config.toml .`; + * 选择 `Yes` 来覆盖原有的 `config.toml`; + +5. ( 可选操作 )你可以选择可视化的方式启动服务器来验证主题是否生效:`hugo server -D` 然后在浏览器中输入 `http://localhost:1313`。可用通过在终端中输入 `Crtl+C` 来停止服务器运行。现在你的博客还是空的,但这也给你留了写作的空间。它看起来如下所示: + +![](https://opensource.com/sites/default/files/styles/panopoly_image_original/public/u128651/hugo_2.png?itok=PINOIOSU) + +你已经成功的给博客设置了主题!你可以在官方 [Hugo 主题][4] 网站上找到上百种漂亮的主题供你使用。 + +### 10-20 分钟:给博客添加内容 + +对于碗来说,它是空的时候用处最大,可以用来盛放东西;但对于博客来说不是这样,空博客几乎毫无用处。在这一步,你将会给博客添加内容。Hugo 和 Kiera 主题都为这个工作提供了方便性。按以下步骤来进行你的第一次提交: + +1. archetypes 将会是你的内容模板。 +2. 添加主题中的 archtypes 至你的博客: + * Unix 系统: `cp themes/kiera/archetypes/* archetypes/` + * Windows 系统:`copy themes\kiera\archetypes\* archetypes\` + * 选择 `Yes` 来覆盖原来的 `default.md` 内容架构类型 + +3. 创建博客 posts 目录: + * Unix 系统: `mkdir content/posts` + * Windows 系统: `mkdir content\posts` + +4. 利用 Hugo 生成你的 post: + * Unix 系统:`hugo nes posts/first-post.md`; + * Windows 系统:`hugo new posts\first-post.md`; + +5. 在文本编辑器中打开这个新建的 post 文件: + * Unix 系统:`gedit content/posts/first-post.md`; + * Windows 系统:`notepadd content\posts\first-post.md`; + +此刻,你可以疯狂起来了。注意到你的提交文件中包括两个部分。第一部分是以 `+++` 符号分隔开的。它包括了提交文档的主要数据,例如名称、时间等。在 Hugo 中,这叫做前缀。在前缀之后,才是正文。下面编辑第一个提交文件内容: + +``` ++++ +title = "First Post" +date = 2018-03-03T13:23:10+01:00 +draft = false +tags = ["Getting started"] +categories = [] ++++ + +Hello Hugo world! No more excuses for having no blog or documentation now! +``` + +现在你要做的就是启动你的服务器:`hugo server -D`;然后打开浏览器,输入 `http://localhost:1313/`。 + +![](https://opensource.com/sites/default/files/styles/panopoly_image_original/public/u128651/hugo_3.png?itok=I-_v0qLx) + +### 20-30 分钟:调整网站 + +前面的工作很完美,但还有一些问题需要解决。例如,简单地命名你的站点: + +1. 终端中按下 `Ctrl+C` 以停止服务器。 +2. 打开 `config.toml`,编辑博客的名称,版权,你的姓名,社交网站等等。 + +当你再次启动服务器后,你会发现博客私人订制味道更浓了。不过,还少一个重要的基础内容:主菜单。快速的解决这个问题。返回 `config.toml` 文件,在末尾插入如下一段: + +``` +[[menu.main]] + name = "Home" #Name in the navigation bar + weight = 10 #The larger the weight, the more on the right this item will be + url = "/" #URL address +[[menu.main]] + name = "Posts" + weight = 20 + url = "/posts/" +``` + +上面这段代码添加了 `Home` 和 `Posts` 到主菜单中。你还需要一个 `About` 页面。这次是创建一个 `.md` 文件,而不是编辑 `config.toml` 文件: + +1. 创建 `about.md` 文件:`hugo new about.md` 。注意它是 `about.md`,不是 `posts/about.md`。该页面不是博客提交内容,所以你不想它显示到博客内容提交当中吧。 +2. 用文本编辑器打开该文件,输入如下一段: + +``` ++++ +title = "About" +date = 2018-03-03T13:50:49+01:00 +menu = "main" #Display this page on the nav menu +weight = "30" #Right-most nav item +meta = "false" #Do not display tags or categories ++++ + +> Waves are the practice of the water. Shunryu Suzuki +``` + +当你启动你的服务器并输入:`http://localhost:1313/`,你将会看到你的博客。(访问我 Gihub 主页上的 [例子][6] )如果你想让文章的菜单栏和 Github 相似,给 `themes/kiera/static/css/styles.css` 打上这个 [补丁][7]。 + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/3/start-blog-30-minutes-hugo + +作者:[Marek Czernek][a] 
译者:[jrg](https://github.com/jrglinux) 
校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://opensource.com/users/mczernek +[1]:https://gohugo.io/ +[2]:https://github.com/gohugoio/hugo/releases +[3]:https://gohugo.io/getting-started/installing/ +[4]:https://themes.gohugo.io/ +[5]:https://github.com/avianto/hugo-kiera +[6]:https://m-czernek.github.io/awesome-blog/ +[7]:https://github.com/avianto/hugo-kiera/pull/18/files diff --git a/published/20180402 Understanding Linux filesystems- ext4 and beyond.md b/published/20180402 Understanding Linux filesystems- ext4 and beyond.md new file mode 100644 index 0000000000..e091f265d3 --- /dev/null +++ b/published/20180402 Understanding Linux filesystems- ext4 and beyond.md @@ -0,0 +1,258 @@ +理解 ext4 等 Linux 文件系统 +====== + +> 了解 ext4 的历史,包括其与 ext3 和之前的其它文件系统之间的区别。 + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/rh_003499_01_linux11x_cc.png?itok=XMDOouJR) + +目前的大部分 Linux 文件系统都默认采用 ext4 文件系统,正如以前的 Linux 发行版默认使用 ext3、ext2 以及更久前的 ext。 + +对于不熟悉 Linux 或文件系统的朋友而言,你可能不清楚 ext4 相对于上一版本 ext3 带来了什么变化。你可能还想知道在一连串关于替代的文件系统例如 Btrfs、XFS 和 ZFS 不断被发布的情况下,ext4 是否仍然能得到进一步的发展。 + +在一篇文章中,我们不可能讲述文件系统的所有方面,但我们尝试让你尽快了解 Linux 默认文件系统的发展历史,包括它的诞生以及未来发展。 + +我仔细研究了维基百科里的各种关于 ext 文件系统文章、kernel.org 的 wiki 中关于 ext4 的条目以及结合自己的经验写下这篇文章。 + +### ext 简史 + +#### MINIX 文件系统 + +在有 ext 之前,使用的是 MINIX 文件系统。如果你不熟悉 Linux 历史,那么可以理解为 MINIX 是用于 IBM PC/AT 微型计算机的一个非常小的类 Unix 系统。Andrew Tannenbaum 为了教学的目的而开发了它,并于 1987 年发布了源代码(以印刷版的格式!)。 + +![](https://opensource.com/sites/default/files/styles/panopoly_image_original/public/u128651/ibm_pc_at.jpg?itok=Tfk3hQYB) + +*IBM 1980 中期的 PC/AT,[MBlairMartin](https://commons.wikimedia.org/wiki/File:IBM_PC_AT.jpg),[CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/deed.en)* + +虽然你可以细读 MINIX 的源代码,但实际上它并不是自由开源软件(FOSS)。出版 Tannebaum 著作的出版商要求你花 69 美元的许可费来运行 MINIX,而这笔费用包含在书籍的费用中。尽管如此,在那时来说非常便宜,并且 MINIX 的使用得到迅速发展,很快超过了 Tannebaum 当初使用它来教授操作系统编码的意图。在整个 20 世纪 90 年代,你可以发现 MINIX 的安装在世界各个大学里面非常流行。而此时,年轻的 Linus Torvalds 使用 MINIX 来开发原始 Linux 内核,并于 1991 年首次公布,而后在 1992 年 12 月在 GPL 开源协议下发布。 + +但是等等,这是一篇以 *文件系统* 为主题的文章不是吗?是的,MINIX 有自己的文件系统,早期的 Linux 版本依赖于它。跟 MINIX 一样,Linux 的文件系统也如同玩具那般小 —— MINIX 文件系统最多能处理 14 个字符的文件名,并且只能处理 64MB 的存储空间。到了 1991 年,一般的硬盘尺寸已经达到了 40-140 MB。很显然,Linux 需要一个更好的文件系统。 + +#### ext + +当 Linus 开发出刚起步的 Linux 内核时,Rémy Card 从事第一代的 ext 文件系统的开发工作。ext 文件系统在 1992 年首次实现并发布 —— 仅在 Linux 首次发布后的一年!—— ext 解决了 MINIX 文件系统中最糟糕的问题。 + +1992 年的 ext 使用在 Linux 内核中的新虚拟文件系统(VFS)抽象层。与之前的 MINIX 文件系统不同的是,ext 可以处理高达 2 GB 存储空间并处理 255 个字符的文件名。 + +但 ext 并没有长时间占统治地位,主要是由于它原始的时间戳(每个文件仅有一个时间戳,而不是今天我们所熟悉的有 inode、最近文件访问时间和最新文件修改时间的时间戳。)仅仅一年后,ext2 就替代了它。 + +#### ext2 + +Rémy 很快就意识到 ext 的局限性,所以一年后他设计出 ext2 替代它。当 ext 仍然根植于 “玩具” 操作系统时,ext2 从一开始就被设计为一个商业级文件系统,沿用 BSD 的 Berkeley 文件系统的设计原理。 + +ext2 提供了 GB 级别的最大文件大小和 TB 级别的文件系统大小,使其在 20 世纪 90 年代的地位牢牢巩固在文件系统大联盟中。很快它被广泛地使用,无论是在 Linux 内核中还是最终在 MINIX 中,且利用第三方模块可以使其应用于 MacOS 和 Windows。 + +但这里仍然有一些问题需要解决:ext2 文件系统与 20 世纪 90 年代的大多数文件系统一样,如果在将数据写入到磁盘的时候,系统发生崩溃或断电,则容易发生灾难性的数据损坏。随着时间的推移,由于碎片(单个文件存储在多个位置,物理上其分散在旋转的磁盘上),它们也遭受了严重的性能损失。 + +尽管存在这些问题,但今天 ext2 还是用在某些特殊的情况下 —— 最常见的是,作为便携式 USB 驱动器的文件系统格式。 + +#### ext3 + +1998 年,在 ext2 被采用后的 6 年后,Stephen Tweedie 宣布他正在致力于改进 ext2。这成了 ext3,并于 2001 年 11 月在 2.4.15 内核版本中被采用到 Linux 内核主线中。 + +![Packard Bell 计算机][2] + +*20 世纪 90 年代中期的 Packard Bell 计算机,[Spacekid][3],[CC0][4]* + +在大部分情况下,ext2 在 Linux 发行版中工作得很好,但像 FAT、FAT32、HFS 和当时的其它文件系统一样 —— 在断电时容易发生灾难性的破坏。如果在将数据写入文件系统时候发生断电,则可能会将其留在所谓 *不一致* 的状态 —— 事情只完成一半而另一半未完成。这可能导致大量文件丢失或损坏,这些文件与正在保存的文件无关甚至导致整个文件系统无法卸载。 + +ext3 和 20 世纪 90 年代后期的其它文件系统,如微软的 NTFS,使用 *日志* 来解决这个问题。日志是磁盘上的一种特殊的分配区域,其写入被存储在事务中;如果该事务完成磁盘写入,则日志中的数据将提交给文件系统自身。如果系统在该操作提交前崩溃,则重新启动的系统识别其为未完成的事务而将其进行回滚,就像从未发生过一样。这意味着正在处理的文件可能依然会丢失,但文件系统 *本身* 保持一致,且其它所有数据都是安全的。 + +在使用 ext3 文件系统的 Linux 内核中实现了三个级别的日志记录方式:日记journal顺序ordered回写writeback。 + +* **日记** 是最低风险模式,在将数据和元数据提交给文件系统之前将其写入日志。这可以保证正在写入的文件与整个文件系统的一致性,但其显著降低了性能。 +* **顺序** 是大多数 Linux 发行版默认模式;顺序模式将元数据写入日志而直接将数据提交到文件系统。顾名思义,这里的操作顺序是固定的:首先,元数据提交到日志;其次,数据写入文件系统,然后才将日志中关联的元数据更新到文件系统。这确保了在发生崩溃时,那些与未完整写入相关联的元数据仍在日志中,且文件系统可以在回滚日志时清理那些不完整的写入事务。在顺序模式下,系统崩溃可能导致在崩溃期间文件的错误被主动写入,但文件系统它本身 —— 以及未被主动写入的文件 —— 确保是安全的。 +* **回写** 是第三种模式 —— 也是最不安全的日志模式。在回写模式下,像顺序模式一样,元数据会被记录到日志,但数据不会。与顺序模式不同,元数据和数据都可以以任何有利于获得最佳性能的顺序写入。这可以显著提高性能,但安全性低很多。尽管回写模式仍然保证文件系统本身的安全性,但在崩溃或崩溃之前写入的文件很容易丢失或损坏。 + +跟之前的 ext2 类似,ext3 使用 16 位内部寻址。这意味着对于有着 4K 块大小的 ext3 在最大规格为 16 TiB 的文件系统中可以处理的最大文件大小为 2 TiB。 + +#### ext4 + +Theodore Ts'o(是当时 ext3 主要开发人员)在 2006 年发表的 ext4,于两年后在 2.6.28 内核版本中被加入到了 Linux 主线。 + +Ts'o 将 ext4 描述为一个显著扩展 ext3 但仍然依赖于旧技术的临时技术。他预计 ext4 终将会被真正的下一代文件系统所取代。 + +![](https://opensource.com/sites/default/files/styles/panopoly_image_original/public/u128651/dell_precision_380_workstation.jpeg?itok=3EjYXY2i) + +*Dell Precision 380 工作站,[Lance Fisher](https://commons.wikimedia.org/wiki/File:Dell_Precision_380_Workstation.jpeg),[CC BY-SA 2.0](https://creativecommons.org/licenses/by-sa/2.0/deed.en)* + +ext4 在功能上与 ext3 在功能上非常相似,但支持大文件系统,提高了对碎片的抵抗力,有更高的性能以及更好的时间戳。 + +### ext4 vs ext3 + +ext3 和 ext4 有一些非常明确的差别,在这里集中讨论下。 + +#### 向后兼容性 + +ext4 特地设计为尽可能地向后兼容 ext3。这不仅允许 ext3 文件系统原地升级到 ext4;也允许 ext4 驱动程序以 ext3 模式自动挂载 ext3 文件系统,因此使它无需单独维护两个代码库。 + +#### 大文件系统 + +ext3 文件系统使用 32 位寻址,这限制它仅支持 2 TiB 文件大小和 16 TiB 文件系统系统大小(这是假设在块大小为 4 KiB 的情况下,一些 ext3 文件系统使用更小的块大小,因此对其进一步被限制)。 + +ext4 使用 48 位的内部寻址,理论上可以在文件系统上分配高达 16 TiB 大小的文件,其中文件系统大小最高可达 1000000 TiB(1 EiB)。在早期 ext4 的实现中有些用户空间的程序仍然将其限制为最大大小为 16 TiB 的文件系统,但截至 2011 年,e2fsprogs 已经直接支持大于 16 TiB 大小的 ext4 文件系统。例如,红帽企业 Linux 在其合同上仅支持最高 50 TiB 的 ext4 文件系统,并建议 ext4 卷不超过 100 TiB。 + +#### 分配方式改进 + +ext4 在将存储块写入磁盘之前对存储块的分配方式进行了大量改进,这可以显著提高读写性能。 + +##### 区段 + +区段extent是一系列连续的物理块 (最多达 128 MiB,假设块大小为 4 KiB),可以一次性保留和寻址。使用区段可以减少给定文件所需的 inode 数量,并显著减少碎片并提高写入大文件时的性能。 + +##### 多块分配 + +ext3 为每一个新分配的块调用一次块分配器。当多个写入同时打开分配器时,很容易导致严重的碎片。然而,ext4 使用延迟分配,这允许它合并写入并更好地决定如何为尚未提交的写入分配块。 + +##### 持久的预分配 + +在为文件预分配磁盘空间时,大部分文件系统必须在创建时将零写入该文件的块中。ext4 允许替代使用 `fallocate()`,它保证了空间的可用性(并试图为它找到连续的空间),而不需要先写入它。这显著提高了写入和将来读取流和数据库应用程序的写入数据的性能。 + +##### 延迟分配 + +这是一个耐人寻味而有争议性的功能。延迟分配允许 ext4 等待分配将写入数据的实际块,直到它准备好将数据提交到磁盘。(相比之下,即使数据仍然在往写入缓存中写入,ext3 也会立即分配块。) + +当缓存中的数据累积时,延迟分配块允许文件系统对如何分配块做出更好的选择,降低碎片(写入,以及稍后的读)并显著提升性能。然而不幸的是,它 *增加* 了还没有专门调用 `fsync()` 方法(当程序员想确保数据完全刷新到磁盘时)的程序的数据丢失的可能性。 + +假设一个程序完全重写了一个文件: + +``` +fd=open("file", O_TRUNC); write(fd, data); close(fd); +``` + +使用旧的文件系统,`close(fd);` 足以保证 `file` 中的内容刷新到磁盘。即使严格来说,写不是事务性的,但如果文件关闭后发生崩溃,则丢失数据的风险很小。 + +如果写入不成功(由于程序上的错误、磁盘上的错误、断电等),文件的原始版本和较新版本都可能丢失数据或损坏。如果其它进程在写入文件时访问文件,则会看到损坏的版本。如果其它进程打开文件并且不希望其内容发生更改 —— 例如,映射到多个正在运行的程序的共享库。这些进程可能会崩溃。 + +为了避免这些问题,一些程序员完全避免使用 `O_TRUNC`。相反,他们可能会写入一个新文件,关闭它,然后将其重命名为旧文件名: + +``` +fd=open("newfile"); write(fd, data); close(fd); rename("newfile", "file"); +``` + +在 *没有* 延迟分配的文件系统下,这足以避免上面列出的潜在的损坏和崩溃问题:因为 `rename()` 是原子操作,所以它不会被崩溃中断;并且运行的程序将继续引用旧的文件。现在 `file` 的未链接版本只要有一个打开的文件文件句柄即可。但是因为 ext4 的延迟分配会导致写入被延迟和重新排序,`rename("newfile", "file")` 可以在 `newfile` 的内容实际写入磁盘内容之前执行,这出现了并行进行再次获得 `file` 坏版本的问题。 + +为了缓解这种情况,Linux 内核(自版本 2.6.30)尝试检测这些常见代码情况并强制立即分配。这会减少但不能防止数据丢失的可能性 —— 并且它对新文件没有任何帮助。如果你是一位开发人员,请注意:保证数据立即写入磁盘的唯一方法是正确调用 `fsync()`。 + +#### 无限制的子目录 + +ext3 仅限于 32000 个子目录;ext4 允许无限数量的子目录。从 2.6.23 内核版本开始,ext4 使用 HTree 索引来减少大量子目录的性能损失。 + +#### 日志校验 + +ext3 没有对日志进行校验,这给处于内核直接控制之外的磁盘或自带缓存的控制器设备带来了问题。如果控制器或具自带缓存的磁盘脱离了写入顺序,则可能会破坏 ext3 的日记事务顺序,从而可能破坏在崩溃期间(或之前一段时间)写入的文件。 + +理论上,这个问题可以使用写入障碍barrier —— 在安装文件系统时,你在挂载选项设置 `barrier=1`,然后设备就会忠实地执行 `fsync` 一直向下到底层硬件。通过实践,可以发现存储设备和控制器经常不遵守写入障碍 —— 提高性能(和跟竞争对手比较的性能基准),但增加了本应该防止数据损坏的可能性。 + +对日志进行校验和允许文件系统崩溃后第一次挂载时意识到其某些条目是无效或无序的。因此,这避免了回滚部分条目或无序日志条目的错误,并进一步损坏的文件系统 —— 即使部分存储设备假做或不遵守写入障碍。 + +#### 快速文件系统检查 + +在 ext3 下,在 `fsck` 被调用时会检查整个文件系统 —— 包括已删除或空文件。相比之下,ext4 标记了 inode 表未分配的块和扇区,从而允许 `fsck` 完全跳过它们。这大大减少了在大多数文件系统上运行 `fsck` 的时间,它实现于内核 2.6.24。 + +#### 改进的时间戳 + +ext3 提供粒度为一秒的时间戳。虽然足以满足大多数用途,但任务关键型应用程序经常需要更严格的时间控制。ext4 通过提供纳秒级的时间戳,使其可用于那些企业、科学以及任务关键型的应用程序。 + +ext3 文件系统也没有提供足够的位来存储 2038 年 1 月 18 日以后的日期。ext4 在这里增加了两个位,将 [Unix 纪元][5]扩展了 408 年。如果你在公元 2446 年读到这篇文章,你很有可能已经转移到一个更好的文件系统 —— 如果你还在测量自 1970 年 1 月 1 日 00:00(UTC)以来的时间,这会让我死后得以安眠。 + +#### 在线碎片整理 + +ext2 和 ext3 都不直接支持在线碎片整理 —— 即在挂载时会对文件系统进行碎片整理。ext2 有一个包含的实用程序 `e2defrag`,它的名字暗示 —— 它需要在文件系统未挂载时脱机运行。(显然,这对于根文件系统来说非常有问题。)在 ext3 中的情况甚至更糟糕 —— 虽然 ext3 比 ext2 更不容易受到严重碎片的影响,但 ext3 文件系统运行 `e2defrag` 可能会导致灾难性损坏和数据丢失。 + +尽管 ext3 最初被认为“不受碎片影响”,但对同一文件(例如 BitTorrent)采用大规模并行写入过程的过程清楚地表明情况并非完全如此。一些用户空间的手段和解决方法,例如 [Shake][6],以这样或那样方式解决了这个问题 —— 但它们比真正的、文件系统感知的、内核级碎片整理过程更慢并且在各方面都不太令人满意。 + +ext4 通过 `e4defrag` 解决了这个问题,且是一个在线、内核模式、文件系统感知、块和区段级别的碎片整理实用程序。 + +### 正在进行的 ext4 开发 + +ext4,正如 Monty Python 中瘟疫感染者曾经说过的那样,“我还没死呢!”虽然它的[主要开发人员][7]认为它只是一个真正的[下一代文件系统][8]的权宜之计,但是在一段时间内,没有任何可能的候选人准备好(由于技术或许可问题)部署为根文件系统。 + +在未来的 ext4 版本中仍然有一些关键功能要开发,包括元数据校验和、一流的配额支持和大分配块。 + +#### 元数据校验和 + +由于 ext4 具有冗余超级块,因此为文件系统校验其中的元数据提供了一种方法,可以自行确定主超级块是否已损坏并需要使用备用块。可以在没有校验和的情况下,从损坏的超级块恢复 —— 但是用户首先需要意识到它已损坏,然后尝试使用备用方法手动挂载文件系统。由于在某些情况下,使用损坏的主超级块安装文件系统读写可能会造成进一步的损坏,即使是经验丰富的用户也无法避免,这也不是一个完美的解决方案! + +与 Btrfs 或 ZFS 等下一代文件系统提供的极其强大的每块校验和相比,ext4 的元数据校验和的功能非常弱。但它总比没有好。虽然校验 **所有的事情** 都听起来很简单!—— 事实上,将校验和与文件系统连接到一起有一些重大的挑战;请参阅[设计文档][9]了解详细信息。 + +#### 一流的配额支持 + +等等,配额?!从 ext2 出现的那天开始我们就有了这些!是的,但它们一直都是事后的添加的东西,而且它们总是犯傻。这里可能不值得详细介绍,但[设计文档][10]列出了配额将从用户空间移动到内核中的方式,并且能够更加正确和高效地执行。 + +#### 大分配块 + +随着时间的推移,那些讨厌的存储系统不断变得越来越大。由于一些固态硬盘已经使用 8K 硬件块大小,因此 ext4 对 4K 模块的当前限制越来越受到限制。较大的存储块可以显著减少碎片并提高性能,代价是增加“松弛”空间(当你只需要块的一部分来存储文件或文件的最后一块时留下的空间)。 + +你可以在[设计文档][11]中查看详细说明。 + +### ext4 的实际限制 + +ext4 是一个健壮、稳定的文件系统。如今大多数人都应该在用它作为根文件系统,但它无法处理所有需求。让我们简单地谈谈你不应该期待的一些事情 —— 现在或可能在未来: + +虽然 ext4 可以处理高达 1 EiB 大小(相当于 1,000,000 TiB)大小的数据,但你 *真的* 不应该尝试这样做。除了能够记住更多块的地址之外,还存在规模上的问题。并且现在 ext4 不会处理(并且可能永远不会)超过 50-100 TiB 的数据。 + +ext4 也不足以保证数据的完整性。随着日志记录的重大进展又回到了 ext3 的那个时候,它并未涵盖数据损坏的许多常见原因。如果数据已经在磁盘上被[破坏][12] —— 由于故障硬件,宇宙射线的影响(是的,真的),或者只是数据随时间衰减 —— ext4 无法检测或修复这种损坏。 + +基于上面两点,ext4 只是一个纯 *文件系统*,而不是存储卷管理器。这意味着,即使你有多个磁盘 —— 也就是奇偶校验或冗余,理论上你可以从 ext4 中恢复损坏的数据,但无法知道使用它是否对你有利。虽然理论上可以在不同的层中分离文件系统和存储卷管理系统而不会丢失自动损坏检测和修复功能,但这不是当前存储系统的设计方式,并且它将给新设计带来重大挑战。 + +### 备用文件系统 + +在我们开始之前,提醒一句:要非常小心,没有任何备用的文件系统作为主线内核的一部分而内置和直接支持! + +即使一个文件系统是 *安全的*,如果在内核升级期间出现问题,使用它作为根文件系统也是非常可怕的。如果你没有充分的理由通过一个 chroot 去使用替代介质引导,耐心地操作内核模块、grub 配置和 DKMS……不要在一个很重要的系统中去掉预留的根文件。 + +可能有充分的理由使用你的发行版不直接支持的文件系统 —— 但如果你这样做,我强烈建议你在系统启动并可用后再安装它。(例如,你可能有一个 ext4 根文件系统,但是将大部分数据存储在 ZFS 或 Btrfs 池中。) + +#### XFS + +XFS 与非 ext 文件系统在 Linux 中的主线中的地位一样。它是一个 64 位的日志文件系统,自 2001 年以来内置于 Linux 内核中,为大型文件系统和高度并发性提供了高性能(即大量的进程都会立即写入文件系统)。 + +从 RHEL 7 开始,XFS 成为 Red Hat Enterprise Linux 的默认文件系统。对于家庭或小型企业用户来说,它仍然有一些缺点 —— 最值得注意的是,重新调整现有 XFS 文件系统是一件非常痛苦的事情,不如创建另一个并复制数据更有意义。 + +虽然 XFS 是稳定的且是高性能的,但它和 ext4 之间没有足够具体的最终用途差异,以值得推荐在非默认(如 RHEL7)的任何地方使用它,除非它解决了对 ext4 的特定问题,例如大于 50 TiB 容量的文件系统。 + +XFS 在任何方面都不是 ZFS、Btrfs 甚至 WAFL(一个专有的 SAN 文件系统)的“下一代”文件系统。就像 ext4 一样,它应该被视为一种更好的方式的权宜之计。 + +#### ZFS + +ZFS 由 Sun Microsystems 开发,以 zettabyte 命名 —— 相当于 1 万亿 GB —— 因为它理论上可以解决大型存储系统。 + +作为真正的下一代文件系统,ZFS 提供卷管理(能够在单个文件系统中处理多个单独的存储设备),块级加密校验和(允许以极高的准确率检测数据损坏),[自动损坏修复][12](其中冗余或奇偶校验存储可用),[快速异步增量复制][13],内联压缩等,[以及更多][14]。 + +从 Linux 用户的角度来看,ZFS 的最大问题是许可证问题。ZFS 许可证是 CDDL 许可证,这是一种与 GPL 冲突的半许可的许可证。关于在 Linux 内核中使用 ZFS 的意义存在很多争议,其争议范围从“它是 GPL 违规”到“它是 CDDL 违规”到“它完全没问题,它还没有在法庭上进行过测试。”最值得注意的是,自 2016 年以来 Canonical 已将 ZFS 代码内联在其默认内核中,而且目前尚无法律挑战。 + +此时,即使我作为一个非常狂热于 ZFS 的用户,我也不建议将 ZFS 作为 Linux 的根文件系统。如果你想在 Linux 上利用 ZFS 的优势,用 ext4 设置一个小的根文件系统,然后将 ZFS 用在你剩余的存储上,把数据、应用程序以及你喜欢的东西放在它上面 —— 但把 root 分区保留在 ext4 上,直到你的发行版明确支持 ZFS 根目录。 + +#### Btrfs + +Btrfs 是 B-Tree Filesystem 的简称,通常发音为 “butter” —— 由 Chris Mason 于 2007 年在 Oracle 任职期间发布。Btrfs 旨在跟 ZFS 有大部分相同的目标,提供多种设备管理、每块校验、异步复制、直列压缩等,[还有更多][8]。 + +截至 2018 年,Btrfs 相当稳定,可用作标准的单磁盘文件系统,但可能不应该依赖于卷管理器。与许多常见用例中的 ext4、XFS 或 ZFS 相比,它存在严重的性能问题,其下一代功能 —— 复制、多磁盘拓扑和快照管理 —— 可能非常多,其结果可能是从灾难性地性能降低到实际数据的丢失。 + +Btrfs 的维持状态是有争议的;SUSE Enterprise Linux 在 2015 年采用它作为默认文件系统,而 Red Hat 于 2017 年宣布它从 RHEL 7.4 开始不再支持 Btrfs。可能值得注意的是,该产品支持 Btrfs 部署用作单磁盘文件系统,而不是像 ZFS 中的多磁盘卷管理器,甚至 Synology 在它的存储设备使用 Btrfs,但是它在传统 Linux 内核 RAID(mdraid)之上分层来管理磁盘。 + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/4/ext4-filesystem + +作者:[Jim Salter][a] +译者:[HardworkFish](https://github.com/HardworkFish) +校对:[wxy](https://github.com/wxy), [pityonline](https://github.com/pityonline) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://opensource.com/users/jim-salter +[1]: https://opensource.com/file/391546 +[2]: https://opensource.com/sites/default/files/styles/panopoly_image_original/public/u128651/packard_bell_pc.jpg?itok=VI8dzcwp (Packard Bell computer) +[3]: https://commons.wikimedia.org/wiki/File:Old_packard_bell_pc.jpg +[4]: https://creativecommons.org/publicdomain/zero/1.0/deed.en +[5]: https://en.wikipedia.org/wiki/Unix_time +[6]: https://vleu.net/shake/ +[7]: http://www.linux-mag.com/id/7272/ +[8]: https://arstechnica.com/information-technology/2014/01/bitrot-and-atomic-cows-inside-next-gen-filesystems/ +[9]: https://ext4.wiki.kernel.org/index.php/Ext4_Metadata_Checksums +[10]: https://ext4.wiki.kernel.org/index.php/Design_For_1st_Class_Quota_in_Ext4 +[11]: https://ext4.wiki.kernel.org/index.php/Design_for_Large_Allocation_Blocks +[12]: https://en.wikipedia.org/wiki/Data_degradation#Visual_example_of_data_degradation +[13]: https://arstechnica.com/information-technology/2015/12/rsync-net-zfs-replication-to-the-cloud-is-finally-here-and-its-fast/ +[14]: https://arstechnica.com/information-technology/2014/02/ars-walkthrough-using-the-zfs-next-gen-filesystem-on-linux/ diff --git a/published/20180424 A gentle introduction to FreeDOS.md b/published/20180424 A gentle introduction to FreeDOS.md new file mode 100644 index 0000000000..11c43870fd --- /dev/null +++ b/published/20180424 A gentle introduction to FreeDOS.md @@ -0,0 +1,110 @@ +FreeDOS 的简单介绍 +====== +> 学习如何穿行于 C:\ 提示符下,就像上世纪 90 年代的 DOS 高手一样。 + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/freedos-fish-laptop-color.png?itok=vfv_Lpph) + +FreeDOS 是一个古老的操作系统,但是对于多数人而言它又是陌生的。在 1994 年,我和几个开发者一起 [开发了 FreeDOS][1] —— 这是一个完整、自由、兼容 DOS 的操作系统,你可以用它来玩经典的 DOS 游戏、运行过时的商业软件或者开发嵌入式系统。任何在 MS-DOS 下工作的程序在 FreeDOS 下也可以运行。 + +在 1994 年,任何一个曾经使用过微软的商业版 MS-DOS 的人都会迅速地熟悉 FreeDOS。这是设计而为之的;FreeDOS 尽可能地去模仿 MS-DOS。结果,1990 年代的 DOS 用户能够直接转换到 FreeDOS。但是,时代变了。今天,开源的开发者们对于 Linux 命令行更熟悉,或者他们可能倾向于像 [GNOME][2] 一样的图形桌面环境,这导致 FreeDOS 命令行界面最初看起来像个异类。 + +新的用户通常会问,“我已经安装了 [FreeDOS][3],但是如何使用呢?”。如果你之前并没有使用过 DOS,那么闪烁的 `C:\>` DOS 提示符看起来会有点不太友好,而且可能有点吓人。这份 FreeDOS 的简单介绍将带你起步。它只提供了基础:如何浏览以及如何查看文件。如果你想了解比这里提及的更多的知识,访问 [FreeDOS 维基][4]。 + +### DOS 提示符 + +首先,让我们看一下空的提示符以及它的含义。 + +![](https://opensource.com/sites/default/files/u128651/0-prompt.png) + +DOS 是在个人电脑从软盘运行时期创建的一个“磁盘操作系统disk operating system”。甚至当电脑支持硬盘了,在 1980 年代和 1990 年代,频繁地在不同的驱动器之间切换也是很普遍的。举例来说,你可能想将最重要的文件都备份一份拷贝到软盘中。 + +DOS 使用一个字母来指代每个驱动器。早期的电脑仅拥有两个软盘驱动器,他们被分配了 `A:` 和 `B:` 盘符。硬盘上的第一个分区盘符是 `C:` ,然后其它的盘符依次这样分配下去。提示符中的 `C:` 表示你正在使用第一个硬盘的第一个分区。 + +从 1983 年的 PC-DOS 2.0 开始,DOS 也支持目录和子目录,非常类似 Linux 文件系统中的目录和子目录。但是跟 Linux 不一样的是,DOS 目录名由 `\` 分隔而不是 `/`。将这个与驱动器字母合起来看,提示符中的 `C:\` 表示你正在 `C:` 盘的顶端或者“根”目录。 + +`>` 符号是提示你输入 DOS 命令的地方,就像众多 Linux shell 的 `$`。`>` 前面的部分告诉你当前的工作目录,然后你在 `>` 提示符这输入命令。 + +### 在 DOS 中找到你的使用方式 + +在 DOS 中浏览目录的基本方式和你在 Linux 命令行下的步骤非常相似。你仅需要记住少数的命令。 + +#### 显示一个目录 + +当你想要查看当前目录的内容时,使用 `DIR` 命令。因为 DOS 命令是大小写不敏感的,你也可以输入 `dir`。默认地,DOS 会显示每个文件和子目录的细节,包括了名字、扩展类型、大小以及最后一次更改的日期和时间。 + +![](https://opensource.com/sites/default/files/u128651/1-dir.png) + +如果你不想显示单个文件大小的额外细节,你可以在 `DIR` 命令中使用 `/w` 选项来显示一个“宽”的目录列表。注意,Linux 用户使用连字号(`-`)或者双连字号(`--`)来开始命令行选项,而 DOS 使用斜线字符(`/`)。 + +![](https://opensource.com/sites/default/files/u128651/2-dirw.png) + +你可以将特定子目录的路径名作为参数传递给 `DIR` 命令来查看它。此外,另一个与 Linux 系统的区别是 Linux 文件和目录是大小写敏感的,而 DOS 下的名称是大小写不敏感的。DOS 通常将文件和目录使用全部大写的方式显示,不过你可以等同地用小写格式来使用它们。 + +![](https://opensource.com/sites/default/files/u128651/3-dir-fdos.png) + + +#### 切换当前工作目录 + +一旦你能够查看一个目录的内容,你就能够“移动到”任何其它的目录。在 DOS 上,使用 `CHDIR` 命令来切换工作目录,也可以简写为 `CD`。你可以使用类似 `CD CHOICE` 的命令进入到一个子目录或者使用 `CD \FDOS\DOC\CHOICE` 进入到一个新的路径。 + +![](https://opensource.com/sites/default/files/u128651/5-dir-choice.png) + +就像在 Linux 命令行,DOS 使用 `.` 来表示当前目录,而 `..` 表示父目录(当前目录的上一级)。你可以将这些组合起来使用。比如,`CD ..` 进入到父目录,然后 `CD ..\..` 由当前目录做两个“向上”目录级别的操作。 + +![](https://opensource.com/sites/default/files/u128651/11-cd.png) + +FreeDOS 也从 Linux 那借鉴了一些特性:你可以使用 `CD -` 跳转回之前的工作目录。在你进入一个新的路径做完一件事之后,想要回退到之前工作状态的情况下,这会很方便。 + +#### 切换当前工作盘符 + +在 Linux 下,“磁盘”的概念是隐藏的。在 Linux 和其它 Unix 系统中,你“挂载”磁盘到一个目录,例如 `/backup`,或者系统自动帮你完成,比如 `/var/run/media/user/flashdrive`。但是 DOS 是一个相对简单的系统。使用 DOS,你必须自行更改工作磁盘。 + +记住 DOS 分配第一块硬盘的第一个分区为 `C:` 盘,然后这样依次分配其它盘符。在现代系统中,人们很少将硬盘分割成多个 DOS 分区;他们简单地使用整个磁盘或者尽可能多地分配给 DOS。如今 `C:` 通常是第一块硬盘,而 `D:` 通常是另一块硬盘或者 CD-ROM 驱动器。其它的网络磁盘驱动器也可以被映射到别的盘符,比如 `E:` 或者 `Z:` 或者任何你想要的组织方式。 + +在 DOS 下切换磁盘很容易。只要在命令行输入盘符后附加一个冒号(`:`),然后 DOS 就会切换到该工作磁盘。举例来说,在我的 [QEMU][5] 系统上,我将 `D:` 设置到我的 Linux 主目录下的一个共享目录,那里存放了各种我想测试的 DOS 应用程序和游戏的安装文件。 + +![](https://opensource.com/sites/default/files/u128651/8-d-dirw.png) + +小心不要尝试切换到一个不存在的磁盘。DOS 可能会将它设置为工作磁盘,但是如果你尝试在那做任何事,你将会遇到略微臭名昭著的“退出、重试、失败Abort, Retry, Fail” DOS 错误信息。 + +![](https://opensource.com/sites/default/files/u128651/9-e-fail.png) + +### 其它可以尝试的事情 + +使用 `CD` 和 `DIR` 命令,你就拥有了基础的浏览 DOS 能力。这些命令允许你查找 DOS 目录并查看其他子目录和文件的存在。一旦你熟悉基础浏览操作,你还可以尝试其它的这些基础 DOS 命令: + + * `MKDIR` 或 `MD` 创建新的目录 + * `RMDIR` 或 `RD` 删除目录 + * `TREE` 以树状格式显示目录和子目录列表 + * `TYPE` 和 `MORE` 显示文件内容 + * `RENAME` 或 `REN` 重命名文件 + * `DEL` 或 `ERASE` 删除文件 + * `EDIT` 编辑文件 + * `CLS` 清除屏幕 + + +如果这些还不够,你可以在 FreeDOS 维基上面找到[所有 DOS 命令][6]的清单。 + +在 FreeDOS 下,针对每个命令你都能够使用 `/?` 参数来获取简要的说明。举例来说,`EDIT /?` 会告诉你编辑器的用法和选项。或者你可以输入 `HELP` 来使用交互式帮助系统。 + +像任何一个 DOS 一样,FreeDOS 被认为是一个简单的操作系统。仅使用一些基本命令就可以轻松浏览 DOS 文件系统。那么,启动一个 QEMU 会话,安装 FreeDOS,然后尝试一下 DOS 命令行界面吧。也许它现在看起来就没那么吓人了。 + + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/4/gentle-introduction-freedos + +作者:[Jim Hall][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[icecoobe](https://github.com/icecoobe) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://opensource.com/users/jim-hall +[1]:https://opensource.com/article/17/10/freedos +[2]:https://opensource.com/article/17/8/gnome-20-anniversary +[3]:http://www.freedos.org/ +[4]:http://wiki.freedos.org/ +[5]:https://www.qemu.org/ +[6]:http://wiki.freedos.org/wiki/index.php/Dos_commands diff --git a/published/20180425 Understanding metrics and monitoring with Python - Opensource.com.md b/published/20180425 Understanding metrics and monitoring with Python - Opensource.com.md new file mode 100644 index 0000000000..29cf30dc41 --- /dev/null +++ b/published/20180425 Understanding metrics and monitoring with Python - Opensource.com.md @@ -0,0 +1,476 @@ +理解监测指标,并使用 Python 去监测它们 +====== +> 通过学习这些关键的术语和概念来理解 Python 应用监测。 + +![Understanding metrics and monitoring with Python](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/metrics_graph_stats_blue.png?itok=OKCc_60D "Understanding metrics and monitoring with Python") + +当我第一次看到术语“计数器counter”和“计量器gauge”和使用颜色及标记着“平均数”和“大于 90%”的数字图表时,我的反应之一是逃避。就像我看到它们一样,我并不感兴趣,因为我不理解它们是干什么的或如何去使用。因为我的工作不需要我去注意它们,它们被我完全无视。 + +这都是在两年以前的事了。随着我的职业发展,我希望去了解更多关于我们的网络应用程序的知识,而那个时候就是我开始去学习监测指标metrics的时候。 + +我的理解监测的学习之旅共有三个阶段(到目前为止),它们是: + +* 阶段 1:什么?(王顾左右) +* 阶段 2:没有指标,我们真的是瞎撞。 +* 阶段 3:出现不合理的指标我们该如何做? + +我现在处于阶段 2,我将分享到目前为止我学到了些什么。我正在向阶段 3 进发,在本文结束的位置我提供了一些我正在使用的学习资源。 + +我们开始吧! + +### 需要的软件 + +在文章中讨论时用到的 demo 都可以在 [我的 GitHub 仓库][6] 中找到。你需要安装 docker 和 docker-compose 才能使用它们。 + +### 为什么要监测? + +关于监测的主要原因是: + +* 理解 _正常的_ 和 _不正常的_ 系统和服务的特征 +* 做容量规划、弹性伸缩 +* 有助于排错 +* 了解软件/硬件改变的效果 +* 测量响应中的系统行为变化 +* 当系统出现意外行为时发出警报 + +### 指标和指标类型 + +从我们的用途来看,一个**指标**就是在一个给定*时间*点上的某些数量的 _测量_ 值。博客文章的总点击次数、参与讨论的总人数、在缓存系统中数据没有被找到的次数、你的网站上的已登录用户数 —— 这些都是指标的例子。 + +它们总体上可以分为三类: + +#### 计数器 + +以你的个人博客为例。你发布一篇文章后,过一段时间后,你希望去了解有多少点击量,这是一个只会增加的数字。这就是一个计数器counter指标。在你的博客文章的生命周期中,它的值从 0 开始增加。用图表来表示,一个计数器看起来应该像下面的这样: + +![Counter metric](https://opensource.com/sites/default/files/styles/panopoly_image_original/public/u128651/counter-graph.png?itok=BZYrB-Hn "Counter metric") + +*一个计数器指标总是在增加的。* + +#### 计量器 + +如果你想去跟踪你的博客每天或每周的点击量,而不是基于时间的总点击量。这种指标被称为一个计量器gauge,它的值可上可下。用图表来表示,一个计量器看起来应该像下面的样子: + +![gauge metric](https://opensource.com/sites/default/files/styles/panopoly_image_original/public/u128651/gauge-graph.png?itok=UA4u4cwz "gauge metric") + +*一个计量器指标可以增加或减少。* + +一个计量器的值在某些时间窗口内通常有一个最大值ceilingfloor。 + +#### 柱状图和计时器 + +柱状图histogram(在 Prometheus 中这么叫它)或计时器 timer(在 StatsD 中这么叫它)是一个跟踪 _已采样的观测结果_ 的指标。不像一个计数器类或计量器类指标,柱状图指标的值并不是显示为上或下的样式。我知道这可能并没有太多的意义,并且可能和一个计量器图看上去没有什么不同。它们的不同之处在于,你期望使用柱状图数据来做什么,而不是与一个计量器图做比较。因此,监测系统需要知道那个指标是一个柱状图类型,它允许你去做哪些事情。 + +![Histogram metric](https://opensource.com/sites/default/files/styles/panopoly_image_original/public/u128651/histogram-graph.png?itok=cHI1v7Ly "Histogram metric") + +*一个柱状图指标可以增加或减少。* + +### Demo 1:计算和报告指标 + +[Demo 1][7] 是使用 [Flask][8] 框架写的一个基本的 web 应用程序。它演示了我们如何去 _计算_ 和 _报告_ 指标。 + +在 `src` 目录中有 `app.py` 和 `src/helpers/middleware.py` 应用程序,包含以下内容: + +``` +from flask import request +import csv +import time + + +def start_timer(): +    request.start_time = time.time() + + +def stop_timer(response): +    # convert this into milliseconds for statsd +    resp_time = (time.time() - request.start_time)*1000 +    with open('metrics.csv', 'a', newline='') as f: +        csvwriter = csv.writer(f) +        csvwriter.writerow([str(int(time.time())), str(resp_time)]) + +    return response + + +def setup_metrics(app): +    app.before_request(start_timer) +    app.after_request(stop_timer) +``` + +当在应用程序中调用 `setup_metrics()` 时,它配置在一个请求被处理之前调用 `start_timer()` 函数,然后在该请求处理之后、响应发送之前调用 `stop_timer()` 函数。在上面的函数中,我们写了时间戳并用它来计算处理请求所花费的时间。 + +当我们在 `demo1` 目录中运行 `docker-compose up`,它会启动这个 web 应用程序,然后在一个客户端容器中可以生成一些对 web 应用程序的请求。你将会看到创建了一个 `src/metrics.csv` 文件,它有两个字段:`timestamp` 和 `request_latency`。 + +通过查看这个文件,我们可以推断出两件事情: + +* 生成了很多数据 +* 没有观测到任何与指标相关的特征 + +没有观测到与指标相关的特征,我们就不能说这个指标与哪个 HTTP 端点有关联,或这个指标是由哪个应用程序的节点所生成的。因此,我们需要使用合适的元数据去限定每个观测指标。 + +### 《Statistics 101》 + +(LCTT 译注:这是一本统计学入门教材的名字) + +假如我们回到高中数学,我们应该回忆起一些统计术语,虽然不太确定,但应该包括平均数、中位数、百分位和柱状图。我们来简要地回顾一下它们,不用去管它们的用法,就像是在上高中一样。 + +#### 平均数 + +平均数mean,即一系列数字的平均值,是将数字汇总然后除以列表的个数。3、2 和 10 的平均数是 (3+2+10)/3 = 5。 + +#### 中位数 + +中位数median是另一种类型的平均,但它的计算方式不同;它是列表从小到大排序(反之亦然)后取列表的中间数字。以我们上面的列表中(2、3、10),中位数是 3。计算并不是非常直观,它取决于列表中数字的个数。 + +#### 百分位 + +百分位percentile是指那个百(千)分比数字低于我们给定的百分数的程度。在一些场景中,它是指这个测量值低于我们数据的百(千)分比数字的程度。比如,上面列表中 95% 是 9.29999。百分位的测量范围是 0 到 100(不包括)。0% 是一组数字的最小分数。你可能会想到它的中位数是 50%,它的结果是 3。 + +一些监测系统将百分位称为 `upper_X`,其中 _X_ 就是百分位;`upper 90` 指的是在 90% 的位置的值。 + +#### 分位数 + +“q-分位数”是将有 _N_ 个数的集合等分为 `qN` 级。`q` 的取值范围为 0 到 1(全部都包括)。当 `q` 取值为 0.5 时,值就是中位数。(分位数quantile)和百分位数的关系是,分位数值 `q` 等于 `100` 百分位值。 + +#### 柱状图 + +histogram这个指标,我们前面学习过,它是监测系统中一个_实现细节_。在统计学中,一个柱状图是一个将数据分组为 _桶_ 的图表。我们来考虑一个人为的不同示例:阅读你的博客的人的年龄。如果你有一些这样的数据,并想将它进行大致的分组,绘制成的柱状图将看起来像下面的这样: + +![Histogram graph](https://opensource.com/sites/default/files/styles/panopoly_image_original/public/u128651/histogram.png?itok=gqfhjB8p "Histogram graph") + +#### 累积柱状图 + +一个累积柱状图cumulative histogram也是一个柱状图,它的每个桶的数包含前一个桶的数,因此命名为_累积_。将上面的数据集做成累积柱状图后,看起来应该是这样的: + +![Cumulative histogram](https://opensource.com/sites/default/files/styles/panopoly_image_original/public/u128651/cumulative-histogram.png?itok=wIGQdZnT "Cumulative histogram") + +#### 我们为什么需要做统计? + +在上面的 Demo 1 中,我们注意到在我们报告指标时,这里生成了许多数据。当我们将它们用于指标时我们需要做统计,因为它们实在是太多了。我们需要的是整体行为,我们没法去处理单个值。我们预期展现出来的值的行为应该是代表我们观察的系统的行为。 + +### Demo 2:在指标上增加特征 + +在我们上面的的 Demo 1 应用程序中,当我们计算和报告一个请求的延迟时,它指向了一个由一些_特征_ 唯一标识的特定请求。下面是其中一些: + +* HTTP 端点 +* HTTP 方法 +* 运行它的主机/节点的标识符 + +如果我们将这些特征附加到要观察的指标上,每个指标将有更多的内容。我们来解释一下 [Demo 2][9] 中添加到我们的指标上的特征。 + +在写入指标时,`src/helpers/middleware.py` 文件将在 CSV 文件中写入多个列: + +``` +node_ids = ['10.0.1.1', '10.1.3.4'] + + +def start_timer(): +    request.start_time = time.time() + + +def stop_timer(response): +    # convert this into milliseconds for statsd +    resp_time = (time.time() - request.start_time)*1000 +    node_id = node_ids[random.choice(range(len(node_ids)))] +    with open('metrics.csv', 'a', newline='') as f: +        csvwriter = csv.writer(f) +        csvwriter.writerow([ +            str(int(time.time())), 'webapp1', node_id, +            request.endpoint, request.method, str(response.status_code), +            str(resp_time) +        ]) + +    return response +``` + +因为这只是一个演示,在报告指标时,我们将随意的报告一些随机 IP 作为节点的 ID。当我们在 `demo2` 目录下运行 `docker-compose up` 时,我们的结果将是一个有多个列的 CSV 文件。 + +#### 用 pandas 分析指标 + +我们将使用 [pandas][10] 去分析这个 CSV 文件。运行 `docker-compose up` 将打印出一个 URL,我们将使用它来打开一个 [Jupyter][11] 会话。一旦我们上传 `Analysis.ipynb notebook` 到会话中,我们就可以将 CSV 文件读入到一个 pandas 数据帧DataFrame中: + +``` +import pandas as pd +metrics = pd.read_csv('/data/metrics.csv', index_col=0) +``` + +`index_col` 表明我们要指定时间戳作为索引。 + +因为每个特征我们都要在数据帧中添加一个列,因此我们可以基于这些列进行分组和聚合: + +``` +import numpy as np +metrics.groupby(['node_id', 'http_status']).latency.aggregate(np.percentile, 99.999) +``` + +更多内容请参考 Jupyter notebook 在数据上的分析示例。 + +### 我应该监测什么? + +一个软件系统有许多的变量,这些变量的值在它的生命周期中不停地发生变化。软件是运行在某种操作系统上的,而操作系统同时也在不停地变化。在我看来,当某些东西出错时,你所拥有的数据越多越好。 + +我建议去监测的关键操作系统指标有: + +* CPU 使用 +* 系统内存使用 +* 文件描述符使用 +* 磁盘使用 + +还需要监测的其它关键指标根据你的软件应用程序不同而不同。 + +#### 网络应用程序 + +如果你的软件是一个监听客户端请求和为它提供服务的网络应用程序,需要测量的关键指标还有: + +* 入站请求数(计数器) +* 未处理的错误(计数器) +* 请求延迟(柱状图/计时器) +* 排队时间,如果在你的应用程序中有队列(柱状图/计时器) +* 队列大小,如果在你的应用程序中有队列(计量器) +* 工作进程/线程用量(计量器) + +如果你的网络应用程序在一个客户端请求的环境中向其它服务发送请求,那么它应该有一个指标去记录它与那个服务之间的通讯行为。需要监测的关键指标包括请求数、请求延迟、和响应状态。 + +#### HTTP web 应用程序后端 + +HTTP 应用程序应该监测上面所列出的全部指标。除此之外,还应该按 HTTP 状态代码分组监测所有非 200 的 HTTP 状态代码的大致数据。如果你的 web 应用程序有用户注册和登录功能,同时也应该为这个功能设置指标。 + +#### 长时间运行的进程 + +长时间运行的进程如 Rabbit MQ 消费者或任务队列的工作进程,虽然它们不是网络服务,它们以选取一个任务并处理它的工作模型来运行。因此,我们应该监测请求的进程数和这些进程的请求延迟。 + +不管是什么类型的应用程序,都有指标与合适的**元数据**相关联。 + +### 将监测集成到一个 Python 应用程序中 + +将监测集成到 Python 应用程序中需要涉及到两个组件: + +* 更新你的应用程序去计算和报告指标 +* 配置一个监测基础设施来容纳应用程序的指标,并允许去查询它们 + +下面是记录和报告指标的基本思路: + +``` +def work(): +    requests += 1 +    # report counter +    start_time = time.time() +    +    # < do the work > + +    # calculate and report latency +    work_latency = time.time() - start_time +    ... +``` + +考虑到上面的模式,我们经常使用修饰符、内容管理器、中间件(对于网络应用程序)所带来的好处去计算和报告指标。在 Demo 1 和 Demo 2 中,我们在一个 Flask 应用程序中使用修饰符。 + +#### 指标报告时的拉取和推送模型 + +大体来说,在一个 Python 应用程序中报告指标有两种模式。在 _拉取_ 模型中,监测系统在一个预定义的 HTTP 端点上“刮取”应用程序。在_推送_ 模型中,应用程序发送数据到监测系统。 + +![Pull and push models](https://opensource.com/sites/default/files/styles/panopoly_image_original/public/u128651/pull_push_model.png?itok=U093wSy8 "Pull and push models") + +工作在 _拉取_ 模型中的监测系统的一个例子是 [Prometheus][12]。而 [StatsD][13] 是 _推送_ 模型的一个例子。 + +#### 集成 StatsD + +将 StatsD 集成到一个 Python 应用程序中,我们将使用 [StatsD Python 客户端][14],然后更新我们的指标报告部分的代码,调用合适的库去推送数据到 StatsD 中。 + +首先,我们需要去创建一个客户端实例: + +``` +statsd = statsd.StatsClient(host='statsd', port=8125, prefix='webapp1') +``` + +`prefix` 关键字参数将为通过这个客户端报告的所有指标添加一个指定的前缀。 + +一旦我们有了客户端,我们可以使用如下的代码为一个计时器报告值: + +``` +statsd.timing(key, resp_time) +``` + +增加计数器: + +``` +statsd.incr(key) +``` + +将指标关联到元数据上,一个键的定义为:`metadata1.metadata2.metric`,其中每个 metadataX 是一个可以进行聚合和分组的字段。 + +这个演示应用程序 [StatsD][15] 是将 statsd 与 Python Flask 应用程序集成的一个完整示例。 + +#### 集成 Prometheus + +要使用 Prometheus 监测系统,我们使用 [Promethius Python 客户端][16]。我们将首先去创建有关的指标类对象: + +``` +REQUEST_LATENCY = Histogram('request_latency_seconds', 'Request latency', +    ['app_name', 'endpoint'] +) +``` + +在上面的语句中的第三个参数是与这个指标相关的标识符。这些标识符是由与单个指标值相关联的元数据定义的。 + +去记录一个特定的观测指标: + +``` +REQUEST_LATENCY.labels('webapp', request.path).observe(resp_time) +``` + +下一步是在我们的应用程序中定义一个 Prometheus 能够刮取的 HTTP 端点。这通常是一个被称为 `/metrics` 的端点: + +``` +@app.route('/metrics') +def metrics(): +    return Response(prometheus_client.generate_latest(), mimetype=CONTENT_TYPE_LATEST) +``` + +这个演示应用程序 [Prometheus][17] 是将 prometheus 与 Python Flask 应用程序集成的一个完整示例。 + +#### 哪个更好:StatsD 还是 Prometheus? + +本能地想到的下一个问题便是:我应该使用 StatsD 还是 Prometheus?关于这个主题我写了几篇文章,你可能发现它们对你很有帮助: + +* [使用 Prometheus 监测多进程 Python 应用的方式][18] +* [使用 Prometheus 监测你的同步 Python 应用][19] +* [使用 Prometheus 监测你的异步 Python 应用][20] + +### 指标的使用方式 + +我们已经学习了一些关于为什么要在我们的应用程序上配置监测的原因,而现在我们来更深入地研究其中的两个用法:报警和自动扩展。 + +#### 使用指标进行报警 + +指标的一个关键用途是创建警报。例如,假如过去的五分钟,你的 HTTP 500 的数量持续增加,你可能希望给相关的人发送一封电子邮件或页面提示。对于配置警报做什么取决于我们的监测设置。对于 Prometheus 我们可以使用 [Alertmanager][21],而对于 StatsD,我们使用 [Nagios][22]。 + +#### 使用指标进行自动扩展 + +在一个云基础设施中,如果我们当前的基础设施供应过量或供应不足,通过指标不仅可以让我们知道,还可以帮我们实现一个自动伸缩的策略。例如,如果在过去的五分钟里,在我们服务器上的工作进程使用率达到 90%,我们可以水平扩展。我们如何去扩展取决于云基础设施。AWS 的自动扩展,缺省情况下,扩展策略是基于系统的 CPU 使用率、网络流量、以及其它因素。然而,让基础设施伸缩的应用程序指标,我们必须发布 [自定义的 CloudWatch 指标][23]。 + +### 在多服务架构中的应用程序监测 + +当我们超越一个单应用程序架构时,比如当客户端的请求在响应被发回之前,能够触发调用多个服务,就需要从我们的指标中获取更多的信息。我们需要一个统一的延迟视图指标,这样我们就能够知道响应这个请求时每个服务花费了多少时间。这可以用 [分布式跟踪][24] 来实现。 + +你可以在我的博客文章 《[在你的 Python 应用程序中通过 Zipkin 引入分布式跟踪][25]》 中看到在 Python 中进行分布式跟踪的示例。 + +### 划重点 + +总之,你需要记住以下几点: + +* 理解你的监测系统中指标类型的含义 +* 知道监测系统需要的你的数据的测量单位 +* 监测你的应用程序中的大多数关键组件 +* 监测你的应用程序在它的大多数关键阶段的行为 + +以上要点是假设你不去管理你的监测系统。如果管理你的监测系统是你的工作的一部分,那么你还要考虑更多的问题! + +### 其它资源 + +以下是我在我的监测学习过程中找到的一些非常有用的资源: + +#### 综合的 + +* [监测分布式系统][26] +* [观测和监测最佳实践][27] +* [谁想使用秒?][28] + +#### StatsD/Graphite + +* [StatsD 指标类型][29] + +#### Prometheus + +* [Prometheus 指标类型][30] +* [Prometheus 计量器如何工作?][31] +* [为什么用 Prometheus 累积柱形图?][32] +* [在 Python 中监测批量作业][33] +* [Prometheus:监测 SoundCloud][34] + +### 避免犯错(即第 3 阶段的学习) + +在我们学习监测的基本知识时,时刻注意不要犯错误是很重要的。以下是我偶然发现的一些很有见解的资源: + +* [如何不测量延迟][35] +* [Prometheus 柱形图:悲伤的故事][36] +* [为什么平均值很讨厌,而百分位很棒][37] +* [对延迟的认知错误][38] +* [谁动了我的 99% 延迟?][39] +* [日志、指标和图形][40] +* [HdrHistogram:一个更好的延迟捕获方式][41] + +--- + +想学习更多内容,参与到 [PyCon Cleveland 2018][43] 上的 Amit Saha 的讨论,[Counter, gauge, upper 90—Oh my!][42] + +## 关于作者 + +[![](https://opensource.com/sites/default/files/styles/profile_pictures/public/osdc_default_avatar_1.png?itok=mmbfqFXm)][44] + +Amit Saha — 我是一名对基础设施、监测、和工具感兴趣的软件工程师。我是“用 Python 做数学”的作者和创始人,以及 Fedora Scientific Spin 维护者。 + +[关于我的更多信息][45] + +* [Learn how you can contribute][46] + +--- + +via: [https://opensource.com/article/18/4/metrics-monitoring-and-python][47] + +作者: [Amit Saha][48] 选题者: [lujun9972][49] 译者: [qhwdw][50] 校对: [wxy][51] + +本文由 [LCTT][52] 原创编译,[Linux中国][53] 荣誉推出 + +[1]: https://opensource.com/resources/python?intcmp=7016000000127cYAAQ +[2]: https://opensource.com/resources/python/ides?intcmp=7016000000127cYAAQ +[3]: https://opensource.com/resources/python/gui-frameworks?intcmp=7016000000127cYAAQ +[4]: https://opensource.com/tags/python?intcmp=7016000000127cYAAQ +[5]: https://developers.redhat.com/?intcmp=7016000000127cYAAQ +[6]: https://github.com/amitsaha/python-monitoring-talk +[7]: https://github.com/amitsaha/python-monitoring-talk/tree/master/demo1 +[8]: http://flask.pocoo.org/ +[9]: https://github.com/amitsaha/python-monitoring-talk/tree/master/demo2 +[10]: https://pandas.pydata.org/ +[11]: http://jupyter.org/ +[12]: https://prometheus.io/ +[13]: https://github.com/etsy/statsd +[14]: https://pypi.python.org/pypi/statsd +[15]: https://github.com/amitsaha/python-monitoring-talk/tree/master/statsd +[16]: https://pypi.python.org/pypi/prometheus_client +[17]: https://github.com/amitsaha/python-monitoring-talk/tree/master/prometheus +[18]: http://echorand.me/your-options-for-monitoring-multi-process-python-applications-with-prometheus.html +[19]: https://blog.codeship.com/monitoring-your-synchronous-python-web-applications-using-prometheus/ +[20]: https://blog.codeship.com/monitoring-your-asynchronous-python-web-applications-using-prometheus/ +[21]: https://github.com/prometheus/alertmanager +[22]: https://www.nagios.org/about/overview/ +[23]: https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/publishingMetrics.html +[24]: http://opentracing.io/documentation/ +[25]: http://echorand.me/introducing-distributed-tracing-in-your-python-application-via-zipkin.html +[26]: https://landing.google.com/sre/book/chapters/monitoring-distributed-systems.html +[27]: http://www.integralist.co.uk/posts/monitoring-best-practices/?imm_mid=0fbebf&cmp=em-webops-na-na-newsltr_20180309 +[28]: https://www.robustperception.io/who-wants-seconds/ +[29]: https://github.com/etsy/statsd/blob/master/docs/metric_types.md +[30]: https://prometheus.io/docs/concepts/metric_types/ +[31]: https://www.robustperception.io/how-does-a-prometheus-gauge-work/ +[32]: https://www.robustperception.io/why-are-prometheus-histograms-cumulative/ +[33]: https://www.robustperception.io/monitoring-batch-jobs-in-python/ +[34]: https://developers.soundcloud.com/blog/prometheus-monitoring-at-soundcloud +[35]: https://www.youtube.com/watch?v=lJ8ydIuPFeU&feature=youtu.be +[36]: http://linuxczar.net/blog/2017/06/15/prometheus-histogram-2/ +[37]: https://www.dynatrace.com/news/blog/why-averages-suck-and-percentiles-are-great/ +[38]: https://bravenewgeek.com/everything-you-know-about-latency-is-wrong/ +[39]: https://engineering.linkedin.com/performance/who-moved-my-99th-percentile-latency +[40]: https://grafana.com/blog/2016/01/05/logs-and-metrics-and-graphs-oh-my/ +[41]: http://psy-lob-saw.blogspot.com.au/2015/02/hdrhistogram-better-latency-capture.html +[42]: https://us.pycon.org/2018/schedule/presentation/133/ +[43]: https://us.pycon.org/2018/ +[44]: https://opensource.com/users/amitsaha +[45]: https://opensource.com/users/amitsaha +[46]: https://opensource.com/participate +[47]: https://opensource.com/article/18/4/metrics-monitoring-and-python +[48]: https://opensource.com/users/amitsaha +[49]: https://github.com/lujun9972 +[50]: https://github.com/qhwdw +[51]: https://github.com/wxy +[52]: https://github.com/LCTT/TranslateProject +[53]: https://linux.cn/ diff --git a/published/20180427 An Official Introduction to the Go Compiler.md b/published/20180427 An Official Introduction to the Go Compiler.md new file mode 100644 index 0000000000..622bf49c6d --- /dev/null +++ b/published/20180427 An Official Introduction to the Go Compiler.md @@ -0,0 +1,77 @@ +Go 编译器介绍 +====== + +`cmd/compile` 包含构成 Go 编译器主要的包。编译器在逻辑上可以被分为四个阶段,我们将简要介绍这几个阶段以及包含相应代码的包的列表。 + +在谈到编译器时,有时可能会听到前端front-end后端back-end这两个术语。粗略地说,这些对应于我们将在此列出的前两个和后两个阶段。第三个术语中间端middle-end通常指的是第二阶段执行的大部分工作。 + +请注意,`go/parser` 和 `go/types` 等 `go/*` 系列的包与编译器无关。由于编译器最初是用 C 编写的,所以这些 `go/*` 包被开发出来以便于能够写出和 `Go` 代码一起工作的工具,例如 `gofmt` 和 `vet`。 + +需要澄清的是,名称 “gc” 代表 “Go 编译器Go compiler”,与大写 GC 无关,后者代表垃圾收集garbage collection。 + +### 1、解析 + +* `cmd/compile/internal/syntax`(词法分析器lexer解析器parser语法树syntax tree) + +在编译的第一阶段,源代码被标记化(词法分析)、解析(语法分析),并为每个源文件构造语法树(LCTT 译注:这里标记指 token,它是一组预定义的、能够识别的字符串,通常由名字和值构成,其中名字一般是词法的类别,如标识符、关键字、分隔符、操作符、文字和注释等;语法树,以及下文提到的抽象语法树Abstract Syntax Tree(AST),是指用树来表达程序设计语言的语法结构,通常叶子节点是操作数,其它节点是操作码)。 + +每个语法树都是相应源文件的确切表示,其中节点对应于源文件的各种元素,例如表达式、声明和语句。语法树还包括位置信息,用于错误报告和创建调试信息。 + +### 2、类型检查和 AST 变换 + +* `cmd/compile/internal/gc`(创建编译器 AST,类型检查type-checkingAST 变换AST transformation) + +gc 包中包含一个继承自(早期)C 语言实现的版本的 AST 定义。所有代码都是基于它编写的,所以 gc 包必须做的第一件事就是将 syntax 包(定义)的语法树转换为编译器的 AST 表示法。这个额外步骤可能会在将来重构。 + +然后对 AST 进行类型检查。第一步是名字解析和类型推断,它们确定哪个对象属于哪个标识符,以及每个表达式具有的类型。类型检查包括特定的额外检查,例如“声明但未使用”以及确定函数是否会终止。 + +特定变换也基于 AST 完成。一些节点被基于类型信息而细化,例如把字符串加法从算术加法的节点类型中拆分出来。其它一些例子是死代码消除dead code elimination函数调用内联function call inlining逃逸分析escape analysis(LCTT 译注:逃逸分析是一种分析指针有效范围的方法)。 + +### 3、通用 SSA + +* `cmd/compile/internal/gc`(转换成 SSA) +* `cmd/compile/internal/ssa`(SSA 相关的环节pass和规则) + +(LCTT 译注:许多常见高级语言的编译器无法通过一次扫描源代码或 AST 就完成所有编译工作,取而代之的做法是多次扫描,每次完成一部分工作,并将输出结果作为下次扫描的输入,直到最终产生目标代码。这里每次扫描称作一个环节pass;最后一个环节之前所有的环节得到的结果都可称作中间表示法,本文中 AST、SSA 等都属于中间表示法。SSA,静态单赋值形式,是中间表示法的一种性质,它要求每个变量只被赋值一次且在使用前被定义)。 + +在此阶段,AST 将被转换为静态单赋值Static Single Assignment(SSA)形式,这是一种具有特定属性的低级中间表示法intermediate representation,可以更轻松地实现优化并最终从它生成机器码。 + +在这个转换过程中,将完成内置函数function intrinsics的处理。这些是特殊的函数,编译器被告知逐个分析这些函数并决定是否用深度优化的代码替换它们(LCTT 译注:内置函数指由语言本身定义的函数,通常编译器的处理方式是使用相应实现函数的指令序列代替对函数的调用指令,有点类似内联函数)。 + +在 AST 转化成 SSA 的过程中,特定节点也被低级化为更简单的组件,以便于剩余的编译阶段可以基于它们工作。例如,内建的拷贝被替换为内存移动,`range` 循环被改写为 `for` 循环。由于历史原因,目前这里面有些在转化到 SSA 之前发生,但长期计划则是把它们都移到这里(转化 SSA)。 + +然后,一系列机器无关的规则和编译环节会被执行。这些并不考虑特定计算机体系结构,因此对所有 `GOARCH` 变量的值都会运行。 + +这类通用的编译环节的一些例子包括,死代码消除、移除不必要的空值检查,以及移除无用的分支等。通用改写规则主要考虑表达式,例如将一些表达式替换为常量,优化乘法和浮点操作。 + +### 4、生成机器码 + +* `cmd/compile/internal/ssa`(SSA 低级化和架构特定的环节) +* `cmd/internal/obj`(机器码生成) + +编译器中机器相关的阶段开始于“低级”的编译环节,该阶段将通用变量改写为它们的特定的机器码形式。例如,在 amd64 架构中操作数可以在内存中操作,这样许多加载-存储load-store操作就可以被合并。 + +注意低级的编译环节运行所有机器特定的重写规则,因此当前它也应用了大量优化。 + +一旦 SSA 被“低级化”并且更具体地针对目标体系结构,就要运行最终代码优化的编译环节了。这包含了另外一个死代码消除的环节,它将变量移动到更靠近它们使用的地方,移除从来没有被读过的局部变量,以及寄存器register分配。 + +本步骤中完成的其它重要工作包括堆栈布局stack frame layout,它将堆栈偏移位置分配给局部变量,以及指针活性分析pointer liveness analysis,后者计算每个垃圾收集安全点上的哪些堆栈上的指针仍然是活动的。 + +在 SSA 生成阶段结束时,Go 函数已被转换为一系列 `obj.Prog` 指令。它们被传递给汇编程序(`cmd/internal/obj`),后者将它们转换为机器码并输出最终的目标文件。目标文件还将包含反射数据,导出数据和调试信息。 + +### 扩展阅读 + +要深入了解 SSA 包的工作方式,包括它的环节和规则,请转到 [cmd/compile/internal/ssa/README.md][1]。 + +-------------------------------------------------------------------------------- + +via: https://github.com/golang/go/blob/master/src/cmd/compile/README.md + +作者:[mvdan][a] +译者:[stephenxs](https://github.com/stephenxs) +校对:[pityonline](https://github.com/pityonline), [wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://github.com/mvdan +[1]: https://github.com/golang/go/blob/master/src/cmd/compile/internal/ssa/README.md diff --git a/published/20180516 How Graphics Cards Work.md b/published/20180516 How Graphics Cards Work.md new file mode 100644 index 0000000000..690c121833 --- /dev/null +++ b/published/20180516 How Graphics Cards Work.md @@ -0,0 +1,83 @@ +极致技术探索:显卡工作原理 +====== + +![AMD-Polaris][1] + +自从 3dfx 推出最初的 Voodoo 加速器以来,不起眼的显卡对你的 PC 是否可以玩游戏起到决定性作用,PC 上任何其它设备都无法与其相比。其它组件当然也很重要,但对于一个拥有 32GB 内存、价值 500 美金的 CPU 和 基于 PCIe 的存储设备的高端 PC,如果使用 10 年前的显卡,都无法以最高分辨率和细节质量运行当前最高品质的游戏AAA titles,会发生卡顿甚至无响应。显卡(也常被称为 GPU,即图形处理单元Graphic Processing Unit),对游戏性能影响极大,我们反复强调这一点;但我们通常并不会深入了解显卡的工作原理。 + +出于实际考虑,本文将概述 GPU 的上层功能特性,内容包括 AMD 显卡、Nvidia 显卡、Intel 集成显卡以及 Intel 后续可能发布的独立显卡之间共同的部分。也应该适用于 Apple、Imagination Technologies、Qualcomm、ARM 和其它显卡生产商发布的移动平台 GPU。 + +### 我们为何不使用 CPU 进行渲染? + +我要说明的第一点是我们为何不直接使用 CPU 完成游戏中的渲染工作。坦率的说,在理论上你确实可以直接使用 CPU 完成渲染rendering工作。在显卡没有广泛普及之前,早期的 3D 游戏就是完全基于 CPU 运行的,例如 《地下创世纪Ultima Underworld(下文中简称 UU)。UU 是一个很特别的例子,原因如下:与《毁灭战士Doom相比,UU 具有一个更高级的渲染引擎,全面支持“向上或向下看”以及一些在当时比较高级的特性,例如纹理映射texture mapping。但为支持这些高级特性,需要付出高昂的代价,很少有人可以拥有真正能运行起 UU 的 PC。 + +![](https://www.extremetech.com/wp-content/uploads/2018/05/UU.jpg) + +*地下创世纪,图片来自 [GOG](https://www.gog.com/game/ultima_underworld_1_2)* + +对于早期的 3D 游戏,包括《半条命Half Life》和《雷神之锤 2Quake II》在内的很多游戏,内部包含一个软件渲染器,让没有 3D 加速器的玩家也可以玩游戏。但现代游戏都弃用了这种方式,原因很简单:CPU 是设计用于通用任务的微处理器,意味着缺少 GPU 提供的专用硬件specialized hardware功能capabilities。对于 18 年前使用软件渲染的那些游戏,当代 CPU 可以轻松胜任;但对于当代最高品质的游戏,除非明显降低景象质量scene、分辨率和各种虚拟特效,否则现有的 CPU 都无法胜任。 + +### 什么是 GPU ? + +GPU 是一种包含一系列专用硬件特性的设备,其中这些特性可以让各种 3D 引擎更好地执行代码,包括形状构建geometry setup,纹理映射,访存memory access着色器shaders等。3D 引擎的功能特性影响着设计者如何设计 GPU。可能有人还记得,AMD HD5000 系列使用 VLIW5 架构archtecture;但在更高端的 HD 6000 系列中使用了 VLIW4 架构。通过 GCN (LCTT 译注:GCN 是 Graphics Core Next 的缩写,字面意思是“下一代图形核心”,既是若干代微体系结构的代号,也是指令集的名称),AMD 改变了并行化的实现方法,提高了每个时钟周期的有效性能。 + +![](https://www.extremetech.com/wp-content/uploads/2018/05/GPU-Evolution.jpg) + +*“GPU 革命”的前两块奠基石属于 AMD 和 NV;而“第三个时代”则独属于 AMD。* + +Nvidia 在发布首款 GeForce 256 时(大致对应 Microsoft 推出 DirectX7 的时间点)提出了 GPU 这个术语,这款 GPU 支持在硬件上执行转换和光照计算lighting calculation。将专用功能直接集成到硬件中是早期 GPU 的显著技术特点。很多专用功能还在(以一种极为不同的方式)使用,毕竟对于特定类型的工作任务,使用片上on-chip专用计算资源明显比使用一组可编程单元programmable cores要更加高效和快速。 + +GPU 和 CPU 的核心有很多差异,但我们可以按如下方式比较其上层特性。CPU 一般被设计成尽可能快速和高效的执行单线程代码。虽然 同时多线程 Simultaneous multithreading(SMT)或 超线程Hyper-Threading(HT)在这方面有所改进,但我们实际上通过堆叠众多高效率的单线程核心来扩展多线程性能。AMD 的 32 核心/64 线程 Epyc CPU 已经是我们能买到的核心数最多的 CPU;相比而言,Nvidia 最低端的 Pascal GPU 都拥有 384 个核心。但相比 CPU 的核心,GPU 所谓的核心是处理能力低得多的的处理单元。 + +**注意:** 简单比较 GPU 核心数,无法比较或评估 AMD 与 Nvidia 的相对游戏性能。在同样 GPU 系列(例如 Nvidia 的 GeForce GTX 10 系列,或 AMD 的 RX 4xx 或 5xx 系列)的情况下,更高的 GPU 核心数往往意味着更高的性能。 + +你无法只根据核心数比较不同供应商或核心系列的 GPU 之间的性能,这是因为不同的架构对应的效率各不相同。与 CPU 不同,GPU 被设计用于并行计算。AMD 和 Nvidia 在结构上都划分为计算资源block。Nvidia 将这些块称之为流处理器Streaming Multiprocessor(SM),而 AMD 则称之为计算单元Compute Unit(CU)。 + +![](https://www.extremetech.com/wp-content/uploads/2018/05/PascalSM.png) + +*一个 Pascal 流处理器(SM)。* + +每个块都包含如下组件:一组核心、一个调度器scheduler、一个寄存器文件register file、指令缓存、纹理和 L1 缓存以及纹理映射单元mapping unit。SM/CU 可以被认为是 GPU 中最小的可工作块。SM/CU 没有涵盖全部的功能单元,例如视频解码引擎,实际在屏幕绘图所需的渲染输出,以及与板载onboard显存Video Memory(VRAM)通信相关的内存接口memory interfaces都不在 SM/CU 的范围内;但当 AMD 提到一个 APU 拥有 8 或 11 个 Vega 计算单元时,所指的是(等价的)硅晶块block of silicon数目。如果你查看任意一款 GPU 的模块设计图,你会发现图中 SM/CU 是反复出现很多次的部分。 + +![](https://www.extremetech.com/wp-content/uploads/2016/11/Pascal-Diagram.jpg) + +*这是 Pascal 的全平面图* + +GPU 中的 SM/CU 数目越多,每个时钟周期内可以并行完成的工作也越多。渲染是一种通常被认为是“高度并行”的计算问题,意味着随着核心数增加带来的可扩展性很高。 + +当我们讨论 GPU 设计时,我们通常会使用一种形如 4096:160:64 的格式,其中第一个数字代表核心数。在核心系列(如 GTX970/GTX 980/GTX 980 Ti,如 RX 560/RX 580 等等)一致的情况下,核心数越高,GPU 也就相对更快。 + +### 纹理映射和渲染输出 + +GPU 的另外两个主要组件是纹理映射单元和渲染输出。设计中的纹理映射单元数目决定了最大的纹素texel输出以及可以多快的处理并将纹理映射到对象上。早期的 3D 游戏很少用到纹理,这是因为绘制 3D 多边形形状的工作有较大的难度。纹理其实并不是 3D 游戏必须的,但不使用纹理的现代游戏屈指可数。 + +GPU 中的纹理映射单元数目用 4096:160:64 指标中的第二个数字表示。AMD、Nvidia 和 Intel 一般都等比例变更指标中的数字。换句话说,如果你找到一个指标为 4096:160:64 的 GPU,同系列中不会出现指标为 4096:320:64 的 GPU。纹理映射绝对有可能成为游戏的瓶颈,但产品系列中次高级别的 GPU 往往提供更多的核心和纹理映射单元(是否拥有更高的渲染输出单元取决于 GPU 系列和显卡的指标)。 + +渲染输出单元Render outputs(ROP),有时也叫做光栅操作管道raster operations pipelines是 GPU 输出汇集成图像的场所,图像最终会在显示器或电视上呈现。渲染输出单元的数目乘以 GPU 的时钟频率决定了像素填充速率pixel fill rate。渲染输出单元数目越多意味着可以同时输出的像素越多。渲染输出单元还处理抗锯齿antialiasing,启用抗锯齿(尤其是超级采样supersampled抗锯齿)会导致游戏填充速率受限。 + +### 显存带宽与显存容量 + +我们最后要讨论的是显存带宽memory bandwidth显存容量memory capacity。显存带宽是指一秒时间内可以从 GPU 专用的显存缓冲区内拷贝进或拷贝出多少数据。很多高级视觉特效(以及更常见的高分辨率)需要更高的显存带宽,以便保证足够的帧率frame rates,因为需要拷贝进和拷贝出 GPU 核心的数据总量增大了。 + +在某些情况下,显存带宽不足会成为 GPU 的显著瓶颈。以 Ryzen 5 2400G 为例的 AMD APU 就是严重带宽受限的,以至于提高 DDR4 的时钟频率可以显著提高整体性能。导致瓶颈的显存带宽阈值,也与游戏引擎和游戏使用的分辨率相关。 + +板载内存大小也是 GPU 的重要指标。如果按指定细节级别或分辨率运行所需的显存量超过了可用的资源量,游戏通常仍可以运行,但会使用 CPU 的主存来存储额外的纹理数据;而从 DRAM 中提取数据比从板载显存中提取数据要慢得多。这会导致游戏在板载的快速访问内存池和系统内存中共同提取数据时出现明显的卡顿。 + +有一点我们需要留意,GPU 生产厂家通常为一款低端或中端 GPU 配置比通常更大的显存,这是他们为产品提价的一种常用手段。很难说大显存是否更具有吸引力,毕竟需要具体问题具体分析。大多数情况下,用更高的价格购买一款仅是显存更高的显卡是不划算的。经验规律告诉我们,低端显卡遇到显存瓶颈之前就会碰到其它瓶颈。如果存在疑问,可以查看相关评论,例如 4G 版本或其它数目的版本是否性能超过 2G 版本。更多情况下,如果其它指标都相同,购买大显存版本并不值得。 + +查看我们的[极致技术探索][2]系列,深入了解更多当前最热的技术话题。 + +-------------------------------------------------------------------------------- + +via: https://www.extremetech.com/gaming/269335-how-graphics-cards-work + +作者:[Joel Hruska][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[pinewall](https://github.com/pinewall) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.extremetech.com/author/jhruska +[1]:https://www.extremetech.com/wp-content/uploads/2016/07/AMD-Polaris-640x353.jpg +[2]:http://www.extremetech.com/tag/extremetech-explains diff --git a/published/20180516 Manipulating Directories in Linux.md b/published/20180516 Manipulating Directories in Linux.md new file mode 100644 index 0000000000..2a71d30db2 --- /dev/null +++ b/published/20180516 Manipulating Directories in Linux.md @@ -0,0 +1,181 @@ +在 Linux 上操作目录 +====== + +![](https://www.linux.com/sites/lcom/files/styles/rendered_file/public/branches-238379_1920_0.jpg?itok=2PlNpsVu) + +> 让我们继续学习一下 Linux 文件系统的树形结构,并展示一下如何在其中创建你的目录。 + +如果你不熟悉本系列(以及 Linux),[请查看我们的第一部分][1]。在那篇文章中,我们贯穿了 Linux 文件系统的树状结构(或者更确切地说是文件层次结构标准File Hierarchy Standard,FHS)。我建议你仔细阅读,确保你理解自己能安全的做哪些操作。因为这一次,我将向你展示目录操作的魅力。 + +### 新建目录 + +在破坏之前,先让我们来创建。首先,打开一个终端窗口并使用命令 `mkdir` 创建一个新目录,如下所示: + +``` +mkdir +``` +如果你只输入了目录名称,该目录将显示在您当前所在目录中。如果你刚刚打开一个终端,你当前位置为你的家目录。在这个例子中,我们展示了将要创建的目录与你当前所处位置的关系: + +``` +$ pwd # 告知你当前所在位置(参见第一部分) +/home/ +$ mkdir newdirectory # 创建 /home//newdirectory +``` + +(注:你不用输入 `#` 后面的文本。`#` 后面的文本为注释内容,用于解释发生了什么。它会被 shell 忽略,不会被执行)。 + +你可以在当前位置中已经存在的某个目录下创建新的目录,方法是在命令行中指定它: + +``` +mkdir Documents/Letters +``` + +这将在 `Documents` 目录中创建 `Letters` 目录。 + +你还可以在路径中使用 `..` 在当前目录的上一级目录中创建目录。假设你进入刚刚创建的 `Documents/Letters/` 目录,并且想要创建`Documents/Memos/` 目录。你可以这样做: + +``` +cd Documents/Letters # 进入到你刚刚创建的 Letters/ 目录 +mkdir ../Memos +``` + +同样,以上所有内容都是相对于你当前的位置做的。这就是使用了相对路径。 + +你还可以使用目录的绝对路径:这意味着告诉 `mkdir` 命令将目录放在和根目录(`/`)有关的位置: + +``` +mkdir /home//Documents/Letters +``` + +在上面的命令中将 `` 更改为你的用户名,这相当于从你的主目录执行 `mkdir Documents/Letters`,通过使用绝对路径你可以在目录树中的任何位置完成这项工作。 + +无论你使用相对路径还是绝对路径,只要命令成功执行,`mkdir` 将静默的创建新目录,而没有任何明显的反馈。只有当遇到某种问题时,`mkdir`才会在你敲下回车键后打印一些反馈。 + +与大多数其他命令行工具一样,`mkdir` 提供了几个有趣的选项。 `-p` 选项特别有用,因为它允许你嵌套创建目录,即使目录不存在也可以。例如,要在 `Documents/` 中创建一个目录存放写给妈妈的信,你可以这样做: + +``` +mkdir -p Documents/Letters/Family/Mom +``` + +`mkdir` 会创建 `Mom/` 之上的整个目录分支,并且也会创建 `Mom/` 目录,无论其上的目录在你敲入该命令时是否已经存在。 + +你也可以用空格来分隔目录名,来同时创建几个目录: + +``` +mkdir Letters Memos Reports +``` + +这将在当前目录下创建目录 `Letters`、`Memos` 和 `Reports`。 + +### 目录名中可怕的空格 + +……这带来了目录名称中关于空格的棘手问题。你能在目录名中使用空格吗?是的你可以。那么建议你使用空格吗?不,绝对不建议。空格使一切变得更加复杂,并且可能是危险的操作。 + +假设您要创建一个名为 `letters mom/` 的目录。如果你不知道如何更好处理,你可能会输入: + +``` +mkdir letters mom +``` + +但这是错误的!错误的!错误的!正如我们在上面介绍的,这将创建两个目录 `letters/` 和 `mom/`,而不是一个目录 `letters mom/`。 + +得承认这是一个小麻烦:你所要做的就是删除这两个目录并重新开始,这没什么大不了。 + +可是等等!删除目录可是个危险的操作。想象一下,你使用图形工具[Dolphin][2] 或 [Nautilus][3] 创建了目录 `letters mom/`。如果你突然决定从终端删除目录 `letters mom`,并且您在同一目录下有另一个名为 `letters` 的目录,并且该目录中包含重要的文档,结果你为了删除错误的目录尝试了以下操作: + +``` +rmdir letters mom +``` + +你将会有删除目录 letters 的风险。这里说“风险”,是因为幸运的是`rmdir` 这条用于删除目录的指令,有一个内置的安全措施,如果你试图删除一个非空目录时,它会发出警告。 + +但是,下面这个: + +``` +rm -Rf letters mom +``` + +(注:这是删除目录及其内容的一种非常标准的方式)将完全删除 `letters/` 目录,甚至永远不会告诉你刚刚发生了什么。) + +`rm` 命令用于删除文件和目录。当你将它与选项 `-R`(递归删除)和 `-f`(强制删除)一起使用时,它会深入到目录及其子目录中,删除它们包含的所有文件,然后删除子目录本身,然后它将删除所有顶层目录中的文件,再然后是删除目录本身。 + +`rm -Rf` 是你必须非常小心处理的命令。 + +我的建议是,你可以使用下划线来代替空格,但如果你仍然坚持使用空格,有两种方法可以使它们起作用。您可以使用单引号或双引号,如下所示: + +``` +mkdir 'letters mom' +mkdir "letters dad" +``` + +或者,你可以转义空格。有些字符对 shell 有特殊意义。正如你所见,空格用于在命令行上分隔选项和参数。 “分离选项和参数”属于“特殊含义”范畴。当你想让 shell 忽略一个字符的特殊含义时,你需要转义,你可以在它前面放一个反斜杠(`\`)如: + +``` +mkdir letters\ mom +mkdir letter\ dad +``` + +还有其他特殊字符需要转义,如撇号或单引号(`'`),双引号(`“`)和&符号(`&`): + +``` +mkdir mom\ \&\ dad\'s\ letters +``` + +我知道你在想什么:如果反斜杠有一个特殊的含义(即告诉 shell 它必须转义下一个字符),这也使它成为一个特殊的字符。然后,你将如何转义转义字符(`\`)? + +事实证明,你转义任何其他特殊字符都是同样的方式: + +``` +mkdir special\\characters +``` + +这将生成一个名为 `special\characters/` 的目录。 + +感觉困惑?当然。这就是为什么你应该避免在目录名中使用特殊字符,包括空格。 + +以防误操作你可以参考下面这个记录特殊字符的列表。(LCTT 译注:此处原文链接丢失。) + +### 总结 + + * 使用 `mkdir ` 创建新目录。 + * 使用 `rmdir ` 删除目录(仅在目录为空时才有效)。 + * 使用 `rm -Rf ` 来完全删除目录及其内容 —— 请务必谨慎使用。 + * 使用相对路径创建相对于当前目录的目录: `mkdir newdir`。 + * 使用绝对路径创建相对于根目录(`/`)的目录: `mkdir /home//newdir`。 + * 使用 `..` 在当前目录的上级目录中创建目录: `mkdir ../newdir`。 + * 你可以通过在命令行上使用空格分隔目录名来创建多个目录: `mkdir onedir twodir threedir`。 + * 同时创建多个目录时,你可以混合使用相对路径和绝对路径: `mkdir onedir twodir /home//threedir`。 + * 在目录名称中使用空格和特殊字符真的会让你很头疼,你最好不要那样做。 + +有关更多信息,您可以查看 `mkdir`、`rmdir` 和 `rm` 的手册: + +``` +man mkdir +man rmdir +man rm +``` + +要退出手册页,请按键盘 `q` 键。 + +### 下次预告 + +在下一部分中,你将学习如何创建、修改和删除文件,以及你需要了解的有关权限和特权的所有信息! + +通过 Linux 基金会和 edX 免费提供的[“Introduction to Linux”][4]课程了解有关Linux的更多信息。 + +-------------------------------------------------------------------------------- + +via: https://www.linux.com/blog/learn/2018/5/manipulating-directories-linux + +作者:[Paul Brown][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[way-ww](https://github.com/way-ww) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.linux.com/users/bro66 +[1]:https://linux.cn/article-9798-1.html +[2]:https://userbase.kde.org/Dolphin +[3]:https://projects-old.gnome.org/nautilus/screenshots.html +[4]:https://training.linuxfoundation.org/linux-courses/system-administration-training/introduction-to-linux diff --git a/published/20180518 Mastering CI-CD at OpenDev.md b/published/20180518 Mastering CI-CD at OpenDev.md new file mode 100644 index 0000000000..5418e196e9 --- /dev/null +++ b/published/20180518 Mastering CI-CD at OpenDev.md @@ -0,0 +1,53 @@ +在 OpenDev 大会上学习 CI/CD +====== +> 未来的开发工作需要非常精通 CI/CD 流程。 + +![在OpenDev上,掌握CI/CD](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/BUSINESS_opennature_3.png?itok=J1OSECM_) + +在 2017 年启动后,OpenDev 大会现在已是一个年度活动。在去年 9 月的首届活动上,会议的重点是边缘计算。今年的活动,于 5 月 22 - 23 日举行,会议的重点是持续集成和持续发布 (CI/CD),并与 OpenStack 峰会一起在温哥华举行。 + +基于我在 OpenStack 项目的 CI/CD 系统的技术背景和我近期进入容器下的 CI/CD 方面的经验,我被邀请加入 OpenDev CI/CD 计划委员会。今天我经常借助很多开源技术,例如 [Jenkins][3]、[GitLab][2]、[Spinnaker][4] 和 [Artifactory][5] 来讨论 CI/CD 流程。 + +这次活动对我来说是很激动人心的,因为我们将在这个活动中融合两个开源基础设施理念。首先,我们将讨论可以被任何组织使用的 CI/CD 工具。为此目的,在 [讲演][6] 中,我们将听到关于开源 CI/CD 工具的使用讲演,一场来自 Boris Renski 的关于 Spinnaker 的讲演,和一场来自 Jim Blair 的关于 [Zuul][7] 的讲演。同时,讲演会涉及关于开源技术的偏好的高级别话题,特别是那种跨社区的和本身就是开源项目的。从Fatih Degirmenci 和 Daniel Farrel 那里,我们将听到关于在不同社区分享持续发布实践经历,接着 Benjamin Mako Hill 会为我们带来一场关于为什么自由软件需要自由工具的分享。 + +在分享 CI/CD 相对新颖的特性后,接下来的活动是对话、研讨会和协作讨论的混合组合。当从人们所提交的讲座和研讨会中进行选择,并提出协作讨论主题时,我们希望确保有一个多样灵活的日程表,这样任何参与者都能在 CI/CD 活动进程中发现有趣的东西。 + +这些讲座会是标准的会议风格,选择涵盖关键主题,如制定 CI/CD 流程,在实践 DevOps 时提升安全性,以及更具体的解决方案,如基于容器关于 Kubernetes 的 [Aptomi][8] 和在 ETSI NFV 环境下 CI/CD。这些会话的大部分将会是作为给新接触 CI/CD 或这些特定技术的参与者关于这些话题和理念的简介。 + +交互式的研讨会会持续相对比较长的时间,参与者将会在思想上得到特定的体验。这些研讨会包括 “[在持续集成任务中的异常检测][9]”、“[如何安装 Zuul 和配置第一个任务][10]”,和“[Spinnake 101:快速可靠的软件发布][11]”。(注意这些研讨会空间是有限的,所以设立了一个 RSVP 系统。你们将会在会议的链接里找到一个 RSVP 的按钮。) + +可能最让我最兴奋的是协作讨论,这些协作讨论占据了一半以上的活动安排。协作讨论的主题由计划委员会选取。计划委员会根据我们在社区里所看到来选取对应的主题。这是“鱼缸”风格式的会议,通常是几个人聚在一个房间里围绕着 CI/CD 讨论某一个主题。 + +这次会议风格的理念是来自于开发者峰会,最初是由 Ubuntu 社区提出,接着 OpenStack 社区也在活动上采纳。这些协作讨论的主题包含不同的会议,这些会议是关于 CI/CD 基础,可以鼓励跨社区协作的提升举措,在组织里推行 CI/CD 文化,和为什么开源 CI/CD 工具如此重要。采用共享文档来做会议笔记,以确保尽可能的在会议的过程中分享知识。在讨论过程中,提出行动项目也是很常见的,因此社区成员可以推动和所涉及的主题相关的倡议。 + +活动将以联合总结会议结束。联合总结会议将总结来自协同讨论的关键点和为即将在这个领域工作的参与者指出可选的职业范围。 + +可以在 [OpenStack 峰会注册页][13] 上注册参加活动。或者可以在温哥华唯一指定售票的会议中心购买活动的入场券,价格是 $199。更多关于票和全部的活动安排见官网 [OpenDev 网站][1]。 + +我希望你们能够加入我们,并在温哥华渡过令人激动的两天,并且在这两天的活动中学习,协作和在 CI/CD 取得进展。 + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/5/opendev + +作者:[Elizabeth K.Joseph][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[jamelouis](https://github.com/jamelouis) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://opensource.com/users/pleia2 +[1]:http://2018.opendevconf.com/ +[2]:https://about.gitlab.com/ +[3]:https://jenkins.io/ +[4]:https://www.spinnaker.io/ +[5]:https://jfrog.com/artifactory/ +[6]:http://2018.opendevconf.com/schedule/ +[7]:https://zuul-ci.org/ +[8]:http://aptomi.io/ +[9]:https://www.openstack.org/summit/vancouver-2018/summit-schedule/events/21692/anomaly-detection-in-continuous-integration-jobs +[10]:https://www.openstack.org/summit/vancouver-2018/summit-schedule/events/21693/how-to-install-zuul-and-configure-your-first-jobs +[11]:https://www.openstack.org/summit/vancouver-2018/summit-schedule/events/21699/spinnaker-101-releasing-software-with-velocity-and-confidence +[12]:https://www.openstack.org/summit/vancouver-2018/summit-schedule/events/21831/opendev-cicd-joint-collab-conclusion +[13]:https://www.eventbrite.com/e/openstack-summit-may-2018-vancouver-tickets-40845826968?aff=VancouverSummit2018 diff --git a/published/20180525 Getting started with the Python debugger.md b/published/20180525 Getting started with the Python debugger.md new file mode 100644 index 0000000000..b966b0a473 --- /dev/null +++ b/published/20180525 Getting started with the Python debugger.md @@ -0,0 +1,279 @@ +Python 调试器入门 +====== + +![](https://fedoramagazine.org/wp-content/uploads/2018/05/pdb-816x345.jpg) + +Python 生态系统包含丰富的工具和库,可以让开发人员更加舒适。 例如,我们之前已经介绍了如何[使用交互式 shell 增强 Python][1]。本文重点介绍另一种可以节省时间并提高 Python 技能的工具:Python 调试器。 + +### Python 调试器 + +Python 标准库提供了一个名为 pdb 的调试器。此调试器提供了调试所需的大多数功能,如断点、单行步进、堆栈帧的检查等等。 + +了解一些pdb 的基本知识很有用,因为它是标准库的一部分。 你可以在无法安装其他增强的调试器的环境中使用它。 + +#### 运行 pdb + +运行 pdb 的最简单方法是从命令行,将程序作为参数传递来调试。 看看以下脚本: + +``` +# pdb_test.py +#!/usr/bin/python3 + +from time import sleep + +def countdown(number): + for i in range(number, 0, -1): + print(i) + sleep(1) + + +if __name__ == "__main__": + seconds = 10 + countdown(seconds) +``` + +你可以从命令行运行 pdb,如下所示: + +``` +$ python3 -m pdb pdb_test.py +> /tmp/pdb_test.py(1)() +-> from time import sleep +(Pdb) +``` + +使用 pdb 的另一种方法是在程序中设置断点。为此,请导入 `pdb` 模块并使用`set_trace` 函数: + +``` +# pdb_test.py +#!/usr/bin/python3 + +from time import sleep + + +def countdown(number): + for i in range(number, 0, -1): + import pdb; pdb.set_trace() + print(i) + sleep(1) + + +if __name__ == "__main__": + seconds = 10 + countdown(seconds) +``` + +``` +$ python3 pdb_test.py +> /tmp/pdb_test.py(6)countdown() +-> print(i) +(Pdb) +``` + +脚本在断点处停止,pdb 显示脚本中的下一行。 你也可以在失败后执行调试器。 这称为事后调试postmortem debugging。 + +#### 穿行于执行堆栈 + +调试中的一个常见用例是在执行堆栈中穿行。 Python 调试器运行后,可以使用以下命令: + ++ `w(here)`:显示当前执行的行以及执行堆栈的位置。 + + ``` +$ python3 test_pdb.py +> /tmp/test_pdb.py(10)countdown() +-> print(i) +(Pdb) w +/tmp/test_pdb.py(16)() +-> countdown(seconds) +> /tmp/test_pdb.py(10)countdown() +-> print(i) +(Pdb) +``` + ++ `l(ist)`:显示当前位置周围更多的上下文(代码)。 + + ``` +$ python3 test_pdb.py +> /tmp/test_pdb.py(10)countdown() +-> print(i) +(Pdb) l + 5 + 6 + 7 def countdown(number): + 8 for i in range(number, 0, -1): + 9 import pdb; pdb.set_trace() + 10 -> print(i) + 11 sleep(1) + 12 + 13 + 14 if __name__ == "__main__": + 15 seconds = 10 +``` + ++ `u(p)`/`d(own)`:向上或向下穿行调用堆栈。 + + ``` +$ py3 test_pdb.py +> /tmp/test_pdb.py(10)countdown() +-> print(i) +(Pdb) up +> /tmp/test_pdb.py(16)() +-> countdown(seconds) +(Pdb) down +> /tmp/test_pdb.py(10)countdown() +-> print(i) +(Pdb) +``` + +#### 单步执行程序 + +pdb提供以下命令来执行和单步执行代码: + ++ `n(ext)`:继续执行,直到达到当前函数中的下一行,或者返回 ++ `s(tep)`:执行当前行并在第一个可能的场合停止(在被调用的函数或当前函数中) ++ `c(ontinue)`:继续执行,仅在断点处停止。 + + ``` +$ py3 test_pdb.py +> /tmp/test_pdb.py(10)countdown() +-> print(i) +(Pdb) n +10 +> /tmp/test_pdb.py(11)countdown() +-> sleep(1) +(Pdb) n +> /tmp/test_pdb.py(8)countdown() +-> for i in range(number, 0, -1): +(Pdb) n +> /tmp/test_pdb.py(9)countdown() +-> import pdb; pdb.set_trace() +(Pdb) s +--Call-- +> /usr/lib64/python3.6/pdb.py(1584)set_trace() +-> def set_trace(): +(Pdb) c +> /tmp/test_pdb.py(10)countdown() +-> print(i) +(Pdb) c +9 +> /tmp/test_pdb.py(9)countdown() +-> import pdb; pdb.set_trace() +(Pdb) +``` + + 该示例显示了 `next` 和 `step` 之间的区别。 实际上,当使用 `step` 时,调试器会进入 `pdb` 模块源代码,而接下来就会执行 `set_trace` 函数。 + +#### 检查变量内容 + ++ pdb 非常有用的地方是检查执行堆栈中存储的变量的内容。 例如,`a(rgs)` 命令打印当前函数的变量,如下所示: + + ``` +py3 test_pdb.py +> /tmp/test_pdb.py(10)countdown() +-> print(i) +(Pdb) where +/tmp/test_pdb.py(16)() +-> countdown(seconds) +> /tmp/test_pdb.py(10)countdown() +-> print(i) +(Pdb) args +number = 10 +(Pdb) +``` + + pdb 打印变量的值,在本例中是 10。 + ++ 可用于打印变量值的另一个命令是 `p(rint)`。 + + ``` +$ py3 test_pdb.py +> /tmp/test_pdb.py(10)countdown() +-> print(i) +(Pdb) list + 5 + 6 + 7 def countdown(number): + 8 for i in range(number, 0, -1): + 9 import pdb; pdb.set_trace() + 10 -> print(i) + 11 sleep(1) + 12 + 13 + 14 if __name__ == "__main__": + 15 seconds = 10 +(Pdb) print(seconds) +10 +(Pdb) p i +10 +(Pdb) p number - i +0 +(Pdb) +``` + + 如示例中最后的命令所示,`print` 可以在显示结果之前计算表达式。 + +[Python 文档][2]包含每个 pdb 命令的参考和示例。 对于开始使用 Python 调试器人来说,这是一个有用的读物。 + +### 增强的调试器 + +一些增强的调试器提供了更好的用户体验。 大多数为 pdb 添加了有用的额外功能,例如语法突出高亮、更好的回溯和自省。 流行的增强调试器包括 [IPython 的 ipdb][3] 和 [pdb++][4]。 + +这些示例显示如何在虚拟环境中安装这两个调试器。 这些示例使用新的虚拟环境,但在调试应用程序的情况下,应使用应用程序的虚拟环境。 + +#### 安装 IPython 的 ipdb + +要安装 IPython ipdb,请在虚拟环境中使用 `pip`: + +``` +$ python3 -m venv .test_pdb +$ source .test_pdb/bin/activate +(test_pdb)$ pip install ipdb +``` + +要在脚本中调用 ipdb,必须使用以下命令。 请注意,该模块称为 ipdb 而不是 pdb: + +``` +import ipdb; ipdb.set_trace() +``` + +IPython 的 ipdb 也可以用 Fedora 包安装,所以你可以使用 Fedora 的包管理器 `dnf` 来安装它: + +``` +$ sudo dnf install python3-ipdb +``` + +#### 安装 pdb++ + +你可以类似地安装 pdb++: + +``` +$ python3 -m venv .test_pdb +$ source .test_pdb/bin/activate +(test_pdb)$ pip install pdbp +``` + +pdb++ 重写了 pdb 模块,因此你可以使用相同的语法在程序中添加断点: + +``` +import pdb; pdb.set_trace() +``` + +### 总结 + +学习如何使用 Python 调试器可以节省你在排查应用程序问题时的时间。 对于了解应用程序或某些库的复杂部分如何工作也是有用的,从而提高 Python 开发人员的技能。 + +-------------------------------------------------------------------------------- + +via: https://fedoramagazine.org/getting-started-python-debugger/ + +作者:[Clément Verna][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[Flowsnow](https://github.com/Flowsnow) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://fedoramagazine.org +[1]:https://fedoramagazine.org/enhance-python-interactive-shell +[2]:https://docs.python.org/3/library/pdb.html +[3]:https://github.com/gotcha/ipdb +[4]:https://github.com/antocuni/pdb diff --git a/published/20180529 How To Add Additional IP (Secondary IP) In Ubuntu System.md b/published/20180529 How To Add Additional IP (Secondary IP) In Ubuntu System.md new file mode 100644 index 0000000000..37a95c6b0b --- /dev/null +++ b/published/20180529 How To Add Additional IP (Secondary IP) In Ubuntu System.md @@ -0,0 +1,341 @@ +如何在 Ubuntu 系统中添加一个辅助 IP 地址 +====== + +Linux 管理员应该意识到这一点,因为这是一项例行任务。很多人想知道为什么我们需要在服务器中添加多个 IP 地址,以及为什么我们需要将它添加到单块网卡中?我说的对吗? + +你可能也会有类似的问题:在 Linux 中如何为单块网卡分配多个 IP 地址?在本文中,你可以得到答案。 + +当我们对一个新服务器进行设置时,理想情况下它将有一个 IP 地址,即服务器主 IP 地址,它与服务器主机名对应。 + +我们不应在服务器主 IP 地址上托管任何应用程序,这是不可取的。如果要在服务器上托管任何应用程序,我们应该为此添加辅助 IP。 + +这是业界的最佳实践,它允许用户安装 SSL 证书。大多数系统都配有单块网卡,这足以添加额外的 IP 地址。 + +**建议阅读:** + +- [在 Linux 命令行中 9 种方法检查公共 IP 地址][1] +- [在 Linux 终端中 3 种简单的方式来检查 DNS(域名服务器)记录][2] +- [在 Linux 上使用 Dig 命令检查 DNS(域名服务器)记录][3] +- [在 Linux 上使用 Nslookup 命令检查 DNS(域名服务器)记录][4] +- [在 Linux 上使用 Host 命令检查 DNS(域名服务器)记录][5] + +我们可以在同一个接口上添加 IP 地址,或者在同一设备上创建子接口,然后在其中添加 IP。默认情况下,一直到 Ubuntu 14.04 LTS,接口给名称为 `ethX (eth0)`,但是从 Ubuntu 15.10 之后网络接口名称已从 `ethX` 更改为 `enXXXXX`(对于服务器是 ens33,桌面版是 enp0s3)。 + +在本文中,我们将教你如何在 Ubuntu 上执行此操作,并且衍生到其它发行版(to 校正:这句自己加的)。 + +**注意:**别在 DNS 详细信息后添加 IP 地址。如果是这样,DNS 将无法正常工作。 + +### 如何在 Ubuntu 14.04 LTS 中添加临时辅助 IP 地址 + +在系统中添加 IP 地址之前,运行以下任一命令即可验证服务器主 IP 地址: + +``` +# ifconfig +或 +# ip addr + +# ip addr + +eth0 Link encap:Ethernet HWaddr 08:00:27:98:b7:36 + inet addr:192.168.56.150 Bcast:192.168.56.255 Mask:255.255.255.0 + inet6 addr: fe80::a00:27ff:fe98:b736/64 Scope:Link + UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 + RX packets:4 errors:0 dropped:0 overruns:0 frame:0 + TX packets:105 errors:0 dropped:0 overruns:0 carrier:0 + collisions:0 txqueuelen:1000 + RX bytes:902 (902.0 B) TX bytes:16423 (16.4 KB) + +eth1 Link encap:Ethernet HWaddr 08:00:27:6a:cf:d3 + inet addr:10.0.3.15 Bcast:10.0.3.255 Mask:255.255.255.0 + inet6 addr: fe80::a00:27ff:fe6a:cfd3/64 Scope:Link + UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 + RX packets:80 errors:0 dropped:0 overruns:0 frame:0 + TX packets:146 errors:0 dropped:0 overruns:0 carrier:0 + collisions:0 txqueuelen:1000 + RX bytes:8698 (8.6 KB) TX bytes:17047 (17.0 KB) + +lo Link encap:Local Loopback + inet addr:127.0.0.1 Mask:255.0.0.0 + inet6 addr: ::1/128 Scope:Host + UP LOOPBACK RUNNING MTU:65536 Metric:1 + RX packets:25 errors:0 dropped:0 overruns:0 frame:0 + TX packets:25 errors:0 dropped:0 overruns:0 carrier:0 + collisions:0 txqueuelen:1 + RX bytes:1730 (1.7 KB) TX bytes:1730 (1.7 KB) +``` + +如我所见,服务器主 IP 地址是 `192.168.56.150`,我将下一个 IP `192.168.56.151` 作为辅助 IP,使用以下方法完成: + +``` +# ip addr add 192.168.56.151/24 broadcast 192.168.56.255 dev eth0 label eth0:1 +``` + +输入以下命令以检查新添加的 IP 地址。如果你重新启动服务器,那么新添加的 IP 地址会消失,因为我们的 IP 是临时添加的。 + +``` +# ip addr +1: lo: mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1 + link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 + inet 127.0.0.1/8 scope host lo + valid_lft forever preferred_lft forever + inet6 ::1/128 scope host + valid_lft forever preferred_lft forever +2: eth0: mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 + link/ether 08:00:27:98:b7:36 brd ff:ff:ff:ff:ff:ff + inet 192.168.56.150/24 brd 192.168.56.255 scope global eth0 + valid_lft forever preferred_lft forever + inet 192.168.56.151/24 brd 192.168.56.255 scope global secondary eth0:1 + valid_lft forever preferred_lft forever + inet6 fe80::a00:27ff:fe98:b736/64 scope link + valid_lft forever preferred_lft forever +3: eth1: mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 + link/ether 08:00:27:6a:cf:d3 brd ff:ff:ff:ff:ff:ff + inet 10.0.3.15/24 brd 10.0.3.255 scope global eth1 + valid_lft forever preferred_lft forever + inet6 fe80::a00:27ff:fe6a:cfd3/64 scope link + valid_lft forever preferred_lft forever +``` + +### 如何在 Ubuntu 14.04 LTS 中添加永久辅助 IP 地址 + +要在 Ubuntu 系统上添加永久辅助 IP 地址,只需编辑 `/etc/network/interfaces` 文件并添加所需的 IP 详细信息。 + +``` +# vi /etc/network/interfaces +``` + +``` +# vi /etc/network/interfaces + +# The loopback network interface +auto lo +iface lo inet loopback + +# The primary network interface +auto eth0 +iface eth0 inet static + address 192.168.56.150 + netmask 255.255.255.0 + network 192.168.56.0 + broadcast 192.168.56.255 + gateway 192.168.56.1 + +auto eth0:1 +iface eth0:1 inet static + address 192.168.56.151 + netmask 255.255.255.0 +``` + +保存并关闭文件,然后重启网络接口服务。 + +``` +# service networking restart +或 +# ifdown eth0:1 && ifup eth0:1 +``` + +验证新添加的 IP 地址: + +``` +# ifconfig +eth0 Link encap:Ethernet HWaddr 08:00:27:98:b7:36 + inet addr:192.168.56.150 Bcast:192.168.56.255 Mask:255.255.255.0 + inet6 addr: fe80::a00:27ff:fe98:b736/64 Scope:Link + UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 + RX packets:5 errors:0 dropped:0 overruns:0 frame:0 + TX packets:84 errors:0 dropped:0 overruns:0 carrier:0 + collisions:0 txqueuelen:1000 + RX bytes:962 (962.0 B) TX bytes:11905 (11.9 KB) + +eth0:1 Link encap:Ethernet HWaddr 08:00:27:98:b7:36 + inet addr:192.168.56.151 Bcast:192.168.56.255 Mask:255.255.255.0 + UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 + +eth1 Link encap:Ethernet HWaddr 08:00:27:6a:cf:d3 + inet addr:10.0.3.15 Bcast:10.0.3.255 Mask:255.255.255.0 + inet6 addr: fe80::a00:27ff:fe6a:cfd3/64 Scope:Link + UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 + RX packets:4924 errors:0 dropped:0 overruns:0 frame:0 + TX packets:3185 errors:0 dropped:0 overruns:0 carrier:0 + collisions:0 txqueuelen:1000 + RX bytes:4037636 (4.0 MB) TX bytes:422516 (422.5 KB) + +lo Link encap:Local Loopback + inet addr:127.0.0.1 Mask:255.0.0.0 + inet6 addr: ::1/128 Scope:Host + UP LOOPBACK RUNNING MTU:65536 Metric:1 + RX packets:0 errors:0 dropped:0 overruns:0 frame:0 + TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 + collisions:0 txqueuelen:1 + RX bytes:0 (0.0 B) TX bytes:0 (0.0 B) +``` + +### 如何在 Ubuntu 16.04 LTS 中临时添加辅助 IP 地址 + +正如本文开头所述,网络接口名称从 Ubuntu 15.10 就开始从 ‘ethX’ 更改为 ‘enXXXX’ (enp0s3),所以,替换你的接口名称。 + +在执行此操作之前,先检查系统上的 IP 信息: + +``` +# ifconfig +或 +# ip addr + +enp0s3: flags=4163 mtu 1500 + inet 192.168.56.201 netmask 255.255.255.0 broadcast 192.168.56.255 + inet6 fe80::a00:27ff:fe97:132e prefixlen 64 scopeid 0x20 + ether 08:00:27:97:13:2e txqueuelen 1000 (Ethernet) + RX packets 7 bytes 420 (420.0 B) + RX errors 0 dropped 0 overruns 0 frame 0 + TX packets 294 bytes 24747 (24.7 KB) + TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 + +enp0s8: flags=4163 mtu 1500 + inet 10.0.3.15 netmask 255.255.255.0 broadcast 10.0.3.255 + inet6 fe80::344b:6259:4dbe:eabb prefixlen 64 scopeid 0x20 + ether 08:00:27:12:e8:c1 txqueuelen 1000 (Ethernet) + RX packets 1 bytes 590 (590.0 B) + RX errors 0 dropped 0 overruns 0 frame 0 + TX packets 97 bytes 10209 (10.2 KB) + TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 + +lo: flags=73 mtu 65536 + inet 127.0.0.1 netmask 255.0.0.0 + inet6 ::1 prefixlen 128 scopeid 0x10 + loop txqueuelen 1000 (Local Loopback) + RX packets 325 bytes 24046 (24.0 KB) + RX errors 0 dropped 0 overruns 0 frame 0 + TX packets 325 bytes 24046 (24.0 KB) + TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 +``` + +如我所见,服务器主 IP 地址是 `192.168.56.201`,所以,我将下一个 IP `192.168.56.202` 作为辅助 IP,使用以下命令完成。 + +``` +# ip addr add 192.168.56.202/24 broadcast 192.168.56.255 dev enp0s3 +``` + +运行以下命令来检查是否已分配了新的 IP。当你重启机器时,它会消失。 + +``` +# ip addr +1: lo: mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 + link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 + inet 127.0.0.1/8 scope host lo + valid_lft forever preferred_lft forever + inet6 ::1/128 scope host + valid_lft forever preferred_lft forever +2: enp0s3: mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 + link/ether 08:00:27:97:13:2e brd ff:ff:ff:ff:ff:ff + inet 192.168.56.201/24 brd 192.168.56.255 scope global enp0s3 + valid_lft forever preferred_lft forever + inet 192.168.56.202/24 brd 192.168.56.255 scope global secondary enp0s3 + valid_lft forever preferred_lft forever + inet6 fe80::a00:27ff:fe97:132e/64 scope link + valid_lft forever preferred_lft forever +3: enp0s8: mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 + link/ether 08:00:27:12:e8:c1 brd ff:ff:ff:ff:ff:ff + inet 10.0.3.15/24 brd 10.0.3.255 scope global dynamic enp0s8 + valid_lft 86353sec preferred_lft 86353sec + inet6 fe80::344b:6259:4dbe:eabb/64 scope link + valid_lft forever preferred_lft forever +``` + +### 如何在 Ubuntu 16.04 LTS 中添加永久辅助 IP 地址 + +要在 Ubuntu 系统上添加永久辅助 IP 地址,只需编辑 `/etc/network/interfaces` 文件并添加所需 IP 的详细信息。 + +我们不应该在 `dns-nameservers` 行之后添加辅助 IP 地址,因为它不会起作用,应该以下面的格式添加 IP 详情。 + +此外,我们不需要添加子接口(我们之前在 Ubuntu 14.04 LTS 中的做法): + +``` +# vi /etc/network/interfaces + +# interfaces(5) file used by ifup(8) and ifdown(8) +auto lo +iface lo inet loopback + +# The primary network interface +auto enp0s3 +iface enp0s3 inet static +address 192.168.56.201 +netmask 255.255.255.0 + +iface enp0s3 inet static +address 192.168.56.202 +netmask 255.255.255.0 + +gateway 192.168.56.1 +network 192.168.56.0 +broadcast 192.168.56.255 +dns-nameservers 8.8.8.8 8.8.4.4 +dns-search 2daygeek.local +``` + +保存并关闭文件,然后重启网络接口服务: + +``` +# systemctl restart networking +或 +# ifdown enp0s3 && ifup enp0s3 +``` + +运行以下命令来检查是否已经分配了新的 IP: + +``` +# ip addr +1: lo: mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 + link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 + inet 127.0.0.1/8 scope host lo + valid_lft forever preferred_lft forever + inet6 ::1/128 scope host + valid_lft forever preferred_lft forever +2: enp0s3: mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 + link/ether 08:00:27:97:13:2e brd ff:ff:ff:ff:ff:ff + inet 192.168.56.201/24 brd 192.168.56.255 scope global enp0s3 + valid_lft forever preferred_lft forever + inet 192.168.56.202/24 brd 192.168.56.255 scope global secondary enp0s3 + valid_lft forever preferred_lft forever + inet6 fe80::a00:27ff:fe97:132e/64 scope link + valid_lft forever preferred_lft forever +3: enp0s8: mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 + link/ether 08:00:27:12:e8:c1 brd ff:ff:ff:ff:ff:ff + inet 10.0.3.15/24 brd 10.0.3.255 scope global dynamic enp0s8 + valid_lft 86353sec preferred_lft 86353sec + inet6 fe80::344b:6259:4dbe:eabb/64 scope link + valid_lft forever preferred_lft forever +``` + +让我来 ping 一下新 IP 地址: + +``` +# ping 192.168.56.202 -c 4 +PING 192.168.56.202 (192.168.56.202) 56(84) bytes of data. +64 bytes from 192.168.56.202: icmp_seq=1 ttl=64 time=0.019 ms +64 bytes from 192.168.56.202: icmp_seq=2 ttl=64 time=0.087 ms +64 bytes from 192.168.56.202: icmp_seq=3 ttl=64 time=0.034 ms +64 bytes from 192.168.56.202: icmp_seq=4 ttl=64 time=0.042 ms + +--- 192.168.56.202 ping statistics --- +4 packets transmitted, 4 received, 0% packet loss, time 3068ms +rtt min/avg/max/mdev = 0.019/0.045/0.087/0.026 ms +``` + +-------------------------------------------------------------------------------- + +via: https://www.2daygeek.com/how-to-add-additional-ip-secondary-ip-in-ubuntu-debian-system/ + +作者:[Prakash Subramanian][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[MjSeven](https://github.com/MjSeven) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.2daygeek.com/author/prakash/ +[1]:https://www.2daygeek.com/check-find-server-public-ip-address-linux/ +[2]:https://www.2daygeek.com/check-find-dns-records-of-domain-in-linux-terminal/ +[3]:https://www.2daygeek.com/dig-command-check-find-dns-records-lookup-linux/ +[4]:https://www.2daygeek.com/nslookup-command-check-find-dns-records-lookup-linux/ +[5]:https://www.2daygeek.com/host-command-check-find-dns-records-lookup-linux/ diff --git a/published/20180618 Twitter Sentiment Analysis using NodeJS.md b/published/20180618 Twitter Sentiment Analysis using NodeJS.md new file mode 100644 index 0000000000..a179c7bc4f --- /dev/null +++ b/published/20180618 Twitter Sentiment Analysis using NodeJS.md @@ -0,0 +1,206 @@ +用 NodeJS 进行 Twitter 情感分析 +============================================================ + + +![](https://i.imgur.com/7hIfpzt.png) + +如果你想知道大家对某件事情的看法,Twitter 是最好的地方了。Twitter 是观点持续不断的涌现出来的地方,每秒钟大概有 6000 条新 Twitter 发送出来。因特网上的发展很快,如果你想与时俱进或者跟上潮流,Twitter 就是你要去的地方。 + +现在,我们生活在一个数据为王的时代,很多公司都善于运用 Twitter 上的数据。根据测量到的他们新产品的人气,尝试预测之后的市场趋势,分析 Twitter 上的数据有很多用处。通过数据,商人把产品卖给合适的用户,收集关于他们品牌和改进的反馈,或者获取他们产品或促销活动失败的原因。不仅仅是商人,很多政治和经济上的决定是在观察人们意见的基础上所作的。今天,我会试着让你感受下关于 Twitter 的简单 [情感分析][1],判断这个 Twitter 是正能量、负能量还是中性的。这不会像专业人士所用的那么复杂,但至少,它会让你知道挖掘观念的想法。 + +我们将使用 NodeJs,因为 JavaScript 太常用了,而且它还是最容易入门的语言。 + +### 前置条件: + +* 安装了 NodeJs 和 NPM +* 有 NodeJs 和 NPM 包的经验 +* 熟悉命令行。 + +好了,就是这样。开始吧。 + +### 开始 + +为了你的项目新建一个目录,进入这个目录下面。打开终端(或是命令行)。进入刚创建的目录下面,运行命令 `npm init -y`。这会在这个目录下创建一个 `package.json` 文件。现在我们可以安装需要的 npm 包了。只需要创建一个新文件,命名为 `index.js` 然后我们就完成了初始的编码。 + +### 获取推文 + +好了,我们想要分析 Twitter ,为了实现这个目的,我们需要以编程的方式访问 Twitter。为此,我们要用到 [twit][2] 包。因此,先用 `npm i wit` 命令安装它。我们还需要注册一个 App,以通过我们的账户来访问 Twitter 的 API。点击这个 [链接][3],填写所有项目,从 “Keys and Access Token” 标签页中复制 “Consumer Key”、“Consumer Secret”、“Access token” 和 “Access Token Secret” 这几项到一个 `.env` 文件中,就像这样: + +``` +# .env +# replace the stars with values you copied +CONSUMER_KEY=************ +CONSUMER_SECRET=************ +ACCESS_TOKEN=************ +ACCESS_TOKEN_SECRET=************ +``` + +现在开始。 + +用你最喜欢的代码编辑器打开 `index.js`。我们需要用 `npm i dotenv` 命令安装 `dotenv` 包来读取 `.env` 文件。好了,创建一个 API 实例。 + +``` +const Twit = require('twit'); +const dotenv = require('dotenv'); + +dotenv.config(); + +const { CONSUMER_KEY + , CONSUMER_SECRET + , ACCESS_TOKEN + , ACCESS_TOKEN_SECRET + } = process.env; + +const config_twitter = { + consumer_key: CONSUMER_KEY, + consumer_secret: CONSUMER_SECRET, + access_token: ACCESS_TOKEN, + access_token_secret: ACCESS_TOKEN_SECRET, + timeout_ms: 60*1000 +}; + +let api = new Twit(config_twitter); +``` + +这里已经用所需的配置文件建立了到 Twitter 上的连接。但我们什么事情都没做。先定义个获取推文的函数: + +``` +async function get_tweets(q, count) { + let tweets = await api.get('search/tweets', {q, count, tweet_mode: 'extended'}); + return tweets.data.statuses.map(tweet => tweet.full_text); +} +``` + +这是个 async 函数,因为 `api.get` 函数返回一个 promise 对象,而不是 `then` 链,我想通过这种简单的方式获取推文。它接收两个参数 `q` 和 `count`,`q` 是查询或者我们想要搜索的关键字,`count` 是让这个 `api` 返回的推文数量。 + +目前为止我们拥有了一个从 Twitter 上获取完整文本的简单方法。不过这里有个问题,现在我们要获取的文本中可能包含某些连接或者由于转推而被截断了。所以我们会编写另一个函数,拆解并返回推文的文本,即便是转发的推文,并且其中有链接的话就删除。 + +``` +function get_text(tweet) { + let txt = tweet.retweeted_status ? tweet.retweeted_status.full_text : tweet.full_text; + return txt.split(/ |\n/).filter(v => !v.startsWith('http')).join(' '); + } + +async function get_tweets(q, count) { + let tweets = await api.get('search/tweets', {q, count, 'tweet_mode': 'extended'}); + return tweets.data.statuses.map(get_text); +} +``` + +现在我们拿到了文本。下一步是从文本中获取情感。为此我们会使用 `npm` 中的另一个包 —— [`sentiment`][4]。让我们像安装其他包那样安装 `sentiment`,添加到脚本中。 + +``` +const sentiment = require('sentiment') +``` + +`sentiment` 用起来很简单。我们只用把 `sentiment` 函数用在我们想要分析的文本上,它就能返回文本的相对分数。如果分数小于 0,它表达的就是消极情感,大于 0 的分数是积极情感,而 0,如你所料,表示中性的情感。基于此,我们将会把推文打印成不同的颜色 —— 绿色表示积极,红色表示消极,蓝色表示中性。为此,我们会用到 [`colors`][5] 包。先安装这个包,然后添加到脚本中。 + +``` +const colors = require('colors/safe'); +``` + +好了,现在把所有东西都整合到 `main` 函数中。 + +``` +async function main() { + let keyword = \* define the keyword that you want to search for *\; + let count = \* define the count of tweets you want *\; + let tweets = await get_tweets(keyword, count); + for (tweet of tweets) { + let score = sentiment(tweet).comparative; + tweet = `${tweet}\n`; + if (score > 0) { + tweet = colors.green(tweet); + } else if (score < 0) { + tweet = colors.red(tweet); + } else { + tweet = colors.blue(tweet); + } + console.log(tweet); + } +} +``` + +最后,执行 `main` 函数。 + +``` +main(); +``` + +就是这样,一个简单的分析推文中的基本情感的脚本。 + +``` +\\ full script +const Twit = require('twit'); +const dotenv = require('dotenv'); +const sentiment = require('sentiment'); +const colors = require('colors/safe'); + +dotenv.config(); + +const { CONSUMER_KEY + , CONSUMER_SECRET + , ACCESS_TOKEN + , ACCESS_TOKEN_SECRET + } = process.env; + +const config_twitter = { + consumer_key: CONSUMER_KEY, + consumer_secret: CONSUMER_SECRET, + access_token: ACCESS_TOKEN, + access_token_secret: ACCESS_TOKEN_SECRET, + timeout_ms: 60*1000 +}; + +let api = new Twit(config_twitter); + +function get_text(tweet) { + let txt = tweet.retweeted_status ? tweet.retweeted_status.full_text : tweet.full_text; + return txt.split(/ |\n/).filter(v => !v.startsWith('http')).join(' '); + } + +async function get_tweets(q, count) { + let tweets = await api.get('search/tweets', {q, count, 'tweet_mode': 'extended'}); + return tweets.data.statuses.map(get_text); +} + +async function main() { + let keyword = 'avengers'; + let count = 100; + let tweets = await get_tweets(keyword, count); + for (tweet of tweets) { + let score = sentiment(tweet).comparative; + tweet = `${tweet}\n`; + if (score > 0) { + tweet = colors.green(tweet); + } else if (score < 0) { + tweet = colors.red(tweet); + } else { + tweet = colors.blue(tweet) + } + console.log(tweet) + } +} + +main(); +``` + +-------------------------------------------------------------------------------- + +via: https://boostlog.io/@anshulc95/twitter-sentiment-analysis-using-nodejs-5ad1331247018500491f3b6a + +作者:[Anshul Chauhan][a] +译者:[BriFuture](https://github.com/BriFuture) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://boostlog.io/@anshulc95 +[1]:https://en.wikipedia.org/wiki/Sentiment_analysis +[2]:https://github.com/ttezel/twit +[3]:https://boostlog.io/@anshulc95/apps.twitter.com +[4]:https://www.npmjs.com/package/sentiment +[5]:https://www.npmjs.com/package/colors +[6]:https://boostlog.io/tags/nodejs +[7]:https://boostlog.io/tags/twitter +[8]:https://boostlog.io/@anshulc95 diff --git a/published/20180626 How to build a professional network when you work in a bazaar.md b/published/20180626 How to build a professional network when you work in a bazaar.md new file mode 100644 index 0000000000..fc9452edbc --- /dev/null +++ b/published/20180626 How to build a professional network when you work in a bazaar.md @@ -0,0 +1,87 @@ +在开源“集市”工作时如何建立一个职业网络 +====== + +> 在组织内建立联系遇到问题了吗?你或许是采用了错误的策略。 + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/connection_people_team_collaboration.png?itok=0_vQT8xV) + +职业社交网络 —— 在同事或专业人员之间建立人际联系 —— 可以采用多种形式、在产业内跨组织进行。建立职业网络需要花费时间和精力,并且当某位成员加入或离开一个组织时,此人的网络通常需要被在一个新的工作环境中重建。 + +职业社交网络在不同组织中起相似作用 —— 信息共享、导师制、机会、工作利益和其他作用 —— 然而传统组织与开放组织在组织内构建特定联系的*方法*和*原因*可能不尽相同。这些差异有其影响:同事联系方式、如何建立信任、组织内多元化的程度和种类以及建立合作的能力,所有这些因素都是相互关联的,而且它们参与并塑造了人们所建立的社交网络。 + +一个开放的组织对包容性的强调可以使社交网络在解决商业问题上比传统等级制组织更加高效。这种观念在开源的思考中有很久的历史。例如,在[《教堂与集市》][1]The Cathedral and the Bazaar中,埃里克·雷蒙德写道:“许多年前社会学家发现,相比一个随机选择的观察者的观点,许多同等专业的(或是同等无知的)观察家的普遍观点是可靠得多的预言。”所以让我们了解社交网络的结构和目的如何影响各类组织的价值观。 + +### 传统组织中的社交网络 + +当我在传统组织工作并要描述我为工作做了什么时,人们问我的第一件事就是我与其他人(通常是总监级的领导)的关系。“你在希拉手下吗?”他们会这么问。“你为马尔科姆工作吗?”这意味着以一种上下级的视角看待传统组织的作用;当试图安排工作或雇员时,人们想要从上下级的角度理解网络结构。 + +换言之,在传统组织中社交网络依赖于等级制结构,因此他们彼此跟随。事实上,甚至弄清一个雇员在关系网中处于怎样的位置也算得上是一种“上下级组织”式的担忧。 + +然而并非所有潜在等级制都是如此。它还视相关人员而定。对于上下级网络的关注会决定雇员在网络中的“价值”,因为网络本身是一个持续的权力关系的系统,它会根据人不同水平的价值给予他们不同的定位。它淡化了个人的能力和技能的重要性。因此,一个人在传统组织的联系促使其能力具有前瞻性,为人所知,有影响力并在其事业中起到支持作用。 + +相比传统等级制组织,一个开放的组织对包容性的强调能使网络解决商业问题更加高效。 + +传统组织的正式结构以特定方式决定着雇员的社交网络 —— 有些可能是优点,有些可能是缺点,这取决于具体环境——例如: + + * 要更快速地了解“谁是谁”并看到人们如何关联是较为便捷的(通常这在特定层级内建立信任网络)。 + * 通常,这种对关系的进一步的理解意味着会有更少的过剩工作(在一个特定网络中项目有清晰的相应的归属者)和过多交流(人们知道谁对交流什么负责)。 + * 相关人员会感到在一个权力结构中感到束手无策,或好像他们不能“闯入”权力结构中,这些结构有时(或更多时候)因为裁员并不起作用。 + * 完成大量的工作和努力是困难的,并且合作会很艰难。 + * 权力转让缓慢;一个人的参与能力更多地决定于等级结构所创造的网络的结盟而非其他因素(比如个人能力),减少了被看做社区和成员利益的东西。 + * 竞争似乎更加清晰;理解“谁在竞争什么”通常发生在一个公认的、被限定了的等级结构中(权力网络中职位的缺乏增进了竞争因此竞争会更激烈)。 + * 当更严格的网络决定了灵活性的限度时,适应能力会受损。网络的“夙愿”和合作的限度也会以同样的方式受影响。 + * 在严格的网络中,方向明确,并且领导人通常靠过度指导来进行管理,在这里,破坏更容易发生。 + * 当社交网络不那么灵活时,风险下降;人们知道什么需要发生,怎样发生,何时发生(但是考虑到在一个组织中工作的广度,这不见得总是“坏事”;一些工作的职能需要较小的风险,例如:人力资源管理 HR),企业并购和法律工作等。 + * 在网络中的信任是更大的,尤其当受雇者是正式网络的一部分的时候(当某人不是网络的一份子时,被排斥的人可能特别难管理或改正)。 + +### 开放组织中的社交网络 + +尽管开放组织必定会有等级结构,但他们并不根据那个网络运作。他们的职业网络结构更加灵活(或者说是“随时随地”)。 + +在一个开放的组织中,当我描述我做了什么工作时,几乎没人问我“我为谁而干?”一个开放的组织更多的以伙伴为中心,而不是以领导为中心。开放的价值观比如包容和特定的治理系统比如强人治理有助于此;那并不是你了解谁而是你了解什么,你怎样使用(比如:“自底而上的设计”)。在一个开放的组织当中,我并不感觉我在为展示自己的价值而奋斗;我的想法有内在的价值。有时我必须示范说明为何使用我的观点比使用别人的更加有用——但是那意味着我正在同事的社区里面诊疗我自己(包括领导层),而不是单独被自上而下的领导层诊疗。 + +如此说来,开放的组织并不基于网络评估员工,而是基于他们对作为个人的同事的了解。这个人有想法吗?她会努力通过利用开放组织的价值实现那些想法吗(领导它们)(也就是说,在开放组织中分享那些观点并且实践以将他人囊括并透明公开的工作等等)? + +开放组织也会以特定的方式构造社交网络(这种方式同样可能会视个人的目的性和渴望程度而很有益或很有害),这包括: + + * 人们会对他们的网络、声望、技能和事业更加负责。 + * 竞争(为了资源、权力、晋升等)会因这些组织天性更具合作性而变得更少。最好的结果是协商,而不是单赢,并且竞争会磨练创意,而不会在人与人之间筑篱设笆。 + * 权力是更加流动和有活力的,在人与人之间流动(但这同时也意味着可能有对可说明性或者责任的误解,而且活动可能会因为没有明晰的[主人翁意识][2]而不被完成)。 + * 信任是“一次一同事”地被建立起来的而不会借助社交网络,在网络中,人是被定位着的。 + * 网络在多样的运转和事件中会自配置,一有机会便会反应性地自启(这帮助了更新但却会造成混乱,因为谁在决策、谁在“受控”是不那么明确的)。 + * 执行速度在混乱的环境中会下降,因为所做之事、做事方式和处事时间需要在制定目标和涵养好整以暇的员工方面上的领导力。 + * 灵活的社交网络同样会增加变革和风险;创意会流通得更快而且更神奇,并且执行会更加自信。 + * 信任建立在同事合作之上(它本该如此!),而不是在对架构的尊重之上。 + +### 让它有效 + +如果你正在考虑从一种组织架构转变为另一种,当你在构建并维持你的职业社交网络时思考一下如下所述内容。 + +#### 来自传统组织的小建议 + + * 对决策的架构和管控不是坏事;运作中的框架需要明晰透明,而且决策者需要考虑他们的决定。 + * 在执行上突出需要经理提供关注,还需要有在滤出任何让人分心或混乱的事务的同时仍能提供足够的来龙去脉的能力。 + * 已经确立的网络帮助了一大批人同步工作并且能管控风险。 + +#### 来自开放组织的小建议 + + * 能力强的领导人是那些可以根据多样的风格和对同事、团队的不同偏好提供不同层次的透明度和指导,同时又不会构建出不灵活的网络的人。 + * 伟大的想法比已建立的组织会赢得更多。 + * 人们对他们的名声会更加负责任。 + * 创意和信息的流转是变革的关键。松散组织中的关系网络可以使这两种元素生发的频度更高、幅度更广。 + + +-------------------------------------------------------------------------------- + +via: https://opensource.com/open-organization/18/6/building-professional-social-networks-openly + +作者:[Heidi Hess von Ludewig][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[ZenMoore](https://github.com/ZenMoore) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://opensource.com/users/heidi-hess-von-ludewig +[1]:http://www.catb.org/~esr/writings/cathedral-bazaar/cathedral-bazaar/ar01s04.html +[2]:https://opensource.com/open-organization/18/4/rethinking-ownership-across-organization diff --git a/published/201807/20141127 Keeping (financial) score with Ledger .md b/published/201807/20141127 Keeping (financial) score with Ledger .md new file mode 100644 index 0000000000..2bcecd2174 --- /dev/null +++ b/published/201807/20141127 Keeping (financial) score with Ledger .md @@ -0,0 +1,75 @@ +使用 Ledger 记录(财务)情况 +====== + +自 2005 年搬到加拿大以来,我使用 [Ledger CLI][1] 来跟踪我的财务状况。我喜欢纯文本的方式,它支持虚拟信封意味着我可以同时将我的银行帐户余额和我的虚拟分配到不同的目录下。以下是我们如何使用这些虚拟信封分别管理我们的财务状况。 + +每个月,我都有一个条目将我生活开支分配到不同的目录中,包括家庭开支的分配。W- 不要求太多, 所以我要谨慎地处理这两者之间的差别和我自己的生活费用。我们处理它的方式是我支付固定金额,这是贷记我支付的杂货。由于我们的杂货总额通常低于我预算的家庭开支,因此任何差异都会留在标签上。我过去常常给他写支票,但最近我只是支付偶尔额外的大笔费用。 + +这是个示例信封分配: + +``` +2014.10.01 * Budget + [Envelopes:Living] + [Envelopes:Household] $500 + ;; More lines go here +``` + +这是设置的信封规则之一。它鼓励我正确地分类支出。所有支出都从我的 “Play” 信封中取出。 + +``` += /^Expenses/ + (Envelopes:Play) -1.0 +``` + +这个为家庭支出报销 “Play” 信封,将金额从 “Household” 信封转移到 “Play” 信封。 + +``` += /^Expenses:House$/ + (Envelopes:Play) 1.0 + (Envelopes:Household) -1.0 +``` + +我有一套定期的支出来模拟我的预算中的家庭开支。例如,这是 10 月份的。 + +``` +2014.10.1 * House + Expenses:House + Assets:Household $-500 +``` + +这是杂货交易的形式: + +``` +2014.09.28 * No Frills + Assets:Household:Groceries $70.45 + Liabilities:MBNA:September $-70.45 + +``` + +接着 `ledger bal Assets:Household` 就会告诉我是否欠他钱(负余额)。如果我支付大笔费用(例如:机票、通管道),那么正常家庭开支预算会逐渐减少余额。 + +我从 W- 那找到了一个为我的信用卡交易添加一个月标签的技巧,他还使用 Ledger 跟踪他的交易。它允许我再次检查条目的余额,看看前一个条目是否已被正确清除。 + +这个资产分类使用有点奇怪,但它在精神上对我有用。 + +使用 Ledger 以这种方式跟踪它可以让我跟踪我们的杂货费用以及我实际支付费用和我预算费用之间的差额。如果我最终支出超出预期,我可以从更多可自由支配的信封中移动虚拟货币,因此我的预算始终保持平衡。 + +Ledger 是一个强大的工具。相当极客,但也许更多的工作流描述可能会帮助那些正在搞清楚它的人! + +-------------------------------------------------------------------------------- + +via: http://sachachua.com/blog/2014/11/keeping-financial-score-ledger/ + +作者:[Sacha Chua][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[geekpi](https://github.com/geekpi) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:http://sachachua.com +[1]:http://www.ledger-cli.org/ +[2]:http://sachachua.com/blog/category/finance/ +[3]:http://sachachua.com/blog/tag/ledger/ +[4]:http://pages.sachachua.com/sharing/blog.html?url=http://sachachua.com/blog/2014/11/keeping-financial-score-ledger/ +[5]:http://sachachua.com/blog/2014/11/keeping-financial-score-ledger/#comments diff --git a/published/20170309 How To Record Everything You Do In Terminal.md b/published/201807/20170309 How To Record Everything You Do In Terminal.md similarity index 100% rename from published/20170309 How To Record Everything You Do In Terminal.md rename to published/201807/20170309 How To Record Everything You Do In Terminal.md diff --git a/translated/tech/20170404 Kernel Tracing with Ftrace.md b/published/201807/20170404 Kernel Tracing with Ftrace.md similarity index 75% rename from translated/tech/20170404 Kernel Tracing with Ftrace.md rename to published/201807/20170404 Kernel Tracing with Ftrace.md index 6ed3a87bf9..6c209d4e0d 100644 --- a/translated/tech/20170404 Kernel Tracing with Ftrace.md +++ b/published/201807/20170404 Kernel Tracing with Ftrace.md @@ -1,49 +1,45 @@ -使用 Ftrace 跟踪内核 +使用 ftrace 跟踪内核 ============================================================ -标签: [ftrace][8],[kernel][9],[kernel profiling][10],[kernel tracing][11],[linux][12],[tracepoints][13] - ![](https://blog.selectel.com/wp-content/uploads/2017/04/PR-1801-2-2.png) -在内核级别上分析事件有很多的工具:[SystemTap][14],[ktap][15],[Sysdig][16],[LTTNG][17]等等,并且你也可以在网络上找到关于这些工具的大量介绍文章和资料。 +在内核层面上分析事件有很多的工具:[SystemTap][14]、[ktap][15]、[Sysdig][16]、[LTTNG][17] 等等,你也可以在网络上找到关于这些工具的大量介绍文章和资料。 而对于使用 Linux 原生机制去跟踪系统事件以及检索/分析故障信息的方面的资料却很少找的到。这就是 [ftrace][18],它是添加到内核中的第一款跟踪工具,今天我们来看一下它都能做什么,让我们从它的一些重要术语开始吧。 ### 内核跟踪和分析 -内核分析可以发现性能“瓶颈”。分析能够帮我们发现在一个程序中性能损失的准确位置。特定的程序生成一个概述 — 一个事件的总结 — 它能够用于帮我们找出哪个函数占用了大量的运行时间。尽管这些程序并不能识别出为什么会损失性能。 +内核分析Kernel profiling可以发现性能“瓶颈”。分析能够帮我们发现在一个程序中性能损失的准确位置。特定的程序生成一个概述profile — 这是一个事件总结 — 它能够用于帮我们找出哪个函数占用了大量的运行时间。尽管这些程序并不能识别出为什么会损失性能。 -瓶颈经常发生在无法通过分析来识别的情况下。去推断出为什么会发生事件,去保存发生事件时的相关上下文,这就需要去跟踪。 +瓶颈经常发生在无法通过分析来识别的情况下。要推断出为什么会发生事件,就必须保存发生事件时的相关上下文,这就需要去跟踪tracing。 -跟踪可以理解为在一个正常工作的系统上活动的信息收集进程。它使用特定的工具来完成这项工作,就像录音机来记录声音一样,用它来记录各种注册的系统事件。 +跟踪可以理解为在一个正常工作的系统上活动的信息收集过程。它使用特定的工具来完成这项工作,就像录音机来记录声音一样,用它来记录各种系统事件。 跟踪程序能够同时跟踪应用级和操作系统级的事件。它们收集的信息能够用于诊断多种系统问题。 有时候会将跟踪与日志比较。它们两者确时很相似,但是也有不同的地方。 -对于跟踪,记录的信息都是些低级别事件。它们的数量是成百上千的,甚至是成千上万的。对于日志,记录的信息都是些高级别事件,数量上通常少多了。这些包含用户登陆系统、应用程序错误、数据库事务等等。 +对于跟踪,记录的信息都是些低级别事件。它们的数量是成百上千的,甚至是成千上万的。对于日志,记录的信息都是些高级别事件,数量上通常少多了。这些包含用户登录系统、应用程序错误、数据库事务等等。 就像日志一样,跟踪数据可以被原样读取,但是用特定的应用程序提取的信息更有用。所有的跟踪程序都能这样做。 在内核跟踪和分析方面,Linux 内核有三个主要的机制: -* 跟踪点 —— 一种基于静态测试代码的工作机制 - -* 探针 —— 一种动态跟踪机制,用于在任意时刻中断内核代码的运行,调用它自己的处理程序,在完成需要的操作之后再返回。 - -* perf_events —— 一个访问 PMU(性能监视单元)的接口 +* 跟踪点tracepoint:一种基于静态测试代码的工作机制 +* 探针kprobe:一种动态跟踪机制,用于在任意时刻中断内核代码的运行,调用它自己的处理程序,在完成需要的操作之后再返回 +* perf_events —— 一个访问 PMU(性能监视单元Performance Monitoring Unit)的接口 我并不想在这里写关于这些机制方面的内容,任何对它们感兴趣的人可以去访问 [Brendan Gregg 的博客][19]。 使用 ftrace,我们可以与这些机制进行交互,并可以从用户空间直接得到调试信息。下面我们将讨论这方面的详细内容。示例中的所有命令行都是在内核版本为 3.13.0-24 的 Ubuntu 14.04 中运行的。 -### Ftrace:常用信息 +### ftrace:常用信息 -Ftrace 是函数 Trace 的简写,但它能做的远不止这些:它可以跟踪上下文切换、测量进程阻塞时间、计算高优先级任务的活动时间等等。 +ftrace 是 Function Trace 的简写,但它能做的远不止这些:它可以跟踪上下文切换、测量进程阻塞时间、计算高优先级任务的活动时间等等。 -Ftrace 是由 Steven Rostedt 开发的,从 2008 年发布的内核 2.6.27 中开始就内置了。这是为记录数据提供的一个调试 `Ring` 缓冲区的框架。这些数据由集成到内核中的跟踪程序来采集。 +ftrace 是由 Steven Rostedt 开发的,从 2008 年发布的内核 2.6.27 中开始就内置了。这是为记录数据提供的一个调试 Ring 缓冲区的框架。这些数据由集成到内核中的跟踪程序来采集。 -Ftrace 工作在 debugfs 文件系统上,这是在大多数现代 Linux 分发版中默认挂载的文件系统。为开始使用 ftrace,你将进入到 `sys/kernel/debug/tracing` 目录(仅对 root 用户可用): +ftrace 工作在 debugfs 文件系统上,在大多数现代 Linux 发行版中都默认挂载了。要开始使用 ftrace,你将进入到 `sys/kernel/debug/tracing` 目录(仅对 root 用户可用): ``` # cd /sys/kernel/debug/tracing @@ -70,16 +66,13 @@ kprobe_profile stack_max_size uprobe_profile 我不想去描述这些文件和子目录;它们的描述在 [官方文档][20] 中已经写的很详细了。我只想去详细介绍与我们这篇文章相关的这几个文件: * available_tracers —— 可用的跟踪程序 - * current_tracer —— 正在运行的跟踪程序 - -* tracing_on —— 负责启用或禁用数据写入到 `Ring` 缓冲区的系统文件(如果启用它,在文件中添加数字 1,禁用它,添加数字 0) - +* tracing_on —— 负责启用或禁用数据写入到 Ring 缓冲区的系统文件(如果启用它,数字 1 被添加到文件中,禁用它,数字 0 被添加) * trace —— 以人类友好格式保存跟踪数据的文件 ### 可用的跟踪程序 -我们可以使用如下的命令去查看可用的跟踪程序的一个列表 +我们可以使用如下的命令去查看可用的跟踪程序的一个列表: ``` root@andrei:/sys/kernel/debug/tracing#: cat available_tracers @@ -89,18 +82,14 @@ blk mmiotrace function_graph wakeup_rt wakeup function nop 我们来快速浏览一下每个跟踪程序的特性: * function —— 一个无需参数的函数调用跟踪程序 - * function_graph —— 一个使用子调用的函数调用跟踪程序 - -* blk —— 一个与块 I/O 跟踪相关的调用和事件跟踪程序(它是 blktrace 的用途) - +* blk —— 一个与块 I/O 跟踪相关的调用和事件跟踪程序(它是 blktrace 使用的) * mmiotrace —— 一个内存映射 I/O 操作跟踪程序 - -* nop —— 简化的跟踪程序,就像它的名字所暗示的那样,它不做任何事情(尽管在某些情况下可能会派上用场,我们将在后文中详细解释) +* nop —— 最简单的跟踪程序,就像它的名字所暗示的那样,它不做任何事情(尽管在某些情况下可能会派上用场,我们将在后文中详细解释) ### 函数跟踪程序 -在开始介绍函数跟踪程序 ftrace 之前,我们先看一下测试脚本: +在开始介绍函数跟踪程序 ftrace 之前,我们先看一个测试脚本: ``` #!/bin/sh @@ -117,7 +106,7 @@ less ${dir}/trace 这个脚本是非常简单的,但是还有几个需要注意的地方。命令 `sysctl ftrace.enabled=1` 启用了函数跟踪程序。然后我们通过写它的名字到 `current_tracer` 文件来启用 `current tracer`。 -接下来,我们写入一个 `1` 到 `tracing_on`,它启用了 `Ring` 缓冲区。这些语法都要求在 `1` 和 `>` 符号前后有一个空格;写成像 `echo1> tracing_on` 这样将不能工作。一行之后我们禁用它(如果 `0` 写入到 `tracing_on`, 缓冲区不会被清除并且 ftrace 并不会被禁用)。 +接下来,我们写入一个 `1` 到 `tracing_on`,它启用了 Ring 缓冲区。这些语法都要求在 `1` 和 `>` 符号前后有一个空格;写成像 `echo 1> tracing_on` 这样将不能工作。一行之后我们禁用它(如果 `0` 写入到 `tracing_on`, 缓冲区不会被清除并且 ftrace 并不会被禁用)。 我们为什么这样做呢?在两个 `echo` 命令之间,我们看到了命令 `sleep 1`。我们启用了缓冲区,运行了这个命令,然后禁用它。这将使跟踪程序采集了这个命令运行期间发生的所有系统调用的信息。 @@ -156,21 +145,18 @@ less ${dir}/trace trace.sh-1295 [000] d... 90.502879: __acct_update_integrals <-acct_account_cputime ``` -这个输出以缓冲区中的信息条目数量和写入的条目数量开始。这两者的数据差异是缓冲区中事件的丢失数量(在我们的示例中没有发生丢失)。 +这个输出以“缓冲区中的信息条目数量”和“写入的全部条目数量”开始。这两者的数据差异是缓冲区中事件的丢失数量(在我们的示例中没有发生丢失)。 在这里有一个包含下列信息的函数列表: * 进程标识符(PID) - * 运行这个进程的 CPU(CPU#) - * 进程开始时间(TIMESTAMP) - * 被跟踪函数的名字以及调用它的父级函数;例如,在我们输出的第一行,`rb_simple_write` 调用了 `mutex-unlock` 函数。 -### Function_graph 跟踪程序 +### function_graph 跟踪程序 -`function_graph` 跟踪程序的工作和函数一样,但是它更详细:它显示了每个函数的进入和退出点。使用这个跟踪程序,我们可以跟踪函数的子调用并且测量每个函数的运行时间。 +function_graph 跟踪程序的工作和函数跟踪程序一样,但是它更详细:它显示了每个函数的进入和退出点。使用这个跟踪程序,我们可以跟踪函数的子调用并且测量每个函数的运行时间。 我们来编辑一下最后一个示例的脚本: @@ -215,11 +201,11 @@ less ${dir}/trace 0) ! 208.154 us | } /* ip_local_deliver_finish */ ``` -在这个图中,`DURATION` 展示了花费在每个运行的函数上的时间。注意使用 `+` 和 `!` 符号标记的地方。加号(+)意思是这个函数花费的时间超过 10 毫秒;而感叹号(!)意思是这个函数花费的时间超过了 100 毫秒。 +在这个图中,`DURATION` 展示了花费在每个运行的函数上的时间。注意使用 `+` 和 `!` 符号标记的地方。加号(`+`)意思是这个函数花费的时间超过 10 毫秒;而感叹号(`!`)意思是这个函数花费的时间超过了 100 毫秒。 在 `FUNCTION_CALLS` 下面,我们可以看到每个函数调用的信息。 -和 C 语言一样使用了花括号({)标记每个函数的边界,它展示了每个函数的开始和结束,一个用于开始,一个用于结束;不能调用其它任何函数的叶子函数用一个分号(;)标记。 +和 C 语言一样使用了花括号(`{`)标记每个函数的边界,它展示了每个函数的开始和结束,一个用于开始,一个用于结束;不能调用其它任何函数的叶子函数用一个分号(`;`)标记。 ### 函数过滤器 @@ -249,13 +235,13 @@ ftrace 还有很多过滤选项。对于它们更详细的介绍,你可以去 ### 跟踪事件 -我们在上面提到到跟踪点机制。跟踪点是插入的由系统事件触发的特定代码。跟踪点可以是动态的(意味着可能会在它们上面附加几个检查),也可以是静态的(意味着不会附加任何检查)。 +我们在上面提到到跟踪点机制。跟踪点是插入的触发系统事件的特定代码。跟踪点可以是动态的(意味着可能会在它们上面附加几个检查),也可以是静态的(意味着不会附加任何检查)。 -静态跟踪点不会对系统有任何影响;它们只是增加几个字节用于调用测试函数以及在一个独立的节上增加一个数据结构。 +静态跟踪点不会对系统有任何影响;它们只是在测试的函数末尾增加几个字节的函数调用以及在一个独立的节上增加一个数据结构。 -当相关代码片断运行时,动态跟踪点调用一个跟踪函数。跟踪数据是写入到 `Ring` 缓冲区。 +当相关代码片断运行时,动态跟踪点调用一个跟踪函数。跟踪数据是写入到 Ring 缓冲区。 -跟踪点可以设置在代码的任何位置;事实上,它们确实可以在许多的内核函数中找到。我们来看一下 `kmem_cache_alloc` 函数(它在 [这里][22]): +跟踪点可以设置在代码的任何位置;事实上,它们确实可以在许多的内核函数中找到。我们来看一下 `kmem_cache_alloc` 函数(取自 [这里][22]): ``` { @@ -294,7 +280,7 @@ fs kvm power scsi vfs ftrace kvmmmu printk signal vmscan ``` -所有可能的事件都按子系统分组到子目录中。在我们开始跟踪事件之前,我们要先确保启用了 `Ring` 缓冲区写入: +所有可能的事件都按子系统分组到子目录中。在我们开始跟踪事件之前,我们要先确保启用了 Ring 缓冲区写入: ``` root@andrei:/sys/kernel/debug/tracing# cat tracing_on @@ -306,25 +292,25 @@ root@andrei:/sys/kernel/debug/tracing# cat tracing_on root@andrei:/sys/kernel/debug/tracing# echo 1 > tracing_on ``` -在我们上一篇的文章中,我们写了关于 `chroot()` 系统调用的内容;我们来跟踪访问一下这个系统调用。为了跟踪,我们使用 `nop` 因为函数跟踪程序和 `function_graph` 跟踪程序记录的信息太多,它包含了我们不感兴趣的事件信息。 +在我们上一篇的文章中,我们写了关于 `chroot()` 系统调用的内容;我们来跟踪访问一下这个系统调用。对于我们的跟踪程序,我们使用 `nop` 因为函数跟踪程序和 `function_graph` 跟踪程序记录的信息太多,它包含了我们不感兴趣的事件信息。 ``` root@andrei:/sys/kernel/debug/tracing# echo nop > current_tracer ``` -所有事件相关的系统调用都保存在系统调用目录下。在这里我们将找到一个进入和退出多个系统调用的目录。我们需要在相关的文件中通过写入数字 `1` 来激活跟踪点: +所有事件相关的系统调用都保存在系统调用目录下。在这里我们将找到一个进入和退出各种系统调用的目录。我们需要在相关的文件中通过写入数字 `1` 来激活跟踪点: ``` root@andrei:/sys/kernel/debug/tracing# echo 1 > events/syscalls/sys_enter_chroot/enable ``` -然后我们使用 `chroot` 来创建一个独立的文件系统(更多内容,请查看 [这篇文章][23])。在我们执行完我们需要的命令之后,我们将禁用跟踪程序,以便于不需要的信息或者过量信息出现在输出中: +然后我们使用 `chroot` 来创建一个独立的文件系统(更多内容,请查看 [之前这篇文章][23])。在我们执行完我们需要的命令之后,我们将禁用跟踪程序,以便于不需要的信息或者过量信息不会出现在输出中: ``` root@andrei:/sys/kernel/debug/tracing# echo 0 > tracing_on ``` -然后,我们去查看 `Ring` 缓冲区的内容。在输出的结束部分,我们找到了有关的系统调用信息(这里只是一个节选)。 +然后,我们去查看 Ring 缓冲区的内容。在输出的结束部分,我们找到了有关的系统调用信息(这里只是一个节选)。 ``` root@andrei:/sys/kernel/debug/tracing# сat trace @@ -343,15 +329,10 @@ root@andrei:/sys/kernel/debug/tracing# сat trace 在这篇文篇中,我们做了一个 ftrace 的功能概述。我们非常感谢你的任何意见或者补充。如果你想深入研究这个主题,我们为你推荐下列的资源: * [https://www.kernel.org/doc/Documentation/trace/tracepoints.txt][1] — 一个跟踪点机制的详细描述 - * [https://www.kernel.org/doc/Documentation/trace/events.txt][2] — 在 Linux 中跟踪系统事件的指南 - * [https://www.kernel.org/doc/Documentation/trace/ftrace.txt][3] — ftrace 的官方文档 - * [https://lttng.org/files/thesis/desnoyers-dissertation-2009-12-v27.pdf][4] — Mathieu Desnoyers(作者是跟踪点和 LTTNG 的创建者)的关于内核跟踪和分析的学术论文。 - * [https://lwn.net/Articles/370423/][5] — Steven Rostedt 的关于 ftrace 功能的文章 - * [http://alex.dzyoba.com/linux/profiling-ftrace.html][6] — 用 ftrace 分析实际案例的一个概述 -------------------------------------------------------------------------------- @@ -360,7 +341,7 @@ via:https://blog.selectel.com/kernel-tracing-ftrace/ 作者:[Andrej Yemelianov][a] 译者:[qhwdw](https://github.com/qhwdw) -校对:[校对者ID](https://github.com/校对者ID) +校对:[wxy](https://github.com/wxy) 本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 diff --git a/published/201807/20170829 An Advanced System Configuration Utility For Ubuntu Power Users.md b/published/201807/20170829 An Advanced System Configuration Utility For Ubuntu Power Users.md new file mode 100644 index 0000000000..07b851caf2 --- /dev/null +++ b/published/201807/20170829 An Advanced System Configuration Utility For Ubuntu Power Users.md @@ -0,0 +1,129 @@ +Ubunsys:面向 Ubuntu 资深用户的一个高级系统配置工具 +====== + +![](https://www.ostechnix.com/wp-content/uploads/2017/08/Ubunsys-4-1-720x340.png) + + +**Ubunsys** 是一个面向 Ubuntu 及其衍生版的基于 Qt 的高级系统工具。高级用户可以使用命令行轻松完成大多数配置。不过为了以防万一某天,你突然不想用命令行了,就可以用 Ubnusys 这个程序来配置你的系统或其衍生系统,如 Linux Mint、Elementary OS 等。Ubunsys 可用来修改系统配置,安装、删除、更新包和旧内核,启用或禁用 `sudo` 权限,安装主线内核,更新软件安装源,清理垃圾文件,将你的 Ubuntu 系统升级到最新版本等等。以上提到的所有功能都可以通过鼠标点击完成。你不需要再依赖于命令行模式,下面是你能用 Ubunsys 做到的事: + + * 安装、删除、更新包 + * 更新和升级软件源 + * 安装主线内核 + * 删除旧的和不再使用的内核 + * 系统整体更新 + * 将系统升级到下一个可用的版本 + * 将系统升级到最新的开发版本 + * 清理系统垃圾文件 + * 在不输入密码的情况下启用或者禁用 `sudo` 权限 + * 当你在终端输入密码时使 `sudo` 密码可见 + * 启用或禁用系统休眠 + * 启用或禁用防火墙 + * 打开、备份和导入 `sources.list.d` 和 `sudoers` 文件 + * 显示或者隐藏启动项 + * 启用或禁用登录音效 + * 配置双启动 + * 启用或禁用锁屏 + * 智能系统更新 + * 使用脚本管理器更新/一次性执行脚本 + * 从 `git` 执行常规用户安装脚本 + * 检查系统完整性和缺失的 GPG 密钥 + * 修复网络 + * 修复已破损的包 + * 还有更多功能在开发中 + +**重要提示:** Ubunsys 不适用于 Ubuntu 新手。它很危险并且仍然不是稳定版。它可能会使你的系统崩溃。如果你刚接触 Ubuntu 不久,不要使用。但如果你真的很好奇这个应用能做什么,仔细浏览每一个选项,并确定自己能承担风险。在使用这一应用之前记着备份你自己的重要数据。 + +### 安装 Ubunsys + +Ubunsys 开发者制作了一个 PPA 来简化安装过程,Ubunsys 现在可以在 Ubuntu 16.04 LTS、 Ubuntu 17.04 64 位版本上使用。 + +逐条执行下面的命令,将 Ubunsys 的 PPA 添加进去,并安装它。 + +``` +sudo add-apt-repository ppa:adgellida/ubunsys +sudo apt-get update +sudo apt-get install ubunsys +``` + +如果 PPA 无法使用,你可以在[发布页面][1]根据你自己当前系统,选择正确的安装包,直接下载并安装 Ubunsys。 + +### 用途 + +一旦安装完成,从菜单栏启动 Ubunsys。下图是 Ubunsys 主界面。 + +![][3] + +你可以看到,Ubunsys 有四个主要部分,分别是 Packages、Tweaks、System 和 Repair。在每一个标签项下面都有一个或多个子标签项以对应不同的操作。 + +**Packages** + +这一部分允许你安装、删除和更新包。 + +![][4] + +**Tweaks** + +在这一部分,我们可以对系统进行多种调整,例如: + + * 打开、备份和导入 `sources.list.d` 和 `sudoers` 文件; + * 配置双启动; + * 启用或禁用登录音效、防火墙、锁屏、系统休眠、`sudo` 权限(在不需要密码的情况下)同时你还可以针对某一用户启用或禁用 `sudo` 权限(在不需要密码的情况下); + * 在终端中输入密码时可见(禁用星号)。 + +![][5] + +**System** + +这一部分被进一步分成 3 个部分,每个都是针对某一特定用户类型。 + +**Normal user** 这一标签下的选项可以: + + * 更新、升级包和软件源 + * 清理系统 + * 执行常规用户安装脚本 + +**Advanced user** 这一标签下的选项可以: + +* 清理旧的/无用的内核 +* 安装主线内核 +* 智能包更新 +* 升级系统 + +**Developer** 这一部分可以将系统升级到最新的开发版本。 + +![][6] + +**Repair** + +这是 Ubunsys 的第四个也是最后一个部分。正如名字所示,这一部分能让我们修复我们的系统、网络、缺失的 GPG 密钥,和已经缺失的包。 + +![][7] + +正如你所见,Ubunsys 可以在几次点击下就能完成诸如系统配置、系统维护和软件维护之类的任务。你不需要一直依赖于终端。Ubunsys 能帮你完成任何高级任务。再次声明,我警告你,这个应用不适合新手,而且它并不稳定。所以当你使用的时候,能会出现 bug 或者系统崩溃。在仔细研究过每一个选项的影响之后再使用它。 + +谢谢阅读! + +### 参考资源 + +- [Ubunsys GitHub Repository][8] + +-------------------------------------------------------------------------------- + +via: https://www.ostechnix.com/ubunsys-advanced-system-configuration-utility-ubuntu-power-users/ + +作者:[SK][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[wenwensnow](https://github.com/wenwensnow) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.ostechnix.com/author/sk/ +[1]:https://github.com/adgellida/ubunsys/releases +[2]:data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7 +[3]:http://www.ostechnix.com/wp-content/uploads/2017/08/Ubunsys-1.png +[4]:http://www.ostechnix.com/wp-content/uploads/2017/08/Ubunsys-2.png +[5]:http://www.ostechnix.com/wp-content/uploads/2017/08/Ubunsys-5.png +[6]:http://www.ostechnix.com/wp-content/uploads/2017/08/Ubunsys-9.png +[7]:http://www.ostechnix.com/wp-content/uploads/2017/08/Ubunsys-11.png +[8]:https://github.com/adgellida/ubunsys \ No newline at end of file diff --git a/published/201807/20171003 Streams a new general purpose data structure in Redis.md b/published/201807/20171003 Streams a new general purpose data structure in Redis.md new file mode 100644 index 0000000000..92933058bb --- /dev/null +++ b/published/201807/20171003 Streams a new general purpose data structure in Redis.md @@ -0,0 +1,183 @@ +Streams:一个新的 Redis 通用数据结构 +====== + +直到几个月以前,对于我来说,在消息传递的环境中,streams只是一个有趣且相对简单的概念。这个概念在 Kafka 流行之后,我主要研究它们在 Disque 案例中的应用,Disque 是一个消息队列,它将在 Redis 4.2 中被转换为 Redis 的一个模块。后来我决定让 Disque 都用 AP 消息(LCTT 译注:参见 [CAP 定理][1]) ,也就是说,它将在不需要客户端过多参与的情况下实现容错和可用性,这样一来,我更加确定地认为流的概念在那种情况下并不适用。 + +然而在那时 Redis 有个问题,那就是缺省情况下导出数据结构并不轻松。它在 Redis 列表list有序集sorted list发布/订阅Pub/Sub功能之间有某些缺陷。你可以权衡使用这些工具对一系列消息或事件建模。 + +有序集是内存消耗大户,那自然就不能对投递的相同消息进行一次又一次的建模,客户端不能阻塞新消息。因为有序集并不是一个序列化的数据结构,它是一个元素可以根据它们量的变化而移动的集合:所以它不像时序性的数据那样。 + +列表有另外的问题,它在某些特定的用例中会产生类似的适用性问题:你无法浏览列表中间的内容,因为在那种情况下,访问时间是线性的。此外,没有任何指定输出的功能,列表上的阻塞操作仅为单个客户端提供单个元素。列表中没有固定的元素标识,也就是说,不能指定从哪个元素开始给我提供内容。 + +对于一对多的工作任务,有发布/订阅机制,它在大多数情况下是非常好的,但是,对于某些不想“即发即弃”fire-and-forget的东西:保留一个历史是很重要的,不只是因为是断开之后会重新获得消息,也因为某些如时序性的消息列表,用范围查询浏览是非常重要的:比如在这 10 秒范围内温度读数是多少? + +我试图解决上述问题,我想规划一个通用的有序集合,并列入一个独特的、更灵活的数据结构,然而,我的设计尝试最终以生成一个比当前的数据结构更加矫揉造作的结果而告终。Redis 有个好处,它的数据结构导出更像自然的计算机科学的数据结构,而不是 “Salvatore 发明的 API”。因此,我最终停止了我的尝试,并且说,“ok,这是我们目前能提供的”,或许我会为发布/订阅增加一些历史信息,或者为列表访问增加一些更灵活的方式。然而,每次在会议上有用户对我说 “你如何在 Redis 中模拟时间系列” 或者类似的问题时,我的脸就绿了。 + +### 起源 + +在 Redis 4.0 中引入模块之后,用户开始考虑他们自己怎么去修复这些问题。其中一个用户 Timothy Downs 通过 IRC 和我说道: + + \ 我计划给这个模块增加一个事务日志式的数据类型 —— 这意味着大量的订阅者可以在不导致 redis 内存激增的情况下做一些像发布/订阅那样的事情 + \ 订阅者持有他们在消息队列中的位置,而不是让 Redis 必须维护每个消费者的位置和为每个订阅者复制消息 + +他的思路启发了我。我想了几天,并且意识到这可能是我们马上同时解决上面所有问题的契机。我需要去重新构思 “日志” 的概念是什么。日志是个基本的编程元素,每个人都使用过它,因为它只是简单地以追加模式打开一个文件,并以一定的格式写入数据。然而 Redis 数据结构必须是抽象的。它们在内存中,并且我们使用内存并不是因为我们懒,而是因为使用一些指针,我们可以概念化数据结构并把它们抽象,以使它们摆脱明确的限制。例如,一般来说日志有几个问题:偏移不是逻辑化的,而是真实的字节偏移,如果你想要与条目插入的时间相关的逻辑偏移应该怎么办?我们有范围查询可用。同样,日志通常很难进行垃圾回收:在一个只能进行追加操作的数据结构中怎么去删除旧的元素?好吧,在我们理想的日志中,我们只需要说,我想要数字最大的那个条目,而旧的元素一个也不要,等等。 + +当我从 Timothy 的想法中受到启发,去尝试着写一个规范的时候,我使用了 Redis 集群中的 radix 树去实现,优化了它内部的某些部分。这为实现一个有效利用空间的日志提供了基础,而且仍然有可能在对数时间logarithmic time内访问范围。同时,我开始去读关于 Kafka 的流相关的内容以获得另外的灵感,它也非常适合我的设计,最后借鉴了 Kafka 消费组consumer groups的概念,并且再次针对 Redis 进行优化,以适用于 Redis 在内存中使用的情况。然而,该规范仅停留在纸面上,在一段时间后我几乎把它从头到尾重写了一遍,以便将我与别人讨论的所得到的许多建议一起增加到 Redis 升级中。我希望 Redis 流能成为对于时间序列有用的特性,而不仅是一个常见的事件和消息类的应用程序。 + +### 让我们写一些代码吧 + +从 Redis 大会回来后,整个夏天我都在实现一个叫 listpack 的库。这个库是 `ziplist.c` 的继任者,那是一个表示在单个分配中的字符串元素列表的数据结构。它是一个非常特殊的序列化格式,其特点在于也能够以逆序(从右到左)解析:以便在各种用例中替代 ziplists。 + +结合 radix 树和 listpacks 的特性,它可以很容易地去构建一个空间高效的日志,并且还是可索引的,这意味着允许通过 ID 和时间进行随机访问。自从这些就绪后,我开始去写一些代码以实现流数据结构。我还在完成这个实现,不管怎样,现在在 Github 上的 Redis 的 streams 分支里它已经可以跑起来了。我并没有声称那个 API 是 100% 的最终版本,但是,这有两个有意思的事实:一,在那时只有消费群组是缺失的,加上一些不太重要的操作流的命令,但是,所有的大的方面都已经实现了。二,一旦各个方面比较稳定了之后,我决定大概用两个月的时间将所有的流的特性向后移植backport到 4.0 分支。这意味着 Redis 用户想要使用流,不用等待 Redis 4.2 发布,它们在生产环境马上就可用了。这是可能的,因为作为一个新的数据结构,几乎所有的代码改变都出现在新的代码里面。除了阻塞列表操作之外:该代码被重构了,我们对于流和列表阻塞操作共享了相同的代码,而极大地简化了 Redis 内部实现。 + +### 教程:欢迎使用 Redis 的 streams + +在某些方面,你可以认为流是 Redis 列表的一个增强版本。流元素不再是一个单一的字符串,而是一个字段fieldvalue组成的对象。范围查询更适用而且更快。在流中,每个条目都有一个 ID,它是一个逻辑偏移量。不同的客户端可以阻塞等待blocking-wait比指定的 ID 更大的元素。Redis 流的一个基本的命令是 `XADD`。是的,所有的 Redis 流命令都是以一个 `X` 为前缀的。 + +``` +> XADD mystream * sensor-id 1234 temperature 10.5 +1506871964177.0 +``` + +这个 `XADD` 命令将追加指定的条目作为一个指定的流 —— “mystream” 的新元素。上面示例中的这个条目有两个字段:`sensor-id` 和 `temperature`,每个条目在同一个流中可以有不同的字段。使用相同的字段名可以更好地利用内存。有意思的是,字段的排序是可以保证顺序的。`XADD` 仅返回插入的条目的 ID,因为在第三个参数中是星号(`*`),表示由命令自动生成 ID。通常这样做就够了,但是也可以去强制指定一个 ID,这种情况用于复制这个命令到从服务器slave serverAOFappend-only file 文件。 + +这个 ID 是由两部分组成的:一个毫秒时间和一个序列号。`1506871964177` 是毫秒时间,它只是一个毫秒级的 UNIX 时间戳。圆点(`.`)后面的数字 `0` 是一个序号,它是为了区分相同毫秒数的条目增加上去的。这两个数字都是 64 位的无符号整数。这意味着,我们可以在流中增加所有想要的条目,即使是在同一毫秒中。ID 的毫秒部分使用 Redis 服务器的当前本地时间生成的 ID 和流中的最后一个条目 ID 两者间的最大的一个。因此,举例来说,即使是计算机时间回跳,这个 ID 仍然是增加的。在某些情况下,你可以认为流条目的 ID 是完整的 128 位数字。然而,事实上它们与被添加到的实例的本地时间有关,这意味着我们可以在毫秒级的精度的范围随意查询。 + +正如你想的那样,快速添加两个条目后,结果是仅一个序号递增了。我们可以用一个 `MULTI`/`EXEC` 块来简单模拟“快速插入”: + +``` +> MULTI +OK +> XADD mystream * foo 10 +QUEUED +> XADD mystream * bar 20 +QUEUED +> EXEC +1) 1506872463535.0 +2) 1506872463535.1 +``` + +在上面的示例中,也展示了无需指定任何初始模式schema的情况下,对不同的条目使用不同的字段。会发生什么呢?就像前面提到的一样,只有每个块(它通常包含 50-150 个消息内容)的第一个消息被使用。并且,相同字段的连续条目都使用了一个标志进行了压缩,这个标志表示与“它们与这个块中的第一个条目的字段相同”。因此,使用相同字段的连续消息可以节省许多内存,即使是字段集随着时间发生缓慢变化的情况下也很节省内存。 + +为了从流中检索数据,这里有两种方法:范围查询,它是通过 `XRANGE` 命令实现的;流播streaming,它是通过 `XREAD` 命令实现的。`XRANGE` 命令仅取得包括从开始到停止范围内的全部条目。因此,举例来说,如果我知道它的 ID,我可以使用如下的命名取得单个条目: + +``` +> XRANGE mystream 1506871964177.0 1506871964177.0 +1) 1) 1506871964177.0 + 2) 1) "sensor-id" + 2) "1234" + 3) "temperature" + 4) "10.5" +``` + +不管怎样,你都可以使用指定的开始符号 `-` 和停止符号 `+` 表示最小和最大的 ID。为了限制返回条目的数量,也可以使用 `COUNT` 选项。下面是一个更复杂的 `XRANGE` 示例: + +``` +> XRANGE mystream - + COUNT 2 +1) 1) 1506871964177.0 + 2) 1) "sensor-id" + 2) "1234" + 3) "temperature" + 4) "10.5" +2) 1) 1506872463535.0 + 2) 1) "foo" + 2) "10" +``` + +这里我们讲的是 ID 的范围,然后,为了取得在一个给定时间范围内的特定范围的元素,你可以使用 `XRANGE`,因为 ID 的“序号” 部分可以省略。因此,你可以只指定“毫秒”时间即可,下面的命令的意思是:“从 UNIX 时间 1506872463 开始给我 10 个条目”: + +``` +127.0.0.1:6379> XRANGE mystream 1506872463000 + COUNT 10 +1) 1) 1506872463535.0 + 2) 1) "foo" + 2) "10" +2) 1) 1506872463535.1 + 2) 1) "bar" + 2) "20" +``` + +关于 `XRANGE` 需要注意的最重要的事情是,假设我们在回复中收到 ID,随后连续的 ID 只是增加了序号部分,所以可以使用 `XRANGE` 遍历整个流,接收每个调用的指定个数的元素。Redis 中的`*SCAN` 系列命令允许迭代 Redis 数据结构,尽管事实上它们不是为迭代设计的,但这样可以避免再犯相同的错误。 + +### 使用 XREAD 处理流播:阻塞新的数据 + +当我们想通过 ID 或时间去访问流中的一个范围或者是通过 ID 去获取单个元素时,使用 `XRANGE` 是非常完美的。然而,在使用流的案例中,当数据到达时,它必须由不同的客户端来消费时,这就不是一个很好的解决方案,这需要某种形式的汇聚池pooling。(对于 *某些* 应用程序来说,这可能是个好主意,因为它们仅是偶尔连接查询的) + +`XREAD` 命令是为读取设计的,在同一个时间,从多个流中仅指定我们从该流中得到的最后条目的 ID。此外,如果没有数据可用,我们可以要求阻塞,当数据到达时,就解除阻塞。类似于阻塞列表操作产生的效果,但是这里并没有消费从流中得到的数据,并且多个客户端可以同时访问同一份数据。 + +这里有一个典型的 `XREAD` 调用示例: + +``` +> XREAD BLOCK 5000 STREAMS mystream otherstream $ $ +``` + +它的意思是:从 `mystream` 和 `otherstream` 取得数据。如果没有数据可用,阻塞客户端 5000 毫秒。在 `STREAMS` 选项之后指定我们想要监听的关键字,最后的是指定想要监听的 ID,指定的 ID 为 `$` 的意思是:假设我现在需要流中的所有元素,因此,只需要从下一个到达的元素开始给我。 + +如果我从另一个客户端发送这样的命令: + +``` +> XADD otherstream * message “Hi There” +``` + +在 `XREAD` 侧会出现什么情况呢? + +``` +1) 1) "otherstream" + 2) 1) 1) 1506935385635.0 + 2) 1) "message" + 2) "Hi There" +``` + +与收到的数据一起,我们也得到了数据的关键字。在下次调用中,我们将使用接收到的最新消息的 ID: + +``` +> XREAD BLOCK 5000 STREAMS mystream otherstream $ 1506935385635.0 +``` + +依次类推。然而需要注意的是使用方式,客户端有可能在一个非常大的延迟之后再次连接(因为它处理消息需要时间,或者其它什么原因)。在这种情况下,期间会有很多消息堆积,为了确保客户端不被消息淹没,以及服务器不会因为给单个客户端提供大量消息而浪费太多的时间,使用 `XREAD` 的 `COUNT` 选项是非常明智的。 + +### 流封顶 + +目前看起来还不错……然而,有些时候,流需要删除一些旧的消息。幸运的是,这可以使用 `XADD` 命令的 `MAXLEN` 选项去做: + +``` +> XADD mystream MAXLEN 1000000 * field1 value1 field2 value2 +``` + +它是基本意思是,如果在流中添加新元素后发现消息数量超过了 `1000000` 个,那么就删除旧的消息,以便于元素总量重新回到 `1000000` 以内。它很像是在列表中使用的 `RPUSH` + `LTRIM`,但是,这次我们是使用了一个内置机制去完成的。然而,需要注意的是,上面的意思是每次我们增加一个新的消息时,我们还需要另外的工作去从流中删除旧的消息。这将消耗一些 CPU 资源,所以在计算 `MAXLEN` 之前,尽可能使用 `~` 符号,以表明我们不要求非常 *精确* 的 1000000 个消息,就是稍微多一些也不是大问题: + +``` +> XADD mystream MAXLEN ~ 1000000 * foo bar +``` + +这种方式的 XADD 仅当它可以删除整个节点的时候才会删除消息。相比普通的 `XADD`,这种方式几乎可以自由地对流进行封顶。 + +### 消费组(开发中) + +这是第一个 Redis 中尚未实现而在开发中的特性。灵感也是来自 Kafka,尽管在这里是以不同的方式实现的。重点是使用了 `XREAD`,客户端也可以增加一个 `GROUP ` 选项。相同组的所有客户端将自动得到 *不同的* 消息。当然,同一个流可以被多个组读取。在这种情况下,所有的组将收到流中到达的消息的相同副本。但是,在每个组内,消息是不会重复的。 + +当指定组时,能够指定一个 `RETRY ` 选项去扩展组:在这种情况下,如果消息没有通过 `XACK` 进行确认,它将在指定的毫秒数后进行再次投递。这将为消息投递提供更佳的可靠性,这种情况下,客户端没有私有的方法将消息标记为已处理。这一部分也正在开发中。 + +### 内存使用和节省加载时间 + +因为用来建模 Redis 流的设计,内存使用率是非常低的。这取决于它们的字段、值的数量和长度,对于简单的消息,每使用 100MB 内存可以有几百万条消息。此外,该格式设想为需要极少的序列化:listpack 块以 radix 树节点方式存储,在磁盘上和内存中都以相同方式表示的,因此它们可以很轻松地存储和读取。例如,Redis 可以在 0.3 秒内从 RDB 文件中读取 500 万个条目。这使流的复制和持久存储非常高效。 + +我还计划允许从条目中间进行部分删除。现在仅实现了一部分,策略是在条目在标记中标识条目为已删除,并且,当已删除条目占全部条目的比例达到指定值时,这个块将被回收重写,如果需要,它将被连到相邻的另一个块上,以避免碎片化。 + +### 关于最终发布时间的结论 + +Redis 的流特性将包含在年底前(LCTT 译注:本文原文发布于 2017 年 10 月)推出的 Redis 4.0 系列的稳定版中。我认为这个通用的数据结构将为 Redis 提供一个巨大的补丁,以用于解决很多现在很难以解决的情况:那意味着你(之前)需要创造性地“滥用”当前提供的数据结构去解决那些问题。一个非常重要的使用场景是时间序列,但是,我觉得对于其它场景来说,通过 `TREAD` 来流播消息将是非常有趣的,因为对于那些需要更高可靠性的应用程序,可以使用发布/订阅模式来替换“即用即弃”,还有其它全新的使用场景。现在,如果你想在有问题环境中评估这个新数据结构,可以更新 GitHub 上的 streams 分支开始试用。欢迎向我们报告所有的 bug。:-) + +如果你喜欢观看视频的方式,这里有一个现场演示:https://www.youtube.com/watch?v=ELDzy9lCFHQ + +--- + +via: http://antirez.com/news/114 + +作者:[antirez][a] +译者:[qhwdw](https://github.com/qhwdw) +校对:[wxy](https://github.com/wxy), [pityonline](https://github.com/pityonline) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: http://antirez.com/ +[1]: https://zh.wikipedia.org/wiki/CAP%E5%AE%9A%E7%90%86 diff --git a/translated/tech/20171024 Learn Blockchains by Building One.md b/published/201807/20171024 Learn Blockchains by Building One.md similarity index 70% rename from translated/tech/20171024 Learn Blockchains by Building One.md rename to published/201807/20171024 Learn Blockchains by Building One.md index 23135eeec9..acbcaed1de 100644 --- a/translated/tech/20171024 Learn Blockchains by Building One.md +++ b/published/201807/20171024 Learn Blockchains by Building One.md @@ -1,40 +1,41 @@ -通过构建一个区块链来学习区块链技术 +想学习区块链?那就用 Python 构建一个 ====== +> 了解区块链是如何工作的最快的方法是构建一个。 + ![](https://cdn-images-1.medium.com/max/2000/1*zutLn_-fZZhy7Ari-x-JWQ.jpeg) -你看到这篇文章是因为和我一样,对加密货币的大热而感到兴奋。并且想知道区块链是如何工作的 —— 它们背后的技术是什么。 + +你看到这篇文章是因为和我一样,对加密货币的大热而感到兴奋。并且想知道区块链是如何工作的 —— 它们背后的技术基础是什么。 但是理解区块链并不容易 —— 至少对我来说是这样。我徜徉在各种难懂的视频中,并且因为示例太少而陷入深深的挫败感中。 -我喜欢在实践中学习。这迫使我去处理被卡在代码级别上的难题。如果你也是这么做的,在本指南结束的时候,你将拥有一个功能正常的区块链,并且实实在在地理解了它的工作原理。 +我喜欢在实践中学习。这会使得我在代码层面上处理主要问题,从而可以让我坚持到底。如果你也是这么做的,在本指南结束的时候,你将拥有一个功能正常的区块链,并且实实在在地理解了它的工作原理。 ### 开始之前 … -记住,区块链是一个 _不可更改的、有序的_ 被称为区块的记录链。它们可以包括事务~~(交易???校对确认一下,下同)~~、文件或者任何你希望的真实数据。最重要的是它们是通过使用_哈希_链接到一起的。 +记住,区块链是一个 _不可更改的、有序的_ 记录(被称为区块)的链。它们可以包括交易transaction、文件或者任何你希望的真实数据。最重要的是它们是通过使用_哈希_链接到一起的。 如果你不知道哈希是什么,[这里有解释][1]。 - **_本指南的目标读者是谁?_** 你应该能很容易地读和写一些基本的 Python 代码,并能够理解 HTTP 请求是如何工作的,因为我们讨论的区块链将基于 HTTP。 + **_本指南的目标读者是谁?_** 你应该能轻松地读、写一些基本的 Python 代码,并能够理解 HTTP 请求是如何工作的,因为我们讨论的区块链将基于 HTTP。 **_我需要做什么?_** 确保安装了 [Python 3.6][2]+(以及 `pip`),还需要去安装 Flask 和非常好用的 Requests 库: ``` - pip install Flask==0.12.2 requests==2.18.4 +pip install Flask==0.12.2 requests==2.18.4 ``` 当然,你也需要一个 HTTP 客户端,像 [Postman][3] 或者 cURL。哪个都行。 **_最终的代码在哪里可以找到?_** 源代码在 [这里][4]。 -* * * - ### 第 1 步:构建一个区块链 -打开你喜欢的文本编辑器或者 IDE,我个人 ❤️ [PyCharm][5]。创建一个名为 `blockchain.py` 的新文件。我将使用一个单个的文件,如果你看晕了,可以去参考 [源代码][6]。 +打开你喜欢的文本编辑器或者 IDE,我个人喜欢 [PyCharm][5]。创建一个名为 `blockchain.py` 的新文件。我将仅使用一个文件,如果你看晕了,可以去参考 [源代码][6]。 #### 描述一个区块链 -我们将创建一个 `Blockchain` 类,它的构造函数将去初始化一个空列表(去存储我们的区块链),以及另一个列表去保存事务。下面是我们的类规划: +我们将创建一个 `Blockchain` 类,它的构造函数将去初始化一个空列表(去存储我们的区块链),以及另一个列表去保存交易。下面是我们的类规划: ``` class Blockchain(object): @@ -58,15 +59,16 @@ class Blockchain(object): @property def last_block(self): # Returns the last Block in the chain -pass + pass ``` +*我们的 Blockchain 类的原型* -我们的区块链类负责管理链。它将存储事务并且有一些为链中增加新区块的助理性质的方法。现在我们开始去充实一些类的方法。 +我们的 `Blockchain` 类负责管理链。它将存储交易并且有一些为链中增加新区块的辅助性质的方法。现在我们开始去充实一些类的方法。 -#### 一个区块是什么样子的? +#### 区块是什么样子的? -每个区块有一个索引、一个时间戳(Unix 时间)、一个事务的列表、一个证明(后面会详细解释)、以及前一个区块的哈希。 +每个区块有一个索引、一个时间戳(Unix 时间)、一个交易的列表、一个证明(后面会详细解释)、以及前一个区块的哈希。 单个区块的示例应该是下面的样子: @@ -86,13 +88,15 @@ block = { } ``` -此刻,链的概念应该非常明显 —— 每个新区块包含它自身的信息和前一个区域的哈希。这一点非常重要,因为这就是区块链不可更改的原因:如果攻击者修改了一个早期的区块,那么所有的后续区块将包含错误的哈希。 +*我们的区块链中的块示例* -这样做有意义吗?如果没有,就让时间来埋葬它吧 —— 这就是区块链背后的核心思想。 +此刻,链的概念应该非常明显 —— 每个新区块包含它自身的信息和前一个区域的哈希。**这一点非常重要,因为这就是区块链不可更改的原因**:如果攻击者修改了一个早期的区块,那么**所有**的后续区块将包含错误的哈希。 -#### 添加事务到一个区块 +*这样做有意义吗?如果没有,就让时间来埋葬它吧 —— 这就是区块链背后的核心思想。* -我们将需要一种区块中添加事务的方式。我们的 `new_transaction()` 就是做这个的,它非常简单明了: +#### 添加交易到一个区块 + +我们将需要一种区块中添加交易的方式。我们的 `new_transaction()` 就是做这个的,它非常简单明了: ``` class Blockchain(object): @@ -113,14 +117,14 @@ class Blockchain(object): 'amount': amount, }) -return self.last_block['index'] + 1 + return self.last_block['index'] + 1 ``` -在 `new_transaction()` 运行后将在列表中添加一个事务,它返回添加事务后的那个区块的索引 —— 那个区块接下来将被挖矿。提交事务的用户后面会用到这些。 +在 `new_transaction()` 运行后将在列表中添加一个交易,它返回添加交易后的那个区块的索引 —— 那个区块接下来将被挖矿。提交交易的用户后面会用到这些。 #### 创建新区块 -当我们的区块链被实例化后,我们需要一个创世区块(一个没有祖先的区块)来播种它。我们也需要去添加一些 “证明” 到创世区块,它是挖矿(工作量证明 PoW)的成果。我们在后面将讨论更多挖矿的内容。 +当我们的 `Blockchain` 被实例化后,我们需要一个创世区块(一个没有祖先的区块)来播种它。我们也需要去添加一些 “证明” 到创世区块,它是挖矿(工作量证明 PoW)的成果。我们在后面将讨论更多挖矿的内容。 除了在我们的构造函数中创建创世区块之外,我们还需要写一些方法,如 `new_block()`、`new_transaction()` 以及 `hash()`: @@ -190,18 +194,18 @@ class Blockchain(object): # We must make sure that the Dictionary is Ordered, or we'll have inconsistent hashes block_string = json.dumps(block, sort_keys=True).encode() -return hashlib.sha256(block_string).hexdigest() + return hashlib.sha256(block_string).hexdigest() ``` 上面的内容简单明了 —— 我添加了一些注释和文档字符串,以使代码清晰可读。到此为止,表示我们的区块链基本上要完成了。但是,你肯定想知道新区块是如何被创建、打造或者挖矿的。 #### 理解工作量证明 -一个工作量证明(PoW)算法是在区块链上创建或者挖出新区块的方法。PoW 的目标是去撞出一个能够解决问题的数字。这个数字必须满足“找到它很困难但是验证它很容易”的条件 —— 网络上的任何人都可以计算它。这就是 PoW 背后的核心思想。 +工作量证明Proof of Work(PoW)算法是在区块链上创建或者挖出新区块的方法。PoW 的目标是去撞出一个能够解决问题的数字。这个数字必须满足“找到它很困难但是验证它很容易”的条件 —— 网络上的任何人都可以计算它。这就是 PoW 背后的核心思想。 我们来看一个非常简单的示例来帮助你了解它。 -我们来解决一个问题,一些整数 x 乘以另外一个整数 y 的结果的哈希值必须以 0 结束。因此,hash(x * y) = ac23dc…0。为简单起见,我们先把 x = 5 固定下来。在 Python 中的实现如下: +我们来解决一个问题,一些整数 `x` 乘以另外一个整数 `y` 的结果的哈希值必须以 `0` 结束。因此,`hash(x * y) = ac23dc…0`。为简单起见,我们先把 `x = 5` 固定下来。在 Python 中的实现如下: ``` from hashlib import sha256 @@ -215,19 +219,21 @@ while sha256(f'{x*y}'.encode()).hexdigest()[-1] != "0": print(f'The solution is y = {y}') ``` -在这里的答案是 y = 21。因为它产生的哈希值是以 0 结尾的: +在这里的答案是 `y = 21`。因为它产生的哈希值是以 0 结尾的: ``` hash(5 * 21) = 1253e9373e...5e3600155e860 ``` +在比特币中,工作量证明算法被称之为 [Hashcash][10]。与我们上面的例子没有太大的差别。这就是矿工们进行竞赛以决定谁来创建新块的算法。一般来说,其难度取决于在一个字符串中所查找的字符数量。然后矿工会因其做出的求解而得到奖励的币——在一个交易当中。 + 网络上的任何人都可以很容易地去核验它的答案。 #### 实现基本的 PoW 为我们的区块链来实现一个简单的算法。我们的规则与上面的示例类似: -> 找出一个数字 p,它与前一个区块的答案进行哈希运算得到一个哈希值,这个哈希值的前四位必须是由 0 组成。 +> 找出一个数字 `p`,它与前一个区块的答案进行哈希运算得到一个哈希值,这个哈希值的前四位必须是由 `0` 组成。 ``` import hashlib @@ -266,25 +272,21 @@ class Blockchain(object): guess = f'{last_proof}{proof}'.encode() guess_hash = hashlib.sha256(guess).hexdigest() -return guess_hash[:4] == "0000" + return guess_hash[:4] == "0000" ``` 为了调整算法的难度,我们可以修改前导 0 的数量。但是 4 个零已经足够难了。你会发现,将前导 0 的数量每增加一,那么找到正确答案所需要的时间难度将大幅增加。 我们的类基本完成了,现在我们开始去使用 HTTP 请求与它交互。 -* * * - ### 第 2 步:以 API 方式去访问我们的区块链 -我们将去使用 Python Flask 框架。它是个微框架,使用它去做端点到 Python 函数的映射很容易。这样我们可以使用 HTTP 请求基于 web 来与我们的区块链对话。 +我们将使用 Python Flask 框架。它是个微框架,使用它去做端点到 Python 函数的映射很容易。这样我们可以使用 HTTP 请求基于 web 来与我们的区块链对话。 我们将创建三个方法: -* `/transactions/new` 在一个区块上创建一个新事务 - +* `/transactions/new` 在一个区块上创建一个新交易 * `/mine` 告诉我们的服务器去挖矿一个新区块 - * `/chain` 返回完整的区块链 #### 配置 Flask @@ -332,33 +334,33 @@ def full_chain(): return jsonify(response), 200 if __name__ == '__main__': -app.run(host='0.0.0.0', port=5000) + app.run(host='0.0.0.0', port=5000) ``` 对上面的代码,我们做添加一些详细的解释: * Line 15:实例化我们的节点。更多关于 Flask 的知识读 [这里][7]。 - * Line 18:为我们的节点创建一个随机的名字。 - * Line 21:实例化我们的区块链类。 - -* Line 24–26:创建 /mine 端点,这是一个 GET 请求。 - -* Line 28–30:创建 /transactions/new 端点,这是一个 POST 请求,因为我们要发送数据给它。 - -* Line 32–38:创建 /chain 端点,它返回全部区块链。 - +* Line 24–26:创建 `/mine` 端点,这是一个 GET 请求。 +* Line 28–30:创建 `/transactions/new` 端点,这是一个 POST 请求,因为我们要发送数据给它。 +* Line 32–38:创建 `/chain` 端点,它返回全部区块链。 * Line 40–41:在 5000 端口上运行服务器。 -#### 事务端点 +#### 交易端点 -这就是对一个事务的请求,它是用户发送给服务器的: +这就是对一个交易的请求,它是用户发送给服务器的: ``` -{ "sender": "my address", "recipient": "someone else's address", "amount": 5} +{ + "sender": "my address", + "recipient": "someone else's address", + "amount": 5 +} ``` +因为我们已经有了添加交易到块中的类方法,剩下的就很容易了。让我们写个函数来添加交易: + ``` import hashlib import json @@ -383,18 +385,17 @@ def new_transaction(): index = blockchain.new_transaction(values['sender'], values['recipient'], values['amount']) response = {'message': f'Transaction will be added to Block {index}'} -return jsonify(response), 201 + return jsonify(response), 201 ``` -创建事务的方法 + +*创建交易的方法* #### 挖矿端点 我们的挖矿端点是见证奇迹的地方,它实现起来很容易。它要做三件事情: 1. 计算工作量证明 - -2. 因为矿工(我们)添加一个事务而获得报酬,奖励矿工(我们) 1 个硬币 - +2. 因为矿工(我们)添加一个交易而获得报酬,奖励矿工(我们) 1 个币 3. 通过将它添加到链上而打造一个新区块 ``` @@ -434,10 +435,10 @@ def mine(): 'proof': block['proof'], 'previous_hash': block['previous_hash'], } -return jsonify(response), 200 + return jsonify(response), 200 ``` -注意,挖掘出的区块的接收方是我们的节点地址。现在,我们所做的大部分工作都只是与我们的区块链类的方法进行交互的。到目前为止,我们已经做到了,现在开始与我们的区块链去交互。 +注意,挖掘出的区块的接收方是我们的节点地址。现在,我们所做的大部分工作都只是与我们的 `Blockchain` 类的方法进行交互的。到目前为止,我们已经做完了,现在开始与我们的区块链去交互。 ### 第 3 步:与我们的区块链去交互 @@ -447,24 +448,33 @@ return jsonify(response), 200 ``` $ python blockchain.py +* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit) ``` -我们通过生成一个 GET 请求到 http://localhost:5000/mine 去尝试挖一个区块: +我们通过生成一个 `GET` 请求到 `http://localhost:5000/mine` 去尝试挖一个区块: ![](https://cdn-images-1.medium.com/max/1600/1*ufYwRmWgQeA-Jxg0zgYLOA.png) -使用 Postman 去生成一个 GET 请求 -我们通过生成一个 POST 请求到 http://localhost:5000/transactions/new 去创建一个区块,它带有一个包含我们的事务结构的 `Body`: +*使用 Postman 去生成一个 GET 请求* + +我们通过生成一个 `POST` 请求到 `http://localhost:5000/transactions/new` 去创建一个区块,请求数据包含我们的交易结构: ![](https://cdn-images-1.medium.com/max/1600/1*O89KNbEWj1vigMZ6VelHAg.png) -使用 Postman 去生成一个 POST 请求 + +*使用 Postman 去生成一个 POST 请求* 如果你不使用 Postman,也可以使用 cURL 去生成一个等价的请求: ``` -$ curl -X POST -H "Content-Type: application/json" -d '{ "sender": "d4ee26eee15148ee92c6cd394edd974e", "recipient": "someone-other-address", "amount": 5}' "http://localhost:5000/transactions/new" +$ curl -X POST -H "Content-Type: application/json" -d '{ + "sender": "d4ee26eee15148ee92c6cd394edd974e", + "recipient": "someone-other-address", + "amount": 5 +}' "http://localhost:5000/transactions/new" ``` -我重启动我的服务器,然后我挖到了两个区块,这样总共有了3 个区块。我们通过请求 http://localhost:5000/chain 来检查整个区块链: + +我重启动我的服务器,然后我挖到了两个区块,这样总共有了 3 个区块。我们通过请求 `http://localhost:5000/chain` 来检查整个区块链: + ``` { "chain": [ @@ -503,18 +513,18 @@ $ curl -X POST -H "Content-Type: application/json" -d '{ "sender": "d4ee26eee151 } ], "length": 3 +} ``` ### 第 4 步:共识 -这是很酷的一个地方。我们已经有了一个基本的区块链,它可以接收事务并允许我们去挖掘出新区块。但是区块链的整个重点在于它是去中心化的。而如果它们是去中心化的,那我们如何才能确保它们表示在同一个区块链上?这就是共识问题,如果我们希望在我们的网络上有多于一个的节点运行,那么我们将必须去实现一个共识算法。 +这是很酷的一个地方。我们已经有了一个基本的区块链,它可以接收交易并允许我们去挖掘出新区块。但是区块链的整个重点在于它是去中心化的decentralized。而如果它们是去中心化的,那我们如何才能确保它们表示在同一个区块链上?这就是共识Consensus问题,如果我们希望在我们的网络上有多于一个的节点运行,那么我们将必须去实现一个共识算法。 #### 注册新节点 在我们能实现一个共识算法之前,我们需要一个办法去让一个节点知道网络上的邻居节点。我们网络上的每个节点都保留有一个该网络上其它节点的注册信息。因此,我们需要更多的端点: -1. /nodes/register 以 URLs 的形式去接受一个新节点列表 - -2. /nodes/resolve 去实现我们的共识算法,由它来解决任何的冲突 —— 确保节点有一个正确的链。 +1. `/nodes/register` 以 URL 的形式去接受一个新节点列表 +2. `/nodes/resolve` 去实现我们的共识算法,由它来解决任何的冲突 —— 确保节点有一个正确的链。 我们需要去修改我们的区块链的构造函数,来提供一个注册节点的方法: @@ -538,11 +548,12 @@ class Blockchain(object): """ parsed_url = urlparse(address) -self.nodes.add(parsed_url.netloc) + self.nodes.add(parsed_url.netloc) ``` -一个添加邻居节点到我们的网络的方法 -注意,我们将使用一个 `set()` 去保存节点列表。这是一个非常合算的方式,它将确保添加的内容是幂等的 —— 这意味着不论你将特定的节点添加多少次,它都是精确地只出现一次。 +*一个添加邻居节点到我们的网络的方法* + +注意,我们将使用一个 `set()` 去保存节点列表。这是一个非常合算的方式,它将确保添加的节点是幂等idempotent的 —— 这意味着不论你将特定的节点添加多少次,它都是精确地只出现一次。 #### 实现共识算法 @@ -615,12 +626,12 @@ class Blockchain(object) self.chain = new_chain return True -return False + return False ``` 第一个方法 `valid_chain()` 是负责来检查链是否有效,它通过遍历区块链上的每个区块并验证它们的哈希和工作量证明来检查这个区块链是否有效。 -`resolve_conflicts()` 方法用于遍历所有的邻居节点,下载它们的链并使用上面的方法去验证它们是否有效。如果找到有效的链,确定谁是最长的链,然后我们就用最长的链来替换我们的当前的链。 +`resolve_conflicts()` 方法用于遍历所有的邻居节点,下载它们的链并使用上面的方法去验证它们是否有效。**如果找到有效的链,确定谁是最长的链,然后我们就用最长的链来替换我们的当前的链。** 在我们的 API 上来注册两个端点,一个用于添加邻居节点,另一个用于解决冲突: @@ -658,18 +669,20 @@ def consensus(): 'chain': blockchain.chain } -return jsonify(response), 200 + return jsonify(response), 200 ``` -这种情况下,如果你愿意可以使用不同的机器来做,然后在你的网络上启动不同的节点。或者是在同一台机器上使用不同的端口启动另一个进程。我是在我的机器上使用了不同的端口启动了另一个节点,并将它注册到了当前的节点上。因此,我现在有了两个节点:[http://localhost:5000][9] 和 http://localhost:5001。 +这种情况下,如果你愿意,可以使用不同的机器来做,然后在你的网络上启动不同的节点。或者是在同一台机器上使用不同的端口启动另一个进程。我是在我的机器上使用了不同的端口启动了另一个节点,并将它注册到了当前的节点上。因此,我现在有了两个节点:`http://localhost:5000` 和 `http://localhost:5001`。 ![](https://cdn-images-1.medium.com/max/1600/1*Dd78u-gmtwhQWHhPG3qMTQ.png) -注册一个新节点 + +*注册一个新节点* 我接着在节点 2 上挖出一些新区块,以确保这个链是最长的。之后我在节点 1 上以 `GET` 方式调用了 `/nodes/resolve`,这时,节点 1 上的链被共识算法替换成节点 2 上的链了: ![](https://cdn-images-1.medium.com/max/1600/1*SGO5MWVf7GguIxfz6S8NVw.png) -工作中的共识算法 + +*工作中的共识算法* 然后将它们封装起来 … 找一些朋友来帮你一起测试你的区块链。 @@ -677,7 +690,7 @@ return jsonify(response), 200 我希望以上内容能够鼓舞你去创建一些新的东西。我是加密货币的狂热拥护者,因此我相信区块链将迅速改变我们对经济、政府和记录保存的看法。 -**更新:** 我正计划继续它的第二部分,其中我将扩展我们的区块链,使它具备事务验证机制,同时讨论一些你可以在其上产生你自己的区块链的方式。 +**更新:** 我正计划继续它的第二部分,其中我将扩展我们的区块链,使它具备交易验证机制,同时讨论一些你可以在其上产生你自己的区块链的方式。(LCTT 译注:第二篇并没有~!) -------------------------------------------------------------------------------- @@ -685,7 +698,7 @@ via: https://hackernoon.com/learn-blockchains-by-building-one-117428612f46 作者:[Daniel van Flymen][a] 译者:[qhwdw](https://github.com/qhwdw) -校对:[校对者ID](https://github.com/校对者ID) +校对:[wxy](https://github.com/wxy) 本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 @@ -699,3 +712,4 @@ via: https://hackernoon.com/learn-blockchains-by-building-one-117428612f46 [7]:http://flask.pocoo.org/docs/0.12/quickstart/#a-minimal-application [8]:http://localhost:5000/transactions/new [9]:http://localhost:5000 +[10]:https://en.wikipedia.org/wiki/Hashcash \ No newline at end of file diff --git a/translated/tech/20171116 How to improve ROI on automation- 4 tips.md b/published/201807/20171116 How to improve ROI on automation- 4 tips.md similarity index 87% rename from translated/tech/20171116 How to improve ROI on automation- 4 tips.md rename to published/201807/20171116 How to improve ROI on automation- 4 tips.md index edce4dcdb2..2139c43c64 100644 --- a/translated/tech/20171116 How to improve ROI on automation- 4 tips.md +++ b/published/201807/20171116 How to improve ROI on automation- 4 tips.md @@ -1,12 +1,15 @@ 如何提升自动化的 ROI:4 个小提示 ====== +> 想要在你的自动化项目上达成强 RIO?采取如下步骤来规避失败。 + ![](https://enterprisersproject.com/sites/default/files/styles/620x350/public/cio_it_investments_2.png?itok=Ut1XIIBN) -在过去的几年间,有关自动化技术的讨论已经很多了。COO 们和运营团队(事实上还有其它的业务部门)对成本随着工作量的增加而增加的这一事实可以重新定义而感到震惊。 -机器人流程自动化(RPA)似乎预示着运营的圣杯(Holy Grail):“我们提供了开箱即用的功能来满足你的日常操作所需 —— 检查电子邮件、保存附件、取数据、更新表格、生成报告、文件以及目录操作。构建一个机器人就像配置这些功能一样简单,然后用机器人将这些操作链接到一起,而不用去请求 IT 部门来构建它们。”这是一个多么诱人的话题。 +在过去的几年间,有关自动化技术的讨论已经很多了。COO 们和运营团队(事实上还有其它的业务部门)对于可以重新定义成本随着工作量的增加而增加的这一事实而感到震惊。 -低成本、几乎不出错、非常遵守流程 —— 对 COO 们和运营领导来说,这些好处即实用可行度又高。RPA 工具承诺,它从运营中节省下来的费用就足够支付它的成本(有一个短的回报期),这一事实使得业务的观点更具有吸引力。 +机器人流程自动化Robotic Process Automation(RPA)似乎预示着运营的圣杯Holy Grail:“我们提供了开箱即用的功能来满足你的日常操作所需 —— 检查电子邮件、保存附件、取数据、更新表格、生成报告、文件以及目录操作。构建一个机器人就像配置这些功能一样简单,然后用机器人将这些操作链接到一起,而不用去请求 IT 部门来构建它们。”这是一个多么诱人的话题。 + +低成本、几乎不出错、非常遵守流程 —— 对 COO 们和运营领导来说,这些好处真实可及。RPA 工具承诺,它从运营中节省下来的费用就足够支付它的成本(有一个短的回报期),这一事实使得业务的观点更具有吸引力。 自动化的谈论都趋向于类似的话题:COO 们和他们的团队想知道,自动化操作能够给他们带来什么好处。他们想知道 RPA 平台特性和功能,以及自动化在现实中的真实案例。从这一点到概念验证的实现过程通常很短暂。 @@ -14,7 +17,7 @@ 但是自动化带来的现实好处有时候可能比你所预期的时间要晚。采用 RPA 的公司在其实施后可能会对它们自身的 ROI 提出一些质疑。一些人没有看到预期之中的成本节省,并对其中的原因感到疑惑。 -## 你是不是自动化了错误的东西? +### 你是不是自动化了错误的东西? 在这些情况下,自动化的愿景和现实之间的差距是什么呢?我们来分析一下它,在决定去继续进行一个自动化验证项目(甚至是一个成熟的实践)之后,我们来看一下通常会发生什么。 @@ -26,7 +29,7 @@ 那么,对于领导们来说,怎么才能确保实施自动化能够带来他们想要的 ROI 呢?实现这个目标有四步: -## 1. 教育团队 +### 1. 教育团队 在你的团队中,从 COO 职位以下的人中,很有可能都听说过 RPA 和运营自动化。同样很有可能他们都有许多的问题和担心。在你开始启动实施之前解决这些问题和担心是非常重要的。 @@ -36,23 +39,23 @@ “实施自动化的第一步是更好地理解你的流程。” -## 2. 审查内部流程 +### 2. 审查内部流程 实施自动化的第一步是更好地理解你的流程。每个 RPA 实施之前都应该进行流程清单、动作分析、以及成本/价值的绘制练习。 -这些练习对于理解流程中何处价值产生(或成本,如果没有价值的情况下)是至关重要的。并且这些练习需要在每个流程或者每个任务这样的粒度级别上来做。 +这些练习对于理解流程中何处产生价值(或成本,如果没有价值的情况下)是至关重要的。并且这些练习需要在每个流程或者每个任务这样的粒度级别上来做。 这将有助你去识别和优先考虑最合适的自动化候选者。由于能够或者可能需要自动化的任务数量较多,流程一般需要分段实施自动化,因此优先级很重要。 **建议**:设置一个小的工作团队,每个运营团队都参与其中。从每个运营团队中提名一个协调人 —— 一般是运营团队的领导或者团队管理者。在团队级别上组织一次研讨会,去构建流程清单、识别候选流程、以及推动购买。你的自动化合作伙伴很可能有“加速器” —— 调查问卷、计分卡等等 —— 这些将帮助你加速完成这项活动。 -## 3. 为优先业务提供强有力的指导 +### 3. 为优先业务提供强有力的指导 实施自动化经常会涉及到在运营团队之间,基于业务价值对流程选择和自动化优先级上要达成共识(有时候是打破平衡)虽然团队的参与仍然是分析和实施的关键部分,但是领导仍然应该是最终的决策者。 **建议**:安排定期会议从工作团队中获取最新信息。除了像推动达成共识和购买之外,工作团队还应该在团队层面上去查看领导们关于 ROI、平台选择、以及自动化优先级上的指导性决定。 -## 4. 应该推动 CIO 和 COO 的紧密合作 +### 4. 应该推动 CIO 和 COO 的紧密合作 当运营团队和技术团队紧密合作时,自动化的实施将异常顺利。COO 需要去帮助推动与 CIO 团队的合作。 @@ -68,7 +71,7 @@ via: https://enterprisersproject.com/article/2017/11/how-improve-roi-automation- 作者:[Rajesh Kamath][a] 译者:[qhwdw](https://github.com/qhwdw) -校对:[校对者ID](https://github.com/校对者ID) +校对:[wxy](https://github.com/wxy) 本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 diff --git a/published/20171228 Container Basics- Terms You Need to Know.md b/published/201807/20171228 Container Basics- Terms You Need to Know.md similarity index 100% rename from published/20171228 Container Basics- Terms You Need to Know.md rename to published/201807/20171228 Container Basics- Terms You Need to Know.md diff --git a/sources/tech/20180103 How To Find The Installed Proprietary Packages In Arch Linux.md b/published/201807/20180103 How To Find The Installed Proprietary Packages In Arch Linux.md similarity index 63% rename from sources/tech/20180103 How To Find The Installed Proprietary Packages In Arch Linux.md rename to published/201807/20180103 How To Find The Installed Proprietary Packages In Arch Linux.md index 69b523426c..29c05462ac 100644 --- a/sources/tech/20180103 How To Find The Installed Proprietary Packages In Arch Linux.md +++ b/published/201807/20180103 How To Find The Installed Proprietary Packages In Arch Linux.md @@ -1,34 +1,40 @@ -How To Find The Installed Proprietary Packages In Arch Linux +如何在 Arch Linux 中查找已安装的专有软件包? ====== + ![](https://www.ostechnix.com/wp-content/uploads/2018/01/Absolutely-Proprietary-720x340.jpg) -Are you an avid free software supporter and currently using any Arch based distribution? I've got a small tip for you! Now, you can easily find the installed proprietary packages in Arch Linux and its variants such as Antergos, Manjaro Linux etc. You don't need to refer the license details of the installed package in its website or use any external tool to find out whether the package is free or proprietary. -### Find The Installed Proprietary Packages In Arch Linux +你是狂热的自由软件支持者吗?你目前在使用任何基于 Arch 的 Linux 发行版吗?我有一个小小的提示送给你!现在,你可以轻松地在 Arch Linux 及其变体(如 Antergos、Manjaro Linux 等)中找到已安装的专有软件包。你无需在已安装软件包的网站中参考其许可细节,也无需使用任何其它外部工具来查明软件包是自由的还是专有的。(LCTT 译注:其实下面还是借助了一个外部程序) -A fellow developer has developed an utility named **" Absolutely Proprietary"**, a proprietary package detector for arch-based distributions. It compares all installed packages in your Arch based system against Parabola's package [blacklist][1] and [aur-blacklist][2] and then prints your **Stallman Freedom Index** (free/total). Additionally, you can save the list to a file and share or compare it with other systems/users. +### 在 Arch Linux 中查找已安装的专有软件包 -Before installing it, Make sure you have installed **python** and **git**. +一位开发人员开发了一个名为 “[Absolutely Proprietary][5]” 的实用程序,它是一种用于基于 Arch 发行版的专有软件包检测器。它将基于 Arch 系统中的所有安装包与 Parabola 的软件包 [blacklist][1]和 [aur-blacklist][2] 进行比较,然后显示出你的斯托曼自由指数Stallman Freedom Index(“自由/总计”比分)。此外,你可以将该列表保存到文件中,并与其他系统/用户共享或比较。 + +在安装之前,确保你安装了 Python 和 Git。 + +然后,`git clone` 仓库: -Then, git clone the repository: ``` git clone https://github.com/vmavromatis/absolutely-proprietary.git ``` -This command will download all contents in a directory called 'absolutely-proprietary' in your current working directory. +这条命令将会下载所有内容到你当前工作目录中的 `absolutely-proprietary` 目录。 + +进入此目录: -Change to that directory: ``` cd absolutely-proprietary ``` -And, find the installed proprietary packages using command: +接着,使用以下命令查找已安装的专有软件: + ``` python main.py ``` -This command will download the blacklist.txt, aur-blacklist.txt and compare the locally installed packages with the remote packages and displays the +这条命令将会下载 `blacklist.txt`、`aur-blacklist.txt`,并将本地已安装的软件包与远程软件包进行比较并显示其指数。 + +以下是在我的 Arch Linux 桌面的示例输出: -Here is the sample output from my Arch Linux desktop: ``` Retrieving local packages (including AUR)... Downloading https://git.parabola.nu/blacklist.git/plain/blacklist.txt @@ -73,9 +79,10 @@ Your Stallman Freedom Index is 96.57 Save list to file? (Y/n) ``` -[![][3]][4] +![][4] + +如你所见,我的系统中有 47 个专有软件包。就像我说的那样,我们可以将它保存到文件中稍后查看。为此,当提示你将列表保存在文件时,请按 `y`。然后按 `y` 接受默认值,或按 `n` 以你喜欢的格式和位置来保存它。 -As you can see, I have 47 proprietary packages in my system. Like I said already, we can save it to a file and review them later. To do so, jut press 'y' when you are prompted to save the list in a file. Then press 'y' to accept the defaults or hit 'n' to save it in your preferred format and location. ``` Save list to file? (Y/n) y Save as markdown table? (Y/n) y @@ -87,29 +94,29 @@ using the "less -S /home/sk/absolutely-proprietary/y.md" or, if installed, the "most /home/sk/absolutely-proprietary/y.md" commands ``` -As you may noticed, I have only the **nonfree** packages. It will display two more type of packages such as semifree, uses-nonfree. +你可能已经注意到,我只有 **nonfree** 包。它还会显示另外两种类型的软件包,例如 semifree、 uses-nonfree。 - * **nonfree** : This package is blatantly nonfree software. - * **semifree** : This package is mostly free, but contains some nonfree software. - * **uses-nonfree** : This package depends on, recommends, or otherwise inappropriately integrates with other nonfree software or services. + * **nonfree**:这个软件包是公然的非自由软件。 + * **semifree**:这个软件包大部分是自由的,但包含一些非自由软件。 + * **uses-nonfree**:这个软件包依赖、推荐或不恰当地与其他自由软件或服务集成。 +该使用程序的另一个显著特点是它不仅显示了专有软件包,而且还显示这些包的替代品。 +希望这有些帮助。我很快就会在这里提供另一份有用的指南。敬请关注! -Another notable feature of this utility is it's not just displays the propriety packages, but also alternatives to such packages. - -Hope this helps. I will be soon here with another useful guide soon. Stay tuned! - -Cheers! +干杯! +资源: +- [Absolutely Proprietary][5] -------------------------------------------------------------------------------- via: https://www.ostechnix.com/find-installed-proprietary-packages-arch-linux/ 作者:[SK][a] -译者:[译者ID](https://github.com/译者ID) -校对:[校对者ID](https://github.com/校对者ID) +译者:[MjSeven](https://github.com/MjSeven) +校对:[wxy](https://github.com/wxy) 本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 @@ -117,4 +124,5 @@ via: https://www.ostechnix.com/find-installed-proprietary-packages-arch-linux/ [1]:https://git.parabola.nu/blacklist.git/plain/blacklist.txt [2]:https://git.parabola.nu/blacklist.git/plain/aur-blacklist.txt [3]:data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7 -[4]:http://www.ostechnix.com/wp-content/uploads/2018/01/Proprietary-Packages-1-1.png () +[4]:http://www.ostechnix.com/wp-content/uploads/2018/01/Proprietary-Packages-1-1.png +[5]:https://github.com/vmavromatis/absolutely-proprietary \ No newline at end of file diff --git a/translated/tech/20180115 How debuggers really work.md b/published/201807/20180115 How debuggers really work.md similarity index 85% rename from translated/tech/20180115 How debuggers really work.md rename to published/201807/20180115 How debuggers really work.md index b4b5740fe1..e7f2772948 100644 --- a/translated/tech/20180115 How debuggers really work.md +++ b/published/201807/20180115 How debuggers really work.md @@ -1,13 +1,15 @@ 调试器到底怎样工作 ====== +> 你也许用过调速器检查过你的代码,但你知道它们是如何做到的吗? + ![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/annoyingbugs.png?itok=ywFZ99Gs) 供图:opensource.com -调试器是那些大多数(即使不是每个)开发人员在软件工程职业生涯中至少使用过一次的软件之一,但是你们中有多少人知道它们到底是如何工作的?我在悉尼 [linux.conf.au 2018][1] 的演讲中,将讨论从头开始编写调试器...使用 [Rust][2]! +调试器是大多数(即使不是每个)开发人员在软件工程职业生涯中至少使用过一次的那些软件之一,但是你们中有多少人知道它们到底是如何工作的?我在悉尼 [linux.conf.au 2018][1] 的演讲中,将讨论从头开始编写调试器……使用 [Rust][2]! -在本文中,术语调试器/跟踪器可以互换。 “被跟踪者”是指正在被跟踪者跟踪的进程。 +在本文中,术语调试器debugger跟踪器tracer可以互换。 “被跟踪者Tracee”是指正在被跟踪器跟踪的进程。 ### ptrace 系统调用 @@ -17,59 +19,46 @@ long ptrace(enum __ptrace_request request, pid_t pid, void *addr, void *data); ``` -这是一个可以操纵进程几乎所有方面的系统调用;但是,在调试器可以连接到一个进程之前,“被跟踪者”必须以请求 `PTRACE_TRACEME` 调用 `ptrace`。这告诉 Linux,父进程通过 `ptrace` 连接到这个进程是合法的。但是......我们如何强制一个进程调用 `ptrace`?很简单!`fork/execve` 提供了在 `fork` 之后但在被跟踪者真正开始使用 `execve` 之前调用 `ptrace` 的简单方法。很方便地,`fork` 还会返回被跟踪者的 `pid`,这是后面使用 `ptrace` 所必需的。 +这是一个可以操纵进程几乎所有方面的系统调用;但是,在调试器可以连接到一个进程之前,“被跟踪者”必须以请求 `PTRACE_TRACEME` 调用 `ptrace`。这告诉 Linux,父进程通过 `ptrace` 连接到这个进程是合法的。但是……我们如何强制一个进程调用 `ptrace`?很简单!`fork/execve` 提供了在 `fork` 之后但在被跟踪者真正开始使用 `execve` 之前调用 `ptrace` 的简单方法。很方便地,`fork` 还会返回被跟踪者的 `pid`,这是后面使用 `ptrace` 所必需的。 现在被跟踪者可以被调试器追踪,重要的变化发生了: - * 每当一个信号被传送到被调试者时,它就会停止,并且一个可以被 `wait` 系列系统调用捕获的等待事件被传送给跟踪器。 + * 每当一个信号被传送到被跟踪者时,它就会停止,并且一个可以被 `wait` 系列的系统调用捕获的等待事件被传送给跟踪器。 * 每个 `execve` 系统调用都会导致 `SIGTRAP` 被传递给被跟踪者。(与之前的项目相结合,这意味着被跟踪者在一个 `execve` 完全发生之前停止。) 这意味着,一旦我们发出 `PTRACE_TRACEME` 请求并调用 `execve` 系统调用来实际在被跟踪者(进程上下文)中启动程序时,被跟踪者将立即停止,因为 `execve` 会传递一个 `SIGTRAP`,并且会被跟踪器中的等待事件捕获。我们如何继续?正如人们所期望的那样,`ptrace` 有大量的请求可以用来告诉被跟踪者可以继续: - * `PTRACE_CONT`:这是最简单的。 被跟踪者运行,直到它接收到一个信号,此时等待事件被传递给跟踪器。这是最常见的实现真实世界调试器的“继续直至断点”和“永远继续”选项的方式。断点将在下面介绍。 * `PTRACE_SYSCALL`:与 `PTRACE_CONT` 非常相似,但在进入系统调用之前以及在系统调用返回到用户空间之前停止。它可以与其他请求(我们将在本文后面介绍)结合使用来监视和修改系统调用的参数或返回值。系统调用追踪程序 `strace` 很大程度上使用这个请求来获知进程发起了哪些系统调用。 * `PTRACE_SINGLESTEP`:这个很好理解。如果您之前使用过调试器(你会知道),此请求会执行下一条指令,然后立即停止。 - - 我们可以通过各种各样的请求停止进程,但我们如何获得被调试者的状态?进程的状态大多是通过其寄存器捕获的,所以当然 `ptrace` 有一个请求来获得(或修改)寄存器: * `PTRACE_GETREGS`:这个请求将给出被跟踪者刚刚被停止时的寄存器的状态。 - * `PTRACE_SETREGS`:如果跟踪器之前通过调用 `PTRACE_GETREGS` 得到了寄存器的值,它可以在参数结构中修改相应寄存器的值并使用 `PTRACE_SETREGS` 将寄存器设为新值。 + * `PTRACE_SETREGS`:如果跟踪器之前通过调用 `PTRACE_GETREGS` 得到了寄存器的值,它可以在参数结构中修改相应寄存器的值,并使用 `PTRACE_SETREGS` 将寄存器设为新值。 * `PTRACE_PEEKUSER` 和 `PTRACE_POKEUSER`:这些允许从被跟踪者的 `USER` 区读取信息,这里保存了寄存器和其他有用的信息。 这可以用来修改单一寄存器,而避免使用更重的 `PTRACE_{GET,SET}REGS` 请求。 - - 在调试器仅仅修改寄存器是不够的。调试器有时需要读取一部分内存,甚至对其进行修改。GDB 可以使用 `print` 得到一个内存位置或变量的值。`ptrace` 通过下面的方法实现这个功能: * `PTRACE_PEEKTEXT` 和 `PTRACE_POKETEXT`:这些允许读取和写入被跟踪者地址空间中的一个字。当然,使用这个功能时被跟踪者要被暂停。 - - -真实世界的调试器也有类似断点和观察点的功能。 在接下来的部分中,我将深入体系结构对调试器支持的细节。为了清晰和简洁,本文将只考虑x86。 +真实世界的调试器也有类似断点和观察点的功能。 在接下来的部分中,我将深入体系结构对调试器支持的细节。为了清晰和简洁,本文将只考虑 x86。 ### 体系结构的支持 `ptrace` 很酷,但它是如何工作? 在前面的部分中,我们已经看到 `ptrace` 跟信号有很大关系:`SIGTRAP` 可以在单步跟踪、`execve` 之前以及系统调用前后被传送。信号可以通过一些方式产生,但我们将研究两个具体的例子,以展示信号可以被调试器用来在给定的位置停止程序(有效地创建一个断点!): - * **未定义的指令**:当一个进程尝试执行一个未定义的指令,CPU 将产生一个异常。此异常通过 CPU 中断处理,内核中相应的中断处理程序被调用。这将导致一个 `SIGILL` 信号被发送给进程。 这依次导致进程被停止,跟踪器通过一个等待事件被通知,然后它可以决定后面做什么。在 x86 上,指令 `ud2` 被确保始终是未定义的。 - * **调试中断**:前面的方法的问题是,`ud2` 指令需要占用两个字节的机器码。存在一条特殊的单字节指令能够触发一个中断,它是 `int $3`,机器码是 `0xCC`。 当该中断发出时,内核向进程发送一个 `SIGTRAP`,如前所述,跟踪器被通知。 - - -这很好,但如何做我们胁迫的被跟踪者执行这些指令? 这很简单:利用 `ptrace` 的 `PTRACE_POKETEXT` 请求,它可以覆盖内存中的一个字。 调试器将使用 `PTRACE_PEEKTEXT` 读取该位置原来的值并替换为 `0xCC` ,然后在其内部状态中记录该处原来的值,以及它是一个断点的事实。 下次被跟踪者执行到该位置时,它将被通过 `SIGTRAP` 信号自动停止。 然后调试器的最终用户可以决定如何继续(例如,检查寄存器)。 +这很好,但如何我们才能胁迫被跟踪者执行这些指令? 这很简单:利用 `ptrace` 的 `PTRACE_POKETEXT` 请求,它可以覆盖内存中的一个字。 调试器将使用 `PTRACE_PEEKTEXT` 读取该位置原来的值并替换为 `0xCC` ,然后在其内部状态中记录该处原来的值,以及它是一个断点的事实。 下次被跟踪者执行到该位置时,它将被通过 `SIGTRAP` 信号自动停止。 然后调试器的最终用户可以决定如何继续(例如,检查寄存器)。 好吧,我们已经讲过了断点,那观察点呢? 当一个特定的内存位置被读或写,调试器如何停止程序? 当然你不可能为了能够读或写内存而去把每一个指令都覆盖为 `int $3`。有一组调试寄存器为了更有效的满足这个目的而被设计出来: - * `DR0` 到 `DR3`:这些寄存器中的每个都包含一个地址(内存位置),调试器因为某种原因希望被跟踪者在那些地址那里停止。 其原因以掩码方式被设定在 `DR7` 寄存器中。 - * `DR4` 和 `DR5`:这些分别是 `DR6` 和 `DR7`过时的别名。 + * `DR4` 和 `DR5`:这些分别是 `DR6` 和 `DR7` 过时的别名。 * `DR6`:调试状态。包含有关 `DR0` 到 `DR3` 中的哪个寄存器导致调试异常被引发的信息。这被 Linux 用来计算与 `SIGTRAP` 信号一起传递给被跟踪者的信息。 - * `DR7`:调试控制。通过使用这些寄存器中的位,调试器可以控制如何解释DR0至DR3中指定的地址。位掩码控制监视点的尺寸(监视1,2,4或8个字节)以及是否在执行、读取、写入时引发异常,或在读取或写入时引发异常。 - + * `DR7`:调试控制。通过使用这些寄存器中的位,调试器可以控制如何解释 `DR0` 至 `DR3` 中指定的地址。位掩码控制监视点的尺寸(监视1、2、4 或 8 个字节)以及是否在执行、读取、写入时引发异常,或在读取或写入时引发异常。 由于调试寄存器是进程的 `USER` 区域的一部分,调试器可以使用 `PTRACE_POKEUSER` 将值写入调试寄存器。调试寄存器只与特定进程相关,因此在进程抢占并重新获得 CPU 控制权之前,调试寄存器会被恢复。 @@ -88,7 +77,7 @@ via: https://opensource.com/article/18/1/how-debuggers-really-work 作者:[Levente Kurusa][a] 译者:[stephenxs](https://github.com/stephenxs) -校对:[校对者ID](https://github.com/校对者ID) +校对:[wxy](https://github.com/wxy) 本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 diff --git a/published/201807/20180115 Why DevSecOps matters to IT leaders.md b/published/201807/20180115 Why DevSecOps matters to IT leaders.md new file mode 100644 index 0000000000..3ca2d5d3ea --- /dev/null +++ b/published/201807/20180115 Why DevSecOps matters to IT leaders.md @@ -0,0 +1,87 @@ +为什么 DevSecOps 对 IT 领导来说如此重要 +====== + +> DevSecOps 也许不是一个优雅的词汇,但是其结果很吸引人:更强的安全、提前出现在开发周期中。来看看一个 IT 领导与 Meltdown 的拼搏。 + +![](https://enterprisersproject.com/sites/default/files/styles/620x350/public/images/TEP_SecurityTraining1_620x414_1014.png?itok=zqxqJGDG) + +如果 [DevOps][1] 最终是关于创造更好的软件,那也就意味着是更安全的软件。 + +而到了术语 “DevSecOps”,就像任何其他 IT 术语一样,DevSecOps —— 一个更成熟的 DevOps 的后代 ——可能容易受到炒作和盗用。但这个术语对那些拥抱了 DevOps 文化的领导者们来说具有重要的意义,并且其实践和工具可以帮助他们实现其承诺。 + +说道这里:“DevSecOps”是什么意思? + +“DevSecOps 是开发、安全、运营的混合,”来自 [Datical][2] 的首席技术官和联合创始人 Robert 说。“这提醒我们,对我们的应用程序来说安全和创建并部署应用到生产中一样重要。” + +**[想阅读其他首席技术官的 DevOps 文章吗?查阅我们丰富的资源,[DevOps:IT 领导者指南][3]]** + +向非技术人员解释 DevSecOps 的一个简单的方法是:它是指将安全有意并提前加入到开发过程中。 + +“安全团队从历史上一直都被孤立于开发团队——每个团队在 IT 的不同领域都发展了很强的专业能力”,来自红帽安全策的专家 Kirsten 最近告诉我们。“不需要这样,非常关注安全也关注他们通过软件来兑现商业价值的能力的企业正在寻找能够在应用开发生命周期中加入安全的方法。他们通过在整个 CI/CD 管道中集成安全实践、工具和自动化来采用 DevSecOps。” + +“为了能够做的更好,他们正在整合他们的团队——专业的安全人员从开始设计到部署到生产中都融入到了开发团队中了,”她说,“双方都收获了价值——每个团队都拓展了他们的技能和基础知识,使他们自己都成更有价值的技术人员。 DevOps 做的很正确——或者说 DevSecOps——提高了 IT 的安全性。” + +IT 团队比任何以往都要求要快速频繁的交付服务。DevOps 在某种程度上可以成为一个很棒的推动者,因为它能够消除开发和运营之间通常遇到的一些摩擦,运营一直被排挤在整个过程之外直到要部署的时候,开发者把代码随便一放之后就不再去管理,他们承担更少的基础架构的责任。那种孤立的方法引起了很多问题,委婉的说,在数字时代,如果将安全孤立起来同样的情况也会发生。 + +“我们已经采用了 DevOps,因为它已经被证明通过移除开发和运营之间的阻碍来提高 IT 的绩效,”Reevess 说,“就像我们不应该在开发周期要结束时才加入运营,我们不应该在快要结束时才加入安全。” + +### 为什么 DevSecOps 必然出现 + +或许会把 DevSecOps 看作是另一个时髦词,但对于安全意识很强的IT领导者来说,它是一个实质性的术语:在软件开发管道中安全必须是第一层面的要素,而不是部署前的最后一步的螺栓,或者更糟的是,作为一个团队只有当一个实际的事故发生的时候安全人员才会被重用争抢。 + +“DevSecOps 不只是一个时髦的术语——因为多种原因它是现在和未来 IT 将呈现的状态”,来自 [Sumo Logic] 的安全和合规副总裁 George 说道,“最重要的好处是将安全融入到开发和运营当中开提供保护的能力” + +此外,DevSecOps 的出现可能是 DevOps 自身逐渐成熟并扎根于 IT 之中的一个征兆。 + +“企业中的 DevOps 文化已成定局,而且那意味着开发者们正以不断增长的速度交付功能和更新,特别是自我管理的组织会对合作和衡量的结果更加满意”,来自 [CYBRIC] 的首席技术官和联合创始人 Mike 说道。 + +在实施 DevOps 的同时继续保留原有安全措施的团队和公司,随着他们继续部署的更快更频繁可能正在经历越来越多的安全管理风险上的痛苦。 + +“现在的手工的安全测试方法会继续远远被甩在后面。” + +“如今,手动的安全测试方法正被甩得越来越远,利用自动化和协作将安全测试转移到软件开发生命周期中,因此推动 DevSecOps 的文化是 IT 领导者们为增加整体的灵活性提供安全保证的唯一途径”,Kail 说。 + +转移安全测试也使开发者受益:他们能够在开放的较早的阶段验证并解决潜在的问题——这样很少需要或者甚至不需要安全人员的介入,而不是在一个新的服务或者更新部署之前在他们的代码中发现一个明显的漏洞。 + +“做的正确,DevSecOps 能够将安全融入到开发生命周期中,允许开发者们在没有安全中断的情况下更加快速容易的保证他们应用的安全”,来自 [SAS][8] 的首席信息安全员 Wilson 说道。 + +Wilson 指出静态(SAST)和源组合分析(SCA)工具,集成到团队的持续交付管道中,作为有用的技术通过给予开发者关于他们的代码中的潜在问题和第三方依赖中的漏洞的反馈来使之逐渐成为可能。 + +“因此,开发者们能够主动和迭代的缓解应用安全的问题,然后在不需要安全人员介入的情况下重新进行安全扫描。” Wilson 说。他同时指出 DevSecOps 能够帮助开发者简化更新和打补丁。 + +DevSecOps 并不意味着你不再需要安全组的意见了,就如同 DevOps 并不意味着你不再需要基础架构专家;它只是帮助你减少在生产中发现缺陷的可能性,或者减少导致降低部署速度的阻碍,因为缺陷已经在开发周期中被发现解决了。 + +“如果他们有问题或者需要帮助,我们就在这儿,但是因为已经给了开发者他们需要的保护他们应用安全的工具,我们很少在一个深入的测试中发现一个导致中断的问题,”Wilson 说道。 + +### DevSecOps 遇到 Meltdown + +Sumo Locic 的 Gerchow 向我们分享了一个在运转中的 DevSecOps 文化的一个及时案例:当最近 [Meltdown 和 Spectre] 的消息传来的时候,团队的 DevSecOps 方法使得有了一个快速的响应来减轻风险,没有任何的通知去打扰内部或者外部的顾客,Gerchow 所说的这点对原生云、高监管的公司来说特别的重要。 + +第一步:Gerchow 的小型安全团队都具有一定的开发能力,能够通过 Slack 和它的主要云供应商协同工作来确保它的基础架构能够在 24 小时之内完成修复。 + +“接着我的团队立即开始进行系统级的修复,实现终端客户的零停机时间,不需要去开工单给工程师,如果那样那意味着你需要等待很长的变更过程。所有的变更都是通过 Slack 的自动 jira 票据进行,通过我们的日志监控和分析解决方案”,Gerchow 解释道。 + +在本质上,它听起来非常像 DevOps 文化,匹配正确的人员、过程和工具,但它明确的将安全作为文化中的一部分进行了混合。 + +“在传统的环境中,这将花费数周或数月的停机时间来处理,因为开发、运维和安全三者是相互独立的”,Gerchow 说道,“通过一个 DevSecOps 的过程和习惯,终端用户可以通过简单的沟通和当日修复获得无缝的体验。” + +-------------------------------------------------------------------------------- + +via: https://enterprisersproject.com/article/2018/1/why-devsecops-matters-it-leaders + +作者:[Kevin Casey][a] +译者:[FelixYFZ](https://github.com/FelixYFZ) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://enterprisersproject.com/user/kevin-casey +[1]:https://enterprisersproject.com/tags/devops +[2]:https://www.datical.com/ +[3]:https://enterprisersproject.com/devops?sc_cid=70160000000h0aXAAQ +[4]:https://www.redhat.com/en?intcmp=701f2000000tjyaAAA +[5]:https://enterprisersproject.com/article/2017/10/what-s-next-devops-5-trends-watch +[6]:https://www.sumologic.com/ +[7]:https://www.cybric.io/ +[8]:https://www.sas.com/en_us/home.html +[9]:https://www.redhat.com/en/blog/what-are-meltdown-and-spectre-heres-what-you-need-know?intcmp=701f2000000tjyaAAA diff --git a/published/201807/20180126 Running a Python application on Kubernetes.md b/published/201807/20180126 Running a Python application on Kubernetes.md new file mode 100644 index 0000000000..a6b709a22c --- /dev/null +++ b/published/201807/20180126 Running a Python application on Kubernetes.md @@ -0,0 +1,276 @@ +在 Kubernetes 上运行一个 Python 应用程序 +============================================================ + +> 这个分步指导教程教你通过在 Kubernetes 上部署一个简单的 Python 应用程序来学习部署的流程。 + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/build_structure_tech_program_code_construction.png?itok=nVsiLuag) + +Kubernetes 是一个具备部署、维护和可伸缩特性的开源平台。它在提供可移植性、可扩展性以及自我修复能力的同时,简化了容器化 Python 应用程序的管理。 + +不论你的 Python 应用程序是简单还是复杂,Kubernetes 都可以帮你高效地部署和伸缩它们,在有限的资源范围内滚动升级新特性。 + +在本文中,我将描述在 Kubernetes 上部署一个简单的 Python 应用程序的过程,它包括: + +* 创建 Python 容器镜像 +* 发布容器镜像到镜像注册中心 +* 使用持久卷 +* 在 Kubernetes 上部署 Python 应用程序 + +### 必需条件 + +你需要 Docker、`kubectl` 以及这个 [源代码][10]。 + +Docker 是一个构建和承载已发布的应用程序的开源平台。可以参照 [官方文档][11] 去安装 Docker。运行如下的命令去验证你的系统上运行的 Docker: + +``` +$ docker info +Containers: 0 +Images: 289 +Storage Driver: aufs + Root Dir: /var/lib/docker/aufs + Dirs: 289 +Execution Driver: native-0.2 +Kernel Version: 3.16.0-4-amd64 +Operating System: Debian GNU/Linux 8 (jessie) +WARNING: No memory limit support +WARNING: No swap limit support +``` + +`kubectl` 是在 Kubernetes 集群上运行命令的一个命令行界面。运行下面的 shell 脚本去安装 `kubectl`: + +``` +curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl +``` + +部署到 Kubernetes 的应用要求必须是一个容器化的应用程序。我们来回顾一下 Python 应用程序的容器化过程。 + +### 一句话了解容器化 + +容器化是指将一个应用程序所需要的东西打包进一个自带操作系统的容器中。这种完整机器虚拟化的好处是,一个应用程序能够在任何机器上运行而无需考虑它的依赖项。 + +我们以 Roman Gaponov 的 [文章][12] 为参考,来为我们的 Python 代码创建一个容器。 + +### 创建一个 Python 容器镜像 + +为创建这些镜像,我们将使用 Docker,它可以让我们在一个隔离的 Linux 软件容器中部署应用程序。Docker 可以使用来自一个 Dockerfile 中的指令来自动化构建镜像。 + +这是我们的 Python 应用程序的 Dockerfile: + +``` +FROM python:3.6 +MAINTAINER XenonStack + +# Creating Application Source Code Directory +RUN mkdir -p /k8s_python_sample_code/src + +# Setting Home Directory for containers +WORKDIR /k8s_python_sample_code/src + +# Installing python dependencies +COPY requirements.txt /k8s_python_sample_code/src +RUN pip install --no-cache-dir -r requirements.txt + +# Copying src code to Container +COPY . /k8s_python_sample_code/src/app + +# Application Environment variables +ENV APP_ENV development + +# Exposing Ports +EXPOSE 5035 + +# Setting Persistent data +VOLUME ["/app-data"] + +# Running Python Application +CMD ["python", "app.py"] +``` + +这个 Dockerfile 包含运行我们的示例 Python 代码的指令。它使用的开发环境是 Python 3.5。 + +### 构建一个 Python Docker 镜像 + +现在,我们可以使用下面的这个命令按照那些指令来构建 Docker 镜像: + +``` +docker build -t k8s_python_sample_code . +``` + +这个命令为我们的 Python 应用程序创建了一个 Docker 镜像。 + +### 发布容器镜像 + +我们可以将我们的 Python 容器镜像发布到不同的私有/公共云仓库中,像 Docker Hub、AWS ECR、Google Container Registry 等等。本教程中我们将发布到 Docker Hub。 + +在发布镜像之前,我们需要给它标记一个版本号: + +``` +docker tag k8s_python_sample_code:latest k8s_python_sample_code:0.1 +``` + +### 推送镜像到一个云仓库 + +如果使用一个 Docker 注册中心而不是 Docker Hub 去保存镜像,那么你需要在你本地的 Docker 守护程序和 Kubernetes Docker 守护程序上添加一个容器注册中心。对于不同的云注册中心,你可以在它上面找到相关信息。我们在示例中使用的是 Docker Hub。 + +运行下面的 Docker 命令去推送镜像: + +``` +docker push k8s_python_sample_code +``` + +### 使用 CephFS 持久卷 + +Kubernetes 支持许多的持久存储提供商,包括 AWS EBS、CephFS、GlusterFS、Azure Disk、NFS 等等。我在示例中使用 CephFS 做为 Kubernetes 的持久卷。 + +为使用 CephFS 存储 Kubernetes 的容器数据,我们将创建两个文件: + +`persistent-volume.yml` : + +``` +apiVersion: v1 +kind: PersistentVolume +metadata: + name: app-disk1 + namespace: k8s_python_sample_code +spec: + capacity: + storage: 50Gi + accessModes: + - ReadWriteMany + cephfs: + monitors: + - "172.17.0.1:6789" + user: admin + secretRef: + name: ceph-secret + readOnly: false +``` + +`persistent_volume_claim.yaml`: + +``` +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: appclaim1 + namespace: k8s_python_sample_code +spec: + accessModes: + - ReadWriteMany + resources: + requests: + storage: 10Gi +``` + +现在,我们将使用 `kubectl` 去添加持久卷并声明到 Kubernetes 集群中: + +``` +$ kubectl create -f persistent-volume.yml +$ kubectl create -f persistent-volume-claim.yml +``` + +现在,我们准备去部署 Kubernetes。 + +### 在 Kubernetes 上部署应用程序 + +为管理部署应用程序到 Kubernetes 上的最后一步,我们将创建两个重要文件:一个服务文件和一个部署文件。 + +使用下列的内容创建服务文件,并将它命名为 `k8s_python_sample_code.service.yml`: + +``` +apiVersion: v1 +kind: Service +metadata: + labels: + k8s-app: k8s_python_sample_code + name: k8s_python_sample_code + namespace: k8s_python_sample_code +spec: + type: NodePort + ports: + - port: 5035 + selector: + k8s-app: k8s_python_sample_code +``` + +使用下列的内容创建部署文件并将它命名为 `k8s_python_sample_code.deployment.yml`: + +``` +apiVersion: extensions/v1beta1 +kind: Deployment +metadata: +  name: k8s_python_sample_code +  namespace: k8s_python_sample_code +spec: +  replicas: 1 +  template: +  metadata: +    labels: +    k8s-app: k8s_python_sample_code +  spec: +    containers: +    - name: k8s_python_sample_code +      image: k8s_python_sample_code:0.1 +      imagePullPolicy: "IfNotPresent" +      ports: +      - containerPort: 5035 +      volumeMounts: +        - mountPath: /app-data +          name: k8s_python_sample_code +     volumes:  +         - name: +           persistentVolumeClaim: +             claimName: appclaim1 +``` + +最后,我们使用 `kubectl` 将应用程序部署到 Kubernetes: + +``` +$ kubectl create -f k8s_python_sample_code.deployment.yml $ kubectl create -f k8s_python_sample_code.service.yml +``` + +现在,你的应用程序已经成功部署到 Kubernetes。 + +你可以通过检查运行的服务来验证你的应用程序是否在运行: + +``` +kubectl get services +``` + +或许 Kubernetes 可以解决未来你部署应用程序的各种麻烦! + + _想学习更多关于 Python 的知识?Nanjekye 的书,[和平共处的 Python 2 和 3][7] 提供了完整的方法,让你写的代码在 Python 2 和 3 上完美运行,包括如何转换已有的 Python 2 代码为能够可靠运行在 Python 2 和 3 上的代码的详细示例。_ + + +### 关于作者 + + [![](https://opensource.com/sites/default/files/styles/profile_pictures/public/pictures/joannah-nanjekye.jpg?itok=F4RqEjoA)][13] Joannah Nanjekye - Straight Outta 256,只要结果不问原因,充满激情的飞行员,喜欢用代码说话。[关于我的更多信息][8] + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/1/running-python-application-kubernetes + +作者:[Joannah Nanjekye][a] +译者:[qhwdw](https://github.com/qhwdw) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://opensource.com/users/nanjekyejoannah +[1]:https://opensource.com/resources/python?intcmp=7016000000127cYAAQ +[2]:https://opensource.com/resources/python/ides?intcmp=7016000000127cYAAQ +[3]:https://opensource.com/resources/python/gui-frameworks?intcmp=7016000000127cYAAQ +[4]:https://opensource.com/tags/python?intcmp=7016000000127cYAAQ +[5]:https://developers.redhat.com/?intcmp=7016000000127cYAAQ +[6]:https://opensource.com/article/18/1/running-python-application-kubernetes?rate=D9iKksKbd9q9vOVb92Mg-v0Iyqn0QVO5fbIERTbSHz4 +[7]:https://www.apress.com/gp/book/9781484229545 +[8]:https://opensource.com/users/nanjekyejoannah +[9]:https://opensource.com/user/196386/feed +[10]:https://github.com/jnanjekye/k8s_python_sample_code/tree/master +[11]:https://docs.docker.com/engine/installation/ +[12]:https://hackernoon.com/docker-tutorial-getting-started-with-python-redis-and-nginx-81a9d740d091 +[13]:https://opensource.com/users/nanjekyejoannah +[14]:https://opensource.com/users/nanjekyejoannah +[15]:https://opensource.com/users/nanjekyejoannah +[16]:https://opensource.com/tags/python +[17]:https://opensource.com/tags/kubernetes diff --git a/published/201807/20180128 Being open about data privacy.md b/published/201807/20180128 Being open about data privacy.md new file mode 100644 index 0000000000..d927af148d --- /dev/null +++ b/published/201807/20180128 Being open about data privacy.md @@ -0,0 +1,95 @@ +对数据隐私持开放的态度 +====== + +> 尽管有包括 GDPR 在内的法规,数据隐私对于几乎所有的人来说都是很重要的事情。 + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/GOV_opendata.png?itok=M8L2HGVx) + +今天(LCTT 译注:本文发表于 2018/1/28)是[数据隐私日][1]Data Privacy Day,(在欧洲叫“数据保护日Data Protection Day”),你可能会认为现在我们处于一个开源的世界中,所有的数据都应该是自由的,[就像人们想的那样][2],但是现实并没那么简单。主要有两个原因: + +1. 我们中的大多数(不仅仅是在开源中)认为至少有些关于我们自己的数据是不愿意分享出去的(我在之前发表的一篇文章中列举了一些例子[3]) +2. 我们很多人虽然在开源中工作,但事实上是为了一些商业公司或者其他一些组织工作,也是在合法的要求范围内分享数据。 + +所以实际上,数据隐私对于每个人来说是很重要的。 + +事实证明,在美国和欧洲之间,人们和政府认为让组织使用哪些数据的出发点是有些不同的。前者通常为商业实体(特别是愤世嫉俗的人们会指出是大型的商业实体)利用他们所收集到的关于我们的数据提供了更多的自由度。在欧洲,完全是另一观念,一直以来持有的多是有更多约束限制的观念,而且在 5 月 25 日,欧洲的观点可以说取得了胜利。 + +### 通用数据保护条例(GDPR)的影响 + +那是一个相当全面的声明,其实事实上这是 2016 年欧盟通过的一项称之为通用数据保护条例General Data Protection Regulation(GDPR)的立法的日期。数据通用保护条例在私人数据怎样才能被保存,如何才能被使用,谁能使用,能被持有多长时间这些方面设置了严格的规则。它描述了什么数据属于私人数据——而且涉及的条目范围非常广泛,从你的姓名、家庭住址到你的医疗记录以及接通你电脑的 IP 地址。 + +通用数据保护条例的重要之处是它并不仅仅适用于欧洲的公司,如果你是阿根廷人、日本人、美国人或者是俄罗斯的公司而且你正在收集涉及到欧盟居民的数据,你就要受到这个条例的约束管辖。 + +“哼!” 你可能会这样说^注1 ,“我的业务不在欧洲:他们能对我有啥约束?” 答案很简单:如果你想继续在欧盟做任何生意,你最好遵守,因为一旦你违反了通用数据保护条例的规则,你将会受到你的全球总收入百分之四的惩罚。是的,你没听错,是全球总收入,而不是仅仅在欧盟某一国家的的收入,也不只是净利润,而是全球总收入。这将会让你去叮嘱告知你的法律团队,他们就会知会你的整个团队,同时也会立即去指引你的 IT 团队,确保你的行为在相当短的时间内合规。 + +看上去这和非欧盟公民没有什么相关性,但其实不然,对大多数公司来说,对所有的他们的顾客、合作伙伴以及员工实行同样的数据保护措施是件既简单又有效的事情,而不是仅针对欧盟公民实施,这将会是一件很有利的事情。^注2 + +然而,数据通用保护条例不久将在全球实施并不意味着一切都会变的很美好^注3 :事实并非如此,我们一直在丢弃关于我们自己的信息——而且允许公司去使用它。 + +有一句话是这么说的(尽管很争议):“如果你没有在付费,那么你就是产品。”这句话的意思就是如果你没有为某一项服务付费,那么其他的人就在付费使用你的数据。你有付费使用 Facebook、推特、谷歌邮箱?你觉得他们是如何赚钱的?大部分是通过广告,一些人会争论那是他们向你提供的一项服务而已,但事实上是他们在利用你的数据从广告商里获取收益。你不是一个真正的广告的顾客——只有当你从看了广告后买了他们的商品之后你才变成了他们的顾客,但直到这个发生之前,都是广告平台和广告商的关系。 + +有些服务是允许你通过付费来消除广告的(流媒体音乐平台声破天就是这样的),但从另一方面来讲,即使你认为付费的服务也可以启用广告(例如,亚马逊正在努力让 Alexa 发广告),除非我们想要开始为这些所有的免费服务付费,我们需要清楚我们所放弃的,而且在我们暴露的和不想暴露的之间做一些选择。 + +### 谁是顾客? + +关于数据的另一个问题一直在困扰着我们,它是产生的数据量的直接结果。有许多组织一直在产生巨量的数据,包括公共的组织比如大学、医院或者是政府部门^注4 ——而且他们没有能力去储存这些数据。如果这些数据没有长久的价值也就没什么要紧的,但事实正好相反,随着处理大数据的工具正在开发中,而且这些组织也认识到他们现在以及在不久的将来将能够去挖掘这些数据。 + +然而他们面临的是,随着数据的增长和存储量无法跟上该怎么办。幸运的是——而且我是带有讽刺意味的使用了这个词^注5 ,大公司正在介入去帮助他们。“把你们的数据给我们,”他们说,“我们将免费保存。我们甚至让你随时能够使用你所收集到的数据!”这听起来很棒,是吗?这是大公司^注6 的一个极具代表性的例子,站在慈善的立场上帮助公共组织管理他们收集到的关于我们的数据。 + +不幸的是,慈善不是唯一的理由。他们是附有条件的:作为同意保存数据的交换条件,这些公司得到了将数据访问权限出售给第三方的权利。你认为公共组织,或者是被收集数据的人在数据被出售使用权使给第三方,以及在他们如何使用上能有发言权吗?我将把这个问题当做一个练习留给读者去思考。^注7 + +### 开放和积极 + +然而并不只有坏消息。政府中有一项在逐渐发展起来的“开放数据”运动鼓励各个部门免费开放大量他们的数据给公众或者其他组织。在某些情况下,这是专门立法的。许多志愿组织——尤其是那些接受公共资金的——正在开始这样做。甚至商业组织也有感兴趣的苗头。而且,有一些技术已经可行了,例如围绕不同的隐私和多方计算上,正在允许跨越多个数据集挖掘数据,而不用太多披露个人的信息——这个计算问题从未如现在比你想象的更容易。 + +这些对我们来说意味着什么呢?我之前在网站 Opensource.com 上写过关于[开源的共享福利][4],而且我越来越相信我们需要把我们的视野从软件拓展到其他区域:硬件、组织,和这次讨论有关的,数据。让我们假设一下你是 A 公司要提向另一家公司客户 B^注8 提供一项服务 。在此有四种不同类型的数据: + + 1. 数据完全开放:对 A 和 B 都是可得到的,世界上任何人都可以得到 + 2. 数据是已知的、共享的,和机密的:A 和 B 可得到,但其他人不能得到 + 3. 数据是公司级别上保密的:A 公司可以得到,但 B 顾客不能 + 4. 数据是顾客级别保密的:B 顾客可以得到,但 A 公司不能 + +首先,也许我们对数据应该更开放些,将数据默认放到选项 1 中。如果那些数据对所有人开放——在无人驾驶、语音识别,矿藏以及人口数据统计会有相当大的作用的。^注9 如果我们能够找到方法将数据放到选项 2、3 和 4 中,不是很好吗?——或者至少它们中的一些——在选项 1 中是可以实现的,同时仍将细节保密?这就是研究这些新技术的希望。 +然而有很长的路要走,所以不要太兴奋,同时,开始考虑将你的的一些数据默认开放。 + +### 一些具体的措施 + +我们如何处理数据的隐私和开放?下面是我想到的一些具体的措施:欢迎大家评论做出更多的贡献。 + + * 检查你的组织是否正在认真严格的执行通用数据保护条例。如果没有,去推动实施它。 + * 要默认加密敏感数据(或者适当的时候用散列算法),当不再需要的时候及时删掉——除非数据正在被处理使用,否则没有任何借口让数据清晰可见。 + * 当你注册了一个服务的时候考虑一下你公开了什么信息,特别是社交媒体类的。 + * 和你的非技术朋友讨论这个话题。 + * 教育你的孩子、你朋友的孩子以及他们的朋友。然而最好是去他们的学校和他们的老师谈谈在他们的学校中展示。 + * 鼓励你所服务和志愿贡献的组织,或者和他们沟通一些推动数据的默认开放。不是去思考为什么我要使数据开放,而是从我为什么不让数据开放开始。 + * 尝试去访问一些开源数据。挖掘使用它、开发应用来使用它,进行数据分析,画漂亮的图,^注10 制作有趣的音乐,考虑使用它来做些事。告诉组织去使用它们,感谢它们,而且鼓励他们去做更多。 + +**注:** + +1. 我承认你可能尽管不会。 +2. 假设你坚信你的个人数据应该被保护。 +3. 如果你在思考“极好的”的寓意,在这点上你并不孤独。 +4. 事实上这些机构能够有多开放取决于你所居住的地方。 +5. 假设我是英国人,那是非常非常大的剂量。 +6. 他们可能是巨大的公司:没有其他人能够负担得起这么大的存储和基础架构来使数据保持可用。 +7. 不,答案是“不”。 +8. 尽管这个例子也同样适用于个人。看看:A 可能是 Alice,B 可能是 BOb…… +9. 并不是说我们应该暴露个人的数据或者是这样的数据应该被保密,当然——不是那类的数据。 +10. 我的一个朋友当她接孩子放学的时候总是下雨,所以为了避免确认失误,她在整个学年都访问天气信息并制作了图表分享到社交媒体上。 + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/1/being-open-about-data-privacy + +作者:[Mike Bursell][a] +译者:[FelixYFZ](https://github.com/FelixYFZ) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://opensource.com/users/mikecamel +[1]:https://en.wikipedia.org/wiki/Data_Privacy_Day +[2]:https://en.wikipedia.org/wiki/Information_wants_to_be_free +[3]:https://aliceevebob.wordpress.com/2017/06/06/helping-our-governments-differently/ +[4]:https://opensource.com/article/17/11/commonwealth-open-source +[5]:http://www.outpost9.com/reference/jargon/jargon_40.html#TAG2036 diff --git a/translated/tech/20180228 Why Python devs should use Pipenv.md b/published/201807/20180228 Why Python devs should use Pipenv.md similarity index 54% rename from translated/tech/20180228 Why Python devs should use Pipenv.md rename to published/201807/20180228 Why Python devs should use Pipenv.md index 1e5d3dcd79..57a305f4b4 100644 --- a/translated/tech/20180228 Why Python devs should use Pipenv.md +++ b/published/201807/20180228 Why Python devs should use Pipenv.md @@ -1,101 +1,101 @@ 为什么 Python 开发人员应该使用 Pipenv ===== +> 只用了一年, Pipenv 就变成了管理软件包依赖关系的 Python 官方推荐资源。 + ![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/python-programming-code-keyboard.png?itok=fxiSpmnd) -这篇文章是与 [Jeff Triplett][1] 共同撰写的。 - -Pipenv 是由 Kenneth Reitz 在一年多前创建的“面向人类(to校正者:这里为人类感觉翻译为为开发者更好一点)而生的 Python 开发工作流”,它已经成为管理软件包依赖关系的[ Python 官方推荐资源][2]。但是对于它解决了什么问题,以及它如何比使用 `pip` 和 `requirements.txt` 文件的标准工作流更有用处,这两点仍然存在困惑。在本月的 Python 专栏中,我们将填补这些空白。 +Pipenv 是由 Kenneth Reitz 在一年多前创建的“面向开发者而生的 Python 开发工作流”,它已经成为管理软件包依赖关系的[ Python 官方推荐资源][2]。但是对于它解决了什么问题,以及它如何比使用 `pip` 和 `requirements.txt` 文件的标准工作流更有用处,这两点仍然存在困惑。在本月的 Python 专栏中,我们将填补这些空白。 ### Python 包安装简史 为了理解 Pipenv 所解决的问题,看一看 Python 包管理如何发展十分有用的。 -让我们回到第一个 Python 版本,我们有 Python,但是没有干净的方法来安装软件包。 +让我们回到第一个 Python 版本,这时我们有了 Python,但是没有干净的方法来安装软件包。 然后有了 [Easy Install][3],这是一个可以相对容易地安装其他 Python 包的软件包,但它也带来了一个问题:卸载不需要的包并不容易。 [pip][4] 登场,绝大多数 Python 用户都熟悉它。`pip` 可以让我们安装和卸载包。我们可以指定版本,运行 `pip freeze > requirements.txt` 来输出一个已安装包列表到一个文本文件,还可以用相同的文本文件配合 `pip install -r requirements.txt` 来安装一个应用程序需要的所有包。 -但是 `pip` 并没有包含将包彼此隔离的方法。我们可能会开发使用相同库的不同版本的应用程序,因此我们需要一种方法来实现这一点。随之而来的是[虚拟环境][5],它使我们能够为我们开发的每个应用程序创建一个小型的,隔离的环境。我们已经看到了许多管理虚拟环境的工具:[virtualenv][6], [venv][7], [virtualenvwrapper][8], [pyenv][9], [pyenv-virtualenv][10], [pyenv-virtualenvwrapper][11] 等等。它们都可以很好地使用 `pip` 和 `requirements.txt` 文件。 +但是 `pip` 并没有包含将软件包彼此隔离的方法。我们可能会开发使用相同库的不同版本的应用程序,因此我们需要一种方法来实现这一点。随之而来的是[虚拟环境][5],它使我们能够为我们开发的每个应用程序创建一个小型的、隔离的环境。我们已经看到了许多管理虚拟环境的工具:[virtualenv][6]、 [venv][7]、 [virtualenvwrapper][8]、 [pyenv][9]、 [pyenv-virtualenv][10]、 [pyenv-virtualenvwrapper][11] 等等。它们都可以很好地使用 `pip` 和 `requirements.txt` 文件。 ### 新方法:Pipenv Pipenv 旨在解决几个问题: -首先,问题是需要 `pip` 库来安装包,外加一个用于创建虚拟环境的库,以及用于管理虚拟环境的库,以及与这些库相关的所有命令。这些都需要管理。Pipenv 附带包管理和虚拟环境支持,因此你可以使用一个工具来安装、卸载、跟踪和记录依赖性,并创建、使用和组织你的虚拟环境。当你使用它启动一个项目时,如果你还没有使用它的话,Pipenv 将自动为该项目创建一个虚拟环境。 +首先,需要 `pip` 库来安装包,外加一个用于创建虚拟环境的库,以及用于管理虚拟环境的库,再有与这些库相关的所有命令。这些都需要管理。Pipenv 附带包管理和虚拟环境支持,因此你可以使用一个工具来安装、卸载、跟踪和记录依赖性,并创建、使用和组织你的虚拟环境。当你使用它启动一个项目时,如果你还没有使用虚拟环境的话,Pipenv 将自动为该项目创建一个虚拟环境。 -Pipenv 通过放弃 `requirements.txt` 规范转而将其移动到一个名为 [Pipfile][12] 的新文档中来完成这种依赖管理。当你使用 Pipenv 安装一个库时,项目的 `Pipfile` 会自动更新安装细节,包括版本信息,还有可能的 Git 仓库位置,文件路径和其他信息。 +Pipenv 通过放弃 `requirements.txt` 规范转而将其移动到一个名为 [Pipfile][12] 的新文档中来完成这种依赖管理。当你使用 Pipenv 安装一个库时,项目的 `Pipfile` 会自动更新安装细节,包括版本信息,还有可能的 Git 仓库位置、文件路径和其他信息。 -其次,Pipenv 希望能更容易地管理复杂的相互依赖关系。你的应用程序可能依赖于某个特定版本的库,而那个库可能依赖于另一个特定版本的库,而它只是依赖关系(to 校正者:这句话不太理解)。当你的应用程序使用的两个库有冲突的依赖关系时,你的情况会变得很艰难。Pipenv 希望通过在一个名为 `Pipfile.lock` 的文件中跟踪应用程序相互依赖关系树来减轻这种痛苦。`Pipfile.lock` 还会验证生产中是否使用了正确版本的依赖关系。 +其次,Pipenv 希望能更容易地管理复杂的相互依赖关系。你的应用程序可能依赖于某个特定版本的库,而那个库可能依赖于另一个特定版本的库,这些依赖关系如海龟般堆叠起来。当你的应用程序使用的两个库有冲突的依赖关系时,你的情况会变得很艰难。Pipenv 希望通过在一个名为 `Pipfile.lock` 的文件中跟踪应用程序相互依赖关系树来减轻这种痛苦。`Pipfile.lock` 还会验证生产中是否使用了正确版本的依赖关系。 -另外,当多个开发人员在开发一个项目时,Pipenv 很方便。通过 `pip` 工作流,Casey 可能会安装一个库,并花两天时间使用该库实现一个新功能。当 Casey 提交更改时,他可能会忘记运行 `pip freeze` 来更新 requirements 文件。第二天,Jamie 拉取 Casey 的变化,突然测试失败。这样会花费好一会儿才能意识到问题是在 requirements 文件中缺少相关库,而 Jamie 尚未在虚拟环境中安装这些文件。 +另外,当多个开发人员在开发一个项目时,Pipenv 很方便。通过 `pip` 工作流,凯西可能会安装一个库,并花两天时间使用该库实现一个新功能。当凯西提交更改时,他可能会忘记运行 `pip freeze` 来更新 `requirements.txt` 文件。第二天,杰米拉取凯西的改变,测试就突然失败了。这样会花费好一会儿才能意识到问题是在 `requirements.txt` 文件中缺少相关库,而杰米尚未在虚拟环境中安装这些文件。 -因为 Pipenv 会在安装时自动记录依赖性,如果 Jamie 和 Casey 使用了 Pipenv,`Pipfile` 会自动更新并包含在 Casey 的提交中。这样 Jamie 和 Casey 就可以节省时间并更快地运送他们的产品。 +因为 Pipenv 会在安装时自动记录依赖性,如果杰米和凯西使用了 Pipenv,`Pipfile` 会自动更新并包含在凯西的提交中。这样杰米和凯西就可以节省时间并更快地运送他们的产品。 -最后,将 Pipenv 推荐给在你项目上工作的其他人,因为它使用标准化的方式来安装项目依赖项,开发和测试需求。使用 `pip` 工作流和 requirements 文件意味着你可能只有一个 `requirements.txt` 文件,或针对不同环境的多个 requirements 文件。例如,你的同事可能不清楚他们是否应该在他们的笔记本电脑上运行项目时运行 `dev.txt` 还是 `local.txt`。当两个相似的 requirements 文件彼此不同步时它也会造成混淆:`local.txt` 是否过时了,还是真的应该与 `dev.txt` 不同?多个 requirements 文件需要更多的上下文和文档,以使其他人能够按照预期正确安装依赖关系。这个工作流程有可能会混淆同时并增加你的维护负担。 +最后,将 Pipenv 推荐给在你项目上工作的其他人,因为它使用标准化的方式来安装项目依赖项和开发和测试的需求。使用 `pip` 工作流和 `requirements.txt` 文件意味着你可能只有一个 `requirements.txt` 文件,或针对不同环境的多个 `requirements.txt` 文件。例如,你的同事可能不清楚他们是否应该在他们的笔记本电脑上运行项目时是运行 `dev.txt` 还是 `local.txt`。当两个相似的 `requirements.txt` 文件彼此不同步时它也会造成混淆:`local.txt` 是否过时了,还是真的应该与 `dev.txt` 不同?多个 `requirements.txt` 文件需要更多的上下文和文档,以使其他人能够按照预期正确安装依赖关系。这个工作流程有可能会混淆同时并增加你的维护负担。 使用 Pipenv,它会生成 `Pipfile`,通过为你管理对不同环境的依赖关系,可以避免这些问题。该命令将安装主项目依赖项: + ``` pipenv install - ``` -添加 `--dev` 标志将安装 dev/testing requirements: +添加 `--dev` 标志将安装开发/测试的 `requirements.txt`: + ``` pipenv install --dev - ``` 使用 Pipenv 还有其他好处:它具有更好的安全特性,以易于理解的格式绘制你的依赖关系,无缝处理 `.env` 文件,并且可以在一个文件中自动处理开发与生产环境的不同依赖关系。你可以在[文档][13]中阅读更多内容。 -### Pipenv 行动 +### 使用 Pipenv 使用 Pipenv 的基础知识在官方 Python 包管理教程[管理应用程序依赖关系][14]部分中详细介绍。要安装 Pipenv,使用 `pip`: + ``` pip install pipenv - ``` 要安装在项目中使用的包,请更改为项目的目录。然后安装一个包(我们将使用 Django 作为例子),运行: + ``` pipenv install django - ``` 你会看到一些输出,表明 Pipenv 正在为你的项目创建一个 `Pipfile`。 如果你还没有使用虚拟环境,你还会看到 Pipenv 的一些输出,说明它正在为你创建一个虚拟环境。 -然后,你将看到你在安装包时习惯看到的输出。 +然后,你将看到你在安装包时常看到的输出。 为了生成 `Pipfile.lock` 文件,运行: + ``` pipenv lock - ``` -你也可以使用 Pipenv 运行 Python 脚本。运行名为 `hello.py` 的(to 校正者:这里 top-level该怎么翻译)Python 脚本: +你也可以使用 Pipenv 运行 Python 脚本。运行名为 `hello.py` 的上层 Python 脚本: + ``` pipenv run python hello.py - ``` 你将在控制台中看到预期结果。 启动一个 shell,运行: + ``` pipenv shell - ``` 如果你想将当前使用 `requirements.txt` 文件的项目转换为使用 Pipenv,请安装 Pipenv 并运行: + ``` pipenv install requirements.txt - ``` -这将创建一个 Pipfile 并安装指定的 requirements。考虑一下升级你的项目! +这将创建一个 Pipfile 并安装指定的 `requirements.txt`。考虑一下升级你的项目! ### 了解更多 @@ -106,9 +106,9 @@ pipenv install requirements.txt via: https://opensource.com/article/18/2/why-python-devs-should-use-pipenv -作者:[Lacey Williams Henschel][a] +作者:[Lacey Williams Henschel][a], [Jeff Triplett][1] 译者:[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/) 荣誉推出 diff --git a/translated/tech/20180301 The Cost of Cloud Computing.md b/published/201807/20180301 The Cost of Cloud Computing.md similarity index 68% rename from translated/tech/20180301 The Cost of Cloud Computing.md rename to published/201807/20180301 The Cost of Cloud Computing.md index c61783d9bc..3734751dfa 100644 --- a/translated/tech/20180301 The Cost of Cloud Computing.md +++ b/published/201807/20180301 The Cost of Cloud Computing.md @@ -1,8 +1,7 @@ 云计算的成本 ============================================================ -### 两个开发团队的一天 - +> 两个开发团队的一天 ![](https://cdn-images-1.medium.com/max/2000/1*nBZJgNXl54jzFKa91s1KfQ.png) @@ -12,103 +11,108 @@ 这两个团队被要求为一家全球化企业开发一个新的服务,该企业目前为全球数百万消费者提供服务。要开发的这项新服务需要满足以下基本需求: -1. 能够随时扩展以满足弹性需求 - -2. 具备应对数据中心故障的弹性 - -3. 确保数据安全以及数据受到保护 - -4. 为排错提供深入的调试功能 - -5. 项目必须能迅速分发 - -6. 服务构建和维护的性价比要高 +1. 能够随时**扩展**以满足弹性需求 +2. 具备应对数据中心故障的**弹性** +3. 确保数据**安全**以及数据受到保护 +4. 为排错提供深入的**调试**功能 +5. 项目必须能**迅速分发** +6. 服务构建和维护的**性价比**要高 就新服务来说,这看起来是非常标准的需求 — 从本质上看传统专用基础设备上没有什么东西可以超越公共云了。 ![](https://cdn-images-1.medium.com/max/1600/1*DgnAPA6P5R0yQiV8n6siJw.png) -* * * - #### 1 — 扩展以满足客户需求 当说到可扩展性时,这个新服务需要去满足客户变化无常的需求。我们构建的服务不可以拒绝任何请求,以防让公司遭受损失或者声誉受到影响。 -传统的团队使用的是专用基础设施,架构体系的计算能力需要与峰值数据需求相匹配。对于负载变化无常的服务来说,大量昂贵的计算能力在低利用率的时间被浪费掉。 +**传统团队** + +使用的是专用基础设施,架构体系的计算能力需要与峰值数据需求相匹配。对于负载变化无常的服务来说,大量昂贵的计算能力在低利用率时被浪费掉。 这是一种很浪费的方法  —  并且大量的资本支出会侵蚀掉你的利润。另外,这些未充分利用的庞大的服务器资源的维护也是一项很大的运营成本。这是一项你无法忽略的成本  —  我不得不再强调一下,为支持一个单一服务去维护一机柜的服务器是多么的浪费时间和金钱。 -云团队使用的是基于云的自动伸缩解决方案,应用会按需要进行自动扩展和收缩。也就是说你只需要支付你所消费的计算资源的费用。 +**云团队** + +使用的是基于云的自动伸缩解决方案,应用会按需要进行自动扩展和收缩。也就是说你只需要支付你所消费的计算资源的费用。 一个架构良好的基于云的应用可以实现无缝地伸缩 —  并且还是自动进行的。开发团队只需要定义好自动伸缩的资源组即可,即当你的应用 CPU 利用率达到某个高位、或者每秒有多大请求数时启动多少实例,并且你可以根据你的意愿去定制这些规则。 -* * * - #### 2 — 应对故障的弹性 -当说到弹性时,将托管服务的基础设施放在同一个房间里并不是一个好的选择。如果你的应用托管在一个单一的数据中心  —  (不是如果)发生某些失败时(译者注:指坍塌、地震、洪灾等),你的所有的东西都被埋了。 +当说到弹性时,将托管服务的基础设施放在同一个房间里并不是一个好的选择。如果你的应用托管在一个单一的数据中心  —  (不是如果)发生某些失败时(LCTT 译注:指坍塌、地震、洪灾等),你的所有的东西都被埋了。 -传统的团队去满足这种基本需求的标准解决方案是,为实现局部弹性建立至少两个服务器  —  在地理上冗余的数据中心之间实施秒级复制。 +**传统团队** -开发团队需要一个负载均衡解决方案,以便于在发生饱合或者故障等事件时将流量转向到另一个节点  —  并且还要确保镜像节点之间,整个栈是持续完全同步的。 +满足这种基本需求的标准解决方案是,为实现局部弹性建立至少两个服务器  —  在地理上冗余的数据中心之间实施秒级复制。 -在全球 50 个区域中的每一个云团队,都由 AWS 提供多个_有效区域_。每个区域由多个容错数据中心组成  —  通过自动故障切换功能,AWS 可以在区域内将服务无缝地转移到其它的区中。 +开发团队需要一个负载均衡解决方案,以便于在发生饱和或者故障等事件时将流量转向到另一个节点  —  并且还要确保镜像节点之间,整个栈是持续完全同步的。 + +**云团队** + +在 AWS 全球 50 个地区中,他们都提供多个_可用区_。每个区域由多个容错数据中心组成  —  通过自动故障切换功能,AWS 可以将服务无缝地转移到该地区的其它区中。 在一个 `CloudFormation` 模板中定义你的_基础设施即代码_,确保你的基础设施在自动伸缩事件中跨区保持一致 — 而对于流量的流向管理,AWS 负载均衡服务仅需要做很少的配置即可。 -* * * - #### 3 — 安全和数据保护 安全是一个组织中任何一个系统的基本要求。我想你肯定不想成为那些不幸遭遇安全问题的公司之一的。 -传统团队为保证运行他们服务的基础服务器安全,他们不得不持续投入成本。这意味着将不得不向监视、识别、以及为来自不同数据源的跨多个供应商解决方案的安全威胁打补丁的团队上投资。 +**传统团队** -使用公共云的团队并不能免除来自安全方面的责任。云团队仍然需要提高警惕,但是并不需要去担心为底层基础设施打补丁的问题。AWS 将积极地对付各种 0 日漏洞 — 最近的一次是 Spectre 和 Meltdown。 +为保证运行他们服务的基础服务器安全,他们不得不持续投入成本。这意味着将需要投资一个团队,以监视和识别安全威胁,并用来自不同数据源的跨多个供应商解决方案打上补丁。 -利用来自 AWS 的识别管理和加密安全服务,可以让云团队专注于他们的应用 —  而不是无差别的安全管理。使用 `CloudTrail` 对 API 到 AWS 服务的调用做全面审计,可以实现透明地监视。 +**云团队** -* * * +使用公共云并不能免除来自安全方面的责任。云团队仍然需要提高警惕,但是并不需要去担心为底层基础设施打补丁的问题。AWS 将积极地对付各种零日漏洞 — 最近的一次是 Spectre 和 Meltdown。 + +利用来自 AWS 的身份管理和加密安全服务,可以让云团队专注于他们的应用 —  而不是无差别的安全管理。使用 CloudTrail 对 API 到 AWS 服务的调用做全面审计,可以实现透明地监视。 #### 4 — 监视和日志 任何基础设施和部署为服务的应用都需要严密监视实时数据。团队应该有一个可以访问的仪表板,当超过指标阈值时仪表板会显示警报,并能够在排错时提供与事件相关的日志。 -使用传统基础设施的传统团队,将不得不在跨不同供应商和“雪花状”的解决方案上配置监视和报告解决方案。配置这些“见鬼的”解决方案将花费你大量的时间和精力 —  并且能够正确地实现你的目的是相当困难的。 +**传统团队** + +对于传统基础设施,将不得不在跨不同供应商和“雪花状”的解决方案上配置监视和报告解决方案。配置这些“见鬼的”解决方案将花费你大量的时间和精力 —  并且能够正确地实现你的目的是相当困难的。 对于大多数部署在专用基础设施上的应用来说,为了搞清楚你的应用为什么崩溃,你可以通过搜索保存在你的服务器文件系统上的日志文件来找到答案。为此你的团队需要通过 SSH 进入服务器,导航到日志文件所在的目录,然后浪费大量的时间,通过 `grep` 在成百上千的日志文件中寻找。如果你在一个横跨 60 台服务器上部署的应用中这么做  —  我能负责任地告诉你,这是一个极差的解决方案。 -云团队利用原生的 AWS 服务,如 CloudWatch 和 CloudTrail,来做云应用程序的监视是非常容易。不需要很多的配置,开发团队就可以监视部署的服务上的各种指标 — 问题的排除过程也不再是个恶梦了。 +**云团队** + +利用原生的 AWS 服务,如 CloudWatch 和 CloudTrail,来做云应用程序的监视是非常容易。不需要很多的配置,开发团队就可以监视部署的服务上的各种指标  —  问题的排除过程也不再是个恶梦了。 对于传统的基础设施,团队需要构建自己的解决方案,配置他们的 REST API 或者服务去推送日志到一个聚合器。而得到这个“开箱即用”的解决方案将对生产力有极大的提升。 -* * * - #### 5 — 加速开发进程 -现在的商业环境中,快速上市的能力越来越重要。由于实施延误所失去的机会成本,可能成为影响最终利润的一个主要因素。 +现在的商业环境中,快速上市的能力越来越重要。由于实施的延误所失去的机会成本,可能成为影响最终利润的一个主要因素。 -大多数组织的这种传统团队,他们需要在新项目所需要的硬件采购、配置和部署上花费很长的时间 — 并且由于预测能力差,提前获得的额外的性能将造成大量的浪费。 +**传统团队** + +对于大多数组织,他们需要在新项目所需要的硬件采购、配置和部署上花费很长的时间 — 并且由于预测能力差,提前获得的额外的性能将造成大量的浪费。 而且还有可能的是,传统的开发团队在无数的“筒仓”中穿梭以及在移交创建的服务上花费数月的时间。项目的每一步都会在数据库、系统、安全、以及网络管理方面需要一个独立工作。 +**云团队** + 而云团队开发新特性时,拥有大量的随时可投入生产系统的服务套件供你使用。这是开发者的天堂。每个 AWS 服务一般都有非常好的文档并且可以通过你选择的语言以编程的方式去访问。 使用新的云架构,例如无服务器,开发团队可以在最小化冲突的前提下构建和部署一个可扩展的解决方案。比如,只需要几天时间就可以建立一个 [Imgur 的无服务器克隆][4],它具有图像识别的特性,内置一个产品级的监视/日志解决方案,并且它的弹性极好。 ![](https://cdn-images-1.medium.com/max/1600/1*jHmtrp1OKM4mZVn-gSNoQg.png) -如果必须要我亲自去设计弹性和可伸缩性,我可以向你保证,我仍然在开发这个项目 — 而且最终的产品将远不如目前的这个好。 +*如何建立一个 Imgur 的无服务器克隆* + +如果必须要我亲自去设计弹性和可伸缩性,我可以向你保证,我会陷在这个项目的开发里 — 而且最终的产品将远不如目前的这个好。 从我实践的情况来看,使用无服务器架构的交付时间远小于在大多数公司中提供硬件所花费的时间。我只是简单地将一系列 AWS 服务与 Lambda 功能 — 以及 ta-da 耦合到一起而已!我只专注于开发解决方案,而无差别的可伸缩性和弹性是由 AWS 为我处理的。 -* * * - #### 关于云计算成本的结论 就弹性而言,云计算团队的按需扩展是当之无愧的赢家 — 因为他们仅为需要的计算能力埋单。而不需要为维护和底层的物理基础设施打补丁付出相应的资源。 -云计算也为开发团队提供一个可使用多个有效区的弹性架构、为每个服务构建的安全特性、持续的日志和监视工具、随用随付的服务、以及低成本的加速分发实践。 +云计算也为开发团队提供一个可使用多个可用区的弹性架构、为每个服务构建的安全特性、持续的日志和监视工具、随用随付的服务、以及低成本的加速分发实践。 大多数情况下,云计算的成本要远低于为你的应用运行所需要的购买、支持、维护和设计的按需基础架构的成本 —  并且云计算的麻烦事更少。 @@ -116,17 +120,17 @@ 也有一些云计算比传统基础设施更昂贵的例子,一些情况是在周末忘记关闭运行的一些极其昂贵的测试机器。 -[Dropbox 在决定推出自己的基础设施并减少对 AWS 服务的依赖之后,在两年的时间内节省近 7500 万美元的费用,Dropbox…www.geekwire.com][5][][6] +[Dropbox 在决定推出自己的基础设施并减少对 AWS 服务的依赖之后,在两年的时间内节省近 7500 万美元的费用,Dropbox…——www.geekwire.com][5][][6] 即便如此,这样的案例仍然是非常少见的。更不用说当初 Dropbox 也是从 AWS 上开始它的业务的  —  并且当它的业务达到一个临界点时,才决定离开这个平台。即便到现在,他们也已经进入到云计算的领域了,并且还在 AWS 和 GCP 上保留了 40% 的基础设施。 -将云服务与基于单一“成本”指标(译者注:此处的“成本”仅指物理基础设施的购置成本)的传统基础设施比较的想法是极其幼稚的  —  公然无视云为开发团队和你的业务带来的一些主要的优势。 +将云服务与基于单一“成本”指标(LCTT 译注:此处的“成本”仅指物理基础设施的购置成本)的传统基础设施比较的想法是极其幼稚的  —  公然无视云为开发团队和你的业务带来的一些主要的优势。 -在极少数的情况下,云服务比传统基础设施产生更多的绝对成本  —  它在开发团队的生产力、速度和创新方面仍然贡献着更好的价值。 +在极少数的情况下,云服务比传统基础设施产生更多的绝对成本  —  但它在开发团队的生产力、速度和创新方面仍然贡献着更好的价值。 ![](https://cdn-images-1.medium.com/max/1600/1*IlrOdfYiujggbsYynTzzEQ.png) -客户才不在乎你的数据中心呢 +*客户才不在乎你的数据中心呢* _我非常乐意倾听你在云中开发的真实成本相关的经验和反馈!请在下面的评论区、Twitter  _ [_@_ _Elliot_F_][7] 上、或者直接在 _ [_LinkedIn_][8] 上联系我。 @@ -136,7 +140,7 @@ via: https://read.acloud.guru/the-true-cost-of-cloud-a-comparison-of-two-develop 作者:[Elliot Forbes][a] 译者:[qhwdw](https://github.com/qhwdw) -校对:[校对者ID](https://github.com/校对者ID) +校对:[wxy](https://github.com/wxy) 本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 diff --git a/translated/tech/20180302 5 open source software tools for supply chain management.md b/published/201807/20180302 5 open source software tools for supply chain management.md similarity index 56% rename from translated/tech/20180302 5 open source software tools for supply chain management.md rename to published/201807/20180302 5 open source software tools for supply chain management.md index 8ead3394de..3c000a2717 100644 --- a/translated/tech/20180302 5 open source software tools for supply chain management.md +++ b/published/201807/20180302 5 open source software tools for supply chain management.md @@ -1,23 +1,25 @@ 供应链管理方面的 5 个开源软件工具 ====== +> 跟踪您的库存和您需要的材料,用这些供应链管理工具制造产品。 + ![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/BIZ_Maze2.png?itok=EH_L-J6Q) 本文最初发表于 2016 年 1 月 14 日,最后的更新日期为 2018 年 3 月 2 日。 -如果你正在管理着处理实体货物的业务,[供应链管理][1] 是你的业务流程中非常重要的一部分。不论你是经营着一个只有几个客户的小商店,还是在世界各地拥有数百万计客户和成千上万产品的世界财富 500 强的制造商或零售商,很清楚地知道你的库存和制造产品所需要的零部件,对你来说都是非常重要的事情。 +如果你正在管理着处理实体货物的业务,[供应链管理][1] 是你的业务流程中非常重要的一部分。不论你是经营着一个只有几个客户的小商店,还是在世界各地拥有数以百万计客户和成千上万产品的世界财富 500 强的制造商或零售商,很清楚地知道你的库存和制造产品所需要的零部件,对你来说都是非常重要的事情。 -保持对货品、供应商、客户的持续跟踪,并且所有与它们相关的变动部分都会从中受益,并且,在某些情况下完全依赖专门的软件来帮助管理这些工作流。在本文中,我们将去了解一些免费的和开源的供应链管理方面的软件,以及它们的其中一些功能。 +保持对货品、供应商、客户的持续跟踪,而且所有与它们相关的变动部分都会受益于这些用来帮助管理工作流的专门软件,而在某些情况下需要完全依赖这些软件。在本文中,我们将去了解一些自由及开源的供应链管理方面的软件,以及它们的其中一些功能。 -供应链管理比单纯的库存管理更为强大。它能帮你去跟踪货物流以降低成本,以及为可能发生的各种糟糕的变化来制定应对计划。它能够帮你对出口合规性进行跟踪,不论是合法性、最低品质要求、还是社会和环境的合规性。它能够帮你计划最低供应量,让你能够在订单数量和交付时间之间做出明智的决策。 +供应链管理比单纯的库存管理更为强大。它能帮你去跟踪货物流以降低成本,以及为可能发生的各种糟糕的变化来制定应对计划。它能够帮你对出口合规性进行跟踪,不论是否是出于法律要求、最低品质要求、还是社会和环境责任。它能够帮你计划最低供应量,让你能够在订单数量和交付时间之间做出明智的决策。 -由于它的本质决定了许多供应链管理软件是与类似的软件捆绑在一起的,比如,[客户关系管理][2](CRM)和 [企业资源计划管理][3] (ERP)。因此,当你选择哪个工具更适合你的组织时,你可能会考虑与其它工具集成作为你的决策依据之一。 +由于其本质决定了许多供应链管理软件是与类似的软件捆绑在一起的,比如,[客户关系管理][2](CRM)和 [企业资源计划管理][3] (ERP)。因此,当你选择哪个工具更适合你的组织时,你可能会考虑与其它工具集成作为你的决策依据之一。 ### Apache OFBiz -[Apache OFBiz][4] 是一套帮你管理多种业务流程的相关工具。虽然它能管理多种相关问题,比如,目录、电子商务网站、帐户、和销售点,它在供应链管理方面的主要功能关注于仓库管理、履行、订单、和生产管理。它的可定制性很强,但是,它需要大量的规划去设置和集成到你现有的流程中。这就是它适用于中大型业务的原因之一。项目的功能构建于三个层面:展示层、业务层、和数据层,它是一个弹性很好的解决方案,但是,再强调一遍,它也很复杂。 +[Apache OFBiz][4] 是一套帮你管理多种业务流程的相关工具。虽然它能管理多种相关问题,比如,分类、电子商务网站、会计和 POS,它在供应链管理方面的主要功能关注于仓库管理、履行、订单和生产管理。它的可定制性很强,但是,对应的它需要大量的规划去设置和集成到你现有的流程中。这就是它适用于中大型业务的原因之一。项目的功能构建于三个层面:展示层、业务层和数据层,它是一个弹性很好的解决方案,但是,再强调一遍,它也很复杂。 -Apache OFBiz 的源代码在 [项目仓库][5] 中可以找到。Apache OFBiz 是用 Java 写的,并且它是按 [Apache 2.0 license][6] 授权的。 +Apache OFBiz 的源代码在其 [项目仓库][5] 中可以找到。Apache OFBiz 是用 Java 写的,并且它是按 [Apache 2.0 许可证][6] 授权的。 如果你对它感兴趣,你也可以去查看 [opentaps][7],它是在 OFBiz 之上构建的。Opentaps 强化了 OFBiz 的用户界面,并且添加了 ERP 和 CRM 的核心功能,包括仓库管理、采购和计划。它是按 [AGPL 3.0][8] 授权使用的,对于不接受开源授权的组织,它也提供了商业授权。 @@ -25,25 +27,25 @@ Apache OFBiz 的源代码在 [项目仓库][5] 中可以找到。Apache OFBiz [OpenBoxes][9] 是一个供应链管理和存货管理项目,最初的主要设计目标是为了医疗行业中的药品跟踪管理,但是,它可以通过修改去跟踪任何类型的货品和相关的业务流。它有一个需求预测工具,可以基于历史订单数量、存储跟踪、支持多种场所、过期日期跟踪、销售点支持等进行预测,并且它还有许多其它功能,这使它成为医疗行业的理想选择,但是,它也可以用于其它行业。 -它在 [Eclipse Public License][10] 下可用,OpenBoxes 主要是由 Groovy 写的,它的源代码可以在 [GitHub][11] 上看到。 +它在 [Eclipse 公开许可证][10] 下可用,OpenBoxes 主要是由 Groovy 写的,它的源代码可以在 [GitHub][11] 上看到。 ### OpenLMIS -与 OpenBoxes 类似,[OpenLMIS][12] 也是一个医疗行业的供应链管理工具,但是,它专用设计用于在非洲的资源缺乏地区使用,以确保有限的药物和医疗用品能够用到需要的病人上。它是 API 驱动的,这样用户可以去定制和扩展 OpenLMIS,同时还能维护一个与通用基准代码的连接。它是由络克菲勒基金会开发的,其它的贡献者包括联合国、美国国际开发署、和比尔 & 梅林达 盖茨基金会。 +与 OpenBoxes 类似,[OpenLMIS][12] 也是一个医疗行业的供应链管理工具,但是,它专用设计用于在非洲的资源缺乏地区使用,以确保有限的药物和医疗用品能够用到需要的病人上。它是 API 驱动的,这样用户可以去定制和扩展 OpenLMIS,同时还能维护一个与通用基准代码的连接。它是由洛克菲勒基金会开发的,其它的贡献者包括联合国、美国国际开发署、和比尔 & 梅林达·盖茨基金会。 -OpenLMIS 是用 Java 和 JavaScript 的 AngularJS 写的。它在 [AGPL 3.0 license][13] 下使用,它的源代码在 [GitHub][13] 上可以找到。 +OpenLMIS 是用 Java 和 JavaScript 的 AngularJS 写的。它在 [AGPL 3.0 许可证][13] 下使用,它的源代码在 [GitHub][13] 上可以找到。 ### Odoo -你可能在我们以前的 [ERP 项目][3] 榜的文章上见到过 [Odoo][14]。事实上,根据你的需要,一个全功能的 ERP 对你来说是最适合的。Odoo 的供应链管理工具主要围绕存货和采购管理,同时还与电子商务网站和销售点连接,但是,它也可以与其它的工具连接,比如,与 [frePPLe][15] 连接,它是一个开源的生产计划工具。 +你可能在我们以前的 [ERP 项目][3] 榜的文章上见到过 [Odoo][14]。事实上,根据你的需要,一个全功能的 ERP 对你来说是最适合的。Odoo 的供应链管理工具主要围绕存货和采购管理,同时还与电子商务网站和 POS 连接,但是,它也可以与其它的工具连接,比如,与 [frePPLe][15] 连接,它是一个开源的生产计划工具。 -Odoo 既有软件即服务的解决方案,也有开源的社区版本。开源的版本是以 [LGPL][16] 版本 3 下发行的,源代码在 [GitHub][17] 上可以找到。Odoo 主要是用 Python 来写的。 +Odoo 既有软件即服务(SaaS)的解决方案,也有开源的社区版本。开源的版本是以 [LGPL][16] 版本 3 下发行的,源代码在 [GitHub][17] 上可以找到。Odoo 主要是用 Python 来写的。 ### xTuple -[xTuple][18] 标称自己是“为成长中的企业提供供应链管理软件”,它专注于已经超越了传统的小型企业 ERP 和 CRM 解决方案的企业。它的开源版本称为 Postbooks,添加了一些存货、分销、采购、以及供应商报告的功能,它提供的核心功能是帐务、CRM、以及 ERP 功能,而它的商业版本扩展了制造和分销的 [功能][19]。 +[xTuple][18] 标称自己是“为成长中的企业提供供应链管理软件”,它专注于已经超越了其传统的小型企业 ERP 和 CRM 解决方案的企业。它的开源版本称为 Postbooks,添加了一些存货、分销、采购、以及供应商报告的功能,它提供的核心功能是会计、CRM、以及 ERP 功能,而它的商业版本扩展了制造和分销的 [功能][19]。 -xTuple 在 [CPAL][20] 下使用,这个项目欢迎开发者去 fork 它,为基于存货的制造商去创建其它的业务软件。它的 Web 应用核心是用 JavaScript 写的,它的源代码在 [GitHub][21] 上可以找到。 +xTuple 在 [CPAL][20] 下使用,这个项目欢迎开发者去复刻它,为基于存货的制造商去创建其它的业务软件。它的 Web 应用核心是用 JavaScript 写的,它的源代码在 [GitHub][21] 上可以找到。 就这些,当然了,还有其它的可以帮你处理供应链管理的开源软件。如果你知道还有更好的软件,请在下面的评论区告诉我们。 @@ -53,14 +55,14 @@ via: https://opensource.com/tools/supply-chain-management 作者:[Jason Baker][a] 译者:[qhwdw](https://github.com/qhwdw) -校对:[校对者ID](https://github.com/校对者ID) +校对:[wxy](https://github.com/wxy) 本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 [a]:https://opensource.com/users/jason-baker [1]:https://en.wikipedia.org/wiki/Supply_chain_management [2]:https://opensource.com/business/14/7/top-5-open-source-crm-tools -[3]:https://opensource.com/resources/top-4-open-source-erp-systems +[3]:https://linux.cn/article-9785-1.html [4]:http://ofbiz.apache.org/ [5]:http://ofbiz.apache.org/source-repositories.html [6]:http://www.apache.org/licenses/LICENSE-2.0 diff --git a/published/201807/20180305 What-s next in IT automation- 6 trends to watch.md b/published/201807/20180305 What-s next in IT automation- 6 trends to watch.md new file mode 100644 index 0000000000..d907efbf41 --- /dev/null +++ b/published/201807/20180305 What-s next in IT automation- 6 trends to watch.md @@ -0,0 +1,132 @@ +IT 自动化的下一步是什么: 6 大趋势 +====== + +> 自动化专家分享了一点对 [自动化][6]不远的将来的看法。请将这些保留在你的视线之内。 + +![](https://enterprisersproject.com/sites/default/files/styles/620x350/public/cio_ai_artificial_intelligence.png?itok=o0csm9l2) + +我们最近讨论了 [推动 IT 自动化的因素][1],可以看到[当前趋势][2]正在增长,以及那些给刚开始使用自动化部分流程的组织的 [有用的技巧][3] 。 + +噢,我们也分享了如何在贵公司[进行自动化的案例][4]及 [长期成功的关键][5]的专家建议。 + +现在,只有一个问题:自动化的下一步是什么? 我们邀请一系列专家分享一下 [自动化][6]不远的将来的看法。 以下是他们建议 IT 领域领导需密切关注的六大趋势。 + +### 1、 机器学习的成熟 + +对于关于 [机器学习][7](与“自我学习系统”相似的定义)的讨论,对于绝大多数组织的项目来说,实际执行起来它仍然为时过早。但预计这将发生变化,机器学习将在下一次 IT 自动化浪潮中将扮演着至关重要的角色。 + +[Advanced Systems Concepts, Inc.][8] 公司的工程总监 Mehul Amin 指出机器学习是 IT 自动化下一个关键增长领域之一。 + +“随着数据化的发展,自动化软件理应可以自我决策,否则这就是开发人员的责任了”,Amin 说。 “例如,开发者构建了需要执行的内容,但通过使用来自系统内部分析的软件,可以确定执行该流程的最佳系统。” + +假设将这个系统延伸到其他地方中。Amin 指出,机器学习可以使自动化系统在必要的时候提供额外的资源,以需要满足时间线或 SLA,同样在不需要资源以及其他的可能性的时候退出。 + +显然不只有 Amin 一个人这样认为。 + +“IT 自动化正在走向自我学习的方向” ,[Sungard Availability Services][9] 公司首席架构师 Kiran Chitturi 表示,“系统将会能测试和监控自己,加强业务流程和软件交付能力。” + +Chitturi 指出自动化测试就是个例子。脚本测试已经被广泛采用,但很快这些自动化测试流程将会更容易学习,更快发展,例如开发出新的代码或将更为广泛地影响生产环境。 + +### 2、 人工智能催生的自动化 + +上述原则同样适合与相关的(但是独立的) [人工智能][10]的领域。根据对人工智能的定义,机器学习在短时间内可能会对 IT 领域产生巨大的影响(并且我们可能会看到这两个领域的许多重叠的定义和理解)。假定新兴的人工智能技术将也会产生新的自动化机会。 + +[SolarWinds][11] 公司技术负责人 Patrick Hubbard 说,“人工智能和机器学习的整合普遍被认为对未来几年的商业成功起至关重要的作用。” + +### 3、 这并不意味着不再需要人力 + +让我们试着安慰一下那些不知所措的人:前两种趋势并不一定意味着我们将失去工作。 + +这很可能意味着各种角色的改变,以及[全新角色][12]的创造。 + +但是在可预见的将来,至少,你不必需要对机器人鞠躬。 + +“一台机器只能运行在给定的环境变量中——它不能选择包含新的变量,在今天只有人类可以这样做,” Hubbard 解释说。“但是,对于 IT 专业人员来说,这将需要培养 AI 和自动化技能,如对程序设计、编程、管理人工智能和机器学习功能算法的基本理解,以及用强大的安全状态面对更复杂的网络攻击。” + +Hubbard 分享一些新的工具或功能例子,例如支持人工智能的安全软件或机器学习的应用程序,这些应用程序可以远程发现石油管道中的维护需求。两者都可以提高效益和效果,自然不会代替需要信息安全或管道维护的人员。 + +“许多新功能仍需要人工监控,”Hubbard 说。“例如,为了让机器确定一些‘预测’是否可能成为‘规律’,人为的管理是必要的。” + +即使你把机器学习和 AI 先放在一边,看待一般的 IT 自动化,同样原理也是成立的,尤其是在软件开发生命周期中。 + +[Juniper Networks][13] 公司自动化首席架构师 Matthew Oswalt ,指出 IT 自动化增长的根本原因是它通过减少操作基础设施所需的人工工作量来创造直接价值。 + +> 在代码上,操作工程师可以使用事件驱动的自动化提前定义他们的工作流程,而不是在凌晨 3 点来应对基础设施的问题。 + +“它也将操作工作流程作为代码而不再是容易过时的文档或系统知识阶段,”Oswalt 解释说。“操作人员仍然需要在[自动化]工具响应事件方面后发挥积极作用。采用自动化的下一个阶段是建立一个能够跨 IT 频谱识别发生的有趣事件的系统,并以自主方式进行响应。在代码上,操作工程师可以使用事件驱动的自动化提前定义他们的工作流程,而不是在凌晨 3 点来应对基础设施的问题。他们可以依靠这个系统在任何时候以同样的方式作出回应。” + +### 4、 对自动化的焦虑将会减少 + +SolarWinds 公司的 Hubbard 指出,“自动化”一词本身就产生大量的不确定性和担忧,不仅仅是在 IT 领域,而且是跨专业领域,他说这种担忧是合理的。但一些随之而来的担忧可能被夸大了,甚至与科技产业本身共存。现实可能实际上是这方面的镇静力:当自动化的实际实施和实践帮助人们认识到这个列表中的第 3 项时,我们将看到第 4 项的出现。 + +“今年我们可能会看到对自动化焦虑的减少,更多的组织开始接受人工智能和机器学习作为增加现有人力资源的一种方式,”Hubbard 说。“自动化历史上为更多的工作创造了空间,通过降低成本和时间来完成较小任务,并将劳动力重新集中到无法自动化并需要人力的事情上。人工智能和机器学习也是如此。” + +自动化还将减少令 IT 领导者神经紧张的一些焦虑:安全。正如[红帽][14]公司首席架构师 Matt Smith 最近[指出][15]的那样,自动化将越来越多地帮助 IT 部门降低与维护任务相关的安全风险。 + +他的建议是:“首先在维护活动期间记录和自动化 IT 资产之间的交互。通过依靠自动化,您不仅可以消除之前需要大量手动操作和手术技巧的任务,还可以降低人为错误的风险,并展示当您的 IT 组织采纳变更和新工作方法时可能发生的情况。最终,这将迅速减少对应用安全补丁的抵制。而且它还可以帮助您的企业在下一次重大安全事件中摆脱头条新闻。” + +**[ 阅读全文: [12个企业安全坏习惯要打破。][16] ] ** + +### 5、 脚本和自动化工具将持续发展 + +许多组织看到了增加自动化的第一步,通常以脚本或自动化工具(有时称为配置管理工具)的形式作为“早期”工作。 + +但是随着各种自动化技术的使用,对这些工具的观点也在不断发展。 + +[DataVision][18] 首席运营官 Mark Abolafia 表示:“数据中心环境中存在很多重复性过程,容易出现人为错误,[Ansible][17] 等技术有助于缓解这些问题。“通过 Ansible ,人们可以为一组操作编写特定的步骤,并输入不同的变量,例如地址等,使过去长时间的过程链实现自动化,而这些过程以前都需要人为触摸和更长的交付时间。” + +**[想了解更多关于 Ansible 这个方面的知识吗?阅读相关文章:[使用 Ansible 时的成功秘诀][19]。 ]** + +另一个因素是:工具本身将继续变得更先进。 + +“使用先进的 IT 自动化工具,开发人员将能够在更短的时间内构建和自动化工作流程,减少易出错的编码,” ASCI 公司的 Amin 说。“这些工具包括预先构建的、预先测试过的拖放式集成,API 作业,丰富的变量使用,参考功能和对象修订历史记录。” + +### 6、 自动化开创了新的指标机会 + +正如我们在此前所说的那样,IT 自动化不是万能的。它不会修复被破坏的流程,或者以其他方式为您的组织提供全面的灵丹妙药。这也是持续不断的:自动化并不排除衡量性能的必要性。 + +**[ 参见我们的相关文章 [DevOps 指标:你在衡量什么重要吗?][20] ]** + +实际上,自动化应该打开了新的机会。 + +[Janeiro Digital][21] 公司架构师总裁 Josh Collins 说,“随着越来越多的开发活动 —— 源代码管理、DevOps 管道、工作项目跟踪等转向 API 驱动的平台,将这些原始数据拼接在一起以描绘组织效率提升的机会和图景”。 + +Collins 认为这是一种可能的新型“开发组织度量指标”。但不要误认为这意味着机器和算法可以突然预测 IT 所做的一切。 + +“无论是衡量个人资源还是整体团队,这些指标都可以很强大 —— 但应该用大量的背景来衡量。”Collins 说,“将这些数据用于高层次趋势并确认定性观察 —— 而不是临床评级你的团队。” + +**想要更多这样知识, IT 领导者?[注册我们的每周电子邮件通讯][22]。** + +-------------------------------------------------------------------------------- + +via: https://enterprisersproject.com/article/2018/3/what-s-next-it-automation-6-trends-watch + +作者:[Kevin Casey][a] +译者:[MZqk](https://github.com/MZqk) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://enterprisersproject.com/user/kevin-casey +[1]:https://enterprisersproject.com/article/2017/12/5-factors-fueling-automation-it-now +[2]:https://enterprisersproject.com/article/2017/12/4-trends-watch-it-automation-expands +[3]:https://enterprisersproject.com/article/2018/1/getting-started-automation-6-tips +[4]:https://enterprisersproject.com/article/2018/1/how-make-case-it-automation +[5]:https://enterprisersproject.com/article/2018/1/it-automation-best-practices-7-keys-long-term-success +[6]:https://enterprisersproject.com/tags/automation +[7]:https://enterprisersproject.com/article/2018/2/how-spot-machine-learning-opportunity +[8]:https://www.advsyscon.com/en-us/ +[9]:https://www.sungardas.com/en/ +[10]:https://enterprisersproject.com/tags/artificial-intelligence +[11]:https://www.solarwinds.com/ +[12]:https://enterprisersproject.com/article/2017/12/8-emerging-ai-jobs-it-pros +[13]:https://www.juniper.net/ +[14]:https://www.redhat.com/en?intcmp=701f2000000tjyaAAA +[15]:https://enterprisersproject.com/article/2018/2/12-bad-enterprise-security-habits-break +[16]:https://enterprisersproject.com/article/2018/2/12-bad-enterprise-security-habits-break?sc_cid=70160000000h0aXAAQ +[17]:https://opensource.com/tags/ansible +[18]:https://datavision.com/ +[19]:https://opensource.com/article/18/2/tips-success-when-getting-started-ansible?intcmp=701f2000000tjyaAAA +[20]:https://enterprisersproject.com/article/2017/7/devops-metrics-are-you-measuring-what-matters?sc_cid=70160000000h0aXAAQ +[21]:https://www.janeirodigital.com/ +[22]:https://enterprisersproject.com/email-newsletter?intcmp=701f2000000tsjPAAQ diff --git a/published/201807/20180313 Migrating to Linux- Using Sudo.md b/published/201807/20180313 Migrating to Linux- Using Sudo.md new file mode 100644 index 0000000000..2eb4b7d47e --- /dev/null +++ b/published/201807/20180313 Migrating to Linux- Using Sudo.md @@ -0,0 +1,81 @@ +迁移到 Linux:使用 sudo +====== + +> sudo 机制可以让你轻松以普通用户偶尔执行管理任务。让我们来学习一下。 + +![](https://www.linux.com/sites/lcom/files/styles/rendered_file/public/ray-hennessy-233438-unsplash.jpg?itok=d4l7QUtF) + +本文是我们关于迁移到 Linux 的系列文章的第五篇。如果你错过了之前的那些,你可以在这里赶上: + +[第1部分 - 入门介绍][1] +[第2部分 - 磁盘、文件和文件系统][2] +[第3部分 - 图形操作环境][3] +[第4部分 - 命令行][4] + +你可能一直想了解 Linux。也许它在你的工作场所使用,如果你每天使用它,你的工作效率会更高。或者,也许你想在家里的某些计算机上安装 Linux。无论是什么原因,这一系列文章都是为了让过渡更容易。 + +与许多其他操作系统一样,Linux 支持多用户。它甚至支持多个用户同时登录。 + +用户帐户通常会被分配一个可以存储文件的家目录。通常这个家目​​录位于: + +``` +/home/ +``` + +这样,每个用户都有存储自己的文档和其他文件的独立位置。 + +### 管理任务 + +在传统的 Linux 安装中,常规用户帐户无权在系统上执行管理任务。典型的安装 Linux 的系统会要求用户以管理员身份登录以执行某些任务,而不是为每个用户分配权限以执行各种任务。 + +Linux 上的管理员帐户称为 root。 + +### Sudo 解释 + +从历史上看,要执行管理任务,必须以 root 身份登录,执行任务,然后登出。这个过程有点乏味,所以很多人以 root 登录并且整天都以管理员身份工作。这种做法可能会导致灾难性的后果,例如,意外删除系统中的所有文件。当然,root 用户可以做任何事情,因此没有任何保护措施可以防止有人意外地执行影响很大的操作。 + +创建 `sudo` 工具是为了使你更容易以常规用户帐户登录,偶尔以 root 身份执行管理任务,而无需登录、执行任务然后登出。具体来说,`sudo` 允许你以不同的用户身份运行命令。如果你未指定特定用户,则假定你指的是 root 用户。 + +`sudo` 可以有复杂的设置,允许用户有权限使用 `sudo` 运行某些命令,而其他的不行。通常,安装的桌面系统会使创建的第一个帐户在 `sudo` 中有完全的权限,因此你作为主要用户可以完全管理 Linux 安装。 + +### 使用 Sudo + +某些安装 Linux 的系统设置了 `sudo`,因此你仍需要知道 root 帐户的密码才能执行管理任务。其他人,设置 `sudo` 输入自己的密码。这里有不同的哲学。 + +当你尝试在图形环境中执行管理任务时,通常会打开一个要求输入密码的对话框。输入你自己的密码(例如,在 Ubuntu 上)或 root 帐户的密码(例如,Red Hat)。 + +当你尝试在命令行中执行管理任务时,它通常只会给你一个 “permission denied” 错误。然后你在前面用 `sudo` 重新运行命令。例如: + +``` +systemctl start vsftpd +Failed to start vsftpd.service: Access denied + +sudo systemctl start vsftpd +[sudo] password for user1: +``` + +### 何时使用 Sudo + +以 root 身份运行命令(在 `sudo` 或其他情况下)并不总是解决权限错误的最佳解决方案。虽然将以 root 身份运行会消除 “permission denied” 错误,但有时最好寻找根本原因而不是仅仅解决症状。有时文件拥有错误的所有者和权限。 + +当你在尝试一个需要 root 权限来执行操作的任务或者程序时使用 `sudo`。如果文件恰好由另一个用户(包括 root 用户)拥有,请不要使用 `sudo`。在第二种情况下,最好正确设置文件的权限。 + +通过 Linux 基金会和 edX 的免费[“Linux 介绍”][5]课程了解有关 Linux 的更多信息。 + +-------------------------------------------------------------------------------- + +via: https://www.linux.com/blog/learn/2018/3/migrating-linux-using-sudo + +作者:[John Bonesio][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[geekpi](https://github.com/geekpi) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.linux.com/users/johnbonesio +[1]:https://linux.cn/article-9212-1.html +[2]:https://linux.cn/article-9213-1.html +[3]:https://linux.cn/article-9293-1.html +[4]:https://linux.cn/article-9565-1.html +[5]:https://training.linuxfoundation.org/linux-courses/system-administration-training/introduction-to-linux diff --git a/translated/tech/20180315 Kubernetes distributed application deployment with sample Face Recognition App.md b/published/201807/20180315 Kubernetes distributed application deployment with sample Face Recognition App.md similarity index 81% rename from translated/tech/20180315 Kubernetes distributed application deployment with sample Face Recognition App.md rename to published/201807/20180315 Kubernetes distributed application deployment with sample Face Recognition App.md index a05307301a..612b84c53d 100644 --- a/translated/tech/20180315 Kubernetes distributed application deployment with sample Face Recognition App.md +++ b/published/201807/20180315 Kubernetes distributed application deployment with sample Face Recognition App.md @@ -1,9 +1,11 @@ -Kubernetes 分布式应用部署实战 -- 以人脸识别应用为例 +Kubernetes 分布式应用部署实战:以人脸识别应用为例 ============================================================ -# 简介 +![](https://skarlso.github.io/img/2018/03/kube_overview.png) -伙计们,请做好准备,下面将是一段漫长的旅程,期望你能够乐在其中。 +## 简介 + +伙计们,请搬好小板凳坐好,下面将是一段漫长的旅程,期望你能够乐在其中。 我将基于 [Kubernetes][5] 部署一个分布式应用。我曾试图编写一个尽可能真实的应用,但由于时间和精力有限,最终砍掉了很多细节。 @@ -11,17 +13,17 @@ Kubernetes 分布式应用部署实战 -- 以人脸识别应用为例 让我们开始吧。 -# 应用 +## 应用 ### TL;DR ![kube overview](https://skarlso.github.io/img/kube_overview.png) -应用本身由 6 个组件构成。代码可以从如下链接中找到:[Kubenetes 集群示例][6]。 +该应用本身由 6 个组件构成。代码可以从如下链接中找到:[Kubenetes 集群示例][6]。 这是一个人脸识别服务,通过比较已知个人的图片,识别给定图片对应的个人。前端页面用表格形式简要的展示图片及对应的个人。具体而言,向 [接收器][6] 发送请求,请求包含指向一个图片的链接。图片可以位于任何位置。接受器将图片地址存储到数据库 (MySQL) 中,然后向队列发送处理请求,请求中包含已保存图片的 ID。这里我们使用 [NSQ][8] 建立队列。 -[图片处理][9]服务一直监听处理请求队列,从中获取任务。处理过程包括如下几步:获取图片 ID,读取图片,通过 [gRPC][11] 将图片路径发送至 Python 编写的[人脸识别][10]后端。如果识别成功,后端给出图片对应个人的名字。图片处理器进而根据个人 ID 更新图片记录,将其标记为处理成功。如果识别不成功,图片被标记为待解决。如果图片识别过程中出现错误,图片被标记为失败。 +[图片处理][9] 服务一直监听处理请求队列,从中获取任务。处理过程包括如下几步:获取图片 ID,读取图片,通过 [gRPC][11] 将图片路径发送至 Python 编写的 [人脸识别][10] 后端。如果识别成功,后端给出图片对应个人的名字。图片处理器进而根据个人 ID 更新图片记录,将其标记为处理成功。如果识别不成功,图片被标记为待解决。如果图片识别过程中出现错误,图片被标记为失败。 标记为失败的图片可以通过计划任务等方式进行重试。 @@ -33,39 +35,31 @@ Kubernetes 分布式应用部署实战 -- 以人脸识别应用为例 ``` curl -d '{"path":"/unknown_images/unknown0001.jpg"}' http://127.0.0.1:8000/image/post - ``` -此时,接收器将路径path存储到共享数据库集群中,对应的条目包括数据库服务提供的 ID。本应用采用”持久层提供条目对象唯一标识“的模型。获得条目 ID 后,接收器向 NSQ 发送消息,至此接收器的工作完成。 +此时,接收器将路径path存储到共享数据库集群中,该实体存储后将从数据库服务收到对应的 ID。本应用采用“实体对象Entity Object的唯一标识由持久层提供”的模型。获得实体 ID 后,接收器向 NSQ 发送消息,至此接收器的工作完成。 ### 图片处理器 -从这里开始变得有趣起来。图片处理器首次运行时会创建两个 Go routines,具体为: +从这里开始变得有趣起来。图片处理器首次运行时会创建两个 Go 协程routine,具体为: ### Consume -这是一个 NSQ 消费者,需要完成三项任务。首先,监听队列中的消息。其次,当有新消息到达时,将对应的 ID 追加到一个线程安全的 ID 片段中,以供第二个 routine 处理。最后,告知第二个 routine 处理新任务,方法为 [sync.Condition][12]。 +这是一个 NSQ 消费者,需要完成三项必需的任务。首先,监听队列中的消息。其次,当有新消息到达时,将对应的 ID 追加到一个线程安全的 ID 片段中,以供第二个协程处理。最后,告知第二个协程处理新任务,方法为 [sync.Condition][12]。 ### ProcessImages -该 routine 会处理指定 ID 片段,直到对应片段全部处理完成。当处理完一个片段后,该 routine 并不是在一个通道上睡眠等待,而是进入悬挂状态。对每个 ID,按如下步骤顺序处理: +该协程会处理指定 ID 片段,直到对应片段全部处理完成。当处理完一个片段后,该协程并不是在一个通道上睡眠等待,而是进入悬挂状态。对每个 ID,按如下步骤顺序处理: * 与人脸识别服务建立 gRPC 连接,其中人脸识别服务会在人脸识别部分进行介绍 - -* 从数据库获取图片对应的条目 - +* 从数据库获取图片对应的实体 * 为 [断路器][1] 准备两个函数 * 函数 1: 用于 RPC 方法调用的主函数 - * 函数 2: 基于 ping 的断路器健康检查 - * 调用函数 1 将图片路径发送至人脸识别服务,其中路径应该是人脸识别服务可以访问的,最好是共享的,例如 NFS - -* 如果调用失败,将图片条目状态更新为 FAILEDPROCESSING - +* 如果调用失败,将图片实体状态更新为 FAILEDPROCESSING * 如果调用成功,返回值是一个图片的名字,对应数据库中的一个个人。通过联合 SQL 查询,获取对应个人的 ID - -* 将数据库中的图片条目状态更新为 PROCESSED,更新图片被识别成的个人的 ID +* 将数据库中的图片实体状态更新为 PROCESSED,更新图片被识别成的个人的 ID 这个服务可以复制多份同时运行。 @@ -89,7 +83,7 @@ curl -d '{"path":"/unknown_images/unknown0001.jpg"}' http://127.0.0.1:8000/image 注意:我曾经试图使用 [GoCV][14],这是一个极好的 Go 库,但欠缺所需的 C 绑定。推荐马上了解一下这个库,它会让你大吃一惊,例如编写若干行代码即可实现实时摄像处理。 -这个 Python 库的工作方式本质上很简单。准备一些你认识的人的图片,把信息记录下来。对于我而言,我有一个图片文件夹,包含若干图片,名称分别为 `hannibal_1.jpg, hannibal_2.jpg, gergely_1.jpg, john_doe.jpg`。在数据库中,我使用两个表记录信息,分别为 `person, person_images`,具体如下: +这个 Python 库的工作方式本质上很简单。准备一些你认识的人的图片,把信息记录下来。对于我而言,我有一个图片文件夹,包含若干图片,名称分别为 `hannibal_1.jpg`、 `hannibal_2.jpg`、 `gergely_1.jpg`、 `john_doe.jpg`。在数据库中,我使用两个表记录信息,分别为 `person`、 `person_images`,具体如下: ``` +----+----------+ @@ -126,13 +120,13 @@ NSQ 是 Go 编写的小规模队列,可扩展且占用系统内存较少。NSQ ### 配置 -为了尽可能增加灵活性以及使用 Kubernetes 的 ConfigSet 特性,我在开发过程中使用 .env 文件记录配置信息,例如数据库服务的地址以及 NSQ 的查询地址。在生产环境或 Kubernetes 环境中,我将使用环境变量属性配置。 +为了尽可能增加灵活性以及使用 Kubernetes 的 ConfigSet 特性,我在开发过程中使用 `.env` 文件记录配置信息,例如数据库服务的地址以及 NSQ 的查询地址。在生产环境或 Kubernetes 环境中,我将使用环境变量属性配置。 ### 应用小结 这就是待部署应用的全部架构信息。应用的各个组件都是可变更的,他们之间仅通过数据库、消息队列和 gRPC 进行耦合。考虑到更新机制的原理,这是部署分布式应用所必须的;在部署部分我会继续分析。 -# 使用 Kubernetes 部署应用 +## 使用 Kubernetes 部署应用 ### 基础知识 @@ -144,55 +138,51 @@ Kubernetes 是容器化服务及应用的管理器。它易于扩展,可以管 在 Kubernetes 中,你给出期望的应用状态,Kubernetes 会尽其所能达到对应的状态。状态可以是已部署、已暂停,有 2 个副本等,以此类推。 -Kubernetes 使用标签和注释标记组件,包括服务,部署,副本组,守护进程组等在内的全部组件都被标记。考虑如下场景,为了识别 pod 与 应用的对应关系,使用 `app: myapp` 标签。假设应用已部署 2 个容器,如果你移除其中一个容器的 `app` 标签,Kubernetes 只能识别到一个容器(隶属于应用),进而启动一个新的具有 `myapp` 标签的实例。 +Kubernetes 使用标签和注释标记组件,包括服务、部署、副本组、守护进程组等在内的全部组件都被标记。考虑如下场景,为了识别 pod 与应用的对应关系,使用 `app: myapp` 标签。假设应用已部署 2 个容器,如果你移除其中一个容器的 `app` 标签,Kubernetes 只能识别到一个容器(隶属于应用),进而启动一个新的具有 `myapp` 标签的实例。 ### Kubernetes 集群 -要使用 Kubernetes,需要先搭建一个 Kubernetes 集群。搭建 Kubernetes 集群可能是一个痛苦的经历,但所幸有工具可以帮助我们。Minikube 为我们在本地搭建一个单节点集群。AWS 的一个 beta 服务工作方式类似于 Kubernetes 集群,你只需请求 Nodes 并定义你的部署即可。Kubernetes 集群组件的文档如下:[Kubernetes 集群组件][17]。 +要使用 Kubernetes,需要先搭建一个 Kubernetes 集群。搭建 Kubernetes 集群可能是一个痛苦的经历,但所幸有工具可以帮助我们。Minikube 为我们在本地搭建一个单节点集群。AWS 的一个 beta 服务工作方式类似于 Kubernetes 集群,你只需请求节点并定义你的部署即可。Kubernetes 集群组件的文档如下:[Kubernetes 集群组件][17]。 -### 节点 (Nodes) +### 节点 -节点是工作单位,形式可以是虚拟机、物理机,也可以是各种类型的云主机。 +节点node是工作单位,形式可以是虚拟机、物理机,也可以是各种类型的云主机。 -### Pods +### Pod -Pods 是本地容器组成的集合,即一个 Pod 中可能包含若干个容器。Pod 创建后具有自己的 DNS 和 虚拟 IP,这样 Kubernetes 可以对到达流量进行负载均衡。你几乎不需要直接和容器打交道;即使是调试的时候,例如查看日志,你通常调用 `kubectl logs deployment/your-app -f` 查看部署日志,而不是使用 `-c container_name` 查看具体某个容器的日志。`-f` 参数表示从日志尾部进行流式输出。 +Pod 是本地容器逻辑上组成的集合,即一个 Pod 中可能包含若干个容器。Pod 创建后具有自己的 DNS 和虚拟 IP,这样 Kubernetes 可以对到达流量进行负载均衡。你几乎不需要直接和容器打交道;即使是调试的时候,例如查看日志,你通常调用 `kubectl logs deployment/your-app -f` 查看部署日志,而不是使用 `-c container_name` 查看具体某个容器的日志。`-f` 参数表示从日志尾部进行流式输出。 -### 部署 (Deployments) +### 部署 -在 Kubernetes 中创建任何类型的资源时,后台使用一个部署,它指定了资源的期望状态。使用部署对象,你可以将 Pod 或服务变更为另外的状态,也可以更新应用或上线新版本应用。你一般不会直接操作副本组 (后续会描述),而是通过部署对象创建并管理。 +在 Kubernetes 中创建任何类型的资源时,后台使用一个部署deployment组件,它指定了资源的期望状态。使用部署对象,你可以将 Pod 或服务变更为另外的状态,也可以更新应用或上线新版本应用。你一般不会直接操作副本组 (后续会描述),而是通过部署对象创建并管理。 -### 服务 (Services) +### 服务 -默认情况下,Pod 会获取一个 IP 地址。但考虑到 Pod 是 Kubernetes 中的易失性组件,我们需要更加持久的组件。不论是队列,mysql,内部 API 或前端,都需要长期运行并使用保持不变的 IP 或 更佳的 DNS 记录。 +默认情况下,Pod 会获取一个 IP 地址。但考虑到 Pod 是 Kubernetes 中的易失性组件,我们需要更加持久的组件。不论是队列,MySQL、内部 API 或前端,都需要长期运行并使用保持不变的 IP 或更好的 DNS 记录。 -为解决这个问题,Kubernetes 提供了服务组件,可以定义访问模式,支持的模式包括负载均衡,简单 IP 或 内部 DNS。 +为解决这个问题,Kubernetes 提供了服务service组件,可以定义访问模式,支持的模式包括负载均衡、简单 IP 或内部 DNS。 Kubernetes 如何获知服务运行正常呢?你可以配置健康性检查和可用性检查。健康性检查是指检查容器是否处于运行状态,但容器处于运行状态并不意味着服务运行正常。对此,你应该使用可用性检查,即请求应用的一个特别接口endpoint。 -由于服务非常重要,推荐你找时间阅读以下文档:[服务][18]。严肃的说,需要阅读的东西很多,有 24 页 A4 纸的篇幅,涉及网络,服务及自动发现。这也有助于你决定是否真的打算在生产环境中使用 Kubernetes。 +由于服务非常重要,推荐你找时间阅读以下文档:[服务][18]。严肃的说,需要阅读的东西很多,有 24 页 A4 纸的篇幅,涉及网络、服务及自动发现。这也有助于你决定是否真的打算在生产环境中使用 Kubernetes。 ### DNS / 服务发现 -在 Kubernetes 集群中创建服务后,该服务会从名为 kube-proxy 和 kube-dns 的特殊 Kubernetes 部署中获取一个 DNS 记录。他们两个用于提供集群内的服务发现。如果你有一个正在运行的 mysql 服务并配置 `clusterIP: no`,那么集群内部任何人都可以通过 `mysql.default.svc.cluster.local` 访问该服务,其中: +在 Kubernetes 集群中创建服务后,该服务会从名为 `kube-proxy` 和 `kube-dns` 的特殊 Kubernetes 部署中获取一个 DNS 记录。它们两个用于提供集群内的服务发现。如果你有一个正在运行的 MySQL 服务并配置 `clusterIP: no`,那么集群内部任何人都可以通过 `mysql.default.svc.cluster.local` 访问该服务,其中: * `mysql` – 服务的名称 - * `default` – 命名空间的名称 - * `svc` – 对应服务分类 - * `cluster.local` – 本地集群的域名 -可以使用自定义设置更改本地集群的域名。如果想让服务可以从集群外访问,需要使用 DNS 提供程序并使用例如 Nginx 将 IP 地址绑定至记录。服务对应的对外 IP 地址可以使用如下命令查询: +可以使用自定义设置更改本地集群的域名。如果想让服务可以从集群外访问,需要使用 DNS 服务,并使用例如 Nginx 将 IP 地址绑定至记录。服务对应的对外 IP 地址可以使用如下命令查询: * 节点端口方式 – `kubectl get -o jsonpath="{.spec.ports[0].nodePort}" services mysql` - * 负载均衡方式 – `kubectl get -o jsonpath="{.spec.ports[0].LoadBalancer}" services mysql` ### 模板文件 -类似 Docker Compose, TerraForm 或其它的服务管理工具,Kubernetes 也提供了基础设施描述模板。这意味着,你几乎不用手动操作。 +类似 Docker Compose、TerraForm 或其它的服务管理工具,Kubernetes 也提供了基础设施描述模板。这意味着,你几乎不用手动操作。 以 Nginx 部署为例,查看下面的 yaml 模板: @@ -218,26 +208,26 @@ spec: #(4) image: nginx:1.7.9 ports: - containerPort: 80 - ``` 在这个示例部署中,我们做了如下操作: -* (1) 使用 kind 关键字定义模板类型 -* (2) 使用 metadata 关键字,增加该部署的识别信息,使用 labels 标记每个需要创建的资源 (3) -* (4) 然后使用 spec 关键字描述所需的状态 - * (5) nginx 应用需要 3 个副本 - * (6) Pod 中容器的模板定义部分 - * 容器名称为 nginx - * 容器模板为 nginx:1.7.9 (本例使用 Docker 镜像) +* (1) 使用 `kind` 关键字定义模板类型 +* (2) 使用 `metadata` 关键字,增加该部署的识别信息 +* (3) 使用 `labels` 标记每个需要创建的资源 +* (4) 然后使用 `spec` 关键字描述所需的状态 +* (5) nginx 应用需要 3 个副本 +* (6) Pod 中容器的模板定义部分 +* 容器名称为 nginx +* 容器模板为 nginx:1.7.9 (本例使用 Docker 镜像) -### 副本组 (ReplicaSet) +### 副本组 -副本组是一个底层的副本管理器,用于保证运行正确数目的应用副本。相比而言,部署是更高层级的操作,应该用于管理副本组。除非你遇到特殊的情况,需要控制副本的特性,否则你几乎不需要直接操作副本组。 +副本组ReplicaSet是一个底层的副本管理器,用于保证运行正确数目的应用副本。相比而言,部署是更高层级的操作,应该用于管理副本组。除非你遇到特殊的情况,需要控制副本的特性,否则你几乎不需要直接操作副本组。 -### 守护进程组 (DaemonSet) +### 守护进程组 -上面提到 Kubernetes 始终使用标签,还有印象吗?守护进程组是一个控制器,用于确保守护进程化的应用一直运行在具有特定标签的节点中。 +上面提到 Kubernetes 始终使用标签,还有印象吗?守护进程组DaemonSet是一个控制器,用于确保守护进程化的应用一直运行在具有特定标签的节点中。 例如,你将所有节点增加 `logger` 或 `mission_critical` 的标签,以便运行日志 / 审计服务的守护进程。接着,你创建一个守护进程组并使用 `logger` 或 `mission_critical` 节点选择器。Kubernetes 会查找具有该标签的节点,确保守护进程的实例一直运行在这些节点中。因而,节点中运行的所有进程都可以在节点内访问对应的守护进程。 @@ -253,7 +243,7 @@ spec: #(4) ### Kubernetes 部分小结 -Kubernetes 是容器编排的便捷工具,工作单元为 Pods,具有分层架构。最顶层是部署,用于操作其它资源,具有高度可配置性。对于你的每个命令调用,Kubernetes 提供了对应的 API,故理论上你可以编写自己的代码,向 Kubernetes API 发送数据,得到与 `kubectl` 命令同样的效果。 +Kubernetes 是容器编排的便捷工具,工作单元为 Pod,具有分层架构。最顶层是部署,用于操作其它资源,具有高度可配置性。对于你的每个命令调用,Kubernetes 提供了对应的 API,故理论上你可以编写自己的代码,向 Kubernetes API 发送数据,得到与 `kubectl` 命令同样的效果。 截至目前,Kubernetes 原生支持所有主流云服务供应商,而且完全开源。如果你愿意,可以贡献代码;如果你希望对工作原理有深入了解,可以查阅代码:[GitHub 上的 Kubernetes 项目][22]。 @@ -272,7 +262,7 @@ kubectl get nodes -o yaml ### 构建容器 -Kubernetes 支持大多数现有的容器技术。我这里使用 Docker。每一个构建的服务容器,对应代码库中的一个 Dockerfile 文件。我推荐你仔细阅读它们,其中大多数都比较简单。对于 Go 服务,我采用了最近引入的多步构建的方式。Go 服务基于 Alpine Linux 镜像创建。人脸识别程序使用 Python,NSQ 和 MySQL 使用对应的容器。 +Kubernetes 支持大多数现有的容器技术。我这里使用 Docker。每一个构建的服务容器,对应代码库中的一个 Dockerfile 文件。我推荐你仔细阅读它们,其中大多数都比较简单。对于 Go 服务,我采用了最近引入的多步构建的方式。Go 服务基于 Alpine Linux 镜像创建。人脸识别程序使用 Python、NSQ 和 MySQL 使用对应的容器。 ### 上下文 @@ -293,9 +283,9 @@ Switched to context "kube-face-cluster". ``` 此后,所有 `kubectl` 命令都会使用 `face` 命名空间。 -(译注:作者后续并没有使用 face 命名空间,模板文件中的命名空间仍为 default,可能 face 命名空间用于开发环境。如果希望使用 face 命令空间,需要将内部 DNS 地址中的 default 改成 face;如果只是测试,可以不执行这两条命令。) +(LCTT 译注:作者后续并没有使用 face 命名空间,模板文件中的命名空间仍为 default,可能 face 命名空间用于开发环境。如果希望使用 face 命令空间,需要将内部 DNS 地址中的 default 改成 face;如果只是测试,可以不执行这两条命令。) -### 应用部署 +## 应用部署 Pods 和 服务概览: @@ -318,7 +308,6 @@ type: Opaque data: mysql_password: base64codehere mysql_userpassword: base64codehere - ``` 其中 base64 编码通过如下命令生成: @@ -326,10 +315,9 @@ data: ``` echo -n "ubersecurepassword" | base64 echo -n "root:ubersecurepassword" | base64 - ``` -(LCTT 译注:secret yaml 文件中的 data 应该有两条,一条对应 mysql_password, 仅包含密码;另一条对应 mysql_userpassword,包含用户和密码。后文会用到 mysql_userpassword,但没有提及相应的生成) +(LCTT 译注:secret yaml 文件中的 data 应该有两条,一条对应 `mysql_password`,仅包含密码;另一条对应 `mysql_userpassword`,包含用户和密码。后文会用到 `mysql_userpassword`,但没有提及相应的生成) 我的部署 yaml 对应部分如下: @@ -362,13 +350,12 @@ echo -n "root:ubersecurepassword" | base64 其中 `presistentVolumeClain` 是关键,告知 Kubernetes 当前资源需要持久化存储。持久化存储的提供方式对用户透明。类似 Pods,如果想了解更多细节,参考文档:[Kubernetes 持久化存储][27]。 -(LCTT 译注:使用 presistentVolumeClain 之前需要创建 presistentVolume,对于单节点可以使用本地存储,对于多节点需要使用共享存储,因为 Pod 可以能调度到任何一个节点) +(LCTT 译注:使用 `presistentVolumeClain` 之前需要创建 `presistentVolume`,对于单节点可以使用本地存储,对于多节点需要使用共享存储,因为 Pod 可以能调度到任何一个节点) 使用如下命令部署 MySQL 服务: ``` kubectl apply -f mysql.yaml - ``` 这里比较一下 `create` 和 `apply`。`apply` 是一种宣告式declarative的对象配置命令,而 `create` 是命令式imperative的命令。当下我们需要知道的是,`create` 通常对应一项任务,例如运行某个组件或创建一个部署;相比而言,当我们使用 `apply` 的时候,用户并没有指定具体操作,Kubernetes 会根据集群目前的状态定义需要执行的操作。故如果不存在名为 `mysql` 的服务,当我执行 `apply -f mysql.yaml` 时,Kubernetes 会创建该服务。如果再次执行这个命令,Kubernetes 会忽略该命令。但如果我再次运行 `create`,Kubernetes 会报错,告知服务已经创建。 @@ -460,7 +447,7 @@ volumes: ``` -(LCTT 译注:数据库初始化脚本需要改成对应的路径,如果是多节点,需要是共享存储中的路径。另外,作者给的 sql 文件似乎有误,person_images 表中的 person_id 列数字都小 1,作者默认 id 从 0 开始,但应该是从 1 开始) +(LCTT 译注:数据库初始化脚本需要改成对应的路径,如果是多节点,需要是共享存储中的路径。另外,作者给的 sql 文件似乎有误,`person_images` 表中的 `person_id` 列数字都小 1,作者默认 `id` 从 0 开始,但应该是从 1 开始) 运行如下命令查看引导脚本是否正确执行: @@ -489,7 +476,6 @@ mysql> ``` kubectl logs deployment/mysql -f - ``` ### NSQ 查询 @@ -505,7 +491,7 @@ NSQ 查询将以内部服务的形式运行。由于不需要外部访问,这 ``` -那么,内部 DNS 对应的条目类似于:`nsqlookup.default.svc.cluster.local`。 +那么,内部 DNS 对应的实体类似于:`nsqlookup.default.svc.cluster.local`。 无头服务的更多细节,可以参考:[无头服务][32]。 @@ -517,7 +503,7 @@ args: ["--broadcast-address=nsqlookup.default.svc.cluster.local"] ``` -你可能会疑惑,`--broadcast-address` 参数是做什么用的?默认情况下,nsqlookup 使用 `hostname` (LCTT 译注:这里是指容器的主机名,而不是 hostname 字符串本身)作为广播地址;这意味着,当用户运行回调时,回调试图访问的地址类似于 `http://nsqlookup-234kf-asdf:4161/lookup?topics=image`,但这显然不是我们期望的。将广播地址设置为内部 DNS 后,回调地址将是 `http://nsqlookup.default.svc.cluster.local:4161/lookup?topic=images`,这正是我们期望的。 +你可能会疑惑,`--broadcast-address` 参数是做什么用的?默认情况下,`nsqlookup` 使用容器的主机名作为广播地址;这意味着,当用户运行回调时,回调试图访问的地址类似于 `http://nsqlookup-234kf-asdf:4161/lookup?topics=image`,但这显然不是我们期望的。将广播地址设置为内部 DNS 后,回调地址将是 `http://nsqlookup.default.svc.cluster.local:4161/lookup?topic=images`,这正是我们期望的。 NSQ 查询还需要转发两个端口,一个用于广播,另一个用于 nsqd 守护进程的回调。在 Dockerfile 中暴露相应端口,在 Kubernetes 模板中使用它们,类似如下: @@ -533,6 +519,7 @@ NSQ 查询还需要转发两个端口,一个用于广播,另一个用于 nsq ``` 服务模板: + ``` spec: ports: @@ -592,13 +579,13 @@ NSQ 守护进程也需要一些调整的参数配置: ``` -其中我们配置了 lookup-tcp-address 和 broadcast-address 参数。前者是 nslookup 服务的 DNS 地址,后者用于回调,就像 nsqlookupd 配置中那样。 +其中我们配置了 `lookup-tcp-address` 和 `broadcast-address` 参数。前者是 nslookup 服务的 DNS 地址,后者用于回调,就像 nsqlookupd 配置中那样。 #### 对外公开 下面即将创建第一个对外公开的服务。有两种方式可供选择。考虑到该 API 负载较高,可以使用负载均衡的方式。另外,如果希望将其部署到生产环境中的任选节点,也应该使用负载均衡方式。 -但由于我使用的本地集群只有一个节点,那么使用 `节点端口` 的方式就足够了。`节点端口` 方式将服务暴露在对应节点的固定端口上。如果未指定端口,将从 30000-32767 数字范围内随机选其一个。也可以指定端口,可以在模板文件中使用 `nodePort` 设置即可。可以通过 `:` 访问该服务。如果使用多个节点,负载均衡可以将多个 IP 合并为一个 IP。 +但由于我使用的本地集群只有一个节点,那么使用 `NodePort` 的方式就足够了。`NodePort` 方式将服务暴露在对应节点的固定端口上。如果未指定端口,将从 30000-32767 数字范围内随机选其一个。也可以指定端口,可以在模板文件中使用 `nodePort` 设置即可。可以通过 `:` 访问该服务。如果使用多个节点,负载均衡可以将多个 IP 合并为一个 IP。 更多信息,请参考文档:[服务发布][33]。 @@ -643,7 +630,7 @@ spec: ### 图片处理器 -图片处理器用于将图片传送至识别组件。它需要访问 nslookupd, mysql 以及后续部署的人脸识别服务的 gRPC 接口。事实上,这是一个无聊的服务,甚至其实并不是服务(LCTT 译注:第一个服务是指在整个架构中,图片处理器作为一个服务;第二个服务是指 Kubernetes 服务)。它并需要对外暴露端口,这是第一个只包含部署的组件。长话短说,下面是完整的模板: +图片处理器用于将图片传送至识别组件。它需要访问 nslookupd、 mysql 以及后续部署的人脸识别服务的 gRPC 接口。事实上,这是一个无聊的服务,甚至其实并不是服务(LCTT 译注:第一个服务是指在整个架构中,图片处理器作为一个服务;第二个服务是指 Kubernetes 服务)。它并需要对外暴露端口,这是第一个只包含部署的组件。长话短说,下面是完整的模板: ``` --- @@ -781,7 +768,7 @@ curl -d '{"path":"/unknown_people/unknown220.jpg"}' http://192.168.99.100:30251/ ``` -图像处理器会在 `/unknown_people` 目录搜索名为 unknown220.jpg 的图片,接着在 known_foler 文件中找到 unknown220.jpg 对应个人的图片,最后返回匹配图片的名称。 +图像处理器会在 `/unknown_people` 目录搜索名为 unknown220.jpg 的图片,接着在 `known_folder` 文件中找到 `unknown220.jpg` 对应个人的图片,最后返回匹配图片的名称。 查看日志,大致信息如下: @@ -861,9 +848,9 @@ receiver-deployment-5cb4797598-sf5ds 1/1 Running 0 26s ``` -### 滚动更新 (Rolling Update) +## 滚动更新 -滚动更新过程中会发生什么呢? +滚动更新Rolling Update过程中会发生什么呢? ![kube rotate](https://skarlso.github.io/img/kube_rotate.png) @@ -871,7 +858,7 @@ receiver-deployment-5cb4797598-sf5ds 1/1 Running 0 26s 目前的 API 一次只能处理一个图片,不能批量处理,对此我并不满意。 -#### 代码 +### 代码 目前,我们使用下面的代码段处理单个图片的情形: @@ -900,7 +887,7 @@ func main() { 这里,你可能会说你并不需要保留旧代码;某些情况下,确实如此。因此,我们打算直接修改旧代码,让其通过少量参数调用新代码。这样操作操作相当于移除了旧代码。当所有客户端迁移完毕后,这部分代码也可以安全地删除。 -#### 新的 Endpoint +### 新的接口 让我们添加新的路由方法: @@ -941,7 +928,7 @@ func PostImage(w http.ResponseWriter, r *http.Request) { ``` -当然,方法名可能容易混淆,但你应该能够理解我想表达的意思。我将请求中的单个路径封装成新方法所需格式,然后将其作为请求发送给新接口处理。仅此而已。在 [滚动更新批量图片 PR][34] 中可以找到更多的修改方式。 +当然,方法名可能容易混淆,但你应该能够理解我想表达的意思。我将请求中的单个路径封装成新方法所需格式,然后将其作为请求发送给新接口处理。仅此而已。在 [滚动更新批量图片的 PR][34] 中可以找到更多的修改方式。 至此,我们使用两种方法调用接收器: @@ -958,7 +945,7 @@ curl -d '{"paths":[{"path":"unknown4456.jpg"}]}' http://127.0.0.1:8000/images/po 为了简洁,我不打算为 NSQ 和其它组件增加批量图片处理的能力。这些组件仍然是一次处理一个图片。这部分修改将留给你作为扩展内容。 :) -#### 新镜像 +### 新镜像 为实现滚动更新,我首先需要为接收器服务创建一个新的镜像。新镜像使用新标签,告诉大家版本号为 v1.1。 @@ -969,11 +956,11 @@ docker build -t skarlso/kube-receiver-alpine:v1.1 . 新镜像创建后,我们可以开始滚动更新了。 -#### 滚动更新 +### 滚动更新 在 Kubernetes 中,可以使用多种方式完成滚动更新。 -##### 手动更新 +#### 手动更新 不妨假设在我配置文件中使用的容器版本为 `v1.0`,那么实现滚动更新只需运行如下命令: @@ -991,7 +978,7 @@ kubectl rolling-update receiver --rollback 容器将回滚到使用上一个版本镜像,操作简捷无烦恼。 -##### 应用新的配置文件 +#### 应用新的配置文件 手动更新的不足在于无法版本管理。 @@ -1051,7 +1038,7 @@ kubectl delete services -all ``` -# 写在最后的话 +## 写在最后的话 各位看官,本文就写到这里了。我们在 Kubernetes 上编写、部署、更新和扩展(老实说,并没有实现)了一个分布式应用。 @@ -1065,9 +1052,9 @@ Gergely 感谢你阅读本文。 via: https://skarlso.github.io/2018/03/15/kubernetes-distributed-application/ -作者:[hannibal ][a] +作者:[hannibal][a] 译者:[pinewall](https://github.com/pinewall) -校对:[校对者ID](https://github.com/校对者ID) +校对:[wxy](https://github.com/wxy) 本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 diff --git a/translated/talk/20180320 Can we build a social network that serves users rather than advertisers.md b/published/201807/20180320 Can we build a social network that serves users rather than advertisers.md similarity index 56% rename from translated/talk/20180320 Can we build a social network that serves users rather than advertisers.md rename to published/201807/20180320 Can we build a social network that serves users rather than advertisers.md index bd279216ca..f7d378580b 100644 --- a/translated/talk/20180320 Can we build a social network that serves users rather than advertisers.md +++ b/published/201807/20180320 Can we build a social network that serves users rather than advertisers.md @@ -1,13 +1,15 @@ 我们能否建立一个服务于用户而非广告商的社交网络? ===== +> 找出 Human Connection 是如何将透明度和社区放在首位的。 + ![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/people_team_community_group.png?itok=Nc_lTsUK) -如今,开源软件具有深远的意义,在推动数字经济创新方面发挥着关键作用。世界正在快速彻底地改变。世界各地的人们需要一个专门的,中立的,透明的在线平台来迎接我们这个时代的挑战。 +如今,开源软件具有深远的意义,在推动数字经济创新方面发挥着关键作用。世界正在快速彻底地改变。世界各地的人们需要一个专门的、中立的、透明的在线平台来迎接我们这个时代的挑战。 -开放的原则可能会成为让我们到达那里的方法(to 校正者:这句上下文没有理解)。如果我们用开放的思维方式将数字创新与社会创新结合在一起,会发生什么? +开放的原则也许是让我们达成这一目标的方法。如果我们用开放的思维方式将数字创新与社会创新结合在一起,会发生什么? -这个问题是我们在 [Human Connection][1] 工作的核心,这是一个具有前瞻性的,以德国为基础的知识和行动网络,其使命是创建一个服务于全球的真正的社交网络。我们受到这样一种观念为指引,即人类天生慷慨而富有同情心,并且他们在慈善行为上茁壮成长。但我们还没有看到一个完全支持我们自然倾向,于乐于助人和合作以促进共同利益的社交网络。Human Connection 渴望成为让每个人都成为积极变革者的平台。 +这个问题是我们在 [Human Connection][1] 工作的核心,这是一个具有前瞻性的,以德国为基础的知识和行动网络,其使命是创建一个服务于全球的真正的社交网络。我们受到这样一种观念为指引,即人类天生慷慨而富有同情心,并且他们在慈善行为上茁壮成长。但我们还没有看到一个完全支持我们的自然趋势,与乐于助人和合作以促进共同利益的社交网络。Human Connection 渴望成为让每个人都成为积极变革者的平台。 为了实现一个以解决方案为导向的平台的梦想,让人们通过与慈善机构、社区团体和社会变革活动人士的接触,围绕社会公益事业采取行动,Human Connection 将开放的价值观作为社会创新的载体。 @@ -15,31 +17,28 @@ ### 首先是透明 -透明是 Human Connection 的指导原则之一。Human Connection 邀请世界各地的程序员通过[在 Github 上提交他们的源代码][2]共同开发平台的源代码(JavaScript, Vue, nuxt),并通过贡献代码或编程附加功能来支持真正的社交网络。 +透明是 Human Connection 的指导原则之一。Human Connection 邀请世界各地的程序员通过[在 Github 上提交他们的源代码][2]共同开发平台的源代码(JavaScript、Vue、nuxt),并通过贡献代码或编程附加功能来支持真正的社交网络。 -但我们对透明的承诺超出了我们的发展实践。事实上,当涉及到建立一种新的社交网络,促进那些对让世界变得更好的人之间的真正联系和互动,分享源代码只是迈向透明的一步。 +但我们对透明的承诺超出了我们的发展实践。事实上,当涉及到建立一种新的社交网络,促进那些让世界变得更好的人之间的真正联系和互动,分享源代码只是迈向透明的一步。 -为促进公开对话,Human Connection 团队举行[定期在线公开会议][3]。我们在这里回答问题,鼓励建议并对潜在的问题作出回应。我们的 Meet The Team (to 校正者:这里如果可以,请翻译得稍微优雅,我想不出来一个词)活动也会记录下来,并在事后向公众开放。通过对我们的流程,源代码和财务状况完全透明,我们可以保护自己免受批评或其他潜在的不利影响。 +为促进公开对话,Human Connection 团队举行[定期在线公开会议][3]。我们在这里回答问题,鼓励建议并对潜在的问题作出回应。我们的 Meet The Team 活动也会记录下来,并在事后向公众开放。通过对我们的流程,源代码和财务状况完全透明,我们可以保护自己免受批评或其他潜在的不利影响。 对透明的承诺意味着,所有在 Human Connection 上公开分享的用户贡献者将在 Creative Commons 许可下发布,最终作为数据包下载。通过让大众知识变得可用,特别是以一种分散的方式,我们创造了一个多元化社会的机会。 -一个问题指导我们所有的组织决策:“它是否服务于人民和更大的利益?”我们用[联合国宪章(UN Charter)][4]和“世界人权宣言(Universal Declaration of Human Rights)”作为我们价值体系的基础。随着我们的规模越来越大,尤其是即将推出的公测版,我们必须对此任务负责。我甚至愿意邀请 Chaos Computer Club (译者注:这是欧洲最大的黑客联盟)或其他黑客俱乐部通过随机检查我们的平台来验证我们的代码和行为的完整性。 +有一个问题指导我们所有的组织决策:“它是否服务于人民和更大的利益?”我们用[联合国宪章][4]UN Charter和“世界人权宣言Universal Declaration of Human Rights”作为我们价值体系的基础。随着我们的规模越来越大,尤其是即将推出的公测版,我们必须对此任务负责。我甚至愿意邀请 Chaos Computer Club (LCTT 译注:这是欧洲最大的黑客联盟)或其他黑客俱乐部通过随机检查我们的平台来验证我们的代码和行为的完整性。 ### 一个合作的社会 以一种[以社区为中心的协作方法][5]来编写 Human Connection 平台是超越社交网络实际应用理念的基础。我们的团队是通过找到问题的答案来驱动:“是什么让一个社交网络真正地社会化?” -一个抛弃了以利润为导向的算法,为广告商而不是最终用户服务的网络,只能通过转向对等生产和协作的过程而繁荣起来。例如,像 [Code Alliance][6] 和 [Code for America][7] 这样的组织已经证明了如何在一个开源环境中创造技术,造福人类并破坏(to 校正:这里译为改变较好)现状。社区驱动的项目,如基于地图的报告平台 [FixMyStreet][8],或者为 Humanitarian OpenStreetMap 而建立的 [Tasking Manager][9],已经将众包作为推动其使用的一种方式。 +一个抛弃了以利润为导向的算法、为最终用户而不是广告商服务的网络,只能通过转向对等生产和协作的过程而繁荣起来。例如,像 [Code Alliance][6] 和 [Code for America][7] 这样的组织已经证明了如何在一个开源环境中创造技术,造福人类并变革现状。社区驱动的项目,如基于地图的报告平台 [FixMyStreet][8],或者为 Humanitarian OpenStreetMap 而建立的 [Tasking Manager][9],已经将众包作为推动其使用的一种方式。 -我们建立 Human Connection 的方法从一开始就是合作。为了收集关于必要功能和真正社交网络的目的的初步数据,我们与巴黎索邦大学(University Sorbonne)的国家东方语言与文明研究所(National Institute for Oriental Languages and Civilizations (INALCO) )和德国斯图加特媒体大学(Stuttgart Media University )合作。这两个项目的研究结果都被纳入了 Human Connection 的早期开发。多亏了这项研究,[用户将拥有一套全新的功能][10],让他们可以控制自己看到的内容以及他们如何与他人的互动。由于早期的支持者[被邀请到网络的 alpha 版本][10],他们可以体验到第一个可用的值得注意的功能。这里有一些: - - * 将信息与行动联系起来是我们研究会议的一个重要主题。当前的社交网络让用户处于信息阶段。这两所大学的学生团体都认为,需要一个以行动为导向的组件,以满足人类共同解决问题的本能。所以我们在平台上构建了一个[“Can Do”功能][11]。这是一个人在阅读了某个话题后可以采取行动的一种方式。“Can Do” 是用户建议的活动,在“采取行动(Take Action)”领域,每个人都可以实现。 - - * “Versus” 功能是另一个定义结果的方式(to 校正者:这句话稍微注意一下)。在传统社交网络仅限于评论功能的地方,我们的学生团体认为需要采用更加结构化且有用的方式进行讨论和争论。“Versus” 是对公共帖子的反驳,它是单独显示的,并提供了一个机会来突出围绕某个问题的不同意见。 +我们建立 Human Connection 的方法从一开始就是合作。为了收集关于必要功能和真正社交网络的目的的初步数据,我们与巴黎索邦大学University Sorbonne国家东方语言与文明研究所National Institute for Oriental Languages and Civilizations(INALCO)和德国斯图加特媒体大学Stuttgart Media University合作。这两个项目的研究结果都被纳入了 Human Connection 的早期开发。多亏了这项研究,[用户将拥有一套全新的功能][10],让他们可以控制自己看到的内容以及他们如何与他人的互动。由于早期的支持者[被邀请到网络的 alpha 版本][10],他们可以体验到第一个可用的值得注意的功能。这里有一些: + * 将信息与行动联系起来是我们研究会议的一个重要主题。当前的社交网络让用户处于信息阶段。这两所大学的学生团体都认为,需要一个以行动为导向的组件,以满足人类共同解决问题的本能。所以我们在平台上构建了一个[“Can Do”功能][11]。这是一个人在阅读了某个话题后可以采取行动的一种方式。“Can Do” 是用户建议的活动,在“采取行动Take Action”领域,每个人都可以实现。 + * “Versus” 功能是另一个成果。在传统社交网络仅限于评论功能的地方,我们的学生团体认为需要采用更加结构化且有用的方式进行讨论和争论。“Versus” 是对公共帖子的反驳,它是单独显示的,并提供了一个机会来突出围绕某个问题的不同意见。 * 今天的社交网络并没有提供很多过滤内容的选项。研究表明,情绪过滤选项可以帮助我们根据日常情绪驾驭社交空间,并可能通过在我们希望仅看到令人振奋的内容的那一天时,不显示悲伤或难过的帖子来潜在地保护我们的情绪健康。 - Human Connection 邀请改革者合作开发一个网络,有可能动员世界各地的个人和团体将负面新闻变成 “Can Do”,并与慈善机构和非营利组织一起参与社会创新项目。 [订阅我们的每周时事通讯][12]以了解有关开放组织的更多信息。 @@ -51,7 +50,7 @@ via: https://opensource.com/open-organization/18/3/open-social-human-connection 作者:[Dennis Hack][a] 译者:[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/) 荣誉推出 diff --git a/published/201807/20180320 Migrating to Linux- Installing Software.md b/published/201807/20180320 Migrating to Linux- Installing Software.md new file mode 100644 index 0000000000..5975f7edfc --- /dev/null +++ b/published/201807/20180320 Migrating to Linux- Installing Software.md @@ -0,0 +1,88 @@ +迁移到 Linux:安装软件 +====== + +> 所有的 Linux 打包系统和工具都会让人迷惑,但是这篇面向初学者的教程可以帮助你搞明白。 + +![](https://www.linux.com/sites/lcom/files/styles/rendered_file/public/birds-1835510_1920.jpg?itok=8i6mBStG) + +如你所见,众所瞩目的 Linux 已经用在互联网,以及 Arduino、Beagle 和树莓派主板等设备上,或许你正在考虑是时候尝试一下 Linux 了。本系列将帮助你成功过渡到 Linux。如果你错过了本系列的早期文章,可以在这里找到它们: + +- [第1部分 - 入门介绍][1] +- [第2部分 - 磁盘、文件和文件系统][2] +- [第3部分 - 图形操作环境][3] +- [第4部分 - 命令行][4] +- [第5部分 - 使用 sudo][5] + +### 安装软件 + +要在你的计算机上获得新软件,通常的方法是从供应商处获得软件产品,然后运行一个安装程序。过去,软件产品会出现在像 CD-ROM 或 DVD 一样的物理媒介上,而现在我们经常从互联网上下载软件产品。 + +使用 Linux,安装软件就像在你的智能手机上安装一样。如同你的手机应用商店一样,在 Linux 上有个提供开源软件工具和程序的中央仓库central repository,几乎任何你想要的程序都会出现在可用软件包列表中以供你安装。 + +每个程序并不需要运行单独的安装程序,而是你可以使用 Linux 发行版附带的软件包管理工具。(这里说的 Linux 发行版就是你安装的 Linux,例如 Ubuntu、Fedora、Debian 等)每个发行版在互联网上都有它自己的集中存储库(称为仓库),它们存储了数千个预先构建好的应用程序。 + +你可能会注意到,在 Linux 上安装软件有几种例外情况。有时候,你仍然需要去供应商那里获取他们的软件,因为该程序不存在于你的发行版的中央仓库中。当软件不是开源和/或自由软件的时候,通常就是这种情况。 + +另外请记住,如果你想要安装一个不在发行版仓库中的程序时,事情就不是那么简单了,即使你正在安装自由及开源程序。这篇文章没有涉及到这些更复杂的情况,请遵循在线的指引。 + +有了所有的 Linux 包管理系统和工具,接下来干什么可能仍然令人困惑。本文应该有助于澄清一些事情。 + +### 包管理 + +目前在 Linux 发行版中有几个相互竞争的用于管理、安装和删除软件的包管理系统。每个发行版都选择使用了一个包管理工具package management tools。Red Hat、Fedora、CentOS、Scientific Linux、SUSE 等使用 Red Hat 包管理(RPM)。Debian、Ubuntu、Linux Mint 等等都使用 Debian 包管理系统,简称 DPKG。还有一些其它包管理系统,但 RPM 和 DPKG 是最常见的。 + +![](https://www.linux.com/sites/lcom/files/styles/floated_images/public/package-installer.png?itok=V9OU1Q0u) + +*图 1: Package installers* + +无论你使用的软件包管理是什么,它们通常都是一组构建于另外一种工具之上的工具(图 1)。最底层是一个命令行工具,它可以让你做任何与安装软件相关的一切工作。你可以列出已安装的程序、删除程序、安装软件包文件等等。 + +这个底层工具并不总是最方便使用的,所以通常会有一个命令行工具,它可以使用单个命令在发行版的中央仓库中找到软件包,并下载和安装它以及任何依赖项。最后,通常会有一个图形应用程序graphical application,可以让你使用鼠标选择任何想要的内容,然后单击 “install” 按钮即可。 + +![](https://www.linux.com/sites/lcom/files/styles/rendered_file/public/package-kit.png?itok=YimOq2Je) + +*图 2: PackageKit* + +对于基于 Red Hat 的发行版,包括 Fedora、CentOS、Scientific Linux 等,它们的底层工具是 rpm,高级工具叫做 dnf(在旧系统上是 yum)。图形安装程序称为 PackageKit(图 2),它可能在系统管理菜单下显示名字为 “Add/Remove Software(添加/删除软件)”。 + +![](https://www.linux.com/sites/lcom/files/styles/rendered_file/public/ubuntu-software.png?itok=5QSctLEW) + +*图 3: Ubuntu Software* + +对于基于 Debian 的发行版,包括 Debian、Ubuntu、Linux Mint、Elementary OS 等,它们的底层命令行工具是 dpkg,高级工具称为 apt。在 Ubuntu 上管理已安装软件的图形工具是 Ubuntu Software(图 3)。对于 Debian 和 Linux Mint,图形工具称为新立得Synaptic,它也可以安装在 Ubuntu 上。 + +你也可以在 Debian 相关发行版上安装一个基于文本的图形化工具 aptitude。它比新立得更强大,并且即使你只能访问命令行也能工作。如果你想通过各种选项进行各种操作,你可以试试这个,但它使用起来比新立得更复杂。其它发行版也可能有自己独特的工具。 + +### 命令行工具 + +在 Linux 上安装软件的在线说明通常描述了在命令行中键入的命令。这些说明通常更容易理解,并且将命令复制粘贴到命令行窗口中,可以在不出错的情况下一步步进行。这与下面的说明相反:“打开这个菜单,选择这个程序,输入这个搜索模式,点击这个标签,选择这个程序,然后点击这个按钮”,这经常让你在各种操作中迷失。 + +有时你正在使用的 Linux 没有图形环境,因此熟悉从命令行安装软件包是件好事。表 1 和表 2 列出了基于 RPM 和 DPKG 系统的一下常见操作及其相关命令。 + +![](https://www.linux.com/sites/lcom/files/styles/rendered_file/public/table_1_0.png?itok=hQ_o5Oh2) + +![](https://www.linux.com/sites/lcom/files/styles/rendered_file/public/table_2.png?itok=yl3UPQDw) + +请注意 SUSE,它像 RedHat 和 Fedora 一样使用 RPM,却没有 dnf 或 yum。相反,它使用一个名为 zypper 的程序作为高级命令行工具。其他发行版也可能有不同的工具,例如 Arch Linux 上的 pacman 或 Gentoo 上的 emerge。有很多包管理工具,所以你可能需要查找哪个适用于你的发行版。 + +这些技巧应该能让你更好地了解如何在新的 Linux 中安装程序,以及更好地了解 Linux 中各种软件包管理方式如何相互关联。 + +通过 Linux 基金会和 edX 的免费 [“Linux 入门”][6]课程了解有关 Linux 的更多信息。 + +--- + +via: https://www.linux.com/blog/learn/2018/3/migrating-linux-installing-software + +作者:[JOHN BONESIO][a] +译者:[MjSeven](https://github.com/MjSeven) +校对:[pityonline](https://github.com/pityonline), [wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.linux.com/users/johnbonesio +[1]:https://linux.cn/article-9212-1.html +[2]:https://linux.cn/article-9213-1.html +[3]:https://linux.cn/article-9293-1.html +[4]:https://linux.cn/article-9565-1.html +[5]:https://linux.cn/article-9819-1.html +[6]:https://training.linuxfoundation.org/linux-courses/system-administration-training/introduction-to-linux diff --git a/published/20180411 Make your first contribution to an open source project.md b/published/201807/20180411 Make your first contribution to an open source project.md similarity index 100% rename from published/20180411 Make your first contribution to an open source project.md rename to published/201807/20180411 Make your first contribution to an open source project.md diff --git a/published/20180418 The Linux Filesystem Explained.md b/published/201807/20180418 The Linux Filesystem Explained.md similarity index 100% rename from published/20180418 The Linux Filesystem Explained.md rename to published/201807/20180418 The Linux Filesystem Explained.md diff --git a/translated/tech/20180423 An introduction to Python bytecode.md b/published/201807/20180423 An introduction to Python bytecode.md similarity index 50% rename from translated/tech/20180423 An introduction to Python bytecode.md rename to published/201807/20180423 An introduction to Python bytecode.md index c27346bc91..832f6a4c1c 100644 --- a/translated/tech/20180423 An introduction to Python bytecode.md +++ b/published/201807/20180423 An introduction to Python bytecode.md @@ -1,7 +1,11 @@ Python 字节码介绍 ====== + +> 了解 Python 字节码是什么,Python 如何使用它来执行你的代码,以及知道它是如何帮到你的。 + ![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/code_computer_development_programming.png?itok=4OM29-82) -如果你从没有写过 Python,或者甚至只是使用过 Python,你或许已经习惯于看 Python 源代码文件;它们的名字以 `.py` 结尾。你可能还看到过其它类型的文件,比如使用 `.pyc` 结尾的文件,或许你可能听说过,它们就是 Python 的 "字节码" 文件。(在 Python 3 上这些可能不容易看到 — 因为它们与你的 `.py` 文件不在同一个目录下,它们在一个叫 `__pycache__` 的子目录中)或者你也听说过,这是节省时间的一种方法,它可以避免每次运行 Python 时去重新解析源代码。 + +如果你曾经编写过 Python,或者只是使用过 Python,你或许经常会看到 Python 源代码文件——它们的名字以 `.py` 结尾。你可能还看到过其它类型的文件,比如以 `.pyc` 结尾的文件,或许你可能听说过它们就是 Python 的 “字节码bytecode” 文件。(在 Python 3 上这些可能不容易看到 —— 因为它们与你的 `.py` 文件不在同一个目录下,它们在一个叫 `__pycache__` 的子目录中)或者你也听说过,这是节省时间的一种方法,它可以避免每次运行 Python 时去重新解析源代码。 但是,除了 “噢,原来这就是 Python 字节码” 之外,你还知道这些文件能做什么吗?以及 Python 是如何使用它们的? @@ -9,29 +13,26 @@ Python 字节码介绍 ### Python 如何工作 -Python 经常被介绍为它是一个解释型语言 — 其中一个原因是程序运行时,你的源代码被转换成 CPU 的原生指令 — 但这样认为只是部分正确。Python 与大多数解释型语言一样,确实是将源代码编译为一组虚拟机指令,并且 Python 解释器是针对相应的虚拟机实现的。这种中间格式被称为 “字节码”。 +Python 经常被介绍为它是一个解释型语言 —— 其中一个原因是在程序运行时,你的源代码被转换成 CPU 的原生指令 —— 但这样的看法只是部分正确。Python 与大多数解释型语言一样,确实是将源代码编译为一组虚拟机指令,并且 Python 解释器是针对相应的虚拟机实现的。这种中间格式被称为 “字节码”。 因此,这些 `.pyc` 文件是 Python 悄悄留下的,是为了让它们运行的 “更快”,或者是针对你的源代码的 “优化” 版本;它们是你的程序在 Python 虚拟机上运行的字节码指令。 -我们来看一个示例。这里是用 Python 写的经典程序 "Hello, World!": +我们来看一个示例。这里是用 Python 写的经典程序 “Hello, World!”: + ``` def hello() -     print("Hello, World!") - ``` 下面是转换后的字节码(转换为人类可读的格式): -``` -2           0 LOAD_GLOBAL              0 (print) - -            2 LOAD_CONST               1 ('Hello, World!') - -            4 CALL_FUNCTION            1 ``` +2 0 LOAD_GLOBAL 0 (print) + 2 LOAD_CONST 1 ('Hello, World!') + 4 CALL_FUNCTION 1 +``` -如果你输入那个 `hello()` 函数,然后使用 [CPython][1] 解释器去运行它,上面的 Python 程序将会运行。它看起来可能有点奇怪,因此,我们来深入了解一下它都做了些什么。 +如果你输入那个 `hello()` 函数,然后使用 [CPython][1] 解释器去运行它,那么上述列出的内容就是 Python 所运行的。它看起来可能有点奇怪,因此,我们来深入了解一下它都做了些什么。 ### Python 虚拟机内幕 @@ -39,84 +40,68 @@ CPython 使用一个基于栈的虚拟机。也就是说,它完全面向栈数 CPython 使用三种类型的栈: - 1. **调用栈**。这是运行 Python 程序的主要结构。它为每个当前活动的函数调用使用了一个东西 — "帧“,栈底是程序的入口点。每个函数调用推送一个新帧到调用栈,每当函数调用返回后,这个帧被销毁。 - 2. 在每个帧中,有一个 **计算栈** (也称为 **数据栈**)。这个栈就是 Python 函数运行的地方,运行的 Python 代码大多数是由推入到这个栈中的东西组成的,操作它们,然后在返回后销毁它们。 - 3. 在每个帧中,还有一个 **块栈**。它被 Python 用于去跟踪某些类型的控制结构:loops、`try`/`except` 块、以及 `with` 块,全部推入到块栈中,当你退出这些控制结构时,块栈被销毁。这将帮助 Python 了解任意给定时刻哪个块是活动的,比如,一个 `continue` 或者 `break` 语句可能影响正确的块。 - - +1. 调用栈call stack。这是运行 Python 程序的主要结构。它为每个当前活动的函数调用使用了一个东西 —— “frame”,栈底是程序的入口点。每个函数调用推送一个新的帧到调用栈,每当函数调用返回后,这个帧被销毁。 +2. 在每个帧中,有一个计算栈evaluation stack (也称为数据栈data stack)。这个栈就是 Python 函数运行的地方,运行的 Python 代码大多数是由推入到这个栈中的东西组成的,操作它们,然后在返回后销毁它们。 +3. 在每个帧中,还有一个块栈block stack。它被 Python 用于去跟踪某些类型的控制结构:循环、`try` / `except` 块、以及 `with` 块,全部推入到块栈中,当你退出这些控制结构时,块栈被销毁。这将帮助 Python 了解任意给定时刻哪个块是活动的,比如,一个 `continue` 或者 `break` 语句可能影响正确的块。 大多数 Python 字节码指令操作的是当前调用栈帧的计算栈,虽然,还有一些指令可以做其它的事情(比如跳转到指定指令,或者操作块栈)。 为了更好地理解,假设我们有一些调用函数的代码,比如这个:`my_function(my_variable, 2)`。Python 将转换为一系列字节码指令: - 1. 一个 `LOAD_NAME` 指令去查找函数对象 `my_function`,然后将它推入到计算栈的顶部 - 2. 另一个 `LOAD_NAME` 指令去查找变量 `my_variable`,然后将它推入到计算栈的顶部 - 3. 一个 `LOAD_CONST` 指令去推入一个实整数值 `2` 到计算栈的顶部 - 4. 一个 `CALL_FUNCTION` 指令 +1. 一个 `LOAD_NAME` 指令去查找函数对象 `my_function`,然后将它推入到计算栈的顶部 +2. 另一个 `LOAD_NAME` 指令去查找变量 `my_variable`,然后将它推入到计算栈的顶部 +3. 一个 `LOAD_CONST` 指令去推入一个实整数值 `2` 到计算栈的顶部 +4. 一个 `CALL_FUNCTION` 指令 - - -这个 `CALL_FUNCTION` 指令将有 2 个参数,它表示那个 Python 需要从栈顶弹出两个位置参数;然后函数将在它上面进行调用,并且它也同时被弹出(对于函数涉及的关键字参数,它使用另一个不同的指令 — `CALL_FUNCTION_KW`,但使用的操作原则类似,以及第三个指令 — `CALL_FUNCTION_EX`,它适用于函数调用涉及到使用 `*` 或 `**` 操作符的情况)。一旦 Python 拥有了这些之后,它将在调用栈上分配一个新帧,填充到函数调用的本地变量上,然后,运行那个帧内的 `my_function` 字节码。运行完成后,这个帧将被调用栈销毁,最初的帧内返回的 `my_function` 将被推入到计算栈的顶部。 +这个 `CALL_FUNCTION` 指令将有 2 个参数,它表示那个 Python 需要从栈顶弹出两个位置参数;然后函数将在它上面进行调用,并且它也同时被弹出(对于函数涉及的关键字参数,它使用另一个不同的指令 —— `CALL_FUNCTION_KW`,但使用的操作原则类似,以及第三个指令 —— `CALL_FUNCTION_EX`,它适用于函数调用涉及到参数使用 `*` 或 `**` 操作符的情况)。一旦 Python 拥有了这些之后,它将在调用栈上分配一个新帧,填充到函数调用的本地变量上,然后,运行那个帧内的 `my_function` 字节码。运行完成后,这个帧将被调用栈销毁,而在最初的帧内,`my_function` 的返回值将被推入到计算栈的顶部。 ### 访问和理解 Python 字节码 -如果你想玩转字节码,那么,Python 标准库中的 `dis` 模块将对你有非常大的帮助;`dis` 模块为 Python 字节码提供了一个 "反汇编",它可以让你更容易地得到一个人类可读的版本,以及查找各种字节码指令。[`dis` 模块的文档][2] 可以让你遍历它的内容,并且提供一个字节码指令能够做什么和有什么样的参数的完整清单。 +如果你想玩转字节码,那么,Python 标准库中的 `dis` 模块将对你有非常大的帮助;`dis` 模块为 Python 字节码提供了一个 “反汇编”,它可以让你更容易地得到一个人类可读的版本,以及查找各种字节码指令。[`dis` 模块的文档][2] 可以让你遍历它的内容,并且提供一个字节码指令能够做什么和有什么样的参数的完整清单。 例如,获取上面的 `hello()` 函数的列表,可以在一个 Python 解析器中输入如下内容,然后运行它: + ``` import dis - dis.dis(hello) - ``` -函数 `dis.dis()` 将反汇编一个函数、方法、类、模块、编译过的 Python 代码对象、或者字符串包含的源代码,以及显示出一个人类可读的版本。`dis` 模块中另一个方便的功能是 `distb()`。你可以给它传递一个 Python 追溯对象,或者发生预期外情况时调用它,然后它将反汇编发生预期外情况时在调用栈上最顶端的函数,并显示它的字节码,以及插入一个指向到引发意外情况的指令的指针。 +函数 `dis.dis()` 将反汇编一个函数、方法、类、模块、编译过的 Python 代码对象、或者字符串包含的源代码,以及显示出一个人类可读的版本。`dis` 模块中另一个方便的功能是 `distb()`。你可以给它传递一个 Python 追溯对象,或者在发生预期外情况时调用它,然后它将在发生预期外情况时反汇编调用栈上最顶端的函数,并显示它的字节码,以及插入一个指向到引发意外情况的指令的指针。 它也可以用于查看 Python 为每个函数构建的编译后的代码对象,因为运行一个函数将会用到这些代码对象的属性。这里有一个查看 `hello()` 函数的示例: + ``` >>> hello.__code__ - ", line 1> - >>> hello.__code__.co_consts - (None, 'Hello, World!') - >>> hello.__code__.co_varnames - () - >>> hello.__code__.co_names - ('print',) - ``` -代码对象在函数中可以作为属性 `__code__` 来访问,并且携带了一些重要的属性: +代码对象在函数中可以以属性 `__code__` 来访问,并且携带了一些重要的属性: * `co_consts` 是存在于函数体内的任意实数的元组 * `co_varnames` 是函数体内使用的包含任意本地变量名字的元组 * `co_names` 是在函数体内引用的任意非本地名字的元组 - - -许多字节码指令 — 尤其是那些推入到栈中的加载值,或者在变量和属性中的存储值 — 在这些用作它们参数的元组中使用索引。 +许多字节码指令 —— 尤其是那些推入到栈中的加载值,或者在变量和属性中的存储值 —— 在这些元组中的索引作为它们参数。 因此,现在我们能够理解 `hello()` 函数中所列出的字节码: - 1. `LOAD_GLOBAL 0`:告诉 Python 通过 `co_names` (它是 `print` 函数)的索引 0 上的名字去查找它指向的全局对象,然后将它推入到计算栈 - 2. `LOAD_CONST 1`:带入 `co_consts` 在索引 1 上的实数值,并将它推入(索引 0 上的实数值是 `None`,它表示在 `co_consts` 中,因为 Python 函数调用有一个隐式的返回值 `None`,如果没有显式的返回表达式,就返回这个隐式的值 )。 - 3. `CALL_FUNCTION 1`:告诉 Python 去调用一个函数;它需要从栈中弹出一个位置参数,然后,新的栈顶将被函数调用。 +1. `LOAD_GLOBAL 0`:告诉 Python 通过 `co_names` (它是 `print` 函数)的索引 0 上的名字去查找它指向的全局对象,然后将它推入到计算栈 +2. `LOAD_CONST 1`:带入 `co_consts` 在索引 1 上的字面值,并将它推入(索引 0 上的字面值是 `None`,它表示在 `co_consts` 中,因为 Python 函数调用有一个隐式的返回值 `None`,如果没有显式的返回表达式,就返回这个隐式的值 )。 +3. `CALL_FUNCTION 1`:告诉 Python 去调用一个函数;它需要从栈中弹出一个位置参数,然后,新的栈顶将被函数调用。 - - -"原始的" 字节码 — 是非人类可读格式的字节 — 也可以在代码对象上作为 `co_code` 属性可用。如果你有兴趣尝试手工反汇编一个函数时,你可以从它们的十进制字节值中,使用列出 `dis.opname` 的方式去查看字节码指令的名字。 +“原始的” 字节码 —— 是非人类可读格式的字节 —— 也可以在代码对象上作为 `co_code` 属性可用。如果你有兴趣尝试手工反汇编一个函数时,你可以从它们的十进制字节值中,使用列出 `dis.opname` 的方式去查看字节码指令的名字。 ### 字节码的用处 -现在,你已经了解的足够多了,你可能会想 ” OK,我认为它很酷,但是知道这些有什么实际价值呢?“由于对它很好奇,我们去了解它,但是除了好奇之外,Python 字节码在几个方面还是非常有用的。 +现在,你已经了解的足够多了,你可能会想 “OK,我认为它很酷,但是知道这些有什么实际价值呢?”由于对它很好奇,我们去了解它,但是除了好奇之外,Python 字节码在几个方面还是非常有用的。 -首先,理解 Python 的运行模型可以帮你更好地理解你的代码。人们都开玩笑说,C 将成为一个 ”便携式汇编器“,在那里你可以很好地猜测出一段 C 代码转换成什么样的机器指令。理解 Python 字节码之后,你在使用 Python 时也具备同样的能力 — 如果你能预料到你的 Python 源代码将被转换成什么样的字节码,那么你可以知道如何更好地写和优化 Python 源代码。 +首先,理解 Python 的运行模型可以帮你更好地理解你的代码。人们都开玩笑说,C 是一种 “可移植汇编器”,你可以很好地猜测出一段 C 代码转换成什么样的机器指令。理解 Python 字节码之后,你在使用 Python 时也具备同样的能力 —— 如果你能预料到你的 Python 源代码将被转换成什么样的字节码,那么你可以知道如何更好地写和优化 Python 源代码。 第二,理解字节码可以帮你更好地回答有关 Python 的问题。比如,我经常看到一些 Python 新手困惑为什么某些结构比其它结构运行的更快(比如,为什么 `{}` 比 `dict()` 快)。知道如何去访问和阅读 Python 字节码将让你很容易回答这样的问题(尝试对比一下: `dis.dis("{}")` 与 `dis.dis("dict()")` 就会明白)。 @@ -131,7 +116,6 @@ dis.dis(hello) * 最后,CPython 解析器是一个开源软件,你可以在 [GitHub][1] 上阅读它。它在文件 `Python/ceval.c` 中实现了字节码解析器。[这是 Python 3.6.4 发行版中那个文件的链接][5];字节码指令是由第 1266 行开始的 `switch` 语句来处理的。 - 学习更多内容,参与到 James Bennett 的演讲,[有关字节的知识:理解 Python 字节码][6],将在 [PyCon Cleveland 2018][7] 召开。 -------------------------------------------------------------------------------- @@ -141,7 +125,7 @@ via: https://opensource.com/article/18/4/introduction-python-bytecode 作者:[James Bennett][a] 选题:[lujun9972](https://github.com/lujun9972) 译者:[qhwdw](https://github.com/qhwdw) -校对:[校对者ID](https://github.com/校对者ID) +校对:[wxy](https://github.com/wxy) 本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 diff --git a/published/201807/20180425 JavaScript Router.md b/published/201807/20180425 JavaScript Router.md new file mode 100644 index 0000000000..34bf9cff3d --- /dev/null +++ b/published/201807/20180425 JavaScript Router.md @@ -0,0 +1,215 @@ +JavaScript 路由器 +====== + +构建单页面应用(SPA)有许多的框架/库,但是我希望它们能少一些。我有一个解决方案,我想共享给大家。 + +``` +class Router { + constructor() { + this.routes = [] + } + + handle(pattern, handler) { + this.routes.push({ pattern, handler }) + } + + exec(pathname) { + for (const route of this.routes) { + if (typeof route.pattern === 'string') { + if (route.pattern === pathname) { + return route.handler() + } + } else if (route.pattern instanceof RegExp) { + const result = pathname.match(route.pattern) + if (result !== null) { + const params = result.slice(1).map(decodeURIComponent) + return route.handler(...params) + } + } + } + } +} +const router = new Router() + +router.handle('/', homePage) +router.handle(/^\/users\/([^\/]+)$/, userPage) +router.handle(/^\//, notFoundPage) + +function homePage() { + return 'home page' +} + +function userPage(username) { + return `${username}'s page` +} + +function notFoundPage() { + return 'not found page' +} + +console.log(router.exec('/')) // home page +console.log(router.exec('/users/john')) // john's page +console.log(router.exec('/foo')) // not found page +``` + +使用它你可以为一个 URL 模式添加处理程序。这个模式可能是一个简单的字符串或一个正则表达式。使用一个字符串将精确匹配它,但是如果使用一个正则表达式将允许你做一些更复杂的事情,比如,从用户页面上看到的 URL 中获取其中的一部分,或者匹配任何没有找到页面的 URL。 + +我将详细解释这个 `exec` 方法 … 正如我前面说的,URL 模式既有可能是一个字符串,也有可能是一个正则表达式,因此,我首先来检查它是否是一个字符串。如果模式与给定的路径名相同,它返回运行处理程序。如果是一个正则表达式,我们与给定的路径名进行匹配。如果匹配成功,它将获取的参数传递给处理程序,并返回运行这个处理程序。 + +### 工作示例 + +那个例子正好记录到了控制台。我们尝试将它整合到一个页面,看看它是什么样的。 + +``` + + + + + + Router Demo + + + + +
+ Home + Profile +
+
+ + +``` + +这是 `index.html`。对于单页面应用程序来说,你必须在服务器侧做一个特别的工作,因为所有未知的路径都将返回这个 `index.html`。在开发时,我们使用了一个 npm 工具调用了 [serve][1]。这个工具去提供静态内容。使用标志 `-s`/`--single`,你可以提供单页面应用程序。 + +使用 [Node.js][2] 和安装的 npm(它与 Node 一起安装),运行: + +``` +npm i -g serve +serve -s +``` + +那个 HTML 文件将脚本 `main.js` 加载为一个模块。在我们渲染的相关页面中,它有一个简单的 `
` 和一个 `
` 元素。 + +在 `main.js` 文件中: + +``` +const main = document.querySelector('main') +const result = router.exec(location.pathname) +main.innerHTML = result +``` + +我们调用传递了当前路径名为参数的 `router.exec()`,然后将 `result` 设置为 `main` 元素的 HTML。 + +如果你访问 `localhost` 并运行它,你将看到它能够正常工作,但不是预期中的来自一个单页面应用程序。当你点击链接时,单页面应用程序将不会被刷新。 + +我们将在每个点击的链接的锚点上附加事件监听器,防止出现缺省行为,并做出正确的渲染。因为一个单页面应用程序是一个动态的东西,你预期要创建的锚点链接是动态的,因此要添加事件监听器,我使用的是一个叫 [事件委托][3] 的方法。 + +我给整个文档附加一个点击事件监听器,然后去检查在锚点上(或内部)是否有点击事件。 + +在 `Router` 类中,我有一个注册回调的方法,在我们每次点击一个链接或者一个 `popstate` 事件发生时,这个方法将被运行。每次你使用浏览器的返回或者前进按钮时,`popstate` 事件将被发送。 + +为了方便其见,我们给回调传递与 `router.exec(location.pathname)` 相同的参数。 + +``` +class Router { + // ... + install(callback) { + const execCallback = () => { + callback(this.exec(location.pathname)) + } + + document.addEventListener('click', ev => { + if (ev.defaultPrevented + || ev.button !== 0 + || ev.ctrlKey + || ev.shiftKey + || ev.altKey + || ev.metaKey) { + return + } + + const a = ev.target.closest('a') + + if (a === null + || (a.target !== '' && a.target !== '_self') + || a.hostname !== location.hostname) { + return + } + + ev.preventDefault() + + if (a.href !== location.href) { + history.pushState(history.state, document.title, a.href) + execCallback() + } + }) + + addEventListener('popstate', execCallback) + execCallback() + } +} +``` + +对于链接的点击事件,除调用了回调之外,我们还使用 `history.pushState()` 去更新 URL。 + +我们将前面的 `main` 元素中的渲染移动到 `install` 回调中。 + +``` +router.install(result => { + main.innerHTML = result +}) +``` + +#### DOM + +你传递给路由器的这些处理程序并不需要返回一个字符串。如果你需要更多的东西,你可以返回实际的 DOM。如: + +``` +const homeTmpl = document.createElement('template') +homeTmpl.innerHTML = ` +
+

Home Page

+
+` + +function homePage() { + const page = homeTmpl.content.cloneNode(true) + // You can do `page.querySelector()` here... + return page +} + +``` + +现在,在 `install` 回调中,你可以去检查 `result` 是一个 `string` 还是一个 `Node`。 +``` +router.install(result => { + if (typeof result === 'string') { + main.innerHTML = result + } else if (result instanceof Node) { + main.innerHTML = '' + main.appendChild(result) + } +}) +``` + +这些就是基本的功能。我希望将它共享出来,因为我将在下篇文章中使用到这个路由器。 + +我已经以一个 [npm 包][4] 的形式将它发布了。 + +-------------------------------------------------------------------------------- + +via: https://nicolasparada.netlify.com/posts/js-router/ + +作者:[Nicolás Parada][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[qhwdw](https://github.com/qhwdw) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://nicolasparada.netlify.com/ +[1]:https://npm.im/serve +[2]:https://nodejs.org/ +[3]:https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Building_blocks/Events#Event_delegation +[4]:https://www.npmjs.com/package/@nicolasparada/router diff --git a/published/201807/20180428 How to get a core dump for a segfault on Linux.md b/published/201807/20180428 How to get a core dump for a segfault on Linux.md new file mode 100644 index 0000000000..0b45ebea9f --- /dev/null +++ b/published/201807/20180428 How to get a core dump for a segfault on Linux.md @@ -0,0 +1,178 @@ +在 Linux 上如何得到一个段错误的核心转储 +============================================================ + +本周工作中,我花了整整一周的时间来尝试调试一个段错误。我以前从来没有这样做过,我花了很长时间才弄清楚其中涉及的一些基本事情(获得核心转储、找到导致段错误的行号)。于是便有了这篇博客来解释如何做那些事情! + +在看完这篇博客后,你应该知道如何从“哦,我的程序出现段错误,但我不知道正在发生什么”到“我知道它出现段错误时的堆栈、行号了! “。 + +### 什么是段错误? + +“段错误segmentation fault”是指你的程序尝试访问不允许访问的内存地址的情况。这可能是由于: + +* 试图解引用空指针(你不被允许访问内存地址 `0`); +* 试图解引用其他一些不在你内存(LCTT 译注:指不在合法的内存地址区间内)中的指针; +* 一个已被破坏并且指向错误的地方的 C++ 虚表指针C++ vtable pointer,这导致程序尝试执行没有执行权限的内存中的指令; +* 其他一些我不明白的事情,比如我认为访问未对齐的内存地址也可能会导致段错误(LCTT 译注:在要求自然边界对齐的体系结构,如 MIPS、ARM 中更容易因非对齐访问产生段错误)。 + +这个“C++ 虚表指针”是我的程序发生段错误的情况。我可能会在未来的博客中解释这个,因为我最初并不知道任何关于 C++ 的知识,并且这种虚表查找导致程序段错误的情况也是我所不了解的。 + +但是!这篇博客后不是关于 C++ 问题的。让我们谈论的基本的东西,比如,我们如何得到一个核心转储? + +### 步骤1:运行 valgrind + +我发现找出为什么我的程序出现段错误的最简单的方式是使用 `valgrind`:我运行 + +``` +valgrind -v your-program +``` + +这给了我一个故障时的堆栈调用序列。 简洁! + +但我想也希望做一个更深入调查,并找出些 `valgrind` 没告诉我的信息! 所以我想获得一个核心转储并探索它。 + +### 如何获得一个核心转储 + +核心转储core dump是您的程序内存的一个副本,并且当您试图调试您的有问题的程序哪里出错的时候它非常有用。 + +当您的程序出现段错误,Linux 的内核有时会把一个核心转储写到磁盘。 当我最初试图获得一个核心转储时,我很长一段时间非常沮丧,因为 - Linux 没有生成核心转储!我的核心转储在哪里? + +这就是我最终做的事情: + +1. 在启动我的程序之前运行 `ulimit -c unlimited` +2. 运行 `sudo sysctl -w kernel.core_pattern=/tmp/core-%e.%p.%h.%t` + +### ulimit:设置核心转储的最大尺寸 + +`ulimit -c` 设置核心转储的最大尺寸。 它往往设置为 0,这意味着内核根本不会写核心转储。 它以千字节为单位。 `ulimit` 是按每个进程分别设置的 —— 你可以通过运行 `cat /proc/PID/limit` 看到一个进程的各种资源限制。 + +例如这些是我的系统上一个随便一个 Firefox 进程的资源限制: + +``` +$ cat /proc/6309/limits +Limit Soft Limit Hard Limit Units +Max cpu time unlimited unlimited seconds +Max file size unlimited unlimited bytes +Max data size unlimited unlimited bytes +Max stack size 8388608 unlimited bytes +Max core file size 0 unlimited bytes +Max resident set unlimited unlimited bytes +Max processes 30571 30571 processes +Max open files 1024 1048576 files +Max locked memory 65536 65536 bytes +Max address space unlimited unlimited bytes +Max file locks unlimited unlimited locks +Max pending signals 30571 30571 signals +Max msgqueue size 819200 819200 bytes +Max nice priority 0 0 +Max realtime priority 0 0 +Max realtime timeout unlimited unlimited us +``` + +内核在决定写入多大的核心转储文件时使用软限制soft limit(在这种情况下,`max core file size = 0`)。 您可以使用 shell 内置命令 `ulimit`(`ulimit -c unlimited`) 将软限制增加到硬限制hard limit。 + +### kernel.core_pattern:核心转储保存在哪里 + +`kernel.core_pattern` 是一个内核参数,或者叫 “sysctl 设置”,它控制 Linux 内核将核心转储文件写到磁盘的哪里。 + +内核参数是一种设定您的系统全局设置的方法。您可以通过运行 `sysctl -a` 得到一个包含每个内核参数的列表,或使用 `sysctl kernel.core_pattern` 来专门查看 `kernel.core_pattern` 设置。 + +所以 `sysctl -w kernel.core_pattern=/tmp/core-%e.%p.%h.%t` 将核心转储保存到目录 `/tmp` 下,并以 `core` 加上一系列能够标识(出故障的)进程的参数构成的后缀为文件名。 + +如果你想知道这些形如 `%e`、`%p` 的参数都表示什么,请参考 [man core][1]。 + +有一点很重要,`kernel.core_pattern` 是一个全局设置 —— 修改它的时候最好小心一点,因为有可能其它系统功能依赖于把它被设置为一个特定的方式(才能正常工作)。 + +### kernel.core_pattern 和 Ubuntu + +默认情况下在 ubuntu 系统中,`kernel.core_pattern` 被设置为下面的值: + +``` +$ sysctl kernel.core_pattern +kernel.core_pattern = |/usr/share/apport/apport %p %s %c %d %P +``` + +这引起了我的迷惑(这 apport 是干什么的,它对我的核心转储做了什么?)。以下关于这个我了解到的: + +* Ubuntu 使用一种叫做 apport 的系统来报告 apt 包有关的崩溃信息。 +* 设定 `kernel.core_pattern=|/usr/share/apport/apport %p %s %c %d %P` 意味着核心转储将被通过管道送给 `apport` 程序。 +* apport 的日志保存在文件 `/var/log/apport.log` 中。 +* apport 默认会忽略来自不属于 Ubuntu 软件包一部分的二进制文件的崩溃信息 + +我最终只是跳过了 apport,并把 `kernel.core_pattern` 重新设置为 `sysctl -w kernel.core_pattern=/tmp/core-%e.%p.%h.%t`,因为我在一台开发机上,我不在乎 apport 是否工作,我也不想尝试让 apport 把我的核心转储留在磁盘上。 + +### 现在你有了核心转储,接下来干什么? + +好的,现在我们了解了 `ulimit` 和 `kernel.core_pattern` ,并且实际上在磁盘的 `/tmp` 目录中有了一个核心转储文件。太好了!接下来干什么?我们仍然不知道该程序为什么会出现段错误! + +下一步将使用 `gdb` 打开核心转储文件并获取堆栈调用序列。 + +### 从 gdb 中得到堆栈调用序列 + +你可以像这样用 `gdb` 打开一个核心转储文件: + +``` +$ gdb -c my_core_file +``` + +接下来,我们想知道程序崩溃时的堆栈是什么样的。在 `gdb` 提示符下运行 `bt` 会给你一个调用序列backtrace。在我的例子里,`gdb` 没有为二进制文件加载符号信息,所以这些函数名就像 “??????”。幸运的是,(我们通过)加载符号修复了它。 + +下面是如何加载调试符号。 + +``` +symbol-file /path/to/my/binary +sharedlibrary +``` + +这从二进制文件及其引用的任何共享库中加载符号。一旦我这样做了,当我执行 `bt` 时,gdb 给了我一个带有行号的漂亮的堆栈跟踪! + +如果你想它能工作,二进制文件应该以带有调试符号信息的方式被编译。在试图找出程序崩溃的原因时,堆栈跟踪中的行号非常有帮助。:) + +### 查看每个线程的堆栈 + +通过以下方式在 `gdb` 中获取每个线程的调用栈! + +``` +thread apply all bt full +``` + +### gdb + 核心转储 = 惊喜 + + +如果你有一个带调试符号的核心转储以及 `gdb`,那太棒了!您可以上下查看调用堆栈(LCTT 译注:指跳进调用序列不同的函数中以便于查看局部变量),打印变量,并查看内存来得知发生了什么。这是最好的。 + +如果您仍然正在基于 gdb 向导来工作上,只打印出栈跟踪与bt也可以。 :) + +### ASAN + +另一种搞清楚您的段错误的方法是使用 AddressSanitizer 选项编译程序(“ASAN”,即 `$CC -fsanitize=address`)然后运行它。 本文中我不准备讨论那个,因为本文已经相当长了,并且在我的例子中打开 ASAN 后段错误消失了,可能是因为 ASAN 使用了一个不同的内存分配器(系统内存分配器,而不是 tcmalloc)。 + +在未来如果我能让 ASAN 工作,我可能会多写点有关它的东西。(LCTT 译注:这里指使用 ASAN 也能复现段错误) + +### 从一个核心转储得到一个堆栈跟踪真的很亲切! + +这个博客听起来很多,当我做这些的时候很困惑,但说真的,从一个段错误的程序中获得一个堆栈调用序列不需要那么多步骤: + +1. 试试用 `valgrind` + +如果那没用,或者你想要拿到一个核心转储来调查: + +1. 确保二进制文件编译时带有调试符号信息; +2. 正确的设置 `ulimit` 和 `kernel.core_pattern`; +3. 运行程序; +4. 一旦你用 `gdb` 调试核心转储了,加载符号并运行 `bt`; +5. 尝试找出发生了什么! + +我可以使用 `gdb` 弄清楚有个 C++ 的虚表条目指向一些被破坏的内存,这有点帮助,并且使我感觉好像更懂了 C++ 一点。也许有一天我们会更多地讨论如何使用 `gdb` 来查找问题! + +-------------------------------------------------------------------------------- + +via: https://jvns.ca/blog/2018/04/28/debugging-a-segfault-on-linux/ + +作者:[Julia Evans][a] +译者:[stephenxs](https://github.com/stephenxs) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://jvns.ca/about/ +[1]:http://man7.org/linux/man-pages/man5/core.5.html diff --git a/published/201807/20180429 Passwordless Auth- Client.md b/published/201807/20180429 Passwordless Auth- Client.md new file mode 100644 index 0000000000..0a14e7a871 --- /dev/null +++ b/published/201807/20180429 Passwordless Auth- Client.md @@ -0,0 +1,359 @@ +无密码验证:客户端 +====== + +我们继续 [无密码验证][1] 的文章。上一篇文章中,我们用 Go 写了一个 HTTP 服务,用这个服务来做无密码验证 API。今天,我们为它再写一个 JavaScript 客户端。 + +我们将使用 [这里的][2] 这个单页面应用程序(SPA)来展示使用的技术。如果你还没有读过它,请先读它。 + +记住流程: + +- 用户输入其 email。 +- 用户收到一个带有魔法链接的邮件。 +- 用户点击该链接、 +- 用户验证成功。 + +对于根 URL(`/`),我们将根据验证的状态分别使用两个不同的页面:一个是带有访问表单的页面,或者是已验证通过的用户的欢迎页面。另一个页面是验证回调的重定向页面。 + +### 伺服 + +我们将使用相同的 Go 服务器来为客户端提供服务,因此,在我们前面的 `main.go` 中添加一些路由: + +``` +router.Handle("GET", "/...", http.FileServer(SPAFileSystem{http.Dir("static")})) +``` + +``` +type SPAFileSystem struct { + fs http.FileSystem +} + +func (spa SPAFileSystem) Open(name string) (http.File, error) { + f, err := spa.fs.Open(name) + if err != nil { + return spa.fs.Open("index.html") + } + return f, nil +} +``` + +这个伺服文件放在 `static` 下,配合 `static/index.html` 作为回调。 + +你可以使用你自己的服务器,但是你得在服务器上启用 [CORS][3]。 + +### HTML + +我们来看一下那个 `static/index.html` 文件。 + +``` + + + + + + Passwordless Demo + + + + + +``` + +单页面应用程序的所有渲染由 JavaScript 来完成,因此,我们使用了一个空的 body 部分和一个 `main.js` 文件。 + +我们将使用 [上篇文章][2] 中的 Router。 + +### 渲染 + +现在,我们使用下面的内容来创建一个 `static/js/main.js` 文件: + +``` +import Router from 'https://unpkg.com/@nicolasparada/router' +import { isAuthenticated } from './auth.js' + +const router = new Router() + +router.handle('/', guard(view('home'))) +router.handle('/callback', view('callback')) +router.handle(/^\//, view('not-found')) + +router.install(async resultPromise => { + document.body.innerHTML = '' + document.body.appendChild(await resultPromise) +}) + +function view(name) { + return (...args) => import(`/js/pages/${name}-page.js`) + .then(m => m.default(...args)) +} + +function guard(fn1, fn2 = view('welcome')) { + return (...args) => isAuthenticated() + ? fn1(...args) + : fn2(...args) +} +``` + +与上篇文章不同的是,我们实现了一个 `isAuthenticated()` 函数和一个 `guard()` 函数,使用它去渲染两种验证状态的页面。因此,当用户访问 `/` 时,它将根据用户是否通过了验证来展示主页或者是欢迎页面。 + +### 验证 + +现在,我们来编写 `isAuthenticated()` 函数。使用下面的内容来创建一个 `static/js/auth.js` 文件: + +``` +export function getAuthUser() { + const authUserItem = localStorage.getItem('auth_user') + const expiresAtItem = localStorage.getItem('expires_at') + + if (authUserItem !== null && expiresAtItem !== null) { + const expiresAt = new Date(expiresAtItem) + + if (!isNaN(expiresAt.valueOf()) && expiresAt > new Date()) { + try { + return JSON.parse(authUserItem) + } catch (_) { } + } + } + + return null +} + +export function isAuthenticated() { + return localStorage.getItem('jwt') !== null && getAuthUser() !== null +} +``` + +当有人登入时,我们将保存 JSON 格式的 web 令牌、它的过期日期,以及在 `localStorage` 上的当前已验证用户。这个模块就是这个用处。 + + * `getAuthUser()` 用于从 `localStorage` 获取已认证的用户,以确认 JSON 格式的 Web 令牌没有过期。 + * `isAuthenticated()` 在前面的函数中用于去检查它是否没有返回 `null`。 + +### 获取 + +在继续这个页面之前,我将写一些与服务器 API 一起使用的 HTTP 工具。 + +我们使用以下的内容去创建一个 `static/js/http.js` 文件: + +``` +import { isAuthenticated } from './auth.js' + +function get(url, headers) { + return fetch(url, { + headers: Object.assign(getAuthHeader(), headers), + }).then(handleResponse) +} + +function post(url, body, headers) { + return fetch(url, { + method: 'POST', + headers: Object.assign(getAuthHeader(), { 'content-type': 'application/json' }, headers), + body: JSON.stringify(body), + }).then(handleResponse) +} + +function getAuthHeader() { + return isAuthenticated() + ? { authorization: `Bearer ${localStorage.getItem('jwt')}` } + : {} +} + +export async function handleResponse(res) { + const body = await res.clone().json().catch(() => res.text()) + const response = { + statusCode: res.status, + statusText: res.statusText, + headers: res.headers, + body, + } + if (!res.ok) { + const message = typeof body === 'object' && body !== null && 'message' in body + ? body.message + : typeof body === 'string' && body !== '' + ? body + : res.statusText + const err = new Error(message) + throw Object.assign(err, response) + } + return response +} + +export default { + get, + post, +} +``` + +这个模块导出了 `get()` 和 `post()` 函数。它们是 `fetch` API 的封装。当用户是已验证的,这二个函数注入一个 `Authorization: Bearer ` 头到请求中;这样服务器就能对我们进行身份验证。 + +### 欢迎页 + +我们现在来到欢迎页面。用如下的内容创建一个 `static/js/pages/welcome-page.js` 文件: + +``` +const template = document.createElement('template') +template.innerHTML = ` +

Passwordless Demo

+

Access

+
+ + +
+` + +export default function welcomePage() { + const page = template.content.cloneNode(true) + + page.getElementById('access-form') + .addEventListener('submit', onAccessFormSubmit) + + return page +} +``` + +这个页面使用一个 `HTMLTemplateElement` 作为视图。这只是一个输入用户 email 的简单表单。 + +为了避免干扰,我将跳过错误处理部分,只是将它们输出到控制台上。 + +现在,我们来写 `onAccessFormSubmit()` 函数。 + +``` +import http from '../http.js' + +function onAccessFormSubmit(ev) { + ev.preventDefault() + + const form = ev.currentTarget + const input = form.querySelector('input') + const email = input.value + + sendMagicLink(email).catch(err => { + console.error(err) + if (err.statusCode === 404 && wantToCreateAccount()) { + runCreateUserProgram(email) + } + }) +} + +function sendMagicLink(email) { + return http.post('/api/passwordless/start', { + email, + redirectUri: location.origin + '/callback', + }).then(() => { + alert('Magic link sent. Go check your email inbox.') + }) +} + +function wantToCreateAccount() { + return prompt('No user found. Do you want to create an account?') +} +``` + +它对 `/api/passwordless/start` 发起了 POST 请求,请求体中包含 `email` 和 `redirectUri`。在本例中它返回 `404 Not Found` 状态码时,我们将创建一个用户。 + +``` +function runCreateUserProgram(email) { + const username = prompt("Enter username") + if (username === null) return + + http.post('/api/users', { email, username }) + .then(res => res.body) + .then(user => sendMagicLink(user.email)) + .catch(console.error) +} +``` + +这个用户创建程序,首先询问用户名,然后使用 email 和用户名做一个 `POST` 请求到 `/api/users`。成功之后,给创建的用户发送一个魔法链接。 + +### 回调页 + +这是访问表单的全部功能,现在我们来做回调页面。使用如下的内容来创建一个 `static/js/pages/callback-page.js` 文件: + +``` +import http from '../http.js' + +const template = document.createElement('template') +template.innerHTML = ` +

Authenticating you

+` + +export default function callbackPage() { + const page = template.content.cloneNode(true) + + const hash = location.hash.substr(1) + const fragment = new URLSearchParams(hash) + for (const [k, v] of fragment.entries()) { + fragment.set(decodeURIComponent(k), decodeURIComponent(v)) + } + const jwt = fragment.get('jwt') + const expiresAt = fragment.get('expires_at') + + http.get('/api/auth_user', { authorization: `Bearer ${jwt}` }) + .then(res => res.body) + .then(authUser => { + localStorage.setItem('jwt', jwt) + localStorage.setItem('auth_user', JSON.stringify(authUser)) + localStorage.setItem('expires_at', expiresAt) + + location.replace('/') + }) + .catch(console.error) + + return page +} +``` + +请记住……当点击魔法链接时,我们会来到 `/api/passwordless/verify_redirect`,它将把我们重定向到重定向 URI,我们将放在哈希中的 JWT 和过期日期传递给 `/callback`。 + +回调页面解码 URL 中的哈希,提取这些参数去做一个 `GET` 请求到 `/api/auth_user`,用 JWT 保存所有数据到 `localStorage` 中。最后,重定向到主页面。 + +### 主页 + +创建如下内容的 `static/pages/home-page.js` 文件: + +``` +import { getAuthUser } from '../auth.js' + +export default function homePage() { + const authUser = getAuthUser() + + const template = document.createElement('template') + template.innerHTML = ` +

Passwordless Demo

+

Welcome back, ${authUser.username} 👋

+ + ` + + const page = template.content + + page.getElementById('logout-button') + .addEventListener('click', logout) + + return page +} + +function logout() { + localStorage.clear() + location.reload() +} +``` + +这个页面用于欢迎已验证用户,同时也有一个登出按钮。`logout()` 函数的功能只是清理掉 `localStorage` 并重载这个页面。 + +这就是全部内容了。我猜你在此之前已经看过这个 [demo][4] 了。当然,这些源代码也在同一个 [仓库][5] 中。 + +-------------------------------------------------------------------------------- + +via: https://nicolasparada.netlify.com/posts/passwordless-auth-client/ + +作者:[Nicolás Parada][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[qhwdw](https://github.com/qhwdw) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://nicolasparada.netlify.com/ +[1]:https://linux.cn/article-9748-1.html +[2]:https://linux.cn/article-9815-1.html +[3]:https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS +[4]:https://go-passwordless-demo.herokuapp.com/ +[5]:https://github.com/nicolasparada/go-passwordless-demo diff --git a/published/201807/20180430 3 practical Python tools- magic methods, iterators and generators, and method magic.md b/published/201807/20180430 3 practical Python tools- magic methods, iterators and generators, and method magic.md new file mode 100644 index 0000000000..7ddd3f33cc --- /dev/null +++ b/published/201807/20180430 3 practical Python tools- magic methods, iterators and generators, and method magic.md @@ -0,0 +1,406 @@ +日常 Python 编程优雅之道 +====== + +> 3 个可以使你的 Python 代码更优雅、可读、直观和易于维护的工具。 + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/serving-bowl-forks-dinner.png?itok=a3YqPwr5) + +Python 提供了一组独特的工具和语言特性来使你的代码更加优雅、可读和直观。为正确的问题选择合适的工具,你的代码将更易于维护。在本文中,我们将研究其中的三个工具:魔术方法、迭代器和生成器,以及方法魔术。 + +### 魔术方法 + +魔术方法可以看作是 Python 的管道。它们被称为“底层”方法,用于某些内置的方法、符号和操作。你可能熟悉的常见魔术方法是 `__init__()`,当我们想要初始化一个类的新实例时,它会被调用。 + +你可能已经看过其他常见的魔术方法,如 `__str__` 和 `__repr__`。Python 中有一整套魔术方法,通过实现其中的一些方法,我们可以修改一个对象的行为,甚至使其行为类似于内置数据类型,例如数字、列表或字典。 + +让我们创建一个 `Money` 类来示例: + +``` +class Money: + + currency_rates = { + '$': 1, + '€': 0.88, + } + + def __init__(self, symbol, amount): + self.symbol = symbol + self.amount = amount + + def __repr__(self): + return '%s%.2f' % (self.symbol, self.amount) + + def convert(self, other): + """ Convert other amount to our currency """ + new_amount = ( + other.amount / self.currency_rates[other.symbol] + * self.currency_rates[self.symbol]) + + return Money(self.symbol, new_amount) +``` + +该类定义为给定的货币符号和汇率定义了一个货币汇率,指定了一个初始化器(也称为构造函数),并实现 `__repr__`,因此当我们打印这个类时,我们会看到一个友好的表示,例如 `$2.00` ,这是一个带有货币符号和金额的 `Money('$', 2.00)` 实例。最重要的是,它定义了一种方法,允许你使用不同的汇率在不同的货币之间进行转换。 + +打开 Python shell,假设我们已经定义了使用两种不同货币的食品的成本,如下所示: + +``` +>>> soda_cost = Money('$', 5.25) +>>> soda_cost + $5.25 + +>>> pizza_cost = Money('€', 7.99) +>>> pizza_cost + €7.99 +``` + +我们可以使用魔术方法使得这个类的实例之间可以相互交互。假设我们希望能够将这个类的两个实例一起加在一起,即使它们是不同的货币。为了实现这一点,我们可以在 `Money` 类上实现 `__add__` 这个魔术方法: + +``` +class Money: + + # ... previously defined methods ... + + def __add__(self, other): + """ Add 2 Money instances using '+' """ + new_amount = self.amount + self.convert(other).amount + return Money(self.symbol, new_amount) +``` + +现在我们可以以非常直观的方式使用这个类: + +``` +>>> soda_cost = Money('$', 5.25) +>>> pizza_cost = Money('€', 7.99) +>>> soda_cost + pizza_cost + $14.33 +>>> pizza_cost + soda_cost + €12.61 +``` + +当我们将两个实例加在一起时,我们得到以第一个定义的货币符号所表示的结果。所有的转换都是在底层无缝完成的。如果我们想的话,我们也可以为减法实现 `__sub__`,为乘法实现 `__mul__` 等等。阅读[模拟数字类型][1]或[魔术方法指南][2]来获得更多信息。 + +我们学习到 `__add__` 映射到内置运算符 `+`。其他魔术方法可以映射到像 `[]` 这样的符号。例如,在字典中通过索引或键来获得一项,其实是使用了 `__getitem__` 方法: + +``` +>>> d = {'one': 1, 'two': 2} +>>> d['two'] +2 +>>> d.__getitem__('two') +2 +``` + +一些魔术方法甚至映射到内置函数,例如 `__len__()` 映射到 `len()`。 + +``` +class Alphabet: + letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' + + def __len__(self): + return len(self.letters) + +>>> my_alphabet = Alphabet() +>>> len(my_alphabet) + 26 +``` + +### 自定义迭代器 + +对于新的和经验丰富的 Python 开发者来说,自定义迭代器是一个非常强大的但令人迷惑的主题。 + +许多内置类型,例如列表、集合和字典,已经实现了允许它们在底层迭代的协议。这使我们可以轻松地遍历它们。 + +``` +>>> for food in ['Pizza', 'Fries']: + +         print(food + '. Yum!') + +Pizza. Yum! +Fries. Yum! +``` + +我们如何迭代我们自己的自定义类?首先,让我们来澄清一些术语。 + + * 要成为一个可迭代对象,一个类需要实现 `__iter__()` + * `__iter__()` 方法需要返回一个迭代器 + * 要成为一个迭代器,一个类需要实现 `__next__()`(或[在 Python 2][3]中是 `next()`),当没有更多的项要迭代时,必须抛出一个 `StopIteration` 异常。 + +呼!这听起来很复杂,但是一旦你记住了这些基本概念,你就可以在任何时候进行迭代。 + +我们什么时候想使用自定义迭代器?让我们想象一个场景,我们有一个 `Server` 实例在不同的端口上运行不同的服务,如 `http` 和 `ssh`。其中一些服务处于 `active` 状态,而其他服务则处于 `inactive` 状态。 + +``` +class Server: + + services = [ + {'active': False, 'protocol': 'ftp', 'port': 21}, + {'active': True, 'protocol': 'ssh', 'port': 22}, + {'active': True, 'protocol': 'http', 'port': 80}, + ] +``` + +当我们遍历 `Server` 实例时,我们只想遍历那些处于 `active` 的服务。让我们创建一个 `IterableServer` 类: + +``` +class IterableServer: +    def __init__(self): +        self.current_pos = 0 +    def __next__(self): +        pass  # TODO: 实现并记得抛出 StopIteration +``` + +首先,我们将当前位置初始化为 `0`。然后,我们定义一个 `__next__()` 方法来返回下一项。我们还将确保在没有更多项返回时抛出 `StopIteration`。到目前为止都很好!现在,让我们实现这个 `__next__()` 方法。 + +``` +class IterableServer: +    def __init__(self): +        self.current_pos = 0.  # 我们初始化当前位置为 0 +    def __iter__(self):  # 我们可以在这里返回 self,因为实现了 __next__ +        return self +    def __next__(self): +        while self.current_pos < len(self.services): +            service = self.services[self.current_pos] +            self.current_pos += 1 +            if service['active']: +                return service['protocol'], service['port'] +        raise StopIteration +    next = __next__  # 可选的 Python2 兼容性 +``` + +我们对列表中的服务进行遍历,而当前的位置小于服务的个数,但只有在服务处于活动状态时才返回。一旦我们遍历完服务,就会抛出一个 `StopIteration` 异常。 + + +因为我们实现了 `__next__()` 方法,当它耗尽时,它会抛出 `StopIteration`。我们可以从 `__iter__()` 返回 `self`,因为 `IterableServer` 类遵循 `iterable` 协议。 + +现在我们可以遍历一个 `IterableServer` 实例,这将允许我们查看每个处于活动的服务,如下所示: + +``` +>>> for protocol, port in IterableServer(): + +        print('service %s is running on port %d' % (protocol, port)) + +service ssh is running on port 22 + +service http is running on port 21 + +``` + +太棒了,但我们可以做得更好!在这样类似的实例中,我们的迭代器不需要维护大量的状态,我们可以简化代码并使用 [generator(生成器)][4] 来代替。 + +``` +class Server: +    services = [ +        {'active': False, 'protocol': 'ftp', 'port': 21}, +        {'active': True, 'protocol': 'ssh', 'port': 22}, +        {'active': True, 'protocol': 'http', 'port': 21}, +    ] +    def __iter__(self): +        for service in self.services: +            if service['active']: +                yield service['protocol'], service['port'] +``` + +`yield` 关键字到底是什么?在定义生成器函数时使用 yield。这有点像 `return`,虽然 `return` 在返回值后退出函数,但 `yield` 会暂停执行直到下次调用它。这允许你的生成器的功能在它恢复之前保持状态。查看 [yield 的文档][5]以了解更多信息。使用生成器,我们不必通过记住我们的位置来手动维护状态。生成器只知道两件事:它现在需要做什么以及计算下一个项目需要做什么。一旦我们到达执行点,即 `yield` 不再被调用,我们就知道停止迭代。 + +这是因为一些内置的 Python 魔法。在 [Python 关于 `__iter__()` 的文档][6]中我们可以看到,如果 `__iter__()` 是作为一个生成器实现的,它将自动返回一个迭代器对象,该对象提供 `__iter__()` 和 `__next__()` 方法。阅读这篇很棒的文章,深入了解[迭代器,可迭代对象和生成器][7]。 + +### 方法魔法 + +由于其独特的方面,Python 提供了一些有趣的方法魔法作为语言的一部分。 + +其中一个例子是别名功能。因为函数只是对象,所以我们可以将它们赋值给多个变量。例如: + +``` +>>> def foo(): +       return 'foo' +>>> foo() +'foo' +>>> bar = foo +>>> bar() +'foo' +``` + +我们稍后会看到它的作用。 + +Python 提供了一个方便的内置函数[称为 `getattr()`][8],它接受 `object, name, default` 参数并在 `object` 上返回属性 `name`。这种编程方式允许我们访问实例变量和方法。例如: + +``` +>>> class Dog: + sound = 'Bark' + def speak(self): + print(self.sound + '!', self.sound + '!') + +>>> fido = Dog() + +>>> fido.sound +'Bark' +>>> getattr(fido, 'sound') +'Bark' + +>>> fido.speak +> +>>> getattr(fido, 'speak') +> + + +>>> fido.speak() +Bark! Bark! +>>> speak_method = getattr(fido, 'speak') +>>> speak_method() +Bark! Bark! +``` + +这是一个很酷的技巧,但是我们如何在实际中使用 `getattr` 呢?让我们看一个例子,我们编写一个小型命令行工具来动态处理命令。 + +``` +class Operations: +    def say_hi(self, name): +        print('Hello,', name) +    def say_bye(self, name): +        print ('Goodbye,', name) +    def default(self, arg): +        print ('This operation is not supported.') + +if __name__ == '__main__': +    operations = Operations() +    # 假设我们做了错误处理 +    command, argument = input('> ').split() +    func_to_call = getattr(operations, command, operations.default) +    func_to_call(argument) +``` + +脚本的输出是: + +``` +$ python getattr.py +> say_hi Nina +Hello, Nina +> blah blah +This operation is not supported. +``` + +接下来,我们来看看 `partial`。例如,`functool.partial(func, *args, **kwargs)` 允许你返回一个新的 [partial 对象][9],它的行为类似 `func`,参数是 `args` 和 `kwargs`。如果传入更多的 `args`,它们会被附加到 `args`。如果传入更多的 `kwargs`,它们会扩展并覆盖 `kwargs`。让我们通过一个简短的例子来看看: + +``` +>>> from functools import partial +>>> basetwo = partial(int, base=2) +>>> basetwo + +>>> basetwo('10010') +18 + +# 这等同于 +>>> int('10010', base=2) +``` + +让我们看看在我喜欢的一个[名为 `agithub`][10] 的库中的一些示例代码中,这个方法魔术是如何结合在一起的,这是一个(名字起得很 low 的) REST API 客户端,它具有透明的语法,允许你以最小的配置快速构建任何 REST API 原型(不仅仅是 GitHub)。我发现这个项目很有趣,因为它非常强大,但只有大约 400 行 Python 代码。你可以在大约 30 行配置代码中添加对任何 REST API 的支持。`agithub` 知道协议所需的一切(`REST`、`HTTP`、`TCP`),但它不考虑上游 API。让我们深入到它的实现中。 + +以下是我们如何为 GitHub API 和任何其他相关连接属性定义端点 URL 的简化版本。在这里查看[完整代码][11]。 + +``` +class GitHub(API): +    def __init__(self, token=None, *args, **kwargs): +        props = ConnectionProperties(api_url = kwargs.pop('api_url', 'api.github.com')) +        self.setClient(Client(*args, **kwargs)) +        self.setConnectionProperties(props) +``` + +然后,一旦配置了[访问令牌][12],就可以开始使用 [GitHub API][13]。 + +``` +>>> gh = GitHub('token') +>>> status, data = gh.user.repos.get(visibility='public', sort='created') +>>> # ^ 映射到 GET /user/repos +>>> data +... ['tweeter', 'snipey', '...'] +``` + +请注意,你要确保 URL 拼写正确,因为我们没有验证 URL。如果 URL 不存在或出现了其他任何错误,将返回 API 抛出的错误。那么,这一切是如何运作的呢?让我们找出答案。首先,我们将查看一个 [`API` 类][14]的简化示例: + +``` +class API: +    # ... other methods ... +    def __getattr__(self, key): +        return IncompleteRequest(self.client).__getattr__(key) +    __getitem__ = __getattr__ +``` + +在 `API` 类上的每次调用都会调用 [`IncompleteRequest` 类][15]作为指定的 `key`。 + +``` +class IncompleteRequest: +    # ... other methods ... +    def __getattr__(self, key): +        if key in self.client.http_methods: +            htmlMethod = getattr(self.client, key) +            return partial(htmlMethod, url=self.url) +        else: +            self.url += '/' + str(key) +            return self +    __getitem__ = __getattr__ + +class Client: +    http_methods = ('get')  # 还有 post, put, patch 等等。 +    def get(self, url, headers={}, **params): +        return self.request('GET', url, None, headers) +``` + +如果最后一次调用不是 HTTP 方法(如 `get`、`post` 等),则返回带有附加路径的 `IncompleteRequest`。否则,它从[`Client` 类][16]获取 HTTP 方法对应的正确函数,并返回 `partial`。 + +如果我们给出一个不存在的路径会发生什么? + +``` +>>> status, data = this.path.doesnt.exist.get() +>>> status +... 404 +``` + +因为 `__getattr__` 别名为 `__getitem__`: + +``` +>>> owner, repo = 'nnja', 'tweeter' +>>> status, data = gh.repos[owner][repo].pulls.get() +>>> # ^ Maps to GET /repos/nnja/tweeter/pulls +>>> data +.... # {....} +``` + +这真心是一些方法魔术! + +### 了解更多 + +Python 提供了大量工具,使你的代码更优雅,更易于阅读和理解。挑战在于找到合适的工具来完成工作,但我希望本文为你的工具箱添加了一些新工具。而且,如果你想更进一步,你可以在我的博客 [nnja.io][17] 上阅读有关装饰器、上下文管理器、上下文生成器和命名元组的内容。随着你成为一名更好的 Python 开发人员,我鼓励你到那里阅读一些设计良好的项目的源代码。[Requests][18] 和 [Flask][19] 是两个很好的起步的代码库。 + + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/4/elegant-solutions-everyday-python-problems + +作者:[Nina Zakharenko][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[MjSeven](https://github.com/MjSeven) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://opensource.com/users/nnja +[1]:https://docs.python.org/3/reference/datamodel.html#emulating-numeric-types +[2]:https://rszalski.github.io/magicmethods/ +[3]:https://docs.python.org/2/library/stdtypes.html#iterator.next +[4]:https://docs.python.org/3/library/stdtypes.html#generator-types +[5]:https://docs.python.org/3/reference/expressions.html#yieldexpr +[6]:https://docs.python.org/3/reference/datamodel.html#object.__iter__ +[7]:http://nvie.com/posts/iterators-vs-generators/ +[8]:https://docs.python.org/3/library/functions.html#getattr +[9]:https://docs.python.org/3/library/functools.html#functools.partial +[10]:https://github.com/mozilla/agithub +[11]:https://github.com/mozilla/agithub/blob/master/agithub/GitHub.py +[12]:https://github.com/settings/tokens +[13]:https://developer.github.com/v3/repos/#list-your-repositories +[14]:https://github.com/mozilla/agithub/blob/dbf7014e2504333c58a39153aa11bbbdd080f6ac/agithub/base.py#L30-L58 +[15]:https://github.com/mozilla/agithub/blob/dbf7014e2504333c58a39153aa11bbbdd080f6ac/agithub/base.py#L60-L100 +[16]:https://github.com/mozilla/agithub/blob/dbf7014e2504333c58a39153aa11bbbdd080f6ac/agithub/base.py#L102-L231 +[17]:http://nnja.io +[18]:https://github.com/requests/requests +[19]:https://github.com/pallets/flask +[20]:https://us.pycon.org/2018/schedule/presentation/164/ +[21]:https://us.pycon.org/2018/ diff --git a/published/201807/20180502 Customizing your text colors on the Linux command line.md b/published/201807/20180502 Customizing your text colors on the Linux command line.md new file mode 100644 index 0000000000..393e857ed2 --- /dev/null +++ b/published/201807/20180502 Customizing your text colors on the Linux command line.md @@ -0,0 +1,165 @@ +在 Linux 命令行中自定义文本颜色 +====== + +> 在 Linux 命令行当中使用不同颜色以期提供一种根据文件类型来识别文件的简单方式。你可以修改这些颜色,但是在做之前应该对你做的事情有充分的理由。 + +![](https://images.idgesg.net/images/article/2018/05/numbers-100756457-large.jpg) + +如果你在 Linux 命令行上花费了大量的时间(如果没有,那么你可能不会读这篇文章),你无疑注意到了 `ls` 以多种不同的颜色显示文件。你可能也注意到了一些区别 —— 目录是一种颜色,可执行文件是另一种颜色等等。 + +这一切是如何发生的呢?以及,你可以选择哪些选项来改变颜色分配可能就不是很多人都知道的。 + +一种方法是运行 `dircolors` 命令得到一大堆展示了如何指定这些颜色的数据。它会显示以下这些东西: + +``` +$ dircolors +LS_COLORS='rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do +=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=00:su=37;41:sg +=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01 +;31:*.tgz=01;31:*.arc=01;31:*.arj=01;31:*.taz=01;31:*.lha=01 +;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=0 +1;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31 +:*.dz=01;31:*.gz=01;31:*.lrz=01;31:*.lz=01;31:*.lzo=01;31:*. +xz=01;31:*.zst=01;31:*.tzst=01;31:*.bz2=01;31:*.bz=01;31:*.t +bz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.j +ar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.a +lz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.r +z=01;31:*.cab=01;31:*.jpg=01;35:*.jpeg=01;35:*.mjpg=01;35:*. +mjpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35: +*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35: +*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;3 +5:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01; +35:*.mkv=01;35:*.webm=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01 +;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01 +;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01 +;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;3 +5:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.ogv=01;3 +5:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.m4a=00;3 +6:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00; +36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.oga=00;36:*.opus=00; +36:*.spx=00;36:*.xspf=00;36:'; +export LS_COLORS +``` + +如果你擅长解析文件,那么你可能会注意到这个列表有一种模式patten。用冒号分隔开,你会看到这样的东西: + +``` +$ dircolors | tr ":" "\n" | head -10 +LS_COLORS='rs=0 +di=01;34 +ln=01;36 +mh=00 +pi=40;33 +so=01;35 +do=01;35 +bd=40;33;01 +cd=40;33;01 +or=40;31;01 +``` + +OK,这里有一个模式 —— 一系列定义,有一到三个数字组件。我们来看看其中的一个定义。 + +``` +pi=40;33 +``` + +有些人可能会问的第一个问题是“pi 是什么?”在这里,我们研究的是颜色和文件类型,所以这显然不是以 3.14 开头的那个有趣的数字。当然不是,这个 “pi” 代表 “pipe(管道)” —— Linux 系统上的一种特殊类型的文件,它可以将数据从一个程序传递给另一个程序。所以,让我们建立一个管道。 + +``` +$ mknod /tmp/mypipe p +$ ls -l /tmp/mypipe +prw-rw-r-- 1 shs shs 0 May 1 14:00 /tmp/mypipe +``` + +当我们在终端窗口中查看我们的管道和其他几个文件时,颜色差异非常明显。 + +![font colors][1] + +在 `pi` 的定义中(如上所示),“40” 使文件在终端(或 PuTTY)窗口中使用黑色背景显示,31 使字体颜色变红。管道是特殊的文件,这种特殊的处理使它们在目录列表中突出显示。 + +`bd` 和 `cd` 定义是相同的 —— `40;33;01`,它有一个额外的设置。这个设置会导致 块设备block device(bd)和 字符设备character device(cd)以黑色背景,橙色字体和另一种效果显示 —— 字符将以粗体显示。 + +以下列表显示由文件类型file type所指定的颜色和字体分配: + +``` +setting file type +======= ========= +rs=0 reset to no color +di=01;34 directory +ln=01;36 link +mh=00 multi-hard link +pi=40;33 pipe +so=01;35 socket +do=01;35 door +bd=40;33;01 block device +cd=40;33;01 character device +or=40;31;01 orphan +mi=00 missing? +su=37;41 setuid +sg=30;43 setgid +ca=30;41 file with capability +tw=30;42 directory with sticky bit and world writable +ow=34;42 directory that is world writable +st=37;44 directory with sticky bit +ex=01;93 executable +``` + +你可能已经注意到,在 `dircolors` 命令输出中,我们的大多数定义都以星号开头(例如,`*.wav=00;36`)。这些按文件扩展名file extension而不是文件类型定义显示属性。这有一个示例: + +``` +$ dircolors | tr ":" "\n" | tail -10 +*.mpc=00;36 +*.ogg=00;36 +*.ra=00;36 +*.wav=00;36 +*.oga=00;36 +*.opus=00;36 +*.spx=00;36 +*.xspf=00;36 +'; +export LS_COLORS +``` + +这些设置(上面列表中所有的 `00;36`)将使这些文件名以青色显示。可用的颜色如下所示。 + +![all colors][2] + +### 如何改变设置 + +你要使用 `ls` 的别名来打开颜色显示功能。这通常是 Linux 系统上的默认设置,看起来是这样的: + +``` +alias ls='ls --color=auto' +``` + +如果要关闭字体颜色,可以运行 `unalias ls` 命令,然后文件列表将仅以默认字体颜色显示。 + +你可以通过修改 `$LS_COLORS` 设置和导出修改后的设置来更改文本颜色。 + +``` +$ export LS_COLORS='rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;... +``` + +注意:上面的命令由于太长被截断了。 + +如果希望文本颜色的修改是永久性的,则需要将修改后的 `$LS_COLORS` 定义添加到一个启动文件中,例如 `.bashrc`。 + +### 更多关于命令行文本 + +你可以在 NetworkWorld 的 [2016 年 11 月][3]的帖子中找到有关文本颜色的其他信息。 + +--- + +via: https://www.networkworld.com/article/3269587/linux/customizing-your-text-colors-on-the-linux-command-line.html + +作者:[Sandra Henry-Stocker][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[MjSeven](https://github.com/MjSeven) +校对:[pityonline](https://github.com/pityonline) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://www.networkworld.com/author/Sandra-Henry_Stocker/ +[1]: https://images.idgesg.net/images/article/2018/05/font-colors-100756483-large.jpg +[2]: https://images.techhive.com/images/article/2016/11/all-colors-100691990-large.jpg +[3]: https://www.networkworld.com/article/3138909/linux/coloring-your-world-with-ls-colors.html diff --git a/published/201807/20180508 How To Check Ubuntu Version and Other System Information Easily.md b/published/201807/20180508 How To Check Ubuntu Version and Other System Information Easily.md new file mode 100644 index 0000000000..48c5f617ed --- /dev/null +++ b/published/201807/20180508 How To Check Ubuntu Version and Other System Information Easily.md @@ -0,0 +1,134 @@ +如何轻松地检查 Ubuntu 版本以及其它系统信息 +====== + +> 摘要:想知道你正在使用的 Ubuntu 具体是什么版本吗?这篇文档将告诉你如何检查你的 Ubuntu 版本、桌面环境以及其他相关的系统信息。 + +通常,你能非常容易的通过命令行或者图形界面获取你正在使用的 Ubuntu 的版本。当你正在尝试学习一篇互联网上的入门教材或者正在从各种各样的论坛里获取帮助的时候,知道当前正在使用的 Ubuntu 确切的版本号、桌面环境以及其他的系统信息将是尤为重要的。 + +在这篇简短的文章中,作者将展示各种检查 [Ubuntu][1] 版本以及其他常用的系统信息的方法。 + +### 如何在命令行检查 Ubuntu 版本 + +这个是获得 Ubuntu 版本的最好的办法。我本想先展示如何用图形界面做到这一点,但是我决定还是先从命令行方法说起,因为这种方法不依赖于你使用的任何[桌面环境][2]。 你可以在 Ubuntu 的任何变种系统上使用这种方法。 + +打开你的命令行终端 (`Ctrl+Alt+T`), 键入下面的命令: + +``` +lsb_release -a +``` + +上面命令的输出应该如下: + +``` +No LSB modules are available. +Distributor ID: Ubuntu +Description: Ubuntu 16.04.4 LTS +Release: 16.04 +Codename: xenial +``` + +![How to check Ubuntu version in command line][3] + +正像你所看到的,当前我的系统安装的 Ubuntu 版本是 Ubuntu 16.04, 版本代号: Xenial。 + +且慢!为什么版本描述中显示的是 Ubuntu 16.04.4 而发行版本是 16.04?到底哪个才是正确的版本?16.04 还是 16.04.4? 这两者之间有什么区别? + +如果言简意赅的回答这个问题的话,那么答案应该是你正在使用 Ubuntu 16.04。这个是基准版本,而 16.04.4 进一步指明这是 16.04 的第四个补丁版本。你可以将补丁版本理解为 Windows 世界里的服务包。在这里,16.04 和 16.04.4 都是正确的版本号。 + +那么输出的 Xenial 又是什么?那正是 Ubuntu 16.04 的版本代号。你可以阅读下面这篇文章获取更多信息:[了解 Ubuntu 的命名惯例][4]。 + +#### 其他一些获取 Ubuntu 版本的方法 + +你也可以使用下面任意的命令得到 Ubuntu 的版本: + +``` +cat /etc/lsb-release +``` + +输出如下信息: + +``` +DISTRIB_ID=Ubuntu +DISTRIB_RELEASE=16.04 +DISTRIB_CODENAME=xenial +DISTRIB_DESCRIPTION="Ubuntu 16.04.4 LTS" +``` + +![How to check Ubuntu version in command line][5] + + +你还可以使用下面的命令来获得 Ubuntu 版本: + +``` +cat /etc/issue +``` + + +命令行的输出将会如下: + +``` +Ubuntu 16.04.4 LTS \n \l +``` + +不要介意输出末尾的\n \l. 这里 Ubuntu 版本就是 16.04.4,或者更加简单:16.04。 + + +### 如何在图形界面下得到 Ubuntu 版本 + +在图形界面下获取 Ubuntu 版本更是小事一桩。这里我使用了 Ubuntu 18.04 的图形界面系统 GNOME 的屏幕截图来展示如何做到这一点。如果你在使用 Unity 或者别的桌面环境的话,显示可能会有所不同。这也是为什么我推荐使用命令行方式来获得版本的原因:你不用依赖形形色色的图形界面。 + +下面我来展示如何在桌面环境获取 Ubuntu 版本。 + +进入‘系统设置’并点击下面的‘详细信息’栏。 + +![Finding Ubuntu version graphically][6] + +你将会看到系统的 Ubuntu 版本和其他和桌面系统有关的系统信息 这里的截图来自 [GNOME][7] 。 + +![Finding Ubuntu version graphically][8] + +### 如何知道桌面环境以及其他的系统信息 + +你刚才学习的是如何得到 Ubuntu 的版本信息,那么如何知道桌面环境呢? 更进一步, 如果你还想知道当前使用的 Linux 内核版本呢? + +有各种各样的命令你可以用来得到这些信息,不过今天我想推荐一个命令行工具, 叫做 [Neofetch][9]。 这个工具能在命令行完美展示系统信息,包括 Ubuntu 或者其他 Linux 发行版的系统图标。 + +用下面的命令安装 Neofetch: + +``` +sudo apt install neofetch +``` + +安装成功后,运行 `neofetch` 将会优雅的展示系统的信息如下。 + +![System information in Linux terminal][10] + +如你所见,`neofetch` 完全展示了 Linux 内核版本、Ubuntu 的版本、桌面系统版本以及环境、主题和图标等等信息。 + + +希望我如上展示方法能帮到你更快的找到你正在使用的 Ubuntu 版本和其他系统信息。如果你对这篇文章有其他的建议,欢迎在评论栏里留言。 + +再见。:) + +-------------------------------------------------------------------------------- + +via: https://itsfoss.com/how-to-know-ubuntu-unity-version/ + +作者:[Abhishek Prakash][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[DavidChenLiang](https://github.com/davidchenliang) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://itsfoss.com/author/abhishek/ +[1]:https://www.ubuntu.com/ +[2]:https://en.wikipedia.org/wiki/Desktop_environment +[3]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2013/03/check-ubuntu-version-command-line-1-800x216.jpeg +[4]:https://itsfoss.com/linux-code-names/ +[5]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2013/03/check-ubuntu-version-command-line-2-800x185.jpeg +[6]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2013/03/ubuntu-version-system-settings.jpeg +[7]:https://www.gnome.org/ +[8]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2013/03/checking-ubuntu-version-gui.jpeg +[9]:https://itsfoss.com/display-linux-logo-in-ascii/ +[10]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2013/03/ubuntu-system-information-terminal-800x400.jpeg diff --git a/translated/talk/20180514 A year as Android Engineer.md b/published/201807/20180514 A year as Android Engineer.md similarity index 79% rename from translated/talk/20180514 A year as Android Engineer.md rename to published/201807/20180514 A year as Android Engineer.md index 940d479d98..573b0ef825 100644 --- a/translated/talk/20180514 A year as Android Engineer.md +++ b/published/201807/20180514 A year as Android Engineer.md @@ -2,7 +2,8 @@ Android 工程师的一年 ============================================================ ![](https://cdn-images-1.medium.com/max/2000/1*tqshw1o4JZZlA1HW3Cki1Q.png) ->妙绝的绘画来自 [Miquel Beltran][0] + +> 这幅妙绝的绘画来自 [Miquel Beltran][0] 我的技术生涯,从两年前算起。开始是 QA 测试员,一年后就转入开发人员角色。没怎么努力,也没有投入过多的个人时间。 @@ -12,7 +13,7 @@ Android 工程师的一年 我的第一个职位角色, Android 开发者,开始于一年前。我工作的这家公司,可以花一半的时间去尝试其它角色的工作,这给我从 QA 职位转到 Android 开发者职位创造了机会。 -这一转变归功于我在晚上和周末投入学习 Android 的时间。我通过了[ Android 基础纳米学位][3]、[Andriod 工程师纳米学位][4]课程,也获得了[ Google 开发者认证][5]。这部分的详细故事在[这儿][6]。 +这一转变归功于我在晚上和周末投入学习 Android 的时间。我通过了 [Android 基础纳米学位][3]、[Andriod 工程师纳米学位][4]课程,也获得了 [Google 开发者认证][5]。这部分的详细故事在[这儿][6]。 两个月后,公司雇佣了另一位 QA,我转向全职工作。挑战从此开始! @@ -46,29 +47,27 @@ Android 工程师的一年 一个例子就是拉取代码进行公开展示和代码审查。有是我会请同事私下检查我的代码,并不想被公开拉取,向任何人展示。 -其他时候,当我做代码审查时,会花好几分钟盯着"批准"按纽犹豫不决,在担心审查通过的会被其他同事找出毛病。 +其他时候,当我做代码审查时,会花好几分钟盯着“批准”按纽犹豫不决,在担心审查通过的代码会被其他同事找出毛病。 当我在一些事上持反对意见时,由于缺乏相关知识,担心被坐冷板凳,从来没有大声说出来过。 > 某些时间我会请同事私下[...]检查我的代码,以避免被公开展示。 -* * * - ### 新的公司,新的挑战 -后来,我手边有了个新的机会。感谢曾经和我共事的朋友,我被[ Babbel ][7]邀请去参加初级 Android 工程师职位的招聘流程。 +后来,我手边有了个新的机会。感谢曾经和我共事的朋友,我被 [Babbel][7] 邀请去参加初级 Android 工程师职位的招聘流程。 我见到了他们的团队,同时自告奋勇的在他们办公室主持了一次本地会议。此事让我下定决心要申请这个职位。我喜欢公司的箴言:全民学习。其次,公司每个人都非常友善,在那儿工作看起来很愉快!但我没有马上申请,因为我认为自己不够好,所以为什么能申请呢? -还好我的朋友和搭档推动我这样做,他们给了我发送简历的力量和勇气。过后不久就进入了面试流程。这很简单:以很小的应该程序来进行编码挑战,随后是和团队一起的技术面试,之后是和招聘经理间关于团队合作的面试。 +还好我的朋友和搭档推动我这样做,他们给了我发送简历的力量和勇气。过后不久就进入了面试流程。这很简单:以很小的程序的形式来进行编码挑战,随后是和团队一起的技术面试,之后是和招聘经理间关于团队合作的面试。 #### 招聘过程 我用周未的时间来完成编码挑战的项目,并在周一就立即发送过去。不久就受邀去当场面试。 -技术面试是关于编程挑战本身,我们谈论了 Android 好的不好的、我为什么以这种方式实现这功能,以及如何改进等等。随后是招聘经理进行的一次简短的关于团队合作面试,也有涉及到编程挑战的事,我们谈到了我面临的挑战,我如何解决这些问题,等等。 +技术面试是关于编程挑战本身,我们谈论了 Android 好的不好的地方、我为什么以这种方式实现这功能,以及如何改进等等。随后是招聘经理进行的一次简短的关于团队合作面试,也有涉及到编程挑战的事,我们谈到了我面临的挑战,我如何解决这些问题,等等。 -最后,通过面试,得到 offer, 我授受了! +最后,通过面试,得到 offer,我授受了! 我的 Android 工程师生涯的第一年,有九个月在一个公司,后面三个月在当前的公司。 @@ -88,7 +87,7 @@ Android 工程师的一年 两次三次后,压力就堵到胸口。为什么我还不知道?为什么就那么难理解?这种状态让我焦虑万分。 -我意识到我需要承认我确实不懂某个特定的主题,但第一步是要知道有这么个概念!有是,仅仅需要的就是更多的时间、更多的练习,最终会"在大脑中完全演绎" :-) +我意识到我需要承认我确实不懂某个特定的主题,但第一步是要知道有这么个概念!有时,仅仅需要的就是更多的时间、更多的练习,最终会“在大脑中完全演绎” :-) 例如,我常常为 Java 的接口类和抽象类所困扰,不管看了多少的例子,还是不能完全明白他们之间的区别。但一旦我使用后,即使还不能解释其工作原理,也知道了怎么使用以及什么时候使用。 @@ -102,19 +101,13 @@ Android 工程师的一年 工程师的角色不仅仅是编码,而是广泛的技能。 我仍然处于旅程的起点,在掌握它的道路上,我想着重于以下几点: -* 交流:因为英文不是我的母语,所以有的时候我会努力传达我的想法,这在我工作中是至关重要的。我可以通过写作,阅读和交谈来解决这个问题。 - -* 提有建设性的反馈意见: 我想给同事有意义的反馈,这样我们一起共同发展。 - -* 为我的成就感到骄傲: 我需要创建一个列表来跟踪各种成就,无论大小,或整体进步,所以当我挣扎时我可以回顾并感觉良好。 - -* 不要着迷于不知道的事情: 当有很多新事物出现时很难做到都知道,所以只关注必须的,及手头项目需要的东西,这非常重要的。 - -* 多和同事分享知识。我是初级的并不意味着没有可以分享的!我需要持续分享我感兴趣的的文章及讨论话题。我知道同事们会感激我的。 - -* 耐心和持续学习: 和现在一样的保持不断学习,但对自己要有更多耐心。 - -* 自我保健: 随时注意休息,不要为难自己。 放松也富有成效。 +* 交流:因为英文不是我的母语,所以有的时候我需要努力传达我的想法,这在我工作中是至关重要的。我可以通过写作,阅读和交谈来解决这个问题。 +* 提有建设性的反馈意见:我想给同事有意义的反馈,这样我们一起共同发展。 +* 为我的成就感到骄傲:我需要创建一个列表来跟踪各种成就,无论大小,或整体进步,所以当我挣扎时我可以回顾并感觉良好。 +* 不要着迷于不知道的事情:当有很多新事物出现时很难做到都知道,所以只关注必须的,及手头项目需要的东西,这非常重要的。 +* 多和同事分享知识:我是初级的并不意味着没有可以分享的!我需要持续分享我感兴趣的的文章及讨论话题。我知道同事们会感激我的。 +* 耐心和持续学习:和现在一样的保持不断学习,但对自己要有更多耐心。 +* 自我保健:随时注意休息,不要为难自己。 放松也富有成效。 -------------------------------------------------------------------------------- @@ -122,7 +115,7 @@ via: https://proandroiddev.com/a-year-as-android-engineer-55e2a428dfc8 作者:[Lara Martín][a] 译者:[runningwater](https://github.com/runningwater) -校对:[校对者ID](https://github.com/校对者ID) +校对:[wxy](https://github.com/wxy) 本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 diff --git a/published/201807/20180515 Give Your Linux Desktop a Stunning Makeover With Xenlism Themes.md b/published/201807/20180515 Give Your Linux Desktop a Stunning Makeover With Xenlism Themes.md new file mode 100644 index 0000000000..07dc338eb2 --- /dev/null +++ b/published/201807/20180515 Give Your Linux Desktop a Stunning Makeover With Xenlism Themes.md @@ -0,0 +1,90 @@ +使用 Xenlism 主题对你的 Linux 桌面进行令人惊叹的改造 +============================================================ + +> 简介:Xenlism 主题包提供了一个美观的 GTK 主题、彩色图标和简约的壁纸,将你的 Linux 桌面转变为引人注目的操作系统。 + +除非我找到一些非常棒的东西,否则我不会每天都把整篇文章献给一个主题。我曾经经常发布主题和图标。但最近,我更喜欢列出[最佳 GTK 主题][6]和图标主题。这对我和你来说都更方便,你可以在一个地方看到许多美丽的主题。 + +在 [Pop OS 主题][7]套件之后,Xenlism 是另一个让我对它的外观感到震惊的主题。 + +![Xenlism GTK theme for Ubuntu and Other Linux](https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/05/xenlishm-minimalism-gtk-theme-800x450.jpeg) + +Xenlism GTK 主题基于 Arc 主题,其得益于许多主题的灵感。GTK 主题提供类似于 macOS 的 Windows 按钮,我既不特别喜欢,也没有特别不喜欢。GTK 主题采用扁平、简约的布局,我喜欢这样。 + +Xenlism 套件中有两个图标主题。Xenlism Wildfire 是以前的,已经进入我们的[最佳图标主题][8]列表。 + +![Beautiful Xenlism Wildfire theme for Ubuntu and Other Linux](https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/05/xenlism-wildfire-theme-800x450.jpeg) + +*Xenlism Wildfire 图标* + +Xenlsim Storm 是一个相对较新的图标主题,但同样美观。 + +![Beautiful Xenlism Storm theme for Ubuntu and Other Linux](https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/05/xenlism-storm-theme-1-800x450.jpeg) + +*Xenlism Storm 图标* + +Xenlism 主题在 GPL 许可下开源。 + +### 如何在 Ubuntu 18.04 上安装 Xenlism 主题包 + +Xenlism 开发提供了一种通过 PPA 安装主题包的更简单方法。尽管 PPA 可用于 Ubuntu 16.04,但我发现 GTK 主题不适用于 Unity。它适用于 Ubuntu 18.04 中的 GNOME 桌面。 + +打开终端(`Ctrl+Alt+T`)并逐个使用以下命令: + +``` +sudo add-apt-repository ppa:xenatt/xenlism +sudo apt update +``` + +该 PPA 提供四个包: + +* xenlism-finewalls:一组壁纸,可直接在 Ubuntu 的壁纸中使用。截图中使用了其中一个壁纸。 +* xenlism-minimalism-theme:GTK 主题 +* xenlism-storm:一个图标主题(见前面的截图) +* xenlism-wildfire-icon-theme:具有多种颜色变化的另一个图标主题(文件夹颜色在变体中更改) + +你可以自己决定要安装的主题组件。就个人而言,我认为安装所有组件没有任何损害。 + +``` +sudo apt install xenlism-minimalism-theme xenlism-storm-icon-theme xenlism-wildfire-icon-theme xenlism-finewalls +``` + +你可以使用 GNOME Tweaks 来更改主题和图标。如果你不熟悉该过程,我建议你阅读本教程以学习[如何在 Ubuntu 18.04 GNOME 中安装主题][9]。 + +### 在其他 Linux 发行版中获取 Xenlism 主题 + +你也可以在其他 Linux 发行版上安装 Xenlism 主题。各种 Linux 发行版的安装说明可在其网站上找到: + +[安装 Xenlism 主题][10] + +### 你怎么看? + +我知道不是每个人都会同意我,但我喜欢这个主题。我想你将来会在 It's FOSS 的教程中会看到 Xenlism 主题的截图。 + +你喜欢 Xenlism 主题吗?如果不喜欢,你最喜欢什么主题?在下面的评论部分分享你的意见。 + +### 关于作者 + +我是一名专业软件开发人员,也是 It's FOSS 的创始人。我是一名狂热的 Linux 爱好者和开源爱好者。我使用 Ubuntu 并相信分享知识。除了Linux,我喜欢经典侦探之谜。我是 Agatha Christie 作品的忠实粉丝。 + +-------------------------------------------------------------------------------- + +via: https://itsfoss.com/xenlism-theme/ + +作者:[Abhishek Prakash][a] +译者:[geekpi](https://github.com/geekpi) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://itsfoss.com/author/abhishek/ +[1]:https://itsfoss.com/author/abhishek/ +[2]:https://itsfoss.com/xenlism-theme/#comments +[3]:https://itsfoss.com/category/desktop/ +[4]:https://itsfoss.com/tag/themes/ +[5]:https://itsfoss.com/tag/xenlism/ +[6]:https://itsfoss.com/best-gtk-themes/ +[7]:https://itsfoss.com/pop-icon-gtk-theme-ubuntu/ +[8]:https://itsfoss.com/best-icon-themes-ubuntu-16-04/ +[9]:https://itsfoss.com/install-themes-ubuntu/ +[10]:http://xenlism.github.io/minimalism/#install diff --git a/published/20180519 Python Debugging Tips.md b/published/201807/20180519 Python Debugging Tips.md similarity index 100% rename from published/20180519 Python Debugging Tips.md rename to published/201807/20180519 Python Debugging Tips.md diff --git a/published/201807/20180522 How to Run Your Own Git Server.md b/published/201807/20180522 How to Run Your Own Git Server.md new file mode 100644 index 0000000000..ca438b25a4 --- /dev/null +++ b/published/201807/20180522 How to Run Your Own Git Server.md @@ -0,0 +1,246 @@ +搭建属于你自己的 Git 服务器 +====== + +![](https://www.linux.com/images/stories/41373/GitLab-3.png) + +> 在本文中,我们的目的是让你了解如何设置属于自己的Git服务器。 + +[Git][1] 是由 [Linux Torvalds 开发][2]的一个版本控制系统,现如今正在被全世界大量开发者使用。许多公司喜欢使用基于 Git 版本控制的 GitHub 代码托管。[根据报道,GitHub 是现如今全世界最大的代码托管网站][3]。GitHub 宣称已经有 920 万用户和 2180 万个仓库。许多大型公司现如今也将代码迁移到 GitHub 上。[甚至于谷歌,一家搜索引擎公司,也正将代码迁移到 GitHub 上][4]。 + +### 运行你自己的 Git 服务器 + +GitHub 能提供极佳的服务,但却有一些限制,尤其是你是单人或是一名 coding 爱好者。GitHub 其中之一的限制就是其中免费的服务没有提供代码私有托管业务。[你不得不支付每月 7 美金购买 5 个私有仓库][5],并且想要更多的私有仓库则要交更多的钱。 + +万一你想要私有仓库或需要更多权限控制,最好的方法就是在你的服务器上运行 Git。不仅你能够省去一笔钱,你还能够在你的服务器有更多的操作。在大多数情况下,大多数高级 Linux 用户已经拥有自己的服务器,并且在这些服务器上方式 Git 就像“啤酒一样免费”(LCTT 译注:指免费软件)。 + +在这篇教程中,我们主要讲在你的服务器上,使用两种代码管理的方法。一种是运行一个纯 Git 服务器,另一个是使用名为 [GitLab][6] 的 GUI 工具。在本教程中,我在 VPS 上运行的操作系统是 Ubuntu 14.04 LTS。 + +### 在你的服务器上安装 Git + +在本篇教程中,我们考虑一个简单案例,我们有一个远程服务器和一台本地服务器,现在我们需要使用这两台机器来工作。为了简单起见,我们就分别叫它们为远程服务器和本地服务器。 + +首先,在两边的机器上安装 Git。你可以从依赖包中安装 Git,在本文中,我们将使用更简单的方法: + +``` +sudo apt-get install git-core +``` + +为 Git 创建一个用户。 + +``` +sudo useradd git +passwd git +``` + +为了容易的访问服务器,我们设置一个免密 ssh 登录。首先在你本地电脑上创建一个 ssh 密钥: + +``` +ssh-keygen -t rsa +``` + +这时会要求你输入保存密钥的路径,这时只需要点击回车保存在默认路径。第二个问题是输入访问远程服务器所需的密码。它生成两个密钥——公钥和私钥。记下您在下一步中需要使用的公钥的位置。 + +现在您必须将这些密钥复制到服务器上,以便两台机器可以相互通信。在本地机器上运行以下命令: + +``` +cat ~/.ssh/id_rsa.pub | ssh git@remote-server "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys" +``` + +现在,用 `ssh` 登录进服务器并为 Git 创建一个项目路径。你可以为你的仓库设置一个你想要的目录。 + +现在跳转到该目录中: + +``` +cd /home/swapnil/project-1.git +``` + +现在新建一个空仓库: + +``` +git init --bare +Initialized empty Git repository in /home/swapnil/project-1.git +``` + +现在我们需要在本地机器上新建一个基于 Git 版本控制仓库: + +``` +mkdir -p /home/swapnil/git/project +``` + +进入我们创建仓库的目录: + +``` +cd /home/swapnil/git/project +``` + +现在在该目录中创建项目所需的文件。留在这个目录并启动 `git`: + +``` +git init +Initialized empty Git repository in /home/swapnil/git/project +``` + +把所有文件添加到仓库中: + +``` +git add . +``` + +现在,每次添加文件或进行更改时,都必须运行上面的 `add` 命令。 您还需要为每个文件更改都写入提交消息。提交消息基本上说明了我们所做的更改。 + +``` +git commit -m "message" -a +[master (root-commit) 57331ee] message + 2 files changed, 2 insertions(+) + create mode 100644 GoT.txt + create mode 100644 writing.txt +``` + +在这种情况下,我有一个名为 GoT(《权力的游戏》的点评)的文件,并且我做了一些更改,所以当我运行命令时,它指定对文件进行更改。 在上面的命令中 `-a` 选项意味着提交仓库中的所有文件。 如果您只更改了一个,则可以指定该文件的名称而不是使用 `-a`。 + +举一个例子: + +``` +git commit -m "message" GoT.txt +[master e517b10] message + 1 file changed, 1 insertion(+) +``` + +到现在为止,我们一直在本地服务器上工作。现在我们必须将这些更改推送到远程服务器上,以便通过互联网访问,并且可以与其他团队成员进行协作。 + +``` +git remote add origin ssh://git@remote-server/repo->path-on-server..git +``` + +现在,您可以使用 `pull` 或 `push` 选项在服务器和本地计算机之间推送或拉取: + +``` +git push origin master +``` + +如果有其他团队成员想要使用该项目,则需要将远程服务器上的仓库克隆到其本地计算机上: + +``` +git clone git@remote-server:/home/swapnil/project.git +``` + +这里 `/home/swapnil/project.git` 是远程服务器上的项目路径,在你本机上则会改变。 + +然后进入本地计算机上的目录(使用服务器上的项目名称): + +``` +cd /project +``` + +现在他们可以编辑文件,写入提交更改信息,然后将它们推送到服务器: + +``` +git commit -m 'corrections in GoT.txt story' -a +``` + +然后推送改变: + +``` +git push origin master +``` + +我认为这足以让一个新用户开始在他们自己的服务器上使用 Git。 如果您正在寻找一些 GUI 工具来管理本地计算机上的更改,则可以使用 GUI 工具,例如 QGit 或 GitK for Linux。 + +![](https://www.linux.com/images/stories/41373/QGit.jpg) + +### 使用 GitLab + +这是项目所有者和协作者的纯命令行解决方案。这当然不像使用 GitHub 那么简单。不幸的是,尽管 GitHub 是全球最大的代码托管商,但是它自己的软件别人却无法使用。因为它不是开源的,所以你不能获取源代码并编译你自己的 GitHub。这与 WordPress 或 Drupal 不同,您无法下载 GitHub 并在您自己的服务器上运行它。 + +像往常一样,在开源世界中,是没有终结的尽头。GitLab 是一个非常优秀的项目。这是一个开源项目,允许用户在自己的服务器上运行类似于 GitHub 的项目管理系统。 + +您可以使用 GitLab 为团队成员或公司运行类似于 GitHub 的服务。您可以使用 GitLab 在公开发布之前开发私有项目。 + +GitLab 采用传统的开源商业模式。他们有两种产品:免费的开源软件,用户可以在自己的服务器上安装,以及类似于 GitHub 的托管服务。 + +可下载版本有两个版本,免费的社区版和付费企业版。企业版基于社区版,但附带针对企业客户的其他功能。它或多或少与 WordPress.org 或 Wordpress.com 提供的服务类似。 + +社区版具有高度可扩展性,可以在单个服务器或群集上支持 25000 个用户。GitLab 的一些功能包括:Git 仓库管理,代码评论,问题跟踪,活动源和维基。它配备了 GitLab CI,用于持续集成和交付。 + +Digital Ocean 等许多 VPS 提供商会为用户提供 GitLab 服务。 如果你想在你自己的服务器上运行它,你可以手动安装它。GitLab 为不同的操作系统提供了软件包。 在我们安装 GitLab 之前,您可能需要配置 SMTP 电子邮件服务器,以便 GitLab 可以在需要时随时推送电子邮件。官方推荐使用 Postfix。所以,先在你的服务器上安装 Postfix: + +``` +sudo apt-get install postfix +``` + +在安装 Postfix 期间,它会问你一些问题,不要跳过它们。 如果你一不小心跳过,你可以使用这个命令来重新配置它: + +``` +sudo dpkg-reconfigure postfix +``` + +运行此命令时,请选择 “Internet Site”并为使用 Gitlab 的域名提供电子邮件 ID。 + +我是这样输入的: + +``` +xxx@x.com +``` + +用 Tab 键并为 postfix 创建一个用户名。接下来将会要求你输入一个目标邮箱。 + +在剩下的步骤中,都选择默认选项。当我们安装且配置完成后,我们继续安装 GitLab。 + +我们使用 `wget` 来下载软件包(用 [最新包][7] 替换下载链接): + +``` +wget https://downloads-packages.s3.amazonaws.com/ubuntu-14.04/gitlab_7.9.4-omnibus.1-1_amd64.deb +``` + +然后安装这个包: + +``` +sudo dpkg -i gitlab_7.9.4-omnibus.1-1_amd64.deb +``` + +现在是时候配置并启动 GitLab 了。 + +``` +sudo gitlab-ctl reconfigure +``` + +您现在需要在配置文件中配置域名,以便您可以访问 GitLab。打开文件。 + +``` +nano /etc/gitlab/gitlab.rb +``` + +在这个文件中编辑 `external_url` 并输入服务器域名。保存文件,然后从 Web 浏览器中打开新建的一个 GitLab 站点。 + +![](https://www.linux.com/images/stories/41373/GitLab-1.jpg) + +默认情况下,它会以系统管理员的身份创建 `root`,并使用 `5iveL!fe` 作为密码。 登录到 GitLab 站点,然后更改密码。 + +![](https://www.linux.com/images/stories/41373/GitLab-2.png) + +密码更改后,登录该网站并开始管理您的项目。 + +![](https://www.linux.com/images/stories/41373/GitLab-3.png) + +GitLab 有很多选项和功能。最后,我借用电影“黑客帝国”中的经典台词:“不幸的是,没有人知道 GitLab 可以做什么。你必须亲自尝试一下。” + + +-------------------------------------------------------------------------------- + +via: https://www.linux.com/learn/how-run-your-own-git-server + +作者:[Swapnil Bhartiya][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[wyxplus](https://github.com/wyxplus) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.linux.com/users/arnieswap +[1]:https://github.com/git/git +[2]:https://www.linuxfoundation.org/blog/10-years-of-git-an-interview-with-git-creator-linus-torvalds/ +[3]:https://github.com/about/press +[4]:http://google-opensource.blogspot.com/2015/03/farewell-to-google-code.html +[5]:https://github.com/pricing +[6]:https://about.gitlab.com/ +[7]:https://about.gitlab.com/downloads/ diff --git a/translated/tech/20180529 5 trending open source machine learning JavaScript frameworks.md b/published/201807/20180529 5 trending open source machine learning JavaScript frameworks.md similarity index 66% rename from translated/tech/20180529 5 trending open source machine learning JavaScript frameworks.md rename to published/201807/20180529 5 trending open source machine learning JavaScript frameworks.md index 4c59c540df..da6138b5e0 100644 --- a/translated/tech/20180529 5 trending open source machine learning JavaScript frameworks.md +++ b/published/201807/20180529 5 trending open source machine learning JavaScript frameworks.md @@ -1,49 +1,50 @@ - 五个最热门的开源机器学习 JavaScript 框架 ====== + +> 如果是你一位想要深入机器学习的 JavaScript 程序员或想成为一位使用 JavaScript 的机器学习专家,那么这些开源框架也许会吸引你。 + ![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/web-spider-frame-framework-2.png?itok=ng6O0fd4) -开源工具的可用性使得开发者能够更加轻松地开发应用,这一点使机器学习领域本身获得了巨大的极高。(例如,AndreyBu,他来自德国,在机器学习领域拥有五年以上的经验,他一直在使用各种各样的开源框架来创造富有魅力的机器学习项目。 +开源工具的涌现使得开发者能够更加轻松地开发应用,这一点使机器学习领域本身获得了极大增长。(例如,AndreyBu,他来自德国,在机器学习领域拥有五年以上的经验,他一直在使用各种各样的开源框架来创造富有魅力的机器学习项目。) -虽然 python 支持绝大多数的机器学习框架,但是 JavaScript 也并没有被抛弃。JavaScript 开发者可以在浏览器中使用各种框架来训练和部署机器学习模型。 +虽然 Python 是绝大多数的机器学习框架所采用的语言,但是 JavaScript 也并没有被抛下。JavaScript 开发者可以在浏览器中使用各种框架来训练和部署机器学习模型。 下面是 JavaScript 中最热门五个机器学习框架 -### 1\. TensorFlow.js +### 1、 TensorFlow.js -[TensorFlow.js][2] 是一个开源库,它使你能在浏览器中完整地运行机器学习程序,它是 Deeplearn.js 的继承者,Deeplearn.js 不再被提供更新。TensorFlow.js 在 Deeplearn.js 功能的基础上进行了改善,使你能够充分利用浏览器,得到更加深入的机器学习经验。 +[TensorFlow.js][2] 是一个开源库,它使你能在浏览器中完整地运行机器学习程序,它是 Deeplearn.js 的继承者,Deeplearn.js 不再更新了。TensorFlow.js 在 Deeplearn.js 功能的基础上进行了改善,使你能够充分利用浏览器,得到更加深入的机器学习经验。 -通过这个开源库,你可以在浏览器中使用有各种功能的、直观的 API 来定义、训练和部署模型。除此之外,它能够自动为 WebGL 和 Node.js 提供支持。 +通过这个开源库,你可以在浏览器中使用有各种功能的、直观的 API 来定义、训练和部署模型。除此之外,它自动提供 WebGL 和 Node.js 的支持。 如果您有了一个已经训练过的模型,你想要导入到浏览器中。TensorFlow.js 可以让你做到这一点,你也可以在不离开浏览器的情况下重新训练已有的模型。 -现在有很多在浏览器中提供广泛的机器学习功能的资源型开源工具,这个机器学习工具库就是这些开源工具的集合。这个工具库为好几种机器学习算法提供支持,包括非监督式学习、监督式学习、数据处理、人工神经网络(ANN)、数学和回归。 +### 2、 机器学习工具库 -如果你以前使用 python,现在想找类似于 Scikit-learn 的,能在浏览器中使用 JavaScript 进行机器学习的工具,这套工具会满足你的要求。 +现在有很多在浏览器中提供广泛的机器学习功能的资源型开源工具,这个[机器学习工具库][3]就是这些开源工具的集合。这个工具库为好几种机器学习算法提供支持,包括非监督式学习、监督式学习、数据处理、人工神经网络(ANN)、数学和回归。 -### 3\. Keras.js +如果你以前使用 Python,现在想找类似于 Scikit-learn 的,能在浏览器中使用 JavaScript 进行机器学习的工具,这套工具会满足你的要求。 + +### 3、 Keras.js [Keras.js][4] 是另外一个热门的开源框架,它使你能够在浏览器中运行机器学习模型,它使用 WebGL 来提供 GPU 模式的支持。如果你有使用 Node.js 的模型,你就只能在 GPU 模式下运行它。Keras.js 还为使用任意后端框架的模型训练提供支持,例如 Microsoft Cognitive Toolkit (CNTK) 。 一些 Keras 模型可以部署在客户端浏览器上,包括 Inception v3 (训练在 ImageNet 上),50 层冗余网络(训练在 ImageNet 上),和卷积变化自动编码器(训练在 MNIST 上)。 -### 4\. Brain.js +### 4、 Brain.js -机器学习里的概念非常重要,它可能会使刚开始进入这个领域的人们气馁,这个领域里的学术用语和专业词汇可能会使初学者感到崩溃,而解决以上问题的能力就是 Brain.js 的优势所在。它是开源的,基于 JavaScript 的框架,简化了定义、训练和运行神经网络的流程。 +机器学习里的概念非常重要,它可能会使刚开始进入这个领域的人们气馁,这个领域里的学术用语和专业词汇可能会使初学者感到崩溃,而解决以上问题的能力就是 [Brain.js][5] 的优势所在。它是开源的,基于 JavaScript 的框架,简化了定义、训练和运行神经网络的流程。 如果你是一个 JavaScript 开发者,并且在机器学习领域是完全的新手,Brain.js 能减低你学习的难度曲线。它可以和 Node.js 一起使用,或者运行在客户端浏览器里来训练机器学习模型。Brain.js 支持部分类型的神经网络,包括前馈式网络、Ellman 网络,和门循环单元网络。 -### 5\. STDLib +### 5、 STDLib [STDLib][6] 是一个基于 JavaScript 和 Node.js 应用的开源库,如果您正在寻找一种在浏览器中运行,支持科学和数字化的基于 web 的机器学习应用,STDLib 能满足你的需要。 - -这个库能提供全面而先进的数学和统计学上的功能,来帮助你构建高性能的机器学习模型。你同样也可以使用它扩展的公用程序来构建应用程序和其他的库。除此之外,如果你想要一个数据可视化和探索性数据分析的框架。 - -STDLib,你,值得拥有。 +这个库能提供全面而先进的数学和统计学上的功能,来帮助你构建高性能的机器学习模型。你同样也可以使用它丰富的功能来构建应用程序和其他的库。除此之外,如果你想要一个数据可视化和探索性数据分析的框架 —— STDLib,你,值得拥有。 -### Conclusion +### 总结 如果你是一个 JavaScript 开发者,并且打算深入研究令人兴奋的机器学习世界,或者说,你是一个机器学习方面的专家,打算开始尝试使用 JavaScript ,那么上述的开源框架会激起您的兴趣。 @@ -56,7 +57,7 @@ via: https://opensource.com/article/18/5/machine-learning-javascript-frameworks 作者:[Dr.Michael J.Garbade][a] 选题:[lujun9972](https://github.com/lujun9972) 译者:[hopefully2333](https://github.com/hopefully2333) -校对:[校对者ID](https://github.com/校对者ID) +校对:[wxy](https://github.com/wxy) 本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 diff --git a/translated/tech/20180530 3 Python command-line tools.md b/published/201807/20180530 3 Python command-line tools.md similarity index 61% rename from translated/tech/20180530 3 Python command-line tools.md rename to published/201807/20180530 3 Python command-line tools.md index 0233fe7268..144edecc7c 100644 --- a/translated/tech/20180530 3 Python command-line tools.md +++ b/published/201807/20180530 3 Python command-line tools.md @@ -1,13 +1,13 @@ -3个 Python 命令行工具 +3 个 Python 命令行工具 ====== +> 用 Click、Docopt 和 Fire 库写你自己的命令行应用。 + ![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/osdc-lead-tool-box.png?itok=NrJYb417) -这篇文章是与 [Lacey Williams Hensche][1] 共同撰写的。 +有时对于某项工作来说一个命令行工具就足以胜任。命令行工具是一种从你的 shell 或者终端之类的地方交互或运行的程序。[Git][2] 和 [Curl][3] 就是两个你也许已经很熟悉的命令行工具。 -有时对于某项工作来说一个命令行工具就足以胜任。命令行工具是一个交互程序,类似你的 shell 或者终端。[Git][2] 和 [Curl][3] 就是两个你也许已经很熟悉的命令行工具。 - -当你有一小段代码需要在一行中执行多次或者经常性地被执行,命令行工具会很实用。Django 开发者执行 `./manage.py runserver` 命令来启动他们的网络服务器;Docker 开发者执行 `docker-compose up` 来启动他们的容器。你想要写一个命令行工具的原因可能和你一开始想写代码的原因有很大不同。 +当你有一小段代码需要在一行中执行多次或者经常性地被执行,命令行工具就会很有用。Django 开发者执行 `./manage.py runserver` 命令来启动他们的网络服务器;Docker 开发者执行 `docker-compose up` 来启动他们的容器。你想要写一个命令行工具的原因可能和你一开始想写代码的原因有很大不同。 对于这个月的 Python 专栏,我们有 3 个库想介绍给希望为自己编写命令行工具的 Python 使用者。 @@ -19,24 +19,24 @@ * 包含说明如何将命令行工具打包成一个更加易于执行的 Python 应用程序 * 自动生成实用的帮助文本 * 使你能够叠加使用可选和必要参数,甚至是 [多个命令][5] - * 有一个 Django 版本( [`django-click`][6] )来编写管理命令 + * 有一个 Django 版本( [`django-click`][6] )用来编写管理命令 Click 使用 `@click.command()` 去声明一个函数作为命令,同时可以指定必要和可选参数。 ``` # hello.py -import click +import click @click.command() @click.option('--name', default='', help='Your name') def say_hello(name): -    click.echo("Hello {}!".format(name)) + click.echo("Hello {}!".format(name)) if __name__ == '__main__': -    hello() + say_hello() ``` -`@click.option()` 修饰器声明了一个 [可选参数][7] 并且 `@click.argument()` 修饰器声明了一个 [必要参数][8]。你可以通过叠加修饰器来组合可选和必要参数。`echo()` 方法将结果打印到控制台。 +`@click.option()` 修饰器声明了一个 [可选参数][7] ,而 `@click.argument()` 修饰器声明了一个 [必要参数][8]。你可以通过叠加修饰器来组合可选和必要参数。`echo()` 方法将结果打印到控制台。 ``` $ python hello.py --name='Lacey' @@ -45,42 +45,42 @@ Hello Lacey! ### Docopt -[Docopt][9] 是一个命令行工具解析器,类似于命令行工具的 Markdown。如果你喜欢流畅地编写应用文档,在本文推荐的库中 Docopt 有着最好的格式化帮助文本。它不是我们最爱的命令行工具开发包的原因是它的文档犹如把人扔进深渊,使你开始使用时会有一些小困难。然而,它仍是一个轻量级广受欢迎的库,特别是当一个漂亮的说明文档对你来说很重要的时候。 +[Docopt][9] 是一个命令行工具的解析器,类似于命令行工具的 Markdown。如果你喜欢流畅地编写应用文档,在本文推荐的库中 Docopt 有着最好的格式化帮助文本。它不是我们最爱的命令行工具开发包的原因是它的文档犹如把人扔进深渊,使你开始使用时会有一些小困难。然而,它仍是一个轻量级的、广受欢迎的库,特别是当一个漂亮的说明文档对你来说很重要的时候。 -Docopt 对于如何格式化文章开头的 docstring 是很特别的。在工具名称后面的 docsring 中,顶部元素必须是“Usage:”并且需要列出你希望命令被调用的方式(比如:自身调用,使用参数等等)。Usage 需要包含 **help** 和 **version** 标记。 +Docopt 对于如何格式化文章开头的 docstring 是很特别的。在工具名称后面的 docsring 中,顶部元素必须是 `Usage:` 并且需要列出你希望命令被调用的方式(比如:自身调用,使用参数等等)。`Usage:` 需要包含 `help` 和 `version` 参数。 -docstring 中的第二个元素是“Options:”,对于在“Usages:”中提及的可选项和参数,它应当提供更多的信息。你的 docstring 的内容变成了你帮助文本的内容。 +docstring 中的第二个元素是 `Options:`,对于在 `Usages:` 中提及的可选项和参数,它应当提供更多的信息。你的 docstring 的内容变成了你帮助文本的内容。 ``` """HELLO CLI Usage: -    hello.py -    hello.py -    hello.py -h|--help -    hello.py -v|--version + hello.py + hello.py + hello.py -h|--help + hello.py -v|--version Options: -     Optional name argument. -    -h --help  Show this screen. -    -v --version  Show version. + Optional name argument. + -h --help Show this screen. + -v --version Show version. """ from docopt import docopt def say_hello(name): -    return("Hello {}!".format(name)) + return("Hello {}!".format(name)) if __name__ == '__main__': -    arguments = docopt(__doc__, version='DEMO 1.0') -    if arguments['']: -        print(say_hello(arguments[''])) -    else: -        print(arguments) + arguments = docopt(__doc__, version='DEMO 1.0') + if arguments['']: + print(say_hello(arguments[''])) + else: + print(arguments) ``` -在最基本的层面,Docopt 被设计用来返回你的参数键值对。如果我不指定名字调用上面的命令,我会得到一个字典的返回: +在最基本的层面,Docopt 被设计用来返回你的参数键值对。如果我不指定上述的 `name` 调用上面的命令,我会得到一个字典的返回值: ``` $ python hello.py @@ -91,20 +91,20 @@ $ python hello.py 这里可看到我没有输入 `help` 和 `version` 标记并且 `name` 参数是 `None`。 -但是如果我带着一个 name 参数调用,`say_hello` 函数就会执行了。 +但是如果我带着一个 `name` 参数调用,`say_hello` 函数就会执行了。 ``` $ python hello.py Jeff Hello Jeff! ``` -Docopt 允许同时制定必要和可选参数,且各自有着不同的语法约定。必要参数需要在 `ALLCAPS` 和 `` 中展示,而可选参数需要单双横杠显示,就像‘--like’。更多内容可以阅读 Docopt 有关 [patterns][10] 的文档。 +Docopt 允许同时指定必要和可选参数,且各自有着不同的语法约定。必要参数需要在 `ALLCAPS` 和 `` 中展示,而可选参数需要单双横杠显示,就像 `--like`。更多内容可以阅读 Docopt 有关 [patterns][10] 的文档。 ### Fire [Fire][11] 是谷歌的一个命令行工具开发库。尤其令人喜欢的是当你的命令需要更多复杂参数或者处理 Python 对象时,它会聪明地尝试解析你的参数类型。 -Fire 的 [文档][12] 包括了海量的样例,但是我希望这些文档能被更好地组织。Fire 能够处理 [同一个文件中的多条命令][13]、使用 [对象][14] 的方法作为命令和 [组][15] 命令。 +Fire 的 [文档][12] 包括了海量的样例,但是我希望这些文档能被更好地组织。Fire 能够处理 [同一个文件中的多条命令][13]、使用 [对象][14] 的方法作为命令和 [分组][15] 命令。 它的弱点在于输出到控制台的文档。命令行中的 docstring 不会出现在帮助文本中,并且帮助文本也不一定标识出参数。 @@ -113,11 +113,11 @@ import fire def say_hello(name=''): -    return 'Hello {}!'.format(name) + return 'Hello {}!'.format(name) if __name__ == '__main__': -  fire.Fire() + fire.Fire() ``` 参数是必要还是可选取决于你是否在函数或者方法定义中为其指定了一个默认值。要调用命令,你必须指定文件名和函数名,比较类似 Click 的语法: @@ -129,7 +129,7 @@ Hello Rikki! 你还可以像标记一样传参,比如 `--name=Rikki`。 -### 额外奖赏:打包! +### 额外赠送:打包! Click 包含了使用 `setuptools` [打包][16] 命令行工具的使用说明(强烈推荐按照说明操作)。 @@ -139,20 +139,20 @@ Click 包含了使用 `setuptools` [打包][16] 命令行工具的使用说明 from setuptools import setup setup( -    name='hello', -    version='0.1', -    py_modules=['hello'], -    install_requires=[ -        'Click', -    ], -    entry_points=''' -        [console_scripts] -        hello=hello:say_hello -    ''', + name='hello', + version='0.1', + py_modules=['hello'], + install_requires=[ + 'Click', + ], + entry_points=''' + [console_scripts] + hello=hello:say_hello + ''', ) ``` -任何你看见 `hello` 的地方,使用你自己的模块名称替换掉,但是要记得忽略`.py` 后缀名。将 `say_hello` 替换成你的函数名称。 +任何你看见 `hello` 的地方,使用你自己的模块名称替换掉,但是要记得忽略 `.py` 后缀名。将 `say_hello` 替换成你的函数名称。 然后,执行 `pip install --editable` 来使你的命令在命令行中可用。 @@ -169,10 +169,10 @@ Hello Jeff! via: https://opensource.com/article/18/5/3-python-command-line-tools -作者:[Jeff Triplett][a] +作者:[Jeff Triplett][a],[Lacey Williams Hensche][1] 选题:[lujun9972](https://github.com/lujun9972) 译者:[hoppipolla-](https://github.com/hoppipolla-) -校对:[校对者ID](https://github.com/校对者ID) +校对:[wxy](https://github.com/wxy) 本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 diff --git a/published/201807/20180531 You don-t know Bash- An introduction to Bash arrays.md b/published/201807/20180531 You don-t know Bash- An introduction to Bash arrays.md new file mode 100644 index 0000000000..48bf345327 --- /dev/null +++ b/published/201807/20180531 You don-t know Bash- An introduction to Bash arrays.md @@ -0,0 +1,228 @@ +你所不了解的 Bash:关于 Bash 数组的介绍 +====== + +> 进入这个古怪而神奇的 Bash 数组的世界。 + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/programming-code-keyboard-laptop.png?itok=pGfEfu2S) + +尽管软件工程师常常使用命令行来进行各种开发,但命令行中的数组似乎总是一个模糊的东西(虽然不像正则操作符 `=~` 那么复杂隐晦)。除开隐晦和有疑问的语法,[Bash][1] 数组其实是非常有用的。 + +### 稍等,这是为什么? + +写 Bash 相关的东西很难,但如果是写一篇像手册那样注重怪异语法的文章,就会非常简单。不过请放心,这篇文章的目的就是让你不用去读该死的使用手册。 + +#### 真实(通常是有用的)示例 + +为了这个目的,想象一下真实世界的场景以及 Bash 是怎么帮忙的:你正在公司里面主导一个新工作,评估并优化内部数据管线的运行时间。首先,你要做个参数扫描分析来评估管线使用线程的状况。简单起见,我们把这个管道当作一个编译好的 C++ 黑盒子,这里面我们能够调整的唯一的参数是用于处理数据的线程数量:`./pipeline --threads 4`。 + +### 基础 + +我们首先要做的事是定义一个数组,用来容纳我们想要测试的 `--threads` 参数: + +``` +allThreads=(1 2 4 8 16 32 64 128) +``` + +本例中,所有元素都是数字,但参数并不一定是数字,Bash 中的数组可以容纳数字和字符串,比如 `myArray=(1 2 "three" 4 "five")` 就是个有效的表达式。就像 Bash 中其它的变量一样,确保赋值符号两边没有空格。否则 Bash 将会把变量名当作程序来执行,把 `=` 当作程序的第一个参数。 + +现在我们初始化了数组,让我们解析它其中的一些元素。仅仅输入 `echo $allThreads` ,你能发现,它只会输出第一个元素。 + +要理解这个产生的原因,需要回到上一步,回顾我们一般是怎么在 Bash 中输出变量。考虑以下场景: + +``` +type="article" +echo "Found 42 $type" +``` + +假如我们得到的变量 `$type` 是一个单词,我们想要添加在句子结尾一个 `s`。我们无法直接把 `s` 加到 `$type` 里面,因为这会把它变成另一个变量,`$types`。尽管我们可以利用像 `echo "Found 42 "$type"s"` 这样的代码形变,但解决这个问题的最好方法是用一个花括号:`echo "Found 42 ${type}s"`,这让我们能够告诉 Bash 变量名的起止位置(有趣的是,JavaScript/ES6 在 [template literals][2] 中注入变量和表达式的语法和这里是一样的) + +事实上,尽管 Bash 变量一般不用花括号,但在数组中需要用到花括号。这反而允许我们指定要访问的索引,例如 `echo ${allThreads[1]}` 返回的是数组中的第二个元素。如果不写花括号,比如 `echo $allThreads[1]`,会导致 Bash 把 `[1]` 当作字符串然后输出。 + +是的,Bash 数组的语法很怪,但是至少他们是从 0 开始索引的,不像有些语言(说的就是你,`R` 语言)。 + +### 遍历数组 + +上面的例子中我们直接用整数作为数组的索引,我们现在考虑两种其他情况:第一,如果想要数组中的第 `$i` 个元素,这里 `$i` 是一个代表索引的变量,我们可以这样 `echo ${allThreads[$i]}` 解析这个元素。第二,要输出一个数组的所有元素,我们把数字索引换成 `@` 符号(你可以把 `@` 当作表示 `all` 的符号):`echo ${allThreads[@]}`。 + +#### 遍历数组元素 + +记住上面讲过的,我们遍历 `$allThreads` 数组,把每个值当作 `--threads` 参数启动管线: + +``` +for t in ${allThreads[@]}; do +  ./pipeline --threads $t +done +``` + +#### 遍历数组索引 + +接下来,考虑一个稍稍不同的方法。不遍历所有的数组元素,我们可以遍历所有的索引: + +``` +for i in ${!allThreads[@]}; do +  ./pipeline --threads ${allThreads[$i]} +done +``` + +一步一步看:如之前所见,`${allThreads[@]}` 表示数组中的所有元素。前面加了个感叹号,变成 `${!allThreads[@]}`,这会返回数组索引列表(这里是 0 到 7)。换句话说。`for` 循环就遍历所有的索引 `$i` 并从 `$allThreads` 中读取第 `$i` 个元素,当作 `--threads` 选项的参数。 + +这看上去很辣眼睛,你可能奇怪为什么我要一开始就讲这个。这是因为有时候在循环中需要同时获得索引和对应的值,例如,如果你想要忽视数组中的第一个元素,使用索引可以避免额外创建在循环中累加的变量。 + +### 填充数组 + +到目前为止,我们已经能够用给定的 `--threads` 选项启动管线了。现在假设按秒计时的运行时间输出到管线。我们想要捕捉每个迭代的输出,然后把它保存在另一个数组中,因此我们最终可以随心所欲的操作它。 + +#### 一些有用的语法 + +在深入代码前,我们要多介绍一些语法。首先,我们要能解析 Bash 命令的输出。用这个语法可以做到:`output=$( ./my_script.sh )`,这会把命令的输出存储到变量 `$output` 中。 + +我们需要的第二个语法是如何把我们刚刚解析的值添加到数组中。完成这个任务的语法看起来很熟悉: + +``` +myArray+=( "newElement1" "newElement2" ) +``` + +#### 参数扫描 + +万事具备,执行参数扫描的脚步如下: + +``` +allThreads=(1 2 4 8 16 32 64 128) +allRuntimes=() +for t in ${allThreads[@]}; do + runtime=$(./pipeline --threads $t) + allRuntimes+=( $runtime ) +done +``` + +就是这个了! + +### 还有什么能做的? + +这篇文章中,我们讲过使用数组进行参数扫描的场景。我敢保证有很多理由要使用 Bash 数组,这里就有两个例子: + +#### 日志警告 + +本场景中,把应用分成几个模块,每一个都有它自己的日志文件。我们可以编写一个 cron 任务脚本,当某个模块中出现问题标志时向特定的人发送邮件: + +``` +# 日志列表,发生问题时应该通知的人 +logPaths=("api.log" "auth.log" "jenkins.log" "data.log") +logEmails=("jay@email" "emma@email" "jon@email" "sophia@email") + +# 在每个日志中查找问题标志 +for i in ${!logPaths[@]}; +do +  log=${logPaths[$i]} +  stakeholder=${logEmails[$i]} +  numErrors=$( tail -n 100 "$log" | grep "ERROR" | wc -l ) + + # 如果近期发现超过 5 个错误,就警告负责人 +  if [[ "$numErrors" -gt 5 ]]; +  then +    emailRecipient="$stakeholder" +    emailSubject="WARNING: ${log} showing unusual levels of errors" +    emailBody="${numErrors} errors found in log ${log}" +    echo "$emailBody" | mailx -s "$emailSubject" "$emailRecipient" +  fi +done +``` + +#### API 查询 + +如果你想要生成一些分析数据,分析你的 Medium 帖子中用户评论最多的。由于我们无法直接访问数据库,SQL 不在我们考虑范围,但我们可以用 API! + +为了避免陷入关于 API 授权和令牌的冗长讨论,我们将会使用 [JSONPlaceholder][3],这是一个面向公众的测试服务 API。一旦我们查询每个帖子,解析出每个评论者的邮箱,我们就可以把这些邮箱添加到我们的结果数组里: + +``` +endpoint="https://jsonplaceholder.typicode.com/comments" +allEmails=() + +# 查询前 10 个帖子 +for postId in {1..10}; +do + # 执行 API 调用,获取该帖子评论者的邮箱 +  response=$(curl "${endpoint}?postId=${postId}") +  + # 使用 jq 把 JSON 响应解析成数组 +  allEmails+=( $( jq '.[].email' <<< "$response" ) ) +done +``` + +注意这里我是用 [jq 工具][4] 从命令行里解析 JSON 数据。关于 `jq` 的语法超出了本文的范围,但我强烈建议你了解它。 + +你可能已经想到,使用 Bash 数组在数不胜数的场景中很有帮助,我希望这篇文章中的示例可以给你思维的启发。如果你从自己的工作中找到其它的例子想要分享出来,请在帖子下方评论。 + +### 请等等,还有很多东西! + +由于我们在本文讲了很多数组语法,这里是关于我们讲到内容的总结,包含一些还没讲到的高级技巧: + +| 语法 | 效果 | +|:--|:--| +| `arr=()` | 创建一个空数组 | +| `arr=(1 2 3)` | 初始化数组 | +| `${arr[2]}` | 取得第三个元素 | +| `${arr[@]}` | 取得所有元素 | +| `${!arr[@]}` | 取得数组索引 | +| `${#arr[@]}` | 计算数组长度 | +| `arr[0]=3` | 覆盖第 1 个元素 | +| `arr+=(4)` | 添加值 | +| `str=$(ls)` | 把 `ls` 输出保存到字符串 | +| `arr=( $(ls) )` | 把 `ls` 输出的文件保存到数组里 | +| `${arr[@]:s:n}` | 取得从索引 `s` 开始的 `n` 个元素 | + +### 最后一点思考 + +正如我们所见,Bash 数组的语法很奇怪,但我希望这篇文章让你相信它们很有用。只要你理解了这些语法,你会发现以后会经常使用 Bash 数组。 + +#### Bash 还是 Python? + +问题来了:什么时候该用 Bash 数组而不是其他的脚本语法,比如 Python? + +对我而言,完全取决于需求——如果你可以只需要调用命令行工具就能立马解决问题,你也可以用 Bash。但有些时候,当你的脚本属于一个更大的 Python 项目时,你也可以用 Python。 + +比如,我们可以用 Python 来实现参数扫描,但我们只用编写一个 Bash 的包装: + +``` +import subprocess + +all_threads = [1, 2, 4, 8, 16, 32, 64, 128] +all_runtimes = [] + +# 用不同的线程数字启动管线 +for t in all_threads: +  cmd = './pipeline --threads {}'.format(t) + + # 使用子线程模块获得返回的输出 +  p = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True) +  output = p.communicate()[0] +  all_runtimes.append(output) +``` + +由于本例中没法避免使用命令行,所以可以优先使用 Bash。 + +#### 羞耻的宣传时间 + +如果你喜欢这篇文章,这里还有很多类似的文章! [在此注册,加入 OSCON][5],2018 年 7 月 17 号我会在这做一个主题为 [你所不了解的 Bash][6] 的在线编码研讨会。没有幻灯片,不需要门票,只有你和我在命令行里面敲代码,探索 Bash 中的奇妙世界。 + +本文章由 [Medium] 首发,再发布时已获得授权。 + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/5/you-dont-know-bash-intro-bash-arrays + +作者:[Robert Aboukhalil][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[BriFuture](https://github.com/BriFuture) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://opensource.com/users/robertaboukhalil +[1]:https://opensource.com/article/17/7/bash-prompt-tips-and-tricks +[2]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals +[3]:https://github.com/typicode/jsonplaceholder +[4]:https://stedolan.github.io/jq/ +[5]:https://conferences.oreilly.com/oscon/oscon-or +[6]:https://conferences.oreilly.com/oscon/oscon-or/public/schedule/detail/67166 +[7]:https://medium.com/@robaboukhalil/the-weird-wondrous-world-of-bash-arrays-a86e5adf2c69 diff --git a/published/201807/20180604 4 cool new projects to try in COPR for June 2018.md b/published/201807/20180604 4 cool new projects to try in COPR for June 2018.md new file mode 100644 index 0000000000..2dad998bbb --- /dev/null +++ b/published/201807/20180604 4 cool new projects to try in COPR for June 2018.md @@ -0,0 +1,86 @@ +2018 年 6 月 COPR 中值得尝试的 4 个很酷的新项目 +====== + +![](https://fedoramagazine.org/wp-content/uploads/2017/08/4-copr-1024x433.jpg) + +COPR 是个人软件仓库[集合][1],它不在 Fedora 中。这是因为某些软件不符合轻松打包的标准。或者它可能不符合其他 Fedora 标准,尽管它是免费和开源的。COPR 可以在 Fedora 套件之外提供这些项目。COPR 中的软件不被 Fedora 基础设施不支持或没有被该项目所签名。但是,这是一种尝试新的或实验性的软件的一种巧妙的方式。 + +这是 COPR 中一组新的有趣项目。 + +### Ghostwriter + +[Ghostwriter][2] 是 [Markdown][3] 格式的文本编辑器,它有一个最小的界面。它以 HTML 格式提供文档预览,并为 Markdown 提供语法高亮显示。它提供了仅高亮显示当前正在编写的段落或句子的选项。此外,Ghostwriter 可以将文档导出为多种格式,包括 PDF 和 HTML。最后,它有所谓的“海明威”模式,其中删除被禁用,迫使用户现在智能编写,而在稍后编辑。 + +![][4] + +#### 安装说明 + +仓库目前为 Fedora 26、27、28 和 Rawhide 以及 EPEL 7 提供 Ghostwriter。要安装 Ghostwriter,请使用以下命令: + +``` +sudo dnf copr enable scx/ghostwriter +sudo dnf install ghostwriter +``` + +### Lector + +[Lector][5] 是一个简单的电子书阅读器程序。Lector 支持最常见的电子书格式,如 EPUB、MOBI 和 AZW,以及漫画书格式 CBZ 和 CBR。它很容易设置 —— 只需指定包含电子书的目录即可。你可以使用表格或书籍封面浏览 Lector 库内的书籍。Lector 的功能包括书签、用户自定义标签和内置字典。![][6] + +#### 安装说明 + +该仓库目前为 Fedora 26、27、28 和 Rawhide 提供Lector。要安装 Lector,请使用以下命令: + +``` +sudo dnf copr enable bugzy/lector +sudo dnf install lector +``` + +### Ranger + +Ranerger 是一个基于文本的文件管理器,它带有 Vim 键绑定。它以三列显示目录结构。左边显示父目录,中间显示当前目录的内容,右边显示所选文件或目录的预览。对于文本文件,Ranger 将文件的实际内容作为预览。![][7] + +#### 安装说明 + +该仓库目前为 Fedora 27、28 和 Rawhide 提供 Ranger。要安装 Ranger,请使用以下命令: + +``` +sudo dnf copr enable fszymanski/ranger +sudo dnf install ranger +``` + +### PrestoPalette + +PrestoPeralette 是一款帮助创建平衡调色板的工具。PrestoPalette 的一个很好的功能是能够使用光照来影响调色板的亮度和饱和度。你可以将创建的调色板导出为 PNG 或 JSON。 + +![][8] + +#### 安装说明 + +仓库目前为 Fedora 26、27、28 和 Rawhide 以及 EPEL 7 提供 PrestoPalette。要安装 PrestoPalette,请使用以下命令: + +``` +sudo dnf copr enable dagostinelli/prestopalette +sudo dnf install prestopalette +``` + + +-------------------------------------------------------------------------------- + +via: https://fedoramagazine.org/4-try-copr-june-2018/ + +作者:[Dominik Turecek][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[geekpi](https://github.com/geekpi) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://fedoramagazine.org +[1]:https://copr.fedorainfracloud.org/ +[2]:http://wereturtle.github.io/ghostwriter/ +[3]:https://daringfireball.net/ +[4]:https://fedoramagazine.org/wp-content/uploads/2018/05/ghostwriter.png +[5]:https://github.com/BasioMeusPuga/Lector +[6]:https://fedoramagazine.org/wp-content/uploads/2018/05/lector.png +[7]:https://fedoramagazine.org/wp-content/uploads/2018/05/ranger.png +[8]:https://fedoramagazine.org/wp-content/uploads/2018/05/prestopalette.png diff --git a/published/201807/20180606 6 Open Source AI Tools to Know.md b/published/201807/20180606 6 Open Source AI Tools to Know.md new file mode 100644 index 0000000000..8c26e7308c --- /dev/null +++ b/published/201807/20180606 6 Open Source AI Tools to Know.md @@ -0,0 +1,71 @@ +你应该了解的 6 个开源 AI 工具 +====== + +> 让我们来看看几个任何人都能用的自由开源的 AI 工具。 + +![](https://www.linux.com/sites/lcom/files/styles/rendered_file/public/artificial-intelligence-3382507_1920.jpg?itok=HarDnwVX) + +在开源领域,不管你的想法是多少的新颖独到,先去看一下别人是否已经做成了这个概念,总是一个很明智的做法。对于有兴趣借助不断成长的人工智能Artificial Intelligence(AI)的力量的组织和个人来说,许多优秀的工具不仅是自由开源的,而且在很多的情况下,它们都已经过测试和久经考验的。 + +在领先的公司和非盈利组织中,AI 的优先级都非常高,并且这些公司和组织都开源了很有价值的工具。下面的举例是任何人都可以使用的自由开源的 AI 工具。 + +### Acumos + +[Acumos AI][1] 是一个平台和开源框架,使用它可以很容易地去构建、共享和分发 AI 应用。它规范了运行一个“开箱即用的”通用 AI 环境所需要的基础设施栈infrastructure stack和组件。这使得数据科学家和模型训练者可以专注于它们的核心竞争力,而不用在无止境的定制、建模,以及训练一个 AI 实现上浪费时间。 + +Acumos 是 [LF 深度学习基金会][2] 的一部分,它是 Linux 基金会中的一个组织,它支持在人工智能、机器学习machine learning、以及深度学习deep learning方面的开源创新。它的目标是让这些重大的新技术可用于开发者和数据科学家,包括那些在深度学习和 AI 上经验有限的人。LF 深度学习基金会 [最近批准了一个项目生命周期和贡献流程][3],并且它现在正接受项目贡献的建议。 + +### Facebook 的框架 + +Facebook [开源了][4] 其中心机器学习系统,它设计用于做一些大规模的人工智能任务,以及一系列其它的 AI 技术。这个工具是经过他们公司验证使用的平台的一部分。Facebook 也开源了一个叫 [Caffe2][5] 的深度学习和人工智能的框架。 + +### CaffeOnSpark + +**说到 Caffe**。 Yahoo 也在开源许可证下发布了它自己的关键的 AI 软件。[CaffeOnSpark 工具][6] 是基于深度学习的,它是人工智能的一个分支,在帮助机器识别人类语言,或者照片、视频的内容方面非常有用。同样地,IBM 的机器学习程序 [SystemML][7] 可以通过 Apache 软件基金会自由地共享和修改。 + +### Google 的工具 + +Google 花费了几年的时间开发了它自己的 [TensorFlow][8] 软件框架,用于去支持它的 AI 软件和其它预测和分析程序。TensorFlow 是你可能都已经在使用的一些 Google 工具背后的引擎,包括 Google Photos 和在 Google app 中使用的语言识别。 + +Google 开源了两个 [AIY 套件][9],它可以让个人很容易地使用人工智能,它们专注于计算机视觉和语音助理。这两个套件将用到的所有组件封装到一个盒子中。该套件目前在美国的 Target 中有售,并且它是基于开源的树莓派平台的 —— 有越来越多的证据表明,在开源和 AI 交集中将发生非常多的事情。 + +### H2O.ai + +我 [以前介绍过][10] H2O.ai,它在机器学习和人工智能领域中占有一席之地,因为它的主要工具是自由开源的。你可以获取主要的 H2O 平台和 Sparkling Water,它与 Apache Spark 一起工作,只需要去 [下载][11] 它们即可。这些工具遵循 Apache 2.0 许可证,它是一个非常灵活的开源许可证,你甚至可以在 Amazon Web 服务(AWS)和其它的集群上运行它们,而这仅需要几百美元而已。 + +### Microsoft 入局 + +“我们的目标是让 AI 大众化,让每个人和组织获得更大的成就,“ Microsoft CEO 萨提亚·纳德拉 [说][12]。因此,微软持续迭代它的 [Microsoft Cognitive Toolkit][13](CNTK)。它是一个能够与 TensorFlow 和 Caffe 去竞争的一个开源软件框架。Cognitive Toolkit 可以工作在 64 位的 Windows 和 Linux 平台上。 + +Cognitive Toolkit 团队的报告称,“Cognitive Toolkit 通过允许用户去创建、训练,以及评估他们自己的神经网络,以使企业级的、生产系统级的 AI 成为可能,这些神经网络可能跨多个 GPU 以及多个机器在大量的数据集中高效伸缩。” + +--- + +从来自 Linux 基金会的新电子书中学习更多的有关 AI 知识。Ibrahim Haddad 的 [开源 AI:项目、洞察和趋势][14] 调查了 16 个流行的开源 AI 项目—— 深入研究了他们的历史、代码库、以及 GitHub 的贡献。 [现在可以免费下载这个电子书][14]。 + +-------------------------------------------------------------------------------- + +via: https://www.linux.com/blog/2018/6/6-open-source-ai-tools-know + +作者:[Sam Dean][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[qhwdw](https://github.com/qhwdw) +校对:[pityonline](https://github.com/pityonline), [wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.linux.com/users/sam-dean +[1]:https://www.acumos.org/ +[2]:https://www.linuxfoundation.org/projects/deep-learning/ +[3]:https://www.linuxfoundation.org/blog/lf-deep-learning-foundation-announces-project-contribution-process/ +[4]:https://code.facebook.com/posts/1687861518126048/facebook-to-open-source-ai-hardware-design/ +[5]:https://venturebeat.com/2017/04/18/facebook-open-sources-caffe2-a-new-deep-learning-framework/ +[6]:http://yahoohadoop.tumblr.com/post/139916563586/caffeonspark-open-sourced-for-distributed-deep +[7]:https://systemml.apache.org/ +[8]:https://www.tensorflow.org/ +[9]:https://www.techradar.com/news/google-assistant-sweetens-raspberry-pi-with-ai-voice-control +[10]:https://www.linux.com/news/sparkling-water-bridging-open-source-machine-learning-and-apache-spark +[11]:http://www.h2o.ai/download +[12]:https://blogs.msdn.microsoft.com/uk_faculty_connection/2017/02/10/microsoft-cognitive-toolkit-cntk/ +[13]:https://www.microsoft.com/en-us/cognitive-toolkit/ +[14]:https://www.linuxfoundation.org/publications/open-source-ai-projects-insights-and-trends/ diff --git a/published/201807/20180606 Getting started with Buildah.md b/published/201807/20180606 Getting started with Buildah.md new file mode 100644 index 0000000000..c1ece0f54e --- /dev/null +++ b/published/201807/20180606 Getting started with Buildah.md @@ -0,0 +1,226 @@ +Buildah 入门 +====== + +> Buildah 提供一种灵活、可脚本编程的方式,来使用你熟悉的工具创建精简、高效的容器镜像。 + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/blocks_building.png?itok=eMOT-ire) + +[Buildah][1] 是一个命令行工具,可以方便、快捷的构建与[开放容器标准][2]Open Container Initiative(OCI)兼容的容器镜像,这意味着其构建的镜像与 Docker 和 Kubernetes 兼容。该工具可作为 Docker 守护进程 `docker build` 命令(即使用传统的 Dockerfile 构建镜像)的一种简单drop-in替换,而且更加灵活,允许构建镜像时使用你擅长的工具。Buildah 可以轻松与脚本集成并生成流水线pipeline,最好之处在于构建镜像不再需要运行容器守护进程(LCTT 译注:这里主要是指 Docker 守护进程)。 + +### docker build 的简单替换 + +目前你可能使用 Dockerfile 和 `docker build` 命令构建镜像,那么你可以马上使用 Buildah 进行替代。Buildah 的 `build-using-dockerfile` (或 `bud`)子命令与 `docker build` 基本等价,因此可以轻松的与已有脚本结合或构建流水线。 + +类似我的上一篇关于 Buildah 的[文章][3],我也将以使用源码安装 “GNU Hello” 为例进行说明,对应的 Dockerfile 文件如下: + +``` +FROM fedora:28 +LABEL maintainer Chris Collins + +RUN dnf install -y tar gzip gcc make \ +        && dnf clean all + +ADD http://ftpmirror.gnu.org/hello/hello-2.10.tar.gz /tmp/hello-2.10.tar.gz + +RUN tar xvzf /tmp/hello-2.10.tar.gz -C /opt + +WORKDIR /opt/hello-2.10 + +RUN ./configure +RUN make +RUN make install +RUN hello -v +ENTRYPOINT "/usr/local/bin/hello" +``` + +使用 Buildah 从 Dockerfile 构建镜像也很简单,使用 `buildah bud -t hello .` 替换 `docker build -t hello .` 即可: + +``` +[chris@krang] $ sudo buildah bud -t hello . +STEP 1: FROM fedora:28 +Getting image source signatures +Copying blob sha256:e06fd16225608e5b92ebe226185edb7422c3f581755deadf1312c6b14041fe73 + 81.48 MiB / 81.48 MiB [====================================================] 8s +Copying config sha256:30190780b56e33521971b0213810005a69051d720b73154c6e473c1a07ebd609 + 2.29 KiB / 2.29 KiB [======================================================] 0s +Writing manifest to image destination +Storing signatures +STEP 2: LABEL maintainer Chris Collins +STEP 3: RUN dnf install -y tar gzip gcc make    && dnf clean all + +<考虑篇幅,略去后续输出> +``` + +镜像构建完毕后,可以使用 `buildah images` 命令查看这个新镜像: + +``` +[chris@krang] $ sudo buildah images +IMAGE ID        IMAGE NAME                              CREATED AT              SIZE +30190780b56e    docker.io/library/fedora:28             Mar 7, 2018 16:53       247 MB +6d54bef73e63    docker.io/library/hello:latest    May 3, 2018 15:24     391.8 MB +``` + +新镜像的标签为 `hello:latest`,我们可以将其推送至远程镜像仓库,可以使用 [CRI-O][4] 或其它 Kubernetes CRI 兼容的运行时来运行该镜像,也可以推送到远程仓库。如果你要测试对 Docker build 命令的替代性,你可以将镜像拷贝至 docker 守护进程的本地镜像存储中,这样 Docker 也可以使用该镜像。使用 `buildah push` 可以很容易的完成推送操作: + +``` +[chris@krang] $ sudo buildah push hello:latest docker-daemon:hello:latest +Getting image source signatures +Copying blob sha256:72fcdba8cff9f105a61370d930d7f184702eeea634ac986da0105d8422a17028 + 247.02 MiB / 247.02 MiB [==================================================] 2s +Copying blob sha256:e567905cf805891b514af250400cc75db3cb47d61219750e0db047c5308bd916 + 144.75 MiB / 144.75 MiB [==================================================] 1s +Copying config sha256:6d54bef73e638f2e2dd8b7bf1c4dfa26e7ed1188f1113ee787893e23151ff3ff + 1.59 KiB / 1.59 KiB [======================================================] 0s +Writing manifest to image destination +Storing signatures + +[chris@krang] $ sudo docker images | head -n2 +REPOSITORY              TAG             IMAGE ID        CREATED                 SIZE +docker.io/hello      latest       6d54bef73e63  2 minutes ago   398 MB + +[chris@krang] $ sudo docker run -t hello:latest +Hello, world! +``` + +### 若干差异 + +与 Docker build 不同,Buildah 不会自动的将 Dockerfile 中的每条指令产生的变更提到新的分层layer中,只是简单的每次从头到尾执行构建。类似于自动化automation流水线构建build pipeline,这种无缓存构建non-cached方式的好处是可以提高构建速度,在指令较多时尤为明显。从自动部署automated deployment持续交付continuous delivery的视角来看,使用这种方式可以快速的将新变更落实到生产环境中。 + +但从实际角度出发,缓存机制的缺乏对镜像开发不利,毕竟缓存层可以避免一遍遍的执行构建,从而显著的节省时间。自动分层只在 `build-using-dockerfile` 命令中生效。但我们在下面会看到,Buildah 原生命令允许我们选择将变更提交到硬盘的时间,提高了开发的灵活性。 + +### Buildah 原生命令 + +Buildah _真正_ 有趣之处在于它的原生命令,你可以在容器构建过程中使用这些命令进行交互。相比与使用 `build-using-dockerfile/bud` 命令执行每次构建,Buildah 提供命令让你可以与构建过程中的临时容器进行交互。(Docker 也使用临时或 _中间_ intermediate容器,但你无法在镜像构建过程中与其交互。) + +还是使用 “GNU Hello” 为例,考虑使用如下 Buildah 命令构建的镜像: + +``` +#!/usr/bin/env bash + +set -o errexit + +# Create a container +container=$(buildah from fedora:28) + +# Labels are part of the "buildah config" command +buildah config --label maintainer="Chris Collins " $container + +# Grab the source code outside of the container +curl -sSL http://ftpmirror.gnu.org/hello/hello-2.10.tar.gz -o hello-2.10.tar.gz + +buildah copy $container hello-2.10.tar.gz /tmp/hello-2.10.tar.gz + +buildah run $container dnf install -y tar gzip gcc make +buildah run $container dnf clean all +buildah run $container tar xvzf /tmp/hello-2.10.tar.gz -C /opt + +# Workingdir is also a "buildah config" command +buildah config --workingdir /opt/hello-2.10 $container + +buildah run $container ./configure +buildah run $container make +buildah run $container make install +buildah run $container hello -v + +# Entrypoint, too, is a “buildah config” command +buildah config --entrypoint /usr/local/bin/hello $container + +# Finally saves the running container to an image +buildah commit --format docker $container hello:latest +``` + +我们可以一眼看出这是一个 Bash 脚本而不是 Dockerfile。基于 Buildah 的原生命令,可以轻易的使用任何脚本语言或你擅长的自动化工具编写脚本。形式可以是 makefile、Python 脚本或其它你擅长的类型。 + +这个脚本做了哪些工作呢?首先,Buildah 命令 `container=$(buildah from fedora:28)` 基于 fedora:28 镜像创建了一个正在运行的容器,将容器名(`buildah from` 命令的返回值)保存到变量中,便于后续使用。后续所有命令都是有 `$container` 变量指明需要操作的容器。这些命令的功能大多可以从名称看出:`buildah copy` 将文件拷贝至容器,`buildah run` 会在容器中执行命令。可以很容易的将上述命令与 Dockerfile 中的指令对应起来。 + +最后一条命令 `buildah commit` 将容器提交到硬盘上的镜像中。当不使用 Dockerfile 而是使用 Buildah 命令构建镜像时,你可以使用 `commit` 命令决定何时保存变更。在上例中,所有的变更是一起提交的;但也可以增加中间提交,让你可以选择作为起点的缓存点cache point。(例如,执行完 `dnf install` 命令后将变更缓存到硬盘是特别有意义的,一方面因为该操作耗时较长,另一方面每次执行的结果也确实相同。) + +### 挂载点,安装目录以及 chroot + +另一个可以大大增加构建镜像灵活性的 Buildah 命令是 `buildah mount`,可以将容器的根目录挂载到你主机的一个挂载点上。例如: + +``` +[chris@krang] $ container=$(sudo buildah from fedora:28) +[chris@krang] $ mountpoint=$(sudo buildah mount ${container}) +[chris@krang] $ echo $mountpoint +/var/lib/containers/storage/overlay2/463eda71ec74713d8cebbe41ee07da5f6df41c636f65139a7bd17b24a0e845e3/merged +[chris@krang] $ cat ${mountpoint}/etc/redhat-release +Fedora release 28 (Twenty Eight) +[chris@krang] $ ls ${mountpoint} +bin   dev  home  lib64          media  opt   root  sbin  sys  usr +boot  etc  lib   lost+found  mnt        proc  run   srv   tmp  var +``` + +这太棒了,你可以通过与挂载点交互对容器镜像进行修改。这允许你使用主机上的工具进行构建和安装软件,不用将这些构建工具打包到容器镜像本身中。例如,在我们上面的 Bash 脚本中,我们需要安装 tar、Gzip、GCC 和 make,在容器内编译 “GNU Hello”。如果使用挂载点,我仍使用同样的工具进行构建,但下载的压缩包和 tar、Gzip 等 RPM 包都在主机而不是容器和生成的镜像内: + +``` +#!/usr/bin/env bash + +set -o errexit + +# Create a container +container=$(buildah from fedora:28) +mountpoint=$(buildah mount $container) + +buildah config --label maintainer="Chris Collins " $container + +curl -sSL http://ftpmirror.gnu.org/hello/hello-2.10.tar.gz \ +     -o /tmp/hello-2.10.tar.gz +tar xvzf src/hello-2.10.tar.gz -C ${mountpoint}/opt + +pushd ${mountpoint}/opt/hello-2.10 +./configure +make +make install DESTDIR=${mountpoint} +popd + +chroot $mountpoint bash -c "/usr/local/bin/hello -v" + +buildah config --entrypoint "/usr/local/bin/hello" $container +buildah commit --format docker $container hello +buildah unmount $container +``` + +在上述脚本中,需要提到如下几点: + + 1. `curl` 命令将压缩包下载到主机中,而不是镜像中; + 2. (主机中的) `tar` 命令将压缩包中的源代码解压到容器的 `/opt` 目录; + 3. `configure`,`make` 和 `make install` 命令都在主机的挂载点目录中执行,而不是在容器内; + 4. 这里的 `chroot` 命令用于将挂载点本身当作根路径并测试 "hello" 是否正常工作;类似于前面例子中用到的 `buildah run` 命令。 + + +这个脚本更加短小,使用大多数 Linux 爱好者都很熟悉的工具,最后生成的镜像也更小(没有 tar 包,没有额外的软件包等)。你甚至可以使用主机系统上的包管理器为容器安装软件。例如,(出于某种原因)你希望安装 GNU Hello 的同时在容器中安装 [NGINX][5]: + +``` +[chris@krang] $ mountpoint=$(sudo buildah mount ${container}) +[chris@krang] $ sudo dnf install nginx --installroot $mountpoint +[chris@krang] $ sudo chroot $mountpoint nginx -v +nginx version: nginx/1.12.1 +``` + +在上面的例子中,DNF 使用 `--installroot` 参数将 NGINX 安装到容器中,可以通过 chroot 进行校验。 + +### 快来试试吧! + +Buildah 是一种轻量级、灵活的容器镜像构建方法,不需要在主机上运行完整的 Docker 守护进程。除了提供基于 Dockerfile 构建容器的开箱即用支持,Buildah 还可以很容易的与脚本或你喜欢的构建工具相结合,特别是可以使用主机上已有的工具构建容器镜像。Buildah 生成的容器体积更小,更便于网络传输,占用更小的存储空间,而且潜在的受攻击面更小。快来试试吧! + +**[阅读相关的故事,[使用 Buildah 创建小体积的容器][6]]** + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/6/getting-started-buildah + +作者:[Chris Collins][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[pinewall](https://github.com/pinewall) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://opensource.com/users/clcollins +[1]:https://github.com/projectatomic/buildah +[2]:https://www.opencontainers.org/ +[3]:http://chris.collins.is/2017/08/17/buildah-a-new-way-to-build-container-images/ +[4]:http://cri-o.io/ +[5]:https://www.nginx.com/ +[6]:https://linux.cn/article-9719-1.html diff --git a/published/20180606 Intel and AMD Reveal New Processor Designs.md b/published/201807/20180606 Intel and AMD Reveal New Processor Designs.md similarity index 100% rename from published/20180606 Intel and AMD Reveal New Processor Designs.md rename to published/201807/20180606 Intel and AMD Reveal New Processor Designs.md diff --git a/translated/tech/20180607 3 journaling applications for the Linux desktop.md b/published/201807/20180607 3 journaling applications for the Linux desktop.md similarity index 54% rename from translated/tech/20180607 3 journaling applications for the Linux desktop.md rename to published/201807/20180607 3 journaling applications for the Linux desktop.md index 23d7435e21..daa4d97ab3 100644 --- a/translated/tech/20180607 3 journaling applications for the Linux desktop.md +++ b/published/201807/20180607 3 journaling applications for the Linux desktop.md @@ -1,10 +1,13 @@ 3 款 Linux 桌面的日记程序 ====== -![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/desk_clock_job_work.jpg?itok=Nj4fuhl6) -保持记日记,即使是不定期,也可以带来很多好处。这不仅是治疗和宣泄,而且还可以很好地记录你所处的位置以及你去过的地方。它可以帮助你展示你在生活中的进步,并提醒你自己做对了什么,做错了什么。 +> 用轻量、灵活的数字日记工具来记录你的活动。 -无论你记日记的原因是什么,都有多种方法可以做到这一点。你可以去读书,使用笔和纸。你可以使用基于 Web 的程序。或者你可以使用[简单的文本文件][1]。 +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/desk_clock_job_work.jpg?itok=Nj4fuhl6) + +保持记日记的习惯,即使是不定期地记,也可以带来很多好处。这不仅是治疗和宣泄,而且还可以很好地记录你所在的位置以及你去过的地方。它可以帮助你展示你在生活中的进步,并提醒你自己做对了什么,做错了什么。 + +无论你记日记的原因是什么,都有多种方法可以做到这一点。你可以使用传统的笔和纸,也可以使用基于 Web 的程序,或者你可以使用[简单的文本文件][1]。 另一种选择是使用专门的日记程序。Linux 桌面有几种非常灵活且非常有用的日记工具。我们来看看其中的三个。 @@ -12,11 +15,11 @@ ![](https://opensource.com/sites/default/files/uploads/red-notebook.png) -在这里描述的三个日记程序中,[RedNotebook][2] 是最灵活的。大部分灵活性来自其模板。这些模板可让莫记录个人想法或会议记录、计划旅程或记录电话。你还可以编辑现有模板或创建自己的模板。 +在这里描述的三个日记程序中,[RedNotebook][2] 是最灵活的。大部分灵活性来自其模板。这些模板可让你记录个人想法或会议记录、计划旅程或记录电话。你还可以编辑现有模板或创建自己的模板。 -你使用与 Markdown 非常相似的标记语言记录日记。你还可以在日记中添加标签,以便于查找。只需在程序的左窗格中单击或输入标记,右窗格中将显示相应日记的列表。 +你可以使用与 Markdown 非常相似的标记语言来记录日记。你还可以在日记中添加标签,以便于查找。只需在程序的左窗格中单击或输入标记,右窗格中将显示相应日记的列表。 -最重要的是,你可以将全部或部分或仅一个日记录导出为纯文本、HTML、LaTeX 或 PDF。在执行此操作之前,你可以通过单击工具栏上的“预览”按钮了解日志在 PDF 或 HTML 中的显示情况。 +最重要的是,你可以将全部、部分或仅一个日记导出为纯文本、HTML、LaTeX 或 PDF。在执行此操作之前,你可以通过单击工具栏上的“预览”按钮了解日志在 PDF 或 HTML 中的显示情况。 总的来说,RedNotebook 是一款易于使用且灵活的程序。它需要习惯,但一旦你这样做,它是一个有用的工具。 @@ -24,9 +27,9 @@ ![](https://opensource.com/sites/default/files/uploads/lifeograph.png) -[Lifeograph][3] 与 RedNotebook 有相似的外观和感觉。它没有那么多功能,但 Lifeograph 可以完成工作。 +[Lifeograph][3] 与 RedNotebook 有相似的外观和感觉。它没有那么多功能,但 Lifeograph 也够了。 -该程序通过保持简单和整洁来简化记日记。你有一个很大的区域可以记录,你可以为日记添加一些基本格式。这包括通常的粗体和斜体,以及箭头和高亮显示。你可以在日记中添加标签,以便更好地组织和查找它们。 +该程序通过保持简单和整洁性来简化记日记这件事。你有一个很大的区域可以记录,你可以为日记添加一些基本格式。这包括通常的粗体和斜体,以及箭头和高亮显示。你可以在日记中添加标签,以便更好地组织和查找它们。 Lifeograph 有一个我觉得特别有用的功能。首先,你可以创建多个日记 - 例如,工作日记和个人日记。其次是密码保护你的日记的能力。虽然该网站声称 Lifeograph 使用“真正的加密”,但没有关于它的详细信息。尽管如此,设置密码仍然会阻止大多数窥探者。 @@ -34,15 +37,15 @@ Lifeograph 有一个我觉得特别有用的功能。首先,你可以创建多 ![](https://opensource.com/sites/default/files/uploads/almanah.png) -[Almanah Diary][4] 是另一种非常简单的日记工具。但不要因为它缺乏功能就关闭它。这很简单,但完成了工作。 +[Almanah Diary][4] 是另一种非常简单的日记工具。但不要因为它缺乏功能就丢掉它。虽简单,但足够。 -有多简单?它差多是一个区域包含了日记输入和日历。你可以做更多的事情 - 比如添加一些基本格式(粗体、斜体和下划线)并将文本转换为超链接。Almanah 还允许你加密日记。 +有多简单?它差不多只是一个包含了日记输入和日历的区域而已。你可以做更多的事情 —— 比如添加一些基本格式(粗体、斜体和下划线)并将文本转换为超链接。Almanah 还允许你加密日记。 -虽然有一个功能可以将纯文本文件导入程序,但我无法使其正常工作。尽管如此,如果你喜欢一个简单,能够快速记日记的软件,那么 Almanah 日记值得一看。 +虽然有一个可以将纯文本文件导入该程序的功能,但我无法使其正常工作。尽管如此,如果你喜欢一个简单,能够快速记日记的软件,那么 Almanah 日记值得一看。 ### 命令行怎么样? -如果你不想用 GUI 则可以不必去做。命令行是保存日记的绝佳选择。 +如果你不想用 GUI 则可以不必用。命令行是保存日记的绝佳选择。 我尝试过并且喜欢的是 [jrnl][5]。或者你可以使用[此方案][6],它使用命令行别名格式化并将日记保存到文本文件中。 @@ -55,7 +58,7 @@ via: https://opensource.com/article/18/6/linux-journaling-applications 作者:[Scott Nesbitt][a] 选题:[lujun9972](https://github.com/lujun9972) 译者:[geekpi](https://github.com/geekpi) -校对:[校对者ID](https://github.com/校对者ID) +校对:[wxy](https://github.com/wxy) 本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 diff --git a/published/201807/20180607 GitLab-s Ultimate - Gold Plans Are Now Free For Open-Source Projects.md b/published/201807/20180607 GitLab-s Ultimate - Gold Plans Are Now Free For Open-Source Projects.md new file mode 100644 index 0000000000..fb1f925c0a --- /dev/null +++ b/published/201807/20180607 GitLab-s Ultimate - Gold Plans Are Now Free For Open-Source Projects.md @@ -0,0 +1,77 @@ +GitLab 的付费套餐现在可以免费用于开源项目 +====== + +最近在开源社区发生了很多事情。首先,[微软收购了 GitHub][1],然后人们开始寻找 [GitHub 替代套餐][2],甚至在 Linus Torvalds 发布 [Linux Kernel 4.17][3] 时没有花一点时间考虑它。好吧,如果你一直关注我们,我认为你知道这一切。 + +但是,如今,GitLab 做出了一个明智的举措,为教育机构和开源项目免费提供高级套餐。当许多开发人员有兴趣将他们的开源项目迁移到 GitLab 时,没有更好的时机来提供这些了。 + +### GitLab 的高级套餐现在对开源项目和教育机构免费 + +![GitLab Logo][4] + +在今天(2018/6/7)[发布的博客][5]中,GitLab 宣布其**旗舰**和黄金套餐现在对教育机构和开源项目免费。虽然我们已经知道为什么 GitLab 做出这个举动(一个完美的时机!),但他们还是解释了他们让它免费的动机: + +> 我们让 GitLab 对教育机构免费,因为我们希望学生使用我们最先进的功能。许多大学已经运行了 GitLab。如果学生使用 GitLab 旗舰和黄金套餐的高级功能,他们将把这些高级功能的经验带到他们的工作场所。 +> +> 我们希望有更多的开源项目使用 GitLab。GitLab.com 上的公共项目已经拥有 GitLab 旗舰套餐的所有功能。像 [Gnome][6] 和 [Debian][7] 这样的项目已经在自己的服务器运行开源版 GitLab 。随着今天的宣布,在专有软件上运行的开源项目可以使用 GitLab 提供的所有功能,同时我们通过向非开源组织收费来建立可持续的业务模式。 + +### GitLab 提供的这些“免费”套餐是什么? + +![GitLab Pricing][8] + +GitLab 有两类产品。一个是你可以在自己的云托管服务如 [Digital Ocean][9] 上运行的软件。另一个是 Gitlab 软件既服务,其中托管由 GitLab 本身管理,你在 GitLab.com 上获得一个帐户。 + +![GitLab Pricing for hosted service][10] + +黄金套餐是托管类别中最高的产品,而旗舰套餐是自托管类别中的最高产品。 + +你可以在 GitLab 定价页面上获得有关其功能的更多详细信息。请注意,支持服务不包括在套餐中。你必须单独购买。 + +### 你必须符合某些条件才能使用此优惠 + +GitLab 还提到 —— 该优惠对谁有效。以下是他们在博客文章中写的内容: + +> 1. **教育机构:**任何为了学习、教育的机构,并且/或者由合格的教育机构、教职人员、学生训练。教育目的不包括商业,专业或任何其他营利目的。 +> +> 2. **开源项目:**任何使用[标准开源许可证][11]且非商业性的项目。它不应该有付费支持或付费贡献者。 +> + + +虽然免费套餐不包括支持,但是当你迫切需要专家帮助解决问题时,你仍然可以支付每用户每月 4.95 美元的额外费用 —— 当你特别需要一个专家来解决问题时,这是一个非常合理的价格。 + +GitLab 还为学生们添加了一条说明: + +> 为减轻 GitLab 的管理负担,只有教育机构才能代表学生申请。如果你是学生并且你的教育机构不申请,你可以在 GitLab.com 上使用公共项目的所有功能,使用私人项目的免费功能,或者自己付费。 + +### 总结 + +现在 GitLab 正在加快脚步,你如何看待它? + +你有 [GitHub][12] 上的项目吗?你会切换么?或者,幸运的是,你从一开始就碰巧使用 GitLab? + +请在下面的评论栏告诉我们你的想法。 + +-------------------------------------------------------------------------------- + +via: https://itsfoss.com/gitlab-free-open-source/ + +作者:[Ankush Das][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[geekpi](https://github.com/geekpi) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://itsfoss.com/author/ankush/ +[1]:https://itsfoss.com/microsoft-github/ +[2]:https://itsfoss.com/github-alternatives/ +[3]:https://itsfoss.com/linux-kernel-4-17/ +[4]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/06/GitLab-logo-800x450.png +[5]:https://about.gitlab.com/2018/06/05/gitlab-ultimate-and-gold-free-for-education-and-open-source/ +[6]:https://www.gnome.org/news/2018/05/gnome-moves-to-gitlab-2/ +[7]:https://salsa.debian.org/public +[8]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/06/gitlab-pricing.jpeg +[9]:https://m.do.co/c/d58840562553 +[10]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/06/gitlab-hosted-service-800x273.jpeg +[11]:https://itsfoss.com/open-source-licenses-explained/ +[12]:https://github.com/ diff --git a/published/201807/20180607 Mesos and Kubernetes- It-s Not a Competition.md b/published/201807/20180607 Mesos and Kubernetes- It-s Not a Competition.md new file mode 100644 index 0000000000..8420ca41aa --- /dev/null +++ b/published/201807/20180607 Mesos and Kubernetes- It-s Not a Competition.md @@ -0,0 +1,68 @@ +Mesos 和 Kubernetes:不是竞争者 +====== + +> 人们经常用 x 相对于 y 这样的术语来考虑问题,但是它并不是一个技术对另一个技术的问题。Ben Hindman 在这里解释了 Mesos 是如何对另外一种技术进行补充的。 + +![](https://www.linux.com/sites/lcom/files/styles/rendered_file/public/architecture-barge-bay-161764_0.jpg?itok=vNChG5fb) + +Mesos 的起源可以追溯到 2009 年,当时,Ben Hindman 还是加州大学伯克利分校研究并行编程的博士生。他们在 128 核的芯片上做大规模的并行计算,以尝试去解决多个问题,比如怎么让软件和库在这些芯片上运行更高效。他与同学们讨论能否借鉴并行处理和多线程的思想,并将它们应用到集群管理上。 + +Hindman 说 “最初,我们专注于大数据” 。那时,大数据非常热门,而 Hadoop 就是其中的一个热门技术。“我们发现,人们在集群上运行像 Hadoop 这样的程序与运行多线程应用及并行应用很相似。”Hindman 说。 + +但是,它们的效率并不高,因此,他们开始去思考,如何通过集群管理和资源管理让它们运行的更好。“我们查看了那个时期很多的各种技术” Hindman 回忆道。 + +然后,Hindman 和他的同事们决定去采用一种全新的方法。“我们决定对资源管理创建一个低级的抽象,然后在此之上运行调度服务和做其它的事情。” Hindman 说,“基本上,这就是 Mesos 的本质 —— 将资源管理部分从调度部分中分离出来。” + +他成功了,并且 Mesos 从那时开始强大了起来。 + +### 将项目呈献给 Apache + +这个项目发起于 2009 年。在 2010 年时,团队决定将这个项目捐献给 Apache 软件基金会(ASF)。它在 Apache 孵化,并于 2013 年成为顶级项目(TLP)。 + +为什么 Mesos 社区选择 Apache 软件基金会有很多的原因,比如,Apache 许可证,以及基金会已经拥有了一个充满活力的其它此类项目的社区。 + +与影响力也有关系。许多在 Mesos 上工作的人也参与了 Apache,并且许多人也致力于像 Hadoop 这样的项目。同时,来自 Mesos 社区的许多人也致力于其它大数据项目,比如 Spark。这种交叉工作使得这三个项目 —— Hadoop、Mesos,以及 Spark —— 成为 ASF 的项目。 + +与商业也有关系。许多公司对 Mesos 很感兴趣,并且开发者希望它能由一个中立的机构来维护它,而不是让它成为一个私有项目。 + +### 谁在用 Mesos? + +更好的问题应该是,谁不在用 Mesos?从 Apple 到 Netflix 每个都在用 Mesos。但是,Mesos 也面临任何技术在早期所面对的挑战。“最初,我要说服人们,这是一个很有趣的新技术。它叫做‘容器’,因为它不需要使用虚拟机” Hindman 说。 + +从那以后,这个行业发生了许多变化,现在,只要与别人聊到基础设施,必然是从”容器“开始的 —— 感谢 Docker 所做出的工作。今天再也不需要做说服工作了,而在 Mesos 出现的早期,前面提到的像 Apple、Netflix,以及 PayPal 这样的公司。他们已经知道了容器替代虚拟机给他们带来的技术优势。“这些公司在容器成为一种现象之前,已经明白了容器的价值所在”, Hindman 说。 + +可以在这些公司中看到,他们有大量的容器而不是虚拟机。他们所做的全部工作只是去管理和运行这些容器,并且他们欣然接受了 Mesos。在 Mesos 早期就使用它的公司有 Apple、Netflix、PayPal、Yelp、OpenTable 和 Groupon。 + +“大多数组织使用 Mesos 来运行各种服务” Hindman 说,“但也有些公司用它做一些非常有趣的事情,比如,数据处理、数据流、分析任务和应用程序。“ + +这些公司采用 Mesos 的其中一个原因是,资源管理层之间有一个明晰的界线。当公司运营容器的时候,Mesos 为他们提供了很好的灵活性。 + +“我们尝试使用 Mesos 去做的一件事情是去创建一个层,以让使用者享受到我们的层带来的好处,当然也可以在它之上创建任何他们想要的东西,” Hindman 说。 “我认为这对一些像 Netflix 和 Apple 这样的大公司非常有用。” + +但是,并不是每个公司都是技术型的公司;不是每个公司都有或者应该有这种专长。为帮助这样的组织,Hindman 联合创建了 Mesosphere 去围绕 Mesos 提供服务和解决方案。“我们最终决定,为这样的组织去构建 DC/OS,它不需要技术专长或者不想把时间花费在像构建这样的事情上。” + +### Mesos vs. Kubernetes? + +人们经常用 x 相对于 y 这样的术语来考虑问题,但是它并不是一个技术对另一个技术的问题。大多数的技术在一些领域总是重叠的,并且它们可以是互补的。“我不喜欢将所有的这些东西都看做是竞争者。我认为它们中的一些与另一个在工作中是互补的,” Hindman 说。 + +“事实上,名字 Mesos 表示它处于 ‘中间’;它是一种中间的操作系统”, Hindman 说,“我们有一个容器调度器的概念,它能够运行在像 Mesos 这样的东西之上。当 Kubernetes 刚出现的时候,我们实际上在 Mesos 的生态系统中接受了它,并将它看做是在 Mesos 上的 DC/OS 中运行容器的另一种方式。” + +Mesos 也复活了一个名为 [Marathon][1](一个用于 Mesos 和 DC/OS 的容器编排器)的项目,它成为了 Mesos 生态系统中最重要的成员。但是,Marathon 确实无法与 Kubernetes 相比较。“Kubernetes 比 Marathon 做的更多,因此,你不能将它们简单地相互交换,” Hindman 说,“与此同时,我们在 Mesos 中做了许多 Kubernetes 中没有的东西。因此,这些技术之间是互补的。” + +不要将这些技术视为相互之间是敌对的关系,它们应该被看做是对行业有益的技术。它们不是技术上的重复;它们是多样化的。据 Hindman 说,“对于开源领域的终端用户来说,这可能会让他们很困惑,因为他们很难去知道哪个技术适用于哪种任务,但这是这个被称之为开源的本质所在。“ + +这只是意味着有更多的选择,并且每个都是赢家。 + +-------------------------------------------------------------------------------- + +via: https://www.linux.com/blog/2018/6/mesos-and-kubernetes-its-not-competition + +作者:[Swapnil Bhartiya][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[qhwdw](https://github.com/qhwdw) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.linux.com/users/arnieswap +[1]:https://mesosphere.github.io/marathon/ diff --git a/translated/tech/20180611 Turn Your Raspberry Pi into a Tor Relay Node.md b/published/201807/20180611 Turn Your Raspberry Pi into a Tor Relay Node.md similarity index 69% rename from translated/tech/20180611 Turn Your Raspberry Pi into a Tor Relay Node.md rename to published/201807/20180611 Turn Your Raspberry Pi into a Tor Relay Node.md index 53296cd8c3..7ccbee05eb 100644 --- a/translated/tech/20180611 Turn Your Raspberry Pi into a Tor Relay Node.md +++ b/published/201807/20180611 Turn Your Raspberry Pi into a Tor Relay Node.md @@ -1,9 +1,11 @@ 将你的树莓派打造成一个 Tor 中继节点 ====== +> 在此教程中学习如何将你的旧树莓派打造成一个完美的 Tor 中继节点。 + ![](https://www.linux.com/sites/lcom/files/styles/rendered_file/public/tor-onion-router.jpg?itok=6WUl0ElH) -你是否和我一样,在第一代或者第二代树莓派发布时买了一个,玩了一段时间就把它搁置“吃灰”了。毕竟,除非你是机器人爱好者,否则一般不太可能去长时间使用一个处理器很慢的并且内存只有 256 MB 的计算机的。这并不是说你不能用它去做一件很酷的东西,但是在工作和其它任务之间,我还没有看到用一些旧的物件发挥新作用的机会。 +你是否和我一样,在第一代或者第二代树莓派发布时买了一个,玩了一段时间就把它搁置“吃灰”了。毕竟,除非你是机器人爱好者,否则一般不太可能去长时间使用一个处理器很慢的、并且内存只有 256 MB 的计算机。这并不是说你不能用它去做一件很酷的东西,但是在工作和其它任务之间,我还没有看到用一些旧的物件发挥新作用的机会。 然而,如果你想去好好利用它并且不想花费你太多的时间和资源的话,可以将你的旧树莓派打造成一个完美的 Tor 中继节点。 @@ -11,18 +13,13 @@ 在此之前你或许听说过 [Tor 项目][1],如果恰好你没有听说过,我简单给你介绍一下,“Tor” 是 “The Onion Router(洋葱路由器)” 的缩写,它是用来对付在线追踪和其它违反隐私行为的技术。 -不论你在因特网上做什么事情,都会在你的 IP 包通过的设备上留下一些数字“脚印”:所有的交换机、路由器、负载均衡,以及目标网络记录的来自你的原始会话的 IP 地址,以及你访问的因特网资源(经常是主机名、[甚至是在使用 HTTPS 时][2])的 IP 地址。如何你是在家中上因特网,那么你的 IP 地址可以直接映射到你的家庭所在地。如果你使用了 VPN 服务([你应该使用][3]),那么你的 IP 地址是映射到你的 VPN 提供商那里,而 VPN 提供商是可以映射到你的家庭所在地的。无论如何,有可能在某个地方的某个人正在根据你访问的网络和在网站上呆了多长时间来为你建立一个个人的在线资料。然后将这个资料进行出售,并与从其它服务上收集的资料进行聚合,然后利用广告网络进行赚钱。至少,这是乐观主义者对如何利用这些数据的一些看法 —— 我相信你还可以找到更多的更恶意地使用这些数据的例子。 - -Tor 项目尝试去提供一个解决这种问题的方案,使它们不可能(或者至少是更加困难)追踪到你的终端 IP 地址。Tor 是通过让你的连接在一个由匿名的入口节点、中继节点、和出口节点组成的匿名中继链上反复跳转的方式来实现防止追踪的目的: - - 1. **入口节点** 只知道你的 IP 地址和中继节点的 IP 地址,但是不知道你最终要访问的目标 IP 地址 - - 2. **中继节点** 只知道入口节点和出口节点的 IP 地址,以及即不是源也不是最终目标的 IP 地址 - - 3. **出口节点** 仅知道中继节点和最终目标地址,它是在到达最终目标地址之前解密流量的节点 - +不论你在互联网上做什么事情,都会在你的 IP 包通过的设备上留下一些数字“脚印”:所有的交换机、路由器、负载均衡,以及目标网络记录的来自你的原始会话的 IP 地址,以及你访问的互联网资源(通常是它的主机名,[即使是在使用 HTTPS 时][2])的 IP 地址。如过你是在家中上互联网,那么你的 IP 地址可以直接映射到你的家庭所在地。如果你使用了 VPN 服务([你应该使用][3]),那么你的 IP 地址映射到你的 VPN 提供商那里,而 VPN 提供商是可以映射到你的家庭所在地的。无论如何,有可能在某个地方的某个人正在根据你访问的网络和在网站上呆了多长时间来为你建立一个个人的在线资料。然后将这个资料进行出售,并与从其它服务上收集的资料进行聚合,然后利用广告网络进行赚钱。至少,这是乐观主义者对如何利用这些数据的一些看法 —— 我相信你还可以找到更多的更恶意地使用这些数据的例子。 +Tor 项目尝试去提供一个解决这种问题的方案,使它们不可能(或者至少是更加困难)追踪到你的终端 IP 地址。Tor 是通过让你的连接在一个由匿名的入口节点、中继节点和出口节点组成的匿名中继链上反复跳转的方式来实现防止追踪的目的: +1. **入口节点** 只知道你的 IP 地址和中继节点的 IP 地址,但是不知道你最终要访问的目标 IP 地址 +2. **中继节点** 只知道入口节点和出口节点的 IP 地址,以及既不是源也不是最终目标的 IP 地址 +3. **出口节点** 仅知道中继节点和最终目标地址,它是在到达最终目标地址之前解密流量的节点 中继节点在这个交换过程中扮演一个关键的角色,因为它在源请求和目标地址之间创建了一个加密的障碍。甚至在意图偷窥你数据的对手控制了出口节点的情况下,在他们没有完全控制整个 Tor 中继链的情况下仍然无法知道请求源在哪里。 @@ -30,81 +27,68 @@ Tor 项目尝试去提供一个解决这种问题的方案,使它们不可能 #### 考虑去做 Tor 中继时要记住的一些事情 -一个 Tor 中继节点仅发送和接收加密流量 —— 它从不访问任何其它站点或者在线资源,因此你不用担心有人会利用你的家庭 IP 地址去直接浏览一些令人担心的站点。话虽如此,但是如果你居住在一个提供匿名增强服务(anonymity-enhancing services)是违法行为的司法管辖区的话,那么你还是不要运营你的 Tor 中继节点了。你还需要去查看你的因特网服务提供商的服务条款是否允许你去运营一个 Tor 中继。 +一个 Tor 中继节点仅发送和接收加密流量 —— 它从不访问任何其它站点或者在线资源,因此你不用担心有人会利用你的家庭 IP 地址去直接浏览一些令人担心的站点。话虽如此,但是如果你居住在一个提供匿名增强服务anonymity-enhancing services是违法行为的司法管辖区的话,那么你还是不要运营你的 Tor 中继节点了。你还需要去查看你的互联网服务提供商的服务条款是否允许你去运营一个 Tor 中继。 ### 需要哪些东西 * 一个带完整外围附件的树莓派(任何型号/代次都行) - * 一张有 [Raspbian Stretch Lite][4] 的 SD 卡 - * 一根以太网线缆 - * 一根用于供电的 micro-USB 线缆 - * 一个键盘和带 HDMI 接口的显示器(在配置期间使用) - - - 本指南假设你已经配置好了你的家庭网络连接的线缆或者 ADSL 路由器,它用于运行 NAT 转换(它几乎是必需的)。大多数型号的树莓派都有一个可用于为树莓派供电的 USB 端口,如果你只是使用路由器的 WiFi 功能,那么路由器应该有空闲的以太网口。但是在我们将树莓派设置为一个“配置完不管”的 Tor 中继之前,我们还需要一个键盘和显示器。 ### 引导脚本 -我改编了一个很流行的 Tor 中继节点引导脚本以适配树莓派上使用 —— 你可以在我的 GitHub 仓库 上找到它。你用它引导树莓派并使用缺省的用户 “pi” 登入之后,做如下的工作: +我改编了一个很流行的 Tor 中继节点引导脚本以适配树莓派上使用 —— 你可以在我的 GitHub 仓库 上找到它。你用它引导树莓派并使用缺省的用户 `pi` 登入之后,做如下的工作: + ``` sudo apt-get install -y git git clone https://github.com/mricon/tor-relay-bootstrap-rpi cd tor-relay-bootstrap-rpi sudo ./bootstrap.sh - ``` 这个脚本将做如下的工作: 1. 安装最新版本的操作系统更新以确保树莓派打了所有的补丁 - 2. 将系统配置为无人值守自动更新,以确保有可用更新时会自动接收并安装 - 3. 安装 Tor 软件 + 4. 告诉你的 NAT 路由器去转发所需要的端口(端口一般是 443 和 8080,因为这两个端口最不可能被互联网提供商过滤掉)上的数据包到你的中继节点 - 4. 告诉你的 NAT 路由器去转发所需要的端口(端口一般是 443 和 8080,因为这两个端口最不可能被因特网提供商过滤掉)上的数据包到你的中继节点 - - - - -脚本运行完成后,你需要去配置 torrc 文件 —— 但是首先,你需要决定打算贡献给 Tor 流量多大带宽。首先,在 Google 中输入 “[Speed Test][5]”,然后点击 “Run Speed Test” 按钮。你可以不用管 “Download speed” 的结果,因为你的 Tor 中继能处理的速度不会超过最大的上行带宽。 +脚本运行完成后,你需要去配置 `torrc` 文件 —— 但是首先,你需要决定打算贡献给 Tor 流量多大带宽。首先,在 Google 中输入 “[Speed Test][5]”,然后点击 “Run Speed Test” 按钮。你可以不用管 “Download speed” 的结果,因为你的 Tor 中继能处理的速度不会超过最大的上行带宽。 所以,将 “Mbps upload” 的数字除以 8,然后再乘以 1024,结果就是每秒多少 KB 的宽带速度。比如,如果你得到的上行带宽是 21.5 Mbps,那么这个数字应该是: + ``` 21.5 Mbps / 8 * 1024 = 2752 KBytes per second - ``` -你可以限制你的中继带宽为那个数字的一半,并允许突发带宽为那个数字的四分之三。确定好之后,使用喜欢的文本编辑器打开 /etc/tor/torrc 文件,调整好带宽设置。 +你可以限制你的中继带宽为那个数字的一半,并允许突发带宽为那个数字的四分之三。确定好之后,使用喜欢的文本编辑器打开 `/etc/tor/torrc` 文件,调整好带宽设置。 + ``` RelayBandwidthRate 1300 KBytes RelayBandwidthBurst 2400 KBytes - ``` 当然,如果你想更慷慨,你可以将那几个设置的数字调的更大,但是尽量不要设置为最大的出口带宽 —— 如果设置的太高,它会影响你的日常使用。 你打开那个文件之后,你应该去设置更多的东西。首先是昵称 —— 只是为了你自己保存记录,第二个是联系信息,只需要一个电子邮件地址。由于你的中继是运行在无人值守模式下的,你应该使用一个定期检查的电子邮件地址 —— 如果你的中继节点离线超过 48 个小时,你将收到 “Tor Weather” 服务的告警信息。 + ``` Nickname myrpirelay ContactInfo you@example.com - ``` 保存文件并重引导系统去启动 Tor 中继。 ### 测试它确认有 Tor 流量通过 -如果你想去确认中继节点的功能,你可以运行 “arm” 工具: +如果你想去确认中继节点的功能,你可以运行 `arm` 工具: + ``` sudo -u debian-tor arm - ``` 它需要一点时间才显示,尤其是在老板子上。它通常会给你显示一个表示入站和出站流量(或者是错误信息,它将有助于你去排错)的柱状图。 @@ -120,7 +104,7 @@ via: https://www.linux.com/blog/intro-to-linux/2018/6/turn-your-raspberry-pi-tor 作者:[Konstantin Ryabitsev][a] 选题:[lujun9972](https://github.com/lujun9972) 译者:[qhwdw](https://github.com/qhwdw) -校对:[校对者ID](https://github.com/校对者ID) +校对:[wxy](https://github.com/wxy) 本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 diff --git a/published/201807/20180615 4 tools for building embedded Linux systems.md b/published/201807/20180615 4 tools for building embedded Linux systems.md new file mode 100644 index 0000000000..fc8aea80ff --- /dev/null +++ b/published/201807/20180615 4 tools for building embedded Linux systems.md @@ -0,0 +1,184 @@ +4 种用于构建嵌入式 Linux 系统的工具 +====== + +> 了解 Yocto、Buildroot、 OpenWRT,和改造过的桌面发行版以确定哪种方式最适合你的项目。 + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/desk_clock_job_work.jpg?itok=Nj4fuhl6) + + +Linux 被部署到比 Linus Torvalds 在他的宿舍里开发时所预期的更广泛的设备。令人震惊的支持了各种芯片,使得Linux 可以应用于大大小小的设备上:从 [IBM 的巨型机][1]到不如其连接的端口大的[微型设备][2],以及各种大小的设备。它被用于大型企业数据中心、互联网基础设施设备和个人的开发系统。它还为消费类电子产品、移动电话和许多物联网设备提供了动力。 + +在为桌面和企业级设备构建 Linux 软件时,开发者通常在他们的构建机器上使用桌面发行版,如 [Ubuntu][3] 以便尽可能与被部署的机器相似。如 [VirtualBox][4] 和 [Docker][5] 这样的工具使得开发、测试和生产环境更好的保持了一致。 + +### 什么是嵌入式系统? + +维基百科将[嵌入式系统][6]定义为:“在更大的机械或电气系统中具有专用功能的计算机系统,往往伴随着实时计算限制。” + +我觉得可以很简单地说,嵌入式系统是大多数人不认为是计算机的计算机。它的主要作用是作为某种设备,而不被视为通用计算平台。 + +嵌入式系统编程的开发环境通常与测试和生产环境大不相同。它们可能会使用不同的芯片架构、软件堆栈甚至操作系统。开发工作流程对于嵌入式开发人员与桌面和 Web 开发人员来说是非常不同的。通常,其构建后的输出将包含目标设备的整个软件映像,包括内核、设备驱动程序、库和应用程序软件(有时也包括引导加载程序)。 + +在本文中,我将对构建嵌入式 Linux 系统的四种常用方式进行纵览。我将介绍一下每种产品的工作原理,并提供足够的信息来帮助读者确定使用哪种工具进行设计。我不会教你如何使用它们中的任何一个;一旦缩小了选择范围,就有大量深入的在线学习资源。没有任何选择适用于所有情况,我希望提供足够的细节来指导您的决定。 + +### Yocto + +[Yocto][7] 项目 [定义][8]为“一个开源协作项目,提供模板、工具和方法,帮助您为嵌入式产品创建定制的基于 Linux 的系统,而不管硬件架构如何。”它是用于创建定制的 Linux 运行时映像的配方、配置值和依赖关系的集合,可根据您的特定需求进行定制。 + +完全公开:我在嵌入式 Linux 中的大部分工作都集中在 Yocto 项目上,而且我对这个系统的认识和偏见可能很明显。 + +Yocto 使用 [Openembedded][9] 作为其构建系统。从技术上讲,这两个是独立的项目;然而,在实践中,用户不需要了解区别,项目名称经常可以互换使用。 + +Yocto 项目的输出大致由三部分组成: + +  * **目标运行时二进制文件:**这些包括引导加载程序、内核、内核模块、根文件系统映像。以及将 Linux 部署到目标平台所需的任何其他辅助文件。 +  * **包流:**这是可以安装在目标上的软件包集合。您可以根据需要选择软件包格式(例如,deb、rpm、ipk)。其中一些可能预先安装在目标运行时二进制文件中,但可以构建用于安装到已部署系统的软件包。 +  * **目标 SDK:**这些是安装在目标平台上的软件的库和头文件的集合。应用程序开发人员在构建代码时使用它们,以确保它们与适当的库链接 + +#### 优点 + +Yocto 项目在行业中得到广泛应用,并得到许多有影响力的公司的支持。此外,它还拥有一个庞大且充满活力的开发人员[社区][10]和[生态系统][11]。开源爱好者和企业赞助商的结合的方式有助于推动 Yocto 项目。 + +获得 Yocto 的支持有很多选择。如果您想自己动手,有书籍和其他培训材料。如果您想获得专业知识,有许多有 Yocto 经验的工程师。而且许多商业组织可以为您的设计提供基于 Yocto 的 Turnkey 产品或基于服务的实施和定制。 + +Yocto 项目很容易通过 [层][12] 进行扩展,层可以独立发布以添加额外的功能,或针对项目发布时尚不可用的平台,或用于保存系统特有定制功能。层可以添加到你的配置中,以添加未特别包含在市面上版本中的独特功能;例如,“[meta-browser] [13]” 层包含 Web 浏览器的清单,可以轻松为您的系统进行构建。因为它们是独立维护的,所以层可以按不同的时间发布(根据层的开发速度),而不是跟着标准的 Yocto 版本发布。 + +Yocto 可以说是本文讨论的任何方式中最广泛的设备支持。由于许多半导体和电路板制造商的支持,Yocto 很可能能够支持您选择的任何目标平台。主版本 Yocto [分支][14]仅支持少数几块主板(以便达成合理的测试和发布周期),但是,标准工作模式是使用外部主板支持层。 + +最后,Yocto 非常灵活和可定制。您的特定应用程序的自定义可以存储在一个层进行封装和隔离,通常将要素层特有的自定义项存储为层本身的一部分,这可以将相同的设置同时应用于多个系统配置。Yocto 还提供了一个定义良好的层优先和覆盖功能。这使您可以定义层应用和搜索元数据的顺序。它还使您可以覆盖具有更高优先级的层的设置;例如,现有清单的许多自定义功能都将保留。 + +#### 缺点 + +Yocto 项目最大的缺点是学习曲线陡峭。学习该系统并真正理解系统需要花费大量的时间和精力。 根据您的需求,这可能对您的应用程序不重要的技术和能力投入太大。 在这种情况下,与一家商业供应商合作可能是一个不错的选择。 + +Yocto 项目的开发时间和资源相当高。 需要构建的包(包括工具链,内核和所有目标运行时组件)的数量相当不少。 Yocto 开发人员的开发工作站往往是大型系统。 不建议使用小型笔记本电脑。 这可以通过使用许多提供商提供的基于云的构建服务器来缓解。 另外,Yocto 有一个内置的缓存机制,当它确定用于构建特定包的参数没有改变时,它允许它重新使用先前构建的组件。 + +#### 建议 + +为您的下一个嵌入式 Linux 设计使用 Yocto 项目是一个强有力的选择。 在这里介绍的选项中,无论您的目标用例如何,它都是最广泛适用的。 广泛的行业支持,积极的社区和广泛的平台支持使其成为必须设计师的不错选择。 + +### Buildroot + +[Buildroot][15] 项目定义为“通过交叉编译生成嵌入式 Linux 系统的简单、高效且易于使用的工具。”它与 Yocto 项目具有许多相同的目标,但它注重简单性和简约性。一般来说,Buildroot 会禁用所有软件包的所有可选编译时设置(有一些值得注意的例外),从而生成尽可能小的系统。系统设计人员需要启用适用于给定设备的设置。 + +Buildroot 从源代码构建所有组件,但不支持按目标包管理。因此,它有时称为固件生成器,因为镜像在构建时大部分是固定的。应用程序可以更新目标文件系统,但是没有机制将新软件包安装到正在运行的系统中。 + +Buildroot 输出主要由三部分组成: + +  * 将 Linux 部署到目标平台所需的根文件系统映像和任何其他辅助文件 +  * 适用于目标硬件的内核,引导加载程序和内核模块 +  * 用于构建所有目标二进制文件的工具链。 + +#### 优点 + +Buildroot 对简单性的关注意味着,一般来说,它比 Yocto 更容易学习。核心构建系统用 Make 编写,并且足够短以便开发人员了解整个系统,同时可扩展到足以满足嵌入式 Linux 开发人员的需求。 Buildroot 核心通常只处理常见用例,但它可以通过脚本进行扩展。 + +Buildroot 系统使用普通的 Makefile 和 Kconfig 语言来进行配置。 Kconfig 由 Linux 内核社区开发,广泛用于开源项目,使得许多开发人员都熟悉它。 + +由于禁用所有可选的构建时设置的设计目标,Buildroot 通常会使用开箱即用的配置生成尽可能最小的镜像。一般来说,构建时间和构建主机资源的规模将比 Yocto 项目的规模更小。 + +#### 缺点 + +关注简单性和最小化启用的构建方式意味着您可能需要执行大量的自定义来为应用程序配置 Buildroot 构建。此外,所有配置选项都存储在单个文件中,这意味着如果您有多个硬件平台,则需要为每个平台进行每个定制更改。 + +对系统配置文件的任何更改都需要全部重新构建所有软件包。与 Yocto 相比,这个问题通过最小的镜像大小和构建时间得到了一定的解决,但在你调整配置时可能会导致构建时间过长。 + +中间软件包状态缓存默认情况下未启用,并且不像 Yocto 实施那么彻底。这意味着,虽然第一次构建可能比等效的 Yocto 构建短,但后续构建可能需要重建许多组件。 + +#### 建议 + +对于大多数应用程序,使用 Buildroot 进行下一个嵌入式 Linux 设计是一个不错的选择。如果您的设计需要多种硬件类型或其他差异,但由于同步多个配置的复杂性,您可能需要重新考虑,但对于由单一设置组成的系统,Buildroot 可能适合您。 + +### OpenWRT/LEDE + +[OpenWRT][16] 项目开始为消费类路由器开发定制固件。您当地零售商提供的许多低成本路由器都可以运行 Linux 系统,但可能无法开箱即用。这些路由器的制造商可能无法提供频繁的更新来解决新的威胁,即使他们这样做,安装更新镜像的机制也很困难且容易出错。 OpenWRT 项目为许多已被其制造商放弃的设备生成更新的固件镜像,让这些设备焕发新生。 + +OpenWRT 项目的主要交付物是可用于大量商业设备的二进制镜像。它有网络可访问的软件包存储库,允许设备最终用户将新软件添加到他们的系统中。 OpenWRT 构建系统是一个通用构建系统,它允许开发人员创建自定义版本以满足他们自己的需求并添加新软件包,但其主要重点是目标二进制文件。 + +#### 优点 + +如果您正在为商业设备寻找替代固件,则 OpenWRT 应位于您的选项列表中。它的维护良好,可以保护您免受制造商固件无法解决的问题。您也可以添加额外的功能,使您的设备更有用。 + +如果您的嵌入式设计专注于网络,则 OpenWRT 是一个不错的选择。网络应用程序是 OpenWRT 的主要用例,您可能会发现许多可用的软件包。 + +#### 缺点 + +OpenWRT 对您的设计限制很多(与 Yocto 和 Buildroot 相比)。如果这些决定不符合您的设计目标,则可能需要进行大量的修改。 + +在部署的设备中允许基于软件包的更新是很难管理的。按照其定义,这会导致与您的 QA 团队测试的软件负载不同。此外,很难保证大多数软件包管理器的原子安装,以及错误的电源循环可能会使您的设备处于不可预知的状态。 + +#### 建议 + +OpenWRT 是爱好者项目或商用硬件再利用的不错选择。它也是网络应用程序的不错选择。如果您需要从默认设置进行大量定制,您可能更喜欢 Buildroot 或 Yocto。 + +### 桌面发行版 + +设计嵌入式 Linux 系统的一种常见方法是从桌面发行版开始,例如 [Debian][17] 或 [Red Hat][18],并删除不需要的组件,直到安装的镜像符合目标设备的占用空间。这是 [Raspberry Pi][20] 平台流行的 [Raspbian][19]发行版的方法。 + +#### 优点 + +这种方法的主要优点是熟悉。通常,嵌入式 Linux 开发人员也是桌面 Linux 用户,并且精通他们的选择发行版。在目标上使用类似的环境可能会让开发人员更快地入门。根据所选的分布,可以使用 apt 和 yum 等标准封装工具安装许多其他工具。 + +可以将显示器和键盘连接到目标设备,并直接在那里进行所有的开发。对于不熟悉嵌入式空间的开发人员来说,这可能是一个更为熟悉的环境,无需配置和使用棘手的跨开发平台设置。 + +大多数桌面发行版可用的软件包数量通常大于前面讨论的嵌入式特定的构建器可用软件包数量。由于较大的用户群和更广泛的用例,您可能能够找到您的应用程序所需的所有运行时包,这些包已经构建并可供使用。 + +#### 缺点 + +将目标平台作为您的主要开发环境可能会很慢。运行编译器工具是一项资源密集型操作,根据您构建的代码的多少,这可能会严重妨碍您的性能。 + +除了一些例外情况,桌面发行版的设计并不适合低资源系统,并且可能难以充分裁剪目标映像。同样,桌面环境中的预设工作流程对于大多数嵌入式设计来说都不理想。以这种方式获得可再现的环境很困难。手动添加和删除软件包很容易出错。这可以使用特定于发行版的工具进行脚本化,例如基于 Debian 系统的 [debootstrap][21]。为了进一步提高[可再现性][21],您可以使用配置管理工具,如 [CFEngine][22](我的雇主 [Mender.io][23] 完整披露了 +这一工具)。但是,您仍然受发行版提供商的支配,他们将更新软件包以满足他们的需求,而不是您的需求。 + +#### 建议 + +对于您打算推向市场的产品,请谨慎使用此方法。这对于爱好者应用程序来说是一个很好的模型;但是,对于需要支持的产品,这种方法很可能会遇到麻烦。虽然您可能能够获得更快的起步,但从长远来看,您可能会花费您的时间和精力。 + +### 其他考虑 + +这个讨论集中在构建系统的功能上,但通常有非功能性需求可能会影响您的决定。如果您已经选择了片上系统(SoC)或电路板,则您的选择很可能由供应商决定。如果您的供应商为特定系统提供板级支持包(BSP),使用它通常会节省相当多的时间,但请研究 BSP 的质量以避免在开发周期后期发生问题。 + +如果您的预算允许,您可能需要考虑为目标操作系统使用商业供应商。有些公司会为这里讨论的许多选项提供经过验证和支持的配置,除非您拥有嵌入式 Linux 构建系统方面的专业知识,否则这是一个不错的选择,可以让您专注于核心能力。 + +作为替代,您可以考虑为您的开发人员进行商业培训。这可能比商业操作系统供应商便宜,并且可以让你更加自给自足。这是快速找到您选择的构建系统基础知识的学习曲线。 + +最后,您可能已经有一些开发人员拥有一个或多个系统的经验。如果你的工程师有倾向性,当你做出决定时,肯定值得考虑。 + +### 总结 + +构建嵌入式 Linux 系统有多种选择,每种都有优点和缺点。将这部分设计放在优先位置至关重要,因为在以后的过程中切换系统的成本非常高。除了这些选择之外,还有新的系统在开发中。希望这次讨论能够为评估新的系统(以及这里提到的系统)提供一些背景,并帮助您为下一个项目做出坚实的决定。 + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/6/embedded-linux-build-tools + +作者:[Drew Moseley][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[LHRChina](https://github.com/LHRChina) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://opensource.com/users/drewmoseley +[1]:https://en.wikipedia.org/wiki/Linux_on_z_Systems +[2]:http://www.picotux.com/ +[3]:https://www.ubuntu.com/ +[4]:https://www.virtualbox.org/ +[5]:https://www.docker.com/ +[6]:https://en.wikipedia.org/wiki/Embedded_system +[7]:https://yoctoproject.org/ +[8]:https://www.yoctoproject.org/about/ +[9]:https://www.openembedded.org/ +[10]:https://www.yoctoproject.org/community/ +[11]:https://www.yoctoproject.org/ecosystem/participants/ +[12]:https://layers.openembedded.org/layerindex/branch/master/layers/ +[13]:https://layers.openembedded.org/layerindex/branch/master/layer/meta-browser/ +[14]:https://yoctoproject.org/downloads +[15]:https://buildroot.org/ +[16]:https://openwrt.org/ +[17]:https://www.debian.org/ +[18]:https://www.redhat.com/ +[19]:https://www.raspbian.org/ +[20]:https://www.raspberrypi.org/ +[21]:https://wiki.debian.org/Debootstrap +[22]:https://cfengine.com/ +[23]:http://Mender.io diff --git a/published/201807/20180615 BLUI- An easy way to create game UI.md b/published/201807/20180615 BLUI- An easy way to create game UI.md new file mode 100644 index 0000000000..f6514e9578 --- /dev/null +++ b/published/201807/20180615 BLUI- An easy way to create game UI.md @@ -0,0 +1,59 @@ +BLUI:创建游戏 UI 的简单方法 +====== + +> 开源游戏开发插件运行虚幻引擎的用户使用基于 Web 的编程方式创建独特的用户界面元素。 + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/gaming_plugin_blui_screenshot.jpg?itok=91nnYCt_) + +游戏开发引擎在过去几年中变得越来越易于​​使用。像 Unity 这样一直免费使用的引擎,以及最近从基于订阅的服务切换到免费服务的虚幻引擎Unreal Engine,允许独立开发者使用 AAA 发行商相同达到行业标准的工具。虽然这些引擎都不是开源的,但每个引擎都能够促进其周围的开源生态系统的发展。 + +这些引擎中可以包含插件以允许开发人员通过添加特定程序来增强引擎的基本功能。这些程序的范围可以从简单的资源包到更复杂的事物,如人工智能 (AI) 集成。这些插件来自不同的创作者。有些是由引擎开发工作室和有些是个人提供的。后者中的很多是开源插件。 + +### 什么是 BLUI? + +作为独立游戏开发工作室的一员,我体验到了在专有游戏引擎上使用开源插件的好处。Aaron Shea 开发的一个开源插件 [BLUI][1] 对我们团队的开发过程起到了重要作用。它允许我们使用基于 Web 的编程(如 HTML/CSS 和 JavaScript)创建用户界面 (UI) 组件。尽管虚幻引擎Unreal Engine(我们选择的引擎)有一个实现了类似目的的内置 UI 编辑器,我们也选择使用这个开源插件。我们选择使用开源替代品有三个主要原因:它们的可访问性、易于实现以及伴随的开源程序活跃的、支持性好的在线社区。 + +在虚幻引擎的最早版本中,我们在游戏中创建 UI 的唯一方法是通过引擎的原生 UI 集成,使用 Autodesk 的 Scaleform 程序,或通过在虚幻社区中传播的一些选定的基于订阅的虚幻引擎集成。在这些情况下,这些解决方案要么不能为独立开发者提供有竞争力的 UI 解决方案,对于小型团队来说太昂贵,要么只能为大型团队和 AAA 开发者提供。 + +在商业产品和虚幻引擎的原生整合失败后,我们向独立社区寻求解决方案。我们在那里发现了 BLUI。它不仅与虚幻引擎无缝集成,而且还保持了一个强大且活跃的社区,经常推出更新并确保独立开发人员可以轻松访问文档。BLUI 使开发人员能够将 HTML 文件导入虚幻引擎,并在程序内部对其进行编程。这使得通过 web 语言创建的 UI 能够集成到游戏的代码、资源和其他元素中,并拥有所有 HTML、CSS、Javascript 和其他网络语言的能力。它还为开源 [Chromium Embedded Framework][2] 提供全面支持。 + +### 安装和使用 BLUI + +使用 BLUI 的基本过程包括首先通过 HTML 创建 UI。开发人员可以使用任何工具来实现此目的,包括自举bootstrapped JavaScript 代码、外部 API 或任何数据库代码。一旦这个 HTML 页面完成,你可以像安装任何虚幻引擎插件那样安装它,并加载或创建一个项目。项目加载后,你可以将 BLUI 函数放在虚幻引擎 UI 图纸中的任何位置,或者通过 C++ 进行硬编码。开发人员可以通过其 HTML 页面调用函数,或使用 BLUI 的内部函数轻松更改变量。 + +![Integrating BLUI into Unreal Engine 4 blueprints][4] + +*将 BLUI 集成到虚幻 4 图纸中。* + +在我们当前的项目中,我们使用 BLUI 将 UI 元素与游戏中的音轨同步,为游戏机制的节奏方面提供视觉反馈。将定制引擎编程与 BLUI 插件集成很容易。 + +![Using BLUI to sync UI elements with the soundtrack.][6] + +*使用 BLUI 将 UI 元素与音轨同步。* + +通过 BLUI GitHub 页面上的[文档][7],将 BLUI 集成到虚幻 4 中是一个轻松的过程。还有一个由支持虚幻引擎开发人员组成的[论坛][8],他们乐于询问和回答关于插件以及实现该工具时出现的任何问题。 + +### 开源优势 + +开源插件可以在专有游戏引擎的范围内扩展创意。他们继续降低进入游戏开发的障碍,并且可以产生前所未有的游戏内的机制和资源。随着对专有游戏开发引擎的访问持续增长,开源插件社区将变得更加重要。不断增长的创造力必将超过专有软件,开源代码将会填补这些空白,并促进开发真正独特的游戏。而这种新颖性正是让独立游戏如此美好的原因! + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/6/blui-game-development-plugin + +作者:[Uwana lkaiddi][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[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/uwikaiddi +[1]:https://github.com/AaronShea/BLUI +[2]:https://bitbucket.org/chromiumembedded/cef +[3]:/file/400616 +[4]:https://opensource.com/sites/default/files/uploads/blui_gaming_plugin-integratingblui.png (Integrating BLUI into Unreal Engine 4 blueprints) +[5]:/file/400621 +[6]:https://opensource.com/sites/default/files/uploads/blui_gaming_plugin-syncui.png (Using BLUI to sync UI elements with the soundtrack.) +[7]:https://github.com/AaronShea/BLUI/wiki +[8]:https://forums.unrealengine.com/community/released-projects/29036-blui-open-source-html5-js-css-hud-ui diff --git a/published/201807/20180618 5 open source alternatives to Dropbox.md b/published/201807/20180618 5 open source alternatives to Dropbox.md new file mode 100644 index 0000000000..e181b37ca5 --- /dev/null +++ b/published/201807/20180618 5 open source alternatives to Dropbox.md @@ -0,0 +1,122 @@ +可代替 Dropbox 的 5 个开源软件 +===== + +> 寻找一个不会破坏你的安全、自由或银行资产的文件共享应用。 + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/dropbox.jpg?itok=qFwcqboT) + +Dropbox 在文件共享应用中是个 800 磅的大猩猩。尽管它是个极度流行的工具,但你可能仍想使用一个软件去替代它。 + +也行你出于各种好的理由,包括安全和自由,这使你决定用[开源方式][1]。亦或是你已经被数据泄露吓坏了,或者定价计划不能满足你实际需要的存储量。 + +幸运的是,有各种各样的开源文件共享应用,可以提供给你更多的存储容量,更好的安全性,并且以低于 Dropbox 很多的价格来让你掌控你自己的数据。有多低呢?如果你有一定的技术和一台 Linux 服务器可供使用,那尝试一下免费的应用吧。 + +这里有 5 个最好的可以代替 Dropbox 的开源应用,以及其他一些,你可能想考虑使用。 + +### ownCloud + +![](https://opensource.com/sites/default/files/uploads/owncloud.png) + +[ownCloud][2] 发布于 2010 年,是本文所列应用中最老的,但是不要被这件事蒙蔽:它仍然十分流行(根据该公司统计,有超过 150 万用户),并且由由 1100 个参与者的社区积极维护,定期发布更新。 + +它的主要特点——文件共享和文档写作功能和 Dropbox 的功能相似。它们的主要区别(除了它的[开源协议][3])是你的文件可以托管在你的私人 Linux 服务器或云上,给予用户对自己数据完全的控制权。(自托管是本文所列应用的一个普遍的功能。) + +使用 ownCloud,你可以通过 Linux、MacOS 或 Windows 的客户端和安卓、iOS 的移动应用程序来同步和访问文件。你还可以通过带有密码保护的链接分享给其他人来协作或者上传和下载。数据传输通过端到端加密(E2EE)和 SSL 加密来保护安全。你还可以通过使用它的 [市场][4] 中的各种各样的第三方应用来扩展它的功能。当然,它也提供付费的、商业许可的企业版本。 + +ownCloud 提供了详尽的[文档][5],包括安装指南和针对用户、管理员、开发者的手册。你可以从 GitHub 仓库中获取它的[源码][6]。 + +### NextCloud + +![](https://opensource.com/sites/default/files/uploads/nextcloud.png) + +[NextCloud][7] 在 2016 年从 ownCloud 分裂出来,并且具有很多相同的功能。 NextCloud 以它的高安全性和法规遵从性作为它的一个独特的[推崇的卖点][8]。它具有 HIPAA (医疗) 和 GDPR (隐私)法规遵从功能,并提供广泛的数据策略约束、加密、用户管理和审核功能。它还在传输和存储期间对数据进行加密,并且集成了移动设备管理和身份验证机制 (包括 LDAP/AD、单点登录、双因素身份验证等)。 + +像本文列表里的其他应用一样, NextCloud 是自托管的,但是如果你不想在自己的 Linux 上安装 NextCloud 服务器,该公司与几个[提供商][9]达成了伙伴合作,提供安装和托管,并销售服务器、设备和服务支持。在[市场][10]中提供了大量的apps 来扩展它的功能。 + +NextCloud 的[文档][11]为用户、管理员和开发者提供了详细的信息,并且它的论坛、IRC 频道和社交媒体提供了基于社区的支持。如果你想贡献或者获取它的源码、报告一个错误、查看它的 AGPLv3 许可,或者想了解更多,请访问它的[GitHub 项目主页][12]。 + +### Seafile + +![](https://opensource.com/sites/default/files/uploads/seafile.png) + +与 ownCloud 或 NextCloud 相比,[Seafile][13] 或许没有花里胡哨的卖点(app 生态),但是它能完成任务。实质上, 它充当了 Linux 服务器上的虚拟驱动器,以扩展你的桌面存储,并允许你使用密码保护和各种级别的权限(即只读或读写) 有选择地共享文件。 + +它的协作功能包括文件夹权限控制,密码保护的下载链接和像 Git 一样的版本控制和记录。文件使用双因素身份验证、文件加密和 AD/LDAP 集成进行保护,并且可以从 Windows、MacOS、Linux、iOS 或 Android 设备进行访问。 + +更多详细信息, 请访问 Seafile 的 [GitHub 仓库][14]、[服务手册][15]、[wiki][16] 和[论坛][17]。请注意, Seafile 的社区版在 [GPLv2][18] 下获得许可,但其专业版不是开源的。 + +### OnionShare + +![](https://opensource.com/sites/default/files/uploads/onionshare.png) + +[OnionShare][19] 是一个很酷的应用:如果你想匿名,它允许你安全地共享单个文件或文件夹。不需要设置或维护服务器,所有你需要做的就是[下载和安装][20],无论是在 MacOS, Windows 还是 Linux 上。文件始终在你自己的计算机上; 当你共享文件时,OnionShare 创建一个 web 服务器,使其可作为 Tor 洋葱服务访问,并生成一个不可猜测的 .onion URL,这个 URL 允许收件人通过 [Tor 浏览器][21]获取文件。 + +你可以设置文件共享的限制,例如限制可以下载的次数或使用自动停止计时器,这会设置一个严格的过期日期/时间,超过这个期限便不可访问(即使尚未访问该文件)。 + +OnionShare 在 [GPLv3][22] 之下被许可;有关详细信息,请查阅其 [GitHub 仓库][22],其中还包括[文档][23],介绍了这个易用的文件共享软件的特点。 + +### Pydio Cells + +![](https://opensource.com/sites/default/files/uploads/pydiochat.png) + +[Pydio Cells][24] 在 2018 年 5 月推出了稳定版,是对 Pydio 共享应用程序的核心服务器代码的彻底大修。由于 Pydio 的基于 PHP 的后端的限制,开发人员决定用 Go 服务器语言和微服务体系结构重写后端。(前端仍然是基于 PHP 的)。 + +Pydio Cells 包括通常的共享和版本控制功能,以及应用程序中的消息接受、移动应用程序(Android 和 iOS),以及一种社交网络风格的协作方法。安全性包括基于 OpenID 连接的身份验证、rest 加密、安全策略等。企业发行版中包含着高级功能,但在社区(家庭)版本中,对于大多数中小型企业和家庭用户来说,依然是足够的。 + +您可以 在 Linux 和 MacOS 里[下载][25] Pydio Cells。有关详细信息, 请查阅 [文档常见问题][26]、[源码库][27] 和 [AGPLv3 许可证][28] + +### 其他 + +如果以上选择不能满足你的需求,你可能想考虑其他开源的文件共享型应用。 + +* 如果你的主要目的是在设备间同步文件而不是分享文件,考察一下 [Syncthing][29]。 +* 如果你是一个 Git 的粉丝而不需要一个移动应用。你可能更喜欢 [SparkleShare][30]。 +* 如果你主要想要一个地方聚合所有你的个人数据, 看看 [Cozy][31]。 +* 如果你想找一个轻量级的或者专注于文件共享的工具,考察一下 [Scott Nesbitt's review][32]——一个罕为人知的工具。 + +哪个是你最喜欢的开源文件共享应用?在评论中让我们知悉。 + +-------------------------------------------------------------------------------- + +via: https://opensource.com/alternatives/dropbox + +作者:[Opensource.com][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[distant1219](https://github.com/distant1219) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://opensource.com +[1]:https://opensource.com/open-source-way +[2]:https://owncloud.org/ +[3]:https://www.gnu.org/licenses/agpl-3.0.html +[4]:https://marketplace.owncloud.com/ +[5]:https://doc.owncloud.com/ +[6]:https://github.com/owncloud +[7]:https://nextcloud.com/ +[8]:https://nextcloud.com/secure/ +[9]:https://nextcloud.com/providers/ +[10]:https://apps.nextcloud.com/ +[11]:https://nextcloud.com/support/ +[12]:https://github.com/nextcloud +[13]:https://www.seafile.com/en/home/ +[14]:https://github.com/haiwen/seafile +[15]:https://manual.seafile.com/ +[16]:https://seacloud.cc/group/3/wiki/ +[17]:https://forum.seafile.com/ +[18]:https://github.com/haiwen/seafile/blob/master/LICENSE.txt +[19]:https://onionshare.org/ +[20]:https://onionshare.org/#downloads +[21]:https://www.torproject.org/ +[22]:https://github.com/micahflee/onionshare/blob/develop/LICENSE +[23]:https://github.com/micahflee/onionshare/wiki +[24]:https://pydio.com/en +[25]:https://pydio.com/download/ +[26]:https://pydio.com/en/docs/faq +[27]:https://github.com/pydio/cells +[28]:https://github.com/pydio/pydio-core/blob/develop/LICENSE +[29]:https://syncthing.net/ +[30]:http://www.sparkleshare.org/ +[31]:https://cozy.io/en/ +[32]:https://opensource.com/article/17/3/file-sharing-tools diff --git a/published/201807/20180619 Getting started with Open edX to host your course.md b/published/201807/20180619 Getting started with Open edX to host your course.md new file mode 100644 index 0000000000..7324079e8f --- /dev/null +++ b/published/201807/20180619 Getting started with Open edX to host your course.md @@ -0,0 +1,91 @@ +使用 Open edX 托管课程 +====== + +> Open edX 为各种规模和类型的组织提供了一个强大而多功能的开源课程管理的解决方案。要不要了解一下。 + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/rh_003588_01_rd3os.combacktoschoolseriesgen_rh_032x_0.png?itok=cApG9aB4) + +[Open edX 平台][2] 是一个自由开源的课程管理系统,它是 [全世界][3] 都在使用的大规模网络公开课(MOOC)以及小型课程和培训模块的托管平台。在 Open edX 的 [第七个主要发行版][1] 中,到现在为止,它已经提供了超过 8,000 个原创课程和 5000 万个课程注册数。你可以使用你自己的本地设备或者任何行业领先的云基础设施服务提供商来安装这个平台,而且,随着项目的[服务提供商][4]名单越来越长,来自它们中的软件即服务(SaaS)的可用模型也越来越多了。 + +Open edX 平台被来自世界各地的顶尖教育机构、私人公司、公共机构、非政府组织、非营利机构,以及教育技术初创企业广泛地使用,并且该项目的服务提供商全球社区不断地让甚至更小的组织也可以访问这个平台。如果你打算向广大的读者设计和提供教育内容,你应该考虑去使用 Open edX 平台。 + +### 安装 + +安装这个软件有多种方式,这可能有点让你难以选择,至少刚开始是这样。但是不管你是以何种方式 [安装 Open edX][5],最终你都得到的是有相同功能的应用程序。默认安装包含一个为在线学习者提供的、全功能的学习管理系统(LMS),和一个全功能的课程管理工作室(CMS),CMS 可以让你的讲师团队用它来编写原创课程内容。你可以把 CMS 当做是课程内容设计和管理的 “[Wordpress][6]”,把 LMS 当做是课程销售、分发、和消费的 “[Magento][7]”。 + +Open edX 是设备无关的、完全响应式的应用软件,并且不用花费很多的努力就可发布一个原生的 iOS 和 Android 应用,它可以无缝地集成到你的实例后端。Open edX 平台的代码库、原生移动应用、以及安装脚本都发布在 [GitHub][8] 上。 + +#### 有何期望 + +Open edX 平台的 [GitHub 仓库][9] 包含适用于各种类型的组织的、性能很好的、产品级的代码。来自数百个机构的数千名程序员经常为 edX 仓库做贡献,并且这个平台是一个名副其实的、研究如何去构建和管理一个复杂的企业级应用的好案例。因此,尽管你可能会遇到大量的类似“如何将平台迁移到生产环境中”的问题,但是你无需对 Open edX 平台代码库本身的质量和健状性担忧。 + +通过少量的培训,你的讲师就可以去设计不错的在线课程。但是请记住,Open edX 是通过它的 [XBlock][10] 组件架构进行扩展的,因此,通过他们和你的努力,你的讲师将有可能将不错的课程变成精品课程。 + +这个平台在单服务器环境下也运行的很好,并且它是高度模块化的,几乎可以进行无限地水平扩展。它也是主题化的和本地化的,平台的功能和外观可以根据你的需要进行几乎无限制地调整。平台在你的设备上可以按需安装并可靠地运行。 + +#### 需要一些封装 + +请记住,有大量的 edX 软件模块是不包含在默认安装中的,并且这些模块提供的经常都是各种组织所需要的功能。比如,分析模块、电商模块,以及课程的通知/公告模块都是不包含在默认安装中的,并且这些单独的模块都是值得安装的。另外,在数据备份/恢复和系统管理方面要完全依赖你自己去处理。幸运的是,有关这方面的内容,社区有越来越多的文档和如何去做的文章。你可以通过 Google 和 Bing 去搜索,以帮助你在生产环境中安装它们。 + +虽然有很多文档良好的程序,但是根据你的技能水平,配置 [oAuth][11] 和 [SSL/TLS][12],以及使用平台的 [REST API][13] 可能对你是一个挑战。另外,一些组织要求将 MySQL 和/或 MongoDB 数据库在中心化环境中管理,如果你正好是这种情况,你还需要将这些服务从默认平台安装中分离出来。edX 设计团队已经尽可能地为你做了简化,但是由于它是一个非常重大的更改,因此可能需要一些时间去实现。 + +如果你面临资源和/或技术上的困难 —— 不要气馁,Open edX 社区 SaaS 提供商,像 [appsembler][14] 和 [eduNEXT][15],提供了引人入胜的替代方案去进行 DIY 安装,尤其是如果你只想简单购买就行。 + +### 技术栈 + +在 Open edX 平台的安装上探索是件令人兴奋的事情,从架构的角度来说,这个项目是一个典范。应用程序模块是 [Django][16] 应用,它利用了大量的开源社区的顶尖项目,包括 [Ubuntu][17]、[MySQL][18]、[MongoDB][19]、[RabbitMQ][20]、[Elasticsearch][21]、[Hadoop][22]、等等。 + +![edx-architecture.png][24] + +*Open edX 技术栈(CC BY,来自 edX)* + +将这些组件安装并配置好本身就是一件非常不容易的事情,但是以这样的一种方式将所有的组件去打包,并适合于任意规模和复杂性的组织,并且能够按他们的需要进行任意调整搭配而无需在代码上做重大改动,看起来似乎是不可能的事情 —— 它就是这种情况,直到你看到主要的平台配置参数安排和命名是多少的巧妙和直观。请注意,平台的组织结构有一个学习曲线,但是,你所学习的一切都是值的去学习的,不仅是对这个项目,对一般意义上的大型 IT 项目都是如此。 + +提醒一点:这个平台的 UI 是在不断变动的,最终的目标是在 [React][25] 和 [Bootstrap][26] 上实现标准化。与此同时,你将会发现基本主题有多个实现的样式,这可能会让你感到困惑。 + +### 采用 + +edX 项目能够迅速得到世界范围内的采纳,很大程度上取决于该软件的运行情况。这一点也不奇怪,这个项目成功地吸引了大量才华卓越的人参与其中,他们作为程序员、项目顾问、翻译者、技术作者、以及博客作者参与了项目的贡献。一年一次的 [Open edX 会议][27]、[官方的 edX Google Group][28]、以及 [Open edX 服务提供商名单][4] 是了解这个多样化的、不断成长的生态系统的非常好的起点。我作为相对而言的新人,我发现参与和直接从事这个项目的各个方面是非常容易的。 + +祝你学习之旅一切顺利,并且当你构思你的项目时,你可以随时联系我。 + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/6/getting-started-open-edx + +作者:[Lawrence Mc Daniel][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[qhwdw](https://github.com/qhwdw) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://opensource.com/users/mcdaniel0073 +[1]:https://openedx.atlassian.net/wiki/spaces/DOC/pages/11108700/Open+edX+Releases +[2]:https://open.edx.org/about-open-edx +[3]:https://www.edx.org/schools-partners +[4]:https://openedx.atlassian.net/wiki/spaces/COMM/pages/65667081/Open+edX+Service+Providers +[5]:https://openedx.atlassian.net/wiki/spaces/OpenOPS/pages/60227779/Open+edX+Installation+Options +[6]:https://wordpress.com/ +[7]:https://magento.com/ +[8]:https://github.com/edx +[9]:https://github.com/edx/edx-platform +[10]:https://open.edx.org/xblocks +[11]:https://oauth.net/ +[12]:https://en.wikipedia.org/wiki/Transport_Layer_Security +[13]:https://en.wikipedia.org/wiki/Representational_state_transfer +[14]:https://www.appsembler.com/ +[15]:https://www.edunext.co/ +[16]:https://www.djangoproject.com/ +[17]:https://www.ubuntu.com/ +[18]:https://www.mysql.com/ +[19]:https://www.mongodb.com/ +[20]:https://www.rabbitmq.com/ +[21]:https://www.elastic.co/ +[22]:http://hadoop.apache.org/ +[23]:/file/400696 +[24]:https://opensource.com/sites/default/files/uploads/edx-architecture_0.png "edx-architecture.png" +[25]:%E2%80%9Chttps://reactjs.org/%E2%80%9C +[26]:%E2%80%9Chttps://getbootstrap.com/%E2%80%9C +[27]:https://con.openedx.org/ +[28]:https://groups.google.com/forum/#!forum/openedx-ops diff --git a/published/201807/20180619 How To Check Which Groups A User Belongs To On Linux.md b/published/201807/20180619 How To Check Which Groups A User Belongs To On Linux.md new file mode 100644 index 0000000000..97ceab20e2 --- /dev/null +++ b/published/201807/20180619 How To Check Which Groups A User Belongs To On Linux.md @@ -0,0 +1,160 @@ +如何在 Linux 上检查用户所属组 +====== + +将用户添加到现有组是 Linux 管理员的常规活动之一。这是一些在大环境中工作的管理员的日常活动。 + +甚至我会因为业务需求而在我的环境中每天都在进行这样的活动。它是帮助你识别环境中现有组的重要命令之一。 + +此外,这些命令还可以帮助你识别用户所属的组。所有用户都列在 `/etc/passwd` 中,组列在 `/etc/group` 中。 + +无论我们使用什么命令,都将从这些文件中获取信息。此外,每个命令都有其独特的功能,可帮助用户单独获取所需的信息。 + +### 什么是 /etc/passwd? + +`/etc/passwd` 是一个文本文件,其中包含登录 Linux 系统所必需的每个用户信息。它维护有用的用户信息,如用户名、密码、用户 ID、组 ID、用户 ID 信息、家目录和 shell。passwd 每行包含了用户的详细信息,共有如上所述的 7 个字段。 + +``` +$ grep "daygeek" /etc/passwd +daygeek:x:1000:1000:daygeek,,,:/home/daygeek:/bin/bash +``` + +### 什么是 /etc/group? + +`/etc/group` 是一个文本文件,用于定义用户所属的组。我们可以将多个用户添加到单个组中。它允许用户访问其他用户文件和文件夹,因为 Linux 权限分为三类:用户、组和其他。它维护有关组的有用信息,例如组名、组密码,组 ID(GID)和成员列表。每个都在一个单独的行。组文件每行包含了每个组的详细信息,共有 4 个如上所述字段。 + +这可以通过使用以下方法来执行。 + + * `groups`: 显示一个组的所有成员。 + * `id`: 打印指定用户名的用户和组信息。 + * `lid`: 显示用户的组或组的用户。 + * `getent`: 从 Name Service Switch 库中获取条目。 + * `grep`: 代表“全局正则表达式打印global regular expression print”,它能打印匹配的模式。 + +### 什么是 groups 命令? + +`groups` 命令打印每个给定用户名的主要组和任何补充组的名称。 + +``` +$ groups daygeek +daygeek : daygeek adm cdrom sudo dip plugdev lpadmin sambashare +``` + +如果要检查与当前用户关联的组列表。只需运行 `groups` 命令,无需带任何用户名。 + +``` +$ groups +daygeek adm cdrom sudo dip plugdev lpadmin sambashare +``` + +### 什么是 id 命令? + +id 代表 “身份identity”。它打印真实有效的用户和组 ID。打印指定用户或当前用户的用户和组信息。 + +``` +$ id daygeek +uid=1000(daygeek) gid=1000(daygeek) groups=1000(daygeek),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),118(lpadmin),128(sambashare) +``` + +如果要检查与当前用户关联的组列表。只运行 `id` 命令,无需带任何用户名。 + +``` +$ id +uid=1000(daygeek) gid=1000(daygeek) groups=1000(daygeek),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),118(lpadmin),128(sambashare) +``` + +### 什么是 lid 命令? + +它显示用户的组或组的用户。显示有关包含用户名的组或组名称中包含的用户的信息。此命令需要管理员权限。 + +``` +$ sudo lid daygeek + adm(gid=4) + cdrom(gid=24) + sudo(gid=27) + dip(gid=30) + plugdev(gid=46) + lpadmin(gid=108) + daygeek(gid=1000) + sambashare(gid=124) +``` + +### 什么是 getent 命令? + +`getent` 命令显示 Name Service Switch 库支持的数据库中的条目,它们在 `/etc/nsswitch.conf` 中配置。 + +``` +$ getent group | grep daygeek +adm:x:4:syslog,daygeek +cdrom:x:24:daygeek +sudo:x:27:daygeek +dip:x:30:daygeek +plugdev:x:46:daygeek +lpadmin:x:118:daygeek +daygeek:x:1000: +sambashare:x:128:daygeek +``` + +如果你只想打印关联的组名称,请在上面的命令中使用 `awk`。 + +``` +$ getent group | grep daygeek | awk -F: '{print $1}' +adm +cdrom +sudo +dip +plugdev +lpadmin +daygeek +sambashare +``` + +运行以下命令仅打印主群组信息。 + +``` +$ getent group daygeek +daygeek:x:1000: + +``` + +### 什么是 grep 命令? + +`grep` 代表 “全局正则表达式打印global regular expression print”,它能打印文件匹配的模式。 + +``` +$ grep "daygeek" /etc/group +adm:x:4:syslog,daygeek +cdrom:x:24:daygeek +sudo:x:27:daygeek +dip:x:30:daygeek +plugdev:x:46:daygeek +lpadmin:x:118:daygeek +daygeek:x:1000: +sambashare:x:128:daygeek +``` + +如果你只想打印关联的组名称,请在上面的命令中使用 `awk`。 + +``` +$ grep "daygeek" /etc/group | awk -F: '{print $1}' +adm +cdrom +sudo +dip +plugdev +lpadmin +daygeek +sambashare +``` + +-------------------------------------------------------------------------------- + +via: https://www.2daygeek.com/how-to-check-which-groups-a-user-belongs-to-on-linux/ + +作者:[Prakash Subramanian][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[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/prakash/ diff --git a/published/20180620 Stop merging your pull requests manually.md b/published/201807/20180620 Stop merging your pull requests manually.md similarity index 100% rename from published/20180620 Stop merging your pull requests manually.md rename to published/201807/20180620 Stop merging your pull requests manually.md diff --git a/published/201807/20180622 Automatically Change Wallpapers in Linux with Little Simple Wallpaper Changer.md b/published/201807/20180622 Automatically Change Wallpapers in Linux with Little Simple Wallpaper Changer.md new file mode 100644 index 0000000000..69408c1ab1 --- /dev/null +++ b/published/201807/20180622 Automatically Change Wallpapers in Linux with Little Simple Wallpaper Changer.md @@ -0,0 +1,77 @@ +使用 LSWC 在 Linux 中自动更改壁纸 +====== + +> 简介:这是一个小脚本,可以在 Linux 桌面上定期自动更改壁纸。 + +顾名思义,LittleSimpleWallpaperChanger (LSWC)是一个小脚本,可以定期地随机更改壁纸。 + +我知道在“外观”或“更改桌面背景”设置中有一个随机壁纸选项。但那是随机更改预置的壁纸而不是你添加的壁纸。 + +因此,在本文中,我们将看到如何使用 LittleSimpleWallpaperChanger 设置包含照片的随机桌面壁纸。 + +### Little Simple Wallpaper Changer (LSWC) + +[LittleSimpleWallpaperChanger][1] (LSWC) 是一个非常轻量级的脚本,它在后台运行,从用户指定的文件夹中更改壁纸。壁纸以 1 至 5 分钟的随机间隔变化。该软件设置起来相当简单,设置完后,用户就可以不用再操心了。 + +![Little Simple Wallpaper Changer to change wallpapers in Linux][2] + +#### 安装 LSWC + +[点此链接下载 LSWC][3]。压缩文件的大小约为 15KB。 + + * 进入下载位置。 + * 右键单击下载的 .zip 文件,然后选择“在此处解压”。 + * 打开解压后的文件夹,右键单击并选择“在终端中打开”。 + * 在终端中复制粘贴命令 `bash ./README_and_install.sh` 并按回车键。 + * 然后会弹出一个对话框,要求你选择包含壁纸的文件夹。单击它,然后选择你存放壁纸的文件夹。 + * 就是这样。然后重启计算机。 + +![Little Simple Wallpaper Changer for Linux][4] + +#### 使用 LSWC + +安装时,LSWC 会要求你选择包含壁纸的文件夹。因此,我建议你在安装 LSWC 之前创建一个文件夹并将你想要的壁纸全部移动到那。或者你可以使用图片文件夹中的“壁纸”文件夹。**所有壁纸都必须是 .jpg 格式。** + +你可以添加更多壁纸或从所选文件夹中删除当前壁纸。要更改壁纸文件夹位置,你可以从以下文件中编辑壁纸的位置。 + +``` +.config/lswc/homepath.conf +``` + +#### 删除 LSWC + +打开终端并运行以下命令以停止 LSWC: + +``` +pkill lswc +``` + +在文件管理器中打开家目录,然后按 `Ctrl+H` 显示隐藏文件,接着删除以下文件: + + * `.local` 中的 `scripts` 文件夹 + * `.config` 中的 `lswc` 文件夹 + * `.config/autostart` 中的 `lswc.desktop` 文件 + +这就完成了。创建自己的桌面背景幻灯片。LSWC 非常轻巧,易于使用。安装它然后忘记它。 + +LSWC 功能不是很丰富,但这是有意的。它做了它打算做的事情,那就是更换壁纸。如果你想要一个自动下载壁纸的工具试试 [WallpaperDownloader][5]。 + +请在下面的评论栏分享你对这个漂亮的小软件的想法。别忘了分享这篇文章。干杯。 + +-------------------------------------------------------------------------------- + +via: https://itsfoss.com/little-simple-wallpaper-changer/ + +作者:[Aquil Roshan][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[geekpi](https://github.com/geekpi) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://itsfoss.com/author/aquil/ +[1]:https://github.com/LittleSimpleWallpaperChanger/lswc +[2]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/05/Little-simple-wallpaper-changer-2-800x450.jpg +[3]:https://github.com/LittleSimpleWallpaperChanger/lswc/raw/master/Lswc.zip +[4]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/05/Little-simple-wallpaper-changer-1-800x450.jpg +[5]:https://itsfoss.com/wallpaperdownloader-linux/ diff --git a/published/201807/20180625 How To Upgrade Everything Using A Single Command In Linux.md b/published/201807/20180625 How To Upgrade Everything Using A Single Command In Linux.md new file mode 100644 index 0000000000..8ef6fb9ff8 --- /dev/null +++ b/published/201807/20180625 How To Upgrade Everything Using A Single Command In Linux.md @@ -0,0 +1,120 @@ +如何在 Linux 中使用一个命令升级所有软件 +====== + +![](https://www.ostechnix.com/wp-content/uploads/2018/06/topgrade-720x340.png) + +众所周知,让我们的 Linux 系统保持最新状态会用到多种包管理器。比如说,在 Ubuntu 中,你无法使用 `sudo apt update` 和 `sudo apt upgrade` 命令升级所有软件。此命令仅升级使用 APT 包管理器安装的应用程序。你有可能使用 `cargo`、[pip][1]、`npm`、`snap` 、`flatpak` 或 [Linuxbrew][2] 包管理器安装了其他软件。你需要使用相应的包管理器才能使它们全部更新。 + +再也不用这样了!跟 `topgrade` 打个招呼,这是一个可以一次性升级系统中所有软件的工具。 + +你无需运行每个包管理器来更新包。这个 `topgrade` 工具通过检测已安装的软件包、工具、插件并运行相应的软件包管理器来更新 Linux 中的所有软件,用一条命令解决了这个问题。它是自由而开源的,使用 **rust 语言**编写。它支持 GNU/Linux 和 Mac OS X. + +### 在 Linux 中使用一个命令升级所有软件 + +`topgrade` 存在于 AUR 中。因此,你可以在任何基于 Arch 的系统中使用 [Yay][3] 助手程序安装它。 + +``` +$ yay -S topgrade +``` + +在其他 Linux 发行版上,你可以使用 `cargo` 包管理器安装 `topgrade`。要安装 cargo 包管理器,请参阅以下链接: + +- [在 Linux 安装 rust 语言][12] + +然后,运行以下命令来安装 `topgrade`。 + +``` +$ cargo install topgrade +``` + +安装完成后,运行 `topgrade` 以升级 Linux 系统中的所有软件。 + +``` +$ topgrade +``` + +一旦调用了 `topgrade`,它将逐个执行以下任务。如有必要,系统会要求输入 root/sudo 用户密码。 + +1、 运行系统的包管理器: + + * Arch:运行 `yay` 或者回退到 [pacman][4] + * CentOS/RHEL:运行 `yum upgrade` + * Fedora :运行 `dnf upgrade` + * Debian/Ubuntu:运行 `apt update` 和 `apt dist-upgrade` + * Linux/macOS:运行 `brew update` 和 `brew upgrade` + +2、 检查 Git 是否跟踪了以下路径。如果有,则拉取它们: + + * `~/.emacs.d` (无论你使用 Spacemacs 还是自定义配置都应该可用) + * `~/.zshrc` + * `~/.oh-my-zsh` + * `~/.tmux` + * `~/.config/fish/config.fish` + * 自定义路径 + +3、 Unix:运行 `zplug` 更新 + +4、 Unix:使用 TPM 升级 `tmux` 插件 + +5、 运行 `cargo install-update` + +6、 升级 Emacs 包 + +7、 升级 Vim 包。对以下插件框架均可用: + + * NeoBundle + * [Vundle][5] + * Plug + +8、 升级 [npm][6] 全局安装的包 + +9、 升级 Atom 包 + +10、 升级 [Flatpak][7] 包 + +11、 升级 [snap][8] 包 + +12、 Linux:运行 `fwupdmgr` 显示固件升级。 (仅查看​​。实际不会执行升级) + +13、 运行自定义命令。 + +最后,`topgrade` 将运行 `needrestart` 以重新启动所有服务。在 Mac OS X 中,它会升级 App Store 程序。 + +我的 Ubuntu 18.04 LTS 测试环境的示例输出: + +![][10] + +好处是如果一个任务失败,它将自动运行下一个任务并完成所有其他后续任务。最后,它将显示摘要,其中包含运行的任务数量,成功的数量和失败的数量等详细信息。 + +![][11] + +**建议阅读:** + +就个人而言,我喜欢创建一个像 `topgrade` 程序的想法,并使用一个命令升级使用各种包管理器安装的所有软件。我希望你也觉得它有用。还有更多的好东西。敬请关注! + +干杯! + +-------------------------------------------------------------------------------- + +via: https://www.ostechnix.com/how-to-upgrade-everything-using-a-single-command-in-linux/ + +作者:[SK][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[geekpi](https://github.com/geekpi) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.ostechnix.com/author/sk/ +[1]:https://www.ostechnix.com/manage-python-packages-using-pip/ +[2]:https://www.ostechnix.com/linuxbrew-common-package-manager-linux-mac-os-x/ +[3]:https://www.ostechnix.com/yay-found-yet-another-reliable-aur-helper/ +[4]:https://www.ostechnix.com/getting-started-pacman/ +[5]:https://www.ostechnix.com/manage-vim-plugins-using-vundle-linux/ +[6]:https://www.ostechnix.com/manage-nodejs-packages-using-npm/ +[7]:https://www.ostechnix.com/flatpak-new-framework-desktop-applications-linux/ +[8]:https://www.ostechnix.com/install-snap-packages-arch-linux-fedora/ +[9]:data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7 +[10]:http://www.ostechnix.com/wp-content/uploads/2018/06/topgrade-1.png +[11]:http://www.ostechnix.com/wp-content/uploads/2018/06/topgrade-2.png +[12]:https://www.ostechnix.com/install-rust-programming-language-in-linux/ \ No newline at end of file diff --git a/published/201807/20180625 How to install Pipenv on Fedora.md b/published/201807/20180625 How to install Pipenv on Fedora.md new file mode 100644 index 0000000000..3e95f2b089 --- /dev/null +++ b/published/201807/20180625 How to install Pipenv on Fedora.md @@ -0,0 +1,92 @@ +如何在 Fedora 上安装 Pipenv +====== + +![](https://fedoramagazine.org/wp-content/uploads/2018/06/pipenv-install-816x345.jpg) + +Pipenv 的目标是将打包界(bundler、composer、npm、cargo、yarn 等)最好的东西带到 Python 世界来。它试图解决一些问题,并简化整个管理过程。 + +目前,Python 程序依赖项的管理有时似乎是一个挑战。开发人员通常为每个新项目创建一个[虚拟环境][1],并使用 [pip][2] 将依赖项安装到其中。此外,他们必须将已安装的软件包的集合保存到 `requirements.txt` 文件中。我们看到过许多旨在自动化此工作流程的工具和包装程序。但是,仍然需要结合多个程序,并且 `requirements.txt` 格式本身并不适用于更复杂的场景。 + +### 一个统治它们的工具 + +Pipenv 可以正确地管理复杂的相互依赖关系,它还提供已安装包的手动记录。例如,开发、测试和生产环境通常需要一组不同的包。过去,每个项目需要维护多个 `requirements.txt`。Pipenv 使用 [TOML][4] 语法引入了新的 [Pipfile][3] 格式。多亏这种格式,你终于可以在单个文件中维护不同环境的多组需求。 + +在将第一行代码提交到项目中仅一年后,Pipenv 已成为管理 Python 程序依赖关系的官方推荐工具。现在它终于在 Fedora 仓库中提供。 + +### 在 Fedora 上安装 Pipenv + +在全新安装 Fedora 28 及更高版本后,你只需在终端上运行此命令即可安装 Pipenv: + +``` +$ sudo dnf install pipenv +``` + +现在,你的系统已准备好在 Pipenv 的帮助下开始使用新的 Python 3 程序。 + +重要的是,虽然这个工具为程序提供了很好的解决方案,但它并不是为处理库需求而设计的。编写 Python 库时,不需要固定依赖项。你应该在 `setup.py` 文件中指定 `install_requires`。 + +### 基本依赖管理 + +首先为项目创建一个目录: + +``` +$ mkdir new-project && cd new-project +``` + +接下来是为此项目创建虚拟环境: + +``` +$ pipenv --three +``` + +这里的 `-three` 选项将虚拟环境的 Python 版本设置为 Python 3。 + +安装依赖项: + +``` +$ pipenv install requests +Installing requests… +Adding requests to Pipfile's [packages]… +Pipfile.lock not found, creating… +Locking [dev-packages] dependencies… +Locking [packages] dependencies… +``` + +最后生成 lockfile: + +``` +$ pipenv lock +Locking [dev-packages] dependencies… +Locking [packages] dependencies… +Updated Pipfile.lock (b14837) +``` + +你还可以检查依赖关系图: + +``` +$ pipenv graph +- certifi [required: >=2017.4.17, installed: 2018.4.16] +- chardet [required: <3.1.0,>=3.0.2, installed: 3.0.4] +- idna [required: <2.8,>=2.5, installed: 2.7] +- urllib3 [required: >=1.21.1,<1.24, installed: 1.23] +``` + +有关 Pipenv 及其命令的更多详细信息,请参见[文档][5]。 + +-------------------------------------------------------------------------------- + +via: https://fedoramagazine.org/install-pipenv-fedora/ + +作者:[Michal Cyprian][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[geekpi](https://github.com/geekpi) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://fedoramagazine.org/author/mcyprian/ +[1]:https://packaging.python.org/tutorials/installing-packages/#creating-virtual-environments +[2]:https://developer.fedoraproject.org/tech/languages/python/pypi-installation.html +[3]:https://github.com/pypa/pipfile +[4]:https://github.com/toml-lang/toml +[5]:https://docs.pipenv.org/ diff --git a/translated/talk/20180626 5 open source puzzle games for Linux.md b/published/201807/20180626 5 open source puzzle games for Linux.md similarity index 51% rename from translated/talk/20180626 5 open source puzzle games for Linux.md rename to published/201807/20180626 5 open source puzzle games for Linux.md index 4091a52a1f..88b5ccbd79 100644 --- a/translated/talk/20180626 5 open source puzzle games for Linux.md +++ b/published/201807/20180626 5 open source puzzle games for Linux.md @@ -1,67 +1,72 @@ Linux 上的五个开源益智游戏 ====== + +> 用这些有趣好玩的游戏来测试你的战略能力。 ![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/puzzle-pieces.jpg?itok=YHIN4_0L) 游戏一直是 Linux 的弱点之一。由于 Steam、GOG 和其他将商业游戏引入多种操作系统的努力,这种情况近年来有所改变,但这些游戏通常不是开源的。当然,这些游戏可以在开源操作系统上玩,但对于纯粹开源主义者来说还不够好。 -那么,一个只使用开源软件的人,能否找到那些经过足够打磨的游戏,在不损害其开源理念的前提下,提供一种可靠的游戏体验呢?当然可以。虽然开源游戏历来不太可能与一些借由大量预算开发的 AAA 商业游戏相匹敌,但在多种类型的开源游戏中,有很多都很有趣,可以从大多数主要 Linux 发行版的仓库中安装。即使某个特定的游戏没有被打包成特定的发行版本,通常也很容易从项目的网站上下载该游戏以便安装和游戏。 +那么,一个只使用开源软件的人,能否找到那些经过足够打磨的游戏,在不损害其开源理念的前提下,提供一种可靠的游戏体验呢?当然可以。虽然开源游戏历来不太可能与一些借由大量预算开发的 AAA 商业游戏相匹敌,但在多种类型的开源游戏中,有很多都很有趣,可以从大多数主要 Linux 发行版的仓库中安装。即使某个特定的游戏没有被打包成特定的发行版本,通常也很容易从项目的网站上下载该游戏以便安装和游戏。 -这篇文章着眼于益智游戏。我已经写过[街机风格游戏][1]和[棋牌游戏][2]. 在之后的文章中,我计划涉足赛车,角色扮演,战略和模拟经营游戏。 +这篇文章着眼于益智游戏。我已经写过[街机风格游戏][1]和[棋牌游戏][2]。 在之后的文章中,我计划涉足赛车,角色扮演、战略和模拟经营游戏。 + +### Atomix -### Atomix ![](https://opensource.com/sites/default/files/uploads/atomix.png) -[Atomix][3] 是1990年在 Amiga、Commodore 64、MS-DOS 和其他平台发布的 [Atomix][4] 益智游戏的开源克隆。Atomix 的目标是通过连接原子来构建原子分子。单个原子可以向上、向下、向左或向右移动,并一直朝这个方向移动,直到原子撞上一个障碍物——水平墙或另一个原子。这意味着需要进行规划,以确定在水平上构建分子的位置,以及移动单个部件的顺序。第一关是一个简单的水分子,它由两个氢原子和一个氧原子组成,但后来的关卡是更复杂的分子。 +[Atomix][3] 是 1990 年在 Amiga、Commodore 64、MS-DOS 和其他平台发布的 [Atomix][4] 益智游戏的开源克隆。Atomix 的目标是通过连接原子来构建原子分子。单个原子可以向上、向下、向左或向右移动,并一直朝这个方向移动,直到原子撞上一个障碍物——水平墙或另一个原子。这意味着需要进行规划,以确定在水平上构建分子的位置,以及移动单个部件的顺序。第一关是一个简单的水分子,它由两个氢原子和一个氧原子组成,但后来的关卡是更复杂的分子。 要安装 Atomix,请运行以下命令: - * 在 Fedora: `dnf`` install ``atomix` - * 在 Debian/Ubuntu: `apt install` + * 在 Fedora: `dnf install atomix` + * 在 Debian/Ubuntu: `apt install atomix` + +### Fish Fillets - Next Generation -### Fish Fillets - Next Generation ![](https://opensource.com/sites/default/files/uploads/fish_fillets.png) -[Fish Fillets - Next Generation][5] 是游戏Fish fillet的Linux移植版本,它在1998年在Windows发布,源代码在2004年GPL旗下发布。游戏中,两条鱼试图将物体移出道路来通过不同的关卡。这两条鱼有不同的属性,所以玩家需要为每个任务挑选合适的鱼。较大的鱼可以移动较重的物体,但它更大,这意味着它不适合较小的空隙。较小的鱼可以适应那些较小的间隙,但它不能移动较重的物体。如果一个物体从上面掉下来,两条鱼都会被压死,所以玩家在移动棋子时要小心。 +[Fish Fillets - Next Generation][5] 是游戏 Fish fillet 的 Linux 移植版本,它于 1998 年在 Windows 发布,源代码在 2004 年以 GPL 许可证发布。游戏中,两条鱼试图将物体移出道路来通过不同的关卡。这两条鱼有不同的属性,所以玩家需要为每个任务挑选合适的鱼。较大的鱼可以移动较重的物体,但它更大,这意味着它不适合较小的空隙。较小的鱼可以适应那些较小的间隙,但它不能移动较重的物体。如果一个物体从上面掉下来,两条鱼都会被压死,所以玩家在移动棋子时要小心。 要安装 Fish fillet——Next Generation,请运行以下命令: - * 在 Fedora: `dnf`` install fillets-ng` - * 在 Debian/Ubuntu: `apt install fillets-ng` + * 在 Fedora:`dnf install fillets-ng` + * 在 Debian/Ubuntu: `apt install fillets-ng` + +### Frozen Bubble -### Frozen Bubble ![](https://opensource.com/sites/default/files/uploads/frozen-bubble.png) -[Frozen Bubble][6] 是一款街机风格的益智游戏,从屏幕底部向屏幕顶部的一堆泡泡射击。如果三个相同颜色的气泡连接在一起,它们就会被从屏幕上移除。任何连接在被移除的气泡下面但没有连接其他任何东西的气泡也会被移除。在拼图模式下,关卡的设计是固定的,玩家只需要在泡泡掉到屏幕底部的线以下前将泡泡从游戏区域中移除。该游戏街机模式和多人模式遵循相同的基本规则,但也有不同,这增加了多样性。Frozen Bubble是一个标志性的开源游戏,所以如果你以前没有玩过它,玩玩看。 +[Frozen Bubble][6] 是一款街机风格的益智游戏,从屏幕底部向屏幕顶部的一堆泡泡射击。如果三个相同颜色的气泡连接在一起,它们就会被从屏幕上移除。任何连接在被移除的气泡下面但没有连接其他任何东西的气泡也会被移除。在拼图模式下,关卡的设计是固定的,玩家只需要在泡泡掉到屏幕底部的线以下前将泡泡从游戏区域中移除。该游戏街机模式和多人模式遵循相同的基本规则,但也有不同,这增加了多样性。Frozen Bubble 是一个标志性的开源游戏,所以如果你以前没有玩过它,玩玩看。 要安装 Frozen Bubble,请运行以下命令: - * 在 Fedora: `dnf`` install frozen-bubble` + * 在 Fedora: `dnf install frozen-bubble` * 在 Debian/Ubuntu: `apt install frozen-bubble` - ### Hex-a-hop + ![](https://opensource.com/sites/default/files/uploads/hex-a-hop.png) -[Hex-a-hop][7] 是一款基于六角形瓦片的益智游戏,玩家需要将所有的绿色瓦片从水平面上移除。瓦片通过移动被移除。由于瓦片在移动后会消失,所以有必要规划出穿过水平面的最佳路径,以便在不被卡住的情况下移除所有的瓦片。但是,如果玩家使用的是次优路径,会有撤销功能。之后的关卡增加了额外的复杂性,包括需要跨越多个时间的瓦片和使玩家跳过一定数量的六角弹跳瓦片。 +[Hex-a-hop][7] 是一款基于六角形瓦片的益智游戏,玩家需要将所有的绿色瓦片从水平面上移除。瓦片通过移动被移除。由于瓦片在移动后会消失,所以有必要规划出穿过水平面的最佳路径,以便在不被卡住的情况下移除所有的瓦片。但是,如果玩家使用的是次优路径,会有撤销功能。之后的关卡增加了额外的复杂性,包括需要跨越多次的瓦片和使玩家跳过一定数量的六角弹跳瓦片。 要安装 Hex-a-hop,请运行以下命令: - * 在 Fedora: `dnf`` install hex-a-hop` + * 在 Fedora: `dnf install hex-a-hop` * 在 Debian/Ubuntu: `apt install hex-a-hop` - ### Pingus + ![](https://opensource.com/sites/default/files/uploads/pingus.png) -[Pingus][8] 是 [Lemmings][9] 的开源克隆。这不是一个精确的克隆,但游戏非常相似。小动物( Lemmings 里的旅鼠,Pingus 里的企鹅)通过关卡入口进入关卡,开始沿着直线行走。玩家需要使用特殊技能使小动物能够到达关卡的出口而不会被困住或者掉下悬崖。这些技能包括挖掘或建桥。如果有足够数量的小动物进入出口,这个关卡将成功完成,玩家可以进入下一个关卡。Pingus 为标准的 Lemmings 添加了一些额外的特性,包括一个世界地图和一些在原版游戏中没有的技能,但经典 Lemmings 游戏的粉丝们在这个开源版本中仍会感到自在。 +[Pingus][8] 是 [Lemmings][9] 的开源克隆。这不是一个精确的克隆,但游戏非常相似。小动物(Lemmings 里是旅鼠,Pingus 里是企鹅)通过关卡入口进入关卡,开始沿着直线行走。玩家需要使用特殊技能使小动物能够到达关卡的出口而不会被困住或者掉下悬崖。这些技能包括挖掘或建桥。如果有足够数量的小动物进入出口,这个关卡将成功完成,玩家可以进入下一个关卡。Pingus 为标准的 Lemmings 添加了一些额外的特性,包括一个世界地图和一些在原版游戏中没有的技能,但经典 Lemmings 游戏的粉丝们在这个开源版本中仍会感到自在。 要安装 Pingus,请运行以下命令: - * 在 Fedora: `dnf`` install ``pingus` - * 在 Debian/Ubuntu: `apt install ``pingus` + * 在 Fedora: `dnf install pingus` + * 在 Debian/Ubuntu: `apt install pingus` 我漏掉你最喜欢的开源益智游戏了吗? 请在下面的评论中分享。 @@ -73,7 +78,7 @@ via: https://opensource.com/article/18/6/puzzle-games-linux 作者:[Joshua Allen Holm][a] 选题:[lujun9972](https://github.com/lujun9972) 译者:[ZenMoore](https://github.com/ZenMoore) -校对:[校对者ID](https://github.com/校对者ID) +校对:[wxy](https://github.com/wxy) 本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 diff --git a/published/201807/20180626 TrueOS Doesnt Want to Be BSD for Desktop Anymore.md b/published/201807/20180626 TrueOS Doesnt Want to Be BSD for Desktop Anymore.md new file mode 100644 index 0000000000..6df9fe975b --- /dev/null +++ b/published/201807/20180626 TrueOS Doesnt Want to Be BSD for Desktop Anymore.md @@ -0,0 +1,73 @@ +TrueOS 不再想要成为“桌面 BSD”了 +============================================================ + + +[TrueOS][9] 很快会有一些非常重大的变化。今天,我们将了解桌面 BSD 领域将会发生什么。 + +### 通告 + +![TrueOS: Core Operating System BSD](https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/06/true-os-bsd-desktop.jpeg) + +[TrueOS][10] 背后的团队[宣布][11],他们将改变项目的重点。到目前为止,TrueOS 使用开箱即用的图形用户界面来轻松安装 BSD。然而,它现在将成为“一个先进的操作系统,保留你所知道和喜欢的 ZFS([OpenZFS][12])和 [FreeBSD][13]的所有稳定性,并添加额外的功能来创造一个全新的、创新的操作系统。我们的目标是创建一个核心操作系统,该系统具有模块化、实用性,非常适合自己动手和高级用户。“ + +从本质上讲,TrueOs 将成为 FreeBSD 的下游分支。他们将集成更新一些的软件到系统中,例如 [OpenRC][14] 和 [LibreSSL][15]。他们希望能坚持 6 个月的发布周期。 + +其目标是使 TrueOS 成为可以作为其他项目构建的基础。缺少图形部分以使其更加地与发行版无关。 + +### 桌面用户如何? + +如果你读过我的[TrueOS 评论][17]并且有兴趣尝试使用桌面 BSD 或已经使用 TrueOS,请不要担心(这对于生活来说也是一个很好的建议)。TrueOS 的所有桌面元素都将剥离到 [Project Trident][18]。目前,Project Trident 网站的细节不多。他们仿佛还在进行剥离的幕后工作。 + +如果你目前拥有 TrueOS,则无需担心迁移。TrueOS 团队表示,“对于那些希望迁移到其他基于 FreeBSD 的发行版,如 Project Trident 或 [GhostBSD][19] 的人而言将会有迁移方式。” + +### 想法 + +当我第一次阅读该公告时,坦率地说有点担心。改变名字可能是一个坏主意。客户将习惯使用一个名称,但如果产品名称发生变化,他们可能很容易失去对项目的跟踪。TrueOS 经历过名称更改。该项目于 2006 年启动时,它被命名为 PC-BSD,但在 2016 年,名称更改为 TrueOS。它让我想起了[ArchMerge 和 Arcolinux 传奇][21]。 + +话虽这么说,我认为这对 BSD 的桌面用户来说是一件好事。我常听见对 PC-BSD 和 TrueOS 的一个批评是它不是很精致。剥离项目的两个部分将有助于提高相关开发人员的关注度。TrueOS 团队将能够为缓慢进展的 FreeBSD 添加更新的功能,Project Trident 团队将能够改善用户的桌面体验。 + +我希望两个团队都好。请记住,当有人为开源而努力时,即使是我们不会使用的部分,我们也都会受益。 + +你对 TrueOS 和 Project Trident 的未来有何看法?请在下面的评论中告诉我们。 + + +------------------------------ + +关于作者: + +我叫 John Paul Wohlscheid。我是一个有抱负的神秘作家,喜欢玩技术,尤其是 Linux。你可以在[我的个人网站][23]关注我。 + +-------------------------------------------------------------------------------- + +via: https://itsfoss.com/trueos-plan-change/ + +作者:[John Paul Wohlscheid][a] +译者:[geekpi](https://github.com/geekpi) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://itsfoss.com/author/john/ +[1]:https://itsfoss.com/author/john/ +[2]:https://itsfoss.com/trueos-plan-change/#comments +[3]:https://itsfoss.com/category/bsd/ +[4]:https://itsfoss.com/category/news/ +[5]:https://itsfoss.com/tag/bsd/ +[6]:https://itsfoss.com/tag/freebsd/ +[7]:https://itsfoss.com/tag/project-trident/ +[8]:https://itsfoss.com/tag/trueos/ +[9]:https://www.trueos.org/ +[10]:https://www.trueos.org/ +[11]:https://www.trueos.org/blog/trueosdownstream/ +[12]:http://open-zfs.org/wiki/Main_Page +[13]:https://www.freebsd.org/ +[14]:https://en.wikipedia.org/wiki/OpenRC +[15]:http://www.libressl.org/ +[16]:https://itsfoss.com/midnightbsd-founder-lucas-holt/ +[17]:https://itsfoss.com/trueos-bsd-review/ +[18]:http://www.project-trident.org/ +[19]:https://www.ghostbsd.org/ +[20]:https://itsfoss.com/interview-freedos-jim-hall/ +[21]:https://itsfoss.com/archlabs-vs-archmerge/ +[22]:http://reddit.com/r/linuxusersgroup +[23]:http://johnpaulwohlscheid.work/ diff --git a/published/20180627 Historical inventory of collaborative editors.md b/published/201807/20180627 Historical inventory of collaborative editors.md similarity index 100% rename from published/20180627 Historical inventory of collaborative editors.md rename to published/201807/20180627 Historical inventory of collaborative editors.md diff --git a/published/201807/20180627 World Cup football on the command line.md b/published/201807/20180627 World Cup football on the command line.md new file mode 100644 index 0000000000..6cae522741 --- /dev/null +++ b/published/201807/20180627 World Cup football on the command line.md @@ -0,0 +1,79 @@ +命令行中的世界杯 +====== + +![](https://i2.wp.com/www.linuxlinks.com/wp-content/uploads/2018/06/football-wc2018.jpg?resize=700%2C450&ssl=1) + +足球始终在我们身边。即使我们国家的队伍已经出局(LCTT 译注:显然这不是指我们国家,因为我们根本没有入局……),我还是想知道球赛比分。目前, 国际足联世界杯是世界上最大的足球锦标赛,2018 届是由俄罗斯主办的。每届世界杯都有一些足球强国未能取得参赛资格(LCTT 译注:我要吐槽么?)。意大利和荷兰就无缘本次世界杯。但是即使在未参加比赛的国家,追踪关注最新比分也成为了一种仪式。我希望能及时了解这个世界级的重大赛事最新比分的变化,而不用去搜索不同的网站。 + +如果你很喜欢命令行,那么有更好的方法用一个小型命令行程序追踪最新的世界杯比分和排名。让我们看一看最热门的可用的球赛趋势分析程序之一,它叫作 football-cli。 + +football-cli 不是一个开创性的应用程序。这几年,有许多命令行工具可以让你了解到最新的球赛比分和赛事排名。例如,我是 soccer-cli (Python 写的)和 App-football (Perl 写的)的重度用户。但我总是在寻找新的趋势分析应用,而 football-cli 在某些方面脱颖而出。 + +football-cli 是 JavaScript 开发的,由 Manraj Singh 编写,它是开源的软件。基于 MIT 许可证发布,用 npm(JavaScript 包管理器)安装十分简单。那么,让我们直接行动吧! + +该应用程序提供了命令以获取过去及现在的赛事得分、查看联赛和球队之前和将要进行的赛事。它也会显示某一特定联赛的排名。有一条指令可以列出程序所支持的不同赛事。我们不妨从最后一个条指令开始。 + +在 shell 提示符下: + +``` +luke@ganges:~$ football lists +``` + +![球赛列表][3] + +世界杯被列在最下方,我错过了昨天的比赛,所以为了了解比分,我在 shell 提示下输入: + +``` +luke@ganges:~$ football scores +``` + +![football-wc-22][4] + +现在,我想看看目前的世界杯小组排名。很简单: + +``` +luke@ganges:~$ football standings -l WC +``` + +下面是输出的一个片段: + +![football-wc-biaoge][5] + +你们当中眼尖的可能会注意到这里有一个错误。比如比利时看上去领先于 G 组,但这是不正确的,比利时和英格兰(截稿前)在得分上打平。在这种情况下,纪律好的队伍排名更高。英格兰收到两张黄牌,而比利时收到三张,因此,英格兰应当名列榜首。 + +假设我想知道利物浦 90 天前英超联赛的结果,那么: + +``` +luke@ganges:~$ football fixtures -l PL -d 90 -t "Liverpool" +``` + +![足球-利物浦][6] + +我发现这个程序非常方便。它用一种清晰、整洁而有吸引力的方式显示分数和排名。当欧洲联赛再次开始时,它就更有用了。(事实上 2018-19 冠军联赛已经在进行中)! + +这几个示例让大家对 football-cli 的实用性有了更深的体会。想要了解更多,请转至开发者的 [GitHub 页面][7]。足球 + 命令行 = football-cli。 + +如同许多类似的工具一样,该软件从 football-data.org 获取相关数据。这项服务以机器可读的方式为所有欧洲主要联赛提供数据,包括比赛、球队、球员、结果等等。所有这些信息都是以 JOSN 形式通过一个易于使用的 RESTful API 提供的。 + + +-------------------------------------------------------------------------------- + +via: https://www.linuxlinks.com/football-cli-world-cup-football-on-the-command-line/ + +作者:[Luke Baker][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[ZenMoore](https://github.com/ZenMoore) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.linuxlinks.com/author/luke-baker/ +[1]:https://www.linuxlinks.com/wp-content/plugins/jetpack/modules/lazy-images/images/1x1.trans.gif +[2]:https://i0.wp.com/www.linuxlinks.com/wp-content/uploads/2017/12/CLI.png?resize=195%2C171&ssl=1 +[3]:https://i2.wp.com/www.linuxlinks.com/wp-content/uploads/2018/06/football-lists.png?resize=595%2C696&ssl=1 +[4]:https://i2.wp.com/www.linuxlinks.com/wp-content/uploads/2018/06/football-wc-22.png?resize=634%2C75&ssl=1 +[5]:https://i0.wp.com/www.linuxlinks.com/wp-content/uploads/2018/06/football-wc-table.png?resize=750%2C581&ssl=1 +[6]:https://i1.wp.com/www.linuxlinks.com/wp-content/uploads/2018/06/football-Liverpool.png?resize=749%2C131&ssl=1 +[7]:https://github.com/ManrajGrover/football-cli +[8]:https://www.linuxlinks.com/links/Software/ +[9]:https://discord.gg/uN8Rqex diff --git a/published/201807/20180628 Blockchain evolution- A quick guide and why open source is at the heart of it.md b/published/201807/20180628 Blockchain evolution- A quick guide and why open source is at the heart of it.md new file mode 100644 index 0000000000..a91a1d4cda --- /dev/null +++ b/published/201807/20180628 Blockchain evolution- A quick guide and why open source is at the heart of it.md @@ -0,0 +1,100 @@ +区块链进化简史:为什么开源是其核心所在 +====== + +> 从比特币到下一代区块链。 + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/block-quilt-chain.png?itok=mECoDbrc) + +当开源项目开发下一个新版本时,用后缀 “-ng” 表示 “下一代”的情况并不鲜见。幸运的是,到目前为止,快速演进的区块链成功地避开了这个命名陷阱。但是在这个开源生态系统的演进过程中,改变是不断发生的,而好的创意以典型的开源方式在许多不同的项目中被采用、交融和演进。 + +在本文中,我将审视不同代次的区块链,并且看一看在处理这个生态系统遇到的问题时出现什么创意。当然,任何对生态系统进行分类的尝试都有其局限性的 —— 和不同意见者的 —— 但是这也将为混乱的区块链项目提供了一个粗略的指南。 + +### 始作俑者:比特币 + +第一代的区块链起源于 [比特币][1]Bitcoin 区块链,这是以去中心化、点对点加密货币为基础的总帐ledger,它从 [Slashdot][2] 网站上的杂谈变成了一个主流话题。 + +这个区块链是一个分布式总帐,它对所有用户的交易transaction保持跟踪,以避免他们双重支付double-spending(双花)货币(在历史上,这个任务是委托给第三方—— 银行 ——来做的)。为防范攻击者在系统上捣乱,总帐被复制到每个参与到比特币网络的计算机上,并且每次只允许一台计算机去更新总帐。为决定哪台计算机能够获得更新总帐的权力,系统安排在比特币网络上的计算机之间每 10 分钟进行一场竞赛,这将消耗它们的(许多)能源才能参与竞赛。赢家将获得将前 10 分钟发生的交易写入到总帐(区块链中的“区块”)的权力,并且为赢家写入区块链的工作给予一些比特币奖励。这种方式被称为工作量证明proof of work(PoW)共识机制。 + +这就是区块链最有趣的地方。比特币以[开源项目][3]的方式发布于 2009 年 1 月 。在 2010 年,由于意识到这些元素中的许多是可以调整的,围绕比特币聚集起了一个社区 —— [bitcointalk 论坛][4],来开始各种实验。 + +起初,看到的比特币区块链是一个分布式数据库的形式, [Namecoin][5] 项目出现后,建议去保存任意数据到它的事务数据库中。如果区块链能够记录金钱的转移,那么它也应该能够记录其它资产的转移,比如域名。这正是 Namecoin 的主要使用场景,它上线于 2011 年 4 月 —— 也就是比特币出现两年后。 + +Namecoin 调整的地方是区块链的内容,[莱特币][6]Litecoin 调整的是两个技术部分:一是将两个区块的时间间隔从 10 分钟减少到 2.5 分钟,二是改变了竞赛方式(用 [scrypt][7] 来替换了 SHA-256 安全哈希算法)。这是能够做到的,因为比特币是以开源软件的方式来发布的,而莱特币本质上与比特币在其它部分是完全相同的。莱特币是修改了比特币共识机制的第一个分叉,这也为其它的更多“币”铺平了道路。 + +沿着这条道路,基于比特币代码库的各种变种越来越多。其中一些扩展了比特币的用途,比如 [Zerocash][8] 协议,它专注于提供交易的匿名性和可替换性,但它最终分拆为它自己的货币 —— [Zcash][9]。 + +虽然 Zcash 带来了它自己的创新,使用了最近被称为“零知识证明zero-knowledge proof”的加密技术,但它维持着与大多数主要的比特币代码库的兼容性,这意味着它能够从上游的比特币创新中获益。 + +另外的项目 —— [CryptoNote][10],它萌芽于相同的社区,但是并没有使用相同的代码,它以比特币为背景来构建的,但又与之不同。它发布于 2012 年 12 月,由于它的出现,导致了几种加密货币的诞生,最著名的 [门罗币][11]Monero (2014)就是其中之一。门罗币与 Zcash 使用了不同的方法,但解决了相同的问题:隐私性和可替换性。 + +就像在开源世界中经常出现的案例一样,做同样的工作有不止一个的工具可用。 + +### 下一代:“Blockchain-ng” + +但是,到目前为止,所有的这些变体只是改进加密货币或者扩展它们去支持其它类型的事务。因此,这就引出了第二代区块链。 + +一旦社区开始去修改区块链的用法和调整技术部分时,对于一些想去扩展和重新思考它们未来的人来说,这种调整花费不了多长时间的。比特币的长期追随者 —— [Vitalik Buterin][12] 在 2013 年底建议,区域链的事务应该能够表示一个状态机的状态变化,将区域链视为能够运行应用程序(“智能合约smart contract”)的分布式计算机。这个项目 —— [以太坊][13]Ethereum,上线于 2015 年 4 月。它在运行分布式应用程序方面取得了巨大的成功,它的一些非常流行的分布式应用程序([加密猫][14]CryptoKitties)甚至导致以太坊区块链变慢。 + +这证明了目前的区块链存在一个很大的局限性:速度和容量。(速度通常用每秒事务数来测量,简称 TPS)有几个提议都建议去解决这个速度问题,从分片sharding侧链sidechain,以及一个被称为“第二层second-layer”的解决方案。这里需要更多的创新。 + +随着“智能合约”这个词开始流行起来,并且用已经被证实仍然很慢的技术去运行它们,那么就需要实现其它的思路:许可区块链Permissioned blockchain。到目前为止,我们所介绍的所有区块链网络有两个没有明说的特征:一是它们是公开的(任何人都可以看到它们的功能),二是它们不需要许可(任何人都可以加入它们)。这两个部分是运行一个分布式的、非基于第三方的货币应该具有的和必需具有的条件。 + +随着区块链被认为出现与加密货币越来越明显的分离趋势,开始去考虑一些隐私、许可场景是很有意义的。一个有业务关系但不需要彼此完全信任的财团类型的参与者,能够从这些区块链类型中获益 —— 比如,物流链上的参与者,定期进行双边结算或者使用一个清算中心的金融、保险、或医疗保健机构。 + +一旦你将设置从“任何人都可以加入”变为“仅邀请者方可加入”,进一步对区块链构建区块的方式进行改变和调整将变得可能,那么对一些人来说,结果将变得非常有趣。 + +首先,设计用来保护网络不受恶意或者垃圾参与者的影响的工作量证明(PoW)可以被替换为更简单的和更少资源消耗的一些东西,比如,基于 [Raft][15] 的共识协议。在更高级别的安全性和更快的速度之间进行权衡,采用更简单的共识算法。对于更多群体来说这样更理想,因为他们可以用基于加密技术的担保来取代其它的基于法律关系的担保,例如为避免由于竞争而产生的大量能源消耗,而工作量证明就是这种情况。另外一个创新的地方是,使用 [股权证明][16]Proof of Stake(PoS),它是公共网络共识机制的一个重量级的竞争者。它将可能像许可链网络一样找到它自己的实现方式。 + +有几个项目可以让创建许可区块链变得更简单,包括 [Quorum][17] (以太坊的一个分叉)和 [Hyperledger][18] 的 [Fabric][19] 和 [Sawtooth][20],这是基于新代码的两个开源项目。 + +许可区块链可以避免公共的、非许可方式的区块链中某些错综复杂的问题,但是它自己也存在一些问题。正确地管理参与者是其中的一个问题:谁可以加入?如何辨别他们?如何将他们从网络上移除?网络上的一个实体是否去管理一个中央公共密钥基础设施(PKI)? + +### 区块链的开放本质 + +到目前为止的所有案例中,有一件事情是很明确的:使用一个区块链的目标是去提升网络中的参与者和它产生的数据的信任水平,理想情况下,不需要做进一步的工作即可足以使用它。 + +只有为这个网络提供动力的软件是自由和开源的,才能达到这种信任水平。即便是一个正确的、专用的、分布式区块链,它的本质仍然是运行着相同的第三方代码的私有代理的集合。从本质上来说,区块链的源代码必须是开源的,但仅是开源还不够。随着生态系统持续成长,这既是最低限度的担保也是进一步创新的源头。 + +最后,值得一提的是,虽然区块链的开放本质被认为是创新和变化的源头,它也被认为是一种治理形式:代码治理,用户期望运行的任何一个特定版本,都应该包含他们认为的整个网络应该包含的功能和方法。在这方面,需要说明的一点是,一些区块链的开放本质正在“变味”。但是这一问题正在解决。 + +### 第三和第四代:治理 + +接下来,我正在考虑第三代和第四代区块链:区块链将内置治理工具,并且项目将去解决棘手的大量不同区块链之间互连互通的问题,以便于它们之间可以交换信息和价值。 + +--- +关于作者 + +axel simon: 长期的自由及开源软件爱好者,就职于 Red Hat ,关注安全和区块链技术,以及分布式系统和协议。致力于保护互联网及其成就(知识分享、信息访问、去中心化和网络中立)。 + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/6/blockchain-guide-next-generation + +作者:[Axel Simon][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[qhwdw](https://github.com/qhwdw) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://opensource.com/users/axel +[1]:https://bitcoin.org +[2]:https://slashdot.org/ +[3]:https://github.com/bitcoin/bitcoin +[4]:https://bitcointalk.org/ +[5]:https://www.namecoin.org/ +[6]:https://litecoin.org/ +[7]:https://en.wikipedia.org/wiki/Scrypt +[8]:http://zerocash-project.org/index +[9]:https://z.cash +[10]:https://cryptonote.org/ +[11]:https://en.wikipedia.org/wiki/Monero_(cryptocurrency) +[12]:https://en.wikipedia.org/wiki/Vitalik_Buterin +[13]:https://ethereum.org +[14]:http://cryptokitties.co/ +[15]:https://en.wikipedia.org/wiki/Raft_(computer_science) +[16]:https://www.investopedia.com/terms/p/proof-stake-pos.asp +[17]:https://www.jpmorgan.com/global/Quorum +[18]:https://hyperledger.org/ +[19]:https://www.hyperledger.org/projects/fabric +[20]:https://www.hyperledger.org/projects/sawtooth diff --git a/published/201807/20180628 Sosreport - A Tool To Collect System Logs And Diagnostic Information.md b/published/201807/20180628 Sosreport - A Tool To Collect System Logs And Diagnostic Information.md new file mode 100644 index 0000000000..d7c728778e --- /dev/null +++ b/published/201807/20180628 Sosreport - A Tool To Collect System Logs And Diagnostic Information.md @@ -0,0 +1,138 @@ +Sosreport:收集系统日志和诊断信息的工具 +====== + +![](https://www.ostechnix.com/wp-content/uploads/2018/06/sos-720x340.png) + +如果你是 RHEL 管理员,你可能肯定听说过 **Sosreport** :一个可扩展、可移植的支持数据收集工具。它是一个从类 Unix 操作系统中收集系统配置详细信息和诊断信息的工具。当用户提出支持服务单时,他/她必须运行此工具并将由 Sosreport 工具生成的结果报告发送给 Red Hat 支持人员。然后,执行人员将根据报告进行初步分析,并尝试找出系统中的问题。不仅在 RHEL 系统上,你可以在任何类 Unix 操作系统上使用它来收集系统日志和其他调试信息。 + +### 安装 Sosreport + +Sosreport 在 Red Hat 官方系统仓库中,因此你可以使用 Yum 或 DNF 包管理器安装它,如下所示。 + +``` +$ sudo yum install sos +``` + +要么, + +``` +$ sudo dnf install sos +``` + +在 Debian、Ubuntu 和 Linux Mint 上运行: + +``` +$ sudo apt install sosreport +``` + +### 用法 + +安装后,运行以下命令以收集系统配置详细信息和其他诊断信息。 + +``` +$ sudo sosreport +``` + +系统将要求你输入系统的一些详细信息,例如系统名称、案例 ID 等。相应地输入详细信息,然后按回车键生成报告。如果你不想更改任何内容并使用默认值,只需按回车键即可。 + +我的 CentOS 7 服务器的示例输出: + +``` +sosreport (version 3.5) + +This command will collect diagnostic and configuration information from +this CentOS Linux system and installed applications. + +An archive containing the collected information will be generated in +/var/tmp/sos.DiJXi7 and may be provided to a CentOS support +representative. + +Any information provided to CentOS will be treated in accordance with +the published support policies at: + +https://wiki.centos.org/ + +The generated archive may contain data considered sensitive and its +content should be reviewed by the originating organization before being +passed to any third party. + +No changes will be made to system configuration. + +Press ENTER to continue, or CTRL-C to quit. + +Please enter your first initial and last name [server.ostechnix.local]: +Please enter the case id that you are generating this report for []: + +Setting up archive ... +Setting up plugins ... +Running plugins. Please wait ... + +Running 73/73: yum... +Creating compressed archive... + +Your sosreport has been generated and saved in: +/var/tmp/sosreport-server.ostechnix.local-20180628171844.tar.xz + +The checksum is: 8f08f99a1702184ec13a497eff5ce334 + +Please send this file to your support representative. + +``` + +如果你不希望系统提示你输入此类详细信息,请如下使用批处理模式。 + +``` +$ sudo sosreport --batch +``` + +正如你在上面的输出中所看到的,生成了一个归档报告并保存在 `/var/tmp/sos.DiJXi7` 中。在 RHEL 6/CentOS 6 中,报告将在 `/tmp` 中生成。你现在可以将此报告发送给你的支持人员,以便他可以进行初步分析并找出问题所在。 + +你可能会担心或想知道报告中的内容。如果是这样,你可以通过运行以下命令来查看它: + +``` +$ sudo tar -tf /var/tmp/sosreport-server.ostechnix.local-20180628171844.tar.xz +``` + +要么, + +``` +$ sudo vim /var/tmp/sosreport-server.ostechnix.local-20180628171844.tar.xz +``` + +请注意,上述命令不会解压存档,而只显示存档中的文件和文件夹列表。如果要查看存档中文件的实际内容,请首先使用以下命令解压存档: + +``` +$ sudo tar -xf /var/tmp/sosreport-server.ostechnix.local-20180628171844.tar.xz +``` + +存档的所有内容都将解压当前工作目录中 `ssosreport-server.ostechnix.local-20180628171844/` 目录中。进入目录并使用 `cat` 命令或任何其他文本浏览器查看文件内容: + +``` +$ cd sosreport-server.ostechnix.local-20180628171844/ + +$ cat uptime +17:19:02 up 1:03, 2 users, load average: 0.50, 0.17, 0.10 +``` + +有关 Sosreport 的更多详细信息,请参阅手册页。 + +``` +$ man sosreport +``` + +就是这些了。希望这些有用。还有更多好东西。敬请关注! + +干杯! + +-------------------------------------------------------------------------------- + +via: https://www.ostechnix.com/sosreport-a-tool-to-collect-system-logs-and-diagnostic-information/ + +作者:[SK][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[geekpi](https://github.com/geekpi) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.ostechnix.com/author/sk/ diff --git a/published/201807/20180702 My first sysadmin mistake.md b/published/201807/20180702 My first sysadmin mistake.md new file mode 100644 index 0000000000..3d9c64b3f0 --- /dev/null +++ b/published/201807/20180702 My first sysadmin mistake.md @@ -0,0 +1,43 @@ +我的第一个系统管理员错误 +====== + +> 如何在崩溃的局面中集中精力寻找解决方案。 + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/BUSINESS_mistakes.png?itok=dN0OoIl5) + +如果你在 IT 领域工作,你知道事情永远不会像你想象的那样完好。在某些时候,你会遇到错误或出现问题,你最终必须解决问题。这就是系统管理员的工作。 + +作为人类,我们都会犯错误。我们不是已经犯错,就是即将犯错。结果,我们最终还必须解决自己的错误。总是这样。我们都会失误、敲错字母或犯错。 + +作为一名年轻的系统管理员,我艰难地学到了这一课。我犯了一个大错。但是多亏了上级的指导,我学会了不去纠缠于我的错误,而是制定一个“错误策略”来做正确的事情。从错误中吸取教训。克服它,继续前进。 + +我的第一份工作是一家小公司的 Unix 系统管理员。真的,我是一名生嫩的系统管理员,但我大部分时间都独自工作。我们是一个小型 IT 团队,只有我们三个人。我是 20 或 30 台 Unix 工作站和服务器的唯一系统管理员。另外两个支持 Windows 服务器和桌面。 + +任何阅读这篇文章的系统管理员都不会对此感到意外,作为一个不成熟的初级系统管理员,我最终在错误的目录中运行了 `rm` 命令——作为 root 用户。我以为我正在为我们的某个程序删除一些陈旧的缓存文件。相反,我错误地清除了 `/etc` 目录中的所有文件。糟糕。 + +我意识到犯了错误是看到了一条错误消息,“`rm` 无法删除某些子目录”。但缓存目录应该只包含文件!我立即停止了 `rm` 命令,看看我做了什么。然后我惊慌失措。一下子,无数个想法涌入了我的脑中。我刚刚销毁了一台重要的服务器吗?系统会怎么样?我会被解雇吗? + +幸运的是,我运行的是 `rm *` 而不是 `rm -rf *`,因此我只删除了文件。子目录仍在那里。但这并没有让我感觉更好。 + +我立刻去找我的主管告诉她我做了什么。她看到我对自己的错误感到愚蠢,但这是我犯的。尽管紧迫,她花了几分钟时间跟我做了一些指导。她说:“你不是第一个这样做的人,在你这种情况下,别人会怎么做?”这帮助我平静下来并专注。我开始更少考虑我刚刚做的愚蠢事情,而更多地考虑我接下来要做的事情。 + +我做了一个简单的策略:不要重启服务器。使用相同的系统作为模板,并重建 `/etc` 目录。 + +制定了行动计划后,剩下的就很容易了。只需运行正确的命令即可从另一台服务器复制 `/etc` 文件并编辑配置,使其与系统匹配。多亏了我对所有东西都做记录的习惯,我使用已有的文档进行最后的调整。我避免了完全恢复服务器,这意味着一个巨大的宕机事件。 + +可以肯定的是,我从这个错误中吸取了教训。在接下来作为系统管理员的日子中,我总是在运行任何命令之前确认我所在的目录。 + +我还学习了构建“错误策略”的价值。当事情出错时,恐慌并思考接下来可能发生的所有坏事是很自然的。这是人性。但是制定一个“错误策略”可以帮助我不再担心出了什么问题,而是专注于让事情变得更好。我仍然会想一下,但是知道我接下来的步骤可以让我“克服它”。 + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/7/my-first-sysadmin-mistake + +作者:[Jim Hall][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[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/jim-hall diff --git a/published/201807/20180704 Install an NVIDIA GPU on almost any machine.md b/published/201807/20180704 Install an NVIDIA GPU on almost any machine.md new file mode 100644 index 0000000000..4731d0ae8f --- /dev/null +++ b/published/201807/20180704 Install an NVIDIA GPU on almost any machine.md @@ -0,0 +1,147 @@ +如何在绝大部分类型的机器上安装 NVIDIA 显卡驱动 +====== + +![](https://fedoramagazine.org/wp-content/uploads/2018/06/nvidia-816x345.jpg) + +无论是研究还是娱乐,安装一个最新的显卡驱动都能提升你的计算机性能,并且使你能全方位地实现新功能。本安装指南使用 Fedora 28 的新的第三方仓库来安装 NVIDIA 驱动。它将引导您完成硬件和软件两方面的安装,并且涵盖需要让你的 NVIDIA 显卡启动和运行起来的一切知识。这个流程适用于任何支持 UEFI 的计算机和任意新的 NVIDIA 显卡。 + +### 准备 + +本指南依赖于下面这些材料: + + * 一台使用 [UEFI][1] 的计算机,如果你不确定你的电脑是否有这种固件,请运行 `sudo dmidecode -t 0`。如果输出中出现了 “UEFI is supported”,你的安装过程就可以继续了。不然的话,虽然可以在技术上更新某些电脑来支持 UEFI,但是这个过程的要求很苛刻,我们通常不建议你这么使用。 + * 一个现代的、支持 UEFI 的 NVIDIA 的显卡 + * 一个满足你的 NVIDIA 显卡的功率和接线要求的电源(有关详细信息,请参考“硬件和修改”的章节) + * 网络连接 + * Fedora 28 系统 + +### 安装实例 + +这个安装示例使用的是: + + * 一台 Optiplex 9010 的主机(一台相当老的机器) + * [NVIDIA GeForce GTX 1050 Ti XLR8 游戏超频版 4 GB GDDR5 PCI Express 3.0 显卡][2] + * 为了满足新显卡的电源要求,电源升级为 [EVGA – 80 PLUS 600 W ATX 12V/EPS 12V][3],这个最新的电源(PSU)比推荐的最低要求高了 300 W,但在大部分情况下,满足推荐的最低要求就足够了。 + * 然后,当然的,Fedora 28 也别忘了. + +### 硬件和修改 + +#### 电源(PSU) + +打开你的台式机的机箱,检查印刷在电源上的最大输出功率。然后,查看你的 NVIDIA 显卡的文档,确定推荐的最小电源功率要求(以瓦特为单位)。除此之外,检查你的显卡,看它是否需要额外的接线,例如 6 针连接器,大多数的入门级显卡只从主板获取电力,但是有一些显卡需要额外的电力,如果出现以下情况,你需要升级你的电源: + + 1. 你的电源的最大输出功率低于显卡建议的最小电源功率。注意:根据一些显卡厂家的说法,比起推荐的功率,预先构建的系统可能会需要更多或更少的功率,而这取决于系统的配置。如果你使用的是一个特别耗电或者特别节能的配置,请灵活决定你的电源需求。 + 2. 你的电源没有提供必须的接线口来为你的显卡供电。 + +电源的更换很容易,但是在你拆除你当前正在使用的电源之前,请务必注意你的接线布局。除此之外,请确保你选择的电源适合你的机箱。 + +#### CPU + +虽然在大多数老机器上安装高性能的 NVIDIA 显卡是可能的,但是一个缓慢或受损的 CPU 会阻碍显卡性能的发挥,如果要计算在你的机器上瓶颈效果的影响,请点击[这里][4]。了解你的 CPU 性能来避免高性能的显卡和 CPU 无法保持匹配是很重要的。升级你的 CPU 是一个潜在的考虑因素。 + +#### 主板 + +在继续进行之前,请确认你的主板和你选择的显卡是兼容的。你的显卡应该插在最靠近散热器的 PCI-E x16 插槽中。确保你的设置为显卡预留了足够的空间。此外,请注意,现在大部分的显卡使用的都是 PCI-E 3.0 技术。虽然这些显卡如果插在 PCI-E 3.0 插槽上会运行地最好,但如果插在一个旧版的插槽上的话,性能也不会受到太大的影响。 + +### 安装 + +1、 首先,打开终端更新你的包管理器(如果没有更新的话): + +``` +sudo dnf update +``` + +2、 然后,使用这条简单的命令进行重启: + +``` +reboot +``` + +3、 在重启之后,安装 Fedora 28 的工作站的仓库: + +``` +sudo dnf install fedora-workstation-repositories +``` + +4、 接着,设置 NVIDIA 驱动的仓库: + +``` +sudo dnf config-manager --set-enabled rpmfusion-nonfree-nvidia-driver +``` + +5、 然后,再次重启。 + +6、 在这次重启之后,通过下面这条命令验证是否添加了仓库: + +``` +sudo dnf repository-packages rpmfusion-nonfree-nvidia-driver info +``` + +如果加载了多个 NVIDIA 工具和它们各自的 spec 文件,请继续进行下一步。如果没有,你可能在添加新仓库的时候遇到了一个错误。你应该再试一次。 + +7、 登录,连接到互联网,然后打开“软件”应用程序。点击“加载项>硬件驱动> NVIDIA Linux 图形驱动>安装”。 + +如果你使用更老的显卡或者想使用多个显卡,请进一步查看 [RPMFusion 指南][8]。最后,要确保启动成功,设置 `/etc/gdm/custom.conf` 中的 `WaylandEnable=false`,确认避免使用安全启动。 +接着,再一次重启。 + +8、这个过程完成后,关闭所有的应用并**关机**。拔下电源插头,然后按下电源按钮以释放余电,避免你被电击。如果你对电源有开关,关闭它。 + +9、 最后,安装显卡,拔掉老的显卡并将新的显卡插入到正确的 PCI-E x16 插槽中。成功安装新的显卡之后,关闭你的机箱,插入电源 ,然后打开计算机,它应该会成功启动。 + +**注意:** 要禁用此安装中使用的 NVIDIA 驱动仓库,或者要禁用所有的 Fedora 工作站仓库,请参考这个 [Fedora Wiki 页面][6]。 + +### 验证 + +1、 如果你新安装的 NVIDIA 显卡已连接到你的显示器并显示正确,则表明你的 NVIDIA 驱动程序已成功和显卡建立连接。 + +如果你想去查看你的设置,或者验证驱动是否在正常工作(这里,主板上安装了两块显卡),再次打开 “NVIDIA X 服务器设置应用程序”。这次,你应该不会得到错误信息提示,并且系统会给出有关 X 的设置文件和你的 NVIDIA 显卡的信息。(请参考下面的屏幕截图) + +![NVIDIA X Server Settings][7] + +通过这个应用程序,你可以根据你的需要需改 X 配置文件,并可以监控显卡的性能,时钟速度和温度信息。 + +2、 为确保新显卡以满功率运行,显卡性能测试是非常必要的。GL Mark 2,是一个提供后台处理、构建、照明、纹理等等有关信息的标准工具。它提供了一个优秀的解决方案。GL Mark 2 记录了各种各样的图形测试的帧速率,然后输出一个总体的性能评分(这被称为 glmark2 分数)。 + +**注意:** glxgears 只会测试你的屏幕或显示器的性能,不会测试显卡本身,请使用 GL Mark 2。 + +要运行 GLMark2: + + 1. 打开终端并关闭其他所有的应用程序 + 2. 运行 `sudo dnf install glmark2` 命令 + 3. 运行 `glmark2` 命令 + 4. 允许运行完整的测试来得到最好的结果。检查帧速率是否符合你对这块显卡的预期。如果你想要额外的验证,你可以查阅网站来确认是否已有你这块显卡的 glmark2 测试评分被公布到网上,你可以比较这个分数来评估你这块显卡的性能。 + 5. 如果你的帧速率或者 glmark2 评分低于预期,请思考潜在的因素。CPU 造成的瓶颈?其他问题导致? + + +如果诊断的结果很好,就开始享受你的新显卡吧。 + +### 参考链接 + +- [How to benchmark your GPU on Linux][9] +- [How to install a graphics card][10] +- [The Fedora Wiki Page][6] +- [The Bottlenecker][4] +- [What Is Unified Extensible Firmware Interface (UEFI)][1] + +-------------------------------------------------------------------------------- + +via: https://fedoramagazine.org/install-nvidia-gpu/ + +作者:[Justice del Castillo][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[hopefully2333](https://github.com/hopefully2333) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://fedoramagazine.org/author/justice/ +[1]:https://whatis.techtarget.com/definition/Unified-Extensible-Firmware-Interface-UEFI +[2]:https://www.cnet.com/products/pny-geforce-gtx-xlr8-gaming-1050-ti-overclocked-edition-graphics-card-gf-gtx-1050-ti-4-gb/specs/ +[3]:https://www.evga.com/products/product.aspx?pn=100-B1-0600-KR +[4]:http://thebottlenecker.com (Home: The Bottle Necker) +[5]:https://bytebucket.org/kenneym/fedora-28-nvidia-gpu-installation/raw/7bee7dc6effe191f1f54b0589fa818960a8fa18b/nvidia_xserver_error.jpg?token=c6a7effe35f1c592a155a4a46a068a19fd060a91 (NVIDIA X Sever Prompt) +[6]:https://fedoraproject.org/wiki/Workstation/Third_Party_Software_Repositories +[7]:https://bytebucket.org/kenneym/fedora-28-nvidia-gpu-installation/raw/7bee7dc6effe191f1f54b0589fa818960a8fa18b/NVIDIA_XCONFIG.png?token=64e1a7be21e5e9ba157f029b65e24e4eef54d88f (NVIDIA X Server Settings) +[8]:https://rpmfusion.org/Howto/NVIDIA?highlight=%28CategoryHowto%29 +[9]: https://www.howtoforge.com/tutorial/linux-gpu-benchmark/ +[10]: https://www.pcworld.com/article/2913370/components-graphics/how-to-install-a-graphics-card.html \ No newline at end of file diff --git a/published/201807/20180704 What is the Difference Between the macOS and Linux Kernels.md b/published/201807/20180704 What is the Difference Between the macOS and Linux Kernels.md new file mode 100644 index 0000000000..bfade197ad --- /dev/null +++ b/published/201807/20180704 What is the Difference Between the macOS and Linux Kernels.md @@ -0,0 +1,60 @@ +macOS 和 Linux 的内核有什么区别 +====== + +有些人可能会认为 macOS 和 Linux 内核之间存在相似之处,因为它们可以处理类似的命令和类似的软件。有些人甚至认为苹果公司的 macOS 是基于 Linux 的。事实上是,两个内核有着截然不同的历史和特征。今天,我们来看看 macOS 和 Linux 的内核之间的区别。 + +![macOS vs Linux][1] + +### macOS 内核的历史 + +我们将从 macOS 内核的历史开始。1985 年,由于与首席执行官 John Sculley 和董事会不和,史蒂夫·乔布斯Steve Jobs离开了苹果公司。然后,他成立了一家名为 [NeXT][2] 的新电脑公司。乔布斯希望将一款(带有新操作系统的)新计算机快速推向市场。为了节省时间,NeXT 团队使用了卡耐基梅隆大学的 [Mach 内核][3] 和部分 BSD 代码库来创建 [NeXTSTEP 操作系统][4]。 + +NeXT 从来没有取得过财务上的成功,部分归因于乔布斯花钱的习惯,就像他还在苹果公司一样。与此同时,苹果公司曾多次试图更新其操作系统,甚至与 IBM 合作,但从未成功。1997年,苹果公司以 4.29 亿美元收购了 NeXT。作为交易的一部分,史蒂夫·乔布斯回到了苹果公司,同时 NeXTSTEP 成为了 macOS 和 iOS 的基础。 + +### Linux 内核的历史 + +与 macOS 内核不同,Linux 的创建并非源于商业尝试。相反,它是由[芬兰计算机科学专业学生林纳斯·托瓦兹Linus Torvalds于 1991 年创建的][5]。最初,内核是按照林纳斯自己的计算机的规格编写的,因为他想利用其新的 80386 处理器(的特性)。林纳斯[于 1991 年 8 月在 Usenet 上][6]发布了他的新内核代码。很快,他就收到了来自世界各地的代码和功能建议。次年,Orest Zborowski 将 X Window 系统移植到 Linux,使其能够支持图形用户界面。 + +在过去的 27 年中,Linux 已经慢慢成长并增加了不少功能。这不再是一个学生的小型项目。现在它运行在[世界上][7]大多数的[计算设备][8]和[超级计算机][9]上。不错! + +### macOS 内核的特性 + +macOS 内核被官方称为 XNU。这个[首字母缩写词][10]代表“XNU is Not Unix”。根据 [苹果公司的 Github 页面][10],XNU 是“将卡耐基梅隆大学开发的 Mach 内核和 FreeBSD 组件整合而成的混合内核,加上用于编写驱动程序的 C++ API”。代码的 BSD 子系统部分[“在微内核系统中通常实现为用户空间的服务”][11]。Mach 部分负责底层工作,例如多任务、内存保护、虚拟内存管理、内核调试支持和控制台 I/O。 + +### Linux 内核的特性 + +虽然 macOS 内核结合了微内核([Mach][12])和宏内核([BSD][13])的特性,但 Linux 只是一个宏内核。[宏内核][14]负责管理 CPU、内存、进程间通信、设备驱动程序、文件系统和系统服务调用( LCTT 译注:原文为 system server calls,但结合 Linux 内核的构成,译者认为这里翻译成系统服务调用更合适,即 system service calls)。 + +### 用一句话总结 Linux 和 Mac 的区别 + +macOS 内核(XNU)比 Linux 历史更悠久,并且基于两个更古老一些的代码库的结合;另一方面,Linux 新一些,是从头开始编写的,并且在更多设备上使用。 + +如果您发现这篇文章很有趣,请花一点时间在社交媒体,黑客新闻或 [Reddit][15] 上分享。 + +-------------------------------------------------------------------------------- + +via: https://itsfoss.com/mac-linux-difference/ + +作者:[John Paul][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[stephenxs](https://github.com/stephenxs) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://itsfoss.com/author/john/ +[1]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/07/macos-vs-linux-kernels.jpeg +[2]:https://en.wikipedia.org/wiki/NeXT +[3]:https://en.wikipedia.org/wiki/Mach_(kernel) +[4]:https://en.wikipedia.org/wiki/NeXTSTEP +[5]:https://www.cs.cmu.edu/%7Eawb/linux.history.html +[6]:https://groups.google.com/forum/#!original/comp.os.minix/dlNtH7RRrGA/SwRavCzVE7gJ +[7]:https://www.zdnet.com/article/sorry-windows-android-is-now-the-most-popular-end-user-operating-system/ +[8]:https://www.linuxinsider.com/story/31855.html +[9]:https://itsfoss.com/linux-supercomputers-2017/ +[10]:https://github.com/apple/darwin-xnu +[11]:http://osxbook.com/book/bonus/ancient/whatismacosx/arch_xnu.html +[12]:https://en.wikipedia.org/wiki/Mach_(kernel +[13]:https://en.wikipedia.org/wiki/FreeBSD +[14]:https://www.howtogeek.com/howto/31632/what-is-the-linux-kernel-and-what-does-it-do/ +[15]:http://reddit.com/r/linuxusersgroup diff --git a/published/201807/20180705 How to use dd in Linux without destroying your disk.md b/published/201807/20180705 How to use dd in Linux without destroying your disk.md new file mode 100644 index 0000000000..1af60d4593 --- /dev/null +++ b/published/201807/20180705 How to use dd in Linux without destroying your disk.md @@ -0,0 +1,97 @@ +如何在 Linux 系统中使用 dd 命令而不会损毁你的磁盘 +=========== + +> 使用 Linux 中的 dd 工具安全、可靠地制作一个驱动器、分区和文件系统的完整镜像。 + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/computer_happy_sad_developer_programming.png?itok=72nkfSQ_) + +*这篇文章节选自 Manning 出版社出版的图书 [Linux in Action][1]的第 4 章。* + +你是否正在从一个即将损坏的存储驱动器挽救数据,或者要把本地归档进行远程备份,或者要把一个别处的活动分区做个完整的副本,那么你需要懂得如何安全而可靠的复制驱动器和文件系统。幸运的是,`dd` 是一个可以使用的简单而又功能强大的镜像复制命令,从现在到未来很长的时间内,也许直到永远都不会出现比 `dd` 更好的工具了。 + +### 对驱动器和分区做个完整的副本 + +仔细研究后,你会发现你可以使用 `dd` 做各种任务,但是它最重要的功能是处理磁盘分区。当然,你可以使用 `tar` 命令或者 `scp` 命令从一台计算机复制整个文件系统的文件,然后把这些文件原样粘贴在另一台刚刚安装好 Linux 操作系统的计算机中。但是,因为那些文件系统归档不是完整的映像文件,所以在复制文件的过程中需要计算机操作系统的运行作为基础。 + +另一方面,使用 `dd` 可以对任何数字信息完美的进行逐个字节的镜像。但是不论何时何地,当你要对分区进行操作时,我要告诉你早期的 Unix 管理员曾开过这样的玩笑:“ dd 的意思是磁盘毁灭者disk destroyer”(LCTT 译注:`dd` 原意是磁盘复制disk dump)。 在使用 `dd` 命令的时候,如果你输入了哪怕是一个字母,也可能立即永久性的擦除掉整个磁盘驱动器里的所有重要的数据。因此,一定要注意命令的拼写格式规范。 + +**记住:** 在按下回车键执行 `dd` 命令之前,暂时停下来仔细的认真思考一下。 + +### dd 命令的基本操作 + +现在你已经得到了适当的提醒,我们将从简单的事情开始。假设你要对代号为 `/dev/sda` 的整个磁盘数据创建精确的映像,你已经插入了一块空的磁盘驱动器 (理想情况下具有与代号为 `/dev/sda` 的磁盘驱动器相同的容量)。语法很简单: `if=` 定义源驱动器,`of=` 定义你要将数据保存到的文件或位置: + +``` +# dd if=/dev/sda of=/dev/sdb +``` + +接下来的例子将要对 `/dev/sda` 驱动器创建一个 .img 的映像文件,然后把该文件保存的你的用户帐号家目录: + +``` +# dd if=/dev/sda of=/home/username/sdadisk.img +``` + +上面的命令针对整个驱动器创建映像文件,你也可以针对驱动器上的单个分区进行操作。下面的例子针对驱动器的单个分区进行操作,同时使用了一个 `bs` 参数用于设置单次拷贝的字节数量 (此例中是 4096)。设定 `bs` 参数值可能会影响 `dd` 命令的整体操作速度,该参数的理想设置取决于你的硬件配置和其它考虑。 + +``` +# dd if=/dev/sda2 of=/home/username/partition2.img bs=4096 +``` + +数据的恢复非常简单:通过颠倒 `if` 和 `of` 参数可以有效的完成任务。在此例中,`if=` 使用你要恢复的映像,`of=` 使用你想要写入映像的目标驱动器: + +``` +# dd if=sdadisk.img of=/dev/sdb +``` + +你也可以在一条命令中同时完成创建和拷贝任务。下面的例子中将使用 SSH 从远程驱动器创建一个压缩的映像文件,并把该文件保存到你的本地计算机中: + +``` +# ssh username@54.98.132.10 "dd if=/dev/sda | gzip -1 -" | dd of=backup.gz +``` + +你应该经常测试你的归档,确保它们可正常使用。如果它是你创建的启动驱动器,将它粘贴到计算机中,看看它是否能够按预期启动。如果它是普通分区的数据,挂载该分区,确保文件都存在而且可以正常的访问。 + +### 使用 dd 擦除磁盘数据 + +多年以前,我的一个负责政府海外大使馆安全的朋友曾经告诉我,在他当时在任的时候, 政府会给每一个大使馆提供一个官方版的锤子。为什么呢? 一旦大使馆设施可能被不友善的人员侵占,就会使用这个锤子毁坏所有的硬盘. + +为什么要那样做?为什么不是删除数据就好了?你在开玩笑,对吧?所有人都知道从存储设备中删除包含敏感信息的文件实际上并没有真正移除这些数据。除非使用锤子彻底的毁坏这些存储介质,否则,只要有足够的时间和动机, 几乎所有的内容都可以从几乎任何数字存储介质重新获取。 + +但是,你可以使用 `dd` 命令让坏人非常难以获得你的旧数据。这个命令需要花费一些时间在 `/dev/sda1` 分区的每个扇区写入数百万个 `0`(LCTT 译注:是指 0x0 字节,意即 NUL ,而不是数字 0 ): + +``` +# dd if=/dev/zero of=/dev/sda1 +``` + +还有更好的方法。通过使用 `/dev/urandom` 作为源文件,你可以在磁盘上写入随机字符: + +``` +# dd if=/dev/urandom of=/dev/sda1 +``` + +### 监控 dd 的操作 + +由于磁盘或磁盘分区的归档可能需要很长的时间,因此你可能需要在命令中添加进度查看器。安装管道查看器(在 Ubuntu 系统上安装命令为 `sudo apt install pv`),然后把 `pv` 命令和 `dd` 命令结合在一起。使用 `pv`,最终的命令是这样的: + +``` +# dd if=/dev/urandom | pv | dd of=/dev/sda1 + +4,14MB 0:00:05 [ 98kB/s] [ <=> ] +``` + +想要推迟备份和磁盘管理工作?有了 `dd` 工具,你不会有太多的借口。它真的非常简单,但是要小心。祝你好运! + +---------------- + +via:https://opensource.com/article/18/7/how-use-dd-linux + +作者:[David Clinton][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[SunWave](https://github.com/SunWave) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + + +[a]: https://opensource.com/users/remyd +[1]: https://www.manning.com/books/linux-in-action?a_aid=bootstrap-it&a_bid=4ca15fc9&chan=opensource diff --git a/published/201807/20180706 6 RFCs for understanding how the internet works.md b/published/201807/20180706 6 RFCs for understanding how the internet works.md new file mode 100644 index 0000000000..12413c0770 --- /dev/null +++ b/published/201807/20180706 6 RFCs for understanding how the internet works.md @@ -0,0 +1,79 @@ +6 个可以帮你理解互联网工作原理的 RFC +====== + +> 以及 3 个有趣的 RFC。 + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/LAW-Internet_construction_9401467_520x292_0512_dc.png?itok=RPkPPtDe) + +阅读源码是开源软件的重要组成部分。这意味着用户可以查看代码并了解做了什么。 + +但“阅读源码”并不仅适用于代码。理解代码实现的标准同样重要。这些标准编写在由[互联网工程任务组][1]Internet Engineering Task Force(IETF)发布的称为“意见征集Requests for Comment”(RFC)的文档中。多年来已经发布了数以千计的 RFC,因此我们收集了一些我们的贡献者认为必读的内容。 + +### 6 个必读的 RFC + +#### RFC 2119 - 在 RFC 中用于指示需求级别的关键字 + +这是一个快速阅读,但它对了解其它 RFC 非常重要。 [RFC 2119][2] 定义了后续 RFC 中使用的需求级别。 “MAY” 究竟意味着什么?如果标准说 “SHOULD”,你*真的*必须这样做吗?通过为需求提供明确定义的分类,RFC 2119 有助于避免歧义。 + +#### RFC 3339 - 互联网上的日期和时间:时间戳 + +时间是全世界程序员的祸根。 [RFC 3339][3] 定义了如何格式化时间戳。基于 [ISO 8601][4] 标准,3339 为我们提供了一种表达时间的常用方法。例如,像星期几这样的冗余信息不应该包含在存储的时间戳中,因为它很容易计算。 + +#### RFC 1918 - 私有互联网的地址分配 + +有属于每个人的互联网,也有只属于你的互联网。私有网络一直在使用,[RFC 1918][5] 定义了这些网络。当然,你可以在路由器上设置在内部使用公网地址,但这是一个坏主意。或者,你可以将未使用的公共 IP 地址视为内部网络。在任何一种情况下都表明你从未阅读过 RFC 1918。 + +#### RFC 1912 - 常见的 DNS 操作和配置错误 + +一切都是 #@%@ 的 DNS 问题,对吧? [RFC 1912][6] 列出了管理员在试图保持互联网运行时所犯的错误。虽然它是在 1996 年发布的,但 DNS(以及人们犯的错误)并没有真正改变这么多。为了理解我们为什么首先需要 DNS,如今我们再来看看 [RFC 289 - 我们希望正式的主机列表是什么样子的][7] 就知道了。 + +#### RFC 2822 — 互联网邮件格式 + +想想你知道什么是有效的电子邮件地址么?如果你知道有多少个站点不接受我邮件地址中 “+” 的话,你就知道你知道不知道了。 [RFC 2822][8] 定义了有效的电子邮件地址。它还详细介绍了电子邮件的其余部分。 + +#### RFC 7231 - 超文本传输​​协议(HTTP/1.1):语义和内容 + +想想看,几乎我们在网上做的一切都依赖于 HTTP。 [RFC 7231][9] 是该协议的最新更新。它有超过 100 页,定义了方法、请求头和状态代码。 + +### 3 个应该阅读的 RFC + +好吧,并非每个 RFC 都是严肃的。 + +#### RFC 1149 - 在禽类载体上传输 IP 数据报的标准 + +网络以多种不同方式传递数据包。 [RFC 1149][10] 描述了鸽子载体的使用。当我距离州际高速公路一英里以外时,它们的可靠性不会低于我的移动提供商。 + +#### RFC 2324 — 超文本咖啡壶控制协议(HTCPCP/1.0) + +咖啡对于完成工作非常重要,当然,我们需要一个用于管理咖啡壶的程序化界面。 [RFC 2324][11] 定义了一个用于与咖啡壶交互的协议,并添加了 HTTP 418(“我是一个茶壶”)。 + +#### RFC 69 — M.I.T.的分发列表更改 + +[RFC 69][12] 是否是第一个误导取消订阅请求的发布示例? + +你必须阅读的 RFC 是什么(无论它们是否严肃)?在评论中分享你的列表。 + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/7/requests-for-comments-to-know + +作者:[Ben Cotton][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[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/bcotton +[1]:https://www.ietf.org +[2]:https://www.rfc-editor.org/rfc/rfc2119.txt +[3]:https://www.rfc-editor.org/rfc/rfc3339.txt +[4]:https://www.iso.org/iso-8601-date-and-time-format.html +[5]:https://www.rfc-editor.org/rfc/rfc1918.txt +[6]:https://www.rfc-editor.org/rfc/rfc1912.txt +[7]:https://www.rfc-editor.org/rfc/rfc289.txt +[8]:https://www.rfc-editor.org/rfc/rfc2822.txt +[9]:https://www.rfc-editor.org/rfc/rfc7231.txt +[10]:https://www.rfc-editor.org/rfc/rfc1149.txt +[11]:https://www.rfc-editor.org/rfc/rfc2324.txt +[12]:https://www.rfc-editor.org/rfc/rfc69.txt diff --git a/published/201807/20180706 How to Run Windows Apps on Android with Wine.md b/published/201807/20180706 How to Run Windows Apps on Android with Wine.md new file mode 100644 index 0000000000..ca6eeadcfd --- /dev/null +++ b/published/201807/20180706 How to Run Windows Apps on Android with Wine.md @@ -0,0 +1,127 @@ +如何在 Android 上借助 Wine 来运行 Windows Apps +====== + +![](https://www.maketecheasier.com/assets/uploads/2018/07/Wine-Android-featured-image.jpg) + +Wine(一种 Linux 上的程序,不是你喝的葡萄酒)是在类 Unix 操作系统上运行 Windows 程序的一个自由开源的兼容层。创建于 1993 年,借助它你可以在 Linux 和 macOS 操作系统上运行很多 Windows 程序,虽然有时可能还需要做一些小修改。现在,Wine 项目已经发布了 3.0 版本,这个版本兼容 Android 设备。 + +在本文中,我们将向你展示,在你的 Android 设备上如何借助 Wine 来运行 Windows Apps。 + +**相关阅读** : [如何使用 Winepak 在 Linux 上轻松安装 Windows 游戏][1] + +### 在 Wine 上你可以运行什么? + +Wine 只是一个兼容层,而不是一个全功能的仿真器,因此,你需要一个 x86 的 Android 设备才能完全发挥出它的优势。但是,大多数消费者手中的 Android 设备都是基于 ARM 的。 + +因为大多数人使用的是基于 ARM 的 Android 设备,所以有一个限制,只有适配在 Windows RT 上运行的那些 App 才能够使用 Wine 在基于 ARM 的 Android 上运行。但是随着发展,能够在 ARM 设备上运行的 App 数量越来越多。你可以在 XDA 开发者论坛上的这个 [帖子][2] 中找到兼容的这些 App 的清单。 + +在 ARM 上能够运行的一些 App 的例子如下: + + * [Keepass Portable][3]: 一个密码钱包 + * [Paint.NET][4]: 一个图像处理程序 + * [SumatraPDF][5]: 一个 PDF 文档阅读器,也能够阅读一些其它的文档类型 + * [Audacity][6]: 一个数字录音和编辑程序 + +也有一些再度流行的开源游戏,比如,[Doom][7] 和 [Quake 2][8],以及它们的开源克隆,比如 [OpenTTD][9] 和《运输大亨》的一个版本。 + +随着 Wine 在 Android 上越来越普及,能够在基于 ARM 的 Android 设备上的 Wine 中运行的程序越来越多。Wine 项目致力于在 ARM 上使用 QEMU 去仿真 x86 的 CPU 指令,在该项目完成后,能够在 Android 上运行的 App 将会迅速增加。 + +### 安装 Wine + +在安装 Wine 之前,你首先需要去确保你的设备的设置 “允许从 Play 商店之外的其它源下载和安装 APK”。对于本文的用途,你需要去许可你的设备从未知源下载 App。 + +1、 打开你手机上的设置,然后选择安全选项。 + +![wine-android-security][10] + +2、 向下拉并点击 “Unknown Sources” 的开关。 + +![wine-android-unknown-sources][11] + +3、 接受风险警告。 + +![wine-android-unknown-sources-warning][12] + +4、 打开 [Wine 安装站点][13],并点选列表中的第一个选择框。下载将自动开始。 + +![wine-android-download-button][14] + +5、 下载完成后,从下载目录中打开它,或者下拉通知菜单并点击这里的已完成的下载。 + +6、 开始安装程序。它将提示你它需要访问和记录音频,并去修改、删除、和读取你的 SD 卡。你也可为程序中使用的一些 App 授予访问音频的权利。 + +![wine-android-app-access][15] + +7、 安装完成后,点击程序图标去打开它。 + +![wine-android-icon-small][16] + +当你打开 Wine 后,它模仿的是 Windows 7 的桌面。 + +![wine-android-desktop][17] + +Wine 有一个缺点是,你得有一个外接键盘去进行输入。如果你在一个小屏幕上运行它,并且触摸非常小的按钮很困难,你也可以使用一个外接鼠标。 + +你可以通过触摸 “开始” 按钮去打开两个菜单 —— “控制面板”和“运行”。 + +![wine-android-start-button][18] + +### 使用 Wine 来工作 + +当你触摸 “控制面板” 后你将看到三个选项 —— 添加/删除程序、游戏控制器、和 Internet 设定。 + +使用 “运行”,你可以打开一个对话框去运行命令。例如,通过输入 `iexplore` 来启动 “Internet Explorer”。 + +![wine-android-run][19] + +### 在 Wine 中安装程序 + +1、 在你的 Android 设备上下载应用程序(或通过云来同步)。一定要记住下载的程序保存的位置。 + +2、 打开 Wine 命令提示符窗口。 + +3、 输入程序的位置路径。如果你把下载的文件保存在 SD 卡上,输入: + +``` +cd sdcard/Download/[filename.exe] +``` + +4、 在 Android 上运行 Wine 中的文件,只需要简单地输入 EXE 文件的名字即可。 + +如果这个支持 ARM 的文件是兼容的,它将会运行。如果不兼容,你将看到一大堆错误信息。在这种情况下,在 Android 上的 Wine 中安装的 Windows 软件可能会损坏或丢失。 + +这个在 Android 上使用的新版本的 Wine 仍然有许多问题。它并不能在所有的 Android 设备上正常工作。它可以在我的 Galaxy S6 Edge 上运行的很好,但是在我的 Galaxy Tab 4 上却不能运行。许多游戏也不能正常运行,因为图形驱动还不支持 Direct3D。因为触摸屏还不是全扩展的,所以你需要一个外接的键盘和鼠标才能很轻松地操作它。 + +即便是在早期阶段的发布版本中存在这样那样的问题,但是这种技术还是值得深思的。当然了,你要想在你的 Android 智能手机上运行 Windows 程序而不出问题,可能还需要等待一些时日。 + +-------------------------------------------------------------------------------- + +via: https://www.maketecheasier.com/run-windows-apps-android-with-wine/ + +作者:[Tracey Rosenberger][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[qhwdw](https://github.com/qhwdw) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.maketecheasier.com/author/traceyrosenberger/ +[1]:https://www.maketecheasier.com/winepak-install-windows-games-linux/ "How to Easily Install Windows Games on Linux with Winepak" +[2]:https://forum.xda-developers.com/showthread.php?t=2092348 +[3]:http://downloads.sourceforge.net/keepass/KeePass-2.20.1.zip +[4]:http://forum.xda-developers.com/showthread.php?t=2411497 +[5]:http://forum.xda-developers.com/showthread.php?t=2098594 +[6]:http://forum.xda-developers.com/showthread.php?t=2103779 +[7]:http://forum.xda-developers.com/showthread.php?t=2175449 +[8]:http://forum.xda-developers.com/attachment.php?attachmentid=1640830&amp;d=1358070370 +[9]:http://forum.xda-developers.com/showpost.php?p=36674868&amp;postcount=151 +[10]:https://www.maketecheasier.com/assets/uploads/2018/07/Wine-Android-security.png "wine-android-security" +[11]:https://www.maketecheasier.com/assets/uploads/2018/07/Wine-Android-unknown-sources.jpg "wine-android-unknown-sources" +[12]:https://www.maketecheasier.com/assets/uploads/2018/07/Wine-Android-unknown-sources-warning.png "wine-android-unknown-sources-warning" +[13]:https://dl.winehq.org/wine-builds/android/ +[14]:https://www.maketecheasier.com/assets/uploads/2018/07/Wine-Android-download-button.png "wine-android-download-button" +[15]:https://www.maketecheasier.com/assets/uploads/2018/07/Wine-Android-app-access.jpg "wine-android-app-access" +[16]:https://www.maketecheasier.com/assets/uploads/2018/07/Wine-Android-icon-small.jpg "wine-android-icon-small" +[17]:https://www.maketecheasier.com/assets/uploads/2018/07/Wine-Android-desktop.png "wine-android-desktop" +[18]:https://www.maketecheasier.com/assets/uploads/2018/07/Wine-Android-start-button.png "wine-android-start-button" +[19]:https://www.maketecheasier.com/assets/uploads/2018/07/Wine-Android-Run.png "wine-android-run" diff --git a/published/201807/20180708 Getting Started with Debian Packaging.md b/published/201807/20180708 Getting Started with Debian Packaging.md new file mode 100644 index 0000000000..108dd69a97 --- /dev/null +++ b/published/201807/20180708 Getting Started with Debian Packaging.md @@ -0,0 +1,215 @@ +Debian 打包入门 +====== + +> 创建 CardBook 软件包、本地 Debian 仓库,并修复错误。 + +![](http://minkush.me/img/posts/12.jpg) + +我在 GSoC(LCTT 译注:Google Summer Of Code,一项针对学生进行的开源项目训练营,一般在夏季进行。)的任务中有一项是为用户构建 Thunderbird 扩展add-ons。一些非常流行的扩展,比如 [Lightning][1] (日历行事历)已经拥有了 deb 包。 + +另外一个重要的用于管理基于 CardDav 和 vCard 标准的联系人的扩展 [Cardbook][2] ,还没有一个 deb 包。 + +我的导师, [Daniel][3] 鼓励我去为它制作一个包,并上传到 [mentors.debian.net][4]。因为这样就可以使用 `apt-get` 来安装,简化了安装流程。这篇博客描述了我是如何从头开始学习为 CardBook 创建一个 Debian 包的。 + +首先,我是第一次接触打包,我在从源码构建包的基础上进行了大量研究,并检查它的协议是是否与 [DFSG][5] 兼容。 + +我从多个 Debian Wiki 中的指南中进行学习,比如 [打包介绍][6]、 [构建一个包][7],以及一些博客。 + +我还研究了包含在 [Lightning 扩展包][8]的 amd64 文件。 + +我创建的包可以在[这里][9]找到。 + +![Debian Package!][10] + +*Debian 包* + +### 创建一个空的包 + +我从使用 `dh_make` 来创建一个 `debian` 目录开始。 + +``` +# Empty project folder +$ mkdir -p Debian/cardbook +``` + +``` +# create files +$ dh_make\ +> --native \ +> --single \ +> --packagename cardbook_1.0.0 \ +> --email minkush@example.com +``` + +一些重要的文件,比如 `control`、`rules`、`changelog`、`copyright` 等文件被初始化其中。 + +所创建的文件的完整列表如下: + +``` +$ find /debian +debian/ +debian/rules +debian/preinst.ex +debian/cardbook-docs.docs +debian/manpage.1.ex +debian/install +debian/source +debian/source/format +debian/cardbook.debhelper.lo +debian/manpage.xml.ex +debian/README.Debian +debian/postrm.ex +debian/prerm.ex +debian/copyright +debian/changelog +debian/manpage.sgml.ex +debian/cardbook.default.ex +debian/README +debian/cardbook.doc-base.EX +debian/README.source +debian/compat +debian/control +debian/debhelper-build-stamp +debian/menu.ex +debian/postinst.ex +debian/cardbook.substvars +debian/files +``` + +我了解了 Debian 系统中 [Dpkg][11] 包管理器及如何用它安装、删除和管理包。 + +我使用 `dpkg` 命令创建了一个空的包。这个命令创建一个空的包文件以及四个名为 `.changes`、`.deb`、 `.dsc`、 `.tar.gz` 的文件。 + +- `.dsc` 文件包含了所发生的修改和签名 +- `.deb` 文件是用于安装的主要包文件。 +- `.tar.gz` (tarball)包含了源代码 + +这个过程也在 `/usr/share` 目录下创建了 `README` 和 `changelog` 文件。它们包含了关于这个包的基本信息比如描述、作者、版本。 + +我安装这个包,并检查这个包安装的内容。我的新包中包含了版本、架构和描述。 + +``` +$ dpkg -L cardbook +/usr +/usr/share +/usr/share/doc +/usr/share/doc/cardbook +/usr/share/doc/cardbook/README.Debian +/usr/share/doc/cardbook/changelog.gz +/usr/share/doc/cardbook/copyright +``` + +### 包含 CardBook 源代码 + +在成功的创建了一个空包以后,我在包中添加了实际的 CardBook 扩展文件。 CardBook 的源代码托管在 [Gitlab][12] 上。我将所有的源码文件包含在另外一个目录,并告诉打包命令哪些文件需要包含在这个包中。 + +我使用 `vi` 编辑器创建一个 `debian/install` 文件并列举了需要被安装的文件。在这个过程中,我花费了一些时间去学习基于 Linux 终端的文本编辑器,比如 `vi` 。这让我熟悉如何在 `vi` 中编辑、创建文件和快捷方式。 + +当这些完成后,我在变更日志中更新了包的版本并记录了我所做的改变。 + +``` +$ dpkg -l | grep cardbook +ii cardbook 1.1.0 amd64 Thunderbird add-on for address book +``` + +![Changelog][13] + +*更新完包的变更日志* + +在重新构建完成后,重要的依赖和描述信息可以被加入到包中。 Debian 的 `control` 文件可以用来添加额外的必须项目和依赖。 + +### 本地 Debian 仓库 + +在不创建本地存储库的情况下,CardBook 可以使用如下的命令来安装: + +``` +$ sudo dpkg -i cardbook_1.1.0.deb +``` + +为了实际测试包的安装,我决定构建一个本地 Debian 存储库。没有它,`apt-get` 命令将无法定位包,因为它没有在 Debian 的包软件列表中。 + +为了配置本地 Debian 存储库,我复制我的包 (.deb)为放在 `/tmp` 目录中的 `Packages.gz` 文件。 + +![Packages-gz][14] + +*本地 Debian 仓库* + +为了使它工作,我了解了 `apt` 的配置和它查找文件的路径。 + +我研究了一种在 `apt-config` 中添加文件位置的方法。最后,我通过在 APT 中添加 `*.list` 文件来添加包的路径,并使用 `apt-cache` 更新APT缓存来完成我的任务。 + +因此,最新的 CardBook 版本可以成功的通过 `apt-get install cardbook` 来安装了。 + +![Package installation!][15] + +*使用 apt-get 安装 CardBook* + +### 修复打包错误和 Bugs + +我的导师 Daniel 在这个过程中帮了我很多忙,并指导我如何进一步进行打包。他告诉我使用 [Lintian][16] 来修复打包过程中出现的常见错误和最终使用 [dput][17] 来上传 CardBook 包。 + +> Lintian 是一个用于发现策略问题和 Bug 的包检查器。它是 Debian 维护者们在上传包之前广泛使用的自动化检查 Debian 策略的工具。 + +我上传了该软件包的第二个更新版本到 Debian 目录中的 [Salsa 仓库][18] 的一个独立分支中。 + +我从 Debian backports 上安装 Lintian 并学习在一个包上用它来修复错误。我研究了它用在其错误信息中的缩写,和如何查看 Lintian 命令返回的详细内容。 + +``` +$ lintian -i -I --show-overrides cardbook_1.2.0.changes +``` + +最初,在 `.changes` 文件上运行命令时,我惊讶地看到显示出来了大量错误、警告和注释! + +![Package Error Brief!][19] + +*在包上运行 Lintian 时看到的大量报错* + +![Lintian error1!][20] + +*详细的 Lintian 报错* + +![Lintian error2!][23] + +*详细的 Lintian 报错 (2) 以及更多* + +我花了几天时间修复与 Debian 包策略违例相关的一些错误。为了消除一个简单的错误,我必须仔细研究每一项策略和 Debian 的规则。为此,我参考了 [Debian 策略手册][21] 以及 [Debian 开发者参考][22]。 + +我仍然在努力使它变得完美无暇,并希望很快可以将它上传到 mentors.debian.net! + +如果 Debian 社区中使用 Thunderbird 的人可以帮助修复这些报错就太感谢了。 + +-------------------------------------------------------------------------------- + +via: http://minkush.me/cardbook-debian-package/ + +作者:[Minkush Jain][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[Bestony](https://github.com/bestony) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:http://minkush.me/cardbook-debian-package/# +[1]:https://addons.mozilla.org/en-US/thunderbird/addon/lightning/ +[2]:https://addons.mozilla.org/nn-NO/thunderbird/addon/cardbook/?src=hp-dl-featured +[3]:https://danielpocock.com/ +[4]:https://mentors.debian.net/ +[5]:https://wiki.debian.org/DFSGLicenses +[6]:https://wiki.debian.org/Packaging/Intro +[7]:https://wiki.debian.org/BuildingAPackage +[8]:https://packages.debian.org/stretch/amd64/lightning/filelist +[9]:https://salsa.debian.org/minkush-guest/CardBook/tree/debian-package/Debian +[10]:http://minkush.me/img/posts/13.png +[11]:https://packages.debian.org/stretch/dpkg +[12]:https://gitlab.com/CardBook/CardBook +[13]:http://minkush.me/img/posts/15.png +[14]:http://minkush.me/img/posts/14.png +[15]:http://minkush.me/img/posts/11.png +[16]:https://packages.debian.org/stretch/lintian +[17]:https://packages.debian.org/stretch/dput +[18]:https://salsa.debian.org/minkush-guest/CardBook/tree/debian-package +[19]:http://minkush.me/img/posts/16.png (Running Lintian on package) +[20]:http://minkush.me/img/posts/10.png +[21]:https://www.debian.org/doc/debian-policy/ +[22]:https://www.debian.org/doc/manuals/developers-reference/ +[23]:http://minkush.me/img/posts/17.png \ No newline at end of file diff --git a/published/201807/20180709 Boost your typing with emoji in Fedora 28 Workstation.md b/published/201807/20180709 Boost your typing with emoji in Fedora 28 Workstation.md new file mode 100644 index 0000000000..0419275816 --- /dev/null +++ b/published/201807/20180709 Boost your typing with emoji in Fedora 28 Workstation.md @@ -0,0 +1,67 @@ +在 Fedora 28 Workstation 使用 emoji 加速输入 +====== + +![](https://fedoramagazine.org/wp-content/uploads/2018/07/emoji-typing-816x345.jpg) + +Fedora 28 Workstation 添加了一个功能允许你使用键盘快速搜索、选择和输入 emoji。emoji,这种可爱的表意文字是 Unicode 的一部分,在消息传递中使用得相当广泛,特别是在移动设备上。你可能听过这样的成语:“一图胜千言”。这正是 emoji 所提供的:简单的图像供你在交流中使用。Unicode 的每个版本都增加了更多 emoji,在最近的 Unicode 版本中添加了 200 多个 emoji。本文向你展示如何使它们在你的 Fedora 系统中易于使用。 + +很高兴看到 emoji 的数量在增长。但与此同时,它带来了如何在计算设备中输入它们的挑战。许多人已经将这些符号用于移动设备或社交网站中的输入。 + +[**编者注:**本文是对此主题以前发表过的文章的更新]。 + +### 在 Fedora 28 Workstation 上启用 emoji 输入 + +新的 emoji 输入法默认出现在 Fedora 28 Workstation 中。要使用它,必须使用“区域和语言设置”对话框启用它。从 Fedora Workstation 设置打开“区域和语言”对话框,或在“概要”中搜索它。 + +[![Region & Language settings tool][1]][2] + +选择 `+` 控件添加输入源。出现以下对话框: + +[![Adding an input source][3]][4] + +选择最后选项(三个点)来完全展开选择。然后,在列表底部找到“Other”并选择它: + +[![Selecting other input sources][5]][6] + +在下面的对话框中,找到 “Typing Booster” 选项并选择它: + +[![][7]][8] + +这个高级输入法由 iBus 在背后支持。该高级输入法可通过列表右侧的齿轮图标在列表中识别。 + +输入法下拉菜单自动出现在 GNOME Shell 顶部栏中。确认你的默认输入法 —— 在此示例中为英语(美国) - 被选为当前输入法,你就可以输入了。 + +[![Input method dropdown in Shell top bar][9]][10] + +### 使用新的表情符号输入法 + +现在 emoji 输入法启用了,按键盘快捷键 `Ctrl+Shift+E` 搜索 emoji。将出现一个弹出对话框,你可以在其中输入搜索词,例如 “smile” 来查找匹配的符号。 + +[![Searching for smile emoji][11]][12] + +使用箭头键翻页列表。然后按回车进行选择,字形将替换输入内容。 + +-------------------------------------------------------------------------------- + +via: https://fedoramagazine.org/boost-typing-emoji-fedora-28-workstation/ + +作者:[Paul W. Frields][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[geekpi](https://github.com/geekpi) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://fedoramagazine.org/author/pfrields/ +[1]:https://fedoramagazine.org/wp-content/uploads/2018/07/Screenshot-from-2018-07-08-15-02-41-1024x718.png +[2]:https://fedoramagazine.org/wp-content/uploads/2018/07/Screenshot-from-2018-07-08-15-02-41.png +[3]:https://fedoramagazine.org/wp-content/uploads/2018/07/Screenshot-from-2018-07-08-14-33-46-1024x839.png +[4]:https://fedoramagazine.org/wp-content/uploads/2018/07/Screenshot-from-2018-07-08-14-33-46.png +[5]:https://fedoramagazine.org/wp-content/uploads/2018/07/Screenshot-from-2018-07-08-14-34-15-1024x839.png +[6]:https://fedoramagazine.org/wp-content/uploads/2018/07/Screenshot-from-2018-07-08-14-34-15.png +[7]:https://fedoramagazine.org/wp-content/uploads/2018/07/Screenshot-from-2018-07-08-14-34-41-1024x839.png +[8]:https://fedoramagazine.org/wp-content/uploads/2018/07/Screenshot-from-2018-07-08-14-34-41.png +[9]:https://fedoramagazine.org/wp-content/uploads/2018/07/Screenshot-from-2018-07-08-15-05-24-300x244.png +[10]:https://fedoramagazine.org/wp-content/uploads/2018/07/Screenshot-from-2018-07-08-15-05-24.png +[11]:https://fedoramagazine.org/wp-content/uploads/2018/07/Screenshot-from-2018-07-08-14-36-31-290x300.png +[12]:https://fedoramagazine.org/wp-content/uploads/2018/07/Screenshot-from-2018-07-08-14-36-31.png diff --git a/published/201807/20180709 Malware Found On The Arch User Repository (AUR).md b/published/201807/20180709 Malware Found On The Arch User Repository (AUR).md new file mode 100644 index 0000000000..6e10a14fc5 --- /dev/null +++ b/published/201807/20180709 Malware Found On The Arch User Repository (AUR).md @@ -0,0 +1,40 @@ +在 Arch 用户仓库(AUR)中发现恶意软件 +====== + +7 月 7 日,有一个 AUR 软件包被改入了一些恶意代码,提醒 [Arch Linux][1] 用户(以及一般的 Linux 用户)在安装之前应该尽可能检查所有由用户生成的软件包。 + +[AUR][3](即 Arch(Linux)用户仓库)包含包描述,也称为 PKGBUILD,它使得从源代码编译包变得更容易。虽然这些包非常有用,但它们永远不应被视为安全的,并且用户应尽可能在使用之前检查其内容。毕竟,AUR 在网页中以粗体显示 “**AUR 包是用户制作的内容。任何使用该提供的文件的风险由你自行承担。**” + +这次[发现][4]包含恶意代码的 AUR 包证明了这一点。[acroread][5] 于 7 月 7 日(看起来它以前是“孤儿”,意思是它没有维护者)被一位名为 “xeactor” 的用户修改,它包含了一行从 pastebin 使用 `curl` 下载脚本的命令。然后,该脚本下载了另一个脚本并安装了一个 systemd 单元以定期运行该脚本。 + +**看来有[另外两个][2] AUR 包以同样的方式被修改。所有违规软件包都已删除,并暂停了用于上传它们的用户帐户(它们注册在更新软件包的同一天)。** + +这些恶意代码没有做任何真正有害的事情 —— 它只是试图上传一些系统信息,比如机器 ID、`uname -a` 的输出(包括内核版本、架构等)、CPU 信息、pacman 信息,以及 `systemctl list-units`(列出 systemd 单元信息)的输出到 pastebin.com。我说“试图”是因为第二个脚本中存在错误而没有实际上传系统信息(上传函数为 “upload”,但脚本试图使用其他名称 “uploader” 调用它)。 + +此外,将这些恶意脚本添加到 AUR 的人将脚本中的个人 Pastebin API 密钥以明文形式留下,再次证明他们真的不明白他们在做什么。(LCTT 译注:意即这是一个菜鸟“黑客”,还不懂得如何有经验地隐藏自己。) + +尝试将此信息上传到 Pastebin 的目的尚不清楚,特别是原本可以上传更加敏感信息的情况下,如 GPG / SSH 密钥。 + +**更新:** Reddit用户 u/xanaxdroid_ [提及][6]同一个名为 “xeactor” 的用户也发布了一些加密货币挖矿软件包,因此他推测 “xeactor” 可能正计划添加一些隐藏的加密货币挖矿软件到 AUR([两个月][7]前的一些 Ubuntu Snap 软件包也是如此)。这就是 “xeactor” 可能试图获取各种系统信息的原因。此 AUR 用户上传的所有包都已删除,因此我无法检查。 + +**另一个更新:**你究竟应该在那些用户生成的软件包检查什么(如 AUR 中发现的)?情况各有不同,我无法准确地告诉你,但你可以从寻找任何尝试使用 `curl`、`wget`和其他类似工具下载内容的东西开始,看看他们究竟想要下载什么。还要检查从中下载软件包源的服务器,并确保它是官方来源。不幸的是,这不是一个确切的“科学做法”。例如,对于 Launchpad PPA,事情变得更加复杂,因为你必须懂得 Debian 如何打包,并且这些源代码是可以直接更改的,因为它托管在 PPA 中并由用户上传的。使用 Snap 软件包会变得更加复杂,因为在安装之前你无法检查这些软件包(据我所知)。在后面这些情况下,作为通用解决方案,我觉得你应该只安装你信任的用户/打包器生成的软件包。 + +-------------------------------------------------------------------------------- + +via: https://www.linuxuprising.com/2018/07/malware-found-on-arch-user-repository.html + +作者:[Logix][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[geekpi](https://github.com/geekpi) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://plus.google.com/118280394805678839070 +[1]:https://www.archlinux.org/ +[2]:https://lists.archlinux.org/pipermail/aur-general/2018-July/034153.html +[3]:https://aur.archlinux.org/ +[4]:https://lists.archlinux.org/pipermail/aur-general/2018-July/034152.html +[5]:https://aur.archlinux.org/cgit/aur.git/commit/?h=acroread&id=b3fec9f2f16703c2dae9e793f75ad6e0d98509bc +[6]:https://www.reddit.com/r/archlinux/comments/8x0p5z/reminder_to_always_read_your_pkgbuilds/e21iugg/ +[7]:https://www.linuxuprising.com/2018/05/malware-found-in-ubuntu-snap-store.html diff --git a/published/201807/20180710 15 open source applications for MacOS.md b/published/201807/20180710 15 open source applications for MacOS.md new file mode 100644 index 0000000000..9d4c9e1c0a --- /dev/null +++ b/published/201807/20180710 15 open source applications for MacOS.md @@ -0,0 +1,74 @@ +15 个适用于 MacOS 的开源应用程序 +====== + +> 钟爱开源的用户不会觉得在非 Linux 操作系统上使用他们喜爱的应用有多难。 + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/computer_keyboard_laptop_development_blue.png?itok=IfckxN48) + +只要有可能的情况下,我都会去选择使用开源工具。不久之前,我回到大学去攻读教育领导学硕士学位。即便是我将喜欢的 Linux 笔记本电脑换成了一台 MacBook Pro(因为我不能确定校园里能够接受 Linux),我还是决定继续使用我喜欢的工具,哪怕是在 MacOS 上也是如此。 + +幸运的是,它很容易,并且没有哪个教授质疑过我用的是什么软件。即然如此,我就不能秘而不宣。 + +我知道,我的一些同学最终会在学区担任领导职务,因此,我与我的那些使用 MacOS 或 Windows 的同学分享了关于下面描述的这些开源软件。毕竟,开源软件是真正地自由和友好的。我也希望他们去了解它,并且愿意以很少的一些成本去提供给他们的学生去使用这些世界级的应用程序。他们中的大多数人都感到很惊讶,因为,众所周知,开源软件除了有像你和我这样的用户之外,压根就没有销售团队。 + +### 我的 MacOS 学习曲线 + +虽然大多数的开源工具都能像以前我在 Linux 上使用的那样工作,只是需要不同的安装方法。但是,经过这个过程,我学习了这些工具在 MacOS 上的一些细微差别。像 [yum][1]、[DNF][2]、和 [APT][3] 在 MacOS 的世界中压根不存在 —— 我真的很怀念它们。 + +一些 MacOS 应用程序要求依赖项,并且安装它们要比我在 Linux 上习惯的方法困难很多。尽管如此,我仍然没有放弃。在这个过程中,我学会了如何在我的新平台上保留最好的软件。即便是 MacOS 大部分的核心也是 [开源的][4]。 + +此外,我的 Linux 的知识背景让我使用 MacOS 的命令行很轻松很舒适。我仍然使用命令行去创建和拷贝文件、添加用户、以及使用其它的像 `cat`、`tac`、`more`、`less` 和 `tail` 这样的 [实用工具][5]。 + +### 15 个适用于 MacOS 的非常好的开源应用程序 + + * 在大学里,要求我使用 DOCX 的电子版格式来提交我的工作,而这其实很容易,最初我使用的是 [OpenOffice][6],而后来我使用的是 [LibreOffice][7] 去完成我的论文。 + * 当我因为演示需要去做一些图像时,我使用的是我最喜欢的图像应用程序 [GIMP][8] 和 [Inkscape][9]。 + * 我喜欢的播客创建工具是 [Audacity][10]。它比起 Mac 上搭载的专有应用程序更加简单。我使用它去录制访谈和为视频演示创建配乐。 + * 在 MacOS 上我最早发现的多媒体播放器是 [VideoLan][11] (VLC)。 + * MacOS 内置的专有视频创建工具是一个非常好的产品,但是你也可以很轻松地去安装和使用 [OpenShot][12],它是一个非常好的内容创建工具。 + * 当我需要在我的客户端上分析网络时,我在我的 Mac 上使用了易于安装的 [Nmap][13] (Network Mapper) 和 [Wireshark][14] 工具。 + * 当我为图书管理员和其它教育工作者提供培训时,我在 MacOS 上使用 [VirtualBox][15] 去做 Raspbian、Fedora、Ubuntu 和其它 Linux 发行版的示范操作。 + * 我使用 [Etcher.io][16] 在我的 MacBook 上制作了一个引导盘,下载 ISO 文件,将它刻录到一个 U 盘上。 + * 我认为 [Firefox][17] 比起 MacBook Pro 自带的专有浏览器更易用更安全,并且它允许我跨操作系统去同步我的书签。 + * 当我使用电子书阅读器时,[Calibre][18] 是当之无愧的选择。它很容易去下载和安装,你甚至只需要几次点击就能将它配置为一台 [教室中使用的电子书服务器][19]。 + * 最近我给中学的学生教 Python 课程,我发现它可以很容易地从 [Python.org][20] 上下载和安装 Python 3 及 IDLE3 编辑器。我也喜欢学习数据科学,并与学生分享。不论你是对 Python 还是 R 感兴趣,我都建议你下载和 [安装][21] [Anaconda 发行版][22]。它包含了非常好的 iPython 编辑器、RStudio、Jupyter Notebooks、和 JupyterLab,以及其它一些应用程序。 + * [HandBrake][23] 是一个将你家里的旧的视频 DVD 转成 MP4 的工具,这样你就可以将它们共享到 YouTube、Vimeo、或者你的 MacOS 上的 [Kodi][24] 服务器上。 + +现在轮到你了:你在 MacOS(或 Windows)上都使用什么样的开源软件?在下面的评论区共享出来吧。 + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/7/open-source-tools-macos + +作者:[Don Watkins][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[qhwdw](https://github.com/qhwdw) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://opensource.com/users/don-watkins +[1]:https://en.wikipedia.org/wiki/Yum_(software) +[2]:https://en.wikipedia.org/wiki/DNF_(software) +[3]:https://en.wikipedia.org/wiki/APT_(Debian) +[4]:https://developer.apple.com/library/archive/documentation/MacOSX/Conceptual/OSX_Technology_Overview/SystemTechnology/SystemTechnology.html +[5]:https://www.gnu.org/software/coreutils/coreutils.html +[6]:https://www.openoffice.org/ +[7]:https://www.libreoffice.org/ +[8]:https://www.gimp.org/ +[9]:https://inkscape.org/en/ +[10]:https://www.audacityteam.org/ +[11]:https://www.videolan.org/index.html +[12]:https://www.openshot.org/ +[13]:https://nmap.org/ +[14]:https://www.wireshark.org/ +[15]:https://www.virtualbox.org/ +[16]:https://etcher.io/ +[17]:https://www.mozilla.org/en-US/firefox/new/ +[18]:https://calibre-ebook.com/ +[19]:https://opensource.com/article/17/6/raspberrypi-ebook-server +[20]:https://www.python.org/downloads/release/python-370/ +[21]:https://opensource.com/article/18/4/getting-started-anaconda-python +[22]:https://www.anaconda.com/download/#macos +[23]:https://handbrake.fr/ +[24]:https://kodi.tv/download diff --git a/published/201807/20180710 6 open source cryptocurrency wallets.md b/published/201807/20180710 6 open source cryptocurrency wallets.md new file mode 100644 index 0000000000..2b5aee97e6 --- /dev/null +++ b/published/201807/20180710 6 open source cryptocurrency wallets.md @@ -0,0 +1,94 @@ +6 个开源的数字货币钱包 +====== + +> 想寻找一个可以存储和交易你的比特币、以太坊和其它数字货币的软件吗?这里有 6 个开源的软件可以选择。 + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/bus_cash_register.jpg?itok=7NKVKuPa) + +没有数字货币钱包,像比特币和以太坊这样的数字货币只不过是又一个空想罢了。这些钱包对于保存、发送、以及接收数字货币来说是必需的东西。 + +迅速成长的 [数字货币][1] 之所以是革命性的,都归功于它的去中心化,该网络中没有中央权威,每个人都享有平等的权力。开源技术是数字货币和 [区块链][2] 网络的核心所在。它使得这个充满活力的新兴行业能够从去中心化中获益 —— 比如,不可改变、透明和安全。 + +如果你正在寻找一个自由开源的数字货币钱包,请继续阅读,并开始去探索以下的选择能否满足你的需求。 + +### 1、 Copay + +[Copay][3] 是一个能够很方便地存储比特币的开源数字货币钱包。这个软件以 [MIT 许可证][4] 发布。 + +Copay 服务器也是开源的。因此,开发者和比特币爱好者可以在服务器上部署他们自己的应用程序来完全控制他们的活动。 + +Copay 钱包能让你手中的比特币更加安全,而不是去信任不可靠的第三方。它允许你使用多重签名来批准交易,并且支持在同一个 app 钱包内支持存储多个独立的钱包。 + +Copay 可以在多种平台上使用,比如 Android、Windows、MacOS、Linux、和 iOS。 + +### 2、 MyEtherWallet + +正如它的名字所示,[MyEtherWallet][5] (缩写为 MEW) 是一个以太坊钱包。它是开源的(遵循 [MIT 许可证][6])并且是完全在线的,可以通过 web 浏览器来访问它。 + +这个钱包的客户端界面非常简洁,它可以让你自信而安全地参与到以太坊区块链中。 + +### 3、 mSIGNA + +[mSIGNA][7] 是一个功能强大的桌面版应用程序,用于在比特币网络上完成交易。它遵循 [MIT 许可证][8] 并且在 MacOS、Windows、和 Linux 上可用。 + +这个区块链钱包可以让你完全控制你存储的比特币。其中一些特性包括用户友好性、灵活性、去中心化的离线密钥生成能力、加密的数据备份,以及多设备同步功能。 + +### 4、 Armory + +[Armory][9] 是一个在你的计算机上产生和保管比特币私钥的开源钱包(遵循 [GNU AGPLv3][10])。它通过使用冷存储和支持多重签名的能力增强了安全性。 + +使用 Armory,你可以在完全离线的计算机上设置一个钱包;你将通过仅查看watch-only功能在因特网上查看你的比特币具体信息,这样有助于改善安全性。这个钱包也允许你去创建多个地址,并使用它们去完成不同的事务。 + +Armory 可用于 MacOS、Windows、和几个比较有特色的 Linux 平台上(包括树莓派)。 + +### 5、 Electrum + +[Electrum][11] 是一个既对新手友好又具备专家功能的比特币钱包。它遵循 [MIT 许可证][12] 来发行。 + +Electrum 可以在你的本地机器上使用较少的资源来实现本地加密你的私钥,支持冷存储,并且提供多重签名能力。 + +它在各种操作系统和设备上都可以使用,包括 Windows、MacOS、Android、iOS 和 Linux,并且也可以在像 [Trezor][13] 这样的硬件钱包中使用。 + +### 6、 Etherwall + +[Etherwall][14] 是第一款可以在桌面计算机上存储和发送以太坊的钱包。它是一个遵循 [GPLv3 许可证][15] 的开源钱包。 + +Etherwall 非常直观而且速度很快。更重要的是,它增加了你的私钥安全性,你可以在一个全节点或瘦节点上来运行它。它作为全节点客户端运行时,可以允许你在本地机器上下载整个以太坊区块链。 + +Etherwall 可以在 MacOS、Linux 和 Windows 平台上运行,并且它也支持 Trezor 硬件钱包。 + +### 智者之言 + +自由开源的数字钱包在让更多的人快速上手数字货币方面扮演至关重要的角色。 + +在你使用任何数字货币软件钱包之前,你一定要确保你的安全,而且一定要记住并完全遵循确保你的资金安全的最佳实践。 + +如果你喜欢的开源数字货币钱包不在以上的清单中,请在下面的评论区共享出你所知道的开源钱包。 + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/7/crypto-wallets + +作者:[Dr.Michael J.Garbade][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[qhwdw](https://github.com/qhwdw) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://opensource.com/users/drmjg +[1]:https://www.liveedu.tv/guides/cryptocurrency/ +[2]:https://opensource.com/tags/blockchain +[3]:https://copay.io/ +[4]:https://github.com/bitpay/copay/blob/master/LICENSE +[5]:https://www.myetherwallet.com/ +[6]:https://github.com/kvhnuke/etherwallet/blob/mercury/LICENSE.md +[7]:https://ciphrex.com/ +[8]:https://github.com/ciphrex/mSIGNA/blob/master/LICENSE +[9]:https://www.bitcoinarmory.com/ +[10]:https://github.com/etotheipi/BitcoinArmory/blob/master/LICENSE +[11]:https://electrum.org/#home +[12]:https://github.com/spesmilo/electrum/blob/master/LICENCE +[13]:https://trezor.io/ +[14]:https://www.etherwall.com/ +[15]:https://github.com/almindor/etherwall/blob/master/LICENSE diff --git a/published/201807/20180710 Display Weather Forecast In Your Terminal With Wttr.in.md b/published/201807/20180710 Display Weather Forecast In Your Terminal With Wttr.in.md new file mode 100644 index 0000000000..e97d5afdd1 --- /dev/null +++ b/published/201807/20180710 Display Weather Forecast In Your Terminal With Wttr.in.md @@ -0,0 +1,110 @@ +使用 Wttr.in 在你的终端中显示天气预报 +====== + +![](https://4.bp.blogspot.com/-NcP3j1tomlo/W0SIxp79cZI/AAAAAAAAA3Q/pmF3f2eeW_czoGuGgOu_MLudAUD_sVKIQCLcBGAs/s640/wttr-in-weather-console.png) + +[wttr.in][1] 是一个功能丰富的天气预报服务,它支持在命令行显示天气。它可以(根据你的 IP 地址)自动检测你的位置,也支持指定位置或搜索地理位置(如城市、山区等)等。哦,另外**你不需要安装它 —— 你只需要使用 cURL 或 Wget**(见下文)。 + +wttr.in 功能包括: + + * **显示当前天气以及 3 天内的天气预报,分为早晨、中午、傍晚和夜晚**(包括温度范围、风速和风向、可见度、降水量和概率) + * **可以显示月相** + * **基于你的 IP 地址自动检测位置** + * **允许指定城市名称、3 字母的机场代码、区域代码、GPS 坐标、IP 地址或域名**。你还可以指定地理位置,如湖泊、山脉、地标等) + * **支持多语言位置名称**(查询字符串必须以 Unicode 指定) + * **支持指定**天气预报显示的语言(它支持超过 50 种语言) + * **来自美国的查询使用 USCS 单位用于,世界其他地方使用公制系统**,但你可以通过附加 `?u` 使用 USCS,附加 `?m` 使用公制系统。 ) + * **3 种输出格式:终端的 ANSI,浏览器的 HTML 和 PNG** + +就像我在文章开头提到的那样,使用 wttr.in,你只需要 cURL 或 Wget,但你也可以在你的服务器上[安装它][3]。 或者你可以安装 [wego][4],这是一个使用 wtter.in 的终端气候应用,虽然 wego 要求注册一个 API 密钥来安装。 + +**在使用 wttr.in 之前,请确保已安装 cURL。**在 Debian、Ubuntu 或 Linux Mint(以及其他基于 Debian 或 Ubuntu 的 Linux 发行版)中,使用以下命令安装 cURL: + +``` +sudo apt install curl +``` + +### wttr.in 命令行示例 + +获取你所在位置的天气(wttr.in 会根据你的 IP 地址猜测你的位置): + +``` +curl wttr.in +``` + +通过在 `curl` 之后添加 `-4`,强制 cURL 将名称解析为 IPv4 地址(如果你用 IPv6 访问 wttr.in 有问题): + +``` +curl -4 wttr.in +``` + +如果你想检索天气预报保存为 png,**还可以使用 Wget**(而不是 cURL),或者你想这样使用它: + +``` +wget -O- -q wttr.in +``` + +如果相对 cURL 你更喜欢 Wget ,可以在下面的所有命令中用 `wget -O- -q` 替换 `curl`。 + +指定位置: + +``` +curl wttr.in/Dublin +``` + +显示地标的天气信息(本例中为艾菲尔铁塔): + +``` +curl wttr.in/~Eiffel+Tower +``` + +获取 IP 地址位置的天气信息(以下 IP 属于 GitHub): + +``` +curl wttr.in/@192.30.253.113 +``` + +使用 USCS 单位检索天气: + +``` +curl wttr.in/Paris?u +``` + +如果你在美国,强制 wttr.in 使用公制系统(SI): + +``` +curl wttr.in/New+York?m +``` + +使用 Wget 将当前天气和 3 天预报下载为 PNG 图像: + +``` +wget wttr.in/Istanbul.png +``` + +你可以指定 PNG 的[透明度][5],这在你要使用一个脚本自动添加天气信息到某些图片(比如墙纸)上有用。 + +**对于其他示例,请查看 wttr.in [项目页面][2]或在终端中输入:** + +``` +curl wttr.in/:help +``` + + +-------------------------------------------------------------------------------- + +via: https://www.linuxuprising.com/2018/07/display-weather-forecast-in-your.html + +作者:[Logix][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[geekpi](https://github.com/geekpi) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://plus.google.com/118280394805678839070 +[1]:https://wttr.in/ +[2]:https://github.com/chubin/wttr.in +[3]:https://github.com/chubin/wttr.in#installation +[4]:https://github.com/schachmat/wego +[5]:https://github.com/chubin/wttr.in#supported-formats diff --git a/published/201807/20180710 Getting started with Perlbrew.md b/published/201807/20180710 Getting started with Perlbrew.md new file mode 100644 index 0000000000..8d85de4527 --- /dev/null +++ b/published/201807/20180710 Getting started with Perlbrew.md @@ -0,0 +1,88 @@ +Perlbrew 入门 +====== + +> 用 Perlbrew 在你系统上安装多个版本的 Perl。 + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/coffee_cafe_brew_laptop_desktop.jpg?itok=G-n1o1-o) + +有比在系统上安装了 Perl 更好的事情吗?那就是在系统中安装了多个版本的 Perl。使用 [Perlbrew][1] 你可以做到这一点。但是为什么呢,除了让你包围在 Perl 下之外,有什么好处吗? + +简短的回答是,不同版本的 Perl 是......不同的。程序 A 可能依赖于较新版本中不推荐使用的行为,而程序 B 需要去年无法使用的新功能。如果你安装了多个版本的 Perl,则每个脚本都可以使用最适合它的版本。如果您是开发人员,这也会派上用场,你可以针对多个版本的 Perl 测试你的程序,这样无论你的用户运行什么,你都知道它能否工作。 + +### 安装 Perlbrew + +另一个好处是 Perlbrew 会安装 Perl 到用户的家目录。这意味着每个用户都可以管理他们的 Perl 版本(以及相关的 CPAN 包),而无需与系统管理员联系。自助服务意味着为用户提供更快的安装,并为系统管理员提供更多时间来解决难题。 + +第一步是在你的系统上安装 Perlbrew。许多 Linux 发行版已经在包仓库中拥有它,因此你只需要 `dnf install perlbrew`(或者适用于你的发行版的命令)。你还可以使用 `cpan App::perlbrew` 从 CPAN 安装 `App::perlbrew` 模块。或者你可以在 [install.perlbrew.pl][2] 下载并运行安装脚本。 + +要开始使用 Perlbrew,请运行 `perlbrew init`。 + +### 安装新的 Perl 版本 + +假设你想尝试最新的开发版本(撰写本文时为 5.27.11)。首先,你需要安装包: + +``` +perlbrew install 5.27.11 +``` + +### 切换 Perl 版本 + +现在你已经安装了新版本,你可以将它用于该 shell: + +``` +perlbrew use 5.27.11 +``` + +或者你可以将其设置为你帐户的默认 Perl 版本(假设你按照 `perlbrew init` 的输出设置了你的配置文件): + +``` +perlbrew switch 5.27.11 +``` + +### 运行单个脚本 + +你也可以用特定版本的 Perl 运行单个命令: + +``` +perlberew exec 5.27.11 myscript.pl +``` + +或者,你可以针对所有已安装的版本运行命令。如果你想针对各种版本运行测试,这尤其方便。在这种情况下,请指定版本为 `perl`: + +``` +plperlbrew exec perl myscriptpl +``` + +### 安装 CPAN 模块 + +如果你想安装 CPAN 模块,`cpanm` 包是一个易于使用的界面,可以很好地与 Perlbrew 一起使用。用下面命令安装它: + +``` +perlbrew install-cpanm +``` + +然后,你可以使用 `cpanm` 命令安装 CPAN 模块: + +``` +cpanm CGI::simple +``` + +### 但是等下,还有更多! + +本文介绍了基本的 Perlbrew 用法。还有更多功能和选项可供选择。从查看 `perlbrew help` 的输出开始,或查看[App::perlbrew 文档][3]。你还喜欢 Perlbrew 的其他什么功能?让我们在评论中知道。 + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/7/perlbrew + +作者:[Ben Cotton][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[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/bcotton +[1]:https://perlbrew.pl/ +[2]:https://raw.githubusercontent.com/gugod/App-perlbrew/master/perlbrew-install +[3]:https://metacpan.org/pod/App::perlbrew diff --git a/published/201807/20180710 Python Sets What Why and How.md b/published/201807/20180710 Python Sets What Why and How.md new file mode 100644 index 0000000000..26100e251b --- /dev/null +++ b/published/201807/20180710 Python Sets What Why and How.md @@ -0,0 +1,366 @@ +Python 集合是什么,为什么应该使用以及如何使用? +===== + +![Python Sets: What, Why and How](https://raw.githubusercontent.com/wilfredinni/pysheetComments/master/2018-july/python_sets/sets.png) + +Python 配备了几种内置数据类型来帮我们组织数据。这些结构包括列表、字典、元组和集合。 + +根据 Python 3 文档: + +> 集合是一个*无序*集合,没有*重复元素*。基本用途包括*成员测试*和*消除重复的条目*。集合对象还支持数学运算,如*并集*、*交集*、*差集*和*对等差分*。 + +在本文中,我们将回顾并查看上述定义中列出的每个要素的示例。让我们马上开始,看看如何创建它。 + +### 初始化一个集合 + +有两种方法可以创建一个集合:一个是给内置函数 `set()` 提供一个元素列表,另一个是使用花括号 `{}`。 + +使用内置函数 `set()` 来初始化一个集合: + +``` +>>> s1 = set([1, 2, 3]) +>>> s1 +{1, 2, 3} +>>> type(s1) + +``` + +使用 `{}`: + + +``` +>>> s2 = {3, 4, 5} +>>> s2 +{3, 4, 5} +>>> type(s2) + +>>> +``` + +如你所见,这两种方法都是有效的。但问题是,如果我们想要一个空的集合呢? + +``` +>>> s = {} +>>> type(s) + +``` + +没错,如果我们使用空花括号,我们将得到一个字典而不是一个集合。=) + +值得一提的是,为了简单起见,本文中提供的所有示例都将使用整数集合,但集合可以包含 Python 支持的所有 [可哈希的][6]hashable 数据类型。换句话说,即整数、字符串和元组,而不是*列表*或*字典*这样的可变类型。 + +``` +>>> s = {1, 'coffee', [4, 'python']} +Traceback (most recent call last): + File "", line 1, in +TypeError: unhashable type: 'list' +``` + +既然你知道了如何创建一个集合以及它可以包含哪些类型的元素,那么让我们继续看看*为什么*我们总是应该把它放在我们的工具箱中。 + +### 为什么你需要使用它 + +写代码时,你可以用不止一种方法来完成它。有些被认为是相当糟糕的,另一些则是清晰的、简洁的和可维护的,或者是 “[Python 式的][7]pythonic”。 + +根据 [Hitchhiker 对 Python 的建议][8]: + +> 当一个经验丰富的 Python 开发人员(Python 人Pythonista)调用一些不够 “Python 式的pythonic” 的代码时,他们通常认为着这些代码不遵循通用指南,并且无法被认为是以一种好的方式(可读性)来表达意图。 + +让我们开始探索 Python 集合那些不仅可以帮助我们提高可读性,还可以加快程序执行时间的方式。 + +#### 无序的集合元素 + +首先你需要明白的是:你无法使用索引访问集合中的元素。 + +``` +>>> s = {1, 2, 3} +>>> s[0] +Traceback (most recent call last): + File "", line 1, in +TypeError: 'set' object does not support indexing +``` + +或者使用切片修改它们: + +``` +>>> s[0:2] +Traceback (most recent call last): + File "", line 1, in +TypeError: 'set' object is not subscriptable +``` + +但是,如果我们需要删除重复项,或者进行组合列表(与)之类的数学运算,那么我们可以,并且*应该*始终使用集合。 + +我不得不提一下,在迭代时,集合的表现优于列表。所以,如果你需要它,那就加深对它的喜爱吧。为什么?好吧,这篇文章并不打算解释集合的内部工作原理,但是如果你感兴趣的话,这里有几个链接,你可以阅读它: + +* [时间复杂度][1] +* [set() 是如何实现的?][2] +* [Python 集合 vs 列表][3] +* [在列表中使用集合是否有任何优势或劣势,以确保独一无二的列表条目?][4] + +#### 没有重复项 + +写这篇文章的时候,我总是不停地思考,我经常使用 `for` 循环和 `if` 语句检查并删除列表中的重复元素。记得那时我的脸红了,而且不止一次,我写了类似这样的代码: + +``` +>>> my_list = [1, 2, 3, 2, 3, 4] +>>> no_duplicate_list = [] +>>> for item in my_list: +... if item not in no_duplicate_list: +... no_duplicate_list.append(item) +... +>>> no_duplicate_list +[1, 2, 3, 4] +``` + +或者使用列表解析: + +``` +>>> my_list = [1, 2, 3, 2, 3, 4] +>>> no_duplicate_list = [] +>>> [no_duplicate_list.append(item) for item in my_list if item not in no_duplicate_list] +[None, None, None, None] +>>> no_duplicate_list +[1, 2, 3, 4] +``` + +但没关系,因为我们现在有了武器装备,没有什么比这更重要的了: + +``` +>>> my_list = [1, 2, 3, 2, 3, 4] +>>> no_duplicate_list = list(set(my_list)) +>>> no_duplicate_list +[1, 2, 3, 4] +>>> +``` + +现在让我们使用 `timeit` 模块,查看列表和集合在删除重复项时的执行时间: + +``` +>>> from timeit import timeit +>>> def no_duplicates(list): +... no_duplicate_list = [] +... [no_duplicate_list.append(item) for item in list if item not in no_duplicate_list] +... return no_duplicate_list +... +>>> # 首先,让我们看看列表的执行情况: +>>> print(timeit('no_duplicates([1, 2, 3, 1, 7])', globals=globals(), number=1000)) +0.0018683355819786227 +``` + +``` +>>> from timeit import timeit +>>> # 使用集合: +>>> print(timeit('list(set([1, 2, 3, 1, 2, 3, 4]))', number=1000)) +0.0010220493243764395 +>>> # 快速而且干净 =) +``` + +使用集合而不是列表推导不仅让我们编写*更少的代码*,而且还能让我们获得*更具可读性*和*高性能*的代码。 + +注意:请记住集合是无序的,因此无法保证在将它们转换回列表时,元素的顺序不变。 + +[Python 之禅][9]: + +> 优美胜于丑陋Beautiful is better than ugly. + +> 明了胜于晦涩Explicit is better than implicit. + +> 简洁胜于复杂Simple is better than complex. + +> 扁平胜于嵌套Flat is better than nested. + +集合不正是这样美丽、明了、简单且扁平吗? + +#### 成员测试 + +每次我们使用 `if` 语句来检查一个元素,例如,它是否在列表中时,意味着你正在进行成员测试: + +``` +my_list = [1, 2, 3] +>>> if 2 in my_list: +... print('Yes, this is a membership test!') +... +Yes, this is a membership test! +``` + +在执行这些操作时,集合比列表更高效: + +``` +>>> from timeit import timeit +>>> def in_test(iterable): +... for i in range(1000): +... if i in iterable: +... pass +... +>>> timeit('in_test(iterable)', +... setup="from __main__ import in_test; iterable = list(range(1000))", +... number=1000) +12.459663048726043 +``` + +``` +>>> from timeit import timeit +>>> def in_test(iterable): +... for i in range(1000): +... if i in iterable: +... pass +... +>>> timeit('in_test(iterable)', +... setup="from __main__ import in_test; iterable = set(range(1000))", +... number=1000) +.12354438152988223 +``` + +注意:上面的测试来自于[这个][10] StackOverflow 话题。 + +因此,如果你在巨大的列表中进行这样的比较,尝试将该列表转换为集合,它应该可以加快你的速度。 + +### 如何使用 + +现在你已经了解了集合是什么以及为什么你应该使用它,现在让我们快速浏览一下,看看我们如何修改和操作它。 + +#### 添加元素 + +根据要添加的元素数量,我们要在 `add()` 和 `update()` 方法之间进行选择。 + +`add()` 适用于添加单个元素: + +``` +>>> s = {1, 2, 3} +>>> s.add(4) +>>> s +{1, 2, 3, 4} +``` + +`update()` 适用于添加多个元素: + +``` +>>> s = {1, 2, 3} +>>> s.update([2, 3, 4, 5, 6]) +>>> s +{1, 2, 3, 4, 5, 6} +``` + +请记住,集合会移除重复项。 + +#### 移除元素 + +如果你希望在代码中尝试删除不在集合中的元素时收到警报,请使用 `remove()`。否则,`discard()` 提供了一个很好的选择: + +``` +>>> s = {1, 2, 3} +>>> s.remove(3) +>>> s +{1, 2} +>>> s.remove(3) +Traceback (most recent call last): + File "", line 1, in +KeyError: 3 +``` + +`discard()` 不会引起任何错误: + +``` +>>> s = {1, 2, 3} +>>> s.discard(3) +>>> s +{1, 2} +>>> s.discard(3) +>>> # 什么都不会发生 +``` + +我们也可以使用 `pop()` 来随机丢弃一个元素: + +``` +>>> s = {1, 2, 3, 4, 5} +>>> s.pop() # 删除一个任意的元素 +1 +>>> s +{2, 3, 4, 5} +``` + +或者 `clear()` 方法来清空一个集合: + +``` +>>> s = {1, 2, 3, 4, 5} +>>> s.clear() # 清空集合 +>>> s +set() +``` + +#### union() + +`union()` 或者 `|` 将创建一个新集合,其中包含我们提供集合中的所有元素: + +``` +>>> s1 = {1, 2, 3} +>>> s2 = {3, 4, 5} +>>> s1.union(s2) # 或者 's1 | s2' +{1, 2, 3, 4, 5} +``` + +#### intersection() + +`intersection` 或 `&` 将返回一个由集合共同元素组成的集合: + +``` +>>> s1 = {1, 2, 3} +>>> s2 = {2, 3, 4} +>>> s3 = {3, 4, 5} +>>> s1.intersection(s2, s3) # 或者 's1 & s2 & s3' +{3} +``` + +#### difference() + +使用 `diference()` 或 `-` 创建一个新集合,其值在 “s1” 中但不在 “s2” 中: + +``` +>>> s1 = {1, 2, 3} +>>> s2 = {2, 3, 4} +>>> s1.difference(s2) # 或者 's1 - s2' +{1} +``` + +#### symmetric_diference() + +`symetric_difference` 或 `^` 将返回集合之间的不同元素。 + +``` +>>> s1 = {1, 2, 3} +>>> s2 = {2, 3, 4} +>>> s1.symmetric_difference(s2) # 或者 's1 ^ s2' +{1, 4} +``` + +### 结论 + +我希望在阅读本文之后,你会知道集合是什么,如何操纵它的元素以及它可以执行的操作。知道何时使用集合无疑会帮助你编写更清晰的代码并加速你的程序。 + +如果你有任何疑问,请发表评论,我很乐意尝试回答。另外,不要忘记,如果你已经理解了集合,它们在 [Python Cheatsheet][12] 中有自己的[一席之地][11],在那里你可以快速参考并重新认知你已经知道的内容。 + +-------------------------------------------------------------------------------- + +via: https://www.pythoncheatsheet.org/blog/python-sets-what-why-how + +作者:[wilfredinni][a] +译者:[MjSeven](https://github.com/MjSeven) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.pythoncheatsheet.org/author/wilfredinni +[1]:https://wiki.python.org/moin/TimeComplexity +[2]:https://stackoverflow.com/questions/3949310/how-is-set-implemented +[3]:https://stackoverflow.com/questions/2831212/python-sets-vs-lists +[4]:https://mail.python.org/pipermail/python-list/2011-June/606738.html +[5]:https://www.pythoncheatsheet.org/author/wilfredinni +[6]:https://docs.python.org/3/glossary.html#term-hashable +[7]:http://docs.python-guide.org/en/latest/writing/style/ +[8]:http://docs.python-guide.org/en/latest/ +[9]:https://www.python.org/dev/peps/pep-0020/ +[10]:https://stackoverflow.com/questions/2831212/python-sets-vs-lists +[11]:https://www.pythoncheatsheet.org/#sets +[12]:https://www.pythoncheatsheet.org/ +  diff --git a/published/201807/20180711 4 add-ons to improve your privacy on Thunderbird.md b/published/201807/20180711 4 add-ons to improve your privacy on Thunderbird.md new file mode 100644 index 0000000000..3fb7d3f7a8 --- /dev/null +++ b/published/201807/20180711 4 add-ons to improve your privacy on Thunderbird.md @@ -0,0 +1,64 @@ +4 个提高你在 Thunderbird 上隐私的加载项 +====== + +![](https://fedoramagazine.org/wp-content/uploads/2017/08/tb-privacy-addons-816x345.jpg) + +Thunderbird 是由 [Mozilla][1] 开发的流行的免费电子邮件客户端。与 Firefox 类似,Thunderbird 提供了大量加载项来用于额外功能和自定义。本文重点介绍四个加载项,以改善你的隐私。 + +### Enigmail + +使用 GPG(GNU Privacy Guard)加密电子邮件是保持其内容私密性的最佳方式。如果你不熟悉 GPG,请[查看我们在这里的入门介绍][2]。 + +[Enigmail][3] 是使用 OpenPGP 和 Thunderbird 的首选加载项。实际上,Enigmail 与 Thunderbird 集成良好,可让你加密、解密、数字签名和验证电子邮件。 + +### Paranoia + +[Paranoia][4] 可让你查看有关收到的电子邮件的重要信息。用一个表情符号显示电子邮件在到达收件箱之前经过的服务器之间的加密状态。 + +黄色、快乐的表情告诉你所有连接都已加密。蓝色、悲伤的表情意味着有一个连接未加密。最后,红色的、害怕的表情表示在多个连接上该消息未加密。 + +还有更多有关这些连接的详细信息,你可以用来检查哪台服务器用于投递邮件。 + +### Sensitivity Header + +[Sensitivity Header][5] 是一个简单的加载项,可让你选择外发电子邮件的隐私级别。使用选项菜单,你可以选择敏感度:正常、个人、隐私和机密。 + +添加此标头不会为电子邮件添加额外的安全性。但是,某些电子邮件客户端或邮件传输/用户代理(MTA/MUA)可以使用此标头根据敏感度以不同方式处理邮件。 + +请注意,开发人员将此加载项标记为实验性的。 + +### TorBirdy + +如果你真的担心自己的隐私,[TorBirdy][6] 就是给你设计的加载项。它将 Thunderbird 配置为使用 [Tor][7] 网络。 + +据其[文档][8]所述,TorBirdy 为以前没有使用 Tor 的电子邮件帐户提供了少量隐私保护。 + +> 请记住,跟之前使用 Tor 访问的电子邮件帐户相比,之前没有使用 Tor 访问的电子邮件帐户提供**更少**的隐私/匿名/更弱的假名。但是,TorBirdy 仍然对现有帐户或实名电子邮件地址有用。例如,如果你正在寻求隐匿位置 —— 你经常旅行并且不想通过发送电子邮件来披露你的所有位置 —— TorBirdy 非常有效! + +请注意,要使用此加载项,必须在系统上安装 Tor。 + +照片由 [Braydon Anderson][9] 在 [Unsplash][10] 上发布。 + + +-------------------------------------------------------------------------------- + +via: https://fedoramagazine.org/4-addons-privacy-thunderbird/ + +作者:[Clément Verna][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[geekpi](https://github.com/geekpi) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://fedoramagazine.org +[1]:https://www.mozilla.org/en-US/ +[2]:https://fedoramagazine.org/gnupg-a-fedora-primer/ +[3]:https://addons.mozilla.org/en-US/thunderbird/addon/enigmail/ +[4]:https://addons.mozilla.org/en-US/thunderbird/addon/paranoia/?src=cb-dl-users +[5]:https://addons.mozilla.org/en-US/thunderbird/addon/sensitivity-header/?src=cb-dl-users +[6]:https://addons.mozilla.org/en-US/thunderbird/addon/torbirdy/?src=cb-dl-users +[7]:https://www.torproject.org/ +[8]:https://trac.torproject.org/projects/tor/wiki/torbirdy +[9]:https://unsplash.com/photos/wOHH-NUTvVc?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText +[10]:https://unsplash.com/search/photos/privacy?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText diff --git a/published/201807/20180711 Install Microsoft Windows Fonts In Ubuntu 18.04 LTS.md b/published/201807/20180711 Install Microsoft Windows Fonts In Ubuntu 18.04 LTS.md new file mode 100644 index 0000000000..767db534c6 --- /dev/null +++ b/published/201807/20180711 Install Microsoft Windows Fonts In Ubuntu 18.04 LTS.md @@ -0,0 +1,174 @@ +在 Ubuntu 18.04 LTS 上安装 Microsoft Windows 字体 +====== + +![](https://www.ostechnix.com/wp-content/uploads/2016/07/Install-Microsoft-Windows-Fonts-in-Ubuntu-1-720x340.png) + +大多数教育机构仍在使用 Microsoft 字体, 我不清楚其他国家是什么情况。但在泰米尔纳德邦(印度的一个州), **Times New Roman** 和 **Arial** 字体主要被用于大学和学校的几乎所有文档工作、项目和作业。不仅是教育机构,而且一些小型组织、办公室和商店仍在使用 MS Windows 字体。以防万一,如果你需要在 Ubuntu 桌面版上使用 Microsoft 字体,请按照以下步骤安装。 + +**免责声明**: Microsoft 已免费发布其核心字体。 但**请注意 Microsoft 字体是禁止使用在其他操作系统中**。在任何 Linux 操作系统中安装 MS 字体之前请仔细阅读 EULA 。我们不负责这种任何种类的盗版行为。 + +(LCTT 译注:本文只做技术探讨,并不代表作者、译者和本站鼓励任何行为。) + +### 在 Ubuntu 18.04 LTS 桌面版上安装 MS 字体 + +如下所示安装 MS TrueType 字体: + +``` +$ sudo apt update +$ sudo apt install ttf-mscorefonts-installer +``` + +然后将会出现 Microsoft 的最终用户协议向导,点击 **OK** 以继续。 + +![][2] + +点击 **Yes** 已接受 Microsoft 的协议: + +![][3] + +安装字体之后, 我们需要使用命令行来更新字体缓存: + +``` +$ sudo fc-cache -f -v +``` + +**示例输出:** + +``` +/usr/share/fonts: caching, new cache contents: 0 fonts, 6 dirs +/usr/share/fonts/X11: caching, new cache contents: 0 fonts, 4 dirs +/usr/share/fonts/X11/Type1: caching, new cache contents: 8 fonts, 0 dirs +/usr/share/fonts/X11/encodings: caching, new cache contents: 0 fonts, 1 dirs +/usr/share/fonts/X11/encodings/large: caching, new cache contents: 0 fonts, 0 dirs +/usr/share/fonts/X11/misc: caching, new cache contents: 89 fonts, 0 dirs +/usr/share/fonts/X11/util: caching, new cache contents: 0 fonts, 0 dirs +/usr/share/fonts/cMap: caching, new cache contents: 0 fonts, 0 dirs +/usr/share/fonts/cmap: caching, new cache contents: 0 fonts, 5 dirs +/usr/share/fonts/cmap/adobe-cns1: caching, new cache contents: 0 fonts, 0 dirs +/usr/share/fonts/cmap/adobe-gb1: caching, new cache contents: 0 fonts, 0 dirs +/usr/share/fonts/cmap/adobe-japan1: caching, new cache contents: 0 fonts, 0 dirs +/usr/share/fonts/cmap/adobe-japan2: caching, new cache contents: 0 fonts, 0 dirs +/usr/share/fonts/cmap/adobe-korea1: caching, new cache contents: 0 fonts, 0 dirs +/usr/share/fonts/opentype: caching, new cache contents: 0 fonts, 2 dirs +/usr/share/fonts/opentype/malayalam: caching, new cache contents: 3 fonts, 0 dirs +/usr/share/fonts/opentype/noto: caching, new cache contents: 24 fonts, 0 dirs +/usr/share/fonts/truetype: caching, new cache contents: 0 fonts, 46 dirs +/usr/share/fonts/truetype/Gargi: caching, new cache contents: 1 fonts, 0 dirs +/usr/share/fonts/truetype/Gubbi: caching, new cache contents: 1 fonts, 0 dirs +/usr/share/fonts/truetype/Nakula: caching, new cache contents: 1 fonts, 0 dirs +/usr/share/fonts/truetype/Navilu: caching, new cache contents: 1 fonts, 0 dirs +/usr/share/fonts/truetype/Sahadeva: caching, new cache contents: 1 fonts, 0 dirs +/usr/share/fonts/truetype/Sarai: caching, new cache contents: 1 fonts, 0 dirs +/usr/share/fonts/truetype/abyssinica: caching, new cache contents: 1 fonts, 0 dirs +/usr/share/fonts/truetype/dejavu: caching, new cache contents: 6 fonts, 0 dirs +/usr/share/fonts/truetype/droid: caching, new cache contents: 1 fonts, 0 dirs +/usr/share/fonts/truetype/fonts-beng-extra: caching, new cache contents: 6 fonts, 0 dirs +/usr/share/fonts/truetype/fonts-deva-extra: caching, new cache contents: 3 fonts, 0 dirs +/usr/share/fonts/truetype/fonts-gujr-extra: caching, new cache contents: 5 fonts, 0 dirs +/usr/share/fonts/truetype/fonts-guru-extra: caching, new cache contents: 1 fonts, 0 dirs +/usr/share/fonts/truetype/fonts-kalapi: caching, new cache contents: 1 fonts, 0 dirs +/usr/share/fonts/truetype/fonts-orya-extra: caching, new cache contents: 1 fonts, 0 dirs +/usr/share/fonts/truetype/fonts-telu-extra: caching, new cache contents: 2 fonts, 0 dirs +/usr/share/fonts/truetype/freefont: caching, new cache contents: 12 fonts, 0 dirs +/usr/share/fonts/truetype/kacst: caching, new cache contents: 15 fonts, 0 dirs +/usr/share/fonts/truetype/kacst-one: caching, new cache contents: 2 fonts, 0 dirs +/usr/share/fonts/truetype/lao: caching, new cache contents: 1 fonts, 0 dirs +/usr/share/fonts/truetype/liberation: caching, new cache contents: 16 fonts, 0 dirs +/usr/share/fonts/truetype/liberation2: caching, new cache contents: 12 fonts, 0 dirs +/usr/share/fonts/truetype/lohit-assamese: caching, new cache contents: 1 fonts, 0 dirs +/usr/share/fonts/truetype/lohit-bengali: caching, new cache contents: 1 fonts, 0 dirs +/usr/share/fonts/truetype/lohit-devanagari: caching, new cache contents: 1 fonts, 0 dirs +/usr/share/fonts/truetype/lohit-gujarati: caching, new cache contents: 1 fonts, 0 dirs +/usr/share/fonts/truetype/lohit-kannada: caching, new cache contents: 1 fonts, 0 dirs +/usr/share/fonts/truetype/lohit-malayalam: caching, new cache contents: 1 fonts, 0 dirs +/usr/share/fonts/truetype/lohit-oriya: caching, new cache contents: 1 fonts, 0 dirs +/usr/share/fonts/truetype/lohit-punjabi: caching, new cache contents: 1 fonts, 0 dirs +/usr/share/fonts/truetype/lohit-tamil: caching, new cache contents: 1 fonts, 0 dirs +/usr/share/fonts/truetype/lohit-tamil-classical: caching, new cache contents: 1 fonts, 0 dirs +/usr/share/fonts/truetype/lohit-telugu: caching, new cache contents: 1 fonts, 0 dirs +/usr/share/fonts/truetype/malayalam: caching, new cache contents: 11 fonts, 0 dirs +/usr/share/fonts/truetype/msttcorefonts: caching, new cache contents: 60 fonts, 0 dirs +/usr/share/fonts/truetype/noto: caching, new cache contents: 2 fonts, 0 dirs +/usr/share/fonts/truetype/openoffice: caching, new cache contents: 1 fonts, 0 dirs +/usr/share/fonts/truetype/padauk: caching, new cache contents: 4 fonts, 0 dirs +/usr/share/fonts/truetype/pagul: caching, new cache contents: 1 fonts, 0 dirs +/usr/share/fonts/truetype/samyak: caching, new cache contents: 1 fonts, 0 dirs +/usr/share/fonts/truetype/samyak-fonts: caching, new cache contents: 3 fonts, 0 dirs +/usr/share/fonts/truetype/sinhala: caching, new cache contents: 1 fonts, 0 dirs +/usr/share/fonts/truetype/tibetan-machine: caching, new cache contents: 1 fonts, 0 dirs +/usr/share/fonts/truetype/tlwg: caching, new cache contents: 58 fonts, 0 dirs +/usr/share/fonts/truetype/ttf-khmeros-core: caching, new cache contents: 2 fonts, 0 dirs +/usr/share/fonts/truetype/ubuntu: caching, new cache contents: 13 fonts, 0 dirs +/usr/share/fonts/type1: caching, new cache contents: 0 fonts, 1 dirs +/usr/share/fonts/type1/gsfonts: caching, new cache contents: 35 fonts, 0 dirs +/usr/local/share/fonts: caching, new cache contents: 0 fonts, 0 dirs +/home/sk/.local/share/fonts: skipping, no such directory +/home/sk/.fonts: skipping, no such directory +/var/cache/fontconfig: cleaning cache directory +/home/sk/.cache/fontconfig: cleaning cache directory +/home/sk/.fontconfig: not cleaning non-existent cache directory +fc-cache: succeeded +``` + +### 在 Linux 和 Windows 双启动的机器上安装 MS 字体 + +如果你有 Linux 和 Windows 的双启动系统,你可以轻松地从 Windows C 驱动器上安装 MS 字体。 +你所要做的就是挂载 Windows 分区(C:/windows)。 + +我假设你已经在 Linux 中将 `C:\Windows` 分区挂载在了 `/Windowsdrive` 目录下。 + +现在,将字体位置链接到你的 Linux 系统的字体文件夹,如下所示: + +``` +ln -s /Windowsdrive/Windows/Fonts /usr/share/fonts/WindowsFonts +``` + +链接字体文件之后,使用命令行重新生成 fontconfig 缓存: + +``` +fc-cache +``` + +或者,将所有的 Windows 字体复制到 `/usr/share/fonts` 目录下并使用一下命令安装字体: + +``` +mkdir /usr/share/fonts/WindowsFonts +cp /Windowsdrive/Windows/Fonts/* /usr/share/fonts/WindowsFonts +chmod 755 /usr/share/fonts/WindowsFonts/* +``` + +最后,使用命令行重新生成 fontconfig 缓存: + +``` +fc-cache +``` + + +### 测试 Windows 字体 + +安装 MS 字体后打开 LibreOffice 或 GIMP。 现在,你将会看到 Microsoft coretype 字体。 + +![][4] + +就是这样, 希望这本指南有用。我再次警告你,在其他操作系统中使用 MS 字体是被禁止的。在安装 MS 字体之前请先阅读 Microsoft 许可协议。 + +如果你觉得我们的指南有用,请在你的社区、专业网络上分享并支持我们。还有更多好东西在等着我们。持续访问! + +庆祝吧!! + +-------------------------------------------------------------------------------- + +via: https://www.ostechnix.com/install-microsoft-windows-fonts-ubuntu-16-04/ + +作者:[SK][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[Auk7F7](https://github.com/Auk7F7) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.ostechnix.com/author/sk/ +[1]:data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7 +[2]:http://www.ostechnix.com/wp-content/uploads/2016/07/ms-fonts-1.png +[3]:http://www.ostechnix.com/wp-content/uploads/2016/07/ms-fonts-2.png +[4]:http://www.ostechnix.com/wp-content/uploads/2016/07/ms-fonts-3.png diff --git a/published/201807/20180718 How To Force User To Change Password On Next Login In Linux.md b/published/201807/20180718 How To Force User To Change Password On Next Login In Linux.md new file mode 100644 index 0000000000..5608feb816 --- /dev/null +++ b/published/201807/20180718 How To Force User To Change Password On Next Login In Linux.md @@ -0,0 +1,157 @@ +如何强制用户在下次登录 Linux 时更改密码 +====== + +当你使用默认密码创建用户时,你必须强制用户在下一次登录时更改密码。 + +当你在一个组织中工作时,此选项是强制性的。因为老员工可能知道默认密码,他们可能会也可能不会尝试不当行为。 + +这是安全投诉之一,所以,确保你必须以正确的方式处理此事而无任何失误。即使是你的团队成员也要一样做。 + +大多数用户都很懒,除非你强迫他们更改密码,否则他们不会这样做。所以要做这个实践。 + +出于安全原因,你需要经常更改密码,或者至少每个月更换一次。 + +确保你使用的是难以猜测的密码(大小写字母,数字和特殊字符的组合)。它至少应该为 10-15 个字符。 + +我们运行了一个 shell 脚本来在 Linux 服务器中创建一个用户账户,它会自动为用户附加一个密码,密码是实际用户名和少量数字的组合。 + +我们可以通过使用以下两种方法来实现这一点: + + * passwd 命令 + * chage 命令 + +**建议阅读:** + +- [如何在 Linux 上检查用户所属的组][1] +- [如何在 Linux 上检查创建用户的日期][2] +- [如何在 Linux 中重置/更改用户密码][3] +- [如何使用 passwd 命令管理密码过期和老化][4] + +### 方法 1:使用 passwd 命令 + +`passwd` 的意思是“密码”。它用于更新用户的身份验证令牌。`passwd` 命令/实用程序用于设置、修改或更改用户的密码。 + +普通的用户只能更改自己的账户,但超级用户可以更改任何账户的密码。 + +此外,我们还可以使用其他选项,允许用户执行其他活动,例如删除用户密码、锁定或解锁用户账户、设置用户账户的密码过期时间等。 + +在 Linux 中这可以通过调用 Linux-PAM 和 Libuser API 执行。 + +在 Linux 中创建用户时,用户详细信息将存储在 `/etc/passwd` 文件中。`passwd` 文件将每个用户的详细信息保存为带有七个字段的单行。 + +此外,在 Linux 系统中创建新用户时,将更新以下四个文件。 + + * `/etc/passwd`: 用户详细信息将在此文件中更新。 + * `/etc/shadow`: 用户密码信息将在此文件中更新。 + * `/etc/group`: 新用户的组详细信息将在此文件中更新。 + * `/etc/gshadow`: 新用户的组密码信息将在此文件中更新。 + +#### 如何使用 passwd 命令执行此操作 + +我们可以使用 `passwd` 命令并添加 `-e` 选项来执行此操作。 + +为了测试这一点,让我们创建一个新用户账户,看看它是如何工作的。 + +``` +# useradd -c "2g Admin - Magesh M" magesh && passwd magesh +Changing password for user magesh. +New password: +Retype new password: +passwd: all authentication tokens updated successfully. +``` + +使用户账户的密码失效,那么在下次登录尝试期间,用户将被迫更改密码。 + +``` +# passwd -e magesh +Expiring password for user magesh. +passwd: Success +``` + +当我第一次尝试使用此用户登录系统时,它要求我设置一个新密码。 + +``` +login as: magesh +[email protected]'s password: +You are required to change your password immediately (root enforced) +WARNING: Your password has expired. +You must change your password now and login again! +Changing password for user magesh. +Changing password for magesh. +(current) UNIX password: +New password: +Retype new password: +passwd: all authentication tokens updated successfully. +Connection to localhost closed. +``` + +### 方法 2:使用 chage 命令 + +`chage` 意即“改变时间”。它会更改用户密码过期信息。 + +`chage` 命令会改变上次密码更改日期之后需要修改密码的天数。系统使用此信息来确定用户何时必须更改他/她的密码。 + +它允许用户执行其他活动,例如设置帐户到期日期,到期后设置密码失效,显示帐户过期信息,设置密码更改前的最小和最大天数以及设置到期警告天数。 + +#### 如何使用 chage 命令执行此操作 + +让我们在 `chage` 命令的帮助下,通过添加 `-d` 选项执行此操作。 + +为了测试这一点,让我们创建一个新用户帐户,看看它是如何工作的。我们将创建一个名为 `thanu` 的用户帐户。 + +``` +# useradd -c "2g Editor - Thanisha M" thanu && passwd thanu +Changing password for user thanu. +New password: +Retype new password: +passwd: all authentication tokens updated successfully. +``` + +要实现这一点,请使用 `chage` 命令将用户的上次密码更改日期设置为 0。 + +``` +# chage -d 0 thanu + +# chage -l thanu +Last password change : Jul 18, 2018 +Password expires : never +Password inactive : never +Account expires : never +Minimum number of days between password change : 0 +Maximum number of days between password change : 99999 +Number of days of warning before password expires : 7 +``` + +当我第一次尝试使用此用户登录系统时,它要求我设置一个新密码。 + +``` +login as: thanu +[email protected]'s password: +You are required to change your password immediately (root enforced) +WARNING: Your password has expired. +You must change your password now and login again! +Changing password for user thanu. +Changing password for thanu. +(current) UNIX password: +New password: +Retype new password: +passwd: all authentication tokens updated successfully. +Connection to localhost closed. +``` + +-------------------------------------------------------------------------------- + +via: https://www.2daygeek.com/how-to-force-user-to-change-password-on-next-login-in-linux/ + +作者:[Prakash Subramanian][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[MjSeven](https://github.com/MjSeven) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.2daygeek.com/author/prakash/ +[1]:https://www.2daygeek.com/how-to-check-which-groups-a-user-belongs-to-on-linux/ +[2]:https://www.2daygeek.com/how-to-check-user-created-date-on-linux/ +[3]:https://www.2daygeek.com/passwd-command-examples/ +[4]:https://www.2daygeek.com/passwd-command-examples-part-l/ diff --git a/published/201807/20180718 How to check free disk space in Linux.md b/published/201807/20180718 How to check free disk space in Linux.md new file mode 100644 index 0000000000..88a9d7ae73 --- /dev/null +++ b/published/201807/20180718 How to check free disk space in Linux.md @@ -0,0 +1,71 @@ +如何检查 Linux 中的可用磁盘空间 +====== + +> 用这里列出的方便的工具来跟踪你的磁盘利用率。 + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/find-file-linux-code_magnifying_glass_zero.png?itok=E2HoPDg0) + +跟踪磁盘利用率信息是系统管理员(和其他人)的日常待办事项列表之一。Linux 有一些内置的使用程序来帮助提供这些信息。 + +### df + +`df` 命令意思是 “disk-free”,显示 Linux 系统上可用和已使用的磁盘空间。 + +`df -h` 以人类可读的格式显示磁盘空间。 + +`df -a` 显示文件系统的完整磁盘使用情况,即使 Available(可用) 字段为 0。 + +![](https://opensource.com/sites/default/files/uploads/df-ha.png) + +`df -T` 显示磁盘使用情况以及每个块的文件系统类型(例如,xfs、ext2、ext3、btrfs 等)。 + +`df -i` 显示已使用和未使用的 inode。 + +![](https://opensource.com/sites/default/files/uploads/df-ti.png) + +### du + +`du` 显示文件,目录等的磁盘使用情况,默认情况下以 kb 为单位显示。 + +`du -h` 以人类可读的方式显示所有目录和子目录的磁盘使用情况。 + +`du -a` 显示所有文件的磁盘使用情况。 + +`du -s` 提供特定文件或目录使用的总磁盘空间。 + +![](https://opensource.com/sites/default/files/uploads/du-has.png) + +### ls -al + +`ls -al` 列出了特定目录的全部内容及大小。 + +![](https://opensource.com/sites/default/files/uploads/ls-al.png) + +### stat + +`stat <文件/目录> `显示文件/目录或文件系统的大小和其他统计信息。 + +![](https://opensource.com/sites/default/files/uploads/stat.png) + +### fdisk -l + +`fdisk -l` 显示磁盘大小以及磁盘分区信息。 + +![](https://opensource.com/sites/default/files/uploads/fdisk.png) + +这些是用于检查 Linux 文件空间的大多数内置实用程序。有许多类似的工具,如 [Disks][1](GUI 工具),[Ncdu][2] 等,它们也显示磁盘空间的利用率。你有你最喜欢的工具而它不在这个列表上吗?请在评论中分享。 + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/7/how-check-free-disk-space-linux + +作者:[Archit Modi][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[MjSeven](https://github.com/MjSeven) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://opensource.com/users/architmodi +[1]:https://wiki.gnome.org/Apps/Disks +[2]:https://dev.yorhel.nl/ncdu diff --git a/published/201807/20180724 Learn how to build your own Twitter bot with Python.md b/published/201807/20180724 Learn how to build your own Twitter bot with Python.md new file mode 100644 index 0000000000..4b96a80563 --- /dev/null +++ b/published/201807/20180724 Learn how to build your own Twitter bot with Python.md @@ -0,0 +1,137 @@ +学习如何使用 Python 构建你自己的 Twitter 机器人 +====== + +![](https://fedoramagazine.org/wp-content/uploads/2018/07/twitterbot-816x345.jpg) + +Twitter 允许用户将博客帖子和文章[分享][1]给全世界。使用 Python 和 Tweepy 库使得创建一个 Twitter 机器人来接管你的所有的推特变得非常简单。这篇文章告诉你如何去构建这样一个机器人。希望你能将这些概念也同样应用到其他的在线服务的项目中去。 + +### 开始 + +[tweepy][2] 库可以让创建一个 Twitter 机器人的过程更加容易上手。它包含了 Twitter 的 API 调用和一个很简单的接口。 + +下面这些命令使用 `pipenv` 在一个虚拟环境中安装 tweepy。如果你没有安装 `pipenv`,可以看一看我们之前的文章[如何在 Fedora 上安装 Pipenv][3]。 + +``` +$ mkdir twitterbot +$ cd twitterbot +$ pipenv --three +$ pipenv install tweepy +$ pipenv shell +``` + +### Tweepy —— 开始 + +要使用 Twitter API ,机器人需要通过 Twitter 的授权。为了解决这个问题, tweepy 使用了 OAuth 授权标准。你可以通过在 创建一个新的应用来获取到凭证。 + + +#### 创建一个新的 Twitter 应用 + +当你填完了表格并点击了“创建你自己的 Twitter 应用Create your Twitter application”的按钮后,你可以获取到该应用的凭证。 Tweepy 需要用户密钥API Key用户密码API Secret,这些都可以在 “密钥和访问令牌Keys and Access Tokens” 中找到。 + +![][4] + +向下滚动页面,使用“创建我的访问令牌Create my access token”按钮生成一个“访问令牌Access Token” 和一个“访问令牌密钥Access Token Secret”。 + +#### 使用 Tweppy —— 输出你的时间线 + +现在你已经有了所需的凭证了,打开一个文件,并写下如下的 Python 代码。 + +``` +import tweepy +auth = tweepy.OAuthHandler("your_consumer_key", "your_consumer_key_secret") +auth.set_access_token("your_access_token", "your_access_token_secret") +api = tweepy.API(auth) +public_tweets = api.home_timeline() +for tweet in public_tweets: + print(tweet.text) +``` + +在确保你正在使用你的 Pipenv 虚拟环境后,执行你的程序。 + +``` +$ python tweet.py +``` + +上述程序调用了 `home_timeline` 方法来获取到你时间线中的 20 条最近的推特。现在这个机器人能够使用 tweepy 来获取到 Twitter 的数据,接下来尝试修改代码来发送 tweet。 + +#### 使用 Tweepy —— 发送一条推特 + +要发送一条推特 ,有一个容易上手的 API 方法 `update_status` 。它的用法很简单: + +``` +api.update_status("The awesome text you would like to tweet") +``` + +Tweepy 拓展为制作 Twitter 机器人准备了非常多不同有用的方法。要获取 API 的详细信息,请查看[文档][5]。 + + +### 一个杂志机器人 + +接下来我们来创建一个搜索 Fedora Magazine 的推特并转推这些的机器人。 + +为了避免多次转推相同的内容,这个机器人存放了最近一条转推的推特的 ID 。 两个助手函数 `store_last_id` 和 `get_last_id` 将会帮助存储和保存这个 ID。 + +然后,机器人使用 tweepy 搜索 API 来查找 Fedora Magazine 的最近的推特并存储这个 ID。 + +``` +import tweepy + +def store_last_id(tweet_id): + """ Stores a tweet id in text file """ + with open('lastid', 'w') as fp: + fp.write(str(tweet_id)) + + +def get_last_id(): + """ Retrieve the list of tweets that were + already retweeted """ + + with open('lastid') as fp: + return fp.read() + +if __name__ == '__main__': + + auth = tweepy.OAuthHandler("your_consumer_key", "your_consumer_key_secret") + auth.set_access_token("your_access_token", "your_access_token_secret") + + api = tweepy.API(auth) + + try: + last_id = get_last_id() + except FileNotFoundError: + print("No retweet yet") + last_id = None + + for tweet in tweepy.Cursor(api.search, q="fedoramagazine.org", since_id=last_id).items(): + if tweet.user.name == 'Fedora Project': + store_last_id(tweet.id) + #tweet.retweet() + print(f'"{tweet.text}" was retweeted') +``` + +为了只转推 Fedora Magazine 的推特 ,机器人搜索内容包含 fedoramagazine.org 和由 「Fedora Project」 Twitter 账户发布的推特。 + +### 结论 + +在这篇文章中你看到了如何使用 tweepy 的 Python 库来创建一个自动阅读、发送和搜索推特的 Twitter 应用。现在,你能使用你自己的创造力来创造一个你自己的 Twitter 机器人。 + +这篇文章的演示源码可以在 [Github][6] 找到。 + +-------------------------------------------------------------------------------- + +via: https://fedoramagazine.org/learn-build-twitter-bot-python/ + +作者:[Clément Verna][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[Bestony](https://github.com/bestony) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://fedoramagazine.org +[1]:https://twitter.com +[2]:https://tweepy.readthedocs.io/en/v3.5.0/ +[3]:https://linux.cn/article-9827-1.html +[4]:https://fedoramagazine.org/wp-content/uploads/2018/07/Screenshot-from-2018-07-19-20-17-17.png +[5]:http://docs.tweepy.org/en/v3.5.0/api.html#id1 +[6]:https://github.com/cverna/magabot diff --git a/published/20180702 View The Contents Of An Archive Or Compressed File Without Extracting It.md b/published/20180702 View The Contents Of An Archive Or Compressed File Without Extracting It.md new file mode 100644 index 0000000000..689061cb81 --- /dev/null +++ b/published/20180702 View The Contents Of An Archive Or Compressed File Without Extracting It.md @@ -0,0 +1,177 @@ +查看一个归档或压缩文件的内容而无需解压它 +====== + +![](https://www.ostechnix.com/wp-content/uploads/2018/07/View-The-Contents-Of-An-Archive-Or-Compressed-File-720x340.png) + +在本教程中,我们将学习如何在类 Unix 系统中查看一个归档或者压缩文件的内容而无需实际解压它。在深入之前,让我们先厘清归档和压缩文件的概念,它们之间有显著不同。归档是将多个文件或者目录归并到一个文件的过程,因此这个生成的文件是没有被压缩过的。而压缩则是结合多个文件或者目录到一个文件并最终压缩这个文件的方法。归档文件不是一个压缩文件,但压缩文件可以是一个归档文件,清楚了吗?好,那就让我们进入今天的主题。 + +### 查看一个归档或者压缩文件的内容而无需解压它 + +得益于 Linux 社区,有很多命令行工具可以来达成上面的目标。下面就让我们来看看使用它们的一些示例。 + +#### 1、使用 vim 编辑器 + +vim 不只是一个编辑器,使用它我们可以干很多事情。下面的命令展示的是在没有解压的情况下使用 vim 查看一个压缩的归档文件的内容: + +``` +$ vim ostechnix.tar.gz +``` + +![][2] + +你甚至还可以浏览归档文件的内容,打开其中的文本文件(假如有的话)。要打开一个文本文件,只需要用方向键将鼠标的游标放置到文件的前面,然后敲 ENTER 键来打开它。 + +#### 2、使用 tar 命令 + +为了列出一个 tar 归档文件的内容,可以运行: + +``` +$ tar -tf ostechnix.tar +ostechnix/ +ostechnix/image.jpg +ostechnix/file.pdf +ostechnix/song.mp3 +``` + +或者使用 `-v` 选项来查看归档文件的具体属性,例如它的文件所有者、属组、创建日期等等。 + +``` +$ tar -tvf ostechnix.tar +drwxr-xr-x sk/users 0 2018-07-02 19:30 ostechnix/ +-rw-r--r-- sk/users 53632 2018-06-29 15:57 ostechnix/image.jpg +-rw-r--r-- sk/users 156831 2018-06-04 12:37 ostechnix/file.pdf +-rw-r--r-- sk/users 9702219 2018-04-25 20:35 ostechnix/song.mp3 +``` + +#### 3、使用 rar 命令 + +要查看一个 rar 文件的内容,只需要执行: + +``` +$ rar v ostechnix.rar + +RAR 5.60 Copyright (c) 1993-2018 Alexander Roshal 24 Jun 2018 +Trial version Type 'rar -?' for help + +Archive: ostechnix.rar +Details: RAR 5 + +Attributes Size Packed Ratio Date Time Checksum Name +----------- --------- -------- ----- ---------- ----- -------- ---- +-rw-r--r-- 53632 52166 97% 2018-06-29 15:57 70260AC4 ostechnix/image.jpg +-rw-r--r-- 156831 139094 88% 2018-06-04 12:37 C66C545E ostechnix/file.pdf +-rw-r--r-- 9702219 9658527 99% 2018-04-25 20:35 DD875AC4 ostechnix/song.mp3 +----------- --------- -------- ----- ---------- ----- -------- ---- +9912682 9849787 99% 3 +``` + +#### 4、使用 unrar 命令 + +你也可以使用带有 `l` 选项的 `unrar` 来做到与上面相同的事情,展示如下: + +``` +$ unrar l ostechnix.rar + +UNRAR 5.60 freeware Copyright (c) 1993-2018 Alexander Roshal + +Archive: ostechnix.rar +Details: RAR 5 + +Attributes Size Date Time Name +----------- --------- ---------- ----- ---- +-rw-r--r-- 53632 2018-06-29 15:57 ostechnix/image.jpg +-rw-r--r-- 156831 2018-06-04 12:37 ostechnix/file.pdf +-rw-r--r-- 9702219 2018-04-25 20:35 ostechnix/song.mp3 +----------- --------- ---------- ----- ---- +9912682 3 +``` + +#### 5、使用 zip 命令 + +为了查看一个 zip 文件的内容而无需解压它,可以使用下面的 `zip` 命令: + +``` +$ zip -sf ostechnix.zip +Archive contains: +Life advices.jpg +Total 1 entries (597219 bytes) +``` + +#### 6、使用 unzip 命令 + +你也可以像下面这样使用 `-l` 选项的 `unzip` 命令来呈现一个 zip 文件的内容: + +``` +$ unzip -l ostechnix.zip +Archive: ostechnix.zip +Length Date Time Name +--------- ---------- ----- ---- +597219 2018-04-09 12:48 Life advices.jpg +--------- ------- +597219 1 file +``` + +#### 7、使用 zipinfo 命令 + +``` +$ zipinfo ostechnix.zip +Archive: ostechnix.zip +Zip file size: 584859 bytes, number of entries: 1 +-rw-r--r-- 6.3 unx 597219 bx defN 18-Apr-09 12:48 Life advices.jpg +1 file, 597219 bytes uncompressed, 584693 bytes compressed: 2.1% +``` + +如你所见,上面的命令展示了一个 zip 文件的内容、它的权限、创建日期和压缩百分比等等信息。 + +#### 8、使用 zcat 命令 + +要一个压缩的归档文件的内容而不解压它,使用 `zcat` 命令,我们可以得到: + +``` +$ zcat ostechnix.tar.gz +``` + +`zcat` 和 `gunzip -c` 命令相同。所以你可以使用下面的命令来查看归档或者压缩文件的内容: + +``` +$ gunzip -c ostechnix.tar.gz +``` + +#### 9、使用 zless 命令 + +要使用 zless 命令来查看一个归档或者压缩文件的内容,只需: + +``` +$ zless ostechnix.tar.gz +``` + +这个命令类似于 `less` 命令,它将一页一页地展示其输出。 + +#### 10、使用 less 命令 + +可能你已经知道 `less` 命令可以打开文件来交互式地阅读它,并且它支持滚动和搜索。 + +运行下面的命令来使用 `less` 命令查看一个归档或者压缩文件的内容: + +``` +$ less ostechnix.tar.gz +``` + +上面便是全部的内容了。现在你知道了如何在 Linux 中使用各种命令查看一个归档或者压缩文件的内容了。希望本文对你有用。更多好的内容将呈现给大家,希望继续关注我们! + +干杯! + +-------------------------------------------------------------------------------- + +via: https://www.ostechnix.com/how-to-view-the-contents-of-an-archive-or-compressed-file-without-extracting-it/ + +作者:[SK][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[FSSlc](https://github.com/FSSlc) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.ostechnix.com/author/sk/ +[1]:data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7 +[2]:http://www.ostechnix.com/wp-content/uploads/2018/07/vim.png diff --git a/published/20180703 Understanding Python Dataclasses — Part 1.md b/published/20180703 Understanding Python Dataclasses — Part 1.md new file mode 100644 index 0000000000..3b0d370546 --- /dev/null +++ b/published/20180703 Understanding Python Dataclasses — Part 1.md @@ -0,0 +1,506 @@ +理解 Python 的 Dataclasses(一) +====== + +![](https://cdn-images-1.medium.com/max/900/1*7pr8EL8EDsP296pxL7Wz_g.png) + +如果你正在阅读本文,那么你已经意识到了 Python 3.7 以及它所包含的新特性。就我个人而言,我对 `Dataclasses` 感到非常兴奋,因为我等了它一段时间了。 + +本系列包含两部分: + +1. Dataclass 特点概述 +2. 在下一篇文章概述 Dataclass 的 `fields` + +### 介绍 + +`Dataclasses` 是 Python 的类(LCTT 译注:更准确的说,它是一个模块),适用于存储数据对象。你可能会问什么是数据对象?下面是定义数据对象的一个不太详细的特性列表: + +* 它们存储数据并代表某种数据类型。例如:一个数字。对于熟悉 ORM 的人来说,模型实例就是一个数据对象。它代表一种特定的实体。它包含那些定义或表示实体的属性。 +* 它们可以与同一类型的其他对象进行比较。例如:一个数字可以是 `greater than`(大于)、`less than`(小于) 或 `equal`(等于) 另一个数字。 + +当然还有更多的特性,但是这个列表足以帮助你理解问题的关键。 + +为了理解 `Dataclasses`,我们将实现一个包含数字的简单类,并允许我们执行上面提到的操作。 + +首先,我们将使用普通类,然后我们再使用 `Dataclasses` 来实现相同的结果。 + +但在我们开始之前,先来谈谈 `Dataclasses` 的用法。 + +Python 3.7 提供了一个装饰器 [dataclass][2],用于将类转换为 `dataclass`。 + +你所要做的就是将类包在装饰器中: + +``` +from dataclasses import dataclass + +@dataclass +class A: + ... +``` + +现在,让我们深入了解一下 `dataclass` 带给我们的变化和用途。 + +### 初始化 + +通常是这样: + +``` +class Number: + + def __init__(self, val): + self.val = val + +>>> one = Number(1) +>>> one.val +>>> 1 +``` + +用 `dataclass` 是这样: + +``` +@dataclass +class Number: + val:int + +>>> one = Number(1) +>>> one.val +>>> 1 +``` + +以下是 `dataclass` 装饰器带来的变化: + +1. 无需定义 `__init__`,然后将值赋给 `self`,`dataclass` 负责处理它(LCTT 译注:此处原文可能有误,提及一个不存在的 `d`) +2. 我们以更加易读的方式预先定义了成员属性,以及[类型提示][3]。我们现在立即能知道 `val` 是 `int` 类型。这无疑比一般定义类成员的方式更具可读性。 + +> Python 之禅: 可读性很重要 + +它也可以定义默认值: + +``` +@dataclass +class Number: + val:int = 0 +``` + +### 表示 + +对象表示指的是对象的一个有意义的字符串表示,它在调试时非常有用。 + +默认的 Python 对象表示不是很直观: + +``` +class Number: + def __init__(self, val = 0): + self.val = val + +>>> a = Number(1) +>>> a +>>> <__main__.Number object at 0x7ff395b2ccc0> +``` + +这让我们无法知悉对象的作用,并且会导致糟糕的调试体验。 + +一个有意义的表示可以通过在类中定义一个 `__repr__` 方法来实现。 + +``` +def __repr__(self): + return self.val +``` + +现在我们得到这个对象有意义的表示: + +``` +>>> a = Number(1) +>>> a +>>> 1 +``` + +`dataclass` 会自动添加一个 `__repr__ ` 函数,这样我们就不必手动实现它了。 + +``` +@dataclass +class Number: + val: int = 0 +``` + +``` +>>> a = Number(1) +>>> a +>>> Number(val = 1) +``` + +### 数据比较 + +通常,数据对象之间需要相互比较。 + +两个对象 `a` 和 `b` 之间的比较通常包括以下操作: + +* `a < b` +* `a > b` +* `a == b` +* `a >= b` +* `a <= b` + +在 Python 中,能够在可以执行上述操作的类中定义[方法][4]。为了简单起见,不让这篇文章过于冗长,我将只展示 `==` 和 `<` 的实现。 + +通常这样写: + +``` +class Number: + def __init__( self, val = 0): + self.val = val + + def __eq__(self, other): + return self.val == other.val + + def __lt__(self, other): + return self.val < other.val +``` + +使用 `dataclass`: + +``` +@dataclass(order = True) +class Number: + val: int = 0 +``` + +是的,就是这样简单。 + +我们不需要定义 `__eq__` 和 `__lt__` 方法,因为当 `order = True` 被调用时,`dataclass` 装饰器会自动将它们添加到我们的类定义中。 + +那么,它是如何做到的呢? + +当你使用 `dataclass` 时,它会在类定义中添加函数 `__eq__` 和 `__lt__` 。我们已经知道这点了。那么,这些函数是怎样知道如何检查相等并进行比较呢? + +生成 `__eq__` 函数的 `dataclass` 类会比较两个属性构成的元组,一个由自己属性构成的,另一个由同类的其他实例的属性构成。在我们的例子中,`自动`生成的 `__eq__` 函数相当于: + +``` +def __eq__(self, other): + return (self.val,) == (other.val,) +``` + +让我们来看一个更详细的例子: + +我们会编写一个 `dataclass` 类 `Person` 来保存 `name` 和 `age`。 + +``` +@dataclass(order = True) +class Person: + name: str + age:int = 0 +``` + +自动生成的 `__eq__` 方法等同于: + +``` +def __eq__(self, other): + return (self.name, self.age) == ( other.name, other.age) +``` + +请注意属性的顺序。它们总是按照你在 `dataclass` 类中定义的顺序生成。 + +同样,等效的 `__le__` 函数类似于: + +``` +def __le__(self, other): + return (self.name, self.age) <= (other.name, other.age) +``` + +当你需要对数据对象列表进行排序时,通常会出现像 `__le__` 这样的函数的定义。Python 内置的 [sorted][5] 函数依赖于比较两个对象。 + +``` +>>> import random + +>>> a = [Number(random.randint(1,10)) for _ in range(10)] #generate list of random numbers + +>>> a + +>>> [Number(val=2), Number(val=7), Number(val=6), Number(val=5), Number(val=10), Number(val=9), Number(val=1), Number(val=10), Number(val=1), Number(val=7)] + +>>> sorted_a = sorted(a) #Sort Numbers in ascending order + +>>> [Number(val=1), Number(val=1), Number(val=2), Number(val=5), Number(val=6), Number(val=7), Number(val=7), Number(val=9), Number(val=10), Number(val=10)] + +>>> reverse_sorted_a = sorted(a, reverse = True) #Sort Numbers in descending order + +>>> reverse_sorted_a + +>>> [Number(val=10), Number(val=10), Number(val=9), Number(val=7), Number(val=7), Number(val=6), Number(val=5), Number(val=2), Number(val=1), Number(val=1)] + +``` + +### `dataclass` 作为一个可调用的装饰器 + +定义所有的 `dunder`(LCTT 译注:这是指双下划线方法,即魔法方法)方法并不总是值得的。你的用例可能只包括存储值和检查相等性。因此,你只需定义 `__init__` 和 `__eq__` 方法。如果我们可以告诉装饰器不生成其他方法,那么它会减少一些开销,并且我们将在数据对象上有正确的操作。 + +幸运的是,这可以通过将 `dataclass` 装饰器作为可调用对象来实现。 + +从官方[文档][6]来看,装饰器可以用作具有如下参数的可调用对象: + +``` +@dataclass(init=True, repr=True, eq=True, order=False, unsafe_hash=False, frozen=False) +class C: + … +``` + +1. `init`:默认将生成 `__init__` 方法。如果传入 `False`,那么该类将不会有 `__init__` 方法。 +2. `repr`:`__repr__` 方法默认生成。如果传入 `False`,那么该类将不会有 `__repr__` 方法。 +3. `eq`:默认将生成 `__eq__` 方法。如果传入 `False`,那么 `__eq__` 方法将不会被 `dataclass` 添加,但默认为 `object.__eq__`。 +4. `order`:默认将生成 `__gt__`、`__ge__`、`__lt__`、`__le__` 方法。如果传入 `False`,则省略它们。 + +我们在接下来会讨论 `frozen`。由于 `unsafe_hash` 参数复杂的用例,它值得单独发布一篇文章。 + +现在回到我们的用例,以下是我们需要的: + +1. `__init__` +2. `__eq__` + +默认会生成这些函数,因此我们需要的是不生成其他函数。那么我们该怎么做呢?很简单,只需将相关参数作为 false 传入给生成器即可。 + +``` +@dataclass(repr = False) # order, unsafe_hash and frozen are False +class Number: + val: int = 0 + + +>>> a = Number(1) + +>>> a + +>>> <__main__.Number object at 0x7ff395afe898> + +>>> b = Number(2) + +>>> c = Number(1) + +>>> a == b + +>>> False + +>>> a < b + +>>> Traceback (most recent call last): + File “”, line 1, in +TypeError: ‘<’ not supported between instances of ‘Number’ and ‘Number’ +``` + +### Frozen(不可变) 实例 + +Frozen 实例是在初始化对象后无法修改其属性的对象。 + +> 无法创建真正不可变的 Python 对象 + +在 Python 中创建对象的不可变属性是一项艰巨的任务,我将不会在本篇文章中深入探讨。 + +以下是我们期望不可变对象能够做到的: + +``` +>>> a = Number(10) #Assuming Number class is immutable + +>>> a.val = 10 # Raises Error +``` + +有了 `dataclass`,就可以通过使用 `dataclass` 装饰器作为可调用对象配合参数 `frozen=True` 来定义一个 `frozen` 对象。 + +当实例化一个 `frozen` 对象时,任何企图修改对象属性的行为都会引发 `FrozenInstanceError`。 + +``` +@dataclass(frozen = True) +class Number: + val: int = 0 + +>>> a = Number(1) + +>>> a.val + +>>> 1 + +>>> a.val = 2 + +>>> Traceback (most recent call last): + File “”, line 1, in + File “”, line 3, in __setattr__ +dataclasses.FrozenInstanceError: cannot assign to field ‘val’ +``` + +因此,一个 `frozen` 实例是一种很好方式来存储: + +* 常数 +* 设置 + +这些通常不会在应用程序的生命周期内发生变化,任何企图修改它们的行为都应该被禁止。 + +### 后期初始化处理 + +有了 `dataclass`,需要定义一个 `__init__` 方法来将变量赋给 `self` 这种初始化操作已经得到了处理。但是我们失去了在变量被赋值之后立即需要的函数调用或处理的灵活性。 + +让我们来讨论一个用例,在这个用例中,我们定义一个 `Float` 类来包含浮点数,然后在初始化之后立即计算整数和小数部分。 + +通常是这样: + +``` +import math + +class Float: + def __init__(self, val = 0): + self.val = val + self.process() + + def process(self): + self.decimal, self.integer = math.modf(self.val) + +>>> a = Float( 2.2) + +>>> a.decimal + +>>> 0.2000 + +>>> a.integer + +>>> 2.0 +``` + +幸运的是,使用 [__post_init__][9]  方法已经能够处理后期初始化操作。 + +生成的 `__init__`  方法在返回之前调用 `__post_init__` 返回。因此,可以在函数中进行任何处理。 + +``` +import math + +@dataclass +class FloatNumber: + val: float = 0.0 + + def __post_init__(self): + self.decimal, self.integer = math.modf(self.val) + +>>> a = Number(2.2) + +>>> a.val + +>>> 2.2 + +>>> a.integer + +>>> 2.0 + +>>> a.decimal + +>>> 0.2 +``` + +多么方便! + +### 继承 + +`Dataclasses` 支持继承,就像普通的 Python 类一样。 + +因此,父类中定义的属性将在子类中可用。 + +``` +@dataclass +class Person: + age: int = 0 + name: str + +@dataclass +class Student(Person): + grade: int + +>>> s = Student(20, "John Doe", 12) + +>>> s.age + +>>> 20 + +>>> s.name + +>>> "John Doe" + +>>> s.grade + +>>> 12 +``` + +请注意,`Student` 的参数是在类中定义的字段的顺序。 + +继承过程中 `__post_init__` 的行为是怎样的? + +由于 `__post_init__` 只是另一个函数,因此必须以传统方式调用它: + +``` +@dataclass +class A: + a: int + + def __post_init__(self): + print("A") + +@dataclass +class B(A): + b: int + + def __post_init__(self): + print("B") + +>>> a = B(1,2) + +>>> B +``` + +在上面的例子中,只有 `B` 的 `__post_init__` 被调用,那么我们如何调用 `A` 的 `__post_init__` 呢? + +因为它是父类的函数,所以可以用 `super` 来调用它。 + +``` +@dataclass +class B(A): + b: int + + def __post_init__(self): + super().__post_init__() # 调用 A 的 post init + print("B") + +>>> a = B(1,2) + +>>> A + B +``` + +### 结论 + +因此,以上是 `dataclass` 使 Python 开发人员变得更轻松的几种方法。 + +我试着彻底覆盖大部分的用例,但是,没有人是完美的。如果你发现了错误,或者想让我注意相关的用例,请联系我。 + +我将在另一篇文章中介绍 [dataclasses.field][10] 和 `unsafe_hash`。 + +在 [Github][11] 和 [Twitter][12] 关注我。 + +更新:`dataclasses.field` 的文章可以在[这里][13]找到。 + + +-------------------------------------------------------------------------------- + +via: https://medium.com/mindorks/understanding-python-dataclasses-part-1-c3ccd4355c34 + +作者:[Shikhar Chauhan][a] +译者:[MjSeven](https://github.com/MjSeven) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://medium.com/@xsschauhan?source=post_header_lockup +[1]:https://medium.com/@xsschauhan/understanding-python-dataclasses-part-2-660ecc11c9b8 +[2]:https://docs.python.org/3.7/library/dataclasses.html#dataclasses.dataclass +[3]:https://stackoverflow.com/q/32557920/4333721 +[4]:https://docs.python.org/3/reference/datamodel.html#object.__lt__ +[5]:https://docs.python.org/3.7/library/functions.html#sorted +[6]:https://docs.python.org/3/library/dataclasses.html#dataclasses.dataclass +[7]:http://twitter.com/dataclass +[8]:http://twitter.com/dataclass +[9]:https://docs.python.org/3/library/dataclasses.html#post-init-processing +[10]:https://docs.python.org/3/library/dataclasses.html#dataclasses.field +[11]:http://github.com/xssChauhan/ +[12]:https://twitter.com/xssChauhan +[13]:https://medium.com/@xsschauhan/understanding-python-dataclasses-part-2-660ecc11c9b8 diff --git a/published/20180706 Anatomy of a Linux DNS Lookup - Part III.md b/published/20180706 Anatomy of a Linux DNS Lookup - Part III.md new file mode 100644 index 0000000000..7df06726df --- /dev/null +++ b/published/20180706 Anatomy of a Linux DNS Lookup - Part III.md @@ -0,0 +1,287 @@ +Linux DNS 查询剖析(第三部分) +============================================================ + +在 [Linux DNS 查询剖析(第一部分)][1]中,我们介绍了: + +* `nsswitch` +* `/etc/hosts` +* `/etc/resolv.conf` +* `ping` 与 `host` 查询方式的对比 + +而在 [Linux DNS 查询剖析(第二部分)][2],我们介绍了: + +* `systemd` 和对应的 `networking` 服务 +* `ifup` 和 `ifdown` +* `dhclient` +* `resolvconf` + +剖析进展如下: + +![linux-dns-2 (2)][4] + + _(大致)准确的关系图_ + +很可惜,故事还没有结束,还有不少东西也会影响 DNS 查询。在第三部分中,我将介绍 `NetworkManager` 和 `dnsmasq`,简要说明它们如何影响 DNS 查询。 + +### 1) NetworkManager + +在第二部分已经提到,我们现在介绍的内容已经偏离 POSIX 标准,涉及的 DNS 解析管理部分在各个发行版上形式并不统一。 + +在我使用的发行版 (Ubuntu)中,有一个名为 [NetworkManager][3] 的可用available服务,它通常作为一些其它软件包的依赖被安装。它实际上是 RedHat 在 2004 年开发的一个服务,用于帮助你管理网络接口。 + +它与 DNS 查询有什么关系呢?让我们安装这个服务并找出答案: + +``` +$ apt-get install -y network-manager +``` + +对于 Ubuntu,在软件包安装后,你可以发现一个新的配置文件: + +``` +$ cat /etc/NetworkManager/NetworkManager.conf +[main] +plugins=ifupdown,keyfile,ofono +dns=dnsmasq + +[ifupdown] +managed=false +``` + +看到 `dns=dnsmasq` 了吧?这意味着 `NetworkManager` 将使用 `dnsmasq` 管理主机上的 DNS。 + +### 2) dnsmasq + +`dnsmasq` 程序是我们很熟悉的程序:只是 `/etc/resolv.conf` 之上的又一个间接层。 + +理论上,`dnsmasq` 有多种用途,但主要被用作 DNS 缓存服务器,缓存到其它 DNS 服务器的请求。`dnsmasq` 在本地所有网络接口上监听 53 端口(标准的 DNS 端口)。 + +那么 `dnsmasq` 运行在哪里呢?`NetworkManager` 的运行情况如下: + +``` +$ ps -ef | grep NetworkManager +root     15048     1  0 16:39 ?        00:00:00 /usr/sbin/NetworkManager --no-daemon +``` + +但并没有找到 `dnsmasq` 相关的进程: + +``` +$ ps -ef | grep dnsmasq +$ +``` + +令人迷惑的是,虽然 `dnsmasq` 被配置用于管理 DNS,但其实并没有安装在系统上!因而,你需要自己安装它。 + +安装之前,让我们查看一下 `/etc/resolv.conf` 文件的内容: + +``` +$ cat /etc/resolv.conf +# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8) +#     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN +nameserver 10.0.2.2 +search home +``` + +可见,并没有被 `NetworkManager` 修改。 + +如果安装 `dnsmasq`: + +``` +$ apt-get install -y dnsmasq +``` + +然后启动运行 `dnsmasq`: + +``` +$ ps -ef | grep dnsmasq +dnsmasq  15286     1  0 16:54 ?        00:00:00 /usr/sbin/dnsmasq -x /var/run/dnsmasq/dnsmasq.pid -u dnsmasq -r /var/run/dnsmasq/resolv.conf -7 /etc/dnsmasq.d,.dpkg-dist,.dpkg-old,.dpkg-new --local-service --trust-anchor=.,19036,8,2,49AAC11D7B6F6446702E54A1607371607A1A41855200FD2CE1CDDE32F24E8FB5 +``` + +然后,`/etc/resolv.conf` 文件内容又改变了! + +``` +root@linuxdns1:~# cat /etc/resolv.conf +# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8) +#     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN +nameserver 127.0.0.1 +search home +``` + +运行 `netstat` 命令,可以看出 `dnsmasq` 在所有网络接口上监听 53 端口: + +``` +$ netstat -nlp4 +Active Internet connections (only servers) +Proto Recv-Q Send-Q Local Address     Foreign Address State   PID/Program name +tcp        0      0 127.0.0.1:53      0.0.0.0:*       LISTEN  15286/dnsmasq  +tcp        0      0 10.0.2.15:53      0.0.0.0:*       LISTEN  15286/dnsmasq +tcp        0      0 172.28.128.11:53  0.0.0.0:*       LISTEN  15286/dnsmasq +tcp        0      0 0.0.0.0:22        0.0.0.0:*       LISTEN  1237/sshd +udp        0      0 127.0.0.1:53      0.0.0.0:*         15286/dnsmasq +udp        0      0 10.0.2.15:53      0.0.0.0:*               15286/dnsmasq   +udp        0      0 172.28.128.11:53  0.0.0.0:*               15286/dnsmasq   +udp        0      0 0.0.0.0:68        0.0.0.0:*               10758/dhclient +udp        0      0 0.0.0.0:68        0.0.0.0:*               10530/dhclient +udp        0      0 0.0.0.0:68        0.0.0.0:*               10185/dhclient +``` + +### 3) 分析 dnsmasq + +在目前的情况下,所有的 DNS 查询都会使用 `127.0.0.1:53` 这个 DNS 服务器,下一步会发生什么呢? + +我再次查看 `/var/run` 目录,可以发现一个线索:`resolvconf` 目录下 `resolv.conf` 文件中的配置也相应变更,变更为 `dnsmasq` 对应的 DNS 服务器: + +``` +$ cat /var/run/resolvconf/resolv.conf +# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8) +#     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN +nameserver 127.0.0.1 +search home +``` + +同时,出现了一个新的 `dnsmasq` 目录,也包含一个 `resolv.conf` 文件: + +``` +$ cat /run/dnsmasq/resolv.conf +nameserver 10.0.2.2 +``` + +(LCTT 译注:这里依次提到了 `/var/run` 和 `/run`,使用 Ubuntu 16.04 LTS 验证发现,`/var/run` 其实是指向 `/run/` 的软链接) + +该文件包含我们从 `DHCP` 获取的 `nameserver`。 + +虽然可以推导出这个结论,但如何查看具体的调用逻辑呢? + +### 4) 调试 dnsmasq + +我经常思考 `dnsmasq` (在整个过程中)的功能定位。幸运的是,如果你将 `/etc/dnsmasq.conf` 中的一行做如下调整,你可以获取大量 `dnsmasq` 状态的信息: + +``` +#log-queries +``` + +修改为: + +``` +log-queries +``` + +然后重启 `dnsmasq`。 + +接下来,只要运行一个简单的命令: + +``` +$ ping -c1 bbc.co.uk +``` + +你就可以在 `/var/log/syslog` 中找到类似的内容(其中 `[...]` 表示行首内容与上一行相同): + +``` +Jul  3 19:56:07 ubuntu-xenial dnsmasq[15372]: query[A] bbc.co.uk from 127.0.0.1 +[...] forwarded bbc.co.uk to 10.0.2.2 +[...] reply bbc.co.uk is 151.101.192.81 +[...] reply bbc.co.uk is 151.101.0.81 +[...] reply bbc.co.uk is 151.101.64.81 +[...] reply bbc.co.uk is 151.101.128.81 +[...] query[PTR] 81.192.101.151.in-addr.arpa from 127.0.0.1 +[...] forwarded 81.192.101.151.in-addr.arpa to 10.0.2.2 +[...] reply 151.101.192.81 is NXDOMAIN +``` + +可以清晰看出 `dnsmasq` 收到的查询、查询被转发到了哪里以及收到的回复。 + +如果查询被缓存命中(或者说,本地的查询结果还在存活时间time-to-live TTL 内,并未过期),日志显示如下: + +``` +[...] query[A] bbc.co.uk from 127.0.0.1 +[...] cached bbc.co.uk is 151.101.64.81 +[...] cached bbc.co.uk is 151.101.128.81 +[...] cached bbc.co.uk is 151.101.192.81 +[...] cached bbc.co.uk is 151.101.0.81 +[...] query[PTR] 81.64.101.151.in-addr.arpa from 127.0.0.1 +``` + +如果你想了解缓存中有哪些记录,可以向 `dnsmasq` 进程 id 发送 `USR1` 信号,这样 `dnsmasq` 会将缓存记录导出并写入到相同的日志文件中: + +``` +$ kill -SIGUSR1 $(cat /run/dnsmasq/dnsmasq.pid) +``` + +(LCTT 译注:原文中命令执行报错,已变更成最接近且符合作者意图的命令) + +导出记录对应如下输出: + +``` +Jul  3 15:08:08 ubuntu-xenial dnsmasq[15697]: time 1530630488 +[...] cache size 150, 0/5 cache insertions re-used unexpired cache entries. +[...] queries forwarded 2, queries answered locally 0 +[...] queries for authoritative zones 0 +[...] server 10.0.2.2#53: queries sent 2, retried or failed 0 +[...] Host           Address        Flags      Expires +[...] linuxdns1      172.28.128.8   4FRI   H +[...] ip6-localhost  ::1            6FRI   H +[...] ip6-allhosts   ff02::3         6FRI   H +[...] ip6-localnet     fe00::         6FRI   H +[...] ip6-mcastprefix  ff00::         6FRI   H +[...] ip6-loopback     :               6F I   H +[...] ip6-allnodes    ff02:           6FRI   H +[...] bbc.co.uk        151.101.64.81  4F         Tue Jul  3 15:11:41 2018 +[...] bbc.co.uk        151.101.192.81 4F         Tue Jul  3 15:11:41 2018 +[...] bbc.co.uk        151.101.0.81    4F         Tue Jul  3 15:11:41 2018 +[...] bbc.co.uk        151.101.128.81 4F         Tue Jul  3 15:11:41 2018 +[...]                  151.101.64.81  4 R  NX    Tue Jul  3 15:34:17 2018 +[...] localhost        127.0.0.1      4FRI   H +[...]           19036   8   2  SF I +[...] ip6-allrouters   ff02::2        6FRI   H +``` + +在上面的输出中,我猜测(并不确认,`?` 代表我比较无根据的猜测)如下: + +* `4` 代表 IPv4 +* `6` 代表 IPv6 +* `H` 代表从 `/etc/hosts` 中读取 IP 地址 +* `I` ? “永生”的 DNS 记录 ? (例如,没有设置存活时间数值 ?) +* `F` ? +* `R` ? +* `S` ? +* `N` ? +* `X` + +(LCTT 译注:查看 `dnsmasq` 的源代码 [`cache.c`][5] 可知,`4` 代表 `IPV4`,`6` 代表 `IPV6`,`C` 代表 `CNAME`,`S` 代表 `DNSSEC`,`F` 代表 `FORWARD`,`R` 代表 `REVERSE`,`I` 代表 `IMMORTAL`,`N` 代表 `NEG`,`X` 代表 `NXDOMAIN`,`H` 代表 `HOSTS`。更具体的含义需要查看代码或相关文档) + +#### dnsmasq 的替代品 + +`NetworkManager` 配置中的 `dns` 字段并不是只能使用 `dnsmasq`,可选项包括 `none`,`default`,`unbound` 和 `dnssec-triggered` 等。使用 `none` 时,`NetworkManager` 不会改动 `/etc/resolv.conf`;使用 `default` 时,`NetworkManager` 会根据当前的活跃连接active connections更新 `resolv.conf`;使用 `unbound` 时,`NetworkManager` 会与 `unbound` 服务通信;`dnssec-triggered` 与 DNS 安全相关,不在本文讨论范围。 + +### 第三部分总结 + +第三部分到此结束,其中我们介绍了 `NetworkManager` 服务及其 `dns=dnsmasq` 的配置。 + +下面简要罗列一下我们已经介绍过的全部内容: + +* `nsswitch` +* `/etc/hosts` +* `/etc/resolv.conf` +* `/run/resolvconf/resolv.conf` +* `systemd` 及对应的 `networking` 服务 +* `ifup` 和 `ifdown` +* `dhclient` +* `resolvconf` +* `NetworkManager` +* `dnsmasq` + +-------------------------------------------------------------------------------- + +via: https://zwischenzugs.com/2018/07/06/anatomy-of-a-linux-dns-lookup-part-iii/ + +作者:[ZWISCHENZUGS][a] +译者:[pinewall](https://github.com/pinewall) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://zwischenzugs.com/ +[1]:https://linux.cn/article-9943-1.html +[2]:https://linux.cn/article-9949-1.html +[3]:https://en.wikipedia.org/wiki/NetworkManager +[4]:https://zwischenzugs.files.wordpress.com/2018/06/linux-dns-2-2.png?w=525 +[5]:https://github.com/imp/dnsmasq/blob/master/src/cache.c diff --git a/published/20180710 How To View Detailed Information About A Package In Linux.md b/published/20180710 How To View Detailed Information About A Package In Linux.md new file mode 100644 index 0000000000..8aa1121bae --- /dev/null +++ b/published/20180710 How To View Detailed Information About A Package In Linux.md @@ -0,0 +1,431 @@ + +如何在 Linux 上检查一个软件包的详细信息 +====== + +我们可以就这个已经被广泛讨论的话题写出大量的文章,大多数情况下,因为各种各样的原因,我们都愿意让包管理器package manager来帮我们做这些事情。 + +每个 Linux 发行版都有自己的包管理器,并且每个都有各自有不同的特性,这些特性包括允许用户执行安装新软件包,删除无用的软件包,更新现存的软件包,搜索某些具体的软件包,以及更新整个系统到其最新的状态之类的操作。 + +习惯于命令行的用户大多数时间都会使用基于命令行方式的包管理器。对于 Linux 而言,这些基于命令行的包管理器有 `yum`、`dnf`、`rpm`、`apt`、`apt-get`、`dpkg`、`pacman` 和 `zypper`。 + +**推荐阅读** + +- [Linux 命令行包管理器列表及其用法][1] +- [一个图形化的 Linux 包管理器前端工具][2] +- [如何搜索知道一个软件包是否存在于你的 Linux 发行版][3] +- [如何使用 dnf/yum 配置包管理器在 Linux 上来添加、启用和禁用软件仓库][4] + +作为一个系统管理员你应该清楚地知道:安装包来自何方,具体来自哪个软件仓库,包的具体版本,包的大小,版本,包的源代码 URL,包的许可证信息,等等。 + +这篇短文将用尽可能简单的方式帮你从随包自带的总结和描述中了解该包的用法。按你所使用的 Linux 发行版的不同,运行下面相应的命令,你能得到你所使用的发行版下的包的详细信息。 + +### YUM 命令:在 RHEL 和 CentOS 系统上获得包的信息 + +[YUM][5] 英文直译是“黄狗更新器--修改版Yellowdog Updater, Modified”,它是一个开源的基于命令行的包管理器前端实用工具。它被广泛应用在基于 RPM 的系统上,例如:RHEL 和 CentOS。 + +Yum 是用于在官方发行版仓库以及其他第三方发行版仓库下获取、安装、删除、查询 RPM 包的主要工具。 + +(LCTT 译注:用 `yum info` 获取 python 包的信息) + +``` +# yum info python +Loaded plugins: fastestmirror, security +Loading mirror speeds from cached hostfile + * epel: epel.mirror.constant.com +Installed Packages +Name : python +Arch : x86_64 +Version : 2.6.6 +Release : 66.el6_8 +Size : 78 k +Repo : installed +From repo : updates +Summary : An interpreted, interactive, object-oriented programming language +URL : http://www.python.org/ +License : Python +Description : Python is an interpreted, interactive, object-oriented programming + : language often compared to Tcl, Perl, Scheme or Java. Python includes + : modules, classes, exceptions, very high level dynamic data types and + : dynamic typing. Python supports interfaces to many system calls and + : libraries, as well as to various windowing systems (X11, Motif, Tk, + : Mac and MFC). + : + : Programmers can write new built-in modules for Python in C or C++. + : Python can be used as an extension language for applications that need + : a programmable interface. + : + : Note that documentation for Python is provided in the python-docs + : package. + : + : This package provides the "python" executable; most of the actual + : implementation is within the "python-libs" package. + +``` + +### YUMDB 命令:查看 RHEL 和 CentOS 系统上的包信息 + +`yumdb info` 这个命令提供与 `yum info` 相类似的的信息,不过它还额外提供了诸如包校验值、包类型、用户信息(由何人安装)。从 yum 3.2.26 版本后,`yum` 开始在 rpm 数据库外储存额外的信息了(此处如显示 `user` 表明该包由用户安装,而 `dep` 说明该包是被作为被依赖的包而被安装的)。 + +(LCTT 译注:用 `yumdb info` 来获取 python 包的信息) + +``` +# yumdb info python +Loaded plugins: fastestmirror +python-2.6.6-66.el6_8.x86_64 + changed_by = 4294967295 + checksum_data = 53c75a1756e5b4f6564c5229a37948c9b4561e0bf58076bd7dab7aff85a417f2 + checksum_type = sha256 + command_line = update -y + from_repo = updates + from_repo_revision = 1488370672 + from_repo_timestamp = 1488371100 + installed_by = 4294967295 + reason = dep + releasever = 6 +``` + +### RPM 命令:在 RHEL/CentOS/Fedora 系统上查看包的信息 + +[RPM][6] 英文直译为“红帽包管理器Red Hat Package Manager”,这是一个在 RedHat 以及其变种发行版(如RHEL、CentOS、Fedora、openSUSE、Megeia)下的功能强大的命令行包管理工具。它能让你轻松的安装、升级、删除、查询以及校验你的系统或服务器上的软件。RPM 文件以 `.rpm` 结尾。RPM 包由它所依赖的软件库以及其他依赖构成,它不会与系统上已经安装的包冲突。 + +(LCTT 译注:用 `rpm -qi` 查询 nano 包的具体信息) + +``` +# rpm -qi nano +Name : nano Relocations: (not relocatable) +Version : 2.0.9 Vendor: CentOS +Release : 7.el6 Build Date: Fri 12 Nov 2010 02:18:36 AM EST +Install Date: Fri 03 Mar 2017 08:57:47 AM EST Build Host: c5b2.bsys.dev.centos.org +Group : Applications/Editors Source RPM: nano-2.0.9-7.el6.src.rpm +Size : 1588347 License: GPLv3+ +Signature : RSA/8, Sun 03 Jul 2011 12:46:50 AM EDT, Key ID 0946fca2c105b9de +Packager : CentOS BuildSystem +URL : http://www.nano-editor.org +Summary : A small text editor +Description : +GNU nano is a small and friendly text editor. +``` + +### DNF 命令:在 Fedora 系统上查看包信息 + +[DNF][7] 指“时髦版的 YumDandified yum”,我们也可以认为 DNF 是下一代的 yum 包管理器(Yum 的一个分支),它在后台使用了 hawkey/libsolv 库。Aleš Kozumplík 在Fedora 18 上开始开发 DNF,在 Fedora 22 上正式最后发布。 `dnf` 命令用来在 Fedora 22 及以后的系统上安装、更新、搜索以及删除包。它能自动的解决包安装过程中的包依赖问题。 + +(LCTT 译注: 用 `dnf info` 查看 tilix 包信息) + +``` +$ dnf info tilix +Last metadata expiration check: 27 days, 10:00:23 ago on Wed 04 Oct 2017 06:43:27 AM IST. +Installed Packages +Name : tilix +Version : 1.6.4 +Release : 1.fc26 +Arch : x86_64 +Size : 3.6 M +Source : tilix-1.6.4-1.fc26.src.rpm +Repo : @System +From repo : @commandline +Summary : Tiling terminal emulator +URL : https://github.com/gnunn1/tilix +License : MPLv2.0 and GPLv3+ and CC-BY-SA +Description : Tilix is a tiling terminal emulator with the following features: + : + : - Layout terminals in any fashion by splitting them horizontally or vertically + : - Terminals can be re-arranged using drag and drop both within and between + : windows + : - Terminals can be detached into a new window via drag and drop + : - Input can be synchronized between terminals so commands typed in one + : terminal are replicated to the others + : - The grouping of terminals can be saved and loaded from disk + : - Terminals support custom titles + : - Color schemes are stored in files and custom color schemes can be created by + : simply creating a new file + : - Transparent background + : - Supports notifications when processes are completed out of view + : + : The application was written using GTK 3 and an effort was made to conform to + : GNOME Human Interface Guidelines (HIG). +``` + +### Zypper 命令:在 openSUSE 系统上查看包信息 + +[zypper][8] 是一个使用 libzypp 库的命令行包管理器。`zypper` 提供诸如软件仓库访问,安装依赖解决,软件包安装等等功能。 + +(LCTT 译注: 用 `zypper info` 查询 nano 包的信息) + +``` +$ zypper info nano + +Loading repository data... +Reading installed packages... + + +Information for package nano: +----------------------------- +Repository : Main Repository (OSS) +Name : nano +Version : 2.4.2-5.3 +Arch : x86_64 +Vendor : openSUSE +Installed Size : 1017.8 KiB +Installed : No +Status : not installed +Source package : nano-2.4.2-5.3.src +Summary : Pico editor clone with enhancements +Description : + GNU nano is a small and friendly text editor. It aims to emulate + the Pico text editor while also offering a few enhancements. +``` + +### Pacman 命令:在 ArchLinux 及 Manjaro 系统上查看包信息 + +[Pacman][9] 意即包管理器package manager实用工具。`pacman` 是一个用于安装、构建、删除、管理 Arch Linux 上包的命令行工具。它后端使用 libalpm(Arch Linux package Manager(ALPM)库)来完成所有功能。 + +(LCTT 译注: 用 `pacman -Qi` 来查询 bash 包信息) + +``` +$ pacman -Qi bash +Name : bash +Version : 4.4.012-2 +Description : The GNU Bourne Again shell +Architecture : x86_64 +URL : http://www.gnu.org/software/bash/bash.html +Licenses : GPL +Groups : base +Provides : sh +Depends On : readline>=7.0 glibc ncurses +Optional Deps : bash-completion: for tab completion +Required By : autoconf automake bison bzip2 ca-certificates-utils db + dhcpcd diffutils e2fsprogs fakeroot figlet findutils + flex freetype2 gawk gdbm gettext gmp grub gzip icu + iptables keyutils libgpg-error libksba libpcap libpng + libtool lvm2 m4 man-db mkinitcpio nano neofetch nspr + nss openresolv os-prober pacman pcre pcre2 shadow + systemd texinfo vte-common which xdg-user-dirs xdg-utils + xfsprogs xorg-mkfontdir xorg-xpr xz +Optional For : None +Conflicts With : None +Replaces : None +Installed Size : 7.13 MiB +Packager : Jan Alexander Steffens (heftig) +Build Date : Tue 14 Feb 2017 01:16:51 PM UTC +Install Date : Thu 24 Aug 2017 06:08:12 AM UTC +Install Reason : Explicitly installed +Install Script : No +Validated By : Signature +``` + +### apt-cache 命令:在 Debian/Ubuntu/Mint 系统上查看包信息 + +[apt-cache][10] 命令能显示 apt 内部数据库中的大量信息。这些信息是从 `sources.list` 中的不同的软件源中搜集而来,因此从某种意义上这些信息也可以被认为是某种缓存。这些信息搜集工作是在运行 `apt update` 命令时执行的。 + +(LCTT 译注:用管理员权限查询 apache2 包的信息) + +``` +$ sudo apt-cache show apache2 +Package: apache2 +Priority: optional +Section: web +Installed-Size: 473 +Maintainer: Ubuntu Developers +Original-Maintainer: Debian Apache Maintainers +Architecture: amd64 +Version: 2.4.12-2ubuntu2 +Replaces: apache2.2-common +Provides: httpd, httpd-cgi +Depends: lsb-base, procps, perl, mime-support, apache2-bin (= 2.4.12-2ubuntu2), apache2-utils (>= 2.4), apache2-data (= 2.4.12-2ubuntu2) +Pre-Depends: dpkg (>= 1.17.14) +Recommends: ssl-cert +Suggests: www-browser, apache2-doc, apache2-suexec-pristine | apache2-suexec-custom, ufw +Conflicts: apache2.2-common (<< 2.3~) +Filename: pool/main/a/apache2/apache2_2.4.12-2ubuntu2_amd64.deb +Size: 91348 +MD5sum: ab0ee0b0d1c6b3d19bd87aa2a9537125 +SHA1: 350c9a1a954906088ed032aebb77de3d5bb24004 +SHA256: 03f515f7ebc3b67b050b06e82ebca34b5e83e34a528868498fce020bf1dbbe34 +Description-en: Apache HTTP Server + The Apache HTTP Server Project's goal is to build a secure, efficient and + extensible HTTP server as standards-compliant open source software. The + result has long been the number one web server on the Internet. + . + Installing this package results in a full installation, including the + configuration files, init scripts and support scripts. +Description-md5: d02426bc360345e5acd45367716dc35c +Homepage: http://httpd.apache.org/ +Bugs: https://bugs.launchpad.net/ubuntu/+filebug +Origin: Ubuntu +Supported: 9m +Task: lamp-server, mythbuntu-frontend, mythbuntu-desktop, mythbuntu-backend-slave, mythbuntu-backend-master, mythbuntu-backend-master +``` + +### APT 命令:查看 Debian/Ubuntu/Mint 系统上的包信息 + +[APT][11] 意为高级打包工具Advanced Packaging Tool,就像 DNF 将如何替代 YUM 一样,APT 是 apt-get 的替代物。它功能丰富的命令行工具包括了如下所有命令的功能如 `apt-cache`、`apt-search`、`dpkg`、`apt-cdrom`、`apt-config`、`apt-key` 等等,我们可以方便的通过 `apt` 来安装 `.dpkg` 包,但是我们却不能通过 `apt-get` 来完成这一点,还有一些其他的类似的功能也不能用 `apt-get` 来完成,所以 `apt-get` 因为没有解决上述功能缺乏的原因而被 `apt` 所取代。 + +(LCTT 译注: 用 `apt show` 查看 nano 包信息) + +``` +$ apt show nano +Package: nano +Version: 2.8.6-3 +Priority: standard +Section: editors +Origin: Ubuntu +Maintainer: Ubuntu Developers +Original-Maintainer: Jordi Mallach +Bugs: https://bugs.launchpad.net/ubuntu/+filebug +Installed-Size: 766 kB +Depends: libc6 (>= 2.14), libncursesw5 (>= 6), libtinfo5 (>= 6) +Suggests: spell +Conflicts: pico +Breaks: nano-tiny (<< 2.8.6-2) +Replaces: nano-tiny (<< 2.8.6-2), pico +Homepage: https://www.nano-editor.org/ +Task: standard, ubuntu-touch-core, ubuntu-touch +Supported: 9m +Download-Size: 222 kB +APT-Manual-Installed: yes +APT-Sources: http://in.archive.ubuntu.com/ubuntu artful/main amd64 Packages +Description: small, friendly text editor inspired by Pico + GNU nano is an easy-to-use text editor originally designed as a replacement + for Pico, the ncurses-based editor from the non-free mailer package Pine + (itself now available under the Apache License as Alpine). + . + However, GNU nano also implements many features missing in pico, including: + - undo/redo + - line numbering + - syntax coloring + - soft-wrapping of overlong lines + - selecting text by holding Shift + - interactive search and replace (with regular expression support) + - a go-to line (and column) command + - support for multiple file buffers + - auto-indentation + - tab completion of filenames and search terms + - toggling features while running + - and full internationalization support +``` + +### dpkg 命令:查看Debian/Ubuntu/Mint系统上的包信息 + + +[dpkg][12] 意指 Debian 包管理器Debian package manager。`dpkg` 是用于 Debian 系统上安装、构建、移除以及管理 Debian 包的命令行工具。`dpkg` 使用 `aptitude`(因为它更为主流及用户友好)作为前端工具来完成所有的功能。其他的工具如` dpkg-deb` 和 `dpkg-query` 使用 `dpkg` 做为前端来实现功能。尽管系统管理员还是时不时会在必要时使用 `dpkg` 来完成一些软件安装的任务,他大多数情况下还是会因为 `apt`、`apt-get` 以及 `aptitude` 的健壮性而使用后者。 + +(LCTT 译注: 用 `dpkg -s` 查看 python 包的信息) + +``` +$ dpkg -s python +Package: python +Status: install ok installed +Priority: optional +Section: python +Installed-Size: 626 +Maintainer: Ubuntu Developers +Architecture: amd64 +Multi-Arch: allowed +Source: python-defaults +Version: 2.7.14-2ubuntu1 +Replaces: python-dev (<< 2.6.5-2) +Provides: python-ctypes, python-email, python-importlib, python-profiler, python-wsgiref +Depends: python2.7 (>= 2.7.14-1~), libpython-stdlib (= 2.7.14-2ubuntu1) +Pre-Depends: python-minimal (= 2.7.14-2ubuntu1) +Suggests: python-doc (= 2.7.14-2ubuntu1), python-tk (>= 2.7.14-1~) +Breaks: update-manager-core (<< 0.200.5-2) +Conflicts: python-central (<< 0.5.5) +Description: interactive high-level object-oriented language (default version) + Python, the high-level, interactive object oriented language, + includes an extensive class library with lots of goodies for + network programming, system administration, sounds and graphics. + . + This package is a dependency package, which depends on Debian's default + Python version (currently v2.7). +Homepage: http://www.python.org/ +Original-Maintainer: Matthias Klose +``` + +我们也可使用 `dpkg` 的 `-p` 选项,这个选项提供和 `dpkg -s` 相类似的信息,但是它还提供了包的校验值和包类型。 + +(LCTT 译注: 用 `dpkg -p` 查看 python3 包的信息) + +``` +$ dpkg -p python3 +Package: python3 +Priority: important +Section: python +Installed-Size: 67 +Origin: Ubuntu +Maintainer: Ubuntu Developers +Bugs: https://bugs.launchpad.net/ubuntu/+filebug +Architecture: amd64 +Multi-Arch: allowed +Source: python3-defaults +Version: 3.6.3-0ubuntu2 +Replaces: python3-minimal (<< 3.1.2-2) +Provides: python3-profiler +Depends: python3.6 (>= 3.6.3-1~), libpython3-stdlib (= 3.6.3-0ubuntu2), dh-python +Pre-Depends: python3-minimal (= 3.6.3-0ubuntu2) +Suggests: python3-doc (>= 3.6.3-0ubuntu2), python3-tk (>= 3.6.3-1~), python3-venv (>= 3.6.3-0ubuntu2) +Filename: pool/main/p/python3-defaults/python3_3.6.3-0ubuntu2_amd64.deb +Size: 8712 +MD5sum: a8bae494c6e5d1896287675faf40d373 +Description: interactive high-level object-oriented language (default python3 version) +Original-Maintainer: Matthias Klose +SHA1: 2daec885cea7d4dc83c284301c3bebf42b23e095 +SHA256: 865e509c91d2504a16c4b573dbe27e260c36fceec2add3fa43a30c1751d7e9bb +Homepage: http://www.python.org/ +Task: minimal, ubuntu-core, ubuntu-core +Description-md5: 950ebd8122c0a7340f0a740c295b9eab +Supported: 9m +``` + +### aptitude 命令:查看 Debian/Ubuntu/Mint 系统上的包信息 + + +`aptitude` 是 Debian GNU/Linux 包管理系统的文本界面。它允许用户查看已安装的包的列表,以及完成诸如安装、升级、删除包之类的包管理任务。这些管理行为也能从图形接口来执行。 + +(LCTT 译注: 用 `aptitude show` 查看 htop 包信息) + +``` +$ aptitude show htop +Package: htop +Version: 2.0.2-1 +State: installed +Automatically installed: no +Priority: optional +Section: universe/utils +Maintainer: Ubuntu Developers +Architecture: amd64 +Uncompressed Size: 216 k +Depends: libc6 (>= 2.15), libncursesw5 (>= 6), libtinfo5 (>= 6) +Suggests: lsof, strace +Conflicts: htop:i386 +Description: interactive processes viewer + Htop is an ncursed-based process viewer similar to top, but it allows one to scroll the list vertically and horizontally to see all processes and their full command lines. + + Tasks related to processes (killing, renicing) can be done without entering their PIDs. +Homepage: http://hisham.hm/htop/ +``` + +-------------------------------------------------------------------------------- + +via: https://www.2daygeek.com/how-to-view-detailed-information-about-a-package-in-linux/ + +作者:[Prakash Subramanian][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[DavidChenLiang](https://github.com/davidchenliang) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.2daygeek.com/author/prakash/ +[1]:https://www.2daygeek.com/list-of-command-line-package-manager-for-linux/ +[2]:https://www.2daygeek.com/list-of-graphical-frontend-tool-for-linux-package-manager/ +[3]:https://www.2daygeek.com/how-to-search-if-a-package-is-available-on-your-linux-distribution-or-not/ +[4]:https://www.2daygeek.com/how-to-add-enable-disable-a-repository-dnf-yum-config-manager-on-linux/ +[5]:https://www.2daygeek.com/yum-command-examples-manage-packages-rhel-centos-systems/ +[6]:https://www.2daygeek.com/rpm-command-examples/ +[7]:https://www.2daygeek.com/dnf-command-examples-manage-packages-fedora-system/ +[8]:https://www.2daygeek.com/zypper-command-examples-manage-packages-opensuse-system/ +[9]:https://www.2daygeek.com/pacman-command-examples-manage-packages-arch-linux-system/ +[10]:https://www.2daygeek.com/apt-get-apt-cache-command-examples-manage-packages-debian-ubuntu-systems/ +[11]:https://www.2daygeek.com/apt-command-examples-manage-packages-debian-ubuntu-systems/ +[12]:https://www.2daygeek.com/dpkg-command-to-manage-packages-on-debian-ubuntu-linux-mint-systems/ diff --git a/published/20180717 Getting started with Etcher.io.md b/published/20180717 Getting started with Etcher.io.md new file mode 100644 index 0000000000..4cfc89741a --- /dev/null +++ b/published/20180717 Getting started with Etcher.io.md @@ -0,0 +1,91 @@ +Etcher.io 入门 +====== +> 用这个易用的媒体创建工具来创建一个可引导的 USB 盘或 SD 卡。 + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/community-penguins-osdc-lead.png?itok=BmqsAF4A) + +可启动 USB 盘是尝试新的 Linux 发行版的很好的方式,以便在安装之前查看你是否喜欢它。虽然一些 Linux 发行版(如 [Fedora][1])可以轻松创建可启动媒体,但大多数其他发行版提供 ISO 或镜像文件,并将创建媒体决定留给用户。用户总是可以选择使用 `dd` 在命令行上创建媒体——但让我们面对现实,即使对于最有经验的用户来说,这仍然很痛苦。也有一些其它程序,如 Mac 上的 UnetBootIn、Disk Utility 和 Windows 上的 Win32DiskImager,它们都可以创建可启动的 USB。 + +### 安装 Etcher + +大约 18 个月前,我遇到了 [Etcher.io][2],这是一个很棒的开源项目,可以在 Linux、Windows 或 MacOS 上轻松、简单地创建媒体。Etcher.io 已成为我为 Linux 创建可启动媒体的“首选”程序。我可以轻松下载 ISO 或 IMG 文件并将其刻录到闪存和 SD 卡。这是一个 [Apache 2.0][3] 许可证下的开源项目,[源代码][4] 可在 GitHub 上获得。 + +进入 [Etcher.io][5] 网站,然后单击适用于你的操作系统:32 位或 64 位 Linux、32 位或 64 位 Windows 或 MacOS 的下载链接。 + +![](https://opensource.com/sites/default/files/uploads/etcher_1.png) + +Etcher 在 GitHub 仓库中提供了很好的指导,可以将 Etcher 添加到你的 Linux 实用程序集合中。 + +如果你使用的是 Debian 或 Ubuntu,请添加 Etcher Debian 仓库: + +``` +$echo "deb https://dl.bintray.com/resin-io/debian stable etcher" | sudo tee /etc/apt/sources.list.d/etcher.list +``` + +信任 Bintray.com GPG 密钥 + +``` +$ sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 379CE192D401AB61 +``` + +然后更新你的系统并安装: + +``` +$ sudo apt-get update +$ sudo apt-get install etcher-electron +``` + +如果你使用的是 Fedora 或 Red Hat Enterprise Linux,请添加 Etcher RPM 仓库: + +``` +$ sudo wget https://bintray.com/resin-io/redhat/rpm -O /etc/yum.repos.d/bintray-resin-io-redhat.repo +``` + +使用以下任一方式更新和安装: + +``` +$ sudo yum install -y etcher-electron +``` + +或者: + +``` +$ sudo dnf install -y etcher-electron +``` + +### 创建可启动盘 + +除了为 Ubuntu、EndlessOS 和其他版本的 Linux 创建可启动镜像之外,我还使用 Etcher [创建 SD 卡镜像][6]用于树莓派。以下是如何创建可启动媒体。 + +首先,将要使用的 ISO 或镜像下载到计算机。然后,启动 Etcher 并将 USB 或 SD 卡插入计算机。 + +![](https://opensource.com/sites/default/files/uploads/etcher_2.png) + +单击 “Select Image”。在本例中,我想创建一个可启动的 USB 盘,以便在新计算机上安装 Ubermix。在我选择了我的 Ubermix 镜像文件并将我的 USB 盘插入计算机,Etcher.io “看到”了驱动器,我就可以开始在 USB 上安装 Ubermix 了。 + +![](https://opensource.com/sites/default/files/uploads/etcher_3.png) + +在我点击 “Flash” 后,安装就开始了。所需时间取决于镜像的大小。在驱动器上安装镜像后,软件会验证安装。最后,一条提示宣布我的媒体创建已经完成。 + +如果您需要 [Etcher 的帮助][7],请通过其 [Discourse][8] 论坛联系社区。Etcher 非常易于使用,它已经取代了我所有其他的媒体创建工具,因为它们都不像 Etcher 那样轻松地完成工作。 + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/7/getting-started-etcherio + +作者:[Don Watkins][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[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/don-watkins +[1]:https://getfedora.org/en_GB/workstation/download/ +[2]:http://etcher.io +[3]:https://github.com/resin-io/etcher/blob/master/LICENSE +[4]:https://github.com/resin-io/etcher +[5]:https://etcher.io/ +[6]:https://www.raspberrypi.org/magpi/pi-sd-etcher/ +[7]:https://github.com/resin-io/etcher/blob/master/SUPPORT.md +[8]:https://forums.resin.io/c/etcher diff --git a/published/20180720 An Introduction to Using Git.md b/published/20180720 An Introduction to Using Git.md new file mode 100644 index 0000000000..f159653403 --- /dev/null +++ b/published/20180720 An Introduction to Using Git.md @@ -0,0 +1,174 @@ +Git 使用简介 +====== +> 我将向你介绍让 Git 的启动、运行,并和 GitHub 一起使用的基础知识。 + +![](https://www.linux.com/sites/lcom/files/styles/rendered_file/public/developer-3461405_1920.png?itok=6H3sYe80) + +如果你是一个开发者,那你应该熟悉许多开发工具。你已经花了多年时间来学习一种或者多种编程语言并打磨你的技巧。你可以熟练运用图形工具或者命令行工具开发。在你看来,没有任何事可以阻挡你。你的代码, 好像你的思想和你的手指一样,将会创建一个优雅的,完美评价的应用程序,并会风靡世界。 + +然而,如果你和其他人共同开发一个项目会发生什么呢?或者,你开发的应用程序变地越来越大,下一步你将如何去做?如果你想成功地和其他开发者合作,你定会想用一个分布式版本控制系统。使用这样一个系统,合作开发一个项目变得非常高效和可靠。这样的一个系统便是 [Git][1]。还有一个叫 [GitHub][2] 的方便的存储仓库,用来存储你的项目代码,这样你的团队可以检查和修改代码。 + +我将向你介绍让 Git 的启动、运行,并和 GitHub 一起使用的基础知识,可以让你的应用程序的开发可以提升到一个新的水平。我将在 Ubuntu 18.04 上进行演示,因此如果您选择的发行版本不同,您只需要修改 Git 安装命令以适合你的发行版的软件包管理器。 + +### Git 和 GitHub + +第一件事就是创建一个免费的 GitHub 账号,打开 [GitHub 注册页面][3],然后填上需要的信息。完成这个之后,你就注备好开始安装 Git 了(这两件事谁先谁后都可以)。 + +安装 Git 非常简单,打开一个命令行终端,并输入命令: + +``` +sudo apt install git-all +``` + +这将会安装大量依赖包,但是你将了解使用 Git 和 GitHub 所需的一切。 + +附注:我使用 Git 来下载程序的安装源码。有许多时候,内置的软件管理器不提供某个软件,除了去第三方库中下载源码,我经常去这个软件项目的 Git 主页,像这样克隆: + +``` +git clone ADDRESS +``` + +“ADDRESS” 就是那个软件项目的 Git 主页。这样我就可以确保自己安装那个软件的最新发行版了。 + +### 创建一个本地仓库并添加一个文件 + +下一步就是在你的电脑里创建一个本地仓库(本文称之为 newproject,位于 `~/` 目录下),打开一个命令行终端,并输入下面的命令: + +``` +cd ~/ +mkdir newproject +cd newproject +``` + +现在你需要初始化这个仓库。在 `~/newproject` 目录下,输入命令 `git init`,当命令运行完,你就可以看到一个刚刚创建的空的 Git 仓库了(图1)。 + +![new repository][5] + +*图 1: 初始化完成的新仓库* + +下一步就是往项目里添加文件。我们在项目根目录(`~/newproject`)输入下面的命令: + +``` +touch readme.txt +``` + +现在项目里多了个空文件。输入 `git status` 来验证 Git 已经检测到多了个新文件(图2)。 + +![readme][8] + +*图 2: Git 检测到新文件readme.txt* + +即使 Git 检测到新的文件,但它并没有被真正的加入这个项目仓库。为此,你要输入下面的命令: + +``` +git add readme.txt +``` + +一旦完成这个命令,再输入 `git status` 命令,可以看到,`readme.txt` 已经是这个项目里的新文件了(图3)。 + +![file added][10] + +*图 3: 我们的文件已经被添加进临时环境* + +### 第一次提交 + +当新文件添加进临时环境之后,我们现在就准备好创建第一个提交commit了。什么是提交呢?简单的说,一个提交就是你更改的项目的文件的记录。创建一个提交也是非常简单的。但是,为提交包含一个描述信息非常重要。通过这样做,你可以添加有关该提交包含的内容的注释,比如你对文件做出的何种修改。然而,在这样做之前,我们需要告知 Git 我们的账户,输入以下命令: + +``` +git config --global user.email EMAIL +git config --global user.name “FULL NAME” +``` + +“EMAIL” 即你的 email 地址,“FULL NAME” 则是你的姓名。 + +现在你可以通过以下命令创建一个提交: + +``` +git commit -m “Descriptive Message” +``` + +“Descriptive Message” 即为你的提交的描述性信息。比如,当你第一个提交是提交一个 `readme.txt` 文件,你可以这样提交: + +``` +git commit -m “First draft of readme.txt file” +``` + +你可以看到输出表明一个文件已经修改,并且,为 `readme.txt` 创建了一个新的文件模式(图4) + +![success][12] + +*图4:提交成功* + + +### 创建分支并推送至 GitHub + +分支是很重要的,它允许你在项目状态间中移动。假如,你想给你的应用创建一个新的特性。为了这样做,你创建了个新分支。一旦你完成你的新特性,你可以把这个新分支合并到你的主分支中去,使用以下命令创建一个新分支: + +``` +git checkout -b BRANCH +``` + +“BRANCH” 即为你新分支的名字,一旦执行完命令,输入 `git branch` 命令来查看是否创建了新分支(图5) + +![featureX][14] + +*图5:名为 featureX 的新分支* + +接下来,我们需要在 GitHub 上创建一个仓库。 登录 GitHub 帐户,请单击帐户主页上的“New Repository”按钮。 填写必要的信息,然后单击 “Create repository”(图6)。 + +![new repository][16] + +*图6:在 GitHub 上新建一个仓库* + +在创建完一个仓库之后,你可以看到一个用于推送本地仓库的地址。若要推送,返回命令行窗口(`~/newproject` 目录中),输入以下命令: + +``` +git remote add origin URL +git push -u origin master +``` + +“URL” 即为我们 GitHub 上新建的仓库地址。 + +系统会提示您,输入 GitHub 的用户名和密码,一旦授权成功,你的项目将会被推送到 GitHub 仓库中。 + +### 拉取项目 + +如果你的同事改变了你们 GitHub 上项目的代码,并且已经合并那些更改,你可以拉取那些项目文件到你的本地机器,这样,你系统中的文件就可以和远程用户的文件保持匹配。你可以输入以下命令来做这件事(`~/newproject` 在目录中), + +``` +git pull origin master +``` + +以上的命令可以拉取任何新文件或修改过的文件到你的本地仓库。 + +### 基础 + +这就是从命令行使用 Git 来处理存储在 GitHub 上的项目的基础知识。 还有很多东西需要学习,所以我强烈建议你使用 `man git`,`man git-push` 和 `man git-pull` 命令来更深入地了解 `git` 命令可以做什么。 + +开发快乐! + +了解更多关于 Linux 的 内容,请访问来自 Linux 基金会和 edX 的免费的 ["Introduction to Linux"][17]课程。 + +-------------------------------------------------------------------------------- + +via: https://www.linux.com/learn/intro-to-linux/2018/7/introduction-using-git + +作者:[Jack Wallen][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[distant1219](https://github.com/distant1219) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.linux.com/users/jlwallen +[1]:https://git-scm.com/ +[2]:https://github.com/ +[3]:https://github.com/join?source=header-home +[5]:https://www.linux.com/sites/lcom/files/styles/rendered_file/public/git_1.jpg?itok=FKkr5Mrk (new repository) +[6]:https://www.linux.com/licenses/category/used-permission +[8]:https://www.linux.com/sites/lcom/files/styles/rendered_file/public/git_2.jpg?itok=54G9KBHS (readme) +[10]:https://www.linux.com/sites/lcom/files/styles/rendered_file/public/git_3.jpg?itok=KAJwRJIB (file added) +[12]:https://www.linux.com/sites/lcom/files/styles/rendered_file/public/git_4.jpg?itok=qR0ighDz (success) +[14]:https://www.linux.com/sites/lcom/files/styles/rendered_file/public/git_5.jpg?itok=6m9RTWg6 (featureX) +[16]:https://www.linux.com/sites/lcom/files/styles/rendered_file/public/git_6.jpg?itok=d2toRrUq (new repository) +[17]:https://training.linuxfoundation.org/linux-courses/system-administration-training/introduction-to-linux diff --git a/published/20180720 How to Install 2048 Game in Ubuntu and Other Linux Distributions.md b/published/20180720 How to Install 2048 Game in Ubuntu and Other Linux Distributions.md new file mode 100644 index 0000000000..35228c9f36 --- /dev/null +++ b/published/20180720 How to Install 2048 Game in Ubuntu and Other Linux Distributions.md @@ -0,0 +1,91 @@ +如何在 Linux 中安装 2048 游戏 +====== + +> 流行的移动益智游戏 2048 也可以在 Ubuntu 和 Linux 发行版上玩。啊!你甚至可以在 Linux 终端上玩 2048。如果你的生产率因为这个让人上瘾的游戏下降,请不要怪我。 + +早在 2014 年,2048 就是 iOS 和 Android 上最受欢迎的游戏之一。这款令人上瘾的游戏非常受欢迎,它在 Linux 上有[浏览器版][1]、桌面版和终端版。 + +![](https://media.giphy.com/media/wT8XEi5gckwJW/giphy.gif) + +通过向上和向下,向左和向右移动滑块来玩这个小游戏。这个益智游戏的目的是通过组合匹配的滑块到数字 2048。因此 2+2 变成 4,4+4 变成 16,依此类推。这可能听起来简单而无聊,但相信我是一个令人上瘾的游戏。 + +### 在 Linux 中玩 2048 [GUI] + +在 Ubuntu 和其他 Linux 中有些 2048 游戏。你可以在软件中心中搜索它,你可以在那里找到一些。 + +有一个[基于 Qt ][2]的 2048 游戏,你可以在 Ubuntu 和其他基于 Debian 和 Ubuntu 的 Linux 发行版上安装。你可以使用以下命令安装它: + +``` +sudo apt install 2048-qt +``` + +安装完成后,你可以在菜单中找到该游戏并启动它。你可以使用箭头键移动数字。你的最高分也会保存。 + +![2048 Game in Ubuntu Linux][3] + +### 在 Linux 终端玩 2048 + +2048 的流行将它带到了终端。如果这让你感到惊讶,你应该知道 Linux 中有很多[很棒的终端游戏][4],而 2048 肯定就是其中之一。 + +现在,有几种方法可以在 Linux 终端中玩 2048。我在这里提其中两个。 + +#### 1、term2048 Snap 程序 + +有一个名为 [term2048][6] 的 [snap 程序][5]可以安装在任何[支持 Snap 的 Linux 发行版][7]中。 + +如果你启用了 Snap,只需使用此命令安装 term2048: + +``` +sudo snap install term2048 +``` + +Ubuntu 用户也可以在软件中心找到这个游戏并从那里安装它。 + +![2048 Terminal Game in Linux][8] + +安装后,你可以使用命令 term2048 来运行游戏。它看起来像这样: + +![2048 Terminal game][9] + +你可以使用箭头键移动。 + +#### 2、2048 游戏的 Bash 脚本 + +这个游戏实际上是一个 shell 脚本,你可以在任何 Linux 终端上运行。从 Github 下载游戏/脚本: + +- [下载 Bash2048][10] + +解压下载的文件。进入解压后的目录,你将看到名为 2048.sh 的 shell 脚本。只需运行 shell 脚本。游戏将立即开始。你可以使用箭头键移动滑块。 + +![Linux Terminal game 2048][11] + +### 你在Linux上玩什么游戏? + +如果你喜欢在 Linux 终端上玩游戏,你也应该尝试 [Linux 终端中的经典 Snake 游戏][12]。 + +你经常在 Linux 中玩哪些游戏?你也在终端中玩游戏吗?如果是的话,哪个是你最喜欢的终端游戏? + +-------------------------------------------------------------------------------- + +via: https://itsfoss.com/2048-game/ + +作者:[Abhishek Prakash][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[geekpi](https://github.com/geekpi) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://itsfoss.com/author/abhishek/ +[1]:http://gabrielecirulli.github.io/2048/ +[2]:https://www.qt.io/ +[3]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/07/2048-qt-ubuntu.jpeg +[4]:https://itsfoss.com/best-command-line-games-linux/ +[5]:https://itsfoss.com/use-snap-packages-ubuntu-16-04/ +[6]:https://snapcraft.io/term2048 +[7]:https://itsfoss.com/install-snap-linux/ +[8]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/07/term2048-game.png +[9]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/07/term2048.jpg +[10]:https://github.com/mydzor/bash2048 +[11]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/07/2048-bash-terminal.png +[12]:https://itsfoss.com/nsnake-play-classic-snake-game-linux-terminal/ (nSnake: Play The Classic Snake Game In Linux Terminal) diff --git a/published/20180720 How to build a URL shortener with Apache.md b/published/20180720 How to build a URL shortener with Apache.md new file mode 100644 index 0000000000..8fc2d473d1 --- /dev/null +++ b/published/20180720 How to build a URL shortener with Apache.md @@ -0,0 +1,77 @@ +如何使用 Apache 构建 URL 缩短服务 +====== +> 用 Apache HTTP 服务器的 mod_rewrite 功能创建你自己的短链接。 + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/openweb-osdc-lead.png?itok=yjU4KliG) + +很久以前,人们开始在 Twitter 上分享链接。140 个字符的限制意味着 URL 可能消耗一条推文的大部分(或全部),因此人们使用 URL 缩短服务。最终,Twitter 加入了一个内置的 URL 缩短服务([t.co][1])。 + +字符数现在不重要了,但还有其他原因要缩短链接。首先,缩短服务可以提供分析功能 —— 你可以看到你分享的链接的受欢迎程度。它还简化了制作易于记忆的 URL。例如,[bit.ly/INtravel][2] 比更容易记住。如果你想预先共享一个链接,但还不知道最终地址,这时 URL 缩短服务可以派上用场。。 + +与任何技术一样,URL 缩短服务并非都是正面的。通过屏蔽最终地址,缩短的链接可用于指向恶意或冒犯性内容。但是,如果你仔细上网,URL 缩短服务是一个有用的工具。 + +我们之前在网站上[发布过缩短服务的文章][3],但也许你想要运行一些由简单的文本文件支持的缩短服务。在本文中,我们将展示如何使用 Apache HTTP 服务器的 mod_rewrite 功能来设置自己的 URL 缩短服务。如果你不熟悉 Apache HTTP 服务器,请查看 David Both 关于[安装和配置][4]它的文章。 + +### 创建一个 VirtualHost + +在本教程中,我假设你购买了一个很酷的域名,你将它专门用于 URL 缩短服务。例如,我的网站是 [funnelfiasco.com][5],所以我买了 [funnelfias.co][6] 用于我的 URL 缩短服务(好吧,它不是很短,但它可以满足我的虚荣心)。如果你不将缩短服务作为单独的域运行,请跳到下一部分。 + +第一步是设置将用于 URL 缩短服务的 VirtualHost。有关 VirtualHost 的更多信息,请参阅 [David Both 的文章][7]。这步只需要几行: + +``` +    +        ServerName funnelfias.co +    +``` + +### 创建重写规则 + +此服务使用 HTTPD 的重写引擎来重写 URL。如果你在上面的部分中创建了 VirtualHost,则下面的配置跳到你的 VirtualHost 部分。否则跳到服务器的 VirtualHost 或主 HTTPD 配置。 + +``` +    RewriteEngine on +    RewriteMap shortlinks txt:/data/web/shortlink/links.txt +    RewriteRule ^/(.+)$ ${shortlinks:$1} [R=temp,L] +``` + +第一行只是启用重写引擎。第二行在文本文件构建短链接的映射。上面的路径只是一个例子。你需要使用系统上使用有效路径(确保它可由运行 HTTPD 的用户帐户读取)。最后一行重写 URL。在此例中,它接受任何字符并在重写映射中查找它们。你可能希望重写时使用特定的字符串。例如,如果你希望所有缩短的链接都是 “slX”(其中 X 是数字),则将上面的 `(.+)` 替换为 `(sl\d+)`。 + +我在这里使用了临时重定向(HTTP 302)。这能让我稍后更新目标 URL。如果希望短链接始终指向同一目标,则可以使用永久重定向(HTTP 301)。用 `permanent` 替换第三行的 `temp`。 + +### 构建你的映射 + +编辑配置文件 `RewriteMap` 行中的指定文件。格式是空格分隔的键值存储。在每一行上放一个链接: + +``` +    osdc https://opensource.com/users/bcotton +    twitter https://twitter.com/funnelfiasco +    swody1 https://www.spc.noaa.gov/products/outlook/day1otlk.html +``` + +### 重启 HTTPD + +最后一步是重启 HTTPD 进程。这是通过 `systemctl restart httpd` 或类似命令完成的(命令和守护进程名称可能因发行版而不同)。你的链接缩短服务现已启动并运行。当你准备编辑映射时,无需重新启动 Web 服务器。你所要做的就是保存文件,Web 服务器将获取到差异。 + +### 未来的工作 + +此示例为你提供了基本的 URL 缩短服务。如果你想将开发自己的管理接口作为学习项目,它可以作为一个很好的起点。或者你可以使用它分享容易记住的链接到那些容易忘记的 URL。 + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/7/apache-url-shortener + +作者:[Ben Cotton][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[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/bcotton +[1]:http://t.co +[2]:http://bit.ly/INtravel +[3]:https://opensource.com/article/17/3/url-link-shortener +[4]:https://opensource.com/article/18/2/how-configure-apache-web-server +[5]:http://funnelfiasco.com +[6]:http://funnelfias.co +[7]:https://opensource.com/article/18/3/configuring-multiple-web-sites-apache diff --git a/published/20180725 How do private keys work in PKI and cryptography.md b/published/20180725 How do private keys work in PKI and cryptography.md new file mode 100644 index 0000000000..e52e7282a7 --- /dev/null +++ b/published/20180725 How do private keys work in PKI and cryptography.md @@ -0,0 +1,102 @@ +公钥基础设施和密码学中的私钥的角色 +====== +> 了解如何验证某人所声称的身份。 + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/security_privacy_lock.png?itok=ZWjrpFzx) + +在[上一篇文章][1]中,我们概述了密码学并讨论了密码学的核心概念:保密性confidentiality (让数据保密)、完整性integrity (防止数据被篡改)和身份认证authentication (确认数据源的身份identity)。由于要在存在各种身份混乱的现实世界中完成身份认证,人们逐渐建立起一个复杂的技术生态体系technological ecosystem,用于证明某人就是其声称的那个人。在本文中,我们将大致介绍这些体系是如何工作的。 + +### 快速回顾公钥密码学及数字签名 + +互联网世界中的身份认证依赖于公钥密码学,其中密钥分为两部分:拥有者需要保密的私钥和可以对外公开的公钥。经过公钥加密过的数据,只能用对应的私钥解密。举个例子,对于希望与[记者][2]建立联系的举报人来说,这个特性非常有用。但就本文介绍的内容而言,私钥更重要的用途是与一个消息一起创建一个数字签名digital signature,用于提供完整性和身份认证。 + +在实际应用中,我们签名的并不是真实消息,而是经过密码学哈希函数cryptographic hash function处理过的消息摘要digest。要发送一个包含源代码的压缩文件,发送者会对该压缩文件的 256 比特长度的 [SHA-256][3] 摘要进行签名,而不是文件本身进行签名,然后用明文发送该压缩包(和签名)。接收者会独立计算收到文件的 SHA-256 摘要,然后结合该摘要、收到的签名及发送者的公钥,使用签名验证算法进行验证。验证过程取决于加密算法,加密算法不同,验证过程也相应不同;而且,很微妙的是签名验证[漏洞][4]依然[层出不穷][5]。如果签名验证通过,说明文件在传输过程中没有被篡改而且来自于发送者,这是因为只有发送者拥有创建签名所需的私钥。 + +### 方案中缺失的环节 + +上述方案中缺失了一个重要的环节:我们从哪里获得发送者的公钥?发送者可以将公钥与消息一起发送,但除了发送者的自我宣称,我们无法核验其身份。假设你是一名银行柜员,一名顾客走过来向你说,“你好,我是 Jane Doe,我要取一笔钱”。当你要求其证明身份时,她指着衬衫上贴着的姓名标签说道,“看,Jane Doe!”。如果我是这个柜员,我会礼貌的拒绝她的请求。 + +如果你认识发送者,你们可以私下见面并彼此交换公钥。如果你并不认识发送者,你们可以私下见面,检查对方的证件,确认真实性后接受对方的公钥。为提高流程效率,你可以举办[聚会][6]并邀请一堆人,检查他们的证件,然后接受他们的公钥。此外,如果你认识并信任 Jane Doe(尽管她在银行的表现比较反常),Jane 可以参加聚会,收集大家的公钥然后交给你。事实上,Jane 可以使用她自己的私钥对这些公钥(及对应的身份信息)进行签名,进而你可以从一个[线上密钥库][7]获取公钥(及对应的身份信息)并信任已被 Jane 签名的那部分。如果一个人的公钥被很多你信任的人(即使你并不认识他们)签名,你也可能选择信任这个人。按照这种方式,你可以建立一个[信任网络][8]Web of Trust。 + +但事情也变得更加复杂:我们需要建立一种标准的编码机制,可以将公钥和其对应的身份信息编码成一个数字捆绑digital bundle,以便我们进一步进行签名。更准确的说,这类数字捆绑被称为证书cerificate。我们还需要可以创建、使用和管理这些证书的工具链。满足诸如此类的各种需求的方案构成了公钥基础设施public key infrastructure(PKI)。 + +### 比信任网络更进一步 + +你可以用人际关系网类比信任网络。如果人们之间广泛互信,可以很容易找到(两个人之间的)一条短信任链short path of trust:就像一个社交圈。基于 [GPG][9] 加密的邮件依赖于信任网络,([理论上][10])只适用于与少量朋友、家庭或同事进行联系的情形。 + +(LCTT 译注:作者提到的“短信任链”应该是暗示“六度空间理论”,即任意两个陌生人之间所间隔的人一般不会超过 6 个。对 GPG 的唱衰,一方面是因为密钥管理的复杂性没有改善,另一方面 Yahoo 和 Google 都提出了更便利的端到端加密方案。) + +在实际应用中,信任网络有一些“[硬伤][11]significant problems”,主要是在可扩展性方面。当网络规模逐渐增大或者人们之间的连接较少时,信任网络就会慢慢失效。如果信任链逐渐变长,信任链中某人有意或无意误签证书的几率也会逐渐增大。如果信任链不存在,你不得不自己创建一条信任链,与其它组织建立联系,验证它们的密钥以符合你的要求。考虑下面的场景,你和你的朋友要访问一个从未使用过的在线商店。你首先需要核验网站所用的公钥属于其对应的公司而不是伪造者,进而建立安全通信信道,最后完成下订单操作。核验公钥的方法包括去实体店、打电话等,都比较麻烦。这样会导致在线购物变得不那么便利(或者说不那么安全,毕竟很多人会图省事,不去核验密钥)。 + +如果世界上有那么几个格外值得信任的人,他们专门负责核验和签发网站证书,情况会怎样呢?你可以只信任他们,那么浏览互联网也会变得更加容易。整体来看,这就是当今互联网的工作方式。那些“格外值得信任的人”就是被称为证书颁发机构cerificate authoritie(CA)的公司。当网站希望获得公钥签名时,只需向 CA 提交证书签名请求certificate signing request(CSR)。 + +CSR 类似于包括公钥和身份信息(在本例中,即服务器的主机名)的存根stub证书,但 CA 并不会直接对 CSR 本身进行签名。CA 在签名之前会进行一些验证。对于一些证书类型(LCTT 译注:域名证实Domain Validated(DV) 类型),CA 只验证申请者的确是 CSR 中列出主机名对应域名的控制者(例如通过邮件验证,让申请者完成指定的域名解析)。[对于另一些证书类型][12] (LCTT 译注:链接中提到扩展证实Extended Validated(EV)类型,其实还有 OVOrganization Validated 类型),CA 还会检查相关法律文书,例如公司营业执照等。一旦验证完成,CA(一般在申请者付费后)会从 CSR 中取出数据(即公钥和身份信息),使用 CA 自己的私钥进行签名,创建一个(签名)证书并发送给申请者。申请者将该证书部署在网站服务器上,当用户使用 HTTPS (或其它基于 [TLS][13] 加密的协议)与服务器通信时,该证书被分发给用户。 + +当用户访问该网站时,浏览器获取该证书,接着检查证书中的主机名是否与当前正在连接的网站一致(下文会详细说明),核验 CA 签名有效性。如果其中一步验证不通过,浏览器会给出安全警告并切断与网站的连接。反之,如果验证通过,浏览器会使用证书中的公钥来核验该服务器发送的签名信息,确认该服务器持有该证书的私钥。有几种算法用于协商后续通信用到的共享密钥shared secret key,其中一种也用到了服务器发送的签名信息。密钥交换key exchange算法不在本文的讨论范围,可以参考这个[视频][14],其中仔细说明了一种密钥交换算法。 + +### 建立信任 + +你可能会问,“如果 CA 使用其私钥对证书进行签名,也就意味着我们需要使用 CA 的公钥验证证书。那么 CA 的公钥从何而来,谁对其进行签名呢?” 答案是 CA 对自己签名!可以使用证书公钥对应的私钥,对证书本身进行签名!这类签名证书被称为是自签名的self-signed;在 PKI 体系下,这意味着对你说“相信我”。(为了表达方便,人们通常说用证书进行了签名,虽然真正用于签名的私钥并不在证书中。) + +通过遵守[浏览器][15]和[操作系统][16]供应商建立的规则,CA 表明自己足够可靠并寻求加入到浏览器或操作系统预装的一组自签名证书中。这些证书被称为“信任锚trust anchor”或 CA 根证书root CA certificate,被存储在根证书区,我们约定implicitly信任该区域内的证书。 + +CA 也可以签发一种特殊的证书,该证书自身可以作为 CA。在这种情况下,它们可以生成一个证书链。要核验证书链,需要从“信任锚”(也就是 CA 根证书)开始,使用当前证书的公钥核验下一层证书的签名(或其它一些信息)。按照这个方式依次核验下一层证书,直到证书链底部。如果整个核验过程没有问题,信任链也建立完成。当向 CA 付费为网站签发证书时,实际购买的是将证书放置在证书链下的权利。CA 将卖出的证书标记为“不可签发子证书”,这样它们可以在适当的长度终止信任链(防止其继续向下扩展)。 + +为何要使用长度超过 2 的信任链呢?毕竟网站的证书可以直接被 CA 根证书签名。在实际应用中,很多因素促使 CA 创建中间 CA 证书intermediate CA certificate,最主要是为了方便。由于价值连城,CA 根证书对应的私钥通常被存放在特定的设备中,一种需要多人解锁的硬件安全模块hardware security module(HSM),该模块完全离线并被保管在配备监控和报警设备的[地下室][18]中。 + +CA/浏览器论坛CAB Forum, CA/Browser Forum负责管理 CA,[要求][19]任何与 CA 根证书(LCTT 译注:就像前文提到的那样,这里是指对应的私钥)相关的操作必须由人工完成。设想一下,如果每个证书请求都需要员工将请求内容拷贝到保密介质中、进入地下室、与同事一起解锁 HSM、(使用 CA 根证书对应的私钥)签名证书,最后将签名证书从保密介质中拷贝出来;那么每天为大量网站签发证书是相当繁重乏味的工作。因此,CA 创建内部使用的中间 CA,用于证书签发自动化。 + +如果想查看证书链,可以在 Firefox 中点击地址栏的锁型图标,接着打开页面信息,然后点击“安全”面板中的“查看证书”按钮。在本文写作时,[opensource.com][20] 使用的证书链如下: + +``` +DigiCert High Assurance EV Root CA +    DigiCert SHA2 High Assurance Server CA +        opensource.com +``` + +### 中间人 + +我之前提到,浏览器需要核验证书中的主机名与已经建立连接的主机名一致。为什么需要这一步呢?要回答这个问题,需要了解所谓的[中间人攻击man-in-the-middle, MIMT][22]。有一类[网络攻击][22]可以让攻击者将自己置身于客户端和服务端中间,冒充客户端与服务端连接,同时冒充服务端与客户端连接。如果网络流量是通过 HTTPS 传输的,加密的流量无法被窃听。此时,攻击者会创建一个代理,接收来自受害者的 HTTPS 连接,解密信息后构建一个新的 HTTPS 连接到原始目的地(即服务端)。为了建立假冒的 HTTPS 连接,代理必须返回一个攻击者具有对应私钥的证书。攻击者可以生成自签名证书,但受害者的浏览器并不会信任该证书,因为它并不是根证书库中的 CA 根证书签发的。换一个方法,攻击者使用一个受信任 CA 签发但主机名对应其自有域名的证书,结果会怎样呢? + +再回到银行的那个例子,我们是银行柜员,一位男性顾客进入银行要求从 Jane Doe 的账户上取钱。当被要求提供身份证明时,他给出了 Joe Smith 的有效驾驶执照。如果这个交易可以完成,我们无疑会被银行开除。类似的,如果检测到证书中的主机名与连接对应的主机名不一致,浏览器会给出类似“连接不安全”的警告和查看更多内容的选项。在 Firefox 中,这类错误被标记为 `SSL_ERROR_BAD_CERT_DOMAIN`。 + +我希望你阅读完本文起码记住这一点:如果看到这类警告,**不要无视它们**!它们出现意味着,或者该网站配置存在严重问题(不推荐访问),或者你已经是中间人攻击的潜在受害者。 + +### 总结 + +虽然本文只触及了 PKI 世界的一些皮毛,我希望我已经为你展示了便于后续探索的大致蓝图。密码学和 PKI 是美与复杂性的结合体。越深入研究,越能发现更多的美和复杂性,就像分形那样。 + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/7/private-keys + +作者:[Alex Wood][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[pinewall](https://github.com/pinewall) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://opensource.com/users/awood +[1]:https://linux.cn/article-9792-1.html +[2]:https://theintercept.com/2014/10/28/smuggling-snowden-secrets/ +[3]:https://en.wikipedia.org/wiki/SHA-2 +[4]:https://www.ietf.org/mail-archive/web/openpgp/current/msg00999.html +[5]:https://www.imperialviolet.org/2014/09/26/pkcs1.html +[6]:https://en.wikipedia.org/wiki/Key_signing_party +[7]:https://en.wikipedia.org/wiki/Key_server_(cryptographic) +[8]:https://en.wikipedia.org/wiki/Web_of_trust +[9]:https://www.gnupg.org/gph/en/manual/x547.html +[10]:https://blog.cryptographyengineering.com/2014/08/13/whats-matter-with-pgp/ +[11]:https://lists.torproject.org/pipermail/tor-talk/2013-September/030235.html +[12]:https://en.wikipedia.org/wiki/Extended_Validation_Certificate +[13]:https://en.wikipedia.org/wiki/Transport_Layer_Security +[14]:https://www.youtube.com/watch?v=YEBfamv-_do +[15]:https://www.mozilla.org/en-US/about/governance/policies/security-group/certs/policy/ +[16]:https://technet.microsoft.com/en-us/library/cc751157.aspx +[17]:https://en.wikipedia.org/wiki/Hardware_security_module +[18]:https://arstechnica.com/information-technology/2012/11/inside-symantecs-ssl-certificate-vault/ +[19]:https://cabforum.org/baseline-requirements-documents/ +[20]:http://opensource.com +[21]:https://en.wikipedia.org/wiki/Man-in-the-middle_attack +[22]:http://www.shortestpathfirst.net/2010/11/18/man-in-the-middle-mitm-attacks-explained-arp-poisoining/ diff --git a/published/20180730 7 Python libraries for more maintainable code.md b/published/20180730 7 Python libraries for more maintainable code.md new file mode 100644 index 0000000000..051ad79f2c --- /dev/null +++ b/published/20180730 7 Python libraries for more maintainable code.md @@ -0,0 +1,124 @@ +让 Python 代码更易维护的七种武器 +====== + +> 检查你的代码的质量,通过这些外部库使其更易维护。 + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/programming_keyboard_coding.png?itok=E0Vvam7A) + +> 可读性很重要。 +> — [Python 之禅][1]The Zen of Python,Tim Peters + +随着软件项目进入“维护模式”,对可读性和编码标准的要求很容易落空(甚至从一开始就没有建立过那些标准)。然而,在代码库中保持一致的代码风格和测试标准能够显著减轻维护的压力,也能确保新的开发者能够快速了解项目的情况,同时能更好地全程保持应用程序的质量。 + +使用外部库来检查代码的质量不失为保护项目未来可维护性的一个好方法。以下会推荐一些我们最喜爱的[检查代码][2](包括检查 PEP 8 和其它代码风格错误)的库,用它们来强制保持代码风格一致,并确保在项目成熟时有一个可接受的测试覆盖率。 + +### 检查你的代码风格 + +[PEP 8][3] 是 Python 代码风格规范,它规定了类似行长度、缩进、多行表达式、变量命名约定等内容。尽管你的团队自身可能也会有稍微不同于 PEP 8 的代码风格规范,但任何代码风格规范的目标都是在代码库中强制实施一致的标准,使代码的可读性更强、更易于维护。下面三个库就可以用来帮助你美化代码。 + +#### 1、 Pylint + +[Pylint][4] 是一个检查违反 PEP 8 规范和常见错误的库。它在一些流行的[编辑器和 IDE][5] 中都有集成,也可以单独从命令行运行。 + +执行 `pip install pylint` 安装 Pylint 。然后运行 `pylint [options] path/to/dir` 或者 `pylint [options] path/to/module.py` 就可以在命令行中使用 Pylint,它会向控制台输出代码中违反规范和出现错误的地方。 + +你还可以使用 `pylintrc` [配置文件][6]来自定义 Pylint 对哪些代码错误进行检查。 + +#### 2、 Flake8 + +[Flake8][7] 是“将 PEP 8、Pyflakes(类似 Pylint)、McCabe(代码复杂性检查器)和第三方插件整合到一起,以检查 Python 代码风格和质量的一个 Python 工具”。 + +执行 `pip install flake8` 安装 flake8 ,然后执行 `flake8 [options] path/to/dir` 或者 `flake8 [options] path/to/module.py` 可以查看报出的错误和警告。 + +和 Pylint 类似,Flake8 允许通过[配置文件][8]来自定义检查的内容。它有非常清晰的文档,包括一些有用的[提交钩子][9],可以将自动检查代码纳入到开发工作流程之中。 + +Flake8 也可以集成到一些流行的编辑器和 IDE 当中,但在文档中并没有详细说明。要将 Flake8 集成到喜欢的编辑器或 IDE 中,可以搜索插件(例如 [Sublime Text 的 Flake8 插件][10])。 + +#### 3、 Isort + +[Isort][11] 这个库能将你在项目中导入的库按字母顺序排序,并将其[正确划分为不同部分][12](例如标准库、第三方库、自建的库等)。这样提高了代码的可读性,并且可以在导入的库较多的时候轻松找到各个库。 + +执行 `pip install isort` 安装 isort,然后执行 `isort path/to/module.py` 就可以运行了。[文档][13]中还提供了更多的配置项,例如通过[配置][14] `.isort.cfg` 文件来决定 isort 如何处理一个库的多行导入。 + +和 Flake8、Pylint 一样,isort 也提供了将其与流行的[编辑器和 IDE][15] 集成的插件。 + +### 分享你的代码风格 + +每次文件发生变动之后都用命令行手动检查代码是一件痛苦的事,你可能也不太喜欢通过运行 IDE 中某个插件来实现这个功能。同样地,你的同事可能会用不同的代码检查方式,也许他们的编辑器中也没有那种插件,甚至你自己可能也不会严格检查代码和按照警告来更正代码。总之,你分享出来的代码库将会逐渐地变得混乱且难以阅读。 + +一个很好的解决方案是使用一个库,自动将代码按照 PEP 8 规范进行格式化。我们推荐的三个库都有不同的自定义级别来控制如何格式化代码。其中有一些设置较为特殊,例如 Pylint 和 Flake8 ,你需要先行测试,看看是否有你无法忍受但又不能修改的默认配置。 + +#### 4、 Autopep8 + +[Autopep8][16] 可以自动格式化指定的模块中的代码,包括重新缩进行、修复缩进、删除多余的空格,并重构常见的比较错误(例如布尔值和 `None` 值)。你可以查看文档中完整的[更正列表][17]。 + +运行 `pip install --upgrade autopep8` 安装 Autopep8。然后执行 `autopep8 --in-place --aggressive --aggressive ` 就可以重新格式化你的代码。`aggressive` 选项的数量表示 Auotopep8 在代码风格控制上有多少控制权。在这里可以详细了解 [aggressive][18] 选项。 + +#### 5、 Yapf + +[Yapf][19] 是另一种有自己的[配置项][20]列表的重新格式化代码的工具。它与 Autopep8 的不同之处在于它不仅会指出代码中违反 PEP 8 规范的地方,还会对没有违反 PEP 8 但代码风格不一致的地方重新格式化,旨在令代码的可读性更强。 + +执行 `pip install yapf` 安装 Yapf,然后执行 `yapf [options] path/to/dir` 或 `yapf [options] path/to/module.py` 可以对代码重新格式化。[定制选项][20]的完整列表在这里。 + +#### 6、 Black + +[Black][21] 在代码检查工具当中算是比较新的一个。它与 Autopep8 和 Yapf 类似,但限制较多,没有太多的自定义选项。这样的好处是你不需要去决定使用怎么样的代码风格,让 Black 来给你做决定就好。你可以在这里查阅 Black [有限的自定义选项][22]以及[如何在配置文件中对其进行设置][23]。 + +Black 依赖于 Python 3.6+,但它可以格式化用 Python 2 编写的代码。执行 `pip install black` 安装 Black,然后执行 `black path/to/dir` 或 `black path/to/module.py` 就可以使用 Black 优化你的代码。 + +### 检查你的测试覆盖率 + +如果你正在进行编写测试,你需要确保提交到代码库的新代码都已经测试通过,并且不会降低测试覆盖率。虽然测试覆盖率不是衡量测试有效性和充分性的唯一指标,但它是确保项目遵循基本测试标准的一种方法。对于计算测试覆盖率,我们推荐使用 Coverage 这个库。 + +#### 7、 Coverage + +[Coverage][24] 有数种显示测试覆盖率的方式,包括将结果输出到控制台或 HTML 页面,并指出哪些具体哪些地方没有被覆盖到。你可以通过[配置文件][25]自定义 Coverage 检查的内容,让你更方便使用。 + +执行 `pip install coverage` 安装 Converage 。然后执行 `coverage [path/to/module.py] [args]` 可以运行程序并查看输出结果。如果要查看哪些代码行没有被覆盖,执行 `coverage report -m` 即可。 + +### 持续集成工具 + +持续集成Continuous integration(CI)是在合并和部署代码之前自动检查代码风格错误和测试覆盖率最小值的过程。很多免费或付费的工具都可以用于执行这项工作,具体的过程不在本文中赘述,但 CI 过程是令代码更易读和更易维护的重要步骤,关于这一部分可以参考 [Travis CI][26] 和 [Jenkins][27]。 + +以上这些只是用于检查 Python 代码的各种工具中的其中几个。如果你有其它喜爱的工具,欢迎在评论中分享。 + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/7/7-python-libraries-more-maintainable-code + +作者:[Jeff Triplett][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[HankChow](https://github.com/HankChow) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://opensource.com/users/laceynwilliams +[1]:https://www.python.org/dev/peps/pep-0020/ +[2]:https://en.wikipedia.org/wiki/Lint_(software) +[3]:https://www.python.org/dev/peps/pep-0008/ +[4]:https://www.pylint.org/ +[5]:https://pylint.readthedocs.io/en/latest/user_guide/ide-integration.html +[6]:https://pylint.readthedocs.io/en/latest/user_guide/run.html#command-line-options +[7]:http://flake8.pycqa.org/en/latest/ +[8]:http://flake8.pycqa.org/en/latest/user/configuration.html#configuration-locations +[9]:http://flake8.pycqa.org/en/latest/user/using-hooks.html +[10]:https://github.com/SublimeLinter/SublimeLinter-flake8 +[11]:https://github.com/timothycrosley/isort +[12]:https://github.com/timothycrosley/isort#how-does-isort-work +[13]:https://github.com/timothycrosley/isort#using-isort +[14]:https://github.com/timothycrosley/isort#configuring-isort +[15]:https://github.com/timothycrosley/isort/wiki/isort-Plugins +[16]:https://github.com/hhatto/autopep8 +[17]:https://github.com/hhatto/autopep8#id4 +[18]:https://github.com/hhatto/autopep8#id5 +[19]:https://github.com/google/yapf +[20]:https://github.com/google/yapf#usage +[21]:https://github.com/ambv/black +[22]:https://github.com/ambv/black#command-line-options +[23]:https://github.com/ambv/black#pyprojecttoml +[24]:https://coverage.readthedocs.io/en/latest/ +[25]:https://coverage.readthedocs.io/en/latest/config.html +[26]:https://travis-ci.org/ +[27]:https://jenkins.io/ + diff --git a/published/20180730 How to use VS Code for your Python projects.md b/published/20180730 How to use VS Code for your Python projects.md new file mode 100644 index 0000000000..2ae8bbd3c3 --- /dev/null +++ b/published/20180730 How to use VS Code for your Python projects.md @@ -0,0 +1,160 @@ +使用 VS Code 进行 Python 编程 +====== + +![](https://fedoramagazine.org/wp-content/uploads/2018/07/pythonvscode-816x345.jpg) + +Visual Studio Code,简称 VS Code,是一个开源的文本编辑器,包含用于构建和调试应用程序的工具。安装启用 Python 扩展后,VS Code 可以配置成理想的 Python 开发工作环境。本文将介绍一些有用的 VS Code 扩展,并配置它们以充分提高 Python 开发效率。 + +如果你的计算机上还没有安装 VS Code,可以参考文章 [在 Fedora 上使用 VS Code](https://fedoramagazine.org/using-visual-studio-code-fedora/) 来安装。 + +### 在 VS Code 中安装 Python 扩展 + +首先,为了更方便地在 VS Code 中进行 Python 开发,需要从 VS Code 扩展商店中安装 Python 扩展。 + +![][2] + +Python 扩展安装完成后,就可以开始配置 Python 扩展了。 + +VS Code 通过两个 JSON 文件管理设置: + + * 一个文件用于 VS Code 的全局设置,作用于所有的项目 + * 另一个文件用于特殊设置,作用于单独项目 + +可以用快捷键 `Ctrl+,` (逗号)打开全局设置,也可以通过 **文件 -> 首选项 -> 设置** 来打开。 + +#### 设置 Python 路径 + +您可以在全局设置中配置 `python.pythonPath` 使 VS Code 自动为每个项目选择最适合的 Python 解释器。 + +``` +// 将设置放在此处以覆盖默认设置和用户设置。 +// Path to Python, you can use a custom version of Python by modifying this setting to include the full path. +{ + "python.pythonPath":"${workspaceRoot}/.venv/bin/python", +} +``` + +这样,VS Code 将使用虚拟环境目录 `.venv` 下项目根目录中的 Python 解释器。 + +#### 使用环境变量 + +默认情况下,VS Code 使用项目根目录下的 `.env` 文件中定义的环境变量。 这对于设置环境变量很有用,如: + +``` +PYTHONWARNINGS="once" +``` + +可使程序在运行时显示警告。 + +可以通过设置 `python.envFile` 来加载其他的默认环境变量文件: + +``` +// Absolute path to a file containing environment variable definitions. +"python.envFile": "${workspaceFolder}/.env", +``` + +### 代码分析 + +Python 扩展还支持不同的代码分析工具(pep8、flake8、pylint)。要启用你喜欢的或者正在进行的项目所使用的分析工具,只需要进行一些简单的配置。 + +扩展默认情况下使用 pylint 进行代码分析。你可以这样配置以使用 flake8 进行分析: + +``` +"python.linting.pylintEnabled": false, +"python.linting.flake8Path": "${workspaceRoot}/.venv/bin/flake8", +"python.linting.flake8Enabled": true, +"python.linting.flake8Args": ["--max-line-length=90"], +``` + +启用代码分析后,分析器会在不符合要求的位置加上波浪线,鼠标置于该位置,将弹窗提示其原因。注意,项目的虚拟环境中需要安装有 flake8,此示例方能有效。 + +![][3] + +### 格式化代码 + +可以配置 VS Code 使其自动格式化代码。目前支持 autopep8、black 和 yapf。下面的设置将启用 “black” 模式。 + +``` +// Provider for formatting. Possible options include 'autopep8', 'black', and 'yapf'. +"python.formatting.provider": "black", +"python.formatting.blackPath": "${workspaceRoot}/.venv/bin/black" +"python.formatting.blackArgs": ["--line-length=90"], +"editor.formatOnSave": true, +``` + +如果不需要编辑器在保存时自动格式化代码,可以将 `editor.formatOnSave` 设置为 `false` 并手动使用快捷键 `Ctrl + Shift + I` 格式化当前文档中的代码。 注意,项目的虚拟环境中需要安装有 black,此示例方能有效。 + +### 运行任务 + +VS Code 的一个重要特点是它可以运行任务。需要运行的任务保存在项目根目录中的 JSON 文件中。 + +#### 运行 flask 开发服务 + +这个例子将创建一个任务来运行 Flask 开发服务器。 使用一个可以运行外部命令的基本模板来创建新的工程: + +![][4] + +编辑如下所示的 `tasks.json` 文件,创建新任务来运行 Flask 开发服务: + +``` +{ + // See https://go.microsoft.com/fwlink/?LinkId=733558 + // for the documentation about the tasks.json format + "version": "2.0.0", + "tasks": [ + { + + "label": "Run Debug Server", + "type": "shell", + "command": "${workspaceRoot}/.venv/bin/flask run -h 0.0.0.0 -p 5000", + "group": { + "kind": "build", + "isDefault": true + } + } + ] +} +``` + +Flask 开发服务使用环境变量来获取应用程序的入口点。 如 **使用环境变量** 一节所说,可以在 `.env` 文件中声明这些变量: + +``` +FLASK_APP=wsgi.py +FLASK_DEBUG=True +``` + +这样就可以使用快捷键 `Ctrl + Shift + B` 来执行任务了。 + +### 单元测试 + +VS Code 还支持单元测试框架 pytest、unittest 和 nosetest。启用测试框架后,可以在 VS Code 中单独运行搜索到的单元测试,通过测试套件运行测试或者运行所有的测试。 + +例如,可以这样启用 pytest 测试框架: + +``` +"python.unitTest.pyTestEnabled": true, +"python.unitTest.pyTestPath": "${workspaceRoot}/.venv/bin/pytest", +``` + +注意,项目的虚拟环境中需要安装有 pytest,此示例方能有效。 + +![][5] + + +-------------------------------------------------------------------------------- + +via: https://fedoramagazine.org/vscode-python-howto/ + +作者:[Clément Verna][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[idea2act](https://github.com/idea2act) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://fedoramagazine.org +[1]:https://fedoramagazine.org/using-visual-studio-code-fedora/ +[2]:https://fedoramagazine.org/wp-content/uploads/2018/07/Peek-2018-07-27-09-44.gif +[3]:https://fedoramagazine.org/wp-content/uploads/2018/07/Peek-2018-07-27-12-05.gif +[4]:https://fedoramagazine.org/wp-content/uploads/2018/07/Peek-2018-07-27-13-26.gif +[5]:https://fedoramagazine.org/wp-content/uploads/2018/07/Peek-2018-07-27-15-33.gif diff --git a/translated/tech/20160325 Network automation with Ansible.md b/published/201808/20160325 Network automation with Ansible.md similarity index 51% rename from translated/tech/20160325 Network automation with Ansible.md rename to published/201808/20160325 Network automation with Ansible.md index 12a0371de1..e343359ad8 100644 --- a/translated/tech/20160325 Network automation with Ansible.md +++ b/published/201808/20160325 Network automation with Ansible.md @@ -5,47 +5,47 @@ ### 网络自动化 -随着 IT 行业的技术变化,从服务器虚拟化到公有云和私有云,以及自服务能力、容器化应用、平台即服务(PaaS)交付,有一直以来落后的一个领域就是网络。 +随着 IT 行业的技术变化,从服务器虚拟化到公有云和私有云,以及自服务能力、容器化应用、平台即服务(PaaS)交付,而一直以来落后的一个领域就是网络。 -在过去的五年多,网络行业似乎有很多新的趋势出现,它们中的很多被归入到软件定义网络(SDN)。 +在过去的五年多,网络行业似乎有很多新的趋势出现,它们中的很多被归入到软件定义网络software-defined networking(SDN)。 ->注意 +>注意: > SDN 是新出现的一种构建、管理、操作和部署网络的方法。SDN 最初的定义是出于将控制层和数据层(包转发)物理分离的需要,并且,解耦合的控制层必须管理好各自的设备。 -> 如今,在 SDN 旗下已经有许多技术,包括基于控制器的网络controller-based networks、网络设备上的 API、网络自动化、白盒交换机、策略网络化、网络功能虚拟化(NFV)等等。 +> 如今,在 SDN 旗下已经有许多技术,包括基于控制器的网络controller-based networks、网络设备 API、网络自动化、白盒交换机whitebox switche、策略网络化、网络功能虚拟化Network Functions Virtualization(NFV)等等。 -> 由于这篇报告的目的,我们参考 SDN 的解决方案作为我们的解决方案,其中包括一个网络控制器作为解决方案的一部分,并且提升了该网络的可管理性,但并不需要从数据层解耦控制层。 +> 出于这篇报告的目的,我们参考 SDN 的解决方案作为我们的解决方案,其中包括一个网络控制器作为解决方案的一部分,并且提升了该网络的可管理性,但并不需要从数据层解耦控制层。 -这些趋势的之一是,网络设备的 API 作为管理和操作这些设备的一种方法而出现,真正地提供了机器对机器的通讯。当需要自动化和构建网络应用时 API 简化了开发过程,在数据如何建模时提供了更多结构。例如,当启用 API 的设备以 JSON/XML 返回数据时,它是结构化的,并且比返回原生文本信息、需要手工去解析的仅支持命令行的设备更易于使用。 +这些趋势的之一是,网络设备的 API 作为管理和操作这些设备的一种方法而出现,真正地提供了机器对机器的通讯。当需要自动化和构建网络应用时 API 简化了开发过程,在数据如何建模时提供了更多结构。例如,当启用 API 的设备以 JSON/XML 返回数据时,它是结构化的,并且比返回原生文本信息 —— 需要手工去解析的仅支持命令行的设备更易于使用。 在 API 之前,用于配置和管理网络设备的两个主要机制是命令行接口(CLI)和简单网络管理协议(SNMP)。让我们来了解一下它们,CLI 是一个设备的人机界面,而 SNMP 并不是为设备提供的实时编程接口。 幸运的是,因为很多供应商争相为设备增加 API,有时候 _只是因为_ 它被放到需求建议书(RFP)中,这就带来了一个非常好的副作用 —— 支持网络自动化。当真正的 API 发布时,访问设备内数据的过程,以及管理配置,就会被极大简化,因此,我们将在本报告中对此进行评估。虽然使用许多传统方法也可以实现自动化,比如,CLI/SNMP。 -> 注意 +> 注意: -> 随着未来几个月或几年的网络设备更新,供应商的 API 无疑应该被做为采购网络设备(虚拟和物理)的关键决策标准而测试和使用。如果供应商提供一些库或集成到自动化工具中,或者如果被用于一个开放的标准或协议,用户应该知道数据是如何通过设备建模的,API 使用的传输类型是什么。 +> 随着未来几个月或几年(LCTT 译注:本文发表于 2016 年)的网络设备更新,供应商的 API 无疑应该被做为采购网络设备(虚拟和物理)的关键决策标准而测试和使用。如果供应商提供一些库或集成到自动化工具中,或者如果被用于一个开放的标准或协议,用户应该知道数据是如何通过设备建模的,API 使用的传输类型是什么。 -总而言之,网络自动化,像大多数类型的自动化一样,是为了更快地工作。工作的更快是好事,降低部署和配置改变的时间并不总是许多 IT 组织需要去解决的问题。 +总而言之,网络自动化,像大多数类型的自动化一样,是为了更快地工作。工作的更快是好事,减少部署和配置改变的时间并不总是许多 IT 组织需要去解决的问题。 包括速度在内,我们现在看看这些各种类型的 IT 组织逐渐采用网络自动化的几种原因。你应该注意到,同样的原则也适用于其它类型的自动化。 -### 简化架构 +#### 简化架构 -今天,每个网络都是一片独特的“雪花”,并且,网络工程师们为能够通过一次性的改变来解决传输和网络应用问题而感到自豪,而这最终导致网络不仅难以维护和管理,而且也很难去实现自动化。 +今天,每个网络都是一片独特的“雪花”,并且,网络工程师们为能够通过一次性的网络改变来解决传输和应用问题而感到自豪,而这最终导致网络不仅难以维护和管理,而且也很难去实现自动化。 -网络自动化和管理需要从一开始就包含到新的架构和设计中去部署,而不是作为一个二级或三级项目。哪个特性可以跨不同的供应商工作?哪个扩展可以跨不同的平台工作?当使用特别的网络设备平台时,API 类型或者自动化工程是什么?当这些问题在设计过程之前得到答案,最终的架构将变成简单的、可重复的、并且易于维护 _和_ 自动化的,在整个网络中将很少启用供应商专用的扩展。 +网络自动化和管理需要从一开始就包含到新的架构和设计中去部署,而不是作为一个二级或三级项目。哪个特性可以跨不同的供应商工作?哪个扩展可以跨不同的平台工作?当使用具体的网络设备平台时,API 类型或者自动化工程是什么?当这些问题在设计过程之前得到答案,最终的架构将变成简单的、可重复的、并且易于维护 _和_ 自动化的,在整个网络中将很少启用供应商专用的扩展。 -### 确定的结果 +#### 确定的结果 在一个企业组织中,改变审查会议change review meeting会评估面临的网络变化、它们对外部系统的影响、以及回滚计划。在人们通过 CLI 来执行这些 _面临的变化_ 的世界上,输入错误的命令造成的影响是灾难性的。想像一下,一个有 3 位、4 位、5位,或者 50 位工程师的团队。每位工程师应对 _面临的变化_ 都有他们自己的独特的方法。并且,在管理这些变化的期间,一个人使用 CLI 或者 GUI 的能力并不会消除和减少出现错误的机率。 -使用经过验证和测试过的网络自动化可以帮助实现更多的可预测行为,并且使执行团队更有可能实现确实性结果,在保证任务没有人为错误的情况下首次正确完成的道路上更进一步。 +使用经过验证的和测试过的网络自动化可以帮助实现更多的可预测行为,并且使执行团队更有可能实现确实性的结果,首次在保证任务没有人为错误的情况下正确完成的道路上更进一步。 -### 业务灵活性 +#### 业务灵活性 -不用说,网络自动化不仅为部署变化提供速度和灵活性,而且使得根据业务需要去从网络设备中检索数据的速度变得更快。自从服务器虚拟化到来以后,服务器和虚拟化使得管理员有能力在瞬间去部署一个新的应用程序。而且,随着应用程序可以更快地部署,随之浮现的问题是为什么还需要花费如此长的时间配置一个 VLAN(虚拟局域网)、路由器、FW ACL(防火墙的访问控制列表)或者负载均衡策略呢? +不用说,网络自动化不仅为部署变化提供了速度和灵活性,而且使得根据业务需要去从网络设备中检索数据的速度变得更快。自从服务器虚拟化到来以后,服务器和虚拟化使得管理员有能力在瞬间去部署一个新的应用程序。而且,随着应用程序可以更快地部署,随之浮现的问题是为什么还需要花费如此长的时间配置一个 VLAN(虚拟局域网)、路由器、FW ACL(防火墙的访问控制列表)或者负载均衡策略呢? 通过了解在一个组织内最常见的工作流和 _为什么_ 真正需要改变网络,部署如 Ansible 这样的现代的自动化工具将使这些变得非常简单。 @@ -61,9 +61,9 @@ _Ansible 是一个无需代理和可扩展的超级简单的自动化平台。_ 让我们更深入地了解它的细节,并且看一看那些使 Ansible 在行业内获得广泛认可的属性。 -### 简单 +#### 简单 -Ansible 的其中一个吸引人的属性是,使用它你 _不_ 需要特定的编程技能。所有的指令,或者任务都是自动化的,以一个标准的、任何人都可以理解的人类可读的数据格式的文档化。在 30 分钟之内完成安装和自动化任务的情况并不罕见! +Ansible 的其中一个吸引人的属性是,使用它你 **不** 需要特定的编程技能。所有的指令,或者说任务都是自动化的,以一个标准的、任何人都可以理解的人类可读的数据格式的文档化。在 30 分钟之内完成安装和自动化任务的情况并不罕见! 例如,下列来自一个 Ansible 剧本playbook的任务用于去确保在一个 VLAN 存在于一个 Cisco Nexus 交换机中: @@ -73,90 +73,83 @@ Ansible 的其中一个吸引人的属性是,使用它你 _不_ 需要特定 你无需熟悉或写任何代码就可以明确地看出它将要做什么! -> 注意 +> 注意: -> 这个报告的下半部分涉到 Ansible 术语(剧本playbook行动play任务task模块module等等)的细节。在我们使用 Ansible 进行网络自动化时,提及这些关键概念时我们会有一些简短的示例。 +> 这个报告的下半部分涉到 Ansible 术语(剧本playbook剧集play任务task模块module等等)的细节。在我们使用 Ansible 进行网络自动化时,提及这些关键概念时我们会有一些简短的示例。 -### 无代理 +#### 无代理 -如果你看到市面上的其它工具,比如 Puppet 和 Chef,你学习它们会发现,一般情况下,它们要求每个实现自动化的设备必须安装特定的软件。这种情况在 Ansible 上 _并不_需要,这就是为什么 Ansible 是实现网络自动化的最佳选择的主要原因。 +如果你看过市面上的其它工具,比如 Puppet 和 Chef,你会发现,一般情况下,它们要求每个实现自动化的设备必须安装特定的软件。这种情况在 Ansible 上 _并不_需要,这就是为什么 Ansible 是实现网络自动化的最佳选择的主要原因。 -它很好理解,那些 IT 自动化工具,包括 Puppet、Chef、CFEngine、SaltStack、和 Ansible,它们最初构建是为管理和自动化配置 Linux 主机,以跟得上部署的应用程序增长的步伐。因为 Linux 系统是被配置成自动化的,要安装代理并不是一个技术难题。如果有的话,它会担误安装过程,因为,现在有 _N_ 多个(你希望去实现自动化的)主机需要在它们上面部署软件。 +这很好理解,那些 IT 自动化工具,包括 Puppet、Chef、CFEngine、SaltStack、和 Ansible,它们最初构建是为管理和自动化配置 Linux 主机,以跟得上部署的应用程序增长的步伐。因为 Linux 系统是被配置成自动化的,要安装代理并不是一个技术难题。如果有的话,它也只会延误安装过程,因为,现在有 _N_ 多个(你希望去实现自动化的)主机需要在它们上面部署软件。 -再加上,当使用代理时,它们需要的 DNS 和 NTP 配置更加复杂。这些都是大多数环境中已经配置好的服务,但是,当你希望快速地获取一些东西或者只是简单地想去测试一下它能做什么的时候,它将极大地担误整个设置和安装的过程。 +再加上,当使用代理时,它们需要的 DNS 和 NTP 配置更加复杂。这些都是大多数环境中已经配置好的服务,但是,当你希望快速地获取一些东西或者只是简单地想去测试一下它能做什么的时候,它将极大地耽误整个设置和安装的过程。 -由于本报告只是为介绍利用 Ansible 实现网络自动化,它最有价值的是,Ansible 作为一个无代理平台,对于系统管理员来说,它更具有吸引力,这是为什么呢? +由于本报告只是为介绍利用 Ansible 实现网络自动化,我们希望指出,Ansible 作为一个无代理平台,对于网络管理员来说,其比对系统管理员更具有吸引力。这是为什么呢? -正如前面所说的那样,对网络管理员来说,它是非常有吸引力的,Linux 操作系统是开源的,并且,任何东西都可以安装在它上面。对于网络来说,虽然它正在逐渐改变,但事实并非如此。如果我们更广泛地部署网络操作系统,如 Cisco IOS,它就是这样的一个例子,并且问一个问题, _“第三方软件能否部署在基于 IOS (译者注:此处的 IOS,指的是思科的网络操作系统 IOS)的平台上吗?”_它并不会给你惊喜,它的回答是 _NO_。 +正如前面所说的那样,对网络管理员来说,它是非常有吸引力的,Linux 操作系统是开源的,并且,任何东西都可以安装在它上面。对于网络来说,却并非如此,虽然它正在逐渐改变。如果我们更广泛地部署网络操作系统,如 Cisco IOS,它就是这样的一个例子,并且问一个问题, _“第三方软件能否部署在基于 IOS (LCTT 译注:此处的 IOS,指的是思科的网络操作系统 IOS)的平台上吗?”_毫无疑问,它的回答是 _NO_。 -在过去的二十多年里,几乎所有的网络操作系统都是闭源的,并且,垂直整合到底层的网络硬件中。在一个网络设备中(路由器、交换机、负载均衡、防火墙、等等),不需要供应商的支持,有一个像 Ansible 这样的自动化平台,从头开始去构建一个无代理、可扩展的自动化平台,就像是它专门为网络行业订制的一样。我们最终将开始减少并消除与网络的人工交互。 +在过去的二十多年里,几乎所有的网络操作系统都是闭源的,并且,垂直整合到底层的网络硬件中。没有供应商的支持,在一个网络设备中(路由器、交换机、负载均衡、防火墙、等等)载入一个代理并不那么轻松。有一个像 Ansible 这样的自动化平台,从头开始去构建一个无代理、可扩展的自动化平台,就像是它专门为网络行业订制的一样。我们最终将开始减少并消除与网络的人工交互。 -### 可扩展 +#### 可扩展 -Ansible 的可扩展性也非常的好。作为一个开源的,并且从代码开始将在网络行业中发挥重要的作用,有一个可扩展的平台是必需的。这意味着如果供应商或社区不提供一个特定的特性或功能,开源社区,终端用户,消费者,顾问者,或者,任何可能去 _扩展_ Ansible 的人,去启用一个给定的功能集。过去,网络供应商或者工具供应商通过一个 hook 去提供插件和集成。想像一下,使用一个像 Ansible 这样的自动化平台,并且,你选择的网络供应商发布了你 _真正_ 需要的自动化的一个新特性。从理论上说,网络供应商或者 Ansible 可以发行一个新的插件去实现自动化这个独特的特性,这是一件非常好的事情,从你的内部工程师到你的增值分销商(VARs)或者你的顾问中的任何人,都可以去提供这种集成。 - -正如前面所说的那样,Ansible 实际上是极具扩展性的,Ansible 最初就是为自动化应用程序和系统构建的。这是因为,Ansible 的可扩展性是被网络供应商编写集成的,包括但不限于 Cisco、Arista、Juniper、F5、HP、A10、Cumulus、和 Palo Alto Networks。 +Ansible 的可扩展性也非常的好。从开源、代码开始在网络行业中发挥重要的作用时起,有一个可扩展的平台是必需的。这意味着如果供应商或社区不提供一个特定的特性或功能,开源社区、终端用户、消费者、顾问,或者任何的人能够 _扩展_ Ansible 来启用一个给定的功能集。过去,网络供应商或者工具供应商通过一个 hook 去提供新的插件和集成。想像一下,使用一个像 Ansible 这样的自动化平台,并且,你选择的网络供应商发布了你 _真正_ 需要的一个自动化的新特性。从理论上说,网络供应商或者 Ansible 可以发行一个新的插件去实现自动化这个独特的特性,这是一件非常好的事情,从你的内部工程师到你的增值分销商(VAR)或者你的顾问中的任何一个人,都可以去提供这种集成。 +正如前面所说的那样,Ansible 实际上是极具扩展性的,Ansible 最初就是为自动化应用程序和系统构建的。这是因为,Ansible 的可扩展性来自于其集成性是为网络供应商编写的,包括但不限于 Cisco、Arista、Juniper、F5、HP、A10、Cumulus 和 Palo Alto Networks。 ### 对于网络自动化,为什么要使用 Ansible? 我们已经简单了解除了 Ansible 是什么,以及一些网络自动化的好处,但是,对于网络自动化,我们为什么要使用 Ansible? -在一个完全透明的环境下,已经说的很多的理由是 Ansible 可以做什么,比如,作为一个很大的自动化应用程序部署平台,但是,我们现在要深入一些,更多地关注于网络,并且继续总结一些更需要注意的其它关键点。 +大家很清楚,使得 Ansible 成为如此伟大的一个自动化应用部署平台的许多原因已经被大家所提及了。但是,我们现在要深入一些,更多地关注于网络,并且继续总结一些更需要注意的其它关键点。 +#### 无代理 -### 无代理 +在实现网络自动化的时候,无代理架构的重要性并不是重点强调的,特别是当它适用于现有的自动化设备时。如果,我们看一下当前网络中已经安装的各种设备时,从 DMZ 和园区,到分支机构和数据中心,最大份额的设备 _并不_ 具有最新 API 的设备。从自动化的角度来看,API 可以使做一些事情变得很简单,像 Ansible 这样的无代理平台有可能去自动化和管理那些 _老旧(传统)_ 的设备。例如,_基于 CLI 的设备_,它的工具可以被用于任何网络环境中。 + +> 注意: -在实现网络自动化的时候,无代理架构的重要性并不是重点强调的,特别是当它适用于现有的自动化设备时。如果,我们看一下当前网络中已经安装的各种设备时,从 DMZ 和园区,到分支和数据中心,最大份额的设备 _并不_ 具有最新 API 的设备。从自动化的角度来看,API 可以使做一些事情变得很简单,像 Ansible 这样的无代理平台有可能去自动化和管理那些 _传统_ 的设备。例如,_基于CLI 的设备_,它的工具可以被用于任何网络环境中。 +> 如果仅支持 CLI 的设备已经集成进 Ansible,它的机制就像是,怎么在设备上通过协议如 telnet、SSH 和 SNMP 去进行只读访问和读写操作。 -###### 注意 +作为一个独立的网络设备,像路由器、交换机、和防火墙正在持续去增加 API 的支持,SDN 解决方案也正在出现。SDN 解决方案的其中一个常见主题是,它们都提供一个单点集成和策略管理,通常是以一个 SDN 控制器的形式出现。这对于 Cisco ACI、VMware NSX、Big Switch Big Cloud Fabric 和 Juniper Contrail,以及其它的 SDN 提供者,比如 Nuage、Plexxi、Plumgrid、Midokura 和 Viptela,是一个真实的解决方案。这甚至包含开源的控制器,比如 OpenDaylight。 -如果仅 CLI 的设备已经集成进 Ansible,它的机制就像是,怎么在设备上通过协议如 telnet、SSH、和 SNMP,去进行只读访问和读写操作。 +所有的这些解决方案都简化了网络管理,就像它们可以让一个管理员开始从“box-by-box”管理(LCTT 译者注:指的是单个设备挨个去操作的意思)迁移到网络范围的管理。这是在正确方向上迈出的很大的一步,这些解决方案并不能消除在变更期间中人类犯错的机率。例如,比起配置 _N_ 个交换机,你可能需要去配置一个单个的 GUI,它需要很长的时间才能实现所需要的配置改变 —— 它甚至可能更复杂,毕竟,相对于一个 CLI,他们更喜欢 GUI!另外,你可能有不同类型的 SDN 解决方案部署在每个应用程序、网络、区域或者数据中心。 -作为一个独立的网络设备,像路由器、交换机、和防火墙持续去增加 APIs 的支持,SDN 解决方案也正在出现。SDN 解决方案的其中一个主题是,它们都提供一个单点集成和策略管理,通常是以一个 SDN 控制器的形式出现。这是真实的解决方案,比如,Cisco ACI、VMware NSX、Big Switch Big Cloud Fabric、和 Juniper Contrail,同时,其它的 SDN 提供者,比如 Nuage、Plexxi、Plumgrid、Midokura、和 Viptela。甚至包含开源的控制器,比如 OpenDaylight。 +在需要自动化的网络中,对于配置管理、监视和数据收集,当行业开始向基于控制器的网络架构中迁移时,这些需求并不会消失。 -所有的这些解决方案都简化了网络管理,就像他们允许一个管理员去开始从“box-by-box”管理(译者注:指的是单个设备挨个去操作的意思)迁移到网络范围的管理。这是在正确方向上迈出的很大的一步,这些解决方案并不能消除在改变窗口中人类犯错的机率。例如,比起配置 _N_ 个交换机,你可能需要去配置一个单个的 GUI,它需要很长的时间才能实现所需要的配置改变 — 它甚至可能更复杂,毕竟,相对于一个 CLI,他们更喜欢 GUI!另外,你可能有不同类型的 SDN 解决方案部署在每个应用程序、网络、区域、或者数据中心。 +大量的软件定义网络中都部署有控制器,几乎所有的控制器都提供expose一个最新的 REST API。并且,因为 Ansible 是一个无代理架构,它实现自动化是非常简单的,而不仅仅是对那些没有 API 的传统设备,但也有通过 REST API 的软件定义网络解决方案,在所有的终端上不需要有额外的软件(LCTT 译注:指的是代理)。最终的结果是,使用 Ansible,无论有或没有 API,可以使任何类型的设备都能够自动化。 -在需要自动化的网络中,对于配置管理、监视、和数据收集,当行业开始向基于控制器的网络架构中迁移时,这些需求并不会消失。 +#### 自由开源软件(FOSS) -大量的软件定义网络中都部署有控制器,所有最新的控制器都提供(expose)一个最新的 REST API。并且,因为 Ansible 是一个无代理架构,它实现自动化是非常简单的,而不仅仅是没有 API 的传统设备,但也有通过 REST APIs 的软件定义网络解决方案,在所有的终端上不需要有额外的软件(译者注:指的是代理)。最终的结果是,使用 Ansible,无论有或没有 API,可以使任何类型的设备都能够自动化。 +Ansible 是一个开源软件,它的全部代码在 GitHub 上都是公开可访问的,使用 Ansible 是完全免费的。它可以在几分钟内完成安装并为网络工程师提供有用的价值。Ansible 这个开源项目,或者 Ansible 公司,在它们交付软件之前,你不会遇到任何一个销售代表。那是显而易见的事实,因为它是一个真正的开源项目,但是,作为开源的、社区驱动的软件项目在网络行业中的使用是非常少的,但是,也在逐渐增加,我们想明确指出这一点。 +同样需要指出的一点是,Ansible, Inc. 也是一个公司,它也需要去赚钱,对吗?虽然 Ansible 是开源的,它也有一个叫 Ansible Tower 的企业产品,它增加了一些特性,比如,基于规则的访问控制(RBAC)、报告、 web UI、REST API、多租户等等,(相比 Ansible)它更适合于企业去部署。并且,更重要的是,Ansible Tower 甚至可以最多在 10 台设备上 _免费_ 使用,至少,你可以去体验一下,它是否会为你的组织带来好处,而无需花费一分钱,并且,也不需要与无数的销售代表去打交道。 -### 免费和开源软件(FOSS) +#### 可扩展性 -Ansible 是一个开源软件,它的全部代码在 GitHub 上都是公开的、可访问的,使用 Ansible 是完全免费的。它可以在几分钟内完成安装并为网络工程师提供有用的价值。Ansible,这个开源项目,或者 Ansible 公司,在它们交付软件之前,你不会遇到任何一个销售代表。那是显而易见的事实,因为它是一个真正的开源项目,但是,开源项目的使用,在网络行业中社区驱动的软件是非常少的,但是,也在逐渐增加,我们想明确指出这一点。 +我们在前面说过,Ansible 主要是为部署 Linux 应用程序而构建的自动化平台,虽然从早期开始已经扩展到 Windows。需要指出的是,Ansible 开源项目并没有“自动化网络基础设施”的目标。事实上是,Ansible 社区更明白如何在底层的 Ansible 架构上更具灵活性和可扩展性,对于他们的自动化需要(包括网络)更容易成为一个 _扩展_ 的 Ansible。在过去的两年中,部署有许多的 Ansible 集成,许多是有行业独立人士进行的,比如,Matt Oswalt、Jason Edelman、Kirk Byers、Elisa Jasinska、David Barroso、Michael Ben-Ami、Patrick Ogenstad 和 Gabriele Gerbino,也有网络系统供应商的领导者,比如,Arista、Juniper、Cumulus、Cisco、F5、和 Palo Alto Networks。 -同样需要指出的一点是,Ansible, Inc. 也是一个公司,它也需要去赚钱,对吗?虽然 Ansible 是开源的,它也有一个叫 Ansible Tower 的企业产品,它增加了一些特性,比如,基于规则的访问控制(RBAC)、报告、 web UI、REST APIs、多租户、等等,(相比 Ansible)它更适合于企业去部署。并且,更重要的是,Ansible Tower 甚至可以最多在 10 台设备上 _免费_ 使用,至少,你可以去体验一下,它是否会为你的组织带来好处,而无需花费一分钱,并且,也不需要与无数的销售代表去打交道。 +#### 集成到已存在的 DevOps 工作流中 +Ansible 在 IT 组织中被用于应用程序部署。它被用于需要管理部署、监视和管理各种类型的应用程序的运维团队中。通过将 Ansible 集成到网络基础设施中,当新应用程序到来或迁移后,它扩展了可能的范围。而不是去等待一个新的顶架交换机(LCTT 译注:TOR,一种数据中心设备接入的方式)的到来、去添加一个 VLAN、或者去检查接口的速度/双工,所有的这些以网络为中心的任务都可以被自动化,并且可以集成到 IT 组织内已经存在的工作流中。 -### 可扩展性 +#### 幂等性 -我们在前面说过,Ansible 主要是为部署 Linux 应用程序而构建的自动化平台,虽然从早期开始已经扩展到 Windows。需要指出的是,Ansible 开源项目并没有自动化网络基础设施的目标。事实上是,Ansible 社区更多地理解了在底层的 Ansible 架构上怎么更具灵活性和可扩展性,对于他们的自动化需要,它变成了 _扩展_ 的 Ansible,它包含了网络。在过去的两年中,部署有许多的 Ansible 集成,许多行业独立人士(industry independents),比如,Matt Oswalt、Jason Edelman、Kirk Byers、Elisa Jasinska、David Barroso、Michael Ben-Ami、Patrick Ogenstad、和 Gabriele Gerbino,以及网络系统供应商的领导者,比如,Arista、Juniper、Cumulus、Cisco、F5、和 Palo Alto Networks。 +术语幂等性idempotency (读作 item-potency)经常用于软件开发的领域中,尤其是当使用 REST API 工作的时候,以及在 _DevOps_ 自动化和配置管理框架的领域中,包括 Ansible。Ansible 的其中一个信念是,所有的 Ansible 模块(集成的)应该是幂等的。那么,对于一个模块来说,幂等是什么意思呢?毕竟,对大多数网络工程师来说,这是一个新的术语。 +答案很简单。幂等性的本质是允许定义的任务,运行一次或者上千次都不会在目标系统上产生不利影响,仅仅是一种一次性的改变。换句话说,如果有一个要做的改变去使系统进入到它期望的状态,这种改变完成之后,并且,如果这个设备已经达到这种状态,就不会再发生改变。这不像大多数传统的定制脚本和拷贝、黏贴到那些终端窗口中的 CLI 命令。当相同的命令或者脚本在同一个系统上重复运行,(有时候)会出现错误。即使是粘贴一组命令到一个路由器中,也可能会遇到一些使你的其余的配置失效的错误。好玩吧? -### 集成到已存在的 DevOps 工作流中 +另外的例子是,如果你有一个配置 10 个 VLAN 的文件文件或者脚本,那么 _每次_ 运行这个脚本,相同的命令命令会被输入 10 次。如果使用一个幂等的 Ansible 模块,首先会从网络设备中采集已存在的配置,并且,每个新的 VLAN 被配置后会再次检查当前配置。仅仅当这个新的 VLAN 需要被添加(或者,比如说改变 VLAN 名字)是一个变更,命令才会真实地推送到设备。 -Ansible 在 IT 组织中被用于应用程序部署。它被用于需要管理部署、监视、和管理各种类型的应用程序的操作团队中。通过将 Ansible 集成到网络基础设施中,当新应用程序到来或迁移后,它扩展了可能的范围。而不是去等待一个新的顶架交换机(TOR,译者注:一种数据中心设备接入的方式)的到来、去添加一个 VLAN、或者去检查接口的速度/双工,所有的这些以网络为中心的任务都可以被自动化,并且可以集成到 IT 组织内已经存在的工作流中。 +当一个技术越来越复杂,幂等性的价值就越高,在你修改的时候,你并不能注意到 _已存在_ 的网络设备的状态,而仅仅是从一个网络配置和策略角度去尝试达到 _期望的_ 状态。 +#### 网络范围的和临时(Ad Hoc)的改变 -### 幂等性 +用配置管理工具解决的其中一个问题是,配置“飘移”(当设备的期望配置逐渐漂移,或者改变,随着时间的推移,手动改变和/或在一个环境中使用了多个不同的工具),事实上,这也是像 Puppet 和 Chef 所使用的地方。代理商电联phone home到前端服务器,验证它的配置,并且,如果需要变更,则改变它。这个方法是非常简单的。如果有故障了,需要去排除怎么办?你通常需要跳过管理系统,直接连到设备,找到并修复它,然后,马上离开,对不对?果然,在下次当代理电连回来,这个修复问题的改变被覆盖了(基于主/前端服务器是怎么配置的)。在高度自动化的环境中,一次性的改变应该被限制,但是,仍然允许使用它们(LCTT 译注:指的是一次性改变)的工具是非常有价值的。正如你想到的,其中一个这样的工具是 Ansible。 -术语 _幂等性_ (明显能提升项目的效能) 经常用于软件开发的领域中,尤其是当使用 REST APIs工作的时候,以及在 _DevOps_ 自动化和配置管理框架的领域中,包括 Ansible。Ansible 的其中一个信念是,所有的 Ansible 模块(集成的)应该是幂等的。那么,对于一个模块来说,幂等是什么意思呢?毕竟,对大多数网络工程师来说,这是一个新的术语。 +因为 Ansible 是无代理的,这里并没有一个默认的推送或者拉取去防止配置漂移。自动化任务被定义在 Ansible playbook中,当使用 Ansible 时,它让用户去运行剧本。如果剧本在一个给定的时间间隔内运行,并且你没有用 Ansible Tower,你肯定知道任务的执行频率;如果你只是在终端提示符下使用一个原生的 Ansible 命令行,那么该剧本就运行一次,并且仅运行一次。 -答案很简单。幂等性的本质是允许定义的任务,运行一次或者上千次都不会在目标系统上产生不利影响,仅仅是一种一次性的改变。换句话说,如果一个请求的改变去使系统进入到它期望的状态,这种改变完成之后,并且,如果这个设备已经达到这种状态,它不会再发生改变。这不像大多数传统的定制脚本,和拷贝(copy),以及过去的那些终端窗口中的 CLI 命令。当相同的命令或者脚本在同一个系统上重复运行,会出现错误(有时候)。以前,粘贴一组命令到一个路由器中,然后得到一些使你的其余的配置失效的错误类型?好玩吧? - -另外的例子是,如果你有一个配置 10 个 VLANs 的文件文件或者脚本,那么 _每次_ 运行这个脚本,相同的命令命令会被输入 10 次。如果使用一个幂等的 Ansible 模块,首先会从网络设备中采集已存在的配置,并且,每个新的 VLAN 被配置后会再次检查当前配置。仅仅是这个新的 VLAN 需要去被添加(或者,改变 VLAN 名字,作为一个示例)是一个改变,或者命令真实地推送到设备。 - -当一个技术越来越复杂,幂等性的价值就越高,在你修改的时候,你并不能注意到 _已存在_ 的网络设备的状态,仅仅是从一个网络配置和策略角度去尝试达到 _期望的_ 状态。 - - -### 网络范围的和临时(Ad Hoc)的改变 - -用配置管理工具解决的其中一个问题是,配置“飘移”(当设备的期望配置逐渐漂移,或者改变,随着时间的推移手动改变和/或在一个环境中使用了多个不同的工具),事实上,这也是像 Puppet 和 Chef 得到使用的地方。代理商 _phone home_ 到前端服务器,验证它的配置,并且,如果需要一个改变,则改变它。这个方法是非常简单的。如果有故障了,需要去排除怎么办?你通常需要通过管理系统,直接连到设备,找到并修复它,然后,马上离开,对不对?果然,在下次当代理的电话打到家里,修复问题的改变被覆盖了(基于主/前端服务器是怎么配置的)。在高度自动化的环境中,一次性的改变应该被限制,但是,仍然允许它们(译者注:指的是一次性改变)使用的工具是非常有价值的。正如你想到的,其中一个这样的工具是 Ansible。 - -因为 Ansible 是无代理的,这里并没有一个默认的推送或者拉取去防止配置漂移。自动化任务被定义在 Ansible playbook 中,当使用 Ansible 时,它推送到用户去运行 playbook。如果 playbook 在一个给定的时间间隔内运行,并且你没有用 Ansible Tower,你肯定知道任务的执行频率;如果你正好在终端提示符下使用一个原生的 Ansible 命令行,playbook 运行一次,并且仅运行一次。 - -缺省运行的 playbook 对网络工程师是很具有吸引力的,让人欣慰的是,在设备上手动进行的改变不会自动被覆盖。另外,当需要的时候,一个 playbook 运行的设备范围很容易被改变,即使是对一个单个设备进行自动化的单次改变,Ansible 仍然可以用,设备的 _范围_ 由一个被称为 Ansible 清单(inventory)的文件决定;这个清单可以是一台设备或者是一千台设备。 +缺省运行一次的剧本对网络工程师是很具有吸引力的,让人欣慰的是,在设备上手动进行的改变不会自动被覆盖。另外,当需要的时候,一个剧本所运行的设备范围很容易被改变,即使是对一个单个设备进行自动化的单次变更,Ansible 仍然可以用,设备的 _范围_ 由一个被称为 Ansible 清单inventory的文件决定;这个清单可以是一台设备或者是一千台设备。 下面展示的一个清单文件示例,它定义了两组共六台设备: @@ -172,13 +165,13 @@ leaf3 leaf4 ``` -为了自动化所有的主机,你的 play 定义的 playbook 的一个片段看起来应该是这样的: +为了自动化所有的主机,你的剧本中的剧集play定义的一个片段看起来应该是这样的: ``` hosts: all ``` -并且,一个自动化的叶子节点交换机,它看起来应该像这样: +并且,要只自动化一个叶子节点交换机,它看起来应该像这样: ``` hosts: leaf1 @@ -190,27 +183,27 @@ hosts: leaf1 hosts: core-switches ``` -###### 注意 +> 注意 -正如前面所说的那样,这个报告的后面部分将详细介绍 playbooks、plays、和清单(inventories)。 +> 正如前面所说的那样,这个报告的后面部分将详细介绍剧本、剧集、和清单。 -因为能够很容易地对一台设备或者 _N_ 台设备进行自动化,所以在需要对这些设备进行一次性改变时,Ansible 成为了最佳的选择。在网络范围内的改变它也做的很好:可以是关闭给定类型的所有接口、配置接口描述、或者是在一个跨企业园区布线的网络中添加 VLANs。 +因为能够很容易地对一台设备或者 _N_ 台设备进行自动化,所以在需要对这些设备进行一次性变更时,Ansible 成为了最佳的选择。在网络范围内的变更它也做的很好:可以是关闭给定类型的所有接口、配置接口描述、或者是在一个跨企业园区布线的网络中添加 VLAN。 ### 使用 Ansible 实现网络任务自动化 这个报告从两个方面逐渐深入地讲解一些技术。第一个方面是围绕 Ansible 架构和它的细节,第二个方面是,从一个网络的角度,讲解使用 Ansible 可以完成什么类型的自动化。在这一章中我们将带你去详细了解第二方面的内容。 -自动化一般被认为是速度快,但是,考虑到一些任务并不要求速度,这就是为什么一些 IT 团队没有认识到自动化的价值所在。VLAN 配置是一个非常好的例子,因为,你可能会想,“创建一个 VLAN 到底有多快?一般情况下每天添加多少个 VLANs?我真的需要自动化吗?” +自动化一般被认为是速度快,但是,考虑到一些任务并不要求速度,这就是为什么一些 IT 团队没有认识到自动化的价值所在。VLAN 配置是一个非常好的例子,因为,你可能会想,“创建一个 VLAN 到底有多快?一般情况下每天添加多少个 VLAN?我真的需要自动化吗?” -在这一节中,我们专注于另外几种有意义的自动化任务,比如,设备准备、数据收集、报告、和遵从情况。但是,需要注意的是,正如我们前面所说的,自动化为你、你的团队、以及你的精确的更可预测的结果和更多的确定性,提供了更快的速度和敏捷性。 +在这一节中,我们专注于另外几种有意义的自动化任务,比如,设备准备、数据收集、报告和遵从情况。但是,需要注意的是,正如我们前面所说的,自动化为你、你的团队、以及你的精确的更可预测的结果和更多的确定性,提供了更快的速度和敏捷性。 -### 设备准备 +#### 设备准备 -为网络自动化开始使用 Ansible 的最容易也是最快的方法是,为设备最初投入使用创建设备配置文件,并且将配置文件推送到网络设备中。 +为网络自动化开始使用 Ansible 的最容易也是最快的方法是,为设备的最初投入使用创建设备配置文件,并且将配置文件推送到网络设备中。 如果我们去完成这个过程,它将分解为两步,第一步是创建一个配置文件,第二步是推送这个配置到设备中。 -首先,我们需要去从供应商配置文件的底层专用语法(CLI)中解耦 _输入_。这意味着我们需要对配置参数中分离出文件和值,比如,VLANs、域信息、接口、路由、和其它的内容、等等,然后,当然是一个配置的模块文件。在这个示例中,这里有一个标准模板,它可以用于所有设备的初始部署。Ansible 将帮助提供配置模板中需要的输入和值之间的部分。几秒钟之内,Ansible 可以生成数百个可靠的和可预测的配置文件。 +首先,我们需要去从供应商配置文件的底层专用语法(CLI)中解耦 _输入_。这意味着我们需要对配置参数中分离出文件和值,比如,VLAN、域信息、接口、路由、和其它的内容等等,然后,当然是一个配置的模块文件。在这个示例中,这里有一个标准模板,它可以用于所有设备的初始部署。Ansible 将帮助提供配置模板中需要的输入和值之间的部分。几秒钟之内,Ansible 可以生成数百个可靠的和可预测的配置文件。 让我们快速的看一个示例,它使用当前的配置,并且分解它到一个模板和单独的一个(作为一个输入源的)变量文件中。 @@ -238,13 +231,13 @@ vlan 50 如果我们提取输入值,这个文件将被转换成一个模板。 -###### 注意 +> 注意: -Ansible 使用基于 Python 的 Jinja2 模板化语言,因此,这个被命名为 _leaf.j2_ 的文件是一个 Jinja2 模板。 +> Ansible 使用基于 Python 的 Jinja2 模板化语言,因此,这个被命名为 _leaf.j2_ 的文件是一个 Jinja2 模板。 -注意,下列的示例中,_双大括号({{)_ 代表一个变量。 +注意,下列的示例中,_双大括号(`{{}}`)_ 代表一个变量。 -模板看起来像这些,并且给它命名为  _leaf.j2_: +模板看起来像这些,并且给它命名为  `leaf.j2`: ``` ! @@ -273,17 +266,17 @@ vlans: - { id: 50, name: misc } ``` -这意味着,如果管理 VLANs 的团队希望在网络设备中添加一个 VLAN,很简单,他们只需要在变量文件中改变它,然后,使用 Ansible 中一个叫 `template` 的模块,去重新生成一个新的配置文件。这整个过程也是幂等的;仅仅是在模板或者值发生改变时,它才会去生成一个新的配置文件。 +这意味着,如果管理 VLAN 的团队希望在网络设备中添加一个 VLAN,很简单,他们只需要在变量文件中改变它,然后,使用 Ansible 中一个叫 `template` 的模块,去重新生成一个新的配置文件。这整个过程也是幂等的;仅仅是在模板或者值发生改变时,它才会去生成一个新的配置文件。 一旦配置文件生成,它需要去 _推送_ 到网络设备。推送配置文件到网络设备使用一个叫做 `napalm_install_config`的开源的 Ansible 模块。 -接下来的示例是一个简单的 playbook 去 _构建并推送_ 一个配置文件到网络设备。同样地,playbook 使用一个名叫 `template` 的模块去构建配置文件,然后使用一个名叫 `napalm_install_config` 的模块去推送它们,并且激活它作为设备上运行的新的配置文件。 +接下来的示例是一个 _构建并推送_ 一个配置文件到网络设备的简单剧本。同样地,该剧本使用一个名叫 `template` 的模块去构建配置文件,然后使用一个名叫 `napalm_install_config` 的模块去推送它们,并且激活它作为设备上运行的新的配置文件。 虽然没有详细解释示例中的每一行,但是,你仍然可以看明白它们实际上做了什么。 -###### 注意 +> 注意: -下面的 playbook 介绍了新的概念,比如,内置变量 `inventory_hostname`。这些概念包含在 [Ansible 术语和入门][1] 中。 +> 下面的剧本介绍了新的概念,比如,内置变量 `inventory_hostname`。这些概念包含在 [Ansible 术语和入门][1] 中。 ``` --- @@ -310,17 +303,17 @@ vlans: replace_config=0 ``` -这个两步的过程是一个使用 Ansible 进行网络自动化入门的简单方法。通过模板简化了你的配置,构建配置文件,然后,推送它们到网络设备 — 因此,被称为 _BUILD 和 PUSH_ 方法。 +这个两步的过程是一个使用 Ansible 进行网络自动化入门的简单方法。通过模板简化了你的配置,构建配置文件,然后,推送它们到网络设备 — 因此,被称为 `BUILD` 和 `PUSH` 方法。 -###### 注意 +> 注意: -像这样的更详细的例子,请查看 [Ansible 网络集成][2]。 +> 像这样的更详细的例子,请查看 [Ansible 网络集成][2]。 -### 数据收集和监视 +#### 数据收集和监视 -监视工具一般使用 SNMP — 这些工具拉某些管理信息库(MIBs),然后给监视工具返回数据。基于返回的数据,它可能多于也可能少于你真正所需要的数据。如果接口基于返回的数据统计你正在拉的内容,你可能会返回在 _show interface_ 命令中显示的计数器。如果你仅需要 _interface resets_ 并且,希望去看到与重置相关的邻接 CDP/LLDP 的接口,那该怎么做呢?当然,这也可以使用当前的技术;可以运行多个显示命令去手动解析输出信息,或者,使用基于 SNMP 的工具,在 GUI 中切换不同的选项卡(Tab)找到真正你所需要的数据。Ansible 怎么能帮助我们去完成这些工作呢? +监视工具一般使用 SNMP —— 这些工具拉取某些管理信息库(MIB),然后给监视工具返回数据。基于返回的数据,它可能多于也可能少于你真正所需要的数据。如果接口基于返回的数据统计你正在拉取的内容,你可能会返回在 `show interface` 命令中显示的计数器。如果你仅需要 `interface resets` 并且,希望去看到与重置相关的邻接 CDP/LLDP 的接口,那该怎么做呢?当然,这也可以使用当前的技术;可以运行多个显示命令去手动解析输出信息,或者,使用基于 SNMP 的工具,在 GUI 中切换不同的选项卡(Tab)找到真正你所需要的数据。Ansible 怎么能帮助我们去完成这些工作呢? -由于 Ansible 是完全开放并且是可扩展的,它可以精确地去收集和监视所需要的计数器或者值。这可能需要一些预先的定制工作,但是,最终这些工作是非常有价值的。因为采集的数据是你所需要的,而不是供应商提供给你的。Ansible 也提供直观的方法去执行某些条件任务,这意味着基于正在返回的数据,你可以执行子任务,它可以收集更多的数据或者产生一个配置改变。 +由于 Ansible 是完全开源并且是可扩展的,它可以精确地去收集和监视所需要的计数器或者值。这可能需要一些预先的定制工作,但是,最终这些工作是非常有价值的。因为采集的数据是你所需要的,而不是供应商提供给你的。Ansible 也提供了执行某些条件任务的直观方法,这意味着基于正在返回的数据,你可以执行子任务,它可以收集更多的数据或者产生一个配置改变。 网络设备有 _许多_ 统计和隐藏在里面的临时数据,而 Ansible 可以帮你提取它们。 @@ -342,26 +335,23 @@ vlans: 你现在可以决定某些事情,而不需要事先知道是什么类型的设备。你所需要知道的仅仅是设备的只读通讯字符串。 +#### 迁移 -### 迁移 +从一个平台迁移到另外一个平台,可能是从同一个供应商或者是从不同的供应商,迁移从来都不是件容易的事。供应商可能提供一个脚本或者一个工具去帮助你迁移。Ansible 可以被用于去为所有类型的网络设备构建配置模板,然后,操作系统用这个方法去为所有的供应商生成一个配置文件,然后作为一个(通用数据模型的)输入设置。当然,如果有供应商专用的扩展,它也是会被用到的。这种灵活性不仅对迁移有帮助,而且也可以用于灾难恢复disaster recovery(DR),它在生产系统中不同的交换机型号之间和灾备数据中心中是经常使用的,即使是在不同的供应商的设备上。 -从一个平台迁移到另外一个平台,可能是从同一个供应商或者是从不同的供应商,迁移从来都不是件容易的事。供应商可能提供一个脚本或者一个工具去帮助你迁移。Ansible 可以被用于去为所有类型的网络设备构建配置模板,然后,操作系统用这个方法去为所有的供应商生成一个配置文件,然后作为一个(通用数据模型的)输入设置。当然,如果有供应商专用的扩展,它也是会被用到的。这种灵活性不仅对迁移有帮助,而且也可以用于灾难恢复(DR),它在生产系统中不同的交换机型号之间和灾备数据中心中是经常使用的,即使是在不同的供应商的设备上。 +#### 配置管理 +正如前面所说的,配置管理是最常用的自动化类型。Ansible 可以很容易地做到创建角色role去简化基于任务的自动化。从更高的层面来看,角色是指针对一个特定设备组的可重用的自动化任务的逻辑分组。关于角色的另一种说法是,认为角色就是相关的工作流workflow。首先,在开始自动化添加值之前,需要理解工作流和过程。不论是开始一个小的自动化任务还是扩展它,理解工作流和过程都是非常重要的。 -### 配置管理 - -正如前面所说的,配置管理是最常用的自动化类型。Ansible 可以很容易地做到创建 _角色(roles)_ 去简化基于任务的自动化。从更高的层面来看,角色是指针对一个特定设备组的可重用的自动化任务的逻辑分组。关于角色的另一种说法是,认为角色就是相关的工作流(workflows)。首先,在开始自动化添加值之前,需要理解工作流和过程。不论是开始一个小的自动化任务还是扩展它,理解工作流和过程都是非常重要的。 - -例如,一组自动化配置路由器和交换机的任务是非常常见的,并且它们也是一个很好的起点。但是,配置在哪台网络设备上?配置的 IP 地址是什么?或许需要一个 IP 地址管理方案?一旦用一个给定的功能分配了 IP 地址并且已经部署,DNS 也更新了吗?DHCP 的范围需要创建吗? +例如,一组自动化地配置路由器和交换机的任务是非常常见的,并且它们也是一个很好的起点。但是,配置在哪台网络设备上?配置的 IP 地址是什么?或许需要一个 IP 地址管理方案?一旦用一个给定的功能分配了 IP 地址并且已经部署,DNS 也更新了吗?DHCP 的范围需要创建吗? 你可以看到工作流是怎么从一个小的任务开始,然后逐渐扩展到跨不同的 IT 系统?因为工作流持续扩展,所以,角色也一样(持续扩展)。 +#### 遵从性 -### 遵从性 +和其它形式的自动化工具一样,用任何形式的自动化工具产生配置改变都被视为风险。手工去产生改变可能看上去风险更大,正如你看到的和亲身经历过的那样,Ansible 有能力去做自动数据收集、监视、和配置构建,这些都是“只读的”和“低风险”的动作。其中一个 _低风险_ 使用案例是,使用收集的数据进行配置遵从性检查和配置验证。部署的配置是否满足安全要求?是否配置了所需的网络?协议 XYZ 禁用了吗?因为每个模块、或者用 Ansible 返回数据的整合,它只是非常简单地 _声明_ 那些事是 _TRUE_ 还是 _FALSE_。然后接着基于 _它_ 是 _TRUE_ 或者是 _FALSE_, 接着由你决定应该发生什么 —— 或许它只是被记录下来,或者,也可能执行一个复杂操作。 -和其它形式的自动化工具一样,用任何形式的自动化工具产生配置改变都视为风险。手工去产生改变可能看上去风险更大,正如你看到的和亲身经历过的那样,Ansible 有能力去做自动数据收集、监视、和配置构建,这些都是“只读的”和“低风险”的动作。其中一个 _低风险_ 使用案例是,使用收集的数据进行配置遵从性检查和配置验证。部署的配置是否满足安全要求?是否配置了所需的网络?协议 XYZ 禁用了吗?因为每个模块、或者用 Ansible 返回数据的整合,它只是非常简单地 _声明_ 那些事是 _TRUE_ 还是 _FALSE_。然后接着基于 _它_ 是 _TRUE_ 或者是 _FALSE_, 接着由你决定应该发生什么 —— 或许它只是被记录下来,或者,也可能执行一个复杂操作。 - -### 报告 +#### 报告 我们现在知道,Ansible 也可以用于去收集数据和执行遵从性检查。Ansible 可以根据你想要做的事情去从设备中返回和收集数据。或许返回的数据成为其它的任务的输入,或者你想去用它创建一个报告。从模板中生成报告,并将真实的数据插入到模板中,创建和使用报告模板的过程与创建配置模板的过程是相同的。 @@ -369,22 +359,21 @@ vlans: 创建报告的用处很多,不仅是为行政管理,也为了运营工程师,因为它们通常有双方都需要的不同指标。 - ### Ansible 怎么工作 -从一个网络自动化的角度理解了 Ansible 能做什么之后,我们现在看一下 Ansible 是怎么工作的。你将学习到从一个 Ansible 管理主机到一个被自动化的节点的全部通讯流。首先,我们回顾一下,Ansible 是怎么 _开箱即用的(out of the box)_,然后,我们看一下 Ansible 怎么去做到的,具体说就是,当网络设备自动化时,Ansible _模块_是怎么去工作的。 +从一个网络自动化的角度理解了 Ansible 能做什么之后,我们现在看一下 Ansible 是怎么工作的。你将学习到从一个 Ansible 管理主机到一个被自动化的节点的全部通讯流。首先,我们回顾一下,Ansible 是怎么开箱即用out of the box的,然后,我们看一下 Ansible 怎么去做到的,具体说就是,当网络设备自动化时,Ansible _模块_是怎么去工作的。 -### 开箱即用 +#### 开箱即用 到目前为止,你已经明白了,Ansible 是一个自动化平台。实际上,它是一个安装在一台单个服务器上或者企业中任何一位管理员的笔记本中的轻量级的自动化平台。当然,(安装在哪里?)这是由你来决定的。在基于 Linux 的机器上,使用一些实用程序(比如 pip、apt、和 yum)安装 Ansible 是非常容易的。 -###### 注意 +> 注意: -在本报告的其余部分,安装 Ansible 的机器被称为 _控制主机_。 +> 在本报告的其余部分,安装 Ansible 的机器被称为控制主机control host。 -控制主机将执行在 Ansible 的 playbook (不用担心,稍后我们将讲到 playbook 和其它的 Ansible 术语)中定义的所有自动化任务。现在,我们只需要知道,一个 playbook 是简单的一组自动化任务和在给定数量的主机上执行的指令。 +控制主机将执行定义在 Ansible 的剧本playbook (不用担心,稍后我们将讲到剧本和其它的 Ansible 术语)中的所有自动化任务。现在,我们只需要知道,一个剧本是简单的一组自动化任务和在给定数量的主机上执行的指令。 -当一个 playbook 创建之后,你还需要去定义它要自动化的主机。映射一个 playbook 和要自动化运行的主机,是通过一个被称为 Ansible 清单的文件。这是一个前面展示的示例,但是,这里是同一个清单文件的另外两个组:`cisco` 和 `arista`: +当一个剧本创建之后,你还需要去定义它要自动化的主机。映射一个剧本和要自动化运行的主机,是通过一个被称为 Ansible 清单inventory的文件。这是一个前面展示的示例,但是,这里是同一个清单文件的另外两个组:`cisco` 和 `arista`: ``` [cisco] @@ -396,13 +385,13 @@ sfo1.acme.com sfo2.acme.com ``` -###### 注意 +> 注意: -你也可以在清单文件中使用 IP 地址,而不是主机名。对于这样的示例,主机名将是通过 DNS 可解析的。 +> 你也可以在清单文件中使用 IP 地址,而不是主机名。对于这样的示例,主机名将是通过 DNS 可解析的。 -正如你所看到的,Ansible 清单文件是一个文本文件,它列出了主机和主机组。然后,你可以在 playbook 中引用一个具体的主机或者组,以此去决定对给定的 play 和 playbook 在哪台主机上进行自动化。下面展示了两个示例。 +正如你所看到的,Ansible 清单文件是一个文本文件,它列出了主机和主机组。然后,你可以在剧本中引用一个具体的主机或者组,以此去决定对给定的剧集play和剧本在哪台主机上进行自动化。下面展示了两个示例。 -展示的第一个示例它看上去像是,你想去自动化 `cisco` 组中所有的主机,而展示的第二个示例只对 _nyc1.acme.com_ 主机进行自动化: +展示的第一个示例它看上去像是,你想去自动化 `cisco` 组中所有的主机,而展示的第二个示例只对 `nyc1.acme.com` 主机进行自动化: ``` --- @@ -424,7 +413,7 @@ sfo2.acme.com - TASKS YOU WANT TO AUTOMATE ``` -现在,我们已经理解了基本的清单文件,我们可以看一下(在控制主机上的)Ansible 是怎么与 _开箱即用_ 的设备通讯的,和在 Linux 终端上自动化的任务。这里需要明白一个重要的观点就是,需要去自动化的网络设备通常是不一样的。(译者注:指的是设备的类型、品牌、型号等等) +现在,我们已经理解了基本的清单文件,我们可以看一下(在控制主机上的)Ansible 是怎么与 _开箱即用_ 的设备通讯的,和在 Linux 终端上自动化的任务。这里需要明白一个重要的观点就是,需要去自动化的网络设备通常是不一样的。(LCTT 译注:指的是设备的类型、品牌、型号等等) Ansible 对基于 Linux 的系统去开箱即用自动化工作有两个要求。它们是 SSH 和 Python。 @@ -434,31 +423,26 @@ Ansible 对基于 Linux 的系统去开箱即用自动化工作有两个要求 如果我们详细解释这个开箱即用工作流,它将分解成如下的步骤: -1. 当一个 Ansible play 被执行,控制主机使用 SSH 连接到基于 Linux 的目标节点。 - -2. 对于每个任务,也就是说,Ansible 模块将在这个 play 中被执行,通过 SSH 发送 Python 代码并直接在远程系统中执行。 - +1. 当执行一个 Ansible 剧集时,控制主机使用 SSH 连接到基于 Linux 的目标节点。 +2. 对于每个任务,也就是说,Ansible 模块将在这个剧集中被执行,通过 SSH 发送 Python 代码并直接在远程系统中执行。 3. 在远程系统上运行的每个 Ansible 模块将返回 JSON 数据到控制主机。这些数据包含有信息,比如,配置改变、任务成功/失败、以及其它模块特定的数据。 - 4. JSON 数据返回给 Ansible,然后被用于去生成报告,或者被用作接下来模块的输入。 +5. 在剧集中为每个任务重复第 3 步。 +6. 在剧本中为每个剧集重复第 1 步。 -5. 在 play 中为每个任务重复第 3 步。 - -6. 在 playbook 中为每个 play 重复第 1 步。 - -是不是意味着每个网络设备都可以被 Ansible 开箱即用?因为它们也都支持 SSH,确实,网络设备都支持 SSH,但是,它是第一个和第二要求的组合限制了网络设备可能的功能。 +是不是意味着每个网络设备都可以被 Ansible 开箱即用?因为它们也都支持 SSH,确实,网络设备都支持 SSH,但是,第一个和第二要求的组合限制了网络设备可能的功能。 刚开始时,大多数网络设备并不支持 Python,因此,使用默认的 Ansible 连接机制是无法进行的。换句话说,在过去的几年里,供应商在几个不同的设备平台上增加了 Python 支持。但是,这些平台中的大多数仍然缺乏必要的集成,以允许 Ansible 去直接通过 SSH 访问一个 Linux shell,并以适当的权限去拷贝所需的代码、创建临时目录和文件、以及在设备中执行代码。尽管 Ansible 中所有的这些部分都可以在基于 Linux 的网络设备上使用 SSH/Python 在本地运行,它仍然需要网络设备供应商去更进一步开放他们的系统。 -###### 注意 +> 注意: -值的注意的是,Arista 确实也提供了原生的集成,因为它可以放弃 SSH 用户,直接进入到一个 Linux shell 中访问 Python 引擎,它可以允许 Ansible 去使用默认连接机制。因为我们调用了 Arista,我们也需要着重强调与 Ansible 默认连接机制一起工作的 Cumulus。这是因为 Cumulus Linux 是原生 Linux,并且它并不需要为 Cumulus Linux 操作系统使用供应商 API。 +> 值的注意的是,Arista 确实也提供了原生的集成,因为它可以无需 SSH 用户,直接进入到一个 Linux shell 中访问 Python 引擎,它可以允许 Ansible 去使用其默认连接机制。因为我们调用了 Arista,我们也需要着重强调与 Ansible 默认连接机制一起工作的 Cumulus。这是因为 Cumulus Linux 是原生 Linux,并且它并不需要为 Cumulus Linux 操作系统使用供应商 API。 -### Ansible 网络集成 +#### Ansible 网络集成 -前面的节讲到过 Ansible 默认的工作方式。我们看一下,在开始一个 _play_ 之后,Ansible 是怎么去设置一个到设备的连接、通过执行拷贝 Python 代码到设备去运行任务、运行代码、和返回结果给 Ansible 控制主机。 +前面的节讲到过 Ansible 默认的工作方式。我们看一下,在开始一个 _剧集_ 之后,Ansible 是怎么去设置一个到设备的连接、通过拷贝 Python 代码到设备、运行代码、和返回结果给 Ansible 控制主机来执行任务。 -在这一节中,我们将看一看,当使用 Ansible 进行自动化网络设备时都做了什么。正如前面讲过的,Ansible 是一个可拔插的连接架构。对于 _大多数_ 的网络集成, `connection` 参数设置为 `local`。在 playbook 中大多数的连接类型都设置为 `local`,如下面的示例所展示的: +在这一节中,我们将看一看,当使用 Ansible 进行自动化网络设备时都做了什么。正如前面讲过的,Ansible 是一个可拔插的连接架构。对于 _大多数_ 的网络集成, `connection` 参数设置为 `local`。在剧本中大多数的连接类型都设置为 `local`,如下面的示例所展示的: ``` --- @@ -471,15 +455,15 @@ Ansible 对基于 Linux 的系统去开箱即用自动化工作有两个要求 - TASKS YOU WANT TO AUTOMATE ``` -注意在 play 中是怎么定义的,这个示例增加 `connection` 参数去和前面节中的示例进行比较。 +注意在剧集中是怎么定义的,这个示例增加 `connection` 参数去和前面节中的示例进行比较。 -这告诉 Ansible 不要通过 SSH 去连接到目标设备,而是连接到本地机器运行这个 playbook。基本上,这是把连接职责委托给 playbook 中 _任务_ 节中使用的真实的 Ansible 模块。每个模块类型的委托权利允许这个模块在必要时以各种形式去连接到设备。这可能是 Juniper 和 HP Comware7 的 NETCONF、Arista 的 eAPI、Cisco Nexus 的 NX-API、或者甚至是基于传统系统的 SNMP,它们没有可编程的 API。 +这告诉 Ansible 不要通过 SSH 去连接到目标设备,而是连接到本地机器运行这个剧本。基本上,这是把连接职责委托给剧本中任务task 节中使用的真实的 Ansible 模块。每个模块类型的委托权利允许这个模块在必要时以各种形式去连接到设备。这可能是 Juniper 和 HP Comware7 的 NETCONF、Arista 的 eAPI、Cisco Nexus 的 NX-API、或者甚至是基于传统系统的 SNMP,它们没有可编程的 API。 -###### 注意 +> 注意: -网络集成在 Ansible 中是以 Ansible 模块的形式带来的。尽管我们持续使用术语来吊你的胃口,比如,playbooks、plays、任务、和讲到的关键概念 `模块`,这些术语中的每一个都会在 [Ansible 术语和入门][3] 和 [动手实践使用 Ansible 去进行网络自动化][4] 中详细解释。 +> 网络集成在 Ansible 中是以 Ansible 模块的形式带来的。尽管我们持续使用术语来吊你的胃口,比如,剧本、剧集、任务、和讲到的关键概念模块,这些术语中的每一个都会在 [Ansible 术语和入门][3] 和 [动手实践使用 Ansible 去进行网络自动化][4] 中详细解释。 -让我们看一看另外一个 playbook 的示例: +让我们看一看另外一个剧本的示例: ``` --- @@ -492,22 +476,21 @@ Ansible 对基于 Linux 的系统去开箱即用自动化工作有两个要求 - nxos_vlan: vlan_id=10 name=WEB_VLAN ``` -你注意到了吗,这个 playbook 现在包含一个任务,并且这个任务使用了 `nxos_vlan` 模块。`nxos_vlan` 模块是一个 Python 文件,并且,在这个文件中它是使用 NX-API 连接到 Cisco 的 NX-OS 设备。可是,这个连接可能是使用其它设备 API 设置的,这就是为什么供应商和用户像我们这样能够去建立自己的集成的原因。集成(模块)通常是以每特性(per-feature)为基础完成的,虽然,你已经看到了像 `napalm_install_config` 这样的模块,它们也可以被用来 _推送_ 一个完整的配置文件。 +你注意到了吗,这个剧本现在包含一个任务,并且这个任务使用了 `nxos_vlan` 模块。`nxos_vlan` 模块是一个 Python 文件,并且,在这个文件中它是使用 NX-API 连接到 Cisco 的 NX-OS 设备。可是,这个连接可能是使用其它设备 API 设置的,这就是为什么供应商和用户像我们这样能够去建立自己的集成的原因。集成(模块)通常是以每特性per-feature为基础完成的,虽然,你已经看到了像 `napalm_install_config` 这样的模块,它们也可以被用来 _推送_ 一个完整的配置文件。 -主要区别之一是使用的默认连接机制,Ansible 启动一个持久的 SSH 连接到设备,并且这个连接为一个给定的 play 持续。当在一个模块中发生连接设置和拆除时,与许多使用 `connection=local` 的网络模块一样,对发生在 play 级别上的 _每个_ 任务,Ansible 将登入/登出设备。 +主要区别之一是使用的默认连接机制,Ansible 启动一个持久的 SSH 连接到设备,并且对于一个给定的剧集而已该连接将持续存在。当在一个模块中发生连接设置和拆除时,与许多使用 `connection=local` 的网络模块一样,对发生在剧集级别上的 _每个_ 任务,Ansible 将登入/登出设备。 -而在传统的 Ansible 形式下,每个网络模块返回 JSON 数据。仅有的区别是相对于目标节点,数据的推取发生在本地的 Ansible 控制主机上。相对于每供应商(per vendor)和模块类型,数据返回到 playbook,但是作为一个示例,许多的 Cisco NX-OS 模块返回已存在的状态、建议状态、和最终状态,以及发送到设备的命令(如果有的话)。 +而在传统的 Ansible 形式下,每个网络模块返回 JSON 数据。仅有的区别是相对于目标节点,数据的推取发生在本地的 Ansible 控制主机上。相对于每供应商per vendor和模块类型,数据返回到剧本,但是作为一个示例,许多的 Cisco NX-OS 模块返回已存在的状态、建议状态、和最终状态,以及发送到设备的命令(如果有的话)。 作为使用 Ansible 进行网络自动化的开始,最重要的是,为 Ansible 的连接设备/拆除过程,记着去设置连接参数为 `local`,并且将它留在模块中。这就是为什么模块支持不同类型的供应商平台,它将与设备使用不同的方式进行通讯。 - ### Ansible 术语和入门 -这一章我们将介绍许多 Ansible 的术语和报告中前面部分出现过的关键概念。比如, _清单文件_、_playbook_、_play_、_任务_、和 _模块_。我们也会去回顾一些其它的概念,这些术语和概念对我们学习使用 Ansible 去进行网络自动化非常有帮助。 +这一章我们将介绍许多 Ansible 的术语和报告中前面部分出现过的关键概念。比如, 清单文件inventory file剧本playbook剧集play任务task模块module。我们也会去回顾一些其它的概念,这些术语和概念对我们学习使用 Ansible 去进行网络自动化非常有帮助。 -在这一节中,我们将引用如下的一个简单的清单文件和 playbook 的示例,它们将在后面的章节中持续出现。 +在这一节中,我们将引用如下的一个简单的清单文件和剧本的示例,它们将在后面的章节中持续出现。 -_清单示例_: +_清单示例_ : ``` # sample inventory file @@ -528,7 +511,7 @@ core1 core2 ``` -_playbook 示例_: +_剧本示例_ : ``` --- @@ -577,54 +560,50 @@ _playbook 示例_: - 50 ``` -### 清单文件 +#### 清单文件 -使用一个清单文件,比如前面提到的那个,允许我们去为自动化任务指定主机、和使用每个 play 顶部节中(如果存在)的参数 `hosts` 所引用的主机/组指定的主机组。 +使用一个清单文件,比如前面提到的那个,允许我们去为自动化任务指定主机、和使用每个剧集顶部节中(如果存在)的参数 `hosts` 所引用的主机/组指定的主机组。 -它也可能在一个清单文件中存储变量。如这个示例中展示的那样。如果变量在同一行视为一台主机,它是一个具体主机变量。如果变量定义在方括号中(“[ ]”),比如,`[all:vars]`,它的意思是指变量在组中的范围 `all`,它是一个默认组,包含了清单文件中的 _所有_ 主机。 +它也可能在一个清单文件中存储变量。如这个示例中展示的那样。如果变量在同一行视为一台主机,它是一个具体主机变量。如果变量定义在方括号中(`[ ]`),比如,`[all:vars]`,它的意思是指变量在组中的范围 `all`,它是一个默认组,包含了清单文件中的 _所有_ 主机。 -###### 注意 +> 注意: -清单文件是使用 Ansible 开始自动化的快速方法,但是,你应该已经有一个真实的网络设备源,比如一个网络管理工具或者 CMDB,它可以去创建和使用一个动态的清单脚本,而不是一个静态的清单文件。 +> 清单文件是使用 Ansible 开始自动化的快速方法,但是,你应该已经有一个真实的网络设备源,比如一个网络管理工具或者 CMDB,它可以去创建和使用一个动态的清单脚本,而不是一个静态的清单文件。 -### Playbook +#### 剧本 -playbook 是去运行自动化网络设备的顶级对象。在我们的示例中,它是一个 _site.yml_ 文件,如前面的示例所展示的。一个 playbook 使用 YAML 去定义一组自动化任务,并且,每个 playbook 由一个或多个 plays 组成。这类似于一个橄榄球的剧本。就像在橄榄球赛中,团队有剧集组成的剧本,Ansible 的 playbooks 也是由 play 组成的。 +剧本是去运行自动化网络设备的顶级对象。在我们的示例中,它是 `site.yml` 文件,如前面的示例所展示的。一个剧本使用 YAML 去定义一组自动化任务,并且,每个剧本由一个或多个剧集组成。这类似于一个橄榄球的剧本。就像在橄榄球赛中,团队有剧集组成的剧本,Ansible 的剧本也是由剧集组成的。 -###### 注意 +> 注意: -YAML 是一种被所有编程语言支持的数据格式。YAML 本身就是 JSON 的超集,并且,YAML 文件非常易于识别,因为它总是三个破折号(连字符)开始,比如,`---`。 +> YAML 是一种被所有编程语言支持的数据格式。YAML 本身就是 JSON 的超集,并且,YAML 文件非常易于识别,因为它总是三个破折号(连字符)开始,比如,`---`。 -### Play +#### 剧集 -一个 Ansible playbook 可以存在一个或多个 plays。在前面的示例中,它在 playbook 中有两个 plays。每个 play 开始的地方都有一个 _header_ 节,它定义了具体的参数。 +一个 Ansible 剧本可以存在一个或多个剧集。在前面的示例中,它在剧本中有两个剧集。每个剧集开始的地方都有一个 _头部_,它定义了具体的参数。 -示例中两个 plays 都定义了下面的参数: +示例中两个剧集都定义了下面的参数: `name` -文件 `PLAY 1 - Top of Rack (TOR) Switches` 是任意内容的,它在 playbook 运行的时候,去改善 playbook 运行和报告期间的可读性。这是一个可选参数。 +文件 `PLAY 1 - Top of Rack (TOR) Switches` 是任意内容的,它在剧本运行的时候,去改善剧本运行和报告期间的可读性。这是一个可选参数。 `hosts` -正如前面讲过的,这是在特定的 play 中要去进行自动化的主机或主机组。这是一个必需参数。 +正如前面讲过的,这是在特定的剧集中要去进行自动化的主机或主机组。这是一个必需参数。 `connection` -正如前面讲过的,这是 play 连接机制的类型。这是个可选参数,但是,对于网络自动化 plays,一般设置为 `local`。 +正如前面讲过的,这是剧集连接机制的类型。这是个可选参数,但是,对于网络自动化剧集,一般设置为 `local`。 +每个剧集都是由一个或多个任务组成。 - -每个 play 都是由一个或多个任务组成。 - - - -### 任务 +#### 任务 任务是以声明的方式去表示自动化的内容,而不用担心底层的语法或者操作是怎么执行的。 -在我们的示例中,第一个 play 有两个任务。每个任务确保存在 10 个 VLAN。第一个任务是为 Cisco Nexus 设备的,而第二个任务是为 Arista 设备的: +在我们的示例中,第一个剧集有两个任务。每个任务确保存在 10 个 VLAN。第一个任务是为 Cisco Nexus 设备的,而第二个任务是为 Arista 设备的: ``` tasks: @@ -638,19 +617,17 @@ tasks: when: vendor == "nxos" ``` -任务也可以使用 `name` 参数,就像 plays 一样。和 plays 一样,文本内容是任意的,并且当 playbook 运行时显示,去改善 playbook 运行和报告期间的可读性。它对每个任务都是可选参数。 +任务也可以使用 `name` 参数,就像剧集一样。和剧集一样,文本内容是任意的,并且当剧本运行时显示,去改善剧本运行和报告期间的可读性。它对每个任务都是可选参数。 示例任务中的下一行是以 `nxos_vlan` 开始的。它告诉我们这个任务将运行一个叫 `nxos_vlan` 的 Ansible 模块。 现在,我们将进入到模块中。 +#### 模块 +在 Ansible 中理解模块的概念是至关重要的。虽然任何编辑语言都可以用来写 Ansible 模块,只要它们能够返回 JSON 键/值对即可,但是,几乎所有的模块都是用 Python 写的。在我们示例中,我们看到有两个模块被运行: `nxos_vlan` 和 `eos_vlan`。这两个模块都是 Python 文件;而事实上,在你不能看到剧本的时候,真实的文件名分别是 `eos_vlan.py` 和 `nxos_vlan.py`。 -### 模块 - -在 Ansible 中理解模块的概念是至关重要的。虽然任何编辑语言都可以用来写 Ansible 模块,只要它们能够返回 JSON 键 — 值对即可,但是,几乎所有的模块都是用 Python 写的。在我们示例中,我们看到有两个模块被运行: `nxos_vlan` 和 `eos_vlan`。这两个模块都是 Python 文件;而事实上,在你不能看到 playbook 的时候,真实的文件名分别是 _eos_vlan.py_ 和 _nxos_vlan.py_。 - -让我们看一下前面的示例中第一个 play 中的第一个 任务: +让我们看一下前面的示例中第一个剧集中的第一个任务: ``` - name: ENSURE VLAN 10 EXISTS ON CISCO TOR SWITCHES @@ -678,48 +655,39 @@ tasks: 用于登入到交换机的密码。 +示例中最后的片断部分使用了一个 `when` 语句。这是在一个剧集中使用的 Ansible 的执行条件任务。正如我们所了解的,在这个剧集的 `tor` 组中有多个设备和设备类型。使用 `when` 基于任意标准去提供更多的选择。这里我们仅自动化 Cisco 设备,因为,我们在这个任务中使用了 `nxos_vlan` 模块,在下一个任务中,我们仅自动化 Arista 设备,因为,我们使用了 `eos_vlan` 模块。 -示例中最后的片断部分使用了一个 `when` 语句。这是在一个 play 中使用的 Ansible 的执行条件任务。正如我们所了解的,在这个 play 的 `tor` 组中有多个设备和设备类型。使用 `when` 基于任意标准去提供更多的选择。这里我们仅自动化 Cisco 设备,因为,我们在这个任务中使用了 `nxos_vlan` 模块,在下一个任务中,我们仅自动化 Arista 设备,因为,我们使用了 `eos_vlan` 模块。 +> 注意: -###### 注意 - -这并不是区分设备的唯一方法。这里仅是演示如何使用 `when`,并且可以在清单文件中定义变量。 +> 这并不是区分设备的唯一方法。这里仅是演示如何使用 `when`,并且可以在清单文件中定义变量。 在清单文件中定义变量是一个很好的开端,但是,如果你继续使用 Ansible,你将会为了扩展性、版本控制、对给定文件的改变最小化而去使用基于 YAML 的变量。这也将简化和改善清单文件和每个使用的变量的可读性。在设备准备的构建/推送方法中讲过一个变量文件的示例。 在最后的示例中,关于任务有几点需要去搞清楚: -* Play 1 任务 1 展示了硬编码了 `username` 和 `password` 作为参数进入到具体的模块中(`nxos_vlan`)。 - -* Play 1 任务 1 和 play 2 在模块中使用了变量,而不是硬编码它们。这掩饰了 `username` 和 `password` 参数,但是,需要值得注意的是,(在这个示例中)这些变量是从清单文件中提取出现的。 - -* Play 1 中为进入到模块中的参数使用了一个 _水平的(horizontal)_ 的 key=value 语法,虽然 play 2 使用了垂直的(vertical) key=value 语法。它们都工作的非常好。你也可以使用垂直的 YAML “key: value” 语法。 - -* 最后的任务也介绍了在 Ansible 中怎么去使用一个 _loop_ 循环。它通过使用 `with_items` 来完成,并且它类似于一个 for 循环。那个特定的任务是循环进入五个 VLANs 中去确保在交换机中它们都存在。注意:它也可能被保存在一个外部的 YAML 变量文件中。还需要注意的一点是,不使用 `with_items` 的替代方案是,每个 VLAN 都有一个任务 —— 如果这样做,它就失去了弹性! - +* 剧集 1 任务 1 展示了硬编码了 `username` 和 `password` 作为参数进入到具体的模块中(`nxos_vlan`)。 +* 剧集 1 任务 1 和 剧集 2 在模块中使用了变量,而不是硬编码它们。这掩饰了 `username` 和 `password` 参数,但是,需要值得注意的是,(在这个示例中)这些变量是从清单文件中提取出现的。 +* 剧集 1 中为进入到模块中的参数使用了一个 _水平的_ 的 key=value 语法,虽然剧集 2 使用了垂直的 key=value 语法。它们都工作的非常好。你也可以使用垂直的 YAML “key: value” 语法。 +* 最后的任务也介绍了在 Ansible 中怎么去使用一个循环。它通过使用 `with_items` 来完成,并且它类似于一个 for 循环。那个特定的任务是循环进入五个 VLAN 中去确保在交换机中它们都存在。注意:它也可能被保存在一个外部的 YAML 变量文件中。还需要注意的一点是,不使用 `with_items` 的替代方案是,每个 VLAN 都有一个任务 —— 如果这样做,它就失去了弹性! ### 动手实践使用 Ansible 去进行网络自动化 -在前面的章节中,提供了 Ansible 术语的一个概述。它已经覆盖了大多数具体的 Ansible 术语,比如 playbooks、plays、任务、模块、和清单文件。这一节将继续提供示例去讲解使用 Ansible 实现网络自动化,而且将提供在不同类型的设备中自动化工作的模块的更多细节。示例中的将要进行自动化设备由多个供应商提供,包括 Cisco、Arista、Cumulus、和 Juniper。 +在前面的章节中,提供了 Ansible 术语的一个概述。它已经覆盖了大多数具体的 Ansible 术语,比如剧本、剧集、任务、模块和清单文件。这一节将继续提供示例去讲解使用 Ansible 实现网络自动化,而且将提供在不同类型的设备中自动化工作的模块的更多细节。示例中的将要进行自动化设备由多个供应商提供,包括 Cisco、Arista、Cumulus、和 Juniper。 在本节中的示例,假设的前提条件如下: * Ansible 已经安装。 - * 在设备中(NX-API、eAPI、NETCONF)适合的 APIs 已经启用。 - * 用户在系统上有通过 API 去产生改变的适当权限。 - * 所有的 Ansible 模块已经在系统中存在,并且也在库的路径变量中。 -###### 注意 +> 注意: -可以在 _ansible.cfg_ 文件中设置模块和库路径。在你运行一个 playbook 时,你也可以使用 `-M` 标志从命令行中去改变它。 +> 可以在 `ansible.cfg` 文件中设置模块和库路径。在你运行一个剧本时,你也可以使用 `-M` 标志从命令行中去改变它。 -在本节中示例使用的清单如下。(删除了密码,IP 地址也发生了变化)。在这个示例中,(和前面的示例一样)某些主机名并不是完全合格域名(FQDNs)。 +在本节中示例使用的清单如下。(删除了密码,IP 地址也发生了变化)。在这个示例中,(和前面的示例一样)某些主机名并不是完全合格域名(FQDN)。 - -### 清单文件 +#### 清单文件 ``` [cumulus] @@ -735,19 +703,19 @@ nx1 hostip=5.6.7.8 un=USERNAME pwd=PASSWORD vsrx hostip=9.10.11.12 un=USERNAME pwd=PASSWORD ``` -###### 注意 +> 注意: -正如你所知道的,Ansible 支持将密码存储在一个加密文件中的功能。如果你想学习关于这个特性的更多内容,请查看在 Ansible 网站上的文档中的 [Ansible Vault][5] 部分。 +> 正如你所知道的,Ansible 支持将密码存储在一个加密文件中的功能。如果你想学习关于这个特性的更多内容,请查看在 Ansible 网站上的文档中的 [Ansible Vault][5] 部分。 这个清单文件有四个组,每个组定义了一台单个的主机。让我们详细回顾一下每一节: -Cumulus +**Cumulus** -主机 `cvx` 是一个 Cumulus Linux (CL) 交换机,并且它是 `cumulus` 组中的唯一设备。记住,CL 是原生 Linux,因此,这意味着它是使用默认连接机制(SSH)连到到需要自动化的 CL 交换机。因为 `cvx` 在 DNS 或者 _/etc/hosts_ 文件中没有定义,我们将让 Ansible 知道不要在清单文件中定义主机名,而是在 `ansible_ssh_host` 中定义的名字/IP。登陆到 CL 交换机的用户名被定义在 playbook 中,但是,你可以看到密码使用变量 `ansible_ssh_pass` 定义在清单文件中。 +主机 `cvx` 是一个 Cumulus Linux (CL) 交换机,并且它是 `cumulus` 组中的唯一设备。记住,CL 是原生 Linux,因此,这意味着它是使用默认连接机制(SSH)连到到需要自动化的 CL 交换机。因为 `cvx` 在 DNS 或者 `/etc/hosts` 文件中没有定义,我们将让 Ansible 知道不要在清单文件中定义主机名,而是在 `ansible_ssh_host` 中定义的名字/IP。登陆到 CL 交换机的用户名被定义在 playbook 中,但是,你可以看到密码使用变量 `ansible_ssh_pass` 定义在清单文件中。 -Arista +**Arista** -被称为 `veos1` 的是一台运行 EOS 的 Arista 交换机。它是在 `arista` 组中唯一的主机。正如你在 Arista 中看到的,在清单文件中并没有其它的参数存在。这是因为 Arista 为它们的设备使用了一个特定的配置文件。在我们的示例中它的名字为 _.eapi.conf_,它存在在 home 目录中。下面是正确使用配置文件的这个功能的示例: +被称为 `veos1` 的是一台运行 EOS 的 Arista 交换机。它是在 `arista` 组中唯一的主机。正如你在 Arista 中看到的,在清单文件中并没有其它的参数存在。这是因为 Arista 为它们的设备使用了一个特定的配置文件。在我们的示例中它的名字为 `.eapi.conf`,它存在在 home 目录中。下面是正确使用配置文件的这个功能的示例: ``` [connection:veos1] @@ -756,27 +724,26 @@ username: unadmin password: pwadmin ``` -这个文件包含了定义在配置文件中的 Ansible 连接到设备(和 Arista 的被称为 _pyeapi_ 的 Python 库)所需要的全部信息。 +这个文件包含了定义在配置文件中的 Ansible 连接到设备(和 Arista 的被称为 `pyeapi` 的 Python 库)所需要的全部信息。 -Cisco +**Cisco** -和 Cumulus 和 Arista 一样,这里仅有一台主机(`nx1`)存在于 `cisco` 组中。这是一台 NX-OS-based Cisco Nexus 交换机。注意在这里为 `nx1` 定义了三个变量。它们包括 `un` 和 `pwd`,这是为了在 playbook 中访问和为了进入到 Cisco 模块去连接到设备。另外,这里有一个称为 `hostip` 的参数,它是必需的,因为,`nx1` 没有在 DNS 中或者是 _/etc/hosts_ 配置文件中定义。 +和 Cumulus 和 Arista 一样,这里仅有一台主机(`nx1`)存在于 `cisco` 组中。这是一台 NX-OS-based Cisco Nexus 交换机。注意在这里为 `nx1` 定义了三个变量。它们包括 `un` 和 `pwd`,这是为了在 playbook 中访问和为了进入到 Cisco 模块去连接到设备。另外,这里有一个称为 `hostip` 的参数,它是必需的,因为,`nx1` 没有在 DNS 中或者是 `/etc/hosts` 配置文件中定义。 +> 注意: -###### 注意 +> 如果自动化一个原生的 Linux 设备,我们可以将这个参数命名为任何东西。`ansible_ssh_host` 被用于到如我们看到的那个 Cumulus 示例(如果在清单文件中的定义不能被解析)。在这个示例中,我们将一直使用 `ansible_ssh_host`,但是,它并不是必需的,因为我们将这个变量作为一个参数进入到 Cisco 模块,而 `ansible_ssh_host` 是在使用默认的 SSH 连接机制时自动检查的。 -如果自动化一个原生的 Linux 设备,我们可以将这个参数命名为任何东西。`ansible_ssh_host` 被用于到如我们看到的那个 Cumulus 示例(如果在清单文件中的定义不能被解析)。在这个示例中,我们将一直使用 `ansible_ssh_host`,但是,它并不是必需的,因为我们将这个变量作为一个参数进入到 Cisco 模块,而 `ansible_ssh_host` 是在使用默认的 SSH 连接机制时自动检查的。 - -Juniper +**Juniper** 和前面的三个组和主机一样,在 `juniper` 组中有一个单个的主机 `vsrx`。它在清单文件中的设置与 Cisco 相同,因为两者在 playbook 中使用了相同的方式。 -### Playbook +#### 剧本 -接下来的 playbook 有四个不同的 plays。每个 play 是基于特定的供应商类型的设备组的自动化构建的。注意,那是在一个单个的 playbook 中执行这些任务的唯一的方法。这里还有其它的方法,它可以使用条件(`when` 语句)或者创建 Ansible 角色(它在这个报告中没有介绍)。 +接下来的剧本有四个不同的剧集。每个剧集是基于特定的供应商类型的设备组的自动化构建的。注意,那是在一个单个的剧本中执行这些任务的唯一的方法。这里还有其它的方法,它可以使用条件(`when` 语句)或者创建 Ansible 角色(它在这个报告中没有介绍)。 -这里有一个 playbook 的示例: +这里有一个剧本的示例: ``` --- @@ -833,29 +800,29 @@ Juniper diffs_file=junpr.diff ``` -你将注意到,前面的两个 plays 是非常类似的,我们已经在最初的 Cisco 和 Arista 示例中讲过了。唯一的区别是每个要自动化的组(`cisco` and `arista`) 定义了它们自己的 play,我们在前面介绍使用 `when` 条件时比较过。 +你将注意到,前面的两个剧集是非常类似的,我们已经在最初的 Cisco 和 Arista 示例中讲过了。唯一的区别是每个要自动化的组(`cisco` and `arista`) 定义了它们自己的剧集,我们在前面介绍使用 `when` 条件时比较过。 这里有一个不正确的或者是错误的方式去做这些。这取决于你预先知道的信息是什么和适合你的环境和使用的最佳案例是什么,但我们的目的是为了展示做同一件事的几种不同的方法。 -第三个 play 是在 Cumulus Linux 交换机的 `swp1` 接口上进行自动化配置。在这个 play 中的第一个任务是去确认 `swp1` 是一个三层接口,并且它配置的 IP 地址是 100.10.10.1。因为 Cumulus Linux 是原生的 Linux,网络服务在改变后需要重启才能生效。这也可以使用 Ansible 的操作来达到这个目的(这已经超出了本报告讨论的范围),这里有一个被称为 `service` 的 Ansible 核心模块来做这些,但它会中断交换机上的网络;使用 `ifreload` 重新启动则不会中断。 +第三个剧集是在 Cumulus Linux 交换机的 `swp1` 接口上进行自动化配置。在这个剧集中的第一个任务是去确认 `swp1` 是一个三层接口,并且它配置的 IP 地址是 100.10.10.1。因为 Cumulus Linux 是原生的 Linux,网络服务在改变后需要重启才能生效。这也可以使用 Ansible 的操作来达到这个目的(这已经超出了本报告讨论的范围),这里有一个被称为 `service` 的 Ansible 核心模块来做这些,但它会中断交换机上的网络;使用 `ifreload` 重新启动则不会中断。 -本节到现在为止,我们已经讲解了专注于特定任务的 Ansible 模块,比如,配置接口和 VLANs。第四个 play 使用了另外的选项。我们将看到一个 _pushes_ 模块,它是一个完整的配置文件并且立即激活它作为正在运行的新的配置。这里将使用 `napalm_install_config`来展示前面的示例,但是,这个示例使用了一个 Juniper 专用的模块。 +本节到现在为止,我们已经讲解了专注于特定任务的 Ansible 模块,比如,配置接口和 VLAN。第四个剧集使用了另外的选项。我们将看到一个 `pushes` 模块,它是一个完整的配置文件并且立即激活它作为正在运行的新的配置。这里将使用 `napalm_install_config` 来展示前面的示例,但是,这个示例使用了一个 Juniper 专用的模块。 `junos_install_config` 模块接受几个参数,如下面的示例中所展示的。到现在为止,你应该理解了什么是 `user`、`passwd`、和 `host`。其它的参数定义如下: -`file` +`file`: 这是一个从 Ansible 控制主机拷贝到 Juniper 设备的配置文件。 -`logfile` +`logfile`: 这是可选的,但是,如果你指定它,它会被用于存储运行这个模块时生成的信息。 -`overwrite` +`overwrite`: 当你设置为 yes/true 时,完整的配置将被发送的配置覆盖。(默认是 false) -`diffs_file` +`diffs_file`: 这是可选的,但是,如果你指定它,当应用配置时,它将存储生成的差异。当应用配置时将存储一个生成的差异。当正好更改了主机名,但是,仍然发送了一个完整的配置文件时会生成一个差异,如下的示例: @@ -867,11 +834,11 @@ Juniper ``` -上面已经介绍了 playbook 概述的细节。现在,让我们看看当 playbook 运行时发生了什么: +上面已经介绍了剧本概述的细节。现在,让我们看看当剧本运行时发生了什么: -###### 注意 +> 注意: -注意:`-i` 标志是用于指定使用的清单文件。也可以设置环境变量 `ANSIBLE_HOSTS`,而不用每次运行 playbook 时都去使用一个 `-i` 标志。 +> `-i` 标志是用于指定使用的清单文件。也可以设置环境变量 `ANSIBLE_HOSTS`,而不用每次运行剧本时都去使用一个 `-i` 标志。 ``` ntc@ntc:~/ansible/multivendor$ ansible-playbook -i inventory demo.yml @@ -949,12 +916,11 @@ veos1 : ok=1 changed=0 unreachable=0 failed=0 vsrx : ok=1 changed=0 unreachable=0 failed=0 ``` -注意:这里有 0 个改变,但是,每次运行任务,正如期望的那样,它们都返回 “ok”。说明在这个 playbook 中的每个模块都是幂等的。 - +注意:这里有 0 个改变,但是,每次运行任务,正如期望的那样,它们都返回 “ok”。说明在这个剧本中的每个模块都是幂等的。 ### 总结 -Ansible 是一个超级简单的、无代理和可扩展的自动化平台。网络社区持续不断地围绕 Ansible 去重整它作为一个能够执行一些自动化网络任务的平台,比如,做配置管理、数据收集和报告,等等。你可以使用 Ansible 去推送完整的配置文件,配置具体的使用幂等模块的网络资源,比如,接口、VLANs,或者,简单地自动收集信息,比如,领居、序列号、启动时间、和接口状态,以及按你的需要定制一个报告。 +Ansible 是一个超级简单的、无代理和可扩展的自动化平台。网络社区持续不断地围绕 Ansible 去重整它作为一个能够执行一些自动化网络任务的平台,比如,做配置管理、数据收集和报告,等等。你可以使用 Ansible 去推送完整的配置文件,配置具体的使用幂等模块的网络资源,比如,接口、VLAN,或者,简单地自动收集信息,比如,领居、序列号、启动时间、和接口状态,以及按你的需要定制一个报告。 因为它的架构,Ansible 被证明是一个在这里可用的、非常好的工具,它可以帮助你实现从传统的基于 _CLI/SNMP_ 的网络设备到基于 _API 驱动_ 的现代化网络设备的自动化。 @@ -968,7 +934,7 @@ Ansible 是一个超级简单的、无代理和可扩展的自动化平台。网 ![](https://d3tdunqjn7n0wj.cloudfront.net/360x360/jason-edelman-crop-5b2672f569f553a3de3a121d0179efcb.jpg) -Jason Edelman,CCIE 15394 & VCDX-NV 167,出生并成长于新泽西州的一位网络工程师。他是一位典型的 “CLI 爱好者” 和 “路由器小子”。在几年前,他决定更多地关注于软件、开发实践、以及怎么与网络工程融合。Jason 目前经营着一个小的咨询公司,公司名为:Network to Code(http://networktocode.com/),帮助供应商和终端用户利用新的工具和技术来减少他们的低效率操作... +Jason Edelman,CCIE 15394 & VCDX-NV 167,出生并成长于新泽西州的一位网络工程师。他是一位典型的 “CLI 爱好者” 和 “路由器小子”。在几年前,他决定更多地关注于软件、开发实践、以及怎么与网络工程融合。Jason 目前经营着一个小的咨询公司,公司名为:Network to Code( http://networktocode.com/ ),帮助供应商和终端用户利用新的工具和技术来减少他们的低效率操作... -------------------------------------------------------------------------------- @@ -976,7 +942,7 @@ via: https://www.oreilly.com/learning/network-automation-with-ansible 作者:[Jason Edelman][a] 译者:[qhwdw](https://github.com/qhwdw) -校对:[校对者ID](https://github.com/校对者ID) +校对:[wxy](https://github.com/wxy) 本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 diff --git a/published/201808/20170713 A Collection Of Useful BASH Scripts For Heavy Commandline Users.md b/published/201808/20170713 A Collection Of Useful BASH Scripts For Heavy Commandline Users.md new file mode 100644 index 0000000000..df4cd3fac9 --- /dev/null +++ b/published/201808/20170713 A Collection Of Useful BASH Scripts For Heavy Commandline Users.md @@ -0,0 +1,603 @@ +献给命令行重度用户的一组实用 BASH 脚本 +====== + +![](https://www.ostechnix.com/wp-content/uploads/2017/07/A-Collection-Of-Useful-BASH-Scripts-720x340.png) + +今天,我偶然发现了一组适用于命令行重度用户的实用 BASH 脚本,这些脚本被称为 **Bash-Snippets**,它们对于那些整天都与终端打交道的人来说可能会很有帮助。想要查看你居住地的天气情况?它为你做了。想知道股票价格?你可以运行显示股票当前详细信息的脚本。觉得无聊?你可以看一些 YouTube 视频。这些全部在命令行中完成,你无需安装任何严重消耗内存的 GUI 应用程序。 + +在撰写本文时,Bash-Snippets 提供以下 19 个实用工具: + + 1. **Cheat** – Linux 命令备忘单。 + 2. **Cloudup** – 一个将 GitHub 仓库备份到 bitbucket 的工具。 + 3. **Crypt** – 加解密文件。 + 4. **Cryptocurrency** – 前 10 大加密货币的实时汇率转换。 + 5. **Currency** – 货币转换器。 + 6. **Geo** – 提供 wan、lan、router、dns、mac 和 ip 的详细信息。 + 7. **Lyrics** – 从命令行快速获取给定歌曲的歌词。 + 8. **Meme** – 创造命令行表情包。 + 9. **Movies** – 搜索并显示电影详情。 + 10. **Newton** – 执行数值计算一直到符号数学解析。(to 校正:这里不理解) + 11. **Qrify** – 将给定的字符串转换为二维码。 + 12. **Short** – 缩短 URL + 13. **Siteciphers** – 检查给定 https 站点启用或禁用的密码。 + 14. **Stocks** – 提供某些股票的详细信息。 + 15. **Taste** – 推荐引擎提供三个类似的项目,如提供物品(如书籍、音乐、艺术家、电影和游戏等。) + 16. **Todo** – 命令行待办事项管理。 + 17. **Transfer** – 从命令行快速传输文件。 + 18. **Weather** – 显示你所在地的天气详情。 + 19. **Youtube-Viewer** – 从终端观看 YouTube 视频。 + +作者可能会在将来添加更多实用程序和/或功能,因此我建议你密切关注该项目的网站或 GitHub 页面以供将来更新。 + +### 安装 + +你可以在任何支持 BASH 的操作系统上安装这些脚本。 + +首先,克隆 git 仓库,使用以下命令: + +``` +$ git clone https://github.com/alexanderepstein/Bash-Snippets +``` + +进入目录: + +``` +$ cd Bash-Snippets/ +``` + +切换到最新的稳定版本: + +``` +$ git checkout v1.22.0 +``` + +最后,使用以下命令安装 Bash-Snippets: + +``` +$ sudo ./install.sh +``` + +这将询问你要安装哪些脚本。只需输入 `Y` 并按回车键即可安装相应的脚本。如果你不想安装某些特定脚本,输入 `N` 并按回车键。 + +``` +Do you wish to install currency [Y/n]: y +``` + +要安装所有脚本,运行: + +``` +$ sudo ./install.sh all +``` + +要安装特定的脚本,比如 currency,运行: + +``` +$ sudo ./install.sh currency +``` + +你也可以使用 [Linuxbrew][1] 包管理器来安装它。 + +安装所有的工具,运行: + +``` +$ brew install bash-snippets +``` + +安装特定的工具: + +``` +$ brew install bash-snippets --without-all-tools --with-newton --with-weather +``` + +另外,对于那些基于 Debian 系统的,例如 Ubuntu、Linux Mint,可以添加 PPA 源: + +``` +$ sudo add-apt-repository ppa:navanchauhan/bash-snippets +$ sudo apt update +$ sudo apt install bash-snippets +``` + +### 用法 + +**需要网络连接**才能使用这些工具。用法很简单。让我们来看看如何使用其中的一些脚本,我假设你已经安装了所有脚本。 + +#### 1、 Currency – 货币转换器 + +这个脚本根据实时汇率转换货币。输入当前货币代码和要交换的货币,以及交换的金额,如下所示: + +``` +$ currency +What is the base currency: INR +What currency to exchange to: USD +What is the amount being exchanged: 10 + +========================= +| INR to USD +| Rate: 0.015495 +| INR: 10 +| USD: .154950 +========================= +``` + +你也可以在单条命令中传递所有参数,如下所示: + +``` +$ currency INR USD 10 +``` + +参考以下屏幕截图: + +[![Bash-Snippets][2]][3] + +#### 2、 Stocks – 显示股票价格详细信息 + +如果你想查看一只股票价格的详细信息,输入股票即可,如下所示: + +``` +$ stocks Intel + +INTC stock info +============================================= +| Exchange Name: NASDAQ +| Latest Price: 34.2500 +| Close (Previous Trading Day): 34.2500 +| Price Change: 0.0000 +| Price Change Percentage: 0.00% +| Last Updated: Jul 12, 4:00PM EDT +============================================= +``` + +上面输出了 **Intel 股票** 的详情。 + +#### 3、 Weather – 显示天气详细信息 + +让我们查看以下天气详细信息,运行以下命令: + +``` +$ weather +``` + +示例输出: + +![][4] + +正如你在上面屏幕截图中看到的那样,它提供了 3 天的天气预报。不使用任何参数的话,它将根据你的 IP 地址显示天气详细信息。你还可以显示特定城市或国家/地区的天气详情,如下所示: + +``` +$ weather Chennai +``` + +同样,你可以查看输入以下命令来查看月相(月亮的形态): + +``` +$ weather moon +``` + +示例输出: + +![][5] + +#### 4、 Crypt – 加解密文件 + +此脚本对 openssl 做了一层包装,允许你快速轻松地加密和解密文件。 + +要加密文件,使用以下命令: + +``` +$ crypt -e [original file] [encrypted file] +``` + +例如,以下命令将加密 `ostechnix.txt`,并将其保存在当前工作目录下,名为 `encrypt_ostechnix.txt`。 + +``` +$ crypt -e ostechnix.txt encrypt_ostechnix.txt +``` + +输入两次文件密码: + +``` +Encrypting ostechnix.txt... +enter aes-256-cbc encryption password: +Verifying - enter aes-256-cbc encryption password: +Successfully encrypted +``` + +上面命令将使用 **AES 256 位密钥**加密给定文件。密码不要保存在纯文本文件中。你可以加密 .pdf、.txt、 .docx、 .doc、 .png、 .jpeg 类型的文件。 + +要解密文件,使用以下命令: + +``` +$ crypt -d [encrypted file] [output file] +``` + +例如: + +``` +$ crypt -d encrypt_ostechnix.txt ostechnix.txt +``` + +输入密码解密: + +``` +Decrypting encrypt_ostechnix.txt... +enter aes-256-cbc decryption password: +Successfully decrypted + +``` + +#### 5、 Movies – 查看电影详情 + +使用这个脚本,你可以查看电影详情。 + +以下命令显示了一部名为 “mother” 的电影的详情: + +``` +$ movies mother + +================================================== +| Title: Mother +| Year: 2009 +| Tomato: 95% +| Rated: R +| Genre: Crime, Drama, Mystery +| Director: Bong Joon Ho +| Actors: Hye-ja Kim, Bin Won, Goo Jin, Je-mun Yun +| Plot: A mother desperately searches for the killer who framed her son for a girl's horrific murder. +================================================== +``` + +#### 6、 显示类似条目 + +要使用这个脚本,你需要从**[这里][6]** 获取 API 密钥。不过不用担心,它完全是免费的。一旦你获得 API 密钥后,将以下行添加到 `~/.bash_profile`:`export TASTE_API_KEY=”你的 API 密钥放在这里”`。(LCTT 译注: TasteDive 是一个推荐引擎,它会根据你的品味推荐相关项目。) + +现在你可以根据你提供的项目查看类似项目,如下所示: + +``` +$ taste -i Red Hot Chilli Peppers +``` + +#### 7、 Short – 缩短 URL + +这个脚本会缩短给定的 URL。 + +``` +$ short +``` + +#### 8、 Geo – 显示网络的详情 + + +这个脚本会帮助你查找网络的详细信息,例如广域网、局域网、路由器、 dns、mac 地址和 ip 地址。 + +例如,要查找你的局域网 ip,运行: + +``` +$ geo -l +``` + +我系统上的输出: + +``` +192.168.43.192 +``` + +查看广域网 ip: + +``` +$ geo -w +``` + +在终端中输入 `geo` 来查看更多详细信息。 + +``` +$ geo +Geo +Description: Provides quick access for wan, lan, router, dns, mac, and ip geolocation data +Usage: geo [flag] + -w Returns WAN IP + -l Returns LAN IP(s) + -r Returns Router IP + -d Returns DNS Nameserver + -m Returns MAC address for interface. Ex. eth0 + -g Returns Current IP Geodata +Examples: + geo -g + geo -wlrdgm eth0 +Custom Geo Output => +[all] [query] [city] [region] [country] [zip] [isp] +Example: geo -a 8.8.8.8 -o city,zip,isp + -o [options] Returns Specific Geodata + -a [address] For specific ip in -s + -v Returns Version + -h Returns Help Screen + -u Updates Bash-Snippets +``` + +#### 9、 Cheat – 显示 Linux 命令的备忘单 + +想参考 Linux 命令的备忘单吗?这是可能的。以下命令将显示 `curl` 命令的备忘单: + +``` +$ cheat curl +``` + +只需用你选择的命令替换 `curl` 即可显示其备忘单。这对于快速参考你要使用的任何命令非常有用。 + +#### 10、 Youtube-Viewer – 观看 YouTube 视频 + +使用此脚本,你可以直接在终端上搜索或打开 YouTube 视频。(LCTT 译注:在媒体播放器中,而不是文本的终端中打开) + +让我们来看一些有关 **Ed Sheeran** 的视频。 + +``` +$ ytview Ed Sheeran +``` + +从列表中选择要播放的视频。所选内容将在你的默认媒体播放器中播放。 + +![][7] + +要查看艺术家的近期视频,你可以使用: + +``` +$ ytview -c [channel name] +``` + +要寻找视频,只需输入: + +``` +$ ytview -s [videoToSearch] +``` + +或者: + +``` +$ ytview [videoToSearch] +``` + +#### 11、 cloudup – 备份 GitHub 仓库到 bitbucket + +你在 GitHub 上托管过任何项目吗?如果托管过,那么你可以随时间 GitHub 仓库备份到 **bitbucket**,它是一种用于源代码和开发项目的基于 Web 的托管服务。 + +你可以使用 `-a` 选项一次性备份指定用户的所有 GitHub 仓库,或者备份单个仓库。 + +要备份 GitHub 仓库,运行: + +``` +$ cloudup +``` + +系统将要求你输入 GitHub 用户名, 要备份的仓库名称以及 bitbucket 用户名和密码等。 + +#### 12、 Qrify – 将字符串转换为二维码 + +这个脚本将任何给定的文本字符串转换为二维码。这对于发送链接或者保存一串命令到手机非常有用。 + +``` +$ qrify convert this text into qr code +``` + +示例输出: + +![][8] + +很酷,不是吗? + +#### 13、 Cryptocurrency + +它将显示十大加密货币实时汇率。 + +输入以下命令,然后单击回车来运行: + +``` +$ cryptocurrency +``` + +![][9] + + +#### 14、 Lyrics + +这个脚本从命令行快速获取一首歌曲的歌词。 + +例如,我将获取 “who is it” 歌曲的歌词,这是一首由 迈克尔·杰克逊Michael Jackson 演唱的流行歌曲。 + +``` +$ lyrics -a michael jackson -s who is it +``` + +![][10] + +#### 15、 Meme + +这个脚本允许你从命令行创建简单的表情贴图。它比基于 GUI 的表情包生成器快得多。 + +要创建一个表情贴图,只需输入: + +``` +$ meme -f mymeme +Enter the name for the meme's background (Ex. buzz, doge, blb ): buzz +Enter the text for the first line: THIS IS A +Enter the text for the second line: MEME +``` + +这将在你当前的工作目录创建 jpg 文件。 + +#### 16、 Newton + +厌倦了解决复杂的数学问题?你来对了。Newton 脚本将执行数值计算,乃至于符号数学解析。 + +![][11] + +#### 17、 Siteciphers + +这个脚本可以帮助你检查在给定的 https 站点上启用/禁用哪些加密算法。(LCTT 译注:指 HTTPS 通讯中采用的加密算法) + +``` +$ siteciphers google.com +``` + +![][12] + +#### 18、 Todo + +它允许你直接从终端创建日常任务。 + +让我们来创建一些任务。 + +``` +$ todo -a The first task +01). The first task Tue Jun 26 14:51:30 IST 2018 +``` + +要添加其它任务,只需添加任务名称重新运行上述命令即可。 + +``` +$ todo -a The second task +01). The first task Tue Jun 26 14:51:30 IST 2018 +02). The second task Tue Jun 26 14:52:29 IST 2018 +``` + +要查看任务列表,运行: + +``` +$ todo -g +01). The first task Tue Jun 26 14:51:30 IST 2018 +02). A The second task Tue Jun 26 14:51:46 IST 2018 +``` + +一旦你完成了任务,就可以将其从列表中删除,如下所示: + +``` +$ todo -r 2 +Sucessfully removed task number 2 +01). The first task Tue Jun 26 14:51:30 IST 2018 +``` + +要清除所有任务,运行: + +``` +$ todo -c +Tasks cleared. +``` + +#### 19、 Transfer + +Transfer 脚本允许你通过互联网快速轻松地传输文件和目录。 + +让我们上传一个文件: + +``` +$ transfer test.txt +Uploading test.txt +################################################################################################################################################ 100.0% +Success! +Transfer Download Command: transfer -d desiredOutputDirectory ivmfj test.txt +Transfer File URL: https://transfer.sh/ivmfj/test.txt +``` + +该文件将上传到 transfer.sh 站点。Transfer.sh 允许你一次上传最大 **10 GB** 的文件。所有共享文件在 **14 天**后自动过期。如你所见,任何人都可以通过 Web 浏览器访问 URL 或使用 transfer 目录来下载文件,当然,transfer 必须安装在他/她的系统中。 + +现在从你的系统中移除文件。 + +``` +$ rm -fr test.txt +``` + +现在,你可以随时(14 天内)从 transfer.sh 站点下载该文件,如下所示: + +``` +$ transfer -d Downloads ivmfj test.txt +``` + +获取关于此实用脚本的更多详情,参考以下指南。 + +* [用命令行在互联网上共享文件的一个简单快捷方法](https://www.ostechnix.com/easy-fast-way-share-files-internet-command-line/) + +### 获得帮助 + +如果你不知道如何使用特定脚本,只需输入该脚本的名称,然后按下 ENTER 键,你将会看到使用细节。以下示例显示 Qrify 脚本的帮助信息。 + +``` +$ qrify +Qrify +Usage: qrify [stringtoturnintoqrcode] +Description: Converts strings or urls into a qr code. + -u Update Bash-Snippet Tools + -m Enable multiline support (feature not working yet) + -h Show the help + -v Get the tool version +Examples: + qrify this is a test string + qrify -m two\\nlines + qrify github.com # notice no http:// or https:// this will fail + +``` + +### 更新脚本 + +你可以随时使用 `-u` 选项更新已安装的工具。以下命令更新 “weather” 工具。 + +``` +$ weather -u +``` + +### 卸载 + +你可以使用以下命令来卸载这些工具。 + +克隆仓库: + +``` +$ git clone https://github.com/alexanderepstein/Bash-Snippets +``` + +进入 Bash-Snippets 目录: + +``` +$ cd Bash-Snippets +``` + +运行以下命令来卸载脚本: + +``` +$ sudo ./uninstall.sh +``` + +输入 `y`,并按下回车键来移除每个脚本。 + +``` +Do you wish to uninstall currency [Y/n]: y +``` + +**另请阅读:** + +- [Cli.Fyi —— 快速而简单地获取诸如 IP、电子邮件、域名等信息的方式](https://www.ostechnix.com/cli-fyi-quick-easy-way-fetch-information-ips-emails-domains-lots/) + +好了,这就是全部了。我必须承认,在测试这些脚本时我印象很深刻。我真的很喜欢将所有有用的脚本组合到一个包中的想法。感谢开发者。试一试,你不会失望的。 + +干杯! + +-------------------------------------------------------------------------------- + +via: https://www.ostechnix.com/collection-useful-bash-scripts-heavy-commandline-users/ + +作者:[SK][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[MjSeven](https://github.com/MjSeven) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.ostechnix.com/author/sk/ +[1]:https://www.ostechnix.com/linuxbrew-common-package-manager-linux-mac-os-x/ +[3]:http://www.ostechnix.com/wp-content/uploads/2017/07/sk@sk_001.png +[4]:http://www.ostechnix.com/wp-content/uploads/2017/07/sk@sk_002-1.png +[5]:http://www.ostechnix.com/wp-content/uploads/2017/07/sk@sk_003.png +[6]:https://tastedive.com/account/api_access +[7]:http://www.ostechnix.com/wp-content/uploads/2017/07/ytview-1.png +[8]:http://www.ostechnix.com/wp-content/uploads/2017/07/sk@sk_005.png +[9]:http://www.ostechnix.com/wp-content/uploads/2017/07/cryptocurrency.png +[10]:http://www.ostechnix.com/wp-content/uploads/2017/07/lyrics.png +[11]:http://www.ostechnix.com/wp-content/uploads/2017/07/newton.png +[12]:http://www.ostechnix.com/wp-content/uploads/2017/07/siteciphers.png diff --git a/published/201808/20170721 Arch Linux Applications Automatic Installation Script.md b/published/201808/20170721 Arch Linux Applications Automatic Installation Script.md new file mode 100644 index 0000000000..2cd278e659 --- /dev/null +++ b/published/201808/20170721 Arch Linux Applications Automatic Installation Script.md @@ -0,0 +1,150 @@ +ArchI0:Arch Linux 应用自动安装脚本 +====== + +![](https://www.ostechnix.com/wp-content/uploads/2017/07/ArchI0-Arch-Linux-Applications-Automatic-Installation-Script-720x340.png) + +Arch 用户你们好!今天,我偶然发现了一个叫做 “**ArchI0**” 的实用工具,它是基于命令行菜单的 Arch Linux 应用自动安装脚本。使用此脚本是为基于 Arch 的发行版安装所有必要的应用最简易的方式。请注意**此脚本仅适用于菜鸟级使用者**。中高级使用者可以轻松掌握[如何使用 pacman][1]来完成这件事。如果你想学习如何使用 Arch Linux,我建议你一个个手动安装所有的软件。对那些仍是菜鸟并且希望为自己基于 Arch 的系统快速安装所有必要应用的用户,可以使用此脚本。 + +### ArchI0 – Arch Linux 应用自动安装脚本 + +此脚本的开发者已经制作了 **ArchI0live** 和 **ArchI0** 两个脚本。你可以通过 ArchI0live 测试应用,无需安装。这可能有助于在将脚本安装到系统之前了解其实际内容。 + +### 安装 ArchI0 + +要安装此脚本,使用如下命令通过 Git 克隆 ArchI0 脚本仓库: + +``` +$ git clone https://github.com/SifoHamlaoui/ArchI0.git +``` + +上面的命令会克隆 ArchI0 的 Github 仓库内容,在你当前目录的一个名为 ArchI0 的文件夹里。使用如下命令进入此目录: + +``` +$ cd ArchI0/ +``` + +使用如下命令赋予脚本可执行权限: + +``` +$ chmod +x ArchI0live.sh +``` + +使用如下命令执行脚本: + +``` +$ sudo ./ArchI0live.sh + +``` + +此脚本需要以 root 或 sudo 用户身份执行,因为安装应用需要 root 权限。 + +> **注意:** 有些人想知道此脚本中开头的那些命令是做什么的,第一个命令是下载 **figlet**,因为此脚本的 logo 是使用 figlet 显示的。第二个命令是安装用来打开并查看许可协议文件的 **Leafpad**。第三个命令是安装用于从 sourceforge 下载文件的 **wget**。第四和第五个命令是下载许可协议文件并用 leafpad 打开。此外,最后的第 6 条命令是在阅读许可协议文件之后关闭它。 + +输入你的 Arch Linux 系统架构然后按回车键。当其请求安装此脚本时,键入 `y` 然后按回车键。 + +![][3] + +一旦开始安装,将会重定向至主菜单。 + +![][4] + +正如前面的截图, ArchI0 包含有 13 类、90 个容易安装的程序。这 90 个程序刚好足够配置一个完整的 Arch Linux 桌面,可执行日常活动。键入 `a` 可查看关于此脚本的信息,键入 `q` 可退出此脚本。 + +安装后无需执行 ArchI0live 脚本。可以直接使用如下命令启动: + +``` +$ sudo ArchI0 +``` + +它会每次询问你选择 Arch Linux 发行版的架构。 + +``` +This script Is under GPLv3 License + +Preparing To Run Script + Checking For ROOT: PASSED + What Is Your OS Architecture? {32/64} 64 +``` + +从现在开始,你可以从主菜单列出的类别选择要安装的程序。要查看特定类别下的可用程序列表,输入类别号即可。举个例子,要查看**文本编辑器**分类下的可用程序列表,输入 **1** 然后按回车键。 + +``` +This script Is under GPLv3 License + +[ R00T MENU ] +Make A Choice + 1) Text Editors + 2) FTP/Torrent Applications + 3) Download Managers + 4) Network managers + 5) VPN clients + 6) Chat Applications + 7) Image Editors + 8) Video editors/Record + 9) Archive Handlers + 10) Audio Applications + 11) Other Applications + 12) Development Environments + 13) Browser/Web Plugins + 14) Dotfiles + 15) Usefull Links + ------------------------ + a) About ArchI0 Script + q) Leave ArchI0 Script + +Choose An Option: 1 +``` + +接下来,选择你想安装的程序。要返回至主菜单,输入 `q` 然后按回车键。 + +我想安装 Emacs,所以我输入 `3`。 + +``` +This script Is under GPLv3 License + +[ TEXT EDITORS ] + [ Option ] [ Description ] + 1) GEdit + 2) Geany + 3) Emacs + 4) VIM + 5) Kate + --------------------------- + q) Return To Main Menu + +Choose An Option: 3 +``` + +现在,Emacs 将会安装至你的 Arch Linux 系统。 + +![][5] + +所选择的应用安装完成后,你可以按回车键返回主菜单。 + +### 结论 + +毫无疑问,此脚本让 Arch Linux 用户使用起来更加容易,特别是刚开始使用的人。如果你正寻找快速简单无需使用 pacman 安装应用的方法,此脚本是一个不错的选择。试用一下并在下面的评论区让我们知道你对此脚本的看法。 + +就这些。希望这个工具能帮到你。我们每天都会推送实用的指南。如果你觉得我们的指南挺实用,请分享至你的社交网络,专业圈子并支持我们。 + +干杯! + + + +-------------------------------------------------------------------------------- + +via: https://www.ostechnix.com/archi0-arch-linux-applications-automatic-installation-script/ + +作者:[SK][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[fuowang](https://github.com/fuowang) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.ostechnix.com/author/sk/ +[1]:http://www.ostechnix.com/getting-started-pacman/ +[2]:data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7 +[3]:http://www.ostechnix.com/wp-content/uploads/2017/07/sk@sk-ArchI0_003.png +[4]:http://www.ostechnix.com/wp-content/uploads/2017/07/sk@sk-ArchI0_004-1.png +[5]:http://www.ostechnix.com/wp-content/uploads/2017/07/pacman-as-superuser_005.png diff --git a/sources/tech/20170805 How to use Fio (Flexible I-O Tester) to Measure Disk Performance in Linux.md b/published/201808/20170805 How to use Fio (Flexible I-O Tester) to Measure Disk Performance in Linux.md similarity index 64% rename from sources/tech/20170805 How to use Fio (Flexible I-O Tester) to Measure Disk Performance in Linux.md rename to published/201808/20170805 How to use Fio (Flexible I-O Tester) to Measure Disk Performance in Linux.md index c2659f3664..768f5dc081 100644 --- a/sources/tech/20170805 How to use Fio (Flexible I-O Tester) to Measure Disk Performance in Linux.md +++ b/published/201808/20170805 How to use Fio (Flexible I-O Tester) to Measure Disk Performance in Linux.md @@ -1,47 +1,42 @@ -How to use Fio (Flexible I/O Tester) to Measure Disk Performance in Linux +如何在 Linux 中使用 Fio 来测评硬盘性能 ====== + ![](https://wpmojo.com/wp-content/uploads/2017/08/wpmojo.com-how-to-use-fio-to-measure-disk-performance-in-linux-dotlayer.com-how-to-use-fio-to-measure-disk-performance-in-linux-816x457.jpeg) -Fio which stands for Flexible I/O Tester [is a free and open source][1] disk I/O tool used both for benchmark and stress/hardware verification developed by Jens Axboe. +Fio(Flexible I/O Tester) 是一款由 Jens Axboe 开发的用于测评和压力/硬件验证的[自由开源][1]的软件。 -It has support for 19 different types of I/O engines (sync, mmap, libaio, posixaio, SG v3, splice, null, network, syslet, guasi, solarisaio, and more), I/O priorities (for newer Linux kernels), rate I/O, forked or threaded jobs, and much more. It can work on block devices as well as files. +它支持 19 种不同类型的 I/O 引擎 (sync、mmap、libaio、posixaio、SG v3、splice、null、network、 syslet、guasi、solarisaio,以及更多), I/O 优先级(针对较新的 Linux 内核),I/O 速度,fork 的任务或线程任务等等。它能够在块设备和文件上工作。 -Fio accepts job descriptions in a simple-to-understand text format. Several example job files are included. Fio displays all sorts of I/O performance information, including complete IO latencies and percentiles. +Fio 接受一种非常简单易于理解的文本格式的任务描述。软件默认包含了几个示例任务文件。 Fio 展示了所有类型的 I/O 性能信息,包括完整的 IO 延迟和百分比。 -It is in wide use in many places, for both benchmarking, QA, and verification purposes. It supports Linux, FreeBSD, NetBSD, OpenBSD, OS X, OpenSolaris, AIX, HP-UX, Android, and Windows. +它被广泛的应用在非常多的地方,包括测评、QA,以及验证用途。它支持 Linux 、FreeBSD 、NetBSD、 OpenBSD、 OS X、 OpenSolaris、 AIX、 HP-UX、 Android 以及 Windows。 -In this tutorial, we will be using Ubuntu 16 and you are required to have sudo or root privileges to the computer. We will go over the installation and use of fio. +在这个教程,我们将使用 Ubuntu 16 ,你需要拥有这台电脑的 `sudo` 或 root 权限。我们将完整的进行安装和 Fio 的使用。 -### Installing fio from Source +### 使用源码安装 Fio + +我们要去克隆 GitHub 上的仓库。安装所需的依赖,然后我们将会从源码构建应用。首先,确保我们安装了 Git 。 -We are going to clone the repo on GitHub. Install the prerequisites, and then we will build the packages from the source code. Lets' start by making sure we have git installed. ``` - sudo apt-get install git - - ``` -For centOS users you can use: -``` +CentOS 用户可以执行下述命令: +``` sudo yum install git - - ``` -Now we change directory to /opt and clone the repo from Github: -``` +现在,我们切换到 `/opt` 目录,并从 Github 上克隆仓库: +``` cd /opt git clone https://github.com/axboe/fio - - ``` -You should see the output below: -``` +你应该会看到下面这样的输出: +``` Cloning into 'fio'... remote: Counting objects: 24819, done. remote: Compressing objects: 100% (44/44), done. @@ -49,72 +44,60 @@ remote: Total 24819 (delta 39), reused 62 (delta 32), pack-reused 24743 Receiving objects: 100% (24819/24819), 16.07 MiB | 0 bytes/s, done. Resolving deltas: 100% (16251/16251), done. Checking connectivity... done. - - ``` -Now, we change directory into the fio codebase by typing the command below inside the opt folder: -``` +现在,我们通过在 `/opt` 目录下输入下方的命令切换到 Fio 的代码目录: +``` cd fio - - ``` -We can finally build fio from source using the `make` build utility bu using the commands below: -``` +最后,我们可以使用下面的命令来使用 `make` 从源码构建软件: +``` # ./configure # make # make install - - ``` -### Installing fio on Ubuntu +### 在 Ubuntu 上安装 Fio -For Ubuntu and Debian, fio is available on the main repository. You can easily install fio using the standard package managers such as yum and apt-get. +对于 Ubuntu 和 Debian 来说, Fio 已经在主仓库内。你可以很容易的使用类似 `yum` 和 `apt-get` 的标准包管理器来安装 Fio。 + +对于 Ubuntu 和 Debian ,你只需要简单的执行下述命令: -For Ubuntu and Debian you can simple use: ``` - sudo apt-get install fio - - ``` -For CentOS/Redhat you can simple use: -On CentOS, you might need to install EPEL repository to your system before you can have access to fio. You can install it by running the following command: -``` +对于 CentOS/Redhat 你只需要简单执行下述命令。 +在 CentOS ,你可能在你能安装 Fio 前需要去安装 EPEL 仓库到你的系统中。你可以通过执行下述命令来安装它: + +``` sudo yum install epel-release -y - - ``` -You can then install fio using the command below: -``` +你可以执行下述命令来安装 Fio: +``` sudo yum install fio -y - - ``` -### Disk Performace testing with Fio +### 使用 Fio 进行磁盘性能测试 -With Fio is installed on your system. It's time to see how to use Fio with some examples below. We are going to perform a random write, read and read and write test. -### Performing a Random Write Test +现在 Fio 已经安装到了你的系统中。现在是时候看一些如何使用 Fio 的例子了。我们将进行随机写、读和读写测试。 + +### 执行随机写测试 + +执行下面的命令来开始。这个命令将要同一时间执行两个进程,写入共计 4GB( 4 个任务 x 512MB = 2GB) 文件: -Let's start by running the following command. This command will write a total 4GB file [4 jobs x 512 MB = 2GB] running 2 processes at a time: ``` - sudo fio --name=randwrite --ioengine=libaio --iodepth=1 --rw=randwrite --bs=4k --direct=0 --size=512M --numjobs=2 --runtime=240 --group_reporting - - -``` ``` +``` ... fio-2.2.10 Starting 2 processes @@ -143,23 +126,20 @@ Run status group 0 (all jobs): Disk stats (read/write): sda: ios=0/0, merge=0/0, ticks=0/0, in_queue=0, util=0.00% - - ``` -### Performing a Random Read Test +### 执行随机读测试 + +我们将要执行一个随机读测试,我们将会尝试读取一个随机的 2GB 文件。 -We are going to perform a random read test now, we will be trying to read a random 2Gb file ``` sudo fio --name=randread --ioengine=libaio --iodepth=16 --rw=randread --bs=4k --direct=0 --size=512M --numjobs=4 --runtime=240 --group_reporting - - ``` -You should see the output below: -``` +你应该会看到下面这样的输出: +``` ... fio-2.2.10 Starting 4 processes @@ -195,25 +175,20 @@ Run status group 0 (all jobs): Disk stats (read/write): sda: ios=521587/871, merge=0/1142, ticks=96664/612, in_queue=97284, util=99.85% - - ``` -Finally, we want to show a sample read-write test to see how the kind out output that fio returns. +最后,我们想要展示一个简单的随机读-写测试来看一看 Fio 返回的输出类型。 -### Read Write Performance Test +### 读写性能测试 + +下述命令将会测试 USB Pen 驱动器 (`/dev/sdc1`) 的随机读写性能: -The command below will measure random read/write performance of USB Pen drive (/dev/sdc1): ``` - sudo fio --randrepeat=1 --ioengine=libaio --direct=1 --gtod_reduce=1 --name=test --filename=random_read_write.fio --bs=4k --iodepth=64 --size=4G --readwrite=randrw --rwmixread=75 - - ``` -Below is the outout we get from the command above. +下面的内容是我们从上面的命令得到的输出: ``` - fio-2.2.10 Starting 1 process Jobs: 1 (f=1): [m(1)] [100.0% done] [217.8MB/74452KB/0KB /s] [55.8K/18.7K/0 iops] [eta 00m:00s] @@ -233,11 +208,9 @@ Run status group 0 (all jobs): Disk stats (read/write): sda: ios=774141/258944, merge=1463/899, ticks=748800/150316, in_queue=900720, util=99.35% - - ``` -We hope you enjoyed this tutorial and enjoyed following along, Fio is a very useful tool and we hope you can use it in your next debugging activity. If you enjoyed reading this post feel free to leave a comment of questions. Go ahead and clone the repo and play around with the code. +我们希望你能喜欢这个教程并且享受接下来的内容,Fio 是一个非常有用的工具,并且我们希望你能在你下一次 Debugging 活动中使用到它。如果你喜欢这个文章,欢迎留下评论和问题。 -------------------------------------------------------------------------------- @@ -245,8 +218,8 @@ We hope you enjoyed this tutorial and enjoyed following along, Fio is a very use via: https://wpmojo.com/how-to-use-fio-to-measure-disk-performance-in-linux/ 作者:[Alex Pearson][a] -译者:[译者ID](https://github.com/译者ID) -校对:[校对者ID](https://github.com/校对者ID) +译者:[Bestony](https://github.com/bestony) +校对:[wxy](https://github.com/wxy) 本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 diff --git a/published/201808/20171009 Considering Pythons Target Audience.md b/published/201808/20171009 Considering Pythons Target Audience.md new file mode 100644 index 0000000000..65f6305864 --- /dev/null +++ b/published/201808/20171009 Considering Pythons Target Audience.md @@ -0,0 +1,195 @@ +盘点 Python 的目标受众 +====== + +Python 是为谁设计的? + +几年前,我在 python-dev 邮件列表中,以及在活跃的 CPython 核心开发人员和认为参与这一过程不是有效利用个人时间和精力的人中[强调][17]说,“CPython 的发展太快了也太慢了” 是很多冲突的原因之一。 + +我一直认为事实确实如此,但这也是一个要点,在这几年中我也花费了很多时间去反思它。在我写那篇文章的时候,我还在波音防务澳大利亚公司(Boeing Defence Australia)工作。下个月,我离开了波音进入红帽亚太(Red Hat Asia-Pacific),并且开始在大企业的[开源供应链管理][18]方面取得了再分发者redistributor层面的视角。 + +### Python 的参考解析器使用情况 + +我尝试将 CPython 的使用情况分解如下,尽管看起来有些过于简化(注意,这些分类的界线并不是很清晰,他们仅关注于考虑新软件特性和版本发布后不同因素的影响): + +* 教育类:教育工作者的主要兴趣在于建模方法的教学和计算操作方面,*不会去*编写或维护生产级别的软件。例如: + * 澳大利亚的[数字课程][1] + * Lorena A. Barba 的 [AeroPython][2] +* 个人类的自动化和爱好者的项目:主要且经常是一类自写自用的软件。例如: + * my Digital Blasphemy [图片下载器][3] + * Paul Fenwick 的 (Inter)National [Rick Astley Hotline][4] +* 组织organisational过程自动化:主要且经常是为组织利益而编写的。例如: + * CPython 的[核心工作流工具][5] + * Linux 发行版的开发、构建和发行管理工具 +* “一劳永逸Set-and-forget” 的基础设施:这类软件在其生命周期中几乎不会升级,但在底层平台可能会升级(这种说法有时候有些争议)。例如: + * 大多数自我管理的企业或机构的基础设施(在那些资金充足的可持续工程计划中,这种情况是让人非常不安的) + * 拨款资助的软件(当最初的拨款耗尽时,维护通常会终止) + * 有严格认证要求的软件(如果没有绝对必要的话,从经济性考虑,重新认证比常规升级来说要昂贵很多) + * 没有自动升级功能的嵌入式软件系统 +* 持续升级的基础设施:具有健壮支撑的工程学模型的软件,对于依赖和平台升级通常是例行的,不必关心源码变更。例如: + * Facebook 的 Python 服务基础设施 + * 滚动发布的 Linux 分发版 + * 大多数的公共 PaaS 无服务器环境(Heroku、OpenShift、AWS Lambda、Google Cloud Functions、Azure Cloud Functions 等等) +* 长周期性升级的标准的操作环境:对其核心组件进行常规升级,但这些升级以年为单位进行,而不是周或月。例如: + * [VFX 平台][6] + * 长期支持(LTS)的 Linux 分发版 + * CPython 和 Python 标准库 + * 基础设施管理和编排工具(如 OpenStack、Ansible) + * 硬件控制系统 +* 短生命周期的软件:软件仅被使用一次,然后就丢弃或忽略,而不是随后接着升级。例如: + * 临时Ad hoc自动化脚本 + * 被确定为 “终止” 的单用户游戏(你玩了一次后,甚至都忘了去卸载它们,或许在一个新的设备上都不打算再去安装了) + * 不具备(或不完整)状态保存的单用户游戏(如果你卸载并重安装它们,游戏体验也不会有什么大的变化) + * 特定事件的应用程序(这些应用程序与特定的事件捆绑,一旦事件结束,这些应用程序就不再有用了) +* 常规用途的应用程序:部署后定期升级的软件。例如: + * 业务管理软件 + * 个人和专业的生产力应用程序(如 Blender) + * 开发工具和服务(如 Mercurial、Buildbot、Roundup) + * 多用户游戏,和其它明显处于持续状态还没有被定义为 “终止” 的游戏 + * 有自动升级功能的嵌入式软件系统 +* 共享的抽象层:在一个特定的问题领域中,设计用于让工作更高效的软件组件。即便是你没有亲自掌握该领域的所有错综复杂的东西。例如: + * 大多数的运行时runtime库和框架都归入这一类(如 Django、Flask、Pyramid、SQL Alchemy、NumPy、SciPy、requests) + * 适合归入这一类的许多测试和类型推断工具(如 pytest、Hypothesis、vcrpy、behave、mypy) + * 其它应用程序的插件(如 Blender plugins、OpenStack hardware adapters) + * 本身就代表了 “Python 世界” 基准的标准库(那是一个[难以置信的复杂][7]的世界观) + +### CPython 主要服务于哪些受众? + +从根本上说,CPython 和标准库的主要受众是哪些呢?是那些不管出于什么原因,将有限的标准库和从 PyPI 显式声明安装的第三方库组合起来所提供的服务还不能够满足需求的那些人。 + +为了更进一步简化上面回顾的不同用法和部署模型,宏观地将最大的 Python 用户群体分开来看,一类是在一些感兴趣的环境中将 Python 作为一种 _脚本语言_ 使用的人;另外一种是将它用作一个 _应用程序开发语言_ 的人,他们最终发布的是一种产品而不是他们的脚本。 + +把 Python 作为一种脚本语言来使用的开发者的典型特性包括: + +* 主要的工作单元是由一个 Python 文件组成的(或 Jupyter notebook),而不是一个 Python 和元数据文件的目录 +* 没有任何形式的单独的构建步骤 —— 是*作为*一个脚本分发的,类似于分发一个独立的 shell 脚本的方式 +* 没有单独的安装步骤(除了下载这个文件到一个合适的位置),因为在目标系统上要求预配置运行时环境 +* 没有显式的规定依赖关系,除了最低的 Python 版本,或一个预期的运行环境声明。如果需要一个标准库以外的依赖项,他们会通过一个环境脚本去提供(无论是操作系统、数据分析平台、还是嵌入 Python 运行时的应用程序) +* 没有单独的测试套件,使用 “通过你给定的输入,这个脚本是否给出了你期望的结果?” 这种方式来进行测试 +* 如果在执行前需要测试,它将以试运行dry run>预览preview模式来向用户展示软件*将*怎样运行 +* 如果使用静态代码分析工具,则通过集成到用户的软件开发环境中,而不是为每个脚本单独设置 + +相比之下,使用 Python 作为一个应用程序开发语言的开发者特征包括: + +* 主要的工作单元是由 Python 和元数据文件组成的目录,而不是单个 Python 文件 +* 在发布之前有一个单独的构建步骤去预处理应用程序,哪怕是把它的这些文件一起打包进一个 Python sdist、wheel 或 zipapp 中 +* 应用程序是否有独立的安装步骤做预处理,取决于它是如何打包的,和支持的目标环境 +* 外部的依赖明确存在于项目目录下的一个元数据文件中,要么是直接在项目目录中(如 `pyproject.toml`、`requirements.txt`、`Pipfile`),要么是作为生成的发行包的一部分(如 `setup.py`、`flit.ini`) +* 有独立的测试套件,或者作为一个 Python API 的一个单元测试,或者作为功能接口的集成测试,或者是两者都有 +* 静态分析工具的使用是在项目级配置的,并作为测试管理的一部分,而不是作为依赖 + +作为以上分类的一个结果,CPython 和标准库的主要用途是,在相应的 CPython 特性发布后,为教育和临时ad hoc的 Python 脚本环境提供 3-5 年基础维护服务。 + +对于临时脚本使用的情况,这个 3-5 年的延迟是由于再分发者给用户开发新版本的延迟造成的,以及那些再分发版本的用户们花在修改他们的标准操作环境上的时间。 + +对于教育环境中的情况是,教育工作者需要一些时间去评估新特性,然后决定是否将它们包含进教学的课程中。 + +### 这些相关问题的原因是什么? + +这篇文章很大程度上是受 Twitter 上对[我的这个评论][8]的讨论的启发,它援引了定义在 [PEP 411][9] 中临时Provisional API 的情形,作为一个开源项目的例子,对用户发出事实上的邀请,请其作为共同开发者去积极参与设计和开发过程,而不是仅被动使用已准备好的最终设计。 + +这些回复包括一些在更高级别的库中支持临时 API 的困难程度的一些沮丧性表述,没有这些库做临时状态的传递,因此而被限制为只有临时 API 的最新版本才支持这些相关特性,而不是任何早期版本的迭代。 + +我的[主要回应][10]是,建议开源提供者应该强制实施有限支持,通过这种强制的有限支持可以让个人的维护努力变得可持续。这意味着,如果对临时 API 的老版本提供迭代支持是非常痛苦的,那么,只有在项目开发人员自己需要、或有人为此支付费用时,他们才会去提供支持。这与我的这个观点是类似的,那就是,志愿者提供的项目是否应该免费支持老的、商业性质的、长周期的 Python 版本,这对他们来说是非常麻烦的事,我[不认为他们应该这样做][11],正如我所期望的那样,大多数这样的需求都来自于管理差劲的惯性,而不是真正的需求(真正的需求,应该去支付费用来解决问题)。 + +而我的[第二个回应][12]是去实现这一点,尽管多年来一直在讨论这个问题(比如,在上面链接中最早在 2011 年的一篇的文章中,以及在 Python 3 问答的回复中的[这里][13]、[这里][14]、和[这里][15],以及去年的这篇文章 [Python 包生态系统][16]中也提到了一些),但我从来没有真实地尝试直接去解释它在标准库设计过程中的影响。 + +如果没有这些背景,设计过程中的一部分,比如临时 API 的引入,或者是受启发而不同于它inspired-by-not-the-same-as的引入,看起来似乎是完全没有意义的,因为他们看起来似乎是在尝试对 API 进行标准化,而实际上并没有。 + +### 适合进入 PyPI 规划的方面有哪些? + +*任何*提交给 python-ideas 或 python-dev 的提案所面临的第一个门槛就是清楚地回答这个问题:“为什么 PyPI 上的模块不够好?”。绝大多数的提案都在这一步失败了,为了通过这一步,这里有几个常见的话题: + +* 比起下载一个合适的第三方库,新手一般可能更倾向于从互联网上 “复制粘贴” 错误的指导。(这就是为什么存在 `secrets` 库的原因:它使得人们很少去使用 `random` 模块,由于安全敏感的原因,它预期用于游戏和模拟统计) +* 该模块旨在提供一个参考实现,并允许与其它的竞争实现之间提供互操作性,而不是对所有人的所有事物都是必要的。(如 `asyncio`、`wsgiref`、`unittest`、和 `logging` 都是这种情况) +* 该模块是预期用于标准库的其它部分(如 `enum` 就是这种情况,像 `unittest` 一样) +* 该模块是被设计用于支持语言之外的一些语法(如 `contextlib`、`asyncio` 和 `typing`) +* 该模块只是普通的临时的脚本用途(如 `pathlib` 和 `ipaddress`) +* 该模块被用于一个教育环境(例如,`statistics` 模块允许进行交互式地探索统计的概念,尽管你可能根本就不会用它来做完整的统计分析) + +只通过了前面的 “PyPI 是不是明显不够好” 的检查,一个模块还不足以确保被纳入标准库中,但它已经足以将问题转变为 “在未来几年中,你所推荐的要包含的库能否对一般的入门级 Python 开发人员的经验有所提升?” + +标准库中的 `ensurepip` 和 `venv` 模块的引入也明确地告诉再分发者,我们期望的 Python 级别的打包和安装工具在任何平台的特定分发机制中都予以支持。 + +### 当添加它们到标准库中时,为什么一些 API 会被修改? + +现有的第三方模块有时候会被批量地采用到标准库中,在其它情况下,实际上添加的是吸收了用户对现有 API 体验之后进行重新设计和重新实现的 API,但是会根据另外的设计考虑和已经成为其中一部分的语言实现参考来进行一些删除或细节修改。 + +例如,与流行的第三方库 `path.py`、`pathlib` 的前身不同,它们并*没有*定义字符串子类,而是以独立的类型替代。作为解决文件互操作性问题的结果,定义了文件系统路径协议,它允许使用文件系统路径的接口去使用更多的对象。 + +为了在 “IP 地址” 这个概念的教学上提供一个更好的工具,`ipaddress` 模块设计调整为明确地将主机接口定义与地址和网络的定义区分开(IP 地址被关联到特定的 IP 网络),而最原始的 `ipaddr` 模块中,在网络术语的使用方式上不那么严格。 + +另外的情况是,标准库将综合多种现有的方法的来构建,以及为早已存在的库定义 API 时,还有可能依赖不存在的语法特性。比如,`asyncio` 和 `typing` 模块就全部考虑了这些因素,虽然在 PEP 557 中正在考虑将后者所考虑的因素应用到 `dataclasses` API 上。(它可以被总结为 “像属性一样,但是使用可变注释作为字段声明”)。 + +这类修改的原理是,这类库不会消失,并且它们的维护者对标准库维护相关的那些限制通常并不感兴趣(特别是相对缓慢的发布节奏)。在这种情况下,在标准库文档的更新版本中使用 “See Also” 链接指向原始模块的做法非常常见,尤其是在第三方版本额外提供了标准库模块中忽略的那些特性时。 + +### 为什么一些 API 是以临时的形式被添加的? + +虽然 CPython 维护了 API 的弃用策略,但在没有正当理由的情况下,我们通常不会去使用该策略(在其他项目试图与 Python 2.7 保持兼容性时,尤其如此)。 + +然而在实践中,当添加这种受已有的第三方启发而不是直接精确拷贝第三方设计的新 API 时,所承担的风险要高于一些正常设计决定可能出现问题的风险。 + +当我们考虑到这种改变的风险比平常要高,我们将相关的 API 标记为临时,表示保守的终端用户要避免完全依赖它们,而共享抽象层的开发者可能希望对他们准备去支持的那个临时 API 的版本考虑实施比平时更严格的限制。 + +### 为什么只有一些标准库 API 被升级? + +这里简短的回答得到升级的主要 API 有哪些: + +* 不太可能有大量的外部因素干扰的附加更新的 +* 无论是对临时脚本用例还是对促进将来多个第三方解决方案之间的互操作性,都有明显好处的 +* 对这方面感兴趣的人提交了一个可接受的建议的 + +如果在将模块用于应用程序开发目的时(如 `datetime`),现有模块的限制主要是显而易见的,如果再分发者通过第三方方案很容易地实现了改进,(如 `requests`),或者如果标准库的发布节奏与所需要的包之间真的存在冲突,(如 `certifi`),那么,建议对标准库版本进行改变的因素将显著减少。 + +从本质上说,这和上面关于 PyPI 问题正好相反:因为从应用程序开发人员体验的角度来说,PyPI 的分发机制通常已经够好了,这种分发方式的改进是有意义的,允许再分发者和平台提供者自行决定将哪些内容作为他们缺省提供的一部分。 + +假设在 3-5 年时间内,缺省出现了被认为是改变带来的可感知的价值时,才会将这些改变纳入到 CPython 和标准库中。 + +### 标准库任何部分都有独立的版本吗? + +是的,就像是 `ensurepip` 使用的捆绑模式(CPython 发行了一个 `pip` 的最新捆绑版本,而并没有把它放进标准库中),将来可能被应用到其它模块中。 + +最有可能的第一个候选者是 `distutils` 构建系统,因为切换到这种模式将允许构建系统在多个发行版本之间保持一致。 + +这种处理方式的其它可能候选者是 Tcl/Tk 图形套件和 IDLE 编辑器,它们已经被拆分,并且一些开发者将其改为可选安装项。 + +### 这些注意事项为什么很重要? + +从本质上说,那些积极参与开源开发的人就是那些致力于开源应用程序和共享抽象层的人。 + +那些写一些临时脚本或为学生设计一些教学习题的人,通常不认为他们是软件开发人员 —— 他们是教师、系统管理员、数据分析人员、金融工程师、流行病学家、物理学家、生物学家、市场研究员、动画师、平面设计师等等。 + +对于一种语言,当我们全部的担心都是开发人员的经验时,那么我们就可以根据人们所知道的内容、他们使用的工具种类、他们所遵循的开发流程种类、构建和部署他们软件的方法等假定,来做大量的简化。 + +当应用程序运行时作为脚本引擎广泛流行时,事情会变得更加复杂。做好任何一项工作已经很困难,并且作为单个项目的一部分来平衡两个受众的需求会导致双方经常不理解和不相信。 + +这篇文章不是为了说明我们在开发 CPython 过程中从来没有做出过不正确的决定 —— 它只是去合理地回应那些对添加到 Python 标准库中的看上去很荒谬的特性的质疑,它将是 “我不是那个特性的预期目标受众的一部分”,而不是 “我对它没有兴趣,因此它对所有人都是毫无用处和没有价值的,添加它纯属骚扰我”。 + +--- + +via: http://www.curiousefficiency.org/posts/2017/10/considering-pythons-target-audience.html + +作者:[Nick Coghlan][a] +译者:[qhwdw](https://github.com/qhwdw) +校对:[wxy](https://github.com/wxy)、[pityonline](https://github.com/pityonline) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: http://www.curiousefficiency.org/pages/about.html +[1]: https://aca.edu.au/#home-unpack +[2]: https://github.com/barbagroup/AeroPython +[3]: https://nbviewer.jupyter.org/urls/bitbucket.org/ncoghlan/misc/raw/default/notebooks/Digital%20Blasphemy.ipynb +[4]: https://github.com/pjf/rickastley +[5]: https://github.com/python/core-workflow +[6]: http://www.vfxplatform.com/ +[7]: http://www.curiousefficiency.org/posts/2015/10/languages-to-improve-your-python.html#broadening-our-horizons +[8]: https://twitter.com/ncoghlan_dev/status/916994106819088384 +[9]: https://www.python.org/dev/peps/pep-0411/ +[10]: https://twitter.com/ncoghlan_dev/status/917092464355241984 +[11]: http://www.curiousefficiency.org/posts/2015/04/stop-supporting-python26.html +[12]: https://twitter.com/ncoghlan_dev/status/917088410162012160 +[13]: http://python-notes.curiousefficiency.org/en/latest/python3/questions_and_answers.html#wouldn-t-a-python-2-8-release-help-ease-the-transition +[14]: http://python-notes.curiousefficiency.org/en/latest/python3/questions_and_answers.html#doesn-t-this-make-python-look-like-an-immature-and-unstable-platform +[15]: http://python-notes.curiousefficiency.org/en/latest/python3/questions_and_answers.html#what-about-insert-other-shiny-new-feature-here +[16]: http://www.curiousefficiency.org/posts/2016/09/python-packaging-ecosystem.html +[17]: http://www.curiousefficiency.org/posts/2011/04/musings-on-culture-of-python-dev.html +[18]: http://community.redhat.com/blog/2015/02/the-quid-pro-quo-of-open-infrastructure/ diff --git a/published/201808/20171101 Linux command line tools for working with non-Linux users.md b/published/201808/20171101 Linux command line tools for working with non-Linux users.md new file mode 100644 index 0000000000..7e8194b432 --- /dev/null +++ b/published/201808/20171101 Linux command line tools for working with non-Linux users.md @@ -0,0 +1,70 @@ +用于与非 Linux 用户一同工作的 Linux 命令行工具 +====== +> 如果你在 Linux 终端工作,那么与非 Linux 用户一同工作时可能遇到困难。这些工具有助于文档兼容性和企业即时消息。 + +![](https://images.techhive.com/images/article/2016/06/linux-shell-100666628-large.jpg) + +我大部分时间都在使用 Shell(命令行、终端或其它随便什么你使用的平台)上。但是,当我需要与大量其他人合作时,这可能会有点挑战,特别是在大型企业公司中 —— 除了 shell 外其他都使用。 + +当公司内的其他人使用与你不同的平台时,问题就会变得更加严重。我倾向于使用 Linux。如果我在 Linux 终端上做了很多日常工作,而我的大多数同事都使用 Windows 10(完全使用 GUI 端),那么事情就会变得……有问题。 + +- **Network World 上另外一篇文章:**[**11 个没用但很酷的 Linux 终端技巧**][1] + +幸运的是,在过去的几年里,我已经想出如何处理这些问题。我已经找到了在非 Unix 的企业环境中使用 Linux(或其他类 Unix 系统)Shell 的方法。这些工具/技巧同样适用于在公司服务器上工作的系统管理员们,就像对开发人员或营销人员一样。 + +让我们首先关注对于大公司中的许多人来说似乎最难解决的两个方面:文档兼容性和企业即时消息。 + +### Linux 和非 Linux 系统之间的文档兼容性 + +出现的最大问题之一是简单的文字处理文档的兼容性。 + +假设你的公司已在 Microsoft Office 上进行了标准化。这让你难过。但不要失去希望!有很多方法可以使它(基本)可用 —— 甚至在 shell 中。 + +两个工具在我的武器库中至关重要:[Pandoc][2] 和 [Wordgrinder][3]。 + +Wordgrinder 是一个简单、直观的文字处理器。它可能不像 LibreOffice 那样功能齐全(或者,实际上,任何主要的 GUI 文字处理应用程序),但速度很快。它很稳定。它有足够的功能(和文件格式)来完成工作。事实上,我完全在 Wordgrinder 中写了我的大部分文章和书籍。 + +但是有一个问题(你知道肯定会有)。 + +Wordgrinder 不支持 .doc(或 .docx)文件。这意味着它无法读取使用 Windows 和 MS Office 的同事发送给你的大多数文件。 + +这就是 Pandoc 的用武之地。它是一个简单的文档转换器,可以将各种文件作为输入(MS Word、LibreOffice、HTML、markdown 等)并将它们转换为其他内容。它支持的格式数量绝对是惊人的 —— PDF、ePub、各种幻灯片格式。它确实使格式之间的文档转换变得轻而易举。 + +这并不是说我不会偶尔遇到格式或功能问题。要转换有大量自定义格式、某些脚本和嵌入式图表的 Word 文档?是的,在这个过程中会丢失很多。 + +但实际上,Pandoc(用于转换文件)和 Wordgrinder(用于文档编辑)的组合已经证明非常有用和强大。 + +### Linux 和非 Linux 系统之间的企业即时消息传递 + +每家公司都喜欢在即时通讯系统上实现标准化 —— 所有员工都可以使用它来保持实时联系。 + +在命令行中,这可能会变得棘手。如果贵公司使用 Google 环聊怎么办?或者 Novell GroupWise Messenger 怎么样?既没有官方支持,也没有基于终端的客户端。 + +谢天谢地,还有 [Finch 和 Hangups][4]。 + +Finch 是 Pidgin(开源,多协议消息客户端)的终端版本。它支持各种协议,包括 Novell GroupWise、(很快会死的)AOL Instant Messenger 以及其他一些协议。 + +而 Hangups 是 Google Hangouts 客户端的开源实现 —— 包含消息历史记录和精美的标签界面。 + +这些方案都不会为你提供语音或视频聊天功能,但对于基于文本的消息,它们的工作得非常好。它们并不完美(Finch 的用户界面需要时间习惯),但它们肯定足以与你的同事保持联系。 + +这些方案能否让你在纯文本 shell 中舒适地过完一个工作日?可能不会。就个人而言,我发现(使用这些工具和其他工具)我可以轻松地将 80% 的时间花在纯文本界面上。 + +这感觉很棒。 + + +-------------------------------------------------------------------------------- + +via: https://www.networkworld.com/article/3235688/linux/linux-command-line-tools-for-working-with-non-linux-users.html + +作者:[Bryan Lunduke][a] +译者:[geekpi](https://github.com/geekpi) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.networkworld.com/author/Bryan-Lunduke/ +[1]:http://www.networkworld.com/article/2926630/linux/11-pointless-but-awesome-linux-terminal-tricks.html#tk.nww-fsb +[2]:https://www.youtube.com/watch?v=BkTYHChkDoE +[3]:https://www.youtube.com/watch?v=WnMyamBgKFE +[4]:https://www.youtube.com/watch?v=19lbWnYOsTc diff --git a/published/201808/20171102 Using User Namespaces on Docker.md b/published/201808/20171102 Using User Namespaces on Docker.md new file mode 100644 index 0000000000..666beb1ae6 --- /dev/null +++ b/published/201808/20171102 Using User Namespaces on Docker.md @@ -0,0 +1,115 @@ +使用 Docker 的用户名字空间功能 +====== + +用户名字空间User Namespaces 于 Docker 1.10 版本正式纳入其中,该功能允许主机系统将自身的 `uid` 和 `gid` 映射为容器进程中的另一个 `uid` 和 `gid`。这对 Docker 的安全性来说是一项巨大的改进。下面我会通过一个案例来展示一下用户名字空间能够解决的问题,以及如何启用该功能。 + +### 创建一个 Docker Machine + +如果你已经创建好了一台用来试验用户名字空间的 docker 机器Machine,那么可以跳过这一步。我在自己的 Macbook 上安装了 Docker Toolbox,因此我只需用 `docker-machine` 命令就很简单地创建一个基于 VirtualBox 的 Docker 机器(这里假设主机名为 `host1`): + +``` +# Create host1 +$ docker-machine create --driver virtualbox host1 + +# Login to host1 +$ docker-machine ssh host1 +``` + +### 理解在用户名字空间未启用的情况下,非 root 用户能做什么 + +在启用用户名字空间前,我们先来看一下会有什么问题。Docker 到底哪个地方做错了?首先,使用 Docker 的一大优势在于用户在容器中可以拥有 root 权限,因此用户可以很方便地安装软件包。但是在 Linux 容器技术中这也是一把双刃剑。只要经过少许操作,非 root 用户就能以 root 的权限访问主机系统中的内容,比如 `/etc`。下面是操作步骤。 + +``` +# Run a container and mount host1's /etc onto /root/etc +$ docker run --rm -v /etc:/root/etc -it ubuntu + +# Make some change on /root/etc/hosts +root@34ef23438542:/# vi /root/etc/hosts + +# Exit from the container +root@34ef23438542:/# exit + +# Check /etc/hosts +$ cat /etc/hosts +``` + +你可以看到,步骤简单到难以置信,很明显 Docker 并不适用于运行在多人共享的电脑上。但是现在,通过用户名字空间,Docker 可以避免这个问题。 + +### 启用用户名字空间 + +``` +# Create a user called "dockremap" +$ sudo adduser dockremap + +# Setup subuid and subgid +$ sudo sh -c 'echo dockremap:500000:65536 > /etc/subuid' +$ sudo sh -c 'echo dockremap:500000:65536 > /etc/subgid' +``` + +然后,打开 `/etc/init.d/docker`,并在 `/usr/local/bin/docker daemon` 后面加上 `--userns-remap=default`,像这样: + +``` +$ sudo vi /etc/init.d/docker + +/usr/local/bin/docker daemon --userns-remap=default -D -g "$DOCKER_DIR" -H unix:// $DOCKER_HOST $EXTRA_ARGS >> "$DOCKER_LOGFILE" 2>&1 & +``` + +然后重启 Docker: + +``` +$ sudo /etc/init.d/docker restart +``` + +这就完成了! + +**注意**:若你使用的是 CentOS 7,则你需要了解两件事。 + +1. 内核默认并没有启用用户名字空间。运行下面命令并重启系统,可以启用该功能。 + + ``` + sudo grubby --args="user_namespace.enable=1" \ + --update-kernel=/boot/vmlinuz-3.10.0-XXX.XX.X.el7.x86_64 + ``` + +2. CentOS 7 使用 `systemctl` 来管理服务,因此你需要编辑的文件是 `/usr/lib/systemd/system/docker.service`。 + +### 确认用户名字空间是否正常工作 + +若一切都配置妥当,则你应该无法再在容器中编辑 host1 上的 `/etc` 了。让我们来试一下。 + +``` +# Create a container and mount host1's /etc to container's /root/etc +$ docker run --rm -v /etc:/root/etc -it ubuntu + +# Check the owner of files in /root/etc, which should be "nobody nogroup". +root@d5802c5e670a:/# ls -la /root/etc +total 180 +drwxr-xr-x 11 nobody nogroup 1100 Mar 21 23:31 . +drwx------ 3 root root 4096 Mar 21 23:50 .. +lrwxrwxrwx 1 nobody nogroup 19 Mar 21 23:07 acpi -> /usr/local/etc/acpi +-rw-r--r-- 1 nobody nogroup 48 Mar 10 22:09 boot2docker +drwxr-xr-x 2 nobody nogroup 60 Mar 21 23:07 default + +# Try creating a file in /root/etc +root@d5802c5e670a:/# touch /root/etc/test +touch: cannot touch '/root/etc/test': Permission denied + +# Try deleting a file +root@d5802c5e670a:/# rm /root/etc/hostname +rm: cannot remove '/root/etc/hostname': Permission denied +``` + +好了,太棒了。这就是用户名字空间的工作方式。 + +--- + +via: https://coderwall.com/p/s_ydlq/using-user-namespaces-on-docker + +作者:[Koji Tanaka][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[lujun9972](https://github.com/lujun9972) +校对:[pityonline](https://github.com/pityonline) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://coderwall.com/kjtanaka diff --git a/published/201808/20171130 Google launches TensorFlow-based vision recognition kit for RPi Zero W.md b/published/201808/20171130 Google launches TensorFlow-based vision recognition kit for RPi Zero W.md new file mode 100644 index 0000000000..47973ad9de --- /dev/null +++ b/published/201808/20171130 Google launches TensorFlow-based vision recognition kit for RPi Zero W.md @@ -0,0 +1,79 @@ +Google 为树莓派 Zero W 发布了基于TensorFlow 的视觉识别套件 +=============== + +![](http://linuxgizmos.com/files/google_aiyvisionkit-thm.jpg) + +Google 发行了一个 45 美元的 “AIY Vision Kit”,它是运行在树莓派 Zero W 上的基于 TensorFlow 的视觉识别开发套件,它使用了一个带 Movidius 芯片的 “VisionBonnet” 板。 + +为加速该设备上的神经网络,Google 的 AIY 视频套件继承了早期树莓派上运行的 [AIY 项目][7] 的语音/AI 套件,这个型号的树莓派随五月份的 MagPi 杂志一起赠送。与语音套件和老的 Google 硬纸板 VR 查看器一样,这个新的 AIY 视觉套件也使用一个硬纸板包装。这个套件和 [Cloud Vision API][8] 是不一样的,它使用了一个在 2015 年演示过的基于树莓派的 GoPiGo 机器人,它完全在本地的处理能力上运行,而不需要使用一个云端连接。这个 AIY 视觉套件现在可以 45 美元的价格去预订,将在 12 月份发货。 + +[![](http://linuxgizmos.com/files/google_aiyvisionkit-sm.jpg)][9]   [![](http://linuxgizmos.com/files/rpi_zerow-sm.jpg)][10] + +*AIY 视觉套件,完整包装(左)和树莓派 Zero W* + +这个套件的主要处理部分除了所需要的 [树莓派 Zero W][21] 单片机之外 —— 一个基于 ARM11 的 1 GHz 的 Broadcom BCM2836 片上系统,另外的就是 Google 最新的 VisionBonnet RPi 附件板。这个 VisionBonnet pHAT 附件板使用了一个 Movidius MA2450,它是 [Movidius Myriad 2 VPU][22] 版的处理器。在 VisionBonnet 上,处理器为神经网络运行了 Google 的开源机器学习库 [TensorFlow][23]。因为这个芯片,使得视觉处理的速度最高达每秒 30 帧。 + +这个 AIY 视觉套件要求用户提供一个树莓派 Zero W、一个 [树莓派摄像机 v2][11]、以及一个 16GB 的 micro SD 卡,它用来下载基于 Linux 的 OS 镜像。这个套件包含了 VisionBonnet、一个 RGB 街机风格的按钮、一个压电扬声器、一个广角镜头套件、以及一个包裹它们的硬纸板。还有一些就是线缆、支架、安装螺母,以及连接部件。 + + + [![](http://linuxgizmos.com/files/google_aiyvisionkit_pieces-sm.jpg)][12]   [![](http://linuxgizmos.com/files/google_visionbonnet-sm.jpg)][13] + +*AIY 视觉套件组件(左)和 VisonBonnet 附件板* + +有三个可用的神经网络模型。一个是通用的模型,它可以识别常见的 1000 个东西,一个是面部检测模型,它可以对 “快乐程度” 进行评分,从 “悲伤” 到 “大笑”,还有一个模型可以用来辨别图像内容是狗、猫、还是人。这个 1000 个图片模型源自 Google 的开源 [MobileNets][24],它是基于 TensorFlow 家族的计算机视觉模型,它设计用于资源受限的移动或者嵌入式设备。 + +MobileNet 模型是低延时、低功耗,和参数化的,以满足资源受限的不同使用情景。Google 说,这个模型可以用于构建分类、检测、嵌入、以及分隔。在本月的早些时候,Google 发布了一个开发者预览版,它是一个对 Android 和 iOS 移动设备友好的 [TensorFlow Lite][14] 库,它与 MobileNets 和 Android 神经网络 API 是兼容的。 + + [![](http://linuxgizmos.com/files/google_aiyvisionkit_assembly-sm.jpg)][15] + +*AIY 视觉套件包装图* + +除了提供这三个模型之外,AIY 视觉套件还提供了基本的 TensorFlow 代码和一个编译器,因此用户可以去开发自己的模型。另外,Python 开发者可以写一些新软件去定制 RGB 按钮颜色、压电元素声音、以及在 VisionBonnet 上的 4x GPIO 针脚,它可以添加另外的指示灯、按钮、或者伺服机构。Potential 模型包括识别食物、基于可视化输入来打开一个狗门、当你的汽车偏离车道时发出文本信息、或者根据识别到的人的面部表情来播放特定的音乐。 + + [![](http://linuxgizmos.com/files/movidius_myriad2vpu_block-sm.jpg)][16]   [![](http://linuxgizmos.com/files/movidius_myriad2_reference_board-sm.jpg)][17] + +*Myriad 2 VPU 结构图(左)和参考板* + +Movidius Myriad 2 处理器在一个标称 1W 的功耗下提供每秒万亿次浮点运算的性能。在被 Intel 收购之前,这个芯片最早出现在 Tango 项目的参考平台上,并内置在 2016 年 5 月由 Movidius 首次亮相的、Ubuntu 驱动的 USB 的 [Fathom][25] 神经网络处理棒中。根据 Movidius 的说法,Myriad 2 目前已经在 “市场上数百万的设备上使用”。 + +**更多信息** + +AIY 视觉套件可以在 Micro Center 上预订,价格为 $44.99,预计在(2017 年) 12 月初发货。更多信息请参考 AIY 视觉套件的 [公告][18]、[Google 博客][19]、以及 [Micro Center 购物页面][20]。 + +-------------------------------------------------------------------------------- + +via: http://linuxgizmos.com/google-launches-tensorflow-based-vision-recognition-kit-for-rpi-zero-w/ + +作者:[Eric Brown][a] +译者:[qhwdw](https://github.com/qhwdw) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:http://linuxgizmos.com/google-launches-tensorflow-based-vision-recognition-kit-for-rpi-zero-w/ +[1]:http://twitter.com/share?url=http://linuxgizmos.com/google-launches-tensorflow-based-vision-recognition-kit-for-rpi-zero-w/&text=Google%20launches%20TensorFlow-based%20vision%20recognition%20kit%20for%20RPi%20Zero%20W%20 +[2]:https://plus.google.com/share?url=http://linuxgizmos.com/google-launches-tensorflow-based-vision-recognition-kit-for-rpi-zero-w/ +[3]:http://www.facebook.com/sharer.php?u=http://linuxgizmos.com/google-launches-tensorflow-based-vision-recognition-kit-for-rpi-zero-w/ +[4]:http://www.linkedin.com/shareArticle?mini=true&url=http://linuxgizmos.com/google-launches-tensorflow-based-vision-recognition-kit-for-rpi-zero-w/ +[5]:http://reddit.com/submit?url=http://linuxgizmos.com/google-launches-tensorflow-based-vision-recognition-kit-for-rpi-zero-w/&title=Google%20launches%20TensorFlow-based%20vision%20recognition%20kit%20for%20RPi%20Zero%20W +[6]:mailto:?subject=Google%20launches%20TensorFlow-based%20vision%20recognition%20kit%20for%20RPi%20Zero%20W&body=%20http://linuxgizmos.com/google-launches-tensorflow-based-vision-recognition-kit-for-rpi-zero-w/ +[7]:http://linuxgizmos.com/free-raspberry-pi-voice-kit-taps-google-assistant-sdk/ +[8]:http://linuxgizmos.com/google-releases-cloud-vision-api-with-demo-for-pi-based-robot/ +[9]:http://linuxgizmos.com/files/google_aiyvisionkit.jpg +[10]:http://linuxgizmos.com/files/rpi_zerow.jpg +[11]:http://linuxgizmos.com/raspberry-pi-cameras-jump-to-8mp-keep-25-dollar-price/ +[12]:http://linuxgizmos.com/files/google_aiyvisionkit_pieces.jpg +[13]:http://linuxgizmos.com/files/google_visionbonnet.jpg +[14]:https://developers.googleblog.com/2017/11/announcing-tensorflow-lite.html +[15]:http://linuxgizmos.com/files/google_aiyvisionkit_assembly.jpg +[16]:http://linuxgizmos.com/files/movidius_myriad2vpu_block.jpg +[17]:http://linuxgizmos.com/files/movidius_myriad2_reference_board.jpg +[18]:https://blog.google/topics/machine-learning/introducing-aiy-vision-kit-make-devices-see/ +[19]:https://developers.googleblog.com/2017/11/introducing-aiy-vision-kit-add-computer.html +[20]:http://www.microcenter.com/site/content/Google_AIY.aspx?ekw=aiy&rd=1 +[21]:http://linuxgizmos.com/raspberry-pi-zero-w-adds-wifi-and-bluetooth-for-only-5-more/ +[22]:https://www.movidius.com/solutions/vision-processing-unit +[23]:https://www.tensorflow.org/ +[24]:https://research.googleblog.com/2017/06/mobilenets-open-source-models-for.html +[25]:http://linuxgizmos.com/usb-stick-brings-neural-computing-functions-to-devices/ +[26]:http://linuxgizmos.com/google-launches-tensorflow-based-vision-recognition-kit-for-rpi-zero-w/ diff --git a/published/201808/20180107 7 leadership rules for the DevOps age.md b/published/201808/20180107 7 leadership rules for the DevOps age.md new file mode 100644 index 0000000000..884aa54eaa --- /dev/null +++ b/published/201808/20180107 7 leadership rules for the DevOps age.md @@ -0,0 +1,125 @@ +DevOps 时代的 7 个领导力准则 +====== + +> DevOps 是一种持续性的改变和提高:那么也准备改变你所珍视的领导力准则吧。 + +![](https://enterprisersproject.com/sites/default/files/styles/620x350/public/images/CIO_DigitalAcumen_2.png?itok=TGeMQYs4) + +如果 [DevOps] 最终更多的是一种文化而非某种技术或者平台,那么请记住:它没有终点线。而是一种持续性的改变和提高——而且最高管理层并不及格。 + +然而,如果期望 DevOps 能够帮助获得更多的成果,领导者需要[修订他们的一些传统的方法][2]。让我们考虑 7 个在 DevOps 时代更有效的 IT 领导的想法。 + +### 1、 向失败说“是的” + +“失败”这个词在 IT 领域中一直包含着非常具体的意义,而且通常是糟糕的意思:服务器失败、备份失败、硬盘驱动器失败——你的印象就是如此。 + +然而一个健康的 DevOps 文化取决于如何重新定义失败——IT 领导者应该在他们的字典里重新定义这个单词,使这个词的含义和“机会”对等起来。 + +“在 DevOps 之前,我们曾有一种惩罚失败者的文化,”[Datical][3] 的首席技术官兼联合创始人罗伯特·里夫斯说,“我们学到的仅仅是去避免错误。在 IT 领域避免错误的首要措施就是不要去改变任何东西:不要加速版本迭代的日程,不要迁移到云中,不要去做任何不同的事” + +那是一个旧时代的剧本,里夫斯坦诚的说,它已经不起作用了,事实上,那种停滞实际上是失败。 + +“那些缓慢的发布周期并逃避云的公司被恐惧所麻痹——他们将会走向失败,”里夫斯说道。“IT 领导者必须拥抱失败,并把它当做成一个机遇。人们不仅仅从他们的过错中学习,也会从别人的错误中学习。开放和[安全心理][4]的文化促进学习和提高。” + +**[相关文章:[为什么敏捷领导者谈论“失败”必须超越它本义][5]]** + +### 2、 在管理层渗透开发运营的理念 + +尽管 DevOps 文化可以在各个方向有机的发展,那些正在从单体、孤立的 IT 实践中转变出来的公司,以及可能遭遇逆风的公司——需要高管层的全面支持。如果缺少了它,你就会传达模糊的信息,而且可能会鼓励那些宁愿被推着走的人,但这是我们一贯的做事方式。[改变文化是困难的][6];人们需要看到高管层完全投入进去并且知道改变已经实际发生了。 + +“高层管理必须全力支持 DevOps,才能成功的实现收益”,来自 [Rainforest QA][7] 的首席信息官德里克·蔡说道。 + +成为一个 DevOps 商店。德里克指出,涉及到公司的一切,从技术团队到工具到进程到规则和责任。 + +“没有高层管理的统一赞助支持,DevOps 的实施将很难成功,”德里克说道,“因此,在转变到 DevOps 之前在高层中保持一致是很重要的。” + +### 3、 不要只是声明 “DevOps”——要明确它 + +即使 IT 公司也已经开始张开双臂拥抱 DevOps,也可能不是每个人都在同一个步调上。 + +**[参考我们的相关文章,[3 阐明了DevOps和首席技术官们必须在同一进程上][8]]** + +造成这种脱节的一个根本原因是:人们对这个术语的有着不同的定义理解。 + +“DevOps 对不同的人可能意味着不同的含义,”德里克解释道,“对高管层和副总裁层来说,要执行明确的 DevOps 的目标,清楚地声明期望的成果,充分理解带来的成果将如何使公司的商业受益,并且能够衡量和报告成功的过程。” + +事实上,在基线定义和远景之外,DevOps 要求正在进行频繁的交流,不是仅仅在小团队里,而是要贯穿到整个组织。IT 领导者必须将它设置为优先。 + +“不可避免的,将会有些阻碍,在商业中将会存在失败和破坏,”德里克说道,“领导者们需要清楚的将这个过程向公司的其他人阐述清楚,告诉他们他们作为这个过程的一份子能够期待的结果。” + +### 4、 DevOps 对于商业和技术同样重要 + +IT 领导者们成功的将 DevOps 商店的这种文化和实践当做一项商业策略,以及构建和运营软件的方法。DevOps 是将 IT 从支持部门转向战略部门的推动力。 + +IT 领导者们必须转变他们的思想和方法,从成本和服务中心转变到驱动商业成果,而且 DevOps 的文化能够通过自动化和强大的协作加速这些成果,来自 [CYBRIC][9] 的首席技术官和联合创始人迈克·凯尔说道。 + +事实上,这是一个强烈的趋势,贯穿这些新“规则”,在 DevOps 时代走在前沿。 + +“促进创新并且鼓励团队成员去聪明的冒险是 DevOps 文化的一个关键部分,IT 领导者们需要在一个持续的基础上清楚的和他们交流”,凯尔说道。 + +“一个高效的 IT 领导者需要比以往任何时候都要积极的参与到业务中去,”来自 [West Monroe Partners][10] 的性能服务部门的主任埃文说道,“每年或季度回顾的日子一去不复返了——[你需要欢迎每两周一次的挤压整理][11],你需要有在年度水平上的思考战略能力,在冲刺阶段的互动能力,在商业期望满足时将会被给予一定的奖励。” + +### 5、 改变妨碍 DevOps 目标的任何事情 + +虽然 DevOps 的老兵们普遍认为 DevOps 更多的是一种文化而不是技术,成功取决于通过正确的过程和工具激活文化。当你声称自己的部门是一个 DevOps 商店却拒绝对进程或技术做必要的改变,这就是你买了辆法拉利却使用了用了 20 年的引擎,每次转动钥匙都会冒烟。 + +展览 A: [自动化][12]。这是 DevOps 成功的重要并行策略。 + +“IT 领导者需要重点强调自动化,”卡伦德说,“这将是 DevOps 的前期投资,但是如果没有它,DevOps 将会很容易被低效吞噬,而且将会无法完整交付。” + +自动化是基石,但改变不止于此。 + +“领导者们需要推动自动化、监控和持续交付过程。这意着对现有的实践、过程、团队架构以及规则的很多改变,” 德里克说。“领导者们需要改变一切会阻碍团队去实现完全自动化的因素。” + +### 6、 重新思考团队架构和能力指标 + +当你想改变时……如果你桌面上的组织结构图和你过去大部分时候嵌入的名字都是一样的,那么你是时候该考虑改革了。 + +“在这个 DevOps 的新时代文化中,IT 执行者需要采取一个全新的方法来组织架构。”凯尔说,“消除组织的边界限制,它会阻碍团队间的合作,允许团队自我组织、敏捷管理。” + +凯尔告诉我们在 DevOps 时代,这种反思也应该拓展应用到其他领域,包括你怎样衡量个人或者团队的成功,甚至是你和人们的互动。 + +“根据业务成果和总体的积极影响来衡量主动性,”凯尔建议。“最后,我认为管理中最重要的一个方面是:有同理心。” + +注意很容易收集的到测量值不是 DevOps 真正的指标,[Red Hat] 的技术专家戈登·哈夫写到,“DevOps 应该把指标以某种形式和商业成果绑定在一起”,他指出,“你可能并不真正在乎开发者些了多少代码,是否有一台服务器在深夜硬件损坏,或者是你的测试是多么的全面。你甚至都不直接关注你的网站的响应情况或者是你更新的速度。但是你要注意的是这些指标可能和顾客放弃购物车去竞争对手那里有关,”参考他的文章,[DevOps 指标:你在测量什么?] + +### 7、 丢弃传统的智慧 + +如果 DevOps 时代要求关于 IT 领导能力的新的思考方式,那么也就意味着一些旧的方法要被淘汰。但是是哪些呢? + +“说实话,是全部”,凯尔说道,“要摆脱‘因为我们一直都是以这种方法做事的’的心态。过渡到 DevOps 文化是一种彻底的思维模式的转变,不是对瀑布式的过去和变革委员会的一些细微改变。” + +事实上,IT 领导者们认识到真正的变革要求的不只是对旧方法的小小接触。它更多的是要求对之前的进程或者策略的一个重新启动。 + +West Monroe Partners 的卡伦德分享了一个阻碍 DevOps 的领导力的例子:未能拥抱 IT 混合模型和现代的基础架构比如说容器和微服务。 + +“我所看到的一个大的规则就是架构整合,或者认为在一个同质的环境下长期的维护会更便宜,”卡伦德说。 + +**领导者们,想要更多像这样的智慧吗?[注册我们的每周邮件新闻报道][15]。** + +-------------------------------------------------------------------------------- + +via: https://enterprisersproject.com/article/2018/1/7-leadership-rules-devops-age + +作者:[Kevin Casey][a] +译者:[FelixYFZ](https://github.com/FelixYFZ) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://enterprisersproject.com/user/kevin-casey +[1]:https://enterprisersproject.com/tags/devops +[2]:https://enterprisersproject.com/article/2017/7/devops-requires-dumping-old-it-leadership-ideas +[3]:https://www.datical.com/ +[4]:https://rework.withgoogle.com/guides/understanding-team-effectiveness/steps/foster-psychological-safety/ +[5]:https://enterprisersproject.com/article/2017/10/why-agile-leaders-must-move-beyond-talking-about-failure?sc_cid=70160000000h0aXAAQ +[6]:https://enterprisersproject.com/article/2017/10/how-beat-fear-and-loathing-it-change +[7]:https://www.rainforestqa.com/ +[8]:https://enterprisersproject.com/article/2018/1/3-areas-where-devops-and-cios-must-get-same-page +[9]:https://www.cybric.io/ +[10]:http://www.westmonroepartners.com/ +[11]:https://www.scrumalliance.org/community/articles/2017/february/product-backlog-grooming +[12]:https://www.redhat.com/en/topics/automation?intcmp=701f2000000tjyaAAA +[13]:https://www.redhat.com/en?intcmp=701f2000000tjyaAAA +[14]:https://enterprisersproject.com/article/2017/7/devops-metrics-are-you-measuring-what-matters +[15]:https://enterprisersproject.com/email-newsletter?intcmp=701f2000000tsjPAAQ diff --git a/published/201808/20180118 How to Play Sound Through Two or More Output Devices in Linux.md b/published/201808/20180118 How to Play Sound Through Two or More Output Devices in Linux.md new file mode 100644 index 0000000000..42e8a7de13 --- /dev/null +++ b/published/201808/20180118 How to Play Sound Through Two or More Output Devices in Linux.md @@ -0,0 +1,62 @@ +Linux 下如何通过两个或多个输出设备播放声音 +====== + +![](https://www.maketecheasier.com/assets/uploads/2018/01/output-audio-multiple-devices-featured.jpg) + +在 Linux 上处理音频是一件很痛苦的事情。Pulseaudio 的出现则是利弊参半。虽然有些事情 Pluseaudio 能够做的更好,但有些事情则反而变得更复杂了。处理音频的输出就是这么一件事情。 + +如果你想要在 Linux PC 上启用多个音频输出,你只需要利用一个简单的工具就能在一个虚拟j接口上启用另一个声音设备。这比看起来要简单的多。 + +你可能会好奇为什么要这么做,一个很常见的情况是用电脑在电视上播放视频,你可以同时使用电脑和电视上的扬声器。 + +### 安装 Paprefs + +实现从多个来源启用音频播放的最简单的方法是是一款名为 “paprefs” 的简单图形化工具。它是 PulseAudio Preferences 的缩写。 + +该软件包含在 Ubuntu 仓库中,可以直接用 apt 来进行安装。 + +``` +sudo apt install paprefs +``` + +安装后就能狗启动这款程序了。 + +### 启动双音频播放 + +虽然这款工具是图形化的,但作为普通用户在命令行中输入 `paprefs` 来启动它恐怕还是要更容易一些。 + +打开的窗口中有一些标签页,这些标签页内有一些可以调整的设置项。我们这里选择最后那个标签页,“Simultaneous Output。” + +![Paprefs on Ubuntu][1] + +这个标签页中没有什么内容,只是一个复选框用来启用该设置。 + +下一步,打开常规的声音首选项。这在不同的发行版中位于不同的位置。在 Ubuntu 上,它位于 GNOME 系统设置内。 + +![Enable Simultaneous Audio][2] + +打开声音首选项后,选择 “output” 标签页。勾选 “Simultaneous output” 单选按钮。现在它就成了你的默认输出了。 + +### 测试一下 + +用什么东西进行测试随你喜欢,不过播放音乐总是可行的。如果你像前面建议的一样,用视频来进行测试也没问题。 + +一切顺利的话,你就能从所有连接的设备中听到有声音传出了。 + +这就是所有要做的事了。此功能最适用于有多个设备(如 HDMI 端口和标准模拟输出)时。你当然也可以试一下其他配置。你还需要注意,只有一个音量控制器,因此你需要根据实际情况调整物理输出设备。 + + +-------------------------------------------------------------------------------- + +via: https://www.maketecheasier.com/play-sound-through-multiple-devices-linux/ + +作者:[Nick Congleton][a] +译者:[lujun9972](https://github.com/lujun9972) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.maketecheasier.com/author/nickcongleton/ +[1]:https://www.maketecheasier.com/assets/uploads/2018/01/sa-paprefs.jpg (Paprefs on Ubuntu) +[2]:https://www.maketecheasier.com/assets/uploads/2018/01/sa-enable.jpg (Enable Simultaneous Audio) +[3]:https://depositphotos.com/89314442/stock-photo-headphones-on-speakers.html diff --git a/published/201808/20180306 How To Check All Running Services In Linux.md b/published/201808/20180306 How To Check All Running Services In Linux.md new file mode 100644 index 0000000000..d390d9427b --- /dev/null +++ b/published/201808/20180306 How To Check All Running Services In Linux.md @@ -0,0 +1,563 @@ +如何查看 Linux 中所有正在运行的服务 +====== + +有许多方法和工具可以查看 Linux 中所有正在运行的服务。大多数管理员会在 System V(SysV)初始化系统中使用 `service service-name status` 或 `/etc/init.d/service-name status`,而在 systemd 初始化系统中使用 `systemctl status service-name`。 + +以上命令可以清楚地显示该服务是否在服务器上运行,这也是每个 Linux 管理员都该知道的非常简单和基础的命令。 + +如果你对系统环境并不熟悉,也不清楚系统在运行哪些服务,你会如何检查? + +是的,我们的确有必要这样检查一下。这将有助于我们了解系统上运行了什么服务,以及哪些是必要的、哪些需要被禁用。 + +init(初始化initialization的简称)是在系统启动期间运行的第一个进程。`init` 是一个守护进程,它将持续运行直至关机。 + +大多数 Linux 发行版都使用如下的初始化系统之一: + +- System V 是更老的初始化系统 +- Upstart 是一个基于事件的传统的初始化系统的替代品 +- systemd 是新的初始化系统,它已经被大多数最新的 Linux 发行版所采用 + +### 什么是 System V(SysV) + +SysV(意即 System V) 初始化系统是早期传统的初始化系统和系统管理器。由于 sysVinit 系统上一些长期悬而未决的问题,大多数最新的发行版都适用于 systemd 系统。 + +### 什么是 Upstart 初始化系统 + +Upstart 是一个基于事件的 /sbin/init 的替代品,它控制在启动时的任务和服务的开始,在关机时停止它们,并在系统运行时监控它们。 + +它最初是为 Ubuntu 发行版开发的,但其是以适合所有 Linux 发行版的开发为目标的,以替换过时的 System-V 初始化系统。 + +### 什么是 systemd + +systemd 是一个新的初始化系统以及系统管理器,它已成为大多数 Linux 发行版中非常流行且广泛适应的新的标准初始化系统。`systemctl` 是一个 systemd 管理工具,它可以帮助我们管理 systemd 系统。 + +### 方法一:如何在 System V(SysV)系统中查看运行的服务 + +以下命令可以帮助我们列出 System V(SysV) 系统中所有正在运行的服务。 + +如果服务很多,我建议使用文件查看命令,如 `less`、`more` 等,以便得到清晰的结果。 + +``` +# service --status-all +或 +# service --status-all | more +或 +# service --status-all | less +``` + +``` +abrt-ccpp hook is installed +abrtd (pid 2131) is running... +abrt-dump-oops is stopped +acpid (pid 1958) is running... +atd (pid 2164) is running... +auditd (pid 1731) is running... +Frequency scaling enabled using ondemand governor +crond (pid 2153) is running... +hald (pid 1967) is running... +htcacheclean is stopped +httpd is stopped +Table: filter +Chain INPUT (policy ACCEPT) +num target prot opt source destination +1 ACCEPT all ::/0 ::/0 state RELATED,ESTABLISHED +2 ACCEPT icmpv6 ::/0 ::/0 +3 ACCEPT all ::/0 ::/0 +4 ACCEPT tcp ::/0 ::/0 state NEW tcp dpt:80 +5 ACCEPT tcp ::/0 ::/0 state NEW tcp dpt:21 +6 ACCEPT tcp ::/0 ::/0 state NEW tcp dpt:22 +7 ACCEPT tcp ::/0 ::/0 state NEW tcp dpt:25 +8 ACCEPT tcp ::/0 ::/0 state NEW tcp dpt:2082 +9 ACCEPT tcp ::/0 ::/0 state NEW tcp dpt:2086 +10 ACCEPT tcp ::/0 ::/0 state NEW tcp dpt:2083 +11 ACCEPT tcp ::/0 ::/0 state NEW tcp dpt:2087 +12 ACCEPT tcp ::/0 ::/0 state NEW tcp dpt:10000 +13 REJECT all ::/0 ::/0 reject-with icmp6-adm-prohibited + +Chain FORWARD (policy ACCEPT) +num target prot opt source destination +1 REJECT all ::/0 ::/0 reject-with icmp6-adm-prohibited + +Chain OUTPUT (policy ACCEPT) +num target prot opt source destination + +iptables: Firewall is not running. +irqbalance (pid 1826) is running... +Kdump is operational +lvmetad is stopped +mdmonitor is stopped +messagebus (pid 1929) is running... + SUCCESS! MySQL running (24376) +rndc: neither /etc/rndc.conf nor /etc/rndc.key was found +named is stopped +netconsole module not loaded +Usage: startup.sh { start | stop } +Configured devices: +lo eth0 eth1 +Currently active devices: +lo eth0 +ntpd is stopped +portreserve (pid 1749) is running... +master (pid 2107) is running... +Process accounting is disabled. +quota_nld is stopped +rdisc is stopped +rngd is stopped +rpcbind (pid 1840) is running... +rsyslogd (pid 1756) is running... +sandbox is stopped +saslauthd is stopped +smartd is stopped +openssh-daemon (pid 9859) is running... +svnserve is stopped +vsftpd (pid 4008) is running... +xinetd (pid 2031) is running... +zabbix_agentd (pid 2150 2149 2148 2147 2146 2140) is running... +``` + +执行以下命令,可以只查看正在运行的服务: + +``` +# service --status-all | grep running +``` + +``` +crond (pid 535) is running... +httpd (pid 627) is running... +mysqld (pid 911) is running... +rndc: neither /etc/rndc.conf nor /etc/rndc.key was found +rsyslogd (pid 449) is running... +saslauthd (pid 492) is running... +sendmail (pid 509) is running... +sm-client (pid 519) is running... +openssh-daemon (pid 478) is running... +xinetd (pid 485) is running... +``` + +运行以下命令以查看指定服务的状态: + +``` +# service --status-all | grep httpd +httpd (pid 627) is running... +``` + +或者,使用以下命令也可以查看指定服务的状态: + +``` +# service httpd status +httpd (pid 627) is running... +``` + +使用以下命令查看系统启动时哪些服务会被启用: + +``` +# chkconfig --list +``` + +``` +crond 0:off 1:off 2:on 3:on 4:on 5:on 6:off +htcacheclean 0:off 1:off 2:off 3:off 4:off 5:off 6:off +httpd 0:off 1:off 2:off 3:on 4:off 5:off 6:off +ip6tables 0:off 1:off 2:on 3:off 4:on 5:on 6:off +iptables 0:off 1:off 2:on 3:on 4:on 5:on 6:off +modules_dep 0:off 1:off 2:on 3:on 4:on 5:on 6:off +mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off +named 0:off 1:off 2:off 3:off 4:off 5:off 6:off +netconsole 0:off 1:off 2:off 3:off 4:off 5:off 6:off +netfs 0:off 1:off 2:off 3:off 4:on 5:on 6:off +network 0:off 1:off 2:on 3:on 4:on 5:on 6:off +nmb 0:off 1:off 2:off 3:off 4:off 5:off 6:off +nscd 0:off 1:off 2:off 3:off 4:off 5:off 6:off +portreserve 0:off 1:off 2:on 3:off 4:on 5:on 6:off +quota_nld 0:off 1:off 2:off 3:off 4:off 5:off 6:off +rdisc 0:off 1:off 2:off 3:off 4:off 5:off 6:off +restorecond 0:off 1:off 2:off 3:off 4:off 5:off 6:off +rpcbind 0:off 1:off 2:on 3:off 4:on 5:on 6:off +rsyslog 0:off 1:off 2:on 3:on 4:on 5:on 6:off +saslauthd 0:off 1:off 2:off 3:on 4:off 5:off 6:off +sendmail 0:off 1:off 2:on 3:on 4:on 5:on 6:off +smb 0:off 1:off 2:off 3:off 4:off 5:off 6:off +snmpd 0:off 1:off 2:off 3:off 4:off 5:off 6:off +snmptrapd 0:off 1:off 2:off 3:off 4:off 5:off 6:off +sshd 0:off 1:off 2:on 3:on 4:on 5:on 6:off +udev-post 0:off 1:on 2:on 3:off 4:on 5:on 6:off +winbind 0:off 1:off 2:off 3:off 4:off 5:off 6:off +xinetd 0:off 1:off 2:off 3:on 4:on 5:on 6:off + +xinetd based services: + chargen-dgram: off + chargen-stream: off + daytime-dgram: off + daytime-stream: off + discard-dgram: off + discard-stream: off + echo-dgram: off + echo-stream: off + finger: off + ntalk: off + rsync: off + talk: off + tcpmux-server: off + time-dgram: off + time-stream: off +``` + +### 方法二:如何在 System V(SysV)系统中查看运行的服务 + +另外一种在 Linux 系统上列出运行的服务的方法是使用 initctl 命令: + +``` +# initctl list +rc stop/waiting +tty (/dev/tty3) start/running, process 1740 +tty (/dev/tty2) start/running, process 1738 +tty (/dev/tty1) start/running, process 1736 +tty (/dev/tty6) start/running, process 1746 +tty (/dev/tty5) start/running, process 1744 +tty (/dev/tty4) start/running, process 1742 +plymouth-shutdown stop/waiting +control-alt-delete stop/waiting +rcS-emergency stop/waiting +readahead-collector stop/waiting +kexec-disable stop/waiting +quit-plymouth stop/waiting +rcS stop/waiting +prefdm stop/waiting +init-system-dbus stop/waiting +ck-log-system-restart stop/waiting +readahead stop/waiting +ck-log-system-start stop/waiting +splash-manager stop/waiting +start-ttys stop/waiting +readahead-disable-services stop/waiting +ck-log-system-stop stop/waiting +rcS-sulogin stop/waiting +serial stop/waiting +``` + +### 方法三:如何在 systemd 系统中查看运行的服务 + +以下命令帮助我们列出 systemd 系统中所有服务: + +``` +# systemctl + UNIT LOAD ACTIVE SUB DESCRIPTION + sys-devices-virtual-block-loop0.device loaded active plugged /sys/devices/virtual/block/loop0 + sys-devices-virtual-block-loop1.device loaded active plugged /sys/devices/virtual/block/loop1 + sys-devices-virtual-block-loop2.device loaded active plugged /sys/devices/virtual/block/loop2 + sys-devices-virtual-block-loop3.device loaded active plugged /sys/devices/virtual/block/loop3 + sys-devices-virtual-block-loop4.device loaded active plugged /sys/devices/virtual/block/loop4 + sys-devices-virtual-misc-rfkill.device loaded active plugged /sys/devices/virtual/misc/rfkill + sys-devices-virtual-tty-ttyprintk.device loaded active plugged /sys/devices/virtual/tty/ttyprintk + sys-module-fuse.device loaded active plugged /sys/module/fuse + sys-subsystem-net-devices-enp0s3.device loaded active plugged 82540EM Gigabit Ethernet Controller (PRO/1000 MT Desktop Adapter) + -.mount loaded active mounted Root Mount + dev-hugepages.mount loaded active mounted Huge Pages File System + dev-mqueue.mount loaded active mounted POSIX Message Queue File System + run-user-1000-gvfs.mount loaded active mounted /run/user/1000/gvfs + run-user-1000.mount loaded active mounted /run/user/1000 + snap-core-3887.mount loaded active mounted Mount unit for core + snap-core-4017.mount loaded active mounted Mount unit for core + snap-core-4110.mount loaded active mounted Mount unit for core + snap-gping-13.mount loaded active mounted Mount unit for gping + snap-termius\x2dapp-8.mount loaded active mounted Mount unit for termius-app + sys-fs-fuse-connections.mount loaded active mounted FUSE Control File System + sys-kernel-debug.mount loaded active mounted Debug File System + acpid.path loaded active running ACPI Events Check + cups.path loaded active running CUPS Scheduler + systemd-ask-password-plymouth.path loaded active waiting Forward Password Requests to Plymouth Directory Watch + systemd-ask-password-wall.path loaded active waiting Forward Password Requests to Wall Directory Watch + init.scope loaded active running System and Service Manager + session-c2.scope loaded active running Session c2 of user magi + accounts-daemon.service loaded active running Accounts Service + acpid.service loaded active running ACPI event daemon + anacron.service loaded active running Run anacron jobs + apache2.service loaded active running The Apache HTTP Server + apparmor.service loaded active exited AppArmor initialization + apport.service loaded active exited LSB: automatic crash report generation + aptik-battery-monitor.service loaded active running LSB: start/stop the aptik battery monitor daemon + atop.service loaded active running Atop advanced performance monitor + atopacct.service loaded active running Atop process accounting daemon + avahi-daemon.service loaded active running Avahi mDNS/DNS-SD Stack + colord.service loaded active running Manage, Install and Generate Color Profiles + console-setup.service loaded active exited Set console font and keymap + cron.service loaded active running Regular background program processing daemon + cups-browsed.service loaded active running Make remote CUPS printers available locally + cups.service loaded active running CUPS Scheduler + dbus.service loaded active running D-Bus System Message Bus + postfix.service loaded active exited Postfix Mail Transport Agent +``` + * `UNIT` 相应的 systemd 单元名称 + * `LOAD` 相应的单元是否被加载到内存中 + * `ACTIVE` 该单元是否处于活动状态 + * `SUB` 该单元是否处于运行状态(LCTT 译注:是较于 ACTIVE 更加详细的状态描述,不同的单元类型有不同的状态。) + * `DESCRIPTION` 关于该单元的简短描述 + +以下选项可根据类型列出单元: + +``` +# systemctl list-units --type service + UNIT LOAD ACTIVE SUB DESCRIPTION + accounts-daemon.service loaded active running Accounts Service + acpid.service loaded active running ACPI event daemon + anacron.service loaded active running Run anacron jobs + apache2.service loaded active running The Apache HTTP Server + apparmor.service loaded active exited AppArmor initialization + apport.service loaded active exited LSB: automatic crash report generation + aptik-battery-monitor.service loaded active running LSB: start/stop the aptik battery monitor daemon + atop.service loaded active running Atop advanced performance monitor + atopacct.service loaded active running Atop process accounting daemon + avahi-daemon.service loaded active running Avahi mDNS/DNS-SD Stack + colord.service loaded active running Manage, Install and Generate Color Profiles + console-setup.service loaded active exited Set console font and keymap + cron.service loaded active running Regular background program processing daemon + cups-browsed.service loaded active running Make remote CUPS printers available locally + cups.service loaded active running CUPS Scheduler + dbus.service loaded active running D-Bus System Message Bus + fwupd.service loaded active running Firmware update daemon + getty@tty1.service loaded active running Getty on tty1 + grub-common.service loaded active exited LSB: Record successful boot for GRUB + irqbalance.service loaded active running LSB: daemon to balance interrupts for SMP systems + keyboard-setup.service loaded active exited Set the console keyboard layout + kmod-static-nodes.service loaded active exited Create list of required static device nodes for the current kernel +``` + +以下选项可帮助您根据状态列出单位,输出与前例类似但更直截了当: + +``` +# systemctl list-unit-files --type service + +UNIT FILE STATE +accounts-daemon.service enabled +acpid.service disabled +alsa-restore.service static +alsa-state.service static +alsa-utils.service masked +anacron-resume.service enabled +anacron.service enabled +apache-htcacheclean.service disabled +apache-htcacheclean@.service disabled +apache2.service enabled +apache2@.service disabled +apparmor.service enabled +apport-forward@.service static +apport.service generated +apt-daily-upgrade.service static +apt-daily.service static +aptik-battery-monitor.service generated +atop.service enabled +atopacct.service enabled +autovt@.service enabled +avahi-daemon.service enabled +bluetooth.service enabled +``` + +运行以下命令以查看指定服务的状态: + +``` +# systemctl | grep apache2 + apache2.service loaded active running The Apache HTTP Server +``` + +或者,使用以下命令也可查看指定服务的状态: + +``` +# systemctl status apache2 +● apache2.service - The Apache HTTP Server + Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled) + Drop-In: /lib/systemd/system/apache2.service.d + └─apache2-systemd.conf + Active: active (running) since Tue 2018-03-06 12:34:09 IST; 8min ago + Process: 2786 ExecReload=/usr/sbin/apachectl graceful (code=exited, status=0/SUCCESS) + Main PID: 1171 (apache2) + Tasks: 55 (limit: 4915) + CGroup: /system.slice/apache2.service + ├─1171 /usr/sbin/apache2 -k start + ├─2790 /usr/sbin/apache2 -k start + └─2791 /usr/sbin/apache2 -k start + +Mar 06 12:34:08 magi-VirtualBox systemd[1]: Starting The Apache HTTP Server... +Mar 06 12:34:09 magi-VirtualBox apachectl[1089]: AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 10.0.2.15. Set the 'ServerName' directive globally to suppre +Mar 06 12:34:09 magi-VirtualBox systemd[1]: Started The Apache HTTP Server. +Mar 06 12:39:10 magi-VirtualBox systemd[1]: Reloading The Apache HTTP Server. +Mar 06 12:39:10 magi-VirtualBox apachectl[2786]: AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using fe80::7929:4ed1:279f:4d65. Set the 'ServerName' directive gl +Mar 06 12:39:10 magi-VirtualBox systemd[1]: Reloaded The Apache HTTP Server. +``` + +执行以下命令,只查看正在运行的服务: +``` +# systemctl | grep running + acpid.path loaded active running ACPI Events Check + cups.path loaded active running CUPS Scheduler + init.scope loaded active running System and Service Manager + session-c2.scope loaded active running Session c2 of user magi + accounts-daemon.service loaded active running Accounts Service + acpid.service loaded active running ACPI event daemon + apache2.service loaded active running The Apache HTTP Server + aptik-battery-monitor.service loaded active running LSB: start/stop the aptik battery monitor daemon + atop.service loaded active running Atop advanced performance monitor + atopacct.service loaded active running Atop process accounting daemon + avahi-daemon.service loaded active running Avahi mDNS/DNS-SD Stack + colord.service loaded active running Manage, Install and Generate Color Profiles + cron.service loaded active running Regular background program processing daemon + cups-browsed.service loaded active running Make remote CUPS printers available locally + cups.service loaded active running CUPS Scheduler + dbus.service loaded active running D-Bus System Message Bus + fwupd.service loaded active running Firmware update daemon + getty@tty1.service loaded active running Getty on tty1 + irqbalance.service loaded active running LSB: daemon to balance interrupts for SMP systems + lightdm.service loaded active running Light Display Manager + ModemManager.service loaded active running Modem Manager + NetworkManager.service loaded active running Network Manager + polkit.service loaded active running Authorization Manager +``` + +使用以下命令查看系统启动时会被启用的服务列表: + +``` +# systemctl list-unit-files | grep enabled +acpid.path enabled +cups.path enabled +accounts-daemon.service enabled +anacron-resume.service enabled +anacron.service enabled +apache2.service enabled +apparmor.service enabled +atop.service enabled +atopacct.service enabled +autovt@.service enabled +avahi-daemon.service enabled +bluetooth.service enabled +console-setup.service enabled +cron.service enabled +cups-browsed.service enabled +cups.service enabled +display-manager.service enabled +dns-clean.service enabled +friendly-recovery.service enabled +getty@.service enabled +gpu-manager.service enabled +keyboard-setup.service enabled +lightdm.service enabled +ModemManager.service enabled +network-manager.service enabled +networking.service enabled +NetworkManager-dispatcher.service enabled +NetworkManager-wait-online.service enabled +NetworkManager.service enabled +``` + +`systemd-cgtop` 按资源使用情况(任务、CPU、内存、输入和输出)列出控制组: + +``` +# systemd-cgtop + +Control Group Tasks %CPU Memory Input/s Output/s +/ - - 1.5G - - +/init.scope 1 - - - - +/system.slice 153 - - - - +/system.slice/ModemManager.service 3 - - - - +/system.slice/NetworkManager.service 4 - - - - +/system.slice/accounts-daemon.service 3 - - - - +/system.slice/acpid.service 1 - - - - +/system.slice/apache2.service 55 - - - - +/system.slice/aptik-battery-monitor.service 1 - - - - +/system.slice/atop.service 1 - - - - +/system.slice/atopacct.service 1 - - - - +/system.slice/avahi-daemon.service 2 - - - - +/system.slice/colord.service 3 - - - - +/system.slice/cron.service 1 - - - - +/system.slice/cups-browsed.service 3 - - - - +/system.slice/cups.service 2 - - - - +/system.slice/dbus.service 6 - - - - +/system.slice/fwupd.service 5 - - - - +/system.slice/irqbalance.service 1 - - - - +/system.slice/lightdm.service 7 - - - - +/system.slice/polkit.service 3 - - - - +/system.slice/repowerd.service 14 - - - - +/system.slice/rsyslog.service 4 - - - - +/system.slice/rtkit-daemon.service 3 - - - - +/system.slice/snapd.service 8 - - - - +/system.slice/system-getty.slice 1 - - - - +``` + +同时,我们可以使用 `pstree` 命令(输出来自 SysVinit 系统)查看正在运行的服务: + +``` +# pstree +init-+-crond + |-httpd---2*[httpd] + |-kthreadd/99149---khelper/99149 + |-2*[mingetty] + |-mysqld_safe---mysqld---9*[{mysqld}] + |-rsyslogd---3*[{rsyslogd}] + |-saslauthd---saslauthd + |-2*[sendmail] + |-sshd---sshd---bash---pstree + |-udevd + `-xinetd +``` + +我们还可以使用 `pstree` 命令(输出来自 systemd 系统)查看正在运行的服务: + +``` +# pstree +systemd─┬─ModemManager─┬─{gdbus} + │ └─{gmain} + ├─NetworkManager─┬─dhclient + │ ├─{gdbus} + │ └─{gmain} + ├─accounts-daemon─┬─{gdbus} + │ └─{gmain} + ├─acpid + ├─agetty + ├─anacron + ├─apache2───2*[apache2───26*[{apache2}]] + ├─aptd───{gmain} + ├─aptik-battery-m + ├─atop + ├─atopacctd + ├─avahi-daemon───avahi-daemon + ├─colord─┬─{gdbus} + │ └─{gmain} + ├─cron + ├─cups-browsed─┬─{gdbus} + │ └─{gmain} + ├─cupsd + ├─dbus-daemon + ├─fwupd─┬─{GUsbEventThread} + │ ├─{fwupd} + │ ├─{gdbus} + │ └─{gmain} + ├─gnome-keyring-d─┬─{gdbus} + │ ├─{gmain} + │ └─{timer} +``` + +### 方法四:如何使用 chkservice 在 systemd 系统中查看正在运行的服务 + +`chkservice` 是一个管理系统单元的终端工具,需要超级用户权限。 + +``` +# chkservice +``` + +![][1] + +要查看帮助页面,请按下 `?` ,它将显示管理 systemd 服务的可用选项。 + +![][2] + +-------------------------------------------------------------------------------- + +via: https://www.2daygeek.com/how-to-check-all-running-services-in-linux/ + +作者:[Magesh Maruthamuthu][a] +译者:[jessie-pang](https://github.com/jessie-pang) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.2daygeek.com/author/magesh/ +[1]:https://www.2daygeek.com/wp-content/uploads/2018/03/chkservice-1.png +[2]:https://www.2daygeek.com/wp-content/uploads/2018/03/chkservice-2.png \ No newline at end of file diff --git a/translated/tech/20180306 How to apply Machine Learning to IoT using Android Things and TensorFlow.md b/published/201808/20180306 How to apply Machine Learning to IoT using Android Things and TensorFlow.md similarity index 79% rename from translated/tech/20180306 How to apply Machine Learning to IoT using Android Things and TensorFlow.md rename to published/201808/20180306 How to apply Machine Learning to IoT using Android Things and TensorFlow.md index 6905e64f39..7b3e113546 100644 --- a/translated/tech/20180306 How to apply Machine Learning to IoT using Android Things and TensorFlow.md +++ b/published/201808/20180306 How to apply Machine Learning to IoT using Android Things and TensorFlow.md @@ -1,30 +1,32 @@ 如何使用 Android Things 和 TensorFlow 在物联网上应用机器学习 -============================================================  +============================= + +![](https://www.survivingwithandroid.com/wp-content/uploads/2018/03/Apply_Machine_Learning_to_IoT.png) + +> 探索如何将 Android Things 与 Tensorflow 集成起来,以及如何应用机器学习到物联网系统上。学习如何在装有 Android Things 的树莓派上使用 Tensorflow 进行图片分类。 这个项目探索了如何将机器学习应用到物联网上。具体来说,物联网平台我们将使用 **Android Things**,而机器学习引擎我们将使用 **Google TensorFlow**。 -![Machine Learning with Android Things](https://www.survivingwithandroid.com/wp-content/uploads/2018/03/machine_learning_android_things.png) +现如今,Android Things 处于名为 Android Things 1.0 的稳定版本,已经可以用在生产系统中了。如你可能已经知道的,树莓派是一个可以支持 Android Things 1.0 做开发和原型设计的平台。本教程将使用 Android Things 1.0 和树莓派,当然,你可以无需修改代码就能换到其它所支持的平台上。这个教程是关于如何将机器学习应用到物联网的,这个物联网平台就是 Android Things Raspberry Pi。 -现如今,机器学习是物联网上使用的最热门的主题之一。给机器学习的最简单的定义,可能就是 [维基百科上的定义][13]:机器学习是计算机科学中,让计算机不需要显式编程就能去“学习”(即,逐步提升在特定任务上的性能)使用数据的一个领域。 +物联网上的机器学习是最热门的话题之一。要给机器学习一个最简单的定义,可能就是 [维基百科上的定义][13]: -换句话说就是,经过训练之后,那怕是它没有针对它们进行特定的编程,这个系统也能够预测结果。另一方面,我们都知道物联网和联网设备的概念。其中一个前景看好的领域就是如何在物联网上应用机器学习,构建专业的系统,这样就能够去开发一个能够“学习”的系统。此外,还可以使用这些知识去控制和管理物理对象。 +> 机器学习是计算机科学中,让计算机不需要显式编程就能去“学习”(即,逐步提升在特定任务上的性能)使用数据的一个领域。 -这里有几个应用机器学习和物联网产生重要价值的领域,以下仅提到了几个感兴趣的领域,它们是: +换句话说就是,经过训练之后,那怕是它没有针对它们进行特定的编程,这个系统也能够预测结果。另一方面,我们都知道物联网和联网设备的概念。其中前景最看好的领域之一就是如何在物联网上应用机器学习,构建专家系统,这样就能够去开发一个能够“学习”的系统。此外,还可以使用这些知识去控制和管理物理对象。在深入了解 Android Things 的细节之前,你应该先将其安装在你的设备上。如果你是第一次使用 Android Things,你可以阅读一下这篇[如何在你的设备上安装 Android Things][14] 的教程。 + +这里有几个应用机器学习和物联网产生重要价值的领域,以下仅提到了几个有趣的领域,它们是: * 在工业物联网(IIoT)中的预见性维护 - * 消费物联网中,机器学习可以让设备更智能,它通过调整使设备更适应我们的习惯 -在本教程中,我们希望去探索如何使用 Android Things 和 TensorFlow 在物联网上应用机器学习。这个 Adnroid Things 物联网项目的基本想法是,探索如何去*构建一个能够识别前方道路上基本形状(比如箭头)的无人驾驶汽车*。我们已经介绍了 [如何使用 Android Things 去构建一个无人驾驶汽车][5],因此,在开始这个项目之前,我们建议你去阅读那个教程。 +在本教程中,我们希望去探索如何使用 Android Things 和 TensorFlow 在物联网上应用机器学习。这个 Adnroid Things 物联网项目的基本想法是,探索如何去*构建一个能够识别前方道路上基本形状(比如箭头)并控制其道路方向的无人驾驶汽车*。我们已经介绍了 [如何使用 Android Things 去构建一个无人驾驶汽车][5],因此,在开始这个项目之前,我们建议你去阅读那个教程。 这个机器学习和物联网项目包含如下的主题: * 如何使用 Docker 配置 TensorFlow 环境 - * 如何训练 TensorFlow 系统 - * 如何使用 Android Things 去集成 TensorFlow - * 如何使用 TensorFlow 的成果去控制无人驾驶汽车 这个项目起源于 [Android Things TensorFlow 图像分类器][6]。 @@ -33,59 +35,55 @@ ### 如何使用 Tensorflow 图像识别 -在开始之前,需要安装和配置 TensorFlow 环境。我不是机器学习方面的专家,因此,我需要快速找到并且准备去使用一些东西,因此,我们可以构建 TensorFlow 图像识别器。为此,我们使用 Docker 去运行一个 TensorFlow 镜像。以下是操作步骤: +在开始之前,需要安装和配置 TensorFlow 环境。我不是机器学习方面的专家,因此,我需要找到一些快速而能用的东西,以便我们可以构建 TensorFlow 图像识别器。为此,我们使用 Docker 去运行一个 TensorFlow 镜像。以下是操作步骤: -1. 克隆 TensorFlow 仓库: - ``` - git clone https://github.com/tensorflow/tensorflow.git - cd /tensorflow - git checkout v1.5.0 - ``` +1、 克隆 TensorFlow 仓库: -2. 创建一个目录(`/tf-data`),它将用于保存这个项目中使用的所有文件。 +``` +git clone https://github.com/tensorflow/tensorflow.git +cd /tensorflow +git checkout v1.5.0 +``` -3. 运行 Docker: - ``` - docker run -it \ - --volume /tf-data:/tf-data \ - --volume /tensorflow:/tensorflow \ - --workdir /tensorflow tensorflow/tensorflow:1.5.0 bash - ``` +2、 创建一个目录(`/tf-data`),它将用于保存这个项目中使用的所有文件。 - 使用这个命令,我们运行一个交互式 TensorFlow 环境,可以在使用项目期间挂载一些目录。 +3、 运行 Docker: + +``` +docker run -it \ +--volume /tf-data:/tf-data \ +--volume /tensorflow:/tensorflow \ +--workdir /tensorflow tensorflow/tensorflow:1.5.0 bash +``` + +使用这个命令,我们运行一个交互式 TensorFlow 环境,可以挂载一些在使用项目期间使用的目录。 ### 如何训练 TensorFlow 去识别图像 在 Android Things 系统能够识别图像之前,我们需要去训练 TensorFlow 引擎,以使它能够构建它的模型。为此,我们需要去收集一些图像。正如前面所言,我们需要使用箭头来控制 Android Things 无人驾驶汽车,因此,我们至少要收集四种类型的箭头: * 向上的箭头 - * 向下的箭头 - * 向左的箭头 - * 向右的箭头 为训练这个系统,需要使用这四类不同的图像去创建一个“知识库”。在 `/tf-data` 目录下创建一个名为 `images` 的目录,然后在它下面创建如下名字的四个子目录: -* up-arrow - -* down-arrow - -* left-arrow - -* right-arrow +* `up-arrow` +* `down-arrow` +* `left-arrow` +* `right-arrow` 现在,我们去找图片。我使用的是 Google 图片搜索,你也可以使用其它的方法。为了简化图片下载过程,你可以安装一个 Chrome 下载插件,这样你只需要点击就可以下载选定的图片。别忘了多下载一些图片,这样训练效果更好,当然,这样创建模型的时间也会相应增加。 **扩展阅读** -[如何使用 API 去集成 Android Things][2] -[如何与 Firebase 一起使用 Android Things][3] + +- [如何使用 API 去集成 Android Things][2] +- [如何与 Firebase 一起使用 Android Things][3] 打开浏览器,开始去查找四种箭头的图片: ![TensorFlow image classifier](https://www.survivingwithandroid.com/wp-content/uploads/2018/03/TensorFlow-image-classifier.png) -[Save][7] 每个类别我下载了 80 张图片。不用管图片文件的扩展名。 @@ -102,9 +100,8 @@ python /tensorflow/examples/image_retraining/retrain.py \ 这个过程你需要耐心等待,它需要花费很长时间。结束之后,你将在 `/tf-data` 目录下发现如下的两个文件: -1. retrained_graph.pb - -2. retrained_labels.txt +1. `retrained_graph.pb` +2. `retrained_labels.txt` 第一个文件包含了 TensorFlow 训练过程产生的结果模型,而第二个文件包含了我们的四个图片类相关的标签。 @@ -139,7 +136,6 @@ python /tensorflow/python/tools/optimize_for_inference.py \ TensorFlow 的数据模型准备就绪之后,我们继续下一步:如何将 Android Things 与 TensorFlow 集成到一起。为此,我们将这个任务分为两步来完成: 1. 硬件部分,我们将把电机和其它部件连接到 Android Things 开发板上 - 2. 实现这个应用程序 ### Android Things 示意图 @@ -147,13 +143,9 @@ TensorFlow 的数据模型准备就绪之后,我们继续下一步:如何将 在深入到如何连接外围部件之前,先列出在这个 Android Things 项目中使用到的组件清单: 1. Android Things 开发板(树莓派 3) - 2. 树莓派摄像头 - 3. 一个 LED 灯 - 4. LN298N 双 H 桥电机驱动模块(连接控制电机) - 5. 一个带两个轮子的无人驾驶汽车底盘 我不再重复 [如何使用 Android Things 去控制电机][9] 了,因为在以前的文章中已经讲过了。 @@ -161,12 +153,10 @@ TensorFlow 的数据模型准备就绪之后,我们继续下一步:如何将 下面是示意图: ![Integrating Android Things with IoT](https://www.survivingwithandroid.com/wp-content/uploads/2018/03/tensor_bb.png) -[Save][10] 上图中没有展示摄像头。最终成果如下图: ![Integrating Android Things with TensorFlow](https://www.survivingwithandroid.com/wp-content/uploads/2018/03/android_things_with_tensorflow-min.jpg) -[Save][11] ### 使用 TensorFlow 实现 Android Things 应用程序 @@ -175,11 +165,8 @@ TensorFlow 的数据模型准备就绪之后,我们继续下一步:如何将 这个 Android Things 应用程序与原始的应用程序是不一样的,因为: 1. 它不使用按钮去开启摄像头图像捕获 - 2. 它使用了不同的模型 - 3. 它使用一个闪烁的 LED 灯来提示,摄像头将在 LED 停止闪烁后拍照 - 4. 当 TensorFlow 检测到图像时(箭头)它将控制电机。此外,在第 3 步的循环开始之前,它将打开电机 5 秒钟。 为了让 LED 闪烁,使用如下的代码: @@ -264,7 +251,7 @@ public void onImageAvailable(ImageReader reader) { 在这个方法中,当 TensorFlow 返回捕获的图片匹配到的可能的标签之后,应用程序将比较这个结果与可能的方向,并因此来控制电机。 -最后,将去使用前面创建的模型了。拷贝 _assets_ 文件夹下的 `opt_graph.pb` 和 `reatrained_labels.txt` 去替换现在的文件。 +最后,将去使用前面创建的模型了。拷贝 `assets` 文件夹下的 `opt_graph.pb` 和 `reatrained_labels.txt` 去替换现在的文件。 打开 `Helper.java` 并修改如下的行: @@ -289,9 +276,9 @@ public static final String OUTPUT_NAME = "final_result"; via: https://www.survivingwithandroid.com/2018/03/apply-machine-learning-iot-using-android-things-tensorflow.html -作者:[Francesco Azzola ][a] +作者:[Francesco Azzola][a] 译者:[qhwdw](https://github.com/qhwdw) -校对:[校对者ID](https://github.com/校对者ID) +校对:[wxy](https://github.com/wxy) 本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 @@ -309,3 +296,4 @@ via: https://www.survivingwithandroid.com/2018/03/apply-machine-learning-iot-usi [11]:http://pinterest.com/pin/create/bookmarklet/?media=data:image/gif;base64,R0lGODdhAQABAPAAAP///wAAACwAAAAAAQABAEACAkQBADs=&url=https://www.survivingwithandroid.com/2018/03/apply-machine-learning-iot-using-android-things-tensorflow.html&is_video=false&description=Integrating%20Android%20Things%20with%20TensorFlow [12]:https://github.com/androidthings/sample-tensorflow-imageclassifier [13]:https://en.wikipedia.org/wiki/Machine_learning +[14]:https://www.survivingwithandroid.com/2017/01/android-things-android-internet-of-things.html \ No newline at end of file diff --git a/published/201808/20180306 Try, learn, modify- The new IT leader-s code.md b/published/201808/20180306 Try, learn, modify- The new IT leader-s code.md new file mode 100644 index 0000000000..7ecf178a6f --- /dev/null +++ b/published/201808/20180306 Try, learn, modify- The new IT leader-s code.md @@ -0,0 +1,58 @@ +尝试、学习、修改:新 IT 领导者的代码 +===== + +> 随着创新步伐的增加, 长期规划变得越来越困难。让我们重新思考一下我们对变化的反应方式。 + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/ship_wheel_gear_devops_kubernetes.png?itok=xm4a74Kv) + +几乎每一天,新的技术发展都可能会动摇那些甚至最复杂、最完善的商业计划。组织经常发现自己需要不断努力适应新的环境,这导致了他们对未来规划的转变。 + +根据 CompTIA 2017 年的[研究][1],目前只有 34% 的公司正在制定超过 12 个月的 IT 架构计划。从长期计划转变的一个原因是:商业环境变化如此之快,以至于几乎不可能进一步规划未来。[CIO.com 说道][1],“如果你的公司正视图制定一项将持续五到十年的计划,那就忘了它。” + +我听过来自世界各地无数客户和合作伙伴的类似声明:技术创新正以一种前所未有的速度发生着。 + +其结果是长期规划已不复存在。如果我们要在这个新世界取得成功,我们需要以不同的方式思考我们运营组织的方式。 + +### 计划是怎么死的 + +正如我在《开放式组织The Open Organization》中写的那样,传统经营组织针对工业经济进行了优化。他们采用等级结构和严格规定的流程,以实现地位竞争优势。要取得成功,他们必须确定他们想要实现的战略地位。然后,他们必须制定并规划实现目标的计划,并以最有效的方式执行这些计划,通过协调活动和推动合规性。 + +管理层的职责是优化这一过程:计划、规定、执行。包括:让我们想象一个有竞争力的优势地位;让我们来配置组织以最终达成目标;然后让我们通过确保组织的所有方面都遵守规定来推动执行。这就是我所说的“机械管理”,对于不同时期来说它都是一个出色的解决方案。 + +在当今动荡不定的世界中,我们预测和定义战略位置的能力正在下降,因为变化的速度,新变量的引入速度正在加速。传统的、长期的、战略性规划和执行不像以前那么有效。 + +如果长期规划变得如此困难,那么规定必要的行为就更具有挑战性。并且衡量对计划的合规性几乎是不可能的。 + +这一切都极大地影响了人们的工作方式。与过去传统经营组织中的工人不同,他们为自己能够重复行动而感到自豪,几乎没有变化和舒适的确定性 —— 今天的工人在充满模糊性的环境中运作。他们的工作需要更大的创造力、直觉和批判性判断 —— 更多的需要背离过去的“常规”,以适应当今的新情况。 + +以这种新方式工作对于价值创造变得更加重要。我们的管理系统必须专注于构建结构,系统和流程,以帮助创建积极主动的工人,他们能够以快速和敏捷的方式进行创新和行动。 + +我们需要提出一个不同的解决方案来优化组织,以适应不同的经济时代,从自下而上而不是自上而下开始。我们需要替换过去的三步骤 —— 计划、规定、执行,以一种更适应当今动荡天气的方法来取得成功 —— 尝试、学习、修改。 + +### 尝试、学习、修改 + +因为环境变化如此之快,而且几乎没有任何预警,并且因为我们需要采取的步骤不再提前计划,我们需要培养鼓励创造性尝试和错误的环境,而不是坚持对五年计划的忠诚。以下是以这种方式开始工作的一些暗示: + + * **更短的计划周期(尝试)。** 管理者需要考虑的是他们可以快速尝试的短期实验,而不是在长期战略方向上苦恼。他们应该寻求方法来帮助他们的团队承担计算风险,并利用他们掌握的数据来对最有利的路径做出最好的猜测。他们可以通过降低开销和让团队自由快速尝试新方法来做到这一点。 + * **更高的失败容忍度(学习)。** 更多的实验频率意味着更大的失败机会。与传统组织相比,富有创造力和有弹性的组织[对失败的容忍度要高得多][2]。管理者应将失败视为学习的机会,在他们的团队正在运行的测试中收集反馈的时刻。 + * **更具适应性的结构(修改)。** 能够轻松修改组织结构和战略方向,以及在条件需要时愿意这样做,是确保组织能够根据快速变化的环境条件发展的关键。管理者不能再拘泥于任何想法,因为这个想法证明自己对实现短期目标很有用。 + +如果长期计划已经消亡,那么就可以进行长期的短期实验。尝试,学习和修改,这是在不确定时期前进的最佳途径。 + +[订阅我们的每周实事通讯][3]以了解有关开源组织的更多信息。 + + +-------------------------------------------------------------------------------- + +via: https://opensource.com/open-organization/18/3/try-learn-modify + +作者:[Jim Whitehurst][a] +译者:[MjSeven](https://github.com/MjSeven) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://opensource.com/users/remyd +[1]:https://www.cio.com/article/3246027/enterprise-architecture/the-death-of-long-term-it-planning.html?upd=1515780110970 +[2]:https://opensource.com/open-organization/16/12/building-culture-innovation-your-organization +[3]:https://opensource.com/open-organization/resources/newsletter diff --git a/published/201808/20180426 How To Check System Hardware Manufacturer, Model And Serial Number In Linux.md b/published/201808/20180426 How To Check System Hardware Manufacturer, Model And Serial Number In Linux.md new file mode 100644 index 0000000000..5bf82ce3ac --- /dev/null +++ b/published/201808/20180426 How To Check System Hardware Manufacturer, Model And Serial Number In Linux.md @@ -0,0 +1,154 @@ +如何在 Linux 中查看系统硬件制造商、型号和序列号 +====== + +对于 Linux 图形界面用户和 Windows 用户来说获取系统硬件信息都不算问题,但是对命令行用户来说想要获取这些细节时有点儿麻烦。 + +甚至我们中的大多数都不知道获取这些信息最好的命令是什么。Linux 中有许多可用的工具集来获取诸如制造商、型号和序列号等硬件信息。 + +在这里我尝试写下获取这些细节的可能的方式,你可以挑选一种最好用的。 + +你必须知道所有这些信息,因为当你向硬件制造商提交任何硬件问题时,你会需要它们。 + +这可以通过 6 种方法来实现,下面我来演示一下怎么做。 + +### 方法一:使用 dmidecode 命令 + +`dmidecode` 是一个读取电脑 DMI(桌面管理接口Desktop Management Interface)表内容并且以人类可读的格式显示系统硬件信息的工具。(也有人说是读取 SMBIOS —— 系统管理 BIOSSystem Management BIOS) + +这个表包含系统硬件组件的说明,也包含如序列号、制造商、发布日期以及 BIOS 修订版本号等其它有用的信息。 + +DMI 表不仅描述了当前的系统构成,还可以报告可能的升级信息(比如可以支持的最快的 CPU 或者最大的内存容量)。 + +这将有助于分析你的硬件兼容性,比如是否支持最新版本的程序。 + +``` +# dmidecode -t system + +# dmidecode 2.12 +# SMBIOS entry point at 0x7e7bf000 +SMBIOS 2.7 present. + +Handle 0x0024, DMI type 1, 27 bytes +System Information + Manufacturer: IBM + Product Name: System x2530 M4: -[1214AC1]- + Version: 0B + Serial Number: MK2RL11 + UUID: 762A99BF-6916-450F-80A6-B2E9E78FC9A1 + Wake-up Type: Power Switch + SKU Number: Not Specified + Family: System X + +Handle 0x004B, DMI type 12, 5 bytes +System Configuration Options + Option 1: JP20 pin1-2: TPM PP Disable, pin2-3: TPM PP Enable + +Handle 0x004D, DMI type 32, 20 bytes +System Boot Information + Status: No errors detected +``` + +**推荐阅读:** [Dmidecode –– 获取 Linux 系统硬件信息的简单方式][1] + +### 方法二:使用 inxi 命令 + +`inxi` 是 Linux 上查看硬件信息的一个灵巧的小工具,它提供了大量的选项来获取所有硬件信息,这是我在现有的其它 Linux 工具集里所没见到过的。它是从 locsmif 编写的古老的但至今看来都异常灵活的 `infobash` fork 出来的。 + +`inxi` 是一个可以快速显示系统硬件、CPU、驱动、Xorg、桌面、内核、GCC 版本、进程、内存使用以及大量其它有用信息的脚本,也可以用来做技术支持和调试工具。 + +``` +# inxi -M +Machine: Device: server System: IBM product: N/A v: 0B serial: MK2RL11 + Mobo: IBM model: 00Y8494 serial: 37M17D UEFI: IBM v: -[VVE134MUS-1.50]- date: 08/30/2013 +``` + +**推荐阅读:** [inxi —— 一个很棒的查看 Linux 硬件信息的工具][2] + +### 方法三:使用 lshw 命令 + +`lshw`(指硬件监听器Hardware Lister)是一个小巧灵活的工具,可以生成如内存配置、固件版本、主板配置、CPU 版本和速度、缓存配置、USB、网卡、显卡、多媒体、打印机以及总线速度等机器中各种硬件组件的详细报告。 + +它通过读取 `/proc` 目录下各种文件的内容和 DMI 表来生成硬件信息。 + +`lshw` 必须以超级用户的权限运行来检测完整的硬件信息,否则它只汇报部分信息。`lshw` 里有一个叫做 `class` 的特殊选项,它可以以详细的模式显示特定的硬件信息。 + +``` +# lshw -C system +enal-dbo01t + description: Blade + product: System x2530 M4: -[1214AC1]- + vendor: IBM + version: 0B + serial: MK2RL11 + width: 64 bits + capabilities: smbios-2.7 dmi-2.7 vsyscall32 + configuration: boot=normal chassis=enclosure family=System X uuid=762A99BF-6916-450F-80A6-B2E9E78FC9A1 +``` + +**推荐阅读:** [LSHW (Hardware Lister) –– 获取 Linux 硬件信息的灵巧的小工具][3] + +### 方法四:使用 /sys 文件系统 + +内核在 `/sys` 目录下的文件中公开了一些 DMI 信息。因此,我们可以通过如下方式运行 `grep` 命令来轻易地获取机器类型。 + +``` +# grep "" /sys/class/dmi/id/[pbs]* +``` + +或者,可以使用 `cat` 命令仅打印出特定的详细信息。 + +``` +# cat /sys/class/dmi/id/board_vendor +IBM + +# cat /sys/class/dmi/id/product_name +System x2530 M4: -[1214AC1]- + +# cat /sys/class/dmi/id/product_serial +MK2RL11 + +# cat /sys/class/dmi/id/bios_version +-[VVE134MUS-1.50]- +``` + +### 方法五:使用 dmesg 命令 + +`dmesg` 命令是在 Linux 上 `syslogd` 或 `klogd` 启动前用来记录内核消息(启动阶段的消息)的。它通过读取内核的环形缓冲区来获取数据。在排查问题或只是尝试获取系统硬件信息时,`dmesg` 非常有用。 + +``` +# dmesg | grep -i DMI +DMI: System x2530 M4: -[1214AC1]-/00Y8494, BIOS -[VVE134MUS-1.50]- 08/30/2013 +``` + +### 方法六:使用 hwinfo 命令 + +`hwinfo`(硬件信息hardware information)是另一个很棒的工具,用于检测当前系统存的硬件,并以人类可读的方式显示各种硬件模块的详细信息。 + +它报告关于 CPU、内存、键盘、鼠标、显卡、声卡、存储、网络接口、磁盘、分区、BIOS 以及桥接器等信息。它可以比其它像 `lshw`、`dmidecode` 或 `inxi` 等工具显示更为详细的信息。 + +`hwinfo` 使用 libhd 库 `libhd.so` 来收集系统上的硬件信息。该工具是为 openSuse 特别设计的,后来其它发行版也将它包含在其官方仓库中。 + +``` +# hwinfo | egrep "system.hardware.vendor|system.hardware.product" + system.hardware.vendor = 'IBM' + system.hardware.product = 'System x2530 M4: -[1214AC1]-' +``` + +**推荐阅读:** [hwinfo (Hardware Info) –– 一款灵活的检测 Linux 系统硬件信息的工具][4] + +--- + +via: https://www.2daygeek.com/how-to-check-system-hardware-manufacturer-model-and-serial-number-in-linux/ + +作者:[VINOTH KUMAR][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[icecoobe](https://github.com/icecoobe) +校对:[pityonline](https://github.com/pityonline) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.2daygeek.com/author/vinoth/ +[1]:https://www.2daygeek.com/dmidecode-get-print-display-check-linux-system-hardware-information/ +[2]:https://www.2daygeek.com/inxi-system-hardware-information-on-linux/ +[3]:https://www.2daygeek.com/lshw-find-check-system-hardware-information-details-linux/ +[4]:https://www.2daygeek.com/hwinfo-check-display-detect-system-hardware-information-linux/ diff --git a/sources/tech/20180429 Asynchronous Processing with Go using Kafka and MongoDB.md b/published/201808/20180429 Asynchronous Processing with Go using Kafka and MongoDB.md similarity index 56% rename from sources/tech/20180429 Asynchronous Processing with Go using Kafka and MongoDB.md rename to published/201808/20180429 Asynchronous Processing with Go using Kafka and MongoDB.md index ba57e40be3..9f1ed9ea4c 100644 --- a/sources/tech/20180429 Asynchronous Processing with Go using Kafka and MongoDB.md +++ b/published/201808/20180429 Asynchronous Processing with Go using Kafka and MongoDB.md @@ -1,48 +1,43 @@ -Asynchronous Processing with Go using Kafka and MongoDB +使用 Kafka 和 MongoDB 进行 Go 异步处理 ============================================================ -In my previous blog post ["My First Go Microservice using MongoDB and Docker Multi-Stage Builds"][9], I created a Go microservice sample which exposes a REST http endpoint and saves the data received from an HTTP POST to a MongoDB database. +在我前面的博客文章 “[我的第一个 Go 微服务:使用 MongoDB 和 Docker 多阶段构建][9]” 中,我创建了一个 Go 微服务示例,它发布一个 REST 式的 http 端点,并将从 HTTP POST 中接收到的数据保存到 MongoDB 数据库。 -In this example, I decoupled the saving of data to MongoDB and created another microservice to handle this. I also added Kafka to serve as the messaging layer so the microservices can work on its own concerns asynchronously. +在这个示例中,我将数据的保存和 MongoDB 分离,并创建另一个微服务去处理它。我还添加了 Kafka 为消息层服务,这样微服务就可以异步处理它自己关心的东西了。 -> In case you have time to watch, I recorded a walkthrough of this blog post in the [video below][1] :) +> 如果你有时间去看,我将这个博客文章的整个过程录制到 [这个视频中了][1] :) -Here is the high-level architecture of this simple asynchronous processing example wtih 2 microservices. +下面是这个使用了两个微服务的简单的异步处理示例的上层架构图。 ![rest-kafka-mongo-microservice-draw-io](https://www.melvinvivas.com/content/images/2018/04/rest-kafka-mongo-microservice-draw-io.jpg) -Microservice 1 - is a REST microservice which receives data from a /POST http call to it. After receiving the request, it retrieves the data from the http request and saves it to Kafka. After saving, it responds to the caller with the same data sent via /POST +微服务 1 —— 是一个 REST 式微服务,它从一个 /POST http 调用中接收数据。接收到请求之后,它从 http 请求中检索数据,并将它保存到 Kafka。保存之后,它通过 /POST 发送相同的数据去响应调用者。 -Microservice 2 - is a microservice which subscribes to a topic in Kafka where Microservice 1 saves the data. Once a message is consumed by the microservice, it then saves the data to MongoDB. +微服务 2 —— 是一个订阅了 Kafka 中的一个主题的微服务,微服务 1 的数据保存在该主题。一旦消息被微服务消费之后,它接着保存数据到 MongoDB 中。 -Before you proceed, we need a few things to be able to run these microservices: +在你继续之前,我们需要能够去运行这些微服务的几件东西: -1. [Download Kafka][2] - I used version kafka_2.11-1.1.0 +1. [下载 Kafka][2] —— 我使用的版本是 kafka_2.11-1.1.0 +2. 安装 [librdkafka][3] —— 不幸的是,这个库应该在目标系统中 +3. 安装 [Kafka Go 客户端][4] +4. 运行 MongoDB。你可以去看我的 [以前的文章][5] 中关于这一块的内容,那篇文章中我使用了一个 MongoDB docker 镜像。 -2. Install [librdkafka][3] - Unfortunately, this library should be present in the target system +我们开始吧! -3. Install the [Kafka Go Client by Confluent][4] - -4. Run MongoDB. You can check my [previous blog post][5] about this where I used a MongoDB docker image. - -Let's get rolling! - -Start Kafka first, you need Zookeeper running before you run the Kafka server. Here's how +首先,启动 Kafka,在你运行 Kafka 服务器之前,你需要运行 Zookeeper。下面是示例: ``` $ cd //kafka_2.11-1.1.0 $ bin/zookeeper-server-start.sh config/zookeeper.properties - ``` -Then run Kafka - I am using port 9092 to connect to Kafka. If you need to change the port, just configure it in config/server.properties. If you are just a beginner like me, I suggest to just use default ports for now. +接着运行 Kafka —— 我使用 9092 端口连接到 Kafka。如果你需要改变端口,只需要在 `config/server.properties` 中配置即可。如果你像我一样是个新手,我建议你现在还是使用默认端口。 ``` $ bin/kafka-server-start.sh config/server.properties - ``` -After running Kafka, we need MongoDB. To make it simple, just use this docker-compose.yml. +Kafka 跑起来之后,我们需要 MongoDB。它很简单,只需要使用这个 `docker-compose.yml` 即可。 ``` version: '3' @@ -61,17 +56,15 @@ volumes: networks: network1: - ``` -Run the MongoDB docker container using Docker Compose +使用 Docker Compose 去运行 MongoDB docker 容器。 ``` docker-compose up - ``` -Here is the relevant code of Microservice 1. I just modified my previous example to save to Kafka rather than MongoDB. +这里是微服务 1 的相关代码。我只是修改了我前面的示例去保存到 Kafka 而不是 MongoDB: [rest-to-kafka/rest-kafka-sample.go][10] @@ -133,15 +126,13 @@ func saveJobToKafka(job Job) { }, nil) } } - ``` -Here is the code of Microservice 2. What is important in this code is the consumption from Kafka, the saving part I already discussed in my previous blog post. Here are the important parts of the code which consumes the data from Kafka. +这里是微服务 2 的代码。在这个代码中最重要的东西是从 Kafka 中消费数据,保存部分我已经在前面的博客文章中讨论过了。这里代码的重点部分是从 Kafka 中消费数据: [kafka-to-mongo/kafka-mongo-sample.go][11] ``` - func main() { //Create MongoDB session @@ -206,60 +197,56 @@ func saveJobToMongo(jobString string) { fmt.Printf("Saved to MongoDB : %s", jobString) } - ``` -Let's get down to the demo, run Microservice 1\. Make sure Kafka is running. +我们来演示一下,运行微服务 1。确保 Kafka 已经运行了。 ``` $ go run rest-kafka-sample.go - ``` -I used Postman to send data to Microservice 1 +我使用 Postman 向微服务 1 发送数据。 ![Screenshot-2018-04-29-22.20.33](https://www.melvinvivas.com/content/images/2018/04/Screenshot-2018-04-29-22.20.33.png) -Here is the log you will see in Microservice 1\. Once you see this, it means data has been received from Postman and saved to Kafka +这里是日志,你可以在微服务 1 中看到。当你看到这些的时候,说明已经接收到了来自 Postman 发送的数据,并且已经保存到了 Kafka。 ![Screenshot-2018-04-29-22.22.00](https://www.melvinvivas.com/content/images/2018/04/Screenshot-2018-04-29-22.22.00.png) -Since we are not running Microservice 2 yet, the data saved by Microservice 1 will just be in Kafka. Let's consume it and save to MongoDB by running Microservice 2. +因为我们尚未运行微服务 2,数据被微服务 1 只保存在了 Kafka。我们来消费它并通过运行的微服务 2 来将它保存到 MongoDB。 ``` $ go run kafka-mongo-sample.go - ``` -Now you'll see that Microservice 2 consumes the data and saves it to MongoDB +现在,你将在微服务 2 上看到消费的数据,并将它保存到了 MongoDB。 ![Screenshot-2018-04-29-22.24.15](https://www.melvinvivas.com/content/images/2018/04/Screenshot-2018-04-29-22.24.15.png) -Check if data is saved in MongoDB. If it is there, we're good! +检查一下数据是否保存到了 MongoDB。如果有数据,我们成功了! ![Screenshot-2018-04-29-22.26.39](https://www.melvinvivas.com/content/images/2018/04/Screenshot-2018-04-29-22.26.39.png) -Complete source code can be found here +完整的源代码可以在这里找到: + [https://github.com/donvito/learngo/tree/master/rest-kafka-mongo-microservice][12] -Shameless plug! If you like this blog post, please follow me in Twitter [@donvito][6]. I tweet about Docker, Kubernetes, GoLang, Cloud, DevOps, Agile and Startups. Would love to connect in [GitHub][7] and [LinkedIn][8] +现在是广告时间:如果你喜欢这篇文章,请在 Twitter [@donvito][6] 上关注我。我的 Twitter 上有关于 Docker、Kubernetes、GoLang、Cloud、DevOps、Agile 和 Startups 的内容。欢迎你们在 [GitHub][7] 和 [LinkedIn][8] 关注我。 -[VIDEO](https://youtu.be/xa0Yia1jdu8) - -Enjoy! +开心地玩吧! -------------------------------------------------------------------------------- via: https://www.melvinvivas.com/developing-microservices-using-kafka-and-mongodb/ -作者:[Melvin Vivas ][a] -译者:[译者ID](https://github.com/译者ID) -校对:[校对者ID](https://github.com/校对者ID) +作者:[Melvin Vivas][a] +译者:[qhwdw](https://github.com/qhwdw) +校对:[wxy](https://github.com/wxy) 本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 [a]:https://www.melvinvivas.com/author/melvin/ -[1]:https://www.melvinvivas.com/developing-microservices-using-kafka-and-mongodb/#video1 +[1]:https://youtu.be/xa0Yia1jdu8 [2]:https://kafka.apache.org/downloads [3]:https://github.com/confluentinc/confluent-kafka-go [4]:https://github.com/confluentinc/confluent-kafka-go diff --git a/published/201808/20180508 Everything old is new again- Microservices - DXC Blogs.md b/published/201808/20180508 Everything old is new again- Microservices - DXC Blogs.md new file mode 100644 index 0000000000..04716d5928 --- /dev/null +++ b/published/201808/20180508 Everything old is new again- Microservices - DXC Blogs.md @@ -0,0 +1,58 @@ +老树发新芽:微服务 +====== + +![](https://csccommunity.files.wordpress.com/2018/05/old-building-with-modern-addition.jpg?w=610) + +如果我告诉你有这样一种软件架构,一个应用程序的组件通过基于网络的通讯协议为其它组件提供服务,我估计你可能会说它是 … + +是的,它和你编程的年限有关。如果你从上世纪九十年代就开始了你的编程生涯,那么你肯定会说它是 [面向服务的架构][1] Service-Oriented Architecture(SOA)。但是,如果你是个年青人,并且在云上获得初步的经验,那么,你将会说:“哦,你说的是 [微服务][2]Microservices。” + +你们都没错。如果想真正地了解它们的差别,你需要深入地研究这两种架构。 + +在 SOA 中,服务是一个功能,它是定义好的、自包含的、并且是不依赖上下文和其它服务的状态的功能。总共有两种服务。一种是消费者服务,它从另外类型的服务 —— 提供者服务 —— 中请求一个服务。一个 SOA 服务可以同时扮演这两种角色。 + +SOA 服务可以与其它服务交换数据。两个或多个服务也可以彼此之间相互协调。这些服务执行基本的任务,比如创建一个用户帐户、提供登录功能、或验证支付。 + +与其说 SOA 是模块化一个应用程序,还不如说它是把分布式的、独立维护和部署的组件,组合成一个应用程序。然后在服务器上运行这些组件。 + +早期版本的 SOA 使用面向对象的协议进行组件间通讯。例如,微软的 [分布式组件对象模型][3] Distributed Component Object Model(DCOM) 和使用 [通用对象请求代理架构][5]Common Object Request Broker Architecture(CORBA) 规范的 [对象请求代理][4] Object Request Broker(ORB)。 + +用于消息服务的最新的版本,有 [Java 消息服务][6] Java Message Service(JMS)或者 [高级消息队列协议][7]Advanced Message Queuing Protocol(AMQP)。这些服务通过企业服务总线Enterprise Service Bus(ESB) 进行连接。基于这些总线,来传递和接收可扩展标记语言(XML)格式的数据。 + +[微服务][2] 是一个架构样式,其中的应用程序以松散耦合的服务或模块组成。它适用于开发大型的、复杂的应用程序的持续集成Continuous Integration/持续部署Continuous Deployment(CI/CD)模型。一个应用程序就是一堆模块的汇总。 + +每个微服务提供一个应用程序编程接口(API)端点。它们通过轻量级协议连接,比如,[表述性状态转移][8] REpresentational State Transfer(REST),或 [gRPC][9]。数据倾向于使用 [JavaScript 对象标记][10] JavaScript Object Notation(JSON)或 [Protobuf][11] 来表示。 + +这两种架构都可以用于去替代以前老的整体式架构,整体式架构的应用程序被构建为单个的、自治的单元。例如,在一个客户机 —— 服务器模式中,一个典型的 Linux、Apache、MySQL、PHP/Python/Perl (LAMP) 服务器端应用程序将去处理 HTTP 请求、运行子程序、以及从底层的 MySQL 数据库中检索/更新数据。所有这些应用程序“绑”在一起提供服务。当你改变了任何一个东西,你都必须去构建和部署一个新版本。 + +使用 SOA,你可以只改变需要的几个组件,而不是整个应用程序。使用微服务,你可以做到一次只改变一个服务。使用微服务,你才能真正做到一个解耦架构。 + +微服务也比 SOA 更轻量级。不过 SOA 服务是部署到服务器和虚拟机上,而微服务是部署在容器中。协议也更轻量级。这使得微服务比 SOA 更灵活。因此,它更适合于要求敏捷性的电商网站。 + +说了这么多,到底意味着什么呢?微服务就是 SOA 在容器和云计算上的变种。 + +老式的 SOA 并没有离我们远去,而因为我们不断地将应用程序搬迁到容器中,所以微服务架构将越来越流行。 + +-------------------------------------------------------------------------------- + +via: https://blogs.dxc.technology/2018/05/08/everything-old-is-new-again-microservices/ + +作者:[Cloudy Weather][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[qhwdw](https://github.com/qhwdw) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://blogs.dxc.technology/author/steven-vaughan-nichols/ +[1]:https://www.service-architecture.com/articles/web-services/service-oriented_architecture_soa_definition.html +[2]:http://microservices.io/ +[3]:https://technet.microsoft.com/en-us/library/cc958799.aspx +[4]:https://searchmicroservices.techtarget.com/definition/Object-Request-Broker-ORB +[5]:http://www.corba.org/ +[6]:https://docs.oracle.com/javaee/6/tutorial/doc/bncdq.html +[7]:https://www.amqp.org/ +[8]:https://www.service-architecture.com/articles/web-services/representational_state_transfer_rest.html +[9]:https://grpc.io/ +[10]:https://www.json.org/ +[11]:https://github.com/google/protobuf/ diff --git a/sources/tech/20180508 UKTools - Easy Way To Install Latest Linux Kernel.md b/published/201808/20180508 UKTools - Easy Way To Install Latest Linux Kernel.md similarity index 85% rename from sources/tech/20180508 UKTools - Easy Way To Install Latest Linux Kernel.md rename to published/201808/20180508 UKTools - Easy Way To Install Latest Linux Kernel.md index c85d9c35d4..17ef94b240 100644 --- a/sources/tech/20180508 UKTools - Easy Way To Install Latest Linux Kernel.md +++ b/published/201808/20180508 UKTools - Easy Way To Install Latest Linux Kernel.md @@ -1,38 +1,41 @@ -UKTools - Easy Way To Install Latest Linux Kernel +UKTools:安装最新 Linux 内核的简便方法 ====== -There are multiple utilities is available for Ubuntu to upgrade Linux kernel to latest stable version. We had already wrote about those utility in the past such as Linux Kernel Utilities (LKU), Ubuntu Kernel Upgrade Utility (UKUU) and Ubunsys. -Also few utilities are available and we will be planning to include in the further article like, ubuntu-mainline-kernel.sh and manual method from mainline kernel. +Ubuntu 中有许多实用程序可以将 Linux 内核升级到最新的稳定版本。我们之前已经写过关于这些实用程序的文章,例如 Linux Kernel Utilities (LKU)、 Ubuntu Kernel Upgrade Utility (UKUU) 和 Ubunsys。 -Today also we are going to teach you the similar utility called UKTools. You can try any one of these utilities to get your Linux kernels to the latest releases. +另外还有一些其它实用程序可供使用。我们计划在其它文章中包含这些,例如 `ubuntu-mainline-kernel.sh` 和从主线内核手动安装的方式。 -Latest kernel release comes with security bug fixes and some improvements so, better to keep latest one to get reliable, secure and better hardware performance. +今天我们还会教你类似的使用工具 —— UKTools。你可以尝试使用这些实用程序中的任何一个来将 Linux 内核升级至最新版本。 -Some times the latest kernel version might be buggy and can crash your system so, it’s your own risk. I would like to advise you to not to install on production environment. +最新的内核版本附带了安全漏洞修复和一些改进,因此,最好保持最新的内核版本以获得可靠、安全和更好的硬件性能。 -**Suggested Read :** -**(#)** [Linux Kernel Utilities (LKU) – A Set Of Shell Scripts To Compile, Install & Update Latest Kernel In Ubuntu/LinuxMint][1] -**(#)** [Ukuu – An Easy Way To Install/Upgrade Linux Kernel In Ubuntu based Systems][2] -**(#)** [6 Methods To Check The Running Linux Kernel Version On System][3] +有时候最新的内核版本可能会有一些漏洞,并且会导致系统崩溃,这是你的风险。我建议你不要在生产环境中安装它。 -### What Is UKTools +**建议阅读:** -[UKTools][4] stands for Ubuntu Kernel Tools, that contains two shell scripts `ukupgrade` and `ukpurge`. +- [Linux 内核实用程序(LKU)- 在 Ubuntu/LinuxMint 中编译,安装和更新最新内核的一组 Shell 脚本][1] +- [Ukuu - 在基于 Ubuntu 的系统中安装或升级 Linux 内核的简便方法][2] +- [6 种检查系统上正在运行的 Linux 内核版本的方法][3] -ukupgrade stands for “Ubuntu Kernel Upgrade”, which allows user to upgrade Linux kernel to latest stable version for Ubuntu/Mint and derivatives based on [kernel.ubuntu.com][5]. +### 什么是 UKTools -ukpurge stands for “Ubuntu Kernel Purge”, which allows user to remove old Linux kernel images/headers in machine for Ubuntu/ Mint and derivatives. It will keep only three kernel versions. +[UKTools][4] 意思是 Ubuntu 内核工具,它包含两个 shell 脚本 `ukupgrade` 和 `ukpurge`。 -There is no GUI for this utility, however it looks very simple and straight forward so, newbie can perform the upgrade without any issues. +`ukupgrade` 意思是 “Ubuntu Kernel Upgrade”,它允许用户将 Linux 内核升级到 Ubuntu/Mint 的最新稳定版本以及基于 [kernel.ubuntu.com][5] 的衍生版本。 + +`ukpurge` 意思是 “Ubuntu Kernel Purge”,它允许用户在机器中删除旧的 Linux 内核镜像或头文件,用于 Ubuntu/Mint 和其衍生版本。它将只保留三个内核版本。 + +此实用程序没有 GUI,但它看起来非常简单直接,因此,新手可以在没有任何问题的情况下进行升级。 + +我正在运行 Ubuntu 17.10,目前的内核版本如下: -I’m running Ubuntu 17.10 and the current kernel version is below. ``` $ uname -a Linux ubuntu 4.13.0-39-generic #44-Ubuntu SMP Thu Apr 5 14:25:01 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux - ``` -Run the following command to get the list of installed kernel on your system (Ubuntu and derivatives). Currently i’m holding `seven` kernels. +运行以下命令来获取系统上已安装内核的列表(Ubuntu 及其衍生产品)。目前我持有 `7` 个内核。 + ``` $ dpkg --list | grep linux-image ii linux-image-4.13.0-16-generic 4.13.0-16.19 amd64 Linux kernel image for version 4.13.0 on 64 bit x86 SMP @@ -50,26 +53,26 @@ ii linux-image-extra-4.13.0-37-generic 4.13.0-37.42 amd64 Linux kernel extra mod ii linux-image-extra-4.13.0-38-generic 4.13.0-38.43 amd64 Linux kernel extra modules for version 4.13.0 on 64 bit x86 SMP ii linux-image-extra-4.13.0-39-generic 4.13.0-39.44 amd64 Linux kernel extra modules for version 4.13.0 on 64 bit x86 SMP ii linux-image-generic 4.13.0.39.42 amd64 Generic Linux kernel image - ``` -### How To Install UKTools +### 如何安装 UKTools -Just run the below commands to install UKTools on Ubuntu and derivatives. +在 Ubuntu 及其衍生产品上,只需运行以下命令来安装 UKTools 即可。 + +在你的系统上运行以下命令来克隆 UKTools 仓库: -Run the below command to clone UKTools repository on your system. ``` $ git clone https://github.com/usbkey9/uktools - ``` -Navigate to uktools directory. +进入 uktools 目录: + ``` $ cd uktools - ``` -Run the Makefile to generate the necessary files. Also this will automatically install latest available kernel. Just reboot the system in order to use the latest kernel. +运行 `Makefile` 以生成必要的文件。此外,这将自动安装最新的可用内核。只需重新启动系统即可使用最新的内核。 + ``` $ sudo make [sudo] password for daygeek: @@ -186,30 +189,30 @@ done Thanks for using this script! Hope it helped. Give it a star: https://github.com/MarauderXtreme/uktools - ``` -Restart the system to activate the latest kernel. +重新启动系统以激活最新的内核。 + ``` $ sudo shutdown -r now - ``` -Once the system back to up, re-check the kernel version. +一旦系统重新启动,重新检查内核版本。 + ``` $ uname -a Linux ubuntu 4.16.7-041607-generic #201805021131 SMP Wed May 2 15:34:55 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux - ``` -This make command will drop the below files into `/usr/local/bin` directory. +此 make 命令会将下面的文件放到 `/usr/local/bin` 目录中。 + ``` do-kernel-upgrade do-kernel-purge - ``` -To remove old kernels, run the following command. +要移除旧内核,运行以下命令: + ``` $ do-kernel-purge @@ -362,10 +365,10 @@ run-parts: executing /etc/kernel/postrm.d/initramfs-tools 4.13.0-37-generic /boo run-parts: executing /etc/kernel/postrm.d/zz-update-grub 4.13.0-37-generic /boot/vmlinuz-4.13.0-37-generic Thanks for using this script!!! - ``` -Re-check the list of installed kernels using the below command. This will keep only old three kernels. +使用以下命令重新检查已安装内核的列表。它将只保留三个旧的内核。 + ``` $ dpkg --list | grep linux-image ii linux-image-4.13.0-38-generic 4.13.0-38.43 amd64 Linux kernel image for version 4.13.0 on 64 bit x86 SMP @@ -374,17 +377,17 @@ ii linux-image-extra-4.13.0-38-generic 4.13.0-38.43 amd64 Linux kernel extra mod ii linux-image-extra-4.13.0-39-generic 4.13.0-39.44 amd64 Linux kernel extra modules for version 4.13.0 on 64 bit x86 SMP ii linux-image-generic 4.13.0.39.42 amd64 Generic Linux kernel image ii linux-image-unsigned-4.16.7-041607-generic 4.16.7-041607.201805021131 amd64 Linux kernel image for version 4.16.7 on 64 bit x86 SMP - ``` -For next time you can call `do-kernel-upgrade` utility for new kernel installation. If any new kernel is available then it will install. If no, it will report no kernel update is available at the moment. +下次你可以调用 `do-kernel-upgrade` 实用程序来安装新的内核。如果有任何新内核可用,那么它将安装。如果没有,它将报告当前没有可用的内核更新。 + ``` $ do-kernel-upgrade Kernel up to date. Finishing - ``` -Run the `do-kernel-purge` command once again to confirm on this. If this found more than three kernels then it will remove. If no, it will report nothing to remove message. +再次运行 `do-kernel-purge` 命令以确认。如果发现超过三个内核,那么它将移除。如果不是,它将报告没有删除消息。 + ``` $ do-kernel-purge @@ -397,17 +400,17 @@ Linux Kernel 4.16.7-041607 Generic (linux-image-4.16.7-041607-generic) Nothing to remove! Thanks for using this script!!! - ``` + -------------------------------------------------------------------------------- via: https://www.2daygeek.com/uktools-easy-way-to-install-latest-stable-linux-kernel-on-ubuntu-mint-and-derivatives/ 作者:[Prakash Subramanian][a] 选题:[lujun9972](https://github.com/lujun9972) -译者:[译者ID](https://github.com/译者ID) -校对:[校对者ID](https://github.com/校对者ID) +译者:[MjSeven](https://github.com/MjSeven) +校对:[wxy](https://github.com/wxy) 本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 diff --git a/published/201808/20180510 Splicing the Cloud Native Stack, One Floor at a Time.md b/published/201808/20180510 Splicing the Cloud Native Stack, One Floor at a Time.md new file mode 100644 index 0000000000..97ddf08956 --- /dev/null +++ b/published/201808/20180510 Splicing the Cloud Native Stack, One Floor at a Time.md @@ -0,0 +1,223 @@ +逐层拼接云原生栈 +====== + +> 看着我们在纽约的办公大楼,我们发现了一种观察不断变化的云原生领域的完美方式。 + +在 Packet,我们的工作价值(基础设施infrastructure自动化)是非常基础的。因此,我们花费大量的时间来研究我们之上所有生态系统中的参与者和趋势 —— 以及之下的极少数! + +当你在任何生态系统的汪洋大海中徜徉时,很容易困惑或迷失方向。我知道这是事实,因为当我去年进入 Packet 工作时,从 Bryn Mawr 获得的英语学位,并没有让我完全得到一个 [Kubernetes][Kubernetes] 的认证。:) + +由于它超快的演进和巨大的影响,云原生生态系统打破了先例。似乎每眨一次眼睛,之前全新的技术(更不用说所有相关的理念了)就变得有意义……或至少有趣了。和其他许多人一样,我依据无处不在的 [CNCF][CNCF] 的 “[云原生蓝图][1]” 作为我去了解这个空间的参考标准。尽管如此,如果有一个定义这个生态系统的元素,那它一定是贡献和引领它们的人。 + +所以,在 12 月份一个很冷的下午,当我们走回办公室时,我们偶然发现了一个给投资人解释“云原生”的创新方式,当我们谈到从 [Aporeto][Aporeto] 中区分 [Cilium][Cilium] 的细微差别时,以及为什么从 [CoreDNS][CoreDNS] 和 [Spiffe][Spiffe] 到 [Digital Rebar][Digital Rebar] 和 [Fission][Fission] 的所有这些都这么有趣时,他的眼里充满了兴趣。 + +在新世贸中心的影子里向我们位于 13 层的狭窄办公室望去,我们突然想到一个把我们带到那个神奇世界的好主意:为什么不把它画出来呢?(LCTT 译注:“rabbit hole” 有多种含义,此处采用“爱丽丝梦游仙境”中的“兔子洞”含义。) + +![][2] + +于是,我们开始了把云原生栈逐层拼接起来的旅程。让我们一起探索它,给你一个“仅限今日有效”的福利。(LCTT 译注:意即云原生领域变化很快,可能本文/本图中所述很快过时。) + +[查看高清大图][3](25Mb)或给我们发邮件索取副本。 + +### 从最底层开始 + +当我们开始下笔的时候,我们希望首先亮出的是我们每天都在打交道的那一部分:硬件,但我们知道那对用户却是基本上不可见的。就像任何投资于下一个伟大的(通常是私有的)东西的秘密实验室一样,我们认为地下室是其最好的地点。 + +从大家公认的像 Intel、AMD 和华为(传言他们雇佣的工程师接近 80000 名)这样的巨头,到像 [Mellanox][Mellanox] 这样的细分市场参与者,硬件生态系统现在非常火。事实上,随着数十亿美元投入去攻克新的 offload(LCTT 译注:offload 泛指以前由软件及 CPU 来完成的工作,现在通过硬件来完成,以提升速度并降低 CPU 负载的做法)、GPU、定制协处理器,我们可能正在进入硬件的黄金时代。 + +著名的软件先驱[艾伦·凯][Alan Kay](Alan Kay)在 25 年前说过:“真正认真对待软件的人应该自己创造硬件”。说得不错,Alan! + +### 云即资本 + +就像我们的 CEO Zac Smith 多次跟我说的:一切都是钱的事。不仅要制造它,还要消费它!在云中,数十亿美元的投入才能让数据中心出现计算机,这样才能让开发者消费它。换句话说(根本没云,它只是别人的电脑而已): + +![][4] + +我们认为,对于“银行”(即能让云运转起来的借款人或投资人)来说最好的位置就是一楼。因此我们将大堂改造成银行家的咖啡馆,以便为所有的创业者提供幸运之轮。 + +![][5] + +### 连通和动力 + +如果金钱是润滑油,那么消耗大量燃料的引擎就是数据中心供应商和连接它们的网络。我们称他们为“连通”和“动力”。 + +从像 [Equinix][Equinix] 这样处于核心地位的接入商的和像 [Vapor.io][Vapor.io] 这样的接入新贵,到 [Verizon][Verizon]、[Crown Castle][Crown Castle] 和其它接入商铺设在地下(或海底)的“管道”,这是我们所有的栈都依赖但很少有人能看到的一部分。 + +因为我们花费大量的时间去研究数据中心和连通性,需要注意的一件事情是,这一部分的变化非常快,尤其是在 5G 正式商用时,某些负载开始不再那么依赖中心化的基础设施了。 + +边缘计算即将到来!:-) + +![][6] + +### 嗨,它就是基础设施! + +居于“连通”和“动力”之上的这一层,我们爱称为“处理器层”。这是奇迹发生的地方 —— 我们将来自下层的创新和实物投资转变成一个 API 终端的某些东西。 + +由于这是纽约的一个大楼,我们让在这里的云供应商处于纽约的中心。这就是为什么你会看到([Digital Ocean][Digital Ocean] 系的)鲨鱼 Sammy 和对 “meet me” 房间里面的 Google 标志的致意的原因了。 + +正如你所见,这个场景是非常写实的。它是由多层机架堆叠起来的。尽管我们爱 EWR1 的设备经理(Michael Pedrazzini),我们努力去尽可能减少这种体力劳动。毕竟布线专业的博士学位是很难拿到的。 + +![][7] + +### 供给 + +再上一层,在基础设施层之上是供给层。这是我们最喜欢的地方之一,它以前被我们称为配置管理config management。但是现在到处都是一开始就是不可变基础设施immutable infrastructure和自动化:[Terraform][Terraform]、[Ansible][Ansible]、[Quay.io][Quay.io] 等等类似的东西。你可以看出软件是按它的方式来工作的,对吗? + +Kelsey Hightower 最近写道“呆在无聊的基础设施中是一个让人兴奋的时刻”,我不认为这说的是物理部分(虽然我们认为它非常让人兴奋),但是由于软件持续侵入到栈的所有层,那必将是一个疯狂的旅程。 + +![][8] + +### 操作系统 + +供应就绪后,我们来到操作系统层。在这里你可以看到我们打趣一些我们最喜欢的同事:注意上面 Brian Redbeard 那超众的瑜珈姿势。:) + +Packet 为客户提供了 11 种主要的操作系统可供选择,包括一些你在图中看到的:[Ubuntu][Ubuntu]、[CoreOS][CoreOS]、[FreeBSD][FreeBSD]、[Suse][Suse]、和各种 [Red Hat][Red Hat] 系的发行版。我们看到越来越多的人们在这一层上加入了他们自己的看法:从定制内核和用于不可变部署的黄金镜像golden images(LCCT 注:golden image 指定型的镜像或模板,一般是经过一些定制,并做快照和版本控制,由此可拷贝出大量与此镜像一致的开发、测试或部署环境,也有人称作 master image),到像 [NixOS][NixOS] 和 [LinuxKit][LinuxKit] 这样的项目。 + +![][9] + +### 运行时 + +为了有趣些,我们将运行时runtime放在了体育馆内,并为 CoreOS 赞助的 [rkt][rkt] 和 [Docker][Docker] 的容器化举行了一次比赛。而无论如何赢家都是 CNCF! + +我们认为快速演进的存储生态系统应该是一些可上锁的储物柜。关于存储部分有趣的地方在于许多的新玩家尝试去解决持久性的挑战问题,以及性能和灵活性问题。就像他们说的:存储很简单。 + +![][10] + +### 编排 + +在过去的这一年里,编排层全是 Kubernetes 了,因此我们选取了其中一位著名的布道者(Kelsey Hightower),并在这个古怪的会议场景中给他一个特写。在我们的团队中有一些 [Nomad][Nomad](LCTT 译注:一个管理机器集群并在集群上运行应用程序的工具)的忠实粉丝,并且如果抛开 Docker 和它的工具集的影响,就无从谈起云原生。 + +虽然负载编排应用程序在我们栈中的地位非常高,我们看到的各种各样的证据表明,这些强大的工具开始去深入到栈中,以帮助用户利用 GPU 和其它特定硬件的优势。请继续关注 —— 我们正处于容器化革命的早期阶段! + +![][11] + +### 平台 + +这是栈中我们喜欢的层之一,因为每个平台都有如此多的工具帮助用户去完成他们想要做的事情(顺便说一下,不是去运行容器,而是运行应用程序)。从 [Rancher][Rancher] 和 [Kontena][Kontena],到 [Tectonic][Tectonic] 和 [Redshift][Redshift] 都是像 [Cycle.io][Cycle.io] 和 [Flynn.io][Flynn.io] 一样是完全不同的方法 —— 我们看到这些项目如何以不同的方式为用户提供服务,总是激动不已。 + +关键点:这些平台是帮助用户转化云原生生态系统中各种各样的快速变化的部分。很高兴能看到他们各自带来的东西! + +![][12] + +### 安全 + +当说到安全时,今年真是很忙的一年!我们尝试去展示一些很著名的攻击,并说明随着工作负载变得更加分散和更加可迁移(当然,同时攻击者也变得更加智能),这些各式各样的工具是如何去帮助保护我们的。 + +我们看到一个用于不可信环境(如 Aporeto)和低级安全(Cilium)的强大动作,以及尝试在网络级别上的像 [Tigera][Tigera] 这样的可信方法。不管你的方法如何,记住这一点:安全无止境。:0 + +![][13] + +### 应用程序 + +如何去表示海量的、无限的应用程序生态系统?在这个案例中,很容易:我们在纽约,选我们最喜欢的。;) 从 [Postgres][Postgres] “房间里的大象” 和 [Timescale][Timescale] 时钟,到鬼鬼祟祟的 [ScyllaDB][ScyllaDB] 垃圾桶和那个悠闲的 [Travis][Travis] 哥们 —— 我们把这个片子拼到一起很有趣。 + +让我们感到很惊奇的一件事情是:很少有人注意到那个复印屁股的家伙。我想现在复印机已经不常见了吧? + +![][14] + +### 可观测性 + +由于我们的工作负载开始到处移动,规模也越来越大,这里没有一件事情能够像一个非常好用的 [Grafana][Grafana] 仪表盘、或方便的 [Datadog][Datadog] 代理让人更加欣慰了。由于复杂度的提升,[SRE][SRE] 时代开始越来越多地依赖监控告警和其它智能事件去帮我们感知发生的事件,出现越来越多的自我修复的基础设施和应用程序。 + +在未来的几个月或几年中,我们将看到什么样的面孔进入这一领域……或许是一些人工智能、区块链、机器学习支撑的仪表盘?:-) + +![][15] + +### 流量管理 + +人们往往认为互联网“只是能工作而已”,但事实上,我们很惊讶于它居然能如此工作。我的意思是,就这些大规模的、不同的网络间的松散连接 —— 你不是在开玩笑吧? + +能够把所有的这些独立的网络拼接到一起的一个原因是流量管理、DNS 和类似的东西。随着规模越来越大,这些让互联网变得更快、更安全、同时更具弹性。我们尤其高兴的是看到像 [Fly.io][Fly.io] 和 [NS1][NS1] 这样的新贵与优秀的老牌玩家进行竞争,最后的结果是整个生态系统都得以提升。让竞争来的更激烈吧! + +![][16] + +### 用户 + +如果没有非常棒的用户,技术栈还有什么用呢?确实,他们享受了大量的创新,但在云原生的世界里,他们所做的远不止消费这么简单:他们也创造并贡献了很多。从像 Kubernetes 这样的大量的贡献者到越来越多的(但同样重要)更多方面,而我们都是其中的非常棒的一份子。 + +在我们屋顶上有许多悠闲的用户,比如 [Ticketmaster][Ticketmaster] 和[《纽约时报》][New York Times],而不仅仅是新贵:这些组织拥抱了部署和管理应用程序的方法的变革,并且他们的用户正在享受变革带来的回报。 + +![][17] + +### 同样重要的,成熟的监管! + +在以前的生态系统中,基金会扮演了一个非常被动的“幕后”角色。而 CNCF 不是!他们的目标(构建一个健壮的云原生生态系统),勇立潮流之先 —— 他们不仅已迎头赶上还一路领先。 + +从坚实的治理和经过深思熟虑的项目组,到提出像 CNCF 这样的蓝图,CNCF 横跨云 CI、Kubernetes 认证、和讲师团 —— CNCF 已不再是 “仅仅” 受欢迎的 [KubeCon + CloudNativeCon][KCCNC] 了。 + +-------------------------------------------------------------------------------- + +via: https://www.packet.net/blog/splicing-the-cloud-native-stack/ + +作者:[Zoe Allen][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[qhwdw](https://github.com/qhwdw) +校对:[wxy](https://github.com/wxy), [pityonline](https://github.com/pityonline) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://www.packet.net/about/zoe-allen/ +[1]: https://landscape.cncf.io/landscape=cloud +[2]: https://assets.packet.net/media/images/PIFg-30.vesey.street.ny.jpg +[3]: https://www.dropbox.com/s/ujxk3mw6qyhmway/Packet_Cloud_Native_Building_Stack.jpg?dl=0 +[4]: https://assets.packet.net/media/images/3vVx-there.is.no.cloud.jpg +[5]: https://assets.packet.net/media/images/X0b9-the.bank.jpg +[6]: https://assets.packet.net/media/images/2Etm-ping.and.power.jpg +[7]: https://assets.packet.net/media/images/C800-infrastructure.jpg +[8]: https://assets.packet.net/media/images/0V4O-provisioning.jpg +[9]: https://assets.packet.net/media/images/eMYp-operating.system.jpg +[10]: https://assets.packet.net/media/images/9BII-run.time.jpg +[11]: https://assets.packet.net/media/images/njak-orchestration.jpg +[12]: https://assets.packet.net/media/images/1QUS-platforms.jpg +[13]: https://assets.packet.net/media/images/TeS9-security.jpg +[14]: https://assets.packet.net/media/images/SFgF-apps.jpg +[15]: https://assets.packet.net/media/images/SXoj-observability.jpg +[16]: https://assets.packet.net/media/images/tKhf-traffic.management.jpg +[17]: https://assets.packet.net/media/images/7cpe-users.jpg +[Kubernetes]: https://kubernetes.io/ +[CNCF]: https://www.cncf.io/ +[Aporeto]: https://www.aporeto.com/ +[Cilium]: https://cilium.io/ +[CoreDNS]: https://coredns.io/ +[Spiffe]: https://spiffe.io/ +[Digital Rebar]: http://rebar.digital/ +[Fission]: https://fission.io/ +[Mellanox]: http://www.mellanox.com/ +[Alan Kay]: https://en.wikipedia.org/wiki/Alan_Kay +[Equinix]: https://www.equinix.com/ +[Vapor.io]: https://www.vapor.io/ +[Verizon]: https://www.verizon.com/ +[Crown Castle]: http://www.crowncastle.com/ +[Digital Ocean]: https://www.digitalocean.com/ +[Terraform]: https://www.terraform.io/ +[Ansible]: https://www.ansible.com/ +[Quay.io]: https://quay.io/ +[Ubuntu]: https://www.ubuntu.com/ +[CoreOS]: https://coreos.com/ +[FreeBSD]: https://www.freebsd.org/ +[Suse]: https://www.suse.com/ +[Red Hat]: https://www.redhat.com/ +[NixOS]: https://nixos.org/ +[LinuxKit]: https://github.com/linuxkit/linuxkit +[rkt]: https://coreos.com/rkt/ +[Docker]: https://www.docker.com/ +[Nomad]: https://www.nomadproject.io/ +[Rancher]: https://rancher.com/ +[Kontena]: https://kontena.io/ +[Tectonic]: https://coreos.com/tectonic/ +[Redshift]: https://aws.amazon.com/redshift/ +[Cycle.io]: https://cycle.io/ +[Flynn.io]: https://flynn.io/ +[Tigera]: https://www.tigera.io/ +[Postgres]: https://www.postgresql.org/ +[Timescale]: https://www.timescale.com/ +[ScyllaDB]: https://www.scylladb.com/ +[Travis]: https://travis-ci.com/ +[Grafana]: https://grafana.com/ +[Datadog]: https://www.datadoghq.com/ +[SRE]: https://en.wikipedia.org/wiki/Site_Reliability_Engineering +[Fly.io]: https://fly.io/ +[NS1]: https://ns1.com/ +[Ticketmaster]: https://www.ticketmaster.com/ +[New York Times]: https://www.nytimes.com/ +[KCCNC]: https://www.cncf.io/community/kubecon-cloudnativecon-events/ diff --git a/sources/tech/20180516 How to Read Outlook Emails by Python.md b/published/201808/20180516 How to Read Outlook Emails by Python.md similarity index 83% rename from sources/tech/20180516 How to Read Outlook Emails by Python.md rename to published/201808/20180516 How to Read Outlook Emails by Python.md index 36a000d010..d10a411b0e 100644 --- a/sources/tech/20180516 How to Read Outlook Emails by Python.md +++ b/published/201808/20180516 How to Read Outlook Emails by Python.md @@ -1,32 +1,32 @@ -translating by lujun9972 -How to Read Outlook Emails by Python +如何用 Python 读取 Outlook 中的电子邮件 ====== ![](https://process.filestackapi.com/cache=expiry:max/resize=width:700/compress/OVArLzhmRzOEQZsvGavF) -when you start e-mail marketing , You need opt-in email address list. You have opt-in list. You are using email client software and If you can export your list from your email client, You will have good list. +从事电子邮件营销,准入opt-in邮箱列表是必不可少的。你可能已经有了准入列表,同时还使用电子邮件客户端软件。如果你能从电子邮件客户端中导出准入列表,那这份列表想必是极好的。 -Now I am trying to explain my codes to write all emails into test file from your outlook profile. +我使用一些代码来将 outlook 配置中的所有邮件写入一个临时文件中,现在让我来尝试解释一下这些代码。 + +首先你需要导入 win32com.client,为此你需要安装 pywin32: -First you should import win32com.client, You need to install pywin32 ``` pip install pywin32 - ``` -We should connect to Outlook by MAPI +我们需要通过 MAPI 协议连接 Outlok: + ``` outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI") - ``` -Then we should get all accounts in your outlook profile. +然后从 outlook 配置中获取所有的账户: + ``` accounts= win32com.client.Dispatch("Outlook.Application").Session.Accounts; - ``` -Then You need to get emails from inbox folder that is named emailleri_al. +在然后需要从名为 emaileri_al 的收件箱中获取邮件: + ``` def emailleri_al(folder): messages = folder.Items @@ -49,7 +49,8 @@ def emailleri_al(folder): pass ``` -You should go to all account and get inbox folder and get emails +你需要进入所有账户的所有收件箱中获取电子邮件: + ``` for account in accounts: global inbox @@ -78,7 +79,8 @@ for account in accounts: print("*************************************************", file= ``` -All Code is as the following +下面是完整的代码: + ``` import win32com.client import win32com @@ -149,7 +151,7 @@ via: https://www.codementor.io/aliacetrefli/how-to-read-outlook-emails-by-python 作者:[A.A. Cetrefli][a] 选题:[lujun9972](https://github.com/lujun9972) 译者:[lujun9972](https://github.com/lujun9972) -校对:[校对者ID](https://github.com/校对者ID) +校对:[wxy](https://github.com/wxy) 本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 diff --git a/published/201808/20180523 A Set Of Useful Utilities For Debian And Ubuntu Users.md b/published/201808/20180523 A Set Of Useful Utilities For Debian And Ubuntu Users.md new file mode 100644 index 0000000000..1c4478766d --- /dev/null +++ b/published/201808/20180523 A Set Of Useful Utilities For Debian And Ubuntu Users.md @@ -0,0 +1,292 @@ +献给 Debian 和 Ubuntu 用户的一组实用程序 +====== + +![](https://www.ostechnix.com/wp-content/uploads/2018/05/debian-goodies-720x340.png) + +你使用的是基于 Debian 的系统吗?如果是,太好了!我今天在这里给你带来了一个好消息。先向 “Debian-goodies” 打个招呼,这是一组基于 Debian 系统(比如:Ubuntu、Linux Mint)的有用工具。这些实用工具提供了一些额外的有用的命令,这些命令在基于 Debian 的系统中默认不可用。通过使用这些工具,用户可以找到哪些程序占用更多磁盘空间,更新系统后需要重新启动哪些服务,在一个软件包中搜索与模式匹配的文件,根据搜索字符串列出已安装的包等等。在这个简短的指南中,我们将讨论一些有用的 Debian 的好东西。 + +### Debian-goodies – 给 Debian 和 Ubuntu 用户的实用程序 + +debian-goodies 包可以在 Debian 和其衍生的 Ubuntu 以及其它 Ubuntu 变体(如 Linux Mint)的官方仓库中找到。要安装 debian-goodies,只需简单运行: + +``` +$ sudo apt-get install debian-goodies +``` + +debian-goodies 安装完成后,让我们继续看一看一些有用的实用程序。 + +#### 1、 checkrestart + +让我从我最喜欢的 `checkrestart` 实用程序开始。安装某些安全更新时,某些正在运行的应用程序可能仍然会使用旧库。要彻底应用安全更新,你需要查找并重新启动所有这些更新。这就是 `checkrestart` 派上用场的地方。该实用程序将查找哪些进程仍在使用旧版本的库,然后,你可以重新启动服务。 + +在进行库更新后,要检查哪些守护进程应该被重新启动,运行: + +``` +$ sudo checkrestart +[sudo] password for sk: +Found 0 processes using old versions of upgraded files +``` + +由于我最近没有执行任何安全更新,因此没有显示任何内容。 + +请注意,`checkrestart` 实用程序确实运行良好。但是,有一个名为 `needrestart` 的类似的新工具可用于最新的 Debian 系统。`needrestart` 的灵感来自 `checkrestart` 实用程序,它完成了同样的工作。 `needrestart` 得到了积极维护,并支持容器(LXC、 Docker)等新技术。 + +以下是 `needrestart` 的特点: + + * 支持(但不要求)systemd + * 二进制程序的黑名单(例如:用于图形显示的显示管理器) + * 尝试检测挂起的内核升级 + * 尝试检测基于解释器的守护进程所需的重启(支持 Perl、Python、Ruby) + * 使用钩子完全集成到 apt/dpkg 中 + +它在默认仓库中也可以使用。所以,你可以使用如下命令安装它: + +``` +$ sudo apt-get install needrestart +``` + +现在,你可以使用以下命令检查更新系统后需要重新启动的守护程序列表: + +``` +$ sudo needrestart +Scanning processes... +Scanning linux images... + +Running kernel seems to be up-to-date. + +Failed to check for processor microcode upgrades. + +No services need to be restarted. + +No containers need to be restarted. + +No user sessions are running outdated binaries. +``` + +好消息是 Needrestart 同样也适用于其它 Linux 发行版。例如,你可以从 Arch Linux 及其衍生版的 AUR 或者其它任何 AUR 帮助程序来安装,就像下面这样: + +``` +$ yaourt -S needrestart +``` + +在 Fedora: + +``` +$ sudo dnf install needrestart +``` + +#### 2、 check-enhancements + +`check-enhancements` 实用程序用于查找那些用于增强已安装的包的软件包。此实用程序将列出增强其它包但不是必须运行它的包。你可以通过 `-ip` 或 `–installed-packages` 选项来查找增强单个包或所有已安装包的软件包。 + +例如,我将列出增强 gimp 包功能的包: + +``` +$ check-enhancements gimp +gimp => gimp-data: Installed: (none) Candidate: 2.8.22-1 +gimp => gimp-gmic: Installed: (none) Candidate: 1.7.9+zart-4build3 +gimp => gimp-gutenprint: Installed: (none) Candidate: 5.2.13-2 +gimp => gimp-help-ca: Installed: (none) Candidate: 2.8.2-0.1 +gimp => gimp-help-de: Installed: (none) Candidate: 2.8.2-0.1 +gimp => gimp-help-el: Installed: (none) Candidate: 2.8.2-0.1 +gimp => gimp-help-en: Installed: (none) Candidate: 2.8.2-0.1 +gimp => gimp-help-es: Installed: (none) Candidate: 2.8.2-0.1 +gimp => gimp-help-fr: Installed: (none) Candidate: 2.8.2-0.1 +gimp => gimp-help-it: Installed: (none) Candidate: 2.8.2-0.1 +gimp => gimp-help-ja: Installed: (none) Candidate: 2.8.2-0.1 +gimp => gimp-help-ko: Installed: (none) Candidate: 2.8.2-0.1 +gimp => gimp-help-nl: Installed: (none) Candidate: 2.8.2-0.1 +gimp => gimp-help-nn: Installed: (none) Candidate: 2.8.2-0.1 +gimp => gimp-help-pt: Installed: (none) Candidate: 2.8.2-0.1 +gimp => gimp-help-ru: Installed: (none) Candidate: 2.8.2-0.1 +gimp => gimp-help-sl: Installed: (none) Candidate: 2.8.2-0.1 +gimp => gimp-help-sv: Installed: (none) Candidate: 2.8.2-0.1 +gimp => gimp-plugin-registry: Installed: (none) Candidate: 7.20140602ubuntu3 +gimp => xcftools: Installed: (none) Candidate: 1.0.7-6 +``` + +要列出增强所有已安装包的,请运行: + +``` +$ check-enhancements -ip +autoconf => autoconf-archive: Installed: (none) Candidate: 20170928-2 +btrfs-progs => snapper: Installed: (none) Candidate: 0.5.4-3 +ca-certificates => ca-cacert: Installed: (none) Candidate: 2011.0523-2 +cryptsetup => mandos-client: Installed: (none) Candidate: 1.7.19-1 +dpkg => debsig-verify: Installed: (none) Candidate: 0.18 +[...] +``` + +#### 3、 dgrep + +顾名思义,`dgrep` 用于根据给定的正则表达式搜索制指定包的所有文件。例如,我将在 Vim 包中搜索包含正则表达式 “text” 的文件。 + +``` +$ sudo dgrep "text" vim +Binary file /usr/bin/vim.tiny matches +/usr/share/doc/vim-tiny/copyright: that they must include this license text. You can also distribute +/usr/share/doc/vim-tiny/copyright: include this license text. You are also allowed to include executables +/usr/share/doc/vim-tiny/copyright: 1) This license text must be included unmodified. +/usr/share/doc/vim-tiny/copyright: text under a) applies to those changes. +/usr/share/doc/vim-tiny/copyright: context diff. You can choose what license to use for new code you +/usr/share/doc/vim-tiny/copyright: context diff will do. The e-mail address to be used is +/usr/share/doc/vim-tiny/copyright: On Debian systems, the complete text of the GPL version 2 license can be +[...] +``` + +`dgrep` 支持大多数 `grep` 的选项。参阅以下指南以了解 `grep` 命令。 + + * [献给初学者的 Grep 命令教程][2] + +#### 4、 dglob + +`dglob` 实用程序生成与给定模式匹配的包名称列表。例如,找到与字符串 “vim” 匹配的包列表。 + +``` +$ sudo dglob vim +vim-tiny:amd64 +vim:amd64 +vim-common:all +vim-runtime:all +``` + +默认情况下,`dglob` 将仅显示已安装的软件包。如果要列出所有包(包括已安装的和未安装的),使用 `-a` 标志。 + +``` +$ sudo dglob vim -a +``` + +#### 5、 debget + +`debget` 实用程序将在 APT 的数据库中下载一个包的 .deb 文件。请注意,它只会下载给定的包,不包括依赖项。 + +``` +$ debget nano +Get:1 http://in.archive.ubuntu.com/ubuntu bionic/main amd64 nano amd64 2.9.3-2 [231 kB] +Fetched 231 kB in 2s (113 kB/s) +``` + +#### 6、 dpigs + +这是此次集合中另一个有用的实用程序。`dpigs` 实用程序将查找并显示那些占用磁盘空间最多的已安装包。 + +``` +$ dpigs +260644 linux-firmware +167195 linux-modules-extra-4.15.0-20-generic +75186 linux-headers-4.15.0-20 +64217 linux-modules-4.15.0-20-generic +55620 snapd +31376 git +31070 libicu60 +28420 vim-runtime +25971 gcc-7 +24349 g++-7 +``` + +如你所见,linux-firmware 包占用的磁盘空间最多。默认情况下,它将显示占用磁盘空间的 **前 10 个**包。如果要显示更多包,例如 20 个,运行以下命令: + +``` +$ dpigs -n 20 +``` + +#### 7. debman + +`debman` 实用程序允许你轻松查看二进制文件 .deb 中的手册页而不提取它。你甚至不需要安装 .deb 包。以下命令显示 nano 包的手册页。 + +``` +$ debman -f nano_2.9.3-2_amd64.deb nano +``` + +如果你没有 .deb 软件包的本地副本,使用 `-p` 标志下载并查看包的手册页。 + +``` +$ debman -p nano nano +``` + +**建议阅读:** + +- [每个 Linux 用户都应该知道的 3 个 man 的替代品][3] + +#### 8、 debmany + +安装的 Debian 包不仅包含手册页,还包括其它文件,如确认、版权和自述文件等。`debmany` 实用程序允许你查看和读取那些文件。 + +``` +$ debmany vim +``` + +![][1] + +使用方向键选择要查看的文件,然后按回车键查看所选文件。按 `q` 返回主菜单。 + +如果未安装指定的软件包,`debmany` 将从 APT 数据库下载并显示手册页。应安装 `dialog` 包来阅读手册页。 + +#### 9、 popbugs + +如果你是开发人员,`popbugs` 实用程序将非常有用。它将根据你使用的包显示一个定制的发布关键 bug 列表(使用 popularity-contest 数据)。对于那些不关心的人,popularity-contest 包设置了一个 cron (定时)任务,它将定期匿名向 Debian 开发人员提交有关该系统上最常用的 Debian 软件包的统计信息。这些信息有助于 Debian 做出决定,例如哪些软件包应该放在第一张 CD 上。它还允许 Debian 改进未来的发行版本,以便为新用户自动安装最流行的软件包。 + +要生成严重 bug 列表并在默认 Web 浏览器中显示结果,运行: + +``` +$ popbugs +``` + +此外,你可以将结果保存在文件中,如下所示。 + +``` +$ popbugs --output=bugs.txt +``` + +#### 10、 which-pkg-broke + +此命令将显示给定包的所有依赖项以及安装每个依赖项的时间。通过使用此信息,你可以在升级系统或软件包之后轻松找到哪个包可能会在什么时间损坏了另一个包。 + +``` +$ which-pkg-broke vim +Package has no install time info +debconf Wed Apr 25 08:08:40 2018 +gcc-8-base:amd64 Wed Apr 25 08:08:41 2018 +libacl1:amd64 Wed Apr 25 08:08:41 2018 +libattr1:amd64 Wed Apr 25 08:08:41 2018 +dpkg Wed Apr 25 08:08:41 2018 +libbz2-1.0:amd64 Wed Apr 25 08:08:41 2018 +libc6:amd64 Wed Apr 25 08:08:42 2018 +libgcc1:amd64 Wed Apr 25 08:08:42 2018 +liblzma5:amd64 Wed Apr 25 08:08:42 2018 +libdb5.3:amd64 Wed Apr 25 08:08:42 2018 +[...] +``` + +#### 11、 dhomepage + +`dhomepage` 实用程序将在默认 Web 浏览器中显示给定包的官方网站。例如,以下命令将打开 Vim 编辑器的主页。 + +``` +$ dhomepage vim +``` + +这就是全部了。Debian-goodies 是你武器库中必备的工具。即使我们不经常使用所有这些实用程序,但它们值得学习,我相信它们有时会非常有用。 + +我希望这很有用。更多好东西要来了。敬请关注! + +干杯! + + +-------------------------------------------------------------------------------- + +via: https://www.ostechnix.com/debian-goodies-a-set-of-useful-utilities-for-debian-and-ubuntu-users/ + +作者:[SK][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[MjSeven](https://github.com/MjSeven) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.ostechnix.com/author/sk/ +[1]:http://www.ostechnix.com/wp-content/uploads/2018/05/debmany.png +[2]: +https://www.ostechnix.com/the-grep-command-tutorial-with-examples-for-beginners/ +[3]: +https://www.ostechnix.com/3-good-alternatives-man-pages-every-linux-user-know/ diff --git a/published/201808/20180524 How CERN Is Using Linux and Open Source.md b/published/201808/20180524 How CERN Is Using Linux and Open Source.md new file mode 100644 index 0000000000..492376d49d --- /dev/null +++ b/published/201808/20180524 How CERN Is Using Linux and Open Source.md @@ -0,0 +1,66 @@ +欧洲核子研究组织(CERN)是如何使用 Linux 和开源的 +============================================================ + +![CERN](https://www.linux.com/sites/lcom/files/styles/rendered_file/public/atlas-cern.jpg?itok=IRLUYCNQ "CERN") + +>欧洲核子研究组织(简称 CERN)依靠开源技术处理大型强子对撞机生成的大量数据。ATLAS(超环面仪器,如图所示)是一种探测基本粒子的通用探测器。(图片来源:CERN) + +[CERN][6] 无需过多介绍了吧。CERN 创建了万维网World Wide Web(WWW)和大型强子对撞机Large Hadron Collider(LHC),这是世界上最大的粒子加速器particle accelerator,就是通过它发现了 [希格斯玻色子][7]Higgs boson。负责该组织 IT 操作系统和基础架构的 Tim Bell 表示,他的团队的目标是“为全球 13000 名物理学家提供计算设施,以分析这些碰撞,了解宇宙的构成以及是如何运转的。” + +CERN 正在进行硬核科学研究,尤其是大型强子对撞机,它在运行时 [生成大量数据][8]。“CERN 目前存储大约 200 PB 的数据,当加速器运行时,每月有超过 10 PB 的数据产生。这必然会给计算基础架构带来极大的挑战,包括存储大量数据,以及能够在合理的时间范围内处理数据,对于网络、存储技术和高效计算架构都是很大的压力。“Bell 说到。 + +![Tim Bell](https://www.linux.com/sites/lcom/files/styles/floated_images/public/tim-bell-cern.png?itok=5eUOpip- "Tim Bell") + +*Tim Bell, CERN* + +大型强子对撞机的运作规模和它产生的数据量带来了严峻的挑战,但 CERN 对这些问题并不陌生。CERN 成立于 1954 年,已经 60 余年了。“我们一直面临着难以解决的计算能力挑战,但我们一直在与开源社区合作解决这些问题。”Bell 说,“即使在 90 年代,当我们发明万维网时,我们也希望与人们共享,使其能够从 CERN 的研究中受益,开源是做这件事的再合适不过的工具了。” + +### 使用 OpenStack 和 CentOS + +时至今日,CERN 是 OpenStack 的深度用户,而 Bell 则是 OpenStack 基金会的董事会成员之一。不过 CERN 比 OpenStack 出现的要早,多年来,他们一直在使用各种开源技术通过 Linux 服务器提供服务。 + +“在过去的十年中,我们发现,与其自己解决问题,不如找到面临类似挑战的上游开源社区进行合作,然后我们一同为这些项目做出贡献,而不是一切都由自己来创造和维护。“Bell 说。 + +一个很好的例子是 Linux 本身。CERN 曾经是 Red Hat Enterprise Linux 的客户。其实,早在 2004 年,他们就与 Fermilab 合作一起建立了自己的 Linux 发行版,名为 [Scientific Linux][9]。最终他们意识到,因为没有修改内核,耗费时间建立自己的发行版是没有意义的,所以他们迁移到了 CentOS 上。由于 CentOS 是一个完全开源和社区驱使的项目,CERN 可以与该项目合作,并为 CentOS 的构建和分发做出贡献。 + +CERN 帮助 CentOS 提供基础架构,他们还组织了 CentOS DoJo 活动(LCTT 译者注:CentOS Dojo 是为期一日的活动,汇聚来自 CentOS 社群的人分享系统管理、最佳实践及新兴科技。),工程师可以汇聚在此共同改进 CentOS 的封装。 + +除了 OpenStack 和 CentOS 之外,CERN 还是其他开源项目的深度用户,包括用于配置管理的 Puppet、用于监控的 Grafana 和 InfluxDB,等等。 + +“我们与全球约 170 个实验室合作。因此,每当我们发现一个开源项目的改进之处,其他实验室便可以很容易地采纳使用。”Bell 说,“与此同时,我们也向其他项目学习。当像 eBay 和 Rackspace 这样大规模的装机量提高了解决方案的可扩展性时,我们也从中受益,也可以扩大规模。“ + +### 解决现实问题 + +2012 年左右,CERN 正在研究如何为大型强子对撞机扩展计算能力,但难点是人员而不是技术。CERN 雇用的员工人数是固定的。“我们必须找到一种方法来扩展计算能力,而不需要大量额外的人来管理。”Bell 说,“OpenStack 为我们提供了一个自动的 API 驱动和软件定义的基础架构。”OpenStack 还帮助 CERN 检查与服务交付相关的问题,然后使其自动化,而无需增加员工。 + +“我们目前在日内瓦和布达佩斯的两个数据中心运行大约 280000 个处理器核心和 7000 台服务器。我们正在使用软件定义的基础架构使一切自动化,这使我们能够在保持员工数量不变的同时继续添加更多的服务器。“Bell 说。 + +随着时间的推移,CERN 将面临更大的挑战。大型强子对撞机有一个到 2035 年的蓝图,包括一些重要的升级。“我们的加速器运转三到四年,然后会用 18 个月或两年的时间来升级基础架构。在这维护期间我们会做一些计算能力的规划。 +”Bell 说。CERN 还计划升级高亮度大型强子对撞机,会允许更高光度的光束。与目前的 CERN 的规模相比,升级意味着计算需求需增加约 60 倍。 + +“根据摩尔定律,我们可能只能满足需求的四分之一,因此我们必须找到相应的扩展计算能力和存储基础架构的方法,并找到自动化和解决方案,例如 OpenStack,将有助于此。”Bell 说。 + +“当我们开始使用大型强子对撞机并观察我们如何提供计算能力时,很明显我们无法将所有内容都放入 CERN 的数据中心,因此我们设计了一个分布式网格结构:位于中心的 CERN 和围绕着它的级联结构。”Bell 说,“全世界约有 12 个大型一级数据中心,然后是 150 所小型大学和实验室。他们从大型强子对撞机的数据中收集样本,以帮助物理学家理解和分析数据。” + +这种结构意味着 CERN 正在进行国际合作,数百个国家正致力于分析这些数据。归结为一个基本原则,即开源不仅仅是共享代码,还包括人们之间的协作、知识共享,以实现个人、组织或公司无法单独实现的目标。这就是开源世界的希格斯玻色子。 + +-------------------------------------------------------------------------------- + +via: https://www.linux.com/blog/2018/5/how-cern-using-linux-open-source + +作者:[SWAPNIL BHARTIYA][a] +译者:[jessie-pang](https://github.com/jessie-pang) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.linux.com/users/arnieswap +[1]:https://www.linux.com/licenses/category/used-permission +[2]:https://www.linux.com/licenses/category/used-permission +[3]:https://home.cern/about/experiments/atlas +[4]:https://www.linux.com/files/images/tim-bell-cernpng +[5]:https://www.linux.com/files/images/atlas-cernjpg +[6]:https://home.cern/ +[7]:https://home.cern/topics/higgs-boson +[8]:https://home.cern/about/computing +[9]:https://www.scientificlinux.org/ \ No newline at end of file diff --git a/published/201808/20180607 Find If A Package Is Available For Your Linux Distribution.md b/published/201808/20180607 Find If A Package Is Available For Your Linux Distribution.md new file mode 100644 index 0000000000..1f1e33ac3e --- /dev/null +++ b/published/201808/20180607 Find If A Package Is Available For Your Linux Distribution.md @@ -0,0 +1,154 @@ + +如何确定你的Linux发行版中有没有某个软件包 +====== + +![](https://www.ostechnix.com/wp-content/uploads/2018/06/Whohas-720x340.png) + + +有时,你可能会想知道如何在你的 Linux 发行版上寻找一个特定的软件包。或者,你仅仅只是想知道安装在你的 Linux 上的软件包有什么版本。如果这就是你想知道的信息,你今天走运了。我正好知道一个小工具能帮你抓到上述信息,下面隆重推荐—— Whohas:这是一个命令行工具,它能一次查询好几个软件包列表,以检查的你软件包是否存在。目前,whohas 支持 Arch、Debian、Fedora、Gentoo、Mandriva、openSUSE、Slackware、Source Mage、Ubuntu、FreeBSD、NetBSD、OpenBSD(LCTT 译注:*BSD 不是 Linux)、Fink、MacPorts 和 Cygwin。使用这个小工具,软件包的维护者能轻而易举从别的 Linux 发行版里找到 ebuilds、 pkgbuilds 等等类似的包定义文件。 + +Whohas 是用 Perl 语言开发的自由、开源的工具。 + +### 在你的 Linux 中寻找一个特定的包 + +#### 安装 Whohas + +Whohas 在 Debian、Ubuntu、Linux Mint 的默认软件仓库里提供。如果你正在使用某种基于 DEB 的系统,你可以用如下命令安装: + +``` +$ sudo apt-get install whohas +``` + +对基于 Arch 的系统,[AUR][1] 里就有提供 whohas。你能使用任何的 AUR 助手程序来安装。 + +使用 [Packer][2]: + +``` +$ packer -S whohas +``` + +或使用[Trizen][3]: + +``` +$ trizen -S whohas +``` + +使用[Yay][4]: + +``` +$ yay -S whohas +``` + +使用 [Yaourt][5]: + +``` +$ yaourt -S whohas +``` + +在别的 Linux 发行版上,从[这里][6]下载源代码并手工编译安装。 + +#### 使用方法 + +Whohas 的主要目标是想让你知道: + +* 哪个 Linux 发布版提供了用户依赖的包。 +* 对于各个 Linux 发行版,指定的软件包是什么版本,或者在这个 Linux 发行版的各个不同版本上,指定的软件包是什么版本。 + +让我们试试看上面的的功能,比如说,哪个 Linux 发行版里有 vim 这个软件?我们可以运行如下命令: + +``` +$ whohas vim +``` + + +这个命令将会显示所有包含可安装的 vim 的 Linux 发行版的信息,包括包的大小,仓库地址和下载URL。 + +![][8] + +你甚至可以通过管道将输出的结果按照发行版的字母排序,只需加入 `sort` 命令即可。 + +``` +$ whohas vim | sort +``` + +请注意上述命令将会显示所有以 vim 开头的软件包,包括 vim-spell、vimcommander、vimpager 等等。你可以继续使用 Linux 的 `grep` 命令在 “vim” 的前后加上空格来缩小你的搜索范围,直到满意为止。 + +``` +$ whohas vim | sort | grep " vim" +$ whohas vim | sort | grep "vim " +$ whohas vim | sort | grep " vim " +``` + +所有将空格放在包名字前面的搜索将会显示以包名字结尾的包。所有将空格放在包名字后面的搜索将会显示以包名字开头的包。前后都有空格将会严格匹配。 + +又或者,你就使用 `--strict` 来严格限制结果。 + +``` +$ whohas --strict vim +``` + +有时,你想知道一个包在不在一个特定的 Linux 发行版里。例如,你想知道 vim 是否在 Arch Linux 里,请运行: + +``` +$ whohas vim | grep "^Arch" +``` + +(LCTT译注:在结果里搜索以 Arch 开头的 Linux) + +Linux 发行版的命名缩写为:'archlinux'、'cygwin'、'debian'、'fedora'、 'fink'、'freebsd'、'gentoo'、'mandriva'、'macports'、'netbsd'、'openbsd'、'opensuse'、'slackware'、'sourcemage' 和 'ubuntu'。 + +你也可以用 `-d` 选项来得到同样的结果。 + +``` +$ whohas -d archlinux vim +``` + +这个命令将在仅仅 Arch Linux 发行版下搜索 vim 包。 + +如果要在多个 Linux 发行版下搜索,如 'archlinux'、'ubuntu',请使用如下命令。 + +``` +$ whohas -d archlinux,ubuntu vim +``` + + +你甚至可以用 `whohas` 来查找哪个发行版有 whohas 包。 + +``` +$ whohas whohas +``` + +更详细的信息,请参照手册。 + +``` +$ man whohas +``` + +#### 最后的话 + +当然,任何一个 Linux 发行版的包管理器都能轻松的在对应的软件仓库里找到自己管理的包。不过,whohas 帮你整合并比较了在不同的 Linux 发行版下指定的软件包信息,这样你能轻易的跨平台之间进行比较。试一下 whohas,你一定不会失望的。 + +好了,今天就到这里吧,希望前面讲的对你有用,下次我还会带来更多好东西!! + +欧耶! + +-------------------------------------------------------------------------------- + +via: https://www.ostechnix.com/find-if-a-package-is-available-for-your-linux-distribution/ + +作者:[SK][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[DavidChenLiang](https://github.com/davidchenliang) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.ostechnix.com/author/sk/ +[1]:https://aur.archlinux.org/packages/whohas/ +[2]:https://www.ostechnix.com/install-packer-arch-linux-2/ +[3]:https://www.ostechnix.com/trizen-lightweight-aur-package-manager-arch-based-systems/ +[4]:https://www.ostechnix.com/yay-found-yet-another-reliable-aur-helper/ +[5]:https://www.ostechnix.com/install-yaourt-arch-linux/ +[6]:http://www.philippwesche.org/200811/whohas/intro.html +[7]:data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7 +[8]:http://www.ostechnix.com/wp-content/uploads/2018/06/whohas-1.png diff --git a/published/201808/20180607 Using MQTT to send and receive data for your next project.md b/published/201808/20180607 Using MQTT to send and receive data for your next project.md new file mode 100644 index 0000000000..d84ce5db55 --- /dev/null +++ b/published/201808/20180607 Using MQTT to send and receive data for your next project.md @@ -0,0 +1,254 @@ +使用 MQTT 在项目中实现数据收发 +====== + +> 从开源数据到开源事件流,了解一下 MQTT 发布/订阅(pubsub)线路协议。 + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/toolbox-learn-draw-container-yearbook.png?itok=xDbwz1pP) + +去年 11 月我们购买了一辆电动汽车,同时也引发了有趣的思考:我们应该什么时候为电动汽车充电?对于电动汽车充电所用的电,我希望能够对应最小的二氧化碳排放,归结为一个特定的问题:对于任意给定时刻,每千瓦时对应的二氧化碳排放量是多少,一天中什么时间这个值最低? + +### 寻找数据 + +我住在纽约州,大约 80% 的电力消耗可以自给自足,主要来自天然气、水坝(大部分来自于尼亚加拉Niagara大瀑布)、核能发电,少部分来自风力、太阳能和其它化石燃料发电。非盈利性组织 [纽约独立电网运营商New York Independent System Operator][1] (NYISO)负责整个系统的运作,实现发电机组发电与用电之间的平衡,同时也是纽约路灯系统的监管部门。 + +尽管没有为公众提供公开 API,NYISO 还是尽责提供了[不少公开数据][2]供公众使用。每隔 5 分钟汇报全州各个发电机组消耗的燃料数据。数据以 CSV 文件的形式发布于公开的档案库中,全天更新。如果你了解不同燃料对发电瓦数的贡献比例,你可以比较准确的估计任意时刻的二氧化碳排放情况。 + +在构建收集处理公开数据的工具时,我们应该时刻避免过度使用这些资源。相比将这些数据打包并发送给所有人,我们有更好的方案。我们可以创建一个低开销的事件流event stream,人们可以订阅并第一时间得到消息。我们可以使用 [MQTT][3] 实现该方案。我的项目([ny-power.org][4])目标是收录到 [Home Assistant][5] 项目中;后者是一个开源的家庭自动化home automation平台,拥有数十万用户。如果所有用户同时访问 CSV 文件服务器,估计 NYISO 不得不增加访问限制。 + +### MQTT 是什么? + +MQTT 是一个发布订阅线路协议publish/subscription wire protocol,为小规模设备设计。发布订阅系统工作原理类似于消息总线。你将一条消息发布到一个主题topic上,那么所有订阅了该主题的客户端都可以获得该消息的一份拷贝。对于消息发送者而言,无需知道哪些人在订阅消息;你只需将消息发布到一系列主题,并订阅一些你感兴趣的主题。就像参加了一场聚会,你选取并加入感兴趣的对话。 + +MQTT 能够构建极为高效的应用。客户端订阅有限的几个主题,也只收到它们感兴趣的内容。不仅节省了处理时间,还降低了网络带宽使用。 + +作为一个开放标准,MQTT 有很多开源的客户端和服务端实现。对于你能想到的每种编程语言,都有对应的客户端库;甚至有嵌入到 Arduino 的库,可以构建传感器网络。服务端可供选择的也很多,我的选择是 Eclipse 项目提供的 [Mosquitto][6] 服务端,这是因为它体积小、用 C 编写,可以承载数以万计的订阅者。 + +### 为何我喜爱 MQTT + +在过去二十年间,我们为软件应用设计了可靠且准确的模型,用于解决服务遇到的问题。我还有其它邮件吗?当前的天气情况如何?我应该此刻购买这种产品吗?在绝大多数情况下,这种问答式ask/receive的模型工作良好;但对于一个数据爆炸的世界,我们需要其它的模型。MQTT 的发布订阅模型十分强大,可以将大量数据发送到系统中。客户可以订阅数据中的一小部分并在订阅数据发布的第一时间收到更新。 + +MQTT 还有一些有趣的特性,其中之一是遗嘱last-will-and-testament消息,可以用于区分两种不同的静默,一种是没有主题相关数据推送,另一种是你的数据接收器出现故障。MQTT 还包括保留消息retained message,当客户端初次连接时会提供相关主题的最后一条消息。这对那些更新缓慢的主题来说很有必要。 + +我在 Home Assistant 项目开发过程中,发现这种消息总线模型对异构系统heterogeneous systems尤为适合。如果你深入物联网Internet of Things领域,你会发现 MQTT 无处不在。 + +### 我们的第一个 MQTT 流 + +NYSO 公布的 CSV 文件中有一个是实时的燃料混合使用情况。每 5 分钟,NYSO 发布这 5 分钟内发电使用的燃料类型和相应的发电量(以兆瓦为单位)。 + +这个 CSV 文件看起来像这样: + +| 时间戳 | 时区 | 燃料类型 | 兆瓦为单位的发电量 | +| --- | --- | --- | --- | +| 05/09/2018 00:05:00 | EDT | 混合燃料 | 1400 | +| 05/09/2018 00:05:00 | EDT | 天然气 | 2144 | +| 05/09/2018 00:05:00 | EDT | 核能 | 4114 | +| 05/09/2018 00:05:00 | EDT | 其它化石燃料 | 4 | +| 05/09/2018 00:05:00 | EDT | 其它可再生资源 | 226 | +| 05/09/2018 00:05:00 | EDT | 风力 | 1 | +| 05/09/2018 00:05:00 | EDT | 水力 | 3229 | +| 05/09/2018 00:10:00 | EDT | 混合燃料 | 1307 | +| 05/09/2018 00:10:00 | EDT | 天然气 | 2092 | +| 05/09/2018 00:10:00 | EDT | 核能 | 4115 | +| 05/09/2018 00:10:00 | EDT | 其它化石燃料 | 4 | +| 05/09/2018 00:10:00 | EDT | 其它可再生资源 | 224 | +| 05/09/2018 00:10:00 | EDT | 风力 | 40 | +| 05/09/2018 00:10:00 | EDT | 水力 | 3166 | + +表中唯一令人不解就是燃料类别中的混合燃料。纽约的大多数天然气工厂也通过燃烧其它类型的化石燃料发电。在冬季寒潮到来之际,家庭供暖的优先级高于发电;但这种情况出现的次数不多,(在我们计算中)可以将混合燃料类型看作天然气类型。 + +CSV 文件全天更新。我编写了一个简单的数据泵,每隔 1 分钟检查是否有数据更新,并将新条目发布到 MQTT 服务器的一系列主题上,主题名称基本与 CSV 文件有一定的对应关系。数据内容被转换为 JSON 对象,方便各种编程语言处理。 + +``` +ny-power/upstream/fuel-mix/Hydro {"units": "MW", "value": 3229, "ts": "05/09/2018 00:05:00"} +ny-power/upstream/fuel-mix/Dual Fuel {"units": "MW", "value": 1400, "ts": "05/09/2018 00:05:00"} +ny-power/upstream/fuel-mix/Natural Gas {"units": "MW", "value": 2144, "ts": "05/09/2018 00:05:00"} +ny-power/upstream/fuel-mix/Other Fossil Fuels {"units": "MW", "value": 4, "ts": "05/09/2018 00:05:00"} +ny-power/upstream/fuel-mix/Wind {"units": "MW", "value": 41, "ts": "05/09/2018 00:05:00"} +ny-power/upstream/fuel-mix/Other Renewables {"units": "MW", "value": 226, "ts": "05/09/2018 00:05:00"} +ny-power/upstream/fuel-mix/Nuclear {"units": "MW", "value": 4114, "ts": "05/09/2018 00:05:00"} +``` + +这种直接的转换是种不错的尝试,可将公开数据转换为公开事件。我们后续会继续将数据转换为二氧化碳排放强度,但这些原始数据还可被其它应用使用,用于其它计算用途。 + +### MQTT 主题 + +主题和主题结构topic structure是 MQTT 的一个主要特色。与其它标准的企业级消息总线不同,MQTT 的主题无需事先注册。发送者可以凭空创建主题,唯一的限制是主题的长度,不超过 220 字符。其中 `/` 字符有特殊含义,用于创建主题的层次结构。我们即将看到,你可以订阅这些层次中的一些分片。 + +基于开箱即用的 Mosquitto,任何一个客户端都可以向任何主题发布消息。在原型设计过程中,这种方式十分便利;但一旦部署到生产环境,你需要增加访问控制列表access control list(ACL)只允许授权的应用发布消息。例如,任何人都能以只读的方式访问我的应用的主题层级,但只有那些具有特定凭证credentials的客户端可以发布内容。 + +主题中不包含自动样式automatic schema,也没有方法查找客户端可以发布的全部主题。因此,对于那些从 MQTT 总线消费数据的应用,你需要让其直接使用已知的主题和消息格式样式。 + +那么应该如何设计主题呢?最佳实践包括使用应用相关的根名称,例如在我的应用中使用 `ny-power`。接着,为提高订阅效率,构建足够深的层次结构。`upstream` 层次结构包含了直接从数据源获取的、不经处理的原始数据,而 `fuel-mix` 层次结构包含特定类型的数据;我们后续还可以增加其它的层次结构。 + +### 订阅主题 + +在 MQTT 中,订阅仅仅是简单的字符串匹配。为提高处理效率,只允许如下两种通配符: + + * `#` 以递归方式匹配,直到字符串结束 + * `+` 匹配下一个 `/` 之前的内容 + +为便于理解,下面给出几个例子: + +``` +ny-power/#  - 匹配 ny-power 应用发布的全部主题 +ny-power/upstream/#  - 匹配全部原始数据的主题 +ny-power/upstream/fuel-mix/+  - 匹配全部燃料类型的主题 +ny-power/+/+/Hydro - 匹配全部两次层级之后为 Hydro 类型的主题(即使不位于 upstream 层次结构下) +``` + +类似 `ny-power/#` 的大范围订阅适用于低数据量low-volume的应用,应用从网络获取全部数据并处理。但对高数据量high-volume应用而言则是一个灾难,由于绝大多数消息并不会被使用,大部分的网络带宽被白白浪费了。 + +在大数据量情况下,为确保性能,应用需要使用恰当的主题筛选(如 `ny-power/+/+/Hydro`)尽量准确获取业务所需的数据。 + +### 增加我们自己的数据层次 + +接下来,应用中的一切都依赖于已有的 MQTT 流并构建新流。第一个额外的数据层用于计算发电对应的二氧化碳排放。 + +利用[美国能源情报署U.S. Energy Information Administration][7] 给出的 2016 年纽约各类燃料发电及排放情况,我们可以给出各类燃料的[平均排放率][8],单位为克/兆瓦时。 + +上述结果被封装到一个专用的微服务中。该微服务订阅 `ny-power/upstream/fuel-mix/+`,即数据泵中燃料组成情况的原始数据,接着完成计算并将结果(单位为克/千瓦时)发布到新的主题层次结构上: + +``` +ny-power/computed/co2 {"units": "g / kWh", "value": 152.9486, "ts": "05/09/2018 00:05:00"} +``` + +接着,另一个服务会订阅该主题层次结构并将数据打包到 [InfluxDB][9] 进程中;同时,发布 24 小时内的时间序列数据到 `ny-power/archive/co2/24h` 主题,这样可以大大简化当前变化数据的绘制。 + +这种层次结构的主题模型效果不错,可以将上述程序之间的逻辑解耦合。在复杂系统中,各个组件可能使用不同的编程语言,但这并不重要,因为交换格式都是 MQTT 消息,即主题和 JSON 格式的消息内容。 + +### 从终端消费数据 + +为了更好的了解 MQTT 完成了什么工作,将其绑定到一个消息总线并查看消息流是个不错的方法。`mosquitto-clients` 包中的 `mosquitto_sub` 可以让我们轻松实现该目标。 + +安装程序后,你需要提供服务器名称以及你要订阅的主题。如果有需要,使用参数 `-v` 可以让你看到有新消息发布的那些主题;否则,你只能看到主题内的消息数据。 + +``` +mosquitto_sub -h mqtt.ny-power.org -t ny-power/# -v +``` + +只要我编写或调试 MQTT 应用,我总会在一个终端中运行 `mosquitto_sub`。 + +### 从网页直接访问 MQTT + +到目前为止,我们已经有提供公开事件流的应用,可以用微服务或命令行工具访问该应用。但考虑到互联网仍占据主导地位,因此让用户可以从浏览器直接获取事件流是很重要。 + +MQTT 的设计者已经考虑到了这一点。协议标准支持三种不同的传输协议:[TCP][10]、[UDP][11] 和 [WebSockets][12]。主流浏览器都支持 WebSockets,可以维持持久连接,用于实时应用。 + +Eclipse 项目提供了 MQTT 的一个 JavaScript 实现,叫做 [Paho][13],可包含在你的应用中。工作模式为与服务器建立连接、建立一些订阅,然后根据接收到的消息进行响应。 + +``` +// ny-power web console application + +var client = new Paho.MQTT.Client(mqttHost, Number("80"), "client-" + Math.random()); + +// set callback handlers +client.onMessageArrived = onMessageArrived; + +// connect the client +client.reconnect = true; +client.connect({onSuccess: onConnect}); + +// called when the client connects +function onConnect() { +    // Once a connection has been made, make a subscription and send a message. +    console.log("onConnect"); +    client.subscribe("ny-power/computed/co2"); +    client.subscribe("ny-power/archive/co2/24h"); +    client.subscribe("ny-power/upstream/fuel-mix/#"); +} + +// called when a message arrives +function onMessageArrived(message) { +    console.log("onMessageArrived:"+message.destinationName + message.payloadString); +    if (message.destinationName == "ny-power/computed/co2") { +        var data = JSON.parse(message.payloadString); +        $("#co2-per-kwh").html(Math.round(data.value)); +        $("#co2-units").html(data.units); +        $("#co2-updated").html(data.ts); +    } + +    if (message.destinationName.startsWith("ny-power/upstream/fuel-mix")) { +        fuel_mix_graph(message); +    } + +    if (message.destinationName == "ny-power/archive/co2/24h") { +        var data = JSON.parse(message.payloadString); +        var plot = [ +            { +                x: data.ts, +                y: data.values, +                type: 'scatter' +            } +        ]; +        var layout = { +            yaxis: { +                title: "g CO2 / kWh", +            } +        }; +        Plotly.newPlot('co2_graph', plot, layout); +    } +``` + +上述应用订阅了不少主题,因为我们将要呈现若干种不同类型的数据;其中 `ny-power/computed/co2` 主题为我们提供当前二氧化碳排放的参考值。一旦收到该主题的新消息,网站上的相应内容会被相应替换。 + +![NYISO 二氧化碳排放图][15] + +*[ny-power.org][4] 网站提供的 NYISO 二氧化碳排放图。* + +`ny-power/archive/co2/24h` 主题提供了时间序列数据,用于为 [Plotly][16] 线表提供数据。`ny-power/upstream/fuel-mix` 主题提供当前燃料组成情况,为漂亮的柱状图提供数据。 + +![NYISO 燃料组成情况][18] + +*[ny-power.org][4] 网站提供的燃料组成情况。* + +这是一个动态网站,数据不从服务器拉取,而是结合 MQTT 消息总线,监听对外开放的 WebSocket。就像数据泵和打包器程序那样,网站页面也是一个发布订阅客户端,只不过是在你的浏览器中执行,而不是在公有云的微服务上。 + +你可以在 站点点看到动态变更,包括图像和可以看到消息到达的实时 MQTT 终端。 + +### 继续深入 + +ny-power.org 应用的完整内容开源在 [GitHub][19] 中。你也可以查阅 [架构简介][20],学习如何使用 [Helm][21] 部署一系列 Kubernetes 微服务构建应用。另一个有趣的 MQTT 示例使用 MQTT 和 OpenWhisk 进行实时文本消息翻译,代码模式code pattern参考[链接][22]。 + +MQTT 被广泛应用于物联网领域,更多关于 MQTT 用途的例子可以在 [Home Assistant][23] 项目中找到。 + +如果你希望深入了解协议内容,可以从 [mqtt.org][3] 获得该公开标准的全部细节。 + +想了解更多,可以参加 Sean Dague 在 [OSCON][25] 上的演讲,主题为 [将 MQTT 加入到你的工具箱][24],会议将于 7 月 16-19 日在奥尔良州波特兰举办。 + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/6/mqtt + +作者:[Sean Dague][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[pinewall](https://github.com/pinewall) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://opensource.com/users/sdague +[1]:http://www.nyiso.com/public/index.jsp +[2]:http://www.nyiso.com/public/markets_operations/market_data/reports_info/index.jsp +[3]:http://mqtt.org/ +[4]:http://ny-power.org/# +[5]:https://www.home-assistant.io +[6]:https://mosquitto.org/ +[7]:https://www.eia.gov/ +[8]:https://github.com/IBM/ny-power/blob/master/src/nypower/calc.py#L1-L60 +[9]:https://www.influxdata.com/ +[10]:https://en.wikipedia.org/wiki/Transmission_Control_Protocol +[11]:https://en.wikipedia.org/wiki/User_Datagram_Protocol +[12]:https://en.wikipedia.org/wiki/WebSocket +[13]:https://www.eclipse.org/paho/ +[14]:/file/400041 +[15]:https://opensource.com/sites/default/files/uploads/mqtt_nyiso-co2intensity.png (NY ISO Grid CO2 Intensity) +[16]:https://plot.ly/ +[17]:/file/400046 +[18]:https://opensource.com/sites/default/files/uploads/mqtt_nyiso_fuel-mix.png (Fuel mix on NYISO grid) +[19]:https://github.com/IBM/ny-power +[20]:https://developer.ibm.com/code/patterns/use-mqtt-stream-real-time-data/ +[21]:https://helm.sh/ +[22]:https://developer.ibm.com/code/patterns/deploy-serverless-multilingual-conference-room/ +[23]:https://www.home-assistant.io/ +[24]:https://conferences.oreilly.com/oscon/oscon-or/public/schedule/speaker/77317 +[25]:https://conferences.oreilly.com/oscon/oscon-or diff --git a/published/201808/20180609 Anatomy of a Linux DNS Lookup - Part I.md b/published/201808/20180609 Anatomy of a Linux DNS Lookup - Part I.md new file mode 100644 index 0000000000..a72a088a31 --- /dev/null +++ b/published/201808/20180609 Anatomy of a Linux DNS Lookup - Part I.md @@ -0,0 +1,263 @@ +Linux DNS 查询剖析(第一部分) +====== + +我经常与虚拟机集群打交道([文1][3]、[文2][4]、[文3][5]、[文4][6]、[文5][7]、[文6][8]),因此最终花费了大量时间试图掌握 [DNS 查询][9]的工作原理。遇到问题时,我只是不求甚解的使用 StackOverflow 上的“解决方案”,而不知道它们为什么有时工作,有时不工作。 + +最终我对此感到了厌倦,决定一并找出所有问题的原因。我没有在网上找到完整的指南,我问过一些同事,他们不知所以然(或许是问题太具体了)。 + +既然如此,我开始自己写这样的手册。 + +结果发现,“Linux 执行一次 DNS 查询”这句话的背后有相当多的工作。 + +![linux-dns-0](https://zwischenzugs.files.wordpress.com/2018/06/linux-dns-0.png?w=121) + +_“究竟有多难呢?”_ + +**本系列文章试图将 Linux 主机上程序获取(域名对应的) IP 地址的过程及期间涉及的组件进行分块剖析。**如果不理解这些块的协同工作方式,调试解决 `dnsmasq`、`vagrant landrush` 和 `resolvconf` 等相关的问题会让人感到眼花缭乱。 + +同时这也是一份有价值的说明,指出原本很简单的东西是如何随着时间的推移变得相当复杂。在弄清楚 DNS 查询的原理的过程中,我了解了大量不同的技术及其发展历程。 + +我甚至编写了一些[自动化脚本][10],可以让我在虚拟机中进行实验。欢迎读者参与贡献或勘误。 + +**请注意,本系列主题并不是“DNS 工作原理”**,而是与查询 Linux 主机配置的真实 DNS 服务器(这里假设查询了一台 DNS 服务器,但后面你会看到有时并不需要)相关的内容,以及如何确定使用哪个查询结果,或者如何使用其它方式确定 IP 地址。 + +### 1) 其实并没有名为“DNS 查询”的系统调用 + +![linux-dns-1](https://zwischenzugs.files.wordpress.com/2018/06/linux-dns-1.png?w=121) + +_工作方式并非如此_ + +**首先要了解的一点是,Linux 上并没有一个单独的方法可以完成 DNS 查询工作**;没有一个有这样的明确接口的核心系统调用system call。 + +不过,有一个标准 C 库函数调用 [`getaddrinfo`][2],不少程序使用了该调用;但不是所有程序或应用都使用该调用! + +让我们看一下两个简单的标准程序:`ping` 和 `host`: + +``` +root@linuxdns1:~# ping -c1 bbc.co.uk | head -1 +PING bbc.co.uk (151.101.192.81) 56(84) bytes of data. +``` + +``` +root@linuxdns1:~# host bbc.co.uk | head -1 +bbc.co.uk has address 151.101.192.81 +``` + +对于同一个域名,两个程序得到的 IP 地址是相同的;那么它们是使用同样的方法得到结果的吧? + +事实并非如此。 + +下面文件给出了我主机上 `ping` 对应的 DNS 相关的系统调用: + +``` +root@linuxdns1:~# strace -e trace=open -f ping -c1 google.com +open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3 +open("/lib/x86_64-linux-gnu/libcap.so.2", O_RDONLY|O_CLOEXEC) = 3 +open("/lib/x86_64-linux-gnu/libc.so.6", O_RDONLY|O_CLOEXEC) = 3 +open("/etc/resolv.conf", O_RDONLY|O_CLOEXEC) = 4 +open("/etc/resolv.conf", O_RDONLY|O_CLOEXEC) = 4 +open("/etc/nsswitch.conf", O_RDONLY|O_CLOEXEC) = 4 +open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 4 +open("/lib/x86_64-linux-gnu/libnss_files.so.2", O_RDONLY|O_CLOEXEC) = 4 +open("/etc/host.conf", O_RDONLY|O_CLOEXEC) = 4 +open("/etc/hosts", O_RDONLY|O_CLOEXEC)  = 4 +open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 4 +open("/lib/x86_64-linux-gnu/libnss_dns.so.2", O_RDONLY|O_CLOEXEC) = 4 +open("/lib/x86_64-linux-gnu/libresolv.so.2", O_RDONLY|O_CLOEXEC) = 4 +PING google.com (216.58.204.46) 56(84) bytes of data. +open("/etc/hosts", O_RDONLY|O_CLOEXEC)  = 4 +64 bytes from lhr25s12-in-f14.1e100.net (216.58.204.46): icmp_seq=1 ttl=63 time=13.0 ms +[...] +``` + +下面是 `host` 对应的系统调用: + +``` +$ strace -e trace=open -f host google.com +[...] +[pid  9869] open("/usr/share/locale/en_US.UTF-8/LC_MESSAGES/libdst.cat", O_RDONLY) = -1 ENOENT (No such file or directory) +[pid  9869] open("/usr/share/locale/en/libdst.cat", O_RDONLY) = -1 ENOENT (No such file or directory) +[pid  9869] open("/usr/share/locale/en/LC_MESSAGES/libdst.cat", O_RDONLY) = -1 ENOENT (No such file or directory) +[pid  9869] open("/usr/lib/ssl/openssl.cnf", O_RDONLY) = 6 +[pid  9869] open("/usr/lib/x86_64-linux-gnu/openssl-1.0.0/engines/libgost.so", O_RDONLY|O_CLOEXEC) = 6[pid  9869] open("/etc/resolv.conf", O_RDONLY) = 6 +google.com has address 216.58.204.46 +[...] +``` + +可以看出 `ping` 打开了 `nsswitch.conf` 文件,但 `host` 没有;但两个程序都打开了 `/etc/resolv.conf` 文件。 + +下面我们依次查看这两个 `.conf` 扩展名的文件。 + +### 2) NSSwitch 与 `/etc/nsswitch.conf` + +我们已经确认应用可以自主决定选用哪个 DNS 服务器。很多应用(例如 `ping`)通过配置文件 `/etc/nsswitch.conf` (根据具体实现[^1] )参考 NSSwitch 完成选择。 + +[^1]: `ping` 实现的变种之多令人惊叹。我 _不_ 希望在这里讨论过多。 + +NSSwitch 不仅用于 DNS 查询,例如,还用于密码与用户信息查询。 + +NSSwitch 最初是 Solaris OS 的一部分,可以让应用无需硬编码查询所需的文件或服务,而是在其它集中式的、无需应用开发人员管理的配置文件中找到。 + +下面是我的 `nsswitch.conf`: + +``` +passwd:         compat +group:          compat +shadow:         compat +gshadow:        files +hosts: files dns myhostname +networks:       files +protocols:      db files +services:       db files +ethers:         db files +rpc:            db files +netgroup:       nis +``` + +我们需要关注的是 `hosts` 行。我们知道 `ping` 用到 `nsswitch.conf` 文件,那么我们修改这个文件(的 `hosts` 行),看看能够如何影响 `ping`。 + +#### 修改 `nsswitch.conf`, `hosts` 行仅保留 `files` + +如果你修改 `nsswitch.conf`,将 `hosts` 行仅保留 `files`: + +``` +hosts: files +``` + +此时, `ping` 无法获取 google.com 对应的 IP 地址: + +``` +$ ping -c1 google.com +ping: unknown host google.com +``` + +但 `localhost` 的解析不受影响: + +``` +$ ping -c1 localhost +PING localhost (127.0.0.1) 56(84) bytes of data. +64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.039 ms +``` + +此外,`host` 命令正常返回: + +``` +$ host google.com +google.com has address 216.58.206.110 +``` + +毕竟如我们之前看到的那样,`host` 不受 `nsswitch.conf` 影响。 + +#### 修改 `nsswitch.conf`, `hosts` 行仅保留 `dns` + +如果你修改 `nsswitch.conf`,将 `hosts` 行仅保留 `dns`: + +``` +hosts: dns +``` + +此时,google.com 的解析恢复正常: + +``` +$ ping -c1 google.com +PING google.com (216.58.198.174) 56(84) bytes of data. +64 bytes from lhr25s10-in-f174.1e100.net (216.58.198.174): icmp_seq=1 ttl=63 time=8.01 ms +``` + +但 `localhost` 无法解析: + +``` +$ ping -c1 localhost +ping: unknown host localhost +``` + +下图给出默认 NSSwitch 中 `hosts` 行对应的查询逻辑: + +![linux-dns-2 (1)](https://zwischenzugs.files.wordpress.com/2018/06/linux-dns-2-11.png?w=525) + +_我的 `hosts:` 配置是 `nsswitch.conf` 给出的默认值_ + +### 3) `/etc/resolv.conf` + +我们已经知道 `host` 和 `ping` 都使用 `/etc/resolv.conf` 文件。 + +下面给出我主机的 `/etc/resolv.conf` 文件内容: + +``` +# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8) +#     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN +nameserver 10.0.2.3 +``` + +先忽略前两行,后面我们会回过头来看这部分(它们很重要,但你还需要一些知识储备)。 + +其中 `nameserver` 行指定了查询用到的 DNS 服务器。 + +如果将该行注释掉: + +``` +#nameserver 10.0.2.3 +``` + +再次运行: + +``` +$ ping -c1 google.com +ping: unknown host google.com +``` + +解析失败了,这是因为没有可用的名字服务器 [^2]。 + +[^2]: 另一个需要注意的地方: `host` 在没有指定 nameserver 的情况下会尝试 127.0.0.1:53。 + +该文件中还可以使用其它选项。例如,你可以在 `resolv.conf` 文件中增加如下行: + +``` +search com +``` + +然后执行 `ping google` (不写 `.com`) + +``` +$ ping google +PING google.com (216.58.204.14) 56(84) bytes of data. +``` + +程序会自动为你尝试 `.com` 域。 + +### 第一部分总结 + +第一部分到此结束,下一部分我们会了解 `resolv.conf` 文件是如何创建和更新的。 + +下面总结第一部分涵盖的内容: + +* 操作系统中并不存在“DNS 查询”这个系统调用 +* 不同程序可能采用不同的策略获取名字对应的 IP 地址 + * 例如, `ping` 使用 `nsswitch`,后者进而使用(或可以使用) `/etc/hosts`、`/etc/resolv.conf` 以及主机名得到解析结果 +* `/etc/resolv.conf` 用于决定: + * 查询什么地址(LCTT 译注:这里可能指 `search` 带来的影响) + * 使用什么 DNS 服务器执行查询 + +如果你曾认为 DNS 查询很复杂,请跟随这个系列学习吧。 + +-------------------------------------------------------------------------------- + +via: https://zwischenzugs.com/2018/06/08/anatomy-of-a-linux-dns-lookup-part-i/ + +作者:[dmatech][a] +译者:[pinewall](https://github.com/pinewall) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://twitter.com/dmatech2 +[1]:https://zwischenzugs.com/2018/06/18/anatomy-of-a-linux-dns-lookup-part-ii/ +[2]:http://man7.org/linux/man-pages/man3/getaddrinfo.3.html +[3]:https://zwischenzugs.com/2017/10/31/a-complete-chef-infrastructure-on-your-laptop/ +[4]:https://zwischenzugs.com/2017/03/04/a-complete-openshift-cluster-on-vagrant-step-by-step/ +[5]:https://zwischenzugs.com/2017/03/04/migrating-an-openshift-etcd-cluster/ +[6]:https://zwischenzugs.com/2017/03/04/1-minute-multi-node-vm-setup/ +[7]:https://zwischenzugs.com/2017/03/18/clustered-vm-testing-how-to/ +[8]:https://zwischenzugs.com/2017/10/27/ten-things-i-wish-id-known-before-using-vagrant/ +[9]:https://zwischenzugs.com/2017/10/21/openshift-3-6-dns-in-pictures/ +[10]:https://github.com/ianmiell/shutit-linux-dns/blob/master/linux_dns.py diff --git a/published/201808/20180615 5 Commands for Checking Memory Usage in Linux.md b/published/201808/20180615 5 Commands for Checking Memory Usage in Linux.md new file mode 100644 index 0000000000..c2d546bc8c --- /dev/null +++ b/published/201808/20180615 5 Commands for Checking Memory Usage in Linux.md @@ -0,0 +1,156 @@ +用以检查 Linux 内存使用的 5 个命令 +====== + +> 对于 Linux 管理员来说,检查系统内存用量是一个重要的技能。Jack 给出了解决这个问题的五种不同方式。 + +![](https://www.linux.com/sites/lcom/files/styles/rendered_file/public/top-main.jpg?itok=WYAw6yJ1) + +Linux 操作系统包含大量工具,所有这些工具都可以帮助你管理系统。从简单的文件和目录工具到非常复杂的安全命令,在 Linux 中没有多少是你做不了的。而且,尽管普通桌面用户可能不需要在命令行熟悉这些工具,但对于 Linux 管理员来说,它们是必需的。为什么?首先,你在某些时候不得不使用没有 GUI 的 Linux 服务器。其次,命令行工具通常比 GUI 替代工具提供更多的功能和灵活性。 + +确定内存使用情况是你可能需要的技能,尤其是某个应用程序变得异常和占用系统内存时。当发生这种情况时,知道有多种工具可以帮助你进行故障排除十分方便的。或者,你可能需要收集有关 Linux 交换分区的信息,或者有关安装的内存的详细信息?对于这些也有相应的命令。让我们深入了解各种 Linux 命令行工具,以帮助你检查系统内存使用情况。这些工具并不是非常难以使用,在本文中,我将向你展示五种不同的方法来解决这个问题。 + +我将在 [Ubuntu 18.04 服务器平台][1]上进行演示,但是你应该在你选择的发行版中找到对应的所有命令。更妙的是,你不需要安装任何东西(因为大多数这些工具都包含 Linux 系统中)。 + +话虽如此,让我们开始工作吧。 + +### top + +我想从最常用的工具开始。`top` 命令提供正在运行的系统的实时动态视图,它检查每个进程的内存使用情况。这非常重要,因为你可以轻松地看到同一命令的多个示例消耗不同的内存量。虽然你无法在没有显示器的服务器上看到这种情况,但是你已经注意到打开 Chrome 使你的系统速度变慢了。运行 `top` 命令以查看 Chrome 有多个进程在运行(每个选项卡一个 - 图 1)。 + +![top][3] + +*图1:top 命令中出现多个 Chrome 进程。* + +Chrome 并不是唯一显示多个进程的应用。你看到图 1 中的 Firefox 了吗?那是 Firefox 的主进程,而 Web Content 进程是其打开的选项卡。在输出的顶部,你将看到系统统计信息。在我的机器上([System76 Leopard Extreme][5]),我总共有 16GB 可用 RAM,其中只有超过 10GB 的 RAM 正在使用中。然后,你可以整理该列表,查看每个进程使用的内存百分比。 + +`top` 最好的地方之一就是发现可能已经失控的服务的进程 ID 号(PID)。有了这些 PID,你可以对有问题的任务进行故障排除(或 `kill`)。 + +如果你想让 `top` 显示更友好的内存信息,使用命令 `top -o %MEM`,这会使 `top` 按进程所用内存对所有进程进行排序(图 2)。 + +![top][7] + +*图 2:在 top 命令中按使用内存对进程排序* + +`top` 命令还为你提供有关使用了多少交换空间的实时更新。 + +### free + +然而有时候,`top` 命令可能不能满足你的需求。你可能只需要查看系统的可用和已用内存。对此,Linux 还有 `free` 命令。`free` 命令显示: + +* 可用和已使用的物理内存总量 +* 系统中交换内存的总量 +* 内核使用的缓冲区和缓存 + +在终端窗口中,输入 `free` 命令。它的输出不是实时的,相反,你将获得的是当前空闲和已用内存的即时快照(图 3)。 + +![free][9] + +*图 3 :free 命令的输出简单明了。* + +当然,你可以通过添加 `-m` 选项来让 `free` 显示得更友好一点,就像这样:`free -m`。这将显示内存的使用情况,以 MB 为单位(图 4)。 + +![free][11] + +*图 4:free 命令以一种更易于阅读的形式输出。* + +当然,如果你的系统是很新的,你将希望使用 `-g` 选项(以 GB 为单位),比如 `free -g`。 + +如果你需要知道内存总量,你可以添加 `-t` 选项,比如:`free -mt`。这将简单地计算每列中的内存总量(图 5)。 + +![total][13] + +*图 5:为你提供空闲的内存列。* + +### vmstat + +另一个非常方便的工具是 `vmstat`。这个特殊的命令是一个报告虚拟内存统计信息的小技巧。`vmstat` 命令将报告关于: + +* 进程 +* 内存 +* 分页 +* 阻塞 IO +* 中断 +* 磁盘 +* CPU + +使用 `vmstat` 的最佳方法是使用 `-s` 选项,如 `vmstat -s`。这将在单列中报告统计信息(这比默认报告更容易阅读)。`vmstat` 命令将提供比你需要的更多的信息(图 6),但更多的总是更好的(在这种情况下)。 + +![vmstat][15] + +*图 6:使用 vmstat 命令来检查内存使用情况。* + +### dmidecode + +如果你想找到关于已安装的系统内存的详细信息,该怎么办?为此,你可以使用 `dmidecode` 命令。这个特殊的工具是 DMI 表解码器,它将系统的 DMI 表内容转储成人类可读的格式。如果你不清楚 DMI 表是什么,那么可以这样说,它可以用来描述系统的构成(以及系统的演变)。 + +要运行 `dmidecode` 命令,你需要 `sudo` 权限。因此输入命令 `sudo dmidecode -t 17`。该命令的输出(图 7)可能很长,因为它显示所有内存类型设备的信息。因此,如果你无法上下滚动,则可能需要将该命令的输出发送到一个文件中,比如:`sudo dmidecode -t 17> dmi_infoI`,或将其传递给 `less` 命令,如 `sudo dmidecode | less`。 + +![dmidecode][17] + +*图 7:dmidecode 命令的输出。* + +### /proc/meminfo + +你可能会问自己:“这些命令从哪里获取这些信息?”在某些情况下,它们从 `/proc/meminfo` 文件中获取。猜到了吗?你可以使用命令 `less /proc/meminfo` 直接读取该文件。通过使用 `less` 命令,你可以在长长的输出中向上和向下滚动,以准确找到你需要的内容(图 8)。 + +![/proc/meminfo][19] + +*图 8:less /proc/meminfo 命令的输出。* + +关于 `/proc/meminfo` 你应该知道:这不是一个真实的文件。相反 `/proc/meminfo` 是一个虚拟文件,包含有关系统的实时动态信息。特别是,你需要检查以下值: + + * 全部内存(`MemTotal`) + * 空闲内存(`MemFree`) + * 可用内存(`MemAvailable`) + * 缓冲区(`Buffers`) + * 文件缓存(`Cached`) + * 交换缓存(`SwapCached`) + * 全部交换区(`SwapTotal`) + * 空闲交换区(`SwapFree`) + +如果你想使用 `/proc/meminfo`,你可以连接 egrep 命令使用它:`egrep --color'Mem | Cache | Swap'/proc/meminfo`。这将生成一个易于阅读的列表,其中包含 `Mem`、 `Cache` 和 `Swap` 等内容的条目将是彩色的(图 9)。 + +![/proc/meminfo][21] + +*图 9:让 /proc/meminfo 更容易阅读。* + +### 继续学习 + +你要做的第一件事就是阅读每个命令的手册页(例如 `man top`、`man free`、`man vmstat`、`man dmidecode`)。从命令的手册页开始,对于如何在 Linux 上使用一个工具,它总是一个很好的学习方法。 + +通过 Linux 基金会和 edX 的免费 [“Linux 简介”][22]课程了解有关 Linux 的更多知识。 + +-------------------------------------------------------------------------------- + +via: https://www.linux.com/learn/5-commands-checking-memory-usage-linux + +作者:[Jack Wallen][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[MjSeven](https://github.com/MjSeven) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.linux.com/users/jlwallen +[1]:https://www.ubuntu.com/download/server +[2]:/files/images/memory1jpg +[3]:https://www.linux.com/sites/lcom/files/styles/rendered_file/public/memory_1.jpg?itok=fhhhUL_l (top) +[4]:/licenses/category/used-permission +[5]:https://system76.com/desktops/leopard +[6]:/files/images/memory2jpg +[7]:https://www.linux.com/sites/lcom/files/styles/rendered_file/public/memory_2.jpg?itok=zuVkQfvv (top) +[8]:/files/images/memory3jpg +[9]:https://www.linux.com/sites/lcom/files/styles/rendered_file/public/memory_3.jpg?itok=rvuQp3t0 (free) +[10]:/files/images/memory4jpg +[11]:https://www.linux.com/sites/lcom/files/styles/rendered_file/public/memory_4.jpg?itok=K_luLLPt (free) +[12]:/files/images/memory5jpg +[13]:https://www.linux.com/sites/lcom/files/styles/rendered_file/public/memory_5.jpg?itok=q50atcsX (total) +[14]:/files/images/memory6jpg +[15]:https://www.linux.com/sites/lcom/files/styles/rendered_file/public/memory_6.jpg?itok=bwFnUVmy (vmstat) +[16]:/files/images/memory7jpg +[17]:https://www.linux.com/sites/lcom/files/styles/rendered_file/public/memory_7.jpg?itok=UNHIT_P6 (dmidecode) +[18]:/files/images/memory8jpg +[19]:https://www.linux.com/sites/lcom/files/styles/rendered_file/public/memory_8.jpg?itok=t87jvmJJ (/proc/meminfo) +[20]:/files/images/memory9jpg +[21]:https://www.linux.com/sites/lcom/files/styles/rendered_file/public/memory_9.jpg?itok=t-iSMEKq (/proc/meminfo) +[22]:https://training.linuxfoundation.org/linux-courses/system-administration-training/introduction-to-linux diff --git a/published/201808/20180618 Anatomy of a Linux DNS Lookup - Part II.md b/published/201808/20180618 Anatomy of a Linux DNS Lookup - Part II.md new file mode 100644 index 0000000000..9bd7f17347 --- /dev/null +++ b/published/201808/20180618 Anatomy of a Linux DNS Lookup - Part II.md @@ -0,0 +1,223 @@ +Linux DNS 查询剖析(第二部分) +============================================== + +在 [Linux DNS 查询剖析 - 第一部分][1] 中,我介绍了: + +* `nsswitch` +* `/etc/hosts` +* `/etc/resolv.conf` +* `ping` 与 `host` 查询方式对比 + +并且发现大多数程序选择要查询的 DNS 服务器时会参考 `/etc/resolv.conf` 配置文件。 + +这种方式在 Linux 上比较普遍[^1]。虽然我使用了特定的发行版 Ubuntu,但背后的原理与 Debian 甚至是那些基于 CentOS 的发行版有相通的地方;当然,与更低或更高的 Ubuntu 版本相比,差异还是存在的。 + +[^1]: 事实上,这是相对于 POSIX 标准的,故不限于 Linux (我从上一篇文章的一条极好的[回复][2]中了解到这一点) + +也就是说,接下来,你主机上的行为很可能与我描述的不一致。 + +在第二部分中,我将介绍 `resolv.conf` 的更新机制、`systemctl restart networking` 命令的运行机制 ,以及 `dhclient` 是如何参与其中。 + +### 1) 手动更新 /etc/resolv.conf + +我们知道 `/etc/resolv.conf` (有极大的可能性)被用到,故你自然可以通过该文件增加一个 `nameserver`,那么主机也将会(与已有的 `nameserver` 一起)使用新加入的 `nameserver` 吧? + +你可以尝试如下: + +``` +$ echo nameserver 10.10.10.10 >> /etc/resolv.conf +``` + +看上去新的 `nameserver` 已经加入: + +``` +# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8) +#     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN +nameserver 10.0.2.3 +search home +nameserver 10.10.10.10 +``` + +但主机网络服务重启后问题出现了: + +``` +$ systemctl restart networking +$ cat /etc/resolv.conf +# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8) +#     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN +nameserver 10.0.2.3 +search home +``` + +我们的 `10.10.10.10` 的 `nameserver` 不见了! + +在上一篇文章中我们忽略了这一点,本文进行补充说明。 + +### 2) resolvconf + +你在 `/etc/resolv.conf` 文件中看到 `generated by resolvconf` 词组了吧?这就是我们的线索。 + +如果深入研究 `systemctl restart networking` 命令,你会发现它做了很多事情,结束时调用了 `/etc/network/if-up.d/000resolvconf` 脚本。在该脚本中,可以发现一次对 `resolvconf` 命令的调用: + +``` +/sbin/resolvconf -a "${IFACE}.${ADDRFAM}" +``` + +稍微研究一下 man 手册,发现`-a` 参数允许我们: + +``` +Add or overwrite the record IFACE.PROG then run the update scripts +if updating is enabled. +``` + +(增加或覆盖 IFACE.PROG 记录,如果开启更新选项,则运行更新脚本) + +故而也许我们可以直接调用该命令增加 `namserver`: + +``` +echo 'nameserver 10.10.10.10' | /sbin/resolvconf -a enp0s8.inet +``` + +测试表明确实可以! + +``` +$ cat /etc/resolv.conf  | grep nameserver +nameserver 10.0.2.3 +nameserver 10.10.10.10 +``` + +是否已经找到答案,这就是 `/etc/resolv.conf` 更新的逻辑?调用 `resolvconf` 将 `nameserver` 添加到某个地方的数据库,然后(“如果配置了更新”,先不管具体什么含义)更新 `resolv.conf` 文件。 + +并非如此。 + +``` +$ systemctl restart networking +root@linuxdns1:/etc# cat /etc/resolv.conf +# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8) +#     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN +nameserver 10.0.2.3 +search home +``` + +呃!(网络服务重启后)新增的 `nameserver` 再次消失了。 + +可见,`systemctl restart networking` 不仅仅运行了 `resolvconf`,还在其它地方获取 `nameserver` 信息。具体是哪里呢? + +### 3) ifup/ifdown + +继续深入研究 `systemctl restart networking`,发现它完成了一系列工作: + +``` +cat /lib/systemd/system/networking.service +[...] +[Service] +Type=oneshot +EnvironmentFile=-/etc/default/networking +ExecStartPre=-/bin/sh -c '[ "$CONFIGURE_INTERFACES" != "no" ] && [ -n "$(ifquery --read-environment --list --exclude=lo)" ] && udevadm settle' +ExecStart=/sbin/ifup -a --read-environment +ExecStop=/sbin/ifdown -a --read-environment --exclude=lo +[...] +``` + +首先,网络服务的重启实质是运行一个单触发oneshot的脚本,脚本包含如下命令: + +``` +/sbin/ifdown -a --read-environment --exclude=lo +/bin/sh -c '[ "$CONFIGURE_INTERFACES" != "no" ] && [ -n "$(ifquery --read-environment --list --exclude=lo)" ] && udevadm settle' +/sbin/ifup -a --read-environment +``` + +第一行使用 `ifdown` 关闭全部的网络接口,但本地回环local, lo接口除外。[^2] + +[^2]: 我不明白为何这没有导致我例子中的 vagrant 会话中断 (有谁明白吗?)。 + +(LCTT 译注:其实这是因为很快就又启动了接口,间隔的时间没有超过 TCP 连接的超时时间,有人在评论中也做了类似回复) + +第二行用于确认系统已经完成关闭网络接口相关的全部工作,以便下一步使用 `ifup` 启动接口。这也让我们了解到,网络服务实质运行的就是 `ifdown` 和 `ifup`。 + +文档中没有找到 `--read-environment` 参数的说明,该参数为 `systemctl` 正常工作所需。很多人以文档不完善为由不喜欢 `systemctl`。 + +很好。那么 `ifup` (和其成对出现的 `ifdown`) 到底做了哪些工作呢?长话短说,它运行了 `/etc/network/if-pre-up.d/` 和 `/etc/network/if-up.d/` 目录下的全部脚本;期间,这些脚本也可能会调用另外的脚本,依此类推。 + +其中一件工作就是运行了 `dhclient`,但我还不完全确定具体的机理,也许 `udev` 参与其中。 + +### 4) dhclient + +`dhclient` 是一个程序,用于与 DHCP 服务器协商对应网络接口应该使用的 IP 地址的详细信息。同时,它也可以获取可用的 DNS 服务器并将其替换到 `/etc/resolv.conf` 中。 + +让我们开始跟踪并模拟它的行为,但仅在我实验虚拟机的 `enp0s3` 接口上。事先已经删除 `/etc/resolv.conf` 文件中的 nameserver 配置: + +``` +$ sed -i '/nameserver.*/d' /run/resolvconf/resolv.conf +$ cat /etc/resolv.conf | grep nameserver +$ dhclient -r enp0s3 && dhclient -v enp0s3 +Killed old client process +Internet Systems Consortium DHCP Client 4.3.3 +Copyright 2004-2015 Internet Systems Consortium. +All rights reserved. +For info, please visit https://www.isc.org/software/dhcp/ +Listening on LPF/enp0s8/08:00:27:1c:85:19 +Sending on   LPF/enp0s8/08:00:27:1c:85:19 +Sending on   Socket/fallback +DHCPDISCOVER on enp0s8 to 255.255.255.255 port 67 interval 3 (xid=0xf2f2513e) +DHCPREQUEST of 172.28.128.3 on enp0s8 to 255.255.255.255 port 67 (xid=0x3e51f2f2) +DHCPOFFER of 172.28.128.3 from 172.28.128.2 +DHCPACK of 172.28.128.3 from 172.28.128.2 +bound to 172.28.128.3 -- renewal in 519 seconds. + +$ cat /etc/resolv.conf | grep nameserver +nameserver 10.0.2.3 +``` + +可见这就是 `nameserver` 的来源。 + +但稍等一下,命令中的 `/run/resolvconf/resolv.conf` 是哪个文件,不应该是 `/etc/resolv.conf` 吗? + +事实上,`/etc/resolv.conf` 并不一定只是一个普通文本文件。 + +在我的虚拟机上,它是一个软链接,指向位于 `/run/resolvconf` 目录下的“真实文件”。这也暗示了我们,该文件是在系统启动时生成的;同时,这也是该文件注释告诉我们不要直接修改该文件的原因。 + +(LCTT 译注:在 CentOS 7 中,没有 `resolvconf` 命令,`/etc/resolv.conf` 也不是软链接) + +假如上面命令中 `sed` 命令直接处理 `/etc/resolv.conf` 文件,效果是不同的,会有警告消息告知待操作的文件不能是软链接(`sed -i` 无法很好的处理软链接,它只会创建一个新文件)。 + +(LCTT 译注:CentOS 7 测试时,`sed -i` 命令操作软链接并没有警告,但确实创建了新文件取代软链接) + +如果你继续深入查看配置文件 `/etc/dhcp/dhclient.conf` 的 `supersede` 部分,你会发现 `dhclient` 可以覆盖 DHCP 提供的 DNS 服务器。 + +![linux-dns-2 (2)](https://zwischenzugs.files.wordpress.com/2018/06/linux-dns-2-2.png?w=525) + + _(大致)准确的关系图_ + +* * * + +### 第二部分的结束语 + +第二部分到此结束。信不信由你,这是一个某种程度上简化的流程版本,但我尽量保留重要和值得了解的部分,让你不会感到无趣。大部分内容都是围绕实际脚本的运行展开的。 + +但我们的工作还没有结束,在第三部分,我们会介绍这些之上的更多层次。 + +让我们简要列出我们已经介绍过的内容: + +* `nsswitch` +* `/etc/hosts` +* `/etc/resolv.conf` +* `/run/resolvconf/resolv.conf` +* `systemd` 和网络服务 +* `ifup` 和 `ifdown` +* `dhclient` +* `resolvconf` + +-------------------------------------------------------------------------------- + +via: https://zwischenzugs.com/2018/06/18/anatomy-of-a-linux-dns-lookup-part-ii/ + +作者:[ZWISCHENZUGS][a] +译者:[pinewall](https://github.com/pinewall) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://zwischenzugs.com/ +[1]:https://linux.cn/article-9943-1.html +[2]:https://zwischenzugs.com/2018/06/08/anatomy-of-a-linux-dns-lookup-part-i/#comment-2312 diff --git a/published/201808/20180619 How to reset, revert, and return to previous states in Git.md b/published/201808/20180619 How to reset, revert, and return to previous states in Git.md new file mode 100644 index 0000000000..92a1dd07a2 --- /dev/null +++ b/published/201808/20180619 How to reset, revert, and return to previous states in Git.md @@ -0,0 +1,274 @@ +如何在 Git 中重置、恢复,返回到以前的状态 +====== + +> 用简洁而优雅的 Git 命令撤销仓库中的改变。 + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/code_computer_development_programming.png?itok=4OM29-82) + +使用 Git 工作时其中一个鲜为人知(和没有意识到)的方面就是,如何轻松地返回到你以前的位置 —— 也就是说,在仓库中如何很容易地去撤销那怕是重大的变更。在本文中,我们将带你了解如何去重置、恢复和完全回到以前的状态,做到这些只需要几个简单而优雅的 Git 命令。 + +### 重置 + +我们从 Git 的 `reset` 命令开始。确实,你应该能够认为它就是一个 “回滚” —— 它将你本地环境返回到之前的提交。这里的 “本地环境” 一词,我们指的是你的本地仓库、暂存区以及工作目录。 + +先看一下图 1。在这里我们有一个在 Git 中表示一系列提交的示意图。在 Git 中一个分支简单来说就是一个命名的、指向一个特定的提交的可移动指针。在这里,我们的 master 分支是指向链中最新提交的一个指针。 + +![Local Git environment with repository, staging area, and working directory][2] + +*图 1:有仓库、暂存区、和工作目录的本地环境* + +如果看一下我们的 master 分支是什么,可以看一下到目前为止我们产生的提交链。 + +``` +$ git log --oneline +b764644 File with three lines +7c709f0 File with two lines +9ef9173 File with one line +``` + +如果我们想回滚到前一个提交会发生什么呢?很简单 —— 我们只需要移动分支指针即可。Git 提供了为我们做这个动作的 `reset` 命令。例如,如果我们重置 master 为当前提交回退两个提交的位置,我们可以使用如下之一的方法: + +``` +$ git reset 9ef9173 +``` + +(使用一个绝对的提交 SHA1 值 `9ef9173`) + +或: + +``` +$ git reset current~2 +``` +(在 “current” 标签之前,使用一个相对值 -2) + +图 2 展示了操作的结果。在这之后,如果我们在当前分支(master)上运行一个 `git log` 命令,我们将看到只有一个提交。 + +``` +$ git log --oneline + +9ef9173 File with one line +``` + +![After reset][4] + +*图 2:在 `reset` 之后* + +`git reset` 命令也包含使用一些选项,可以让你最终满意的提交内容去更新本地环境的其它部分。这些选项包括:`hard` 在仓库中去重置指向的提交,用提交的内容去填充工作目录,并重置暂存区;`soft` 仅重置仓库中的指针;而 `mixed`(默认值)将重置指针和暂存区。 + +这些选项在特定情况下非常有用,比如,`git reset --hard ` 这个命令将覆盖本地任何未提交的更改。实际上,它重置了(清除掉)暂存区,并用你重置的提交内容去覆盖了工作区中的内容。在你使用 `hard` 选项之前,一定要确保这是你真正地想要做的操作,因为这个命令会覆盖掉任何未提交的更改。 + +### 恢复 + +`git revert` 命令的实际结果类似于 `reset`,但它的方法不同。`reset` 命令(默认)是在链中向后移动分支的指针去“撤销”更改,`revert` 命令是在链中添加一个新的提交去“取消”更改。再次查看图 1 可以非常轻松地看到这种影响。如果我们在链中的每个提交中向文件添加一行,一种方法是使用 `reset` 使那个提交返回到仅有两行的那个版本,如:`git reset HEAD~1`。 + +另一个方法是添加一个新的提交去删除第三行,以使最终结束变成两行的版本 —— 实际效果也是取消了那个更改。使用一个 `git revert` 命令可以实现上述目的,比如: + +``` +$ git revert HEAD +``` + +因为它添加了一个新的提交,Git 将提示如下的提交信息: + +``` +Revert "File with three lines" + +This reverts commit b764644bad524b804577684bf74e7bca3117f554. + +# Please enter the commit message for your changes. Lines starting +# with '#' will be ignored, and an empty message aborts the commit. +# On branch master +# Changes to be committed: +#       modified:   file1.txt +# +``` + +图 3(在下面)展示了 `revert` 操作完成后的结果。 + +如果我们现在运行一个 `git log` 命令,我们将看到前面的提交之前的一个新提交。 + +``` +$ git log --oneline +11b7712 Revert "File with three lines" +b764644 File with three lines +7c709f0 File with two lines +9ef9173 File with one line +``` + +这里是工作目录中这个文件当前的内容: + +``` +$ cat +Line 1 +Line 2 +``` + +![img](https://opensource.com/sites/default/files/uploads/figure3a.png) + +*图 3 `revert` 操作之后* + +#### 恢复或重置如何选择? + +为什么要优先选择 `revert` 而不是 `reset` 操作?如果你已经将你的提交链推送到远程仓库(其它人可以已经拉取了你的代码并开始工作),一个 `revert` 操作是让他们去获得更改的非常友好的方式。这是因为 Git 工作流可以非常好地在分支的末端添加提交,但是当有人 `reset` 分支指针之后,一组提交将再也看不见了,这可能会是一个挑战。 + +当我们以这种方式使用 Git 工作时,我们的基本规则之一是:在你的本地仓库中使用这种方式去更改还没有推送的代码是可以的。如果提交已经推送到了远程仓库,并且可能其它人已经使用它来工作了,那么应该避免这些重写提交历史的更改。 + +总之,如果你想回滚、撤销或者重写其它人已经在使用的一个提交链的历史,当你的同事试图将他们的更改合并到他们拉取的原始链上时,他们可能需要做更多的工作。如果你必须对已经推送并被其他人正在使用的代码做更改,在你做更改之前必须要与他们沟通,让他们先合并他们的更改。然后在这个侵入操作没有需要合并的内容之后,他们再拉取最新的副本。 + +你可能注意到了,在我们做了 `reset` 操作之后,原始的提交链仍然在那个位置。我们移动了指针,然后 `reset` 代码回到前一个提交,但它并没有删除任何提交。换句话说就是,只要我们知道我们所指向的原始提交,我们能够通过简单的返回到分支的原始链的头部来“恢复”指针到前面的位置: + +``` +git reset +``` + +当提交被替换之后,我们在 Git 中做的大量其它操作也会发生类似的事情。新提交被创建,有关的指针被移动到一个新的链,但是老的提交链仍然存在。 + +### 变基 + +现在我们来看一个分支变基。假设我们有两个分支:master 和 feature,提交链如下图 4 所示。master 的提交链是 `C4->C2->C1->C0` 和 feature 的提交链是 `C5->C3->C2->C1->C0`。 + +![Chain of commits for branches master and feature][6] + +*图 4:master 和 feature 分支的提交链* + +如果我们在分支中看它的提交记录,它们看起来应该像下面的这样。(为了易于理解,`C` 表示提交信息) + +``` +$ git log --oneline master +6a92e7a C4 +259bf36 C2 +f33ae68 C1 +5043e79 C0 + +$ git log --oneline feature +79768b8 C5 +000f9ae C3 +259bf36 C2 +f33ae68 C1 +5043e79 C0 +``` + +我告诉人们在 Git 中,可以将 `rebase` 认为是 “将历史合并”。从本质上来说,Git 将一个分支中的每个不同提交尝试“重放”到另一个分支中。 + +因此,我们使用基本的 Git 命令,可以变基一个 feature 分支进入到 master 中,并将它拼入到 `C4` 中(比如,将它插入到 feature 的链中)。操作命令如下: + +``` +$ git checkout feature +$ git rebase master + +First, rewinding head to replay your work on top of it... +Applying: C3 +Applying: C5 +``` + +完成以后,我们的提交链将变成如下图 5 的样子。 + +![Chain of commits after the rebase command][8] + +*图 5:`rebase` 命令完成后的提交链* + +接着,我们看一下提交历史,它应该变成如下的样子。 + +``` +$ git log --oneline master +6a92e7a C4 +259bf36 C2 +f33ae68 C1 +5043e79 C0 + +$ git log --oneline feature +c4533a5 C5 +64f2047 C3 +6a92e7a C4 +259bf36 C2 +f33ae68 C1 +5043e79 C0 +``` + +注意那个 `C3'` 和 `C5'`— 在 master 分支上已处于提交链的“顶部”,由于产生了更改而创建了新提交。但是也要注意的是,rebase 后“原始的” `C3` 和 `C5` 仍然在那里 — 只是再没有一个分支指向它们而已。 + +如果我们做了这个变基,然后确定这不是我们想要的结果,希望去撤销它,我们可以做下面示例所做的操作: + +``` +$ git reset 79768b8 +``` + +由于这个简单的变更,现在我们的分支将重新指向到做 `rebase` 操作之前一模一样的位置 —— 完全等效于撤销操作(图 6)。 + +![After undoing rebase][10] + +*图 6:撤销 `rebase` 操作之后* + +如果你想不起来之前一个操作指向的一个分支上提交了什么内容怎么办?幸运的是,Git 命令依然可以帮助你。用这种方式可以修改大多数操作的指针,Git 会记住你的原始提交。事实上,它是在 `.git` 仓库目录下,将它保存为一个特定的名为 `ORIG_HEAD ` 的文件中。在它被修改之前,那个路径是一个包含了大多数最新引用的文件。如果我们 `cat` 这个文件,我们可以看到它的内容。 + +``` +$ cat .git/ORIG_HEAD +79768b891f47ce06f13456a7e222536ee47ad2fe +``` + +我们可以使用 `reset` 命令,正如前面所述,它返回指向到原始的链。然后它的历史将是如下的这样: + +``` +$ git log --oneline feature +79768b8 C5 +000f9ae C3 +259bf36 C2 +f33ae68 C1 +5043e79 C0 +``` + +在 reflog 中是获取这些信息的另外一个地方。reflog 是你本地仓库中相关切换或更改的详细描述清单。你可以使用 `git reflog` 命令去查看它的内容: + +``` +$ git reflog +79768b8 HEAD@{0}: reset: moving to 79768b +c4533a5 HEAD@{1}: rebase finished: returning to refs/heads/feature +c4533a5 HEAD@{2}: rebase: C5 +64f2047 HEAD@{3}: rebase: C3 +6a92e7a HEAD@{4}: rebase: checkout master +79768b8 HEAD@{5}: checkout: moving from feature to feature +79768b8 HEAD@{6}: commit: C5 +000f9ae HEAD@{7}: checkout: moving from master to feature +6a92e7a HEAD@{8}: commit: C4 +259bf36 HEAD@{9}: checkout: moving from feature to master +000f9ae HEAD@{10}: commit: C3 +259bf36 HEAD@{11}: checkout: moving from master to feature +259bf36 HEAD@{12}: commit: C2 +f33ae68 HEAD@{13}: commit: C1 +5043e79 HEAD@{14}: commit (initial): C0 +``` + +你可以使用日志中列出的、你看到的相关命名格式,去重置任何一个东西: + +``` +$ git reset HEAD@{1} +``` + +一旦你理解了当“修改”链的操作发生后,Git 是如何跟踪原始提交链的基本原理,那么在 Git 中做一些更改将不再是那么可怕的事。这就是强大的 Git 的核心能力之一:能够很快速、很容易地尝试任何事情,并且如果不成功就撤销它们。 + +Brent Laster 将在 7 月 16 日至 19 日在俄勒冈州波特兰举行的第 20 届 OSCON 年度活动上,展示 [强大的 Git:Rerere, Bisect, Subtrees, Filter Branch, Worktrees, Submodules, 等等][11]。想了解在任何水平上使用 Git 的一些技巧和缘由,请查阅 Brent 的书 ——"[Professional Git][13]",它在 Amazon 上有售。 + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/6/git-reset-revert-rebase-commands + +作者:[Brent Laster][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[qhwdw](https://github.com/qhwdw) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://opensource.com/users/bclaster +[1]:/file/401126 +[2]:https://opensource.com/sites/default/files/uploads/gitcommands1_local-environment.png "Local Git environment with repository, staging area, and working directory" +[3]:/file/401131 +[4]:https://opensource.com/sites/default/files/uploads/gitcommands2_reset.png "After reset" +[5]:/file/401141 +[6]:https://opensource.com/sites/default/files/uploads/gitcommands4_commits-branches.png "Chain of commits for branches master and feature" +[7]:/file/401146 +[8]:https://opensource.com/sites/default/files/uploads/gitcommands5_commits-rebase.png "Chain of commits after the rebase command" +[9]:/file/401151 +[10]:https://opensource.com/sites/default/files/uploads/gitcommands6_rebase-undo.png "After undoing rebase" +[11]:https://conferences.oreilly.com/oscon/oscon-or/public/schedule/detail/67142 +[12]:https://conferences.oreilly.com/oscon/oscon-or +[13]:https://www.amazon.com/Professional-Git-Brent-Laster/dp/111928497X/ref=la_B01MTGIINQ_1_2?s=books&ie=UTF8&qid=1528826673&sr=1-2 diff --git a/published/201808/20180621 Bitcoin is a Cult - Adam Caudill.md b/published/201808/20180621 Bitcoin is a Cult - Adam Caudill.md new file mode 100644 index 0000000000..4296baec06 --- /dev/null +++ b/published/201808/20180621 Bitcoin is a Cult - Adam Caudill.md @@ -0,0 +1,103 @@ +比特币是一个邪教 +====== + +经过这些年,比特币社区已经发生了非常大的变化;社区成员从闭着眼睛都能讲解 [梅克尔树][1] 的技术迷们,变成了被一夜爆富欲望驱使的投机者和由一些连什么是梅克尔树都不懂的人所领导的企图寻求 10 亿美元估值的区块链初创公司。随着时间的流逝,围绕比特币和其它加密货币形成了一股热潮,他们认为比特币和其它加密货币远比实际的更重要;他们相信常见的货币(法定货币)正在成为过去,而加密货币将从根本上改变世界经济。 + +每一年他们的队伍都在壮大,而他们对加密货币的看法也在变得更加宏伟,那怕是对该技术的[新奇的用法][2]而使它陷入了困境。虽然我坚信设计优良的加密货币可以使金钱的跨境流动更容易,并且在大规模通胀的领域提供一个更稳定的选择,但现实情况是,我们并没有做到这些。实际上,正是价值的巨大不稳定性才使得投机者赚钱。那些宣扬美元和欧元即将死去的人,已经完全抛弃了对现实世界客观公正的看法。 + +### 一点点背景 … + +比特币发行那天,我读了它的白皮书 —— 它使用有趣的 [梅克尔树][1] 去创建一个公共账簿和一个非常合理的共识协议 —— 由于它新颖的特性引起了密码学领域中许多人的注意。在白皮书发布后的几年里,比特币变得非常有价值,并由此吸引了许多人将它视为是一种投资,和那些认为它将改变一切的忠实追随者(和发声者)。这篇文章将讨论的正是后者。 + +昨天(2018/6/20),有人在推特上发布了一个最近的比特币区块的哈希,下面成千上万的推文和其它讨论让我相信,比特币已经跨越界线进入了真正的邪教领域。 + +一切都源于 Mark Wilcox 的[这个推文][9]: + +> [#00000000000000000021e800c1e8df51b22c1588e5a624bea17e9faa34b2dc4a][8] + +> — Mark Wilcox (@mwilcox) [June 19, 2018][9] + +张贴的这个值是 [比特币 #528249 号区块][3] 的哈希值。前导零是挖矿过程的结果;挖掘一个区块就是把区块内容与一个现时数nonce(和其它数据)组合起来,然后做哈希运算,并且它至少有一定数量的前导零才能被验证为有效区块。如果它不是正确的数字,你可以更换现时数再试。重复这个过程直到哈希值的前导零数量是正确的数字之后,你就有了一个有效的区块。让人们感到很兴奋的部分是接下来的 `21e800`。 + +一些人说这是一个有意义的编号,挖掘出这个区块的人实际上的难度远远超出当前所看到的,不仅要调整前导零的数量,还要匹配接下来的 24 位 —— 它要求非常强大的计算能力。如果有人能够以蛮力去实现它,这将表明有些事情很严重,比如,在计算或密码学方面的重大突破。 + +你一定会有疑问,为什么 `21e800` 如此重要 —— 一个你问了肯定会后悔的问题。有人说它是参考了 [E8 理论][4](一个广受批评的提出标准场理论的论文),或是表示总共存在 2,100,000,000 枚比特币(`21 x 10^8` 就是 2,100,000,000)。还有其它说法,因为太疯狂了而没有办法写出来。另一个重要的事实是,在前导零后面有 21e8 的区块平均每年被挖掘出一次 —— 这些从来没有人认为是很重要的。 + +这就引出了有趣的地方:关于这是如何发生的[理论][5]。 + + * 一台量子计算机,它能以某种方式用不可思议的速度做哈希运算。尽管在量子计算机的理论中还没有迹象表明它能够做这件事。哈希是量子计算机认为安全的东西之一。 + * 时间旅行。是的,真的有人这么说,有人从未来穿梭回到现在去挖掘这个区块。我认为这种说法太荒谬了,都懒得去解释它为什么是错误的。 + * 中本聪回来了。尽管事实上他的私钥没有任何活动,一些人从理论上认为他回来了,他能做一些没人能做的事情。这些理论是无法解释他如何做到的。 + +> 因此,总的来说(按我的理解)中本聪,为了知道和计算他做的事情,根据现代科学,他可能是以下之一: +> +> A) 使用了一台量子计算机 +> B) 来自未来 +> C) 两者都是 +> +> — Crypto Randy Marsh [REKT] (@nondualrandy) [June 21, 2018][6] + +如果你觉得所有的这一切听起来像 [命理学][7]numerology,不止你一个人是这样想的。 + +所有围绕有特殊意义的区块哈希的讨论,也引发了对在某种程度上比较有趣的东西的讨论。比特币的创世区块,它是第一个比特币区块,有一个不寻常的属性:早期的比特币要求哈希值的前 32 bit是零;而创始区块的前导零有 43 位。因为产生创世区块的代码从未发布过,不知道它是如何产生的,也不知道是用什么类型的硬件产生的。中本聪有学术背景,因此可能他有比那个时候大学中常见设备更强大的计算能力。从这一点上说,只是对古怪的创世区块的历史有点好奇,仅此而已。 + +### 关于哈希运算的简单题外话 + +这种喧嚣始于比特币区块的哈希运算;因此理解哈希是什么很重要,并且要理解一个非常重要的属性,哈希是单向加密函数,它能够基于给定的数据创建一个伪随机输出。 + +这意味着什么呢?基于本文讨论的目的,对于每个给定的输入你将得到一个随机的输出。随机数有时看起来很有趣,很简单,因为它是随机的结果,并且人类大脑可以很容易从任何东西中找到顺序。当你从随机数据中开始查看顺序时,你就会发现有趣的事情 —— 这些东西毫无意义,因为它们只是简单地随机数。当人们把重要的意义归属到随机数据上时,它将告诉你很多这些参与者观念相关的东西,而不是数据本身。 + +### 币之邪教 + +首先,我们来定义一组术语: + + * 邪教Cult:一个宗教崇拜和直接向一个特定的人或物虔诚的体系。 + * 宗教Religion:有人认为是至高无上的追求或兴趣。 + +币之邪教Cult of the Coin有许多圣人,或许没有人比中本聪Satoshi Nakamoto更伟大,他是比特币创始者(们)的假名。(对他的)狂热拥戴,要归因于他的能力和理解力远超过一般的研究人员,认为他的远见卓视无人能比,他影响了世界新经济的秩序。当将中本聪的神秘本质和未知的真实身份结合起来时,狂热的追随着们将中本聪视为一个真正值得尊敬的人物。 + +当然,除了追随其他圣人的追捧者之外,毫无疑问这些追捧者认为自己是正确的。任何对他们的圣人的批评都被认为也是对他们的批评。例如,那些追捧 EOS 的人,可能会视中本聪为一个开发了失败项目的黑客,而对 EOS 那怕是最轻微的批评,他们也会作出激烈的反应,之所以反应如此强烈,仅仅是因为攻击了他们心目中的神。那些追捧 IOTA 的人的反应也一样;还有更多这样的例子。 + +这些追随者在讨论问题时已经失去了理性和客观,他们的狂热遮盖了他们的视野。任何对这些项目和项目背后的人的讨论,如果不是溢美之词,必然以某种程序的刻薄言辞结束,对于一个技术的讨论那种做法是毫无道理的。 + +这很危险,原因很多: + + * 开发者 & 研究者对缺陷视而不见。由于追捧者的大量赞美,这些参与开发的人对自己的能力的看法开始膨胀,并将一些批评看作是无端的攻击 —— 因为他们认为自己是不可能错的。 + * 真正的问题是被攻击。技术问题不再被看作是需要去解决的问题和改进的机会,他们认为是来自那些想去破坏项目的人的攻击。 + * 物以类聚,人以币分。追随者们通常会结盟到一起,而圣人仅有一个。承认其它项目的优越,意味着认同自己项目的缺陷或不足,而这是他们不愿意做的事情。 + * 阻止真实的进步。进化是很残酷的,死亡是必然会有的,项目可能失败,也要承认这些失败的原因。如果忽视失败的教训,如果不允许那些应该去死亡的事情发生,进步就会停止。 + +许多围绕加密货币和相关区块链项目的讨论已经开始变得越来越”有毒“,善意的人想在不受攻击的情况下进行技术性讨论越来越不可能。随着对真正缺陷的讨论,那些在其它环境中注定要失败的缺陷,在没有做任何的事实分析的情况下即刻被判定为异端已经成为了惯例,善意的人参与其中的代价变得极其昂贵。至少有些人已经意识到极其严重的安全漏洞,由于高“毒性”的环境,他们选择保持沉默。 + +曾经被好奇、学习和改进的期望、创意可行性所驱动的东西,现在被盲目的贪婪、宗教般的狂热、自以为是和自我膨胀所驱动。 + +我对受这种狂热激励的项目的未来不抱太多的希望,而它持续地传播,可能会损害多年来在这个领域中真正的研究者。这些技术项目中,一些项目成功了,一些项目失败了 —— 这就是技术演进的方式。设计这些系统的人,就和你我一样都有缺点,同样这些项目也有缺陷。有些项目非常适合某些使用场景而不适合其它场景,有些项目不适合任何使用场景,没有一个项目适合所有使用场景。关于这些项目的讨论应该关注于技术方面,这样做是为了让这一研究领域得以发展;在这些项目中掺杂宗教般狂热必将损害所有人。 + +[注意:这种行为有许多例子可以引用,但是为了保护那些因批评项目而成为被攻击目标的人,我选择尽可能少的列出这种例子。我看到许多我很尊敬的人、许多我认为是朋友的人成为这种恶毒攻击的受害者 —— 我不想引起人们对这些攻击的注意和重新引起对他们的攻击。] + +--- +关于作者: + +我是一个资深应用安全顾问、研究员和具有超过 15 年的经验的软件开发者。我主要关注的是应用程序安全、安全通信和加密, 虽然我经常由于无聊而去研究新的领域。我通常会写了一些关于我的研究和安全、开发和软件设计,和我当前吸引了我注意力的爱好的文章。 + +-------------------------------------------------------------------------------- + +via: https://adamcaudill.com/2018/06/21/bitcoin-is-a-cult/ + +作者:[Adam Caudill][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[qhwdw](https://github.com/qhwdw) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://adamcaudill.com/author/adam/ +[1]:https://en.wikipedia.org/wiki/Merkle_tree +[2]:https://hackernoon.com/how-crypto-kitties-disrupted-the-ethereum-network-845c22aa1e6e +[3]:https://blockchain.info/block-height/528249 +[4]:https://en.wikipedia.org/wiki/An_Exceptionally_Simple_Theory_of_Everything +[5]:https://medium.com/@coop__soup/00000000000000000021e800c1e8df51b22c1588e5a624bea17e9faa34b2dc4a-cd4b67d446be +[6]:https://twitter.com/nondualrandy/status/1009609117768605696?ref_src=twsrc%5Etfw +[7]:https://en.wikipedia.org/wiki/Numerology +[8]:https://twitter.com/hashtag/00000000000000000021e800c1e8df51b22c1588e5a624bea17e9faa34b2dc4a?src=hash&ref_src=twsrc%5Etfw +[9]:https://twitter.com/mwilcox/status/1009160832398262273?ref_src=twsrc%5Etfw \ No newline at end of file diff --git a/published/201808/20180622 How to Check Disk Space on Linux from the Command line.md b/published/201808/20180622 How to Check Disk Space on Linux from the Command line.md new file mode 100644 index 0000000000..de22e3e545 --- /dev/null +++ b/published/201808/20180622 How to Check Disk Space on Linux from the Command line.md @@ -0,0 +1,146 @@ +如何使用命令行检查 Linux 上的磁盘空间 +======== + +> Linux 提供了所有必要的工具来帮助你确切地发现你的驱动器上剩余多少空间。Jack 在这里展示了如何做。 + +![](https://www.linux.com/sites/lcom/files/styles/rendered_file/public/diskspace-main.jpg?itok=t9Oxxc9X) + +快速提问:你的驱动器剩余多少剩余空间?一点点还是很多?接下来的提问是:你知道如何找出这些剩余空间吗?如果你碰巧使用的是 GUI 桌面( 例如 GNOME、KDE、Mate、Pantheon 等 ),则任务可能非常简单。但是,当你要在一个没有 GUI 桌面的服务器上查询剩余空间,你该如何去做呢?你是否要为这个任务安装相应的软件工具?答案是绝对不是。在 Linux 中,具备查找驱动器上的剩余磁盘空间的所有工具。事实上,有两个非常容易使用的工具。 + +在本文中,我将演示这些工具。我将使用 [Elementary OS][1](LCTT译注:Elementary OS 是基于 Ubuntu 精心打磨美化的桌面 Linux 发行版 ),它还包括一个 GUI 方式,但我们将限制自己仅使用命令行。好消息是这些命令行工具随时可用于每个 Linux 发行版。在我的测试系统中,连接了许多的驱动器(内部的和外部的)。使用的命令与连接驱动器的位置无关,仅仅与驱动器是否已经挂载好并且对操作系统可见有关。 + +言归正传,让我们来试试这些工具。 + +### df + +`df` 命令是我第一个用于在 Linux 上查询驱动器空间的工具,时间可以追溯到 20 世纪 90 年代。它的使用和报告结果非常简单。直到今天,`df` 还是我执行此任务的首选命令。此命令有几个选项开关,对于基本的报告,你实际上只需要一个选项。该命令是 `df -H` 。`-H` 选项开关用于将 `df` 的报告结果以人类可读的格式进行显示。`df -H` 的输出包括:已经使用了的空间量、可用空间、空间使用的百分比,以及每个磁盘连接到系统的挂载点(图 1)。 + +![df output][3] + +*图 1:Elementary OS 系统上 `df -H` 命令的输出结果* + +如果你的驱动器列表非常长并且你只想查看单个驱动器上使用的空间,该怎么办?对于 `df` 这没问题。我们来看一下位于 `/dev/sda1` 的主驱动器已经使用了多少空间。为此,执行如下命令: + +``` +df -H /dev/sda1 +``` +输出将限于该驱动器(图 2)。 + +![disk usage][6] + +*图 2:一个单独驱动器空间情况* + +你还可以限制 `df` 命令结果报告中显示指定的字段。可用的字段包括: + +- `source` — 文件系统的来源(LCTT译注:通常为一个设备,如 `/dev/sda1` ) +- `size` — 块总数 +- `used` — 驱动器已使用的空间 +- `avail` — 可以使用的剩余空间 +- `pcent` — 驱动器已经使用的空间占驱动器总空间的百分比 +- `target` —驱动器的挂载点 + +让我们显示所有驱动器的输出,仅显示 `size` ,`used` ,`avail` 字段。对此的命令是: + +``` +df -H --output=size,used,avail +``` + +该命令的输出非常简单( 图 3 )。 + +![output][8] + +*图 3:显示我们驱动器的指定输出* + +这里唯一需要注意的是我们不知道该输出的来源,因此,我们要把 `source` 加入命令中: + +``` +df -H --output=source,size,used,avail +``` + +现在输出的信息更加全面有意义(图 4)。 + +![source][10] + +*图 4:我们现在知道了磁盘使用情况的来源* + +### du + +我们的下一个命令是 `du` 。 正如您所料,这代表磁盘使用情况disk usage。 `du` 命令与 `df` 命令完全不同,因为它报告目录而不是驱动器的空间使用情况。 因此,您需要知道要检查的目录的名称。 假设我的计算机上有一个包含虚拟机文件的目录。 那个目录是 `/media/jack/HALEY/VIRTUALBOX` 。 如果我想知道该特定目录使用了多少空间,我将运行如下命令: + +``` +du -h /media/jack/HALEY/VIRTUALBOX +``` + +上面命令的输出将显示目录中每个文件占用的空间(图 5)。 + +![du command][12] + +*图 5 在特定目录上运行 `du` 命令的输出* + +到目前为止,这个命令并没有那么有用。如果我们想知道特定目录的总使用量怎么办?幸运的是,`du` 可以处理这项任务。对于同一目录,命令将是: + +``` +du -sh /media/jack/HALEY/VIRTUALBOX/ +``` + +现在我们知道了上述目录使用存储空间的总和(图 6)。 + +![space used][14] + +*图 6:我的虚拟机文件使用存储空间的总和是 559GB* + +您还可以使用此命令查看父项的所有子目录使用了多少空间,如下所示: + +``` +du -h /media/jack/HALEY +``` + +此命令的输出见(图 7),是一个用于查看各子目录占用的驱动器空间的好方法。 + +![directories][16] + +*图 7:子目录的存储空间使用情况* + +`du` 命令也是一个很好的工具,用于查看使用系统磁盘空间最多的目录列表。执行此任务的方法是将 `du` 命令的输出通过管道传递给另外两个命令:`sort` 和 `head` 。下面的命令用于找出驱动器上占用存储空间最大的前 10 个目录: + +``` +du -a /media/jack | sort -n -r |head -n 10 +``` + +输出将以从大到小的顺序列出这些目录(图 8)。 + +![top users][18] + +*图 8:使用驱动器空间最多的 10 个目录* + +### 没有你想像的那么难 + +查看 Linux 系统上挂载的驱动器的空间使用情况非常简单。只要你将你的驱动器挂载在 Linux 系统上,使用 `df` 命令或 `du` 命令在报告必要信息方面都会非常出色。使用 `df` 命令,您可以快速查看磁盘上总的空间使用量,使用 `du` 命令,可以查看特定目录的空间使用情况。对于每一个 Linux 系统的管理员来说,这两个命令的结合使用是必须掌握的。 + +而且,如果你没有注意到,我最近介绍了[查看 Linux 上内存使用情况的方法][19]。总之,这些技巧将大力帮助你成功管理 Linux 服务器。 + +通过 Linux Foundation 和 edX 免费提供的 “Linux 简介” 课程,了解更多有关 Linux 的信息。 + +-------- + +via: https://www.linux.com/learn/intro-to-linux/2018/6how-check-disk-space-linux-command-line + +作者:[Jack Wallen][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[SunWave](https://github.com/SunWave) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.linux.com/users/jlwallen +[1]:https://elementary.io/ +[3]:https://www.linux.com/sites/lcom/files/styles/rendered_file/public/diskspace_1.jpg?itok=aJa8AZAM +[6]:https://www.linux.com/sites/lcom/files/styles/rendered_file/public/diskspace_2.jpg?itok=_PAq3kxC +[8]:https://www.linux.com/sites/lcom/files/styles/rendered_file/public/diskspace_3.jpg?itok=51m8I-Vu +[10]:https://www.linux.com/sites/lcom/files/styles/rendered_file/public/diskspace_4.jpg?itok=SuwgueN3 +[12]:https://www.linux.com/sites/lcom/files/styles/rendered_file/public/diskspace_5.jpg?itok=XfS4s7Zq +[14]:https://www.linux.com/sites/lcom/files/styles/rendered_file/public/diskspace_6.jpg?itok=r71qICyG +[16]:https://www.linux.com/sites/lcom/files/styles/rendered_file/public/diskspace_7.jpg?itok=PtDe4q5y +[18]:https://www.linux.com/sites/lcom/files/styles/rendered_file/public/diskspace_8.jpg?itok=v9E1SFcC +[19]:https://www.linux.com/learn/5-commands-checking-memory-usage-linux +[20]:https://training.linuxfoundation.org/linux-courses/system-administration-training/introduction-to-linux \ No newline at end of file diff --git a/published/201808/20180623 Don-t Install Yaourt- Use These Alternatives for AUR in Arch Linux.md b/published/201808/20180623 Don-t Install Yaourt- Use These Alternatives for AUR in Arch Linux.md new file mode 100644 index 0000000000..a96deb62dc --- /dev/null +++ b/published/201808/20180623 Don-t Install Yaourt- Use These Alternatives for AUR in Arch Linux.md @@ -0,0 +1,194 @@ +Yaourt 已死!在 Arch 上使用这些替代品 +====== + +**前略:Yaourt 曾是最流行的 AUR 助手,但现已停止开发。在这篇文章中,我们会为 Arch 衍生发行版们列出 Yaourt 最佳的替代品。** + +[Arch User Repository][1] (常被称作 AUR),是一个为 Arch 用户而生的社区驱动软件仓库。Debian/Ubuntu 用户的对应类比是 PPA。 + +AUR 包含了不直接被 [Arch Linux][2] 官方所背书的软件。如果有人想在 Arch 上发布软件或者包,它可以通过这个社区仓库提供。这让最终用户们可以使用到比默认仓库里更多的软件。 + +所以你该如何使用 AUR 呢?简单来说,你需要另外的工具以从 AUR 中安装软件。Arch 的包管理器 [pacman][3] 不直接支持 AUR。那些支持 AUR 的“特殊工具”我们称之为 [AUR 助手][4]。 + +Yaourt (Yet AnOther User Repository Tool)(曾经)是 `pacman` 的一个封装,便于用户在 Arch Linux 上安装 AUR 软件。它基本上采用和 `pacman` 一样的语法。Yaourt 对于 AUR 的搜索、安装,乃至冲突解决和包依赖关系维护都有着良好的支持。 + +然而,Yaourt 的开发进度近来十分缓慢,甚至在 Arch Wiki 上已经被[列为][5]“停止或有问题”。[许多 Arch 用户认为它不安全][6] 进而开始寻找其它的 AUR 助手。 + +![Yaourt 以外的 AUR Helpers][7] + +在这篇文章中,我们会介绍 Yaourt 最佳的替代品以便于你从 AUR 安装软件。 + +### 最好的 AUR 助手 + +我刻意忽略掉了例如 Trizen 和 Packer 这样的流行的选择,因为它们也被列为“停止或有问题”的了。 + +#### 1、 aurman + +[aurman][8] 是最好的 AUR 助手之一,也能胜任 Yaourt 替代品的地位。它有非常类似于 `pacman` 的语法,可以支持所有的 `pacman` 操作。你可以搜索 AUR、解决包依赖,在构建 AUR 包前检查 PKGBUILD 的内容等等。 + +aurman 的特性: + + * aurman 支持所有 `pacman` 操作,并且引入了可靠的包依赖解决方案、冲突判定和分包split package支持 + * 线程化的 sudo 循环会在后台运行,所以你每次安装只需要输入一次管理员密码 + * 提供开发包支持,并且可以区分显性安装和隐性安装的包 + * 支持搜索 AUR 包和仓库 + * 在构建 AUR 包之前,你可以检视并编辑 PKGBUILD 的内容 + * 可以用作单独的 [包依赖解决工具][9] + +安装 aurman: + +``` +git clone https://aur.archlinux.org/aurman.git +cd aurman +makepkg -si +``` + +使用 aurman: + +用名字搜索: + +``` +aurman -Ss +``` + +安装: + +``` +aurman -S <package-name> +``` + +#### 2、 yay + +[yay][10] 是下一个最好的 AUR 助手。它使用 Go 语言写成,宗旨是提供最少化用户输入的 `pacman` 界面、yaourt 式的搜索,而几乎没有任何依赖软件。 + +yay 的特性: + + * `yay` 提供 AUR 表格补全,并且从 ABS 或 AUR 下载 PKGBUILD + * 支持收窄搜索,并且不需要引用 PKGBUILD 源 + * `yay` 的二进制文件除了 `pacman` 以外别无依赖 + * 提供先进的包依赖解决方案,以及在编译安装之后移除编译时的依赖 + * 当在 `/etc/pacman.conf` 文件配置中启用了色彩时支持色彩输出 + * `yay` 可被配置成只支持 AUR 或者 repo 里的软件包 + +安装 yay: + +你可以从 `git` 克隆并编译安装。 + +``` +git clone https://aur.archlinux.org/yay.git +cd yay +makepkg -si +``` + +使用 yay: + +搜索: + +``` +yay -Ss +``` + +安装: + +``` +yay -S +``` + +#### 3、 pakku + +[Pakku][11] 是另一个还处于开发早期的 pacman 封装,虽然它还处于开放早期,但这不说明它逊于其它任何 AUR 助手。Pakku 能很好地支持从 AUR 搜索和安装,并且也可以在安装后移除不必要的编译依赖。 + +pakku 的特性: + + * 从 AUR 搜索和安装软件 + * 检视不同构建之间的文件和变化 + * 从官方仓库编译,并事后移除编译依赖 + * 获取 PKGBUILD 以及 pacman 整合 + * 类 pacman 的用户界面和选项支持 + * 支持pacman 配置文件以及无需 PKGBUILD 源 + +安装 pakku: + +``` +git clone https://aur.archlinux.org/pakku.git +cd pakku +makepkg -si +``` + +使用 pakku: + +搜索: + +``` +pakku -Ss spotify +``` + +安装: + +``` +pakku -S spotify +``` + +#### 4、 aurutils + +[aurutils][12] 本质上是一堆使用 AUR 的自动化脚本的集合。它可以搜索 AUR、检查更新,并且解决包依赖。 + +aurutils 的特性: + + * aurutils 使用本地仓库以支持 pacman 文件,所有的包都支持 `–asdeps` + * 不同的任务可以有多个仓库 + * `aursync -u` 一键同步本地代码库 + * `aursearch` 搜索提供 pkgbase、长格式和 raw 支持 + * 能忽略指定包 + +安装 aurutils: + +``` +git clone https://aur.archlinux.org/aurutils.git +cd aurutils +makepkg -si +``` + +使用 aurutils: + +搜索: + +``` +aurutils -Ss +``` + +安装: + +``` +aurutils -S +``` + +所有这些包,在有 Yaourt 或者其它 AUR 助手的情况下都可以直接安装。 + +### 写在最后 + +Arch Linux 有着[很多 AUR 助手][4] 可以自动完成 AUR 各方面的日常任务。很多用户依然使用 Yaourt 来完成 AUR 相关任务,每个人都有自己不一样的偏好,欢迎留言告诉我们你在 Arch 里使用什么,又有什么心得? + +-------------------------------------------------------------------------------- + +via: https://itsfoss.com/best-aur-helpers/ + +作者:[Ambarish Kumar][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[Moelf](https://github.com/Moelf) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://itsfoss.com/author/ambarish/ +[1]:https://wiki.archlinux.org/index.php/Arch_User_Repository +[2]:https://www.archlinux.org/ +[3]:https://wiki.archlinux.org/index.php/pacman +[4]:https://wiki.archlinux.org/index.php/AUR_helpers +[5]:https://wiki.archlinux.org/index.php/AUR_helpers#Comparison_table +[6]:https://www.reddit.com/r/archlinux/comments/4azqyb/whats_so_bad_with_yaourt/ +[7]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/06/no-yaourt-arch-800x450.jpeg +[8]:https://github.com/polygamma/aurman +[9]:https://github.com/polygamma/aurman/wiki/Using-aurman-as-dependency-solver +[10]:https://github.com/Jguer/yay +[11]:https://github.com/kitsunyan/pakku +[12]:https://github.com/AladW/aurutils diff --git a/published/201808/20180623 Intercepting and Emulating Linux System Calls with Ptrace - null program.md b/published/201808/20180623 Intercepting and Emulating Linux System Calls with Ptrace - null program.md new file mode 100644 index 0000000000..90b2310a32 --- /dev/null +++ b/published/201808/20180623 Intercepting and Emulating Linux System Calls with Ptrace - null program.md @@ -0,0 +1,292 @@ +使用 Ptrace 去拦截和仿真 Linux 系统调用 +====== + +`ptrace(2)`(“进程跟踪process trace)系统调用通常都与调试有关。它是类 Unix 系统上通过原生调试器监测被调试进程的主要机制。它也是实现 [strace][1](系统调用跟踪system call trace)的常见方法。使用 Ptrace,跟踪器可以暂停被跟踪进程,[检查和设置寄存器和内存][2],监视系统调用,甚至可以拦截intercepting系统调用。 + +通过拦截功能,意味着跟踪器可以篡改系统调用参数,篡改系统调用的返回值,甚至阻塞某些系统调用。言外之意就是,一个跟踪器本身完全可以提供系统调用服务。这是件非常有趣的事,因为这意味着**一个跟踪器可以仿真一个完整的外部操作系统**,而这些都是在没有得到内核任何帮助的情况下由 Ptrace 实现的。 + +问题是,在同一时间一个进程只能被一个跟踪器附着,因此在那个进程的调试期间,不可能再使用诸如 GDB 这样的工具去仿真一个外部操作系统。另外的问题是,仿真系统调用的开销非常高。 + +在本文中,我们将专注于 x86-64 [Linux 的 Ptrace][3],并将使用一些 Linux 专用的扩展。同时,在本文中,我们将忽略掉一些错误检查,但是完整的源代码仍然会包含这些错误检查。 + +本文中的可直接运行的示例代码在这里: + +### strace + +在进入到最有趣的部分之前,我们先从回顾 strace 的基本实现来开始。它[不是 DTrace][4],但 strace 仍然非常有用。 + +Ptrace 一直没有被标准化。它的接口在不同的操作系统上非常类似,尤其是在核心功能方面,但是在不同的系统之间仍然存在细微的差别。`ptrace(2)` 的原型基本上应该像下面这样,但特定的类型可能有些差别。 + +``` +long ptrace(int request, pid_t pid, void *addr, void *data); +``` + +`pid` 是被跟踪进程的 ID。虽然**同一个时间**只有一个跟踪器可以附着到该进程上,但是一个跟踪器可以附着跟踪多个进程。 + +`request` 字段选择一个具体的 Ptrace 函数,比如 `ioctl(2)` 接口。对于 strace,只需要两个: + +* `PTRACE_TRACEME`:这个进程被它的父进程跟踪。 +* `PTRACE_SYSCALL`:继续跟踪,但是在下一下系统调用入口或出口时停止。 +* `PTRACE_GETREGS`:取得被跟踪进程的寄存器内容副本。 + +另外两个字段,`addr` 和 `data`,作为所选的 Ptrace 函数的一般参数。一般情况下,可以忽略一个或全部忽略,在那种情况下,传递零个参数。 + +strace 接口实质上是前缀到另一个命令之前。 + +``` +$ strace [strace options] program [arguments] +``` + +最小化的 strace 不需要任何选项,因此需要做的第一件事情是 —— 假设它至少有一个参数 —— 在 `argv` 尾部的 `fork(2)` 和 `exec(2)` 被跟踪进程。但是在加载目标程序之前,新的进程将告知内核,目标程序将被它的父进程继续跟踪。被跟踪进程将被这个 Ptrace 系统调用暂停。 + +``` +pid_t pid = fork(); +switch (pid) { + case -1: /* error */ + FATAL("%s", strerror(errno)); + case 0: /* child */ + ptrace(PTRACE_TRACEME, 0, 0, 0); + execvp(argv[1], argv + 1); + FATAL("%s", strerror(errno)); +} +``` + +父进程使用 `wait(2)` 等待子进程的 `PTRACE_TRACEME`,当 `wait(2)` 返回后,子进程将被暂停。 + +``` +waitpid(pid, 0, 0); +``` + +在允许子进程继续运行之前,我们告诉操作系统,被跟踪进程和它的父进程应该一同被终止。一个真实的 strace 实现可能会设置其它的选择,比如: `PTRACE_O_TRACEFORK`。 + +``` +ptrace(PTRACE_SETOPTIONS, pid, 0, PTRACE_O_EXITKILL); +``` + +剩余部分就是一个简单的、无休止的循环了,每循环一次捕获一个系统调用。循环体总共有四步: + +1. 等待进程进入下一个系统调用。 +2. 输出系统调用的一个描述。 +3. 允许系统调用去运行并等待返回。 +4. 输出系统调用返回值。 + +这个 `PTRACE_SYSCALL` 请求被用于等待下一个系统调用时开始,和等待那个系统调用退出。和前面一样,需要一个 `wait(2)` 去等待被跟踪进程进入期望的状态。 + +``` +ptrace(PTRACE_SYSCALL, pid, 0, 0); +waitpid(pid, 0, 0); +``` + +当 `wait(2)` 返回时,进行了系统调用的线程的寄存器中写入了该系统调用的系统调用号及其参数。尽管如此,*操作系统仍然没有为这个系统调用提供服务*。这个细节对后续操作很重要。 + +接下来的一步是采集系统调用信息。这是各个系统架构不同的地方。在 x86-64 上,[系统调用号是在 `rax` 中传递的][5],而参数(最多 6 个)是在 `rdi`、`rsi`、`rdx`、`r10`、`r8` 和 `r9` 中传递的。这些寄存器是由另外的 Ptrace 调用读取的,不过这里再也不需要 `wait(2)` 了,因为被跟踪进程的状态再也不会发生变化了。 + +``` +struct user_regs_struct regs; +ptrace(PTRACE_GETREGS, pid, 0, ®s); +long syscall = regs.orig_rax; + +fprintf(stderr, "%ld(%ld, %ld, %ld, %ld, %ld, %ld)", + syscall, + (long)regs.rdi, (long)regs.rsi, (long)regs.rdx, + (long)regs.r10, (long)regs.r8, (long)regs.r9); +``` + +这里有一个警告。由于 [内核的内部用途][6],系统调用号是保存在 `orig_rax` 中而不是 `rax` 中。而所有的其它系统调用参数都是非常简单明了的。 + +接下来是它的另一个 `PTRACE_SYSCALL` 和 `wait(2)`,然后是另一个 `PTRACE_GETREGS` 去获取结果。结果保存在 `rax` 中。 + +``` +ptrace(PTRACE_GETREGS, pid, 0, ®s); +fprintf(stderr, " = %ld\n", (long)regs.rax); +``` + +这个简单程序的输出也是非常粗糙的。这里的系统调用都没有符号名,并且所有的参数都是以数字形式输出,甚至是一个指向缓冲区的指针也是如此。更完整的 strace 输出将能知道哪个参数是指针,并使用 `process_vm_readv(2)` 从被跟踪进程中读取哪些缓冲区,以便正确输出它们。 + +然而,这些仅仅是系统调用拦截的基础工作。 + +### 系统调用拦截 + +假设我们想使用 Ptrace 去实现如 OpenBSD 的 [`pledge(2)`][7] 这样的功能,它是 [一个进程承诺pledge只使用一套受限的系统调用][8]。初步想法是,许多程序一般都有一个初始化阶段,这个阶段它们都需要进行许多的系统访问(比如,打开文件、绑定套接字、等等)。初始化完成以后,它们进行一个主循环,在主循环中它们处理输入,并且仅使用所需的、很少的一套系统调用。 + +在进入主循环之前,一个进程可以限制它自己只能运行所需要的几个操作。如果 [程序有缺陷][9],能够通过恶意的输入去利用该缺陷,这个**承诺**可以有效地限制漏洞利用的实现。 + +使用与 strace 相同的模型,但不是输出所有的系统调用,我们既能够阻塞某些系统调用,也可以在它的行为异常时简单地终止被跟踪进程。终止它很容易:只需要在跟踪器中调用 `exit(2)`。因此,它也可以被设置为去终止被跟踪进程。阻塞系统调用和允许子进程继续运行都只是些雕虫小技而已。 + +最棘手的部分是**当系统调用启动后没有办法去中断它**。当跟踪器在入口从 `wait(2)` 中返回到系统调用时,从一开始停止一个系统调用的仅有方式是,终止被跟踪进程。 + +然而,我们不仅可以“搞乱”系统调用的参数,也可以改变系统调用号本身,将它修改为一个不存在的系统调用。返回时,在 `errno` 中 [通过正常的内部信号][10],我们就可以报告一个“友好的”错误信息。 + +``` +for (;;) { + /* Enter next system call */ + ptrace(PTRACE_SYSCALL, pid, 0, 0); + waitpid(pid, 0, 0); + + struct user_regs_struct regs; + ptrace(PTRACE_GETREGS, pid, 0, ®s); + + /* Is this system call permitted? */ + int blocked = 0; + if (is_syscall_blocked(regs.orig_rax)) { + blocked = 1; + regs.orig_rax = -1; // set to invalid syscall + ptrace(PTRACE_SETREGS, pid, 0, ®s); + } + + /* Run system call and stop on exit */ + ptrace(PTRACE_SYSCALL, pid, 0, 0); + waitpid(pid, 0, 0); + + if (blocked) { + /* errno = EPERM */ + regs.rax = -EPERM; // Operation not permitted + ptrace(PTRACE_SETREGS, pid, 0, ®s); + } +} +``` + +这个简单的示例只是检查了系统调用是否违反白名单或黑名单。而它们在这里并没有差别,比如,允许文件以只读而不是读写方式打开(`open(2)`),允许匿名内存映射但不允许非匿名映射等等。但是这里仍然没有办法去动态撤销被跟踪进程的权限。 + +跟踪器与被跟踪进程如何沟通?使用人为的系统调用! + +### 创建一个人为的系统调用 + +对于我的这个类似于 pledge 的系统调用 —— 我可以通过调用 `xpledge()` 将它与真实的系统调用区分开 —— 我设置 10000 作为它的系统调用号,这是一个非常大的数字,真实的系统调用中从来不会用到它。 + +``` +#define SYS_xpledge 10000 +``` + +为演示需要,我同时构建了一个非常小的接口,这在实践中并不是个好主意。它与 OpenBSD 的 `pledge(2)` 稍有一些相似之处,它使用了一个 [字符串接口][11]。*事实上*,设计一个健壮且安全的权限集是非常复杂的,正如在 `pledge(2)` 的手册页面上所显示的那样。下面是对被跟踪进程的系统调用的完整接口*和*实现: + +``` +#define _GNU_SOURCE +#include + +#define XPLEDGE_RDWR (1 << 0) +#define XPLEDGE_OPEN (1 << 1) + +#define xpledge(arg) syscall(SYS_xpledge, arg) +``` + +如果给它传递个参数 0 ,仅允许一些基本的系统调用,包括那些用于去分配内存的系统调用(比如 `brk(2)`)。 `PLEDGE_RDWR` 位允许 [各种][12] 读和写的系统调用(`read(2)`、`readv(2)`、`pread(2)`、`preadv(2)` 等等)。`PLEDGE_OPEN` 位允许 `open(2)`。 + +为防止发生提升权限的行为,`pledge()` 会拦截它自己 —— 但这样也防止了权限撤销,以后再细说这方面内容。 + +在 xpledge 跟踪器中,我需要去检查这个系统调用: + +``` +/* Handle entrance */ +switch (regs.orig_rax) { + case SYS_pledge: + register_pledge(regs.rdi); + break; +} +``` + +操作系统将返回 `ENOSYS`(函数尚未实现),因为它不是一个*真实的*系统调用。为此在退出时我用一个 `success(0)` 去覆写它。 + +``` +/* Handle exit */ +switch (regs.orig_rax) { + case SYS_pledge: + ptrace(PTRACE_POKEUSER, pid, RAX * 8, 0); + break; +} +``` + +我写了一小段测试程序去打开 `/dev/urandom`,做一个读操作,尝试去承诺后,然后试着第二次打开 `/dev/urandom`,然后确认它能够读取原始的 `/dev/urandom` 文件描述符。在没有承诺跟踪器的情况下运行,输出如下: + +``` +$ ./example +fread("/dev/urandom")[1] = 0xcd2508c7 +XPledging... +XPledge failed: Function not implemented +fread("/dev/urandom")[2] = 0x0be4a986 +fread("/dev/urandom")[1] = 0x03147604 +``` + +做一个无效的系统调用并不会让应用程序崩溃。它只是失败,这是一个很方便的返回方式。当它在跟踪器下运行时,它的输出如下: + +``` +$ ./xpledge ./example +fread("/dev/urandom")[1] = 0xb2ac39c4 +XPledging... +fopen("/dev/urandom")[2]: Operation not permitted +fread("/dev/urandom")[1] = 0x2e1bd1c4 +``` + +这个承诺很成功,第二次的 `fopen(3)` 并没有进行,因为跟踪器用一个 `EPERM` 阻塞了它。 + +可以将这种思路进一步发扬光大,比如,改变文件路径或返回一个假的结果。一个跟踪器可以很高效地 chroot 它的被跟踪进程,通过一个系统调用将任意路径传递给 root 从而实现 chroot 路径。它甚至可以对用户进行欺骗,告诉用户它以 root 运行。事实上,这些就是 [Fakeroot NG][13] 程序所做的事情。 + +### 仿真外部系统 + +假设你不满足于仅拦截一些系统调用,而是想拦截*全部*系统调用。你就会有了 [一个打算在其它操作系统上运行的二进制程序][14],无需系统调用,这个二进制程序可以一直运行。 + +使用我在前面所描述的这些内容你就可以管理这一切。跟踪器可以使用一个假冒的东西去代替系统调用号,允许它失败,以及为系统调用本身提供服务。但那样做的效率很低。其实质上是对每个系统调用做了三个上下文切换:一个是在入口上停止,一个是让系统调用总是以失败告终,还有一个是在系统调用退出时停止。 + +从 2005 年以后,对于这个技术,PTrace 的 Linux 版本有更高效的操作:`PTRACE_SYSEMU`。PTrace 仅在每个系统调用发出时停止*一次*,在允许被跟踪进程继续运行之前,由跟踪器为系统调用提供服务。 + +``` +for (;;) { + ptrace(PTRACE_SYSEMU, pid, 0, 0); + waitpid(pid, 0, 0); + + struct user_regs_struct regs; + ptrace(PTRACE_GETREGS, pid, 0, ®s); + + switch (regs.orig_rax) { + case OS_read: + /* ... */ + + case OS_write: + /* ... */ + + case OS_open: + /* ... */ + + case OS_exit: + /* ... */ + + /* ... and so on ... */ + } +} +``` + +从任何具有(足够)稳定的系统调用 ABI(LCTT 译注:应用程序二进制接口),在相同架构的机器上运行一个二进制程序时,你只需要 `PTRACE_SYSEMU` 跟踪器、一个加载器(用于代替 `exec(2)`),和这个二进制程序所需要(或仅运行静态的二进制程序)的任何系统库即可。 + +事实上,这听起来有点像一个有趣的周末项目。 + +**参见** + +- [给 Linux 内核克隆实现一个 OpenBSD 承诺][15] + +-------------------------------------------------------------------------------- + +via: http://nullprogram.com/blog/2018/06/23/ + +作者:[Chris Wellons][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[qhwdw](https://github.com/qhwdw) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: http://nullprogram.com +[1]: https://blog.plover.com/Unix/strace-groff.html +[2]: http://nullprogram.com/blog/2016/09/03/ +[3]: http://man7.org/linux/man-pages/man2/ptrace.2.html +[4]: http://nullprogram.com/blog/2018/01/17/ +[5]: http://nullprogram.com/blog/2015/05/15/ +[6]: https://stackoverflow.com/a/6469069 +[7]: https://man.openbsd.org/pledge.2 +[8]: http://www.openbsd.org/papers/hackfest2015-pledge/mgp00001.html +[9]: http://nullprogram.com/blog/2017/07/19/ +[10]: http://nullprogram.com/blog/2016/09/23/ +[11]: https://www.tedunangst.com/flak/post/string-interfaces +[12]: http://nullprogram.com/blog/2017/03/01/ +[13]: https://fakeroot-ng.lingnu.com/index.php/Home_Page +[14]: http://nullprogram.com/blog/2017/11/30/ +[15]: https://www.youtube.com/watch?v=uXgxMDglxVM diff --git a/published/201808/20180627 CIP- Keeping the Lights On with Linux.md b/published/201808/20180627 CIP- Keeping the Lights On with Linux.md new file mode 100644 index 0000000000..739fba2da0 --- /dev/null +++ b/published/201808/20180627 CIP- Keeping the Lights On with Linux.md @@ -0,0 +1,55 @@ +CIP:延续 Linux 之光 +====== + +> CIP 的目标是创建一个基本的系统,使用开源软件来为我们现代社会的基础设施提供动力。 + +![](https://www.linux.com/sites/lcom/files/styles/rendered_file/public/cip-lights.jpg?itok=6LAUoIzt) + + +现如今,现代民用基础设施遍及各处 —— 发电厂、雷达系统、交通信号灯、水坝和天气系统等。这些基础设施项目已然存在数十年,这些设施还将继续提供更长时间的服务,所以安全性和使用寿命是至关重要的。 + +并且,其中许多系统都是由 Linux 提供支持,它为技术提供商提供了对这些问题的更多控制。然而,如果每个提供商都在构建自己的解决方案,这可能会导致分散和重复工作。因此,[民用基础设施平台][1]Civil Infrastructure Platform(CIP)最首要的目标是创造一个开源基础层,提供给工业设施,例如嵌入式控制器或是网关设备。 + +担任 CIP 的技术指导委员会主席的 Yoshitake Kobayashi 说过,“我们在这个领域有一种非常保守的文化,因为一旦我们建立了一个系统,它必须得到长达十多年的支持,在某些情况下超过 60 年。这就是为什么这个项目被创建的原因,因为这个行业的每个使用者都面临同样的问题,即能够长时间地使用 Linux。” + +CIP 的架构是创建一个非常基础的系统,以在控制器上使用开源软件。其中,该基础层包括 Linux 内核和一系列常见的开源软件如 libc、busybox 等。由于软件的使用寿命是一个最主要的问题,CIP 选择使用 Linux 4.4 版本的内核,这是一个由 Greg Kroah-Hartman 维护的长期支持版本。 + +### 合作 + +由于 CIP 有上游优先政策,因此他们在项目中需要的代码必须位于上游内核中。为了与内核社区建立积极的反馈循环,CIP 聘请 Ben Hutchings 作为 CIP 的官方维护者。Hutchings 以他在 Debian LTS 版本上所做的工作而闻名,这也促成了 CIP 与 Debian 项目之间的官方合作。 + +在新的合作下,CIP 将使用 Debian LTS 版本作为构建平台。 CIP 还将支持 Debian 长期支持版本(LTS),延长所有 Debian 稳定版的生命周期。CIP 还将与 Freexian 进行密切合作,后者是一家围绕 Debian LTS 版本提供商业服务的公司。这两个组织将专注于嵌入式系统的开源软件的互操作性、安全性和维护。CIP 还会为一些 Debian LTS 版本提供资金支持。 + +Debian 项目负责人 Chris Lamb 表示,“我们对此次合作以及 CIP 对 Debian LTS 项目的支持感到非常兴奋,这样将使支持周期延长至五年以上。我们将一起致力于为用户提供长期支持,并为未来的城市奠定基础。” + +### 安全性 + +Kobayashi 说过,其中最需要担心的是安全性。虽然出于明显的安全原因,大部分民用基础设施没有接入互联网(你肯定不想让一座核电站连接到互联网),但也存在其他风险。 + +仅仅是系统本身没有连接到互联网,这并不意味着能避开所有危险。其他系统,比如个人移动电脑也能够通过接入互联网而间接入侵到本地系统中。如若有人收到一封带有恶意文件作为电子邮件的附件,这将会“污染”系统内部的基础设备。 + +因此,至关重要的是保持运行在这些控制器上的所有软件是最新的并且完全修补的。为了确保安全性,CIP 还向后移植了内核自我保护Kernel Self Protection(KSP)项目的许多组件。CIP 还遵循最严格的网络安全标准之一 —— IEC 62443,该标准定义了软件的流程和相应的测试,以确保系统更安全。 + +### 展望未来 + +随着 CIP 日趋成熟,官方正在加大与各个 Linux 提供商的合作力度。除了与 Debian 和 freexian 的合作外,CIP 最近还邀请了企业 Linux 操作系统供应商 Cybertrust Japan Co., Ltd. 作为新的银牌成员。 + +Cybertrust 与其他行业领军者合作,如西门子、东芝、Codethink、日立、Moxa、Plat'Home 和瑞萨,致力于为未来数十年打造一个可靠、安全的基于 Linux 的嵌入式软件平台。 + +这些公司在 CIP 的保护下所进行的工作,将确保管理我们现代社会中的民用基础设施的完整性。 + +想要了解更多信息,请访问 [民用基础设施官网][1]。 + +-------------------------------------------------------------------------------- + +via: https://www.linux.com/blog/2018/6/cip-keeping-lights-linux + +作者:[Swapnil Bhartiya][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[wyxplus](https://github.com/wyxplus) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.linux.com/users/arnieswap +[1]:https://www.cip-project.org/ diff --git a/published/201808/20180702 How to edit Adobe InDesign files with Scribus and Gedit.md b/published/201808/20180702 How to edit Adobe InDesign files with Scribus and Gedit.md new file mode 100644 index 0000000000..ae972f1943 --- /dev/null +++ b/published/201808/20180702 How to edit Adobe InDesign files with Scribus and Gedit.md @@ -0,0 +1,130 @@ +如何用 Scribus 和 Gedit 编辑 Adobe InDesign 文件 +====== + +> 学习一下这些用开源工具编辑 InDesign 文件的方案。 + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/open-indesign-scribus-gedit-graphic.jpg?itok=OPJaGdA5) + +要想成为一名优秀的平面设计师,您必须善于使用各种各样专业的工具。现在,对大多数设计师来说,最常用的工具是 Adobe 全家桶Adobe Creative Suite。 + +但是,有时候使用开源工具能够帮您摆脱困境。比如,您正在使用一台公共打印机打印一份用 Adobe InDesign 创建的文件。这时,您需要对文件做一些简单的改动(比如,改正一个错别字),但您无法立刻使用 Adobe 套件。虽然这种情况很少见,但电子杂志制作软件 [Scribus][1] 和文本编辑器 [Gedit][2] 等开源工具可以节约您的时间。 + +在本文中,我将向您展示如何使用 Scribus 和 Gedit 编辑 Adobe InDesign 文件。请注意,还有许多其他开源平面设计软件可以用来代替 Adobe InDesign 或者结合使用。详情请查看我的文章:[昂贵的工具(从来!)不是平面设计的唯一选择][3] 以及 [两个开源 Adobe InDesign 脚本][4]. + +在编写本文的时候,我阅读了一些关于如何使用开源软件编辑 InDesign 文件的博客,但没有找到有用的文章。我尝试了两个解决方案。一个是:在 InDesign 创建一个 EPS 并在文本编辑器 Scribus 中将其以可编辑文件打开,但这不起作用。另一个是:从 InDesign 中创建一个 IDML(一种旧的 InDesign 文件格式)文件,并在 Scribus 中打开它。第二种方法效果更好,也是我在下文中使用的解决方法。 + +### 编辑名片 + +我尝试在 Scribus 中打开和编辑 InDesign 名片文件的效果很好。唯一的问题是字母间的间距有些偏移,以及我用倒过来的 ‘J’ 来创建 “Jeff” 中的 ‘f’ 被翻转。其他部分,像样式和颜色等都完好无损。 + +![Business card in Adobe InDesign][6] + +*图:在 Adobe InDesign 中编辑名片。* + +![InDesign IDML file opened in Scribus][8] + +*图:在 Scribus 中打开 InDesign IDML 文件。* + +### 删除带页码的书籍中的副本 + +书籍的转换并不顺利。书籍的正文还 OK,但当我用 Scribus 打开 InDesign 文件,目录、页脚和一些首字下沉的段落都出现问题。不过至少,它是一个可编辑的文档。其中一个问题是一些块引用中的文字变成了默认的 Arial 字体,这是因为字体样式(似乎来自其原始的 Word 文档)的优先级比段落样式高。这个问题容易解决。 + +![Book layout in InDesign][10] + +*图:InDesign 中的书籍布局。* + +![InDesign IDML file of book layout opened in Scribus][12] + +*图:用 Scribus 打开 InDesign IDML 文件的书籍布局。* + +当我试图选择并删除一页文本的时候,发生了奇异事件。我把光标放在文本中,按下 `Command + A`(“全选”的快捷键)。表面看起来高亮显示了一页文本,但事实并非如此! + +![Selecting text in Scribus][14] + +*图:Scribus 中被选中的文本。* + +当我按下“删除”键,整个文本(不只是高亮的部分)都消失了。 + +![Both pages of text deleted in Scribus][16] + +*图:两页文本都被删除了。* + +然后,更奇异的事情发生了……我按下 `Command + Z` 键来撤回删除操作,文本恢复,但文本格式全乱套了。 + +![Undo delete restored the text, but with bad formatting.][18] + +*图:Command+Z (撤回删除操作) 恢复了文本,但格式乱套了。* + +### 用文本编辑器打开 InDesign 文件 + +当您用普通的记事本(比如,Mac 中的 TextEdit)分别打开 Scribus 文件和 InDesign 文件,会发现 Scribus 文件是可读的,而 InDesign 文件全是乱码。 + +您可以用 TextEdit 对两者进行更改并成功保存,但得到的文件是损坏的。下图是当我用 InDesign 打开编辑后的文件时的报错。 + +![InDesign error message][20] + +*图:InDesign 的报错。* + +我在 Ubuntu 系统上用文本编辑器 Gedit 编辑 Scribus 时得到了更好的结果。我从命令行启动了 Gedit,然后打开并编辑 Scribus 文件,保存后,再次使用 Scribus 打开文件时,我在 Gedit 中所做的更改都成功显示在 Scribus 中。 + +![Editing Scribus file in Gedit][22] + +*图:用 Gedit 编辑 Scribus 文件。* + +![Result of the Gedit edit in Scribus][24] + +*图:用 Scribus 打开 Gedit 编辑过的文件。* + +当您正准备打印的时候,客户打来电话说有一个错别字需要更改,此时您不需要苦等客户爸爸发来新的文件,只需要用 Gedit 打开 Scribus 文件,改正错别字,继续打印。 + +### 把图像拖拽到 ID 文件中 + +我将 InDesign 文档另存为 IDML 文件,这样我就可以用 Scribus 往其中拖进一些 PDF 文档。似乎 Scribus 并不能像 InDesign 一样把 PDF 文档拖拽进去。于是,我把 PDF 文档转换成 JPG 格式的图片然后导入到 Scribus 中,成功了。但这么做的结果是,将 IDML 文档转换成 PDF 格式后,文件大小非常大。 + +![Huge PDF file][26] + +*图:把 Scribus 转换成 PDF 时得到一个非常大的文件*。 + +我不确定为什么会这样——这个坑留着以后再填吧。 + +您是否有使用开源软件编辑平面图形文件的技巧?如果有,请在评论中分享哦。 + +------ + +via: https://opensource.com/article/18/7/adobe-indesign-open-source-tools + +作者:[Jeff Macharyas][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[XiatianSummer](https://github.com/XiatianSummer) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://opensource.com/users/rikki-endsley +[1]: https://www.scribus.net/ +[2]: https://wiki.gnome.org/Apps/Gedit +[3]: https://opensource.com/life/16/8/open-source-alternatives-graphic-design +[4]: https://opensource.com/article/17/3/scripts-adobe-indesign +[5]: /file/402516 +[6]: https://opensource.com/sites/default/files/uploads/1-business_card_designed_in_adobe_indesign_cc.png "Business card in Adobe InDesign" +[7]: /file/402521 +[8]: https://opensource.com/sites/default/files/uploads/2-indesign_.idml_file_opened_in_scribus.png "InDesign IDML file opened in Scribus" +[9]: /file/402531 +[10]: https://opensource.com/sites/default/files/uploads/3-book_layout_in_indesign.png "Book layout in InDesign" +[11]: /file/402536 +[12]: https://opensource.com/sites/default/files/uploads/4-indesign_.idml_file_of_book_opened_in_scribus.png "InDesign IDML file of book layout opened in Scribus" +[13]: /file/402541 +[14]: https://opensource.com/sites/default/files/uploads/5-command-a_in_the_scribus_file.png "Selecting text in Scribus" +[15]: /file/402546 +[16]: https://opensource.com/sites/default/files/uploads/6-deleted_text_in_scribus.png "Both pages of text deleted in Scribus" +[17]: /file/402551 +[18]: https://opensource.com/sites/default/files/uploads/7-command-z_in_scribus.png "Undo delete restored the text, but with bad formatting." +[19]: /file/402556 +[20]: https://opensource.com/sites/default/files/uploads/8-indesign_error_message.png "InDesign error message" +[21]: /file/402561 +[22]: https://opensource.com/sites/default/files/uploads/9-scribus_edited_in_gedit_on_linux.png "Editing Scribus file in Gedit" +[23]: /file/402566 +[24]: https://opensource.com/sites/default/files/uploads/10-scribus_opens_after_gedit_changes.png "Result of the Gedit edit in Scribus" +[25]: /file/402571 +[26]: https://opensource.com/sites/default/files/uploads/11-large_pdf_size.png "Huge PDF file" + diff --git a/published/201808/20180703 How to make a career move from proprietary to open source technology.md b/published/201808/20180703 How to make a career move from proprietary to open source technology.md new file mode 100644 index 0000000000..0e4d89f3bd --- /dev/null +++ b/published/201808/20180703 How to make a career move from proprietary to open source technology.md @@ -0,0 +1,60 @@ +怎样实现由专有环境向开源环境的职业转变 +====== + +> 学习一点转变到新的技术文化的小技巧。 + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/open%20source_collaboration_0.png?itok=YEl_GXbv) + +作为一名软件工程师,我的职业生涯是从北电开始的,在这里我开发出了电信级的电话交换机所用的专有软件。 即使我已经在大学中学习了 Pascal 语言,公司还是给我进行了以 C 语言为基础是专有编程语言培养。在公司中我使用的也是专有操作系统和专有版本控制软件。 + +我很享受专有环境下的工作,并有幸接触了很多有趣的项目,这样过了很多年,直到一场招聘会,我遇到了事业转折点。那时我受邀在当地一所中学的 STEM 行业座谈会进行演讲,给学生们讲述了作为一名软件工程师的主要工作内容和责任,一名学生问我:“这些事是你一直梦想要做的吗?你热爱你现在的工作吗?” + +每次领导问我这个问题时,保险起见,我都会回答他,“我当然热爱工作了!”但从来没有一名还在读六年级的单纯的 STEM 小爱好者问过我这个问题。我的回答还是一样,“我当然喜欢!” + +我确实很热爱我当时的事业,但那名学生的话让我忍不住思考,我开始重新审视我的事业,重新审视专有环境。在我的领域里我如鱼得水,但这也有局限性:我只能用代码来定义我的领域。我忍不住反思,这些年我在专有环境中学到了不同的技术了吗?在同行中我的技能组还算得上先进吗?我有没有混日子?我真的想继续为这项事业奋斗吗? + +我想了很多,忍不住问自己:当年的激情和创意还在吗? + +时间不会停止,但我的生活发生了改变。我离开了北电 ,打算休息一段时间来陪陪我的家人。 + +在我准备返回工作岗位时,那个小朋友的话又在我的脑海中响起,这真的是我想要的工作吗?我投了很多份简历,有一个岗位是我最中意的,但那家公司的回复是,他们想要的是拥有五年及以上的 Java 和 Python 工作经验的人。在过去十五年里我以之为生的知识和技术看起来已经过时了。 + +### 机遇与挑战 + +我的第一项挑战是学会在新的环境下应用我先前在封闭环境学到的技能。IT 行业由专有环境转向开源后发生了天翻地覆的变化。我打算先自学眼下最需要的 Python 。接触 Python 后我意识到,我需要一个项目来证明自己的能力,让自己更具有竞争力。 + +我的第二个挑战是怎么获得 Python 相关的项目经验。我丈夫和之前的同事都向我推荐了开源软件,通过谷歌搜索我发现网上有许许多多的开源项目,它们分别来源于一个人的小团队、50 人左右的团队,还有跨国的百人大团队。 + +在 Github 上我用相关专业术语搜索出了许多适合我的项目。综合我的兴趣和网络相关的工作经验,我打算把第一个项目贡献给 OpenStack。 我还注意到了 [Outreachy][1] 项目,它为不具备相关技术基础的人员提供三个月的实习期。 + +### 经验与教训 + +我学到的第一件事是我发现可以通过许多方式进行贡献。不论是文件编制、用户设计,还是测试用例,都是贡献的形式。我在探索中丰富了我的技能组,根本用不着 5 年的时间,只需要在开源平台上接受委托,之后做出成果。 + +在我为 OpenStack 做出的第一个贡献被合并、发表后,我正式成为了 Outreachy 项目的一员。 Outreachy 项目最好的一点是,项目分配给我的导师能够引领我在开源世界中找到方向。 + +下面还有三个宝贵的提示: + +**持之以恒** 你需要找到最适合你核心技能组的项目,当然,最好有行为准则和新人入门指南,这样的项目比较适合初学者加入。找到了合适的项目你可以持之以恒地在社区中进行贡献。 + +**不厌其烦** 适应开源环境需要一段时间。融入开源社区需要时间。进行深思熟虑的反馈需要时间。阅读反馈并经行改进也需要时间。在这其中你需要耐心等待。 + +**参与其中** 在开源社区,从事什么领域或技术的工作不需要特殊批准,你可以自己选择工作的领域,并深入其中。 + +7 月 16-19 日,俄勒冈州波特兰,第 20 届 [开源大会][3] 上,Petra Sargent 将为您展示:[老狗也能学会新把戏——封闭环境工作者如何适应开源环境][2]。 + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/7/career-move + +作者:[Petra Sargent][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[Valoniakim](https://github.com/Valoniakim) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://opensource.com/users/psargent +[1]:https://www.outreachy.org/ +[2]:https://conferences.oreilly.com/oscon/oscon-or/public/schedule/speaker/307631 +[3]:https://conferences.oreilly.com/oscon/oscon-or diff --git a/published/201808/20180703 Why is Arch Linux So Challenging and What are Its Pros - Cons.md b/published/201808/20180703 Why is Arch Linux So Challenging and What are Its Pros - Cons.md new file mode 100644 index 0000000000..c41d1cd867 --- /dev/null +++ b/published/201808/20180703 Why is Arch Linux So Challenging and What are Its Pros - Cons.md @@ -0,0 +1,74 @@ +为什么 Arch Linux 如此“难弄”又有何优劣? +====== + +![](https://www.fossmint.com/wp-content/uploads/2018/07/Why-Arch-Linux-Is-Best.png) + +[Arch Linux][1] 于 **2002** 年发布,由 **Aaron Grifin** 领头,是当下最热门的 Linux 发行版之一。从设计上说,Arch Linux 试图给用户提供简单、最小化且优雅的体验,但它的目标用户群可不是怕事儿多的用户。Arch 鼓励参与社区建设,并且从设计上期待用户自己有学习操作系统的能力。 + +很多 Linux 老鸟对于 **Arch Linux** 会更了解,但电脑前的你可能只是刚开始打算把 Arch 当作日常操作系统来使用。虽然我也不是权威人士,但下面几点优劣是我认为你总会在使用中慢慢发现的。 + +### 1、优点: 定制属于你自己的 Linux 操作系统 + +大多数热门的 Linux 发行版(比如 **Ubuntu** 和 **Fedora**)很像一般我们会看到的预装系统,和 **Windows** 或者 **MacOS** 一样。但 Arch 则会更鼓励你去把操作系统配置的符合你的品味。如果你能顺利做到这点的话,你会得到一个每一个细节都如你所想的操作系统。 + +#### 缺点: 安装过程让人头疼 + +[Arch Linux 的安装 ][2] 别辟蹊径——因为你要花些时间来微调你的操作系统。你会在过程中了解到不少终端命令和组成你系统的各种软件模块——毕竟你要自己挑选安装什么。当然,你也知道这个过程少不了阅读一些文档/教程。 + +### 2、优点: 没有预装垃圾 + +鉴于 **Arch** 允许你在安装时选择你想要的系统部件,你再也不用烦恼怎么处理你不想要的一堆预装软件。作为对比,**Ubuntu** 会预装大量的软件和桌面应用——很多你不需要、甚至卸载之前都不知道它们存在的东西。 + +总而言之,**Arch Linux* 能省去大量的系统安装后时间。**Pacman**,是 Arch Linux 默认使用的优秀包管理组件。或者你也可以选择 [Pamac][3] 作为替代。 + +### 3、优点: 无需繁琐系统升级 + +**Arch Linux** 采用滚动升级模型,简直妙极了。这意味着你不需要操心升级了。一旦你用上了 Arch,持续的更新体验会让你和一会儿一个版本的升级说再见。只要你记得‘滚’更新(Arch 用语),你就一直会使用最新的软件包们。 + +#### 缺点: 一些升级可能会滚坏你的系统 + +虽然升级过程是完全连续的,你有时得留意一下你在更新什么。没人能知道所有软件的细节配置,也没人能替你来测试你的情况。所以如果你盲目更新,有时候你会滚坏你的系统。(LCTT 译注:别担心,你可以‘滚’回来 ;D ) + +### 4、优点: Arch 有一个社区基因 + +所有 Linux 用户通常有一个共同点:对独立自由的追求。虽然大多数 Linux 发行版和公司企业等挂钩极少,但也并非没有。比如 基于 **Ubuntu** 的衍生版本们不得不受到 Canonical 公司决策的影响。 + +如果你想让你的电脑更独立,那么 Arch Linux 是你的伙伴。不像大多数操作系统,Arch 完全没有商业集团的影响,完全由社区驱动。 + +### 5、优点: Arch Wiki 无敌 + +[Arch Wiki][4] 是一个无敌文档库,几乎涵盖了所有关于安装和维护 Arch 以及关于操作系统本身的知识。Arch Wiki 最厉害的一点可能是,不管你在用什么发行版,你多多少少可能都在 Arch Wiki 的页面里找到有用信息。这是因为 Arch 用户也会用别的发行版用户会用的东西,所以一些技巧和知识得以泛化。 + +### 6、优点: 别忘了 Arch 用户软件库 (AUR) + +[Arch 用户软件库][5]Arch User Repository (AUR)是一个来自社区的超大软件仓库。如果你找了一个还没有 Arch 的官方仓库里出现的软件,那你肯定能在 AUR 里找到社区为你准备好的包。 + +AUR 是由用户自发编译和维护的。Arch 用户也可以给每个包投票,这样后来者就能找到最有用的那些软件包了。 + +#### 最后: Arch Linux 适合你吗? + +**Arch Linux** 优点多于缺点,也有很多优缺点我无法在此一一叙述。安装过程很长,对非 Linux 用户来说也可能偏有些技术,但只要你投入一些时间和善用 Wiki,你肯定能迈过这道坎。 + +**Arch Linux** 是一个非常优秀的发行版——尽管它有一些复杂性。同时它也很受那些知道自己想要什么的用户的欢迎——只要你肯做点功课,有些耐心。 + +当你从零开始搭建完 Arch 的时候,你会掌握很多 GNU/Linux 的内部细节,也再也不会对你的电脑内部运作方式一无所知了。 + +欢迎读者们在评论区讨论你使用 Arch Linux 的优缺点?以及你曾经遇到过的一些挑战。 + +-------------------------------------------------------------------------------- + +via: https://www.fossmint.com/why-is-arch-linux-so-challenging-what-are-pros-cons/ + +作者:[Martins D. Okoi][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[Moelf](https://github.com/Moelf) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.fossmint.com/author/dillivine/ +[1]:https://www.archlinux.org/ +[2]:https://www.tecmint.com/arch-linux-installation-and-configuration-guide/ +[3]:https://www.fossmint.com/pamac-arch-linux-gui-package-manager/ +[4]:https://wiki.archlinux.org/ +[5]:https://wiki.archlinux.org/index.php/Arch_User_Repository diff --git a/published/201808/20180705 Testing Node.js in 2018.md b/published/201808/20180705 Testing Node.js in 2018.md new file mode 100644 index 0000000000..829aaf74de --- /dev/null +++ b/published/201808/20180705 Testing Node.js in 2018.md @@ -0,0 +1,322 @@ +测试 Node.js,2018 +============================================================ + +![](https://cdn-images-1.medium.com/max/1600/1*J3lGUOAGK-XdZMXwiHcI6w.png) + +超过 3 亿用户正在使用 [Stream][4]。这些用户全都依赖我们的框架,而我们十分擅长测试要放到生产环境中的任何东西。我们大部分的代码库是用 Go 语言编写的,剩下的部分则是用 Python 编写。 + +我们最新的展示应用,[Winds 2.0][5],是用 Node.js 构建的,很快我们就了解到测试 Go 和 Python 的常规方法并不适合它。而且,创造一个好的测试套件需要用 Node.js 做很多额外的工作,因为我们正在使用的框架没有提供任何内建的测试功能。 + +不论你用什么语言,要构建完好的测试框架可能都非常复杂。本文我们会展示 Node.js 测试过程中的困难部分,以及我们在 Winds 2.0 中用到的各种工具,并且在你要编写下一个测试集合时为你指明正确的方向。 + +### 为什么测试如此重要 + +我们都向生产环境中推送过糟糕的提交,并且遭受了其后果。碰到这样的情况不是好事。编写一个稳固的测试套件不仅仅是一个明智的检测,而且它还让你能够完全地重构代码,并自信重构之后的代码仍然可以正常运行。这在你刚刚开始编写代码的时候尤为重要。 + +如果你是与团队共事,达到测试覆盖率极其重要。没有它,团队中的其他开发者几乎不可能知道他们所做的工作是否导致重大变动(或破坏)。 + +编写测试同时会促进你和你的队友把代码分割成更小的片段。这让别人去理解你的代码和修改 bug 变得容易多了。产品收益变得更大,因为你能更早的发现 bug。 + +最后,没有测试,你的基本代码还不如一堆纸片。基本不能保证你的代码是稳定的。 + +### 困难的部分 + +在我看来,我们在 Winds 中遇到的大多数测试问题是 Node.js 中特有的。它的生态系统一直在变大。例如,如果你用的是 macOS,运行 `brew upgrade`(安装了 homebrew),你看到你一个新版本的 Node.js 的概率非常高。由于 Node.js 迭代频繁,相应的库也紧随其后,想要与最新的库保持同步非常困难。 + +以下是一些马上映入脑海的痛点: + +1. 在 Node.js 中进行测试是非常主观而又不主观的。人们对于如何构建一个测试架构以及如何检验成功有不同的看法。沮丧的是还没有一个黄金准则规定你应该如何进行测试。 +2. 有一堆框架能够用在你的应用里。但是它们一般都很精简,没有完好的配置或者启动过程。这会导致非常常见的副作用,而且还很难检测到;所以你最终会想要从零开始编写自己的测试执行平台test runner测试执行平台。 +3. 几乎可以保证你 _需要_ 编写自己的测试执行平台(马上就会讲到这一节)。 + +以上列出的情况不是理想的,而且这是 Node.js 社区应该尽管处理的事情。如果其他语言解决了这些问题,我认为也是作为广泛使用的语言, Node.js 解决这些问题的时候。 + +### 编写你自己的测试执行平台 + +所以……你可能会好奇test runner测试执行平台 _是_ 什么,说实话,它并不复杂。测试执行平台是测试套件中最高层的容器。它允许你指定全局配置和环境,还可以导入配置。可能有人觉得做这个很简单,对吧?别那么快下结论。 + +我们所了解到的是,尽管现在就有足够多的测试框架了,但没有一个测试框架为 Node.js 提供了构建你的测试执行平台的标准方式。不幸的是,这需要开发者来完成。这里有个关于测试执行平台的需求的简单总结: + +* 能够加载不同的配置(比如,本地的、测试的、开发的),并确保你 _永远不会_ 加载一个生产环境的配置 —— 你能想象出那样会出什么问题。 +* 播种数据库——产生用于测试的数据。必须要支持多种数据库,不论是 MySQL、PostgreSQL、MongoDB 或者其它任何一个数据库。 +* 能够加载配置(带有用于开发环境测试的播种数据的文件)。 + +开发 Winds 的时候,我们选择 Mocha 作为测试执行平台。Mocha 提供了简单并且可编程的方式,通过命令行工具(整合了 Babel)来运行 ES6 代码的测试。 + +为了进行测试,我们注册了自己的 Babel 模块引导器。这为我们提供了更细的粒度,更强大的控制,在 Babel 覆盖掉 Node.js 模块加载过程前,对导入的模块进行控制,让我们有机会在所有测试运行前对模块进行模拟。 + +此外,我们还使用了 Mocha 的测试执行平台特性,预先把特定的请求赋给 HTTP 管理器。我们这么做是因为常规的初始化代码在测试中不会运行(服务器交互是用 Chai HTTP 插件模拟的),还要做一些安全性检查来确保我们不会连接到生产环境数据库。 + +尽管这不是测试执行平台的一部分,有一个配置fixture加载器也是我们测试套件中的重要的一部分。我们试验过已有的解决方案;然而,我们最终决定编写自己的助手程序,这样它就能贴合我们的需求。根据我们的解决方案,在生成或手动编写配置时,通过遵循简单专有的协议,我们就能加载数据依赖很复杂的配置。 + +### Winds 中用到的工具 + +尽管过程很冗长,我们还是能够合理使用框架和工具,使得针对后台 API 进行的适当测试变成现实。这里是我们选择使用的工具: + +#### Mocha + +[Mocha][6],被称为 “运行在 Node.js 上的特性丰富的测试框架”,是我们用于该任务的首选工具。拥有超过 15K 的星标,很多支持者和贡献者,我们知道对于这种任务,这是正确的框架。 + +#### Chai + +然后是我们的断言库。我们选择使用传统方法,也就是最适合配合 Mocha 使用的 —— [Chai][7]。Chai 是一个用于 Node.js,适合 BDD 和 TDD 模式的断言库。拥有简单的 API,Chai 很容易整合进我们的应用,让我们能够轻松地断言出我们 _期望_ 从 Winds API 中返回的应该是什么。最棒的地方在于,用 Chai 编写测试让人觉得很自然。这是一个简短的例子: + +``` +describe('retrieve user', () => { + let user; + + before(async () => { + await loadFixture('user'); + user = await User.findOne({email: authUser.email}); + expect(user).to.not.be.null; + }); + + after(async () => { + await User.remove().exec(); + }); + + describe('valid request', () => { + it('should return 200 and the user resource, including the email field, when retrieving the authenticated user', async () => { + const response = await withLogin(request(api).get(`/users/${user._id}`), authUser); + + expect(response).to.have.status(200); + expect(response.body._id).to.equal(user._id.toString()); + }); + + it('should return 200 and the user resource, excluding the email field, when retrieving another user', async () => { + const anotherUser = await User.findOne({email: 'another_user@email.com'}); + + const response = await withLogin(request(api).get(`/users/${anotherUser.id}`), authUser); + + expect(response).to.have.status(200); + expect(response.body._id).to.equal(anotherUser._id.toString()); + expect(response.body).to.not.have.an('email'); + }); + + }); + + describe('invalid requests', () => { + + it('should return 404 if requested user does not exist', async () => { + const nonExistingId = '5b10e1c601e9b8702ccfb974'; + expect(await User.findOne({_id: nonExistingId})).to.be.null; + + const response = await withLogin(request(api).get(`/users/${nonExistingId}`), authUser); + expect(response).to.have.status(404); + }); + }); + +}); +``` + +#### Sinon + +拥有与任何单元测试框架相适应的能力,[Sinon][8] 是模拟库的首选。而且,精简安装带来的超级整洁的整合,让 Sinon 把模拟请求变成了简单而轻松的过程。它的网站有极其良好的用户体验,并且提供简单的步骤,供你将 Sinon 整合进自己的测试框架中。 + +#### Nock + +对于所有外部的 HTTP 请求,我们使用健壮的 HTTP 模拟库 [nock][9],在你要和第三方 API 交互时非常易用(比如说 [Stream 的 REST API][10])。它做的事情非常酷炫,这就是我们喜欢它的原因,除此之外关于这个精妙的库没有什么要多说的了。这是我们的速成示例,调用我们在 Stream 引擎中提供的 [personalization][11]: + +``` +nock(config.stream.baseUrl) + .get(/winds_article_recommendations/) + .reply(200, { results: [{foreign_id:`article:${article.id}`}] }); +``` + +#### Mock-require + +[mock-require][12] 库允许依赖外部代码。用一行代码,你就可以替换一个模块,并且当代码尝试导入这个库时,将会产生模拟请求。这是一个小巧但稳定的库,我们是它的超级粉丝。 + +#### Istanbul + +[Istanbul][13] 是 JavaScript 代码覆盖工具,在运行测试的时候,通过模块钩子自动添加覆盖率,可以计算语句,行数,函数和分支覆盖率。尽管我们有相似功能的 CodeCov(见下一节),进行本地测试时,这仍然是一个很棒的工具。 + +### 最终结果 — 运行测试 + +_有了这些库,还有之前提过的测试执行平台,现在让我们看看什么是完整的测试(你可以在 [_这里_][14] 看看我们完整的测试套件):_ + +``` +import nock from 'nock'; +import { expect, request } from 'chai'; + +import api from '../../src/server'; +import Article from '../../src/models/article'; +import config from '../../src/config'; +import { dropDBs, loadFixture, withLogin } from '../utils.js'; + +describe('Article controller', () => { + let article; + + before(async () => { + await dropDBs(); + await loadFixture('initial-data', 'articles'); + article = await Article.findOne({}); + expect(article).to.not.be.null; + expect(article.rss).to.not.be.null; + }); + + describe('get', () => { + it('should return the right article via /articles/:articleId', async () => { + let response = await withLogin(request(api).get(`/articles/${article.id}`)); + expect(response).to.have.status(200); + }); + }); + + describe('get parsed article', () => { + it('should return the parsed version of the article', async () => { + const response = await withLogin( + request(api).get(`/articles/${article.id}`).query({ type: 'parsed' }) + ); + expect(response).to.have.status(200); + }); + }); + + describe('list', () => { + it('should return the list of articles', async () => { + let response = await withLogin(request(api).get('/articles')); + expect(response).to.have.status(200); + }); + }); + + describe('list from personalization', () => { + after(function () { + nock.cleanAll(); + }); + + it('should return the list of articles', async () => { + nock(config.stream.baseUrl) + .get(/winds_article_recommendations/) + .reply(200, { results: [{foreign_id:`article:${article.id}`}] }); + + const response = await withLogin( + request(api).get('/articles').query({ + type: 'recommended', + }) + ); + expect(response).to.have.status(200); + expect(response.body.length).to.be.at.least(1); + expect(response.body[0].url).to.eq(article.url); + }); + }); +}); +``` + +### 持续集成 + +有很多可用的持续集成服务,但我们钟爱 [Travis CI][15],因为他们和我们一样喜爱开源环境。考虑到 Winds 是开源的,它再合适不过了。 + +我们的集成非常简单 —— 我们用 [.travis.yml] 文件设置环境,通过简单的 [npm][17] 命令进行测试。测试覆盖率反馈给 GitHub,在 GitHub 上我们将清楚地看出我们最新的代码或者 PR 是不是通过了测试。GitHub 集成很棒,因为它可以自动查询 Travis CI 获取结果。以下是一个在 GitHub 上看到 (经过了测试的) PR 的简单截图: + +![](https://cdn-images-1.medium.com/max/1600/1*DWfI0No5wZn7BBoWtJsLoA.png) + +除了 Travis CI,我们还用到了叫做 [CodeCov][18] 的工具。CodeCov 和 [Istanbul] 很像,但它是个可视化的工具,方便我们查看代码覆盖率、文件变动、行数变化,还有其他各种小玩意儿。尽管不用 CodeCov 也可以可视化数据,但把所有东西囊括在一个地方也很不错。 + +![](https://cdn-images-1.medium.com/max/1600/1*c9uadS4Rk4oQHxf9Gl6Q3g.png) + +### 我们学到了什么 + +在开发我们的测试套件的整个过程中,我们学到了很多东西。开发时没有所谓“正确”的方法,我们决定开始创造自己的测试流程,通过理清楚可用的库,找到那些足够有用的东西添加到我们的工具箱中。 + +最终我们学到的是,在 Node.js 中进行测试不是听上去那么简单。还好,随着 Node.js 持续完善,社区将会聚集力量,构建一个坚固稳健的库,可以用“正确”的方式处理所有和测试相关的东西。 + +但在那时到来之前,我们还会接着用自己的测试套件,它开源在 [Winds 的 GitHub 仓库][20]。 + +### 局限 + +#### 创建配置没有简单的方法 + +有的框架和语言,就如 Python 中的 Django,有简单的方式来创建配置。比如,你可以使用下面这些 Django 命令,把数据导出到文件中来自动化配置的创建过程: + +以下命令会把整个数据库导出到 `db.json` 文件中: + +``` +./manage.py dumpdata > db.json +``` + +以下命令仅导出 django 中 `admin.logentry` 表里的内容: + +``` +./manage.py dumpdata admin.logentry > logentry.json +``` + +以下命令会导出 `auth.user` 表中的内容: + +``` +./manage.py dumpdata auth.user > user.json +``` + +Node.js 里面没有创建配置的简单方式。我们最后做的事情是用 MongoDB Compass 工具导出数据到 JSON 中。这生成了不错的配置,如下图(但是,这是个乏味的过程,肯定会出错): + +![](https://cdn-images-1.medium.com/max/1600/1*HvXXS57rAIfBTOQ9h1HCew.png) + +#### 使用 Babel,模拟模块和 Mocha 测试执行平台时,模块加载不直观 + +为了支持多种 node 版本,和获取 JavaScript 标准的最新附件,我们使用 Babel 把 ES6 代码转换成 ES5。Node.js 模块系统基于 CommonJS 标准,而 ES6 模块系统中有不同的语义。 + +Babel 在 Node.js 模块系统的顶层模拟 ES6 模块语义,但由于我们要使用 mock-require 来介入模块的加载,所以我们经历了罕见的怪异的模块加载过程,这看上去很不直观,而且能导致在整个代码中,导入的、初始化的和使用的模块有不同的版本。这使测试时的模拟过程和全局状态管理复杂化了。 + +#### 在使用 ES6 模块时声明的函数,模块内部的函数,都无法模拟 + +当一个模块导出多个函数,其中一个函数调用了其他的函数,就不可能模拟使用在模块内部的函数。原因在于当你引用一个 ES6 模块时,你得到的引用集合和模块内部的是不同的。任何重新绑定引用,将其指向新值的尝试都无法真正影响模块内部的函数,内部函数仍然使用的是原始的函数。 + +### 最后的思考 + +测试 Node.js 应用是复杂的过程,因为它的生态系统总在发展。掌握最新和最好的工具很重要,这样你就不会掉队了。 + +如今有很多方式获取 JavaScript 相关的新闻,导致与时俱进很难。关注邮件新闻刊物如 [JavaScript Weekly][21] 和 [Node Weekly][22] 是良好的开始。还有,关注一些 reddit 子模块如 [/r/node][23] 也不错。如果你喜欢了解最新的趋势,[State of JS][24] 在测试领域帮助开发者可视化趋势方面就做的很好。 + +最后,这里是一些我喜欢的博客,我经常在这上面发文章: + +* [Hacker Noon][1] +* [Free Code Camp][2] +* [Bits and Pieces][3] + +觉得我遗漏了某些重要的东西?在评论区或者 Twitter [@NickParsons][25] 让我知道。 + +还有,如果你想要了解 Stream,我们的网站上有很棒的 5 分钟教程。点 [这里][26] 进行查看。 + +-------------------------------------------------------------------------------- + +作者简介: + +Nick Parsons + +Dreamer. Doer. Engineer. Developer Evangelist https://getstream.io. + +-------------------------------------------------------------------------------- + +via: https://hackernoon.com/testing-node-js-in-2018-10a04dd77391 + +作者:[Nick Parsons][a] +译者:[BriFuture](https://github.com/BriFuture) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://hackernoon.com/@nparsons08?source=post_header_lockup +[1]:https://hackernoon.com/ +[2]:https://medium.freecodecamp.org/ +[3]:https://blog.bitsrc.io/ +[4]:https://getstream.io/ +[5]:https://getstream.io/winds +[6]:https://github.com/mochajs/mocha +[7]:http://www.chaijs.com/ +[8]:http://sinonjs.org/ +[9]:https://github.com/node-nock/nock +[10]:https://getstream.io/docs_rest/ +[11]:https://getstream.io/personalization +[12]:https://github.com/boblauer/mock-require +[13]:https://github.com/gotwarlost/istanbul +[14]:https://github.com/GetStream/Winds/tree/master/api/test +[15]:https://travis-ci.org/ +[16]:https://github.com/GetStream/Winds/blob/master/.travis.yml +[17]:https://www.npmjs.com/ +[18]:https://codecov.io/#features +[19]:https://github.com/gotwarlost/istanbul +[20]:https://github.com/GetStream/Winds/tree/master/api/test +[21]:https://javascriptweekly.com/ +[22]:https://nodeweekly.com/ +[23]:https://www.reddit.com/r/node/ +[24]:https://stateofjs.com/2017/testing/results/ +[25]:https://twitter.com/@nickparsons +[26]:https://getstream.io/try-the-api diff --git a/published/201808/20180706 Revisiting wallabag, an open source alternative to Instapaper.md b/published/201808/20180706 Revisiting wallabag, an open source alternative to Instapaper.md new file mode 100644 index 0000000000..ce46d44df2 --- /dev/null +++ b/published/201808/20180706 Revisiting wallabag, an open source alternative to Instapaper.md @@ -0,0 +1,72 @@ +重温 wallabag:Instapaper 的开源替代品 +====== + +> 这个稍后阅读应用增加了功能,使其成为诸如 Pocket、Paper 和 Instapaper 之类应用的可靠替代品。 + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/email_paper_envelope_document.png?itok=uPj_kouJ) + +早在 2014 年,我[写了篇关于 wallabag 的文章][1],它是诸如 Instapaper 和 Pocket 这样的稍后阅读应用的开源替代品。如果你愿意,去看看那篇文章吧。别担心,我会等你的。 + +好了么?很好。 + +自从我写这篇文章的四年来,[wallabag][2] 的很多东西都发生了变化。现在是时候悄悄看一下 wallabag 是如何成熟的。 + +### 有什么新的 + +最大的变化发生在幕后。Wallabag 的开发人员 Nicolas Lœuillet 和该项目的贡献者对代码进行了大量修改,从而改进了程序。每次使用时,你都会看到并感受到 wallabag 新代码库所带来的变化。 + +那么这些变化有哪些呢?有[很多][3]。以下是我发现最有趣和最有用的内容。 + +除了使 wallabag 更加快速和稳定之外,该应用的导入和导出内容的能力也得到了提高。你可以从 Pocket 和 Instapaper 导入文章,也可导入书签服务 [Pinboard][4] 中标记为 “To read” 的文章。你还可以导入 Firefox 和 Chrome 书签。 + +你还可以以多种格式导出文章,包括 EPUB、MOBI、PDF 和纯文本。你可以为单篇文章、所有未读文章或所有已读和未读执行此操作。我四年前使用的 wallabag 版本可以导出到 EPUB 和 PDF,但有时导出很糟糕。现在,这些导出快速而顺利。 + +Web 界面中的注释和高亮显示现在可以更好、更一致地工作。不可否认,我并不经常使用它们 —— 但它们不会像 wallabag v1 那样随机消失。 + +![](https://opensource.com/sites/default/files/uploads/wallabag-annotation.png) + +wallabag 的外观和感觉也有所改善。这要归功于受 [Material Design][5] 启发的新主题。这似乎不是什么大不了的事,但这个主题使得 wallabag 在视觉上更具吸引力,使文章更容易扫描和阅读。是的,孩子们,良好的用户体验可以有所不同。 + +![](https://opensource.com/sites/default/files/uploads/wallabag-theme.png) + +其中一个最大的变化是引入了 wallabag 的[托管版本][6]。不是只有少数人(包括你在内)没有服务器来运行网络程序,并且也不太愿意维护台服务器。当遇到任何技术问题时,我很窘迫。我不介意每年花 9 欧元(我写这篇文章的时候只要 10 美元),以获得一个我不需要关注的程序的完整工作版本。 + +### 没有改变什么 + +总的来说,wallabag 的核心功能是相同的。如上所述,更新的代码库使这些函数运行得更顺畅,更快速。 + +Wallabag 的[浏览器扩展][7]以同样的方式完成同样的工作。我发现这些扩展比我第一次尝试时和程序的 v1 版本时要好一些。 + +### 有什么令人失望的 + +移动应用良好,但不算很棒。它在渲染文章方面做得很好,并且有一些配置选项。但是你不能高亮或注释文章。也就是说,你可以使用该程序浏览你的存档文章。 + +![](https://opensource.com/sites/default/files/uploads/wallabag-android.png) + +虽然 wallabag 在收藏文章方面做得很好,但有些网站的内容却无法保存。我没有碰到很多这样的网站,但已经遇到让人烦恼的情况。我不确定与 wallabag 有多大关系。相反,我怀疑它与网站的编码方式有关 —— 我在使用几个专有的稍后阅读工具时遇到了同样的问题。 + +Wallabag 可能不是 Pocket 或 Instapaper 的等功能的替代品,但它做得很好。自从我第一次写这篇文章以来的四年里,它已经有了明显的改善。它仍然有改进的余地,但要做好它宣传的。 + +### 最后的想法 + +自 2014 年以来,wallabag 在一直在演化。它一点一滴,一步一步地变得更好。虽然它可能不是 Instapaper 和 Pocket 等功能的替代品,但 wallabag 有价值的专有稍后阅读工具的开源替代品。 + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/7/wallabag + +作者:[Scott Nesbitt][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[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/scottnesbitt +[1]:https://opensource.com/life/14/4/open-source-read-it-later-app-wallabag +[2]:https://wallabag.org/en +[3]:https://www.wallabag.org/en/news/wallabag-v2 +[4]:https://pinboard.in +[5]:https://en.wikipedia.org/wiki/Material_Design +[6]:https://www.wallabag.it +[7]:https://github.com/wallabag/wallabagger diff --git a/published/201808/20180709 A sysadmin-s guide to network management.md b/published/201808/20180709 A sysadmin-s guide to network management.md new file mode 100644 index 0000000000..70b7d0bcc0 --- /dev/null +++ b/published/201808/20180709 A sysadmin-s guide to network management.md @@ -0,0 +1,182 @@ +面向系统管理员的网络管理指南 +====== + +> 一个使管理服务器和网络更轻松的 Linux 工具和命令的参考列表。 + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/openwires_fromRHT_520_0612LL.png?itok=PqZi55Ab) + +如果你是一位系统管理员,那么你的日常工作应该包括管理服务器和数据中心的网络。以下的 Linux 实用工具和命令 —— 从基础的到高级的 —— 将帮你更轻松地管理你的网络。 + +在几个命令中,你将会看到 ``,它是“完全合格域名”的全称。当你看到它时,你应该用你的网站 URL 或你的服务器来代替它(比如,`server-name.company.com`),具体要视情况而定。 + +### Ping + +正如它的名字所表示的那样,`ping` 是用于去检查从你的系统到你想去连接的系统之间端到端的连通性。当一个 ping 成功时,它使用的 [ICMP][1] 的 echo 包将会返回到你的系统中。它是检查系统/网络连通性的一个良好开端。你可以在 IPv4 和 IPv6 地址上使用 `ping` 命令。(阅读我的文章 "[如何在 Linux 系统上找到你的 IP 地址][2]" 去学习更多关于 IP 地址的知识) + +**语法:** + + * IPv4: `ping /` + * IPv6: `ping6 /` + +你也可以使用 `ping` 去解析出网站所对应的 IP 地址,如下图所示: + +![](https://opensource.com/sites/default/files/uploads/ping-screen-0.png) + +### Traceroute + +`ping` 是用于检查端到端的连通性,`traceroute` 实用工具将告诉你到达对端系统、网站、或服务器所经过的路径上所有路由器的 IP 地址。`traceroute` 在网络连接调试中经常用于在 `ping` 之后的第二步。 + +这是一个跟踪从你的系统到其它对端的全部网络路径的非常好的工具。在检查端到端的连通性时,这个实用工具将告诉你到达对端系统、网站、或服务器上所经历的路径上的全部路由器的 IP 地址。通常用于网络连通性调试的第二步。 + +**语法:** + + * `traceroute /` + +### Telnet + +**语法:** + + * `telnet /` 是用于 [telnet][3] 进入任何支持该协议的服务器。 + +### Netstat + +这个网络统计(`netstat`)实用工具是用于去分析解决网络连接问题和检查接口/端口统计数据、路由表、协议状态等等的。它是任何管理员都应该必须掌握的工具。 + +**语法:** + + * `netstat -l` 显示所有处于监听状态的端口列表。 + * `netstat -a` 显示所有端口;如果去指定仅显示 TCP 端口,使用 `-at`(指定信显示 UDP 端口,使用 `-au`)。 + * `netstat -r` 显示路由表。 + + ![](https://opensource.com/sites/default/files/uploads/netstat-r.png) + + * `netstat -s` 显示每个协议的状态总结。 + + ![](https://opensource.com/sites/default/files/uploads/netstat-s.png) + + * `netstat -i` 显示每个接口传输/接收(TX/RX)包的统计数据。 + + ![](https://opensource.com/sites/default/files/uploads/netstat-i.png) + +### Nmcli + +`nmcli` 是一个管理网络连接、配置等工作的非常好的实用工具。它能够去管理网络管理程序和修改任何设备的网络配置详情。 + +**语法:** + + * `nmcli device` 列出网络上的所有设备。 + * `nmcli device show ` 显示指定接口的网络相关的详细情况。 + * `nmcli connection` 检查设备的连接情况。 + * `nmcli connection down ` 关闭指定接口。 + * `nmcli connection up ` 打开指定接口。 + * `nmcli con add type vlan con-name dev id ipv4 gw4 ` 在特定的接口上使用指定的 VLAN 号添加一个虚拟局域网(VLAN)接口、IP 地址、和网关。 + + ![](https://opensource.com/sites/default/files/uploads/nmcli.png) + +### 路由 + +检查和配置路由的命令很多。下面是其中一些比较有用的: + +**语法:** + + * `ip route` 显示各自接口上所有当前的路由配置。 + + ![](https://opensource.com/sites/default/files/uploads/ip-route.png) + + * `route add default gw ` 在路由表中添加一个默认的网关。 + * `route add -net gw ` 在路由表中添加一个新的网络路由。还有许多其它的路由参数,比如,添加一个默认路由,默认网关等等。 + * `route del -net ` 从路由表中删除一个指定的路由条目。 + + ![](https://opensource.com/sites/default/files/uploads/route-add-del.png) + + * `ip neighbor` 显示当前的邻接表和用于去添加、改变、或删除新的邻居。 + + ![](https://opensource.com/sites/default/files/uploads/ip-neighbor.png) + + ![](https://opensource.com/sites/default/files/uploads/ip-neigh-help.png) + + * `arp` (它的全称是 “地址解析协议”)类似于 `ip neighbor`。`arp` 映射一个系统的 IP 地址到它相应的 MAC(介质访问控制)地址。 + + ![](https://opensource.com/sites/default/files/uploads/arp.png) + +### Tcpdump 和 Wireshark + +Linux 提供了许多包捕获工具,比如 `tcpdump`、`wireshark`、`tshark` 等等。它们被用于去捕获传输/接收的网络流量中的数据包,因此它们对于系统管理员去诊断丢包或相关问题时非常有用。对于热衷于命令行操作的人来说,`tcpdump` 是一个非常好的工具,而对于喜欢 GUI 操作的用户来说,`wireshark` 是捕获和分析数据包的不二选择。`tcpdump` 是一个 Linux 内置的用于去捕获网络流量的实用工具。它能够用于去捕获/显示特定端口、协议等上的流量。 + +**语法:** + + * `tcpdump -i ` 显示指定接口上实时通过的数据包。通过在命令中添加一个 `-w` 标志和输出文件的名字,可以将数据包保存到一个文件中。例如:`tcpdump -w -i `。 + + ![](https://opensource.com/sites/default/files/uploads/tcpdump-i.png) + + * `tcpdump -i src ` 从指定的源 IP 地址上捕获数据包。 + * `tcpdump -i dst ` 从指定的目标 IP 地址上捕获数据包。 + * `tcpdump -i port ` 从一个指定的端口号(比如,53、80、8080 等等)上捕获数据包。 + * `tcpdump -i ` 捕获指定协议的数据包,比如:TCP、UDP、等等。 + + + +### Iptables + +`iptables` 是一个包过滤防火墙工具,它能够允许或阻止某些流量。这个实用工具的应用范围非常广泛;下面是它的其中一些最常用的使用命令。 + +**语法:** + + * `iptables -L` 列出所有已存在的 `iptables` 规则。 + * `iptables -F` 删除所有已存在的规则。 + +下列命令允许流量从指定端口到指定接口: + + * `iptables -A INPUT -i -p tcp –dport -m state –state NEW,ESTABLISHED -j ACCEPT` + * `iptables -A OUTPUT -o -p tcp -sport -m state – state ESTABLISHED -j ACCEPT` + +下列命令允许环回loopback接口访问系统: + + * `iptables -A INPUT -i lo -j ACCEPT` + * `iptables -A OUTPUT -o lo -j ACCEPT` + +### Nslookup + +`nslookup` 工具是用于去获得一个网站或域名所映射的 IP 地址。它也能用于去获得你的 DNS 服务器的信息,比如,一个网站的所有 DNS 记录(具体看下面的示例)。与 `nslookup` 类似的一个工具是 `dig`(Domain Information Groper)实用工具。 + +**语法:** + + * `nslookup ` 显示你的服务器组中 DNS 服务器的 IP 地址,它后面就是你想去访问网站的 IP 地址。 + * `nslookup -type=any ` 显示指定网站/域中所有可用记录。 + + +### 网络/接口调试 + +下面是用于接口连通性或相关网络问题调试所需的命令和文件的汇总。 + +**语法:** + + * `ss` 是一个转储套接字统计数据的实用工具。 + * `nmap `,它的全称是 “Network Mapper”,它用于扫描网络端口、发现主机、检测 MAC 地址,等等。 + * `ip addr/ifconfig -a` 提供一个系统上所有接口的 IP 地址和相关信息。 + * `ssh -vvv user@` 允许你使用指定的 IP/域名和用户名通过 SSH 协议登入到其它服务器。`-vvv` 标志提供 SSH 登入到服务器过程中的 "最详细的" 信息。 + * `ethtool -S ` 检查指定接口上的统计数据。 + * `ifup ` 启动指定的接口。 + * `ifdown ` 关闭指定的接口 + * `systemctl restart network` 重启动系统上的一个网络服务。 + * `/etc/sysconfig/network-scripts/` 是一个对指定的接口设置 IP 地址、网络、网关等等的接口配置文件。DHCP 模式也可以在这里设置。 + * `/etc/hosts` 这个文件包含自定义的主机/域名到 IP 地址的映射。 + * `/etc/resolv.conf` 指定系统上的 DNS 服务器的 IP 地址。 + * `/etc/ntp.conf` 指定 NTP 服务器域名。 + + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/7/sysadmin-guide-networking-commands + +作者:[Archit Modi][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[qhwdw](https://github.com/qhwdw) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://opensource.com/users/architmodi +[1]:https://en.wikipedia.org/wiki/Internet_Control_Message_Protocol +[2]:https://opensource.com/article/18/5/how-find-ip-address-linux +[3]:https://en.wikipedia.org/wiki/Telnet diff --git a/published/201808/20180710 4 Essential and Practical Usage of Cut Command in Linux.md b/published/201808/20180710 4 Essential and Practical Usage of Cut Command in Linux.md new file mode 100644 index 0000000000..0071db3e5c --- /dev/null +++ b/published/201808/20180710 4 Essential and Practical Usage of Cut Command in Linux.md @@ -0,0 +1,525 @@ +Linux 下 cut 命令的 4 个基础实用的示例 +============================================================ + +`cut` 命令是用来从文本文件中移除“某些列”的经典工具。在本文中的“一列”可以被定义为按照一行中位置区分的一系列字符串或者字节,或者是以某个分隔符为间隔的某些域。 + +先前我已经介绍了[如何使用 AWK 命令][13]。在本文中,我将解释 linux 下 `cut` 命令的 4 个本质且实用的例子,有时这些例子将帮你节省很多时间。 + +![Cut Linux 命令示例](https://i1.wp.com/linuxhandbook.com/wp-content/uploads/2018/07/cut-command-linux.jpeg?resize=702%2C395&ssl=1) + +### Linux 下 cut 命令的 4 个实用示例 + +假如你想,你可以观看下面的视频,视频中解释了本文中我列举的 cut 命令的使用例子。 + +- https://www.youtube.com/PhE_cFLzVFw + +### 1、 作用在一系列字符上 + +当启用 `-c` 命令行选项时,`cut` 命令将移除一系列字符。 + +和其他的过滤器类似, `cut` 命令不会直接改变输入的文件,它将复制已修改的数据到它的标准输出里去。你可以通过重定向命令的结果到一个文件中来保存修改后的结果,或者使用管道将结果送到另一个命令的输入中,这些都由你来负责。 + +假如你已经下载了上面视频中的[示例测试文件][26],你将看到一个名为 `BALANCE.txt` 的数据文件,这些数据是直接从我妻子在她工作中使用的某款会计软件中导出的: + +``` +sh$ head BALANCE.txt +ACCDOC ACCDOCDATE ACCOUNTNUM ACCOUNTLIB ACCDOCLIB DEBIT CREDIT +4 1012017 623477 TIDE SCHEDULE ALNEENRE-4701-LOC 00000001615,00 +4 1012017 445452 VAT BS/ENC ALNEENRE-4701-LOC 00000000323,00 +4 1012017 4356 PAYABLES ALNEENRE-4701-LOC 00000001938,00 +5 1012017 623372 ACCOMODATION GUIDE ALNEENRE-4771-LOC 00000001333,00 +5 1012017 445452 VAT BS/ENC ALNEENRE-4771-LOC 00000000266,60 +5 1012017 4356 PAYABLES ALNEENRE-4771-LOC 00000001599,60 +6 1012017 4356 PAYABLES FACT FA00006253 - BIT QUIROBEN 00000001837,20 +6 1012017 445452 VAT BS/ENC FACT FA00006253 - BIT QUIROBEN 00000000306,20 +6 1012017 623795 TOURIST GUIDE BOOK FACT FA00006253 - BIT QUIROBEN 00000001531,00 +``` + +上述文件是一个固定宽度的文本文件,因为对于每一项数据,都使用了不定长的空格做填充,使得它看起来是一个对齐的列表。 + +这样一来,每一列数据开始和结束的位置都是一致的。从 `cut` 命令的字面意思去理解会给我们带来一个小陷阱:`cut` 命令实际上需要你指出你想_保留_的数据范围,而不是你想_移除_的范围。所以,假如我_只_需要上面文件中的 `ACCOUNTNUM` 和 `ACCOUNTLIB` 列,我需要这么做: + +``` +sh$ cut -c 25-59 BALANCE.txt | head +ACCOUNTNUM ACCOUNTLIB +623477 TIDE SCHEDULE +445452 VAT BS/ENC +4356 /accountPAYABLES +623372 ACCOMODATION GUIDE +445452 VAT BS/ENC +4356 PAYABLES +4356 PAYABLES +445452 VAT BS/ENC +623795 TOURIST GUIDE BOOK +``` + +#### 范围如何定义? + +正如我们上面看到的那样, `cut` 命令需要我们特别指定需要保留的数据的_范围_。所以,下面我将更正式地介绍如何定义范围:对于 `cut` 命令来说,范围是由连字符(`-`)分隔的起始和结束位置组成,范围是基于 1 计数的,即每行的第一项是从 1 开始计数的,而不是从 0 开始。范围是一个闭区间,开始和结束位置都将包含在结果之中,正如它们之间的所有字符那样。如果范围中的结束位置比起始位置小,则这种表达式是错误的。作为快捷方式,你可以省略起始_或_结束值,正如下面的表格所示: + + +| 范围 | 含义 | +|---|---| +| `a-b` | a 和 b 之间的范围(闭区间) | +|`a` | 与范围 `a-a` 等价 | +| `-b` | 与范围 `1-a` 等价 | +| `b-` | 与范围 `b-∞` 等价 | + +`cut` 命令允许你通过逗号分隔多个范围,下面是一些示例: + +``` +# 保留 1 到 24 之间(闭区间)的字符 +cut -c -24 BALANCE.txt + +# 保留 1 到 24(闭区间)以及 36 到 59(闭区间)之间的字符 +cut -c -24,36-59 BALANCE.txt + +# 保留 1 到 24(闭区间)、36 到 59(闭区间)和 93 到该行末尾之间的字符 +cut -c -24,36-59,93- BALANCE.txt +``` + +`cut` 命令的一个限制(或者是特性,取决于你如何看待它)是它将 _不会对数据进行重排_。所以下面的命令和先前的命令将产生相同的结果,尽管范围的顺序做了改变: + +``` +cut -c 93-,-24,36-59 BALANCE.txt +``` + +你可以轻易地使用 `diff` 命令来验证: + +``` +diff -s <(cut -c -24,36-59,93- BALANCE.txt) \ + <(cut -c 93-,-24,36-59 BALANCE.txt) +Files /dev/fd/63 and /dev/fd/62 are identical +``` + +类似的,`cut` 命令 _不会重复数据_: + +``` +# 某人或许期待这可以第一列三次,但并不会…… +cut -c -10,-10,-10 BALANCE.txt | head -5 +ACCDOC +4 +4 +4 +5 +``` + +值得提及的是,曾经有一个提议,建议使用 `-o` 选项来去除上面提到的两个限制,使得 `cut` 工具可以重排或者重复数据。但这个提议被 [POSIX 委员会拒绝了][14],_“因为这类增强不属于 IEEE P1003.2b 草案标准的范围”_。 + +据我所知,我还没有见过哪个版本的 `cut` 程序实现了上面的提议,以此来作为扩展,假如你知道某些例外,请使用下面的评论框分享给大家! + +### 2、 作用在一系列字节上 + +当使用 `-b` 命令行选项时,`cut` 命令将移除字节范围。 + +咋一看,使用_字符_范围和使用_字节_没有什么明显的不同: + +``` +sh$ diff -s <(cut -b -24,36-59,93- BALANCE.txt) \ + <(cut -c -24,36-59,93- BALANCE.txt) +Files /dev/fd/63 and /dev/fd/62 are identical +``` + +这是因为我们的示例数据文件使用的是 [US-ASCII 编码][27](字符集),使用 `file -i` 便可以正确地猜出来: + +``` +sh$ file -i BALANCE.txt +BALANCE.txt: text/plain; charset=us-ascii +``` + +在 US-ASCII 编码中,字符和字节是一一对应的。理论上,你只需要使用一个字节就可以表示 256 个不同的字符(数字、字母、标点符号和某些符号等)。实际上,你能表达的字符数比 256 要更少一些,因为字符编码中为某些特定值做了规定(例如 32 或 65 就是[控制字符][28])。即便我们能够使用上述所有的字节范围,但对于存储种类繁多的人类手写符号来说,256 是远远不够的。所以如今字符和字节间的一一对应更像是某种例外,并且几乎总是被无处不在的 UTF-8 多字节编码所取代。下面让我们看看如何来处理多字节编码的情形。 + +#### 作用在多字节编码的字符上 + +正如我前面提到的那样,示例数据文件来源于我妻子使用的某款会计软件。最近好像她升级了那个软件,然后呢,导出的文本就完全不同了,你可以试试和上面的数据文件相比,找找它们之间的区别: + +``` +sh$ head BALANCE-V2.txt +ACCDOC ACCDOCDATE ACCOUNTNUM ACCOUNTLIB ACCDOCLIB DEBIT CREDIT +4 1012017 623477 TIDE SCHEDULE ALNÉENRE-4701-LOC 00000001615,00 +4 1012017 445452 VAT BS/ENC ALNÉENRE-4701-LOC 00000000323,00 +4 1012017 4356 PAYABLES ALNÉENRE-4701-LOC 00000001938,00 +5 1012017 623372 ACCOMODATION GUIDE ALNÉENRE-4771-LOC 00000001333,00 +5 1012017 445452 VAT BS/ENC ALNÉENRE-4771-LOC 00000000266,60 +5 1012017 4356 PAYABLES ALNÉENRE-4771-LOC 00000001599,60 +6 1012017 4356 PAYABLES FACT FA00006253 - BIT QUIROBEN 00000001837,20 +6 1012017 445452 VAT BS/ENC FACT FA00006253 - BIT QUIROBEN 00000000306,20 +6 1012017 623795 TOURIST GUIDE BOOK FACT FA00006253 - BIT QUIROBEN 00000001531,00 +``` + +上面的标题栏或许能够帮助你找到什么被改变了,但无论你找到与否,现在让我们看看上面的更改过后的结果: + +``` +sh$ cut -c 93-,-24,36-59 BALANCE-V2.txt +ACCDOC ACCDOCDATE ACCOUNTLIB DEBIT CREDIT +4 1012017 TIDE SCHEDULE 00000001615,00 +4 1012017 VAT BS/ENC 00000000323,00 +4 1012017 PAYABLES 00000001938,00 +5 1012017 ACCOMODATION GUIDE 00000001333,00 +5 1012017 VAT BS/ENC 00000000266,60 +5 1012017 PAYABLES 00000001599,60 +6 1012017 PAYABLES 00000001837,20 +6 1012017 VAT BS/ENC 00000000306,20 +6 1012017 TOURIST GUIDE BOOK 00000001531,00 +19 1012017 SEMINAR FEES 00000000080,00 +19 1012017 PAYABLES 00000000080,00 +28 1012017 MAINTENANCE 00000000746,58 +28 1012017 VAT BS/ENC 00000000149,32 +28 1012017 PAYABLES 00000000895,90 +31 1012017 PAYABLES 00000000240,00 +31 1012017 VAT BS/DEBIT 00000000040,00 +31 1012017 ADVERTISEMENTS 00000000200,00 +32 1012017 WATER 00000000202,20 +32 1012017 VAT BS/DEBIT 00000000020,22 +32 1012017 WATER 00000000170,24 +32 1012017 VAT BS/DEBIT 00000000009,37 +32 1012017 PAYABLES 00000000402,03 +34 1012017 RENTAL COSTS 00000000018,00 +34 1012017 PAYABLES 00000000018,00 +35 1012017 MISCELLANEOUS CHARGES 00000000015,00 +35 1012017 VAT BS/DEBIT 00000000003,00 +35 1012017 PAYABLES 00000000018,00 +36 1012017 LANDLINE TELEPHONE 00000000069,14 +36 1012017 VAT BS/ENC 00000000013,83 +``` + +我_毫无删减地_复制了上面命令的输出。所以可以很明显地看出列对齐那里有些问题。 + +对此我的解释是原来的数据文件只包含 US-ASCII 编码的字符(符号、标点符号、数字和没有发音符号的拉丁字母)。 + +但假如你仔细地查看经软件升级后产生的文件,你可以看到新导出的数据文件保留了带发音符号的字母。例如现在合理地记录了名为 “ALNÉENRE” 的公司,而不是先前的 “ALNEENRE”(没有发音符号)。 + +`file -i` 正确地识别出了改变,因为它报告道现在这个文件是 [UTF-8 编码][15] 的。 + +``` +sh$ file -i BALANCE-V2.txt +BALANCE-V2.txt: text/plain; charset=utf-8 +``` + +如果想看看 UTF-8 文件中那些带发音符号的字母是如何编码的,我们可以使用 `[hexdump][12]`,它可以让我们直接以字节形式查看文件: + +``` +# 为了减少输出,让我们只关注文件的第 2 行 +sh$ sed '2!d' BALANCE-V2.txt +4 1012017 623477 TIDE SCHEDULE ALNÉENRE-4701-LOC 00000001615,00 +sh$ sed '2!d' BALANCE-V2.txt | hexdump -C +00000000 34 20 20 20 20 20 20 20 20 20 31 30 31 32 30 31 |4 101201| +00000010 37 20 20 20 20 20 20 20 36 32 33 34 37 37 20 20 |7 623477 | +00000020 20 20 20 54 49 44 45 20 53 43 48 45 44 55 4c 45 | TIDE SCHEDULE| +00000030 20 20 20 20 20 20 20 20 20 20 20 41 4c 4e c3 89 | ALN..| +00000040 45 4e 52 45 2d 34 37 30 31 2d 4c 4f 43 20 20 20 |ENRE-4701-LOC | +00000050 20 20 20 20 20 20 20 20 20 20 20 20 20 30 30 30 | 000| +00000060 30 30 30 30 31 36 31 35 2c 30 30 20 20 20 20 20 |00001615,00 | +00000070 20 20 20 20 20 20 20 20 20 20 20 0a | .| +0000007c +``` + +在 `hexdump`  输出的 00000030 那行,在一系列的空格(字节 `20`)之后,你可以看到: + +* 字母 `A` 被编码为 `41`, +* 字母 `L` 被编码为 `4c`, +* 字母 `N` 被编码为 `4e`。 + +但对于大写的[带有注音的拉丁大写字母 E][16] (这是它在 Unicode 标准中字母 _É_ 的官方名称),则是使用 _2_ 个字节 `c3 89` 来编码的。 + +这样便出现问题了:对于使用固定宽度编码的文件, 使用字节位置来表示范围的 `cut` 命令工作良好,但这并不适用于使用变长编码的 UTF-8 或者 [Shift JIS][17] 编码。这种情况在下面的 [POSIX 标准的非规范性摘录][18] 中被明确地解释过: + +> 先前版本的 `cut` 程序将字节和字符视作等同的环境下运作(正如在某些实现下对退格键 `` 和制表键 `` 的处理)。在针对多字节字符的情况下,特别增加了 `-b` 选项。 + +嘿,等一下!我并没有在上面“有错误”的例子中使用 '-b' 选项,而是 `-c` 选项呀!所以,难道_不应该_能够成功处理了吗!? + +是的,确实_应该_:但是很不幸,即便我们现在已身处 2018 年,GNU Coreutils 的版本为 8.30 了,`cut` 程序的 GNU 版本实现仍然不能很好地处理多字节字符。引用 [GNU 文档][19] 的话说,_`-c` 选项“现在和 `-b` 选项是相同的,但对于国际化的情形将有所不同[...]”_。需要提及的是,这个问题距今已有 10 年之久了! + +另一方面,[OpenBSD][20] 的实现版本和 POSIX 相吻合,这将归功于当前的本地化(`locale`)设定来合理地处理多字节字符: + +``` +# 确保随后的命令知晓我们现在处理的是 UTF-8 编码的文本文件 +openbsd-6.3$ export LC_CTYPE=en_US.UTF-8 + +# 使用 `-c` 选项, `cut` 能够合理地处理多字节字符 +openbsd-6.3$ cut -c -24,36-59,93- BALANCE-V2.txt +ACCDOC ACCDOCDATE ACCOUNTLIB DEBIT CREDIT +4 1012017 TIDE SCHEDULE 00000001615,00 +4 1012017 VAT BS/ENC 00000000323,00 +4 1012017 PAYABLES 00000001938,00 +5 1012017 ACCOMODATION GUIDE 00000001333,00 +5 1012017 VAT BS/ENC 00000000266,60 +5 1012017 PAYABLES 00000001599,60 +6 1012017 PAYABLES 00000001837,20 +6 1012017 VAT BS/ENC 00000000306,20 +6 1012017 TOURIST GUIDE BOOK 00000001531,00 +19 1012017 SEMINAR FEES 00000000080,00 +19 1012017 PAYABLES 00000000080,00 +28 1012017 MAINTENANCE 00000000746,58 +28 1012017 VAT BS/ENC 00000000149,32 +28 1012017 PAYABLES 00000000895,90 +31 1012017 PAYABLES 00000000240,00 +31 1012017 VAT BS/DEBIT 00000000040,00 +31 1012017 ADVERTISEMENTS 00000000200,00 +32 1012017 WATER 00000000202,20 +32 1012017 VAT BS/DEBIT 00000000020,22 +32 1012017 WATER 00000000170,24 +32 1012017 VAT BS/DEBIT 00000000009,37 +32 1012017 PAYABLES 00000000402,03 +34 1012017 RENTAL COSTS 00000000018,00 +34 1012017 PAYABLES 00000000018,00 +35 1012017 MISCELLANEOUS CHARGES 00000000015,00 +35 1012017 VAT BS/DEBIT 00000000003,00 +35 1012017 PAYABLES 00000000018,00 +36 1012017 LANDLINE TELEPHONE 00000000069,14 +36 1012017 VAT BS/ENC 00000000013,83 +``` + +正如期望的那样,当使用 `-b` 选项而不是 `-c` 选项后, OpenBSD 版本的 `cut` 实现和传统的 `cut` 表现是类似的: + +``` +openbsd-6.3$ cut -b -24,36-59,93- BALANCE-V2.txt +ACCDOC ACCDOCDATE ACCOUNTLIB DEBIT CREDIT +4 1012017 TIDE SCHEDULE 00000001615,00 +4 1012017 VAT BS/ENC 00000000323,00 +4 1012017 PAYABLES 00000001938,00 +5 1012017 ACCOMODATION GUIDE 00000001333,00 +5 1012017 VAT BS/ENC 00000000266,60 +5 1012017 PAYABLES 00000001599,60 +6 1012017 PAYABLES 00000001837,20 +6 1012017 VAT BS/ENC 00000000306,20 +6 1012017 TOURIST GUIDE BOOK 00000001531,00 +19 1012017 SEMINAR FEES 00000000080,00 +19 1012017 PAYABLES 00000000080,00 +28 1012017 MAINTENANCE 00000000746,58 +28 1012017 VAT BS/ENC 00000000149,32 +28 1012017 PAYABLES 00000000895,90 +31 1012017 PAYABLES 00000000240,00 +31 1012017 VAT BS/DEBIT 00000000040,00 +31 1012017 ADVERTISEMENTS 00000000200,00 +32 1012017 WATER 00000000202,20 +32 1012017 VAT BS/DEBIT 00000000020,22 +32 1012017 WATER 00000000170,24 +32 1012017 VAT BS/DEBIT 00000000009,37 +32 1012017 PAYABLES 00000000402,03 +34 1012017 RENTAL COSTS 00000000018,00 +34 1012017 PAYABLES 00000000018,00 +35 1012017 MISCELLANEOUS CHARGES 00000000015,00 +35 1012017 VAT BS/DEBIT 00000000003,00 +35 1012017 PAYABLES 00000000018,00 +36 1012017 LANDLINE TELEPHONE 00000000069,14 +36 1012017 VAT BS/ENC 00000000013,83 +``` + +### 3、 作用在域上 + +从某种意义上说,使用 `cut` 来处理用特定分隔符隔开的文本文件要更加容易一些,因为只需要确定好每行中域之间的分隔符,然后复制域的内容到输出就可以了,而不需要烦恼任何与编码相关的问题。 + +下面是一个用分隔符隔开的示例文本文件: + +``` +sh$ head BALANCE.csv +ACCDOC;ACCDOCDATE;ACCOUNTNUM;ACCOUNTLIB;ACCDOCLIB;DEBIT;CREDIT +4;1012017;623477;TIDE SCHEDULE;ALNEENRE-4701-LOC;00000001615,00; +4;1012017;445452;VAT BS/ENC;ALNEENRE-4701-LOC;00000000323,00; +4;1012017;4356;PAYABLES;ALNEENRE-4701-LOC;;00000001938,00 +5;1012017;623372;ACCOMODATION GUIDE;ALNEENRE-4771-LOC;00000001333,00; +5;1012017;445452;VAT BS/ENC;ALNEENRE-4771-LOC;00000000266,60; +5;1012017;4356;PAYABLES;ALNEENRE-4771-LOC;;00000001599,60 +6;1012017;4356;PAYABLES;FACT FA00006253 - BIT QUIROBEN;;00000001837,20 +6;1012017;445452;VAT BS/ENC;FACT FA00006253 - BIT QUIROBEN;00000000306,20; +6;1012017;623795;TOURIST GUIDE BOOK;FACT FA00006253 - BIT QUIROBEN;00000001531,00; +``` + +你可能知道上面文件是一个 [CSV][29] 格式的文件(它以逗号来分隔),即便有时候域分隔符不是逗号。例如分号(`;`)也常被用来作为分隔符,并且对于那些总使用逗号作为 [十进制分隔符][30]的国家(例如法国,所以上面我的示例文件中选用了他们国家的字符),当导出数据为 “CSV” 格式时,默认将使用分号来分隔数据。另一种常见的情况是使用 [tab 键][32] 来作为分隔符,从而生成叫做 [tab 分隔的值][32] 的文件。最后,在 Unix 和 Linux 领域,冒号 (`:`) 是另一种你能找到的常见分隔符号,例如在标准的 `/etc/passwd` 和 `/etc/group` 这两个文件里。 + +当处理使用分隔符隔开的文本文件格式时,你可以向带有 `-f` 选项的 `cut` 命令提供需要保留的域的范围,并且你也可以使用 `-d` 选项来指定分隔符(当没有使用 `-d` 选项时,默认以 tab 字符来作为分隔符): + +``` +sh$ cut -f 5- -d';' BALANCE.csv | head +ACCDOCLIB;DEBIT;CREDIT +ALNEENRE-4701-LOC;00000001615,00; +ALNEENRE-4701-LOC;00000000323,00; +ALNEENRE-4701-LOC;;00000001938,00 +ALNEENRE-4771-LOC;00000001333,00; +ALNEENRE-4771-LOC;00000000266,60; +ALNEENRE-4771-LOC;;00000001599,60 +FACT FA00006253 - BIT QUIROBEN;;00000001837,20 +FACT FA00006253 - BIT QUIROBEN;00000000306,20; +FACT FA00006253 - BIT QUIROBEN;00000001531,00; +``` + +#### 处理不包含分隔符的行 + +但要是输入文件中的某些行没有分隔符又该怎么办呢?很容易地认为可以将这样的行视为只包含第一个域。但 `cut` 程序并 _不是_ 这样做的。 + +默认情况下,当使用 `-f` 选项时,`cut` 将总是原样输出不包含分隔符的那一行(可能假设它是非数据行,就像表头或注释等): + +``` +sh$ (echo "# 2018-03 BALANCE"; cat BALANCE.csv) > BALANCE-WITH-HEADER.csv + +sh$ cut -f 6,7 -d';' BALANCE-WITH-HEADER.csv | head -5 +# 2018-03 BALANCE +DEBIT;CREDIT +00000001615,00; +00000000323,00; +;00000001938,00 +``` + +使用 `-s` 选项,你可以做出相反的行为,这样 `cut` 将总是忽略这些行: + +``` +sh$ cut -s -f 6,7 -d';' BALANCE-WITH-HEADER.csv | head -5 +DEBIT;CREDIT +00000001615,00; +00000000323,00; +;00000001938,00 +00000001333,00; +``` + +假如你好奇心强,你还可以探索这种特性,来作为一种相对隐晦的方式去保留那些只包含给定字符的行: + +``` +# 保留含有一个 `e` 的行 +sh$ printf "%s\n" {mighty,bold,great}-{condor,monkey,bear} | cut -s -f 1- -d'e' +``` + +#### 改变输出的分隔符 + +作为一种扩展, GNU 版本实现的 `cut` 允许通过使用 `--output-delimiter` 选项来为结果指定一个不同的域分隔符: + +``` +sh$ cut -f 5,6- -d';' --output-delimiter="*" BALANCE.csv | head +ACCDOCLIB*DEBIT*CREDIT +ALNEENRE-4701-LOC*00000001615,00* +ALNEENRE-4701-LOC*00000000323,00* +ALNEENRE-4701-LOC**00000001938,00 +ALNEENRE-4771-LOC*00000001333,00* +ALNEENRE-4771-LOC*00000000266,60* +ALNEENRE-4771-LOC**00000001599,60 +FACT FA00006253 - BIT QUIROBEN**00000001837,20 +FACT FA00006253 - BIT QUIROBEN*00000000306,20* +FACT FA00006253 - BIT QUIROBEN*00000001531,00* +``` + +需要注意的是,在上面这个例子中,所有出现域分隔符的地方都被替换掉了,而不仅仅是那些在命令行中指定的作为域范围边界的分隔符。 + +### 4、 非 POSIX GNU 扩展 + +说到非 POSIX GNU 扩展,它们中的某些特别有用。特别需要提及的是下面的扩展也同样对字节、字符或者域范围工作良好(相对于当前的 GNU 实现来说)。 + +`--complement`: + +想想在 sed 地址中的感叹符号(`!`),使用它,`cut` 将只保存**没有**被匹配到的范围: + +``` +# 只保留第 5 个域 +sh$ cut -f 5 -d';' BALANCE.csv |head -3 +ACCDOCLIB +ALNEENRE-4701-LOC +ALNEENRE-4701-LOC + +# 保留除了第 5 个域之外的内容 +sh$ cut --complement -f 5 -d';' BALANCE.csv |head -3 +ACCDOC;ACCDOCDATE;ACCOUNTNUM;ACCOUNTLIB;DEBIT;CREDIT +4;1012017;623477;TIDE SCHEDULE;00000001615,00; +4;1012017;445452;VAT BS/ENC;00000000323,00; +``` + +`--zero-terminated (-z)`: + +使用 [NUL 字符][6] 来作为行终止符,而不是 [新行newline字符][7]。当你的数据包含 新行字符时, `-z` 选项就特别有用了,例如当处理文件名的时候(因为在文件名中新行字符是可以使用的,而 NUL 则不可以)。 + +为了展示 `-z` 选项,让我们先做一点实验。首先,我们将创建一个文件名中包含换行符的文件: + +``` +bash$ touch $'EMPTY\nFILE\nWITH FUNKY\nNAME'.txt +bash$ ls -1 *.txt +BALANCE.txt +BALANCE-V2.txt +EMPTY?FILE?WITH FUNKY?NAME.txt +``` + +现在假设我想展示每个 `*.txt` 文件的前 5 个字符。一个想当然的解决方法将会失败: + +``` +sh$ ls -1 *.txt | cut -c 1-5 +BALAN +BALAN +EMPTY +FILE +WITH +NAME. +``` + +你可以已经知道 [ls][21] 是为了[方便人类使用][33]而特别设计的,并且在一个命令管道中使用它是一个反模式(确实是这样的)。所以让我们用 [find][22] 来替换它: + +``` +sh$ find . -name '*.txt' -printf "%f\n" | cut -c 1-5 +BALAN +EMPTY +FILE +WITH +NAME. +BALAN +``` + +上面的命令基本上产生了与先前类似的结果(尽管以不同的次序,因为 `ls` 会隐式地对文件名做排序,而 `find` 则不会)。 + +在上面的两个例子中,都有一个相同的问题,`cut` 命令不能区分 新行 字符是数据域的一部分(即文件名),还是作为最后标记的 新行 记号。但使用 NUL 字节(`\0`)来作为行终止符就将排除掉这种混淆的情况,使得我们最后可以得到期望的结果: + +``` +# 我被告知在某些旧版的 `tr` 程序中需要使用 `\000` 而不是 `\0` 来代表 NUL 字符(假如你需要这种改变请让我知晓!) +sh$ find . -name '*.txt' -printf "%f\0" | cut -z -c 1-5| tr '\0' '\n' +BALAN +EMPTY +BALAN +``` + +通过上面最后的例子,我们就达到了本文的最后部分了,所以我将让你自己试试 `-printf` 后面那个有趣的 `"%f\0"` 参数或者理解为什么我在管道的最后使用了 [tr][23] 命令。 + +### 使用 cut 命令可以实现更多功能 + +我只是列举了 `cut` 命令的最常见且在我眼中最基础的使用方式。你甚至可以将它以更加实用的方式加以运用,这取决于你的逻辑和想象。 + +不要再犹豫了,请使用下面的评论框贴出你的发现。最后一如既往的,假如你喜欢这篇文章,请不要忘记将它分享到你最喜爱网站和社交媒体中! + +-------------------------------------------------------------------------------- + +via: https://linuxhandbook.com/cut-command/ + +作者:[Sylvain Leroux][a] +译者:[FSSlc](https://github.com/FSSlc) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://linuxhandbook.com/author/sylvain/ +[1]:https://linuxhandbook.com/cut-command/#_what_s_a_range +[2]:https://linuxhandbook.com/cut-command/#_working_with_multibyte_characters +[3]:https://linuxhandbook.com/cut-command/#_handling_lines_not_containing_the_delimiter +[4]:https://linuxhandbook.com/cut-command/#_changing_the_output_delimiter +[5]:http://click.linksynergy.com/deeplink?id=IRL8ozn3lq8&type=10&mid=39197&murl=https%3A%2F%2Fwww.udemy.com%2Fyes-i-know-the-bash-linux-command-line-tools%2F +[6]:https://en.wikipedia.org/wiki/Null_character +[7]:https://en.wikipedia.org/wiki/Newline +[8]:https://linuxhandbook.com/cut-command/#_working_with_character_ranges +[9]:https://linuxhandbook.com/cut-command/#_working_with_byte_ranges +[10]:https://linuxhandbook.com/cut-command/#_working_with_fields +[11]:https://linuxhandbook.com/cut-command/#_non_posix_gnu_extensions +[12]:https://linux.die.net/man/1/hexdump +[13]:https://linuxhandbook.com/awk-command-tutorial/ +[14]:http://pubs.opengroup.org/onlinepubs/9699919799/utilities/cut.html#tag_20_28_18 +[15]:https://en.wikipedia.org/wiki/UTF-8#Codepage_layout +[16]:https://www.fileformat.info/info/unicode/char/00c9/index.htm +[17]:https://en.wikipedia.org/wiki/Shift_JIS#Shift_JIS_byte_map +[18]:http://pubs.opengroup.org/onlinepubs/9699919799/utilities/cut.html#tag_20_28_16 +[19]:https://www.gnu.org/software/coreutils/manual/html_node/cut-invocation.html#cut-invocation +[20]:https://www.openbsd.org/ +[21]:https://linux.die.net/man/1/ls +[22]:https://linux.die.net/man/1/find +[23]:https://linux.die.net/man/1/tr +[24]:https://linuxhandbook.com/author/sylvain/ +[25]:https://linuxhandbook.com/cut-command/#comments +[26]:https://static.yesik.it/EP22/Yes_I_Know_IT-EP22.tar.gz +[27]:https://en.wikipedia.org/wiki/ASCII#Character_set +[28]:https://en.wikipedia.org/wiki/Control_character +[29]:https://en.wikipedia.org/wiki/Comma-separated_values +[30]:https://en.wikipedia.org/wiki/Decimal_separator +[31]:https://en.wikipedia.org/wiki/Tab_key#Tab_characters +[32]:https://en.wikipedia.org/wiki/Tab-separated_values +[33]:http://lists.gnu.org/archive/html/coreutils/2014-02/msg00005.html diff --git a/published/201808/20180710 How I Fully Quit Google And You Can Too.md b/published/201808/20180710 How I Fully Quit Google And You Can Too.md new file mode 100644 index 0000000000..cc4fcd03a0 --- /dev/null +++ b/published/201808/20180710 How I Fully Quit Google And You Can Too.md @@ -0,0 +1,216 @@ +逃离 Google,重获自由(与君共勉) +====== + +> 寻求挣脱科技巨头的一次开创性尝试 + +![](https://cdn-images-1.medium.com/max/2000/1*BWtEYNsmqON6zdURcLa6hg.png) + +在过去的六个月里,难以想象我到底经历了些什么。艰难的、耗时的、开创性的探索,为的只是完全摒弃一家公司 —— Google(谷歌)—— 的产品。本该是件简简单单的任务,但真要去做,花费在研究和测试上的又何止几个小时。但我成功了。现在,我已经不需要 Google 了,作为西方世界中极其少数的群体中的一份子,不再使用世界上最有价值的两家科技公司的产品(是的,我也不用 [Facebook(脸书)][6])。 + +本篇指南将向你展示我逃离 Google 生态的始末。以及根据本人的研究和个人需求,选择的替代方案。我不是技术方面的专家,或者说程序员,但作为记者,我的工作要求我对安全和隐私的问题保持警惕。 + +我选择替代方案时,主要考察其本身的长处、可用性、成本、以及是否具备我需要的功能。我的选择并不是那么大众,仅反映我自身的需求和期许,也不牵涉任何商业利益。下面列出的所有替代方案都没有给我赞助,也从未试图花钱诱使我使用他们的服务。 + +### 首先我们需要知道:为什么? + +你们说这事情整的,我和 Google 可无冤无仇。事实上,不久前我还是个忠实的 Google 粉。还是记得是 90 年代末,当时我还在读高中,我和 Google 搜索引擎的第一次邂逅,那一瞬的美简直惊为天人。那时候的 Google 可是领先了 Yahoo、Altavista、Ask Jeeves 这些公司好几年。Google 实打实地去帮用户找到他们想在网络上找的东西,但同样是那个时代,乌七八糟的网站和糟糕的索引遍地横生。 + +Google 很快就从仅提供检索服务转向提供其它服务,其中许多都是我欣然拥抱的服务。早在 2005 年,当时你们可能还只能[通过邀请][7]加入 Gmail 的时候,我就已经是早期使用者了。Gmail 采用了线程对话、归档、标签,毫无疑问是我使用过的最好的电子邮件服务。当 Google 在 2006 年推出其日历工具时,那种对操作的改进绝对是革命性的。针对不同日历使用不同的颜色进行编排、检索事件、以及发送可共享的邀请,操作极其简单。2007 年推出的 Google Docs 同样令人惊叹。在我的第一份全职工作期间,我还促成我们团队使用支持多人同时编辑的 Google 电子表格、文档和演示文稿来完成日常工作。 + +和许多人一样,我也是 Google 开疆拓土过程中的受害者。从搜索(引擎)到电子邮件、文档、分析、再到照片,许多其它服务都建立在彼此之上,相互勾连。Google 从一家发布实用产品的公司转变成诱困用户的公司,与此同时将整个互联网转变为牟利和数据采集的机器。Google 在我们的数字生活中几乎无处不在,这种程度的存在远非其他公司可以比拟。与之相比使用其他科技巨头的产品想要抽身就相对容易。对于 Apple(苹果),你要么身处 iWorld 之中,要么是局外人。亚马逊亦是如此,甚至连 Facebook 也不过是拥有少数的几个平台,不用(Facebook)更多的是[心理挑战][8],实际上并没有多么困难。 + +然而,Google 无处不在。无论是笔记本电脑、智能手机或者平板电脑,我猜其中至少会有那么一个 Google 的应用程序。Google 就是搜索(引擎)、地图、电子邮件、浏览器和大多数智能手机操作系统的代名词。甚至还有些应用有赖于其提供的“[服务][9]”和分析,比方说 Uber 便需要采用 Google 地图来运营其乘车服务。 + +Google 现在俨然已是许多语言中的单词,但彰显其超然全球统治地位的方面显然不止于此。可以说只要你不是极其注重个人隐私,那其庞大而成套的工具几乎没有多少众所周知或广泛使用的替代品。这恰好也是大家选择 Google 的原因,在很多方面能更好的替代现有的产品。但现在,使我们的难以割舍的主要原因其实是 Google 已经成为了默认选择,或者说由于其主导地位导致替代品无法对我们构成足够的吸引。 + +事实上,替代方案是存在的,这些年自爱德华·斯诺登Edward Snowden披露 Google 涉事 [棱镜][10]Prism以来,又陆续涌现了许多替代品。我从去年年底开始着手这个项目。经过六个月的研究、测评以及大量的尝试和失败,我终于找到了所有我正在使用的 Google 产品对应的注重个人隐私的替代品。令我感到吃惊的是,其中的一些替代品比 Google 的做的还要好。 + +### 一些注意事项 + +这个过程中需要面临的几个挑战之一便是,大多数的替代方案,特别是那些注重隐私空间的开源替代方案,确实对用户不太友好。我不是技术人员,但是自己有一个网站,了解如何管理 Wordpress,可以排除一些基本的故障,但我用不来命令行,也做不来任何需要编码的事。 + +提供的这些替代方案中的大多数,即便不能完整替代 Google 产品的功能,但至少可以轻松上手。不过有些还是需要你有自己的 Web 主机或服务器的。 + +此外,[Google Takeout][11] 是你的好帮手。我通过它下载了我所有的电子邮件历史记录,并将其上传到我的计算机上,再通过 Thunderbird 访问,这意味着我可以轻松访问这十几年的电子邮件。关于日历和文档也同样如此,我将后者转换为 ODT 格式,存在我的替代云上,下面我将进一步介绍其中的细节。 + +### 初级 + +#### 搜索引擎 + +[DuckDuckGo][12] 和 [startpage][13] 都是以保护个人隐私为中心的搜索引擎,不收集任何搜索数据。我用这两个搜索引擎来负责之前用 Google 搜索的所有需求。 + +其它的替代方案:实际上并不多,Google 坐拥全球 74% 的市场份额时,剩下的那些主要是因为中国的原因。不过还有 Ask.com,以及 Bing…… + +#### Chrome + +[Mozilla Firefox][14] —— 近期的[一次大升级][15],是对早期版本的巨大改进。是一个由积极致力于保护隐私的非营利基金会打造的浏览器。它的存在让你觉得没有必要死守 Chrome。 + +其它的替代方案:考虑到 Opera 和 Vivaldi 都基于 Chrome。[Brave][16] 浏览器是我的第二选择。 + +#### Hangouts(环聊)和 Google Chat + +[Jitsi Meet][17] —— 一款 Google Hangouts 的开源免费替代方案。你可以直接在浏览器上使用或下载应用程序。快速,安全,几乎适用于所有平台。 + +其它的替代方案:Zoom 在专业领域渐受青睐,但大部分的特性需要付费。[Signal][18],一个开源、安全的消息通讯类应用程序,可以用来打电话,不过仅限于移动设备。不推荐 Skype,既耗流量,界面还糟。 + +#### Google Maps(地图) + +桌面端:[HERE WeGo][19] —— 加载速度更快,所有能在 Google Maps 找到的几乎都能找到。不过由于某些原因,还缺了一些国家,如日本。 + +移动端:[MAPS.ME][20] —— 我一开始用的就是这款地图,但是自从他们专注于导航模式后地图功能就有点鸡肋了。MAPS.ME 还是相当不错的,并且具有比 Google 更好的离线功能,这对像我这样的经常旅行的人来说非常好用。 + +其它的替代方案:[OpenStreetMap][21] 是我全心支持的一个项目,不过功能严重缺乏。甚至无法找到我在奥克兰的家庭住址。 + +### 初级(需付费) + +当然其中有一部分是自作自受。例如,在寻找 Gmail 的替代品时,我想的不是仅仅从 Gmail 切换到另一家科技巨头产品作为替代。这就意味不会存在转到 Yahoo Mail 或 Microsoft Outlook 的情况,因为这并不能消除我对隐私问题的困扰。 + +请记住,虽说 Google 的许多服务都是免费的(更不必说包括 Facebook 在内的竞争对手的服务),那是因为他们正在积极地将我们的数据货币化。由于替代方案极力避免将数据货币化,这使他们不得不向我们收取费用。我愿意付钱来保护我的隐私,但也明白并非所有人都会做出这样的选择。 + +或许我们可以换一个方向来思考:可还曾记得以前寄信时也不得不支付邮票的费用吗?或者从商店购买周卡会员?从本质上讲,这就是使用注重隐私的电子邮件或日历应用程序的成本。也没那么糟。 + +#### Gmail + +[ProtonMail][22] —— 由前 CERN(欧洲核子研究中心)的科学家创立,总部设在瑞士,一个拥有强大隐私保护的国家。但 ProtonMail 真正吸引我的地方是,它与大多数其它注重隐私的电子邮件程序不同,用户体验友好。界面类似于 Gmail,带标签,有过滤器和文件夹,无需了解任何有关安全性或隐私的信息即可使用。 + +免费版只提供 500MB 的存储空间。而我选择的是付费 5GB 帐户及其 VPN 服务。 + +其它的替代方案:[Fastmail][23] 不仅面向注重隐私的用户,界面也很棒。还有 [Hushmail][24] 和 [Tutanota][25],两者都具有与 ProtonMail 相似的功能。 + +#### Calendar(日历) + +[Fastmail][26] 日历 —— 这个决定异常艰难,也抛出了另一个问题。Google 的产品存在于很多方面,可以用无处不在来形容,这导致初创公司甚至不再费心去创造替代品。在尝试了其它一些平庸的选项后,我最后还是推荐并选择 Fastmail 同时作为备用电子邮件和日历的选项。 + +### 进阶 + +这些需要一些技术知识,或者需要你自己有 Web 主机。我尝试研究过更简单的替代方案,但最终都没能入围。 + +#### Google Docs(文档)、Drive(云端硬盘)、Photos(照片)和 Contacts(联系人) + +[Nextcloud][27] —— 一个功能齐全、安全并且开源的云套件,具有直观、友好的用户界面。问题是你需要自己有主机才能使用 Nextcloud。我有一个用于部署自己网站的主机,并且能够使用 Softaculous 在我主机的 C-Panel 上快速安装 Nextcloud。你需要一个 HTTPS 证书,我从 [Let's Encrypt][28] 上免费获得了一个。不似开通 Google Drive 帐户那般容易,但也不是很难。 + +同时我也在用 Nextcloud 作为 Google 的照片存储和联系人的替代方案,然后通过 CalDev 与手机同步。 + +其它的替代方案:还有其它开源选项,如 [ownCloud][29] 或者 [Openstack][30]。一些营利的选项也很不错,因为作为首选的 Dropbox 和 Box 也没有采用从你的数据中牟利的运营模式。 + +#### Google Analytics(分析) + +[Matomo][31] —— 正式名为 Piwic,这是一个自托管的分析平台。虽然不像 Google 分析那样功能丰富,但可以很好地分析基本的网站流量,还有一个额外的好处,就是你无需为 Google 贡献流量数据了。 + +其它的替代方案:真的不多。[OpenWebAnalytics][32] 是另一个开源选择,还有一些营利性的选择,比如 GoStats 和 Clicky。 + +#### Android(安卓) + +[LineageOS][33] + [F-Droid App Store][34]。可悲的是,智能手机世界已成为一个事实上的双头垄断,Google 的 Android 和 Apple 的 iOS 控制着整个市场。几年前存在的几个可用的替代品,如 Blackberry OS 或 Mozilla 的 Firefox OS,也已不再维护。 + +因此,只能选择次一级的 Lineage OS:一款注重隐私的、开源的 Android 版本,Google 服务及 APP 是选装的。这需要懂一些技术知识,因为安装的整个过程并不是那么一帆风顺,但运行状况良好,且不似大多数 Android 那般有大量预置软件。 + +其它的替代方案:呃…… Windows 10 Mobile?[PureOS][35] 看起来有那么点意思,[UbuntuTouch][36] 也差不多。 + +### 意想不到的挑战 + +首先,由于有关可用替代方案的优质资源匮乏,以及将数据从 Google 迁移到其它平台所面临的挑战,所以比我计划的时间要长许多。 + +但最棘手的是电子邮件,这与 ProtonMail 或 Google 无关。 + +在我 2004 年加入 Gmail 之前,我可能每年都会切换一次电子邮件。我的第一个帐户是使用 Hotmail,然后我使用了 Mail.com,Yahoo Mail 以及像 Bigfoot 这样被遗忘已久的服务。当我在变更电子邮件提供商时,我未曾记得有这般麻烦。我会告诉所有朋友,更新他们的地址簿,并更改其它网络帐户的邮箱地址。以前定期更改邮箱地址非常必要 —— 还记得曾几何时垃圾邮件是如何盘踞你旧收件箱的吗? + +事实上,Gmail 最好的创新之一就是能够将垃圾邮件过滤掉。这意味着再也不用频繁更改邮箱地址了。 + +电子邮件是使用互联网的关键。你需要用它来开设 Facebook 帐户,使用网上银行,在留言板上发布等等。因此,当你决定切换帐户时,你就需要更新所有这些不同服务的邮箱地址。 + +令人惊讶的是,现在从 Gmail 迁出居然成为了最大的麻烦,因为遍地都需要通过邮箱地址来设置帐户。有几个站点不再允许你从后台执行此操作。有个服务事实上就是让我注销现在的帐户,然后开通一个新的,只因他们无法更改我的邮箱地址,然后他们手动转移了我的帐户数据。另一些迫使我打电话给客服要求更改邮箱地址,无谓的浪费了很多时间。 + +更令人惊讶的是,另一些服务接受了我的更改,却仍继续向我原来的 Gmail 帐户发送邮件,就需要打一次电话了。另一些甚至更烦人,向我的新电子邮件发送了一些消息,但仍在使用我的旧帐户发送其它电子邮件。这事最后变得异常繁琐,迫使我不得不将我的 Gmail 帐户和我新的 ProtonMail 帐户同时开了几个月,以确保重要的电子邮件不会丢失。这是我花了六个月时间的主要元凶。 + +如今人们很少变更他们的邮箱地址,大多数公司的平台在设计时就没有考虑去处理这种可能性。这是表明当今网络糟糕状态的一个明显迹象,即便是在 2002 年更改邮箱地址都比 2018 年来的容易。技术也并不总是一成不变的向前发展。 + +### 那么,这些 Google 的替代方案都好用吗? + +有些确实更好!Jitsi Meet 运行更顺畅,需要的带宽更少,并且比 Hangouts 跨平台支持好。Firefox 比 Chrome 更稳定,占用的内存更少。Fastmail 的日历具有更好的时区集成。 + +还有些旗鼓相当。ProtonMail 具有 Gmail 的大部分功能,但缺少一些好用的集成,例如我之前使用的 Boomerang 邮件日程功能。还缺少联系人界面,但我正在使用 Nextcloud。说到 Nextcloud,它非常适合托管文件、联系人,还包含了一个漂亮的笔记工具(以及诸多其它插件)。但它没有 Google Docs 丰富的多人编辑功能。在我的预算中,还没有找到可行的替代方案。虽然还有 Collabora Office,但这需要升级我的服务器,这对我来说不能算切实可行。 + +一些取决于位置。在一些国家(如印度尼西亚),MAPS.ME 实际上比 Google 地图更好用,而在另一些国家(包括美国)就差了许多。 + +还有些要求用户牺牲一些特性或功能。Piwic 是一个穷人版的 Google Analytics,缺乏前者的许多详细报告和搜索功能。DuckDuckGo 适用于一般搜索,但是在特定的搜索方面还存在问题,当我搜索非英文内容时,它和 startpage 时常都会检索失败。 + +### 最后,我不再心念 Google + +事实上,我觉得我解放了。如此这般依赖单一公司的那么多产品是一种形式上奴役,特别是当你的数据经常为你买单的时候。而且,其中许多替代方案实际上更好。清楚自己正掌控自己数据的感觉真得很爽。 + +如果我们别无选择,只能使用 Google 的产品,那我们便失去了作为消费者的最后一丝力量。 + +我希望 Google、Facebook、Apple 和其他科技巨头在对待用户时不要这么理所当然,不要试图强迫我们进入其无所不包的生态系统。我也期待新选手能够出现并与之竞争,就像以前一样,Google 的新搜索工具可以与当时的行业巨头 Altavista 和 Yahoo 竞争,或者说 Facebook 的社交网络能够与 MySpace 和 Friendster 竞争。Google 给出了更好的搜索方案,使互联网变得更加美好。有选择是个好事,可移植也是。 + +如今,我们很少有人哪怕只是尝试其它产品,因为我们已经习惯了 Google。我们不再更改邮箱地址,因为这太难了。我们甚至不尝试使用 Facebook 以外的替代品,因为我们所有的朋友都在 Facebook 上。这些我明白。 + +你不必完全脱离 Google。但最好给其它选择一个机会。到时候时你可能会感到惊讶,并想起那些年上网的初衷。 + +--- + +### 其它资源 + +我并未打算让这篇文章成为包罗万象的指南,这只不过是一个关于我如何脱离 Google 的故事。以下的那些资源会向你展示其它替代方案。其中有一些对我来说过于专业,还有一些我还没有时间去探索。 + +* [Localization Lab][2] 一份开源或注重隐私技术的项目的详细清单 —— 有些技术含量高,有些用户友好度比较好。 +* [Framasoft][3] 有一整套针对 Google 的替代方案,大部分是开源的,虽然大部分是法语。 +* Restore Privacy 也[整理了一份替代方案的清单][4]。 + +到你了。你可以直接回复或者通过 Twitter 来分享你喜欢的 Google 产品的替代方案。我确信我遗漏了许多,也非常乐意尝试。我并不打算一直固守我列出的这些方案。 + +--- + +作者简介: + +Nithin Coca + +自由撰稿人,涵盖政治,环境和人权以及全球科技的社会影响。更多参考 http://www.nithincoca.com + +--- + +via: https://medium.com/s/story/how-i-fully-quit-google-and-you-can-too-4c2f3f85793a + +作者:[Nithin Coca][a] +译者:[martin2011qi](https://github.com/martin2011qi) +校对:[pityonline](https://github.com/pityonline) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://medium.com/@excinit +[1]: https://medium.com/@excinit +[2]: https://www.localizationlab.org/projects/ +[3]: https://framasoft.org/?l=en +[4]: https://restoreprivacy.com/google-alternatives/ +[5]: https://medium.com/@excinit +[6]: https://www.nithincoca.com/2011/11/20/7-months-no-facebook/ +[7]: https://www.quora.com/How-long-was-Gmail-in-private-%28invitation-only%29-beta +[8]: https://www.theverge.com/2018/4/28/17293056/facebook-deletefacebook-social-network-monopoly +[9]: https://en.wikipedia.org/wiki/Google_Play_Services +[10]: https://www.theguardian.com/world/2013/jun/06/us-tech-giants-nsa-data +[11]: https://takeout.google.com/settings/takeout +[12]: https://duckduckgo.com/ +[13]: https://www.startpage.com/ +[14]: https://www.mozilla.org/en-US/firefox/new/ +[15]: https://www.seattletimes.com/business/firefox-is-back-and-its-time-to-give-it-a-try/ +[16]: https://brave.com/ +[17]: https://jitsi.org/jitsi-meet/ +[18]: https://signal.org/ +[19]: https://wego.here.com/ +[20]: https://maps.me/ +[21]: https://www.openstreetmap.org/ +[22]: https://protonmail.com/ +[23]: https://www.fastmail.com/ +[24]: https://www.hushmail.com/ +[25]: https://tutanota.com/ +[26]: https://www.fastmail.com/ +[27]: https://nextcloud.com/ +[28]: https://letsencrypt.org/ +[29]: https://owncloud.org/ +[30]: https://www.openstack.org/ +[31]: https://matomo.org/ +[32]: http://www.openwebanalytics.com/ +[33]: https://lineageos.org/ +[34]: https://f-droid.org/en/ +[35]: https://puri.sm/posts/tag/pureos/ +[36]: https://ubports.com/ diff --git a/published/201808/20180711 Javascript Framework Comparison with Examples React Vue Hyperapp.md b/published/201808/20180711 Javascript Framework Comparison with Examples React Vue Hyperapp.md new file mode 100644 index 0000000000..48c6187c94 --- /dev/null +++ b/published/201808/20180711 Javascript Framework Comparison with Examples React Vue Hyperapp.md @@ -0,0 +1,169 @@ +JavaScript 框架对比及案例(React、Vue 及 Hyperapp) +============================================= + +在[我的上一篇文章中][5],我试图解释为什么我认为 [Hyperapp][6] 是一个 [React][7] 或 [Vue][8] 的可用替代品,原因是,我发现它易于起步。许多人批评这篇文章,认为它自以为是,并没有给其它框架一个展示自己的机会。因此,在这篇文章中,我将尽可能客观的通过提供一些最小化的例子来比较这三个框架,以展示它们的能力。 + +### 耳熟能详的计时器例子 + +计时器可能是响应式编程中最常用的例子之一,极其易于理解: + +* 你需要一个变量 `count` 保持对计数器的追踪。 +* 你需要两个方法来增加或减少 `count` 变量的值。 +* 你需要一种方法来渲染 `count` 变量,并将其呈现给用户。 +* 你需要挂载到这两个方法上的两个按钮,以便在用户和它们产生交互时变更 `count` 变量。 + +下述代码是上述所有三个框架的实现: + +![](https://cdn-images-1.medium.com/max/2000/1*SqyC-DRj22wZRBiI-NOiwA.png) + +*使用 React、Vue 和 Hyperapp 实现的计数器* + +这里或许会有很多要做的事情,特别是当你并不熟悉其中的一个或多个步骤的时候,因此,我们来一步一步解构这些代码: + +* 这三个框架的顶部都有一些 `import` 语句 +* React 更推崇面向对象的范式,就是创建一个 `Counter` 组件的 `class`。Vue 遵循类似的范式,通过创建一个新的 `Vue` 类的实例并将信息传递给它来实现。最后,Hyperapp 坚持函数范式,同时完全彼此分离 `view`、`state`和`action`。 +* 就 `count` 变量而言, React 在组件的构造函数内对其进行实例化,而 Vue 和 Hyperapp 则分别是在它们的 `data` 和 `state` 中设置这些属性。 +* 继续看,你可能注意到 React 和 Vue 有相同的方法来与 `count` 变量进行交互。 React 使用继承自 `React.Component` 的 `setState` 方法来修改它的状态,而 Vue 直接修改 `this.count`。 Hyperapp 使用 ES6 的双箭头语法来实现这个方法,而据我所知,这是唯一一个推荐使用这种语法的框架,React 和 Vue 需要在它们的方法内使用 `this`。另一方面,Hyperapp 的方法需要将状态作为参数,这意味着可以在不同的上下文中重用它们。 +* 这三个框架的渲染部分实际上是相同的。唯一的细微差别是 Vue 需要一个函数 `h` 作为参数传递给渲染器,事实上 Hyperapp 使用 `onclick` 替代 `onClick` ,以及基于每个框架中实现状态的方式引用 `count` 变量。 +* 最后,所有的三个框架都被挂载到了 `#app` 元素上。每个框架都有稍微不同的语法,Vue 则使用了最直接的语法,通过使用元素选择器而不是使用元素来提供最大的通用性。 + +#### 计数器案例对比意见 + +同时比较所有的三个框架,Hyperapp 需要最少的代码来实现计数器,并且它是唯一一个使用函数范式的框架。然而,Vue 的代码在绝对长度上似乎更短一些,元素选择器的挂载方式是一个很好的增强。React 的代码看起来最多,但是并不意味着代码不好理解。 + +### 使用异步代码 + +偶尔你可能需要处理异步代码。最常见的异步操作之一是发送请求给一个 API。为了这个例子的目的,我将使用一个[占位 API] 以及一些假数据来渲染一个文章列表。必须做的事情如下: + +* 在状态里保存一个 `posts` 的数组 +* 使用一个方法和正确的 URL 来调用 `fetch()` ,等待返回数据,转化为 JSON,并最终使用接收到的数据更新 `posts` 变量。 +* 渲染一个按钮,这个按钮将调用抓取文章的方法。 +* 渲染有主键的 `posts` 列表。 + +![](https://cdn-images-1.medium.com/max/2000/1*aubSG-bpe4g20EOJ_99CFA.png) + +*从一个 RESTFul API 抓取数据* + +让我们分解上面的代码,并比较三个框架: + +* 与上面的技术里例子类似,这三个框架之间的存储状态、渲染视图和挂载非常相似。这些差异与上面的讨论相同。 +* 在三个框架中使用 `fetch()` 抓取数据都非常简单,并且可以像预期一样工作。然而其中的关键在于, Hyperapp 处理异步操作和其它两种框架有些不同。当数据被接收到并转换为 JSON 时,该操作将调用不同的同步动作以取代直接在异步操作中修改状态。 +* 就代码长度而言,Hyperapp 依然只用最少的代码行数实现了相同的结果,但是 Vue 的代码看起来不那么的冗长,同时拥有最少的绝对字符长度。 + +#### 异步代码对比意见 + +无论你选择哪种框架,异步操作都非常简单。在应用异步操作时, Hyperapp 可能会迫使你去遵循编写更加函数化和模块化的代码的方式。但是另外两个框架也确实可以做到这一点,并且在这一方面给你提供更多的选择。 + +### To-Do 列表组件案例 + +在响应式编程中,最出名的例子可能是使用每一个框架里来实现 To-Do 列表。我不打算在这里实现整个部分,我只实现一个无状态的组件,来展示三个框架如何创建更小的可复用的块来协助构建应用程序。 + +![](https://cdn-images-1.medium.com/max/1600/1*3-v6XHigZe_5VfPvcR6nyQ.png) + +*示例 TodoItem 实现* + +上面的图片展示了每一个框架一个例子,并为 React 提供了一个额外的例子。接下来是我们从它们四个中看到的: + +* React 在编程范式上最为灵活。它支持函数组件,也支持类组件。它还支持你在右下角看到的 Hyperapp 组件,无需任何修改。 +* Hyperapp 还支持 React 的函数组件实现,这意味着两个框架之间还有很多的实验空间。 +* 最后出现的 Vue 有着其合理而又奇怪的语法,即使是对另外两个框架很有经验的人,也不能马上理解其含义。 +* 在长度方面,所有的案例代码长度非常相似,在 React 的一些方法中稍微冗长一些。 + +#### To-Do 列表项目对比意见 + +Vue 需要花费一些时间来熟悉,因为它的模板和其它两个框架有一些不同。React 非常的灵活,支持多种不同的方法来创建组件,而 HyperApp 保持一切简单,并提供与 React 的兼容性,以免你希望在某些时刻进行切换。 + +### 生命周期方法比较 + +另一个关键对比是组件的生命周期事件,每一个框架允许你根据你的需要来订阅和处理事件。下面是我根据各框架的 API 参考手册创建的表格: + +![](https://cdn-images-1.medium.com/max/1600/1*yj4H9pYnagZ7b1pyRE-wmQ.png) + +*生命周期方式比较* + +* Vue 提供了最多的生命周期钩子,提供了处理生命周期事件之前或之后发生的任何事件的机会。这能有效帮助管理复杂的组件。 +* React 和 Hyperapp 的生命周期钩子非常类似,React 将 `unmount` 和 `destory` 绑定在了一起,而 Hyperapp 则将 `create` 和 `mount` 绑定在了一起。两者在处理生命周期事件方面都提供了相当多的控制。 +* Vue 根本没有处理 `unmount` (据我所理解),而是依赖于 `destroy` 事件在组件稍后的生命周期进行处理。 React 不处理 `destory` 事件,而是选择只处理 `unmount` 事件。最终,HyperApp 不处理 `create` 事件,取而代之的是只依赖 `mount` 事件。 + +#### 生命周期对比意见 + +总的来说,每个框架都提供了生命周期组件,它们帮助你处理组件生命周期中的许多事情。这三个框架都为它们的生命周期提供了钩子,其之间的细微差别,可能源自于实现和方案上的根本差异。通过提供更细粒度的时间处理,Vue 可以更进一步的允许你在开始或结束之后处理生命周期事件。 + +### 性能比较 + +除了易用性和编码技术以外,性能也是大多数开发人员考虑的关键因素,尤其是在进行更复杂的应用程序时。[js-framework-benchmark][10] 是一个很好的用于比较框架的工具,所以让我们看看每一组测评数据数组都说了些什么: + +![](https://cdn-images-1.medium.com/max/1600/1*ojtkwrkY4NETUmPsfQYDYA.png) + +*测评操作表* + +* 与三个框架的有主键操作相比,无主键操作更快。 +* 无主键的 React 在所有六种对比中拥有最强的性能,它在所有测试上都有令人深刻的表现。 +* 有主键的 Vue 只比有主键的 React 性能稍强,而无主键的 Vue 要比无主键的 React 性能明显差。 +* Vue 和 Hyperapp 在进行局部更新的性能测试时遇见了一些问题,与此同时,React 似乎对该问题进行很好的优化。 + +![](https://cdn-images-1.medium.com/max/1600/1*YFIM2Rd93jDnEZmqw_k3cw.png) + +*启动测试* + +* Hyperapp 是三个框架中最轻量的,而 React 和 Vue 有非常小的大小差异。 +* Hyperapp 具有最快的启动时间,这得益于它极小的大小和极简的 API +* Vue 在启动上比 React 好一些,但是差异非常小。 + +![](https://cdn-images-1.medium.com/max/1600/1*WVtufoJUvyjkaeEl2hz2sQ.png) + +*内存分配测试* + +* Hyperapp 是三者中对资源依赖最小的一个,与其它两者相比,任何一个操作都需要更少的内存。 +* 资源消耗不是非常高,三者都应该在现代硬件上进行类似的操作。 + +#### 性能对比意见 + +如果性能是一个问题,你应该考虑你正在使用什么样的应用程序以及你的需求是什么。看起来 Vue 和 React 用于更复杂的应用程序更好,而 Hyperapp 更适合于更小的应用程序、更少的数据处理和需要快速启动的应用程序,以及需要在低端硬件上工作的应用程序。 + +但是,要记住,这些测试远不能代表一般场景,所以在现实场景中可能会看到不同的结果。 + +### 额外备注 + +比较 React、Vue 和 Hyperapp 可能像在许多方面比较苹果、橘子。关于这些框架还有一些其它的考虑,它们可以帮助你决定使用另一个框架。 + +* React 通过引入[片段][1],避免了相邻的 JSX 元素必须封装在父元素中的问题,这些元素允许你将子元素列表分组,而无需向 DOM 添加额外的节点。 +* React 还为你提供[更高级别的组件][2],而 VUE 为你提供重用组件功能的 [MIXIN][3]。 +* Vue 允许使用[模板][4]来分离结构和功能,从而更好的分离关注点。 +* 与其它两个相比,Hyperapp 感觉像是一个较低级别的 API,它的代码短得多,如果你愿意调整它并学习它的工作原理,那么它可以提供更多的通用性。 + +### 结论 + +我认为如果你已经阅读了这么多,你已经知道哪种工具更适合你的需求。毕竟,这不是讨论哪一个更好,而是讨论哪一个更适合每种情况。总而言之: + +* React 是一个非常强大的工具,围绕它有大规模的开发者社区,可能会帮助你找到一个工作。入门并不难,但是掌握它肯定需要很多时间。然而,这是非常值得去花费你的时间全面掌握的。 +* 如果你过去曾使用过另外的 JavaScript 框架,Vue 可能看起来有点奇怪,但它也是一个非常有趣的工具。如果 React 不是你所喜欢的,那么它可能是一个可行的、值得学习的选择。它有一些非常酷的内置功能,其社区也在增长中,甚至可能要比 React 增长还要快。 +* 最后,Hyperapp 是一个为小型项目而生的很酷的小框架,也是初学者入门的好地方。它提供比 React 或 Vue 更少的工具,但是它能帮助你快速构建原型并理解许多基本原理。你为它编写的许多代码和其它两个框架兼容,要么立即能用,或者是稍做更改就行,你可以在对它们中另外一个有信心时切换框架。 + +-------------------------------------------------------------------------------- + +作者简介: + +喜欢编码的 Web 开发者,“30 秒编码” ( https://30secondsofcode.org/ )和 mini.css 框架( http://minicss.org ) 的创建者。 + +-------------------------------------------------------------------------------- + +via: https://hackernoon.com/javascript-framework-comparison-with-examples-react-vue-hyperapp-97f064fb468d + +作者:[Angelos Chalaris][a] +译者:[Bestony](https://github.com/bestony) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://hackernoon.com/@chalarangelo?source=post_header_lockup +[1]:https://reactjs.org/docs/fragments.html +[2]:https://reactjs.org/docs/higher-order-components.html +[3]:https://vuejs.org/v2/guide/mixins.html +[4]:https://vuejs.org/v2/guide/syntax.html +[5]:https://hackernoon.com/i-abandonded-react-in-favor-of-hyperapp-heres-why-df65638f8a79 +[6]:https://hyperapp.js.org/ +[7]:https://reactjs.org/ +[8]:https://vuejs.org/ +[9]:https://jsonplaceholder.typicode.com/ +[10]:https://github.com/krausest/js-framework-benchmark diff --git a/published/201808/20180711 netdev-day-1--ipsec.md b/published/201808/20180711 netdev-day-1--ipsec.md new file mode 100644 index 0000000000..1188757861 --- /dev/null +++ b/published/201808/20180711 netdev-day-1--ipsec.md @@ -0,0 +1,117 @@ +netdev 第一天:IPsec! +============================================================ + +嗨!和去年一样,今年我又参加了 [netdev 会议][3]。([这里][14]是我上一年所做的笔记)。 + +在今天的会议中,我学到了很多有关 IPsec 的知识,所以下面我将介绍它们!其中 Sowmini Varadhan 和 [Paul Wouters][5] 做了一场关于 IPsec 的专题研讨会。本文中的错误 100% 都是我的错 :)。 + +### 什么是 IPsec? + +IPsec 是一个用来加密 IP 包的协议。某些 VPN 已经是通过使用 IPsec 来实现的。直到今天我才真正意识到 VPN 使用了不只一种协议,原来我以为 VPN 只是一个通用术语,指的是“你的数据包将被加密,然后通过另一台服务器去发送“。VPN 可以使用一系列不同的协议(OpenVPN、PPTP、SSTP、IPsec 等)以不同的方式来实现。 + +为什么 IPsec 和其他的 VPN 协议如此不同呢?(或者说,为什么在本次 netdev 会议会有 IPsec 的教程,而不是其他的协议呢?)我的理解是有 2 点使得它如此不同: + +* 它是一个 IETF 标准,例如可以在文档 [RFC 6071][1] 等中查到(你知道 IETF 是制定 RFC 标准的组织吗?我也是直到今天才知道的!)。 +* 它在 Linux 内核中被实现了(所以这才是为什么本次 netdev 会议中有关于它的教程,因为 netdev 是一个跟 Linux 内核网络有关的会议 :))。 + +### IPsec 是如何工作的? + +假如说你的笔记本正使用 IPsec 来加密数据包并通过另一台设备来发送它们,那这是怎么工作的呢?对于 IPsec 来说,它有 2 个部分:一个是用户空间部分,另一个是内核空间部分。 + +IPsec 的用户空间部分负责**密钥的交换**,使用名为 [IKE][6] (网络密钥传输internet key exchange)的协议。总的来说,当你打开一个 VPN 连接的时候,你需要与 VPN 服务器通信,并且和它协商使用一个密钥来进行加密。 + +IPsec 的内核部分负责数据包的实际加密工作 —— 一旦使用 IKE 生成了一个密钥,IPsec 的用户空间部分便会告诉内核使用哪个密钥来进行加密。然后内核便会使用该密钥来加密数据包! + +### 安全策略以及安全关联 + +(LCTT 译注:security association 我翻译为安全关联, 参考自 https://zh.wikipedia.org/wiki/%E5%AE%89%E5%85%A8%E9%97%9C%E8%81%AF ) + +IPSec 的内核部分有两个数据库:**安全策略数据库**(SPD)和**安全关联数据库**(SAD)。 + +安全策略数据库包含 IP 范围和用于该范围的数据包需要执行的操作(对其执行 IPsec、丢弃数据包、让数据包通过)。对于这点我有点迷糊,因为针对不同 IP 范围的数据包所采取的规则已经在路由表(`sudo ip route list`)中使用过,但显然你也可以设定 IPsec 规则,但它们位于不同的地方! + +而在我眼中,安全关联数据库存放有用于各种不同 IP 的加密密钥。 + +查看这些数据库的方式却是非常不直观的,需要使用一个名为 `ip xfrm` 的命令,至于 `xfrm` 是什么意思呢?我也不知道! + +(LCTT 译注:我在 https://www.allacronyms.com/XFMR/Transformer 上查到 xfmr 是 Transformer 的简写,又根据 [man7](http://man7.org/linux/man-pages/man8/ip-xfrm.8.html) 上的简介, 我认为这个说法可信。) + +``` +# security policy database +$ sudo ip xfrm policy +$ sudo ip x p + +# security association database +$ sudo ip xfrm state +$ sudo ip x s +``` + +### 为什么 IPsec 被实现在 Linux 内核中而 TLS 没有? + +对于 TLS 和 IPsec 来说,当打开一个连接时,它们都需要做密钥交换(使用 Diffie-Hellman 或者其他算法)。基于某些可能很明显但我现在还没有理解(??)的原因,在内核中人们并不想做密钥的交换。 + +IPsec 更容易在内核实现的原因是使用 IPsec 你可以更少频率地协商密钥的交换(对于每个你想通过 VPN 来连接的 IP 只需要一次),并且 IPsec 会话存活得更长。所以对于用户空间来说,使用 IPsec 来做密钥交换、密钥的获取和将密钥传递给内核将更容易,内核得到密钥后将使用该密钥来处理每个 IP 数据包。 + +而对于 TLS 来说,则存在一些问题: + +a. 当你每打开一个 TLS 连接时,每次你都要做新的密钥交换,并且 TLS 连接存活时间较短。 +b. 当你需要开始做加密时,使用 IPsec 没有一个自然的协议边界,你只需要加密给定 IP 范围内的每个 IP 包即可,但如果使用 TLS,你需要查看 TCP 流,辨别 TCP 包是否是一个数据包,然后决定是否加密它。 + +实际上有一个补丁用于 [在 Linux 内核中实现 TLS][7],它让用户空间做密钥交换,然后传给内核密钥,所以很明显,使用 TLS 不是不可能的,但它是一个新事物,并且我认为相比使用 IPsec,使用 TLS 更加复杂。 + +### 使用什么软件来实现 IPsec 呢? + +据我所知有 Libreswan 和 Strongswan 两个软件。今天的教程关注的是 libreswan。 + +有些让人迷糊的是,尽管 Libreswan 和 Strongswan 是不同的程序包,但它们都会安装一个名为 `ipsec` 的二进制文件来管理 IPsec 连接,并且这两个 `ipsec` 二进制文件并不是相同的程序(尽管它们担任同样的角色)。 + +在上面的“IPsec 如何工作”部分,我已经描述了 Strongswan 和 Libreswan 做了什么 —— 使用 IKE 做密钥交换,并告诉内核有关如何使用密钥来做加密。 + +### VPN 不是只能使用 IPsec 来实现! + +在本文的开头我说“IPsec 是一个 VPN 协议”,这是对的,但你并不必须使用 IPsec 来实现 VPN!实际上有两种方式来使用 IPsec: + +1. “传输模式”,其中 IP 表头没有改变,只有 IP 数据包的内容被加密。这种模式有点类似于使用 TLS —— 你直接告诉服务器你正在通信(而不是通过一个 VPN 服务器或其他设备),只有 IP 包里的内容被加密。 +2. ”隧道模式“,其中 IP 表头和它的内容都被加密了,并且被封装进另一个 UDP 包内。这个模式被 VPN 所使用 —— 你获取你正传送给一个秘密网站的包,然后加密它,并将它送给你的 VPN 服务器,然后 VPN 服务器再传送给你。 + +### 投机的 IPsec + +今天我学到了 IPsec “传输模式”的一个有趣应用,它叫做 “投机的 IPsec”(通过它,你可以通过开启一个 IPsec 连接来直接和你要通信的主机连接,而不是通过其他的中介服务器),现在已经有一个“投机的 IPsec” 服务器了,它位于 [http://oe.libreswan.org/][8]。 + +我认为当你在你的电脑上设定好 `libreswan` 和 `unbound` DNS 程序后,当你连接到 [http://oe.libreswan.org][8] 时,主要发生了如下的几件事: + +1. `unbound` 做一次 DNS 查询来获取 `oe.libreswan.org` (`dig ipseckey oe.libreswan.org`) 的 IPSECKEY 记录,以便获取到公钥来用于该网站(这需要 DNSSEC 是安全的,并且当我获得足够多这方面的知识后,我将用另一篇文章来说明它。假如你想看到相关的结果,并且如果你只是使用 dig 命令来运行此次 DNS 查询的话,它也可以工作)。 +2. `unbound` 将公钥传给 `libreswan` 程序,然后 `libreswan` 使用它来和运行在 `oe.libreswan.org` 网站上的 IKE 服务器做一次密钥交换。 +3. `libreswan`  完成了密钥交换,将加密密钥传给内核并告诉内核当和 `oe.libreswan.org` 做通信时使用该密钥。 +4. 你的连接现在被加密了!即便它是 HTTP 连接!有趣吧! + +### IPsec 和 TLS 相互借鉴 + +在今天的教程中听到一个有趣的花絮是 IPsec 和 TLS 协议实际上总是从对方学习 —— 正如他们说在 TLS 出现前, IPsec 的 IKE 协议有着完美的正向加密,而 IPsec 也从 TLS 那里学了很多。很高兴能听到不同的网络协议之间是如何从对方那里学习并与时俱进的事实! + +### IPsec 是有趣的! + +我已经花了很长时间来学习 TLS,很明显它是一个超级重要的网络协议(让我们来加密网络吧!:D)。但 IPsec 也是一个很重要的网络加密协议,它与 TLS 有着不同的角色!很明显有些移动电话协议(例如 5G/LTE)使用 IPsec 来加密它们的网络流量! + +现在我很高兴我知道更多关于 IPsec 的知识!和以前一样可能本文有些错误,但希望不会错的太多 :) + +-------------------------------------------------------------------------------- + +via: https://jvns.ca/blog/2018/07/11/netdev-day-1--ipsec/ + +作者:[Julia Evans][a] +译者:[FSSlc](https://github.com/FSSlc) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://jvns.ca/about +[1]:https://tools.ietf.org/html/rfc6071 +[2]:https://jvns.ca/categories/netdev +[3]:https://www.netdevconf.org/0x12/ +[4]:https://jvns.ca/categories/netdev/ +[5]:https://nohats.ca/ +[6]:https://en.wikipedia.org/wiki/Internet_Key_Exchange +[7]:https://blog.filippo.io/playing-with-kernel-tls-in-linux-4-13-and-go/ +[8]:http://oe.libreswan.org/ +[14]:https://jvns.ca/categories/netdev/ \ No newline at end of file diff --git a/published/201808/20180712 A sysadmin-s guide to SELinux- 42 answers to the big questions.md b/published/201808/20180712 A sysadmin-s guide to SELinux- 42 answers to the big questions.md new file mode 100644 index 0000000000..e8f93b59e3 --- /dev/null +++ b/published/201808/20180712 A sysadmin-s guide to SELinux- 42 answers to the big questions.md @@ -0,0 +1,171 @@ +系统管理员的 SELinux 指南:这个大问题的 42 个答案 +====== + +> 获取有关生活、宇宙和除了有关 SELinux 的重要问题的答案 + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/security-lock-password.jpg?itok=KJMdkKum) + +> “一个重要而普遍的事实是,事情并不总是你看上去的那样 …” +> ―Douglas Adams,《银河系漫游指南》 + +安全、坚固、遵从性、策略是末世中系统管理员的四骑士。除了我们的日常任务之外 —— 监控、备份、实施、调优、更新等等 —— 我们还需要负责我们的系统安全。即使这些系统是第三方提供商告诉我们该禁用增强安全性的系统。这看起来像《碟中碟》中 [Ethan Hunt][1] 的工作一样。 + +面对这种窘境,一些系统管理员决定去[服用蓝色小药丸][2],因为他们认为他们永远也不会知道如生命、宇宙、以及其它一些大问题的答案。而我们都知道,它的答案就是这个 **[42][3]**。 + +按《银河系漫游指南》的精神,这里是关于在你的系统上管理和使用 [SELinux][4] 这个大问题的 42 个答案。 + +1. SELinux 是一个标签系统,这意味着每个进程都有一个标签。每个文件、目录、以及系统对象都有一个标签。策略规则负责控制标签化的进程和标签化的对象之间的访问。由内核强制执行这些规则。 +2. 两个最重要的概念是:标签化(文件、进程、端口等等)和类型强制(基于不同的类型隔离不同的的进程)。 +3. 正确的标签格式是 `user:role:type:level`(可选)。 +4. 多级别安全Multi-Level Security(MLS)强制的目的是基于它们所使用数据的安全级别,对进程(域)强制实施控制。比如,一个秘密级别的进程是不能读取极机密级别的数据。 +5. 多类别安全Multi-Category Security(MCS)强制相互保护相似的进程(如虚拟机、OpenShift gears、SELinux 沙盒、容器等等)。 +6. 在启动时改变 SELinux 模式的内核参数有: + * `autorelabel=1` → 强制给系统重新标签化 + * `selinux=0` → 内核不加载 SELinux 基础设施的任何部分 + * `enforcing=0` → 以许可permissive模式启动 +7. 如果给整个系统重新标签化: + + ``` + # touch /.autorelabel + # reboot + ``` +如果系统标签中有大量的错误,为了能够让 autorelabel 成功,你可以用许可模式引导系统。 +8. 检查 SELinux 是否启用:`# getenforce` +9. 临时启用/禁用 SELinux:`# setenforce [1|0]` +10. SELinux 状态工具:`# sestatus` +11. 配置文件:`/etc/selinux/config` +12. SELinux 是如何工作的?这是一个为 Apache Web Server 标签化的示例: + * 二进制文件:`/usr/sbin/httpd`→`httpd_exec_t` + * 配置文件目录:`/etc/httpd`→`httpd_config_t` + * 日志文件目录:`/var/log/httpd` → `httpd_log_t` + * 内容目录:`/var/www/html` → `httpd_sys_content_t` + * 启动脚本:`/usr/lib/systemd/system/httpd.service` → `httpd_unit_file_d` + * 进程:`/usr/sbin/httpd -DFOREGROUND` → `httpd_t` + * 端口:`80/tcp, 443/tcp` → `httpd_t, http_port_t` + + 在 `httpd_t` 安全上下文中运行的一个进程可以与具有 `httpd_something_t` 标签的对象交互。 +13. 许多命令都可以接收一个 `-Z` 参数去查看、创建、和修改安全上下文: + * `ls -Z` + * `id -Z` + * `ps -Z` + * `netstat -Z` + * `cp -Z` + * `mkdir -Z` + + 当文件被创建时,它们的安全上下文会根据它们父目录的安全上下文来创建(可能有某些例外)。RPM 可以在安装过程中设定安全上下文。 +14. 这里有导致 SELinux 出错的四个关键原因,它们将在下面的 15 - 21 条中展开描述: + * 标签化问题 + * SELinux 需要知道一些东西 + * SELinux 策略或者应用有 bug + * 你的信息可能被损坏 +15. 标签化问题:如果在 `/srv/myweb` 中你的文件没有被正确的标签化,访问可能会被拒绝。这里有一些修复这类问题的方法: + * 如果你知道标签:`# semanage fcontext -a -t httpd_sys_content_t '/srv/myweb(/.*)?'` + * 如果你知道和它有相同标签的文件:`# semanage fcontext -a -e /srv/myweb /var/www` + * 恢复安全上下文(对于以上两种情况):`# restorecon -vR /srv/myweb` +16. 标签化问题:如果你是移动了一个文件,而不是去复制它,那么这个文件将保持原始的环境。修复这类问题: + * 使用标签来改变安全上下文:`# chcon -t httpd_system_content_t /var/www/html/index.html` + * 使用参考文件的标签来改变安全上下文:`# chcon --reference /var/www/html/ /var/www/html/index.html` + * 恢复安全上下文(对于以上两种情况):`# restorecon -vR /var/www/html/` +17. 如果 SELinux 需要知道 HTTPD 在 8585 端口上监听,使用下列命令告诉 SELinux:`# semanage port -a -t http_port_t -p tcp 8585` +18. SELinux 需要知道是否允许在运行时改变 SELinux 策略部分,而无需重写 SELinux 策略。例如,如果希望 httpd 去发送邮件,输入:`# setsebool -P httpd_can_sendmail 1` +19. SELinux 需要知道 SELinux 设置的关闭或打开的一系列布尔值: + * 查看所有的布尔值:`# getsebool -a` + * 查看每个布尔值的描述:`# semanage boolean -l` + * 设置某个布尔值:`# setsebool [_boolean_] [1|0]` + * 将它配置为永久值,添加 `-P` 标志。例如:`# setsebool httpd_enable_ftp_server 1 -P` +20. SELinux 策略/应用可能有 bug,包括: + * 不寻常的代码路径 + * 配置 + * 重定向 `stdout` + * 泄露的文件描述符 + * 可执行内存 + * 错误构建的库 + + 开一个工单(但不要提交 Bugzilla 报告;使用 Bugzilla 没有对应的服务) +21. 你的信息可能被损坏了,假如你被限制在某个区域,尝试这样做: + * 加载内核模块 + * 关闭 SELinux 的强制模式 + * 写入 `etc_t/shadow_t` + * 修改 iptables 规则 +22. 用于开发策略模块的 SELinux 工具:`# yum -y install setroubleshoot setroubleshoot-server`。安装完成之后重引导机器或重启 `auditd` 服务。 +23. 使用 `journalctl` 去列出所有与 `setroubleshoot` 相关的日志:`# journalctl -t setroubleshoot --since=14:20` +24. 使用 `journalctl` 去列出所有与特定 SELinux 标签相关的日志。例如:`# journalctl _SELINUX_CONTEXT=system_u:system_r:policykit_t:s0` +25. 当 SELinux 错误发生时,使用`setroubleshoot` 的日志,并尝试找到某些可能的解决方法。例如:从 `journalctl` 中: + ``` + Jun 14 19:41:07 web1 setroubleshoot: SELinux is preventing httpd from getattr access on the file /var/www/html/index.html. For complete message run: sealert -l 12fd8b04-0119-4077-a710-2d0e0ee5755e + + # sealert -l 12fd8b04-0119-4077-a710-2d0e0ee5755e +SELinux is preventing httpd from getattr access on the file /var/www/html/index.html. + + ***** Plugin restorecon (99.5 confidence) suggests ************************ + + If you want to fix the label, + /var/www/html/index.html default label should be httpd_syscontent_t. + Then you can restorecon. + Do + # /sbin/restorecon -v /var/www/html/index.html +``` +26. 日志:SELinux 记录的信息全在这些地方: + * `/var/log/messages` + * `/var/log/audit/audit.log` + * `/var/lib/setroubleshoot/setroubleshoot_database.xml` +27. 日志:在审计日志中查找 SELinux 错误:`# ausearch -m AVC,USER_AVC,SELINUX_ERR -ts today` +28. 针对特定的服务,搜索 SELinux 的访问向量缓存Access Vector Cache(AVC)信息:`# ausearch -m avc -c httpd` +29. `audit2allow` 实用工具可以通过从日志中搜集有关被拒绝的操作,然后生成 SELinux 策略允许的规则,例如: + * 产生一个人类可读的关于为什么拒绝访问的描述:`# audit2allow -w -a` + * 查看允许被拒绝的类型强制规则:`# audit2allow -a` + * 创建一个自定义模块:`# audit2allow -a -M mypolicy`,其中 `-M` 选项将创建一个特定名称的强制类型文件(.te),并编译这个规则到一个策略包(.pp)中:`mypolicy.pp mypolicy.te` + * 安装自定义模块:`# semodule -i mypolicy.pp` +30. 配置单个进程(域)运行在许可模式:`# semanage permissive -a httpd_t` +31. 如果不再希望一个域在许可模式中:`# semanage permissive -d httpd_t` +32. 禁用所有的许可域:`# semodule -d permissivedomains` +33. 启用 SELinux MLS 策略:`# yum install selinux-policy-mls`。 + 在 `/etc/selinux/config` 中: + ``` + SELINUX=permissive + SELINUXTYPE=mls + ``` + 确保 SELinux 运行在许可模式:`# setenforce 0` + + 使用 `fixfiles` 脚本来确保在下一次重启时文件将被重新标签化:`# fixfiles -F onboot # reboot` +34. 创建一个带有特定 MLS 范围的用户:`# useradd -Z staff_u john` + + 使用 `useradd` 命令,映射新用户到一个已存在的 SELinux 用户(上面例子中是 `staff_u`)。 +35. 查看 SELinux 和 Linux 用户之间的映射:`# semanage login -l` +36. 为用户定义一个指定的范围:`# semanage login --modify --range s2:c100 john` +37. 调整用户家目录上的标签(如果需要的话):`# chcon -R -l s2:c100 /home/john` +38. 列出当前类别:`# chcat -L` +39. 修改类别或者创建你自己的分类,修改如下文件:`/etc/selinux/__/setrans.conf` +40. 以某个特定的文件、角色和用户安全上下文来运行一个命令或者脚本:`# runcon -t initrc_t -r system_r -u user_u yourcommandhere` + * `-t` 是文件安全上下文 + * `-r` 是角色安全上下文 + * `-u` 是用户安全上下文 +41. 在容器中禁用 SELinux: + * 使用 Podman:`# podman run --security-opt label=disable ...` + * 使用 Docker:`# docker run --security-opt label=disable ...` +42. 如果需要给容器提供完全访问系统的权限: + * 使用 Podman:`# podman run --privileged ...` + * 使用 Docker:`# docker run --privileged ...` + +就这些了,你已经知道了答案。因此请相信我:**不用恐慌,去打开 SELinux 吧**。 + +### 作者简介 + +Alex Callejas 是位于墨西哥城的红帽公司拉丁美洲区的一名技术客服经理。作为一名系统管理员,他已有超过 10 年的经验。在基础设施强化方面具有很强的专业知识。对开源抱有热情,通过在不同的公共事件和大学中分享他的知识来支持社区。天生的极客,当然他一般选择使用 Fedora Linux 发行版。[这里][11]有更多关于他的信息。 + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/7/sysadmin-guide-selinux + +作者:[Alex Callejas][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[qhwdw](https://github.com/qhwdw), [FSSlc](https://github.com/FSSlc) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://opensource.com/users/darkaxl +[1]:https://en.wikipedia.org/wiki/Ethan_Hunt +[2]:https://en.wikipedia.org/wiki/Red_pill_and_blue_pill +[3]:https://en.wikipedia.org/wiki/Phrases_from_The_Hitchhiker%27s_Guide_to_the_Galaxy#Answer_to_the_Ultimate_Question_of_Life,_the_Universe,_and_Everything_%2842%29 +[4]:https://en.wikipedia.org/wiki/Security-Enhanced_Linux \ No newline at end of file diff --git a/published/201808/20180712 Slices from the ground up.md b/published/201808/20180712 Slices from the ground up.md new file mode 100644 index 0000000000..f631cbfe1d --- /dev/null +++ b/published/201808/20180712 Slices from the ground up.md @@ -0,0 +1,236 @@ +从零开始学习 Go 语言的切片 +====== + +这篇文章受到了我与同事讨论使用切片slice作为stack的一次聊天的启发。后来话题聊到了 Go 语言中的切片是如何工作的。我认为这些信息对别人也有用,所以就把它记录了下来。 + +### 数组 + +任何关于 Go 语言切片的讨论都要从另一个数据结构也就是数组array开始。Go 的数组有两个特性: + +1. 数组的长度是固定的;`[5]int` 是由 5 个 `int` 构成的数组,和 `[3]int` 不同。 +2. 数组是值类型。看下面这个示例: + + ``` + package main + + import "fmt" + + func main() { + var a [5]int + b := a + b[2] = 7 + fmt.Println(a, b) // prints [0 0 0 0 0] [0 0 7 0 0] + } + ``` + + 语句 `b := a` 定义了一个类型是 `[5]int` 的新变量 `b`,然后把 `a` 中的内容 _复制_ 到 `b` 中。改变 `b` 对 `a` 中的内容没有影响,因为 `a` 和 `b` 是相互独立的值。[^1] + +### 切片 + +Go 语言的切片和数组的主要有如下两个区别: + +1. 切片没有一个固定的长度。切片的长度不是它类型定义的一部分,而是由切片内部自己维护的。我们可以使用内置的 `len` 函数知道它的长度。[^2] +2. 将一个切片赋值给另一个切片时 _不会_ 对切片内容进行复制操作。这是因为切片没有直接持有其内部数据,而是保留了一个指向 _底层数组_ [^3] 的指针。数据都保留在底层数组里。 + +基于第二个特性,两个切片可以享有共同的底层数组。看下面的示例: + +1. 对切片取切片 + + ``` + package main + + import "fmt" + + func main() { + var a = []int{1,2,3,4,5} + b := a[2:] + b[0] = 0 + fmt.Println(a, b) // prints [1 2 0 4 5] [0 4 5] + } + ``` + + 在这个例子里,`a` 和 `b` 享有共同的底层数组 —— 尽管 `b` 在数组里的起始偏移量不同,两者的长度也不同。通过 `b` 修改底层数组的值也会导致 `a` 里的值的改变。 + +2. 将切片传进函数 + + ``` + package main + + import "fmt" + + func negate(s []int) { + for i := range s { + s[i] = -s[i] + } + } + + func main() { + var a = []int{1, 2, 3, 4, 5} + negate(a) + fmt.Println(a) // prints [-1 -2 -3 -4 -5] + } + ``` + + 在这个例子里,`a` 作为形参 `s` 的实参传进了 `negate` 函数,这个函数遍历 `s` 内的元素并改变其符号。尽管 `nagate` 没有返回值,且没有访问到 `main` 函数里的 `a`。但是当将之传进 `negate` 函数内时,`a` 里面的值却被改变了。 + +大多数程序员都能直观地了解 Go 语言切片的底层数组是如何工作的,因为它与其它语言中类似数组的工作方式类似。比如下面就是使用 Python 重写的这一小节的第一个示例: + +``` +Python 2.7.10 (default, Feb 7 2017, 00:08:15) +[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)] on darwin +Type "help", "copyright", "credits" or "license" for more information. +>>> a = [1,2,3,4,5] +>>> b = a +>>> b[2] = 0 +>>> a +[1, 2, 0, 4, 5] +``` + +以及使用 Ruby 重写的版本: + +``` +irb(main):001:0> a = [1,2,3,4,5] +=> [1, 2, 3, 4, 5] +irb(main):002:0> b = a +=> [1, 2, 3, 4, 5] +irb(main):003:0> b[2] = 0 +=> 0 +irb(main):004:0> a +=> [1, 2, 0, 4, 5] +``` + +在大多数将数组视为对象或者是引用类型的语言也是如此。[^4] + +### 切片头 + +切片同时拥有值和指针特性的神奇之处在于理解切片实际上是一个结构体struct类型。通常在[反射reflect包内相应部分之后][7]的这个结构体被称作切片头slice header。切片头的定义大致如下: + +![](https://dave.cheney.net/wp-content/uploads/2018/07/slice.001-300x257.png) + +``` +package runtime + +type slice struct { + ptr unsafe.Pointer + len int + cap int +} +``` + +这很重要,因为和 [`map` 以及 `chan` 这两个类型不同][7],切片是值类型,当被赋值或者被作为参数传入函数时候会被复制过去。 + +程序员们都能理解 `square` 的形参 `v` 和 `main` 中声明的 `v` 的是相互独立的。请看下面的例子: + +``` +package main + +import "fmt" + +func square(v int) { + v = v * v +} + +func main() { + v := 3 + square(v) + fmt.Println(v) // prints 3, not 9 +} +``` + +因此 `square` 对自己的形参 `v` 的操作没有影响到 `main` 中的 `v`。下面这个示例中的 `s` 也是 `main` 中声明的切片 `s` 的独立副本, _而不是_ 指向 `main` 的 `s` 的指针。 + +``` +package main + +import "fmt" + +func double(s []int) { + s = append(s, s...) +} + +func main() { + s := []int{1, 2, 3} + double(s) + fmt.Println(s, len(s)) // prints [1 2 3] 3 +} +``` + +Go 的切片是作为值传递而不是指针这一点不太寻常。当你在 Go 内定义一个结构体时,90% 的时间里传递的都是这个结构体的指针[^5] 。切片的传递方式真的很不寻常,我能想到的唯一与之相同的例子只有 `time.Time`。 + +切片作为值传递而不是作为指针传递这一特殊行为会让很多想要理解切片的工作原理的 Go 程序员感到困惑。你只需要记住,当你对切片进行赋值、取切片、传参或者作为返回值等操作时,你是在复制切片头结构的三个字段:指向底层数组的指针、长度,以及容量。 + +### 总结 + +我们来用引出这一话题的切片作为栈的例子来总结下本文的内容: + +``` +package main + +import "fmt" + +func f(s []string, level int) { + if level > 5 { + return + } + s = append(s, fmt.Sprint(level)) + f(s, level+1) + fmt.Println("level:", level, "slice:", s) +} + +func main() { + f(nil, 0) +} +``` + +在 `main` 函数的最开始我们把一个 `nil` 切片传给了函数 `f` 作为 `level` 0 。在函数 `f` 里我们把当前的 `level` 添加到切片的后面,之后增加 `level` 的值并进行递归。一旦 `level` 大于 5,函数返回,打印出当前的 `level` 以及它们复制到的 `s` 的内容。 + +``` +level: 5 slice: [0 1 2 3 4 5] +level: 4 slice: [0 1 2 3 4] +level: 3 slice: [0 1 2 3] +level: 2 slice: [0 1 2] +level: 1 slice: [0 1] +level: 0 slice: [0] +``` + +你可以注意到在每一个 `level` 内 `s` 的值没有被别的 `f` 的调用影响,尽管当计算更高的 `level` 时作为 `append` 的副产品,调用栈内的四个 `f` 函数创建了四个底层数组[^6] ,但是没有影响到当前各自的切片。 + +### 扩展阅读 + +如果你想要了解更多 Go 语言内切片运行的原理,我建议看看 Go 博客里的这些文章: + +* [Go Slices: usage and internals][5] (blog.golang.org) +* [Arrays, slices (and strings): The mechanics of 'append'][6] (blog.golang.org) + +[^1]: 这不是数组才有的特性,在 Go 语言里中 _一切_ 赋值都是复制过去的。 +[^2]: 你也可以在对数组使用 `len` 函数,但是其结果本来就人尽皆知。 +[^3]: 有时也叫做后台数组backing array,以及更不严谨的说法是后台切片。 +[^4]: Go 语言里我们倾向于说值类型以及指针类型,因为 C++ 的引用reference类型这个词产生误会。但在这里我认为调用数组作为引用类型是没有问题的。 +[^5]: 如果你的结构体有[定义在其上的方法或者用于满足某个接口][7],那么你传入结构体指针的比率可以飙升到接近 100%。 +[^6]: 证明留做习题。 + +### 相关文章: + +1. [If a map isn't a reference variable, what is it?][1] +2. [What is the zero value, and why is it useful?][2] +3. [The empty struct][3] +4. [Should methods be declared on T or *T][4] + +--- + +via: https://dave.cheney.net/2018/07/12/slices-from-the-ground-up + +作者:[Dave Cheney][a] +译者:[name1e5s](https://github.com/name1e5s) +校对:[pityonline](https://github.com/pityonline) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://dave.cheney.net/ +[1]: https://dave.cheney.net/2017/04/30/if-a-map-isnt-a-reference-variable-what-is-it +[2]: https://dave.cheney.net/2013/01/19/what-is-the-zero-value-and-why-is-it-useful +[3]: https://dave.cheney.net/2014/03/25/the-empty-struct +[4]: https://dave.cheney.net/2016/03/19/should-methods-be-declared-on-t-or-t +[5]: https://blog.golang.org/go-slices-usage-and-internals +[6]: https://blog.golang.org/slices +[7]: https://golang.org/pkg/reflect/#SliceHeader diff --git a/published/201808/20180712 netdev day 2 moving away from as fast as possible in networking code.md b/published/201808/20180712 netdev day 2 moving away from as fast as possible in networking code.md new file mode 100644 index 0000000000..24fd68fef4 --- /dev/null +++ b/published/201808/20180712 netdev day 2 moving away from as fast as possible in networking code.md @@ -0,0 +1,115 @@ +netdev 第二天:从网络代码中移除“尽可能快”这个目标 +======= + +嗨!今天是 netdev 会议的第 2 天,我只参加了早上的会议,但它_非常有趣_。今早会议的主角是 [Van Jacobson][1] 给出的一场名为 “从尽可能快中变化:教网卡以时间”的演讲,它的主题是关于互联网中拥塞控制的未来!!! + +下面我将尝试着对我从这次演讲中学到的东西做总结,我几乎肯定下面的内容有些错误,但不管怎样,让我们开始吧! + +这次演讲是关于互联网是如何从 1988 开始改变的,为什么现在我们需要新的算法,以及我们可以怎样改变 Linux 的网络栈来更容易地实现这些算法。 + +### 什么是拥塞控制? + +在网络上的任何成员总是无时无刻地发送信息包,而在互联网上的连接之间有着极其不同的速度(某些相比其他极其缓慢),而有时候它们将被塞满!当互联网的一个设备以超过它能处理的速率接收信息包时,它将丢弃某些信息包。 + +你所能想象的最天真的发送信息包方式是: + +1. 将你必须发送的信息包一次性发送完。 +2. 假如你发现其中有的信息包被丢弃了,就马上重新发送这些包。 + +结果表明假如你按照上面的思路来实现 TCP,互联网将会崩溃并停止运转。我们知道它会崩溃是因为在 1986 年确实发生了崩溃的现象。为了解决这个问题,专家发明了拥塞控制算法 —— 描述如何避免互联网的崩溃的原始论文是 Van Jacobson 于 1988 年发表的 [拥塞避免与控制][2](30 年前!)。 + +### 从 1988 年后互联网发生了什么改变? + +在演讲中,Van Jacobson 说互联网的这些已经发生了改变:在以前的互联网上,交换机可能总是拥有比服务器更快的网卡,所以这些位于互联网中间层的服务器也可能比客户端更快,并且并不能对客户端发送信息包的速率有多大影响。 + +很显然今天已经不是这样的了!众所周知,今天的计算机相比于 5 年前的计算机在速度上并没有多大的提升(我们遇到了某些有关光速的问题)。所以我想路由器上的大型交换机并不会在速度上大幅领先于数据中心里服务器上的网卡。 + +这听起来有些糟糕,因为这意味着客户端更容易在中间层的连接中达到饱和,而这将导致互联网变慢(而且 [缓冲膨胀][3] 将带来更高的延迟)。 + +所以为了提高互联网的性能且不让每个路由上的任务队列都达到饱和,客户端需要表现得更好并且在发送信息包的时候慢一点。 + +### 以更慢的速率发送更多的信息包以达到更好的性能 + +下面的结论真的让我非常意外 —— 以更慢的速率发送信息包实际上可能会带来更好的性能(即便你是在整个传输过程中,这样做的唯一的人),下面是原因: + +假设你打算发送 10MB 的数据,在你和你需要连接的客户端之间有一个中间层,并且它的传输速率_非常低_,例如 1MB/s。假设你可以辨别这个慢连接(或者更多的后续中间层)的速度,那么你有 2 个选择: + +1. 一次性将这 10MB 的数据发送完,然后看看会发生什么。 +2. 减慢速率使得你能够以 1MB/s 的速率传给它。 + +现在,无论你选择何种方式,你可能都会发生丢包的现象。所以这样看起来,你可能需要选择一次性发送所有的信息包这种方式,对吧?不!!实际上在你的数据流的中间环节丢包要比在你的数据流的最后丢包要好得多。假如在中间环节有些包被丢弃了,你需要送往的那个客户端可以察觉到这个事情,然后再告诉你,这样你就可以再次发送那些被丢弃的包,这样便没有多大的损失。但假如信息包在最末端被丢弃,那么客户端将完全没有办法知道你一次性发送了所有的信息包!所以基本上在某个时刻被丢弃的包没有让你收到 ACK 信号时,你需要启用超时机制,并且还得重新发送它们。而超时往往意味着需要花费很长时间! + +所以为什么以更慢的速率发送数据会更好呢?假如你发送数据的速率快于连接中的瓶颈,这时所有的信息包将会在某个地方堆积成一个队列,这个队列将会被塞满,然后在你的数据流的最末端的信息包将会被丢弃。并且像我们刚才解释的那样,处于数据流最后面的信息包很有可能丢弃!所以相比于最初以合适的速率发送信息包,一次性发送它们将会触发超时机制,发送 10MB 的数据将会花费更长的时间。 + +我认为这非常酷,因为这个过程并不需要与互联网中的其他人合作 —— 即便其他的所有人都已非常快的速率传送他们的信息包,对你来说以合适的速率(中间层的瓶颈速率)传送你自己的信息包_仍然_更有优势。 + +### 如何辨别发送数据的合适速率:BBR! + +在上面我说过:“假设你可以辨别出位于你的终端和服务器之间慢连接的速率……”,那么如何做到呢?来自 Google(Jacobson 工作的地方)的某些专家已经提出了一个算法来估计瓶颈的速率!它叫做 BBR,由于本次的分享已经很长了,所以这里不做具体介绍,但你可以参考 [BBR:基于拥塞的拥塞控制][4] 和 [来自晨读论文的总结][5] 这两处链接。 + +(另外,[https://blog.acolyer.org][6] 的每日“晨读论文”总结基本上是我学习和理解计算机科学论文的唯一方式,它有可能是整个互联网上最好的博客之一!) + +### 网络代码被设计为运行得“尽可能快“ + +所以,假设我们相信我们想以一个更慢的速率(例如以我们连接中的瓶颈速率)来传输数据。这很好,但网络软件并不是被设计为以一个可控速率来传输数据的!下面是我所理解的大多数网络软件怎么做的: + +1. 现在有一个队列的信息包来临; +2. 然后软件读取队列并尽可能快地发送信息包; +3. 就这样,没有了。 + +这个过程非常呆板 —— 假设我以一个非常快的速率发送信息包,而另一端的连接却非常慢。假如我所拥有的就是一个放置所有信息包的队列,当我实际要发送数据时,我并没有办法来控制这个发送过程,所以我便不能减慢这个队列传输的速率。 + +### 一个更好的方式:给每个信息包一个“最早的出发时间” + +BBR 协议将会修改 Linux 内核中 skb 的数据结构(这个数据结构被用来表达网络信息包),使得它有一个时间戳,这个时间戳代表着这个信息包应该被发送出去的最早时间。 + +对于 Linux 网络栈我不知道更多的详情了,但对于我来说,这个协议最有趣的地方是这个改动并不是一个非常大的改动!它只是添加了一个额外的时间戳而已。 + +### 用时间轮盘替换队列!!! + +一旦我们将时间戳打到这些信息包上,我们怎样在合适的时间将它们发送出去呢?使用_时间轮盘_! + +在前不久的“我们喜爱的论文”活动中(这是关于这次聚会描述的[某些好的链接][7]),有一个演讲谈论了关于时间轮盘的话题。时间轮盘是一类用来指导 Linux 的进程调度器决定何时运行进程的算法。 + +Van Jacobson 说道:时间轮盘实际上比队列调度工作得更好 —— 它们都提供常数时间的操作,但因为某些缓存机制,时间轮盘的常数要更小一些。我真的没有太明白这里他说的关于性能的解释。 + +他说道:关于时间轮盘的一个关键点是你可以很轻松地用时间轮盘实现一个队列(但反之不能!)—— 假如每次你增加一个新的信息包,在最开始你说我想让它_现在_就被发送走,很显然这样你就可以得到一个队列了。而这个时间轮盘方法是向后兼容的,它使得你可以更容易地实现某些更加复杂的对流量非常敏感的算法,例如让你针对不同的信息包以不同的速率去发送它们。 + +### 或许我们可以通过改善 Linux 来修复互联网! + +对于任何影响到整个互联网规模的问题,最为棘手的问题是当你要做出改善时,例如改变互联网协议的实现,你需要面对各种不同的设备。你要面对 Linux 的机器、BSD 的机器、Windows 的机器、各种各样的手机、瞻博或者思科的路由器以及数量繁多的其他设备! + +但是在网络环境中 Linux 处于某种有趣的位置上! + +* Android 手机运行着 Linux +* 大多数的消费级 WiFi 路由器运行着 Linux +* 无数的服务器运行着 Linux + +所以在任何给定的网络连接中,实际上很有可能在两端都有一台 Linux 机器(例如一个 Linux 服务器、或者一个 Linux 路由器、一台 Android 设备)。 + +所以重点是假如你想大幅改善互联网上的拥塞状况,只需要改变 Linux 网络栈就会大所不同(或许 iOS 网络栈也是类似的)。这也就是为什么在本次的 Linux 网络会议上有这样的一个演讲! + +### 互联网仍在改变!酷! + +通常我以为 TCP/IP 仍然是上世纪 80 年代的东西,所以当从这些专家口中听说这些我们正在设计的网路协议仍然有许多严重的问题时,真的是非常有趣,并且听说现在有不同的方式来设计它们。 + +当然也确实是这样 —— 网络硬件以及和速度相关的任何设备,以及人们使用网络来干的各种事情(例如观看 Netflix 的节目)等等,一直都在随着时间发生着改变,所以正因为这样,我们需要为 2018 年的互联网而不是为 1988 年的互联网设计我们不同的算法。 + +-------------------------------------------------------------------------------- + +via: https://jvns.ca/blog/2018/07/12/netdev-day-2--moving-away-from--as-fast-as-possible/ + +作者:[Julia Evans][a] +译者:[FSSlc](https://github.com/FSSlc) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://jvns.ca/about +[1]:https://en.wikipedia.org/wiki/Van_Jacobson +[2]:https://cs162.eecs.berkeley.edu/static/readings/jacobson-congestion.pdf +[3]:https://apenwarr.ca/log/?m=201101#10 +[4]:https://queue.acm.org/detail.cfm?id=3022184 +[5]:https://blog.acolyer.org/2017/03/31/bbr-congestion-based-congestion-control/ +[6]:https://blog.acolyer.org/ +[7]:https://www.meetup.com/Papers-We-Love-Montreal/events/235100825/ diff --git a/published/201808/20180716 3 cool productivity apps for Fedora 28.md b/published/201808/20180716 3 cool productivity apps for Fedora 28.md new file mode 100644 index 0000000000..c39eac0b53 --- /dev/null +++ b/published/201808/20180716 3 cool productivity apps for Fedora 28.md @@ -0,0 +1,70 @@ +适用于 Fedora 28 的 3 款酷炫生产力应用 +====== + +![](https://fedoramagazine.org/wp-content/uploads/2018/07/3-productivity-apps-2018-816x345.jpg) + +生产力应用在移动设备上特别受欢迎。但是当你坐下来做工作时,你经常在笔记本电脑或台式电脑上工作。假设你使用 Fedora 系统。你能找到帮助你完成工作的程序吗?当然!请继续阅读了解这些帮助你专注目标的程序。 + +所有这些程序都可以在 Fedora 系统上免费使用。当然,它们也维护了你的自由。 (许多还允许你使用你可能已经拥有帐户的现有服务。) + +### FocusWriter + +FocusWriter 只是一个全屏文字处理器。该程序可以提高你的工作效率,因为它覆盖了屏幕其他地方。当你使用 FocusWriter 时,除了你和文本,别无它物。有了这个程序,你可以专注于你的想法,减少分心。 + +[![Screenshot of FocusWriter][1]][2] + +FocusWriter 允许你调整字体、颜色和主题以最适合你的喜好。它还会记住你上一个文档和位置。此功能可让你快速重新专注于书写。 + +要安装 FocusWriter,请使用 Fedora Workstation 中的软件中心。或者在终端中[使用 sudo ][3]运行此命令: + +``` +sudo dnf install focuswriter +``` + +### GNOME ToDo + +你可以猜到这个独特的程序是为 GNOME 桌面环境设计的。因此,它非常适合你的 Fedora Workstation。ToDo 有一个简单的目的:它可以让你列出你需要完成的事情。 + +![](https://fedoramagazine.org/wp-content/uploads/2018/07/Screenshot-from-2018-07-15-18-08-59.png) + +使用 ToDo,你可以为所有任务确定优先级并安排截止日期。你还可以根据需要构建任意数量的任务列表。ToDo 有大量提供了有用功能的扩展,以提高你的工作效率。这些包括 GNOME Shell 通知,以及带有 todo.txt 的列表管理。如果你有 Todoist 或者 Google 帐户,ToDo 甚至可以与它们交互。它可以同步任务,因此你可以跨设备共享。 + +要安装它,在软件中心搜索 ToDo,或在命令行运行: + +``` +sudo dnf install gnome-todo +``` + +### Zanshin + +如果你是使用 KDE 的生产力粉丝,你可能会喜欢 [Zanshin][4]。该行事历可帮助你规划跨多个项目的操作。它有完整的功能界面,可让你浏览各种任务,以了解下一步要做的最重要的事情。 + +[![Screenshot of Zanshin on Fedora 28][5]][6] + +Zanshin 非常适合键盘操作,因此你可在钻研时提高效率。它还集成了众多 KDE 程序以及 Plasma 桌面。你可以将其与 KMail、KOrganizer 和 KRunner 一起使用。 + +要安装它,请运行以下命令: + +``` +sudo dnf install zanshin +``` + + +-------------------------------------------------------------------------------- + +via: https://fedoramagazine.org/3-cool-productivity-apps/ + +作者:[Paul W. Frields][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[geekpi](https://github.com/geekpi) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://fedoramagazine.org/author/pfrields/ +[1]:https://fedoramagazine.org/wp-content/uploads/2018/07/Screenshot-from-2018-07-15-18-10-18-1024x768.png +[2]:https://fedoramagazine.org/wp-content/uploads/2018/07/Screenshot-from-2018-07-15-18-10-18.png +[3]:https://fedoramagazine.org/howto-use-sudo/ +[4]:https://zanshin.kde.org/ +[5]:https://fedoramagazine.org/wp-content/uploads/2018/07/Screenshot_20180715_192216-1024x653.png +[6]:https://fedoramagazine.org/wp-content/uploads/2018/07/Screenshot_20180715_192216.png diff --git a/published/201808/20180719 Incomplete Path Expansion (Completion) For Bash.md b/published/201808/20180719 Incomplete Path Expansion (Completion) For Bash.md new file mode 100644 index 0000000000..4a47c998fb --- /dev/null +++ b/published/201808/20180719 Incomplete Path Expansion (Completion) For Bash.md @@ -0,0 +1,78 @@ +针对 Bash 的不完整路径展开(补全)功能 +====== + + +![](https://4.bp.blogspot.com/-k2pRIKTzcBU/W1BpFtzzWuI/AAAAAAAABOE/pqX4XcOX8T4NWkKOmzD0T0OioqxzCmhLgCLcBGAs/s1600/Gnu-bash-logo.png) + +[bash-complete-partial-path][1] 通过添加不完整的路径展开(类似于 Zsh)来增强 Bash(它在 Linux 上,macOS 使用 gnu-sed,Windows 使用 MSYS)中的路径补全。如果你想在 Bash 中使用这个省时特性,而不必切换到 Zsh,它将非常有用。 + +这是它如何工作的。当按下 `Tab` 键时,bash-complete-partial-path 假定每个部分都不完整并尝试展开它。假设你要进入 `/usr/share/applications` 。你可以输入 `cd /u/s/app`,按下 `Tab`,bash-complete-partial-path 应该把它展开成 `cd /usr/share/applications` 。如果存在冲突,那么按 `Tab` 仅补全没有冲突的路径。例如,Ubuntu 用户在 `/usr/share` 中应该有很多以 “app” 开头的文件夹,在这种情况下,输入 `cd /u/s/app` 只会展开 `/usr/share/` 部分。 + +另一个更深层不完整文件路径展开的例子。在Ubuntu系统上输入 `cd /u/s/f/t/u`,按下 `Tab`,它应该自动展开为 `cd /usr/share/fonts/truetype/ubuntu`。 + +功能包括: + +* 转义特殊字符 +* 如果用户路径开头使用引号,则不转义字符转义,而是在展开路径后使用匹配字符结束引号 +* 正确展开 `~` 表达式 +* 如果正在使用 bash-completion 包,则此代码将安全地覆盖其 `_filedir` 函数。无需额外配置,只需确保在主 bash-completion 后引入此项目。 + +查看[项目页面][2]以获取更多信息和演示截图。 + +### 安装 bash-complete-partial-path + +bash-complete-partial-path 安装说明指定直接下载 bash_completion 脚本。我更喜欢从 Git 仓库获取,这样我可以用一个简单的 `git pull` 来更新它,因此下面的说明将使用这种安装 bash-complete-partial-path。如果你喜欢,可以使用[官方][3]说明。 + +1、 安装 Git(需要克隆 bash-complete-partial-path 的 Git 仓库)。 + +在 Debian、Ubuntu、Linux Mint 等中,使用此命令安装 Git: + +``` +sudo apt install git +``` + +2、 在 `~/.config/` 中克隆 bash-complete-partial-path 的 Git 仓库: + +``` +cd ~/.config && git clone https://github.com/sio/bash-complete-partial-path +``` + +3、 在 `~/.bashrc` 文件中 source `~/.config/bash-complete-partial-path/bash_completion`, + +用文本编辑器打开 ~/.bashrc。例如你可以使用 Gedit: + +``` +gedit ~/.bashrc +``` + +在 `~/.bashrc` 的末尾添加以下内容(在一行中): + +``` +[ -s "$HOME/.config/bash-complete-partial-path/bash_completion" ] && source "$HOME/.config/bash-complete-partial-path/bash_completion" +``` + +我提到在文件的末尾添加它,因为这需要包含在你的 `~/.bashrc` 文件的主 bash-completion 下面(之后)。因此,请确保不要将其添加到原始 bash-completion 之上,因为它会导致问题。 + +4、 引入 `~/.bashrc`: + +``` +source ~/.bashrc +``` + +这样就好了,现在应该安装完 bash-complete-partial-path 并可以使用了。 + +-------------------------------------------------------------------------------- + +via: https://www.linuxuprising.com/2018/07/incomplete-path-expansion-completion.html + +作者:[Logix][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[geekpi](https://github.com/geekpi) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://plus.google.com/118280394805678839070 +[1]:https://github.com/sio/bash-complete-partial-path +[2]:https://github.com/sio/bash-complete-partial-path +[3]:https://github.com/sio/bash-complete-partial-path#installation-and-updating diff --git a/published/201808/20180720 3 Methods to List All The Users in Linux System.md b/published/201808/20180720 3 Methods to List All The Users in Linux System.md new file mode 100644 index 0000000000..f2cd524935 --- /dev/null +++ b/published/201808/20180720 3 Methods to List All The Users in Linux System.md @@ -0,0 +1,192 @@ +列出 Linux 系统上所有用户的 3 种方法 +======= + +> 通过使用 `/etc/passwd` 文件,`getent` 命令,`compgen` 命令这三种方法查看系统中用户的信息 + +大家都知道,Linux 系统中用户信息存放在 `/etc/passwd` 文件中。 + +这是一个包含每个用户基本信息的文本文件。当我们在系统中创建一个用户,新用户的详细信息就会被添加到这个文件中。 + +`/etc/passwd` 文件将每个用户的基本信息记录为文件中的一行,一行中包含 7 个字段。 + +`/etc/passwd` 文件的一行代表一个单独的用户。该文件将用户的信息分为 3 个部分。 + + * 第 1 部分:`root` 用户信息 + * 第 2 部分:系统定义的账号信息 + * 第 3 部分:真实用户的账户信息 + +第一部分是 `root` 账户,这代表管理员账户,对系统的每个方面都有完全的权力。 + +第二部分是系统定义的群组和账户,这些群组和账号是正确安装和更新系统软件所必需的。 + +第三部分在最后,代表一个使用系统的真实用户。 + +在创建新用户时,将修改以下 4 个文件。 + + * `/etc/passwd`: 用户账户的详细信息在此文件中更新。 + * `/etc/shadow`: 用户账户密码在此文件中更新。 + * `/etc/group`: 新用户群组的详细信息在此文件中更新。 + * `/etc/gshadow`: 新用户群组密码在此文件中更新。 + +** 建议阅读 : ** + +- [ 如何在 Linux 上查看创建用户的日期 ][1] +- [ 如何在 Linux 上查看 A 用户所属的群组 ][2] +- [ 如何强制用户在下一次登录 Linux 系统时修改密码 ][3] + +### 方法 1 :使用 `/etc/passwd` 文件 + +使用任何一个像 `cat`、`more`、`less` 等文件操作命令来打印 Linux 系统上创建的用户列表。 + +`/etc/passwd` 是一个文本文件,其中包含了登录 Linux 系统所必需的每个用户的信息。它保存用户的有用信息,如用户名、密码、用户 ID、群组 ID、用户 ID 信息、用户的家目录和 Shell 。 + +`/etc/passwd` 文件将每个用户的详细信息写为一行,其中包含七个字段,每个字段之间用冒号 `:` 分隔: + +``` +# cat /etc/passwd +root:x:0:0:root:/root:/bin/bash +bin:x:1:1:bin:/bin:/sbin/nologin +daemon:x:2:2:daemon:/sbin:/sbin/nologin +adm:x:3:4:adm:/var/adm:/sbin/nologin +lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin +sync:x:5:0:sync:/sbin:/bin/sync +shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown +halt:x:7:0:halt:/sbin:/sbin/halt +mail:x:8:12:mail:/var/spool/mail:/sbin/nologin +ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin +postfix:x:89:89::/var/spool/postfix:/sbin/nologin +sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin +tcpdump:x:72:72::/:/sbin/nologin +2gadmin:x:500:10::/home/viadmin:/bin/bash +apache:x:48:48:Apache:/var/www:/sbin/nologin +zabbix:x:498:499:Zabbix Monitoring System:/var/lib/zabbix:/sbin/nologin +mysql:x:497:502::/home/mysql:/bin/bash +zend:x:502:503::/u01/zend/zend/gui/lighttpd:/sbin/nologin +rpc:x:32:32:Rpcbind Daemon:/var/cache/rpcbind:/sbin/nologin +2daygeek:x:503:504::/home/2daygeek:/bin/bash +named:x:25:25:Named:/var/named:/sbin/nologin +mageshm:x:506:507:2g Admin - Magesh M:/home/mageshm:/bin/bash + +``` +7 个字段的详细信息如下。 + +* **用户名** (`magesh`): 已创建用户的用户名,字符长度 1 个到 12 个字符。 +* **密码**(`x`):代表加密密码保存在 `/etc/shadow 文件中。 +* **用户 ID(`506`):代表用户的 ID 号,每个用户都要有一个唯一的 ID 。UID 号为 0 的是为 `root` 用户保留的,UID 号 1 到 99 是为系统用户保留的,UID 号 100-999 是为系统账户和群组保留的。 +* **群组 ID (`507`):代表群组的 ID 号,每个群组都要有一个唯一的 GID ,保存在 `/etc/group` 文件中。 +* **用户信息(`2g Admin - Magesh M`):代表描述字段,可以用来描述用户的信息(LCTT 译注:此处原文疑有误)。 +* **家目录(`/home/mageshm`):代表用户的家目录。 +* **Shell(`/bin/bash`):代表用户使用的 shell 类型。 + +你可以使用 `awk` 或 `cut` 命令仅打印出 Linux 系统中所有用户的用户名列表。显示的结果是相同的。 + +``` +# awk -F':' '{ print $1}' /etc/passwd +or +# cut -d: -f1 /etc/passwd +root +bin +daemon +adm +lp +sync +shutdown +halt +mail +ftp +postfix +sshd +tcpdump +2gadmin +apache +zabbix +mysql +zend +rpc +2daygeek +named +mageshm +``` +### 方法 2 :使用 `getent` 命令 + +`getent` 命令显示 Name Service Switch 库支持的数据库中的条目。这些库的配置文件为 `/etc/nsswitch.conf`。 + +`getent` 命令显示类似于 `/etc/passwd` 文件的用户详细信息,它将每个用户详细信息显示为包含七个字段的单行。 + +``` +# getent passwd +root:x:0:0:root:/root:/bin/bash +bin:x:1:1:bin:/bin:/sbin/nologin +daemon:x:2:2:daemon:/sbin:/sbin/nologin +adm:x:3:4:adm:/var/adm:/sbin/nologin +lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin +sync:x:5:0:sync:/sbin:/bin/sync +shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown +halt:x:7:0:halt:/sbin:/sbin/halt +mail:x:8:12:mail:/var/spool/mail:/sbin/nologin +ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin +postfix:x:89:89::/var/spool/postfix:/sbin/nologin +sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin +tcpdump:x:72:72::/:/sbin/nologin +2gadmin:x:500:10::/home/viadmin:/bin/bash +apache:x:48:48:Apache:/var/www:/sbin/nologin +zabbix:x:498:499:Zabbix Monitoring System:/var/lib/zabbix:/sbin/nologin +mysql:x:497:502::/home/mysql:/bin/bash +zend:x:502:503::/u01/zend/zend/gui/lighttpd:/sbin/nologin +rpc:x:32:32:Rpcbind Daemon:/var/cache/rpcbind:/sbin/nologin +2daygeek:x:503:504::/home/2daygeek:/bin/bash +named:x:25:25:Named:/var/named:/sbin/nologin +mageshm:x:506:507:2g Admin - Magesh M:/home/mageshm:/bin/bash +``` + +7 个字段的详细信息如上所述。(LCTT 译注:此处内容重复,删节) + +你同样可以使用 `awk` 或 `cut` 命令仅打印出 Linux 系统中所有用户的用户名列表。显示的结果是相同的。 + +### 方法 3 :使用 `compgen` 命令 + +`compgen` 是 `bash` 的内置命令,它将显示所有可用的命令,别名和函数。 + +``` +# compgen -u +root +bin +daemon +adm +lp +sync +shutdown +halt +mail +ftp +postfix +sshd +tcpdump +2gadmin +apache +zabbix +mysql +zend +rpc +2daygeek +named +mageshm +``` + +------------------------ + +via: https://www.2daygeek.com/3-methods-to-list-all-the-users-in-linux-system/ + +作者:[Magesh Maruthamuthu][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[SunWave](https://github.com/SunWave) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.2daygeek.com/author/magesh/ +[1]:https://www.2daygeek.com/how-to-check-user-created-date-on-linux/ +[2]:https://www.2daygeek.com/how-to-check-which-groups-a-user-belongs-to-on-linux/ +[3]:https://www.2daygeek.com/how-to-force-user-to-change-password-on-next-login-in-linux/ + + diff --git a/published/201808/20180720 4 cool new projects to try in COPR for July 2018.md b/published/201808/20180720 4 cool new projects to try in COPR for July 2018.md new file mode 100644 index 0000000000..e87b107b92 --- /dev/null +++ b/published/201808/20180720 4 cool new projects to try in COPR for July 2018.md @@ -0,0 +1,93 @@ +2018 年 7 月 COPR 中 4 个值得尝试很酷的新项目 +====== + +![](https://fedoramagazine.org/wp-content/uploads/2017/08/4-copr-945x400.jpg) + +COPR 是个人软件仓库[集合][1],它不在 Fedora 中。这是因为某些软件不符合轻松打包的标准。或者它可能不符合其他 Fedora 标准,尽管它是自由而开源的。COPR 可以在 Fedora 套件之外提供这些项目。COPR 中的软件不被 Fedora 基础设施不支持或没有被该项目所签名。但是,这是一种尝试新的或实验性的软件的一种巧妙的方式。 + +这是 COPR 中一组新的有趣项目。 + +### Hledger + +[Hledger][2] 是用于跟踪货币或其他商品的命令行程序。它使用简单的纯文本格式日志来存储数据和复式记帐。除了命令行界面,hledger 还提供终端界面和 Web 客户端,可以显示帐户余额图。 + +![][3] + +#### 安装说明 + +该仓库目前为 Fedora 27、28 和 Rawhide 提供了 hledger。要安装 hledger,请使用以下命令: + +``` +sudo dnf copr enable kefah/HLedger +sudo dnf install hledger +``` + +### Neofetch + +[Neofetch][4] 是一个命令行工具,可显示有关操作系统、软件和硬件的信息。其主要目的是以紧凑的方式显示数据来截图。你可以使用命令行标志和配置文件将 Neofetch 配置为完全按照你希望的方式显示。 + +![][5] + +#### 安装说明 + +仓库目前为 Fedora 28 提供 Neofetch。要安装 Neofetch,请使用以下命令: + +``` +sudo dnf copr enable sysek/neofetch +sudo dnf install neofetch + +``` + +### Remarkable + +[Remarkable][6]是 Markdown 文本编辑器,它使用类似 GitHub 的 Markdown 风格。它提供了文档的预览,以及导出为 PDF 和 HTML 的选项。Markdown 有几种可用的样式,包括使用 CSS 创建自己的样式的选项。此外,Remarkable 支持用于编写方程的 LaTeX 语法和源代码的语法高亮。 + +![][7] + +#### 安装说明 + +该仓库目前为 Fedora 28 和 Rawhide 提供 Remarkable。要安装 Remarkable,请使用以下命令: + +``` +sudo dnf copr enable neteler/remarkable +sudo dnf install remarkable +``` + +### Aha + +[Aha][8](即 ANSI HTML Adapter)是一个命令行工具,可将终端转义成 HTML 代码。这允许你将 git diff 或 htop 的输出共享为静态 HTML 页面。 + +![][9] + +#### 安装说明 + +[仓库][10] 目前为 Fedora 26、27、28 和 Rawhide、EPEL 6 和 7 以及其他发行版提供 aha。要安装 aha,请使用以下命令: + +``` +sudo dnf copr enable scx/aha +sudo dnf install aha +``` + + +-------------------------------------------------------------------------------- + +via: https://fedoramagazine.org/4-try-copr-july-2018/ + +作者:[Dominik Turecek][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[geekpi](https://github.com/geekpi) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://fedoramagazine.org +[1]:https://copr.fedorainfracloud.org/ +[2]:http://hledger.org/ +[3]:https://fedoramagazine.org/wp-content/uploads/2018/07/hledger.png +[4]:https://github.com/dylanaraps/neofetch +[5]:https://fedoramagazine.org/wp-content/uploads/2018/07/neofetch.png +[6]:https://remarkableapp.github.io/linux.html +[7]:https://fedoramagazine.org/wp-content/uploads/2018/07/remarkable.png +[8]:https://github.com/theZiz/aha +[9]:https://fedoramagazine.org/wp-content/uploads/2018/07/aha.png +[10]:https://copr.fedorainfracloud.org/coprs/scx/aha/ diff --git a/published/201808/20180720 Convert video using Handbrake.md b/published/201808/20180720 Convert video using Handbrake.md new file mode 100644 index 0000000000..51b1618311 --- /dev/null +++ b/published/201808/20180720 Convert video using Handbrake.md @@ -0,0 +1,58 @@ +使用 Handbrake 转换视频 +====== + +> 这个开源工具可以很简单地将老视频转换为新格式。 + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/OpenVideo.png?itok=jec9ibU5) + +最近,当我的儿子让我数字化他的高中篮球比赛的一些旧 DVD 时,我马上就想到了 [Handbrake][1]。它是一个开源软件包,可轻松将视频转换为可在 MacOS、Windows、Linux、iOS、Android 和其他平台上播放的格式所需的所有工具。 + +Handbrake 是开源的,并在 [GPLv2 许可证][2]下分发。它很容易在 MacOS、Windows 和 Linux 包括 [Fedora][3] 和 [Ubuntu][4] 上安装。在 Linux 中,安装后就可以从命令行使用 `$ handbrake` 或从图形用户界面中选择它。(我的情况是 GNOME 3) + +![](https://opensource.com/sites/default/files/uploads/handbrake_1.png) + +Handbrake 的菜单系统易于使用。单击 “Open Source” 选择要转换的视频源。对于我儿子的篮球视频,它是我的 Linux 笔记本中的 DVD 驱动器。将 DVD 插入驱动器后,软件会识别磁盘的内容。 + +![](https://opensource.com/sites/default/files/uploads/handbrake_2.png) + +正如你在上面截图中的 “Source” 旁边看到的那样,Handbrake 将其识别为 720x480 的 DVD,宽高比为 4:3,以每秒 29.97 帧的速度录制,有一个音轨。该软件还能预览视频。 + +如果默认转换设置可以接受,只需按下 “Start Encoding” 按钮(一段时间后,根据处理器的速度),DVD 的内容将被转换并以默认格式 [M4V][5] 保存(可以改变)。 + +如果你不喜欢文件名,很容易改变它。 + +![](https://opensource.com/sites/default/files/uploads/handbrake_3.png) + +Handbrake 有各种格式、大小和配置的输出选项。例如,它可以生成针对 YouTube、Vimeo 和其他网站以及 iPod、iPad、Apple TV、Amazon Fire TV、Roku、PlayStation 等设备优化的视频。 + +![](https://opensource.com/sites/default/files/uploads/handbrake_4.png) + +你可以在 “Dimensions” 选项卡中更改视频输出大小。其他选项卡允许你应用过滤器、更改视频质量和编码、添加或修改音轨,包括字幕和修改章节。“Tags” 选项卡可让你识别输出视频文件中的作者、演员、导演、发布日期等。 + +![](https://opensource.com/sites/default/files/uploads/handbrake_5.png) + +如果使用 Handbrake 为特定平台输出,可以使用包含的预设。 + +![](https://opensource.com/sites/default/files/uploads/handbrake_6.png) + +你还可以使用菜单选项创建自己的格式,具体取决于你需要的功能。 + +Handbrake 是一款非常强大的软件,但它并不是唯一的开源视频转换工具。你有其他喜欢的吗?如果有,请分享评论。 + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/7/handbrake + +作者:[Don Watkins][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[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/don-watkins +[1]:https://handbrake.fr/ +[2]:https://github.com/HandBrake/HandBrake/blob/master/LICENSE +[3]:https://fedora.pkgs.org/28/rpmfusion-free-x86_64/HandBrake-1.1.0-1.fc28.x86_64.rpm.html +[4]:https://launchpad.net/~stebbins/+archive/ubuntu/handbrake-releases +[5]:https://en.wikipedia.org/wiki/M4V diff --git a/published/201808/20180723 4 open source media conversion tools for the Linux desktop.md b/published/201808/20180723 4 open source media conversion tools for the Linux desktop.md new file mode 100644 index 0000000000..1a265f14fe --- /dev/null +++ b/published/201808/20180723 4 open source media conversion tools for the Linux desktop.md @@ -0,0 +1,72 @@ +Linux 桌面中 4 个开源媒体转换工具 +====== +> 使用这些易用的工具来将音视频文件从一种格式转换为另一种格式。 + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/BUSINESS_newmedia.png?itok=imgehG2v) + +啊,有这么多的文件格式,特别是音频和视频格式,如果你不认识这个文件扩展名或者你的播放器无法播放那个格式,或者你想使用一种开放格式,那就需要花点心思了。 + +那么,Linux 用户可以做些什么呢?当然是去使用 Linux 桌面的众多开源媒体转换工具之一。我们来看看其中的四个。 + +### Gnac + +![](https://opensource.com/sites/default/files/uploads/gnac.png) + +[Gnac][1] 是我最喜欢的音频转换器之一,已经存在很多年了。它易于使用,功能强大,并且它做得很好 —— 任何一流的程序都应该如此。 + +有多简单?单击工具栏按钮添加一个或多个要转换的文件,选择要转换的格式,然后单击**Convert**。转换很快,而且很干净。 + +有多强大?Gnac 可以处理 [GStreamer][2] 多媒体框架支持的所有音频格式。开箱即用,你可以在 Ogg、FLAC、AAC、MP3、WAV 和 SPX 之间进行转换。你还可以更改每种格式的转换选项或添加新格式。 + +### SoundConverter + +![](https://opensource.com/sites/default/files/uploads/soundconverter.png) + +如果在简单的同时你还要一些额外的功能,那么请看一下 [SoundConverter][3]。正如其名称所述,SoundConverter 仅对音频文件起作用。与 Gnac 一样,它可以读取 GStreamer 支持的格式,它可以输出 Ogg Vorbis、MP3、FLAC、WAV、AAC 和 Opus 文件。 + +通过单击 **Add File** 或将其拖放到 SoundConverter 窗口中来加载单个文件或整个文件夹。单击 **Convert**,软件将完成转换。它也很快 —— 我已经在大约一分钟内转换了一个包含几十个文件的文件夹。 + +SoundConverter 有设置转换文件质量的选项。你可以更改文件的命名方式(例如,在标题中包含曲目编号或专辑名称),并为转换后的文件创建子文件夹。 + +### WinFF + +![](https://opensource.com/sites/default/files/uploads/winff.png) + +[WinFF][4] 本身并不是转换器。它是 FFmpeg 的图形化前端,[Tim Nugent 为此][5] 在 Opensource.com 写了篇文章。虽然 WinFF 没有 FFmpeg 的所有灵活性,但它使 FFmpeg 更易于使用,并且可以快速,轻松地完成工作。 + +虽然它不是这里最漂亮的程序,也不需要是。它远比可以使用要好。你可以从下拉列表中选择要转换的格式,并选择多个预设配置。最重要的是,你可以指定比特率和帧速率,要使用的音频通道数量,甚至裁剪视频的大小等选项。 + +转换,特别是视频,需要一些时间,但结果通常非常好。有时,转换会有点受损 —— 但往往不足以引起关注。而且,正如我之前所说,使用 WinFF 可以节省一些时间。 + +### Miro Video Converter + +![](https://opensource.com/sites/default/files/uploads/miro-main-window.png) + +并非所有视频文件都是同样创建的。有些是专有格式。有的在显示器或电视屏幕上看起来很棒但是没有针对移动设备进行优化。这就是 [Miro Video Converter][6] 可以用的地方。 + +Miro Video Converter 非常重视移动设备。它可以转换在 Android 手机、Apple 设备、PlayStation Portable 和 Kindle Fire 上播放的视频。它会将最常见的视频格式转换为 MP4、[WebM][7] 和 [Ogg Theora][8]。你可以[在 Miro 的网站][6]上找到支持的设备和格式的完整列表 + +要使用它,可以将文件拖放到窗口中,也可以选择要转换的文件。然后,单击“Format”菜单以选择转换的格式。你还可以单击 Apple、Android 或其他菜单以选择要转换文件的设备。Miro Video Converter 会为设备屏幕分辨率调整视频大小。 + +你有最喜欢的 Linux 媒体转换程序吗?请留下评论,随意分享。 + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/7/media-conversion-tools-linux + +作者:[Scott Nesbitt][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[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/scottnesbitt +[1]:http://gnac.sourceforge.net +[2]:http://www.gstreamer.net/ +[3]:http://soundconverter.org/ +[4]:https://www.biggmatt.com/winff/ +[5]:https://opensource.com/article/17/6/ffmpeg-convert-media-file-formats +[6]:http://www.mirovideoconverter.com/ +[7]:https://en.wikipedia.org/wiki/WebM +[8]:https://en.wikipedia.org/wiki/Ogg_theora diff --git a/published/201808/20180724 Textricator- Data extraction made simple.md b/published/201808/20180724 Textricator- Data extraction made simple.md new file mode 100644 index 0000000000..ad003defd1 --- /dev/null +++ b/published/201808/20180724 Textricator- Data extraction made simple.md @@ -0,0 +1,42 @@ +Textricator:让数据提取变得简单 +====== + +> 这个新的开源工具可以从 PDF 文档中提取复杂的数据,而无需编程技能。 + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/document_free_access_cut_security.png?itok=ocvCv8G2) + +你可能知道这种感觉:你请求得到数据并得到积极的响应,只打开电子邮件并发现一大堆附加的 PDF。数据——中断。 + +我们理解你的挫败感,并为此做了一些事情:让我们介绍下 [Textricator][1],这是我们的第一个开源产品。 + +我们是 “Measures for Justice”(MFJ),一个刑事司法研究和透明度组织。我们的使命是为整个司法系统从逮捕到定罪后提供数据透明度。我们通过制定一系列多达 32 项指标来实现这一目标,涵盖每个县的整个刑事司法系统。我们以多种方式获取数据 —— 当然,所有这些都是合法的 —— 虽然许多州和县机构都掌握数据,可以为我们提供 CSV 格式的高质量格式化数据,但这些数据通常捆绑在软件中,没有简单的方法可以提取。PDF 报告是他们能提供的最佳报告。 + +开发者 Joe Hale 和 Stephen Byrne 在过去两年中一直在开发 Textricator,它用来提取数万页数据供我们内部使用。Textricator 可以处理几乎任何基于文本的 PDF 格式 —— 不仅仅是表格,还包括复杂的报表,其中包含从 Crystal Reports 等工具生成的文本和细节部分。只需告诉 Textricator 你要收集的字段的属性,它就会整理文档,收集并写出你的记录。 + +不是软件工程师?Textricator 不需要编程技巧。相反,用户描述 PDF 的结构,Textricator 处理其余部分。大多数用户通过命令行运行它。但是,你可以使用基于浏览器的 GUI。 + +我们评估了其他很好的开源解决方案,如 [Tabula][2],但它们无法处理我们需要抓取的一些 PDF 的结构。技术总监 Andrew Branch 说:“Textricator 既灵活又强大,缩短了我们花费大量时间处理大型数据集的时间。” + +在 MFJ,我们致力于透明度和知识共享,其中包括向任何人提供我们的软件,特别是那些试图公开自由共享数据的人。Textricator 可以在 [GitHub][3] 上找到,并在 [GNU Affero 通用公共许可证第 3 版][4]下发布。 + +你可以在我们的免费[在线数据门户][5]上查看我们的工作成果,包括通过 Textricator 处理的数据。Textricator 是我们流程的重要组成部分,我们希望民间技术机构和政府组织都可以使用这个新工具解锁更多数据。 + +如果你使用 Textricator,请告诉我们它如何帮助你解决数据问题。想要改进吗?提交一个拉取请求。 + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/7/textricator + +作者:[Stephen Byrne][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[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/stephenbyrne-mfj +[1]:https://textricator.mfj.io/ +[2]:https://tabula.technology/ +[3]:https://github.com/measuresforjustice/textricator +[4]:https://www.gnu.org/licenses/agpl-3.0.en.html +[5]:https://www.measuresforjustice.org/portal/ diff --git a/published/201808/20180726 4 cool apps for your terminal.md b/published/201808/20180726 4 cool apps for your terminal.md new file mode 100644 index 0000000000..2920905836 --- /dev/null +++ b/published/201808/20180726 4 cool apps for your terminal.md @@ -0,0 +1,121 @@ +4 款酷炫的终端应用 +====== + +![](https://fedoramagazine.org/wp-content/uploads/2018/07/terminal4cool-816x345.jpg) + +许多 Linux 用户认为在终端中工作太复杂、无聊,并试图逃避它。但这里有个改善方法 —— 四款终端下很棒的开源程序。它们既有趣又易于使用,甚至可以在你需要在命令行中工作时照亮你的生活。 + +### No More Secrets + +这是一个简单的命令行工具,可以重现 1992 年电影 [Sneakers][1] 中所见的著名数据解密效果。该项目让你编译个 `nms` 命令,该命令与管道数据一起使用并以混乱字符的形式打印输出。开始后,你可以按任意键,并能在输出中看到很酷的好莱坞效果的现场“解密”。 + +![][2] + +#### 安装说明 + +一个全新安装的 Fedora Workstation 系统已经包含了从源代码构建 No More Secrets 所需的一切。只需在终端中输入以下命令: + +``` +git clone https://github.com/bartobri/no-more-secrets.git +cd ./no-more-secrets +make nms +make sneakers ## Optional +sudo make install +``` + +对于那些记得原来的电影的人来说,`sneakers` 命令是一个小小的彩蛋,但主要的英雄是 `nms`。使用管道将任何 Linux 命令重定向到 `nms`,如下所示: + +``` +systemctl list-units --type=target | nms +``` + +当文本停止闪烁,按任意键“解密”它。上面的 `systemctl` 命令只是一个例子 —— 你几乎可以用任何东西替换它! + +### lolcat + +这是一个用彩虹为终端输出着色的命令。没什么用,但是它看起来很棒! + +![][3] + +#### 安装说明 + +`lolcat` 是一个 Ruby 软件包,可从官方 Ruby Gems 托管中获得。所以,你首先需要 gem 客户端: + +``` +sudo dnf install -y rubygems +``` + +然后安装 `lolcat` 本身: + +``` +gem install lolcat +``` + +再说一次,使用 `lolcat` 命令管道任何其他命令,并在 Fedora 终端中享受彩虹(和独角兽!)。 + +### chafa + +![][4] + +`chafa` 是一个[命令行图像转换器和查看器][5]。它可以帮助你在不离开终端的情况下欣赏图像。语法非常简单: + +``` +chafa /path/to/your/image +``` + +你可以将几乎任何类型的图像投射到 `chafa`,包括 JPG、PNG、TIFF、BMP 或几乎任何 ImageMagick 支持的图像 - 这是 `chafa` 用于解析输入文件的引擎。最酷的部分是 `chafa` 还可以在你的终端内显示非常流畅的 GIF 动画! + +#### 安装说明 + +`chafa` 还没有为 Fedora 打包,但从源代码构建它很容易。首先,获取必要的构建依赖项: + +``` +sudo dnf install -y autoconf automake libtool gtk-doc glib2-devel ImageMagick-devel +``` + +接下来,克隆代码或从项目的 GitHub 页面下载快照,然后 cd 到 `chafa` 目录,这样就行了: + +``` +git clone https://github.com/hpjansson/chafa +./autogen.sh +make +sudo make install +``` + +大的图像在第一次运行时可能需要一段时间处理,但 `chafa` 会缓存你加载的所有内容。下一次运行几乎是瞬间完成的。 + +### Browsh + +Browsh 是完善的终端网页浏览器。它比 Lynx 更强大,当然更引人注目。 Browsh 以无头模式启动 Firefox Web 浏览器(因此你无法看到它)并在特殊 Web 扩展的帮助下将其与你的终端连接。因此,Browsh 能像 Firefox 一样呈现所有富媒体内容,只是有点像素化的风格。 + +![][6] + +#### 安装说明 + +该项目为各种 Linux 发行版提供了包,包括 Fedora。以这种方式安装: + +``` +sudo dnf install -y https://github.com/browsh-org/browsh/releases/download/v1.4.6/browsh_1.4.6_linux_amd64.rpm +``` + +之后,启动 `browsh` 命令并给它几秒钟加载。按 `Ctrl+L` 将焦点切换到地址栏并开始浏览 Web,就像以前一样使用!使用 `Ctrl+Q` 返回终端。 + + +-------------------------------------------------------------------------------- + +via: https://fedoramagazine.org/4-cool-apps-for-your-terminal/ + +作者:[atolstoy][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[geekpi](https://github.com/geekpi) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://fedoramagazine.org/author/atolstoy/ +[1]:https://www.imdb.com/title/tt0105435/ +[2]:https://fedoramagazine.org/wp-content/uploads/2018/07/nms.gif +[3]:https://fedoramagazine.org/wp-content/uploads/2018/07/lolcat.png +[4]:https://fedoramagazine.org/wp-content/uploads/2018/07/sir.gif +[5]:https://hpjansson.org/chafa/ +[6]:https://fedoramagazine.org/wp-content/uploads/2018/07/browsh.png diff --git a/published/201808/20180726 The evolution of package managers.md b/published/201808/20180726 The evolution of package managers.md new file mode 100644 index 0000000000..f50ecba7c4 --- /dev/null +++ b/published/201808/20180726 The evolution of package managers.md @@ -0,0 +1,630 @@ +包管理器的进化 +====== + +> 包管理器在 Linux 软件管理中扮演了重要角色。这里对一些主要的包管理器进行了对比。 + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/suitcase_container_bag.png?itok=q40lKCBY) + +今天,每个可计算设备都会使用某种软件来完成预定的任务。在软件开发的上古时期,为了找出软件中的“虫”和其它缺陷,软件会被严格的测试。在近十年间,软件被通过互联网来频繁分发,以试图通过持续不断的安装新版本的软件来解决软件的缺陷问题。在很多情况下,每个独立的应用软件都有其自带的更新器。而其它一些软件则让用户自己去搞明白如何获取和升级软件。 + +Linux 较早采用了维护一个中心化的软件仓库来发布软件更新这种做法,用户可以在这个软件仓库里查找并安装软件。在这篇文章里, 笔者将回顾在 Linux 上的如何进行软件安装的历史,以及现代操作系统如何保持更新以应对[软件安全漏洞(CVE)][1]不断的曝光。 + +### 那么在包管理器出现之前在 Linux 上是如何安装软件的呢? + +曾几何时,软件都是通过 FTP 或邮件列表(LCTT 译注:即通过邮件列表发布源代码的补丁包)来分发的(最终这些发布方式在互联网的迅猛发展下都演化成为一个个现今常见的软件发布网站)。(一般在一个 tar 文件中)只有一个非常小的文件包含了创建二进制的说明。你需要做的是先解压这个包,然后仔细阅读当中的 `README` 文件, 如果你的系统上恰好有 GCC(LCTT 译注:GNU C Compiler)或者其它厂商的 C 编译器的话,你得首先运行 `./configure` 脚本,并在脚本后添加相应的参数,如库函数的路径、创建可执行文件的路径等等。除此之外,这个配置过程也会检查你操作系统上的软件依赖是否满足安装要求。如果缺失了任何主要的依赖,该配置脚本会退出不再继续安装,直到你满足了该依赖。如果该配置脚本正常执行完毕,将会创建一个 `Makefile` 文件。 + +当有了一个 `Makefile` 文件时, 你就可以接下去执行 `make` 命令(该命令由你所使用的编译器提供)。`make` 命令也有很多参数,被称为 `make` 标识flag,这些标识能为你的系统优化最终生成出来的二进制可执行文件。在计算机世界的早期,这些优化是非常重要的,因为彼时的计算机硬件正在为了跟上软件迅速的发展而疲于奔命。今日今时,编译标识变得更加通用而不是为了优化哪些具体的硬件型号,这得益于现代硬件和现代软件相比已经变得成本低廉,唾手可得。 + +最后,在 `make` 完成之后, 你需要运行 `make install` (或 `sudo make install`)(LCTT 译注:依赖于你的用户权限) 来“真正”将这个软件安装到你的系统上。可以想象,为你系统上的每一个软件都执行上述的流程将是多么无聊费时,更不用说如果更新一个已经安装的软件将会多复杂,多么需要精力投入。(LCTT 译注:上述流程也称 CMMI 安装, 即Configure、Make、Make Install) + +### 那么软件包是什么? + +软件包package(LCTT 译注:下文简称“包”)这个概念是用来解决在软件安装、升级过程中的复杂性的。包将软件安装升级中需要的多个数据文件合并成一个单独的文件,这将便于传输和(通过压缩文件来)减小存储空间(LCTT 译注:减少存储空间这一点在现在已经不再重要),包中的二进制可执行文件已根据开发者所选择的编译标识预编译。包本身包括了所有需要的元数据,如软件的名字、软件的说明、版本号,以及要运行这个软件所需要的依赖包等等。 + +不同流派的 Linux 发行版都创造了它们自己的包格式,其中最常用的包格式有: + +* .deb:这种包格式由 Debian、Ubuntu、Linux Mint 以及其它的变种使用。这是最早被发明的包类型。 +* .rpm:这种包格式最初被称作红帽包管理器Red Hat Package Manager(LCTT 译注: 取自英文的首字母)。使用这种包的 Linux 发行版有 Red Hat、Fedora、SUSE 以及其它一些较小的发行版。 +* .tar.xz:这种包格式只是一个软件压缩包而已,这是 Arch Linux 所使用的格式。(LCTT 译注:这种格式无需特别的包管理器,解压即可) + +尽管上述的包格式自身并不能直接管理软件的依赖问题,但是它们的出现将 Linux 软件包管理向前推进了一大步。 + +### 软件仓库到底是什么? + +多年以前(当智能电话还没有像现在这样流行时),非 Linux 世界的用户是很难理解软件仓库的概念的。甚至今时今日,大多数完全工作在 Windows 下的用户还是习惯于打开浏览器,搜索要安装的软件(或升级包),下载然后安装。但是,智能电话传播了软件“商店”(LCTT 译注: 对应 Linux 里的软件仓库)这样一个概念。智能电话用户获取软件的方式和包管理器的工作方式已经非常相近了。些许不同的是,尽管大多数软件商店还在费力美化它的图形界面来吸引用户,大多数 Linux 用户还是愿意使用命令行来安装软件。总而言之,软件仓库是一个中心化的可安装软件列表,上面列举了在当前系统中预先配置好的软件仓库里所有可以安装的软件。下面我们举一些例子来说在各个不同的 Linux 发行版下如何在对应的软件仓库里搜寻某个特定的软件(输出有截断)。 + +在 Arch Linux 下使用 `aurman`: + +``` +user@arch ~ $  aurman -Ss kate + +extra/kate 18.04.2-2 (kde-applications kdebase) +    Advanced Text Editor +aur/kate-root 18.04.0-1 (11, 1.139399) +    Advanced Text Editor, patched to be able to run as root +aur/kate-git r15288.15d26a7-1 (1, 1e-06) +    An advanced editor component which is used in numerous KDE applications requiring a text editing component +``` + +在 CentOS 7 下使用 `yum`: + +``` +[user@centos ~]$ yum search kate + +kate-devel.x86_64 : Development files for kate +kate-libs.x86_64 : Runtime files for kate +kate-part.x86_64 : Kate kpart plugin +``` + + +在 Ubuntu 下使用 `apt`: + +``` +user@ubuntu ~ $ apt search kate +Sorting... Done +Full Text Search... Done + +kate/xenial 4:15.12.3-0ubuntu2 amd64 +  powerful text editor + +kate-data/xenial,xenial 4:4.14.3-0ubuntu4 all +  shared data files for Kate text editor + +kate-dbg/xenial 4:15.12.3-0ubuntu2 amd64 +  debugging symbols for Kate + +kate5-data/xenial,xenial 4:15.12.3-0ubuntu2 all +  shared data files for Kate text editor +``` + +### 最好用的包管理器有哪些? + +如上示例的输出,包管理器用来和相应的软件仓库交互,获取软件的相应信息。下面对它们做一个简短介绍。 + +#### 基于 PRM 包格式的包管理器 + +更新基于 RPM 的系统,特别是那些基于 Red Hat 技术的系统,有着非常有趣而又详实的历史。实际上,现在的 [YUM][2] 版本(用于 企业级发行版)和 [DNF][3](用于社区版)就融合了好几个开源项目来提供它们现在的功能。 + +Red Hat 最初使用的包管理器,被称为 [RPM][4](红帽包管理器Red Hat Package Manager),时至今日还在使用着。不过,它的主要作用是安装本地的 RPM 包,而不是去在软件仓库搜索软件。后来开发了一个叫 `up2date` 的包管理器,它被用来通知用户包的最新更新,还能让用户在远程仓库里搜索软件并便捷的安装软件的依赖。尽管这个包管理器尽职尽责,但一些社区成员还是感觉 `up2date` 有着明显的不足。 + +现在的 YUM 来自于好几个不同社区的努力。1999-2001 年一群在 Terra Soft Solution 的伙计们开发了黄狗更新器Yellowdog Updater(YUP),将其作为 [Yellow Dog Linux][5] 图形安装器的后端。杜克大学Duke University喜欢这个主意就决定去增强它的功能,它们开发了[黄狗更新器--修改版][16]Yellowdog Updater, Modified(YUM),这最终被用来帮助管理杜克大学的 Red Hat 系统。Yum 壮大的很快,到 2005 年,它已经被超过一半的 Linux 市场所采用。今日,几乎所有的使用 RPM 的的 Linux 都会使用 YUM 来进行包管理(当然也有一些例外)。 + +##### 使用 YUM + +为了能让 YUM 正常工作,比如从一个软件仓库里下载和安装包,仓库说明文件必须放在 `/etc/yum.repos.d/` 目录下且必须以 `.repo` 作为扩展名。如下是一个示例文件的内容: + +``` +[local_base] +name=Base CentOS  (local) +baseurl=http://7-repo.apps.home.local/yum-repo/7/ +enabled=1 +gpgcheck=0 +``` + +这是笔者本地仓库之一,这也是为什么 gpgcheck 值为 0 的原因。如果这个值为 1 的话,每个包都需要被密钥签名,相应的密钥(的公钥)也要导入到安装软件的系统上。因为这个软件仓库是笔者本人维护的且笔者信任这个仓库里的包,所以就不去对它们一一签名了。 + +当一个仓库文件准备好时,你就能开始从远程软件仓库开始安装文件了。最基本的命令是 `yum update`,这将会更新所有已安装的包。你也不需要用特殊的命令来更新仓库本身,所有这一切都已自动完成了。运行命令示例如下: + +``` +[user@centos ~]$ sudo yum update +Loaded plugins: fastestmirror, product-id, search-disabled-repos, subscription-manager +local_base                             | 3.6 kB  00:00:00     +local_epel                             | 2.9 kB  00:00:00     +local_rpm_forge                        | 1.9 kB  00:00:00     +local_updates                          | 3.4 kB  00:00:00     +spideroak-one-stable                   | 2.9 kB  00:00:00     +zfs                                    | 2.9 kB  00:00:00     +(1/6): local_base/group_gz             | 166 kB  00:00:00     +(2/6): local_updates/primary_db        | 2.7 MB  00:00:00     +(3/6): local_base/primary_db           | 5.9 MB  00:00:00     +(4/6): spideroak-one-stable/primary_db |  12 kB  00:00:00     +(5/6): local_epel/primary_db           | 6.3 MB  00:00:00     +(6/6): zfs/x86_64/primary_db           |  78 kB  00:00:00     +local_rpm_forge/primary_db             | 125 kB  00:00:00     +Determining fastest mirrors +Resolving Dependencies +--> Running transaction check +``` + +如果你确定想让 YUM 在执行任何命令时不要停下来等待用户输入,你可以命令里放 `-y` 标志,如 `yum update -y`。 + +安装一个新包很简单。首先,用 `yum search` 搜索包的名字。 + +``` +[user@centos ~]$ yum search kate + +artwiz-aleczapka-kates-fonts.noarch : Kates font in Artwiz family +ghc-highlighting-kate-devel.x86_64 : Haskell highlighting-kate library development files +kate-devel.i686 : Development files for kate +kate-devel.x86_64 : Development files for kate +kate-libs.i686 : Runtime files for kate +kate-libs.x86_64 : Runtime files for kate +kate-part.i686 : Kate kpart plugin +``` + +当你找到你要安装的包后,你可以用 `sudo yum install kate-devel -y` 来安装。如果你安装了你不需要的软件,可以用 `sudo yum remove kdate-devel -y` 来从系统上删除它,默认情况下,YUM 会删除软件包以及它的依赖。 + +有些时候你甚至都不清楚要安装的包的名称,你只知道某个实用程序的名字。(LCTT 译注:可以理解实用程序是安装包的子集)。例如,你想找实用程序 `updatedb`(它是用来创建/更新由 `locate` 命令所使用的数据库的),直接试图安装 `updatedb` 会返回下面的结果: + +``` +[user@centos ~]$ sudo yum install updatedb +Loaded plugins: fastestmirror, langpacks +Loading mirror speeds from cached hostfile +No package updatedb available. +Error: Nothing to do +``` + +你可以搜索实用程序来自哪个包: + +``` +[user@centos ~]$ yum whatprovides *updatedb +Loaded plugins: fastestmirror, langpacks +Loading mirror speeds from cached hostfile + +bacula-director-5.2.13-23.1.el7.x86_64 : Bacula Director files +Repo        : local_base +Matched from: +Filename    : /usr/share/doc/bacula-director-5.2.13/updatedb + +mlocate-0.26-8.el7.x86_64 : An utility for finding files by name +Repo        : local_base +Matched from: +Filename    : /usr/bin/updatedb +``` + +笔者在前面使用星号的原因是 `yum whatprovides` 使用路径去匹配文件。笔者不确定文件在哪里,所以使用星号去指代任意路径。 + +当然 YUM 还有很多其它的可选项。这里笔者希望你能够自己查看 YUM 的手册来找到其它额外的可选项。 + +[时髦的 Yum][7]Dandified Yum(DNF)是 YUM 的下一代接班人。从 Fedora 18 开始被作为包管理器引入系统,不过它并没有被企业版所采用,所以它只在 Fedora(以及变种)上占据了主导地位。DNF 的用法和 YUM 几乎一模一样,它主要是用来解决性能问题、晦涩无说明的API、缓慢/不可靠的依赖解析,以及偶尔的高内存占用。DNF 是作为 YUM 的直接替代品来开发的,因此这里笔者就不重复它的用法了,你只用简单的将 `yum` 替换为 `dnf` 就行了。 + +##### 使用 Zypper + +[Zypper][8] 是用来管理 RPM 包的另外一个包管理器。这个包管理器主要用于 [SUSE][9](和 [openSUSE][10]),在[MeeGo][11]、[Sailfish OS][12]、[Tizen][13] 上也有使用。它最初开发于 2006 年,已经经过了多次迭代。除了作为系统管理工具 [YaST][14] 的后端和有些用户认为它比 YUM 要快之外也没有什么好多说的。 + +Zypper 使用与 YUM 非常相像。它被用来搜索、更新、安装和删除包,简单的使用命令如下: + +``` +zypper search kate +zypper update +zypper install kate +zypper remove kate +``` + +主要的不同来自于使用 Zypper 的系统在添加软件仓库的做法上,Zypper 使用包管理器本身来添加软件仓库。最通用的方法是通过一个 URL,但是 Zypper 也支持从仓库文件里导入。 + +``` +suse:~ # zypper addrepo http://download.videolan.org/pub/vlc/SuSE/15.0 vlc +Adding repository 'vlc' [done] +Repository 'vlc' successfully added + +Enabled     : Yes +Autorefresh : No +GPG Check   : Yes +URI         : http://download.videolan.org/pub/vlc/SuSE/15.0 +Priority    : 99 +``` + +你也能用相似的手段来删除软件仓库: + +``` +suse:~ # zypper removerepo vlc +Removing repository 'vlc' ...................................[done] +Repository 'vlc' has been removed. +``` + +使用 `zypper repos` 命令来查看当前系统上的软件仓库的状态: + +``` +suse:~ # zypper repos +Repository priorities are without effect. All enabled repositories share the same priority. + +#  | Alias                     | Name                                    | Enabled | GPG Check | Refresh +---|---------------------------|-----------------------------------------|---------|-----------|-------- + 1 | repo-debug                | openSUSE-Leap-15.0-Debug                | No      | ----      | ----   + 2 | repo-debug-non-oss        | openSUSE-Leap-15.0-Debug-Non-Oss        | No      | ----      | ----   + 3 | repo-debug-update         | openSUSE-Leap-15.0-Update-Debug         | No      | ----      | ----   + 4 | repo-debug-update-non-oss | openSUSE-Leap-15.0-Update-Debug-Non-Oss | No      | ----      | ----   + 5 | repo-non-oss              | openSUSE-Leap-15.0-Non-Oss              | Yes     | ( p) Yes  | Yes     + 6 | repo-oss                  | openSUSE-Leap-15.0-Oss                  | Yes     | ( p) Yes  | Yes     +``` + +`zypper` 甚至还有和 YUM 相同的功能:搜索包含文件或二进制的包。和 YUM 有所不同的是,它在命令行里使用破折号(但是这个搜索方法现在被废除了……) + +``` +localhost:~ # zypper what-provides kate +Command 'what-provides' is replaced by 'search --provides --match-exact'. +See 'help search' for all available options. +Loading repository data... +Reading installed packages... + +S  | Name | Summary              | Type       +---|------|----------------------|------------ +i+ | Kate | Advanced Text Editor | application +i  | kate | Advanced Text Editor | package   +``` + +YUM、DNF 和 Zypper 三剑客拥有的功能比在这篇小文里讨论的要多得多,请查看官方文档来得到更深入的信息。 + +#### 基于 Debian 的包管理器 + +作为一个现今仍在被积极维护的最古老的 Linux 发行版之一,Debian 的包管理系统和基于 RPM 的系统的包管理系统非常类似。它使用扩展名为 “.deb” 的包,这种文件能被一个叫做 `dpkg` 的工具所管理。`dpgk` 同 `rpm` 非常相似,它被设计成用来管理在存在于本地(硬盘)的包。它不会去做包依赖关系解析(它会做依赖关系检查,不过仅此而已),而且在同远程软件仓库交互上也并无可靠的途径。为了提高用户体验并便于使用,Debian 项目开始了一个软件项目:Deity,最终这个代号被丢弃并改成了现在的 [高级打包工具][15]Advanced Package Tool(APT)。 + +在 1998 年,APT 测试版本发布(甚至早于 1999 年的 Debian 2.1 发布),许多用户认为 APT 是基于 Debian 系统标配功能之一。APT 使用了和 RPM 一样的风格来管理仓库,不过和 YUM 使用单独的 .repo 文件不同,APT 曾经使用 `/etc/apt/sources.list` 文件来管理软件仓库,后来的变成也可以使用 `/etc/apt/sources.d` 目录来管理。如同基于 RPM 的系统一样,你也有很多很多选项配置来完成同样的事情。你可以编辑和创建前述的文件,或者使用图形界面来完成上述工作(如 Ubuntu 的“Software & Updates”),为了给所有的 Linux 发行版统一的待遇,笔者将会只介绍命令行的选项。 +要想不直接编辑文件内容而直接增加软件仓库的话,可以用如下命令: + +``` +user@ubuntu:~$ sudo apt-add-repository "deb http://APT.spideroak.com/ubuntu-spideroak-hardy/ release restricted" +``` + +这个命令将会在 `/etc/apt/sources.list.d` 目录里创建一个 `spideroakone.list` 文件。显而易见,文件里的内容依赖于所添加的软件仓库,如果你想加一个个人软件包存档Personal Package Archive(PPA)的话,你可以用如下的办法: + +``` +user@ubuntu:~$ sudo apt-add-repository ppa:gnome-desktop +``` + +注意: Debian 原生并不支持本地 PPA 。 + +在添加了一个软件仓库后,需要通知基于 Debian 的系统有一个新的仓库可以用来搜索包,可以运行 `apt-get update` 来完成: + +``` +user@ubuntu:~$ sudo apt-get update +Get:1 http://security.ubuntu.com/ubuntu xenial-security InRelease [107 kB] +Hit:2 http://APT.spideroak.com/ubuntu-spideroak-hardy release InRelease +Hit:3 http://ca.archive.ubuntu.com/ubuntu xenial InRelease +Get:4 http://ca.archive.ubuntu.com/ubuntu xenial-updates InRelease [109 kB]               +Get:5 http://security.ubuntu.com/ubuntu xenial-security/main amd64 Packages [517 kB] +Get:6 http://security.ubuntu.com/ubuntu xenial-security/main i386 Packages [455 kB]       +Get:7 http://security.ubuntu.com/ubuntu xenial-security/main Translation-en [221 kB]     +... + +Fetched 6,399 kB in 3s (2,017 kB/s)                                           +Reading package lists... Done +``` + +现在新的软件仓库已经在你的系统里安装并更新好了,你可以用 `apt-cache` 来搜索你想要的包了。 + +``` +user@ubuntu:~$ apt-cache search kate +aterm-ml - Afterstep XVT - a VT102 emulator for the X window system +frescobaldi - Qt4 LilyPond sheet music editor +gitit - Wiki engine backed by a git or darcs filestore +jedit - Plugin-based editor for programmers +kate - powerful text editor +kate-data - shared data files for Kate text editor +kate-dbg - debugging symbols for Kate +katepart - embeddable text editor component +``` + +要安装 kate,简单的运行下面的命令: + +``` +user@ubuntu:~$ sudo apt-get install kate +``` + +要是删除一个包,使用 `apt-get remove`: + +``` +user@ubuntu:~$ sudo apt-get remove kate +``` + +要探索一个包的话,APT 并没有提供一个类似于 `yum whatprovides` 的功能,如果你想深入包内部去确定一个特定的文件的话,也有一些别的方法能帮你完成这个目标, + +如: 用 `dpkg` + +``` +user@ubuntu:~$ dpkg -S /bin/ls +coreutils: /bin/ls +``` + +或者: `apt-file` + +``` +user@ubuntu:~$ sudo apt-get install apt-file -y +user@ubuntu:~$ sudo apt-file update +user@ubuntu:~$ apt-file search kate +``` + +与 `yum whatprovides` 不同的是,`apt-file search` 的问题是因为自动添加了通配符搜索而输出过于详细(除非你知道确切的路径),最终在结果里包括了所有包含有 “kate” 的结果。 + +``` +kate: /usr/bin/kate +kate: /usr/lib/x86_64-linux-gnu/qt5/plugins/ktexteditor/katebacktracebrowserplugin.so +kate: /usr/lib/x86_64-linux-gnu/qt5/plugins/ktexteditor/katebuildplugin.so +kate: /usr/lib/x86_64-linux-gnu/qt5/plugins/ktexteditor/katecloseexceptplugin.so +kate: /usr/lib/x86_64-linux-gnu/qt5/plugins/ktexteditor/katectagsplugin.so +``` + +上面这些例子大部分都使用了 `apt-get`。请注意现今大多数的 Ubuntu 教程里都径直使用了 `apt`。 单独一个 `apt` 设计用来实现那些最常用的 APT 命令的。`apt` 命令看上去是用来整合那些被分散在 `apt-get`、`apt-cache` 以及其它一些命令的的功能的。它还加上了一些额外的改进,如色彩、进度条以及其它一些小功能。上述的常用命令都能被 `apt` 替代,但是并不是所有的基于 Debian 的系统都能使用 `apt` 接受安全包补丁的,你有可能要安装额外的包的实现上述功能。 + +#### 基于 Arch 的包管理器 + +[Arch Linux][16] 使用称为 [packman][17] 的包管理器。和 .deb 以及 .rpm 不同,它使用更为传统的 LZMA2 压缩包形式 .tar.xz 。这可以使 Arch Linux 包能够比其它形式的压缩包(如 gzip)有更小的尺寸。自从 2002 年首次发布以来, `pacman` 一直在稳定发布和改善。使用它最大的好处之一是它支持 [Arch Build System][18],这是一个从源代码级别构建包的构建系统。该构建系统借助一个叫 `PKGBUILD` 的文件,这个文件包含了如版本号、发布号、依赖等等的元数据,以及一个为编译遵守 Arch Linux 需求的包所需要的带有必要的编译选项的脚本。而编译的结果就是前文所提的被 `pacman` 所使用的 .tar.xz 的文件。 + +上述的这套系统技术上导致了 [Arch 用户仓库][19]Arch User Respository(AUR)的产生,这是一个社区驱动的软件仓库,仓库里包括有 `PKGBUILD` 文件以及支持补丁或脚本。这给 Arch Linux 带了无穷无尽的软件资源。最为明显的好处是如果一个用户(或开发者)希望他开发的软件能被广大公众所使用,他不必通过官方途径去在主流软件仓库获得许可。而不利之处则是它必须将依赖社区的流程,类似于 [Docker Hub][20]、 +Canonical 的 Snap Packages(LCTT 译注: Canonical 是 Ubuntu 的发行公司),或者其它类似的机制。有很多特定于 AUR 的包管理器能被用来从 AUR 里的 `PGKBUILD` 文件下载、编译、安装,下面我们来仔细看看怎么做。 + +##### 使用 pacman 和官方软件仓库 + +Arch 的主要包管理器:`pacman`,使用标识位而不是像 `yum` 或 `apt` 一样使用命令词。例如,要搜索一个包,你要用 `pacman -Ss` 。和 Linux 上别的命令一样,你可以找到 pacman 的手册页和在线帮助。`pacman` 大多数的命令都使用了同步(`-S`)这个标识位。例如: + +``` +user@arch ~ $ pacman -Ss kate + +extra/kate 18.04.2-2 (kde-applications kdebase) +    Advanced Text Editor +extra/libkate 0.4.1-6 [installed] +    A karaoke and text codec for embedding in ogg +extra/libtiger 0.3.4-5 [installed] +    A rendering library for Kate streams using Pango and Cairo +extra/ttf-cheapskate 2.0-12 +    TTFonts collection from dustimo.com +community/haskell-cheapskate 0.1.1-100 +    Experimental markdown processor. +``` + +Arch 也使用和别的包管理器类似的软件仓库。在上面的输出中,搜索结果前面有标明它是从哪个仓库里搜索到的(这里是 `extra/` 和 `community/`)。同 Red Hat 和 Debian 系统一样,Arch 依靠用户将软件仓库的信息加入到一个特定的文件里:`/etc/pacman.conf`。下面的例子非常接近一个仓库系统。笔者还打开了 `[multilib]` 仓库来支持 Steam: + +``` +[options] +Architecture = auto + +Color +CheckSpace + +SigLevel    = Required DatabaseOptional +LocalFileSigLevel = Optional + +[core] +Include = /etc/pacman.d/mirrorlist + +[extra] +Include = /etc/pacman.d/mirrorlist + +[community] +Include = /etc/pacman.d/mirrorlist + +[multilib] +Include = /etc/pacman.d/mirrorlist +``` + +你也可以在 `pacman.conf` 里指定具体的 URL。这个功能可以用来确保在某一时刻所有的包来自一个确定的地方,比如,如果一个安装包存在严重的功能缺陷并且很不幸它恰好还有几个包依赖,你能及时回滚到一个安全点,如果你已经在 `pacman.conf` 里加入了具体的 URL 的话,你就用用这个命令降级你的系统。 + +``` +[core] +Server=https://archive.archlinux.org/repos/2017/12/22/$repo/os/$arch +``` + +和 Debian 系统一样,Arch 并不会自动更新它的本地仓库。你可以用下面的命令来刷新包管理器的数据库: + +``` +user@arch ~ $ sudo pacman -Sy + +:: Synchronizing package databases... + core                                                                     130.2 KiB   851K/s 00:00 [##########################################################] 100% + extra                                                                   1645.3 KiB  2.69M/s 00:01 [##########################################################] 100% + community                                                                  4.5 MiB  2.27M/s 00:02 [##########################################################] 100% + multilib is up to date +``` + +你可以看到在上述的输出中,`pacman` 认为 multilib 包数据库是更新到最新状态的。如果你认为这个结果不正确的话,你可以强制运行刷新:`pacman -Syy`。如果你想升级你的整个系统的话(不包括从 AUR 安装的包),你可以运行 `pacman -Syu`: + +``` +user@arch ~ $ sudo pacman -Syu + +:: Synchronizing package databases... + core is up to date + extra is up to date + community is up to date + multilib is up to date +:: Starting full system upgrade... +resolving dependencies... +looking for conflicting packages... + +Packages (45) ceph-13.2.0-2  ceph-libs-13.2.0-2  debootstrap-1.0.105-1  guile-2.2.4-1  harfbuzz-1.8.2-1  harfbuzz-icu-1.8.2-1  haskell-aeson-1.3.1.1-20 +              haskell-attoparsec-0.13.2.2-24  haskell-tagged-0.8.6-1  imagemagick-7.0.8.4-1  lib32-harfbuzz-1.8.2-1  lib32-libgusb-0.3.0-1  lib32-systemd-239.0-1 +              libgit2-1:0.27.2-1  libinput-1.11.2-1  libmagick-7.0.8.4-1  libmagick6-6.9.10.4-1  libopenshot-0.2.0-1  libopenshot-audio-0.1.6-1  libosinfo-1.2.0-1 +              libxfce4util-4.13.2-1  minetest-0.4.17.1-1  minetest-common-0.4.17.1-1  mlt-6.10.0-1  mlt-python-bindings-6.10.0-1  ndctl-61.1-1  netctl-1.17-1 +              nodejs-10.6.0-1   + +Total Download Size:      2.66 MiB +Total Installed Size:   879.15 MiB +Net Upgrade Size:      -365.27 MiB + +:: Proceed with installation? [Y/n] +``` + +在前面提到的降级系统的情景中,你可以运行 `pacman -Syyuu` 来强行降级系统。你必须重视这一点:虽然在大多数情况下这不会引起问题,但是这种可能性还是存在,即降级一个包或几个包将会引起级联传播的失败并会将你的系统处于不一致的状态(LCTT 译注:即系统进入无法正常使用的状态),请务必小心! + +运行 `pacman -S kate` 来安装一个包。 + +``` +user@arch ~ $ sudo pacman -S kate + +resolving dependencies... +looking for conflicting packages... + +Packages (7) editorconfig-core-c-0.12.2-1  kactivities-5.47.0-1  kparts-5.47.0-1  ktexteditor-5.47.0-2  syntax-highlighting-5.47.0-1  threadweaver-5.47.0-1 +             kate-18.04.2-2 + +Total Download Size:   10.94 MiB +Total Installed Size:  38.91 MiB + +:: Proceed with installation? [Y/n] +``` + +你可以运行 `pacman -R kate` 来删除一个包。这将会只删除这个包自身而不会去删除它的依赖包。 + +``` +user@arch ~ $ sudo pacman -S kate + +checking dependencies... + +Packages (1) kate-18.04.2-2 + +Total Removed Size:  20.30 MiB + +:: Do you want to remove these packages? [Y/n] +``` + +如果你想删除没有被其它包依赖的包,你可以运行 `pacman -Rs`: + +``` +user@arch ~ $ sudo pacman -Rs kate + +checking dependencies... + +Packages (7) editorconfig-core-c-0.12.2-1  kactivities-5.47.0-1  kparts-5.47.0-1  ktexteditor-5.47.0-2  syntax-highlighting-5.47.0-1  threadweaver-5.47.0-1 +             kate-18.04.2-2 + +Total Removed Size:  38.91 MiB + +:: Do you want to remove these packages? [Y/n] +``` + +在笔者看来,Pacman 是搜索一个指定实用程序中的包名的最齐全的工具。如上所示,YUM 和 APT 都依赖于“路径”去搜索到有用的结果,而 Pacman 则做了一些智能的猜测,它会去猜测你最有可能想搜索的包。 + +``` +user@arch ~ $ sudo pacman -Fs updatedb +core/mlocate 0.26.git.20170220-1 +    usr/bin/updatedb + +user@arch ~ $ sudo pacman -Fs kate +extra/kate 18.04.2-2 +    usr/bin/kate +``` + +##### 使用 AUR + +有很多流行的 AUR 包管理器助手。其中 `yaourt` 和 `pacaur` 颇为流行。不过,这两个项目已经被 [Arch Wiki][21] 列为“不继续开发以及有已知的问题未解决”。因为这个原因,这里直接讨论 `aurman`,除了会搜索 AUR 以及包含几个有帮助的(其实很危险)的选项之外,它的工作机制和 `pacman` 极其类似。从 AUR 安装一个包将会初始化包维护者的构建脚本。你将会被要求输入几次授权以便让程序继续进行下去(为了简短起见,笔者截断了输出)。 + +``` +aurman -S telegram-desktop-bin +~~ initializing aurman... +~~ the following packages are neither in known repos nor in the aur +... +~~ calculating solutions... + +:: The following 1 package(s) are getting updated: +   aur/telegram-desktop-bin  1.3.0-1  ->  1.3.9-1 + +?? Do you want to continue? Y/n: Y + +~~ looking for new pkgbuilds and fetching them... +Cloning into 'telegram-desktop-bin'... + +remote: Counting objects: 301, done. +remote: Compressing objects: 100% (152/152), done. +remote: Total 301 (delta 161), reused 286 (delta 147) +Receiving objects: 100% (301/301), 76.17 KiB | 639.00 KiB/s, done. +Resolving deltas: 100% (161/161), done. +?? Do you want to see the changes of telegram-desktop-bin? N/y: N + +[sudo] password for user: + +... +==> Leaving fakeroot environment. +==> Finished making: telegram-desktop-bin 1.3.9-1 (Thu 05 Jul 2018 11:22:02 AM EDT) +==> Cleaning up... +loading packages... +resolving dependencies... +looking for conflicting packages... + +Packages (1) telegram-desktop-bin-1.3.9-1 + +Total Installed Size:  88.81 MiB +Net Upgrade Size:       5.33 MiB + +:: Proceed with installation? [Y/n] +``` + +依照你所安装的包的复杂性程度的高低,有时你将会被要求给出进一步的输入,为了避免这些反复的输入,`aurman` 允许你使用 `--noconfirm` 和 `--noedit` 选项。这相当于说“接受所有的预定设置,并相信包管理器不会干坏事”。**使用这两个选项时请务必小心!!**,虽然这些选项本身不太会破坏你的系统,你也不能盲目的接受他人的脚本程序。 + +### 总结 + +这篇文章当然只能触及包管理器的皮毛。还有很多别的包管理器笔者没有在这篇文章里谈及。有些 Linux 发布版,如 Ubuntu 或 Elementary OS,已经在图形版的包管理器的开发上有了长远的进展。 + +如果你对包管理器的更高级功能有进一步的兴趣,请在评论区留言,笔者很乐意进一步的写一写相关的文章。 + +### 附录 + +``` +# search for packages +yum search +dnf search +zypper search +apt-cache search +apt search +pacman -Ss + +# install packages +yum install +dnf install +zypper install +apt-get install +apt install +pacman -Ss + +# update package database, not required by yum, dnf and zypper +apt-get update +apt update +pacman -Sy + +# update all system packages +yum update +dnf update +zypper update +apt-get upgrade +apt upgrade +pacman -Su + +# remove an installed package +yum remove +dnf remove +apt-get remove +apt remove +pacman -R +pacman -Rs + +# search for the package name containing specific file or folder +yum whatprovides * +dnf whatprovides * +zypper what-provides +zypper search --provides +apt-file search +pacman -Sf +``` + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/7/evolution-package-managers + +作者:[Steve Ovens][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[DavidChenLiang](https://github.com/davidchenliang) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://opensource.com/users/stratusss +[1]:https://en.wikipedia.org/wiki/Common_Vulnerabilities_and_Exposures +[2]:https://en.wikipedia.org/wiki/Yum_(software) +[3]:https://fedoraproject.org/wiki/DNF +[4]:https://en.wikipedia.org/wiki/Rpm_(software) +[5]:https://en.wikipedia.org/wiki/Yellow_Dog_Linux +[6]:https://searchdatacenter.techtarget.com/definition/Yellowdog-Updater-Modified-YUM +[7]:https://en.wikipedia.org/wiki/DNF_(software) +[8]:https://en.opensuse.org/Portal:Zypper +[9]:https://www.suse.com/ +[10]:https://www.opensuse.org/ +[11]:https://en.wikipedia.org/wiki/MeeGo +[12]:https://sailfishos.org/ +[13]:https://www.tizen.org/ +[14]:https://en.wikipedia.org/wiki/YaST +[15]:https://en.wikipedia.org/wiki/APT_(Debian) +[16]:https://www.archlinux.org/ +[17]:https://wiki.archlinux.org/index.php/pacman +[18]:https://wiki.archlinux.org/index.php/Arch_Build_System +[19]:https://aur.archlinux.org/ +[20]:https://hub.docker.com/ +[21]:https://wiki.archlinux.org/index.php/AUR_helpers#Discontinued_or_problematic diff --git a/published/201808/20180727 Three Graphical Clients for Git on Linux.md b/published/201808/20180727 Three Graphical Clients for Git on Linux.md new file mode 100644 index 0000000000..ef1ed9bebe --- /dev/null +++ b/published/201808/20180727 Three Graphical Clients for Git on Linux.md @@ -0,0 +1,116 @@ +三款 Linux 下的 Git 图形客户端 +====== + +> 了解这三个 Git 图形客户端工具如何增强你的开发流程。 + +![](https://www.linux.com/sites/lcom/files/styles/rendered_file/public/git-tools.jpg?itok=Be56iPT0) + +在 Linux 下工作的人们对 [Git][1] 非常熟悉。一个理所当然的原因是,Git 是我们这个星球上最广为人知也是使用最广泛的版本控制工具。不过大多数情况下,Git 需要学习繁杂的终端命令。毕竟,我们的大多数开发工作可能是基于命令行的,那么没理由不以同样的方式与 Git 交互。 + +但在某些情况下,使用带图形界面的工具可能使你的工作更高效一点(起码对那些更倾向于使用图形界面的人们来说)。那么,有哪些 Git 图形客户端可供选择呢?幸运的是,我们找到一些客户端值得你花费时间和金钱(一些情况下)去尝试一下。在此,我主要推荐三种可以运行在 Linux 操作系统上的 Git 客户端。在这几种中,你可以找到一款满足你所有要求的客户端。 + +在这里我假设你理解如何使用 Git 和具有 GitHub 类似功能的代码仓库,[使用方法我之前讲过了][2],因此我不再花费时间讲解如何使用这些工具。本篇文章主要是一篇介绍,介绍几种可以用在开发任务中的工具。 + +提前说明一下:这些工具并不都是免费的,它们中的一些可能需要商业授权。不过,它们都在 Linux 下运行良好并且可以轻而易举的和 GitHub 相结合。 + +就说这些了,快让我们看看这些出色的 Git 图形客户端吧。 + +### SmartGit + +[SmartGit][3] 是一个商业工具,不过如果你在非商业环境下使用是免费的。如果你打算在商业环境下使用的话,一个许可证每人每年需要 99 美元,或者 5.99 美元一个月。还有一些其它升级功能(比如分布式评审Distributed Reviews智能同步SmartSynchronize),这两个工具每个许可证需要另加 15 美元。你也能通过下载源码或者 deb 安装包进行安装。我在 Ubuntu 18.04 下测试,发现 SmartGit 运行良好,没有出现一点问题。 + +不过,我们为什么要用 SmartGit 呢?有许多原因,最重要的一点是,SmartGit 可以非常方便的和 GitHub 以及 Subversion 等版本控制工具整合。不需要你花费宝贵的时间去配置各种远程账号,SmartGit 的这些功能开箱即用。SmartGit 的界面(图 1)设计的也很好,整洁直观。 + +![SmartGit][5] + +*图 1: SmartGit 帮助简化工作* + +安装完 SmartGit 后,我马上就用它连接到了我的 GitHub 账户。默认的工具栏是和仓库操作相关联的,非常简洁。推送、拉取、检出、合并、添加分支、cherry pick、撤销、变基、重置 —— 这些 Git 的的流行功能都支持。除了支持标准 Git 和 GitHub 的大部分功能,SmartGit 运行也非常稳定。至少当你在 Ubuntu上使用时,你会觉得这一款软件是专门为 Linux 设计和开发的。 + +SmartGit 可能是使各个水平的 Git 用户都可以非常轻松的使用 Git,甚至 Git 高级功能的最好工具。为了了解更多 SmartGit 相关知识,你可以查看一下其[丰富的文档][7]。 + +### GitKraken + +[GitKraken][8] 是另外一款商业 Git 图形客户端,它可以使你感受到一种绝不会后悔的使用 Git 或者 GitHub 的美妙体验。SmartGit 具有非常简洁的界面,而 GitKraken 拥有非常华丽的界面,它一开始就给你展现了很多特色。GitKraken 有一个免费版(你也可以使用完整版 15 天)。试用期过了,你也可以继续使用免费版,不过不能用于商业用途。 + +对那些想让其开发工作流发挥最大功效的人们来说,GitKraken 可能是一个比较好的选择。界面上具有的功能包括:可视化交互、可缩放的提交图、拖拽、与 Github、GitLab 和 BitBucked 的无缝整合、简单的应用内任务清单、应用内置的合并工具、模糊查找、支持 Gitflow、一键撤销与重做、快捷键、文件历史与追责、子模块、亮色和暗色主题、Git 钩子支持和 Git LFS 等许多功能。不过用户倍加赞赏的还是精美的界面(图 2)。 + +![GitKraken][10] + +*图 2: GitKraken的界面非常出色* + +除了令人惊艳的图形界面,另一个使 GitKraken 在 Git 图形客户端竞争中脱颖而出的功能是:GitKraken 使得使用多个远程仓库和多套配置变得非常简单。不过有一个告诫,使用 GitKraken 需要花钱(它是专有的)。如果你想商业使用,许可证的价钱如下: + + * 一人一年 49 美元 + * 10 人以上团队,39 美元每人每年 + * 100 人以上团队, 29 美元每人每年 + +专业版账户不但可以在商业环境使用 Git 相关功能,还可以使用 Glo Boards(GitKraken 的项目管理工具)。Glo Boards 的一个吸引人的功能是可以将数据同步到 GitHub 工单Issues。Glo Boards 具有分享功能还具有搜索过滤、问题跟踪、Markdown 支持、附件、@ 功能、清单卡片等许多功能。所有的这些功能都可以在 GitKraken 界面里进行操作。 + +GitKraken 可以通过 deb 文件或者源码进行安装。 + +### Git Cola + +[Git Cola][11] 是我们推荐列表中一款自由开源的 Git 图像客户端。不像 GitKraken 和 SmartGit,Git Cola是一款比较难啃的骨头,一款比较实用的 Git 客户端。Git Cola 是用 Python 写成的,使用的是 GTK 界面,因此无论你用的是什么 Linux 发行版和桌面,都可以无缝支持。并且因为它是开源的,你可以在你使用的发行版的包管理器中找到它。因此安装过程无非是打开应用商店,搜索 “Git Cola” 安装即可。你也可以通过下面的命令进行安装: + +``` +sudo apt install git-cola +``` + +或者 + +``` +sudo dnf install git-cola +``` + +Git Cola 看起来相对比较简单(图 3)。事实上,你无法找到更复杂的东西,因为 Git Cola 是非常基础的。 + +![Git Cola][13] + +*图 3:Git Cola 界面是非常简单的* + +因为 Git Cola 看起来回归自然,所以很多时间你必须同终端打交道。不过这并不是什么难事儿(因为大多数开发人员需要经常使用终端)。Git Cola 包含以下特性: + + * 支持多个子命令 + * 自定义窗口设置 + * 可设置环境变量 + * 语言设置 + * 支持自定义 GUI 设置 + * 支持快捷键 + +尽管 Git Cola 支持连接到远程仓库,但和像 GitHub 这样的仓库整合看起来也没有 GitKraken 和 SmartGit 直观。不过如果你的大部分工作是在本地进行的,Git Cola 并不失为一个出色的工具。 + +Git Cola 也带有有一个高级的 DAG(有向无环图)可视化工具,叫做 Git DAG。这个工具可以使你获得分支的可视化展示。你可以独立使用 Git DAG,也可以在 Git Cola 内通过 “view->DAG” 菜单来打开。正是 Git DAG 这个威力巨大的工具使用 Git Cola 跻身于应用商店中 Git 图形客户端前列。 + +### 更多的客户端 + +还有更多的 Git 图形客户端。不过,从上面介绍的这几款中,你已经可以做很多事情了。无论你在寻找一款更有丰富功能的 Git 客户端(不管许可证的话)还是你本身是一名坚定的 GPL 支持者,都可以从上面找到适合自己的一款。 + +如果想学习更多关于 Linux 的知识,可以通过学习Linux基金会的[走进 Linux][14]课程。 + +-------------------------------------------------------------------------------- + +via: https://www.linux.com/learn/intro-to-linux/2018/7/three-graphical-clients-git-linux + +作者:[Jack Wallen][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[tarepanda1024](https://github.com/tarepanda1024) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.linux.com/users/jlwallen +[1]:https://git-scm.com/ +[2]:https://www.linux.com/learn/intro-to-linux/2018/7/introduction-using-git +[3]:https://www.syntevo.com/smartgit/ +[4]:/files/images/gitgui1jpg +[5]:https://www.linux.com/sites/lcom/files/styles/rendered_file/public/gitgui_1.jpg?itok=LEZ_PYIf (SmartGit) +[6]:/licenses/category/used-permission +[7]:http://www.syntevo.com/doc/display/SG/Manual +[8]:https://www.gitkraken.com/ +[9]:/files/images/gitgui2jpg +[10]:https://www.linux.com/sites/lcom/files/styles/rendered_file/public/gitgui_2.jpg?itok=Y8crSLhf (GitKraken) +[11]:https://git-cola.github.io/ +[12]:/files/images/gitgui3jpg +[13]:https://www.linux.com/sites/lcom/files/styles/rendered_file/public/gitgui_3.jpg?itok=bS9OYPQo (Git Cola) +[14]:https://training.linuxfoundation.org/linux-courses/system-administration-training/introduction-to-linux diff --git a/published/201808/20180730 Open Source Networking Jobs- A Hotbed of Innovation and Opportunities.md b/published/201808/20180730 Open Source Networking Jobs- A Hotbed of Innovation and Opportunities.md new file mode 100644 index 0000000000..42f67043cd --- /dev/null +++ b/published/201808/20180730 Open Source Networking Jobs- A Hotbed of Innovation and Opportunities.md @@ -0,0 +1,48 @@ +开源网络方面的职位:创新与机遇的温床 +====== + +> 诸如容器、边缘计算这样的技术焦点领域大红大紫,对在这一领域能够整合、协作、创新的开发者和系统管理员们的需求在日益增进。 + +![](https://www.linux.com/sites/lcom/files/styles/rendered_file/public/os-jobs-networking.jpg?itok=PgUzydn-) + +随着全球经济更加靠近数字化未来,每个垂直行业的公司和组织都在紧抓如何进一步在业务与运营上整合与部署技术。虽然 IT 企业在很大程度上遥遥领先,但是他们的经验与教训已经应用在了各行各业。尽管全国失业率为 4.1%,但整个科技专业人员的整体的失业率在 4 月份为 1.9%,开源工作的未来看起来尤其光明。我在开源网络领域工作,并且目睹着创新和机遇正在改变世界交流的方式。 + +它曾经是个发展缓慢的行业,现在由网络运营商、供应商、系统集成商和开发者所组成的网络生态系统正在采用开源软件,并且正在向商用硬件上运行的虚拟化和软件定义网络上转移。事实上,接近 70% 的全球移动用户由[低频网络][1]运营商成员所占据。该网络运营商成员致力于协调构成开放网络栈和相邻技术的项目。 + +### 技能需求 + +这一领域的开发者和系统管理员采用云原生和 DevOps 的方法开发新的使用案例,应对最紧迫的行业挑战。诸如容器、边缘计算等焦点领域大红大紫,并且在这一领域能够整合、协作、创新的开发者和系统管理员们的需求在日益增进。 + +开源软件与 Linux 使这一切成为可能,根据最近出版的 [2018开源软件工作报告][2],高达 80% 的招聘经理寻找会 Linux 技能的应聘者,**而 46% 希望在网络领域招聘人才,可以说“网络技术”在他们的招聘决策中起到了至关重要的作用。** + +开发人员相当抢手,72% 的招聘经理都在找他们,其次是 DevOps 开发者(59%),工程师(57%)和系统管理员(49%)。报告同时指出,对容器技能需求的惊人的增长符合我们在网络领域所见到的,即云本地虚拟功能(CNF)的创建和持续集成/持续部署方式的激增,就如在 OPNFV 中的 [XCI 倡议][3] 一样。 + +### 开始吧 + +对于求职者来说,好消息是有着大量的关于开源软件的内容,包括免费的 [Linux 入门课程][4]。好的工作需要有多项证书,因此我鼓励你探索更多领域,去寻求培训的机会。计算机网络方面,在 [OPNFV][5] 上查看最新的培训课程或者是 [ONAP][6] 项目,也可以选择这门[开源网络技术简介][7]课程。 + +如果你还没有做好这些,下载 [2018 开源软件工作报告][2] 以获得更多见解,在广阔的开放源码技术世界中规划你的课程,去寻找另一边等待你的令人兴奋的职业! + +点击这里[下载完整的开源软件工作报告][8]并且[了解更多关于 Linux 的认证][9]。 + +-------------------------------------------------------------------------------- + +via: https://www.linux.com/blog/os-jobs-report/2018/7/open-source-networking-jobs-hotbed-innovation-and-opportunities + +作者:[Brandon Wick][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[LuuMing](https://github.com/LuuMing) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.linux.com/users/brandon-wick +[1]:https://www.lfnetworking.org/ +[2]:https://www.linuxfoundation.org/publications/2018/06/open-source-jobs-report-2018/ +[3]:https://docs.opnfv.org/en/latest/submodules/releng-xci/docs/xci-overview.html +[4]:https://www.edx.org/course/introduction-linux-linuxfoundationx-lfs101x-1 +[5]:https://training.linuxfoundation.org/training/opnfv-fundamentals/ +[6]:https://training.linuxfoundation.org/training/onap-fundamentals/ +[7]:https://www.edx.org/course/introduction-to-software-defined-networking-technologies +[8]:https://www.linuxfoundation.org/publications/open-source-jobs-report-2018/ +[9]:https://training.linuxfoundation.org/certification diff --git a/published/201808/20180731 A sysadmin-s guide to Bash.md b/published/201808/20180731 A sysadmin-s guide to Bash.md new file mode 100644 index 0000000000..debdb1fd74 --- /dev/null +++ b/published/201808/20180731 A sysadmin-s guide to Bash.md @@ -0,0 +1,173 @@ +面向系统管理员的 Bash 指南 +====== + +> 使 Bash 工作的更好的技巧。 + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/build_structure_tech_program_code_construction.png?itok=nVsiLuag) + +每个行业都有一个该行业的大师们最常使用的工具。 对于许多系统管理员来说,这个工具就是他们的 [shell][1]。 在大多数 Linux 和其他类 Unix 系统上,默认的 shell 是 Bash。 + +Bash 是一个相当古老的程序——它起源于 20 世纪 80 年代后期——但它建立在更多更老的 shell 上,比如 C shell(csh),csh 至少是它 10 年前的前辈了。 因为 shell 的概念是那么古老,所以有大量的神秘知识等待着系统管理员去吸收领悟,使其生活更轻松。 + +我们来看看一些基础知识。 + +在某些时候,谁曾经无意中以 root 身份运行命令并导致某种问题? *举手* + +我很确定我们很多人一度都是那个人。 这很痛苦。 这里有一些非常简单的技巧可以防止你再次碰上这类问题。 + +### 使用别名 + +首先,为 `mv` 和 `rm` 等命令设置别名,指向 `mv -i` 和 `rm -i`。 这将确保在运行 `rm -f /boot` 时至少需要你确认。 在 Red Hat 企业版 Linux 中,如果你使用 root 帐户,则默认设置这些别名。 + +如果你还要为普通用户帐户设置这些别名,只需将这两行放入家目录下名为 `.bashrc` 的文件中(这些也适用于 `sudo` ): + +``` +alias mv='mv -i' +alias rm='rm -i' +``` + +### 让你的 root 提示符脱颖而出 + +你可以采取的防止意外发生的另一项措施是确保你很清楚在使用 root 帐户。 在日常工作中,我通常会让 root 提示符从日常使用的提示符中脱颖而出。 + +如果将以下内容放入 root 的家目录中的 `.bashrc` 文件中,你将看到一个黑色背景上的红色的 root 提示符,清楚地表明你(或其他任何人)应该谨慎行事。 + +``` +export PS1="\[$(tput bold)$(tput setab 0)$(tput setaf 1)\]\u@\h:\w # \[$(tput sgr0)\]" +``` + +实际上,你应该尽可能避免以 root 用户身份登录,而是通过 `sudo` 运行大多数系统管理命令,但这是另一回事。 + +使用了一些小技巧用于防止使用 root 帐户时的“不小心的副作用”之后,让我们看看 Bash 可以帮助你在日常工作中做的一些好事。 + +### 控制你的历史 + +你可能知道在 Bash 中你按向上的箭头时能看见和重新使用你之前所有(好吧,大多数)的命令。这是因为这些命令已经保存到了你家目录下的名为 `.bash_history` 的文件中。这个历史文件附带了一组有用的设置和命令。 + +首先,你可以通过键入 `history` 来查看整个最近的命令历史记录,或者你可以通过键入 `history 30` 将其限制为最近 30 个命令。不过这技巧太平淡无奇了(LCTT 译注: vanilla 原为香草,后引申没拓展的、标准、普通的,比如 vanilla C++ compiler 意为标准 C++ 编译器)。 你可以更好地控制 Bash 保存的内容以及保存方式。 + +例如,如果将以下内容添加到 `.bashrc`,那么任何以空格开头的命令都不会保存到历史记录列表中: + +``` +HISTCONTROL=ignorespace +``` + +如果你需要以明文形式将密码传递给一个命令,这就非常有用。 (是的,这太可怕了,但它仍然会发生。) + +如果你不希望经常执行的命令充斥在历史记录中,请使用: + +``` +HISTCONTROL=ignorespace:erasedups +``` + +这样,每次使用一个命令时,都会从历史记录文件中删除之前出现的所有相同命令,并且只将最后一次调用保存到历史记录列表中。 + +我特别喜欢的历史记录设置是 `HISTTIMEFORMAT` 设置。 这将在历史记录文件中在所有的条目前面添加上时间戳。 例如,我使用: + +``` +HISTTIMEFORMAT="%F %T  " +``` + +当我输入 `history 5` 时,我得到了很好的完整信息,如下所示: + +``` +1009  2018-06-11 22:34:38  cat /etc/hosts +1010  2018-06-11 22:34:40  echo $foo +1011  2018-06-11 22:34:42  echo $bar +1012  2018-06-11 22:34:44  ssh myhost +1013  2018-06-11 22:34:55  vim .bashrc +``` + +这使我更容易浏览我的命令历史记录并找到我两天前用来建立到我家实验室的 SSH 连接(我一次又一次地忘记......)。 + +### Bash 最佳实践 + +我将在编写 Bash 脚本时最好的(或者至少是好的,我不要求无所不知)11 项实践列出来。 + +11、 Bash 脚本可能变得复杂,不过注释也很方便。 如果你在考虑是否要添加注释,那就添加一个注释。 如果你在周末之后回来并且不得不花时间搞清楚你上周五想要做什么,那你是忘了添加注释。 + +10、 用花括号括起所有变量名,比如 `${myvariable}`。 养成这个习惯可以使用 `${variable}_suffix` 这种用法了,还能提高整个脚本的一致性。 + +9、 计算表达式时不要使用反引号;请改用 `$()` 语法。 所以使用: + +``` +for  file in $(ls); do +``` + +而不使用: + +``` +for  file in `ls`; do +``` + +前一个方式是可嵌套的,更易于阅读的,还能让一般的系统管理员群体感到满意。 不要使用反引号。 + +8、 一致性是好的。 选择一种风格并在整个脚本中坚持下去。 显然,我喜欢人们选择 `$()` 语法而不是反引号,并将其变量包在花括号中。 我更喜欢人们使用两个或四个空格而不是制表符来缩进,但即使你选择了错误的方式,也要一贯地错下去。 + +7、 为 Bash 脚本使用适当的[释伴][3]shebang(LCTT 译注:**Shebang**,也称为 **Hashbang** ,是一个由井号和叹号构成的字符序列 `#!` ,其出现在文本文件的第一行的前两个字符。 在文件中存在释伴的情况下,类 Unix 操作系统的程序载入器会分析释伴后的内容,将这些内容作为解释器指令,并调用该指令,并将载有释伴的文件路径作为该解释器的参数)。 因为我正在编写Bash脚本,只打算用 Bash 执行它们,所以我经常使用 `#!/usr/bin/bash` 作为我的释伴。 不要使用 `#!/bin/sh` 或 `#!/usr/bin/sh`。 你的脚本会被执行,但它会以兼容模式运行——可能会产生许多意外的副作用。 (当然,除非你想要兼容模式。) + +6、 比较字符串时,在 `if` 语句中给变量加上引号是个好主意,因为如果你的变量是空的,Bash 会为这样的行抛出一个错误: + +``` +if [ ${myvar} == "foo" ]; then + echo "bar" +fi +``` + +对于这样的行,将判定为 `false`: + +``` +if [ "${myvar}" == "foo" ]; then + echo "bar" +fi +``` + +此外,如果你不确定变量的内容(例如,在解析用户输入时),请给变量加引号以防止解释某些特殊字符,并确保该变量被视为单个单词,即使它包含空格。 + +5、 我想这是一个品味问题,但我更喜欢使用双等号( `==` ),即使是比较 Bash 中的字符串。 这是一致性的问题,尽管对于字符串比较,只有一个等号会起作用,我的思维立即变为“单个 `=` 是一个赋值运算符!” + +4、 使用适当的退出代码。 确保如果你的脚本无法执行某些操作,则会向用户显示已写好的失败消息(最好提供解决问题的方法)并发送非零退出代码: + +``` +# we have failed +echo "Process has failed to complete, you need to manually restart the whatchamacallit" +exit 1 +``` + +这样可以更容易地以编程方式从另一个脚本调用你的脚本并验证其成功完成。 + +3、 使用 Bash 的内置机制为变量提供合理的默认值,或者如果未定义你希望定义的变量,则抛出错误: + +``` +# this sets the value of $myvar to redhat, and prints 'redhat' +echo ${myvar:=redhat} +``` + +``` +# this throws an error reading 'The variable myvar is undefined, dear reader' if $myvar is undefined +${myvar:?The variable myvar is undefined, dear reader} +``` + +2、 特别是如果你正在编写大型脚本,或者是如果你与其他人一起开发该大型脚本,请考虑在函数内部定义变量时使用 `local` 关键字。 `local` 关键字将创建一个局部变量,该变量只在该函数中可见。 这限制了变量冲突的可能性。 + +1、 每个系统管理员有时必须这样做:在控制台上调试一些东西,可能是数据中心的真实服务器,也可能是虚拟化平台的虚拟服务器。 如果你必须以这种方式调试脚本,你会感谢你自己记住了这个:不要让你的脚本中的行太长! + +在许多系统上,控制台的默认宽度仍为 80 个字符。 如果你需要在控制台上调试脚本并且该脚本有很长的行,那么你将成为一个悲伤的熊猫。 此外,具有较短行的脚本—— 默认值仍为 80 个字符——在普通编辑器中也更容易阅读和理解! + +我真的很喜欢 Bash。 我可以花几个小时写这篇文章或与其他爱好者交流优秀的技巧。 就希望你们能在评论中留下赞美。 + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/7/admin-guide-bash + +作者:[Maxim Burgerhout][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[Flowsnow](https://github.com/Flowsnow) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://opensource.com/users/wzzrd +[1]:http://www.catb.org/jargon/html/S/shell.html +[2]:https://en.wikipedia.org/wiki/C_shell +[3]:https://linux.cn/article-3664-1.html \ No newline at end of file diff --git a/published/201808/20180731 How To Use Pbcopy And Pbpaste Commands On Linux.md b/published/201808/20180731 How To Use Pbcopy And Pbpaste Commands On Linux.md new file mode 100644 index 0000000000..b100d4f815 --- /dev/null +++ b/published/201808/20180731 How To Use Pbcopy And Pbpaste Commands On Linux.md @@ -0,0 +1,136 @@ +如何在 Linux 上使用 pbcopy 和 pbpaste 命令 +====== + +![](https://www.ostechnix.com/wp-content/uploads/2018/07/Pbcopy-And-Pbpaste-Commands-720x340.png) + +由于 Linux 和 Mac OS X 是基于 *Nix 的系统,因此许多命令可以在两个平台上运行。但是,某些命令可能在两个平台上都没有,比如 `pbcopy` 和 `pbpast`。这些命令仅在 Mac OS X 平台上可用。`pbcopy` 命令将标准输入复制到剪贴板。然后,你可以在任何地方使用 `pbpaste` 命令粘贴剪贴板内容。当然,上述命令可能有一些 Linux 替代品,例如 `xclip`。 `xclip` 与 `pbcopy` 完全相同。但是,从 Mac OS 切换到 Linux 的发行版的人将会找不到这两个命令,不过仍然想使用它们。别担心!这个简短的教程描述了如何在 Linux 上使用 `pbcopy` 和 `pbpaste` 命令。 + +### 安装 xclip / xsel + +就像我已经说过的那样,Linux 中没有 `pbcopy` 和 `pbpaste` 命令。但是,我们可以通过 shell 别名使用 xclip 和/或 xsel 命令复制 `pbcopy` 和 `pbpaste` 命令的功能。xclip 和 xsel 包存在于大多数 Linux 发行版的默认存储库中。请注意,你无需安装这两个程序。只需安装上述任何一个程序即可。 + +要在 Arch Linux 及其衍生产版上安装它们,请运行: + +``` +$ sudo pacman xclip xsel +``` + +在 Fedora 上: + +``` +$ sudo dnf xclip xsel +``` + +在 Debian、Ubuntu、Linux Mint 上: + +``` +$ sudo apt install xclip xsel +``` + +安装后,你需要为 `pbcopy` 和 `pbpaste` 命令创建别名。为此,请编辑 `~/.bashrc`: + +``` +$ vi ~/.bashrc +``` + +如果要使用 xclip,请粘贴以下行: + +``` +alias pbcopy='xclip -selection clipboard' +alias pbpaste='xclip -selection clipboard -o' +``` + +如果要使用 xsel,请在 `~/.bashrc` 中粘贴以下行。 + +``` +alias pbcopy='xsel --clipboard --input' +alias pbpaste='xsel --clipboard --output' +``` + +保存并关闭文件。 + +接下来,运行以下命令以更新 `~/.bashrc` 中的更改。 + +``` +$ source ~/.bashrc +``` + +ZSH 用户将上述行粘贴到 `~/.zshrc` 中。 + +### 在 Linux 上使用 pbcopy 和 pbpaste 命令 + +让我们看一些例子。 + +`pbcopy` 命令将文本从 stdin 复制到剪贴板缓冲区。例如,看看下面的例子。 + +``` +$ echo "Welcome To OSTechNix!" | pbcopy +``` + +上面的命令会将文本 “Welcome to OSTechNix” 复制到剪贴板中。你可以稍后访问此内容并使用如下所示的 `pbpaste` 命令将其粘贴到任何位置。 + +``` +$ echo `pbpaste` +Welcome To OSTechNix! +``` + +![](https://www.ostechnix.com/wp-content/uploads/2018/07/pbcopy-and-pbpaste-commands-in-action.png) + +以下是一些其他例子。 + +我有一个名为 `file.txt` 的文件,其中包含以下内容。 + +``` +$ cat file.txt +Welcome To OSTechNix! +``` + +你可以直接将文件内容复制到剪贴板中,如下所示。 + +``` +$ pbcopy < file.txt +``` + +现在,只要你用其他文件的内容更新了剪切板,那么剪切板中的内容就可用了。 + +要从剪贴板检索内容,只需输入: + +``` +$ pbpaste +Welcome To OSTechNix! +``` + +你还可以使用管道字符将任何 Linux 命令的输出发送到剪贴板。看看下面的例子。 + +``` +$ ps aux | pbcopy +``` + +现在,输入 `pbpaste` 命令以显示剪贴板中 `ps aux` 命令的输出。 + +``` +$ pbpaste +``` + +![](https://www.ostechnix.com/wp-content/uploads/2018/07/pbcopy-and-pbpaste-commands-2.png) + +使用 `pbcopy` 和 `pbpaste` 命令可以做更多的事情。我希望你现在对这些命令有一个基本的想法。 + +就是这些了。还有更好的东西。敬请关注! + +干杯! + + + +-------------------------------------------------------------------------------- + +via: https://www.ostechnix.com/how-to-use-pbcopy-and-pbpaste-commands-on-linux/ + +作者:[SK][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[geekpi](https://github.com/geekpi) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.ostechnix.com/author/sk/ diff --git a/published/201808/20180801 Cross-Site Request Forgery.md b/published/201808/20180801 Cross-Site Request Forgery.md new file mode 100644 index 0000000000..4becfc1546 --- /dev/null +++ b/published/201808/20180801 Cross-Site Request Forgery.md @@ -0,0 +1,52 @@ +CSRF(跨站请求伪造)简介 +====== +![](http://www.linuxandubuntu.com/uploads/2/1/1/5/21152474/understanding-csrf-cross-site-forgery_orig.jpg) + +设计 Web 程序时,安全性是一个主要问题。我不是在谈论 DDoS 保护、使用强密码或两步验证。我说的是对网络程序的最大威胁。它被称为**CSRF**, 是 **Cross Site Resource Forgery** (跨站请求伪造)的缩写。 + +### 什么是 CSRF? + + [![csrf what is cross site forgery](http://www.linuxandubuntu.com/uploads/2/1/1/5/21152474/csrf-what-is-cross-site-forgery_orig.jpg)][1] + +首先,**CSRF** 是 Cross Site Resource Forgery 的缩写。它通常发音为 “sea-surf”,也经常被称为 XSRF。CSRF 是一种攻击类型,在受害者不知情的情况下,在受害者登录的 Web 程序上执行各种操作。这些行为可以是任何事情,从简单地点赞或评论社交媒体帖子到向人们发送垃圾消息,甚至从受害者的银行账户转移资金。 + +### CSRF 如何工作? + +**CSRF** 攻击尝试利用所有浏览器上的一个简单的常见漏洞。每次我们对网站进行身份验证或登录时,会话 cookie 都会存储在浏览器中。因此,每当我们向网站提出请求时,这些 cookie 就会自动发送到服务器,服务器通过匹配与服务器记录一起发送的 cookie 来识别我们。这样就知道是我们了。 + + [![cookies set by website chrome](http://www.linuxandubuntu.com/uploads/2/1/1/5/21152474/cookies-set-by-website-chrome_orig.jpg)][2] + +这意味着我将在知情或不知情的情况下发出请求。由于 cookie 也被发送并且它们将匹配服务器上的记录,服务器认为我在发出该请求。 +​ +CSRF 攻击通常以链接的形式出现。我们可以在其他网站上点击它们或通过电子邮件接收它们。单击这些链接时,会向服务器发出不需要的请求。正如我之前所说,服务器认为我们发出了请求并对其进行了身份验证。 + +#### 一个真实世界的例子 + +为了把事情看得更深入,想象一下你已登录银行的网站。并在 **yourbank.com/transfer** 上填写表格。你将接收者的帐号填写为 1234,填入金额 5,000 并单击提交按钮。现在,我们将有一个 **yourbank.com/transfer/send?to=1234&amount=5000** 的请求。因此服务器将根据请求进行操作并转账。现在想象一下你在另一个网站上,然后点击一个链接,用黑客的帐号作为参数打开上面的 URL。这笔钱现在会转账给黑客,服务器认为你做了交易。即使你没有。 + + [![csrf hacking bank account](http://www.linuxandubuntu.com/uploads/2/1/1/5/21152474/csrf-hacking-bank-account_orig.jpg)][3] + +#### CSRF 防护 + +CSRF 防护非常容易实现。它通常将一个称为 CSRF 令牌的令牌发送到网页。每次发出新请求时,都会发送并验证此令牌。因此,向服务器发出的恶意请求将通过 cookie 身份验证,但 CSRF 验证会失败。大多数 Web 框架为防止 CSRF 攻击提供了开箱即用的支持,而 CSRF 攻击现在并不像以前那样常见。 + +### 总结 + +CSRF 攻击在 10 年前是一件大事,但如今我们看不到太多。过去,Youtube、纽约时报和 Netflix 等知名网站都容易受到 CSRF 的攻击。然而,CSRF 攻击的普遍性和发生率最近有减少。尽管如此,CSRF 攻击仍然是一种威胁,重要的是,你要保护自己的网站或程序免受攻击。 + + +-------------------------------------------------------------------------------- + +via: http://www.linuxandubuntu.com/home/understanding-csrf-cross-site-request-forgery + +作者:[linuxandubuntu][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[geekpi](https://github.com/geekpi) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:http://www.linuxandubuntu.com +[1]:http://www.linuxandubuntu.com/uploads/2/1/1/5/21152474/csrf-what-is-cross-site-forgery_orig.jpg +[2]:http://www.linuxandubuntu.com/uploads/2/1/1/5/21152474/cookies-set-by-website-chrome_orig.jpg +[3]:http://www.linuxandubuntu.com/uploads/2/1/1/5/21152474/csrf-hacking-bank-account_orig.jpg diff --git a/published/201808/20180802 6 Easy Ways to Check User Name And Other Information in Linux.md b/published/201808/20180802 6 Easy Ways to Check User Name And Other Information in Linux.md new file mode 100644 index 0000000000..32fe8a11c0 --- /dev/null +++ b/published/201808/20180802 6 Easy Ways to Check User Name And Other Information in Linux.md @@ -0,0 +1,361 @@ +6 个简单的方式来查看 Linux 中的用户名和其它信息 +====== + +这是一个非常基础的话题,在 Linux 中,每个人都知道如何使用 `id` 来查找用户信息。一些用户也从 `/etc/passwd` 文件中过滤用户信息。 + +我们还使用其它命令来获取用户信息。 + +你可能会问,为什么要讨论这个基础话题呢?即使我也这么认为,因为除了这两个之外没有更好的方法了,但是我们也有一些不错的选择。 + +与这两者相比,那些命令提供了更详细的信息,这对于新手非常有帮助。 + +这是帮助管理员在 Linux 中查找用户信息的基本命令之一。Linux 中的一切都是文件,甚至用户信息都存储在一个文件中。 + +建议阅读: + +- [怎样在 Linux 上查看用户创建的日期][1] +- [怎样在 Linux 上查看用户属于哪个组][2] +- [怎样在 Linux 上查看强制用户在下次登录时改变密码][3] + +所有用户都被添加在 `/etc/passwd` 文件中,这里保留了用户名和其它相关详细信息。在 Linux 中创建用户时,用户详细信息将存储在 `/etc/passwd` 文件中。passwd 文件将每个用户详细信息保存为一行,包含 7 字段。 + +我们可以使用以下 6 种方法来查看用户信息。 + + * `id`:为指定的用户名打印用户和组信息。 + * `getent`:从 Name Service Switch 库中获取条目。 + * `/etc/passwd`: 文件包含每个用户的详细信息,每个用户详情是一行,包含 7 个字段。 + * `finger`:用户信息查询程序 + * `lslogins`:显示系统中已有用户的信息 + * `compgen`:是 bash 内置命令,它将显示用户的所有可用命令。 + +### 1) 使用 id 命令 + +`id` 代表身份identity。它输出真实有效的用户和组 ID。也可以输出指定用户或当前用户的用户和组信息。 + +``` +# id daygeek +uid=1000(daygeek) gid=1000(daygeek) groups=1000(daygeek),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),118(lpadmin),128(sambashare) +``` + +下面是上述输出的详细信息: + + * `uid (1000/daygeek)`: 它显示用户 ID 和用户名 + * `gid (1000/daygeek)`: 它显示用户的组 ID 和名称 + * `groups`: 它显示用户的附加组 ID 和名称 + +### 2) 使用 getent 命令 + +`getent` 命令显示 Name Service Switch 库支持的数据库中的条目,这些库在 `/etc/nsswitch.conf` 中配置。 + +`getent` 命令会显示类似于 `/etc/passwd` 文件的用户详情,它将每个用户的详细信息放在一行,包含 7 个字段。 + +``` +# getent passwd +root:x:0:0:root:/root:/bin/bash +bin:x:1:1:bin:/bin:/sbin/nologin +daemon:x:2:2:daemon:/sbin:/sbin/nologin +adm:x:3:4:adm:/var/adm:/sbin/nologin +lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin +sync:x:5:0:sync:/sbin:/bin/sync +shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown +halt:x:7:0:halt:/sbin:/sbin/halt +mail:x:8:12:mail:/var/spool/mail:/sbin/nologin +uucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologin +operator:x:11:0:operator:/root:/sbin/nologin +games:x:12:100:games:/usr/games:/sbin/nologin +gopher:x:13:30:gopher:/var/gopher:/sbin/nologin +ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin +nobody:x:99:99:Nobody:/:/sbin/nologin +dbus:x:81:81:System message bus:/:/sbin/nologin +vcsa:x:69:69:virtual console memory owner:/dev:/sbin/nologin +abrt:x:173:173::/etc/abrt:/sbin/nologin +haldaemon:x:68:68:HAL daemon:/:/sbin/nologin +ntp:x:38:38::/etc/ntp:/sbin/nologin +saslauth:x:499:76:Saslauthd user:/var/empty/saslauth:/sbin/nologin +postfix:x:89:89::/var/spool/postfix:/sbin/nologin +sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin +tcpdump:x:72:72::/:/sbin/nologin +centos:x:500:500:Cloud User:/home/centos:/bin/bash +prakash:x:501:501:2018/04/12:/home/prakash:/bin/bash +apache:x:48:48:Apache:/var/www:/sbin/nologin +nagios:x:498:498::/var/spool/nagios:/sbin/nologin +rpc:x:32:32:Rpcbind Daemon:/var/lib/rpcbind:/sbin/nologin +nrpe:x:497:497:NRPE user for the NRPE service:/var/run/nrpe:/sbin/nologin +magesh:x:502:503:2g Admin - Magesh M:/home/magesh:/bin/bash +thanu:x:503:504:2g Editor - Thanisha M:/home/thanu:/bin/bash +sudha:x:504:505:2g Editor - Sudha M:/home/sudha:/bin/bash +``` + +下面是关于 7 个字段的详细信息: + +``` +magesh:x:502:503:2g Admin - Magesh M:/home/magesh:/bin/bash +``` + + * `Username (magesh)`: 已创建的用户名。字符长度应该在 1 到 32 之间。 + * `Password (x)`: 它表明加密密码存储在 `/etc/shadow` 文件中。 + * `User ID (UID-502)`: 它表示用户 ID(UID),每个用户应包含唯一的 UID。UID (0-Zero) 保留给 root,UID(1-99)是为系统用户保留的,UID(100-999)是为系统账户/组保留的。 + * `Group ID (GID-503)`: 它表示组 ID(GID),每个组应该包含唯一的 GID,它存储在 `/etc/group` 文件中。 + * `User ID Info (2g Admin - Magesh M)`: 它表示命令字段。这个字段可用于描述用户信息。 + * `Home Directory (/home/magesh)`: 它表示用户家目录。 + * `shell (/bin/bash)`: 它表示用户的 bash shell。 + +如果你只想在 `getent` 命令的输出中显示用户名,使用以下命令格式: + +``` +# getent passwd | cut -d: -f1 +root +bin +daemon +adm +lp +sync +shutdown +halt +mail +uucp +operator +games +gopher +ftp +nobody +dbus +vcsa +abrt +haldaemon +ntp +saslauth +postfix +sshd +tcpdump +centos +prakash +apache +nagios +rpc +nrpe +magesh +thanu +sudha +``` + +只显示用户的家目录,使用以下命令格式: + +``` +# getent passwd | grep '/home' | cut -d: -f1 +centos +prakash +magesh +thanu +sudha +``` + +### 3) 使用 /etc/passwd 文件 + +`/etc/passwd` 是一个文本文件,它包含每个用户登录 Linux 系统所必需的的信息。它维护用户的有用信息,如用户名,密码,用户 ID,组 ID,用户 ID 信息,家目录和 shell。`/etc/passwd` 文件将每个用户详细信息放在一行中,包含 7 个字段,如下所示: + +``` +# cat /etc/passwd +root:x:0:0:root:/root:/bin/bash +bin:x:1:1:bin:/bin:/sbin/nologin +daemon:x:2:2:daemon:/sbin:/sbin/nologin +adm:x:3:4:adm:/var/adm:/sbin/nologin +lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin +sync:x:5:0:sync:/sbin:/bin/sync +shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown +halt:x:7:0:halt:/sbin:/sbin/halt +mail:x:8:12:mail:/var/spool/mail:/sbin/nologin +uucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologin +operator:x:11:0:operator:/root:/sbin/nologin +games:x:12:100:games:/usr/games:/sbin/nologin +gopher:x:13:30:gopher:/var/gopher:/sbin/nologin +ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin +nobody:x:99:99:Nobody:/:/sbin/nologin +dbus:x:81:81:System message bus:/:/sbin/nologin +vcsa:x:69:69:virtual console memory owner:/dev:/sbin/nologin +abrt:x:173:173::/etc/abrt:/sbin/nologin +haldaemon:x:68:68:HAL daemon:/:/sbin/nologin +ntp:x:38:38::/etc/ntp:/sbin/nologin +saslauth:x:499:76:Saslauthd user:/var/empty/saslauth:/sbin/nologin +postfix:x:89:89::/var/spool/postfix:/sbin/nologin +sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin +tcpdump:x:72:72::/:/sbin/nologin +centos:x:500:500:Cloud User:/home/centos:/bin/bash +prakash:x:501:501:2018/04/12:/home/prakash:/bin/bash +apache:x:48:48:Apache:/var/www:/sbin/nologin +nagios:x:498:498::/var/spool/nagios:/sbin/nologin +rpc:x:32:32:Rpcbind Daemon:/var/lib/rpcbind:/sbin/nologin +nrpe:x:497:497:NRPE user for the NRPE service:/var/run/nrpe:/sbin/nologin +magesh:x:502:503:2g Admin - Magesh M:/home/magesh:/bin/bash +thanu:x:503:504:2g Editor - Thanisha M:/home/thanu:/bin/bash +sudha:x:504:505:2g Editor - Sudha M:/home/sudha:/bin/bash +``` + +以下是 7 个字段的详细信息。 + +``` +magesh:x:502:503:2g Admin - Magesh M:/home/magesh:/bin/bash +``` + + * `Username (magesh)`: 已创建的用户名。字符长度应该在 1 到 32 之间。 + * `Password (x)`: 它表明加密密码存储在 `/etc/shadow` 文件中。 + * `User ID (UID-502)`: 它表示用户 ID(UID),每个用户应包含唯一的 UID。UID (0-Zero) 保留给 root,UID(1-99)是为系统用户保留的,UID(100-999)是为系统账户/组保留的。 + * `Group ID (GID-503)`: 它表示组 ID(GID),每个组应该包含唯一的 GID,它存储在 `/etc/group` 文件中。 + * `User ID Info (2g Admin - Magesh M)`: 它表示命令字段。这个字段可用于描述用户信息。 + * `Home Directory (/home/magesh)`: 它表示用户家目录。 + * `shell (/bin/bash)`: 它表示用户的 bash shell。 + +如果你只想显示 `/etc/passwd` 文件中的用户名,使用以下格式: + +``` +# cut -d: -f1 /etc/passwd +root +bin +daemon +adm +lp +sync +shutdown +halt +mail +uucp +operator +games +gopher +ftp +nobody +dbus +vcsa +abrt +haldaemon +ntp +saslauth +postfix +sshd +tcpdump +centos +prakash +apache +nagios +rpc +nrpe +magesh +thanu +sudha +``` + +只显示用户的家目录,使用以下格式: + +``` +# cat /etc/passwd | grep '/home' | cut -d: -f1 +centos +prakash +magesh +thanu +sudha +``` + +### 4) 使用 finger 命令 + +`finger` 命令显示有关系统用户的信息。它显示用户的真实姓名,终端名称和写入状态(如果没有写入权限,那么最为终端名称后面的 `*`),空闲时间和登录时间。 + +``` +# finger magesh +Login: magesh Name: 2g Admin - Magesh M +Directory: /home/magesh Shell: /bin/bash +Last login Tue Jul 17 22:46 (EDT) on pts/2 from 103.5.134.167 +No mail. +No Plan. +``` + +以下是上述输出的详细信息: + + * `Login`: 用户名 + * `Name`: 附加/有关用户的其它信息 + * `Directory`: 用户家目录的信息 + * `Shell`: 用户的 shell 信息 + * `LAST-LOGIN`: 上次登录日期和其它信息 + +### 5) 使用 lslogins 命令 + +它显示系统已知用户的信息。默认情况下,它将列出系统中所有用户的信息。 + +`lslogins` 使用程序的灵感来自于 `logins` 实用程序,该实用程序最初出现在 FreeBSD 4.10 中。 + +``` +# lslogins -u +UID USER PWD-LOCK PWD-DENY LAST-LOGIN GECOS + 0 root 0 0 00:17:28 root +500 centos 0 1 Cloud User +501 prakash 0 0 Apr12/04:08 2018/04/12 +502 magesh 0 0 Jul17/22:46 2g Admin - Magesh M +503 thanu 0 0 Jul18/00:40 2g Editor - Thanisha M +504 sudha 0 0 Jul18/01:18 2g Editor - Sudha M +``` + +以下是上述输出的详细信息: + + * `UID`: 用户 id + * `USER`: 用户名 + * `PWD-LOCK`: 密码已设置,但是已锁定 + * `PWD-DENY`: 登录密码是否禁用 + * `LAST-LOGIN`: 上次登录日期 + * `GECOS`: 有关用户的其它信息 + +### 6) 使用 compgen 命令 + +`compgen` 是 bash 内置命令,它将显示所有可用的命令,别名和函数。(LCTT 译注:它的 `-u` 参数可以列出系统中用户。) + +``` +# compgen -u +root +bin +daemon +adm +lp +sync +shutdown +halt +mail +uucp +operator +games +gopher +ftp +nobody +dbus +vcsa +abrt +haldaemon +ntp +saslauth +postfix +sshd +tcpdump +centos +prakash +apache +nagios +rpc +nrpe +magesh +thanu +sudha + +``` + +-------------------------------------------------------------------------------- + +via: https://www.2daygeek.com/6-easy-ways-to-check-user-name-and-other-information-in-linux/ + +作者:[Prakash Subramanian][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[MjSeven](https://github.com/MjSeven) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.2daygeek.com/author/prakash/ +[1]:https://www.2daygeek.com/how-to-check-user-created-date-on-linux/ +[2]:https://www.2daygeek.com/how-to-check-which-groups-a-user-belongs-to-on-linux/ +[3]:https://www.2daygeek.com/how-to-force-user-to-change-password-on-next-login-in-linux/ diff --git a/published/201808/20180802 Getting started with Mu, a Python editor for beginners.md b/published/201808/20180802 Getting started with Mu, a Python editor for beginners.md new file mode 100644 index 0000000000..c405e59186 --- /dev/null +++ b/published/201808/20180802 Getting started with Mu, a Python editor for beginners.md @@ -0,0 +1,69 @@ +Mu 入门:一个面向初学者的 Python 编辑器 +====== +> 相识 Mu —— 一个可以使学生学习 Python 更轻松的开源编辑器。 + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/programming-code-keyboard-laptop-music-headphones.png?itok=EQZ2WKzy) + +Mu 是一个给初学者的 Python 编辑器,它旨在使学习体验更加愉快。它使学生​​能够在早期体验成功,这在你学习任何新知识的时候都很重要。 + +如果你曾试图教年轻人如何编程,你会立即把握到 [Mu][1] 的重要性。大多数编程工具都是由开发人员为开发人员编写的,不管他们的年龄如何,它们并不适合初学者。然而,Mu 是由老师为学生写的。 + +### Mu 的起源 + +Mu 是 [Nicholas Tollervey][2] 的心血结晶(我听过他 5 月份在 PyCon2018 上发言)。Nicholas 是一位受过古典音乐训练的音乐家,在担任音乐老师期间,他在职业生涯早期就开始对 Python 和开发感兴趣。他还写了 [Python in Education][3],这是一本可以从 O'Reilly 下载的免费书。 + +Nicholas 曾经寻找过一个更简单的 Python 编程界面。他想要一些没有其他编辑器(甚至是 Python 附带的 IDLE3 编辑器 )复杂性的东西,所以他与 Raspberry Pi 基金会(赞助他的工作)的教育总监 [Carrie Ann Philbin][4] 合作开发了 Mu 。 + +Mu 是一个用 Python 编写的开源程序(在 [GNU GPLv3][5] 许可证下)。它最初是为 [Micro:bit][6] 迷你计算机开发的,但是其他老师的反馈和请求促使他将 Mu 重写为通用的 Python 编辑器。 + +### 受音乐启发 + +Nicholas 对 Mu 的启发来自于他教授音乐的方法。他想知道如果我们按照教授音乐的方式教授编程会如何,并立即看出了差别。与编程不同,我们没有音乐训练营,我们也不会书上学习如何演奏乐器,比如说如何演奏长笛。 + +Nicholas 说,Mu “旨在成为真实的东西”,因为没有人可以在 30 分钟内学习 Python。当他开发 Mu 时,他与老师一起工作,观察编程俱乐部,并观看中学生使用 Python。他发现少即多,保持简单可以改善成品的功能。Nicholas 说,Mu 只有大约 3,000 行代码。 + +### 使用 Mu + +要尝试它,[下载][7] Mu 并按照 [Linux、Windows 和 Mac OS] [8]的简易安装说明进行操作。如果像我一样,你想[在 Raspberry Pi 上安装] [9],请在终端中输入以下内容: + +``` +$ sudo apt-get update +$ sudo apt-get install mu +``` + +从编程菜单启动 Mu。然后你就可以选择如何使用 Mu。 + +![](https://opensource.com/sites/default/files/uploads/mu_selectmode.png) + +我选择了Python 3,它启动了编写代码的环境。Python shell 直接在下面,它允许你查看代码执行。 + +![](https://opensource.com/sites/default/files/uploads/mu_writecode.png) + +菜单使用和理解非常简单,这实现了 Mu 的目标 —— 让编写代码对初学者简单。 + +在 Mu 用户的网站上可找到[教程][10]和其他资源。在网站上,你还可以看到一些帮助开发 Mu 的[志愿者][11]的名字。如果你想成为其中之一并[为 Mu 的发展做出贡献][12],我们非常欢迎您。 + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/8/getting-started-mu-python-editor-beginners + +作者:[Don Watkins][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[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/don-watkins +[1]:https://codewith.mu +[2]:https://us.pycon.org/2018/speaker/profile/194/ +[3]:https://www.oreilly.com/programming/free/python-in-education.csp +[4]:https://uk.linkedin.com/in/carrie-anne-philbin-a20649b7 +[5]:https://mu.readthedocs.io/en/latest/license.html +[6]:http://microbit.org/ +[7]:https://codewith.mu/en/download +[8]:https://codewith.mu/en/howto/install_with_python +[9]:https://codewith.mu/en/howto/install_raspberry_pi +[10]:https://codewith.mu/en/tutorials/ +[11]:https://codewith.mu/en/thanks +[12]:https://mu.readthedocs.io/en/latest/contributing.html diff --git a/published/201808/20180803 UNIX curiosities.md b/published/201808/20180803 UNIX curiosities.md new file mode 100644 index 0000000000..aca2e0c204 --- /dev/null +++ b/published/201808/20180803 UNIX curiosities.md @@ -0,0 +1,102 @@ +UNIX 的怪东西 +====== + +最近我在用我编写的各种工具做更多 UNIX 下的事情,我遇到了两个有趣的问题。这些都不是 “bug”,而是我没想到的行为。 + +### 线程安全的 printf + +我有一个 C 程序从磁盘读取一些图像,进行一些处理,并将有关这些图像的输出写入 STDOUT。伪代码: + +``` +for(imagefilename in images) +{ + results = process(imagefilename); + printf(results); +} +``` + +对于每个图像都是独立处理的,因此我自然希望将处理任务分配在各个 CPU 之间以加快速度。我通常使用 `fork()`,所以我写了这个: + +``` +for(child in children) +{ + pipe = create_pipe(); + worker(pipe); +} + +// main parent process +for(imagefilename in images) +{ + write(pipe[i_image % N_children], imagefilename) +} + +worker() +{ + while(1) + { + imagefilename = read(pipe); + results = process(imagefilename); + printf(results); + } +} +``` + +这是正常的做法:我为 IPC 创建管道,并通过这些管道给子进程 worker 发送图像名。每个 worker _能够_通过另一组管道将其结果写回主进程,但这很痛苦,所以每个 worker 都直接写入共享 STDOUT。这工作正常,但正如人们所预料的那样,对 STDOUT 的写入发生冲突,因此各种图像的结果最终会混杂在一起。那很糟糕。我不想自己设置个锁,但幸运的是 GNU libc 为它提供了函数:[flockfile()][1]。我把它们放进去了……但是没有用!为什么?因为 `flockfile()` 最终因为 `fork()` 的写时复制行为而被限制在单个子进程中。即 `fork()`提供的额外安全性(与线程相比),这实际上最终破坏了锁。 + +我没有尝试使用其他锁机制(例如 pthread 互斥锁),但我可以想象它们会遇到类似的问题。我想保持简单,所以将输出发送回父输出是不可能的:这给程序员和运行程序的计算机制造了更多的工作。 + +解决方案:使用线程而不是 `fork()`。这有制造冗余管道的好的副作用。最终的伪代码: + +``` +for(children) +{ + pthread_create(worker, child_index); +} +for(children) +{ + pthread_join(child); +} + +worker(child_index) +{ + for(i_image = child_index; i_image < N_images; i_image += N_children) + { + results = process(images[i_image]); + flockfile(stdout); + printf(results); + funlockfile(stdout); + } +} +``` + +这更简单,如预期的那样工作。我猜有时线程更好。 + +### 将部分读取的文件传递给子进程 + +对于各种 [vnlog][2] 工具,我需要实现这个操作序列: + +1. 进程打开一个关闭 `O_CLOEXEC` 标志的文件 +2. 进程读取此文件的一部分(在 vnlog 的情况下直到图例的末尾) +3. 进程调用 `exec()` 以调用另一个程序来处理已经打开的文件的其余部分 + +第二个程序可能需要命令行中的文件名而不是已打开的文件描述符,因为第二个程序可能自己调用 `​​open()`。如果我传递文件名,这个新程序将重新打开文件,然后从头开始读取文件,而不是从原始程序停止的位置开始读取。在我的程序上不可以这样做,因此将文件名传递给第二个程序是行不通的。 + +所以我真的需要以某种方式传递已经打开的文件描述符。我在使用 Linux(其他操作系统可能在这里表现不同),所以我理论上可以通过传递 `/dev/fd/N` 而不是文件名来实现。但事实证明这也不起作用。在 Linux上(再说一次,也许是特定于 Linux)对于普通文件 `/dev/fd/N` 是原始文件的符号链接。所以这最终做的是与传递文件名完全相同的事情。 + +但有一个临时方案!如果我们正在读取管道而不是文件,那么没有什么可以符号链接,并且 `/dev/fd/N` 最终将原始管道传递给第二个进程,然后程序正常工作。我可以通过将上面的 `open("filename")` 更改为 `popen("cat filename")` 之类的东西来伪装。呸!这真的是我们所能做到最好的吗?这在 BSD 上看上去会怎么样? + + +-------------------------------------------------------------------------------- + +via: http://notes.secretsauce.net/notes/2018/08/03_unix-curiosities.html + +作者:[Dima Kogan][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[geekpi](https://github.com/geekpi) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:http://notes.secretsauce.net/ +[1]:https://www.gnu.org/software/libc/manual/html_node/Streams-and-Threads.html +[2]:http://www.github.com/dkogan/vnlog diff --git a/published/201808/20180803 What data is too risky for the cloud.md b/published/201808/20180803 What data is too risky for the cloud.md new file mode 100644 index 0000000000..be50a54c83 --- /dev/null +++ b/published/201808/20180803 What data is too risky for the cloud.md @@ -0,0 +1,65 @@ +什么数据对于云服务器来说风险很大 +====== + +> 在这个关于混合多云陷阱的系列文章的最后一篇当中,让我们来学习一下如何设计一个低风险的云迁移战略。 + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/rh_003499_01_cloud21x_cc.png?itok=5UwC92dO) + +在这四篇系列文章中,我们了解到了每个组织在做云迁移的时候所应该避免的陷阱 —— 特别是混合多云的情况下。 + +[在第一部分][1],我们介绍了一些基本的定义以及我们对于混合云以及多云的观点,确保展示了两者之间的区别。[在第二部分][2],我们会对三个陷阱之一进行讨论:为什么成本并不是迁移到云端的显然的推动因素。而且,[在第三部分][3],我们考察了将所有工作向云端进行迁移的可行性。 + +最后,在这个第四部分中,我们来看看数据上云要做什么。您应该把数据向云端迁移吗?迁移多少?什么数据可以放在云端?又是什么会造成上云风险很大? + +### 数据…数据…数据 + +影响您对云端数据的所有决策的关键因素在于确定您的带宽以及存储需求。 Gartner 预计 “数据存储在 2018 年将成为一项[$173 亿美元][4]的业务”,并且大部分资金是浪费在一些不必要的存储容量上:“但是只需要优化一下工作负载,全球的所有公司就可以节约 620 亿美元的不必要 IT 成本。”根据 Gartner 的研究,非常令人惊讶的是,全球所有的公司“为云服务器平均支付的费用比他们实际的费用多达 36% 。” + +如果你已经阅读了本系列的前三个章节,那么你应该不会为此感到惊讶。然而令人更惊讶的是 Gartner 的结论是 “如果全球的公司将他们的服务器数据直接迁移到云端上,仅仅只有 25% 的公司能够做到省钱。” + +等一下……工作负载是可以针对云进行优化的,但是只有一小部分公司能通过将数据向云端迁移而节省资金吗?这个又是什么意思? + +如果你去认为云服务商会根据带宽来收取云产生的费用,那么将所有的公司内部数据移至云端很快就会成为他们的成本负担。在以下三种情况,公司才可能会觉得值得把数据放在云端中: + + * 单个云包括存储和应用程序 + * 应用程序在云端,存储在本地 + * 应用程序在云端,而且数据缓存也在云端,存储在本地 + +在第一种情况下,通过将所有的内容都放在单个云服务商来节省带宽成本,但是这会产生一些(供应商)锁定,这个通常与 CIO 的云战略或者风险防范计划所冲突。 + +第二种方案是仅仅保留应用程序在云端所收集的数据,并且以最小的方式传输到本地存储。这就需要仔细的考虑策略,其中只有最少使用数据的应用程序部署在云端。 + +第三种情况就是将数据缓存在云端,应用程序和存储的数据被存储在本地。这也就意味着分析、人工智能、机器学习可以在内部运行而无需把数据向云服务商上传,然后处理之后再返回。缓存的数据仅仅基于应用程序对云的需求,甚至进行跨多云的部署缓存。 + +要想获得更多信息,请下载红帽[案例研究][5],其中描述了跨混合多云环境下的阿姆斯特丹的史基浦机场的数据以及云和部署策略。 + +### 数据危险 + +大多数公司都认识到了他们的数据是在其市场中的专有优势以及知识能力。因此他们会非常仔细的考虑它在云存储的地点。 + +想象一下这种情况:如果你是一个零售商,全球十大零售商之一。而且你已经计划了很长一段时间云存储战略,并且考虑使用亚马逊的云服务。但是突然间, [亚马逊收购了全食超市][6],并且准备进入你的市场。 + +一夜之间,亚马逊已经增长了 50% 的零售规模,你是否还会去信任把零售数据放到他们的云上?如果您的数据已经就在亚马逊云中,你会打算怎么做?您创建云计划时是否考虑过退出策略?虽然亚马逊可能永远不会去利用您的数据潜在价值 —— 该公司可能甚至有针对此的条款 —— 但你能相信世界上任何人的话吗? + +### 陷阱分享,避免陷阱 + +分享我们在以前经验中看到的一些陷阱来帮助您的公司规划更安全、更持久的云端策略。了解了[成本不是显然的推动因素][2],[并非一切东西都应该在云端][3],而是你必须在云端有效管理数据才是您成功的关键所在。 + + +-------------------------------------------------------------------------------- +via: https://opensource.com/article/18/8/data-risky-cloud + +作者:[Eric D.Schabell][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[geekmar](https://github.com/geekmar) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://opensource.com/users/eschabell +[1]:https://opensource.com/article/18/4/pitfalls-hybrid-multi-cloud +[2]:https://opensource.com/article/18/6/reasons-move-to-cloud +[3]:https://opensource.com/article/18/7/why-you-cant-move-everything-cloud +[4]:http://www.businessinsider.com/companies-waste-62-billion-on-the-cloud-by-paying-for-storage-they-dont-need-according-to-a-report-2017-11 +[5]:https://www.redhat.com/en/resources/amsterdam-airport-schiphol-case-study +[6]:https://www.forbes.com/sites/ciocentral/2017/06/23/amazon-buys-whole-foods-now-what-the-story-behind-the-story/#33e9cc6be898 diff --git a/published/201808/20180803 Why I still love Alpine for email at the Linux terminal.md b/published/201808/20180803 Why I still love Alpine for email at the Linux terminal.md new file mode 100644 index 0000000000..0c8cbe85f6 --- /dev/null +++ b/published/201808/20180803 Why I still love Alpine for email at the Linux terminal.md @@ -0,0 +1,81 @@ +为什么我仍然喜欢用 Alpine 在 Linux 终端中发送电子邮件 +====== + +> 这个免费的邮件客户端使用直观、易于定制,并且可以在许多操作系统上使用。 + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/email_paper_envelope_document.png?itok=uPj_kouJ) + +也许你有这个经历:你试了一个程序,并且很喜欢它。多年后,有新的程序开发出来,它可以做同样的事情或者更多,甚至更好。你试了下它们,它们也很棒 —— 但你会继续使用第一个程序。 + +这是我与 [Alpine Mail][1] 关系的故事。所以我决定写一篇赞美我最喜欢的邮件程序的文章。 + +![alpine_main_menu.png][3] + +*Alpine 邮件客户端的主菜单屏幕* + +在 90 年代中期,我发现了 [GNU/Linux][4] 操作系统。因为我之前从未见过类 Unix 的系统,所以我阅读了大量的文档和书籍,并尝试了很多程序来熟悉这个迷人的系统。 + +没多久,[Pine][5] 成了我最喜欢的邮件客户端,其后是其继任者 Alpine。我发现它直观且易于使用 —— 你始终可以在底部看到可能的命令或选项,因此引导很容易快速学习,并且 Alpine 提供了很好的帮助。 + +入门很容易。 + +大多数发行版包含 Alpine。它可以通过包管理器安装。 + +只需按下 `S`(或移动高亮栏到“设置”那一行)你就会看到可以配置的项目。在底部,你可以使用快捷键来执行你可以立即执行的命令。对于其他命令,按下 `O`(“其他命令”)。 + +按下 `S` 进入配置对话框。当你向下滚动列表时,很明显你可以设置 Apline 如你所希望的那样运行。如果你只有一个邮件帐户,只需移动到你想要更改的行,按下 `C`(“更改值”),然后输入值: + +![alpine_setup_configuration.png][7] + +*Alpine 设置配置屏幕* + +请注意如何输入 SNMP 和 IMAP 服务器,因为这与那些有辅助助手和预填字段的邮件客户端不同。如果你像这样输入“服务器/SSL/用户”: + +``` +imap.myprovider.com:993/ssl/user=max@example.com +``` + +Alpine 会询问你是否使用“收件箱”(选择“是”)并在“服务器”两边加上大括号。完成后,按下 `E`(“退出设置”)并按下 `Y`(“是”)提交更改。回到主菜单,然后你可以移动到文件夹列表和收件箱以查看是否有邮件(系统将提示你输入密码)。你现在可以使用 `>` 和 `<` 进行移动。 + +![navigating_the_message_index.png][9] + +*在 Apline 中浏览消息索引* + +要撰写邮件,只需移动到相应的菜单并编写即可。请注意,底部的选项会根据你所在的行而变化。`^T`(`Ctrl + T`)可代表 To Addressbook(“地址簿”)或 To Files(“文件”)。要附加文件,只需移动到 Attchmt:(“附件”)然后按 `Ctrl + T` 转到文件浏览器,或按 `Ctrl + J` 输入路径。 + +用 `^X` 发送邮件。 + +![composing_an_email_in_alpine.png][11] + +在 Alpine 中撰写电子邮件 + +### 为何选择 Alpine? + +当然,每个用户的个人偏好和需求都是不同的。如果你需要一个更像 “office” 的解决方案,像 Evolution 或 Thunderbird 这样的应用可能是更好的选择。 + +但对我来说,Alpine(和 Pine)是软件界的活化石。你可以以舒适的方式管理邮件 —— 不多也不少。它适用于许多操作系统(甚至 [Termux for Android][12])。并且因为配置存储在纯文本文件(`.pinerc`)中,所以你只需将其复制到设备即可。 + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/8/love-alpine + +作者:[Heiko Ossowski][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[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/hossow +[1]:https://en.wikipedia.org/wiki/Alpine_(email_client) +[2]:/file/405641 +[3]:https://opensource.com/sites/default/files/uploads/alpine_main_menu.png (alpine_main_menu.png) +[4]:https://www.gnu.org/gnu/linux-and-gnu.en.html +[5]:https://en.wikipedia.org/wiki/Pine_(email_client) +[6]:/file/405646 +[7]:https://opensource.com/sites/default/files/uploads/alpine_setup_configuration.png (alpine_setup_configuration.png) +[8]:/file/405651 +[9]:https://opensource.com/sites/default/files/uploads/navigating_the_message_index.png (navigating_the_message_index.png) +[10]:/file/405656 +[11]:https://opensource.com/sites/default/files/uploads/composing_an_email_in_alpine.png (composing_an_email_in_alpine.png) +[12]:https://termux.com/ diff --git a/published/201808/20180806 A gawk script to convert smart quotes.md b/published/201808/20180806 A gawk script to convert smart quotes.md new file mode 100644 index 0000000000..52c94c39cb --- /dev/null +++ b/published/201808/20180806 A gawk script to convert smart quotes.md @@ -0,0 +1,151 @@ +一个转换花引号的 gawk 脚本 +====== + +> 下载我的 awk 秘籍。 + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/osdc_520x292_opensourceprescription.png?itok=gFrc_GTH) + +我管理着一个个人网站,用手工编辑网站上的网页。由于网站上的页面并不多,这种方法对我很适合,可以让我对网站代码的细节一清二楚。 + +最近我升级了网站的设计样式,我决定把所有的普通引号都转换成“花引号”,即在打印材料中使用的那种引号:用 “” 来代替 ""。 + +手工修改所有的引号太耗时了,因此我决定将这个转换所有 HTML 文件中引号的过程自动化。不过通过程序或脚本来实现该功能需要费点劲。这个脚本需要知道何时将普通引号转换成花引号,并决定使用哪种引号(LCTT 译注:左引号还是右引号,单引号还是双引号)。 + +有多种方法可以转换引号。Greg Pittman 写过一个 [Python 脚本][1] 来修正文本中的花引号。而我自己使用 GNU [awk][2] (gawk) 来实现。 + +> 下载我的 awk 秘籍。[免费下载][3]。 + +开始之前,我写了一个简单的 gawk 函数来评估单个字符。若该字符是一个引号,这该函数判断是输出普通引号还是花引号。函数查看前一个字符;若前一个字符是空格,则函数输出左花引号。否则函数输出右花引号。脚本对单引号的处理方式也一样。 + +``` +function smartquote (char, prevchar) { +        # print smart quotes depending on the previous character +        # otherwise just print the character as-is + +        if (prevchar ~ /\s/) { +                # prev char is a space +                if (char == "'") { +                        printf("‘"); +                } +                else if (char == "\"") { +                        printf("“"); +                } +                else { +                        printf("%c", char); +                } +        } +        else { +                # prev char is not a space +                if (char == "'") { +                        printf("’"); +                } +                else if (char == "\"") { +                        printf("”"); +                } +                else { +                        printf("%c", char); +                } +        } +} +``` + +这个 gawk 脚本的主体部分通过该函数处理 HTML 输入文件的一个个字符。该脚本在 HTML 标签内部逐字原样输出所有内容(比如,``)。在 HTML 标签外,脚本使用 `smartquote()` 函数来输出文本。`smartquote()` 函数来评估是输出普通引号还是花引号。 + +``` +function smartquote (char, prevchar) { +        ... +} + +BEGIN {htmltag = 0} + +{ +        # for each line, scan one letter at a time: + +        linelen = length($0); + +        prev = "\n"; + +        for (i = 1; i <= linelen; i++) { +                char = substr($0, i, 1); + +                if (char == "<") { +                        htmltag = 1; +                } + +                if (htmltag == 1) { +                        printf("%c", char); +                } +                else { +                        smartquote(char, prev); +                        prev = char; +                } + +                if (char == ">") { +                        htmltag = 0; +                } +        } + +        # add trailing newline at end of each line +        printf ("\n"); +} +``` + +下面是一个例子: + +``` +gawk -f quotes.awk test.html > test2.html +``` + +其输入为: + +``` + + + +  Test page + + + 

Website logo

"Hi there!"

It's and its.

+ + +``` + +其输出为: + +``` + + + +  Test page + + + 

Website logo

“Hi there!”

It’s and its.

+ + +``` + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/8/gawk-script-convert-smart-quotes + +作者:[Jim Hall][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[lujun9972](https://github.com/lujun9972) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://opensource.com/users/jim-hall +[1]:https://opensource.com/article/17/3/python-scribus-smart-quotes +[2]:https://opensource.com/downloads/cheat-sheet-awk-features +[3]:https://opensource.com/downloads/cheat-sheet-awk-features diff --git a/published/201808/20180806 Learn Python programming the easy way with EduBlocks.md b/published/201808/20180806 Learn Python programming the easy way with EduBlocks.md new file mode 100644 index 0000000000..b84cac0dc3 --- /dev/null +++ b/published/201808/20180806 Learn Python programming the easy way with EduBlocks.md @@ -0,0 +1,77 @@ +使用 EduBlocks 轻松学习 Python 编程 +====== + +> EduBlocks 提供了 Scratch 式的图形界面来编写 Python 3 代码。 + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/blocks_building.png?itok=eMOT-ire) + +如果你正在寻找一种方法将你的学生(或你自己)从使用 [Scratch][1] 编程转移到学习 [Python][2],我建议你了解一下 [EduBlocks][3]。它为 Python 3 编程带来了熟悉的拖放式图形用户界面(GUI)。 + +从 Scratch 过渡到 Python 的一个障碍是缺少拖放式 GUI,而正是这种拖放式 GUI 使得 Scratch 成为 K-12 学校的首选程序。EduBlocks 的拖放版的 Python 3 改变了这种范式。它的目的是“帮助教师在较早的时候向儿童介绍基于文本的编程语言,如 Python。” + +EduBlocks 的硬件要求非常适中 —— 一个树莓派和一条互联网连接 —— 应该可以在许多教室中使用。 + +EduBlocks 是由来自英国的 14 岁 Python 开发人员 Joshua Lowe 开发的。我看到 Joshua 在 2018 年 5 月的 [PyCon 2018][4] 上展示了他的项目。 + +### 入门 + +安装 EduBlocks 很容易。该网站提供了清晰的安装说明,你可以在项目的 [GitHub][5] 仓库中找到详细的截图。 + +使用以下命令在 Raspberry Pi 命令行安装 EduBlocks: + +``` +curl -sSL get.edublocks.org | bash +``` + +### 在 EduBlocks 中编程 + +安装完成后,从桌面快捷方式或 Raspberry Pi 上的“编程”菜单启动 EduBlocks。 + +![](https://opensource.com/sites/default/files/uploads/edublocks_programming-menu.png) + +启动程序后,你可以使用 EduBlocks 的拖放界面开始创建 Python 3 代码。它的菜单有清晰的标签。你可以通过单击 **Samples** 菜单按钮使用示例代码。你还可以通过单击 **Theme** 为你的编程界面选择不同的配色方案。使用 **Save** 菜单,你可以保存你的作品,然后 **Download** 你的 Python 代码。单击 **Run** 来执行并测试你的代码。 + +你可以通过单击最右侧的 **Blockly** 按钮来查看代码。它让你在 ”Blockly” 界面和普通的 Python 代码视图之间切换(正如你在任何其他 Python 编辑器中看到的那样)。 + +![](https://opensource.com/sites/default/files/uploads/edublocks_blockly.png) + +EduBlocks 附带了一系列代码库,包括 [EduPython][6]、[Minecraft] [7]、[Sonic Pi] [8]、[GPIO Zero][9] 和 [Sense Hat][10]。 + +### 学习和支持 + +该项目维护了一个[学习门户网站][11],其中包含教程和其他资源,可以轻松地 [hack][12] 树莓派版本的 Minecraft,编写 GPIOZero 和 Sonic Pi,并使用 Micro:bit 代码编辑器控制 LED。可以在 Twitter [@edu_blocks][13] 和 [@all_about_code][14] 以及 [email][15] 提供对 EduBlocks 的支持。 + +为了更深入的了解,你可以在 [GitHub][16] 上访问 EduBlocks 的源代码。该程序在 GNU Affero Public License v3.0 下[许可][17]。EduBlocks 的创建者(项目负责人 [Joshua Lowe][18] 和开发人员 [Chris Dell][19] 和 [Les Pounder][20])希望它成为一个社区项目,并邀请人们提出问题,提供反馈,以及提交 pull request 以向项目添加功能或修复。 + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/8/edublocks + +作者:[Don Watkins][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[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/don-watkins +[1]:https://scratch.mit.edu/ +[2]:https://www.python.org/ +[3]:https://edublocks.org/ +[4]:https://us.pycon.org/2018/about/ +[5]:https://github.com/AllAboutCode/EduBlocks +[6]:https://edupython.tuxfamily.org/ +[7]:https://minecraft.net/en-us/edition/pi/ +[8]:https://sonic-pi.net/ +[9]:https://gpiozero.readthedocs.io/en/stable/ +[10]:https://www.raspberrypi.org/products/sense-hat/ +[11]:https://edublocks.org/learn.html +[12]:https://edublocks.org/resources/1.pdf +[13]:https://twitter.com/edu_blocks?lang=en +[14]:https://twitter.com/all_about_code +[15]:mailto:support@edublocks.org +[16]:https://github.com/allaboutcode/edublocks +[17]:https://github.com/AllAboutCode/EduBlocks/blob/tarball-install/LICENSE +[18]:https://github.com/JoshuaLowe1002 +[19]:https://twitter.com/cjdell?lang=en +[20]:https://twitter.com/biglesp?lang=en diff --git a/published/201808/20180806 What is CI-CD.md b/published/201808/20180806 What is CI-CD.md new file mode 100644 index 0000000000..66f0d104f5 --- /dev/null +++ b/published/201808/20180806 What is CI-CD.md @@ -0,0 +1,209 @@ +什么是 CI/CD? +====== + +在软件开发中经常会提到持续集成Continuous Integration(CI)和持续交付Continuous Delivery(CD)这几个术语。但它们真正的意思是什么呢? + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/fail_progress_cycle_momentum_arrow.png?itok=q-ZFa_Eh) + +在谈论软件开发时,经常会提到持续集成Continuous Integration(CI)和持续交付Continuous Delivery(CD)这几个术语。但它们真正的意思是什么呢?在本文中,我将解释这些和相关术语背后的含义和意义,例如持续测试Continuous Testing持续部署Continuous Deployment。 + +### 概览 + +工厂里的装配线以快速、自动化、可重复的方式从原材料生产出消费品。同样,软件交付管道以快速、自动化和可重复的方式从源代码生成发布版本。如何完成这项工作的总体设计称为“持续交付”(CD)。启动装配线的过程称为“持续集成”(CI)。确保质量的过程称为“持续测试”,将最终产品提供给用户的过程称为“持续部署”。一些专家让这一切简单、顺畅、高效地运行,这些人被称为运维开发DevOps践行者。 + +### “持续”是什么意思? + +“持续”用于描述遵循我在此提到的许多不同流程实践。这并不意味着“一直在运行”,而是“随时可运行”。在软件开发领域,它还包括几个核心概念/最佳实践。这些是: + +* **频繁发布**:持续实践背后的目标是能够频繁地交付高质量的软件。此处的交付频率是可变的,可由开发团队或公司定义。对于某些产品,一季度、一个月、一周或一天交付一次可能已经足够频繁了。对于另一些来说,一天可能需要多次交付也是可行的。所谓持续也有“偶尔、按需”的方面。最终目标是相同的:在可重复、可靠的过程中为最终用户提供高质量的软件更新。通常,这可以通过很少甚至无需用户的交互或掌握的知识来完成(想想设备更新)。 +* **自动化流程**:实现此频率的关键是用自动化流程来处理软件生产中的方方面面。这包括构建、测试、分析、版本控制,以及在某些情况下的部署。 +* **可重复**:如果我们使用的自动化流程在给定相同输入的情况下始终具有相同的行为,则这个过程应该是可重复的。也就是说,如果我们把某个历史版本的代码作为输入,我们应该得到对应相同的可交付产出。这也假设我们有相同版本的外部依赖项(即我们不创建该版本代码使用的其它交付物)。理想情况下,这也意味着可以对管道中的流程进行版本控制和重建(请参阅稍后的 DevOps 讨论)。 +* **快速迭代**:“快速”在这里是个相对术语,但无论软件更新/发布的频率如何,预期的持续过程都会以高效的方式将源代码转换为交付物。自动化负责大部分工作,但自动化处理的过程可能仍然很慢。例如,对于每天需要多次发布候选版更新的产品来说,一轮集成测试integrated testing下来耗时就要大半天可能就太慢了。 + +### 什么是“持续交付管道”? + +将源代码转换为可发布产品的多个不同的任务task作业job通常串联成一个软件“管道”,一个自动流程成功完成后会启动管道中的下一个流程。这些管道有许多不同的叫法,例如持续交付管道、部署管道和软件开发管道。大体上讲,程序管理者在管道执行时管理管道各部分的定义、运行、监控和报告。 + +### 持续交付管道是如何工作的? + +软件交付管道的实际实现可以有很大不同。有许多程序可用在管道中,用于源代码跟踪、构建、测试、指标采集,版本管理等各个方面。但整体工作流程通常是相同的。单个业务流程/工作流应用程序管理整个管道,每个流程作为独立的作业运行或由该应用程序进行阶段管理。通常,在业务流程中,这些独立作业是以应用程序可理解并可作为工作流程管理的语法和结构定义的。 + +这些作业被用于一个或多个功能(构建、测试、部署等)。每个作业可能使用不同的技术或多种技术。关键是作业是自动化的、高效的,并且可重复的。如果作业成功,则工作流管理器将触发管道中的下一个作业。如果作业失败,工作流管理器会向开发人员、测试人员和其他人发出警报,以便他们尽快纠正问题。这个过程是自动化的,所以比手动运行一组过程可更快地找到错误。这种快速排错称为快速失败fail fast,并且在抵达管道端点方面同样有价值。 + +### “快速失败”是什么意思? + +管道的工作之一就是快速处理变更。另一个是监视创建发布的不同任务/作业。由于编译失败或测试未通过的代码可以阻止管道继续运行,因此快速通知用户此类情况非常重要。快速失败指的是在管道流程中尽快发现问题并快速通知用户的方式,这样可以及时修正问题并重新提交代码以便使管道再次运行。通常在管道流程中可通过查看历史记录来确定是谁做了那次修改并通知此人及其团队。 + +### 所有持续交付管道都应该被自动化吗? + +管道的几乎所有部分都是应该自动化的。对于某些部分,有一些人为干预/互动的地方可能是有意义的。一个例子可能是用户验收测试user-acceptance testing(让最终用户试用软件并确保它能达到他们想要/期望的水平)。另一种情况可能是部署到生产环境时用户希望拥有更多的人为控制。当然,如果代码不正确或不能运行,则需要人工干预。 + +有了对“持续”含义理解的背景,让我们看看不同类型的持续流程以及它们在软件管道上下文中的含义。 + +### 什么是“持续集成”? + +持续集成(CI)是在源代码变更后自动检测、拉取、构建和(在大多数情况下)进行单元测试的过程。持续集成是启动管道的环节(尽管某些预验证 —— 通常称为上线前检查pre-flight checks —— 有时会被归在持续集成之前)。 + +持续集成的目标是快速确保开发人员新提交的变更是好的,并且适合在代码库中进一步使用。 + +### 持续集成是如何工作的? + +持续集成的基本思想是让一个自动化过程监测一个或多个源代码仓库是否有变更。当变更被推送到仓库时,它会监测到更改、下载副本、构建并运行任何相关的单元测试。 + +### 持续集成如何监测变更? + +目前,监测程序通常是像 [Jenkins][1] 这样的应用程序,它还协调管道中运行的所有(或大多数)进程,监视变更是其功能之一。监测程序可以以几种不同方式监测变更。这些包括: + +* **轮询**:监测程序反复询问代码管理系统,“代码仓库里有什么我感兴趣的新东西吗?”当代码管理系统有新的变更时,监测程序会“唤醒”并完成其工作以获取新代码并构建/测试它。 +* **定期**:监测程序配置为定期启动构建,无论源码是否有变更。理想情况下,如果没有变更,则不会构建任何新内容,因此这不会增加额外的成本。 +* **推送**:这与用于代码管理系统检查的监测程序相反。在这种情况下,代码管理系统被配置为提交变更到仓库时将“推送”一个通知到监测程序。最常见的是,这可以以 webhook 的形式完成 —— 在新代码被推送时一个挂勾hook的程序通过互联网向监测程序发送通知。为此,监测程序必须具有可以通过网络接收 webhook 信息的开放端口。 + +### 什么是“预检查”(又称“上线前检查”)? + +在将代码引入仓库并触发持续集成之前,可以进行其它验证。这遵循了最佳实践,例如测试构建test build代码审查code review。它们通常在代码引入管道之前构建到开发过程中。但是一些管道也可能将它们作为其监控流程或工作流的一部分。 + +例如,一个名为 [Gerrit][2] 的工具允许在开发人员推送代码之后但在允许进入([Git][3] 远程)仓库之前进行正式的代码审查、验证和测试构建。Gerrit 位于开发人员的工作区和 Git 远程仓库之间。它会“接收”来自开发人员的推送,并且可以执行通过/失败验证以确保它们在被允许进入仓库之前的检查是通过的。这可以包括检测新变更并启动构建测试(CI 的一种形式)。它还允许开发者在那时进行正式的代码审查。这种方式有一种额外的可信度评估机制,即当变更的代码被合并到代码库中时不会破坏任何内容。 + +### 什么是“单元测试”? + +单元测试(也称为“提交测试”),是由开发人员编写的小型的专项测试,以确保新代码独立工作。“独立”这里意味着不依赖或调用其它不可直接访问的代码,也不依赖外部数据源或其它模块。如果运行代码需要这样的依赖关系,那么这些资源可以用模拟mock来表示。模拟是指使用看起来像资源的代码存根code stub,可以返回值,但不实现任何功能。 + +在大多数组织中,开发人员负责创建单元测试以证明其代码正确。事实上,一种称为测试驱动开发test-driven develop(TDD)的模型要求将首先设计单元测试作为清楚地验证代码功能的基础。因为这样的代码可以更改速度快且改动量大,所以它们也必须执行很快。 + +由于这与持续集成工作流有关,因此开发人员在本地工作环境中编写或更新代码,并通单元测试来确保新开发的功能或方法正确。通常,这些测试采用断言形式,即函数或方法的给定输入集产生给定的输出集。它们通常进行测试以确保正确标记和处理出错条件。有很多单元测试框架都很有用,例如用于 Java 开发的 [JUnit][4]。 + +### 什么是“持续测试”? + +持续测试是指在代码通过持续交付管道时运行扩展范围的自动化测试的实践。单元测试通常与构建过程集成,作为持续集成阶段的一部分,并专注于和其它与之交互的代码隔离的测试。 + +除此之外,可以有或者应该有各种形式的测试。这些可包括: + +* **集成测试** 验证组件和服务组合在一起是否正常。 +* **功能测试** 验证产品中执行功能的结果是否符合预期。 +* **验收测试** 根据可接受的标准验证产品的某些特征。如性能、可伸缩性、抗压能力和容量。 + +所有这些可能不存在于自动化的管道中,并且一些不同类型的测试分类界限也不是很清晰。但是,在交付管道中持续测试的目标始终是相同的:通过持续的测试级别证明代码的质量可以在正在进行的发布中使用。在持续集成快速的原则基础上,第二个目标是快速发现问题并提醒开发团队。这通常被称为快速失败。 + +### 除了测试之外,还可以对管道中的代码进行哪些其它类型的验证? + +除了测试是否通过之外,还有一些应用程序可以告诉我们测试用例执行(覆盖)的源代码行数。这是一个可以衡量代码量指标的例子。这个指标称为代码覆盖率code-coverage,可以通过工具(例如用于 Java 的 [JaCoCo][5])进行统计。 + +还有很多其它类型的指标统计,例如代码行数、复杂度以及代码结构对比分析等。诸如 [SonarQube][6] 之类的工具可以检查源代码并计算这些指标。此外,用户还可以为他们可接受的“合格”范围的指标设置阈值。然后可以在管道中针对这些阈值设置一个检查,如果结果不在可接受范围内,则流程终端上。SonarQube 等应用程序具有很高的可配置性,可以设置仅检查团队感兴趣的内容。 + +### 什么是“持续交付”? + +持续交付(CD)通常是指整个流程链(管道),它自动监测源代码变更并通过构建、测试、打包和相关操作运行它们以生成可部署的版本,基本上没有任何人为干预。 + +持续交付在软件开发过程中的目标是自动化、效率、可靠性、可重复性和质量保障(通过持续测试)。 + +持续交付包含持续集成(自动检测源代码变更、执行构建过程、运行单元测试以验证变更),持续测试(对代码运行各种测试以保障代码质量),和(可选)持续部署(通过管道发布版本自动提供给用户)。 + +### 如何在管道中识别/跟踪多个版本? + +版本控制是持续交付和管道的关键概念。持续意味着能够经常集成新代码并提供更新版本。但这并不意味着每个人都想要“最新、最好的”。对于想要开发或测试已知的稳定版本的内部团队来说尤其如此。因此,管道创建并轻松存储和访问的这些版本化对象非常重要。 + +在管道中从源代码创建的对象通常可以称为工件artifact。工件在构建时应该有应用于它们的版本。将版本号分配给工件的推荐策略称为语义化版本控制semantic versioning。(这也适用于从外部源引入的依赖工件的版本。) + +语义版本号有三个部分:主要版本major次要版本minor补丁版本patch。(例如,1.4.3 反映了主要版本 1,次要版本 4 和补丁版本 3。)这个想法是,其中一个部分的更改表示工件中的更新级别。主要版本仅针对不兼容的 API 更改而递增。当以向后兼容backward-compatible的方式添加功能时,次要版本会增加。当进行向后兼容的版本 bug 修复时,补丁版本会增加。这些是建议的指导方针,但只要团队在整个组织内以一致且易于理解的方式这样做,团队就可以自由地改变这种方法。例如,每次为发布完成构建时增加的数字可以放在补丁字段中。 + +### 如何“分销”工件? + +团队可以为工件分配分销promotion级别以指示适用于测试、生产等环境或用途。有很多方法。可以用 Jenkins 或 [Artifactory][7] 等应用程序进行分销。或者一个简单的方案可以在版本号字符串的末尾添加标签。例如,`-snapshot` 可以指示用于构建工件的代码的最新版本(快照)。可以使用各种分销策略或工具将工件“提升”到其它级别,例如 `-milestone` 或 `-production`,作为工件稳定性和完备性版本的标记。 + +### 如何存储和访问多个工件版本? + +从源代码构建的版本化工件可以通过管理工件仓库artifact repository的应用程序进行存储。工件仓库就像构建工件的版本控制工具一样。像 Artifactory 或 [Nexus][8] 这类应用可以接受版本化工件,存储和跟踪它们,并提供检索的方法。 + +管道用户可以指定他们想要使用的版本,并在这些版本中使用管道。 + +### 什么是“持续部署”? + +持续部署(CD)是指能够自动提供持续交付管道中发布版本给最终用户使用的想法。根据用户的安装方式,可能是在云环境中自动部署、app 升级(如手机上的应用程序)、更新网站或只更新可用版本列表。 + +这里的一个重点是,仅仅因为可以进行持续部署并不意味着始终部署来自管道的每组可交付成果。它实际上指,通过管道每套可交付成果都被证明是“可部署的”。这在很大程度上是由持续测试的连续级别完成的(参见本文中的持续测试部分)。 + +管道构建的发布成果是否被部署可以通过人工决策,或利用在完全部署之前“试用”发布的各种方法来进行控制。 + +### 在完全部署到所有用户之前,有哪些方法可以测试部署? + +由于必须回滚/撤消对所有用户的部署可能是一种代价高昂的情况(无论是技术上还是用户的感知),已经有许多技术允许“尝试”部署新功能并在发现问题时轻松“撤消”它们。这些包括: + +#### 蓝/绿测试/部署 + +在这种部署软件的方法中,维护了两个相同的主机环境 —— 一个“蓝色” 和一个“绿色”。(颜色并不重要,仅作为标识。)对应来说,其中一个是“生产环境”,另一个是“预发布环境”。 + +在这些实例的前面是调度系统,它们充当产品或应用程序的客户“网关”。通过将调度系统指向蓝色或绿色实例,可以将客户流量引流到期望的部署环境。通过这种方式,切换指向哪个部署实例(蓝色或绿色)对用户来说是快速,简单和透明的。 + +当新版本准备好进行测试时,可以将其部署到非生产环境中。在经过测试和批准后,可以更改调度系统设置以将传入的线上流量指向它(因此它将成为新的生产站点)。现在,曾作为生产环境实例可供下一次候选发布使用。 + +同理,如果在最新部署中发现问题并且之前的生产实例仍然可用,则简单的更改可以将客户流量引流回到之前的生产实例 —— 有效地将问题实例“下线”并且回滚到以前的版本。然后有问题的新实例可以在其它区域中修复。 + +#### 金丝雀测试/部署 + +在某些情况下,通过蓝/绿发布切换整个部署可能不可行或不是期望的那样。另一种方法是为金丝雀canary测试/部署。在这种模型中,一部分客户流量被重新引流到新的版本部署中。例如,新版本的搜索服务可以与当前服务的生产版本一起部署。然后,可以将 10% 的搜索查询引流到新版本,以在生产环境中对其进行测试。 + +如果服务那些流量的新版本没问题,那么可能会有更多的流量会被逐渐引流过去。如果仍然没有问题出现,那么随着时间的推移,可以对新版本增量部署,直到 100% 的流量都调度到新版本。这有效地“更替”了以前版本的服务,并让新版本对所有客户生效。 + +#### 功能开关 + +对于可能需要轻松关掉的新功能(如果发现问题),开发人员可以添加功能开关feature toggles。这是代码中的 `if-then` 软件功能开关,仅在设置数据值时才激活新代码。此数据值可以是全局可访问的位置,部署的应用程序将检查该位置是否应执行新代码。如果设置了数据值,则执行代码;如果没有,则不执行。 + +这为开发人员提供了一个远程“终止开关”,以便在部署到生产环境后发现问题时关闭新功能。 + +#### 暗箱发布 + +在暗箱发布dark launch中,代码被逐步测试/部署到生产环境中,但是用户不会看到更改(因此名称中有暗箱dark一词)。例如,在生产版本中,网页查询的某些部分可能会重定向到查询新数据源的服务。开发人员可收集此信息进行分析,而不会将有关接口,事务或结果的任何信息暴露给用户。 + +这个想法是想获取候选版本在生产环境负载下如何执行的真实信息,而不会影响用户或改变他们的经验。随着时间的推移,可以调度更多负载,直到遇到问题或认为新功能已准备好供所有人使用。实际上功能开关标志可用于这种暗箱发布机制。 + +### 什么是“运维开发”? + +[运维开发][9]DevOps 是关于如何使开发和运维团队更容易合作开发和发布软件的一系列想法和推荐的实践。从历史上看,开发团队研发了产品,但没有像客户那样以常规、可重复的方式安装/部署它们。在整个周期中,这组安装/部署任务(以及其它支持任务)留给运维团队负责。这经常导致很多混乱和问题,因为运维团队在后期才开始介入,并且必须在短时间内完成他们的工作。同样,开发团队经常处于不利地位 —— 因为他们没有充分测试产品的安装/部署功能,他们可能会对该过程中出现的问题感到惊讶。 + +这往往导致开发和运维团队之间严重脱节和缺乏合作。DevOps 理念主张是贯穿整个开发周期的开发和运维综合协作的工作方式,就像持续交付那样。 + +### 持续交付如何与运维开发相交? + +持续交付管道是几个 DevOps 理念的实现。产品开发的后期阶段(如打包和部署)始终可以在管道的每次运行中完成,而不是等待产品开发周期中的特定时间。同样,从开发到部署过程中,开发和运维都可以清楚地看到事情何时起作用,何时不起作用。要使持续交付管道循环成功,不仅要通过与开发相关的流程,还要通过与运维相关的流程。 + +说得更远一些,DevOps 建议实现管道的基础架构也会被视为代码。也就是说,它应该自动配置、可跟踪、易于修改,并在管道发生变化时触发新一轮运行。这可以通过将管道实现为代码来完成。 + +### 什么是“管道即代码”? + +管道即代码pipeline-as-code是通过编写代码创建管道作业/任务的通用术语,就像开发人员编写代码一样。它的目标是将管道实现表示为代码,以便它可以与代码一起存储、评审、跟踪,如果出现问题并且必须终止管道,则可以轻松地重建。有几个工具允许这样做,如 [Jenkins 2][1]。 + +### DevOps 如何影响生产软件的基础设施? + +传统意义上,管道中使用的各个硬件系统都有配套的软件(操作系统、应用程序、开发工具等)。在极端情况下,每个系统都是手工设置来定制的。这意味着当系统出现问题或需要更新时,这通常也是一项自定义任务。这种方法违背了持续交付的基本理念,即具有易于重现和可跟踪的环境。 + +多年来,很多应用被开发用于标准化交付(安装和配置)系统。同样,虚拟机virtual machine被开发为模拟在其它计算机之上运行的计算机程序。这些 VM 要有管理程序才能在底层主机系统上运行,并且它们需要自己的操作系统副本才能运行。 + +后来有了容器container。容器虽然在概念上与 VM 类似,但工作方式不同。它们只需使用一些现有的操作系统结构来划分隔离空间,而不需要运行单独的程序和操作系统的副本。因此,它们的行为类似于 VM 以提供隔离但不需要过多的开销。 + +VM 和容器是根据配置定义创建的,因此可以轻易地销毁和重建,而不会影响运行它们的主机系统。这允许运行管道的系统也可重建。此外,对于容器,我们可以跟踪其构建定义文件的更改 —— 就像对源代码一样。 + +因此,如果遇到 VM 或容器中的问题,我们可以更容易、更快速地销毁和重建它们,而不是在当前环境尝试调试和修复。 + +这也意味着对管道代码的任何更改都可以触发管道新一轮运行(通过 CI),就像对代码的更改一样。这是 DevOps 关于基础架构的核心理念之一。 + +--- + +via: https://opensource.com/article/18/8/what-cicd + +作者:[Brent Laster][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[pityonline](https://github.com/pityonline) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://opensource.com/users/bclaster +[1]: https://jenkins.io +[2]: https://www.gerritcodereview.com +[3]: https://opensource.com/resources/what-is-git +[4]: https://junit.org/junit5/ +[5]: https://www.eclemma.org/jacoco/ +[6]: https://www.sonarqube.org/ +[7]: https://jfrog.com/artifactory/ +[8]: https://www.sonatype.com/nexus-repository-sonatype +[9]: https://opensource.com/resources/devops diff --git a/published/201808/20180809 How To Switch Between Multiple PHP Versions In Ubuntu.md b/published/201808/20180809 How To Switch Between Multiple PHP Versions In Ubuntu.md new file mode 100644 index 0000000000..acf5b328ce --- /dev/null +++ b/published/201808/20180809 How To Switch Between Multiple PHP Versions In Ubuntu.md @@ -0,0 +1,124 @@ +如何在 Ubuntu 中切换多个 PHP 版本 +====== + +![](https://www.ostechnix.com/wp-content/uploads/2018/08/php-720x340.png) + +有时,最新版本的安装包可能无法按预期工作。你的程序可能与更新的软件包不兼容,并且仅支持特定的旧版软件包。在这种情况下,你可以立即将有问题的软件包降级到其早期的工作版本。请参阅我们的旧指南,[在这][1]了解如何降级 Ubuntu 及其衍生版中的软件包以及[在这][1]了解如何降级 Arch Linux 及其衍生版中的软件包。但是,你无需降级某些软件包。我们可以同时使用多个版本。例如,假设你在测试部署在 Ubuntu 18.04 LTS 中的[LAMP 栈][3]的 PHP 程序。过了一段时间,你发现应用程序在 PHP 5.6 中工作正常,但在 PHP 7.2 中不正常(Ubuntu 18.04 LTS 默认安装 PHP 7.x)。你打算重新安装 PHP 或整个 LAMP 栈吗?但是没有必要。你甚至不必将 PHP 降级到其早期版本。在这个简短的教程中,我将向你展示如何在 Ubuntu 18.04 LTS 中切换多个 PHP 版本。它没你想的那么难。请继续阅读。 + +### 在多个 PHP 版本之间切换 + +要查看 PHP 的默认安装版本,请运行: + +``` +$ php -v +PHP 7.2.7-0ubuntu0.18.04.2 (cli) (built: Jul 4 2018 16:55:24) ( NTS ) +Copyright (c) 1997-2018 The PHP Group +Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies +with Zend OPcache v7.2.7-0ubuntu0.18.04.2, Copyright (c) 1999-2018, by Zend Technologies +``` + +如你所见,已安装的 PHP 的版本为 7.2.7。在测试你的程序几天后,你会发现你的程序不支持 PHP7.2。在这种情况下,同时使用 PHP5.x 和 PHP7.x 是个不错的主意,这样你就可以随时轻松地在任何支持的版本之间切换。 + +你不必删除 PHP7.x 或重新安装 LAMP 栈。你可以同时使用 PHP5.x 和 7.x 版本。 + +我假设你还没有在你的系统中卸载 PHP 5.6。万一你已将其删除,你可以使用下面的 PPA 再次安装它。 + +你可以从 PPA 中安装 PHP 5.6: + +``` +$ sudo add-apt-repository -y ppa:ondrej/php +$ sudo apt update +$ sudo apt install php5.6 +``` + +#### 从 PHP 7.x 切换到 PHP 5.x. + +首先使用命令禁用 PHP 7.2 模块: + +``` +$ sudo a2dismod php7.2 +Module php7.2 disabled. +To activate the new configuration, you need to run: +systemctl restart apache2 +``` + +接下来,启用 PHP 5.6 模块: + +``` +$ sudo a2enmod php5.6 +``` + +将 PHP 5.6 设置为默认版本: + +``` +$ sudo update-alternatives --set php /usr/bin/php5.6 +``` + +或者,你可以运行以下命令来设置默认情况下要使用的全局 PHP 版本。 + +``` +$ sudo update-alternatives --config php +``` + +输入选择的号码将其设置为默认版本,或者只需按回车键保持当前选择。 + +如果你已安装其他 PHP 扩展,请将它们设置为默认值。 + +``` +$ sudo update-alternatives --set phar /usr/bin/phar5.6 +``` + +最后,重启 Apache Web 服务器: + +``` +$ sudo systemctl restart apache2 +``` + +现在,检查 PHP 5.6 是否是默认版本: + +``` +$ php -v +PHP 5.6.37-1+ubuntu18.04.1+deb.sury.org+1 (cli) +Copyright (c) 1997-2016 The PHP Group +Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies +with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies +``` + +#### 从 PHP 5.x 切换到 PHP 7.x. + +同样,你可以从 PHP 5.x 切换到 PHP 7.x 版本,如下所示。 + +``` +$ sudo a2enmod php7.2 +$ sudo a2dismod php5.6 +$ sudo update-alternatives --set php /usr/bin/php7.2 +$ sudo systemctl restart apache2 +``` + +**提醒一句:** + +最终稳定版 PHP 5.6 于 2017 年 1 月 19 日达到[**活跃支持截止**][4]。但是,直到 2018 年 12 月 31 日,PHP 5.6 将继续获得对关键安全问题的支持。所以,建议尽快升级所有 PHP 程序并与 PHP 7.x 兼容。 + +如果你希望防止 PHP 将来自动升级,请参阅以下指南。 + +就是这些了。希望这有帮助。还有更多的好东西。敬请关注! + +干杯! + + +-------------------------------------------------------------------------------- + +via: https://www.ostechnix.com/how-to-switch-between-multiple-php-versions-in-ubuntu/ + +作者:[SK][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[geekpi](https://github.com/geekpi) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.ostechnix.com/author/sk/ +[1]:https://www.ostechnix.com/how-to-downgrade-a-package-in-ubuntu/ +[2]:https://www.ostechnix.com/downgrade-package-arch-linux/ +[3]:https://www.ostechnix.com/install-apache-mariadb-php-lamp-stack-ubuntu-16-04/ +[4]:http://php.net/supported-versions.php diff --git a/published/201808/20180810 Image creation applications for Fedora.md b/published/201808/20180810 Image creation applications for Fedora.md new file mode 100644 index 0000000000..113c367ba9 --- /dev/null +++ b/published/201808/20180810 Image creation applications for Fedora.md @@ -0,0 +1,76 @@ +Fedora 下的图像创建程序 +====== + +![](https://fedoramagazine.org/wp-content/uploads/2018/08/creatingimages-816x346.png) + +有了创意吗?Fedora 有很多程序可以帮助你的创造力。从数字绘图、矢量到像素艺术,每个人都可以在这个周末发挥创意。本文重点介绍了 Fedora 下创建很棒图像的程序。 + +### 矢量图形:Inkscape + +[Inkscape][1] 是一个众所周知的、受人喜爱的开源矢量图形编辑器。SVG 是 Inkscape 的主要文件格式,因此你所有的图形都可以任意伸缩!Inkscape 已存在多年,所以有一个坚实的社区和用于入门的[大量教程和其他资源][2]。 + +作为矢量图形编辑器,Inkscape 更适合于简单的插图(例如简单的漫画风格)。然而,使用矢量模糊,一些艺术家创造了一些[令人惊奇的矢量图][3]。 + +![][4] + +从 Fedora Workstation 中的软件应用安装 Inkscape,或在终端中使用以下命令: + +``` +sudo dnf install inkscape +``` + +### 数字绘图:Krita 和 Mypaint + +[Krita][5] 是一个流行的图像创建程序,用于数字绘图、光栅插图和纹理。此外,Krita 是一个活跃的项目,拥有一个充满活力的社区 —— 所以[有用于入门的很多教程][6]。Krita 有多个画笔引擎、带有弹出调色板的 UI、用于创建无缝图案的环绕模式、滤镜、图层等等。 + +![][7] + +从 Fedora Workstation 中的软件应用安装 Krita,或在终端中使用以下命令: + +``` +sudo dnf install krita +``` + +[Mypaint][8] 是另一款适用于 Fedora 令人惊奇的数字绘图程序。像 Krita 一样,它有多个画笔和使用图层的能力。 + +![][9] + +从 Fedora Workstation 中的软件应用安装 Mypaint,或在终端中使用以下命令: + +``` +sudo dnf install mypaint +``` + +### 像素艺术:Libresprite + +[Libresprite][10] 是一个专为创建像素艺术和像素动画而设计的程序。它支持一系列颜色模式,并可导出为多种格式(包括动画 GIF)。此外,Libresprite 还有用于创建像素艺术的绘图工具:多边形工具、轮廓和着色工具。 + +![][11] + +Libresprite 可从 Flathub 应用仓库下载。要安装,只需[启用 Flathub 作为软件源][12],然后通过软件应用进行安装。 + + +-------------------------------------------------------------------------------- + +via: https://fedoramagazine.org/image-creation-applications-fedora/ + +作者:[Ryan Lerch][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[geekpi](https://github.com/geekpi) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://fedoramagazine.org/introducing-flatpak/ +[1]:http://inkscape.org +[2]:https://inkscape.org/en/learn/tutorials/ +[3]:https://inkscape.org/en/gallery/ +[4]:https://fedoramagazine.org/wp-content/uploads/2018/08/inkscape.png +[5]:https://krita.org/en/ +[6]:https://docs.krita.org/en/ +[7]:https://fedoramagazine.org/wp-content/uploads/2018/08/krita.jpg +[8]:http://mypaint.org/about/ +[9]:https://fedoramagazine.org/wp-content/uploads/2018/08/mypaint.png +[10]:https://github.com/LibreSprite/LibreSprite +[11]:https://fedoramagazine.org/wp-content/uploads/2018/08/libresprite.gif +[12]:https://fedoramagazine.org/install-flathub-apps-fedora/ diff --git a/published/201808/20180812 Ubuntu 18.04 Vs. Fedora 28.md b/published/201808/20180812 Ubuntu 18.04 Vs. Fedora 28.md new file mode 100644 index 0000000000..37b1a6620a --- /dev/null +++ b/published/201808/20180812 Ubuntu 18.04 Vs. Fedora 28.md @@ -0,0 +1,108 @@ +对比 Ubuntu 18.04 和 Fedora 28 +====== + +![](http://www.linuxandubuntu.com/uploads/2/1/1/5/21152474/ubuntu-18-04-vs-fedora-28_orig.jpg) + +大家好,我准备在今天突出说明一下两大主流 Linux 发行版,即 **Ubuntu 18.04** 和 **Fedora 28**,包括一些特性和差异。两者都有各自的包管理系统,其中 Ubuntu 使用 DEB,Fedora 使用 RPM;但二者使用同样的[桌面环境Desktop Environment][3] (DE)[GNOME][4],并致力于为 Linux 用户提供高品质的桌面体验desktop experience。 + +**Ubuntu 18.04** 是 Ubuntu 目前最新的 [长期支持版本Long Term Support][1](LTS),为用户提供 GNOME 桌面系统。**Fedora 28** 也提供 GNOME 桌面系统,但落实到具体的软件包管理方面,二者的桌面体验存在差异;在用户界面User Interfaces方面也显然存在差异。 + +### 基本概念 + +不知你是否了解,虽然 Ubuntu 基于 Debian,但 Ubuntu 比 Debian 更早提供最新版本的软件。举个例子,当 Ubuntu 提供流行网页浏览器 Firefox Quantum 时,Debian 仍在提供 Firefox 的延期支持版Extended Support Release(ESR)。 + +(LCTT 译注:从 2012 年 1 月开始,Firefox 进入快速版本期,每 6 周发布新的主线版本,每隔 7 个主线版本发布新的 ESR 版本。Firefox 57 的桌面版发布时被命名为 Firefox Quantum,同期的 ESR 版本与 Firefox 52 一同发布并基于 Firefox 48。参考 [Wiki: History\_of\_Firefox][9]) + +同样的情况也适用于 Fedora,它为终端用户提供前沿的软件,也被用作下一个稳定版本的 RHEL (Red Hat Enterprise Linux) 的测试平台。 + +### 桌面预览 + +Fedora 提供原汁原味的vanilla GNOME 桌面体验;相比之下,Ubuntu 18.04 对 GNOME 做了若干方面的微调,以便长期以来的 Unity 用户可以平滑的过渡到 GNOME 桌面环境。 + +_为节省开发时间,Canonical (从 Ubuntu [17.10][2] 开始)已经决定放弃 Unity 并转向 GNOME 桌面,以便可以将更多精力投入到 IoT 领域。_ + +因此,在 Fedora 的桌面预览中,我们可以看到一个简洁的无图标桌面和一个自动隐藏的侧边栏,整体外观采用 GNOME 默认的 Adwaita 主题。 + + [![fedora 28 gnome](http://www.linuxandubuntu.com/uploads/2/1/1/5/21152474/ubuntu-18-04-gnome_orig.jpg)][5] + +相比之下,Ubuntu 采用其经典的有图标桌面样式,左侧边栏用于模拟其传统的“程序坞dock”,使用 Ubuntu Ambiance 主题定制化窗口,与其传统的(Unity 桌面)外观和体验基本一致。 + + [![Ubuntu gnome 18.04](http://www.linuxandubuntu.com/uploads/2/1/1/5/21152474/ubuntu-gnome-18-04_orig.jpg)][6] + +虽然存在一定差异,但习惯使用其中一种桌面环境后切换到另外一种并不困难。毕竟二者设计时都充分考虑了简洁性和用户友好性,即使是新用户也不会对这两种 Linux 发行版感到不适应。 +​ +但外观或 UI 并不是决定用户选择哪一种 Linux 发行版的唯一因素,还有其它因素也会影响用户的选择。下面主要介绍两种 Linux 发行版在软件包管理相关方面的内容。 + +### 软件中心 + +Ubuntu 使用 dpkg(即 Debian Package Management)将软件分发给终端用户;Fedora 则使用 rpm(全称为 Red Hat Package Management)。它们都是 Linux 社区中非常流行的包管理系统,对应的命令行工具也都简单易用。 + + [![ubuntu software center](http://www.linuxandubuntu.com/uploads/2/1/1/5/21152474/ubuntu-software-center_2_orig.jpg)][7] + +但在具体分发的软件方面,各个 Linux 发行版会有明显差异。Canonical 每 6 个月发布新版本的 Ubuntu,一般是在每年的 4 月和 10 月。对每个版本,开发者会维护一个开发计划;Ubuntu 新版本发布后,该版本就会进入冻结freeze状态,即停止新软件的开发和测试。 + +​相比之下,Fedora 也采用相似的 6 个月发布周期,看起来很像一种滚动更新rolling release的 Linux 发行版(其实并不是这样)。与 Ubuntu 不同之处在于,(Fedora 中的)几乎所有软件包更新都很频繁,让用户有机会尝试最新版本的软件。但这样也导致软件 Bug 更频繁出现,给用户带来“不稳定性”,虽然还不至于导致系统不可用。 + +### 软件更新 + +我上面已经提到了 Ubuntu 版本的冻结状态。好吧,由于它对 Ubuntu 软件更新方式有着重要的影响,我再次提到这个状态:当 Ubuntu 新版本发布后,该版本的开发(这里是指测试新软件)就停止了。 + +_即将发布的下个版本的开发也随之开始,先后历经 “每日构建daily build” 和 “测试版beta release” 阶段,最后作为新版本发布给终端用户。_ + +在冻结状态下,Ubuntu 维护者不会在软件源package repository中增加最新版软件,除非用于解决严重的安全问题。因此,Ubuntu 用户可用的软件更新更多涉及 Bug 修复而不是新特性,这样的好处在于系统可以保持稳定,不会扰乱用户的使用。 + +Fedora 试图为终端用户提供最新版本的软件,故用户的可用软件更新相比 Ubuntu 而言会更多涉及新特性。当然,开发者为了维持系统的稳定性,也采取了一系列措施。例如,在操作系统启动时,用户可以从最多三个可用内核working kernel(最新内核处于最上方)中进行选择;当新内核无法启动时,用户可以回滚使用之前两个可用内核。 + +### Snaps 和 flatpak + +它们都是新出现的酷炫工具,可以将软件发布到多个 Linux 发行版上。Ubuntu 提供 **snaps**,而 Fedora 则提供 **flatpak** 。二者之中 snaps 更加流行,更多流行软件或版权软件都在考虑上架 snap 商店。Flatpak 也在吸引关注,越来越多的软件上线该平台。 + +不幸的是,由于二者出现的时间都不久,很多人遇到“窗口主题不一致window theme-breaking”问题并在网上表达不满。但由于二者都很易于使用,在二者之间切换并不是难事。 + +(LCTT 译注:按译者理解,由于二者都增加了一层安全隔离,读取系统主题方面会遇到问题;另外,似乎也有反馈 snap 专用主题无法及时应用于 snap 的问题) + +### 应用对比 + +下面列出一些在 Ubuntu 和 Fedora 上共有的常见应用,然后在两个平台之间进行对比: + +#### 计算器 + +Fedora 上的计算器程序启动速度更快。这是因为 Fedora 上的计算器程序是软件包形式安装的,而 Ubuntu 上的计算器程序则是 snap 版本。 + +#### 系统监视器 + +可能听上去比较书呆子气,但我认为观察计算机性能并杀掉令人讨厌的进程是必要且直观的。程序启动速度对比与计算器的结果一致,即 (软件包方式安装的)Fedora 版本快于(snap 形式提供的)Ubuntu 版本。 + +#### 帮助程序 + +我已经提到,(为便于长期以来的 Untiy 用户平滑切换到 GNOME),Ubuntu 提供的 GNOME 桌面环境是经过微调的版本。不幸的是,Ubuntu 开发者似乎忘记或忽略了对帮助程序的更新,用户阅读文档(入门视频)后会发现演示视频与真实环境有略微差异,这可能让人感到迷惑。 + + [![ubuntu 18.04 help manual](http://www.linuxandubuntu.com/uploads/2/1/1/5/21152474/ubuntu-18-04-help-manual_orig.jpg)][8] + +### 结论 + +Ubuntu 和 Fedora 是两个主流的 Linux 发行版。两者都各自有一些华而不实的特性,因而新接触 Linux 的人很难抉择。我的建议是同时尝试二者,这样你在试用后可以发现哪个发行版提供的工具更适合你。 + +希望你阅读愉快,你可以在下方的评论区给出我漏掉的内容或你的建议。 + +-------------------------------------------------------------------------------- + +via: http://www.linuxandubuntu.com/home/ubuntu-1804-vs-fedora-28 + +作者:[LinuxAndUbuntu][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[pinewall](https://github.com/pinewall) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:http://www.linuxandubuntu.com +[1]:http://www.linuxandubuntu.com/home/ubuntu-1804-codename-announced-bionic-beaver +[2]:http://www.linuxandubuntu.com/home/what-new-is-going-to-be-in-ubuntu-1704-zesty-zapus +[3]:http://www.linuxandubuntu.com/home/5-best-linux-desktop-environments-with-pros-cons +[4]:http://www.linuxandubuntu.com/home/walkthrough-on-how-to-use-gnome-boxes +[5]:http://www.linuxandubuntu.com/uploads/2/1/1/5/21152474/ubuntu-18-04-gnome_orig.jpg +[6]:http://www.linuxandubuntu.com/uploads/2/1/1/5/21152474/ubuntu-gnome-18-04_orig.jpg +[7]:http://www.linuxandubuntu.com/uploads/2/1/1/5/21152474/ubuntu-software-center_2_orig.jpg +[8]:http://www.linuxandubuntu.com/uploads/2/1/1/5/21152474/ubuntu-18-04-help-manual_orig.jpg +[9]:https://en.wikipedia.org/wiki/History_of_Firefox diff --git a/published/201808/20180813 Convert file systems with Fstransform.md b/published/201808/20180813 Convert file systems with Fstransform.md new file mode 100644 index 0000000000..9a6e6747f9 --- /dev/null +++ b/published/201808/20180813 Convert file systems with Fstransform.md @@ -0,0 +1,63 @@ +使用 Fstransform 转换文件系统 +====== + +![](https://fedoramagazine.org/wp-content/uploads/2018/08/converting-filesystems-816x345.jpg) + +很少有人知道他们可以将文件系统从一种类型转换为另一种类型而不会丢失数据(即非破坏性的)。这可能听起来像魔术,但 [Fstransform][1] 可以几乎以任意组合将 ext2、ext3、ext4、jfs、reiserfs 或 xfs 分区转换成另一类型。更重要的是,它可以直接执行,而无需格式化或复制数据。除此之外,还有一点好处:Fstransform 也可以处理 ntfs、btrfs、fat 和 exfat 分区。 + +### 在运行之前 + +Fstransform 存在一些警告和限制,因此强烈建议在尝试转换之前进行备份。此外,使用 Fstransform 时需要注意一些限制: + +* 你的 Linux 内核必须支持源文件系统和目标文件系统。听起来很明显,如果你想使用 ext2、ext3、ext4、reiserfs、jfs 和 xfs 分区,这样不会出现风险。Fedora 支持所有分区,所以没问题。 +* 将 ext2 升级到 ext3 或 ext4 不需要 Fstransform。请使用 Tune2fs。 +* 源文件系统的设备必须至少有 5% 的可用空间。 +* 你需要在开始之前卸载源文件系统。 +* 源文件系统存储的数据越多,转换的时间就越长。实际速度取决于你的设备,但预计它大约为每分钟 1GB。大量的硬链接也会降低转换速度。 +* 虽然 Fstransform 被证明是稳定的,但请备份源文件系统上的数据。 + +### 安装说明 + +Fstransform 已经是 Fedora 的一部分。使用以下命令安装: + +``` +sudo dnf install fstransform +``` + +### 转换 + +![][2] + +`fstransform` 命令的语法非常简单:`fstransform <源设备> <目标文件系统>`。请记住,它需要 root 权限才能运行,所以不要忘记在开头添加 `sudo`。这是一个例子: + +``` +sudo fstransform /dev/sdb1 ext4 +``` + +请注意,无法转换根文件系统,这是一种安全措施。请改用测试分区或实验性 USB 盘。与此同时,Fstransform 会在控制台中有许多辅助输出。最有用的部分是预计完成时间,让你随时了解该过程需要多长时间。同样,在几乎空的驱动器上的几个小文件将使 Fstransform 在一分钟左右完成其工作,而更多真实世界的任务可能需要数小时的等待时间。 + +### 更多支持的文件系统 + +如上所述,可以尝试在 ntfs、btrfs、fat 和 exfat 分区使用 Fstransform。这些类型是早期实验性的,没有人能保证完美转换。尽管如此,还是有许多成功案例,你可以通过在测试分区上使用示例数据集测试 Fstransform 来添加自己的成功案例。可以使用 `--force-untested-file-systems` 参数启用这些额外的文件系统: + +``` +sudo fstransform /dev/sdb1 ntfs --force-untested-file-systems +``` + +有时,该过程可能会因错误而中断。请放心再次执行命令 —— 它可能最终会在两、三次尝试后完成转换。 + + +-------------------------------------------------------------------------------- + +via: https://fedoramagazine.org/transform-file-systems-in-linux/ + +作者:[atolstoy][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[geekpi](https://github.com/geekpi) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://fedoramagazine.org/author/atolstoy/ +[1]:https://github.com/cosmos72/fstransform +[2]:https://fedoramagazine.org/wp-content/uploads/2018/08/Screenshot_20180805_230116.png diff --git a/published/201808/20180813 How To Switch Between Different Versions Of Commands In Linux.md b/published/201808/20180813 How To Switch Between Different Versions Of Commands In Linux.md new file mode 100644 index 0000000000..6a393bfb92 --- /dev/null +++ b/published/201808/20180813 How To Switch Between Different Versions Of Commands In Linux.md @@ -0,0 +1,140 @@ +如何在 Linux 中切换相同程序的不同版本 +====== + +![](https://www.ostechnix.com/wp-content/uploads/2018/08/alt-tool-720x340.png) + +几天前,我们曾经讨论[如何在不同的 PHP 版本之间进行切换][1]。在那篇文章中,我们使用 `update-alternatives` 命令实现从一个 PHP 版本切换到另一个 PHP 版本。也就是说,`update-alternatives` 命令可以将系统范围system wide默认使用的 PHP 版本设置为我们希望的版本。通俗的来说,你可以通过 `update-alternatives` 命令从系统范围设置程序的版本。如果你希望可以在不同目录动态设置不同的程序版本,该如何完成呢?在这种情况下,`alt` 工具可以大显身手。`alt` 是一个命令行工具,可以让你在类 Unix 系统中切换相同程序的不同版本。该工具简单易用,是 Rust 语言编写的自由、开源软件。 + +### 安装 + +安装 `alt` 工具十分简单。 + +运行如下命令,即可在 Linux 主机上安装 `alt`: + +``` +$ curl -sL https://github.com/dotboris/alt/raw/master/install.sh | bash -s +``` + +下一步,将 `shims` 目录添加到你的 PATH 环境变量中,具体操作取决于你使用的 Shell。 + +对于 Bash: + +``` +$ echo 'export PATH="$HOME/.local/alt/shims:$PATH"' >> ~/.bashrc +$ source ~/.bashrc +``` + +对于 Zsh: + +``` +$ echo 'export PATH="$HOME/.local/alt/shims:$PATH"' >> ~/.zshrc +$ source ~/.zshrc +``` + +对于 Fish: + +``` +$ echo 'set -x PATH "$HOME/.local/alt/shims" $PATH' >> ~/.config/fish/config.fish +``` + +现在 `alt` 已经安装完毕! + +### 使用 alt 工具在 Linux 系统中切换相同程序的不同版本 + +如我之前所述,alt 只影响当前目录。换句话说,当你进行版本切换时,只在当前目录生效,而不是整个系统范围。 + +下面举例说明。我在我的 Ubuntu 系统中安装了两个版本的 PHP,分别为 PHP 5.6 和 PHP 7.2;另外,在 `myproject` 目录中包含一些 PHP 应用。 + +首先,通过命令查看系统范围默认的 PHP 版本: + +``` +$ php -v +``` + +示例输出: + +![查找 PHP 版本][3] + +如截图中所示,我系统中默认的 PHP 版本为 PHP 7.2。 + +然后,我将进入放置 PHP 应用的 `myproject` 目录。 + +``` +$ cd myproject +``` + +使用如下命令扫描可用的 PHP 版本: + +``` +$ alt scan php +``` + +示例输出: + +![扫描 PHP 版本][4] + +可见,我有两个 PHP 版本,即 PHP 5.6 和 PHP 7.2。按下 `<空格>` 键选中当前可用的版本。选中全部可用版本后,你可以看到图中所示的叉号cross mark。使用上下方向键在版本间移动,点击回车即可保存变更。 + +![选取 PHP 版本][5] + +下面运行该命令并选取我们希望在 `myproject` 目录中使用的 PHP 版本: + +``` +$ alt use php +``` + +我希望使用 PHP5.6 版本,故我(使用方向键)选取该版本并点击回车键。 + +![设置 PHP 版本][6] + +现在,你可以在 `/home/sk/myproject` 目录下使用 PHP 5.6 版本啦。 + +让我们检查一下,在 `myproject` 目录下是否默认使用 PHP 5.6 版本: + +``` +$ php -v +``` + +示例输出: + +![检查 PHP 版本][7] + +只要你不设置成其它版本,(在该目录下)将一直使用 PHP 5.6 版本。清楚了吗?很好!请注意,我们仅在这个目录下使用 PHP 5.6 版本。在系统范围内(LCTT 译注:当然是没单独设置过其它版本的目录下),PHP 7.2 仍是默认的版本。让我们检验一下,请看下图。 + +![比对 PHP 版本][8] + +从上面的截图中可以看出,我有两个版本的 PHP:在 `myproject` 目录下,使用的版本为 PHP 5.6;在 `myproject` 外的其它目录,使用的版本为 PHP 7.2。 + +同理,你可以为每个目录设置你希望的程序版本。我这里使用 PHP 仅用于说明操作,但方法适用于任何你打算使用的软件,例如 NodeJS 等。 + +下面是 NodeJS 的示例视频。 + +![][9] + +如果你希望在不同软件包版本下测试你的应用,那么 `alt` 是你不错的选择。 + +本次分享到此结束。后续还有更多内容,敬请期待! + +干杯! + +-------------------------------------------------------------------------------- + +via: https://www.ostechnix.com/how-to-switch-between-different-versions-of-commands-in-linux/ + +作者:[SK][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[pinewall](https://github.com/pinewall) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.ostechnix.com/author/sk/ +[1]:https://www.ostechnix.com/how-to-switch-between-multiple-php-versions-in-ubuntu/ +[2]:data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7 +[3]:http://www.ostechnix.com/wp-content/uploads/2018/08/Find-PHP-version.png +[4]:http://www.ostechnix.com/wp-content/uploads/2018/08/alt-scan-php.png +[5]:http://www.ostechnix.com/wp-content/uploads/2018/08/Select-php-version.png +[6]:http://www.ostechnix.com/wp-content/uploads/2018/08/set-php-version.png +[7]:http://www.ostechnix.com/wp-content/uploads/2018/08/Check-PHP-version.png +[8]:http://www.ostechnix.com/wp-content/uploads/2018/08/Check-PHP-version-1.png +[9]:http://www.ostechnix.com/wp-content/uploads/2018/08/Alt-NodeJS-demo.gif diff --git a/published/201808/20180813 How to display data in a human-friendly way on Linux.md b/published/201808/20180813 How to display data in a human-friendly way on Linux.md new file mode 100644 index 0000000000..95c2da43bd --- /dev/null +++ b/published/201808/20180813 How to display data in a human-friendly way on Linux.md @@ -0,0 +1,234 @@ +在 Linux 中如何以人性化的方式显示数据 +====== + +> 许多 Linux 命令现在都有使其输出更易于理解的选项。让我们了解一些可以让我们心爱的操作系统更友好的东西。 + +![](https://images.idgesg.net/images/article/2018/08/smile-face-on-hand-100767756-large.jpg) + +不是每个人都以二进制方式思考,他们不想在大脑中给大数字插入逗号来了解文件的大小。因此,Linux 命令在过去的几十年里不断发展,以更人性化的方式向用户显示信息,这一点也不奇怪。在今天的文章中,我们将看一看各种命令所提供的一些选项,它们使得数据变得更容易理解。 + +### 为什么默认显示不更友好一些? + +如果你想知道为什么默认不显示得更人性化,毕竟,我们人类才是计算机的默认用户啊。你可能会问自己:“为什么我们不竭尽全力输出对每个人都有意义的命令的响应?”主要的答案是:改变命令的默认输出可能会干扰许多其它进程,这些进程是在期望默认响应之上构建的。其它的工具,以及过去几十年开发的脚本,如果突然以一种完全不同的格式输出,而不是它们过去所期望的那样,可能会被一种非常丑陋的方式破坏。 + +说真的,也许我们中的一些人可能更愿意看文件大小中的所有数字,即 1338277310 而不是 1.3G。在任何情况下,切换默认习惯都可能造成破坏,但是为更加人性化的响应提供一些简单的选项只需要让我们学习一些命令选项而已。 + +### 可以显示人性化数据的命令 + +有哪些简单的选项可以使 Unix 命令的输出更容易解析呢?让我们来看一些命令。 + +#### top + +你可能没有注意到这个命令,但是在 top 命令中,你可以通过输入 `E`(大写字母 E)来更改显示全部内存使用的方式。连续按下将数字显示从 KiB 到 MiB,再到 GiB,接着是 TiB、PiB、EiB,最后回到 KiB。 + +认识这些单位吧?这里有一组定义: + +``` +2`10 = 1,024 = 1 KiB (kibibyte) +2`20 = 1,048,576 = 1 MiB (mebibyte) +2`30 = 1,073,741,824 = 1 GiB (gibibyte) +2`40 = 1,099,511,627,776 = 1 TiB (tebibyte) +2`50 = 1,125,899,906,842,624 = PiB (pebibyte) +2`60 = 1,152,921,504,606,846,976 = EiB (exbibyte) +2`70 = 1,180,591,620,717,411,303,424 = 1 ZiB (zebibyte) +2`80 = 1,208,925,819,614,629,174,706,176 = 1 YiB (yobibyte) +``` + +这些单位与千字节(KB)、兆字节(MB)和千兆字节(GB)密切相关。虽然它们很接近,但是它们之间仍有很大的区别:一组是基于 10 的幂,另一组是基于 2 的幂。例如,比较千字节和千兆字节,我们可以看看它们不同点: + +``` +KB = 1000 = 10`3 +KiB = 1024 = 2`10 +``` + +以下是 `top` 命令输出示例,使用 KiB 为单位默认显示: + +``` +top - 10:49:06 up 5 days, 35 min, 1 user, load average: 0.05, 0.04, 0.01 +Tasks: 158 total, 1 running, 118 sleeping, 0 stopped, 0 zombie +%Cpu(s): 0.0 us, 0.2 sy, 0.0 ni, 99.8 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st +KiB Mem : 6102680 total, 4634980 free, 392244 used, 1075456 buff/cache +KiB Swap: 2097148 total, 2097148 free, 0 used. 5407432 avail Mem +``` + +在按下 `E` 之后,单位变成了 MiB: + +``` +top - 10:49:31 up 5 days, 36 min, 1 user, load average: 0.03, 0.04, 0.01 +Tasks: 158 total, 2 running, 118 sleeping, 0 stopped, 0 zombie +%Cpu(s): 0.0 us, 0.6 sy, 0.0 ni, 99.4 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st +MiB Mem : 5959.648 total, 4526.348 free, 383.055 used, 1050.246 buff/cache +MiB Swap: 2047.996 total, 2047.996 free, 0.000 used. 5280.684 avail Mem +``` + +再次按下 `E`,单位变为 GiB: + +``` +top - 10:49:49 up 5 days, 36 min, 1 user, load average: 0.02, 0.03, 0.01 +Tasks: 158 total, 1 running, 118 sleeping, 0 stopped, 0 zombie +%Cpu(s): 0.0 us, 0.0 sy, 0.0 ni,100.0 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st +GiB Mem : 5.820 total, 4.420 free, 0.374 used, 1.026 buff/cache +GiB Swap: 2.000 total, 2.000 free, 0.000 used. 5.157 avail Mem +``` + +你还可以通过按字母 `e` 来更改为显示每个进程使用内存的数字单位。它将从默认的 KiB 到 MiB,再到 GiB、TiB,接着到 PiB(估计你能看到小数点后的很多 0),然后返回 KiB。下面是按了一下 `e` 之后的 `top` 输出: + +``` +top - 08:45:28 up 4 days, 22:32, 1 user, load average: 0.02, 0.03, 0.00 +Tasks: 167 total, 1 running, 118 sleeping, 0 stopped, 0 zombie +%Cpu(s): 0.2 us, 0.0 sy, 0.0 ni, 99.8 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st +KiB Mem : 6102680 total, 4641836 free, 393348 used, 1067496 buff/cache +KiB Swap: 2097148 total, 2097148 free, 0 used. 5406396 avail Mem + + PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND + 784 root 20 0 543.2m 26.8m 16.1m S 0.9 0.5 0:22.20 snapd + 733 root 20 0 107.8m 2.0m 1.8m S 0.4 0.0 0:18.49 irqbalance +22574 shs 20 0 107.5m 5.5m 4.6m S 0.4 0.1 0:00.09 sshd + 1 root 20 0 156.4m 9.3m 6.7m S 0.0 0.2 0:05.59 systemd +``` + +#### du + +`du` 命令显示磁盘空间文件或目录使用了多少,如果使用 `-h` 选项,则将输出大小调整为最合适的单位。默认情况下,它以千字节(KB)为单位。 + +``` +$ du camper* +360 camper_10.jpg +5684 camper.jpg +240 camper_small.jpg +$ du -h camper* +360K camper_10.jpg +5.6M camper.jpg +240K camper_small.jpg +``` + +#### df + +`df` 命令也提供了一个 `-h` 选项。请注意在下面的示例中是如何以千兆字节(GB)和兆字节(MB)输出的: + +``` +$ df -h | grep -v loop +Filesystem Size Used Avail Use% Mounted on +udev 2.9G 0 2.9G 0% /dev +tmpfs 596M 1.7M 595M 1% /run +/dev/sda1 110G 9.0G 95G 9% / +tmpfs 3.0G 0 3.0G 0% /dev/shm +tmpfs 5.0M 4.0K 5.0M 1% /run/lock +tmpfs 3.0G 0 3.0G 0% /sys/fs/cgroup +tmpfs 596M 16K 596M 1% /run/user/121 +/dev/sdb2 457G 73M 434G 1% /apps +tmpfs 596M 0 596M 0% /run/user/1000 +``` + +下面的命令使用了 `-h` 选项,同时使用 `-T` 选项来显示我们正在查看的文件系统的类型。 + +``` +$ df -hT /mnt2 +Filesystem Type Size Used Avail Use% Mounted on +/dev/sdb2 ext4 457G 73M 434G 1% /apps +``` + +#### ls + +即使是 `ls`,它也为我们提供了调整大小显示的选项,保证是最合理的单位。 + +``` +$ ls -l camper* +-rw-rw-r-- 1 shs shs 365091 Jul 14 19:42 camper_10.jpg +-rw-rw-r-- 1 shs shs 5818597 Jul 14 19:41 camper.jpg +-rw-rw-r-- 1 shs shs 241844 Jul 14 19:45 camper_small.jpg +$ ls -lh camper* +-rw-rw-r-- 1 shs shs 357K Jul 14 19:42 camper_10.jpg +-rw-rw-r-- 1 shs shs 5.6M Jul 14 19:41 camper.jpg +-rw-rw-r-- 1 shs shs 237K Jul 14 19:45 camper_small.jpg +``` + +#### free + +`free` 命令允许你以字节(B),千字节(KB),兆字节(MB)和千兆字节(GB)为单位查看内存使用情况。 + +``` +$ free -b + total used free shared buff/cache available +Mem: 6249144320 393076736 4851625984 1654784 1004441600 5561253888 +Swap: 2147479552 0 2147479552 +$ free -k + total used free shared buff/cache available +Mem: 6102680 383836 4737924 1616 980920 5430932 +Swap: 2097148 0 2097148 +$ free -m + total used free shared buff/cache available +Mem: 5959 374 4627 1 957 5303 +Swap: 2047 0 2047 +$ free -g + total used free shared buff/cache available +Mem: 5 0 4 0 0 5 +Swap: 1 0 1 +``` + +#### tree + +虽然 `tree` 命令与文件或内存计算无关,但它也提供了非常人性化的文件视图,它分层显示文件以说明文件是如何组织的。当你试图了解如何安排目录内容时,这种显示方式非常有用。(LCTT 译注:也可以看看 `pstree`,它以树状结构显示进程树。) + +``` +$ tree +.g to +├── 123 +├── appended.png +├── appts +├── arrow.jpg +├── arrow.png +├── bin +│ ├── append +│ ├── cpuhog1 +│ ├── cpuhog2 +│ ├── loop +│ ├── mkhome +│ ├── runme +``` + +#### stat + +`stat` 命令是另一个以非常人性化的格式显示信息的命令。它提供了更多关于文件的元数据,包括文件大小(以字节和块为单位)、文件类型、设备和 inode(索引节点)、文件所有者和组(名称和数字 ID)、以数字和 rwx 格式显示的文件权限以及文件的最后访问和修改日期。在某些情况下,它也可能显示最初创建文件的时间。 + +``` +$ stat camper* + File: camper_10.jpg + Size: 365091 Blocks: 720 IO Block: 4096 regular file +Device: 801h/2049d Inode: 796059 Links: 1 +Access: (0664/-rw-rw-r--) Uid: ( 1000/ shs) Gid: ( 1000/ shs) +Access: 2018-07-19 18:56:31.841013385 -0400 +Modify: 2018-07-14 19:42:25.230519509 -0400 +Change: 2018-07-14 19:42:25.230519509 -0400 + Birth: - + File: camper.jpg + Size: 5818597 Blocks: 11368 IO Block: 4096 regular file +Device: 801h/2049d Inode: 796058 Links: 1 +Access: (0664/-rw-rw-r--) Uid: ( 1000/ shs) Gid: ( 1000/ shs) +Access: 2018-07-19 18:56:31.845013872 -0400 +Modify: 2018-07-14 19:41:46.882024039 -0400 +Change: 2018-07-14 19:41:46.882024039 -0400 + Birth: - +``` + +### 总结 + +Linux 命令提供了许多选项,可以让用户更容易理解或比较它们的输出。对于许多命令,`-h` 选项会显示更友好的输出格式。对于其它的,你可能必须通过使用某些特定选项或者按下某个键来查看你希望的输出。我希望这其中一些选项会让你的 Linux 系统看起来更友好一点。 + +加入[Facebook][1] 和 [LinkedIn][2] 上的网络世界社区,一起来评论重要的话题吧。 + + +-------------------------------------------------------------------------------- + +via: https://www.networkworld.com/article/3296631/linux/displaying-data-in-a-human-friendly-way-on-linux.html + +作者:[Sandra Henry-Stocker][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[MjSeven](https://github.com/MjSeven) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.networkworld.com/author/Sandra-Henry_Stocker/ +[1]:https://www.facebook.com/NetworkWorld/ +[2]:https://www.linkedin.com/company/network-world diff --git a/published/201808/20180813 Tips for using the top command in Linux.md b/published/201808/20180813 Tips for using the top command in Linux.md new file mode 100644 index 0000000000..5985907a19 --- /dev/null +++ b/published/201808/20180813 Tips for using the top command in Linux.md @@ -0,0 +1,177 @@ +在 Linux 中使用 top 命令的建议 +====== + +> 通过这篇教程提升你的 `top` 命令的知识。 + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/linux_penguin_green.png?itok=ENdVzW22) + +尝试找出你的机器正在运行什么程序,以及哪个进程耗尽了内存导致系统非常非常慢 —— 这是 `top` 命令所能胜任的工作。 + +`top` 是一个非常有用的程序,其作用类似于 Windows 任务管理器或 MacOS 的活动监视器。在 \*nix 机器上运行 `top` 将实时显示系统上运行的进程的情况。 + +``` +$ top +``` + +取决于你运行的 `top` 版本,你会看到类似如下内容: + +``` +top - 08:31:32 up 1 day, 4:09, 0 users, load average: 0.20, 0.12, 0.10 +Tasks: 3 total, 1 running, 2 sleeping, 0 stopped, 0 zombie +%Cpu(s): 0.5 us, 0.3 sy, 0.0 ni, 99.2 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st +KiB Mem: 4042284 total, 2523744 used, 1518540 free, 263776 buffers +KiB Swap: 1048572 total, 0 used, 1048572 free. 1804264 cached Mem + + PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND + 1 root 20 0 21964 3632 3124 S 0.0 0.1 0:00.23 bash + 193 root 20 0 123520 29636 8640 S 0.0 0.7 0:00.58 flask + 195 root 20 0 23608 2724 2400 R 0.0 0.1 0:00.21 top +``` + +你所用的 `top` 版本可能跟这个看起来不一样,特别是在显示的列上。 + +### 如何阅读输出的内容 + +你可以根据输出判断你正在运行的内容,但尝试去解释结果你可能会有些困惑。 + +前几行包含一堆统计信息(详细信息),后跟一个包含结果列的表(列)。让我们从后者开始吧。 + +#### 列 + +这些是系统正在运行的进程。默认按 CPU 使用率降序排序。这意味着在列表顶部的程序正使用更多的 CPU 资源并对你的系统造成更重的负担。对于资源使用而言,这些程序是字面上的消耗资源最多的(top)进程。不得不说,`top` 这个名字起得很妙。 + +最右边的 `COMMAND` 一列报告进程名(启动它们的命令)。在这个例子里,进程名是 `bash`(一个我们正在运行 `top` 的命令解释器)、`flask`(一个 Python 写的 web 框架)和 `top` 自身。 + +其它列提供了关于进程的有用信息: + +* `PID`:进程 ID,一个用来定位进程的唯一标识符 +* `USER`:运行进程的用户 +* `PR`:任务的优先级 +* `NI`:Nice 值,优先级的一个更好的表现形式 +* `VIRT`:虚拟内存的大小,单位是 KiB(kibibytes) +* `RES`:常驻内存大小,单位是 KiB(物理内存和虚拟内存的一部分) +* `SHR`:共享内存大小,单位是 KiB(共享内存和虚拟内存的一部分) +* `S`:进程状态,一般 **I** 代表空闲,**R** 代表运行,**S** 代表休眠,**Z** 代表僵尸进程,**T** 或 **t** 代表停止(还有其它更少见的选项) +* `%CPU`:自从上次屏幕更新后的 CPU 使用率 +* `%MEM`:自从上次屏幕更新后的 `RES` 常驻内存使用率 +* `TIME+`:自从程序启动后总的 CPU 使用时间 +* `COMMAND`:启动命令,如之前描述那样 + +确切知道 `VIRT`,`RES` 和 `SHR` 值代表什么在日常操作中并不重要。重要的是要知道 `VIRT` 值最高的进程就是内存使用最多的进程。当你在用 `top` 排查为什么你的电脑运行无比卡的时候,那个 `VIRT` 数值最大的进程就是元凶。如果你想要知道共享内存和物理内存的确切意思,请查阅 [top 手册][1]的 Linux Memory Types 段落。 + +是的,我说的是 kibibytes 而不是 kilobytes。通常称为 kilobyte 的 1024 值实际上是 kibibyte。希腊语的 kilo(χίλιοι)意思是一千(例如一千米是 1000 米,一千克是 1000 克)。Kibi 是 kilo 和 binary 的合成词,意思是 1024 字节(或者 2^10 )。但是,因为这个词很难说,所以很多人在说 1024 字节的时候会说 kilobyte。`top` 试图在这里使用恰当的术语,所以按它说的理解就好。 + +#### 屏幕更新说明 + +实时屏幕更新是 Linux 程序可以做的 **非常酷** 的事之一。这意味着程序能实时更新它们显示的内容,所以看起来是动态的,即使它们用的是文本。非常酷!在我们的例子中,更新时间间隔很重要,因为一些统计数据(`%CPU` 和 `%MEM`)是基于上次屏幕更新的数值的。 + +因为我们运行在一个持久性的程序中,我们就可以输入一些命令来实时修改配置(而不是停止应用,然后用一个不同的命令行选项再次运行)。 + +按下 `h` 调用帮助界面,该界面也显示了默认延迟(屏幕更新的时间间隔)。这个值默认(大约)是 3 秒,但你可以输入 `d`(大概是 delay 的意思)或者 `s`(可能是 screen 或 seconds 的意思)来修改它。 + +#### 细节 + +在进程列表上面有一大堆有用的信息。有些细节看起来有点儿奇怪,让人困惑。但是一旦你花点儿时间来逐个过一遍,你会发现,在紧要关头,这些是非常有用的。 + +第一行包含系统的大致信息: + +* `top`:我们正在运行 `top`!你好!`top`! +* `XX:YY:XX`:当前时间,每次屏幕更新的时候更新 +* `up`(接下去是 `X day, YY:ZZ`):系统的 [uptime][2],或者自从系统启动后已经过去了多长时间 +* `load average`(后跟三个数字):分别是过去一分钟、五分钟、15 分钟的[系统负载][3] + +第二行(`Task`)显示了正在运行的任务的信息,不用解释。它显示了进程总数和正在运行的、休眠中的、停止的进程数和僵尸进程数。这实际上是上述 `S`(状态)列的总和。 + +第三行(`%Cpu(s)`)显示了按类型划分的 CPU 使用情况。数据是屏幕刷新之间的值。这些值是: + +* `us`:用户进程 +* `sy`:系统进程 +* `ni`:[nice][4] 用户进程 +* `id`:CPU 的空闲时间,这个值比较高时说明系统比较空闲 +* `wa`:等待时间,或者消耗在等待 I/O 完成的时间 +* `hi`:消耗在硬件中断的时间 +* `si`:消耗在软件中断的时间 +* `st`:“虚拟机管理程序从该虚拟机窃取的时间” + +你可以通过点击 `t`(toggle)来展开或折叠 `Task` 和 `%Cpu(s)` 行。 + +第四行(`Kib Mem`)和第五行(`KiB Swap`)提供了内存和交换空间的信息。这些数值是: + +* 总内存容量 +* 已用内存 +* 空闲内存 +* 内存的缓冲值 +* 交换空间的缓存值 + +默认它们是用 KiB 为单位展示的,但是按下 `E`(扩展内存缩放 extend memory scaling)可以轮换不同的单位:KiB、MiB、GiB、TiB、PiB、EiB(kilobytes、megabytes、gigabytes、terabytes、petabytes 和 exabytes) + +`top` 用户手册有更多选项和配置项信息。你可以运行 `man top` 来查看你系统上的文档。还有很多 [HTML 版的 man 手册][1],但是请留意,这些手册可能是针对不同 top 版本的。 + +### 两个 top 的替代品 + +你不必总是用 `top` 查看系统状态。你可以根据你的情况用其它工具来协助排查问题,尤其是当你想要更图形化或更专业的界面的时候。 + +#### htop + +`htop` 很像 `top`,但是它带来了一些非常有用的东西:它可以以图形界面展示 CPU 和内存使用情况。 + +![](https://opensource.com/sites/default/files/uploads/htop_preview.png) + +这是我们在刚才运行 `top` 的同一环境中 `htop` 的样子。显示更简洁,但功能却很丰富。 + +任务统计、负载、uptime 和进程列表仍然在,但是它有了漂亮、彩色、动态的每核 CPU 使用情况,还有图形化的内存使用情况。 + +以下是不同颜色的含义(你也可以通过按下 `h` 来获得这些信息的帮助)。 + +CPU 任务优先级或类型: + +* 蓝色:低优先级 +* 绿色:正常优先级 +* 红色:内核任务 +* 蓝色:虚拟任务 +* 条状图末尾的值是已用 CPU 的百分比 + +内存: + +* 绿色:已经使用的内存 +* 蓝色:缓冲的内存 +* 黄色:缓存内存 +* 条状图末尾的值显示已用内存和总内存 + +如果颜色对你没用,你可以运行 `htop -C` 来禁用它们;那样 `htop` 将使用不同的符号来展示 CPU 和内存类型。 + +它的底部有一组激活的快捷键提示,可以用来操作过滤结果或改变排序顺序。试着按一些快捷键看看它们能做什么。不过尝试 `F9` 时要小心,它会调出一个信号列表,这些信号会杀死(即停止)一个过程。我建议在生产环境之外探索这些选项。 + +`htop` 的作者 Hisham Muhammad(是的,`htop` 的名字就是源自 Hisham 的)在二月份的 [FOSDEM 2018][6] 做了一个[简短的演讲][5]。他阐述了 `htop` 不仅有简洁的图形界面,还有更现代的进程信息统计展示方式,这都是之前的工具(如 `top`)所不具备的。 + +你可以在[手册页面][7]或 [htop 网站][8]阅读更多关于 `htop` 的信息。(提示:网站背景是一个动态的 `htop`。) + +#### docker stats + +如果你在用 Docker,你可以运行 `docker stats` 来为容器状态生成一个有丰富上下文的界面。 + +这可能比 `top` 更有帮助,因为它不是按进程分类,而是按容器分类的。这点特别有用,当某个容器运行缓慢时,查看哪个容器耗资源最多比运行 `top` 再找到容器的进程要快。 + +借助于上面对 `top` 和 `htop` 术语的解释,你应该会更容易理解 `docker stats` 中的那些。然而,[docker stats 文档][9]对每一列都提供了详尽的描述。 + +--- + +via: https://opensource.com/article/18/8/top-tips-speed-up-computer + +作者:[Katie McLaughlin][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[ypingcn](https://github.com/ypingcn) +校对:[pityonline](https://github.com/pityonline) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://opensource.com/users/glasnt +[1]: http://man7.org/linux/man-pages/man1/top.1.html +[2]: https://en.wikipedia.org/wiki/Uptime +[3]: https://en.wikipedia.org/wiki/Load_(computing) +[4]: https://en.wikipedia.org/wiki/Nice_(Unix)#Etymology +[5]: https://www.youtube.com/watch?v=L25waVhy78o +[6]: https://fosdem.org/2018/schedule/event/htop/ +[7]: https://linux.die.net/man/1/htop +[8]: https://hisham.hm/htop/index.php +[9]: https://docs.docker.com/engine/reference/commandline/stats/ diff --git a/published/201808/20180814 How To Record Terminal Sessions As SVG Animations In Linux.md b/published/201808/20180814 How To Record Terminal Sessions As SVG Animations In Linux.md new file mode 100644 index 0000000000..b9df74963d --- /dev/null +++ b/published/201808/20180814 How To Record Terminal Sessions As SVG Animations In Linux.md @@ -0,0 +1,135 @@ +将 Linux 终端会话录制成 SVG 动画 +====== + +![Banner 图](https://www.ostechnix.com/wp-content/uploads/2018/08/termtosvg-720x340.png) + +录制终端会话可以满足我们不同类型的需求。通过录制终端会话,你可以完整记录你在终端中执行的操作,将其保存以供后续参考。通过录制终端会话,你还可以向青少年、学生或其它打算学习 Linux 的人展示各种 Linux 命令及其用例。值得庆幸的是,市面上已经有不少工具,可以帮助我们在类 Unix 操作系统下录制终端会话。我们已经介绍过一些可以帮助你录制终端会话的工具,可以在下面的链接中找到。 + ++ [如何录制你在终端中的所作所为][3] ++ [Asciinema – 录制终端会话并在网上分享][4] + +今天,我们要介绍另一款录制终端操作的工具,名字叫做 **Termtosvg**。从名字可以看出,Termtosvg 将你的终端会话录制成一个单独的 SVG 动画。它是一款简单的命令行工具,使用 **Python** 语言编写,可以生成轻量级、外观整洁的动画,可以嵌入到网页项目中。Termtosvg 支持自定义色彩主题color themes、终端 UI,还可以通过 [SVG 模板][1]完成动画控制。它兼容 asciinema 录制格式,支持 GNU/Linux,Mac OS 和 BSD 等操作系统。 + +### 安装 Termtosvg + +PIP 是一个面向 Python 语言编写的软件包的管理器,可以用于安装 Termtosvg。如果你没有安装 PIP,可以参考下面的指导: + +[如何使用 PIP 管理 Python 软件包][5] + +安装 PIP 后,运行如下命令安装 Termtosvg 工具: + +``` +$ pip3 install --user termtosvg +``` + +此外,还要安装渲染终端屏幕所需的依赖包: + +``` +$ pip3 install pyte python-xlib svgwrite +``` + +安装完毕,我们接下来生成 SVG 格式的终端会话。 + +### 将 Linux 终端会话录制成 SVG 动画 + +使用 `termtosvg` 录制终端会话十分容易。打开终端窗口,运行如下命令即可开始录制: + +``` +$ termtosvg +``` + +**注意:** 如果 `termtosvg` 命令不可用,重启操作系统一次即可。 + +运行 `termtosvg` 命令后,可以看到如下命令输出: + +``` +Recording started, enter "exit" command or Control-D to end + +``` + +你目前位于一个子 Shell 中,在这里可以像平常那样输入命令。你在终端中的所作所为都会被录制。 + +不妨随便输入一些命令: + +``` +$ mkdir mydirectory +$ cd mydirectory/ +$ touch file.txt +$ cd .. +$ uname -a + +``` + +操作完成后,使用组合键 `CTRL+D` 或者输入 `exit` 停止录制。录制结果将会保存在 `/tmp` 目录,(由于做了唯一性处理)文件名并不会重复。 + +![](https://www.ostechnix.com/wp-content/uploads/2018/08/Termtosvg-in-action-1-1.png) + +现在,你可以在命令行运行命令,使用你的浏览器打开 SVG 文件: + +``` +$ firefox /tmp/termtosvg_ddkehjpu.svg +``` + +你也可以在(图形界面的)浏览器中直接打开这个 SVG 文件( **File -> \** )。 + +我用 Firefox 浏览器打开的效果如下: + +![](https://www.ostechnix.com/wp-content/uploads/2018/08/Termtosvg-in-browser.gif) + +下面举例说明几种使用 Termtosvg 录制终端会话的方式。 + +我刚刚提到,Termtosvg 录制终端会话后默认保存成 `/tmp` 目录下的一个 SVG 动画文件。 + +但你可以指定 SVG 动画文件的文件名,例如 `animation.svg`;也可以指定一个存放路径,例如 `/home/sk/ostechnix/`。 + +``` +$ termtosvg /home/sk/ostechnix/animation.svg +``` + +录制终端会话并使用特定模板进行渲染: + +``` +$ termtosvg -t ~/templates/my_template.svg +``` + +使用指定的屏幕参数screen geometry录制终端会话: + +``` +$ termtosvg -g 80x24 animation.svg +``` + +使用 asciicast v2 格式录制终端会话: + +``` +$ termtosvg record recording.cast +``` + +将 asciicast 格式的录制结果渲染成 SVG 动画: + +``` +$ termtosvg render recording.cast animation.svg +``` + +欲了解更多细节,请参考 [**Termtosvg 手册**][2]。 + +好了,本次分享就到这里,希望对你有帮助。更多精彩内容,敬请期待! + +干杯! + +-------------------------------------------------------------------------------- + +via: https://www.ostechnix.com/how-to-record-terminal-sessions-as-svg-animations-in-linux/ + +作者:[SK][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[pinewall](https://github.com/pinewall) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.ostechnix.com/author/sk/ +[1]:https://nbedos.github.io/termtosvg/pages/templates.html +[2]:https://github.com/nbedos/termtosvg/blob/develop/man/termtosvg.md +[3]:https://www.ostechnix.com/record-everything-terminal/ +[4]:https://www.ostechnix.com/asciinema-record-terminal-sessions-share-web/ +[5]:https://www.ostechnix.com/manage-python-packages-using-pip/ diff --git a/published/201808/20180815 How the L1 Terminal Fault vulnerability affects Linux systems.md b/published/201808/20180815 How the L1 Terminal Fault vulnerability affects Linux systems.md new file mode 100644 index 0000000000..54cad9f239 --- /dev/null +++ b/published/201808/20180815 How the L1 Terminal Fault vulnerability affects Linux systems.md @@ -0,0 +1,69 @@ +L1 终端错误漏洞(L1TF)如何影响 Linux 系统 +====== + +> L1 终端错误(L1TF)影响英特尔处理器和 Linux 操作系统。让我们了解一下这个漏洞是什么,以及 Linux 用户需要为它做点什么。 + +![](https://images.idgesg.net/images/article/2018/08/l1tf-copy-100768129-large.jpg) + +昨天(LCTT 译注:本文发表于 2018/8/15)在英特尔、微软和红帽的安全建议中宣布,一个新发现的漏洞英特尔处理器(还有 Linux)的漏洞称为 L1TF 或 “L1 终端错误L1 Terminal Fault”,引起了 Linux 用户和管理员的注意。究竟什么是这个漏洞,谁应该担心它? + +### L1TF、 L1 Terminal Fault 和 Foreshadow + +处理器漏洞被称作 L1TF、L1 Terminal Fault 和 Foreshadow。研究人员在 1 月份发现了这个问题并向英特尔报告称其为 “Foreshadow”。它类似于过去发现的漏洞(例如 Spectre)。 + +此漏洞是特定于英特尔的。其他处理器不受影响。与其他一些漏洞一样,它之所以存在,是因为设计时为了优化内核处理速度,但允许其他进程访问数据。 + +**[另请阅读:[22 个必要的 Linux 安全命令][1]]** + +已为此问题分配了三个 CVE: + + * CVE-2018-3615:英特尔软件保护扩展Software Guard Extension(英特尔 SGX) + * CVE-2018-3620:操作系统和系统管理模式ystem Management Mode(SMM) + * CVE-2018-3646:虚拟化的影响 + +英特尔发言人就此问题发表了这一声明: + +> “L1 Terminal Fault 通过今年早些时候发布的微代码更新得到解决,再加上从今天开始提供的操作系统和虚拟机管理程序软件的相应更新。我们在网上提供了更多信息,并继续鼓励每个人更新操作系统,因为这是得到保护的最佳方式之一。我们要感谢 imec-DistriNet、KU Leuven、以色列理工学院,密歇根大学,阿德莱德大学和 Data61 的研究人员以及我们的行业合作伙伴,他们帮助我们识别和解决了这个问题。“ + +### L1TF 会影响你的 Linux 系统吗? + +简短的回答是“可能不会”。如果你因为在今年 1 月爆出的 [Spectre 和 Meltdown 漏洞][2]修补过系统,那你应该是安全的。与 Spectre 和 Meltdown 一样,英特尔声称真实世界中还没有系统受到影响的报告或者检测到。他们还表示,这些变化不太可能在单个系统上产生明显的性能影响,但它们可能对使用虚拟化操作系统的数据中心产生大的影响。 + +即使如此,仍然推荐频繁地打补丁。要检查你当前的内核版本,使用 `uname -r` 命令: + +``` +$ uname -r +4.18.0-041800-generic +``` + +### 更多资源 + +请查看如下资源以了解 L1TF 的更多细节,以及为什么会出现这个漏洞: + +- [L1TF explained in ~3 minutes (Red Hat)][5] +- [L1TF explained in under 11 minutes (Red Hat)][6] +- [Technical deep dive][7] +- [Red Hat explanation of L1TF][8] +- [Ubuntu updates for L1TF][9] + +-------------------------------------------------------------------------------- + +via: https://www.networkworld.com/article/3298157/linux/linux-and-l1tf.html + +作者:[Sandra Henry-Stocker][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[geekpi](https://github.com/geekpi) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://www.networkworld.com/author/Sandra-Henry_Stocker/ +[1]: https://www.networkworld.com/article/3272286/open-source-tools/22-essential-security-commands-for-linux.html +[2]: https://www.networkworld.com/article/3245813/security/meltdown-and-spectre-exploits-cutting-through-the-fud.html +[3]: https://www.facebook.com/NetworkWorld/ +[4]: https://www.linkedin.com/company/network-world +[5]: https://www.youtube.com/watch?v=kBOsVt0iXE4&feature=youtu.be +[6]: https://www.youtube.com/watch?v=kqg8_KH2OIQ +[7]: https://www.redhat.com/en/blog/deeper-look-l1-terminal-fault-aka-foreshadow +[8]: https://access.redhat.com/security/vulnerabilities/L1TF +[9]: https://blog.ubuntu.com/2018/08/14/ubuntu-updates-for-l1-terminal-fault-vulnerabilities diff --git a/published/201808/20180819 How to define and use functions in Linux Shell Script.md b/published/201808/20180819 How to define and use functions in Linux Shell Script.md new file mode 100644 index 0000000000..daa4547134 --- /dev/null +++ b/published/201808/20180819 How to define and use functions in Linux Shell Script.md @@ -0,0 +1,260 @@ +如何在 Linux Shell 编程中定义和使用函数 +====== + +函数是一段可复用的代码。我们通常把重复的代码放进函数中并且在不同的地方去调用它。库是函数的集合。我们可以在库中定义经常使用的函数,这样其它脚本便可以不再重复代码而使用这些函数。 + +![Functions-Linux-Shell-Script][1] + +本文我们将讨论诸多关于函数的内容和一些使用技巧。为了方便演示,我将在 Ubuntu 系统上使用 **Bourne Again SHell (Bash)**。 + +### 调用函数 + +在 Shell 中调用函数和调用其它命令是一模一样的。例如,如果你的函数名称为 `my_func`,你可以在命令行中像下面这样执行它: + +``` +$ my_func +``` + +如果你的函数接收多个参数,那么可以像下面这样写(类似命令行参数的使用): + +``` +$ my_func arg1 arg2 arg3 +``` + +### 定义函数 + +我们可以用下面的语法去定义一个函数: + +``` +function function_name { + Body of function +} +``` + +函数的主体可以包含任何有效的命令、循环语句和其它函数或脚本。现在让我们创建一个简单的函数,它向屏幕上显示一些消息(注:直接在命令行里写)。 + +``` +function print_msg { + echo "Hello, World" +} +``` + +现在,让我们执行这个函数: + +``` +$ print_msg +Hello, World +``` + +不出所料,这个函数在屏幕上显示了一些消息。 + +在上面的例子中,我们直接在终端里创建了一个函数。这个函数也可以保存到文件中。如下面的例子所示。 + +``` +#!/bin/bash +function print_msg { + echo "Hello, World" +} +print_msg +``` + +我们已经在 `function.sh` 文件中定义了这个函数。现在让我们执行这个脚本: + +``` +$ chmod +x function.sh +$ ./function.sh +Hello, World +``` + +你可以看到,上面的输出和之前的是一模一样的。 + +### 更多函数用法 + +在上一小节中我们定义了一个非常简单的函数。然而在软件开发的过程中,我们需要更多高级的函数,它可以接收多个参数并且带有返回值。在这一小节中,我们将讨论这种函数。 + +#### 向函数传递参数 + +我们可以像调用其它命令那样给函数提供参数。我们可以在函数里使用美元 `$` 符号访问到这些参数。例如,`$1` 表示第一个参数,`$2` 代表第二个参数,以此类推。 + +让我们修改下之前的函数,让它以参数的形式接收信息。修改后的函数就像这样: + +``` +function print_msg { + echo "Hello $1" +} +``` + +在上面的函数中我们使用 `$1` 符号访问第一个参数。让我们执行这个函数: + +``` +$ print_msg "LinuxTechi" +``` + +执行完后,生成如下信息: + +``` +Hello LinuxTechi +``` + +#### 从函数中返回数值 + +跟其它编程语言一样,Bash 提供了返回语句让我们可以向调用者返回一些数值。让我们举例说明: + +``` +function func_return_value { + return 10 +} +``` + +上面的函数向调用者返回 `10`。让我们执行这个函数: + +``` +$ func_return_value +$ echo "Value returned by function is: $?" +``` + +当你执行完,将会产生如下的输出结果: + +``` +Value returned by function is: 10 +``` + +**提示**:在 Bash 中使用 `$?` 去获取函数的返回值。 + +### 函数技巧 + +目前我们已经对 Bash 中的函数有了一些了解。现在让我们创建一些非常有用的 Bash 函数,它们可以让我们的生活变得更加轻松。 + +#### Logger + +让我们创建一个 `logger` 函数,它可以输出带有日期和时间的 log 信息。 + +``` +function log_msg { + echo "[`date '+ %F %T'` ]: $@" +} +``` + +执行这个函数: + +``` +$ log_msg "This is sample log message" +``` + +执行完,就会生成如下信息: + +``` +[ 2018-08-16 19:56:34 ]: This is sample log message +``` + +#### 显示系统信息 + +让我们创建一个显示 GNU/Linux 信息的函数 + +``` +function system_info { + echo "### OS information ###" + lsb_release -a + + echo + echo "### Processor information ###" + processor=`grep -wc "processor" /proc/cpuinfo` + model=`grep -w "model name" /proc/cpuinfo  | awk -F: '{print $2}'` + echo "Processor = $processor" + echo "Model     = $model" + + echo + echo "### Memory information ###" + total=`grep -w "MemTotal" /proc/meminfo | awk '{print $2}'` + free=`grep -w "MemFree" /proc/meminfo | awk '{print $2}'` + echo "Total memory: $total kB" + echo "Free memory : $free kB" +} +``` + +执行完后会生成以下信息: + +``` +### OS information ### +No LSB modules are available. +Distributor ID:           Ubuntu +Description:   Ubuntu 18.04.1 LTS +Release:         18.04 +Codename:    bionic + +### Processor information ### +Processor = 1 +Model     =  Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz + +### Memory information ### +Total memory: 4015648 kB +Free memory : 2915428 kB +``` + +#### 在当前目录下查找文件或者目录 + +下面的函数从当前目录下查找文件或者目录: + +``` +function search { + find . -name $1 +} +``` + +让我们使用下面的命令查找 `dir4` 这个目录: + +``` +$ search dir4 +``` + +当你执行完命令后,将会产生如下输出: + +``` +./dir1/dir2/dir3/dir4 +``` + +#### 数字时钟 + +下面的函数在终端里创建了一个简单的数字时钟: + +``` +function digital_clock { + clear + while [ 1 ] + do + date +'%T' + sleep 1 + clear + done +} +``` + +### 函数库 + +库是函数的集合。将函数定义在文件里并在当前环境中导入那个文件,这样可以创建函数库。 + +假设我们已经在 `utils.sh` 中定义好了所有函数,接着在当前的环境下使用下面的命令导入函数: + +``` +$ source utils.sh +``` + +之后你就可以像调用其它 Bash 命令那样执行库中任何的函数了。 + +### 总结 + +本文我们讨论了诸多可以提升效率的实用技巧。我希望这篇文章能够启发你去创造自己的技巧。 + +-------------------------------------------------------------------------------- + +via: https://www.linuxtechi.com/define-use-functions-linux-shell-script/ + +作者:[Pradeep Kumar][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[LuuMing](https://github.com/LuuMing) +校对:[pityonline](https://github.com/pityonline) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: http://www.linuxtechi.com/author/pradeep/ +[1]: https://www.linuxtechi.com/wp-content/uploads/2018/08/Functions-Linux-Shell-Script.jpg diff --git a/published/201808/20180821 A Collection Of More Useful Unix Utilities.md b/published/201808/20180821 A Collection Of More Useful Unix Utilities.md new file mode 100644 index 0000000000..2ff4011f39 --- /dev/null +++ b/published/201808/20180821 A Collection Of More Useful Unix Utilities.md @@ -0,0 +1,313 @@ +一套有用的 Unix 实用程序 +====== + +![](https://www.ostechnix.com/wp-content/uploads/2017/08/Moreutils-720x340.png) + +我们都了解 GNU 核心实用程序GNU Core Utilities,所有类 Unix 操作系统都预装了它们。它们是 GNU 操作系统中与文件、Shell 和 文本处理相关的基础实用工具。GNU 核心实用程序包括很多日常操作命令,例如 `cat`、`ls`、`rm`、`mkdir`、`rmdir`、`touch`、`tail` 和 `wc` 等。除了这些实用程序,还有更多有用的实用程序没有预装在类 Unix 操作系统中,它们汇集起来构成了 `moreutilis` 这个日益增长的集合。`moreutils` 可以在 GNU/Linux 和包括 FreeBSD,openBSD 及 Mac OS 在内的多种 Unix 类型操作系统上安装。 + +截至到编写这份指南时, `moreutils` 提供如下实用程序: + +* `chronic` – 运行程序并忽略正常运行的输出 +* `combine` – 使用布尔操作合并文件的行 +* `errno` – 查询 errno 名称及描述 +* `ifdata` – 获取网络接口信息,无需解析 `ifconfig` 的结果 +* `ifne` – 在标准输入非空的情况下运行程序 +* `isutf8` – 检查文件或标准输入是否采用 UTF-8 编码 +* `lckdo` – 带锁运行程序 +* `mispipe` – 使用管道连接两个命令,返回第一个命令的退出状态 +* `parallel` – 同时运行多个任务 +* `pee` – 将标准输入传递给多个管道 +* `sponge` – 整合标准输入并写入文件 +* `ts` – 为标准输入增加时间戳信息 +* `vidir` – 使用你默认的文本编辑器操作目录文件 +* `vipe` – 在管道中插入信息编辑 +* `zrun` – 自动解压并将其作为参数传递给命令 + +### 在 Linux 上安装 moreutils + +由于 `moreutils` 已经被打包到多种 Linux 发行版中,你可以使用发行版对应的软件包管理器安装 `moreutils`。 + +在 **Arch Linux** 或衍生的 **Antergos** 和 **Manjaro Linux** 上,运行如下命令安装 `moreutils`: + +``` +$ sudo pacman -S moreutils +``` + +在 **Fedora** 上,运行: + +``` +$ sudo dnf install moreutils +``` + +在 **RHEL**,**CentOS** 和 **Scientific Linux** 上,运行: + +``` +$ sudo yum install epel-release +$ sudo yum install moreutils +``` + +在 **Debian**,**Ubuntu** 和 **Linux Mint** 上,运行: + +``` +$ sudo apt-get install moreutils +``` + +### Moreutils – 打包更多有用的 Unix 实用程序 + +让我们看一下几个 `moreutils` 工具的用法细节。 + +#### combine 实用程序 + +正如 `combine` 名称所示,moreutils 中的这个实用程序可以使用包括 `and`,`not`,`or` 和 `xor` 在内的布尔操作,合并两个文件中的行。 + +* `and` – 输出 `file1` 和 `file2` 都包含的行。 +* `not` – 输出 `file1` 包含但 `file2` 不包含的行。 +* `or` – 输出 `file1` 或 `file2` 包含的行。 +* `xor` – 输出仅被 `file1` 或 `file2` 包含的行 + +下面举例说明,方便你理解该实用程序的功能。这里有两个文件,文件名分别为 `file1` 和 `file2`,其内容如下: + +``` +$ cat file1 +is +was +were +where +there + +$ cat file2 +is +were +there +``` + +下面,我使用 `and` 布尔操作合并这两个文件。 + +``` +$ combine file1 and file2 +is +were +there +``` + +从上例的输出中可以看出,`and` 布尔操作只输出那些 `file1` 和 `file2` 都包含的行;更具体的来说,命令输出为两个文件共有的行,即 is,were 和 there。 + +下面我们换成 `not` 操作,观察一下输出。 + +``` +$ combine file1 not file2 +was +where +``` + +从上面的输出中可以看出,`not` 操作输出 `file1` 包含但 `file2` 不包含的行。 + +#### ifdata 实用程序 + +`ifdata` 实用程序可用于检查网络接口是否存在,也可用于获取网络接口的信息,例如 IP 地址等。与预装的 `ifconfig` 和 `ip` 命令不同,`ifdata` 的输出更容易解析,这种设计的初衷是便于在 Shell 脚本中使用。 + +如果希望查看某个接口的 IP 地址,不妨以 `wlp9s0` 为例,运行如下命令: + +``` +$ ifdata -p wlp9s0 +192.168.43.192 255.255.255.0 192.168.43.255 1500 +``` + +如果只查看掩码信息,运行如下命令: + +``` +$ ifdata -pn wlp9s0 +255.255.255.0 +``` + +如果查看网络接口的物理地址,运行如下命令: + +``` +$ ifdata -ph wlp9s0 +A0:15:46:90:12:3E +``` + +如果判断接口是否存在,可以使用 `-pe` 参数: + +``` +$ ifdata -pe wlp9s0 +yes +``` + +#### pee 命令 + +该命令某种程度上类似于 `tee` 命令。 + +我们先用一个例子看一下 `tee` 的用法。 + +``` +$ echo "Welcome to OSTechNIx" | tee file1 file2 +Welcome to OSTechNIx +``` + +上述命令首先创建两个文件,名为 `file1` 和 `file2`;接着,将 “Welcome to OSTechNix” 行分别附加到两个文件中;最后,在终端中打印输出 “Welcome to OSTechNix”。 + +`pee` 命令提供类似的功能,但与 `tee` 又稍微有些差异。查看下面的例子: + +``` +$ echo "Welcome to OSTechNIx" | pee cat cat +Welcome to OSTechNIx +Welcome to OSTechNIx +``` + +从上面的命令输出中可以看出,有两个 `cat` 命令实例获取 `echo` 命令的输出并执行,因而终端中出现两个同样的输出。 + +#### sponge 实用程序 + +这是 `moreutils` 软件包中的另一个有用的实用程序。`sponge` 读取标准输入并写入到指定的文件中。与 Shell 中的重定向不同,`sponge` 接收到完整输入后再写入输出文件。 + +查看下面这个文本文件的内容: + +``` +$ cat file1 +I +You +Me +We +Us +``` + +可见,文件包含了一些无序的行;更具体的说,这些行“没有”按照字母顺序排序。如果希望将其内容安装字母顺序排序,你会怎么做呢? + +``` +$ sort file1 > file1_sorted +``` + +这样做没错,对吧?当然没错!在上面的命令中,我将 `file1` 文件内容按照字母顺序排序,将排序后的内容保存在 `file1_sorted` 文件中。但如果使用 `sponge` 命令,你可以在不创建新文件(即 `file1_sorted`)的情况下完成同样的任务,命令如下: + +``` +$ sort file1 | sponge file1 +``` + +那么,让我们检查一下文件内容是否已经按照字母顺序排序: + +``` +$ cat file1 +I +Me +Us +We +You +``` + +看到了吧?并不需要创建新文件。在脚本编程中,这非常有用。另一个好消息是,如果待写入的文件已经存在,`sponge` 会保持其权限信息permissions不变。 + +#### ts 实用程序 + +正如名称所示,`ts` 命令在每一行输出的行首增加时间戳timestamp。 + +查看如下命令的输出: + +``` +$ ping -c 2 localhost +PING localhost(localhost.localdomain (::1)) 56 data bytes +64 bytes from localhost.localdomain (::1): icmp_seq=1 ttl=64 time=0.055 ms +64 bytes from localhost.localdomain (::1): icmp_seq=2 ttl=64 time=0.079 ms + +--- localhost ping statistics --- +2 packets transmitted, 2 received, 0% packet loss, time 1018ms +rtt min/avg/max/mdev = 0.055/0.067/0.079/0.012 ms +``` + +下面,结合 `ts` 实用程序运行同样地命令: + +``` +$ ping -c 2 localhost | ts +Aug 21 13:32:28 PING localhost(localhost (::1)) 56 data bytes +Aug 21 13:32:28 64 bytes from localhost (::1): icmp_seq=1 ttl=64 time=0.063 ms +Aug 21 13:32:28 64 bytes from localhost (::1): icmp_seq=2 ttl=64 time=0.113 ms +Aug 21 13:32:28 +Aug 21 13:32:28 --- localhost ping statistics --- +Aug 21 13:32:28 2 packets transmitted, 2 received, 0% packet loss, time 4ms +Aug 21 13:32:28 rtt min/avg/max/mdev = 0.063/0.088/0.113/0.025 ms +``` + +对比输出可以看出,`ts` 在每一行行首增加了时间戳。下面给出另一个例子: + +``` +$ ls -l | ts +Aug 21 13:34:25 total 120 +Aug 21 13:34:25 drwxr-xr-x 2 sk users 12288 Aug 20 20:05 Desktop +Aug 21 13:34:25 drwxr-xr-x 2 sk users 4096 Aug 10 18:44 Documents +Aug 21 13:34:25 drwxr-xr-x 24 sk users 12288 Aug 21 13:06 Downloads +[...] +``` + +#### vidir 实用程序 + +`vidir` 实用程序可以让你使用 `vi` 编辑器(或其它 `$EDITOR` 环境变量指定的编辑器)编辑指定目录的内容。如果没有指定目录,`vidir` 会默认编辑你当前的目录。 + +下面的命令编辑 `Desktop` 目录的内容: + +``` +$ vidir Desktop/ +``` + +![vidir][2] + +上述命令使用 `vi` 编辑器打开了指定的目录,其中目录内的文件都会对应一个数字。下面你可以按照 `vi` 的操作方式来编辑目录中的这些文件:例如,删除行意味着删除目录中对应的文件,修改行中字符串意味着对文件进行重命名。 + +你也可以编辑子目录。下面的命令会编辑当前目录及所有子目录: + +``` +$ find | vidir - +``` + +请注意命令结尾的 `-`。如果 `-` 被指定为待编辑的目录,`vidir` 会从标准输入读取一系列文件名,列出它们让你进行编辑。 + +如果你只想编辑当前目录下的文件,可以使用如下命令: + +``` +$ find -type f | vidir - +``` + +只想编辑特定类型的文件,例如 `.PNG` 文件?你可以使用如下命令: + +``` +$ vidir *.png +``` + +这时命令只会编辑当前目录下以 `.PNG` 为后缀的文件。 + +#### vipe 实用程序 + +`vipe` 命令可以让你使用默认编辑器接收 Unix 管道输入,编辑之后使用管道输出供下一个程序使用。 + +执行下面的命令会打开 `vi` 编辑器(当然是我默认使用的编辑器),你可以编辑 `echo` 命令的管道输入(即 “Welcome to OSTechNix”),最后将编辑过的内容输出到终端中。 + +``` +$ echo "Welcome to OSTechNIx" | vipe +Hello World +``` + +从上面的输出可以看出,我通过管道将 “Welcome to OSTechNix” 输入到 `vi` 编辑器中,将内容编辑为 “Hello World”,最后显示该内容。 + +好了,就介绍这么多吧。我只介绍了一小部分实用程序,而 `moreutils` 包含更多有用的实用程序。我在文章开始的时候已经列出目前 `moreutils` 软件包内包含的实用程序,你可以通过 `man` 帮助页面获取更多相关命令的细节信息。举个例子,如果你想了解 `vidir` 命令,请运行: + +``` +$ man vidir +``` + +希望这些内容对你有所帮助。我还将继续分享其它有趣且实用的指南,如果你认为这些内容对你有所帮助,请分享到社交网络或专业圈子,也欢迎你支持 OSTechNix 项目。 + +干杯! + +-------------------------------------------------------------------------------- + +via: https://www.ostechnix.com/moreutils-collection-useful-unix-utilities/ + +作者:[SK][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[pinewall](https://github.com/pinewall) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.ostechnix.com/author/sk/ +[1]:data:image/gif;base64,lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7 +[2]:http://www.ostechnix.com/wp-content/uploads/2017/08/sk@sk_001-1.png diff --git a/published/20180802 Distrochooser Helps Linux Beginners To Choose A Suitable Linux Distribution.md b/published/20180802 Distrochooser Helps Linux Beginners To Choose A Suitable Linux Distribution.md new file mode 100644 index 0000000000..1cb44b2ed1 --- /dev/null +++ b/published/20180802 Distrochooser Helps Linux Beginners To Choose A Suitable Linux Distribution.md @@ -0,0 +1,76 @@ +Distrochooser 帮助 Linux 初学者选择合适的 Linux 发行版 +====== + +![](https://www.ostechnix.com/wp-content/uploads/2018/08/distrochooser-logo-720x340.png) + +你好 Linux 新手!今天,我为你们带来了一个好消息!你也许想知道如何选择合适的 Linux 发行版。当然,你可能已经咨询过一些 Linux 专家来帮助你的需要选择 Linux 发行版。你们中的一些人可能已经用 Google 搜索并浏览了各种资源、Linux 论坛、网站和博客来寻找完美的发行版。好了,你不必再那样做了。有了 **Distrochooser**,一个帮助你轻松找到 Linux 发行版的网站。 + +### Distrochooser 如何帮助 Linux 初学者选择合适的 Linux 发行版? + +Distrochooser 会根据你的答案向你询问一系列问题并建议你尝试不同的 Linux 发行版。激动吗?太好了!让我们继续看看如何找到合适的 Linux 发行版。单击以下链接开始。 + +![][2] + +你将被重定向到 Distrochooser 主页,其中有一个小测试在等待你注册。 + +![](https://www.ostechnix.com/wp-content/uploads/2018/08/distrochooser-home-page.png) + +你需要回答一系列问题(准确地说是 16 个问题)。问题同时有单选和多选。以下是完整的问题列表。 + + 1. 软件:使用情况 + 2. 计算机知识 + 3. Linux 知识 + 4. 安装:预设 + 5. 安装:需要 Live 测试么? + 6. 安装:硬件支持 + 7. 配置:帮助源 + 8. 发行版:用户体验概念 + 9. 发行版:价格 + 10. 发行版:范围 + 11. 发行版:意识形态 + 12. 发行版:隐私 + 13. 发行版:预设主题,图标和壁纸 + 14. 发行版:特色 + 15. 软件:管理 + 16. 软件:更新 + +仔细阅读问题并在相应问题下面选择合适的答案。Distrochooser 提供了更多选择来选择接近完美的发行版。 + + * 你总是可以跳过问题, + * 你可以随时点击“获取结果”, + * 你可以任意顺序回答, + * 你可以随时删除答案, + * 你可以在测试结束时对属性进行加权,以强调对你来说重要的内容。 + +选择问题的答案后,单击“Proceed”以转到下一个问题。完成后,单击“Get Result”按钮。你也可以通过单击答案下面的“Clear”按钮随时清除选择。 + +### 结果? + +我以前不相信 Distrochooser 会找到我想要的东西。哦,我错了!令我惊讶的是,它确实做得很好。结果对我来说几乎是准确的。我期待 Arch Linux 在结果中,结果确实是在推荐第一位,接下来是其他 11 个建议,如 NixOS、Void Linux、Qubes OS、Scientific Linux、Devuan、Gentoo Linux、Bedrock Linux、Slackware、CentOS、Linux from scratch、Redhat Enterprise Linux。总共有 12 个推荐,每个结果都非常详细,带有发行版的描述和主页。 + +![](https://www.ostechnix.com/wp-content/uploads/2018/08/distrochooser-result.png) + +我在 Reddit 上发布了 Distrochooser 链接,80% 的用户可以找到合适的 Linux 发行版。但是,我不会声称 Distrochooser 足以为每个人找到好结果。一些用户对调查结果感到失望,甚至结果与他们使用中或者想要使用的一点不接近。因此,我强烈建议你在尝试任何 Linux 之前咨询其他 Linux 专家、网站和论坛。你可以在[**这里**][3]阅读完整的 Reddit 讨论。 + +你在等什么?进入 Distrochooser 网站并为你选择合适的 Linux 发行版吧。 + +就是这些了。还有更多好东西。敬请期待! + +干杯! + + + +-------------------------------------------------------------------------------- + +via: https://www.ostechnix.com/distrochooser-helps-linux-beginners-to-choose-a-suitable-linux-distribution/ + +作者:[SK][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[geekpi](https://github.com/geekpi) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.ostechnix.com/author/sk/ +[2]:https://distrochooser.de/en +[3]:https://www.reddit.com/r/linux/comments/93p6az/distrochooser_helps_linux_beginners_to_choose_a/ diff --git a/published/20180803 10 Popular Windows Apps That Are Also Available on Linux.md b/published/20180803 10 Popular Windows Apps That Are Also Available on Linux.md new file mode 100644 index 0000000000..7e49ec1195 --- /dev/null +++ b/published/20180803 10 Popular Windows Apps That Are Also Available on Linux.md @@ -0,0 +1,137 @@ +10 个在 Linux 上也有的流行的 Windows 程序 +====== + +![](https://www.fossmint.com/wp-content/uploads/2018/08/Install-Windows-Apps-on-Linux.png) + +回顾过去,2018 年是 Linux 社区的好年景。许多仅在 Windows 和/或 Mac上 有的程序可在 Linux 平台上使用了,而且不用麻烦。向 [Snap][3] 和 [Flatpak][4] 技术致敬,这些技术已经为 Linux 用户带来了许多“受限制”的程序。 + +**另请阅读**:[很酷的 Linux 程序和工具大全][5] + +今天,我们为你提供了一个有名的 Windows 程序列表,你不需要寻找它们的替代品,因为它们已经在 Linux 上可用。 + +### 1、Skype + +它可以说是世界上最受欢迎的 VoIP 程序,**Skype** 提供出色的视频和语音通话质量,以及其他功能,如拨打本地和国际电话、固定电话、即时消息、表情符号等功能。 + +``` +$ sudo snap install skype --classic +``` + +### 2、Spotify + +**Spotify** 是最流行的音乐流媒体平台,在很长一段时间里,Linux 用户需要使用脚本和一些手段才能在他们的机器上设置该程序,感谢 snap,安装和使用 Spotify 就像点击一个按钮那样简单。 + +``` +$ sudo snap install spotify +``` + +### 3、Minecraft + +**Minecraft** 被证明是一款年度好游戏。更酷的是,它持续地得到维护。如果你不了解 Minecraft,它是一款冒险游戏,它可以让你在一个无限无边的虚拟世界中使用积木创建任何你想创建的虚拟事物。 + +``` +$ sudo snap install minecraft +``` + +### 4、JetBrains Dev Suite + +**JetBrains** 以其高级的开发 IDE 套件而闻名,他们这个最受欢迎的程序声称可在 Linux 上使用而不会有任何麻烦。 + +#### 安装 IDEA Community – Java IDE + +``` +$ sudo snap install intellij-idea-community --classic +``` + +#### 安装 PyCharm EDU – Python IDE + +``` +$ sudo snap install pycharm-educational --classic +``` + +#### 安装 PhpStorm – PHP IDE + +``` +$ sudo snap install phpstorm --classic +``` + +#### 安装 WebStorm – JavaScript IDE + +``` +$ sudo snap install webstorm --classic +``` + +#### 安装 RubyMine – Ruby and Rails IDE + +``` +$ sudo snap install rubymine --classic +``` + +### 5、PowerShell + +**PowerShell** 是一个用于管理 PC 自动化和配置的平台,它提供了一个带有相关脚本语言的命令行 shell。如果你认为它仅在 Windows 上可用,那么请再想一想。 + +``` +$ sudo snap install powershell --classic +``` + +### 6、Ghost + +**Ghost** 是一款现代桌面程序,可让用户在无干扰的环境中管理多个 Ghost 博客、杂志、在线出版物等。 + +``` +$ sudo snap install ghost-desktop +``` + +### 7、MySQL Workbench + +**MySQL Workbench** 是一个 GUI 程序,用于设计和管理集成 SQL 功能的数据库。 + +- [**下载 MySQL Workbench**][6] + +### 8、PlayOnLinux 中的 Adobe App Suite + +你可能错过了我们在 [PlayOnLinux][7] 上发表的文章,所以这是另一个了解的机会。 + +PlayOnLinux 基本上是 **wine** 的改进版本,允许用户更轻松地安装 Adobe 的创意云程序。请注意,试用和订阅限制仍然适用。 + +- [**如何使用 PlayOnLinux**][8] + +### 9、Slack + +这据说是开发人员和项目经理之间最常用的团队沟通软件,**Slack** 提供了每个人似乎无法满足的有各种文档和消息管理功能的工作空间。 + +``` +$ sudo snap install slack --classic +``` + +### 10、Blender + +**Blender** 是最受欢迎的 3D 创作程序之一。它是免费的、开源的,并且支持完整 3D 管道。 + +``` +$ sudo snap install blender --classic +``` + +就是这些了!我们知道列表还有很多,但我们只能列出这么多。我们是否省略了你认为应该将其列入清单的任何程序?在下面的评论栏添加你的建议。 + +-------------------------------------------------------------------------------- + +via: https://www.fossmint.com/install-popular-windows-apps-on-linux/ + +作者:[Martins D. Okoi][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[geekpi](https://github.com/geekpi) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.fossmint.com/author/dillivine/ +[1]:https://plus.google.com/share?url=https://www.fossmint.com/install-popular-windows-apps-on-linux/ (Share on Google+) +[2]:https://www.linkedin.com/shareArticle?mini=true&url=https://www.fossmint.com/install-popular-windows-apps-on-linux/ (Share on LinkedIn) +[3]:https://www.fossmint.com/what-are-ubuntu-snaps-and-how-are-they-important/ +[4]:https://www.fossmint.com/install-flatpak-in-linux/ +[5]:https://www.fossmint.com/awesome-linux-software/ +[6]:https://dev.mysql.com/downloads/workbench/ +[7]:https://www.fossmint.com/playonlinux-another-open-source-solution-for-linux-game-lovers/ +[8]:https://www.fossmint.com/adobe-creative-cloud-install-adobe-apps-on-linux/ diff --git a/published/20180804 Installing Andriod on VirtualBox.md b/published/20180804 Installing Andriod on VirtualBox.md new file mode 100644 index 0000000000..5f69eee83a --- /dev/null +++ b/published/20180804 Installing Andriod on VirtualBox.md @@ -0,0 +1,162 @@ +在 VirtualBox 中安装 Android 系统 +====== + +如果你正在开发 Android 应用,也许会遇到小麻烦。诚然,ios 移动开发有 macOS 系统平台为其提供友好便利性, Android 开发仅有支持少部分 Android 系统(其中还包括可穿戴设备系统)的 Android Studio 工具。 + +毋庸置疑,所有的二进制工具、SDK 工具、开发框架工具以及调试器都会产生大量日志和其他各种文件,使得你的文件系统很混乱。一个有效的解决方法就是在 VirtualBox 中安装 Android 系统,这样还解决了 Android 开发中最为棘手问题之一 —— 设备模拟器。你可以在该虚拟机里测试应用程序,也可以使用 Android 的内部功能。因此,让我们迫不及待的开始吧! + +### 准备工作 + +首先,你需要在你的系统上安装 VirtualBox,可从[这里][1]下载 Windows 版本、macOS 版本或者各种 Linux 版本的 VitualBox。然后,你需要一个能在 x86 平台运行的 Android 镜像,因为 VirtualBox 为虚拟机提供运行 x86 或者 x86\_64(即 AMD64)平台的功能。 + +虽然大部分 Android 设备都在 ARM 上运行,但我们依然可以从 [Android on x86 项目][2] 中获得帮助。这些优秀的开发者已经将 Android 移植到 x86 平台上运行(包括实体机和虚拟机),我们可以下载最新版本的 Android 7.1。你也可以用之前更为稳定的版本,本文写作时最新稳定版是 Android 6.0。 + +### 创建 VM 虚拟机 + +打开 VirtualBox,单击左上角的 “新建” 按钮,在弹出的窗口中选择 “类型:Linux” ,然后根据下载的 ISO 镜像来确定版本,x86 对应 “32-bit”,x86_64 对应 “64-bit”,此处选择 “Linux 2.6 / 3.x / 4.x (64-bit)”。 + +RAM 大小设置为 2 GB 到你系统能提供的最大内存之间。如果你想模拟真实的使用环境你可以设置 6 GB RAM 和 32 GB ROM。 + +![][3] + +![][4] + +创建完成后,你还需要做一些设置,添加更多的处理器核心,提高开机显示内存。在 VM 上打开设置选项,“设置 -> 系统 -> 处理器”,如果硬件条件允许,可以多分配一些处理器。 + +![][5] + +在 “设置 -> 显示 -> 显存大小” 中,你可以分配一大块内存并开启 3D 加速功能。 + +![][6] + +现在我们可以启动 VM 虚拟机了。 + +### 安装 Android + +首次启动 VM 虚拟机,VirtualBox 会提示你需要提供启动媒介,选择之前下载好的Android 镜像。 + +![][7] + +下一步,如果想长时间使用 Android,选择 “Installation” 选项,你也可以选择 Live 模式体验 Android 环境。 + +![][8] + +按回车键。 + +#### 分区 + +分区是通过文本界面操作,并没有友好的 GUI 界面,所以每个操作都需要小心对待。例如,在第一屏中还没有创建分区并且只检测到原始(虚拟)硬盘时显示如下。 + +![][9] + +红色字母 `C` 和 `D` 表明 `C` 开头选项可以创建或者修改分区,`D` 开头选项可以检测设备。你可以选择 `D` 开头选项,然后它就会检测硬盘,也可不进行这步操作,因为在启动的时候它会自动检测。 + +我们选择 `C` 开头选项,在虚拟盘中创建分区。官方不推荐使用 GPT 格式,所以我们选择 “No” 并按回车键。 + +![][10] + +现在你被引导到 fdisk 工具页面。 + +![][11] + +为了简洁起见,我们就只创建一个较大的分区,使用方向键来选择 “New” ,然后选择 “Primary”,按回车键以确认。 + +![][12] + +分区大小系统已经为你计算好了,按回车键确认。 + +![][13] + +这个分区就是 Android 系统所在的分区,所以需要它是可启动的。选择 “Bootable”,然后按回车键(上方表格中 “Flags” 标志下面会出现 “boot” 标志),进一步,选择 “Write” 选项,保存刚才的操作记录并写入分区表。 + +![][14] + +现在你可以选择退出分区工具,然后继续安装过程。 + +![][15] + +#### 文件系统格式化为 EXT4 并安装 Android + +在“Choose Partition”分区页面上会出现一个刚刚我们创建的分区,选择它并点击“OK”进入。 + +![][16] + +在下一个菜单中选择 Ext4 作为实际的文件系统,在下一页中选择 “Yes” 然后格式化开始。会提示是否安装 GRUB 引导工具以及是否允许在目录 `/system` 进行读写,都选择 “Yes” 。现在,安装进程开始。 + +安装完成后,当系统提示可以重启的时候你可以安全地重启系统。在重启之前,你可以先关机,然后在 VitualBox 的 “设置 -> 存储” 中检查 Android iso 镜像是否还连接在虚拟机上,如果在,将它移除。 + +![][17] + +移除安装媒介并保存修改,再去启动 VM 虚拟机。 + +#### 运行 Android + +在 GRUB 引导界面,有调试模式和普通模式的选项。我们选择默认选项,如下图所示。 + +![][18] + +如果一切正常,你将会看到如下界面: + +![][19] + +如今的 Android 系统使用触摸交互而不是鼠标。不过 Android-x86 平台提供了鼠标操作支持,但开始时可能需要方向键来辅助操作。 + +![][20] + +移动到”let’s go“按钮并按下回车键。选择 “Set up as new” 选项,回车确认。 + +![][21] + +在提示用谷歌账户登陆之前,系统检查更新并检测设备信息。你可以跳过这一步,直接去设置日期和时间、用户名等。 + +还有一些其他的选项,和让你设置一个新的 Android 设备类似。选择 “I Agree” 选项同意有关更新、服务等的相应的选项,当然谷歌的服务条款是不得不同意的。 + +![][22] + +在这之后,因为它是个虚拟机,所以可能需要添加额外的 email 账户来设置 “On-body detection”,大部分的选项对我们来说都没有多大作用,因此可以选择 ”All Set“。 + +接下来,它会提示你选择主屏应用,这个根据个人需求选择。现在我们进入了一个虚拟的 Android 系统。 + +![][23] + +如果你需要在 VM 做一些交互测试,有个可触摸屏幕会提供很大的方便,因为那样才更接近真实使用环境。 + +希望这篇教程会给你带来帮助。 + +-------------------------------------------------------------------------------- + +via: https://linuxhint.com/install_android_virtualbox/ + +作者:[Ranvir Singh][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[jrglinux](https://github.com/jrglinux) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://linuxhint.com/author/sranvir155/ +[1]:https://www.virtualbox.org/wiki/Downloads +[2]:http://www.android-x86.org/ +[3]:https://linuxhint.com/wp-content/uploads/2018/08/a.png +[4]:https://linuxhint.com/wp-content/uploads/2018/08/a1.png +[5]:https://linuxhint.com/wp-content/uploads/2018/08/a2.png +[6]:https://linuxhint.com/wp-content/uploads/2018/08/a3.png +[7]:https://linuxhint.com/wp-content/uploads/2018/08/a4.png +[8]:https://linuxhint.com/wp-content/uploads/2018/08/a5.png +[9]:https://linuxhint.com/wp-content/uploads/2018/08/a6.png +[10]:https://linuxhint.com/wp-content/uploads/2018/08/a7.png +[11]:https://linuxhint.com/wp-content/uploads/2018/08/a8.png +[12]:https://linuxhint.com/wp-content/uploads/2018/08/a9.png +[13]:https://linuxhint.com/wp-content/uploads/2018/08/a10.png +[14]:https://linuxhint.com/wp-content/uploads/2018/08/a11.png +[15]:https://linuxhint.com/wp-content/uploads/2018/08/a12.png +[16]:https://linuxhint.com/wp-content/uploads/2018/08/a13.png +[17]:https://linuxhint.com/wp-content/uploads/2018/08/a14.png +[18]:https://linuxhint.com/wp-content/uploads/2018/08/a16.png +[19]:https://linuxhint.com/wp-content/uploads/2018/08/a17.png +[20]:https://linuxhint.com/wp-content/uploads/2018/08/a18.png +[21]:https://linuxhint.com/wp-content/uploads/2018/08/a19.png +[22]:https://linuxhint.com/wp-content/uploads/2018/08/a20.png +[23]:https://linuxhint.com/wp-content/uploads/2018/08/a21.png + + diff --git a/published/20180806 Anatomy of a Linux DNS Lookup - Part IV.md b/published/20180806 Anatomy of a Linux DNS Lookup - Part IV.md new file mode 100644 index 0000000000..e2f893b210 --- /dev/null +++ b/published/20180806 Anatomy of a Linux DNS Lookup - Part IV.md @@ -0,0 +1,161 @@ +Linux DNS 查询剖析(第四部分) +============================================ + +在 [Linux DNS 查询剖析(第一部分)][1],[Linux DNS 查询剖析(第二部分)][2] 和 [Linux DNS 查询剖析(第三部分)][3] 中,我们已经介绍了以下内容: + +* `nsswitch` +* `/etc/hosts` +* `/etc/resolv.conf` +* `ping` 与 `host` 查询方式的对比 +* `systemd` 和对应的 `networking` 服务 +* `ifup` 和 `ifdown` +* `dhclient` +* `resolvconf` +* `NetworkManager` +* `dnsmasq` + +在第四部分中,我将介绍容器如何完成 DNS 查询。你想的没错,也不是那么简单。 + +### 1) Docker 和 DNS + +在 [Linux DNS 查询剖析(第三部分)][3] 中,我们介绍了 `dnsmasq`,其工作方式如下:将 DNS 查询指向到 localhost 地址 `127.0.0.1`,同时启动一个进程监听 `53` 端口并处理查询请求。 + +在按上述方式配置 DNS 的主机上,如果运行了一个 Docker 容器,容器内的 `/etc/resolv.conf` 文件会是怎样的呢? + +我们来动手试验一下吧。 + +按照默认 Docker 创建流程,可以看到如下的默认输出: + +``` +$ docker run  ubuntu cat /etc/resolv.conf +# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8) +#     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN +# 127.0.0.53 is the systemd-resolved stub resolver. +# run "systemd-resolve --status" to see details about the actual nameservers. + +search home +nameserver 8.8.8.8 +nameserver 8.8.4.4 +``` + +奇怪! + +#### 地址 `8.8.8.8` 和 `8.8.4.4` 从何而来呢? + +当我思考容器内的 `/etc/resolv.conf` 配置时,我的第一反应是继承主机的 `/etc/resolv.conf`。但只要稍微进一步分析,就会发现这样并不总是有效的。 + +如果在主机上配置了 `dnsmasq`,那么 `/etc/resolv.conf` 文件总会指向 `127.0.0.1` 这个回环地址loopback address。如果这个地址被容器继承,容器会在其本身的网络上下文networking context中使用;由于容器内并没有运行(在 `127.0.0.1` 地址的)DNS 服务器,因此 DNS 查询都会失败。 + +“有了!”你可能有了新主意:将 _主机的_ 的 IP 地址用作 DNS 服务器地址,其中这个 IP 地址可以从容器的默认路由default route中获取: + +``` +root@79a95170e679:/# ip route +default via 172.17.0.1 dev eth0 +172.17.0.0/16 dev eth0 proto kernel scope link src 172.17.0.2 +``` + +#### 使用主机 IP 地址真的可行吗? + +从默认路由中,我们可以找到主机的 IP 地址 `172.17.0.1`,进而可以通过手动指定 DNS 服务器的方式进行测试(你也可以更新 `/etc/resolv.conf` 文件并使用 `ping` 进行测试;但我觉得这里很适合介绍新的 `dig` 工具及其 `@` 参数,后者用于指定需要查询的 DNS 服务器地址): + +``` +root@79a95170e679:/# dig @172.17.0.1 google.com | grep -A1 ANSWER.SECTION +;; ANSWER SECTION: +google.com.             112     IN      A       172.217.23.14 +``` + +但是还有一个问题,这种方式仅适用于主机配置了 `dnsmasq` 的情况;如果主机没有配置 `dnsmasq`,主机上并不存在用于查询的 DNS 服务器。 + +在这个问题上,Docker 的解决方案是忽略所有可能的复杂情况,即无论主机中使用什么 DNS 服务器,容器内都使用 Google 的 DNS 服务器 `8.8.8.8` 和 `8.8.4.4` 完成 DNS 查询。 + +_我的经历:在 2013 年,我遇到了使用 Docker 以来的第一个问题,与 Docker 的这种 DNS 解决方案密切相关。我们公司的网络屏蔽了 `8.8.8.8` 和 `8.8.4.4`,导致容器无法解析域名。_ + +这就是 Docker 容器的情况,但对于包括 Kubernetes 在内的容器 编排引擎orchestrators,情况又有些不同。 + +### 2) Kubernetes 和 DNS + +在 Kubernetes 中,最小部署单元是 pod;它是一组相互协作的容器,共享 IP 地址(和其它资源)。 + +Kubernetes 面临的一个额外的挑战是,将 Kubernetes 服务请求(例如,`myservice.kubernetes.io`)通过对应的解析器resolver,转发到具体服务地址对应的内网地址private network。这里提到的服务地址被称为归属于“集群域cluster domain”。集群域可由管理员配置,根据配置可以是 `cluster.local` 或 `myorg.badger` 等。 + +在 Kubernetes 中,你可以为 pod 指定如下四种 pod 内 DNS 查询的方式。 + +**Default** + +在这种(名称容易让人误解)的方式中,pod 与其所在的主机采用相同的 DNS 查询路径,与前面介绍的主机 DNS 查询一致。我们说这种方式的名称容易让人误解,因为该方式并不是默认选项!`ClusterFirst` 才是默认选项。 + +如果你希望覆盖 `/etc/resolv.conf` 中的条目,你可以添加到 `kubelet` 的配置中。 + +**ClusterFirst** + +在 `ClusterFirst` 方式中,遇到 DNS 查询请求会做有选择的转发。根据配置的不同,有以下两种方式: + +第一种方式配置相对古老但更简明,即采用一个规则:如果请求的域名不是集群域的子域,那么将其转发到 pod 所在的主机。 + +第二种方式相对新一些,你可以在内部 DNS 中配置选择性转发。 + +下面给出示例配置并从 [Kubernetes 文档][4]中选取一张图说明流程: + +``` +apiVersion: v1 +kind: ConfigMap +metadata: + name: kube-dns + namespace: kube-system +data: + stubDomains: | + {"acme.local": ["1.2.3.4"]} + upstreamNameservers: | + ["8.8.8.8", "8.8.4.4"] +``` + +在 `stubDomains` 条目中,可以为特定域名指定特定的 DNS 服务器;而 `upstreamNameservers` 条目则给出,待查询域名不是集群域子域情况下用到的 DNS 服务器。 + +这是通过在一个 pod 中运行我们熟知的 `dnsmasq` 实现的。 + +![kubedns](https://zwischenzugs.files.wordpress.com/2018/08/kubedns.png?w=525) + +剩下两种选项都比较小众: + +**ClusterFirstWithHostNet** + +适用于 pod 使用主机网络的情况,例如绕开 Docker 网络配置,直接使用与 pod 对应主机相同的网络。 + +**None** + +`None` 意味着不改变 DNS,但强制要求你在 `pod` 规范文件specification的 `dnsConfig` 条目中指定 DNS 配置。 + +### CoreDNS 即将到来 + +除了上面提到的那些,一旦 `CoreDNS` 取代 Kubernetes 中的 `kube-dns`,情况还会发生变化。`CoreDNS` 相比 `kube-dns` 具有可配置性更高、效率更高等优势。 + +如果想了解更多,参考[这里][5]。 + +如果你对 OpenShift 的网络感兴趣,我曾写过一篇[文章][6]可供你参考。但文章中 OpenShift 的版本是 3.6,可能有些过时。 + +### 第四部分总结 + +第四部分到此结束,其中我们介绍了: + +* Docker DNS 查询 +* Kubernetes DNS 查询 +* 选择性转发(子域不转发) +* kube-dns + +-------------------------------------------------------------------------------- + +via: https://zwischenzugs.com/2018/08/06/anatomy-of-a-linux-dns-lookup-part-iv/ + +作者:[zwischenzugs][a] +译者:[pinewall](https://github.com/pinewall) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://zwischenzugs.com/ +[1]:https://linux.cn/article-9943-1.html +[2]:https://linux.cn/article-9949-1.html +[3]:https://linux.cn/article-9972-1.html +[4]:https://kubernetes.io/docs/tasks/administer-cluster/dns-custom-nameservers/#impacts-on-pods +[5]:https://coredns.io/ +[6]:https://zwischenzugs.com/2017/10/21/openshift-3-6-dns-in-pictures/ diff --git a/published/20180806 Installing and using Git and GitHub on Ubuntu Linux- A beginner-s guide.md b/published/20180806 Installing and using Git and GitHub on Ubuntu Linux- A beginner-s guide.md new file mode 100644 index 0000000000..5c2e7d40b5 --- /dev/null +++ b/published/20180806 Installing and using Git and GitHub on Ubuntu Linux- A beginner-s guide.md @@ -0,0 +1,158 @@ +初学者指南:在 Ubuntu Linux 上安装和使用 Git 和 GitHub +====== + +Github 是一个存放着世界上最棒的一些软件项目的宝藏,这些软件项目由全世界的开发者无私贡献。这个看似简单,实则非常强大的平台因为大大帮助了那些对开发大规模软件感兴趣的开发者而被开源社区所称道。 + +这篇向导是对于安装和使用 GitHub 的的一个快速说明,本文还将涉及诸如创建本地仓库,如何链接这个本地仓库到包含你的项目的远程仓库(这样每个人都能看到你的项目了),以及如何提交改变并最终推送所有的本地内容到 Github。 + +请注意这篇向导假设你对 Git 术语有基本的了解,如推送、拉取请求(PR)、提交、仓库等等。并且希望你在 GitHub 上已注册成功并记下了你的 GitHub 用户名,那么我们这就进入正题吧: + +### 1、在 Linux 上安装 Git + +下载并安装 Git: + +``` +sudo apt-get install git +``` + +上面的命令适用于 Ubuntu 并且应该在所有最新版的 Ubuntu 上都能工作,它们在 Ubuntu 16.04 和 Ubuntu 18.04 LTS(Bionic Beaver)上都测试过,在将来的版本上应该也能工作。 + +### 2、配置 GitHub + +一旦安装完成,接下去就是配置 GitHub 用户的详细配置信息。请使用下面的两条命令,并确保用你自己的 GitHub 用户名替换 `user_name`,用你创建 GitHub 账户的电子邮件替换 `email_id`。 + +``` +git config --global user.name "user_name" +git config --global user.email "email_id" +``` + +下面的图片显示的例子是如何用我的 GitHub 用户名:“akshaypai” 和我的邮件地址 “abc123@gmail.com” 来配置上面的命令。 + +[![Git config][3]][4] + +### 3、创建本地仓库 + +在你的系统上创建一个目录。它将会被作为本地仓库使用,稍后它会被推送到 GitHub 的远程仓库。请使用如下命令: + +``` +git init Mytest +``` + +如果目录被成功创建,你会看到如下信息: + +``` +Initialized empty Git repository in /home/akshay/Mytest/.git/ +``` + +这行信息可能随你的系统不同而变化。 + +这里,`Mytest` 是创建的目录,而 `init` 将其转化为一个 GitHub 仓库。将当前目录改为这个新创建的目录。 + +``` +cd Mytest +``` + +### 4、新建一个 README 文件来描述仓库 + +现在创建一个 `README` 文件并输入一些文本,如 “this is git setup on linux”。README 文件一般用于描述这个仓库用来放置什么内容或这个项目是关于什么的。例如: + +``` +gedit README +``` + +你可以使用任何文本编辑器。我喜欢使用 gedit。`README` 文件的内容可以为: + +``` +This is a git repo +``` + +### 5、将仓库里的文件加入一个索引 + +这是很重要的一步。这里我们会将所有需要推送到 GitHub 的内容都加入一个索引。这些内容可能包括你第一次加入仓库的文本文件或者应用程序,也有可能是对已存在文件的一些编辑(文件的一个更新版本)。 + +既然我们已经有了 `README` 文件,那么让我们创建一个别的文件吧,如一个简单的 C 程序,我们叫它 `sample.c`。文件内容是: + +``` +#include +int main() +{ + printf("hello world"); + return 0; +} +``` + +现在我们有两个文件了。`README` 和 `sample.c`。 + +用下面的命令将它们加入索引: + +``` +git add README +git add smaple.c +``` + +请注意 `git add` 命令能将任意数量的文件和目录加入到索引。这里,当我说 “索引” 的时候,我是指一个有一定空间的缓冲区,这个缓冲区存储了所有已经被加入到 Git 仓库的文件或目录。 + +### 6、将所作的改动加入索引 + +所有的文件都加好以后,你就可以提交了。这意味着你已经确定了最终的文件改动(或增加),现在它们已经准备好被上传到我们自己的仓库了。请使用命令: + +``` +git commit -m "some_message" +``` + +“some_message” 在上面的命令里可以是一些简单的信息如“我的第一次提交”或者“编辑了readme 文件”,等等。 + +### 7、在 GitHub 上创建一个仓库 + +在 GitHub 上创建一个仓库。请注意仓库的名字必须和你本地创建的仓库的名字严格一致。在这个例子里是 “Mytest”。请首先登录你的 [GitHub](https://github.com) 账户。点击页面右上角的 “+” 符号,并选择“create nw repository”。如下图所示填入详细信息,点击 “create repository”。 + +[![Creating a repository on GitHub][5]][6] + +一旦创建完成,我们就能将本地的仓库推送到 GitHub 你名下的仓库,用下列命令连接 GitHub 上的仓库: + +> 请注意:请确保在运行下列命令前替换了路径中的 “user_name” 和 “Mytest” 为你的 GitHub 用户名和目录名! + +``` +git remote add origin https://github.com/user\_name/Mytest.git> +``` + +### 8、将本地仓库里的文件推送到 GitHub 仓库 + +最后一步是用下列的命令将本地仓库的内容推送到远程仓库(GitHub): + +``` +git push origin master +``` + +当提示登录名和密码时键入登录名和密码。 + +下面的图片显示了步骤 5 到步骤 8 的流程 + +[![Pushing files in local repository to GitHub repository][7]][8] + +上述将 Mytest 目录里的所有内容(文件)推送到了 GitHub。对于以后的项目或者创建新的仓库,你可以直接从步骤 3 开始。最后,如果你登录你的 GitHub 账户并点击你的 Mytest 仓库,你会看到这两个文件:`README` 和 `sample.c` 已经被上传并像如下图片显示: + +[![Content uploaded to Github][9]][10] + +-------------------------------------------------------------------------------- + +via: https://www.howtoforge.com/tutorial/install-git-and-github-on-ubuntu/ + +作者:[Akshay Pai][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[DavidChenLiang](https://github.com/DavidChenLiang) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.howtoforge.com/tutorial/installing-tensorflow-neural-network-software-for-cpu-and-gpu-on-ubuntu-16-04/ +[1]:https://github.com/ +[2]:https://www.howtoforge.com/cdn-cgi/l/email-protection +[3]:https://www.howtoforge.com/images/ubuntu_github_getting_started/config.png +[4]:https://www.howtoforge.com/images/ubuntu_github_getting_started/big/config.png +[5]:https://www.howtoforge.com/images/ubuntu_github_getting_started/details.png +[6]:https://www.howtoforge.com/images/ubuntu_github_getting_started/big/details.png +[7]:https://www.howtoforge.com/images/ubuntu_github_getting_started/steps.png +[8]:https://www.howtoforge.com/images/ubuntu_github_getting_started/big/steps.png +[9]:https://www.howtoforge.com/images/ubuntu_github_getting_started/final.png +[10]:https://www.howtoforge.com/images/ubuntu_github_getting_started/big/final.png diff --git a/published/20180808 5 applications to manage your to-do list on Fedora.md b/published/20180808 5 applications to manage your to-do list on Fedora.md new file mode 100644 index 0000000000..99a163bf4f --- /dev/null +++ b/published/20180808 5 applications to manage your to-do list on Fedora.md @@ -0,0 +1,89 @@ +5 个在 Fedora 上管理待办事项的程序 +====== + +![](https://fedoramagazine.org/wp-content/uploads/2018/08/todoapps-816x345.jpg) + +有效管理待办事项(to-do)可以为你的工作效率创造奇迹。有些人更喜欢在文本中保存待办事项,甚至只使用记事本和笔。对于需要更多待办事项功能的用户,他们通常会使用应用程序。在本文中,我们将重点介绍 4 个图形程序和一个基于终端的工具来管理待办事项。 + +### GNOME To Do + +[GNOME To Do][1] 是专为 GNOME 桌面(Fedora Workstation 的默认桌面)设计的个人任务管理器。GNOME To Do 与其他程序进行比较,它有一系列简洁的功能。 + +GNOME To Do 提供列表形式的任务组织方式,并能为该列表指定颜色。此外,可以为各个任务分配截止日期和优先级,以及每项任务的注释。此外,GNOME To Do 还支持扩展,能添加更多功能,包括支持 [todo.txt][2] 以及与 [todoist][3] 等在线服务同步。 + +![][4] + +使用软件中心或者在终端中使用下面的命令安装 GNOME To Do: + +``` +sudo dnf install gnome-todo +``` + +### Getting things GNOME! + +在 GNOME To Do 出现之前,在 GNOME 上追踪任务的首选程序是 [Getting things GNOME!][5] 这个老式的 GNOME 程序采用多窗口布局,能让你同时显示多个任务的细节。GTG 没有任务列表,它能在任务中添加子任务,甚至在子任务中添加子任务。GTG 同样能添加截止日期和开始日期。也可以通过插件同步其他程序和服务。 + +![][6] + +在软件中心或者在终端中使用下面的命令安装 Getting Things GNOME: + +``` +sudo dnf install gtg +``` + +### Go For It! + +[Go For It!][7] 是一个超级简单的任务管理程序。它能简单地创建一个任务列表,并在完成后标记它们。它不能将任务分组,也不能创建子任务。Go For It! 默认将任务存储为 todo.txt 格式,这能更方便地同步到在线服务或者其他程序中。额外地,Go For It! 包含了一个简单定时器来追踪你在当前任务花费了多少时间。 + +![][8] + +Go For It! 能在 Flathub 应用仓库中找到。要安装它,只需[启用 Flathub 作为软件源][9],接着在软件中心中安装。 + +### Agenda + +如果你在寻找一款非常简单的待办应用,非 [Agenda][10] 莫属。创建任务,标记完成,接着从列表中删除它们。Agenda 会在你删除它们之前一直显示所有任务(完成的或者进行中)。 + +![][11] + +Agenda 能从 Flathub 应用仓库下载。要安装它,只需[启用 Flathub 作为软件源][9],接着在软件中心中安装。 + +### Taskwarrior + +[Taskwarrior][12] 是一个灵活的命令行任务管理程序。它高度可定制化,但同样“开箱即用”。使用简单的命令,你可以创建任务,标记完成,并列出当前进行中的任务。另外,任务可以被标记、添加到项目、搜索和过滤。此外,你可以设置循环任务,并设置任务截止日期。 + +[之前在 Fedora Magazine 上的文章][13] 对 Taskwarrior 的入门做了很好的概述。 + +![][14] + +在终端中使用这个命令安装 Taskwarrior: + +``` +sudo dnf install task +``` + +-------------------------------------------------------------------------------- + +via: https://fedoramagazine.org/5-tools-to-manage-your-to-do-list-on-fedora/ + +作者:[Ryan Lerch][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[geekpi](https://github.com/geekpi) +校对:[wxy](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://fedoramagazine.org/introducing-flatpak/ +[1]:https://wiki.gnome.org/Apps/Todo/ +[2]:http://todotxt.org/ +[3]:https://en.todoist.com/ +[4]:https://fedoramagazine.org/wp-content/uploads/2018/08/gnome-todo.png +[5]:https://wiki.gnome.org/Apps/GTG +[6]:https://fedoramagazine.org/wp-content/uploads/2018/08/gtg.png +[7]:http://manuel-kehl.de/projects/go-for-it/ +[8]:https://fedoramagazine.org/wp-content/uploads/2018/08/goforit.png +[9]:https://fedoramagazine.org/install-flathub-apps-fedora/ +[10]:https://github.com/dahenson/agenda +[11]:https://fedoramagazine.org/wp-content/uploads/2018/08/agenda.png +[12]:https://taskwarrior.org/ +[13]:https://fedoramagazine.org/getting-started-taskwarrior/ +[14]:https://fedoramagazine.org/wp-content/uploads/2018/08/taskwarrior.png diff --git a/published/20180808 5 open source role-playing games for Linux.md b/published/20180808 5 open source role-playing games for Linux.md new file mode 100644 index 0000000000..4399c9ceb9 --- /dev/null +++ b/published/20180808 5 open source role-playing games for Linux.md @@ -0,0 +1,149 @@ + +五个 Linux 上的开源角色扮演游戏 +====== + +> 换一个新的身份,并用这些开源的角色扮演游戏探索新世界。 + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/dice_tabletop_board_gaming_game.jpg?itok=y93eW7HN) + +游戏是 Linux 的传统弱项之一,感谢 Steam、GOG 和其他的游戏开发商将商业游戏移植到了多个操作系统,Linux 的这个弱项在近几年有所改观,但是这些游戏通常都不是开源的。当然,这些游戏可以在开源系统上运行,但是对于开源的纯粹主义者来说这还不够好。 + +那么,有没有一款能让只使用自由开源软件的人在不影响他们开源理念的情况下也能享受到可靠游戏体验的精致游戏呢? + +当然有啦!虽然开源游戏不太可能和拥有大量开发预算的 3A 级大作相媲美,但有许多类型的开源游戏也很有趣,而且它们可以直接从大多数主要的 Linux 发行版的仓库中进行安装。即使某个游戏没有被某些仓库打包,你也可以很简单地从这个游戏的官网下载它,并进行安装和运行。 + +这篇文章着眼于角色扮演游戏,我已经写过关于[街机游戏][1]、[棋牌游戏][2]、[益智游戏][3],以及[赛车和飞行游戏][4]。在本系列的最后一篇文章中,我打算覆盖战略游戏和模拟游戏这两方面。 + +### Endless Sky + +![](https://opensource.com/sites/default/files/uploads/endless_sky.png) + +[Endless Sky][5] 是 Ambrosia Software 的 [Escape Velocity][6] 系列的开源克隆品。玩家乘坐一艘宇宙飞船,在不同的世界之间旅行来运送货物和乘客,并在沿途中承接其他任务,或者玩家也可以变成海盗,并从其他货船中偷取货物。这个游戏让玩家自己决定要如何去体验这个游戏,以太阳系为背景的超大地图是非常具有探索性的。Endless Sky 是那些违背正常游戏类别分类的游戏之一。但这个兼具动作、角色扮演、太空模拟和交易这四种类型的游戏非常值得一试。 + +如果要安装 Endless Sky ,请运行下面的命令。 + +在 Fedora 上: + +``` +dnf install endless-sky +``` + +在 Debian/Ubuntu 上: + +``` +apt install endless-sky +``` + +### FreeDink + +![](https://opensource.com/sites/default/files/uploads/freedink.png) + +[FreeDink][7] 是 [Dink Smallwood][8] 的开源版本,Dink Smallwood 是一个由 RTSoft 在 1997 年发售的动作角色扮演游戏。Dink Smallwood 在 1999 年时变为了免费游戏,并在 2003 年时公布了源代码。在 2008 年时,游戏的数据除了少部分的声音文件,都在开源协议下进行了开源。FreeDink 用一些替代的声音文件替换了缺少的那部分文件,来提供了一个完整的游戏。游戏的玩法类似于任天堂的[塞尔达传说][9]系列。玩家控制的角色和 Dink Smallwood 同名,他在从一个任务地点移动到下一个任务地点的时候,探索这个充满隐藏物品和隐藏洞穴的世界地图。由于这个游戏的年龄,FreeDink 不能和现代的商业游戏相抗衡,但它仍然是一个拥有着有趣故事的有趣的游戏。游戏可以通过 [D-Mods][10] 进行扩展,D-Mods 是提供额外任务的附加模块,但是 D-Mods 在复杂性、质量,和年龄适应性上确实有很大的差异。游戏主要适合青少年,但也有部分额外组件适用于成年玩家。 + +要安装 FreeDink ,请运行下面的命令。 + +在 Fedora 上: + +``` +dnf install freedink +``` + +在 Debian/Ubuntu 上: + +``` +apt install freedink +``` + +### ManaPlus + +![](https://opensource.com/sites/default/files/uploads/manaplus.png) + +从技术上讲,[ManaPlus][11] 本身并不是一个游戏,它是一个访问各种大型多人在线角色扮演游戏的客户端。[The Mana World][12] 和 [Evol Online][13] 是两款可以通过 ManaPlus 访问的开源游戏,但是游戏的服务器不在那里。这个游戏的 2D 精灵图像让人想起超级任天堂游戏,虽然 ManaPlus 支持的游戏没有一款能像商业游戏那样受欢迎的,但它们都有一个有趣的世界,并且在绝大部分时间里都有至少一小部分玩家在线。一个玩家不太可能遇到很多的其他玩家,但通常都能有足够的人一起在这个 [MMORPG][14] 游戏里进行冒险,而不是一个需要连接到服务器的单机游戏。Mana World 和 Evol Online 的开发者联合起来进行未来的开发,但是对于目前而言,Mana World 的历史服务器和 Evol Online 提供了不同的游戏体验。 + +要安装 ManaPlus,请运行下面的命令。 + +在 Fedora 上: + +``` +dnf install manaplus +``` + +在 Debian/Ubuntu 上: + +``` +apt install manaplus +``` + +### Minetest + +![](https://opensource.com/sites/default/files/uploads/minetest.png) + +使用 [Minetest][15] 来在一个开放式世界里进行探索和创造,Minetest 是 Minecraft 的克隆品。就像它所基于的 Minecraft 一样,Minetest 提供了一个开放的世界,玩家可以在这个世界里探索和创造他们想要的一切。Minetest 提供了各种各样的方块和工具,对于想要一个比 Minecraft 更加开放的游戏的人来说,Minetest 是一个很好的替代品。除了基本的游戏之外,Minetest 还可以通过[额外的模块][16]进行可扩展,增加更多的选项。 + +如果要安装 Minetest ,请运行下面的命令。 + +在 Fedora 上: + +``` +dnf install minetest +``` + +在 Debian/Ubuntu 上: + +``` +apt install minetest +``` + +### NetHack + +![](https://opensource.com/sites/default/files/uploads/nethack.png) + +[NetHack][17] 是一款经典的 [Roguelike][18] 类型的角色扮演游戏,玩家可以从不同的角色种族、分类和阵营中进行选择,来探索这个多层次的地下城。这个游戏的目的就是找回 Yendor 的护身符,玩家从地下层的第一层开始探索,并尝试向下一层移动,每一层都是随机生成的,这样每次都能获得不同的游戏体验。虽然这个游戏只具有 ASCII 图形和基本图形,但是游戏玩法的深度能够弥补画面的不足。玩家如果想要更好一些的画面的话,可能就需要去查看 [NetHack 的 Vulture][19] 了,这个方式可以提供更好的图像、声音和背景音乐。 + +如果要安装 NetHack ,请运行下面的命令。 + +在 Fedora 上: + +``` +dnf install nethack +``` + +在 Debian/Ubuntu 上: + +``` +apt install nethack-x11 or apt install nethack-console +``` + +我有错过了你最喜欢的角色扮演游戏吗?请在下面的评论区分享出来。 + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/8/role-playing-games-linux + +作者:[Joshua Allen Holm][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[hopefully2333](https://github.com/hopefully2333) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://opensource.com/users/holmja +[1]:https://opensource.com/article/18/1/arcade-games-linux +[2]:https://opensource.com/article/18/3/card-board-games-linux +[3]:https://opensource.com/article/18/6/puzzle-games-linux +[4]:https://opensource.com/article/18/7/racing-flying-games-linux +[5]:https://endless-sky.github.io/ +[6]:https://en.wikipedia.org/wiki/Escape_Velocity_(video_game) +[7]:http://www.gnu.org/software/freedink/ +[8]:http://www.rtsoft.com/pages/dink.php +[9]:https://en.wikipedia.org/wiki/The_Legend_of_Zelda +[10]:http://www.dinknetwork.com/files/category_dmod/ +[11]:http://manaplus.org/ +[12]:http://www.themanaworld.org/ +[13]:http://evolonline.org/ +[14]:https://en.wikipedia.org/wiki/Massively_multiplayer_online_role-playing_game +[15]:https://www.minetest.net/ +[16]:https://wiki.minetest.net/Mods +[17]:https://www.nethack.org/ +[18]:https://en.wikipedia.org/wiki/Roguelike +[19]:http://www.darkarts.co.za/vulture-for-nethack diff --git a/published/20180810 6 Reasons Why Linux Users Switch to BSD.md b/published/20180810 6 Reasons Why Linux Users Switch to BSD.md new file mode 100644 index 0000000000..2807f83920 --- /dev/null +++ b/published/20180810 6 Reasons Why Linux Users Switch to BSD.md @@ -0,0 +1,78 @@ +Linux 用户应该换到 BSD 的 6 个理由 +====== + +迄今我因 BSD 是 自由及开源软件Free and Open Source Software(FOSS) 已经写了数篇关于它的文章。但总有人会问:“为什么要纠结于 BSD?”。我认为最好的办法是写一篇关于这个话题的文章。 + +### 为什么用 BSD 取代 Linux? + +为了准备这篇文章,我与几位 BSD 的用户聊了聊,其中有人使用了多年 Linux 而后转入 BSD。因而这篇文章的观点都来源于真实的 BSD 用户。本文希望提出一个不同的观点。 + +![why use bsd over linux][2] + +#### 1、BSD 不仅仅是一个内核 + +几个人都指出 BSD 提供的操作系统对于终端用户来说就是一个巨大而统一的软件包。他们指出所谓 “Linux” 仅仅说的是内核。一个 Linux 发行版由上述的内核与许多由发行者所选取的不同的应用与软件包组成。有时候安装新的软件包所导致的不兼容会使系统产生崩溃。 + +一个典型的 BSD 由内核和许多必要的软件包组成。这些包里的大多数是通过活跃的项目所开发,因此其具备高集成度与高响应度的特点。 + +#### 2、软件包更值得信赖 + +说起软件包,BSD 用户提出的另一点是软件包的可信度。在 Linux 上,软件包可以从一堆不同的源上获得,一些是发行版的开发者提供的,另一些是第三方。[Ubuntu][3] 和[其他发行版][4]就遇到了在第三方应用里隐藏了恶意软件的问题。 + +在 BSD 上,所有的软件包由“集中式软件包/ ports 系统”所提供,“每个软件包都是单一仓库的一部分,并且每一步都设有安全系统”。这就确保了黑客不能将恶意软件潜入到看似稳定的应用程序中,保障了 BSD 的长期稳定性。 + +#### 3、更新缓慢 = 更好的长期稳定性 + +如果更新是一场竞赛,那么 Linux 就是兔子,BSD 就是乌龟。甚至最慢的 Linux 发行版每年至少发布一个新版本(当然,除了 Debian)。在 BSD 的世界里,重大版本的发布需要更长时间。这就意味着可以更关注于将事情做完善之后再将它推送给用户。 + +这也意味着操作系统的变化会随着时间的推移而发生。Linux 世界经历了数次快速而重大的变化,我们至今仍感觉如此(咳咳, [systemD][5],咳咳)。就像 Debian 那样,长时间的开发周期可以帮助 BSD 去测试新的想法,保证在它在永久改变之前正常工作。它也有助于生产出不太可能出现问题的代码。 + +#### 4、Linux 太乱了 + +没有一个 BSD 用户直截了当地指出这一点,但这是他们许多经验所显示出的情况。很多用户从一个 Linux 发行版跳到另一个发行版去寻找适合他的版本。很多情况下,他们无法使所有的软件或硬件正常工作。这时,他们决定尝试使用 BSD,接着,所有的东西都正常工作了。 + +当考虑到如何选择 BSD 时,一切就变得相当简单。目前只有六个 BSD 发行版在积极开发。这些 BSD 中的每一个都有特定的用途。“[OpenBSD][6] 更安全,[FreeBSD][7] 适用于桌面或服务器,[NetBSD][8] 无所不包,[DragonFlyBSD][9] 精简高效”。与此同时,充斥着 Linux 世界的许多发行版仅仅是在现有的发行版上增加了主题或者图标而已。BSD 项目数量之少意味着它重复性低并且更加专注。 + +#### 5、ZFS 支持 + +一个 BSD 用户说到他选择 BSD 最主要的原因是 [ZFS][10]。事实上,几乎所有我谈过的人都提到 BSD 支持 ZFS 是他们没有返回 Linux 的原因。 + +这一点是 Linux 从一开始就处于下风的地方。虽然在一些 Linux 发行版上可以使用 [OpenZFS][11],但是 ZFS 已经内置在了 BSD 的内核中。这意味着 ZFS 在 BSD 上将会有更好地性能。尽管有过将 ZFS 加入到 Linux 内核中的数次尝试,但许可证问题依旧无法解决。 + +#### 6、许可证 + +就许可证而言也有不同的看法。大多数人所持有的想法是,GPL 不是真正的自由,因为它限制了如何使用软件。一些人也认为 GPL “太庞大而复杂而难于理解,如果在开发过程中不仔细检查许可证会导致法律问题。” + +另一方面,BSD 协议只有 3 条,并且允许任何人“使用软件、进行修改、做任何事,并且对开发者提供了保护”。 + +### 总结 + +这些仅仅只是一小部分人们使用 BSD 而不使用 Linux 的原因。如果你感兴趣,你可以[在这][12]阅读其他人的评论。如果你是 BSD 用户并且觉得我错过什么重要的地方,请在评论里说出你的想法。 + +如果你觉得这篇文章有意思,请在社交媒体上、技术资讯或者 [Reddit][13] 上分享它。 + +-------------------------------------------------------------------------------- + +via: https://itsfoss.com/why-use-bsd/ + +作者:[John Paul][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[LuuMing](https://github.com/LuuMing) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://itsfoss.com/author/john/ +[1]:https://itsfoss.com/category/bsd/ +[2]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/08/why-BSD.png +[3]:https://itsfoss.com/snapstore-cryptocurrency-saga/ +[4]:https://www.bleepingcomputer.com/news/security/malware-found-in-arch-linux-aur-package-repository/ +[5]:https://www.freedesktop.org/wiki/Software/systemd/ +[6]:https://www.openbsd.org/ +[7]:https://www.freebsd.org/ +[8]:http://netbsd.org/ +[9]:http://www.dragonflybsd.org/ +[10]:https://en.wikipedia.org/wiki/ZFS +[11]:http://open-zfs.org/wiki/Main_Page +[12]:https://discourse.trueos.org/t/why-do-you-guys-use-bsd/2601 +[13]:http://reddit.com/r/linuxusersgroup diff --git a/published/20180810 Automatically Switch To Light - Dark Gtk Themes Based On Sunrise And Sunset Times With AutomaThemely.md b/published/20180810 Automatically Switch To Light - Dark Gtk Themes Based On Sunrise And Sunset Times With AutomaThemely.md new file mode 100644 index 0000000000..407155c167 --- /dev/null +++ b/published/20180810 Automatically Switch To Light - Dark Gtk Themes Based On Sunrise And Sunset Times With AutomaThemely.md @@ -0,0 +1,80 @@ +基于日出和日落时间自动切换到明/暗 Gtk 主题 +====== + +如果你在寻找一种基于日出和日落时间自动更改 Gtk 主题的简单方法,请尝试一下 [AutomaThemely][3]。 + +![](https://4.bp.blogspot.com/-LS0XNNflbp0/W2q8zAwhUdI/AAAAAAAABUY/l8fVbjt-tHExYxPHsyVv74iUhV4O9UXLwCLcBGAs/s640/automathemely-settings.png) + +AutomaThemely 是一个 Python 程序,它可以根据光亮和黑暗时间自动更改 Gnome 主题,如果你想在夜间使用黑暗的 Gtk 主题并在白天使用明亮的 Gtk 主题,那么它非常有用。 + +**虽然该程序是为 Gnome 桌面制作的,但它也适用于 Unity**。AutomaThemely 不支持不使用 `org.gnome.desktop.interface Gsettings` 的桌面环境,如 Cinnamon,的 Gtk 主题,或者更改图标主题,至少现在还不行。它也不支持设置 Gnome Shell 主题。 + +除了自动更改 Gtk3 主题外,**AutomaThemely 还可以自动切换 Atom 编辑器和 VSCode 的明暗主题,以及 Atom 编辑器的明暗语法高亮。**这显然也是基于一天中的时间完成的。 + +[![AutomaThemely Atom VSCode][1]][2] + +*AutomaThemely Atom 和 VSCode 主题/语法设置* + +程序使用你的 IP 地址来确定你的位置,以便检索日出和日落时间,并且需要有可用的 Internet 连接。但是,你可以从程序用户界面禁用自动定位,并手动输入你的位置。 + +在 AutomaThemely 用户界面中,你还可以输入日出和日落时间的偏移(以分钟为单位),并启用或禁用主题更改的通知。 + +### 下载/安装 AutomaThemely + +- [下载 AutomaThemely][4] + +**Ubuntu 18.04**:使用上面的链接,下载包含依赖项的 Python 3.6 DEB(`python3.6-automathemely_1.2_all.deb`)。 + +**Ubuntu 16.04**:你需要下载并安装 AutomaThemely Python 3.5 DEB,它不包含依赖项(`python3.5-no_deps-automathemely_1.2_all.deb`),并使用 PIP3 分别安装依赖项(`requests`、`astral `、`pytz`、`tzlocal` 和 `schedule`): + +``` +sudo apt install python3-pip +python3 -m pip install --user requests astral pytz tzlocal schedule +``` + +AutomaThemely 下载页面还包含 Python 3.5 或 3.6 的 RPM 包,有包含和不包含依赖项两种。安装适合你的 Python 版本的软件包。如果你下载了包含依赖项的包但无法在你的系统上使用,请下载 “no_deps” 包并如上所述使用 PIP3 安装 Python3 依赖项。 + +### 使用 AutomaThemely 根据太阳时间更改明亮/黑暗 Gtk 主题 + +安装完成后,运行 AutomaThemely 一次以生成配置文件。单击 AutomaThemely 菜单条目或在终端中运行: + +``` +automathemely +``` + +这不会运行任何 GUI,它只生成配置文件。 + +使用 AutomaThemely 有点反直觉。你将在菜单中看到 AutomaThemely 图标,但单击它不会打开任何窗口/GUI。如果你使用支持列表跳转/快捷列表的 Gnome 或其他基于 Gnome 的桌面,你可以右键单击菜单中的 AutomaThemely 图标(或者你可以将其固定为 Dash/dock 并在那里右键单击它)并选择 Manage Settings 启动GUI: + +![](https://2.bp.blogspot.com/-7YWj07q0-M0/W2rACrCyO_I/AAAAAAAABUs/iaN_LEyRSG8YGM0NB6Aw9PLKmRU4NxzMACLcBGAs/s320/automathemely-jumplists.png) + +你还可以使用以下命令从命令行启动 AutomaThemely GUI: + +``` +automathemely --manage +``` + +**配置要使用的主题后,你需要更新太阳的时间并重新启动 AutomaThemely 调度器**。你可以通过右键单击 AutomaThemely 图标(应该在 Unity/Gnome 中可用)并选择 “Update sun times” 来更新太阳时间,然后选择 “Restart the scheduler” 来重启调度器完成此操作。你也可以使用以下命令从终端执行此操作: + +``` +automathemely --update +automathemely --restart +``` + + +-------------------------------------------------------------------------------- + +via: https://www.linuxuprising.com/2018/08/automatically-switch-to-light-dark-gtk.html + +作者:[Logix][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[geekpi](https://github.com/geekpi) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://plus.google.com/118280394805678839070 +[1]:https://4.bp.blogspot.com/-K2-1K_MIWv0/W2q9GEWYA6I/AAAAAAAABUg/-z_gTMSHlxgN-ZXDvUGIeTQ8I72WrRq0ACLcBGAs/s640/automathemely-settings_2.png (AutomaThemely Atom VSCode) +[2]:https://4.bp.blogspot.com/-K2-1K_MIWv0/W2q9GEWYA6I/AAAAAAAABUg/-z_gTMSHlxgN-ZXDvUGIeTQ8I72WrRq0ACLcBGAs/s1600/automathemely-settings_2.png +[3]:https://github.com/C2N14/AutomaThemely +[4]:https://github.com/C2N14/AutomaThemely/releases diff --git a/published/20180813 MPV Player- A Minimalist Video Player for Linux.md b/published/20180813 MPV Player- A Minimalist Video Player for Linux.md new file mode 100644 index 0000000000..545753574a --- /dev/null +++ b/published/20180813 MPV Player- A Minimalist Video Player for Linux.md @@ -0,0 +1,114 @@ +MPV 播放器:Linux 下的极简视频播放器 +====== + +> MPV 是一个开源的,跨平台视频播放器,带有极简的 GUI 界面以及丰富的命令行控制。 + +VLC 可能是 Linux 或者其他平台下最好的视频播放器。我已经使用 VLC 很多年了,它现在仍是我最喜欢的播放器。 + +不过最近,我倾向于使用简洁界面的极简应用。这也是我偶然发现 MPV 的原因。我太喜欢这个软件,并把它加入了 [Ubuntu 最佳应用][1]列表里。 + +[MPV][2] 是一个开源的视频播放器,有 Linux、Windows、MacOS、BSD 以及 Android 等平台下的版本。它实际上是从 [MPlayer][3] 分支出来的。 + +它的图形界面只有必须的元素而且非常整洁。 + +![MPV 播放器在 Linux 下的界面][4] + +*MPV 播放器* + +### MPV 的功能 + +MPV 有标准播放器该有的所有功能。你可以播放各种视频,以及通过常用快捷键来控制播放。 + + * 极简图形界面以及必须的控件。 + * 自带视频解码器。 + * 高质量视频输出以及支持 GPU 硬件视频解码。 + * 支持字幕。 + * 可以通过命令行播放 YouTube 等流媒体视频。 + * 命令行模式的 MPV 可以嵌入到网页或其他应用中。 + +尽管 MPV 播放器只有极简的界面以及有限的选项,但请不要怀疑它的功能。它主要的能力都来自命令行版本。 + +只需要输入命令 `mpv --list-options`,然后你会看到它所提供的 447 个不同的选项。但是本文不会介绍 MPV 的高级应用。让我们看看作为一个普通的桌面视频播放器,它能有多么优秀。 + +### 在 Linux 上安装 MPV + +MPV 是一个常用应用,加入了大多数 Linux 发行版默认仓库里。在软件中心里搜索一下就可以了。 + +我可以确认在 Ubuntu 的软件中心里能找到。你可以在里面选择安装,或者通过下面的命令安装: + +``` +sudo apt install mpv +``` + +你可以在 [MPV 网站][5]上查看其他平台的安装指引。 + +### 使用 MPV 视频播放器 + +在安装完成以后,你可以通过鼠标右键点击视频文件,然后在列表里选择 MPV 来播放。 + +![MPV 播放器界面][6] + +*MPV 播放器界面* + +整个界面只有一个控制面板,只有在鼠标移动到播放窗口上才会显示出来。控制面板上有播放/暂停,选择视频轨道,切换音轨,字幕以及全屏等选项。 + +MPV 的默认大小取决于你所播放视频的画质。比如一个 240p 的视频,播放窗口会比较小,而在全高清显示器上播放 1080p 视频时,会几乎占满整个屏幕。不管视频大小,你总是可以在播放窗口上双击鼠标切换成全屏。 + +#### 字幕 + +如果你的视频带有字幕,MPV 会[自动加载字幕][7],你也可以选择关闭。不过,如果你想使用其他外挂字幕文件,不能直接在播放器界面上操作。 + +你可以将额外的字幕文件名改成和视频文件一样,并且将它们放在同一个目录下。MPV 会加载你的字幕文件。 + +更简单的播放外挂字幕的方式是,用鼠标选中文件拖到播放窗口里放开。 + +#### 播放 YouTube 或其他在线视频 + +要播放在线视频,你只能使用命令行模式的 MPV。 + +打开终端窗口,然后用类似下面的方式来播放: + +``` +mpv +``` + +![在 Linux 桌面上使用 MPV 播放 YouTube 视频][8] + +*在 Linux 桌面上使用 MPV 播放 YouTube 视频* + +用 MPV 播放 YouTube 视频的体验不怎么好。它总是在缓冲缓冲,有点烦。 + +### 是否安装 MPV 播放器? + +这个看你自己。如果你想体验各种应用,大可以试试 MPV。否则,默认的视频播放器或者 VLC 就足够了。 + +我在早些时候写关于 [Sayonara][9] 的文章时,并不确定大家会不会喜欢一个相对不常用的音乐播放器,但是 FOSS 的读者觉得很好。 + +试一下 MPV,然后看看你会不会将它作为你的默认视频播放器。 + +如果你喜欢 MPV,但又觉得它的图形界面需要更多功能,我推荐你使用 [GNOME MPV 播放器][10]。 + +你用过 MPV 视频播放器吗?体验怎么样?喜欢还是不喜欢?欢迎在下面的评论区留言。 + +-------------------------------------------------------------------------------- + +via: https://itsfoss.com/mpv-video-player/ + +作者:[Abhishek Prakash][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[zpl1025](https://github.com/zpl1025) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://itsfoss.com/author/abhishek/ +[1]:https://itsfoss.com/best-ubuntu-apps/ +[2]:https://mpv.io/ +[3]:http://www.mplayerhq.hu/design7/news.html +[4]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/08/mpv-player.jpg +[5]:https://mpv.io/installation/ +[6]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/08/mpv-player-interface.png +[7]:https://itsfoss.com/how-to-play-movie-with-subtitles-on-samsung-tv-via-usb/ +[8]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/08/play-youtube-videos-on-mpv-player.jpeg +[9]:https://itsfoss.com/sayonara-music-player/ +[10]:https://gnome-mpv.github.io/ diff --git a/published/20180815 How To Enable Hardware Accelerated Video Decoding In Chromium On Ubuntu Or Linux Mint.md b/published/20180815 How To Enable Hardware Accelerated Video Decoding In Chromium On Ubuntu Or Linux Mint.md new file mode 100644 index 0000000000..53ec95d09b --- /dev/null +++ b/published/20180815 How To Enable Hardware Accelerated Video Decoding In Chromium On Ubuntu Or Linux Mint.md @@ -0,0 +1,107 @@ +如何在 Ubuntu 或 Linux Mint 启用 Chromium 硬件加速的视频解码 +====== + +你或许已经注意到了,在 Linux 上使用 Google Chrome 或 Chromium 浏览器在 YouTube 或其它类似网站观看高清视频会增加你的 CPU 使用率,如果你用的是笔记本,电脑会发热而且电池会很快用完。这是因为 Chrome/Chromium(Firefox 也是如此,但是 Firefox 的问题没有办法解决)在 Linux 上不支持硬件加速的视频解码。 + +这篇文章讲述了如何在 Linux 环境安装带有 VA-API 补丁的 Chromium 开发版,它支持 GPU 加速的视频解码,可以显著减少观看在线高清视频时的 CPU 使用率,这篇教程只适用于 Intel 和 Nvidia 的显卡,我没有 ATI/AMD 的显卡可以试验,也没有使用过这几种显卡。 + +这是 Chromium 浏览器在 Ubuntu18.04 中,在没有 GPU 加速视频解码的情况下播放一个 1080p 的 YouTube 视频: + +![](https://4.bp.blogspot.com/-KtUQni2PMvE/W3KlJ62yLLI/AAAAAAAABW4/NrNVFaTAkZ8AmwqWwRvWD6czT51ni-R-gCLcBGAs/s1600/chromium-default-no-accel.png) + +这是带有 VA-API 补丁的 Chromium 浏览器在 Ubuntu18.04 中,在带有 GPU 加速视频解码的情况下播放同样的 1080p 的 YouTube 视频: + +![](https://4.bp.blogspot.com/-0c-wb4UNhW8/W3KlQBfeFnI/AAAAAAAABW8/WVUAYzM6hA8wRTlCcrPXPMpoXoFVR6b1QCLcBGAs/s1600/chromium-hardware-acceleration-enabled.png) + +注意截图中的 CPU 使用率。两张截图都是在我老旧而依然强大的桌面计算机上捕捉的。在我的笔记本电脑上,没有硬件加速的 Chromium 带来更高的 CPU 使用率。 + +“只需 VA-API 即可在 Linux 启用 VAVDA、VAVEA 和 VAJDA” 这个[补丁][3]在一年多以前就提交给了 Chromium,但是它还没有合并。 + +Chrome 有一个选项可以覆盖软件渲染列表(`#ignore-gpu-blacklist`),但是这个选项不能启用硬件加速的视频解码。启用这个选项以后,你或许会在访问 `chrome://gpu` 时发现这些信息:“_Video Decode: Hardware accelerated_ “,然而这个并不意味着真的可以工作。在 YouTube 打开一个高清视频并用诸如 `htop` 的工具查看 CPU 使用率(这是我在以上截图中用来查看 CPU 使用率的)。因为 GPU 视频解码没有真的被启用,你应该看到较高的 CPU 使用率。下面有一个部分是关于检查你是否真的在使用硬件加速的视频解码的。 + +**文中使用的 Chromium 浏览器 Ubuntu 版启用 VA-API 的补丁在[这个地址][1]可以获得** + +### 在 Ubuntu 和 Linux Mint 安装和使用带有 VA-API 支持的 Chromium 浏览器 + +每个人都该知道 Chromium 开发版本没有理想中那么稳定。所以你可能发现 bug,它可能会发生崩溃等情况。它现在可能正常运行,但是谁知道几次更新以后会发生什么。 + +还有,如果你想启用 Widevine 支持(这样你才能观看 Netflix 视频和 YouTube 付费视频),Chromium dev 分支 PPA 要求你执行一些额外步骤。 如果你想要一些功能,比如同步,也是如此(需要注册 API 密钥还要在你的系统上设置好)。执行这些任务的说明在 [Chromium 开发版本的 PPA][4] 中有详细解释。 + +对于 Nvidia 显卡,vdpau 视频驱动程序需要更新以便显示 vaQuerySurfaceAttributes。所以 Nvidia 需要使用打过补丁的 vdpau-va-driver。值得庆幸的是,Chromium-dev PPA 提供了这个打过补丁的包。 + +带有 VA-API 补丁的 Chromium 也可用于其它 Linux 发行版,在第三方仓库,比如说 [Arch Linux][5](对于 Nvidia 你需要[这个][6]补丁过的 libva-vdpau-driver)。如果你不使用 Ubuntu 或 Linux Mint,你得自己找那些包。 + +#### 1、安装带有 VA-API 补丁的 Chromium + +有一个带 VA-API 补丁的 Chromium Beta PPA,但是它缺少适用于 Ubuntu 18.04 的 vdpau-video。如果你需要,你可以使用这个 [Beta PPA][7],而不是我在下面的步骤中使用 [Dev PPA][8],不过如果你使用 Nvidia 显卡,你需要从这个 Dev PPA 中下载安装 vdpau-va-driver,并确认 Ubuntu/Linux Mint 不更新这个包(有点复杂,如果你准备根据下面步骤使用 Dev PPA 的话,不需要手动做这些)。 + +你可以添加 [Chromium 开发分支 PPA][4],并在 Ubuntu 或 Linux Mint(及其它基于 Ubuntu 的发行版,如 elementary,以及 Ubuntu 或 Linux Mint 的风味版,如 Xubuntu、Kubuntu、Ubuntu MATE、Linux Mint MATE 等等)上安装最新的 Chromium 浏览器开发版: + + +``` +sudo add-apt-repository ppa:saiarcot895/chromium-dev +sudo apt-get update +sudo apt install chromium-browser + +``` + +#### 2、安装 VA-API 驱动 + +对于 Intel 的显卡,你需要安装 `i965-va-driver` 这个包(它可能早就安装好了) + +``` +sudo apt install i965-va-driver +``` + +对于 Nvidia 的显卡(在开源的 Nouveau 驱动和闭源的 Nvidia 驱动上,它应该都有效), 安装 `vdpau-va-driver`: + +``` +sudo apt install vdpau-va-driver +``` + +#### 3、在 Chromium 启用硬件加速视频选项 + +复制这串地址,粘贴进 Chromium 的 URL 栏: `chrome://flags/#enable-accelerated-video` (或者在 `chrome://flags` 搜索 `Hardware-accelerated video` )并启用它,然后重启 Chromium 浏览器。 + +在默认的 Google Chrome / Chromium 版本,这个选项不可用,但是你可以在启用了 VP-API 的 Chromium 版本启用它。 + +#### 4、安装 [h264ify][2] Chrome 扩展 + +YouTube(可能还有其它一些网址也是如此)默认使用 VP8 或 VP9 编码解码器,许多 GPU 不支持这种编码解码器的硬件解码。h264ify 会强制 YouTube 使用大多数 GPU 都支持的 H.264 而不是 VP8/VP9。 + +这个扩展还能阻塞 60fps 的视频,对低性能机器有用。 + +你可以在视频上右键点击,并且选择 `Stats for nerds` 以查看 Youtube 视频所使用额编码解码器,如果启用了 h264ify 扩展,你可以看到编码解码器是 avc / mp4a。如果没有启用,编码解码器应该是 vp09 / opus。 + +### 如何检查 Chromium 是否在使用 GPU 视频解码 + +在 YouTube 打开一个视频,然后,在 Chromium 打开一个新的标签页并将以下地址输入 URL 栏:`chrome://media-internals`。 + +在 `chrome://media-internals` 标签页中,点击视频的 URL(为了展开它), 往下滚动查看 `Player Properties` 的下面,你应该可以找到 `video_decoder` 属性。如果`video_decoder` 的值是 `GpuVideoDecoder` ,这说明当前在另一个标签页播放的 YouTube 视频正在使用硬件加速的的视频解码。 + +![](https://4.bp.blogspot.com/-COBJWVT_Y0Q/W3KnG7AeHsI/AAAAAAAABXM/W2XAJA_S0BIHug4eQKTMOdIfXHhgkXhhQCLcBGAs/s1600/chromium-gpuvideodecoder-linux.png) + +如果它显示的是 `FFmpegVideoDecoder` 或 `VpxVideoDecoder` ,说明加速视频解码无效或者你忘记安装或禁用了 h264ify 这个 Chrome 扩展。 + +如果无效,你可以通过在命令行运行 `chromium-browser` ,通过查看是否有 VA-API 相关的错误显示出来以调试。你也可以运行 `vainfo`(在 Ubuntu 或 Linux Mint 上安装:`sudo apt install vainfo`)和 `vdpauinfo` (对于 Nvidia,在 Ubuntu 或 Linux Mint 上安装:`sudo apt install vdpauinfo`)并且查看是否有显示任何错误。 + +-------------------------------------------------------------------------------- + +via: https://www.linuxuprising.com/2018/08/how-to-enable-hardware-accelerated.html + +作者:[Logix][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[GraveAccent](https://github.com/GraveAccent) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://plus.google.com/118280394805678839070 +[1]:https://github.com/saiarcot895/chromium-ubuntu-build/tree/master/debian/patches +[2]:https://chrome.google.com/webstore/detail/h264ify/aleakchihdccplidncghkekgioiakgal +[3]:https://chromium-review.googlesource.com/c/chromium/src/+/532294 +[4]:https://launchpad.net/~saiarcot895/+archive/ubuntu/chromium-dev +[5]:https://aur.archlinux.org/packages/?O=0&SeB=nd&K=chromium+vaapi&outdated=&SB=n&SO=a&PP=50&do_Search=Go +[6]:https://aur.archlinux.org/packages/libva-vdpau-driver-chromium/ +[7]:https://launchpad.net/~saiarcot895/+archive/ubuntu/chromium-beta +[8]:https://launchpad.net/~saiarcot895/+archive/ubuntu/chromium-dev/+packages diff --git a/published/20180822 How To Switch Between TTYs Without Using Function Keys In Linux.md b/published/20180822 How To Switch Between TTYs Without Using Function Keys In Linux.md new file mode 100644 index 0000000000..0b27f921c8 --- /dev/null +++ b/published/20180822 How To Switch Between TTYs Without Using Function Keys In Linux.md @@ -0,0 +1,104 @@ +如何在 Linux 中不使用功能键在 TTY 之间切换 +====== + +![](https://www.ostechnix.com/wp-content/uploads/2018/08/Switch-Between-TTYs-720x340.png) + +本简要指南介绍了在类 Unix 操作系统中如何在不使用功能键的情况下切换 TTY。在进一步讨论之前,我们将了解 TTY 是什么。正如在 AskUbuntu 论坛的一个[答案][1]中所提到的,**TTY**这个词来自 **T**ele**TY**pewriter(电传打字机)。在 Unix 的早期,连接到计算机的用户终端就是机电的电传机或电传打字机(简称 tty)。从那时起,TTY 这个名称继续用于纯文本控制台。如今,所有文本控制台都代表虚拟控制台,而不是物理控制台。TTY 命令打印连接到标准输入的终端的文件名。 + +### 在 Linux 中切换 TTY + +默认情况下,Linux 中有 7 个 tty。它们被称为 tty1、tty2……tty7。1 到 6 的 tty 只是命令行。第 7 个 tty 是 GUI(你的 X 桌面会话)。你可以使用 `CTRL+ALT+Fn` 键在不同的 TTY 之间切换。例如,要切换到 tty1,我们按下 `CTRL+ALT+F1`。这就是 tty1 在 Ubuntu 18.04 LTS 服务器中的样子。 + +![](https://www.ostechnix.com/wp-content/uploads/2018/08/tty1.png) + +如果你的系统没有 X 会话, 只需要按下 `Alt+Fn` 键,不需要按下 `CTRL`。 + +在某些 Linux 版本中(例如,从 Ubuntu 17.10 开始),登录屏开始使用 1 号虚拟控制台。因此,你需要按 `CTRL+ALT+F3` 到 `CTRL+ALT+F6` 来访问虚拟控制台。要返回桌面环境,请在 Ubuntu 17.10 及更高版本上按下 `CTRL+ALT+F2` 或 `CTRL+ALT+F7`。 + +目前为止我们看到我们可以使用 `CTRL+ALT+Fn`(`F1` - `F7`)在 TTY 之间轻松切换。但是,如果出于任何原因你不想使用功能键,那么在 Linux 中有一个名为 `chvt` 的简单命令。 + +`chvt N` 命令让你切换到前台终端 N,这与按 `CTRL+ALT+Fn` 相同。如果它不存在,则创建相应的屏幕。 + +让我们试试显示当前的 tty: + +``` +$ tty +``` + +我的 Ubuntu 18.04 LTS 服务器的示例输出。 + +![](https://www.ostechnix.com/wp-content/uploads/2018/08/tty-command-output.png) + +现在让我们切换到 tty2。为此,请输入: + +``` +$ sudo chvt 2 +``` + +记住你需要在 `chvt` 命令一同使用 `sudo`。 + +现在,使用命令检查当前的 tty: + +``` +$ tty +``` + +你会看到 tty 现在已经改变了。 + +同样,你可以使用 `sudo chvt 3` 切换到 tty3,使用 `sudo chvt 4` 切换到 tty4 等等。 + +当任何一个功能键不起作用时,`chvt` 命令会很有用。 + +要查看活动虚拟控制台的总数,请运行: + +``` +$ fgconsole +2 +``` + +如你所见,我的系统中有两个活动的虚拟终端。 + +你可以使用以下命令查看下一个未分配的虚拟终端: + +``` +$ fgconsole --next-available +3 +``` + +如果虚拟控制台不是前台控制台,并且它没有打开任何进程来读取或写入,并且未在其屏幕上选择任何文本,则它是未使用的。 + +要移除未使用的虚拟终端,只需键入: + +``` +$ deallocvt +``` + +上面的命令为所有未使用的虚拟控制台释放内核内存和数据结构。简单地说,此命令将释放连接到未使用的虚拟控制台的所有资源。 + +有关更多详细信息,请参阅相应命令的手册页。 + +``` +$ man tty +$ man chvt +$ man fgconsole +$ man deallocvt +``` + +就是这些了。希望这很有用。还有更多的好东西。敬请关注! + +干杯! + + +-------------------------------------------------------------------------------- + +via: https://www.ostechnix.com/how-to-switch-between-ttys-without-using-function-keys-in-linux/ + +作者:[SK][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[geekpi](https://github.com/geekpi) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.ostechnix.com/author/sk/ +[1]:https://askubuntu.com/questions/481906/what-does-tty-stand-for diff --git a/published/20180822 What is a Makefile and how does it work.md b/published/20180822 What is a Makefile and how does it work.md new file mode 100644 index 0000000000..152a511265 --- /dev/null +++ b/published/20180822 What is a Makefile and how does it work.md @@ -0,0 +1,322 @@ +Makefile 及其工作原理 +====== + +> 用这个方便的工具来更有效的运行和编译你的程序。 + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/osdc_liberate%20docs_1109ay.png?itok=xQOLreya) + +当你需要在一些源文件改变后运行或更新一个任务时,通常会用到 `make` 工具。`make` 工具需要读取一个 `Makefile`(或 `makefile`)文件,在该文件中定义了一系列需要执行的任务。你可以使用 `make` 来将源代码编译为可执行程序。大部分开源项目会使用 `make` 来实现最终的二进制文件的编译,然后使用 `make install` 命令来执行安装。 + +本文将通过一些基础和进阶的示例来展示 `make` 和 `Makefile` 的使用方法。在开始前,请确保你的系统中安装了 `make`。 + +### 基础示例 + +依然从打印 “Hello World” 开始。首先创建一个名字为 `myproject` 的目录,目录下新建 `Makefile` 文件,文件内容为: + +``` +say_hello: +        echo "Hello World" +``` + +在 `myproject` 目录下执行 `make`,会有如下输出: + +``` +$ make +echo "Hello World" +Hello World +``` + +在上面的例子中,“say_hello” 类似于其他编程语言中的函数名。这被称之为目标target。在该目标之后的是预置条件或依赖。为了简单起见,我们在这个示例中没有定义预置条件。`echo ‘Hello World'` 命令被称为步骤recipe。这些步骤基于预置条件来实现目标。目标、预置条件和步骤共同构成一个规则。 + +总结一下,一个典型的规则的语法为: + +``` +目标: 预置条件 + 步骤 +``` + +作为示例,目标可以是一个基于预置条件(源代码)的二进制文件。另一方面,预置条件也可以是依赖其他预置条件的目标。 + +``` +final_target: sub_target final_target.c +        Recipe_to_create_final_target +        +sub_target: sub_target.c +        Recipe_to_create_sub_target +``` + +目标并不要求是一个文件,也可以只是步骤的名字,就如我们的例子中一样。我们称之为“伪目标”。 + +再回到上面的示例中,当 `make` 被执行时,整条指令 `echo "Hello World"` 都被显示出来,之后才是真正的执行结果。如果不希望指令本身被打印处理,需要在 `echo` 前添加 `@`。 + +``` +say_hello: +        @echo "Hello World" +``` + +重新运行 `make`,将会只有如下输出: + +``` +$ make +Hello World +``` + +接下来在 `Makefile` 中添加如下伪目标:`generate` 和 `clean`: + +``` +say_hello: +        @echo "Hello World" + +generate: +        @echo "Creating empty text files..." +        touch file-{1..10}.txt + +clean: +        @echo "Cleaning up..." +        rm *.txt +``` + +随后当我们运行 `make` 时,只有 `say_hello` 这个目标被执行。这是因为`Makefile` 中的第一个目标为默认目标。通常情况下会调用默认目标,这就是你在大多数项目中看到 `all` 作为第一个目标而出现。`all` 负责来调用它他的目标。我们可以通过 `.DEFAULT_GOAL` 这个特殊的伪目标来覆盖掉默认的行为。 + +在 `Makefile` 文件开头增加 `.DEFAULT_GOAL`: + +``` +.DEFAULT_GOAL := generate +``` + +`make` 会将 `generate` 作为默认目标: + +``` +$ make +Creating empty text files... +touch file-{1..10}.txt +``` + +顾名思义,`.DEFAULT_GOAL` 伪目标仅能定义一个目标。这就是为什么很多 `Makefile` 会包括 `all` 这个目标,这样可以调用多个目标。 + +下面删除掉 `.DEFAULT_GOAL`,增加 `all` 目标: + +``` +all: say_hello generate + +say_hello: +        @echo "Hello World" + +generate: +        @echo "Creating empty text files..." +        touch file-{1..10}.txt + +clean: +        @echo "Cleaning up..." +        rm *.txt +``` + +运行之前,我们再增加一些特殊的伪目标。`.PHONY` 用来定义这些不是文件的目标。`make` 会默认调用这些伪目标下的步骤,而不去检查文件名是否存在或最后修改日期。完整的 `Makefile` 如下: + +``` +.PHONY: all say_hello generate clean + +all: say_hello generate + +say_hello: +        @echo "Hello World" + +generate: +        @echo "Creating empty text files..." +        touch file-{1..10}.txt + +clean: +        @echo "Cleaning up..." +        rm *.txt +``` + +`make` 命令会调用 `say_hello` 和 `generate`: + +``` +$ make +Hello World +Creating empty text files... +touch file-{1..10}.txt +``` + +`clean` 不应该被放入 `all` 中,或者被放入第一个目标中。`clean` 应当在需要清理时手动调用,调用方法为 `make clean`。 + +``` +$ make clean +Cleaning up... +rm *.txt +``` + +现在你应该已经对 `Makefile` 有了基础的了解,接下来我们看一些进阶的示例。 + +### 进阶示例 + +#### 变量 + +在之前的实例中,大部分目标和预置条件是已经固定了的,但在实际项目中,它们通常用变量和模式来代替。 + +定义变量最简单的方式是使用 `=` 操作符。例如,将命令 `gcc` 赋值给变量 `CC`: + +``` +CC = gcc +``` + +这被称为递归扩展变量,用于如下所示的规则中: + +``` +hello: hello.c +    ${CC} hello.c -o hello +``` + +你可能已经想到了,这些步骤将会在传递给终端时展开为: + +``` +gcc hello.c -o hello +``` + +`${CC}` 和 `$(CC)` 都能对 `gcc` 进行引用。但如果一个变量尝试将它本身赋值给自己,将会造成死循环。让我们验证一下: + +``` +CC = gcc +CC = ${CC} + +all: +    @echo ${CC} +``` + +此时运行 `make` 会导致: + +``` +$ make +Makefile:8: *** Recursive variable 'CC' references itself (eventually).  Stop. +``` + +为了避免这种情况发生,可以使用 `:=` 操作符(这被称为简单扩展变量)。以下代码不会造成上述问题: + +``` +CC := gcc +CC := ${CC} + +all: +    @echo ${CC} +``` + +#### 模式和函数 + +下面的 `Makefile` 使用了变量、模式和函数来实现所有 C 代码的编译。我们来逐行分析下: + +``` +# Usage: +# make        # compile all binary +# make clean  # remove ALL binaries and objects + +.PHONY = all clean + +CC = gcc                        # compiler to use + +LINKERFLAG = -lm + +SRCS := $(wildcard *.c) +BINS := $(SRCS:%.c=%) + +all: ${BINS} + +%: %.o +        @echo "Checking.." +        ${CC} ${LINKERFLAG} $< -o $@ + +%.o: %.c +        @echo "Creating object.." +        ${CC} -c $< + +clean: +        @echo "Cleaning up..." +        rm -rvf *.o ${BINS} +``` + +* 以 `#` 开头的行是评论。 +* `.PHONY = all clean` 行定义了 `all` 和 `clean` 两个伪目标。 +* 变量 `LINKERFLAG` 定义了在步骤中 `gcc` 命令需要用到的参数。 +* `SRCS := $(wildcard *.c)`:`$(wildcard pattern)` 是与文件名相关的一个函数。在本示例中,所有 “.c”后缀的文件会被存入 `SRCS` 变量。 +* `BINS := $(SRCS:%.c=%)`:这被称为替代引用。本例中,如果 `SRCS` 的值为 `'foo.c bar.c'`,则 `BINS`的值为 `'foo bar'`。 +* `all: ${BINS}` 行:伪目标 `all` 调用 `${BINS}` 变量中的所有值作为子目标。 +* 规则: + + ``` +%: %.o +   @echo "Checking.." +   ${CC} ${LINKERFLAG} $< -o $@ +``` + + 下面通过一个示例来理解这条规则。假定 `foo` 是变量 `${BINS}` 中的一个值。`%` 会匹配到 `foo`(`%`匹配任意一个目标)。下面是规则展开后的内容: + + ``` +foo: foo.o +   @echo "Checking.." +   gcc -lm foo.o -o foo +``` + + 如上所示,`%` 被 `foo` 替换掉了。`$<` 被 `foo.o` 替换掉。`$<`用于匹配预置条件,`$@` 匹配目标。对 `${BINS}` 中的每个值,这条规则都会被调用一遍。 +* 规则: + + ``` +%.o: %.c +   @echo "Creating object.." +   ${CC} -c $< +``` + + 之前规则中的每个预置条件在这条规则中都会都被作为一个目标。下面是展开后的内容: + + ``` +foo.o: foo.c +  @echo "Creating object.." +  gcc -c foo.c +``` +* 最后,在 `clean` 目标中,所有的二进制文件和编译文件将被删除。 + +下面是重写后的 `Makefile`,该文件应该被放置在一个有 `foo.c` 文件的目录下: + +``` +# Usage: +# make        # compile all binary +# make clean  # remove ALL binaries and objects + +.PHONY = all clean + +CC = gcc                        # compiler to use + +LINKERFLAG = -lm + +SRCS := foo.c +BINS := foo + +all: foo + +foo: foo.o +        @echo "Checking.." +        gcc -lm foo.o -o foo + +foo.o: foo.c +        @echo "Creating object.." +        gcc -c foo.c + +clean: +        @echo "Cleaning up..." +        rm -rvf foo.o foo +``` + +关于 `Makefile` 的更多信息,[GNU Make 手册][1]提供了更完整的说明和实例。 + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/8/what-how-makefile + +作者:[Sachin Patil][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[Zafiry](https://github.com/zafiry) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://opensource.com/users/psachin +[1]:https://www.gnu.org/software/make/manual/make.pdf diff --git a/published/20180823 An introduction to pipes and named pipes in Linux.md b/published/20180823 An introduction to pipes and named pipes in Linux.md new file mode 100644 index 0000000000..bea644e6c4 --- /dev/null +++ b/published/20180823 An introduction to pipes and named pipes in Linux.md @@ -0,0 +1,62 @@ +介绍 Linux 中的管道和命名管道 +====== + +> 要在命令间移动数据?使用管道可使此过程便捷。 + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/LAW-Internet_construction_9401467_520x292_0512_dc.png?itok=RPkPPtDe) + +在 Linux 中,`pipe` 能让你将一个命令的输出发送给另一个命令。管道,如它的名称那样,能重定向一个进程的标准输出、输入和错误到另一个进程,以便于进一步处理。 + +“管道”(或称“未命名管道”)命令的语法是在两个命令之间加上 `|` 字符: + +``` +Command-1 | Command-2 | ...| Command-N +``` + +这里,该管道不能通过另一个会话访问;它被临时创建用于接收 `Command-1` 的执行并重定向标准输出。它在成功执行之后删除。 + +![](https://opensource.com/sites/default/files/uploads/pipe.png) + +在上面的示例中,`contents.txt` 包含特定目录中所有文件的列表 —— 具体来说,就是 `ls -al` 命令的输出。我们首先通过管道(如图所示)使用 “file” 关键字从 `contents.txt` 中 `grep` 文件名,因此 `cat` 命令的输出作为 `grep` 命令的输入提供。接下来,我们添加管道来执行 `awk` 命令,该命令显示 `grep` 命令的过滤输出中的第 9 列。我们还可以使用 `wc -l` 命令计算 `contents.txt` 中的行数。 + +只要系统启动并运行或直到它被删除,命名管道就可以持续使用。它是一个遵循 [FIFO][1](先进先出)机制的特殊文件。它可以像普通文件一样使用。也就是,你可以写入,从中读取,然后打开或关闭它。要创建命名管道,命令为: + +``` +mkfifo +``` + +这将创建一个命名管道文件,它甚至可以在多个 shell 会话中使用。 + +创建 FIFO 命名管道的另一种方法是使用此命令: + +``` +mknod p +``` + +要重定向任何命令的标准输出到其它命令,请使用 `>` 符号。要重定向任何命令的标准输入,请使用 `<` 符号。 + +![](https://opensource.com/sites/default/files/uploads/redirection.png) + +如上所示,`ls -al` 命令的输出被重定向到 `contents.txt` 并插入到文件中。类似地,`tail` 命令的输入通过 `<` 符号从 `contents.txt` 读取。 + +![](https://opensource.com/sites/default/files/uploads/create-named-pipe.png) + +![](https://opensource.com/sites/default/files/uploads/verify-output.png) + +这里,我们创建了一个命名管道 `my-named-pipe`,并将 `ls -al` 命令的输出重定向到命名管道。我们可以打开一个新的 shell 会话并 `cat` 命名管道的内容,如前所述,它显示了 `ls -al` 命令的输出。请注意,命名管道的大小为零,并有一个标志 “p”。 + +因此,下次你在 Linux 终端上使用命令并在命令之间移动数据时,希望管道使这个过程快速简便。 + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/8/introduction-pipes-linux + +作者:[Archit Modi][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[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/architmodi +[1]:https://en.wikipedia.org/wiki/FIFO_(computing_and_electronics) diff --git a/published/20180823 How to publish a WordPress blog to a static GitLab Pages site.md b/published/20180823 How to publish a WordPress blog to a static GitLab Pages site.md new file mode 100644 index 0000000000..d6843be2bf --- /dev/null +++ b/published/20180823 How to publish a WordPress blog to a static GitLab Pages site.md @@ -0,0 +1,92 @@ +如何将 WordPress 博客发布到静态 GitLab Pages 上 +====== + +> 通过 GitLab 或 GitHub Pages 来提供一个 WordPress 镜像站点, 从而最小化安全问题。 + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/web-design-monitor-website.png?itok=yUK7_qR0) + +很久以前,我为一个家庭成员建立了一个 WordPress 博客。如今有很多选择,但是当时如果你需要一个带有所见即所得的编辑器的基于 Web 的 CMS,那么就没什么像样的的选择了。而一切运行良好的不幸的副作用是随着时间的推移该博客产生了很多内容。这意味着我要经常更新 WordPress 以防止不断出现的漏洞。 + +因此,当我决定劝说家人切换到 [Hugo][1] 会相对容易,然后可以在 [GitLab][2] 上托管博客。但是尝试提取所有内容并将其转换为 [Markdown][3] 变成了一个巨大的麻烦。有自动脚本完成了 95% 的工作,但并不完美。手动更新所有帖子不是我想做的事情,所以最终,我放弃了试图移动博客。 + +最近,我又开始考虑这个问题,并意识到有一个我没有考虑过的解决方案:我可以继续维护 WordPress 服务器,但将其设置为发布静态镜像,并使用 [GitLab Pages][4](或 [GitHub Pages][5] ,如果你喜欢的话)提供服务。这能让我自动化 [Let's Encrypt][6] 证书续订并消除与托管 WordPress 站点相关的安全问题。然而,这意味着评论将无法使用,但在这种情况下感觉就像是一个小损失,因为博客没有收到很多评论。 + +这是我提出的解决方案,到目前为止似乎运作良好: + + * 托管 WordPress 站点中的 URL 没有链接到或来自其他任何地方,以减少它被利用的几率。在此例中,我们将使用 (即使此站点实际上是使用 Pelican 构建的)。 + * 将公共 URL [托管到 GitLab Pages 上][7]。 + * 添加 [cron 任务][8],确定两个 URL 之间的最后构建日期何时不同。如果构建日期不同,则镜像 WordPress 版本。 + * 使用 `wget` 镜像后,将所有链接从“私有”更新成“公共”。 + * 运行 `git push` 来发布新内容。 + +这是我使用的两个脚本: + +`check-diff.sh` (cron 每 15 分钟调用一次): + +``` +#!/bin/bash + +ORIGINDATE="$(curl -v --silent http://private.localconspiracy.com/feed/ 2>&1|grep lastBuildDate)" +PUBDATE="$(curl -v --silent https://www.localconspiracy.com/feed/ 2>&1|grep lastBuildDate)" + +if [ "$ORIGINDATE" !=  "$PUBDATE" ] +then +  /home/doc/repos/localconspiracy/mirror.sh +fi +``` + +`mirror.sh`: + +``` +#!/bin/sh + +cd /home/doc/repos/localconspiracy + +wget \ +--mirror \ +--convert-links  \ +--adjust-extension \ +--page-requisites  \ +--retry-connrefused  \ +--exclude-directories=comments \ +--execute robots=off \ +http://private.localconspiracy.com + +git rm -rf public/* +mv private.localconspiracy.com/* public/. +rmdir private.localconspiracy.com +find ./public/ -type f -exec sed -i -e 's|http://private.localconspiracy|https://www.localconspiracy|g' {} \; +find ./public/ -type f -exec sed -i -e 's|http://www.localconspiracy|https://www.localconspiracy|g' {} \; +git add public/* +git commit -m "new snapshot" +git push origin master +``` + +就是这些了!现在,当博客发生变化时,在 15 分钟内将网站镜像到静态版本并推送到仓库,这将在 GitLab Pages 中反映出来。 + +如果你想[在本地运行 WordPress][9],这个概念可以进一步扩展。在这种情况下,你不需要服务器来托管你的 WordPress 博客。你可以在本机运行它。在这种情况下,你的博客不可能被攻击利用。只要你可以在本地运行 `wget`,就可以使用上面的方法在 GitLab Pages 上托管 WordPress 站点。 + +_这篇文章最初发表于 [Local Conspiracy] [10]。允许转载。_ + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/8/publish-wordpress-static-gitlab-pages-site + +作者:[Christopher Aedo][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[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/docaedo +[1]:https://gohugo.io/ +[2]:https://gitlab.com/ +[3]:https://en.wikipedia.org/wiki/Markdown +[4]:https://docs.gitlab.com/ee/user/project/pages/ +[5]:https://pages.github.com/ +[6]:https://letsencrypt.org/ +[7]:https://about.gitlab.com/2016/04/07/gitlab-pages-setup/ +[8]:https://en.wikipedia.org/wiki/Cron +[9]:https://codex.wordpress.org/Installing_WordPress_Locally_on_Your_Mac_With_MAMP +[10]:https://localconspiracy.com/2018/08/wp-on-gitlab.html diff --git a/published/20180824 How to install software from the Linux command line.md b/published/20180824 How to install software from the Linux command line.md new file mode 100644 index 0000000000..6d84eec83c --- /dev/null +++ b/published/20180824 How to install software from the Linux command line.md @@ -0,0 +1,104 @@ +如何从 Linux 命令行安装软件 +====== +> 学习一种不同的包管理器和怎么使用它。 + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/suitcase_container_bag.png?itok=q40lKCBY) + +如果你在一直在使用 Linux,你很快就会发现做同样的事情有很多不同的方法。这包括通过命令行在 Linux 上安装应用。我已经是大约 25 年的 Linux 用户,我一次又一次地回到命令行来安装我的应用。 + +从命令行安装应用程序最常用的方法是使用称为包管理器通过软件库(存储软件的地方)安装。所有 Linux 应用都作为软件包分发,这些软件包只不过是与软件包管理系统相关的文件。每个 Linux 发行版都附带一个包管理系统,但它们并不完全相同。 + +### 什么是包管理系统? + +包管理系统由一组工具和文件格式组成,它们一起用于安装、更新和卸载 Linux 应用。两种最常见的包管理系统来自 Red Hat 和 Debian。 Red Hat、CentOS 和 Fedora 都使用 `rpm` 系统(.rpm 文件),而 Debian、Ubuntu、Mint 和 Ubuntu 都使用 `dpkg`(.deb 文件)。Gentoo Linux 使用名为 Portage 的系统,Arch Linux 只使用 tarball(.tar 文件)。这些系统之间的主要区别在于它们如何安装和维护应用。 + +你可能想知道 `.rpm`、`.deb` 或 `.tar` 文件中的内容。你可能会惊讶地发现,所有这些都只是普通的老式归档文件(如 `.zip`),其中包含应用的代码,如何安装它的说明,依赖项(它可能依赖的其他应用),以及配置文件的位置。读取和执行所有这些指令的软件称为包管理器。 + +### Debian、Ubuntu、Mint 等 + +Debian、Ubuntu、Mint 和其它基于 Debian 的发行版都使用 `.deb` 文件和 `dpkg` 包管理系统。有两种方法可以通过此系统安装应用。你可以使用 `apt` 程序从仓库进行安装,也可以使用 `dpkg` 程序从 `.deb` 文件安装应用。我们来看看如何做到这两点。 + +使用 `apt` 安装应用非常简单: + +``` +$ sudo apt install app_name +``` + +通过 `apt` 卸载应用也非常简单: + +``` +$ sudo apt remove app_name +``` + +要升级已安装的应用,首先需要更新应用仓库: + +``` +$ sudo apt update +``` + +完成后,你可以使用以下命令更新任何程序: + +``` +$ sudo apt upgrade +``` + +如果你只想更新一个应用,该怎么办?没问题。 + +``` +$ sudo apt update app_name +``` + +最后,假设你要安装的应用不存在于 Debian 仓库中,但有 `.deb` 下载。 + +``` +$ sudo dpkg -i app_name.deb +``` + +### Red Hat、CentOS 和 Fedora + +默认情况下,Red Hat 使用多个包管理系统。这些系统在使用自己的命令时,互相仍然非常相似,而且与 Debian 中使用的也相似。例如,我们可以使用 `yum` 或 `dnf` 管理器来安装应用。 + +``` +$ sudo yum install app_name +$ sudo dnf install app_name +``` + +`.rpm` 格式的应用也可以使用 `rpm` 命令安装。 + +``` +$ sudo rpm -i app_name.rpm +``` + +删除不需要的应用同样容易。 + +``` +$ sudo yum remove app_name +$ sudo dnf remove app_name +``` + +更新应用同样容易。 + +``` +$ yum update +$ sudo dnf upgrade --refresh +``` + +如你所见,从命令行安装、卸载和更新 Linux 应用并不难。事实上,一旦你习惯它,你会发现它比使用基于桌面 GUI 的管理工具更快! + +有关从命令行安装应用程序的更多信息,请访问 Debian [Apt wiki][1]、[Yum 速查表][2] 和 [DNF wiki][3]。 + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/8/how-install-software-linux-command-line + +作者:[Patrick H.Mullins][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[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/pmullins +[1]:https://wiki.debian.org/Apt +[2]:https://access.redhat.com/articles/yum-cheat-sheet +[3]:https://fedoraproject.org/wiki/DNF?rd=Dnf diff --git a/published/20180824 Steam Makes it Easier to Play Windows Games on Linux.md b/published/20180824 Steam Makes it Easier to Play Windows Games on Linux.md new file mode 100644 index 0000000000..a257cee609 --- /dev/null +++ b/published/20180824 Steam Makes it Easier to Play Windows Games on Linux.md @@ -0,0 +1,78 @@ + +Steam 让我们在 Linux 上玩 Windows 的游戏更加容易 +====== + +![Steam Wallpaper][1] + +总所周知,[Linux 游戏][2]库中的游戏只有 Windows 游戏库中的一部分,实际上,许多人甚至都不会考虑将操作系统[转换为 Linux][3],原因很简单,因为他们喜欢的游戏,大多数都不能在这个平台上运行。 + +在撰写本文时,Steam 上已有超过 5000 种游戏可以在 Linux 上运行,而 Steam 上的游戏总数已经接近 27000 种了。现在 5000 种游戏可能看起来很多,但还没有达到 27000 种,确实没有。 + +虽然几乎所有的新的独立游戏indie game都是在 Linux 中推出的,但我们仍然无法在这上面玩很多的 [3A 大作][4]。对我而言,虽然这其中有很多游戏我都很希望能有机会玩,但这从来都不是一个非黑即白的问题。因为我主要是玩独立游戏和[复古游戏][5],所以几乎所有我喜欢的游戏都可以在 Linux 系统上运行。 + +### 认识 Proton,Steam 的一个 WINE 复刻 + +现在,这个问题已经成为过去式了,因为本周 Valve [宣布][6]要对 Steam Play 进行一次更新,此次更新会将一个名为 Proton 的 Wine 复刻版本添加到 Linux 客户端中。是的,这个工具是开源的,Valve 已经在 [GitHub][7] 上开源了源代码,但该功能仍然处于测试阶段,所以你必须使用测试版的 Steam 客户端才能使用这项功能。 + +#### 使用 proton ,可以在 Linux 系统上通过 Steam 运行更多 Windows 游戏 + +这对我们这些 Linux 用户来说,实际上意味着什么?简单来说,这意味着我们可以在 Linux 电脑上运行全部 27000 种游戏,而无需配置像 [PlayOnLinux][8] 或 [Lutris][9] 这样的东西。我要告诉你的是,配置这些东西有时候会非常让人头疼。 + +对此更为复杂的答案是,某种原因听起来非常美好。虽然在理论上,你可以用这种方式在 Linux 上玩所有的 Windows 平台上的游戏。但只有一少部分游戏在推出时会正式支持 Linux。这少部分游戏包括 《DOOM》、《最终幻想 VI》、《铁拳 7》、《星球大战:前线 2》,和其他几个。 + +#### 你可以在 Linux 上玩所有的 Windows 游戏(理论上) + +虽然目前该列表只有大约 30 个游戏,你可以点击“为所有游戏启用 Steam Play”复选框来强制使用 Steam 的 Proton 来安装和运行任意游戏。但你最好不要有太高的期待,它们的稳定性和性能表现不一定有你希望的那么好,所以请把期望值压低一点。 + +![Steam Play][10] + +据[这份报告][13],已经有超过一千个游戏可以在 Linux 上玩了。按[此指南][14]来了解如何启用 Steam Play 测试版本。 + +#### 体验 Proton,没有我想的那么烂 + +例如,我安装了一些难度适中的游戏,使用 Proton 来进行安装。其中一个是《上古卷轴 4:湮没》,在我玩这个游戏的两个小时里,它只崩溃了一次,而且几乎是紧跟在游戏教程的自动保存点之后。 + +我有一块英伟达 Gtx 1050 Ti 的显卡。所以我可以使用 1080P 的高配置来玩这个游戏。而且我没有遇到除了这次崩溃之外的任何问题。我唯一真正感到不爽的只有它的帧数没有原本的高。在 90% 的时间里,游戏的帧数都在 60 帧以上,但我知道它的帧数应该能更高。 + +我安装和运行的其他所有游戏都运行得很完美,虽然我还没有较长时间地玩过它们中的任何一个。我安装的游戏中包括《森林》、《丧尸围城 4》和《刺客信条 2》。(你觉得我这是喜欢恐怖游戏吗?) + +#### 为什么 Steam(仍然)要下注在 Linux 上? + +现在,一切都很好,这件事为什么会发生呢?为什么 Valve 要花费时间,金钱和资源来做这样的事?我倾向于认为,他们这样做是因为他们懂得 Linux 社区的价值,但是如果要我老实地说,我不相信我们和它有任何的关系。 + +如果我一定要在这上面花钱,我想说 Valve 开发了 Proton,因为他们还没有放弃 [Steam Machine][11]。因为 [Steam OS][12] 是基于 Linux 的发行版,在这类东西上面投资可以获取最大的利润,Steam OS 上可用的游戏越多,就会有更多的人愿意购买 Steam Machine。 + +可能我是错的,但是我敢打赌啊,我们会在不远的未来看到新一批的 Steam Machine。可能我们会在一年内看到它们,也有可能我们再等五年都见不到,谁知道呢! + +无论哪种方式,我所知道的是,我终于能兴奋地从我的 Steam 游戏库里玩游戏了。这个游戏库是多年来我通过各种慈善包、促销码和不定时地买的游戏慢慢积累的,只不过是想试试让它在 Lutris 中运行。 + +#### 为 Linux 上越来越多的游戏而激动? + +你怎么看?你对此感到激动吗?或者说你会害怕只有很少的开发者会开发 Linux 平台上的游戏,因为现在几乎没有需求?Valve 喜欢 Linux 社区,还是说他们喜欢钱?请在下面的评论区告诉我们您的想法,然后重新搜索来查看更多类似这样的开源软件方面的文章。 + +-------------------------------------------------------------------------------- + +via: https://itsfoss.com/steam-play-proton/ + +作者:[Phillip Prado][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[hopefully2333](https://github.com/hopefully2333) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://itsfoss.com/author/phillip/ +[1]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/08/steam-wallpaper.jpeg +[2]:https://itsfoss.com/linux-gaming-guide/ +[3]:https://itsfoss.com/reasons-switch-linux-windows-xp/ +[4]:https://itsfoss.com/triplea-game-review/ +[5]:https://itsfoss.com/play-retro-games-linux/ +[6]:https://steamcommunity.com/games/221410 +[7]:https://github.com/ValveSoftware/Proton/ +[8]:https://www.playonlinux.com/en/ +[9]:https://lutris.net/ +[10]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/08/SteamProton.jpg +[11]:https://store.steampowered.com/sale/steam_machines +[12]:https://itsfoss.com/valve-annouces-linux-based-gaming-operating-system-steamos/ +[13]:https://spcr.netlify.com/ +[14]:https://itsfoss.com/steam-play/ diff --git a/published/20180824 [Solved] -sub process usr bin dpkg returned an error code 1- Error in Ubuntu.md b/published/20180824 [Solved] -sub process usr bin dpkg returned an error code 1- Error in Ubuntu.md new file mode 100644 index 0000000000..df829aa425 --- /dev/null +++ b/published/20180824 [Solved] -sub process usr bin dpkg returned an error code 1- Error in Ubuntu.md @@ -0,0 +1,118 @@ +怎样解决 Ubuntu 中的 “sub process usr bin dpkg returned an error code 1” 错误 +====== + +> 如果你在 Ubuntu Linux 上安装软件时遇到 “sub process usr bin dpkg returned an error code 1”,请按照以下步骤进行修复。 + +Ubuntu 和其他基于 Debian 的发行版中的一个常见问题是已经损坏的包。你尝试更新系统或安装新软件包时会遇到类似 “Sub-process /usr/bin/dpkg returned an error code” 的错误。 + +这就是前几天发生在我身上的事。我试图在 Ubuntu 中安装一个电台程序时,它给我了这个错误: + +``` +Unpacking python-gst-1.0 (1.6.2-1build1) ... +Selecting previously unselected package radiotray. +Preparing to unpack .../radiotray_0.7.3-5ubuntu1_all.deb ... +Unpacking radiotray (0.7.3-5ubuntu1) ... +Processing triggers for man-db (2.7.5-1) ... +Processing triggers for desktop-file-utils (0.22-1ubuntu5.2) ... +Processing triggers for bamfdaemon (0.5.3~bzr0+16.04.20180209-0ubuntu1) ... +Rebuilding /usr/share/applications/bamf-2.index... +Processing triggers for gnome-menus (3.13.3-6ubuntu3.1) ... +Processing triggers for mime-support (3.59ubuntu1) ... +Setting up polar-bookshelf (1.0.0-beta56) ... +ln: failed to create symbolic link '/usr/local/bin/polar-bookshelf': No such file or directory +dpkg: error processing package polar-bookshelf (--configure): +subprocess installed post-installation script returned error exit status 1 +Setting up python-appindicator (12.10.1+16.04.20170215-0ubuntu1) ... +Setting up python-gst-1.0 (1.6.2-1build1) ... +Setting up radiotray (0.7.3-5ubuntu1) ... +Errors were encountered while processing: +polar-bookshelf +E: Sub-process /usr/bin/dpkg returned an error code (1) + +``` + +这里最后三行非常重要。 + +``` +Errors were encountered while processing: +polar-bookshelf +E: Sub-process /usr/bin/dpkg returned an error code (1) +``` + +它告诉我 polar-bookshelf 包引发了问题。这可能对你如何修复这个错误至关重要。 + +### 修复 Sub-process /usr/bin/dpkg returned an error code (1) + +![Fix update errors in Ubuntu Linux][1] + +让我们尝试修复这个损坏的错误包。我将展示几种你可以逐一尝试的方法。最初的那些易于使用,几乎不用动脑子。 + +在试了这里讨论的每一种方法之后,你应该尝试运行 `sudo apt update`,接着尝试安装新的包或升级。 + +#### 方法 1:重新配包数据库 + +你可以尝试的第一种方法是重新配置包数据库。数据库可能在安装包时损坏了。重新配置通常可以解决问题。 + +``` +sudo dpkg --configure -a +``` + +#### 方法 2:强制安装 + +如果是之前包安装过程被中断,你可以尝试强制安装。 + +``` +sudo apt-get install -f +``` + +#### 方法3:尝试删除有问题的包 + +如果这不是你的问题,你可以尝试手动删除包。但不要对 Linux 内核包(以 linux- 开头)执行此操作。 + +``` +sudo apt remove +``` + +#### 方法 4:删除有问题的包中的信息文件 + +这应该是你最后的选择。你可以尝试从 `/var/lib/dpkg/info` 中删除与相关软件包关联的文件。 + +**你需要了解一些基本的 Linux 命令来了解发生了什么以及如何对应你的问题** + +就我而言,我在 polar-bookshelf 中遇到问题。所以我查找了与之关联的文件: + +``` +ls -l /var/lib/dpkg/info | grep -i polar-bookshelf +-rw-r--r-- 1 root root 2324811 Aug 14 19:29 polar-bookshelf.list +-rw-r--r-- 1 root root 2822824 Aug 10 04:28 polar-bookshelf.md5sums +-rwxr-xr-x 1 root root 113 Aug 10 04:28 polar-bookshelf.postinst +-rwxr-xr-x 1 root root 84 Aug 10 04:28 polar-bookshelf.postrm +``` + +现在我需要做的就是删除这些文件: + +``` +sudo mv /var/lib/dpkg/info/polar-bookshelf.* /tmp +``` + +使用 `sudo apt update`,接着你应该就能像往常一样安装软件了。 + +#### 哪种方法适合你(如果有效)? + +我希望这篇快速文章可以帮助你修复 “E: Sub-process /usr/bin/dpkg returned an error code (1)” 的错误。 + +如果它对你有用,是那种方法?你是否设法使用其他方法修复此错误?如果是,请分享一下以帮助其他人解决此问题。 + +-------------------------------------------------------------------------------- + +via: https://itsfoss.com/dpkg-returned-an-error-code-1/ + +作者:[Abhishek Prakash][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[geekpi](https://github.com/geekpi) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://itsfoss.com/author/abhishek/ +[1]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/08/fix-common-update-errors-ubuntu.jpeg diff --git a/published/20180826 How to capture and analyze packets with tcpdump command on Linux.md b/published/20180826 How to capture and analyze packets with tcpdump command on Linux.md new file mode 100644 index 0000000000..431bbefe5e --- /dev/null +++ b/published/20180826 How to capture and analyze packets with tcpdump command on Linux.md @@ -0,0 +1,418 @@ +如何在 Linux 上使用 tcpdump 命令捕获和分析数据包 +====== + +`tcpdump` 是一个有名的命令行**数据包分析**工具。我们可以使用 `tcpdump` 命令捕获实时 TCP/IP 数据包,这些数据包也可以保存到文件中。之后这些捕获的数据包可以通过 `tcpdump` 命令进行分析。`tcpdump` 命令在网络层面进行故障排除时变得非常方便。 + +![](https://www.linuxtechi.com/wp-content/uploads/2018/08/tcpdump-command-examples-linux.jpg) + +`tcpdump` 在大多数 Linux 发行版中都能用,对于基于 Debian 的Linux,可以使用 `apt` 命令安装它。 + +``` +# apt install tcpdump -y +``` + +在基于 RPM 的 Linux 操作系统上,可以使用下面的 `yum` 命令安装 `tcpdump`。 + +``` +# yum install tcpdump -y +``` + +当我们在没用任何选项的情况下运行 `tcpdump` 命令时,它将捕获所有接口的数据包。因此,要停止或取消 `tcpdump` 命令,请键入 `ctrl+c`。在本教程中,我们将使用不同的实例来讨论如何捕获和分析数据包。 + +### 示例:1)从特定接口捕获数据包 + +当我们在没用任何选项的情况下运行 `tcpdump` 命令时,它将捕获所有接口上的数据包,因此,要从特定接口捕获数据包,请使用选项 `-i`,后跟接口名称。 + +语法: + +``` +# tcpdump -i {接口名} +``` + +假设我想从接口 `enp0s3` 捕获数据包。 + +输出将如下所示, + +``` +tcpdump: verbose output suppressed, use -v or -vv for full protocol decode +listening on enp0s3, link-type EN10MB (Ethernet), capture size 262144 bytes +06:43:22.905890 IP compute-0-1.example.com.ssh > 169.144.0.1.39374: Flags [P.], seq 21952160:21952540, ack 13537, win 291, options [nop,nop,TS val 26164373 ecr 6580205], length 380 +06:43:22.906045 IP compute-0-1.example.com.ssh > 169.144.0.1.39374: Flags [P.], seq 21952540:21952760, ack 13537, win 291, options [nop,nop,TS val 26164373 ecr 6580205], length 220 +06:43:22.906150 IP compute-0-1.example.com.ssh > 169.144.0.1.39374: Flags [P.], seq 21952760:21952980, ack 13537, win 291, options [nop,nop,TS val 26164373 ecr 6580205], length 220 +06:43:22.906291 IP 169.144.0.1.39374 > compute-0-1.example.com.ssh: Flags [.], ack 21952980, win 13094, options [nop,nop,TS val 6580205 ecr 26164373], length 0 +06:43:22.906303 IP 169.144.0.1.39374 > compute-0-1.example.com.ssh: Flags [P.], seq 13537:13609, ack 21952980, win 13094, options [nop,nop,TS val 6580205 ecr 26164373], length 72 +06:43:22.906322 IP compute-0-1.example.com.ssh > 169.144.0.1.39374: Flags [P.], seq 21952980:21953200, ack 13537, win 291, options [nop,nop,TS val 26164373 ecr 6580205], length 220 +^C +109930 packets captured +110065 packets received by filter +133 packets dropped by kernel +[[email protected] ~]# + +``` + +### 示例:2)从特定接口捕获特定数量数据包 + +假设我们想从特定接口(如 `enp0s3`)捕获 12 个数据包,这可以使用选项 `-c {数量} -I {接口名称}` 轻松实现。 + +``` +root@compute-0-1 ~]# tcpdump -c 12 -i enp0s3 +``` + +上面的命令将生成如下所示的输出, + +[![N-Number-Packsets-tcpdump-interface][1]][2] + +### 示例:3)显示 tcpdump 的所有可用接口 + +使用 `-D` 选项显示 `tcpdump` 命令的所有可用接口, + +``` +[root@compute-0-1 ~]# tcpdump -D +1.enp0s3 +2.enp0s8 +3.ovs-system +4.br-int +5.br-tun +6.nflog (Linux netfilter log (NFLOG) interface) +7.nfqueue (Linux netfilter queue (NFQUEUE) interface) +8.usbmon1 (USB bus number 1) +9.usbmon2 (USB bus number 2) +10.qbra692e993-28 +11.qvoa692e993-28 +12.qvba692e993-28 +13.tapa692e993-28 +14.vxlan_sys_4789 +15.any (Pseudo-device that captures on all interfaces) +16.lo [Loopback] +[[email protected] ~]# +``` + +我正在我的一个 openstack 计算节点上运行 `tcpdump` 命令,这就是为什么在输出中你会看到数字接口、标签接口、网桥和 vxlan 接口 + +### 示例:4)捕获带有可读时间戳的数据包(`-tttt` 选项) + +默认情况下,在 `tcpdump` 命令输出中,不显示可读性好的时间戳,如果您想将可读性好的时间戳与每个捕获的数据包相关联,那么使用 `-tttt` 选项,示例如下所示, + +``` +[[email protected] ~]# tcpdump -c 8 -tttt -i enp0s3 +tcpdump: verbose output suppressed, use -v or -vv for full protocol decode +listening on enp0s3, link-type EN10MB (Ethernet), capture size 262144 bytes +2018-08-25 23:23:36.954883 IP compute-0-1.example.com.ssh > 169.144.0.1.39406: Flags [P.], seq 1449206247:1449206435, ack 3062020950, win 291, options [nop,nop,TS val 86178422 ecr 21583714], length 188 +2018-08-25 23:23:36.955046 IP 169.144.0.1.39406 > compute-0-1.example.com.ssh: Flags [.], ack 188, win 13585, options [nop,nop,TS val 21583717 ecr 86178422], length 0 +2018-08-25 23:23:37.140097 IP controller0.example.com.amqp > compute-0-1.example.com.57818: Flags [P.], seq 814607956:814607964, ack 2387094506, win 252, options [nop,nop,TS val 86172228 ecr 86176695], length 8 +2018-08-25 23:23:37.140175 IP compute-0-1.example.com.57818 > controller0.example.com.amqp: Flags [.], ack 8, win 237, options [nop,nop,TS val 86178607 ecr 86172228], length 0 +2018-08-25 23:23:37.355238 IP compute-0-1.example.com.57836 > controller0.example.com.amqp: Flags [P.], seq 1080415080:1080417400, ack 1690909362, win 237, options [nop,nop,TS val 86178822 ecr 86163054], length 2320 +2018-08-25 23:23:37.357119 IP controller0.example.com.amqp > compute-0-1.example.com.57836: Flags [.], ack 2320, win 1432, options [nop,nop,TS val 86172448 ecr 86178822], length 0 +2018-08-25 23:23:37.357545 IP controller0.example.com.amqp > compute-0-1.example.com.57836: Flags [P.], seq 1:22, ack 2320, win 1432, options [nop,nop,TS val 86172449 ecr 86178822], length 21 +2018-08-25 23:23:37.357572 IP compute-0-1.example.com.57836 > controller0.example.com.amqp: Flags [.], ack 22, win 237, options [nop,nop,TS val 86178825 ecr 86172449], length 0 +8 packets captured +134 packets received by filter +69 packets dropped by kernel +[[email protected] ~]# +``` + +### 示例:5)捕获数据包并将其保存到文件(`-w` 选项) + +使用 `tcpdump` 命令中的 `-w` 选项将捕获的 TCP/IP 数据包保存到一个文件中,以便我们可以在将来分析这些数据包以供进一步分析。 + +语法: + +``` +# tcpdump -w 文件名.pcap -i {接口名} +``` + +注意:文件扩展名必须为 `.pcap`。 + +假设我要把 `enp0s3` 接口捕获到的包保存到文件名为 `enp0s3-26082018.pcap`。 + +``` +[root@compute-0-1 ~]# tcpdump -w enp0s3-26082018.pcap -i enp0s3 +``` + +上述命令将生成如下所示的输出, + +``` +[root@compute-0-1 ~]# tcpdump -w enp0s3-26082018.pcap -i enp0s3 +tcpdump: listening on enp0s3, link-type EN10MB (Ethernet), capture size 262144 bytes +^C841 packets captured +845 packets received by filter +0 packets dropped by kernel +[root@compute-0-1 ~]# ls +anaconda-ks.cfg enp0s3-26082018.pcap +[root@compute-0-1 ~]# +``` + +捕获并保存大小**大于 N 字节**的数据包。 + +``` +[root@compute-0-1 ~]# tcpdump -w enp0s3-26082018-2.pcap greater 1024 +``` + +捕获并保存大小**小于 N 字节**的数据包。 + +``` +[root@compute-0-1 ~]# tcpdump -w enp0s3-26082018-3.pcap less 1024 +``` + +### 示例:6)从保存的文件中读取数据包(`-r` 选项) + +在上面的例子中,我们已经将捕获的数据包保存到文件中,我们可以使用选项 `-r` 从文件中读取这些数据包,例子如下所示, + +``` +[root@compute-0-1 ~]# tcpdump -r enp0s3-26082018.pcap +``` + +用可读性高的时间戳读取包内容, + +``` +[root@compute-0-1 ~]# tcpdump -tttt -r enp0s3-26082018.pcap +reading from file enp0s3-26082018.pcap, link-type EN10MB (Ethernet) +2018-08-25 22:03:17.249648 IP compute-0-1.example.com.ssh > 169.144.0.1.39406: Flags [P.], seq 1426167803:1426167927, ack 3061962134, win 291, options +[nop,nop,TS val 81358717 ecr 20378789], length 124 +2018-08-25 22:03:17.249840 IP 169.144.0.1.39406 > compute-0-1.example.com.ssh: Flags [.], ack 124, win 564, options [nop,nop,TS val 20378791 ecr 81358 +717], length 0 +2018-08-25 22:03:17.454559 IP controller0.example.com.amqp > compute-0-1.example.com.57836: Flags [.], ack 1079416895, win 1432, options [nop,nop,TS v +al 81352560 ecr 81353913], length 0 +2018-08-25 22:03:17.454642 IP compute-0-1.example.com.57836 > controller0.example.com.amqp: Flags [.], ack 1, win 237, options [nop,nop,TS val 8135892 +2 ecr 81317504], length 0 +2018-08-25 22:03:17.646945 IP compute-0-1.example.com.57788 > controller0.example.com.amqp: Flags [.], seq 106760587:106762035, ack 688390730, win 237 +, options [nop,nop,TS val 81359114 ecr 81350901], length 1448 +2018-08-25 22:03:17.647043 IP compute-0-1.example.com.57788 > controller0.example.com.amqp: Flags [P.], seq 1448:1956, ack 1, win 237, options [nop,no +p,TS val 81359114 ecr 81350901], length 508 +2018-08-25 22:03:17.647502 IP controller0.example.com.amqp > compute-0-1.example.com.57788: Flags [.], ack 1956, win 1432, options [nop,nop,TS val 813 +52753 ecr 81359114], length 0 +......................................................................................................................... +``` + +### 示例:7)仅捕获特定接口上的 IP 地址数据包(`-n` 选项) + +使用 `tcpdump` 命令中的 `-n` 选项,我们能只捕获特定接口上的 IP 地址数据包,示例如下所示, + +``` +[root@compute-0-1 ~]# tcpdump -n -i enp0s3 +``` + +上述命令输出如下, + +``` +tcpdump: verbose output suppressed, use -v or -vv for full protocol decode +listening on enp0s3, link-type EN10MB (Ethernet), capture size 262144 bytes +22:22:28.537904 IP 169.144.0.20.ssh > 169.144.0.1.39406: Flags [P.], seq 1433301395:1433301583, ack 3061976250, win 291, options [nop,nop,TS val 82510005 ecr 20666610], length 188 +22:22:28.538173 IP 169.144.0.1.39406 > 169.144.0.20.ssh: Flags [.], ack 188, win 9086, options [nop,nop,TS val 20666613 ecr 82510005], length 0 +22:22:28.538573 IP 169.144.0.20.ssh > 169.144.0.1.39406: Flags [P.], seq 188:552, ack 1, win 291, options [nop,nop,TS val 82510006 ecr 20666613], length 364 +22:22:28.538736 IP 169.144.0.1.39406 > 169.144.0.20.ssh: Flags [.], ack 552, win 9086, options [nop,nop,TS val 20666613 ecr 82510006], length 0 +22:22:28.538874 IP 169.144.0.20.ssh > 169.144.0.1.39406: Flags [P.], seq 552:892, ack 1, win 291, options [nop,nop,TS val 82510006 ecr 20666613], length 340 +22:22:28.539042 IP 169.144.0.1.39406 > 169.144.0.20.ssh: Flags [.], ack 892, win 9086, options [nop,nop,TS val 20666613 ecr 82510006], length 0 +22:22:28.539178 IP 169.144.0.20.ssh > 169.144.0.1.39406: Flags [P.], seq 892:1232, ack 1, win 291, options [nop,nop,TS val 82510006 ecr 20666613], length 340 +22:22:28.539282 IP 169.144.0.1.39406 > 169.144.0.20.ssh: Flags [.], ack 1232, win 9086, options [nop,nop,TS val 20666614 ecr 82510006], length 0 +22:22:28.539479 IP 169.144.0.20.ssh > 169.144.0.1.39406: Flags [P.], seq 1232:1572, ack 1, win 291, options [nop,nop,TS val 82510006 ecr 20666614], length 340 +22:22:28.539595 IP 169.144.0.1.39406 > 169.144.0.20.ssh: Flags [.], ack 1572, win 9086, options [nop,nop,TS val 20666614 ecr 82510006], length 0 +22:22:28.539760 IP 169.144.0.20.ssh > 169.144.0.1.39406: Flags [P.], seq 1572:1912, ack 1, win 291, options [nop,nop,TS val 82510007 ecr 20666614], length 340 +......................................................................... +``` + +您还可以使用 `tcpdump` 命令中的 `-c` 和 `-N` 选项捕获 N 个 IP 地址包, + +``` +[root@compute-0-1 ~]# tcpdump -c 25 -n -i enp0s3 +``` + + +### 示例:8)仅捕获特定接口上的 TCP 数据包 + +在 `tcpdump` 命令中,我们能使用 `tcp` 选项来只捕获 TCP 数据包, + +``` +[root@compute-0-1 ~]# tcpdump -i enp0s3 tcp +tcpdump: verbose output suppressed, use -v or -vv for full protocol decode +listening on enp0s3, link-type EN10MB (Ethernet), capture size 262144 bytes +22:36:54.521053 IP 169.144.0.20.ssh > 169.144.0.1.39406: Flags [P.], seq 1433336467:1433336655, ack 3061986618, win 291, options [nop,nop,TS val 83375988 ecr 20883106], length 188 +22:36:54.521474 IP 169.144.0.1.39406 > 169.144.0.20.ssh: Flags [.], ack 188, win 9086, options [nop,nop,TS val 20883109 ecr 83375988], length 0 +22:36:54.522214 IP 169.144.0.20.ssh > 169.144.0.1.39406: Flags [P.], seq 188:552, ack 1, win 291, options [nop,nop,TS val 83375989 ecr 20883109], length 364 +22:36:54.522508 IP 169.144.0.1.39406 > 169.144.0.20.ssh: Flags [.], ack 552, win 9086, options [nop,nop,TS val 20883109 ecr 83375989], length 0 +22:36:54.522867 IP 169.144.0.20.ssh > 169.144.0.1.39406: Flags [P.], seq 552:892, ack 1, win 291, options [nop,nop,TS val 83375990 ecr 20883109], length 340 +22:36:54.523006 IP 169.144.0.1.39406 > 169.144.0.20.ssh: Flags [.], ack 892, win 9086, options [nop,nop,TS val 20883109 ecr 83375990], length 0 +22:36:54.523304 IP 169.144.0.20.ssh > 169.144.0.1.39406: Flags [P.], seq 892:1232, ack 1, win 291, options [nop,nop,TS val 83375990 ecr 20883109], length 340 +22:36:54.523461 IP 169.144.0.1.39406 > 169.144.0.20.ssh: Flags [.], ack 1232, win 9086, options [nop,nop,TS val 20883110 ecr 83375990], length 0 +22:36:54.523604 IP 169.144.0.20.ssh > 169.144.0.1.39406: Flags [P.], seq 1232:1572, ack 1, win 291, options [nop,nop,TS val 83375991 ecr 20883110], length 340 +................................................................................................................................................... +``` + +### 示例:9)从特定接口上的特定端口捕获数据包 + +使用 `tcpdump` 命令,我们可以从特定接口 `enp0s3` 上的特定端口(例如 22)捕获数据包。 + +语法: + +``` +# tcpdump -i {interface-name} port {Port_Number} +``` +``` +[root@compute-0-1 ~]# tcpdump -i enp0s3 port 22 +tcpdump: verbose output suppressed, use -v or -vv for full protocol decode +listening on enp0s3, link-type EN10MB (Ethernet), capture size 262144 bytes +22:54:45.032412 IP compute-0-1.example.com.ssh > 169.144.0.1.39406: Flags [P.], seq 1435010787:1435010975, ack 3061993834, win 291, options [nop,nop,TS val 84446499 ecr 21150734], length 188 +22:54:45.032631 IP 169.144.0.1.39406 > compute-0-1.example.com.ssh: Flags [.], ack 188, win 9131, options [nop,nop,TS val 21150737 ecr 84446499], length 0 +22:54:55.037926 IP compute-0-1.example.com.ssh > 169.144.0.1.39406: Flags [P.], seq 188:576, ack 1, win 291, options [nop,nop,TS val 84456505 ecr 21150737], length 388 +22:54:55.038106 IP 169.144.0.1.39406 > compute-0-1.example.com.ssh: Flags [.], ack 576, win 9154, options [nop,nop,TS val 21153238 ecr 84456505], length 0 +22:54:55.038286 IP compute-0-1.example.com.ssh > 169.144.0.1.39406: Flags [P.], seq 576:940, ack 1, win 291, options [nop,nop,TS val 84456505 ecr 21153238], length 364 +22:54:55.038564 IP 169.144.0.1.39406 > compute-0-1.example.com.ssh: Flags [.], ack 940, win 9177, options [nop,nop,TS val 21153238 ecr 84456505], length 0 +22:54:55.038708 IP compute-0-1.example.com.ssh > 169.144.0.1.39406: Flags [P.], seq 940:1304, ack 1, win 291, options [nop,nop,TS val 84456506 ecr 21153238], length 364 +............................................................................................................................ +``` + + +### 示例:10)在特定接口上捕获来自特定来源 IP 的数据包 + +在 `tcpdump` 命令中,使用 `src` 关键字后跟 IP 地址,我们可以捕获来自特定来源 IP 的数据包, + +语法: + +``` +# tcpdump -n -i {接口名} src {IP 地址} +``` + +例子如下, + +``` +[root@compute-0-1 ~]# tcpdump -n -i enp0s3 src 169.144.0.10 +tcpdump: verbose output suppressed, use -v or -vv for full protocol decode +listening on enp0s3, link-type EN10MB (Ethernet), capture size 262144 bytes +23:03:45.912733 IP 169.144.0.10.amqp > 169.144.0.20.57800: Flags [.], ack 526623844, win 243, options [nop,nop,TS val 84981008 ecr 84982372], length 0 +23:03:46.136757 IP 169.144.0.10.amqp > 169.144.0.20.57796: Flags [.], ack 2535995970, win 252, options [nop,nop,TS val 84981232 ecr 84982596], length 0 +23:03:46.153398 IP 169.144.0.10.amqp > 169.144.0.20.57798: Flags [.], ack 3623063621, win 243, options [nop,nop,TS val 84981248 ecr 84982612], length 0 +23:03:46.361160 IP 169.144.0.10.amqp > 169.144.0.20.57802: Flags [.], ack 2140263945, win 252, options [nop,nop,TS val 84981456 ecr 84982821], length 0 +23:03:46.376926 IP 169.144.0.10.amqp > 169.144.0.20.57808: Flags [.], ack 175946224, win 252, options [nop,nop,TS val 84981472 ecr 84982836], length 0 +23:03:46.505242 IP 169.144.0.10.amqp > 169.144.0.20.57810: Flags [.], ack 1016089556, win 252, options [nop,nop,TS val 84981600 ecr 84982965], length 0 +23:03:46.616994 IP 169.144.0.10.amqp > 169.144.0.20.57812: Flags [.], ack 832263835, win 252, options [nop,nop,TS val 84981712 ecr 84983076], length 0 +23:03:46.809344 IP 169.144.0.10.amqp > 169.144.0.20.57814: Flags [.], ack 2781799939, win 252, options [nop,nop,TS val 84981904 ecr 84983268], length 0 +23:03:46.809485 IP 169.144.0.10.amqp > 169.144.0.20.57816: Flags [.], ack 1662816815, win 252, options [nop,nop,TS val 84981904 ecr 84983268], length 0 +23:03:47.033301 IP 169.144.0.10.amqp > 169.144.0.20.57818: Flags [.], ack 2387094362, win 252, options [nop,nop,TS val 84982128 ecr 84983492], length 0 +^C +10 packets captured +12 packets received by filter +0 packets dropped by kernel +``` + +### 示例:11)在特定接口上捕获来自特定目的 IP 的数据包 + +语法: + +``` +# tcpdump -n -i {接口名} dst {IP 地址} +``` + +``` +[root@compute-0-1 ~]# tcpdump -n -i enp0s3 dst 169.144.0.1 +tcpdump: verbose output suppressed, use -v or -vv for full protocol decode +listening on enp0s3, link-type EN10MB (Ethernet), capture size 262144 bytes +23:10:43.520967 IP 169.144.0.20.ssh > 169.144.0.1.39406: Flags [P.], seq 1439564171:1439564359, ack 3062005550, win 291, options [nop,nop,TS val 85404988 ecr 21390356], length 188 +23:10:43.521441 IP 169.144.0.20.ssh > 169.144.0.1.39406: Flags [P.], seq 188:408, ack 1, win 291, options [nop,nop,TS val 85404988 ecr 21390359], length 220 +23:10:43.521719 IP 169.144.0.20.ssh > 169.144.0.1.39406: Flags [P.], seq 408:604, ack 1, win 291, options [nop,nop,TS val 85404989 ecr 21390359], length 196 +23:10:43.521993 IP 169.144.0.20.ssh > 169.144.0.1.39406: Flags [P.], seq 604:800, ack 1, win 291, options [nop,nop,TS val 85404989 ecr 21390359], length 196 +23:10:43.522157 IP 169.144.0.20.ssh > 169.144.0.1.39406: Flags [P.], seq 800:996, ack 1, win 291, options [nop,nop,TS val 85404989 ecr 21390359], length 196 +23:10:43.522346 IP 169.144.0.20.ssh > 169.144.0.1.39406: Flags [P.], seq 996:1192, ack 1, win 291, options [nop,nop,TS val 85404989 ecr 21390359], length 196 +......................................................................................... +``` + +### 示例:12)捕获两台主机之间的 TCP 数据包通信 + +假设我想捕获两台主机 169.144.0.1 和 169.144.0.20 之间的 TCP 数据包,示例如下所示, + +``` +[root@compute-0-1 ~]# tcpdump -w two-host-tcp-comm.pcap -i enp0s3 tcp and \(host 169.144.0.1 or host 169.144.0.20\) +``` + +使用 `tcpdump` 命令只捕获两台主机之间的 SSH 数据包流, + +``` +[root@compute-0-1 ~]# tcpdump -w ssh-comm-two-hosts.pcap -i enp0s3 src 169.144.0.1 and port 22 and dst 169.144.0.20 and port 22 +``` + +### 示例:13)捕获两台主机之间(来回)的 UDP 网络数据包 + +语法: + +``` +# tcpdump -w -s -i udp and \(host and host \) +``` + +``` +[root@compute-0-1 ~]# tcpdump -w two-host-comm.pcap -s 1000 -i enp0s3 udp and \(host 169.144.0.10 and host 169.144.0.20\) +``` + +### 示例:14)捕获十六进制和 ASCII 格式的数据包 + +使用 `tcpdump` 命令,我们可以以 ASCII 和十六进制格式捕获 TCP/IP 数据包, + +要使用 `-A` 选项捕获 ASCII 格式的数据包,示例如下所示: + +``` +[root@compute-0-1 ~]# tcpdump -c 10 -A -i enp0s3 +tcpdump: verbose output suppressed, use -v or -vv for full protocol decode +listening on enp0s3, link-type EN10MB (Ethernet), capture size 262144 bytes +00:37:10.520060 IP compute-0-1.example.com.ssh > 169.144.0.1.39406: Flags [P.], seq 1452637331:1452637519, ack 3062125586, win 333, options [nop,nop,TS val 90591987 ecr 22687106], length 188 +E...[root@compute-0-1 @...............V.|...T....MT...... +.fR..Z-....b.:..Z5...{.'p....]."}...Z..9.?......."root@compute-0-1 <.....V..C.....{,...OKP.2.*...`..-sS..1S...........:.O[.....{G..%ze.Pn.T..N.... ....qB..5...n.....`...:=...[..0....k.....S.:..5!.9..G....!-..'.. +00:37:10.520319 IP 169.144.0.1.39406 > compute-0-1.example.com.ssh: Flags [.], ack 188, win 13930, options [nop,nop,TS val 22687109 ecr 90591987], length 0 +root@compute-0-1 @.|+..............T.V.}O..6j.d..... +.Z-..fR. +00:37:11.687543 IP controller0.example.com.amqp > compute-0-1.example.com.57800: Flags [.], ack 526624548, win 243, options [nop,nop,TS val 90586768 ecr 90588146], length 0 +root@compute-0-1 @.!L... +.....(..g....c.$........... +.f>..fC. +00:37:11.687612 IP compute-0-1.example.com.57800 > controller0.example.com.amqp: Flags [.], ack 1, win 237, options [nop,nop,TS val 90593155 ecr 90551716], length 0 +root@compute-0-1 @.......... +...(.c.$g.......Se..... +.fW..e.. +.................................................................................................................................................. +``` + +要同时以十六进制和 ASCII 格式捕获数据包,请使用 `-XX` 选项。 + +``` +[root@compute-0-1 ~]# tcpdump -c 10 -XX -i enp0s3 +tcpdump: verbose output suppressed, use -v or -vv for full protocol decode +listening on enp0s3, link-type EN10MB (Ethernet), capture size 262144 bytes +00:39:15.124363 IP compute-0-1.example.com.ssh > 169.144.0.1.39406: Flags [P.], seq 1452640859:1452641047, ack 3062126346, win 333, options [nop,nop,TS val 90716591 ecr 22718257], length 188 +0x0000: 0a00 2700 0000 0800 27f4 f935 0800 4510 ..'.....'..5..E. +0x0010: 00f0 5bc6 4000 4006 8afc a990 0014 a990 ..[root@compute-0-1 @......... +0x0020: 0001 0016 99ee 5695 8a5b b684 570a 8018 ......V..[..W... +0x0030: 014d 5418 0000 0101 080a 0568 39af 015a .MT........h9..Z +0x0040: a731 adb7 58b6 1a0f 2006 df67 c9b6 4479 .1..X......g..Dy +0x0050: 19fd 2c3d 2042 3313 35b9 a160 fa87 d42c ..,=.B3.5..`..., +0x0060: 89a9 3d7d dfbf 980d 2596 4f2a 99ba c92a ..=}....%.O*...* +0x0070: 3e1e 7bf7 3af2 a5cc ee4f 10bc 7dfc 630d >.{.:....O..}.c. +0x0080: 898a 0e16 6825 56c7 b683 1de4 3526 ff04 ....h%V.....5&.. +0x0090: 68d1 4f7d babd 27ba 84ae c5d3 750b 01bd h.O}..'.....u... +0x00a0: 9c43 e10a 33a6 8df2 a9f0 c052 c7ed 2ff5 .C..3......R../. +0x00b0: bfb1 ce84 edfc c141 6dad fa19 0702 62a7 .......Am.....b. +0x00c0: 306c db6b 2eea 824e eea5 acd7 f92e 6de3 0l.k...N......m. +0x00d0: 85d0 222d f8bf 9051 2c37 93c8 506d 5cb5 .."-...Q,7..Pm\. +0x00e0: 3b4a 2a80 d027 49f2 c996 d2d9 a9eb c1c4 ;J*..'I......... +0x00f0: 7719 c615 8486 d84c e42d 0ba3 698c w......L.-..i. +00:39:15.124648 IP 169.144.0.1.39406 > compute-0-1.example.com.ssh: Flags [.], ack 188, win 13971, options [nop,nop,TS val 22718260 ecr 90716591], length 0 +0x0000: 0800 27f4 f935 0a00 2700 0000 0800 4510 ..'..5..'.....E. +0x0010: 0034 6b70 4000 4006 7c0e a990 0001 a990 root@compute-0-1 @.|....... +0x0020: 0014 99ee 0016 b684 570a 5695 8b17 8010 ........W.V..... +0x0030: 3693 7c0e 0000 0101 080a 015a a734 0568 6.|........Z.4.h +0x0040: 39af +....................................................................... +``` + +这就是本文的全部内容,我希望您能了解如何使用 `tcpdump` 命令捕获和分析 TCP/IP 数据包。请分享你的反馈和评论。 + +-------------------------------------------------------------------------------- + +via: https://www.linuxtechi.com/capture-analyze-packets-tcpdump-command-linux/ + +作者:[Pradeep Kumar][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[ypingcn](https://github.com/ypingcn) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: http://www.linuxtechi.com/author/pradeep/ +[1]: https://www.linuxtechi.com/wp-content/uploads/2018/08/N-Number-Packsets-tcpdump-interface-1024x422.jpg +[2]: https://www.linuxtechi.com/wp-content/uploads/2018/08/N-Number-Packsets-tcpdump-interface.jpg diff --git a/published/20180827 An introduction to diffs and patches.md b/published/20180827 An introduction to diffs and patches.md new file mode 100644 index 0000000000..734b1cc978 --- /dev/null +++ b/published/20180827 An introduction to diffs and patches.md @@ -0,0 +1,122 @@ +差异文件(diff)和补丁文件(patch)简介 +====== + +> 这篇文章介绍差异文件diff补丁文件patch,以及它们如何在开源项目中使用的例子。 + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/find-file-linux-code_magnifying_glass_zero.png?itok=E2HoPDg0) + +如果你曾有机会在一个使用分布式开发模型的大型代码库上工作过,你就应该听说过类似下面的话,“Sue 刚发过来一个补丁patch”,“Rajiv 正在签出checking out差异diff”, 可能这些词(补丁、差异文件)对你而言很陌生,而你确定很想搞懂他们到底指什么。开源软件对上述提到的名词有很大的贡献,作为大型项目从 Apache web 服务器到 Linux 内核的开发模型,“基于补丁文件的开发” 这一模式贯穿了上述项目的始终。实际上,你可能不知道 Apache 的名字就来自“一系列的代码补丁”(LCTT 译注:Apache 英文发音和补丁的英文 patch 相似),它们被一一收集起来并针对原来的 [NCSA HTTPd server source code][1] 进行了修订。 + +你可能认为这只不过是些逸闻,但是一份早期的 [Apache 网站的存档中][2] 声称 Apache 的名字就是来自于最早的“补丁”集合;即“打了补丁的APAtCHy”服务器,简化为 Apache。 + +好了,言归正传,程序员嘴里说的“差异”和“补丁”到底是什么? + +首先,在这篇文章里,我们可以认为这两个术语都指向同一个概念。“diff” 是 ”difference“ 的简写;Unix 下的同名工具程序 `diff`剖析了一个或多个文件之间的“差异”。下面我们会看到 `diff` 的例子: + +一个“补丁”指的是文件之间一系列差异,这些差异能被 Unix 的 `diff` 程序应用在源代码树上。我们能使用 `diff` 工具来创建“差异”(或“补丁”),然后使用该工具将它们 “打” 在一个没有这个补丁的同样的源代码版本上。此外,(我又要开始跑题说些历史轶事了……),“补丁” 这个词真的指在计算机的早期使用打卡机的时候,用来覆盖在打孔纸带上来对软件进行修改的覆盖纸,那个时代打孔纸带就是在计算机处理器上运行的程序。下面来自 [维基页面][3] 的这张图真切的描绘了最初的“打补丁”这个词的出处: + +![](https://opensource.com/sites/default/files/uploads/360px-harvard_mark_i_program_tape.agr_.jpg) + +现在你对补丁和差异就了一个基本的概念,让我们来看看软件开发者是怎么使用这些工具的。如果你还没有使用过类似于 [Git][4] 或 [subversion][5] 这样的源代码版本控制工具的话,我将会一步步展示最流行的软件项目是怎么使用它们的。如果你将一个软件的生命周期看成是一条时间线的话,你就能看见这个软件的点滴变化,比如在何时源代码加上了一个功能,在何时源代码修复了一个功能缺陷。我们称这些改变的点为“提交commit”,“提交”这个词被当今最流行的源代码版本管理工具 Git 所使用,当你想检查在一个提交前后的代码变化的话,(或者在许多个提交之间的代码变化),你都可以使用工具来观察文件差异。 + +如果你同样在使用 Git 开发软件的话,你可以在你的本地开发环境做些希望交给别的开发者的提交,以添加到他们的源代码树中。为了给别的开发者你的提交,一个方法就是创建一个你本地文件的差异文件,然后将这个“补丁”发送给和你工作在同一个源代码树的别的开发者。别的开发者在“打”了你的补丁之后,就能看到在你的代码变树上的变化。 + +### Linux、Git 和 GitHub + +这种分享补丁的开发模型正是现今 Linux 内核社区如何处理内核修改提议而采用的模型。如果你有机会浏览任何一个主流的 Linux 内核邮件列表 —— 主要是 [LKML][6],也包括 [linux-containers][7]、[fs-devel][8]、[Netdev][9] 等等,你能看到很多开发者会贴出他们想让其他内核开发者审核、测试或者合入 Linux 官方 Git 代码树某个位置的补丁。当然,讨论 Git 不在这篇文章范围之内(Git 是由 Linus Torvalds 开发的源代码控制系统,它支持分布式开发模型以及允许独立于主要代码仓库的补丁包,这些补丁包能被推送或拉取到不同的源代码树上,并遵守这些代码树各自的开发流程。) + +在继续我们的话题之前,我们当然不能忽略和补丁和差异这个概念相关的最流行的服务:[GitHub][10]。从它的名字就能猜想出 GitHub 是基于 Git 的,而且它还围绕着 Git 对分布式开源代码开发模型提供了基于 Web 和 API 的工作流管理。(LCTT 译注:即拉取请求Pull Request)。在 GitHub 上,分享补丁的方式不是像 Linux 内核社区那样通过邮件列表,而是通过创建一个 **拉取请求** 。当你提交你自己的源代码树的改动时,你能通过创建一个针对软件项目的共享仓库的“拉取请求”来分享你的代码改动(LCTT 译注:即核心开发者维护一个主仓库,开发者去“复刻fork”这个仓库,待各自的提交后再创建针对这个主仓库的拉取请求,所有的拉取请求由主仓库的核心开发者批准后才能合入主代码库。)GitHub 被当今很多活跃的开源社区所采用,如 [Kubernetes][11]、[Docker][12]、[容器网络接口 (CNI)][13]、[Istio][14] 等等。在 GitHub 的世界里,用户会倾向于使用基于 Web 页面的方式来审核一个拉取请求里的补丁或差异,你也可以直接访问原始的补丁并在命令行上直接使用它们。 + +### 该说点干货了 + +我们前面已经讲了在流行的开源社区里是怎么应用补丁和差异的,现在看看一些例子。 + +第一个例子包括一个源代码树的两个不同副本,其中一个有代码改动,我们想用 `diff` 来看看这些改动是什么。这个例子里,我们想看的是“合并格式unified”的补丁,这是现在软件开发世界里最通用的格式。如果想知道更详细参数的用法以及如何生成差异文件,请参考 `diff` 手册。原始的代码在 `sources-orig` 目录,而改动后的代码在 `sources-fixed` 目录。如果要在你的命令行上用“合并格式”来展示补丁,请运行如下命令。(LCTT 译注:参数 `-N` 代表如果比较的文件不存在,则认为是个空文件, `-a` 代表将所有文件都作为文本文件对待,`-u` 代表使用合并格式并输出上下文,`-r` 代表递归比较目录) + + +``` +$ diff -Naur sources-orig/ sources-fixed/ +``` + +……下面是 `diff` 命令的输出: + +``` +diff -Naur sources-orig/officespace/interest.go sources-fixed/officespace/interest.go +--- sources-orig/officespace/interest.go        2018-08-10 16:39:11.000000000 -0400 ++++ sources-fixed/officespace/interest.go       2018-08-10 16:39:40.000000000 -0400 +@@ -11,15 +11,13 @@ +   InterestRate float64 + } + ++// compute the rounded interest for a transaction + func computeInterest(acct *Account, t Transaction) float64 { + +   interest := t.Amount * t.InterestRate +   roundedInterest := math.Floor(interest*100) / 100.0 +   remainingInterest := interest - roundedInterest + +-  // a little extra.. +-  remainingInterest *= 1000 +- +   // Save the remaining interest into an account we control: +   acct.Balance = acct.Balance + remainingInterest +``` + +最开始几行 `diff` 命令的输出可以这样解释:三个 `---` 显示了原来文件的名字;任何在原文件(LCTT 译注:不是源文件)里存在而在新文件里不存在的行将会用前缀 `-`,用来表示这些行被从源代码里“减去”了。而 `+++` 表示的则相反:在新文件里被加上的行会被放上前缀 `+`,表示这是在新文件里被“加上”的行。补丁文件中的每一个补丁“块”(用 `@@` 作为前缀的的部分)都有上下文的行号,这能帮助补丁工具(或其它处理器)知道在代码的哪里应用这个补丁块。你能看到我们已经修改了“Office Space”这部电影里提到的那个函数(移除了三行并加上了一行代码注释),电影里那个有点贪心的工程师可是偷偷的在计算利息的函数里加了点“料”哦。(LCTT译注:剧情详情请见电影 https://movie.douban.com/subject/1296424/) + +如果你想找人来测试你的代码改动,你可以将差异保存到一个补丁里: + +``` +$ diff -Naur sources-orig/ sources-fixed/ >myfixes.patch +``` + +现在你有补丁 `myfixes.patch` 了,你能把它分享给别的开发者,他们可以将这个补丁打在他们自己的源代码树上从而得到和你一样的代码并测试他们。如果一个开发者的当前工作目录就是他的源代码树的根的话,他可以用下面的命令来打补丁: + +``` +$ patch -p1 < ../myfixes.patch +patching file officespace/interest.go +``` + +现在这个开发者的源代码树已经打好补丁并准备好构建和测试文件的修改了。那么如果这个开发者在打补丁之前已经改动过了怎么办?只要这些改动没有直接冲突(LCTT 译注:比如改在同一行上),补丁工具就能自动的合并代码的改动。例如下面的interest.go 文件,它有其它几处改动,然后它想打上 `myfixes.patch` 这个补丁: + +``` +$ patch -p1 < ../myfixes.patch +patching file officespace/interest.go +Hunk #1 succeeded at 26 (offset 15 lines). +``` + +在这个例子中,补丁警告说代码改动并不在文件原来的地方而是偏移了 15 行。如果你文件改动的很厉害,补丁可能干脆说找不到要应用的地方,还好补丁程序提供了提供了打开“模糊”匹配的选项(这个选项在文档里有预置的警告信息,对其讲解已经超出了本文的范围)。 + +如果你使用 Git 或者 GitHub 的话,你可能不会直接使用补丁或差异。Git 已经内置了这些功能,你能使用这些功能和共享一个源代码树的其他开发者交互,拉取或合并代码。Git 一个比较相近的功能是可以使用 `git diff` 来对你的本地代码树生成全局差异,又或者对你的任意两次”引用“(可能是一个代表提交的数字,或一个标记或分支的名字,等等)做全局补丁。你甚至能简单的用管道将 `git diff` 的输出到一个文件里(这个文件必须严格符合将要被使用它的程序的输入要求),然后将这个文件交给一个并不使用 Git 的开发者应用到他的代码上。当然,GitHub 把这些功能放到了 Web 上,你能直接在 Web 页面上查看一个拉取请求的文件变动。在 Web 上你能看到所展示的合并差异,GitHub 还允许你将这些代码改动下载为原始的补丁文件。 + +### 总结 + +好了,你已经学到了”差异“和”补丁“是什么,以及在 Unix/Linux 上怎么使用命令行工具和它们交互。除非你还在像 Linux 内核开发这样的项目中工作而使用完全基于补丁文件的开发方式,你应该会主要通过你的源代码控制系统(如 Git)来使用补丁。但熟悉像 GitHub 这样的高级别工具的技术背景和技术底层对你的工作也是大有裨益的。谁知道会不会有一天你需要和一个来自 Linux 世界邮件列表的补丁包打交道呢? + + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/8/diffs-patches + +作者:[Phil Estes][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[David Chen](https://github.com/DavidChenLiang) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://opensource.com/users/estesp +[1]:https://github.com/TooDumbForAName/ncsa-httpd +[2]:https://web.archive.org/web/19970615081902/http:/www.apache.org/info.html +[3]:https://en.wikipedia.org/wiki/Patch_(computing) +[4]:https://git-scm.com/ +[5]:https://subversion.apache.org/ +[6]:https://lkml.org/ +[7]:https://lists.linuxfoundation.org/pipermail/containers/ +[8]:https://patchwork.kernel.org/project/linux-fsdevel/list/ +[9]:https://www.spinics.net/lists/netdev/ +[10]:https://github.com/ +[11]:https://kubernetes.io/ +[12]:https://www.docker.com/ +[13]:https://github.com/containernetworking/cni +[14]:https://istio.io/ diff --git a/published/20180828 15 command-line aliases to save you time.md b/published/20180828 15 command-line aliases to save you time.md new file mode 100644 index 0000000000..77d7f713b7 --- /dev/null +++ b/published/20180828 15 command-line aliases to save you time.md @@ -0,0 +1,134 @@ +15 个可以节省你时间的命令别名 +====== +> 在你安装的 Linux 发行版中默认就包含了一些别名。 + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/computer_keyboard_laptop_development_blue.png?itok=IfckxN48) + +Linux 命令行别名非常适合帮助你提高工作效率。更好的是,在你安装的 Linux 发行版中默认就包含了一些别名。 + +这是 Fedora 27 中的命令别名的示例: + +![](https://opensource.com/sites/default/files/uploads/default.png) + +这个 `alias` 命令列出了已有的别名。设置别名也十分简单: + +``` +alias new_name="command" +``` + +这里有 15 个命令行别名,可以节省你的时间: + +1、安装任何应用实用 / 应用程序: + +``` +alias install="sudo yum install -y" +``` + +在这里,根据每个用户的偏好,`sudo` 和 `-y` 是可选的: + +![install alias.png][2] + +2、更新系统: + +``` +alias update="sudo yum update -y" +``` + +3、升级系统: + +``` +alias upgrade="sudo yum upgrade -y" +``` + +4、切换 root 用户: + +``` +alias root="sudo su -" +``` + +5、切换到 “user” 用户, 其中 `user` 设置为你的用户名: + +``` +alias user="su user" +``` + +6、显示列出所有可用端口、状态还有 IP: + +``` +alias myip="ip -br -c a" +``` + +7、`ssh` 到你的服务器 `myserver`: + +``` +alias myserver="ssh user@my_server_ip” +``` + +8、列出系统中所有进程: + +``` +alias process="ps -aux" +``` + +9、检查系统的服务状态: + +``` +alias sstatus="sudo systemctl status" +``` + +10、重启系统服务: + +``` +alias srestart="sudo systemctl restart" +``` + +11、按名称杀死进程: + +``` +alias kill="sudo pkill" +``` + +![kill process alias.png][4] + +12、显示系统系统总使用内存和空闲内存 : + +``` +alias mem="free -h" +``` + +13、显示系统 CPU 框架结构、CPU 数量、线程数等: + +``` +alias cpu="lscpu" +``` + +14、显示系统总磁盘大小: + +``` +alias disk="df -h" +``` + +15、显示当前系统 Linux 发行版本(适用于 CentOS、Fedora 和 Red Hat): + +``` +alias os="cat /etc/redhat-release" +``` + +![system_details alias.png][6] + + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/8/time-saving-command-line-aliases + +作者:[Aarchit Modi][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[MZqk](https://github.com/MZqk) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux 中国](https://linux.cn/) 荣誉推出 + +[a]:https://opensource.com/users/architmodi +[2]:https://opensource.com/sites/default/files/uploads/install.png (install alias.png) +[4]:https://opensource.com/sites/default/files/uploads/kill.png (kill process alias.png) +[6]:https://opensource.com/sites/default/files/uploads/system_details.png (system_details alias.png) diff --git a/published/20180828 A Cat Clone With Syntax Highlighting And Git Integration.md b/published/20180828 A Cat Clone With Syntax Highlighting And Git Integration.md new file mode 100644 index 0000000000..6d4f18f51c --- /dev/null +++ b/published/20180828 A Cat Clone With Syntax Highlighting And Git Integration.md @@ -0,0 +1,161 @@ +Bat:一种具有语法高亮和 Git 集成的 Cat 类命令 +====== + +![](https://www.ostechnix.com/wp-content/uploads/2018/08/Bat-command-720x340.png) + +在类 UNIX 系统中,我们使用 `cat` 命令去打印和连接文件。使用 `cat` 命令,我们能将文件目录打印到到标准输出,合成几个文件为一个目标文件,还有追加几个文件到目标文件中。今天,我偶然发现一个具有相似作用的命令叫做 “Bat” ,它是 `cat` 命令的一个克隆版,具有一些例如语法高亮、 Git 集成和自动分页等非常酷的特性。在这个简略指南中,我们将讲述如何在 Linux 中安装和使用 `bat` 命令。 + +### 安装 + +Bat 可以在 Arch Linux 的默认软件源中获取。 所以你可以使用 `pacman` 命令在任何基于 arch 的系统上来安装它。 + +``` +$ sudo pacman -S bat +``` + +在 Debian、Ubuntu、Linux Mint 等系统中,从其[发布页面][1]下载 **.deb** 文件,然后用下面的命令来安装。 + +``` +$ sudo apt install gdebi +$ sudo gdebi bat_0.5.0_amd64.deb +``` + +对于其他系统,你也许需要从软件源编译并安装。确保你已经安装了 Rust 1.26 或者更高版本。 + +然后运行以下命令来安装 Bat: + +``` +$ cargo install bat +``` + +或者,你可以从 [Linuxbrew][2] 软件包管理中来安装它。 + +``` +$ brew install bat +``` + +### bat 命令的使用 + +`bat` 命令的使用与 `cat` 命令的使用非常相似。 + +使用 `bat` 命令创建一个新的文件: + +``` +$ bat > file.txt +``` + +使用 `bat` 命令来查看文件内容,只需要: + +``` +$ bat file.txt +``` + +你能同时查看多个文件: + +``` +$ bat file1.txt file2.txt +``` + +将多个文件的内容合并至一个单独文件中: + +``` +$ bat file1.txt file2.txt file3.txt > document.txt +``` + +就像我之前提到的那样,除了浏览和编辑文件以外,`bat` 命令有一些非常酷的特性。 + +`bat` 命令支持大多数编程和标记语言的语法高亮syntax highlighting。比如,下面这个例子。我将使用 `cat` 和 `bat` 命令来展示 `reverse.py` 的内容。 + +![](https://www.ostechnix.com/wp-content/uploads/2018/08/bat-and-cat-command-output-comparison.png) + +你注意到区别了吗? `cat` 命令以纯文本格式显示文件的内容,而 `bat` 命令显示了语法高亮和整齐的文本对齐格式。更好了不是吗? + +如果你只想显示行号(而没有表格)使用 `-n` 标记。 + +``` +$ bat -n reverse.py +``` + +![](https://www.ostechnix.com/wp-content/uploads/2018/08/bat-command-output-3.png) + +另一个 `bat` 命令中值得注意的特性是它支持自动分页automatic paging。 它的意思是当文件的输出对于屏幕来说太大的时候,`bat` 命令自动将自己的输出内容传输到 `less` 命令中,所以你可以一页一页的查看输出内容。 + +让我给你看一个例子,使用 `cat` 命令查看跨多个页面的文件的内容时,提示符会快速跳至文件的最后一页,你看不到内容的开头和中间部分。 + +看一下下面的输出: + +![](https://www.ostechnix.com/wp-content/uploads/2018/08/cat-command-output.png) + +正如你所看到的,`cat` 命令显示了文章的最后一页。 + +所以你也许需要去将使用 `cat` 命令的输出传输到 `less` 命令中去从开头一页一页的查看内容。 + +``` +$ cat reverse.py | less +``` + +现在你可以使用回车键去一页一页的查看输出。然而当你使用 `bat` 命令时这些都是不必要的。`bat` 命令将自动传输跨越多个页面的文件的输出。 + +``` +$ bat reverse.py +``` + +![](https://www.ostechnix.com/wp-content/uploads/2018/08/bat-command-output-1.png) + +现在按下回车键去往下一页。 + +`bat` 命令也支持 Git 集成**GIT integration**,这样您就可以轻松查看/编辑 Git 存储库中的文件。 它与 Git 连接可以显示关于索引的修改。(看左栏) + +![](https://www.ostechnix.com/wp-content/uploads/2018/08/bat-command-output-2.png) + +### 定制 Bat + +如果你不喜欢默认主题,你也可以修改它。Bat 同样有修改它的选项。 + +若要显示可用主题,只需运行: + +``` +$ bat --list-themes +1337 +DarkNeon +Default +GitHub +Monokai Extended +Monokai Extended Bright +Monokai Extended Light +Monokai Extended Origin +TwoDark +``` + + +要使用其他主题,例如 TwoDark,请运行: + +``` +$ bat --theme=TwoDark file.txt +``` + +如果你想永久改变主题,在你的 shells 启动文件中加入 `export BAT_THEME="TwoDark"`。 + +`bat` 还可以选择修改输出的外观。使用 `--style` 选项来修改输出外观。仅显示 Git 的更改和行号但不显示网格和文件头,请使用 `--style=numbers,changes`。 + +更多详细信息,请参阅 Bat 项目的 GitHub 库(链接在文末)。 + +最好,这就是目前的全部内容了。希望这篇文章会帮到你。更多精彩文章即将到来,敬请关注! + +干杯! + + +-------------------------------------------------------------------------------- + +via: https://www.ostechnix.com/bat-a-cat-clone-with-syntax-highlighting-and-git-integration/ + +作者:[SK][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[z52527](https://github.com/z52527) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.ostechnix.com/author/sk/ +[1]:https://github.com/sharkdp/bat/releases +[2]:https://www.ostechnix.com/linuxbrew-common-package-manager-linux-mac-os-x/ diff --git a/published/20180828 How to Play Windows-only Games on Linux with Steam Play.md b/published/20180828 How to Play Windows-only Games on Linux with Steam Play.md new file mode 100644 index 0000000000..3d5d3a20bc --- /dev/null +++ b/published/20180828 How to Play Windows-only Games on Linux with Steam Play.md @@ -0,0 +1,89 @@ +如何使用 Steam Play 在 Linux 上玩仅限 Windows 的游戏 +====== + +> Steam 的新实验功能允许你在 Linux 上玩仅限 Windows 的游戏。以下是如何在 Steam 中使用此功能。 + +你已经听说过这个消息。游戏发行平台 [Steam 正在复刻一个 WINE 分支来允许你玩仅限于 Windows 上的游戏][1]。对于 Linux 用户来说,这绝对是一个好消息,因为我们总抱怨 Linux 的游戏数量不足。 + +这个新功能仍处于测试阶段,但你现在可以在 Linux 上试用它并在 Linux 上玩仅限 Windows 的游戏。让我们看看如何做到这一点。 + +### 使用 Steam Play 在 Linux 中玩仅限 Windows 的游戏 + +![Play Windows-only games on Linux][2] + +你需要先安装 Steam。Steam 适用于所有主要 Linux 发行版。我已经详细介绍了[在 Ubuntu 上安装 Steam][3],如果你还没有安装 Steam,你可以参考那篇文章。 + +安装了 Steam 并且你已登录到 Steam 帐户,就可以了解如何在 Steam Linux 客户端中启用 Windows 游戏。 + +#### 步骤 1:进入帐户设置 + +运行 Steam 客户端。在左上角,单击 “Steam”,然后单击 “Settings”。 + +![Enable steam play beta on Linux][4] + +#### 步骤 2:选择加入测试计划 + +在“Settings”中,从左侧窗口中选择“Account”,然后单击 “Beta participation” 下的 “CHANGE” 按钮。 + +![Enable beta feature in Steam Linux][5] + +你应该在此处选择 “Steam Beta Update”。 + +![Enable beta feature in Steam Linux][6] + +在此处保存设置后,Steam 将重新启动并下载新的测试版更新。 + +#### 步骤 3:启用 Steam Play 测试版 + +下载好 Steam 新的测试版更新后,它将重新启动。到这里就差不多了。 + +再次进入“Settings”。你现在可以在左侧窗口看到新的 “Steam Play” 选项。单击它并选中复选框: + + * Enable Steam Play for supported titles (你可以玩列入白名单的 Windows 游戏) + * Enable Steam Play for all titles (你可以尝试玩所有仅限 Windows 的游戏) + +![Play Windows games on Linux using Steam Play][7] + +我不记得 Steam 是否会再次重启,但我想这无所谓。你现在应该可以在 Linux 上看到安装仅限 Windows 的游戏的选项了。 + +比如,我的 Steam 库中有《Age of Empires》,正常情况下这个在 Linux 中没有。但我在 Steam Play 测试版启用所有 Windows 游戏后,现在我可以选择在 Linux 上安装《Age of Empires》了。 + +![Install Windows-only games on Linux using Steam][8] + +*现在可以在 Linux 上安装仅限 Windows 的游戏* + +### 有关 Steam Play 测试版功能的信息 + +在 Linux 上使用 Steam Play 测试版玩仅限 Windows 的游戏有一些事情你需要知道并且牢记。 + + * 目前,[只有 27 个 Steam Play 中的 Windows 游戏被列入白名单][9]。这些白名单游戏可以在 Linux 上无缝运行。 + * 你可以使用 Steam Play 测试版尝试任何 Windows 游戏,但它可能不是总能运行。有些游戏有时会崩溃,而某些游戏可能根本无法运行。 + * 在测试版中,你无法 Steam 商店中看到适用于 Linux 的 Windows 限定游戏。你必须自己尝试游戏或参考[这个社区维护的列表][10]以查看该 Windows 游戏的兼容性状态。你也可以通过填写[此表][11]来为列表做出贡献。 + * 如果你在 Windows 中通过 Steam 下载了游戏,你可以[在 Linux 和 Windows 之间共享 Steam 游戏文件][12]来节省下载的数据。 + +我希望本教程能帮助你在 Linux 上运行仅限 Windows 的游戏。你期待在 Linux 上玩哪些游戏? + +-------------------------------------------------------------------------------- + +via: https://itsfoss.com/steam-play/ + +作者:[Abhishek Prakash][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[geekpi](https://github.com/geekpi) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://itsfoss.com/author/abhishek/ +[1]:https://linux.cn/article-10054-1.html +[2]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/08/play-windows-games-on-linux-featured.jpeg +[3]:https://itsfoss.com/install-steam-ubuntu-linux/ +[4]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/08/enable-steam-play-beta.jpeg +[5]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/08/enable-steam-play-beta-2.jpeg +[6]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/08/enable-steam-play-beta-3.jpeg +[7]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/08/enable-steam-play-beta-4.jpeg +[8]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/08/install-windows-games-linux.jpeg +[9]:https://steamcommunity.com/games/221410 +[10]:https://docs.google.com/spreadsheets/d/1DcZZQ4HL_Ol969UbXJmFG8TzOHNnHoj8Q1f8DIFe8-8/htmlview?sle=true# +[11]:https://docs.google.com/forms/d/e/1FAIpQLSeefaYQduMST_lg0IsYxZko8tHLKe2vtVZLFaPNycyhY4bidQ/viewform +[12]:https://linux.cn/article-8027-1.html diff --git a/published/20180829 Add GUIs to your programs and scripts easily with PySimpleGUI.md b/published/20180829 Add GUIs to your programs and scripts easily with PySimpleGUI.md new file mode 100644 index 0000000000..9eff0b65d3 --- /dev/null +++ b/published/20180829 Add GUIs to your programs and scripts easily with PySimpleGUI.md @@ -0,0 +1,348 @@ +使用 PySimpleGUI 轻松为程序和脚本增加 GUI +====== + +> 五分钟创建定制 GUI。 + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/web_browser_desktop_devlopment_design_system_computer.jpg?itok=pfqRrJgh) + +对于 `.exe` 类型的程序文件,我们可以通过双击鼠标左键打开;但对于 `.py` 类型的 Python 程序,几乎不会有人尝试同样的操作。对于一个(非程序员类型的)典型用户,他们双击打开 `.exe` 文件时预期弹出一个可以交互的窗体。基于 Tkinter,可以通过标准 Python 安装standard Python installations的方式提供 GUI,但很多程序都不太可能这样做。 + +如果打开 Python 程序并进入 GUI 界面变得如此容易,以至于真正的初学者也可以掌握,会怎样呢?会有人感兴趣并使用吗?这个问题不好回答,因为直到今天创建自定义 GUI 布局仍不是件容易的事情。 + +在为程序或脚本增加 GUI 这件事上,似乎存在能力的“错配”。(缺乏这方面能力的)真正的初学者被迫只能使用命令行方式,而很多(具备这方面能力的)高级程序员却不愿意花时间创建一个 Tkinter GUI。 + +### GUI 框架 + +Python 的 GUI 框架并不少,其中 Tkinter,wxPython,Qt 和 Kivy 是几种比较主流的框架。此外,还有不少在上述框架基础上封装的简化框架,例如 EasyGUI,PyGUI 和 Pyforms 等。 + +但问题在于,对于初学者(这里是指编程经验不超过 6 个月的用户)而言,即使是最简单的主流框架,他们也无从下手;他们也可以选择封装过的(简化)框架,但仍难以甚至无法创建自定义 GUI 布局layout。即便学会了某种(简化)框架,也需要编写连篇累牍的代码。 + +[PySimpleGUI][1] 尝试解决上述 GUI 难题,它提供了一种简单明了、易于理解、方便自定义的 GUI 接口。如果使用 PySimpleGUI,很多复杂的 GUI 也仅需不到 20 行代码。 + +### 秘诀 + +PySimpleGUI 极为适合初学者的秘诀在于,它已经包含了绝大多数原本需要用户编写的代码。PySimpleGUI 会处理按钮回调callback,无需用户编写代码。对于初学者,在几周内掌握函数的概念已经不容易了,要求其理解回调函数似乎有些强人所难。 + +在大部分 GUI 框架中,布局 GUI 小部件widgets通常需要写一些代码,每个小部件至少 1-2 行。PySimpleGUI 使用了 “auto-packer” 技术,可以自动创建布局。因而,布局 GUI 窗口不再需要 pack 或 grid 系统。 + +(LCTT 译注:这里提到的 pack 和 grid 都是 Tkinter 的布局管理器,另外一种叫做 place 。) + +最后,PySimpleGUI 框架编写中有效地利用了 Python 语言特性,降低用户代码量并简化 GUI 数据返回的方式。在窗体form布局中创建小部件时,小部件会被部署到对应的布局中,无需额外的代码。 + +### GUI 是什么? + +绝大多数 GUI 只完成一件事情:收集用户数据并返回。在程序员看来,可以归纳为如下的函数调用: + +``` +button, values = GUI_Display(gui_layout) +``` + +绝大多数 GUI 支持的用户行为包括鼠标点击(例如,“确认”,“取消”,“保存”,“是”和“否”等)和内容输入。GUI 本质上可以归结为一行代码。 + +这也正是 PySimpleGUI (的简单 GUI 模式)的工作原理。当执行命令显示 GUI 后,除非点击鼠标关闭窗体,否则不会执行任何代码。 + +当然还有更复杂的 GUI,其中鼠标点击后窗口并不关闭;例如,机器人的远程控制界面,聊天窗口等。这类复杂的窗体也可以用 PySimpleGUI 创建。 + +### 快速创建 GUI + +PySimpleGUI 什么时候有用呢?显然,是你需要 GUI 的时候。仅需不超过 5 分钟,就可以让你创建并尝试 GUI。最便捷的 GUI 创建方式就是从 [PySimpleGUI 经典实例][2]中拷贝一份代码。具体操作流程如下: + +* 找到一个与你需求最接近的 GUI +* 从经典实例中拷贝代码 +* 粘贴到 IDE 中并运行 + +下面我们看一下书中的第一个经典实例recipe: + +``` +import PySimpleGUI as sg + +# Very basic form.  Return values as a list +form = sg.FlexForm('Simple data entry form')  # begin with a blank form + +layout = [ +          [sg.Text('Please enter your Name, Address, Phone')], +          [sg.Text('Name', size=(15, 1)), sg.InputText('name')], +          [sg.Text('Address', size=(15, 1)), sg.InputText('address')], +          [sg.Text('Phone', size=(15, 1)), sg.InputText('phone')], +          [sg.Submit(), sg.Cancel()] +         ] + +button, values = form.LayoutAndRead(layout) + +print(button, values[0], values[1], values[2]) +``` + +运行后会打开一个大小适中的窗体。 + +![](https://opensource.com/sites/default/files/uploads/pysimplegui_cookbook-form.jpg) + +如果你只是想收集一些字符串类型的值,拷贝上述经典实例中的代码,稍作修改即可满足你的需求。 + +你甚至可以只用 5 行代码创建一个自定义 GUI 布局。 + +``` +import PySimpleGUI as sg + +form = sg.FlexForm('My first GUI') + +layout = [ [sg.Text('Enter your name'), sg.InputText()], +           [sg.OK()] ] + +button, (name,) = form.LayoutAndRead(layout) +``` + +![](https://opensource.com/sites/default/files/uploads/pysimplegui-5-line-form.jpg) + +### 5 分钟内创建一个自定义 GUI + +在简单布局的基础上,通过修改经典实例中的代码,5 分钟内即可使用 PySimpleGUI 创建自定义布局。 + +在 PySimpleGUI 中,小部件widgets被称为元素elements。元素的名称与编码中使用的名称保持一致。 + +(LCTT 译注:Tkinter 中使用小部件这个词) + +#### 核心元素 + +``` +Text +InputText +Multiline +InputCombo +Listbox +Radio +Checkbox +Spin +Output +SimpleButton +RealtimeButton +ReadFormButton +ProgressBar +Image +Slider +Column +``` + +#### 元素简写 + +PySimpleGUI 还包含两种元素简写方式。一种是元素类型名称简写,例如 `T` 用作 `Text` 的简写;另一种是元素参数被配置了默认值,你可以无需指定所有参数,例如 `Submit` 按钮默认的文本就是 “Submit”。 + +``` +T = Text +Txt = Text +In = InputText +Input = IntputText +Combo = InputCombo +DropDown = InputCombo +Drop = InputCombo +``` + +(LCTT 译注:第一种简写就是 Python 类的别名,第二种简写是在返回元素对象的 Python 函数定义时指定了参数的默认值) + +#### 按钮简写 + +一些通用按钮具有简写实现,包括: + +``` +FolderBrowse +FileBrowse +FileSaveAs +Save +Submit +OK +Ok (LCTT 译注:这里 `k` 是小写) +Cancel +Quit +Exit +Yes +No +``` + +此外,还有通用按钮功能对应的简写: + +``` +SimpleButton +ReadFormButton +RealtimeButton +``` + +(LCTT 译注:其实就是返回 `Button` 类实例的函数) + +上面就是 PySimpleGUI 支持的全部元素。如果不在上述列表之中,就不会在你的窗口布局中生效。 + +(LCTT 译注:上述都是 PySimpleGUI 的类名、类别名或返回实例的函数,自然只能使用列表内的。) + +#### GUI 设计模式 + +对于 GUI 程序,创建并展示窗口的调用大同小异,差异在于元素的布局。 + +设计模式代码与上面的例子基本一致,只是移除了布局: + +``` +import PySimpleGUI as sg + +form = sg.FlexForm('Simple data entry form') +# Define your form here (it's a list of lists) +button, values = form.LayoutAndRead(layout) +``` + +(LCTT 译注:这段代码无法运行,只是为了说明每个程序都会用到的设计模式。) + +对于绝大多数 GUI,编码流程如下: + +* 创建窗体对象 +* 以“列表的列表”的形式定义 GUI +* 展示 GUI 并获取元素的值 + +上述流程与 PySimpleGUI 设计模式部分的代码一一对应。 + +#### GUI 布局 + +要创建自定义 GUI,首先要将窗体分割成多个行,因为窗体是一行一行定义的。然后,在每一行中从左到右依次放置元素。 + +我们得到的就是一个“列表的列表”,类似如下: + +``` +layout = [  [Text('Row 1')], +            [Text('Row 2'), Checkbox('Checkbox 1', OK()), Checkbox('Checkbox 2'), OK()] ] +``` + +上述布局对应的效果如下: + +![](https://opensource.com/sites/default/files/uploads/pysimplegui-custom-form.jpg) + +### 展示 GUI + +当你完成布局、拷贝完用于创建和展示窗体的代码后,下一步就是展示窗体并收集用户数据。 + +下面这行代码用于展示窗体并返回收集的数据: + +``` +button, values = form.LayoutAndRead(layout) +``` + +窗体返回的结果由两部分组成:一部分是被点击按钮的名称,另一部分是一个列表,包含所有用户输入窗体的值。 + +在这个例子中,窗体显示后用户直接点击 “OK” 按钮,返回的结果如下: + +``` +button == 'OK' +values == [False, False] +``` + +Checkbox 类型元素返回 `True` 或 `False` 类型的值。由于默认处于未选中状态,两个元素的值都是 `False`。 + +### 显示元素的值 + +一旦从 GUI 获取返回值,检查返回变量中的值是个不错的想法。与其使用 `print` 语句进行打印,我们不妨坚持使用 GUI 并在一个窗口中输出这些值。 + +(LCTT 译注:考虑使用的是 Python 3 版本,`print` 应该是函数而不是语句。) + +在 PySimpleGUI 中,有多种消息框可供选取。传递给消息框(函数)的数据会被显示在消息框中;函数可以接受任意数目的参数,你可以轻松的将所有要查看的变量展示出来。 + +在 PySimpleGUI 中,最常用的消息框是 `MsgBox`。要展示上面例子中的数据,只需编写一行代码: + +``` +MsgBox('The GUI returned:', button, values) +``` + +### 整合 + +好了,你已经了解了基础知识,让我们创建一个包含尽可能多 PySimpleGUI 元素的窗体吧!此外,为了更好的感观效果,我们将采用绿色/棕褐色的配色方案。 + +``` +import PySimpleGUI as sg + +sg.ChangeLookAndFeel('GreenTan') + +form = sg.FlexForm('Everything bagel', default_element_size=(40, 1)) + +column1 = [[sg.Text('Column 1', background_color='#d3dfda', justification='center', size=(10,1))], +           [sg.Spin(values=('Spin Box 1', '2', '3'), initial_value='Spin Box 1')], +           [sg.Spin(values=('Spin Box 1', '2', '3'), initial_value='Spin Box 2')], +           [sg.Spin(values=('Spin Box 1', '2', '3'), initial_value='Spin Box 3')]] +layout = [ +    [sg.Text('All graphic widgets in one form!', size=(30, 1), font=("Helvetica", 25))], +    [sg.Text('Here is some text.... and a place to enter text')], +    [sg.InputText('This is my text')], +    [sg.Checkbox('My first checkbox!'), sg.Checkbox('My second checkbox!', default=True)], +    [sg.Radio('My first Radio!     ', "RADIO1", default=True), sg.Radio('My second Radio!', "RADIO1")], +    [sg.Multiline(default_text='This is the default Text should you decide not to type anything', size=(35, 3)), +     sg.Multiline(default_text='A second multi-line', size=(35, 3))], +    [sg.InputCombo(('Combobox 1', 'Combobox 2'), size=(20, 3)), +     sg.Slider(range=(1, 100), orientation='h', size=(34, 20), default_value=85)], +    [sg.Listbox(values=('Listbox 1', 'Listbox 2', 'Listbox 3'), size=(30, 3)), +     sg.Slider(range=(1, 100), orientation='v', size=(5, 20), default_value=25), +     sg.Slider(range=(1, 100), orientation='v', size=(5, 20), default_value=75), +     sg.Slider(range=(1, 100), orientation='v', size=(5, 20), default_value=10), +     sg.Column(column1, background_color='#d3dfda')], +    [sg.Text('_'  * 80)], +    [sg.Text('Choose A Folder', size=(35, 1))], +    [sg.Text('Your Folder', size=(15, 1), auto_size_text=False, justification='right'), +     sg.InputText('Default Folder'), sg.FolderBrowse()], +    [sg.Submit(), sg.Cancel()] +     ] + +button, values = form.LayoutAndRead(layout) +sg.MsgBox(button, values) +``` + +看上面要写不少代码,但如果你试着直接使用 Tkinter 框架实现同样的 GUI,你很快就会发现 PySimpleGUI 版本的代码是多么的简洁。 + +![](https://opensource.com/sites/default/files/uploads/pysimplegui-everything.jpg) + +代码的最后一行打开了一个消息框,效果如下: + +![](https://opensource.com/sites/default/files/uploads/pysimplegui-message-box.jpg) + +消息框函数中的每一个参数的内容都会被打印到单独的行中。本例的消息框中包含两行,其中第二行非常长而且包含列表嵌套。 + +建议花一点时间将上述结果与 GUI 中的元素一一比对,这样可以更好的理解这些结果是如何产生的。 + +### 为你的程序或脚本添加 GUI + +如果你有一个命令行方式使用的脚本,添加 GUI 不一定意味着完全放弃该脚本。一种简单的方案如下:如果脚本不需要命令行参数,那么可以直接使用 GUI 调用该脚本;反之,就按原来的方式运行脚本。 + +仅需类似如下的逻辑: + +``` +if len(sys.argv) == 1: +        # collect arguments from GUI +else: +    # collect arguements from sys.argv +``` + +创建并运行 GUI 最便捷的方式就是从 [PySimpleGUI 经典实例][2]中拷贝一份代码并修改。 + +快来试试吧!给你一直疲于手动执行的脚本增加一些趣味。只需 5-10 分钟即可玩转示例脚本。你可能发现一个几乎满足你需求的经典实例;如果找不到,也很容易自己编写一个。即使你真的玩不转,也只是浪费了 5-10 分钟而已。 + +### 资源 + +#### 安装方式 + +支持 Tkinter 的系统就支持 PySimpleGUI,甚至包括树莓派Raspberry Pi,但你需要使用 Python 3。 + +``` +pip install PySimpleGUI +``` + +#### 文档 + +* [手册][3] +* [经典实例][2] +* [GitHub repository][1] + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/8/pysimplegui + +作者:[Mike Barnett][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[pinewall](https://github.com/pinewall) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://opensource.com/users/pysimplegui +[1]: https://github.com/MikeTheWatchGuy/PySimpleGUI +[2]: https://pysimplegui.readthedocs.io/en/latest/cookbook/ +[3]: https://pysimplegui.readthedocs.io/en/latest/ diff --git a/published/20180830 How To Reset MySQL Or MariaDB Root Password.md b/published/20180830 How To Reset MySQL Or MariaDB Root Password.md new file mode 100644 index 0000000000..42aa6e912b --- /dev/null +++ b/published/20180830 How To Reset MySQL Or MariaDB Root Password.md @@ -0,0 +1,95 @@ +如何重置 MySQL 或 MariaDB 的 Root 密码 +====== + +![](https://www.ostechnix.com/wp-content/uploads/2018/08/Reset-MySQL-Or-MariaDB-Root-Password-720x340.png) + +几个月前,我在[Ubuntu 18.04 上安装了 LAMP][1]。今天,我尝试以 root 用户身份登录数据库,但我完全忘记了密码。经过一阵 Google 搜索并浏览一些文章后,我成功重置了密码。对于那些想知道如何做到这一点的人,这个简短的教程解释了如何在类 Unix 操作系统中重置 MySQL 或 MariaDB Root 密码。 + +### 重置 MySQL 或 MariaDB Root 密码 + +首先,停止数据库。 + +如果你使用 MySQL,请输入以下命令并下按回车键。 + +``` +$ sudo systemctl stop mysql +``` + +对于 MariaDB: + +``` +$ sudo systemctl stop mariadb +``` + +接下来,使用以下命令在没有权限检查的情况下重新启动数据库: + +``` +$ sudo mysqld_safe --skip-grant-tables & +``` + +这里, `--skip-grant-tables` 选项让你在没有密码和所有权限的情况下进行连接。如果使用此选项启动服务器,它还会启用 `--skip-networking` 选项,这用于防止其他客户端连接到数据库服务器。并且,`&` 符号用于在后台运行命令,因此你可以在以下步骤中输入其他命令。请注意,上述命令很危险,并且你的数据库会变得不安全。你应该只在短时间内运行此命令以重置密码。 + +接下来,以 root 用户身份登录 MySQL/MariaDB 服务器: + +``` +$ mysql +``` + +在 **mysql >** 或 **MariaDB [(none)] >** 提示符下,运行以下命令重置 root 用户密码: + +``` +UPDATE mysql.user SET Password=PASSWORD('NEW-PASSWORD') WHERE User='root'; +``` + +使用你自己的密码替换上述命令中的 **NEW-PASSWORD**。 + +然后,输入以下命令退出 mysql 控制台。 + +``` +FLUSH PRIVILEGES; +exit +``` + +最后,关闭之前使用 `--skip-grant-tables` 选项运行的数据库。为此,运行: + +``` +$ sudo mysqladmin -u root -p shutdown +``` + +系统将要求你输入在上一步中设置的 MySQL/MariaDB 用户密码。 + +现在,使用以下命令正常启动 MySQL/MariaDB 服务: + +``` +$ sudo systemctl start mysql +``` + +对于 MariaDB: + +``` +$ sudo systemctl start mariadb +``` + +使用以下命令验证密码是否确实已更改: + +``` +$ mysql -u root -p +``` + +今天就是这些了。还有更多好东西。敬请期待! + +干杯! + +-------------------------------------------------------------------------------- + +via: https://www.ostechnix.com/how-to-reset-mysql-or-mariadb-root-password/ + +作者:[SK][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[geekpi](https://github.com/geekpi) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://www.ostechnix.com/author/sk/ +[1]: https://www.ostechnix.com/install-apache-mariadb-php-lamp-stack-ubuntu-16-04/ diff --git a/published/20180830 How to Update Firmware on Ubuntu 18.04.md b/published/20180830 How to Update Firmware on Ubuntu 18.04.md new file mode 100644 index 0000000000..fc8922b48c --- /dev/null +++ b/published/20180830 How to Update Firmware on Ubuntu 18.04.md @@ -0,0 +1,100 @@ +如何在 Ubuntu 18.04 上更新固件 +====== + +通常,Ubuntu 和其他 Linux 中的默认软件中心会处理系统固件的更新。但是如果你遇到了错误,你可以使用 `fwupd` 命令行工具更新系统的固件。 + +我使用 [Dell XPS 13 Ubuntu 版本][1]作为我的主要操作系统。我全新[安装了 Ubuntu 18.04][2],我对硬件兼容性感到满意。蓝牙、外置 USB 耳机和扬声器、多显示器,一切都开箱即用。 + +困扰我的一件事是软件中心出现的一个[固件][3]更新。 + +![Updating firmware in Ubuntu][4] + +单击“更新”按钮会在几秒钟后出现错误。 + +![Updating firmware in Ubuntu][5] + +错误消息是: + +> Unable to update “Thunderbolt NVM for Xps Notebook 9360”: could not detect device after update: timed out while waiting for device + +在这篇文章中,我将向你展示如何在 [Ubuntu][6] 中更新系统固件。 + +### 在 Ubuntu 18.04 中更新固件 + +![How to update firmware in Ubuntu][7] + +有一件事你应该知道 GNOME Software(即 Ubuntu 18.04 中的软件中心)也能够更新固件。但是在由于某种原因失败的情况下,你可以使用命令行工具 `fwupd`。 + +[fwupd][8] 是一个开源守护进程,可以处理基于 Linux 的系统中的固件升级。它由 GNOME 开发人员 [Richard Hughes][9] 创建。戴尔的开发人员也为这一开源工具的开发做出了贡献。 + +基本上,它使用 LVFS —— Linux 供应商固件服务Linux Vendor Firmware Service。硬件供应商将可再发行固件上传到 LVFS 站点,并且多亏 `fwupd`,你可以从操作系统内部升级这些固件。`fwupd` 得到了 Ubuntu 和 Fedora 等主要 Linux 发行版的支持。 + +首先打开终端并更新系统: + +``` +sudo apt update && sudo apt upgrade -y +``` + +之后,你可以逐个使用以下命令来启动守护程序,刷新可用固件更新列表并安装固件更新。 + +``` +sudo service fwupd start +``` + +守护进程运行后,检查是否有可用的固件更新。 + +``` +sudo fwupdmgr refresh +``` + +输出应如下所示: + +``` +Fetching metadata https://cdn.fwupd.org/downloads/firmware.xml.gz +Downloading… [****************************] +Fetching signature https://cdn.fwupd.org/downloads/firmware.xml.gz.asc +``` + +在此之后,运行固件更新: + +``` +sudo fwupdmgr update +``` + +固件更新的输出可能与此类似: + +``` +No upgrades for XPS 13 9360 TPM 2.0, current is 1.3.1.0: 1.3.1.0=same +No upgrades for XPS 13 9360 System Firmware, current is 0.2.8.1: 0.2.8.1=same, 0.2.7.1=older, 0.2.6.2=older, 0.2.5.1=older, 0.2.4.2=older, 0.2.3.1=older, 0.2.2.1=older, 0.2.1.0=older, 0.1.3.7=older, 0.1.3.5=older, 0.1.3.2=older, 0.1.2.3=older +Downloading 21.00 for XPS13 9360 Thunderbolt Controller… +Updating 21.00 on XPS13 9360 Thunderbolt Controller… +Decompressing… [***********] +Authenticating… [***********] +Restarting device… [***********] +``` + +这应该处理了在 Ubuntu 18.04 中的固件更新。我希望这篇文章可以帮助你在 Linux 中进行固件更新。 + +如果你有任何问题或建议,请在下面的评论栏留言。 + +-------------------------------------------------------------------------------- + +via: https://itsfoss.com/update-firmware-ubuntu/ + +作者:[Abhishek Prakash][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[geekpi](https://github.com/geekpi) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://itsfoss.com/author/abhishek/ +[1]: https://itsfoss.com/dell-xps-13-ubuntu-review/ +[2]: https://itsfoss.com/install-ubuntu-dual-boot-mode-windows/ +[3]: https://en.wikipedia.org/wiki/Firmware +[4]: https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/08/ubuntu-firmware-update-error-1.png +[5]: https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/08/ubuntu-firmware-update-error-2.jpg +[6]: https://www.ubuntu.com/ +[7]: https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/08/update-firmware-ubuntu.png +[8]: https://fwupd.org/ +[9]: https://github.com/hughsie/fwupd diff --git a/published/20180831 6 open source tools for making your own VPN.md b/published/20180831 6 open source tools for making your own VPN.md new file mode 100644 index 0000000000..19e668c20c --- /dev/null +++ b/published/20180831 6 open source tools for making your own VPN.md @@ -0,0 +1,109 @@ +6 个打造你自己的 VPN 的开源工具 +====== + +> 想尝试建立您自己的 VPN,但是不确定从哪里开始吗? + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/vpn_scrabble_networking.jpg?itok=pdsUHw5N) + +如果您想尝试建立您自己的 VPN,但是不确定从哪里开始,那么您来对地方了。我将比较 6 个在您自己的服务器上搭建和使用 VPN 的最好的自由和开源工具。不管您是想为您的企业建立站点到站点的 VPN,还是只是想创建一个远程代理访问以解除访问限制并对 ISP 隐藏你的互联网流量,都可以通过 VPN 来达成。 + +根据您的需求和条件,并参考您自己的技术特长、环境以及您想要通过 VPN 实现的目标。需要考虑以下因素: + + * VPN 协议 + * 客户端的数量和设备类型 + * 服务端的兼容性 + * 需要的技术专业能力 + +### Algo + +[Algo][1] 是从下往上设计的,可以为需要互联网安全代理的商务旅客创建 VPN 专用网。它“只包括您所需要的最小化的软件”,这意味着为了简单而牺牲了可扩展性。Algo 是基于 StrongSwan 的,但是删除了所有您不需要的东西,这有另外一个好处,那就是去除了新手可能不会注意到的安全漏洞。 + +作为额外的奖励,它甚至可以屏蔽广告! + +Algo 只支持 IKEv2 协议和 Wireguard。因为对 IKEv2 的支持现在已经内置在大多数设备中,所以它不需要像 OpenVPN 这样的客户端应用程序。Algo 可以使用 Ansible 在 Ubuntu (首选选项)、Windows、RedHat、CentOS 和 FreeBSD 上部署。 使用 Ansible 可以自动化安装,它会根据您对一组简短的问题的回答来配置服务。卸载和重新部署也非常容易。 + +Algo 可能是在本文中安装和部署最简单和最快的 VPN。它非常简洁,考虑周全。如果您不需要其他工具提供的高级功能,只需要一个安全代理,这是一个很好的选择。请注意,Algo 明确表示,它不是为了解除地理封锁或逃避审查,主要是为了加密。 + +### Streisand + +[Streisand][2] 可以使用一个命令安装在任何 Ubuntu 16.04 服务器上;这个过程大约需要 10 分钟。它支持 L2TP、OpenConnect、OpenSSH、OpenVPN、Shadowsocks、Stunnel、Tor bridge 和 WireGuard。根据您选择的协议,您可能需要安装客户端应用程序。 + +在很多方面,Streisand 与 Algo 相似,但是它提供了更多的协议和定制。这需要更多的工作来管理和维护,但也更加灵活。注意 Streisand 不支持 IKEv2。因为它的多功能性,我认为 Streisand 在某国和土耳其这样的地方绕过审查制度更有效,但是 Algo 的安装更容易和更快。 + +使用 Ansible 可以自动化安装,所以不需要太多的专业技术知识。通过向用户发送自定义生成的连接指令,包括服务器 SSL 证书的嵌入副本,可以轻松添加更多用户。 + +卸载 Streisand 是一个快速无痛的过程,您也可以随时重新部署。 + +### OpenVPN + +[OpenVPN][3] 要求客户端和服务器应用程序使用其同名的协议建立 VPN 连接。OpenVPN 可以根据您的需求进行调整和定制,但它也需要更多专业技术知识。它支持远程访问和站点到站点配置;如果您计划使用 VPN 作为互联网代理,前者是您所需要的。因为在大多数设备上使用 OpenVPN 需要客户端应用程序,所以最终用户必须保持更新。 + +服务器端您可以选择部署在云端或你自己的 Linux 服务器上。兼容的发行版包括 CentOS 、Ubuntu 、Debian 和 openSUSE。Windows 、MacOS 、iOS 和 Android 都有客户端应用程序,其他设备也有非官方应用程序。企业可以选择设置一个 OpenVPN 接入服务器,但是对于想要使用社区版的个人来说,这可能有点过分。 + +OpenVPN 使用静态密钥加密来配置相对容易,但并不十分安全。相反,我建议使用 [easy-rsa][4] 来设置它,这是一个密钥管理包,可以用来设置公钥基础设施(PKI)。这允许您一次连接多个设备,并因此得到完美前向保密perfect forward secrecy和其他好处的保护。OpenVPN 使用 SSL/TLS 进行加密,而且您可以在配置中指定 DNS 服务器。 + +OpenVPN 可以穿透防火墙和 NAT 防火墙,这意味着您可以使用它绕过可能会阻止连接的网关和防火墙。它同时支持 TCP 和 UDP 传输。 + +### StrongSwan + +您可能会遇到一些名称中有 “Swan” 的各种 VPN 工具。FreeS/WAN 、OpenSwan、LibreSwan 和 [strongSwan][5] 都是同一个项目的分叉,后者是我个人最喜欢的。在服务器端,strongSwan 可以运行在 Linux 2.6、3.x 和 4x 内核、Android、FreeBSD、macOS、iOS 和 Windows 上。 + +StrongSwan 使用 IKEv2 协议和 IPSec 。与 OpenVPN 相比,IKEv2 连接速度更快,同时提供了很好的速度和安全性。如果您更喜欢不需要在客户端安装额外应用程序的协议,这将非常有用,因为现在生产的大多数新设备都支持 IKEv2,包括 Windows、MacOS、iOS 和 Android。 + +StrongSwan 并不特别容易使用,尽管文档不错,但它使用的词汇与大多数其他工具不同,这可能会让人比较困惑。它的模块化设计让它对企业来说很棒,但这也意味着它不是很精简。这当然不像 Algo 或 Streisand 那么简单。 + +访问控制可以基于使用 X.509 属性证书的组成员身份,这是 strongSwan 独有的功能。它支持用于集成到其他环境(如 Windows Active Directory)中的 EAP 身份验证方法。strongSwan 可以穿透NAT 网络防火墙。 + +### SoftEther + +[SoftEther][6] 是由日本筑波大学的一名研究生发起的一个项目。SoftEther VPN 服务器和 VPN 网桥可以运行在 Windows、Linux、OSX、FreeBSD 和 Solaris 上,而客户端应用程序可以运行在 Windows、Linux 和 MacOS 上。VPN 网桥主要用于需要设置站点到站点 VPN 的企业,因此单个用户只需要服务器和客户端程序来设置远程访问。 + +SoftEther 支持 OpenVPN、L2TP、SSTP 和 EtherIP 协议,由于采用“基于 HTTPS 的以太网”伪装,它自己的 SoftEther 协议声称能够免疫深度数据包检测。SoftEther 还做了一些调整,以减少延迟并增加吞吐量。此外,SoftEther 还包括一个克隆功能,允许您轻松地从 OpenVPN 过渡到 SoftEther。 + +SoftEther 可以穿透 NAT 防火墙并绕过防火墙。在只允许 ICMP 和 DNS 数据包的受限网络上,您可以利用 SoftEther 的基于 ICMP 或 DNS 的 VPN 方式来穿透防火墙。SoftEther 可与 IPv4 和 IPv6 一起工作。 + +SoftEther 比 OpenVPN 和 strongSwan 更容易设置,但比 Streisand 和 Algo 要复杂。 + +### WireGuard + +[WireGuard][7] 是这个名单上最新的工具;它太新了,甚至还没有完成。也就是说,它为部署 VPN 提供了一种快速简便的方法。它旨在通过使 IPSec 更简单、更精简来改进它,就像 SSH 一样。 + +与 OpenVPN 一样,WireGuard 既是一种协议,也是一种用于部署使用所述协议的 VPN 的软件工具。一个关键特性是“加密密钥路由”,它将公钥与隧道内允许的 IP 地址列表相关联。 + +WireGuard 可用于 Ubuntu、Debian、Fedora、CentOS、MacOS、Windows 和安卓系统。WireGuard 可在 IPv4 和 IPv6 上工作。 + +WireGuard 比大多数其他 VPN 协议轻得多,它只在需要发送数据时才发送数据包。 + +开发人员说,WireGuard 还不应该被信任,因为它还没有被完全审计过,但是欢迎你给它一个机会。这可能是下一个热门! + +### 自制 VPN vs. 商业 VPN + +制作您自己的 VPN 为您的互联网连接增加了一层隐私和安全,但是如果您是唯一一个使用它的人,那么装备精良的第三方,比如政府机构,将很容易追踪到你的活动。 + +此外,如果您计划使用您的 VPN 来解锁地理锁定的内容,自制的 VPN 可能不是最好的选择。因为您只能从一个 IP 地址连接,所以你的 VPN 服务器很容易被阻止。 + +好的商业 VPN 不存在这些问题。有了像 [ExpressVPN][8] 这样的提供商,您可以与数十甚至数百个其他用户共享服务器的 IP 地址,这使得跟踪一个用户的活动几乎变得不可能。您也可以从成百上千的服务器中选择,所以如果其中一台被列入黑名单,你可以切换到另一台。 + +然而,商业 VPN 的权衡是,您必须相信提供商不会窥探您的互联网流量。一定要选择一个有明确的无日志政策的信誉良好的供应商。 + + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/8/open-source-tools-vpn + +作者:[Paul Bischoff][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[heguangzhi](https://github.com/heguangzhi) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://opensource.com/users/paulbischoff +[1]: https://blog.trailofbits.com/2016/12/12/meet-algo-the-vpn-that-works/ +[2]: https://github.com/StreisandEffect/streisand +[3]: https://openvpn.net/ +[4]: https://github.com/OpenVPN/easy-rsa +[5]: https://www.strongswan.org/ +[6]: https://www.softether.org/ +[7]: https://www.wireguard.com/ +[8]: https://www.comparitech.com/vpn/reviews/expressvpn/ diff --git a/published/20180831 How to Create a Slideshow of Photos in Ubuntu 18.04 and other Linux Distributions.md b/published/20180831 How to Create a Slideshow of Photos in Ubuntu 18.04 and other Linux Distributions.md new file mode 100644 index 0000000000..6dc4f4dba6 --- /dev/null +++ b/published/20180831 How to Create a Slideshow of Photos in Ubuntu 18.04 and other Linux Distributions.md @@ -0,0 +1,69 @@ +如何在 Ubuntu 和其他 Linux 发行版中创建照片幻灯片 +====== + +创建照片幻灯片只需点击几下。以下是如何在 Ubuntu 18.04 和其他 Linux 发行版中制作照片幻灯片。 + +![How to create slideshow of photos in Ubuntu Linux][1] + +想象一下,你的朋友和亲戚正在拜访你,并请你展示最近的活动/旅行照片。 + +你将照片保存在计算机上,并整齐地放在单独的文件夹中。你邀请计算机附近的所有人。你进入该文件夹​​,单击其中一张图片,然后按箭头键逐个显示照片。 + +但那太累了!如果这些图片每隔几秒自动更改一次,那将会好很多。 + +这称之为幻灯片,我将向你展示如何在 Ubuntu 中创建照片幻灯片。这能让你在文件夹中循环播放图片并以全屏模式显示它们。 + +### 在 Ubuntu 18.04 和其他 Linux 发行版中创建照片幻灯片 + +虽然有几种图像浏览器可以做到,但我将向你展示大多数发行版中应该提供的两种最常用的工具。 + +#### 方法 1:使用 GNOME 默认图像浏览器浏览照片幻灯片 + +如果你在 Ubuntu 18.04 或任何其他发行版中使用 GNOME,那么你很幸运。Gnome 的默认图像浏览器,Eye of GNOME,能够在当前文件夹中显示图片的幻灯片。 + +只需单击其中一张图片,你将在程序的右上角菜单中看到设置选项。它看起来像堆叠在一起的三条横栏。 + +你会在这里看到几个选项。勾选幻灯片选项,它将全屏显示图像。 + +![How to create slideshow of photos in Ubuntu Linux][2] + +默认情况下,图像以 5 秒的间隔变化。你可以进入 “Preferences -> Slideshow” 来更改幻灯片放映间隔。 + +![change slideshow interval in Ubuntu][3] + +#### 方法 2:使用 Shotwell Photo Manager 进行照片幻灯片放映 + +[Shotwell][4] 是一款流行的 [Linux 照片管理程序][5]。适用于所有主要的 Linux 发行版。 + +如果尚未安装,请在你的发行版软件中心中搜索 Shotwell 并安装。 + +Shotwell 的运行略有不同。如果你在 Shotwell Viewer 中直接打开照片,则不会看到首选项或者幻灯片的选项。 + +对于幻灯片放映和其他选项,你必须打开 Shotwell 并导入包含这些图片的文件夹。导入文件夹后,从左侧窗格中选择该文件夹,然后单击菜单中的 “View”。你应该在此处看到幻灯片选项。只需单击它即可创建所选文件夹中所有图像的幻灯片。 + +![How to create slideshow of photos in Ubuntu Linux][6] + +你还可以更改幻灯片设置。当图像以全屏显示时,将显示此选项。只需将鼠标悬停在底部,你就会看到一个设置选项。 + +#### 创建照片幻灯片很容易 + +如你所见,在 Linux 中创建照片幻灯片非常简单。我希望你觉得这个简单的提示有用。如果你有任何问题或建议,请在下面的评论栏告诉我们。 + +-------------------------------------------------------------------------------- + +via: https://itsfoss.com/photo-slideshow-ubuntu/ + +作者:[Abhishek Prakash][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[geekpi](https://github.com/geekpi) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://itsfoss.com/author/abhishek/ +[1]: https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/08/Create-photos-Slideshow-Linux.png +[2]: https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/08/create-slideshow-photos-ubuntu-gnome.jpeg +[3]: https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/08/change-slideshow-interval-gnome-image.jpeg +[4]: https://wiki.gnome.org/Apps/Shotwell +[5]: https://itsfoss.com/linux-photo-management-software/ +[6]: https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/08/create-slideshow-photos-shotwell.jpeg diff --git a/published/20180903 Turn your vi editor into a productivity powerhouse.md b/published/20180903 Turn your vi editor into a productivity powerhouse.md new file mode 100644 index 0000000000..41fb8e50d7 --- /dev/null +++ b/published/20180903 Turn your vi editor into a productivity powerhouse.md @@ -0,0 +1,325 @@ +增强 Vim 编辑器,提高编辑效率 +====== +> 这 20 多个有用的命令可以增强你使用 Vi 的体验。 + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/checklist_hands_team_collaboration.png?itok=u82QepPk) + +*编者注:标题和文章最初称呼的 `vi` 编辑器,现已更新为编辑器的正确名称:`Vim`。* + +`Vim` 作为一款功能强大、选项丰富的编辑器,为许多用户所热爱。本文介绍了一些在 `Vim` 中默认未启用但实际非常有用的选项。虽然可以在每个 `Vim` 会话中单独启用,但为了创建一个开箱即用的高效编辑环境,还是建议在 `Vim` 的配置文件中配置这些命令。 + +### 开始前的准备 + +这里所说的选项或配置均位于用户主目录中的 `Vim` 启动配置文件 `.vimrc`。 按照下面的说明在 `.vimrc` 中设置选项: + +(注意:`vimrc` 文件也用于 `Linux` 中的全局配置,如 `/etc/vimrc` 或 `/etc/vim/vimrc`。本文所说的 `.vimrc` 均是指位于用户主目录中的 `.vimrc` 文件。) + +Linux 系统中: + + * 用 `Vim` 打开 `.vimrc` 文件: `vim ~/.vimrc` + * 复制本文最后的 `选项列表` 粘贴到 `.vimrc` 文件 + * 保存并关闭 (`:wq`) + +(LCTT 译注:此处不建议使用 `Vim` 编辑 `.vimrc` 文件,因为很可能无法粘贴成功,可以选择 `gedit` 编辑器编辑 `.vimrc` 文件。) + +Windows 系统中: + + * 首先,[安装 gvim][1] + * 打开 `gvim` + * 单击 “编辑” -> “启动设置”,打开 `_vimrc` 文件 + * 复制本文最后的 “选项列表” 粘贴到 `_vimrc` 文件 + * 单击 “文件” -> “保存” + +(LCTT 译注:此处应注意不要使用 `Windows` 自带的记事本编辑该 `_vimrc` 文件,否则可能会因为行结束符不同而导致问题。) + +下面,我们将深入研究提高 `Vim` 编辑效率的选项。主要分为以下几类: + + 1. 缩进 & 制表符 + 2. 显示 & 格式化 + 3. 搜索 + 4. 浏览 & 滚动 + 5. 拼写 + 6. 其他选项 + +### 1. 缩进 & 制表符 + +使 `Vim` 在创建新行的时候使用与上一行同样的缩进: + +```vim +set autoindent +``` + +创建新行时使用智能缩进,主要用于 `C` 语言一类的程序。通常,打开 `smartindent` 时也应该打开 `autoindent`: + +```vim +set smartindent +``` + +注意:`Vim` 具有语言感知功能,且其默认设置可以基于文件中的编程语言来改变配置以提高效率。有许多默认的配置选项,包括 `axs cindent`,`cinoptions`,`indentexpr` 等,没有在这里说明。 `syn` 是一个非常有用的命令,用于设置文件的语法以更改显示模式。 + +(LCTT 译注:这里的 `syn` 是指 `syntax`,可用于设置文件所用的编程语言,开启对应的语法高亮,以及执行自动事件 (`autocmd`)。) + +设置文件里的制表符 `(TAB)` 的宽度(以空格的数量表示): + +```vim +set tabstop=4 +``` + +设置移位操作 `>>` 或 `<<` 的缩进长度(以空格的数量表示): + +```vim +set shiftwidth=4 +``` + +如果你更喜欢在编辑文件时使用空格而不是制表符,设置以下选项可以使 `Vim` 在你按下 `Tab` 键时用空格代替制表符。 + +```vim +set expandtab +``` + +注意:这可能会导致依赖于制表符的 `Python` 等编程语言出现问题。这时,你可以根据文件类型设置该选项(请参考 `autocmd`)。 + +### 2. 显示 & 格式化 + +要在每行的前面显示行号: + +```vim +set number +``` + +![](https://opensource.com/sites/default/files/uploads/picture01.png) + +要在文本行超过一定长度时自动换行: + +```vim +set textwidth=80 +``` + +要根据从窗口右侧向左数的列数来自动换行: + +```vim +set wrapmargin=2 +``` + +(LCTT 译注:如果 `textwidth` 选项不等于零,本选项无效。) + +当光标遍历文件时经过括号时,高亮标识匹配的括号: + +```vim +set showmatch +``` + +![](https://opensource.com/sites/default/files/uploads/picture02-03.jpg) + +### 3. 搜索 + +高亮搜索内容的所有匹配位置: + +```vim +set hlsearch +``` + +![](https://opensource.com/sites/default/files/uploads/picture04.png) + +搜索过程中动态显示匹配内容: + +```vim +set incsearch +``` + +![](https://opensource.com/sites/default/files/picture05.png) + +搜索时忽略大小写: + +```vim +set ignorecase +``` + +在打开 `ignorecase` 选项的条件下,搜索内容包含部分大写字符时,要使搜索大小写敏感: + +```vim +set smartcase +``` + +例如,如果文件内容是: + +``` +test +Test +``` + +当打开 `ignorecase` 和 `smartcase` 选项时,搜索 `test` 时的突出显示: + +> test +> Test + +搜索 `Test` 时的突出显示: + +> test +> Test + +### 4. 浏览 & 滚动 + +为获得更好的视觉体验,你可能希望将光标放在窗口中间而不是第一行,以下选项使光标距窗口上下保留 5 行。 + +```vim +set scrolloff=5 +``` + +一个例子: + +第一张图中 `scrolloff=0`,第二张图中 `scrolloff=5`。 + +![](https://opensource.com/sites/default/files/uploads/picture06-07.jpg) + +提示:如果你没有设置选项 `nowrap`,那么设置 `sidescrolloff` 将非常有用。 + +在 `Vim` 窗口底部显示一个永久状态栏,可以显示文件名、行号和列号等内容: + +```vim +set laststatus=2 +``` + +![](https://opensource.com/sites/default/files/picture08.png) + +### 5. 拼写 + +`Vim` 有一个内置的拼写检查器,对于文本编辑和编码非常有用。`Vim` 可以识别文件类型并仅对代码中的注释进行拼写检查。使用下面的选项打开英语拼写检查: + +```vim +set spell spelllang=en_us +``` + +(LCTT 译注:中文、日文或其它东亚语字符通常会在打开拼写检查时被标为拼写错误,因为拼写检查不支持这些语种,可以在 `spelllang` 选项中加入 `cjk` 来忽略这些错误标注。) + +### 6. 其他选项 + +禁止创建备份文件:启用此选项后,`Vim` 将在覆盖文件前创建一个备份,文件成功写入后保留该备份。如果不想保留该备份文件,可以按下面的方式关闭: + +```vim +set nobackup +``` + +禁止创建交换文件:启用此选项后,`Vim` 将在编辑该文件时创建一个交换文件。 交换文件用于在崩溃或发生使用冲突时恢复文件。交换文件是以 `.` 开头并以 `.swp` 结尾的隐藏文件。 + +```vim +set noswapfile +``` + +如果需要在同一个 `Vim` 窗口中编辑多个文件并进行切换。默认情况下,工作目录是打开的第一个文件的目录。而将工作目录自动切换到正在编辑的文件的目录是非常有用的。要自动切换工作目录: + +```vim +set autochdir +``` + +`Vim` 自动维护编辑的历史记录,允许撤消更改。默认情况下,该历史记录仅在文件关闭之前有效。`Vim` 包含一个增强功能,使得即使在文件关闭后也可以维护撤消历史记录,这意味着即使在保存、关闭和重新打开文件后,也可以撤消之前的更改。历史记录文件是使用 `.un~` 扩展名保存的隐藏文件。 + +```vim +set undofile +``` + +错误信息响铃,只对错误信息起作用: + +```vim +set errorbells +``` + +如果你愿意,还可以设置错误视觉提示: + +```vim +set visualbell +``` + +### 惊喜 + +`Vim` 提供长格式和短格式命令,两种格式都可用于设置或取消选项配置。 + +`autoindent` 选项的长格式是: + +```vim +set autoindent +``` + +`autoindent` 选项的短格式是: + +```vim +set ai +``` + +要在不更改选项当前值的情况下查看其当前设置,可以在 `Vim` 的命令行上使用在末尾加上 `?` 的命令: + +```vim +set autoindent? +``` + +在大多数选项前加上 `no` 前缀可以取消或关闭选项: + +```vim +set noautoindent +``` + +可以为单独的文件配置选项,而不必修改全局配置文件。需要的话,请打开文件并输入 `:`,然后键入 `set`命令。这样的话,配置仅对当前的文件编辑会话有效。 + +![](https://opensource.com/sites/default/files/uploads/picture09.png) + +使用命令行获取帮助: + +```vim +:help autoindent +``` + +![](https://opensource.com/sites/default/files/uploads/picture10-11.jpg) + +注意:此处列出的命令仅对 Linux 上的 Vim 7.4 版本和 Windows 上的 Vim 8.0 版本进行了测试。 + +这些有用的命令肯定会增强您的 `Vim` 使用体验。你会推荐哪些其他有用的命令? + +### 选项列表 + +复制该选项列表粘贴到 `.vimrc` 文件中: + +```vim +" Indentation & Tabs +set autoindent +set smartindent +set tabstop=4 +set shiftwidth=4 +set expandtab +set smarttab +" Display & format +set number +set textwidth=80 +set wrapmargin=2 +set showmatch +" Search +set hlsearch +set incsearch +set ignorecase +set smartcase +" Browse & Scroll +set scrolloff=5 +set laststatus=2 +" Spell +set spell spelllang=en_us +" Miscellaneous +set nobackup +set noswapfile +set autochdir +set undofile +set visualbell +set errorbells +``` + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/9/vi-editor-productivity-powerhouse + +作者:[Girish Managoli][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[idea2act](https://github.com/idea2act) +校对:[apemost](https://github.com/apemost), [wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://opensource.com/users/gammay +[1]: https://www.vim.org/download.php#pc diff --git a/published/20180904 8 Linux commands for effective process management.md b/published/20180904 8 Linux commands for effective process management.md new file mode 100644 index 0000000000..5f17d5832d --- /dev/null +++ b/published/20180904 8 Linux commands for effective process management.md @@ -0,0 +1,292 @@ +8 个用于有效地管理进程的 Linux 命令 +====== + +> 通过这些关键的命令来全程管理你的应用。 + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/command_line_prompt.png?itok=wbGiJ_yg) + +一般来说,应用程序进程的生命周期有三种主要状态:启动、运行和停止。如果我们想成为称职的管理员,每个状态都可以而且应该得到认真的管理。这八个命令可用于管理进程的整个生命周期。 + +### 启动进程 + +启动进程的最简单方法是在命令行中键入其名称,然后按回车键。如果要启动 Nginx web 服务器,请键入 `nginx` 。也许您只是想看看其版本。 + +``` +alan@workstation:~$ nginx + +alan@workstation:~$ nginx -v +nginx version: nginx/1.14.0 +``` + +### 查看您的可执行路径 + +以上启动进程的演示是假设可执行文件位于您的可执行路径中。理解这个路径是可靠地启动和管理进程的关键。管理员通常会为他们想要的目的定制这条路径。您可以使用 `echo $PATH` 查看您的可执行路径。 + +``` +alan@workstation:~$ echo $PATH +/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin +``` + +#### WHICH + +使用 `which` 命令查看可执行文件的完整路径。 + +``` +alan@workstation:~$ which nginx +/opt/nginx/bin/nginx +``` + +我将使用流行的 web 服务器软件 Nginx 作为我的例子。假设安装了 Nginx。如果执行 `which nginx` 的命令什么也不返回,那么是找不到 Nginx 了,因为它只搜索您指定的可执行路径。有三种方法可以补救一个进程不能简单地通过名字启动的情况。首先是键入完整路径 —— 虽然,我不情愿输入全部路径,您会吗? + +``` +alan@workstation:~$ /home/alan/web/prod/nginx/sbin/nginx -v +nginx version: nginx/1.14.0 +``` + +第二个解决方案是将应用程序安装在可执行文件路径中的目录中。然而,这有时可能是办不到的,特别是如果您没有 root 权限。 + +第三个解决方案是更新您的可执行路径环境变量,包括要使用的特定应用程序的安装目录。这个解决方案是与 shell 相关的。例如,Bash 用户需要在他们的 `.bashrc` 文件中编辑 `PATH=` 行。 + +``` +PATH="$HOME/web/prod/nginx/sbin:$PATH" +``` + +现在,重复您的 `echo` 和 `which` 命令或者尝试检查版本。容易多了! + +``` +alan@workstation:~$ echo $PATH +/home/alan/web/prod/nginx/sbin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin + +alan@workstation:~$ which nginx +/home/alan/web/prod/nginx/sbin/nginx + +alan@workstation:~$ nginx -v                                                 +nginx version: nginx/1.14.0 +``` + +### 保持进程运行 + +#### NOHUP + +注销或关闭终端时,进程可能不会继续运行。这种特殊情况可以通过在要使用 `nohup` 命令放在要运行的命令前面让进程持续运行。此外,附加一个`&` 符号将会把进程发送到后台,并允许您继续使用终端。例如,假设您想运行 `myprogram.sh` 。 + +``` +nohup myprogram.sh & +``` + +`nohup` 会返回运行进程的 PID。接下来我会更多地谈论 PID。 + +### 管理正在运行的进程 + +每个进程都有一个唯一的进程标识号 (PID) 。这个数字是我们用来管理每个进程的。我们还可以使用进程名称,我将在下面演示。有几个命令可以检查正在运行的进程的状态。让我们快速看看这些命令。 + +#### PS + +最常见的是 `ps` 命令。`ps` 的默认输出是当前终端中运行的进程的简单列表。如下所示,第一列包含 PID。 + +``` +alan@workstation:~$ ps +PID TTY          TIME CMD +23989 pts/0    00:00:00 bash +24148 pts/0    00:00:00 ps +``` + +我想看看我之前启动的 Nginx 进程。为此,我告诉 `ps` 给我展示每一个正在运行的进程(`-e`)和完整的列表(`-f`)。 + +``` +alan@workstation:~$ ps -ef +UID        PID  PPID  C STIME TTY          TIME CMD +root         1     0  0 Aug18 ?        00:00:10 /sbin/init splash +root         2     0  0 Aug18 ?        00:00:00 [kthreadd] +root         4     2  0 Aug18 ?        00:00:00 [kworker/0:0H] +root         6     2  0 Aug18 ?        00:00:00 [mm_percpu_wq] +root         7     2  0 Aug18 ?        00:00:00 [ksoftirqd/0] +root         8     2  0 Aug18 ?        00:00:20 [rcu_sched] +root         9     2  0 Aug18 ?        00:00:00 [rcu_bh] +root        10     2  0 Aug18 ?        00:00:00 [migration/0] +root        11     2  0 Aug18 ?        00:00:00 [watchdog/0] +root        12     2  0 Aug18 ?        00:00:00 [cpuhp/0] +root        13     2  0 Aug18 ?        00:00:00 [cpuhp/1] +root        14     2  0 Aug18 ?        00:00:00 [watchdog/1] +root        15     2  0 Aug18 ?        00:00:00 [migration/1] +root        16     2  0 Aug18 ?        00:00:00 [ksoftirqd/1] +alan     20506 20496  0 10:39 pts/0    00:00:00 bash +alan     20520  1454  0 10:39 ?        00:00:00 nginx: master process nginx +alan     20521 20520  0 10:39 ?        00:00:00 nginx: worker process +alan     20526 20506  0 10:39 pts/0    00:00:00 man ps +alan     20536 20526  0 10:39 pts/0    00:00:00 pager +alan     20564 20496  0 10:40 pts/1    00:00:00 bash +``` + +您可以在上面 `ps` 命令的输出中看到 Nginx 进程。这个命令显示了将近 300 行,但是我在这个例子中缩短了它。可以想象,试图处理 300 行过程信息有点混乱。我们可以将这个输出输送到 `grep`,过滤一下仅显示 nginx。 + +``` +alan@workstation:~$ ps -ef |grep nginx +alan     20520  1454  0 10:39 ?        00:00:00 nginx: master process nginx +alan     20521 20520  0 10:39 ?        00:00:00 nginx: worker process +``` + +确实更好了。我们可以很快看到,Nginx 有 20520 和 20521 的 PID。 + +#### PGREP + +`pgrep` 命令更加简化单独调用 `grep` 遇到的问题。 + +``` +alan@workstation:~$ pgrep nginx +20520 +20521 +``` + +假设您在一个托管环境中,多个用户正在运行几个不同的 Nginx 实例。您可以使用 `-u` 选项将其他人排除在输出之外。 + +``` +alan@workstation:~$ pgrep -u alan nginx +20520 +20521 +``` + +#### PIDOF + + +另一个好用的是 `pidof`。此命令将检查特定二进制文件的 PID,即使另一个同名进程正在运行。为了建立一个例子,我将我的 Nginx 复制到第二个目录,并以相应的路径前缀启动。在现实生活中,这个实例可能位于不同的位置,例如由不同用户拥有的目录。如果我运行两个 Nginx 实例,则`pidof` 输出显示它们的所有进程。 + +``` +alan@workstation:~$ ps -ef |grep nginx +alan     20881  1454  0 11:18 ?        00:00:00 nginx: master process ./nginx -p /home/alan/web/prod/nginxsec +alan     20882 20881  0 11:18 ?        00:00:00 nginx: worker process +alan     20895  1454  0 11:19 ?        00:00:00 nginx: master process nginx +alan     20896 20895  0 11:19 ?        00:00:00 nginx: worker process +``` + +使用 `grep` 或 `pgrep` 将显示 PID 数字,但我们可能无法辨别哪个实例是哪个。 + +``` +alan@workstation:~$ pgrep nginx +20881 +20882 +20895 +20896 +``` + +`pidof` 命令可用于确定每个特定 Nginx 实例的 PID。 + +``` +alan@workstation:~$ pidof /home/alan/web/prod/nginxsec/sbin/nginx +20882 20881 + +alan@workstation:~$ pidof /home/alan/web/prod/nginx/sbin/nginx +20896 20895 +``` + +#### TOP + +`top` 命令已经有很久的历史了,对于查看运行进程的细节和快速识别内存消耗等问题是非常有用的。其默认视图如下所示。 + +``` +top - 11:56:28 up 1 day, 13:37,  1 user,  load average: 0.09, 0.04, 0.03 +Tasks: 292 total,   3 running, 225 sleeping,   0 stopped,   0 zombie +%Cpu(s):  0.1 us,  0.2 sy,  0.0 ni, 99.7 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st +KiB Mem : 16387132 total, 10854648 free,  1859036 used,  3673448 buff/cache +KiB Swap:        0 total,        0 free,        0 used. 14176540 avail Mem + +  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND +17270 alan      20   0 3930764 247288  98992 R   0.7  1.5   5:58.22 gnome-shell +20496 alan      20   0  816144  45416  29844 S   0.5  0.3   0:22.16 gnome-terminal- +21110 alan      20   0   41940   3988   3188 R   0.1  0.0   0:00.17 top +    1 root      20   0  225564   9416   6768 S   0.0  0.1   0:10.72 systemd +    2 root      20   0       0      0      0 S   0.0  0.0   0:00.01 kthreadd +    4 root       0 -20       0      0      0 I   0.0  0.0   0:00.00 kworker/0:0H +    6 root       0 -20       0      0      0 I   0.0  0.0   0:00.00 mm_percpu_wq +    7 root      20   0       0      0      0 S   0.0  0.0   0:00.08 ksoftirqd/0 +``` + +可以通过键入字母 `s` 和您喜欢的更新秒数来更改更新间隔。为了更容易监控我们的示例 Nginx 进程,我们可以使用 `-p` 选项并传递 PID 来调用 `top`。这个输出要干净得多。 + +``` +alan@workstation:~$ top -p20881 -p20882 -p20895 -p20896 + +Tasks:   4 total,   0 running,   4 sleeping,   0 stopped,   0 zombie +%Cpu(s):  2.8 us,  1.3 sy,  0.0 ni, 95.9 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st +KiB Mem : 16387132 total, 10856008 free,  1857648 used,  3673476 buff/cache +KiB Swap:        0 total,        0 free,        0 used. 14177928 avail Mem + +  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND +20881 alan      20   0   12016    348      0 S   0.0  0.0   0:00.00 nginx +20882 alan      20   0   12460   1644    932 S   0.0  0.0   0:00.00 nginx +20895 alan      20   0   12016    352      0 S   0.0  0.0   0:00.00 nginx +20896 alan      20   0   12460   1628    912 S   0.0  0.0   0:00.00 nginx +``` + +在管理进程,特别是终止进程时,正确确定 PID 是非常重要。此外,如果以这种方式使用 `top`,每当这些进程中的一个停止或一个新进程开始时,`top` 都需要被告知有新的进程。 + +### 终止进程 + +#### KILL + +有趣的是,没有 `stop` 命令。在 Linux 中,有 `kill` 命令。`kill` 用于向进程发送信号。最常用的信号是“终止”(`SIGTERM`)或“杀死”(`SIGKILL`)。然而,还有更多。下面是一些例子。完整的列表可以用 `kill -L` 显示。 + +``` + 1) SIGHUP       2) SIGINT       3) SIGQUIT      4) SIGILL       5) SIGTRAP + 6) SIGABRT      7) SIGBUS       8) SIGFPE       9) SIGKILL     10) SIGUSR1 +11) SIGSEGV     12) SIGUSR2     13) SIGPIPE     14) SIGALRM     15) SIGTERM + +``` + +注意第 9 号信号是 `SIGKILL`,通常,我们会发出比如 `kill -9 20896` 这样的命令。默认信号是 15,这是 `SIGTERM`。请记住,许多应用程序都有自己的停止方法。Nginx 使用 `-s` 选项传递信号,如 `stop` 或 `reload`。通常,我更喜欢使用应用程序的特定方法来停止操作。然而,我将演示用 `kill` 命令来停止 Nginx 进程 20896,然后用 `pgrep` 确认它已经停止。PID 20896 就不再出现。 + +``` +alan@workstation:~$ kill -9 20896 +  +alan@workstation:~$ pgrep nginx +20881 +20882 +20895 +22123 +``` + +#### PKILL + +命令 `pkill` 类似于 `pgrep`,因为它可以按名称搜索。这意味着在使用 `pkill` 时必须非常小心。在我的 Nginx 示例中,如果我只想杀死一个 Nginx 实例,我可能不会选择使用它。我可以将 Nginx 选项 `-s stop` 传递给特定的实例来消除它,或者我需要使用 `grep` 来过滤整个 `ps` 输出。 + +``` +/home/alan/web/prod/nginx/sbin/nginx -s stop +/home/alan/web/prod/nginxsec/sbin/nginx -s stop +``` + +如果我想使用 `pkill`,我可以包括 `-f` 选项,让 `pkill` 过滤整个命令行参数。这当然也适用于 `pgrep`。所以,在执行 `pkill -f` 之前,首先我可以用 `pgrep -a` 确认一下。 + +``` +alan@workstation:~$ pgrep -a nginx +20881 nginx: master process ./nginx -p /home/alan/web/prod/nginxsec +20882 nginx: worker process +20895 nginx: master process nginx +20896 nginx: worker process +``` + +我也可以用 `pgrep -f` 缩小我的结果。`pkill` 使用相同参数会停止该进程。 + +``` +alan@workstation:~$ pgrep -f nginxsec +20881 +                                            +alan@workstation:~$ pkill -f nginxsec +``` + +`pgrep`(尤其是 `pkill`)要记住的关键点是,您必须始终确保搜索结果准确性,这样您就不会无意中影响到错误的进程。 + +大多数这些命令都有许多命令行选项,所以我总是建议阅读每一个命令的 [man 手册页][1]。虽然大多数这些命令都存在于 Linux、Solaris 和 BSD 等平台上,但也有一些不同之处。在命令行工作或编写脚本时,始终测试并随时准备根据需要进行更正。 + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/9/linux-commands-process-management + +作者:[Alan Formy-Duval][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[heguangzhi](https://github.com/heguangzhi) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://opensource.com/users/alanfdoss +[1]: https://www.kernel.org/doc/man-pages/ diff --git a/published/20180904 Why I love Xonsh.md b/published/20180904 Why I love Xonsh.md new file mode 100644 index 0000000000..c852b24088 --- /dev/null +++ b/published/20180904 Why I love Xonsh.md @@ -0,0 +1,142 @@ +我为什么喜欢 Xonsh +====== + +> 有没有想过用 Python 做你的 shell? + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/shelloff.png?itok=L8pjHXjW) + +Shell 语言对交互式使用很有用。但是在使用它们作为编程语言时这种优化就需要权衡,有时在编写 shell 脚本时会感觉到这点。 + +如果你的 shell 也能理解一种更可伸缩的语言会怎样?比如说,Python? + +进入 [Xonsh][1]。 + +安装 Xonsh 就像创建虚拟环境一样简单,运行 `pip install xonsh [ptk,linux]`,然后运行 `xonsh`。 + +首先,你可能奇怪为什么你的 Python shell 有一个奇怪的提示: + +``` +$ 1+1 +2 +``` + +好的,计算器! + +``` +$ print("hello world") +hello world +``` + +我们还可以调用其他函数: + +``` +$ from antigravity import geohash +$ geohash(37.421542, -122.085589, b'2005-05-26-10458.68') +37.857713 -122.544543 +``` + +然而,我们仍然可以像常规 shell 一样使用它: + +``` +$ echo "hello world" +hello world +``` + +我们甚至可以混搭! + +``` +$ for i in range(3): +.     echo "hello world" +. +hello world +hello world +hello world +``` + +Xonsh 支持使用 [Prompt Toolkit][2] 补全 shell 命令和 Python 表达式。补全有可视化提示,会显示可能的补全并有下拉列表。 + +它还支持访问环境变量。它使用简单但强大的启发式方法将 Python 类型应用于环境变量。默认值为 “string”,但是,例如,路径变量是自动列表。 + +``` +$ '/usr/bin' in $PATH +True +``` + +Xonsh 接受 shell 形式或 Python 形式的布尔快捷运算符: + +``` +$ cat things +foo +$ grep -q foo things and echo "found" +found +$ grep -q bar things && echo "found" +$ grep -q foo things or echo "found" +$ grep -q bar things || echo "found" +found +``` + +这意味着 Python 关键字是被解释了。如果我们想要打印著名的《苏斯博士》书的标题,我们需要引用关键词。 + +``` +$ echo green eggs "and" ham +green eggs and ham +``` + +如果我们不这样做,我们会感到惊讶: + +``` +$ echo green eggs and ham +green eggs +xonsh: For full traceback set: $XONSH_SHOW_TRACEBACK = True +xonsh: subprocess mode: command not found: ham +Did you mean one of the following? +    as:   Command (/usr/bin/as) +    ht:   Command (/usr/bin/ht) +    mag:  Command (/usr/bin/mag) +    ar:   Command (/usr/bin/ar) +    nm:   Command (/usr/bin/nm) +``` + +虚拟环境可能会有点棘手。一般的虚拟环境(取决于它们类似 Bash 的语法)无法工作。但是,Xonsh 自带了一个名为 `vox` 的虚拟环境管理系统。 + +`vox` 可以创建、激活和停用 `~/.virtualenvs` 中的环境。如果你用过 `virtualenvwrapper`,这就是环境变量所在的地方。 + +请注意,当前激活的环境不会影响 `xonsh`。它无法从激活的环境中导入任何内容。 + +``` +$ xontrib load vox +$ vox create my-environment                                                     +... +$ vox activate my-environment         +Activated "my-environment".                                                     +$ pip install money                                                             +... +$ python                                                               +... +>>> import money                                                               +>>> money.Money('3.14')                         +$ import money +xonsh: For full traceback set: $XONSH_SHOW_TRACEBACK = True +ModuleNotFoundError: No module named 'money' +``` + +第一行启用 `vox`:它是一个 `xontrib`,是 Xonsh 的一个第三方扩展。`xontrib` 管理器可以列出所有可能的 `xontribs` 及其当前状态(已安装、已加载或未加载)。 + +可以编写一个 `xontrib` 并上传到 `PyPi` 以使其可用。但是,最好将它添加到 `xontrib` 索引中,以便 Xonsh 提前知道它。比如,这能让配置向导建议它。 + +如果你曾经想过,“Python 可以成为我的 shell 吗?”,然后你只要 `pip install xonsh` 一下就能知道。 + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/9/xonsh-bash-alternative + +作者:[Moshe Zadka][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[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/moshez +[1]: https://xon.sh/ +[2]: https://python-prompt-toolkit.readthedocs.io/en/master/ diff --git a/published/20180905 5 tips to improve productivity with zsh.md b/published/20180905 5 tips to improve productivity with zsh.md new file mode 100644 index 0000000000..22cd2dfc2b --- /dev/null +++ b/published/20180905 5 tips to improve productivity with zsh.md @@ -0,0 +1,308 @@ +用 zsh 提高生产力的 5 个技巧 +====== +> zsh 提供了数之不尽的功能和特性,这里有五个可以让你在命令行暴增效率的方法。 + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/features_solutions_command_data.png?itok=4_VQN3RK) + +Z shell([zsh][1])是 Linux 和类 Unix 系统中的一个[命令解析器][2]。 它跟 sh (Bourne shell) 家族的其它解析器(如 bash 和 ksh)有着相似的特点,但它还提供了大量的高级特性以及强大的命令行编辑功能,如增强版 Tab 补全。 + +在这里不可能涉及到 zsh 的所有功能,[描述][3]它的特性需要好几百页。在本文中,我会列出 5 个技巧,让你通过在命令行使用 zsh 来提高你的生产力。 + +### 1、主题和插件 + +多年来,开源社区已经为 zsh 开发了数不清的主题和插件。主题是一个预定义提示符的配置,而插件则是一组常用的别名命令和函数,可以让你更方便的使用一种特定的命令或者编程语言。 + +如果你现在想开始用 zsh 的主题和插件,那么使用一种 zsh 的配置框架是你最快的入门方式。在众多的配置框架中,最受欢迎的则是 [Oh My Zsh][4]。在默认配置中,它就已经为 zsh 启用了一些合理的配置,同时它也自带上百个主题和插件。 + +主题会在你的命令行提示符之前添加一些有用的信息,比如你 Git 仓库的状态,或者是当前使用的 Python 虚拟环境,所以它会让你的工作更高效。只需要看到这些信息,你就不用再敲命令去重新获取它们,而且这些提示也相当酷炫。下图就是我选用的主题 [Powerlevel9k][5]: + +![zsh Powerlevel9K theme][7] + +*zsh 主题 Powerlevel9k* + +除了主题,Oh my Zsh 还自带了大量常用的 zsh 插件。比如,通过启用 Git 插件,你可以用一组简便的命令别名操作 Git, 比如 + +``` +$ alias | grep -i git | sort -R | head -10 +g=git +ga='git add' +gapa='git add --patch' +gap='git apply' +gdt='git diff-tree --no-commit-id --name-only -r' +gau='git add --update' +gstp='git stash pop' +gbda='git branch --no-color --merged | command grep -vE "^(\*|\s*(master|develop|dev)\s*$)" | command xargs -n 1 git branch -d' +gcs='git commit -S' +glg='git log --stat' +``` + +zsh 还有许多插件可以用于许多编程语言、打包系统和一些平时在命令行中常用的工具。以下是我 Ferdora 工作站中用到的插件表: + +``` +git golang fedora docker oc sudo vi-mode virtualenvwrapper +``` + +### 2、智能的命令别名 + +命令别名在 zsh 中十分有用。为你常用的命令定义别名可以节省你的打字时间。Oh My Zsh 默认配置了一些常用的命令别名,包括目录导航命令别名,为常用的命令添加额外的选项,比如: + +``` +ls='ls --color=tty' +grep='grep  --color=auto --exclude-dir={.bzr,CVS,.git,.hg,.svn}' +``` + +除了命令别名以外, zsh 还自带两种额外常用的别名类型:后缀别名和全局别名。 + +后缀别名可以让你基于文件后缀,在命令行中利用指定程序打开这个文件。比如,要用 vim 打开 YAML 文件,可以定义以下命令行别名: + +``` +alias -s {yml,yaml}=vim +``` + +现在,如果你在命令行中输入任何后缀名为 `yml` 或 `yaml` 文件, zsh 都会用 vim 打开这个文件。 + +``` +$ playbook.yml +# Opens file playbook.yml using vim +``` + +全局别名可以让你创建一个可在命令行的任何地方展开的别名,而不仅仅是在命令开始的时候。这个在你想替换常用文件名或者管道命令的时候就显得非常有用了。比如: + +``` +alias -g G='| grep -i' +``` + +要使用这个别名,只要你在想用管道命令的时候输入 `G` 就好了: + +``` +$ ls -l G do +drwxr-xr-x.  5 rgerardi rgerardi 4096 Aug  7 14:08 Documents +drwxr-xr-x.  6 rgerardi rgerardi 4096 Aug 24 14:51 Downloads +``` + +接着,我们就来看看 zsh 是如何导航文件系统的。 + +### 3、便捷的目录导航 + +当你使用命令行的时候,在不同的目录之间切换访问是最常见的工作了。 zsh 提供了一些十分有用的目录导航功能来简化这个操作。这些功能已经集成到 Oh My Zsh 中了, 而你可以用以下命令来启用它 + +``` +setopt  autocd autopushd \ pushdignoredups +``` + +使用了上面的配置后,你就不用输入 `cd` 来切换目录了,只需要输入目录名称,zsh 就会自动切换到这个目录中: + +``` +$ pwd +/home/rgerardi +$ /tmp +$ pwd +/tmp +``` + +如果想要回退,只要输入 `-`: + +zsh 会记录你访问过的目录,这样下次你就可以快速切换到这些目录中。如果想要看这个目录列表,只要输入 `dirs -v`: + +``` +$ dirs -v +0       ~ +1       /var/log +2       /var/opt +3       /usr/bin +4       /usr/local +5       /usr/lib +6       /tmp +7       ~/Projects/Opensource.com/zsh-5tips +8       ~/Projects +9       ~/Projects/ansible +10      ~/Documents +``` + +如果想要切换到这个列表中的其中一个目录,只需输入 `~#` (`#` 代表目录在列表中的序号)就可以了。比如 + +``` +$ pwd +/home/rgerardi +$ ~4 +$ pwd +/usr/local +``` + +你甚至可以用别名组合这些命令,这样切换起来就变得更简单: + +``` +d='dirs -v | head -10' +1='cd -' +2='cd -2' +3='cd -3' +4='cd -4' +5='cd -5' +6='cd -6' +7='cd -7' +8='cd -8' +9='cd -9' +``` + +现在你可以通过输入 `d` 来查看这个目录列表的前10个,然后用目录的序号来进行切换: + +``` +$ d +0       /usr/local +1       ~ +2       /var/log +3       /var/opt +4       /usr/bin +5       /usr/lib +6       /tmp +7       ~/Projects/Opensource.com/zsh-5tips +8       ~/Projects +9       ~/Projects/ansible +$ pwd +/usr/local +$ 6 +/tmp +$ pwd +/tmp +``` + +最后,你可以在 zsh 中利用 Tab 来自动补全目录名称。你可以先输入目录的首字母,然后按 `TAB` 键来补全它们: + +``` +$ pwd +/home/rgerardi +$ p/o/z (TAB) +$ Projects/Opensource.com/zsh-5tips/ +``` + +以上仅仅是 zsh 强大的 Tab 补全系统中的一个功能。接来下我们来探索它更多的功能。 + +### 4、先进的 Tab 补全 + +zsh 强大的补全系统是它的卖点之一。为了简便起见,我称它为 Tab 补全,然而在系统底层,它起到了几个作用。这里通常包括展开以及命令补全,我会在这里用讨论它们。如果想了解更多,详见 [用户手册][8]。 + +在 Oh My Zsh 中,命令补全是默认启用的。要启用它,你只要在 `.zshrc` 文件中添加以下命令: + +``` +autoload -U compinit +compinit +``` + +zsh 的补全系统非常智能。它会尝试唯一提示可用在当前上下文环境中的项目 —— 比如,你输入了 `cd` 和 `TAB`,zsh 只会为你提示目录名,因为它知道其它的项目放在 `cd` 后面没用。 + +反之,如果你使用与用户相关的命令便会提示用户名,而 `ssh` 或者 `ping` 这类则会提示主机名。 + +zsh 拥有一个巨大而又完整的库,因此它能识别许多不同的命令。比如,如果你使用 `tar` 命令, 你可以按 `TAB` 键,它会为你展示一个可以用于解压的文件列表: + +``` +$ tar -xzvf test1.tar.gz test1/file1 (TAB) +file1 file2 +``` + +如果使用 `git` 的话,这里有个更高级的示例。在这个示例中,当你按 `TAB` 键, zsh 会自动补全当前库可以操作的文件: + +``` +$ ls +original  plan.txt  zsh-5tips.md  zsh_theme_small.png +$ git status +On branch master +Your branch is up to date with 'origin/master'. + +Changes not staged for commit: +  (use "git add ..." to update what will be committed) +  (use "git checkout -- ..." to discard changes in working directory) + +        modified:   zsh-5tips.md + +no changes added to commit (use "git add" and/or "git commit -a") +$ git add (TAB) +$ git add zsh-5tips.md +``` + +zsh 还能识别命令行选项,同时它只会提示与选中子命令相关的命令列表: + +``` +$ git commit - (TAB) +--all                  -a       -- stage all modified and deleted paths +--allow-empty                   -- allow recording an empty commit +--allow-empty-message           -- allow recording a commit with an empty message +--amend                         -- amend the tip of the current branch +--author                        -- override the author name used in the commit +--branch                        -- show branch information +--cleanup                       -- specify how the commit message should be cleaned up +--date                          -- override the author date used in the commit +--dry-run                       -- only show the list of paths that are to be committed or not, and any untracked +--edit                 -e       -- edit the commit message before committing +--file                 -F       -- read commit message from given file +--gpg-sign             -S       -- GPG-sign the commit +--include              -i       -- update the given files and commit the whole index +--interactive                   -- interactively update paths in the index file +--message              -m       -- use the given message as the commit message +... TRUNCATED ... +``` + +在按 `TAB` 键之后,你可以使用方向键来选择你想用的命令。现在你就不用记住所有的 `git` 命令项了。 + +zsh 还有很多有用的功能。当你用它的时候,你就知道哪些对你才是最有用的。 + +### 5、命令行编辑与历史记录 + +zsh 的命令行编辑功能也十分有用。默认条件下,它是模拟 emacs 编辑器的。如果你是跟我一样更喜欢用 vi/vim,你可以用以下命令启用 vi 的键绑定。 + +``` +$ bindkey -v +``` + +如果你使用 Oh My Zsh,`vi-mode` 插件可以启用额外的绑定,同时会在你的命令提示符上增加 vi 的模式提示 —— 这个非常有用。 + +当启用 vi 的绑定后,你可以在命令行中使用 vi 命令进行编辑。比如,输入 `ESC+/` 来查找命令行记录。在查找的时候,输入 `n` 来找下一个匹配行,输入 `N` 来找上一个。输入 `ESC` 后,常用的 vi 命令都可以使用,如输入 `0` 跳转到行首,输入 `$` 跳转到行尾,输入 `i` 来插入文本,输入 `a` 来追加文本等等,即使是跟随的命令也同样有效,比如输入 `cw` 来修改单词。 + +除了命令行编辑,如果你想修改或重新执行之前使用过的命令,zsh 还提供几个常用的命令行历史功能。比如,你打错了一个命令,输入 `fc`,你可以在你偏好的编辑器中修复最后一条命令。使用哪个编辑是参照 `$EDITOR` 变量的,而默认是使用 vi。 + +另外一个有用的命令是 `r`, 它会重新执行上一条命令;而 `r ` 则会执行上一条包含 `WORD` 的命令。 + +最后,输入两个感叹号(`!!`),可以在命令行中回溯最后一条命令。这个十分有用,比如,当你忘记使用 `sudo` 去执行需要权限的命令时: + +``` +$ less /var/log/dnf.log +/var/log/dnf.log: Permission denied +$ sudo !! +$ sudo less /var/log/dnf.log +``` + +这个功能让查找并且重新执行之前命令的操作更加方便。 + +### 下一步呢? + +这里仅仅介绍了几个可以让你提高生产率的 zsh 特性;其实还有更多功能有待你的发掘;想知道更多的信息,你可以访问以下的资源: + +- [An Introduction to the Z Shell][9] +- [A User's Guide to ZSH][10] +- [Archlinux Wiki][11] +- [zsh-lovers][12] + +你有使用 zsh 提高生产力的技巧可以分享吗?我很乐意在下方评论中看到它们。 + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/9/tips-productivity-zsh + +作者:[Ricardo Gerardi][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[tnuoccalanosrep](https://github.com/tnuoccalanosrep) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://opensource.com/users/rgerardi +[1]: http://www.zsh.org/ +[2]: https://en.wikipedia.org/wiki/Shell_(computing) +[3]: http://zsh.sourceforge.net/Doc/Release/zsh_toc.html +[4]: https://ohmyz.sh/ +[5]: https://github.com/bhilburn/powerlevel9k +[7]: https://opensource.com/sites/default/files/uploads/zsh_theme_small.png (zsh Powerlevel9K theme) +[8]: http://zsh.sourceforge.net/Guide/zshguide06.html#l144 +[9]: http://zsh.sourceforge.net/Intro/intro_toc.html +[10]: http://zsh.sourceforge.net/Guide/ +[11]: https://wiki.archlinux.org/index.php/zsh +[12]: https://grml.org/zsh/ diff --git a/published/20180905 8 great Python libraries for side projects.md b/published/20180905 8 great Python libraries for side projects.md new file mode 100644 index 0000000000..f8d05dc41a --- /dev/null +++ b/published/20180905 8 great Python libraries for side projects.md @@ -0,0 +1,68 @@ +8 个用于业余项目的优秀 Python 库 +====== + +> 这些库可以使你更容易构架个人项目。 + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/python-programming-code-keyboard.png?itok=fxiSpmnd) + +在 Python/Django 的世界里有这样一个谚语:为语言而来,为社区而留。对绝大多数人来说的确是这样的,但是,还有一件事情使得我们一直停留在 Python 的世界里,不愿离开,那就是我们可以很容易地利用一顿午餐或晚上几个小时的时间,把一个想法快速地实现出来。 + +这个月,我们来探讨一些我们喜欢用来快速完成业余项目side projects或打发午餐时间的 Python 库。 + +### 在数据库中即时保存数据:Dataset + +当我们想要在不知道最终数据库表长什么样的情况下,快速收集数据并保存到数据库中的时候,[Dataset][1] 库将是我们的最佳选择。Dataset 库有一个简单但功能强大的 API,因此我们可以很容易的把数据保存下来,之后再进行整理。 + +Dataset 建立在 SQLAlchemy 之上,所以如果需要对它进行扩展,你会感到非常熟悉。使用 Django 内建的 [inspectdb][2] 管理命令可以很容易地把底层数据库模型导入 Django 中,这使得和现有数据库一同工作不会出现任何障碍。 + +### 从网页抓取数据:Beautiful Soup + +[Beautiful Soup][3](一般写作 BS4)库使得从 HTML 网页中提取信息变得非常简单。当我们需要把非结构化或弱结构化的 HTML 转换为结构化数据的时候,就需要使用 Beautiful Soup 。用它来处理 XML 数据也是一个很好的选择,否则 XML 的可读性或许会很差。 + +### 和 HTTP 内容打交道:Requests + +当需要和 HTTP 内容打交道的时候,[Requests][4] 毫无疑问是最好的标准库。当我们想要抓取 HTML 网页或连接 API 的时候,都离不开 Requests 库。同时,它也有很好的文档。 + +### 编写命令行工具:Click + +当需要写一个简单的 Python 脚本作为命令行工具的时候,[Click][5] 是我最喜欢用的库。它的 API 非常直观,并且在实现时经过了深思熟虑,我们只需要记住很少的几个模式。它的文档也很优秀,这使得学习其高级特性更加容易。 + +### 对事物命名:Python Slugify + +众所周知,命名是一件困难的事情。[Python Slugify][6] 是一个非常有用的库,它可以把一个标题或描述转成一个带有特性的唯一标识符。如果你正在做一个 Web 项目,并且你想要使用对搜索引擎优化友好SEO-friendly的链接,那么,使用 Python Slugify 可以让这件事变得很容易。 + +### 和插件打交道:Pluggy + +[Pluggy][7] 库相对较新,但是如果你想添加一个插件系统到现有应用中,那么使用 Pluggy 是最好也是最简单的方式。如果你使用过 pytest,那么实际上相当于已经使用过 Pluggy 了,虽然你还不知道它。 + +### 把 CSV 文件转换到 API 中:DataSette + +[DataSette][8] 是一个神奇的工具,它可以很容易地把 CSV 文件转换为全特性的只读 REST JSON API,同时,不要把它和 Dataset 库混淆。Datasette 有许多特性,包括创建图表和 geo(用于创建交互式地图),并且很容易通过容器或第三方网络主机进行部署。 + +### 处理环境变量等:Envparse + +如果你不想在源代码中保存 API 密钥、数据库凭证或其他敏感信息,那么你便需要解析环境变量,这时候 [envparse][9] 是最好的选择。Envparse 能够处理环境变量、ENV 文件、变量类型,甚至还可以进行预处理和后处理(例如,你想要确保变量名总是大写或小写的)。 + +有什么你最喜欢的用于业余项目的 Python 库不在这个列表中吗?请在评论中和我们分享。 + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/9/python-libraries-side-projects + +作者:[Jeff Triplett][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[ucasFL](https://github.com/ucasFL) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://opensource.com/users/laceynwilliams +[1]: https://dataset.readthedocs.io/en/latest/ +[2]: https://docs.djangoproject.com/en/2.1/ref/django-admin/#django-admin-inspectdb +[3]: https://www.crummy.com/software/BeautifulSoup/ +[4]: http://docs.python-requests.org/ +[5]: http://click.pocoo.org/5/ +[6]: https://github.com/un33k/python-slugify +[7]: https://pluggy.readthedocs.io/en/latest/ +[8]: https://github.com/simonw/datasette +[9]: https://github.com/rconradharris/envparse diff --git a/published/20180905 Find your systems easily on a LAN with mDNS.md b/published/20180905 Find your systems easily on a LAN with mDNS.md new file mode 100644 index 0000000000..49be86d1ab --- /dev/null +++ b/published/20180905 Find your systems easily on a LAN with mDNS.md @@ -0,0 +1,99 @@ +使用 mDNS 在局域网中轻松发现系统 +====== + +![](https://fedoramagazine.org/wp-content/uploads/2018/09/mDNS-816x345.jpg) + +mDNS(多播 DNSMulticast DNS)允许系统在局域网中广播查询其他资源的名称。Fedora 用户经常在没有复杂名称服务的路由器上接有多个 Linux 系统。在这种情况下,mDNS 允许你按名称与多个系统通信 —— 多数情况下不用路由器。你也不必在所有本地系统上同步类似 `/etc/hosts` 之类的文件。本文介绍如何设置它。 + +mDNS 是一个零配置网络服务,它已经诞生了很长一段时间。Fedora Workstation 带有零配置系统 Avahi(它包含 mDNS)。 (mDNS 也是 Bonjour 的一部分,可在 Mac OS 上找到。) + +本文假设你有两个系统运行受支持的 Fedora 版本(27 或 28)。它们的主机名是 castor 和 pollux。 + +### 安装包 + +确保系统上安装了 nss-mdns 和 avahi 软件包。你可能是不同的版本,这也没问题: + +``` +$ rpm -q nss-mdns avahi +nss-mdns-0.14.1-1.fc28.x86_64 +avahi-0.7-13.fc28.x86_64 +``` + +Fedora Workstation 默认提供这两个包。如果不存在,请安装它们: + +``` +$ sudo dnf install nss-mdns avahi +``` + +确保 `avahi-daemon.service` 单元已启用并正在运行。同样,这是 Fedora Workstation 的默认设置。 + +``` +$ sudo systemctl enable --now avahi-daemon.service +``` + +虽然是可选的,但你可能还需要安装 avahi-tools 软件包。该软件包包括许多方便的程序,用于检查系统上的零配置服务的工作情况。使用这个 `sudo` 命令: + +``` +$ sudo dnf install avahi-tools +``` + +`/etc/nsswitch.conf` 控制系统使用哪个服务用于解析,以及它们的顺序。你应该在那个文件中看到这样的一行: + +``` +hosts: files mdns4_minimal [NOTFOUND=return] dns myhostname +``` + +注意命令 `mdns4_minimal [NOTFOUND=return]`。它们告诉你的系统使用多播 DNS 解析程序将主机名解析为 IP 地址。即使该服务有效,如果名称无法解析,也会尝试其余服务。 + +如果你没有看到与此类似的配置,则可以(以 root 用户身份)对其进行编辑。但是,nss-mdns 包会为你处理此问题。如果你对自己编辑它感到不舒服,请删除并重新安装该软件包以修复该文件。 + +在**两个系统**中执行同样的步骤 。 + +### 设置主机名并测试 + +现在你已完成常见的配置工作,请使用以下方法之一设置每个主机的名称: + +1. 如果你正在使用 Fedora Workstation,[你可以使用这个步骤][1]。 +2. 如果没有,请使用 `hostnamectl` 来做。在第一台机器上这么做:`$ hostnamectl set-hostname castor`。 +3. 你还可以编辑 `/etc/avahi/avahi-daemon.conf`,删除主机名设置行上的注释,并在那里设置名称。但是,默认情况下,Avahi 使用系统提供的主机名,因此你**不应该**需要此方法。 + +接下来,重启 Avahi 守护进程,以便它接收更改: + +``` +$ sudo systemctl restart avahi-daemon.service +``` + +然后正确设置另一台机器: + +``` +$ hostnamectl set-hostname pollux +$ sudo systemctl restart avahi-daemon.service +``` + +只要你的路由器没有禁止 mDNS 流量,你现在应该能够登录到 castor 并 ping 通另一台机器。你应该使用默认的 .local 域名,以便解析正常工作: + +``` +$ ping pollux.local +PING pollux.local (192.168.0.1) 56(84) bytes of data. +64 bytes from 192.168.0.1 (192.168.0.1): icmp_seq=1 ttl=64 time=3.17 ms +64 bytes from 192.168.0.1 (192.168.0.1): icmp_seq=2 ttl=64 time=1.24 ms +... +``` + +如果你在 pollux `ping castor.local`,同样的技巧也适用。现在在网络中访问你的系统更方便了! + +此外,如果你的路由器也支持这个服务,请不要感到惊讶。现代 WiFi 和有线路由器通常提供这些服务,以使消费者的生活更轻松。 + +此过程适用于大多数系统。但是,如果遇到麻烦,请使用 avahi-browse 和 avahi-tools 软件包中的其他工具来查看可用的服务。 + + +-------------------------------------------------------------------------------- + +via: https://fedoramagazine.org/find-systems-easily-lan-mdns/ + +作者:[Paul W. Frields][a] 
选题:[lujun9972](https://github.com/lujun9972) 
译者:[geekpi](https://github.com/geekpi) 
校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://fedoramagazine.org/author/pfrields/ +[1]: https://fedoramagazine.org/set-hostname-fedora/ diff --git a/published/20180906 3 top open source JavaScript chart libraries.md b/published/20180906 3 top open source JavaScript chart libraries.md new file mode 100644 index 0000000000..5aabeaa9f9 --- /dev/null +++ b/published/20180906 3 top open source JavaScript chart libraries.md @@ -0,0 +1,245 @@ +最好的 3 个开源 JavaScript 图表库 +====== +> 图表及其它可视化方式让传递数据的信息变得更简单。 + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/books_library_reading_list_colorful.jpg?itok=jJtnyniB) + +对于数据可视化和制作精美网站来说,图表和图形很重要。视觉上的展示让分析大块数据及传递信息变得更简单。JavaScript 图表库能让数据以极好的、易于理解的和交互的方式进行可视化,还能够优化你的网站设计。 + +本文会带你学习最好的 3 个开源 JavaScript 图表库。 + +### 1、 Chart.js + +[Chart.js][1] 是一个开源的 JavaScript 库,你可以在自己的应用中用它创建生动美丽和交互式的图表。使用它需要遵循 MIT 协议。 + +使用 Chart.js,你可以创建各种各样令人印象深刻的图表和图形,包括条形图、折线图、范围图、线性标度和散点图。它可以响应各种设备,使用 HTML5 Canvas 元素进行绘制。 + +示例代码如下,它使用该库绘制了一个条形图。本例中我们使用 Chart.js 的内容分发网络(CDN)来包含这个库。注意这里使用的数据仅用于展示。 + +``` + + + +  + + + +    +    +   +    +    + + +``` + +如你所见,通过设置 `type` 和 `bar` 来构造条形图。你可以把条形体的方向改成其他类型 —— 比如把 `type` 设置成 `horizontalBar`。 + +在 `backgroundColor` 数组参数中提供颜色类型,就可以设置条形图的颜色。 + +颜色被分配给关联数组中相同索引的标签和数据。例如,第二个标签 “Latin American”,颜色会是 “蓝色(blue)”(第二个颜色),数值是 4(data 中的第二个数字)。 + +代码的执行结果如下。 + +![](https://opensource.com/sites/default/files/uploads/chartjs-output.png) + +### 2、 Chartist.js + +[Chartist.js][2] 是一个简单的 JavaScript 动画库,你能够自制美丽的响应式图表,或者进行其他创作。使用它需要遵循 WTFPL 或者 MIT 协议。 + +这个库是由一些对现有图表工具不满的开发者进行开发的,它可以为设计师或程序员提供美妙的功能。 + +在项目中包含 Chartist.js 库后,你可以使用它们来创建各式各样的图表,包括动画,条形图和折线图。它使用 SVG 来动态渲染图表。 + +这里是使用该库绘制一个饼图的例子。 + +``` + + + +    +    +    +    +      + + + +   
+ +    + +    + + +``` + +使用 Chartist JavaScript 库,你可以使用各种预先构建好的 CSS 样式,而不是在项目中指定各种与样式相关的部分。你可以使用这些样式来设置已创建的图表的外观。 + +比如,预创建的 CSS 类 `.ct-chart` 是用来构建饼状图的容器。还有 `.ct-golden-section` 类可用于获取纵横比,它基于响应式设计进行缩放,帮你解决了计算固定尺寸的麻烦。Chartist 还提供了其它类别的比例容器,你可以在自己的项目中使用它们。 + +为了给各个扇形设置样式,可以使用默认的 `.ct-serials-a` 类。字母 `a` 是根据系列的数量变化的(a、b、c,等等),因此它与每个要设置样式的扇形相对应。 + +`Chartist.Pie` 方法用来创建一个饼状图。要创建另一种类型的图表,比如折线图,请使用 `Chartist.Line`。 + +代码的执行结果如下。 + +![](https://opensource.com/sites/default/files/uploads/chartistjs-output.png) + +### 3、 D3.js + +[D3.js][3] 是另一个好用的开源 JavaScript 图表库。使用它需要遵循 BSD 许可证。D3 的主要用途是,根据提供的数据,处理和添加文档的交互功能,。 + +借助这个 3D 动画库,你可以通过 HTML5、SVG 和 CSS 来可视化你的数据,并且让你的网站变得更精美。更重要的是,使用 D3,你可以把数据绑定到文档对象模型(DOM)上,然后使用基于数据的函数改变文档。 + +示例代码如下,它使用该库绘制了一个简单的条形图。 + +``` + + + +      +    +      + + + +   
+    +    + +    + + +``` + +使用 D3 库的主要概念是应用 CSS 样式选择器来定位 DOM 节点,然后对其执行操作,就像其它的 DOM 框架,比如 JQuery。 + +将数据绑定到文档上后,.`enter()` 函数会被调用,为即将到来的数据构建新的节点。所有在 .`enter()` 之后调用的方法会为数据中的每一个项目调用一次。 + +代码的执行结果如下。 + +![](https://opensource.com/sites/default/files/uploads/d3js-output.png) + +### 总结 + +[JavaScript][4] 图表库提供了强大的工具,你可以将自己的网络资源进行数据可视化。通过这三个开源库,你可以把自己的网站变得更好看,更容易使用。 + +你知道其它强大的用于创造 JavaScript 动画效果的前端库吗?请在下方的评论区留言分享。 + + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/9/open-source-javascript-chart-libraries + +作者:[Dr.Michael J.Garbade][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[BriFuture](https://github.com/brifuture) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://opensource.com/users/drmjg +[1]: https://www.chartjs.org/ +[2]: https://gionkunz.github.io/chartist-js/ +[3]: https://d3js.org/ +[4]: https://www.liveedu.tv/guides/programming/javascript/ diff --git a/published/20180906 Two open source alternatives to Flash Player.md b/published/20180906 Two open source alternatives to Flash Player.md new file mode 100644 index 0000000000..1d0911abcd --- /dev/null +++ b/published/20180906 Two open source alternatives to Flash Player.md @@ -0,0 +1,56 @@ +Flash Player 的两种开源替代方案 +====== +> Adobe 将于 2020 年终止对 Flash 媒体播放器的支持,但仍有很多人们希望访问的 Flash 视频。这里有两个开源的替代品或许可以帮到你。 + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/bulb-light-energy-power-idea.png?itok=zTEEmTZB) + +2017 年 7 月,Adobe 为 Flash Media Player 敲响了[丧钟][1],宣布将在 2020 年终止对曾经无处不在的在线视频播放器的支持。但事实上,在一系列损害了其声誉的零日攻击后,Flash 的份额在过去的 8 年一直在下跌。苹果公司在 2010 年宣布它不会支持这项技术后,其未来趋于黯淡,并且在谷歌停止在 Chrome 浏览器中默认启用 Flash(支持 HTML5)后,它的消亡在 2016 年进一步加速。 + +即便如此,Adobe 仍然每月发布该软件的更新,截至 2018 年 8 月,它在网站的使用率从 2011 年的 28.5% 下降到[仅 4.4%] [2]。还有更多证据表明 Flash 的下滑:谷歌工程总监 [Parisa Tabriz 说][3]通过浏览器访问 Flash 内容的 Chrome 用户数量从 2014 年的 80% 下降到 2018 年的 8%。 + +尽管如今很少有视频创作者以 Flash 格式发布,但仍有很多人们希望在未来几年内访问的 Flash 视频。鉴于官方支持的日期已经屈指可数,开源软件创建者有很好的机会涉足 Adobe Flash 媒体播放器的替代品。这其中两个应用是 Lightspark 和 GNU Gnash。它们都不是完美的替代品,但来自贡献者的帮助可以使它们成为可行的替代品。 + +### Lightspark + +[Lightspark][4] 是 Linux 上的 Flash Player 替代品。虽然它仍处于 alpha 状态,但自从 Adobe 在 2017 宣布废弃 Adobe 以来,开发速度已经加快。据其网站称,Lightspark 实现了 60% 的 Flash API,可在许多流行网站包括 BBC 新闻、Google Play 音乐和亚马逊音乐上[使用][5]。 + +Lightspark 是用 C++/C 编写的,并在 [LGPLv3][6] 下许可。该项目列出了 41 个贡献者,并正在积极征求错误报告和其他贡献。有关更多信息,请查看其 [GitHub 仓库][5]。 + +### GNU Gnash + +[GNU Gnash][7] 是一个用于 GNU/Linux 操作系统,包括 Ubuntu、Fedora 和 Debian 的 Flash Player。它作为独立软件和插件可用于 Firefox 和 Konqueror 浏览器中。 + +Gnash 的主要缺点是它不支持最新版本的 Flash 文件 —— 它支持大多数 Flash SWF v7 功能,一些 v8 和 v9 功能,不支持 v10 文件。它处于测试阶段,由于它在 [GNU GPLv3 或更高版本][8]下许可,因此你可以帮助实现它的现代化。访问其[项目页面][9]获取更多信息。 + +### 想要创建 Flash 吗? + +仅因为大多数人都不会发布 Flash 视频,但这并不意味着永远不需要创建 SWF 文件。如果你发现自己需要,这两个开源工具可能会有所帮助: + +* [Motion-Twin ActionScript 2 编译器][10](MTASC):一个命令行编译器,它可以在没有 Adobe Animate(Adobe 当前的视频创建软件)的情况下生成 SWF 文件。 +* [Ming][11]:用 C 编写的可以生成 SWF 文件的库。它还包含一些可用于处理 Flash 的[程序][12]。 + + +-------------------------------------------------------------------------------- + +via: https://opensource.com/alternatives/flash-media-player + +作者:[Opensource.com][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[geekpi](https://github.com/geekpi) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://opensource.com +[1]: https://theblog.adobe.com/adobe-flash-update/ +[2]: https://w3techs.com/technologies/details/cp-flash/all/all +[3]: https://www.bleepingcomputer.com/news/security/google-chrome-flash-usage-declines-from-80-percent-in-2014-to-under-8-percent-today/ +[4]: http://lightspark.github.io/ +[5]: https://github.com/lightspark/lightspark/wiki/Site-Support +[6]: https://github.com/lightspark/lightspark/blob/master/COPYING +[7]: https://www.gnu.org/software/gnash/ +[8]: http://www.gnu.org/licenses/gpl-3.0.html +[9]: http://savannah.gnu.org/projects/gnash/ +[10]: http://tech.motion-twin.com/mtasc.html +[11]: http://www.libming.org/ +[12]: http://www.libming.org/WhatsIncluded diff --git a/published/20180907 Autotrash - A CLI Tool To Automatically Purge Old Trashed Files.md b/published/20180907 Autotrash - A CLI Tool To Automatically Purge Old Trashed Files.md new file mode 100644 index 0000000000..a16e264dcb --- /dev/null +++ b/published/20180907 Autotrash - A CLI Tool To Automatically Purge Old Trashed Files.md @@ -0,0 +1,124 @@ +Autotrash:一个自动清除旧垃圾的命令行工具 +====== + +![](https://www.ostechnix.com/wp-content/uploads/2018/09/autotrash-720x340.png) + +**Autotrash** 是一个命令行程序,它用于自动清除旧的已删除文件。它将清除超过指定天数的在回收站中的文件。你不需要清空回收站或执行 `SHIFT+DELETE` 以永久清除文件/文件夹。Autortrash 将处理回收站中的内容,并在特定时间段后自动删除它们。简而言之,Autotrash 永远不会让你的垃圾变得太大。 + +### 安装 Autotrash + +Autotrash 默认存在于基于 Debian 系统的仓库中。要在 Debian、Ubuntu、Linux Mint 上安装 `autotrash`,请运行: + +``` +$ sudo apt-get install autotrash +``` + +在 Fedora 上: + +``` +$ sudo dnf install autotrash +``` + +对于 Arch linux 及其变体,你可以使用任何 AUR 助手程序, 如 [**Yay**][1] 安装它。 + +``` +$ yay -S autotrash-git +``` + +### 自动清除旧的垃圾文件 + +每当你运行 `autotrash` 时,它会扫描你的 `~/.local/share/Trash/info` 目录并读取 `.trashinfo` 以找出它们的删除日期。如果文件已在回收站中超过指定的日期,那么就会删除它们。 + +让我举几个例子。 + +要删除回收站中超过 30 天的文件,请运行: + +``` +$ autotrash -d 30 +``` + +如上例所示,如果回收站中的文件超过 30 天,Autotrash 会自动将其从回收站中删除。你无需手动删除它们。只需将没用的文件放到回收站即可忘记。Autotrash 将处理已删除的文件。 + +以上命令仅处理当前登录用户的垃圾目录。如果要使 autotrash 处理所有用户的垃圾目录(不仅仅是在你的家目录中),请使用 `-t` 选项,如下所示。 + +``` +$ autotrash -td 30 +``` + +Autotrash 还允许你根据回收站可用容量或磁盘可用空间来删除已删除的文件。 + +例如,看下下面的例子: + +``` +$ autotrash --max-free 1024 -d 30 +``` + +根据上面的命令,如果回收站的剩余的空间少于 **1GB**,那么 autotrash 将从回收站中清除超过 **30 天**的已删除文件。如果你的回收站空间不足,这可能很有用。 + +我们还可以从回收站中按最早的时间清除文件直到回收站至少有 1GB 的空间。 + +``` +$ autotrash --min-free 1024 +``` + +在这种情况下,对旧的已删除文件没有限制。 + +你可以将这两个选项(`--min-free` 和 `--max-free`)组合在一个命令中,如下所示。 + +``` +$ autotrash --max-free 2048 --min-free 1024 -d 30 +``` + +根据上面的命令,如果可用空间小于 **2GB**,`autotrash` 将读取回收站,接着关注容量。此时,删除超过 30 天的文件,如果少于 **1GB** 的可用空间,则删除更新的文件。 + +如你所见,所有命令都应由用户手动运行。你可能想知道,我该如何自动执行此任务?这很容易!只需将 `autotrash` 添加为 crontab 任务即可。现在,命令将在计划的时间自动运行,并根据定义的选项清除回收站中的文件。 + +要在 crontab 中添加这些命令,请运行: + +``` +$ crontab -e +``` + +添加任务,例如: + +``` +@daily /usr/bin/autotrash -d 30 +``` + +现在,autotrash 将每天清除回收站中超过 30 天的文件。 + +有关计划任务的更多详细信息,请参阅以下链接。 + ++ [Cron 任务的初学者指南]][2] ++ [如何在 Linux 中轻松安全地管理 Cron 作业]][3] + +请注意,如果你无意中删除了任何重要文件,它们将在规定的日期后永久消失,所以请小心。 + +请参阅手册页以了解有关 Autotrash 的更多信息。 + +``` +$ man autotrash +``` + +清空回收站或按 `SHIFT+DELETE` 永久删除 Linux 系统中没用的东西没什么大不了的。它只需要几秒钟。但是,如果你需要额外的程序来处理垃圾文件,Autotrash 可能会有所帮助。试一下,看看它是如何工作的。 + +就是这些了。希望这个有用。还有更多的好东西。 + +干杯! + + +-------------------------------------------------------------------------------- + +via: https://www.ostechnix.com/autotrash-a-cli-tool-to-automatically-purge-old-trashed-files/ + +作者:[SK][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[geekpi](https://github.com/geekpi) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://www.ostechnix.com/author/sk/ +[1]: https://www.ostechnix.com/yay-found-yet-another-reliable-aur-helper/ +[2]: https://www.ostechnix.com/a-beginners-guide-to-cron-jobs/ +[3]: https://www.ostechnix.com/how-to-easily-and-safely-manage-cron-jobs-in-linux/ diff --git a/published/20180907 What do open source and cooking have in common.md b/published/20180907 What do open source and cooking have in common.md new file mode 100644 index 0000000000..ae99bed725 --- /dev/null +++ b/published/20180907 What do open source and cooking have in common.md @@ -0,0 +1,74 @@ +开源与烹饪有什么相似之处? +====== + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/waffles-recipe-eggs-cooking-mix.png?itok=Fp06VOBx) + +有什么好的方法,既可以宣传开源的精神又不用写代码呢?这里有个点子:“开源食堂open source cooking”。在过去的 8 年间,这就是我们在慕尼黑做的事情。 + +开源食堂已经是我们常规的开源宣传活动了,因为我们发现开源与烹饪有很多共同点。 + +### 协作烹饪 + +[慕尼黑开源聚会][1]自 2009 年 7 月在 [Café Netzwerk][2] 创办以来,已经组织了若干次活动,活动一般在星期五的晚上组织。该聚会为开源项目工作者或者开源爱好者们提供了相互认识的方式。我们的信条是:“每四周的星期五属于自由软件Every fourth Friday for free software”。当然在一些周末,我们还会举办一些研讨会。那之后,我们很快加入了很多其他的活动,包括白香肠早餐、桑拿与烹饪活动。 + +事实上,第一次开源烹饪聚会举办的有些混乱,但是我们经过这 8 年来以及 15 次的活动,已经可以为 25-30 个与会者提供丰盛的美食了。 + +回头看看这些夜晚,我们愈发发现共同烹饪与开源社区协作之间,有很多相似之处。 + +### 烹饪步骤中的自由开源精神 + +这里是几个烹饪与开源精神相同的地方: + + * 我们乐于合作且朝着一个共同的目标前进 + * 我们成了一个社区 + * 由于我们有相同的兴趣与爱好,我们可以更多的了解我们自身与他人,并且可以一同协作 + * 我们也会犯错,但我们会从错误中学习,并为了共同的利益去分享关于错误的经验,从而让彼此避免再犯相同的错误 + * 每个人都会贡献自己擅长的事情,因为每个人都有自己的一技之长 + * 我们会动员其他人去做出贡献并加入到我们之中 + * 虽说协作是关键,但难免会有点混乱 + * 每个人都会从中收益 + +### 烹饪中的开源气息 + +同很多成功的开源聚会一样,开源烹饪也需要一些协作和组织结构。在每次活动之前,我们会组织所有的成员对菜单进行投票,而不单单是直接给每个人分一角披萨,我们希望真正的作出一道美味,迄今为止我们做过日本、墨西哥、匈牙利、印度等地区风味的美食,限于篇幅就不一一列举了。 + +就像在生活中,共同烹饪同样需要各个成员之间相互的尊重和理解,所以我们也会试着为素食主义者、食物过敏者、或者对某些事物有偏好的人提供针对性的事物。正式开始烹饪之前,在家预先进行些小规模的测试会非常有帮助(和乐趣!) + +可扩展性也很重要,在杂货店采购必要的食材很容易就消耗掉 3 个小时。所以我们使用一些表格工具(自然是 LibreOffice Calc)来做一些所需要的食材以及相应的成本。 + +我们会同志愿者一起,对于每次晚餐我们都有一个“包维护者”,从而及时的制作出菜单并在问题产生的时候寻找一些独到的解决方法。 + +虽然不是所有人都是大厨,但是只要给与一些帮助,并比较合理的分配任务和责任,就很容易让每个人都参与其中。某种程度上来说,处理 18kg 的西红柿和 100 个鸡蛋都不会让你觉得是件难事,相信我!唯一的限制是一个烤炉只有四个灶,所以可能是时候对基础设施加大投入了。 + +发布有时间要求,当然要求也不那么严格,我们通常会在 21:30 和 01:30 之间的相当“灵活”时间内供应主菜,即便如此,这个时间也是硬性的发布规定。 + +最后,像很多开源项目一样,烹饪文档同样有提升的空间。类似洗碟子这样的扫尾工作同样也有可优化的地方。 + +### 未来的一些新功能点 + +我们预计的一些想法包括: + + * 在其他的国家开展活动 + * 购买和烹饪一个价值 700 欧元的大南瓜,并且 + * 找家可以为我们采购提供折扣的商店 + +最后一点,也是开源软件的动机:永远记住,还有一些人们生活在阴影中,他们为没有同等的权限去访问资源而苦恼着。我们如何通过开源的精神去帮助他们呢? + +一想到这点,我便期待这下一次的开源烹饪聚会。如果读了上面的东西让你觉得不够完美,并且想自己运作这样的活动,我们非常乐意你能够借鉴我们的想法,甚至抄袭一个。我们也乐意你能够参与到我们其中,甚至做一些演讲和问答。 + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/9/open-source-cooking + +作者:[Florian Effenberger][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[sd886393](https://github.com/sd886393) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://opensource.com/users/floeff +[1]: https://www.opensourcetreffen.de/ +[2]: http://www.cafe-netzwerk.de/ +[3]: https://blog.effenberger.org/2018/05/28/what-do-open-source-and-cooking-have-in-common/ +[4]: https://en.wikipedia.org/wiki/Free_and_open-source_software diff --git a/published/20180909 What is ZFS- Why People Use ZFS- [Explained for Beginners].md b/published/20180909 What is ZFS- Why People Use ZFS- [Explained for Beginners].md new file mode 100644 index 0000000000..652ebd6c1d --- /dev/null +++ b/published/20180909 What is ZFS- Why People Use ZFS- [Explained for Beginners].md @@ -0,0 +1,115 @@ +初学者指南:ZFS 是什么,为什么要使用 ZFS? +====== + +![ZFS filesystem][9] + +今天,我们来谈论一下 ZFS,一个先进的文件系统。我们将讨论 ZFS 从何而来,它是什么,以及为什么它在科技界和企业界如此受欢迎。 + +虽然我是一个美国人,但我更喜欢读成 ZedFS 而不是 ZeeFS,因为前者听起来更酷一些。你可以根据你的个人喜好来发音。 + +> 注意:在这篇文章中,你将会看到 ZFS 被提到很多次。当我在谈论特性和安装的时候,我所指的是 OpenZFS 。自从甲骨文Oracle公司放弃 OpenSolaris 项目之后,ZFS(由甲骨文公司开发)和 OpenZFS 已经走向了不同的发展道路。(后面详述) + +### ZFS 的历史 + +Z 文件系统Z File System(ZFS)是由 [Matthew Ahrens 和 Jeff Bonwick][1] 在 2001 年开发的。ZFS 是作为[太阳微系统Sun MicroSystem][2] 公司的 [OpenSolaris][3] 的下一代文件系统而设计的。在 2008 年,ZFS 被移植到了 FreeBSD 。同一年,一个移植 [ZFS 到 Linux][4] 的项目也启动了。然而,由于 ZFS 是[通用开发和发布许可证][5]Common Development and Distribution License(CDDL)许可的,它和 [GNU 通用公共许可证][6] 不兼容,因此不能将它迁移到 Linux 内核中。为了解决这个问题,绝大多数 Linux 发行版提供了一些方法来安装 ZFS 。 + +在甲骨文公司收购太阳微系统公司之后不久,OpenSolaris 就闭源了,这使得 ZFS 的之后的开发也变成闭源的了。许多 ZFS 开发者对这件事情非常不满。[三分之二的 ZFS 核心开发者][1],包括 Ahrens 和 Bonwick,因为这个决定而离开了甲骨文公司。他们加入了其它公司,并于 2013 年 9 月创立了 [OpenZFS][7] 这一项目。该项目引领着 ZFS 的开源开发。 + +让我们回到上面提到的许可证问题上。既然 OpenZFS 项目已经和 Oracle 公司分离开了,有人可能好奇他们为什么不使用和 GPL 兼容的许可证,这样就可以把它加入到 Linux 内核中了。根据 [OpenZFS 官网][8] 的介绍,更改许可证需要联系所有为当前 OpenZFS 实现贡献过代码的人(包括初始的公共 ZFS 代码以及 OpenSolaris 代码),并得到他们的许可才行。这几乎是不可能的(因为一些贡献者可能已经去世了或者很难找到),因此他们决定保留原来的许可证。 + +### ZFS 是什么,它有什么特性? + +正如前面所说过的,ZFS 是一个先进的文件系统。因此,它有一些有趣的[特性][10]。比如: + + * 存储池 + * 写时拷贝 + * 快照 + * 数据完整性验证和自动修复 + * RAID-Z + * 最大单个文件大小为 16 EB(1 EB = 1024 PB) + * 最大 256 千万亿(256*10^15 )的 ZB(1 ZB = 1024 EB)的存储 + +让我们来深入了解一下其中一些特性。 + +#### 存储池 + +与大多数文件系统不同,ZFS 结合了文件系统和卷管理器的特性。这意味着,它与其他文件系统不同,ZFS 可以创建跨越一系列硬盘或池的文件系统。不仅如此,你还可以通过添加硬盘来增大池的存储容量。ZFS 可以进行[分区和格式化][11]。 + +![Pooled storage in ZFS][12] + +*ZFS 存储池* + +#### 写时拷贝 + +[写时拷贝][13]Copy-on-write是另一个有趣并且很酷的特性。在大多数文件系统上,当数据被重写时,它将永久丢失。而在 ZFS 中,新数据会写到不同的块。写完成之后,更新文件系统元数据信息,使之指向新的数据块(LCTT 译注:更新之后,原数据块成为磁盘上的垃圾,需要有对应的垃圾回收机制)。这确保了如果在写新数据的时候系统崩溃(或者发生其它事,比如突然断电),那么原数据将会保存下来。这也意味着,在系统发生崩溃之后,不需要运行 [fsck][14] 来检查和修复文件系统。 + +#### 快照 + +写时拷贝使得 ZFS 有了另一个特性:快照snapshots。ZFS 使用快照来跟踪文件系统中的更改。[快照][13]包含文件系统的原始版本(文件系统的一个只读版本),实时文件系统则包含了自从快照创建之后的任何更改。没有使用额外的空间。因为新数据将会写到实时文件系统新分配的块上。如果一个文件被删除了,那么它在快照中的索引也会被删除。所以,快照主要是用来跟踪文件的更改,而不是文件的增加和创建。 + +快照可以挂载成只读的,以用来恢复一个文件的过去版本。实时文件系统也可以回滚到之前的快照。回滚之后,自从快照创建之后的所有更改将会丢失。 + +#### 数据完整性验证和自动修复 + +当向 ZFS 写入新数据时,会创建该数据的校验和。在读取数据的时候,使用校验和进行验证。如果前后校验和不匹配,那么就说明检测到了错误,然后,ZFS 会尝试自动修正错误。 + +#### RAID-Z + +ZFS 不需要任何额外软件或硬件就可以处理 RAID(磁盘阵列)。毫不奇怪,因为 ZFS 有自己的 RAID 实现:RAID-Z 。RAID-Z 是 RAID-5 的一个变种,不过它克服了 RAID-5 的写漏洞:意外重启之后,数据和校验信息会变得不同步(LCTT 译注:RAID-5 的条带在正写入数据时,如果这时候电源中断,那么奇偶校验数据将跟该部分数据不同步,因此前边的写无效;RAID-Z 用了 “可变宽的 RAID 条带” 技术,因此所有的写都是全条带写入)。为了使用[基本级别的 RAID-Z][15](RAID-Z1),你需要至少三块磁盘,其中两块用来存储数据,另外一块用来存储[奇偶校验信息][16]。而 RAID-Z2 需要至少两块磁盘存储数据以及两块磁盘存储校验信息。RAID-Z3 需要至少两块磁盘存储数据以及三块磁盘存储校验信息。另外,只能向 RAID-Z 池中加入偶数倍的磁盘,而不能是奇数倍的。 + +#### 巨大的存储潜力 + +创建 ZFS 的时候,它是作为[最后一个文件系统][17]而设计的 。那时候,大多数文件系统都是 64 位的,ZFS 的创建者决定直接跳到 128 位,等到将来再来证明这是对的。这意味着 ZFS 的容量大小是 32 位或 64 位文件系统的 1600 亿亿倍。事实上,Jeff Bonwick(其中一个创建者)说:“完全填满一个 128 位的存储池所需要的[能量][18],从字面上讲,比煮沸海洋需要的还多。” + +### 如何安装 ZFS? + +如果你想立刻使用 ZFS(开箱即用),那么你需要安装 [FreeBSD][19] 或一个[使用 illumos 内核的操作系统][20]。[illumos][21] 是 OpenSolaris 内核的一个克隆版本。 + +事实上,支持 [ZFS 是一些有经验的 Linux 用户选择 BSD 的主要原因][22]。 + +如果你想在 Linux 上尝试 ZFS,那么只能在存储文件系统上使用。据我所知,没有任何 Linux 发行版可以在根目录上安装 ZFS,实现开箱即用。如果你对在 Linux 上尝试 ZFS 感兴趣,那么 [ZFS on Linux 项目][4] 上有大量的教程可以指导你怎么做。 + +### 附加说明 + +这篇文章论述了 ZFS 的优点。现在,让我来告诉你一个关于 ZFS 很现实的问题。使用 RAID-Z [会很贵][23],因为你需要购买大量的磁盘来增大存储空间。 + +你已经使用过 ZFS 了吗?你的使用经验是什么样的?请在下面的评论中告诉我们。 + +如果你觉得这篇文章有趣,请花一分钟的时间把它分享到社交媒体、极客新闻或 [Reddit][24] 。 + +-------------------------------------------------------------------------------- + +via: https://itsfoss.com/what-is-zfs/ + +作者:[John Paul][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[ucasFL](https://github.com/ucasFL) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://itsfoss.com/author/john/ +[1]: https://wiki.gentoo.org/wiki/ZFS +[2]: http://en.wikipedia.org/wiki/Sun_Microsystems +[3]: http://en.wikipedia.org/wiki/Opensolaris +[4]: https://zfsonlinux.org/ +[5]: https://en.wikipedia.org/wiki/Common_Development_and_Distribution_License +[6]: https://en.wikipedia.org/wiki/GNU_General_Public_License +[7]: http://www.open-zfs.org/wiki/Main_Page +[8]: http://www.open-zfs.org/wiki/FAQ#Do_you_plan_to_release_OpenZFS_under_a_license_other_than_the_CDDL.3F +[9]: https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/09/what-is-zfs.png +[10]: https://wiki.archlinux.org/index.php/ZFS +[11]: https://www.howtogeek.com/175159/an-introduction-to-the-z-file-system-zfs-for-linux/ +[12]: https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/09/zfs-overview.png +[13]: https://www.freebsd.org/doc/handbook/zfs-term.html +[14]: https://en.wikipedia.org/wiki/Fsck +[15]: https://wiki.archlinux.org/index.php/ZFS/Virtual_disks#Creating_and_Destroying_Zpools +[16]: https://www.pcmag.com/encyclopedia/term/60364/raid-parity +[17]: https://web.archive.org/web/20060428092023/http://www.sun.com/2004-0914/feature/ +[18]: https://blogs.oracle.com/bonwick/128-bit-storage:-are-you-high +[19]: https://www.freebsd.org/ +[20]: https://wiki.illumos.org/display/illumos/Distributions +[21]: https://wiki.illumos.org/display/illumos/illumos+Home +[22]: https://itsfoss.com/why-use-bsd/ +[23]: http://louwrentius.com/the-hidden-cost-of-using-zfs-for-your-home-nas.html +[24]: http://reddit.com/r/linuxusersgroup diff --git a/published/20180910 13 Keyboard Shortcut Every Ubuntu 18.04 User Should Know.md b/published/20180910 13 Keyboard Shortcut Every Ubuntu 18.04 User Should Know.md new file mode 100644 index 0000000000..461e586b2d --- /dev/null +++ b/published/20180910 13 Keyboard Shortcut Every Ubuntu 18.04 User Should Know.md @@ -0,0 +1,173 @@ +每位 Ubuntu 18.04 用户都应该知道的快捷键 +====== + +了解快捷键能够提升您的生产力。这里有一些实用的 Ubuntu 快捷键助您像专业人士一样使用 Ubuntu。 + +您可以用键盘和鼠标组合来使用操作系统。 + +> 注意:本文中提到的键盘快捷键适用于 Ubuntu 18.04 GNOME 版。 通常,它们中的大多数(或者全部)也适用于其他的 Ubuntu 版本,但我不能够保证。 + +![Ubuntu keyboard shortcuts][1] + +### 实用的 Ubuntu 快捷键 + +让我们来看一看 Ubuntu GNOME 必备的快捷键吧!通用的快捷键如 `Ctrl+C`(复制)、`Ctrl+V`(粘贴)或者 `Ctrl+S`(保存)不再赘述。 + +注意:Linux 中的 Super 键即键盘上带有 Windows 图标的键,本文中我使用了大写字母,但这不代表你需要按下 `shift` 键,比如,`T` 代表键盘上的 ‘t’ 键,而不代表 `Shift+t`。 + +#### 1、 Super 键:打开活动搜索界面 + +使用 `Super` 键可以打开活动菜单。如果你只能在 Ubuntu 上使用一个快捷键,那只能是 `Super` 键。 + +想要打开一个应用程序?按下 `Super` 键然后搜索应用程序。如果搜索的应用程序未安装,它会推荐来自应用中心的应用程序。 + +想要看看有哪些正在运行的程序?按下 `Super` 键,屏幕上就会显示所有正在运行的 GUI 应用程序。 + +想要使用工作区吗?只需按下 `Super` 键,您就可以在屏幕右侧看到工作区选项。 + +#### 2、 Ctrl+Alt+T:打开 Ubuntu 终端窗口 + +![Ubuntu Terminal Shortcut][2] + +*使用 Ctrl+alt+T 来打开终端窗口* + +想要打开一个新的终端,您只需使用快捷键 `Ctrl+Alt+T`。这是我在 Ubuntu 中最喜欢的键盘快捷键。 甚至在我的许多 FOSS 教程中,当需要打开终端窗口是,我都会提到这个快捷键。 + +#### 3、 Super+L 或 Ctrl+Alt+L:锁屏 + +当您离开电脑时锁定屏幕,是最基本的安全习惯之一。您可以使用 `Super+L` 快捷键,而不是繁琐地点击屏幕右上角然后选择锁定屏幕选项。 + +有些系统也会使用 `Ctrl+Alt+L` 键锁定屏幕。 + +#### 4、 Super+D or Ctrl+Alt+D:显示桌面 + +按下 `Super+D` 可以最小化所有正在运行的应用程序窗口并显示桌面。 + +再次按 `Super+D` 将重新打开所有正在运行的应用程序窗口,像之前一样。 + +您也可以使用 `Ctrl+Alt+D` 来实现此目的。 + +#### 5、 Super+A:显示应用程序菜单 + +您可以通过单击屏幕左下角的 9 个点打开 Ubuntu 18.04 GNOME 中的应用程序菜单。 但是一个更快捷的方法是使用 `Super+A` 快捷键。 + +它将显示应用程序菜单,您可以在其中查看或搜索系统上已安装的应用程序。 + +您可以使用 `Esc` 键退出应用程序菜单界面。 + +#### 6、 Super+Tab 或 Alt+Tab:在运行中的应用程序间切换 + +如果您运行的应用程序不止一个,则可以使用 `Super+Tab` 或 `Alt+Tab` 快捷键在应用程序之间切换。 + +按住 `Super` 键同时按下 `Tab` 键,即可显示应用程序切换器。 按住 `Super` 的同时,继续按下 `Tab` 键在应用程序之间进行选择。 当光标在所需的应用程序上时,松开 `Super` 和 `Tab` 键。 + +默认情况下,应用程序切换器从左向右移动。 如果要从右向左移动,可使用 `Super+Shift+Tab` 快捷键。 + +在这里您也可以用 `Alt` 键代替 `Super` 键。 + +> 提示:如果有多个应用程序实例,您可以使用 Super+` 快捷键在这些实例之间切换。 + +#### 7、 Super+箭头:移动窗口位置 + + + +这个快捷键也适用于 Windows 系统。 使用应用程序时,按下 `Super+左箭头`,应用程序将贴合屏幕的左边缘,占用屏幕的左半边。 + +同样,按下 `Super+右箭头`会使应用程序贴合右边缘。 + +按下 `Super+上箭头`将最大化应用程序窗口,`Super+下箭头`将使应用程序恢复到其正常的大小。 + +#### 8、 Super+M:切换到通知栏 + +GNOME 中有一个通知栏,您可以在其中查看系统和应用程序活动的通知,这里也有一个日历。 + +![Notification Tray Ubuntu 18.04 GNOME][3] + +*通知栏* + +使用 `Super+M` 快捷键,您可以打开此通知栏。 如果再次按这些键,将关闭打开的通知托盘。 + +使用 `Super+V` 也可实现相同的功能。 + +#### 9、 Super+空格:切换输入法(用于多语言设置) + +如果您使用多种语言,可能您的系统上安装了多个输入法。 例如,我需要在 Ubuntu 上同时使用[印地语] [4]和英语,所以我安装了印地语(梵文)输入法以及默认的英语输入法。 + +如果您也使用多语言设置,则可以使用 `Super+空格` 快捷键快速更改输入法。 + +#### 10、 Alt+F2:运行控制台 + +这适用于高级用户。 如果要运行快速命令,而不是打开终端并在其中运行命令,则可以使用 `Alt+F2` 运行控制台。 + +![Alt+F2 to run commands in Ubuntu][5] + +*控制台* + +当您使用只能在终端运行的应用程序时,这尤其有用。 + +#### 11、 Ctrl+Q:关闭应用程序窗口 + +如果您有正在运行的应用程序,可以使用 `Ctrl+Q` 快捷键关闭应用程序窗口。您也可以使用 `Ctrl+W` 来实现此目的。 + +`Alt+F4` 是关闭应用程序窗口更“通用”的快捷方式。 + +它不适用于一些应用程序,如 Ubuntu 中的默认终端。 + +#### 12、 Ctrl+Alt+箭头:切换工作区 + +![Workspace switching][6] + +*切换工作区* + +如果您是使用工作区的重度用户,可以使用 `Ctrl+Alt+上箭头`和 `Ctrl+Alt+下箭头`在工作区之间切换。 + +#### 13、 Ctrl+Alt+Del:注销 + +不!在 Linux 中使用著名的快捷键 `Ctrl+Alt+Del` 并不会像在 Windows 中一样打开任务管理器(除非您使用自定义快捷键)。 + +![Log Out Ubuntu][7] + +*注销* + +在普通的 GNOME 桌面环境中,您可以使用 `Ctrl+Alt+Del` 键打开关机菜单,但 Ubuntu 并不总是遵循此规范,因此当您在 Ubuntu 中使用 `Ctrl+Alt+Del` 键时,它会打开注销菜单。 + +### 在 Ubuntu 中使用自定义键盘快捷键 + +您不是只能使用默认的键盘快捷键,您可以根据需要创建自己的自定义键盘快捷键。 + +转到“设置->设备->键盘”,您将在这里看到系统的所有键盘快捷键。向下滚动到底部,您将看到“自定义快捷方式”选项。 + +![Add custom keyboard shortcut in Ubuntu][8] + +您需要提供易于识别的快捷键名称、使用快捷键时运行的命令,以及您自定义的按键组合。 + +### Ubuntu 中你最喜欢的键盘快捷键是什么? + +快捷键无穷无尽。如果需要,你可以看一看所有可能的 [GNOME 快捷键][9],看其中有没有你需要用到的快捷键。 + +您可以学习使用您经常使用应用程序的快捷键,这是很有必要的。例如,我使用 Kazam 进行[屏幕录制][10],键盘快捷键帮助我方便地暂停和开始录像。 + +您最喜欢、最离不开的 Ubuntu 快捷键是什么? + +-------------------------------------------------------------------------------- + +via: https://itsfoss.com/ubuntu-shortcuts/ + +作者:[Abhishek Prakash][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[XiatianSummer](https://github.com/XiatianSummer) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://itsfoss.com/author/abhishek/ +[1]: https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/09/ubuntu-keyboard-shortcuts.jpeg +[2]: https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/09/ubuntu-terminal-shortcut.jpg +[3]: https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/09/notification-tray-ubuntu-gnome.jpeg +[4]: https://itsfoss.com/type-indian-languages-ubuntu/ +[5]: https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/09/console-alt-f2-ubuntu-gnome.jpeg +[6]: https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/09/workspace-switcher-ubuntu.png +[7]: https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/09/log-out-ubuntu.jpeg +[8]: https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/09/custom-keyboard-shortcut.jpg +[9]: https://wiki.gnome.org/Design/OS/KeyboardShortcuts +[10]: https://itsfoss.com/best-linux-screen-recorders/ diff --git a/published/20180910 3 open source log aggregation tools.md b/published/20180910 3 open source log aggregation tools.md new file mode 100644 index 0000000000..0bad973eba --- /dev/null +++ b/published/20180910 3 open source log aggregation tools.md @@ -0,0 +1,110 @@ +3 个开源日志聚合工具 +====== + +> 日志聚合系统可以帮助我们进行故障排除和其它任务。以下是三个主要工具介绍。 + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/data_metrics_analytics_desktop_laptop.png?itok=9QXd7AUr) + +指标聚合metrics aggregation日志聚合log aggregation有何不同?日志不能包括指标吗?日志聚合系统不能做与指标聚合系统相同的事情吗? + +这些是我经常听到的问题。我还看到供应商推销他们的日志聚合系统作为所有可观察问题的解决方案。日志聚合是一个有价值的工具,但它通常对时间序列数据的支持不够好。 + +时间序列的指标聚合系统中几个有价值的功能是专门为时间序列数据定制的固定间隔regular interval和存储系统。固定间隔允许用户不断地收集实时的数据结果。如果要求日志聚合系统以固定间隔收集指标数据,它也可以。但是,它的存储系统没有针对指标聚合系统中典型的查询类型进行优化。使用日志聚合工具中的存储系统处理这些查询将花费更多的资源和时间。 + +所以,我们知道日志聚合系统可能不适合时间序列数据,但是它有什么好处呢?日志聚合系统是收集事件数据的好地方。这些无规律的活动是非常重要的。最好的例子为 web 服务的访问日志,这些很重要,因为我们想知道什么正在访问我们的系统,什么时候访问的。另一个例子是应用程序错误记录 —— 因为它不是正常的操作记录,所以在故障排除过程中可能很有价值的。 + +日志记录的一些规则: + + * **须**包含时间戳 + * **须**格式化为 JSON + * **不**记录无关紧要的事件 + * **须**记录所有应用程序的错误 + * **可**记录警告错误 + * **可**开关的日志记录 + * **须**以可读的形式记录信息 + * **不**在生产环境中记录信息 + * **不**记录任何无法阅读或反馈的内容 + +### 云的成本 + +当研究日志聚合工具时,云服务可能看起来是一个有吸引力的选择。然而,这可能会带来巨大的成本。当跨数百或数千台主机和应用程序聚合时,日志数据是大量的。在基于云的系统中,数据的接收、存储和检索是昂贵的。 + +以一个真实的系统来参考,大约 500 个节点和几百个应用程序的集合每天产生 200GB 的日志数据。这个系统可能还有改进的空间,但是在许多 SaaS 产品中,即使将它减少一半,每月也要花费将近 10000 美元。而这通常仅保留 30 天,如果你想查看一年一年的趋势数据,就不可能了。 + +并不是要不使用这些基于云的系统,尤其是对于较小的组织它们可能非常有价值的。这里的目的是指出可能会有很大的成本,当这些成本很高时,就可能令人非常的沮丧。本文的其余部分将集中讨论自托管的开源和商业解决方案。 + +### 工具选择 + +#### ELK + +[ELK][1],即 Elasticsearch、Logstash 和 Kibana 简称,是最流行的开源日志聚合工具。它被 Netflix、Facebook、微软、LinkedIn 和思科使用。这三个组件都是由 [Elastic][2] 开发和维护的。[Elasticsearch][3] 本质上是一个 NoSQL 数据库,以 Lucene 搜索引擎实现的。[Logstash][4] 是一个日志管道系统,可以接收数据,转换数据,并将其加载到像 Elasticsearch 这样的应用中。[Kibana][5] 是 Elasticsearch 之上的可视化层。 + +几年前,引入了 Beats 。Beats 是数据采集器。它们简化了将数据运送到 Logstash 的过程。用户不需要了解每种日志的正确语法,而是可以安装一个 Beats 来正确导出 NGINX 日志或 Envoy 代理日志,以便在 Elasticsearch 中有效地使用它们。 + +安装生产环境级 ELK 套件时,可能会包括其他几个部分,如 [Kafka][6]、[Redis][7] 和 [NGINX][8]。此外,用 Fluentd 替换 Logstash 也很常见,我们将在后面讨论。这个系统操作起来很复杂,这在早期导致了很多问题和抱怨。目前,这些问题基本上已经被修复,不过它仍然是一个复杂的系统,如果你使用少部分的功能,建议不要使用它了。 + +也就是说,有其它可用的服务,所以你不必苦恼于此。可以使用 [Logz.io][9],但是如果你有很多数据,它的标价有点高。当然,你可能规模比较小,没有很多数据。如果你买不起 Logz.io,你可以看看 [AWS Elasticsearch Service][10] (ES) 。ES 是 Amazon Web Services (AWS) 提供的一项服务,它很容易就可以让 Elasticsearch 马上工作起来。它还拥有使用 Lambda 和 S3 将所有AWS 日志记录到 ES 的工具。这是一个更便宜的选择,但是需要一些管理操作,并有一些功能限制。 + +ELK 套件的母公司 Elastic [提供][11] 一款更强大的产品,它使用开源核心open core模式,为分析工具和报告提供了额外的选项。它也可以在谷歌云平台或 AWS 上托管。由于这种工具和托管平台的组合提供了比大多数 SaaS 选项更加便宜,这也许是最好的选择,并且很有用。该系统可以有效地取代或提供 [安全信息和事件管理][12](SIEM)系统的功能。 + +ELK 套件通过 Kibana 提供了很好的可视化工具,但是它缺少警报功能。Elastic 在付费的 X-Pack 插件中提供了警报功能,但是在开源系统没有内置任何功能。Yelp 已经开发了一种解决这个问题的方法,[ElastAlert][13],不过还有其他方式。这个额外的软件相当健壮,但是它增加了已经复杂的系统的复杂性。 + +#### Graylog + +[Graylog][14] 最近越来越受欢迎,但它是在 2010 年由 Lennart Koopmann 创建并开发的。两年后,一家公司以同样的名字诞生了。尽管它的使用者越来越多,但仍然远远落后于 ELK 套件。这也意味着它具有较少的社区开发特征,但是它可以使用与 ELK 套件相同的 Beats 。由于 Graylog Collector Sidecar 使用 [Go][15] 编写,所以 Graylog 在 Go 社区赢得了赞誉。 + +Graylog 使用 Elasticsearch、[MongoDB][16] 和底层的 Graylog Server 。这使得它像 ELK 套件一样复杂,也许还要复杂一些。然而,Graylog 附带了内置于开源版本中的报警功能,以及其他一些值得注意的功能,如流、消息重写和地理定位。 + +流功能可以允许数据在被处理时被实时路由到特定的 Stream。使用此功能,用户可以在单个 Stream 中看到所有数据库错误,在另外的 Stream 中看到 web 服务器错误。当添加新项目或超过阈值时,甚至可以基于这些 Stream 提供警报。延迟可能是日志聚合系统中最大的问题之一,Stream 消除了 Graylog 中的这一问题。一旦日志进入,它就可以通过 Stream 路由到其他系统,而无需完全处理好。 + +消息重写功能使用开源规则引擎 [Drools][17] 。允许根据用户定义的规则文件评估所有传入的消息,从而可以删除消息(称为黑名单)、添加或删除字段或修改消息。 + +Graylog 最酷的功能或许是它的地理定位功能,它支持在地图上绘制 IP 地址。这是一个相当常见的功能,在 Kibana 也可以这样使用,但是它增加了很多价值 —— 特别是如果你想将它用作 SIEM 系统。地理定位功能在系统的开源版本中提供。 + +如果你需要的话,Graylog 公司会提供对开源版本的收费支持。它还为其企业版提供了一个开源核心模式,提供存档、审计日志记录和其他支持。其它提供支持或托管服务的不太多,如果你不需要 Graylog 公司的,你可以托管。 + +#### Fluentd + +[Fluentd][18] 是 [Treasure Data][19] 开发的,[CNCF][20] 已经将它作为一个孵化项目。它是用 C 和 Ruby 编写的,并被 [AWS][21] 和 [Google Cloud][22] 所推荐。Fluentd 已经成为许多系统中 logstach 的常用替代品。它可以作为一个本地聚合器,收集所有节点日志并将其发送到中央存储系统。它不是日志聚合系统。 + +它使用一个强大的插件系统,提供不同数据源和数据输出的快速和简单的集成功能。因为有超过 500 个插件可用,所以你的大多数用例都应该包括在内。如果没有,这听起来是一个为开源社区做出贡献的机会。 + +Fluentd 由于占用内存少(只有几十兆字节)和高吞吐量特性,是 Kubernetes 环境中的常见选择。在像 [Kubernetes][23] 这样的环境中,每个 pod 都有一个 Fluentd 附属件 ,内存消耗会随着每个新 pod 的创建而线性增加。在这种情况下,使用 Fluentd 将大大降低你的系统利用率。这对于 Java 开发的工具来说是一个常见的问题,这些工具旨在为每个节点运行一个工具,而内存开销并不是主要问题。 + + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/9/open-source-log-aggregation-tools + +作者:[Dan Barker][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[heguangzhi](https://github.com/heguangzhi) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://opensource.com/users/barkerd427 +[1]: https://www.elastic.co/webinars/introduction-elk-stack +[2]: https://www.elastic.co/ +[3]: https://www.elastic.co/products/elasticsearch +[4]: https://www.elastic.co/products/logstash +[5]: https://www.elastic.co/products/kibana +[6]: http://kafka.apache.org/ +[7]: https://redis.io/ +[8]: https://www.nginx.com/ +[9]: https://logz.io/ +[10]: https://aws.amazon.com/elasticsearch-service/ +[11]: https://www.elastic.co/cloud +[12]: https://en.wikipedia.org/wiki/Security_information_and_event_management +[13]: https://github.com/Yelp/elastalert +[14]: https://www.graylog.org/ +[15]: https://opensource.com/tags/go +[16]: https://www.mongodb.com/ +[17]: https://www.drools.org/ +[18]: https://www.fluentd.org/ +[19]: https://www.treasuredata.com/ +[20]: https://www.cncf.io/ +[21]: https://aws.amazon.com/blogs/aws/all-your-data-fluentd/ +[22]: https://cloud.google.com/logging/docs/agent/ +[23]: https://opensource.com/resources/what-is-kubernetes + diff --git a/published/20180910 Randomize your MAC address using NetworkManager.md b/published/20180910 Randomize your MAC address using NetworkManager.md new file mode 100644 index 0000000000..54485e6ca4 --- /dev/null +++ b/published/20180910 Randomize your MAC address using NetworkManager.md @@ -0,0 +1,103 @@ +使用 NetworkManager 随机化你的 MAC 地址 +====== + +![](https://fedoramagazine.org/wp-content/uploads/2018/09/randomizemacaddress-816x345.png) + +今时今日,无论在家里的沙发上,还是在外面的咖啡厅,只要打开笔记本电脑,连上 Wi-Fi,就能通过网络与外界保持联系。但现在的 Wi-Fi 热点们大都能够通过[每张网卡对应的唯一 MAC 地址][1]来追踪你的设备。下面就来看一下如何避免被追踪。 + +现在很多人已经开始注重个人隐私这个问题。个人隐私问题并不仅仅指防止他人能够访问到你电脑上的私有内容(这又是另一个问题了),而更多的是指可追踪性legibility,也就是是否能够被轻易地统计和追踪到。大家都应该[对此更加重视][2]。同时,这方面的底线是,服务提供者在得到了用户的授权后才能对用户进行追踪,例如机场的计时 Wi-Fi 只有在用户授权后才能够使用。 + +因为固定的 MAC 地址能被轻易地追踪到,所以应该定时进行更换,随机的 MAC 地址是一个好的选择。由于 MAC 地址一般只在局域网内使用,因此随机的 MAC 地址也不大会产生[冲突][3]。 + +### 配置 NetworkManager + +要将随机的 MAC 地址默认地用于所有的 Wi-Fi 连接,需要创建 `/etc/NetworkManager/conf.d/00-macrandomize.conf` 这个文件: + +``` +[device] +wifi.scan-rand-mac-address=yes + +[connection] +wifi.cloned-mac-address=stable +ethernet.cloned-mac-address=stable +connection.stable-id=${CONNECTION}/${BOOT} +``` + +然后重启 NetworkManager : + +``` +systemctl restart NetworkManager +``` + +以上配置文件中,将 `cloned-mac-address` 的值设置为 `stable` 就可以在每次 NetworkManager 激活连接的时候都生成相同的 MAC 地址,但连接时使用不同的 MAC 地址。如果要在每次激活连接时也获得随机的 MAC 地址,需要将 `cloned-mac-address` 的值设置为 `random`。 + +设置为 `stable` 可以从 DHCP 获取相同的 IP 地址,也可以让 Wi-Fi 的[强制主页](https://en.wikipedia.org/wiki/Captive_portal)captive portal根据 MAC 地址记住你的登录状态。如果设置为 `random` ,在每次连接的时候都需要重新认证(或者点击“我同意”),在使用机场 Wi-Fi 的时候会需要到这种 `random` 模式。可以在这篇 NetworkManager 的[博客文章][4]中参阅到有关使用 `nmcli` 从终端配置特定连接的详细说明。 + +使用 `ip link` 命令可以查看当前的 MAC 地址,MAC 地址将会显示在 `ether` 一词的后面。 + +``` +$ ip link +1: lo: mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000 + link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 +2: enp2s0: mtu 1500 qdisc fq_codel state DOWN mode DEFAULT group default qlen 1000 + link/ether 52:54:00:5f:d5:4e brd ff:ff:ff:ff:ff:ff +3: wlp1s0: mtu 1500 qdisc mq state UP mode DORMANT group default qlen 1000 + link/ether 52:54:00:03:23:59 brd ff:ff:ff:ff:ff:ff +``` + +### 什么时候不能随机化 MAC 地址 + +当然,在某些情况下确实需要能被追踪到。例如在家用网络中,可能需要将路由器配置为对电脑分配一致的 IP 地址以进行端口转发;再例如公司的雇主可能需要根据 MAC 地址来提供 Wi-Fi 服务,这时候就需要进行追踪。要更改特定的 Wi-Fi 连接,请使用 `nmcli` 查看 NetworkManager 连接并显示当前设置: + +``` +$ nmcli c | grep wifi +Amtrak_WiFi 5f4b9f75-9e41-47f8-8bac-25dae779cd87 wifi -- +StaplesHotspot de57940c-32c2-468b-8f96-0a3b9a9b0a5e wifi -- +MyHome e8c79829-1848-4563-8e44-466e14a3223d wifi wlp1s0 +... +$ nmcli c show 5f4b9f75-9e41-47f8-8bac-25dae779cd87 | grep cloned +802-11-wireless.cloned-mac-address: -- +$ nmcli c show e8c79829-1848-4563-8e44-466e14a3223d | grep cloned +802-11-wireless.cloned-mac-address: stable +``` + +这个例子在 Amtrak 使用完全随机 MAC 地址(使用默认配置)和 MyHome 的永久 MAC 地址(使用 `stable` 配置)。永久 MAC 地址是在硬件生产的时候分配到网络接口上的,网络管理员能够根据永久 MAC 地址来查看[设备的制造商 ID][5]。 + +更改配置并重新连接活动的接口: + +``` +$ nmcli c modify 5f4b9f75-9e41-47f8-8bac-25dae779cd87 802-11-wireless.cloned-mac-address random +$ nmcli c modify e8c79829-1848-4563-8e44-466e14a3223d 802-11-wireless.cloned-mac-address permanent +$ nmcli c down e8c79829-1848-4563-8e44-466e14a3223d +$ nmcli c up e8c79829-1848-4563-8e44-466e14a3223d +$ ip link +... +``` + +你还可以安装 NetworkManager-tui ,就可以通过可视化界面菜单来编辑连接。 + +### 总结 + +当你走在路上时,你要[留意周围的环境][6],并[警惕可能的危险][7]。同样,在使用公共互联网资源时也要注意你自己的可追踪性。 + +-------------------------------------------------------------------------------- + +via: https://fedoramagazine.org/randomize-mac-address-nm/ + +作者:[sheogorath][a],[Stuart D Gathman][b] +选题:[lujun9972](https://github.com/lujun9972) +译者:[HankChow](https://github.com/HankChow) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://fedoramagazine.org/author/sheogorath/ +[b]: https://fedoramagazine.org/author/sdgathman/ +[1]: https://en.wikipedia.org/wiki/MAC_address +[2]: https://www.ribbonfarm.com/2010/07/26/a-big-little-idea-called-legibility/ +[3]: https://serverfault.com/questions/462178/duplicate-mac-address-on-the-same-lan-possible +[4]: https://blogs.gnome.org/thaller/2016/08/26/mac-address-spoofing-in-networkmanager-1-4-0/ +[5]: https://www.wireshark.org/tools/oui-lookup.html +[6]: https://www.isba.org/committees/governmentlawyers/newsletter/2013/06/becomingmoreawareafewtipsonkeepingy +[7]: http://www.selectinternational.com/safety-blog/aware-of-surroundings-can-reduce-safety-incidents + diff --git a/published/20180911 Visualize Disk Usage On Your Linux System.md b/published/20180911 Visualize Disk Usage On Your Linux System.md new file mode 100644 index 0000000000..4e92b49723 --- /dev/null +++ b/published/20180911 Visualize Disk Usage On Your Linux System.md @@ -0,0 +1,99 @@ +Filelight:可视化查看 Linux 系统上的磁盘使用情况 +====== + +![](https://www.ostechnix.com/wp-content/uploads/2018/09/filelight-720x340.png) + +查看硬盘使用情况对于类 Unix 操作系统来说不是什么大问题。我们有一个名为 [du][1] 的内置命令,可以在几分钟之内计算和汇总磁盘空间的使用情况。此外,我们还有一些第三方工具,比如 [Ncdu][2] 和 [Agedu][3],它们也可以用来追踪磁盘使用情况。如您所见,这些都是命令行中的实用程序,磁盘使用情况将以纯文本的形式显示。但是,有些人希望以可视化、图表的形式查看结果。别担心!我知道一个 GUI 工具可以显示磁盘使用细节。它就是 “**Filelight**”,这是一个图形化实用程序,用于可视化显示 Linux 系统上的磁盘使用情况,并以彩色径向图显示结果。Filelight 是历史最悠久的项目之一,它已经存在了很长时间,它完全免费使用并开源。 + +### 安装 Filelight + +Filelight 是 KDE 应用程序的一部分,并预装在基于 KDE 的 Linux 发行版上。 + +如果您使用的是非 KDE 发行版,官方存储库中包含了 Filelight,因此您可以使用默认的包管理器进行安装。 + +在 Arch Linux 及其衍生版,如 Antergos、Manjaro Linux 中,Filelight 可以按照如下方法安装。 + +``` +$ sudo pacman -S filelight +``` + +在 Debian、Ubuntu、Linux Mint 中, + +``` +$ sudo apt install filelight +``` + +在 Fedora 中, + +``` +$ sudo dnf install filelight +``` + +在 openSUSE 中, + +``` +$ sudo zypper install filelight +``` + +### 可视化查看 Linux 系统上的磁盘使用情况 + +安装后,从菜单或应用程序启动器启动 Filelight。 + +Filelight 以图形方式将您的文件系统表示为一组同心圆环段。 + +![](https://www.ostechnix.com/wp-content/uploads/2018/09/filelight-1-1.png) + +如您所见,Filelight 默认显示磁盘中 `/` 和 `/boot` 文件系统的使用情况。 + +您还可以选择扫描的各个文件夹,以查看该特定文件夹的磁盘使用情况。为此,请到 “Filelight -> Scan -> Scan Folder” 并选择要扫描的文件夹。 + +Filelight 在扫描时排除以下目录: + + * `/dev` + * `/proc` + * `/sys` + * `/root` + +此选项有助于跳过您可能没有权限读取的目录,或者属于虚拟文件系统的文件夹,例如 `/proc`。 + +如果您想要在此列表中增加文件夹,请到 “Filelight -> Settings -> Scanning” 并点击 “Add” 按钮然后选择您想要增加的文件夹。 + +![](http://www.ostechnix.com/wp-content/uploads/2018/09/filelight-settings.png) + +类似的,要想从此列表中移除某个文件夹,选择文件夹并点击 “Remove”。 + +如果您想要改变 Filelight 的外观,请到 “Settings - > Appearance” 栏,按照您的喜好改变配色方案。 + +径向图中的每个段用不同的颜色表示。下图显示了 `/` 文件系统的整个径向布局。要查看文件和文件夹的完整信息,只需将鼠标指针悬停在它们上边。 + +![](https://www.ostechnix.com/wp-content/uploads/2018/09/filelight-2.png) + +只需点击相应的段即可浏览文件系统。要查看某个文件或文件夹的磁盘使用情况,只需单击它们即可获得该特定文件夹、文件的完整磁盘使用情况。 + +不仅仅是本地文件系统,Filelight 还能够扫描远程磁盘和可移动磁盘。 如果您使用任何基于 KDE 的 Linux 发行版,它可以集成到 Konqueror、Dolphin 和 Krusader 等文件管理器中。 + +与 CLI 实用程序不同,您不必使用任何额外的参数或选项来以易读的(而非乱码的)格式查看结果。 默认情况下,Filelight 将自动以易读的格式显示磁盘使用情况。 + +### 总结 + +使用 Filelight,您可以快速找到文件系统中占用磁盘空间的位置,并通过删除不需要的文件或文件夹释放空间。 如果您正在寻找一些简单且易上手的图形界面磁盘使用情况查看器,那么 Filelight 值得一试。 + +就是这样。希望这篇文章对您有用。更多的好文章,敬请关注! + +干杯! + +-------------------------------------------------------------------------------- + +via: https://www.ostechnix.com/filelight-visualize-disk-usage-on-your-linux-system/ + +作者:[SK][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[XiatianSummer](https://github.com/XiatianSummer) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://www.ostechnix.com/author/sk/ +[1]: https://www.ostechnix.com/find-size-directory-linux/ +[2]: https://www.ostechnix.com/check-disk-space-usage-linux-using-ncdu/ +[3]: https://www.ostechnix.com/agedu-find-out-wasted-disk-space-in-linux/ diff --git a/published/20180912 How To Configure Mouse Support For Linux Virtual Consoles.md b/published/20180912 How To Configure Mouse Support For Linux Virtual Consoles.md new file mode 100644 index 0000000000..64052c2714 --- /dev/null +++ b/published/20180912 How To Configure Mouse Support For Linux Virtual Consoles.md @@ -0,0 +1,115 @@ +如何为 Linux 虚拟控制台配置鼠标支持 +====== + +![](https://www.ostechnix.com/wp-content/uploads/2018/09/GPM-1-720x340.png) + +我使用 Oracle VirtualBox 来测试各种类 Unix 操作系统。我的大多数虚拟机都是无头headless服务器,它们没有图形桌面环境。很长一段时间,我一直想知道如何在无头 Linux 服务器的基于文本的终端中使用鼠标。感谢 **GPM**,今天我了解到我们可以在虚拟控制台中使用鼠标进行复制和粘贴操作。 **GPM**,是通用鼠标General Purpose Mouse的首字母缩写,它是一个守护程序,可以帮助你配置 Linux 虚拟控制台的鼠标支持。请不要将 GPM 与 **GDM**(GNOME 显示管理器GNOME Display manager)混淆。两者有完全不同的用途。 + +GPM 在以下场景中特别有用: + + * 新的 Linux 服务器安装或默认情况下不能或不使用 X Windows 的系统,如 Arch Linux 和 Gentoo。 + * 在虚拟终端/控制台中使用复制/粘贴操作。 + * 在基于文本的编辑器和浏览器中使用复制/粘贴(例如,emacs、lynx)。 + * 在文本文件管理器中使用复制/粘贴(例如 Ranger、Midnight commander)。 + +在这个简短的教程中,我们将看到如何在类 Unix 操作系统中在基于文本的终端中使用鼠标。 + +### 安装 GPM + +要在纯文本 Linux 系统中启用鼠标支持,请安装 GPM 包。它在大多数 Linux 发行版的默认仓库中都有。 + +在 Arch Linux 及其变体如 Antergos、Manjaro Linux 上,运行以下命令来安装 GPM: + +``` +$ sudo pacman -S gpm +``` + +在 Debian、Ubuntu、Linux Mint 中: + +``` +$ sudo apt install gpm +``` + +在 Fedora 上: + +``` +$ sudo dnf install gpm +``` + +在 openSUSE 上: + +``` +$ sudo zypper install gpm +``` + +安装后,使用以下命令启用并启动 GPM 服务: + +``` +$ sudo systemctl enable gpm +$ sudo systemctl start gpm +``` + +在基于 Debian 的系统中,gpm 服务将在你安装后自动启动,因此你无需如上所示手动启动服务。 + +### 为 Linux 虚拟控制台配置鼠标支持 + +无需特殊配置。GPM 将在你安装并启动 gpm 服务后立即开始工作。 + +在安装 GPM 之前,看下我的 Ubuntu 18.04 LTS 服务器的屏幕截图: + +![](https://www.ostechnix.com/wp-content/uploads/2018/09/Ubuntu-18.04-CLI.png) + +正如你在上面的截图中看到的,我的 Ubuntu 18.04 LTS 无头服务器中没有可见的鼠标指针。只有一个闪烁的光标,它不能让我选择文本,使用鼠标复制/粘贴文本。在仅限 CLI 的 Linux 服务器中,鼠标根本没用。 + +在安装 GPM 后查看 Ubuntu 18.04 LTS 服务器的以下截图: + +![](https://www.ostechnix.com/wp-content/uploads/2018/09/GPM.png) + +看见了吗?我现在可以选择文字了。 + +要选择,复制和粘贴文本,请执行以下操作: + + * 要选择文本,请按下鼠标左键并拖动鼠标。 + * 选择文本后,放开鼠标左键,并按下中键在同一个或另一个控制台中粘贴文本。 + * 右键用于扩展选择,就像在 `xterm` 中。 + * 如果你使用的是双键鼠标,请使用右键粘贴文本。 + +就这么简单! + +就像我已经说过的那样,GPM 工作得很好,并且不需要额外的配置。以下是 GPM 配置文件 `/etc/gpm.conf`(或在某些发行版中是 `/etc/conf.d/gpm`)的示例内容: + +``` +# protected from evaluation (i.e. by quoting them). +# +# This file is used by /etc/init.d/gpm and can be modified by +# "dpkg-reconfigure gpm" or by hand at your option. +# +device=/dev/input/mice +responsiveness= +repeat_type=none +type=exps2 +append='' +sample_rate= +``` + +在我的例子中,我使用 USB 鼠标。如果你使用的是其他鼠标,则可能需要更改 `device=/dev/input/mice` 和 `type=exps2` 参数的值。 + +有关更多详细信息,请参阅手册页。 + +``` +$ man gpm +``` + +就是这些了。希望这个有用。还有更多的好东西。敬请期待! + +干杯! + +-------------------------------------------------------------------------------- + +via: https://www.ostechnix.com/how-to-configure-mouse-support-for-linux-virtual-consoles/ + +作者:[SK][a] 
选题:[lujun9972](https://github.com/lujun9972) 
译者:[geekpi](https://github.com/geekpi) 
校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://www.ostechnix.com/author/sk/ diff --git a/published/20180917 Linux tricks that can save you time and trouble.md b/published/20180917 Linux tricks that can save you time and trouble.md new file mode 100644 index 0000000000..6c9f3d3247 --- /dev/null +++ b/published/20180917 Linux tricks that can save you time and trouble.md @@ -0,0 +1,169 @@ +让你提高效率的 Linux 技巧 +====== + +> 想要在 Linux 命令行工作中提高效率,你需要使用一些技巧。 + +![](https://images.idgesg.net/images/article/2018/09/boy-jumping-off-swing-100772498-large.jpg) + +巧妙的 Linux 命令行技巧能让你节省时间、避免出错,还能让你记住和复用各种复杂的命令,专注在需要做的事情本身,而不是你要怎么做。以下介绍一些好用的命令行技巧。 + +### 命令编辑 + +如果要对一个已输入的命令进行修改,可以使用 `^a`(`ctrl + a`)或 `^e`(`ctrl + e`)将光标快速移动到命令的开头或命令的末尾。 + +还可以使用 `^` 字符实现对上一个命令的文本替换并重新执行命令,例如 `^before^after^` 相当于把上一个命令中的 `before` 替换为 `after` 然后重新执行一次。 + +``` +$ eho hello world <== 错误的命令 + +Command 'eho' not found, did you mean: + + command 'echo' from deb coreutils + command 'who' from deb coreutils + +Try: sudo apt install + +$ ^e^ec^ <== 替换 +echo hello world +hello world + +``` + +### 使用远程机器的名称登录到机器上 + +如果使用命令行登录其它机器上,可以考虑添加别名。在别名中,可以填入需要登录的用户名(与本地系统上的用户名可能相同,也可能不同)以及远程机器的登录信息。例如使用 `server_name ='ssh -v -l username IP-address'` 这样的别名命令: + +``` +$ alias butterfly=”ssh -v -l jdoe 192.168.0.11” +``` + +也可以通过在 `/etc/hosts` 文件中添加记录或者在 DNS 服务器中加入解析记录来把 IP 地址替换成易记的机器名称。 + +执行 `alias` 命令可以列出机器上已有的别名。 + +``` +$ alias +alias butterfly='ssh -v -l jdoe 192.168.0.11' +alias c='clear' +alias egrep='egrep --color=auto' +alias fgrep='fgrep --color=auto' +alias grep='grep --color=auto' +alias l='ls -CF' +alias la='ls -A' +alias list_repos='grep ^[^#] /etc/apt/sources.list /etc/apt/sources.list.d/*' +alias ll='ls -alF' +alias ls='ls --color=auto' +alias show_dimensions='xdpyinfo | grep '\''dimensions:'\''' +``` + +只要将新的别名添加到 `~/.bashrc` 或类似的文件中,就可以让别名在每次登录后都能立即生效。 + +### 冻结、解冻终端界面 + +`^s`(`ctrl + s`)将通过执行流量控制命令 XOFF 来停止终端输出内容,这会对 PuTTY 会话和桌面终端窗口产生影响。如果误输入了这个命令,可以使用 `^q`(`ctrl + q`)让终端重新响应。所以只需要记住 `^q` 这个组合键就可以了,毕竟这种情况并不多见。 + +### 复用命令 + +Linux 提供了很多让用户复用命令的方法,其核心是通过历史缓冲区收集执行过的命令。复用命令的最简单方法是输入 `!` 然后接最近使用过的命令的开头字母;当然也可以按键盘上的向上箭头,直到看到要复用的命令,然后按回车键。还可以先使用 `history` 显示命令历史,然后输入 `!` 后面再接命令历史记录中需要复用的命令旁边的数字。 + +``` +!! <== 复用上一条命令 +!ec <== 复用上一条以 “ec” 开头的命令 +!76 <== 复用命令历史中的 76 号命令 +``` + +### 查看日志文件并动态显示更新内容 + +使用形如 `tail -f /var/log/syslog` 的命令可以查看指定的日志文件,并动态显示文件中增加的内容,需要监控向日志文件中追加内容的的事件时相当有用。这个命令会输出文件内容的末尾部分,并逐渐显示新增的内容。 + +``` +$ tail -f /var/log/auth.log +Sep 17 09:41:01 fly CRON[8071]: pam_unix(cron:session): session closed for user smmsp +Sep 17 09:45:01 fly CRON[8115]: pam_unix(cron:session): session opened for user root +Sep 17 09:45:01 fly CRON[8115]: pam_unix(cron:session): session closed for user root +Sep 17 09:47:00 fly sshd[8124]: Accepted password for shs from 192.168.0.22 port 47792 +Sep 17 09:47:00 fly sshd[8124]: pam_unix(sshd:session): session opened for user shs by +Sep 17 09:47:00 fly systemd-logind[776]: New session 215 of user shs. +Sep 17 09:55:01 fly CRON[8208]: pam_unix(cron:session): session opened for user root +Sep 17 09:55:01 fly CRON[8208]: pam_unix(cron:session): session closed for user root + <== 等待显示追加的内容 +``` + +### 寻求帮助 + +对于大多数 Linux 命令,都可以通过在输入命令后加上选项 `--help` 来获得这个命令的作用、用法以及它的一些相关信息。除了 `man` 命令之外, `--help` 选项可以让你在不使用所有扩展选项的情况下获取到所需要的内容。 + +``` +$ mkdir --help +Usage: mkdir [OPTION]... DIRECTORY... +Create the DIRECTORY(ies), if they do not already exist. + +Mandatory arguments to long options are mandatory for short options too. + -m, --mode=MODE set file mode (as in chmod), not a=rwx - umask + -p, --parents no error if existing, make parent directories as needed + -v, --verbose print a message for each created directory + -Z set SELinux security context of each created directory + to the default type + --context[=CTX] like -Z, or if CTX is specified then set the SELinux + or SMACK security context to CTX + --help display this help and exit + --version output version information and exit + +GNU coreutils online help: +Full documentation at: +or available locally via: info '(coreutils) mkdir invocation' +``` + +### 谨慎删除文件 + +如果要谨慎使用 `rm` 命令,可以为它设置一个别名,在删除文件之前需要进行确认才能删除。有些系统管理员会默认使用这个别名,对于这种情况,你可能需要看看下一个技巧。 + +``` +$ rm -i <== 请求确认 +``` + +### 关闭别名 + +你可以使用 `unalias` 命令以交互方式禁用别名。它不会更改别名的配置,而仅仅是暂时禁用,直到下次登录或重新设置了这一个别名才会重新生效。 + +``` +$ unalias rm +``` + +如果已经将 `rm -i` 默认设置为 `rm` 的别名,但你希望在删除文件之前不必进行确认,则可以将 `unalias` 命令放在一个启动文件(例如 `~/.bashrc`)中。 + +### 使用 sudo + +如果你经常在只有 root 用户才能执行的命令前忘记使用 `sudo`,这里有两个方法可以解决。一是利用命令历史记录,可以使用 `sudo !!`(使用 `!!` 来运行最近的命令,并在前面添加 `sudo`)来重复执行,二是设置一些附加了所需 `sudo` 的命令别名。 + +``` +$ alias update=’sudo apt update’ +``` + +### 更复杂的技巧 + +有时命令行技巧并不仅仅是一个别名。毕竟,别名能帮你做的只有替换命令以及增加一些命令参数,节省了输入的时间。但如果需要比别名更复杂功能,可以通过编写脚本、向 `.bashrc` 或其他启动文件添加函数来实现。例如,下面这个函数会在创建一个目录后进入到这个目录下。在设置完毕后,执行 `source .bashrc`,就可以使用 `md temp` 这样的命令来创建目录立即进入这个目录下。 + +``` +md () { mkdir -p "$@" && cd "$1"; } +``` + +### 总结 + +使用 Linux 命令行是在 Linux 系统上工作最有效也最有趣的方法,但配合命令行技巧和巧妙的别名可以让你获得更好的体验。 + +-------------------------------------------------------------------------------- + +via: https://www.networkworld.com/article/3305811/linux/linux-tricks-that-even-you-can-love.html + +作者:[Sandra Henry-Stocker][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[HankChow](https://github.com/HankChow) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://www.networkworld.com/author/Sandra-Henry_Stocker/ +[1]: https://www.facebook.com/NetworkWorld/ +[2]: https://www.linkedin.com/company/network-world + diff --git a/published/20180918 How To Force APT Package Manager To Use IPv4 In Ubuntu 16.04.md b/published/20180918 How To Force APT Package Manager To Use IPv4 In Ubuntu 16.04.md new file mode 100644 index 0000000000..36c159ac16 --- /dev/null +++ b/published/20180918 How To Force APT Package Manager To Use IPv4 In Ubuntu 16.04.md @@ -0,0 +1,46 @@ +如何在 Ubuntu 16.04 强制 APT 包管理器使用 IPv4 +====== + +![](https://www.ostechnix.com/wp-content/uploads/2018/09/ipv4-720x340.png) + +**APT**, 是 **A** dvanced **P** ackage **T** ool 的缩写,是基于 Debian 的系统的默认包管理器。我们可以使用 APT 安装、更新、升级和删除应用程序。最近,我一直遇到一个奇怪的错误。每当我尝试更新我的 Ubuntu 16.04 时,我都会收到此错误 - **“0% [Connecting to in.archive.ubuntu.com (2001:67c:1560:8001::14)]”** ,同时更新流程会卡住很长时间。我的网络连接没问题,我可以 ping 通所有网站,包括 Ubuntu 官方网站。在搜索了一番谷歌后,我意识到 Ubuntu 镜像站点有时无法通过 IPv6 访问。在我强制将 APT 包管理器在更新系统时使用 IPv4 代替 IPv6 访问 Ubuntu 镜像站点后,此问题得以解决。如果你遇到过此错误,可以按照以下说明解决。 + +### 强制 APT 包管理器在 Ubuntu 16.04 中使用 IPv4 + +要在更新和升级 Ubuntu 16.04 LTS 系统时强制 APT 使用 IPv4 代替 IPv6,只需使用以下命令: + +``` +$ sudo apt-get -o Acquire::ForceIPv4=true update +$ sudo apt-get -o Acquire::ForceIPv4=true upgrade +``` + +瞧!这次更新很快就完成了。 + +你还可以使用以下命令在 `/etc/apt/apt.conf.d/99force-ipv4` 中添加以下行,以便将来对所有 `apt-get` 事务保持持久性: + +``` +$ echo 'Acquire::ForceIPv4 "true";' | sudo tee /etc/apt/apt.conf.d/99force-ipv4 +``` + +**免责声明:** + +我不知道最近是否有人遇到这个问题,但我今天在我的 Ubuntu 16.04 LTS 虚拟机中遇到了至少四、五次这样的错误,我按照上面的说法解决了这个问题。我不确定这是推荐的解决方案。请浏览 Ubuntu 论坛来确保此方法合法。由于我只是一个 VM,我只将它用于测试和学习目的,我不介意这种方法的真实性。请自行承担使用风险。 + +希望这有帮助。还有更多的好东西。敬请关注! + +干杯! + + + +-------------------------------------------------------------------------------- + +via: https://www.ostechnix.com/how-to-force-apt-package-manager-to-use-ipv4-in-ubuntu-16-04/ + +作者:[SK][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[geekpi](https://github.com/geekpi) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://www.ostechnix.com/author/sk/ diff --git a/published/20180919 Understand Fedora memory usage with top.md b/published/20180919 Understand Fedora memory usage with top.md new file mode 100644 index 0000000000..a8c6906ca1 --- /dev/null +++ b/published/20180919 Understand Fedora memory usage with top.md @@ -0,0 +1,60 @@ +使用 top 命令了解 Fedora 的内存使用情况 +====== + +![](https://fedoramagazine.org/wp-content/uploads/2018/09/memory-top-816x345.jpg) + +如果你使用过 `top` 命令来查看 Fedora 系统中的内存使用情况,你可能会惊讶,看起来消耗的数量比系统可用的内存更多。下面会详细介绍内存使用情况以及如何理解这些数据。 + +### 内存实际使用情况 + +操作系统对内存的使用方式并不是太通俗易懂。事实上,其背后有很多不为人知的巧妙技术在发挥着作用。通过这些方式,可以在无需用户干预的情况下,让操作系统更有效地使用内存。 + +大多数应用程序都不是系统自带的,但每个应用程序都依赖于安装在系统中的库中的一些函数集。在 Fedora 中,RPM 包管理系统能够确保在安装应用程序时也会安装所依赖的库。 + +当应用程序运行时,操作系统并不需要将它要用到的所有信息都加载到物理内存中。而是会为存放代码的存储空间构建一个映射,称为虚拟内存。操作系统只把需要的部分加载到内存中,当某一个部分不再需要后,这一部分内存就会被释放掉。 + +这意味着应用程序可以映射大量的虚拟内存,而使用较少的系统物理内存。特殊情况下,映射的虚拟内存甚至可以比系统实际可用的物理内存更多!而且在操作系统中这种情况也并不少见。 + +另外,不同的应用程序可能会对同一个库都有依赖。Fedora 中的 Linux 内核通常会在各个应用程序之间共享内存,而不需要为不同应用分别加载同一个库的多个副本。类似地,对于同一个应用程序的不同实例也是采用这种方式共享内存。 + +如果不首先了解这些细节,`top` 命令显示的数据可能会让人摸不着头脑。下面就举例说明如何正确查看内存使用量。 + +### 使用 `top` 命令查看内存使用量 + +如果你还没有使用过 `top` 命令,可以打开终端直接执行查看。使用 `Shift + M` 可以按照内存使用量来进行排序。下图是在 Fedora Workstation 中执行的结果,在你的机器上显示的结果可能会略有不同: + +![](https://fedoramagazine.org/wp-content/uploads/2018/09/Screenshot-from-2018-09-17-14-23-17.png) + +主要通过以下三列来查看内存使用情况:`VIRT`、`RES` 和 `SHR`。目前以 KB 为单位显示相关数值。 + +`VIRT` 列代表该进程映射的虚拟virtual内存。如上所述,虚拟内存不是实际消耗的物理内存。例如, GNOME Shell 进程 `gnome-shell` 实际上没有消耗超过 3.1 GB 的物理内存,但它对很多更低或更高级的库都有依赖,系统必须对每个库都进行映射,以确保在有需要时可以加载这些库。 + +`RES` 列代表应用程序消耗了多少实际(驻留resident)内存。对于 GNOME Shell 大约是 180788 KB。例子中的系统拥有大约 7704 MB 的物理内存,因此内存使用率显示为 2.3%。 + +但根据 `SHR` 列显示,其中至少有 88212 KB 是共享shared内存,这部分内存可能是其它应用程序也在使用的库函数。这意味着 GNOME Shell 本身大约有 92 MB 内存不与其他进程共享。需要注意的是,上述例子中的其它程序也共享了很多内存。在某些应用程序中,共享内存在内存使用量中会占很大的比例。 + +值得一提的是,有时进程之间通过内存通信,这些内存也是共享的,但 `top` 这样的工具却不一定能检测到,所以以上的说明也不一定准确。 + +### 关于交换分区 + +系统还可以通过交换分区来存储数据(例如硬盘),但读写的速度相对较慢。当物理内存渐渐用满,操作系统就会查找内存中暂时不会使用的部分,将其写出到交换区域等待需要的时候使用。 + +因此,如果交换内存的使用量一直偏高,表明系统的物理内存已经供不应求了。有时候一个不正常的应用也有可能导致出现这种情况,但如果这种现象经常出现,就需要考虑提升物理内存或者限制某些程序的运行了。 + +感谢 [Stig Nygaard][1] 在 [Flickr][2] 上提供的图片(CC BY 2.0)。 + +-------------------------------------------------------------------------------- + +via: https://fedoramagazine.org/understand-fedora-memory-usage-top/ + +作者:[Paul W. Frields][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[HankChow](https://github.com/HankChow) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://fedoramagazine.org/author/pfrields/ +[1]: https://www.flickr.com/photos/stignygaard/ +[2]: https://www.flickr.com/photos/stignygaard/3138001676/ + diff --git a/published/20180929 Getting started with the i3 window manager on Linux.md b/published/20180929 Getting started with the i3 window manager on Linux.md new file mode 100644 index 0000000000..2aa0df4c6b --- /dev/null +++ b/published/20180929 Getting started with the i3 window manager on Linux.md @@ -0,0 +1,122 @@ +i3 窗口管理器入门 +====== + +> 本篇文章会介绍如何在 Fedora 系统中,安装、配置、使用 i3 瓦片式桌面管理器。 + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/windows-tiling-windows-wall.png?itok=mTH7uVrn) + +在我的文章 [i3 桌面让 Linux 更好的 5 个理由][1],我分享了选择 [i3 桌面管理器][2] 作为一种 Linux 桌面替代方案的最主要五个理由。 + +在本篇文章中,我将向大家展示,如何在 Fedora 28 上安装与简单配置 i3。 + +### 1、 安装 + +首先进入 Fedora 系统中,打开一个终端。使用 `dnf` 来安装需要的软件包,如下: + +``` +[ricardo@f28i3 ~]$ sudo dnf install -y i3 i3-ipc i3status i3lock dmenu terminator --exclude=rxvt-unicode +Last metadata expiration check: 1:36:15 ago on Wed 08 Aug 2018 12:04:31 PM EDT. +Dependencies resolved. +================================================================================================ + Package Arch Version Repository Size +================================================================================================ +Installing: + dmenu x86_64 4.8-1.fc28 fedora 33 k + i3 x86_64 4.15-1.fc28 fedora 323 k + i3-ipc noarch 0.1.4-12.fc28 fedora 14 k + i3lock x86_64 2.9.1-2.fc28 fedora 33 k + i3status x86_64 2.12-1.fc28 updates 62 k + terminator noarch 1.91-4.fc28 fedora 570 k +Installing dependencies: + dzen2 x86_64 0.8.5-21.20100104svn.fc28 fedora 60 k + +... Skipping dependencies/install messages + +Complete! +[ricardo@f28i3 ~]$ +``` + +注意:在这个命令中,我排除了 `rxvt-unicode` 这个包,因为我更喜欢 `terminator` 作为我的终端模拟器。 + +据用户目前的系统状态,在命令执行过程中可能会安装很多依赖。等待所有的依赖安装完成,之后重启你的电脑。 + +### 2、 首次登录与初始化 + +在你的机器重启之后,你便可以第一次体验 i3 了。在 GNOME 显示管理器(GDM)屏幕,选择你的用户名,之后先别着急输密码,点击下方的密码输入框下方的小齿轮,之后选择 i3 而不是 GNOME,像下方这样: + +![](https://opensource.com/sites/default/files/uploads/i3_first_login_small.png) + +输入你的密码,并点击 “Sign In”。在你第一次登入之后,会先看到 i3 的配置界面: + +![](https://opensource.com/sites/default/files/uploads/i3_first_configuration_small.png) + +点击回车键就会在 `$HOME/.config/i3` 生成一个配置文件,之后你可以通过这个配置文件来定制化 i3 的一些行为。 + +在下一屏,你需要选择你的 `Mod` 键。这一步很关键,因为 `Mod` 键通常都会作为 i3 命令快捷键的发起键。按回车会选择 `Win` 键作为默认的 `Mod` 键。如果你的键盘没有 `Win` 键,用 `Alt` 键做替代,用方向键键选择后按回车键确认。 + +![](https://opensource.com/sites/default/files/uploads/i3_generate_config_small.png) + +现在你就登录到了 i3 的系统中。由于 i3 是一个极简的窗口管理器,你会看到一个黑屏窗口,以及屏幕底端显示的状态栏: + +![](https://opensource.com/sites/default/files/uploads/i3_start_small.png) + +接下来,让我们看看 i3 的如何实际使用。 + +### 3、 基本的快捷键 + +现在你已经登录到了 i3 会话中,你需要几个基本的快捷键来应对基本的操作。 + +大多数的 i3 快捷键都会用到之前配置的 `Mod` 键。在下面的例子中,当我提到 `Mod` 键,请根据情况使用你定义的做替换。通常使用 `Win` 键或者 `Alt` 键。 + +首先,要打开一个终端,可以使用 `Mod+ENTER`。重复打开几个终端,观察 i3 是如何自动将它们在桌面中排列。默认情况下, i3 会在水平的方向分割屏幕;使用 `Mod + v` 来垂直分割,再按 `Mod + h` 会恢复水平分割模式。 + +![](https://opensource.com/sites/default/files/uploads/i3_3terminal_tiled_small.png) + +当需要启动其他的应用,按 `Mod + d` 来打开 `dmenu`,一个简单的文字应用菜单。默认情况下,`dmenu` 会呈现出所有在你 `$PATH` 中设置的应用。使用方向键来选择你想启动的应用,同时你可以键入应用的名称,来缩小选择的范围,之后按回车键来启动选择的应用。 + +![](https://opensource.com/sites/default/files/uploads/i3_dmenu.png) + +如果你的应用没有提供退出的方法,你可以使用 i3 来关闭对应的窗口,通过按 `Mod + Shift +q`。注意,你可能会丢失未保存的工作内容。 + +最后,当你想关闭会话并退出 i3,按 `Mod + Shift +e`。之后会在窗口的上方提示你是否退出。点击 “Yes, exit i3” 退出,或选择 “X” 来取消。 + +![](https://opensource.com/sites/default/files/uploads/i3_exit_small.png) + +这些就是 i3 中最基本的快捷键,如果想了解更多,请查阅官方[文档][3]。 + +### 4、 替换 GDM + +使用 i3 窗口管理器会降低你操作系统的内存占用;然而,Fedora 依然会使用 GDM 作为登录屏。GDM 会载入几个与 GNOME 相关的库从而占用内存。 + +如果你想进一步的降低你的内存占用,你可以使用一些更轻量级的显示管理器来替换 GDM,比如 lightdm : + +``` +[ricardo@f28i3 ~]$ sudo dnf install -y lightdm +[ricardo@f28i3 ~]$ sudo systemctl disable gdm +Removed /etc/systemd/system/display-manager.service. +[ricardo@f28i3 ~]$ sudo systemctl enable lightdm +Created symlink /etc/systemd/system/display-manager.service -> /usr/lib/systemd/system/lightdm.service. +[ricardo@f28i3 ~]$ +``` + +之后重启你的机器来使用 Lightdm 的登录界面。 + +现在你可以继续登录并使用 i3了。 + +![](https://opensource.com/sites/default/files/uploads/i3_lightdm_small.png) + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/8/getting-started-i3-window-manager + +作者:[Ricardo Gerardi][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[sd886393](https://github.com/sd886393) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://opensource.com/users/rgerardi +[1]: https://opensource.com/article/18/8/i3-tiling-window-manager +[2]: https://i3wm.org +[3]: https://i3wm.org/docs/userguide.html#_default_keybindings diff --git a/sources/talk/20180117 How to get into DevOps.md b/sources/talk/20180117 How to get into DevOps.md deleted file mode 100644 index 09e50ae4f2..0000000000 --- a/sources/talk/20180117 How to get into DevOps.md +++ /dev/null @@ -1,143 +0,0 @@ -How to get into DevOps -====== -![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/rh_003784_02_os.comcareers_resume_rh1x.png?itok=S3HGxi6E) - -I've observed a sharp uptick of developers and systems administrators interested in "getting into DevOps" within the past year or so. This pattern makes sense: In an age in which a single developer can spin up a globally distributed infrastructure for an application with a few dollars and a few API calls, the gap between development and systems administration is closer than ever. Although I've seen plenty of blog posts and articles about cool DevOps tools and thoughts to think about, I've seen fewer content on pointers and suggestions for people looking to get into this work. - -My goal with this article is to draw what that path looks like. My thoughts are based upon several interviews, chats, late-night discussions on [reddit.com/r/devops][1], and random conversations, likely over beer and delicious food. I'm also interested in hearing feedback from those who have made the jump; if you have, please reach out through [my blog][2], [Twitter][3], or in the comments below. I'd love to hear your thoughts and stories. - -### Olde world IT - -Understanding history is key to understanding the future, and DevOps is no exception. To understand the pervasiveness and popularity of the DevOps movement, understanding what IT was like in the late '90s and most of the '00s is helpful. This was my experience. - -I started my career in late 2006 as a Windows systems administrator in a large, multi-national financial services firm. In those days, adding new compute involved calling Dell (or, in our case, CDW) and placing a multi-hundred-thousand-dollar order of servers, networking equipment, cables, and software, all destined for your on- and offsite datacenters. Although VMware was still convincing companies that using virtual machines was, indeed, a cost-effective way of hosting its "performance-sensitive" application, many companies, including mine, pledged allegiance to running applications on their physical hardware. - -Our technology department had an entire group dedicated to datacenter engineering and operations, and its job was to negotiate our leasing rates down to some slightly less absurd monthly rate and ensure that our systems were being cooled properly (an exponentially difficult problem if you have enough equipment). If the group was lucky/wealthy enough, the offshore datacenter crew knew enough about all of our server models to not accidentally pull the wrong thing during after-hours trading. Amazon Web Services and Rackspace were slowly beginning to pick up steam, but were far from critical mass. - -In those days, we also had teams dedicated to ensuring that the operating systems and software running on top of that hardware worked when they were supposed to. The engineers were responsible for designing reliable architectures for patching, monitoring, and alerting these systems as well as defining what the "gold image" looked like. Most of this work was done with a lot of manual experimentation, and the extent of most tests was writing a runbook describing what you did, and ensuring that what you did actually did what you expected it to do after following said runbook. This was important in a large organization like ours, since most of the level 1 and 2 support was offshore, and the extent of their training ended with those runbooks. - -(This is the world that your author lived in for the first three years of his career. My dream back then was to be the one who made the gold standard!) - -Software releases were another beast altogether. Admittedly, I didn't gain a lot of experience working on this side of the fence. However, from stories that I've gathered (and recent experience), much of the daily grind for software development during this time went something like this: - - * Developers wrote code as specified by the technical and functional requirements laid out by business analysts from meetings they weren't invited to. - * Optionally, developers wrote unit tests for their code to ensure that it didn't do anything obviously crazy, like try to divide over zero without throwing an exception. - * When done, developers would mark their code as "Ready for QA." A quality assurance person would pick up the code and run it in their own environment, which might or might not be like production or even the environment the developer used to test their own code against. - * Failures would get sent back to the developers within "a few days or weeks" depending on other business activities and where priorities fell. - - - -Although sysadmins and developers didn't often see eye to eye, the one thing they shared a common hatred for was "change management." This was a composition of highly regulated (and in the case of my employer at the time), highly necessary rules and procedures governing when and how technical changes happened in a company. Most companies followed [ITIL][4] practices, which, in a nutshell, asked a lot of questions around why, when, where, and how things happened and provided a process for establishing an audit trail of the decisions that led up to those answers. - -As you could probably gather from my short history lesson, many, many things were done manually in IT. This led to a lot of mistakes. Lots of mistakes led up to lots of lost revenue. Change management's job was to minimize those lost revenues; this usually came in the form of releases only every two weeks and changes to servers, regardless of their impact or size, queued up to occur between Friday at 4 p.m. and Monday at 5:59 a.m. (Ironically, this batching of work led to even more mistakes, usually more serious ones.) - -### DevOps isn't a Tiger Team - -You might be thinking "What is Carlos going on about, and when is he going to talk about Ansible playbooks?" I love Ansible tons, but hang on; this is important. - -Have you ever been assigned to a project where you had to interact with the "DevOps" team? Or did you have to rely on a "configuration management" or "CI/CD" team to ensure your pipeline was set up properly? Have you had to attend meetings about your release and what it pertains to--weeks after the work was marked "code complete"? - -If so, then you're reliving history. All of that comes from all of the above. - -[Silos form][5] out of an instinctual draw to working with people like ourselves. Naturally, it's no surprise that this human trait also manifests in the workplace. I even saw this play out at a 250-person startup where I used to work. When I started, developers all worked in common pods and collaborated heavily with each other. As the codebase grew in complexity, developers who worked on common features naturally aligned with each other to try and tackle the complexity within their own feature. Soon afterwards, feature teams were officially formed. - -Sysadmins and developers at many of the companies I worked at not only formed natural silos like this, but also fiercely competed with each other. Developers were mad at sysadmins when their environments were broken. Developers were mad at sysadmins when their environments were too locked down. Sysadmins were mad that developers were breaking their environments in arbitrary ways all of the time. Sysadmins were mad at developers for asking for way more computing power than they needed. Neither side understood each other, and worse yet, neither side wanted to. - -Most developers were uninterested in the basics of operating systems, kernels, or, in some cases, computer hardware. As well, most sysadmins, even Linux sysadmins, took a 10-foot pole approach to learning how to code. They tried a bit of C in college, hated it and never wanted to touch an IDE again. Consequently, developers threw their environment problems over the wall to sysadmins, sysadmins prioritized them with the hundreds of other things that were thrown over the wall to them, and everyone busy-waited angrily while hating each other. The purpose of DevOps was to put an end to this. - -DevOps isn't a team. CI/CD isn't a group in Jira. DevOps is a way of thinking. According to the movement, in an ideal world, developers, sysadmins, and business stakeholders would be working as one team. While they might not know everything about each other's worlds, not only do they all know enough to understand each other and their backlogs, but they can, for the most part, speak the same language. - -This is the basis behind having all infrastructure and business logic be in code and subject to the same deployment pipelines as the software that sits on top of it. Everybody is winning because everyone understands each other. This is also the basis behind the rise of other tools like chatbots and easily accessible monitoring and graphing. - -[Adam Jacob said][6] it best: "DevOps is the word we will use to describe the operational side of the transition to enterprises being software led." - -### What do I need to know to get into DevOps? - -I'm commonly asked this question, and the answer, like most open-ended questions like this, is: It depends. - -At the moment, the "DevOps engineer" varies from company to company. Smaller companies that have plenty of software developers but fewer folks that understand infrastructure will likely look for people with more experience administrating systems. Other, usually larger and/or older companies that have a solid sysadmin organization will likely optimize for something closer to a [Google site reliability engineer][7], i.e. "a software engineer to design an operations function." This isn't written in stone, however, as, like any technology job, the decision largely depends on the hiring manager sponsoring it. - -That said, we typically look for engineers who are interested in learning more about: - - * How to administrate and architect secure and scalable cloud platforms (usually on AWS, but Azure, Google Cloud Platform, and PaaS providers like DigitalOcean and Heroku are popular too); - * How to build and optimize deployment pipelines and deployment strategies on popular [CI/CD][8] tools like Jenkins, Go continuous delivery, and cloud-based ones like Travis CI or CircleCI; - * How to monitor, log, and alert on changes in your system with timeseries-based tools like Kibana, Grafana, Splunk, Loggly, or Logstash; and - * How to maintain infrastructure as code with configuration management tools like Chef, Puppet, or Ansible, as well as deploy said infrastructure with tools like Terraform or CloudFormation. - - - -Containers are becoming increasingly popular as well. Despite the [beef against the status quo][9] surrounding Docker at scale, containers are quickly becoming a great way of achieving an extremely high density of services and applications running on fewer systems while increasing their reliability. (Orchestration tools like Kubernetes or Mesos can spin up new containers in seconds if the host they're being served by fails.) Given this, having knowledge of Docker or rkt and an orchestration platform will go a long way. - -If you're a systems administrator that's looking to get into DevOps, you will also need to know how to write code. Python and Ruby are popular languages for this purpose, as they are portable (i.e., can be used on any operating system), fast, and easy to read and learn. They also form the underpinnings of the industry's most popular configuration management tools (Python for Ansible, Ruby for Chef and Puppet) and cloud API clients (Python and Ruby are commonly used for AWS, Azure, and Google Cloud Platform clients). - -If you're a developer looking to make this change, I highly recommend learning more about Unix, Windows, and networking fundamentals. Even though the cloud abstracts away many of the complications of administrating a system, debugging slow application performance is aided greatly by knowing how these things work. I've included a few books on this topic in the next section. - -If this sounds overwhelming, you aren't alone. Fortunately, there are plenty of small projects to dip your feet into. One such toy project is Gary Stafford's Voter Service, a simple Java-based voting platform. We ask our candidates to take the service from GitHub to production infrastructure through a pipeline. One can combine that with Rob Mile's awesome DevOps Tutorial repository to learn about ways of doing this. - -Another great way of becoming familiar with these tools is taking popular services and setting up an infrastructure for them using nothing but AWS and configuration management. Set it up manually first to get a good idea of what to do, then replicate what you just did using nothing but CloudFormation (or Terraform) and Ansible. Surprisingly, this is a large part of the work that we infrastructure devs do for our clients on a daily basis. Our clients find this work to be highly valuable! - -### Books to read - -If you're looking for other resources on DevOps, here are some theory and technical books that are worth a read. - -#### Theory books - - * [The Phoenix Project][10] by Gene Kim. This is a great book that covers much of the history I explained earlier (with much more color) and describes the journey to a lean company running on agile and DevOps. - * [Driving Technical Change][11] by Terrance Ryan. Awesome little book on common personalities within most technology organizations and how to deal with them. This helped me out more than I expected. - * [Peopleware][12] by Tom DeMarco and Tim Lister. A classic on managing engineering organizations. A bit dated, but still relevant. - * [Time Management for System Administrators][13] by Tom Limoncelli. While this is heavily geared towards sysadmins, it provides great insight into the life of a systems administrator at most large organizations. If you want to learn more about the war between sysadmins and developers, this book might explain more. - * [The Lean Startup][14] by Eric Ries. Describes how Eric's 3D avatar company, IMVU, discovered how to work lean, fail fast, and find profit faster. - * [Lean Enterprise][15] by Jez Humble and friends. This book is an adaption of The Lean Startup for the enterprise. Both are great reads and do a good job of explaining the business motivation behind DevOps. - * [Infrastructure As Code][16] by Kief Morris. Awesome primer on, well, infrastructure as code! It does a great job of describing why it's essential for any business to adopt this for their infrastructure. - * [Site Reliability Engineering][17] by Betsy Beyer, Chris Jones, Jennifer Petoff, and Niall Richard Murphy. A book explaining how Google does SRE, or also known as "DevOps before DevOps was a thing." Provides interesting opinions on how to handle uptime, latency, and keeping engineers happy. - - - -#### Technical books - -If you're looking for books that'll take you straight to code, you've come to the right section. - - * [TCP/IP Illustrated][18] by the late W. Richard Stevens. This is the classic (and, arguably, complete) tome on the fundamental networking protocols, with special emphasis on TCP/IP. If you've heard of Layers 1, 2, 3, and 4 and are interested in learning more, you'll need this book. - * [UNIX and Linux System Administration Handbook][19] by Evi Nemeth, Trent Hein, and Ben Whaley. A great primer into how Linux and Unix work and how to navigate around them. - * [Learn Windows Powershell In A Month of Lunches][20] by Don Jones and Jeffrey Hicks. If you're doing anything automated with Windows, you will need to learn how to use Powershell. This is the book that will help you do that. Don Jones is a well-known MVP in this space. - * Practically anything by [James Turnbull][21]. He puts out great technical primers on popular DevOps-related tools. - - - -From companies deploying everything to bare metal (there are plenty that still do, for good reasons) to trailblazers doing everything serverless, DevOps is likely here to stay for a while. The work is interesting, the results are impactful, and, most important, it helps bridge the gap between technology and business. It's a wonderful thing to see. - -Originally published at [Neurons Firing on a Keyboard][22], CC-BY-SA. - --------------------------------------------------------------------------------- - -via: https://opensource.com/article/18/1/getting-devops - -作者:[Carlos Nunez][a] -译者:[译者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/carlosonunez -[1]:https://www.reddit.com/r/devops/ -[2]:https://carlosonunez.wordpress.com/ -[3]:https://twitter.com/easiestnameever -[4]:https://en.wikipedia.org/wiki/ITIL -[5]:https://www.psychologytoday.com/blog/time-out/201401/getting-out-your-silo -[6]:https://twitter.com/adamhjk/status/572832185461428224 -[7]:https://landing.google.com/sre/interview/ben-treynor.html -[8]:https://en.wikipedia.org/wiki/CI/CD -[9]:https://thehftguy.com/2016/11/01/docker-in-production-an-history-of-failure/ -[10]:https://itrevolution.com/book/the-phoenix-project/ -[11]:https://pragprog.com/book/trevan/driving-technical-change -[12]:https://en.wikipedia.org/wiki/Peopleware:_Productive_Projects_and_Teams -[13]:http://shop.oreilly.com/product/9780596007836.do -[14]:http://theleanstartup.com/ -[15]:https://info.thoughtworks.com/lean-enterprise-book.html -[16]:http://infrastructure-as-code.com/book/ -[17]:https://landing.google.com/sre/book.html -[18]:https://en.wikipedia.org/wiki/TCP/IP_Illustrated -[19]:http://www.admin.com/ -[20]:https://www.manning.com/books/learn-windows-powershell-in-a-month-of-lunches-third-edition -[21]:https://jamesturnbull.net/ -[22]:https://carlosonunez.wordpress.com/2017/03/02/getting-into-devops/ diff --git a/sources/talk/20180123 Moving to Linux from dated Windows machines.md b/sources/talk/20180123 Moving to Linux from dated Windows machines.md index 74bf66df68..6acd6e53f2 100644 --- a/sources/talk/20180123 Moving to Linux from dated Windows machines.md +++ b/sources/talk/20180123 Moving to Linux from dated Windows machines.md @@ -1,4 +1,3 @@ -translating by leowang Moving to Linux from dated Windows machines ====== diff --git a/sources/talk/20180209 How writing can change your career for the better, even if you don-t identify as a writer.md b/sources/talk/20180209 How writing can change your career for the better, even if you don-t identify as a writer.md index 55618326c6..98d57bcca3 100644 --- a/sources/talk/20180209 How writing can change your career for the better, even if you don-t identify as a writer.md +++ b/sources/talk/20180209 How writing can change your career for the better, even if you don-t identify as a writer.md @@ -1,4 +1,4 @@ -How writing can change your career for the better, even if you don't identify as a writer +How writing can change your career for the better, even if you don't identify as a writer Translating by FelixYFZ ====== Have you read Marie Kondo's book [The Life-Changing Magic of Tidying Up][1]? Or did you, like me, buy it and read a little bit and then add it to the pile of clutter next to your bed? diff --git a/sources/talk/20180306 Try, learn, modify- The new IT leader-s code.md b/sources/talk/20180306 Try, learn, modify- The new IT leader-s code.md deleted file mode 100644 index bcc0729f77..0000000000 --- a/sources/talk/20180306 Try, learn, modify- The new IT leader-s code.md +++ /dev/null @@ -1,59 +0,0 @@ -Try, learn, modify: The new IT leader's code -====== - -![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/ship_wheel_gear_devops_kubernetes.png?itok=xm4a74Kv) - -Just about every day, new technological developments threaten to destabilize even the most intricate and best-laid business plans. Organizations often find themselves scrambling to adapt to new conditions, and that's created a shift in how they plan for the future. - -According to a 2017 [study][1] by CompTIA, only 34% of companies are currently developing IT architecture plans that extend beyond 12 months. One reason for that shift away from a longer-term plan is that business contexts are changing so quickly that planning any further into the future is nearly impossible. "If your company is trying to set a plan that will last five to 10 years down the road," [CIO.com writes][1], "forget it." - -I've heard similar statements from countless customers and partners around the world. Technological innovations are occurring at an unprecedented pace. - -The result is that long-term planning is dead. We need to be thinking differently about the way we run our organizations if we're going to succeed in this new world. - -### How planning died - -As I wrote in The Open Organization, traditionally-run organizations are optimized for industrial economies. They embrace hierarchical structures and rigidly prescribed processes as they work to achieve positional competitive advantage. To be successful, they have to define the strategic positions they want to achieve. Then they have to formulate and dictate plans for getting there, and execute on those plans in the most efficient ways possible—by coordinating activities and driving compliance. - -Management's role is to optimize this process: plan, prescribe, execute. It consists of saying: Let's think of a competitively advantaged position; let's configure our organization to ultimately get there; and then let's drive execution by making sure all aspects of the organization comply. It's what I'll call "mechanical management," and it's a brilliant solution for a different time. - -In today's volatile and uncertain world, our ability to predict and define strategic positions is diminishing—because the pace of change, the rate of introduction of new variables, is accelerating. Classic, long-term, strategic planning and execution isn't as effective as it used to be. - -If long-term planning has become so difficult, then prescribing necessary behaviors is even more challenging. And measuring compliance against a plan is next to impossible. - -All this dramatically affects the way people work. Unlike workers in the traditionally-run organizations of the past—who prided themselves on being able to act repetitively, with little variation and comfortable certainty—today's workers operate in contexts of abundant ambiguity. Their work requires greater creativity, intuition, and critical judgment—there is a greater demand to deviate from yesterday's "normal" and adjust to today's new conditions. - -In today's volatile and uncertain world, our ability to predict and define strategic positions is diminishing—because the pace of change, the rate of introduction of new variables, is accelerating. - -Working in this new way has become more critical to value creation. Our management systems must focus on building structures, systems, and processes that help create engaged, motivated workers—people who are enabled to innovate and act with speed and agility. - -We need to come up with a different solution for optimizing organizations for a very different economic era, one that works from the bottom up rather than the top down. We need to replace that old three-step formula for success—plan, prescribe, execute—with one much better suited to today's tumultuous climate: try, learn, modify. - -### Try, learn, modify - -Because conditions can change so rapidly and with so little warning—and because the steps we need to take next are no longer planned in advance—we need to cultivate environments that encourage creative trial and error, not unyielding allegiance to a five-year schedule. Here are just a few implications of beginning to work this way: - - * **Shorter planning cycles (try).** Rather than agonize over long-term strategic directions, managers need to be thinking of short-term experiments they can try quickly. They should be seeking ways to help their teams take calculated risks and leverage the data at their disposal to make best guesses about the most beneficial paths forward. They can do this by lowering overhead and giving teams the freedom to try new approaches quickly. - * **Higher tolerance for failure (learn).** Greater frequency of experimentation means greater opportunity for failure. Creative and resilient organizations have a[significantly higher tolerance for failure][2] than traditional organizations do. Managers should treat failures as learning opportunities—moments to gather feedback on the tests their teams are running. - * **More adaptable structures (modify).** An ability to easily modify organizational structures and strategic directions—and the willingness to do it when conditions necessitate—is the key to ensuring that organizations can evolve in line with rapidly changing environmental conditions. Managers can't be wedded to any idea any longer than that idea proves itself to be useful for accomplishing a short-term goal. - - - -If long-term planning is dead, then long live shorter-term experimentation. Try, learn, and modify—that's the best path forward during uncertain times. - -[Subscribe to our weekly newsletter][3] to learn more about open organizations. - --------------------------------------------------------------------------------- - -via: https://opensource.com/open-organization/18/3/try-learn-modify - -作者:[Jim Whitehurst][a] -译者:[译者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/remyd -[1]:https://www.cio.com/article/3246027/enterprise-architecture/the-death-of-long-term-it-planning.html?upd=1515780110970 -[2]:https://opensource.com/open-organization/16/12/building-culture-innovation-your-organization -[3]:https://opensource.com/open-organization/resources/newsletter diff --git a/sources/talk/20180308 20 questions DevOps job candidates should be prepared to answer.md b/sources/talk/20180308 20 questions DevOps job candidates should be prepared to answer.md index 79e41645ec..beb6f372b9 100644 --- a/sources/talk/20180308 20 questions DevOps job candidates should be prepared to answer.md +++ b/sources/talk/20180308 20 questions DevOps job candidates should be prepared to answer.md @@ -1,4 +1,4 @@ -20 questions DevOps job candidates should be prepared to answer +20 questions DevOps job candidates should be prepared to answer Translating by FelixYFZ ====== ![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/hire-job-career.png?itok=SrZo0QJ3) diff --git a/sources/talk/20180308 What is open source programming.md b/sources/talk/20180308 What is open source programming.md deleted file mode 100644 index 4eeef6d9fd..0000000000 --- a/sources/talk/20180308 What is open source programming.md +++ /dev/null @@ -1,95 +0,0 @@ -What is open source programming? -====== - -![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/code_computer_development_programming.png?itok=4OM29-82) - -At the simplest level, open source programming is merely writing code that other people can freely use and modify. But you've heard the old chestnut about playing Go, right? "So simple it only takes a minute to learn the rules, but so complex it requires a lifetime to master." Writing open source code is a pretty similar experience. It's easy to chuck a few lines of code up on GitHub, Bitbucket, SourceForge, or your own blog or site. But doing it right requires some personal investment, effort, and forethought. - -![](https://opensource.com/sites/default/files/styles/panopoly_image_original/public/u128651/floorgoban.jpeg?itok=r8gA5jOk) - -### What open source programming isn't - -Let's be clear up front about something: Just being on GitHub in a public repo does not make your code open source. Copyright in nearly all countries attaches automatically when a work is fixed in a medium, without need for any action by the author. For any code that has not been licensed by the author, it is only the author who can exercise the rights associated with copyright ownership. Unlicensed code—no matter how publicly accessible—is a ticking time bomb for anyone who is unwise enough to use it. - -A well-meaning author may think, "well, it's obvious this is free to use," and have no plans ever to sue anyone, but that doesn't mean the code is safe to use. No matter what you think someone will do, that author has the right to sue anyone who uses, modifies, or embeds that code anywhere else without an expressly granted license. - -Clearly, you shouldn't put your own code out in public without a license and expect others to use or contribute to it. I would also recommend you avoid using (or even looking at) such code yourself. If you create a highly similar function or routine to a piece of unlicensed work you inspected at some point in the past, you could open yourself or your employer to infringement lawsuits. - -Let's say that Jill Schmill writes AwesomeLib and puts it on GitHub without a license. Even if Jill never sues anybody, she might eventually sell all the rights to AwesomeLib to EvilCorp, who will. (Think of it as a lurking vulnerability, just waiting to be exploited.) - -Unlicensed code is unsafe code, period. - -### Choosing the right license - -OK, you've decided you want to write a new program, and you want people to have open source rights to use it. The next step is figuring out which [license][1] best fits your needs. You can get started with the GitHub-curated [choosealicense.com][2], which is just what it says on the tin. The site is laid out a bit like a simple quiz, and most people should be one or two clicks at most from finding the right license for their project. - -Unlicensed code is unsafe code, period. - -A word of caution: Don't get overly fancy or self-important. If you choose a commonly used and well-known license like the - -A word of caution: Don't get overly fancy or self-important. If you choose a commonly used and well-known license like the [Apache License][3] or the [GPLv3][4] , it's easy for people to understand what their rights are and what your rights are without needing a team of lawyers to look for pitfalls and problems. The further you stray from the beaten path, though, the more problems you open yourself and others up to. - -Most importantly, do not write your own license! Making up your own license is an unnecessary source of confusion for everyone. Don't do it. If you absolutely must have your own special terms that you can't find in any existing license, write them as an addendum to an otherwise well-understood license... and keep the main license and your addendum clearly separated so everyone involved knows which parts they've got to be extra careful about. - -I know some people stubborn up and say, "I don't care about licenses and don't want to think about them; it's public domain." The problem with that is that "public domain" isn't a universally understood term in a legal sense. It means different things from one country to the next, with different rights and terms attached. In some countries, you can't even place your own works in the public domain, because the government reserves control over that. Luckily, the [Unlicense][5] has you covered. The Unlicense uses as few words as possible to clearly describe what "just make it public domain!" means in a clear and universally enforceable way. - -### How to apply the license - -Once you've chosen a license, you need to clearly and unambiguously apply it. If you're publishing somewhere like GitHub or GitLab or BitBucket, you'll have what amounts to a folder structure for your project's files. In the root folder of your project, you should have a plaintext file called LICENSE.txt that contains the text of the license you selected. - -Putting LICENSE.txt in the root folder of your project isn't quite the last step—you also need a comment block declaring the license at the header of each significant file in your project. This is one of those times where it comes in handy to be using a well-established license. A comment that says: `# this work (c)2018 myname, licensed GPLv3—see https://www.gnu.org/licenses/gpl-3.0.en.html` is much, much stronger and more useful than a comment block that merely makes a cryptic reference to a completely custom license. - -If you're self-publishing your code on your own site, you'll want to follow basically the same process. Have a LICENSE.txt, put the full copy of your license in it, and link to your license in an abbreviated comment block at the head of each significant file. - -### Open source code is different - -A big difference between proprietary and open source code is that open source code is meant to be seen. As a 40-something sysadmin, I've written a lot of code. Most of it has been effectively proprietary—I started out writing code for myself to make my own jobs easier and scratch my own and/or my company's itches. The goal of such code is simple: All it has to do is work, in the exact way and under the exact circumstance its creator planned. As long as the thing you expected to happen when you invoked the program happens more frequently than not, it's a success. - -A big difference between proprietary and open source code is that open source code is meant to be seen. - -Open source code is very different. When you write open source code, you know that it not only has to work, it has to work in situations you never dreamed of and may not have planned for. Maybe you only had one very narrow use case for your code and invoked it in exactly the same way every time. The people you share it with, though... they'll expose use cases, mixtures of arguments, and just plain strange thought processes you never considered. Your code doesn't necessarily have to satisfy all of them—but it at least needs to handle their requests gracefully, and fail in predictable and logical ways when it can't service them. (For example: "Division by zero on line 583" is not an acceptable response to a failure to supply a command-line argument.) - -Open source code is very different. When you write open source code, you know that it not only has to work, it has to work in situations you never dreamed of and may not have planned for. Maybe you only had one very narrow use case for your code and invoked it in exactly the same way every time. The people you share it with, though... they'll expose use cases, mixtures of arguments, and just plain strange thought processes you never considered. Your code doesn't necessarily have to satisfy all of them—but it at least needs to handle their requests gracefully, and fail in predictable and logical ways when it can't service them. (For example: "Division by zero on line 583" is not an acceptable response to a failure to supply a command-line argument.) - -Your open source code also has to avoid unduly embarrassing you. That means that after you struggle and struggle to get a balky function or sub to finally produce the output you expected, you don't just sigh and move on to the next thing—you clean it up, because you don't want the rest of the world seeing your obvious house of cards. It means that you stop littering your code with variables like `$variable` and `$lol` and replace them with meaningful names like `$iterationcounter` or `$modelname`. And it means commenting things professionally (even if they're obvious to you in the heat of the moment) since you expect other people to be able to follow your code later. - -This can be a little painful and frustrating at first—it's work you're not accustomed to doing. It makes you a better programmer, though, and it makes your code better as well. Just as important: Even if you're the only contributor your project ever has, it saves you work in the long run. Trust me, a year from now when you have to revisit your app, you're going to be very glad that `$modelname`, which gets parsed by several stunningly opaque regular expressions before getting socked into some other array somewhere, isn't named `$lol` anymore. - -### You're not writing just for yourself - -The true heart of open source isn't the code at all: it's the community. Projects with a strong community survive longer and are adopted much more heavily than those that don't. With that in mind, it's a good idea not only to embrace but actively plan for the community you hope to build around your project. - -Batman might spend hundreds of hours in seclusion furiously building a project in secrecy, but you don't have to. Take to Twitter, Reddit, or mailing lists relevant to your project's scope, and announce that you're thinking of creating a new project. Talk about your design goals and how you plan to achieve them. Request input, listen to similar (but maybe not identical) use cases, and build that information into your process as you write code. You don't have to accept every suggestion or request—but if you know about them ahead of time, you can avoid pitfalls that require arduous major overhauls later. - -This process doesn't end with the initial announcement. If you want your project to be adopted and used by other people, you need to develop it that way too. This isn't a barrier to entry; it's just a pattern to use. So don't just hunker down privately on your own machine with a text editor—start a real, publicly accessible project at one of the big foundries, and treat it as though the community was already there and watching. - -### Ways to build a real public project - -You can open accounts for open source projects at GitHub, GitLab, or BitBucket for free. Once you've opened your account and created a repository for your project, use it—create a README, assign a LICENSE, and push code incrementally as you develop it. This will build the habits you'll need to work with a real team later as you get accustomed to writing your code in measurable, documented commits with clear goals. The further you go, the more likely you'll start generating interest—usually in the form of end users first. - -The users will start opening tickets, which will both delight and annoy you. You should take those tickets seriously and treat their owners courteously. Some of them will be based on tremendous misunderstandings of what your project is and what is or isn't within its scope—treat those courteously and professionally, also. In some cases, you'll guide those users into the fold of what you're doing. In others, however haltingly, they'll guide you into realizing the larger—or slightly differently centered—scope you probably should have planned for in the first place. - -If you do a good job with the users, eventually fellow developers will show up and take an interest. This will also both delight and annoy you. At first, you'll probably just get trivial bugfixes. Eventually, you'll start to get pull requests that would either hardcode really, really niche special use-cases into your project (which would be a nightmare to maintain) or significantly alter the scope or even the focus of your project. You'll need to learn how to recognize which contributions are which and decide which ones you want to embrace and which you should politely reject. - -### Why bother with all of this? - -If all of this sounds like a lot of work, there's a good reason: it is. But it's rewarding work that you can cash in on in plenty of ways. Open source work sharpens your skills in ways you never realized were dull—from writing cleaner, more maintainable code to learning how to communicate well and work as a team. It's also the best possible resume builder for a working or aspiring professional developer; potential employers can hit your repository and see what you're capable of, and developers you've worked with on community projects may want to bring you in on paying gigs. - -Ultimately, working on open source projects—yours or others'—means personal growth, because you're working on something larger than yourself. - --------------------------------------------------------------------------------- - -via: https://opensource.com/article/18/3/what-open-source-programming - -作者:[Jim Salter][a] -译者:[译者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-salter -[1]:https://opensource.com/tags/licensing -[2]:https://choosealicense.com/ -[3]:https://choosealicense.com/licenses/apache-2.0/ -[4]:https://choosealicense.com/licenses/gpl-3.0/ -[5]:https://choosealicense.com/licenses/unlicense/ diff --git a/sources/talk/20180402 Understanding Linux filesystems- ext4 and beyond.md b/sources/talk/20180402 Understanding Linux filesystems- ext4 and beyond.md deleted file mode 100644 index 9e1b37b043..0000000000 --- a/sources/talk/20180402 Understanding Linux filesystems- ext4 and beyond.md +++ /dev/null @@ -1,249 +0,0 @@ -Understanding Linux filesystems: ext4 and beyond -====== - -![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/rh_003499_01_linux11x_cc.png?itok=XMDOouJR) - -The majority of modern Linux distributions default to the ext4 filesystem, just as previous Linux distributions defaulted to ext3, ext2, and—if you go back far enough—ext. - -If you're new to Linux—or to filesystems—you might wonder what ext4 brings to the table that ext3 didn't. You might also wonder whether ext4 is still in active development at all, given the flurries of news coverage of alternate filesystems such as btrfs, xfs, and zfs. - -We can't cover everything about filesystems in a single article, but we'll try to bring you up to speed on the history of Linux's default filesystem, where it stands, and what to look forward to. - -I drew heavily on Wikipedia's various ext filesystem articles, kernel.org's wiki entries on ext4, and my own experiences while preparing this overview. - -### A brief history of ext - -#### MINIX filesystem - -Before there was ext, there was the MINIX filesystem. If you're not up on your Linux history, MINIX was a very small Unix-like operating system for IBM PC/AT microcomputers. Andrew Tannenbaum developed it for teaching purposes and released its source code (in print form!) in 1987. - -![](https://opensource.com/sites/default/files/styles/panopoly_image_original/public/u128651/ibm_pc_at.jpg?itok=Tfk3hQYB) - -Although you could peruse MINIX's source, it was not actually free and open source software (FOSS). The publishers of Tannebaum's book required a $69 license fee to operate MINIX, which was included in the cost of the book. Still, this was incredibly inexpensive for the time, and MINIX adoption took off rapidly, soon exceeding Tannenbaum's original intent of using it simply to teach the coding of operating systems. By and throughout the 1990s, you could find MINIX installations thriving in universities worldwide—and a young Linus Torvalds used MINIX to develop the original Linux kernel, first announced in 1991, and released under the GPL in December 1992. - -But wait, this is a filesystem article, right? Yes, and MINIX had its own filesystem, which early versions of Linux also relied on. Like MINIX, it could uncharitably be described as a "toy" example of its kind—the MINIX filesystem could handle filenames only up to 14 characters and address only 64MB of storage. In 1991, the typical hard drive was already 40-140MB in size. Linux clearly needed a better filesystem! - -#### ext - -While Linus hacked away on the fledgling Linux kernel, Rémy Card worked on the first ext filesystem. First implemented in 1992—only a year after the initial announcement of Linux itself!—ext solved the worst of the MINIX filesystem's problems. - -1992's ext used the new virtual filesystem (VFS) abstraction layer in the Linux kernel. Unlike the MINIX filesystem before it, ext could address up to 2GB of storage and handle 255-character filenames. - -But ext didn't have a long reign, largely due to its primitive timestamping (only one timestamp per file, rather than the three separate stamps for inode creation, file access, and file modification we're familiar with today). A mere year later, ext2 ate its lunch. - -#### ext2 - -Rémy clearly realized ext's limitations pretty quickly, since he designed ext2 as its replacement a year later. While ext still had its roots in "toy" operating systems, ext2 was designed from the start as a commercial-grade filesystem, along the same principles as BSD's Berkeley Fast File System. - -Ext2 offered maximum filesizes in the gigabytes and filesystem sizes in the terabytes, placing it firmly in the big leagues for the 1990s. It was quickly and widely adopted, both in the Linux kernel and eventually in MINIX, as well as by third-party modules making it available for MacOS and Windows. - -There were still problems to solve, though: ext2 filesystems, like most filesystems of the 1990s, were prone to catastrophic corruption if the system crashed or lost power while data was being written to disk. They also suffered from significant performance losses due to fragmentation (the storage of a single file in multiple places, physically scattered around a rotating disk) as time went on. - -Despite these problems, ext2 is still used in some isolated cases today—most commonly, as a format for portable USB thumb drives. - -#### ext3 - -In 1998, six years after ext2's adoption, Stephen Tweedie announced he was working on significantly improving it. This became ext3, which was adopted into mainline Linux with kernel version 2.4.15, in November 2001. - - -![Packard Bell computer][2] - -Mid-1990s Packard Bell computer, [Spacekid][3], [CC0][4] - -Ext2 had done very well by Linux distributions for the most part, but—like FAT, FAT32, HFS, and other filesystems of the time—it was prone to catastrophic corruption during power loss. If you lose power while writing data to the filesystem, it can be left in what's called an inconsistent state—one in which things have been left half-done and half-undone. This can result in loss or corruption of vast swaths of files unrelated to the one being saved or even unmountability of the entire filesystem. - -Ext3, and other filesystems of the late 1990s, such as Microsoft's NTFS, uses journaling to solve this problem. The journal is a special allocation on disk where writes are stored in transactions; if the transaction finishes writing to disk, its data in the journal is committed to the filesystem itself. If the system crashes before that operation is committed, the newly rebooted system recognizes it as an incomplete transaction and rolls it back as though it had never taken place. This means that the file being worked on may still be lost, but the filesystem itself remains consistent, and all other data is safe. Three levels of journaling are available in the Linux kernel implementation of ext3: **journal** , **ordered** , and **writeback**. - - * **Journal** is the lowest risk mode, writing both data and metadata to the journal before committing it to the filesystem. This ensures consistency of the file being written to, as well as the filesystem as a whole, but can significantly decrease performance. - * **Ordered** is the default mode in most Linux distributions; ordered mode writes metadata to the journal but commits data directly to the filesystem. As the name implies, the order of operations here is rigid: First, metadata is committed to the journal; second, data is written to the filesystem, and only then is the associated metadata in the journal flushed to the filesystem itself. This ensures that, in the event of a crash, the metadata associated with incomplete writes is still in the journal, and the filesystem can sanitize those incomplete writes while rolling back the journal. In ordered mode, a crash may result in corruption of the file or files being actively written to during the crash, but the filesystem itself—and files not actively being written to—are guaranteed safe. - * **Writeback** is the third—and least safe—journaling mode. In writeback mode, like ordered mode, metadata is journaled, but data is not. Unlike ordered mode, metadata and data alike may be written in whatever order makes sense for best performance. This can offer significant increases in performance, but it's much less safe. Although writeback mode still offers a guarantee of safety to the filesystem itself, files that were written to during or before the crash are vulnerable to loss or corruption. - - - -Like ext2 before it, ext3 uses 16-bit internal addressing. This means that with a blocksize of 4K, the largest filesize it can handle is 2 TiB in a maximum filesystem size of 16 TiB. - -#### ext4 - -Theodore Ts'o (who by then was ext3's principal developer) announced ext4 in 2006, and it was added to mainline Linux two years later, in kernel version 2.6.28. Ts'o describes ext4 as a stopgap technology which significantly extends ext3 but is still reliant on old technology. He expects it to be supplanted eventually by a true next-generation filesystem. - -![](https://opensource.com/sites/default/files/styles/panopoly_image_original/public/u128651/dell_precision_380_workstation.jpeg?itok=3EjYXY2i) - -Ext4 is functionally very similar to ext3, but brings large filesystem support, improved resistance to fragmentation, higher performance, and improved timestamps. - -### Ext4 vs ext3 - -Ext3 and ext4 have some very specific differences, which I'll focus on here. - -#### Backwards compatibility - -Ext4 was specifically designed to be as backward-compatible as possible with ext3. This not only allows ext3 filesystems to be upgraded in place to ext4; it also permits the ext4 driver to automatically mount ext3 filesystems in ext3 mode, making it unnecessary to maintain the two codebases separately. - -#### Large filesystems - -Ext3 filesystems used 32-bit addressing, limiting them to 2 TiB files and 16 TiB filesystems (assuming a 4 KiB blocksize; some ext3 filesystems use smaller blocksizes and are thus limited even further). - -Ext4 uses 48-bit internal addressing, making it theoretically possible to allocate files up to 16 TiB on filesystems up to 1,000,000 TiB (1 EiB). Early implementations of ext4 were still limited to 16 TiB filesystems by some userland utilities, but as of 2011, e2fsprogs has directly supported the creation of >16TiB ext4 filesystems. As one example, Red Hat Enterprise Linux contractually supports ext4 filesystems only up to 50 TiB and recommends ext4 volumes no larger than 100 TiB. - -#### Allocation improvements - -Ext4 introduces a lot of improvements in the ways storage blocks are allocated before writing them to disk, which can significantly increase both read and write performance. - -##### Extents - -An extent is a range of contiguous physical blocks (up to 128 MiB, assuming a 4 KiB block size) that can be reserved and addressed at once. Utilizing extents decreases the number of inodes required by a given file and significantly decreases fragmentation and increases performance when writing large files. - -##### Multiblock allocation - -Ext3 called its block allocator once for each new block allocated. This could easily result in heavy fragmentation when multiple writers are open concurrently. However, ext4 uses delayed allocation, which allows it to coalesce writes and make better decisions about how to allocate blocks for the writes it has not yet committed. - -##### Persistent pre-allocation - -When pre-allocating disk space for a file, most file systems must write zeroes to the blocks for that file on creation. Ext4 allows the use of `fallocate()` instead, which guarantees the availability of the space (and attempts to find contiguous space for it) without first needing to write to it. This significantly increases performance in both writes and future reads of the written data for streaming and database applications. - -##### Delayed allocation - -This is a chewy—and contentious—feature. Delayed allocation allows ext4 to wait to allocate the actual blocks it will write data to until it's ready to commit that data to disk. (By contrast, ext3 would allocate blocks immediately, even while the data was still flowing into a write cache.) - -Delaying allocation of blocks as data accumulates in cache allows the filesystem to make saner choices about how to allocate those blocks, reducing fragmentation (write and, later, read) and increasing performance significantly. Unfortunately, it increases the potential for data loss in programs that have not been specifically written to call `fsync()` when the programmer wants to ensure data has been flushed entirely to disk. - -Let's say a program rewrites a file entirely: - -`fd=open("file" ,O_TRUNC); write(fd, data); close(fd);` - -With legacy filesystems, `close(fd);` is sufficient to guarantee that the contents of `file` will be flushed to disk. Even though the write is not, strictly speaking, transactional, there's very little risk of losing the data if a crash occurs after the file is closed. - -If the write does not succeed (due to errors in the program, errors on the disk, power loss, etc.), both the original version and the newer version of the file may be lost or corrupted. If other processes access the file as it is being written, they will see a corrupted version. And if other processes have the file open and do not expect its contents to change—e.g., a shared library mapped into multiple running programs—they may crash. - -To avoid these issues, some programmers avoid using `O_TRUNC` at all. Instead, they might write to a new file, close it, then rename it over the old one: - -`fd=open("newfile"); write(fd, data); close(fd); rename("newfile", "file");` - -Under filesystems without delayed allocation, this is sufficient to avoid the potential corruption and crash problems outlined above: Since `rename()` is an atomic operation, it won't be interrupted by a crash; and running programs will continue to reference the old, now unlinked version of `file` for as long as they have an open filehandle to it. But because ext4's delayed allocation can cause writes to be delayed and re-ordered, the `rename("newfile","file")` may be carried out before the contents of `newfile` are actually written to disk, which opens the problem of parallel processes getting bad versions of `file` all over again. - -To mitigate this, the Linux kernel (since version 2.6.30) attempts to detect these common code cases and force the files in question to be allocated immediately. This reduces, but does not prevent, the potential for data loss—and it doesn't help at all with new files. If you're a developer, please take note: The only way to guarantee data is written to disk immediately is to call `fsync()` appropriately. - -#### Unlimited subdirectories - -Ext3 was limited to a total of 32,000 subdirectories; ext4 allows an unlimited number. Beginning with kernel 2.6.23, ext4 uses HTree indices to mitigate performance loss with huge numbers of subdirectories. - -#### Journal checksumming - -Ext3 did not checksum its journals, which presented problems for disk or controller devices with caches of their own, outside the kernel's direct control. If a controller or a disk with its own cache did writes out of order, it could break ext3's journaling transaction order, potentially corrupting files being written to during (or for some time preceding) a crash. - -In theory, this problem is resolved by the use of write barriers—when mounting the filesystem, you set `barrier=1` in the mount options, and the device will then honor `fsync()` calls all the way down to the metal. In practice, it's been discovered that storage devices and controllers frequently do not honor write barriers—improving performance (and benchmarks, where they're compared to their competitors) but opening up the possibility of data corruption that should have been prevented. - -Checksumming the journal allows the filesystem to realize that some of its entries are invalid or out-of-order on the first mount after a crash. This thereby avoids the mistake of rolling back partial or out-of-order journal entries and further damaging the filesystem—even if the storage devices lie and don't honor barriers. - -#### Fast filesystem checks - -Under ext3, the entire filesystem—including deleted and empty files—required checking when `fsck` is invoked. By contrast, ext4 marks unallocated blocks and sections of the inode table as such, allowing `fsck` to skip them entirely. This greatly reduces the time to run `fsck` on most filesystems and has been implemented since kernel 2.6.24. - -#### Improved timestamps - -Ext3 offered timestamps granular to one second. While sufficient for most uses, mission-critical applications are frequently looking for much, much tighter time control. Ext4 makes itself available to those enterprise, scientific, and mission-critical applications by offering timestamps in the nanoseconds. - -Ext3 filesystems also did not provide sufficient bits to store dates beyond January 18, 2038. Ext4 adds an additional two bits here, extending [the Unix epoch][5] another 408 years. If you're reading this in 2446 AD, you have hopefully already moved onto a better filesystem—but it'll make me posthumously very, very happy if you're still measuring the time since UTC 00:00, January 1, 1970. - -#### Online defragmentation - -Neither ext2 nor ext3 directly supported online defragmentation—that is, defragging the filesystem while mounted. Ext2 had an included utility, **e2defrag** , that did what the name implies—but it needed to be run offline while the filesystem was not mounted. (This is, obviously, especially problematic for a root filesystem.) The situation was even worse in ext3—although ext3 was much less likely to suffer from severe fragmentation than ext2 was, running **e2defrag** against an ext3 filesystem could result in catastrophic corruption and data loss. - -Although ext3 was originally deemed "unaffected by fragmentation," processes that employ massively parallel write processes to the same file (e.g., BitTorrent) made it clear that this wasn't entirely the case. Several userspace hacks and workarounds, such as [Shake][6], addressed this in one way or another—but they were slower and in various ways less satisfactory than a true, filesystem-aware, kernel-level defrag process. - -Ext4 addresses this problem head on with **e4defrag** , an online, kernel-mode, filesystem-aware, block-and-extent-level defragmentation utility. - -### Ongoing ext4 development - -Ext4 is, as the Monty Python plague victim once said, "not quite dead yet!" Although [its principal developer regards it][7] as a mere stopgap along the way to a truly [next-generation filesystem][8], none of the likely candidates will be ready (due to either technical or licensing problems) for deployment as a root filesystem for some time yet. - -There are still a few key features being developed into future versions of ext4, including metadata checksumming, first-class quota support, and large allocation blocks. - -#### Metadata checksumming - -Since ext4 has redundant superblocks, checksumming the metadata within them offers the filesystem a way to figure out for itself whether the primary superblock is corrupt and needs to use an alternate. It is possible to recover from a corrupt superblock without checksumming—but the user would first need to realize that it was corrupt, and then try manually mounting the filesystem using an alternate. Since mounting a filesystem read-write with a corrupt primary superblock can, in some cases, cause further damage, this isn't a sufficient solution, even with a sufficiently experienced user! - -Compared to the extremely robust per-block checksumming offered by next-gen filesystems such as btrfs or zfs, ext4's metadata checksumming is a pretty weak feature. But it's much better than nothing. - -Although it sounds like a no-brainer—yes, checksum ALL THE THINGS!—there are some significant challenges to bolting checksums into a filesystem after the fact; see [the design document][9] for the gritty details. - -#### First-class quota support - -Wait, quotas?! We've had those since the ext2 days! Yes, but they've always been an afterthought, and they've always kinda sucked. It's probably not worth going into the hairy details here, but the [design document][10] lays out the ways quotas will be moved from userspace into the kernel and more correctly and performantly enforced. - -#### Large allocation blocks - -As time goes by, those pesky storage systems keep getting bigger and bigger. With some solid-state drives already using 8K hardware blocksizes, ext4's current limitation to 4K blocks gets more and more limiting. Larger storage blocks can decrease fragmentation and increase performance significantly, at the cost of increased "slack" space (the space left over when you only need part of a block to store a file or the last piece of a file). - -You can view the hairy details in the [design document][11]. - -### Practical limitations of ext4 - -Ext4 is a robust, stable filesystem, and it's what most people should probably be using as a root filesystem in 2018. But it can't handle everything. Let's talk briefly about some of the things you shouldn't expect from ext4—now or probably in the future. - -Although ext4 can address up to 1 EiB—equivalent to 1,000,000 TiB—of data, you really, really shouldn't try to do so. There are problems of scale above and beyond merely being able to remember the addresses of a lot more blocks, and ext4 does not now (and likely will not ever) scale very well beyond 50-100 TiB of data. - -Ext4 also doesn't do enough to guarantee the integrity of your data. As big an advancement as journaling was back in the ext3 days, it does not cover a lot of the common causes of data corruption. If data is [corrupted][12] while already on disk—by faulty hardware, impact of cosmic rays (yes, really), or simple degradation of data over time—ext4 has no way of either detecting or repairing such corruption. - -Building on the last two items, ext4 is only a pure filesystem, and not a storage volume manager. This means that even if you've got multiple disks—and therefore parity or redundancy, which you could theoretically recover corrupt data from—ext4 has no way of knowing that or using it to your benefit. While it's theoretically possible to separate a filesystem and storage volume management system in discrete layers without losing automatic corruption detection and repair features, that isn't how current storage systems are designed, and it would present significant challenges to new designs. - -### Alternate filesystems - -Before we get started, a word of warning: Be very careful with any alternate filesystem which isn't built into and directly supported as a part of your distribution's mainline kernel! - -Even if a filesystem is safe, using it as the root filesystem can be absolutely terrifying if something hiccups during a kernel upgrade. If you aren't extremely comfortable with the idea of booting from alternate media and poking manually and patiently at kernel modules, grub configs, and DKMS from a chroot... don't go off the reservation with the root filesystem on a system that matters to you. - -There may well be good reasons to use a filesystem your distro doesn't directly support—but if you do, I strongly recommend you mount it after the system is up and usable. (For example, you might have an ext4 root filesystem, but store most of your data on a zfs or btrfs pool.) - -#### XFS - -XFS is about as mainline as a non-ext filesystem gets under Linux. It's a 64-bit, journaling filesystem that has been built into the Linux kernel since 2001 and offers high performance for large filesystems and high degrees of concurrency (i.e., a really large number of processes all writing to the filesystem at once). - -XFS became the default filesystem for Red Hat Enterprise Linux, as of RHEL 7. It still has a few disadvantages for home or small business users—most notably, it's a real pain to resize an existing XFS filesystem, to the point it usually makes more sense to create another one and copy your data over. - -While XFS is stable and performant, there's not enough of a concrete end-use difference between it and ext4 to recommend its use anywhere that it isn't the default (e.g., RHEL7) unless it addresses a specific problem you're having with ext4, such as >50 TiB capacity filesystems. - -XFS is not in any way a "next-generation" filesystem in the ways that ZFS, btrfs, or even WAFL (a proprietary SAN filesystem) are. Like ext4, it should most likely be considered a stopgap along the way towards [something better][8]. - -#### ZFS - -ZFS was developed by Sun Microsystems and named after the zettabyte—equivalent to 1 trillion gigabytes—as it could theoretically address storage systems that large. - -A true next-generation filesystem, ZFS offers volume management (the ability to address multiple individual storage devices in a single filesystem), block-level cryptographic checksumming (allowing detection of data corruption with an extremely high accuracy rate), [automatic corruption repair][12] (where redundant or parity storage is available), rapid [asynchronous incremental replication][13], inline compression, and more. [A lot more][14]. - -The biggest problem with ZFS, from a Linux user's perspective, is the licensing. ZFS was licensed CDDL, which is a semi-permissive license that conflicts with the GPL. There is a lot of controversy over the implications of using ZFS with the Linux kernel, with opinions ranging from "it's a GPL violation" to "it's a CDDL violation" to "it's perfectly fine, it just hasn't been tested in court." Most notably, Canonical has included ZFS code inline in its default kernels since 2016 without legal challenge so far. - -At this time, even as a very avid ZFS user myself, I would not recommend ZFS as a root Linux filesystem. If you want to leverage the benefits of ZFS on Linux, set up a small root filesystem on ext4, then put ZFS on your remaining storage, and put data, applications, whatever you like on it—but keep root on ext4, until your distribution explicitly supports a zfs root. - -#### btrfs - -Btrfs—short for B-Tree Filesystem, and usually pronounced "butter"—was announced by Chris Mason in 2007 during his tenure at Oracle. Btrfs aims at most of the same goals as ZFS, offering multiple device management, per-block checksumming, asynchronous replication, inline compression, and [more][8]. - -As of 2018, btrfs is reasonably stable and usable as a standard single-disk filesystem but should probably not be relied on as a volume manager. It suffers from significant performance problems compared to ext4, XFS, or ZFS in many common use cases, and its next-generation features—replication, multiple-disk topologies, and snapshot management—can be pretty buggy, with results ranging from catastrophically reduced performance to actual data loss. - -The ongoing status of btrfs is controversial; SUSE Enterprise Linux adopted it as its default filesystem in 2015, whereas Red Hat announced it would no longer support btrfs beginning with RHEL 7.4 in 2017. It is probably worth noting that production, supported deployments of btrfs use it as a single-disk filesystem, not as a multiple-disk volume manager a la ZFS—even Synology, which uses btrfs on its storage appliances, but layers it atop conventional Linux kernel RAID (mdraid) to manage the disks. - --------------------------------------------------------------------------------- - -via: https://opensource.com/article/18/4/ext4-filesystem - -作者:[Jim Salter][a] -译者:[译者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-salter -[1]:https://opensource.com/file/391546 -[2]:https://opensource.com/sites/default/files/styles/panopoly_image_original/public/u128651/packard_bell_pc.jpg?itok=VI8dzcwp (Packard Bell computer) -[3]:https://commons.wikimedia.org/wiki/File:Old_packard_bell_pc.jpg -[4]:https://creativecommons.org/publicdomain/zero/1.0/deed.en -[5]:https://en.wikipedia.org/wiki/Unix_time -[6]:https://vleu.net/shake/ -[7]:http://www.linux-mag.com/id/7272/ -[8]:https://arstechnica.com/information-technology/2014/01/bitrot-and-atomic-cows-inside-next-gen-filesystems/ -[9]:https://ext4.wiki.kernel.org/index.php/Ext4_Metadata_Checksums -[10]:https://ext4.wiki.kernel.org/index.php/Design_For_1st_Class_Quota_in_Ext4 -[11]:https://ext4.wiki.kernel.org/index.php/Design_for_Large_Allocation_Blocks -[12]:https://en.wikipedia.org/wiki/Data_degradation#Visual_example_of_data_degradation -[13]:https://arstechnica.com/information-technology/2015/12/rsync-net-zfs-replication-to-the-cloud-is-finally-here-and-its-fast/ -[14]:https://arstechnica.com/information-technology/2014/02/ars-walkthrough-using-the-zfs-next-gen-filesystem-on-linux/ diff --git a/sources/talk/20180410 Microservices Explained.md b/sources/talk/20180410 Microservices Explained.md index 5a2151a00b..1d7e946a12 100644 --- a/sources/talk/20180410 Microservices Explained.md +++ b/sources/talk/20180410 Microservices Explained.md @@ -1,4 +1,3 @@ -(translating by runningwater) Microservices Explained ====== diff --git a/sources/talk/20180518 Mastering CI-CD at OpenDev.md b/sources/talk/20180518 Mastering CI-CD at OpenDev.md deleted file mode 100644 index cb8b9fdfc8..0000000000 --- a/sources/talk/20180518 Mastering CI-CD at OpenDev.md +++ /dev/null @@ -1,53 +0,0 @@ -Mastering CI/CD at OpenDev -====== - -![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/BUSINESS_opennature_3.png?itok=J1OSECM_) -After launching in 2017, the [OpenDev Conference][1] is now an annual event. At the inaugural event last September, the conference focus was on edge computing. This year's event, taking place May 22-23, will be focused on Continuous Integration/Continuous Deployment (CI/CD) and will be co-located with the OpenStack Summit in Vancouver. - - - -I was invited to participate in the program committee for OpenDev CI/CD based on my background on the CI/CD system for the OpenStack project and my recent move into the container space. Today I frequently talk about CI/CD pipelines using various open source technologies, including [Jenkins][3] [GitLab][2],[Spinnaker][4] , and [Artifactory][5] - -This event is exciting for me because we're bringing two open source infrastructure ideas together into one event. First, we'll be discussing CI/CD tooling that can be used by any organization. To this end, in the [keynotes][6] we'll hear practical talks about open source CI/CD tooling, including a talk about Spinnaker from Boris Renski and one from Jim Blair on [Zuul][7]. The keynotes also will include higher-level talks about the preference for open technologies, especially across communities and inside open source projects themselves. From Fatih Degirmenci and Daniel Farrell we'll hear about sharing continuous delivery practices across communities, and Benjamin Mako Hill will join us to talk about why free software needs free tools. - -Given the relative newness of CI/CD, the rest of the event is a mix of talks, workshops, and collaborative discussions. When selecting from talks and workshops submitted, and coming up with collaborative discussion topics, we wanted to make sure there was a diverse schedule so anyone on the open CI/CD spectrum would find something interesting. - -The talks will be standard conference style, selected to cover key topics like crafting CI/CD pipelines, improving security when practicing DevOps, and more specific solutions like container-based [Aptomi][8] on Kubernetes and doing CI/CD in ETSI NFV environments. Many of these sessions will serve as an introduction to these topics, ideal for those who are new to the CI/CD space or any of these specific technologies. - -The hands-on workshops are longer and will have specific outcomes in mind for attendees. These include "[Anomaly Detection in Continuous Integration Jobs][9]," "[How to Install Zuul and Configure Your First Jobs][10]," and "[Spinnaker 101: Releasing Software with Velocity and Confidence][11]." (Note that space is limited in these workshops, so an RSVP system has been set up. You'll find an RSVP button on the session links provided here.) - -Perhaps what I'm most excited about are the collaborative discussions, and these take up over half of the conference schedule. The topics were chosen by the program committee based on what we've been seeing in our communities. These are "fishbowl"-style sessions, where several people get in a room together to discuss a specific topic around CI/CD. - -The idea for this style of session was taken from developer summits that the Ubuntu community pioneered and the OpenStack community continued. Topics for these collaborative discussions include separate sessions for CI and CD fundamentals, improvements that can be made to encourage cross-community collaboration, driving CI/CD culture in organizations, and why open source CI/CD tooling is so important. Shared documents are used to take notes during these sessions to make sure that as much knowledge shared during the session is retained as possible. It's also common for action items to come from these discussions, so community members can push forward initiatives related to the topic being covered. - -The event concludes with a [Joint Conclusion Session][12], which will be summarizing the key points from the collaborative discussions and identifying work areas that attendees wish to work on in future. - -Registration for this event is included in [OpenStack Summit registration][13], or tickets for this event only can be purchased for $199 onsite at the Vancouver Convention Center. Learn more about tickets and the full agenda on the [OpenDev website][1]. - -I hope you'll join us in Vancouver for an exciting two days of learning, collaborating and making progress together on CI/CD. - --------------------------------------------------------------------------------- - -via: https://opensource.com/article/18/5/opendev - -作者:[Elizabeth K.Joseph][a] -选题:[lujun9972](https://github.com/lujun9972) -译者:[译者ID](https://github.com/译者ID) -校对:[校对者ID](https://github.com/校对者ID) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 - -[a]:https://opensource.com/users/pleia2 -[1]:http://2018.opendevconf.com/ -[2]:https://about.gitlab.com/ -[3]:https://jenkins.io/ -[4]:https://www.spinnaker.io/ -[5]:https://jfrog.com/artifactory/ -[6]:http://2018.opendevconf.com/schedule/ -[7]:https://zuul-ci.org/ -[8]:http://aptomi.io/ -[9]:https://www.openstack.org/summit/vancouver-2018/summit-schedule/events/21692/anomaly-detection-in-continuous-integration-jobs -[10]:https://www.openstack.org/summit/vancouver-2018/summit-schedule/events/21693/how-to-install-zuul-and-configure-your-first-jobs -[11]:https://www.openstack.org/summit/vancouver-2018/summit-schedule/events/21699/spinnaker-101-releasing-software-with-velocity-and-confidence -[12]:https://www.openstack.org/summit/vancouver-2018/summit-schedule/events/21831/opendev-cicd-joint-collab-conclusion -[13]:https://www.eventbrite.com/e/openstack-summit-may-2018-vancouver-tickets-40845826968?aff=VancouverSummit2018 diff --git a/sources/talk/20180620 3 pitfalls everyone should avoid with hybrid multi-cloud, part 2.md b/sources/talk/20180620 3 pitfalls everyone should avoid with hybrid multi-cloud, part 2.md new file mode 100644 index 0000000000..bc6d037ec4 --- /dev/null +++ b/sources/talk/20180620 3 pitfalls everyone should avoid with hybrid multi-cloud, part 2.md @@ -0,0 +1,68 @@ +3 pitfalls everyone should avoid with hybrid multi-cloud, part 2 +====== + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/clouds_hybrid.png?itok=RanzEhiu) + +This article was co-written with [Roel Hodzelmans][1]. + +Cloud hype is all around you—you're told it's critical to ensuring a digital future for your business. Whether you choose cloud, hybrid cloud, or hybrid multi-cloud, you have numerous decisions to make, even as you continue the daily work of enhancing your customers' experience and agile delivery of your applications (including legacy applications)—likely some of your business' most important resources. + +In this series, we explain three pitfalls everyone should avoid when transitioning to hybrid multi-cloud environments. [In part one][2], we defined the different cloud types and explained the differences between hybrid cloud and multi-cloud. Here, in part two, we will dive into the first pitfall: Why cost is not always the best motivator for moving to the cloud. + +### Why not? + +When looking at hybrid or multi-cloud strategies for your business, don't let cost become the obvious motivator. There are a few other aspects of any migration strategy that you should review when putting your plan together. But often budget rules the conversations. + +When giving this talk three times at conferences, we've asked our audience to answer a live, online questionnaire about their company, customers, and experiences in the field. Over 73% of respondents said cost was the driving factor in their business' decision to move to hybrid or multi-cloud. + +But, if you already have full control of your on-premises data centers, yet perpetually underutilize and overpay for resources, how can you expect to prevent those costs from rolling over into your cloud strategy? + +There are three main (and often forgotten, ignored, and unaccounted for) reasons cost shouldn't be the primary motivating factor for migrating to the cloud: labor costs, overcapacity, and overpaying for resources. They are important points to consider when developing a hybrid or multi-cloud strategy. + +### Labor costs + +Imagine a utility company making the strategic decision to move everything to the cloud within the next three years. The company kicks off enthusiastically, envisioning huge cost savings, but soon runs into labor cost issues that threaten to blow up the budget. + +One of the most overlooked aspects of moving to the cloud is the cost of labor to migrate existing applications and data. A Forrester study reports that labor costs can consume [over 50% of the total cost of a public cloud migration][3]. Forrester says, "customer-facing apps for systems of engagement… typically employ lots of new code rather than migrating existing code to cloud platforms." + +Step back and analyze what's essential to your customer success and move only that to the cloud. Then, evaluate all your non-essential applications and, over time, consider moving them to commercial, off-the-shelf solutions that require little labor cost. + +### Overcapacity + +"More than 80% of in-house data centers have [way more server capacity than is necessary][4]," reports Business Insider. This amazing bit of information should shock you to your core. + +What exactly is "way more" in this context? + +One hint comes from Deutsche Bank CTO Pat Healey, presenting at Red Hat Summit 2017. He talks about ordering hardware for the financial institution's on-premises data center, only to find out later that [usage numbers were in the single digits][5]. + +Healey is not alone; many companies have these problems. They don't do routine assessments, such as checking electricity, cooling, licensing, and other factors, to see how much capacity they are using on a consistent basis. + +### Overpaying + +Companies are paying an average of 36% more for cloud services than they need to, according to the Business Insider article mentioned above. + +One reason is that public cloud providers enthusiastically support customers coming agnostically into their cloud. As customers leverage more of the platform's cloud-native features, they reach a monetary threshold, and technical support drops off dramatically. + +It's a classic case of vendor lock-in, where the public cloud provider knows it is cost-prohibitive for the customer to migrate off its cloud, so it doesn't feel compelled to provide better service. + +### Coming up + +In part three of this series, we'll discuss the second of three pitfalls that everyone should avoid with hybrid multi-cloud. Stay tuned to learn why you should take care with moving everything to the cloud. + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/6/reasons-move-to-cloud + +作者:[Eric D.Schabell][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://opensource.com/users/eschabell +[1]:https://opensource.com/users/roelh +[2]:https://opensource.com/article/18/4/pitfalls-hybrid-multi-cloud +[3]:https://www.techrepublic.com/article/labor-costs-can-make-up-50-of-public-cloud-migration-is-it-worth-it/ +[4]:http://www.businessinsider.com/companies-waste-62-billion-on-the-cloud-by-paying-for-storage-they-dont-need-according-to-a-report-2017-11 +[5]:https://youtu.be/SPRUJ5Z-Aew diff --git a/sources/talk/20180626 How to build a professional network when you work in a bazaar.md b/sources/talk/20180626 How to build a professional network when you work in a bazaar.md deleted file mode 100644 index 0fa3323b0c..0000000000 --- a/sources/talk/20180626 How to build a professional network when you work in a bazaar.md +++ /dev/null @@ -1,95 +0,0 @@ - 翻译中 by ZenMoore -How to build a professional network when you work in a bazaar -====== - -![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/connection_people_team_collaboration.png?itok=0_vQT8xV) - -Professional social networking—creating interpersonal connections between work colleagues or professionals—can take many forms and span organizations across industries. Establishing professional networks takes time and effort, and when someone either joins or departs an organization, that person's networks often need to be rebuilt in a new work environment. - -Professional social networks perform similar functions in different organizations—information sharing, mentorship, opportunities, work interests, and more—but the methods and reasons for making particular connections in an organization can vary between conventional and open organizations. And these differences make a difference: to the way colleagues relate, to how they build trust, to the amount and kinds of diversity within the organization, and to the forces that create collaboration. All these elements are interrelated, and they contribute to and shape the social networks people form. - -An open organization's emphasis on inclusivity can produce networks more effective at solving business problems than those that emerge in conventional, hierarchical organizations. This notion has a long history in open source thinking. For example, in [The Cathedral and the Bazaar][1], Eric Raymond writes that "Sociologists years ago discovered that the averaged opinion of a mass of equally expert (or equally ignorant) observers is quite a bit more reliable a predictor than the opinion of a single randomly-chosen one of the observers." So let's examine how the structure and purpose of social networks impact what each type of organization values. - -### Social networks in conventional organizations - -When I worked in conventional organizations and would describe what I do for work, the first thing people asked me was how I was related to someone else, usually a director-level leader. "Is that under Hira?" they'd say. "Do you work for Malcolm?" That makes sense considering conventional organizations function in a "top-down" way; when trying to situate work or an employee, people wanted to understand the structure of the network from that top-down perspective. - -In other words, in conventional organizations the social network depends upon the hierarchical structure, so they track one another. In fact, even figuring out where an employee exists within a network is a very "top-down organization" kind of concern. - -But that isn't all that the underlying hierarchy does. It also vets associates. A focus on the top-down network can determine an employee's "value" in the network because the network itself is a system of ongoing power relations that grants people placed in its different locations varying levels of value. It downplays the value of individual talents and skills. Therefore, a person's connections in the conventional organization facilitate that person's ability to be proactive, heard, influential, and supported in their careers. - -An open organization's emphasis on inclusivity can produce networks more effective at solving business problems than those that emerge in conventional, hierarchical organizations. - -The conventional organization's formal structure defines employees' social networks in particular ways—some of which might be benefits, some of which might be disadvantages, depending on one's context—such as: - - * It's easier to know "who's who" and see how people are related more quickly (often this builds trusted networks within the particular hierarchy). - * Often, this increased understanding of relationships means there's less redundancy of work (projects have a clear owner embedded in a particular network) and communication (people know who is responsible for communicating what). - * Associates can feel "stuck" in a power structure, or like they can't "break into" power structures that sometimes (too often?) don't work, diminishing meritocracy. - * Crossing silos of work and effort is difficult and collaboration suffers. - * Power transfers slowly; a person's ability to engage is determined more in alignment with network created by the hierarchical structure than by other factors (like individual abilities), reducing what is considered "community" and the benefits of its membership. - * Competition seems more clear; understanding "who is vying for what" usually occurs within a recognized and delimited hierarchical structure (and the scarcity of positions in the power network increase competition so competition can be more fierce). - * Adaptability can suffer when a more rigid network defines the limits of flexibility; what the network "wants" and the limits of collaboration can be affected this same way. - * Execution occurs much more easily in rigid networks, where direction is clear and often leaders manage by overdirecting. - * Risk is decreased when the social networks are less flexible; people know what needs to happen, how, and when (but this isn't always "bad" considering the wide range of work in an organization; some job functions require less risk, such as HR, mergers and acquisitions, legal, etc.). - * Trust within the network is greater, especially when an employee is part of the formal network (when someone is not part of the network, exclusion can be particularly difficult to manage or to rectify). - - - -### Social networks in open organizations - -While open organizations can certainly have hierarchical structures, they don't operate only according to that network. Their professional networking structure is more flexible (or "all over and whenever"). - -An open organization is more associate-centric than leader-centric. - -In an open organization, when I've described what I do for work virtually no one asks "for whom?" An open organization is more associate-centric than leader-centric. Open values like inclusivity and specific governance systems like meritocracy contribute to this; it's not who you know but rather it's what you know and how you use it (e.g., "bottom-up"). In an open organization, I don't feel like I'm fighting to show my value; my ideas are inherently valuable. I sometimes have to demonstrate how using my idea is more valuable than using someone else's idea―but that means I'm vetting myself within the community of my associates (including leadership), rather than being vetted solely by top-down leadership. - -In this way, an open organization doesn't assess employees based on the network but rather on what they know of the associate as an individual. Does this person have good ideas? Does she work toward those ideas (lead them) by using the open organization values (that is, share those ideas and work across the organization to include others and work transparently, etc.)? - -Open organizations also structure social networks in particular ways (which, again, could be advantageous or disadvantageous depending on one's goals and desires), including: - - * People are more responsible for their networks, reputations, skills, and careers. - * Competition (for resources, power, promotions, etc.) decreases because these organizations are by nature more collaborative (even during a "collision," the best outcome is negotiation, not winning, and competition hones the ideas instead of creating wedges between people). - * Power is more fluid and dynamic, flowing from person to person (but this also means there can be a misunderstanding about accountability or responsibility and activities can go undone or unfinished because there is not a clear [sense of ownership][2]). - * Trust is created "one associate at a time," rather than through the reputation of the network in which the person is situated. - * Networks self-configure around a variety of work and activities, rising reactively around opportunity (this aids innovation but can add to confusion because who makes decisions, and who is in "control" is less clear). - * Rate of execution can decrease in confusing contexts because what to do and how and when to do it requires leadership skills in setting direction and creating engaged and skilled associates. - * Flexible social networks also increase innovation and risk; ideas circulate faster and are more novel, and execution is less assured. - * Trust is based on associate relationships (as it should be!), rather than on sheer deference to structure. - - - -### Making it work - -If you're thinking of transitioning from one type of organizational structure to another, consider the following when building and maintaining your professional social networks. - -#### Tips from conventional organizations - - * Structure and control around decision-making isn't a bad thing; operational frameworks need to be clear and transparent, and decision-makers need to account for their decisions. - * Excelling at execution requires managers to provide focus and the ability to provide sufficient context while filtering out anything that could distract or confuse. - * Established networks help large groups of people work in concert and manage risk. - - - -#### Tips from open organizations - - * Strong leaders are those who can provide different levels of clarity and guidance according to the various styles and preferences of associates and teams without creating inflexible networks. - * Great ideas win more, not established networks. - * People are more responsible for their reputations. - * The circulation of ideas and information is key to innovation. Loosening the networks in your organization can help these two elements occur with increased frequency and breadth. - - - --------------------------------------------------------------------------------- - -via: https://opensource.com/open-organization/18/6/building-professional-social-networks-openly - -作者:[Heidi Hess;von Ludewig][a] -选题:[lujun9972](https://github.com/lujun9972) -译者:[译者ID](https://github.com/译者ID) -校对:[校对者ID](https://github.com/校对者ID) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 - -[a]:https://opensource.com/users/heidi-hess-von-ludewig -[1]:http://www.catb.org/~esr/writings/cathedral-bazaar/cathedral-bazaar/ar01s04.html -[2]:https://opensource.com/open-organization/18/4/rethinking-ownership-across-organization diff --git a/sources/talk/20180627 World Cup football on the command line.md b/sources/talk/20180627 World Cup football on the command line.md deleted file mode 100644 index 849663f231..0000000000 --- a/sources/talk/20180627 World Cup football on the command line.md +++ /dev/null @@ -1,74 +0,0 @@ - 翻译中 by ZenMoore -World Cup football on the command line -====== - -![](https://i2.wp.com/www.linuxlinks.com/wp-content/uploads/2018/06/football-wc2018.jpg?resize=700%2C450&ssl=1) - -Football is around us constantly. Even when domestic leagues have finished, there’s always a football score I want to know. Currently, it’s the biggest football tournament in the world, the Fifa World Cup 2018, hosted in Russia. Every World Cup there are some great football nations that don’t manage to qualify for the tournament. This time around the Italians and the Dutch missed out. But even in non-participating countries, it’s a rite of passage to keep track of the latest scores. I also like to keep abreast of the latest scores from the major leagues around the world without having to search different websites. - -![Command-Line Interface][2]If you’re a big fan of the command-line, what better way to keep track of the latest World Cup scores and standings with a small command-line utility. Let’s take a look at one of the hottest trending football utilities available. It’s goes by the name football-cli. - -If you’re a big fan of the command-line, what better way to keep track of the latest World Cup scores and standings with a small command-line utility. Let’s take a look at one of the hottest trending football utilities available. It’s goes by the name football-cli. - -football-cli is not a groundbreaking app. Over the years, there’s been a raft of command line tools that let you keep you up-to-date with the latest football scores and league standings. For example, I am a heavy user of soccer-cli, a Python based tool, and App-Football, written in Perl. But I’m always looking on the look out for trending apps. And football-cli stands out from the crowd in a few ways. - -football-cli is developed in JavaScript and written by Manraj Singh. It’s open source software, published under the MIT license. Installation is trivial with npm (the package manager for JavaScript), so let’s get straight into the action. - -The utility offers commands that give scores of past and live fixtures, see upcoming and past fixtures of a league and team. It also displays standings of a particular league. There’s a command that lists the various supported competitions. Let’s start with the last command. - -At a shell prompt. - -`luke@ganges:~$ football lists` - -![football-lists][3] - -The World Cup is listed at the bottom. I missed yesterday’s games, so to catch up on the scores, I type at a shell prompt: - -`luke@ganges:~$ football scores` - -![football-wc-22][4] - -Now I want to see the current World Cup group standings. That’s easy. - -`luke@ganges:~$ football standings -l WC` - -Here’s an excerpt of the output: - -![football-wc-table][5] - -The eagle-eyed among you may notice a bug here. Belgium is showing as the leader of Group G. But this is not correct. Belgium and England are (at the time of writing) both tied on points, goal difference, and goals scored. In this situation, the team with the better disciplinary record is ranked higher. England and Belgium have received 2 and 3 yellow cards respectively, so England top the group. - -Suppose I want to find out Liverpool’s results in the Premiership going back 90 days from today. - -`luke@ganges:~$ football fixtures -l PL -d 90 -t "Liverpool"` - -![football-Liverpool][6] - -I’m finding the utility really handy, displaying the scores and standings in a clear, uncluttered, and attractive way. When the European domestic games start up again, it’ll get heavy usage. (Actually, the 2018-19 Champions League is already underway)! - -These few examples give a taster of the functionality available with football-cli. Read more about the utility from the developer’s **[GitHub page][7].** Football + command-line = football-cli - -Like similar tools, the software retrieves its football data from football-data.org. This service provide football data for all major European leagues in a machine-readable way. This includes fixtures, teams, players, results and more. All this information is provided via an easy-to-use RESTful API in JSON representation. - - --------------------------------------------------------------------------------- - -via: https://www.linuxlinks.com/football-cli-world-cup-football-on-the-command-line/ - -作者:[Luke Baker][a] -选题:[lujun9972](https://github.com/lujun9972) -译者:[译者ID](https://github.com/译者ID) -校对:[校对者ID](https://github.com/校对者ID) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 - -[a]:https://www.linuxlinks.com/author/luke-baker/ -[1]:https://www.linuxlinks.com/wp-content/plugins/jetpack/modules/lazy-images/images/1x1.trans.gif -[2]:https://i0.wp.com/www.linuxlinks.com/wp-content/uploads/2017/12/CLI.png?resize=195%2C171&ssl=1 -[3]:https://i2.wp.com/www.linuxlinks.com/wp-content/uploads/2018/06/football-lists.png?resize=595%2C696&ssl=1 -[4]:https://i2.wp.com/www.linuxlinks.com/wp-content/uploads/2018/06/football-wc-22.png?resize=634%2C75&ssl=1 -[5]:https://i0.wp.com/www.linuxlinks.com/wp-content/uploads/2018/06/football-wc-table.png?resize=750%2C581&ssl=1 -[6]:https://i1.wp.com/www.linuxlinks.com/wp-content/uploads/2018/06/football-Liverpool.png?resize=749%2C131&ssl=1 -[7]:https://github.com/ManrajGrover/football-cli -[8]:https://www.linuxlinks.com/links/Software/ -[9]:https://discord.gg/uN8Rqex diff --git a/sources/talk/20180703 What Game of Thrones can teach us about open innovation.md b/sources/talk/20180703 What Game of Thrones can teach us about open innovation.md new file mode 100644 index 0000000000..120c4df0f3 --- /dev/null +++ b/sources/talk/20180703 What Game of Thrones can teach us about open innovation.md @@ -0,0 +1,49 @@ +What Game of Thrones can teach us about open innovation +====== + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/osdc_thinklaterally_520x292.jpg?itok=JkbRl5KU) + +You might think the only synergy one can find in Game of Thrones is that between Jaime Lannister and his sister, Cersei. Characters in the show's rotating cast don't see many long term relationships, as they're killed off, betrayed, and otherwise trading loyalty in an effort to stay alive. Even the Stark children, siblings suffering from the deaths of their parents, don't really get along most of the time. + +But there's something about the chaotic free-for-all of constantly shifting loyalties in Game of Thrones that lends itself to a thought exercise: How can we always be aligning disparate positions in order to innovate? + +Here are three ways Game of Thrones illustrates behaviors that lead to innovation. + +### Join forces + +Aria Stark has no loyalties. Through the death of her parents and separation from her siblings, young Aria demonstrates courage in pursuing an education with the faceless man. And she's rewarded for her courage with the development of seemingly supernatural abilities. + +Aria's hate for the people on her list has her innovating left and right in an attempt to get closer to them. As the audience, we're on Aria's side; despite her violent and deadly methods, we identify with her attempts to overcome hardship. Her determination makes us loyal fans, and in an open organization, courage and determination like hers would be rewarded with some well-deserved influence. + +Being loyal and helpful to driven people like Aria will help you and (by extension) your organization innovate. Passion is infectious. + +### Be nimble + +The Lannisters represent a traditional management structure that forcibly resists innovation. Their resistance is usually the result of their fear of change. + +Without a doubt, change is scary—especially to people who wield power in an organization. Losing status causes us fear, because in our evolutionary and social history, losing status could mean that we would be unable to survive. But look to Tyrion as an example of how to thrive once status is lost. + +There's something about the chaotic free-for-all of constantly shifting loyalties in Game of Thrones that lends itself to a thought exercise: How can we always be aligning disparate positions in order to innovate? + +Tyrion is cast out (demoted) by his family (the senior executive team). Instead of lamenting his loss of power, he seeks out a community (by the side of Daenerys) that values (and can utilize) his unique skills, connections, and influences. His resilience in the face of being cast out of Casterly Rock is the perfect metaphor for how innovation occurs: It's iterative and never straightforward. It requires resilience. A more open source way to say this would be: "fail forward," or "release early, release often." + +### Score resources + +Daenerys Targaryen embodies all the necessary traits for successful innovation. She can be seen as a model for the kind of employee that thrives in an open organization. What the Mother of Dragons needs, the Mother of Dragons gets, and she doesn't compromise her ideals to do it. + +Whether freeing slaves (and then asking for their help) or forming alliances to acquire transport vehicles she's never seen before, Daenerys is resourceful. In an open organization, a staff member needs to have the wherewithal to get things done. Colleagues (even the entire organization) may not always share your priorities, but innovation happens when people take risks. Becoming a savvy negotiator like Khaleesi, and developing a willingness to trade a lot for a little (she's been known to do favors for the mere promise of loyalty), you can get things done, fail forward, and innovate. + +Courage, resilience, and resourcefulness are necessary traits for innovating in an open organization. What else can Game of Thrones teach us about working—and succeeding—openly? + +-------------------------------------------------------------------------------- + +via: https://opensource.com/open-organization/18/7/open-innovation-lessons-game-of-thrones + +作者:[Laura Hilliger][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://opensource.com/users/laurahilliger diff --git a/sources/talk/20180704 Comparing Twine and Ren-Py for creating interactive fiction.md b/sources/talk/20180704 Comparing Twine and Ren-Py for creating interactive fiction.md new file mode 100644 index 0000000000..f4bf136f51 --- /dev/null +++ b/sources/talk/20180704 Comparing Twine and Ren-Py for creating interactive fiction.md @@ -0,0 +1,70 @@ +Comparing Twine and Ren'Py for creating interactive fiction +====== + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/book_list_fiction_sand_vacation_read.jpg?itok=IViIZu8J) + +Any experienced technology educator knows engagement and motivation are key to a student's learning. Of the many techniques for stimulating engagement and motivation among learners, storytelling and game creation have good track records of success, and writing interactive fiction is a great way to combine both of those techniques. + +Interactive fiction has a respectable history in computing, stretching back to the text-only adventure games of the early 1980s, and it's enjoyed a new popularity recently. There are many technology tools that can be used for writing interactive fiction, but the two that will be considered here, [Twine][1] and [Ren'Py][2], are ideal for the task. Each has different strengths that make it more attractive for particular types of projects. + +### Twine + +![Twine 2.0][4] + +![][5] + +Twine is a popular cross-platform open source interactive fiction system that developed out of the HTML- and JavaScript-based [TiddlyWiki][6]. If you're not familiar with Twine, multimedia artist and Opensource.com contributor Seth Kenlon's article on how he [uses Twine to create interactive adventure games][7] is a great introduction to the tool. + +One of Twine's advantages is that it produces a single, compiled HTML file, which makes it easy to distribute and play an interactive fiction work on any system with a reasonably modern web browser. But this comes at a cost: While it will support graphics, sound files, and embedded video, Twine is somewhat limited by its roots as a primarily text-based system (even though it has developed a lot over the years). + +This is very appealing to new learners who can rapidly produce something that looks good and is fun to play. However, when they want to add visual effects, graphics, and multimedia, learners can get lost among the different, creative ways to do this and the maze of different Twine program versions and story formats. Even so, there's an impressive amount of resources available on how to use Twine. + +Educators often hope learners will take the skills they have gained using one tool and build on them, but this isn't a strength for Twine. While Twine is great for developing literacy and creative writing skills, the coding and programming side is weaker. The story format scripting language has what you would expect: logic commands, conditional statements, arrays/lists, and loops, but it is not closely related to any popular programming language. + +### Ren'Py + +![Ren'Py 7.0][9] + +![][5] + +Ren'Py approaches interactive fiction from a different angle; [Wikipedia][10] describes it as a "visual novel engine." This means that the integration of graphics and other multimedia elements is a lot smoother and more integrated than in Twine. In addition, as Opensource.com contributor Joshua Allen Holm explained, [you don't need much coding experience][11] to use Ren'Py. + +Ren'Py can export finished work for Android, Linux, Mac, and Windows, which is messier than the "one file for all systems" that comes from Twine, particularly if you get into the complexity of making builds for mobile devices. Bear in mind, too, that finished Ren'Py projects with their multimedia elements are a lot bigger than Twine projects. + +The ease of downloading graphics and multimedia files from the internet for Ren'Py projects also provides a great opportunity to teach learners about the complexities of copyright and advocate (as everyone should!) for [Creative Commons][12] licenses. + +As its name suggests, Ren'Py's scripting languages are a mix of true Python and Python-like additions. This will be very attractive to educators who want learners to progress to Python programming. Python's syntatical rules and strict enforcement of indentation are more intimidating to use than the scripting options in Twine, but the long-term gains are worth it. + +### Comparing Twine and Ren'Py + +There are various reasons why Twine has become so successful, but one that will appeal to open source enthusiasts is that anyone can take a compiled Twine story or game and import it back into Twine. This means if you come across a compiled Twine story or game with a neat feature, you can look at the source code and find out how it was done. Ren'Py allows a level of obfuscation that prevents low-level attempts at hacking. + +When it comes to my work helping people with visual impairments use technology, Ren'Py is superior to Twine. Despite claims to the contrary, Twine's HTML files can be used by screen reader users—but only with difficulty. In contrast, Ren'Py has built-in self-voicing capabilities, something that I am very pleased to see, although Linux users may need to add the [eSpeak package][13] to support it. + +Ren'Py and Twine can be used for similar purposes. Text-based projects tend to be simpler and quicker to create than ones that require creating or sourcing graphics and multimedia elements. If your projects will be more text-based, Twine might be the best choice. And, if your projects make extensive use of graphics and multimedia elements, Ren'Py might suit you better. + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/7/twine-vs-renpy-interactive-fiction + +作者:[Peter Cheer][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://opensource.com/users/petercheer +[1]:http://twinery.org/ +[2]:https://www.renpy.org/ +[3]:/file/402696 +[4]:https://opensource.com/sites/default/files/uploads/twine2.png (Twine 2.0) +[5]:data:image/gif;base64,R0lGODlhAQABAPABAP///wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw== (Click and drag to move) +[6]:https://tiddlywiki.com/ +[7]:https://opensource.com/article/18/2/twine-gaming +[8]:/file/402701 +[9]:https://opensource.com/sites/default/files/uploads/renpy.png (Ren'Py 7.0) +[10]:https://en.wikipedia.org/wiki/Ren%27Py +[11]:https://opensource.com/life/13/8/gaming-renpy +[12]:https://creativecommons.org/ +[13]:http://espeak.sourceforge.net/ diff --git a/sources/talk/20180705 New Training Options Address Demand for Blockchain Skills.md b/sources/talk/20180705 New Training Options Address Demand for Blockchain Skills.md new file mode 100644 index 0000000000..dedbf748d6 --- /dev/null +++ b/sources/talk/20180705 New Training Options Address Demand for Blockchain Skills.md @@ -0,0 +1,45 @@ +New Training Options Address Demand for Blockchain Skills +====== + +![](https://www.linux.com/sites/lcom/files/styles/rendered_file/public/blockchain-301.png?itok=1EA-Ob6F) + +Blockchain technology is transforming industries and bringing new levels of trust to contracts, payment processing, asset protection, and supply chain management. Blockchain-related jobs are the second-fastest growing in today’s labor market, [according to TechCrunch][1]. But, as in the rapidly expanding field of artificial intelligence, there is a pronounced blockchain skills gap and a need for expert training resources. + +### Blockchain for Business + +A new training option was recently announced from The Linux Foundation. Enrollment is now open for a free training course called[Blockchain: Understanding Its Uses and Implications][2], as well as a [Blockchain for Business][2] professional certificate program. Delivered through the edX training platform, the new course and program provide a way to learn about the impact of blockchain technologies and a means to demonstrate that knowledge. Certification, in particular, can make a difference for anyone looking to work in the blockchain arena. + +“In the span of only a year or two, blockchain has gone from something seen only as related to cryptocurrencies to a necessity for businesses across a wide variety of industries,” [said][3] Linux Foundation General Manager, Training & Certification Clyde Seepersad. “Providing a free introductory course designed not only for technical staff but business professionals will help improve understanding of this important technology, while offering a certificate program through edX will enable professionals from all over the world to clearly demonstrate their expertise.” + +TechCrunch [also reports][4] that venture capital is rapidly flowing toward blockchain-focused startups. And, this new program is designed for business professionals who need to understand the potential – or threat – of blockchain to their company and industry. + +“Professional Certificate programs on edX deliver career-relevant education in a flexible, affordable way, by focusing on the critical skills industry leaders and successful professionals are seeking today,” said Anant Agarwal, edX CEO and MIT Professor. + +### Hyperledger Fabric + +The Linux Foundation is steward to many valuable blockchain resources and includes some notable community members. In fact, a recent New York Times article — “[The People Leading the Blockchain Revolution][5]” — named Brian Behlendorf, Executive Director of The Linux Foundation’s [Hyperledger Project][6], one of the [top influential voices][7] in the blockchain world. + +Hyperledger offers proven paths for gaining credibility and skills in the blockchain space. For example, the project offers a free course titled Introduction to Hyperledger Fabric for Developers. Fabric has emerged as a key open source toolset in the blockchain world. Through the Hyperledger project, you can also take the B9-lab Certified Hyperledger Fabric Developer course. More information on both courses is available [here][8]. + +“As you can imagine, someone needs to do the actual coding when companies move to experiment and replace their legacy systems with blockchain implementations,” states the Hyperledger website. “With training, you could gain serious first-mover advantage.” + +-------------------------------------------------------------------------------- + +via: https://www.linux.com/blog/2018/7/new-training-options-address-demand-blockchain-skills + +作者:[SAM DEAN][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.linux.com/users/sam-dean +[1]:https://techcrunch.com/2018/02/14/blockchain-engineers-are-in-demand/ +[2]:https://www.edx.org/course/understanding-blockchain-and-its-implications +[3]:https://www.linuxfoundation.org/press-release/as-demand-skyrockets-for-blockchain-expertise-the-linux-foundation-and-edx-offer-new-introductory-blockchain-course-and-blockchain-for-business-professional-certificate-program/ +[4]:https://techcrunch.com/2018/05/20/with-at-least-1-3-billion-invested-globally-in-2018-vc-funding-for-blockchain-blows-past-2017-totals/ +[5]:https://www.nytimes.com/2018/06/27/business/dealbook/blockchain-stars.html +[6]:https://www.hyperledger.org/ +[7]:https://www.linuxfoundation.org/blog/hyperledgers-brian-behlendorf-named-as-top-blockchain-influencer-by-new-york-times/ +[8]:https://www.hyperledger.org/resources/training diff --git a/sources/talk/20180713 What-s the difference between a fork and a distribution.md b/sources/talk/20180713 What-s the difference between a fork and a distribution.md new file mode 100644 index 0000000000..f7f50e014b --- /dev/null +++ b/sources/talk/20180713 What-s the difference between a fork and a distribution.md @@ -0,0 +1,81 @@ +What's the difference between a fork and a distribution? +====== + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/spoons_forks_520x292_jh.png?itok=DzEzZBuG) + +If you've been around open source software for any length of time, you'll hear the terms fork and distribution thrown around casually in conversation. For many people, the distinction between the two isn't clear, so here I'll try to clear up the confusion. + +### First, some definitions + +Before explaining the nuances of a fork vs. a distribution and the pitfalls thereof, let's define key concepts. + +**[Open source software][1]** is software that: + + * Is freely available to distribute under certain [license][2] restraints + * Permits its source code to be viewable and modified under certain license restraints + + + +Open source software can be **consumed** in the following ways: + + * Downloaded in binary or source code format, often at no charge (e.g., the [Eclipse developer environment][3]) + * As a distribution (product) by a vendor, sometimes at a cost to the user (e.g., [Red Hat products][4]) + * Embedded into proprietary software solutions (e.g., some smartphones and browsers display fonts using the open source [freetype software][5]) + + + +**Free and open source (FOSS)** is not necessarily "free" as in "zero cost." Free and open source simply means the software is free to distribute, modify, study, and use, subject to the software's licensing. The software distributor may attach a purchase price to it. For example, Linux is available at no cost as Fedora, CentOS, Gentoo, etc. or as a paid distribution as Red Hat Enterprise Linux, SUSE, etc. + +**Community** refers to the organizations and individuals that collaboratively work on an open source project. Any individual or organization can contribute to the project by writing or reviewing code, documentation, test suites, managing meetings, updating websites, etc., provided they abide by the license. For example, at [Openhub.net][6], we see government, nonprofit, commercial, and education organizations [contributing to some open source projects][7]. + +**project** is the result of this collaborative development, documentation, and testing. Most projects have a central repository where code, documentation, testing, and so forth are developed. + +An open sourceis the result of this collaborative development, documentation, and testing. Most projects have a central repository where code, documentation, testing, and so forth are developed. + +A **distribution** is a copy, in binary or source code format, of an open source project. For example, CentOS, Fedora, Red Hat Enterprise Linux, SUSE, Ubuntu, and others are distributions of the Linux project. Tectonic, Google Kubernetes Engine, Amazon Container Service, and Red Hat OpenShift are distributions of the Kubernetes project. + +Vendor distributions of open source projects are often called **products** , thus Red Hat OpenStack Platform is the Red Hat OpenStack product that is a distribution of the OpenStack upstream project—and it is still 100% open source. + +The **trunk** is the main workstream in the community where the open source project is developed. + +An open source **fork** is a version of the open source project that is developed along a separate workstream from the main trunk. + +Thus, **a distribution is not the same as a fork**. A distribution is a packaging of the upstream project that is made available by vendors, often as products. However, the core code and documentation in the distribution adhere to the version in the upstream project. A fork—and any distribution based on the fork—results in a version of the code and documentation that are different from the upstream project. Users who have forked upstream open source code have to maintain it on their own, meaning they lose the benefit of the collaboration that takes place in the upstream community. + +To further explain a software fork, let's use the analogy of migrating animals. Whales and sea lions migrate from the Arctic to California and Mexico; Monarch butterflies migrate from Alaska to Mexico; and (in the Northern Hemisphere) swallows and many other birds fly south for the winter. The key to a successful migration is that all animals in the group stick together, follow the leaders, find food and shelter, and don't get lost. + +### Risks of going it on your own + +A bird, butterfly, or whale that strays from the group loses the benefit of remaining with the group and knowing where to find food, shelter, and the desired destination. + +Similarly, users or organizations that fork and modify an upstream project and maintain it on their own run the following risks: + + 1. **They cannot update their code based on the upstream because their code differs.** This is known as technical debt; the more changes made to forked code, the more it costs in time and money to rebase the fork to the upstream project. + 2. **They potentially run less secure code.** If a vulnerability is found in open source code and fixed by the community in the upstream, a forked version of the code may not benefit from this fix because it is different from the upstream. + 3. **They might not benefit from new features.** The upstream community, using input from many organizations and individuals, creates new features for the benefit of all users of the upstream project. If an organization forks the upstream, they potentially cannot incorporate the new features because their code differs. + 4. **They might not integrate with other software packages.** Open source projects are rarely developed as single entities; rather they often are packaged together with other projects to create a solution. Forked code may not be able to be integrated with other projects because the developers of the forked code are not collaborating in the upstream with other participants. + 5. **They might not certify on hardware platforms.** Software packages are often certified to run on hardware platforms so, if problems arise, the hardware and software vendors can collaborate to find the root cause or problem. + + + +In summary, an open source distribution is simply a packaging of an upstream, multi-organizational, collaborative open source project sold and supported by a vendor. A fork is a separate development workstream of an open source project and risks not being able to benefit from the collaborative efforts of the upstream community. + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/7/forks-vs-distributions + +作者:[Jonathan Gershater][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://opensource.com/users/jgershat +[1]:https://opensource.com/resources/what-open-source +[2]:https://opensource.com/tags/licensing +[3]:https://www.eclipse.org/che/getting-started/download/ +[4]:https://access.redhat.com/downloads +[5]:https://www.freetype.org/ +[6]:http://openhub.net +[7]:https://www.openhub.net/explore/orgs diff --git a/sources/talk/20180717 Tips for Success with Open Source Certification.md b/sources/talk/20180717 Tips for Success with Open Source Certification.md new file mode 100644 index 0000000000..ad2ec2738b --- /dev/null +++ b/sources/talk/20180717 Tips for Success with Open Source Certification.md @@ -0,0 +1,63 @@ +Tips for Success with Open Source Certification +====== + +![](https://www.linux.com/sites/lcom/files/styles/rendered_file/public/desktop_1.jpg?itok=Nf2yTUar) + +In today’s technology arena, open source is pervasive. The [2018 Open Source Jobs Report][1] found that hiring open source talent is a priority for 83 percent of hiring managers, and half are looking for candidates holding certifications. And yet, 87 percent of hiring managers also cite difficulty in finding the right open source skills and expertise. This article is the second in a weekly series on the growing importance of open source certification. + +In the [first article][2], we focused on why certification matters now more than ever. Here, we’ll focus on the kinds of certifications that are making a difference, and what is involved in completing necessary training and passing the performance-based exams that lead to certification, with tips from Clyde Seepersad, General Manager of Training and Certification at The Linux Foundation. + +### Performance-based exams + +So, what are the details on getting certified and what are the differences between major types of certification? Most types of open source credentials and certification that you can obtain are performance-based. In many cases, trainees are required to demonstrate their skills directly from the command line. + +“You're going to be asked to do something live on the system, and then at the end, we're going to evaluate that system to see if you were successful in accomplishing the task,” said Seepersad. This approach obviously differs from multiple choice exams and other tests where candidate answers are put in front of you. Often, certification programs involve online self-paced courses, so you can learn at your own speed, but the exams can be tough and require demonstration of expertise. That’s part of why the certifications that they lead to are valuable. + +### Certification options + +Many people are familiar with the certifications offered by The Linux Foundation, including the [Linux Foundation Certified System Administrator][3] (LFCS) and [Linux Foundation Certified Engineer][4] (LFCE) certifications. The Linux Foundation intentionally maintains separation between its training and certification programs and uses an independent proctoring solution to monitor candidates. It also requires that all certifications be renewed every two years, which gives potential employers confidence that skills are current and have been recently demonstrated. + +“Note that there are no prerequisites,” Seepersad said. “What that means is that if you're an experienced Linux engineer, and you think the LFCE, the certified engineer credential, is the right one for you…, you're allowed to do what we call ‘challenge the exams.’ If you think you're ready for the LFCE, you can sign up for the LFCE without having to have gone through and taken and passed the LFCS.” + +Seepersad noted that the LFCS credential is great for people starting their careers, and the LFCE credential is valuable for many people who have experience with Linux such as volunteer experience, and now want to demonstrate the breadth and depth of their skills for employers. He also said that the LFCS and LFCE coursework prepares trainees to work with various Linux distributions. Other certification options, such as the [Kubernetes Fundamentals][5] and [Essentials of OpenStack Administration][6]courses and exams, have also made a difference for many people, as cloud adoption has increased around the world. + +Seepersad added that certification can make a difference if you are seeking a promotion. “Being able show that you're over the bar in terms of certification at the engineer level can be a great way to get yourself into the consideration set for that next promotion,” he said. + +### Tips for Success + +In terms of practical advice for taking an exam, Seepersad offered a number of tips: + + * Set the date, and don’t procrastinate. + + * Look through the online exam descriptions and get any training needed to be able to show fluency with the required skill sets. + + * Practice on a live Linux system. This can involve downloading a free terminal emulator or other software and actually performing tasks that you will be tested on. + + + + +Seepersad also noted some common mistakes that people make when taking their exams. These include spending too long on a small set of questions, wasting too much time looking through documentation and reference tools, and applying changes without testing them in the work environment. + +With open source certification playing an increasingly important role in securing a rewarding career, stay tuned for more certification details in this article series, including how to prepare for certification. + +[Learn more about Linux training and certification.][7] + +-------------------------------------------------------------------------------- + +via: https://www.linux.com/blog/sysadmin-cert/2018/7/tips-success-open-source-certification + +作者:[Sam Dean][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.linux.com/users/sam-dean +[1]:https://www.linuxfoundation.org/publications/open-source-jobs-report-2018/ +[2]:https://www.linux.com/blog/sysadmin-cert/2018/7/5-reasons-open-source-certification-matters-more-ever +[3]:https://training.linuxfoundation.org/certification/lfcs +[4]:https://training.linuxfoundation.org/certification/lfce +[5]:https://training.linuxfoundation.org/linux-courses/system-administration-training/kubernetes-fundamentals +[6]:https://training.linuxfoundation.org/linux-courses/system-administration-training/openstack-administration-fundamentals +[7]:https://training.linuxfoundation.org/certification diff --git a/sources/talk/20180719 Finding Jobs in Software.md b/sources/talk/20180719 Finding Jobs in Software.md new file mode 100644 index 0000000000..f1eff9caee --- /dev/null +++ b/sources/talk/20180719 Finding Jobs in Software.md @@ -0,0 +1,91 @@ +translating by lujun9972 +Finding Jobs in Software +====== + +A [PDF of this article][1] is available. + +I was back home in Lancaster last week, chatting with a [friend from grad school][2] who’s remained in academia, and naturally we got to talking about what advice he could give his computer science students to better prepare them for their probable future careers. + +In some later follow-up emails we got to talking about how engineers find jobs. I’ve fielded this question about a dozen times over the last couple years, so I thought it was about time to crystallize it into a blog post for future linking. + +Here are some strategies for finding jobs, ordered roughly from most to least useful: + +### Friend-of-a-friend networking + +Many of the best jobs never make it to the open market at all, and it’s all about who you know. This makes sense for employers, since good engineers are hard to find and a reliable reference can be invaluable. + +In the case of my current job at Iterable, for example, a mutual colleague from thoughtbot (a previous employer) suggested that I should talk to Iterable’s VP of engineering, since he’d worked with both of us and thought we’d get along well. We did, and I liked the team, so I went through the interview process and took the job. + +Like many companies, thoughtbot has an alumni Slack group with a `#job-board` channel. Those sorts of semi-formal corporate alumni networks can definitely be useful, but you’ll probably find yourself relying more on individual connections. + +“Networking” isn’t a dirty word, and it’s not about handing out business cards at a hotel bar. It’s about getting to know people in a friendly and sincere way, being interested in them, and helping them out (by, say, writing a lengthy blog post about how their students might find jobs). I’m not the type to throw around words like karma, but if I were, I would. + +Go to (and speak at!) [meetups][3], offer help and advice when you can, and keep in touch with friends and ex-colleagues. In a couple of years you’ll have a healthy network. Easy-peasy. + +This strategy doesn’t usually work at the beginning of a career, of course, but new grads and students should know that it’s eventually how things happen. + +### Applying directly to specific companies + +I keep a text file of companies where I might want to work. As I come across companies that catch my eye, I add ‘em to the list. When I’m on the hunt for a new job I just consult my list. + +Lots of things might convince me to add a company to the list. They might have an especially appealing mission or product, use some particular technology, or employ some specific people that I’d like to work with and learn from. + +One shockingly good heuristic that identifies a great workplace is whether a company sponsors or organizes meetups, and specifically if they sponsor groups related to minorities in tech. Plenty of great companies don’t do that, and they still may be terrific, but if they do it’s an extremely good sign. + +### Job boards + +I generally don’t use job boards, myself, because I find networking and targeted applications to be more valuable. + +The big sites like Indeed and Dice are rarely useful. While some genuinely great companies do cross-post jobs there, there are so many atrocious jobs mixed in that I don’t bother with them. + +However, smaller and more targeted job boards can be really handy. Someone has created a job site for any given technology (language, framework, database, whatever). If you’re really interested in working with a specific tool or in a particular market niche, it might be worthwhile for you to track down the appropriate board. + +Similarly, if you’re interested in remote work, there are a few boards that cater specifically to that. [We Work Remotely][4] is a prominent and reputable one. + +The enormously popular tech news site [Hacker News][5] posts a monthly “Who’s Hiring?” thread ([an example][6]). HN focuses mainly on startups and is almost adorably obsessed with trends, tech-wise, so it’s a thoroughly biased sample, but it’s still a huge selection of relatively high-quality jobs. Browsing it can also give you an idea of what technologies are currently in vogue. Some folks have also built [sites that make it easier to filter][7] those listings. + +### Recruiters + +These are the folks that message you on LinkedIn. Recruiters fall into two categories: internal and external. + +An internal recruiter is an employee of a specific company and hires engineers to work for that company. They’re almost invariably non-technical, but they often have a fairly clear idea of what technical skills they’re looking for. They have no idea who you are, or what your goals are, but they’re encouraged to find a good fit for the company and are generally harmless. + +It’s normal to work with an internal recruiter as part of the application process at a software company, especially a larger one. + +An external recruiter works independently or for an agency. They’re market makers; they have a stable of companies who have contracted with them to find employees, and they get a placement fee for every person that one of those companies hires. As such, they have incentives to make as many matches as possible as quickly as possible, and they rarely have to deal with the fallout if the match isn’t a good one. + +In my experience they add nothing to the job search process and, at best, just gum up the works as unnecessary middlemen. Less reputable ones may edit your resume without your approval, forward it along to companies that you’d never want to work with, and otherwise mangle your reputation. I avoid them. + +Helpful and ethical external recruiters are a bit like UFOs. I’m prepared to acknowledge that they might, possibly, exist, but I’ve never seen one myself or spoken directly with anyone who’s encountered one, and I’ve only heard about them through confusing and doubtful chains of testimonials (and such testimonials usually make me question the testifier more than my assumptions). + +### University career services + +I’ve never found these to be of any use. The software job market is extraordinarily specialized, and it’s virtually impossible for a career services employee (who needs to be able to place every sort of student in every sort of job) to be familiar with it. + +A recruiter, whose purview is limited to the software world, will often try to estimate good matches by looking at resume keywords like “Python” or “natural language processing.” A university career services employee needs to rely on even more amorphous keywords like “software” or “programming.” It’s hard for a non-technical person to distinguish a job engineering compilers from one hooking up printers. + +Exceptions exist, of course (MIT and Stanford, for example, have predictably excellent software-specific career services), but they’re thoroughly exceptional. + +There are plenty of other ways to find jobs, of course (job fairs at good industrial conferences—like [PyCon][8] or [Strange Loop][9]—aren’t bad, for example, though I’ve never taken a job through one). But the avenues above are the most common ways that job-finding happens. Good luck! + +-------------------------------------------------------------------------------- + +via: https://harryrschwartz.com/2018/07/19/finding-jobs-in-software.html + +作者:[Harry R. Schwartz][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[lujun9972](https://github.com/lujun9972) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://harryrschwartz.com/ +[1]:https://harryrschwartz.com/assets/documents/articles/finding-jobs-in-software.pdf +[2]:https://www.fandm.edu/ed-novak +[3]:https://meetup.com +[4]:https://weworkremotely.com +[5]:https://news.ycombinator.com +[6]:https://news.ycombinator.com/item?id=13764728 +[7]:https://www.hnhiring.com +[8]:https://us.pycon.org +[9]:https://thestrangeloop.com diff --git a/sources/talk/20180724 Open Source Certification- Preparing for the Exam.md b/sources/talk/20180724 Open Source Certification- Preparing for the Exam.md new file mode 100644 index 0000000000..2abcaa7693 --- /dev/null +++ b/sources/talk/20180724 Open Source Certification- Preparing for the Exam.md @@ -0,0 +1,64 @@ +Open Source Certification: Preparing for the Exam +====== +Open source is the new normal in tech today, with open components and platforms driving mission-critical processes at organizations everywhere. As open source has become more pervasive, it has also profoundly impacted the job market. Across industries [the skills gap is widening, making it ever more difficult to hire people][1] with much needed job skills. That’s why open source training and certification are more important than ever, and this series aims to help you learn more and achieve your own certification goals. + +In the [first article in the series][2], we explored why certification matters so much today. In the [second article][3], we looked at the kinds of certifications that are making a difference. This story will focus on preparing for exams, what to expect during an exam, and how testing for open source certification differs from traditional types of testing. + +Clyde Seepersad, General Manager of Training and Certification at The Linux Foundation, stated, “For many of you, if you take the exam, it may well be the first time that you've taken a performance-based exam and it is quite different from what you might have been used to with multiple choice, where the answer is on screen and you can identify it. In performance-based exams, you get what's called a prompt.” + +As a matter of fact, many Linux-focused certification exams literally prompt test takers at the command line. The idea is to demonstrate skills in real time in a live environment, and the best preparation for this kind of exam is practice, backed by training. + +### Know the requirements + +"Get some training," Seepersad emphasized. "Get some help to make sure that you're going to do well. We sometimes find folks have very deep skills in certain areas, but then they're light in other areas. If you go to the website for [Linux Foundation training and certification][4], for the [LFCS][5] and the [LFCE][6] certifications, you can scroll down the page and see the details of the domains and tasks, which represent the knowledge areas you're supposed to know.” + +Once you’ve identified the skills you need, “really spend some time on those and try to identify whether you think there are areas where you have gaps. You can figure out what the right training or practice regimen is going to be to help you get prepared to take the exam," Seepersad said. + +### Practice, practice, practice + +"Practice is important, of course, for all exams," he added. "We deliver the exams in a bit of a unique way -- through your browser. We're using a terminal emulator on your browser and you're being proctored, so there's a live human who is watching you via video cam, your screen is being recorded, and you're having to work through the exam console using the browser window. You're going to be asked to do something live on the system, and then at the end, we're going to evaluate that system to see if you were successful in accomplishing the task" + +What if you run out of time on your exam, or simply don’t pass because you couldn’t perform the required skills? “I like the phrase, exam insurance,” Seepersad said. “The way we take the stress out is by offering a ‘no questions asked’ retake. If you take either exam, LFCS, LFCE and you do not pass on your first attempt, you are automatically eligible to have a free second attempt.” + +The Linux Foundation intentionally maintains separation between its training and certification programs and uses an independent proctoring solution to monitor candidates. It also requires that all certifications be renewed every two years, which gives potential employers confidence that skills are current and have been recently demonstrated. + +### Free certification guide + +Becoming a Linux Foundation Certified System Administrator or Engineer is no small feat, so the Foundation has created [this free certification guide][7] to help you with your preparation. In this guide, you’ll find: + + * Critical things to keep in mind on test day + + + * An array of both free and paid study resources to help you be as prepared as possible + + * A few tips and tricks that could make the difference at exam time + + * A checklist of all the domains and competencies covered in the exam + + + + +With certification playing a more important role in securing a rewarding long-term career, careful planning and preparation are key. Stay tuned for the next article in this series that will answer frequently asked questions pertaining to open source certification and training. + +[Learn more about Linux training and certification.][8] + +-------------------------------------------------------------------------------- + +via: https://www.linux.com/blog/sysadmin-cert/2018/7/open-source-certification-preparing-exam + +作者:[Sam Dean][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.linux.com/users/sam-dean +[1]:https://www.linux.com/blog/os-jobs-report/2017/9/demand-open-source-skills-rise +[2]:https://www.linux.com/blog/sysadmin-cert/2018/7/5-reasons-open-source-certification-matters-more-ever +[3]:https://www.linux.com/blog/sysadmin-cert/2018/7/tips-success-open-source-certification +[4]:https://training.linuxfoundation.org/ +[5]:https://training.linuxfoundation.org/certification/linux-foundation-certified-sysadmin-lfcs/ +[6]:https://training.linuxfoundation.org/certification/linux-foundation-certified-engineer-lfce/ +[7]:https://training.linuxfoundation.org/download-free-certification-prep-guide +[8]:https://training.linuxfoundation.org/certification/ diff --git a/sources/talk/20180724 Why moving all your workloads to the cloud is a bad idea.md b/sources/talk/20180724 Why moving all your workloads to the cloud is a bad idea.md new file mode 100644 index 0000000000..1d97805178 --- /dev/null +++ b/sources/talk/20180724 Why moving all your workloads to the cloud is a bad idea.md @@ -0,0 +1,71 @@ +Why moving all your workloads to the cloud is a bad idea +====== + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/cloud-globe.png?itok=_drXt4Tn) + +As we've been exploring in this series, cloud hype is everywhere, telling you that migrating your applications to the cloud—including hybrid cloud and multicloud—is the way to ensure a digital future for your business. This hype rarely dives into the pitfalls of moving to the cloud, nor considers the daily work of enhancing your customer's experience and agile delivery of new and legacy applications. + +In [part one][1] of this series, we covered basic definitions (to level the playing field). We outlined our views on hybrid cloud and multi-cloud, making sure to show the dividing lines between the two. This set the stage for [part two][2], where we discussed the first of three pitfalls: Why cost is not always the obvious motivator for moving to the cloud. + +In part three, we'll look at the second pitfall: Why moving all your workloads to the cloud is a bad idea. + +### Everything's better in the cloud? + +There's a misconception that everything will benefit from running in the cloud. All workloads are not equal, and not all workloads will see a measurable effect on the bottom line from moving to the cloud. + +As [InformationWeek wrote][3], "Not all business applications should migrate to the cloud, and enterprises must determine which apps are best suited to a cloud environment." This is a hard fact that the utility company in part two of this series learned when labor costs rose while trying to move applications to the cloud. Discovering this was not a viable solution, the utility company backed up and reevaluated its applications. It found some applications were not heavily used and others had data ownership and compliance issues. Some of its applications were not certified for use in a cloud environment. + +Sometimes running applications in the cloud is not physically possible, but other times it's not financially viable to run in the cloud. + +Imagine a fictional online travel company. As its business grew, it expanded its on-premises hosting capacity to over 40,000 servers. It eventually became a question of expanding resources by purchasing a data center at a time, not a rack at a time. Its business consumes bandwidth at such volumes that cloud pricing models based on bandwidth usage remain prohibitive. + +### Get a baseline + +Sometimes running applications in the cloud is not physically possible, but other times it's not financially viable to run in the cloud. + +As these examples show, nothing is more important than having a thorough understanding of your application landscape. Along with a having good understanding of what applications need to migrate to the cloud, you also need to understand current IT environments, know your present level of resources, and estimate your costs for moving. + +As these examples show, nothing is more important than having a thorough understanding of your application landscape. Along with a having good understanding of what applications need to migrate to the cloud, you also need to understand current IT environments, know your present level of resources, and estimate your costs for moving. + +Understanding your baseline–each application's current situation and performance requirements (network, storage, CPU, memory, application and infrastructure behavior under load, etc.)–gives you the tools to make the right decision. + +If you're running servers with single-digit CPU utilization due to complex acquisition processes, a cloud with on-demand resourcing might be a great idea. However, first ask these questions: + + * How long did this low-utilization exist? + * Why wasn't it caught earlier? + * Isn't there a process or effective monitoring in place? + * Do you really need a cloud to fix this? Or just a better process for both getting and managing your resources? + * Will you have a better process in the cloud? + + + +### Are containers necessary? + +Many believe you need containers to be successful in the cloud. This popular [catchphrase][4] sums it up nicely, "We crammed this monolith into a container and called it a microservice." + +Containers are a means to an end, and using containers doesn't mean your organization is capable of running maturely in the cloud. It's not about the technology involved, it's about applications that often were written in days gone by with technology that's now outdated. If you put a tire fire into a container and then put that container on a container platform to ship, it's still functionality that someone is using. + +Is that fire easier to extinguish now? These container fires just create more challenges for your DevOps teams, who are already struggling to keep up with all the changes being pushed through an organization moving everything into the cloud. + +Note, it's not necessarily a bad decision to move legacy workloads into the cloud, nor is it a bad idea to containerize them. It's about weighing the benefits and the downsides, assessing the options available, and making the right choices for each of your workloads. + +### Coming up + +In part four of this series, we'll describe the third and final pitfall everyone should avoid with hybrid multi-cloud. Find out what the cloud means for your data. + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/7/why-you-cant-move-everything-cloud + +作者:[Eric D.Schabell][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://opensource.com/users/eschabell +[1]:https://opensource.com/article/18/4/pitfalls-hybrid-multi-cloud +[2]:https://opensource.com/article/18/6/reasons-move-to-cloud +[3]:https://www.informationweek.com/cloud/10-cloud-migration-mistakes-to-avoid/d/d-id/1318829 +[4]:https://speakerdeck.com/caseywest/containercon-north-america-cloud-anti-patterns?slide=22 diff --git a/sources/talk/20180726 Tech jargon- The good, the bad, and the ugly.md b/sources/talk/20180726 Tech jargon- The good, the bad, and the ugly.md new file mode 100644 index 0000000000..def2701a78 --- /dev/null +++ b/sources/talk/20180726 Tech jargon- The good, the bad, and the ugly.md @@ -0,0 +1,108 @@ +Tech jargon: The good, the bad, and the ugly +====== +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/change_words_scrabble_letters.jpg?itok=mbRFmPJ1) + +One enduring and complex piece of jargon is the use of "free" in relation to software. In fact, the term is so ambiguous that different terms have evolved to describe some of the variants—open source, FOSS, and even phrases such as "free as in speech, not as in beer." But surely this is a good thing, right? We know what we mean; we're sharing shorthand by using a particular word in a particular way. Some people might not understand, and there's some ambiguity. But does that matter? + +### A couple of definitions + +I was involved in an interesting discussion with colleagues recently about the joys (or otherwise) of jargon. It stemmed from a section I wrote in a recent article, [How to talk to security people: a guide for the rest of us][1], where I said: + +> "Jargon has at least two uses: +> +> 1. as an exclusionary mechanism for groups to keep non-members in the dark; +> 2. as a short-hand to exchange information between 'in-the-know' people so that they don't need to explain everything in exhaustive detail every time." +> + + +Given the discussion that arose, I thought it was worth delving more deeply into this question. It's more than an idle interest, as I think there are important lessons around our use of jargon that impact how we interact with our colleagues and peers that deserve some careful thought. These lessons apply particularly to my chosen field, security. + +Before we start, we should define "jargon". It's always nice to have two conflicting versions, so here we go: + + * "Special words or expressions used by a profession or group that are difficult for others to understand." ([Oxford Living Dictionaries][2]) + * "Without a qualifier, denotes informal 'slangy' language peculiar to or predominantly found among hackers." ([The Jargon File][3]) + + + +I should start by pointing out that The Jargon File, which was published in paper form in at least [two versions][4] as The Hacker's Dictionary (ed. Steele) and The New Hacker's Dictionary (ed. Raymond), has a pretty special place in my heart. When I decided that I wanted to properly "take up" geekery,1,2 I read The New Hacker's Dictionary from cover to cover, several times, and when a new edition came out, I bought that and did the same. + +In fact, for more technical readers, I suspect that a fair amount of your cultural background is expressed within its covers (paper or virtual), even if you're not aware of it. If you're interested in delving deeper and like the feel of paper in your hands, I encourage you to purchase a copy—but be careful to get the right one. There are some expensive versions that seem just to be printouts of The Jargon File, rather than properly typeset and edited versions.3 + +But let's get onto the meat of this article: is jargon a force for good or ill? + +### First: Why jargon is good + +The case for jargon is quite simple. We need jargon to enable us to discuss concepts and the use of terms in normal language—like scheduling—as jargon leads to some interesting metaphors that guide us in our practice.4 We absolutely need shared practice, and for that we need shared language—and some of that language is bound to become jargon over time. But consider a lexicon, or an FAQ, or other ways to allow your colleagues to participate: be inclusive, not exclusive. That's the good. The problem, however, is the bad. + +### The case against jargon: Ambiguity + +You would think jargon would serve to provide agreed terms within a particular discipline and help prevent ambiguity around contexts. It may be a surprise, then, that the first problem we often run into with jargon is namespace clashes. Consider the following. There's an old joke about how to distinguish an electrical engineer from a humanities5 graduate: ask them how many syllables are in the word "coax." The point here, of course, is that they come from different disciplines. But there are lots of words—and particularly abbreviations—that have different meanings or expansions depending on context and where disciplines and contexts may collide. + +What do these words mean to you?6 + + * Scheduling: kernel-level CPU allocation to processes OR placement of workloads by an orchestration component + * Comms: I/O in a computer system OR marketing/analyst communications + * Layer: OSI model OR IP suite layer OR another architectural abstraction layer such as host or workload + * SME: subject matter expert OR small/medium enterprise + * SMB: small/medium business OR small message block + * TLS: transport layer security OR Times Literary Supplement + * IP: internet protocol OR intellectual property OR intellectual property as expressed as a silicon component block + * FFS for further study OR …7 + + + +One of the interesting things is that quite a lot of my background is betrayed by the various options that present themselves to me. I wonder how many readers will have thought of the Times Literary Supplement, for example. I'm also more likely to think of SME as the term relating to organisations, because that's the favoured form in Europe, whereas I believe that the US tends to SMB. I'm sure your experiences will all be different—which rather makes my point for me. + +That's the first problem. In a context where jargon is often praised as a way of shortcutting lengthy explanations, it can actually be a significant ambiguating force. + +### The case against jargon: Exclusion + +Intentionally or not—and sometimes it is intentional—groups define themselves through the use of specific terminology. Once this terminology becomes opaque to those outside the group, it becomes "jargon," as per our first definition above. "Good" use of jargon generally allows those within the group to converse using shared context around concepts that do not need to be explained in detail every time they are used. + +An example would be a "smoke test"—a quick test to check that basic functionality is performing correctly (see the Jargon File's [definition][5] for more). If everyone in the group understands what this means, then why go into more detail? But if you are joined at a stand-up meeting8 by a member of marketing who wants to know whether a particular build is ready for release, and you say "well, no—it's only been smoke-tested so far," then it's likely you'll need to explain. + +The problem is that there are occasions when jargon can exclude others, whether that usage is intended or not. There have been times for most of us, I'm sure, when we want to show we're part of a group, so we use terms that we know another person won't understand. On other occasions, the term may be so ingrained in our practice that we use it without thinking, and the other person is unintentionally excluded. I would argue that we need to be careful to avoid both of these uses. + +Intentional exclusion is rarely helpful, but unintentional exclusion can be just as damaging—in some ways more so, as it is typically unremarked and therefore difficult to remedy. + +### What to do? + +First, be aware when you're using jargon, and try to foster an environment where people feel happy to query what you mean. If you see people's eyes glazing over, take a step back and explain the context and the term. Second, be on the lookout for ambiguity: if you're on a project where something can mean more than one thing, disambiguate somewhere in a file or diagram that everyone can access and is easily discoverable. And last, don't use jargon to exclude. We need all the people we can get, so let's bring them in, not push them out. + +1\. "Properly"—really? Although I'm not sure "improperly" is any better. + +2\. I studied English Literature and Theology at university, so this was a conscious decision to embrace a rather different culture. + +3\. The most recent "real" edition of which I'm aware is Raymond, Eric S., 1996, [The New Hacker's Dictionary][6], 3rd ed., MIT University Press, Cambridge, Mass. + +4\. Although metaphors can themselves be constraining as they tend to push us to think in a particular way, even if that way isn't entirely applicable in this context. + +5\. Or "liberal arts". + +6\. I've added the first options that spring to mind when I come across them—I'm aware there are almost certainly others. + +7\. Believe me, when I saw this abbreviation in a research paper for the first time, I was most confused and had to look it up. + +8\. Oh, look: jargon… + +This article originally appeared on [Alice, Eve, and Bob – a security blog][7] and is republished with permission. + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/7/tech-jargon + +作者:[Mike Bursell][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://opensource.com/users/mikecamel +[1]:http://aliceevebob.com/2018/05/08/how-to-talk-to-security-people-a-guide-for-the-rest-of-us/ +[2]:https://en.oxforddictionaries.com/definition/jargon +[3]:http://catb.org/jargon/html/distinctions.html +[4]:https://en.wikipedia.org/wiki/Jargon_File +[5]:http://catb.org/jargon/html/S/smoke-test.html +[6]:https://www.amazon.com/New-Hackers-Dictionary-3rd/dp/0262680920 +[7]:https://aliceevebob.com/2018/06/26/jargon-a-force-for-good-or-ill/ diff --git a/sources/talk/20180731 How to be the lazy sysadmin.md b/sources/talk/20180731 How to be the lazy sysadmin.md new file mode 100644 index 0000000000..25024a20bd --- /dev/null +++ b/sources/talk/20180731 How to be the lazy sysadmin.md @@ -0,0 +1,110 @@ +How to be the lazy sysadmin +====== +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/cat-yawn-vm.png?itok=0c_zy6aQ) + +The job of a Linux SysAdmin is always complex and often fraught with various pitfalls and obstacles. Ranging from never having enough time to do everything, to having the Pointy-Haired Boss (PHB) staring over your shoulder while you try to work on the task that she or he just gave you, to having the most critical server in your care crash at the most inopportune time, problems and challenges abound. I have found that becoming the Lazy Sysadmin can help. + +I discuss how to be a lazy SysAdmin in detail in my forthcoming book, [The Linux Philosophy for SysAdmins][1], (Apress), which is scheduled to be available in September. Parts of this article are taken from that book, especially Chapter 9, "Be a Lazy SysAdmin." Let's take a brief look at what it means to be a Lazy SysAdmin before we discuss how to do it. + +### Real vs. fake productivity + +#### Fake productivity + +At one place I worked, the PHB believed in the management style called "management by walking around," the supposition being that anyone who wasn't typing something on their keyboard, or at least examining something on their display, was not being productive. This was a horrible place to work. It had high administrative walls between departments that created many, tiny silos, a heavy overburden of useless paperwork, and excruciatingly long wait times to obtain permission to do anything. For these and other reasons, it was impossible to do anything efficiently—if at all—so we were incredibly non-productive. To look busy, we all had our Look Busy Kits (LBKs), which were just short Bash scripts that showed some activity, or programs like `top`, `htop`, `iotop`, or any monitoring tool that constantly displayed some activity. The ethos of this place made it impossible to be truly productive, and I hated both the place and the fact that it was nearly impossible to accomplish anything worthwhile. + +That horrible place was a nightmare for real SysAdmins. None of us was happy. It took four or five months to accomplish what took only a single morning in other places. We had little real work to do but spent a huge amount of time working to look busy. We had an unspoken contest going to create the best LBK, and that is where we spent most of our time. I only managed to last a few months at that job, but it seemed like a lifetime. If you looked only at the surface of that dungeon, you could say we were lazy because we accomplished almost zero real work. + +This is an extreme example, and it is totally the opposite of what I mean when I say I am a Lazy SysAdmin and being a Lazy SysAdmin is a good thing. + +#### Real productivity + +I am fortunate to have worked for some true managers—they were people who understood that the productivity of a SysAdmin is not measured by how many hours per day are spent banging on a keyboard. After all, even a monkey can bang on a keyboard, but that is no indication of the value of the results. + +As I say in my book: + +> "I am a lazy SysAdmin and yet I am also a very productive SysAdmin. Those two seemingly contradictory statements are not mutually exclusive, rather they are complementary in a very positive way. … +> +> "A SysAdmin is most productive when thinking—thinking about how to solve existing problems and about how to avoid future problems; thinking about how to monitor Linux computers in order to find clues that anticipate and foreshadow those future problems; thinking about how to make their work more efficient; thinking about how to automate all of those tasks that need to be performed whether every day or once a year. +> +> "This contemplative aspect of the SysAdmin job is not well known or understood by those who are not SysAdmins—including many of those who manage the SysAdmins, the Pointy Haired Bosses. SysAdmins all approach the contemplative parts of their job in different ways. Some of the SysAdmins I have known found their best ideas at the beach, cycling, participating in marathons, or climbing rock walls. Others think best when sitting quietly or listening to music. Still others think best while reading fiction, studying unrelated disciplines, or even while learning more about Linux. The point is that we all stimulate our creativity in different ways, and many of those creativity boosters do not involve typing a single keystroke on a keyboard. Our true productivity may be completely invisible to those around the SysAdmin." + +There are some simple secrets to being the Lazy SysAdmin—the SysAdmin who accomplishes everything that needs to be done and more, all the while keeping calm and collected while others are running around in a state of panic. Part of this is working efficiently, and part is about preventing problems in the first place. + +### Ways to be the Lazy SysAdmin + +#### Thinking + +I believe the most important secret about being the Lazy SysAdmin is thinking. As in the excerpt above, great SysAdmins spend a significant amount of time thinking about things we can do to work more efficiently, locate anomalies before they become problems, and work smarter, all while considering how to accomplish all of those things and more. + +For example, right now—in addition to writing this article—I am thinking about a project I intend to start as soon as the new parts arrive from Amazon and the local computer store. The motherboard on one of my less critical computers is going bad, and it has been crashing more frequently recently. But my very old and minimal server—the one that handles my email and external websites, as well as providing DHCP and DNS services for the rest of my network—isn't failing but has to deal with intermittent overloads due to external attacks of various types. + +I started by thinking I would just replace the motherboard and its direct components—memory, CPU, and possibly the power supply—in the failing unit. But after thinking about it for a while, I decided I should put the new components into the server and move the old (but still serviceable) ones from the server into the failing system. This would work and take only an hour, or perhaps two, to remove the old components from the server and install the new ones. Then I could take my time replacing the components in the failing computer. Great. So I started generating a mental list of tasks to do to accomplish this. + +However, as I worked the list, I realized that about the only components of the server I wouldn't replace were the case and the hard drive, and the two computers' cases are almost identical. After having this little revelation, I started thinking about replacing the failing computer's components with the new ones and making it my server. Then, after some testing, I would just need to remove the hard drive from my current server and install it in the case with all the new components, change a couple of network configuration items, change the hostname on the KVM switch port, and change the hostname labels on the case, and it should be good to go. This will produce far less server downtime and significantly less stress for me. Also, if something fails, I can simply move the hard drive back to the original server until I can fix the problem with the new one. + +So now I have created a mental list of the tasks I need to do to accomplish this. And—I hope you were watching closely—my fingers never once touched the keyboard while I was working all of this out in my head. My new mental action plan is low risk and involves a much smaller amount of server downtime compared to my original plan. + +When I worked for IBM, I used to see signs all over that said "THINK" in many languages. Thinking can save time and stress and is the main hallmark of a Lazy SysAdmin. + +#### Doing preventative maintenance + +In the mid-1970s, I was hired as a customer engineer at IBM, and my territory consisted of a fairly large number of [unit record machines][2]. That just means that they were heavily mechanical devices that processed punched cards—a few dated from the 1930s. Because these machines were primarily mechanical, their parts often wore out or became maladjusted. Part of my job was to fix them when they broke. The main part of my job—the most important part—was to prevent them from breaking in the first place. The preventative maintenance was intended to replace worn parts before they broke and to lubricate and adjust the moving components to ensure that they were working properly. + +As I say in The Linux Philosophy for SysAdmins: + +> "My managers at IBM understood that was only the tip of the iceberg; they—and I—knew my job was customer satisfaction. Although that usually meant fixing broken hardware, it also meant reducing the number of times the hardware broke. That was good for the customer because they were more productive when their machines were working. It was good for me because I received far fewer calls from those happier customers. I also got to sleep more due to the resultant fewer emergency off-hours callouts. I was being the Lazy [Customer Engineer]. By doing the extra work upfront, I had to do far less work in the long run. +> +> "This same tenet has become one of the functional tenets of the Linux Philosophy for SysAdmins. As SysAdmins, our time is best spent doing those tasks that minimize future workloads." + +Looking for problems to fix in a Linux computer is the equivalent of project management. I review the system logs looking for hints of problems that might become critical later. If something appears to be a little amiss, or I notice my workstation or a server is not responding as it should, or if the logs show something unusual—all of these can be indicative of an underlying problem that has not generated symptoms obvious to users or the PHB. + +I do frequent checks of the files in `/var/log/`, especially messages and security. One of my more common problems is the many script kiddies who try various types of attacks on my firewall system. And, no, I do not rely on the alleged firewall in the modem/router provided by my ISP. These logs contain a lot of information about the source of the attempted attack and can be very valuable. But it takes a lot of work to scan the logs on various hosts and put solutions into place. So I turn to automation. + +#### Automating + +I have found that a very large percentage of my work can be performed by some form of automation. One of the tenets of the Linux Philosophy for SysAdmins is "automate everything," and this includes boring, drudge tasks like scanning logfiles every day. + +Programs like [Logwatch][3] can monitor your logfiles for anomalous entries and notify you when they occur. Logwatch usually runs as a cron job once a day and sends an email to root on the localhost. You can run Logwatch from the command line and view the results immediately on your display. Now I just need to look at the Logwatch email notification every day. + +But the reality is just getting a notification is not enough, because we can't sit and watch for problems all the time. Sometimes an immediate response is required. Another program I like, one that does all of the work for me—see, this is the real Lazy Admin—is [Fail2Ban][4]. Fail2Ban scans designated logfiles for various types of hacking and intrusion attempts, and if it sees enough sustained activity of a specific type from a particular IP address, it adds an entry to the firewall that blocks any further hacking attempts from that IP address for a specified time. The defaults tend to be around 10 minutes, but I like to specify 12 or 24 hours for most types of attacks. Each type of hacking attack is configured separately, such as those trying to log in via SSH and those attacking a web server. + +#### Writing scripts + +Automation is one of the key components of the Philosophy. Everything that can be automated should be, and the rest should be automated as much as possible. So, I also write a lot of scripts to solve problems, which also means I write scripts to do most of my work for me. + +My scripts save me huge amounts of time because they contain the commands to perform specific tasks, which significantly reduces the amount of typing I need to do. For example, I frequently restart my email server and my spam-fighting software (which needs restarted when configuration changes are made to SpamAssassin's `local.cf` file). Those services must be stopped and restarted in a specific order. So, I wrote a short script with a few commands and stored it in `/usr/local/bin`, where it is accessible. Now, instead of typing several commands and waiting for each to finish before typing the next one—not to mention remembering the correct sequence of commands and the proper syntax of each—I type in a three-character command and leave the rest to my script. + +#### Reducing typing + +Another way to be the Lazy SysAdmin is to reduce the amount of typing we need to do. Besides, my typing skills are really horrible (that is to say I have none—a few clumsy fingers at best). One possible cause for errors is my poor typing, so I try to keep typing to a minimum. + +The vast majority of GNU and Linux core utilities have very short names. They are, however, names that have some meaning. Tools like `cd` for change directory, `ls` for list (the contents of a directory), and `dd` for disk dump are pretty obvious. Short names mean less typing and fewer opportunities for errors to creep in. I think the short names are usually easier to remember. + +When I write shell scripts, I like to keep the names short but meaningful (to me at least) like `rsbu` for Rsync BackUp. In some cases, I like the names a bit longer, such as `doUpdates` to perform system updates. In the latter case, the longer name makes the script's purpose obvious. This saves time because it's easy to remember the script's name. + +Other methods to reduce typing are command line aliases and command line recall and editing. Aliases are simply substitutions that are made by the Bash shell when you type a command. Type the `alias` command and look at the list of aliases that are configured by default. For example, when you enter the command `ls`, the entry `alias ls='ls –color=auto'` substitutes the longer command, so you only need to type two characters instead of 14 to get a listing with colors. You can also use the `alias` command to add your own aliases. + +Command line recall allows you to use the keyboard's Up and Down arrow keys to scroll through your command history. If you need to use the same command again, you can just press the Enter key when you find the one you need. If you need to change the command once you have found it, you can use standard command line editing features to make the changes. + +### Parting thoughts + +It is actually quite a lot of work being the Lazy SysAdmin. But we work smart, rather than working hard. We spend time exploring the hosts we are responsible for and dealing with any little problems long before they become large problems. We spend a lot of time thinking about the best ways to resolve problems, and we think a lot about discovering new ways to work smarter at being the Lazy SysAdmin. + +There are many other ways to be the Lazy SysAdmin besides the few described here. I'm sure you have some of your own; please share them with the rest of us in the comments. + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/7/how-be-lazy-sysadmin + +作者:[David Both][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://opensource.com/users/dboth +[1]:https://www.apress.com/us/book/9781484237298 +[2]:https://en.wikipedia.org/wiki/Unit_record_equipment +[3]:https://www.techrepublic.com/article/how-to-install-and-use-logwatch-on-linux/ +[4]:https://www.fail2ban.org/wiki/index.php/Main_Page diff --git a/sources/talk/20180802 Design thinking as a way of life.md b/sources/talk/20180802 Design thinking as a way of life.md new file mode 100644 index 0000000000..5d88bdf04f --- /dev/null +++ b/sources/talk/20180802 Design thinking as a way of life.md @@ -0,0 +1,95 @@ +Design thinking as a way of life +====== + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/innovation_lightbulb_gears_devops_ansible.png?itok=TSbmp3_M) + +Over the past few years, design has become more than a discipline. It has become a mindset, one gaining more and more traction in industrial practices, processes, and operations. + +People have begun to recognize the value in making design the fundamental component of the process and methodologies aimed at both the "business side" and the "people side" of the organization. In other words, "thinking with design" is a great way to approach business problems and organizational culture problems. + +Design thinkers have tried to visualize how design can be translated as the core of methodologies like Design Thinking, Lean, Agile, and others in a meaningful way, as industries begin seeing potential in a design-driven approach capable of helping organizations be more efficient and effective in delivering value to customers. + +But still, many questions remain—especially questions about the operational aspect of translating core design values. For example: + + * "When should we use Design Thinking?" + * "What is the best way to run a design process?" + * "How effectively we can fit design into Agile? Or Agile into the design process?" + * "Which methodologies are best for my team and the design practices I am following?" + + + +The list goes on. In general, though, the tighter integration of design principles into all phases of development processes is becoming more common—something we might call "[DesOps][1]." This mode of thinking, "Design Operations," is a mindset that some believe might be the successor of the DevOps movement. In this article, I want to explain how open principles intersect with the DesOps movement. + +### Eureka + +The quest for a design "Holy Grail," especially from a service design perspective, has led many on a journey through similar methodologies yet toward the same goal: that "eureka" moment that reveals the "best fit" service model for a design process that will work most effectively. But among those various methodologies and practices are so many overlaps, and as a result, everyone is looking for the common framework capable of assessing problems from diverse angles, like business and engineering. It's as if all the gospels of all major religions are preaching and striving for the same higher human values of love, peace, and conscience—but the question is "Which is the right and most effective way?" + +I may have found an answer. + +On my first day at Red Hat, I received a copy of Jim Whitehurst's The Open Organization. What immediately came to my mind was: "Oh, another book with rants about open source practices and benefits." + +But over the weekend, as I scanned the book's pages, I realized it's about more than just "open source culture." It's a book about the quest to find an answer to a much more basic puzzle, one that every organization is currently trying to solve: "What is that common thread that can bind best practices and philosophies in a way that's meaningful for organizations?" + +This was interesting! As I dove more deeply, I found something that made even more sense in context of all the design- and operations-related questions I've seen debated for years: Being "open" is the key to bringing together the best of different practices and philosophies, something that allows us to retain their authenticity and yet help in catering to real needs in operations and design. + +It's also the key to thinking with DesOps. + +### DesOps: Culture, process, technology + +Like every organizational framework, DesOps touches upon culture, process, and technology—the entire ecosystem of the enterprise. + +Like every organizational framework, DesOps touches upon culture, process, and technology—the entire ecosystem of the enterprise. Because it is inspired by the culture of DevOps, people tend to view it more from the angle of technological aspects (such as automation, continuous integration, and a delivery point of view). However the most difficult—and yet most important—piece of the DesOps puzzle to solve is the cultural one. This is critical because it involves human-to-human interactions (unlike the machine-to-machine or human-to-machine interactions that are a more common part of purely technological questions). + +So DesOps is not only about bringing automation and continuous integration to systems-to-systems interactions. It's an approach to organically making the systems a part of all interaction touch points that actually enable in human-to-human communication and feedback models. + +Humans are at the center of DesOps, which requires a culture that itself follows design philosophies and values, including "zero waste" in translation across interaction touch points (including lean methodologies across the activity chains). Stressing dynamic culture based on agile philosophies, DesOps is design thinking as a way of life. + +But how can we build an organizational culture that aligns to basic DesOps philosophies? What kind of culture can organically compliment those meaningfully integrated system-to-system and system-to-human toolings and eco-systems as part of DesOps? + +The answer can be found in The Open Organization. + +A DesOps culture is essentially an open culture, and that solves a critical piece of the puzzle. What I realized during my [book-length exploration of DesOps][2] is that every DesOps-led organization is actually an open organization. + +### DesOps, open by default + +To ensure we can sustain our organizations in the future, we must rethink how to we work together and prepare ourselves—how we develop and sustain a culture of innovation. + +Broadly, DesOps focuses on how to converge different work practices so that an organization's product management, design, engineering, and marketing teams can work together in an optimal way. Then the organization can nurture and sustain creativity and innovation, while at the same time delivering that "wow" experience to customers and end users through products and services. + +At a fundamental level, DesOps is not about introducing new models or process in the enterprise; rather, it's about orchestrating best practices from Design Thinking, Lean Methodologies, User-Centered Design models, and other best practices with modern technologies to understand, create, and deliver value. + +Let's take a closer look at core DesOps philosophies. Some are inherently aligned with and draw inspirations from the DevOps movement, and all are connected to the attributes of an open organization (both at organizational and individual levels). + +Being "open" means: + + * Every individual is transparent. So is the organization they're part of. The upshot is that each member of the organization enables greater transparency and more feedback-loops. + * There's less manipulation in translation among touch points. This also means the process is lean and every touch point is easily accessible. + * There's greater accessibility, which means the organizational structure tends towards zero hierarchy, as each ladder is accessible through openness. Every one is encouraged to interact, ask questions, and share thoughts and ideas, and provide feedback. When individuals ask and share ideas across roles, they feel more responsible, and a sense of ownership develops. + * Greater accessibility, in turn, helps nurture ideas from bottom up, as it provides avenues for ideas to germinate and evolve upward. + * Bottom-up momentum helps with inclusivity, as it opens doors for grassroots movements in the organization and eliminates structural boundaries within it. + * Inclusivity reduces gaps among functional roles, again reducing hierarchy. + * Feedback loops form across the organization (and also through development life cycles). This in return enables more meaningful data for informed decision making. + * Empathy is nurtured, which helps people in the organization to understand the needs and pain-points of users and customers. Within the organization, it helps people identify and solve core issues, making it possible to implement design thinking as a way of life. With the enablement of empathy and humility, the culture becomes more receptive and will tend towards zero bias. The open, receptive, and empathetic team has greater agility, one that's more open to change. + * Freedom arrives as a bonus when the organization has a open culture, and this creates a positive environment for the team to innovate, not feeling psychologically fearful and encourage fail-fast philosophies. + + + +We're at an interesting historical moment, when competition in the market is increasing, technology has matured, and unstructured data is a fuel that can open up new possibilities. Our organizational management models have matured beyond corporate, autocratic ways of running people and systems. To ensure we can sustain our organizations in the future, we must rethink how to we work together and prepare ourselves—how we develop and sustain a culture of innovation. + +Open organization principles are guideposts on that journey. + + +-------------------------------------------------------------------------------- + +via: https://opensource.com/open-organization/18/8/introduction-to-desops + +作者:[Samir Dash][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://opensource.com/users/sdash +[1]:http://desops.io/ +[2]:http://desops.io/2018/06/07/paperback-the-desops-enterprise-re-invent-your-organization-volume-1-the-overview-culture/ diff --git a/sources/talk/20180802 How blockchain will influence open source.md b/sources/talk/20180802 How blockchain will influence open source.md new file mode 100644 index 0000000000..707f4fe033 --- /dev/null +++ b/sources/talk/20180802 How blockchain will influence open source.md @@ -0,0 +1,185 @@ +How blockchain will influence open source +====== + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/block-quilt-chain.png?itok=mECoDbrc) + +What [Satoshi Nakamoto][1] started as Bitcoin a decade ago has found a lot of followers and turned into a movement for decentralization. For some, blockchain technology is a religion that will have the same impact on humanity as the Internet has had. For others, it is hype and technology suitable only for Ponzi schemes. While blockchain is still evolving and trying to find its place, one thing is for sure: It is a disruptive technology that will fundamentally transform certain industries. And I'm betting open source will be one of them. + +### The open source model + +Open source is a collaborative software development and distribution model that allows people with common interests to gather and produce something that no individual can create on their own. It allows the creation of value that is bigger than the sum of its parts. Open source is enabled by distributed collaboration tools (IRC, email, git, wiki, issue trackers, etc.), distributed and protected by an open source licensing model and often governed by software foundations such as the [Apache Software Foundation][2] (ASF), [Cloud Native Computing Foundation][3] (CNCF), etc. + +One interesting aspect of the open source model is the lack of financial incentives in its core. Some people believe open source work should remain detached from money and remain a free and voluntary activity driven only by intrinsic motivators (such as "common purpose" and "for the greater good”). Others believe open source work should be rewarded directly or indirectly through extrinsic motivators (such as financial incentive). While the idea of open source projects prospering only through voluntary contributions is romantic, in reality, the majority of open source contributions are done through paid development. Yes, we have a lot of voluntary contributions, but these are on a temporary basis from contributors who come and go, or for exceptionally popular projects while they are at their peak. Creating and sustaining open source projects that are useful for enterprises requires developing, documenting, testing, and bug-fixing for prolonged periods, even when the software is no longer shiny and exciting. It is a boring activity that is best motivated through financial incentives. + +### Commercial open source + +Software foundations such as ASF survive on donations and other income streams such as sponsorships, conference fees, etc. But those funds are primarily used to run the foundations, to provide legal protection for the projects, and to ensure there are enough servers to run builds, issue trackers, mailing lists, etc. + +Similarly, CNCF has member fees and other income streams, which are used to run the foundation and provide resources for the projects. These days, most software is not built on laptops; it is run and tested on hundreds of machines on the cloud, and that requires money. Creating marketing campaigns, brand designs, distributing stickers, etc. takes money, and some foundations can assist with that as well. At its core, foundations implement the right processes to interact with users, developers, and control mechanisms and ensure distribution of available financial resources to open source projects for the common good. + +If users of open source projects can donate money and the foundations can distribute it in a fair way, what is missing? + +What is missing is a direct, transparent, trusted, decentralized, automated bidirectional link for transfer of value between the open source producers and the open source consumer. Currently, the link is either unidirectional or indirect: + + * **Unidirectional** : A developer (think of a "developer" as any role that is involved in the production, maintenance, and distribution of software) can use their brain juice and devote time to do a contribution and share that value with all open source users. But there is no reverse link. + + * **Indirect** : If there is a bug that affects a specific user/company, the options are: + + * To have in-house developers to fix the bug and do a pull request. That is ideal, but it not always possible to hire in-house developers who are knowledgeable about hundreds of open source projects used daily. + + * To hire a freelancer specializing in that specific open source project and pay for the services. Ideally, the freelancer is also a committer for the open source project and can directly change the project code quickly. Otherwise, the fix might not ever make it to the project. + + * To approach a company providing services around the open source project. Such companies typically employ open source committers to influence and gain credibility in the community and offer products, expertise, and professional services. + + + + +The third option has been a successful [model][4] for sustaining many open source projects. Whether they provide services (training, consulting, workshops), support, packaging, open core, or SaaS, there are companies that employ hundreds of staff members who work on open source full time. There is a long [list of companies][5] that have managed to build a successful open source business model over the years, and that list is growing steadily. + +The companies that back open source projects play an important role in the ecosystem: They are the catalyst between the open source projects and the users. The ones that add real value do more than just package software nicely; they can identify user needs and technology trends, and they create a full stack and even an ecosystem of open source projects to address these needs. They can take a boring project and support it for years. If there is a missing piece in the stack, they can start an open source project from scratch and build a community around it. They can acquire a closed source software company and open source the projects (here I got a little carried away, but yes, I'm talking about my employer, [Red Hat][6]). + +To summarize, with the commercial open source model, projects are officially or unofficially managed and controlled by a very few individuals or companies that monetize them and give back to the ecosystem by ensuring the project is successful. It is a win-win-win for open source developers, managing companies, and end users. The alternative is inactive projects and expensive closed source software. + +### Self-sustaining, decentralized open source + +For a project to become part of a reputable foundation, it must conform to certain criteria. For example, ASF and CNCF require incubation and graduation processes, respectively, where apart from all the technical and formal requirements, a project must have a healthy number of active committer and users. And that is the essence of forming a sustainable open source project. Having source code on GitHub is not the same thing as having an active open source project. The latter requires committers who write the code and users who use the code, with both groups enforcing each other continuously by exchanging value and forming an ecosystem where everybody benefits. Some project ecosystems might be tiny and short-lived, and some may consist of multiple projects and competing service providers, with very complex interactions lasting for many years. But as long as there is an exchange of value and everybody benefits from it, the project is developed, maintained, and sustained. + +If you look at ASF [Attic][7], you will find projects that have reached their end of life. When a project is no longer technologically fit for its purpose, it is usually its natural end. Similarly, in the ASF [Incubator][8], you will find tons of projects that never graduated but were instead retired. Typically, these projects were not able to build a large enough community because they are too specialized or there are better alternatives available. + +But there are also cases where projects with high potential and superior technology cannot sustain themselves because they cannot form or maintain a functioning ecosystem for the exchange of value. The open source model and the foundations do not provide a framework and mechanisms for developers to get paid for their work or for users to get their requests heard. There isn’t a common value commitment framework for either party. As a result, some projects can sustain themselves only in the context of commercial open source, where a company acts as an intermediary and value adder between developers and users. That adds another constraint and requires a service provider company to sustain some open source projects. Ideally, users should be able to express their interest in a project and developers should be able to show their commitment to the project in a transparent and measurable way, which forms a community with common interest and intent for the exchange of value. + +Imagine there is a model with mechanisms and tools that enable direct interaction between open source users and developers. This includes not only code contributions through pull requests, questions over the mailing lists, GitHub stars, and stickers on laptops, but also other ways that allow users to influence projects' destinies in a richer, more self-controlled and transparent manner. + +This model could include incentives for actions such as: + + * Funding open source projects directly rather than through software foundations + + * Influencing the direction of projects through voting (by token holders) + + * Feature requests driven by user needs + + * On-time pull request merges + + * Bounties for bug hunts + + * Better test coverage incentives + + * Up-to-date documentation rewards + + * Long-term support guarantees + + * Timely security fixes + + * Expert assistance, support, and services + + * Budget for evangelism and promotion of the projects + + * Budget for regular boring activities + + * Fast email and chat assistance + + * Full visibility of the overall project findings, etc. + + + + +If you haven't guessed, I'm talking about using blockchain and [smart contracts][9] to allow such interactions between users and developers—smart contracts that will give power to the hand of token holders to influence projects. + +![blockchain_in_open_source_ecosystem.png][11] + +The usage of blockchain in the open source ecosystem + +Existing channels in the open source ecosystem provide ways for users to influence projects through financial commitments to service providers or other limited means through the foundations. But the addition of blockchain-based technology to the open source ecosystem could open new channels for interaction between users and developers. I'm not saying this will replace the commercial open source model; most companies working with open source do many things that cannot be replaced by smart contracts. But smart contracts can spark a new way of bootstrapping new open source projects, giving a second life to commodity projects that are a burden to maintain. They can motivate developers to apply boring pull requests, write documentation, get tests to pass, etc., providing a direct value exchange channel between users and open source developers. Blockchain can add new channels to help open source projects grow and become self-sustaining in the long term, even when company backing is not feasible. It can create a new complementary model for self-sustaining open source projects—a win-win. + +### Tokenizing open source + +There are already a number of initiatives aiming to tokenize open source. Some focus only on an open source model, and some are more generic but apply to open source development as well: + + * [Gitcoin][12] \- grow open source, one of the most promising ones in this area. + + * [Oscoin][13] \- cryptocurrency for open source + + * [Open collective][14] \- a platform for supporting open source projects. + + * [FundYourselfNow][15] \- Kickstarter and ICOs for projects. + + * [Kauri][16] \- support for open source project documentation. + + * [Liberapay][17] \- a recurrent donations platform. + + * [FundRequest][18] \- a decentralized marketplace for open source collaboration. + + * [CanYa][19] \- recently acquired [Bountysource][20], now the world’s largest open source P2P bounty platform. + + * [OpenGift][21] \- a new model for open source monetization. + + * [Hacken][22] \- a white hat token for hackers. + + * [Coinlancer][23] \- a decentralized job market. + + * [CodeFund][24] \- an open source ad platform. + + * [IssueHunt][25] \- a funding platform for open source maintainers and contributors. + + * [District0x 1Hive][26] \- a crowdfunding and curation platform. + + * [District0x Fixit][27] \- github bug bounties. + + + + +This list is varied and growing rapidly. Some of these projects will disappear, others will pivot, but a few will emerge as the [SourceForge][28], the ASF, the GitHub of the future. That doesn't necessarily mean they'll replace these platforms, but they'll complement them with token models and create a richer open source ecosystem. Every project can pick its distribution model (license), governing model (foundation), and incentive model (token). In all cases, this will pump fresh blood to the open source world. + +### The future is open and decentralized + + * Software is eating the world. + + * Every company is a software company. + + * Open source is where innovation happens. + + + + +Given that, it is clear that open source is too big to fail and too important to be controlled by a few or left to its own destiny. Open source is a shared-resource system that has value to all, and more importantly, it must be managed as such. It is only a matter of time until every company on earth will want to have a stake and a say in the open source world. Unfortunately, we don't have the tools and the habits to do it yet. Such tools would allow anybody to show their appreciation or ignorance of software projects. It would create a direct and faster feedback loop between producers and consumers, between developers and users. It will foster innovation—innovation driven by user needs and expressed through token metrics. + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/8/open-source-tokenomics + +作者:[Bilgin lbryam][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://opensource.com/users/bibryam +[1]:https://en.wikipedia.org/wiki/Satoshi_Nakamoto +[2]:https://www.apache.org/ +[3]:https://www.cncf.io/ +[4]:https://medium.com/open-consensus/3-oss-business-model-progressions-dafd5837f2d +[5]:https://docs.google.com/spreadsheets/d/17nKMpi_Dh5slCqzLSFBoWMxNvWiwt2R-t4e_l7LPLhU/edit#gid=0 +[6]:http://jobs.redhat.com/ +[7]:https://attic.apache.org/ +[8]:http://incubator.apache.org/ +[9]:https://en.wikipedia.org/wiki/Smart_contract +[10]:/file/404421 +[11]:https://opensource.com/sites/default/files/uploads/blockchain_in_open_source_ecosystem.png (blockchain_in_open_source_ecosystem.png) +[12]:https://gitcoin.co/ +[13]:http://oscoin.io/ +[14]:https://opencollective.com/opensource +[15]:https://www.fundyourselfnow.com/page/about +[16]:https://kauri.io/ +[17]:https://liberapay.com/ +[18]:https://fundrequest.io/ +[19]:https://canya.io/ +[20]:https://www.bountysource.com/ +[21]:https://opengift.io/pub/ +[22]:https://hacken.io/ +[23]:https://www.coinlancer.com/home +[24]:https://codefund.io/ +[25]:https://issuehunt.io/ +[26]:https://blog.district0x.io/district-proposal-spotlight-1hive-283957f57967 +[27]:https://github.com/district0x/district-proposals/issues/177 +[28]:https://sourceforge.net/ diff --git a/sources/talk/20180807 Becoming a successful programmer in an underrepresented community.md b/sources/talk/20180807 Becoming a successful programmer in an underrepresented community.md new file mode 100644 index 0000000000..ff86e1f213 --- /dev/null +++ b/sources/talk/20180807 Becoming a successful programmer in an underrepresented community.md @@ -0,0 +1,94 @@ +Becoming a successful programmer in an underrepresented community +====== + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/people_remote_teams_world.png?itok=_9DCHEel) + +Becoming a programmer from an underrepresented community like Cameroon is tough. Many Africans don't even know what computer programming is—and a lot who do think it's only for people from Western or Asian countries. + +I didn't own a computer until I was 18, and I didn't start programming until I was a 19-year-old high school senior, and had to write a lot of code on paper because I couldn't be carrying my big desktop to school. I have learned a lot over the past five years as I've moved up the ladder to become a successful programmer from an underrepresented community. While these lessons are from my experience in Africa, many apply to other underrepresented communities, including women. + +### 1\. Learn how to code + +This is obvious: To be a successful programmer, you first have to be a programmer. In an African community, this may not be very easy. To learn how to code you need a computer and probably internet, too, which aren't very common for Africans to have. I didn't own a desktop computer until I was 18 years old—and I didn't own a laptop until I was about 20, and some may have still considered me privileged. Some students don't even know what a computer looks like until they get to the university. + +You still have to find a way to learn how to code. Before I had a computer, I used to walk for miles to see a friend who had one. He wasn't very interested in it, so I spent a lot of time with it. I also visited cybercafes regularly, which consumed most of my pocket money. + +Take advantage of local programming communities, as this could be one of your greatest sources of motivation. When you're working on your own, you may feel like a ninja, but that may be because you do not interact much with other programmers. Attend tech events. Make sure you have at least one friend who is better than you. See that person as a competitor and work hard to beat them, even though they may be working as hard as you are. Even if you never win, you'll be growing in skill as a programmer. + +### 2\. Don't read too much into statistics + +A lot of smart people in underrepresented communities never even make it to the "learning how to code" part because they take statistics as hard facts. I remember when I was aspiring to be a hacker, I used to get discouraged about the statistic that there are far fewer black people than white people in technology. If you google the "top 50 computer programmers of all time," there probably won't be many (if any) black people on the list. Most of the inspiring names in tech, like Ada Lovelace, Linus Torvalds, and Bill Gates, are white. + +Growing up, I always believed technology was a white person's thing. I used to think I couldn't do it. When I was young, I never saw a science fiction movie with a black man as a hacker or an expert in computing. It was always white people. I remember when I got to high school and our teacher wrote that programming was part of our curriculum, I thought that was a joke—I wondered, "since when and how will that even be possible?" I wasn't far from the truth. Our teachers couldn't program at all. + +Statistics also say that a lot of the amazing, inspiring programmers you look up to, no matter what their color, started coding at the age of 13. But you didn't even know programming existed until you were 19. You ask yourself questions like: How am I going to catch up? Do I even have the intelligence for this? When I was 13, I was still playing stupid, childish games—how can I compete with this? + +This may make you conclude that white people are naturally better at tech. That's wrong. Yes, the statistics are correct, but they're just statistics. And they can change. Make them change. Your environment contributes a lot to the things you do while growing up. How can you compare yourself to someone whose parents got him a computer before he was nine—when you didn't even see one until you were 19? That's a 10-year gap. And that nine-year-old kid also had a lot of people to coach him. + +How can you compare yourself to someone whose parents got him a computer before he was nine—when you didn't even see one until you were 19? + +You can be a great software engineer regardless of your background. It may be a little harder because you may not have the resources or opportunities people in the western world have, but it's not impossible. + +### 3\. Have a local hero or mentor + +I think having someone in your life to look up to is one of the most important things. We all admire people like Linus Torvalds and Bill Gates but trying to make them your role models can be demotivating. Bill Gates began coding at age 13 and formed his first venture at age 17. I'm 24 and still trying to figure out what I want to do with my life. Those stories always make me wonder why I'm not better yet, rather than looking for reasons to get better. + +Having a local hero or mentor is more helpful. Because you're both living in the same community, there's a greater chance there won't be such a large gap to discourage you. A local mentor probably started coding around the age you did and was unlikely to start a big venture at a very young age. + +I've always admired the big names in tech and still do. But I never saw them as mentors. First, because their stories seemed like fantasy to me, and second, I couldn't reach them. I chose my mentors and role models to be those near my reach. Choosing a role model doesn't mean you just want to get to where they are and stop. Success is step by step, and you need a role model for each stage you're trying to reach. When you attain a stage, get another role model for the next stage. + +You probably can't get one-on-one advice from someone like Bill Gates. You can get the advice they're giving to the public at conferences, which is great, too. I always follow smart people. But advice that makes the most impact is advice that is directed to you. Advice that takes into consideration your goals and circumstances. You can get that only from someone you have direct access to. + +I'm a product of many mentors at different stages of my life. One is [Nyah Check][1] , who was a year ahead of me at the university, but in terms of skill and experience, he was two to three years ahead. I heard stories about him when I was still in high school. He made people want to be great programmers, not just focus on getting a 4.0 GPA. He was one of the first people in French-speaking Africa to participate in [Google Summer of Code][2] . While still at the university, he traveled abroad more times than many lecturers would dream of—without spending a dime. He could write code that even our course instructors couldn't understand. He co-founded [Google Developer Group Buea][3] and created an elite programmers club that helped many students learn to code. He started a lot of other communities, like the [Docker Buea meetup][4] that I'm the lead organizer for. + +These things inspired me. I wanted to be like him and knew what I would gain by becoming friends with him. Discussions with him were always very inspiring—he talked about programming and his adventures traveling the world for conferences. I learned a lot from him, and I think he taught me well. Now younger students want to be around me for the same reasons I wanted to learn from him. + +### 4\. Get involved with open source + +If you're in Africa and want to gain top skills from top engineers, your best bet is to join an open source project. The tech ecosystem in Africa is small and mostly made of startups, so getting experience in a field you love might not be easy. It's rare for startups in Africa to be working with machine learning, distributed computing, or containers and technologies like Kubernetes. Unless your passion is web development, your best bet is joining an open source project. I've learned most of what I know by being part of the [OpenMRS][5] community. I've also contributed to other open source projects including [LibreHealth][6], [Coala][7], and [Kubernetes][8]. Along with gaining tech skills, you'll be building your network of influential people. Most of my peers know about Linus Torvalds from books, but I have a picture with him. + +Participate in open source outreach programs like Google Summer of Code, [Google Code-in][9], [Outreachy][10], or [Linux Foundation Networking Internships][11]. These opportunities help you gain skills that may not be available in startups. + +I participated in Google Summer of Code twice as a student, and I'm now a mentor. I've been a Google Code-in org admin, and I'm volunteering as an open source developer. All these activities help me learn new things. + +### 5\. Take advantage of diversity programs while you can + +Diversity programs are great, but if you're like me, you may not like to benefit very much from them. If you're on a team of five and the basis of your offer is that you're a black person and the other four are white, you might wonder if you're really good enough. You won't want people to think a foundation sponsored your trip because you're black rather than because you add as much value as anyone else. It's never only that you're a minority—it's because the sponsoring organization thinks you're an exceptional minority. You're not the only person who applied for the diversity scholarship, and not everyone that applied won the award. Take advantage of diversity opportunities while you can and build your knowledge base and network. + +When people ask me why the Linux Foundation sponsored my trip to the Open Source Summit, I say: "I was invited to give a talk at their conference, but they have diversity scholarships you can apply for." How cool does that sound? + +Attend as many conferences as you can—diversity scholarships can help. Learn all you can learn. Practice what you learn. Get to know people. Apply to give talks. Start small. My right leg used to shake whenever I stood in front of a crowd to give a speech, but with practice, I've gotten better. + +### 6\. Give back + +Always find a way to give back. Mentor someone. Take up an active role in a community. These are the ways I give back to my community. It isn't only a moral responsibility—it's a win-win because you can learn a lot while helping others get closer to their dreams. + +I was part of a Programming Language meetup organized by Google Developer Group Buea where I mentored 15 students in Java programming (from beginner to intermediate). After the program was over, I created a Java User Group to keep the Java community together. I recruited two members from the meetup to join me as volunteer developers at LibreHealth, and under my guidance, they made useful commits to the project. They were later accepted as Google Summer of Code students, and I was assigned to mentor them during the program. I'm also the lead organizer for Docker Buea, the official Docker meetup in Cameroon, and I'm also Docker Campus Ambassador. + +Taking up leadership roles in this community has forced me to learn. As Docker Campus Ambassador, I'm supposed to train students on how to use Docker. Because of this, I've learned a lot of cool stuff about Docker and containers in general. + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/8/becoming-successful-programmer + +作者:[lvange Larry][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://opensource.com/users/ivange94 +[1]:https://github.com/Ch3ck +[2]:https://summerofcode.withgoogle.com/ +[3]:http://www.gdgbuea.net/ +[4]:https://www.meetup.com/Docker-Buea/?_cookie-check=EnOn1Ct-CS4o1YOw +[5]:https://openmrs.org/ +[6]:https://librehealth.io/ +[7]:https://coala.io/#/home' +[8]:https://kubernetes.io/ +[9]:https://codein.withgoogle.com/archive/ +[10]:https://www.outreachy.org/ +[11]:https://wiki.lfnetworking.org/display/LN/LF+Networking+Internships +[12]:http://sched.co/FAND +[13]:https://ossna18.sched.com/ diff --git a/sources/talk/20180807 Building more trustful teams in four steps.md b/sources/talk/20180807 Building more trustful teams in four steps.md new file mode 100644 index 0000000000..60dfe37133 --- /dev/null +++ b/sources/talk/20180807 Building more trustful teams in four steps.md @@ -0,0 +1,70 @@ +Building more trustful teams in four steps +====== + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/BUSINESS_trust.png?itok=KMfi0Rdo) + +Robin Dreeke's The Code of Trust is a helpful guide to developing trustful relationships, and it's particularly useful to people working in open organizations (where trust is fundamental to any kind of work). As its title implies, Dreeke's book presents a "code" or set of principles people can follow when attempting to establish trust. I explained those in [the first installment of this review][1]. In this article, then, I'll outline what Dreeke (a former FBI agent) calls "The Four Steps to Inspiring Trust"—a set of practices for enacting the principles. In other words, the Steps make the Code work in the real world. + +### The Four Steps + +#### 1\. Align your goals + +First, determine your primary goal—what you want to achieve and what sacrifices you are willing to make to achieve those goals. Learn the goals of others. Look for ways to align your goals with their goals, to make parts of their goals a part of yours. "You'll achieve the power that only combined forces can attain," Dreeke writes. For example, in the sales manager seminar I once ran regularly, I mentioned that if a sales manager helps a salesman reach his sales goals, the manager will reach his goals automatically. Also, if a salesman helps his customer reach his goals, the salesman will reach his goals automatically. This is aligning goals. (For more on this, see an [earlier article][2] I wrote about how companies can determine when to compete and when to cooperate). + +This couldn't be more true in open organizations, which depend on both internal and external contributors a great deal. What are those contributors' goals? Everyone must understand these if an open organization is going to be successful. + +When aligning goals, try to avoid having strong opinions on the topic at hand. This leads to inflexibility, Dreeke says, and reduces the chance of generating options that align with other people's goals. To find their goals, consider what their fears or concerns are. Then try to help them overcome those fears or concerns. + +If you can't get them to align with your goals, then you should choose to not align with them and instead remove them from the team. Dreeke recommends doing this in a way that allows you to stay approachable for other projects. In one issue, goals might not be aligned; in other issues, they may. + +Dreeke also notes that many people believe being successful means carefully narrowing your focus to your own goals. "But that's one of those lazy shortcuts that slow you down," Dreeke writes. Success, Dreeke says, arrives faster when you inspire others to merge their goals with yours, then forge ahead together. In that respect, if you place heavy attention on other people and their goals while doing the same with yours, success in opening someone up comes far sooner. This all sounds very much like advice for activating transparency, inclusivity, and collaboration—key open organization principles. + +#### 2\. Apply the power of context + +Dreeke recommends really getting to know your partners, discovering "their desires, beliefs, personality traits, behaviors, and demographic characteristics." Those are key influences that define their context. + +To achieve trust, you must find a plan that achieves their goals along with yours. + +People only trust those who know them (including these beliefs, goals, and personalities). Once known, you can match their goals with yours. To achieve trust, you must find a plan that achieves their goals along with yours (see above). If you try to push your goals on them, they'll become defensive and information exchange will shut down. If that happens, no good ideas will materialize. + +#### 3\. Craft your encounter + +When you meet with potential allies, plan the meeting meticulously—especially the first meeting. Create the perfect environment for it. Know in advance: 1. the proper atmosphere and mood required, 2. the special nature of the occasion, 3. the perfect time and location, 4. your opening remark, and 5. your plan of what to offer the other person (and what to ask for at that time). Creating the best possible environment for every interaction sets the stage for success. + +Dreeke explains the difference between times for planning and thinking and times for simply performing (like when you meet a stranger for the first time). If you are not well prepared, the fear and emotions of the moment could be overwhelming. To reduce that emotion, planning, preparing and role playing can be very helpful. + +Later in the book, Dreeke discusses "toxic situations," suggesting you should not ignore toxic situations, as they'll more than likely get worse if you do. People could become emotional and say irrational things. You must address the toxic situation by helping people stay rational. Then try to laser in on interactions between your goals and theirs. What does the person want to achieve? Suspending your ego gives you "the freedom to laser-in" on others' points of view and places where their goals can lead to joint ultimate goals, Dreeke says. Stay focused on their context, not your ego, in toxic situations. + +Some leaders think it is best to strongly confront toxic people, maybe embarrassing them in front of others. That might feel good at the time, but "kicking ass in a crowd" just builds people's defenses, Dreeke says. To build a productive plan, he says, you need "shields down," so information will be shared. + +Show others you speak their language—not only for understanding, but also to demonstrate reason, respect, and consideration. + +"Trust leaders take no interest in their own power," Dreeke argues, as they are deeply interested and invested in others. By helping others, their trust develops. For toxic people, the opposite is true: They want power. Unfortunately, this desire for power just espouses more fear and distrust. Dreeke says that to combat a toxic environment, trust leaders do not "fight fire with fire" which spreads the toxicity. They "fight fire with water" to reduce it. In movies, fights are exciting; in real life they are counterproductive. + +#### 4\. Connect + +Finally, show others you speak their language—not only for understanding, but also to demonstrate reason, respect, and consideration. Speak about what they want to hear (namely, issues that focus on them and their needs). The speed of trust is directly opposed to the speed of speech, Dreeke says. People who speak slowly and carefully build trust faster than people who rush their speaking. + +Importantly, Dreeke also covers a way to get people to like you. It doesn't involve directly getting people to like you personally; it involves getting people to like themselves. Show more respect for them than they might even feel about themselves. Praise them for qualities about themselves that they hadn't thought about. That will open the doors to a trusting relationship. + +### Putting it together + +I've spent my entire career attempting to build trust globally, throughout the business communities in which I've worked. I have no experience in the intelligence community, but I do see great similarities in spite of the different working environment. The book has given me new insights I never considered (like the section on "crafting your encounter," for example). I recommend people pick up the book and read it thoroughly, as there is other helpful advice in it that I couldn't cover in this short article. + +As I [mentioned in Part 1][1], following Dreeke's Code of Trust can lead to building strong trust networks or communities. Those trust communities are exactly what we are trying to create in open organizations. + + +-------------------------------------------------------------------------------- + +via: https://opensource.com/open-organization/18/8/steps-trust + +作者:[Ron McFarland][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://opensource.com/users/ron-mcfarland +[1]:https://opensource.com/open-organization/18/7/the-code-of-trust-1 +[2]:https://opensource.com/open-organization/17/6/collaboration-vs-competition-part-1 diff --git a/sources/talk/20180808 3 tips for moving your team to a microservices architecture.md b/sources/talk/20180808 3 tips for moving your team to a microservices architecture.md new file mode 100644 index 0000000000..fd990a0d8e --- /dev/null +++ b/sources/talk/20180808 3 tips for moving your team to a microservices architecture.md @@ -0,0 +1,180 @@ +3 tips for moving your team to a microservices architecture +====== +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/building_architecture_design.jpg?itok=lB_qYv-I) + +Microservices are gaining in popularity and providing new ways for tech companies to improve their services for end users. But what impact does the shift to microservices have on team culture and morale? What issues should CTOs, developers, and project managers consider when the best technological choice is a move to microservices? + +Below you’ll find key advice and insight from CTOs and project leads as they reflect on their experiences with team culture and microservices. + +### You can't build successful microservices without a successful team culture + +When I was working with Java developers, there was tension within the camp about who got to work on the newest and meatiest features. Our engineering leadership had decided that we would exclusively use Java to build all new microservices. + +There were great reasons for this decision, but as I will explain later, such a restrictive decision come with some repercussions. Communicating the “why” of technical decisions can go a long way toward creating a culture where people feel included and informed. + +When you're organizing and managing a team around microservices, it’s always challenging to balance the mood, morale, and overall culture. In most cases, the leadership needs to balance the risk of team members using new technology against the needs of the client and the business itself. + +This dilemma, and many others like it, has led CTOs to ask themselves questions such as: How much freedom should I give my team when it comes to adopting new technologies? And perhaps even more importantly, how can I manage the overarching culture within my camp? + +### Give every team member a chance to thrive + +When the engineering leaders in the example above decided that Java was the best technology to use when building microservices, the decision was best for the company: Java is performant, and many of the senior people on the team were well-versed with it. However, not everyone on the team had experience with Java. + +The problem was, our team was split into two camps: the Java guys and the JavaScript guys. As time went by and exciting new projects came up, we’d always reach for Java to get the job done. Before long, some annoyance within the JavaScript camp crept in: “Why do the Java guys always get to work on the exciting new projects while we’re left to do the mundane front-end tasks like implementing third-party analytics tools? We want a big, exciting project to work on too!” + +Like most rifts, it started out small, but it grew worse over time. + +The lesson I learned from that experience was to take your team’s expertise and favored technologies into account when choosing a de facto tech stack for your microservices and when adjusting your team's level of freedom to pick and choose their tools. + +Sure, you need some structure, but if you’re too restrictive—or worse, blind to the desire of team members to innovate with different technologies—you may have a rift of your own to manage. + +So evaluate your team closely and come up with a plan that empowers everyone. That way, every section of your team can get involved in major projects, and nobody will feel like they’re being left on the bench. + +### Technology choices: stability vs. flexibility + +Let’s say you hire a new junior developer who is excited about some brand new, fresh-off-the-press JavaScript framework. + +That framework, while sporting some technical breakthroughs, may not have proven itself in production environments, and it probably doesn’t have great support available. CTOs have to make a difficult choice: Okaying that move for the morale of the team, or declining it to protect the company and its bottom line and to keep the project stable as the deadline approaches. + +The answer depends on a lot of different factors (which also means there is no single correct answer). + +### Technological freedom + +“We give our team and ourselves 100% freedom in considering technology choices. We eventually identified two or three technologies not to use in the end, primarily due to not wanting to complicate our deployment story,” said [Benjamin Curtis][1], co-founder of [Honeybadger][2]. + +“In other words, we considered introducing new languages and new approaches into our tech stack when creating our microservices, and we actually did deploy a production microservice on a different stack at one point. [While we do generally] stick with technologies that we know in order to simplify our ops stack, we periodically revisit that decision to see if potential performance or reliability benefits would be gained by adopting a new technology, but so far we haven't made a change,” Curtis continued. + +When I spoke with [Stephen Blum][3], CTO at [PubNub][4], he expressed a similar view, welcoming pretty much any technology that cuts the mustard: “We're totally open with it. We want to continue to push forward with new open source technologies that are available, and we only have a couple of constraints with the team that are very fair: [It] must run in container environment, and it has to be cost-effective.” + +### High freedom, high responsibility + +[Sumo Logic][5] CTO [Christian Beedgen][6] and chief architect [Stefan Zier][7] expanded on this topic, agreeing that if you’re going to give developers freedom to choose their technology, it must come with a high level of responsibility attached. “It’s really important that [whoever builds] the software takes full ownership for it. In other words, they not only build software, but they also run the software and remain responsible for the whole lifecycle.” + +Beedgen and Zier recommend implementing a system that resembles a federal government system, keeping those freedoms in check by heightening responsibility: “[You need] a federal culture, really. You've got to have a system where multiple, independent teams can come together towards the greater goal. That limits the independence of the units to some degree, as they have to agree that there is potentially a federal government of some sort. But within those smaller groups, they can make as many decisions on their own as they like within guidelines established on a higher level.” + +Decentralized, federal, or however you frame it, this approach to structuring microservice teams gives each team and each team member the freedom they want, without enabling anyone to pull the project apart. + +However, not everyone agrees. + +### Restrict technology to simplify things + +[Darby Frey][8], co-founder of [Lead Honestly][9], takes a more restrictive approach to technology selection. + +“At my last company we had a lot of services and a fairly small team, and one of the main things that made it work, especially for the team size that we had, was that every app was the same. Every backend service was a Ruby app,” he explained. + +Frey explained that this helped simplify the lives of his team members: “[Every service has] the same testing framework, the same database backend, the same background job processing tool, et cetera. Everything was the same. + +“That meant that when an engineer would jump around between apps, they weren’t having to learn a new pattern or learn a different language each time,” Frey continued, “So we're very aware and very strict about keeping that commonality.” + +While Frey is sympathetic to developers wanting to introduce a new language, admitting that he “loves the idea of trying new things,” he feels that the cons still outweigh the pros. + +“Having a polyglot architecture can increase the development and maintenance costs. If it's just all the same, you can focus on business value and business features and not have to be super siloed in how your services operate. I don't think everybody loves that decision, but at the end of the day, when they have to fix something on a weekend or in the middle of the night, they appreciate it,” said Frey. + +### Centralized or decentralized organization + +How your team is structured is also going to impact your microservices engineering culture—for better or worse. + +For example, it’s common for software engineers to write the code before shipping it off to the operations team, who in turn deploy it to the servers. But when things break (and things always break!), an internal conflict occurs. + +Because operation engineers don’t write the code themselves, they rarely understand problems when they first arise. As a result, they need to get in touch with those who did code it: the software engineers. So right from the get-go, you’ve got a middleman relaying messages between the problem and the team that can fix that problem. + +To add an extra layer of complexity, because software engineers aren’t involved with operations, they often can’t fully appreciate how their code affects the overall operation of the platform. They learn of issues only when operations engineers complain about them. + +As you can see, this is a relationship that’s destined for constant conflict. + +### Navigating conflict + +One way to attack this problem is by following the lead of Netflix and Amazon, both of which favor decentralized governance. Software development thought leaders James Lewis and Martin Fowler feel that decentralized governance is the way to go when it comes to microservice team organization, as they explain in a [blog post][10]. + +“One of the consequences of centralized governance is the tendency to standardize on single technology platforms. Experience shows that this approach is constricting—not every problem is a nail and not every solution a hammer,” the article reads. “Perhaps the apogee of decentralized governance is the ‘build it, run it’ ethos popularized by Amazon. Teams are responsible for all aspects of the software they build, including operating the software 24/7.” + +Netflix, Lewis and Fowler write, is another company pushing higher levels of responsibility on development teams. They hypothesize that, because they’ll be responsible and called upon should anything go wrong later down the line, more care will be taken during the development and testing stages to ensure each microservice is in ship shape. + +“These ideas are about as far away from the traditional centralized governance model as it is possible to be,” they conclude. + +### Who's on weekend pager duty? + +When considering a centralized or decentralized culture, think about how it impacts your team members when problems inevitably crop up at inopportune times. A decentralized system implies that each decentralized team takes responsibility for one service or one set of services. But that also creates a problem: Silos. + +That’s one reason why Lead Honestly's Frey isn’t a proponent of the concept of decentralized governance. + +“The pattern of ‘a single team is responsible for a particular service’ is something you see a lot in microservice architectures. We don't do that, for a couple of reasons. The primary business reason is that we want teams that are responsible not for specific code but for customer-facing features. A team might be responsible for order processing, so that will touch multiple code bases but the end result for the business is that there is one team that owns the whole thing end to end, so there are fewer cracks for things to fall through,” Frey explained. + +The other main reason, he continued, is that developers can take more ownership of the overall project: “They can actually think about [the project] holistically.” + +Nathan Peck, developer advocate for container services at Amazon Web Services, [explained this problem in more depth][11]. In essence, when you separate the software engineers and the operations engineers, you make life harder for your team whenever an issue arises with the code—which is bad news for end users, too. + +But does decentralization need to lead to separation and siloization? + +Peck explained that his solution lies in [DevOps][12], a model aimed at tightening the feedback loop by bringing these two teams closer together, strengthening team culture and communication in the process. Peck describes this as the “you build it, you run it” approach. + +However, that doesn’t mean teams need to get siloed or distanced away from partaking in certain tasks, as Frey suggests might happen. + +“One of the most powerful approaches to decentralized governance is to build a mindset of ‘DevOps,’” Peck wrote. “[With this approach], engineers are involved in all parts of the software pipeline: writing code, building it, deploying the resulting product, and operating and monitoring it in production. The DevOps way contrasts with the older model of separating development teams from operations teams by having development teams ship code ‘over the wall’ to operations teams who were then responsible to run it and maintain it.” + +DevOps, as [Armory][13] CTO [Isaac Mosquera][14] explained, is an agile software development framework and culture that’s gaining traction thanks to—well, pretty much everything that Peck said. + +Interestingly, Mosquera feels that this approach actually flies in the face of [Conway’s Law][15]: + +_" Organizations which design systems ... are constrained to produce designs which are copies of the communication structures of these organizations." — M. Conway_ + +“Instead of communication driving software design, now software architecture drives communication. Not only do teams operate and organize differently, but it requires a new set of tooling and process to support this type of architecture; i.e., DevOps,” Mosquera explained. + +[Chris McFadden][16], VP of engineering at [SparkPost][17], offers an interesting example that might be worth following. At SparkPost, you’ll find decentralized governance—but you won’t find a one-team-per-service culture. + +“The team that is developing these microservices started off as one team, but they’re now split up into three teams under the same larger group. Each team has some level of responsibility around certain domains and certain expertise, but the ownership of these services is not restricted to any one of these teams,” McFadden explained. + +This approach, McFadden continued, allows any team to work on anything from new features to bug fixes to production issues relating to any of those services. There’s total flexibility and not a silo in sight. + +“It allows [the teams to be] a little more flexible both in terms of new product development as well, just because you're not getting too restricted and that's based on our size as a company and as an engineering team. We really need to retain some flexibility,” he said. + +However, size might matter here. McFadden admitted that if SparkPost was a lot larger, “then it would make more sense to have a single, larger team own one of those microservices.” + +“[It's] better, I think, to have a little bit more broad responsibility for these services and it gives you a little more flexibility. At least that works for us at this time, where we are as an organization,” he said. + +### A successful microservices engineering culture is a balancing act + +When it comes to technology, freedom—with responsibility—looks to be the most rewarding path. Team members with differing technological preferences will come and go, while new challenges may require you to ditch technologies that have previously served you well. Software development is constantly in flux, so you’ll need to continually balance the needs of your team are new devices, technologies, and clients emerge. + +As for structuring your teams, a decentralized yet un-siloed approach that leverages DevOps and instills a “you build it, you run it” mentality seems to be popular, although other schools of thought do exist. As usual, you’re going to have to experiment to see what suits your team best. + +Here’s a quick recap on how to ensure your team culture meshes well with a microservices architecture: + + * **Be sustainable, yet flexible** : Balance sustainability without forgetting about flexibility and the need for your team to be innovative when the right opportunity comes along. However, there’s a distinct difference of opinion over how you should achieve that balance. + + * **Give equal opportunities** : Don’t favor one section of your team over another. If you’re going to impose restrictions, make sure it’s not going to fundamentally alienate team members from the get-go. Think about how your product roadmap is shaping up and forecast how it will be built and who’s going to do the work. + + * **Structure your team to be agile, yet responsible** : Decentralized governance and agile development is the flavor of the day for a good reason, but don’t forget to install a sense of responsibility within each team. + + + + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/8/microservices-team-challenges + +作者:[Jake Lumetta][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://opensource.com/users/jakelumetta +[1]:https://twitter.com/stympy?lang=en +[2]:https://www.honeybadger.io/ +[3]:https://twitter.com/stephenlb +[4]:https://www.pubnub.com/ +[5]:http://sumologic.com/ +[6]:https://twitter.com/raychaser +[7]:https://twitter.com/stefanzier +[8]:https://twitter.com/darbyfrey +[9]:https://leadhonestly.com/ +[10]:https://martinfowler.com/articles/microservices.html#ProductsNotProjects +[11]:https://medium.com/@nathankpeck/microservice-principles-decentralized-governance-4cdbde2ff6ca +[12]:https://opensource.com/resources/devops +[13]:http://armory.io/ +[14]:https://twitter.com/imosquera +[15]:https://en.wikipedia.org/wiki/Conway%27s_law +[16]:https://twitter.com/cristoirmac +[17]:https://www.sparkpost.com/ diff --git a/sources/talk/20180809 How do tools affect culture.md b/sources/talk/20180809 How do tools affect culture.md new file mode 100644 index 0000000000..89fedec026 --- /dev/null +++ b/sources/talk/20180809 How do tools affect culture.md @@ -0,0 +1,56 @@ +How do tools affect culture? +====== + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/coffee_cafe_brew_laptop_desktop.jpg?itok=G-n1o1-o) + +Most of the DevOps community talks about how tools don’t matter much. The culture has to change first, the argument goes, which might modify how the tools are used. + +I agree and disagree with that concept. I believe the relationship between tools and culture is more symbiotic and bidirectional than unidirectional. I have discovered this through real-world transformations across several companies now. I admit it’s hard to determine whether the tools changed the culture or whether the culture changed how the tools were used. + +### Violating principles + +Some tools violate core principles of modern development and operations. The primary violation I have seen are tools that require GUI interactions. This often separates operators from the value pipeline in a way that is cognitively difficult to overcome. If everything in your infrastructure is supposed to be configured and deployed through a value pipeline, then taking someone out of that flow inherently changes their perspective and engagement. Making manual modifications also injects risk into the system that creates unpredictability and undermines the value of the pipeline. + +I’ve heard it said that these tools are fine and can be made to work within the new culture, and I’ve tried this in the past. Screen scraping and form manipulation tools have been used to attempt automation with some systems I’ve integrated. This is very fragile and doesn’t work on all systems. It ultimately required a lot of manual intervention. + +Another system from a large vendor providing integrated monitoring and ticketing solutions for infrastructure seemed to implement its API as an afterthought, and this resulted in the system being unable to handle the load from the automated system. This required constant manual recoveries and sometimes the tedious task of manually closing errant tickets that shouldn’t have been created or that weren’t closed properly. + +The individuals maintaining these systems experienced great frustration and often expressed a lack of confidence in the overall DevOps transformation. In one of these instances, we introduced a modern tool for monitoring and alerting, and the same individuals suddenly developed a tremendous amount of confidence in the overall DevOps transformation. I believe this is because tools can reinforce culture and improve it when a similar tool that lacks modern capabilities would otherwise stymie motivation and engagement. + +### Choosing tools + +At the NAIC (National Association of Insurance Commissioners), we’ve adopted a practice of evaluating new and existing tools based on features we believe reinforce the core principles of our value pipeline. We currently have seven items on our list: + + * REST API provided and fully functional (possesses all application functionality) + * Ability to provision immutably (can be installed, configured, and started without human intervention) + * Ability to provide all configuration through static files + * Open source code + * Uses open standards when available + * Offered as Software as a Service (SaaS) or hosted (we don't run anything) + * Deployable to public cloud (based on licensing and cost) + + + +This is a prioritized list. Each item gets rated green, yellow, or red to indicate how much each statement applies to a particular technology. This creates a visual that makes it quite clear how the different candidates compare to one another. We then use this to make decisions about which tools we should use. We don’t make decisions solely on these criteria, but they do provide a clearer picture and help us know when we’re sacrificing principles. Transparency is a core principle in our culture, and this system helps reinforce that in our decision-making process. + +We use green, yellow, and red because there’s not normally a clear binary representation of these criteria within each tool. For example, some tools have an incomplete API, which would result in yellow being applied. If the tool uses open standards like OpenAPI and there’s no other applicable open standard, then it would receive green for “Uses open standards when available.” However, a tracing system that uses OpenAPI and not OpenTracing would receive a yellow rating. + +This type of system creates a common understanding of what is valued when it comes to tool selection, and it helps avoid unknowingly violating core principles of your value pipeline. We recently used this method to select [GitLab][1] as our version control and continuous integration system, and it has drastically improved our culture for many reasons. I estimated 50 users for the first year, and we’re already over 120 in just the first few months. + +The tools we used previously didn’t allow us to contribute back our own features, collaborate transparently, or automate so completely. We’ve also benefited from GitLab’s culture influencing ours. Its [handbook][2] and open communication have been invaluable to our growth. Tools, and the companies that make them, can and will influence your company’s culture. What are you willing to allow in? + + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/8/how-tools-affect-culture + +作者:[Dan Barker][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://opensource.com/users/barkerd427 +[1]:https://about.gitlab.com/ +[2]:https://about.gitlab.com/handbook/ diff --git a/sources/talk/20180811 Dropbox To End Sync Support For All Filesystems Except Ext4 on Linux.md b/sources/talk/20180811 Dropbox To End Sync Support For All Filesystems Except Ext4 on Linux.md new file mode 100644 index 0000000000..7d471f42bb --- /dev/null +++ b/sources/talk/20180811 Dropbox To End Sync Support For All Filesystems Except Ext4 on Linux.md @@ -0,0 +1,71 @@ +Dropbox To End Sync Support For All Filesystems Except Ext4 on Linux +====== +Dropbox is thinking of limiting the synchronization support to only a handful of file system types: NTFS for Windows, HFS+/APFS for macOS and Ext4 for Linux. + +![Dropbox ends support for various file system types][1] + +[Dropbox][2] is one of the most popular [cloud services for Linux][3]. A lot of folks happen to utilize the Dropbox sync client for Linux. However, recently, some of the users received a warning on their Dropbox Linux desktop client that said: + +> “Move Dropbox location +> Dropbox will stop syncing in November“ + +### Dropbox will only support a handful of file systems + +A [Reddit thread][4] highlighted the announcement where one of the users inquired about it on [Dropbox forums][5], which was addressed by a community moderator with an unexpected news. Here’s what the[reply][6] was: + +> **“Hi everyone, on Nov. 7, 2018, we’re ending support for Dropbox syncing to drives with certain uncommon file systems. The supported file systems are NTFS for Windows, HFS+ or APFS for Mac, and Ext4 for Linux.** +> +> [Official Dropbox Forum][6] + +![Dropbox official confirmation over limitation on supported file systems][7] +Dropbox official confirmation over limitation on supported file systems + +The move is intended to provide a stable and consistent experience. Dropbox has also updated its [desktop requirements.][8] + +### So, what should you do? + +If you are using Dropbox on an unsupported filesystem to sync with, you should consider changing the location. + +Only Ext4 file system will be supported for Linux. And that’s not entirely a worrying news because chances are that you are already using Ext4 file system. + +On Ubuntu or other Ubuntu based distributions, open the Disks application and see the file system for the partition where you have installed your Linux system. + +![Check file system type on Ubuntu][9] +Check file system type on Ubuntu + +If you don’t have this Disk utility installed on your system, you can always [use the command line to find out file system type][10]. + +If you are using Ext4 file system and still getting the warning from Dropbox, check if you have an inactive computer/device linked for which you might be getting the notification. If yes, [unlink that system from your Dropbox account][11]. + +### Dropbox won’t support encrypted Ext4 as well? + +Some users are also reporting that they received the warning while they have an encrypted Ext4 filesystem synced with. So, does this mean that the Dropbox client for Linux will only support unencrypted Ext4 filesystem? There is no official statement from Dropbox in this regard. + +What filesystem are you using? Did you receive the warning as well? If you’re still not sure what to do after receiving the warning, you should head to the [official help center page][12] which mentions the solution. + +Let us know your thoughts in the comments below. + +-------------------------------------------------------------------------------- + +via: https://itsfoss.com/dropbox-linux-ext4-only/ + +作者:[Ankush Das][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://itsfoss.com/author/ankush/ +[1]: https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/08/dropbox-filesystem-support-featured.png +[2]: https://www.dropbox.com/ +[3]: https://itsfoss.com/cloud-services-linux/ +[4]: https://www.reddit.com/r/linux/comments/966xt0/linux_dropbox_client_will_stop_syncing_on_any/ +[5]: https://www.dropboxforum.com/t5/Syncing-and-uploads/ +[6]: https://www.dropboxforum.com/t5/Syncing-and-uploads/Linux-Dropbox-client-warn-me-that-it-ll-stop-syncing-in-Nov-why/m-p/290065/highlight/true#M42255 +[7]: https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/08/dropbox-stopping-file-system-supports.jpeg +[8]: https://www.dropbox.com/help/desktop-web/system-requirements#desktop +[9]: https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/08/check-file-system-type-ubuntu.jpg +[10]: https://www.thegeekstuff.com/2011/04/identify-file-system-type/ +[11]: https://www.dropbox.com/help/mobile/unlink-relink-computer-mobile +[12]: https://www.dropbox.com/help/desktop-web/cant-establish-secure-connection#location diff --git a/sources/talk/20180816 Debian Turns 25- Here are Some Interesting Facts About Debian Linux.md b/sources/talk/20180816 Debian Turns 25- Here are Some Interesting Facts About Debian Linux.md new file mode 100644 index 0000000000..c90262dfee --- /dev/null +++ b/sources/talk/20180816 Debian Turns 25- Here are Some Interesting Facts About Debian Linux.md @@ -0,0 +1,116 @@ +Debian Turns 25! Here are Some Interesting Facts About Debian Linux +====== +One of the oldest Linux distribution still in development, Debian has just turned 25. Let’s have a look at some interesting facts about this awesome FOSS project. + +### 10 Interesting facts about Debian Linux + +![Interesting facts about Debian Linux][1] + +The facts presented here have been collected from various sources available from the internet. They are true to my knowledge, but in case of any error, please remind me to update the article. + +#### 1\. One of the oldest Linux distributions still under active development + +[Debian project][2] was announced on 16th August 1993 by Ian Murdock, Debian Founder. Like Linux creator [Linus Torvalds][3], Ian was a college student when he announced Debian project. + +![](https://farm6.staticflickr.com/5710/20006308374_7f51ae2a5c_z.jpg) + +#### 2\. Some people get tattoo while some name their project after their girlfriend’s name + +The project was named by combining the name of Ian and his then-girlfriend Debra Lynn. Ian and Debra got married and had three children. Debra and Ian got divorced in 2008. + +#### 3\. Ian Murdock: The Maverick behind the creation of Debian project + +![Debian Founder Ian Murdock][4] +Ian Murdock + +[Ian Murdock][5] led the Debian project from August 1993 until March 1996. He shaped Debian into a community project based on the principals of Free Software. The [Debian Manifesto][6] and the [Debian Social Contract][7] are still governing the project. + +He founded a commercial Linux company called [Progeny Linux Systems][8] and worked for a number of Linux related companies such as Sun Microsystems, Linux Foundation and Docker. + +Sadly, [Ian committed suicide in December 2015][9]. His contribution to Debian is certainly invaluable. + +#### 4\. Debian is a community project in the true sense + +Debian is a community based project in true sense. No one ‘owns’ Debian. Debian is being developed by volunteers from all over the world. It is not a commercial project, backed by corporates like many other Linux distributions. + +Debian Linux distribution is composed of Free Software only. It’s one of the few Linux distributions that is true to the spirit of [Free Software][10] and takes proud in being called a GNU/Linux distribution. + +Debian has its non-profit organization called [Software in Public Interest][11] (SPI). Along with Debian, SPI supports many other open source projects financially. + +#### 5\. Debian and its 3 branches + +Debian has three branches or versions: Debian Stable, Debian Unstable (Sid) and Debian Testing. + +Debian Stable, as the name suggests, is the stable branch that has all the software and packages well tested to give you a rock solid stable system. Since it takes time before a well-tested software lands in the stable branch, Debian Stable often contains older versions of programs and hence people joke that Debian Stable means stale. + +[Debian Unstable][12] codenamed Sid is the version where all the development of Debian takes place. This is where the new packages first land or developed. After that, these changes are propagated to the testing version. + +[Debian Testing][13] is the next release after the current stable release. If the current stable release is N, Debian testing would be the N+1 release. The packages from Debian Unstable are tested in this version. After all the new changes are well tested, Debian Testing is then ‘promoted’ as the new Stable version. + +There is no strict release schedule for Debian. + +#### 7\. There was no Debian 1.0 release + +Debian 1.0 was never released. The CD vendor, InfoMagic, accidentally shipped a development release of Debian and entitled it 1.0 in 1996. To prevent confusion between the CD version and the actual Debian release, the Debian Project renamed its next release to “Debian 1.1”. + +#### 8\. Debian releases are codenamed after Toy Story characters + +![Toy Story Characters][14] + +Debian releases are codenamed after the characters from Pixar’s hit animation movie series [Toy Story][15]. + +Debian 1.1 was the first release with a codename. It was named Buzz after the Toy Story character Buzz Lightyear. + +It was in 1996 and [Bruce Perens][16] had taken over leadership of the Project from Ian Murdock. Bruce was working at Pixar at the time. + +This trend continued and all the subsequent releases had codenamed after Toy Story characters. For example, the current stable release is Stretch while the upcoming release has been codenamed Buster. + +The unstable Debian version is codenamed Sid. This character in Toy Story is a kid with emotional problems and he enjoys breaking toys. This is symbolic in the sense that Debian Unstable might break your system with untested packages. + +#### 9\. Debian also has a BSD ditribution + +Debian is not limited to Linux. Debian also has a distribution based on FreeBSD kernel. It is called [Debian GNU/kFreeBSD][17]. + +#### 10\. Google uses Debian + +[Google uses Debian][18] as its in-house development platform. Earlier, Google used a customized version of Ubuntu as its development platform. Recently they opted for Debian based gLinux. + +#### Happy 25th birthday Debian + +![Happy 25th birthday Debian][19] + +I hope you liked these little facts about Debian. Stuff like these are reasons why people love Debian. + +I wish a very happy 25th birthday to Debian. Please continue to be awesome. Cheers :) + +-------------------------------------------------------------------------------- + +via: https://itsfoss.com/debian-facts/ + +作者:[Abhishek Prakash][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://itsfoss.com/author/abhishek/ +[1]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/08/Interesting-facts-about-debian.jpeg +[2]:https://www.debian.org +[3]:https://itsfoss.com/linus-torvalds-facts/ +[4]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/08/ian-murdock.jpg +[5]:https://en.wikipedia.org/wiki/Ian_Murdock +[6]:https://www.debian.org/doc/manuals/project-history/ap-manifesto.en.html +[7]:https://www.debian.org/social_contract +[8]:https://en.wikipedia.org/wiki/Progeny_Linux_Systems +[9]:https://itsfoss.com/ian-murdock-dies-mysteriously/ +[10]:https://www.fsf.org/ +[11]:https://www.spi-inc.org/ +[12]:https://www.debian.org/releases/sid/ +[13]:https://www.debian.org/releases/testing/ +[14]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/08/toy-story-characters.jpeg +[15]:https://en.wikipedia.org/wiki/Toy_Story_(franchise) +[16]:https://perens.com/about-bruce-perens/ +[17]:https://wiki.debian.org/Debian_GNU/kFreeBSD +[18]:https://itsfoss.com/goobuntu-glinux-google/ +[19]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/08/happy-25th-birthday-Debian.jpeg diff --git a/sources/talk/20180817 Mixing software development roles produces great results.md b/sources/talk/20180817 Mixing software development roles produces great results.md new file mode 100644 index 0000000000..20c2e76a3d --- /dev/null +++ b/sources/talk/20180817 Mixing software development roles produces great results.md @@ -0,0 +1,71 @@ +Mixing software development roles produces great results +====== + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/checklist_hands_team_collaboration.png?itok=u82QepPk) + +Most open source communities don’t have a lot of formal roles. There are certainly people who help with sysadmin tasks, testing, writing documentation, and translating or developing code. But people in open source communities typically move among different roles, often fulfilling several at once. + +In contrast, team members at most traditional companies have defined roles, working on documentation, support, QA, and in other areas. + +Why do open source communities take a shared-role approach, and more importantly, how does this way of collaborating affect products and customers? + +[Nextcloud][1] has adopted this community-style practice of mixing roles, and we see large benefits for our customers and our users. + +### 1\. Better product testing + +Testing is a difficult job, as any tester can tell you. You need to understand the products engineers develop, and you need to devise test plans, execute them, and return the results to the developers. When that process is done, the developer makes changes, and you repeat the process, going back-and-forth as many times as necessary until the job is done. + +In a community, contributors typically feel responsible for the projects they develop, so they test and document them extensively before handing them to users. Users close to the project often help test, translate, and write documentation in collaboration with developers. This creates a much tighter, faster feedback loop, speeding up development and improving quality. + +When developers continuously confront the results of their work, it encourages them to write in a way that minimizes testing and debugging. Automated testing is an important element in development, and the feedback loop ensures that it is done right: Developers are organically motivated to automate what should be automated—no more and no less. Sure, they might _want_ others to do more testing or test automation, but when testing is the right thing to do, they do it. Moreover, they review each others' code because they know that issues tend to come back bite them later. + +So, while I won't argue that it's better to forgo dedicated testers, certainly in a project without community volunteers who test, testers should be developers and closely embedded in the development team. The result? Customers get a product that was tested and developed by people who are 100% motivated to ensure that it is stable and reliable. + +### 2\. Close alignment between development and customer needs + +It is extraordinarily difficult to align product development with customer needs. Every customer has their own unique needs, there are long- and short-term factors to consider—and of course, as a company, you have ideas on where you want to go. How do you integrate all these ideas and visions? + +Companies typically create roles like product management, support, QA, and others, which are separate from engineering and product development. The idea behind this is that people do best when they specialize, and engineers shouldn't be bothered with "simple" tasks like testing or support. + +In effect, this role separation is a cost-cutting measure. It enables management to micromanage and feel more in control as they can simply order product management, for example, to prioritize items on the roadmap. (It also creates more meetings!) + +In communities, on the other hand, "those who do the work decide." Developers are often also users (or are paid by users), so they align with users’ needs naturally. When users help with testing (as described above), developers work with them constantly, so both sides fully understand what is possible and what is needed. + +This open way of working closely aligns users and projects. Without management interference and overhead, users' most pressing needs can be quickly met because engineers already intimately understand them. + +At Nextcloud, customers never need to explain things twice or rely on a junior support team member to accurately communicate issues to an engineer. Our engineers continuously calibrate their priorities based on real customer needs. Meanwhile, long-term goals are set collaboratively, based on a deep knowledge of our customers. + +### 3\. The best support + +Unlike proprietary or [open core][2] vendors, open source vendors have a powerful incentive to offer the best possible support: It is a key differentiator from other companies in their ecosystem. + +Why is the driving force behind a project—think [Collabora][3] behind [LibreOffice][4], [The Qt Company][5] behind [Qt][6], or [Red Hat][7] behind [RHEL][8]—the best source of customer support? + +Direct access to engineers, of course. Rather than walling off support from engineering, many of these companies offer customers access to engineers' expertise. This helps ensure that customers always get the best answers as quickly as possible. While some engineers may spend more time than others on support, the entire engineering team plays a role in customer success. Proprietary vendors might provide customers a dedicated on-site engineer for a considerable cost, for example, but an open source company like [OpenNMS][9] offers that same level of service in your support contract—even if you’re not a Fortune 500 customer. + +There's another benefit, which relates back to testing and customer alignment: Sharing roles ensures that engineers deal with customer issues and wishes daily, which motivates them to fix the most common problems quickly. They also tend to build extra tools and features to save customers from asking. + +Put simply, folding QA, support, product management, and other engineering roles into one team ensures that the three famous virtues of great developers—[laziness, impatience, and hubris][10]—closely align with customers. + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/8/mixing-roles-engineering + +作者:[Jos Poortvliet][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://opensource.com/users/jospoortvliet +[1]:https://nextcloud.com/ +[2]:https://en.wikipedia.org/wiki/Open_core +[3]:https://www.collaboraoffice.com/ +[4]:https://www.libreoffice.org/ +[5]:https://www.qt.io/ +[6]:https://www.qt.io/developers/ +[7]:https://www.redhat.com/en +[8]:https://www.redhat.com/en/technologies/linux-platforms/enterprise-linux +[9]:https://www.opennms.org/en +[10]:http://threevirtues.com/ diff --git a/sources/talk/20180817 OERu makes a college education affordable.md b/sources/talk/20180817 OERu makes a college education affordable.md new file mode 100644 index 0000000000..ba7d66b7a5 --- /dev/null +++ b/sources/talk/20180817 OERu makes a college education affordable.md @@ -0,0 +1,60 @@ +OERu makes a college education affordable +====== + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/edu_math_formulas.png?itok=B59mYTG3) + +Open, higher education courses are a boon to adults who don’t have the time, money, or confidence to enroll in traditional college courses but want to further their education for work or personal satisfaction. [OERu][1] is a great option for these learners. It allows people to take courses assembled by accredited colleges and universities for free, using open textbooks, and pay for assessment only when (and if) they want to apply for formal academic credit. + +I spoke with [Dave Lane][2], open source technologist at the [Open Education Resource Foundation][3], which is OERu’s parent organization, to learn more about the program. The OER Foundation is a nonprofit organization hosted by [Otago Polytechnic][4] in Dunedin, New Zealand. It partners with organizations around the globe to provide leadership, networking, and support to help advance [open education principles][5]. + +OERu is one of the foundation's flagship projects. (The other is [WikiEducator][6], a community of educators collaboratively developing open source materials.) OERu was conceived in 2011, two years after the foundation’s launch, with representatives from educational institutions around the world. + +Its network "is made up of tertiary educational institutions in five continents working together to democratize tertiary education and its availability for those who cannot afford (or cannot find a seat in) tertiary education," Dave says. Some of OERu’s educational partners include UTaz (Australia), Thompson River University (Canada), North-West University or National Open University (ZA and Nigeria in Africa, respectively), and the University of the Highlands and Islands (Scotland in the UK). Funding is provided by the [William and Flora Hewlett Foundation][7]. These institutions have worked out the complexity associated with transferring academic credits within the network and across the different educational cultures, accreditation boards, and educational review committees. + +### How it works + +The primary requirements for taking OERu courses are fluency in English (which is the primary teaching language) and having a computer with internet access. To start learning, peruse the [list of courses][8], click the title of the course you want to take, and click “Start Learning” to complete any registration details (different courses have different requirements). + +Once you complete a course, you can take an assessment that may qualify you for college-level course credit. While there’s no cost to take a course, each partner institution charges fees for administering assessments—but they are far less expensive than traditional college tuition and fees. + +In March 2018, OERu launched a [Certificate Higher Education Business][9] (CertHE), a one-year program that the organization calls its [first year of study][10], which is "equivalent to the first year of a bachelor's degree." CertHE “is an introductory level qualification in business and management studies which provides a general overview for a possible career in business across a wide range of sectors and industries.” Although CertHE assessment costs vary, it’s likely that the first full year of study will be US$ 2,500, a significant cost savings for students. + +OERu is adding courses and looking for ways to expand the model to eventually offer full baccalaureate degrees and possibly even graduate degrees at much lower cost than a traditional degree program. + +### Open source technologist's background + +Dave didn’t set out to work in IT or live and work in New Zealand. He grew up in the United States and earned his master’s degree in mechanical engineering from the University of Washington. Fresh out of graduate school, he moved to New Zealand to take a position as a research scientist at a government-funded [Crown Research Institute][11] to improve the efficiency of the country’s forest industry. + +IT and open technologies were important parts of getting his job done. "The image processing and photogrammetry software I developed … was built on Linux, entirely using open source math (C/C++) and interface libraries (Qt)," he says. "The source material for my advanced photogrammetric algorithms was US Geological Survey scientist papers from the 1950s-60s, all publicly available." + +His frustration with the low quality of IT systems in the outlying offices led him to assume the role of "ad hoc IT manager" using "100% open source software," he says, which delighted his colleagues but frustrated the fulltime IT staff in the main office. + +After four years of working for the government, he founded a company called Egressive to build Linux-based server systems for small businesses in the Christchurch area. Egressive became a successful small business IT provider, specializing in free and open source software, web development and hosting, systems integration, and outsourced sysadmin services. After selling the business, he joined the OER Foundation’s staff in 2015. In addition to working on the WikiEducator.org and OERu projects, he develops [open source collaboration][12] and teaching tools for the foundation. + +If you're interested in learning more about the OER Foundation, OERu, open source technology, and Dave's work, take a look at [his blog][13]. + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/8/oeru-courses + +作者:[João Trindade][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.flickr.com/photos/joao_trindade/4362409183 +[1]:https://oeru.org/ +[2]:https://www.linkedin.com/in/davelanenz/ +[3]:http://wikieducator.org/OERF:Home +[4]:https://www.op.ac.nz/ +[5]:https://oeru.org/how-it-works/ +[6]:http://wikieducator.org/ +[7]:https://hewlett.org/ +[8]:https://oeru.org/courses/ +[9]:https://oeru.org/certhe-business/ +[10]:https://oeru.org/qualifications/ +[11]:https://en.wikipedia.org/wiki/Crown_Research_Institute +[12]:https://tech.oeru.org/many-simple-tools-loosely-coupled +[13]:https://tech.oeru.org/blog/1 diff --git a/sources/talk/20180826 How to Install and Use FreeDOS on VirtualBox.md b/sources/talk/20180826 How to Install and Use FreeDOS on VirtualBox.md new file mode 100644 index 0000000000..8ba7db5139 --- /dev/null +++ b/sources/talk/20180826 How to Install and Use FreeDOS on VirtualBox.md @@ -0,0 +1,154 @@ +How to Install and Use FreeDOS on VirtualBox +====== +This step-by-step guide shows you how to install FreeDOS on VirtualBox in Linux. + +### Installing FreeDOS on VirtualBox in Linux + + + +In November of 2017, I [interviewed Jim Hall][1] about the history behind the [FreeDOS project][2]. Today, I’m going to tell you how to install and use FreeDOS. Please note: I will be using [VirtualBox][3] 5.2.14 on [Solus][4]. + +Note: I used Solus as the host operating system for this tutorial because it is very easy to setup. One thing you should keep in mind is that Solus’ Software Center contains two versions of VirtualBox: `virtualbox` and `virtualbox-current`. Solus gives you the option to use the linux-lts kernel and the linux-current kernel. `virtualbox`is modified for linux-lts and `virtualbox-current` is for linux-current. + +#### Step 1 – Create New Virtual Machine + +![][5] + +Once you open VirtualBox, press the “New” button to create a new virtual machine. You can name it whatever you want, I just use “FreeDOS”. You can use the label to specify what version of FreeDOS you are installing. You also need to select the type and version of the operating system you will be installing. Select “Other” and “DOS”. + +#### Step 2 – Select Memory Size + +![][6] + +The next dialog box will ask you how much of the host computer’s memory you want to make available to FreeDOS. The default is 32MB. Don’t change it. Back in the day, this would be a huge amount of RAM for a DOS machine. If you need to, you can increase it later by right-clicking on the virtual machine you created for FreeDOS and selecting Settings -> System. + +![][7] + +#### Step 3 – Create Virtual Hard Disk + +![][8] + +Next, you will be asked to create a virtual hard drive where FreeDOS and its files will be stored. Since you haven’t created one yet, just click “Create”. + +The next dialog box will ask you what hard disk file type you want to use. This default (VirtualBox Disk Image) works just fine. Click “Next”. + +The next question you will encounter is how you want the virtual disk to act. Do you want it to start small and gradually grow to its full size as you create files and install programs? Then choose dynamically allocated. If you prefer that the virtual hard drive (vhd) is created at full size, then choose fixed size. Dynamically allocated is nice if you don’t plan to use the whole vhd or if you don’t have very much free space on your hard drive. (Keep in mind that while the size of a dynamically allocated vhd increases as you add files, it will not drop when you remove files.) I prefer dynamically allocated, but you can choose the option that serves your needs best and click “Next”. + +![][9] + +Now, you can choose the size and location of the vhd. 500 MB should be plenty of space. Remember most of the programs you will be using will be text-based, thus fairly small. Once you make your adjustments, click Create, + +#### Step 4 – Attach .iso file + +Before we continue, you will need to [download][10] the FreeDOS .iso file. You will need to choose the CDROM “standard” installer. + +![][11] + +Once the file has been downloaded, return to VirtualBox. Select your virtual machine and open the settings. You can do this by either right-clicking on the virtual machine and selecting “Settings” or highlight the virtual machine and click the “Settings” button. + +Now, click the “Storage” tab. Under “Storage Devices”, select the CD icon. (It should say “Empty” next to it.) In the “Attributes” panel on the right, click on the CD icon and select the location of the .iso file you just downloaded. + +Note: Typically, after you install an operating system on VirtualBox you can delete the original .iso file. Not with FreeDOS. You need the .iso file if you want to install applications via the FreeDOS package manager. I generally keep the ,iso file attached the virtual machine in case I want to install something. If you do that, you have to make sure that you tell FreeDOS you want to boot from the hard drive each time you boot it up because it defaults to the attached CD/iso. If you forget to attach the .iso, don’t worry. You can do so by selecting “Devices” on the top of your FreeDOS virtual machine window. The .iso files are listed under “Optical Drives”. + +#### Step 5 – Install FreeDOS + +![][12] + +Now that we’ve completed all of the preparations, let’s install FreeDOS. + +First, you need to be aware of a bug in the most recent version of VirtualBox. If you start the virtual machine that we just created and select “Install to harddisk” when the FreeDOS welcome screen appears, you will see an unending, scrolling mass of machine code. I’ve only run into this issue recently and it affects both the Linux and Windows versions of VirtualBox. (I know first hand.) + +To get around this, you need to make a simple edit. When you see the FreeDOS welcome screen, press Tab. (Make sure that the “Install to harddrive” option is selected.) Type the word `raw` after “fdboot.img” and hit Enter. The FreeDOS installer will then start. + +![][13] + +The first part of the installer will handle formatting your virtual drive. Once formatting is completed, the installer will reboot. When the FreeDOS welcome screen appears again, you will have to re-enter the `raw` comment you used earlier. + +Make sure that you select “Yes” on all of the questions in the installer. One important question that doesn’t have a “Yes” or “No” answer is: “What FreeDOS packages do you want to install?. The two options are “Base packages” or “Full installation”. Base packages are for those who want a DOS experience most like the original MS-DOS. The Full installation includes a bunch of tools and utilities to improve DOS. + +At the end of the installation, you will be given the option to reboot or stay on DOS. Select “reboot”. + +#### Step 6 – Setup Networking + +Unlike the original DOS, FreeDOS can access the internet. You can install new packages and update the ones already you have installed. In order to use networking, you need to install several applications in FreeDOS. + +![][14] + +First, boot into your newly created FreeDOS virtual machine. At the FreeDOS selection screen, select “Boot from System harddrive”. + +![][15] + +Now, to access the FreeDOS package manager, type `fdimples`. You can navigate around the package manager with the arrow keys and select categories or packages with the space bar. From the “Networking” category, you need to select `fdnet`. The FreeDOS Project also recommends installing `mtcp` and `wget`. Hit “Tab” several times until “OK” is selected and press “Enter”. Once the installation is complete, type `reboot` and hit enter. After the system reboots, boot to your system drive. If the network installation was successful, you will see several new messages at the terminal listing your network information. + +![][16] + +##### Note + +Sometimes the default VirtualBox setup doesn’t work. If that happens, close your FreeDOS VirtualBox window. Right-click your virtual machine from the main VirtualBox screen and select “Settings”. The default VirtualBox network setting is “NAT”. Change it to “Bridged Adapter” and retry installing the FreeDOS packages. It should work now. + +#### Step 7 – Basic Usage of FreeDOS + +##### Commons Commands + +Now that you have installed FreeDOS, let’s look at a few basic commands. If you have ever used the Command Prompt on Windows, you will be familiar with some of these commands. + + * `DIR`– display the contents of the current directory + * `CD` – change the directory you are currently in + * `COPY OLD.TXT NEW.TXT`– copy files + * `TYPE TEST.TXT` – display content of file + * `DEL TEST.TXT` – delete file + * `XCOPY DIR NEWDIR` – copy directory and all of its contents + * `EDIT TEST.TXT`– edit a file + * `MKDIR NEWDIR` – create a new directory + * `CLS` – clear the screen + + + +You can find more basic DOS commands on the web or the [handy cheat sheet][17] created by Jim Hall. + +##### Running a Program + +Running program on FreeDos is fairly easy. When you install an application with the `fdimples` package manager, be sure to note where the .EXE file of the application is located. This is shown in the application’s details. To run the application, you generally need to navigate to the application folder and type the application’s name. + +For example, FreeDOS has an editor named `FED` that you can install. After installing it, all you need to do is navigate to `C:\FED` and type `FED`. + +Sometimes a program, such as Pico, is stored in the `\bin` folder. These programs can be called up from any folder. + +Games usually have an .EXE program or two that you have to run before you can play the game. These setup file usually fix sound, video, or control issues. + +If you run into problems that this tutorial didn’t cover, don’t forget to visit the [home of FreeDOS][2]. They have a wiki and several other support options. + +Have you ever used FreeDOS? What tutorials would you like to see in the future? Please let us know in the comments below. + +If you found this article interesting, please take a minute to share it on social media, Hacker News or [Reddit][18]. + +-------------------------------------------------------------------------------- + +via: https://itsfoss.com/install-freedos/ + +作者:[John Paul][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://itsfoss.com/author/john/ +[1]:https://itsfoss.com/interview-freedos-jim-hall/ +[2]:http://www.freedos.org/ +[3]:https://www.virtualbox.org/ +[4]:https://solus-project.com/home/ +[5]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/07/freedos-tutorial-1.jpg +[6]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/07/freedos-tutorial-2.jpg +[7]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/07/freedos-tutorial-3.jpg +[8]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/07/freedos-tutorial-4.jpg +[9]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/07/freedos-tutorial-6.jpg +[10]:http://www.freedos.org/download/ +[11]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/07/freedos-tutorial-7.jpg +[12]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/07/freedos-tutorial-8.png +[13]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/07/freedos-tutorial-9.png +[14]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/07/freedos-tutorial-10.png +[15]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/07/freedos-tutorial-11.png +[16]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/07/freedos-tutorial-12.png +[17]:https://opensource.com/article/18/6/freedos-commands-cheat-sheet +[18]:http://reddit.com/r/linuxusersgroup diff --git a/sources/talk/20180904 How blockchain can complement open source.md b/sources/talk/20180904 How blockchain can complement open source.md new file mode 100644 index 0000000000..7712539f3f --- /dev/null +++ b/sources/talk/20180904 How blockchain can complement open source.md @@ -0,0 +1,95 @@ +How blockchain can complement open source +====== + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/block-quilt-chain.png?itok=mECoDbrc) + +[The Cathedral and The Bazaar][1] is a classic open source story, written 20 years ago by Eric Steven Raymond. In the story, Eric describes a new revolutionary software development model where complex software projects are built without (or with a very little) central management. This new model is open source. + +Eric's story compares two models: + + * The classic model (represented by the cathedral), in which software is crafted by a small group of individuals in a closed and controlled environment through slow and stable releases. + * And the new model (represented by the bazaar), in which software is crafted in an open environment where individuals can participate freely but still produce a stable and coherent system. + + + +Some of the reasons open source is so successful can be traced back to the founding principles Eric describes. Releasing early, releasing often, and accepting the fact that many heads are inevitably better than one allows open source projects to tap into the world’s pool of talent (and few companies can match that using the closed source model). + +Two decades after Eric's reflective analysis of the hacker community, we see open source becoming dominant. It is no longer a model only for scratching a developer’s personal itch, but instead, the place where innovation happens. Even the world's [largest][2] software companies are transitioning to this model in order to continue dominating. + +### A barter system + +If we look closely at how the open source model works in practice, we realize that it is a closed system, exclusive only to open source developers and techies. The only way to influence the direction of a project is by joining the open source community, understanding the written and the unwritten rules, learning how to contribute, the coding standards, etc., and doing it yourself. + +This is how the bazaar works, and it is where the barter system analogy comes from. A barter system is a method of exchanging services and goods in return for other services and goods. In the bazaar—where the software is built—that means in order to take something, you must also be a producer yourself and give something back in return. And that is by exchanging your time and knowledge for getting something done. A bazaar is a place where open source developers interact with other open source developers and produce open source software the open source way. + +The barter system is a great step forward and an evolution from the state of self-sufficiency where everybody must be a jack of all trades. The bazaar (open source model) using the barter system allows people with common interests and different skills to gather, collaborate, and create something that no individual can create on their own. The barter system is simple and lacks complex problems of the modern monetary systems, but it also has some limitations, such as: + + * Lack of divisibility: In the absence of a common medium of exchange, a large indivisible commodity/value cannot be exchanged for a smaller commodity/value. For example, if you want to do even a small change in an open source project, you may sometimes still need to go through a high entry barrier. + * Storing value: If a project is important to your company, you may want to have a large investment/commitment in it. But since it is a barter system among open source developers, the only way to have a strong say is by employing many open source committers, and that is not always possible. + * Transferring value: If you have invested in a project (trained employees, hired open source developers) and want to move focus to another project, it is not possible to transfer expertise, reputation, and influence quickly. + * Temporal decoupling: The barter system does not provide a good mechanism for deferred or advance commitments. In the open source world, that means a user cannot express commitment or interest in a project in a measurable way in advance, or continuously for future periods. + + + +Below, we will explore how to address these limitations using the back door to the bazaar. + +### A currency system + +People are hanging at the bazaar for different reasons: Some are there to learn, some are there to scratch a personal developer's itch, and some work for large software farms. Because the only way to have a say in the bazaar is to become part of the open source community and join the barter system, in order to gain credibility in the open source world, many large software companies employ these developers and pay them in monetary value. This represents the use of a currency system to influence the bazaar. Open source is no longer only for scratching the personal developer itch. It also accounts for a significant part of the overall software production worldwide, and there are many who want to have an influence. + +Open source sets the guiding principles through which developers interact and build a coherent system in a distributed way. It dictates how a project is governed, how software is built, and how the output distributed to users. It is an open consensus model for decentralized entities for building quality software together. But the open source model does not cover how open source is subsidized. Whether it is sponsored, directly or indirectly, through intrinsic or extrinsic motivators is irrelevant to the bazaar. + +![](https://opensource.com/sites/default/files/uploads/tokenomics_-_page_4.png) + +Currently, there is no equivalent of the decentralized open source development model for subsidization purposes. The majority of open source subsidization is centralized, where typically one company dominates a project by employing the majority of the open source developers of that project. And to be honest, this is currently the best-case scenario, as it guarantees that the developers will be paid for a long period and the project will continue to flourish. + +There are also exceptions for the project monopoly scenario: For example, some Cloud Native Computing Foundation projects are developed by a large number of competing companies. Also, the Apache Software Foundation aims for their projects not to be dominated by a single vendor by encouraging diverse contributors, but most of the popular projects, in reality, are still single-vendor projects. + +What we are missing is an open and decentralized model that works like the bazaar without a central coordination and ownership, where consumers (open source users) and producers (open source developers) interact with each other, driven by market forces and open source value. In order to complement open source, such a model must also be open and decentralized, and this is why I think the blockchain technology would [fit best here][3]. + +Most of the existing blockchain (and non-blockchain) platforms that aim to subsidize open source development are targeting primarily bug bounties, small and piecemeal tasks. A few also focus on funding new open source projects. But not many aim to provide mechanisms for sustaining continued development of open source projects—basically, a system that would emulate the behavior of an open source service provider company, or open core, open source-based SaaS product company: ensuring developers get continued and predictable incentives and guiding the project development based on the priorities of the incentivizers; i.e., the users. Such a model would address the limitations of the barter system listed above: + + * Allow divisibility: If you want something small fixed, you can pay a small amount rather than the full premium of becoming an open source developer for a project. + * Storing value: You can invest a large amount into a project and ensure both its continued development and that your voice is heard. + * Transferring value: At any point, you can stop investing in the project and move funds into other projects. + * Temporal decoupling: Allow regular recurring payments and subscriptions. + + + +There would be also other benefits, purely from the fact that such a blockchain-based system is transparent and decentralized: to quantify a project’s value/usefulness based on its users’ commitment, open roadmap commitment, decentralized decision making, etc. + +### Conclusion + +On the one hand, we see large companies hiring open source developers and acquiring open source startups and even foundational platforms (such as Microsoft buying GitHub). Many, if not most, long-running successful open source projects are centralized around a single vendor. The significance of open source and its centralization is a fact. + +On the other hand, the challenges around [sustaining open source][4] software are becoming more apparent, and many are investigating this space and its foundational issues more deeply. There are a few projects with high visibility and a large number of contributors, but there are also many other still-important projects that lack enough contributors and maintainers. + +There are [many efforts][3] trying to address the challenges of open source through blockchain. These projects should improve the transparency, decentralization, and subsidization and establish a direct link between open source users and developers. This space is still very young, but it is progressing quickly, and with time, the bazaar is going to have a cryptocurrency system. + +Given enough time and adequate technology, decentralization is happening at many levels: + + * The internet is a decentralized medium that has unlocked the world’s potential for sharing and acquiring knowledge. + * Open source is a decentralized collaboration model that has unlocked the world’s potential for innovation. + * Similarly, blockchain can complement open source and become the decentralized open source subsidization model. + + + +Follow me on [Twitter][5] for other posts in this space. + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/9/barter-currency-system + +作者:[Bilgin lbryam][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://opensource.com/users/bibryam +[1]: http://catb.org/ +[2]: http://oss.cash/ +[3]: https://opensource.com/article/18/8/open-source-tokenomics +[4]: https://www.youtube.com/watch?v=VS6IpvTWwkQ +[5]: http://twitter.com/bibryam diff --git a/sources/talk/20180904 Why schools of the future are open.md b/sources/talk/20180904 Why schools of the future are open.md new file mode 100644 index 0000000000..32b2f58e99 --- /dev/null +++ b/sources/talk/20180904 Why schools of the future are open.md @@ -0,0 +1,48 @@ +Why schools of the future are open +====== + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/EDU_OSDC_BYU_520x292_FINAL.png?itok=NVY7vR8o) + +Someone recently asked me what education will look like in the modern era. My response: Much like it has for the last 100 years. How's that for a pessimistic view of our education system? + +It's not a pessimistic view as much as it is a pragmatic one. Anyone who spends time in schools could walk away feeling similarly, given that the ways we teach young people are stubbornly resistant to change. As schools in the United States begin a new year, most students are returning to classrooms where desks are lined-up in rows, the instructional environment is primarily teacher-centred, progress is measured by Carnegie units and A-F grading, and collaboration is often considered cheating. + +Were we able to point to evidence that this industrialized model was producing the kind of results that are required, where every child is given the personal attention needed to grow a love of learning and develop the skills needed to thrive in today's innovation economy, then we could very well be satisfied with the status quo. But any honest and objective look at current metrics speaks to the need for fundamental change. + +But my view isn't a pessimistic one. In fact, it's quite optimistic. + +For as easy as it is to dwell on what's wrong with our current education model, I also know of example after example of where education stakeholders are willing to step out of what's comfortable and challenge this system that is so immune to change. Teachers are demanding more collaboration with peers and more ways to be open and transparent about prototyping ideas that lead to true innovation for students—not just repackaging of traditional methods with technology. Administrators are enabling deeper, more connected learning to real-world applications through community-focused, project-based learning—not just jumping through hoops of "doing projects" in isolated classrooms. And parents are demanding that the joy and wonder of learning return to the culture of their schools that have been corrupted by an emphasis on test prep. + +These and other types of cultural changes are never easy, especially in an environment so reluctant to take risks in the face of political backlash from any dip in test scores (regardless of statistical significance). So why am I optimistic that we are approaching a tipping point where the type of changes we desperately need can indeed overcome the inertia that has thwarted them for too long? + +Because there is something else in water at this point in our modern era that was not present before: an ethos of openness, catalyzed by digital technology. + +Think for a moment: If you need to learn how to speak basic French for an upcoming trip to France, where do you turn? You could sign up for a course at a local community college or check out a book from the library, but in all likelihood, you'll access a free online video and learn the basics you will need for your trip. Never before in human history has free, on-demand learning been so accessible. In fact, one can sign up right now for a free, online course from MIT on "[Special Topics in Mathematics with Applications: Linear Algebra and the Calculus of Variations][1]." Sign me up! + +Why do schools such as MIT, Stanford, and Harvard offer free access to their courses? Why are people and corporations willing to openly share what was once tightly controlled intellectual property? Why are people all over the planet willing to invest their time—for no pay—to help with citizen science projects? + +There is something else in water at this point in our modern era that was not present before: an ethos of openness, catalyzed by digital technology. + +In his wonderful book [Open: How We'll Work Live and Learn in the Future][2], author David Price clearly describes how informal, social learning is becoming the new norm of learning, especially among young people accustomed to being able to get the "just in time" knowledge they need. Through a series of case studies, Price paints a clear picture of what happens when traditional institutions don't adapt to this new reality and thus become less and less relevant. That's the missing ingredient that has the crowdsourced power of creating positive disruption. + +What Price points out (and what people are now demanding at a grassroots level) is nothing short of an open movement, one recognizing that open collaboration and free exchange of ideas have already disrupted ecosystems from music to software to publishing. And more than any top-down driven "reform," this expectation for openness has the potential to fundamentally alter an educational system that has resisted change for too long. In fact, one of the hallmarks of the open ethos is that it expects the transparent and fair democratization of knowledge for the benefit of all. So what better ecosystem for such an ethos to thrive than within the one that seeks to prepare young people to inherit the world and make it better? + +Sure, the pessimist in me says that my earlier prediction about the future of education may indeed be the state of education in the short term future. But I am also very optimistic that this prediction will be proven to be dead wrong. I know that I and many other kindred-spirit educators are working every day to ensure that it's wrong. Won't you join me as we start a movement to help our schools [transform into open organizations][3]—to transition from from an outdated, legacy model to one that is more open, nimble, and responsive to the needs of every student and the communities in which they serve? + +That's a true education model appropriate for the modern era. + +-------------------------------------------------------------------------------- + +via: https://opensource.com/open-organization/18/9/modern-education-open-education + +作者:[Ben Owens][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://opensource.com/users/engineerteacher +[1]: https://ocw.mit.edu/courses/mechanical-engineering/2-035-special-topics-in-mathematics-with-applications-linear-algebra-and-the-calculus-of-variations-spring-2007/ +[2]: https://www.goodreads.com/book/show/18730272-open +[3]: https://opensource.com/open-organization/resources/open-org-definition diff --git a/sources/talk/20180906 DevOps- The consequences of blame.md b/sources/talk/20180906 DevOps- The consequences of blame.md new file mode 100644 index 0000000000..f7efed4d66 --- /dev/null +++ b/sources/talk/20180906 DevOps- The consequences of blame.md @@ -0,0 +1,67 @@ +DevOps: The consequences of blame +====== + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/mistake_bug_fix_find_error.png?itok=PZaz3dga) + +Merriam-Webster defines "blame" as both a verb and a noun. As a verb, it means "to find fault with or to hold responsible." As a noun, it means "an expression of disapproval or responsibility for something believed to deserve censure." + +Either way, blame isn’t a pleasant thing. It can create feelings of fear and shame, foster power imbalances, and cause us to devalue others. + +Just think of what it felt like the last time you were yelled at or accused of something. Conversely, consider the opposite of blame: Praise, flattery, and approval. How does it feel to be complimented or commended for a job well done? + +You may be wondering what all this talk about blame has to do with DevOps. Read on: + +### DevOps and blame + +The three pillars of DevOps are flow, feedback, and continuous improvement. How can an organization or a team improve if its members are focused on finding someone to blame? For a DevOps culture to succeed, blame must be eliminated. + +For example, suppose your product has a bug or experiences an outage. If your organization's leaders react to this by looking for someone to blame, there’s little chance for feedback on how to improve. Look at how blame is flowing in your organization and work to remove it. Strive for blameless post-mortems and move away from _root-cause analysis_ , which tends to focus on assigning blame. In today’s complex business infrastructure, many factors can contribute to bugs and other problems. Successful DevOps teams practice post-incident reviews to examine the bigger picture when things go wrong. + +### Consequences of blame + +DevOps is about creating a culture of collaboration and community. This is not possible in a culture of blame. Because blame does not correct behavior, there is no continuous learning. What _is_ learned is how to avoid blame—so instead of solving problems, team members focus on how they can avoid being blamed for them. + +What about accountability? Avoiding blame does not mean avoiding accountability or consequences. Here are some tips to create an environment in which people are held accountable without blame: + + * When mistakes are made, focus on what steps you can take to avoid making the same mistake in the future. What did you learn, and how can you apply that knowledge to improving things? + + * When something goes wrong, people feel stress. Work toward eliminating or reducing that stress. Avoid yelling and putting additional pressure on people. + + * Accept that mistakes will happen. Nobody—and nothing—is perfect. + + * When corrective actions are necessary, provide them privately, not publicly. + + + + +As a child, I loved reading the [Family Circus][1] comic strip, especially the ones featuring “Not Me.” Not Me frequently appeared with “Ida Know” and “Nobody” when Mom and Dad asked an accusatory question. Why did the kids in Family Circus blame Not Me? Look no further than the parents' angry, frustrated expressions. Like the kids in the comic strip, we quickly learn to assign blame or look for faults in others because blaming ourselves is too painful. + +In his book, [_Thinking, Fast and Slow_][2], author Daniel Kanheman points out that most of us spend as little time as possible thinking—after all, thinking is hard. To make things easier, we learn from previous experiences, which in turn creates biases. If blame is part of that equation, it will be included in our bias: _“The last time a question was asked in a meeting and I took responsibility, I was chewed out in front of all my co-workers. I won’t do that again.”_ + +When something goes wrong, we want answers and accountability. Uncertainty is scary and leads to stress; we prefer predictable scenarios. This drives us to look for root causes, which often leads to blame. + +But what if, instead of assigning blame, we turned the situation into something constructive and helpful—an opportunity for learning? It isn't always easy, but working to eliminate blame will build a stronger DevOps team and a happier, more productive company. + +Next time you find yourself starting to look for someone to blame, think of this poem by Rupi Kaur: + +_“It takes grace_ + +_To remain kind_ + +_In cruel situations”_ + + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/9/consequences-blame-your-devops-team + +作者:[Dawn Parzych][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://opensource.com/users/dawnparzych +[1]: http://familycircus.com/comics/september-1-2012/ +[2]: https://www.amazon.com/Thinking-Fast-Slow-Daniel-Kahneman/dp/0374533555 diff --git a/sources/talk/20180915 Linux vs Mac- 7 Reasons Why Linux is a Better Choice than Mac.md b/sources/talk/20180915 Linux vs Mac- 7 Reasons Why Linux is a Better Choice than Mac.md new file mode 100644 index 0000000000..42f842a803 --- /dev/null +++ b/sources/talk/20180915 Linux vs Mac- 7 Reasons Why Linux is a Better Choice than Mac.md @@ -0,0 +1,133 @@ +Translating by Ryze-Borgia + +Linux vs Mac: 7 Reasons Why Linux is a Better Choice than Mac +====== +Recently, we highlighted a few points about [why Linux is better than Windows][1]. Unquestionably, Linux is a superior platform. But, like other operating systems it has its drawbacks as well. For a very particular set of tasks (such as Gaming), Windows OS might prove to be better. And, likewise, for another set of tasks (such as video editing), a Mac-powered system might come in handy. It all trickles down to your preference and what you would like to do with your system. So, in this article, we will highlight a number of reasons why Linux is better than Mac. + +If you’re already using a Mac or planning to get one, we recommend you to thoroughly analyze the reasons and decide whether you want to switch/keep using Linux or continue using Mac. + +### 7 Reasons Why Linux is Better Than Mac + +![Linux vs Mac: Why Linux is a Better Choice][2] + +Both Linux and macOS are Unix-like OS and give access to Unix commands, BASH and other shells. Both of them have fewer applications and games than Windows. But the similarity ends here. + +Graphic designers and video editors swear by macOS whereas Linux is a favorite of developers, sysadmins and devops. + +So the question is should you use Linux over Mac? If yes, why? Let me give you some practical and some ideological reasons why Linux is better than Mac. + +#### 1\. Price + +![Linux vs Mac: Why Linux is a Better Choice][3] + +Let’s suppose, you use the system only to browse stuff, watch movies, download photos, write a document, create a spreadsheet, and other similar stuff. And, in addition to those activities, you want to have a secure operating system. + +In that case, you could choose to spend a couple of hundred bucks for a system to get things done. Or do you think spending more for a MacBook is a good idea? Well, you are the judge. + +So, it really depends on what you prefer. Whether you want to spend on a Mac-powered system or get a budget laptop/PC and install any Linux distro for free. Personally, I’ll be happy with a Linux system except for editing videos and music production. In that case, Final Cut Pro (for video editing) and Logic Pro X (for music production) will be my preference. + +#### 2\. Hardware Choices + +![Linux vs Mac: Why Linux is a Better Choice][4] + +Linux is free. You can install it on computers with any configuration. No matter how powerful/old your system is, Linux will work. [Even if you have an 8-year old PC laying around, you can have Linux installed and expect it to run smoothly by selecting the right distro][5]. + +But, Mac is as an Apple-exclusive. If you want to assemble a PC or get a budget laptop (with DOS) and expect to install Mac OS, it’s almost impossible. Mac comes baked in with the system Apple manufactures. + +There are [ways to install macOS on non Apple devices][6]. However, the kind of expertise and troubles it requires, it makes you question whether it’s worth the effort. + +You will have a wide range of hardware choices when you go with Linux but a minimal set of configurations when it comes to Mac OS. + +#### 3\. Security + +![Linux vs Mac: Why Linux is a Better Choice][7] + +A lot of people are all praises for iOS and Mac for being a secure platform. Well, yes, it is secure in a way (maybe more secure than Windows OS), but probably not as secure as Linux. + +I am not bluffing. There are malware and adware targeting macOS and the [number is growing every day][8]. I have seen not-so-techie users struggling with their slow mac. A quick investigation revealed that a [browser hijacking malware][9] was the culprit. + +There are no 100% secure operating systems and Linux is not an exception. There are vulnerabilities in the Linux world as well but they are duly patched by the timely updates provided by Linux distributions. + +Thankfully, we don’t have auto-running viruses or browser hijacking malwares in Linux world so far. And that’s one more reason why you should use Linux instead of a Mac. + +#### 4\. Customization & Flexibility + +![Linux vs Mac: Why Linux is a Better Choice][10] + +You don’t like something? Customize it or remove it. End of the story. + +For example, if you do not like the [Gnome desktop environment][11] on Ubuntu 18.04.1, you might as well change it to [KDE Plasma][11]. You can also try some of the [Gnome extensions][12] to enhance your desktop experience. You won’t find this level of freedom and customization on Mac OS. + +Besides, you can even modify the source code of your OS to add/remove something (which requires necessary technical knowledge) and create your own custom OS. Can you do that on Mac OS? + +Moreover, you get an array of Linux distributions to choose from as per your needs. For instance, if you need to mimic the workflow on Mac OS, [Elementary OS][13] would help. Do you want to have a lightweight Linux distribution installed on your old PC? We’ve got you covered in our list of [lightweight Linux distros][5]. Mac OS lacks this kind of flexibility. + +#### 5\. Using Linux helps your professional career [For IT/Tech students] + +![Linux vs Mac: Why Linux is a Better Choice][14] + +This is kind of controversial and applicable to students and job seekers in the IT field. Using Linux doesn’t make you a super-intelligent being and could possibly get you any IT related job. + +However, as you start using Linux and exploring it, you gain experience. As a techie, sooner or later you dive into the terminal, learning your way to move around the file system, installing applications via command line. You won’t even realize that you have learned the skills that newcomers in IT companies get trained on. + +In addition to that, Linux has enormous scope in the job market. There are so many Linux related technologies (Cloud, Kubernetes, Sysadmin etc.) you can learn, earn certifications and get a nice paying job. And to learn these, you have to use Linux. + +#### 6\. Reliability + +![Linux vs Mac: Why Linux is a Better Choice][15] + +Ever wondered why Linux is the best OS to run on any server? Because it is more reliable! + +But, why is that? Why is Linux more reliable than Mac OS? + +The answer is simple – more control to the user while providing better security. Mac OS does not provide you with the full control of its platform. It does that to make things easier for you simultaneously enhancing your user experience. With Linux, you can do whatever you want – which may result in poor user experience (for some) – but it does make it more reliable. + +#### 7\. Open Source + +![Linux vs Mac: Why Linux is a Better Choice][16] + +Open Source is something not everyone cares about. But to me, the most important aspect of Linux being a superior choice is its Open Source nature. And, most of the points discussed below are the direct advantages of an Open Source software. + +To briefly explain, you get to see/modify the source code yourself if it is an open source software. But, for Mac, Apple gets an exclusive control. Even if you have the required technical knowledge, you will not be able to independently take a look at the source code of Mac OS. + +In other words, a Mac-powered system enables you to get a car for yourself but the downside is you cannot open up the hood to see what’s inside. That’s bad! + +If you want to dive in deeper to know about the benefits of an open source software, you should go through [Ben Balter’s article][17] on OpenSource.com. + +### Wrapping Up + +Now that you’ve known why Linux is better than Mac OS. What do you think about it? Are these reasons enough for you to choose Linux over Mac OS? If not, then what do you prefer and why? + +Let us know your thoughts in the comments below. + +Note: The artwork here is based on Club Penguins. + +-------------------------------------------------------------------------------- + +via: https://itsfoss.com/linux-vs-mac/ + +作者:[Ankush Das][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://itsfoss.com/author/ankush/ +[1]: https://itsfoss.com/linux-better-than-windows/ +[2]: https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/09/Linux-vs-mac-featured.png +[3]: https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/09/linux-vs-mac-1.jpeg +[4]: https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/09/linux-vs-mac-4.jpeg +[5]: https://itsfoss.com/lightweight-linux-beginners/ +[6]: https://hackintosh.com/ +[7]: https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/09/linux-vs-mac-2.jpeg +[8]: https://www.computerworld.com/article/3262225/apple-mac/warning-as-mac-malware-exploits-climb-270.html +[9]: https://www.imore.com/how-to-remove-browser-hijack +[10]: https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/09/linux-vs-mac-3.jpeg +[11]: https://www.gnome.org/ +[12]: https://itsfoss.com/best-gnome-extensions/ +[13]: https://elementary.io/ +[14]: https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/09/linux-vs-mac-5.jpeg +[15]: https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/09/linux-vs-mac-6.jpeg +[16]: https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/09/linux-vs-mac-7.jpeg +[17]: https://opensource.com/life/15/12/why-open-source diff --git a/sources/talk/20180916 Linus, His Apology, And Why We Should Support Him.md b/sources/talk/20180916 Linus, His Apology, And Why We Should Support Him.md new file mode 100644 index 0000000000..e2bf768324 --- /dev/null +++ b/sources/talk/20180916 Linus, His Apology, And Why We Should Support Him.md @@ -0,0 +1,57 @@ +heguangzhi translating + + +Linus, His Apology, And Why We Should Support Him +====== + +![](https://i1.wp.com/www.jonobacon.com/wp-content/uploads/2018/09/Linus-Torvalds-640x353.jpg?resize=640%2C353&ssl=1) + +Today, Linus Torvalds, the creator of Linux, which powers everything from smartwatches to electrical grids posted [a pretty remarkable note on the kernel mailing list][1]. + +As a little bit of backstory, Linus has sometimes come under fire for the ways in which he has expressed feedback, provided criticism, and reacted to various scenarios on the kernel mailing list. This criticism has been fair in many cases: he has been overly aggressive at times, and while the kernel maintainers are a tight-knit group, the optics, particularly for those new to kernel development has often been pretty bad. + +Like many conflict scenarios, this feedback has been communicated back to him in both constructive and non-constructive ways. Historically he has been seemingly reluctant to really internalize this feedback, I suspect partially because (a) the Linux kernel is a very successful project, and (b) some of the critics have at times gone nuclear at him (which often doesn’t work as a strategy towards defensive people). Well, things changed today. + +In his post today he shared some self-reflection on this feedback: + +> This week people in our community confronted me about my lifetime of not understanding emotions. My flippant attacks in emails have been both unprofessional and uncalled for. Especially at times when I made it personal. In my quest for a better patch, this made sense to me. I know now this was not OK and I am truly sorry. + +He went on to not just share an admission that this has been a problem, but to also share a very personal acceptance that he struggles to understand and engage with people’s emotions: + +> The above is basically a long-winded way to get to the somewhat painful personal admission that hey, I need to change some of my behavior, and I want to apologize to the people that my personal behavior hurt and possibly drove away from kernel development entirely. I am going to take time off and get some assistance on how to understand people’s emotions and respond appropriately. + +His post is sure to light up the open source, Linux, and tech world for the next few weeks. For some it will be celebrated as a step in the right direction. For some it will be too little too late, and their animus will remain. For some they will be cautiously supportive, but defer judgement until they have seen his future behavior demonstrate substantive changes. + +### My Take + +I wouldn’t say I know Linus very closely; we have a casual relationship. I see him at conferences from time to time, and we often bump into each other and catch up. I interviewed him for my book and for the Global Learning XPRIZE. From my experience he is a funny, genuine, friendly guy. Interestingly, and not unusually at all for open source, his online persona is rather different to his in-person persona. I am not going to deny that when I would see these dust-ups on LKML, it didn’t reflect the Linus I know. I chalked it down to a mixture of his struggles with social skills, dogmatic pragmatism, and ego. + +His post today is a pretty remarkable change of posture for him, and I encourage that we as a community support him in making these changes. + +**Accepting these personal challenges is tough, particularly for someone in his position**. Linux is a global phenomenon. It has resulted in billions of dollars of technology creation, powering thousands of companies, and changing the norms around of how software is consumed and created. It is easy to forget that Linux was started by a quiet Finnish kid in his university dorm room. It is important to remember that **just because Linux has scaled elegantly, it doesn’t mean that Linus has been able to**. He isn’t a codebase, he is a human being, and bugs are harder to spot and fix in humans. You can’t just deploy a fix immediately. It takes time to identify the problem and foster and grow a change. The starting point for this is to support people in that desire for change, not re-litigate the ills of the past: that will get us nowhere quickly. + +[![Young Linus Torvalds][2]][3] + +I am also mindful of ego. None of us like to admit we have an ago, but we all do. You don’t get to build one of the most fundamental technologies in the last thirty years and not have an ego. He built it…they came…and a revolution was energized because of what he created. While Linus’s ego is more subtle, and thankfully doesn’t extend to faddish self-promotion, overly expensive suits, and forays into Hollywood (quite the opposite), his ego has naturally resulted in abrupt opinions on how his project should run, sometimes plugging fingers in his ears to particularly challenging viewpoints from others. **His post today is a clear example of him putting Linux as a project ahead of his own personal ego**. + +This is important for a few reasons. Firstly, being in such a public position and accepting your personal flaws isn’t a problem many people face, and isn’t a situation many people handle well. I work with a lot of CEOs, and they often say it is the loneliest job on the planet. I have heard American presidents say the same in interviews. This is because they are the top of the tree with all the responsibility and expectations on their shoulders. Put yourself in Linus’s position: his little project has blown up into a global phenomenon, and he didn’t necessarily have the social tools to be able to handle this change. Ego forces these internal struggles under the surface and to push them down and avoid them. So, to accept them as publicly and openly as he did today is a very firm step in the right direction. Now, the true test will be results, but we need to all provide the breathing space for him to accomplish them. + +So, I would encourage everyone to give Linus a shot. This doesn’t mean the frustrations of the past are erased, and he has acknowledged and apologized for these mistakes as a first step. He has accepted he struggles with understanding other’s emotions, and a desire to help improve this for the betterment of the project and himself. **He is a human, and the best tonic for humans to resolve their own internal struggles is the support and encouragement of other humans**. This is not unique to Linus, but to anyone who faces similar struggles. + +All the best, Linus. + +-------------------------------------------------------------------------------- + +via: https://www.jonobacon.com/2018/09/16/linus-his-apology-and-why-we-should-support-him/ + +作者:[Jono Bacon][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://www.jonobacon.com/author/admin/ +[1]: https://lkml.org/lkml/2018/9/16/167 +[2]: https://i1.wp.com/www.jonobacon.com/wp-content/uploads/2018/09/linus.jpg?resize=499%2C342&ssl=1 +[3]: https://i1.wp.com/www.jonobacon.com/wp-content/uploads/2018/09/linus.jpg?ssl=1 diff --git a/sources/talk/20180917 How gaming turned me into a coder.md b/sources/talk/20180917 How gaming turned me into a coder.md new file mode 100644 index 0000000000..f5675c4628 --- /dev/null +++ b/sources/talk/20180917 How gaming turned me into a coder.md @@ -0,0 +1,103 @@ +How gaming turned me into a coder +====== + +Text-based adventure gaming leads to a satisfying career in tech. + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/keyboard_numbers_letters_type_game.jpg?itok=fLlWGw1K) + +I think the first word I learned to type fast—and I mean really fast—was "fireball." + +Like most of us, I started my typing career with a "hunt-and-peck" technique, using my index fingers and keeping my eyes focused on the keyboard to find letters as I needed them. It's not a technique that allows you to read and write at the same time; you might call it half-duplex. It was okay for typing **cd** and **dir** , but it wasn't nearly fast enough to get ahead in the game. Especially if that game was a MUD. + +### Gaming with multi-user dungeons + +MUD is short for multi-user dungeon. Or multi-user domain, depending on who (and when) you ask. MUDs are text-based adventure games, like [Colossal Cave Adventure][1] and Zork, which you may have heard about in Season 2 [Episode 1][2] of [Command Line Heroes][3]. But MUDs have an extra twist: you aren't the only person playing them. They allow you to group with others to tackle particularly nasty beasts, trade goods, and make new friends. They were the great granddaddies of modern massively multiplayer online role-playing games (MMORPGs) like Everquest and World of Warcraft. And, for an aspiring command-line hero, they offered an experience those modern games still don't. + +My "home MUD" was NyxMud, which you could access by telnetting to port 2000 of nyx.cs.du.edu. It was the first command line I ever mastered. In a lot of ways, it allowed me to be a hero—or at least play the part of one. + +One special quality of NyxMud was that every time you connected to play, you started with an empty inventory. The gold you collected was still there from your last session, but none of your hard-won weapons, armor, or magical items were. So, at the end of every session, you had to make it back to a store to sell everything… and you would get a fraction of what you paid. If you were killed, the first player who encountered your lifeless body could take everything you had. + +![dying and losing everything in a MUD.][5] + +This shows what it looks like when you die and lose everything in a MUD + +This made the game extremely sticky. Selling everything and quitting was a horrible thing to do, fiscally speaking. It meant that your session had to be profitable. If you didn't earn enough gold through looting and quests between the time you bought and sold your gear, you wouldn't be able to equip yourself as well the next time you played. If you died, it was even worse: You might find yourself killing balls of slime with a newbie sword as you scraped together enough gold for better gear. + +I never wanted to "pay the store tax" by selling my gear, which meant a lot of late nights and sleeping through morning biology classes. Every modern game designer wants you to say, "I can't have dinner now, Dad, I have to keep playing or I'm in big trouble." NyxMud had me so hooked that I was saying that several decades ago. + +So when it came time to "cast fireball" or die an imminent and ruinous death, I was forced to learn how to type properly. It also forced me to take a social approach to the game—having friends around to fight off scavengers allowed me to reclaim my gear when I died. + +Command-line heroes all have some things in common: They work with others and they type wicked fast. NyxMud trained me to do both. + +### From gamer to creator + +NyxMud was not the largest MUD by any measure. But it was still an expansive world filled with hundreds of areas and dozens of epic adventures, each one tailored to a different level of a player's advancement. Over time, it became apparent that not all these areas were created by the same person. The term "user-generated content" was yet to be invented, but the concept was dead simple even to my young mind: This entire world was created by a group of people, other players. + +Once you completed each of the challenging quests and achieved level 20, you became a wizard. This was a singularity of sorts, beyond which existed a reality known only to a few. During lunch breaks at school, my circle of friends would muse about the powers of a wizard; you see, we knew wizards could create rooms, beasts, items, and quests. We knew they could kill players at will. We really didn't know much else about their powers. The whole thing was shrouded in mystery. + +In our group of high school friends, Eddie was the first to become a wizard. His flaunting and taunting threw us into overdrive, and Jared was quick to follow. I was last, but only by a day or two. Now that 25 years have passed, let's just call it a three-way tie. We discovered it was pretty much what we thought. We could create rooms, beasts, items, and quests. We could kill players. Oh, and we could become invisible. In NyxMud, that was just about it. + +![a wizard’s private workroom][7] + +This shows a wizard’s private workroom. + +Wizards used the Wand of Creation, an item invented by Quasi (rhymed with "crazy"), the grand wizard. He alone had access to the code for the engine, due to a strict policy set by the administrator of the Nyx system where it ran. So, he created a complicated, magical object that would allow users to generate new game elements. This wand, when invoked, ran the wizard through a menu-based workflow for creating rooms and objects, establishing quest objectives, and designing terrible monsters. + +Having that magical wand was enough. I immediately set to work creating new lands and grand adventures across a series of islands, each with a different, exotic climate and theme. I found immense pleasure in hovering, invisible, as the savage beasts from my imagination would slay intrepid adventurers over and over again. But it was even better to see players persevere after a hard battle, knowing I had tweaked and tuned my quests to be just within the realm of possibility. + +Being accepted into this elite group of creators was one of the more rewarding and satisfying moments of my young life. Each new wizard would have to pass my test, spending countless hours and sleepless nights, just as I did, to complete the quests of the wizards before me. I had proven my value through dedication and contribution. It was just a game, but it was also a community—the first one I encountered, and the one that showed me how powerful a properly run [meritocracy][8] could be. + +### From creator to coder + +NyxMud was based on the LPMud codebase, which was created by Lars Pensjö. LPMud was not the first MUD software developed, but it contained one very important innovation: It allowed players to code the game from within the game. It accomplished this by separating the mudlib, which contained all the content and user-facing functionality, from the driver, which acted as a real-time interpreter for the mudlib and provided access to basic network and storage resources. This architecture meant the mudlib could be edited on-the-fly by virtually untrusted people (e.g., players like me) who could augment the game experience without being able to do anything particularly harmful to the server it was running on. The driver provided an "air gap." + +This air gap was not enough for NyxMud; it was allowed to exist only if a single person could be trusted to write all the code. In most LPMud systems, players who became wizards could use **ls** , **cd** , and **ed** to traverse the mudlib and modify files, all from the same command line they had used countless times for casting fireballs and drinking potions. Quasi went to great lengths to modify the Nyx mudlib so wizards couldn't traipse around the system with a full set of sharp tools. The Wand of Creation was born. + +As a wizard who hadn't played any other MUDs, I didn't miss what I never had. Besides, I didn't have a way to access any systems at the time—telnet was disabled on Nyx, which was my only connection to the internet. But I did have access to Usenet, which provided me with [The Totally Unofficial List of Internet Muds][9]. It was clear there was more of the MUD universe for me to discover. I read all the documentation about mudlibs I could get my hands on and got some exposure to [LPC][10], the niche programming language used to create new content. + +I convinced my dad to make an investment in my future by paying for a shell account at Netcom (remember that?). With that account, I could connect to any MUD I wanted, and, based on several strong recommendations, I chose Viking MUD. It still [exists today][11]. It was a real MUD, the bleeding edge, and it showcased the true potential of a universe built with code instead of the limited menu system of a magical wand. But, to be honest, I never got very far as a player. I really wanted to learn how to code, and I didn't want to slay slimeballs with a noobsword for hours to get there. + +There was a very small window of time—between February and August 1992, according to Lauren P. Burka's [Mud Timeline][12]—where the perfect place existed for my exploration. The Mud Institute (TMI for short) was a very special MUD designed to teach people how to program in LPC, illuminating the darkest corners of the mudlib. It offered immediate omnipotence to all who applied and built a community for the development of a new generation of LPMuds. + +![a snippet of code from the wizard's workroom][14] + +This is a snippet of code from the wizard's workroom. + +This was my first exposure to C programming, as LPC was essentially a flavor of C that shared the same types, control structures, and syntax. It was C with training wheels, designed for rapid creation of content but allowing coders to develop intricate game scenarios (if they had the chops). I had always seen the curly brace on my keyboard, and now I knew what it was used for. The only thing I can remember creating was a special vending machine, somewhat inspired by the Wand of Creation, that would create the monster of your choice on-the-spot. + +TMI was not a long-lasting phenomenon; in fact, it was gone almost before I had a chance to discover it. It quickly abandoned its educational charter, although its efforts were ultimately productive with the release of [MudOS][15]—which still lives through its modern-day descendant, [FluffOS][16]. But what a treasure trove of knowledge about a highly specific subject! Immediately after logging in, I was presented with a complete set of developer tools, a library of instructional materials, and a ton of interesting sample code to learn from. + +I never talked to anyone or asked for any help, and I never had to. The community had published just enough resources for me to get started by myself. I was able to learn the basics of structured programming without a textbook or teacher, all within the context of a fantastical computer game. As a result, I have had a long and (mostly) fulfilling career in technology. + +The line from Field of Dreams, "if you build it, they will come," is almost certainly untrue for communities.** **The folks at The Mud Institute built the makings of a great community, but I can't say they were successful. They didn't become a widely known wizarding school—in fact, it's really hard to find any information about TMI at all. If you build it, they may not come; if they do, you may still fail. But it still accomplished something wonderful that its creators never thought to predict: It got me excited about programming. + +For more on the gamer-to-coder phenomenon and its effect on open source community culture, check out [Episode 1 of Season 2 of Command Line Heroes][2]. + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/9/gamer-coder + +作者:[Ross Turk][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://opensource.com/users/rossturk +[1]: https://opensource.com/article/17/6/revisit-colossal-cave-adventure-open-adventure +[2]: https://www.redhat.com/en/command-line-heroes/season-2/press-start +[3]: https://www.redhat.com/en/command-line-heroes +[4]: /file/409311 +[5]: https://opensource.com/sites/default/files/uploads/sourcecode_wizard_workroom.png (dying and losing everything in a MUD) +[6]: /file/409306 +[7]: https://opensource.com/sites/default/files/uploads/wizard_workroom.png (a wizard’s private workroom) +[8]: https://opensource.com/open-organization/16/8/how-make-meritocracy-work +[9]: http://textfiles.com/internet/mudlist.txt +[10]: https://en.wikipedia.org/wiki/LPC_(programming_language) +[11]: https://www.vikingmud.org +[12]: http://www.linnaean.org/~lpb/muddex/mudline.html +[13]: /file/409301 +[14]: https://opensource.com/sites/default/files/uploads/firstroom_newplayer.png (a snippet of code from the wizard's workroom) +[15]: https://en.wikipedia.org/wiki/MudOS +[16]: https://github.com/fluffos/fluffos diff --git a/sources/talk/20180919 5 ways DevSecOps changes security.md b/sources/talk/20180919 5 ways DevSecOps changes security.md new file mode 100644 index 0000000000..28e4b90eec --- /dev/null +++ b/sources/talk/20180919 5 ways DevSecOps changes security.md @@ -0,0 +1,76 @@ +5 ways DevSecOps changes security +====== + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/security-lock-password.jpg?itok=KJMdkKum) + +There’s been an ongoing kerfuffle over whether we need to expand [DevOps][1] to explicitly bring in security. After all, the thinking goes, [DevOps][2] has always been something of a shorthand for a broad set of new practices, using new tools (often open source) and built on more collaborative cultures. Why not [DevBizOps][3] for better aligning with business needs? Or DevChatOps to emphasize better and faster communications? + +However, [as John Willis wrote earlier this year][4] on his coming around to the [DevSecOps][5] terminology, “Hopefully, someday we will have a world where we no longer have to use the word DevSecOps and security will be an inherent part of all service delivery discussions. Until that day, and at this point, my general conclusion is that it’s just three new characters. More importantly, the name really differentiates the problem statement in a world where we as an industry are not doing a great job on information security.” + +So why aren’t we doing a great job on [information security][6], and what does it mean to do a great job in a DevSecOps context? + +We’ve arguably never done a great job of information security in spite of (or maybe because of) the vast industry of complex point products addressing narrow problems. But we also arguably did a good enough job during the era when defending against threats focused on securing the perimeter, network connections were limited, and most users were employees using company-provided devices. + +Those circumstances haven’t accurately described most organizations’ reality for a number of years now. But the current era, which brings in not only DevSecOps but new application architectural patterns, development practices, and an increasing number of threats, defines a stark new normal that requires a faster pace of change. It’s not so much that DevSecOps in isolation changes security, but that infosec circa 2018 requires new approaches. + +Consider these five areas. + +### Automation + +Lots of automation is a hallmark of DevOps generally. It’s partly about speed. If you’re going to move fast (and not break things), you need to have repeatable processes that execute without a lot of human intervention. Indeed, automation is one of the best entry points for DevOps, even in organizations that are still mostly working on monolithic legacy apps. Automating routine processes associated with configurations or testing with easy-to-use tools such as [Ansible][7] is a common quick hit for starting down the path to DevOps. + +DevSecOps is no different. Security today is a continuous process rather than a discrete checkpoint in the application lifecycle, or even a weekly or monthly check. When vulnerabilities are found and fixes issued by a vendor, it’s important they be applied quickly given that exploits taking advantage of those vulnerabilities will be out soon. + +### "Shift left" + +Traditional security is often viewed as a gatekeeper at the end of the development process. Check all the boxes and your app goes into production. Otherwise, try again. Security teams have a reputation for saying no a lot. + +Therefore, the thinking goes, why not move security earlier (left in a typical left-to-right drawing of a development pipeline)? Security may still say no, but the consequences of rework in early-stage development are a lot less than they are when the app is complete and ready to ship. + +I don’t like the “shift left” term, though. It implies that security is still a one-time event that’s just been moved earlier. Security needs to be a largely automated process everywhere in the application lifecycle, from the supply chain to the development and test process all the way through deployment. + +### Manage dependencies + +One of the big changes we see with modern app development is that you often don’t write most of the code. Using open source libraries and frameworks is one obvious case in point. But you may also just use external services from public cloud providers or other sources. In many cases, this external code and services will dwarf what you write yourself. + +As a result, DevSecOps needs to include a serious focus on your [software supply chain][8]. Are you getting your software from trusted sources? Is it up to date? Is it integrated into the security processes that you use for your own code? What policies do you have in place for which code and APIs you can use? Is commercial support available for the components that you are using for your own production code? + +No set of answers are going to be appropriate in all cases. They may be different for a proof-of-concept versus an at-scale production workload. But, as has been the case in manufacturing for a long time (and DevSecOps has many analogs in how manufacturing has evolved), the integrity of the supply chain is critical. + +### Visibility + +I’ve talked a lot about the need for automation throughout all the stages of the application lifecycle. That makes the assumption that we can see what’s going on in each of those stages. + +Effective DevSecOps requires effective instrumentation so that automation knows what to do. This instrumentation falls into a number of categories. There are long-term and high-level metrics that help tell us if the overall DevSecOps process is working well. There are critical alerts that require immediate human intervention (the security scanning system is down!). There are alerts, such as for a failed scan, that require remediation. And there are logs of the many parameters we capture for later analysis (what’s changing over time? What caused that failure?). + +### Services vs. monoliths + +While DevSecOps practices can be applied across many types of application architectures, they’re most effective with small and loosely coupled components that can be updated and reused without potentially forcing changes elsewhere in the app. In their purest form, these components can be [microservices][9] or functions, but the general principles apply wherever you have loosely coupled services communicating over a network. + +This pattern does introduce some new security challenges. The interactions between components can be complex and the total attack surface can be larger because there are now more entry points to the application across the network. + +On the other hand, this type of architecture also means that automated security and monitoring also has more granular visibility into the application components because they’re no longer buried deep within a monolithic application. + +Don’t get too wrapped up in the DevSecOps term, but take it as a reminder that security is evolving because the way that we write and deploy applications is evolving. + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/9/devsecops-changes-security + +作者:[Gordon Haff][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://opensource.com/users/ghaff +[1]: https://opensource.com/resources/devops +[2]: https://opensource.com/tags/devops +[3]: https://opensource.com/article/18/5/steps-apply-devops-culture-beyond-it +[4]: https://www.devsecopsdays.com/articles/its-just-a-name +[5]: https://opensource.com/article/18/4/devsecops +[6]: https://opensource.com/article/18/6/where-cycle-security-devops +[7]: https://opensource.com/tags/ansible +[8]: https://opensource.com/article/17/1/be-open-source-supply-chain +[9]: https://opensource.com/tags/microservices diff --git a/sources/talk/20180919 How Writing Can Expand Your Skills and Grow Your Career.md b/sources/talk/20180919 How Writing Can Expand Your Skills and Grow Your Career.md new file mode 100644 index 0000000000..a862920028 --- /dev/null +++ b/sources/talk/20180919 How Writing Can Expand Your Skills and Grow Your Career.md @@ -0,0 +1,46 @@ +How Writing Can Expand Your Skills and Grow Your Career +====== + +![](https://www.linux.com/sites/lcom/files/styles/rendered_file/public/graffiti-1281310_1920.jpg?itok=RCayfGKv) + +At the recent [Open Source Summit in Vancouver][1], I participated in a panel discussion called [How Writing can Change Your Career for the Better (Even if You don't Identify as a Writer][2]. The panel was moderated by Rikki Endsley, Community Manager and Editor for Opensource.com, and it included VM (Vicky) Brasseur, Open Source Strategy Consultant; Alex Williams, Founder, Editor in Chief, The New Stack; and Dawn Foster, Consultant, The Scale Factory. + +The talk was [inspired by this article][3], in which Rikki examined some ways that writing can "spark joy" and improve your career in unexpected ways. Full disclosure: I have known Rikki for a long time. We worked at the same company for many years, raised our children together, and remain close friends. + +### Write and learn + +As Rikki noted in the talk description, “even if you don't consider yourself to be ‘a writer,’ you should consider writing about your open source contributions, project, or community.” Writing can be a great way to share knowledge and engage others in your work, but it has personal benefits as well. It can help you meet new people, learn new skills, and improve your communication style. + +I find that writing often clarifies for me what I don’t know about a particular topic. The process highlights gaps in my understanding and motivates me to fill in those gaps through further research, reading, and asking questions. + +“Writing about what you don't know can be much harder and more time consuming, but also much more fulfilling and help your career. I've found that writing about what I don't know helps me learn, because I have to research it and understand it well enough to explain it,” Rikki said. + +Writing about what you’ve just learned can be valuable to other learners as well. In her blog, [Julia Evans][4] often writes about learning new technical skills. She has a friendly, approachable style along with the ability to break down topics into bite-sized pieces. In her posts, Evans takes readers through her learning process, identifying what was and was not helpful to her along the way, essentially removing obstacles for her readers and clearing a path for those new to the topic. + +### Communicate more clearly + +Writing can help you practice thinking and speaking more precisely, especially if you’re writing (or speaking) for an international audience. [In this article,][5] for example, Isabel Drost-Fromm provides tips for removing ambiguity for non-native English speakers. Writing can also help you organize your thoughts before a presentation, whether you’re speaking at a conference or to your team. + +“The process of writing the articles helps me organize my talks and slides, and it was a great way to provide ‘notes’ for conference attendees, while sharing the topic with a larger international audience that wasn't at the event in person,” Rikki stated. + +If you’re interested in writing, I encourage you to do it. I highly recommend the articles mentioned here as a way to get started thinking about the story you have to tell. Unfortunately, our discussion at Open Source Summit was not recorded, but I hope we can do another talk in the future and share more ideas. + +Check out the schedule of talks for Open Source Summit Europe and sign up to receive updates: + +-------------------------------------------------------------------------------- + +via: https://www.linux.com/blog/2018/9/how-writing-can-help-you-learn-new-skills-and-grow-your-career + +作者:[Amber Ankerholz][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://www.linux.com/users/aankerholz +[1]: https://events.linuxfoundation.org/events/open-source-summit-north-america-2018/ +[2]: https://ossna18.sched.com/event/FAOF/panel-discussion-how-writing-can-change-your-career-for-the-better-even-if-you-dont-identify-as-a-writer-moderated-by-rikki-endsley-opensourcecom-red-hat?iframe=no# +[3]: https://opensource.com/article/18/2/career-changing-magic-writing +[4]: https://jvns.ca/ +[5]: https://www.linux.com/blog/event/open-source-summit-eu/2017/12/technical-writing-international-audience diff --git a/sources/talk/20180919 Linux Has a Code of Conduct and Not Everyone is Happy With it.md b/sources/talk/20180919 Linux Has a Code of Conduct and Not Everyone is Happy With it.md new file mode 100644 index 0000000000..e161ec4eec --- /dev/null +++ b/sources/talk/20180919 Linux Has a Code of Conduct and Not Everyone is Happy With it.md @@ -0,0 +1,167 @@ +Linux Has a Code of Conduct and Not Everyone is Happy With it +====== +**Linux kernel has a new code of conduct (CoC). Linus Torvalds took a break from Linux kernel development just 30 minutes after signing this code of conduct. And since **the writer of this code of conduct has had a controversial past,** it has now become a point of heated discussion. With all the politics involved, not many people are happy with this new CoC.** + +If you do not know already, [Linux creator Linus Torvalds has apologized for his past behavior and has taken a temporary break from Linux kernel development to improve his behavior][1]. + +### The new code of conduct for Linux kernel development + +Linux kernel developers have a code of conduct. It’s not like they didn’t have a code before, but the previous [code of conflict][2] is now replaced by this new code of conduct to “help make the kernel community a welcoming environment to participate in.” + +> “In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.” + +You can read the entire code of conduct on this commit page. + +[Linux Code of Conduct][33] + + +### Was Linus Torvalds forced to apologize and take a break? + +![Linus Torvalds Apologizes][3] + +The code of conduct was signed off by Linus Torvalds and Greg Kroah-Hartman (kind of second-in-command after Torvalds). Dan Williams of Intel and Chris Mason from Facebook were some of the other signees. + +If I have read through the timeline correctly, half an hour after signing this code of conduct, Torvalds sent a [mail apologizing for his past behavior][4]. He also announced taking a temporary break to improve upon his behavior. + +But at this point some people started reading between the lines, with a special attention to this line from his mail: + +> **This week people in our community confronted me about my lifetime of not understanding emotions**. My flippant attacks in emails have been both unprofessional and uncalled for. Especially at times when I made it personal. In my quest for a better patch, this made sense to me. I know now this was not OK and I am truly sorry. + +This particular line could be read as if he was coerced into apologizing and taking a break because of the new code of conduct. Though it could also be a precautionary measure to prevent Torvalds from violating the newly created code of conduct. + +### The controversy around Contributor Convent creator Coraline Ada Ehmke + +The Linux code of conduct is based on the [Contributor Covenant, version 1.4][5]. Contributor Convent has been adopted by hundreds of open source projects. Eclipse, Angular, Ruby, Kubernetes are some of the [many adopters of Contributor Convent][6]. + +Contributor Covenant has been created by [Coraline Ada Ehmke][7], a software developer, an open-source advocate, and an [LGBT][8] activist. She has been instrumental in promoting diversity in the open source world. + +Coraline has also been vocal about her stance against [meritocracy][9]. The Latin word meritocracy originally refers to a “system under which advancement within the system turns on “merits”, like intelligence, credentials, and education.” But activists like [Coraline believe][10] that meritocracy is a negative system where the worth of an individual is measured not by their humanity, but solely by their intellectual output. + +[![croraline meritocracy][11]][12] +Image credit: Twitter user @nickmon1112 + +Remember that [Linus Torvalds has repeatedly said that he cares about the code, not the person who writes it][13]. Clearly, this goes against Coraline’s view on meritocracy. + +Coraline has had a troubled incident in the past with a contributor of [Opal project][14]. There was a [discussion taking place on Twitter][15] where Elia, a core contributor to Opal project from Italy, said “(trans people) not accepting reality is the problem here”. + +Coraline was neither in the discussion nor was she a contributor to the Opal project. But as an LGBT activist, she took it to herself and [demanded that Elia be removed from the Opal Project][16] for his ‘views against trans people’. A lengthy and heated discussion took place on Opal’s GitHub repository. Coraline and her supporters, who never contributed to Opal, tried to coerce the moderators into removing Elia, a core contributor of the project. + +While Elia wasn’t removed from the project, Opal project maintainers agreed to put up a code of conduct in place. And this code of conduct was nothing else but Coraline’s famed Contributor Covenant that she had pitched to the maintainers herself. + +But the story didn’t end here. The Contributor Covenant was then modified and a [new clause added in order to get to Elia][17]. The new clause widened the scope of conduct in public spaces. This malicious change was [spotted by the maintainers][18] and they edited the clause. Opal eventually got rid of the Contributor Covenant and put in place its own guideline. + +This is a classic example of how a few offended people, who never contributed a single line of code to the project, tried to oust its core contributor. + +### People’s reaction on Linux Code of Conduct and Torvalds’ apology + +As soon as Linux code of conduct and Torvalds’ apology went public, Social Media and forums were rife with rumors and [speculations][19]. While many people appreciated this new development, there were some who saw a conspiracy by [SJW infiltrating Linux][20]. + +A sarcastic tweet by Caroline only fueled the fire. + +> I can’t wait for the mass exodus from Linux now that it’s been infiltrated by SJWs. Hahahah [pic.twitter.com/eFeY6r4ENv][21] +> +> — Coraline Ada Ehmke (@CoralineAda) [September 16, 2018][22] + +In the wake of the Linux CoC controversy, Coraline openly said that the Contributor Convent code of conduct is a political document. This did not go down well with the people who want the political stuff out of the open source projects. + +> Some people are saying that the Contributor Covenant is a political document, and they’re right. +> +> — Coraline Ada Ehmke (@CoralineAda) [September 16, 2018][23] + +Nick Monroe, a freelance journalist, dig up the past of Coraline in order to validate his claim that there is more to Linux CoC than meets the eye. You can go by the entire thread if you want. + +> Alright. You've seen this a million times before. It's a code of conduct blah blah blah +> +> that has social justice baked right into it. blah blah blah. +> +> But something is different about this. [pic.twitter.com/8NUL2K1gu2][24] +> +> — Nick Monroe (@nickmon1112) [September 17, 2018][25] + +Nick wasn’t the only one to disapprove of the new Linux CoC. The [SJW][26] involvement led to more skepticism. + +> I guess the big news in Linux today is that the Linux kernel is now governed by a Code of Conduct and a “post meritocracy” world view. +> +> In principle these CoCs look great. In practice they are abused tools to hunt people SJWs don’t like. And they don’t like a lot of people. +> +> — Mark Kern (@Grummz) [September 17, 2018][27] + +While there were many who appreciated Torvalds’ apology, there were a few who blamed Torvalds’ attitude: + +> Am I the only one who thinks Linus Torvalds attitude for decades was a prime contributors to how many of the condescending, rudes, jerks in Linux and open source "communities" behaved? I've never once felt welcomed into the Linux community as a new user. +> +> — Jonathan Frappier (@jfrappier) [September 17, 2018][28] + +And some were simply not amused with his apology: + +> Oh look, an abusive OSS maintainer finally admitted, after *decades* of abusive and toxic behavior, that his behavior *might* be an issue. +> +> And a bunch of people I follow are tripping all over themselves to give him cookies for that. 🙄🙄🙄 +> +> — Kelly Ellis (@justkelly_ok) [September 17, 2018][29] + +The entire Torvalds apology episode has raised a genuine concern ;) + +> Do we have to put "I don't/do forgive Linus Torvalds" in our bio now? +> +> — Verónica. (@maria_fibonacci) [September 17, 2018][30] + +Jokes apart, the genuine concern was raised by Sharp, who had [quit Linux Kernel development][31] in 2015 due to the ‘toxic community’. + +> The real test here is whether the community that built Linus up and protected his right to be verbally abusive will change. Linus not only needs to change himself, but the Linux kernel community needs to change as well. +> +> — Sage Sharp (@_sagesharp_) [September 17, 2018][32] + +### What do you think of Linux Code of Conduct? + +If you ask my opinion, I do think that a Code of Conduct is the need of the time. It guides people in behaving in a respectable way and helps create a positive environment for all kind of people irrespective of their race, ethnicity, religion, nationality and political views (both left and right). + +What are your views on the entire episode? Do you think the CoC will help Linux kernel development? Or will it deteriorate with the involvement of anti-meritocracy SJWs? + +We don’t have a code of conduct at It’s FOSS but let’s keep the discussion civil :) + +-------------------------------------------------------------------------------- + +via: https://itsfoss.com/linux-code-of-conduct/ + +作者:[Abhishek Prakash][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://itsfoss.com/author/abhishek/ +[1]: https://itsfoss.com/torvalds-takes-a-break-from-linux/ +[2]: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/CodeOfConflict?id=ddbd2b7ad99a418c60397901a0f3c997d030c65e +[3]: https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/09/linus-torvalds-apologizes.jpeg +[4]: https://lkml.org/lkml/2018/9/16/167 +[5]: https://www.contributor-covenant.org/version/1/4/code-of-conduct.html +[6]: https://www.contributor-covenant.org/adopters +[7]: https://en.wikipedia.org/wiki/Coraline_Ada_Ehmke +[8]: https://en.wikipedia.org/wiki/LGBT +[9]: https://en.wikipedia.org/wiki/Meritocracy +[10]: https://modelviewculture.com/pieces/the-dehumanizing-myth-of-the-meritocracy +[11]: https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/09/croraline-meritocracy.jpg +[12]: https://pbs.twimg.com/media/DnTTfi7XoAAdk08.jpg +[13]: https://arstechnica.com/information-technology/2015/01/linus-torvalds-on-why-he-isnt-nice-i-dont-care-about-you/ +[14]: https://opalrb.com/ +[15]: https://twitter.com/krainboltgreene/status/611569515315507200 +[16]: https://github.com/opal/opal/issues/941 +[17]: https://github.com/opal/opal/pull/948/commits/817321e27eccfffb3841f663815c17eecb8ef061#diff-a1ee87dafebc22cbd96979f1b2b7e837R11 +[18]: https://github.com/opal/opal/pull/948#issuecomment-113486020 +[19]: https://www.reddit.com/r/linux/comments/9go8cp/linus_torvalds_daughter_has_signed_the/ +[20]: https://snew.github.io/r/linux/comments/9ghrrj/linuxs_new_coc_is_a_piece_of_shit/ +[21]: https://t.co/eFeY6r4ENv +[22]: https://twitter.com/CoralineAda/status/1041441155874009093?ref_src=twsrc%5Etfw +[23]: https://twitter.com/CoralineAda/status/1041465346656530432?ref_src=twsrc%5Etfw +[24]: https://t.co/8NUL2K1gu2 +[25]: https://twitter.com/nickmon1112/status/1041668315947708416?ref_src=twsrc%5Etfw +[26]: https://www.urbandictionary.com/define.php?term=SJW +[27]: https://twitter.com/Grummz/status/1041524170331287552?ref_src=twsrc%5Etfw +[28]: https://twitter.com/jfrappier/status/1041486055038492674?ref_src=twsrc%5Etfw +[29]: https://twitter.com/justkelly_ok/status/1041522269002985473?ref_src=twsrc%5Etfw +[30]: https://twitter.com/maria_fibonacci/status/1041538148121997313?ref_src=twsrc%5Etfw +[31]: https://www.networkworld.com/article/2988850/opensource-subnet/linux-kernel-dev-sarah-sharp-quits-citing-brutal-communications-style.html +[32]: https://twitter.com/_sagesharp_/status/1041480963287539712?ref_src=twsrc%5Etfw +[33]: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=8a104f8b5867c682d994ffa7a74093c54469c11f diff --git a/sources/talk/20180920 Building a Secure Ecosystem for Node.js.md b/sources/talk/20180920 Building a Secure Ecosystem for Node.js.md new file mode 100644 index 0000000000..a64f0e32cc --- /dev/null +++ b/sources/talk/20180920 Building a Secure Ecosystem for Node.js.md @@ -0,0 +1,51 @@ +Building a Secure Ecosystem for Node.js +====== + +![](https://www.linux.com/sites/lcom/files/styles/rendered_file/public/node-collective.jpg?itok=0e7Y9Iy3) + +At[Node+JS Interactive][1], attendees collaborate face to face, network, and learn how to improve their skills with JS in serverless, IoT, and more. [Stephanie Evans][2], Content Manager for Back-end Web Development at LinkedIn Learning, will be speaking at the upcoming conference about building a secure ecosystem for Node.js. Here she answers a few questions about teaching and learning basic security practices. + +**Linux.com: Your background is in tech education, can you provide more details on how you would define this and how you got into this area of expertise?** + +**Stephanie Evans:** It sounds cliché, but I’ve always been passionate about education and helping others. After college, I started out as an instructor of a thoroughly analog skill: reading. I worked my way up to hiring and training reading teachers and discovered my passion for helping people share their knowledge and refine their teaching craft. Later, I went to work for McGraw Hill Education, publishing self-study certification books on popular IT certs like CompTIA’s Network+ and Security+, ISAAP’s CISSP, etc. My job was to figure out who the biggest audiences in IT were; what they needed to know to succeed professionally; hire the right book author; and help develop the manuscript with them. + +I moved into online learning/e-learning 4 years ago and shifted to video training courses geared towards developers. I enjoy working with people who spend their time building and solving complex problems. I now manage the video training library for back-end web developers at LinkedIn Learning/Lynda.com and figure out what developers need to know; hire instructors to create that content; and work together to figure out how best to teach it to them. And, then update those courses when they inevitably become out of date. + +**Linux.com: What initially drove you to use your skill set in education to help with security practices?** + +**Evans:** I attend a lot of conferences, watch a lot of talks, and chat to a lot of developers as part of my job. I distinctly remember attending a security best practices talk at a very large, enterprise-tech focused conference and was surprised by the rudimentary content being covered. Poor guy, I’d thought…he’s going to get panned by this audience. But then I looked around and most everyone was engaged. They were learning something new and compelling. And it hit me: I had been in a security echo chamber of my own making. Just like the mainstream developer isn’t working with the cutting-edge technology people are raving about on Twitter, they aren’t necessarily as fluent in basic security practices as I’d assumed. A mix of unawareness, intense time pressure, and perhaps some misplaced trust can lead to a “security later” mentality. But with the global cost of cybercrime up to 6 00 billion a year from 500 billion in 2014 as well as the [exploding amount of data on the web][3]. We can’t afford to be working around security or assuming everyone knows the basics. + +**Linux.com: What do you think are some common misconceptions about security with Node.js and in general with developers?** + +**Evans:** I think one of the biggest misconceptions is that security awareness and practices should come “later” in a developer’s career (and later in the development cycle). Yes, your first priority is to learn that Java and JavaScript are not the same thing—that’s obviously most important. And you do have to understand how to create a form before you can understand how to prevent cross-site -scripting attacks. But helping developers understand—at all stages of their career and learning journey—what the potential vulnerabilities are and how they can be exploited needs to be a much higher priority and come earlier than we may intuitively think. + +I joke with my instructors that we have to sneak in the ‘eat your vegetables’ content to our courses. Security is an exciting, complex and challenging topic, but it can feel like you’re having to eat your vegetables as a developer when you dig into it. Often ‘security’ is a separate department (that can be perceived as ‘slowing things down’ or getting in the way of deploying code) and it can further distance developers from their role in securing their applications. + +I also think that those who truly understand security can feel that it’s overwhelmingly complex to teach—but we have to start somewhere. I attended an introductory npm talk last year that talked about how to work with dependencies and packages…but never once mentioned the possibility of malicious code making it into your application through these packages. I’m all about teaching just enough at the right time and not throwing the kitchen sink of knowledge at new developers. We should stop thinking of security—or even just security awareness—as an intermediate or advanced skill and start bringing it up early and often. + +**Linux.com: How can we infuse tech education into our security practices? Where does this begin?** + +**Evans:** It definitely goes both ways. Clear documentation and practical resources right alongside security recommendations go a long way towards ensuring understanding and adoption. You have to make things as easy as possible if you want people to actually do it. And you have to make those best practices accessible enough to understand. + +The [2018 Node User Survey Report][4] from the Node.js Foundation showed that while learning resources around Node.js and JavaScript development improved, the availability and quality of learning resources for Node.js Security received the lowest scores across the board. + +After documentation and Stack Overflow, many developers rely on online videos and tutorials—we need to push security education to the forefront, rather than expecting developers to seek it out. OWASP, the nodegoat project, and the Node.js Security Working Group are doing great work here to move the needle. I think tech education can do even more to bring security in earlier in the learning journey and create awareness about common exploits and important resources. + +Learn more at [Node+JS Interactive][1], coming up October 10-12, 2018 in Vancouver, Canada. + +-------------------------------------------------------------------------------- + +via: https://www.linux.com/blog/node-js/2018/9/building-secure-ecosystem-nodejs + +作者:[The Linux Foundation][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://www.linux.com/users/ericstephenbrown +[1]: https://events.linuxfoundation.org/events/node-js-interactive-2018/?utm_source=Linux.com&utm_medium=article&utm_campaign=jsint18 +[2]: https://jsi2018.sched.com/speaker/stevans1?iframe=no +[3]: https://www.forbes.com/sites/bernardmarr/2018/05/21/how-much-data-do-we-create-every-day-the-mind-blowing-stats-everyone-should-read/#101d261a60ba +[4]: https://nodejs.org/en/user-survey-report/ diff --git a/sources/talk/20180920 WinWorld - A Large Collection Of Defunct OSs, Software And Games.md b/sources/talk/20180920 WinWorld - A Large Collection Of Defunct OSs, Software And Games.md new file mode 100644 index 0000000000..93c84ae43c --- /dev/null +++ b/sources/talk/20180920 WinWorld - A Large Collection Of Defunct OSs, Software And Games.md @@ -0,0 +1,126 @@ +WinWorld – A Large Collection Of Defunct OSs, Software And Games +====== + +![](https://www.ostechnix.com/wp-content/uploads/2018/09/WinWorld-720x340.jpeg) + +The other day, I was testing **Dosbox** which is used to [**run MS-DOS games and programs in Linux**][1]. While searching for some classic programs like Turbo C++, I stumbled upon a website named **WinWorld**. I went through a few links in this site and quite surprised. WinWorld has a plenty of good-old and classic OSs, software, applications, development tools, games and a lot of other miscellaneous utilities which are abandoned by the developers a long time ago. It is an online museum run by community members, volunteers and is dedicated to the preservation and sharing of vintage, abandoned, and pre-release software. + +WinWorld was started back in 2003 and its founder claims that the idea to start this site inspired by Yahoo briefcases. The primary purpose of this site is to preserve and share old software. Over the years, many people volunteered to improve this site in numerous ways and the collection of old software in WinWorld has grown exponentially. The entire WinWorld library is free, open and available to everyone. + +### WinWorld Hosts A Huge Collection Of Defunct OSs, Software, System Applications And Games + +Like I already said, WinWorld hosts a huge collection of abandonware which are no-longer in development. + +**Linux and Unix:** + +Here, I have given the complete list of UNIX and LINUX OSs with brief summary of the each OS and the release year of first version. + + * **A/UX** – An early port of Unix to Apple’s 68k based Macintosh platform, released in 1988. + * **AIX** – A Unix port originally developed by IBM, released in 1986. + * **AT &T System V Unix** – One of the first commercial versions of the Unix OS, released in 1983. + * **Banyan VINES** – A network operating system originally designed for Unix, released in 1984. + * **Corel Linux** – A commercial Linux distro, released in 1999. + * **DEC OSF-1** – A version of UNIX developed by Digital Equipment Corporation (DEC), released in 1991. + * **Digital UNIX** – A renamed version of **OSF-1** , released by DEC in 1995.** +** + * **FreeBSD** **1.0** – The first release of FreeBSD, released in 1993. It is based on 4.3BSD. + * **Gentus Linux** – A distribution that failed to comply with GPL. Developed by ABIT and released in 2000. + * **HP-UX** – A UNIX variant, released in 1992. + * **IRIX** – An a operating system developed by Silicon Graphics Inc (SGI ) and it is released in 1988. + * **Lindows** – Similar to Corel Linux. It is developed for commercial purpose and released in 2002. + * **Linux Kernel** – A copy of the Linux Sourcecode, version 0.01. Released in the early 90’s. + * **Mandrake Linux** – A Linux distribution based on Red Hat Linux. It was later renamed to Mandriva. Released in 1999. + * **NEWS-OS** – A variant of BSD, developed by Sony and released in 1989. + * **NeXTStep** – A Unix based OS from NeXT computers headed by **Steve Jobs**. It is released in 1987. + * **PC/IX** – A UNIX variant created for IBM PCs. Released in 1984. + * **Red Hat Linux 5.0** – A commercial Linux distribution by Red Hat. + * **Sun Solaris** – A Unix based OS by Sun Microsystems. Released in 1992. + * **SunOS** – A Unix-based OS derived from BSD by Sun Microsystems, released in 1982. + * **Tru64 UNIX** – A formerly known OSF/1 by DEC. + * **Ubuntu 4.10** – The well-known OS based on Debian.This was a beta pre-release, prior to the very first official Ubuntu release. + * **Ultrix** – A UNIX clone developed by DEC. + * **UnixWare** – A UNIX variant from Novell. + * **Xandros Linux** – A proprietary variant of Linux. It is based on Corel Linux. The first version is released in 2003. + * **Xenix** – A UNIX variant originally published by Microsoft released in 1984. + + + +Not just Linux/Unix, you can find other operating systems including DOS, Windows, Apple/Mac, OS 2, Novell netware and other OSs and shells. + +**DOS & CP/M:** + + * 86-DOS + * Concurrent CPM-86 & Concurrent DOS + * CP/M 86 & CP/M-80 + * DOS Plus + * DR-DOS + * GEM + * MP/M + * MS-DOS + * Multitasking MS-DOS 4.00 + * Multiuser DOS + * PC-DOS + * PC-MOS + * PTS-DOS + * Real/32 + * Tandy Deskmate + * Wendin DOS + + + +**Windows:** + + * BackOffice Server + * Windows 1.0/2.x/3.0/3.1/95/98/2000/ME/NT 3.X/NT 4.0 + * Windows Whistler + * WinFrame + + + +**Apple/Mac:** + + * Mac OS 7/8/9 + * Mac OS X + * System Software (0-6) + + + +**OS/2:** + + * Citrix Multiuser + * OS/2 1.x + * OS/2 2.0 + * OS/2 3.x + * OS/2 Warp 4 + + + +Also, WinWorld hosts a huge collection of old software, system applications, development tools and games. Go and check them out as well. + +To be honest, I don’t even know the existence of most of the stuffs listed in this site. Some of the tools listed here were released years before I was born. + +Just in case, If you ever in need of or wanted to test a classic stuff (be it a game, software, OS), look nowhere, just head over to WinWorld library and download them that you want to explore. Good luck! + +**Disclaimer:** + +OSTechNix is not affiliated with WinWorld site in any way. We, at OSTechNix, don’t know the authenticity and integrity of the stuffs hosted in this site. Also, downloading software from third-party sites is not safe or may be illegal in your region. Neither the author nor OSTechNix is responsible for any kind of damage. Use this service at your own risk. + +And, that’s all for now. Hope this was useful. More good stuffs to come. Stay tuned! + +Cheers! + + + +-------------------------------------------------------------------------------- + +via: https://www.ostechnix.com/winworld-a-large-collection-of-defunct-oss-software-and-games/ + +作者:[SK][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://www.ostechnix.com/author/sk/ +[1]: https://www.ostechnix.com/how-to-run-ms-dos-games-and-programs-in-linux/ diff --git a/sources/talk/20180926 CPU Power Manager - Control And Manage CPU Frequency In Linux.md b/sources/talk/20180926 CPU Power Manager - Control And Manage CPU Frequency In Linux.md new file mode 100644 index 0000000000..aeffd1f144 --- /dev/null +++ b/sources/talk/20180926 CPU Power Manager - Control And Manage CPU Frequency In Linux.md @@ -0,0 +1,74 @@ +CPU Power Manager – Control And Manage CPU Frequency In Linux +====== + +![](https://www.ostechnix.com/wp-content/uploads/2018/09/Manage-CPU-Frequency-720x340.jpeg) + +If you are a laptop user, you probably know that power management on Linux isn’t really as good as on other OSes. While there are tools like **TLP** , [**Laptop Mode Tools** and **powertop**][1] to help reduce power consumption, overall battery life on Linux isn’t as good as Windows or Mac OS. Another way to reduce power consumption is to limit the frequency of your CPU. While this is something that has always been doable, it generally requires complicated terminal commands, making it inconvenient. But fortunately, there’s a gnome extension that helps you easily set and manage your CPU’s frequency – **CPU Power Manager**. CPU Power Manager uses the **intel_pstate** frequency scaling driver (supported by almost every Intel CPU) to control and manage CPU frequency in your GNOME desktop. + +Another reason to use this extension is to reduce heating in your system. There are many systems out there which can get uncomfortably hot in normal usage. Limiting your CPU’s frequency could reduce heating. It will also decrease the wear and tear on your CPU and other components. + +### Installing CPU Power Manager + +First, go to the [**extension’s page**][2], and install the extension. + +Once the extension has installed, you’ll get a CPU icon at the right side of the Gnome top bar. Click the icon, and you get an option to install the extension: + +![](https://www.ostechnix.com/wp-content/uploads/2018/09/CPU-Power-Manager-icon.png) + +If you click **“Attempt Installation”** , you’ll get a password prompt. The extension needs root privileges to add policykit rule for controlling CPU frequency. This is what the prompt looks like: + +![](https://www.ostechnix.com/wp-content/uploads/2018/09/CPU-Power-Manager-1.png) + +Type in your password and Click **“Authenticate”** , and that finishes installation. The last action adds a policykit file – **mko.cpupower.setcpufreq.policy** at **/usr/share/polkit-1/actions**. + +After installation is complete, if you click the CPU icon at the top right, you’ll get something like this: + +![](https://www.ostechnix.com/wp-content/uploads/2018/09/CPU-Power-Manager.png) + +### Features + + * **See the current CPU frequency:** Obviously, you can use this window to see the frequency that your CPU is running at. + * **Set maximum and minimum frequency:** With this extension, you can set maximum and minimum frequency limits in terms of percentage of max frequency. Once these limits are set, the CPU will operate only in this range of frequencies. + * **Turn Turbo Boost On and Off:** This is my favorite feature. Most Intel CPU’s have “Turbo Boost” feature, whereby the one of the cores of the CPU is boosted past the normal maximum frequency for extra performance. While this can make your system more performant, it also increases power consumption a lot. So if you aren’t doing anything intensive, it’s nice to be able to turn off Turbo Boost and save power. In fact, in my case, I have Turbo Boost turned off most of the time. + * **Make Profiles:** You can make profiles with max and min frequency that you can turn on/off easily instead of fiddling with max and frequencies. + + + +### Preferences + +You can also customize the extension via the preferences window: + +![](https://www.ostechnix.com/wp-content/uploads/2018/09/CPU-Power-Manager-preferences.png) + +As you can see, you can set whether CPU frequency is to be displayed, and whether to display it in **Mhz** or **Ghz**. + +You can also edit and create/delete profiles: + +![](https://www.ostechnix.com/wp-content/uploads/2018/09/CPU-Power-Manager-preferences-1.png) + +You can set maximum and minimum frequencies, and turbo boost for each profile. + +### Conclusion + +As I said in the beginning, power management on Linux is not the best, and many people are always looking to eek out a few minutes more out of their Linux laptop. If you are one of those, check out this extension. This is a unconventional method to save power, but it does work. I certainly love this extension, and have been using it for a few months now. + +What do you think about this extension? Put your thoughts in the comments below! + +Cheers! + + + +-------------------------------------------------------------------------------- + +via: https://www.ostechnix.com/cpu-power-manager-control-and-manage-cpu-frequency-in-linux/ + +作者:[EDITOR][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://www.ostechnix.com/author/editor/ +[1]: https://www.ostechnix.com/improve-laptop-battery-performance-linux/ +[2]: https://extensions.gnome.org/extension/945/cpu-power-manager/ diff --git a/sources/tech/20111221 30 Best Sources For Linux - -BSD - Unix Documentation On the Web.md b/sources/tech/20111221 30 Best Sources For Linux - -BSD - Unix Documentation On the Web.md index ac35f7c596..81e3acacdb 100644 --- a/sources/tech/20111221 30 Best Sources For Linux - -BSD - Unix Documentation On the Web.md +++ b/sources/tech/20111221 30 Best Sources For Linux - -BSD - Unix Documentation On the Web.md @@ -1,5 +1,12 @@ -30 Best Sources For Linux / *BSD / Unix Documentation On the Web +# sober-wang 翻译中 + + + +30 Best Sources For Linux / *BSD / Unix Documentation On the We ====== + + + Man pages are written by sys-admin and developers for IT techs, and are intended more as a reference than as a how to. Man pages are very useful for people who are already familiar with Linux, Unix, and BSD operating systems. Use man pages when you just need to know the syntax for particular commands or configuration file, but they are not helpful for new Linux users. Man pages are not good for learning something new for the first time. Here are thirty best documentation sites on the web for learning Linux and Unix like operating systems. ![Dennis Ritchie and Ken Thompson working with UNIX PDP11][1] @@ -12,8 +19,8 @@ Please note that BSD manpages are usually better as compare to Linux. RHEL is developed by Red Hat and targeted toward the commercial market. It has one of the best documentations covering basis of RHEL to advanced topics like security, SELinux, virtualization, directory server, clustering, JBOSS, HPC, and much more. Red Hat documentation has been translated into twenty-two languages and is available in multi-page HTML, single-page HTML, PDF, and EPUB formats. The good news is you can use the same documentation for CentOS or Scientific Linux (community enterprise distros). All of these documents ship with the OS, so if you don't have a network connection, then you have them there as well. The RHEL docs **covers everything from installation to configuring clusters**. The only downside is you need to be a paid customer. This is perfect for an enterprise company. - 1. RHEL Documentation: [in HTML/PDF format][3] - 2. Support forums: Only available to Red Hat customer portal to submit a support case. + 1. RHEL Documentation: [in HTML/PDF format][3] + 2. Support forums: Only available to Red Hat customer portal to submit a support case. @@ -366,87 +373,87 @@ via: https://www.cyberciti.biz/tips/linux-unix-bsd-documentations.html 本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 [a]:https://www.cyberciti.biz -[1]:https://www.cyberciti.biz/media/new/tips/2011/12/unix-pdp11.jpg (Dennis Ritchie and Ken Thompson working with UNIX PDP11) -[2]:https://www.cyberciti.biz/media/new/tips/2011/12/redhat-enterprise-linux-docs-150x150.png (Red hat Enterprise Linux Docs) +[1]:https://www.cyberciti.biz/media/new/tips/2011/12/unix-pdp11.jpg "Dennis Ritchie and Ken Thompson working with UNIX PDP11" +[2]:https://www.cyberciti.biz/media/new/tips/2011/12/redhat-enterprise-linux-docs-150x150.png "Red hat Enterprise Linux Docs" [3]:https://access.redhat.com/documentation/en-us/ -[4]:https://www.cyberciti.biz/media/new/tips/2011/12/centos-linux-wiki-150x150.png (Centos Linux Wiki, Support, Documents) -[5]:https://www.cyberciti.biz/media/new/tips/2011/12/arch-linux-wiki-150x150.png (Arch Linux wiki and tutorials ) +[4]:https://www.cyberciti.biz/media/new/tips/2011/12/centos-linux-wiki-150x150.png "Centos Linux Wiki, Support, Documents" +[5]:https://www.cyberciti.biz/media/new/tips/2011/12/arch-linux-wiki-150x150.png "Arch Linux wiki and tutorials " [6]:https://wiki.archlinux.org/index.php/Category:Networking_%28English%29 [7]:https://bbs.archlinux.org/ [8]:https://wiki.archlinux.org/ -[9]:https://www.cyberciti.biz/media/new/tips/2011/12/gentoo-linux-wiki1-150x150.png (Gentoo Linux Handbook and Wiki) +[9]:https://www.cyberciti.biz/media/new/tips/2011/12/gentoo-linux-wiki1-150x150.png "Gentoo Linux Handbook and Wiki" [10]:http://www.gentoo.org/doc/en/handbook/ [11]:https://wiki.gentoo.org [12]:https://forums.gentoo.org/ [13]:http://gentoo-wiki.com -[14]:https://www.cyberciti.biz/media/new/tips/2011/12/ubuntu-linux-wiki.png (Ubuntu Linux Wiki and Forums) +[14]:https://www.cyberciti.biz/media/new/tips/2011/12/ubuntu-linux-wiki.png "Ubuntu Linux Wiki and Forums" [15]:https://help.ubuntu.com/community [16]:https://help.ubuntu.com/ [17]:https://ubuntuforums.org/ -[18]:https://www.cyberciti.biz/media/new/tips/2011/12/ibm-devel.png (IBM: Technical for Linux programmers and system administrators) +[18]:https://www.cyberciti.biz/media/new/tips/2011/12/ibm-devel.png "IBM: Technical for Linux programmers and system administrators" [19]:https://www.ibm.com/developerworks/learn/linux/index.html [20]:https://www.ibm.com/developerworks/community/forums/html/public?lang=en -[21]:https://www.cyberciti.biz/media/new/tips/2011/12/freebsd-docs.png (Freebsd Documentation) -[22]:https://www.cyberciti.biz/media/new/tips/2011/12/bash-hackers-wiki-150x150.png (Bash hackers wiki for bash users) +[21]:https://www.cyberciti.biz/media/new/tips/2011/12/freebsd-docs.png "Freebsd Documentation" +[22]:https://www.cyberciti.biz/media/new/tips/2011/12/bash-hackers-wiki-150x150.png "Bash hackers wiki for bash users" [23]:http://wiki.bash-hackers.org/doku.php -[24]:https://www.cyberciti.biz/media/new/tips/2011/12/bash-faq-150x150.png (Bash FAQ: Answers to frequently asked questions about GNU/BASH) +[24]:https://www.cyberciti.biz/media/new/tips/2011/12/bash-faq-150x150.png "Bash FAQ: Answers to frequently asked questions about GNU/BASH" [25]:http://mywiki.wooledge.org/BashPitfalls [26]:https://mywiki.wooledge.org/BashFAQ -[27]:https://www.cyberciti.biz/media/new/tips/2011/12/howtoforge-150x150.png (Howtoforge tutorials) +[27]:https://www.cyberciti.biz/media/new/tips/2011/12/howtoforge-150x150.png "Howtoforge tutorials" [28]:https://howtoforge.com/ -[29]:https://www.cyberciti.biz/media/new/tips/2011/12/openbsd-faq-150x150.png (OpenBSD Documenation) +[29]:https://www.cyberciti.biz/media/new/tips/2011/12/openbsd-faq-150x150.png "OpenBSD Documenation" [30]:https://www.openbsd.org/faq/index.html [31]:https://www.openbsd.org/mail.html -[32]:https://www.cyberciti.biz/media/new/tips/2011/12/calomel_org.png (Open Source Research and Reference Documentation) +[32]:https://www.cyberciti.biz/media/new/tips/2011/12/calomel_org.png "Open Source Research and Reference Documentation" [33]:https://calomel.org -[34]:https://www.cyberciti.biz/media/new/tips/2011/12/slackware-linux-book-150x150.png (Slackware Linux Book and Documentation ) +[34]:https://www.cyberciti.biz/media/new/tips/2011/12/slackware-linux-book-150x150.png "Slackware Linux Book and Documentation " [35]:http://www.slackbook.org/ -[36]:https://www.cyberciti.biz/media/new/tips/2011/12/tldp-150x150.png (Linux Learning Site and Documentation ) +[36]:https://www.cyberciti.biz/media/new/tips/2011/12/tldp-150x150.png "Linux Learning Site and Documentation " [37]:http://tldp.org/LDP/abs/html/index.html [38]:http://tldp.org/HOWTO/HOWTO-INDEX/howtos.html [39]:http://tldp.org/ -[40]:https://www.cyberciti.biz/media/new/tips/2011/12/linuxhomenetworking-150x150.png (Linux Home Networking ) +[40]:https://www.cyberciti.biz/media/new/tips/2011/12/linuxhomenetworking-150x150.png "Linux Home Networking " [41]:http://www.linuxhomenetworking.com/ -[42]:https://www.cyberciti.biz/media/new/tips/2011/12/linux-action-show-150x150.png (Linux Podcast ) +[42]:https://www.cyberciti.biz/media/new/tips/2011/12/linux-action-show-150x150.png "Linux Podcast " [43]:http://www.jupiterbroadcasting.com/show/linuxactionshow/ [44]:https://www.commandlinefu.com/commands/browse/sort-by-votes -[45]:https://www.cyberciti.biz/media/new/tips/2011/12/commandlinefu.png (The best Unix / Linux Commands ) +[45]:https://www.cyberciti.biz/media/new/tips/2011/12/commandlinefu.png "The best Unix / Linux Commands " [46]:https://commandlinefu.com/ [47]:https://www.debian-administration.org/hof -[48]:https://www.cyberciti.biz/media/new/tips/2011/12/debian-admin.png (Debian Linux Adminstration: Tips and Tutorial For Sys Admin) +[48]:https://www.cyberciti.biz/media/new/tips/2011/12/debian-admin.png "Debian Linux Adminstration: Tips and Tutorial For Sys Admin" [49]:https://www.debian-administration.org/ -[50]:https://www.cyberciti.biz/media/new/tips/2011/12/catonmat-150x150.png (Sed, Awk, Perl Tutorials) +[50]:https://www.cyberciti.biz/media/new/tips/2011/12/catonmat-150x150.png "Sed, Awk, Perl Tutorials" [51]:http://www.catonmat.net/blog/worlds-best-introduction-to-sed/ [52]:https://www.catonmat.net/blog/sed-one-liners-explained-part-one/ [53]:https://www.catonmat.net/blog/the-definitive-guide-to-bash-command-line-history/ [54]:https://www.catonmat.net/blog/awk-one-liners-explained-part-one/ [55]:https://catonmat.net/ -[56]:https://www.cyberciti.biz/media/new/tips/2011/12/debian-wiki-150x150.png (Debian Linux Tutorials and Wiki) +[56]:https://www.cyberciti.biz/media/new/tips/2011/12/debian-wiki-150x150.png "Debian Linux Tutorials and Wiki" [57]:https://www.debian.org/doc/ [58]:https://wiki.debian.org/ [59]:https://www.debian.org/support [60]:http://swift.siphos.be/linux_sea/ -[61]:https://www.cyberciti.biz/media/new/tips/2011/12/orelly-150x150.png (Oreilly Free Linux / Unix / Php / Javascript / Ubuntu Books) +[61]:https://www.cyberciti.biz/media/new/tips/2011/12/orelly-150x150.png "Oreilly Free Linux / Unix / Php / Javascript / Ubuntu Books" [62]:http://commons.oreilly.com/wiki/index.php/O%27Reilly_Commons -[63]:https://www.cyberciti.biz/media/new/tips/2011/12/ubuntu-guide-150x150.png (Ubuntu Book For New Users) +[63]:https://www.cyberciti.biz/media/new/tips/2011/12/ubuntu-guide-150x150.png "Ubuntu Book For New Users" [64]:http://ubuntupocketguide.com/ -[65]:https://www.cyberciti.biz/media/new/tips/2011/12/rute-150x150.png (GNU/LINUX system administration free book) +[65]:https://www.cyberciti.biz/media/new/tips/2011/12/rute-150x150.png "GNU/LINUX system administration free book" [66]:https://web.archive.org/web/20160204213406/http://rute.2038bug.com/rute.html.gz -[67]:https://www.cyberciti.biz/media/new/tips/2011/12/advanced-linux-programming-150x150.png (Download Advanced Linux Programming PDF version) +[67]:https://www.cyberciti.biz/media/new/tips/2011/12/advanced-linux-programming-150x150.png "Download Advanced Linux Programming PDF version" [68]:https://github.com/MentorEmbedded/advancedlinuxprogramming -[69]:https://www.cyberciti.biz/media/new/tips/2011/12/lpic-150x150.png (Download Linux Professional Institute Certification PDF Book) +[69]:https://www.cyberciti.biz/media/new/tips/2011/12/lpic-150x150.png "Download Linux Professional Institute Certification PDF Book" [70]:http://academy.delmar.edu/Courses/ITSC1358/eBooks/LPI-101.LinuxTrainingCourseNotes.pdf [71]://www.cyberciti.biz/faq/top5-linux-video-editing-system-software/ -[72]:https://www.cyberciti.biz/media/new/tips/2011/12/floss-manuals.png (Download manuals about free and open source software) +[72]:https://www.cyberciti.biz/media/new/tips/2011/12/floss-manuals.png "Download manuals about free and open source software" [73]:https://flossmanuals.net/ -[74]:https://www.cyberciti.biz/media/new/tips/2011/12/linux-starter-150x150.png (New to Linux? Start Linux starter book [ PDF version ]) +[74]:https://www.cyberciti.biz/media/new/tips/2011/12/linux-starter-150x150.png "New to Linux? Start Linux starter book [ PDF version ]" [75]:http://www.tuxradar.com/linuxstarterpack [76]:https://linux.com [77]:https://lwn.net/ [78]:http://hints.macworld.com/ [79]:https://developer.apple.com/library/mac/navigation/ [80]:https://developer.apple.com/library/mac/#documentation/OpenSource/Conceptual/ShellScripting/Introduction/Introduction.html -[81]:https://support.apple.com/kb/index?page=search&locale=en_US&q= +[81]:https://support.apple.com/kb/index?page=search&locale=en_US&q= [82]:https://www.netbsd.org/docs/ [83]:https://www.flickr.com/photos/9479603@N02/3311745151/in/set-72157614479572582/ [84]:https://twitter.com/nixcraft diff --git a/sources/tech/20140929 A Word from The Beegoist - Richard Kenneth Eng - Medium.md b/sources/tech/20140929 A Word from The Beegoist - Richard Kenneth Eng - Medium.md new file mode 100644 index 0000000000..707c2942a7 --- /dev/null +++ b/sources/tech/20140929 A Word from The Beegoist - Richard Kenneth Eng - Medium.md @@ -0,0 +1,623 @@ +A Word from The Beegoist – Richard Kenneth Eng – Medium +====== +I like the [Go programming language][22]. I sought to use Go to write web applications. To this end, I examined two of the “full stack” web frameworks available to Go developers (aka “Gophers”): [Beego][23] and [Revel][24]. + +The reason I looked for full stack was because of my prior experience with [web2py][25], a Python-based framework with extraordinary capability that was also [deliciously easy to get started and be highly productive in][26]. (I also cut my teeth on Smalltalk-based [Seaside][27], which has the same qualities.) In my opinion, full stack is the only way to go because developers should not waste time and effort on the minutiae of tool configuration and setup. The focus should be almost entirely on writing your application. + +Between Beego and Revel, I chose the former. It seemed to be more mature and better documented. It also had a built-in [ORM][28]. + +To be sure, Beego isn’t as easy and productive as web2py, but I believe in Go, so it is worth the effort to give Beego my best shot. To get started with Beego, I needed a project, a useful exercise that covered all the bases, such as database management, CSS styling, email capability, form validation, etc., and also provided a useful end product. + +The project I selected was a user account management component for web applications. All of my previous applications required user registration/login, and Beego did not appear to have anything like that available. + +Now that I’ve completed the project, I believe it would be an excellent foundation for a Beego tutorial. I do not pretend that the code is optimal, nor do I pretend that it is bug-free, but if there are any bugs, it would be a good exercise for a novice to resolve them. + +The inspiration for this tutorial arose from my failure to find good, thorough tutorials when I first started learning Beego. There is one 2-part tutorial that is often mentioned, but I found Part 2 sorely lacking. Throwing source code at you for you to figure out on your own is no way to teach. Thus, I wanted to offer my take on a tutorial. Only history will determine whether it was successful. + +So, without further ado, let’s begin. The word is “Go!” + +### Basic Assumptions + +You have some familiarity with the Go language. I highly recommend you follow this [Go tutorial][1]. + +You’ve installed [Go][2] and [Beego][3] on your computer. There are plenty of good online resources to help you here (for [example][4]). It’s really quite easy. + +You have basic knowledge of CSS, HTML, and databases. You have at least one database package installed on your computer such as [MySQL][5] (Community Edition) or [SQLite][6]. I have SQLite because it’s much easier to use. + +You have some experience writing software; basic skills are assumed. If you studied computer programming in school, then you’re off to a good start. + +You will be using your favourite programming editor in conjunction with the command line. I use [LiteIDE][7] (on the Mac), but I can suggest alternatives such as [TextMate][8] for the Mac, [Notepad++][9] for Windows, and [vim][10] for Linux. + +These basic assumptions define the target audience for the tutorial. If you’re a programming veteran, though, you’ll breeze through it and hopefully gain much useful knowledge, as well. + +### Creating the Project + +First, we must create a Beego project. We’ll call it ‘[ACME][11]’. From the command line, change directory (cd) to $GOPATH/src and enter: +``` +$ bee new acme + +``` + +The following directory structure will be created: +``` +acme +....conf +....controllers +....models +....routers +....static +........css +........img +........js +....tests +....views + +``` + +Note that Beego is a MVC framework (Model/View/Controller), which means that your application will be separated into three general sections. Model refers to the internal database structure of your application. View is all about how your application looks on the computer screen; in our case, this includes HTML and CSS code. And Controller is where you have your business logic and user interactions. + +You can immediately compile and run your application by changing directory (cd acme) and typing: +``` +$ bee run + +``` + +In your browser, go to to see the running application. It doesn’t do anything fancy right now; it simply greets you. But upon this foundation, we shall raise an impressive edifice. + +### The Source Code + +To follow along, you may [download the source code][12] for this tutorial. Cd to $GOPATH/src and unzip the file. [When you download the source, the filename that Github uses is ‘acme-master’. You must change it to ‘acme’.] + +### Program Design + +The user account management component provides the following functionality: + + 1. User registration (account creation) + 2. Account verification (via email) + 3. Login (create a session) + 4. Logout (delete the session) + 5. User profile (can change name, email, or password) + 6. Remove user account + + + +The essence of a web application is the mapping of URLs (webpages) to the server functions that will process the HTTP requests. This mapping is what generates the work flow in the application. In Beego, the mapping is defined within the ‘router’. Here’s the code for our router (look at router.go in the ‘routers’ directory): +``` +beego.Router("/home", &controllers.MainController{}) +beego.Router("/user/login/:back", &controllers.MainController{}, "get,post:Login") +beego.Router("/user/logout", &controllers.MainController{}, "get:Logout") +beego.Router("/user/register", &controllers.MainController{}, "get,post:Register") +beego.Router("/user/profile", &controllers.MainController{}, "get,post:Profile") +beego.Router("/user/verify/:uuid({[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}})", &controllers.MainController{}, "get:Verify") +beego.Router("/user/remove", &controllers.MainController{}, "get,post:Remove") +beego.Router("/notice", &controllers.MainController{}, "get:Notice") + +``` + +For example, in the line for ‘login’, “get,post:Login” says that both the GET and POST operations are handled by the ‘Login’ function. The ‘:back’ is a request parameter; in this case, it tells us what page to return to after successful login. + +In the line for ‘verify’, the ‘:uuid’ is a request parameter that must match the [regular expression][13] for a Version 4 UUID. The GET operation is handled by the ‘Verify’ function. + +More on this when we talk about controllers. + +Note that I’ve added ‘/home’ to the first line in the router (it was originally ‘/’). This makes it convenient to go to the home page, which we often do in our application. + +### Model + +The database model for a user account is represented by the following struct: +``` +package models + +``` +``` +import ( + "github.com/astaxie/beego/orm" + "time" +) + +``` +``` +type AuthUser struct { + Id int + First string + Last string + Email string `orm:"unique"` + Password string + Reg_key string + Reg_date time.Time `orm:"auto_now_add;type(datetime)"` +} + +``` +``` +func init() { + orm.RegisterModel(new(AuthUser)) +} + +``` + +Place this in models.go in the ‘models’ directory. Ignore the init() for the time being. + +‘Id’ is the primary key which is auto-incremented in the database. We also have ‘First’ and ‘Last’ names. ‘Password’ contains the hexadecimal representation of the [PBKDF2 hash][14] of the plaintext password. + +‘Reg_key’ contains the [UUID][15] string that is used for account verification (via email). ‘Reg_date’ is the timestamp indicating the time of registration. + +The funny-looking string literals associated with both ‘Email’ and ‘Reg_date’ are used to tell the database the special requirements of these fields. ‘Email’ must be a unique key. ‘Reg_date’ will be automatically assigned the date and time of database insertion. + +By the way, don’t be scared of the PBKDF2 and UUID references. PBKDF2 is simply a way to securely store a user’s password in the database. A UUID is a unique identifier that can be used to ensure the identity of the user for verification purposes. + +### View + +For our CSS template design, I’ve chosen the [Stardust][16] theme (pictured at the start of this article). We will use its index.html as a basis for the view layout. + +Place the appropriate files from the Stardust theme into the ‘css’ and ‘img’ directories of ‘static’ directory. The link statement in the header of index.html must be amended to: +``` + + +``` + +And all references to image gifs and jpegs in index.html and default.css must point to ‘/static/img/’. + +The view layout contains a header section, a footer section, a sidebar section, and the central section where most of the action will take place. We will be using Go’s templating facility which allows us to replace embedded codes, signified by ‘{{‘ and ‘}}’, with actual HTML. Here’s our basic-layout.tpl (.tpl for ‘template’): +``` +{{.Header}} +{{.LayoutContent}} +{{.Sidebar}} +{{.Footer}} + +``` + +Since every webpage in our application will need to adhere to this basic layout, we need a common method to set it up (look at default.go): +``` +func (this *MainController) activeContent(view string) { + this.Layout = "basic-layout.tpl" + this.LayoutSections = make(map[string]string) + this.LayoutSections["Header"] = "header.tpl" + this.LayoutSections["Sidebar"] = "sidebar.tpl" + this.LayoutSections["Footer"] = "footer.tpl" + this.TplNames = view + ".tpl" + +``` +``` + sess := this.GetSession("acme") + if sess != nil { + this.Data["InSession"] = 1 // for login bar in header.tpl + m := sess.(map[string]interface{}) + this.Data["First"] = m["first"] + } +} + +``` + +The template parameters, such as ‘.Sidebar’, correspond to the keys used in the LayoutSections map. ‘.LayoutContent’ is a special, implicit template parameter. We’ll get to the GetSession stuff further below. + +Of course, we need to create the various template files (such as footer.tpl) in the ‘views’ directory. From index.html, we can carve out the header section for header.tpl: +``` + + + + +StarDust by Free Css Templates + + + + + +``` +``` + + +
+ +
+ + +
+ +``` + +I leave it as an exercise for you to carve out the sections for sidebar.tpl and footer.tpl. + +Note the lines in bold. I added them to facilitate a “login bar” at the top of every webpage. Once you’ve logged into the application, you will see the bar as so: + +![][17] + +This login bar works in conjunction with the GetSession code snippet we saw in activeContent(). The logic is, if the user is logged in (ie, there is a non-nil session), then we set the InSession parameter to a value (any value), which tells the templating engine to use the “Welcome” bar instead of “Login”. We also extract the user’s first name from the session so that we can present the friendly affectation “Welcome, Richard”. + +The home page, represented by index.tpl, uses the following snippet from index.html: +``` + +
+
+

Welcome to StarDust

+ // to save space, I won't enter the remainder + // of the snippet +
+ + +``` + +#### Special Note + +The template files for the user module reside in the ‘user’ directory within ‘views’, just to keep things tidy. So, for example, the call to activeContent() for login is: +``` +this.activeContent("user/login") + +``` + +### Controller + +A controller handles requests by handing them off to the appropriate function or ‘method’. We only have one controller for our application and it’s defined in default.go. The default method Get() for handling a GET operation is associated with our home page: +``` +func (this *MainController) Get() { + this.activeContent("index") + +``` +``` + //bin //boot //dev //etc //home //lib //lib64 //media //mnt //opt //proc //root //run //sbin //speedup //srv //sys //tmp //usr //var This page requires login + sess := this.GetSession("acme") + if sess == nil { + this.Redirect("/user/login/home", 302) + return + } + m := sess.(map[string]interface{}) + fmt.Println("username is", m["username"]) + fmt.Println("logged in at", m["timestamp"]) +} + +``` + +I’ve made login a requirement for accessing this page. Logging in means creating a session, which by default expires after 3600 seconds of inactivity. A session is typically maintained on the client side by a ‘cookie’. + +In order to support sessions in the application, the ‘SessionOn’ flag must be set to true. There are two ways to do this: + + 1. Insert ‘beego.SessionOn = true’ in the main program, main.go. + 2. Insert ‘sessionon = true’ in the configuration file, app.conf, which can be found in the ‘conf’ directory. + + + +I chose #1. (But note that I used the configuration file to set ‘EnableAdmin’ to true: ‘enableadmin = true’. EnableAdmin allows you to use the Supervisor Module in Beego that keeps track of CPU, memory, Garbage Collector, threads, etc., via port 8088: .) + +#### The Main Program + +The main program is also where we initialize the database to be used with the ORM (Object Relational Mapping) component. ORM makes it more convenient to perform database activities within our application. The main program’s init(): +``` +func init() { + orm.RegisterDriver("sqlite", orm.DR_Sqlite) + orm.RegisterDataBase("default", "sqlite3", "acme.db") + name := "default" + force := false + verbose := false + err := orm.RunSyncdb(name, force, verbose) + if err != nil { + fmt.Println(err) + } +} + +``` + +To use SQLite, we must import ‘go-sqlite3', which can be installed with the command: +``` +$ go get github.com/mattn/go-sqlite3 + +``` + +As you can see in the code snippet, the SQLite driver must be registered and ‘acme.db’ must be registered as our SQLite database. + +Recall in models.go, there was an init() function: +``` +func init() { + orm.RegisterModel(new(AuthUser)) +} + +``` + +The database model has to be registered so that the appropriate table can be generated. To ensure that this init() function is executed, you must import ‘models’ without actually using it within the main program, as follows: +``` +import _ "acme/models" + +``` + +RunSyncdb() is used to autogenerate the tables when you start the program. (This is very handy for creating the database tables without having to **manually** do it in the database command line utility.) If you set ‘force’ to true, it will drop any existing tables and recreate them. + +#### The User Module + +User.go contains all the methods for handling login, registration, profile, etc. There are several third-party packages we need to import; they provide support for email, PBKDF2, and UUID. But first we must get them into our project… +``` +$ go get github.com/alexcesaro/mail/gomail +$ go get github.com/twinj/uuid + +``` + +I originally got **github.com/gokyle/pbkdf2** , but this package was pulled from Github, so you can no longer get it. I’ve incorporated this package into my source under the ‘utilities’ folder, and the import is: +``` +import pk "acme/utilities/pbkdf2" + +``` + +The ‘pk’ is a convenient alias so that I don’t have to type the rather unwieldy ‘pbkdf2'. + +#### ORM + +It’s pretty straightforward to use ORM. The basic pattern is to create an ORM object, specify the ‘default’ database, and select which ORM operation you want, eg, +``` +o := orm.NewOrm() +o.Using("default") +err := o.Insert(&user) // or +err := o.Read(&user, "Email") // or +err := o.Update(&user) // or +err := o.Delete(&user) + +``` + +#### Flash + +By the way, Beego provides a way to present notifications on your webpage through the use of ‘flash’. Basically, you create a ‘flash’ object, give it your notification message, store the flash in the controller, and then retrieve the message in the template file, eg, +``` +flash := beego.NewFlash() +flash.Error("You've goofed!") // or +flash.Notice("Well done!") +flash.Store(&this.Controller) + +``` + +And in your template file, reference the Error flash with: +``` +{{if .flash.error}} +

{{.flash.error}}

+  +{{end}} + +``` + +#### Form Validation + +Once the user posts a request (by pressing the Submit button, for example), our handler must extract and validate the form input. So, first, check that we have a POST operation: +``` +if this.Ctx.Input.Method() == "POST" { + +``` + +Let’s get a form element, say, email: +``` +email := this.GetString("email") + +``` + +The string “email” is the same as in the HTML form: +``` + + +``` + +To validate it, we create a validation object, specify the type of validation, and then check to see if there are any errors: +``` +valid := validation.Validation{} +valid.Email(email, "email") // must be a proper email address +if valid.HasErrors() { + for _, err := range valid.Errors { + +``` + +What you do with the errors is up to you. I like to present all of them at once to the user, so as I go through the range of valid.Errors, I add them to a map of errors that will eventually be used in the template file. Hence, the full snippet: +``` +if this.Ctx.Input.Method() == "POST" { + email := this.GetString("email") + password := this.GetString("password") + valid := validation.Validation{} + valid.Email(email, "email") + valid.Required(password, "password") + if valid.HasErrors() { + errormap := []string{} + for _, err := range valid.Errors { + errormap = append(errormap, "Validation failed on "+err.Key+": "+err.Message+"\n") + } + this.Data["Errors"] = errormap + return + } + +``` + +### The User Management Methods + +We’ve looked at the major pieces of the controller. Now, we get to the meat of the application, the user management methods: + + * Login() + * Logout() + * Register() + * Verify() + * Profile() + * Remove() + + + +Recall that we saw references to these functions in the router. The router associates each URL (and HTTP request) with the corresponding controller method. + +#### Login() + +Let’s look at the pseudocode for this method: +``` +if the HTTP request is "POST" then + Validate the form (extract the email address and password). + Read the password hash from the database, keying on email. + Compare the submitted password with the one on record. + Create a session for this user. +endif + +``` + +In order to compare passwords, we need to give pk.MatchPassword() a variable with members ‘Hash’ and ‘Salt’ that are **byte slices**. Hence, +``` +var x pk.PasswordHash + +``` +``` +x.Hash = make([]byte, 32) +x.Salt = make([]byte, 16) +// after x has the password from the database, then... + +``` +``` +if !pk.MatchPassword(password, &x) { + flash.Error("Bad password") + flash.Store(&this.Controller) + return +} + +``` + +Creating a session is trivial, but we want to store some useful information in the session, as well. So we make a map and store first name, email address, and the time of login: +``` +m := make(map[string]interface{}) +m["first"] = user.First +m["username"] = email +m["timestamp"] = time.Now() +this.SetSession("acme", m) +this.Redirect("/"+back, 302) // go to previous page after login + +``` + +Incidentally, the name “acme” passed to SetSession is completely arbitrary; you just need to reference the same name to get the same session. + +#### Logout() + +This one is trivially easy. We delete the session and redirect to the home page. + +#### Register() +``` +if the HTTP request is "POST" then + Validate the form. + Create the password hash for the submitted password. + Prepare new user record. + Convert the password hash to hexadecimal string. + Generate a UUID and insert the user into database. + Send a verification email. + Flash a message on the notification page. +endif + +``` + +To send a verification email to the user, we use **gomail** … +``` +link := "http://localhost:8080/user/verify/" + u // u is UUID +host := "smtp.gmail.com" +port := 587 +msg := gomail.NewMessage() +msg.SetAddressHeader("From", "acmecorp@gmail.com", "ACME Corporation") +msg.SetHeader("To", email) +msg.SetHeader("Subject", "Account Verification for ACME Corporation") +msg.SetBody("text/html", "To verify your account, please click on the link: "+link+"

Best Regards,
ACME Corporation") +m := gomail.NewMailer(host, "youraccount@gmail.com", "YourPassword", port) +if err := m.Send(msg); err != nil { + return false +} + +``` + +I chose Gmail as my email relay (you will need to open your own account). Note that Gmail ignores the “From” address (in our case, “[acmecorp@gmail.com][18]”) because Gmail does not permit you to alter the sender address in order to prevent phishing. + +#### Notice() + +This special router method is for displaying a flash message on a notification page. It’s not really a user module function; it’s general enough that you can use it in many other places. + +#### Profile() + +We’ve already discussed all the pieces in this function. The pseudocode is: +``` +Login required; check for a session. +Get user record from database, keyed on email (or username). +if the HTTP request is "POST" then + Validate the form. + if there is a new password then + Validate the new password. + Create the password hash for the new password. + Convert the password hash to hexadecimal string. + endif + Compare submitted current password with the one on record. + Update the user record. + - update the username stored in session +endif + +``` + +#### Verify() + +The verification email contains a link which, when clicked by the recipient, causes Verify() to process the UUID. Verify() attempts to read the user record, keyed on the UUID or registration key, and if it’s found, then the registration key is removed from the database. + +#### Remove() + +Remove() is pretty much like Login(), except that instead of creating a session, you delete the user record from the database. + +### Exercise + +I left out one user management method: What if the user has forgotten his password? We should provide a way to reset the password. I leave this as an exercise for you. All the pieces you need are in this tutorial. (Hint: You’ll need to do it in a way similar to Registration verification. You should add a new Reset_key to the AuthUser table. And make sure the user email address exists in the database before you send the Reset email!) + +[Okay, so I’ll give you the [exercise solution][19]. I’m not cruel.] + +### Wrapping Up + +Let’s review what we’ve learned. We covered the mapping of URLs to request handlers in the router. We showed how to incorporate a CSS template design into our views. We discussed the ORM package, and how it’s used to perform database operations. We examined a number of third-party utilities useful in writing our application. The end result is a component useful in many scenarios. + +This is a great deal of material in a tutorial, but I believe it’s the best way to get started in writing a practical application. + +[For further material, look at the [sequel][20] to this article, as well as the [final edition][21].] + +-------------------------------------------------------------------------------- + +via: https://medium.com/@richardeng/a-word-from-the-beegoist-d562ff8589d7 + +作者:[Richard Kenneth Eng][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://medium.com/@richardeng?source=post_header_lockup +[1]:http://tour.golang.org/ +[2]:http://golang.org/ +[3]:http://beego.me/ +[4]:https://medium.com/@richardeng/in-the-beginning-61c7e63a3ea6 +[5]:http://www.mysql.com/ +[6]:http://www.sqlite.org/ +[7]:https://code.google.com/p/liteide/ +[8]:http://macromates.com/ +[9]:http://notepad-plus-plus.org/ +[10]:https://medium.com/@richardeng/back-to-the-future-9db24d6bcee1 +[11]:http://en.wikipedia.org/wiki/Acme_Corporation +[12]:https://github.com/horrido/acme +[13]:http://en.wikipedia.org/wiki/Regular_expression +[14]:http://en.wikipedia.org/wiki/PBKDF2 +[15]:http://en.wikipedia.org/wiki/Universally_unique_identifier +[16]:http://www.freewebtemplates.com/download/free-website-template/stardust-141989295/ +[17]:https://cdn-images-1.medium.com/max/1600/1*1OpYy1ISYGUaBy0U_RJ75w.png +[18]:mailto:acmecorp@gmail.com +[19]:https://github.com/horrido/acme-exercise +[20]:https://medium.com/@richardeng/a-word-from-the-beegoist-ii-9561351698eb +[21]:https://medium.com/@richardeng/a-word-from-the-beegoist-iii-dbd6308b2594 +[22]: http://golang.org/ +[23]: http://beego.me/ +[24]: http://revel.github.io/ +[25]: http://www.web2py.com/ +[26]: https://medium.com/@richardeng/the-zen-of-web2py-ede59769d084 +[27]: http://www.seaside.st/ +[28]: http://en.wikipedia.org/wiki/Object-relational_mapping diff --git a/sources/tech/20160503 Cloud Commander - A Web File Manager With Console And Editor.md b/sources/tech/20160503 Cloud Commander - A Web File Manager With Console And Editor.md deleted file mode 100644 index 0aae74d680..0000000000 --- a/sources/tech/20160503 Cloud Commander - A Web File Manager With Console And Editor.md +++ /dev/null @@ -1,143 +0,0 @@ -Cloud Commander – A Web File Manager With Console And Editor -====== - -![](https://www.ostechnix.com/wp-content/uploads/2016/05/Cloud-Commander-A-Web-File-Manager-With-Console-And-Editor-720x340.png) - -**Cloud commander** is a web-based file manager application that allows you to view, access, and manage the files and folders of your system from any computer, mobile, and tablet Pc via a web browser. It has two simple and classic panels, and automatically converts it’s size as per your device’s display size. It also has two built-in editors namely **Dword** and **Edward** with support of Syntax-highlighting and one **Console** with support of your system’s command line. So you can edit your files on the go. Cloud Commander server is a cross-platform application that runs on Linux, Windows and Mac OS X operating systems, and the client will run on any web browser. It is written using **JavaScript/Node.Js** , and is licensed under **MIT**. - -In this brief tutorial, let us see how to install Cloud Commander in Ubuntu 18.04 LTS server. - -### Prerequisites - -As I mentioned earlier, Cloud Commander is written using Node.Js. So, in order to install Cloud Commander we need to install Node.Js first. To do so, refer the following guide. - -### Install Cloud Commander - -After installing Node.Js, run the following command to install Cloud Commander: -``` -$ npm i cloudcmd -g - -``` - -Congratulations! Cloud Commander has been installed. Let us go ahead and see the basic usage of Cloud Commander. - -### Getting started with Cloud Commander - -Run the following command to start Cloud Commander: -``` -$ cloudcmd - -``` - -**Sample output:** -``` -url: http://localhost:8000 - -``` - -Now, open your web browser and navigate to the URL: ** ****. - -From now on, you can create, delete, view, manage files or folders right in the web browser from the local system or remote system, or mobile, tablet etc. - -![][2] - -As you can see in the above screenshot, Cloud Commander has two panels, ten hotkeys (F1 to F10), and Console. - -Each hotkey does a unique job. - - * F1 – Help - * F2 – Rename file/folder - * F3 – View files and folders - * F4 – Edit files - * F5 – Copy files/folders - * F6 – Move files/folders - * F7 – Create new directory - * F8 – Delete file/folder - * F9 – Open Menu - * F10 – Open config - - - -#### Cloud Commander console - -Click on the Console icon. This will open your default system’s shell. - -![][3] - -From this console you can do all sort of administration tasks such as installing packages, removing packages, update your system etc. You can even shutdown or reboot system. Therefore, Cloud Commander is not just a file manager, but also has the functionality of a remote administration tool. - -#### Creating files/folders - -To create a new file or folder Right click on any empty place and go to **New - >File or Directory**. - -![][4] - -#### View files - -You can view pictures, watch audio and video files. - -![][5] - -#### Upload files - -The other cool feature is we can easily upload a file to Cloud Commander system from any system or device. - -To upload a file, right click on any empty space in the Cloud Commander panel, and click on the **Upload** option. - -![][6] - -Select the files you want to upload. - -Also, you can upload files from the Cloud services like Google drive, Dropbox, Amazon cloud drive, Facebook, Twitter, Gmail, GtiHub, Picasa, Instagram and many. - -To upload files from Cloud, right click on any empty space in the panel and select **Upload from Cloud**. - -![][7] - -Select any web service of your choice, for example Google drive. Click **Connect to Google drive** button. - -![][8] - -In the next step, authenticate your google drive with Cloud Commander. Finally, select the files from your Google drive and click **Upload**. - -![][9] - -#### Update Cloud Commander - -To update Cloud Commander to the latest available version, run the following command: -``` -$ npm update cloudcmd -g - -``` - -#### Conclusion - -As far as I tested Cloud Commander, It worked like charm. I didn’t face a single issue during the testing in my Ubuntu server. Also, Cloud Commander is not just a web-based file manager, but also acts as a remote administration tool that performs most Linux administration tasks. You can create a files/folders, rename, delete, edit, and view them. Also, You can install, update, upgrade, and remove any package as the way you do in the local system from the Terminal. And, of course, you can even shutdown or restart the system from the Cloud Commander console itself. What do you need more? Give it a try, you will find it useful. - -That’s all for now. I will be here soon with another interesting article. Until then, stay tuned with OSTechNix. - -Cheers! - - - --------------------------------------------------------------------------------- - -via: https://www.ostechnix.com/cloud-commander-a-web-file-manager-with-console-and-editor/ - -作者:[SK][a] -选题:[lujun9972](https://github.com/lujun9972) -译者:[译者ID](https://github.com/译者ID) -校对:[校对者ID](https://github.com/校对者ID) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 - -[a]:https://www.ostechnix.com/author/sk/ -[1]:data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7 -[2]:http://www.ostechnix.com/wp-content/uploads/2016/05/Cloud-Commander-Google-Chrome_006-4.jpg -[3]:http://www.ostechnix.com/wp-content/uploads/2016/05/Cloud-Commander-Google-Chrome_007-2.jpg -[4]:http://www.ostechnix.com/wp-content/uploads/2016/05/Cloud-commander-file-folder-1.png -[5]:http://www.ostechnix.com/wp-content/uploads/2016/05/Cloud-Commander-home-sk-Google-Chrome_008-1.jpg -[6]:http://www.ostechnix.com/wp-content/uploads/2016/05/cloud-commander-upload-2.png -[7]:http://www.ostechnix.com/wp-content/uploads/2016/05/upload-from-cloud-1.png -[8]:http://www.ostechnix.com/wp-content/uploads/2016/05/Cloud-Commander-home-sk-Google-Chrome_009-2.jpg -[9]:http://www.ostechnix.com/wp-content/uploads/2016/05/Cloud-Commander-home-sk-Google-Chrome_010-1.jpg diff --git a/sources/tech/20170410 Writing a Time Series Database from Scratch.md b/sources/tech/20170410 Writing a Time Series Database from Scratch.md index a7f8289b63..ba66193a0d 100644 --- a/sources/tech/20170410 Writing a Time Series Database from Scratch.md +++ b/sources/tech/20170410 Writing a Time Series Database from Scratch.md @@ -1,4 +1,4 @@ -Writing a Time Series Database from Scratch +[haoqixu翻译中]Writing a Time Series Database from Scratch ============================================================ diff --git a/sources/tech/20170710 iWant - The Decentralized Peer To Peer File Sharing Commandline Application.md b/sources/tech/20170710 iWant - The Decentralized Peer To Peer File Sharing Commandline Application.md new file mode 100644 index 0000000000..7ecb35e4da --- /dev/null +++ b/sources/tech/20170710 iWant - The Decentralized Peer To Peer File Sharing Commandline Application.md @@ -0,0 +1,200 @@ +iWant – The Decentralized Peer To Peer File Sharing Commandline Application +====== + +![](https://www.ostechnix.com/wp-content/uploads/2017/07/p2p-720x340.jpg) + +A while ago, we have written a guide about two file sharing utilities named [**transfer.sh**][1], a free web service that allows you to share files over Internet easily and quickly, and [**PSiTransfer**][2], a simple open source self-hosted file sharing solution. Today, we will see yet another file sharing utility called **“iWant”**. It is a free and open source CLI-based decentralized peer to peer file sharing application. + +What’s makes it different from other file sharing applications? You might wonder. Here are some prominent features of iWant. + + * It’s commandline application. You don’t need any memory consuming GUI utilities. You need only the Terminal. + * It is decentralized. That means your data will not be stored in any central location. So, there is no central point of failure. + * iWant allows you to pause the download and you can resume it later when you want. You don’t need to download it from beginning, it just resumes the downloads from where you left off. + * Any changes made in the files in the shared directory (such as deletion, addition, modification) will be reflected instantly in the network. + * Just like torrents, iWant downloads the files from multiple peers. If any seeder left the group or failed to respond, it will continue the download from another seeder. + * It is cross-platform, so, you can use it in GNU/Linux, MS Windows, and Mac OS X. + + + +### iWant – A CLI-based Decentralized Peer To Peer File Sharing Solution + +#### Install iWant + +iWant can be easily installed using PIP package manager. Make sure you have pip installed in your Linux distribution. if it is not installed yet, refer the following guide. + +[How To Manage Python Packages Using Pip](https://www.ostechnix.com/manage-python-packages-using-pip/) + +After installing PIP, make sure you have installed the the following dependencies: + + * libffi-dev + * libssl-dev + + + +Say for example, on Ubuntu, you can install these dependencies using command: +``` +$ sudo apt-get install libffi-dev libssl-dev + +``` + +Once all dependencies installed, install iWant using the following command: +``` +$ sudo pip install iwant + +``` + +We have now iWant in our system. Let us go ahead and see how to use it to transfer files over network. + +#### Usage + +First, start iWant server using command: +``` +$ iwanto start + +``` + +At the first time, iWant will ask the Shared and Download folder’s location. Enter the actual location of both folders. Then, choose which interface you want to use: + +Sample output would be: +``` +Shared/Download folder details looks empty.. +Note: Shared and Download folder cannot be the same +SHARED FOLDER(absolute path):/home/sk/myshare +DOWNLOAD FOLDER(absolute path):/home/sk/mydownloads +Network interface available +1. lo => 127.0.0.1 +2. enp0s3 => 192.168.43.2 +Enter index of the interface:2 +now scanning /home/sk/myshare +[Adding] /home/sk/myshare 0.0 +Updating Leader 56f6d5e8-654e-11e7-93c8-08002712f8c1 +[Adding] /home/sk/myshare 0.0 +connecting to 192.168.43.2:1235 for hashdump + +``` + +If you see an output something like above, you can start using iWant right away. + +Similarly, start iWant service on all systems in the network, assign valid Shared and Downloads folder’s location, and select the network interface card. + +The iWant service will keep running in the current Terminal window until you press **CTRL+C** to quit it. You need to open a new tab or new Terminal window to use iWant. + +iWant usage is very simple. It has few commands as listed below. + + * **iwanto start** – Starts iWant server. + * **iwanto search ** – Search for files. + * **iwanto download ** – Download a file. + * **iwanto share ** – Change the Shared folder’s location. + * **iwanto download to ** – Change the Download folder’s location. + * **iwanto view config** – View Shared and Download folders. + * **iwanto –version** – Displays the iWant version. + * **iwanto -h** – Displays the help section. + + + +Allow me to show you some examples. + +**Search files** + +To search for a file, run: +``` +$ iwanto search + +``` + +Please note that you don’t need to specify the accurate name. + +Example: +``` +$ iwanto search command + +``` + +The above command will search for any files that contains the string “command”. + +Sample output from my Ubuntu system: +``` +Filename Size Checksum +------------------------------------------- ------- -------------------------------- +/home/sk/myshare/THE LINUX COMMAND LINE.pdf 3.85757 efded6cc6f34a3d107c67c2300459911 + +``` + +**Download files** + +You can download the files from any system on your network. To download a file, just mention the hash (checksum) of the file as shown below. You can get hash value of a share using “iwanto search” command. +``` +$ iwanto download efded6cc6f34a3d107c67c2300459911 + +``` + +The file will be saved in your Download location (/home/sk/mydownloads/ in my case). +``` +Filename: /home/sk/mydownloads/THE LINUX COMMAND LINE.pdf +Size: 3.857569 MB + +``` + +**View configuration** + +To view the configuration i.e the Shared and Download folders, run: +``` +$ iwanto view config + +``` + +Sample output: +``` +Shared folder:/home/sk/myshare +Download folder:/home/sk/mydownloads + +``` + +**Change Shared and Download folder’s location** + +You can change the Shared folder and Download folder location to some other path like below. +``` +$ iwanto share /home/sk/ostechnix + +``` + +Now, the Shared location has been changed to /home/sk/ostechnix location. + +Also, you can change the Downloads location using command: +``` +$ iwanto download to /home/sk/Downloads + +``` + +To view the changes made, run the config command: +``` +$ iwanto view config + +``` + +**Stop iWant** + +Once you done with iWant, you can quit it by pressing **CTRL+C**. + +If it is not working by any chance, it might be due to Firewall or your router doesn’t support multicast. You can view all logs in** ~/.iwant/.iwant.log** file. For more details, refer the project’s GitHub page provided at the end. + +And, that’s all. Hope this tool helps. I will be here again with another interesting guide. Till then, stay tuned with OSTechNix! + +Cheers! + + + +-------------------------------------------------------------------------------- + +via: https://www.ostechnix.com/iwant-decentralized-peer-peer-file-sharing-commandline-application/ + +作者:[SK][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.ostechnix.com/author/sk/ +[1]:https://www.ostechnix.com/easy-fast-way-share-files-internet-command-line/ +[2]:https://www.ostechnix.com/psitransfer-simple-open-source-self-hosted-file-sharing-solution/ diff --git a/sources/tech/20170713 A Collection Of Useful BASH Scripts For Heavy Commandline Users.md b/sources/tech/20170713 A Collection Of Useful BASH Scripts For Heavy Commandline Users.md deleted file mode 100644 index 6b8d840889..0000000000 --- a/sources/tech/20170713 A Collection Of Useful BASH Scripts For Heavy Commandline Users.md +++ /dev/null @@ -1,601 +0,0 @@ -A Collection Of Useful BASH Scripts For Heavy Commandline Users -====== - -![](https://www.ostechnix.com/wp-content/uploads/2017/07/A-Collection-Of-Useful-BASH-Scripts-720x340.png) - -Today, I have stumbled upon a collection of useful BASH scripts for heavy commandline users. These scripts, known as **Bash-Snippets** , might be quite helpful for those who live in Terminal all day. Want to check the weather of a place where you live? This script will do that for you. Wondering what is the Stock price? You can run the script that displays the current details of a stock. Feel bored? You can watch some youtube videos. All from commandline. You don’t need to install any heavy memory consumable GUI applications. - -As of writing this, Bash-Snippets provides the following 19 useful tools: - - 1. **Cheat** – Linux Commands cheat sheet. - 2. **Cloudup** – A tool to backup your GitHub repositories to bitbucket. - 3. **Crypt** – Encrypt and decrypt files. - 4. **Cryptocurrency** – Converts Cryptocurrency based on realtime exchange rates of the top 10 cryptos. - 5. **Currency** – Currency converter. - 6. **Geo** – Provides the details of wan, lan, router, dns, mac, and ip. - 7. **Lyrics** – Grab lyrics for a given song quickly from the command line. - 8. **Meme** – Command line meme creator. - 9. **Movies** – Search and display a movie details. - 10. **Newton** – Performs numerical calculations all the way up to symbolic math parsing. - 11. **Qrify** – Turns the given string into a qr code. - 12. **Short** – URL Shortner - 13. **Siteciphers** – Check which ciphers are enabled / disabled for a given https site. - 14. **Stocks** – Provides certain Stock details. - 15. **Taste** – Recommendation engine that provides three similar items like the supplied item (The items can be books, music, artists, movies, and games etc). - 16. **Todo** – Command line todo manager. - 17. **Transfer** – Quickly transfer files from the command line. - 18. **Weather** – Displays weather details of your place. - 19. **Youtube-Viewer** – Watch YouTube from Terminal. - - - -The author might add more utilities and/or features in future, so I recommend you to keep an eye on the project’s website or GitHub page for future updates. - -### Bash-Snippets – A Collection Of Useful BASH Scripts For Heavy Commandline Users - -#### Installation - -You can install these scripts on any OS that supports BASH. - -First, clone the GIT repository using command: -``` -$ git clone https://github.com/alexanderepstein/Bash-Snippets - -``` - -Go to the cloned directory: -``` -$ cd Bash-Snippets/ - -``` - -Git checkout to the latest stable release: -``` -$ git checkout v1.22.0 - -``` - -Finally, install the Bash-Snippets using command: -``` -$ sudo ./install.sh - -``` - -This will ask you which scripts to install. Just type **Y** and press ENTER key to install the respective script. If you don’t want to install a particular script, type **N** and hit ENTER. -``` -Do you wish to install currency [Y/n]: y - -``` - -To install all scripts, run: -``` -$ sudo ./install.sh all - -``` - -To install a specific script, say currency, run: -``` -$ sudo ./install.sh currency - -``` - -You can also install it using [**Linuxbrew**][1] package manager. - -To installs all tools, run: -``` -$ brew install bash-snippets - -``` - -To install specific tools: -``` -$ brew install bash-snippets --without-all-tools --with-newton --with-weather - -``` - -Also, there is a PPA for Debian-based systems such as Ubuntu, Linux Mint. -``` -$ sudo add-apt-repository ppa:navanchauhan/bash-snippets -$ sudo apt update -$ sudo apt install bash-snippets - -``` - -#### Usage - -**An active Internet connection is required** to use these tools. The usage is fairly simple. Let us see how to use some of these scripts. I assume you have installed all scripts. - -**1\. Currency – Currency Converter** - -This script converts the currency based on realtime exchange rates. Enter the base currency code and the currency to exchange to, and the amount being exchanged one by one as shown below. -``` -$ currency -What is the base currency: INR -What currency to exchange to: USD -What is the amount being exchanged: 10 - -========================= -| INR to USD -| Rate: 0.015495 -| INR: 10 -| USD: .154950 -========================= - -``` - -You can also pass all arguments in a single command as shown below. -``` -$ currency INR USD 10 - -``` - -Refer the following screenshot. - -[![Bash-Snippets][2]][3] - -**2\. Stocks – Display stock price details** - -If you want to check a stock price details, mention the stock item as shown below. -``` -$ stocks Intel - -INTC stock info -============================================= -| Exchange Name: NASDAQ -| Latest Price: 34.2500 -| Close (Previous Trading Day): 34.2500 -| Price Change: 0.0000 -| Price Change Percentage: 0.00% -| Last Updated: Jul 12, 4:00PM EDT -============================================= - -``` - -The above output the **Intel stock** details. - -**3\. Weather – Display Weather details** - -Let us check the Weather details by running the following command: -``` -$ weather - -``` - -**Sample output:** - -![][4] - -As you see in the above screenshot, it provides the 3 day weather forecast. Without any arguments, it will display the weather details based on your IP address. You can also bring the weather details of a particular city or country like below. -``` -$ weather Chennai - -``` - -Also, you can view the moon phase by entering the following command: -``` -$ weather moon - -``` - -Sample output would be: - -![][5] - -**4\. Crypt – Encrypt and Decrypt files** - -This script is a wrapper for openssl that allows you to encrypt and decrypt files quickly and easily. - -To encrypt a file, use the following command: -``` -$ crypt -e [original file] [encrypted file] - -``` - -For example, the following command will encrypt a file called **ostechnix.txt** , and save it as **encrypt_ostechnix.txt **in the current working directory. -``` -$ crypt -e ostechnix.txt encrypt_ostechnix.txt - -``` - -Enter the password for the file twice. -``` -Encrypting ostechnix.txt... -enter aes-256-cbc encryption password: -Verifying - enter aes-256-cbc encryption password: -Successfully encrypted - -``` - -The above command will encrypt the given file using **AES 256 level encryption**. The password will not be saved in plain text. You can encrypt .pdf, .txt, .docx, .doc, .png, .jpeg type files. - -To decrypt the file, use the following command: -``` -$ crypt -d [encrypted file] [output file] - -``` - -Example: -``` -$ crypt -d encrypt_ostechnix.txt ostechnix.txt - -``` - -Enter the password to decrypt. -``` -Decrypting encrypt_ostechnix.txt... -enter aes-256-cbc decryption password: -Successfully decrypted - -``` - -**5\. Movies – Find Movie details** - -Using this script, you can find a movie details. - -The following command displays the details of a movie called “mother”. -``` -$ movies mother - -================================================== -| Title: Mother -| Year: 2009 -| Tomato: 95% -| Rated: R -| Genre: Crime, Drama, Mystery -| Director: Bong Joon Ho -| Actors: Hye-ja Kim, Bin Won, Goo Jin, Je-mun Yun -| Plot: A mother desperately searches for the killer who framed her son for a girl's horrific murder. -================================================== - -``` - -**6\. Display similar items like the supplied item** - -To use this script, you need to get the API key **[here][6]**. No worries, it is completely FREE! Once the you got the API, add the following line to your **~/.bash_profile** : **export TASTE_API_KEY=”yourAPIKeyGoesHere”**`` - -Now, you can view the similar item like the supplied item as shown below: -``` -$ taste -i Red Hot Chilli Peppers - -``` - -**7\. Short – Shorten URLs** - -This script shortens the given URL. -``` -$ short - -``` - -**8\. Geo – Display the details of your network** - -This script helps you to find out the details of your network, such as wan, lan, router, dns, mac, and ip geolocation. - -For example, to find out your LAN ip, run: -``` -$ geo -l - -``` - -Sample output from my system: -``` -192.168.43.192 - -``` - -To find your Wan IP: -``` -$ geo -w - -``` - -For more details, just type ‘geo’ in the Terminal. -``` -$ geo -Geo -Description: Provides quick access for wan, lan, router, dns, mac, and ip geolocation data -Usage: geo [flag] - -w Returns WAN IP - -l Returns LAN IP(s) - -r Returns Router IP - -d Returns DNS Nameserver - -m Returns MAC address for interface. Ex. eth0 - -g Returns Current IP Geodata -Examples: - geo -g - geo -wlrdgm eth0 -Custom Geo Output => -[all] [query] [city] [region] [country] [zip] [isp] -Example: geo -a 8.8.8.8 -o city,zip,isp - -o [options] Returns Specific Geodata - -a [address] For specific ip in -s - -v Returns Version - -h Returns Help Screen - -u Updates Bash-Snippets - -``` - -**9\. Cheat – Display cheatsheets of Linux commands** - -Want to refer the cheatsheet of Linux command? Well, it is also possible. The following command will display the cheatsheet of **curl** command: -``` -$ cheat curl - -``` - -Just replace **curl** with the command of your choice to display its cheatsheet. This can be very useful for the quick reference to any command you want to use. - -**10\. Youtube-Viewer – Watch YouTube videos** - -Using this script, you can search or watch youtube videos right from the Terminal. - -Let us watch some **Ed Sheeran** videos. -``` -$ ytview Ed Sheeran - -``` - -Choose the video you want to play from the list. The selected will play in your default media player. - -![][7] - -To view recent videos by an artist, you can use: -``` -$ ytview -c [channel name] - -``` - -To search for videos, just enter: -``` -$ ytview -s [videoToSearch] - -``` - -or just, -``` -$ ytview [videoToSearch] - -``` - -**11\. cloudup – Backup GitHub repositories to bitbucket** - -Have you hosted any project on GitHub? Great! You can backup the GitHub repositories to **bitbucket** , a web-based hosting service used for source code and development projects, at any time. - -You can either backup all github repositories of the designated user at once with the **-a** option. Or run it with no flags and backup individual repositories. - -To backup GitHub repository, run: -``` -$ cloudup - -``` - -You will be asked to enter your GitHub username, name of the repository to backup, and bitbucket username and password etc. - -**12\. Qrify – Convert Strings into QR code** - -This script converts any given string of text into a QR code. This is useful for sending links or saving a string of commands to your phone -``` -$ qrify convert this text into qr code - -``` - -Sample output would be: - -![][8] - -Cool, isn’t it? - -**13\. Cryptocurrency** - -It displays the top ten cryptocurrencies realtime exchange rates. - -Type the following command and hit ENTER to run it: -``` -$ cryptocurrency - -``` - -![][9] - -**14\. Lyrics** - -This script grabs the lyrics for a given song quickly from the command line. - -Say for example, I am going to fetch the lyrics of **“who is it”** song, a popular song sung by **Michael Jackson**. -``` -$ lyrics -a michael jackson -s who is it - -``` - -![][10] - -**15\. Meme** - -This script allows you to create simple memes from command line. It is quite faster than GUI-based meme generators. - -To create a meme, just type: -``` -$ meme -f mymeme -Enter the name for the meme's background (Ex. buzz, doge, blb ): buzz -Enter the text for the first line: THIS IS A -Enter the text for the second line: MEME - -``` - -This will create jpg file in your current working directory. - -**16\. Newton** - -Tired of solving complex Maths problems? Here you go. The Newton script will perform numerical calculations all the way up to symbolic math parsing. - -![][11] - -**17\. Siteciphers** - -This script helps you to check which ciphers are enabled / disabled for a given https site. -``` -$ siteciphers google.com - -``` - -![][12] - -**18\. Todo** - -It allows you to create everyday tasks directly from the Terminal. - -Let us create some tasks. -``` -$ todo -a The first task -01). The first task Tue Jun 26 14:51:30 IST 2018 - -``` - -To add another task, simply re-run the above command with the task name. -``` -$ todo -a The second task -01). The first task Tue Jun 26 14:51:30 IST 2018 -02). The second task Tue Jun 26 14:52:29 IST 2018 - -``` - -To view the list of tasks, run: -``` -$ todo -g -01). The first task Tue Jun 26 14:51:30 IST 2018 -02). A The second task Tue Jun 26 14:51:46 IST 2018 - -``` - -Once you completed a task, remove it from the list as shown below. -``` -$ todo -r 2 -Sucessfully removed task number 2 -01). The first task Tue Jun 26 14:51:30 IST 2018 - -``` - -To clear all tasks, run: -``` -$ todo -c -Tasks cleared. - -``` - -**19\. Transfer** - -The transfer script allows you to quickly and easily transfer files and directories over Internet. - -Let us upload a file. -``` -$ transfer test.txt -Uploading test.txt -################################################################################################################################################ 100.0% -Success! -Transfer Download Command: transfer -d desiredOutputDirectory ivmfj test.txt -Transfer File URL: https://transfer.sh/ivmfj/test.txt - -``` - -The file will be uploaded to transfer.sh site. Transfer.sh allows you to upload files up to **10 GB** in one go. All shared files automatically expire after **14 days**. As you can see, anyone can download the file either by visiting the second URL via a web browser or using the transfer command (it is installed in his/her system, of course). - -Now remove the file from your system. -``` -$ rm -fr test.txt - -``` - -Now, you can download the file from transfer.sh site at any time (within 14 days) like below. -``` -$ transfer -d Downloads ivmfj test.txt - -``` - -For more details about this utility, refer our following guide. - -##### Getting help - -If you don’t know how to use a particular script, just type that script’s name and press ENTER. You will see the usage details. The following example displays the help section of **Qrify** script. -``` -$ qrify -Qrify -Usage: qrify [stringtoturnintoqrcode] -Description: Converts strings or urls into a qr code. - -u Update Bash-Snippet Tools - -m Enable multiline support (feature not working yet) - -h Show the help - -v Get the tool version -Examples: - qrify this is a test string - qrify -m two\\nlines - qrify github.com # notice no http:// or https:// this will fail - -``` - -#### Updating scripts - -You can update the installed tools at any time suing -u option. The following command updates “weather” tool. -``` -$ weather -u - -``` - -#### Uninstall - -You can uninstall these tools as shown below. - -Git clone the repository: -``` -$ git clone https://github.com/alexanderepstein/Bash-Snippets - -``` - -Go to the Bash-Snippets directory: -``` -$ cd Bash-Snippets - -``` - -And uninstall the scripts by running the following command: -``` -$ sudo ./uninstall.sh - -``` - -Type **y** and hit ENTER to remove each script. -``` -Do you wish to uninstall currency [Y/n]: y - -``` - -**Also read: ** - -And, that’s all for now folks. I must admit that I’m very impressed when testing this scripts. I really liked the idea of combing all useful scripts into a single package. Kudos to the developer. Give it a try, you won’t be disappointed. - -Cheers! - - - --------------------------------------------------------------------------------- - -via: https://www.ostechnix.com/collection-useful-bash-scripts-heavy-commandline-users/ - -作者:[SK][a] -选题:[lujun9972](https://github.com/lujun9972) -译者:[译者ID](https://github.com/译者ID) -校对:[校对者ID](https://github.com/校对者ID) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 - -[a]:https://www.ostechnix.com/author/sk/ -[1]:https://www.ostechnix.com/linuxbrew-common-package-manager-linux-mac-os-x/ -[3]:http://www.ostechnix.com/wp-content/uploads/2017/07/sk@sk_001.png -[4]:http://www.ostechnix.com/wp-content/uploads/2017/07/sk@sk_002-1.png -[5]:http://www.ostechnix.com/wp-content/uploads/2017/07/sk@sk_003.png -[6]:https://tastedive.com/account/api_access -[7]:http://www.ostechnix.com/wp-content/uploads/2017/07/ytview-1.png -[8]:http://www.ostechnix.com/wp-content/uploads/2017/07/sk@sk_005.png -[9]:http://www.ostechnix.com/wp-content/uploads/2017/07/cryptocurrency.png -[10]:http://www.ostechnix.com/wp-content/uploads/2017/07/lyrics.png -[11]:http://www.ostechnix.com/wp-content/uploads/2017/07/newton.png -[12]:http://www.ostechnix.com/wp-content/uploads/2017/07/siteciphers.png diff --git a/sources/tech/20170829 An Advanced System Configuration Utility For Ubuntu Power Users.md b/sources/tech/20170829 An Advanced System Configuration Utility For Ubuntu Power Users.md deleted file mode 100644 index 5292c290cc..0000000000 --- a/sources/tech/20170829 An Advanced System Configuration Utility For Ubuntu Power Users.md +++ /dev/null @@ -1,139 +0,0 @@ -An Advanced System Configuration Utility For Ubuntu Power Users -====== - -![](https://www.ostechnix.com/wp-content/uploads/2017/08/Ubunsys-4-1-720x340.png) - -**Ubunsys** is a Qt-based advanced system utility for Ubuntu and its derivatives. Most of the configuration can be easily done from the command-line by the advanced users. Just in case, you don’t want to use CLI all the time, you can use Ubunsys utility to configure your Ubuntu desktop system or its derivatives such as Linux Mint, Elementary OS etc. Ubunsys can be used to modify system configuration, install, remove, update packages and old kernels, enable/disable sudo access, install mainline kernel, update software repositories, clean up junk files, upgrade your Ubuntu to latest version, and so on. All of the aforementioned actions can be done with simple mouse clicks. You don’t need to depend on CLI mode anymore. Here is the list of things you can do with Ubunsys: - - * Install, update, and remove packages. - * Update and upgrade software repositories. - * Install mainline Kernel. - * Remove old and unused Kernels. - * Full system update. - * Complete System upgrade to next available version. - * Upgrade to latest development version. - * Clean up junk files from your system. - * Enable and/or disable sudo access without password. - * Make Sudo Passwords visible when you type them in the Terminal. - * Enable and/or disable hibernation. - * Enable and/or disable firewall. - * Open, backup and import sources.list.d and sudoers files. - * Show/unshow hidden startup items. - * Enable and/or disable Login sounds. - * Configure dual boot. - * Enable/disable Lock screen. - * Smart system update. - * Update and/or run all scripts at once using Scripts Manager. - * Exec normal user installation script from git. - * Check system integrity and missing GPG keys. - * Repair network. - * Fix broken packages. - * And more yet to come. - - - -**Important note:** Ubunsys is not for Ubuntu beginners. It is dangerous and not a stable version yet. It might break your system. If you’re a new to Ubuntu, don’t use it. If you are very curious to use this application, go through each option carefully and proceed at your own risk. Do not forget to backup your important data before using this application. - -### Ubunsys – An Advanced System Configuration Utility For Ubuntu Power Users - -#### Install Ubunsys - -Ubunusys developer has made a PPA to make the installation process much easier. Ubunsys will currently work on Ubuntu 16.04 LTS, Ubuntu 17.04 64bit editions. - -Run the following commands one by one to add Ubunsys PPA and install it. -``` -sudo add-apt-repository ppa:adgellida/ubunsys - -sudo apt-get update - -sudo apt-get install ubunsys - -``` - -If the PPA doesn’t work, head over to the [**releases page**][1], download and install the Ubunsys package depending upon the architecture you use. - -#### Usage - -Once installed, launch Ubunsys from Menu. This is how Ubunsys main interface looks like. - -![][3] - -As you can see, Ubunusys has four main sections namely **Packages** , **Tweaks** , **System** , and **Repair**. There are one or more sub-sections available for each main tab to do different operations. - -**Packages** - -This section allows you to install, remove, update packages. - -![][4] - -**Tweaks** - -In this section, we can do various various system tweaks such as, - - * Open, backup, import sources.list and sudoers file; - * Configure dual boot; - * Enable/disable login sound, firewall, lock screen, hibernation, sudo access without password. You can also enable or disable for sudo access without password to specific users. - * Can make the passwords visible while typing them in Terminal (Disable Asterisks). - - - -![][5] - -**System** - -This section further categorized into three sub-categories, each for distinct user type. - -The **Normal user** tab allows us to, - - * Update, upgrade packages and software repos. - * Clean system. - * Exec normal user installation script. - - - -The **Advanced user** section allows us to, - - * Clean Old/Unused Kernels. - * Install mainline Kernel. - * do smart packages update. - * Upgrade system. - - - -The **Developer** section allows us to upgrade the Ubuntu system to latest development version. - -![][6] - -**Repair** - -This is the fourth and last section of Ubunsys. As the name says, this section allows us to do repair our system, network, missing GPG keys, and fix broken packages. - -![][7] - -As you can see, Ubunsys helps you to do any system configuration, maintenance and software management tasks with few mouse clicks. You don’t need to depend on Terminal anymore. Ubunsys can help you to accomplish any advanced tasks. Again, I warn you, It’s not for beginners and it is not stable yet. So, you can expect bugs and crashes when using it. Use it with care after studying options and impact. - -Cheers! - -**Resource:** - - - --------------------------------------------------------------------------------- - -via: https://www.ostechnix.com/ubunsys-advanced-system-configuration-utility-ubuntu-power-users/ - -作者:[SK][a] -选题:[lujun9972](https://github.com/lujun9972) -译者:[译者ID](https://github.com/译者ID) -校对:[校对者ID](https://github.com/校对者ID) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 - -[a]:https://www.ostechnix.com/author/sk/ -[1]:https://github.com/adgellida/ubunsys/releases -[2]:data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7 -[3]:http://www.ostechnix.com/wp-content/uploads/2017/08/Ubunsys-1.png -[4]:http://www.ostechnix.com/wp-content/uploads/2017/08/Ubunsys-2.png -[5]:http://www.ostechnix.com/wp-content/uploads/2017/08/Ubunsys-5.png -[6]:http://www.ostechnix.com/wp-content/uploads/2017/08/Ubunsys-9.png -[7]:http://www.ostechnix.com/wp-content/uploads/2017/08/Ubunsys-11.png diff --git a/sources/tech/20171003 Trash-Cli - A Command Line Interface For Trashcan On Linux.md b/sources/tech/20171003 Trash-Cli - A Command Line Interface For Trashcan On Linux.md deleted file mode 100644 index 29902a588f..0000000000 --- a/sources/tech/20171003 Trash-Cli - A Command Line Interface For Trashcan On Linux.md +++ /dev/null @@ -1,145 +0,0 @@ -Trash-Cli : A Command Line Interface For Trashcan On Linux -====== -Everyone knows about `Trashcan` which is common for all users like Linux, or Windows, or Mac. Whenever you delete a file or folder, it will be moved to trash. - -Note that moving files to the trash does not free up space on the file system until the Trashcan is empty. - -Trash stores deleted files temporarily which help us to restore when it's necessary, if you don't want these files then delete it permanently (empty the trash). - -Make sure, you won't find any files or folders in the trash when you delete using `rm` command. So, think twice before performing rm command. If you did a mistake that's it, it'll go away and you can't restore back. since metadata is not stored on disk nowadays. - -Trash is a feature provided by the desktop manager such as GNOME, KDE, and XFCE, etc, as per [freedesktop.org specification][1]. when you delete a file or folder from file manger then it will go to trash and the trash folder can be found @ `$HOME/.local/share/Trash`. - -Trash folder contains two folder `files` & `info`. Files folder stores actual deleted files and folders & Info folder contains deleted files & folders information such as file path, deleted date & time in separate file. - -You might ask, Why you want CLI utility When having GUI Trashcan, most of the NIX guys (including me) play around CLI instead of GUI even though when they working GUI based system. So, if some one looking for CLI based Trashcan then this is the right choice for them. - -### What's Trash-Cli - -[trash-cli][2] is a command line interface for Trashcan utility compliant with the FreeDesktop.org trash specifications. It stores the name, original path, deletion date, and permissions of each trashed file. - -### How to Install Trash-Cli in Linux - -Trash-Cli is available on most of the Linux distribution official repository, so run the following command to install. - -For **`Debian/Ubuntu`** , use [apt-get command][3] or [apt command][4] to install Trash-Cli. -``` -$ sudo apt install trash-cli - -``` - -For **`RHEL/CentOS`** , use [YUM Command][5] to install Trash-Cli. -``` -$ sudo yum install trash-cli - -``` - -For **`Fedora`** , use [DNF Command][6] to install Trash-Cli. -``` -$ sudo dnf install trash-cli - -``` - -For **`Arch Linux`** , use [Pacman Command][7] to install Trash-Cli. -``` -$ sudo pacman -S trash-cli - -``` - -For **`openSUSE`** , use [Zypper Command][8] to install Trash-Cli. -``` -$ sudo zypper in trash-cli - -``` - -If you distribution doesn't offer Trash-cli, we can easily install from pip. Your system should have pip package manager, in order to install python packages. -``` -$ sudo pip install trash-cli -Collecting trash-cli - Downloading trash-cli-0.17.1.14.tar.gz -Installing collected packages: trash-cli - Running setup.py bdist_wheel for trash-cli ... done -Successfully installed trash-cli-0.17.1.14 - -``` - -### How to Use Trash-Cli - -It's not a big deal since it's offering native syntax. It provides following commands. - - * **`trash-put:`** Delete files and folders. - * **`trash-list:`** Pint Deleted files and folders. - * **`trash-restore:`** Restore a file or folder from trash. - * **`trash-rm:`** Remove individual files from the trashcan. - * **`trash-empty:`** Empty the trashcan(s). - - - -Let's try some examples to experiment this. - -1) Delete files and folders : In our case, we are going to send a file named `2g.txt` and folder named `magi` to Trash by running following command. -``` -$ trash-put 2g.txt magi - -``` - -You can see the same in file manager. - -2) Pint Delete files and folders : To view deleted files and folders, run the following command. As i can see detailed infomation about deleted files and folders such as name, date & time, and file path. -``` -$ trash-list -2017-10-01 01:40:50 /home/magi/magi/2g.txt -2017-10-01 01:40:50 /home/magi/magi/magi - -``` - -3) Restore a file or folder from trash : At any point of time you can restore a files and folders by running following command. It will ask you to enter the choice which you want to restore. In our case, we are going to restore `2g.txt` file, so my option is `0`. -``` -$ trash-restore - 0 2017-10-01 01:40:50 /home/magi/magi/2g.txt - 1 2017-10-01 01:40:50 /home/magi/magi/magi -What file to restore [0..1]: 0 - -``` - -4) Remove individual files from the trashcan : If you want to remove specific files from trashcan, run the following command. In our case, we are going to remove `magi` folder. -``` -$ trash-rm magi - -``` - -5) Empty the trashcan : To remove everything from the trashcan, run the following command. -``` -$ trash-empty - -``` - -6) Remove older then X days file : Alternatively you can remove older then X days files so, run the following command to do it. In our case, we are going to remove `10` days old items from trashcan. -``` -$ trash-empty 10 - -``` - -trash-cli works great but if you want to try alternative, give a try to [gvfs-trash][9] & [autotrash][10] - --------------------------------------------------------------------------------- - -via: https://www.2daygeek.com/trash-cli-command-line-trashcan-linux-system/ - -作者:[2daygeek][a] -译者:[译者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/2daygeek/ -[1]:https://freedesktop.org/wiki/Specifications/trash-spec/ -[2]:https://github.com/andreafrancia/trash-cli -[3]:https://www.2daygeek.com/apt-get-apt-cache-command-examples-manage-packages-debian-ubuntu-systems/ -[4]:https://www.2daygeek.com/apt-command-examples-manage-packages-debian-ubuntu-systems/ -[5]:https://www.2daygeek.com/yum-command-examples-manage-packages-rhel-centos-systems/ -[6]:https://www.2daygeek.com/dnf-command-examples-manage-packages-fedora-system/ -[7]:https://www.2daygeek.com/pacman-command-examples-manage-packages-arch-linux-system/ -[8]:https://www.2daygeek.com/zypper-command-examples-manage-packages-opensuse-system/ -[9]:http://manpages.ubuntu.com/manpages/trusty/man1/gvfs-trash.1.html -[10]:https://github.com/bneijt/autotrash diff --git a/sources/tech/20171005 10 Games You Can Play on Linux with Wine.md b/sources/tech/20171005 10 Games You Can Play on Linux with Wine.md index 5bab9d8c65..37b1adb669 100644 --- a/sources/tech/20171005 10 Games You Can Play on Linux with Wine.md +++ b/sources/tech/20171005 10 Games You Can Play on Linux with Wine.md @@ -1,3 +1,4 @@ +### fuzheng1998 translating 10 Games You Can Play on Linux with Wine ====== ![](https://www.maketecheasier.com/assets/uploads/2017/09/wine-games-feat.jpg) diff --git a/sources/tech/20171012 7 Best eBook Readers for Linux.md b/sources/tech/20171012 7 Best eBook Readers for Linux.md index 5198f1bdc0..128c667d88 100644 --- a/sources/tech/20171012 7 Best eBook Readers for Linux.md +++ b/sources/tech/20171012 7 Best eBook Readers for Linux.md @@ -1,3 +1,4 @@ +Translating by bayar199468 7 Best eBook Readers for Linux ====== **Brief:** In this article, we are covering some of the best ebook readers for Linux. These apps give a better reading experience and some will even help in managing your ebooks. diff --git a/sources/tech/20171022 Review- Algorithms to Live By by Brian Christian - Tom Griffiths.md b/sources/tech/20171022 Review- Algorithms to Live By by Brian Christian - Tom Griffiths.md deleted file mode 100644 index edd1844f71..0000000000 --- a/sources/tech/20171022 Review- Algorithms to Live By by Brian Christian - Tom Griffiths.md +++ /dev/null @@ -1,44 +0,0 @@ -Review: Algorithms to Live By -====== -![](https://www.eyrie.org/~eagle/reviews/covers/1-62779-037-3.jpg) - -Another read for the work book club. This was my favorite to date, apart from the books I recommended myself. - -One of the foundations of computer science as a field of study is research into algorithms: how do we solve problems efficiently using computer programs? This is a largely mathematical field, but it's often less about ideal or theoretical solutions and more about making the most efficient use of limited resources and arriving at an adequate, if not perfect, answer. Many of these problems are either day-to-day human problems or are closely related to them; after all, the purpose of computer science is to solve practical problems with computers. The question asked by Algorithms to Live By is "can we reverse this?": can we learn lessons from computer science's approach to problems that would help us make day-to-day decisions? - -There's a lot of interesting material in the eleven chapters of this book, but there's also an amusing theme: humans are already very good at this. Many chapters start with an examination of algorithms and mathematical analysis of problems, dive into a discussion of how we can use those results to make better decisions, then talk about studies of the decisions humans actually make... and discover that humans are already applying ad hoc versions of the best algorithms we've come up with, given the constraints of typical life situations. It tends to undermine the stated goal of the book. Thankfully, it in no way undermines interesting discussion of general classes of problems, how computer science has tackled them, and what we've learned about the mathematical and technical shapes of those problems. There's a bit less self-help utility here than I think the authors had intended, but lots of food for thought. - -(That said, it's worth considering whether this congruence is less because humans are already good at this and more because our algorithms are designed from human intuition. Maybe our best algorithms just reflect human thinking. In some cases we've checked our solutions against mathematical ideals, but in other cases they're still just our best guesses to date.) - -This is the sort of a book where a chapter listing is an important part of the review. The areas of algorithms discussed here are optimal stopping, explore/exploit decisions (when to go with the best thing you've found and when to look for something better), sorting, caching, scheduling, Bayes's rule (and prediction in general), overfitting when building models, relaxation (solving an easier problem than your actual problem), randomized algorithms, a collection of networking algorithms, and finally game theory. Each of these has useful insights and thought-provoking discussion of how these sometimes-theoretical concepts map surprisingly well onto daily problems. The book concludes with a discussion of "computational kindness": an encouragement to reduce the required computation and complexity penalty for both yourself and the people you interact with. - -If you have a computer science background (as I do), many of these will be familiar concepts, and you might be dubious that a popularization would tell you much that's new. Give this book a shot, though; the analogies are less stretched than you might fear, and the authors are both careful and smart about how they apply these principles. This book passes with flying colors a key sanity check: the chapters on topics that I know well or have thought about a lot make few or no obvious errors and say useful and important things. For example, the scheduling chapter, which unsurprisingly is about time management, surpasses more than half of the time management literature by jumping straight to the heart of most time management problems: if you're going to do everything on a list, it rarely matters the order in which you do it, so the hardest scheduling problems are about deciding what not to do rather than deciding order. - -The point in the book where the authors won my heart completely was in the chapter on Bayes's rule. Much of the chapter is about Bayesian priors, and how one's knowledge of past events is a vital part of analysis of future probabilities. The authors then discuss the (in)famous marshmallow experiment, in which children are given one marshmallow and told that if they refrain from eating it until the researcher returns, they'll get two marshmallows. Refraining from eating the marshmallow (delayed gratification, in the psychological literature) was found to be associated with better life outcomes years down the road. This experiment has been used and abused for years for all sorts of propaganda about how trading immediate pleasure for future gains leads to a successful life, and how failure in life is because of inability to delay gratification. More evil analyses have (of course) tied that capability to ethnicity, with predictably racist results. - -I have [kind of a thing][1] about the marshmallow experiment. It's a topic that reliably sends me off into angry rants. - -Algorithms to Live By is the only book I have ever read to mention the marshmallow experiment and then apply the analysis that I find far more convincing. This is not a test of innate capability in the children; it's a test of their Bayesian priors. When does it make perfect sense to eat the marshmallow immediately instead of waiting for a reward? When their past experience tells them that adults are unreliable, can't be trusted, disappear for unpredictable lengths of time, and lie. And, even better, the authors supported this analysis with both a follow-up study I hadn't heard of before and with the observation that some children would wait for some time and then "give in." This makes perfect sense if they were subconsciously using a Bayesian model with poor priors. - -This is a great book. It may try a bit too hard in places (applicability of the math of optimal stopping to everyday life is more contingent and strained than I think the authors want to admit), and some of this will be familiar if you've studied algorithms. But the writing is clear, succinct, and very well-edited. No part of the book outlives its welcome; the discussion moves right along. If you find yourself going "I know all this already," you'll still probably encounter a new concept or neat explanation in a few more pages. And sometimes the authors make connections that never would have occurred to me but feel right in retrospect, such as relating exponential backoff in networking protocols to choosing punishments in the criminal justice system. Or the realization that our modern communication world is not constantly connected, it's constantly buffered, and many of us are suffering from the characteristic signs of buffer bloat. - -I don't think you have to be a CS major, or know much about math, to read this book. There is a lot of mathematical details in the end notes if you want to dive in, but the main text is almost always readable and clear, at least so far as I could tell (as someone who was a CS major and has taken a lot of math, so a grain of salt may be indicated). And it still has a lot to offer even if you've studied algorithms for years. - -The more I read of this book, the more I liked it. Definitely recommended if you like reading this sort of analysis of life. - -Rating: 9 out of 10 - -Reviewed: 2017-10-22 - --------------------------------------------------------------------------------- - -via: https://www.eyrie.org/~eagle/reviews/books/1-62779-037-3.html - -作者:[Brian Christian;Tom Griffiths][a] -译者:[译者ID](https://github.com/译者ID) -校对:[校对者ID](https://github.com/校对者ID) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 - -[a]:https://www.eyrie.org -[1]:https://www.eyrie.org1-59184-679-X.html diff --git a/sources/tech/20171101 Linux command line tools for working with non-Linux users.md b/sources/tech/20171101 Linux command line tools for working with non-Linux users.md deleted file mode 100644 index 23d87f6231..0000000000 --- a/sources/tech/20171101 Linux command line tools for working with non-Linux users.md +++ /dev/null @@ -1,69 +0,0 @@ -Linux command line tools for working with non-Linux users -====== -![](https://images.techhive.com/images/article/2016/06/linux-shell-100666628-large.jpg) -I spend most of my computing life in the Shell (command line, terminal or whatever you want to call it on your platform of choice). This can be a bit challenging, though, when I need to work with large groups of other people, especially in big enterprise companies that -- well -- use anything but the Shell. - -The problems that crop up are made worse when other people within your company use a different platform than you. I tend to use Linux. If I'm doing a lot of my daily work from a Linux terminal and the bulk of my co-workers use Windows 10 (entirely from the GUI side), things can get … problematic. - - **Also on Network World:**[ **11 pointless but awesome Linux terminal tricks**][1] - -Luckily, over the past few years, I've figured out how to deal with these problems. I've found ways to make using a Linux (or other Unix-like systems) Shell much more doable within a non-Unix, corporate environment. These tools/tips apply equally well for SysAdmins working on a company's servers as they do for developers or marketing people. - -## Command line tools for working with non-Linux users - -Let's start by focusing on the two areas that seem to be the hardest to solve for many people in big companies: document compatibility and enterprise instant messaging. - -### Document compatibility between Linux and non-Linux systems - -One of the biggest issues that crops up is that of simple word processing document compatibility. - -Let's say your company has standardized on Microsoft Office. This makes you sad. But do not lose hope! There are ways to make this (mostly) work -- even from the Shell. - -Two tools are critical in my arsenal: [Pandoc][2] and [Wordgrinder][3]. - -Wordgrinder is a simple, straight-to-the-point word processor. It may not be as full-featured as LibreOffice (or, really, any major GUI word-processing application), but it's fast. It's stable. And it supports just enough features (and file formats) to get the job done. In fact, I write the majority of my articles and books entirely in Wordgrinder. - -But there's a problem (you knew there had to be). - -Wordgrinder doesn't support .doc (or .docx) files. That means it can't read most files that your Windows- and MS Office-using co-workers send you. - -That's where Pandoc comes in. It's a simple document converter that takes a wide range of files as input (MS Word, LibreOffice, HTML, markdown, etc.) and converts them to something else. The number of formats supported here is absolutely phenomenal -- PDF, ePub, various slideshow formats. It really makes converting documents between formats a breeze. - -That's not to say I don't occasionally encounter formatting or feature issues. Converting a Word document that has a lot of custom formatting, some scripting, and an embedded chart? Yeah, a lot of that will be lost in the process. - -But in practical terms, the combination of Pandoc (for converting files) and Wordgrinder (for document editing) has proven quite capable and powerful. - -### Corporate instant messaging between Linux and non-Linux systems - -Every company likes to standardize on an instant messaging system -- something for all employees to use to keep in real-time contact. - -From the command line, this can get tricky. What if your company uses Google Hangouts? Or how about Novell GroupWise Messenger? Neither have officially supported, terminal-based clients. - -Thank goodness, then, for [Finch & Hangups][4]. - -Finch is sort of the terminal version of Pidgin (the open-source, multi-protocol messenger client). It supports a wide variety of protocols, including Novell GroupWise, (the soon to be dead) AOL Instant Messenger, and a bunch of others. - -And Hangups is an open implementation of a Google Hangouts client -- complete with message history and a nice tabbed interface. - -Neither of these solutions will provide you with voice or video chat capabilities, but for text-based messaging, they work delightfully well. They aren't perfect (the user interface of Finch takes some getting used to), but they're definitely good enough to keep in touch with your co-workers. - -Will these solutions allow you to spend your entire work day within the comforts of a text-only Shell? Probably not. Personally, I find that (with these tools, and others) I can comfortably spend roughly 80 percent of my day in a text-only interface. - -Which feels pretty darn great. - - --------------------------------------------------------------------------------- - -via: https://www.networkworld.com/article/3235688/linux/linux-command-line-tools-for-working-with-non-linux-users.html - -作者:[Bryan Lunduke][a] -译者:[译者ID](https://github.com/译者ID) -校对:[校对者ID](https://github.com/校对者ID) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 - -[a]:https://www.networkworld.com/author/Bryan-Lunduke/ -[1]:http://www.networkworld.com/article/2926630/linux/11-pointless-but-awesome-linux-terminal-tricks.html#tk.nww-fsb -[2]:https://www.youtube.com/watch?v=BkTYHChkDoE -[3]:https://www.youtube.com/watch?v=WnMyamBgKFE -[4]:https://www.youtube.com/watch?v=19lbWnYOsTc diff --git a/sources/tech/20171111 A CEOs Guide to Emacs.md b/sources/tech/20171111 A CEOs Guide to Emacs.md index ad75b856f0..a694d07917 100644 --- a/sources/tech/20171111 A CEOs Guide to Emacs.md +++ b/sources/tech/20171111 A CEOs Guide to Emacs.md @@ -1,4 +1,4 @@ -# mandeler translating A CEO's Guide to Emacs +A CEO's Guide to Emacs ============================================================ Years—no, decades—ago, I lived in Emacs. I wrote code and documents, managed email and calendar, and shelled all in the editor/OS. I was quite happy. Years went by and I moved to newer, shinier things. As a result, I forgot how to do tasks as basic as efficiently navigating files without a mouse. About three months ago, noticing just how much of my time was spent switching between applications and computers, I decided to give Emacs another try. It was a good decision for several reasons that will be covered in this post. Covered too are `.emacs` and Dropbox tips so that you can set up a good, movable environment. diff --git a/sources/tech/20171124 How do groups work on Linux.md b/sources/tech/20171124 How do groups work on Linux.md deleted file mode 100644 index bc1833b0d6..0000000000 --- a/sources/tech/20171124 How do groups work on Linux.md +++ /dev/null @@ -1,141 +0,0 @@ -How do groups work on Linux? -============================================================ - -Hello! Last week, I thought I knew how users and groups worked on Linux. Here is what I thought: - -1. Every process belongs to a user (like `julia`) - -2. When a process tries to read a file owned by a group, Linux a) checks if the user `julia` can access the file, and b) checks which groups `julia` belongs to, and whether any of those groups owns & can access that file - -3. If either of those is true (or if the ‘any’ bits are set right) then the process can access the file - -So, for example, if a process is owned by the `julia` user and `julia` is in the `awesome` group, then the process would be allowed to read this file. - -``` -r--r--r-- 1 root awesome 6872 Sep 24 11:09 file.txt - -``` - -I had not thought carefully about this, but if pressed I would have said that it probably checks the `/etc/group` file at runtime to see what groups you’re in. - -### that is not how groups work - -I found out at work last week that, no, what I describe above is not how groups work. In particular Linux does **not** check which groups a process’s user belongs to every time that process tries to access a file. - -Here is how groups actually work! I learned this by reading Chapter 9 (“Process Credentials”) of [The Linux Programming Interface][1] which is an incredible book. As soon as I realized that I did not understand how users and groups worked, I opened up the table of contents with absolute confidence that it would tell me what’s up, and I was right. - -### how users and groups checks are done - -They key new insight for me was pretty simple! The chapter starts out by saying that user and group IDs are **attributes of the process**: - -* real user ID and group ID; - -* effective user ID and group ID; - -* saved set-user-ID and saved set-group-ID; - -* file-system user ID and group ID (Linux-specific); and - -* supplementary group IDs. - -This means that the way Linux **actually** does group checks to see a process can read a file is: - -* look at the process’s group IDs & supplementary group IDs (from the attributes on the process, **not** by looking them up in `/etc/group`) - -* look at the group on the file - -* see if they match - -Generally when doing access control checks it uses the **effective** user/group ID, not the real user/group ID. Technically when accessing a file it actually uses the **file-system** ids but those are usually the same as the effective uid/gid. - -### Adding a user to a group doesn’t put existing processes in that group - -Here’s another fun example that follows from this: if I create a new `panda` group and add myself (bork) to it, then run `groups` to check my group memberships – I’m not in the panda group! - -``` -bork@kiwi~> sudo addgroup panda -Adding group `panda' (GID 1001) ... -Done. -bork@kiwi~> sudo adduser bork panda -Adding user `bork' to group `panda' ... -Adding user bork to group panda -Done. -bork@kiwi~> groups -bork adm cdrom sudo dip plugdev lpadmin sambashare docker lxd - -``` - -no `panda` in that list! To double check, let’s try making a file owned by the `panda`group and see if I can access it: - -``` -$ touch panda-file.txt -$ sudo chown root:panda panda-file.txt -$ sudo chmod 660 panda-file.txt -$ cat panda-file.txt -cat: panda-file.txt: Permission denied - -``` - -Sure enough, I can’t access `panda-file.txt`. No big surprise there. My shell didn’t have the `panda` group as a supplementary GID before, and running `adduser bork panda` didn’t do anything to change that. - -### how do you get your groups in the first place? - -So this raises kind of a confusing question, right – if processes have groups baked into them, how do you get assigned your groups in the first place? Obviously you can’t assign yourself more groups (that would defeat the purpose of access control). - -It’s relatively clear how processes I **execute** from my shell (bash/fish) get their groups – my shell runs as me, and it has a bunch of group IDs on it. Processes I execute from my shell are forked from the shell so they get the same groups as the shell had. - -So there needs to be some “first” process that has your groups set on it, and all the other processes you set inherit their groups from that. That process is called your **login shell** and it’s run by the `login` program (`/bin/login`) on my laptop. `login` runs as root and calls a C function called `initgroups` to set up your groups (by reading `/etc/group`). It’s allowed to set up your groups because it runs as root. - -### let’s try logging in again! - -So! Let’s say I am running in a shell, and I want to refresh my groups! From what we’ve learned about how groups are initialized, I should be able to run `login` to refresh my groups and start a new login shell! - -Let’s try it: - -``` -$ sudo login bork -$ groups -bork adm cdrom sudo dip plugdev lpadmin sambashare docker lxd panda -$ cat panda-file.txt # it works! I can access the file owned by `panda` now! - -``` - -Sure enough, it works! Now the new shell that `login` spawned is part of the `panda` group! Awesome! This won’t affect any other shells I already have running. If I really want the new `panda` group everywhere, I need to restart my login session completely, which means quitting my window manager and logging in again. - -### newgrp - -Somebody on Twitter told me that if you want to start a new shell with a new group that you’ve been added to, you can use `newgrp`. Like this: - -``` -sudo addgroup panda -sudo adduser bork panda -newgrp panda # starts a new shell, and you don't have to be root to run it! - -``` - -You can accomplish the same(ish) thing with `sg panda bash` which will start a `bash` shell that runs with the `panda` group. - -### setuid sets the effective user ID - -I’ve also always been a little vague about what it means for a process to run as “setuid root”. It turns out that setuid sets the effective user ID! So if I (`julia`) run a setuid root process (like `passwd`), then the **real** user ID will be set to `julia`, and the **effective** user ID will be set to `root`. - -`passwd` needs to run as root, but it can look at its real user ID to see that `julia`started the process, and prevent `julia` from editing any passwords except for `julia`’s password. - -### that’s all! - -There are a bunch more details about all the edge cases and exactly how everything works in The Linux Programming Interface so I will not get into all the details here. That book is amazing. Everything I talked about in this post is from Chapter 9, which is a 17-page chapter inside a 1300-page book. - -The thing I love most about that book is that reading 17 pages about how users and groups work is really approachable, self-contained, super useful, and I don’t have to tackle all 1300 pages of it at once to learn helpful things :) - --------------------------------------------------------------------------------- - -via: https://jvns.ca/blog/2017/11/20/groups/ - -作者:[Julia Evans ][a] -译者:[译者ID](https://github.com/译者ID) -校对:[校对者ID](https://github.com/校对者ID) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 - -[a]:https://jvns.ca/ -[1]:http://man7.org/tlpi/ diff --git a/sources/tech/20171129 How to Install and Use Wireshark on Debian and Ubuntu 16.04_17.10.md b/sources/tech/20171129 How to Install and Use Wireshark on Debian and Ubuntu 16.04_17.10.md deleted file mode 100644 index ce2ed658a4..0000000000 --- a/sources/tech/20171129 How to Install and Use Wireshark on Debian and Ubuntu 16.04_17.10.md +++ /dev/null @@ -1,182 +0,0 @@ -How to Install and Use Wireshark on Debian 9 / Ubuntu 16.04 / 17.10 -============================================================ - -by [Pradeep Kumar][1] · Published November 29, 2017 · Updated November 29, 2017 - - [![wireshark-Debian-9-Ubuntu 16.04 -17.10](https://www.linuxtechi.com/wp-content/uploads/2017/11/wireshark-Debian-9-Ubuntu-16.04-17.10.jpg)][2] - -Wireshark is free and open source, cross platform, GUI based Network packet analyzer that is available for Linux, Windows, MacOS, Solaris etc. It captures network packets in real time & presents them in human readable format. Wireshark allows us to monitor the network packets up to microscopic level. Wireshark also has a command line utility called ‘tshark‘ that performs the same functions as Wireshark but through terminal & not through GUI. - -Wireshark can be used for network troubleshooting, analyzing, software & communication protocol development & also for education purposed. Wireshark uses a library called ‘pcap‘ for capturing the network packets. - -Wireshark comes with a lot of features & some those features are; - -* Support for a hundreds of protocols for inspection, - -* Ability to capture packets in real time & save them for later offline analysis, - -* A number of filters to analyzing data, - -* Data captured can be compressed & uncompressed on the fly, - -* Various file formats for data analysis supported, output can also be saved to XML, CSV, plain text formats, - -* data can be captured from a number of interfaces like ethernet, wifi, bluetooth, USB, Frame relay , token rings etc. - -In this article, we will discuss how to install Wireshark on Ubuntu/Debain machines & will also learn to use Wireshark for capturing network packets. - -#### Installation of Wireshark on Ubuntu 16.04 / 17.10 - -Wireshark is available with default Ubuntu repositories & can be simply installed using the following command. But there might be chances that you will not get the latest version of wireshark. - -``` -linuxtechi@nixworld:~$ sudo apt-get update -linuxtechi@nixworld:~$ sudo apt-get install wireshark -y -``` - -So to install latest version of wireshark we have to enable or configure official wireshark repository. - -Use the beneath commands one after the another to configure repository and to install latest version of Wireshark utility - -``` -linuxtechi@nixworld:~$ sudo add-apt-repository ppa:wireshark-dev/stable -linuxtechi@nixworld:~$ sudo apt-get update -linuxtechi@nixworld:~$ sudo apt-get install wireshark -y -``` - -Once the Wireshark is installed execute the below command so that non-root users can capture live packets of interfaces, - -``` -linuxtechi@nixworld:~$ sudo setcap 'CAP_NET_RAW+eip CAP_NET_ADMIN+eip' /usr/bin/dumpcap -``` - -#### Installation of Wireshark on Debian 9 - -Wireshark package and its dependencies are already present in the default debian 9 repositories, so to install latest and stable version of Wireshark on Debian 9, use the following command: - -``` -linuxtechi@nixhome:~$ sudo apt-get update -linuxtechi@nixhome:~$ sudo apt-get install wireshark -y -``` - -During the installation, it will prompt us to configure dumpcap for non-superusers, - -Select ‘yes’ and then hit enter. - - [![Configure-Wireshark-Debian9](https://www.linuxtechi.com/wp-content/uploads/2017/11/Configure-Wireshark-Debian9-1024x542.jpg)][3] - -Once the Installation is completed, execute the below command so that non-root users can also capture the live packets of the interfaces. - -``` -linuxtechi@nixhome:~$ sudo chmod +x /usr/bin/dumpcap -``` - -We can also use the latest source package to install the wireshark on Ubuntu/Debain & many other Linux distributions. - -#### Installing Wireshark using source code on Debian / Ubuntu Systems - -Firstly download the latest source package (which is 2.4.2 at the time for writing this article), use the following command, - -``` -linuxtechi@nixhome:~$ wget https://1.as.dl.wireshark.org/src/wireshark-2.4.2.tar.xz -``` - -Next extract the package & enter into the extracted directory, - -``` -linuxtechi@nixhome:~$ tar -xf wireshark-2.4.2.tar.xz -C /tmp -linuxtechi@nixhome:~$ cd /tmp/wireshark-2.4.2 -``` - -Now we will compile the code with the following commands, - -``` -linuxtechi@nixhome:/tmp/wireshark-2.4.2$ ./configure --enable-setcap-install -linuxtechi@nixhome:/tmp/wireshark-2.4.2$ make -``` - -Lastly install the compiled packages to install Wireshark on the system, - -``` -linuxtechi@nixhome:/tmp/wireshark-2.4.2$ sudo make install -linuxtechi@nixhome:/tmp/wireshark-2.4.2$ sudo ldconfig -``` - -Upon installation a separate group for Wireshark will also be created, we will now add our user to the group so that it can work with wireshark otherwise you might get ‘permission denied‘ error when starting wireshark. - -To add the user to the wireshark group, execute the following command, - -``` -linuxtechi@nixhome:~$ sudo usermod -a -G wireshark linuxtechi -``` - -Now we can start wireshark either from GUI Menu or from terminal with this command, - -``` -linuxtechi@nixhome:~$ wireshark -``` - -#### Access Wireshark on Debian 9 System - - [![Access-wireshark-debian9](https://www.linuxtechi.com/wp-content/uploads/2017/11/Access-wireshark-debian9-1024x664.jpg)][4] - -Click on Wireshark icon - - [![Wireshark-window-debian9](https://www.linuxtechi.com/wp-content/uploads/2017/11/Wireshark-window-debian9-1024x664.jpg)][5] - -#### Access Wireshark on Ubuntu 16.04 / 17.10 - - [![Access-wireshark-Ubuntu](https://www.linuxtechi.com/wp-content/uploads/2017/11/Access-wireshark-Ubuntu-1024x664.jpg)][6] - -Click on Wireshark icon - - [![Wireshark-window-Ubuntu](https://www.linuxtechi.com/wp-content/uploads/2017/11/Wireshark-window-Ubuntu-1024x664.jpg)][7] - -#### Capturing and Analyzing packets - -Once the wireshark has been started, we should be presented with the wireshark window, example is shown above for Ubuntu and Debian system. - - [![wireshark-Linux-system](https://www.linuxtechi.com/wp-content/uploads/2017/11/wireshark-Linux-system.jpg)][8] - -All these are the interfaces from where we can capture the network packets. Based on the interfaces you have on your system, this screen might be different for you. - -We are selecting ‘enp0s3’ for capturing the network traffic for that inteface. After selecting the inteface, network packets for all the devices on our network start to populate (refer to screenshot below) - - [![Capturing-Packet-from-enp0s3-Ubuntu-Wireshark](https://www.linuxtechi.com/wp-content/uploads/2017/11/Capturing-Packet-from-enp0s3-Ubuntu-Wireshark-1024x727.jpg)][9] - -First time we see this screen we might get overwhelmed by the data that is presented in this screen & might have thought how to sort out this data but worry not, one the best features of Wireshark is its filters. - -We can sort/filter out the data based on IP address, Port number, can also used source & destination filters, packet size etc & can also combine 2 or more filters together to create more comprehensive searches. We can either write our filters in ‘Apply a Display Filter‘ tab , or we can also select one of already created rules. To select pre-built filter, click on ‘flag‘ icon , next to ‘Apply a Display Filter‘ tab, - - [![Filter-in-wireshark-Ubuntu](https://www.linuxtechi.com/wp-content/uploads/2017/11/Filter-in-wireshark-Ubuntu-1024x727.jpg)][10] - -We can also filter data based on the color coding, By default, light purple is TCP traffic, light blue is UDP traffic, and black identifies packets with errors , to see what these codes mean, click View -> Coloring Rules, also we can change these codes. - - [![Packet-Colouring-Wireshark](https://www.linuxtechi.com/wp-content/uploads/2017/11/Packet-Colouring-Wireshark-1024x682.jpg)][11] - -After we have the results that we need, we can then click on any of the captured packets to get more details about that packet, this will show all the data about that network packet. - -Wireshark is an extremely powerful tool takes some time to getting used to & make a command over it, this tutorial will help you get started. Please feel free to drop in your queries or suggestions in the comment box below. - --------------------------------------------------------------------------------- - -via: https://www.linuxtechi.com - -作者:[Pradeep Kumar][a] -译者:[译者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/ -[1]:https://www.linuxtechi.com/author/pradeep/ -[2]:https://www.linuxtechi.com/wp-content/uploads/2017/11/wireshark-Debian-9-Ubuntu-16.04-17.10.jpg -[3]:https://www.linuxtechi.com/wp-content/uploads/2017/11/Configure-Wireshark-Debian9.jpg -[4]:https://www.linuxtechi.com/wp-content/uploads/2017/11/Access-wireshark-debian9.jpg -[5]:https://www.linuxtechi.com/wp-content/uploads/2017/11/Wireshark-window-debian9.jpg -[6]:https://www.linuxtechi.com/wp-content/uploads/2017/11/Access-wireshark-Ubuntu.jpg -[7]:https://www.linuxtechi.com/wp-content/uploads/2017/11/Wireshark-window-Ubuntu.jpg -[8]:https://www.linuxtechi.com/wp-content/uploads/2017/11/wireshark-Linux-system.jpg -[9]:https://www.linuxtechi.com/wp-content/uploads/2017/11/Capturing-Packet-from-enp0s3-Ubuntu-Wireshark.jpg -[10]:https://www.linuxtechi.com/wp-content/uploads/2017/11/Filter-in-wireshark-Ubuntu.jpg -[11]:https://www.linuxtechi.com/wp-content/uploads/2017/11/Packet-Colouring-Wireshark.jpg diff --git a/sources/tech/20171130 Google launches TensorFlow-based vision recognition kit for RPi Zero W.md b/sources/tech/20171130 Google launches TensorFlow-based vision recognition kit for RPi Zero W.md deleted file mode 100644 index 5bf32964e4..0000000000 --- a/sources/tech/20171130 Google launches TensorFlow-based vision recognition kit for RPi Zero W.md +++ /dev/null @@ -1,85 +0,0 @@ -# [Google launches TensorFlow-based vision recognition kit for RPi Zero W][26] - - -![](http://linuxgizmos.com/files/google_aiyvisionkit-thm.jpg) -Google’s $45 “AIY Vision Kit” for the Raspberry Pi Zero W performs TensorFlow-based vision recognition using a “VisionBonnet” board with a Movidius chip. - -Google’s AIY Vision Kit for on-device neural network acceleration follows an earlier [AIY Projects][7] voice/AI kit for the Raspberry Pi that shipped to MagPi subscribers back in May. Like the voice kit and the older Google Cardboard VR viewer, the new AIY Vision Kit has a cardboard enclosure. The kit differs from the [Cloud Vision API][8], which was demo’d in 2015 with a Raspberry Pi based GoPiGo robot, in that it runs entirely on local processing power rather than requiring a cloud connection. The AIY Vision Kit is available now for pre-order at $45, with shipments due in early December. - - - [![](http://linuxgizmos.com/files/google_aiyvisionkit-sm.jpg)][9]   [![](http://linuxgizmos.com/files/rpi_zerow-sm.jpg)][10] -**AIY Vision Kit, fully assembled (left) and Raspberry Pi Zero W** -(click images to enlarge) - - -The kit’s key processing element, aside from the 1GHz ARM11-based Broadcom BCM2836 SoC found on the required [Raspberry Pi Zero W][21] SBC, is Google’s new VisionBonnet RPi accessory board. The VisionBonnet pHAT board uses a Movidius MA2450, a version of the [Movidius Myriad 2 VPU][22] processor. On the VisionBonnet, the processor runs Google’s open source [TensorFlow][23]machine intelligence library for neural networking. The chip enables visual perception processing at up to 30 frames per second. - -The AIY Vision Kit requires a user-supplied RPi Zero W, a [Raspberry Pi Camera v2][11], and a 16GB micro SD card for downloading the Linux-based image. The kit includes the VisionBonnet, an RGB arcade-style button, a piezo speaker, a macro/wide lens kit, and the cardboard enclosure. You also get flex cables, standoffs, a tripod mounting nut, and connecting components. - - - [![](http://linuxgizmos.com/files/google_aiyvisionkit_pieces-sm.jpg)][12]   [![](http://linuxgizmos.com/files/google_visionbonnet-sm.jpg)][13] -**AIY Vision Kit kit components (left) and VisonBonnet accessory board** -(click images to enlarge) - - -Three neural network models are available. There’s a general-purpose model that can recognize 1,000 common objects, a facial detection model that can also score facial expression on a “joy scale” that ranges from “sad” to “laughing,” and a model that can identify whether the image contains a dog, cat, or human. The 1,000-image model derives from Google’s open source [MobileNets][24], a family of TensorFlow based computer vision models designed for the restricted resources of a mobile or embedded device. - -MobileNet models offer low latency and low power consumption, and are parameterized to meet the resource constraints of different use cases. The models can be built for classification, detection, embeddings, and segmentation, says Google. Earlier this month, Google released a developer preview of a mobile-friendly [TensorFlow Lite][14] library for Android and iOS that is compatible with MobileNets and the Android Neural Networks API. - - - [![](http://linuxgizmos.com/files/google_aiyvisionkit_assembly-sm.jpg)][15] -**AIY Vision Kit assembly views** -(click image to enlarge) - - -In addition to providing the three models, the AIY Vision Kit provides basic TensorFlow code and a compiler, so users can develop their own models. In addition, Python developers can write new software to customize RGB button colors, piezo element sounds, and 4x GPIO pins on the VisionBonnet that can add additional lights, buttons, or servos. Potential models include recognizing food items, opening a dog door based on visual input, sending a text when your car leaves the driveway, or playing particular music based on facial recognition of a person entering the camera’s viewpoint. - - - [![](http://linuxgizmos.com/files/movidius_myriad2vpu_block-sm.jpg)][16]   [![](http://linuxgizmos.com/files/movidius_myriad2_reference_board-sm.jpg)][17] -**Myriad 2 VPU block diagram (left) and reference board** -(click image to enlarge) - - -The Movidius Myriad 2 processor provides TeraFLOPS of performance within a nominal 1 Watt power envelope. The chip appeared on early Project Tango reference platforms, and is built into the Ubuntu-driven [Fathom][25] neural processing USB stick that Movidius debuted in May 2016, prior to being acquired by Intel. According to Movidius, the Myriad 2 is available “in millions of devices on the market today.” - -**Further information** - -The AIY Vision Kit is available for pre-order from Micro Center at $44.99, with shipments due in early December. More information may be found in the AIY Vision Kit [announcement][18], [Google Blog notice][19], and [Micro Center shopping page][20]. - --------------------------------------------------------------------------------- - -via: http://linuxgizmos.com/google-launches-tensorflow-based-vision-recognition-kit-for-rpi-zero-w/ - -作者:[ Eric Brown][a] -译者:[译者ID](https://github.com/译者ID) -校对:[校对者ID](https://github.com/校对者ID) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 - -[a]:http://linuxgizmos.com/google-launches-tensorflow-based-vision-recognition-kit-for-rpi-zero-w/ -[1]:http://twitter.com/share?url=http://linuxgizmos.com/google-launches-tensorflow-based-vision-recognition-kit-for-rpi-zero-w/&text=Google%20launches%20TensorFlow-based%20vision%20recognition%20kit%20for%20RPi%20Zero%20W%20 -[2]:https://plus.google.com/share?url=http://linuxgizmos.com/google-launches-tensorflow-based-vision-recognition-kit-for-rpi-zero-w/ -[3]:http://www.facebook.com/sharer.php?u=http://linuxgizmos.com/google-launches-tensorflow-based-vision-recognition-kit-for-rpi-zero-w/ -[4]:http://www.linkedin.com/shareArticle?mini=true&url=http://linuxgizmos.com/google-launches-tensorflow-based-vision-recognition-kit-for-rpi-zero-w/ -[5]:http://reddit.com/submit?url=http://linuxgizmos.com/google-launches-tensorflow-based-vision-recognition-kit-for-rpi-zero-w/&title=Google%20launches%20TensorFlow-based%20vision%20recognition%20kit%20for%20RPi%20Zero%20W -[6]:mailto:?subject=Google%20launches%20TensorFlow-based%20vision%20recognition%20kit%20for%20RPi%20Zero%20W&body=%20http://linuxgizmos.com/google-launches-tensorflow-based-vision-recognition-kit-for-rpi-zero-w/ -[7]:http://linuxgizmos.com/free-raspberry-pi-voice-kit-taps-google-assistant-sdk/ -[8]:http://linuxgizmos.com/google-releases-cloud-vision-api-with-demo-for-pi-based-robot/ -[9]:http://linuxgizmos.com/files/google_aiyvisionkit.jpg -[10]:http://linuxgizmos.com/files/rpi_zerow.jpg -[11]:http://linuxgizmos.com/raspberry-pi-cameras-jump-to-8mp-keep-25-dollar-price/ -[12]:http://linuxgizmos.com/files/google_aiyvisionkit_pieces.jpg -[13]:http://linuxgizmos.com/files/google_visionbonnet.jpg -[14]:https://developers.googleblog.com/2017/11/announcing-tensorflow-lite.html -[15]:http://linuxgizmos.com/files/google_aiyvisionkit_assembly.jpg -[16]:http://linuxgizmos.com/files/movidius_myriad2vpu_block.jpg -[17]:http://linuxgizmos.com/files/movidius_myriad2_reference_board.jpg -[18]:https://blog.google/topics/machine-learning/introducing-aiy-vision-kit-make-devices-see/ -[19]:https://developers.googleblog.com/2017/11/introducing-aiy-vision-kit-add-computer.html -[20]:http://www.microcenter.com/site/content/Google_AIY.aspx?ekw=aiy&rd=1 -[21]:http://linuxgizmos.com/raspberry-pi-zero-w-adds-wifi-and-bluetooth-for-only-5-more/ -[22]:https://www.movidius.com/solutions/vision-processing-unit -[23]:https://www.tensorflow.org/ -[24]:https://research.googleblog.com/2017/06/mobilenets-open-source-models-for.html -[25]:http://linuxgizmos.com/usb-stick-brings-neural-computing-functions-to-devices/ -[26]:http://linuxgizmos.com/google-launches-tensorflow-based-vision-recognition-kit-for-rpi-zero-w/ diff --git a/sources/tech/20171202 Scrot Linux command-line screen grabs made simple.md b/sources/tech/20171202 Scrot Linux command-line screen grabs made simple.md deleted file mode 100644 index c1f3ee8cf6..0000000000 --- a/sources/tech/20171202 Scrot Linux command-line screen grabs made simple.md +++ /dev/null @@ -1,70 +0,0 @@ -# Scrot: Linux command-line screen grabs made simple - -by [Scott Nesbitt][a] · November 30, 2017 - -> Scrot is a basic, flexible tool that offers a number of handy options for taking screen captures from the Linux command line. - -[![Original photo by Rikki Endsley. CC BY-SA 4.0](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/community-penguins-osdc-lead.png?itok=BmqsAF4A)][1] - - - -There are great tools on the Linux desktop for taking screen captures, such as [KSnapshot][2] and [Shutter][3]. Even the simple utility that comes with the GNOME desktop does a pretty good job of capturing screens. But what if you rarely need to take screen captures? Or you use a Linux distribution without a built-in capture tool, or an older computer with limited resources? - -Turn to the command line and a little utility called [Scrot][4]. It does a fine job of taking simple screen captures, and it includes a few features that might surprise you. - -### Getting started with Scrot -Many Linux distributions come with Scrot already installed—to check, type `which scrot`. If it isn't there, you can install Scrot using your distro's package manager. If you're willing to compile the code, grab it [from GitHub][5]. - -To take a screen capture, crack open a terminal window and type `scrot [filename]`, where `[filename]` is the name of file to which you want to save the image (for example, `desktop.png`). If you don't include a name for the file, Scrot will create one for you, such as `2017-09-24-185009_1687x938_scrot.png`. (That filename isn't as descriptive it could be, is it? That's why it's better to add one to the command.) - -Running Scrot with no options takes a screen capture of your entire desktop. If you don't want to do that, Scrot lets you focus on smaller portions of your screen. - -### Taking a screen capture of a single window - -Tell Scrot to take a screen capture of a single window by typing `scrot -u [filename]`. - -The `-u` option tells Scrot to grab the window currently in focus. That's usually the terminal window you're working in, which might not be the one you want. - -To grab another window on your desktop, type `scrot -s [filename]`. - -The `-s` option lets you do one of two things: - -* select an open window, or - -* draw a rectangle around a window or a portion of a window to capture it. - -You can also set a delay, which gives you a little more time to select the window you want to capture. To do that, type `scrot -u -d [num] [filename]`. - -The `-d` option tells Scrot to wait before grabbing the window, and `[num]` is the number of seconds to wait. Specifying `-d 5` (wait five seconds) should give you enough time to choose a window. - -### More useful options - -Scrot offers a number of additional features (most of which I never use). The ones I find most useful include: - -* `-b` also grabs the window's border - -* `-t` grabs a window and creates a thumbnail of it. This can be useful when you're posting screen captures online. - -* `-c` creates a countdown in your terminal when you use the `-d` option. - -To learn about Scrot's other options, check out the its documentation by typing `man scrot` in a terminal window, or [read it online][6]. Then start snapping images of your screen. - -It's basic, but Scrot gets the job done nicely. - --------------------------------------------------------------------------------- - -via: https://opensource.com/article/17/11/taking-screen-captures-linux-command-line-scrot - -作者:[Scott Nesbitt][a] -译者:[译者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/scottnesbitt -[1]:https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/community-penguins-osdc-lead.png?itok=BmqsAF4A -[2]:https://www.kde.org/applications/graphics/ksnapshot/ -[3]:https://launchpad.net/shutter -[4]:https://github.com/dreamer/scrot -[5]:http://manpages.ubuntu.com/manpages/precise/man1/scrot.1.html -[6]:https://github.com/dreamer/scrot diff --git a/sources/tech/20180102 Top 7 open source project management tools for agile teams.md b/sources/tech/20180102 Top 7 open source project management tools for agile teams.md deleted file mode 100644 index 81eca56adb..0000000000 --- a/sources/tech/20180102 Top 7 open source project management tools for agile teams.md +++ /dev/null @@ -1,133 +0,0 @@ -Top 7 open source project management tools for agile teams -====== - -![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/BUSINESS_orgchart1.png?itok=tukiFj89) - -Opensource.com has surveyed the landscape of popular open source project management tools. We've done this before—but this year we've added a twist. This time, we're looking specifically at tools that support [agile][1] methodology, including related practices such as [Scrum][2], Lean, and Kanban. - -The growth of interest in and use of agile is why we've decided to focus on these types of tools this year. A majority of organizations—71%—say they [are using agile approaches][3] at least sometimes. In addition, agile projects are [28% more successful][4] than projects managed with traditional approaches. - -For this roundup, we looked at the project management tools we covered in [2014][5], [2015][6], and [2016][7] and plucked the ones that support agile, then did research to uncover any additions or changes. Whether your organization is already using agile or is one of the many planning to adopt agile approaches in 2018, one of these seven open source project management tools may be exactly what you're looking for. - -### MyCollab - -![](https://opensource.com/sites/default/files/u128651/mycollab_kanban-board.png) - -[MyCollab][8] is a suite of three collaboration modules for small and midsize businesses: project management, customer relationship management (CRM), and document creation and editing software. There are two licensing options: a commercial "ultimate" edition, which is faster and can be run on-premises or in the cloud, and the open source "community edition," which is the version we're interested in here. - -The community edition doesn't have a cloud option and is slower, due to not using query cache, but provides essential project management features, including tasks, issues management, activity stream, roadmap view, and a Kanban board for agile teams. While it doesn't have a separate mobile app, it works on mobile devices as well as Windows, MacOS, Linux, and Unix computers. - -The latest version of MyCollab is 5.4.10 and the source code is available on [GitHub][9]. It is licensed under AGPLv3 and requires a Java runtime and MySQL stack to operate. It's available for [download][10] for Windows, Linux, Unix, and MacOS. - -### Odoo - -![](https://opensource.com/sites/default/files/u128651/odoo_projects_screenshots_01a.gif) - -[Odoo][11] is more than project management software; it's a full, integrated business application suite that includes accounting, human resources, website & e-commerce, inventory, manufacturing, sales management (CRM), and other tools. - -The free and open source community edition has limited [features][12] compared to the paid enterprise suite. Its project management application includes a Kanban-style task-tracking view for agile teams, which was updated in its latest release, Odoo 11.0, to include a progress bar and animation for tracking project status. The project management tool also includes Gantt charts, tasks, issues, graphs, and more. Odoo has a thriving [community][13] and provides [user guides][14] and other training resources. - -It is licensed under GPLv3 and requires Python and PostgreSQL. It is available for [download][15] for Windows, Linux, and Red Hat Package Manager, as a [Docker][16] image, and as source on [GitHub][17]. - -### OpenProject - -![](https://opensource.com/sites/default/files/u128651/openproject-screenshot-agile-scrum.png) - -[OpenProject][18] is a powerful open source project management tool that is notable for its ease of use and rich project management and team collaboration features. - -Its modules support project planning, scheduling, roadmap and release planning, time tracking, cost reporting, budgeting, bug tracking, and agile and Scrum. Its agile features, including creating stories, prioritizing sprints, and tracking tasks, are integrated with OpenProject's other modules. - -OpenProject is licensed under GPLv3 and its source code is available on [GitHub][19]. Its latest version, 7.3.2. is available for [download][20] for Linux; you can learn more about installing and configuring it in Birthe Lindenthal's article "[Getting started with OpenProject][21]." - -### OrangeScrum - -![](https://opensource.com/sites/default/files/u128651/orangescrum_kanban.png) - -As you would expect from its name, [OrangeScrum][22] supports agile methodologies, specifically with a Scrum task board and Kanban-style workflow view. It's geared for smaller organizations—freelancers, agencies, and small and midsize businesses. - -The open source version offers many of the [features][23] in OrangeScrum's paid editions, including a mobile app, resource utilization, and progress tracking. Other features, including Gantt charts, time logs, invoicing, and client management, are available as paid add-ons, and the paid editions include a cloud option, which the community version does not. - -OrangeScrum is licensed under GPLv3 and is based on the CakePHP framework. It requires Apache, PHP 5.3 or higher, and MySQL 4.1 or higher, and works on Windows, Linux, and MacOS. Its latest release, 1.6.1. is available for [download][24], and its source code can be found on [GitHub][25]. - -### ]project-open[ - -![](https://opensource.com/sites/default/files/u128651/projectopen_dashboard.png) - -[]project-open[][26] is a dual-licensed enterprise project management tool, meaning that its core is open source, and some additional features are available in commercially licensed modules. According to the project's [comparison][27] of the community and enterprise editions, the open source core offers plenty of features for small and midsize organizations. - -]project-open[ supports [agile][28] projects with Scrum and Kanban support, as well as classic Gantt/waterfall projects and hybrid or mixed projects. - -The application is licensed under GPL and the [source code][29] is accessible via CVS. ]project-open[ is available as [installers][26] for both Linux and Windows, but also in cloud images and as a virtual appliance. - -### Taiga - -![](https://opensource.com/sites/default/files/u128651/taiga_screenshot.jpg) - -[Taiga][30] is an open source project management platform that focuses on Scrum and agile development, with features including a Kanban board, tasks, sprints, issues, a backlog, and epics. Other features include ticket management, multi-project support, wiki pages, and third-party integrations. - -It also offers a free mobile app for iOS, Android, and Windows devices, and provides import tools that make it easy to migrate from other popular project management applications. - -Taiga is free for public projects, with no restrictions on either the number of projects or the number of users. For private projects, there is a wide range of [paid plans][31] available under a "freemium" model, but, notably, the software's features are the same, no matter which type of plan you have. - -Taiga is licensed under GNU Affero GPLv3, and requires a stack that includes Nginx, Python, and PostgreSQL. The latest release, [3.1.0 Perovskia atriplicifolia][32], is available on [GitHub][33]. - -### Tuleap - -![](https://opensource.com/sites/default/files/u128651/tuleap-scrum-prioritized-backlog.png) - -[Tuleap][34] is an application lifecycle management (ALM) platform that aims to manage projects for every type of team—small, midsize, large, waterfall, agile, or hybrid—but its support for agile teams is prominent. Notably, it offers support for Scrum, Kanban, sprints, tasks, reports, continuous integration, backlogs, and more. - -Other [features][35] include issue tracking, document tracking, collaboration tools, and integration with Git, SVN, and Jenkins, all of which make it an appealing choice for open source software development projects. - -Tuleap is licensed under GPLv2. More information, including Docker and CentOS downloads, is available on their [Get Started][36] page. You can also get the source code for its latest version, 9.14, on Tuleap's [Git][37]. - -The trouble with this type of list is that it's usually out of date as soon as it's published. Are you using an open source project management tool that supports agile that we forgot to include? Or do you have feedback on the ones we mentioned? Please leave a comment below. - --------------------------------------------------------------------------------- - -via: https://opensource.com/article/18/2/agile-project-management-tools - -作者:[Opensource.com][a] -译者:[译者ID](https://github.com/译者ID) -校对:[校对者ID](https://github.com/校对者ID) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 - -[a]:https://opensource.com -[1]:http://agilemanifesto.org/principles.html -[2]:https://opensource.com/resources/scrum -[3]:https://www.pmi.org/-/media/pmi/documents/public/pdf/learning/thought-leadership/pulse/pulse-of-the-profession-2017.pdf -[4]:https://www.pwc.com/gx/en/actuarial-insurance-services/assets/agile-project-delivery-confidence.pdf -[5]:https://opensource.com/business/14/1/top-project-management-tools-2014 -[6]:https://opensource.com/business/15/1/top-project-management-tools-2015 -[7]:https://opensource.com/business/16/3/top-project-management-tools-2016 -[8]:https://community.mycollab.com/ -[9]:https://github.com/MyCollab/mycollab -[10]:https://www.mycollab.com/ce-registration/ -[11]:https://www.odoo.com/ -[12]:https://www.odoo.com/page/editions -[13]:https://www.odoo.com/page/community -[14]:https://www.odoo.com/documentation/user/11.0/ -[15]:https://www.odoo.com/page/download -[16]:https://hub.docker.com/_/odoo/ -[17]:https://github.com/odoo/odoo -[18]:https://www.openproject.org/ -[19]:https://github.com/opf/openproject -[20]:https://www.openproject.org/download-and-installation/ -[21]:https://opensource.com/article/17/11/how-install-and-use-openproject -[22]:https://www.orangescrum.org/ -[23]:https://www.orangescrum.org/compare-orangescrum -[24]:http://www.orangescrum.org/free-download -[25]:https://github.com/Orangescrum/orangescrum/ -[26]:http://www.project-open.com/en/list-installers -[27]:http://www.project-open.com/en/products/editions.html -[28]:http://www.project-open.com/en/project-type-agile -[29]:http://www.project-open.com/en/developers-cvs-checkout -[30]:https://taiga.io/ -[31]:https://tree.taiga.io/support/subscription-and-plans/payment-process-faqs/#q.-what-s-about-custom-plans-private-projects-with-more-than-25-members-? -[32]:https://blog.taiga.io/taiga-perovskia-atriplicifolia-release-310.html -[33]:https://github.com/taigaio -[34]:https://www.tuleap.org/ -[35]:https://www.tuleap.org/features/project-management -[36]:https://www.tuleap.org/get-started -[37]:https://tuleap.net/plugins/git/tuleap/tuleap/stable diff --git a/sources/tech/20180118 How to Play Sound Through Two or More Output Devices in Linux.md b/sources/tech/20180118 How to Play Sound Through Two or More Output Devices in Linux.md deleted file mode 100644 index 2f35b15ac7..0000000000 --- a/sources/tech/20180118 How to Play Sound Through Two or More Output Devices in Linux.md +++ /dev/null @@ -1,62 +0,0 @@ -translating by lujun9972 -How to Play Sound Through Two or More Output Devices in Linux -====== - -![](https://www.maketecheasier.com/assets/uploads/2018/01/output-audio-multiple-devices-featured.jpg) - -Handling audio in Linux can be a pain. Pulseaudio has made it both better and worse. While some things work better than they did before, other things have become more complicated. Handling audio output is one of those things. - -If you want to enable multiple audio outputs from your Linux PC, you can use a simple utility to enable your other sound devices on a virtual interface. It's a lot easier than it sounds. - -In case you're wondering why you'd want to do this, a pretty common instance is playing video from your computer on a TV and using both the PC and TV speakers. - -### Install Paprefs - -The easiest way to enable audio playback from multiple sources is to use a simple graphical utility called "paprefs." It's short for PulseAudio Preferences. - -It's available through the Ubuntu repositories, so just install it with Apt. -``` -sudo apt install paprefs -``` - -When the install finishes, you can just launch the program. - -### Enable Dual Audio Playback - -Even though the utility is graphical, it's still probably easier to launch it by typing `paprefs` in the command line as a regular user. - -The window that opens has a few tabs with settings that you can tweak. The tab that you're looking for is the last one, "Simultaneous Output." - -![Paprefs on Ubuntu][1] - -There isn't a whole lot on the tab, just a checkbox to enable the setting. - -Next, open up the regular sound preferences. It's in different places on different distributions. On Ubuntu it'll be under the GNOME system settings. - -![Enable Simultaneous Audio][2] - -Once you have your sound preferences open, select the "Output" tab. Select the "Simultaneous output" radio button. It's now your default output. - -### Test It - -To test it, you can use anything you like, but music always works. If you are using a video, like suggested earlier, you can certainly test it with that as well. - -If everything is working well, you should hear audio out of all connected devices. - -That's all there really is to do. This works best when there are multiple devices, like the HDMI port and the standard analog output. You can certainly try it with other configurations, too. You should also keep in mind that there will only be a single volume control, so adjust the physical output devices accordingly. - - --------------------------------------------------------------------------------- - -via: https://www.maketecheasier.com/play-sound-through-multiple-devices-linux/ - -作者:[Nick Congleton][a] -译者:[lujun9972](https://github.com/lujun9972) -校对:[校对者ID](https://github.com/校对者ID) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 - -[a]:https://www.maketecheasier.com/author/nickcongleton/ -[1]:https://www.maketecheasier.com/assets/uploads/2018/01/sa-paprefs.jpg (Paprefs on Ubuntu) -[2]:https://www.maketecheasier.com/assets/uploads/2018/01/sa-enable.jpg (Enable Simultaneous Audio) -[3]:https://depositphotos.com/89314442/stock-photo-headphones-on-speakers.html diff --git a/sources/tech/20180126 Running a Python application on Kubernetes.md b/sources/tech/20180126 Running a Python application on Kubernetes.md deleted file mode 100644 index 19a440dc77..0000000000 --- a/sources/tech/20180126 Running a Python application on Kubernetes.md +++ /dev/null @@ -1,280 +0,0 @@ -Running a Python application on Kubernetes -============================================================ - -### This step-by-step tutorial takes you through the process of deploying a simple Python application on Kubernetes. - -![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/build_structure_tech_program_code_construction.png?itok=nVsiLuag) -Image by : opensource.com - -Kubernetes is an open source platform that offers deployment, maintenance, and scaling features. It simplifies management of containerized Python applications while providing portability, extensibility, and self-healing capabilities. - -Whether your Python applications are simple or more complex, Kubernetes lets you efficiently deploy and scale them, seamlessly rolling out new features while limiting resources to only those required. - -In this article, I will describe the process of deploying a simple Python application to Kubernetes, including: - -* Creating Python container images - -* Publishing the container images to an image registry - -* Working with persistent volume - -* Deploying the Python application to Kubernetes - -### Requirements - -You will need Docker, kubectl, and this [source code][10]. - -Docker is an open platform to build and ship distributed applications. To install Docker, follow the [official documentation][11]. To verify that Docker runs your system: - -``` -$ docker info -Containers: 0 -Images: 289 -Storage Driver: aufs - Root Dir: /var/lib/docker/aufs - Dirs: 289 -Execution Driver: native-0.2 -Kernel Version: 3.16.0-4-amd64 -Operating System: Debian GNU/Linux 8 (jessie) -WARNING: No memory limit support -WARNING: No swap limit support -``` - -kubectl is a command-line interface for executing commands against a Kubernetes cluster. Run the shell script below to install kubectl: - -``` -curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl -``` - -Deploying to Kubernetes requires a containerized application. Let's review containerizing Python applications. - -### Containerization at a glance - -Containerization involves enclosing an application in a container with its own operating system. This full machine virtualization option has the advantage of being able to run an application on any machine without concerns about dependencies. - -Roman Gaponov's [article][12] serves as a reference. Let's start by creating a container image for our Python code. - -### Create a Python container image - -To create these images, we will use Docker, which enables us to deploy applications inside isolated Linux software containers. Docker is able to automatically build images using instructions from a Docker file. - -This is a Docker file for our Python application: - -``` -FROM python:3.6 -MAINTAINER XenonStack - -# Creating Application Source Code Directory -RUN mkdir -p /k8s_python_sample_code/src - -# Setting Home Directory for containers -WORKDIR /k8s_python_sample_code/src - -# Installing python dependencies -COPY requirements.txt /k8s_python_sample_code/src -RUN pip install --no-cache-dir -r requirements.txt - -# Copying src code to Container -COPY . /k8s_python_sample_code/src/app - -# Application Environment variables -ENV APP_ENV development - -# Exposing Ports -EXPOSE 5035 - -# Setting Persistent data -VOLUME ["/app-data"] - -# Running Python Application -CMD ["python", "app.py"] -``` - -This Docker file contains instructions to run our sample Python code. It uses the Python 3.5 development environment. - -### Build a Python Docker image - -We can now build the Docker image from these instructions using this command: - -``` -docker build -t k8s_python_sample_code . -``` - -This command creates a Docker image for our Python application. - -### Publish the container images - -We can publish our Python container image to different private/public cloud repositories, like Docker Hub, AWS ECR, Google Container Registry, etc. For this tutorial, we'll use Docker Hub. - -Before publishing the image, we need to tag it to a version: - -``` -docker tag k8s_python_sample_code:latest k8s_python_sample_code:0.1 -``` - -### Push the image to a cloud repository - -Using a Docker registry other than Docker Hub to store images requires you to add that container registry to the local Docker daemon and Kubernetes Docker daemons. You can look up this information for the different cloud registries. We'll use Docker Hub in this example. - -Execute this Docker command to push the image: - -``` -docker push k8s_python_sample_code -``` - -### Working with CephFS persistent storage - -Kubernetes supports many persistent storage providers, including AWS EBS, CephFS, GlusterFS, Azure Disk, NFS, etc. I will cover Kubernetes persistence storage with CephFS. - -To use CephFS for persistent data to Kubernetes containers, we will create two files: - -persistent-volume.yml - -``` -apiVersion: v1 -kind: PersistentVolume -metadata: -  name: app-disk1 -  namespace: k8s_python_sample_code -spec: -  capacity: -  storage: 50Gi -  accessModes: -  - ReadWriteMany -  cephfs: -  monitors: -    - "172.17.0.1:6789" -  user: admin -  secretRef: -    name: ceph-secret -  readOnly: false -``` - -persistent_volume_claim.yaml - -``` -apiVersion: v1 -kind: PersistentVolumeClaim -metadata: -  name: appclaim1 -  namespace: k8s_python_sample_code -spec: -  accessModes: -  - ReadWriteMany -  resources: -  requests: -    storage: 10Gi -``` - -We can now use kubectl to add the persistent volume and claim to the Kubernetes cluster: - -``` -$ kubectl create -f persistent-volume.yml -$ kubectl create -f persistent-volume-claim.yml -``` - -We are now ready to deploy to Kubernetes. - -### Deploy the application to Kubernetes - -To manage the last mile of deploying the application to Kubernetes, we will create two important files: a service file and a deployment file. - -Create a file and name it `k8s_python_sample_code.service.yml` with the following content: - -``` -apiVersion: v1 -kind: Service -metadata: -  labels: -  k8s-app: k8s_python_sample_code -  name: k8s_python_sample_code -  namespace: k8s_python_sample_code -spec: -  type: NodePort -  ports: -  - port: 5035 -  selector: -  k8s-app: k8s_python_sample_code -``` - -Create a file and name it `k8s_python_sample_code.deployment.yml` with the following content: - -``` -apiVersion: extensions/v1beta1 -kind: Deployment -metadata: -  name: k8s_python_sample_code -  namespace: k8s_python_sample_code -spec: -  replicas: 1 -  template: -  metadata: -    labels: -    k8s-app: k8s_python_sample_code -  spec: -    containers: -    - name: k8s_python_sample_code -      image: k8s_python_sample_code:0.1 -      imagePullPolicy: "IfNotPresent" -      ports: -      - containerPort: 5035 -      volumeMounts: -        - mountPath: /app-data -          name: k8s_python_sample_code -     volumes:  -         - name: -           persistentVolumeClaim: -             claimName: appclaim1 -``` - -Finally, use kubectl to deploy the application to Kubernetes: - -``` -$ kubectl create -f k8s_python_sample_code.deployment.yml $ kubectl create -f k8s_python_sample_code.service.yml -``` - -Your application was successfully deployed to Kubernetes. - -You can verify whether your application is running by inspecting the running services: - -``` -kubectl get services -``` - -May Kubernetes free you from future deployment hassles! - - _Want to learn more about Python? Nanjekye's book, [Python 2 and 3 Compatibility][7]offers clean ways to write code that will run on both Python 2 and 3, including detailed examples of how to convert existing Python 2-compatible code to code that will run reliably on both Python 2 and 3._ - - -### About the author - - [![](https://opensource.com/sites/default/files/styles/profile_pictures/public/pictures/joannah-nanjekye.jpg?itok=F4RqEjoA)][13] Joannah Nanjekye - Straight Outta 256 , I choose Results over Reasons, Passionate Aviator, Show me the code.[More about me][8] - --------------------------------------------------------------------------------- - -via: https://opensource.com/article/18/1/running-python-application-kubernetes - -作者:[Joannah Nanjekye ][a] -译者:[译者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/nanjekyejoannah -[1]:https://opensource.com/resources/python?intcmp=7016000000127cYAAQ -[2]:https://opensource.com/resources/python/ides?intcmp=7016000000127cYAAQ -[3]:https://opensource.com/resources/python/gui-frameworks?intcmp=7016000000127cYAAQ -[4]:https://opensource.com/tags/python?intcmp=7016000000127cYAAQ -[5]:https://developers.redhat.com/?intcmp=7016000000127cYAAQ -[6]:https://opensource.com/article/18/1/running-python-application-kubernetes?rate=D9iKksKbd9q9vOVb92Mg-v0Iyqn0QVO5fbIERTbSHz4 -[7]:https://www.apress.com/gp/book/9781484229545 -[8]:https://opensource.com/users/nanjekyejoannah -[9]:https://opensource.com/user/196386/feed -[10]:https://github.com/jnanjekye/k8s_python_sample_code/tree/master -[11]:https://docs.docker.com/engine/installation/ -[12]:https://hackernoon.com/docker-tutorial-getting-started-with-python-redis-and-nginx-81a9d740d091 -[13]:https://opensource.com/users/nanjekyejoannah -[14]:https://opensource.com/users/nanjekyejoannah -[15]:https://opensource.com/users/nanjekyejoannah -[16]:https://opensource.com/tags/python -[17]:https://opensource.com/tags/kubernetes diff --git a/sources/tech/20180130 Trying Other Go Versions.md b/sources/tech/20180130 Trying Other Go Versions.md index 731747d19a..1ab1b4f948 100644 --- a/sources/tech/20180130 Trying Other Go Versions.md +++ b/sources/tech/20180130 Trying Other Go Versions.md @@ -1,3 +1,4 @@ +imquanquan Translating Trying Other Go Versions ============================================================ @@ -109,4 +110,4 @@ via: https://pocketgophers.com/trying-other-versions/ [8]:https://pocketgophers.com/trying-other-versions/#trying-a-specific-release [9]:https://pocketgophers.com/guide-to-json/ [10]:https://pocketgophers.com/trying-other-versions/#trying-any-release -[11]:https://pocketgophers.com/trying-other-versions/#trying-a-source-build-e-g-tip \ No newline at end of file +[11]:https://pocketgophers.com/trying-other-versions/#trying-a-source-build-e-g-tip diff --git a/sources/tech/20180131 What I Learned from Programming Interviews.md b/sources/tech/20180131 What I Learned from Programming Interviews.md deleted file mode 100644 index 17fde91392..0000000000 --- a/sources/tech/20180131 What I Learned from Programming Interviews.md +++ /dev/null @@ -1,140 +0,0 @@ -What I Learned from Programming Interviews -============================================================ - -![](https://cdn-images-1.medium.com/max/1250/1*DXPdaGPM4oM6p5nSkup7IQ.jpeg) -Whiteboard programming interviews - -In 2017, I went to the [Grace Hopper Celebration][1] of women in computing. It’s the largest gathering of this kind, with 17,000 women attending last year. - -This conference has a huge career fair where companies interview attendees. Some even get offers. Walking around the area, I noticed that some people looked stressed and worried. I overheard conversations, and some talked about how they didn’t do well in the interview. - -I approached a group of people that I overheard and gave them advice. I considered some of the advice I gave to be basic, such as “it’s okay to think of the naive solution first.” But people were surprised by most of the advice I gave them. - -I wanted to help more people with this. I gathered a list of tips that worked for me and published a [podcast episode][2] about them. They’re also the topic of this post. - -I’ve had many programming interviews both for internships and full-time jobs. When I was in college studying Computer Science, there was a career fair every fall semester where the first round of interviews took place. I have failed at the first and final rounds of interviews. After each interview, I reflected on what I could’ve done better and had mock up interviews with friends who gave me feedback. - -Whether we find a job through a job portal, networking, or university recruiting, part of the process involves doing a technical interview. - -In recent years we’ve seen different interview formats emerge: - -* Pair programming with an engineer - -* Online quiz and online coding - -* Whiteboard interviews - -I’ll focus on the whiteboard interview because it’s the one that I have experienced. I’ve had many interviews. Some of them have gone well, while others haven’t. - -### What I did wrong - -First, I want to go over the things I did wrong in my interviews. This helps see the problems and what to improve. - -When an interviewer gave me a technical problem, I immediately went to the whiteboard and started trying to solve it.  _Without saying a word._ - -I made two mistakes here: - -#### Not clarifying information that is crucial to solve a problem - -For example, are we only working with numbers or also strings? Are we supporting multiple data types? If you don’t ask questions before you start working on a question, your interviewer can get the impression that you won’t ask questions before you start working on a project at their company. This is an important skill to have in the workplace. It is not like school anymore. You don’t get an assignment with all the steps detailed for you. You have to find out what those are and define them. - -#### Thinking without writing or communicating - -Often times I stood there thinking without writing. When I was doing a mock interview with a friend, he told me that he knew I was thinking because we had worked together. To a stranger, it can seem that I’m clueless, or that I’m thinking. It is also important not to rush on a solution right away. Take some time to brainstorm ideas. Sometimes the interviewer will gladly participate in this. After all, that’s how it is at work meetings. - -### Coming up with a solution - -Before you begin writing code, it helps if you come up with the algorithm first. Don’t start writing code and hope that you’ll solve the problem as you write. - -This is what has worked for me: - -1. Brainstorm - -2. Coding - -3. Error handling - -4. Testing - -#### 1\. Brainstorm - -For me, it helps to visualize first what the problem is through a series of examples. If it’s a problem related to trees, I would start with the null case, one node, two nodes, three nodes. This can help you generalize a solution. - -On the whiteboard, write down a list of the things the algorithm needs to do. This way, you can find bugs and issues before writing any code. Just keep track of the time. I made a mistake once where I spent too much time asking clarifying questions and brainstorming, and I barely had time to write the code. The downside of this is that your interviewer doesn’t get to see how you code. You can also come off as if you’re trying to avoid the coding portion. It helps to wear a wrist watch, or if there’s a clock in the room, look at it occasionally. Sometimes the interviewer will tell you, “I think we have the necessary information, let’s start coding it.” - -#### 2\. Coding and code walkthrough - -If you don’t have the solution right away, it always helps to point out the obvious naive solution. While you’re explaining this, you should be thinking of how to improve it. When you state the obvious, indicate why it is not the best solution. For this it helps to be familiar with big O notation. It is okay to go over 2–3 solutions first. The interviewer sometimes guides you by saying, “Can we do better?” This can sometimes mean they are looking for a more efficient solution. - -#### 3\. Error handling - -While you’re coding, point out that you’re leaving a code comment for error handling. Once an interviewer said, “That’s a good point. How would you handle it? Would you throw an exception? Or return a specific value?” This can make for a good short discussion about code quality. Mention a few error cases. Other times, the interviewer might say that you can assume that the parameters you’re getting already passed a validation. However, it is still important to bring this up to show that you are aware of error cases and quality. - -#### 4\. Testing - -After you have finished coding the solution, re-use the examples from brainstorming to walk through your code and make sure it works. For example you can say, “Let’s go over the example of a tree with one node, two nodes.” - -After you finish this, the interviewer sometimes asks you how you would test your code, and what your test cases would be. I recommend that you organize your test cases in different categories. - -Some examples are: - -1. Performance - -2. Error cases - -3. Positive expected cases - -For performance, think about extreme quantities. For example, if the problem is about lists, mention that you would have a case with a large list and a really small list. If it’s about numbers, you’ll test the maximum integer number and the smallest. I recommend reading about testing software to get more ideas. My favorite book on this is [How We Test Software at Microsoft][3]. - -For error cases, think about what is expected to fail and list those. - -For positive expected cases, it helps to think of what the user requirements are. What are the cases that this solution is meant to solve? Those are the positive test cases. - -### “Do you have any questions for me?” - -Almost always there will be a few minutes dedicated at the end for you to ask questions. I recommend that you write down the questions you would ask your interviewer before the interview. Don’t say, “I don’t have any questions.” Even if you feel the interview didn’t go well, or you’re not super passionate about the company, there’s always something you can ask. It can be about what the person likes and hates most about his or her job. Or it can be something related to the person’s work, or technologies and practices used at the company. Don’t feel discouraged to ask something even if you feel you didn’t do well. - -### Applying for a job - -As for searching and applying for a job, I’ve been told that you should only apply to a place that you would be truly passionate to work for. They say pick a company that you love, or a product that you enjoy using, and see if you can work there. - -I don’t recommend that you always do this. You can rule out many good options this way, especially if you’re looking for an internship or an entry-level job. - -You can focus on other goals instead. What do I want to get more experience in? Is it cloud computing, web development, or artificial intelligence? When you talk to companies at the career fair, find out if their job openings are in this area. You might find a really good position at a company or a non-profit that wasn’t in your list. - -#### Switching teams - -After a year and a half at my first team, I decided that it was time to explore something different. I found a team I liked and had 4 rounds of interviews. I didn’t do well. - -I didn’t practice anything, not even simply writing on a whiteboard. My logic had been, if I have been working at the company for almost 2 years, why would I need to practice? I was wrong about this. I struggled to write a solution on the whiteboard. Things like my writing being too small and running out of space by not starting at the top left all contributed to not passing. - -I hadn’t brushed up on data structures and algorithms. If I had, I would’ve been more confident. Even if you’ve been working at a company as a Software Engineer, before you do a round of interviews with another team, I strongly recommend you go through practice problems on a whiteboard. - -As for finding a team, if you are looking to switch teams at your company, it helps to talk informally with members of that team. For this, I found that almost everyone is willing to have lunch with you. People are mostly available at noon too, so there is low risk of lack of availability and meeting conflicts. This is an informal way to find out what the team is working on, and see what the personalities of your potential team members are like. You can learn many things from lunch meetings that can help you in the formal interviews. - -It is important to know that at the end of the day, you are interviewing for a specific team. Even if you do really well, you might not get an offer because you are not a culture fit. That’s part of why I try to meet different people in the team first, but this is not always possible. Don’t get discouraged by a rejection, keep your options open, and practice. - -This content is from the [“Programming interviews”][4] episode on [The Women in Tech Show: Technical Interviews with Prominent Women in Tech][5]. - --------------------------------------------------------------------------------- - -作者简介: - -Software Engineer II at Microsoft Research, opinions are my own, host of www.thewomenintechshow.com - ------------- - -via: https://medium.freecodecamp.org/what-i-learned-from-programming-interviews-29ba49c9b851 - -作者:[Edaena Salinas ][a] -译者:[译者ID](https://github.com/译者ID) -校对:[校对者ID](https://github.com/校对者ID) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 - -[a]:https://medium.freecodecamp.org/@edaenas -[1]:https://anitab.org/event/2017-grace-hopper-celebration-women-computing/ -[2]:https://thewomenintechshow.com/2017/12/18/programming-interviews/ -[3]:https://www.amazon.com/How-We-Test-Software-Microsoft/dp/0735624259 -[4]:https://thewomenintechshow.com/2017/12/18/programming-interviews/ -[5]:https://thewomenintechshow.com/ \ No newline at end of file diff --git a/sources/tech/20180201 Conditional Rendering in React using Ternaries and.md b/sources/tech/20180201 Conditional Rendering in React using Ternaries and.md deleted file mode 100644 index b5f740c92c..0000000000 --- a/sources/tech/20180201 Conditional Rendering in React using Ternaries and.md +++ /dev/null @@ -1,206 +0,0 @@ -Conditional Rendering in React using Ternaries and Logical AND -============================================================ - - -![](https://cdn-images-1.medium.com/max/2000/1*eASRJrCIVgsy5VbNMAzD9w.jpeg) -Photo by [Brendan Church][1] on [Unsplash][2] - -There are several ways that your React component can decide what to render. You can use the traditional `if` statement or the `switch` statement. In this article, we’ll explore a few alternatives. But be warned that some come with their own gotchas, if you’re not careful. - -### Ternary vs if/else - -Let’s say we have a component that is passed a `name` prop. If the string is non-empty, we display a greeting. Otherwise we tell the user they need to sign in. - -Here’s a Stateless Function Component (SFC) that does just that. - -``` -const MyComponent = ({ name }) => { - if (name) { - return ( -
- Hello {name} -
- ); - } - return ( -
- Please sign in -
- ); -}; -``` - -Pretty straightforward. But we can do better. Here’s the same component written using a conditional ternary operator. - -``` -const MyComponent = ({ name }) => ( -
- {name ? `Hello ${name}` : 'Please sign in'} -
-); -``` - -Notice how concise this code is compared to the example above. - -A few things to note. Because we are using the single statement form of the arrow function, the `return` statement is implied. Also, using a ternary allowed us to DRY up the duplicate `
` markup. 🎉 - -### Ternary vs Logical AND - -As you can see, ternaries are wonderful for `if/else` conditions. But what about simple `if` conditions? - -Let’s look at another example. If `isPro` (a boolean) is `true`, we are to display a trophy emoji. We are also to render the number of stars (if not zero). We could go about it like this. - -``` -const MyComponent = ({ name, isPro, stars}) => ( -
-
- Hello {name} - {isPro ? '🏆' : null} -
- {stars ? ( -
- Stars:{'⭐️'.repeat(stars)} -
- ) : null} -
-); -``` - -But notice the “else” conditions return `null`. This is becasue a ternary expects an else condition. - -For simple `if` conditions, we could use something a little more fitting: the logical AND operator. Here’s the same code written using a logical AND. - -``` -const MyComponent = ({ name, isPro, stars}) => ( -
-
- Hello {name} - {isPro && '🏆'} -
- {stars && ( -
- Stars:{'⭐️'.repeat(stars)} -
- )} -
-); -``` - -Not too different, but notice how we eliminated the `: null` (i.e. else condition) at the end of each ternary. Everything should render just like it did before. - - -Hey! What gives with John? There is a `0` when nothing should be rendered. That’s the gotcha that I was referring to above. Here’s why. - -[According to MDN][3], a Logical AND (i.e. `&&`): - -> `expr1 && expr2` - -> Returns `expr1` if it can be converted to `false`; otherwise, returns `expr2`. Thus, when used with Boolean values, `&&` returns `true` if both operands are true; otherwise, returns `false`. - -OK, before you start pulling your hair out, let me break it down for you. - -In our case, `expr1` is the variable `stars`, which has a value of `0`. Because zero is falsey, `0` is returned and rendered. See, that wasn’t too bad. - -I would write this simply. - -> If `expr1` is falsey, returns `expr1`, else returns `expr2`. - -So, when using a logical AND with non-boolean values, we must make the falsey value return something that React won’t render. Say, like a value of `false`. - -There are a few ways that we can accomplish this. Let’s try this instead. - -``` -{!!stars && ( -
- {'⭐️'.repeat(stars)} -
-)} -``` - -Notice the double bang operator (i.e. `!!`) in front of `stars`. (Well, actually there is no “double bang operator”. We’re just using the bang operator twice.) - -The first bang operator will coerce the value of `stars` into a boolean and then perform a NOT operation. If `stars` is `0`, then `!stars` will produce `true`. - -Then we perform a second NOT operation, so if `stars` is 0, `!!stars` would produce `false`. Exactly what we want. - -If you’re not a fan of `!!`, you can also force a boolean like this (which I find a little wordy). - -``` -{Boolean(stars) && ( -``` - -Or simply give a comparator that results in a boolean value (which some might say is even more semantic). - -``` -{stars > 0 && ( -``` - -#### A word on strings - -Empty string values suffer the same issue as numbers. But because a rendered empty string is invisible, it’s not a problem that you will likely have to deal with, or will even notice. However, if you are a perfectionist and don’t want an empty string on your DOM, you should take similar precautions as we did for numbers above. - -### Another solution - -A possible solution, and one that scales to other variables in the future, would be to create a separate `shouldRenderStars` variable. Then you are dealing with boolean values in your logical AND. - -``` -const shouldRenderStars = stars > 0; -``` - -``` -return ( -
- {shouldRenderStars && ( -
- {'⭐️'.repeat(stars)} -
- )} -
-); -``` - -Then, if in the future, the business rule is that you also need to be logged in, own a dog, and drink light beer, you could change how `shouldRenderStars` is computed, and what is returned would remain unchanged. You could also place this logic elsewhere where it’s testable and keep the rendering explicit. - -``` -const shouldRenderStars = - stars > 0 && loggedIn && pet === 'dog' && beerPref === 'light`; -``` - -``` -return ( -
- {shouldRenderStars && ( -
- {'⭐️'.repeat(stars)} -
- )} -
-); -``` - -### Conclusion - -I’m of the opinion that you should make best use of the language. And for JavaScript, this means using conditional ternary operators for `if/else`conditions and logical AND operators for simple `if` conditions. - -While we could just retreat back to our safe comfy place where we use the ternary operator everywhere, you now possess the knowledge and power to go forth AND prosper. - --------------------------------------------------------------------------------- - -作者简介: - -Managing Editor at the American Express Engineering Blog http://aexp.io and Director of Engineering @AmericanExpress. MyViews !== ThoseOfMyEmployer. - ----------------- - -via: https://medium.freecodecamp.org/conditional-rendering-in-react-using-ternaries-and-logical-and-7807f53b6935 - -作者:[Donavon West][a] -译者:[译者ID](https://github.com/译者ID) -校对:[校对者ID](https://github.com/校对者ID) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 - -[a]:https://medium.freecodecamp.org/@donavon -[1]:https://unsplash.com/photos/pKeF6Tt3c08?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText -[2]:https://unsplash.com/search/photos/road-sign?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText -[3]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_Operators \ No newline at end of file diff --git a/sources/tech/20180201 Here are some amazing advantages of Go that you dont hear much about.md b/sources/tech/20180201 Here are some amazing advantages of Go that you dont hear much about.md deleted file mode 100644 index 12c581b773..0000000000 --- a/sources/tech/20180201 Here are some amazing advantages of Go that you dont hear much about.md +++ /dev/null @@ -1,223 +0,0 @@ -Here are some amazing advantages of Go that you don’t hear much about -============================================================ - -![](https://cdn-images-1.medium.com/max/2000/1*NDXd5I87VZG0Z74N7dog0g.png) - -Artwork from [https://github.com/ashleymcnamara/gophers][1] - -In this article, I discuss why you should give Go a chance and where to start. - -Golang is a programming language you might have heard about a lot during the last couple years. Even though it was created back in 2009, it has started to gain popularity only in recent years. - - -![](https://cdn-images-1.medium.com/max/2000/1*cQ8QzhCPiFXqk_oQdUk_zw.png) -Golang popularity according to Google Trends - -This article is not about the main selling points of Go that you usually see. - -Instead, I would like to present to you some rather small but still significant features that you only get to know after you’ve decided to give Go a try. - -These are amazing features that are not laid out on the surface, but they can save you weeks or months of work. They can also make software development more enjoyable. - -Don’t worry if Go is something new for you. This article does not require any prior experience with the language. I have included a few extra links at the bottom, in case you would like to learn a bit more. - -We will go through such topics as: - -* GoDoc - -* Static code analysis - -* Built-in testing and profiling framework - -* Race condition detection - -* Learning curve - -* Reflection - -* Opinionatedness - -* Culture - -Please, note that the list doesn’t follow any particular order. It is also opinionated as hell. - -### GoDoc - -Documentation in code is taken very seriously in Go. So is simplicity. - -[GoDoc][4] is a static code analyzing tool that creates beautiful documentation pages straight out of your code. A remarkable thing about GoDoc is that it doesn’t use any extra languages, like JavaDoc, PHPDoc, or JSDoc to annotate constructions in your code. Just English. - -It uses as much information as it can get from the code to outline, structure, and format the documentation. And it has all the bells and whistles, such as cross-references, code samples, and direct links to your version control system repository. - -All you can do is to add a good old `// MyFunc transforms Foo into Bar` kind of comment which would be reflected in the documentation, too. You can even add [code examples][5] which are actually runnable via the web interface or locally. - -GoDoc is the only documentation engine for Go that is used by the whole community. This means that every library or application written in Go has the same format of documentation. In the long run, it saves you tons of time while browsing those docs. - -Here, for example, is the GoDoc page for my recent pet project: [pullkee — GoDoc][6]. - -### Static code analysis - -Go heavily relies on static code analysis. Examples include [godoc][7] for documentation, [gofmt][8] for code formatting, [golint][9] for code style linting, and many others. - -There are so many of them that there’s even an everything-included-kind-of project called [gometalinter][10] to compose them all into a single utility. - -Those tools are commonly implemented as stand-alone command line applications and integrate easily with any coding environment. - -Static code analysis isn’t actually something new to modern programming, but Go sort of brings it to the absolute. I can’t overestimate how much time it saved me. Also, it gives you a feeling of safety, as though someone is covering your back. - -It’s very easy to create your own analyzers, as Go has dedicated built-in packages for parsing and working with Go sources. - -You can learn more from this talk: [GothamGo Kickoff Meetup: Go Static Analysis Tools by Alan Donovan][11]. - -### Built-in testing and profiling framework - -Have you ever tried to pick a testing framework for a Javascript project you are starting from scratch? If so, you might understand that struggle of going through such an analysis paralysis. You might have also realized that you were not using like 80% of the framework you have chosen. - -The issue repeats over again once you need to do some reliable profiling. - -Go comes with a built-in testing tool designed for simplicity and efficiency. It provides you the simplest API possible, and makes minimum assumptions. You can use it for different kinds of testing, profiling, and even to provide executable code examples. - -It produces CI-friendly output out-of-box, and the usage is usually as easy as running `go test`. Of course, it also supports advanced features like running tests in parallel, marking them skipped, and many more. - -### Race condition detection - -You might already know about Goroutines, which are used in Go to achieve concurrent code execution. If you don’t, [here’s][12] a really brief explanation. - -Concurrent programming in complex applications is never easy regardless of the specific technique, partly due to the possibility of race conditions. - -Simply put, race conditions happen when several concurrent operations finish in an unpredicted order. It might lead to a huge number of bugs, which are particularly hard to chase down. Ever spent a day debugging an integration test which only worked in about 80% of executions? It probably was a race condition. - -All that said, concurrent programming is taken very seriously in Go and, luckily, we have quite a powerful tool to hunt those race conditions down. It is fully integrated into Go’s toolchain. - -You can read more about it and learn how to use it here: [Introducing the Go Race Detector — The Go Blog][13]. - -### Learning curve - -You can learn ALL Go’s language features in one evening. I mean it. Of course, there are also the standard library, and the best practices in different, more specific areas. But two hours would totally be enough time to get you confidently writing a simple HTTP server, or a command-line app. - -The project has [marvelous documentation][14], and most of the advanced topics have already been covered on their blog: [The Go Programming Language Blog][15]. - -Go is much easier to bring to your team than Java (and the family), Javascript, Ruby, Python, or even PHP. The environment is easy to setup, and the investment your team needs to make is much smaller before they can complete your first production code. - -### Reflection - -Code reflection is essentially an ability to sneak under the hood and access different kinds of meta-information about your language constructs, such as variables or functions. - -Given that Go is a statically typed language, it’s exposed to a number of various limitations when it comes to more loosely typed abstract programming. Especially compared to languages like Javascript or Python. - -Moreover, Go [doesn’t implement a concept called Generics][16] which makes it even more challenging to work with multiple types in an abstract way. Nevertheless, many people think it’s actually beneficial for the language because of the amount of complexity Generics bring along. And I totally agree. - -According to Go’s philosophy (which is a separate topic itself), you should try hard to not over-engineer your solutions. And this also applies to dynamically-typed programming. Stick to static types as much as possible, and use interfaces when you know exactly what sort of types you’re dealing with. Interfaces are very powerful and ubiquitous in Go. - -However, there are still cases in which you can’t possibly know what sort of data you are facing. A great example is JSON. You convert all the kinds of data back and forth in your applications. Strings, buffers, all sorts of numbers, nested structs and more. - -In order to pull that off, you need a tool to examine all the data in runtime that acts differently depending on its type and structure. Reflection to rescue! Go has a first-class [reflect][17] package to enable your code to be as dynamic as it would be in a language like Javascript. - -An important caveat is to know what price you pay for using it — and only use it when there is no simpler way. - -You can read more about it here: [The Laws of Reflection — The Go Blog][18]. - -You can also read some real code from the JSON package sources here: [src/encoding/json/encode.go — Source Code][19] - -### Opinionatedness - -Is there such a word, by the way? - -Coming from the Javascript world, one of the most daunting processes I faced was deciding which conventions and tools I needed to use. How should I style my code? What testing library should I use? How should I go about structure? What programming paradigms and approaches should I rely on? - -Which sometimes basically got me stuck. I was doing this instead of writing the code and satisfying the users. - -To begin with, I should note that I totally get where those conventions should come from. It’s always you and your team. Anyway, even a group of experienced Javascript developers can easily find themselves having most of the experience with entirely different tools and paradigms to achieve kind of the same results. - -This makes the analysis paralysis cloud explode over the whole team, and also makes it harder for the individuals to integrate with each other. - -Well, Go is different. You have only one style guide that everyone follows. You have only one testing framework which is built into the basic toolchain. You have a lot of strong opinions on how to structure and maintain your code. How to pick names. What structuring patterns to follow. How to do concurrency better. - -While this might seem too restrictive, it saves tons of time for you and your team. Being somewhat limited is actually a great thing when you are coding. It gives you a more straightforward way to go when architecting new code, and makes it easier to reason about the existing one. - -As a result, most of the Go projects look pretty alike code-wise. - -### Culture - -People say that every time you learn a new spoken language, you also soak in some part of the culture of the people who speak that language. Thus, the more languages you learn, more personal changes you might experience. - -It’s the same with programming languages. Regardless of how you are going to apply a new programming language in the future, it always gives you a new perspective on programming in general, or on some specific techniques. - -Be it functional programming, pattern matching, or prototypal inheritance. Once you’ve learned it, you carry these approaches with you which broadens the problem-solving toolset that you have as a software developer. It also changes the way you see high-quality programming in general. - -And Go is a terrific investment here. The main pillar of Go’s culture is keeping simple, down-to-earth code without creating many redundant abstractions and putting the maintainability at the top. It’s also a part of the culture to spend the most time actually working on the codebase, instead of tinkering with the tools and the environment. Or choosing between different variations of those. - -Go is also all about “there should be only one way of doing a thing.” - -A little side note. It’s also partially true that Go usually gets in your way when you need to build relatively complex abstractions. Well, I’d say that’s the tradeoff for its simplicity. - -If you really need to write a lot of abstract code with complex relationships, you’d be better off using languages like Java or Python. However, even when it’s not obvious, it’s very rarely the case. - -Always use the best tool for the job! - -### Conclusion - -You might have heard of Go before. Or maybe it’s something that has been staying out of your radar for a while. Either way, chances are, Go can be a very decent choice for you or your team when starting a new project or improving the existing one. - -This is not a complete list of all the amazing things about Go. Just the undervalued ones. - -Please, give Go a try with [A Tour of Go][20] which is an incredible place to start. - -If you wish to learn more about Go’s benefits, you can check out these links: - -* [Why should you learn Go? — Keval Patel — Medium][2] - -* [Farewell Node.js — TJ Holowaychuk — Medium][3] - -Share your observations down in the comments! - -Even if you are not specifically looking for a new language to use, it’s worth it to spend an hour or two getting the feel of it. And maybe it can become quite useful for you in the future. - -Always be looking for the best tools for your craft! - -* * * - -If you like this article, please consider following me for more, and clicking on those funny green little hands right below this text for sharing. 👏👏👏 - -Check out my [Github][21] and follow me on [Twitter][22]! - --------------------------------------------------------------------------------- - -作者简介: - -Software Engineer and Traveler. Coding for fun. Javascript enthusiast. Tinkering with Golang. A lot into SOA and Docker. Architect at Velvica. - ------------- - - -via: https://medium.freecodecamp.org/here-are-some-amazing-advantages-of-go-that-you-dont-hear-much-about-1af99de3b23a - -作者:[Kirill Rogovoy][a] -译者:[译者ID](https://github.com/译者ID) -校对:[校对者ID](https://github.com/校对者ID) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 - -[a]: -[1]:https://github.com/ashleymcnamara/gophers -[2]:https://medium.com/@kevalpatel2106/why-should-you-learn-go-f607681fad65 -[3]:https://medium.com/@tjholowaychuk/farewell-node-js-4ba9e7f3e52b -[4]:https://godoc.org/ -[5]:https://blog.golang.org/examples -[6]:https://godoc.org/github.com/kirillrogovoy/pullkee -[7]:https://godoc.org/ -[8]:https://golang.org/cmd/gofmt/ -[9]:https://github.com/golang/lint -[10]:https://github.com/alecthomas/gometalinter#supported-linters -[11]:https://vimeo.com/114736889 -[12]:https://gobyexample.com/goroutines -[13]:https://blog.golang.org/race-detector -[14]:https://golang.org/doc/ -[15]:https://blog.golang.org/ -[16]:https://golang.org/doc/faq#generics -[17]:https://golang.org/pkg/reflect/ -[18]:https://blog.golang.org/laws-of-reflection -[19]:https://golang.org/src/encoding/json/encode.go -[20]:https://tour.golang.org/ -[21]:https://github.com/kirillrogovoy/ -[22]:https://twitter.com/krogovoy \ No newline at end of file diff --git a/sources/tech/20180203 API Star- Python 3 API Framework - Polyglot.Ninja().md b/sources/tech/20180203 API Star- Python 3 API Framework - Polyglot.Ninja().md deleted file mode 100644 index 10bb70fe72..0000000000 --- a/sources/tech/20180203 API Star- Python 3 API Framework - Polyglot.Ninja().md +++ /dev/null @@ -1,259 +0,0 @@ -API Star: Python 3 API Framework – Polyglot.Ninja() -====== -For building quick APIs in Python, I have mostly depended on [Flask][1]. Recently I came across a new API framework for Python 3 named “API Star” which seemed really interesting to me for several reasons. Firstly the framework embraces modern Python features like type hints and asyncio. And then it goes ahead and uses these features to provide awesome development experience for us, the developers. We will get into those features soon but before we begin, I would like to thank Tom Christie for all the work he has put into Django REST Framework and now API Star. - -Now back to API Star – I feel very productive in the framework. I can choose to write async codes based on asyncio or I can choose a traditional backend like WSGI. It comes with a command line tool – `apistar` to help us get things done faster. There’s (optional) support for both Django ORM and SQLAlchemy. There’s a brilliant type system that enables us to define constraints on our input and output and from these, API Star can auto generate api schemas (and docs), provide validation and serialization feature and a lot more. Although API Star is heavily focused on building APIs, you can also build web applications on top of it fairly easily. All these might not make proper sense until we build something all by ourselves. - -### Getting Started - -We will start by installing API Star. It would be a good idea to create a virtual environment for this exercise. If you don’t know how to create a virtualenv, don’t worry and go ahead. -``` -pip install apistar - -``` - -If you’re not using a virtual environment or the `pip` command for your Python 3 is called `pip3`, then please use `pip3 install apistar` instead. - -Once we have the package installed, we should have access to the `apistar` command line tool. We can create a new project with it. Let’s create a new project in our current directory. -``` -apistar new . - -``` - -Now we should have two files created – `app.py` – which contains the main application and then `test.py` for our tests. Let’s examine our `app.py` file: -``` -from apistar import Include, Route -from apistar.frameworks.wsgi import WSGIApp as App -from apistar.handlers import docs_urls, static_urls - - -def welcome(name=None): - if name is None: - return {'message': 'Welcome to API Star!'} - return {'message': 'Welcome to API Star, %s!' % name} - - -routes = [ - Route('/', 'GET', welcome), - Include('/docs', docs_urls), - Include('/static', static_urls) -] - -app = App(routes=routes) - - -if __name__ == '__main__': - app.main() - -``` - -Before we dive into the code, let’s run the app and see if it works. If we navigate to `http://127.0.0.1:8080/` we will get this following response: -``` -{"message": "Welcome to API Star!"} - -``` - -And if we navigate to: `http://127.0.0.1:8080/?name=masnun` -``` -{"message": "Welcome to API Star, masnun!"} - -``` - -Similarly if we navigate to: `http://127.0.0.1:8080/docs/`, we will see auto generated docs for our API. - -Now let’s look at the code. We have a `welcome` function that takes a parameter named `name` which has a default value of `None`. API Star is a smart api framework. It will try to find the `name` key in the url path or query string and pass it to our function. It also generates the API docs based on it. Pretty nice, no? - -We then create a list of `Route` and `Include` instances and pass the list to the `App` instance. `Route` objects are used to define custom user routing. `Include` , as the name suggests, includes/embeds other routes under the path provided to it. - -### Routing - -Routing is simple. When constructing the `App` instance, we need to pass a list as the `routes` argument. This list should comprise of `Route` or `Include` objects as we just saw above. For `Route`s, we pass a url path, http method name and the request handler callable (function or otherwise). For the `Include` instances, we pass a url path and a list of `Routes` instance. - -##### Path Parameters - -We can put a name inside curly braces to declare a url path parameter. For example `/user/{user_id}` defines a path where the `user_id` is a path parameter or a variable which will be injected into the handler function (actually callable). Here’s a quick example: -``` -from apistar import Route -from apistar.frameworks.wsgi import WSGIApp as App - - -def user_profile(user_id: int): - return {'message': 'Your profile id is: {}'.format(user_id)} - - -routes = [ - Route('/user/{user_id}', 'GET', user_profile), -] - -app = App(routes=routes) - -if __name__ == '__main__': - app.main() - -``` - -If we visit `http://127.0.0.1:8080/user/23` we will get a response like this: -``` -{"message": "Your profile id is: 23"} - -``` - -But if we try to visit `http://127.0.0.1:8080/user/some_string` – it will not match. Because the `user_profile` function we defined, we added a type hint for the `user_id` parameter. If it’s not integer, the path doesn’t match. But if we go ahead and delete the type hint and just use `user_profile(user_id)`, it will match this url. This is again API Star is being smart and taking advantages of typing. - -#### Including / Grouping Routes - -Sometimes it might make sense to group certain urls together. Say we have a `user` module that deals with user related functionality. It might be better to group all the user related endpoints under the `/user` path. For example – `/user/new`, `/user/1`, `/user/1/update` and what not. We can easily create our handlers and routes in a separate module or package even and then include them in our own routes. - -Let’s create a new module named `user`, the file name would be `user.py`. Let’s put these codes in this file: -``` -from apistar import Route - - -def user_new(): - return {"message": "Create a new user"} - - -def user_update(user_id: int): - return {"message": "Update user #{}".format(user_id)} - - -def user_profile(user_id: int): - return {"message": "User Profile for: {}".format(user_id)} - - -user_routes = [ - Route("/new", "GET", user_new), - Route("/{user_id}/update", "GET", user_update), - Route("/{user_id}/profile", "GET", user_profile), -] - -``` - -Now we can import our `user_routes` from within our main app file and use it like this: -``` -from apistar import Include -from apistar.frameworks.wsgi import WSGIApp as App - -from user import user_routes - -routes = [ - Include("/user", user_routes) -] - -app = App(routes=routes) - -if __name__ == '__main__': - app.main() - -``` - -Now `/user/new` will delegate to `user_new` function. - -### Accessing Query String / Query Parameters - -Any parameters passed in the query parameters can be injected directly into handler function. Say for the url `/call?phone=1234`, the handler function can define a `phone` parameter and it will receive the value from the query string / query parameters. If the url query string doesn’t include a value for `phone`, it will get `None` instead. We can also set a default value to the parameter like this: -``` -def welcome(name=None): - if name is None: - return {'message': 'Welcome to API Star!'} - return {'message': 'Welcome to API Star, %s!' % name} - -``` - -In the above example, we set a default value to `name` which is `None` anyway. - -### Injecting Objects - -By type hinting a request handler, we can have different objects injected into our views. Injecting request related objects can be helpful for accessing them directly from inside the handler. There are several built in objects in the `http` package from API Star itself. We can also use it’s type system to create our own custom objects and have them injected into our functions. API Star also does data validation based on the constraints specified. - -Let’s define our own `User` type and have it injected in our request handler: -``` -from apistar import Include, Route -from apistar.frameworks.wsgi import WSGIApp as App -from apistar import typesystem - - -class User(typesystem.Object): - properties = { - 'name': typesystem.string(max_length=100), - 'email': typesystem.string(max_length=100), - 'age': typesystem.integer(maximum=100, minimum=18) - } - - required = ["name", "age", "email"] - - -def new_user(user: User): - return user - - -routes = [ - Route('/', 'POST', new_user), -] - -app = App(routes=routes) - -if __name__ == '__main__': - app.main() - -``` - -Now if we send this request: - -``` -curl -X POST \ - http://127.0.0.1:8080/ \ - -H 'Cache-Control: no-cache' \ - -H 'Content-Type: application/json' \ - -d '{"name": "masnun", "email": "masnun@gmail.com", "age": 12}' -``` - -Guess what happens? We get an error saying age must be equal to or greater than 18. The type system is allowing us intelligent data validation as well. If we enable the `docs` url, we will also get these parameters automatically documented there. - -### Sending a Response - -If you have noticed so far, we can just pass a dictionary and it will be JSON encoded and returned by default. However, we can set the status code and any additional headers by using the `Response` class from `apistar`. Here’s a quick example: -``` -from apistar import Route, Response -from apistar.frameworks.wsgi import WSGIApp as App - - -def hello(): - return Response( - content="Hello".encode("utf-8"), - status=200, - headers={"X-API-Framework": "API Star"}, - content_type="text/plain" - ) - - -routes = [ - Route('/', 'GET', hello), -] - -app = App(routes=routes) - -if __name__ == '__main__': - app.main() - -``` - -It should send a plain text response along with a custom header. Please note that the `content` should be bytes, not string. That’s why I encoded it. - -### Moving On - -I just walked through some of the features of API Star. There’s a lot more of cool stuff in API Star. I do recommend going through the [Github Readme][2] for learning more about different features offered by this excellent framework. I shall also try to cover short, focused tutorials on API Star in the coming days. - --------------------------------------------------------------------------------- - -via: http://polyglot.ninja/api-star-python-3-api-framework/ - -作者:[MASNUN][a] -译者:[译者ID](https://github.com/译者ID) -校对:[校对者ID](https://github.com/校对者ID) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 - -[a]:http://polyglot.ninja/author/masnun/ -[1]:http://polyglot.ninja/rest-api-best-practices-python-flask-tutorial/ -[2]:https://github.com/encode/apistar diff --git a/sources/tech/20180205 Writing eBPF tracing tools in Rust.md b/sources/tech/20180205 Writing eBPF tracing tools in Rust.md index 18b8eb5742..093d3de215 100644 --- a/sources/tech/20180205 Writing eBPF tracing tools in Rust.md +++ b/sources/tech/20180205 Writing eBPF tracing tools in Rust.md @@ -1,3 +1,4 @@ +Zafiry translating... Writing eBPF tracing tools in Rust ============================================================ diff --git a/sources/tech/20180215 Build a bikesharing app with Redis and Python.md b/sources/tech/20180215 Build a bikesharing app with Redis and Python.md index 67ddd07730..06e4c6949a 100644 --- a/sources/tech/20180215 Build a bikesharing app with Redis and Python.md +++ b/sources/tech/20180215 Build a bikesharing app with Redis and Python.md @@ -1,5 +1,3 @@ -hankchow translating - Build a bikesharing app with Redis and Python ====== diff --git a/sources/tech/20180226 Linux Virtual Machines vs Linux Live Images.md b/sources/tech/20180226 Linux Virtual Machines vs Linux Live Images.md deleted file mode 100644 index f846e9486d..0000000000 --- a/sources/tech/20180226 Linux Virtual Machines vs Linux Live Images.md +++ /dev/null @@ -1,58 +0,0 @@ -Linux Virtual Machines vs Linux Live Images -====== -I'll be the first to admit that I tend to try out new [Linux distros][1] on a far too frequent basis. Yet the method I use to test them, does vary depending on my goals for each instance. In this article, we're going to look at both running Linux virtual machines and running Linux live images. There are advantages to each method, but there are some hurdles with each method as well. - -### Testing out a new Linux distro for the first time - -When I test out a brand new Linux distro for the first time, the method I use depends heavily on the resources of the PC I'm currently on. If I have access to my desktop PC, I'm going to run the distro to be tested in a virtual machine. The reason for this approach is that I can download and test the distro in not only a live environment, but also as an installed product with persistent storage abilities. - -On the other hand, if I am working with much less robust hardware on a PC, then testing out a distro with a virtual machine installation of Linux is counter-productive. I'd be pushing that PC to its limits and honestly would be better off using a live Linux image instead running from a flash drive. - -### Touring software on a new Linux distro - -If you're interested in checking out a distro's desktop environment or the available software, you can't go wrong with a live image of the distro. A live environment provides you with a birds eye view of what to expect in terms of overall layout, applications provided and how the user experience flows overall. - -To be fair, you could do the same thing with a virtual machine installation, but it may be a bit overkill if you would rather avoid filling up hard drive space with yet more data. After all, this is a simple tour of the distro. Remember what I said in the first section – I like to run Linux in a virtual machine to test it. This means I'm going to see how it installs, what the partition options look like and other elements you wouldn't see from using a live image of any given distro. - -Touring usually indicates that you're only looking to take a quick look at a distro, so in this case the method that can be done with the least amount of resistance and time investment is a good course of action. - -### Taking a Linux distro with you - -While it's not as common as it was a few years ago, the ability to take a Linux distro with you may be a consideration for some users. Obviously, virtual machine installations don't necessarily lend themselves favorably to portability. However a live image of a Linux distro is actually quite portable. A live image can be written to a DVD or copied onto a flash drive for easy traveling. - -Expanding on this concept of Linux portability, it's also beneficial to have a live image on a flash drive when showing off how Linux works on a friend's computer. This empowers you to demonstrate how Linux can enrich their life while not relying on running a virtual machine on their PC. It's a bit of a win-win in favor of using a live image. - -### Alternative to dual-booting Linux - -This next item is a huge one. Consider this – perhaps you're a Windows user. You like playing with Linux, but would rather not take the plunge. Dual-booting is out of the question in case something goes wrong or perhaps you're not comfortable identifying individual partitions. Whatever the case may be, both using Linux in a virtual machine or from a live image might be a great option for you. - -Now I'm going to take a rather odd stance on something. I think you'll get far more value in the long term running Linux on a flash drive using a live image than with a virtual machine. There are two reasons for this. First of all, you'll get used to truly running Linux vs running it inside of a virtual machine on top of Windows. Second, you can setup your flash drive to contain user data with persistent storage. - -I'll grant you the same could be said with a virtual machine running Linux, however you will never have an update break anything using the live image approach. Why? Because you're not updating a host OS or the guest OS. Remember there are entire distros that are designed to be nothing more than persistent storage Linux distros. Puppy Linux is one great example. Not only can it run on PCs that would otherwise be recycled or thrown away, it allows you to never be bothered again with tedious system updates thanks to the way the distro handles security. It's not a normal Linux distro and it's walled off in such a way that the persistent live image is free from anything scary. - -### When a Linux virtual machine is absolutely the best option - -As I bring this article to a close, let me leave you with this. There is one instance where using a virtual machine such as Virtual Box is absolutely better than using a live image – recording the desktop environment of any Linux distro. - -For example, I make videos that provide a tour and review of a variety of Linux distros. Doing this with live images would require me to capture the screen with a hardware device or install a software capture device from the live image's repositories. Clearly, a virtual machine is better suited for this job than a live image of a Linux distro. - -Once you toss audio capture into the mix, there is no question that if you're going to use software to capture your review, you really want to have a host OS that has all the basic needs covered for a reasonably decent capture environment. Again, you could do all of this with a hardware device...but that might be cost prohibitive if you're only do video/audio capturing as a part time endeavor. - -### A Linux virtual machine vs a Linux live image - -What is your preferred method of trying out new distros? Perhaps you're someone who is fine with formatting their hard drive and throwing caution to the wind, thus, making the idea of any of this unneeded? - -Most people I've interacted with online tend to follow much of the methodology I've touched on above, but I'd love to hear what approach works best for you. Hit the comments, let me know which method you prefer when checking out the greatest and latest from the Linux distro world. - --------------------------------------------------------------------------------- - -via: https://www.datamation.com/open-source/linux-virtual-machines-vs-linux-live-images.html - -作者:[Matt Hartley][a] -译者:[译者ID](https://github.com/译者ID) -校对:[校对者ID](https://github.com/校对者ID) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 - -[a]:https://www.datamation.com/author/Matt-Hartley-3080.html -[1]:https://www.datamation.com/open-source/best-linux-distro.html diff --git a/sources/tech/20180306 How To Check All Running Services In Linux.md b/sources/tech/20180306 How To Check All Running Services In Linux.md deleted file mode 100644 index 7baf3c3e14..0000000000 --- a/sources/tech/20180306 How To Check All Running Services In Linux.md +++ /dev/null @@ -1,516 +0,0 @@ -How To Check All Running Services In Linux -====== - -There are many ways and tools to check and list all running services in Linux. Usually most of the administrator use `service service-name status` or `/etc/init.d/service-name status` for sysVinit system and `systemctl status service-name` for systemd systems. - -The above command clearly shows that the mentioned service is running on server or not. It is very simple and basic command that should known by every Linux administrator. - -If you are new to your environment and you don’t know what services are running on the system. How do you check? - -Yes, we can check this. This will will help us to understand what are the services are running on the system and whether it’s necessary or need to disable. - -### What Is SysVinit - -init (short for initialization) is the first process started during booting of the computer system. Init is a daemon process that continues running until the system is shut down. - -SysVinit is an old and traditional init system and system manager for old systems. Most of the latest distributions were adapted to systemd system due to some of the long pending issues on sysVinit system. - -### What Is systemd - -systemd is a new init system and system manager which is become very popular and widely adapted new standard init system by most of Linux distributions. Systemctl is a systemd utility which is help us to manage systemd system. - -### Method-1: How To Check Running Services In sysVinit System - -The below command helps us to check and list all running services in sysVinit system. - -If you have many number of services, i would advise you to use file view commands such as less, more, etc commands for clear view. -``` -# service --status-all -or -# service --status-all | more -or -# service --status-all | less - -abrt-ccpp hook is installed -abrtd (pid 2131) is running... -abrt-dump-oops is stopped -acpid (pid 1958) is running... -atd (pid 2164) is running... -auditd (pid 1731) is running... -Frequency scaling enabled using ondemand governor -crond (pid 2153) is running... -hald (pid 1967) is running... -htcacheclean is stopped -httpd is stopped -Table: filter -Chain INPUT (policy ACCEPT) -num target prot opt source destination -1 ACCEPT all ::/0 ::/0 state RELATED,ESTABLISHED -2 ACCEPT icmpv6 ::/0 ::/0 -3 ACCEPT all ::/0 ::/0 -4 ACCEPT tcp ::/0 ::/0 state NEW tcp dpt:80 -5 ACCEPT tcp ::/0 ::/0 state NEW tcp dpt:21 -6 ACCEPT tcp ::/0 ::/0 state NEW tcp dpt:22 -7 ACCEPT tcp ::/0 ::/0 state NEW tcp dpt:25 -8 ACCEPT tcp ::/0 ::/0 state NEW tcp dpt:2082 -9 ACCEPT tcp ::/0 ::/0 state NEW tcp dpt:2086 -10 ACCEPT tcp ::/0 ::/0 state NEW tcp dpt:2083 -11 ACCEPT tcp ::/0 ::/0 state NEW tcp dpt:2087 -12 ACCEPT tcp ::/0 ::/0 state NEW tcp dpt:10000 -13 REJECT all ::/0 ::/0 reject-with icmp6-adm-prohibited - -Chain FORWARD (policy ACCEPT) -num target prot opt source destination -1 REJECT all ::/0 ::/0 reject-with icmp6-adm-prohibited - -Chain OUTPUT (policy ACCEPT) -num target prot opt source destination - -iptables: Firewall is not running. -irqbalance (pid 1826) is running... -Kdump is operational -lvmetad is stopped -mdmonitor is stopped -messagebus (pid 1929) is running... - SUCCESS! MySQL running (24376) -rndc: neither /etc/rndc.conf nor /etc/rndc.key was found -named is stopped -netconsole module not loaded -Usage: startup.sh { start | stop } -Configured devices: -lo eth0 eth1 -Currently active devices: -lo eth0 -ntpd is stopped -portreserve (pid 1749) is running... -master (pid 2107) is running... -Process accounting is disabled. -quota_nld is stopped -rdisc is stopped -rngd is stopped -rpcbind (pid 1840) is running... -rsyslogd (pid 1756) is running... -sandbox is stopped -saslauthd is stopped -smartd is stopped -openssh-daemon (pid 9859) is running... -svnserve is stopped -vsftpd (pid 4008) is running... -xinetd (pid 2031) is running... -zabbix_agentd (pid 2150 2149 2148 2147 2146 2140) is running... - -``` - -Run the following command to view only running services in the system. -``` -# service --status-all | grep running - -crond (pid 535) is running... -httpd (pid 627) is running... -mysqld (pid 911) is running... -rndc: neither /etc/rndc.conf nor /etc/rndc.key was found -rsyslogd (pid 449) is running... -saslauthd (pid 492) is running... -sendmail (pid 509) is running... -sm-client (pid 519) is running... -openssh-daemon (pid 478) is running... -xinetd (pid 485) is running... - -``` - -Run the following command to view the particular service status. -``` -# service --status-all | grep httpd -httpd (pid 627) is running... - -``` - -Alternatively use the following command to view the particular service status. -``` -# service httpd status - -httpd (pid 627) is running... - -``` - -Use the following command to view the list of running services enabled in boot. -``` -# chkconfig --list -crond 0:off 1:off 2:on 3:on 4:on 5:on 6:off -htcacheclean 0:off 1:off 2:off 3:off 4:off 5:off 6:off -httpd 0:off 1:off 2:off 3:on 4:off 5:off 6:off -ip6tables 0:off 1:off 2:on 3:off 4:on 5:on 6:off -iptables 0:off 1:off 2:on 3:on 4:on 5:on 6:off -modules_dep 0:off 1:off 2:on 3:on 4:on 5:on 6:off -mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off -named 0:off 1:off 2:off 3:off 4:off 5:off 6:off -netconsole 0:off 1:off 2:off 3:off 4:off 5:off 6:off -netfs 0:off 1:off 2:off 3:off 4:on 5:on 6:off -network 0:off 1:off 2:on 3:on 4:on 5:on 6:off -nmb 0:off 1:off 2:off 3:off 4:off 5:off 6:off -nscd 0:off 1:off 2:off 3:off 4:off 5:off 6:off -portreserve 0:off 1:off 2:on 3:off 4:on 5:on 6:off -quota_nld 0:off 1:off 2:off 3:off 4:off 5:off 6:off -rdisc 0:off 1:off 2:off 3:off 4:off 5:off 6:off -restorecond 0:off 1:off 2:off 3:off 4:off 5:off 6:off -rpcbind 0:off 1:off 2:on 3:off 4:on 5:on 6:off -rsyslog 0:off 1:off 2:on 3:on 4:on 5:on 6:off -saslauthd 0:off 1:off 2:off 3:on 4:off 5:off 6:off -sendmail 0:off 1:off 2:on 3:on 4:on 5:on 6:off -smb 0:off 1:off 2:off 3:off 4:off 5:off 6:off -snmpd 0:off 1:off 2:off 3:off 4:off 5:off 6:off -snmptrapd 0:off 1:off 2:off 3:off 4:off 5:off 6:off -sshd 0:off 1:off 2:on 3:on 4:on 5:on 6:off -udev-post 0:off 1:on 2:on 3:off 4:on 5:on 6:off -winbind 0:off 1:off 2:off 3:off 4:off 5:off 6:off -xinetd 0:off 1:off 2:off 3:on 4:on 5:on 6:off - -xinetd based services: - chargen-dgram: off - chargen-stream: off - daytime-dgram: off - daytime-stream: off - discard-dgram: off - discard-stream: off - echo-dgram: off - echo-stream: off - finger: off - ntalk: off - rsync: off - talk: off - tcpmux-server: off - time-dgram: off - time-stream: off - -``` - -### Method-2: How To Check Running Services In systemd System - -The below command helps us to check and list all running services in “systemd” system. -``` -# systemctl - - UNIT LOAD ACTIVE SUB DESCRIPTION - sys-devices-virtual-block-loop0.device loaded active plugged /sys/devices/virtual/block/loop0 - sys-devices-virtual-block-loop1.device loaded active plugged /sys/devices/virtual/block/loop1 - sys-devices-virtual-block-loop2.device loaded active plugged /sys/devices/virtual/block/loop2 - sys-devices-virtual-block-loop3.device loaded active plugged /sys/devices/virtual/block/loop3 - sys-devices-virtual-block-loop4.device loaded active plugged /sys/devices/virtual/block/loop4 - sys-devices-virtual-misc-rfkill.device loaded active plugged /sys/devices/virtual/misc/rfkill - sys-devices-virtual-tty-ttyprintk.device loaded active plugged /sys/devices/virtual/tty/ttyprintk - sys-module-fuse.device loaded active plugged /sys/module/fuse - sys-subsystem-net-devices-enp0s3.device loaded active plugged 82540EM Gigabit Ethernet Controller (PRO/1000 MT Desktop Adapter) - -.mount loaded active mounted Root Mount - dev-hugepages.mount loaded active mounted Huge Pages File System - dev-mqueue.mount loaded active mounted POSIX Message Queue File System - run-user-1000-gvfs.mount loaded active mounted /run/user/1000/gvfs - run-user-1000.mount loaded active mounted /run/user/1000 - snap-core-3887.mount loaded active mounted Mount unit for core - snap-core-4017.mount loaded active mounted Mount unit for core - snap-core-4110.mount loaded active mounted Mount unit for core - snap-gping-13.mount loaded active mounted Mount unit for gping - snap-termius\x2dapp-8.mount loaded active mounted Mount unit for termius-app - sys-fs-fuse-connections.mount loaded active mounted FUSE Control File System - sys-kernel-debug.mount loaded active mounted Debug File System - acpid.path loaded active running ACPI Events Check - cups.path loaded active running CUPS Scheduler - systemd-ask-password-plymouth.path loaded active waiting Forward Password Requests to Plymouth Directory Watch - systemd-ask-password-wall.path loaded active waiting Forward Password Requests to Wall Directory Watch - init.scope loaded active running System and Service Manager - session-c2.scope loaded active running Session c2 of user magi - accounts-daemon.service loaded active running Accounts Service - acpid.service loaded active running ACPI event daemon - anacron.service loaded active running Run anacron jobs - apache2.service loaded active running The Apache HTTP Server - apparmor.service loaded active exited AppArmor initialization - apport.service loaded active exited LSB: automatic crash report generation - aptik-battery-monitor.service loaded active running LSB: start/stop the aptik battery monitor daemon - atop.service loaded active running Atop advanced performance monitor - atopacct.service loaded active running Atop process accounting daemon - avahi-daemon.service loaded active running Avahi mDNS/DNS-SD Stack - colord.service loaded active running Manage, Install and Generate Color Profiles - console-setup.service loaded active exited Set console font and keymap - cron.service loaded active running Regular background program processing daemon - cups-browsed.service loaded active running Make remote CUPS printers available locally - cups.service loaded active running CUPS Scheduler - dbus.service loaded active running D-Bus System Message Bus - postfix.service loaded active exited Postfix Mail Transport Agent - -``` - - * **`UNIT`** Unit describe about the corresponding systemd unit name. - * **`LOAD`** This describes whether the corresponding unit currently loaded in memory or not. - * **`ACTIVE`** It’s indicate whether the unit is active or not. - * **`SUB`** It’s indicate whether the unit is running state or not. - * **`DESCRIPTION`** A short description about the unit. - - - -The below option help you to list units based on the type. -``` -# systemctl list-units --type service - UNIT LOAD ACTIVE SUB DESCRIPTION - accounts-daemon.service loaded active running Accounts Service - acpid.service loaded active running ACPI event daemon - anacron.service loaded active running Run anacron jobs - apache2.service loaded active running The Apache HTTP Server - apparmor.service loaded active exited AppArmor initialization - apport.service loaded active exited LSB: automatic crash report generation - aptik-battery-monitor.service loaded active running LSB: start/stop the aptik battery monitor daemon - atop.service loaded active running Atop advanced performance monitor - atopacct.service loaded active running Atop process accounting daemon - avahi-daemon.service loaded active running Avahi mDNS/DNS-SD Stack - colord.service loaded active running Manage, Install and Generate Color Profiles - console-setup.service loaded active exited Set console font and keymap - cron.service loaded active running Regular background program processing daemon - cups-browsed.service loaded active running Make remote CUPS printers available locally - cups.service loaded active running CUPS Scheduler - dbus.service loaded active running D-Bus System Message Bus - fwupd.service loaded active running Firmware update daemon - [email protected] loaded active running Getty on tty1 - grub-common.service loaded active exited LSB: Record successful boot for GRUB - irqbalance.service loaded active running LSB: daemon to balance interrupts for SMP systems - keyboard-setup.service loaded active exited Set the console keyboard layout - kmod-static-nodes.service loaded active exited Create list of required static device nodes for the current kernel - -``` - -The below option help you to list units based on the state. It’s similar to the above output but straight forward. -``` -# systemctl list-unit-files --type service - -UNIT FILE STATE -accounts-daemon.service enabled -acpid.service disabled -alsa-restore.service static -alsa-state.service static -alsa-utils.service masked -anacron-resume.service enabled -anacron.service enabled -apache-htcacheclean.service disabled -[email protected] disabled -apache2.service enabled -[email protected] disabled -apparmor.service enabled -[email protected] static -apport.service generated -apt-daily-upgrade.service static -apt-daily.service static -aptik-battery-monitor.service generated -atop.service enabled -atopacct.service enabled -[email protected] enabled -avahi-daemon.service enabled -bluetooth.service enabled - -``` - -Run the following command to view the particular service status. -``` -# systemctl | grep apache2 - apache2.service loaded active running The Apache HTTP Server - -``` - -Alternatively use the following command to view the particular service status. -``` -# systemctl status apache2 -● apache2.service - The Apache HTTP Server - Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled) - Drop-In: /lib/systemd/system/apache2.service.d - └─apache2-systemd.conf - Active: active (running) since Tue 2018-03-06 12:34:09 IST; 8min ago - Process: 2786 ExecReload=/usr/sbin/apachectl graceful (code=exited, status=0/SUCCESS) - Main PID: 1171 (apache2) - Tasks: 55 (limit: 4915) - CGroup: /system.slice/apache2.service - ├─1171 /usr/sbin/apache2 -k start - ├─2790 /usr/sbin/apache2 -k start - └─2791 /usr/sbin/apache2 -k start - -Mar 06 12:34:08 magi-VirtualBox systemd[1]: Starting The Apache HTTP Server... -Mar 06 12:34:09 magi-VirtualBox apachectl[1089]: AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 10.0.2.15. Set the 'ServerName' directive globally to suppre -Mar 06 12:34:09 magi-VirtualBox systemd[1]: Started The Apache HTTP Server. -Mar 06 12:39:10 magi-VirtualBox systemd[1]: Reloading The Apache HTTP Server. -Mar 06 12:39:10 magi-VirtualBox apachectl[2786]: AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using fe80::7929:4ed1:279f:4d65. Set the 'ServerName' directive gl -Mar 06 12:39:10 magi-VirtualBox systemd[1]: Reloaded The Apache HTTP Server. - -``` - -Run the following command to view only running services in the system. -``` -# systemctl | grep running - acpid.path loaded active running ACPI Events Check - cups.path loaded active running CUPS Scheduler - init.scope loaded active running System and Service Manager - session-c2.scope loaded active running Session c2 of user magi - accounts-daemon.service loaded active running Accounts Service - acpid.service loaded active running ACPI event daemon - apache2.service loaded active running The Apache HTTP Server - aptik-battery-monitor.service loaded active running LSB: start/stop the aptik battery monitor daemon - atop.service loaded active running Atop advanced performance monitor - atopacct.service loaded active running Atop process accounting daemon - avahi-daemon.service loaded active running Avahi mDNS/DNS-SD Stack - colord.service loaded active running Manage, Install and Generate Color Profiles - cron.service loaded active running Regular background program processing daemon - cups-browsed.service loaded active running Make remote CUPS printers available locally - cups.service loaded active running CUPS Scheduler - dbus.service loaded active running D-Bus System Message Bus - fwupd.service loaded active running Firmware update daemon - [email protected] loaded active running Getty on tty1 - irqbalance.service loaded active running LSB: daemon to balance interrupts for SMP systems - lightdm.service loaded active running Light Display Manager - ModemManager.service loaded active running Modem Manager - NetworkManager.service loaded active running Network Manager - polkit.service loaded active running Authorization Manager - -``` - -Use the following command to view the list of running services enabled in boot. -``` -# systemctl list-unit-files | grep enabled -acpid.path enabled -cups.path enabled -accounts-daemon.service enabled -anacron-resume.service enabled -anacron.service enabled -apache2.service enabled -apparmor.service enabled -atop.service enabled -atopacct.service enabled -[email protected] enabled -avahi-daemon.service enabled -bluetooth.service enabled -console-setup.service enabled -cron.service enabled -cups-browsed.service enabled -cups.service enabled -display-manager.service enabled -dns-clean.service enabled -friendly-recovery.service enabled -[email protected] enabled -gpu-manager.service enabled -keyboard-setup.service enabled -lightdm.service enabled -ModemManager.service enabled -network-manager.service enabled -networking.service enabled -NetworkManager-dispatcher.service enabled -NetworkManager-wait-online.service enabled -NetworkManager.service enabled - -``` - -systemd-cgtop show top control groups by their resource usage such as tasks, CPU, Memory, Input, and Output. -``` -# systemd-cgtop - -Control Group Tasks %CPU Memory Input/s Output/s -/ - - 1.5G - - -/init.scope 1 - - - - -/system.slice 153 - - - - -/system.slice/ModemManager.service 3 - - - - -/system.slice/NetworkManager.service 4 - - - - -/system.slice/accounts-daemon.service 3 - - - - -/system.slice/acpid.service 1 - - - - -/system.slice/apache2.service 55 - - - - -/system.slice/aptik-battery-monitor.service 1 - - - - -/system.slice/atop.service 1 - - - - -/system.slice/atopacct.service 1 - - - - -/system.slice/avahi-daemon.service 2 - - - - -/system.slice/colord.service 3 - - - - -/system.slice/cron.service 1 - - - - -/system.slice/cups-browsed.service 3 - - - - -/system.slice/cups.service 2 - - - - -/system.slice/dbus.service 6 - - - - -/system.slice/fwupd.service 5 - - - - -/system.slice/irqbalance.service 1 - - - - -/system.slice/lightdm.service 7 - - - - -/system.slice/polkit.service 3 - - - - -/system.slice/repowerd.service 14 - - - - -/system.slice/rsyslog.service 4 - - - - -/system.slice/rtkit-daemon.service 3 - - - - -/system.slice/snapd.service 8 - - - - -/system.slice/system-getty.slice 1 - - - - - -``` - -Also we can check the running services using pstree command (Output from SysVinit system). -``` -# pstree -init-|-crond - |-httpd---2*[httpd] - |-kthreadd/99149---khelper/99149 - |-2*[mingetty] - |-mysqld_safe---mysqld---9*[{mysqld}] - |-rsyslogd---3*[{rsyslogd}] - |-saslauthd---saslauthd - |-2*[sendmail] - |-sshd---sshd---bash---pstree - |-udevd - `-xinetd - -``` - -Also we can check the running services using pstree command (Output from systemd system). -``` -# pstree -systemd─┬─ModemManager─┬─{gdbus} - │ └─{gmain} - ├─NetworkManager─┬─dhclient - │ ├─{gdbus} - │ └─{gmain} - ├─accounts-daemon─┬─{gdbus} - │ └─{gmain} - ├─acpid - ├─agetty - ├─anacron - ├─apache2───2*[apache2───26*[{apache2}]] - ├─aptd───{gmain} - ├─aptik-battery-m - ├─atop - ├─atopacctd - ├─avahi-daemon───avahi-daemon - ├─colord─┬─{gdbus} - │ └─{gmain} - ├─cron - ├─cups-browsed─┬─{gdbus} - │ └─{gmain} - ├─cupsd - ├─dbus-daemon - ├─fwupd─┬─{GUsbEventThread} - │ ├─{fwupd} - │ ├─{gdbus} - │ └─{gmain} - ├─gnome-keyring-d─┬─{gdbus} - │ ├─{gmain} - │ └─{timer} - -``` - -### Method-3: How To Check Running Services In systemd System using chkservice - -chkservice is a new tool for managing systemd units in terminal. It requires super user privileges to manage the units. -``` -# chkservice - -``` - -![][1] - -To view help page, hit `?` button. This will shows you available options to manage the systemd services. -![][2] - --------------------------------------------------------------------------------- - -via: https://www.2daygeek.com/how-to-check-all-running-services-in-linux/ - -作者:[Magesh Maruthamuthu][a] -译者:[译者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/ -[1]:https://www.2daygeek.com/wp-content/uploads/2018/03/chkservice-1.png -[2]:https://www.2daygeek.com/wp-content/uploads/2018/03/chkservice-2.png diff --git a/sources/tech/20180313 Migrating to Linux- Using Sudo.md b/sources/tech/20180313 Migrating to Linux- Using Sudo.md deleted file mode 100644 index 7ad9426ab8..0000000000 --- a/sources/tech/20180313 Migrating to Linux- Using Sudo.md +++ /dev/null @@ -1,84 +0,0 @@ -translating---geekpi - -Migrating to Linux: Using Sudo -====== - -![](https://www.linux.com/sites/lcom/files/styles/rendered_file/public/ray-hennessy-233438-unsplash.jpg?itok=d4l7QUtF) - -This article is the fifth in our series about migrating to Linux. If you missed earlier ones, you can catch up here: - -[Part 1 - An Introduction][1] - -[Part 2 - Disks, Files, and Filesystems][2] - -[Part 3 - Graphical Environments][3] - -[Part 4 - The Command Line][4] - -You may have been wondering about Linux for a while. Perhaps it's used in your workplace and you'd be more efficient at your job if you used it on a daily basis. Or, perhaps you'd like to install Linux on some computer equipment you have at home. Whatever the reason, this series of articles is here to make the transition easier. - -Linux, like many other operating systems supports multiple users. It even supports multiple users being logged in simultaneously. - -User accounts are typically assigned a home directory where files can be stored. Usually this home directory is in: -``` -/home/ - -``` - -This way, each user has their own separate location for their documents and other files. - -### Admin Tasks - -In a traditional Linux installation, regular user accounts don't have permissions to perform administrative tasks on the system. And instead of assigning rights to each user to perform various tasks, a typical Linux installation will require a user to log in as the admin to do certain tasks. - -The administrator account on Linux is called root. - -### Sudo Explained - -Historically, to perform admin tasks, one would have to login as root, perform the task, and then log back out. This process was a bit tedious, so many folks logged in as root and worked all day long as the admin. This practice could lead to disastrous results, for example, accidentally deleting all the files in the system. The root user, of course, can do anything, so there are no protections to prevent someone from accidentally performing far-reaching actions. - -The sudo facility was created to make it easier to login as your regular user account and occasionally perform admin tasks as root without having to login, do the task, and log back out. Specifically, sudo allows you to run a command as a different user. If you don't specify a specific user, it assumes you mean root. - -Sudo can have complex settings to allow users certain permissions to use sudo for some commands but not for others. Typically, a desktop installation will make it so the first account created has full permissions in sudo, so you as the primary user can fully administer your Linux installation. - -### Using Sudo - -Some Linux installations set up sudo so that you still need to know the password for the root account to perform admin tasks. Others, set up sudo so that you type in your own password. There are different philosophies here. - -When you try to perform an admin task in the graphical environment, it will usually open a dialog box asking for a password. Enter either your own password (e.g., on Ubuntu), or the root account's password (e.g., Red Hat). - -When you try to perform an admin task in the command line, it will usually just give you a "permission denied" error. Then you would re-run the command with sudo in front. For example: -``` -systemctl start vsftpd -Failed to start vsftpd.service: Access denied - -sudo systemctl start vsftpd -[sudo] password for user1: - -``` - -### When to Use Sudo - -Running commands as root (under sudo or otherwise) is not always the best solution to get around permission errors. While will running as root will remove the "permission denied" errors, it's sometimes best to look for the root cause rather than just addressing the symptom. Sometimes files have the wrong owner and permissions. - -Use sudo when you are trying to perform a task or run a program and the program requires root privileges to perform the operation. Don't use sudo if the file just happens to be owned by another user (including root). In this second case, it's better to set the permission on the file correctly. - -Learn more about Linux through the free ["Introduction to Linux" ][5]course from The Linux Foundation and edX. - --------------------------------------------------------------------------------- - -via: https://www.linux.com/blog/learn/2018/3/migrating-linux-using-sudo - -作者:[John Bonesio][a] -选题:[lujun9972](https://github.com/lujun9972) -译者:[译者ID](https://github.com/译者ID) -校对:[校对者ID](https://github.com/校对者ID) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 - -[a]:https://www.linux.com/users/johnbonesio -[1]:https://www.linux.com/blog/learn/intro-to-linux/2017/10/migrating-linux-introduction -[2]:https://www.linux.com/blog/learn/intro-to-linux/2017/11/migrating-linux-disks-files-and-filesystems -[3]:https://www.linux.com/blog/learn/2017/12/migrating-linux-graphical-environments -[4]:https://www.linux.com/blog/learn/2018/1/migrating-linux-command-line -[5]:https://training.linuxfoundation.org/linux-courses/system-administration-training/introduction-to-linux diff --git a/sources/tech/20180316 How to Encrypt Files From Within a File Manager.md b/sources/tech/20180316 How to Encrypt Files From Within a File Manager.md deleted file mode 100644 index 491c18eb04..0000000000 --- a/sources/tech/20180316 How to Encrypt Files From Within a File Manager.md +++ /dev/null @@ -1,179 +0,0 @@ -How to Encrypt Files From Within a File Manager -====== - -![](https://www.linux.com/sites/lcom/files/styles/rendered_file/public/encryption.jpg?itok=Pk3_x5hz) -The Linux desktop and server enjoys a remarkable level of security. That doesn’t mean, however, you should simply rest easy. You should always consider that your data is always a quick hack away from being compromised. That being said, you might want to employ various tools for encryption, such as GnuPG, which lets you encrypt and decrypt files and much more. One problem with GnuPG is that some users don’t want to mess with the command line. If that’s the case, you can turn to a desktop file manager. Many Linux desktops include the ability to easily encrypt or decrypt files, and if that capability is not built in, it’s easy to add. - -I will walk you through the process of encrypting and decrypting a file from within three popular Linux file managers: - - * Nautilus (aka GNOME Files) - - * Dolphin - - * Thunar - - - - -### Installing GnuPG - -Before we get into the how to of this, we have to ensure your system includes the necessary base component… [GnuPG][1]. Most distributions ship with GnuPG included. On the off chance you use a distribution that doesn’t ship with GnuPG, here’s how to install it: - - * Ubuntu-based distribution: sudo apt install gnupg - - * Fedora-based distribution: sudo yum install gnupg - - * openSUSE: sudo zypper in gnupg - - * Arch-based distribution: sudo pacman -S gnupg - - - - -Whether you’ve just now installed GnuPG or it was installed by default, you will have to create a GPG key for this to work. Each desktop uses a different GUI tool for this (or may not even include a GUI tool for the task), so let’s create that key from the command line. Open up your terminal window and issue the following command: -``` -gpg --gen-key - -``` - -You will then be asked to answer the following questions. Unless you have good reason, you can accept the defaults: - - * What kind of key do you want? - - * What key size do you want? - - * Key is valid for? - - - - -Once you’ve answered these questions, type y to indicate the answers are correct. Next you’ll need to supply the following information: - - * Real name. - - * Email address. - - * Comment. - - - - -Complete the above and then, when prompted, type O (for Okay). You will then be required to type a passphrase for the new key. Once the system has collected enough entropy (you’ll need to do some work on the desktop so this can happen), your key will have been created and you’re ready to go. - -Let’s see how to encrypt/decrypt files from within the file managers. - -### Nautilus - -We start with the default GNOME file manager because it is the easiest. Nautilus requires no extra installation or extra work to encrypt/decrypt files from within it’s well-designed interface. Once you have your gpg key created, you can open up the file manager, navigate to the directory housing the file to be encrypted, right-click the file in question, and select Encrypt from the menu (Figure 1). - - -![nautilus][3] - -Figure 1: Encrypting a file from within Nautilus. - -[Used with permission][4] - -You will be asked to select a recipient (or list of recipients — Figure 2). NOTE: Recipients will be those users whose public keys you have imported. Select the necessary keys and then select your key (email address) from the Sign message as drop-down. - -![nautilus][6] - -Figure 2: Selecting recipients and a signer. - -[Used with permission][4] - -Notice you can also opt to encrypt the file with only a passphrase. This is important if the file will remain on your local machine (more on this later). Once you’ve set up the encryption, click OK and (when prompted) type the passphrase for your key. The file will be encrypted (now ending in .gpg) and saved in the working directory. You can now send that encrypted file to the recipients you selected during the encryption process. - -Say someone (who has your public key) has sent you an encrypted file. Save that file, open the file manager, navigate to the directory housing that file, right-click the encrypted file, select Open With Decrypt File, give the file a new name (without the .gpg extension), and click Save. When prompted, type your gpg key passphrase and the file will be decrypted and ready to use. - -### Dolphin - -On the KDE front, there’s a package that must be installed in order to encrypt/decrypt from with the Dolphin file manager. Log into your KDE desktop, open the terminal window, and issue the following command (I’m demonstrating with Neon. If your distribution isn’t Ubuntu-based, you’ll have to alter the command accordingly): -``` -sudo apt install kgpg - -``` - -Once that installs, logout and log back into the KDE desktop. You can open up Dolphin and right-click a file to be encrypted. Since this is the first time you’ve used kgpg, you’ll have to walk through a quick setup wizard (which self-explanatory). When you’ve completed the wizard, you can go back to that file, right-click it (Figure 3), and select Encrypt File. - - -![Dolphin][8] - -Figure 3: Encrypting a file within Dolphin. - -[Used with permission][4] - -You’ll be prompted to select the key to use for encryption (Figure 4). Make your selection and click OK. The file will encrypt and you’re ready to send it to the recipient. - -Note: With KDE’s Dolphin file manager, you cannot encrypt with a passphrase only. - - -![Dolphin][10] - -Figure 4: Selecting your recipients for encryption. - -[Used with permission][4] - -If you receive an encrypted file from a user who has your public key (or you have a file you’ve encrypted yourself), open up Dolphin, navigate to the file in question, double-click the file, give the file a new name, type the encryption passphrase, and click OK. You can now read your newly decrypted file. If you’ve encrypted the file with your own key, you won’t be prompted to type the passphrase (as it has already been stored). - -### Thunar - -The Thunar file manager is a bit trickier. There aren’t any extra packages to install; instead, you need to create new custom action for Encrypt. Once you’ve done this, you’ll have the ability to do this from within the file manager. - -To create the custom actions, open up the Thunar file manager and click Edit > Configure Custom Actions. In the resulting window, click the + button (Figure 5) and enter the following for an Encrypt action: - -Name: Encrypt - -Description: File Encryption - -Command: gnome-terminal -x gpg --encrypt --recipient %f - -Click OK to save this action. - - -![Thunar][12] - -Figure 5: Creating an custom action within Thunar. - -[Used with permission][4] - -NOTE: If gnome-terminal isn’t your default terminal, substitute the command to open your default terminal in. - -You can also create an action that encrypts with a passphrase only (not a key). To do this, the details for the action would be: - -Name: Encrypt Passphrase - -Description: Encrypt with Passphrase only - -Command: gnome-terminal -x gpg -c %f - -You don’t need to create a custom action for the decryption process, as Thunar already knows what to do with an encrypted file. To decrypt a file, simply right-click it (within Thunar), select Open With Decrypt File, give the decrypted file a name, and (when/if prompted) type the encryption passphrase. Viola, your encrypted file has been decrypted and is ready to use. - -### One caveat - -Do note: If you encrypt your own files, using your own keys, you won’t need to enter an encryption passphrase to decrypt them (because your public keys are stored). If, however, you receive files from others (who have your public key) you will be required to enter your passphrase. If you’re wanting to store your own encrypted files, instead of encrypting them with a key, encrypt them with a passphrase only. This is possible with Nautilus and Thunar (but not KDE). By opting for passphrase encryption (over key encryption), when you go to decrypt the file, it will always prompt you for the passphrase. - -### Other file managers - -There are plenty of other file managers out there, some of them can work with encryption, some cannot. Chances are, you’re using one of these three tools, so the ability to add encryption/decryption to the contextual menu is not only possible, it’s pretty easy. Give this a try and see if it doesn’t make the process of encryption and decryption much easier. - -Learn more about Linux through the free ["Introduction to Linux" ][13] course from The Linux Foundation and edX. - --------------------------------------------------------------------------------- - -via: https://www.linux.com/learn/intro-to-linux/2018/3/how-encrypt-files-within-file-manager - -作者:[JACK WALLEN][a] -译者:[译者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/users/jlwallen -[1]:https://www.gnupg.org/ -[3]:https://www.linux.com/sites/lcom/files/styles/rendered_file/public/nautilus.jpg?itok=ae7Gtj60 (nautilus) -[4]:https://www.linux.com/licenses/category/used-permission -[6]:https://www.linux.com/sites/lcom/files/styles/rendered_file/public/nautilus_2.jpg?itok=3ht7j63n (nautilus) -[8]:https://www.linux.com/sites/lcom/files/styles/rendered_file/public/kde_0.jpg?itok=KSTctVw0 (Dolphin) -[10]:https://www.linux.com/sites/lcom/files/styles/rendered_file/public/kde_2.jpg?itok=CeqWikNl (Dolphin) -[12]:https://www.linux.com/sites/lcom/files/styles/rendered_file/public/thunar.jpg?itok=fXcHk08B (Thunar) -[13]:https://training.linuxfoundation.org/linux-courses/system-administration-training/introduction-to-linux diff --git a/sources/tech/20180324 How To Compress And Decompress Files In Linux.md b/sources/tech/20180324 How To Compress And Decompress Files In Linux.md deleted file mode 100644 index 8766b9e39b..0000000000 --- a/sources/tech/20180324 How To Compress And Decompress Files In Linux.md +++ /dev/null @@ -1,210 +0,0 @@ -How To Compress And Decompress Files In Linux -====== - -![](https://www.ostechnix.com/wp-content/uploads/2018/03/compress-720x340.jpg) -Compressing is quite useful when backing up important files and also sending large files over Internet. Please note that compressing an already compressed file adds extra overhead, hence you will get a slightly bigger file. So, stop compressing a compressed file. There are many programs to compress and decompress files in GNU/Linux. In this tutorial, we’re going to learn about two applications only. - -### Compress and decompress files - -The most common programs used to compress files in Unix-like systems are: - - 1. gzip - 2. bzip2 - - - -##### 1\. Compress and decompress files using Gzip program - -The gzip is an utility to compress and decompress files using Lempel-Ziv coding (LZ77) algorithm. - -**1.1 Compress files** - -To compress a file named **ostechnix.txt** , replacing it with a gzipped compressed version, run: -``` -$ gzip ostechnix.txt - -``` - -Gzip will replace the original file **ostechnix.txt** with a gzipped compressed version named **ostechnix.txt.gz**. - -The gzip command can also be used in other ways too. One fine example is we can create a compressed version of a specific command’s output. Look at the following command. -``` -$ ls -l Downloads/ | gzip > ostechnix.txt.gz - -``` - -The above command creates compressed version of the directory listing of Downloads folder. - -**1.2 Compress files and write the output to different files (Don’t replace the original file) -** - -By default, gzip program will compress the given file, replacing it with a gzipped compressed version. You can, however, keep the original file and write the output to standard output. For example, the following command, compresses **ostechnix.txt** and writes the output to **output.txt.gz**. -``` -$ gzip -c ostechnix.txt > output.txt.gz - -``` - -Similarly, to decompress a gzipped file specifying the output filename: -``` -$ gzip -c -d output.txt.gz > ostechnix1.txt - -``` - -The above command decompresses the **output.txt.gz** file and writes the output to **ostechnix1.txt** file. In both cases, it won’t delete the original file. - -**1.3 Decompress files** - -To decompress the file **ostechnix.txt.gz** , replacing it with the original uncompressed version, we do: -``` -$ gzip -d ostechnix.txt.gz - -``` - -We can also use gunzip to decompress the files. -``` -$ gunzip ostechnix.txt.gz - -``` - -**1.4 View contents of compressed files without decompressing them** - -To view the contents of the compressed file using gzip without decompressing it, use **-c** flag as shown below: -``` -$ gunzip -c ostechnix1.txt.gz - -``` - -Alternatively, use **zcat** utility like below. -``` -$ zcat ostechnix.txt.gz - -``` - -You can also pipe the output to “less” command to view the output page by page like below. -``` -$ gunzip -c ostechnix1.txt.gz | less - -$ zcat ostechnix.txt.gz | less - -``` - -Alternatively, there is a **zless** program which performs the same function as the pipeline above. -``` -$ zless ostechnix1.txt.gz - -``` - -**1.5 Compress file with gzip by specifying compression level** - -Another notable advantage of gzip is it supports compression level. It supports 3 compression levels as given below. - - * **1** – Fastest (Worst) - * **9** – Slowest (Best) - * **6** – Default level - - - -To compress a file named **ostechnix.txt** , replacing it with a gzipped compressed version with **best** compression level, we use: -``` -$ gzip -9 ostechnix.txt - -``` - -**1.6 Concatenate multiple compressed files** - -It is also possible to concatenate multiple compressed files into one. How? Have a look at the following example. -``` -$ gzip -c ostechnix1.txt > output.txt.gz - -$ gzip -c ostechnix2.txt >> output.txt.gz - -``` - -The above two commands will compress ostechnix1.txt and ostechnix2.txt and saves them in one file named **output.txt.gz**. - -You can view the contents of both files (ostechnix1.txt and ostechnix2.txt) without extracting them using any one of the following commands: -``` -$ gunzip -c output.txt.gz - -$ gunzip -c output.txt - -$ zcat output.txt.gz - -$ zcat output.txt - -``` - -For more details, refer the man pages. -``` -$ man gzip - -``` - -##### 2\. Compress and decompress files using bzip2 program - -The **bzip2** is very similar to gzip program, but uses different compression algorithm named the Burrows-Wheeler block sorting text compression algorithm, and Huffman coding. The files compressed using bzip2 will end with **.bz2** extension. - -Like I said, the usage of bzip2 is almost same as gzip. Just replace **gzip** in the above examples with **bzip2** , **gunzip** with **bunzip2** , **zcat** with **bzcat** and so on. - -To compress a file using bzip2, replacing it with compressed version, run: -``` -$ bzip2 ostechnix.txt - -``` - -If you don’t want to replace the original file, use **-c** flag and write the output to a new file. -``` -$ bzip2 -c ostechnix.txt > output.txt.bz2 - -``` - -To decompress a compressed file: -``` -$ bzip2 -d ostechnix.txt.bz2 - -``` - -Or, -``` -$ bunzip2 ostechnix.txt.bz2 - -``` - -To view the contents of a compressed file without decompressing it: -``` -$ bunzip2 -c ostechnix.txt.bz2 - -``` - -Or, -``` -$ bzcat ostechnix.txt.bz2 - -``` - -For more details, refer man pages. -``` -$ man bzip2 - -``` - -##### Summary - -In this tutorial, we learned what is gzip and bzip2 programs and how to use them to compress and decompress files with some examples in GNU/Linux. In this next, guide we are going to learn how to archive files and directories in Linux. - -Cheers! - - - --------------------------------------------------------------------------------- - -via: https://www.ostechnix.com/how-to-compress-and-decompress-files-in-linux/ - -作者:[SK][a] -译者:[译者ID](https://github.com/译者ID) -校对:[校对者ID](https://github.com/校对者ID) -选题:[lujun9972](https://github.com/lujun9972) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 - -[a]:https://www.ostechnix.com/author/sk/ diff --git a/sources/tech/20180326 Start a blog in 30 minutes with Hugo, a static site generator written in Go.md b/sources/tech/20180326 Start a blog in 30 minutes with Hugo, a static site generator written in Go.md deleted file mode 100644 index 465941491c..0000000000 --- a/sources/tech/20180326 Start a blog in 30 minutes with Hugo, a static site generator written in Go.md +++ /dev/null @@ -1,191 +0,0 @@ -Start a blog in 30 minutes with Hugo, a static site generator written in Go -====== - -![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/programming-code-keyboard-laptop-music-headphones.png?itok=EQZ2WKzy) -Do you want to start a blog to share your latest adventures with various software frameworks? Do you love a project that is poorly documented and want to fix that? Or do you just want to create a personal website? - -Many people who want to start a blog have a significant caveat: lack of knowledge about a content management system (CMS) or time to learn. Well, what if I said you don't need to spend days learning a new CMS, setting up a basic website, styling it, and hardening it against attackers? What if I said you could create a blog in 30 minutes, start to finish, with [Hugo][1]? - -![](https://opensource.com/sites/default/files/styles/panopoly_image_original/public/u128651/hugo_1.png?itok=JgxBSOBG) - -Hugo is a static site generator written in Go. Why use Hugo, you ask? - - * Because there is no database, no plugins requiring any permissions, and no underlying platform running on your server, there's no added security concern. - * The blog is a set of static websites, which means lightning-fast serve time. Additionally, all pages are rendered at deploy time, so your server's load is minimal. - * Version control is easy. Some CMS platforms use their own version control system (VCS) or integrate Git into their interface. With Hugo, all your source files can live natively on the VCS of your choice. - - - -### Minutes 0-5: Download Hugo and generate a site - -To put it bluntly, Hugo is here to make writing a website fun again. Let's time the 30 minutes, shall we? - -To simplify the installation of Hugo, download the binary file. To do so: - - 1. Download the appropriate [archive][2] for your operating system. - - 2. Unzip the archive into a directory of your choice, for example `C:\hugo_dir` or `~/hugo_dir`; this path will be referred to as `${HUGO_HOME}`. - - 3. Open the command line and change into your directory: `cd ${HUGO_HOME}`. - - 4. Verify that Hugo is working: - - * On Unix: `${HUGO_HOME}/[hugo version]` - * On Windows: `${HUGO_HOME}\[hugo.exe version]` -For example, `c:\hugo_dir\hugo version`. - -For simplicity, I'll refer to the path to the Hugo binary (including the binary) as `hugo`. For example, `hugo version` would translate to `C:\hugo_dir\hugo version` on your computer. - -If you get an error message, you may have downloaded the wrong version. Also note there are many possible ways to install Hugo. See the [official documentation][3] for more information. Ideally, you put the Hugo binary on PATH. For this quick start, it's fine to use the full path of the Hugo binary. - - - - 5. Create a new site that will become your blog: `hugo new site awesome-blog`. - 6. Change into the newly created directory: `cd awesome-blog`. - - - -Congratulations! You have just created your new blog. - -### Minutes 5-10: Theme your blog - -With Hugo, you can either theme your blog yourself or use one of the beautiful, ready-made [themes][4]. I chose [Kiera][5] because it is deliciously simple. To install the theme: - - 1. Change into the themes directory: `cd themes`. - 2. Clone your theme: `git clone https://github.com/avianto/hugo-kiera kiera`. If you do not have Git installed: - * Download the .zip file from [GitHub][5]. - * Unzip it to your site's `themes` directory. - * Rename the directory from `hugo-kiera-master` to `kiera`. - 3. Change the directory to the awesome-blog level: `cd awesome-blog`. - 4. Activate the theme. Themes (including Kiera) often come with a directory called `exampleSite`, which contains example content and an example settings file. To activate Kiera, copy the provided `config.toml` file to your blog: - * On Unix: `cp themes/kiera/exampleSite/config.toml .` - * On Windows: `copy themes\kiera\exampleSite\config.toml .` - * Confirm `Yes` to override the old `config.toml` - 5. (Optional) You can start your server to visually verify the theme is activated: `hugo server -D` and access `http://localhost:1313` in your web browser. Once you've reviewed your blog, you can turn off the server by pressing `Ctrl+C` in the command line. Your blog is empty, but we're getting someplace. It should look something like this: - -![](https://opensource.com/sites/default/files/styles/panopoly_image_original/public/u128651/hugo_2.png?itok=PINOIOSU) - -You have just themed your blog! You can find hundreds of beautiful themes on the official [Hugo themes][4] site. - -### Minutes 10-20: Add content to your blog - -Whereas a bowl is most useful when it is empty, this is not the case for a blog. In this step, you'll add content to your blog. Hugo and the Kiera theme simplify this process. To add your first post: - - 1. Article archetypes are templates for your content. - 2. Add theme archetypes to your blog site: - * On Unix: `cp themes/kiera/archetypes/* archetypes/` - * On Windows: `copy themes\kiera\archetypes\* archetypes\` - * Confirm `Yes` to override the `default.md` archetype - 3. Create a new directory for your blog posts: - * On Unix: `mkdir content/posts` - * On Windows: `mkdir content\posts` - 4. Use Hugo to generate your post: - * On Unix: `hugo new posts/first-post.md` - * On Windows: `hugo new posts\first-post.md` - 5. Open the new post in a text editor of your choice: - * On Unix: `gedit content/posts/first-post.md` - * On Windows: `notepad content\posts\first-post.md` - - - -At this point, you can go wild. Notice that your post consists of two sections. The first one is separated by `+++`. It contains metadata about your post, such as its title. In Hugo, this is called front matter. After the front matter, the article begins. Create the first post: -``` -+++ - -title = "First Post" - -date = 2018-03-03T13:23:10+01:00 - -draft = false - -tags = ["Getting started"] - -categories = [] - -+++ - - - -Hello Hugo world! No more excuses for having no blog or documentation now! - -``` - -All you need to do now is start the server: `hugo server -D`. Open your browser and enter: `http://localhost:1313/`. -![](https://opensource.com/sites/default/files/styles/panopoly_image_original/public/u128651/hugo_3.png?itok=I-_v0qLx) - -### Minutes 20-30: Tweak your site - -What we've done is great, but there are still a few niggles to iron out. For example, naming your site is simple: - - 1. Stop your server by pressing `Ctrl+C` on the command line. - 2. Open `config.toml` and edit settings such as the blog's title, copyright, name, your social network links, etc. - - - -When you start your server again, you'll see your blog has a bit more personalization. One more basic thing is missing: menus. That's a quick fix as well. Back in `config.toml`, insert the following at the bottom: -``` -[[menu.main]] - -    name = "Home" #Name in the navigation bar - -    weight = 10 #The larger the weight, the more on the right this item will be - -    url = "/" #URL address - -[[menu.main]] - -    name = "Posts" - -    weight = 20 - -    url = "/posts/" - -``` - -This adds menus for Home and Posts. You still need an About page. Instead of referencing it from the `config.toml` file, reference it from a markdown file: - - 1. Create an About file: `hugo new about.md`. Notice that it's `about.md`, not `posts/about.md`. The About page is not a blog post, so you don't want it displayed in the Posts section. - 2. Open the file in a text editor and enter the following: - - -``` -+++ - -title = "About" - -date = 2018-03-03T13:50:49+01:00 - -menu = "main" #Display this page on the nav menu - -weight = "30" #Right-most nav item - -meta = "false" #Do not display tags or categories - -+++ - - - -> Waves are the practice of the water. Shunryu Suzuki - -``` - -When you start your Hugo server and open `http://localhost:1313/`, you should see your new blog ready to be used. (Check out [my example][6] on my GitHub page.) If you'd like to change the active style of menu items to make the padding slightly nicer (like the GitHub live version), apply [this patch][7] to your `themes/kiera/static/css/styles.css` file. - --------------------------------------------------------------------------------- - -via: https://opensource.com/article/18/3/start-blog-30-minutes-hugo - -作者:[Marek Czernek][a] -译者:[译者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/mczernek -[1]:https://gohugo.io/ -[2]:https://github.com/gohugoio/hugo/releases -[3]:https://gohugo.io/getting-started/installing/ -[4]:https://themes.gohugo.io/ -[5]:https://github.com/avianto/hugo-kiera -[6]:https://m-czernek.github.io/awesome-blog/ -[7]:https://github.com/avianto/hugo-kiera/pull/18/files diff --git a/sources/tech/20180403 3 pitfalls everyone should avoid with hybrid multicloud.md b/sources/tech/20180403 3 pitfalls everyone should avoid with hybrid multicloud.md new file mode 100644 index 0000000000..b128be62f0 --- /dev/null +++ b/sources/tech/20180403 3 pitfalls everyone should avoid with hybrid multicloud.md @@ -0,0 +1,87 @@ +3 pitfalls everyone should avoid with hybrid multicloud +====== +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/BIZ_darwincloud_520x292_0311LL.png?itok=74DLgd8Q) + +This article was co-written with [Roel Hodzelmans][1]. + +We're all told the cloud is the way to ensure a digital future for our businesses. But which cloud? From cloud to hybrid cloud to hybrid multi-cloud, you need to make choices, and these choices don't preclude the daily work of enhancing your customers' experience or agile delivery of the applications they need. + +This article is the first in a four-part series on avoiding pitfalls in hybrid multi-cloud computing. Let's start by examining multi-cloud, hybrid cloud, and hybrid multi-cloud and what makes them different from one another. + +### Hybrid vs. multi-cloud + +There are many conversations you may be having in your business around moving to the cloud. For example, you may want to take your on-premises computing capacity and turn it into your own private cloud. You may wish to provide developers with a cloud-like experience using the same resources you already have. A more traditional reason for expansion is to use external computing resources to augment those in your own data centers. The latter leads you to the various public cloud providers, as well as to our first definition, multi-cloud. + +#### Multi-cloud + +Multi-cloud means using multiple clouds from multiple providers for multiple tasks. + +![Multi-cloud][3] + +Figure 1. Multi-cloud IT with multiple isolated cloud environments + +Typically, multi-cloud refers to the use of several different public clouds in order to achieve greater flexibility, lower costs, avoid vendor lock-in, or use specific regional cloud providers. + +A challenge of the multi-cloud approach is achieving consistent policies, compliance, and management with different providers involved. + +Multi-cloud is mainly a strategy to expand your business while leveraging multi-vendor cloud solutions and spreading the risk of lock-in. Figure 1 shows the isolated nature of cloud services in this model, without any sort of coordination between the services and business applications. Each is managed separately, and applications are isolated to services found in their environments. + +#### Hybrid cloud + +Hybrid cloud solves issues where isolation and coordination are central to the solution. It is a combination of one or more public and private clouds with at least a degree of workload portability, integration, orchestration, and unified management. + +![Hybrid cloud][5] + +Figure 2. Hybrid clouds may be on or off premises, but must have a degree of interoperability + +The key issue here is that there is an element of interoperability, migration potential, and a connection between tasks running in public clouds and on-premises infrastructure, even if it's not always seamless or otherwise fully implemented. + +If your cloud model is missing portability, integration, orchestration, and management, then it's just a bunch of clouds, not a hybrid cloud. + +The cloud environments in Fig. 2 include at least one private and public cloud. They can be off or on premises, but they have some degree of the following: + + * Interoperability + * Application portability + * Data portability + * Common management + + + +As you can probably guess, combining multi-cloud and hybrid cloud results in a hybrid multi-cloud. But what does that look like? + +### Hybrid multi-cloud + +Hybrid multi-cloud pulls together multiple clouds and provides the tools to ensure interoperability between the various services in hybrid and multi-cloud solutions. + +![Hybrid multi-cloud][7] + +Figure 3. Hybrid multi-cloud solutions using open technologies + +Bringing these together can be a serious challenge, but the result ensures better use of resources without isolation in their respective clouds. + +Fig. 3 shows an example of hybrid multi-cloud based on open technologies for interoperability, workload portability, and management. + +### Moving forward: Pitfalls of hybrid multi-cloud + +In part two of this series, we'll look at the first of three pitfalls to avoid with hybrid multi-cloud. Namely, why cost is not always the obvious motivator when determining how to transition your business to the cloud. + +This article is based on "[3 pitfalls everyone should avoid with hybrid multi-cloud][8]," a talk the authors will be giving at [Red Hat Summit 2018][9], which will be held May 8-10 in San Francisco. [Register by May 7][9] to save US$ 500 off of registration. Use discount code **OPEN18** on the payment page to apply the discount. + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/4/pitfalls-hybrid-multi-cloud + +作者:[Eric D.Schabell][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://opensource.com/users/eschabell +[1]:https://opensource.com/users/roelh +[3]:https://opensource.com/sites/default/files/u128651/multi-cloud.png (Multi-cloud) +[5]:https://opensource.com/sites/default/files/u128651/hybrid-cloud.png (Hybrid cloud) +[7]:https://opensource.com/sites/default/files/u128651/hybrid-multicloud.png (Hybrid multi-cloud) +[8]:https://agenda.summit.redhat.com/SessionDetail.aspx?id=153892 +[9]:https://www.redhat.com/en/summit/2018 diff --git a/sources/tech/20180424 A gentle introduction to FreeDOS.md b/sources/tech/20180424 A gentle introduction to FreeDOS.md deleted file mode 100644 index ba43d23eb7..0000000000 --- a/sources/tech/20180424 A gentle introduction to FreeDOS.md +++ /dev/null @@ -1,110 +0,0 @@ -A gentle introduction to FreeDOS -====== - -![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/freedos-fish-laptop-color.png?itok=vfv_Lpph) - -FreeDOS is an old operating system, but it is new to many people. In 1994, several developers and I came together to [create FreeDOS][1]—a complete, free, DOS-compatible operating system you can use to play classic DOS games, run legacy business software, or develop embedded systems. Any program that works on MS-DOS should also run on FreeDOS. - -In 1994, FreeDOS was immediately familiar to anyone who had used Microsoft's proprietary MS-DOS. And that was by design; FreeDOS intended to mimic MS-DOS as much as possible. As a result, DOS users in the 1990s were able to jump right into FreeDOS. But times have changed. Today, open source developers are more familiar with the Linux command line or they may prefer a graphical desktop like [GNOME][2], making the FreeDOS command line seem alien at first. - -New users often ask, "I [installed FreeDOS][3], but how do I use it?" If you haven't used DOS before, the blinking `C:\>` DOS prompt can seem a little unfriendly. And maybe scary. This gentle introduction to FreeDOS should get you started. It offers just the basics: how to get around and how to look at files. If you want to learn more than what's offered here, visit the [FreeDOS wiki][4]. - -### The DOS prompt - -First, let's look at the empty prompt and what it means. - -![](https://opensource.com/sites/default/files/u128651/0-prompt.png) - -DOS is a "disk operating system" created when personal computers ran from floppy disks. Even when computers supported hard drives, it was common in the 1980s and 1990s to switch frequently between the different drives. For example, you might make a backup copy of your most important files to a floppy disk. - -DOS referenced each drive by a letter. Early PCs could have only two floppy drives, which were assigned as the `A:` and `B:` drives. The first partition on the first hard drive was the `C:` drive, and so on for other drives. The `C:` in the prompt means you are using the first partition on the first hard drive. - -Starting with PC-DOS 2.0 in 1983, DOS also supported directories and subdirectories, much like the directories and subdirectories on Linux filesystems. But unlike Linux, DOS directory names are delimited by `\` instead of `/`. Putting that together with the drive letter, the `C:\` in the prompt means you are in the top, or "root," directory of the `C:` drive. - -The `>` is the literal prompt where you type your DOS commands, like the `$` prompt on many Linux shells. The part before the `>` tells you the current working directory, and you type commands at the `>` prompt. - -### Finding your way around in DOS - -The basics of navigating through directories in DOS are very similar to the steps you'd use on the Linux command line. You need to remember only a few commands. - -#### Displaying a directory - -When you want to see the contents of the current directory, use the `DIR` command. Since DOS commands are not case-sensitive, you could also type `dir`. By default, DOS displays the details of every file and subdirectory, including the name, extension, size, and last modified date and time. - -![](https://opensource.com/sites/default/files/u128651/1-dir.png) - -If you don't want the extra details about individual file sizes, you can display a "wide" directory by using the `/w` option with the `DIR` command. Note that Linux uses the hyphen (`-`) or double-hyphen (`--`) to start command-line options, but DOS uses the slash character (`/`). - -![](https://opensource.com/sites/default/files/u128651/2-dirw.png) - -You can look inside a specific subdirectory by passing the pathname as a parameter to `DIR`. Again, another difference from Linux is that Linux files and directories are case-sensitive, but DOS names are case-insensitive. DOS will usually display files and directories in all uppercase, but you can equally reference them in lowercase. - -![](https://opensource.com/sites/default/files/u128651/3-dir-fdos.png) - - -#### Changing the working directory - -Once you can see the contents of a directory, you can "move into" any other directory. On DOS, you change your working directory with the `CHDIR` command, also abbreviated as `CD`. You can change into a subdirectory with a command like `CD CHOICE` or into a new path with `CD \FDOS\DOC\CHOICE`. - -![](https://opensource.com/sites/default/files/u128651/5-dir-choice.png) - -Just like on the Linux command line, DOS uses `.` to represent the current directory, and `..` for the parent directory (one level "up" from the current directory). You can combine these. For example, `CD ..` changes to the parent directory, and `CD ..\..` moves you two levels "up" from the current directory. - -![](https://opensource.com/sites/default/files/u128651/11-cd.png) - -FreeDOS also borrows a feature from Linux: You can use `CD -` to jump back to your previous working directory. That is handy after you change into a new path to do one thing and want to go back to your previous work. - -#### Changing the working drive - -Under Linux, the concept of a "drive" is hidden. In Linux and other Unix systems, you "mount" a drive to a directory path, such as `/backup`, or the system does it for you automatically, such as `/var/run/media/user/flashdrive`. But DOS is a much simpler system. With DOS, you must change the working drive by yourself. - -Remember that DOS assigns the first partition on the first hard drive as the `C:` drive, and so on for other drive letters. On modern systems, people rarely divide a hard drive with multiple DOS partitions; they simply use the whole disk—or as much of it as they can assign to DOS. Today, `C:` is usually the first hard drive, and `D:` is usually another hard drive or the CD-ROM drive. Other network drives can be mapped to other letters, such as `E:` or `Z:` or however you want to organize them. - -Changing drives is easy under DOS. Just type the drive letter followed by a colon (`:`) on the command line, and DOS will change to that working drive. For example, on my [QEMU][5] system, I set my `D:` drive to a shared directory in my Linux home directory, where I keep installers for various DOS applications and games I want to test. - -![](https://opensource.com/sites/default/files/u128651/8-d-dirw.png) - -Be careful that you don't try to change to a drive that doesn't exist. DOS may set the working drive, but if you try to do anything there you'll get the somewhat infamous "Abort, Retry, Fail" DOS error message. - -![](https://opensource.com/sites/default/files/u128651/9-e-fail.png) - -### Other things to try - -With the `CD` and `DIR` commands, you have the basics of DOS navigation. These commands allow you to find your way around DOS directories and see what other subdirectories and files exist. Once you are comfortable with basic navigation, you might also try these other basic DOS commands: - - * `MKDIR` or `MD` to create new directories - * `RMDIR` or `RD` to remove directories - * `TREE` to view a list of directories and subdirectories in a tree-like format - * `TYPE` and `MORE` to display file contents - * `RENAME` or `REN` to rename files - * `DEL` or `ERASE` to delete files - * `EDIT` to edit files - * `CLS` to clear the screen - - - -If those aren't enough, you can find a list of [all DOS commands][6] on the FreeDOS wiki. - -In FreeDOS, you can use the `/?` parameter to get brief instructions to use each command. For example, `EDIT /?` will show you the usage and options for the editor. Or you can type `HELP` to use an interactive help system. - -Like any DOS, FreeDOS is meant to be a simple operating system. The DOS filesystem is pretty simple to navigate with only a few basic commands. So fire up a QEMU session, install FreeDOS, and experiment with the DOS command line. Maybe now it won't seem so scary. - - --------------------------------------------------------------------------------- - -via: https://opensource.com/article/18/4/gentle-introduction-freedos - -作者:[Jim Hall][a] -选题:[lujun9972](https://github.com/lujun9972) -译者:[译者ID](https://github.com/译者ID) -校对:[校对者ID](https://github.com/校对者ID) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 - -[a]:https://opensource.com/users/jim-hall -[1]:https://opensource.com/article/17/10/freedos -[2]:https://opensource.com/article/17/8/gnome-20-anniversary -[3]:http://www.freedos.org/ -[4]:http://wiki.freedos.org/ -[5]:https://www.qemu.org/ -[6]:http://wiki.freedos.org/wiki/index.php/Dos_commands diff --git a/sources/tech/20180425 A gentle introduction to FreeDOS - Opensource.com.md b/sources/tech/20180425 A gentle introduction to FreeDOS - Opensource.com.md deleted file mode 100644 index d68334db33..0000000000 --- a/sources/tech/20180425 A gentle introduction to FreeDOS - Opensource.com.md +++ /dev/null @@ -1,141 +0,0 @@ -# A gentle introduction to FreeDOS - -![A gentle introduction to FreeDOS](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/freedos-fish-laptop-color.png?itok=vfv_Lpph "A gentle introduction to FreeDOS") - -Image credits :  - -Jim Hall, CC BY - -## Get the newsletter - -Join the 85,000 open source advocates who receive our giveaway alerts and article roundups. - -FreeDOS is an old operating system, but it is new to many people. In 1994, several developers and I came together to [create FreeDOS][1]—a complete, free, DOS-compatible operating system you can use to play classic DOS games, run legacy business software, or develop embedded systems. Any program that works on MS-DOS should also run on FreeDOS. - -In 1994, FreeDOS was immediately familiar to anyone who had used Microsoft's proprietary MS-DOS. And that was by design; FreeDOS intended to mimic MS-DOS as much as possible. As a result, DOS users in the 1990s were able to jump right into FreeDOS. But times have changed. Today, open source developers are more familiar with the Linux command line or they may prefer a graphical desktop like [GNOME][2], making the FreeDOS command line seem alien at first. - -New users often ask, "I [installed FreeDOS][3], but how do I use it?" If you haven't used DOS before, the blinking C:\> DOS prompt can seem a little unfriendly. And maybe scary. This gentle introduction to FreeDOS should get you started. It offers just the basics: how to get around and how to look at files. If you want to learn more than what's offered here, visit the [FreeDOS wiki][4]. - -## The DOS prompt - -First, let's look at the empty prompt and what it means. - -![The empty DOS prompt](https://opensource.com/sites/default/files/styles/panopoly_image_original/public/u128651/0-prompt.png?itok=b-JIeX0a "The empty DOS prompt") - -DOS is a "disk operating system" created when personal computers ran from floppy disks. Even when computers supported hard drives, it was common in the 1980s and 1990s to switch frequently between the different drives. For example, you might make a backup copy of your most important files to a floppy disk. - -DOS referenced each drive by a letter. Early PCs could have only two floppy drives, which were assigned as the A: and B: drives. The first partition on the first hard drive was the C: drive, and so on for other drives. The C: in the prompt means you are using the first partition on the first hard drive. - -Starting with PC-DOS 2.0 in 1983, DOS also supported directories and subdirectories, much like the directories and subdirectories on Linux filesystems. But unlike Linux, DOS directory names are delimited by \ instead of /. Putting that together with the drive letter, the C:\ in the prompt means you are in the top, or "root," directory of the C: drive. - -The > is the literal prompt where you type your DOS commands, like the $ prompt on many Linux shells. The part before the > tells you the current working directory, and you type commands at the > prompt. - -## Finding your way around in DOS - -The basics of navigating through directories in DOS are very similar to the steps you'd use on the Linux command line. You need to remember only a few commands. - -### Displaying a directory - -When you want to see the contents of the current directory, use the DIR command. Since DOS commands are not case-sensitive, you could also type dir. By default, DOS displays the details of every file and subdirectory, including the name, extension, size, and last modified date and time. - -![Displaying a directory with DIR](https://opensource.com/sites/default/files/styles/panopoly_image_original/public/u128651/1-dir.png?itok=reXNmrUD "Displaying a directory with DIR") - -If you don't want the extra details about individual file sizes, you can display a "wide" directory by using the /w option with the DIR command. Note that Linux uses the hyphen (-) or double-hyphen (--) to start command-line options, but DOS uses the slash character (/). - -![Displaying a wide directory with DIR /w](https://opensource.com/sites/default/files/styles/panopoly_image_original/public/u128651/2-dirw.png?itok=OZB54jXr "Displaying a wide directory with DIR /w") - -You can look inside a specific subdirectory by passing the pathname as a parameter to DIR. Again, another difference from Linux is that Linux files and directories are case-sensitive, but DOS names are case-insensitive. DOS will usually display files and directories in all uppercase, but you can equally reference them in lowercase. - -![Displaying the contents of the FDOS directory](https://opensource.com/sites/default/files/styles/panopoly_image_original/public/u128651/3-dir-fdos.png?itok=FSGY2Ybb "Displaying the contents of the FDOS directory") - -### Changing the working directory - -Once you can see the contents of a directory, you can "move into" any other directory. On DOS, you change your working directory with the CHDIR command, also abbreviated as CD. You can change into a subdirectory with a command like CD CHOICE or into a new path with CD \FDOS\DOC\CHOICE. - -![Changing into the \FDOS\DOC\CHOICE subdirectory](https://opensource.com/sites/default/files/styles/panopoly_image_original/public/u128651/5-dir-choice.png?itok=0JdsvDga "Changing into the \FDOS\DOC\CHOICE subdirectory") - -Just like on the Linux command line, DOS uses . to represent the current directory, and .. for the parent directory (one level "up" from the current directory). You can combine these. For example, CD .. changes to the parent directory, and CD ..\.. moves you two levels "up" from the current directory. - -FreeDOS also borrows a feature from Linux: You can use CD - to jump back to your previous working directory. That is handy after you change into a new path to do one thing and want to go back to your previous work. - -![Different ways to change directory](https://opensource.com/sites/default/files/styles/panopoly_image_original/public/u128651/11-cd.png?itok=R4rsx411 "Different ways to change directory") - -### Changing the working drive - -Under Linux, the concept of a "drive" is hidden. In Linux and other Unix systems, you "mount" a drive to a directory path, such as /backup, or the system does it for you automatically, such as /var/run/media/user/flashdrive. But DOS is a much simpler system. With DOS, you must change the working drive by yourself. - -Remember that DOS assigns the first partition on the first hard drive as the C: drive, and so on for other drive letters. On modern systems, people rarely divide a hard drive with multiple DOS partitions; they simply use the whole disk—or as much of it as they can assign to DOS. Today, C: is usually the first hard drive, and D: is usually another hard drive or the CD-ROM drive. Other network drives can be mapped to other letters, such as E: or Z: or however you want to organize them. - -Changing drives is easy under DOS. Just type the drive letter followed by a colon (:) on the command line, and DOS will change to that working drive. For example, on my [QEMU][5] system, I set my D: drive to a shared directory in my Linux home directory, where I keep installers for various DOS applications and games I want to test. - -![Changing to the D: drive](https://opensource.com/sites/default/files/styles/panopoly_image_original/public/u128651/8-d-dirw.png?itok=MC0FXAtm "Changing to the D: drive") - -Be careful that you don't try to change to a drive that doesn't exist. DOS may set the working drive, but if you try to do anything there you'll get the somewhat infamous "Abort, Retry, Fail" DOS error message. - -![Abort, Retry, Fail on a drive that doesn't exist](https://opensource.com/sites/default/files/styles/panopoly_image_original/public/u128651/9-e-fail.png?itok=TaDDolTD "Abort, Retry, Fail on a drive that doesn't exist") - -## Other things to try - -With the CD and DIR commands, you have the basics of DOS navigation. These commands allow you to find your way around DOS directories and see what other subdirectories and files exist. Once you are comfortable with basic navigation, you might also try these other basic DOS commands: - -* MKDIR or MD to create new directories -* RMDIR or RD to remove directories -* TREE to view a list of directories and subdirectories in a tree-like format -* TYPE and MORE to display file contents -* RENAME or REN to rename files -* DEL or ERASE to delete files -* EDIT to edit files -* CLS to clear the screen - -If those aren't enough, you can find a list of [all DOS commands][6] on the FreeDOS wiki. - -In FreeDOS, you can use the /? parameter to get brief instructions to use each command. For example, EDIT /? will show you the usage and options for the editor. Or you can type HELP to use an interactive help system. - -Like any DOS, FreeDOS is meant to be a simple operating system. The DOS filesystem is pretty simple to navigate with only a few basic commands. So fire up a QEMU session, install FreeDOS, and experiment with the DOS command line. Maybe now it won't seem so scary. - -## Related stories: - -* [How to install FreeDOS in QEMU][7] -* [How to install FreeDOS on Raspberry Pi][8] -* [The origin and evolution of FreeDOS][9] -* [Four cool facts about FreeDOS][10] - -## About the author - -[![photo of Jim Hall](https://opensource.com/sites/default/files/styles/profile_pictures/public/pictures/jimhall1.jpg?itok=LprhmAgl)][11] - -Jim Hall \- Jim Hall is an open source software developer and advocate, probably best known as the founder and project coordinator for FreeDOS. Jim is also very active in the usability of open source software, as a mentor for usability testing in GNOME Outreachy, and as an occasional adjunct professor teaching a course on the Usability of Open Source Software. From 2016 to 2017, Jim served as a director on the GNOME Foundation Board of Directors. At work, Jim is Chief Information Officer in local... [more about Jim Hall][12] - -[More about me][13] - -* [Learn how you can contribute][14] - ---- - -via: [https://opensource.com/article/18/4/gentle-introduction-freedos][15] - -作者: [undefined][16] 选题者: [@lujun9972][17] 译者: [译者ID][18] 校对: [校对者ID][19] - -本文由 [LCTT][20] 原创编译,[Linux中国][21] 荣誉推出 - -[1]: https://opensource.com/article/17/10/freedos -[2]: https://opensource.com/article/17/8/gnome-20-anniversary -[3]: http://www.freedos.org/ -[4]: http://wiki.freedos.org/ -[5]: https://www.qemu.org/ -[6]: http://wiki.freedos.org/wiki/index.php/Dos_commands -[7]: https://opensource.com/article/17/10/run-dos-applications-linux -[8]: https://opensource.com/article/18/3/can-you-run-dos-raspberry-pi -[9]: https://opensource.com/article/17/10/freedos -[10]: https://opensource.com/article/17/6/freedos-still-cool-today -[11]: https://opensource.com/users/jim-hall -[12]: https://opensource.com/users/jim-hall -[13]: https://opensource.com/users/jim-hall -[14]: https://opensource.com/participate -[15]: https://opensource.com/article/18/4/gentle-introduction-freedos -[16]: undefined -[17]: https://github.com/lujun9972 -[18]: https://github.com/译者ID -[19]: https://github.com/校对者ID -[20]: https://github.com/LCTT/TranslateProject -[21]: https://linux.cn/ diff --git a/sources/tech/20180425 Understanding metrics and monitoring with Python - Opensource.com.md b/sources/tech/20180425 Understanding metrics and monitoring with Python - Opensource.com.md deleted file mode 100644 index f181016aba..0000000000 --- a/sources/tech/20180425 Understanding metrics and monitoring with Python - Opensource.com.md +++ /dev/null @@ -1,488 +0,0 @@ -# Understanding metrics and monitoring with Python - -![Understanding metrics and monitoring with Python](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/metrics_graph_stats_blue.png?itok=OKCc_60D "Understanding metrics and monitoring with Python") - -Image by :  - -opensource.com - -## Get the newsletter - -Join the 85,000 open source advocates who receive our giveaway alerts and article roundups. - -My reaction when I first came across the terms counter and gauge and the graphs with colors and numbers labeled "mean" and "upper 90" was one of avoidance. It's like I saw them, but I didn't care because I didn't understand them or how they might be useful. Since my job didn't require me to pay attention to them, they remained ignored. - -That was about two years ago. As I progressed in my career, I wanted to understand more about our network applications, and that is when I started learning about metrics. - -The three stages of my journey to understanding monitoring (so far) are: - -* Stage 1: What? (Looks elsewhere) -* Stage 2: Without metrics, we are really flying blind. -* Stage 3: How do we keep from doing metrics wrong? - -I am currently in Stage 2 and will share what I have learned so far. I'm moving gradually toward Stage 3, and I will offer some of my resources on that part of the journey at the end of this article. - -Let's get started! - -## Software prerequisites - -More Python Resources - -* [What is Python?][1] -* [Top Python IDEs][2] -* [Top Python GUI frameworks][3] -* [Latest Python content][4] -* [More developer resources][5] - -All the demos discussed in this article are available on [my GitHub repo][6]. You will need to have docker and docker-compose installed to play with them. - -## Why should I monitor? - -The top reasons for monitoring are: - -* Understanding _normal_ and _abnormal_ system and service behavior -* Doing capacity planning, scaling up or down -* Assisting in performance troubleshooting -* Understanding the effect of software/hardware changes -* Changing system behavior in response to a measurement -* Alerting when a system exhibits unexpected behavior - -## Metrics and metric types - -For our purposes, a **metric** is an _observed_ value of a certain quantity at a given point in _time_. The total of number hits on a blog post, the total number of people attending a talk, the number of times the data was not found in the caching system, the number of logged-in users on your website—all are examples of metrics. - -They broadly fall into three categories: - -### Counters - -Consider your personal blog. You just published a post and want to keep an eye on how many hits it gets over time, a number that can only increase. This is an example of a **counter** metric. Its value starts at 0 and increases during the lifetime of your blog post. Graphically, a counter looks like this: - -![Counter metric](https://opensource.com/sites/default/files/styles/panopoly_image_original/public/u128651/counter-graph.png?itok=BZYrB-Hn "Counter metric") - -A counter metric always increases. - -### Gauges - -Instead of the total number of hits on your blog post over time, let's say you want to track the number of hits per day or per week. This metric is called a **gauge** and its value can go up or down. Graphically, a gauge looks like this: - -![gauge metric](https://opensource.com/sites/default/files/styles/panopoly_image_original/public/u128651/gauge-graph.png?itok=UA4u4cwz "gauge metric") - -A gauge metric can increase or decrease. - -A gauge's value usually has a _ceiling_ and a _floor_ in a certain time window. - -### Histograms and timers - -A **histogram** (as Prometheus calls it) or a **timer** (as StatsD calls it) is a metric to track _sampled observations_. Unlike a counter or a gauge, the value of a histogram metric doesn't necessarily show an up or down pattern. I know that doesn't make a lot of sense and may not seem different from a gauge. What's different is what you expect to _do_ with histogram data compared to a gauge. Therefore, the monitoring system needs to know that a metric is a histogram type to allow you to do those things. - -![Histogram metric](https://opensource.com/sites/default/files/styles/panopoly_image_original/public/u128651/histogram-graph.png?itok=cHI1v7Ly "Histogram metric") - -A histogram metric can increase or decrease. - -## Demo 1: Calculating and reporting metrics - -[Demo 1][7] is a basic web application written using the [Flask][8] framework. It demonstrates how we can _calculate_ and _report_ metrics. - -The src directory has the application in app.py with the src/helpers/middleware.py containing the following: - -``` -from flask import request -import csv -import time - - -def start_timer(): -    request.start_time = time.time() - - -def stop_timer(response): -    # convert this into milliseconds for statsd -    resp_time = (time.time() - request.start_time)*1000 -    with open('metrics.csv', 'a', newline='') as f: -        csvwriter = csv.writer(f) -        csvwriter.writerow([str(int(time.time())), str(resp_time)]) - -    return response - - -def setup_metrics(app): -    app.before_request(start_timer) -    app.after_request(stop_timer) -``` - -When setup_metrics() is called from the application, it configures the start_timer() function to be called before a request is processed and the stop_timer() function to be called after a request is processed but before the response has been sent. In the above function, we write the timestamp and the time it took (in milliseconds) for the request to be processed. - -When we run docker-compose up in the demo1 directory, it starts the web application, then a client container that makes a number of requests to the web application. You will see a src/metrics.csv file that has been created with two columns: timestamp and request_latency. - -Looking at this file, we can infer two things: - -* There is a lot of data that has been generated -* No observation of the metric has any characteristic associated with it - -Without a characteristic associated with a metric observation, we cannot say which HTTP endpoint this metric was associated with or which node of the application this metric was generated from. Hence, we need to qualify each metric observation with the appropriate metadata. - -## Statistics 101 - -If we think back to high school mathematics, there are a few statistics terms we should all recall, even if vaguely, including mean, median, percentile, and histogram. Let's briefly recap them without judging their usefulness, just like in high school. - -### Mean - -The **mean**, or the average of a list of numbers, is the sum of the numbers divided by the cardinality of the list. The mean of 3, 2, and 10 is (3+2+10)/3 = 5. - -### Median - -The **median** is another type of average, but it is calculated differently; it is the center numeral in a list of numbers ordered from smallest to largest (or vice versa). In our list above (2, 3, 10), the median is 3. The calculation is not very straightforward; it depends on the number of items in the list. - -### Percentile - -The **percentile** is a measure that gives us a measure below which a certain (k) percentage of the numbers lie. In some sense, it gives us an _idea_ of how this measure is doing relative to the k percentage of our data. For example, the 95th percentile score of the above list is 9.29999. The percentile measure varies from 0 to 100 (non-inclusive). The _zeroth_ percentile is the minimum score in a set of numbers. Some of you may recall that the median is the 50th percentile, which turns out to be 3. - -Some monitoring systems refer to the percentile measure as upper_X where _X_ is the percentile; _upper 90_ refers to the value at the 90th percentile. - -### Quantile - -The **q-Quantile** is a measure that ranks q_N_ in a set of _N_ numbers. The value of **q** ranges between 0 and 1 (both inclusive). When **q** is 0.5, the value is the median. The relationship between the quantile and percentile is that the measure at **q** quantile is equivalent to the measure at **100_q_** percentile. - -### Histogram - -The metric **histogram**, which we learned about earlier, is an _implementation detail_ of monitoring systems. In statistics, a histogram is a graph that groups data into _buckets_. Let's consider a different, contrived example: the ages of people reading your blog. If you got a handful of this data and wanted a rough idea of your readers' ages by group, plotting a histogram would show you a graph like this: - -![Histogram graph](https://opensource.com/sites/default/files/styles/panopoly_image_original/public/u128651/histogram.png?itok=gqfhjB8p "Histogram graph") - -### Cumulative histogram - -A **cumulative histogram** is a histogram where each bucket's count includes the count of the previous bucket, hence the name _cumulative_. A cumulative histogram for the above dataset would look like this: - -![Cumulative histogram](https://opensource.com/sites/default/files/styles/panopoly_image_original/public/u128651/cumulative-histogram.png?itok=wIGQdZnT "Cumulative histogram") - -### Why do we need statistics? - -In Demo 1 above, we observed that there is a lot of data that is generated when we report metrics. We need statistics when working with metrics because there are just too many of them. We don't care about individual values, rather overall behavior. We expect the behavior the values exhibit is a proxy of the behavior of the system under observation. - -## Demo 2: Adding characteristics to metrics - -In our Demo 1 application above, when we calculate and report a request latency, it refers to a specific request uniquely identified by few _characteristics_. Some of these are: - -* The HTTP endpoint -* The HTTP method -* The identifier of the host/node where it's running - -If we attach these characteristics to a metric observation, we have more context around each metric. Let's explore adding characteristics to our metrics in [Demo 2][9]. - -The src/helpers/middleware.py file now writes multiple columns to the CSV file when writing metrics: - -``` -node_ids = ['10.0.1.1', '10.1.3.4'] - - -def start_timer(): -    request.start_time = time.time() - - -def stop_timer(response): -    # convert this into milliseconds for statsd -    resp_time = (time.time() - request.start_time)*1000 -    node_id = node_ids[random.choice(range(len(node_ids)))] -    with open('metrics.csv', 'a', newline='') as f: -        csvwriter = csv.writer(f) -        csvwriter.writerow([ -            str(int(time.time())), 'webapp1', node_id, -            request.endpoint, request.method, str(response.status_code), -            str(resp_time) -        ]) - -    return response -``` - -Since this is a demo, I have taken the liberty of reporting random IPs as the node IDs when reporting the metric. When we run docker-compose up in the demo2 directory, it will result in a CSV file with multiple columns. - -### Analyzing metrics with pandas - -We'll now analyze this CSV file with [pandas][10]. Running docker-compose up will print a URL that we will use to open a [Jupyter][11] session. Once we upload the Analysis.ipynb notebook into the session, we can read the CSV file into a pandas DataFrame: - -``` -import pandas as pd -metrics = pd.read_csv('/data/metrics.csv', index_col=0) -``` - -The index_col specifies that we want to use the timestamp as the index. - -Since each characteristic we add is a column in the DataFrame, we can perform grouping and aggregation based on these columns: - -``` -import numpy as np -metrics.groupby(['node_id', 'http_status']).latency.aggregate(np.percentile, 99.999) -``` - -Please refer to the Jupyter notebook for more example analysis on the data. - -## What should I monitor? - -A software system has a number of variables whose values change during its lifetime. The software is running in some sort of an operating system, and operating system variables change as well. In my opinion, the more data you have, the better it is when something goes wrong. - -Key operating system metrics I recommend monitoring are: - -* CPU usage -* System memory usage -* File descriptor usage -* Disk usage - -Other key metrics to monitor will vary depending on your software application. - -### Network applications - -If your software is a network application that listens to and serves client requests, the key metrics to measure are: - -* Number of requests coming in (counter) -* Unhandled errors (counter) -* Request latency (histogram/timer) -* Queued time, if there is a queue in your application (histogram/timer) -* Queue size, if there is a queue in your application (gauge) -* Worker processes/threads usage (gauge) - -If your network application makes requests to other services in the context of fulfilling a client request, it should have metrics to record the behavior of communications with those services. Key metrics to monitor include number of requests, request latency, and response status. - -### HTTP web application backends - -HTTP applications should monitor all the above. In addition, they should keep granular data about the count of non-200 HTTP statuses grouped by all the other HTTP status codes. If your web application has user signup and login functionality, it should have metrics for those as well. - -### Long-running processes - -Long-running processes such as Rabbit MQ consumer or task-queue workers, although not network servers, work on the model of picking up a task and processing it. Hence, we should monitor the number of requests processed and the request latency for those processes. - -No matter the application type, each metric should have appropriate **metadata** associated with it. - -## Integrating monitoring in a Python application - -There are two components involved in integrating monitoring into Python applications: - -* Updating your application to calculate and report metrics -* Setting up a monitoring infrastructure to house the application's metrics and allow queries to be made against them - -The basic idea of recording and reporting a metric is: - -``` -def work(): -    requests += 1 -    # report counter -    start_time = time.time() -    -    # < do the work > - -    # calculate and report latency -    work_latency = time.time() - start_time -    ... -``` - -Considering the above pattern, we often take advantage of _decorators_, _context managers_, and _middleware_ (for network applications) to calculate and report metrics. In Demo 1 and Demo 2, we used decorators in a Flask application. - -### Pull and push models for metric reporting - -Essentially, there are two patterns for reporting metrics from a Python application. In the _pull_ model, the monitoring system "scrapes" the application at a predefined HTTP endpoint. In the _push_ model, the application sends the data to the monitoring system. - -![Pull and push models](https://opensource.com/sites/default/files/styles/panopoly_image_original/public/u128651/pull_push_model.png?itok=U093wSy8 "Pull and push models") - -An example of a monitoring system working in the _pull_ model is [Prometheus][12]. [StatsD][13] is an example of a monitoring system where the application _pushes_ the metrics to the system. - -### Integrating StatsD - -To integrate StatsD into a Python application, we would use the [StatsD Python client][14], then update our metric-reporting code to push data into StatsD using the appropriate library calls. - -First, we need to create a client instance: - -``` -statsd = statsd.StatsClient(host='statsd', port=8125, prefix='webapp1') -``` - -The prefix keyword argument will add the specified prefix to all the metrics reported via this client. - -Once we have the client, we can report a value for a timer using: - -``` -statsd.timing(key, resp_time) -``` - -To increment a counter: - -``` -statsd.incr(key) -``` - -To associate metadata with a metric, a key is defined as metadata1.metadata2.metric, where each metadataX is a field that allows aggregation and grouping. - -The demo application [StatsD][15] is a complete example of integrating a Python Flask application with statsd. - -### Integrating Prometheus - -To use the Prometheus monitoring system, we will use the [Promethius Python client][16]. We will first create objects of the appropriate metric class: - -``` -REQUEST_LATENCY = Histogram('request_latency_seconds', 'Request latency', -    ['app_name', 'endpoint'] -) -``` - -The third argument in the above statement is the labels associated with the metric. These labels are what defines the metadata associated with a single metric value. - -To record a specific metric observation: - -``` -REQUEST_LATENCY.labels('webapp', request.path).observe(resp_time) -``` - -The next step is to define an HTTP endpoint in our application that Prometheus can scrape. This is usually an endpoint called /metrics: - -``` -@app.route('/metrics') -def metrics(): -    return Response(prometheus_client.generate_latest(), mimetype=CONTENT_TYPE_LATEST) -``` - -The demo application [Prometheus][17] is a complete example of integrating a Python Flask application with prometheus. - -### Which is better: StatsD or Prometheus? - -The natural next question is: Should I use StatsD or Prometheus? I have written a few articles on this topic, and you may find them useful: - -* [Your options for monitoring multi-process Python applications with Prometheus][18] -* [Monitoring your synchronous Python web applications using Prometheus][19] -* [Monitoring your asynchronous Python web applications using Prometheus][20] - -## Ways to use metrics - -We've learned a bit about why we want to set up monitoring in our applications, but now let's look deeper into two of them: alerting and autoscaling. - -### Using metrics for alerting - -A key use of metrics is creating alerts. For example, you may want to send an email or pager notification to relevant people if the number of HTTP 500s over the past five minutes increases. What we use for setting up alerts depends on our monitoring setup. For Prometheus we can use [Alertmanager][21] and for StatsD, we use [Nagios][22]. - -### Using metrics for autoscaling - -Not only can metrics allow us to understand if our current infrastructure is over- or under-provisioned, they can also help implement autoscaling policies in a cloud infrastructure. For example, if worker process usage on our servers routinely hits 90% over the past five minutes, we may need to horizontally scale. How we would implement scaling depends on the cloud infrastructure. AWS Auto Scaling, by default, allows scaling policies based on system CPU usage, network traffic, and other factors. However, to use application metrics for scaling up or down, we must publish [custom CloudWatch metrics][23]. - -## Application monitoring in a multi-service architecture - -When we go beyond a single application architecture, such that a client request can trigger calls to multiple services before a response is sent back, we need more from our metrics. We need a unified view of latency metrics so we can see how much time each service took to respond to the request. This is enabled with [distributed tracing][24]. - -You can see an example of distributed tracing in Python in my blog post [Introducing distributed tracing in your Python application via Zipkin][25]. - -## Points to remember - -In summary, make sure to keep the following things in mind: - -* Understand what a metric type means in your monitoring system -* Know in what unit of measurement the monitoring system wants your data -* Monitor the most critical components of your application -* Monitor the behavior of your application in its most critical stages - -The above assumes you don't have to manage your monitoring systems. If that's part of your job, you have a lot more to think about! - -## Other resources - -Following are some of the resources I found very useful along my monitoring education journey: - -### General - -* [Monitoring distributed systems][26] -* [Observability and monitoring best practices][27] -* [Who wants seconds?][28] - -### StatsD/Graphite - -* [StatsD metric types][29] - -### Prometheus - -* [Prometheus metric types][30] -* [How does a Prometheus gauge work?][31] -* [Why are Prometheus histograms cumulative?][32] -* [Monitoring batch jobs in Python][33] -* [Prometheus: Monitoring at SoundCloud][34] - -## Avoiding mistakes (i.e., Stage 3 learnings) - -As we learn the basics of monitoring, it's important to keep an eye on the mistakes we don't want to make. Here are some insightful resources I have come across: - -* [How not to measure latency][35] -* [Histograms with Prometheus: A tale of woe][36] -* [Why averages suck and percentiles are great][37] -* [Everything you know about latency is wrong][38] -* [Who moved my 99th percentile latency?][39] -* [Logs and metrics and graphs][40] -* [HdrHistogram: A better latency capture method][41] - ---- - -To learn more, attend Amit Saha's talk, [Counter, gauge, upper 90—Oh my!][42], at [PyCon Cleveland 2018][43]. - -## About the author - -[![](https://opensource.com/sites/default/files/styles/profile_pictures/public/osdc_default_avatar_1.png?itok=mmbfqFXm)][44] - -Amit Saha \- I am a software engineer interested in infrastructure, monitoring and tooling. I am the author of "Doing Math with Python" and creator and the maintainer of Fedora Scientific Spin. - -[More about me][45] - -* [Learn how you can contribute][46] - ---- - -via: [https://opensource.com/article/18/4/metrics-monitoring-and-python][47] - -作者: [Amit Saha][48] 选题者: [@lujun9972][49] 译者: [译者ID][50] 校对: [校对者ID][51] - -本文由 [LCTT][52] 原创编译,[Linux中国][53] 荣誉推出 - -[1]: https://opensource.com/resources/python?intcmp=7016000000127cYAAQ -[2]: https://opensource.com/resources/python/ides?intcmp=7016000000127cYAAQ -[3]: https://opensource.com/resources/python/gui-frameworks?intcmp=7016000000127cYAAQ -[4]: https://opensource.com/tags/python?intcmp=7016000000127cYAAQ -[5]: https://developers.redhat.com/?intcmp=7016000000127cYAAQ -[6]: https://github.com/amitsaha/python-monitoring-talk -[7]: https://github.com/amitsaha/python-monitoring-talk/tree/master/demo1 -[8]: http://flask.pocoo.org/ -[9]: https://github.com/amitsaha/python-monitoring-talk/tree/master/demo2 -[10]: https://pandas.pydata.org/ -[11]: http://jupyter.org/ -[12]: https://prometheus.io/ -[13]: https://github.com/etsy/statsd -[14]: https://pypi.python.org/pypi/statsd -[15]: https://github.com/amitsaha/python-monitoring-talk/tree/master/statsd -[16]: https://pypi.python.org/pypi/prometheus_client -[17]: https://github.com/amitsaha/python-monitoring-talk/tree/master/prometheus -[18]: http://echorand.me/your-options-for-monitoring-multi-process-python-applications-with-prometheus.html -[19]: https://blog.codeship.com/monitoring-your-synchronous-python-web-applications-using-prometheus/ -[20]: https://blog.codeship.com/monitoring-your-asynchronous-python-web-applications-using-prometheus/ -[21]: https://github.com/prometheus/alertmanager -[22]: https://www.nagios.org/about/overview/ -[23]: https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/publishingMetrics.html -[24]: http://opentracing.io/documentation/ -[25]: http://echorand.me/introducing-distributed-tracing-in-your-python-application-via-zipkin.html -[26]: https://landing.google.com/sre/book/chapters/monitoring-distributed-systems.html -[27]: http://www.integralist.co.uk/posts/monitoring-best-practices/?imm_mid=0fbebf&cmp=em-webops-na-na-newsltr_20180309 -[28]: https://www.robustperception.io/who-wants-seconds/ -[29]: https://github.com/etsy/statsd/blob/master/docs/metric_types.md -[30]: https://prometheus.io/docs/concepts/metric_types/ -[31]: https://www.robustperception.io/how-does-a-prometheus-gauge-work/ -[32]: https://www.robustperception.io/why-are-prometheus-histograms-cumulative/ -[33]: https://www.robustperception.io/monitoring-batch-jobs-in-python/ -[34]: https://developers.soundcloud.com/blog/prometheus-monitoring-at-soundcloud -[35]: https://www.youtube.com/watch?v=lJ8ydIuPFeU&feature=youtu.be -[36]: http://linuxczar.net/blog/2017/06/15/prometheus-histogram-2/ -[37]: https://www.dynatrace.com/news/blog/why-averages-suck-and-percentiles-are-great/ -[38]: https://bravenewgeek.com/everything-you-know-about-latency-is-wrong/ -[39]: https://engineering.linkedin.com/performance/who-moved-my-99th-percentile-latency -[40]: https://grafana.com/blog/2016/01/05/logs-and-metrics-and-graphs-oh-my/ -[41]: http://psy-lob-saw.blogspot.com.au/2015/02/hdrhistogram-better-latency-capture.html -[42]: https://us.pycon.org/2018/schedule/presentation/133/ -[43]: https://us.pycon.org/2018/ -[44]: https://opensource.com/users/amitsaha -[45]: https://opensource.com/users/amitsaha -[46]: https://opensource.com/participate -[47]: https://opensource.com/article/18/4/metrics-monitoring-and-python -[48]: https://opensource.com/users/amitsaha -[49]: https://github.com/lujun9972 -[50]: https://github.com/译者ID -[51]: https://github.com/校对者ID -[52]: https://github.com/LCTT/TranslateProject -[53]: https://linux.cn/ diff --git a/sources/tech/20180426 How To Check System Hardware Manufacturer, Model And Serial Number In Linux.md b/sources/tech/20180426 How To Check System Hardware Manufacturer, Model And Serial Number In Linux.md deleted file mode 100644 index da97e87fc6..0000000000 --- a/sources/tech/20180426 How To Check System Hardware Manufacturer, Model And Serial Number In Linux.md +++ /dev/null @@ -1,155 +0,0 @@ -How To Check System Hardware Manufacturer, Model And Serial Number In Linux -====== -Getting system hardware information is not a problem for Linux GUI and Windows users but CLI users facing trouble to get this details. - -Even most of us don’t know what is the best command to get this. There are many utilities available in Linux to get system hardware information such as - -System Hardware Manufacturer, Model And Serial Number. - -We are trying to write possible ways to get this details but you can choose the best method for you. - -It is mandatory to know all these information because it will be needed when you raise a case with hardware vendor for any kind of hardware issues. - -This can be achieved in six methods, let me show you how to do that. - -### Method-1 : Using Dmidecode Command - -Dmidecode is a tool which reads a computer’s DMI (stands for Desktop Management Interface) (some say SMBIOS – stands for System Management BIOS) table contents and display system hardware information in a human-readable format. - -This table contains a description of the system’s hardware components, as well as other useful information such as serial number, Manufacturer information, Release Date, and BIOS revision, etc,., - -The DMI table doesn’t only describe what the system is currently made of, it also can report the possible evolution (such as the fastest supported CPU or the maximal amount of memory supported). - -This will help you to analyze your hardware capability like whether it’s support latest application version or not? -``` -# dmidecode -t system - -# dmidecode 2.12 -# SMBIOS entry point at 0x7e7bf000 -SMBIOS 2.7 present. - -Handle 0x0024, DMI type 1, 27 bytes -System Information - Manufacturer: IBM - Product Name: System x2530 M4: -[1214AC1]- - Version: 0B - Serial Number: MK2RL11 - UUID: 762A99BF-6916-450F-80A6-B2E9E78FC9A1 - Wake-up Type: Power Switch - SKU Number: Not Specified - Family: System X - -Handle 0x004B, DMI type 12, 5 bytes -System Configuration Options - Option 1: JP20 pin1-2: TPM PP Disable, pin2-3: TPM PP Enable - -Handle 0x004D, DMI type 32, 20 bytes -System Boot Information - Status: No errors detected - -``` - -**Suggested Read :** [Dmidecode – Easy Way To Get Linux System Hardware Information][1] - -### Method-2 : Using inxi Command - -inxi is a nifty tool to check hardware information on Linux and offers wide range of option to get all the hardware information on Linux system that i never found in any other utility which are available in Linux. It was forked from the ancient and mindbendingly perverse yet ingenius infobash, by locsmif. - -inxi is a script that quickly shows system hardware, CPU, drivers, Xorg, Desktop, Kernel, GCC version(s), Processes, RAM usage, and a wide variety of other useful information, also used for forum technical support & debugging tool. -``` -# inxi -M -Machine: Device: server System: IBM product: N/A v: 0B serial: MK2RL11 - Mobo: IBM model: 00Y8494 serial: 37M17D UEFI: IBM v: -[VVE134MUS-1.50]- date: 08/30/2013 - -``` - -**Suggested Read :** [inxi – A Great Tool to Check Hardware Information on Linux][2] - -### Method-3 : Using lshw Command - -lshw (stands for Hardware Lister) is a small nifty tool that generates detailed reports about various hardware components on the machine such as memory configuration, firmware version, mainboard configuration, CPU version and speed, cache configuration, usb, network card, graphics cards, multimedia, printers, bus speed, etc. - -It’s generating hardware information by reading varies files under /proc directory and DMI table. - -lshw must be run as super user to detect the maximum amount of information or it will only report partial information. Special option is available in lshw called class which will shows specific given hardware information in detailed manner. -``` -# lshw -C system -enal-dbo01t - description: Blade - product: System x2530 M4: -[1214AC1]- - vendor: IBM - version: 0B - serial: MK2RL11 - width: 64 bits - capabilities: smbios-2.7 dmi-2.7 vsyscall32 - configuration: boot=normal chassis=enclosure family=System X uuid=762A99BF-6916-450F-80A6-B2E9E78FC9A1 - -``` - -**Suggested Read :** [LSHW (Hardware Lister) – A Nifty Tool To Get A Hardware Information On Linux][3] - -### Method-4 : Using /sys file system - -The kernel expose some DMI information in the /sys virtual filesystem. So we can easily get the machine type by running grep command with following format. -``` -# grep "" /sys/class/dmi/id/[pbs]* - -``` - -Alternatively we can print only specific details by using cat command. -``` -# cat /sys/class/dmi/id/board_vendor -IBM - -# cat /sys/class/dmi/id/product_name -System x2530 M4: -[1214AC1]- - -# cat /sys/class/dmi/id/product_serial -MK2RL11 - -# cat /sys/class/dmi/id/bios_version --[VVE134MUS-1.50]- - -``` - -### Method-5 : Using dmesg Command - -The dmesg command is used to write the kernel messages (boot-time messages) in Linux before syslogd or klogd start. It obtains its data by reading the kernel ring buffer. dmesg can be very useful when troubleshooting or just trying to obtain information about the hardware on a system. -``` -# dmesg | grep -i DMI -DMI: System x2530 M4: -[1214AC1]-/00Y8494, BIOS -[VVE134MUS-1.50]- 08/30/2013 - -``` - -### Method-6 : Using hwinfo Command - -hwinfo stands for hardware information tool is another great utility that used to probe for the hardware present in the system and display detailed information about varies hardware components in human readable format. - -It reports information about CPU, RAM, keyboard, mouse, graphics card, sound, storage, network interface, disk, partition, bios, and bridge, etc,., This tool could display more detailed information among others like lshw, dmidecode, inxi, etc,. - -hwinfo uses libhd library libhd.so to gather hardware information on the system. This tool especially designed for openSUSE system, later other distributions are included the tool into their official repository. -``` -# hwinfo | egrep "system.hardware.vendor|system.hardware.product" - system.hardware.vendor = 'IBM' - system.hardware.product = 'System x2530 M4: -[1214AC1]-' - -``` - -**Suggested Read :** [hwinfo (Hardware Info) – A Nifty Tool To Detect System Hardware Information On Linux][4] - --------------------------------------------------------------------------------- - -via: https://www.2daygeek.com/how-to-check-system-hardware-manufacturer-model-and-serial-number-in-linux/ - -作者:[VINOTH KUMAR][a] -选题:[lujun9972](https://github.com/lujun9972) -译者:[译者ID](https://github.com/译者ID) -校对:[校对者ID](https://github.com/校对者ID) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 - -[a]:https://www.2daygeek.com/author/vinoth/ -[1]:https://www.2daygeek.com/dmidecode-get-print-display-check-linux-system-hardware-information/ -[2]:https://www.2daygeek.com/inxi-system-hardware-information-on-linux/ -[3]:https://www.2daygeek.com/lshw-find-check-system-hardware-information-details-linux/ -[4]:https://www.2daygeek.com/hwinfo-check-display-detect-system-hardware-information-linux/ diff --git a/sources/tech/20180427 An Official Introduction to the Go Compiler.md b/sources/tech/20180427 An Official Introduction to the Go Compiler.md deleted file mode 100644 index 65c35fee64..0000000000 --- a/sources/tech/20180427 An Official Introduction to the Go Compiler.md +++ /dev/null @@ -1,130 +0,0 @@ -// Copyright 2018 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -## Introduction to the Go compiler - -`cmd/compile` contains the main packages that form the Go compiler. The compiler -may be logically split in four phases, which we will briefly describe alongside -the list of packages that contain their code. - -You may sometimes hear the terms "front-end" and "back-end" when referring to -the compiler. Roughly speaking, these translate to the first two and last two -phases we are going to list here. A third term, "middle-end", often refers to -much of the work that happens in the second phase. - -Note that the `go/*` family of packages, such as `go/parser` and `go/types`, -have no relation to the compiler. Since the compiler was initially written in C, -the `go/*` packages were developed to enable writing tools working with Go code, -such as `gofmt` and `vet`. - -It should be clarified that the name "gc" stands for "Go compiler", and has -little to do with uppercase GC, which stands for garbage collection. - -### 1. Parsing - -* `cmd/compile/internal/syntax` (lexer, parser, syntax tree) - -In the first phase of compilation, source code is tokenized (lexical analysis), -parsed (syntactic analyses), and a syntax tree is constructed for each source -file. - -Each syntax tree is an exact representation of the respective source file, with -nodes corresponding to the various elements of the source such as expressions, -declarations, and statements. The syntax tree also includes position information -which is used for error reporting and the creation of debugging information. - -### 2. Type-checking and AST transformations - -* `cmd/compile/internal/gc` (create compiler AST, type checking, AST transformations) - -The gc package includes an AST definition carried over from when it was written -in C. All of its code is written in terms of it, so the first thing that the gc -package must do is convert the syntax package's syntax tree to the compiler's -AST representation. This extra step may be refactored away in the future. - -The AST is then type-checked. The first steps are name resolution and type -inference, which determine which object belongs to which identifier, and what -type each expression has. Type-checking includes certain extra checks, such as -"declared and not used" as well as determining whether or not a function -terminates. - -Certain transformations are also done on the AST. Some nodes are refined based -on type information, such as string additions being split from the arithmetic -addition node type. Some other examples are dead code elimination, function call -inlining, and escape analysis. - -### 3. Generic SSA - -* `cmd/compile/internal/gc` (converting to SSA) -* `cmd/compile/internal/ssa` (SSA passes and rules) - - -In this phase, the AST is converted into Static Single Assignment (SSA) form, a -lower-level intermediate representation with specific properties that make it -easier to implement optimizations and to eventually generate machine code from -it. - -During this conversion, function intrinsics are applied. These are special -functions that the compiler has been taught to replace with heavily optimized -code on a case-by-case basis. - -Certain nodes are also lowered into simpler components during the AST to SSA -conversion, so that the rest of the compiler can work with them. For instance, -the copy builtin is replaced by memory moves, and range loops are rewritten into -for loops. Some of these currently happen before the conversion to SSA due to -historical reasons, but the long-term plan is to move all of them here. - -Then, a series of machine-independent passes and rules are applied. These do not -concern any single computer architecture, and thus run on all `GOARCH` variants. - -Some examples of these generic passes include dead code elimination, removal of -unneeded nil checks, and removal of unused branches. The generic rewrite rules -mainly concern expressions, such as replacing some expressions with constant -values, and optimizing multiplications and float operations. - -### 4. Generating machine code - -* `cmd/compile/internal/ssa` (SSA lowering and arch-specific passes) -* `cmd/internal/obj` (machine code generation) - -The machine-dependent phase of the compiler begins with the "lower" pass, which -rewrites generic values into their machine-specific variants. For example, on -amd64 memory operands are possible, so many load-store operations may be combined. - -Note that the lower pass runs all machine-specific rewrite rules, and thus it -currently applies lots of optimizations too. - -Once the SSA has been "lowered" and is more specific to the target architecture, -the final code optimization passes are run. This includes yet another dead code -elimination pass, moving values closer to their uses, the removal of local -variables that are never read from, and register allocation. - -Other important pieces of work done as part of this step include stack frame -layout, which assigns stack offsets to local variables, and pointer liveness -analysis, which computes which on-stack pointers are live at each GC safe point. - -At the end of the SSA generation phase, Go functions have been transformed into -a series of obj.Prog instructions. These are passed to the assembler -(`cmd/internal/obj`), which turns them into machine code and writes out the -final object file. The object file will also contain reflect data, export data, -and debugging information. - -### Further reading - -To dig deeper into how the SSA package works, including its passes and rules, -head to `cmd/compile/internal/ssa/README.md`. - - - --------------------------------------------------------------------------------- - -via: https://github.com/golang/go/blob/master/src/cmd/compile/README.md - -作者:[mvdan ][a] -译者:[译者ID](https://github.com/译者ID) -校对:[校对者ID](https://github.com/校对者ID) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 - -[a]: https://github.com/mvdan diff --git a/sources/tech/20180428 How to get a core dump for a segfault on Linux.md b/sources/tech/20180428 How to get a core dump for a segfault on Linux.md deleted file mode 100644 index 1fe70221ac..0000000000 --- a/sources/tech/20180428 How to get a core dump for a segfault on Linux.md +++ /dev/null @@ -1,195 +0,0 @@ -translating by stenphenxs -How to get a core dump for a segfault on Linux -============================================================ - -This week at work I spent all week trying to debug a segfault. I’d never done this before, and some of the basic things involved (get a core dump! find the line number that segfaulted!) took me a long time to figure out. So here’s a blog post explaining how to do those things! - -At the end of this blog post, you should know how to go from “oh no my program is segfaulting and I have no idea what is happening” to “well I know what its stack / line number was when it segfaulted at at least!“. - -### what’s a segfault? - -A “segmentation fault” is when your program tries to access memory that it’s not allowed to access, or tries to . This can be caused by: - -* trying to dereference a null pointer (you’re not allowed to access the memory address `0`) - -* trying to dereference some other pointer that isn’t in your memory - -* a C++ vtable pointer that got corrupted and is pointing to the wrong place, which causes the program to try to execute some memory that isn’t executable - -* some other things that I don’t understand, like I think misaligned memory accesses can also segfault - -This “C++ vtable pointer” thing is what was happening to my segfaulting program. I might explain that in a future blog post because I didn’t know any C++ at the beginning of this week and this vtable lookup thing was a new way for a program to segfault that I didn’t know about. - -But! This blog post isn’t about C++ bugs. Let’s talk about the basics, like, how do we even get a core dump? - -### step 1: run valgrind - -I found the easiest way to figure out why my program is segfaulting was to use valgrind: I ran - -``` -valgrind -v your-program - -``` - -and this gave me a stack trace of what happened. Neat! - -But I wanted also wanted to do a more in-depth investigation and find out more than just what valgrind was telling me! So I wanted to get a core dump and explore it. - -### How to get a core dump - -A core dump is a copy of your program’s memory, and it’s useful when you’re trying to debug what went wrong with your problematic program. - -When your program segfaults, the Linux kernel will sometimes write a core dump to disk. When I originally tried to get a core dump, I was pretty frustrated for a long time because – Linux wasn’t writing a core dump!! Where was my core dump???? - -Here’s what I ended up doing: - -1. Run `ulimit -c unlimited` before starting my program - -2. Run `sudo sysctl -w kernel.core_pattern=/tmp/core-%e.%p.%h.%t` - -### ulimit: set the max size of a core dump - -`ulimit -c` sets the maximum size of a core dump. It’s often set to 0, which means that the kernel won’t write core dumps at all. It’s in kilobytes. ulimits are per process – you can see a process’s limits by running `cat /proc/PID/limit` - -For example these are the limits for a random Firefox process on my system: - -``` -$ cat /proc/6309/limits -Limit Soft Limit Hard Limit Units -Max cpu time unlimited unlimited seconds -Max file size unlimited unlimited bytes -Max data size unlimited unlimited bytes -Max stack size 8388608 unlimited bytes -Max core file size 0 unlimited bytes -Max resident set unlimited unlimited bytes -Max processes 30571 30571 processes -Max open files 1024 1048576 files -Max locked memory 65536 65536 bytes -Max address space unlimited unlimited bytes -Max file locks unlimited unlimited locks -Max pending signals 30571 30571 signals -Max msgqueue size 819200 819200 bytes -Max nice priority 0 0 -Max realtime priority 0 0 -Max realtime timeout unlimited unlimited us - -``` - -The kernel uses the soft limit (in this case, “max core file size = 0”) when deciding how big of a core file to write. You can increase the soft limit up to the hard limit using the `ulimit` shell builtin (`ulimit -c unlimited`!) - -### kernel.core_pattern: where core dumps are written - -`kernel.core_pattern` is a kernel parameter or a “sysctl setting” that controls where the Linux kernel writes core dumps to disk. - -Kernel parameters are a way to set global settings on your system. You can get a list of every kernel parameter by running `sysctl -a`, or use `sysctl kernel.core_pattern` to look at the `kernel.core_pattern` setting specifically. - -So `sysctl -w kernel.core_pattern=/tmp/core-%e.%p.%h.%t` will write core dumps to `/tmp/core-` - -If you want to know more about what these `%e`, `%p` parameters read, see [man core][1]. - -It’s important to know that `kernel.core_pattern` is a global settings – it’s good to be a little careful about changing it because it’s possible that other systems depend on it being set a certain way. - -### kernel.core_pattern & Ubuntu - -By default on Ubuntu systems, this is what `kernel.core_pattern` is set to - -``` -$ sysctl kernel.core_pattern -kernel.core_pattern = |/usr/share/apport/apport %p %s %c %d %P - -``` - -This caused me a lot of confusion (what is this apport thing and what is it doing with my core dumps??) so here’s what I learned about this: - -* Ubuntu uses a system called “apport” to report crashes in apt packages - -* Setting `kernel.core_pattern=|/usr/share/apport/apport %p %s %c %d %P`means that core dumps will be piped to `apport` - -* apport has logs in /var/log/apport.log - -* apport by default will ignore crashes from binaries that aren’t part of an Ubuntu packages - -I ended up just overriding this Apport business and setting `kernel.core_pattern` to `sysctl -w kernel.core_pattern=/tmp/core-%e.%p.%h.%t` because I was on a dev machine, I didn’t care whether Apport was working on not, and I didn’t feel like trying to convince Apport to give me my core dumps. - -### So you have a core dump. Now what? - -Okay, now we know about ulimits and `kernel.core_pattern` and you have actually have a core dump file on disk in `/tmp`. Amazing! Now what??? We still don’t know why the program segfaulted! - -The next step is to open the core file with `gdb` and get a backtrace. - -### Getting a backtrace from gdb - -You can open a core file with gdb like this: - -``` -$ gdb -c my_core_file - -``` - -Next, we want to know what the stack was when the program crashed. Running `bt` at the gdb prompt will give you a backtrace. In my case gdb hadn’t loaded symbols for the binary, so it was just like `??????`. Luckily, loading symbols fixed it. - -Here’s how to load debugging symbols. - -``` -symbol-file /path/to/my/binary -sharedlibrary - -``` - -This loads symbols from the binary and from any shared libraries the binary uses. Once I did that, gdb gave me a beautiful stack trace with line numbers when I ran `bt`!!! - -If you want this to work, the binary should be compiled with debugging symbols. Having line numbers in your stack traces is extremely helpful when trying to figure out why a program crashed :) - -### look at the stack for every thread - -Here’s how to get the stack for every thread in gdb! - -``` -thread apply all bt full - -``` - -### gdb + core dumps = amazing - -If you have a core dump & debugging symbols and gdb, you are in an amazing situation!! You can go up and down the call stack, print out variables, and poke around in memory to see what happened. It’s the best. - -If you are still working on being a gdb wizard, you can also just print out the stack trace with `bt` and that’s okay :) - -### ASAN - -Another path to figuring out your segfault is to do one compile the program with AddressSanitizer (“ASAN”) (`$CC -fsanitize=address`) and run it. I’m not going to discuss that in this post because this is already pretty long and anyway in my case the segfault disappeared with ASAN turned on for some reason, possibly because the ASAN build used a different memory allocator (system malloc instead of tcmalloc). - -I might write about ASAN more in the future if I ever get it to work :) - -### getting a stack trace from a core dump is pretty approachable! - -This blog post sounds like a lot and I was pretty confused when I was doing it but really there aren’t all that many steps to getting a stack trace out of a segfaulting program: - -1. try valgrind - -if that doesn’t work, or if you want to have a core dump to investigate: - -1. make sure the binary is compiled with debugging symbols - -2. set `ulimit` and `kernel.core_pattern` correctly - -3. run the program - -4. open your core dump with `gdb`, load the symbols, and run `bt` - -5. try to figure out what happened!! - -I was able using gdb to figure out that there was a C++ vtable entry that is pointing to some corrupt memory, which was somewhat helpful and helped me feel like I understood C++ a bit better. Maybe we’ll talk more about how to use gdb to figure things out another day! - --------------------------------------------------------------------------------- - -via: https://jvns.ca/blog/2018/04/28/debugging-a-segfault-on-linux/ - -作者:[Julia Evans ][a] -译者:[译者ID](https://github.com/译者ID) -校对:[校对者ID](https://github.com/校对者ID) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 - -[a]:https://jvns.ca/about/ -[1]:http://man7.org/linux/man-pages/man5/core.5.html diff --git a/sources/tech/20180430 3 practical Python tools- magic methods, iterators and generators, and method magic.md b/sources/tech/20180430 3 practical Python tools- magic methods, iterators and generators, and method magic.md deleted file mode 100644 index 2cb0e5a948..0000000000 --- a/sources/tech/20180430 3 practical Python tools- magic methods, iterators and generators, and method magic.md +++ /dev/null @@ -1,633 +0,0 @@ -3 practical Python tools: magic methods, iterators and generators, and method magic -====== - -![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/serving-bowl-forks-dinner.png?itok=a3YqPwr5) -Python offers a unique set of tools and language features that help make your code more elegant, readable, and intuitive. By selecting the right tool for the right problem, your code will be easier to maintain. In this article, we'll examine three of those tools: magic methods, iterators and generators, and method magic. - -### Magic methods - - -Magic methods can be considered the plumbing of Python. They're the methods that are called "under the hood" for certain built-in methods, symbols, and operations. A common magic method you may be familiar with is, `__init__()`,which is called when we want to initialize a new instance of a class. - -You may have seen other common magic methods, like `__str__` and `__repr__`. There is a whole world of magic methods, and by implementing a few of them, we can greatly modify the behavior of an object or even make it behave like a built-in datatype, such as a number, list, or dictionary. - -Let's take this `Money` class for example: -``` -class Money: - - - -    currency_rates = { - -        '$': 1, - -        '€': 0.88, - -    } - - - -    def __init__(self, symbol, amount): - -        self.symbol = symbol - -        self.amount = amount - - - -    def __repr__(self): - -        return '%s%.2f' % (self.symbol, self.amount) - - - -    def convert(self, other): - -        """ Convert other amount to our currency """ - -        new_amount = ( - -            other.amount / self.currency_rates[other.symbol] - -            * self.currency_rates[self.symbol]) - - - -        return Money(self.symbol, new_amount) - -``` - -The class defines a currency rate for a given symbol and exchange rate, specifies an initializer (also known as a constructor), and implements `__repr__`, so when we print out the class, we see a nice representation such as `$2.00` for an instance `Money('$', 2.00)` with the currency symbol and amount. Most importantly, it defines a method that allows you to convert between different currencies with different exchange rates. - -Using a Python shell, let's say we've defined the costs for two food items in different currencies, like so: -``` ->>> soda_cost = Money('$', 5.25) - ->>> soda_cost - -    $5.25 - - - ->>> pizza_cost = Money('€', 7.99) - ->>> pizza_cost - -    €7.99 - -``` - -We could use magic methods to help instances of this class interact with each other. Let's say we wanted to be able to add two instances of this class together, even if they were in different currencies. To make that a reality, we could implement the `__add__` magic method on our `Money` class: -``` -class Money: - - - -    # ... previously defined methods ... - - - -    def __add__(self, other): - -        """ Add 2 Money instances using '+' """ - -        new_amount = self.amount + self.convert(other).amount - -        return Money(self.symbol, new_amount) - -``` - -Now we can use this class in a very intuitive way: -``` ->>> soda_cost = Money('$', 5.25) - - - ->>> pizza_cost = Money('€', 7.99) - - - ->>> soda_cost + pizza_cost - -    $14.33 - - - ->>> pizza_cost + soda_cost - -    €12.61 - -``` - -When we add two instances together, we get a result in the first defined currency. All the conversion is done seamlessly under the hood. If we wanted to, we could also implement `__sub__` for subtraction, `__mul__` for multiplication, and many more. Read about [emulating numeric types][1], or read this [guide to magic methods][2] for others. - -We learned that `__add__` maps to the built-in operator `+`. Other magic methods can map to symbols like `[]`. For example, to access an item by index or key (in the case of a dictionary), use the `__getitem__` method: -``` ->>> d = {'one': 1, 'two': 2} - - - ->>> d['two'] - -2 - ->>> d.__getitem__('two') - -2 - -``` - -Some magic methods even map to built-in functions, such as `__len__()`, which maps to `len()`. -``` -class Alphabet: - -    letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' - - - -    def __len__(self): - -        return len(self.letters) - - - - - ->>> my_alphabet = Alphabet() - ->>> len(my_alphabet) - -    26 - -``` - -### Custom iterators - -Custom iterators are an incredibly powerful but unfortunately confusing topic to new and seasoned Pythonistas alike. - -Many built-in types, such as lists, sets, and dictionaries, already implement the protocol that allows them to be iterated over under the hood. This allows us to easily loop over them. -``` ->>> for food in ['Pizza', 'Fries']: - -         print(food + '. Yum!') - - - -Pizza. Yum! - -Fries. Yum! - -``` - -How can we iterate over our own custom classes? First, let's clear up some terminology. - - * To be iterable, a class needs to implement `__iter__()` - * The `__iter__()` method needs to return an iterator - * To be an iterator, a class needs to implement `__next__()` (or `next()` [in Python 2][3]), which must raise a `StopIteration` exception when there are no more items to iterate over. - - - -Whew! It sounds complicated, but once you remember these fundamental concepts, you'll be able to iterate in your sleep. - -When might we want to use a custom iterator? Let's imagine a scenario where we have a `Server` instance running different services such as `http` and `ssh` on different ports. Some of these services have an `active` state while others are `inactive`. -``` -class Server: - - - -    services = [ - -        {'active': False, 'protocol': 'ftp', 'port': 21}, - -        {'active': True, 'protocol': 'ssh', 'port': 22}, - -        {'active': True, 'protocol': 'http', 'port': 80}, - -    ] - -``` - -When we loop over our `Server` instance, we only want to loop over `active` services. Let's create a new class, an `IterableServer`: -``` -class IterableServer: - - - -    def __init__(self): - -        self.current_pos = 0 - - - -    def __next__(self): - -        pass  # TODO: Implement and remember to raise StopIteration - -``` - -First, we initialize our current position to `0`. Then, we define a `__next__()` method, which will return the next item. We'll also ensure that we raise `StopIteration` when there are no more items to return. So far so good! Now, let's implement this `__next__()` method. -``` -class IterableServer: - - - -    def __init__(self): - -        self.current_pos = 0.  # we initialize our current position to zero - - - -    def __iter__(self):  # we can return self here, because __next__ is implemented - -        return self - - - -    def __next__(self): - -        while self.current_pos < len(self.services): - -            service = self.services[self.current_pos] - -            self.current_pos += 1 - -            if service['active']: - -                return service['protocol'], service['port'] - -        raise StopIteration - - - -    next = __next__  # optional python2 compatibility - -``` - -We keep looping over the services in our list while our current position is less than the length of the services but only returning if the service is active. Once we run out of services to iterate over, we raise a `StopIteration` exception. - -Because we implement a `__next__()` method that raises `StopIteration` when it is exhausted, we can return `self` from `__iter__()` because the `IterableServer` class adheres to the `iterable` protocol. - -Now we can loop over an instance of `IterableServer`, which will allow us to look at each active service, like so: -``` ->>> for protocol, port in IterableServer(): - -        print('service %s is running on port %d' % (protocol, port)) - - - -service ssh is running on port 22 - -service http is running on port 21 - -``` - -That's pretty great, but we can do better! In an instance like this, where our iterator doesn't need to maintain a lot of state, we can simplify our code and use a [generator][4] instead. -``` -class Server: - - - -    services = [ - -        {'active': False, 'protocol': 'ftp', 'port': 21}, - -        {'active': True, 'protocol': 'ssh', 'port': 22}, - -        {'active': True, 'protocol': 'http', 'port': 21}, - -    ] - - - -    def __iter__(self): - -        for service in self.services: - -            if service['active']: - -                yield service['protocol'], service['port'] - -``` - -What exactly is the `yield` keyword? Yield is used when defining a generator function. It's sort of like a `return`. While a `return` exits the function after returning the value, `yield` suspends execution until the next time it's called. This allows your generator function to maintain state until it resumes. Check out [yield's documentation][5] to learn more. With a generator, we don't have to manually maintain state by remembering our position. A generator knows only two things: what it needs to do right now and what it needs to do to calculate the next item. Once we reach a point of execution where `yield` isn't called again, we know to stop iterating. - -This works because of some built-in Python magic. In the [Python documentation for `__iter__()`][6] we can see that if `__iter__()` is implemented as a generator, it will automatically return an iterator object that supplies the `__iter__()` and `__next__()` methods. Read this great article for a deeper dive of [iterators, iterables, and generators][7]. - -### Method magic - -Due to its unique aspects, Python provides some interesting method magic as part of the language. - -One example of this is aliasing functions. Since functions are just objects, we can assign them to multiple variables. For example: -``` ->>> def foo(): - -       return 'foo' - - - ->>> foo() - -'foo' - - - ->>> bar = foo - - - ->>> bar() - -'foo' - -``` - -We'll see later on how this can be useful. - -Python provides a handy built-in, [called `getattr()`][8], that takes the `object, name, default` parameters and returns the attribute `name` on `object`. This programmatically allows us to access instance variables and methods. For example: -``` ->>> class Dog: - -        sound = 'Bark' - -        def speak(self): - -            print(self.sound + '!', self.sound + '!') - - - ->>> fido = Dog() - - - ->>> fido.sound - -'Bark' - ->>> getattr(fido, 'sound') - -'Bark' - - - ->>> fido.speak - -> - ->>> getattr(fido, 'speak') - -> - - - - - ->>> fido.speak() - -Bark! Bark! - ->>> speak_method = getattr(fido, 'speak') - ->>> speak_method() - -Bark! Bark! - -``` - -Cool trick, but how could we practically use `getattr`? Let's look at an example that allows us to write a tiny command-line tool to dynamically process commands. -``` -class Operations: - -    def say_hi(self, name): - -        print('Hello,', name) - - - -    def say_bye(self, name): - -        print ('Goodbye,', name) - - - -    def default(self, arg): - -        print ('This operation is not supported.') - - - -if __name__ == '__main__': - -    operations = Operations() - - - -    # let's assume we do error handling - -    command, argument = input('> ').split() - -    func_to_call = getattr(operations, command, operations.default) - -    func_to_call(argument) - -``` - -The output of our script is: -``` -$ python getattr.py - - - -> say_hi Nina - -Hello, Nina - - - -> blah blah - -This operation is not supported. - -``` - -Next, we'll look at `partial`. For example, **`functool.partial(func, *args, **kwargs)`** allows you to return a new [partial object][9] that behaves like `func` called with `args` and `kwargs`. If more `args` are passed in, they're appended to `args`. If more `kwargs` are passed in, they extend and override `kwargs`. Let's see it in action with a brief example: -``` ->>> from functools import partial - ->>> basetwo = partial(int, base=2) - ->>> basetwo - - - - - ->>> basetwo('10010') - -18 - - - -# This is the same as - ->>> int('10010', base=2) - -``` - -Let's see how this method magic ties together in some sample code from a library I enjoy using [called][10]`agithub`, which is a (poorly named) REST API client with transparent syntax that allows you to rapidly prototype any REST API (not just GitHub) with minimal configuration. I find this project interesting because it's incredibly powerful yet only about 400 lines of Python. You can add support for any REST API in about 30 lines of configuration code. `agithub` knows everything it needs to about protocol (`REST`, `HTTP`, `TCP`), but it assumes nothing about the upstream API. Let's dive into the implementation. - -Here's a simplified version of how we'd define an endpoint URL for the GitHub API and any other relevant connection properties. View the [full code][11] instead. -``` -class GitHub(API): - - - -    def __init__(self, token=None, *args, **kwargs): - -        props = ConnectionProperties(api_url = kwargs.pop('api_url', 'api.github.com')) - -        self.setClient(Client(*args, **kwargs)) - -        self.setConnectionProperties(props) - -``` - -Then, once your [access token][12] is configured, you can start using the [GitHub API][13]. -``` ->>> gh = GitHub('token') - ->>> status, data = gh.user.repos.get(visibility='public', sort='created') - ->>> # ^ Maps to GET /user/repos - ->>> data - -... ['tweeter', 'snipey', '...'] - -``` - -Note that it's up to you to spell things correctly. There's no validation of the URL. If the URL doesn't exist or anything else goes wrong, the error thrown by the API will be returned. So, how does this all work? Let's figure it out. First, we'll check out a simplified example of the [`API` class][14]: -``` -class API: - - - -    # ... other methods ... - - - -    def __getattr__(self, key): - -        return IncompleteRequest(self.client).__getattr__(key) - -    __getitem__ = __getattr__ - -``` - -Each call on the `API` class ferries the call to the [`IncompleteRequest` class][15] for the specified `key`. -``` -class IncompleteRequest: - - - -    # ... other methods ... - - - -    def __getattr__(self, key): - -        if key in self.client.http_methods: - -            htmlMethod = getattr(self.client, key) - -            return partial(htmlMethod, url=self.url) - -        else: - -            self.url += '/' + str(key) - -            return self - -    __getitem__ = __getattr__ - - - - - -class Client: - -    http_methods = ('get')  # ... and post, put, patch, etc. - - - -    def get(self, url, headers={}, **params): - -        return self.request('GET', url, None, headers) - -``` - -If the last call is not an HTTP method (like 'get', 'post', etc.), it returns an `IncompleteRequest` with an appended path. Otherwise, it gets the right function for the specified HTTP method from the [`Client` class][16] and returns a `partial` . - -What happens if we give a non-existent path? -``` ->>> status, data = this.path.doesnt.exist.get() - ->>> status - -... 404 - -``` - -And because `__getitem__` is aliased to `__getattr__`: -``` ->>> owner, repo = 'nnja', 'tweeter' - ->>> status, data = gh.repos[owner][repo].pulls.get() - ->>> # ^ Maps to GET /repos/nnja/tweeter/pulls - ->>> data - -.... # {....} - -``` - -Now that's some serious method magic! - -### Learn more - -Python provides plenty of tools that allow you to make your code more elegant and easier to read and understand. The challenge is finding the right tool for the job, but I hope this article added some new ones to your toolbox. And, if you'd like to take this a step further, you can read about decorators, context managers, context generators, and `NamedTuple`s on my blog [nnja.io][17]. As you become a better Python developer, I encourage you to get out there and read some source code for well-architected projects. [Requests][18] and [Flask][19] are two great codebases to start with. - - --------------------------------------------------------------------------------- - -via: https://opensource.com/article/18/4/elegant-solutions-everyday-python-problems - -作者:[Nina Zakharenko][a] -选题:[lujun9972](https://github.com/lujun9972) -译者:[译者ID](https://github.com/译者ID) -校对:[校对者ID](https://github.com/校对者ID) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 - -[a]:https://opensource.com/users/nnja -[1]:https://docs.python.org/3/reference/datamodel.html#emulating-numeric-types -[2]:https://rszalski.github.io/magicmethods/ -[3]:https://docs.python.org/2/library/stdtypes.html#iterator.next -[4]:https://docs.python.org/3/library/stdtypes.html#generator-types -[5]:https://docs.python.org/3/reference/expressions.html#yieldexpr -[6]:https://docs.python.org/3/reference/datamodel.html#object.__iter__ -[7]:http://nvie.com/posts/iterators-vs-generators/ -[8]:https://docs.python.org/3/library/functions.html#getattr -[9]:https://docs.python.org/3/library/functools.html#functools.partial -[10]:https://github.com/mozilla/agithub -[11]:https://github.com/mozilla/agithub/blob/master/agithub/GitHub.py -[12]:https://github.com/settings/tokens -[13]:https://developer.github.com/v3/repos/#list-your-repositories -[14]:https://github.com/mozilla/agithub/blob/dbf7014e2504333c58a39153aa11bbbdd080f6ac/agithub/base.py#L30-L58 -[15]:https://github.com/mozilla/agithub/blob/dbf7014e2504333c58a39153aa11bbbdd080f6ac/agithub/base.py#L60-L100 -[16]:https://github.com/mozilla/agithub/blob/dbf7014e2504333c58a39153aa11bbbdd080f6ac/agithub/base.py#L102-L231 -[17]:http://nnja.io -[18]:https://github.com/requests/requests -[19]:https://github.com/pallets/flask -[20]:https://us.pycon.org/2018/schedule/presentation/164/ -[21]:https://us.pycon.org/2018/ diff --git a/sources/tech/20180502 Customizing your text colors on the Linux command line.md b/sources/tech/20180502 Customizing your text colors on the Linux command line.md deleted file mode 100644 index 381df0e53a..0000000000 --- a/sources/tech/20180502 Customizing your text colors on the Linux command line.md +++ /dev/null @@ -1,163 +0,0 @@ -Customizing your text colors on the Linux command line -====== - -![](https://images.idgesg.net/images/article/2018/05/numbers-100756457-large.jpg) -If you spend much time on the Linux command line (and you probably wouldn't be reading this if you didn't), you've undoubtedly noticed that the ls command displays your files in a number of different colors. You've probably also come to recognize some of the distinctions — directories appearing in one color, executable files in another, etc. - -How that all happens and what options are available for you to change the color assignments might not be so obvious. - -One way to get a big dose of data showing how these colors are assigned is to run the **dircolors** command. It will show you something like this: -``` -$ dircolors -LS_COLORS='rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do -=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=00:su=37;41:sg -=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01 -;31:*.tgz=01;31:*.arc=01;31:*.arj=01;31:*.taz=01;31:*.lha=01 -;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=0 -1;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31 -:*.dz=01;31:*.gz=01;31:*.lrz=01;31:*.lz=01;31:*.lzo=01;31:*. -xz=01;31:*.zst=01;31:*.tzst=01;31:*.bz2=01;31:*.bz=01;31:*.t -bz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.j -ar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.a -lz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.r -z=01;31:*.cab=01;31:*.jpg=01;35:*.jpeg=01;35:*.mjpg=01;35:*. -mjpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35: -*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35: -*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;3 -5:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01; -35:*.mkv=01;35:*.webm=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01 -;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01 -;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01 -;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;3 -5:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.ogv=01;3 -5:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.m4a=00;3 -6:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00; -36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.oga=00;36:*.opus=00; -36:*.spx=00;36:*.xspf=00;36:'; -export LS_COLORS - -``` - -If you're good at parsing, you probably noticed that there's a pattern to this listing. Break it on the colons, and you'll see something like this: -``` -$ dircolors | tr ":" "\n" | head -10 -LS_COLORS='rs=0 -di=01;34 -ln=01;36 -mh=00 -pi=40;33 -so=01;35 -do=01;35 -bd=40;33;01 -cd=40;33;01 -or=40;31;01 - -``` - -OK, so we have a pattern here — a series of definitions that have one to three numeric components. Let's hone in on one of definition. -``` -pi=40;33 - -``` - -The first question someone is likely to ask is "What is pi?" We're working with colors and file types here, so this clearly isn't the intriguing number that starts with 3.14. No, this "pi" stands for "pipe" — a particular type of file on Linux systems that makes it possible to send data from one program to another. So, let's set one up. -``` -$ mknod /tmp/mypipe p -$ ls -l /tmp/mypipe -prw-rw-r-- 1 shs shs 0 May 1 14:00 /tmp/mypipe - -``` - -When we look at our pipe and a couple other files in a terminal window, the color differences are quite obvious. - -![font colors][1] Sandra Henry-Stocker - -The "40" in the definition of pi (shown above) makes the file show up in the terminal (or PuTTY) window with a black background. The 31 makes the font color red. Pipes are special files, and this special handling makes them stand out in a directory listing. - -The **bd** and **cd** definitions are identical to each other — 40;33;01 and have an extra setting. The settings cause block (bd) and character (cd) devices to be displayed with a black background, an orange font, and one other effect — the characters will be in bold. - -The following list shows the color and font assignments that are made by **file type** : -``` -setting file type -======= ========= -rs=0 reset to no color -di=01;34 directory -ln=01;36 link -mh=00 multi-hard link -pi=40;33 pipe -so=01;35 socket -do=01;35 door -bd=40;33;01 block device -cd=40;33;01 character device -or=40;31;01 orphan -mi=00 missing? -su=37;41 setuid -sg=30;43 setgid -ca=30;41 file with capability -tw=30;42 directory with sticky bit and world writable -ow=34;42 directory that is world writable -st=37;44 directory with sticky bit -ex=01;93 executable - -``` - -You may have noticed that in our **dircolors** command output, most of our definitions started with asterisks (e.g., *.wav=00;36). These define display attributes by **file extension** rather than file type. Here's a sampling: -``` -$ dircolors | tr ":" "\n" | tail -10 -*.mpc=00;36 -*.ogg=00;36 -*.ra=00;36 -*.wav=00;36 -*.oga=00;36 -*.opus=00;36 -*.spx=00;36 -*.xspf=00;36 -'; -export LS_COLORS - -``` - -These settings (all 00:36 in the listing above) would have these file names displaying in cyan. The available colors are shown below. - -![all colors][2] Sandra Henry-Stocker - -### How to change your settings - -The colors and font changes described require that you use an alias for ls that turns on the color feature. This is usually the default on Linux systems and will look like this: -``` -alias ls='ls --color=auto' - -``` - -If you wanted to turn off font colors, you could run the **unalias ls** command and your file listings would then show in only the default font color. - -You can alter your text colors by modifying your $LS_COLORS settings and exporting the modified setting: -``` -$ export LS_COLORS='rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;... - -``` - -NOTE: The command above is truncated. - -If you want your modified text colors to be permanent, you would need to add your modified LS_COLORS definition to one of your startup files (e.g., .bashrc). - -### More on command line text - -You can find additional information on text colors in this [November 2016][3] post on NetworkWorld. - - --------------------------------------------------------------------------------- - -via: https://www.networkworld.com/article/3269587/linux/customizing-your-text-colors-on-the-linux-command-line.html - -作者:[Sandra Henry-Stocker][a] -选题:[lujun9972](https://github.com/lujun9972) -译者:[译者ID](https://github.com/译者ID) -校对:[校对者ID](https://github.com/校对者ID) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 - -[a]:https://www.networkworld.com/author/Sandra-Henry_Stocker/ -[1]:https://images.idgesg.net/images/article/2018/05/font-colors-100756483-large.jpg -[2]:https://images.techhive.com/images/article/2016/11/all-colors-100691990-large.jpg -[3]:https://www.networkworld.com/article/3138909/linux/coloring-your-world-with-ls-colors.html diff --git a/sources/tech/20180508 How To Check Ubuntu Version and Other System Information Easily.md b/sources/tech/20180508 How To Check Ubuntu Version and Other System Information Easily.md deleted file mode 100644 index 9395b7708a..0000000000 --- a/sources/tech/20180508 How To Check Ubuntu Version and Other System Information Easily.md +++ /dev/null @@ -1,127 +0,0 @@ -How To Check Ubuntu Version and Other System Information Easily -====== -**Brief: Wondering which Ubuntu version are you using? Here’s how to check Ubuntu version, desktop environment and other relevant system information.** - -You can easily find the Ubuntu version you are using in the command line or via the graphical interface. Knowing the exact Ubuntu version, desktop environment and other system information helps a lot when you are trying to follow a tutorial from the web or seeking help in various forums. - -In this quick tip, I’ll show you various ways to check [Ubuntu][1] version and other common system information. - -### How to check Ubuntu version in terminal - -This is the best way to find Ubuntu version. I could have mentioned the graphical way first but then I chose this method because this one doesn’t depend on the [desktop environment][2] you are using. You can use it on any Ubuntu variant. - -Open a terminal (Ctrl+Alt+T) and type the following command: -``` -lsb_release -a - -``` - -The output of the above command should be like this: -``` -No LSB modules are available. -Distributor ID: Ubuntu -Description: Ubuntu 16.04.4 LTS -Release: 16.04 -Codename: xenial - -``` - -![How to check Ubuntu version in command line][3] - -As you can see, the current Ubuntu installed in my system is Ubuntu 16.04 and its code name is Xenial. - -Wait! Why does it say Ubuntu 16.04.4 in Description and 16.04 in the Release? Which one is it, 16.04 or 16.04.4? What’s the difference between the two? - -The short answer is that you are using Ubuntu 16.04. That’s the base image. 16.04.4 signifies the fourth point release of 16.04. A point release can be thought of as a service pack in Windows era. Both 16.04 and 16.04.4 will be the correct answer here. - -What’s Xenial in the output? That’s the codename of the Ubuntu 16.04 release. You can read this [article to know about Ubuntu naming convention][4]. - -#### Some alternate ways to find Ubuntu version - -Alternatively, you can use either of the following commands to find Ubuntu version: -``` -cat /etc/lsb-release - -``` - -The output of the above command would look like this: -``` -DISTRIB_ID=Ubuntu -DISTRIB_RELEASE=16.04 -DISTRIB_CODENAME=xenial -DISTRIB_DESCRIPTION="Ubuntu 16.04.4 LTS" - -``` - -![How to check Ubuntu version in command line][5] - -You can also use this command to know Ubuntu version -``` -cat /etc/issue - -``` - -The output of this command will be like this: -``` -Ubuntu 16.04.4 LTS \n \l - -``` - -Forget the \n \l. The Ubuntu version is 16.04.4 in this case or simply Ubuntu 16.04. - -### How to check Ubuntu version graphically - -Checking Ubuntu version graphically is no big deal either. I am going to use screenshots from Ubuntu 18.04 GNOME here. Things may look different if you are using Unity or some other desktop environment. This is why I recommend the command line version discussed in the previous sections because that doesn’t depend on the desktop environment. - -I’ll show you how to find the desktop environment in the next section. - -For now, go to System Settings and look under the Details segment. - -![Finding Ubuntu version graphically][6] - -You should see the Ubuntu version here along with the information about the desktop environment you are using, [GNOME][7] being the case here. - -![Finding Ubuntu version graphically][8] - -### How to know the desktop environment and other system information in Ubuntu - -So you just learned how to find Ubuntu version. What about the desktop environment in use? Which Linux kernel version is being used? - -Of course, there are various commands you can use to get all those information but I’ll recommend a command line utility called [Neofetch][9]. This will show you essential system information in the terminal beautifully with the logo of Ubuntu or any other Linux distribution you are using. - -Install Neofetch using the command below: -``` -sudo apt install neofetch - -``` - -Once installed, simply run the command `neofetch` in the terminal and see a beautiful display of system information. - -![System information in Linux terminal][10] - -As you can see, Neofetch shows you the Linux kernel version, Ubuntu version, desktop environment in use along with its version, themes and icons in use etc. - -I hope it helps you to find Ubuntu version and other system information. If you have suggestions to improve this article, feel free to drop it in the comment section. Ciao :) - --------------------------------------------------------------------------------- - -via: https://itsfoss.com/how-to-know-ubuntu-unity-version/ - -作者:[Abhishek Prakash][a] -选题:[lujun9972](https://github.com/lujun9972) -译者:[译者ID](https://github.com/译者ID) -校对:[校对者ID](https://github.com/校对者ID) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 - -[a]: https://itsfoss.com/author/abhishek/ -[1]:https://www.ubuntu.com/ -[2]:https://en.wikipedia.org/wiki/Desktop_environment -[3]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2013/03/check-ubuntu-version-command-line-1-800x216.jpeg -[4]:https://itsfoss.com/linux-code-names/ -[5]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2013/03/check-ubuntu-version-command-line-2-800x185.jpeg -[6]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2013/03/ubuntu-version-system-settings.jpeg -[7]:https://www.gnome.org/ -[8]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2013/03/checking-ubuntu-version-gui.jpeg -[9]:https://itsfoss.com/display-linux-logo-in-ascii/ -[10]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2013/03/ubuntu-system-information-terminal-800x400.jpeg diff --git a/sources/tech/20180510 Splicing the Cloud Native Stack, One Floor at a Time.md b/sources/tech/20180510 Splicing the Cloud Native Stack, One Floor at a Time.md deleted file mode 100644 index 6515b3e193..0000000000 --- a/sources/tech/20180510 Splicing the Cloud Native Stack, One Floor at a Time.md +++ /dev/null @@ -1,174 +0,0 @@ -Splicing the Cloud Native Stack, One Floor at a Time -====== -At Packet, our value (automated infrastructure) is super fundamental. As such, we spend an enormous amount of time looking up at the players and trends in all the ecosystems above us - as well as the very few below! - -It’s easy to get confused, or simply lose track, when swimming deep in the oceans of any ecosystem. I know this for a fact because when I started at Packet last year, my English degree from Bryn Mawr didn’t quite come with a Kubernetes certification. :) - -Due to its super fast evolution and massive impact, the cloud native ecosystem defies precedent. It seems that every time you blink, entirely new technologies (not to mention all of the associated logos) have become relevant...or at least interesting. Like many others, I’ve relied on the CNCF’s ubiquitous “[Cloud Native Landscape][1]” as a touchstone as I got to know the space. However, if there is one element that defines ecosystems, it is the people that contribute to and steer them. - -That’s why, when we were walking back to the office one cold December afternoon, we hit upon a creative way to explain “cloud native” to an investor, whose eyes were obviously glazing over as we talked about the nuances that distinguished Cilium from Aporeto, and why everything from CoreDNS and Spiffe to Digital Rebar and Fission were interesting in their own right. - -Looking up at our narrow 13 story office building in the shadow of the new World Trade Center, we hit on an idea that took us down an artistic rabbit hole: why not draw it? - -![][2] - -And thus began our journey to splice the Cloud Native Stack, one floor at a time. Let’s walk through it together and we can give you the “guaranteed to be outdated tomorrow” down low. - -[[View a High Resolution JPG][3]] or email us to request a copy. - -### Starting at the Very Bottom - -As we started to put pen to paper, we knew we wanted to shine a light on parts of the stack that we interact with on a daily basis, but that is largely invisible to users further up: hardware. And like any good secret lab investing in the next great (usually proprietary) thing, we thought the basement was the perfect spot. - -From the well established giants of the space like Intel, AMD and Huawei (rumor has it they employ nearly 80,000 engineers!), to more niche players like Mellanox, the hardware ecosystem is on fire. In fact, we may be entering a Golden Age of hardware, as billions of dollars are poured into upstarts hacking on new offloads, GPU’s, custom co-processors. - -The famous software trailblazer Alan Kay said over 25 years ago: “People who are really serious about software should make their own hardware.” Good call Alan! - -### The Cloud is About Capital - -As our CEO Zac Smith has told me many times: it’s all about the money. And not just about making it, but spending it! In the cloud, it takes billions of dollars of capital to make computers show up in data centers so that developers can consume them with software. In other words: - - -![][4] - -We thought the best place for “The Bank” (e.g. the lenders and investors that make this cloud fly) was the ground floor. So we transformed our lobby into the Banker’s Cafe, complete with a wheel of fortune for all of us out there playing the startup game. - -![][5] - -### The Ping and Power - -If the money is the grease, then the engine that consumes much of the fuel is the datacenter providers and the networks that connect them. We call them “power” and “ping”. - -From top of mind names like Equinix and edge upstarts like Vapor.io, to the “pipes” that Verizon, Crown Castle and others literally put in the ground (or on the ocean floor), this is a part of the stack that we all rely upon but rarely see in person. - -Since we spend a lot of time looking at datacenters and connectivity, one thing to note is that this space is changing quite rapidly, especially as 5G arrives in earnest and certain workloads start to depend on less centralized infrastructure. - -The edge is coming y’all! :-) - -![][6] - -### Hey, It's Infrastructure! - -Sitting on top of “ping” and “power” is the floor we lovingly call “processors”. This is where our magic happens - we turn the innovation and physical investments from down below into something at the end of an API. - -Since this is a NYC building, we kept the cloud providers here fairly NYC centric. That’s why you see Sammy the Shark (of Digital Ocean lineage) and a nod to Google over in the “meet me” room. - -As you’ll see, this scene is pretty physical. Racking and stacking, as it were. While we love our facilities manager in EWR1 (Michael Pedrazzini), we are working hard to remove as much of this manual labor as possible. PhD’s in cabling are hard to come by, after all. - -![][7] - -### Provisioning - -One floor up, layered on top of infrastructure, is provisioning. This is one of our favorite spots, which years ago we might have called “config management.” But now it’s all about immutable infrastructure and automation from the start: Terraform, Ansible, Quay.io and the like. You can tell that software is working its way down the stack, eh? - -Kelsey Hightower noted recently “it’s an exciting time to be in boring infrastructure.” I don’t think he meant the physical part (although we think it’s pretty dope), but as software continues to hack on all layers of the stack, you can guarantee a wild ride. - -![][8] - -### Operating Systems - -With provisioning in place, we move to the operating system layer. This is where we get to start poking fun at some of our favorite folks as well: note Brian Redbeard’s above average yoga pose. :) - -Packet offers eleven major operating systems for our clients to choose from, including some that you see in this illustration: Ubuntu, CoreOS, FreeBSD, Suse, and various Red Hat offerings. More and more, we see folks putting their opinion on this layer: from custom kernels and golden images of their favorite distros for immutable deploys, to projects like NixOS and LinuxKit. - -![][9] - -### Run Time - -We had to have fun with this, so we placed the runtime in the gym, with a championship match between CoreOS-sponsored rkt and Docker’s containerd. Either way the CNCF wins! - -We felt the fast-evolving storage ecosystem deserved some lockers. What’s fun about the storage aspect is the number of new players trying to conquer the challenging issue of persistence, as well as performance and flexibility. As they say: storage is just plain hard. - -![][10] - -### Orchestration - -The orchestration layer has been all about Kubernetes this past year, so we took one of its most famous evangelists (Kelsey Hightower) and featured him in this rather odd meetup scene. We have some major Nomad fans on our team, and there is just no way to consider the cloud native space without the impact of Docker and its toolset. - -While workload orchestration applications are fairly high up our stack, we see all kinds of evidence for these powerful tools are starting to look way down the stack to help users take advantage of GPU’s and other specialty hardware. Stay tuned - we’re in the early days of the container revolution! - -![][11] - -### Platforms - -This is one of our favorite layers of the stack, because there is so much craft in how each platform helps users accomplish what they really want to do (which, by the way, isn’t run containers but run applications!). From Rancher and Kontena, to Tectonic and Redshift to totally different approaches like Cycle.io and Flynn.io - we’re always thrilled to see how each of these projects servers users differently. - -The main takeaway: these platforms are helping to translate all of the various, fast-moving parts of the cloud native ecosystem to users. It’s great watching what they each come up with! - -![][12] - -### Security - -When it comes to security, it’s been a busy year! We tried to represent some of the more famous attacks and illustrate how various tools are trying to help protect us as workloads become highly distributed and portable (while at the same time, attackers become ever more resourceful). - -We see a strong movement towards trustless environments (see Aporeto) and low level security (Cilium), as well as tried and true approaches at the network level like Tigera. No matter your approach, it’s good to remember: This is definitely not fine. :0 - -![][13] - -### Apps - -How to represent the huge, vast, limitless ecosystem of applications? In this case, it was easy: stay close to NYC and pick our favorites. ;) From the Postgres “elephant in the room” and the Timescale clock, to the sneaky ScyllaDB trash and the chillin’ Travis dude - we had fun putting this slice together. - -One thing that surprised us: how few people noticed the guy taking a photocopy of his rear end. I guess it’s just not that common to have a photocopy machine anymore?!? - -![][14] - -### Observability - -As our workloads start moving all over the place, and the scale gets gigantic, there is nothing quite as comforting as a really good Grafana dashboard, or that handy Datadog agent. As complexity increases, the “SRE” generation are starting to rely ever more on alerting and other intelligence events to help us make sense of what’s going on, and work towards increasingly self-healing infrastructure and applications. - -It will be interesting to see what kind of logos make their way into this floor over the coming months and years...maybe some AI, blockchain, ML powered dashboards? :-) - -![][15] - -### Traffic Management - -People tend to think that the internet “just works” but in reality, we’re kind of surprised it works at all. I mean, a loose connection of disparate networks at massive scale - you have to be joking!? - -One reason it all sticks together is traffic management, DNS and the like. More and more, these players are helping to make the interest both faster and safer, as well as more resilient. We’re especially excited to see upstarts like Fly.io and NS1 competing against well established players, and watching the entire ecosystem improve as a result. Keep rockin’ it y’all! - -![][16] - -### Users - -What good is a technology stack if you don’t have fantastic users? Granted, they sit on top of a massive stack of innovation, but in the cloud native world they do more than just consume: they create and contribute. From massive contributions like Kubernetes to more incremental (but equally important) aspects, what we’re all a part of is really quite special. - -Many of the users lounging on our rooftop deck, like Ticketmaster and the New York Times, are not mere upstarts: these are organizations that have embraced a new way of deploying and managing their applications, and their own users are reaping the rewards. - -![][17] - -### Last but not Least, the Adult Supervision! - -In previous ecosystems, foundations have played a more passive “behind the scenes” role. Not the CNCF! Their goal of building a robust cloud native ecosystem has been supercharged by the incredible popularity of the movement - and they’ve not only caught up but led the way. - -From rock solid governance and a thoughtful group of projects, to outreach like the CNCF Landscape, CNCF Cross Cloud CI, Kubernetes Certification, and Speakers Bureau - the CNCF is way more than “just” the ever popular KubeCon + CloudNativeCon. - --------------------------------------------------------------------------------- - -via: https://www.packet.net/blog/splicing-the-cloud-native-stack/ - -作者:[Zoe Allen][a] -选题:[lujun9972](https://github.com/lujun9972) -译者:[译者ID](https://github.com/译者ID) -校对:[校对者ID](https://github.com/校对者ID) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 - -[a]:https://www.packet.net/about/zoe-allen/ -[1]:https://landscape.cncf.io/landscape=cloud -[2]:https://assets.packet.net/media/images/PIFg-30.vesey.street.ny.jpg -[3]:https://www.dropbox.com/s/ujxk3mw6qyhmway/Packet_Cloud_Native_Building_Stack.jpg?dl=0 -[4]:https://assets.packet.net/media/images/3vVx-there.is.no.cloud.jpg -[5]:https://assets.packet.net/media/images/X0b9-the.bank.jpg -[6]:https://assets.packet.net/media/images/2Etm-ping.and.power.jpg -[7]:https://assets.packet.net/media/images/C800-infrastructure.jpg -[8]:https://assets.packet.net/media/images/0V4O-provisioning.jpg -[9]:https://assets.packet.net/media/images/eMYp-operating.system.jpg -[10]:https://assets.packet.net/media/images/9BII-run.time.jpg -[11]:https://assets.packet.net/media/images/njak-orchestration.jpg -[12]:https://assets.packet.net/media/images/1QUS-platforms.jpg -[13]:https://assets.packet.net/media/images/TeS9-security.jpg -[14]:https://assets.packet.net/media/images/SFgF-apps.jpg -[15]:https://assets.packet.net/media/images/SXoj-observability.jpg -[16]:https://assets.packet.net/media/images/tKhf-traffic.management.jpg -[17]:https://assets.packet.net/media/images/7cpe-users.jpg diff --git a/sources/tech/20180514 Tuptime - A Tool To Report The Historical Uptime Of Linux System.md b/sources/tech/20180514 Tuptime - A Tool To Report The Historical Uptime Of Linux System.md new file mode 100644 index 0000000000..d079dd19af --- /dev/null +++ b/sources/tech/20180514 Tuptime - A Tool To Report The Historical Uptime Of Linux System.md @@ -0,0 +1,330 @@ +Tuptime - A Tool To Report The Historical Uptime Of Linux System +====== +Beginning of this month we written an article about system uptime that helps user to check how long your Linux system has been running without downtime? when the system is up and what date. This can be done using 11 methods. + +uptime is one of the very famous commands, which everyone use when there is a requirement to check the Linux server uptime. + +But it won’t shows historical and statistical running time of Linux system, that’s why tuptime is came to picture. + +server uptime is very important when the server running with critical applications such as online portals. + +**Suggested Read :** [11 Methods To Find System/Server Uptime In Linux][1] + +### What Is tuptime? + +[Tuptime][2] is a tool for report the historical and statistical running time of the system, keeping it between restarts. Like uptime command but with more interesting output. + +### tuptime Features + + * Count system startups + * Register first boot time (a.k.a. installation time) + * Count nicely and accidentally shutdowns + * Uptime and downtime percentage since first boot time + * Accumulated system uptime, downtime and total + * Largest, shortest and average uptime and downtime + * Current uptime + * Print formatted table or list with most of the previous values + * Register used kernels + * Narrow reports since and/or until a given startup or timestamp + * Reports in csv + + + +### Prerequisites + +Make sure your system should have installed Python3 as a prerequisites. If no, install it using your distribution package manager. + +**Suggested Read :** [3 Methods To Install Latest Python3 Package On CentOS 6 System][3] + +### How To Install tuptime + +Few distributions offer tuptime package but it may be bit older version. I would advise you to install latest available version to avail all the features using the below method. + +Clone tuptime repository from github. +``` +# git clone https://github.com/rfrail3/tuptime.git + +``` + +Copy executable file from `tuptime/src/tuptime` to `/usr/bin/` and assign 755 permission. +``` +# cp tuptime/src/tuptime /usr/bin/tuptime +# chmod 755 /usr/bin/tuptime + +``` + +All scripts, units and related files are provided inside this repo so, copy and past the necessary files in the appropriate location to get full functionality of tuptime utility. + +Add tuptime user because it doesn’t run as a daemon, at least, it only need execution when the init manager startup and shutdown the system. +``` +# useradd -d /var/lib/tuptime -s /bin/sh tuptime + +``` + +Change owner of the db file. +``` +# chown -R tuptime:tuptime /var/lib/tuptime + +``` + +Copy cron file from `tuptime/src/tuptime` to `/usr/bin/` and assign 644 permission. +``` +# cp tuptime/src/cron.d/tuptime /etc/cron.d/tuptime +# chmod 644 /etc/cron.d/tuptime + +``` + +Add system service file based on your system initsystem. Use the below command to check if your system is running with systemd or init. +``` +# ps -p 1 + PID TTY TIME CMD + 1 ? 00:00:03 systemd + +# ps -p 1 + PID TTY TIME CMD + 1 ? 00:00:00 init + +``` + +If is a system with systemd, copy service file and enable it. +``` +# cp tuptime/src/systemd/tuptime.service /lib/systemd/system/ +# chmod 644 /lib/systemd/system/tuptime.service +# systemctl enable tuptime.service + +``` + +If have upstart system, copy the file: +``` +# cp tuptime/src/init.d/redhat/tuptime /etc/init.d/tuptime +# chmod 755 /etc/init.d/tuptime +# chkconfig --add tuptime +# chkconfig tuptime on + +``` + +If have init system, copy the file: +``` +# cp tuptime/src/init.d/debian/tuptime /etc/init.d/tuptime +# chmod 755 /etc/init.d/tuptime +# update-rc.d tuptime defaults +# /etc/init.d/tuptime start + +``` + +### How To Use tuptime + +Make sure you should run the command with a privileged user. Intially you will get output similar to this. +``` +# tuptime +System startups: 1 since 02:48:00 AM 04/12/2018 +System shutdowns: 0 ok - 0 bad +System uptime: 100.0 % - 26 days, 5 hours, 31 minutes and 52 seconds +System downtime: 0.0 % - 0 seconds +System life: 26 days, 5 hours, 31 minutes and 52 seconds + +Largest uptime: 26 days, 5 hours, 31 minutes and 52 seconds from 02:48:00 AM 04/12/2018 +Shortest uptime: 26 days, 5 hours, 31 minutes and 52 seconds from 02:48:00 AM 04/12/2018 +Average uptime: 26 days, 5 hours, 31 minutes and 52 seconds + +Largest downtime: 0 seconds +Shortest downtime: 0 seconds +Average downtime: 0 seconds + +Current uptime: 26 days, 5 hours, 31 minutes and 52 seconds since 02:48:00 AM 04/12/2018 + +``` + +### Details: + + * **`System startups:`** Total number of system startups from since to until date. Until is joined if is used in a narrow range. + * **`System shutdowns:`** Total number of shutdowns done correctly or incorrectly. The separator usually points to the state of last shutdown () bad. + * **`System uptime:`** Percentage of uptime and time counter. + * **`System downtime:`** Percentage of downtime and time counter. + * **`System life:`** Time counter since first startup date until last. + * **`Largest/Shortest uptime:`** Time counter and date with the largest/shortest uptime register. + * **`Largest/Shortest downtime:`** Time counter and date with the largest/shortest downtime register. + * **`Average uptime/downtime:`** Time counter with the average time. + * **`Current uptime:`** Actual time counter and date since registered boot date. + + + +If you do the same a few days after some reboot, the output may will be more similar to this. +``` +# tuptime +System startups: 3 since 02:48:00 AM 04/12/2018 +System shutdowns: 0 ok -> 2 bad +System uptime: 97.0 % - 28 days, 4 hours, 6 minutes and 0 seconds +System downtime: 3.0 % - 20 hours, 54 minutes and 22 seconds +System life: 29 days, 1 hour, 0 minutes and 23 seconds + +Largest uptime: 26 days, 5 hours, 32 minutes and 57 seconds from 02:48:00 AM 04/12/2018 +Shortest uptime: 1 hour, 31 minutes and 12 seconds from 02:17:11 AM 05/11/2018 +Average uptime: 9 days, 9 hours, 22 minutes and 0 seconds + +Largest downtime: 20 hours, 51 minutes and 58 seconds from 08:20:57 AM 05/08/2018 +Shortest downtime: 2 minutes and 24 seconds from 02:14:47 AM 05/11/2018 +Average downtime: 10 hours, 27 minutes and 11 seconds + +Current uptime: 1 hour, 31 minutes and 12 seconds since 02:17:11 AM 05/11/2018 + +``` + +Enumerate as table each startup number, startup date, uptime, shutdown date, end status and downtime. Multiple order options can be combined together. +``` +# tuptime -t +No. Startup Date Uptime Shutdown Date End Downtime + +1 02:48:00 AM 04/12/2018 26 days, 5 hours, 32 minutes and 57 seconds 08:20:57 AM 05/08/2018 BAD 20 hours, 51 minutes and 58 seconds +2 05:12:55 AM 05/09/2018 1 day, 21 hours, 1 minute and 52 seconds 02:14:47 AM 05/11/2018 BAD 2 minutes and 24 seconds +3 02:17:11 AM 05/11/2018 1 hour, 34 minutes and 33 seconds + +``` + +Enumerate as list each startup number, startup date, uptime, shutdown date, end status and offtime. Multiple order options can be combined together. +``` +# tuptime -l +Startup: 1 at 02:48:00 AM 04/12/2018 +Uptime: 26 days, 5 hours, 32 minutes and 57 seconds +Shutdown: BAD at 08:20:57 AM 05/08/2018 +Downtime: 20 hours, 51 minutes and 58 seconds + +Startup: 2 at 05:12:55 AM 05/09/2018 +Uptime: 1 day, 21 hours, 1 minute and 52 seconds +Shutdown: BAD at 02:14:47 AM 05/11/2018 +Downtime: 2 minutes and 24 seconds + +Startup: 3 at 02:17:11 AM 05/11/2018 +Uptime: 1 hour, 34 minutes and 36 seconds + +``` + +To print kernel information with tuptime output. +``` +# tuptime -k +System startups: 3 since 02:48:00 AM 04/12/2018 +System shutdowns: 0 ok -> 2 bad +System uptime: 97.0 % - 28 days, 4 hours, 11 minutes and 25 seconds +System downtime: 3.0 % - 20 hours, 54 minutes and 22 seconds +System life: 29 days, 1 hour, 5 minutes and 47 seconds +System kernels: 1 + +Largest uptime: 26 days, 5 hours, 32 minutes and 57 seconds from 02:48:00 AM 04/12/2018 +...with kernel: Linux-2.6.32-696.23.1.el6.x86_64-x86_64-with-centos-6.9-Final +Shortest uptime: 1 hour, 36 minutes and 36 seconds from 02:17:11 AM 05/11/2018 +...with kernel: Linux-2.6.32-696.23.1.el6.x86_64-x86_64-with-centos-6.9-Final +Average uptime: 9 days, 9 hours, 23 minutes and 48 seconds + +Largest downtime: 20 hours, 51 minutes and 58 seconds from 08:20:57 AM 05/08/2018 +...with kernel: Linux-2.6.32-696.23.1.el6.x86_64-x86_64-with-centos-6.9-Final +Shortest downtime: 2 minutes and 24 seconds from 02:14:47 AM 05/11/2018 +...with kernel: Linux-2.6.32-696.23.1.el6.x86_64-x86_64-with-centos-6.9-Final +Average downtime: 10 hours, 27 minutes and 11 seconds + +Current uptime: 1 hour, 36 minutes and 36 seconds since 02:17:11 AM 05/11/2018 +...with kernel: Linux-2.6.32-696.23.1.el6.x86_64-x86_64-with-centos-6.9-Final + +``` + +Change the date format. By default it’s printed based on system locales. +``` +# tuptime -d %d/%m/%y %H:%M:%S +System startups: 3 since 12/04/18 +System shutdowns: 0 ok -> 2 bad +System uptime: 97.0 % - 28 days, 4 hours, 15 minutes and 18 seconds +System downtime: 3.0 % - 20 hours, 54 minutes and 22 seconds +System life: 29 days, 1 hour, 9 minutes and 41 seconds + +Largest uptime: 26 days, 5 hours, 32 minutes and 57 seconds from 12/04/18 +Shortest uptime: 1 hour, 40 minutes and 30 seconds from 11/05/18 +Average uptime: 9 days, 9 hours, 25 minutes and 6 seconds + +Largest downtime: 20 hours, 51 minutes and 58 seconds from 08/05/18 +Shortest downtime: 2 minutes and 24 seconds from 11/05/18 +Average downtime: 10 hours, 27 minutes and 11 seconds + +Current uptime: 1 hour, 40 minutes and 30 seconds since 11/05/18 + +``` + +Print information about the internals of tuptime. It’s good for debugging how it gets the variables. +``` +# tuptime -v +INFO:Arguments: {'endst': 0, 'seconds': None, 'table': False, 'csv': False, 'ts': None, 'silent': False, 'order': False, 'since': 0, 'kernel': False, 'reverse': False, 'until': 0, 'db_file': '/var/lib/tuptime/tuptime.db', 'lst': False, 'tu': None, 'date_format': '%X %x', 'update': True} +INFO:Linux system +INFO:uptime = 5773.54 +INFO:btime = 1526019431 +INFO:kernel = Linux-2.6.32-696.23.1.el6.x86_64-x86_64-with-centos-6.9-Final +INFO:Execution user = 0 +INFO:Directory exists = /var/lib/tuptime +INFO:DB file exists = /var/lib/tuptime/tuptime.db +INFO:Last btime from db = 1526019431 +INFO:Last uptime from db = 5676.04 +INFO:Drift over btime = 0 +INFO:System wasn't restarted. Updating db values... +System startups: 3 since 02:48:00 AM 04/12/2018 +System shutdowns: 0 ok -> 2 bad +System uptime: 97.0 % - 28 days, 4 hours, 11 minutes and 2 seconds +System downtime: 3.0 % - 20 hours, 54 minutes and 22 seconds +System life: 29 days, 1 hour, 5 minutes and 25 seconds + +Largest uptime: 26 days, 5 hours, 32 minutes and 57 seconds from 02:48:00 AM 04/12/2018 +Shortest uptime: 1 hour, 36 minutes and 14 seconds from 02:17:11 AM 05/11/2018 +Average uptime: 9 days, 9 hours, 23 minutes and 41 seconds + +Largest downtime: 20 hours, 51 minutes and 58 seconds from 08:20:57 AM 05/08/2018 +Shortest downtime: 2 minutes and 24 seconds from 02:14:47 AM 05/11/2018 +Average downtime: 10 hours, 27 minutes and 11 seconds + +Current uptime: 1 hour, 36 minutes and 14 seconds since 02:17:11 AM 05/11/2018 + +``` + +Print a quick reference of the command line parameters. +``` +# tuptime -h +Usage: tuptime [options] + +Options: + -h, --help show this help message and exit + -c, --csv csv output + -d DATE_FORMAT, --date=DATE_FORMAT + date format output + -f FILE, --filedb=FILE + database file + -g, --graceful register a gracefully shutdown + -k, --kernel print kernel information + -l, --list enumerate system life as list + -n, --noup avoid update values + -o TYPE, --order=TYPE + order enumerate by [] + -r, --reverse reverse order + -s, --seconds output time in seconds and epoch + -S SINCE, --since=SINCE + restric since this register number + -t, --table enumerate system life as table + --tsince=TIMESTAMP restrict since this epoch timestamp + --tuntil=TIMESTAMP restrict until this epoch timestamp + -U UNTIL, --until=UNTIL + restrict until this register number + -v, --verbose verbose output + -V, --version show version + -x, --silent update values into db without output + +``` + +-------------------------------------------------------------------------------- + +via: https://www.2daygeek.com/tuptime-a-tool-to-report-the-historical-and-statistical-running-time-of-linux-system/ + +作者:[Prakash Subramanian][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.2daygeek.com/author/prakash/ +[1]:https://www.2daygeek.com/11-methods-to-find-check-system-server-uptime-in-linux/ +[2]:https://github.com/rfrail3/tuptime/ +[3]:https://www.2daygeek.com/3-methods-to-install-latest-python3-package-on-centos-6-system/ diff --git a/sources/tech/20180515 Give Your Linux Desktop a Stunning Makeover With Xenlism Themes.md b/sources/tech/20180515 Give Your Linux Desktop a Stunning Makeover With Xenlism Themes.md deleted file mode 100644 index f76a483199..0000000000 --- a/sources/tech/20180515 Give Your Linux Desktop a Stunning Makeover With Xenlism Themes.md +++ /dev/null @@ -1,92 +0,0 @@ -Give Your Linux Desktop a Stunning Makeover With Xenlism Themes -============================================================ - - - _Brief: Xenlism theme pack provides an aesthetically pleasing GTK theme, colorful icons, and minimalist wallpapers to transform your Linux desktop into an eye-catching setup._ - -It’s not every day that I dedicate an entire article to a theme unless I find something really awesome. I used to cover themes and icons regularly. But lately, I preferred having lists of [best GTK themes][6] and icon themes. This is more convenient for me and for you as well as you get to see many beautiful themes in one place. - -After [Pop OS theme][7] suit, Xenlism is another theme that has left me awestruck by its look.  - -![Xenlism GTK theme for Ubuntu and Other Linux](https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/05/xenlishm-minimalism-gtk-theme-800x450.jpeg) - -Xenlism GTK theme is based on the Arc theme, an inspiration behind so many themes these days. The GTK theme provides Windows buttons similar to macOS which I neither like nor dislike. The GTK theme has a flat, minimalist layout and I like that. - -There are two icon themes in the Xenlism suite. Xenlism Wildfire is an old one and had already made to our list of [best icon themes][8]. - -![Beautiful Xenlism Wildfire theme for Ubuntu and Other Linux](https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/05/xenlism-wildfire-theme-800x450.jpeg) -Xenlism Wildfire Icons - -Xenlsim Storm is the relatively new icon theme but is equally beautiful. - -![Beautiful Xenlism Storm theme for Ubuntu and Other Linux](https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/05/xenlism-storm-theme-1-800x450.jpeg) -Xenlism Storm Icons - -Xenlism themes are open source under GPL license. - -### How to install Xenlism theme pack on Ubuntu 18.04 - -Xenlism dev provides an easier way of installing the theme pack through a PPA. Though the PPA is available for Ubuntu 16.04, I found the GTK theme wasn’t working with Unity. It works fine with the GNOME desktop in Ubuntu 18.04. - -Open a terminal (Ctrl+Alt+T) and use the following commands one by one: - -``` -sudo add-apt-repository ppa:xenatt/xenlism -sudo apt update -``` - -This PPA offers four packages: - -* xenlism-finewalls: for a set of wallpapers that will be available directly in the wallpaper section of Ubuntu. One of the wallpapers has been used in the screenshot. - -* xenlism-minimalism-theme: GTK theme - -* xenlism-storm: an icon theme (see previous screenshots) - -* xenlism-wildfire-icon-theme: another icon theme with several color variants (folder colors get changed in the variants) - -You can decide on your own what theme component you want to install. Personally, I don’t see any harm in installing all the components. - -``` -sudo apt install xenlism-minimalism-theme xenlism-storm-icon-theme xenlism-wildfire-icon-theme xenlism-finewalls -``` - -You can use GNOME Tweaks for changing the theme and icons. If you are not familiar with the procedure already, I suggest reading this tutorial to learn [how to install themes in Ubuntu 18.04 GNOME][9]. - -### Getting Xenlism themes in other Linux distributions - -You can install Xenlism themes on other Linux distributions as well. Installation instructions for various Linux distributions can be found on its website: - -[Install Xenlism Themes][10] - -### What do you think? - -I know not everyone would agree with me but I loved this theme. I think you are going to see the glimpse of Xenlism theme in the screenshots in future tutorials on It’s FOSS. - -Did you like Xenlism theme? If not, what theme do you like the most? Share your opinion in the comment section below. - -#### 关于作者 - -I am a professional software developer, and founder of It's FOSS. I am an avid Linux lover and Open Source enthusiast. I use Ubuntu and believe in sharing knowledge. Apart from Linux, I love classic detective mysteries. I'm a huge fan of Agatha Christie's work. - --------------------------------------------------------------------------------- - -via: https://itsfoss.com/xenlism-theme/ - -作者:[Abhishek Prakash ][a] -译者:[译者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/ -[1]:https://itsfoss.com/author/abhishek/ -[2]:https://itsfoss.com/xenlism-theme/#comments -[3]:https://itsfoss.com/category/desktop/ -[4]:https://itsfoss.com/tag/themes/ -[5]:https://itsfoss.com/tag/xenlism/ -[6]:https://itsfoss.com/best-gtk-themes/ -[7]:https://itsfoss.com/pop-icon-gtk-theme-ubuntu/ -[8]:https://itsfoss.com/best-icon-themes-ubuntu-16-04/ -[9]:https://itsfoss.com/install-themes-ubuntu/ -[10]:http://xenlism.github.io/minimalism/#install diff --git a/sources/tech/20180516 Manipulating Directories in Linux.md b/sources/tech/20180516 Manipulating Directories in Linux.md deleted file mode 100644 index 9c6df23e43..0000000000 --- a/sources/tech/20180516 Manipulating Directories in Linux.md +++ /dev/null @@ -1,182 +0,0 @@ -Manipulating Directories in Linux -====== - -![](https://www.linux.com/sites/lcom/files/styles/rendered_file/public/branches-238379_1920_0.jpg?itok=2PlNpsVu) - -If you are new to this series (and to Linux), [take a look at our first installment][1]. In that article, we worked our way through the tree-like structure of the Linux filesystem, or more precisely, the File Hierarchy Standard. I recommend reading through it to make sure you understand what you can and cannot safely touch. Because this time around, I’ll show how to get all touchy-feely with your directories. - -### Making Directories - -Let's get creative before getting destructive, though. To begin, open a terminal window and use `mkdir` to create a new directory like this: -``` -mkdir - -``` - -If you just put the directory name, the directory will appear hanging off the directory you are currently in. If you just opened a terminal, that will be your home directory. In a case like this, we say the directory will be created _relative_ to your current position: -``` -$ pwd #This tells you where you are now -- see our first tutorial -/home/ -$ mkdir newdirectory #Creates /home//newdirectory - -``` - -(Note that you do not have to type the text following the `#`. Text following the pound symbol `#` is considered a comment and is used to explain what is going on. It is ignored by the shell). - -You can create a directory within an existing directory hanging off your current location by specifying it in the command line: -``` -mkdir Documents/Letters - -``` - -Will create the _Letters_ directory within the _Documents_ directory. - -You can also create a directory above where you are by using `..` in the path. Say you move into the _Documents/Letters/_ directory you just created and you want to create a _Documents/Memos/_ directory. You can do: -``` -cd Documents/Letters # Move into your recently created Letters/ directory -mkdir ../Memos - -``` - -Again, all of the above is done relative to you current position. This is called using a _relative path_. - -You can also use an _absolute path_ to directories: This means telling `mkdir` where to put your directory in relation to the root (`/`) directory: -``` -mkdir /home//Documents/Letters - -``` - -Change `` to your user name in the command above and it will be equivalent to executing `mkdir Documents/Letters` from your home directory, except that it will work from wherever you are located in the directory tree. - -As a side note, regardless of whether you use a relative or an absolute path, if the command is successful, `mkdir` will create the directory silently, without any apparent feedback whatsoever. Only if there is some sort of trouble will `mkdir` print some feedback after you hit _[Enter]_. - -As with most other command-line tools, `mkdir` comes with several interesting options. The `-p` option is particularly useful, as it lets you create directories within directories within directories, even if none exist. To create, for example, a directory for letters to your Mom within _Documents/_ , you could do: -``` -mkdir -p Documents/Letters/Family/Mom - -``` - -And `mkdir` will create the whole branch of directories above _Mom/_ and also the directory _Mom/_ for you, regardless of whether any of the parent directories existed before you issued the command. - -You can also create several folders all at once by putting them one after another, separated by spaces: -``` -mkdir Letters Memos Reports - -``` - -will create the directories _Letters/_ , _Memos/_ and _Reports_ under the current directory. - -### In space nobody can hear you scream - -... Which brings us to the tricky question of spaces in directory names. Can you use spaces in directory names? Yes, you can. Is it advised you use spaces? No, absolutely not. Spaces make everything more complicated and, potentially, dangerous. - -Say you want to create a directory called _letters mom/_. If you didn't know any better, you could type: -``` -mkdir letters mom - -``` - -But this is WRONG! WRONG! WRONG! As we saw above, this will create two directories, _letters/_ and _mom/_ , but not _letters mom/_. - -Agreed that this is a minor annoyance: all you have to do is delete the two directories and start over. No big deal. - -But, wait! Deleting directories is where things get dangerous. Imagine you did create _letters mom/_ using a graphical tool, like, say [Dolphin][2] or [Nautilus][3]. If you suddenly decide to delete _letters mom/_ from a terminal, and you have another directory just called _letters/_ under the same directory, and said directory is full of important documents, and you tried this: -``` -rmdir letters mom - -``` - -You would risk removing _letters/_. I say "risk" because fortunately `rmdir`, the instruction used to remove directories, has a built in safeguard and will warn you if you try to delete a non-empty directory. - -However, this: -``` -rm -Rf letters mom - -``` - -(and this is a pretty standard way of getting rid of directories and their contents) will completely obliterate _letters/_ and will never even tell you what just happened. - -The `rm` command is used to delete files and directories. When you use it with the options `-R` (delete _recursively_ ) and `-f` ( _force_ deletion), it will burrow down into a directory and its subdirectories, deleting all the files they contain, then deleting the subdirectories themselves, then it will delete all the files in the top directory and then the directory itself. - -`rm -Rf` is an instruction you must handle with extreme care. - -My advice is, instead of spaces, use underscores (`_`), but if you still insist on spaces, there are two ways of getting them to work. You can use single or double quotes (`'` or `"`) like so: -``` -mkdir 'letters mom' -mkdir "letters dad" - -``` - -Or, you can _escape_ the spaces. Some characters have a special meaning for the shell. Spaces, as you have seen, are used to separate options and arguments on the command line. "Separating options and arguments" falls under the category of "special meaning". When you want the shell to ignore the special meaning of a character, you need to _escape_ it and to escape a character, you put a backslash (`\`) in front of it: -``` -mkdir letters\ mom -mkdir letter\ dad - -``` - -There are other special characters that would need escaping, like the apostrophe or single quote (`'`), double quotes (`"`), and the ampersand (`&`): -``` -mkdir mom\ \&\ dad\'s\ letters - -``` - -I know what you're thinking: If the backslash has a special meaning (to wit, telling the shell it has to escape the next character), that makes it a special character, too. Then, how would you escape the escape character which is `\`? - -Turns out, the exact way you escape any other special character: -``` -mkdir special\\characters - -``` - -will produce a directory called _special\characters_. - -Confusing? Of course. That's why you should avoid using special characters, including spaces, in directory names. - -For the record, here is a list of special characters you can refer to just in case. - -### Things to Remember - - * Use `mkdir ` to create a new directory. - * Use `rmdir ` to delete a directory (only works if it is empty). - * Use `rm -Rf ` to annihilate a directory -- use with extreme caution. - * Use a relative path to create directories relative to your current directory: `mkdir newdir.`. - * Use an absolute path to create directories relative to the root directory (`/`): `mkdir /home//newdir` - * Use `..` to create a directory in the directory above the current directory: `mkdir ../newdir` - * You can create several directories all in one go by separating them with spaces on the command line: `mkdir onedir twodir threedir` - * You can mix and mash relative and absolute paths when creating several directories simultaneously: `mkdir onedir twodir /home//threedir` - * Using spaces and special characters in directory names guarantees plenty of headaches and heartburn. Don't do it. - - - -For more information, you can look up the manuals of `mkdir`, `rmdir` and `rm`: -``` -man mkdir -man rmdir -man rm - -``` - -To exit the man pages, press _[q]_. - -### Next Time - -In the next installment, you'll learn about creating, modifying, and erasing files, as well as everything you need to know about permissions and privileges. See you then! - -Learn more about Linux through the free ["Introduction to Linux" ][4]course from The Linux Foundation and edX. - --------------------------------------------------------------------------------- - -via: https://www.linux.com/blog/learn/2018/5/manipulating-directories-linux - -作者:[Paul Brown][a] -选题:[lujun9972](https://github.com/lujun9972) -译者:[译者ID](https://github.com/译者ID) -校对:[校对者ID](https://github.com/校对者ID) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 - -[a]:https://www.linux.com/users/bro66 -[1]:https://www.linux.com/blog/learn/intro-to-linux/2018/4/linux-filesystem-explained -[2]:https://userbase.kde.org/Dolphin -[3]:https://projects-old.gnome.org/nautilus/screenshots.html -[4]:https://training.linuxfoundation.org/linux-courses/system-administration-training/introduction-to-linux diff --git a/sources/tech/20180522 Free Resources for Securing Your Open Source Code.md b/sources/tech/20180522 Free Resources for Securing Your Open Source Code.md deleted file mode 100644 index 4a7522ff9f..0000000000 --- a/sources/tech/20180522 Free Resources for Securing Your Open Source Code.md +++ /dev/null @@ -1,83 +0,0 @@ -Free Resources for Securing Your Open Source Code -====== - -![](https://www.linux.com/sites/lcom/files/styles/rendered_file/public/open-security.jpg?itok=R3M5LDrb) - -While the widespread adoption of open source continues at a healthy rate, the recent [2018 Open Source Security and Risk Analysis Report][1] from Black Duck and Synopsys reveals some common concerns and highlights the need for sound security practices. The report examines findings from the anonymized data of over 1,100 commercial codebases with represented Industries from automotive, Big Data, enterprise software, financial services, healthcare, IoT, manufacturing, and more. - -The report highlights a massive uptick in open source adoption, with 96 percent of the applications scanned containing open source components. However, the report also includes warnings about existing vulnerabilities. Among the [findings][2]: - - * “What is worrisome is that 78 percent of the codebases examined contained at least one open source vulnerability, with an average 64 vulnerabilities per codebase.” - - * “Over 54 percent of the vulnerabilities found in audited codebases are considered high-risk vulnerabilities.” - - * Seventeen percent of the codebases contained a highly publicized vulnerability such as Heartbleed, Logjam, Freak, Drown, or Poodle. - - - - -"The report clearly demonstrates that with the growth in open source use, organizations need to ensure they have the tools to detect vulnerabilities in open source components and manage whatever license compliance their use of open source may require," said Tim Mackey, technical evangelist at Black Duck by Synopsys. - -Indeed, with ever more impactful security threats emerging,the need for fluency with security tools and practices has never been more pronounced. Most organizations are aware that network administrators and sysadmins need to have strong security skills, and, in many cases security certifications. [In this article,][3] we explored some of the tools, certifications and practices that many of them wisely embrace. - -The Linux Foundation has also made available many informational and educational resources on security. Likewise, the Linux community offers many free resources for specific platforms and tools. For example, The Linux Foundation has published a [Linux workstation security checklist][4] that covers a lot of good ground. Online publications ranging from the [Fedora security guide][5] to the[Securing Debian Manual][6] can also help users protect against vulnerabilities within specific platforms. - -The widespread use of cloud platforms such as OpenStack is also stepping up the need for cloud-centric security smarts. According to The Linux Foundation’s[Guide to the Open Cloud][7]: “Security is still a top concern among companies considering moving workloads to the public cloud, according to Gartner, despite a strong track record of security and increased transparency from cloud providers. Rather, security is still an issue largely due to companies’ inexperience and improper use of cloud services.” - -For both organizations and individuals, the smallest holes in implementation of routers, firewalls, VPNs, and virtual machines can leave room for big security problems. Here is a collection of free tools that can plug these kinds of holes: - - * [Wireshark][8], a packet analyzer - - * [KeePass Password Safe][9], a free open source password manager - - * [Malwarebytes][10], a free anti-malware and antivirus tool - - * [NMAP][11], a powerful security scanner - - * [NIKTO][12], an open source web server scanner - - * [Ansible][13], a tool for automating secure IT provisioning - - * [Metasploit][14], a tool for understanding attack vectors and doing penetration testing - - - - -Instructional videos abound for these tools. You’ll find a whole[tutorial series][15] for Metasploit, and [video tutorials][16] for Wireshark. Quite a few free ebooks provide good guidance on security as well. For example, one of the common ways for security threats to invade open source platforms occurs in M&A scenarios, where technology platforms are merged—often without proper open source audits. In an ebook titled [Open Source Audits in Merger and Acquisition Transactions][17], from Ibrahim Haddad and The Linux Foundation, you’ll find an overview of the open source audit process and important considerations for code compliance, preparation, and documentation. - -Meanwhile, we’ve[previously covered][18] a free ebook from the editors at[The New Stack][19] called Networking, Security & Storage with Docker & Containers. It covers the latest approaches to secure container networking, as well as native efforts by Docker to create efficient and secure networking practices. The ebook is loaded with best practices for locking down security at scale. - -All of these tools and resources, and many more, can go a long way toward preventing security problems, and an ounce of prevention is, as they say, worth a pound of cure. With security breaches continuing, now is an excellent time to look into the many security and compliance resources for open source tools and platforms available. Learn more about security, compliance, and open source project health [here][20]. - --------------------------------------------------------------------------------- - -via: https://www.linux.com/blog/2018/5/free-resources-securing-your-open-source-code - -作者:[Sam Dean][a] -选题:[lujun9972](https://github.com/lujun9972) -译者:[译者ID](https://github.com/译者ID) -校对:[校对者ID](https://github.com/校对者ID) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 - -[a]:https://www.linux.com/users/sam-dean -[1]:https://www.blackducksoftware.com/open-source-security-risk-analysis-2018 -[2]:https://www.prnewswire.com/news-releases/synopsys-report-finds-majority-of-software-plagued-by-known-vulnerabilities-and-license-conflicts-as-open-source-adoption-soars-300648367.html -[3]:https://www.linux.com/blog/sysadmin-ebook/2017/8/future-proof-your-sysadmin-career-locking-down-security -[4]:http://go.linuxfoundation.org/ebook_workstation_security -[5]:https://docs.fedoraproject.org/en-US/Fedora/19/html/Security_Guide/index.html -[6]:https://www.debian.org/doc/manuals/securing-debian-howto/index.en.html -[7]:https://www.linux.com/publications/2016-guide-open-cloud -[8]:https://www.wireshark.org/ -[9]:http://keepass.info/ -[10]:https://www.malwarebytes.com/ -[11]:http://searchsecurity.techtarget.co.uk/tip/Nmap-tutorial-Nmap-scan-examples-for-vulnerability-discovery -[12]:https://cirt.net/Nikto2 -[13]:https://www.ansible.com/ -[14]:https://www.metasploit.com/ -[15]:http://www.computerweekly.com/tutorial/The-Metasploit-Framework-Tutorial-PDF-compendium-Your-ready-reckoner -[16]:https://www.youtube.com/watch?v=TkCSr30UojM -[17]:https://www.linuxfoundation.org/resources/open-source-audits-merger-acquisition-transactions/ -[18]:https://www.linux.com/news/networking-security-storage-docker-containers-free-ebook-covers-essentials -[19]:http://thenewstack.io/ebookseries/ -[20]:https://www.linuxfoundation.org/projects/security-compliance/ diff --git a/sources/tech/20180522 How to Run Your Own Git Server.md b/sources/tech/20180522 How to Run Your Own Git Server.md deleted file mode 100644 index 9a1ee8509a..0000000000 --- a/sources/tech/20180522 How to Run Your Own Git Server.md +++ /dev/null @@ -1,233 +0,0 @@ -translating by wyxplus -How to Run Your Own Git Server -====== -**Learn how to set up your own Git server in this tutorial from our archives.** - -[Git ][1]is a versioning system [developed by Linus Torvalds][2], that is used by millions of users around the globe. Companies like GitHub offer code hosting services based on Git. [According to reports, GitHub, a code hosting site, is the world's largest code hosting service.][3] The company claims that there are 9.2M people collaborating right now across 21.8M repositories on GitHub. Big companies are now moving to GitHub. [Even Google, the search engine giant, is shutting it's own Google Code and moving to GitHub.][4] - -### Run your own Git server - -GitHub is a great service, however there are some limitations and restrictions, especially if you are an individual or a small player. One of the limitations of GitHub is that the free service doesn’t allow private hosting of the code. [You have to pay a monthly fee of $7 to host 5 private repositories][5], and the expenses go up with more repos. - -In cases like these or when you want more control, the best path is to run Git on your own server. Not only do you save costs, you also have more control over your server. In most cases a majority of advanced Linux users already have their own servers and pushing Git on those servers is like ‘free as in beer’. - -In this tutorial we are going to talk about two methods of managing your code on your own server. One is running a bare, basic Git server and and the second one is via a GUI tool called [GitLab][6]. For this tutorial I used a fully patched Ubuntu 14.04 LTS server running on a VPS. - -### Install Git on your server - -In this tutorial we are considering a use-case where we have a remote server and a local server and we will work between these machines. For the sake of simplicity we will call them remote-server and local-server. - -First, install Git on both machines. You can install Git from the packages already available via the repos or your distros, or you can do it manually. In this article we will use the simpler method: -``` -sudo apt-get install git-core - -``` - -Then add a user for Git. -``` -sudo useradd git -passwd git - -``` - -In order to ease access to the server let's set-up a password-less ssh login. First create ssh keys on your local machine: -``` -ssh-keygen -t rsa - -``` - -It will ask you to provide the location for storing the key, just hit Enter to use the default location. The second question will be to provide it with a pass phrase which will be needed to access the remote server. It generates two keys - a public key and a private key. Note down the location of the public key which you will need in the next step. - -Now you have to copy these keys to the server so that the two machines can talk to each other. Run the following command on your local machine: -``` -cat ~/.ssh/id_rsa.pub | ssh git@remote-server "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys" - -``` - -Now ssh into the server and create a project directory for Git. You can use the desired path for the repo. - -Then change to this directory: -``` -cd /home/swapnil/project-1.git - -``` - -Then create an empty repo: -``` -git init --bare -Initialized empty Git repository in /home/swapnil/project-1.git - -``` - -We now need to create a Git repo on the local machine. -``` -mkdir -p /home/swapnil/git/project - -``` - -And change to this directory: -``` -cd /home/swapnil/git/project - -``` - -Now create the files that you need for the project in this directory. Stay in this directory and initiate git: -``` -git init -Initialized empty Git repository in /home/swapnil/git/project - -``` - -Now add files to the repo: -``` -git add . - -``` - -Now every time you add a file or make changes you have to run the add command above. You also need to write a commit message with every change in a file. The commit message basically tells what changes were made. -``` -git commit -m "message" -a -[master (root-commit) 57331ee] message - 2 files changed, 2 insertions(+) - create mode 100644 GoT.txt - create mode 100644 writing.txt - -``` - -In this case I had a file called GoT (Game of Thrones review) and I made some changes, so when I ran the command it specified that changes were made to the file. In the above command '-a' option means commits for all files in the repo. If you made changes to only one you can specify the name of that file instead of using '-a'. - -An example: -``` -git commit -m "message" GoT.txt -[master e517b10] message - 1 file changed, 1 insertion(+) - -``` - -Until now we have been working on the local server. Now we have to push these changes to the server so the work is accessible over the Internet and you can collaborate with other team members. -``` -git remote add origin ssh://git@remote-server/repo->path-on-server..git - -``` - -Now you can push or pull changes between the server and local machine using the 'push' or 'pull' option: -``` -git push origin master - -``` - -If there are other team members who want to work with the project they need to clone the repo on the server to their local machine: -``` -git clone git@remote-server:/home/swapnil/project.git - -``` - -Here /home/swapnil/project.git is the project path on the remote server, exchange the values for your own server. - -Then change directory on the local machine (exchange project with the name of project on your server): -``` -cd /project - -``` - -Now they can edit files, write commit change messages and then push them to the server: -``` -git commit -m 'corrections in GoT.txt story' -a -And then push changes: - -git push origin master - -``` - -I assume this is enough for a new user to get started with Git on their own servers. If you are looking for some GUI tools to manage changes on local machines, you can use GUI tools such as QGit or GitK for Linux. - -### Using GitLab - -This was a pure command line solution for project owner and collaborator. It's certainly not as easy as using GitHub. Unfortunately, while GitHub is the world's largest code hosting service; its own software is not available for others to use. It's not open source so you can't grab the source code and compile your own GitHub. Unlike WordPress or Drupal you can't download GitHub and run it on your own servers. - -As usual in the open source world there is no end to the options. GitLab is a nifty project which does exactly that. It's an open source project which allows users to run a project management system similar to GitHub on their own servers. - -You can use GitLab to run a service similar to GitHub for your team members or your company. You can use GitLab to work on private projects before releasing them for public contributions. - -GitLab employs the traditional Open Source business model. They have two products: free of cost open source software, which users can install on their own servers, and a hosted service similar to GitHub. - -The downloadable version has two editions - the free of cost community edition and the paid enterprise edition. The enterprise edition is based on the community edition but comes with additional features targeted at enterprise customers. It’s more or less similar to what WordPress.org or Wordpress.com offer. - -The community edition is highly scalable and can support 25,000 users on a single server or cluster. Some of the features of GitLab include: Git repository management, code reviews, issue tracking, activity feeds, and wikis. It comes with GitLab CI for continuous integration and delivery. - -Many VPS providers such as Digital Ocean offer GitLab droplets for users. If you want to run it on your own server, you can install it manually. GitLab offers an Omnibus package for different operating systems. Before we install GitLab, you may want to configure an SMTP email server so that GitLab can push emails as and when needed. They recommend Postfix. So, install Postfix on your server: -``` -sudo apt-get install postfix - -``` - -During installation of Postfix it will ask you some questions; don't skip them. If you did miss it you can always re-configure it using this command: -``` -sudo dpkg-reconfigure postfix - -``` - -When you run this command choose "Internet Site" and provide the email ID for the domain which will be used by Gitlab. - -In my case I provided it with: -``` -This e-mail address is being protected from spambots. You need JavaScript enabled to view it - - -``` - -Use Tab and create a username for postfix. The Next page will ask you to provide a destination for mail. - -In the rest of the steps, use the default options. Once Postfix is installed and configured, let's move on to install GitLab. - -Download the packages using wget (replace the download link with the [latest packages from here][7]) : -``` -wget https://downloads-packages.s3.amazonaws.com/ubuntu-14.04/gitlab_7.9.4-omnibus.1-1_amd64.deb - -``` - -Then install the package: -``` -sudo dpkg -i gitlab_7.9.4-omnibus.1-1_amd64.deb - -``` - -Now it's time to configure and start GitLabs. -``` -sudo gitlab-ctl reconfigure - -``` - -You now need to configure the domain name in the configuration file so you can access GitLab. Open the file. -``` -nano /etc/gitlab/gitlab.rb - -``` - -In this file edit the 'external_url' and give the server domain. Save the file and then open the newly created GitLab site from a web browser. - -By default it creates 'root' as the system admin and uses '5iveL!fe' as the password. Log into the GitLab site and then change the password. - -Once the password is changed, log into the site and start managing your project. - -GitLab is overflowing with features and options. I will borrow popular lines from the movie, The Matrix: "Unfortunately, no one can be told what all GitLab can do. You have to try it for yourself." - --------------------------------------------------------------------------------- - -via: https://www.linux.com/learn/how-run-your-own-git-server - -作者:[Swapnil Bhartiya][a] -选题:[lujun9972](https://github.com/lujun9972) -译者:[译者ID](https://github.com/译者ID) -校对:[校对者ID](https://github.com/校对者ID) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 - -[a]:https://www.linux.com/users/arnieswap -[1]:https://github.com/git/git -[2]:https://www.linuxfoundation.org/blog/10-years-of-git-an-interview-with-git-creator-linus-torvalds/ -[3]:https://github.com/about/press -[4]:http://google-opensource.blogspot.com/2015/03/farewell-to-google-code.html -[5]:https://github.com/pricing -[6]:https://about.gitlab.com/ -[7]:https://about.gitlab.com/downloads/ diff --git a/sources/tech/20180523 A Set Of Useful Utilities For Debian And Ubuntu Users.md b/sources/tech/20180523 A Set Of Useful Utilities For Debian And Ubuntu Users.md deleted file mode 100644 index e14f5ac850..0000000000 --- a/sources/tech/20180523 A Set Of Useful Utilities For Debian And Ubuntu Users.md +++ /dev/null @@ -1,287 +0,0 @@ -A Set Of Useful Utilities For Debian And Ubuntu Users -====== - -![](https://www.ostechnix.com/debian-goodies-a-set-of-useful-utilities-for-debian-and-ubuntu-users/) - -Are you using a Debian-based system? Great! I am here today with a good news for you. Say hello to **“Debian-goodies”** , a collection of useful utilities for Debian-based systems, like Ubuntu, Linux Mint. These set of utilities provides some additional useful commands which are not available by default in the Debian-based systems. Using these tools, the users can find which programs are consuming more disk space, which services need to be restarted after updating the system, search for a file matching a pattern in a package, list the installed packages based on the search string and a lot more. In this brief guide, we will be discussing some useful Debian goodies. - -### Debian-goodies – Useful Utilities For Debian And Ubuntu Users - -The debian-goodies package is available in the official repositories of Debian and its derivative Ubuntu and other Ubuntu variants such as Linux Mint. To install debian-goodies package, simply run: -``` -$ sudo apt-get install debian-goodies - -``` - -Debian-goodies has just been installed. Let us go ahead and see some useful utilities. - -#### **1. Checkrestart** - -Let me start from one of my favorite, the **“checkrestart”** utility. When installing security updates, some running applications might still use the old libraries. In order to apply the security updates completely, you need to find and restart all of them. This is where Checkrestart comes in handy. This utility will find which processes are still using the old versions of libs. You can then restart the services. - -To check which daemons need to be restarted after library upgrades, run: -``` -$ sudo checkrestart -[sudo] password for sk: -Found 0 processes using old versions of upgraded files - -``` - -Since I didn’t perform any security updates lately, it shows nothing. - -Please note that Checkrestart utility does work well. However, there is a new similar tool named “needrestart” available latest Debian systems. The needrestart is inspired by the checkrestart utility and it does exactly the same job. Needrestart is actively maintained and supports newer technologies such as containers (LXC, Docker). - -Here are the features of Needrestart: - - * supports (but does not require) systemd - * binary blacklisting (i.e. display managers) - * tries to detect pending kernel upgrades - * tries to detect required restarts of interpreter based daemons (supports Perl, Python, Ruby) - * fully integrated into apt/dpkg using hooks - - - -It is available in the default repositories too. so, you can install it using command: -``` -$ sudo apt-get install needrestart - -``` - -Now you can check the list of daemons need to be restarted after updating your system using command: -``` -$ sudo needrestart -Scanning processes... -Scanning linux images... - -Running kernel seems to be up-to-date. - -Failed to check for processor microcode upgrades. - -No services need to be restarted. - -No containers need to be restarted. - -No user sessions are running outdated binaries. - -``` - -The good thing is Needrestart works on other Linux distributions too. For example, you can install on Arch Linux and its variants from AUR using any AUR helper programs like below. -``` -$ yaourt -S needrestart - -``` - -On fedora: -``` -$ sudo dnf install needrestart - -``` - -#### 2. Check-enhancements - -The check-enhancements utility is used to find packages which enhance the installed packages. This utility will list all packages that enhances other packages but are not strictly necessary to run it. You can find enhancements for a single package or all installed installed packages using “-ip” or “–installed-packages” flag. - -For example, I am going to list the enhancements for gimp package. -``` -$ check-enhancements gimp -gimp => gimp-data: Installed: (none) Candidate: 2.8.22-1 -gimp => gimp-gmic: Installed: (none) Candidate: 1.7.9+zart-4build3 -gimp => gimp-gutenprint: Installed: (none) Candidate: 5.2.13-2 -gimp => gimp-help-ca: Installed: (none) Candidate: 2.8.2-0.1 -gimp => gimp-help-de: Installed: (none) Candidate: 2.8.2-0.1 -gimp => gimp-help-el: Installed: (none) Candidate: 2.8.2-0.1 -gimp => gimp-help-en: Installed: (none) Candidate: 2.8.2-0.1 -gimp => gimp-help-es: Installed: (none) Candidate: 2.8.2-0.1 -gimp => gimp-help-fr: Installed: (none) Candidate: 2.8.2-0.1 -gimp => gimp-help-it: Installed: (none) Candidate: 2.8.2-0.1 -gimp => gimp-help-ja: Installed: (none) Candidate: 2.8.2-0.1 -gimp => gimp-help-ko: Installed: (none) Candidate: 2.8.2-0.1 -gimp => gimp-help-nl: Installed: (none) Candidate: 2.8.2-0.1 -gimp => gimp-help-nn: Installed: (none) Candidate: 2.8.2-0.1 -gimp => gimp-help-pt: Installed: (none) Candidate: 2.8.2-0.1 -gimp => gimp-help-ru: Installed: (none) Candidate: 2.8.2-0.1 -gimp => gimp-help-sl: Installed: (none) Candidate: 2.8.2-0.1 -gimp => gimp-help-sv: Installed: (none) Candidate: 2.8.2-0.1 -gimp => gimp-plugin-registry: Installed: (none) Candidate: 7.20140602ubuntu3 -gimp => xcftools: Installed: (none) Candidate: 1.0.7-6 - -``` - -To list the enhancements for all installed packages, run: -``` -$ check-enhancements -ip -autoconf => autoconf-archive: Installed: (none) Candidate: 20170928-2 -btrfs-progs => snapper: Installed: (none) Candidate: 0.5.4-3 -ca-certificates => ca-cacert: Installed: (none) Candidate: 2011.0523-2 -cryptsetup => mandos-client: Installed: (none) Candidate: 1.7.19-1 -dpkg => debsig-verify: Installed: (none) Candidate: 0.18 -[...] - -``` - -#### 3. dgrep - -As the name implies, dgrep is used to search all files in specified packages based on the given regex. For instance, I am going to search for files that contains the regex “text” in Vim package. -``` -$ sudo dgrep "text" vim -Binary file /usr/bin/vim.tiny matches -/usr/share/doc/vim-tiny/copyright: that they must include this license text. You can also distribute -/usr/share/doc/vim-tiny/copyright: include this license text. You are also allowed to include executables -/usr/share/doc/vim-tiny/copyright: 1) This license text must be included unmodified. -/usr/share/doc/vim-tiny/copyright: text under a) applies to those changes. -/usr/share/doc/vim-tiny/copyright: context diff. You can choose what license to use for new code you -/usr/share/doc/vim-tiny/copyright: context diff will do. The e-mail address to be used is -/usr/share/doc/vim-tiny/copyright: On Debian systems, the complete text of the GPL version 2 license can be -[...] - -``` - -The dgrep supports most of grep’s options. Refer the following guide to learn grep commands. - -#### 4 dglob - -The dglob utility generates a list of package names which match a pattern. For example, find the list of packages that matches the string “vim”. -``` -$ sudo dglob vim -vim-tiny:amd64 -vim:amd64 -vim-common:all -vim-runtime:all - -``` - -By default, dglob will display only the installed packages. If you want to list all packages (installed and not installed), use **-a** flag. -``` -$ sudo dglob vim -a - -``` - -#### 5. debget - -The **debget** utility will download a .deb for a package in APT’s database. Please note that it will only download the given package, not the dependencies. -``` -$ debget nano -Get:1 http://in.archive.ubuntu.com/ubuntu bionic/main amd64 nano amd64 2.9.3-2 [231 kB] -Fetched 231 kB in 2s (113 kB/s) - -``` - -#### 6. dpigs - -This is another useful utility in this collection. The **dpigs** utility will find and show you which installed packages occupy the most disk space. -``` -$ dpigs -260644 linux-firmware -167195 linux-modules-extra-4.15.0-20-generic -75186 linux-headers-4.15.0-20 -64217 linux-modules-4.15.0-20-generic -55620 snapd -31376 git -31070 libicu60 -28420 vim-runtime -25971 gcc-7 -24349 g++-7 - -``` - -As you can see, the linux-firmware packages occupies the most disk space. By default, it will display the **top 10** packages that occupies the most disk space. If you want to display more packages, for example 20, run the following command: -``` -$ dpigs -n 20 - -``` - -#### 7. debman - -The **debman** utility allows you to easily view man pages from a binary **.deb** without extracting it. You don’t even need to install the .deb package. The following command displays the man page of nano package. -``` -$ debman -f nano_2.9.3-2_amd64.deb nano - -``` - -If you don’t have a local copy of the .deb package, use **-p** flag to download and view package’s man page. -``` -$ debman -p nano nano - -``` - -**Suggested read:** - -#### 8. debmany - -An installed Debian package has not only a man page, but also includes other files such as acknowledgement, copy right, and read me etc. The **debmany** utility allows you to view and read those files. -``` -$ debmany vim - -``` - -![][1] - -Choose the file you want to view using arrow keys and hit ENTER to view the selected file. Press **q** to go back to the main menu. - -If the specified package is not installed, debmany will download it from the APT database and display the man pages. The **dialog** package should be installed to read the man pages. - -#### 9. popbugs - -If you’re a developer, the **popbugs** utility will be quite useful. It will display a customized release-critical bug list based on packages you use (using popularity-contest data). For those who don’t know, the popularity-contest package sets up a cron job that will periodically anonymously submit to the Debian developers statistics about the most used Debian packages on this system. This information helps Debian make decisions such as which packages should go on the first CD. It also lets Debian improve future versions of the distribution so that the most popular packages are the ones which are installed automatically for new users. - -To generate a list of critical bugs and display the result in your default web browser, run: -``` -$ popbugs - -``` - -Also, you can save the result in a file as shown below. -``` -$ popbugs --output=bugs.txt - -``` - -#### 10. which-pkg-broke - -This command will display all the dependencies of the given package and when each dependency was installed. By using this information, you can easily find which package might have broken another at what time after upgrading the system or a package. -``` -$ which-pkg-broke vim -Package has no install time info -debconf Wed Apr 25 08:08:40 2018 -gcc-8-base:amd64 Wed Apr 25 08:08:41 2018 -libacl1:amd64 Wed Apr 25 08:08:41 2018 -libattr1:amd64 Wed Apr 25 08:08:41 2018 -dpkg Wed Apr 25 08:08:41 2018 -libbz2-1.0:amd64 Wed Apr 25 08:08:41 2018 -libc6:amd64 Wed Apr 25 08:08:42 2018 -libgcc1:amd64 Wed Apr 25 08:08:42 2018 -liblzma5:amd64 Wed Apr 25 08:08:42 2018 -libdb5.3:amd64 Wed Apr 25 08:08:42 2018 -[...] - -``` - -#### 11. dhomepage - -The dhomepage utility will display the official website of the given package in your default web browser. For example, the following command will open Vim editor’s home page. -``` -$ dhomepage vim - -``` - -And, that’s all for now. Debian-goodies is a must-have tool in your arsenal. Even though, we don’t use all those utilities often, they are worth to learn and I am sure they will be really helpful at times. - -I hope this was useful. More good stuffs to come. Stay tuned! - -Cheers! - - - --------------------------------------------------------------------------------- - -via: https://www.ostechnix.com/debian-goodies-a-set-of-useful-utilities-for-debian-and-ubuntu-users/ - -作者:[SK][a] -选题:[lujun9972](https://github.com/lujun9972) -译者:[译者ID](https://github.com/译者ID) -校对:[校对者ID](https://github.com/校对者ID) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 - -[a]:https://www.ostechnix.com/author/sk/ -[1]:http://www.ostechnix.com/wp-content/uploads/2018/05/debmany.png diff --git a/sources/tech/20180524 How CERN Is Using Linux and Open Source.md b/sources/tech/20180524 How CERN Is Using Linux and Open Source.md deleted file mode 100644 index 958a255997..0000000000 --- a/sources/tech/20180524 How CERN Is Using Linux and Open Source.md +++ /dev/null @@ -1,67 +0,0 @@ -How CERN Is Using Linux and Open Source -============================================================ - -![CERN](https://www.linux.com/sites/lcom/files/styles/rendered_file/public/atlas-cern.jpg?itok=IRLUYCNQ "CERN") ->CERN relies on open source technology to handle huge amounts of data generated by the Large Hadron Collider. The ATLAS (shown here) is a general-purpose detector that probes for fundamental particles. (Image courtesy: CERN)[Used with permission][2] - -[CERN][3] - -[CERN][6] really needs no introduction. Among other things, the European Organization for Nuclear Research created the World Wide Web and the Large Hadron Collider (LHC), the world’s largest particle accelerator, which was used in discovery of the [Higgs boson][7].  Tim Bell, who is responsible for the organization’s  IT Operating Systems and Infrastructure group, says the goal of his team is “to provide the compute facility for 13,000 physicists around the world to analyze those collisions, understand what the universe is made of and how it works.” - -CERN is conducting hardcore science, especially with the LHC, which [generates massive amounts of data][8] when it’s operational. “CERN currently stores about 200 petabytes of data, with over 10 petabytes of data coming in each month when the accelerator is running. This certainly produces extreme challenges for the computing infrastructure, regarding storing this large amount of data, as well as the having the capability to process it in a reasonable timeframe. It puts pressure on the networking and storage technologies and the ability to deliver an efficient compute framework,” Bell said. - -### [tim-bell-cern.png][4] - -![Tim Bell](https://www.linux.com/sites/lcom/files/styles/floated_images/public/tim-bell-cern.png?itok=5eUOpip- "Tim Bell") -Tim Bell, CERN[Used with permission][1]Swapnil Bhartiya - -The scale at which LHC operates and the amount of data it generates pose some serious challenges. But CERN is not new to such problems. Founded in 1954, CERN has been around for about 60 years. “We've always been facing computing challenges that are difficult problems to solve, but we have been working with open source communities to solve them,” Bell said. “Even in the 90s, when we invented the World Wide Web, we were looking to share this with the rest of humanity in order to be able to benefit from the research done at CERN and open source was the right vehicle to do that.” - -### Using OpenStack and CentOS - -Today, CERN is a heavy user of OpenStack, and Bell is one of the Board Members of the OpenStack Foundation. But CERN predates OpenStack. For several years, they have been using various open source technologies to deliver services through Linux servers. - -“Over the past 10 years, we've found that rather than taking our problems ourselves, we find upstream open source communities with which we can work, who are facing similar challenges and then we contribute to those projects rather than inventing everything ourselves and then having to maintain it as well,” said Bell. - -A good example is Linux itself. CERN used to be a Red Hat Enterprise Linux customer. But, back in 2004, they worked with Fermilab to  build their own Linux distribution called [Scientific Linux][9]. Eventually they realized that, because they were not modifying the kernel, there was no point in spending time spinning up their own distribution; so they migrated to CentOS. Because CentOS is a fully open source and community driven project, CERN could collaborate with the project and contribute to how CentOS is built and distributed. - -CERN helps CentOS with infrastructure and they also organize CentOS DoJo at CERN where engineers can get together to improve the CentOS packaging. - -In addition to OpenStack and CentOS, CERN is a heavy user of other open source projects, including Puppet for configuration management, Grafana and  influxDB for monitoring, and is involved in many more. - -“We collaborate with around 170 labs around the world. So every time that we find an improvement in an open source project, other labs can easily take that and use it,” said Bell, “At the same time, we also learn from others. When large scale installations like eBay and Rackspace make changes to improve scalability of solutions, it benefits us and allows us to scale.” - -### Solving realistic problems - -Around 2012, CERN was looking at ways to scale computing for the LHC, but the challenge was people rather than technology. The number of staff that CERN employs is fixed. “We had to find ways in which we can scale the compute without requiring a large number of additional people in order to administer that,” Bell said. “OpenStack provided us with an automated API-driven, software-defined infrastructure.” OpenStack also allowed CERN to look at problems related to the delivery of services and then automate those, without having to scale the staff. - -“We're currently running about 280,000 cores and 7,000 servers across two data centers in Geneva and in Budapest. We are  using software-defined infrastructure to automate everything, which allows us to continue to add additional servers while remaining within the same envelope of staff,” said Bell. - -As time progresses, CERN will be dealing with even bigger challenges. Large Hadron Collider has a roadmap out to 2035, including a number of significant upgrades. “We run the accelerator for three to four years and then have a period of 18 months or two years when we upgrade the infrastructure. This maintenance period allows us to also do some computing planning,” said Bell. CERN is also  planning High Luminosity Large Hadron Collider upgrade, which will allow for beams with higher luminosity. The upgrade would mean about 60 times more compute requirement compared to what CERN has today. - -“With Moore's Law, we will maybe get one quarter of the way there, so we have to find ways under which we can be scaling the compute and the storage infrastructure correspondingly  and finding automation and solutions such as OpenStack will help that,” said Bell. - -“When we started off the large Hadron collider and looked at how we would deliver the computing, it was clear that we couldn't put everything into the data center at CERN, so we devised a distributed grid structure, with tier zero at CERN and then a cascading structure around that,” said Bell. “There are around 12 large tier one centers and then 150 small universities and labs around the world. They receive samples at the data from the LHC in order to assist the physicists to understand and analyze the data.” - -That structure means CERN is collaborating internationally, with hundreds of countries contributing toward the analysis of that data. It boils down to the fundamental principle that open source is not just about sharing code, it’s about collaboration among people to share knowledge and achieve what no single individual, organization, or company can achieve alone. That’s the Higgs boson of the open source world. - --------------------------------------------------------------------------------- - -via: https://www.linux.com/blog/2018/5/how-cern-using-linux-open-source - -作者:[SWAPNIL BHARTIYA ][a] -译者:[译者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/users/arnieswap -[1]:https://www.linux.com/licenses/category/used-permission -[2]:https://www.linux.com/licenses/category/used-permission -[3]:https://home.cern/about/experiments/atlas -[4]:https://www.linux.com/files/images/tim-bell-cernpng -[5]:https://www.linux.com/files/images/atlas-cernjpg -[6]:https://home.cern/ -[7]:https://home.cern/topics/higgs-boson -[8]:https://home.cern/about/computing -[9]:https://www.scientificlinux.org/ diff --git a/sources/tech/20180525 Getting started with the Python debugger.md b/sources/tech/20180525 Getting started with the Python debugger.md deleted file mode 100644 index 560440fd02..0000000000 --- a/sources/tech/20180525 Getting started with the Python debugger.md +++ /dev/null @@ -1,287 +0,0 @@ -Getting started with the Python debugger -====== - -![](https://fedoramagazine.org/wp-content/uploads/2018/05/pdb-816x345.jpg) - -The Python ecosystem is rich with many tools and libraries that improve developers’ lives. For example, the Magazine has previously covered how to [enhance your Python with a interactive shell][1]. This article focuses on another tool that saves you time and improves your Python skills: the Python debugger. - -### Python Debugger - -The Python standard library provides a debugger called pdb. This debugger provides most features needed for debugging such as breakpoints, single line stepping, inspection of stack frames, and so on. - -A basic knowledge of pdb is useful since it’s part of the standard library. You can use it in environments where you can’t install another enhanced debugger. - -#### Running pdb - -The easiest way to run pdb is from the command line, passing the program to debug as an argument. Considering the following script: -``` -# pdb_test.py -#!/usr/bin/python3 - -from time import sleep - -def countdown(number): - for i in range(number, 0, -1): - print(i) - sleep(1) - - -if __name__ == "__main__": - seconds = 10 - countdown(seconds) - -``` - -You can run pdb from the command line like this: -``` -$ python3 -m pdb pdb_test.py -> /tmp/pdb_test.py(1)() --> from time import sleep -(Pdb) - -``` - -Another way to use pdb is to set a breakpoint in the program. To do this, import the pdb module and use the set_trace function: -``` -1 # pdb_test.py -2 #!/usr/bin/python3 -3 -4 from time import sleep -5 -6 -7 def countdown(number): -8 for i in range(number, 0, -1): -9 import pdb; pdb.set_trace() -10 print(i) -11 sleep(1) -12 -13 -14 if __name__ == "__main__": -15 seconds = 10 -16 countdown(seconds) - -$ python3 pdb_test.py -> /tmp/pdb_test.py(6)countdown() --> print(i) -(Pdb) - -``` - -The script stops at the breakpoint, and pdb displays the next line in the script. You can also execute the debugger after a failure. This is known as postmortem debugging. - -#### Navigate the execution stack - -A common use case in debugging is to navigate the execution stack. Once the Python debugger is running, the following commands are useful : - -+ w(here) : Shows which line is currently executed and where the execution stack is. - - -``` -$ python3 test_pdb.py -> /tmp/test_pdb.py(10)countdown() --> print(i) -(Pdb) w -/tmp/test_pdb.py(16)() --> countdown(seconds) -> /tmp/test_pdb.py(10)countdown() --> print(i) -(Pdb) - -``` - -+ l(ist) : Shows more context (code) around the current the location. - - -``` -$ python3 test_pdb.py -> /tmp/test_pdb.py(10)countdown() --> print(i) -(Pdb) l -5 -6 -7 def countdown(number): -8 for i in range(number, 0, -1): -9 import pdb; pdb.set_trace() -10 -> print(i) -11 sleep(1) -12 -13 -14 if __name__ == "__main__": -15 seconds = 10 -(Pdb) - -``` - -+ u(p)/d(own) : Navigate the call stack up or down. - - -``` -$ py3 test_pdb.py -> /tmp/test_pdb.py(10)countdown() --> print(i) -(Pdb) up -> /tmp/test_pdb.py(16)() --> countdown(seconds) -(Pdb) down -> /tmp/test_pdb.py(10)countdown() --> print(i) -(Pdb) - -``` - -#### Stepping through a program - -pdb provides the following commands to execute and step through code: - -+ n(ext): Continue execution until the next line in the current function is reached, or it returns -+ s(tep): Execute the current line and stop at the first possible occasion (either in a function that is called or in the current function) -+ c(ontinue): Continue execution, only stopping at a breakpoint. - - -``` -$ py3 test_pdb.py -> /tmp/test_pdb.py(10)countdown() --> print(i) -(Pdb) n -10 -> /tmp/test_pdb.py(11)countdown() --> sleep(1) -(Pdb) n -> /tmp/test_pdb.py(8)countdown() --> for i in range(number, 0, -1): -(Pdb) n -> /tmp/test_pdb.py(9)countdown() --> import pdb; pdb.set_trace() -(Pdb) s ---Call-- -> /usr/lib64/python3.6/pdb.py(1584)set_trace() --> def set_trace(): -(Pdb) c -> /tmp/test_pdb.py(10)countdown() --> print(i) -(Pdb) c -9 -> /tmp/test_pdb.py(9)countdown() --> import pdb; pdb.set_trace() -(Pdb) - -``` - -The example shows the difference between next and step. Indeed, when using step the debugger stepped into the pdb module source code, whereas next would have just executed the set_trace function. - -#### Examine variables content - -Where pdb is really useful is examining the content of variables stored in the execution stack. For example, the a(rgs) command prints the variables of the current function, as shown below: -``` -py3 test_pdb.py -> /tmp/test_pdb.py(10)countdown() --> print(i) -(Pdb) where -/tmp/test_pdb.py(16)() --> countdown(seconds) -> /tmp/test_pdb.py(10)countdown() --> print(i) -(Pdb) args -number = 10 -(Pdb) - -``` - -pdb prints the value of the variable number, in this case 10. - -Another command that can be used to print variables value is p(rint). -``` -$ py3 test_pdb.py -> /tmp/test_pdb.py(10)countdown() --> print(i) -(Pdb) list -5 -6 -7 def countdown(number): -8 for i in range(number, 0, -1): -9 import pdb; pdb.set_trace() -10 -> print(i) -11 sleep(1) -12 -13 -14 if __name__ == "__main__": -15 seconds = 10 -(Pdb) print(seconds) -10 -(Pdb) p i -10 -(Pdb) p number - i -0 -(Pdb) - -``` - -As shown in the example’s last command, print can evaluate an expression before displaying the result. - -The [Python documentation][2] contains the reference and examples for each of the pdb commands. This is a useful read for someone starting with the Python debugger. - -### Enhanced debugger - -Some enhanced debuggers provide a better user experience. Most add useful extra features to pdb, such as syntax highlighting, better tracebacks, and introspection. Popular choices of enhanced debuggers include [IPython’s ipdb][3] and [pdb++][4]. - -These examples show you how to install these two debuggers in a virtual environment. These examples use a new virtual environment, but in the case of debugging an application, the application’s virtual environment should be used. - -#### Install IPython’s ipdb - -To install the IPython ipdb, use pip in the virtual environment: -``` -$ python3 -m venv .test_pdb -$ source .test_pdb/bin/activate -(test_pdb)$ pip install ipdb - -``` - -To call ipdb inside a script, you must use the following command. Note that the module is called ipdb instead of pdb: -``` -import ipdb; ipdb.set_trace() - -``` - -IPython’s ipdb is also available in Fedora packages, so you can install it using Fedora’s package manager dnf: -``` -$ sudo dnf install python3-ipdb - -``` - -#### Install pdb++ - -You can install pdb++ similarly: -``` -$ python3 -m venv .test_pdb -$ source .test_pdb/bin/activate -(test_pdb)$ pip install pdbp - -``` - -pdb++ overrides the pdb module, and therefore you can use the same syntax to add a breakpoint inside a program: -``` -import pdb; pdb.set_trace() - -``` - -### Conclusion - -Learning how to use the Python debugger saves you time when investigating problems with an application. It can also be useful to understand how a complex part of an application or some libraries work, and thereby improve your Python developer skills. - - --------------------------------------------------------------------------------- - -via: https://fedoramagazine.org/getting-started-python-debugger/ - -作者:[Clément Verna][a] -选题:[lujun9972](https://github.com/lujun9972) -译者:[译者ID](https://github.com/译者ID) -校对:[校对者ID](https://github.com/校对者ID) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 - -[a]:https://fedoramagazine.org -[1]:https://fedoramagazine.org/enhance-python-interactive-shell -[2]:https://docs.python.org/3/library/pdb.html -[3]:https://github.com/gotcha/ipdb -[4]:https://github.com/antocuni/pdb diff --git a/sources/tech/20180528 What is behavior-driven Python.md b/sources/tech/20180528 What is behavior-driven Python.md deleted file mode 100644 index 5931b0b5f7..0000000000 --- a/sources/tech/20180528 What is behavior-driven Python.md +++ /dev/null @@ -1,307 +0,0 @@ -What is behavior-driven Python? -====== -![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/checklist_hands_team_collaboration.png?itok=u82QepPk) -Have you heard about [behavior-driven development][1] (BDD) and wondered what all the buzz is about? Maybe you've caught team members talking in "gherkin" and felt left out of the conversation. Or perhaps you're a Pythonista looking for a better way to test your code. Whatever the circumstance, learning about BDD can help you and your team achieve better collaboration and test automation, and Python's `behave` framework is a great place to start. - -### What is BDD? - - * Submitting forms on a website - * Searching for desired results - * Saving a document - * Making REST API calls - * Running command-line interface commands - - - -In software, a behavior is how a feature operates within a well-defined scenario of inputs, actions, and outcomes. Products can exhibit countless behaviors, such as: - -Defining a product's features based on its behaviors makes it easier to describe them, develop them, and test them. This is the heart of BDD: making behaviors the focal point of software development. Behaviors are defined early in development using a [specification by example][2] language. One of the most common behavior spec languages is [Gherkin][3], the Given-When-Then scenario format from the [Cucumber][4] project. Behavior specs are basically plain-language descriptions of how a behavior works, with a little bit of formal structure for consistency and focus. Test frameworks can easily automate these behavior specs by "gluing" step texts to code implementations. - -Below is an example of a behavior spec written in Gherkin: -``` -Scenario: Basic DuckDuckGo Search - -  Given the DuckDuckGo home page is displayed - -  When the user searches for "panda" - -  Then results are shown for "panda" - -``` - -At a quick glance, the behavior is intuitive to understand. Except for a few keywords, the language is freeform. The scenario is concise yet meaningful. A real-world example illustrates the behavior. Steps declaratively indicate what should happen—without getting bogged down in the details of how. - -The [main benefits of BDD][5] are good collaboration and automation. Everyone can contribute to behavior development, not just programmers. Expected behaviors are defined and understood from the beginning of the process. Tests can be automated together with the features they cover. Each test covers a singular, unique behavior in order to avoid duplication. And, finally, existing steps can be reused by new behavior specs, creating a snowball effect. - -### Python's behave framework - -`behave` is one of the most popular BDD frameworks in Python. It is very similar to other Gherkin-based Cucumber frameworks despite not holding the official Cucumber designation. `behave` has two primary layers: - - 1. Behavior specs written in Gherkin `.feature` files - 2. Step definitions and hooks written in Python modules that implement Gherkin steps - - - -As shown in the example above, Gherkin scenarios use a three-part format: - - 1. Given some initial state - 2. When an action is taken - 3. Then verify the outcome - - - -Each step is "glued" by decorator to a Python function when `behave` runs tests. - -### Installation - -As a prerequisite, make sure you have Python and `pip` installed on your machine. I strongly recommend using Python 3. (I also recommend using [`pipenv`][6], but the following example commands use the more basic `pip`.) - -Only one package is required for `behave`: -``` -pip install behave - -``` - -Other packages may also be useful, such as: -``` -pip install requests    # for REST API calls - -pip install selenium    # for Web browser interactions - -``` - -The [behavior-driven-Python][7] project on GitHub contains the examples used in this article. - -### Gherkin features - -The Gherkin syntax that `behave` uses is practically compliant with the official Cucumber Gherkin standard. A `.feature` file has Feature sections, which in turn have Scenario sections with Given-When-Then steps. Below is an example: -``` -Feature: Cucumber Basket - -  As a gardener, - -  I want to carry many cucumbers in a basket, - -  So that I don’t drop them all. - -  - -  @cucumber-basket - -  Scenario: Add and remove cucumbers - -    Given the basket is empty - -    When "4" cucumbers are added to the basket - -    And "6" more cucumbers are added to the basket - -    But "3" cucumbers are removed from the basket - -    Then the basket contains "7" cucumbers - -``` - -There are a few important things to note here: - - * Both the Feature and Scenario sections have [short, descriptive titles][8]. - * The lines immediately following the Feature title are comments ignored by `behave`. It is a good practice to put the user story there. - * Scenarios and Features can have tags (notice the `@cucumber-basket` mark) for hooks and filtering (explained below). - * Steps follow a [strict Given-When-Then order][9]. - * Additional steps can be added for any type using `And` and `But`. - * Steps can be parametrized with inputs—notice the values in double quotes. - - - -Scenarios can also be written as templates with multiple input combinations by using a Scenario Outline: -``` -Feature: Cucumber Basket - - - -  @cucumber-basket - -  Scenario Outline: Add cucumbers - -    Given the basket has “” cucumbers - -    When "" cucumbers are added to the basket - -    Then the basket contains "" cucumbers - - - -    Examples: Cucumber Counts - -      | initial | more | total | - -      |    0    |   1  |   1   | - -      |    1    |   2  |   3   | - -      |    5    |   4  |   9   | - -``` - -Scenario Outlines always have an Examples table, in which the first row gives column titles and each subsequent row gives an input combo. The row values are substituted wherever a column title appears in a step surrounded by angle brackets. In the example above, the scenario will be run three times because there are three rows of input combos. Scenario Outlines are a great way to avoid duplicate scenarios. - -There are other elements of the Gherkin language, but these are the main mechanics. To learn more, read the Automation Panda articles [Gherkin by Example][10] and [Writing Good Gherkin][11]. - -### Python mechanics - -Every Gherkin step must be "glued" to a step definition, a Python function that provides the implementation. Each function has a step type decorator with the matching string. It also receives a shared context and any step parameters. Feature files must be placed in a directory named `features/`, while step definition modules must be placed in a directory named `features/steps/`. Any feature file can use step definitions from any module—they do not need to have the same names. Below is an example Python module with step definitions for the cucumber basket features. -``` -from behave import * - -from cucumbers.basket import CucumberBasket - - - -@given('the basket has "{initial:d}" cucumbers') - -def step_impl(context, initial): - -    context.basket = CucumberBasket(initial_count=initial) - - - -@when('"{some:d}" cucumbers are added to the basket') - -def step_impl(context, some): - -    context.basket.add(some) - - - -@then('the basket contains "{total:d}" cucumbers') - -def step_impl(context, total): - -    assert context.basket.count == total - -``` - -Three [step matchers][12] are available: `parse`, `cfparse`, and `re`. The default and simplest marcher is `parse`, which is shown in the example above. Notice how parametrized values are parsed and passed into the functions as input arguments. A common best practice is to put double quotes around parameters in steps. - -Each step definition function also receives a [context][13] variable that holds data specific to the current scenario being run, such as `feature`, `scenario`, and `tags` fields. Custom fields may be added, too, to share data between steps. Always use context to share data—never use global variables! - -`behave` also supports [hooks][14] to handle automation concerns outside of Gherkin steps. A hook is a function that will be run before or after a step, scenario, feature, or whole test suite. Hooks are reminiscent of [aspect-oriented programming][15]. They should be placed in a special `environment.py` file under the `features/` directory. Hook functions can check the current scenario's tags, as well, so logic can be selectively applied. The example below shows how to use hooks to set up and tear down a Selenium WebDriver instance for any scenario tagged as `@web`. -``` -from selenium import webdriver - - - -def before_scenario(context, scenario): - -    if 'web' in context.tags: - -        context.browser = webdriver.Firefox() - -        context.browser.implicitly_wait(10) - - - -def after_scenario(context, scenario): - -    if 'web' in context.tags: - -        context.browser.quit() - -``` - -Note: Setup and cleanup can also be done with [fixtures][16] in `behave`. - -To offer an idea of what a `behave` project should look like, here's the example project's directory structure: - -![](https://opensource.com/sites/default/files/uploads/behave_dir_layout.png) - -Any Python packages and custom modules can be used with `behave`. Use good design patterns to build a scalable test automation solution. Step definition code should be concise. - -### Running tests - -To run tests from the command line, change to the project's root directory and run the `behave` command. Use the `–help` option to see all available options. - -Below are a few common use cases: -``` -# run all tests - -behave - - - -# run the scenarios in a feature file - -behave features/web.feature - - - -# run all tests that have the @duckduckgo tag - -behave --tags @duckduckgo - - - -# run all tests that do not have the @unit tag - -behave --tags ~@unit - - - -# run all tests that have @basket and either @add or @remove - -behave --tags @basket --tags @add,@remove - -``` - -For convenience, options may be saved in [config][17] files. - -### Other options - -`behave` is not the only BDD test framework in Python. Other good frameworks include: - - * `pytest-bdd` , a plugin for `pytest``behave`, it uses Gherkin feature files and step definition modules, but it also leverages all the features and plugins of `pytest`. For example, it can run Gherkin scenarios in parallel using `pytest-xdist`. BDD and non-BDD tests can also be executed together with the same filters. `pytest-bdd` also offers a more flexible directory layout. - - * `radish` is a "Gherkin-plus" framework—it adds Scenario Loops and Preconditions to the standard Gherkin language, which makes it more friendly to programmers. It also offers rich command line options like `behave`. - - * `lettuce` is an older BDD framework very similar to `behave`, with minor differences in framework mechanics. However, GitHub shows little recent activity in the project (as of May 2018). - - - -Any of these frameworks would be good choices. - -Also, remember that Python test frameworks can be used for any black box testing, even for non-Python products! BDD frameworks are great for web and service testing because their tests are declarative, and Python is a [great language for test automation][18]. - -This article is based on the author's [PyCon Cleveland 2018][19] talk, [Behavior-Driven Python][20]. - --------------------------------------------------------------------------------- - -via: https://opensource.com/article/18/5/behavior-driven-python - -作者:[Andrew Knight][a] -选题:[lujun9972](https://github.com/lujun9972) -译者:[译者ID](https://github.com/译者ID) -校对:[校对者ID](https://github.com/校对者ID) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 - -[a]:https://opensource.com/users/andylpk247 -[1]:https://automationpanda.com/bdd/ -[2]:https://en.wikipedia.org/wiki/Specification_by_example -[3]:https://automationpanda.com/2017/01/26/bdd-101-the-gherkin-language/ -[4]:https://cucumber.io/ -[5]:https://automationpanda.com/2017/02/13/12-awesome-benefits-of-bdd/ -[6]:https://docs.pipenv.org/ -[7]:https://github.com/AndyLPK247/behavior-driven-python -[8]:https://automationpanda.com/2018/01/31/good-gherkin-scenario-titles/ -[9]:https://automationpanda.com/2018/02/03/are-gherkin-scenarios-with-multiple-when-then-pairs-okay/ -[10]:https://automationpanda.com/2017/01/27/bdd-101-gherkin-by-example/ -[11]:https://automationpanda.com/2017/01/30/bdd-101-writing-good-gherkin/ -[12]:http://behave.readthedocs.io/en/latest/api.html#step-parameters -[13]:http://behave.readthedocs.io/en/latest/api.html#detecting-that-user-code-overwrites-behave-context-attributes -[14]:http://behave.readthedocs.io/en/latest/api.html#environment-file-functions -[15]:https://en.wikipedia.org/wiki/Aspect-oriented_programming -[16]:http://behave.readthedocs.io/en/latest/api.html#fixtures -[17]:http://behave.readthedocs.io/en/latest/behave.html#configuration-files -[18]:https://automationpanda.com/2017/01/21/the-best-programming-language-for-test-automation/ -[19]:https://us.pycon.org/2018/ -[20]:https://us.pycon.org/2018/schedule/presentation/87/ diff --git a/sources/tech/20180531 How to Build an Amazon Echo with Raspberry Pi.md b/sources/tech/20180531 How to Build an Amazon Echo with Raspberry Pi.md index 0bf792f769..a5d4767706 100644 --- a/sources/tech/20180531 How to Build an Amazon Echo with Raspberry Pi.md +++ b/sources/tech/20180531 How to Build an Amazon Echo with Raspberry Pi.md @@ -1,5 +1,3 @@ -heart4lor translating - How to Build an Amazon Echo with Raspberry Pi ====== diff --git a/sources/tech/20180531 How to create shortcuts in vi.md b/sources/tech/20180531 How to create shortcuts in vi.md index 0e9772e402..ba856e745a 100644 --- a/sources/tech/20180531 How to create shortcuts in vi.md +++ b/sources/tech/20180531 How to create shortcuts in vi.md @@ -1,4 +1,4 @@ -How to create shortcuts in vi +【sd886393认领翻译中】How to create shortcuts in vi ====== ![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/documentation-type-keys-yearbook.png?itok=Q-ELM2rn) diff --git a/sources/tech/20180531 You don-t know Bash- An introduction to Bash arrays.md b/sources/tech/20180531 You don-t know Bash- An introduction to Bash arrays.md deleted file mode 100644 index 10a1ecf526..0000000000 --- a/sources/tech/20180531 You don-t know Bash- An introduction to Bash arrays.md +++ /dev/null @@ -1,268 +0,0 @@ -You don't know Bash: An introduction to Bash arrays -====== - -![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/programming-code-keyboard-laptop.png?itok=pGfEfu2S) - -Although software engineers regularly use the command line for many aspects of development, arrays are likely one of the more obscure features of the command line (although not as obscure as the regex operator `=~`). But obscurity and questionable syntax aside, [Bash][1] arrays can be very powerful. - -### Wait, but why? - -Writing about Bash is challenging because it's remarkably easy for an article to devolve into a manual that focuses on syntax oddities. Rest assured, however, the intent of this article is to avoid having you RTFM. - -#### A real (actually useful) example - -To that end, let's consider a real-world scenario and how Bash can help: You are leading a new effort at your company to evaluate and optimize the runtime of your internal data pipeline. As a first step, you want to do a parameter sweep to evaluate how well the pipeline makes use of threads. For the sake of simplicity, we'll treat the pipeline as a compiled C++ black box where the only parameter we can tweak is the number of threads reserved for data processing: `./pipeline --threads 4`. - -### The basics - -`--threads` parameter that we want to test: -``` -allThreads=(1 2 4 8 16 32 64 128) - -``` - -The first thing we'll do is define an array containing the values of theparameter that we want to test: - -In this example, all the elements are numbers, but it need not be the case—arrays in Bash can contain both numbers and strings, e.g., `myArray=(1 2 "three" 4 "five")` is a valid expression. And just as with any other Bash variable, make sure to leave no spaces around the equal sign. Otherwise, Bash will treat the variable name as a program to execute, and the `=` as its first parameter! - -Now that we've initialized the array, let's retrieve a few of its elements. You'll notice that simply doing `echo $allThreads` will output only the first element. - -To understand why that is, let's take a step back and revisit how we usually output variables in Bash. Consider the following scenario: -``` -type="article" - -echo "Found 42 $type" - -``` - -Say the variable `$type` is given to us as a singular noun and we want to add an `s` at the end of our sentence. We can't simply add an `s` to `$type` since that would turn it into a different variable, `$types`. And although we could utilize code contortions such as `echo "Found 42 "$type"s"`, the best way to solve this problem is to use curly braces: `echo "Found 42 ${type}s"`, which allows us to tell Bash where the name of a variable starts and ends (interestingly, this is the same syntax used in JavaScript/ES6 to inject variables and expressions in [template literals][2]). - -So as it turns out, although Bash variables don't generally require curly brackets, they are required for arrays. In turn, this allows us to specify the index to access, e.g., `echo ${allThreads[1]}` returns the second element of the array. Not including brackets, e.g.,`echo $allThreads[1]`, leads Bash to treat `[1]` as a string and output it as such. - -Yes, Bash arrays have odd syntax, but at least they are zero-indexed, unlike some other languages (I'm looking at you, `R`). - -### Looping through arrays - -Although in the examples above we used integer indices in our arrays, let's consider two occasions when that won't be the case: First, if we wanted the `$i`-th element of the array, where `$i` is a variable containing the index of interest, we can retrieve that element using: `echo ${allThreads[$i]}`. Second, to output all the elements of an array, we replace the numeric index with the `@` symbol (you can think of `@` as standing for `all`): `echo ${allThreads[@]}`. - -#### Looping through array elements - -With that in mind, let's loop through `$allThreads` and launch the pipeline for each value of `--threads`: -``` -for t in ${allThreads[@]}; do - -  ./pipeline --threads $t - -done - -``` - -#### Looping through array indices - -Next, let's consider a slightly different approach. Rather than looping over array elements, we can loop over array indices: -``` -for i in ${!allThreads[@]}; do - -  ./pipeline --threads ${allThreads[$i]} - -done - -``` - -Let's break that down: As we saw above, `${allThreads[@]}` represents all the elements in our array. Adding an exclamation mark to make it `${!allThreads[@]}` will return the list of all array indices (in our case 0 to 7). In other words, the `for` loop is looping through all indices `$i` and reading the `$i`-th element from `$allThreads` to set the value of the `--threads` parameter. - -This is much harsher on the eyes, so you may be wondering why I bother introducing it in the first place. That's because there are times where you need to know both the index and the value within a loop, e.g., if you want to ignore the first element of an array, using indices saves you from creating an additional variable that you then increment inside the loop. - -### Populating arrays - -So far, we've been able to launch the pipeline for each `--threads` of interest. Now, let's assume the output to our pipeline is the runtime in seconds. We would like to capture that output at each iteration and save it in another array so we can do various manipulations with it at the end. - -#### Some useful syntax - -But before diving into the code, we need to introduce some more syntax. First, we need to be able to retrieve the output of a Bash command. To do so, use the following syntax: `output=$( ./my_script.sh )`, which will store the output of our commands into the variable `$output`. - -The second bit of syntax we need is how to append the value we just retrieved to an array. The syntax to do that will look familiar: -``` -myArray+=( "newElement1" "newElement2" ) - -``` - -#### The parameter sweep - -Putting everything together, here is our script for launching our parameter sweep: -``` -allThreads=(1 2 4 8 16 32 64 128) - -allRuntimes=() - -for t in ${allThreads[@]}; do - -  runtime=$(./pipeline --threads $t) - -  allRuntimes+=( $runtime ) - -done - -``` - -And voilà! - -### What else you got? - -In this article, we covered the scenario of using arrays for parameter sweeps. But I promise there are more reasons to use Bash arrays—here are two more examples. - -#### Log alerting - -In this scenario, your app is divided into modules, each with its own log file. We can write a cron job script to email the right person when there are signs of trouble in certain modules:`` -``` -# List of logs and who should be notified of issues - -logPaths=("api.log" "auth.log" "jenkins.log" "data.log") - -logEmails=("jay@email" "emma@email" "jon@email" "sophia@email") - - - -# Look for signs of trouble in each log - -for i in ${!logPaths[@]}; - -do - -  log=${logPaths[$i]} - -  stakeholder=${logEmails[$i]} - -  numErrors=$( tail -n 100 "$log" | grep "ERROR" | wc -l ) - - - -  # Warn stakeholders if recently saw > 5 errors - -  if [[ "$numErrors" -gt 5 ]]; - -  then - -    emailRecipient="$stakeholder" - -    emailSubject="WARNING: ${log} showing unusual levels of errors" - -    emailBody="${numErrors} errors found in log ${log}" - -    echo "$emailBody" | mailx -s "$emailSubject" "$emailRecipient" - -  fi - -done - -``` - -#### API queries - -Say you want to generate some analytics about which users comment the most on your Medium posts. Since we don't have direct database access, SQL is out of the question, but we can use APIs! - -To avoid getting into a long discussion about API authentication and tokens, we'll instead use [JSONPlaceholder][3], a public-facing API testing service, as our endpoint. Once we query each post and retrieve the emails of everyone who commented, we can append those emails to our results array: -``` -endpoint="https://jsonplaceholder.typicode.com/comments" - -allEmails=() - - - -# Query first 10 posts - -for postId in {1..10}; - -do - -  # Make API call to fetch emails of this posts's commenters - -  response=$(curl "${endpoint}?postId=${postId}") - - - -  # Use jq to parse the JSON response into an array - -  allEmails+=( $( jq '.[].email' <<< "$response" ) ) - -done - -``` - -Note here that I'm using the [`jq` tool][4] to parse JSON from the command line. The syntax of `jq` is beyond the scope of this article, but I highly recommend you look into it. - -As you might imagine, there are countless other scenarios in which using Bash arrays can help, and I hope the examples outlined in this article have given you some food for thought. If you have other examples to share from your own work, please leave a comment below. - -### But wait, there's more! - -Since we covered quite a bit of array syntax in this article, here's a summary of what we covered, along with some more advanced tricks we did not cover: - -Syntax Result `arr=()` Create an empty array `arr=(1 2 3)` Initialize array `${arr[2]}` Retrieve third element `${arr[@]}` Retrieve all elements `${!arr[@]}` Retrieve array indices `${#arr[@]}` Calculate array size `arr[0]=3` Overwrite 1st element `arr+=(4)` Append value(s) `str=$(ls)` Save `ls` output as a string `arr=( $(ls) )` Save `ls` output as an array of files `${arr[@]:s:n}` Retrieve elements at indices `n` to `s+n` - -### One last thought - -As we've discovered, Bash arrays sure have strange syntax, but I hope this article convinced you that they are extremely powerful. Once you get the hang of the syntax, you'll find yourself using Bash arrays quite often. - -#### Bash or Python? - -Which begs the question: When should you use Bash arrays instead of other scripting languages such as Python? - -To me, it all boils down to dependencies—if you can solve the problem at hand using only calls to command-line tools, you might as well use Bash. But for times when your script is part of a larger Python project, you might as well use Python. - -For example, we could have turned to Python to implement the parameter sweep, but we would have ended up just writing a wrapper around Bash: -``` -import subprocess - - - -all_threads = [1, 2, 4, 8, 16, 32, 64, 128] - -all_runtimes = [] - - - -# Launch pipeline on each number of threads - -for t in all_threads: - -  cmd = './pipeline --threads {}'.format(t) - - - -  # Use the subprocess module to fetch the return output - -  p = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True) - -  output = p.communicate()[0] - -  all_runtimes.append(output) - -``` - -Since there's no getting around the command line in this example, using Bash directly is preferable. - -#### Time for a shameless plug - -If you enjoyed this article, there's more where that came from! [Register here to attend OSCON][5], where I'll be presenting the live-coding workshop [You Don't Know Bash][6] on July 17, 2018. No slides, no clickers—just you and me typing away at the command line, exploring the wondrous world of Bash. - -This article originally appeared on [Medium][7] and is republished with permission. - --------------------------------------------------------------------------------- - -via: https://opensource.com/article/18/5/you-dont-know-bash-intro-bash-arrays - -作者:[Robert Aboukhalil][a] -选题:[lujun9972](https://github.com/lujun9972) -译者:[译者ID](https://github.com/译者ID) -校对:[校对者ID](https://github.com/校对者ID) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 - -[a]:https://opensource.com/users/robertaboukhalil -[1]:https://opensource.com/article/17/7/bash-prompt-tips-and-tricks -[2]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals -[3]:https://github.com/typicode/jsonplaceholder -[4]:https://stedolan.github.io/jq/ -[5]:https://conferences.oreilly.com/oscon/oscon-or -[6]:https://conferences.oreilly.com/oscon/oscon-or/public/schedule/detail/67166 -[7]:https://medium.com/@robaboukhalil/the-weird-wondrous-world-of-bash-arrays-a86e5adf2c69 diff --git a/sources/tech/20180604 4 cool new projects to try in COPR for June 2018.md b/sources/tech/20180604 4 cool new projects to try in COPR for June 2018.md deleted file mode 100644 index 8f030028b7..0000000000 --- a/sources/tech/20180604 4 cool new projects to try in COPR for June 2018.md +++ /dev/null @@ -1,80 +0,0 @@ -4 cool new projects to try in COPR for June 2018 -====== -COPR is a [collection][1] of personal repositories for software that isn’t carried in Fedora. Some software doesn’t conform to standards that allow easy packaging. Or it may not meet other Fedora standards, despite being free and open source. COPR can offer these projects outside the Fedora set of packages. Software in COPR isn’t supported by Fedora infrastructure or signed by the project. However, it can be a neat way to try new or experimental software. - -Here’s a set of new and interesting projects in COPR. - -### Ghostwriter - -[Ghostwriter][2] is a text editor for [Markdown][3] format with a minimal interface. It provides a preview of the document in HTML and syntax highlighting for Markdown. It offers the option to highlight only the paragraph or sentence currently being written. In addition, Ghostwriter can export documents to several formats, including PDF and HTML. Finally, it has the so-called “Hemingway” mode, in which erasing is disabled, forcing the user to write now and edit later.![][4] - -#### Installation instructions - -The repo currently provides Ghostwriter for Fedora 26, 27, 28, and Rawhide, and EPEL 7. To install Ghostwriter, use these commands: -``` -sudo dnf copr enable scx/ghostwriter -sudo dnf install ghostwriter - -``` - -### Lector - -[Lector][5] is a simple ebook reader application. Lector supports most common ebook formats, such as EPUB, MOBI, and AZW, as well as comic book archives CBZ and CBR. It’s easy to setup — just specify the directory containing your ebooks. You can browse books in Lector’s library using either a table or book covers. Among Lector’s features are bookmarks, user-defined tags, and a built-in dictionary.![][6] - -#### Installation instructions - -The repo currently provides Lector for Fedora 26, 27, 28, and Rawhide. To install Lector, use these commands: -``` -sudo dnf copr enable bugzy/lector -sudo dnf install lector - -``` - -### Ranger - -Ranerger is a text-based file manager with Vim key bindings. It displays the directory structure in three columns. The left one shows the parent directory, the middle the contents of the current directory, and the right a preview of the selected file or directory. In the case of text files, Ranger shows actual contents of the file as a preview.![][7] - -#### Installation instructions - -The repo currently provides Ranger for Fedora 27, 28, and Rawhide. To install Ranger, use these commands: -``` -sudo dnf copr enable fszymanski/ranger -sudo dnf install ranger - -``` - -### PrestoPalette - -PrestoPeralette is a tool that helps create balanced color palettes. A nice feature of PrestoPalette is the ability to use lighting to affect both lightness and saturation of the palette. You can export created palettes either as PNG or JSON. -![][8] - -#### Installation instructions - -The repo currently provides PrestoPalette for Fedora 26, 27, 28, and Rawhide, and EPEL 7. To install PrestoPalette, use these commands: -``` -sudo dnf copr enable dagostinelli/prestopalette -sudo dnf install prestopalette - -``` - - --------------------------------------------------------------------------------- - -via: https://fedoramagazine.org/4-try-copr-june-2018/ - -作者:[Dominik Turecek][a] -选题:[lujun9972](https://github.com/lujun9972) -译者:[译者ID](https://github.com/译者ID) -校对:[校对者ID](https://github.com/校对者ID) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 - -[a]:https://fedoramagazine.org -[1]:https://copr.fedorainfracloud.org/ -[2]:http://wereturtle.github.io/ghostwriter/ -[3]:https://daringfireball.net/ -[4]:https://fedoramagazine.org/wp-content/uploads/2018/05/ghostwriter.png -[5]:https://github.com/BasioMeusPuga/Lector -[6]:https://fedoramagazine.org/wp-content/uploads/2018/05/lector.png -[7]:https://fedoramagazine.org/wp-content/uploads/2018/05/ranger.png -[8]:https://fedoramagazine.org/wp-content/uploads/2018/05/prestopalette.png diff --git a/sources/tech/20180604 BootISO - A Simple Bash Script To Securely Create A Bootable USB Device From ISO File.md b/sources/tech/20180604 BootISO - A Simple Bash Script To Securely Create A Bootable USB Device From ISO File.md new file mode 100644 index 0000000000..f716a164a5 --- /dev/null +++ b/sources/tech/20180604 BootISO - A Simple Bash Script To Securely Create A Bootable USB Device From ISO File.md @@ -0,0 +1,172 @@ +BootISO – A Simple Bash Script To Securely Create A Bootable USB Device From ISO File +====== +Most of us (including me) very often create a bootable USB device from ISO file for OS installation. + +There are many applications freely available in Linux for this purpose. Even we wrote few of the utility in the past. + +Every one uses different application and each application has their own features and functionality. + +In that few of applications are belongs to CLI and few of them associated with GUI. + +Today we are going to discuss about similar kind of utility called BootISO. It’s a simple bash script, which allow users to create a USB device from ISO file. + +Many of the Linux admin uses dd command to create bootable ISO, which is one of the native and famous method but the same time, it’s one of the very dangerous command. So, be careful, when you performing any action with dd command. + +**Suggested Read :** +**(#)** [Etcher – Easy way to Create a bootable USB drive & SD card from an ISO image][1] +**(#)** [Create a bootable USB drive from an ISO image using dd command on Linux][2] + +### What IS BootISO + +[BootIOS][3] is a simple bash script, which allow users to securely create a bootable USB device from one ISO file. It’s written in bash. + +It doesn’t offer any GUI but in the same time it has vast of options, which allow newbies to create a bootable USB device in Linux without any issues. Since it’s a intelligent tool that automatically choose if any USB device is connected on the system. + +It will print the list when the system has more than one USB device connected. When you choose manually another hard disk manually instead of USB, this will safely exit without writing anything on it. + +This script will also check for dependencies and prompt user for installation, it works with all package managers such as apt-get, yum, dnf, pacman and zypper. + +### BootISO Features + + * It checks whether the selected ISO has the correct mime-type or not. If no then it exit. + * BootISO will exit automatically, if you selected any other disks (local hard drive) except USB drives. + * BootISO allow users to select the desired USB drives when you have more than one. + * BootISO prompts the user for confirmation before erasing and paritioning USB device. + * BootISO will handle any failure from a command properly and exit. + * BootISO will call a cleanup routine on exit with trap. + + + +### How To Install BootISO In Linux + +There are few ways are available to install BootISO in Linux but i would advise users to install using the following method. +``` +$ curl -L https://git.io/bootiso -O +$ chmod +x bootiso +$ sudo mv bootiso /usr/local/bin/ + +``` + +Once BootISO installed, run the following command to list the available USB devices. +``` +$ bootiso -l + +Listing USB drives available in your system: +NAME HOTPLUG SIZE STATE TYPE +sdd 1 32G running disk + +``` + +If you have only one USB device, then simple run the following command to create a bootable USB device from ISO file. +``` +$ bootiso /path/to/iso file + +$ bootiso /opt/iso_images/archlinux-2018.05.01-x86_64.iso +Granting root privileges for bootiso. +Listing USB drives available in your system: +NAME HOTPLUG SIZE STATE TYPE +sdd 1 32G running disk +Autoselecting `sdd' (only USB device candidate) +The selected device `/dev/sdd' is connected through USB. +Created ISO mount point at `/tmp/iso.vXo' +`bootiso' is about to wipe out the content of device `/dev/sdd'. +Are you sure you want to proceed? (y/n)>y +Erasing contents of /dev/sdd... +Creating FAT32 partition on `/dev/sdd1'... +Created USB device mount point at `/tmp/usb.0j5' +Copying files from ISO to USB device with `rsync' +Synchronizing writes on device `/dev/sdd' +`bootiso' took 250 seconds to write ISO to USB device with `rsync' method. +ISO succesfully unmounted. +USB device succesfully unmounted. +USB device succesfully ejected. +You can safely remove it ! + +``` + +Mention your device name, when you have more than one USB device using `--device` option. +``` +$ bootiso -d /dev/sde /opt/iso_images/archlinux-2018.05.01-x86_64.iso + +``` + +By default bootios uses `rsync` command to perform all the action and if you want to use `dd` command instead of, use the following format. +``` +$ bootiso --dd -d /dev/sde /opt/iso_images/archlinux-2018.05.01-x86_64.iso + +``` + +If you want to skip `mime-type` check, include the following option with bootios utility. +``` +$ bootiso --no-mime-check -d /dev/sde /opt/iso_images/archlinux-2018.05.01-x86_64.iso + +``` + +Add the below option with bootios to skip user for confirmation before erasing and partitioning USB device. +``` +$ bootiso -y -d /dev/sde /opt/iso_images/archlinux-2018.05.01-x86_64.iso + +``` + +Enable autoselecting USB devices in conjunction with -y option. +``` +$ bootiso -y -a /opt/iso_images/archlinux-2018.05.01-x86_64.iso + +``` + +To know more all the available option for bootiso, run the following command. +``` +$ bootiso -h +Create a bootable USB from any ISO securely. +Usage: bootiso [...] + +Options + +-h, --help, help Display this help message and exit. +-v, --version Display version and exit. +-d, --device Select block file as USB device. + If is not connected through USB, `bootiso' will fail and exit. + Device block files are usually situated in /dev/sXX or /dev/hXX. + You will be prompted to select a device if you don't use this option. +-b, --bootloader Install a bootloader with syslinux (safe mode) for non-hybrid ISOs. Does not work with `--dd' option. +-y, --assume-yes `bootiso' won't prompt the user for confirmation before erasing and partitioning USB device. + Use at your own risks. +-a, --autoselect Enable autoselecting USB devices in conjunction with -y option. + Autoselect will automatically select a USB drive device if there is exactly one connected to the system. + Enabled by default when neither -d nor --no-usb-check options are given. +-J, --no-eject Do not eject device after unmounting. +-l, --list-usb-drives List available USB drives. +-M, --no-mime-check `bootiso' won't assert that selected ISO file has the right mime-type. +-s, --strict-mime-check Disallow loose application/octet-stream mime type in ISO file. +-- POSIX end of options. +--dd Use `dd' utility instead of mounting + `rsync'. + Does not allow bootloader installation with syslinux. +--no-usb-check `bootiso' won't assert that selected device is a USB (connected through USB bus). + Use at your own risks. + +Readme + + Bootiso v2.5.2. + Author: Jules Samuel Randolph + Bugs and new features: https://github.com/jsamr/bootiso/issues + If you like bootiso, please help the community by making it visible: + * star the project at https://github.com/jsamr/bootiso + * upvote those SE post: https://goo.gl/BNRmvm https://goo.gl/YDBvFe + +``` + +-------------------------------------------------------------------------------- + +via: https://www.2daygeek.com/bootiso-a-simple-bash-script-to-securely-create-a-bootable-usb-device-in-linux-from-iso-file/ + +作者:[Prakash Subramanian][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.2daygeek.com/author/prakash/ +[1]:https://www.2daygeek.com/etcher-easy-way-to-create-a-bootable-usb-drive-sd-card-from-an-iso-image-on-linux/ +[2]:https://www.2daygeek.com/create-a-bootable-usb-drive-from-an-iso-image-using-dd-command-on-linux/ +[3]:https://github.com/jsamr/bootiso diff --git a/sources/tech/20180606 6 Open Source AI Tools to Know.md b/sources/tech/20180606 6 Open Source AI Tools to Know.md deleted file mode 100644 index 3aacd9b7d7..0000000000 --- a/sources/tech/20180606 6 Open Source AI Tools to Know.md +++ /dev/null @@ -1,55 +0,0 @@ -6 Open Source AI Tools to Know -====== - -![](https://www.linux.com/sites/lcom/files/styles/rendered_file/public/artificial-intelligence-3382507_1920.jpg?itok=HarDnwVX) - -In open source, no matter how original your own idea seems, it is always wise to see if someone else has already executed the concept. For organizations and individuals interested in leveraging the growing power of artificial intelligence (AI), many of the best tools are not only free and open source, but, in many cases, have already been hardened and tested. - -At leading companies and non-profit organizations, AI is a huge priority, and many of these companies and organizations are open sourcing valuable tools. Here is a sampling of free, open source AI tools available to anyone. - -**Acumos.** [Acumos AI][1] is a platform and open source framework that makes it easy to build, share, and deploy AI apps. It standardizes the infrastructure stack and components required to run an out-of-the-box general AI environment. This frees data scientists and model trainers to focus on their core competencies rather than endlessly customizing, modeling, and training an AI implementation. - -Acumos is part of the[LF Deep Learning Foundation][2], an organization within The Linux Foundation that supports open source innovation in artificial intelligence, machine learning, and deep learning. The goal is to make these critical new technologies available to developers and data scientists, including those who may have limited experience with deep learning and AI. The LF Deep Learning Foundation just [recently approved a project lifecycle and contribution process][3] and is now accepting proposals for the contribution of projects. - -**Facebook’s Framework.** Facebook[has open sourced][4] its central machine learning system designed for artificial intelligence tasks at large scale, and a series of other AI technologies. The tools are part of a proven platform in use at the company. Facebook has also open sourced a framework for deep learning and AI [called Caffe2][5]. - -**Speaking of Caffe.** Yahoo also released its key AI software under an open source license. The[CaffeOnSpark tool][6] is based on deep learning, a branch of artificial intelligence particularly useful in helping machines recognize human speech or the contents of a photo or video. Similarly, IBM’s machine learning program known as [SystemML][7] is freely available to share and modify through the Apache Software Foundation. - -**Google’s Tools.** Google spent years developing its [TensorFlow][8] software framework to support its AI software and other predictive and analytics programs. TensorFlow is the engine behind several Google tools you may already use, including Google Photos and the speech recognition found in the Google app. - -Two [AIY kits][9] open sourced by Google let individuals easily get hands-on with artificial intelligence. Focused on computer vision and voice assistants, the two kits come as small self-assembly cardboard boxes with all the components needed for use. The kits are currently available at Target in the United States, and are based on the open source Raspberry Pi platform — more evidence of how much is happening at the intersection of open source and AI. - -**H2O.ai.** **** I[previously covered][10] H2O.ai, which has carved out a niche in the machine learning and artificial intelligence arena because its primary tools are free and open source. You can get the main H2O platform and Sparkling Water, which works with Apache Spark, simply by[downloading][11] them. These tools operate under the Apache 2.0 license, one of the most flexible open source licenses available, and you can even run them on clusters powered by Amazon Web Services (AWS) and others for just a few hundred dollars. - -**Microsoft Onboard.** “Our goal is to democratize AI to empower every person and every organization to achieve more,” Microsoft CEO Satya Nadella[has said][12]. With that in mind, Microsoft is continuing to iterate its[Microsoft Cognitive Toolkit][13]. It’s an open source software framework that competes with tools such as TensorFlow and Caffe. Cognitive Toolkit works with both Windows and Linux on 64-bit platforms. - -“Cognitive Toolkit enables enterprise-ready, production-grade AI by allowing users to create, train, and evaluate their own neural networks that can then scale efficiently across multiple GPUs and multiple machines on massive data sets,” reports the Cognitive Toolkit Team. - -Learn more about AI in this new ebook from The Linux Foundation. [Open Source AI: Projects, Insights, and Trends by Ibrahim Haddad][14] surveys 16 popular open source AI projects – looking in depth at their histories, codebases, and GitHub contributions. [Download the free ebook now.][14] - --------------------------------------------------------------------------------- - -via: https://www.linux.com/blog/2018/6/6-open-source-ai-tools-know - -作者:[Sam Dean][a] -选题:[lujun9972](https://github.com/lujun9972) -译者:[译者ID](https://github.com/译者ID) -校对:[校对者ID](https://github.com/校对者ID) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 - -[a]:https://www.linux.com/users/sam-dean -[1]:https://www.acumos.org/ -[2]:https://www.linuxfoundation.org/projects/deep-learning/ -[3]:https://www.linuxfoundation.org/blog/lf-deep-learning-foundation-announces-project-contribution-process/ -[4]:https://code.facebook.com/posts/1687861518126048/facebook-to-open-source-ai-hardware-design/ -[5]:https://venturebeat.com/2017/04/18/facebook-open-sources-caffe2-a-new-deep-learning-framework/ -[6]:http://yahoohadoop.tumblr.com/post/139916563586/caffeonspark-open-sourced-for-distributed-deep -[7]:https://systemml.apache.org/ -[8]:https://www.tensorflow.org/ -[9]:https://www.techradar.com/news/google-assistant-sweetens-raspberry-pi-with-ai-voice-control -[10]:https://www.linux.com/news/sparkling-water-bridging-open-source-machine-learning-and-apache-spark -[11]:http://www.h2o.ai/download -[12]:https://blogs.msdn.microsoft.com/uk_faculty_connection/2017/02/10/microsoft-cognitive-toolkit-cntk/ -[13]:https://www.microsoft.com/en-us/cognitive-toolkit/ -[14]:https://www.linuxfoundation.org/publications/open-source-ai-projects-insights-and-trends/ diff --git a/sources/tech/20180606 Getting started with Buildah.md b/sources/tech/20180606 Getting started with Buildah.md deleted file mode 100644 index 8d72b92fed..0000000000 --- a/sources/tech/20180606 Getting started with Buildah.md +++ /dev/null @@ -1,343 +0,0 @@ -pinewall translating - -Getting started with Buildah -====== -![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/blocks_building.png?itok=eMOT-ire) - -[Buildah][1] is a command-line tool for building [Open Container Initiative][2]-compatible (that means Docker- and Kubernetes-compatible, too) images quickly and easily. It can act as a drop-in replacement for the Docker daemon’s `docker build` command (i.e., building images with a traditional Dockerfile) but is flexible enough to allow you to build images with whatever tools you prefer to use. Buildah is easy to incorporate into scripts and build pipelines, and best of all, it doesn’t require a running container daemon to build its image. - -### A drop-in replacement for docker build - -You can get started with Buildah immediately, dropping it into place where images are currently built using a Dockerfile and `docker build`. Buildah’s `build-using-dockerfile`, or `bud` argument makes it behave just like `docker build` does, so it's easy to incorporate into existing scripts or build pipelines. - -As with [previous articles I’ve written about Buildah][3], I like to use the example of installing "GNU Hello" from source. Consider this Dockerfile: -``` -FROM fedora:28 - -LABEL maintainer Chris Collins - - - -RUN dnf install -y tar gzip gcc make \ - -        && dnf clean all - - - -ADD http://ftpmirror.gnu.org/hello/hello-2.10.tar.gz /tmp/hello-2.10.tar.gz - - - -RUN tar xvzf /tmp/hello-2.10.tar.gz -C /opt - - - -WORKDIR /opt/hello-2.10 - - - -RUN ./configure - -RUN make - -RUN make install - -RUN hello -v - -ENTRYPOINT "/usr/local/bin/hello" - -``` - -Buildah can create an image from this Dockerfile as easily as `buildah bud -t hello .`, replacing `docker build -t hello .`: -``` -[chris@krang] $ sudo buildah bud -t hello . - -STEP 1: FROM fedora:28 - -Getting image source signatures - -Copying blob sha256:e06fd16225608e5b92ebe226185edb7422c3f581755deadf1312c6b14041fe73 - - 81.48 MiB / 81.48 MiB [====================================================] 8s - -Copying config sha256:30190780b56e33521971b0213810005a69051d720b73154c6e473c1a07ebd609 - - 2.29 KiB / 2.29 KiB [======================================================] 0s - -Writing manifest to image destination - -Storing signatures - -STEP 2: LABEL maintainer Chris Collins - -STEP 3: RUN dnf install -y tar gzip gcc make    && dnf clean all - - - - - -``` - -Once the build is complete, you can see the new image with the `buildah images` command: -``` -[chris@krang] $ sudo buildah images - -IMAGE ID        IMAGE NAME                              CREATED AT              SIZE - -30190780b56e    docker.io/library/fedora:28             Mar 7, 2018 16:53       247 MB - -6d54bef73e63    docker.io/library/hello:latest    May 3, 2018 15:24     391.8 MB - -``` - -The new image, tagged `hello:latest`, can be pushed to a remote image registry or run using [CRI-O][4] or other Kubernetes CRI-compatible runtimes, or pushed to a remote registry. If you’re testing it as a replacement for Docker build, you will probably want to copy the image to the docker daemon’s local image storage so it can be run by Docker. This is easily accomplished with the `buildah push` command: -``` -[chris@krang] $ sudo buildah push hello:latest docker-daemon:hello:latest - -Getting image source signatures - -Copying blob sha256:72fcdba8cff9f105a61370d930d7f184702eeea634ac986da0105d8422a17028 - - 247.02 MiB / 247.02 MiB [==================================================] 2s - -Copying blob sha256:e567905cf805891b514af250400cc75db3cb47d61219750e0db047c5308bd916 - - 144.75 MiB / 144.75 MiB [==================================================] 1s - -Copying config sha256:6d54bef73e638f2e2dd8b7bf1c4dfa26e7ed1188f1113ee787893e23151ff3ff - - 1.59 KiB / 1.59 KiB [======================================================] 0s - -Writing manifest to image destination - -Storing signatures - - - -[chris@krang] $ sudo docker images | head -n2 - -REPOSITORY              TAG             IMAGE ID        CREATED                 SIZE - -docker.io/hello      latest       6d54bef73e63  2 minutes ago   398 MB - - - -[chris@krang] $ sudo docker run -t hello:latest - -Hello, world! - -``` - -### A few differences - -Unlike Docker build, Buildah doesn’t commit changes to a layer automatically for every instruction in the Dockerfile—it builds everything from top to bottom, every time. On the positive side, this means non-cached builds (for example, those you would do with automation or build pipelines) end up being somewhat faster than their Docker build counterparts, especially if there are a lot of instructions. This is great for getting new changes into production quickly from an automated deployment or continuous delivery standpoint. - -Practically speaking, however, the lack of caching may not be quite as useful for image development, where caching layers can save significant time when doing builds over and over again. This applies only to the `build-using-dockerfile` command, however. When using Buildah native commands, as we’ll see below, you can choose when to commit your changes to disk, allowing for more flexible development. - -### Buildah native commands - -Where Buildah _really_ shines is in its native commands, which you can use to interact with container builds. Rather than using `build-using-dockerfile/bud` for each build, Buildah has commands to actually interact with the temporary container created during the build process. (Docker uses temporary, or _intermediate_ containers, too, but you don’t really interact with them while the image is being built.) - -Using the "GNU Hello" example again, consider this image build using Buildah commands: -``` -#!/usr/bin/env bash - - - -set -o errexit - - - -# Create a container - -container=$(buildah from fedora:28) - - - -# Labels are part of the "buildah config" command - -buildah config --label maintainer="Chris Collins " $container - - - -# Grab the source code outside of the container - -curl -sSL http://ftpmirror.gnu.org/hello/hello-2.10.tar.gz -o hello-2.10.tar.gz - - - -buildah copy $container hello-2.10.tar.gz /tmp/hello-2.10.tar.gz - - - -buildah run $container dnf install -y tar gzip gcc make - -Buildah run $container dnf clean all - -buildah run $container tar xvzf /tmp/hello-2.10.tar.gz -C /opt - - - -# Workingdir is also a "buildah config" command - -buildah config --workingdir /opt/hello-2.10 $container - - - -buildah run $container ./configure - -buildah run $container make - -buildah run $container make install - -buildah run $container hello -v - - - -# Entrypoint, too, is a “buildah config” command - -buildah config --entrypoint /usr/local/bin/hello $container - - - -# Finally saves the running container to an image - -buildah commit --format docker $container hello:latest - -``` - -One thing that should be immediately obvious is the fact that this is a Bash script rather than a Dockerfile. Using Buildah’s native commands makes it easy to script, in whatever language or automation context you like to use. This could be a makefile, a Python script, or whatever tools you like to use. - -So what is going on here? The first Buildah command `container=$(buildah from fedora:28)`, creates a running container from the fedora:28 image, and stores the container name (the output of the command) as a variable for later use. All the rest of the Buildah commands use the `$container` variable to say what container to act upon. For the most part those commands are self-explanatory: `buildah copy` moves a file into the container, `buildah run` executes a command in the container. It is easy to match them to their Dockerfile equivalents. - -The final command, `buildah commit`, commits the container to an image on disk. When building images with Buildah commands rather than from a Dockerfile, you can use the `commit` command to decide when to save your changes. In the example above, all of the changes are committed at once, but intermediate commits could be included too, allowing you to choose cache points from which to start. (For example, it would be particularly useful to cache to disk after the `dnf install`, as that can take a long time, but is also reliably the same each time.) - -### Mountpoints, install directories, and chroots - -Another useful Buildah command opens the door to a lot of flexibility in building images. `buildah mount` mounts the root directory of a container to a mountpoint on your host. For example: -``` -[chris@krang] $ container=$(sudo buildah from fedora:28) - -[chris@krang] $ mountpoint=$(sudo buildah mount ${container}) - -[chris@krang] $ echo $mountpoint - -/var/lib/containers/storage/overlay2/463eda71ec74713d8cebbe41ee07da5f6df41c636f65139a7bd17b24a0e845e3/merged - -[chris@krang] $ cat ${mountpoint}/etc/redhat-release - -Fedora release 28 (Twenty Eight) - -[chris@krang] $ ls ${mountpoint} - -bin   dev  home  lib64          media  opt   root  sbin  sys  usr - -boot  etc  lib   lost+found  mnt        proc  run   srv   tmp  var - -``` - -This is great because now you can interact with the mountpoint to make changes to your container image. This allows you to use tools on your host to build and install software, rather than including those tools in the container image itself. For example, in the Bash script above, we needed to install the tar, Gzip, GCC, and make packages to compile "GNU Hello" inside the container. Using a mountpoint, we can build an image with the same software, but the downloaded tarball and tar, Gzip, etc., RPMs are all on the host machine rather than in the container and resulting image: -``` -#!/usr/bin/env bash - - - -set -o errexit - - - -# Create a container - -container=$(buildah from fedora:28) - -mountpoint=$(buildah mount $container) - - - -buildah config --label maintainer="Chris Collins " $container - - - -curl -sSL http://ftpmirror.gnu.org/hello/hello-2.10.tar.gz \ - -     -o /tmp/hello-2.10.tar.gz - -tar xvzf src/hello-2.10.tar.gz -C ${mountpoint}/opt - - - -pushd ${mountpoint}/opt/hello-2.10 - -./configure - -make - -make install DESTDIR=${mountpoint} - -popd - - - -chroot $mountpoint bash -c "/usr/local/bin/hello -v" - - - -buildah config --entrypoint "/usr/local/bin/hello" $container - -buildah commit --format docker $container hello - -buildah unmount $container - -``` - -Take note of a few things in the script above: - - 1. The `curl` command downloads the tarball to the host, not the image - - 2. The `tar` command (running from the host itself) extracts the source code from the tarball into `/opt` inside the container. - - 3. `Configure`, `make`, and `make install` are all running from a directory inside the mountpoint, mounted to the host rather than running inside the container itself. - - 4. The `chroot` command here is used to change root into the mountpoint itself and test that "hello" is working, similar to the `buildah run` command used in the previous example. - - - - -This script is shorter, it uses tools most Linux folks are already familiar with, and the resulting image is smaller (no tarball, no extra packages, etc). You could even use the package manager for the host system to install software into the container. For example, let’s say you wanted to install [NGINX][5] into the container with GNU Hello (for whatever reason): -``` -[chris@krang] $ mountpoint=$(sudo buildah mount ${container}) - -[chris@krang] $ sudo dnf install nginx --installroot $mountpoint - -[chris@krang] $ sudo chroot $mountpoint nginx -v - -nginx version: nginx/1.12.1 - -``` - -In the example above, DNF is used with the `--installroot` flag to install NGINX into the container, which can be verified with chroot. - -### Try it out! - -Buildah is a lightweight and flexible way to create container images without running a full Docker daemon on your host. In addition to offering out-of-the-box support for building from Dockerfiles, Buildah is easy to use with scripts or build tools of your choice and can help build container images using existing tools on the build host. The result is leaner images that use less bandwidth to ship around, require less storage space, and have a smaller surface area for potential attackers. Give it a try! - -**[See our related story,[Creating small containers with Buildah][6]]** - --------------------------------------------------------------------------------- - -via: https://opensource.com/article/18/6/getting-started-buildah - -作者:[Chris Collins][a] -选题:[lujun9972](https://github.com/lujun9972) -译者:[译者ID](https://github.com/译者ID) -校对:[校对者ID](https://github.com/校对者ID) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 - -[a]:https://opensource.com/users/clcollins -[1]:https://github.com/projectatomic/buildah -[2]:https://www.opencontainers.org/ -[3]:http://chris.collins.is/2017/08/17/buildah-a-new-way-to-build-container-images/ -[4]:http://cri-o.io/ -[5]:https://www.nginx.com/ -[6]:https://opensource.com/article/18/5/containers-buildah diff --git a/sources/tech/20180607 Find If A Package Is Available For Your Linux Distribution.md b/sources/tech/20180607 Find If A Package Is Available For Your Linux Distribution.md deleted file mode 100644 index b1bc538ff5..0000000000 --- a/sources/tech/20180607 Find If A Package Is Available For Your Linux Distribution.md +++ /dev/null @@ -1,152 +0,0 @@ -Find If A Package Is Available For Your Linux Distribution -====== - -![](https://www.ostechnix.com/wp-content/uploads/2018/06/Whohas-720x340.png) - -Some times, you might wonder how to find if a package is available for your Linux distribution. Or, you simply wanted to know what version of package is available for your distribution. If so, well, it’s your lucky day. I know a tool that can get you such information. Meet **“Whohas”** – a command line tool that allows querying several package lists at once. Currently, it supports Arch, Debian, Fedora, Gentoo, Mandriva, openSUSE, Slackware, Source Mage, Ubuntu, FreeBSD, NetBSD, OpenBSD, Fink, MacPorts and Cygwin. Using this little tool, the package maintainers can easily find ebuilds, pkgbuilds and similar package definitions from other distributions. Whohas is free, open source and written in Perl programming language. - -### Find If A Package Is Available For Your Linux Distribution - -**Installing Whohas** - -Whohas is available in the default repositories of Debian, Ubuntu, Linux Mint. If you’re using any one of the DEB-based system, you can install it using command: -``` -$ sudo apt-get install whohas - -``` - -For Arch-based systems, it is available in [**AUR**][1]. You can use any AUR helper programs to install it. - -Using [**Packer**][2]: -``` -$ packer -S whohas - -``` - -Using [**Trizen**][3]: -``` -$ trizen -S whohas - -``` - -Using [**Yay**][4]: -``` -$ yay -S whohas - -``` - -Using [**Yaourt**][5]: -``` -$ yaourt -S whohas - -``` - -In other Linux distributions, download Whohas utility source from [**here**][6] and manually compile and install it. - -**Usage** - -The main objective of Whohas tool is to let you know: - - * Which distribution provides packages on which the user depends. - * What version of a given package is in use in each distribution, or in each release of a distribution. - - - -Let us find which distributions contains a specific package, for example **vim**. To do so, run: -``` -$ whohas vim - -``` - -This command will show all distributions that contains the vim package with the available version of the given package, its size, repository and the download URL. - -![][8] - -You can even sort the results in alphabetical order by distribution using by piping the output to “sort” command like below. -``` -$ whohas vim | sort - -``` - -Please note that the above commands will display all packages that starts with name **vim** , for example vim-spell, vimcommander, vimpager etc. You can narrow down the search to the exact package by using grep command and space before or after or on both sides of your package like below. -``` -$ whohas vim | sort | grep " vim" - -$ whohas vim | sort | grep "vim " - -$ whohas vim | sort | grep " vim " - -``` - -The space before the package name will display all packages that ends with search term. The space after the package name will display all packages whose names begin with your search term. The space on both sides of the search will display the exact match. - -Alternatively, you could simply use “–strict” option like below. -``` -$ whohas --strict vim - -``` - -Sometimes, you want to know if a package is available for a specific distribution only. For example, to find if vim package is available in Arch Linux, run: -``` -$ whohas vim | grep "^Arch" - -``` - -The distribution names are abbreviated as “archlinux”, “cygwin”, “debian”, “fedora”, “fink”, “freebsd”, “gentoo”, “mandriva”, “macports”, “netbsd”, “openbsd”, “opensuse”, “slackware”, “sourcemage”, and “ubuntu”. - -You can also get the same results by using **-d** option like below. -``` -$ whohas -d archlinux vim - -``` - -This command will search vim packages for Arch Linux distribution only. - -To search for multiple distributions, for example arch linux, ubuntu, use the following command instead. -``` -$ whohas -d archlinux,ubuntu vim - -``` - -You can even find which distributions have “whohas” package. -``` -$ whohas whohas - -``` - -For more details, refer the man pages. -``` -$ man whohas - -``` - -**Also read:** - -All package managers can easily find the available package versions in the repositories.. However, Whohas can help you to get the comparison of available versions of packages across different distributions and which even has it available now. Give it a try, you won’t be disappointed. - -And, that’s all for now. Hope this was useful. More good stuffs to come. Stay tuned! - -Cheers! - - - --------------------------------------------------------------------------------- - -via: https://www.ostechnix.com/find-if-a-package-is-available-for-your-linux-distribution/ - -作者:[SK][a] -选题:[lujun9972](https://github.com/lujun9972) -译者:[译者ID](https://github.com/译者ID) -校对:[校对者ID](https://github.com/校对者ID) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 - -[a]:https://www.ostechnix.com/author/sk/ -[1]:https://aur.archlinux.org/packages/whohas/ -[2]:https://www.ostechnix.com/install-packer-arch-linux-2/ -[3]:https://www.ostechnix.com/trizen-lightweight-aur-package-manager-arch-based-systems/ -[4]:https://www.ostechnix.com/yay-found-yet-another-reliable-aur-helper/ -[5]:https://www.ostechnix.com/install-yaourt-arch-linux/ -[6]:http://www.philippwesche.org/200811/whohas/intro.html -[7]:data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7 -[8]:http://www.ostechnix.com/wp-content/uploads/2018/06/whohas-1.png diff --git a/sources/tech/20180607 GitLab-s Ultimate - Gold Plans Are Now Free For Open-Source Projects.md b/sources/tech/20180607 GitLab-s Ultimate - Gold Plans Are Now Free For Open-Source Projects.md deleted file mode 100644 index 1a7e3ca5e6..0000000000 --- a/sources/tech/20180607 GitLab-s Ultimate - Gold Plans Are Now Free For Open-Source Projects.md +++ /dev/null @@ -1,77 +0,0 @@ -GitLab’s Ultimate & Gold Plans Are Now Free For Open-Source Projects -====== -A lot has happened in the open-source community recently. First, [Microsoft acquired GitHub][1] and then people started to look for [GitHub alternatives][2] without even taking a second to think about it while Linus Torvalds released the [Linux Kernel 4.17][3]. Well, if you’ve been following us, I assume that you know all that. - -But, today, GitLab made a smart move by making some of its high-tier plans free for educational institutes and open-source projects. There couldn’t be a better time to offer something like this when a lot of developers are interested in migrating their open-source projects to GitLab. - -### GitLab’s premium plans are now free for open source projects and educational institutes - -![GitLab Logo][4] - -In a [blog post][5] today, GitLab announced that the **Ultimate** and Gold plans are now free for educational institutes and open-source projects. While we already know why GitLab made this move (a darn perfect timing!), they did explain their motive to make it free: - -> We make GitLab free for education because we want students to use our most advanced features. Many universities already run GitLab. If the students use the advanced features of GitLab Ultimate and Gold they will take their experiences with these advanced features to their workplaces. -> -> We would love to have more open source projects use GitLab. Public projects on GitLab.com already have all the features of GitLab Ultimate. And projects like [Gnome][6] and [Debian][7] already run their own server with the open source version of GitLab. With today’s announcement, open source projects that are comfortable running on proprietary software can use all the features GitLab has to offer while allowing us to have a sustainable business model by charging non-open-source organizations. - -### What are these ‘free’ plans offered by GitLab? - -![GitLab Pricing][8] - -GitLab has two categories of offerings. One is the software that you could host on your own cloud hosting service like [Digital Ocean][9]. The other is providing GitLab software as a service where the hosting is managed by GitLab itself and you get an account on GitLab.com. - -![GitLab Pricing for hosted service][10] - -Gold is the highest offering in the hosted category while Ultimate is the highest offering in the self-hosted category. - -You can get more details about their features on GitLab pricing page. Do note that the support is not included in this offer. You have to purchase it separately. - -### You have to match certain criteria to avail this offer - -GitLab also mentioned – to whom the offer will be valid for. Here’s what they wrote in their blog post: - -> 1. **Educational institutions:** any institution whose purposes directly relate to learning, teaching, and/or training by a qualified educational institution, faculty, or student. Educational purposes do not include commercial, professional, or any other for-profit purposes. -> -> 2. **Open source projects:** any project that uses a [standard open source license][11] and is non-commercial. It should not have paid support or paid contributors. -> -> - - -Although the free plan does not include support, you can still pay an additional fee of 4.95 USD per user per month – which is a very fair price, when you are in the dire need of an expert to help resolve an issue. - -GitLab also added a note for the students: - -> To reduce the administrative burden for GitLab, only educational institutions can apply on behalf of their students. If you’re a student and your educational institution does not apply, you can use public projects on GitLab.com with all functionality, use private projects with the free functionality, or pay yourself. - -### Wrapping Up - -Now that GitLab is stepping up its game, what do you think about it? - -Do you have a project hosted on [GitHub][12]? Will you be switching over? Or, luckily, you already happen to use GitLab from the start? - -Let us know your thoughts in the comments section below. - --------------------------------------------------------------------------------- - -via: https://itsfoss.com/gitlab-free-open-source/ - -作者:[Ankush Das][a] -选题:[lujun9972](https://github.com/lujun9972) -译者:[译者ID](https://github.com/译者ID) -校对:[校对者ID](https://github.com/校对者ID) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 - -[a]:https://itsfoss.com/author/ankush/ -[1]:https://itsfoss.com/microsoft-github/ -[2]:https://itsfoss.com/github-alternatives/ -[3]:https://itsfoss.com/linux-kernel-4-17/ -[4]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/06/GitLab-logo-800x450.png -[5]:https://about.gitlab.com/2018/06/05/gitlab-ultimate-and-gold-free-for-education-and-open-source/ -[6]:https://www.gnome.org/news/2018/05/gnome-moves-to-gitlab-2/ -[7]:https://salsa.debian.org/public -[8]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/06/gitlab-pricing.jpeg -[9]:https://m.do.co/c/d58840562553 -[10]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/06/gitlab-hosted-service-800x273.jpeg -[11]:https://itsfoss.com/open-source-licenses-explained/ -[12]:https://github.com/ diff --git a/sources/tech/20180607 Mesos and Kubernetes- It-s Not a Competition.md b/sources/tech/20180607 Mesos and Kubernetes- It-s Not a Competition.md deleted file mode 100644 index a168ac9f4a..0000000000 --- a/sources/tech/20180607 Mesos and Kubernetes- It-s Not a Competition.md +++ /dev/null @@ -1,66 +0,0 @@ -Mesos and Kubernetes: It's Not a Competition -====== - -![](https://www.linux.com/sites/lcom/files/styles/rendered_file/public/architecture-barge-bay-161764_0.jpg?itok=vNChG5fb) - -The roots of Mesos can be traced back to 2009 when Ben Hindman was a PhD student at the University of California, Berkeley working on parallel programming. They were doing massive parallel computations on 128-core chips, trying to solve multiple problems such as making software and libraries run more efficiently on those chips. He started talking with fellow students so see if they could borrow ideas from parallel processing and multiple threads and apply them to cluster management. - -“Initially, our focus was on Big Data,” said Hindman. Back then, Big Data was really hot and Hadoop was one of the hottest technologies. “We recognized that the way people were running things like Hadoop on clusters was similar to the way that people were running multiple threaded applications and parallel applications,” said Hindman. - -However, it was not very efficient, so they started thinking how it could be done better through cluster management and resource management. “We looked at many different technologies at that time,” Hindman recalled. - -Hindman and his colleagues, however, decided to adopt a novel approach. “We decided to create a lower level of abstraction for resource management, and run other services on top to that to do scheduling and other things,” said Hindman, “That’s essentially the essence of Mesos -- to separate out the resource management part from the scheduling part.” - -It worked, and Mesos has been going strong ever since. - -### The project goes to Apache - -The project was founded in 2009. In 2010 the team decided to donate the project to the Apache Software Foundation (ASF). It was incubated at Apache and in 2013, it became a Top-Level Project (TLP). - -There were many reasons why the Mesos community chose Apache Software Foundation, such as the permissiveness of Apache licensing, and the fact that they already had a vibrant community of other such projects. - -It was also about influence. A lot of people working on Mesos were also involved with Apache, and many people were working on projects like Hadoop. At the same time, many folks from the Mesos community were working on other Big Data projects like Spark. This cross-pollination led all three projects -- Hadoop, Mesos, and Spark -- to become ASF projects. - -It was also about commerce. Many companies were interested in Mesos, and the developers wanted it to be maintained by a neutral body instead of being a privately owned project. - -### Who is using Mesos? - -A better question would be, who isn’t? Everyone from Apple to Netflix is using Mesos. However, Mesos had its share of challenges that any technology faces in its early days. “Initially, I had to convince people that there was this new technology called ‘containers’ that could be interesting as there is no need to use virtual machines,” said Hindman. - -The industry has changed a great deal since then, and now every conversation around infrastructure starts with ‘containers’ -- thanks to the work done by Docker. Today convincing is not needed, but even in the early days of Mesos, companies like Apple, Netflix, and PayPal saw the potential. They knew they could take advantage of containerization technologies in lieu of virtual machines. “These companies understood the value of containers before it became a phenomenon,” said Hindman. - -These companies saw that they could have a bunch of containers, instead of virtual machines. All they needed was something to manage and run these containers, and they embraced Mesos. Some of the early users of Mesos included Apple, Netflix, PayPal, Yelp, OpenTable, and Groupon. - -“Most of these organizations are using Mesos for just running arbitrary services,” said Hindman, “But there are many that are using it for doing interesting things with data processing, streaming data, analytics workloads and applications.” - -One of the reasons these companies adopted Mesos was the clear separation between the resource management layers. Mesos offers the flexibility that companies need when dealing with containerization. - -“One of the things we tried to do with Mesos was to create a layering so that people could take advantage of our layer, but also build whatever they wanted to on top,” said Hindman. “I think that's worked really well for the big organizations like Netflix and Apple.” - -However, not every company is a tech company; not every company has or should have this expertise. To help those organizations, Hindman co-founded Mesosphere to offer services and solutions around Mesos. “We ultimately decided to build DC/OS for those organizations which didn’t have the technical expertise or didn't want to spend their time building something like that on top.” - -### Mesos vs. Kubernetes? - -People often think in terms of x versus y, but it’s not always a question of one technology versus another. Most technologies overlap in some areas, and they can also be complementary. “I don't tend to see all these things as competition. I think some of them actually can work in complementary ways with one another,” said Hindman. - -“In fact the name Mesos stands for ‘middle’; it’s kind of a middle OS,” said Hindman, “We have the notion of a container scheduler that can be run on top of something like Mesos. When Kubernetes first came out, we actually embraced it in the Mesos ecosystem and saw it as another way of running containers in DC/OS on top of Mesos.” - -Mesos also resurrected a project called [Marathon][1](a container orchestrator for Mesos and DC/OS), which they have made a first-class citizen in the Mesos ecosystem. However, Marathon does not really compare with Kubernetes. “Kubernetes does a lot more than what Marathon does, so you can’t swap them with each other,” said Hindman, “At the same time, we have done many things in Mesos that are not in Kubernetes. So, these technologies are complementary to each other.” - -Instead of viewing such technologies as adversarial, they should be seen as beneficial to the industry. It’s not duplication of technologies; it’s diversity. According to Hindman, “it could be confusing for the end user in the open source space because it's hard to know which technologies are suitable for what kind of workload, but that’s the nature of the beast called Open Source.” - -That just means there are more choices, and everybody wins. - --------------------------------------------------------------------------------- - -via: https://www.linux.com/blog/2018/6/mesos-and-kubernetes-its-not-competition - -作者:[Swapnil Bhartiya][a] -选题:[lujun9972](https://github.com/lujun9972) -译者:[译者ID](https://github.com/译者ID) -校对:[校对者ID](https://github.com/校对者ID) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 - -[a]:https://www.linux.com/users/arnieswap -[1]:https://mesosphere.github.io/marathon/ diff --git a/sources/tech/20180607 Using MQTT to send and receive data for your next project.md b/sources/tech/20180607 Using MQTT to send and receive data for your next project.md deleted file mode 100644 index 7005aee93f..0000000000 --- a/sources/tech/20180607 Using MQTT to send and receive data for your next project.md +++ /dev/null @@ -1,311 +0,0 @@ -pinewall translating - -Using MQTT to send and receive data for your next project -====== - -![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/toolbox-learn-draw-container-yearbook.png?itok=xDbwz1pP) - -Last November we bought an electric car, and it raised an interesting question: When should we charge it? I was concerned about having the lowest emissions for the electricity used to charge the car, so this is a specific question: What is the rate of CO2 emissions per kWh at any given time, and when during the day is it at its lowest? - -### Finding the data - -I live in New York State. About 80% of our electricity comes from in-state generation, mostly through natural gas, hydro dams (much of it from Niagara Falls), nuclear, and a bit of wind, solar, and other fossil fuels. The entire system is managed by the [New York Independent System Operator][1] (NYISO), a not-for-profit entity that was set up to balance the needs of power generators, consumers, and regulatory bodies to keep the lights on in New York. - -Although there is no official public API, as part of its mission, NYISO makes [a lot of open data][2] available for public consumption. This includes reporting on what fuels are being consumed to generate power, at five-minute intervals, throughout the state. These are published as CSV files on a public archive and updated throughout the day. If you know the number of megawatts coming from different kinds of fuels, you can make a reasonable approximation of how much CO2 is being emitted at any given time. - -We should always be kind when building tools to collect and process open data to avoid overloading those systems. Instead of sending everyone to their archive service to download the files all the time, we can do better. We can create a low-overhead event stream that people can subscribe to and get updates as they happen. We can do that with [MQTT][3]. The target for my project ([ny-power.org][4]) was inclusion in the [Home Assistant][5] project, an open source home automation platform that has hundreds of thousands of users. If all of these users were hitting this CSV server all the time, NYISO might need to restrict access to it. - -### What is MQTT? - -MQTT is a publish/subscribe (pubsub) wire protocol designed with small devices in mind. Pubsub systems work like a message bus. You send a message to a topic, and any software with a subscription for that topic gets a copy of your message. As a sender, you never really know who is listening; you just provide your information to a set of topics and listen for any other topics you might care about. It's like walking into a party and listening for interesting conversations to join. - -This can make for extremely efficient applications. Clients subscribe to a narrow selection of topics and only receive the information they are looking for. This saves both processing time and network bandwidth. - -As an open standard, MQTT has many open source implementations of both clients and servers. There are client libraries for every language you could imagine, even a library you can embed in Arduino for making sensor networks. There are many servers to choose from. My go-to is the [Mosquitto][6] server from Eclipse, as it's small, written in C, and can handle tens of thousands of subscribers without breaking a sweat. - -### Why I like MQTT - -Over the past two decades, we've come up with tried and true models for software applications to ask questions of services. Do I have more email? What is the current weather? Should I buy this thing now? This pattern of "ask/receive" works well much of the time; however, in a world awash with data, there are other patterns we need. The MQTT pubsub model is powerful where lots of data is published inbound to the system. Clients can subscribe to narrow slices of data and receive updates instantly when that data comes in. - -MQTT also has additional interesting features, such as "last-will-and-testament" messages, which make it possible to distinguish between silence because there is no relevant data and silence because your data collectors have crashed. MQTT also has retained messages, which provide the last message on a topic to clients when they first connect. This is extremely useful for topics that update slowly. - -In my work with the Home Assistant project, I've found this message bus model works extremely well for heterogeneous systems. If you dive into the Internet of Things space, you'll quickly run into MQTT everywhere. - -### Our first MQTT stream - -One of NYSO's CSV files is the real-time fuel mix. Every five minutes, it's updated with the fuel sources and power generated (in megawatts) during that time period. - -The CSV file looks something like this: - -| Time Stamp | Time Zone | Fuel Category | Gen MW | -| 05/09/2018 00:05:00 | EDT | Dual Fuel | 1400 | -| 05/09/2018 00:05:00 | EDT | Natural Gas | 2144 | -| 05/09/2018 00:05:00 | EDT | Nuclear | 4114 | -| 05/09/2018 00:05:00 | EDT | Other Fossil Fuels | 4 | -| 05/09/2018 00:05:00 | EDT | Other Renewables | 226 | -| 05/09/2018 00:05:00 | EDT | Wind | 1 | -| 05/09/2018 00:05:00 | EDT | Hydro | 3229 | -| 05/09/2018 00:10:00 | EDT | Dual Fuel | 1307 | -| 05/09/2018 00:10:00 | EDT | Natural Gas | 2092 | -| 05/09/2018 00:10:00 | EDT | Nuclear | 4115 | -| 05/09/2018 00:10:00 | EDT | Other Fossil Fuels | 4 | -| 05/09/2018 00:10:00 | EDT | Other Renewables | 224 | -| 05/09/2018 00:10:00 | EDT | Wind | 40 | -| 05/09/2018 00:10:00 | EDT | Hydro | 3166 | - -The only odd thing in the table is the dual-fuel category. Most natural gas plants in New York can also burn other fossil fuel to generate power. During cold snaps in the winter, the natural gas supply gets constrained, and its use for home heating is prioritized over power generation. This happens at a low enough frequency that we can consider dual fuel to be natural gas (for our calculations). - -The file is updated throughout the day. I created a simple data pump that polls for the file every minute and looks for updates. It publishes any new entries out to the MQTT server into a set of topics that largely mirror this CSV file. The payload is turned into a JSON object that is easy to parse from nearly any programming language. -``` -ny-power/upstream/fuel-mix/Hydro {"units": "MW", "value": 3229, "ts": "05/09/2018 00:05:00"} - -ny-power/upstream/fuel-mix/Dual Fuel {"units": "MW", "value": 1400, "ts": "05/09/2018 00:05:00"} - -ny-power/upstream/fuel-mix/Natural Gas {"units": "MW", "value": 2144, "ts": "05/09/2018 00:05:00"} - -ny-power/upstream/fuel-mix/Other Fossil Fuels {"units": "MW", "value": 4, "ts": "05/09/2018 00:05:00"} - -ny-power/upstream/fuel-mix/Wind {"units": "MW", "value": 41, "ts": "05/09/2018 00:05:00"} - -ny-power/upstream/fuel-mix/Other Renewables {"units": "MW", "value": 226, "ts": "05/09/2018 00:05:00"} - -ny-power/upstream/fuel-mix/Nuclear {"units": "MW", "value": 4114, "ts": "05/09/2018 00:05:00"} - -``` - -This direct reflection is a good first step in turning open data into open events. We'll be converting this into a CO2 intensity, but other applications might want these raw feeds to do other calculations with them. - -### MQTT topics - -Topics and topic structures are one of MQTT's major design points. Unlike more "enterprisey" message buses, in MQTT topics are not preregistered. A sender can create topics on the fly, the only limit being that they are less than 220 characters. The `/` character is special; it's used to create topic hierarchies. As we'll soon see, you can subscribe to slices of data in these hierarchies. - -Out of the box with Mosquitto, every client can publish to any topic. While it's great for prototyping, before going to production you'll want to add an access control list (ACL) to restrict writing to authorized applications. For example, my app's tree is accessible to everyone in read-only format, but only clients with specific credentials can publish to it. - -There is no automatic schema around topics nor a way to discover all the possible topics that clients will publish to. You'll have to encode that understanding directly into any application that consumes the MQTT bus. - -So how should you design your topics? The best practice is to start with an application-specific root name, in our case, `ny-power`. After that, build a hierarchy as deep as you need for efficient subscription. The `upstream` tree will contain data that comes directly from an upstream source without any processing. Our `fuel-mix` category is a specific type of data. We may add others later. - -### Subscribing to topics - -Subscriptions in MQTT are simple string matches. For processing efficiency, only two wildcards are allowed: - - * `#` matches everything recursively to the end - * `+` matches only until the next `/` character - - - -It's easiest to explain this with some examples: -``` -ny-power/#  - match everything published by the ny-power app - -ny-power/upstream/#  - match all raw data - -ny-power/upstream/fuel-mix/+  - match all fuel types - -ny-power/+/+/Hydro - match everything about Hydro power that's - -       nested 2 deep (even if it's not in the upstream tree) - -``` - -A wide subscription like `ny-power/#` is common for low-volume applications. Just get everything over the network and handle it in your own application. This works poorly for high-volume applications, as most of the network bandwidth will be wasted as you drop most of the messages on the floor. - -To stay performant at higher volumes, applications will do some clever topic slides like `ny-power/+/+/Hydro` to get exactly the cross-section of data they need. - -### Adding our next layer of data - -From this point forward, everything in the application will work off existing MQTT streams. The first additional layer of data is computing the power's CO2 intensity. - -Using the 2016 [U.S. Energy Information Administration][7] numbers for total emissions and total power by fuel type in New York, we can come up with an [average emissions rate][8] per megawatt hour of power. - -This is encapsulated in a dedicated microservice. This has a subscription on `ny-power/upstream/fuel-mix/+`, which matches all upstream fuel-mix entries from the data pump. It then performs the calculation and publishes out to a new topic tree: -``` -ny-power/computed/co2 {"units": "g / kWh", "value": 152.9486, "ts": "05/09/2018 00:05:00"} - -``` - -In turn, there is another process that subscribes to this topic tree and archives that data into an [InfluxDB][9] instance. It then publishes a 24-hour time series to `ny-power/archive/co2/24h`, which makes it easy to graph the recent changes. - -This layer model works well, as the logic for each of these programs can be distinct from each other. In a more complicated system, they may not even be in the same programming language. We don't care, because the interchange format is MQTT messages, with well-known topics and JSON payloads. - -### Consuming from the command line - -To get a feel for MQTT in action, it's useful to just attach it to a bus and see the messages flow. The `mosquitto_sub` program included in the `mosquitto-clients` package is a simple way to do that. - -After you've installed it, you need to provide a server hostname and the topic you'd like to listen to. The `-v` flag is important if you want to see the topics being posted to. Without that, you'll see only the payloads. -``` -mosquitto_sub -h mqtt.ny-power.org -t ny-power/# -v - -``` - -Whenever I'm writing or debugging an MQTT application, I always have a terminal with `mosquitto_sub` running. - -### Accessing MQTT directly from the web - -We now have an application providing an open event stream. We can connect to it with our microservices and, with some command-line tooling, it's on the internet for all to see. But the web is still king, so it's important to get it directly into a user's browser. - -The MQTT folks thought about this one. The protocol specification is designed to work over three transport protocols: [TCP][10], [UDP][11], and [WebSockets][12]. WebSockets are supported by all major browsers as a way to retain persistent connections for real-time applications. - -The Eclipse project has a JavaScript implementation of MQTT called [Paho][13], which can be included in your application. The pattern is to connect to the host, set up some subscriptions, and then react to messages as they are received. -``` -// ny-power web console application - -var client = new Paho.MQTT.Client(mqttHost, Number("80"), "client-" + Math.random()); - - - -// set callback handlers - -client.onMessageArrived = onMessageArrived; - - - -// connect the client - -client.reconnect = true; - -client.connect({onSuccess: onConnect}); - - - -// called when the client connects - -function onConnect() { - -    // Once a connection has been made, make a subscription and send a message. - -    console.log("onConnect"); - -    client.subscribe("ny-power/computed/co2"); - -    client.subscribe("ny-power/archive/co2/24h"); - -    client.subscribe("ny-power/upstream/fuel-mix/#"); - -} - - - -// called when a message arrives - -function onMessageArrived(message) { - -    console.log("onMessageArrived:"+message.destinationName + message.payloadString); - -    if (message.destinationName == "ny-power/computed/co2") { - -        var data = JSON.parse(message.payloadString); - -        $("#co2-per-kwh").html(Math.round(data.value)); - -        $("#co2-units").html(data.units); - -        $("#co2-updated").html(data.ts); - -    } - -    if (message.destinationName.startsWith("ny-power/upstream/fuel-mix")) { - -        fuel_mix_graph(message); - -    } - -    if (message.destinationName == "ny-power/archive/co2/24h") { - -        var data = JSON.parse(message.payloadString); - -        var plot = [ - -            { - -                x: data.ts, - -                y: data.values, - -                type: 'scatter' - -            } - -        ]; - -        var layout = { - -            yaxis: { - -                title: "g CO2 / kWh", - -            } - -        }; - -        Plotly.newPlot('co2_graph', plot, layout); - -    } - -``` - -This application subscribes to a number of topics because we're going to display a few different kinds of data. The `ny-power/computed/co2` topic provides us a topline number of current intensity. Whenever we receive that topic, we replace the related contents on the site. - - -![NY ISO Grid CO2 Intensity][15] - -NY ISO Grid CO2 Intensity graph from [ny-power.org][4]. - -The `ny-power/archive/co2/24h` topic provides a time series that can be loaded into a [Plotly][16] line graph. And `ny-power/upstream/fuel-mix` provides the data needed to provide a nice bar graph of the current fuel mix. - - -![Fuel mix on NYISO grid][18] - -Fuel mix on NYISO grid, [ny-power.org][4]. - -This is a dynamic website that is not polling the server. It is attached to the MQTT bus and listening on its open WebSocket. The webpage is a pub/sub client just like the data pump and the archiver. This one just happens to be executing in your browser instead of a microservice in the cloud. - -You can see the page in action at . That includes both the graphics and a real-time MQTT console to see the messages as they come in. - -### Diving deeper - -The entire ny-power.org application is [available as open source on GitHub][19]. You can also check out [this architecture overview][20] to see how it was built as a set of Kubernetes microservices deployed with [Helm][21]. You can see another interesting MQTT application example with [this code pattern][22] using MQTT and OpenWhisk to translate text messages in real time. - -MQTT is used extensively in the Internet of Things space, and many more examples of MQTT use can be found at the [Home Assistant][23] project. - -And if you want to dive deep into the protocol, [mqtt.org][3] has all the details for this open standard. - -To learn more, attend Sean Dague's talk, [Adding MQTT to your toolkit][24], at [OSCON][25], which will be held July 16-19 in Portland, Oregon. - --------------------------------------------------------------------------------- - -via: https://opensource.com/article/18/6/mqtt - -作者:[Sean Dague][a] -选题:[lujun9972](https://github.com/lujun9972) -译者:[译者ID](https://github.com/译者ID) -校对:[校对者ID](https://github.com/校对者ID) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 - -[a]:https://opensource.com/users/sdague -[1]:http://www.nyiso.com/public/index.jsp -[2]:http://www.nyiso.com/public/markets_operations/market_data/reports_info/index.jsp -[3]:http://mqtt.org/ -[4]:http://ny-power.org/# -[5]:https://www.home-assistant.io -[6]:https://mosquitto.org/ -[7]:https://www.eia.gov/ -[8]:https://github.com/IBM/ny-power/blob/master/src/nypower/calc.py#L1-L60 -[9]:https://www.influxdata.com/ -[10]:https://en.wikipedia.org/wiki/Transmission_Control_Protocol -[11]:https://en.wikipedia.org/wiki/User_Datagram_Protocol -[12]:https://en.wikipedia.org/wiki/WebSocket -[13]:https://www.eclipse.org/paho/ -[14]:/file/400041 -[15]:https://opensource.com/sites/default/files/uploads/mqtt_nyiso-co2intensity.png (NY ISO Grid CO2 Intensity) -[16]:https://plot.ly/ -[17]:/file/400046 -[18]:https://opensource.com/sites/default/files/uploads/mqtt_nyiso_fuel-mix.png (Fuel mix on NYISO grid) -[19]:https://github.com/IBM/ny-power -[20]:https://developer.ibm.com/code/patterns/use-mqtt-stream-real-time-data/ -[21]:https://helm.sh/ -[22]:https://developer.ibm.com/code/patterns/deploy-serverless-multilingual-conference-room/ -[23]:https://www.home-assistant.io/ -[24]:https://conferences.oreilly.com/oscon/oscon-or/public/schedule/speaker/77317 -[25]:https://conferences.oreilly.com/oscon/oscon-or diff --git a/sources/tech/20180612 Using Ledger for YNAB-like envelope budgeting.md b/sources/tech/20180612 Using Ledger for YNAB-like envelope budgeting.md new file mode 100644 index 0000000000..47fc4eaed9 --- /dev/null +++ b/sources/tech/20180612 Using Ledger for YNAB-like envelope budgeting.md @@ -0,0 +1,143 @@ +Using Ledger for YNAB-like envelope budgeting +====== +### Bye bye Elbank + +I have to start this post with this: I will not be actively maintaining [Elbank][1] anymore, simply because I switched back to [Ledger][2]. If someone wants to take over, please contact me! + +The main reason for switching is budgeting. While Elbank was a cool experiment, it is not an accounting software, and inherently lacks support for powerful budgeting. + +When I started working on Elbank as a replacement for Ledger, I was looking for a reporting tool within Emacs that would fetch bank transactions automatically, so I wouldn’t have to enter transactions by hand (this is a seriously tedious task, and I grew tired of doing it after roughly two years, and finally gave up). + +Since then, I learned about ledger-autosync and boobank, which I use to sync my bank statements with Ledger (more about that in another post). + +### YNAB’s way of budgeting + +I only came across [YNAB][3] recently. While I won’t use their software (being a non-free web application, and, you know… there’s no `M-x ynab`), I think that the principles behind it are really appealing for personal budgeting. I encourage you to [read more about it][4] (or grab a [copy of the book][5], it’s great), but here’s the idea. + + 1. **Budget every euro** : Quite simple once you get it. Every single Euro you have should be in a budget envelope. You should assign a job to every Euro you earn (that’s called [zero-based][6], [envelope system][7]). + + 2. **Embrace your true expenses** : Plan for larger and less frequent expenses, so when a yearly bill arrives, or your car breaks down, you’ll be covered. + + 3. **Roll with the punches** : Address overspending as it happens by taking money overspent from another envelope. As long as you keep budgeting, you’re succeeding. + + 4. **Age your money** : Spend less than you earn, so your money stays in the bank account longer. As you do that, the age of your money will grow, and once you reach the goal of spending money that is at least one month old, you won’t worry about that next bill. + + + + +### Implementation in Ledger + +I assume that you are familiar with Ledger, but if not I recommend reading its great [introduction][8] and [tutorial][9]. + +The implementation in Ledger uses plain double-entry accounting. I took most of it from [Sacha][10], with some minor differences. + +#### Budgeting new money + +After each income transaction, I budget the new money: +``` +2018-06-12 Employer + Assets:Bank:Checking 1600.00 EUR + Income:Salary -1600.00 EUR + +2018-06-12 Budget + [Assets:Budget:Food] 400.00 EUR + [Assets:Budget:Rent] 600.00 EUR + [Assets:Budget:Utilities] 600.00 EUR + [Equity:Budget] -1600.00 EUR + +``` + +Did you notice the square brackets around the accounts of the budget transaction? It’s a feature Ledger calls [virtual postings][11]. These postings are not considered real, and won’t be present in any report that uses the `--real` flag. This is exactly what we want, since it’s a budget allocation and not a “real” transaction. Therefore we’ll use the `--real` flag for all reports except for our budget report. + +#### Automatically crediting budget accounts when spending money + +Next, we need to credit the budget accounts each time we spend money. Ledger has another neat feature called [automated transactions][12] for this: +``` += /Expenses/ + [Assets:Budget:Unbudgeted] -1.0 + [Equity:Budget] 1.0 + += /Expenses:Food/ + [Assets:Budget:Food] -1.0 + [Assets:Budget:Unbudgeted] 1.0 + += /Expenses:Rent/ + [Assets:Budget:Rent] -1.0 + [Assets:Budget:Unbudgeted] 1.0 + += /Expenses:Utilities/ + [Assets:Budget:Utilities] -1.0 + [Assets:Budget:Unbudgeted] 1.0 + +``` + +Every expense is taken out of the `Assets:Budget:Unbudgeted` account by default. + +This forces me to budget properly, as `Assets:Budget:Unbudgeted` should always be 0 (if it is not the case I immediately know that there is something wrong going on). + +All other automatic transactions take money out of the `Assets:Budget:Unbudgeted` account instead of `Equity:Budget` account. + +#### A Budget report + +This is the final piece of the puzzle. Here’s the budget report command: +``` +ledger --empty -S -T -f ledger.dat bal ^assets:budget + +``` + +If we have the following transactions: +``` +2018/06/12 Groceries store + Expenses:Food 123.00 EUR + Assets:Bank:Checking + +2018/06/12 Landlord + Expenses:Rent 600.00 EUR + Assets:Bank:Checking + +2018/06/12 Internet provider + Expenses:Utilities:Internet 40.00 EUR + Assets:Bank:Checking + +``` + +Here’s what the report looks like: +``` + 837.00 EUR Assets:Budget + 560.00 EUR Utilities + 277.00 EUR Food + 0 Rent + 0 Unbudgeted +-------------------- + 837.00 EUR + +``` + +### Conclusion + +Ledger is amazingly powerful, and provides a great framework for YNAB-like budgeting. In a future post I’ll explain how I automatically import my bank transactions using a mix of `ledger-autosync` and `weboob`. + +-------------------------------------------------------------------------------- + +via: https://emacs.cafe/ledger/emacs/ynab/budgeting/2018/06/12/elbank-ynab.html + +作者:[Nicolas Petton][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://emacs.cafe/l +[1]:https://github.com/NicolasPetton/elbank +[2]:https://www.ledger-cli.org/ +[3]:https://ynab.com +[4]:https://www.youneedabudget.com/method/ +[5]:https://www.youneedabudget.com/book-order-now/ +[6]:https://en.wikipedia.org/wiki/Zero-based_budgeting +[7]:https://en.wikipedia.org/wiki/Envelope_system +[8]:https://www.ledger-cli.org/3.0/doc/ledger3.html#Introduction-to-Ledger +[9]:https://www.ledger-cli.org/3.0/doc/ledger3.html#Ledger-Tutorial +[10]:http://sachachua.com/blog/2014/11/keeping-financial-score-ledger/ +[11]:https://www.ledger-cli.org/3.0/doc/ledger3.html#Virtual-postings +[12]:https://www.ledger-cli.org/3.0/doc/ledger3.html#Automated-Transactions diff --git a/sources/tech/20180615 5 Commands for Checking Memory Usage in Linux.md b/sources/tech/20180615 5 Commands for Checking Memory Usage in Linux.md deleted file mode 100644 index 05c3da4f6c..0000000000 --- a/sources/tech/20180615 5 Commands for Checking Memory Usage in Linux.md +++ /dev/null @@ -1,195 +0,0 @@ -5 Commands for Checking Memory Usage in Linux -====== - -![](https://www.linux.com/sites/lcom/files/styles/rendered_file/public/top-main.jpg?itok=WYAw6yJ1) -The Linux operating system includes a plethora of tools, all of which are ready to help you administer your systems. From simple file and directory tools to very complex security commands, there’s not much you can’t do on Linux. And, although regular desktop users may not need to become familiar with these tools at the command line, they’re mandatory for Linux admins. Why? First, you will have to work with a GUI-less Linux server at some point. Second, command-line tools often offer far more power and flexibility than their GUI alternative. - -Determining memory usage is a skill you might need should a particular app go rogue and commandeer system memory. When that happens, it’s handy to know you have a variety of tools available to help you troubleshoot. Or, maybe you need to gather information about a Linux swap partition or detailed information about your installed RAM? There are commands for that as well. Let’s dig into the various Linux command-line tools to help you check into system memory usage. These tools aren’t terribly hard to use, and in this article, I’ll show you five different ways to approach the problem. - -I’ll be demonstrating on the [Ubuntu Server 18.04 platform][1]. You should, however, find all of these commands available on your distribution of choice. Even better, you shouldn’t need to install a single thing (as most of these tools are included). - -With that said, let’s get to work. - -### top - -I want to start out with the most obvious tool. The top command provides a dynamic, real-time view of a running system. Included in that system summary is the ability to check memory usage on a per-process basis. That’s very important, as you could easily have multiple iterations of the same command consuming different amounts of memory. Although you won’t find this on a headless server, say you’ve opened Chrome and noticed your system slowing down. Issue the top command to see that Chrome has numerous processes running (one per tab - Figure 1). - -![top][3] - -Figure 1: Multiple instances of Chrome appearing in the top command. - -[Used with permission][4] - -Chrome isn’t the only app to show multiple processes. You see the Firefox entry in Figure 1? That’s the primary process for Firefox, whereas the Web Content processes are the open tabs. At the top of the output, you’ll see the system statistics. On my machine (a [System76 Leopard Extreme][5]), I have a total of 16GB of RAM available, of which just over 10GB is in use. You can then comb through the list and see what percentage of memory each process is using. - -One of the things top is very good for is discovering Process ID (PID) numbers of services that might have gotten out of hand. With those PIDs, you can then set about to troubleshoot (or kill) the offending tasks. - -If you want to make top a bit more memory-friendly, issue the command top -o %MEM, which will cause top to sort all processes by memory used (Figure 2). - -![top][7] - -Figure 2: Sorting process by memory used in top. - -[Used with permission][4] - -The top command also gives you a real-time update on how much of your swap space is being used. - -### free - -Sometimes, however, top can be a bit much for your needs. You may only need to see the amount of free and used memory on your system. For that, there is the free command. The free command displays: - - * Total amount of free and used physical memory - - * Total amount of swap memory in the system - - * Buffers and caches used by the kernel - - - - -From your terminal window, issue the command free. The output of this command is not in real time. Instead, what you’ll get is an instant snapshot of the free and used memory in that moment (Figure 3). - -![free][9] - -Figure 3: The output of the free command is simple and clear. - -[Used with permission][4] - -You can, of course, make free a bit more user-friendly by adding the -m option, like so: free -m. This will report the memory usage in MB (Figure 4). - -![free][11] - -Figure 4: The output of the free command in a more human-readable form. - -[Used with permission][4] - -Of course, if your system is even remotely modern, you’ll want to use the -g option (gigabytes), as in free -g. - -If you need memory totals, you can add the t option like so: free -mt. This will simply total the amount of memory in columns (Figure 5). - -![total][13] - -Figure 5: Having free total your memory columns for you. - -[Used with permission][4] - -### vmstat - -Another very handy tool to have at your disposal is vmstat. This particular command is a one-trick pony that reports virtual memory statistics. The vmstat command will report stats on: - - * Processes - - * Memory - - * Paging - - * Block IO - - * Traps - - * Disks - - * CPU - - - - -The best way to issue vmstat is by using the -s switch, like vmstat -s. This will report your stats in a single column (which is so much easier to read than the default report). The vmstat command will give you more information than you need (Figure 6), but more is always better (in such cases). - -![vmstat][15] - -Figure 6: Using the vmstat command to check memory usage. - -[Used with permission][4] - -### dmidecode - -What if you want to find out detailed information about your installed system RAM? For that, you could use the dmidecode command. This particular tool is the DMI table decoder, which dumps a system’s DMI table contents into a human-readable format. If you’re unsure as to what the DMI table is, it’s a means to describe what a system is made of (as well as possible evolutions for a system). - -To run the dmidecode command, you do need sudo privileges. So issue the command sudo dmidecode -t 17. The output of the command (Figure 7) can be lengthy, as it displays information for all memory-type devices. So if you don’t have the ability to scroll, you might want to send the output of that command to a file, like so: sudo dmidecode -t 17 > dmi_infoI, or pipe it to the less command, as in sudo dmidecode | less. - -![dmidecode][17] - -Figure 7: The output of the dmidecode command. - -[Used with permission][4] - -### /proc/meminfo - -You might be asking yourself, “Where do these commands get this information from?”. In some cases, they get it from the /proc/meminfo file. Guess what? You can read that file directly with the command less /proc/meminfo. By using the less command, you can scroll up and down through that lengthy output to find exactly what you need (Figure 8). - -![/proc/meminfo][19] - -Figure 8: The output of the less /proc/meminfo command. - -[Used with permission][4] - -One thing you should know about /proc/meminfo: This is not a real file. Instead /pro/meminfo is a virtual file that contains real-time, dynamic information about the system. In particular, you’ll want to check the values for: - - * MemTotal - - * MemFree - - * MemAvailable - - * Buffers - - * Cached - - * SwapCached - - * SwapTotal - - * SwapFree - - - - -If you want to get fancy with /proc/meminfo you can use it in conjunction with the egrep command like so: egrep --color 'Mem|Cache|Swap' /proc/meminfo. This will produce an easy to read listing of all entries that contain Mem, Cache, and Swap ... with a splash of color (Figure 9). - -![/proc/meminfo][21] - -Figure 9: Making /proc/meminfo easier to read. - -[Used with permission][4] - -### Keep learning - -One of the first things you should do is read the manual pages for each of these commands (so man top, man free, man vmstat, man dmidecode). Starting with the man pages for commands is always a great way to learn so much more about how a tool works on Linux. - -Learn more about Linux through the free ["Introduction to Linux" ][22]course from The Linux Foundation and edX. - --------------------------------------------------------------------------------- - -via: https://www.linux.com/learn/5-commands-checking-memory-usage-linux - -作者:[Jack Wallen][a] -选题:[lujun9972](https://github.com/lujun9972) -译者:[译者ID](https://github.com/译者ID) -校对:[校对者ID](https://github.com/校对者ID) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 - -[a]:https://www.linux.com/users/jlwallen -[1]:https://www.ubuntu.com/download/server -[2]:/files/images/memory1jpg -[3]:https://www.linux.com/sites/lcom/files/styles/rendered_file/public/memory_1.jpg?itok=fhhhUL_l (top) -[4]:/licenses/category/used-permission -[5]:https://system76.com/desktops/leopard -[6]:/files/images/memory2jpg -[7]:https://www.linux.com/sites/lcom/files/styles/rendered_file/public/memory_2.jpg?itok=zuVkQfvv (top) -[8]:/files/images/memory3jpg -[9]:https://www.linux.com/sites/lcom/files/styles/rendered_file/public/memory_3.jpg?itok=rvuQp3t0 (free) -[10]:/files/images/memory4jpg -[11]:https://www.linux.com/sites/lcom/files/styles/rendered_file/public/memory_4.jpg?itok=K_luLLPt (free) -[12]:/files/images/memory5jpg -[13]:https://www.linux.com/sites/lcom/files/styles/rendered_file/public/memory_5.jpg?itok=q50atcsX (total) -[14]:/files/images/memory6jpg -[15]:https://www.linux.com/sites/lcom/files/styles/rendered_file/public/memory_6.jpg?itok=bwFnUVmy (vmstat) -[16]:/files/images/memory7jpg -[17]:https://www.linux.com/sites/lcom/files/styles/rendered_file/public/memory_7.jpg?itok=UNHIT_P6 (dmidecode) -[18]:/files/images/memory8jpg -[19]:https://www.linux.com/sites/lcom/files/styles/rendered_file/public/memory_8.jpg?itok=t87jvmJJ (/proc/meminfo) -[20]:/files/images/memory9jpg -[21]:https://www.linux.com/sites/lcom/files/styles/rendered_file/public/memory_9.jpg?itok=t-iSMEKq (/proc/meminfo) -[22]:https://training.linuxfoundation.org/linux-courses/system-administration-training/introduction-to-linux diff --git a/sources/tech/20180615 Complete Sed Command Guide [Explained with Practical Examples].md b/sources/tech/20180615 Complete Sed Command Guide [Explained with Practical Examples].md index a1d721ae3c..e548213483 100644 --- a/sources/tech/20180615 Complete Sed Command Guide [Explained with Practical Examples].md +++ b/sources/tech/20180615 Complete Sed Command Guide [Explained with Practical Examples].md @@ -1,4 +1,3 @@ -translating by amwps290 Complete Sed Command Guide [Explained with Practical Examples] ====== In a previous article, I showed the [basic usage of Sed][1], the stream editor, on a practical use case. Today, be prepared to gain more insight about Sed as we will take an in-depth tour of the sed execution model. This will be also an opportunity to make an exhaustive review of all Sed commands and to dive into their details and subtleties. So, if you are ready, launch a terminal, [download the test files][2] and sit comfortably before your keyboard: we will start our exploration right now! diff --git a/sources/tech/20180618 5 open source alternatives to Dropbox.md b/sources/tech/20180618 5 open source alternatives to Dropbox.md deleted file mode 100644 index d94b4537aa..0000000000 --- a/sources/tech/20180618 5 open source alternatives to Dropbox.md +++ /dev/null @@ -1,122 +0,0 @@ -5 open source alternatives to Dropbox -====== - -![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/dropbox.jpg?itok=qFwcqboT) - -Dropbox is the 800-pound gorilla of filesharing applications. Even though it's a massively popular tool, you may choose to use an alternative. - -Maybe that's because you're dedicated to the [open source way][1] for all the good reasons, including security and freedom, or possibly you've been spooked by data breaches. Or perhaps the pricing plan doesn't work out in your favor for the amount of storage you actually need. - -Fortunately, there are a variety of open source filesharing applications out there that give you more storage, security, and control over your data at a far lower price than Dropbox charges. How much lower? Try free, if you're a bit tech savvy and have a Linux server to use. - -Here are five of the best open source alternatives to Dropbox, plus a few others that you might want to consider. - -### ownCloud - -![](https://opensource.com/sites/default/files/uploads/owncloud.png) - -[ownCloud][2], launched in 2010, is the oldest application on this list, but don't let that fool you: It's still very popular (with over 1.5 million users, according to the company) and actively maintained by a community of 1,100 contributors, with updates released regularly. - -Its primary features—file and folding sharing, document collaboration—are similar to Dropbox's. Its primary difference (aside from its [open source license][3]) is that your files are hosted on your private Linux server or cloud, giving users complete control over your data. (Self-hosting is a common thread among the apps on this list.) - -With ownCloud, you can sync and access files through clients for Linux, MacOS, or Windows computers or mobile apps for Android and iOS devices, and provide password-protected links to others for collaboration or file upload/download. Data transfers are secured by end-to-end encryption (E2EE) and SSL encryption. You can also expand its functionality with a wide variety of third-party apps available in its [marketplace][4], and there is also a paid, commercially licensed enterprise edition. - -ownCloud offers comprehensive [documentation][5], including an installation guide and manuals for users, admins, and developers, and you can access its [source code][6] in its GitHub repository. - -### NextCloud - -![](https://opensource.com/sites/default/files/uploads/nextcloud.png) - -[NextCloud][7] spun out of ownCloud in 2016 and shares much of the same functionality. Nextcloud [touts][8] its high security and regulatory compliance as a distinguishing feature. It has HIPAA (healthcare) and GDPR (privacy) compliance features and offers extensive data-policy enforcement, encryption, user management, and auditing capabilities. It also encrypts data during transfer and at rest and integrates with mobile device management and authentication mechanisms (including LDAP/AD, single-sign-on, two-factor authentication, etc.). - -Like the other solutions on this list, NextCloud is self-hosted, but if you don't want to roll your own NextCloud server on Linux, the company partners with several [providers][9] for setup and hosting and sells servers, appliances, and support. A [marketplace][10] offers numerous apps to extend its features. - -NextCloud's [documentation][11] page offers thorough information for users, admins, and developers as well as links to its forums, IRC channel, and social media pages for community-based support. If you'd like to contribute, access its source code, report a bug, check out its (AGPLv3) license, or just learn more, visit the project's [GitHub repository][12]. - -### Seafile - -![](https://opensource.com/sites/default/files/uploads/seafile.png) - -[Seafile][13] may not have the bells and whistles (or app ecosystem) of ownCloud or Nextcloud, but it gets the job done. Essentially, it acts as a virtual drive on your Linux server to extend your desktop storage and allow you to share files selectively with password protection and various levels of permission (i.e., read-only or read/write). - -Its collaboration features include per-folder access control, password-protected download links, and Git-like version control and retention. Files are secured with two-factor authentication, file encryption, and AD/LDAP integration, and they're accessible from Windows, MacOS, Linux, iOS, or Android devices. - -For more information, visit Seafile's [GitHub repository][14], [server manual][15], [wiki][16], and [forums][17]. Note that Seafile's community edition is licensed under [GPLv2][18], but its professional edition is not open source. - -### OnionShare - -![](https://opensource.com/sites/default/files/uploads/onionshare.png) - -[OnionShare][19] is a cool app that does one thing: It allows you to share individual files or folders securely and, if you want, anonymously. There's no server to set up or maintain—all you need to do is [download and install][20] the app on MacOS, Windows, or Linux. Files are always hosted on your own computer; when you share a file, OnionShare creates a web server, makes it accessible as a Tor Onion service, and generates an unguessable .onion URL that allows the recipient to access the file via [Tor browser][21]. - -You can set limits on your fileshare, such as limiting the number of times it can be downloaded or using an auto-stop timer, which sets a strict expiration date/time after which the file is inaccessible (even if it hasn't been accessed yet). - -OnionShare is licensed under [GPLv3][22]; for more information, check out its GitHub [repository][22], which also includes [documentation][23] that covers the features in this easy-to-use filesharing application. - -### Pydio Cells - -![](https://opensource.com/sites/default/files/uploads/pydiochat.png) - -[Pydio Cells][24], which achieved stability in May 2018, is a complete overhaul of the Pydio filesharing application's core server code. Due to limitations with Pydio's PHP-based backend, the developers decided to rewrite the backend in the Go server language with a microservices architecture. (The frontend is still based on PHP.) - -Pydio Cells includes the usual filesharing and version control features, as well as in-app messaging, mobile apps (Android and iOS), and a social network-style approach to collaboration. Security includes OpenID Connect-based authentication, encryption at rest, security policies, and more. Advanced features are included in the enterprise distribution, but there's plenty of power for most small and midsize businesses and home users in the community (or "Home") version. - -You can [download][25] Pydio Cells for Linux and MacOS. For more information, check out the [documentation FAQ][26], [source code][27] repository, and [AGPLv3 license][28]. - -### Others to consider - -If these choices don't meet your needs, you may want to consider these open source filesharing-type applications. - - * If your main goal is to sync files between devices, rather than to share files, check out [Syncthing][29]). - * If you're a Git fan and don't need a mobile app, you might appreciate [SparkleShare][30]. - * If you primarily want a place to aggregate all your personal data, take a look at [Cozy][31]. - * And, if you're looking for a lightweight or dedicated filesharing tool, peruse [Scott Nesbitt's review][32] of some lesser-known options. - - - -What is your favorite open source filesharing application? Let us know in the comments. - --------------------------------------------------------------------------------- - -via: https://opensource.com/alternatives/dropbox - -作者:[OPensource.com][a] -选题:[lujun9972](https://github.com/lujun9972) -译者:[译者ID](https://github.com/译者ID) -校对:[校对者ID](https://github.com/校对者ID) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 - -[a]:https://opensource.com -[1]:https://opensource.com/open-source-way -[2]:https://owncloud.org/ -[3]:https://www.gnu.org/licenses/agpl-3.0.html -[4]:https://marketplace.owncloud.com/ -[5]:https://doc.owncloud.com/ -[6]:https://github.com/owncloud -[7]:https://nextcloud.com/ -[8]:https://nextcloud.com/secure/ -[9]:https://nextcloud.com/providers/ -[10]:https://apps.nextcloud.com/ -[11]:https://nextcloud.com/support/ -[12]:https://github.com/nextcloud -[13]:https://www.seafile.com/en/home/ -[14]:https://github.com/haiwen/seafile -[15]:https://manual.seafile.com/ -[16]:https://seacloud.cc/group/3/wiki/ -[17]:https://forum.seafile.com/ -[18]:https://github.com/haiwen/seafile/blob/master/LICENSE.txt -[19]:https://onionshare.org/ -[20]:https://onionshare.org/#downloads -[21]:https://www.torproject.org/ -[22]:https://github.com/micahflee/onionshare/blob/develop/LICENSE -[23]:https://github.com/micahflee/onionshare/wiki -[24]:https://pydio.com/en -[25]:https://pydio.com/download/ -[26]:https://pydio.com/en/docs/faq -[27]:https://github.com/pydio/cells -[28]:https://github.com/pydio/pydio-core/blob/develop/LICENSE -[29]:https://syncthing.net/ -[30]:http://www.sparkleshare.org/ -[31]:https://cozy.io/en/ -[32]:https://opensource.com/article/17/3/file-sharing-tools diff --git a/sources/tech/20180618 What-s all the C Plus Fuss- Bjarne Stroustrup warns of dangerous future plans for his C.md b/sources/tech/20180618 What-s all the C Plus Fuss- Bjarne Stroustrup warns of dangerous future plans for his C.md deleted file mode 100644 index 04644aebb2..0000000000 --- a/sources/tech/20180618 What-s all the C Plus Fuss- Bjarne Stroustrup warns of dangerous future plans for his C.md +++ /dev/null @@ -1,154 +0,0 @@ -What's all the C Plus Fuss? Bjarne Stroustrup warns of dangerous future plans for his C++ -====== - -![](https://regmedia.co.uk/2018/06/15/shutterstock_38621860.jpg?x=442&y=293&crop=1) - -**Interview** Earlier this year, Bjarne Stroustrup, creator of C++, managing director in the technology division of Morgan Stanley, and a visiting professor of computer science at Columbia University in the US, wrote [a letter][1] inviting those overseeing the evolution of the programming language to “Remember the Vasa!” - -Easy for a Dane to understand no doubt, but perhaps more of a stretch for those with a few gaps in their knowledge of 17th century Scandinavian history. The Vasa was a Swedish warship, commissioned by King Gustavus Adolphus. It was the most powerful warship in the Baltic Sea from its maiden voyage on the August 10, 1628, until a few minutes later when it sank. - -The formidable Vasa suffered from a design flaw: it was top-heavy, so much so that it was [undone by a gust of wind][2]. By invoking the memory of the capsized ship, Stroustrup served up a cautionary tale about the risks facing C++ as more and more features get added to the language. - -Quite a few such features have been suggested. Stroustrup cited 43 proposals in his letter. He contends those participating in the evolution of the ISO standard language, a group known as [WG21][3], are working to advance the language but not together. - -In his letter, he wrote: - ->Individually, many proposals make sense. Together they are insanity to the point of endangering the future of C++. - -He makes clear that he doesn’t interpret the fate of the Vasa to mean that incremental improvements spell doom. Rather, he takes it as a lesson to build a solid foundation, to learn from experience and to test thoroughly. - -With the recent conclusion of the C++ Standardization Committee Meeting in Rapperswil, Switzerland, earlier this month, Stroustrup addressed a few questions put to him by _The Register_ about what's next for the language. (The most recent version is C++17, which arrived last year; the next version C++20 is under development and expected in 2020.) - -**_Register:_ In your note, Remember the Vasa!, you wrote:** - ->The foundation begun in C++11 is not yet complete, and C++17 did little to make our foundation more solid, regular, and complete. Instead, it added significant surface complexity and increased the number of features people need to learn. C++ could crumble under the weight of these – mostly not quite fully-baked – proposals. We should not spend most our time creating increasingly complicated facilities for experts, such as ourselves. - -**Is C++ too challenging for newcomers, and if so, what features do you believe would make the language more accessible?** - -_**Stroustrup:**_ Some parts of C++ are too challenging for newcomers. - -On the other hand, there are parts of C++ that makes it far more accessible to newcomers than C or 1990s C++. The difficulty is to get the larger community to focus on those parts and help beginners and casual C++ users to avoid the parts that are there to support implementers of advanced libraries. - -I recommend the [C++ Core Guidelines][4] as an aide for that. - -Also, my “A Tour of C++” can help people get on the right track with modern C++ without getting lost in 1990s complexities or ensnarled by modern facilities meant for expert use. The second edition of “A Tour of C++” covering C++17 and parts of C++20 is on its way to the stores. - -I and others have taught C++ to 1st year university students with no previous programming experience in 3 months. It can be done as long as you don’t try to dig into every obscure corner of the language and focus on modern C++. - -“Making simple things simple” is a long-term goal of mine. Consider the C++11 range-for loop: -``` -for (int& x : v) ++x; // increment each element of the container v - -``` - -where v can be just about any container. In C and C-style C++, that might look like this: -``` -for (int i=0; i``.` This overwrites any local changes you haven't committed. In effect, it resets (clears out) the staging area and overwrites content in the working directory with the content from the commit you reset to. Before you use the `hard` option, be sure that's what you really want to do, since the command overwrites any uncommitted changes. - -### Revert - -The net effect of the `git revert` command is similar to reset, but its approach is different. Where the `reset` command moves the branch pointer back in the chain (typically) to "undo" changes, the `revert` command adds a new commit at the end of the chain to "cancel" changes. The effect is most easily seen by looking at Figure 1 again. If we add a line to a file in each commit in the chain, one way to get back to the version with only two lines is to reset to that commit, i.e., `git reset HEAD~1`. - -Another way to end up with the two-line version is to add a new commit that has the third line removed—effectively canceling out that change. This can be done with a `git revert` command, such as: -``` -$ git revert HEAD - -``` - -Because this adds a new commit, Git will prompt for the commit message: -``` -Revert "File with three lines" - -This reverts commit b764644bad524b804577684bf74e7bca3117f554. - -# Please enter the commit message for your changes. Lines starting -# with '#' will be ignored, and an empty message aborts the commit. -# On branch master -# Changes to be committed: -#       modified:   file1.txt -# -``` - -Figure 3 (below) shows the result after the `revert` operation is completed. - -If we do a `git log` now, we'll see a new commit that reflects the contents before the previous commit. -``` -$ git log --oneline -11b7712 Revert "File with three lines" -b764644 File with three lines -7c709f0 File with two lines -9ef9173 File with one line -``` - -Here are the current contents of the file in the working directory: -``` -$ cat -Line 1 -Line 2 -``` - -#### Revert or reset? - -Why would you choose to do a `revert` over a `reset` operation? If you have already pushed your chain of commits to the remote repository (where others may have pulled your code and started working with it), a revert is a nicer way to cancel out changes for them. This is because the Git workflow works well for picking up additional commits at the end of a branch, but it can be challenging if a set of commits is no longer seen in the chain when someone resets the branch pointer back. - -This brings us to one of the fundamental rules when working with Git in this manner: Making these kinds of changes in your local repository to code you haven't pushed yet is fine. But avoid making changes that rewrite history if the commits have already been pushed to the remote repository and others may be working with them. - -In short, if you rollback, undo, or rewrite the history of a commit chain that others are working with, your colleagues may have a lot more work when they try to merge in changes based on the original chain they pulled. If you must make changes against code that has already been pushed and is being used by others, consider communicating before you make the changes and give people the chance to merge their changes first. Then they can pull a fresh copy after the infringing operation without needing to merge. - -You may have noticed that the original chain of commits was still there after we did the reset. We moved the pointer and reset the code back to a previous commit, but it did not delete any commits. This means that, as long as we know the original commit we were pointing to, we can "restore" back to the previous point by simply resetting back to the original head of the branch: -``` -git reset - -``` - -A similar thing happens in most other operations we do in Git when commits are replaced. New commits are created, and the appropriate pointer is moved to the new chain. But the old chain of commits still exists. - -### Rebase - -Now let's look at a branch rebase. Consider that we have two branches—master and feature—with the chain of commits shown in Figure 4 below. Master has the chain `C4->C2->C1->C0` and feature has the chain `C5->C3->C2->C1->C0`. - -![Chain of commits for branches master and feature][6] - -Fig. 4: Chain of commits for branches master and feature - -If we look at the log of commits in the branches, they might look like the following. (The `C` designators for the commit messages are used to make this easier to understand.) -``` -$ git log --oneline master -6a92e7a C4 -259bf36 C2 -f33ae68 C1 -5043e79 C0 - -$ git log --oneline feature -79768b8 C5 -000f9ae C3 -259bf36 C2 -f33ae68 C1 -5043e79 C0 -``` - -I tell people to think of a rebase as a "merge with history" in Git. Essentially what Git does is take each different commit in one branch and attempt to "replay" the differences onto the other branch. - -So, we can rebase a feature onto master to pick up `C4` (e.g., insert it into feature's chain). Using the basic Git commands, it might look like this: -``` -$ git checkout feature -$ git rebase master - -First, rewinding head to replay your work on top of it... -Applying: C3 -Applying: C5 -``` - -Afterward, our chain of commits would look like Figure 5. - -![Chain of commits after the rebase command][8] - -Fig. 5: Chain of commits after the `rebase` command - -Again, looking at the log of commits, we can see the changes. -``` -$ git log --oneline master -6a92e7a C4 -259bf36 C2 -f33ae68 C1 -5043e79 C0 - -$ git log --oneline feature -c4533a5 C5 -64f2047 C3 -6a92e7a C4 -259bf36 C2 -f33ae68 C1 -5043e79 C0 -``` - -Notice that we have `C3'` and `C5'`—new commits created as a result of making the changes from the originals "on top of" the existing chain in master. But also notice that the "original" `C3` and `C5` are still there—they just don't have a branch pointing to them anymore. - -If we did this rebase, then decided we didn't like the results and wanted to undo it, it would be as simple as: -``` -$ git reset 79768b8 - -``` - -With this simple change, our branch would now point back to the same set of commits as before the `rebase` operation—effectively undoing it (Figure 6). - -![After undoing rebase][10] - -Fig. 6: After undoing the `rebase` operation - -What happens if you can't recall what commit a branch pointed to before an operation? Fortunately, Git again helps us out. For most operations that modify pointers in this way, Git remembers the original commit for you. In fact, it stores it in a special reference named `ORIG_HEAD `within the `.git` repository directory. That path is a file containing the most recent reference before it was modified. If we `cat` the file, we can see its contents. -``` -$ cat .git/ORIG_HEAD -79768b891f47ce06f13456a7e222536ee47ad2fe -``` - -We could use the `reset` command, as before, to point back to the original chain. Then the log would show this: -``` -$ git log --oneline feature -79768b8 C5 -000f9ae C3 -259bf36 C2 -f33ae68 C1 -5043e79 C0 -``` - -Another place to get this information is in the reflog. The reflog is a play-by-play listing of switches or changes to references in your local repository. To see it, you can use the `git reflog` command: -``` -$ git reflog -79768b8 HEAD@{0}: reset: moving to 79768b -c4533a5 HEAD@{1}: rebase finished: returning to refs/heads/feature -c4533a5 HEAD@{2}: rebase: C5 -64f2047 HEAD@{3}: rebase: C3 -6a92e7a HEAD@{4}: rebase: checkout master -79768b8 HEAD@{5}: checkout: moving from feature to feature -79768b8 HEAD@{6}: commit: C5 -000f9ae HEAD@{7}: checkout: moving from master to feature -6a92e7a HEAD@{8}: commit: C4 -259bf36 HEAD@{9}: checkout: moving from feature to master -000f9ae HEAD@{10}: commit: C3 -259bf36 HEAD@{11}: checkout: moving from master to feature -259bf36 HEAD@{12}: commit: C2 -f33ae68 HEAD@{13}: commit: C1 -5043e79 HEAD@{14}: commit (initial): C0 -``` - -You can then reset to any of the items in that list using the special relative naming format you see in the log: -``` -$ git reset HEAD@{1} - -``` - -Once you understand that Git keeps the original chain of commits around when operations "modify" the chain, making changes in Git becomes much less scary. This is one of Git's core strengths: being able to quickly and easily try things out and undo them if they don't work. - -Brent Laster will present [Power Git: Rerere, Bisect, Subtrees, Filter Branch, Worktrees, Submodules, and More][11] at the 20th annual [OSCON][12] event, July 16-19 in Portland, Ore. For more tips and explanations about using Git at any level, checkout Brent's book "[Professional Git][13]," available on Amazon. - --------------------------------------------------------------------------------- - -via: https://opensource.com/article/18/6/git-reset-revert-rebase-commands - -作者:[Brent Laster][a] -选题:[lujun9972](https://github.com/lujun9972) -译者:[译者ID](https://github.com/译者ID) -校对:[校对者ID](https://github.com/校对者ID) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 - -[a]:https://opensource.com/users/bclaster -[1]:/file/401126 -[2]:https://opensource.com/sites/default/files/uploads/gitcommands1_local-environment.png (Local Git environment with repository, staging area, and working directory) -[3]:/file/401131 -[4]:https://opensource.com/sites/default/files/uploads/gitcommands2_reset.png (After reset) -[5]:/file/401141 -[6]:https://opensource.com/sites/default/files/uploads/gitcommands4_commits-branches.png (Chain of commits for branches master and feature) -[7]:/file/401146 -[8]:https://opensource.com/sites/default/files/uploads/gitcommands5_commits-rebase.png (Chain of commits after the rebase command) -[9]:/file/401151 -[10]:https://opensource.com/sites/default/files/uploads/gitcommands6_rebase-undo.png (After undoing rebase) -[11]:https://conferences.oreilly.com/oscon/oscon-or/public/schedule/detail/67142 -[12]:https://conferences.oreilly.com/oscon/oscon-or -[13]:https://www.amazon.com/Professional-Git-Brent-Laster/dp/111928497X/ref=la_B01MTGIINQ_1_2?s=books&ie=UTF8&qid=1528826673&sr=1-2 diff --git a/sources/tech/20180622 Automatically Change Wallpapers in Linux with Little Simple Wallpaper Changer.md b/sources/tech/20180622 Automatically Change Wallpapers in Linux with Little Simple Wallpaper Changer.md deleted file mode 100644 index d3d3c00937..0000000000 --- a/sources/tech/20180622 Automatically Change Wallpapers in Linux with Little Simple Wallpaper Changer.md +++ /dev/null @@ -1,85 +0,0 @@ -translating----geekpi - -Automatically Change Wallpapers in Linux with Little Simple Wallpaper Changer -====== - -**Brief: Here is a tiny script that automatically changes wallpaper at regular intervals in your Linux desktop.** - -As the name suggests, LittleSimpleWallpaperChanger is a small script that changes the wallpapers randomly at intervals. - -Now I know that there is a random wallpaper option in the ‘Appearance’ or the ‘Change desktop background’ settings. But that randomly changes the pre-installed wallpapers and not the wallpapers that you add. - -So in this article, we’ll be seeing how to set up a random desktop wallpaper setup consisting of your photos using LittleSimpleWallpaperChanger. - -### Little Simple Wallpaper Changer (LSWC) - -[LittleSimpleWallpaperChanger][1] or LSWC is a very lightweight script that runs in the background, changing the wallpapers from the user-specified folder. The wallpapers change at a random interval between 1 to 5 minutes. The software is rather simple to set up, and once set up, the user can just forget about it. - -![Little Simple Wallpaper Changer to change wallpapers in Linux][2] - -#### Installing LSWC - -Download LSWC by [clicking on this link.][3] The zipped file is around 15 KB in size. - - * Browse to the download location. - * Right click on the downloaded .zip file and select ‘extract here’. - * Open the extracted folder, right click and select ‘Open in terminal’. - * Copy paste the command in the terminal and hit enter. -`bash ./README_and_install.sh` - * Now a dialogue box will pop up asking you to select the folder containing the wallpapers. Click on it and then select the folder that you’ve stored your wallpapers in. - * That’s it. Reboot your computer. - - - -![Little Simple Wallpaper Changer for Linux][4] - -#### Using LSWC - -On installation, LSWC asks you to select the folder containing your wallpapers. So I suggest you create a folder and move all the wallpapers you want to use there before we install LSWC. Or you can just use the ‘Wallpapers’ folder in the Pictures folder. **All the wallpapers need to be .jpg format.** - -You can add more wallpapers or delete the current wallpapers from your selected folder. To change the wallpapers folder location, you can edit the location of the wallpapers in the -following file. -``` -.config/lswc/homepath.conf - -``` - -#### To remove LSWC - -Open a terminal and run the below command to stop LSWC -``` -pkill lswc - -``` - -Open home in your file manager and press ctrl+H to show hidden files, then delete the following files: - - * ‘scripts’ folder from .local - * ‘lswc’ folder from .config - * ‘lswc.desktop’ file from .config/autostart - - - -There you have it. How to create your own desktop background slideshow. LSWC is really lightweight and simple to use. Install it and then forget it. - -LSWC is not very feature rich but that intentional. It does what it intends to do and that is to change wallpapers. If you want a tool that automatically downloads wallpapers try [WallpaperDownloader][5]. - -Do share your thoughts on this nifty little software in the comments section below. Don’t forget to share this article. Cheers. - --------------------------------------------------------------------------------- - -via: https://itsfoss.com/little-simple-wallpaper-changer/ - -作者:[Aquil Roshan][a] -选题:[lujun9972](https://github.com/lujun9972) -译者:[译者ID](https://github.com/译者ID) -校对:[校对者ID](https://github.com/校对者ID) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 - -[a]:https://itsfoss.com/author/aquil/ -[1]:https://github.com/LittleSimpleWallpaperChanger/lswc -[2]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/05/Little-simple-wallpaper-changer-2-800x450.jpg -[3]:https://github.com/LittleSimpleWallpaperChanger/lswc/raw/master/Lswc.zip -[4]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/05/Little-simple-wallpaper-changer-1-800x450.jpg -[5]:https://itsfoss.com/wallpaperdownloader-linux/ diff --git a/sources/tech/20180622 How to Check Disk Space on Linux from the Command Line.md b/sources/tech/20180622 How to Check Disk Space on Linux from the Command Line.md deleted file mode 100644 index c69e6459fc..0000000000 --- a/sources/tech/20180622 How to Check Disk Space on Linux from the Command Line.md +++ /dev/null @@ -1,181 +0,0 @@ -How to Check Disk Space on Linux from the Command Line -====== - -![](https://www.linux.com/sites/lcom/files/styles/rendered_file/public/diskspace-main.jpg?itok=t9Oxxc9X) - -Quick question: How much space do you have left on your drives? A little or a lot? Follow up question: Do you know how to find out? If you happen to use a GUI desktop (e.g., GNOME, KDE, Mate, Pantheon, etc.), the task is probably pretty simple. But what if you’re looking at a headless server, with no GUI? Do you need to install tools for the task? The answer is a resounding no. All the necessary bits are already in place to help you find out exactly how much space remains on your drives. In fact, you have two very easy-to-use options at the ready. - -In this article, I’ll demonstrate these tools. I’ll be using [Elementary OS][1], which also includes a GUI option, but we’re going to limit ourselves to the command line. The good news is these command-line tools are readily available for every Linux distribution. On my testing system, there are a number of attached drives (both internal and external). The commands used are agnostic to where a drive is plugged in; they only care that the drive is mounted and visible to the operating system. - -With that said, let’s take a look at the tools. - -### df - -The df command is the tool I first used to discover drive space on Linux, way back in the 1990s. It’s very simple in both usage and reporting. To this day, df is my go-to command for this task. This command has a few switches but, for basic reporting, you really only need one. That command is df -H. The -H switch is for human-readable format. The output of df -H will report how much space is used, available, percentage used, and the mount point of every disk attached to your system (Figure 1). - - -![df output][3] - -Figure 1: The output of df -H on my Elementary OS system. - -[Used with permission][4] - -What if your list of drives is exceedingly long and you just want to view the space used on a single drive? With df, that is possible. Let’s take a look at how much space has been used up on our primary drive, located at /dev/sda1. To do that, issue the command: -``` -df -H /dev/sda1 - -``` - -The output will be limited to that one drive (Figure 2). - - -![disk usage][6] - -Figure 2: How much space is on one particular drive? - -[Used with permission][4] - -You can also limit the reported fields shown in the df output. Available fields are: - - * source — the file system source - - * size — total number of blocks - - * used — spaced used on a drive - - * avail — space available on a drive - - * pcent — percent of used space, divided by total size - - * target — mount point of a drive - - - - -Let’s display the output of all our drives, showing only the size, used, and avail (or availability) fields. The command for this would be: -``` -df -H --output=size,used,avail - -``` - -The output of this command is quite easy to read (Figure 3). - - -![output][8] - -Figure 3: Specifying what output to display for our drives. - -[Used with permission][4] - -The only caveat here is that we don’t know the source of the output, so we’d want to include source like so: -``` -df -H --output=source,size,used,avail - -``` - -Now the output makes more sense (Figure 4). - -![source][10] - -Figure 4: We now know the source of our disk usage. - -[Used with permission][4] - -### du - -Our next command is du. As you might expect, that stands for disk usage. The du command is quite different to the df command, in that it reports on directories and not drives. Because of this, you’ll want to know the names of directories to be checked. Let’s say I have a directory containing virtual machine files on my machine. That directory is /media/jack/HALEY/VIRTUALBOX. If I want to find out how much space is used by that particular directory, I’d issue the command: -``` -du -h /media/jack/HALEY/VIRTUALBOX - -``` - -The output of the above command will display the size of every file in the directory (Figure 5). - -![du command][12] - -Figure 5: The output of the du command on a specific directory. - -[Used with permission][4] - -So far, this command isn’t all that helpful. What if we want to know the total usage of a particular directory? Fortunately, du can handle that task. On the same directory, the command would be: -``` -du -sh /media/jack/HALEY/VIRTUALBOX/ - -``` - -Now we know how much total space the files are using up in that directory (Figure 6). - -![space used][14] - -Figure 6: My virtual machine files are using 559GB of space. - -[Used with permission][4] - -You can also use this command to see how much space is being used on all child directories of a parent, like so: -``` -du -h /media/jack/HALEY - -``` - -The output of this command (Figure 7) is a good way to find out what subdirectories are hogging up space on a drive. - -![directories][16] - -Figure 7: How much space are my subdirectories using? - -[Used with permission][4] - -The du command is also a great tool to use in order to see a list of directories that are using the most disk space on your system. The way to do this is by piping the output of du to two other commands: sort and head. The command to find out the top 10 directories eating space on a drive would look something like this: -``` -du -a /media/jack | sort -n -r | head -n 10 - -``` - -The output would list out those directories, from largest to least offender (Figure 8). - -![top users][18] - -Figure 8: Our top ten directories using up space on a drive. - -[Used with permission][4] - -### Not as hard as you thought - -Finding out how much space is being used on your Linux-attached drives is quite simple. As long as your drives are mounted to the Linux system, both df and du will do an outstanding job of reporting the necessary information. With df you can quickly see an overview of how much space is used on a disk and with du you can discover how much space is being used by specific directories. These two tools in combination should be considered must-know for every Linux administrator. - -And, in case you missed it, I recently showed how to [determine your memory usage on Linux][19]. Together, these tips will go a long way toward helping you successfully manage your Linux servers. - -Learn more about Linux through the free ["Introduction to Linux"][20]course from The Linux Foundation and edX. - --------------------------------------------------------------------------------- - -via: https://www.linux.com/learn/intro-to-linux/2018/6how-check-disk-space-linux-command-line - -作者:[Jack Wallen][a] -选题:[lujun9972](https://github.com/lujun9972) -译者:[译者ID](https://github.com/译者ID) -校对:[校对者ID](https://github.com/校对者ID) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 - -[a]:https://www.linux.com/users/jlwallen -[1]:https://elementary.io/ -[2]:/files/images/diskspace1jpg -[3]:https://www.linux.com/sites/lcom/files/styles/rendered_file/public/diskspace_1.jpg?itok=aJa8AZAM (df output) -[4]:https://www.linux.com/licenses/category/used-permission -[5]:/files/images/diskspace2jpg -[6]:https://www.linux.com/sites/lcom/files/styles/rendered_file/public/diskspace_2.jpg?itok=_PAq3kxC (disk usage) -[7]:/files/images/diskspace3jpg -[8]:https://www.linux.com/sites/lcom/files/styles/rendered_file/public/diskspace_3.jpg?itok=51m8I-Vu (output) -[9]:/files/images/diskspace4jpg -[10]:https://www.linux.com/sites/lcom/files/styles/rendered_file/public/diskspace_4.jpg?itok=SuwgueN3 (source) -[11]:/files/images/diskspace5jpg -[12]:https://www.linux.com/sites/lcom/files/styles/rendered_file/public/diskspace_5.jpg?itok=XfS4s7Zq (du command) -[13]:/files/images/diskspace6jpg -[14]:https://www.linux.com/sites/lcom/files/styles/rendered_file/public/diskspace_6.jpg?itok=r71qICyG (space used) -[15]:/files/images/diskspace7jpg -[16]:https://www.linux.com/sites/lcom/files/styles/rendered_file/public/diskspace_7.jpg?itok=PtDe4q5y (directories) -[17]:/files/images/diskspace8jpg -[18]:https://www.linux.com/sites/lcom/files/styles/rendered_file/public/diskspace_8.jpg?itok=v9E1SFcC (top users) -[19]:https://www.linux.com/learn/5-commands-checking-memory-usage-linux -[20]:https://training.linuxfoundation.org/linux-courses/system-administration-training/introduction-to-linux diff --git a/sources/tech/20180623 Don-t Install Yaourt- Use These Alternatives for AUR in Arch Linux.md b/sources/tech/20180623 Don-t Install Yaourt- Use These Alternatives for AUR in Arch Linux.md deleted file mode 100644 index b2e4eed821..0000000000 --- a/sources/tech/20180623 Don-t Install Yaourt- Use These Alternatives for AUR in Arch Linux.md +++ /dev/null @@ -1,203 +0,0 @@ -Don’t Install Yaourt! Use These Alternatives for AUR in Arch Linux -====== -**Brief: Yaourt had been the most popular AUR helper, but it is not being developed anymore. In this article, we list out some of the best alternatives to Yaourt for Arch based Linux distributions. ** - -[Arch User Repository][1] popularly known as AUR is the community-driven software repository for Arch users. Debian/Ubuntu users can think of AUR as the equivalent of PPA. - -It contains the packages that are not directly endorsed by [Arch Linux][2]. If someone develops a software or package for Arch Linux, it can be provided through this community repositories. This enables the end-user to access more software than what they get by default. - -So, how do you use AUR then? Well, you need a different tool to install software from AUR. Arch’s package manager [pacman][3] doesn’t support it directly. These ‘special tools’ are called [AUR helpers][4]. - -Yaourt (Yet AnOther User Repository Tool) is/was a wrapper for pacman that helps to install AUR packages on Arch Linux. It uses the same syntax as pacman. Yaourt has great support for Arch User Repository for searching, installing, conflict resolution and dependency maintenance. - -However, Yaourt development has been slow lately and is [listed][5] as “Discontinued or problematic” on Arch Wiki. [Many Arch User believe it’s not secure][6] and hence go towards a different AUR helper. - -![AUR Helpers other than Yaourt][7] - -In this article, we will see the best Yaourt alternatives that you can use for installing software from AUR. - -### Best AUR helpers to use AUR - -I am deliberating omitting some of the other popular AUR helpers like trizen or packer because they too have been flagged as ‘discontinued or problematic’. - -#### 1\. aurman - -[aurman][8] is one of the best AUR helpers and serves pretty well as an alternative to Yaourt. It has almost similar syntax to pacman with support for all pacman operations. You can search the AUR, resolve dependencies, check PKGBUILD content before a package build etc. - -##### Features of aurman - - * aurman supports all pacman operations and incorporates reliable dependency resolving, conflict detection and split package support. - * Threaded sudo loop runs in the background saving you from entering your password each time. - * Provides development package support and distincts between explictily and inlicitly installed packages. - * Support for searching of AUR packages and repositories. - * You can see and edit the PKGBUILDs before starting AUR package build. - * It can also be used as a standalone [dependency solver][9]. - - - -##### Installing aurman -``` -git clone https://aur.archlinux.org/aurman.git -cd aurman -makepkg -si - -``` - -##### Using aurman - -Searching for an application through aurman in Arch User Repository is done in the following manner: -``` -aurman -Ss - -``` - -Installing an application using aurman: -``` -aurman -S <package-name> - -``` - -#### 2\. yay - -[yay][10] is the next best AUR helper written in Go with the objective of providing an interface of pacman with minimal user input, yaourt like search and with almost no dependencies. - -##### Features of yay - - * yay provides AUR table completion and download the PKGBUILD from ABS or AUR. - * Supports search narrowing and no sourcing of PKGBUILD. - * The binary has no additional dependencies than pacman. - * Provides advanced dependency solver and remove make dependencies at the end of the build process. - * Supports colored output when you enable Color option in the /etc/pacman.conf file. - * It can be made to support only AUR package or only repo packages. - - - -##### Installing yay - -You can install yay by cloning the git repo and building it. Use the below command to install yay in Arch Linux : -``` -git clone https://aur.archlinux.org/yay.git -cd yay -makepkg -si - -``` - -##### Using yay - -Searching an application through Yay in AUR: -``` -yay -Ss - -``` - -Installing an application: -``` -yay -S - -``` - -#### 3\. pakku - -[Pakku][11] is another pacman wrapper which is still in its initial stage. However, just because its new doesn’t mean its lacking any of the features supported by other AUR helper. It does its job pretty nice and along with searching and installing applications from AUR, it removes dependencies after a build. - -##### Features of pakku - - * Searching and installing packages from Arch User Repository. - * Viewing files and changes between builds. - * Building packages from official repositories and removing make dependencies after a build. - * PKGBUILD retrieving and Pacman integration. - * Pacman-like user interface and pacman options supports. - * Pacman configuration supports and no PKGBUILD sourcing. - - - -##### Installing pakku -``` -git clone https://aur.archlinux.org/pakku.git -cd pakku -makepkg -si - -``` - -##### Using pakku - -You can search an application from AUR using below command.: -``` -pakku -Ss spotify - -``` - -And then the package can be installed similar to pacman: -``` -pakku -S spotify - -``` - -#### 4\. aurutils - -[aurutils][12] is basically a collection of scripts that automates the usage of Arch User Repository. It can search AUR, check updates for different applications installed and settle up dependencies issues. - -##### Features of aurutils - - * aurutils uses a local repository which gives it a benefit of pacman file support, and all packages works with –asdeps. - * There can be multiple repos for different tasks. - * Update local repository in one go with aursync -u - * pkgbase, long format and raw support for aursearch - * Ability to ignore package - - - -##### Installing aurutils -``` -git clone https://aur.archlinux.org/aurutils.git -cd aurutils -makepkg -si - -``` - -##### Using aurutils - -Searching an application via aurutils: -``` -aurutils -Ss - -``` - -Installing a package from AUR: -``` -aurutils -S - -``` - -All of these packages can directly be installed if you are already using Yaourt or any other AUR helper. - -#### Final Words on AUR helpers - -Arch Linux has some [more AUR helper][4] that can automate certain tasks for the Arch User Repository. Many users are still using Yaourt for their AUR-work and - -The choice differs for each user and we would like to know which one you use for your Arch Linux. Let us know in the comments. - --------------------------------------------------------------------------------- - -via: https://itsfoss.com/best-aur-helpers/ - -作者:[Ambarish Kumar][a] -选题:[lujun9972](https://github.com/lujun9972) -译者:[译者ID](https://github.com/译者ID) -校对:[校对者ID](https://github.com/校对者ID) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 - -[a]:https://itsfoss.com/author/ambarish/ -[1]:https://wiki.archlinux.org/index.php/Arch_User_Repository -[2]:https://www.archlinux.org/ -[3]:https://wiki.archlinux.org/index.php/pacman -[4]:https://wiki.archlinux.org/index.php/AUR_helpers -[5]:https://wiki.archlinux.org/index.php/AUR_helpers#Comparison_table -[6]:https://www.reddit.com/r/archlinux/comments/4azqyb/whats_so_bad_with_yaourt/ -[7]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/06/no-yaourt-arch-800x450.jpeg -[8]:https://github.com/polygamma/aurman -[9]:https://github.com/polygamma/aurman/wiki/Using-aurman-as-dependency-solver -[10]:https://github.com/Jguer/yay -[11]:https://github.com/kitsunyan/pakku -[12]:https://github.com/AladW/aurutils diff --git a/sources/tech/20180623 Intercepting and Emulating Linux System Calls with Ptrace - null program.md b/sources/tech/20180623 Intercepting and Emulating Linux System Calls with Ptrace - null program.md deleted file mode 100644 index 08fde90f66..0000000000 --- a/sources/tech/20180623 Intercepting and Emulating Linux System Calls with Ptrace - null program.md +++ /dev/null @@ -1,293 +0,0 @@ -Intercepting and Emulating Linux System Calls with Ptrace « null program -====== - -The `ptrace(2)` (“process trace”) system call is usually associated with debugging. It’s the primary mechanism through which native debuggers monitor debuggees on unix-like systems. It’s also the usual approach for implementing [strace][1] — system call trace. With Ptrace, tracers can pause tracees, [inspect and set registers and memory][2], monitor system calls, or even intercept system calls. - -By intercept, I mean that the tracer can mutate system call arguments, mutate the system call return value, or even block certain system calls. Reading between the lines, this means a tracer can fully service system calls itself. This is particularly interesting because it also means **a tracer can emulate an entire foreign operating system**. This is done without any special help from the kernel beyond Ptrace. - -The catch is that a process can only have one tracer attached at a time, so it’s not possible emulate a foreign operating system while also debugging that process with, say, GDB. The other issue is that emulated systems calls will have higher overhead. - -For this article I’m going to focus on [Linux’s Ptrace][3] on x86-64, and I’ll be taking advantage of a few Linux-specific extensions. For the article I’ll also be omitting error checks, but the full source code listings will have them. - -You can find runnable code for the examples in this article here: - -**** - -### strace - -Before getting into the really interesting stuff, let’s start by reviewing a bare bones implementation of strace. It’s [no DTrace][4], but strace is still incredibly useful. - -Ptrace has never been standardized. Its interface is similar across different operating systems, especially in its core functionality, but it’s still subtly different from system to system. The `ptrace(2)` prototype generally looks something like this, though the specific types may be different. -``` -long ptrace(int request, pid_t pid, void *addr, void *data); - -``` - -The `pid` is the tracee’s process ID. While a tracee can have only one tracer attached at a time, a tracer can be attached to many tracees. - -The `request` field selects a specific Ptrace function, just like the `ioctl(2)` interface. For strace, only two are needed: - - * `PTRACE_TRACEME`: This process is to be traced by its parent. - * `PTRACE_SYSCALL`: Continue, but stop at the next system call entrance or exit. - * `PTRACE_GETREGS`: Get a copy of the tracee’s registers. - - - -The other two fields, `addr` and `data`, serve as generic arguments for the selected Ptrace function. One or both are often ignored, in which case I pass zero. - -The strace interface is essentially a prefix to another command. -``` -$ strace [strace options] program [arguments] - -``` - -My minimal strace doesn’t have any options, so the first thing to do — assuming it has at least one argument — is `fork(2)` and `exec(2)` the tracee process on the tail of `argv`. But before loading the target program, the new process will inform the kernel that it’s going to be traced by its parent. The tracee will be paused by this Ptrace system call. -``` -pid_t pid = fork(); -switch (pid) { - case -1: /* error */ - FATAL("%s", strerror(errno)); - case 0: /* child */ - ptrace(PTRACE_TRACEME, 0, 0, 0); - execvp(argv[1], argv + 1); - FATAL("%s", strerror(errno)); -} - -``` - -The parent waits for the child’s `PTRACE_TRACEME` using `wait(2)`. When `wait(2)` returns, the child will be paused. -``` -waitpid(pid, 0, 0); - -``` - -Before allowing the child to continue, we tell the operating system that the tracee should be terminated along with its parent. A real strace implementation may want to set other options, such as `PTRACE_O_TRACEFORK`. -``` -ptrace(PTRACE_SETOPTIONS, pid, 0, PTRACE_O_EXITKILL); - -``` - -All that’s left is a simple, endless loop that catches on system calls one at a time. The body of the loop has four steps: - - 1. Wait for the process to enter the next system call. - 2. Print a representation of the system call. - 3. Allow the system call to execute and wait for the return. - 4. Print the system call return value. - - - -The `PTRACE_SYSCALL` request is used in both waiting for the next system call to begin, and waiting for that system call to exit. As before, a `wait(2)` is needed to wait for the tracee to enter the desired state. -``` -ptrace(PTRACE_SYSCALL, pid, 0, 0); -waitpid(pid, 0, 0); - -``` - -When `wait(2)` returns, the registers for the thread that made the system call are filled with the system call number and its arguments. However, the operating system has not yet serviced this system call. This detail will be important later. - -The next step is to gather the system call information. This is where it gets architecture specific. On x86-64, [the system call number is passed in `rax`][5], and the arguments (up to 6) are passed in `rdi`, `rsi`, `rdx`, `r10`, `r8`, and `r9`. Reading the registers is another Ptrace call, though there’s no need to `wait(2)` since the tracee isn’t changing state. -``` -struct user_regs_struct regs; -ptrace(PTRACE_GETREGS, pid, 0, ®s); -long syscall = regs.orig_rax; - -fprintf(stderr, "%ld(%ld, %ld, %ld, %ld, %ld, %ld)", - syscall, - (long)regs.rdi, (long)regs.rsi, (long)regs.rdx, - (long)regs.r10, (long)regs.r8, (long)regs.r9); - -``` - -There’s one caveat. For [internal kernel purposes][6], the system call number is stored in `orig_rax` rather than `rax`. All the other system call arguments are straightforward. - -Next it’s another `PTRACE_SYSCALL` and `wait(2)`, then another `PTRACE_GETREGS` to fetch the result. The result is stored in `rax`. -``` -ptrace(PTRACE_GETREGS, pid, 0, ®s); -fprintf(stderr, " = %ld\n", (long)regs.rax); - -``` - -The output from this simple program is very crude. There is no symbolic name for the system call and every argument is printed numerically, even if it’s a pointer to a buffer. A more complete strace would know which arguments are pointers and use `process_vm_readv(2)` to read those buffers from the tracee in order to print them appropriately. - -However, this does lay the groundwork for system call interception. - -### System call interception - -Suppose we want to use Ptrace to implement something like OpenBSD’s [`pledge(2)`][7], in which [a process pledges to use only a restricted set of system calls][8]. The idea is that many programs typically have an initialization phase where they need lots of system access (opening files, binding sockets, etc.). After initialization they enter a main loop in which they processing input and only a small set of system calls are needed. - -Before entering this main loop, a process can limit itself to the few operations that it needs. If [the program has a flaw][9] allowing it to be exploited by bad input, the pledge significantly limits what the exploit can accomplish. - -Using the same strace model, rather than print out all system calls, we could either block certain system calls or simply terminate the tracee when it misbehaves. Termination is easy: just call `exit(2)` in the tracer. Since it’s configured to also terminate the tracee. Blocking the system call and allowing the child to continue is a little trickier. - -The tricky part is that **there’s no way to abort a system call once it’s started**. When tracer returns from `wait(2)` on the entrance to the system call, the only way to stop a system call from happening is to terminate the tracee. - -However, not only can we mess with the system call arguments, we can change the system call number itself, converting it to a system call that doesn’t exist. On return we can report a “friendly” `EPERM` error in `errno` [via the normal in-band signaling][10]. -``` -for (;;) { - /* Enter next system call */ - ptrace(PTRACE_SYSCALL, pid, 0, 0); - waitpid(pid, 0, 0); - - struct user_regs_struct regs; - ptrace(PTRACE_GETREGS, pid, 0, ®s); - - /* Is this system call permitted? */ - int blocked = 0; - if (is_syscall_blocked(regs.orig_rax)) { - blocked = 1; - regs.orig_rax = -1; // set to invalid syscall - ptrace(PTRACE_SETREGS, pid, 0, ®s); - } - - /* Run system call and stop on exit */ - ptrace(PTRACE_SYSCALL, pid, 0, 0); - waitpid(pid, 0, 0); - - if (blocked) { - /* errno = EPERM */ - regs.rax = -EPERM; // Operation not permitted - ptrace(PTRACE_SETREGS, pid, 0, ®s); - } -} - -``` - -This simple example only checks against a whitelist or blacklist of system calls. And there’s no nuance, such as allowing files to be opened (`open(2)`) read-only but not as writable, allowing anonymous memory maps but not non-anonymous mappings, etc. There’s also no way to the tracee to dynamically drop privileges. - -How could the tracee communicate to the tracer? Use an artificial system call! - -### Creating an artificial system call - -For my new pledge-like system call — which I call `xpledge()` to distinguish it from the real thing — I picked system call number 10000, a nice high number that’s unlikely to ever be used for a real system call. -``` -#define SYS_xpledge 10000 - -``` - -Just for demonstration purposes, I put together a minuscule interface that’s not good for much in practice. It has little in common with OpenBSD’s `pledge(2)`, which uses a [string interface][11]. Actually designing robust and secure sets of privileges is really complicated, as the `pledge(2)` manpage shows. Here’s the entire interface and implementation of the system call for the tracee: -``` -#define _GNU_SOURCE -#include - -#define XPLEDGE_RDWR (1 << 0) -#define XPLEDGE_OPEN (1 << 1) - -#define xpledge(arg) syscall(SYS_xpledge, arg) - -``` - -If it passes zero for the argument, only a few basic system calls are allowed, including those used to allocate memory (e.g. `brk(2)`). The `PLEDGE_RDWR` bit allows [various][12] read and write system calls (`read(2)`, `readv(2)`, `pread(2)`, `preadv(2)`, etc.). The `PLEDGE_OPEN` bit allows `open(2)`. - -To prevent privileges from being escalated back, `pledge()` blocks itself — though this also prevents dropping more privileges later down the line. - -In the xpledge tracer, I just need to check for this system call: -``` -/* Handle entrance */ -switch (regs.orig_rax) { - case SYS_pledge: - register_pledge(regs.rdi); - break; -} - -``` - -The operating system will return `ENOSYS` (Function not implemented) since this isn’t a real system call. So on the way out I overwrite this with a success (0). -``` -/* Handle exit */ -switch (regs.orig_rax) { - case SYS_pledge: - ptrace(PTRACE_POKEUSER, pid, RAX * 8, 0); - break; -} - -``` - -I wrote a little test program that opens `/dev/urandom`, makes a read, tries to pledge, then tries to open `/dev/urandom` a second time, then confirms it can read from the original `/dev/urandom` file descriptor. Running without a pledge tracer, the output looks like this: -``` -$ ./example -fread("/dev/urandom")[1] = 0xcd2508c7 -XPledging... -XPledge failed: Function not implemented -fread("/dev/urandom")[2] = 0x0be4a986 -fread("/dev/urandom")[1] = 0x03147604 - -``` - -Making an invalid system call doesn’t crash an application. It just fails, which is a rather convenient fallback. When run under the tracer, it looks like this: -``` -$ ./xpledge ./example -fread("/dev/urandom")[1] = 0xb2ac39c4 -XPledging... -fopen("/dev/urandom")[2]: Operation not permitted -fread("/dev/urandom")[1] = 0x2e1bd1c4 - -``` - -The pledge succeeds but the second `fopen(3)` does not since the tracer blocked it with `EPERM`. - -This concept could be taken much further, to, say, change file paths or return fake results. A tracer could effectively chroot its tracee, prepending some chroot path to the root of any path passed through a system call. It could even lie to the process about what user it is, claiming that it’s running as root. In fact, this is exactly how the [Fakeroot NG][13] program works. - -### Foreign system emulation - -Suppose you don’t just want to intercept some system calls, but all system calls. You’ve got [a binary intended to run on another operating system][14], so none of the system calls it makes will ever work. - -You could manage all this using only what I’ve described so far. The tracer would always replace the system call number with a dummy, allow it to fail, then service the system call itself. But that’s really inefficient. That’s essentially three context switches for each system call: one to stop on the entrance, one to make the always-failing system call, and one to stop on the exit. - -The Linux version of PTrace has had a more efficient operation for this technique since 2005: `PTRACE_SYSEMU`. PTrace stops only once per a system call, and it’s up to the tracer to service that system call before allowing the tracee to continue. -``` -for (;;) { - ptrace(PTRACE_SYSEMU, pid, 0, 0); - waitpid(pid, 0, 0); - - struct user_regs_struct regs; - ptrace(PTRACE_GETREGS, pid, 0, ®s); - - switch (regs.orig_rax) { - case OS_read: - /* ... */ - - case OS_write: - /* ... */ - - case OS_open: - /* ... */ - - case OS_exit: - /* ... */ - - /* ... and so on ... */ - } -} - -``` - -To run binaries for the same architecture from any system with a stable (enough) system call ABI, you just need this `PTRACE_SYSEMU` tracer, a loader (to take the place of `exec(2)`), and whatever system libraries the binary needs (or only run static binaries). - -In fact, this sounds like a fun weekend project. - --------------------------------------------------------------------------------- - -via: http://nullprogram.com/blog/2018/06/23/ - -作者:[Chris Wellons][a] -选题:[lujun9972](https://github.com/lujun9972) -译者:[译者ID](https://github.com/译者ID) -校对:[校对者ID](https://github.com/校对者ID) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 - -[a]:http://nullprogram.com -[1]:https://blog.plover.com/Unix/strace-groff.html -[2]:http://nullprogram.com/blog/2016/09/03/ -[3]:http://man7.org/linux/man-pages/man2/ptrace.2.html -[4]:http://nullprogram.com/blog/2018/01/17/ -[5]:http://nullprogram.com/blog/2015/05/15/ -[6]:https://stackoverflow.com/a/6469069 -[7]:https://man.openbsd.org/pledge.2 -[8]:http://www.openbsd.org/papers/hackfest2015-pledge/mgp00001.html -[9]:http://nullprogram.com/blog/2017/07/19/ -[10]:http://nullprogram.com/blog/2016/09/23/ -[11]:https://www.tedunangst.com/flak/post/string-interfaces -[12]:http://nullprogram.com/blog/2017/03/01/ -[13]:https://fakeroot-ng.lingnu.com/index.php/Home_Page -[14]:http://nullprogram.com/blog/2017/11/30/ diff --git a/sources/tech/20180625 How To Upgrade Everything Using A Single Command In Linux.md b/sources/tech/20180625 How To Upgrade Everything Using A Single Command In Linux.md deleted file mode 100644 index 741cd82f0d..0000000000 --- a/sources/tech/20180625 How To Upgrade Everything Using A Single Command In Linux.md +++ /dev/null @@ -1,123 +0,0 @@ -How To Upgrade Everything Using A Single Command In Linux -====== - -![](https://www.ostechnix.com/wp-content/uploads/2018/06/topgrade-720x340.png) - -As we all know already, keeping our Linux system up-to-date involves invoking more than one package manager. Say for instance, in Ubuntu you can’t upgrade everything using “sudo apt update && sudo apt upgrade” command. This command will only upgrade the applications which are installed using APT package manager. There are chances that you might have installed some other applications using **cargo** , [**pip**][1], **npm** , **snap** , **flatpak** or [**Linuxbrew**][2] package managers. You need to use the respective package manager in order to keep them all updated. Not anymore! Say hello to **“topgrade”** , an utility to upgrade all the things in your system in one go. - -You need not to run every package manager to update the packages. The topgrade tool resolves this problem by detecting the installed packages, tools, plugins and run their appropriate package manager to update everything in your Linux box with a single command. It is free, open source and written using **rust programming language**. It supports GNU/Linux and Mac OS X. - -### Upgrade Everything Using A Single Command In Linux - -The topgrade is available in AUR. So, you can install it using [**Yay**][3] helper program in any Arch-based systems. -``` -$ yay -S topgrade - -``` - -On other Linux distributions, you can install topgrade utility using **cargo** package manager. To install cargo package manager, refer the following link. - -And, then run the following command to install topgrade. -``` -$ cargo install topgrade - -``` - -Once installed, run the topgrade to upgrade all the things in your Linux system. -``` -$ topgrade - -``` - -Once topgrade is invoked, it will perform the following tasks one by one. You will be asked to enter root/sudo user password wherever necessary. - -1 Run your system’s package manager: - - * Arch: Run **yay** or fall back to [**pacman**][4] - * CentOS/RHEL: Run `yum upgrade` - * Fedora – Run `dnf upgrade` - * Debian/Ubuntu: Run `apt update && apt dist-upgrade` - * Linux/macOS: Run `brew update && brew upgrade` - - - -2\. Check if the following paths are tracked by Git. If so, pull them: - - * ~/.emacs.d (Should work whether you use **Spacemacs** or a custom configuration) - * ~/.zshrc - * ~/.oh-my-zsh - * ~/.tmux - * ~/.config/fish/config.fish - * Custom defined paths - - - -3\. Unix: Run **zplug** update - -4\. Unix: Upgrade **tmux** plugins with **TPM** - -5\. Run **Cargo install-update** - -6\. Upgrade **Emacs** packages - -7\. Upgrade Vim packages. Works with the following plugin frameworks: - - * NeoBundle - * [**Vundle**][5] - * Plug - - - -8\. Upgrade [**NPM**][6] globally installed packages - -9\. Upgrade **Atom** packages - -10\. Update [**Flatpak**][7] packages - -11\. Update [**snap**][8] packages - -12\. **Linux:** Run **fwupdmgr** to show firmware upgrade. (View only. No upgrades will actually be performed) - -13\. Run custom defined commands. - -Finally, topgrade utility will run **needrestart** to restart all services. In Mac OS X, it will upgrade App Store applications. - -Sample output from my Ubuntu 18.04 LTS test box: - -![][10] - -The good thing is if one task is failed, it will automatically run the next task and complete all other subsequent tasks. Finally, it will display the summary with details such as how many tasks did it run, how many succeeded and how many failed etc. - -![][11] - -**Suggested read:** - -Personally, I liked this idea of creating an utility like topgrade and upgrade everything installed with various package managers with a single command. I hope you find it useful too. More good stuffs to come. Stay tuned! - -Cheers! - - - --------------------------------------------------------------------------------- - -via: https://www.ostechnix.com/how-to-upgrade-everything-using-a-single-command-in-linux/ - -作者:[SK][a] -选题:[lujun9972](https://github.com/lujun9972) -译者:[译者ID](https://github.com/译者ID) -校对:[校对者ID](https://github.com/校对者ID) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 - -[a]:https://www.ostechnix.com/author/sk/ -[1]:https://www.ostechnix.com/manage-python-packages-using-pip/ -[2]:https://www.ostechnix.com/linuxbrew-common-package-manager-linux-mac-os-x/ -[3]:https://www.ostechnix.com/yay-found-yet-another-reliable-aur-helper/ -[4]:https://www.ostechnix.com/getting-started-pacman/ -[5]:https://www.ostechnix.com/manage-vim-plugins-using-vundle-linux/ -[6]:https://www.ostechnix.com/manage-nodejs-packages-using-npm/ -[7]:https://www.ostechnix.com/flatpak-new-framework-desktop-applications-linux/ -[8]:https://www.ostechnix.com/install-snap-packages-arch-linux-fedora/ -[9]:data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7 -[10]:http://www.ostechnix.com/wp-content/uploads/2018/06/topgrade-1.png -[11]:http://www.ostechnix.com/wp-content/uploads/2018/06/topgrade-2.png diff --git a/sources/tech/20180625 How to install Pipenv on Fedora.md b/sources/tech/20180625 How to install Pipenv on Fedora.md deleted file mode 100644 index e1099d5ded..0000000000 --- a/sources/tech/20180625 How to install Pipenv on Fedora.md +++ /dev/null @@ -1,95 +0,0 @@ -translating---geekpi - -How to install Pipenv on Fedora -====== - -![](https://fedoramagazine.org/wp-content/uploads/2018/06/pipenv-install-816x345.jpg) - -Pipenv aims to bring the best of all packaging worlds (bundler, composer, npm, cargo, yarn, etc.) to the Python world. It tries to solve a couple of problems and also simplify the whole management process. - -Currently the management of Python application dependencies sometimes seems like a bit of a challenge. Developers usually create a [virtual environment][1] for each new project and install dependencies into it using [pip][2]. In addition they have to store the set of installed packages into the requirements.txt text file. We’ve seen many tools and wrappers that aim to automate this workflow. However, there was still necessity to combine multiple utilities and the requirements.txt format itself is not ideal for more complicated scenarios. - -### One tol to rule them all - -Pipenv manages complex inter-dependencies properly and it also provides manual documenting of installed packages. For example development, testing and production environments often require a different set of packages. It used to be necessary to maintain multiple requirements.txt per project. Pipenv introduces the new [Pipfile][3] format using [TOML][4] syntax. Thanks to this format, you can finally maintain multiple set of requirement for different environments in a single file. - -Pipenv has become the officially recommended tool for managing Python application dependencies only a year after the first lines of code were committed into the project. Now it is finally available as an package in Fedora repositories as well. - -### Installing Pipenv on Fedora - -On clean installation of Fedora 28 and later you can simply install Pipenv by running this command at the terminal: -``` -$ sudo dnf install pipenv - -``` - -Your system is now ready to start working on your new Python 3 application with help of Pipenv. - -The important point is that while this tool provides nice solution for the applications, it is not designed for dealing with library requirements. When writing a Python library, pinning dependencies is not desirable. You should rather specify install_requires in setup.py file. - -### Basic dependencies management - -Create a directory for your project first: -``` -$ mkdir new-project && cd new-project - -``` - -Another step is to create a virtual environment for this project: -``` -$ pipenv --three - -``` - -The –three option here sets the Python version of the virtual environment to Python 3. - -Install dependencies: -``` -$ pipenv install requests -Installing requests… -Adding requests to Pipfile's [packages]… -Pipfile.lock not found, creating… -Locking [dev-packages] dependencies… -Locking [packages] dependencies… - -``` - -Finally generate a lockfile: -``` -$ pipenv lock -Locking [dev-packages] dependencies… -Locking [packages] dependencies… -Updated Pipfile.lock (b14837) - -``` - -You can also check a dependency graph: -``` -$ pipenv graph - - certifi [required: >=2017.4.17, installed: 2018.4.16] -- chardet [required: <3.1.0,>=3.0.2, installed: 3.0.4] -- idna [required: <2.8,>=2.5, installed: 2.7] -- urllib3 [required: >=1.21.1,<1.24, installed: 1.23] - -``` - -More details on Pipenv and it commands are available in the [documentation][5]. - - --------------------------------------------------------------------------------- - -via: https://fedoramagazine.org/install-pipenv-fedora/ - -作者:[Michal Cyprian][a] -选题:[lujun9972](https://github.com/lujun9972) -译者:[译者ID](https://github.com/译者ID) -校对:[校对者ID](https://github.com/校对者ID) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 - -[a]:https://fedoramagazine.org/author/mcyprian/ -[1]:https://packaging.python.org/tutorials/installing-packages/#creating-virtual-environments -[2]:https://developer.fedoraproject.org/tech/languages/python/pypi-installation.html -[3]:https://github.com/pypa/pipfile -[4]:https://github.com/toml-lang/toml -[5]:https://docs.pipenv.org/ diff --git a/sources/tech/20180626 TrueOS Doesnt Want to Be BSD for Desktop Anymore.md b/sources/tech/20180626 TrueOS Doesnt Want to Be BSD for Desktop Anymore.md deleted file mode 100644 index 1a4d55e474..0000000000 --- a/sources/tech/20180626 TrueOS Doesnt Want to Be BSD for Desktop Anymore.md +++ /dev/null @@ -1,77 +0,0 @@ -TrueOS Doesn’t Want to Be ‘BSD for Desktop’ Anymore -============================================================ - - -There are some really big changes on the horizon for [TrueOS][9]. Today, we will take a look at what is going on in the world of desktop BSD. - -### The Announcement - -![TrueOS: Core Operating System BSD](https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/06/true-os-bsd-desktop.jpeg) - -The team behind [TrueOS][10] [announced][11] that they would be changing the focus of the project. Up until this point, TrueOS has made it easy to install BSD with a graphical user interface out of the box. However, it will now become “a cutting-edge operating system that keeps all of the stability that you know and love from ZFS ([OpenZFS][12]) and [FreeBSD][13], and adds additional features to create a fresh, innovative operating system. Our goal is to create a core-centric operating system that is modular, functional, and perfect for do-it-yourselfers and advanced users alike.” - -Essentially, TrueOs will become a downstream fork of FreeBSD. They will integrate newer software into the system, such as [OpenRC][14] and [LibreSSL][15]. They hope to stick to a 6-month release cycle. - -The goal is to make TrueOS so it can be used as the base for other projects to build on. The graphical part will be missing to make it more distro-agnostic. - -[Suggested readInterview with MidnightBSD Founder and Lead Dev Lucas Holt][16] - -### What about Desktop Users? - -If you read my [review of TrueOS][17] and are interested in trying a desktop BSD or already use TrueOS, never fear (which is good advice for life too). All of the desktop elements of TrueOS will be spun off into [Project Trident][18]. Currently, the Project Trident website is very light on details. It seems as though they are still figuring out the logistics of the spin-off. - -If you currently have TrueOS, you don’t have to worry about moving. The TrueOS team said that “there will be migration paths available for those that would like to move to other FreeBSD-based distributions like Project Trident or [GhostBSD][19].” - -[Suggested readInterview with FreeDOS Founder and Lead Dev Jim Hall][20] - -### Thoughts - -When I first read the announcement, I was frankly a little worried. Changing names can be a bad idea. Customers will be used to one name, but if the product name changes they could lose track of the project very easily. TrueOS already went through a name change. When the project was started in 2006 it was named PC-BSD, but in 2016 the name was changed to TrueOS. It kinds of reminds me of the [ArchMerge and Arcolinux saga][21]. - -That being said, I think this will be a good thing for desktop users of BSD. One of the common criticisms that I heard about PC-BSD and TrueOS is that it wasn’t very polished. Separating the two parts of the project will help sharpen the focus of the respective developers. The TrueOS team will be able to add newer features to the slow-moving FreeBSD base and the Project Trident team will be able to improve user’s desktop experience. - -I wish both teams well. Remember, people, when someone works on open source, we all benefit even if the work is done on something we don’t use. - -What are your thoughts about the future of TrueOS and Project Trident? Please let us know in the comments below. - - ------------------------------- - -关于作者: - -My name is John Paul Wohlscheid. I'm an aspiring mystery writer who loves to play with technology, especially Linux. You can catch up with me at [my personal website][23] - --------------------------------------------------------------------------------- - -via: https://itsfoss.com/trueos-plan-change/ - -作者:[John Paul Wohlscheid ][a] -译者:[译者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/john/ -[1]:https://itsfoss.com/author/john/ -[2]:https://itsfoss.com/trueos-plan-change/#comments -[3]:https://itsfoss.com/category/bsd/ -[4]:https://itsfoss.com/category/news/ -[5]:https://itsfoss.com/tag/bsd/ -[6]:https://itsfoss.com/tag/freebsd/ -[7]:https://itsfoss.com/tag/project-trident/ -[8]:https://itsfoss.com/tag/trueos/ -[9]:https://www.trueos.org/ -[10]:https://www.trueos.org/ -[11]:https://www.trueos.org/blog/trueosdownstream/ -[12]:http://open-zfs.org/wiki/Main_Page -[13]:https://www.freebsd.org/ -[14]:https://en.wikipedia.org/wiki/OpenRC -[15]:http://www.libressl.org/ -[16]:https://itsfoss.com/midnightbsd-founder-lucas-holt/ -[17]:https://itsfoss.com/trueos-bsd-review/ -[18]:http://www.project-trident.org/ -[19]:https://www.ghostbsd.org/ -[20]:https://itsfoss.com/interview-freedos-jim-hall/ -[21]:https://itsfoss.com/archlabs-vs-archmerge/ -[22]:http://reddit.com/r/linuxusersgroup -[23]:http://johnpaulwohlscheid.work/ diff --git a/sources/tech/20180628 Blockchain evolution- A quick guide and why open source is at the heart of it.md b/sources/tech/20180628 Blockchain evolution- A quick guide and why open source is at the heart of it.md deleted file mode 100644 index 585a7203d1..0000000000 --- a/sources/tech/20180628 Blockchain evolution- A quick guide and why open source is at the heart of it.md +++ /dev/null @@ -1,97 +0,0 @@ -Blockchain evolution: A quick guide and why open source is at the heart of it -====== - -![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/block-quilt-chain.png?itok=mECoDbrc) - -It isn't uncommon, when working on a new version of an open source project, to suffix it with "-ng", for "next generation." Fortunately, in their rapid evolution blockchains have so far avoided this naming pitfall. But in this evolutionary open source ecosystem, changes have been abundant, and good ideas have been picked up, remixed, and evolved between many different projects in a typical open source fashion. - -In this article, I will look at the different generations of blockchains and what ideas have emerged to address the problems the ecosystem has encountered. Of course, any attempt at classifying an ecosystem will have limits—and objectors—but it should provide a rough guide to the jungle of blockchain projects. - -### The beginning: Bitcoin - -The first generation of blockchains stems from the [Bitcoin][1] blockchain, the ledger underpinning the decentralized, peer-to-peer cryptocurrency that has gone from [Slashdot][2] miscellanea to a mainstream topic. - -This blockchain is a distributed ledger that keeps track of all users' transactions to prevent them from double-spending their coins (a task historically entrusted to third parties: banks). To prevent attackers from gaming the system, the ledger is replicated to every computer participating in the Bitcoin network and can be updated by only one computer in the network at a time. To decide which computer earns the right to update the ledger, the system organizes every 10 minutes a race between the computers, which costs them (a lot of) energy to enter. The winner wins the right to commit the last 10 minutes of transactions to the ledger (the "block" in blockchain) and some Bitcoin as a reward for their efforts. This setup is called a _proof of work_ consensus mechanism. - -The goal of using a blockchain is to raise the level of trust participants have in the network. - -This is where it gets interesting. Bitcoin was released as an [open source project][3] in January 2009. In 2010, realizing that quite a few of these elements can be tweaked, the community that had aggregated around Bitcoin, often on the [bitcointalk forums][4], started experimenting with them. - -First, seeing that the Bitcoin blockchain is a form of a distributed database, the [Namecoin][5] project emerged, suggesting to store arbitrary data in its transaction database. If the blockchain can record the transfer of money, it could also record the transfer of other assets, such as domain names. This is exactly Namecoin's main use case, which went live in April 2011, two years after Bitcoin's introduction. - -Where Namecoin tweaked the content of the blockchain, [Litecoin][6] tweaked two technical aspects: reducing the time between two blocks from 10 to 2.5 minutes and changing how the race is run (replacing the SHA-256 secure hashing algorithm with [scrypt][7]). This was possible because Bitcoin was released as open source software and Litecoin is essentially identical to Bitcoin in all other places. Litecoin was the first fork to modify the consensus mechanism, paving the way for many more. - -Along the way, many more variations of the Bitcoin codebase have appeared. Some started as proposed extensions to Bitcoin, such as the [Zerocash][8] protocol, which aimed to provide transaction anonymity and fungibility but was eventually spun off into its own currency, [Zcash][9]. - -While Zcash has brought its own innovations, using recent cryptographic advances known as zero-knowledge proofs, it maintains compatibility with the vast majority of the Bitcoin code base, meaning it too can benefit from upstream Bitcoin innovations. - -Another project, [CryptoNote][10], didn't use the same code base but sprouted from the same community, building on (and against) Bitcoin and again, on older ideas. Published in December 2012, it led to the creation of several cryptocurrencies, of which [Monero][11] (2014) is the best-known. Monero takes a different approach to Zcash but aims to solve the same issues: privacy and fungibility. - -As is often the case in the open source world, there is more than one tool for the job. - -### The next generations: "Blockchain-ng" - -So far, however, all these variations have only really been about refining cryptocurrencies or extending them to support another type of transaction. This brings us to the second generation of blockchains. - -Once the community started modifying what a blockchain could be used for and tweaking technical aspects, it didn't take long for some people to expand and rethink them further. A longtime follower of Bitcoin, [Vitalik Buterin][12] suggested in late 2013 that a blockchain's transactions could represent the change of states of a state machine, conceiving the blockchain as a distributed computer capable of running applications ("smart contracts"). The project, [Ethereum][13], went live in July 2015. It has seen fair success in running distributed apps, and the popularity of some of its better-known distributed apps ([CryptoKitties][14]) have even caused the Ethereum blockchain to slow down. - -This demonstrates one of the big limitations of current blockchains: speed and capacity. (Speed is often measured in transactions per second, or TPS.) Several approaches have been suggested to solve this, from sharding to sidechains and so-called "second-layer" solutions. The need for more innovation here is strong. - -With the words "smart contract" in the air and a proved—if still slow—technology to run them, another idea came to fruition: permissioned blockchains. So far, all the blockchain networks we've described have had two unsaid characteristics: They are public (anyone can see them function), and they are without permission (anyone can join them). These two aspects are both desirable and necessary to run a distributed, non-third-party-based currency. - -As blockchains were being considered more and more separately from cryptocurrencies, it started to make sense to consider them in some private, permissioned settings. A consortium-type group of actors that have business relationships but don't necessarily trust each other fully can benefit from these types of blockchains—for example, actors along a logistics chain, financial or insurance institutions that regularly do bilateral settlements or use a clearinghouse, idem for healthcare institutions. - -Once you change the setting from "anyone can join" to "invitation-only," further changes and tweaks to the blockchain building blocks become possible, yielding interesting results for some. - -For a start, proof of work, designed to protect the network from malicious and spammy actors, can be replaced by something simpler and less resource-hungry, such as a [Raft][15]-based consensus protocol. A tradeoff appears between a high level of security or faster speed, embodied by the option of simpler consensus algorithms. This is highly desirable to many groups, as they can trade some cryptography-based assurance for assurance based on other means—legal relationships, for instance—and avoid the energy-hungry arms race that proof of work often leads to. This is another area where innovation is ongoing, with [Proof of Stake][16] a notable contender for the public network consensus mechanism of choice. It would likely also find its way to permissioned networks too. - -Several projects make it simple to create permissioned blockchains, including [Quorum][17] (a fork of Ethereum) and [Hyperledger][18]'s [Fabric][19] and [Sawtooth][20], two open source projects based on new code. - -Permissioned blockchains can avoid certain complexities that public, non-permissioned ones can't, but they still have their own set of issues. Proper management of participants is one: Who can join? How do they identify? How can they be removed from the network? Does one entity on the network manage a central public key infrastructure (PKI)? - -The open nature of blockchains is seen as a form of governance. - -### Open nature of blockchains - -In all of the cases so far, one thing is clear: The goal of using a blockchain is to raise the level of trust participants have in the network and the data it produces—ideally, enough to be able to use it as is, without further work. - -Reaching this level of trust is possible only if the software that powers the network is free and open source. Even a correctly distributed proprietary blockchain is essentially a collection of independent agents running the same third party's code. By nature, it's necessary—but not sufficient—for a blockchain's source code to be open source. This has both been a minimum guarantee and the source of further innovation as the ecosystem keeps growing. - -Finally, it is worth mentioning that while the open nature of blockchains has been a source of innovation and variation, it has also been seen as a form of governance: governance by code, where users are expected to run whichever specific version of the code contains a function or approach they think the whole network should embrace. In this respect, one can say the open nature of some blockchains has also become a cop-out regarding governance. But this is being addressed. - -### Third and fourth generations: governance - -Next, I will look at what I am currently considering the third and fourth generations of blockchains: blockchains with built-in governance tools and projects to solve the tricky question of interconnecting the multitude of different blockchain projects to let them exchange information and value with each other. - --------------------------------------------------------------------------------- - -via: https://opensource.com/article/18/6/blockchain-guide-next-generation - -作者:[Axel Simon][a] -选题:[lujun9972](https://github.com/lujun9972) -译者:[译者ID](https://github.com/译者ID) -校对:[校对者ID](https://github.com/校对者ID) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 - -[a]:https://opensource.com/users/axel -[1]:https://bitcoin.org -[2]:https://slashdot.org/ -[3]:https://github.com/bitcoin/bitcoin -[4]:https://bitcointalk.org/ -[5]:https://www.namecoin.org/ -[6]:https://litecoin.org/ -[7]:https://en.wikipedia.org/wiki/Scrypt -[8]:http://zerocash-project.org/index -[9]:https://z.cash -[10]:https://cryptonote.org/ -[11]:https://en.wikipedia.org/wiki/Monero_(cryptocurrency) -[12]:https://en.wikipedia.org/wiki/Vitalik_Buterin -[13]:https://ethereum.org -[14]:http://cryptokitties.co/ -[15]:https://en.wikipedia.org/wiki/Raft_(computer_science) -[16]:https://www.investopedia.com/terms/p/proof-stake-pos.asp -[17]:https://www.jpmorgan.com/global/Quorum -[18]:https://hyperledger.org/ -[19]:https://www.hyperledger.org/projects/fabric -[20]:https://www.hyperledger.org/projects/sawtooth diff --git a/sources/tech/20180628 Sosreport - A Tool To Collect System Logs And Diagnostic Information.md b/sources/tech/20180628 Sosreport - A Tool To Collect System Logs And Diagnostic Information.md deleted file mode 100644 index a476c5e0cd..0000000000 --- a/sources/tech/20180628 Sosreport - A Tool To Collect System Logs And Diagnostic Information.md +++ /dev/null @@ -1,142 +0,0 @@ -translating---geekpi - - -Sosreport – A Tool To Collect System Logs And Diagnostic Information -====== - -![](https://www.ostechnix.com/wp-content/uploads/2018/06/sos-720x340.png) - -If you’re working as RHEL administrator, you might definitely heard about **Sosreport** – an extensible, portable and support data collection tool. It is a tool to collect system configuration details and diagnostic information from a Unix-like operating system. When the user raise a support ticket, he/she has to run this tool and send the resulting report generated by Sosreport tool to the Red Hat support executive. The executive will then perform an initial analysis based on the report and try to find what’s the problem in the system. Not just on RHEL system, you can use it on any Unix-like operating systems for collecting system logs and other debug information. - -### Installing Sosreport - -Sosreport is available on Red Hat official systems, so you can install it using Yum Or DNF package managers as shown below. -``` -$ sudo yum install sos - -``` - -Or, -``` -$ sudo dnf install sos - -``` - -On Debian, Ubuntu and Linux Mint, run: -``` -$ sudo apt install sosreport - -``` - -### Usage - -Once installed, run the following command to collect your system configuration details and other diagnostic information. -``` -$ sudo sosreport - -``` - -You will be asked to enter some details of your system, such as system name, case id etc. Type the details accordingly, and press ENTER key to generate the report. If you don’t want to change anything and want to use the default values, simply press ENTER. - -Sample output from my CentOS 7 server: -``` -sosreport (version 3.5) - -This command will collect diagnostic and configuration information from -this CentOS Linux system and installed applications. - -An archive containing the collected information will be generated in -/var/tmp/sos.DiJXi7 and may be provided to a CentOS support -representative. - -Any information provided to CentOS will be treated in accordance with -the published support policies at: - -https://wiki.centos.org/ - -The generated archive may contain data considered sensitive and its -content should be reviewed by the originating organization before being -passed to any third party. - -No changes will be made to system configuration. - -Press ENTER to continue, or CTRL-C to quit. - -Please enter your first initial and last name [server.ostechnix.local]: -Please enter the case id that you are generating this report for []: - -Setting up archive ... -Setting up plugins ... -Running plugins. Please wait ... - -Running 73/73: yum... -Creating compressed archive... - -Your sosreport has been generated and saved in: -/var/tmp/sosreport-server.ostechnix.local-20180628171844.tar.xz - -The checksum is: 8f08f99a1702184ec13a497eff5ce334 - -Please send this file to your support representative. - -``` - -If you don’t want to be prompted for entering such details, simply use batch mode like below. -``` -$ sudo sosreport --batch - -``` - -As you can see in the above output, an archived report is generated and saved in **/var/tmp/sos.DiJXi7** file. In RHEL 6/CentOS 6, the report will be generated in **/tmp** location. You can now send this report to your support executive, so that he can do initial analysis and find what’s the problem. - -You might be concerned or wanted to know what’s in the report. If so, you can view it by running the following command: -``` -$ sudo tar -tf /var/tmp/sosreport-server.ostechnix.local-20180628171844.tar.xz - -``` - -Or, -``` -$ sudo vim /var/tmp/sosreport-server.ostechnix.local-20180628171844.tar.xz - -``` - -Please note that above commands will not extract the archive, but only display the list of files and folders in the archive. If you want to view the actual contents of the files in the archive, first extract the archive using command: -``` -$ sudo tar -xf /var/tmp/sosreport-server.ostechnix.local-20180628171844.tar.xz - -``` - -All the contents of the archive will be extracted in a directory named “sosreport-server.ostechnix.local-20180628171844/” in the current working directory. Go to the directory and view the contents of any file using cat command or any other text viewer: -``` -$ cd sosreport-server.ostechnix.local-20180628171844/ - -$ cat uptime -17:19:02 up 1:03, 2 users, load average: 0.50, 0.17, 0.10 - -``` - -For more details about Sosreport, refer man pages. -``` -$ man sosreport - -``` - -And, that’s all for now. Hope this was useful. More good stuffs to come. Stay tuned! - -Cheers! - - - --------------------------------------------------------------------------------- - -via: https://www.ostechnix.com/sosreport-a-tool-to-collect-system-logs-and-diagnostic-information/ - -作者:[SK][a] -选题:[lujun9972](https://github.com/lujun9972) -译者:[译者ID](https://github.com/译者ID) -校对:[校对者ID](https://github.com/校对者ID) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 - -[a]:https://www.ostechnix.com/author/sk/ diff --git a/sources/tech/20180629 How To Get Flatpak Apps And Games Built With OpenGL To Work With Proprietary Nvidia Graphics Drivers.md b/sources/tech/20180629 How To Get Flatpak Apps And Games Built With OpenGL To Work With Proprietary Nvidia Graphics Drivers.md new file mode 100644 index 0000000000..a9d540adae --- /dev/null +++ b/sources/tech/20180629 How To Get Flatpak Apps And Games Built With OpenGL To Work With Proprietary Nvidia Graphics Drivers.md @@ -0,0 +1,113 @@ +How To Get Flatpak Apps And Games Built With OpenGL To Work With Proprietary Nvidia Graphics Drivers +====== +**Some applications and games built with OpenGL support and packaged as Flatpak fail to start with proprietary Nvidia drivers. This article explains how to get such Flatpak applications or games them to start, without installing the open source drivers (Nouveau).** + +Here's an example. I'm using the proprietary Nvidia drivers on my Ubuntu 18.04 desktop (`nvidia-driver-390`) and when I try to launch the latest +``` +$ /usr/bin/flatpak run --branch=stable --arch=x86_64 --command=krita --file-forwarding org.kde.krita +Gtk-Message: Failed to load module "canberra-gtk-module" +Gtk-Message: Failed to load module "canberra-gtk-module" +libGL error: No matching fbConfigs or visuals found +libGL error: failed to load driver: swrast +Could not initialize GLX + +``` + +To fix Flatpak games and applications not starting when using OpenGL with proprietary Nvidia graphics drivers, you'll need to install a runtime for your currently installed proprietary Nvidia drivers. Here's how to do this. + +**1\. Add the FlatHub repository if you haven't already. You can find exact instructions for your Linux distribution[here][1].** + +**2. Now you'll need to figure out the exact version of the proprietary Nvidia drivers installed on your system. ** + +_This step is dependant of the Linux distribution you're using and I can't cover all cases. The instructions below are Ubuntu-oriented (and Ubuntu flavors) but hopefully you can figure out for yourself the Nvidia drivers version installed on your system._ + +To do this in Ubuntu, open `Software & Updates` , switch to the `Additional Drivers` tab and note the name of the Nvidia driver package. + +As an example, this is `nvidia-driver-390` in my case, as you can see here: + +![](https://1.bp.blogspot.com/-FAfjtGNeUJc/WzYXMYTFBcI/AAAAAAAAAx0/xUhIO83IAjMuK4Hn0jFUYKJhSKw8y559QCLcBGAs/s1600/additional-drivers-nvidia-ubuntu.png) + +That's not all. We've only found out the Nvidia drivers major version but we'll also need to know the minor version. To get the exact Nvidia driver version, which we'll need for the next step, run this command (should work in any Debian-based Linux distribution, like Ubuntu, Linux Mint and so on): +``` +apt-cache policy NVIDIA-PACKAGE-NAME + +``` + +Where NVIDIA-PACKAGE-NAME is the Nvidia drivers package name listed in `Software & Updates` . For example, to see the exact installed version of the `nvidia-driver-390` package, run this command: +``` +$ apt-cache policy nvidia-driver-390 +nvidia-driver-390: + Installed: 390.48-0ubuntu3 + Candidate: 390.48-0ubuntu3 + Version table: + * 390.48-0ubuntu3 500 + 500 http://ro.archive.ubuntu.com/ubuntu bionic/restricted amd64 Packages + 100 /var/lib/dpkg/status + +``` + +In this command's output, look for the `Installed` section and note the version numbers (excluding `-0ubuntu3` and anything similar). Now we know the exact version of the installed Nvidia drivers (`390.48` in my example). Remember this because we'll need it for the next step. + +**3\. And finally, you can install the Nvidia runtime for your installed proprietary Nvidia graphics drivers, from FlatHub** + +To list all the available Nvidia runtime packages available on FlatHub, you can use this command: +``` +flatpak remote-ls flathub | grep nvidia + +``` + +Hopefully the runtime for your installed Nvidia drivers is available on FlatHub. You can now proceed to install the runtime by using this command: + + * For 64bit systems: + + +``` +flatpak install flathub org.freedesktop.Platform.GL.nvidia-MAJORVERSION-MINORVERSION + +``` + +Replace MAJORVERSION with the Nvidia driver major version installed on your computer (390 in my example above) and +MINORVERSION with the minor version (48 in my example from step 2). + +For example, to install the runtime for Nvidia graphics driver version 390.48, you'd have to use this command: +``` +flatpak install flathub org.freedesktop.Platform.GL.nvidia-390-48 + +``` + + * For 32bit systems (or to be able to run 32bit applications or games on 64bit), install the 32bit runtime using: + + +``` +flatpak install flathub org.freedesktop.Platform.GL32.nvidia-MAJORVERSION-MINORVERSION + +``` + +Once again, replace MAJORVERSION with the Nvidia driver major version installed on your computer (390 in my example above) and MINORVERSION with the minor version (48 in my example from step 2). + +For example, to install the 32bit runtime for Nvidia graphics driver version 390.48, you'd have to use this command: +``` +flatpak install flathub org.freedesktop.Platform.GL32.nvidia-390-48 + +``` + +That is all you need to do to get applications or games packaged as Flatpak that are built with OpenGL to run. + + +-------------------------------------------------------------------------------- + +via: https://www.linuxuprising.com/2018/06/how-to-get-flatpak-apps-and-games-built.html + +作者:[Logix][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://plus.google.com/118280394805678839070 +[1]:https://flatpak.org/setup/ +[2]:https://www.linuxuprising.com/2018/06/free-painting-software-krita-410.html +[3]:https://www.linuxuprising.com/2018/06/winepak-is-flatpak-repository-for.html +[4]:https://github.com/winepak/applications/issues/23 +[5]:https://github.com/flatpak/flatpak/issues/138 diff --git a/sources/tech/20180701 How to migrate to the world of Linux from Windows.md b/sources/tech/20180701 How to migrate to the world of Linux from Windows.md new file mode 100644 index 0000000000..5d9ef80c08 --- /dev/null +++ b/sources/tech/20180701 How to migrate to the world of Linux from Windows.md @@ -0,0 +1,154 @@ +How to migrate to the world of Linux from Windows +====== +Installing Linux on a computer, once you know what you’re doing, really isn’t a difficult process. After getting accustomed to the ins and outs of downloading ISO images, creating bootable media, and installing your distribution (henceforth referred to as distro) of choice, you can convert a computer to Linux in no time at all. In fact, the time it takes to install Linux and get it updated with all the latest patches is so short that enthusiasts do the process over and over again to try out different distros; this process is called distro hopping. + +With this guide, I want to target people who have never used Linux before. I’ll give an overview of some distros that are great for beginners, how to write or burn them to media, and how to install them. I’ll show you the installation process of Linux Mint, but the process is similar if you choose Ubuntu. For a distro such as Fedora, however, your experience will deviate quite a bit from what’s shown in this post. I’ll also touch on the sort of software available, and how to install additional software. + +The command line will not be covered; despite what some people say, using the command line really is optional in distributions such as Linux Mint, which is aimed at beginners. Most distros come with update managers, software managers, and file managers with graphical interfaces, which largely do away with the need for a command line. Don’t get me wrong, the command line can be great – I do use it myself from time to time – but largely for convenience purposes. + +This guide will also not touch on troubleshooting or dual booting. While Linux does generally support new hardware, there’s a slight chance that any cutting edge hardware you have might not yet be supported by Linux. Setting up a dual boot system is easy enough, though wiping the disk and doing a clean install is usually my preferred method. For this reason, if you intend to follow the guide, either use a virtual machine to install Linux or use a spare computer that you’ve got lying around. + +The chief appeal for most Linux users is the customisability and the diverse array of Linux distributions or distros that are available. For the majority of people getting into Linux, the usual entry point is Ubuntu, which is backed by Canonical. Ubuntu was my gateway Linux distribution in 2008; although not my favourite, it’s certainly easy to begin using and is very polished. + +Another beginner-friendly distribution is Linux Mint. It’s the distribution I use day-to-day on every one of my machines. It’s very easy to start using, is generally very stable, and the user interface (UI) doesn’t drastically change; anyone familiar with Windows XP or Windows Vista will be familiar with the the UI of Linux Mint. While everyone went chasing the convergence dream of merging mobile and desktop together, Linux Mint stayed staunchly of the position that an operating system on the desktop should be designed for desktop and therefore totally avoids being mobile-friendly UI; desktop and laptops are front and centre. + +For your first dive into Linux, I highly recommend the two mentioned above, simply because they’ve got huge communities and developers tending to them around the clock. With that said, several other operating systems such as elementary OS (based on Ubuntu) and Fedora (run by Red Hat) are also good ways to get started. Other users are fond of options such as Manjaro and Antergos which make the difficult-to-configure Arch Linux easy to use. + +Now, we’re starting to get our hands dirty. For this guide, I will include screenshots of Linux Mint 18.3 Cinnamon edition. If you decide to go with Ubuntu or another version of Linux Mint, note that things may look slightly different. For example, when it comes to a distro that isn’t based on Ubuntu – like Fedora or Manjaro – things will look significantly different during installation, but not so much that you won’t be able to work the process out. + +In order to download Linux Mint, head on over to the Linux Mint downloads page and select either the 32-bit version or 64-bit version of the Cinnamon edition. If you aren’t sure which version is needed for your computer, pick the 64-bit version; this tends to work on computers even from 2007, so it’s a safe bet. The only time I’d advise the 32-bit version is if you’re planning to install Linux on a netbook. + +Once you’ve selected your version, you can either download the ISO image via one of the many mirrors, or as a torrent. It’s best to download it as a torrent because if your internet cuts out, you won’t have to restart the 1.9 GB download. Additionally, the downloaded ISO you receive via torrent will be signed with the correct keys, ensuring authenticity. If you download another distribution, you’ll be able to continue to the next step once you have an ISO file saved to your computer. + +Note: If you’re using a virtual machine, you don’t need to write or burn the ISO to USB or DVD, just use the ISO to launch the distro on your chosen virtual machine. + +Ten years ago when I started using Linux, you could fit an entire distribution onto a CD. Nowadays, you’ll need a DVD or a USB to boot the distro from. + +To write the ISO to a USB device, I recommend downloading a tool called Rufus. Once it’s downloaded and installed, you should insert a USB stick that’s 4GB or more. Be sure to backup the data as the device will be erased. + +Next, launch Rufus and select the device you want to write to; if you aren’t sure which is your USB device, unplug it, check the list, then plug it back in to work out which device you need to write to. Once you’ve worked out which USB drive you want to write to, select ‘MBR Partition Scheme for BIOS or UEFI’ under ‘Partition scheme and target system type’. Once you’ve done that, press the optical drive icon alongside the enabled ‘Create a bootable disk using’ field. You can then navigate to the ISO file that you just downloaded. Once it finishes writing to the USB, you’ve got everything you need to boot into Linux. + +Note: If you’re using a virtual machine, you don’t need to write or burn the ISO to USB or DVD, just use the ISO to launch the distro on your chosen virtual machine. + +If you’re on Windows 7 or above and want to burn the ISO to a DVD, simply insert a blank DVD into the computer, then right-click the ISO file and select ‘Burn disc image’, from the dialogue window which appears, select the drive where the DVD is located, and tick ‘Verify disc after burning’, then hit Burn. + +If you’re on Windows Vista, XP, or lower, download an install Infra Recorder and insert your blank DVD into your computer, selecting ‘Do nothing’ or ‘Cancel’ if any autorun windows pop up. Next, open Infra Recorder and select ‘Write Image’ on the main screen or go to Actions > Burn Image. From there find the Linux ISO you want to burn and press ‘OK’ when prompted. + +Once you’ve got your DVD or USB media ready you’re ready to boot into Linux; doing so won’t harm your Windows install in any way. + +Once you’ve got your installation media on hand, you’re ready to boot into the live environment. The operating system will load entirely from your DVD or USB device without making changes to your hard drive, meaning Windows will be left intact. The live environment is used to see whether your graphics card, wireless devices, and so on are compatible with Linux before you install it. + +To boot into the live environment you’re going to have to switch off the computer and boot it back up with your installation media already inserted into the computer. It’s also a must to ensure that your boot up sequence is set to launch from USB or DVD before your current operating system boots up from the hard drive. Configuring the boot sequence is beyond the scope of this guide, but if you can’t boot from the USB or DVD, I recommend doing a web search for how to access the BIOS to change the boot sequence order on your specific motherboard. Common keys to enter the BIOS or select the drive to boot from are F2, F10, and F11. + +If your boot up sequence is configured correctly, you should see a ten second countdown, that when completed, will automatically boot Linux Mint. + +![][1] + +![][2] + +Those who opted to try Linux Mint can let the countdown run to zero and the boot up will commence normally. On Ubuntu you’ll probably be prompted to choose a language, then press ‘Try Ubuntu without installing’, or the equivalent option on Linux Mint if you interrupted the automatic countdown by pressing the keyboard. If at any time you have the choice between trying or installing your Linux distribution of choice, always opt to try it, as the install option can cause irreversible damage to your Windows installation. + +Hopefully, everything went according to plan, and you’ve made it through to the live environment. The first thing to do now is to check to see whether your Wi-Fi is available. To connect to Wi-Fi press the icon to the left of the clock, where you should see the usual list of available networks; if this is the case, great! If not, don’t despair just yet. In the second case, when wireless card doesn’t seem to be working, either establish a wired connection via Ethernet or connect your phone to the computer – provided your handset supports tethering (via Wi-Fi, not data). + +Once you’ve got some sort of internet connection via one of those methods, press ‘Menu’ and use the search box to look for ‘Driver Manager’. This usually requires an internet connection and may let you enable your wireless card driver. If that doesn’t work, you’re probably out of luck, but the vast majority of cards should work with Linux Mint. + +For those who have a fancy graphics card, chances are that Linux is using an open source driver alternative instead of the proprietary driver you use on Windows. If you notice any issues pertaining to graphics, you can check the Driver Manager and see whether any proprietary drivers are available. + +Once those two critical components are confirmed to be up and running, you may want to check printer and webcam compatibility. To test your printer, go to ‘Menu’ > ‘Office’ > ‘LibreOffice Writer’ and try printing a document. If it works, that’s great, if not, some printers may be made to work with some effort, but that’s outside the scope of this particular guide. I’d recommend searching something like ‘Linux [your printer model]’ and there may be solutions available. As for your webcam, go to ‘Menu’ again and use the search box to look for ‘Software Manager’; this is the Microsoft Store equivalent on Linux Mint. Search for a program named ‘Cheese’ and install it. Once installed, open it up using the ‘Launch’ button in Software Manager, or have a look in ‘Menu’ and find it manually. If it detects a webcam it means it’s compatible! + +![][3] + +By now, you’ve probably had a good look at Linux Mint or your distribution of choice and, hopefully, everything is working for you. If you’ve had enough and want to return to Windows, simply press Menu and then the power off button which is located right above ‘Menu’, then press ‘Shut Down’ if a dialogue box pops up. + +Given that you’re sticking with me and want to install Linux Mint on your computer, thus erasing Windows, ensure that you’ve backed up everything on your computer. Dual boot installations are available from the installer, but in this guide I’ll explain how to install Linux as the sole operating system. Assuming you do decide to deviate and set up a dual boot system, then ensure you still back up your files from Windows first, because things could potentially go wrong for you. + +In order to do a clean install, close down any programs that you’ve got running in the live environment. On the desktop, you should see a disc icon labelled ‘Install Linux Mint’ – click that to continue. + +![][4] + +On the first screen of the installer, choose your language and press continue. + +![][5] + +On the second screen, most users will want to install third-party software to ensure hardware and codecs work. + +![][6] + +In the ‘Installation type’ section you can choose to erase your hard drive or dual boot. You can encrypt the entire drive if you check ‘Encrypt the new Linux Mint installation for security’ and ‘Use LVM with the new Linux Mint installation’. You can press ‘Something else’ for a specific custom set up. In order to set up a dual boot system, the hard drive which you’re installing to must already have Windows installed first. + +![][7] + +Now pick your location so that the operating system’s time can be set correctly, and press continue. + +![][8] + +Now set your keyboard’s language, and press continue. + +![][9] + +On the ‘Who are you’ screen, you’ll create a new user. Pop in your name, leave the computer’s name as default or enter a custom name, pick a username, and enter a password. You can choose to have the system log you in automatically or require a password. If you choose to require a password then you can also encrypt your home folder, which is different from encrypting your entire system. However, if you encrypt your entire system, there’s not a lot of point to encrypting your home folder too. + +![][10] + +Once you’ve completed the ‘Who are you’ screen, Linux Mint will begin installing. You’ll see a slideshow detailing what the operating system offers. + +![][11] + +Once the installation finishes, you’ll be prompted to restart. Go ahead and do so. + +Now that you’ve restarted the computer and removed the Linux media, your computer should boot up straight to your new install. If everything has gone smoothly, you should arrive at the login screen where you just need to enter the password you created during the set up. + +![][12] + +Once you reach the desktop, the first thing you’ll want to do is apply all the system updates that are available. On Linux Mint you should see a shield icon with a blue logo in the bottom right-hand corner of the desktop near the clock, click on it to open the Update Manager. + +![][13] + +You should be prompted to pick an update policy, give them all a read over and apply whichever you think is most appropriate for you then press ‘OK’. + +![][14] + +![][15] + +You’ll probably be asked to pick a more local mirror too. This is optional, but could allow your updates to download quicker. Now, apply any updates offered, until the shield icon has a green tick indicating that all updates have been applied. In future, the Update Manager will continually check for new updates and alert you to them. + +You’ve got all the necessary tasks out the way for setting up Linux Mint and now you’re free to start using the system for whatever you like. By default, Mozilla Firefox is installed, so if you’ve got a Sync account it’s probably a good idea to go pull in all your passwords and bookmarks. If you’re a Chrome user, you can either run Chromium which is in the Software Manager, or download Google Chrome from the internet. If you opt to get Chrome, you’ll be offered a .deb file which you should save to your system and then double-click to install. Installing .deb files is straightforward enough, just press ‘Install’ when prompted and the system will handle the rest, you’ll find the new software in ‘Menu’. + +![][16] + +Other pre-installed software includes LibreOffice which has decent compatibility with Microsoft Office; Mozilla’s Thunderbird for managing your emails; GIMP for editing images; Transmission is readily available for you to begin torrenting files, it supports adding IP block lists too; Pidgin and Hexchat will allow you to send instant messages and connect to IRC respectively. As for media playback, you will find VLC and Rhythmbox under ‘Sound and Video’ to satisfy all your music and video needs. If you need any other software, check out the Software Manager, there are lots of popular packages including Skype, Minecraft, Google Earth, Steam, and Private Internet Access Manager. + +Throughout this guide, I’ve explained that it will not touch on troubleshooting problems. However, the Linux Mint community can help you overcome any complications. The first port of call is definitely a quick web search, as most problems have been resolved by others in the past and you might be able to find your solution online. If you’re still stuck, you can try the Linux Mint forums as well as the Linux Mint subreddit, both of which are oriented towards troubleshooting. + +Linux definitely isn’t for everyone. It still lacks on the gaming front, despite the existence of Steam on Linux, and the growing number of games. In addition, some commonly used software isn’t available on Linux, but usually there are alternatives available. If, however, you have a computer lying around that isn’t powerful enough to support Windows any more, then Linux could be a good option for you. Linux is also free to use, so it’s great for those who don’t want to spend money on a new copy of Windows too. + +loading... + +-------------------------------------------------------------------------------- + +via: http://infosurhoy.com/cocoon/saii/xhtml/en_GB/technology/how-to-migrate-to-the-world-of-linux-from-windows/ + +作者:[Marta Subat][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:http://infosurhoy.com/cocoon/saii/xhtml/en_GB/author/marta-subat/ +[1]:https://cdn.neow.in/news/images/uploaded/2018/02/1519139198_autoboot_linux_mint.jpg +[2]:https://cdn.neow.in/news/images/uploaded/2018/02/1519139206_bootmenu_linux_mint.jpg +[3]:https://cdn.neow.in/news/images/uploaded/2018/02/1519139213_cheese_linux_mint.jpg +[4]:https://cdn.neow.in/news/images/uploaded/2018/02/1519139254_install_1_linux_mint.jpg +[5]:https://cdn.neow.in/news/images/uploaded/2018/02/1519139261_install_2_linux_mint.jpg +[6]:https://cdn.neow.in/news/images/uploaded/2018/02/1519139270_install_3_linux_mint.jpg +[7]:https://cdn.neow.in/news/images/uploaded/2018/02/1519139278_install_4_linux_mint.jpg +[8]:https://cdn.neow.in/news/images/uploaded/2018/02/1519139285_install_5_linux_mint.jpg +[9]:https://cdn.neow.in/news/images/uploaded/2018/02/1519139293_install_6_linux_mint.jpg +[10]:https://cdn.neow.in/news/images/uploaded/2018/02/1519139302_install_7_linux_mint.jpg +[11]:https://cdn.neow.in/news/images/uploaded/2018/02/1519139317_install_8_linux_mint.jpg +[12]:https://cdn.neow.in/news/images/uploaded/2018/02/1519139224_first_boot_1_linux_mint.jpg +[13]:https://cdn.neow.in/news/images/uploaded/2018/02/1519139232_first_boot_2_linux_mint.jpg +[14]:https://cdn.neow.in/news/images/uploaded/2018/02/1519139240_first_boot_3_linux_mint.jpg +[15]:https://cdn.neow.in/news/images/uploaded/2018/02/1519139248_first_boot_4_linux_mint.jpg +[16]:https://cdn.neow.in/news/images/uploaded/2018/02/1519219725_software_1_linux_mint.jpg diff --git a/sources/tech/20180702 Diggs v4 launch: an optimism born of necessity.md b/sources/tech/20180702 Diggs v4 launch an optimism born of necessity.md similarity index 100% rename from sources/tech/20180702 Diggs v4 launch: an optimism born of necessity.md rename to sources/tech/20180702 Diggs v4 launch an optimism born of necessity.md diff --git a/sources/tech/20180702 How to edit Adobe InDesign files with Scribus and Gedit.md b/sources/tech/20180702 How to edit Adobe InDesign files with Scribus and Gedit.md deleted file mode 100644 index 3e8d2022c2..0000000000 --- a/sources/tech/20180702 How to edit Adobe InDesign files with Scribus and Gedit.md +++ /dev/null @@ -1,128 +0,0 @@ -How to edit Adobe InDesign files with Scribus and Gedit -====== - -![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/open-indesign-scribus-gedit-graphic.jpg?itok=OPJaGdA5) - -To be a good graphic designer, you must be adept at using the profession's tools, which for most designers today are the ones in the proprietary Adobe Creative Suite. - -However, there are times that open source tools will get you out of a jam. For example, imagine you're a commercial printer tasked with printing a file created in Adobe InDesign. You need to make a simple change (e.g., fixing a small typo) to the file, but you don't have immediate access to the Adobe suite. While these situations are admittedly rare, open source tools like desktop publishing software [Scribus][1] and text editor [Gedit][2] can save the day. - -In this article, I'll show you how I edit Adobe InDesign files with Scribus and Gedit. Note that there are many open source graphic design solutions that can be used instead of or in conjunction with Adobe InDesign. For more on this subject, check out my articles: [Expensive tools aren't the only option for graphic design (and never were)][3] and [2 open][4][source][4][Adobe InDesign scripts][4]. - -When developing this solution, I read a few blogs on how to edit InDesign files with open source software but did not find what I was looking for. One suggestion I found was to create an EPS from InDesign and open it as an editable file in Scribus, but that did not work. Another suggestion was to create an IDML (an older InDesign file format) document from InDesign and open that in Scribus. That worked much better, so that's the workaround I used in the following examples. - -### Editing a business card - -Opening and editing my InDesign business card file in Scribus worked fairly well. The only issue I had was that the tracking (the space between letters) was a bit off and the upside-down "J" I used to create the lower-case "f" in "Jeff" was flipped. Otherwise, the styles and colors were all intact. - - -![Business card in Adobe InDesign][6] - -Business card designed in Adobe InDesign. - -![InDesign IDML file opened in Scribus][8] - -InDesign IDML file opened in Scribus. - -### Deleting copy in a paginated book - -The book conversion didn't go as well. The main body of the text was OK, but the table of contents and some of the drop caps and footers were messed up when I opened the InDesign file in Scribus. Still, it produced an editable document. One problem was some of my blockquotes defaulted to Arial font because a character style (apparently carried over from the original Word file) was on top of the paragraph style. This was simple to fix. - -![Book layout in InDesign][10] - -Book layout in InDesign. - -![InDesign IDML file of book layout opened in Scribus][12] - -InDesign IDML file of book layout opened in Scribus. - -Trying to select and delete a page of text produced surprising results. I placed the cursor in the text and hit Command+A (the keyboard shortcut for "select all"). It looked like one page was highlighted. However, that wasn't really true. - -![Selecting text in Scribus][14] - -Selecting text in Scribus. - -When I hit the Delete key, the entire text string (not just the highlighted page) disappeared. - -![Both pages of text deleted in Scribus][16] - -Both pages of text deleted in Scribus. - -Then something even more interesting happened… I hit Command+Z to undo the deletion. When the text came back, the formatting was messed up. - -![Undo delete restored the text, but with bad formatting.][18] - -Command+Z (undo delete) restored the text, but the formatting was bad. - -### Opening a design file in a text editor - -If you open a Scribus file and an InDesign file in a standard text editor (e.g., TextEdit on a Mac), you will see that the Scribus file is very readable whereas the InDesign file is not. - -You can use TextEdit to make changes to either type of file and save it, but the resulting file is useless. Here's the error I got when I tried re-opening the edited file in InDesign. - -![InDesign error message][20] - -InDesign error message. - -I got much better results when I used Gedit on my Linux Ubuntu machine to edit the Scribus file. I launched Gedit from the command line and voilà, the Scribus file opened, and the changes I made in Gedit were retained. - -![Editing Scribus file in Gedit][22] - -Editing a Scribus file in Gedit. - -![Result of the Gedit edit in Scribus][24] - -Result of the Gedit edit opened in Scribus. - -This could be very useful to a printer that receives a call from a client about a small typo in a project. Instead of waiting to get a new file, the printer could open the Scribus file in Gedit, make the change, and be good to go. - -### Dropping images into a file - -I converted an InDesign doc to an IDML file so I could try dropping in some PDFs using Scribus. It seems Scribus doesn't do this as well as InDesign, as it failed. Instead, I converted my PDFs to JPGs and imported them into Scribus. That worked great. However, when I exported my document as a PDF, I found that the files size was rather large. - -![Huge PDF file][26] - -Exporting Scribus to PDF produced a huge file. - -I'm not sure why this happened—I'll have to investigate it later. - -Do you have any tips for using open source software to edit graphics files? If so, please share them in the comments. - --------------------------------------------------------------------------------- - -via: https://opensource.com/article/18/7/adobe-indesign-open-source-tools - -作者:[Jeff Macharyas][a] -选题:[lujun9972](https://github.com/lujun9972) -译者:[译者ID](https://github.com/译者ID) -校对:[校对者ID](https://github.com/校对者ID) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 - -[a]:https://opensource.com/users/rikki-endsley -[1]:https://www.scribus.net/ -[2]:https://wiki.gnome.org/Apps/Gedit -[3]:https://opensource.com/life/16/8/open-source-alternatives-graphic-design -[4]:https://opensource.com/article/17/3/scripts-adobe-indesign -[5]:/file/402516 -[6]:https://opensource.com/sites/default/files/uploads/1-business_card_designed_in_adobe_indesign_cc.png (Business card in Adobe InDesign) -[7]:/file/402521 -[8]:https://opensource.com/sites/default/files/uploads/2-indesign_.idml_file_opened_in_scribus.png (InDesign IDML file opened in Scribus) -[9]:/file/402531 -[10]:https://opensource.com/sites/default/files/uploads/3-book_layout_in_indesign.png (Book layout in InDesign) -[11]:/file/402536 -[12]:https://opensource.com/sites/default/files/uploads/4-indesign_.idml_file_of_book_opened_in_scribus.png (InDesign IDML file of book layout opened in Scribus) -[13]:/file/402541 -[14]:https://opensource.com/sites/default/files/uploads/5-command-a_in_the_scribus_file.png (Selecting text in Scribus) -[15]:/file/402546 -[16]:https://opensource.com/sites/default/files/uploads/6-deleted_text_in_scribus.png (Both pages of text deleted in Scribus) -[17]:/file/402551 -[18]:https://opensource.com/sites/default/files/uploads/7-command-z_in_scribus.png (Undo delete restored the text, but with bad formatting.) -[19]:/file/402556 -[20]:https://opensource.com/sites/default/files/uploads/8-indesign_error_message.png (InDesign error message) -[21]:/file/402561 -[22]:https://opensource.com/sites/default/files/uploads/9-scribus_edited_in_gedit_on_linux.png (Editing Scribus file in Gedit) -[23]:/file/402566 -[24]:https://opensource.com/sites/default/files/uploads/10-scribus_opens_after_gedit_changes.png (Result of the Gedit edit in Scribus) -[25]:/file/402571 -[26]:https://opensource.com/sites/default/files/uploads/11-large_pdf_size.png (Huge PDF file) diff --git a/sources/tech/20180702 View The Contents Of An Archive Or Compressed File Without Extracting It.md b/sources/tech/20180702 View The Contents Of An Archive Or Compressed File Without Extracting It.md deleted file mode 100644 index bff7f44c63..0000000000 --- a/sources/tech/20180702 View The Contents Of An Archive Or Compressed File Without Extracting It.md +++ /dev/null @@ -1,184 +0,0 @@ -View The Contents Of An Archive Or Compressed File Without Extracting It -====== -![](https://www.ostechnix.com/wp-content/uploads/2018/07/View-The-Contents-Of-An-Archive-Or-Compressed-File-720x340.png) - -In this tutorial, we are going to learn how to view the contents of an Archive and/or Compressed file without actually extracting it in Unix-like operating systems. Before going further, let be clear about Archive and compress files. There is significant difference between both. The Archiving is the process of combining multiple files or folders or both into a single file. In this case, the resulting file is not compressed. The compressing is a method of combining multiple files or folders or both into a single file and finally compress the resulting file. The archive is not a compressed file, but the compressed file can be an archive. Clear? Well, let us get to the topic. - -### View The Contents Of An Archive Or Compressed File Without Extracting It - -Thanks to Linux community, there are many command line applications are available to do it. Let us going to see some of them with examples. - -**1\. Using Vim Editor** - -Vim is not just an editor. Using Vim, we can do numerous things. The following command displays the contents of an compressed archive file without decompressing it. -``` -$ vim ostechnix.tar.gz - -``` - -![][2] - -You can even browse through the archive and open the text files (if there are any) in the archive as well. To open a text file, just put the mouse cursor in-front of the file using arrow keys and hit ENTER to open it. - - -**2\. Using Tar command** - -To list the contents of a tar archive file, run: -``` -$ tar -tf ostechnix.tar -ostechnix/ -ostechnix/image.jpg -ostechnix/file.pdf -ostechnix/song.mp3 - -``` - -Or, use **-v** flag to view the detailed properties of the archive file, such as permissions, file owner, group, creation date etc. -``` -$ tar -tvf ostechnix.tar -drwxr-xr-x sk/users 0 2018-07-02 19:30 ostechnix/ --rw-r--r-- sk/users 53632 2018-06-29 15:57 ostechnix/image.jpg --rw-r--r-- sk/users 156831 2018-06-04 12:37 ostechnix/file.pdf --rw-r--r-- sk/users 9702219 2018-04-25 20:35 ostechnix/song.mp3 - -``` - - -**3\. Using Rar command** - -To view the contents of a rar file, simply do: -``` -$ rar v ostechnix.rar - -RAR 5.60 Copyright (c) 1993-2018 Alexander Roshal 24 Jun 2018 -Trial version Type 'rar -?' for help - -Archive: ostechnix.rar -Details: RAR 5 - -Attributes Size Packed Ratio Date Time Checksum Name ------------ --------- -------- ----- ---------- ----- -------- ---- --rw-r--r-- 53632 52166 97% 2018-06-29 15:57 70260AC4 ostechnix/image.jpg --rw-r--r-- 156831 139094 88% 2018-06-04 12:37 C66C545E ostechnix/file.pdf --rw-r--r-- 9702219 9658527 99% 2018-04-25 20:35 DD875AC4 ostechnix/song.mp3 ------------ --------- -------- ----- ---------- ----- -------- ---- -9912682 9849787 99% 3 - -``` - -**4\. Using Unrar command** - -You can also do the same using **Unrar** command with **l** flag as shown below. -``` -$ unrar l ostechnix.rar - -UNRAR 5.60 freeware Copyright (c) 1993-2018 Alexander Roshal - -Archive: ostechnix.rar -Details: RAR 5 - -Attributes Size Date Time Name ------------ --------- ---------- ----- ---- --rw-r--r-- 53632 2018-06-29 15:57 ostechnix/image.jpg --rw-r--r-- 156831 2018-06-04 12:37 ostechnix/file.pdf --rw-r--r-- 9702219 2018-04-25 20:35 ostechnix/song.mp3 ------------ --------- ---------- ----- ---- -9912682 3 - -``` - -**5\. Using Zip command** - -To view the contents of a zip file without extracting it, use the following zip command: -``` -$ zip -sf ostechnix.zip -Archive contains: -Life advices.jpg -Total 1 entries (597219 bytes) - -``` - -**6. Using Unzip command -** - -You can also use Unzip command with -l flag to display the contents of a zip file like below. -``` -$ unzip -l ostechnix.zip -Archive: ostechnix.zip -Length Date Time Name ---------- ---------- ----- ---- -597219 2018-04-09 12:48 Life advices.jpg ---------- ------- -597219 1 file - -``` - - -**7\. Using Zipinfo command** -``` -$ zipinfo ostechnix.zip -Archive: ostechnix.zip -Zip file size: 584859 bytes, number of entries: 1 --rw-r--r-- 6.3 unx 597219 bx defN 18-Apr-09 12:48 Life advices.jpg -1 file, 597219 bytes uncompressed, 584693 bytes compressed: 2.1% - -``` - -As you can see, the above command displays the contents of the zip file, its permissions, creating date, and percentage of compression etc. - -**8. Using Zcat command -** - -To view the contents of a compressed archive file without extracting it using **zcat** command, we do: -``` -$ zcat ostechnix.tar.gz - -``` - -The zcat is same as “gunzip -c” command. So, you can also use the following command to view the contents of the archive/compressed file: -``` -$ gunzip -c ostechnix.tar.gz - -``` - -**9. Using Zless command -** - -To view the contents of an archive/compressed file using Zless command, simply do: -``` -$ zless ostechnix.tar.gz - -``` - -This command is similar to “less” command where it displays the output page by page. - -**10. Using Less command -** - -As you might already know, the **less** command can be used to open a file for interactive reading, allowing scrolling and search. - -Run the following command to view the contents of an archive/compressed file using less command: -``` -$ less ostechnix.tar.gz - -``` - -And, that’s all for now. You know now how to view the contents of an archive of compressed file using various commands in Linux. Hope you find this useful. More good stuffs to come. Stay tuned! - -Cheers! - - --------------------------------------------------------------------------------- - -via: https://www.ostechnix.com/how-to-view-the-contents-of-an-archive-or-compressed-file-without-extracting-it/ - -作者:[SK][a] -选题:[lujun9972](https://github.com/lujun9972) -译者:[译者ID](https://github.com/译者ID) -校对:[校对者ID](https://github.com/校对者ID) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 - -[a]:https://www.ostechnix.com/author/sk/ -[1]:data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7 -[2]:http://www.ostechnix.com/wp-content/uploads/2018/07/vim.png diff --git a/sources/tech/20180703 10 killer tools for the admin in a hurry.md b/sources/tech/20180703 10 killer tools for the admin in a hurry.md new file mode 100644 index 0000000000..363f401709 --- /dev/null +++ b/sources/tech/20180703 10 killer tools for the admin in a hurry.md @@ -0,0 +1,87 @@ +10 killer tools for the admin in a hurry +====== + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/cloud_tools_hardware.png?itok=PGjJenqT) + +Administering networks and systems can get very stressful when the workload piles up. Nobody really appreciates how long anything takes, and everyone wants their specific thing done yesterday. + +So it's no wonder so many of us are drawn to the open source spirit of figuring out what works and sharing it with everyone. Because, when deadlines are looming, and there just aren't enough hours in the day, it really helps if you can just find free answers you can implement immediately. + +So, without further ado, here's my Swiss Army Knife of stuff to get you out of the office before dinner time. + +### Server configuration and scripting + +Let's jump right in. + +**[NixCraft][1]** +Use the site's internal search function. With more than a decade of regular updates, there's gold to be found here—useful scripts and handy hints that can solve your problem straight away. This is often the second place I look after Google. + +**[Webmin][2]** +This gives you a nice web interface to remotely edit your configuration files. It cuts down on a lot of time spent having to juggle directory paths and `sudo nano`, which is handy when you're handling several customers. + +**[Windows Subsystem for Linux][3]** +The reality of the modern workplace is that most employees are on Windows, while the grown-up gear in the server room is on Linux. So sometimes you find yourself trying to do admin tasks from (gasp) a Windows desktop. + +What do you do? Install a virtual machine? It's actually much faster and far less work to configure if you install the Windows Subsystem for Linux compatibility layer, now available at no cost on Windows 10. + +This gives you a Bash terminal in a window where you can run Bash scripts and Linux binaries on the local machine, have full access to both Windows and Linux filesystems, and mount network drives. It's available in Ubuntu, OpenSUSE, SLES, Debian, and Kali flavors. + +**[mRemoteNG][4]** +This is an excellent SSH and remote desktop client for when you have 100+ servers to manage. + +### Setting up a network so you don't have to do it again + +A poorly planned network is the sworn enemy of the admin who hates working overtime. + +**[IP Addressing Schemes that Scale][5]** +The diabolical thing about running out of IP addresses is that, when it happens, the network's grown large enough that a new addressing scheme is an expensive, time-consuming pain in the proverbial. + +Ain't nobody got time for that! + +At some point, IPv6 will finally arrive to save the day. Until then, these one-size-fits-most IP addressing schemes should keep you going, no matter how many network-connected wearables, tablets, smart locks, lights, security cameras, VoIP headsets, and espresso machines the world throws at us. + +**[Linux Chmod Permissions Cheat Sheet][6]** +A short but sweet cheat sheet of Bash commands to set permissions across the network. This is so when Bill from Customer Service falls for that ransomware scam, you're recovering just his files and not the entire company's. + +**[VLSM Subnet Calculator][7]** +Just put in the number of networks you want to create from an address space and the number of hosts you want per network, and it calculates what the subnet mask should be for everything. + +### Single-purpose Linux distributions + +Need a Linux box that does just one thing? It helps if someone else has already sweated the small stuff on an operating system you can install and have ready immediately. + +Each of these has, at one point, made my work day so much easier. + +**[Porteus Kiosk][8]** +This is for when you want a computer totally locked down to just a web browser. With a little tweaking, you can even lock the browser down to just one website. This is great for public access machines. It works with touchscreens or with a keyboard and mouse. + +**[Parted Magic][9]** +This is an operating system you can boot from a USB drive to partition hard drives, recover data, and run benchmarking tools. + +**[IPFire][10]** +Hahahaha, I still can't believe someone called a router/firewall/proxy combo "I pee fire." That's my second favorite thing about this Linux distribution. My favorite is that it's a seriously solid software suite. It's so easy to set up and configure, and there is a heap of plugins available to extend it. + +So, how about you? What tools, resources, and cheat sheets have you found to make the workday easier? I'd love to know. Please share in the comments. + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/7/tools-admin + +作者:[Grant Hamono][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://opensource.com/users/grantdxm +[1]:https://www.cyberciti.biz/ +[2]:http://www.webmin.com/ +[3]:http://wsl-guide.org/en/latest/ +[4]:https://mremoteng.org/ +[5]:https://blog.dxmtechsupport.com.au/ip-addressing-for-a-small-business-that-might-grow/ +[6]:https://isabelcastillo.com/linux-chmod-permissions-cheat-sheet +[7]:http://www.vlsm-calc.net/ +[8]:http://porteus-kiosk.org/ +[9]:https://partedmagic.com/ +[10]:https://www.ipfire.org/ diff --git a/sources/tech/20180703 Install Oracle VirtualBox On Ubuntu 18.04 LTS Headless Server.md b/sources/tech/20180703 Install Oracle VirtualBox On Ubuntu 18.04 LTS Headless Server.md new file mode 100644 index 0000000000..dd8c3cdb13 --- /dev/null +++ b/sources/tech/20180703 Install Oracle VirtualBox On Ubuntu 18.04 LTS Headless Server.md @@ -0,0 +1,320 @@ +Install Oracle VirtualBox On Ubuntu 18.04 LTS Headless Server +====== + +![](https://www.ostechnix.com/wp-content/uploads/2016/07/Install-Oracle-VirtualBox-On-Ubuntu-18.04-720x340.png) + +This step by step tutorial walk you through how to install **Oracle VirtualBox** on Ubuntu 18.04 LTS headless server. And, this guide also describes how to manage the VirtualBox headless instances using **phpVirtualBox** , a web-based front-end tool for VirtualBox. The steps described below might also work on Debian, and other Ubuntu derivatives such as Linux Mint. Let us get started. + +### Prerequisites + +Before installing Oracle VirtualBox, we need to do the following prerequisites in our Ubuntu 18.04 LTS server. + +First of all, update the Ubuntu server by running the following commands one by one. +``` +$ sudo apt update + +$ sudo apt upgrade + +$ sudo apt dist-upgrade + +``` + +Next, install the following necessary packages: +``` +$ sudo apt install build-essential dkms unzip wget + +``` + +After installing all updates and necessary prerequisites, restart the Ubuntu server. +``` +$ sudo reboot + +``` + +### Install Oracle VirtualBox on Ubuntu 18.04 LTS server + +Add Oracle VirtualBox official repository. To do so, edit **/etc/apt/sources.list** file: +``` +$ sudo nano /etc/apt/sources.list + +``` + +Add the following lines. + +Here, I will be using Ubuntu 18.04 LTS, so I have added the following repository. +``` +deb http://download.virtualbox.org/virtualbox/debian bionic contrib + +``` + +![][2] + +Replace the word **‘bionic’** with your Ubuntu distribution’s code name, such as ‘xenial’, ‘vivid’, ‘utopic’, ‘trusty’, ‘raring’, ‘quantal’, ‘precise’, ‘lucid’, ‘jessie’, ‘wheezy’, or ‘squeeze**‘.** + +Then, run the following command to add the Oracle public key: +``` +$ wget -q https://www.virtualbox.org/download/oracle_vbox_2016.asc -O- | sudo apt-key add - + +``` + +For VirtualBox older versions, add the following key: +``` +$ wget -q https://www.virtualbox.org/download/oracle_vbox.asc -O- | sudo apt-key add - + +``` + +Next, update the software sources using command: +``` +$ sudo apt update + +``` + +Finally, install latest Oracle VirtualBox latest version using command: +``` +$ sudo apt install virtualbox-5.2 + +``` + +### Adding users to VirtualBox group + +We need to create and add our system user to the **vboxusers** group. You can either create a separate user and assign it to vboxusers group or use the existing user. I don’t want to create a new user, so I added my existing user to this group. Please note that if you use a separate user for virtualbox, you must log out and log in to that particular user and do the rest of the steps. + +I am going to use my username named **sk** , so, I ran the following command to add it to the vboxusers group. +``` +$ sudo usermod -aG vboxusers sk + +``` + +Now, run the following command to check if virtualbox kernel modules are loaded or not. +``` +$ sudo systemctl status vboxdrv + +``` + +![][3] + +As you can see in the above screenshot, the vboxdrv module is loaded and running! + +For older Ubuntu versions, run: +``` +$ sudo /etc/init.d/vboxdrv status + +``` + +If the virtualbox module doesn’t start, run the following command to start it. +``` +$ sudo /etc/init.d/vboxdrv setup + +``` + +Great! We have successfully installed VirtualBox and started virtualbox module. Now, let us go ahead and install Oracle VirtualBox extension pack. + +### Install VirtualBox Extension pack + +The VirtualBox Extension pack provides the following functionalities to the VirtualBox guests. + + * The virtual USB 2.0 (EHCI) device + * VirtualBox Remote Desktop Protocol (VRDP) support + * Host webcam passthrough + * Intel PXE boot ROM + * Experimental support for PCI passthrough on Linux hosts + + + +Download the latest Extension pack for VirtualBox 5.2.x from [**here**][4]. +``` +$ wget https://download.virtualbox.org/virtualbox/5.2.14/Oracle_VM_VirtualBox_Extension_Pack-5.2.14.vbox-extpack + +``` + +Install Extension pack using command: +``` +$ sudo VBoxManage extpack install Oracle_VM_VirtualBox_Extension_Pack-5.2.14.vbox-extpack + +``` + +Congratulations! We have successfully installed Oracle VirtualBox with extension pack in Ubuntu 16.04 LTS server. It is time to deploy virtual machines. Refer the [**virtualbox official guide**][5] to start creating and managing virtual machines in command line. + +Not everyone is command line expert. Some of you might want to create and use virtual machines graphically. No worries! Here is where **phpVirtualBox** comes in handy!! + +### About phpVirtualBox + +**phpVirtualBox** is a free, web-based front-end to Oracle VirtualBox. It is written using PHP language. Using phpVirtualBox, we can easily create, delete, manage and administer virtual machines via a web browser from any remote system on the network. + +### Install phpVirtualBox in Ubuntu 18.04 LTS + +Since it is a web-based tool, we need to install Apache web server, PHP and some php modules. + +To do so, run: +``` +$ sudo apt install apache2 php php-mysql libapache2-mod-php php-soap php-xml + +``` + +Then, Download the phpVirtualBox 5.2.x version from the [**releases page**][6]. Please note that we have installed VirtualBox 5.2, so we must install phpVirtualBox version 5.2 as well. + +To download it, run: +``` +$ wget https://github.com/phpvirtualbox/phpvirtualbox/archive/5.2-0.zip + +``` + +Extract the downloaded archive with command: +``` +$ unzip 5.2-0.zip + +``` + +This command will extract the contents of 5.2.0.zip file into a folder named “phpvirtualbox-5.2-0”. Now, copy or move the contents of this folder to your apache web server root folder. +``` +$ sudo mv phpvirtualbox-5.2-0/ /var/www/html/phpvirtualbox + +``` + +Assign the proper permissions to the phpvirtualbox folder. +``` +$ sudo chmod 777 /var/www/html/phpvirtualbox/ + +``` + +Next, let us configure phpVirtualBox. + +Copy the sample config file as shown below. +``` +$ sudo cp /var/www/html/phpvirtualbox/config.php-example /var/www/html/phpvirtualbox/config.php + +``` + +Edit phpVirtualBox **config.php** file: +``` +$ sudo nano /var/www/html/phpvirtualbox/config.php + +``` + +Find the following lines and replace the username and password with your system user (The same username that we used in “Adding users to VirtualBox group” section). + +In my case, my Ubuntu system username is **sk** , and its password is **ubuntu**. +``` +var $username = 'sk'; +var $password = 'ubuntu'; + +``` + +![][7] + +Save and close the file. + +Next, create a new file called **/etc/default/virtualbox** : +``` +$ sudo nano /etc/default/virtualbox + +``` + +Add the following line. Replace ‘sk’ with your own username. +``` +VBOXWEB_USER=sk + +``` + +Finally, Reboot your system or simply restart the following services to complete the configuration. +``` +$ sudo systemctl restart vboxweb-service + +$ sudo systemctl restart vboxdrv + +$ sudo systemctl restart apache2 + +``` + +### Adjust firewall to allow Apache web server + +By default, the apache web browser can’t be accessed from remote systems if you have enabled the UFW firewall in Ubuntu 18.04 LTS. You must allow the http and https traffic via UFW by following the below steps. + +First, let us view which applications have installed a profile using command: +``` +$ sudo ufw app list +Available applications: +Apache +Apache Full +Apache Secure +OpenSSH + +``` + +As you can see, Apache and OpenSSH applications have installed UFW profiles. + +If you look into the **“Apache Full”** profile, you will see that it enables traffic to the ports **80** and **443** : +``` +$ sudo ufw app info "Apache Full" +Profile: Apache Full +Title: Web Server (HTTP,HTTPS) +Description: Apache v2 is the next generation of the omnipresent Apache web +server. + +Ports: +80,443/tcp + +``` + +Now, run the following command to allow incoming HTTP and HTTPS traffic for this profile: +``` +$ sudo ufw allow in "Apache Full" +Rules updated +Rules updated (v6) + +``` + +If you want to allow https traffic, but only http (80) traffic, run: +``` +$ sudo ufw app info "Apache" + +``` + +### Access phpVirtualBox Web console + +Now, go to any remote system that has graphical web browser. + +In the address bar, type: ****. + +In my case, I navigated to this link – **** + +You should see the following screen. Enter the phpVirtualBox administrative user credentials. + +The default username and phpVirtualBox is **admin** / **admin**. + +![][8] + +Congratulations! You will now be greeted with phpVirtualBox dashboard. + +![][9] + +Now, start creating your VMs and manage them from phpvirtualbox dashboard. As I mentioned earlier, You can access the phpVirtualBox from any system in the same network. All you need is a web browser and the username and password of phpVirtualBox. + +If you haven’t enabled virtualization support in the BISO of host system (not the guest), phpVirtualBox allows you to create 32-bit guests only. To install 64-bit guest systems, you must enable virtualization in your host system’s BIOS. Look for an option that is something like “virtualization” or “hypervisor” in your bios and make sure it is enabled. + +That’s it. Hope this helps. If you find this guide useful, please share it on your social networks and support us. + +More good stuffs to come. Stay tuned! + + +-------------------------------------------------------------------------------- + +via: https://www.ostechnix.com/install-oracle-virtualbox-ubuntu-16-04-headless-server/ + +作者:[SK][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.ostechnix.com/author/sk/ +[1]:data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7 +[2]:http://www.ostechnix.com/wp-content/uploads/2016/07/Add-VirtualBox-repository.png +[3]:http://www.ostechnix.com/wp-content/uploads/2016/07/vboxdrv-service.png +[4]:https://www.virtualbox.org/wiki/Downloads +[5]:http://www.virtualbox.org/manual/ch08.html +[6]:https://github.com/phpvirtualbox/phpvirtualbox/releases +[7]:http://www.ostechnix.com/wp-content/uploads/2016/07/phpvirtualbox-config.png +[8]:http://www.ostechnix.com/wp-content/uploads/2016/07/phpvirtualbox-1.png +[9]:http://www.ostechnix.com/wp-content/uploads/2016/07/phpvirtualbox-2.png diff --git a/sources/tech/20180704 BASHing data- Truncated data items.md b/sources/tech/20180704 BASHing data- Truncated data items.md new file mode 100644 index 0000000000..33a9dd636b --- /dev/null +++ b/sources/tech/20180704 BASHing data- Truncated data items.md @@ -0,0 +1,107 @@ +BASHing data: Truncated data items +====== +### Truncated data items + +**truncated** (adj.): abbreviated, abridged, curtailed, cut off, clipped, cropped, trimmed... + +One way to truncate a data item is to enter it into a database field that has a character limit shorter than the data item. For example, the string + +>Yarrow Ravine Rattlesnake Habitat Area, 2 mi ENE of Yermo CA + +is 60 characters long. If you enter it into a "Locality" field with a 50-character limit, you get + +>Yarrow Ravine Rattlesnake Habitat Area, 2 mi ENE #Ends with a whitespace + +Truncations can also be data entry errors. You meant to enter + +>Sally Ann Hunter (aka Sally Cleveland) + +but you forgot the closing bracket + +>Sally Ann Hunter (aka Sally Cleveland + +leaving the data user to wonder whether Sally has other aliases that were trimmed off the data item. + +Truncated data items are very difficult to detect. When auditing data I use three different methods to find possible truncations, but I probably miss some. + +**Item length distribution.** The first method catches most of the truncations I find in individual fields. I pass the field to an AWK command that tallies up data items by field width, then I use **sort** to print the tallies in reverse order of width. For example, to check field 33 in the tab-separated file "midges": + +``` +awk -F"\t" 'NR>1 {a[length($33)]++} \ +END {for (i in a) print i FS a[i]}' midges | sort -nr +``` + +![distro1][1] + +The longest entries have exactly 50 characters, which is suspicious, and there's a "bulge" of data items at that width, which is even more suspicious. Inspection of those 50-character-wide items reveals truncations: + +![distro2][2] + +Other tables I've checked this way had bulges at 100, 200 and 255 characters. In each case the bulges contained apparent truncations. + +**Unmatched brackets**. The second method looks for data items like "...(Sally Cleveland" above. A good starting point is a tally of all the punctuation in the data table. Here I'm checking the file "mag2": + +grep -o "[[:punct:]]" file | sort | uniqc + +![punct][3] + +Note that the numbers of opening and closing round brackets in "mag2" aren't equal. To see what's going on, I use the function "unmatched", which takes three arguments and checks all fields in a data table. The first argument is the filename and the second and third are the opening and closing brackets, enclosed in quotes. + +``` +unmatched() +{ +awk -F"\t" -v start="$2" -v end="$3" \ +'{for (i=1;i<=NF;i++) \ +if (split($i,a,start) != split($i,b,end)) \ +print "line "NR", field "i":\n"$i}' "$1" + +} +``` + +"unmatched" reports line number and field number if it finds a mismatch between opening and closing brackets in the field. It relies on AWK's **split** function, which returns the number of elements (including blank space) separated by the splitting character. This number will always be one more than the number of splitters: + +![split][4] + +Here "ummatched" checks the round brackets in "mag2" and finds some likely truncations: + +![unmatched][5] + +I use "unmatched" to locate unmatched round brackets (), square brackets [], curly brackets {} and arrows <>, but the function can be used for any paired punctuation characters. + +**Unexpected endings**. The third method looks for data items that end in a trailing space or a non-terminal punctuation mark, like a comma or a hyphen. This can be done on a single field with **cut** piped to **grep** , or in one step with AWK. Here I'm checking field 47 of the tab-separated table "herp5", and pulling out suspect data items and their line numbers: + +``` +cut -f47 herp5 | grep -n "[ ,;:-]$" + +awk -F"\t" '$47 ~ /[ ,;:-]$/ {print NR": "$47}' herp5 +``` + +![herps5][6] + +The all-fields version of the AWK command for a tab-separated file is: + +``` +awk -F"\t" '{for (i=1;i<=NF;i++) if ($i ~ /[ ,;:-]$/) \ +print "line "NR", field "i":\n"$i}' file +``` + +**Cautionary thoughts**. Truncations also appear during the validation tests I do on fields. For example, I might be checking for plausible 4-digit entries in a "Year" field, and there's a 198 that hints at 198n. Or is it 1898? Truncated data items with their lost characters are mysteries. As a data auditor I can only report (possible) character losses and suggest that the (possibly) missing characters be restored by the data compilers or managers. + +-------------------------------------------------------------------------------- + +via: https://www.polydesmida.info/BASHing/2018-07-04.html + +作者:[polydesmida][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.polydesmida.info/ +[1]:https://www.polydesmida.info/BASHing/img1/2018-07-04_1.png +[2]:https://www.polydesmida.info/BASHing/img1/2018-07-04_2.png +[3]:https://www.polydesmida.info/BASHing/img1/2018-07-04_3.png +[4]:https://www.polydesmida.info/BASHing/img1/2018-07-04_4.png +[5]:https://www.polydesmida.info/BASHing/img1/2018-07-04_5.png +[6]:https://www.polydesmida.info/BASHing/img1/2018-07-04_6.png diff --git a/sources/tech/20180704 Setup Headless Virtualization Server Using KVM In Ubuntu 18.04 LTS.md b/sources/tech/20180704 Setup Headless Virtualization Server Using KVM In Ubuntu 18.04 LTS.md new file mode 100644 index 0000000000..a85a637830 --- /dev/null +++ b/sources/tech/20180704 Setup Headless Virtualization Server Using KVM In Ubuntu 18.04 LTS.md @@ -0,0 +1,332 @@ +Setup Headless Virtualization Server Using KVM In Ubuntu 18.04 LTS +====== + +![](https://www.ostechnix.com/wp-content/uploads/2016/11/kvm-720x340.jpg) + +We already have covered [**setting up Oracle VirtualBox on Ubuntu 18.04**][1] headless server. In this tutorial, we will be discussing how to setup headless virtualization server using **KVM** and how to manage the guest machines from a remote client. As you may know already, KVM ( **K** ernel-based **v** irtual **m** achine) is an open source, full virtualization for Linux. Using KVM, we can easily turn any Linux server in to a complete virtualization environment in minutes and deploy different kind of VMs such as GNU/Linux, *BSD, Windows etc. + +### Setup Headless Virtualization Server Using KVM + +I tested this guide on Ubuntu 18.04 LTS server, however this tutorial will work on other Linux distributions such as Debian, CentOS, RHEL and Scientific Linux. This method will be perfectly suitable for those who wants to setup a simple virtualization environment in a Linux server that doesn’t have any graphical environment. + +For the purpose of this guide, I will be using two systems. + +**KVM virtualization server:** + + * **Host OS** – Ubuntu 18.04 LTS minimal server (No GUI) + * **IP Address of Host OS** : 192.168.225.22/24 + * **Guest OS** (Which we are going to host on Ubuntu 18.04) : Ubuntu 16.04 LTS server + + + +**Remote desktop client :** + + * **OS** – Arch Linux + + + +### Install KVM + +First, let us check if our system supports hardware virtualization. To do so, run the following command from the Terminal: +``` +$ egrep -c '(vmx|svm)' /proc/cpuinfo + +``` + +If the result is **zero (0)** , the system doesn’t support hardware virtualization or the virtualization is disabled in the Bios. Go to your bios and check for the virtualization option and enable it. + +if the result is **1** or **more** , the system will support hardware virtualization. However, you still need to enable the virtualization option in Bios before running the above commands. + +Alternatively, you can use the following command to verify it. You need to install kvm first as described below, in order to use this command. +``` +$ kvm-ok + +``` + +**Sample output:** +``` +INFO: /dev/kvm exists +KVM acceleration can be used + +``` + +If you got the following error instead, you still can run guest machines in KVM, but the performance will be very poor. +``` +INFO: Your CPU does not support KVM extensions +INFO: For more detailed results, you should run this as root +HINT: sudo /usr/sbin/kvm-ok + +``` + +Also, there are other ways to find out if your CPU supports Virtualization or not. Refer the following guide for more details. + +Next, Install KVM and other required packages to setup a virtualization environment in Linux. + +On Ubuntu and other DEB based systems, run: +``` +$ sudo apt-get install qemu-kvm libvirt-bin virtinst bridge-utils cpu-checker + +``` + +Once KVM installed, start libvertd service (If it is not started already): +``` +$ sudo systemctl enable libvirtd + +$ sudo systemctl start libvirtd + +``` + +### Create Virtual machines + +All virtual machine files and other related files will be stored under **/var/lib/libvirt/**. The default path of ISO images is **/var/lib/libvirt/boot/**. + +First, let us see if there is any virtual machines. To view the list of available virtual machines, run: +``` +$ sudo virsh list --all + +``` + +**Sample output:** +``` +Id Name State +---------------------------------------------------- + +``` + +![][3] + +As you see above, there is no virtual machine available right now. + +Now, let us crate one. + +For example, let us create Ubuntu 16.04 Virtual machine with 512 MB RAM, 1 CPU core, 8 GB Hdd. +``` +$ sudo virt-install --name Ubuntu-16.04 --ram=512 --vcpus=1 --cpu host --hvm --disk path=/var/lib/libvirt/images/ubuntu-16.04-vm1,size=8 --cdrom /var/lib/libvirt/boot/ubuntu-16.04-server-amd64.iso --graphics vnc + +``` + +Please make sure you have Ubuntu 16.04 ISO image in path **/var/lib/libvirt/boot/** or any other path you have given in the above command. + +**Sample output:** +``` +WARNING Graphics requested but DISPLAY is not set. Not running virt-viewer. +WARNING No console to launch for the guest, defaulting to --wait -1 + +Starting install... +Creating domain... | 0 B 00:00:01 +Domain installation still in progress. Waiting for installation to complete. +Domain has shutdown. Continuing. +Domain creation completed. +Restarting guest. + +``` + +![][4] + +Let us break down the above command and see what each option do. + + * **–name** : This option defines the name of the virtual name. In our case, the name of VM is **Ubuntu-16.04**. + * **–ram=512** : Allocates 512MB RAM to the VM. + * **–vcpus=1** : Indicates the number of CPU cores in the VM. + * **–cpu host** : Optimizes the CPU properties for the VM by exposing the host’s CPU’s configuration to the guest. + * **–hvm** : Request the full hardware virtualization. + * **–disk path** : The location to save VM’s hdd and it’s size. In our example, I have allocated 8GB hdd size. + * **–cdrom** : The location of installer ISO image. Please note that you must have the actual ISO image in this location. + * **–graphics vnc** : Allows VNC access to the VM from a remote client. + + + +### Access Virtual machines using VNC client + +Now, go to the remote Desktop system. SSH to the Ubuntu server(Virtualization server) as shown below. + +Here, **sk** is my Ubuntu server’s user name and **192.168.225.22** is its IP address. + +Run the following command to find out the VNC port number. We need this to access the Vm from a remote system. +``` +$ sudo virsh dumpxml Ubuntu-16.04 | grep vnc + +``` + +**Sample output:** +``` + + +``` + +![][5] + +Note down the port number **5900**. Install any VNC client application. For this guide, I will be using TigerVnc. TigerVNC is available in the Arch Linux default repositories. To install it on Arch based systems, run: +``` +$ sudo pacman -S tigervnc + +``` + +Type the following SSH port forwarding command from your remote client system that has VNC client application installed. + +Again, **192.168.225.22** is my Ubuntu server’s (virtualization server) IP address. + +Then, open the VNC client from your Arch Linux (client). + +Type **localhost:5900** in the VNC server field and click **Connect** button. + +![][6] + +Then start installing the Ubuntu VM as the way you do in the physical system. + +![][7] + +![][8] + +Similarly, you can setup as many as virtual machines depending upon server hardware specifications. + +Alternatively, you can use **virt-viewer** utility in order to install operating system in the guest machines. virt-viewer is available in the most Linux distribution’s default repositories. After installing virt-viewer, run the following command to establish VNC access to the VM. +``` +$ sudo virt-viewer --connect=qemu+ssh://192.168.225.22/system --name Ubuntu-16.04 + +``` + +### Manage virtual machines + +Managing VMs from the command-line using virsh management user interface is very interesting and fun. The commands are very easy to remember. Let us see some examples. + +To view the list of running VMs, run: +``` +$ sudo virsh list + +``` + +Or, +``` +$ sudo virsh list --all + +``` + +**Sample output:** +``` + Id Name State +---------------------------------------------------- + 2 Ubuntu-16.04 running + +``` + +![][9] + +To start a VM, run: +``` +$ sudo virsh start Ubuntu-16.04 + +``` + +Alternatively, you can use the VM id to start it. + +![][10] + +As you see in the above output, Ubuntu 16.04 virtual machine’s Id is 2. So, in order to start it, just specify its Id like below. +``` +$ sudo virsh start 2 + +``` + +To restart a VM, run: +``` +$ sudo virsh reboot Ubuntu-16.04 + +``` + +**Sample output:** +``` +Domain Ubuntu-16.04 is being rebooted + +``` + +![][11] + +To pause a running VM, run: +``` +$ sudo virsh suspend Ubuntu-16.04 + +``` + +**Sample output:** +``` +Domain Ubuntu-16.04 suspended + +``` + +To resume the suspended VM, run: +``` +$ sudo virsh resume Ubuntu-16.04 + +``` + +**Sample output:** +``` +Domain Ubuntu-16.04 resumed + +``` + +To shutdown a VM, run: +``` +$ sudo virsh shutdown Ubuntu-16.04 + +``` + +**Sample output:** +``` +Domain Ubuntu-16.04 is being shutdown + +``` + +To completely remove a VM, run: +``` +$ sudo virsh undefine Ubuntu-16.04 + +$ sudo virsh destroy Ubuntu-16.04 + +``` + +**Sample output:** +``` +Domain Ubuntu-16.04 destroyed + +``` + +![][12] + +For more options, I recommend you to look into the man pages. +``` +$ man virsh + +``` + +That’s all for now folks. Start playing with your new virtualization environment. KVM virtualization will be opt for research & development and testing purposes, but not limited to. If you have sufficient hardware, you can use it for large production environments. Have fun and don’t forget to leave your valuable comments in the comment section below. + +Cheers! + + + +-------------------------------------------------------------------------------- + +via: https://www.ostechnix.com/setup-headless-virtualization-server-using-kvm-ubuntu/ + +作者:[SK][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.ostechnix.com/author/sk/ +[1]:https://www.ostechnix.com/install-oracle-virtualbox-ubuntu-16-04-headless-server/ +[2]:data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7 +[3]:http://www.ostechnix.com/wp-content/uploads/2016/11/sk@ubuntuserver-_001.png +[4]:http://www.ostechnix.com/wp-content/uploads/2016/11/sk@ubuntuserver-_008-1.png +[5]:http://www.ostechnix.com/wp-content/uploads/2016/11/sk@ubuntuserver-_002.png +[6]:http://www.ostechnix.com/wp-content/uploads/2016/11/VNC-Viewer-Connection-Details_005.png +[7]:http://www.ostechnix.com/wp-content/uploads/2016/11/QEMU-Ubuntu-16.04-TigerVNC_006.png +[8]:http://www.ostechnix.com/wp-content/uploads/2016/11/QEMU-Ubuntu-16.04-TigerVNC_007.png +[9]:http://www.ostechnix.com/wp-content/uploads/2016/11/sk@ubuntuserver-_010-1.png +[10]:http://www.ostechnix.com/wp-content/uploads/2016/11/sk@ubuntuserver-_010-2.png +[11]:http://www.ostechnix.com/wp-content/uploads/2016/11/sk@ubuntuserver-_011-1.png +[12]:http://www.ostechnix.com/wp-content/uploads/2016/11/sk@ubuntuserver-_012.png diff --git a/sources/tech/20180705 5 Reasons Open Source Certification Matters More Than Ever.md b/sources/tech/20180705 5 Reasons Open Source Certification Matters More Than Ever.md new file mode 100644 index 0000000000..dace150f39 --- /dev/null +++ b/sources/tech/20180705 5 Reasons Open Source Certification Matters More Than Ever.md @@ -0,0 +1,49 @@ +5 Reasons Open Source Certification Matters More Than Ever +====== + +![](https://www.linux.com/sites/lcom/files/styles/rendered_file/public/open-source-training_0.jpg?itok=lqkiM56e) +In today’s technology landscape, open source is the new normal, with open source components and platforms driving mission-critical processes and everyday tasks at organizations of all sizes. As open source has become more pervasive, it has also profoundly impacted the job market. Across industries [the skills gap is widening][1], making it ever more difficult to hire people with much needed job skills. In response, the [demand for training and certification is growing][2]. + +In a recent webinar, Clyde Seepersad, General Manager of Training and Certification at The Linux Foundation, discussed the growing need for certification and some of the benefits of obtaining open source credentials. “As open source has become the new normal in everything from startups to Fortune 2000 companies, it is important to start thinking about the career road map, the paths that you can take and how Linux and open source in general can help you reach your career goals,” Seepersad said. + +With all this in mind, this is the first article in a weekly series that will cover: why it is important to obtain certification; what to expect from training options that lead to certification; and how to prepare for exams and understand what your options are if you don’t initially pass them. + +Seepersad pointed to these five reasons for pursuing certification: + + * **Demand for Linux and open source talent.** “Year after year, we do the Linux jobs report, and year after year we see the same story, which is that the demand for Linux professionals exceeds the supply. This is true for the open source market in general,” Seepersad said. For example, certifications such as the [LFCE, LFCS,][3] and [OpenStack administrator exam][4] have made a difference for many people. + + * **Getting the interview.** “One of the challenges that recruiters always reference, especially in the age of open source, is that it can be hard to decide who you want to have come in to the interview,” Seepersad said. “Not everybody has the time to do reference checks. One of the beautiful things about certification is that it independently verifies your skillset.” + + * **Confirming your skills.** “Certification programs allow you to step back, look across what we call the domains and topics, and find those areas where you might be a little bit rusty,” Seepersad said. “Going through that process and then being able to demonstrate skills on the exam shows that you have a very broad skillset, not just a deep skillset in certain areas.” + + * **Confidence.** This is the beauty of performance-based exams,” Seepersad said. “You're working on our live system. You're being monitored and recorded. Your timer is counting down. This really puts you on the spot to demonstrate that you can troubleshoot.” The inevitable result of successfully navigating the process is confidence. + + * **Making hiring decisions.** “As you become more senior in your career, you're going to find the tables turned and you are in the role of making a hiring decision,” Seepersad said. “You're going to want to have candidates who are certified, because you recognize what that means in terms of the skillsets.” + + + + +Although Linux has been around for more than 25 years, “it's really only in the past few years that certification has become a more prominent feature,” Seepersad noted. As a matter of fact, 87 percent of hiring managers surveyed for the [2018 Open Source Jobs Report][5] cite difficulty in finding the right open source skills and expertise. The Jobs Report also found that hiring open source talent is a priority for 83 percent of hiring managers, and half are looking for candidates holding certifications. + +With certification playing a more important role in securing a rewarding long-term career, are you interested in learning about options for gaining credentials? If so, stay tuned for more information in this series. + +[Learn more about Linux training and certification.][6] + +-------------------------------------------------------------------------------- + +via: https://www.linux.com/blog/sysadmin-cert/2018/7/5-reasons-open-source-certification-matters-more-ever + +作者:[Sam Dean][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.linux.com/users/sam-dean +[1]:https://www.linuxfoundation.org/blog/open-source-skills-soar-in-demand-according-to-2018-jobs-report/ +[2]:https://www.linux.com/blog/os-jobs-report/2018/7/certification-plays-big-role-open-source-hiring +[3]:https://www.linux.com/learn/certification/2018/5/linux-foundation-lfcs-lfce-maja-kraljic +[4]:https://training.linuxfoundation.org/linux-courses/system-administration-training/openstack-administration-fundamentals +[5]:https://www.linuxfoundation.org/publications/open-source-jobs-report-2018/ +[6]:https://training.linuxfoundation.org/certification diff --git a/sources/tech/20180706 Robolinux Lets You Easily Run Linux and Windows Without Dual Booting.md b/sources/tech/20180706 Robolinux Lets You Easily Run Linux and Windows Without Dual Booting.md new file mode 100644 index 0000000000..783aa0bd4e --- /dev/null +++ b/sources/tech/20180706 Robolinux Lets You Easily Run Linux and Windows Without Dual Booting.md @@ -0,0 +1,141 @@ +Robolinux Lets You Easily Run Linux and Windows Without Dual Booting +====== + +![](https://www.linux.com/sites/lcom/files/styles/rendered_file/public/robolinux-main.jpg?itok=zsMPdGsP) + +The number of Linux distributions available just keeps getting bigger. In fact, in the time it took me to write this sentence, another one may have appeared on the market. Many Linux flavors have trouble standing out in this crowd, and some are just a different combination of puzzle pieces joined to form something new: An Ubuntu base with a KDE desktop environment. A Debian base with an Xfce desktop. The combinations go on and on. + +[Robolinux][1], however, does something unique. It’s the only distro, to my knowledge, that makes working with Windows alongside Linux a little easier for the typical user. With just a few clicks, it lets you create a Windows virtual machine (by way of VirtualBox) that can run side by side with Linux. No more dual booting. With this process, you can have Windows XP, Windows 7, or Windows 10 up and running with ease. + +And, you get all this on top of an operating system that’s pretty fantastic on its own. Robolinux not only makes short work of having Windows along for the ride, it simplifies using Linux itself. Installation is easy, and the installed collection of software means anyone can be productive right away. + +Let’s install Robolinux and see what there is to see. + +### Installation + +As I mentioned earlier, installing Robolinux is easy. Obviously, you must first [download an ISO][2] image of the operating system. You have the choice of installing a Cinnamon, Mate, LXDE, or xfce desktop (I opted to go the Mate route). I will warn you, the developers do make a pretty heavy-handed plea for donations. I don’t fault them for this. Developing an operating system takes a great deal of time. So if you have the means, do make a donation. +Once you’ve downloaded the file, burn it to a CD/DVD or flash drive. Boot your system with the media and then, once the desktop loads, click the Install icon on the desktop. As soon as the installer opens (Figure 1), you should be immediately familiar with the layout of the tool. + +![Robolinux installer][4] + +Figure 1: The Robolinux installer is quite user-friendly. + +[Used with permission][5] + +Once you’ve walked through the installer, reboot, remove the installation media, and login when prompted. I will say that I installed Robolinux as a VirtualBox VM and it installed to perfection. This however, isn’t a method you should use, if you’re going to take advantage of the Stealth VM option. After logging in, the first thing I did was install the Guest Additions and everything was working smoothly. + +### Default applications + +The collection of default applications is impressive, but not overwhelming. You’ll find all the standard tools to get your work done, including: + + * LibreOffice + + * Atril Document Viewer + + * Backups + + * GNOME Disks + + * Medit text editor + + * Seahorse + + * GIMP + + * Shotwell + + * Simple Scan + + * Firefox + + * Pidgen + + * Thunderbird + + * Transmission + + * Brasero + + * Cheese + + * Kazam + + * Rhythmbox + + * VLC + + * VirtualBox + + * And more + + + + +With that list of software, you shouldn’t want for much. However, should you find a app not installed, click on the desktop menu button and then click Package Manager, which will open Synaptic Package Manager, where you can install any of the Linux software you need. + +If that’s not enough, it’s time to take a look at the Windows side of things. + +### Installing Windows + +This is what sets Robolinux apart from other Linux distributions. If you click on the desktop menu button, you see a Stealth VM entry. Within that sub-menu, a listing of the different Windows VMs that can be installed appears (Figure 2). + +![Windows VMs][7] + +Figure 2: The available Windows VMs that can be installed alongside of Robolinux. + +[Used with permission][5] + +Before you can install one of the VMs, you must first download the Stealth VM file. To do that, double-click on the desktop icon that includes an image of the developer’s face (labeled Robo’s FREE Stealth VM). You must save that file to the ~/Downloads directory. Don’t save it anywhere else, don’t extract it, and don’t rename it. With that file in place, click the start menu and then click Stealth VM. From the listing, click the top entry, Robolinx Stealth VM Installer. When prompted, type your sudo password. You will then be prompted that the Stealth VM is ready to be used. Go back to the start menu and click Stealth VM and select the version of Windows you want to install. A new window will appear (Figure 3). Click Yes and the installation will continue. + +![Installing Windows][9] + +Figure 3: Installing Windows in the Stealth VM. + +[Used with permission][5] + +Next you will be prompted to type your sudo password again (so your user can be added to the vboxusers group). Once you’ve taken care of that, you’ll be prompted to configure the RAM you want to dedicate to the VM. After that, a browser window will appear (once again asking for a donation). At this point everything is (almost) done. Close the browser and the terminal window. + +You’re not finished. + +Next you must insert the Windows installer media that matches the type of Windows VM you installed. You then must start VirtualBox by click start menu > System Tools > Oracle VM VirtualBox. When VirtualBox opens, an entry will already be created for your Windows VM (Figure 4). + +![Windows VM][11] + +Figure 4: Your Windows VM is ready to go. + +[Used with permission][5] + +You can now click the Start button (in VirtualBox) to finish up the installation. When the Windows installation completes, you’re ready to work with Linux and Windows side-by-side. + +### Making VMs a bit more user-friendly + +You may be thinking to yourself, “Creating a virtual machine for Windows is actually easier than that!”. Although you are correct with that sentiment, not everyone knows how to create a new VM with VirtualBox. In the time it took me to figure out how to work with the Robolinux Stealth VM, I could have had numerous VMs created in VirtualBox. Additionally, this approach doesn’t happen free of charge. You do still have to have a licensed copy of Windows (as well as the installation media). But anything developers can do to make using Linux easier is a plus. That’s how I see this—a Linux distribution doing something just slightly different that could remove a possible barrier to entry for the open source platform. From my perspective, that’s a win-win. And, you’re getting a pretty solid Linux distribution to boot. + +If you already know the ins and outs of VirtualBox, Robolinux might not be your cuppa. But, if you don’t like technology getting in the way of getting your work done and you want to have a Linux distribution that includes all the necessary tools to help make you productive, Robolinux is definitely worth a look. + +Learn more about Linux through the free ["Introduction to Linux" ][12] course from The Linux Foundation and edX. + +-------------------------------------------------------------------------------- + +via: https://www.linux.com/learn/intro-to-linux/2018/7/robolinux-lets-you-easily-run-linux-and-windows-without-dual-booting + +作者:[Jack Wallen][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.linux.com/users/jlwallen +[1]:https://www.robolinux.org +[2]:https://www.robolinux.org/downloads/ +[3]:/files/images/robolinux1jpg +[4]:https://www.linux.com/sites/lcom/files/styles/rendered_file/public/robolinux_1.jpg?itok=MA0MD6KY (Robolinux installer) +[5]:/licenses/category/used-permission +[6]:/files/images/robolinux2jpg +[7]:https://www.linux.com/sites/lcom/files/styles/rendered_file/public/robolinux_2.jpg?itok=bHktIhhK (Windows VMs) +[8]:/files/images/robolinux3jpg +[9]:https://www.linux.com/sites/lcom/files/styles/rendered_file/public/robolinux_3.jpg?itok=B7ar6hZf (Installing Windows) +[10]:/files/images/robolinux4jpg +[11]:https://www.linux.com/sites/lcom/files/styles/rendered_file/public/robolinux_4.jpg?itok=nEOt5Vnc (Windows VM) +[12]:https://training.linuxfoundation.org/linux-courses/system-administration-training/introduction-to-linux diff --git a/sources/tech/20180706 Using Ansible to set up a workstation.md b/sources/tech/20180706 Using Ansible to set up a workstation.md new file mode 100644 index 0000000000..cc9e63b2d8 --- /dev/null +++ b/sources/tech/20180706 Using Ansible to set up a workstation.md @@ -0,0 +1,168 @@ +Using Ansible to set up a workstation +====== + +![](https://fedoramagazine.org/wp-content/uploads/2018/07/ansible-workstation-816x345.png) + +Ansible is an extremely popular [open-source configuration management and software automation project][1]. While IT professionals almost certainly use Ansible on a daily basis, its influence outside the IT industry is not as wide. Ansible is a powerful and flexible tool. It is easily applied to a task common to nearly every desktop computer user: the post-installation “checklist”. + +Most users like to apply one “tweak” after a new installation. Ansible’s idempotent, declarative syntax lends itself perfectly to describing how a system should be configured. + +### Ansible in a nutshell + +The _ansible_ program itself performs a **single task** against a set of hosts. This is roughly conceptualized as: +``` +for HOST in $HOSTS; do + ssh $HOST /usr/bin/echo "Hello World" +done + +``` + +To perform more than one task, Ansible defines the concept of a “playbook”. A playbook is a YAML file describing the _state_ of the targeted machine. When run, Ansible inspects each host and performs only the tasks necessary to enforce the state defined in the playbook. +``` +- hosts: all + tasks: + - name: Echo "Hello World" + command: echo "Hello World" + +``` + +Run the playbook using the _ansible-playbook_ command: +``` +$ ansible-playbook ~/playbook.yml + +``` + +### Configuring a workstation + +Start by installing ansible: +``` +dnf install ansible + +``` + +Next, create a file to store the playbook: +``` +touch ~/post_install.yml + +``` + +Start by defining the host on which to run this playbook. In this case, “localhost”: +``` +- hosts: localhost + +``` + +Each task consists of a _name_ field and a module field. Ansible has **a lot** of [modules][2]. Be sure to browse the module index to become familiar with all Ansible has to offer. + +#### The package module + +Most users install additional packages after a fresh install, and many like to remove some shipped software they don’t use. The _[package][3]_ module provides a generic wrapper around the system package manager (in Fedora’s case, _dnf_ ). +``` +- hosts: localhost + tasks: + - name: Install Builder + become: yes + package: + name: gnome-builder + state: present + - name: Remove Rhythmbox + become: yes + package: + name: rhythmbox + state: absent + - name: Install GNOME Music + become: yes + package: + name: gnome-music + state: present + - name: Remove Shotwell + become: yes + package: + name: shotwell + state: absent +``` + +This playbook results in the following outcomes: + + * GNOME Builder and GNOME Music are installed + * Rhythmbox is removed + * On Fedora 28 or greater, nothing happens with Shotwell (it is not in the default list of packages) + * On Fedora 27 or older, Shotwell is removed + + + +This playbook also introduces the **become: yes** directive. This specifies the task must be run by a privileged user (in most cases, _root_ ). + +#### The DConf Module + +Ansible can do a lot more than install software. For example, GNOME includes a great color-shifting feature called Night Light. It ships disabled by default, however the Ansible _[dconf][4]_ module can very easily enable it. +``` +- hosts: localhost + tasks: + - name: Enable Night Light + dconf: + key: /org/gnome/settings-daemon/plugins/color/night-light-enabled + value: true + - name: Set Night Light Temperature + dconf: + key: /org/gnome/settings-daemon/plugins/color/night-light-temperature + value: uint32 5500 +``` + +Ansible can also create files at specified locations with the _[copy][5]_ module. In this example, a local file is copied to the destination path. +``` +- hosts: localhost + tasks: + - name: Enable "AUTH_ADMIN_KEEP" for pkexec + become: yes + copy: + src: files/51-pkexec-auth-admin-keep.rules + dest: /etc/polkit-1/rules.d/51-pkexec-auth-admin-keep.rules + +``` + +#### The Command Module + +Ansible can still run commands even if no specialized module exists (via the aptly named _[command][6]_ module). This playbook enables the [Flathub][7] repository and installs a few Flatpaks. The commands are crafted in such a way that they are effectively idempotent. This is an important behavior to consider; a playbook should succeed each time it is run on a machine. +``` +- hosts: localhost + tasks: + - name: Enable Flathub repository + become: yes + command: flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo + - name: Install Fractal + become: yes + command: flatpak install --assumeyes flathub org.gnome.Fractal + - name: Install Spotify + become: yes + command: flatpak install --assumeyes flathub com.spotify.Client +``` + +Combine all these tasks together into a single playbook and, in one command, ** Ansible will customize a freshly installed workstation. Not only that, but 6 months later, after making changes to the playbook, run it again to bring a “seasoned” install back to a known state. +``` +$ ansible-playbook -K ~/post_install.yml + +``` + +This article only touched the surface of what’s possible with Ansible. A follow-up article will go into more advanced Ansible concepts such as _roles,_ configuring multiple hosts with a divided set of responsibilities. + + +-------------------------------------------------------------------------------- + +via: https://fedoramagazine.org/using-ansible-setup-workstation/ + +作者:[Link Dupont][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://fedoramagazine.org/author/linkdupont/ +[1]:https://ansible.com +[2]:https://docs.ansible.com/ansible/latest/modules/list_of_all_modules.html +[3]:https://docs.ansible.com/ansible/latest/modules/package_module.html#package-module +[4]:https://docs.ansible.com/ansible/latest/modules/dconf_module.html#dconf-module +[5]:https://docs.ansible.com/ansible/latest/modules/copy_module.html#copy-module +[6]:https://docs.ansible.com/ansible/latest/modules/command_module.html#command-module +[7]:https://flathub.org diff --git a/sources/tech/20180708 simple and elegant free podcast player.md b/sources/tech/20180708 simple and elegant free podcast player.md new file mode 100644 index 0000000000..72e35c7029 --- /dev/null +++ b/sources/tech/20180708 simple and elegant free podcast player.md @@ -0,0 +1,119 @@ +simple and elegant free podcast player +====== + +![](https://i0.wp.com/www.linuxlinks.com/wp-content/uploads/2018/07/CPod-Subscriptions.jpg?resize=750%2C393&ssl=1) + +CPod (formerly known as Cumulonimbus) is a cross-platform, open source podcast player for the desktop. The application is built with web technologies – it’s written in the JavaScript programming language and uses the Electron framework. Electron is often (rightly?) criticized for being a memory hog and dog slow. But is that mainly because of poor programming, rather than an inherent flaw in the technology? + +CPod is available for Linux, Mac OS, and Windows. Installation was a breeze on my Ubuntu 18.04 distribution as the author conveniently provides a 64-bit deb package. If you don’t run a Debian/Ubuntu based distro, there’s an AppImage which effortlessly installs the software on all major Linux distributions. There’s also a snap package from the snapcraft website, but bizarrely (and incorrectly) flags the software as proprietary software. As CPod is released under an open source license, there’s the full source code available too. + +The deb package installs the software to /opt/CPod, although the binary is still called cumulonimbus. A bit of tidying up needed there. For Mac OS users, there’s an Apple Disk Image file. + +### Home + +![CPod Playlist][2] +First off, you cannot fail to notice the gorgeous attractive interface. Presentation is first class. + +First off, you cannot fail to notice the gorgeous attractive interface. Presentation is first class. + +The home section shows your subscribed podcasts. There are helpful filters at the top. They let you select podcasts of specified duration (handy if time is limited), you can filter by date, filter for podcasts that you’ve downloaded an offline copy, as well as podcasts that have not been listened to, you’ve started listening to, and podcasts you’ve heard to the end. + +Below the filters, there’s the option to select multiple podcasts, download local copies, add podcasts to your queue, as well as actually playing a podcast. The interface is remarkably intuitive. + +One quirk is that offline episodes are downloaded to the directory ~/.config/cumulonimbus/offline_episodes/. The downloaded podcasts are therefore not visible in the Files file manager by default (this is because the standard installation of Files does not display ‘hidden files’). It’s easy to enable hidden files in the file manager. Good news, the developer plans to add a configurable default download directory. + +There’s lots of nice touches which enhance the user experience, such as the progress bars when downloading episodes. + +### Playing a podcast + +![CPod][3] + +Here’s one of my favourite podcasts, Ubuntu Podcast, in playback. There’s visualization effects enabled; they only show when the window has focus. The visualizations don’t always display properly. There’s also the option of changing the playback speed (0.5x – 4x speed). I’m not sure why I’d want to change the playback speed though. Maybe someone could enlighten me? + +More functional is the slider that lets you skip to a specific point of the podcast although this is a tad buggy. The software is in an early stage of development. In any case, I prefer using the keyboard shortcuts to move forwards and backwards, and they work fine. Some podcasts offer links that let you skip to a particular segment; they are displayed in the large pane. + +There’s also the ability to watch video podcasts in both fullscreen and window mode. I spend most of my time listening to audio podcasts, but having full screen video podcasts is a pretty cool feature. Video playback is powered by ffmpeg. + +### Queue + +![CPod Queue][4] +There’s not much to say about the queue functionality, but it’s worth noting you can change the order of episodes simply by dragging and dropping them in the interface. It’s well implemented and really simple to use. Another tick for CPod. + +### Subscriptions + +There’s not much to say about the queue functionality, but it’s worth noting you can change the order of episodes simply by dragging and dropping them in the interface. It’s well implemented and really simple to use. Another tick for CPod. + +![CPod Subscriptions][5] + +The interface makes it really easy to subscribe and unsubscribe to podcasts. Clicking the image of a subscribed podcast lets you find an episode, as well as a list of recent episodes, again with the ability to play, queue, and download. It’s all very clean and easy to use. + +### Explore + +In explore you can search for podcasts. Just type some keywords into the Explore dialog box, and you’re presented with a list of podcasts you can listen and subscribe. + +If you’re a fan of YouTube, you’re in luck. There’s the ability to preview and subscribe to YouTube channels by pasting a channel’s URL into the Explore box. That’s great if you have YouTube channel hyperlinks handy, but some sort of YouTube channel finder would be a great addition. + +Here’s a YouTube video in action. + +![CPod YTube][6] + +### Settings + +![CPod Settings][7] + +There’s a lot you can configure in Settings. There’s functionality to: + + * Internationalization support – the ability to select the language displayed. Currently, there’s fairly limited support in this respect. Besides English, there’s Chinese, French, German, Korean, Portuguese, Portuguese (Brazilian), and Spanish available. Contributing translations is probably the easiest way for non-programmers to contribute to an open source project. + * Option to group episodes in Home by day or month. + * Keyboard shortcuts that let you skip backward, skip forward, and play/pause playback. I love my keyboard shortcuts. + * Configure different lengths of forward/backward skip. + * Enable waveform visualization – you can see examples of the visualization in our images (Playlist and Subscription sections). + * Basic gpodder.net integration (currently only subscriptions and device sync are supported; other functionality such as episodes actions and queue are planned). + * Allow pre-releases when auto-updating. + * Export subscriptions to OPML – Outline Processor Markup Language is an XML format commonly used to exchange lists of web feeds between web feed aggregators. + * Import subscriptions from OPML. + * Update podcast cover art. + * View offline episodes directory. + + + +The software has a bag of neat touches. For example, if I change the language setting, the software presents a pop up saying CPod needs to be restarted for the change to take effect. All very user-friendly. + +The Media Player Remote Interfacing Specification (MPRIS) is a standard D-Bus interface which aims to provide a common programmatic API for controlling media players. CPod offers basic MPRIS integration. + +### Summary + +CPod is another good example of what’s possible with modern web technologies. Sure, it’s got a few quirks, it’s in an early stage of development (read ‘expect to find lots of bugs’), and there’s some useful functionality waiting to be implemented. But I’m using the software on a daily basis, and will definitely keep up-to-date with developments. + +Linux already has some high quality open source podcast players. But CPod is definitely worth a download if you’re passionate about podcasts. + +**Website:** [**github.com/z————-/CPod**][8] +**Support:** +**Developer:** Zack Guard +**License:** Apache License 2.0 + +Zack Guard, CPod’s developer, is a student who lives in Hong Kong. You can buy him a coffee at ****. Unfortunately, I’m an impoverished student too. + +### Related + + +-------------------------------------------------------------------------------- + +via: https://www.linuxlinks.com/cpod-simple-elegant-free-podcast-player/ + +作者:[Luke Baker][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.linuxlinks.com/author/luke-baker/ +[1]:https://www.linuxlinks.com/wp-content/plugins/jetpack/modules/lazy-images/images/1x1.trans.gif +[2]:https://i2.wp.com/www.linuxlinks.com/wp-content/uploads/2018/07/CPod-Playlist.jpg?resize=750%2C368&ssl=1 +[3]:https://i0.wp.com/www.linuxlinks.com/wp-content/uploads/2018/07/CPod-Main.jpg?resize=750%2C368&ssl=1 +[4]:https://i0.wp.com/www.linuxlinks.com/wp-content/uploads/2018/07/CPod-Queue.jpg?resize=750%2C368&ssl=1 +[5]:https://i0.wp.com/www.linuxlinks.com/wp-content/uploads/2018/07/CPod-Subscriptions.jpg?resize=750%2C368&ssl=1 +[6]:https://i1.wp.com/www.linuxlinks.com/wp-content/uploads/2018/07/CPod-YouTube.jpg?resize=750%2C368&ssl=1 +[7]:https://i1.wp.com/www.linuxlinks.com/wp-content/uploads/2018/07/CPod-Settings.jpg?resize=750%2C368&ssl=1 +[8]:https://github.com/z-------------/CPod diff --git a/sources/tech/20180709 5 Firefox extensions to protect your privacy.md b/sources/tech/20180709 5 Firefox extensions to protect your privacy.md new file mode 100644 index 0000000000..848856fe07 --- /dev/null +++ b/sources/tech/20180709 5 Firefox extensions to protect your privacy.md @@ -0,0 +1,54 @@ +5 Firefox extensions to protect your privacy +====== + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/biz_cinderblock_cloud_yellowhat.jpg?itok=sJdlsYTF) + +In the wake of the Cambridge Analytica story, I took a hard look at how far I had let Facebook penetrate my online presence. As I'm generally concerned about single points of failure (or compromise), I am not one to use social logins. I use a password manager and create unique logins for every site (and you should, too). + +What I was most perturbed about was the pervasive intrusion Facebook was having on my digital life. I uninstalled the Facebook mobile app almost immediately after diving into the Cambridge Analytica story. I also [disconnected all apps, games, and websites][1] from Facebook. Yes, this will change your experience on Facebook, but it will also protect your privacy. As a veteran with friends spread out across the globe, maintaining the social connectivity of Facebook is important to me. + +I went about the task of scrutinizing other services as well. I checked Google, Twitter, GitHub, and more for any unused connected applications. But I know that's not enough. I need my browser to be proactive in preventing behavior that violates my privacy. I began the task of figuring out how best to do that. Sure, I can lock down a browser, but I need to make the sites and tools I use work while trying to keep them from leaking data. + +Following are five tools that will protect your privacy while using your browser. The first three extensions are available for Firefox and Chrome, while the latter two are only available for Firefox. + +### Privacy Badger + +[Privacy Badger][2] has been my go-to extension for quite some time. Do other content or ad blockers do a better job? Maybe. The problem with a lot of content blockers is that they are "pay for play." Meaning they have "partners" that get whitelisted for a fee. That is the antithesis of why content blockers exist. Privacy Badger is made by the Electronic Frontier Foundation (EFF), a nonprofit entity with a donation-based business model. Privacy Badger promises to learn from your browsing habits and requires minimal tuning. For example, I have only had to whitelist a handful of sites. Privacy Badger also allows granular controls of exactly which trackers are enabled on what sites. It's my #1, must-install extension, no matter the browser. + +### DuckDuckGo Privacy Essentials + +The search engine DuckDuckGo has typically been privacy-conscious. [DuckDuckGo Privacy Essentials][3] works across major mobile devices and browsers. It's unique in the sense that it grades sites based on the settings you give them. For example, Facebook gets a D, even with Privacy Protection enabled. Meanwhile, [chrisshort.net][4] gets a B with Privacy Protection enabled and a C with it disabled. If you're not keen on EFF or Privacy Badger for whatever reason, I would recommend DuckDuckGo Privacy Essentials (choose one, not both, as they essentially do the same thing). + +### HTTPS Everywhere + +[HTTPS Everywhere][5] is another extension from the EFF. According to HTTPS Everywhere, "Many sites on the web offer some limited support for encryption over HTTPS, but make it difficult to use. For instance, they may default to unencrypted HTTP or fill encrypted pages with links that go back to the unencrypted site. The HTTPS Everywhere extension fixes these problems by using clever technology to rewrite requests to these sites to HTTPS." While a lot of sites and browsers are getting better about implementing HTTPS, there are a lot of sites that still need help. HTTPS Everywhere will try its best to make sure your traffic is encrypted. + +### NoScript Security Suite + +[NoScript Security Suite][6] is not for the faint of heart. While the Firefox-only extension "allows JavaScript, Java, Flash, and other plugins to be executed only by trusted websites of your choice," it doesn't do a great job at figuring out what your choices are. But, make no mistake, a surefire way to prevent leaking data is not executing code that could leak it. NoScript enables that via its "whitelist-based preemptive script blocking." This means you will need to build the whitelist as you go for sites not already on it. Note that NoScript is only available for Firefox. + +### Facebook Container + +[Facebook Container][7] makes Firefox the only browser where I will use Facebook. "Facebook Container works by isolating your Facebook identity into a separate container that makes it harder for Facebook to track your visits to other websites with third-party cookies." This means Facebook cannot snoop on activity happening elsewhere in your browser. Suddenly those creepy ads will stop appearing so frequently (assuming you uninstalled the Facebook app from your mobile devices). Using Facebook in an isolated space will prevent any additional collection of data. Remember, you've given Facebook data already, and Facebook Container can't prevent that data from being shared. + +These are my go-to extensions for browser privacy. What are yours? Please share them in the comments. + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/7/firefox-extensions-protect-privacy + +作者:[Chris Short][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://opensource.com/users/chrisshort +[1]:https://www.facebook.com/help/211829542181913 +[2]:https://www.eff.org/privacybadger +[3]:https://duckduckgo.com/app +[4]:https://chrisshort.net +[5]:https://www.eff.org/https-everywhere +[6]:https://noscript.net/ +[7]:https://addons.mozilla.org/en-US/firefox/addon/facebook-container/ diff --git a/sources/tech/20180709 Anbox- How To Install Google Play Store And Enable ARM (libhoudini) Support, The Easy Way.md b/sources/tech/20180709 Anbox- How To Install Google Play Store And Enable ARM (libhoudini) Support, The Easy Way.md new file mode 100644 index 0000000000..f390109123 --- /dev/null +++ b/sources/tech/20180709 Anbox- How To Install Google Play Store And Enable ARM (libhoudini) Support, The Easy Way.md @@ -0,0 +1,101 @@ +Anbox: How To Install Google Play Store And Enable ARM (libhoudini) Support, The Easy Way +====== +**[Anbox][1], or Android in a Box, is a free and open source tool that allows running Android applications on Linux.** It works by running the Android runtime environment in an LXC container, recreating the directory structure of Android as a mountable loop image, while using the native Linux kernel to execute applications. + +Its key features are security, performance, integration and convergence (scales across different form factors), according to its website. + +**Using Anbox, each Android application or game is launched in a separate window, just like system applications** , and they behave more or less like regular windows, showing up in the launcher, can be tiled, etc. + +By default, Anbox doesn't ship with the Google Play Store or support for ARM applications. To install applications you must download each app APK and install it manually using adb. Also, installing ARM applications or games doesn't work by default with Anbox - trying to install ARM apps results in the following error being displayed: +``` +Failed to install PACKAGE.NAME.apk: Failure [INSTALL_FAILED_NO_MATCHING_ABIS: Failed to extract native libraries, res=-113] + +``` + +You can set up both Google Play Store and support for ARM applications (through libhoudini) manually for Android in a Box, but it's a quite complicated process. **To make it easier to install Google Play Store and Google Play Services on Anbox, and get it to support ARM applications and games (using libhoudini), the folks at[geeks-r-us.de][2] (linked article is in German) have created a [script][3] that automates these tasks.** + +Before using this, I'd like to make it clear that not all Android applications and games work in Anbox, even after integrating libhoudini for ARM support. Some Android applications and games may not show up in the Google Play Store at all, while others may be available for installation but will not work. Also, some features may not be available in some applications. + +### Install Google Play Store and enable ARM applications / games support on Anbox (Android in a Box) + +These instructions will obviously not work if Anbox is not already installed on your Linux desktop. If you haven't already, install Anbox by following the installation instructions found + +`anbox.appmgr` + +at least once after installing Anbox and before using this script, to avoid running into issues. + +1\. Install the required dependencies (`wget` , `lzip` , `unzip` and `squashfs-tools`). + +In Debian, Ubuntu or Linux Mint, use this command to install the required dependencies: +``` +sudo apt install wget lzip unzip squashfs-tools + +``` + +2\. Download and run the script that automatically downloads and installs Google Play Store (and Google Play Services) and libhoudini (for ARM apps / games support) on your Android in a Box installation. + +**Warning: never run a script you didn't write without knowing what it does. Before running this script, check out its [code][4]. ** + +To download the script, make it executable and run it on your Linux desktop, use these commands in a terminal: +``` +wget https://raw.githubusercontent.com/geeks-r-us/anbox-playstore-installer/master/install-playstore.sh +chmod +x install-playstore.sh +sudo ./install-playstore.sh + +``` + +3\. To get Google Play Store to work in Anbox, you need to enable all the permissions for both Google Play Store and Google Play Services + +To do this, run Anbox: +``` +anbox.appmgr + +``` + +Then go to `Settings > Apps > Google Play Services > Permissions` and enable all available permissions. Do the same for Google Play Store! + +You should now be able to login using a Google account into Google Play Store. + +Without enabling all permissions for Google Play Store and Google Play Services, you may encounter an issue when trying to login to your Google account, with the following error message: " _Couldn't sign in. There was a problem communicating with Google servers. Try again later_ ", as you can see in this screenshot: + +After logging in, you can disable some of the Google Play Store / Google Play Services permissions. + +**If you're encountering some connectivity issues when logging in to your Google account on Anbox,** make sure the `anbox-bride.sh` is running: + + * to start it: + + +``` +sudo /snap/anbox/current/bin/anbox-bridge.sh start + +``` + + * to restart it: + + +``` +sudo /snap/anbox/current/bin/anbox-bridge.sh restart + +``` + +You may also need to install the dnsmasq package if you continue to have connectivity issues with Anbox, according to + + +-------------------------------------------------------------------------------- + +via: https://www.linuxuprising.com/2018/07/anbox-how-to-install-google-play-store.html + +作者:[Logix][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://plus.google.com/118280394805678839070 +[1]:https://anbox.io/ +[2]:https://geeks-r-us.de/2017/08/26/android-apps-auf-dem-linux-desktop/ +[3]:https://github.com/geeks-r-us/anbox-playstore-installer/ +[4]:https://github.com/geeks-r-us/anbox-playstore-installer/blob/master/install-playstore.sh +[5]:https://docs.anbox.io/userguide/install.html +[6]:https://github.com/anbox/anbox/issues/118#issuecomment-295270113 diff --git a/sources/tech/20180710 The aftermath of the Gentoo GitHub hack.md b/sources/tech/20180710 The aftermath of the Gentoo GitHub hack.md new file mode 100644 index 0000000000..fc9ff4b4e5 --- /dev/null +++ b/sources/tech/20180710 The aftermath of the Gentoo GitHub hack.md @@ -0,0 +1,72 @@ +The aftermath of the Gentoo GitHub hack +====== + +![](https://images.idgesg.net/images/article/2018/07/gentoo_penguins-100763422-large.jpg) + +### Gentoo GitHub hack: What happened? + +Late last month (June 28), the Gentoo GitHub repository was attacked after someone gained control of an admin account. All access to the repositories was soon removed from Gentoo developers. Repository and page content were altered. But within 10 minutes of the attacker gaining access, someone noticed something was going on, 7 minutes later a report was sent, and within 70 minutes the attack was over. Legitimate Gentoo developers were shut out for 5 days while the dust settled and repairs and analysis were completed. + +The attackers also attempted to add "rm -rf" commands to some repositories to cause user data to be recursively removed. As it turns out, this code was unlikely to be run because of technical precautions that were in place, but this wouldn't have been obvious to the attacker. + +One of the things that constrained how big a disaster this break in might have turned out to be was that the attack was "loud." The removal of developers resulted in them being emailed, and developers quickly discovered they'd been shut out. A stealthier attack might have led to a significant delay in anyone responding to the problem and a significantly bigger problem. + +A detailed timeline showing the details of what happened is available at the [Gentoo Linux site][1]. + +### How the Gentoo GitHub attack happened + +Much of the focus in the aftermath of this very significant attack has been on how the attacker was able to gain admin access and what might have been done differently to keep the site safe. The most obvious take-home was that the admin's password was guessed because it too closely related to one that had been captured on another system. This might be like your using "Spring2018" on one system and "Summer2018" on another. + +Another problem was that it was unclear how end users might have been able to tell whether or not they had a clean copy of the code, and there was no confirmation as to whether the malicious commits (accessible for a while) would execute. + +### Lessons learned from the hack + +The lessons learned should come as no surprise. We should all be careful not to use the same password on multiple systems and not to use passwords that relate to each other so strongly that knowing one in a set suggests another. + +We also have to admit that two-factor authentication would have prevented this break-in. While something of a burden on users (i.e., they may have to carry a token generator or confirm their login through some secondary service), it very strongly limits who can get access to an account. + +Of course the lessons learned should also not overlook what this incident showed us was going right. The fact that the break-in was noticed so quickly and that communications lines were functional meant the break-in could be quickly addressed. The breach was also made public, the repository was only a secondary copy of the main Gentoo source code, and changes in the main repository were signed and could be verified. + +#### The best news + +The really good news is that it appears that no one was affected by the break in other than the fact that developers were locked out for a while. The hackers weren't able to penetrate Gentoo's master repository (the default location for automatic updates). They also weren't able to get their hands on Gentoo's digital signing key. This means that default updates would have rejected their files as fakes. + +The harm that could have been made to Gentoo's reputation was avoided by the precautions in place and their professional handling of the incident. What could have cost them a lot ended up as a confirmation of what they're doing right and added to their determination to make some changes to strengthen their security. They faced up to some cyberbullies and came out stronger and more confident. + +### Fixing the potholes + +Gentoo is already addressing the weaknesses that contributed to the break-in. They are making frequent backups of their GitHub Organization (i.e., their content), starting to use two-factor authentication by default, working on an incident response plan with a focus on sharing information about a security incident with their users, and tightening procedures around credential revocation. They are also reducing the number of users with elevated privileges, auditing logins, and publishing password policies that mandate the use of password managers. + +### Gentoo and GitHub + +For readers unfamiliar with Gentoo, it's important to understand that Gentoo is different than most Linux distributions. Users download and then compile the source to build the OS they will then be using. It's as close to the Linux mantra of “know how to do it yourself” as you can get. + +Git is a code management system not unlike CVS, and GitHub provides repositories for the code. + +### Gentoo strengths + +Gentoo users tend to be more knowledgeable about the low-level aspects of the OS (e.g., kernel configuration and hardware support) than most Linux users — probably due to their interest in working with the source code. The OS is also highly scalable and flexible with a "build what you need" focus. The name derives from that of the "Gentoo penguin" — a penguin breed that lives on many sub-Antarctic islands. More information and downloads are available at [www.gentoo.org][2]. + +### More on the Gentoo GitHub break-in + +More information on the break in is available on [Naked Security][3] and (as noted above) the [Gentoo site][1]. + +Join the Network World communities on [Facebook][4] and [LinkedIn][5] to comment on topics that are top of mind. + +-------------------------------------------------------------------------------- + +via: https://www.networkworld.com/article/3287973/linux/the-aftermath-of-the-gentoo-github-hack.html + +作者:[Sandra Henry-Stocker][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.networkworld.com/author/Sandra-Henry_Stocker/ +[1]:https://wiki.gentoo.org/wiki/Project:Infrastructure/Incident_Reports/2018-06-28_Github +[2]:https://www.gentoo.org/ +[3]:https://nakedsecurity.sophos.com/2018/06/29/linux-distro-hacked-on-github-all-code-considered-compromised/ +[4]:https://www.facebook.com/NetworkWorld/ +[5]:https://www.linkedin.com/company/network-world diff --git a/sources/tech/20180710 Users, Groups, and Other Linux Beasts.md b/sources/tech/20180710 Users, Groups, and Other Linux Beasts.md new file mode 100644 index 0000000000..6083111a32 --- /dev/null +++ b/sources/tech/20180710 Users, Groups, and Other Linux Beasts.md @@ -0,0 +1,153 @@ +Users, Groups, and Other Linux Beasts +====== + +![](https://www.linux.com/sites/lcom/files/styles/rendered_file/public/flamingo-2458782_1920.jpg?itok=_gkzGGx5) + +Having reached this stage, [after seeing how to manipulate folders/directories][1], but before flinging ourselves headlong into fiddling with files, we have to brush up on the matter of _permissions_ , _users_ and _groups_. Luckily, [there is already an excellent and comprehensive tutorial on this site that covers permissions][2], so you should go and read that right now. In a nutshell: you use permissions to establish who can do stuff to files and directories and what they can do with each file and directory -- read from it, write to it, move it, erase it, etc. + +To try everything this tutorial covers, you'll need to create a new user on your system. Let's be practical and make a user for anybody who needs to borrow your computer, that is, what we call a _guest account_. + +**WARNING:** _Creating and especially deleting users, along with home directories, can seriously damage your system if, for example, you remove your own user and files by mistake. You may want to practice on another machine which is not your main work machine or on a virtual machine. Regardless of whether you want to play it safe, or not, it is always a good idea to back up your stuff frequently, check the backups have worked correctly, and save yourself a lot of gnashing of teeth later on._ + +### A New User + +You can create a new user with the `useradd` command. Run `useradd` with superuser/root privileges, that is using `sudo` or `su`, depending on your system, you can do: +``` +sudo useradd -m guest + +``` + +... and input your password. Or do: +``` +su -c "useradd -m guest" + +``` + +... and input the password of root/the superuser. + +( _For the sake of brevity, we'll assume from now on that you get superuser/root privileges by using`sudo`_ ). + +By including the `-m` argument, `useradd` will create a home directory for the new user. You can see its contents by listing _/home/guest_. + +Next you can set up a password for the new user with +``` +sudo passwd guest + +``` + +Or you could also use `adduser`, which is interactive and asks you a bunch of questions, including what shell you want to assign the user (yes, there are more than one), where you want their home directory to be, what groups you want them to belong to (more about that in a second) and so on. At the end of running `adduser`, you get to set the password. Note that `adduser` is not installed by default on many distributions, while `useradd` is. + +Incidentally, you can get rid of a user with `userdel`: +``` +sudo userdel -r guest + +``` + +With the `-r` option, `userdel` not only removes the _guest_ user, but also deletes their home directory and removes their entry in the mailing spool, if they had one. + +### Skeletons at Home + +Talking of users' home directories, depending on what distro you're on, you may have noticed that when you use the `-m` option, `useradd` populates a user's directory with subdirectories for music, documents, and whatnot as well as an assortment of hidden files. To see everything in you guest's home directory run `sudo ls -la /home/guest`. + +What goes into a new user's directory is determined by a skeleton directory which is usually _/etc/skel_. Sometimes it may be a different directory, though. To check which directory is being used, run: +``` +useradd -D +GROUP=100 +HOME=/home +INACTIVE=-1 +EXPIRE= +SHELL=/bin/bash +SKEL=/etc/skel +CREATE_MAIL_SPOOL=no + +``` + +This gives you some extra interesting information, but what you're interested in right now is the `SKEL=/etc/skel` line. In this case, and as is customary, it is pointing to _/etc/skel/_. + +As everything is customizable in Linux, you can, of course, change what gets put into a newly created user directory. Try this: Create a new directory in _/etc/skel/_ : +``` +sudo mkdir /etc/skel/Documents + +``` + +And create a file containing a welcome text and copy it over: +``` +sudo cp welcome.txt /etc/skel/Documents + +``` + +Now delete the guest account: +``` +sudo userdel -r guest + +``` + +And create it again: +``` +sudo useradd -m guest + +``` + +Hey presto! Your _Documents/_ directory and _welcome.txt_ file magically appear in the guest's home directory. + +You can also modify other things when you create a user by editing _/etc/default/useradd_. Mine looks like this: +``` +GROUP=users +HOME=/home +INACTIVE=-1 +EXPIRE= +SHELL=/bin/bash +SKEL=/etc/skel +CREATE_MAIL_SPOOL=no + +``` + +Most of these options are self-explanatory, but let's take a closer look at the `GROUP` option. + +### Herd Mentality + +Instead of assigning permissions and privileges to users one by one, Linux and other Unix-like operating systems rely on _groups_. A group is a what you imagine it to be: a bunch of users that are related in some way. On your system you may have a group of users that are allowed to use the printer. They would belong to the _lp_ (for " _line printer_ ") group. The members of the _wheel_ group were traditionally the only ones who could become superuser/root by using _su_. The _network_ group of users can bring up and power down the network. And so on and so forth. + +Different distributions have different groups and groups with the same or similar names have different privileges also depending on the distribution you are using. So don't be surprised if what you read in the prior paragraph doesn't match what is going on in your system. + +Either way, to see which groups are on your system you can use: +``` +getent group + +``` + +The `getent` command lists the contents of some of the system's databases. + +To find out which groups your current user belongs to, try: +``` +groups + +``` + +When you create a new user with `useradd`, unless you specify otherwise, the user will only belong to one group: their own. A _guest_ user will belong to a _guest_ group and the group gives the user the power to administer their own stuff and that is about it. + +You can create new groups and then add users to them at will with the `groupadd` command: +``` +sudo groupadd photos + +``` + +will create the _photos_ group, for example. Next time, we’ll use this to build a shared directory all members of the group can read from and write to, and we'll learn even more about permissions and privileges. Stay tuned! + +Learn more about Linux through the free ["Introduction to Linux" ][3]course from The Linux Foundation and edX. + +-------------------------------------------------------------------------------- + +via: https://www.linux.com/learn/intro-to-linux/2018/7/users-groups-and-other-linux-beasts + +作者:[Paul Brown][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.linux.com/users/bro66 +[1]:https://www.linux.com/blog/learn/2018/5/manipulating-directories-linux +[2]:https://www.linux.com/learn/understanding-linux-file-permissions +[3]:https://training.linuxfoundation.org/linux-courses/system-administration-training/introduction-to-linux diff --git a/sources/tech/20180711 5 open source racing and flying games for Linux.md b/sources/tech/20180711 5 open source racing and flying games for Linux.md new file mode 100644 index 0000000000..c2b540f498 --- /dev/null +++ b/sources/tech/20180711 5 open source racing and flying games for Linux.md @@ -0,0 +1,102 @@ +5 open source racing and flying games for Linux +====== + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/car-penguin-drive-linux-yellow.png?itok=twWGlYAc) + +Gaming has traditionally been one of Linux's weak points. That has changed somewhat in recent years thanks to Steam, GOG, and other efforts to bring commercial games to multiple operating systems, but those games often are not open source. Sure, the games can be played on an open source operating system, but that is not good enough for an open source purist. + +So, can someone who uses only free and open source software find games that are polished enough to present a solid gaming experience without compromising their open source ideals? Absolutely. While open source games are unlikely to ever rival some of the AAA commercial games developed with massive budgets, there are plenty of open source games, in many genres, that are fun to play and can be installed from the repositories of most major Linux distributions. Even if a particular game is not packaged for a particular distribution, it is usually easy to download the game from the project's website to install and play it. + +This article looks at racing and flying games. I have already written about [arcade-style games][1], [board and card games][2], and [puzzle games][3]. In future articles, I plan to cover role-playing games and strategy & simulation games. + +### Extreme Tux Racer + +![](https://opensource.com/sites/default/files/uploads/extreme_tux_racer.png) + +Race down snow and ice-covered mountains as Tux or other characters in [Extreme Tux Racer][4]. In this racing game, the goal is to collect herrings and earn the best time. There are many different tracks to choose from, and tracks can be customized by altering the time of day, wind, and weather conditions. While the game has a few rough edges compared to modern, commercial racing games, it is still an enjoyable game to play. The controls and gameplay are straightforward and simple to learn, making this a great choice for kids. + +To install Extreme Tux Racer, run the following command: + + * On Fedora: `dnf install extremetuxracer` + * On Debian/Ubuntu: `apt install extremetuxracer` + + + +### FlightGear + +![](https://opensource.com/sites/default/files/uploads/flightgear.png) + +[FlightGear][5] is a full-fledged, open source flight simulator. Multiple aircraft types are available, and 20,000 airports are included in the full world scenery set. That means the player can fly to most parts of the world and have realistic airports and scenery. The full world scenery data is large enough to fill three DVDs. Even the developers are jokingly not sure if that counts as "a feature or a problem," so be aware that a complete installation of FlightGear and all its scenery data is huge. While certainly not the right game for everyone, FlightGear provides a very complete and complex flight simulator experience for players looking to explore the skies on their own computer. + +To install FlightGear, run the following command: + + * On Fedora: `dnf install FlightGear` + * On Debian/Ubuntu: `apt install flightgear` + + + +### SuperTuxKart + +![](https://opensource.com/sites/default/files/uploads/supertuxkart.png) + +[SuperTuxKart][6] takes the basic formula used by Nintendo in the Mario Kart series and applies it to open source mascots. Players race around a variety of tracks in go-karts driven by the mascots for a plethora of open source projects. Character choices include the mascots for open source operating systems and applications of varying familiarity, with options ranging from Tux and Beastie to Gavroche, the mascot for [GNU MediaGoblin][7]. There are several gameplay modes to choose from, including multi-player modes, but many of the tracks are unavailable until they are unlocked by playing the game's single-player story mode. SuperTuxKart's graphics settings can be tweaked to run on everything from older computers with built-in graphics to modern hardware with high-end graphics cards. There is also a version of [SuperTuxKart for Android][8] available. SuperTuxKart is a very good game and great for players of all ages. + +To install SuperTuxKart, run the following command: + + * On Fedora: `dnf install supertuxkart` + * On Debian/Ubuntu: `apt install supertuxkart` + + + +### Torcs + +![](https://opensource.com/sites/default/files/uploads/torcs.png) + +[Torcs][9] is a fairly standard racing game with some extra features for the tech-savvy. Torcs can be played as just a standard racing game, where the player drives around a track trying to get the best time, but an alternative usage is as a platform to develop an artificial intelligence driver that can drive itself through Torcs' tracks. The cars and tracks included with the game vary in style, ranging from stock car racing to rally racing, but the gameplay is pretty typical for a racing game. Keyboard, mouse, joystick, and steering wheel input are all supported, but keyboard and mouse input modes are a little hard to get used to. Single-player races range from practice runs to championships, and there is a [split-screen multi-player mode][10] for up to four players. + +To install Torcs, run the following command: + + * On Fedora: `dnf install torcs` + * On Debian/Ubuntu: `apt install torcs` + + + +### Trigger Rally + +![](https://opensource.com/sites/default/files/uploads/trigger_rally.png) + +[Trigger Rally][11] is an off-road, single-player rally racing game. The player needs to make it to each checkpoint in time to complete the race, which is standard racing game fare, but still enjoyable. The gameplay is more arcade-like than a strict racing simulator like Torcs but more realistic than cartoonish racing games like SuperTuxKart. The tracks are interesting and the controls are responsive, but a little too sensitive when playing with a keyboard. Joystick controls are available by changing an option in a configuration file. Unfortunately, development on the game is slow going, with the latest release in 2016, but the gameplay that is already there is fun. + +To install Trigger Rally, run the following command: + + * On Debian/Ubuntu: `apt install trigger-rally` + + + +Unfortunately, Trigger Rally is not packaged for Fedora. + +Did I miss one of your favorite open source racing or flying games? Share it in the comments below. + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/7/racing-flying-games-linux + +作者:[About The Author;Joshua Allen Holm;Mlis;Med;Is One Of Opensource.Com'S Community Moderators. Joshua'S Main Interests Are Digital Humanities;Open Access;Open Educational Resources. He Can Reached At][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://opensource.com/users/holmja +[1]:https://opensource.com/article/18/1/arcade-games-linux +[2]:https://opensource.com/article/18/3/card-board-games-linux +[3]:https://opensource.com/article/18/6/puzzle-games-linux +[4]:https://extremetuxracer.sourceforge.io/ +[5]:http://home.flightgear.org/ +[6]:https://supertuxkart.net/Main_Page +[7]:https://mediagoblin.org +[8]:https://play.google.com/store/apps/details?id=org.supertuxkart.stk +[9]:http://torcs.sourceforge.net/index.php +[10]:http://torcs.sourceforge.net/?name=Sections&op=viewarticle&artid=30#c4_4_4 +[11]:http://trigger-rally.sf.net/ diff --git a/sources/tech/20180711 Becoming a senior developer 9 experiences you ll encounter.md b/sources/tech/20180711 Becoming a senior developer 9 experiences you ll encounter.md new file mode 100644 index 0000000000..7ff8e59007 --- /dev/null +++ b/sources/tech/20180711 Becoming a senior developer 9 experiences you ll encounter.md @@ -0,0 +1,141 @@ +Becoming a senior developer: 9 experiences you'll encounter +============================================================ + +![](https://www.hpe.com/content/dam/hpe/insights/articles/2018/07/becoming-a-senior-developer-9-experiences-youll-encounter/featuredStory/do-You-Want-To-Be-a-Master-Programmer.jpg.transform/nxt-1043x496-crop/image.jpeg) + +Plenty of career guides suggest appropriate steps to take if you want a management track. But what if you want to stay technical—and simply become the best possible programmer? These non-obvious markers let you know you’re on the right path. + +Many programming career guidelines stress the skills a software developer is expected to acquire. Such general advice suggests that someone who wants to focus on a technical track—as opposed to, say, [taking a management path to CIO][5]—should go after the skills needed to mentor junior developers, design future application features, build out release engineering systems, and set company standards. + +That isn’t this article. + +Being a developer—a good one—isn't just about writing code. To be successful, you do a lot of planning, you deal with catastrophes, and you prevent catastrophes. Not to mention you spend plenty of time [working with other humans][6] about what your code should do. + +Following are a number of markers you’ll likely encounter as your career progresses and you become a more accomplished developer. You’ll have highs that boost you up and remind you how awesome you are. You'll also encounter lows that keep you humble and give you wisdom—at least in retrospect, if you respond to them appropriately. + +These experiences may feel good, they may be uncomfortable, or they may be downright scary. They're all learning experiences—at least for those developers who sincerely want to move forward, in both skills and professional ambition. These experiences often change the way developers look at their job or how they approach the next problem. It's why an experienced developer's value to a company is more than just a list of technology buzzwords. + +Here, in no particular order, is a sampling of what you'll run into on your way to becoming a senior developer—not in terms of a specific job title but being confident about creating quality code that serves users. + +### You write your first big bug into production + +Probably your initial step into the big leagues is the first bug you write into production. It's a sickening feeling. You know that the software you're working on is now broken in some significant way because of something you did, code you wrote, or a test you didn't run. + +No matter how good a programmer you are, you'll make mistakes. You're a human, and that's part of what we do. + +Most developers learn from the “bug that went live” experience. You promise never to make the same bug again. You analyze what happened, and you think about how the bug could have been prevented. For me, one effect of discovering I let a bug into production code is that it reinforced my belief that compiler warnings and static analysis tools are a programmer's best friend. + +You repeat the process when it happens again. It  _will_  happen again, but as your programming skill improves, it happens less frequently. + +### You delete production data for the first time + +It might be a `DROP TABLE` in production or [a mistaken `rm -rf`][7]. Maybe you clicked on the wrong volume to format. You get an uneasy feeling that "this is taking longer to run than I would expect. It's not running on... oh, no!" followed by a mad scramble to fix it. + +Data loss has long-term effects on a growing-wiser developer much like the production bug. Afterward, you re-examine how you work. It teaches you to take more safeguards than you did previously. Maybe you decide to create a more rigorous rotation schedule for backups, or even start having a backup schedule at all. + +As with the bug in production, you learn that you can survive making a mistake, and it's not the end of the world. + +### You automate away part of your job + +There's an old saying that you can't get promoted if you can't be replaced. Anything that ties you to a specific job or task is an anchor on your ability to move up in the company or be assigned newer and more interesting tasks. + +When good programmers find themselves doing drudgework as part of their job, they find a way to let a machine do it. If they are stuck [scanning server logs][8] every Monday looking for problems, they'll install a tool like Logwatch to summarize the results. When there are many servers to be monitored, a good programmer will turn to a more capable tool that analyzes logs on multiple servers. + +Unsure how to get started with containers? Yes, we have a guide for that. Get Containers for Dummies. + +[Download now][4] + +In each case, wise programmers provide more value to their company, because an automated system is much cheaper than a senior programmer’s salary. They also grow personally by eliminating drudgery, leaving them more time to work on more challenging tasks. + +### You use existing code instead of writing your own + +A senior programmer knows that code that doesn't get written doesn't have bugs, and that many problems, both common and uncommon, have already been solved—in many cases, multiple times. + +Senior programmers know that the chances are very low that they can write, test, and debug their own code for a task faster or cheaper than existing code that does what they want. It doesn't have to be perfect to make it worth their while. + +It might take a little bit of turning down your ego to make it happen, but that's an excellent skill for senior programmers to have, too. + +### You are publicly recognized for achievements + +Many people aren't comfortable with public recognition. It's embarrassing. We have these amazing skills, and we like the feeling of helping others, but we can be embarrassed when it's called out. + +Praise comes in many forms and many sizes. Maybe it's winning an "employee of the quarter" award for a project you drove and being presented a plaque onstage. It could be as low-key as your team leader saying, "Thanks to Cheryl for implementing that new microservice." + +Whatever it is, accept it graciously and appreciatively, even if you're embarrassed by the attention. Don't diminish the praise you receive with, "Oh, it was nothing" or anything similar. Accept credit for the things that users and co-workers appreciate. Thank the speaker and say you were glad you could be of service. + +First, this is the polite thing to do. When people praise you, they want it to be acknowledged. In addition, that warm recognition helps you in the future. Remembering it gets you through those crappy days, such as when you uncover bugs in your code. + +### You turn down a user request + +As much as we love being superheroes who can do amazing things with computers, sometimes turning down a request is best for the organization. Part of being a senior programmer is knowing when not to write code. A senior programmer knows that every bit of code in a codebase is a chance for things to go wrong and a potential future cost for maintenance. + +You might be uncomfortable the first time you tell a user that you won’t be incorporating his maybe-even-useful suggestion. But this is a notable occasion. It means you understand the application and its role in a larger context. It also means you “own” the software, in a positive, confident way. + +The organization need not be an employer, either. Open source project managers deal with this all the time, when they have to tell a user, "Sorry, it doesn't fit with where the project is going.” + +### You know when to fight for what's right and when it really doesn't matter + +Rookie programmers are full of knowledge straight from school, having learned all the right ways to do things. They're eager to apply their knowledge and make amazing things happen for their employers. However, they're often surprised to find that out in the business world, things sometimes don't get done the "right" way. + +There's an old military saying: No plan survives contact with the enemy. It's the same with new programmers and project plans. Sometimes in the heat of the battle of business, the purist computer science techniques learned in school fall by the wayside. + +Maybe the database schema gets slapped together in a way that isn't perfect [fifth normal form][9]. Sometimes code gets cut and pasted rather than refactored out into a new function or library. Plenty of production systems run on shell scripts and prayers. The wise programmer knows when to push for the right way to do things and when to take the cheap way out. + +The first time you do it, it feels like you're selling out your principles. It’s not. The balance between academic purism and the realities of getting work done can be a delicate one, and that knowledge of when to do things less than perfectly is part of the wisdom you’ll acquire. + +### You are asked what to do + +After a while, you'll have earned a reputation in your organization for getting things done. It won’t be just for having expertise in a certain area—it’ll be wisdom. Someone will come to you and ask for guidance with a project or a problem. + +That person isn't just asking you for help with a problem. You are being asked to lead. + +A common situation is when you are asked to help a team of less-experienced developers that's navigating difficult new terrain or needs shepherding on a project. That's when you'll be called on to help not just do things but show people how to improve their own skills. + +It might also be leadership from a technical point of view. Your boss might say, "We need a new indexing solution. Find out what you can about FooIndex and BarSearch, and let me know what you propose." That's the sort of responsibility given only to someone who has demonstrated wisdom and experience. + +### You are seriously headhunted for the first time + +Recruiting professionals are always looking for talent. Most recruiters seem to do random emailing and LinkedIn harvesting. But every so often, they find out about talented performers and hunt them down. + +When that happens, it's a feather in your cap. Maybe a former colleague spoke to a recruiter friend trying to place a developer at a company that needs the skills you have. If you get a personal recommendation for a position—even if you don’t want the job—it means you've really arrived. You're recognized as an expert, or someone who brings value to an organization, enough to recommend you to others. + +### Onward + +I hope that my little list helps prompt some thought about [where you are in your career][10] or [where you might be headed][11]. Markers and milestones can help you understand what’s around you and what to expect. + +This list is far from complete, of course. Everyone has their own story. In fact, one of the ways to know you’ve hit a milestone is when you find yourself telling a story about it to others. When you do find yourself looking back at a tough situation, make sure to reflect on what it means to you and why. Experience is a great teacher—if you listen to it. + +What are your markers? How did you know you had finally become a senior programmer? Tweet at [@enterprisenxt][12] and let me know. + +This article/content was written by the individual writer identified and does not necessarily reflect the view of Hewlett Packard Enterprise Company. + + [![](https://www.hpe.com/content/dam/hpe/insights/contributors/andy-lester/AndyLester_headshot-400x400.jpg.transform/nxt-116x116/image.jpeg)][13] + +### 作者简介 + +Andy Lester has been a programmer and developer since the 1980s, when COBOL walked the earth. He is the author of the job-hunting guide [Land the Tech Job You Love][2] (2009, Pragmatic Bookshelf). Andy has been an active contributor to the open source community for decades, most notably as the creator of the grep-like code search tool [ack][3]. + +-------------------------------------------------------------------------------- + +via: https://www.hpe.com/us/en/insights/articles/becoming-a-senior-developer-9-experiences-youll-encounter-1807.html + +作者:[Andy Lester ][a] +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.hpe.com/us/en/insights/contributors/andy-lester.html +[1]:https://www.hpe.com/us/en/insights/contributors/andy-lester.html +[2]:https://pragprog.com/book/algh/land-the-tech-job-you-love +[3]:https://beyondgrep.com/ +[4]:https://www.hpe.com/us/en/resources/storage/containers-for-dummies.html?jumpid=in_510384402_seniordev0718 +[5]:https://www.hpe.com/us/en/insights/articles/7-career-milestones-youll-meet-on-the-cio-and-it-management-track-1805.html +[6]:https://www.hpe.com/us/en/insights/articles/how-to-succeed-in-it-without-social-skills-1705.html +[7]:https://www.hpe.com/us/en/insights/articles/the-linux-commands-you-should-never-use-1712.html +[8]:https://www.hpe.com/us/en/insights/articles/back-to-basics-what-sysadmins-must-know-about-logging-and-monitoring-1805.html +[9]:http://www.bkent.net/Doc/simple5.htm +[10]:https://www.hpe.com/us/en/insights/articles/career-interventions-when-your-it-career-needs-a-swift-kick-1806.html +[11]:https://www.hpe.com/us/en/insights/articles/how-to-avoid-an-it-career-dead-end-1806.html +[12]:https://twitter.com/enterprisenxt +[13]:https://www.hpe.com/us/en/insights/contributors/andy-lester.html diff --git a/sources/tech/20180711 Open hardware meets open science in a multi-microphone hearing aid project.md b/sources/tech/20180711 Open hardware meets open science in a multi-microphone hearing aid project.md new file mode 100644 index 0000000000..f6a348980d --- /dev/null +++ b/sources/tech/20180711 Open hardware meets open science in a multi-microphone hearing aid project.md @@ -0,0 +1,69 @@ +Open hardware meets open science in a multi-microphone hearing aid project +====== + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/BIZ_OpenInnovation.png?itok=l29msbql) + +Since [Opensource.com][1] first published the story of the [GNU/Linux hearing aid][2] research platform in 2010, there has been an explosion in the availability of miniature system boards, including the original BeagleBone in 2011 and the Raspberry Pi in 2012. These ARM processor devices built from cellphone chips differ from the embedded system reference boards of the past—not only by being far less expensive and more widely available—but also because they are powerful enough to run familiar GNU/Linux distributions and desktop applications. + +What took a laptop to accomplish in 2010 can now be achieved with a pocket-sized board costing a fraction as much. Because a hearing aid does not need a screen and a small ARM board's power consumption is far less than a typical laptop's, field trials can potentially run all day. Additionally, the system's lower weight is easier for the end user to wear. + +The [openMHA project][3]—from the [Carl von Ossietzky Universität Oldenburg][4] in Germany, [BatAndCat Sound Labs][5] in Palo Alto, California, and [HörTech gGmbH][6]—is an open source platform for improving hearing aids using real-time audio signal processing. For the next iteration of the research platform, openMHA is using the US$ 55 [BeagleBone Black][7] board with its 1GHz Cortex A8 CPU. + +The BeagleBone family of boards enjoys guaranteed long-term availability, thanks to its open hardware design that can be produced by anyone with the requisite knowledge. For example, BeagleBone hardware variations are available from community members including [SeeedStudio][8] and [SanCloud][9]. + +![BeagleBone Black][11] + +The BeagleBone Black is open hardware finding its way into research labs. + +Spatial filtering techniques, including [beamforming][12] and [directional microphone arrays][13], can suppress distracting noise, focusing audio amplification on the point in space where the hearing aid wearer is looking, rather than off to the side where a truck might be thundering past. These neat tricks can use two or three microphones per ear, yet typical sound cards for embedded devices support only one or two input channels in total. + +Fortunately, the [McASP][14] communication peripheral in Texas Instruments chips offers multiple channels and support for the [I2S protocol][15], originally devised by Philips for short digital audio interconnects inside CD players. This means an add-on "cape" board can hook directly into the BeagleBone's audio system without using USB or other external interfaces. The direct approach helps reduce the signal processing delay into the range where it is undetectable by the hearing aid wearer. + +The openMHA project uses an audio cape developed by the [Hearing4all][16] project, which combines three stereo codecs to provide up to six input channels. Like the BeagleBone, the Cape4all is open hardware with design files available on [GitHub][17]. + +The Cape4all, [presented recently][18] at the Linux Audio Conference in Berlin, Germany, runs at a sample rate from 24kHz to 96Khz with as few as 12 samples per period, leading to internal latencies in the sub-millisecond range. With hearing enhancement algorithms running, the complete round-trip latency from a microphone to an earpiece has been measured at 3.6 milliseconds (at 48KHz sample rate with 16 samples per period). Using the speed of sound for comparison, this latency is similar to listening to someone just over four feet away without a hearing aid. + +![Cape4all ][20] + +The Cape4all might be the first multi-microphone hearing aid on an open hardware platform. + +The next step for the openMHA project is to develop a [Bluetooth Low Energy][21] module that will enable remote control of the research device from a smartphone and perhaps route phone calls and media playback to the hearing aid. Consumer hearing aids support Bluetooth, so the openMHA research platform must do so, too. + +Also, instructions for running a [stereo hearing aid on the Raspberry Pi][22] were released by an openMHA user-project. + +As evidenced by the openMHA project, open source innovation has transformed digital hearing aid research from an esoteric branch of audiology into an accessible open science. + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/7/open-hearing-aid-platform + +作者:[Daniel James,Christopher Obbard][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://opensource.com/users/daniel-james +[1]:http://Opensource.com +[2]:https://opensource.com/life/10/9/open-source-designing-next-generation-digital-hearing-aids +[3]:http://www.openmha.org/ +[4]:https://www.uni-oldenburg.de/ +[5]:http://batandcat.com/ +[6]:http://www.hoertech.de/ +[7]:https://beagleboard.org/black +[8]:https://www.seeedstudio.com/ +[9]:http://www.sancloud.co.uk +[10]:/file/403046 +[11]:https://opensource.com/sites/default/files/uploads/1-beagleboneblack-600.jpg (BeagleBone Black) +[12]:https://en.wikipedia.org/wiki/Beamforming +[13]:https://en.wikipedia.org/wiki/Microphone_array +[14]:https://en.wikipedia.org/wiki/McASP +[15]:https://en.wikipedia.org/wiki/I%C2%B2S +[16]:http://hearing4all.eu/EN/ +[17]:https://github.com/HoerTech-gGmbH/Cape4all +[18]:https://lac.linuxaudio.org/2018/pages/event/35/ +[19]:/file/403051 +[20]:https://opensource.com/sites/default/files/uploads/2-beaglebone-wireless-with-cape4all-labelled-600.jpg (Cape4all ) +[21]:https://en.wikipedia.org/wiki/Bluetooth_Low_Energy +[22]:http://www.openmha.org/userproject/2017/12/21/openMHA-on-raspberry-pi.html diff --git a/sources/tech/20180716 Confessions of a recovering Perl hacker.md b/sources/tech/20180716 Confessions of a recovering Perl hacker.md new file mode 100644 index 0000000000..48a904cf35 --- /dev/null +++ b/sources/tech/20180716 Confessions of a recovering Perl hacker.md @@ -0,0 +1,46 @@ +Confessions of a recovering Perl hacker +====== + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/rh_003499_01_linux11x_cc.png?itok=XMDOouJR) + +My name's MikeCamel, and I'm a Perl hacker. + +There, I've said it. That's the first step. + +My handle on IRC, Twitter and pretty much everywhere else in the world is "MikeCamel." This is because, back in the day, when there were no chat apps—no apps at all, in fact—I was in a technical "chatroom" and the name "Mike" had been taken. I looked around, and the first thing I noticed on my desk was the [Camel Book][1], the O'Reilly Perl Bible. + +I have the second edition now, but this was the first edition. Yesterday, I happened to pick up the second edition, the really thick one, to show someone on a video conference call, and it had a thin layer of dust on it. I was a little bit ashamed, but a little bit relieved as well. + +For years, I was a sysadmin. Just bits and pieces, from time to time. Nothing serious, you understand—mainly my systems, my friends' systems. Sometimes I'd admin systems owned by other people—even at work. I always had it under control, and I was always able to step away. There were whole weeks—well days—when I didn't administer a system at all. With the exception of remote systems, which felt different, somehow less serious. + +What pushed it over the edge, on reflection, was the Perl. This was the '90s—the 1990s, just to be clear—when Perl was young, and free, and didn't even pretend to be object-oriented. We all know it still isn't, but those youngsters—they like to pretend, and we old lags, well, we play along. + +The thing about Perl is that it just starts small, with a regexp here, a text-file line counter there. Nothing that couldn't have been managed quite easily in Bash or Sed or Awk. But once you've written a couple of scripts, you're in—there's no going back. Long-term Perl users remember how we started, and we see the newbs going the same way. + +I taught myself Perl in order to collate static web pages from five disparate FoxPro databases. I did it by starting at the beginning of the Camel Book and reading as much of it as I could before my brain started to hurt, then picking up a few pages back and carrying on. And then writing some Perl, which always failed, mainly because of lack of semicolons to start with, and then because I didn't really understand much of what I was doing. But I kept with it until I wasn't just writing scripts to collate databases, but scripts to load data into a single database and using CGI to serve pages in real time. My wife knew, and some of my colleagues knew, but I don't think they fully understood how deep I was in. + +You know that Perl has you when you start looking for admin tasks to automate with it. Tasks that don't need automating and that would be much, much faster if you performed them by hand. When you start scouring the web for three- or four-character commands that, when executed, alphabetise, spell-check, and decrypt three separate files in parallel and output them to STDERR, ROT13ed. + +I was lucky: I escaped in time. I always insisted on commenting my Perl. I never got to the very end of the Camel Book. Not in one reading, anyway. I never experimented with the darker side-effects; three or four separate operations per line was always enough for me. Over time, as my responsibilities moved more to programming, I cut back on the sysadmin tasks. Of course, that didn't stop the Perl use completely—it's amazing how often you can find an excuse to automate a task and how often Perl is the answer. But it reduced my Perl to manageable levels, levels that didn't affect my day-to-day functioning. + +I'd like to pretend that I've stopped, but you never really give up on Perl, and it never gives up on you. + +I'd like to pretend that I've stopped, but you never really give up on Perl, and it never gives up on you. My Camel Book (2nd ed.) is still around, even if it's a little dusty. I always check that the core modules are installed on any systems I run. And about five months ago, I found that my 10-year-old daughter had some mathematics homework that was susceptible to brute-forcing. Just a few lines. A couple of loops. No more than that. Nothing that I didn't feel went out of scope. + +I'd like to pretend that I've stopped, but you never really give up on Perl, and it never gives up on you. My Camel Book (2nd ed.) is still around, even if it's a little dusty. I always check that the core modules are installed on any systems I run. And about five months ago, I found that my 10-year-old daughter had some mathematics homework that was susceptible to brute-forcing. Just a few lines. A couple of loops. No more than that. Nothing that I didn't feel went out of scope. + +I discovered after she handed in the results that it hadn't produced the correct results, but I didn't mind. It was tight, it was elegant, it was beautiful. It was Perl. My Perl. + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/7/confessions-recovering-perl-hacker + +作者:[Mike Bursell][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://opensource.com/users/mikecamel +[1]:https://en.wikipedia.org/wiki/Programming_Perl diff --git a/sources/tech/20180716 How To Find The Mounted Filesystem Type In Linux.md b/sources/tech/20180716 How To Find The Mounted Filesystem Type In Linux.md new file mode 100644 index 0000000000..5005cf44f7 --- /dev/null +++ b/sources/tech/20180716 How To Find The Mounted Filesystem Type In Linux.md @@ -0,0 +1,259 @@ +How To Find The Mounted Filesystem Type In Linux +====== + +![](https://www.ostechnix.com/wp-content/uploads/2018/07/filesystem-720x340.png) + +As you may already know, the Linux supports numerous filesystems, such as Ext4, ext3, ext2, sysfs, securityfs, FAT16, FAT32, NTFS, and many. The most commonly used filesystem is Ext4. Ever wondered what type of filesystem are you currently using in your Linux system? No? Worry not! We got your back. This guide explains how to find the mounted filesystem type in Unix-like operating systems. + +### Find The Mounted Filesystem Type In Linux + +There can be many ways to find the filesystem type in Linux. Here, I have given 8 different methods. Let us get started, shall we? + +#### Method 1 – Using findmnt command + +This is the most commonly used method to find out the type of a filesystem. The **findmnt** command will list all mounted filesystems or search for a filesystem. The findmnt command can be able to search in **/etc/fstab** , **/etc/mtab** or **/proc/self/mountinfo**. + +findmnt command comes pre-installed in most Linux distributions, because it is part of the package named **util-linux**. Just in case if it is not available, simply install this package and you’re good to go. For instance, you can install **util-linux** package in Debian-based systems using command: +``` +$ sudo apt install util-linux + +``` + +Let us go ahead and see how to use findmnt command to find out the mounted filesystems. + +If you run it without any arguments/options, it will list all mounted filesystems in a tree-like format as shown below. +``` +$ findmnt + +``` + +**Sample output:** + +![][2] + +As you can see, the findmnt command displays the target mount point (TARGET), source device (SOURCE), file system type (FSTYPE), and relevant mount options, like whether the filesystem is read/write or read-only. (OPTIONS). In my case, my root(/) filesystem type is EXT4. + +If you don’t like/want to display the output in tree-like format, use **-l** flag to display in simple, plain format. +``` +$ findmnt -l + +``` + +![][3] + +You can also list a particular type of filesystem, for example **ext4** , using **-t** option. +``` +$ findmnt -t ext4 +TARGET SOURCE FSTYPE OPTIONS +/ /dev/sda2 ext4 rw,relatime,commit=360 +└─/boot /dev/sda1 ext4 rw,relatime,commit=360,data=ordered + +``` + +Findmnt can produce df style output as well. +``` +$ findmnt --df + +``` + +Or +``` +$ findmnt -D + +``` + +Sample output: +``` +SOURCE FSTYPE SIZE USED AVAIL USE% TARGET +dev devtmpfs 3.9G 0 3.9G 0% /dev +run tmpfs 3.9G 1.1M 3.9G 0% /run +/dev/sda2 ext4 456.3G 342.5G 90.6G 75% / +tmpfs tmpfs 3.9G 32.2M 3.8G 1% /dev/shm +tmpfs tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup +bpf bpf 0 0 0 - /sys/fs/bpf +tmpfs tmpfs 3.9G 8.4M 3.9G 0% /tmp +/dev/loop0 squashfs 82.1M 82.1M 0 100% /var/lib/snapd/snap/core/4327 +/dev/sda1 ext4 92.8M 55.7M 30.1M 60% /boot +tmpfs tmpfs 788.8M 32K 788.8M 0% /run/user/1000 +gvfsd-fuse fuse.gvfsd-fuse 0 0 0 - /run/user/1000/gvfs + +``` + +You can also display filesystems for a specific device, or mountpoint too. + +Search for a device: +``` +$ findmnt /dev/sda1 +TARGET SOURCE FSTYPE OPTIONS +/boot /dev/sda1 ext4 rw,relatime,commit=360,data=ordered + +``` + +Search for a mountpoint: +``` +$ findmnt / +TARGET SOURCE FSTYPE OPTIONS +/ /dev/sda2 ext4 rw,relatime,commit=360 + +``` + +You can even find filesystems with specific label: +``` +$ findmnt LABEL=Storage + +``` + +For more details, refer the man pages. +``` +$ man findmnt + +``` + +The findmnt command is just enough to find the type of a mounted filesystem in Linux. It is created for that specific purpose only. However, there are also few other ways available to find out the filesystem type. If you’re interested to know, read on. + +#### Method 2 – Using blkid command + +The **blkid** command is used locate and print block device attributes. It is also part of the util-linux package, so you don’t bother to install it. + +To find out the type of a filesystem using blkid command, run: +``` +$ blkid /dev/sda1 + +``` + +#### Method 3 – Using df command + +The **df** command is used to report filesystem disk space usage in Unix-like operating systems. To find the type of all mounted filesystems, simply run: +``` +$ df -T + +``` + +**Sample output:** + +![][4] + +For details about df command, refer the following guide. + +Also, check man pages. +``` +$ man df + +``` + +#### Method 4 – Using file command + +The **file** command determines the type of a specified file. It works just fine for files with no file extension. + +Run the following command to find the filesystem type of a partition: +``` +$ sudo file -sL /dev/sda1 +[sudo] password for sk: +/dev/sda1: Linux rev 1.0 ext4 filesystem data, UUID=83a1dbbf-1e15-4b45-94fe-134d3872af96 (needs journal recovery) (extents) (large files) (huge files) + +``` + +Check man pages for more details: +``` +$ man file + +``` + +#### Method 5 – Using fsck command + +The **fsck** command is used to check the integrity of a filesystem or repair it. You can find the type of a filesystem by passing the partition as an argument like below. +``` +$ fsck -N /dev/sda1 +fsck from util-linux 2.32 +[/usr/bin/fsck.ext4 (1) -- /boot] fsck.ext4 /dev/sda1 + +``` + +For more details, refer man pages. +``` +$ man fsck + +``` + +#### Method 6 – Using fstab Command + +**fstab** is a file that contains static information about the filesystems. This file usually contains the mount point, filesystem type and mount options. + +To view the type of a filesystem, simply run: +``` +$ cat /etc/fstab + +``` + +![][5] + +For more details, refer man pages. +``` +$ man fstab + +``` + +#### Method 7 – Using lsblk command + +The **lsblk** command displays the information about devices. + +To display info about mounted filesystems, simply run: +``` +$ lsblk -f +NAME FSTYPE LABEL UUID MOUNTPOINT +loop0 squashfs /var/lib/snapd/snap/core/4327 +sda +├─sda1 ext4 83a1dbbf-1e15-4b45-94fe-134d3872af96 /boot +├─sda2 ext4 4d25ddb0-5b20-40b4-ae35-ef96376d6594 / +└─sda3 swap 1f8f5e2e-7c17-4f35-97e6-8bce7a4849cb [SWAP] +sr0 + +``` + +For more details, refer man pages. +``` +$ man lsblk + +``` + +#### Method 8 – Using mount command + +The **mount** command is used to mount a local or remote filesystems in Unix-like systems. + +To find out the type of a filesystem using mount command, do: +``` +$ mount | grep "^/dev" +/dev/sda2 on / type ext4 (rw,relatime,commit=360) +/dev/sda1 on /boot type ext4 (rw,relatime,commit=360,data=ordered) + +``` + +For more details, refer man pages. +``` +$ man mount + +``` + +And, that’s all for now folks. You now know 8 different Linux commands to find out the type of a mounted Linux filesystems. If you know any other methods, feel free to let me know in the comment section below. I will check and update this guide accordingly. + +More good stuffs to come. Stay tuned! + + + +-------------------------------------------------------------------------------- + +via: https://www.ostechnix.com/how-to-find-the-mounted-filesystem-type-in-linux/ + +作者:[SK][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.ostechnix.com/author/sk/ +[1]:data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7 +[2]:http://www.ostechnix.com/wp-content/uploads/2018/07/findmnt-1.png +[3]:http://www.ostechnix.com/wp-content/uploads/2018/07/findmnt-2.png +[4]:http://www.ostechnix.com/wp-content/uploads/2018/07/df.png +[5]:http://www.ostechnix.com/wp-content/uploads/2018/07/fstab.png diff --git a/sources/tech/20180716 Users, Groups and Other Linux Beasts- Part 2.md b/sources/tech/20180716 Users, Groups and Other Linux Beasts- Part 2.md new file mode 100644 index 0000000000..b164bb6cf5 --- /dev/null +++ b/sources/tech/20180716 Users, Groups and Other Linux Beasts- Part 2.md @@ -0,0 +1,110 @@ +Users, Groups and Other Linux Beasts: Part 2 +====== +![](https://www.linux.com/blog/learn/intro-to-linux/2018/7/users-groups-and-other-linux-beasts-part-2) +In this ongoing tour of Linux, we’ve looked at [how to manipulate folders/directories][1], and now we’re continuing our discussion of _permissions_ , _users_ and _groups_ , which are necessary to establish who can manipulate which files and directories. [Last time,][2] we showed how to create new users, and now we’re going to dive right back in: + +You can create new groups and then add users to them at will with the `groupadd` command. For example, using: +``` +sudo groupadd photos + +``` + +will create the _photos_ group. + +You’ll need to [create a directory][1] hanging off the root directory: +``` +sudo mkdir /photos + +``` + +If you run `ls -l /`, one of the lines will be: +``` +drwxr-xr-x 1 root root 0 jun 26 21:14 photos + +``` + +The first _root_ in the output is the user owner and the second _root_ is the group owner. + +To transfer the ownership of the _/photos_ directory to the _photos_ group, use +``` +chgrp photos /photos + +``` + +The `chgrp` command typically takes two parameters, the first parameter is the group that will take ownership of the file or directory and the second is the file or directory you want to give over to the the group. + +Next, run `ls -l /` and you'll see the line has changed to: +``` +drwxr-xr-x 1 root photos 0 jun 26 21:14 photos + +``` + +You have successfully transferred the ownership of your new directory over to the _photos_ group. + +Then, add your own user and the _guest_ user to the _photos_ group: +``` +sudo usermod -a -G photos +sudo usermod guest -a -G photos + +``` + +You may have to log out and log back in to see the changes, but, when you do, running `groups` will show _photos_ as one of the groups you belong to. + +A couple of things to point out about the `usermod` command shown above. First: Be careful not to use the `-g` option instead of `-G`. The `-g` option changes your primary group and could lock you out of your stuff if you use it by accident. `-G`, on the other hand, _adds_ you to the groups listed and doesn't mess with the primary group. If you want to add your user to more groups than one, list them one after another, separated by commas, no spaces, after `-G`: +``` +sudo usermod -a -G photos,pizza,spaceforce + +``` + +Second: Be careful not to forget the `-a` parameter. The `-a` parameter stands for _append_ and attaches the list of groups you pass to `-G` to the ones you already belong to. This means that, if you don't include `-a`, the list of groups you already belong to, will be overwritten, again locking you out from stuff you need. + +Neither of these are catastrophic problems, but it will mean you will have to add your user back manually to all the groups you belonged to, which can be a pain, especially if you have lost access to the _sudo_ and _wheel_ group. + +### Permits, Please! + +There is still one more thing to do before you can copy images to the _/photos_ directory. Notice how, when you did `ls -l /` above, permissions for that folder came back as _drwxr-xr-x_. + +If you read [the article I recommended at the beginning of this post][3], you'll know that the first _d_ indicates that the entry in the file system is a directory, and then you have three sets of three characters ( _rwx_ , _r-x_ , _r-x_ ) that indicate the permissions for the user owner ( _rwx_ ) of the directory, then the group owner ( _r-x_ ), and finally the rest of the users ( _r-x_ ). This means that the only person who has write permissions so far, that is, the only person who can copy or create files in the _/photos_ directory, is the _root_ user. + +But [that article I mentioned also tells you how to change the permissions for a directory or file][3]: +``` +sudo chmod g+w /photos + +``` + +Running `ls -l /` after that will give you _/photos_ permissions as _drwxrwxr-x_ which is what you want: group members can now write into the directory. + +Now you can try and copy an image or, indeed, any other file to the directory and it should go through without a problem: +``` +cp image.jpg /photos + +``` + +The _guest_ user will also be able to read and write from the directory. They will also be able to read and write to it, and even move or delete files created by other users within the shared directory. + +### Conclusion + +The permissions and privileges system in Linux has been honed over decades. inherited as it is from the old Unix systems of yore. As such, it works very well and is well thought out. Becoming familiar with it is essential for any Linux sysadmin. In fact, you can't do much admining at all unless you understand it. But, it's not that hard. + +Next time, we'll be dive into files and see the different ways of creating, manipulating, and destroying them in creative ways. Always fun, that last one. + +See you then! + +Learn more about Linux through the free ["Introduction to Linux" ][4]course from The Linux Foundation and edX. + +-------------------------------------------------------------------------------- + +via: https://www.linux.com/blog/learn/intro-to-linux/2018/7/users-groups-and-other-linux-beasts-part-2 + +作者:[Paul Brown][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.linux.com/users/bro66 +[1]:https://www.linux.com/blog/learn/2018/5/manipulating-directories-linux +[2]:https://www.linux.com/learn/intro-to-linux/2018/7/users-groups-and-other-linux-beasts +[3]:https://www.linux.com/learn/understanding-linux-file-permissions +[4]:https://training.linuxfoundation.org/linux-courses/system-administration-training/introduction-to-linux diff --git a/sources/tech/20180719 Building tiny container images.md b/sources/tech/20180719 Building tiny container images.md new file mode 100644 index 0000000000..bdaef5f08c --- /dev/null +++ b/sources/tech/20180719 Building tiny container images.md @@ -0,0 +1,362 @@ +Building tiny container images +====== + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/containers_scale_performance.jpg?itok=R7jyMeQf) + +When [Docker][1] exploded onto the scene a few years ago, it brought containers and container images to the masses. Although Linux containers existed before then, Docker made it easy to get started with a user-friendly command-line interface and an easy-to-understand way to build images using the Dockerfile format. But while it may be easy to jump in, there are still some nuances and tricks to building container images that are usable, even powerful, but still small in size. + +### First pass: Clean up after yourself + +Some of these examples involve the same kind of cleanup you would use with a traditional server, but more rigorously followed. Smaller image sizes are critical for quickly moving images around, and storing multiple copies of unnecessary data on disk is a waste of resources. Consequently, these techniques should be used more regularly than on a server with lots of dedicated storage. + +An example of this kind of cleanup is removing cached files from an image to recover space. Consider the difference in size between a base image with [Nginx][2] installed by `dnf` with and without the metadata and yum cache cleaned up: +``` +# Dockerfile with cache + +FROM fedora:28 + +LABEL maintainer Chris Collins + + + +RUN dnf install -y nginx + + + +----- + + + +# Dockerfile w/o cache + +FROM fedora:28 + +LABEL maintainer Chris Collins + + + +RUN dnf install -y nginx \ + +        && dnf clean all \ + +        && rm -rf /var/cache/yum + + + +----- + + + +[chris@krang] $ docker build -t cache -f Dockerfile .   + +[chris@krang] $ docker images --format "{{.Repository}}: {{.Size}}" + +| head -n 1 + +cache: 464 MB + + + +[chris@krang] $ docker build -t no-cache -f Dockerfile-wo-cache . + +[chris@krang] $ docker images --format "{{.Repository}}: {{.Size}}"  | head -n 1 + +no-cache: 271 MB + +``` + +That is a significant difference in size. The version with the `dnf` cache is almost twice the size of the image without the metadata and cache. Package manager cache, Ruby gem temp files, `nodejs` cache, even downloaded source tarballs are all perfect candidates for cleaning up. + +### Layers—a potential gotcha + +Unfortunately (or fortunately, as you’ll see later), based on the way layers work with containers, you cannot simply add a `RUN rm -rf /var/cache/yum` line to your Dockerfile and call it a day. Each instruction of a Dockerfile is stored in a layer, with changes between layers applied on top. So even if you were to do this: +``` +RUN dnf install -y nginx + +RUN dnf clean all + +RUN rm -rf /var/cache/yum + +``` + +...you’d still end up with three layers, one of which contains all the cache, and two intermediate layers that "remove" the cache from the image. But the cache is actually still there, just as when you mount a filesystem over the top of another one, the files are there—you just can’t see or access them. + +You’ll notice that the example in the previous section chains the cache cleanup in the same Dockerfile instruction where the cache is generated: +``` +RUN dnf install -y nginx \ + +        && dnf clean all \ + +        && rm -rf /var/cache/yum + +``` + +This is a single instruction and ends up being a single layer within the image. You’ll lose a bit of the Docker (*ahem*) cache this way, making a rebuild of the image slightly longer, but the cached data will not end up in your final image. As a nice compromise, just chaining related commands (e.g., `yum install` and `yum clean all`, or downloading, extracting and removing a source tarball, etc.) can save a lot on your final image size while still allowing you to take advantage of the Docker cache for quicker development. + +This layer "gotcha" is more subtle than it first appears, though. Because the image layers document the _changes_ to each layer, one upon another, it’s not just the existence of files that add up, but any change to the file. For example, _even changing the mode_ of the file creates a copy of that file in the new layer. + +For example, the output of `docker images` below shows information about two images. The first, `layer_test_1`, was created by adding a single 1GB file to a base CentOS image. The second image, `layer_test_2`, was created `FROM layer_test_1` and did nothing but change the mode of the 1GB file with `chmod u+x`. +``` +layer_test_2        latest       e11b5e58e2fc           7 seconds ago           2.35 GB + +layer_test_1        latest       6eca792a4ebe           2 minutes ago           1.27 GB + +``` + +As you can see, the new image is more than 1GB larger than the first. Despite the fact that `layer_test_1` is only the first two layers of `layer_test_2`, there’s still an extra 1GB file floating around hidden inside the second image. This is true anytime you remove, move, or change any file during the image build process. + +### Purpose-built images vs. flexible images + +An anecdote: As my office heavily invested in [Ruby on Rails][3] applications, we began to embrace the use of containers. One of the first things we did was to create an official Ruby base image for all of our teams to use. For simplicity’s sake (and suffering under “this is the way we did it on our servers”), we used [rbenv][4] to install the latest four versions of Ruby into the image, allowing our developers to migrate all of their applications into containers using a single image. This resulted in a very large but flexible (we thought) image that covered all the bases of the various teams we were working with. + +This turned out to be wasted work. The effort required to maintain separate, slightly modified versions of a particular image was easy to automate, and selecting a specific image with a specific version actually helped to identify applications approaching end-of-life before a breaking change was introduced, wreaking havoc downstream. It also wasted resources: When we started to split out the different versions of Ruby, we ended up with multiple images that shared a single base and took up very little extra space if they coexisted on a server, but were considerably smaller to ship around than a giant image with multiple versions installed. + +That is not to say building flexible images is not helpful, but in this case, creating purpose-build images from a common base ended up saving both storage space and maintenance time, and each team could modify their setup however they needed while maintaining the benefit of the common base image. + +### Start without the cruft: Add what you need to a blank image + +As friendly and easy-to-use as the _Dockerfile_ is, there are tools available that offer the flexibility to create very small Docker-compatible container images without the cruft of a full operating system—even those as small as the standard Docker base images. + +[I’ve written about Buildah before][5], and I’ll mention it again because it is flexible enough to create an image from scratch using tools from your host to install packaged software and manipulate the image. Those tools then never need to be included in the image itself. + +Buildah replaces the `docker build` command. With it, you can mount the filesystem of your container image to your host machine and interact with it using tools from the host. + +Let’s try Buildah with the Nginx example from above (ignoring caches for now): +``` +#!/usr/bin/env bash + +set -o errexit + + + +# Create a container + +container=$(buildah from scratch) + + + +# Mount the container filesystem + +mountpoint=$(buildah mount $container) + + + +# Install a basic filesystem and minimal set of packages, and nginx + +dnf install --installroot $mountpoint  --releasever 28 glibc-minimal-langpack nginx --setopt install_weak_deps=false -y + + + +# Save the container to an image + +buildah commit --format docker $container nginx + + + +# Cleanup + +buildah unmount $container + + + +# Push the image to the Docker daemon’s storage + +buildah push nginx:latest docker-daemon:nginx:latest + +``` + +You’ll notice we’re no longer using a Dockerfile to build the image, but a simple Bash script, and we’re building it from a scratch (or blank) image. The Bash script mounts the container’s root filesystem to a mount point on the host, and then uses the hosts’ command to install the packages. This way the package manager doesn’t even have to exist inside the container. + +Without extra cruft—all the extra stuff in the base image, like `dnf`, for example—the image weighs in at only 304 MB, more than 100 MB smaller than the Nginx image built with a Dockerfile above. +``` +[chris@krang] $ docker images |grep nginx + +docker.io/nginx      buildah      2505d3597457    4 minutes ago         304 MB + +``` + +_Note: The image name has`docker.io` appended to it due to the way the image is pushed into the Docker daemon’s namespace, but it is still the image built locally with the build script above._ + +That 100 MB is already a huge savings when you consider a base image is already around 300 MB on its own. Installing Nginx with a package manager brings in a ton of dependencies, too. For something compiled from source using tools from the host, the savings can be even greater because you can choose the exact dependencies and not pull in any extra files you don’t need. + +If you’d like to try this route, [Tom Sweeney][6] wrote a much more in-depth article, [Creating small containers with Buildah][7], which you should check out. + +Using Buildah to build images without a full operating system and included build tools can enable much smaller images than you would otherwise be able to create. For some types of images, we can take this approach even further and create images with _only_ the application itself included. + +### Create images with only statically linked binaries + +Following the same philosophy that leads us to ditch administrative and build tools inside images, we can go a step further. If we specialize enough and abandon the idea of troubleshooting inside of production containers, do we need Bash? Do we need the [GNU core utilities][8]? Do we _really_ need the basic Linux filesystem? You can do this with any compiled language that allows you to create binaries with [statically linked libraries][9]—where all the libraries and functions needed by the program are copied into and stored within the binary itself. + +This is a relatively popular way of doing things within the [Golang][10] community, so we’ll use a Go application to demonstrate. + +The Dockerfile below takes a small Go Hello-World application and compiles it in an image `FROM golang:1.8`: +``` +FROM golang:1.8 + + + +ENV GOOS=linux + +ENV appdir=/go/src/gohelloworld + + + +COPY ./ /go/src/goHelloWorld + +WORKDIR /go/src/goHelloWorld + + + +RUN go get + +RUN go build -o /goHelloWorld -a + + + +CMD ["/goHelloWorld"] + +``` + +The resulting image, containing the binary, the source code, and the base image layer comes in at 716 MB. The only thing we actually need for our application is the compiled binary, however. Everything else is unused cruft that gets shipped around with our image. + +If we disable `cgo` with `CGO_ENABLED=0` when we compile, we can create a binary that doesn’t wrap C libraries for some of its functions: +``` +GOOS=linux CGO_ENABLED=0 go build -a goHelloWorld.go + +``` + +The resulting binary can be added to an empty, or "scratch" image: +``` +FROM scratch + +COPY goHelloWorld / + +CMD ["/goHelloWorld"] + +``` + +Let’s compare the difference in image size between the two: +``` +[ chris@krang ] $ docker images + +REPOSITORY      TAG             IMAGE ID                CREATED                 SIZE + +goHello     scratch     a5881650d6e9            13 seconds ago          1.55 MB + +goHello     builder     980290a100db            14 seconds ago          716 MB + +``` + +That’s a huge difference. The image built from `golang:1.8` with the `goHelloWorld` binary in it (tagged "builder" above) is _460_ times larger than the scratch image with just the binary. The entirety of the scratch image with the binary is only 1.55 MB. That means we’d be shipping around 713 MB of unnecessary data if we used the builder image. + +As mentioned above, this method of creating small images is used often in the Golang community, and there is no shortage of blog posts on the subject. [Kelsey Hightower][11] wrote [an article on the subject][12] that goes into more detail, including dealing with dependencies other than just C libraries. + +### Consider squashing, if it works for you + +There’s an alternative to chaining all the commands into layers in an attempt to save space: Squashing your image. When you squash an image, you’re really exporting it, removing all the intermediate layers, and saving a single layer with the current state of the image. This has the advantage of reducing that image to a much smaller size. + +Squashing layers used to require some creative workarounds to flatten an image—exporting the contents of a container and re-importing it as a single layer image, or using tools like `docker-squash`. Starting in version 1.13, Docker introduced a handy flag, `--squash`, to accomplish the same thing during the build process: +``` +FROM fedora:28 + +LABEL maintainer Chris Collins + + + +RUN dnf install -y nginx + +RUN dnf clean all + +RUN rm -rf /var/cache/yum + + + +[chris@krang] $ docker build -t squash -f Dockerfile-squash --squash . + +[chris@krang] $ docker images --format "{{.Repository}}: {{.Size}}"  | head -n 1 + +squash: 271 MB + +``` + +Using `docker squash` with this multi-layer Dockerfile, we end up with another 271MB image, as we did with the chained instruction example. This works great for this use case, but there’s a potential gotcha. + +“What? ANOTHER gotcha?” + +Well, sort of—it’s the same issue as before, causing problems in another way. + +### Going too far: Too squashed, too small, too specialized + +Images can share layers. The base may be _x_ megabytes in size, but it only needs to be pulled/stored once and each image can use it. The effective size of all the images sharing layers is the base layers plus the diff of each specific change on top of that. In this way, thousands of images may take up only a small amount more than a single image. + +This is a drawback with squashing or specializing too much. When you squash an image into a single layer, you lose any opportunity to share layers with other images. Each image ends up being as large as the total size of its single layer. This might work well for you if you use only a few images and run many containers from them, but if you have many diverse images, it could end up costing you space in the long run. + +Revisiting the Nginx squash example, we can see it’s not a big deal for this case. We end up with Fedora, Nginx installed, no cache, and squashing that is fine. Nginx by itself is not incredibly useful, though. You generally need customizations to do anything interesting—e.g., configuration files, other software packages, maybe some application code. Each of these would end up being more instructions in the Dockerfile. + +With a traditional image build, you would have a single base image layer with Fedora, a second layer with Nginx installed (with or without cache), and then each customization would be another layer. Other images with Fedora and Nginx could share these layers. + +Need an image: +``` +[   App 1 Layer (  5 MB) ]          [   App 2 Layer (6 MB) ] + +[   Nginx Layer ( 21 MB) ] ------------------^ + +[ Fedora  Layer (249 MB) ]   + +``` + +But if you squash the image, then even the Fedora base layer is squashed. Any squashed image based on Fedora has to ship around its own Fedora content, adding another 249 MB for _each image!_ +``` +[ Fedora + Nginx + App 1 (275 MB)]      [ Fedora + Nginx + App 2 (276 MB) ]   + +``` + +This also becomes a problem if you build lots of highly specialized, super-tiny images. + +As with everything in life, moderation is key. Again, thanks to how layers work, you will find diminishing returns as your container images become smaller and more specialized and can no longer share base layers with other related images. + +Images with small customizations can share base layers. As explained above, the base may be _x_ megabytes in size, but it only needs to be pulled/stored once and each image can use it. The effective size of all the images is the base layers plus the diff of each specific change on top of that. In this way, thousands of images may take up only a small amount more than a single image. +``` +[ specific app   ]      [ specific app 2 ] + +[ customizations ]--------------^ + +[ base layer     ] + +``` + +If you go too far with your image shrinking and you have too many variations or specializations, you can end up with many images, none of which share base layers and all of which take up their own space on disk. +``` + [ specific app 1 ]     [ specific app 2 ]      [ specific app 3 ] + +``` + +### Conclusion + +There are a variety of different ways to reduce the amount of storage space and bandwidth you spend working with container images, but the most effective way is to reduce the size of the images themselves. Whether you simply clean up your caches (avoiding leaving them orphaned in intermediate layers), squash all your layers into one, or add only static binaries in an empty image, it’s worth spending some time looking at where bloat might exist in your container images and slimming them down to an efficient size. + + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/7/building-container-images + +作者:[Chris Collins][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://opensource.com/users/clcollins +[1]:https://www.docker.com/ +[2]:https://www.nginx.com/ +[3]:https://rubyonrails.org/ +[4]:https://github.com/rbenv/rbenv +[5]:https://opensource.com/article/18/6/getting-started-buildah +[6]:https://twitter.com/TSweeneyRedHat +[7]:https://opensource.com/article/18/5/containers-buildah +[8]:https://www.gnu.org/software/coreutils/coreutils.html +[9]:https://en.wikipedia.org/wiki/Static_library +[10]:https://golang.org/ +[11]:https://twitter.com/kelseyhightower +[12]:https://medium.com/@kelseyhightower/optimizing-docker-images-for-static-binaries-b5696e26eb07 diff --git a/sources/tech/20180720 A brief history of text-based games and open source.md b/sources/tech/20180720 A brief history of text-based games and open source.md new file mode 100644 index 0000000000..2b8728fb39 --- /dev/null +++ b/sources/tech/20180720 A brief history of text-based games and open source.md @@ -0,0 +1,142 @@ +A brief history of text-based games and open source +====== + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/compass_map_explore_adventure.jpg?itok=ecCoVTrZ) + +The [Interactive Fiction Technology Foundation][1] (IFTF) is a non-profit organization dedicated to the preservation and improvement of technologies enabling the digital art form we call interactive fiction. When a Community Moderator for Opensource.com suggested an article about IFTF, the technologies and services it supports, and how it all intersects with open source, I found it a novel angle to the decades-long story I’ve so often told. The history of IF is longer than—but quite enmeshed with—the modern FOSS movement. I hope you’ll enjoy my sharing it here. + +### Definitions and history + +To me, the term interactive fiction includes any video game or digital artwork whose audience interacts with it primarily through text. The term originated in the 1980s when parser-driven text adventure games—epitomized in the United States by [Zork][2], [The Hitchhiker’s Guide to the Galaxy][3], and the rest of [Infocom][4]’s canon—defined home-computer entertainment. Its mainstream commercial viability had guttered by the 1990s, but online hobbyist communities carried on the tradition, releasing both games and game-creation tools. + +After a quarter century, interactive fiction now comprises a broad and sparkling variety of work, from puzzle-laden text adventures to sprawling and introspective hypertexts. Regular online competitions and festivals provide a great place to peruse and play new work: The English-language IF world enjoys annual events including [Spring Thing][5] and [IFComp][6], the latter a centerpiece of modern IF since 1995—which also makes it the longest-lived continually running game showcase event of its kind in any genre. [IFComp’s crop of judged-and-ranked entries from 2017][7] shows the amazing diversity in form, style, and subject matter that text-based games boast today. + +(I specify "English-language" above because IF communities tend to self-segregate by language, perhaps due to the technology's focus on writing. There are also annual IF events in [French][8] and [Italian][9], for example, and I've heard of at least one Chinese IF festival. Happily, these borders are porous; during the four years I managed IFComp, it has welcomed English-translated work from all international communities.) + +![counterfeit monkey game screenshot][11] + +Starting a new game of Emily Short's "Counterfeit Monkey," running on the interpreter Lectrote (both open source software). + +Also due to its focus on text, IF presents some of the most accessible platforms for both play and authorship. Almost anyone who can read digital text—including users of assistive technology such as text-to-speech software—can play most IF works. Likewise, IF creation is open to all writers willing to learn and work with its tools and techniques. + +This brings us to IF’s long relationship with open source, which has helped enable the art form’s availability since its commercial heyday. I'll provide an overview of contemporary open-source IF creation tools, and then discuss the ancient and sometimes curious tradition of IF works that share their source code. + +### The world of open source IF tools + +A number of development platforms, most of which are open source, are available to create traditional parser-driven IF in which the user types commands—for example, `go north,` `get lamp`, `pet the cat`, or `ask Zoe about quantum mechanics`—to interact with the game’s world. The early 1990s saw the emergence of several hacker-friendly parser-game development kits; those still in use today include [TADS][12], [Alan][13], and [Quest][14]—all open, with the latter two bearing FOSS licenses. + +But by far the most prominent of these is [Inform][15], first released by Graham Nelson in 1993 and now maintained by a team Nelson still leads. Inform source is semi-open, in an unusual fashion: Inform 6, the previous major version, [makes its source available through the Artistic License][16]. This has more immediate relevance than may be obvious, since the otherwise proprietary Inform 7 holds Inform 6 at its core, translating its [remarkable natural-language syntax][17] into its predecessor’s more C-like code before letting it compile the work down into machine code. + +![inform 7 IDE screenshot][19] + +The Inform 7 IDE, loaded up with documentation and a sample project. + +Inform games run on a virtual machine, a relic of the Infocom era when that publisher targeted a VM so that it could write a single game that would run on Apple II, Commodore 64, Atari 800, and other flavors of the "[home computer][20]." Fewer popular operating systems exist today, but Inform’s virtual machines—the relatively modern [Glulx][21] or the charmingly antique [Z-machine][22], a reverse-engineered clone of Infocom’s historical VM—let Inform-created work run on any computer with an Inform interpreter. Currently, popular cross-platform interpreters include desktop programs like [Lectrote][23] and [Gargoyle][24] or browser-based ones like [Quixe][25] and [Parchment][26]. All are open source. + +If the pace of Inform’s development has slowed in its maturity, it remains vital through an active and transparent ecosystem—just like any other popular open source project. In Inform’s case, this includes the aforementioned interpreters, [a collection of language extensions][27] (usually written in a mix of Inform 6 and 7), and of course, all the work created with it and shared with the world, sometimes with source included (I’ll return to that topic later in this article). + +IF creation tools invented in the 21st century tend to explore player interactions outside of the traditional parser, generating hypertext-driven work that any modern web browser can load. Chief among these is [Twine][28], originally developed by Chris Klimas in 2009 and under active development by many contributors today as [a GNU-licensed open source project][29]. (In fact, [Twine][30] can trace its OSS lineage back to [TiddlyWiki][31], the project from which Klimas initially derived it.) + +Twine represents a sort of maximally [open and accessible approach][30] to IF development: Beyond its own FOSS nature, it renders its output as self-contained websites, relying not on machine code requiring further specialized interpretation but the open and well-exercised standards of HTML, CSS, and JavaScript. As a creative tool, Twine can match its own exposed complexity to the creator’s skill level. Users with little or no programming knowledge can create simple but playable IF work, while those with more coding and design skills—including those developing these skills by making Twine games—can develop more sophisticated projects. Little wonder that Twine’s visibility and popularity in educational contexts has grown quite a bit in recent years. + +Other noteworthy open source IF development projects include the MIT-licensed [Undum][32] by Ian Millington, and [ChoiceScript][33] by Dan Fabulich and the [Choice of Games][34] team—both of which also target the web browser as the gameplay platform. Looking beyond strict development systems like these, web-based IF gives us a rich and ever-churning ecosystem of open source work, such as furkle’s [collection of Twine-extending tools][35] and Liza Daly’s [Windrift][36], a JavaScript framework purpose-built for her own IF games. + +### Programs, games, and game-programs + +Twine benefits from [a standing IFTF program dedicated to its support][37], allowing the public to help fund its maintenance and development. IFTF also directly supports two long-time public services, IFComp and the IF Archive, both of which depend upon and contribute back into open software and technologies. + +![Harmonia opening screen shot][39] + +The opening of Liza Daly's "Harmonia," created with the Windrift open source IF-creation framework. + +The Perl- and JavaScript-based application that runs the IFComp’s website has been [a shared-source project][40] since 2014, and it reflects [the stew of FOSS licenses used by its IF-specific sub-components][41], including the various code libraries that allow parser-driven competition entries to run in a web browser. [The IF Archive][42]—online since 1992 and [an IFTF project since 2017][43]—is a set of mirrored repositories based entirely on ancient and stable internet standards, with [a little open source Python script][44] to handle indexing. + +### At last, the fun part: Let's talk about open source text games + +The bulk of the archive [comprises games][45], of course—years and years of games, reflecting decades of evolving game-design trends and IF tool development. + +Lots of IF work shares its source code, and the community’s quick-start solution for finding it is simple: [Search the IFDB for the tag "source available"][46]. (The IFDB is yet another long-running IF community service, run privately by TADS creator Mike Roberts.) Users who are comfortable with a more bare-bones interface may also wish to browse [the `/games/source` directory][47] of the IF Archive, which groups content by development platform and written language (there's also a lot of work either too miscellaneous or too ancient to categorize floating at the top). + +A little bit of random sampling of these code-sharing games reveals an interesting dilemma: Unlike the wider world of open source software, the IF community lacks a generally agreed-upon way of licensing all the code that it generates. Unlike a software tool—including all the tools we use to build IF—an interactive fiction game is a work of art in the most literal sense, meaning that an open source license intended for software would fit it no better than it would any other work of prose or poetry. But then again, an IF game is also a piece of software, and it exhibits source-code patterns and techniques that its creator may legitimately wish to share with the world. What is an open source-aware IF creator to do? + +Some games address this by passing their code into the public domain, either through explicit license or—as in the case of [the original 42-year-old Adventure by Crowther and Woods][48]—through community fiat. Some try to split the difference, rolling their own license that allows for free re-use of a game’s exposed business logic but prohibits the creation of work derived specifically from its prose. This is the tack I took when I opened up the source of my own game, [The Warbler’s Nest][49]. Lord knows how well that’d stand up in court, but I didn’t have any better ideas at the time. + +Naturally, you can find work that simply puts everything under a single common license and never mind the naysayers. A prominent example is [Emily Short’s epic Counterfeit Monkey][50], released in its entirety under a Creative Commons 4.0 license. [CC frowns at its application to code][51], but you could argue that [the strangely prose-like nature of Inform 7 source][52] makes it at least a little more compatible with a CC license than a more traditional software project would be. + +### What now, adventurer? + +If you are eager to start exploring the world of interactive fiction, here are a few links to check out: + + ++ As mentioned above, IFDB and the IF Archive both present browsable interfaces to more than 40 years worth of collected interactive fiction work. Much of this is playable in a web browser, but some require additional interpreter programs. IFDB can help you find and install these. + + IFComp’s annual results pages provide another view into the best of this free and archive-available work. + ++ The Interactive Fiction Technology Foundation is a charitable non-profit organization that helps support Twine, IFComp, and the IF Archive, as well as improve the accessibility of IF, explore IF’s use in education, and more. Join its mailing list to receive IFTF’s monthly newsletter, peruse its blog, and browse some thematic merchandise. + ++ John Paul Wohlscheid wrote this article about open-source IF tools earlier this year. It covers some platforms not mentioned here, so if you’re still hungry for more, have a look. + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/7/interactive-fiction-tools + +作者:[Jason Mclntosh][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://opensource.com/users/jmac +[1]:http://iftechfoundation.org/ +[2]:https://en.wikipedia.org/wiki/Zork +[3]:https://en.wikipedia.org/wiki/The_Hitchhiker%27s_Guide_to_the_Galaxy_(video_game) +[4]:https://en.wikipedia.org/wiki/Infocom +[5]:http://www.springthing.net/ +[6]:http://ifcomp.org/ +[7]:https://ifcomp.org/comp/2017 +[8]:http://www.fiction-interactive.fr/ +[9]:http://www.oldgamesitalia.net/content/marmellata-davventura-2018 +[10]:/file/403396 +[11]:https://opensource.com/sites/default/files/uploads/monkey.png (counterfeit monkey game screenshot) +[12]:http://tads.org/ +[13]:https://www.alanif.se/ +[14]:http://textadventures.co.uk/quest/ +[15]:http://inform7.com/ +[16]:https://github.com/DavidKinder/Inform6 +[17]:http://inform7.com/learn/man/RB_4_1.html#e307 +[18]:/file/403386 +[19]:https://opensource.com/sites/default/files/uploads/inform.png (inform 7 IDE screenshot) +[20]:https://www.youtube.com/watch?v=bu55q_3YtOY +[21]:http://ifwiki.org/index.php/Glulx +[22]:http://ifwiki.org/index.php/Z-machine +[23]:https://github.com/erkyrath/lectrote +[24]:https://github.com/garglk/garglk/ +[25]:http://eblong.com/zarf/glulx/quixe/ +[26]:https://github.com/curiousdannii/parchment +[27]:https://github.com/i7/extensions +[28]:http://twinery.org/ +[29]:https://github.com/klembot/twinejs +[30]:/article/18/7/twine-vs-renpy-interactive-fiction +[31]:https://tiddlywiki.com/ +[32]:https://github.com/idmillington/undum +[33]:https://github.com/dfabulich/choicescript +[34]:https://www.choiceofgames.com/ +[35]:https://github.com/furkle +[36]:https://github.com/lizadaly/windrift +[37]:http://iftechfoundation.org/committees/twine/ +[38]:/file/403391 +[39]:https://opensource.com/sites/default/files/uploads/harmonia.png (Harmonia opening screen shot) +[40]:https://github.com/iftechfoundation/ifcomp +[41]:https://github.com/iftechfoundation/ifcomp/blob/master/LICENSE.md +[42]:https://www.ifarchive.org/ +[43]:http://blog.iftechfoundation.org/2017-06-30-iftf-is-adopting-the-if-archive.html +[44]:https://github.com/iftechfoundation/ifarchive-ifmap-py +[45]:https://www.ifarchive.org/indexes/if-archiveXgames +[46]:http://ifdb.tads.org/search?sortby=ratu&searchfor=%22source+available%22 +[47]:https://www.ifarchive.org/indexes/if-archiveXgamesXsource.html +[48]:http://ifdb.tads.org/viewgame?id=fft6pu91j85y4acv +[49]:https://github.com/jmacdotorg/warblers-nest/ +[50]:https://github.com/i7/counterfeit-monkey +[51]:https://creativecommons.org/faq/#can-i-apply-a-creative-commons-license-to-software +[52]:https://github.com/i7/counterfeit-monkey/blob/master/Counterfeit%20Monkey.materials/Extensions/Counterfeit%20Monkey/Liquids.i7x diff --git a/sources/tech/20180723 Setting Up a Timer with systemd in Linux.md b/sources/tech/20180723 Setting Up a Timer with systemd in Linux.md new file mode 100644 index 0000000000..27841dec61 --- /dev/null +++ b/sources/tech/20180723 Setting Up a Timer with systemd in Linux.md @@ -0,0 +1,165 @@ +Setting Up a Timer with systemd in Linux +====== + +![](https://www.linux.com/sites/lcom/files/styles/rendered_file/public/clock-650753_1920.jpg?itok=RiRyCbAP) + +Previously, we saw how to enable and disable systemd services [by hand][1], [at boot time and on power down][2], [when a certain device is activated][3], and [when something changes in the filesystem][4]. + +Timers add yet another way of starting services, based on... well, time. Although similar to cron jobs, systemd timers are slightly more flexible. Let's see how they work. + +### "Run when" + +Let's expand the [Minetest][5] [service you set up][1] in [the first two articles of this series][2] as our first example on how to use timer units. If you haven't read those articles yet, you may want to go and give them a look now. + +So you will "improve" your Minetest set up by creating a timer that will run the game's server 1 minute after boot up has finished instead of right away. The reason for this could be that, as you want your service to do other stuff, like send emails to the players telling them the game is available, you will want to make sure other services (like the network) are fully up and running before doing anything fancy. + +Jumping in at the deep end, your _minetest.timer_ unit will look like this: +``` +# minetest.timer +[Unit] +Description=Runs the minetest.service 1 minute after boot up + +[Timer] +OnBootSec=1 m +Unit=minetest.service + +[Install] +WantedBy=basic.target + +``` + +Not hard at all. + +As usual, you have a `[Unit]` section with a description of what the unit does. Nothing new there. The `[Timer]` section is new, but it is pretty self-explanatory: it contains information on when the service will be triggered and the service to trigger. In this case, the `OnBootSec` is the directive you need to tell systemd to run the service after boot has finished. + +Other directives you could use are: + + * `OnActiveSec=`, which tells systemd how long to wait after the timer itself is activated before starting the service. + * `OnStartupSec=`, on the other hand, tells systemd how long to wait after systemd was started before starting the service. + * `OnUnitActiveSec=` tells systemd how long to wait after the service the timer is activating was last activated. + * `OnUnitInactiveSec=` tells systemd how long to wait after the service the timer is activating was last deactivated. + + + +Continuing down the _minetest.timer_ unit, the `basic.target` is usually used as a synchronization point for late boot services. This means it makes _minetest.timer_ wait until local mount points and swap devices are mounted, sockets, timers, path units and other basic initialization processes are running before letting _minetest.timer_ start. As we explained in [the second article on systemd units][2], _targets_ are like the old run levels and can be used to put your machine into one state or another, or, like here, to tell your service to wait until a certain state has been reached. + +The _minetest.service_ you developed in the first two articles [ended up][2] looking like this: +``` +# minetest.service +[Unit] +Description= Minetest server +Documentation= https://wiki.minetest.net/Main_Page + +[Service] +Type= simple +User= + +ExecStart= /usr/games/minetest --server +ExecStartPost= /home//bin/mtsendmail.sh "Ready to rumble?" "Minetest Starting up" + +TimeoutStopSec= 180 +ExecStop= /home//bin/mtsendmail.sh "Off to bed. Nightie night!" "Minetest Stopping in 2 minutes" +ExecStop= /bin/sleep 120 +ExecStop= /bin/kill -2 $MAINPID + +[Install] +WantedBy= multi-user.target + +``` + +There’s nothing you need to change here. But you do have to change _mtsendmail.sh_ (your email sending script) from this: +``` +#!/bin/bash +# mtsendmail +sleep 20 +echo $1 | mutt -F /home//.muttrc -s "$2" my_minetest@mailing_list.com +sleep 10 + +``` + +to this: +``` +#!/bin/bash +# mtsendmail.sh +echo $1 | mutt -F /home/paul/.muttrc -s "$2" pbrown@mykolab.com + +``` + +What you are doing is stripping out those hacky pauses in the Bash script. Systemd does the waiting now. + +### Making it work + +To make sure things work, disable _minetest.service_ : +``` +sudo systemctl disable minetest + +``` + +so it doesn't get started when the system starts; and, instead, enable _minetest.timer_ : +``` +sudo systemctl enable minetest.timer + +``` + +Now you can reboot you server machine and, when you run `sudo journalctl -u minetest.*` you will see how, first the _minetest.timer_ unit gets executed and then the _minetest.service_ starts up after a minute... more or less. + +![minetest timer][7] + +Figure 1: The minetest.service gets started one minute after the minetest.timer... more or less. + +[Used with permission][8] + +### A Matter of Time + +A couple of clarifications about why the _minetest.timer_ entry in the systemd's Journal shows its start time as 09:08:33, while the _minetest.service_ starts at 09:09:18, that is less than a minute later: First, remember we said that the `OnBootSec=` directive calculates when to start a service from when boot is complete. By the time _minetest.timer_ comes along, boot has finished a few seconds ago. + +The other thing is that systemd gives itself a margin of error (by default, 1 minute) to run stuff. This helps distribute the load when several resource-intensive processes are running at the same time: by giving itself a minute, systemd can wait for some processes to power down. This also means that _minetest.service_ will start somewhere between the 1 minute and 2 minute mark after boot is completed, but when exactly within that range is anybody's guess. + +For the record, [you can change the margin of error with `AccuracySec=` directive][9]. + +Another thing you can do is check when all the timers on your system are scheduled to run or the last time the ran: +``` +systemctl list-timers --all + +``` + +![check timer][11] + +Figure 2: Check when your timers are scheduled to fire or when they fired last. + +[Used with permission][8] + +The final thing to take into consideration is the format you should use to express the periods of time. Systemd is very flexible in that respect: `2 h`, `2 hours` or `2hr` will all work to express a 2 hour delay. For seconds, you can use `seconds`, `second`, `sec`, and `s`, the same way as for minutes you can use `minutes`, `minute`, `min`, and `m`. You can see a full list of time units systemd understands by checking `man systemd.time`. + +### Next Time + +You'll see how to use calendar dates and times to run services at regular intervals and how to combine timers and device units to run services at defined point in time after you plug in some hardware. + +See you then! + +Learn more about Linux through the free ["Introduction to Linux" ][12]course from The Linux Foundation and edX. + +-------------------------------------------------------------------------------- + +via: https://www.linux.com/blog/learn/intro-to-linux/2018/7/setting-timer-systemd-linux + +作者:[Paul Brown][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.linux.com/users/bro66 +[1]:https://www.linux.com/blog/learn/intro-to-linux/2018/5/writing-systemd-services-fun-and-profit +[2]:https://www.linux.com/blog/learn/2018/5/systemd-services-beyond-starting-and-stopping +[3]:https://www.linux.com/blog/intro-to-linux/2018/6/systemd-services-reacting-change +[4]:https://www.linux.com/blog/learn/intro-to-linux/2018/6/systemd-services-monitoring-files-and-directories +[5]:https://www.minetest.net/ +[6]:/files/images/minetest-timer-1png +[7]:https://www.linux.com/sites/lcom/files/styles/rendered_file/public/minetest-timer-1.png?itok=TG0xJvYM (minetest timer) +[8]:/licenses/category/used-permission +[9]:https://www.freedesktop.org/software/systemd/man/systemd.timer.html#AccuracySec= +[10]:/files/images/minetest-timer-2png +[11]:https://www.linux.com/sites/lcom/files/styles/rendered_file/public/minetest-timer-2.png?itok=pYxyVx8- (check timer) +[12]:https://training.linuxfoundation.org/linux-courses/system-administration-training/introduction-to-linux diff --git a/sources/tech/20180723 System Snapshot And Restore Utility For Linux.md b/sources/tech/20180723 System Snapshot And Restore Utility For Linux.md new file mode 100644 index 0000000000..26630a372a --- /dev/null +++ b/sources/tech/20180723 System Snapshot And Restore Utility For Linux.md @@ -0,0 +1,237 @@ +System Snapshot And Restore Utility For Linux +====== +![](https://www.ostechnix.com/wp-content/uploads/2018/07/backup-restore-720x340.jpg) + +**CYA** , stands for **C** over **Y** our **A** ssets, is a free, open source system snapshot and restore utility for any Unix-like operating systems that uses BASH shell. Cya is portable and supports many popular filesystems such as EXT2/3/4, XFS, UFS, GPFS, reiserFS, JFS, BtrFS, and ZFS etc. Please note that **Cya will not backup the actual user data**. It only backups and restores the operating system itself and not your actual user data. **Cya is a system restore utility**. By default, it will backup all key directories like /bin/, /lib/, /usr/, /var/ and several others. You can, however, define your own directories and files path to include in the backup, so Cya will pick those up as well. Also, it is possible define some directories/files to skip from the backup. For example, you can skip /var/logs/ if you don’t log files. Cya actually uses **Rsync** backup method under the hood. However, Cya is super easier than Rsync when creating rolling backups. + +When restoring your operating system, Cya will rollback the OS using your backup profile which you created earlier. You can either restore the entire system or any specific directories only. Also, you can easily access the backup files even without a complete rollback using your terminal or file manager. ANother notable feature is we can generate a custom recovery script to automate the mounting of your system partition(s) when you restore off a live CD, USB, or network image. In a nutshell, CYA can help you to restore your system to previous states when you end-up with a broken system caused by software update, configuration changes, intrusions/hacks, etc. + +### Installing CYA + +Installing CYA is very easy. All you have to do is download Cya binary and put it in your system path. +``` +$ git clone https://github.com/cleverwise/cya.git + +``` + +This will clone the latest cya version in a directory called cya in your current working directory. + +Next, copy the cya binary to your path or wherever you want. +``` +$ sudo cp cya/cya /usr/local/bin/ + +``` + +CYA as been installed. Now let us go ahead and create snapshots. + +### Creating Snapshots + +Before creating any snapshots/backups, create a recovery script using command: +``` +$ cya script +☀ Cover Your Ass(ets) v2.2 ☀ + +ACTION ⯮ Generating Recovery Script + +Generating Linux recovery script ... +Checking sudo permissions... +Complete + +IMPORTANT: This script will ONLY mount / and /home. Thus if you are storing data on another mount point open the recovery.sh script and add the additional mount point command where necessary. This is also a best guess and should be tested before an emergency to verify it works as desired. + + +‣ Disclaimer: CYA offers zero guarantees as improper usage can cause undesired results +‣ Notice: Proper usage can correct unauthorized changes to system from attacks + +``` + +Save the resulting **recovery.sh** file in your USB drive which we are going to use it later when restoring backups. This script will help you to setup a chrooted environment and mount drives when you rollback your system. + +Now, let us create snapshots. + +To create a standard rolling backup, run: +``` +$ cya save + +``` + +The above command will keep **three backups** before overwriting. + +**Sample output:** +``` +☀ Cover Your Ass(ets) v2.2 ☀ + +ACTION ⯮ Standard Backup + +Checking sudo permissions... +[sudo] password for sk: +We need to create /home/cya/points/1 ... done +Backing up /bin/ ... complete +Backing up /boot/ ... complete +Backing up /etc/ ... complete +. +. +. +Backing up /lib/ ... complete +Backing up /lib64/ ... complete +Backing up /opt/ ... complete +Backing up /root/ ... complete +Backing up /sbin/ ... complete +Backing up /snap/ ... complete +Backing up /usr/ ... complete +Backing up /initrd.img ... complete +Backing up /initrd.img.old ... complete +Backing up /vmlinuz ... complete +Backing up /vmlinuz.old ... complete +Write out date file ... complete +Update rotation file ... complete + +‣ Disclaimer: CYA offers zero guarantees as improper usage can cause undesired results +‣ Notice: Proper usage can correct unauthorized changes to system from attacks + +``` + +You can view the contents of the newly created snapshot, under **/home/cya/points/** location. +``` +$ ls /home/cya/points/1/ +bin cya-date initrd.img lib opt sbin usr vmlinuz +boot etc initrd.img.old lib64 root snap var vmlinuz.old + +``` + +To create a backup with a custom name that will not be overwritten, run: +``` +$ cya keep name BACKUP_NAME + +``` + +Replace **BACKUP_NAME** with your own name. + +To create a backup with a custom name that will overwrite, do: +``` +$ cya keep name BACKUP_NAME overwrite + +``` + +To create a backup and archive and compress it, run: +``` +$ cya keep name BACKUP_NAME archive + +``` + +This command will store the backups in **/home/cya/archives** location. + +By default, CYA will store its configuration in **/home/cya/** directory and the snapshots with a custom name will be stored in **/home/cya/points/BACKUP_NAME** location. You can, however, change these settings by editing the CYA configuration file stored at **/home/cya/cya.conf**. + +Like I already said, CYA will not backup user data by default. It will only backup the important system files. You can, however, include your own directories or files along with system files. Say for example, if you wanted to add the directory named **/home/sk/Downloads** directory in the backup, edit **/home/cya/cya.conf** file: +``` +$ vi /home/cya/cya.conf + +``` + +Define your directory data path that you wanted to include in the backup like below. +``` +MYDATA_mybackup="/home/sk/Downloads/ /mnt/backup/sk/" + +``` + +Please be mindful that both source and destination directories should end with a trailing slash. As per the above configuration, CYA will copy all the contents of **/home/sk/Downloads/** directory and save them in **/mnt/backup/sk/** (assuming you already created this) directory. Here **mybackup** is the profile name. Save and close the file. + +Now to backup the contents of /home/sk/Downloads/ directory, you need to enter the profile name (i.e mybackup in my case) with the **cya mydata** command like below: +``` +$ cya mydata mybackup + +``` + +Similarly, you can include multiple user data with a different profile names. All profile names must be unique. + +### Exclude directories + +Some times, you may not want to backup all system files. You might want to exclude some unimportant such as log files. For example, if you don’t want to include **/var/tmp/** and **/var/logs/** directories, add the following in **/home/cya/cya.conf** file. +``` +EXCLUDE_/var/=”tmp/ logs/” + +``` + +Similarly, you can specify all directories one by one that you want to exclude from the backup. Once done, save and close the file. + +### Add specific files to the backup + +Instead of backing up whole directories, you can include a specific files from a directory. To do so, add the path of your files one by one in **/home/cya/cya.conf** file. +``` +BACKUP_FILES="/home/sk/Downloads/ostechnix.txt" + +``` + +### Restore your system + +Remember, we already create a recovery script named **recovery.sh** and saved it in an USB drive? Yeah, we will need it now to restore our broken system. + +Boot your system with any live bootable CD/DVD, USB drive. The developer of CYA recommends to use a live boot environment from same major version as your installed environment! For example if you use Ubuntu 18.04 system, then use Ubuntu 18.04 live media. + +Once you’re in the live system, mount the USB drive that contains the recovery.sh script. Once you mounted the drive(s), your system’s **/** and **/home** will be mounted to the **/mnt/cya** directory. This is made really easy and handled automatically by the **recovery.sh** script for Linux users. + +Then, start the restore process using command: +``` +$ sudo /mnt/cya/home/cya/cya restore + +``` + +Just follow the onscreen instructions. Once the restoration is done, remove the live media and unmount the drives and finally, reboot your system. + +What if you don’t have or lost recovery script? No problem, we still can restore our broken system. + +Boot the live media. From the live session, create a directory to mount the drive(s). +``` +$ sudo mkdir -p /mnt/cya + +``` + +Then, mount your **/** and **/home** (if on another partition) into the **/mnt/cya** directory. +``` +$ sudo mount /dev/sda1 /mnt/cya + +$ sudo mount /dev/sda3 /mnt/cya/home + +``` + +Replace /dev/sda1 and /dev/sda3 with your correct partitions (Use **fdisk -l** command to find your partitions). + +Finally, start the restoration process using command: +``` +$ sudo /mnt/cya/home/cya/cya restore + +``` + +Once the recovery is completed, unmount all mounted partitions and remove install media and reboot your system. + +At this stage, you might get a working system. I deleted some important libraries in Ubuntu 18.04 LTS server. I successfully restored it to the working state by using CYA utility. + +### Schedule CYA backup + +It is always recommended to use crontab to schedule the CYA snapshot process at regular interval. You can setup a cron job using root or setup a user that doesn’t need to enter a sudo password. + +The example entry below will run cya at every Monday at 2:05 am with output dumped into /dev/null. +``` +5 2 * * 1 /home/USER/bin/cya save >/dev/null 2>&1 + +``` + +And, that’s all for now. Unlike Systemback and other system restore utilities, Cya is not a distribution-specific restore utility. It supports many Linux operating systems that uses BASH. It is one of the must-have applications in your arsenal. Install it right away and create snapshots. You won’t regret when you accidentally crashed your Linux system. + +Cheers! + + + +-------------------------------------------------------------------------------- + +via: https://www.ostechnix.com/cya-system-snapshot-and-restore-utility-for-linux/ + +作者:[SK][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.ostechnix.com/author/sk/ diff --git a/sources/tech/20180724 75 Most Used Essential Linux Applications of 2018.md b/sources/tech/20180724 75 Most Used Essential Linux Applications of 2018.md new file mode 100644 index 0000000000..919182ba1f --- /dev/null +++ b/sources/tech/20180724 75 Most Used Essential Linux Applications of 2018.md @@ -0,0 +1,988 @@ +75 Most Used Essential Linux Applications of 2018 +====== + +**2018** has been an awesome year for a lot of applications, especially those that are both free and open source. And while various Linux distributions come with a number of default apps, users are free to take them out and use any of the free or paid alternatives of their choice. + +Today, we bring you a [list of Linux applications][3] that have been able to make it to users’ Linux installations almost all the time despite the butt-load of other alternatives. + +To simply put, any app on this list is among the most used in its category, and if you haven’t already tried it out you are probably missing out. Enjoy! + +### Backup Tools + +#### Rsync + +[Rsync][4] is an open source bandwidth-friendly utility tool for performing swift incremental file transfers and it is available for free. +``` +$ rsync [OPTION...] SRC... [DEST] + +``` + +To know more examples and usage, read our article “[10 Practical Examples of Rsync Command][5]” to learn more about it. + +#### Timeshift + +[Timeshift][6] provides users with the ability to protect their system by taking incremental snapshots which can be reverted to at a different date – similar to the function of Time Machine in Mac OS and System restore in Windows. + +![](https://www.fossmint.com/wp-content/uploads/2018/07/Timeshift-Create-Linux-Mint-Snapshot.png) + +### BitTorrent Client + +![](https://www.fossmint.com/wp-content/uploads/2018/07/Linux-Torrent-Clients.png) + +#### Deluge + +[Deluge][7] is a beautiful cross-platform BitTorrent client that aims to perfect the **μTorrent** experience and make it available to users for free. + +Install **Deluge** on **Ubuntu** and **Debian** , using following commands. +``` +$ sudo add-apt-repository ppa:deluge-team/ppa +$ sudo apt-get update +$ sudo apt-get install deluge + +``` + +#### qBittorent + +[qBittorent][8] is an open source BitTorrent protocol client that aims to provide a free alternative to torrent apps like μTorrent. + +Install **qBittorent** on **Ubuntu** and **Debian** , using following commands. +``` +$ sudo add-apt-repository ppa:qbittorrent-team/qbittorrent-stable +$ sudo apt-get update +$ sudo apt-get install qbittorrent + +``` + +#### Transmission + +[Transmission][9] is also a BitTorrent client with awesome functionalities and a major focus on speed and ease of use. It comes preinstalled with many Linux distros. + +Install **Transmission** on **Ubuntu** and **Debian** , using following commands. +``` +$ sudo add-apt-repository ppa:transmissionbt/ppa +$ sudo apt-get update +$ sudo apt-get install transmission-gtk transmission-cli transmission-common transmission-daemon + +``` + +### Cloud Storage + +![](https://www.fossmint.com/wp-content/uploads/2018/07/Linux-Cloud-Storage.png) + +#### Dropbox + +The [Dropbox][10] team rebranded their cloud service earlier this year to provide an even better performance and app integration for their clients. It starts with 2GB of storage for free. + +Install **Dropbox** on **Ubuntu** and **Debian** , using following commands. +``` +$ cd ~ && wget -O - "https://www.dropbox.com/download?plat=lnx.x86" | tar xzf - [On 32-Bit] +$ cd ~ && wget -O - "https://www.dropbox.com/download?plat=lnx.x86_64" | tar xzf - [On 64-Bit] +$ ~/.dropbox-dist/dropboxd + +``` + +#### Google Drive + +[Google Drive][11] is Google’s cloud service solution and my guess is that it needs no introduction. Just like with **Dropbox** , you can sync files across all your connected devices. It starts with 15GB of storage for free and this includes Gmail, Google photos, Maps, etc. + +Check out: [5 Google Drive Clients for Linux][12] + +#### Mega + +[Mega][13] stands out from the rest because apart from being extremely security-conscious, it gives free users 50GB to do as they wish! Its end-to-end encryption ensures that they can’t access your data, and if you forget your recovery key, you too wouldn’t be able to. + +[**Download MEGA Cloud Storage for Ubuntu][14] + +### Commandline Editors + +![](https://www.fossmint.com/wp-content/uploads/2018/07/Commandline-Editors.png) + +#### Vim + +[Vim][15] is an open source clone of vi text editor developed to be customizable and able to work with any type of text. + +Install **Vim** on **Ubuntu** and **Debian** , using following commands. +``` +$ sudo add-apt-repository ppa:jonathonf/vim +$ sudo apt update +$ sudo apt install vim + +``` + +#### Emacs + +[Emacs][16] refers to a set of highly configurable text editors. The most popular variant, GNU Emacs, is written in Lisp and C to be self-documenting, extensible, and customizable. + +Install **Emacs** on **Ubuntu** and **Debian** , using following commands. +``` +$ sudo add-apt-repository ppa:kelleyk/emacs +$ sudo apt update +$ sudo apt install emacs25 + +``` + +#### Nano + +[Nano][17] is a feature-rich CLI text editor for power users and it has the ability to work with different terminals, among other functionalities. + +Install **Nano** on **Ubuntu** and **Debian** , using following commands. +``` +$ sudo add-apt-repository ppa:n-muench/programs-ppa +$ sudo apt-get update +$ sudo apt-get install nano + +``` + +### Download Manager + +![](https://www.fossmint.com/wp-content/uploads/2018/07/Linux-Download-Managers.png) + +#### Aria2 + +[Aria2][18] is an open source lightweight multi-source and multi-protocol command line-based downloader with support for Metalinks, torrents, HTTP/HTTPS, SFTP, etc. + +Install **Aria2** on **Ubuntu** and **Debian** , using following command. +``` +$ sudo apt-get install aria2 + +``` + +#### uGet + +[uGet][19] has earned its title as the **#1** open source download manager for Linux distros and it features the ability to handle any downloading task you can throw at it including using multiple connections, using queues, categories, etc. + +Install **uGet** on **Ubuntu** and **Debian** , using following commands. +``` +$ sudo add-apt-repository ppa:plushuang-tw/uget-stable +$ sudo apt update +$ sudo apt install uget + +``` + +#### XDM + +[XDM][20], **Xtreme Download Manager** is an open source downloader written in Java. Like any good download manager, it can work with queues, torrents, browsers, and it also includes a video grabber and a smart scheduler. + +Install **XDM** on **Ubuntu** and **Debian** , using following commands. +``` +$ sudo add-apt-repository ppa:noobslab/apps +$ sudo apt-get update +$ sudo apt-get install xdman + +``` + +### Email Clients + +![](https://www.fossmint.com/wp-content/uploads/2018/07/Linux-Email-Clients.png) + +#### Thunderbird + +[Thunderbird][21] is among the most popular email applications. It is free, open source, customizable, feature-rich, and above all, easy to install. + +Install **Thunderbird** on **Ubuntu** and **Debian** , using following commands. +``` +$ sudo add-apt-repository ppa:ubuntu-mozilla-security/ppa +$ sudo apt-get update +$ sudo apt-get install thunderbird + +``` + +#### Geary + +[Geary][22] is an open source email client based on WebKitGTK+. It is free, open-source, feature-rich, and adopted by the GNOME project. + +Install **Geary** on **Ubuntu** and **Debian** , using following commands. +``` +$ sudo add-apt-repository ppa:geary-team/releases +$ sudo apt-get update +$ sudo apt-get install geary + +``` + +#### Evolution + +[Evolution][23] is a free and open source email client for managing emails, meeting schedules, reminders, and contacts. + +Install **Evolution** on **Ubuntu** and **Debian** , using following commands. +``` +$ sudo add-apt-repository ppa:gnome3-team/gnome3-staging +$ sudo apt-get update +$ sudo apt-get install evolution + +``` + +### Finance Software + +![](https://www.fossmint.com/wp-content/uploads/2018/07/Linux-Accounting-Software.png) + +#### GnuCash + +[GnuCash][24] is a free, cross-platform, and open source software for financial accounting tasks for personal and small to mid-size businesses. + +Install **GnuCash** on **Ubuntu** and **Debian** , using following commands. +``` +$ sudo sh -c 'echo "deb http://archive.getdeb.net/ubuntu $(lsb_release -sc)-getdeb apps" >> /etc/apt/sources.list.d/getdeb.list' +$ sudo apt-get update +$ sudo apt-get install gnucash + +``` + +#### KMyMoney + +[KMyMoney][25] is a finance manager software that provides all important features found in the commercially-available, personal finance managers. + +Install **KMyMoney** on **Ubuntu** and **Debian** , using following commands. +``` +$ sudo add-apt-repository ppa:claydoh/kmymoney2-kde4 +$ sudo apt-get update +$ sudo apt-get install kmymoney + +``` + +### IDE Editors + +![](https://www.fossmint.com/wp-content/uploads/2018/07/Linux-IDE-Editors.png) + +#### Eclipse IDE + +[Eclipse][26] is the most widely used Java IDE containing a base workspace and an impossible-to-overemphasize configurable plug-in system for personalizing its coding environment. + +For installation, read our article “[How to Install Eclipse Oxygen IDE in Debian and Ubuntu][27]” + +#### Netbeans IDE + +A fan-favourite, [Netbeans][28] enables users to easily build applications for mobile, desktop, and web platforms using Java, PHP, HTML5, JavaScript, and C/C++, among other languages. + +For installation, read our article “[How to Install Netbeans Oxygen IDE in Debian and Ubuntu][29]” + +#### Brackets + +[Brackets][30] is an advanced text editor developed by Adobe to feature visual tools, preprocessor support, and a design-focused user flow for web development. In the hands of an expert, it can serve as an IDE in its own right. + +Install **Brackets** on **Ubuntu** and **Debian** , using following commands. +``` +$ sudo add-apt-repository ppa:webupd8team/brackets +$ sudo apt-get update +$ sudo apt-get install brackets + +``` + +#### Atom IDE + +[Atom IDE][31] is a more robust version of Atom text editor achieved by adding a number of extensions and libraries to boost its performance and functionalities. It is, in a sense, Atom on steroids. + +Install **Atom** on **Ubuntu** and **Debian** , using following commands. +``` +$ sudo apt-get install snapd +$ sudo snap install atom --classic + +``` + +#### Light Table + +[Light Table][32] is a self-proclaimed next-generation IDE developed to offer awesome features like data value flow stats and coding collaboration. + +Install **Light Table** on **Ubuntu** and **Debian** , using following commands. +``` +$ sudo add-apt-repository ppa:dr-akulavich/lighttable +$ sudo apt-get update +$ sudo apt-get install lighttable-installer + +``` + +#### Visual Studio Code + +[Visual Studio Code][33] is a source code editor created by Microsoft to offer users the best-advanced features in a text editor including syntax highlighting, code completion, debugging, performance statistics and graphs, etc. + +[**Download Visual Studio Code for Ubuntu][34] + +### Instant Messaging + +![](https://www.fossmint.com/wp-content/uploads/2018/07/Linux-IM-Clients.png) + +#### Pidgin + +[Pidgin][35] is an open source instant messaging app that supports virtually all chatting platforms and can have its abilities extended using extensions. + +Install **Pidgin** on **Ubuntu** and **Debian** , using following commands. +``` +$ sudo add-apt-repository ppa:jonathonf/backports +$ sudo apt-get update +$ sudo apt-get install pidgin + +``` + +#### Skype + +[Skype][36] needs no introduction and its awesomeness is available for any interested Linux user. + +Install **Skype** on **Ubuntu** and **Debian** , using following commands. +``` +$ sudo apt install snapd +$ sudo snap install skype --classic + +``` + +#### Empathy + +[Empathy][37] is a messaging app with support for voice, video chat, text, and file transfers over multiple several protocols. It also allows you to add other service accounts to it and interface with all of them through it. + +Install **Empathy** on **Ubuntu** and **Debian** , using following commands. +``` +$ sudo apt-get install empathy + +``` + +### Linux Antivirus + +#### ClamAV/ClamTk + +[ClamAV][38] is an open source and cross-platform command line antivirus app for detecting Trojans, viruses, and other malicious codes. [ClamTk][39] is its GUI front-end. + +Install **ClamAV/ClamTk** on **Ubuntu** and **Debian** , using following commands. +``` +$ sudo apt-get install clamav +$ sudo apt-get install clamtk + +``` + +### Linux Desktop Environments + +#### Cinnamon + +[Cinnamon][40] is a free and open-source derivative of **GNOME3** and it follows the traditional desktop metaphor conventions. + +Install **Cinnamon** desktop on **Ubuntu** and **Debian** , using following commands. +``` +$ sudo add-apt-repository ppa:embrosyn/cinnamon +$ sudo apt update +$ sudo apt install cinnamon-desktop-environment lightdm + +``` + +#### Mate + +The [Mate][41] Desktop Environment is a derivative and continuation of **GNOME2** developed to offer an attractive UI on Linux using traditional metaphors. + +Install **Mate** desktop on **Ubuntu** and **Debian** , using following commands. +``` +$ sudo apt install tasksel +$ sudo apt update +$ sudo tasksel install ubuntu-mate-desktop + +``` + +#### GNOME + +[GNOME][42] is a Desktop Environment comprised of several free and open-source applications and can run on any Linux distro and on most BSD derivatives. + +Install **Gnome** desktop on **Ubuntu** and **Debian** , using following commands. +``` +$ sudo apt install tasksel +$ sudo apt update +$ sudo tasksel install ubuntu-desktop + +``` + +#### KDE + +[KDE][43] is developed by the KDE community to provide users with a graphical solution to interfacing with their system and performing several computing tasks. + +Install **KDE** desktop on **Ubuntu** and **Debian** , using following commands. +``` +$ sudo apt install tasksel +$ sudo apt update +$ sudo tasksel install kubuntu-desktop + +``` + +### Linux Maintenance Tools + +#### GNOME Tweak Tool + +The [GNOME Tweak Tool][44] is the most popular tool for customizing and tweaking GNOME3 and GNOME Shell settings. + +Install **GNOME Tweak Tool** on **Ubuntu** and **Debian** , using following commands. +``` +$ sudo apt install gnome-tweak-tool + +``` + +#### Stacer + +[Stacer][45] is a free, open-source app for monitoring and optimizing Linux systems. + +Install **Stacer** on **Ubuntu** and **Debian** , using following commands. +``` +$ sudo add-apt-repository ppa:oguzhaninan/stacer +$ sudo apt-get update +$ sudo apt-get install stacer + +``` + +#### BleachBit + +[BleachBit][46] is a free disk space cleaner that also works as a privacy manager and system optimizer. + +[**Download BleachBit for Ubuntu][47] + +### Linux Terminals + +#### GNOME Terminal + +[GNOME Terminal][48] is GNOME’s default terminal emulator. + +Install **Gnome Terminal** on **Ubuntu** and **Debian** , using following commands. +``` +$ sudo apt-get install gnome-terminal + +``` + +#### Konsole + +[Konsole][49] is a terminal emulator for KDE. + +Install **Konsole** on **Ubuntu** and **Debian** , using following commands. +``` +$ sudo apt-get install konsole + +``` + +#### Terminator + +[Terminator][50] is a feature-rich GNOME Terminal-based terminal app built with a focus on arranging terminals, among other functions. + +Install **Terminator** on **Ubuntu** and **Debian** , using following commands. +``` +$ sudo apt-get install terminator + +``` + +#### Guake + +[Guake][51] is a lightweight drop-down terminal for the GNOME Desktop Environment. + +Install **Guake** on **Ubuntu** and **Debian** , using following commands. +``` +$ sudo apt-get install guake + +``` + +### Multimedia Editors + +#### Ardour + +[Ardour][52] is a beautiful Digital Audio Workstation (DAW) for recording, editing, and mixing audio professionally. + +Install **Ardour** on **Ubuntu** and **Debian** , using following commands. +``` +$ sudo add-apt-repository ppa:dobey/audiotools +$ sudo apt-get update +$ sudo apt-get install ardour + +``` + +#### Audacity + +[Audacity][53] is an easy-to-use cross-platform and open source multi-track audio editor and recorder; arguably the most famous of them all. + +Install **Audacity** on **Ubuntu** and **Debian** , using following commands. +``` +$ sudo add-apt-repository ppa:ubuntuhandbook1/audacity +$ sudo apt-get update +$ sudo apt-get install audacity + +``` + +#### GIMP + +[GIMP][54] is the most popular open source Photoshop alternative and it is for a reason. It features various customization options, 3rd-party plugins, and a helpful user community. + +Install **Gimp** on **Ubuntu** and **Debian** , using following commands. +``` +$ sudo add-apt-repository ppa:otto-kesselgulasch/gimp +$ sudo apt update +$ sudo apt install gimp + +``` + +#### Krita + +[Krita][55] is an open source painting app that can also serve as an image manipulating tool and it features a beautiful UI with a reliable performance. + +Install **Krita** on **Ubuntu** and **Debian** , using following commands. +``` +$ sudo add-apt-repository ppa:kritalime/ppa +$ sudo apt update +$ sudo apt install krita + +``` + +#### Lightworks + +[Lightworks][56] is a powerful, flexible, and beautiful tool for editing videos professionally. It comes feature-packed with hundreds of amazing effects and presets that allow it to handle any editing task that you throw at it and it has 25 years of experience to back up its claims. + +[**Download Lightworks for Ubuntu][57] + +#### OpenShot + +[OpenShot][58] is an award-winning free and open source video editor known for its excellent performance and powerful capabilities. + +Install **Openshot** on **Ubuntu** and **Debian** , using following commands. +``` +$ sudo add-apt-repository ppa:openshot.developers/ppa +$ sudo apt update +$ sudo apt install openshot-qt + +``` + +#### PiTiV + +[Pitivi][59] is a beautiful video editor that features a beautiful code base, awesome community, is easy to use, and allows for hassle-free collaboration. + +Install **PiTiV** on **Ubuntu** and **Debian** , using following commands. +``` +$ flatpak install --user https://flathub.org/repo/appstream/org.pitivi.Pitivi.flatpakref +$ flatpak install --user http://flatpak.pitivi.org/pitivi.flatpakref +$ flatpak run org.pitivi.Pitivi//stable + +``` + +### Music Players + +#### Rhythmbox + +[Rhythmbox][60] posses the ability to perform all music tasks you throw at it and has so far proved to be a reliable music player that it ships with Ubuntu. + +Install **Rhythmbox** on **Ubuntu** and **Debian** , using following commands. +``` +$ sudo add-apt-repository ppa:fossfreedom/rhythmbox +$ sudo apt-get update +$ sudo apt-get install rhythmbox + +``` + +#### Lollypop + +[Lollypop][61] is a beautiful, relatively new, open source music player featuring a number of advanced options like online radio, scrubbing support and party mode. Yet, it manages to keep everything simple and easy to manage. + +Install **Lollypop** on **Ubuntu** and **Debian** , using following commands. +``` +$ sudo add-apt-repository ppa:gnumdk/lollypop +$ sudo apt-get update +$ sudo apt-get install lollypop + +``` + +#### Amarok + +[Amarok][62] is a robust music player with an intuitive UI and tons of advanced features bundled into a single unit. It also allows users to discover new music based on their genre preferences. + +Install **Amarok** on **Ubuntu** and **Debian** , using following commands. +``` +$ sudo apt-get update +$ sudo apt-get install amarok + +``` + +#### Clementine + +[Clementine][63] is an Amarok-inspired music player that also features a straight-forward UI, advanced control features, and the ability to let users search for and discover new music. + +Install **Clementine** on **Ubuntu** and **Debian** , using following commands. +``` +$ sudo add-apt-repository ppa:me-davidsansome/clementine +$ sudo apt-get update +$ sudo apt-get install clementine + +``` + +#### Cmus + +[Cmus][64] is arguably the most efficient CLI music player, Cmus is fast and reliable, and its functionality can be increased using extensions. + +Install **Cmus** on **Ubuntu** and **Debian** , using following commands. +``` +$ sudo add-apt-repository ppa:jmuc/cmus +$ sudo apt-get update +$ sudo apt-get install cmus + +``` + +### Office Suites + +#### Calligra Suite + +The [Calligra Suite][65] provides users with a set of 8 applications which cover working with office, management, and graphics tasks. + +Install **Calligra Suite** on **Ubuntu** and **Debian** , using following commands. +``` +$ sudo apt-get install calligra + +``` + +#### LibreOffice + +[LibreOffice][66] the most actively developed office suite in the open source community, LibreOffice is known for its reliability and its functions can be increased using extensions. + +Install **LibreOffice** on **Ubuntu** and **Debian** , using following commands. +``` +$ sudo add-apt-repository ppa:libreoffice/ppa +$ sudo apt update +$ sudo apt install libreoffice + +``` + +#### WPS Office + +[WPS Office][67] is a beautiful office suite alternative with a more modern UI. + +[**Download WPS Office for Ubuntu][68] + +### Screenshot Tools + +#### Shutter + +[Shutter][69] allows users to take screenshots of their desktop and then edit them using filters and other effects coupled with the option to upload and share them online. + +Install **Shutter** on **Ubuntu** and **Debian** , using following commands. +``` +$ sudo add-apt-repository -y ppa:shutter/ppa +$ sudo apt update +$ sudo apt install shutter + +``` + +#### Kazam + +[Kazam][70] screencaster captures screen content to output a video and audio file supported by any video player with VP8/WebM and PulseAudio support. + +Install **Kazam** on **Ubuntu** and **Debian** , using following commands. +``` +$ sudo add-apt-repository ppa:kazam-team/unstable-series +$ sudo apt update +$ sudo apt install kazam python3-cairo python3-xlib + +``` + +#### Gnome Screenshot + +[Gnome Screenshot][71] was once bundled with Gnome utilities but is now a standalone app. It can be used to take screencasts in a format that is easily shareable. + +Install **Gnome Screenshot** on **Ubuntu** and **Debian** , using following commands. +``` +$ sudo apt-get update +$ sudo apt-get install gnome-screenshot + +``` + +### Screen Recorders + +#### SimpleScreenRecorder + +[SimpleScreenRecorder][72] was created to be better than the screen-recording apps available at the time of its creation and has now turned into one of the most efficient and easy-to-use screen recorders for Linux distros. + +Install **SimpleScreenRecorder** on **Ubuntu** and **Debian** , using following commands. +``` +$ sudo add-apt-repository ppa:maarten-baert/simplescreenrecorder +$ sudo apt-get update +$ sudo apt-get install simplescreenrecorder + +``` + +#### recordMyDesktop + +[recordMyDesktop][73] is an open source session recorder that is also capable of recording desktop session audio. + +Install **recordMyDesktop** on **Ubuntu** and **Debian** , using following commands. +``` +$ sudo apt-get update +$ sudo apt-get install gtk-recordmydesktop + +``` + +### Text Editors + +#### Atom + +[Atom][74] is a modern and customizable text editor created and maintained by GitHub. It is ready for use right out of the box and can have its functionality enhanced and its UI customized using extensions and themes. + +Install **Atom** on **Ubuntu** and **Debian** , using following commands. +``` +$ sudo apt-get install snapd +$ sudo snap install atom --classic + +``` + +#### Sublime Text + +[Sublime Text][75] is easily among the most awesome text editors to date. It is customizable, lightweight (even when bulldozed with a lot of data files and extensions), flexible, and remains free to use forever. + +Install **Sublime Text** on **Ubuntu** and **Debian** , using following commands. +``` +$ sudo apt-get install snapd +$ sudo snap install sublime-text + +``` + +#### Geany + +[Geany][76] is a memory-friendly text editor with basic IDE features designed to exhibit shot load times and extensible functions using libraries. + +Install **Geany** on **Ubuntu** and **Debian** , using following commands. +``` +$ sudo apt-get update +$ sudo apt-get install geany + +``` + +#### Gedit + +[Gedit][77] is famous for its simplicity and it comes preinstalled with many Linux distros because of its function as an excellent general purpose text editor. + +Install **Gedit** on **Ubuntu** and **Debian** , using following commands. +``` +$ sudo apt-get update +$ sudo apt-get install gedit + +``` + +### To-Do List Apps + +#### Evernote + +[Evernote][78] is a cloud-based note-taking productivity app designed to work perfectly with different types of notes including to-do lists and reminders. + +There is no any official evernote app for Linux, so check out other third party [6 Evernote Alternative Clients for Linux][79]. + +#### Everdo + +[Everdo][78] is a beautiful, security-conscious, low-friction Getting-Things-Done app productivity app for handling to-dos and other note types. If Evernote comes off to you in an unpleasant way, Everdo is a perfect alternative. + +[**Download Everdo for Ubuntu][80] + +#### Taskwarrior + +[Taskwarrior][81] is an open source and cross-platform command line app for managing tasks. It is famous for its speed and distraction-free environment. + +Install **Taskwarrior** on **Ubuntu** and **Debian** , using following commands. +``` +$ sudo apt-get update +$ sudo apt-get install taskwarrior + +``` + +### Video Players + +#### Banshee + +[Banshee][82] is an open source multi-format-supporting media player that was first developed in 2005 and has only been getting better since. + +Install **Banshee** on **Ubuntu** and **Debian** , using following commands. +``` +$ sudo add-apt-repository ppa:banshee-team/ppa +$ sudo apt-get update +$ sudo apt-get install banshee + +``` + +#### VLC + +[VLC][83] is my favourite video player and it’s so awesome that it can play almost any audio and video format you throw at it. You can also use it to play internet radio, record desktop sessions, and stream movies online. + +Install **VLC** on **Ubuntu** and **Debian** , using following commands. +``` +$ sudo add-apt-repository ppa:videolan/stable-daily +$ sudo apt-get update +$ sudo apt-get install vlc + +``` + +#### Kodi + +[Kodi][84] is among the world’s most famous media players and it comes as a full-fledged media centre app for playing all things media whether locally or remotely. + +Install **Kodi** on **Ubuntu** and **Debian** , using following commands. +``` +$ sudo apt-get install software-properties-common +$ sudo add-apt-repository ppa:team-xbmc/ppa +$ sudo apt-get update +$ sudo apt-get install kodi + +``` + +#### SMPlayer + +[SMPlayer][85] is a GUI for the award-winning **MPlayer** and it is capable of handling all popular media formats; coupled with the ability to stream from YouTube, Chromcast, and download subtitles. + +Install **SMPlayer** on **Ubuntu** and **Debian** , using following commands. +``` +$ sudo add-apt-repository ppa:rvm/smplayer +$ sudo apt-get update +$ sudo apt-get install smplayer + +``` + +### Virtualization Tools + +#### VirtualBox + +[VirtualBox][86] is an open source app created for general-purpose OS virtualization and it can be run on servers, desktops, and embedded systems. + +Install **VirtualBox** on **Ubuntu** and **Debian** , using following commands. +``` +$ wget -q https://www.virtualbox.org/download/oracle_vbox_2016.asc -O- | sudo apt-key add - +$ wget -q https://www.virtualbox.org/download/oracle_vbox.asc -O- | sudo apt-key add - +$ sudo apt-get update +$ sudo apt-get install virtualbox-5.2 +$ virtualbox + +``` + +#### VMWare + +[VMware][87] is a digital workspace that provides platform virtualization and cloud computing services to customers and is reportedly the first to successfully virtualize x86 architecture systems. One of its products, VMware workstations allows users to run multiple OSes in a virtual memory. + +For installation, read our article “[How to Install VMware Workstation Pro on Ubuntu][88]“. + +### Web Browsers + +#### Chrome + +[Google Chrome][89] is undoubtedly the most popular browser. Known for its speed, simplicity, security, and beauty following Google’s Material Design trend, Chrome is a browser that web developers cannot do without. It is also free to use and open source. + +Install **Google Chrome** on **Ubuntu** and **Debian** , using following commands. +``` +$ wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add - +$ sudo sh -c 'echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' +$ sudo apt-get update +$ sudo apt-get install google-chrome-stable + +``` + +#### Firefox + +[Firefox Quantum][90] is a beautiful, speed, task-ready, and customizable browser capable of any browsing task that you throw at it. It is also free, open source, and packed with developer-friendly tools that are easy for even beginners to get up and running with. + +Install **Firefox Quantum** on **Ubuntu** and **Debian** , using following commands. +``` +$ sudo add-apt-repository ppa:mozillateam/firefox-next +$ sudo apt update && sudo apt upgrade +$ sudo apt install firefox + +``` + +#### Vivaldi + +[Vivaldi][91] is a free and open source Chrome-based project that aims to perfect Chrome’s features with a couple of more feature additions. It is known for its colourful panels, memory-friendly performance, and flexibility. + +[**Download Vivaldi for Ubuntu][91] + +That concludes our list for today. Did I skip a famous title? Tell me about it in the comments section below. + +Don’t forget to share this post and to subscribe to our newsletter to get the latest publications from FossMint. + + +-------------------------------------------------------------------------------- + +via: https://www.fossmint.com/most-used-linux-applications/ + +作者:[Martins D. Okoi][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.fossmint.com/author/dillivine/ +[1]:https://plus.google.com/share?url=https://www.fossmint.com/most-used-linux-applications/ (Share on Google+) +[2]:https://www.linkedin.com/shareArticle?mini=true&url=https://www.fossmint.com/most-used-linux-applications/ (Share on LinkedIn) +[3]:https://www.fossmint.com/awesome-linux-software/ +[4]:https://rsync.samba.org/ +[5]:https://www.tecmint.com/rsync-local-remote-file-synchronization-commands/ +[6]:https://github.com/teejee2008/timeshift +[7]:https://deluge-torrent.org/ +[8]:https://www.qbittorrent.org/ +[9]:https://transmissionbt.com/ +[10]:https://www.dropbox.com/ +[11]:https://www.google.com/drive/ +[12]:https://www.fossmint.com/best-google-drive-clients-for-linux/ +[13]:https://mega.nz/ +[14]:https://mega.nz/sync!linux +[15]:https://www.vim.org/ +[16]:https://www.gnu.org/s/emacs/ +[17]:https://www.nano-editor.org/ +[18]:https://aria2.github.io/ +[19]:http://ugetdm.com/ +[20]:http://xdman.sourceforge.net/ +[21]:https://www.thunderbird.net/ +[22]:https://github.com/GNOME/geary +[23]:https://github.com/GNOME/evolution +[24]:https://www.gnucash.org/ +[25]:https://kmymoney.org/ +[26]:https://www.eclipse.org/ide/ +[27]:https://www.tecmint.com/install-eclipse-oxygen-ide-in-ubuntu-debian/ +[28]:https://netbeans.org/ +[29]:https://www.tecmint.com/install-netbeans-ide-in-ubuntu-debian-linux-mint/ +[30]:http://brackets.io/ +[31]:https://ide.atom.io/ +[32]:http://lighttable.com/ +[33]:https://code.visualstudio.com/ +[34]:https://code.visualstudio.com/download +[35]:https://www.pidgin.im/ +[36]:https://www.skype.com/ +[37]:https://wiki.gnome.org/Apps/Empathy +[38]:https://www.clamav.net/ +[39]:https://dave-theunsub.github.io/clamtk/ +[40]:https://github.com/linuxmint/cinnamon-desktop +[41]:https://mate-desktop.org/ +[42]:https://www.gnome.org/ +[43]:https://www.kde.org/plasma-desktop +[44]:https://github.com/nzjrs/gnome-tweak-tool +[45]:https://github.com/oguzhaninan/Stacer +[46]:https://www.bleachbit.org/ +[47]:https://www.bleachbit.org/download +[48]:https://github.com/GNOME/gnome-terminal +[49]:https://konsole.kde.org/ +[50]:https://gnometerminator.blogspot.com/p/introduction.html +[51]:http://guake-project.org/ +[52]:https://ardour.org/ +[53]:https://www.audacityteam.org/ +[54]:https://www.gimp.org/ +[55]:https://krita.org/en/ +[56]:https://www.lwks.com/ +[57]:https://www.lwks.com/index.php?option=com_lwks&view=download&Itemid=206 +[58]:https://www.openshot.org/ +[59]:http://www.pitivi.org/ +[60]:https://wiki.gnome.org/Apps/Rhythmbox +[61]:https://gnumdk.github.io/lollypop-web/ +[62]:https://amarok.kde.org/en +[63]:https://www.clementine-player.org/ +[64]:https://cmus.github.io/ +[65]:https://www.calligra.org/tour/calligra-suite/ +[66]:https://www.libreoffice.org/ +[67]:https://www.wps.com/ +[68]:http://wps-community.org/downloads +[69]:http://shutter-project.org/ +[70]:https://launchpad.net/kazam +[71]:https://gitlab.gnome.org/GNOME/gnome-screenshot +[72]:http://www.maartenbaert.be/simplescreenrecorder/ +[73]:http://recordmydesktop.sourceforge.net/about.php +[74]:https://atom.io/ +[75]:https://www.sublimetext.com/ +[76]:https://www.geany.org/ +[77]:https://wiki.gnome.org/Apps/Gedit +[78]:https://everdo.net/ +[79]:https://www.fossmint.com/evernote-alternatives-for-linux/ +[80]:https://everdo.net/linux/ +[81]:https://taskwarrior.org/ +[82]:http://banshee.fm/ +[83]:https://www.videolan.org/ +[84]:https://kodi.tv/ +[85]:https://www.smplayer.info/ +[86]:https://www.virtualbox.org/wiki/VirtualBox +[87]:https://www.vmware.com/ +[88]:https://www.tecmint.com/install-vmware-workstation-in-linux/ +[89]:https://www.google.com/chrome/ +[90]:https://www.mozilla.org/en-US/firefox/ +[91]:https://vivaldi.com/ diff --git a/sources/tech/20180724 Building a network attached storage device with a Raspberry Pi.md b/sources/tech/20180724 Building a network attached storage device with a Raspberry Pi.md new file mode 100644 index 0000000000..3144efd4ee --- /dev/null +++ b/sources/tech/20180724 Building a network attached storage device with a Raspberry Pi.md @@ -0,0 +1,284 @@ +Building a network attached storage device with a Raspberry Pi +====== + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/bus-storage.png?itok=95-zvHYl) + +In this three-part series, I'll explain how to set up a simple, useful NAS (network attached storage) system. I use this kind of setup to store my files on a central system, creating incremental backups automatically every night. To mount the disk on devices that are located in the same network, NFS is installed. To access files offline and share them with friends, I use [Nextcloud][1]. + +This article will cover the basic setup of software and hardware to mount the data disk on a remote device. In the second article, I will discuss a backup strategy and set up a cron job to create daily backups. In the third and last article, we will install Nextcloud, a tool for easy file access to devices synced offline as well as online using a web interface. It supports multiple users and public file-sharing so you can share pictures with friends, for example, by sending a password-protected link. + +The target architecture of our system looks like this: +![](https://opensource.com/sites/default/files/uploads/nas_part1.png) + +### Hardware + +Let's get started with the hardware you need. You might come up with a different shopping list, so consider this one an example. + +The computing power is delivered by a [Raspberry Pi 3][2], which comes with a quad-core CPU, a gigabyte of RAM, and (somewhat) fast ethernet. Data will be stored on two USB hard drives (I use 1-TB disks); one is used for the everyday traffic, the other is used to store backups. Be sure to use either active USB hard drives or a USB hub with an additional power supply, as the Raspberry Pi will not be able to power two USB drives. + +### Software + +The operating system with the highest visibility in the community is [Raspbian][3] , which is excellent for custom projects. There are plenty of [guides][4] that explain how to install Raspbian on a Raspberry Pi, so I won't go into details here. The latest official supported version at the time of this writing is [Raspbian Stretch][5] , which worked fine for me. + +At this point, I will assume you have configured your basic Raspbian and are able to connect to the Raspberry Pi by `ssh`. + +### Prepare the USB drives + +To achieve good performance reading from and writing to the USB hard drives, I recommend formatting them with ext4. To do so, you must first find out which disks are attached to the Raspberry Pi. You can find the disk devices in `/dev/sd/`. Using the command `fdisk -l`, you can find out which two USB drives you just attached. Please note that all data on the USB drives will be lost as soon as you follow these steps. +``` +pi@raspberrypi:~ $ sudo fdisk -l + + + +<...> + + + +Disk /dev/sda: 931.5 GiB, 1000204886016 bytes, 1953525168 sectors + +Units: sectors of 1 * 512 = 512 bytes + +Sector size (logical/physical): 512 bytes / 512 bytes + +I/O size (minimum/optimal): 512 bytes / 512 bytes + +Disklabel type: dos + +Disk identifier: 0xe8900690 + + + +Device     Boot Start        End    Sectors   Size Id Type + +/dev/sda1        2048 1953525167 1953523120 931.5G 83 Linux + + + + + +Disk /dev/sdb: 931.5 GiB, 1000204886016 bytes, 1953525168 sectors + +Units: sectors of 1 * 512 = 512 bytes + +Sector size (logical/physical): 512 bytes / 512 bytes + +I/O size (minimum/optimal): 512 bytes / 512 bytes + +Disklabel type: dos + +Disk identifier: 0x6aa4f598 + + + +Device     Boot Start        End    Sectors   Size Id Type + +/dev/sdb1  *     2048 1953521663 1953519616 931.5G  83 Linux + +``` + +As those devices are the only 1TB disks attached to the Raspberry Pi, we can easily see that `/dev/sda` and `/dev/sdb` are the two USB drives. The partition table at the end of each disk shows how it should look after the following steps, which create the partition table and format the disks. To do this, repeat the following steps for each of the two devices by replacing `sda` with `sdb` the second time (assuming your devices are also listed as `/dev/sda` and `/dev/sdb` in `fdisk`). + +First, delete the partition table of the disk and create a new one containing only one partition. In `fdisk`, you can use interactive one-letter commands to tell the program what to do. Simply insert them after the prompt `Command (m for help):` as follows (you can also use the `m` command anytime to get more information): +``` +pi@raspberrypi:~ $ sudo fdisk /dev/sda + + + +Welcome to fdisk (util-linux 2.29.2). + +Changes will remain in memory only, until you decide to write them. + +Be careful before using the write command. + + + + + +Command (m for help): o + +Created a new DOS disklabel with disk identifier 0x9c310964. + + + +Command (m for help): n + +Partition type + +   p   primary (0 primary, 0 extended, 4 free) + +   e   extended (container for logical partitions) + +Select (default p): p + +Partition number (1-4, default 1): + +First sector (2048-1953525167, default 2048): + +Last sector, +sectors or +size{K,M,G,T,P} (2048-1953525167, default 1953525167): + + + +Created a new partition 1 of type 'Linux' and of size 931.5 GiB. + + + +Command (m for help): p + + + +Disk /dev/sda: 931.5 GiB, 1000204886016 bytes, 1953525168 sectors + +Units: sectors of 1 * 512 = 512 bytes + +Sector size (logical/physical): 512 bytes / 512 bytes + +I/O size (minimum/optimal): 512 bytes / 512 bytes + +Disklabel type: dos + +Disk identifier: 0x9c310964 + + + +Device     Boot Start        End    Sectors   Size Id Type + +/dev/sda1        2048 1953525167 1953523120 931.5G 83 Linux + + + +Command (m for help): w + +The partition table has been altered. + +Syncing disks. + +``` + +Now we will format the newly created partition `/dev/sda1` using the ext4 filesystem: +``` +pi@raspberrypi:~ $ sudo mkfs.ext4 /dev/sda1 + +mke2fs 1.43.4 (31-Jan-2017) + +Discarding device blocks: done + + + +<...> + + + +Allocating group tables: done + +Writing inode tables: done + +Creating journal (1024 blocks): done + +Writing superblocks and filesystem accounting information: done + +``` + +After repeating the above steps, let's label the new partitions according to their usage in your system: +``` +pi@raspberrypi:~ $ sudo e2label /dev/sda1 data + +pi@raspberrypi:~ $ sudo e2label /dev/sdb1 backup + +``` + +Now let's get those disks mounted to store some data. My experience, based on running this setup for over a year now, is that USB drives are not always available to get mounted when the Raspberry Pi boots up (for example, after a power outage), so I recommend using autofs to mount them when needed. + +First install autofs and create the mount point for the storage: +``` +pi@raspberrypi:~ $ sudo apt install autofs + +pi@raspberrypi:~ $ sudo mkdir /nas + +``` + +Then mount the devices by adding the following line to `/etc/auto.master`: +``` +/nas    /etc/auto.usb + +``` + +Create the file `/etc/auto.usb` if not existing with the following content, and restart the autofs service: +``` +data -fstype=ext4,rw :/dev/disk/by-label/data + +backup -fstype=ext4,rw :/dev/disk/by-label/backup + +pi@raspberrypi3:~ $ sudo service autofs restart + +``` + +Now you should be able to access the disks at `/nas/data` and `/nas/backup`, respectively. Clearly, the content will not be too thrilling, as you just erased all the data from the disks. Nevertheless, you should be able to verify the devices are mounted by executing the following commands: +``` +pi@raspberrypi3:~ $ cd /nas/data + +pi@raspberrypi3:/nas/data $ cd /nas/backup + +pi@raspberrypi3:/nas/backup $ mount + +<...> + +/etc/auto.usb on /nas type autofs (rw,relatime,fd=6,pgrp=463,timeout=300,minproto=5,maxproto=5,indirect) + +<...> + +/dev/sda1 on /nas/data type ext4 (rw,relatime,data=ordered) + +/dev/sdb1 on /nas/backup type ext4 (rw,relatime,data=ordered) + +``` + +First move into the directories to make sure autofs mounts the devices. Autofs tracks access to the filesystems and mounts the needed devices on the go. Then the `mount` command shows that the two devices are actually mounted where we wanted them. + +Setting up autofs is a bit fault-prone, so do not get frustrated if mounting doesn't work on the first try. Give it another chance, search for more detailed resources (there is plenty of documentation online), or leave a comment. + +### Mount network storage + +Now that you have set up the basic network storage, we want it to be mounted on a remote Linux machine. We will use the network file system (NFS) for this. First, install the NFS server on the Raspberry Pi: +``` +pi@raspberrypi:~ $ sudo apt install nfs-kernel-server + +``` + +Next we need to tell the NFS server to expose the `/nas/data` directory, which will be the only device accessible from outside the Raspberry Pi (the other one will be used for backups only). To export the directory, edit the file `/etc/exports` and add the following line to allow all devices with access to the NAS to mount your storage: +``` +/nas/data *(rw,sync,no_subtree_check) + +``` + +For more information about restricting the mount to single devices and so on, refer to `man exports`. In the configuration above, anyone will be able to mount your data as long as they have access to the ports needed by NFS: `111` and `2049`. I use the configuration above and allow access to my home network only for ports 22 and 443 using the routers firewall. That way, only devices in the home network can reach the NFS server. + +To mount the storage on a Linux computer, run the commands: +``` +you@desktop:~ $ sudo mkdir /nas/data + +you@desktop:~ $ sudo mount -t nfs :/nas/data /nas/data + +``` + +Again, I recommend using autofs to mount this network device. For extra help, check out [How to use autofs to mount NFS shares][6]. + +Now you are able to access files stored on your own RaspberryPi-powered NAS from remote devices using the NFS mount. In the next part of this series, I will cover how to automatically back up your data to the second hard drive using `rsync`. To save space on the device while still doing daily backups, you will learn how to create incremental backups with `rsync`. + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/7/network-attached-storage-Raspberry-Pi + +作者:[Manuel Dewald][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://opensource.com/users/ntlx +[1]:https://nextcloud.com/ +[2]:https://www.raspberrypi.org/products/raspberry-pi-3-model-b/ +[3]:https://www.raspbian.org/ +[4]:https://www.raspberrypi.org/documentation/installation/installing-images/ +[5]:https://www.raspberrypi.org/blog/raspbian-stretch/ +[6]:https://opensource.com/article/18/6/using-autofs-mount-nfs-shares diff --git a/sources/tech/20180724 How To Mount Google Drive Locally As Virtual File System In Linux.md b/sources/tech/20180724 How To Mount Google Drive Locally As Virtual File System In Linux.md new file mode 100644 index 0000000000..3f804ffe9e --- /dev/null +++ b/sources/tech/20180724 How To Mount Google Drive Locally As Virtual File System In Linux.md @@ -0,0 +1,265 @@ +How To Mount Google Drive Locally As Virtual File System In Linux +====== + +![](https://www.ostechnix.com/wp-content/uploads/2018/07/Google-Drive-720x340.png) + +[**Google Drive**][1] is the one of the popular cloud storage provider on the planet. As of 2017, over 800 million users are actively using this service worldwide. Even though the number of users have dramatically increased, Google haven’t released a Google drive client for Linux yet. But it didn’t stop the Linux community. Every now and then, some developers had brought few google drive clients for Linux operating system. In this guide, we will see three unofficial google drive clients for Linux. Using these clients, you can mount Google drive locally as a virtual file system and access your drive files in your Linux box. Read on. + +### 1. Google-drive-ocamlfuse + +The **google-drive-ocamlfuse** is a FUSE filesystem for Google Drive, written in OCaml. For those wondering, FUSE, stands for **F** ilesystem in **Use** rspace, is a project that allows the users to create virtual file systems in user level. **google-drive-ocamlfuse** allows you to mount your Google Drive on Linux system. It features read/write access to ordinary files and folders, read-only access to Google docks, sheets, and slides, support for multiple google drive accounts, duplicate file handling, access to your drive trash directory, and more. + +#### Installing google-drive-ocamlfuse + +google-drive-ocamlfuse is available in the [**AUR**][2], so you can install it using any AUR helper programs, for example [**Yay**][3]. +``` +$ yay -S google-drive-ocamlfuse + +``` + +On Ubuntu: +``` +$ sudo add-apt-repository ppa:alessandro-strada/ppa +$ sudo apt-get update +$ sudo apt-get install google-drive-ocamlfuse + +``` + +To install latest beta version, do: +``` +$ sudo add-apt-repository ppa:alessandro-strada/google-drive-ocamlfuse-beta +$ sudo apt-get update +$ sudo apt-get install google-drive-ocamlfuse + +``` + +#### Usage + +Once installed, run the following command to launch **google-drive-ocamlfuse** utility from your Terminal: +``` +$ google-drive-ocamlfuse + +``` + +When you run this first time, the utility will open your web browser and ask your permission to authorize your google drive files. Once you gave authorization, all necessary config files and folders it needs to mount your google drive will be automatically created. + +![][5] + +After successful authentication, you will see the following message in your Terminal. +``` +Access token retrieved correctly. + +``` + +You’re good to go now. Close the web browser and then create a mount point to mount your google drive files. +``` +$ mkdir ~/mygoogledrive + +``` + +Finally, mount your google drive using command: +``` +$ google-drive-ocamlfuse ~/mygoogledrive + +``` + +Congratulations! You can access access your files either from Terminal or file manager. + +From **Terminal** : +``` +$ ls ~/mygoogledrive + +``` + +From **File manager** : + +![][6] + +If you have more than one account, use **label** option to distinguish different accounts like below. +``` +$ google-drive-ocamlfuse -label label [mountpoint] + +``` + +Once you’re done, unmount the FUSE flesystem using command: +``` +$ fusermount -u ~/mygoogledrive + +``` + +For more details, refer man pages. +``` +$ google-drive-ocamlfuse --help + +``` + +Also, do check the [**official wiki**][7] and the [**project GitHub repository**][8] for more details. + +### 2. GCSF + +**GCSF** is a FUSE filesystem based on Google Drive, written using **Rust** programming language. The name GCSF has come from the Romanian word “ **G** oogle **C** onduce **S** istem de **F** ișiere”, which means “Google Drive Filesystem” in English. Using GCSF, you can mount your Google drive as a local virtual file system and access the contents from the Terminal or file manager. You might wonder how it differ from other Google Drive FUSE projects, for example **google-drive-ocamlfuse**. The developer of GCSF replied to a similar [comment on Reddit][9] “GCSF tends to be faster in several cases (listing files recursively, reading large files from Drive). The caching strategy it uses also leads to very fast reads (x4-7 improvement compared to google-drive-ocamlfuse) for files that have been cached, at the cost of using more RAM“. + +#### Installing GCSF + +GCSF is available in the [**AUR**][10], so the Arch Linux users can install it using any AUR helper, for example [**Yay**][3]. +``` +$ yay -S gcsf-git + +``` + +For other distributions, do the following. + +Make sure you have installed Rust on your system. + +Make sure **pkg-config** and the **fuse** packages are installed. They are available in the default repositories of most Linux distributions. For example, on Ubuntu and derivatives, you can install them using command: +``` +$ sudo apt-get install -y libfuse-dev pkg-config + +``` + +Once all dependencies installed, run the following command to install GCSF: +``` +$ cargo install gcsf + +``` + +#### Usage + +First, we need to authorize our google drive. To do so, simply run: +``` +$ gcsf login ostechnix + +``` + +You must specify a session name. Replace **ostechnix** with your own session name. You will see an output something like below with an URL to authorize your google drive account. + +![][11] + +Just copy and navigate to the above URL from your browser and click **allow** to give permission to access your google drive contents. Once you gave the authentication you will see an output like below. +``` +Successfully logged in. Credentials saved to "/home/sk/.config/gcsf/ostechnix". + +``` + +GCSF will create a configuration file in **$XDG_CONFIG_HOME/gcsf/gcsf.toml** , which is usually defined as **$HOME/.config/gcsf/gcsf.toml**. Credentials are stored in the same directory. + +Next, create a directory to mount your google drive contents. +``` +$ mkdir ~/mygoogledrive + +``` + +Then, edit **/etc/fuse.conf** file: +``` +$ sudo vi /etc/fuse.conf + +``` + +Uncomment the following line to allow non-root users to specify the allow_other or allow_root mount options. +``` +user_allow_other + +``` + +Save and close the file. + +Finally, mount your google drive using command: +``` +$ gcsf mount ~/mygoogledrive -s ostechnix + +``` + +Sample output: +``` +INFO gcsf > Creating and populating file system... +INFO gcsf > File sytem created. +INFO gcsf > Mounting to /home/sk/mygoogledrive +INFO gcsf > Mounted to /home/sk/mygoogledrive +INFO gcsf::gcsf::file_manager > Checking for changes and possibly applying them. +INFO gcsf::gcsf::file_manager > Checking for changes and possibly applying them. + +``` + +Again, replace **ostechnix** with your session name. You can view the existing sessions using command: +``` +$ gcsf list +Sessions: +- ostechnix + +``` + +You can now access your google drive contents either from the Terminal or from File manager. + +From **Terminal** : +``` +$ ls ~/mygoogledrive + +``` + +From **File manager** : + +![][12] + +If you don’t know where your Google drive is mounted, use **df** or **mount** command as shown below. +``` +$ df -h +Filesystem Size Used Avail Use% Mounted on +udev 968M 0 968M 0% /dev +tmpfs 200M 1.6M 198M 1% /run +/dev/sda1 20G 7.5G 12G 41% / +tmpfs 997M 0 997M 0% /dev/shm +tmpfs 5.0M 4.0K 5.0M 1% /run/lock +tmpfs 997M 0 997M 0% /sys/fs/cgroup +tmpfs 200M 40K 200M 1% /run/user/1000 +GCSF 15G 857M 15G 6% /home/sk/mygoogledrive + +$ mount | grep GCSF +GCSF on /home/sk/mygoogledrive type fuse (rw,nosuid,nodev,relatime,user_id=1000,group_id=1000,allow_other) + +``` + +Once done, unmount the google drive using command: +``` +$ fusermount -u ~/mygoogledrive + +``` + +Check the [**GCSF GitHub repository**][13] for more details. + +### 3. Tuxdrive + +**Tuxdrive** is yet another unofficial google drive client for Linux. We have written a detailed guide about Tuxdrive a while ago. Please check the following link. + +Of course, there were few other unofficial google drive clients available in the past, such as Grive2, Syncdrive. But it seems that they are discontinued now. I will keep updating this list when I come across any active google drive clients. + +And, that’s all for now, folks. Hope this was useful. More good stuffs to come. Stay tuned! + +Cheers! + + + +-------------------------------------------------------------------------------- + +via: https://www.ostechnix.com/how-to-mount-google-drive-locally-as-virtual-file-system-in-linux/ + +作者:[SK][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.ostechnix.com/author/sk/ +[1]:https://www.google.com/drive/ +[2]:https://aur.archlinux.org/packages/google-drive-ocamlfuse/ +[3]:https://www.ostechnix.com/yay-found-yet-another-reliable-aur-helper/ +[4]:data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7 +[5]:http://www.ostechnix.com/wp-content/uploads/2018/07/google-drive.png +[6]:http://www.ostechnix.com/wp-content/uploads/2018/07/google-drive-2.png +[7]:https://github.com/astrada/google-drive-ocamlfuse/wiki/Configuration +[8]:https://github.com/astrada/google-drive-ocamlfuse +[9]:https://www.reddit.com/r/DataHoarder/comments/8vlb2v/google_drive_as_a_file_system/e1oh9q9/ +[10]:https://aur.archlinux.org/packages/gcsf-git/ +[11]:http://www.ostechnix.com/wp-content/uploads/2018/07/google-drive-3.png +[12]:http://www.ostechnix.com/wp-content/uploads/2018/07/google-drive-4.png +[13]:https://github.com/harababurel/gcsf diff --git a/sources/tech/20180725 Best Online Linux Terminals and Online Bash Editors.md b/sources/tech/20180725 Best Online Linux Terminals and Online Bash Editors.md new file mode 100644 index 0000000000..7f430c3d59 --- /dev/null +++ b/sources/tech/20180725 Best Online Linux Terminals and Online Bash Editors.md @@ -0,0 +1,212 @@ +Best Online Linux Terminals and Online Bash Editors +====== +No matter whether you want to practice Linux commands or just analyze/test your shell scripts online, there’s always a couple of online Linux terminals and online bash compilers available. + +This is particularly helpful when you are using the Windows operating system. Though you can [install Linux inside Windows using Windows Subsystem for Linux][1], using online Linux terminals are often more convenient for a quick test. + +![Websites that allow to use Linux Terminal online][2] + +But where can you find free Linux console? Which online Linux shell should you use? + +Fret not, to save you the hassle, here, we have compiled a list of the best online Linux terminals and a separate list of best online bash compilers for you to look at. + +**Note:** All of the online terminals support several browsers that include Google Chrome, Mozilla Firefox, Opera and Microsoft Edge. + +### Best Online Linux Terminals To Practice Linux Commands + +In the first part, I’ll list the online Linux terminals. These websites allow you to run the regular Linux commands in a web browser so that you can practice or test them. Some websites may require you to register and login to save your sessions. + +#### 1. JSLinux + +![online linux terminal - jslinux][3] + +JSLinux is more like a complete Linux emulator instead of just offering you the terminal. As the name suggests, it has been entirely written in JavaScript. You get to choose a console-based system or a GUI-based online Linux system. However, in this case, you would want to launch the console-based system to practice Linux commands. To be able to connect your account, you need to sign up first. + +JSLinux also lets you upload files to the virtual machine. At its core, it utilizes [Buildroot][4] (a tool that helps you to build a complete Linux system for an embedded system). + +[Try JSLinux Terminal][5] + +#### 2. Copy.sh + +![copysh online linux terminal][6] + +Copy.sh offers one of the best online Linux terminals which is fast and reliable to test and run Linux commands. + +Copy.sh is also on [GitHub][7] – and it is being actively maintained, which is a good thing. It also supports other Operating Systems, which includes: + + * Windows 98 + * KolibriOS + * FreeDOS + * Windows 1.01 + * Archlinux + + + +[Try Copy.sh Terminal][8] + +#### 3. Webminal + +![webminal online linux terminal][9] + +Webminal is an impressive online Linux terminal – and my personal favorite when it comes to a recommendation for beginners to practice Linux commands online. + +The website offers several lessons to learn from while you type in the commands in the same window. So, you do not need to refer to another site for the lessons and then switch back or split the screen in order to practice commands. It’s all right there – in a single tab on the browser. + +[Try Webminal Terminal][10] + +#### 4. Tutorialspoint Unix Terminal + +![tutorialspoint linux terminal][11] + +You might be aware of Tutorialspoint – which happens to be one of the most popular websites with high quality (yet free) online tutorials for just about any programming language (and more). + +So, for obvious reasons, they provide a free online Linux console for you to practice commands while referring to their site as a resource at the same time. You also get the ability to upload files. It is quite simple but an effective online terminal. Also, it doesn’t stop there, it offers a lot of different online terminals as well in its [Coding Ground][12] page. + +[Try Unix Terminal Online][13] + +#### 5. JS/UIX + +![js uix online linux terminal][14] + +JS/UIX is yet another online Linux terminal which is written entirely in JavaScript without any plug-ins. It contains an online Linux virtual machine, virtual file-system, shell, and so on. + +You can go through its manual page for the list of commands implemented. + +[Try JS/UX Terminal][15] + +#### 6. CB.VU + +![online linux terminal][16] + +If you are in for a treat with FreeBSD 7.1 stable version, cb.vu is a quite simple solution for that. + +Nothing fancy, just try out the Linux commands you want and get the output. Unfortunately, you do not get the ability to upload files here. + +[Try CB.VU Terminal][17] + +#### 7. Linux Containers + +![online linux terminal][18] + +Linux Containers lets you run a demo server with a 30-minute countdown on which acts as one of the best online Linux terminals. In fact, it’s a project sponsored by Canonical. + +[Try Linux LXD][19] + +#### 8. Codeanywhere + +![online linux terminal][20] + +Codeanywhere is a service which offers cross-platform cloud IDEs. However, in order to run a free Linux virtual machine, you just need to sign up and choose the free plan. And, then, proceed to create a new connection while setting up a container with an OS of your choice. Finally, you will have a free Linux console at your disposal. + +[Try Codeanywhere Editor][21] + +### Best Online Bash Editors + +Wait a sec! Are the online Linux terminals not good enough for Bash scripting? They are. But creating bash scripts in terminal editors and then executing them is not as convinient as using an online Bash editor. + +These bash editors allow you to easily write shell scripts online and you can run them to check if it works or not. + +Let’s see here can you run shell scripts online. + +#### Tutorialspoint Bash Compiler + +![online bash compiler][22] + +As mentioned above, Tutorialspoint also offers an online Bash compiler. It is a very simple bash compiler to execute bash shell online. + +[Try Tutorialspoint Bash Compiler][23] + +#### JDOODLE + +![online bash compiler][24] + +Yet another useful online bash editor to test Bash scripts is JDOODLE. It also offers other IDEs, but we’ll focus on bash script execution here. You get to set the command line arguments and the stdin inputs, and would normally get the result of your code. + +[Try JDOODLE Bash Script Online Tester][25] + +#### Paizo.io + +![paizo online bash editor][26] + +Paizo.io is a good bash online editor that you can try for free. To utilize some of its advanced features like task scheduling, you need to first sign up. It also supports real-time collaboration, but that’s still in the experimental phase. + +[Try Paizo.io Bash Editor][27] + +#### ShellCheck + +![shell check bash check][28] + +An interesting Bash editor which lets you find bugs in your shell script. It is available on [GitHub][29] as well. In addition, you can install ShellCheck locally on [supported platforms][30]. + +[Try ShellCheck][31] + +#### Rextester + +![rextester bash editor][32] + +If you only want a dead simple online bash compiler, Rextester should be your choice. It also supports other programming languages. + +[Try Rextester][33] + +#### Learn Shell + +![online bash shell editor][34] + +Just like [Webminal][35], Learnshell provides you with the content (or resource) to learn shell programming and you could also run/try your code at the same time. It covers the basics and a few advanced topics as well. + +[Try Learn Shell Programming][36] + +### Wrapping Up + +Now that you know of the most reliable and fast online Linux terminals & online bash editors, learn, experiment, and play with the code! + +We might have missed any of your favorite online Linux terminals or maybe the best online bash compiler which you happen to use? Let us know your thoughts in the comments below. + +-------------------------------------------------------------------------------- + +via: https://itsfoss.com/online-linux-terminals/ + +作者:[Ankush Das][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://itsfoss.com/author/ankush/ +[1]:https://itsfoss.com/install-bash-on-windows/ +[2]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/07/online-linux-terminals.jpeg +[3]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/07/jslinux-online-linux-terminal.jpg +[4]:https://buildroot.org/ +[5]:https://bellard.org/jslinux/ +[6]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/07/copy-sh-online-linux-terminal.jpg +[7]:https://github.com/copy/v86 +[8]:https://copy.sh/v86/?profile=linux26 +[9]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/07/webminal.jpg +[10]:http://www.webminal.org/terminal/ +[11]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/07/coding-ground-tutorialspoint-online-linux-terminal.jpg +[12]:https://www.tutorialspoint.com/codingground.htm +[13]:https://www.tutorialspoint.com/unix_terminal_online.php +[14]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/07/JS-UIX-online-linux-terminal.jpg +[15]:http://www.masswerk.at/jsuix/index.html +[16]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/07/cb-vu-online-linux-terminal.jpg +[17]:http://cb.vu/ +[18]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/07/linux-containers-terminal.jpg +[19]:https://linuxcontainers.org/lxd/try-it/ +[20]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/07/codeanywhere-terminal.jpg +[21]:https://codeanywhere.com/editor/ +[22]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/07/tutorialspoint-bash-compiler.jpg +[23]:https://www.tutorialspoint.com/execute_bash_online.php +[24]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/07/jdoodle-online-bash-editor.jpg +[25]:https://www.jdoodle.com/test-bash-shell-script-online +[26]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/07/paizo-io-bash-editor.jpg +[27]:https://paiza.io/en/projects/new?language=bash +[28]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/07/shell-check-bash-analyzer.jpg +[29]:https://github.com/koalaman/shellcheck +[30]:https://github.com/koalaman/shellcheck#user-content-installing +[31]:https://www.shellcheck.net/# +[32]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/07/rextester-bash-editor.jpg +[33]:http://rextester.com/l/bash_online_compiler +[34]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/07/learnshell-online-bash-shell.jpg +[35]:http://www.webminal.org/ +[36]:http://www.learnshell.org/ diff --git a/sources/tech/20180725 Build an interactive CLI with Node.js.md b/sources/tech/20180725 Build an interactive CLI with Node.js.md new file mode 100644 index 0000000000..6ec13f1cfc --- /dev/null +++ b/sources/tech/20180725 Build an interactive CLI with Node.js.md @@ -0,0 +1,531 @@ +Build an interactive CLI with Node.js +====== + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/programming_keyboard_coding.png?itok=E0Vvam7A) + +Node.js can be very useful when it comes to building command-line interfaces (CLIs). In this post, I'll teach you how to use [Node.js][1] to build a CLI that asks some questions and creates a file based on the answers. + +### Get started + +Let's start by creating a brand new [npm][2] package. (Npm is the JavaScript package manager.) +``` +mkdir my-script + +cd my-script + +npm init + +``` + +Npm will ask some questions. After that, we need to install some packages. +``` +npm install --save chalk figlet inquirer shelljs + +``` + +Here's what these packages do: + + * **Chalk:** Terminal string styling done right + * **Figlet:** A program for making large letters out of ordinary text + * **Inquirer:** A collection of common interactive command-line user interfaces + * **ShellJS:** Portable Unix shell commands for Node.js + + + +### Make an index.js file + +Now we'll create an `index.js` file with the following content: +``` +#!/usr/bin/env node + + + +const inquirer = require("inquirer"); + +const chalk = require("chalk"); + +const figlet = require("figlet"); + +const shell = require("shelljs"); + +``` + +### Plan the CLI + +It's always good to plan what a CLI needs to do before writing any code. This CLI will do just one thing: **create a file**. + +The CLI will ask two questions—what is the filename and what is the extension?—then create the file, and show a success message with the created file path. +``` +// index.js + + + +const run = async () => { + +  // show script introduction + +  // ask questions + +  // create the file + +  // show success message + +}; + + + +run(); + +``` + +The first function is the script introduction. Let's use `chalk` and `figlet` to get the job done. +``` +const init = () => { + +  console.log( + +    chalk.green( + +      figlet.textSync("Node JS CLI", { + +        font: "Ghost", + +        horizontalLayout: "default", + +        verticalLayout: "default" + +      }) + +    ) + +  ); + +} + + + +const run = async () => { + +  // show script introduction + +  init(); + + + +  // ask questions + +  // create the file + +  // show success message + +}; + + + +run(); + +``` + +Second, we'll write a function that asks the questions. +``` +const askQuestions = () => { + +  const questions = [ + +    { + +      name: "FILENAME", + +      type: "input", + +      message: "What is the name of the file without extension?" + +    }, + +    { + +      type: "list", + +      name: "EXTENSION", + +      message: "What is the file extension?", + +      choices: [".rb", ".js", ".php", ".css"], + +      filter: function(val) { + +        return val.split(".")[1]; + +      } + +    } + +  ]; + +  return inquirer.prompt(questions); + +}; + + + +// ... + + + +const run = async () => { + +  // show script introduction + +  init(); + + + +  // ask questions + +  const answers = await askQuestions(); + +  const { FILENAME, EXTENSION } = answers; + + + +  // create the file + +  // show success message + +}; + +``` + +Notice the constants FILENAME and EXTENSIONS that came from `inquirer`. + +The next step will create the file. +``` +const createFile = (filename, extension) => { + +  const filePath = `${process.cwd()}/${filename}.${extension}` + +  shell.touch(filePath); + +  return filePath; + +}; + + + +// ... + + + +const run = async () => { + +  // show script introduction + +  init(); + + + +  // ask questions + +  const answers = await askQuestions(); + +  const { FILENAME, EXTENSION } = answers; + + + +  // create the file + +  const filePath = createFile(FILENAME, EXTENSION); + + + +  // show success message + +}; + +``` + +And last but not least, we'll show the success message along with the file path. +``` +const success = (filepath) => { + +  console.log( + +    chalk.white.bgGreen.bold(`Done! File created at ${filepath}`) + +  ); + +}; + + + +// ... + + + +const run = async () => { + +  // show script introduction + +  init(); + + + +  // ask questions + +  const answers = await askQuestions(); + +  const { FILENAME, EXTENSION } = answers; + + + +  // create the file + +  const filePath = createFile(FILENAME, EXTENSION); + + + +  // show success message + +  success(filePath); + +}; + +``` + +Let's test the script by running `node index.js`. Here's what we get: + +### The full code + +Here is the final code: +``` +#!/usr/bin/env node + + + +const inquirer = require("inquirer"); + +const chalk = require("chalk"); + +const figlet = require("figlet"); + +const shell = require("shelljs"); + + + +const init = () => { + +  console.log( + +    chalk.green( + +      figlet.textSync("Node JS CLI", { + +        font: "Ghost", + +        horizontalLayout: "default", + +        verticalLayout: "default" + +      }) + +    ) + +  ); + +}; + + + +const askQuestions = () => { + +  const questions = [ + +    { + +      name: "FILENAME", + +      type: "input", + +      message: "What is the name of the file without extension?" + +    }, + +    { + +      type: "list", + +      name: "EXTENSION", + +      message: "What is the file extension?", + +      choices: [".rb", ".js", ".php", ".css"], + +      filter: function(val) { + +        return val.split(".")[1]; + +      } + +    } + +  ]; + +  return inquirer.prompt(questions); + +}; + + + +const createFile = (filename, extension) => { + +  const filePath = `${process.cwd()}/${filename}.${extension}` + +  shell.touch(filePath); + +  return filePath; + +}; + + + +const success = filepath => { + +  console.log( + +    chalk.white.bgGreen.bold(`Done! File created at ${filepath}`) + +  ); + +}; + + + +const run = async () => { + +  // show script introduction + +  init(); + + + +  // ask questions + +  const answers = await askQuestions(); + +  const { FILENAME, EXTENSION } = answers; + + + +  // create the file + +  const filePath = createFile(FILENAME, EXTENSION); + + + +  // show success message + +  success(filePath); + +}; + + + +run(); + +``` + +### Use the script anywhere + +To execute this script anywhere, add a `bin` section in your `package.json` file and run `npm link`. +``` +{ + +  "name": "creator", + +  "version": "1.0.0", + +  "description": "", + +  "main": "index.js", + +  "scripts": { + +    "test": "echo \"Error: no test specified\" && exit 1", + +    "start": "node index.js" + +  }, + +  "author": "", + +  "license": "ISC", + +  "dependencies": { + +    "chalk": "^2.4.1", + +    "figlet": "^1.2.0", + +    "inquirer": "^6.0.0", + +    "shelljs": "^0.8.2" + +  }, + +  "bin": { + +    "creator": "./index.js" + +  } + +} + +``` + +Running `npm link` makes this script available anywhere. + +That's what happens when you run this command: +``` +/usr/bin/creator -> /usr/lib/node_modules/creator/index.js + +/usr/lib/node_modules/creator -> /home/hugo/code/creator + +``` + +It links the `index.js` file as an executable. This is only possible because of the first line of the CLI script: `#!/usr/bin/env node`. + +Now we can run this script by calling: +``` +$ creator + +``` + +### Wrapping up + +As you can see, Node.js makes it very easy to build nice command-line tools! If you want to go even further, check this other packages: + + * [meow][3] – a simple command-line helper + * [yargs][4] – a command-line opt-string parser + * [pkg][5] – package your Node.js project into an executable + + + +Tell us about your experience building a CLI in the comments. + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/7/node-js-interactive-cli + +作者:[Hugo Dias][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://opensource.com/users/hugodias +[1]:https://nodejs.org/en/ +[2]:https://www.npmjs.com/ +[3]:https://github.com/sindresorhus/meow +[4]:https://github.com/yargs/yargs +[5]:https://github.com/zeit/pkg diff --git a/sources/tech/20180727 4 Ways to Customize Xfce and Give it a Modern Look.md b/sources/tech/20180727 4 Ways to Customize Xfce and Give it a Modern Look.md new file mode 100644 index 0000000000..c4372724f7 --- /dev/null +++ b/sources/tech/20180727 4 Ways to Customize Xfce and Give it a Modern Look.md @@ -0,0 +1,145 @@ +4 Ways to Customize Xfce and Give it a Modern Look +====== +**Brief: Xfce is a great lightweight desktop environment with one drawback. It looks sort of old. But you don’t have to stick with the default looks. Let’s see various ways you can customize Xfce to give it a modern and beautiful look.** + +![Customize Xfce desktop envirnment][1] + +To start with, Xfce is one of the most [popular desktop environments][2]. Being a lightweight DE, you can run Xfce on very low resource and it still works great. This is one of the reasons why many [lightweight Linux distributions][3] use Xfce by default. + +Some people prefer it even on a high-end device stating its simplicity, easy of use and non-resource hungry nature as the main reasons. + +[Xfce][4] is in itself minimal and provides just what you need. The one thing that bothers is its look and feel which feel old. However, you can easily customize Xfce to look modern and beautiful without reaching the limit where a Unity/GNOME session eats up system resources. + +### 4 ways to Customize Xfce desktop + +Let’s see some of the ways by which we can improve the look and feel of your Xfce desktop environment. + +The default Xfce desktop environment looks something like this : + +![Xfce default screen][5] + +As you can see, the default Xfce desktop is kinda boring. We will use some themes, icon packs and change the default dock to make it look fresh and a bit revealing. + +#### 1. Change themes in Xfce + +The first thing we will do is pick up a theme from [xfce-look.org][6]. My favorite Xfce theme is [XFCE-D-PRO][7]. + +You can download the theme from [here][8] and extract it somewhere. + +You can copy this extracted file to **.theme** folder in your home directory. If the folder is not present by default, you can create one and the same goes for icons which needs a **.icons** folder in the home directory. + +Open **Settings > Appearance > Style** to select the theme, log out and login to see the change. Adwaita-dark from default is also a nice one. + +![Appearance Xfce][9] + +You can use any [good GTK theme][10] on Xfce. + +#### 2. Change icons in Xfce + +Xfce-look.org also provides icon themes which you can download, extract and put it in your home directory under **.icons** directory. Once you have added the icon theme in the .icons directory, go to **Settings > Appearance > Icons** to select that icon theme. + +![Moka icon theme][11] + +I have installed [Moka icon set][12] that looks awesome. + +![Moka theme][13] + +You can also refer to our list of [awesome icon themes][14]. + +##### **Optional: Installing themes through Synaptic** + +If you want to avoid the manual search and copying of the files, install Synaptic Manager in your system. You can look for some best themes over web and icon sets, and using synaptic manager you can search and install it. +``` +sudo apt-get install synaptic + +``` + +**Searching and installing theme/icons through Synaptic** + +Open synaptic and click on **Search**. Enter your desired theme, and it will display the list of matching items. Mark all the additional required changes and click on **Apply**. This will download the theme and then install it. + +![Arc Theme][15] + +Once done, you can open the **Appearance** option to select the desired theme. + +In my opinion, this is not the best way to install themes in Xfce. + +#### 3. Change wallpapers in Xfce + +Again, the default Xfce wallpaper is not bad at all. But you can change the wallpaper to something that matches with your icons and themes. + +To change wallpapers in Xfce, right click on the desktop and click on Desktop Settings. You can change the desktop background from your custom collection or the defaults one given. + +Right click on the desktop and click on **Desktop Settings**. Choose **Background** from the folder option, and choose any one of the default backgrounds or a custom one. + +![Changing desktop wallpapers][16] + +#### 4. Change the dock in Xfce + +The default dock is nice and pretty much does what it is for. But again, it looks a bit boring. + +![Docky][17] + +However, if you want your dock to be better and with a little more customization options, you can install another dock. + +Plank is one of the simplest and lightweight docks and is highly configurable. + +To install Plank use the command below: + +`sudo apt-get install plank` + +If Plank is not available in the default repository, you can install it from this PPA. +``` +sudo add-apt-repository ppa:ricotz/docky +sudo apt-get update +sudo apt-get install plank + +``` + +Before you use Plank, you should remove the default dock by right-clicking in it and under Panel Settings, clicking on delete. + +Once done, go to **Accessory > Plank** to launch Plank dock. + +![Plank][18] + +Plank picks up icons from the one you are using. So if you change the icon themes, you’ll see the change is reflected in the dock also. + +### Wrapping Up + +XFCE is a lightweight, fast and highly customizable. If you are limited on system resource, it serves good and you can easily customize it to look better. Here’s how my screen looks after applying these steps. + +![XFCE desktop][19] + +This is just with half an hour of effort. You can make it look much better with different themes/icons customization. Feel free to share your customized XFCE desktop screen in the comments and the combination of themes and icons you are using. + +-------------------------------------------------------------------------------- + +via: https://itsfoss.com/customize-xfce/ + +作者:[Ambarish Kumar][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://itsfoss.com/author/ambarish/ +[1]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/07/xfce-customization.jpeg +[2]:https://itsfoss.com/best-linux-desktop-environments/ +[3]:https://itsfoss.com/lightweight-linux-beginners/ +[4]:https://xfce.org/ +[5]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/06/1-1-800x410.jpg +[6]:http://xfce-look.org +[7]:https://www.xfce-look.org/p/1207818/XFCE-D-PRO +[8]:https://www.xfce-look.org/p/1207818/startdownload?file_id=1523730502&file_name=XFCE-D-PRO-1.6.tar.xz&file_type=application/x-xz&file_size=105328&url=https%3A%2F%2Fdl.opendesktop.org%2Fapi%2Ffiles%2Fdownloadfile%2Fid%2F1523730502%2Fs%2F6019b2b57a1452471eac6403ae1522da%2Ft%2F1529360682%2Fu%2F%2FXFCE-D-PRO-1.6.tar.xz +[9]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/07/4.jpg +[10]:https://itsfoss.com/best-gtk-themes/ +[11]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/07/6.jpg +[12]:https://snwh.org/moka +[13]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/07/11-800x547.jpg +[14]:https://itsfoss.com/best-icon-themes-ubuntu-16-04/ +[15]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/07/5-800x531.jpg +[16]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/07/7-800x546.jpg +[17]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/07/8.jpg +[18]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/07/9.jpg +[19]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/07/10-800x447.jpg diff --git a/sources/tech/20180727 Download Subtitles Via Right Click From File Manager Or Command Line With OpenSubtitlesDownload.py.md b/sources/tech/20180727 Download Subtitles Via Right Click From File Manager Or Command Line With OpenSubtitlesDownload.py.md new file mode 100644 index 0000000000..9d4c7fedd7 --- /dev/null +++ b/sources/tech/20180727 Download Subtitles Via Right Click From File Manager Or Command Line With OpenSubtitlesDownload.py.md @@ -0,0 +1,221 @@ +Download Subtitles Via Right Click From File Manager Or Command Line With OpenSubtitlesDownload.py +====== +**If you're looking for a quick way to download subtitles from OpenSubtitles.org from your Linux desktop or server, give[OpenSubtitlesDownload.py][1] a try. This neat Python tool can be used as a Nautilus, Nemo or Caja script, or from the command line.** + +![](https://4.bp.blogspot.com/-Aq1A6erIWMI/W1sMHL89yTI/AAAAAAAABPg/LOs17N9XfUwftE9Mj_up48v8fcC9cb3EgCLcBGAs/s1600/opensubtitles-downloader-found.png) + +The Python script **searches for subtitles on OpenSubtitles.org using the video hash sum to find exact matches** , and thus avoid out of sync subtitles. In case no match is found, it then tries to perform a search based on the video file name, although such subtitles may not always be in sync. + +OpenSubtitlesDownload.py has quite a few cool features, including **support for more than 60 languages,** and it can query both multiple subtitle languages and videos in the same time (so it **supports mass subtitle search and download** ). + +The **optional graphical user interface** (uses Zenity for Gnome and Kdialog for KDE) can display multiple subtitle matches and by digging into its settings you can enable the display of some extra information, like the subtitles download count, rating, language, and more. + +Other OpenSubtitlesDownload.py features include: + + * Option to download subtitles automatically if only one is available, choose the one you want otherwise. + * Option to rename downloaded subtitles to match source video file. Possibility to append the language code to the file name (ex: movie_en.srt). + + + +The Python tool does not yet support downloading subtitles for movies within a directory recursively, but this is a planned feature. + +In case you encounter errors when downloading a large number of subtitles, you should be aware that OpenSubtitles has a daily subtitle download limit (it appears it was 200 subtitles downloads / day a while back, I'm not sure if it changed). For VIP users it's 1000 subtitles per day, but OpenSubtitlesDownload.py does not allow logging it to an OpenSubtitles account and thus, you can't take advantage of a VIP account while using this tool. + +### Installing and using OpenSubtitlesDownload.py as a Nautilus, Nemo or Caja script + +The instructions below explain how to install OpenSubtitlesDownload.py as a script for Caja, Nemo or Nautilus file managers. Thanks to this you'll be able to right click (context menu) one or multiple video files in your file manager, select `Scripts > OpenSubtitlesDownload.py` and the script will search for and download subtitles from OpenSubtitles.org for your video files. + +This is OpenSubtitlesDownload.py used as a Nautilus script: + +![](https://3.bp.blogspot.com/-9w0n1TW_s9w/W1sNZWPhSoI/AAAAAAAABPs/kMn3aO-ZQqE9FZIxRe9z9XXoBXXMdx8_wCLcBGAs/s1600/opensubtitles-downloader-nautilus.png) + +And as a Nemo script: + +![](https://1.bp.blogspot.com/-DXyjV9Jvbvw/W1sNe_Jn8GI/AAAAAAAABPw/LdPJtKdcUCUMyF6_ihurIUM6wdHraB4ywCLcBGAs/s1600/opensubtitles-downloader-nemo.png) + +To install OpenSubtitlesDownload.py as a Nautilus, Nemo or Caja script, see the instructions below. + +1\. Install the dependencies required by OpenSubtitlesDownload.py + +You'll need to install `gzip` , `wget` and `zenity` before using OpenSubtitlesDownload.py. The instructions below assume you already have Python (both Python 2 and 3 will do it), as well as `ps` and `grep` available. + +In Debian, Ubuntu, or Linux Mint, install `gzip` , `wget` and `zenity` using this command: +``` +sudo apt install gzip wget zenity + +``` + +2\. Now you can download the OpenSubtitlesDownload.py +``` +wget https://raw.githubusercontent.com/emericg/OpenSubtitlesDownload/master/OpenSubtitlesDownload.py + +``` + +3\. Use the commands below to move the downloaded OpenSubtitlesDownload.py script to the file manager scripts folder and make it executable (use the commands for your current file manager - Nautilus, Nemo or Caja): + + * Nautilus (default Gnome, Unity and Solus OS file manager): + + +``` +mkdir -p ~/.local/share/nautilus/scripts +mv OpenSubtitlesDownload.py ~/.local/share/nautilus/scripts/ +chmod u+x ~/.local/share/nautilus/scripts/OpenSubtitlesDownload.py + +``` + + * Nemo (default Cinnamon file manager): + + +``` +mkdir -p ~/.local/share/nemo/scripts +mv OpenSubtitlesDownload.py ~/.local/share/nemo/scripts/ +chmod u+x ~/.local/share/nemo/scripts/OpenSubtitlesDownload.py + +``` + + * Caja (default MATE file manager): + + +``` +mkdir -p ~/.config/caja/scripts +mv OpenSubtitlesDownload.py ~/.config/caja/scripts/ +chmod u+x ~/.config/caja/scripts/OpenSubtitlesDownload.py + +``` + +4\. Configure OpenSubtitlesDownload.py + +Since it's running as a file manager script, without any arguments, you'll need to modify the script if you want to change some of its settings, like enabling the GUI, changing the subtitles language, and so on. These are optional of course, and you can use it directly to automatically download subtitles using its default settings. + +To Configure OpenSubtitlesDownload.py, you'll need to open it with a text editor. The script path should now be: + + * Nautilus: + +`~/.local/share/nautilus/scripts` + + * Nemo: + +`~/.local/share/nemo/scripts` + + * Caja: + +`~/.config/caja/scripts` + + + + +Navigate to that folder using your file manager and open the OpenSubtitlesDownload.py file with a text editor. + +Here's what you may want to change in this file: + + * To change the subtitle language, search for `opt_languages = ['eng']` and change the language from `['eng']` (English) to `['fre']` (French), or whatever language you want to use. The ISO codes for each language supported by OpenSubtitles.org are available on [this][2] page (use the code in the first column). + + * If you want a GUI to present you with all subtitles options and let you choose which to download, find the `opt_selection_mode = 'default'` setting and change it to `'manual'` . You'll not want to change this to 'manual' (or better yet, change it to 'auto') if you want to download multiple subtitles in the same time and avoid having a window popup for each video! + + * To force the Gnome GUI to be used, search for `opt_gui = 'auto'` and change `'auto'` to `'gnome'` + + * You can also enable multiple info columns in the GUI: + + * Search for `opt_selection_rating = 'off'` and change it to `'auto'` to display user ratings if available + + * Search for `opt_selection_count = 'off'` and change it to `'auto'` to display the subtitle number of downloads if available + + +**You can find a list of OpenSubtitlesDownload.py settings with explanations by visiting[this page][3].** + +And you're done. OpenSubtitlesDownload.py should now appear in Nautilus, Nemo or Caja, when right clicking a file and selecting Scripts. Clicking OpenSubtitlesDownload.py should search and download subtitles for the selected video(s). + +### Installing and using OpenSubtitlesDownload.py from the command line + +1\. Install the dependencies required by OpenSubtitlesDownload.py (command line only) + +You'll need to install `gzip` and `wget` . On Debian, Ubuntu or Linux Mint you can install these packages by using this command: +``` +sudo apt install wget gzip + +``` + +2\. Install the `/usr/local/bin/` and set it so it uses the command line interface by default: +``` +wget https://raw.githubusercontent.com/emericg/OpenSubtitlesDownload/master/OpenSubtitlesDownload.py -O opensubtitlesdownload +sed -i "s/opt_gui = 'auto'/opt_gui = 'cli'/" opensubtitlesdownload +sudo install opensubtitlesdownload /usr/local/bin/ + +``` + +Now you can start using it. To use the script with automatic selection and download of the best available subtitle, type: +``` +opensubtitlesdownload --auto /path/to/video.mkv + +``` + +You can specify the language by appending `--lang LANG` , where `LANG` is the ISO code for a language supported by OpenSubtitles.org, available on +``` +opensubtitlesdownload --lang SPA /home/logix/Videos/Sintel.2010.720p.mkv + +``` + +Which provides this output (it allows you to choose the best subtitle since we didn't use `--auto` only, nor did we append `--select manual` to allow manual selection): +``` +>> Title: Sintel +>> Filename: Sintel.2010.720p.mkv +>> Available subtitles: +[1] "Sintel (2010).spa.srt" > "Language: Spanish" +[2] "sintel_es.srt" > "Language: Spanish" +[3] "Sintel.2010.720p.x264-VODO-spa.srt" > "Language: Spanish" +[0] Cancel search +>> Enter your choice (0-3): 1 +>> Downloading 'Spanish' subtitles for 'Sintel' +2018-07-27 14:37:04 URL:http://dl.opensubtitles.org/en/download/src-api/vrf-19c10c57/sid-8rL5O0xhUw2BgKG6lvsVBM0p00f/filead/1955318590.gz [936/936] -> "-" [1] + +``` + +These are all the available options: +``` +$ opensubtitlesdownload --help +usage: OpenSubtitlesDownload.py [-h] [-g GUI] [--cli] [-s SEARCH] [-t SELECT] + [-a] [-v] [-l [LANG]] + filePathListArg [filePathListArg ...] + +This software is designed to help you find and download subtitles for your favorite videos! + + + -h, --help show this help message and exit + -g GUI, --gui GUI Select the GUI you want from: auto, kde, gnome, cli (default: auto) + --cli Force CLI mode + -s SEARCH, --search SEARCH + Search mode: hash, filename, hash_then_filename, hash_and_filename (default: hash_then_filename) + -t SELECT, --select SELECT + Selection mode: manual, default, auto + -a, --auto Force automatic selection and download of the best subtitles found + -v, --verbose Force verbose output + -l [LANG], --lang [LANG] + Specify the language in which the subtitles should be downloaded (default: eng). + Syntax: + -l eng,fre: search in both language + -l eng -l fre: download both language + +``` + +**The theme used for the screenshots in this article is called[Canta][4].** + +**You may also be interested in:[How To Replace Nautilus With Nemo File Manager On Ubuntu 18.04 Gnome Desktop (Complete Guide)][5]** + +-------------------------------------------------------------------------------- + +via: https://www.linuxuprising.com/2018/07/download-subtitles-via-right-click-from.html + +作者:[Logix][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://plus.google.com/118280394805678839070 +[1]:https://emericg.github.io/OpenSubtitlesDownload/ +[2]:http://www.opensubtitles.org/addons/export_languages.php +[3]:https://github.com/emericg/OpenSubtitlesDownload/wiki/Adjust-settings +[4]:https://www.linuxuprising.com/2018/04/canta-is-amazing-material-design-gtk.html +[5]:https://www.linuxuprising.com/2018/07/how-to-replace-nautilus-with-nemo-file.html +[6]:https://raw.githubusercontent.com/emericg/OpenSubtitlesDownload/master/OpenSubtitlesDownload.py diff --git a/sources/tech/20180727 How to analyze your system with perf and Python.md b/sources/tech/20180727 How to analyze your system with perf and Python.md new file mode 100644 index 0000000000..ccc66b04a7 --- /dev/null +++ b/sources/tech/20180727 How to analyze your system with perf and Python.md @@ -0,0 +1,1481 @@ +pinewall translating + +How to analyze your system with perf and Python +====== + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/metrics_data_dashboard_system_computer_analytics.png?itok=oxAeIEI-) + +Modern computers are ever increasing in performance and capacity. This matters little if that increasing capacity is not well utilized. Following is a description of the motivation and work behind "curt," a new tool for Linux systems for measuring and breaking down system utilization by process, by task, and by CPU using the `perf` command's Python scripting capabilities. + +I had the privilege of presenting this topic at [Texas Linux Fest 2018][1], and here I've gone a bit deeper into the details, included links to further information, and expanded the scope of my talk. + +### System utilization + +In discussing computation, let's begin with some assertions: + + 1. Every computational system is equally fast at doing nothing. + 2. Computational systems were created to do things. + 3. A computational system is better at doing things when it is doing something than when it is doing nothing. + + + +Modern computational systems have many streams of execution: + + * Often, very large systems are created by literally wiring together smaller systems. At IBM, these smaller systems are sometimes called CECs (short for Central Electronics Complexes and pronounced "keks"). + * There are multiple sockets for processor modules in each system. + * There are sometimes multiple chips per socket (in the form of dual-chip modules—DCMs—or multi-chip modules—MCMs). + * There are multiple cores per chip. + * There are multiple threads per core. + + + +In sum, there are potentially thousands of execution threads across a single computational system. + +Ideally, all these execution streams are 100% busy doing useful work. One measure of **utilization** for an individual execution stream (CPU thread) is the percentage of time that thread has tasks scheduled and running. (Note that I didn't say "doing useful work." Creating a tool that measures useful work is left as an exercise for the reader.) By extension, **system utilization** is the overall percentage of time that all execution streams of a system have tasks scheduled and running. Similarly, utilization can be defined with respect to an individual task. **Task utilization** is the percentage of the lifetime of the task that was spent actively running on any CPU thread. By extension, **process utilization** is the collective utilization of its tasks. + +### Utilization measurement tools + +There are tools that measure system utilization: `uptime`, `vmstat`, `mpstat`, `nmon`, etc. There are tools that measure individual process utilization: `time`. There are not many tools that measure system-wide per-process and per-task utilization. One such command is `curt` on AIX. According to [IBM's Knowledge Center][2]: "The `curt` command takes an AIX trace file as input and produces a number of statistics related to processor (CPU) utilization and process/thread/pthread activity." + +The AIX `curt` command reports system-wide, per-processor, per-process, and per-task statistics for application processing (user time), system calls (system time), hypervisor calls, kernel threads, interrupts, and idle time. + +This seems like a good model for a similar command for a Linux system. + +### Utilization data + +Before starting to create any tools for utilization analysis, it is important to know what data is required. Since utilization is directly related to whether a task is actively running or not, related scheduling events are required: When is the task made to run, and when is it paused? Tracking on which CPU the task runs is important, so migration events are required for implicit migrations. There are also certain system calls that force explicit migrations. Creation and deletion of tasks are obviously important. Since we want to understand user time, system time, hypervisor time, and interrupt time, events that show the transitions between those task states are required. + +The Linux kernel contains "tracepoints" for all those events. It is possible to enable tracing for those events directly in the kernel's `debugfs` filesystem, usually mounted at `/sys/kernel/debug`, in the `tracing` directory (`/sys/kernel/debug/tracing`). + +An easier way to record tracing data is with the Linux `perf` command. + +### The perf command + +`perf` is a very powerful userspace command for tracing or counting both hardware and software events. + +Software events are predefined in the kernel, can be predefined in userspace code, and can be dynamically created (as "probes") in kernel or userspace code. + +`perf` can do much more than just trace and count, though. + +#### perf stat + +The `stat` subcommand of `perf` will run a command, count some events commonly found interesting, and produce a simple report: +``` +Performance counter stats for './load 100000': +  +      90537.006424      task-clock:u (msec)       #    1.000 CPUs utilized           +                 0      context-switches:u        #    0.000 K/sec                   +                 0      cpu-migrations:u          #    0.000 K/sec                   +               915      page-faults:u             #    0.010 K/sec                   +   386,836,206,133      cycles:u                  #    4.273 GHz                      (66.67%) +     3,488,523,420      stalled-cycles-frontend:u #    0.90% frontend cycles idle     (50.00%) +   287,222,191,827      stalled-cycles-backend:u  #   74.25% backend cycles idle      (50.00%) +   291,102,378,513      instructions:u            #    0.75  insn per cycle         +                                                  #    0.99  stalled cycles per insn  (66.67%) +    43,730,320,236      branches:u                #  483.010 M/sec                    (50.00%) +       822,030,340      branch-misses:u           #    1.88% of all branches          (50.00%) +  +      90.539972837 seconds time elapsed +``` + +#### perf record, perf report, and perf annotate + +For much more interesting analysis, the `perf` command can also be used to record events and information associated with the task state at the time the event occurred: +``` +$ perf record ./some-command +[ perf record: Woken up 55 times to write data ] +[ perf record: Captured and wrote 13.973 MB perf.data (366158 samples) ] +$ perf report --stdio --show-nr-samples --percent-limit 4 +# Samples: 366K of event 'cycles:u' +# Event count (approx.): 388851358382 +# +# Overhead       Samples  Command  Shared Object      Symbol                                           +# ........  ............  .......  .................  ................................................ +# +    62.31%        228162  load     load               [.] main +    19.29%         70607  load     load               [.] sum_add +    18.33%         67117  load     load               [.] sum_sub +``` + +This example shows a program that spends about 60% of its running time in the function `main` and about 20% each in subfunctions `sum_sub` and `sum_add`. Note that the default event used by `perf record` is "cycles." Later examples will show how to use `perf record` with other events. + +`perf report` can further report runtime statistics by source code line (if the compilation was performed with the `-g` flag to produce debug information): +``` +$ perf report --stdio --show-nr-samples --percent-limit 4 --sort=srcline +# Samples: 366K of event 'cycles:u' +# Event count (approx.): 388851358382 +# +# Overhead       Samples  Source:Line                         +# ........  ............  ................................... +# +    19.40%         71031  load.c:58 +    16.16%         59168  load.c:18 +    15.11%         55319  load.c:14 +    13.30%         48690  load.c:66 +    13.23%         48434  load.c:70 +     4.58%         16767  load.c:62 +     4.01%         14677  load.c:56 +``` + +Further, `perf annotate` can show statistics for each instruction of the program: +``` +$ perf annotate --stdio +Percent |      Source code & Disassembly of load for cycles:u (70607 samples) +------------------------------------------------------------------------------ +         :      0000000010000774 : +         :      int sum_add(int sum, int value) { +   12.60 :        10000774:   std     r31,-8(r1) +    0.02 :        10000778:   stdu    r1,-64(r1) +    0.00 :        1000077c:   mr      r31,r1 +   41.90 :        10000780:   mr      r10,r3 +    0.00 :        10000784:   mr      r9,r4 +    0.05 :        10000788:   stw     r10,32(r31) +   23.78 :        1000078c:   stw     r9,36(r31) +         :              return (sum + value); +    0.76 :        10000790:   lwz     r10,32(r31) +    0.00 :        10000794:   lwz     r9,36(r31) +   14.75 :        10000798:   add     r9,r10,r9 +    0.00 :        1000079c:   extsw   r9,r9 +         :      } +    6.09 :        100007a0:   mr      r3,r9 +    0.02 :        100007a4:   addi    r1,r31,64 +    0.03 :        100007a8:   ld      r31,-8(r1) +    0.00 :        100007ac:   blr +``` + +(Note: this code is not optimized.) + +#### perf top + +Similar to the `top` command, which displays (at a regular update interval) the processes using the most CPU time, `perf top` will display the functions using the most CPU time among all processes on the system, a nice leap in granularity. + +![](https://opensource.com/sites/default/files/uploads/perf-top.gif) + +#### perf list + +The examples thus far have used the default event, run cycles. There are hundreds and perhaps thousands of events of different types. `perf list` will show them all. Following are just a few examples: +``` +$ perf list +  instructions                                       [Hardware event] +  context-switches OR cs                             [Software event] +  L1-icache-loads                                    [Hardware cache event] +  mem_access OR cpu/mem_access/                      [Kernel PMU event] +cache: +  pm_data_from_l2                                   +       [The processor's data cache was reloaded from local core's L2 due to a demand load] +floating point: +  pm_fxu_busy                                       +       [fxu0 busy and fxu1 busy] +frontend: +  pm_br_mpred_cmpl                                   +       [Number of Branch Mispredicts] +memory: +  pm_data_from_dmem                                 +       [The processor's data cache was reloaded from another chip's memory on the same Node or Group (Distant) due to a demand load] +  pm_data_from_lmem                                 +       [The processor's data cache was reloaded from the local chip's Memory due to a demand load] +  rNNN                                               [Raw hardware event descriptor] +  raw_syscalls:sys_enter                             [Tracepoint event] +  syscalls:sys_enter_chmod                           [Tracepoint event] +  sdt_libpthread:pthread_create                      [SDT event] +``` + +Events labeled as `Hardware event`, `Hardware cache event`, `Kernel PMU event`, and most (if not all) of the events under the categories like `cache`, `floating point`, `frontend`, and `memory` are hardware events counted by the hardware and triggered each time a certain count is reached. Once triggered, an entry is made into the kernel trace buffer with the current state of the associated task. `Raw hardware event` codes are alphanumeric encodings of the hardware events. These are mostly needed when the hardware is newer than the kernel and the user needs to enable events that are new for that hardware. Users will rarely, if ever, need to use raw event codes. + +Events labeled `Tracepoint event` are embedded in the kernel. These are triggered when that section of code is executed by the kernel. There are "syscalls" events for every system call supported by the kernel. `raw_syscalls` events are triggered for every system call. Since there is a limit to the number of events being actively traced, the `raw_syscalls` events may be more practical when a large number of system calls need to be traced. + +Events labeled `SDT event` are for software-defined tracepoints (SDTs). These can be embedded in application or library code and enabled as needed. When enabled, they behave just like other events: When that section of code is executed (by any task being traced on the system), an entry is made in the kernel trace buffer with the current state of the associated task. This is a very powerful capability that can prove very useful. + +#### perf buildid-cache and perf probe + +Enabling SDTs is easy. First, make the SDTs for a certain library known to `perf`: +``` +$ perf buildid-cache -v --add /lib/powerpc64le-linux-gnu/libpthread.so.0 +$ perf list | grep libpthread +[…] +  sdt_libpthread:pthread_create                      [SDT event] +[…] +``` + +Then, turn SDT definitions into available tracepoints: +``` +$ /usr/bin/sudo perf probe sdt_libpthread:pthread_create +Added new event: +  sdt_libpthread:pthread_create (on %pthread_create in /lib/powerpc64le-linux-gnu/libpthread-2.27.so) +You can now use it in all perf tools, such as: +    perf record -e sdt_libpthread:pthread_create -aR sleep 1 +$ perf record -a -e sdt_libpthread:pthread_create ./test +[ perf record: Woken up 1 times to write data ] +[ perf record: Captured and wrote 0.199 MB perf.data (9 samples) ] +``` + +Note that any location in an application or library can be made into a tracepoint. To find functions in an application that can be made into tracepoints, use `perf probe` with `–funcs`: +``` +$ perf probe –x ./load --funcs +[…] +main +sum_add +sum_sub +``` + +To enable the function `main` of the `./load` application as a tracepoint: +``` +/usr/bin/sudo perf probe –x ./load main +Added new event: +  probe_load:main      (on main in /home/pc/projects/load-2.1pc/load) +You can now use it in all perf tools, such as: +    perf record –e probe_load:main –aR sleep 1 +$ perf list | grep load:main +  probe_load:main                                     [Tracepoint event] +$ perf record –e probe_load:main ./load +[ perf record: Woken up 1 times to write data ] +[ perf record: Captured and wrote 0.024 MB perf.data (1 samples) ] +``` + +#### perf script + +Continuing the previous example, `perf script` can be used to walk through the `perf.data` file and output the contents of each record: +``` +$ perf script +            Load 16356 [004] 80526.760310: probe_load:main: (4006a2) +``` + +### Processing perf trace data + +The preceding discussion and examples show that `perf` can collect the data required for system utilization analysis. However, how can that data be processed to produce the desired results? + +#### perf eBPF + +A relatively new and emerging technology with `perf` is called [eBPF][3]. BPF is an acronym for Berkeley Packet Filter, and it is a C-like language originally for, not surprisingly, network packet filtering in the kernel. eBPF is an acronym for extended BPF, a similar, but more robust C-like language based on BPF. + +Recent versions of `perf` can be used to incorporate compiled eBPF code into the kernel to securely and intelligently handle events for any number of purposes, with some limitations. + +The capability is very powerful and quite useful for real-time, continuous updates of event-related data and statistics. + +However, as this capability is emerging, support is mixed on current releases of Linux distributions. It's a bit complicated (or, put differently, I have not figured it out yet). It's also only for online use; there is no offline capability. For these reasons, I won't cover it further here. + +#### perf data file + +`perf record` produces a `perf.data` file. The file is a structured binary file, is not particularly well documented, has no programming interface for access, and is unclear on what compatibility guarantees exist. For these reasons, I chose not to directly use the `perf.data` file. + +#### perf script + +One of the last examples above showed how `perf script` is used for walking through the `perf.data` file and emitting basic information about each record there. This is an appropriate model for what would be needed to process the file and track the state changes and compute the statistics required for system utilization analysis. + +`perf script` has several modes of operation, including several higher-level scripts that come with `perf` that produce statistics based on the trace data in a `perf.data` file. +``` +$ perf script -l +List of available trace scripts: +  rw-by-pid                            system-wide r/w activity +  rwtop [interval]                     system-wide r/w top +  wakeup-latency                       system-wide min/max/avg wakeup latency +  failed-syscalls [comm]               system-wide failed syscalls +  rw-by-file                    r/w activity for a program, by file +  failed-syscalls-by-pid [comm]        system-wide failed syscalls, by pid +  intel-pt-events                      print Intel PT Power Events and PTWRITE +  syscall-counts-by-pid [comm]         system-wide syscall counts, by pid +  export-to-sqlite [database name] [columns] [calls] export perf data to a sqlite3 database +  futex-contention                     futext contention measurement +  sctop [comm] [interval]              syscall top +  event_analyzing_sample               analyze all perf samples +  net_dropmonitor                      display a table of dropped frames +  compaction-times [-h] [-u] [-p|-pv] [-t | [-m] [-fs] [-ms]] [pid|pid-range|comm-regex] display time taken by mm compaction +  export-to-postgresql [database name] [columns] [calls] export perf data to a postgresql database +  stackcollapse                        produce callgraphs in short form for scripting use +  netdev-times [tx] [rx] [dev=] [debug] display a process of packet and processing time +  syscall-counts [comm]                system-wide syscall counts +  sched-migration                      sched migration overview +$ perf script failed-syscalls-by-pid /bin/ls +  +syscall errors: +  +comm [pid]                           count +------------------------------  ---------- +  +ls [18683] +  syscall: access           +    err = ENOENT                         1 +  syscall: statfs           +    err = ENOENT                         1 +  syscall: ioctl           +    err = ENOTTY                         3 +``` + +What do these scripts look like? Let's find out. +``` +$ locate failed-syscalls-by-pid +/usr/libexec/perf-core/scripts/python/failed-syscalls-by-pid.py +[…] +$ rpm –qf /usr/libexec/perf-core/scripts/python/failed-syscalls-by-pid.py +perf-4.14.0-46.el7a.x86_64 +$ $ ls /usr/libexec/perf-core/scripts +perl  python +$ perf script -s lang +  +Scripting language extensions (used in perf script -s [spec:]script.[spec]): +  +  Perl                                       [Perl] +  pl                                         [Perl] +  Python                                     [Python] +  py                                         [Python] +``` + +So, these scripts come with `perf`, and both Python and Perl are supported languages. + +Note that for the entirety of this content, I will refer exclusively to Python. + +#### perf scripts + +How do these scripts do what they do? Here are important extracts from `/usr/libexec/perf-core/scripts/python/failed-syscalls-by-pid.py`: +``` +def raw_syscalls__sys_exit(event_name, context, common_cpu, +        common_secs, common_nsecs, common_pid, common_comm, +        common_callchain, id, ret): +[…] +        if ret < 0: +[…] +                        syscalls[common_comm][common_pid][id][ret] += 1 +``` + +The function `raw_syscalls__sys_exit` has parameters for all the data for the associated event. The rest of the function only increments a counter associated with the command, process ID, and system call. The rest of the code doesn't do that much. Most of the complexity is in the function signature for the event-handling routine. + +Fortunately, `perf` makes it easy to figure out the proper signatures for various tracepoint event-handling functions. + +#### perf script –gen-script + +For the `raw_syscalls` events, we can generate a trace containing just those events: +``` +$ perf list | grep raw_syscalls +  raw_syscalls:sys_enter                             [Tracepoint event] +  raw_syscalls:sys_exit                              [Tracepoint event] +$ perf record -e 'raw_syscalls:*' /bin/ls >/dev/null +[ perf record: Woken up 1 times to write data ] +[ perf record: Captured and wrote 0.025 MB perf.data (176 samples) ] +``` + +We can then have `perf` generate a script that contains sample implementations of event-handling functions for the events in the `perf.data` file: +``` +$ perf script --gen-script python +generated Python script: perf-script.py +``` + +What do we find in the script? +``` +def raw_syscalls__sys_exit(event_name, context, common_cpu, +        common_secs, common_nsecs, common_pid, common_comm, +        common_callchain, id, ret): +[…] +def raw_syscalls__sys_enter(event_name, context, common_cpu, +        common_secs, common_nsecs, common_pid, common_comm, +        common_callchain, id, args): +``` + +Both event-handling functions are specified with their signatures. Nice! + +Note that this script works with `perf script –s`: +``` +$ perf script -s ./perf-script.py +in trace_begin +raw_syscalls__sys_exit     7 94571.445908134    21117 ls                    id=0, ret=0 +raw_syscalls__sys_enter     7 94571.445942946    21117 ls                    id=45, args=���?bc���?� +[…] +``` + +Now we have a template on which to base writing a Python script to parse the events of interest for reporting system utilization. + +### perf scripting + +The Python scripts generated by `perf script –gen-script` are not directly executable. They must be invoked by `perf`: +``` +$ perf script –s ./perf-script.py +``` + +What's really going on here? + + 1. First, `perf` starts. The `script` subcommand's `-s` option indicates that an external script will be used. + + 2. `perf` establishes a Python runtime environment. + + 3. `perf` loads the specified script. + + 4. `perf` runs the script. The script can perform normal initialization and even handle command line arguments, although passing the arguments is slightly awkward, requiring a `--` separator between the arguments for `perf` and for the script: + ``` + $ perf script -s ./perf-script.py -- --script-arg1 [...] + + ``` + + 5. `perf` processes each record of the trace file, calling the appropriate event-handling function in the script. Those event-handling functions can do whatever they need to do. + + + + +### Utilization + +It appears that `perf` scripting has sufficient capabilities for a workable solution. What sort of information is required to generate the statistics for system utilization? + + * Task creation (`fork`, `pthread_create`) + * Task termination (`exit`) + * Task replacement (`exec`) + * Task migration, explicit or implicit, and current CPU + * Task scheduling + * System calls + * Hypervisor calls + * Interrupts + + + +It can be helpful to understand what portion of time a task spends in various system calls, handling interrupts, or making explicit calls out to the hypervisor. Each of these categories of time can be considered a "state" for the task, and the methods of transitioning from one state to another need to be tracked: + +![](https://opensource.com/sites/default/files/uploads/task-state-diagram.png) + +The most important point of the diagram is that there are events for each state transition. + + * Task creation: `clone` system call + * Task termination: `sched:sched_process_exit` + * Task replacement: `sched:sched_process_exec` + * Task migration: `sched_setaffinity` system call (explicit), `sched:sched_migrate_task` (implicit) + * Task scheduling: `sched:sched_switch` + * System calls: `raw_syscalls:sys_enter`, `raw_syscalls:sys_exit` + * Hypervisor calls: (POWER-specific) `powerpc:hcall_entry`, `powerpc:hcall_exit` + * Interrupts: `irq:irq_handler_entry`, `irq:irq_handler_exit` + + + +### The curt command for Linux + +`perf` provides a suitable infrastructure with which to capture the necessary data for system utilization. There are a sufficient set of events available for tracing in the Linux kernel. The Python scripting capabilities permit a powerful and flexible means of processing the trace data. It's time to write the tool. + +#### High-level design + +In processing each event, the relevant state of the affected tasks must be updated: + + * New task? Create and initialize data structures to track the task's state + * Command + * Process ID + * Task ID + * Migration count (0) + * Current CPU + * New CPU for this task? Create and initialize data structures for CPU-specific data + * User time (0) + * System time (0) + * Hypervisor time (0) + * Interrupt time (0) + * Idle time (0) + * New transaction for this task? Create and initialize data structures for transaction-specific data + * Elapsed time (0) + * Count (0) + * Minimum (maxint), maximum (0) + * Existing task? + * Accumulate time for the previous state + * Transaction ending? Accumulate time for the transaction, adjust minimum, maximum values + * Set new state + * Save current time (time current state entered) + * Migration? Increment migration count + + + +#### High-level example + +For a `raw_syscalls:sys_enter` event: + + * If this task has not been seen before, allocate and initialize a new task data structure + * If the CPU is new for this task, allocate and initialize a new CPU data structure + * If this system call is new for this task, allocate and initialize a new call data structure + * In the task data structure: + * Accumulate the time since the last state change in a bucket for the current state ("user") + * Set the new state ("system") + * Save the current timestamp as the start of this time period for the new state + + + +#### Edge cases + +##### sys_exit as a task's first event + +If the first event in the trace for a task is `raw_syscalls:sys_exit`: + + * There is no matching `raw_syscalls:sys_enter` with which to determine the start time of this system call. + * The accumulated time since the start of the trace was all spent in the system call and needs to be added to the overall elapsed time spent in all calls to this system call. + * The elapsed time of this system call is unknown. + * It would be inaccurate to account for this elapsed time in the average, minimum, or maximum statistics for this system call. + + + +In this case, the tool creates a separate bucket called "pending" for time spent in the system call that cannot be accounted for in the average, minimum, or maximum. + +A "pending" bucket is required for all transactional events (system calls, hypervisor calls, and interrupts). + +##### sys_enter as a task's last event + +Similarly, If the last event in the trace for a task is `raw_syscalls:sys_enter`: + + * There is no matching `raw_syscalls:sys_exit` with which to determine the end time of this system call. + * The accumulated time from the start of the system call to the end of the trace was all spent in the system call and needs to be added to the overall elapsed time spent in all calls to this system call. + * The elapsed time of this system call is unknown. + * It would be inaccurate to account for this elapsed time in the average, minimum, or maximum statistics for this system call. + + + +This elapsed time is also accumulated in the "pending" bucket. + +A "pending" bucket is required for all transactional events (system calls, hypervisor calls, and interrupts). + +Since this condition can only be discovered at the end of the trace, a final "wrap-up" step is required in the tool where the statistics for all known tasks are completed based on their final states. + +##### Indeterminable state + +It is possible that a very busy task (or a short trace) will never see an event for a task from which the task's state can be determined. For example, if only `sched:sched_switch` or `sched:sched_task_migrate` events are seen for a task, it is impossible to determine that task's state. However, the task is known to exist and to be running. + +Since the actual state cannot be determined, the runtime for the task is accumulated in a separate bucket, arbitrarily called "busy-unknown." For completeness, this time is also displayed in the final report. + +##### Invisible tasks + +For very, very busy tasks (or a short trace), it is possible that a task was actively running during the entire time the trace was being collected, but no events for that task appear in the trace. It was never migrated, paused, or forced to wait. + +Such tasks cannot be known to exist by the tool and will not appear in the report. + +#### curt.py Python classes + +##### Task + + * One per task + * Holds all task-specific data (command, process ID, state, CPU, list of CPU data structures [see below], migration count, lists of per-call data structures [see below]) + * Maintains task state + + + +##### Call + + * One per unique transaction, per task (for example, one for the "open" system call, one for the "close" system call, one for IRQ 27, etc.) + * Holds call-specific data (e.g., start timestamp, count, elapsed time, minimum, maximum) + * Allocated as needed (lazy allocation) + * Stored within a task in a Python dictionary indexed by the unique identifier of the call (e.g., system call code, IRQ number, etc.) + + + +##### CPU + + * One per CPU on which this task has been observed to be running + * Holds per-CPU task data (e.g., user time, system time, hypervisor call time, interrupt time) + * Allocated as needed (lazy allocation) + * Stored within a task in a Python dictionary indexed by the CPU number + + + +#### curt.py event processing example + +As previously discussed, `perf script` will iterate over all events in the trace and call the appropriate event-handling function for each event. + +A first attempt at an event-handling function for `sys_exit`, given the high-level example above, might be: +``` +tasks = {} + +def raw_syscalls__sys_enter(event_name, context, common_cpu, common_secs, common_nsecs, common_pid, common_comm, common_callchain, id, args): + + # convert the multiple timestamp values into a single value + timestamp = nsecs(common_secs, common_nsecs) + + # find this task's data structure + try: + task = tasks[common_pid] + except: + # new task! + task = Task() + # save the command string + task.comm = common_comm + # save the new task in the global list (dictionary) of tasks + tasks[common_pid] = task + + if common_cpu not in task.cpus: + # new CPU! + task.cpu = common_cpu + task.cpus[common_cpu] = CPU() + + # compute time spent in the previous state ('user') + delta = timestamp – task.timestamp + # accumulate 'user' time for this task/CPU + task.cpus[task.cpu].user += delta + if id not in task.syscalls: + # new system call for this task! + task.syscalls[id] = Call() + + # change task's state + task.mode = 'sys' + + # save the timestamp for the last event (this one) for this task + task.timestamp = timestamp + +def raw_syscalls__sys_exit(event_name, context, common_cpu, common_secs, common_nsecs, common_pid, common_comm, common_callchain, id, ret): + + # convert the multiple timestamp values into a single value + timestamp = nsecs(common_secs, common_nsecs) + + # get the task data structure + task = tasks[common_pid] + + # compute elapsed time for this system call + delta = task.timestamp - timestamp + + # accumulate time for this task/system call + task.syscalls[id].elapsed += delta + # increment the tally for this task/system call + task.syscalls[id].count += 1 + # adjust statistics + if delta < task.syscalls[id].min: + task.syscalls[id].min = delta + if delta > task.syscalls[id].max: + task.syscalls[id].max = delta + + # accumulate time for this task's state on this CPU + task.cpus[common_cpu].system += delta + + # change task's state + task.mode = 'user' + + # save the timestamp for the last event (this one) for this task + task.timestamp = timestamp +``` + +### Handling the edge cases + +Following are some of the edge cases that are possible and must be handled. + +#### Sys_exit as first event + +As a system-wide trace can be started at an arbitrary time, it is certainly possible that the first event for a task is `raw_syscalls:sys_exit`. This requires adding the same code for new task discovery from the event-handling function for `raw_syscalls:sys_enter` to the handler for `raw_syscalls:sys_exit`. This: +``` +  # get the task data structure +  task = tasks[common_pid] +``` + +becomes this: +``` +  # find this task's data structure +  try: +    task = tasks[common_pid] +  except: +    # new task! +    task = Task() +    # save the command string +    task.comm = common_comm +    # save the new task in the global list (dictionary) of tasks +    tasks[common_pid] = task +``` + +Another issue is that it is impossible to properly accumulate the data for this system call since there is no timestamp for the start of the system call. The time from the start of the trace until this event has been spent by this task in the system call. It would be inaccurate to ignore this time. It would also be inaccurate to incorporate this time such that it is used to compute the average, minimum, or maximum. The only reasonable option is to accumulate this separately, calling it "pending" system time. To accurately compute this time, the timestamp of the first event of the trace must be known. Since any event could be the first event in the trace, every event must conditionally save its timestamp if it is the first event. A global variable is required: +``` +start_timestamp = 0 + +``` + +And every event-handling function must conditionally save its timestamp: +``` +  # convert the multiple timestamp values into a single value +  timestamp = nsecs(common_secs, common_nsecs) + +  If start_timestamp = 0: +    start_timestamp = timestamp +``` + +So, the event-handling function for `raw_syscalls:sys_exit` becomes: +``` +def raw_syscalls__sys_exit(event_name, context, common_cpu, common_secs, common_nsecs, common_pid, common_comm, common_callchain, id, ret): + +  # convert the multiple timestamp values into a single value +  timestamp = nsecs(common_secs, common_nsecs) + +  If start_timestamp = 0: +    start_timestamp = timestamp + +  # find this task's data structure +  try: +    task = tasks[common_pid] + +    # compute elapsed time for this system call +    delta =  task.timestamp - timestamp + +    # accumulate time for this task/system call +    task.syscalls[id].elapsed += delta +    # increment the tally for this task/system call +    task.syscalls[id].count += 1 +    # adjust statistics +    if delta < task.syscalls[id].min: +      task.syscalls[id].min = delta +    if delta > task.syscalls[id].max: +      task.syscalls[id].max = delta + +  except: +    # new task! +    task = Task() +    # save the command string +    task.comm = common_comm +    # save the new task in the global list (dictionary) of tasks +    tasks[common_pid] = task + +    # compute elapsed time for this system call +    delta =  start_timestamp - timestamp + +    # accumulate time for this task/system call +    task.syscalls[id].pending += delta + +  # accumulate time for this task's state on this CPU +  task.cpus[common_cpu].system += delta + +  # change task's state +  task.mode = 'user' + +  # save the timestamp for the last event (this one) for this task +  task.timestamp = timestamp +``` +### Sys_enter as last event + +A similar issue to having `sys_exit` as the first event for a task is when `sys_enter` is the last event seen for a task. The time spent in the system call must be accumulated for completeness but can't accurately impact the average, minimum, nor maximum. This time will also be accumulated in for a separate "pending" state. + +To accurately determine the elapsed time of the pending system call, from `sys_entry` to the end of the trace period, the timestamp of the final event in the trace file is required. Unfortunately, there is no way to know which event is the last event until that event has already been processed. So, all events must save their respective timestamps in a global variable. + +It may be that many tasks are in the state where the last event seen for them was `sys_enter`. Thus, after the last event is processed, a final "wrap up" step is required to complete the statistics for those tasks. Fortunately, there is a `trace_end` function which is called by `perf` after the final event has been processed. + +Last, we need to save the `id` of the system call in every `sys_enter`. +``` +curr_timestamp = 0 + +def raw_syscalls__sys_enter(event_name, context, common_cpu, common_secs, common_nsecs, common_pid, common_comm, common_callchain, id, args): + +  # convert the multiple timestamp values into a single value +  curr_timestamp = nsecs(common_secs, common_nsecs) +[…] +  task.syscall = id +[…] + +def trace_end(): +        for tid in tasks.keys(): +                task = tasks[tid] +                # if this task ended while executing a system call +                if task.mode == 'sys': +                        # compute the time from the entry to the system call to the end of the trace period +                        delta = curr_timestamp - task.timestamp +                        # accumulate the elapsed time for this system call +                        task.syscalls[task.syscall].pending += delta +                        # accumulate the system time for this task/CPU +                        task.cpus[task.cpu].sys += delta +``` + +### Migrations + +A task migration is when a task running on one CPU is moved to another CPU. This can happen by either: + + 1. Explicit request (e.g., a call to `sched_setaffinity`), or + 2. Implicitly by the kernel (e.g., load balancing or vacating a CPU being taken offline) + + + +When detected: + + * The migration count for the task should be incremented + * The statistics for the previous CPU should be updated + * A new CPU data structure may need to be updated and initialized if the CPU is new for the task + * The task's current CPU is set to the new CPU + + + +For accurate statistics, task migrations must be detected as soon as possible. The first case, explicit request, happens within a system call and can be detected in the `sys_exit` event for that system call. The second case has its own event, `sched:sched_migrate_task`, so it will need a new event-handling function. +``` +def raw_syscalls__sys_exit(event_name, context, common_cpu, common_secs, common_nsecs, common_pid, common_comm, common_callchain, id, ret): + +  # convert the multiple timestamp values into a single value +  timestamp = nsecs(common_secs, common_nsecs) + +  If start_timestamp = 0: +    start_timestamp = timestamp + +  # find this task's data structure +  try: +    task = tasks[common_pid] + +    # compute elapsed time for this system call +    delta =  task.timestamp - timestamp + +    # accumulate time for this task/system call +    task.syscalls[id].elapsed += delta +    # increment the tally for this task/system call +    task.syscalls[id].count += 1 +    # adjust statistics +    if delta < task.syscalls[id].min: +      task.syscalls[id].min = delta +    if delta > task.syscalls[id].max: +      task.syscalls[id].max = delta + +  except: +    # new task! +    task = Task() +    # save the command string +    task.comm = common_comm +    # save the new task in the global list (dictionary) of tasks +    tasks[common_pid] = task + +    task.cpu = common_cpu + +    # compute elapsed time for this system call +    delta =  start_timestamp - timestamp + +    # accumulate time for this task/system call +    task.syscalls[id].pending += delta + +  If common_cpu != task.cpu: +    task.migrations += 1 +    # divide the time spent in this syscall in half... +    delta /= 2 +    # and give have to the previous CPU, below, and half to the new CPU, later +    task.cpus[task.cpu].system += delta + +  # accumulate time for this task's state on this CPU +  task.cpus[common_cpu].system += delta + +  # change task's state +  task.mode = 'user' + +  # save the timestamp for the last event (this one) for this task +  task.timestamp = timestamp + +def sched__sched_migrate_task(event_name, context, common_cpu, +        common_secs, common_nsecs, common_pid, common_comm, +        common_callchain, comm, pid, prio, orig_cpu, +        dest_cpu, perf_sample_dict): + +  If start_timestamp = 0: +    start_timestamp = timestamp + +  # find this task's data structure +  try: +    task = tasks[common_pid] +  except: +    # new task! +    task = Task() +    # save the command string +    task.comm = common_comm +    # save the new task in the global list (dictionary) of tasks +    tasks[common_pid] = task + +    task.cpu = common_cpu + +    If common_cpu not in task.cpus: +      task.cpus[common_cpu] = CPU() + +    task.migrations += 1 +``` + +### Task creation + +To accurately collect statistics for a task, it is essential to know when the task is created. Tasks can be created with `fork()`, which creates a new process, or `pthread_create()`, which creates a new task within the same process. Fortunately, both are manifested by a `clone` system call and made evident by a `sched:sched_process_fork` event. The lifetime of the task starts at the `sched_process_fork` event. The edge case that arises is that the first likely events for the new task are: + + 1. `sched_switch` when the new task starts running. The new task should be considered idle at creation until this event occurs + 2. `sys_exit` for the `clone` system call. The initial state of the new task needs to be based on the state of the task that creates it, including being within the `clone` system call. + + + +One edge case that must be handled is if the creating task (parent) is not yet known, it must be created and initialized, and the presumption is that it has been actively running since the start of the trace. +``` +def sched__sched_process_fork(event_name, context, common_cpu, +        common_secs, common_nsecs, common_pid, common_comm, +        common_callchain, parent_comm, parent_pid, child_comm, child_pid): +  global start_timestamp, curr_timestamp +  curr_timestamp = self.timestamp +  if (start_timestamp == 0): +    start_timestamp = curr_timestamp +  # find this task's data structure +  try: +    task = tasks[common_pid] +  except: +    # new task! +    task = Task() +    # save the command string +    task.comm = common_comm +    # save the new task in the global list (dictionary) of tasks +    tasks[common_pid] = task +  try: +    parent = tasks[self.parent_tid] +  except: +    # need to create parent task here! +    parent = Task(start_timestamp, self.command, 'sys', self.pid) +    parent.sched_stat = True # ? +    parent.cpu = self.cpu +    parent.cpus[parent.cpu] = CPU() +    tasks[self.parent_tid] = parent +  +    task.resume_mode = parent.mode +    task.syscall = parent.syscall +    task.syscalls[task.syscall] = Call() +    task.syscalls[task.syscall].timestamp = self.timestamp +``` + +### Task exit + +Similarly, for complete and accurate task statistics, it is essential to know when a task has terminated. There's an event for that: `sched:sched_process_exit`. This one is pretty easy to handle, in that the effort is just to close out the statistics and set the mode appropriately, so any end-of-trace processing will not think the task is still active: +``` +def sched__sched_process_exit_old(event_name, context, common_cpu, +        common_secs, common_nsecs, common_pid, common_comm, +        common_callchain, comm, pid, prio): +  global start_timestamp, curr_timestamp +  curr_timestamp = self.timestamp +  if (start_timestamp == 0): +    start_timestamp = curr_timestamp + +  # find this task's data structure +  try: +    task = tasks[common_pid] +  except: +    # new task! +    task = Task() +    # save the command string +    task.comm = common_comm +    task.timestamp = curr_timestamp +    # save the new task in the global list (dictionary) of tasks +    tasks[common_pid] = task + +  delta = timestamp – task.timestamp +  task.sys += delta +  task.mode = 'exit' +``` + +### Output + +What follows is an example of the report displayed by `curt`, slightly reformatted to fit on a narrower page width and with the idle-time classification data (which makes the output very wide) removed, and for brevity. Seen are two processes, 1497 and 2857. Process 1497 has two tasks, 1497 and 1523. Each task has a per-CPU summary and system-wide ("ALL" CPUs) summary. Each task's data is followed by the system call data for that task (if any), hypervisor call data (if any), and interrupt data (if any). After each process's respective tasks is a per-process summary. Process 2857 has a task 2857-0 that is the previous task image before an exec() system call replaced the process image. After all processes is a system-wide summary. +``` +1497: +-- [  task] command     cpu      user       sys       irq        hv      busy      idle |  util% moves +   [  1497] X             2  0.076354  0.019563  0.000000  0.000000  0.000000 15.818719 |   0.6% +   [  1497] X           ALL  0.076354  0.019563  0.000000  0.000000  0.000000 15.818719 |   0.6%     0 +  +  -- ( ID)name             count   elapsed      pending      average      minimum      maximum +     (  0)read                 2  0.004699     0.000000     0.002350     0.002130     0.002569 +     (232)epoll_wait           1  9.968375     5.865208     9.968375     9.968375     9.968375 +  +-- [  task] command     cpu      user       sys       irq        hv      busy      idle |  util% moves +   [  1523] InputThread   1  0.052598  0.037073  0.000000  0.000000  0.000000 15.824965 |   0.6% +   [  1523] InputThread ALL  0.052598  0.037073  0.000000  0.000000  0.000000 15.824965 |   0.6%     0 +  +  -- ( ID)name             count   elapsed      pending      average      minimum      maximum +     (  0)read                14  0.011773     0.000000     0.000841     0.000509     0.002185 +     (  1)write                2  0.010763     0.000000     0.005381     0.004974     0.005789 +     (232)epoll_wait           1  9.966649     5.872853     9.966649     9.966649     9.966649 +  +-- [  task] command     cpu      user       sys       irq        hv      busy      idle |  util% moves +   [   ALL]             ALL  0.128952  0.056636  0.000000  0.000000  0.000000 31.643684 |   0.6%     0 +  +2857: +-- [  task] command     cpu      user       sys       irq        hv      busy      idle |  util% moves +   [  2857] execs.sh      1  0.257617  0.249685  0.000000  0.000000  0.000000  0.266200 |  65.6% +   [  2857] execs.sh      2  0.000000  0.023951  0.000000  0.000000  0.000000  0.005728 |  80.7% +   [  2857] execs.sh      5  0.313509  0.062271  0.000000  0.000000  0.000000  0.344279 |  52.2% +   [  2857] execs.sh      6  0.136623  0.128883  0.000000  0.000000  0.000000  0.533263 |  33.2% +   [  2857] execs.sh      7  0.527347  0.194014  0.000000  0.000000  0.000000  0.990625 |  42.1% +   [  2857] execs.sh    ALL  1.235096  0.658804  0.000000  0.000000  0.000000  2.140095 |  46.9%     4 +  +  -- ( ID)name             count   elapsed      pending      average      minimum      maximum +     (  9)mmap                15  0.059388     0.000000     0.003959     0.001704     0.017919 +     ( 14)rt_sigprocmask      12  0.006391     0.000000     0.000533     0.000431     0.000711 +     (  2)open                 9  2.253509     0.000000     0.250390     0.008589     0.511953 +     (  3)close                9  0.017771     0.000000     0.001975     0.000681     0.005245 +     (  5)fstat                9  0.007911     0.000000     0.000879     0.000683     0.001182 +     ( 10)mprotect             8  0.052198     0.000000     0.006525     0.003913     0.018073 +     ( 13)rt_sigaction         8  0.004281     0.000000     0.000535     0.000458     0.000751 +     (  0)read                 7  0.197772     0.000000     0.028253     0.000790     0.191028 +     ( 12)brk                  5  0.003766     0.000000     0.000753     0.000425     0.001618 +     (  8)lseek                3  0.001766     0.000000     0.000589     0.000469     0.000818 +  +-- [  task] command     cpu      user       sys       irq        hv      busy      idle |  util% moves +   [2857-0] perf          6  0.053925  0.191898  0.000000  0.000000  0.000000  0.827263 |  22.9% +   [2857-0] perf          7  0.000000  0.656423  0.000000  0.000000  0.000000  0.484107 |  57.6% +   [2857-0] perf        ALL  0.053925  0.848321  0.000000  0.000000  0.000000  1.311370 |  40.8%     1 +  +  -- ( ID)name             count   elapsed      pending      average      minimum      maximum +     (  0)read                 0  0.000000     0.167845           --           --           -- +     ( 59)execve               0  0.000000     0.000000           --           --           -- +  +ALL: +-- [  task] command     cpu      user       sys       irq        hv      busy      idle |  util% moves +   [   ALL]             ALL 10.790803 29.633170  0.160165  0.000000  0.137747 54.449823 |   7.4%    50 +  +  -- ( ID)name             count   elapsed      pending      average      minimum      maximum +     (  1)write             2896  1.623985     0.000000     0.004014     0.002364     0.041399 +     (102)getuid            2081  3.523861     0.000000     0.001693     0.000488     0.025157 +     (142)sched_setparam     691  7.222906    32.012841     0.024925     0.002024     0.662975 +     ( 13)rt_sigaction       383  0.235087     0.000000     0.000614     0.000434     0.014402 +     (  8)lseek              281  0.169157     0.000000     0.000602     0.000452     0.013404 +     (  0)read               133  2.782795     0.167845     0.020923     0.000509     1.864439 +     (  7)poll                96  8.583354   131.889895     0.193577     0.000626     4.596280 +     (  4)stat                93  7.036355     1.058719     0.183187     0.000981     3.661659 +     ( 47)recvmsg             85  0.146644     0.000000     0.001725     0.000646     0.019067 +     (  3)close               79  0.171046     0.000000     0.002165     0.000428     0.020659 +     (  9)mmap                78  0.311233     0.000000     0.003990     0.001613     0.017919 +     (186)gettid              74  0.067315     0.000000     0.000910     0.000403     0.014075 +     (  2)open                71  3.081589     0.213059     0.184248     0.001921     0.937946 +     (202)futex               62  5.145112   164.286154     0.405566     0.000597    11.587437 +  +  -- ( ID)name             count   elapsed      pending      average      minimum      maximum +     ( 12)i8042               10  0.160165     0.000000     0.016016     0.010920     0.032805 +  +Total Trace Time: 15.914636 ms +``` + +### Hurdles and issues + +Following are some of the issues encountered in the development of `curt`. + +#### Out-of-order events + +One of the more challenging issues is the discovery that events in a `perf.data` file can be out of time order. For a program trying to monitor state transitions carefully, this is a serious issue. For example, a trace could include the following sequence of events, displayed as they appear in the trace file: +``` +time 0000:  sys_enter syscall1 +time 0007:  sys_enter syscall2 +time 0006:  sys_exit syscall1 +time 0009:  sys_exit syscall2 +``` + +Just blindly processing these events in the order they are presented to their respective event-handling functions (in the wrong time order) will result in incorrect statistics (or worse). + +The most user-friendly ways to handle out-of-order events include: + + * Prevent traces from having out-of-order events in the first place by changing the way `perf record` works + * Providing a means to reorder events in a trace file, perhaps by enhancing `perf inject` + * Modifying how `perf script` works to present the events to the event-handling functions in time order + + + +But user-friendly is not the same as straightforward, nor easy. Also, none of the above are in the user's control. + +I chose to implement a queue for incoming events that would be sufficiently deep to allow for proper reordering of all events. This required a significant redesign of the code, including implementation of classes for each event, and moving the event processing for each event type into a method in that event's class. + +In the redesigned code, the actual event handlers' only job is to save the relevant data from the event into an instance of the event class, queue it, then process the top (oldest in time) event from the queue: +``` +def raw_syscalls__sys_enter(event_name, context, common_cpu, common_secs, common_nsecs, common_pid, common_comm, common_callchain, id, args): +         event = Event_sys_enter(nsecs(common_secs,common_nsecs), common_cpu, common_pid, common_comm, id) +        process_event(event) +``` + +The simple reorderable queuing mechanism is in a common function: +``` +events = [] +n_events = 0 +def process_event(event): +        global events,n_events,curr_timestamp +        i = n_events +        while i > 0 and events[i-1].timestamp > event.timestamp: +                i = i-1 +        events.insert(i,event) +        if n_events < params.window: +                n_events = n_events+1 +        else: +                event = events[0] +                # need to delete from events list now, +                # because event.process() could reenter here +                del events[0] +                if event.timestamp < curr_timestamp: +                        sys.stderr.write("Error: OUT OF ORDER events detected.\n  Try increasing the size of the look-ahead window with --window=\n") +                event.process() +``` + +Note that the size of the queue is configurable, primarily for performance and to limit memory consumption. The function will report when that queue size is insufficient to eliminate out-of-order events. It is worth considering whether to consider this case a catastrophic failure and elect to terminate the program. + +Implementing a class for each event type led to some consideration for refactoring, such that common code could coalesce into a base class: +``` +class Event (object): +  +        def __init__(self): +                self.timestamp = 0 +                self.cpu = 0 +                self.tid = 0 +                self.command = 'unknown' +                self.mode = 'unknown' +                self.pid = 0 +  +        def process(self): +                global start_timestamp +  +                try: +                        task = tasks[self.tid] +                        if task.pid == 'unknown': +                                tasks[self.tid].pid = self.pid +                except: +                        task = Task(start_timestamp, self.command, self.mode, self.pid) +                        tasks[self.tid] = task +  +                if self.cpu not in task.cpus: +                        task.cpus[self.cpu] = CPU() +                        if task.cpu == 'unknown': +                                task.cpu = self.cpu +  +                if self.cpu != task.cpu: +                        task.cpu = self.cpu +                        task.migrations += 1 +  +                return task +``` + +Then a class for each event type would be similarly constructed: +``` +class Event_sys_enter ( Event ): +  +        def __init__(self, timestamp, cpu, tid, comm, id, pid): +                self.timestamp = timestamp +                self.cpu = cpu +                self.tid = tid +                self.command = comm +                self.id = id +                self.pid = pid +                self.mode = 'busy-unknown' +                +        def process(self): +                global start_timestamp, curr_timestamp +                curr_timestamp = self.timestamp +                if (start_timestamp == 0): +                        start_timestamp = curr_timestamp +  +                task = super(Event_sys_enter, self).process() +  +                if task.mode == 'busy-unknown': +                        task.mode = 'user' +                        for cpu in task.cpus: +                                task.cpus[cpu].user = task.cpus[cpu].busy_unknown +                                task.cpus[cpu].busy_unknown = 0 +  +                task.syscall = self.id +                if self.id not in task.syscalls: +                        task.syscalls[self.id] = Call() +  +                task.syscalls[self.id].timestamp = curr_timestamp +                task.change_mode(curr_timestamp, 'sys') +``` + +Further refactoring is evident above, as well, moving the common code that updates relevant statistics based on a task's state change and the state change itself into a `change_mode` method of the `Task` class. + +### Start-of-trace timestamp + +As mentioned above, for scripts that depend on elapsed time, there should be an easier way to get the first timestamp in the trace other than forcing every event-handling function to conditionally save its timestamp as the start-of-trace timestamp. + +### Awkward invocation + +The syntax for invoking a `perf` Python script, including script parameters, is slightly awkward: +``` +$ perf script –s ./curt.py -- --window=80 +``` + +Also, it's awkward that `perf` Python scripts are not themselves executable. + +The `curt.py` script was made directly executable and will invoke `perf`, which will in turn invoke the script. Implementation is a bit confusing but it's easy to use: +``` +$ ./curt.py --window=80 +``` + +This script must detect when it has been directly invoked. The Python environment established by `perf` is a virtual module from which the `perf` Python scripts import: +``` +try: +        from perf_trace_context import * +``` + +If this import fails, the script was directly invoked. In this case, the script will `exec perf`, specifying itself as the script to run, and passing along any command line parameters: +``` +except: +        if len(params.file_or_command) == 0: +                params.file_or_command = [ "perf.data" ] +        sys.argv = ['perf', 'script', '-i' ] + params.file_or_command + [ '-s', sys.argv[0] ] +        sys.argv.append('--') +        sys.argv += ['--window', str(params.window)] +        if params.debug: +                sys.argv.append('--debug') +        sys.argv += ['--api', str(params.api)] +        if params.debug: +                print sys.argv +        os.execvp("perf", sys.argv) +        sys.exit(1) +``` + +In this way, the script can not only be run directly, it can still be run by using the `perf script` command. + +#### Simultaneous event registration required + +An artifact of the way `perf` enables events can lead to unexpected trace data. For example, specifying: +``` +$ perf record –a –e raw_syscalls:sys_enter –e raw_syscalls:sys_exit ./command +``` + +Will result in a trace file that begins with the following series of events for a single task (the `perf` command itself): +``` +sys_enter +sys_enter +sys_enter +… + +``` + +This happens because `perf` will register the `sys_enter` event for every CPU on the system (because of the `-a` argument), then it will register the `sys_exit` event for every CPU. In the latter case, since the `sys_enter` event has already been enabled for each CPU, that event shows up in the trace; but since the `sys_exit` has not been enabled on each CPU until after the call returns, the `sys_exit` call does not show up in the trace. The reverse issue happens at the end of the trace file, with a series of `sys_exit` events in the trace because the `sys_enter` event has already been disabled. + +The solution to this issue is to group the events, which is not well documented: +``` +$ perf record –e '{raw_syscalls:sys_enter,raw_syscalls:sys_exit}' ./command +``` + +With this syntax, the `sys_enter` and `sys_exit` events are enabled simultaneously. + +#### Awkward recording step + +There are a lot of different events required for computation of the full set of statistics for tasks. This leads to a very long, complicated command for recording: +``` +$ perf record -e '{raw_syscalls:*,sched:sched_switch,sched:sched_migrate_task,sched:sched_process_exec,sched:sched_process_fork,sched:sched_process_exit,sched:sched_stat_runtime,sched:sched_stat_wait,sched:sched_stat_sleep,sched:sched_stat_blocked,sched:sched_stat_iowait,powerpc:hcall_entry,powerpc:hcall_exit}' -a *command --args* + +``` + +The solution to this issue is to enable the script to perform the record step itself, by itself invoking `perf`. A further enhancement is to proceed after the recording is complete and report the statistics from that recording: +``` +if params.record: +        # [ed. Omitting here the list of events for brevity] +        eventlist = '{' + eventlist + '}' # group the events +        command = ['perf', 'record', '--quiet', '--all-cpus', +                '--event', eventlist ] + params.file_or_command +        if params.debug: +                print command +        subprocess.call(command) +``` + +The command syntax required to record and report becomes: +``` +$ ./curt.py --record ./command +``` + +### Process IDs and perf API change + +Process IDs are treated a bit cavalierly by `perf` scripting. Note well above that one of the common parameters for the generated event-handling functions is named `common_pid`. This is not the process ID, but the task ID. In fact, on many current Linux-based distributions, there is no way to determine a task's process ID from within a `perf` Python script. This presents a serious problem for a script that wants to compute statistics for a process. + +Fortunately, in Linux kernel v4.14, an additional parameter was provided to each of the event-handling functions—`perf_sample_dict`—a dictionary from which the process ID could be extracted: (`perf_sample_dict['sample']['pid']`). + +Unfortunately, current Linux distributions may not have that version of the Linux kernel. If the script is written to expect that extra parameter, the script will fail and report an error: +``` +TypeError: irq__irq_handler_exit_new() takes exactly 11 arguments (10 given) +``` + +Ideally, a means to automatically discover if the additional parameter is passed would be available to permit a script to easily run with both the old and new APIs and to take advantage of the new API if it is available. Unfortunately, such a means is not readily apparent. + +Since there is clearly value in using the new API to determine process-wide statistics, `curt` provides a command line option to use the new API. `curt` then takes advantage of Python's lazy function binding to adjust, at run-time, which API to use: +``` +if params.api == 1: +        dummy_dict = {} +        dummy_dict['sample'] = {} +        dummy_dict['sample']['pid'] = 'unknown' +        raw_syscalls__sys_enter = raw_syscalls__sys_enter_old +        […] +else: +        raw_syscalls__sys_enter = raw_syscalls__sys_enter_new +        […] +``` + +This requires two functions for each event: +``` +def raw_syscalls__sys_enter_new(event_name, context, common_cpu, common_secs, common_nsecs, common_pid, common_comm, common_callchain, id, args, perf_sample_dict): +  +        event = Event_sys_enter(nsecs(common_secs,common_nsecs), common_cpu, common_pid, common_comm, id, perf_sample_dict['sample']['pid']) +        process_event(event) +  +def raw_syscalls__sys_enter_old(event_name, context, common_cpu, common_secs, common_nsecs, common_pid, common_comm, common_callchain, id, args): +        global dummy_dict +        raw_syscalls__sys_enter_new(event_name, context, common_cpu, common_secs, common_nsecs, common_pid, common_comm, common_callchain, id, args, dummy_dict) +``` + +Note that the event-handling function for the older API will make use of the function for the newer API, passing a statically defined dictionary containing just enough data such that accessing it as `perf_sample_dict['sample']['pid']` will work (resulting in `'unknown'`). + +#### Events reported on other CPUs + +Not all events that refer to a task are reported from a CPU on which the task is running. This could result in an artificially high migration count and other incorrect statistics. For these types of events (`sched_stat`), the event CPU is ignored. + +#### Explicit migrations (no sched_migrate event) + +While there is conveniently an event for when the kernel decides to migrate a task from one CPU to another, there is no event for when the task requests a migration on its own. These are effected by system calls (`sched_setaffinity`), so the `sys_exit` event handler must compare the event CPU to the task's CPU, and if different, presume a migration has occurred. (This is described above, but repeated here in the "issues" section for completeness.) + +#### Mapping system call IDs to names is architecture-specific + +System calls are identified in events only as unique numeric identifiers. These identifiers are not readily interpreted by humans in the report. These numeric identifiers are not readily mapped to their mnemonics because they are architecture-specific, and new system calls can be added in newer kernels. Fortunately, `perf` provides a means to map system call numeric identifiers to system call names. A simple example follows: +``` +from Util import syscall_name +def raw_syscalls__sys_enter(event_name, context, common_cpu, +        common_secs, common_nsecs, common_pid, common_comm, +        common_callchain, id, args, perf_sample_dict): +                print "%s id=%d" % (syscall_name(id), id) +``` + +Unfortunately, using syscall_name introduces a dependency on the `audit` python bindings. This dependency is being removed in upstream versions of perf. + +#### Mapping hypervisor call IDs to names is non-existent + +Similar to system calls, hypervisor calls are also identified only with numeric identifiers. For IBM's POWER hypervisor, they are statically defined. Unfortunately, `perf` does not provide a means to map hypervisor call identifiers to mnemonics. `curt` includes a (hardcoded) function to do just that: +``` +hcall_to_name = { +        '0x4':'H_REMOVE', +        '0x8':'H_ENTER',       +        '0xc':'H_READ',       +        '0x10':'H_CLEAR_MOD', +[…] +} +  +def hcall_name(opcode): +        try: +                return hcall_to_name[hex(opcode)] +        except: +                return str(opcode) +``` + +### Command strings as bytearrays + +`perf` stores command names and string arguments in Python bytearrays. Unfortunately, printing bytearrays in Python prints every character in the bytearray—even if the string is null-terminated. For example: +``` +$ perf record –a –e 'sched:sched_switch' sleep 3 +$ perf script –g Python +generated Python script: perf-script.py +$ perf script -s ./perf-script.py +in trace_begin +sched__sched_switch      3 664597.912692243    21223 perf                  prev_comm=perf^@-terminal-^@, prev_pid=21223, prev_prio=120, prev_state=, next_comm=migration/3^@^@^@^@^@, next_pid=23, next_prio=0 +[…] +``` + +One solution is to truncate the length of these bytearrays based on null termination, as needed before printing: +``` +def null(ba): +        null = ba.find('\x00') +        if null >= 0: +                ba = ba[0:null] +        return ba + +def sched__sched_switch(event_name, context, common_cpu, +        common_secs, common_nsecs, common_pid, common_comm, +        common_callchain, prev_comm, prev_pid, prev_prio, prev_state, +        next_comm, next_pid, next_prio, perf_sample_dict): + +                print "prev_comm=%s, prev_pid=%d, prev_prio=%d, " \ +                "prev_state=%s, next_comm=%s, next_pid=%d, " \ +                "next_prio=%d" % \ +                (null(prev_comm), prev_pid, prev_prio, +                flag_str("sched__sched_switch", "prev_state", prev_state), +                null(next_comm), next_pid, next_prio) +``` + +Which nicely cleans up the output: +``` +sched__sched_switch      3 664597.912692243    21223 perf                  prev_comm=perf, prev_pid=21223, prev_prio=120, prev_state=, next_comm=migration/3, next_pid=23, next_prio=0 +``` + +### Dynamic mappings, like IRQ number to name + +Dissimilar to system calls and hypervisor calls, interrupt numbers (IRQs) are dynamically assigned by the kernel on demand, so there can't be a static table mapping an IRQ number to a name. Fortunately, `perf` passes the name to the event's `irq_handler_entry` routine. This allows a script to create a dictionary that maps the IRQ number to a name: +``` +irq_to_name = {} +def irq__irq_handler_entry_new(event_name, context, common_cpu, common_secs, common_nsecs, common_pid, common_comm, common_callchain, irq, name, perf_sample_dict): +        irq_to_name[irq] = name +        event = Event_irq_handler_entry(nsecs(common_secs,common_nsecs), common_cpu, common_pid, common_comm, irq, name, getpid(perf_sample_dict)) +        process_event(event) +``` + +Somewhat oddly, `perf` does not pass the name to the `irq_handler_exit` routine. So, it is possible that a trace may only see an `irq_handler_exit` for an IRQ and must be able to tolerate that. Here, instead of mapping the IRQ to a name, the IRQ number is returned as a string instead: +``` +def irq_name(irq): +        if irq in irq_to_name: +                return irq_to_name[irq] +        return str(irq) +``` +#### Task 0 +Task 0 shows up everywhere. It's not a real task. It's a substitute for the "idle" state. It's the task ID given to the `sched_switch` event handler when the CPU is going to (or coming from) the "idle" state. It's often the task that is "interrupted" by interrupts. Tracking the statistics for task 0 as if it were a real task would not make sense. Currently, `curt` ignores task 0. However, this loses some information, like some time spent in interrupt processing. `curt` should, but currently doesn't, track interesting (non-idle) time for task 0. + +#### Spurious sched_migrate_task events (same CPU) + +Rarely, a `sched_migrate_task` event occurs in which the source and target CPUs are the same. In other words, the task is not migrated. To avoid artificially inflated migration counts, this case must be explicitly ignored: +``` +class Event_sched_migrate_task (Event): +        def process(self): +[…] +                if self.cpu == self.dest_cpu: +                        return +``` + +#### exec + +The semantics of the `exec` system call are that the image of the current process is replaced by a completely new process image without changing the process ID. This is awkward for tracking the statistics of a process (really, a task) based on the process (task) ID. The change is significant enough that the statistics for each task should be accumulated separately, so the current task's statistics need to be closed out and a new set of statistics should be initialized. The challenge is that both the old and new tasks have the same process (task) ID. `curt` addresses this by tagging the task's task ID with a numeric suffix: +``` +class Event_sched_process_exec (Event): +  def process(self): +    global start_timestamp, curr_timestamp +    curr_timestamp = self.timestamp +    if (start_timestamp == 0): +      start_timestamp = curr_timestamp +  +    task = super(Event_sched_process_exec, self).process() +  +    new_task = Task(self.timestamp, self.command, task.mode, self.pid) +    new_task.sched_stat = True +    new_task.syscall = task.syscall +    new_task.syscalls[task.syscall] = Call() +    new_task.syscalls[task.syscall].timestamp = self.timestamp +  +    task.change_mode(curr_timestamp, 'exit') +  +    suffix=0 +    while True: +      old_tid = str(self.tid)+"-"+str(suffix) +      if old_tid in tasks: +        suffix += 1 +      else: +        break +  +    tasks[old_tid] = tasks[self.tid] +  +    del tasks[self.tid] +  +    tasks[self.tid] = new_task +``` + +This will clearly separate the statistics for the different process images. In the example below, the `perf` command (task "9614-0") `exec`'d `exec.sh` (task "9614-1"), which in turn `exec`'d itself (task "9614"): +``` +-- [  task] command   cpu      user       sys       irq        hv      busy      idle |  util% moves +    [  9614] execs.sh    4  1.328238  0.485604  0.000000  0.000000  0.000000  2.273230 |  44.4% +    [  9614] execs.sh    7  0.000000  0.201266  0.000000  0.000000  0.000000  0.003466 |  98.3% +    [  9614] execs.sh  ALL  1.328238  0.686870  0.000000  0.000000  0.000000  2.276696 |  47.0%     1 + +-- [  task] command   cpu      user       sys       irq        hv      busy      idle |  util% moves +    [9614-0] perf        3  0.000000  0.408588  0.000000  0.000000  0.000000  2.298722 |  15.1% +    [9614-0] perf        4  0.059079  0.028269  0.000000  0.000000  0.000000  0.611355 |  12.5% +    [9614-0] perf        5  0.000000  0.067626  0.000000  0.000000  0.000000  0.004702 |  93.5% +    [9614-0] perf      ALL  0.059079  0.504483  0.000000  0.000000  0.000000  2.914779 |  16.2%     2 +  +-- [  task] command   cpu      user       sys       irq        hv      busy      idle |  util% moves +    [9614-1] execs.sh    3  1.207972  0.987433  0.000000  0.000000  0.000000  2.435908 |  47.4% +    [9614-1] execs.sh    4  0.000000  0.341152  0.000000  0.000000  0.000000  0.004147 |  98.8% +    [9614-1] execs.sh  ALL  1.207972  1.328585  0.000000  0.000000  0.000000  2.440055 |  51.0%     1 +``` + +#### Distribution support + +Surprisingly, there is currently no support for `perf`'s Python bindings in Ubuntu. [Follow the saga][4] for more detail. + +#### Limit on number of traced events + +As `curt` gets more sophisticated, it is likely that more and more events may be required to be included in the trace file. `perf` currently requires one file descriptor per event per CPU. This becomes a problem when the maximum number of open file descriptors is not a large multiple of the number of CPUs on the system. On systems with large numbers of CPUs, this quickly becomes a problem. For example, the default maximum number of open file descriptors is often 1,024. An IBM POWER8 system with four sockets may have 12 cores per socket and eight threads (CPUs) per core. Such a system has 4 * 12 * 8 = 392 CPUs. In that case, `perf` could trace only about two events! A workaround is to (significantly) increase the maximum number of open file descriptors (`ulimit –n` if the system administrator has configured the hard limits high enough; or the administrator can set the limits higher in `/etc/security/limits.conf` for `nofile`). + +### Summary + +I hope this article shows the power of `perf`—and specifically the utility and flexibility of the Python scripting enabled with `perf`—to perform sophisticated processing of kernel trace data. Also, it shows some of the issues and edge cases that can be encountered when the boundaries of such technologies are tested. + +Please feel free to download and make use of the `curt` tool described here, report problems, suggest improvements, or contribute code of your own on the [`curt` GitHub page][5]. + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/7/fun-perf-and-python + +作者:[Paul Clarke][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://opensource.com/users/thinkopenly +[1]:https://2018.texaslinuxfest.org/ +[2]:https://www.ibm.com/support/knowledgecenter/en/ssw_aix_72/com.ibm.aix.cmds1/curt.htm +[3]:https://opensource.com/article/17/9/intro-ebpf +[4]:https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1707875 +[5]:https://github.com/open-power-sdk/curt diff --git a/sources/tech/20180730 50 Best Ubuntu Apps You Should Be Using Right Now.md b/sources/tech/20180730 50 Best Ubuntu Apps You Should Be Using Right Now.md new file mode 100644 index 0000000000..d305b716d6 --- /dev/null +++ b/sources/tech/20180730 50 Best Ubuntu Apps You Should Be Using Right Now.md @@ -0,0 +1,499 @@ +50 Best Ubuntu Apps You Should Be Using Right Now +====== +**Brief: A comprehensive list of best Ubuntu apps for all kind of users. These software will help you in getting a better experience with your Linux desktop.** + +I have written about [things to do after installing Ubuntu][1] several times in the past. Each time I suggest installing the essential applications in Ubuntu. + +But the question arises, what are the essential Ubuntu applications? There is no set answer here. It depends on your need and the kind of work you do on your Ubuntu desktop. + +Still, I have been asked to suggest some good Ubuntu apps by a number of readers. This is the reason I have created this comprehensive list of Ubuntu applications you can use regularly. + +The list has been divided into respective categories for ease of reading and ease of comprehension. + +### Best Ubuntu apps for a better Ubuntu experience + +![Best Ubuntu Apps][2] + +Of course, you don’t have to use all of these applications. Just go through this list of essential Ubuntu software, read the description and then install the ones you need or are inclined to use. Just keep this page bookmarked for future reference or simply search on Google with term ‘best ubuntu apps itsfoss’. + +The best Ubuntu application list is intended for average Ubuntu user. Therefore not all the applications here are open source. I have also marked the slightly complicated applications that might not be suitable for a beginner. The list should be valid for Ubuntu 16.04,18.04 and other versions. + +Unless exclusively mentioned, the software listed here are available in Ubuntu Software Center. + +If you don’t find any application in the software center or if it is missing installation instruction, let me know and I’ll add the installation procedure. + +Enough talk! Let’s see what are the best apps for Ubuntu. + +#### Web Browser + +Ubuntu comes with Firefox as the default web browser. Since the Quantum release, Firefox has improved drastically. Personally, I always use more than one web browser for the sake of distinguishing between different type of works. + +##### Google Chrome + +![Google Chrome Logo][3] + +Google Chrome is the most used web browser on the internet for a reason. With your Google account, it allows you seamless syncing across devices. Plenty of extensions and apps further enhance its capabilities. You can [download Chrome in Ubuntu from its website][4]. + +##### Brave + +![brave browser][5] + +Google Chrome might be the most used web browser but it’s a privacy invader. An [alternative browser][6] is [Brave][7] that blocks ads and tracking scripts by default. This provides you with a faster and secure web browsing experience. + +#### Music applications + +![best music apps ubuntu][8] + +Ubuntu has Rhythmbox as the default music player which is not at all a bad choice for the default music player. However, you can definitely install a better music player. + +##### Sayonara + +[Sayonara][9] is a small, lightweight music player with a nice dark user interface. It comes with all the essential features you would expect in a standard music player. It integrates well with the Ubuntu desktop environment and doesn’t eat up your RAM. + +##### Audacity + +[Audacity][10] is more of an audio editor than an audio player. You can record and edit audio with this free and open source tool. It is available for Linux, Windows and macOS. You can install it from the Software Center. + +##### MusicBrainz Picard + +[Picard][11] is not a music player, it is a music tagger. If you have tons of local music files, Picard allows you to automatically update the music files with correct tracks, album, artist info and album cover art. + +#### Streaming Music Applications + +![Streaming Music app Ubuntu][12] + +In this age of the internet, music listening habit has surely changed. People these days rely more on streaming music players rather than storing hundreds of local music files. Let’s see some apps you can use for streaming music. + +##### Spotify + +[Spotify][13] is the king of streaming music. And the good thing is that it has a native Linux app. The [Spotify app on Ubuntu][14] integrates well with the media key and sound menu along with the desktop notification. Do note that Spotify may or may not be available in your country. + +##### Nuvola music player + +[Nuvola][15] is not a streaming music service like Spotify. It is a desktop music player that allows you to use several streaming music services in one application. You can use Spotify, Deezer, Google Play Music, Amazon Cloud Player and many more such services. + +#### Video Players + +![Video players for Linux][16] + +Ubuntu has the default GNOME video player (previously known as Totem) which is okay but it doesn’t support various media codecs. There are certainly other video players better than the GNOME video player. + +##### VLC + +The free and open source software [VLC][17] is the king of video players. It supports almost all possible media codecs. It also allows you to increase the volume up to 200%. It can also resume playing from the last known position. There are so many [VLC tricks][18] you can use to get the most of it. + +##### MPV + +[MPV][19] is a video player that deserves more attention. A sleek minimalist GUI and plenty of features, MPV has everything you would expect from a good video player. You can even use it in the command line. If you are not happy with VLC, you should surely give MPV a try. + +#### Cloud Storage Service + +Local backups are fine but cloud storage gives an additional degree of freedom. You don’t have to carry a USB key with you all the time or worry about a hard disk crash with cloud services. + +##### Dropbox + +![Dropbox logo][20] + +[Dropbox][21] is one of the most popular Cloud service providers. You get 2GB of free storage with the option to get more by referring others. Dropbox provides a native Linux client and you can download it from its website. It creates a local folder on your system that is synced with the cloud servers. + +##### pCloud + +![pCloud icon][22] + +[pCloud][23] is another good cloud storage service for Linux. It also has a native Linux client that you can download from its website. You get up to 20GB of free storage and if you need more, the pricing is better than Dropbox. pCloud is based in Switzerland, a country renowned for strict data privacy laws. + +#### Image Editors + +I am sure that you would need a photo editor at some point in time. Here are some of the best Ubuntu apps for editing images. + +##### GIMP + +![gimp icon][24] + +[GIMP][25] is a free and open source image editor available for Linux, Windows and macOS. It’s the best alternative for Adobe Photoshop in Linux. You can use it for all kind of image editing. There are plenty of resources available on the internet to help you with Gimp. + +##### Inkscape + +![inkscape icon][26] + +[Inkscape][27] is also a free and open source image editor specifically focusing on vector graphics. You can design vector arts and logo on it. You can compare it to Adobe Illustrator. Like Gimp, Inkscape too has plenty of tutorials available online. + +#### Paint applications + +Painting applications are not the same as image editors though their functionalities overlap at times. Here are some paint apps you can use in Ubuntu. +![Painting apps for Ubuntu Linux][28] + +##### Krita + +[Krita][29] is a free and open source digital painting application. You can create digital art, comics and animation with it. It’s a professional grade software and is even used as the primary software in art schools. + +##### Pinta + +[Pinta][30] might not be as feature rich as Krita but that’s deliberate. You can think of Pinta as Microsoft Paint for Linux. You can draw, paint, add text and do other such small tasks you do in a paint application. + +#### Photography applications + +Amateur photographer or a professional? You have plenty of [photography tools][31] at your disposal. Here are some recommended applications. + +##### digiKam + +![digikam][32] + +With open source software [digiKam][33], you can handle your high-end camera images in a professional manner. digiKam provides all the tools required for viewing, managing, editing, enhancing, organizing, tagging and sharing photographs. + +##### Darktable + +![Darktable icon][34] + +[darktable][35] is an open source photography workflow application with a special focus on raw image development. This is the best alternative you can get for Adobe Lightroom. It is also available for Windows and macOS. + +#### Video editors + +![Video editors Ubuntu][36] + +There is no dearth of [video editors for Linux][37] but I won’t go in detail here. Take a look at some of the feature-rich yet relatively simple to use video editors for Ubuntu. + +##### Kdenlive + +[Kdenlive][38] is the best all-purpose video editor for Linux. It has enough features that compare it to iMovie or Movie Maker. + +##### Shotcut + +[Shotcut][39] is another good choice for a video editor. It is an open source software with all the features you can expect in a standard video editor. + +#### Image and video converter + +If you need to [convert the file format][40] of your images and videos, here are some of my recommendations. + +##### Xnconvert + +![xnconvert logo][41] + +[Xnconvert][42] is an excellent batch image conversion tool. You can bulk resize images, convert the file type and rename them. + +##### Handbrake + +![Handbrake Logo][43] + +[HandBrake][44] is an easy to use open source tool for converting videos from a number of formats to a few modern, popular formats. + +#### Screenshot and screen recording tools + +![Screenshot and recorders Ubuntu][45] + +Here are the best Ubuntu apps for taking screenshots and recording your screen. + +##### Shutter + +[Shutter][46] is my go-to tool for taking screenshots. You can also do some quick editing to those screenshots such as adding arrows, text or resizing the images. The screenshots you see on It’s FOSS have been edited with Shutter. Definitely one of the best apps for Ubuntu. + +##### Kazam + +[Kazam][47] is my favorite [screen recorder for Linux][48]. It’s a tiny tool that allows you to record the entire window, an application window or a selected area. You can also use shortcuts to pause or resume recording. The tutorials on [It’s FOSS YouTube channel][49] have been recorded with Kazam. + +#### Office suites + +I cannot imagine that you could use a computer without a document editor. And why restrict yourself to just one document editor? Go for a complete office suite. + +##### LibreOffice + +![LibreOffice logo][50] + +[LibreOffice][51] comes preinstalled on Ubuntu and it is undoubtedly the [best open source office software][52]. It’s a complete package comprising of a document editor, spreadsheet tool, presentation software, maths tool and a graphics tool. You can even edit some PDF files with LibreOffice. + +##### WPS Office + +![WPS Office logo][53] + +[WPS Office][54] has gained popularity for being a Microsoft Office clone. It has an interface identical to Microsoft Office and it claims to be more compatible with MS Office. If you are looking for something similar to the Microsoft Office, WPS Office is a good choice. + +#### Downloading tools + +![Downloading software Ubuntu][55] + +If you often download videos or other big files from the internet, these tools will help you. + +##### youtube-dl + +This is one of the rare Ubuntu application on the list that is command line based. If you want to download videos from YouTube, DailyMotion or other video websites, youtube-dl is an excellent choice. It provides plenty of [advanced option for video downloading][56]. + +##### uGet + +[uGet][57] is a feature rich [download manager for Linux][58]. It allows you to pause and resume your downloads, schedule your downloads, monitor clipboard for downloadable content. A perfect tool if you have a slow, inconsistent internet or daily data limit. + +#### Code Editors + +![Coding apps for Ubuntu][59] + +If you are into programming, the default Gedit text editor might not be sufficient for your coding needs. Here are some of the better code editors for you. + +##### Atom + +[Atom][60] is a free and [open source code editor][61] from GitHub. Even before it was launched its first stable version, it became a hot favorite among coders for its UI, features and vast range of plugins. + +##### Visual Studio Code + +[VS Code][62] is an open source code editor from Microsoft. Don’t worry about Microsoft, VS Code is an awesome editor for web development. It also supports a number of other programming languages. + +#### PDF and eBooks related applications + +![eBook Management tools in Ubuntu][63] + +In this digital age, you cannot only rely on the real paper books especially when there are plenty of free eBooks available. Here are some Ubuntu apps for managing PDFs and eBooks. + +##### Calibre + +If you are a bibliophile and collect eBooks, you should use [Calibre][64]. It is an eBook manager with all the necessary software for [creating eBooks][65], converting eBook formats and managing an eBook library. + +##### Okular + +Okular is mostly a PDF viewer with options for editing PDF files. You can do some basic [PDF editing on Linux][66] with Okular such as adding pop-ups notes, inline notes, freehand line drawing, highlighter, stamp etc. + +#### Messaging applications + +![Messaging apps for Ubuntu][67] + +I believe you use at least one [messaging app on Linux][68]. Here are my recommendations. + +##### Skype + +[Skype][69] is the most popular video chatting application. It is also used by many companies and businesses for interviews and meetings. This makes Skype one of the must-have applications for Ubuntu. + +##### Rambox + +[Rambox][70] is not a messaging application on its own. But it allows you to use Skype, Viber, Facebook Messanger, WhatsApp, Slack and a number of other messaging applications from a single application window. + +#### Notes and To-do List applications + +Need a to-do list app or simple an app for taking notes? Have a look at these: + +##### Simplenote + +![Simplenote logo][71] + +[Simplenote][72] is a free and open source note taking application from WordPress creators [Automattic][73]. It is available for Windows, Linux, macOS, iOS and Android. Your notes are synced to a cloud server and you can access them on any device. You can download the DEB file from its website. + +##### Remember The Milk + +![Remember The Milk logo][74] + +[Remember The Milk][75] is a popular to-do list application. It is available for Windows, Linux, macOS, iOS and Android. Your to-do list is accessible on all the devices you own. You can also access it from a web browser. It also has an official native application for Linux that you can download from its website. + +#### Password protection and encryption + +![Encryption software Ubuntu][76] + +If there are other people regularly using your computer perhaps you would like to add an extra layer of security by password protecting files and folders. + +##### EncryptPad + +[EncryptPad][77] is an open source text editor that allows you to lock your files with a password. You can choose the type of encryption. There is also a command line version of this tool. + +##### Gnome Encfs Manager + +Gnome Encfs Manager allows you to [lock folders with a password in Linux][78]. You can keep whatever files you want in a secret folder and then lock it with a password. + +#### Gaming + +![Gaming on Ubuntu][79] + +[Gaming on Linux][80] is a lot better than what it used to be a few years ago. You can enjoy plenty of games on Linux without going back to Windows. + +##### Steam + +[Steam][81] is a digital distribution platform that allows you to purchase (if required) games. Steam has over 1500 [games for Linux][82]. You can download the Steam client from the Software Center. + +##### PlayOnLinux + +[PlayOnLinux][83] allows you to run Windows games on Linux over WINE compatibility layer. Don’t expect too much out of it because not every game will run flawlessly with PlayOnLinux. + +#### Package Managers [Intermediate to advanced users] + +![Package Management tools Ubuntu][84] + +Ubuntu Software Center is more than enough for an average Ubuntu user’s software needs but you can have more control on it using these applications. + +##### Gdebi + +Gedbi is a tiny packagae manager that you can use for installing DEB files. It is faster than the Software Center and it also handles dependency issues. + +##### Synaptic + +Synaptic was the default GUI package manager for most Linux distributions a decade ago. It still is in some Linux distributions. This powerful package manager is particularly helpful in [finding installed applications and removing them][85]. + +#### Backup and Recovery tools + +![Backup and data recovery tools for Ubuntu][86] + +Backup and recovery tools are must-have software for any system. Let’s see what softwares you must have on Ubuntu. + +##### Timeshift + +Timeshift is a tool that allows you to [take a snapshot of your system][87]. This allows you to restore your system to a previous state in case of an unfortunate incident when your system configuration is messed up. Note that it’s not the best tool for your personal data backup though. For that, you can use Ubuntu’s default Deja Dup (also known as Backups) tool. + +##### TestDisk [Intermediate Users] + +This is another command line tool on this list of best Ubuntu application. [TestDisk][88] allows you to [recover data on Linux][89]. If you accidentally deleted files, there are still chances that you can get it back using TestDisk. + +#### System Tweaking and Management Tools + +![System Maintenance apps Ubuntu][90] + +##### GNOME/Unity Tweak Tool + +These Tweak tools are a must for every Ubuntu user. They allow you to access some advanced system settings. Best of all, you can [change themes in Ubuntu][91] using these tweak tools. + +##### UFW Firewall + +[UFW][92] stands for Uncomplicated Firewall and rightly so. UFW has predefined firewall settings for Home, Work and Public networks. + +##### Stacer + +If you want to free up space on Ubuntu, try Stacer. This graphical tool allows you to [optimize your Ubuntu system][93] by removing unnecessary files and completely uninstalling software. Download Stacer from [its website][94]. + +#### Other Utilities + +![Utilities Ubuntu][95] + +In the end, I’ll list some of my other favorite Ubuntu apps that I could not put into a certain category. + +##### Neofetch + +One more command line tool! Neofetch displays your system information such as [Ubuntu version][96], desktop environment, theme, icons, RAM etc info along with [ASCII logo of the distribution][97]. Use this command for installing Neofetch. +``` +sudo apt install neofetch + +``` + +##### Etcher + +Ubuntu has a live USB creator tool installed already but Etcher is a better application for this task. It is also available for Windows and macOS. You can download it [from its website][98]. + +##### gscan2pdf + +I use this tiny tool for the sole purpose of [converting images into PDF][99]. You can use it for combining multiple images into one PDF file as well. + +##### Audio Recorder + +Another tiny yet essential Ubuntu application for [recording audio on Ubuntu][100]. You can use it to record sound from system microphone, from music player or from any other source. + +### Your suggestions for essential Ubuntu applications? + +I would like to conclude my list of best Ubuntu apps here. I know that you might not need or use all of them but I am certain that you would like most of the software listed here. + +Did you find some useful applications that you didn’t know about before? If you would have to suggest your favorite Ubuntu application, which one would it be? + +In the end, if you find this article useful, please share it on social media, Reddit, Hacker News or other community or forums you visit regularly. This way you help us grow :) + +-------------------------------------------------------------------------------- + +via: https://itsfoss.com/best-ubuntu-apps/ + +作者:[Abhishek Prakash][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://itsfoss.com/author/abhishek/ +[1]:https://itsfoss.com/things-to-do-after-installing-ubuntu-18-04/ +[2]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/07/best-ubuntu-apps-featured.jpeg +[3]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/07/google-chrome.jpeg +[4]:https://www.google.com/chrome/ +[5]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/07/brave-browser-icon.jpeg +[6]:https://itsfoss.com/open-source-browsers-linux/ +[7]:https://brave.com/ +[8]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/07/music-apps-ubuntu.jpeg +[9]:https://itsfoss.com/sayonara-music-player/ +[10]:https://www.audacityteam.org/ +[11]:https://itsfoss.com/musicbrainz-picard/ +[12]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/07/streaming-music-apps-ubuntu.jpeg +[13]:https://www.spotify.com// +[14]:https://itsfoss.com/install-spotify-ubuntu-1404/ +[15]:https://tiliado.eu/nuvolaplayer/ +[16]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/07/Video-Players-linux.jpg +[17]:https://www.videolan.org/index.html +[18]:https://itsfoss.com/vlc-pro-tricks-linux/ +[19]:https://mpv.io/ +[20]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/07/dropbox-icon.jpeg +[21]:https://www.dropbox.com/ +[22]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/07/pcloud-icon.jpeg +[23]:https://itsfoss.com/recommends/pcloud/ +[24]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/07/gimp-icon.jpeg +[25]:https://www.gimp.org/ +[26]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/07/inkscape-icon.jpeg +[27]:https://inkscape.org/en/ +[28]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/07/paint-apps-ubuntu.jpeg +[29]:https://krita.org/en/ +[30]:https://pinta-project.com/pintaproject/pinta/ +[31]:https://itsfoss.com/image-applications-ubuntu-linux/ +[32]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/07/digikam-icon.jpeg +[33]:https://www.digikam.org/ +[34]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/07/darktable-icon.jpeg +[35]:https://www.darktable.org/ +[36]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/07/video-editing-apps-ubuntu.jpeg +[37]:https://itsfoss.com/best-video-editing-software-linux/ +[38]:https://kdenlive.org/en/ +[39]:https://shotcut.org/ +[40]:https://itsfoss.com/format-factory-alternative-linux/ +[41]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/07/xnconvert-logo.jpeg +[42]:https://www.xnview.com/en/xnconvert/ +[43]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/07/handbrake-logo.jpeg +[44]:https://handbrake.fr/ +[45]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/07/screen-recording-ubuntu-apps.jpeg +[46]:http://shutter-project.org/ +[47]:https://launchpad.net/kazam +[48]:https://itsfoss.com/best-linux-screen-recorders/ +[49]:https://www.youtube.com/c/itsfoss?sub_confirmation=1 +[50]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/07/libre-office-logo.jpeg +[51]:https://www.libreoffice.org/download/download/ +[52]:https://itsfoss.com/best-free-open-source-alternatives-microsoft-office/ +[53]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/07/wps-office-logo.jpeg +[54]:http://wps-community.org/ +[55]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/07/download-apps-ubuntu.jpeg +[56]:https://itsfoss.com/download-youtube-linux/ +[57]:http://ugetdm.com/ +[58]:https://itsfoss.com/4-best-download-managers-for-linux/ +[59]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/07/coding-apps-ubuntu.jpeg +[60]:https://atom.io/ +[61]:https://itsfoss.com/best-modern-open-source-code-editors-for-linux/ +[62]:https://itsfoss.com/install-visual-studio-code-ubuntu/ +[63]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/07/pdf-management-apps-ubuntu.jpeg +[64]:https://calibre-ebook.com/ +[65]:https://itsfoss.com/create-ebook-calibre-linux/ +[66]:https://itsfoss.com/pdf-editors-linux/ +[67]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/07/messaging-apps-ubuntu.jpeg +[68]:https://itsfoss.com/best-messaging-apps-linux/ +[69]:https://www.skype.com/en/ +[70]:https://rambox.pro/ +[71]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/07/simplenote-logo.jpeg +[72]:http://simplenote.com/ +[73]:https://automattic.com/ +[74]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/07/remember-the-milk-logo.jpeg +[75]:https://itsfoss.com/remember-the-milk-linux/ +[76]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/07/encryption-apps-ubuntu.jpeg +[77]:https://itsfoss.com/encryptpad-encrypted-text-editor-linux/ +[78]:https://itsfoss.com/password-protect-folder-linux/ +[79]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/07/gaming-ubuntu.jpeg +[80]:https://itsfoss.com/linux-gaming-guide/ +[81]:https://store.steampowered.com/ +[82]:https://itsfoss.com/free-linux-games/ +[83]:https://www.playonlinux.com/en/ +[84]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/07/package-management-apps-ubuntu.jpeg +[85]:https://itsfoss.com/how-to-add-remove-programs-in-ubuntu/ +[86]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/07/backup-recovery-tools-ubuntu.jpeg +[87]:https://itsfoss.com/backup-restore-linux-timeshift/ +[88]:https://www.cgsecurity.org/wiki/TestDisk +[89]:https://itsfoss.com/recover-deleted-files-linux/ +[90]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/07/system-maintenance-apps-ubuntu.jpeg +[91]:https://itsfoss.com/install-themes-ubuntu/ +[92]:https://wiki.ubuntu.com/UncomplicatedFirewall +[93]:https://itsfoss.com/optimize-ubuntu-stacer/ +[94]:https://github.com/oguzhaninan/Stacer +[95]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/07/utilities-apps-ubuntu.jpeg +[96]:https://itsfoss.com/how-to-know-ubuntu-unity-version/ +[97]:https://itsfoss.com/display-linux-logo-in-ascii/ +[98]:https://etcher.io/ +[99]:https://itsfoss.com/convert-multiple-images-pdf-ubuntu-1304/ +[100]:https://itsfoss.com/record-streaming-audio/ diff --git a/sources/tech/20180730 A single-user, lightweight OS for your next home project - Opensource.com.md b/sources/tech/20180730 A single-user, lightweight OS for your next home project - Opensource.com.md new file mode 100644 index 0000000000..a4dbfb9e12 --- /dev/null +++ b/sources/tech/20180730 A single-user, lightweight OS for your next home project - Opensource.com.md @@ -0,0 +1,65 @@ +A single-user, lightweight OS for your next home project | Opensource.com +====== +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/robot_arm_artificial_ai.png?itok=8CUU3U_7) + +What on earth is RISC OS? Well, it's not a new kind of Linux. And it's not someone's take on Windows. In fact, released in 1987, it's older than either of these. But you wouldn't necessarily realize it by looking at it. + +The point-and-click graphic user interface features a pinboard and an icon bar across the bottom for your active applications. So, it looks eerily like Windows 95, eight years before it happened. + +This OS was originally written for the [Acorn Archimedes][1] . The Acorn RISC Machines CPU in this computer was completely new hardware that needed completely new software to run on it. This was the original operating system for the ARM chip, long before anyone had thought of Android or [Armbian][2] + +And while the Acorn desktop eventually faded to obscurity, the ARM chip went on to conquer the world. And here, RISC OS has always had a niche—often in embedded devices, where you'd never actually know it was there. RISC OS was, for a long time, a completely proprietary operating system. But in recent years, the owners have started releasing the source code to a project called [RISC OS Open][3]. + +### 1\. You can install it on your Raspberry Pi + +The Raspberry Pi's official operating system, [Raspbian][4], is actually pretty great (but if you aren't interested in tinkering with novel and different things in tech, you probably wouldn't be fiddling with a Raspberry Pi in the first place). Because RISC OS is written specifically for ARM, it can run on all kinds of small-board computers, including every model of Raspberry Pi. + +### 2\. It's super lightweight + +The RISC OS installation on my Raspberry Pi takes up a few hundred megabytes—and that's after I've loaded dozens of utilities and games. Most of these are well under a megabyte. + +If you're really on a diet, the RISC OS Pico will fit on a 16MB SD card. This is perfect if you're hacking something to go in an embedded system or IoT project. Of course, 16MB is actually a fair bit more than the 512KB ROM chip squeezed into the old Archimedes. But I guess with 30 years of progress in memory technology, it's okay to stretch your legs just a little a bit. + +### 3\. It's excellent for retro gaming + +When the Archimedes was in its prime, the ARM CPU was several times faster than the Motorola 68000 in the Apple Macintosh and Commodore Amiga, and it totally smoked that new 386, too. This made it an attractive platform for game developers who wanted to strut their stuff with the most powerful desktop computer on the planet. + +Many of the rights holders to these games have been generous enough to give permission for hobbyists to download their old work for free. And while RISC OS and the hardware has moved on, with a very small amount of fiddling you can get them to run. + +If you're interested in exploring this, [here's a guide][5] to getting these games working on your Raspberry Pi. + +### 4\. It's got BBC BASIC + +Press F12 to go to the command line, type `*BASIC`, and you get a full BBC BASIC interpreter, just like the old days. + +For those who weren't around for it in the 80s, let me explain: BBC BASIC was the first ever programming language for so many of us back in the day, for the excellent reason that it was specifically designed to teach children how to code. There were mountains of books and magazine articles that taught us to code our own simple but highly playable games. + +Decades later, coding your own game in BBC BASIC is still a great project for a technically minded kid who wants something to do during school holidays. But few kids have a BBC micro at home anymore. So what should they run it on? + +Well, there are interpreters you can run on just about every home computer, but that's not helpful when someone else needs to use it. So why not a Raspberry Pi with RISC OS installed? + +### 5\. It's a simple, single-user operating system + +RISC OS is not like Linux, with its user and superuser access. It has one user who has full access to the whole machine. So it's probably not the best daily driver to deploy across an enterprise, or even to give to granddad to do his banking. But if you're looking for something to hack and tinker with, it's absolutely fantastic. There isn't all that much between you and the bare metal, so you can just tuck right in. + +### Further reading + +If you want to learn more about this operating system, check out [RISC OS Open][3], or just flash an image to a card and start using it. + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/7/gentle-intro-risc-os + +作者:[James Mawson][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://opensource.com/users/dxmjames +[1]:https://en.wikipedia.org/wiki/Acorn_Archimedes +[2]:https://www.armbian.com/ +[3]:https://www.riscosopen.org/content/ +[4]:https://www.raspbian.org/ +[5]:https://www.riscosopen.org/wiki/documentation/show/Introduction%20to%20RISC%20OS diff --git a/sources/tech/20180731 What-s in a container image- Meeting the legal challenges.md b/sources/tech/20180731 What-s in a container image- Meeting the legal challenges.md new file mode 100644 index 0000000000..dafb058a42 --- /dev/null +++ b/sources/tech/20180731 What-s in a container image- Meeting the legal challenges.md @@ -0,0 +1,64 @@ +What's in a container image: Meeting the legal challenges +====== +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/freesoftwareway_law3.png?itok=wyze_0fV) + +[Container][1] technology has, for many years, been transforming how workloads in data centers are managed and speeding the cycle of application development and deployment. + +In addition, container images are increasingly used as a distribution format, with container registries a mechanism for software distribution. Isn't this just like packages distributed using package management tools? Not quite. While container image distribution is similar to RPMs, DEBs, and other package management systems (for example, storing and distributing archives of files), the implications of container image distribution are more complicated. It is not the fault of container technology itself; rather, it's because container distribution is used differently than package management systems. + +Talking about the challenges of license compliance for container images, [Dirk Hohndel][2], chief open source officer at VMware, pointed out that the content of a container image is more complex than most people expect, and many readily available images have been built in surprisingly cavalier ways. (See the [LWN.net article][3] by Jake Edge about a talk Dirk gave in April.) + +Why is it hard to understand the licensing of container images? Shouldn't there just be a label for the image ("the license is X")? In the [Open Container Image Format Specification][4] , one of the pre-defined annotation keys is "org.opencontainers.image.licenses," which is described as "License(s) under which contained software is distributed as an SPDX License Expression." But that doesn't contemplate the complexity of a container image–while very simple images are built from tens of components, images are often built from hundreds of components. An [SPDX License Expression][5] is most frequently used to convey the licensing for a single source file. Such expressions can handle more than one license, such as "GPL-2.0 OR BSD-3-Clause" (see, for example, [Appendix IV][6] of version 2.1 of the SPDX specification). But the licensing for a typical container image is, typically, much more complicated. + +In talking about container-related technology, the term "[container][7]" can lead to confusion. A container does not refer to the containment of files for storing or transferring. Rather, it refers to using features built into the kernel (such as cgroups and namespaces) to present a sort of "contained" experience to code running on the kernel. In other words, the containment to which "container" refers is an execution experience, not a distribution experience. The set of files to be laid out in a file system as the basis for an executing container is typically distributed in what is known as a "container image," sometimes confusingly referred to simply as a container, thereby awkwardly overloading the term "container." + +In understanding software distribution via container images, I believe it is useful to consider two separate factors: + + * **Diversity of content:** The basic unit of software distribution (a container image) includes a larger quantity and diversity of content than in the basic unit of distribution in typical software distribution mechanisms. + * **Use model:** The nature of widely used tooling fosters the use of a registry, which is often publicly available, in the typical workflow. + + + +### Diversity of content + +When talking about a particular container image, the focus of attention is often on a particular software component (for example, a database or the code that implements one specific service). However, the container image includes a much larger collection of software. In fact, even the developer who created the image may have only a superficial understanding of and/or interest in most of the components in the image. With other distribution mechanisms, those other pieces of software would be identified as dependencies, and users of the software might be directed elsewhere for expertise on those components. In a container, the individual who acquires the container image isn't aware of those additional components that play supporting roles to the featured component. + +#### The unit of distribution: user-driven vs. factory-driven + +For container images, the distribution unit is user-driven, not factory-driven. Container images are a great tool for reducing the burden on software consumers. With a container image, the image's consumer can focus on the application of interest; the image's builder can take care of the dependencies and configuration. This simplification can be a huge benefit. + +When the unit of software is driven by the "factory," the user bears a greater responsibility for building a platform on which to run the software of interest, assembling the correct versions of the dependencies, and getting all the configuration details right. The unit of distribution in a package management system is a modular unit, rather than a complete solution. This unit facilitates building and maintaining a flow of components that are flexible enough to be assembled into myriad solutions. Note that because of this unit, a package maintainer will typically be far more familiar with the content of the packages than someone who builds containers. A person building a container may have a detailed understanding of the container's featured components, but limited familiarity with the image's supporting components. + +Packages, package management system tools, package maintenance processes, and package maintainers are incredibly underappreciated. They have been central to delivery of a large variety of software over the last two decades. While container images are playing a growing role, I don't expect the importance of package management systems to fade anytime soon. In fact, the bulk of the content in container images benefits from being built from such packages. + +In understanding container images, it is important to appreciate how distribution via such images has different properties than distribution of packages. Much of the content in images is built from packages, but the image's consumer may not know what packages are included or other package-level information. In the future, a variety of techniques may be used to build containers, e.g., directly from source without involvement of a package maintainer. + +### Use models + +What about reports that so many container images are poorly built? In part, the volume of casually built images is because of container tools that facilitate a workflow to make images publicly available. When experimenting with container tools and moving to a workflow that extends beyond a laptop, the tools expect you to have a repository where multiple machines can pull container images (a container registry). You could spin up your own. Some widely used tools make it easy to use an existing registry that is available at no cost, provided the images are publicly available. This makes many casually built images visible, even those that were never intended to be maintained or updated. + +By comparison, how often do you see developers publishing RPMs of their early explorations? RPMs resulting from experimentation by random developers are not ending up in the major package repositories. + +Or consider someone experimenting with the latest machine learning frameworks. In the past, a researcher might have shared only analysis results. Now, they can share a full analytical software configuration by publishing a container image. This could be a great benefit to other researchers. However, those browsing a container registry could be confused by the ready-to-run nature of such images. It is important to distinguish between an image built for one individual's exploration and an image that was assembled and tested with broad use in mind. + +Be aware that container images include supporting software, not just the featured software; a container image distributes a collection of software. If you are building upon or otherwise using images built by others, be aware of how that image was built and consider your level of confidence in the image's source. + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/7/whats-container-image-meeting-legal-challenges + +作者:[Scott Peterson][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://opensource.com/users/skpeterson +[1]:https://opensource.com/resources/what-are-linux-containers +[2]:https://www.linkedin.com/in/dirkhohndel +[3]:https://lwn.net/Articles/752982/ +[4]:https://github.com/opencontainers/image-spec/blob/master/spec.md +[5]:https://spdx.org/ +[6]:https://spdx.org/spdx-specification-21-web-version#h.jxpfx0ykyb60 +[7]:https://opensource.com/bus/16/8/introduction-linux-containers-and-image-signing diff --git a/sources/tech/20180801 5 of the Best Linux Games to Play in 2018.md b/sources/tech/20180801 5 of the Best Linux Games to Play in 2018.md new file mode 100644 index 0000000000..a0580434ec --- /dev/null +++ b/sources/tech/20180801 5 of the Best Linux Games to Play in 2018.md @@ -0,0 +1,83 @@ +5 of the Best Linux Games to Play in 2018 +====== + +![](https://www.maketecheasier.com/assets/uploads/2018/07/best-linux-games-2018-header.jpg) + +Linux may not be establishing itself as the gamer’s platform of choice any time soon – the lack of success with Valve’s Steam Machines seems a poignant reminder of that – but that doesn’t mean that the platform isn’t steadily growing with its fair share of great games. + +From indie hits to glorious RPGs, 2018 has already been a solid year for Linux games. Here we’ve listed our five favourites so far. + +Looking for great Linux games but don’t want to splash the cash? Look to our list of the best [free Linux games][1] for guidance! + +### 1. Pillars of Eternity II: Deadfire + +![best-linux-games-2018-pillars-of-eternity-2-deadfire][2] + +One of the titles that best represents the cRPG revival of recent years makes your typical Bethesda RPG look like a facile action-adventure. The latest entry in the majestic Pillars of Eternity series has a more buccaneering slant as you sail with a crew around islands filled with adventures and peril. + +Adding naval combat to the mix, Deadfire continues with the rich storytelling and excellent writing of its predecessor while building on those beautiful graphics and hand-painted backgrounds of the original game. + +This is a deep and unquestionably hardcore RPG that may cause some to bounce off it, but those who take to it will be absorbed in its world for months. + +### 2. Slay the Spire + +![best-linux-games-2018-slay-the-spire][3] + +Still in early access, but already one of the best games of the year, Slay the Spire is a deck-building card game that’s embellished by a vibrant visual style and rogue-like mechanics that’ll leave you coming back for more after each infuriating (but probably deserved) death. + +With endless card combinations and a different layout each time you play, Slay the Spire feels like the realisation of all the best systems that have been rocking the indie scene in recent years – card games and a permadeath adventure rolled into one. + +And we repeat that it’s still in early access, so it’s only going to get better! + +### 3. Battletech + +![best-linux-games-2018-battletech][4] + +As close as we get on this list to a “blockbuster” game, Battletech is an intergalactic wargame (based on a tabletop game) where you load up a team of Mechs and guide them through a campaign of rich, turn-based battles. + +The action takes place across a range of terrain – from frigid wastelands to golden sun-soaked climes – as you load your squad of four with hulking hot weaponry, taking on rival squads. If this sounds a little “MechWarrior” to you, then you’re thinking along the right track, albeit this one’s more focused on the tactics than outright action. + +Alongside a campaign that sees you navigate your way through a cosmic conflict, the multiplayer mode is also likely to consume untold hours of your life. + +### 4. Dead Cells + +![best-linux-games-2018-dead-cells][5] + +This one deserves highlighting as the combat-platformer of the year. With its rogue-lite structure, Dead Cells throws you into a dark (yet gorgeously coloured) world where you slash and dodge your way through procedurally-generated levels. It’s a bit like a 2D Dark Souls, if Dark Souls were saturated in vibrant neon colours. + +Dead Cells can be merciless, but its precise and responsive controls ensure that you only ever have yourself to blame for failure, and its upgrades system that carries over between runs ensures that you always have some sense of progress. + +Dead Cells is a zenith of pixel-game graphics, animations and mechanics, a timely reminder of just how much can be achieved without the excesses of 3D graphics. + +### 5. Iconoclasts + +![best-linux-games-2018-iconoclasts][6] + +A little less known than some of the above, this is still a lovely game that could be seen as a less foreboding, more cutesy alternative to Dead Cells. It casts you as Robin, a girl who’s cast out as a fugitive after finding herself at the wrong end of the twisted politics of an alien world. + +It’s a good plot, even though your role in it is mainly blasting your way through the non-linear levels. Robin acquires all kinds of imaginative upgrades, the most crucial of which is her wrench, which you use to do everything from deflecting projectiles to solving the clever little environmental puzzles. + +Iconoclasts is a joyful, vibrant platformer, borrowing from greats like Megaman for its combat and Metroid for its exploration. You can do a lot worse than take inspiration from those two classics. + +### Conclusion + +That’s it for our picks of the best Linux games to have come out in 2018. Have you dug up any gaming gems that we’ve missed? Let us know in the comments! + +-------------------------------------------------------------------------------- + +via: https://www.maketecheasier.com/best-linux-games/ + +作者:[Robert Zak][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://www.maketecheasier.com/author/robzak/ +[1]:https://www.maketecheasier.com/open-source-linux-games/ +[2]:https://www.maketecheasier.com/assets/uploads/2018/07/best-linux-games-2018-pillars-of-eternity-2-deadfire.jpg (best-linux-games-2018-pillars-of-eternity-2-deadfire) +[3]:https://www.maketecheasier.com/assets/uploads/2018/07/best-linux-games-2018-slay-the-spire.jpg (best-linux-games-2018-slay-the-spire) +[4]:https://www.maketecheasier.com/assets/uploads/2018/07/best-linux-games-2018-battletech.jpg (best-linux-games-2018-battletech) +[5]:https://www.maketecheasier.com/assets/uploads/2018/07/best-linux-games-2018-dead-cells.jpg (best-linux-games-2018-dead-cells) +[6]:https://www.maketecheasier.com/assets/uploads/2018/07/best-linux-games-2018-iconoclasts.jpg (best-linux-games-2018-iconoclasts) diff --git a/sources/tech/20180801 Getting started with Standard Notes for encrypted note-taking.md b/sources/tech/20180801 Getting started with Standard Notes for encrypted note-taking.md new file mode 100644 index 0000000000..a2845eef65 --- /dev/null +++ b/sources/tech/20180801 Getting started with Standard Notes for encrypted note-taking.md @@ -0,0 +1,299 @@ +Getting started with Standard Notes for encrypted note-taking +====== + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/features_solutions_command_data.png?itok=4_VQN3RK) + +[Standard Notes][1] is a simple, encrypted notes app that aims to make dealing with your notes the easiest thing you'll do all day. When you sign up for a free sync account, your notes are automatically encrypted and seamlessly synced with all your devices. + +There are two key factors that differentiate Standard Notes from other, commercial software solutions: + + 1. The server and client are both completely open source. + 2. The company is built on sustainable business practices and focuses on product development. + + + +When you combine open source with ethical business practices, you get a software product that has the potential to serve you for decades. You start to feel ownership in the product rather than feeling like just another transaction for an IPO-bound company. + +In this article, I’ll describe how to deploy your own Standard Notes open source syncing server on a Linux machine. You’ll then be able to use your server with our published applications for Linux, Windows, Android, Mac, iOS, and the web. + +If you don’t want to host your own server and are ready to start using Standard Notes right away, you can use our public syncing server. Simply head on over to [Standard Notes][1] to get started. + +### Hosting your own Standard Notes server + +Get the [Standard File Rails app][2] running on your Linux box and expose it via [NGINX][3] or any other web server. + +### Getting started + +These instructions are based on setting up our syncing server on a fresh [CentOS][4]-like installation. You can use a hosting service like [AWS][5] or [DigitalOcean][6] to launch your server, or even run it locally on your own machine. + + 1. Update your system: + +``` + sudo yum update + +``` + + 2. Install [RVM][7] (Ruby Version Manager): + +``` + gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 + \curl -sSL https://get.rvm.io | bash -s stable + +``` + + 3. Begin using RVM in current session: +``` + source /home/ec2-user/.rvm/scripts/rvm + +``` + + 4. Install [Ruby][8]: + +``` + rvm install ruby + +``` + +This should install the latest version of Ruby (2.3 at the time of this writing.) + +Note that at least Ruby 2.2.2 is required for Rails 5. + + 5. Use Ruby: +``` + rvm use ruby + +``` + + 6. Install [Bundler][9]: + +``` + gem install bundler --no-ri --no-rdoc + +``` + + 7. Install [mysql-devel][10]: +``` + sudo yum install mysql-devel + +``` + + 8. Install [MySQL][11] (optional; you can also use a hosted db through [Amazon RDS][12], which is recommended): +``` + sudo yum install mysql56-server + + sudo service mysqld start + + sudo mysql_secure_installation + + sudo chkconfig mysqld on + +``` + +Create a database: + +``` + mysql -u root -p + + > create database standard_file; + + > quit; + +``` + + 9. Install [Passenger][13]: +``` + sudo yum install rubygems + + gem install rubygems-update --no-rdoc --no-ri + + update_rubygems + + gem install passenger --no-rdoc --no-ri + +``` + + 10. Remove system NGINX installation if installed (you’ll use Passenger’s instead): +``` + sudo yum remove nginx + sudo rm -rf /etc/nginx +``` + + 11. Configure Passenger: +``` + sudo chmod o+x "/home/ec2-user" + + sudo yum install libcurl-devel + + rvmsudo passenger-install-nginx-module + + rvmsudo passenger-config validate-install + +``` + + 12. Install Git: +``` + sudo yum install git + +``` + + 13. Set up HTTPS/SSL for your server (free using [Let'sEncrypt][14]; required if using the secure client on [https://app.standardnotes.org][15]): +``` + sudo chown ec2-user /opt + + cd /opt + + git clone https://github.com/letsencrypt/letsencrypt + + cd letsencrypt + +``` + +Run the setup wizard: +``` + ./letsencrypt-auto certonly --standalone --debug + +``` + +Note the location of the certificates, typically `/etc/letsencrypt/live/domain.com/fullchain.pem` + + 14. Configure NGINX: +``` + sudo vim /opt/nginx/conf/nginx.conf + +``` + +Add this to the bottom of the file, inside the last curly brace: +``` + server { + +     listen 443 ssl default_server; + +     ssl_certificate /etc/letsencrypt/live/domain.com/fullchain.pem; + +     ssl_certificate_key /etc/letsencrypt/live/domain.com/privkey.pem; + +     server_name domain.com; + +     passenger_enabled on; + +     passenger_app_env production; + +     root /home/ec2-user/ruby-server/public; + +   } + +``` + + 15. Make sure you are in your home directory and clone the Standard File [ruby-server][2] project: +``` + cd ~ + + git clone https://github.com/standardfile/ruby-server.git + + cd ruby-server + +``` + + 16. Set up project: +``` + bundle install + + bower install + + rails assets:precompile + +``` + + 17. Create a .env file for your environment variables. The Rails app will automatically load these when it starts. + +``` + vim .env + +``` + +Insert: +``` + RAILS_ENV=production + + SECRET_KEY_BASE=use "bundle exec rake secret" + + + + DB_HOST=localhost + + DB_PORT=3306 + + DB_DATABASE=standard_file + + DB_USERNAME=root + + DB_PASSWORD= + +``` + + 18. Setup database: +``` + rails db:migrate + +``` + + 19. Start NGINX: +``` + sudo /opt/nginx/sbin/nginx + +``` + +Tip: you will need to restart NGINX whenever you make changes to your environment variables or the NGINX configuration: +``` + sudo /opt/nginx/sbin/nginx -s reload + +``` + + 20. You’re done! + + + + +### Using your new server + +Now that you have your server running, you can plug it into any of the Standard Notes applications and sign into it. + +**On the Standard Notes web or desktop app:** + +Click Account, then Register. Choose "Advanced Options" and you’ll see a field for Sync Server. Enter your server’s URL here. + +**On the Standard Notes Android or iOS app:** + +Open the Settings window, click "Advanced Options" when signing in or registering, and enter your server URL in the Sync Server field. + +For help or questions with your Standard Notes server, join our [Slack group][16] in the #dev channel, or visit our [help page][17] for frequently asked questions and other topics. + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/8/getting-started-standard-notes + +作者:[Mo Bitar][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://opensource.com/users/mobitar +[1]:https://standardnotes.org/ +[2]:https://github.com/standardfile/ruby-server +[3]:https://www.nginx.com/ +[4]:https://www.centos.org/ +[5]:https://aws.amazon.com/ +[6]:https://www.digitalocean.com/ +[7]:https://rvm.io/ +[8]:https://www.ruby-lang.org/en/ +[9]:https://bundler.io/ +[10]:https://rpmfind.net/linux/rpm2html/search.php?query=mysql-devel +[11]:https://www.mysql.com/ +[12]:https://aws.amazon.com/rds/ +[13]:https://www.phusionpassenger.com/ +[14]:https://letsencrypt.org/ +[15]:https://app.standardnotes.org/ +[16]:https://standardnotes.org/slack +[17]:https://standardnotes.org/help diff --git a/sources/tech/20180801 Hiri is a Linux Email Client Exclusively Created for Microsoft Exchange.md b/sources/tech/20180801 Hiri is a Linux Email Client Exclusively Created for Microsoft Exchange.md new file mode 100644 index 0000000000..dbe5d042f9 --- /dev/null +++ b/sources/tech/20180801 Hiri is a Linux Email Client Exclusively Created for Microsoft Exchange.md @@ -0,0 +1,114 @@ +Hiri is a Linux Email Client Exclusively Created for Microsoft Exchange +====== +Previously, I have written about the email services [Protonmail][1] and [Tutanota][2] on It’s FOSS. And though I liked both of those email providers very much, some of us couldn’t possibly use these email services exclusively. If you are like me and you have an email address provided for you by your work, then you understand what I am talking about. + +Some of us use [Thunderbird][3] for these types of use cases, while others of us use something like [Geary][4] or even [Mailspring][5]. But for those of us who have to deal with [Microsoft Exchange Servers][6], none of these offer seamless solutions on Linux for our work needs. + +This is where [Hiri][7] comes in. We have already featured Hiri on our list of [best email clients for Linux][8], but we thought it was about time for an in-depth review. + +FYI, Hiri is neither free nor open source software. + +### Reviewing Hiri email client on Linux + +![Hiri email client review][9] + +According to their website, Hiri not only supports Microsoft Exchange and Office 365 accounts, it was exclusively “built for the Microsoft email ecosystem.” + +Based in Dublin, Ireland, Hiri has raised $2 million in funding. They have been in the business for almost five years but started supporting Linux only last year. The support for Linux has brought Hiri a considerable amount of success. + +I have been using Hiri for a week as of yesterday, and I have to say, I have been very pleased with my experience…for the most part. + +#### Hiri features + +Some of the main features of Hiri are: + + * Cross-platform application available for Linux, macOS and Windows + * **Supports only Office 365, Outlook and Microsoft Exchange for now** + * Clean and intuitive UI + * Action filters + * Reminders + * [Skills][10]: Plugins to make you more productive with your emails + * Office 365 and Exchange and other Calendar Sync + * Compatible with [Active Directory][11] + * Offline email access + * Secure (it doesn’t send data to any third party server, it’s just an email client) + * Compatible with Microsoft’s archiving tool + + + +#### Taking a look at Hiri Features + +![][12] + +Hiri can either be compiled manually or [installed easily as Snap][13] and comes jam-packed with useful features. But, if you knew me at all, you would know that usually, a robust feature list is not a huge selling point for me. As a self-proclaimed minimalist, I tend to believe the simpler option is often the better option, and the less “fluff” there is surrounding a product, the easier it is to get to the part that really matters. Admittedly, this is not always the case. For example, KDE’s [Plasma][14] desktop is known for its excessive amount of tweaks and features and I am still a huge Plasma fan. But in Hiri’s case, it has what feels like the perfect feature set and in no way feels convoluted or confusing. + +That is partially due to the way that Hiri works. If I had to put it into my own words, I would say that Hiri feels almost modular. It does this by utilizing what Hiri calls the Skill Center. Here you can add or remove functionality in Hiri at the flip of a switch. This includes the ability to add tasks, delegate action items to other people, set reminders, and even enables the user to create better subject lines. None of which are required, but each of which adds something to Hiri that no other email client has done as well. + +Using these features can help you organize your email like never before. The Dashboard feature allows you to monitor your time spent working on emails, the Task List enables you to stay on track, the Action/FYI feature allows you to tag your emails as needed to help you cipher through a messy inbox, and the Zero Inbox feature helps the user keep their inbox count at a minimum once they have sorted through the nonsense. And as someone who is an avid Inbox Zeroer (if that is even a thing), this to me was incredibly useful. + +Hiri also syncs with your associated calendars as you would expect, and it even allows a global search for all of the other accounts associated with your office. Need to email Frank Smith in Human Resources but can’t remember his email address? No big deal! Hiri will auto-fill the email address once you start typing in his name just like in a native Outlook client. + +Multiple account support is also available in Hiri. The support for IMAP will be added in a few months. + +In short, Hiri’s feature-set allows for what feels like a truly native Microsoft offering on Linux. It is clean, simple enough, and allows someone with my productivity workflow to thrive. I really dig what Hiri has to offer, and it’s as simple as that. + +#### Experiencing the Hiri UI + +As far as design goes, Hiri gets a solid A from me. I never felt like I was using something outdated looking like [Evolution][15] (I know people like Evolution a lot, but to say it is clean and modern is a lie), it never felt overly complicated like [KMail][16], and it felt less cramped than Thunderbird. Though I love Thunderbird dearly, the inbox list is just a little too small to feel like I can really cipher through my emails in a decent amount of time. Hiri seemingly fixes this but adds another issue that may be even worse. + +![][17] + +Geary is an email client that I think does layouts just right. It is spacious, but not in a wasteful way, it is clean, simple, and allows me to get from point A to point B quickly. Hiri, on the other hand, falls just shy of layout heaven. Though the inbox list looks fantastic, when you click to read an email it takes up the whole screen. Whereas Geary or Thunderbird can be set up to have the user’s list of emails on the left and opened emails in the same window on the right, which is my preferred way to read email, Hiri does not allow this functionality. The layout either looks and functions like it belongs on a mobile device, or the email preview is below the email list instead of to the right. This isn’t a make or break issue for me, but I will be honest and say I really don’t like it. + +In my opinion, Hiri could work even better with a couple of tweaks. But that opinion is just that, an opinion. Hiri is modern, clean, and intuitive enough, I am just obnoxiously picky. Other than that, the color palette is beautiful, the soft edges are pretty stunning, and Hiri’s overall design language is a breath of fresh air in the, at times, outdated feel that is oh so common in the Linux application world. + +Also, this isn’t Hiri’s fault but since I installed the Hiri snap it still has the same cursor theme issue that many other snaps suffer from, which drives me UP A WALL when I move in and out of the application, so there’s that. + +#### How much does Hiri cost? + +![Hiri is compatible with Microsoft Active Directory][18] + +Hiri is neither free nor open source software. [Hiri costs][19] either up to $39 a year or $119 for a lifetime license. However, it does provide a free seven day trial period. + +Considering the features it provides, Hiri is a good product even if you don’t have to deal with Microsoft Exchange Servers. Don’t take my word for it. Give Hiri a try for free for the seven day trial and see for yourself if it is worth paying or not. + +And if you decide to purchase it, I have further good news for you. Hiri team has agreed to provide an exclusive 60% discount to It’s FOSS readers. All you have to do is to use coupon code ITSFOSS60 at checkout. + +[Get 60% Off with ITSFOSS60 Coupon Code][20] + +#### Conclusion + +In the end, Hiri is an amazingly beautiful piece of software that checks so many boxes for me. That being said, the three marks that it misses for me are collectively too big to overlook: the layout, the cost, and the freedom (or lack thereof). If you are someone who is really in need of a native client, the layout does not bother you, you can justify spending some money, and you don’t want or need it to be FOSS, then you may have just found your new email client! + +-------------------------------------------------------------------------------- + +via: https://itsfoss.com/hiri-email-review/ + +作者:[Phillip Prado][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://itsfoss.com/author/phillip/ +[1]:https://itsfoss.com/protonmail/ +[2]:https://itsfoss.com/tutanota-review/ +[3]:https://www.thunderbird.net/en-US/ +[4]:https://wiki.gnome.org/Apps/Geary +[5]:http://getmailspring.com/ +[6]:https://en.wikipedia.org/wiki/Microsoft_Exchange_Server +[7]:https://www.hiri.com/ +[8]:https://itsfoss.com/best-email-clients-linux/ +[9]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/08/hiri-email-client-review.jpeg +[10]:https://www.hiri.com/skills/ +[11]:https://en.wikipedia.org/wiki/Active_Directory +[12]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/07/Hiri2-e1533106054811.png +[13]:https://snapcraft.io/hiri +[14]:https://www.kde.org/plasma-desktop +[15]:https://wiki.gnome.org/Apps/Evolution +[16]:https://www.kde.org/applications/internet/kmail/ +[17]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/07/Hiri3-e1533106099642.png +[18]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/07/Hiri1-e1533106238745.png +[19]:https://www.hiri.com/pricing/ +[20]:https://www.hiri.com/download/ diff --git a/sources/tech/20180801 Migrating Perl 5 code to Perl 6.md b/sources/tech/20180801 Migrating Perl 5 code to Perl 6.md new file mode 100644 index 0000000000..0399fd7a62 --- /dev/null +++ b/sources/tech/20180801 Migrating Perl 5 code to Perl 6.md @@ -0,0 +1,77 @@ +Migrating Perl 5 code to Perl 6 +====== + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/perl6-logo-camilla.png?itok=LY5EkYUV) + +Whether you are a programmer who is taking the first steps to convert your Perl 5 code to Perl 6 and encountering some issues or you're just interested in learning about what might happen if you try to port Perl 5 programs to Perl 6, this article should answer your questions. + +The [Perl 6 documentation][1] already contains most (if not all) the [documentation you need][2] to deal with the issues you will confront in migrating Perl 5 code to Perl 6. But, as documentation goes, the focus is on the factual differences. I will try to go a little more in-depth about specific issues and provide a little more hands-on information based on my experience porting quite a lot of Perl 5 code to Perl 6. + +### How is Perl 6 anyway? + +Very well, thank you! Since its first official release in December 2015, Rakudo Perl 6 has seen an order of magnitude of improvement and quite a few bug fixes (more than 14,000 commits in total). Seven books about Perl 6 have been published so far. [Learning Perl 6][3] by Brian D. Foy will soon be published by O'Reilly, having been re-worked from the seminal [Learning Perl][4] (aka "The Llama Book") that many people have come to know and love. + +The user distribution [Rakudo Star][5] is on a three-month release cycle, and more than 1,100 modules are available in the [Perl 6 ecosystem][6]. The Rakudo Compiler Release is on a monthly release cycle and typically contains contributions by more than 30 people. Perl 6 modules are uploaded to the Perl programming Authors Upload Server ([PAUSE][7]) and distributed all over the world using the Comprehensive Perl Archive Network ([CPAN][8]). + +The online [Perl 6 Introduction][9] document has been translated into 12 languages, teaching over 3 billion people about Perl 6 in their native language. The most recent incarnation of [Perl 6 Weekly][10] has been reporting on all things Perl 6 every week since February 2014. + +[Cro][11], a microservices framework, uses all of Perl 6's features from the ground up, providing HTTP 1.1 persistent connections, HTTP 2.0 with request multiplexing, and HTTPS with optional certificate authority out of the box. And a [Perl 6 IDE][12] is now in (paid) beta (think of it as a Kickstarter with immediate deliverables). + +### Using Perl 5 features in Perl 6 + +Perl 5 code can be seamlessly integrated with Perl 6 using the [`Inline::Perl5`][13] module, making all of [CPAN][14] available to any Perl 6 program. This could be considered cheating, as it will embed a Perl 5 interpreter and therefore continues to have a dependency on the `perl` (5) runtime. But it does make it easy to get your Perl 6 code running (if you need access to modules that have not yet been ported) simply by adding `:from` to your `use` statement, like `use DBI:from;`. + +In January 2018, I proposed a [CPAN Butterfly Plan][15] to convert Perl 5 functionality to Perl 6 as closely as possible to the original API. I stated this as a goal because Perl 5 (as a programming language) is so much more than syntax alone. Ask anyone what Perl's unique selling point is, and they will most likely tell you it is CPAN. Therefore, I think it's time to move from this view of the Perl universe: + +![](https://opensource.com/sites/default/files/uploads/perl_dromecentricview.png) + +to a more modern view: + +![](https://opensource.com/sites/default/files/uploads/perl_cpannicanview.png) + +In other words: put CPAN, as the most important element of Perl, in the center. + +### Converting semantics + +To run Perl 5 code natively in Perl 6, you also need a lot of Perl 5 semantics. Having (optional) support for Perl 5 semantics available in Perl 6 lowers the conceptual threshold that Perl 5 programmers perceive when trying to program in Perl 6. It's easier to feel at home! + +Since the publication of the CPAN Butterfly Plan, more than 100 built-in Perl 5 functions are now supported in Perl 6 with the same API. Many functions already exist in Perl 6 but have slightly different semantics, e.g., `shift` in Perl 5 magically shifts from `@_` (or `@ARGV`) if no parameter is specified; in Perl 6 the parameter is obligatory. + +More than 50 Perl 5 CPAN distributions have also been ported to Perl 6 while adhering to the original Perl 5 API. These include core modules such as [Scalar::Util][16] and [List::Util][17], but also non-core modules such as [Text::CSV][18] and [Memoize][19]. Distributions that are upstream on the [River of CPAN][20] are targeted to have as much effect on the ecosystem as possible. + +### Summary + +Rakudo Perl 6 has matured in such a way that using Perl 6 is now a viable approach to creating new, interactive projects. Being able to use reliable and proven Perl 5 language components aids in lowering the threshold for developers to use Perl 6, and it builds towards a situation where the sum of Perl 5 and Perl 6 becomes greater than its parts. + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/8/migrating-perl-5-perl-6 + +作者:[Elizabeth Mattijsen][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://opensource.com/users/lizmat +[1]:https://docs.perl6.org/ +[2]:https://docs.perl6.org/language/5to6-overview +[3]:https://www.learningperl6.com +[4]:http://shop.oreilly.com/product/0636920049517.do +[5]:https://rakudo.org/files +[6]:https://modules.perl6.org +[7]:https://pause.perl.org/pause/query?ACTION=pause_04about +[8]:https://www.cpan.org +[9]:https://perl6intro.com +[10]:https://p6weekly.wordpress.com +[11]:https://cro.services +[12]:https://commaide.com +[13]:http://modules.perl6.org/dist/Inline::Perl5:cpan:NINE +[14]:https://metacpan.org +[15]:https://www.perl.com/article/an-open-letter-to-the-perl-community/ +[16]:https://modules.perl6.org/dist/Scalar::Util +[17]:https://modules.perl6.org/dist/List::Util +[18]:https://modules.perl6.org/dist/Text::CSV +[19]:https://modules.perl6.org/dist/Memoize +[20]:http://neilb.org/2015/04/20/river-of-cpan.html diff --git a/sources/tech/20180802 Top 5 CAD Software Available for Linux in 2018.md b/sources/tech/20180802 Top 5 CAD Software Available for Linux in 2018.md new file mode 100644 index 0000000000..ec02690b6e --- /dev/null +++ b/sources/tech/20180802 Top 5 CAD Software Available for Linux in 2018.md @@ -0,0 +1,143 @@ +Top 5 CAD Software Available for Linux in 2018 +====== +[Computer Aided Design (CAD)][1] is an essential part of many streams of engineering. CAD is professionally used is architecture, auto parts design, space shuttle research, aeronautics, bridge construction, interior design, and even clothing and jewelry. + +A number of professional grade CAD software like SolidWorks and Autodesk AutoCAD are not natively supported on the Linux platform. So today we will be having a look at the top CAD software available for Linux. Let’s dive right in. + +### Best CAD Software available for Linux + +![CAD Software for Linux][2] + +Before you see the list of CAD software for Linux, you should keep one thing in mind that not all the applications listed here are open source. We included some non-FOSS CAD software to help average Linux user. + +Installation instructions of Ubuntu-based Linux distributions have been provided. You may check the respective websites to learn the installation procedure for other distributions. + +The list is not any specific order. CAD application at number one should not be considered better than the one at number three and so on. + +#### 1\. FreeCAD + +For 3D Modelling, FreeCAD is an excellent option which is both free (beer and speech) and open source. FreeCAD is built with keeping mechanical engineering and product design as target purpose. FreeCAD is multiplatform and is available on Windows, Mac OS X+ along with Linux. + +![freecad][3] + +Although FreeCAD has been the choice of many Linux users, it should be noted that FreeCAD is still on version 0.17 and therefore, is not suitable for major deployment. But the development has picked up pace recently. + +[FreeCAD][4] + +FreeCAD does not focus on direct 2D drawings and animation of organic shapes but it’s great for design related to mechanical engineering. FreeCAD version 0.15 is available in the Ubuntu repositories. You can install it by running the below command. +``` +sudo apt install freecad + +``` + +To get newer daily builds (0.17 at the moment), open a terminal (ctrl+alt+t) and run the commands below one by one. +``` +sudo add-apt-repository ppa:freecad-maintainers/freecad-daily + +sudo apt update + +sudo apt install freecad-daily + +``` + +#### 2\. LibreCAD + +LibreCAD is a free, opensource, 2D CAD solution. Generally, CAD tends to be a resource-intensive task, and if you have a rather modest hardware, then I’d suggest you go for LibreCAD as it is really lightweight in terms of resource usage. LibreCAD is a great candidate for geometric constructions. + +![librecad][5] +As a 2D tool, LibreCAD is good but it cannot work on 3D models and renderings. It might be unstable at times but it has a dependable autosave which won’t let your work go wasted. + +[LibreCAD][6] + +You can install LibreCAD by running the following command +``` +sudo apt install librecad + +``` + +#### 3\. OpenSCAD + +OpenSCAD is a free 3D CAD software. OpenSCAD is very lightweight and flexible. OpenSCAD is not interactive. You need to ‘program’ the model and OpenSCAD interprets that code to render a visual model. It is a compiler in a sense. You cannot draw the model. You describe the model. + +![openscad][7] + +OpenSCAD is the most complicated tool on this list but once you get to know it, it provides an enjoyable work experience. + +[OpenSCAD][8] + +You can use the following commands to install OpenSCAD. +``` +sudo apt-get install openscad + +``` + +#### 4\. BRL-CAD + +BRL-CAD is one of the oldest CAD tools out there. It also has been loved by Linux/UNIX users as it aligns itself with *nix philosophies of modularity and freedom. + +![BRL-CAD rendering by Sean][9] + +BRL-CAD was started in 1979, and it is still developed actively. Now, BRL-CAD is not AutoCAD but it is still a great choice for transport studies such as thermal and ballistic penetration. BRL-CAD underlies CSG instead of boundary representation. You might need to keep that in mind while opting for BRL-CAD. You can download BRL-CAD from its official website. + +[BRL-CAD][10] + +#### 5\. DraftSight (not open source) + +If You’re used to working on AutoCAD, then DraftSight would be the perfect alternative for you. + +DraftSight is a great CAD tool available on Linux. It has a rather similar workflow to AutoCAD, which makes migrating easier. It even provides a similar look and feel. DrafSight is also compatible with the .dwg file format of AutoCAD. But DrafSight is a 2D CAD software. It does not support 3D CAD as of yet. + +![draftsight][11] + +Although DrafSight is a commercial software with a starting price of $149. A free version is also made available on the[DraftSight website][12]. You can download the .deb package and install it on Ubuntu based distributions. need to register your free copy using your email ID to start using DraftSight. + +[DraftSight][12] + +#### Honorary mentions + + * With a huge growth in cloud computing technologies, cloud CAD solutions like [OnShape][13] have been getting popular day by day. + * [SolveSpace][14] is another open-source project worth mentioning. It supports 3D modeling. + * Siemens NX is an industrial grade CAD solution available on Windows, Mac OS and Linux, but it is ridiculously expensive, so omitted in this list. + * Then you have [LeoCAD][15], which is a CAD software where you use LEGO blocks to build stuff. What you do with this information is up to you. + + + +#### CAD on Linux, in my opinion + +Although gaming on Linux has picked up, I always tell my hardcore gaming friends to stick to Windows. Similarly, if You are an engineering student with CAD in your curriculum, I’d recommend that you use the software that your college prescribes (AutoCAD, SolidEdge, Catia), which generally tend to run on Windows only. + +And for the advanced professionals, these tools are simply not up to the mark when we’re talking about industry standards. + +For those of you thinking about running AutoCAD in WINE, although some older versions of AutoCAD can be installed on WINE, they simply do not perform, with glitches and crashes ruining the experience. + +That being said, I highly respect the work that has been put by the developers of the above-listed software. They have enriched the FOSS world. And it’s great to see software like FreeCAD developing with an accelerated pace in the recent years. + +Well, that’s it for today. Do share your thoughts with us using the comments section below and don’t forget to share this article. Cheers. + +-------------------------------------------------------------------------------- + +via: https://itsfoss.com/cad-software-linux/ + +作者:[Aquil Roshan][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://itsfoss.com/author/aquil/ +[1]:https://en.wikipedia.org/wiki/Computer-aided_design +[2]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/08/cad-software-linux.jpeg +[3]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/07/freecad.jpg +[4]:https://www.freecadweb.org/ +[5]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/07/librecad.jpg +[6]:https://librecad.org/ +[7]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/07/openscad.jpg +[8]:http://www.openscad.org/ +[9]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/07/brlcad.jpg +[10]:https://brlcad.org/ +[11]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/07/draftsight.jpg +[12]:https://www.draftsight2018.com/ +[13]:https://www.onshape.com/ +[14]:http://solvespace.com/index.pl +[15]:https://www.leocad.org/ diff --git a/sources/tech/20180802 Walkthrough On How To Use GNOME Boxes.md b/sources/tech/20180802 Walkthrough On How To Use GNOME Boxes.md new file mode 100644 index 0000000000..f4c9790df9 --- /dev/null +++ b/sources/tech/20180802 Walkthrough On How To Use GNOME Boxes.md @@ -0,0 +1,117 @@ +Walkthrough On How To Use GNOME Boxes +====== + +![](http://www.linuxandubuntu.com/uploads/2/1/1/5/21152474/how-to-use-gnome-boxes_orig.jpg) + +Boxes or GNOME Boxes is a virtualization software for GNOME Desktop Environment. It is similar to Oracle VirtualBox but features a simple user interface. Boxes also pose some challenge for newbies and VirtualBox users, for instance, on VirtualBox, it is easy to install guest addition image through menu bar but the same is not true for Boxes. Rather, users are encouraged to install additional guest tools from the terminal program within the guest session. + +This article will provide a walkthrough on how to use GNOME Boxes by installing the software and actually setting a guest session on the machine. It will also take you through the steps for installing the guest tools and provide some additional tips for Boxes configuration. + +### Purpose of virtualization + +If you are wondering what is the purpose of virtualization and why most computer experts and developers use them a lot. There is usually a common reason for this: **TESTING**. + +Developers who use Linux and writes software for Windows has to test his program on an actual Windows environment before deploying it to the end users. Virtualization makes it possible for him to install and set up a Windows guest session on his Linux computer. + +Virtualization is also used by ordinary users who wish to get hands-on with their favorite Linux distro that is still in beta release, without installing it on their physical computer. So in the event the virtual machine crashes, the host is not affected and the important files & documents stored on the physical disk remain intact. + +​Virtualization allows you to test a software built for another platform/architecture which may include ARM, MIPS, SPARC, etc on your computer equipped with another architecture such as Intel or AMD. + +### Installing GNOME Boxes + +Launch Ubuntu Software and key in " gnome boxes ". Click the application name to load its installer page and then select the Install button. [![install gnome boxes](http://www.linuxandubuntu.com/uploads/2/1/1/5/21152474/install-gnome-boxes_orig.jpg)][1] + +### Extra setup for Ubuntu 18.04 + +There's a bug in GNOME Boxes on Ubuntu 18.04; it fails to start the Virtual Machine (VM). To remedy that, perform the below two steps on a terminal program: + +1. Add the line "group=kvm" to the qemu config file sudo gedit /etc/modprobe.d/qemu-system-x86.conf + +2. Add your user account to kvm group sudo usermod -a -G kvm ​ + + [![gnome boxes extras for ubuntu 18.04](http://www.linuxandubuntu.com/uploads/2/1/1/5/21152474/gnome-boxes-extras-for-ubuntu-18-04_orig.jpg)][2] + + After that, logout and re-login again for the changes to take effect. + +#### Downloading an image file + +You can download an image file/Operating System (OS) from the Internet or within the GNOME Boxes setup itself. However, for this article we'll proceed with the realistic method ie., downloading an image file from the Internet. We'll be configuring Lubuntu on Boxes so head over to this website to download the Linux distro. + +[Download][3] + +#### To burn or not to burn + +If you have no intention to distribute Lubuntu to your friends or install it on a physical machine then it's best not to burn the image file to a blank disc or portable USB drive. Instead just leave it as it is, we'll use it for creating a VM afterward. + +#### Starting GNOME Boxes + +Below is the interface of GNOME Boxes on Ubuntu - [![create gnome boxes](http://www.linuxandubuntu.com/uploads/2/1/1/5/21152474/create-gnome-boxes_orig.jpg)][4] + +The interface is simple and intuitive for newbies to get familiar right away without much effort. Boxes don't feature a menu bar or toolbar, unlike Oracle VirtualBox. On the top left is the New button to create a VM and on the right houses buttons for VM options; delete list or grid view, and configuration (they'll become available when a VM is created). + +### Installing an Operating System + +Click the New button and choose "Select a file". Select the downloaded Lubuntu image file on the Downloads library and then click Create button. + + [![install os on ubuntu guest box](http://www.linuxandubuntu.com/uploads/2/1/1/5/21152474/install-os-on-ubuntu-guest-box_orig.jpg)][5] + +In case this is your first time installing an OS on a VM, do not panic when the installer pops up a window asking you to erase the disk partition. It's safe, your physical computer hard drive won't be erased, only that the storage space would be allocated for your VM. So on a 1TB hard drive, if you allocate 30 GB for your VM, performing erase partition operation on Boxes would only erase that virtual 30 GB storage drive and not the physical storage. + + _Usually, computer students find virtualization a useful tool for practicing advanced partitioning using UNIX based OS. You can too since there is no risk that would tamper the main OS files._ + +After installing Lubuntu, you'll be prompted to reboot the computer (VM) to finish the installation process and actually boot from the hard drive. Confirm the operation. + +​ + +Sometimes, certain Linux distros hang in the reboot process after installation. The trick is to force shutdown the VM from the options button found on the top right side of the tile bar and then power it on again. + +#### Set up Guest tools + +By now you might have noticed Lubuntu's screen resolution is small with extra black spaces on the left and right side, and folder sharing is not enabled too. This brings up the need to install guest tools on Lubuntu. + +​ + +Launch terminal program from the guest session (not your host terminal program) and install the guest tools using the below command: + +sudo apt install spice-vdagent spice-webdavd + +After that, reboot Lubuntu and the next boot will set the VM to its appropriate screen resolution; no more extra black spaces on the left and right side. You can resize Boxes window and the guest screen resolution will automatically resize itself. + + [![lubuntu on gnome boxes](http://www.linuxandubuntu.com/uploads/2/1/1/5/21152474/lubuntu-on-gnome-boxes_orig.jpg)][6] + +To share a folder between the host and guest, open Boxes options while the guest is still running and choose Properties. On the Devices & Shares category, click the + button and set up the name. By default, Public folder from the host will be shared with the guest OS. You can configure the directory of your choice. After that is done, launch Lubuntu's file manager program (it's called PCManFM) and click Go menu on the menu bar. Select Network and choose Spice Client Folder. The first time you try to open it a dialog box will pop up asking you which program should handle the network, select PCManFM under Accessories category and the network will be mounted on the desktop. Launch it and there you'll see your shared folder name. + +​Now you can share files and folders between host and guest computer. Subsequent launch of the network will directly open the shared folder so you don't have to open the folder manually the next time. + + [![gnome boxes guest addition](http://www.linuxandubuntu.com/uploads/2/1/1/5/21152474/gnome-boxes-guest-addition_orig.jpg)][7] + +#### Where's the OS installed? + +Lubuntu is installed as a VM using **GNOME Boxes** but where does it store the disk image? + +This question is of particular interest for those who wish to move the huge image file to another partition where there is sufficient storage. The trick is using symlinks which is efficient as it saves more space for Linux root partition and or home partition, depending on how the user set it up during installation. Boxes stores the disk image files to ~/.local/share/gnome-boxes/images folder + +### Conclusion + +We've successfully set up Lubuntu as a guest OS on our Ubuntu. You can try other variants of Ubuntu such as Kubuntu, Ubuntu MATE, Xubuntu, etc or some random Linux distros which in my opinion would be quite challenging due to varying package management. But there's no harm in wanting to :) You can also try installing other platforms like Microsoft Windows, OpenBSD, etc on your computer as a VM. And by the way, don't forget to leave your opinions in the comment section below. + + +-------------------------------------------------------------------------------- + +via: http://www.linuxandubuntu.com/home/walkthrough-on-how-to-use-gnome-boxes + +作者:[linuxandubuntu][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:http://www.linuxandubuntu.com +[1]:http://www.linuxandubuntu.com/uploads/2/1/1/5/21152474/install-gnome-boxes_orig.jpg +[2]:http://www.linuxandubuntu.com/uploads/2/1/1/5/21152474/gnome-boxes-extras-for-ubuntu-18-04_orig.jpg +[3]:https://lubuntu.net/ +[4]:http://www.linuxandubuntu.com/uploads/2/1/1/5/21152474/create-gnome-boxes_orig.jpg +[5]:http://www.linuxandubuntu.com/uploads/2/1/1/5/21152474/install-os-on-ubuntu-guest-box_orig.jpg +[6]:http://www.linuxandubuntu.com/uploads/2/1/1/5/21152474/lubuntu-on-gnome-boxes_orig.jpg +[7]:http://www.linuxandubuntu.com/uploads/2/1/1/5/21152474/gnome-boxes-guest-addition_orig.jpg diff --git a/sources/tech/20180803 5 Essential Tools for Linux Development.md b/sources/tech/20180803 5 Essential Tools for Linux Development.md new file mode 100644 index 0000000000..006372ca82 --- /dev/null +++ b/sources/tech/20180803 5 Essential Tools for Linux Development.md @@ -0,0 +1,148 @@ +5 Essential Tools for Linux Development +====== + +![](https://www.linux.com/sites/lcom/files/styles/rendered_file/public/dev-tools.png?itok=kkDNylRg) + +Linux has become a mainstay for many sectors of work, play, and personal life. We depend upon it. With Linux, technology is expanding and evolving faster than anyone could have imagined. That means Linux development is also happening at an exponential rate. Because of this, more and more developers will be hopping on board the open source and Linux dev train in the immediate, near, and far-off future. For that, people will need tools. Fortunately, there are a ton of dev tools available for Linux; so many, in fact, that it can be a bit intimidating to figure out precisely what you need (especially if you’re coming from another platform). + +To make that easier, I thought I’d help narrow down the selection a bit for you. But instead of saying you should use Tool X and Tool Y, I’m going to narrow it down to five categories and then offer up an example for each. Just remember, for most categories, there are several available options. And, with that said, let’s get started. + +### Containers + +Let’s face it, in this day and age you need to be working with containers. Not only are they incredibly easy to deploy, they make for great development environments. If you regularly develop for a specific platform, why not do so by creating a container image that includes all of the tools you need to make the process quick and easy. With that image available, you can then develop and roll out numerous instances of whatever software or service you need. + +Using containers for development couldn’t be easier than it is with [Docker][1]. The advantages of using containers (and Docker) are: + + * Consistent development environment. + + * You can trust it will “just work” upon deployment. + + * Makes it easy to build across platforms. + + * Docker images available for all types of development environments and languages. + + * Deploying single containers or container clusters is simple. + + + + +Thanks to [Docker Hub][2], you’ll find images for nearly any platform, development environment, server, service… just about anything you need. Using images from Docker Hub means you can skip over the creation of the development environment and go straight to work on developing your app, server, API, or service. + +Docker is easily installable of most every Linux platform. For example: To install Docker on Ubuntu, you only have to open a terminal window and issue the command: +``` +sudo apt-get install docker.io + +``` + +With Docker installed, you’re ready to start pulling down specific images, developing, and deploying (Figure 1). + +![Docker images][4] + +Figure 1: Docker images ready to deploy. + +[Used with permission][5] + +### Version control system + +If you’re working on a large project or with a team on a project, you’re going to need a version control system. Why? Because you need to keep track of your code, where your code is, and have an easy means of making commits and merging code from others. Without such a tool, your projects would be nearly impossible to manage. For Linux users, you cannot beat the ease of use and widespread deployment of [Git][6] and [GitHub][7]. If you’re new to their worlds, Git is the version control system that you install on your local machine and GitHub is the remote repository you use to upload (and then manage) your projects. Git can be installed on most Linux distributions. For example, on a Debian-based system, the install is as simple as: +``` +sudo apt-get install git + +``` + +Once installed, you are ready to start your journey with version control (Figure 2). + +![Git installed][9] + +Figure 2: Git is installed and available for many important tasks. + +[Used with permission][5] + +Github requires you to create an account. You can use it for free for non-commercial projects, or you can pay for commercial project housing (for more information check out the price matrix [here][10]). + +### Text editor + +Let’s face it, developing on Linux would be a bit of a challenge without a text editor. Of course what a text editor is varies, depending upon who you ask. One person might say vim, emacs, or nano, whereas another might go full-on GUI with their editor. But since we’re talking development, we need a tool that can meet the needs of the modern day developer. And before I mention a couple of text editors, I will say this: Yes, I know that vim is a serious workhorse for serious developers and, if you know it well vim will meet and exceed all of your needs. However, getting up to speed enough that it won’t be in your way, can be a bit of a hurdle for some developers (especially those new to Linux). Considering my goal is to always help win over new users (and not just preach to an already devout choir), I’m taking the GUI route here. + +As far as text editors are concerned, you cannot go wrong with the likes of [Bluefish][11]. Bluefish can be found in most standard repositories and features project support, multi-threaded support for remote files, search and replace, open files recursively, snippets sidebar, integrates with make, lint, weblint, xmllint, unlimited undo/redo, in-line spell checker, auto-recovery, full screen editing, syntax highlighting (Figure 3), support for numerous languages, and much more. + +![Bluefish][13] + +Figure 3: Bluefish running on Ubuntu Linux 18.04. + +[Used with permission][5] + +### IDE + +Integrated Development Environment (IDE) is a piece of software that includes a comprehensive set of tools that enable a one-stop-shop environment for developing. IDEs not only enable you to code your software, but document and build them as well. There are a number of IDEs for Linux, but one in particular is not only included in the standard repositories it is also very user-friendly and powerful. That tool in question is [Geany][14]. Geany features syntax highlighting, code folding, symbol name auto-completion, construct completion/snippets, auto-closing of XML and HTML tags, call tips, many supported filetypes, symbol lists, code navigation, build system to compile and execute your code, simple project management, and a built-in plugin system. + +Geany can be easily installed on your system. For example, on a Debian-based distribution, issue the command: +``` +sudo apt-get install geany + +``` + +Once installed, you’re ready to start using this very powerful tool that includes a user-friendly interface (Figure 4) that has next to no learning curve. + +![Geany][16] + +Figure 4: Geany is ready to serve as your IDE. + +[Used with permission][5] + +### diff tool + +There will be times when you have to compare two files to find where they differ. This could be two different copies of what was the same file (only one compiles and the other doesn’t). When that happens, you don’t want to have to do that manually. Instead, you want to employ the power of tool like [Meld][17]. Meld is a visual diff and merge tool targeted at developers. With Meld you can make short shrift out of discovering the differences between two files. Although you can use a command line diff tool, when efficiency is the name of the game, you can’t beat Meld. + +Meld allows you to open a comparison between to files and it will highlight the differences between each. Meld also allows you to merge comparisons either from the right or the left (as the files are opened side by side - Figure 5). + +![Comparing two files][19] + +Figure 5: Comparing two files with a simple difference. + +[Used with permission][5] + +Meld can be installed from most standard repositories. On a Debian-based system, the installation command is: +``` +sudo apt-get install meld + +``` + +### Working with efficiency + +These five tools not only enable you to get your work done, they help to make it quite a bit more efficient. Although there are a ton of developer tools available for Linux, you’re going to want to make sure you have one for each of the above categories (maybe even starting with the suggestions I’ve made). + +Learn more about Linux through the free ["Introduction to Linux" ][20]course from The Linux Foundation and edX. + +-------------------------------------------------------------------------------- + +via: https://www.linux.com/learn/intro-to-linux/2018/8/5-essential-tools-linux-development + +作者:[Jack Wallen][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.linux.com/users/jlwallen +[1]:https://www.docker.com/ +[2]:https://hub.docker.com/ +[3]:/files/images/5devtools1jpg +[4]:https://www.linux.com/sites/lcom/files/styles/rendered_file/public/5devtools_1.jpg?itok=V1Bsbkg9 (Docker images) +[5]:/licenses/category/used-permission +[6]:https://git-scm.com/ +[7]:https://github.com/ +[8]:/files/images/5devtools2jpg +[9]:https://www.linux.com/sites/lcom/files/styles/rendered_file/public/5devtools_2.jpg?itok=YJjhe4O6 (Git installed) +[10]:https://github.com/pricing +[11]:http://bluefish.openoffice.nl/index.html +[12]:/files/images/5devtools3jpg +[13]:https://www.linux.com/sites/lcom/files/styles/rendered_file/public/5devtools_3.jpg?itok=66A7Svme (Bluefish) +[14]:https://www.geany.org/ +[15]:/files/images/5devtools4jpg +[16]:https://www.linux.com/sites/lcom/files/styles/rendered_file/public/5devtools_4.jpg?itok=jRcA-0ue (Geany) +[17]:http://meldmerge.org/ +[18]:/files/images/5devtools5jpg +[19]:https://www.linux.com/sites/lcom/files/styles/rendered_file/public/5devtools_5.jpg?itok=eLkfM9oZ (Comparing two files) +[20]:https://training.linuxfoundation.org/linux-courses/system-administration-training/introduction-to-linux diff --git a/sources/tech/20180803 How to use Fedora Server to create a router - gateway.md b/sources/tech/20180803 How to use Fedora Server to create a router - gateway.md new file mode 100644 index 0000000000..0394826c10 --- /dev/null +++ b/sources/tech/20180803 How to use Fedora Server to create a router - gateway.md @@ -0,0 +1,285 @@ +How to use Fedora Server to create a router / gateway +====== + +![](https://fedoramagazine.org/wp-content/uploads/2018/07/buildingarouter-816x345.jpg) + +Building a router (or gateway) using Fedora Server is an interesting project for users wanting to learn more about Linux system administration and networking. In this article, learn how to configure a Fedora Server minimal install to act as an internet router / gateway. + +This guide is based on [Fedora 28][1] and assumes you have already installed Fedora Server (minimal install). Additionally, you require a suitable network card / modem for the incoming internet connection. In this example, the [DrayTek VigorNIC 132][2] NIC was used to create the router. + +### Why build your own router + +There are many benefits for building your own router over buying a standalone box (or using the one supplied by your internet provider): + + * Easily update and run latest software versions + * May be less prone to be part of larger hacking campaign as its not a common consumer device + * Run your own VMs or containers on same host/router + * Build OpenShift on top of router (future story in this series) + * Include your own VPN, Tor, or other tunnel paths along with correct routing + + + +The downside is related to time and knowledge. + + * You have to manage your own security + * You need to have the knowledge to troubleshoot if an issue happens or find it through the web (no support calls) + * Costs more in most cases than hardware provided by an internet provider + + + +Basic network topology + +The diagram below describes the basic topology used in this setup. The machine running Fedora Server has a PCI Express modem for VDSL. Alternatively, if you use a [Raspberry Pi][3] with external modem the configuration is mostly similar. + +![topology][4] + +### Initial Setup + +First of all, install the packages needed to make the router. Bash auto-complete is included to make things easier when later configuring. Additionally, install packages to allow you to host your own VMs on the same router/hosts via KVM-QEMU. +``` +dnf install -y bash-completion NetworkManager-ppp qemu-kvm qemu-img virt-manager libvirt libvirt-python libvirt-client virt-install virt-viewer + +``` + +Next, use **nmcli** to set the MTU on the WAN(PPPoE) interfaces to align with DSL/ATM MTU and create **pppoe** interface. This [link][5] has a great explanation on how this works. The username and password will be provided by your internet provider. +``` +nmcli connection add type pppoe ifname enp2s0 username 00xxx5511yyy0001@t-online.de password XXXXXX 802-3-ethernet.mtu 1452 + +``` + +Now, set up the firewall with the default zone as external and remove incoming SSH access. +``` +firewall-cmd --set-default-zone=external +firewall-cmd --permanent --zone=external --remove-service=ssh + +``` + +Add LAN interface(br0) along with preferred LAN IP address and then add your physical LAN interface to the bridge. +``` +nmcli connection add ifname br0 type bridge con-name br0 bridge.stp no ipv4.addresses 10.0.0.1/24 ipv4.method manual +nmcli connection add type bridge-slave ifname enp1s0 master br0 + +``` + +Remember to use a subnet that does not overlap with your works VPN subnet. For example my work provides a 10.32.0.0/16 subnet when I VPN into the office so I need to avoid using this in my home network. If you overlap addressing then the route provided by your VPN will likely have lower priority and you will not route through the VPN tunnel. + +Now create a file called bridge.xml, containing a bridge definition that **virsh** will consume to create a bridge in **QEMU**. +``` +cat > bridge.xml < +    host-bridge +     +     + +EOF + +``` + +Start and enable your libvirt-guests service so you can add the bridge in your virtual environment for the VMs to use. +``` +systemctl start libvirt-guests.service +systemctl enable libvirt-guests.service + +``` + +Add your “host-bridge” to QEMU via virsh command and the XML file you created earlier. +``` +virsh net-define bridge.xml + +``` + +virsh net-start host-bridge virsh net-autostart host-bridge + +Add br0 to internal zone and allow DNS and DHCP as we will be setting up our own services on this router. +``` +firewall-cmd --permanent --zone=internal --add-interface=br0 +firewall-cmd --permanent --zone=internal --add-service=dhcp +firewall-cmd --permanent --zone=internal --add-service=dns + +``` + +Since many DHCP clients including Windows and Linux don’t take into account the MTU attribute in DHCP, we will need to allow TCP based protocols to set MSS based on PMTU size. +``` +firewall-cmd --permanent --direct --add-passthrough ipv4 -I FORWARD -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu + +``` + +Now we reload the firewall to take permanent changes into account. +``` +nmcli connection reload + +``` + +### Install and Configure DHCP + +DHCP configuration depends on your home network setup. Use your own desired domain name and and the subnet was defined during the creation of **br0**. Be sure to note the MAC address in the config file below can either be capture from the command below once you have DHCP services up and running or you can pull it off the label externally on the device you want to set to static addressing. +``` +cat /var/lib/dhcpd/dhcpd.leases + +dnf -y install dhcp +vi /etc/dhcp/dhcpd.conf + +option domain-name "lajoie.org"; +option domain-name-servers 10.0.0.1; +default-lease-time 600; +max-lease-time 7200; +authoritative; +subnet 10.0.0.0 netmask 255.255.255.0 { + range dynamic-bootp 10.0.0.100 10.0.0.254; + option broadcast-address 10.0.0.255; + option routers 10.0.0.1; option interface-mtu 1452; +} +host ubifi { + option host-name "ubifi.lajoie.org"; + hardware ethernet f0:9f:c2:1f:c1:12; + fixed-address 10.0.0.2; +} + +``` + +Now enable and start your DHCP server +``` +systemctl start dhcpd +systemctl enable dhcpd + +``` + +### DNS Install and Configure + +Next, install **bind** and and **bind-utils** for tools like **nslookup** and **dig**. +``` +dnf -y install bind bind-utils + +``` + +Configure your bind server with listening address (LAN interface in this case) and the forward/reverse zones. +``` +$ vi /etc/named.conf + +options { + listen-on port 53 { 10.0.0.1; }; + listen-on-v6 port 53 { none; }; + directory "/var/named"; + dump-file "/var/named/data/cache_dump.db"; + statistics-file "/var/named/data/named_stats.txt"; + memstatistics-file "/var/named/data/named_mem_stats.txt"; + secroots-file "/var/named/data/named.secroots"; + recursing-file "/var/named/data/named.recursing"; + allow-query { 10.0.0.0/24; }; + recursion yes; + forwarders {8.8.8.8; 8.8.4.4; }; + dnssec-enable yes; + dnssec-validation yes; + managed-keys-directory "/var/named/dynamic"; + pid-file "/run/named/named.pid"; + session-keyfile "/run/named/session.key"; + include "/etc/crypto-policies/back-ends/bind.config"; +}; +controls { }; +logging { + channel default_debug { + file "data/named.run"; + severity dynamic; + }; +}; +view "internal" { + match-clients { localhost; 10.0.0.0/24; }; + zone "lajoie.org" IN { + type master; + file "lajoie.org.db"; + allow-update { none; }; + }; + zone "0.0.10.in-addr.arpa" IN { + type master; + file "0.0.10.db"; + allow-update { none; }; + }; +}; + +``` + +Here is a zone file for example and make sure to update the serial number after each edit of the bind service will assume no changes took place. +``` +$ vi /var/named/lajoie.org.db + +$TTL 86400 +@ IN SOA gw.lajoie.org. root.lajoie.org. ( + 2018040801 ;Serial + 3600 ;Refresh + 1800 ;Retry + 604800 ;Expire + 86400 ;Minimum TTL ) +IN NS gw.lajoie.org. +IN A 10.0.0.1 +gw IN A 10.0.0.1 +ubifi IN A 10.0.0.2 + +``` + +Here is a reverse zone file for example and make sure to update the serial number after each edit of the bind service will assume no changes took place. +``` +$ vi /var/named/0.0.10.db + +$TTL 86400 +@ IN SOA gw.lajoie.org. root.lajoie.org. ( + 2018040801 ;Serial + 3600 ;Refresh + 1800 ;Retry + 604800 ;Expire + 86400 ;Minimum TTL ) +IN NS gw.lajoie.org. +IN PTR lajoie.org. +IN A 255.255.255.0 +1 IN PTR gw.lajoie.org. +2 IN PTR ubifi.lajoie.org. + +``` + +Now enable and start your DNS server +``` +systemctl start named +systemctl enable named + +``` + +# Secure SSH + +Last simple step is to make SSH service listen only on your LAN segment. Run this command to see whats listening at this moment. Remember we did not allow SSH on the external firewall zone but this step is still best practice in my opinion. +``` +ss -lnp4 + +``` + +Now edit the SSH service to only listen on your LAN segment. +``` +vi /etc/ssh/sshd_config + +AddressFamily inet +ListenAddress 10.0.0.1 + +``` + +Restart your SSH service for changes to take effect. +``` +systemctl restart sshd.service + +``` + + +-------------------------------------------------------------------------------- + +via: https://fedoramagazine.org/use-fedora-server-create-router-gateway/ + +作者:[Eric Lajoie][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://fedoramagazine.org/author/elajoie/ +[1]:https://getfedora.org/en/server/ +[2]:https://www.draytek.com/en/products/products-a-z/router.all/vigornic-132-series/ +[3]:https://fedoraproject.org/wiki/Architectures/ARM/Raspberry_Pi +[4]:https://ericlajoie.com/photo/FedoraRouter.png +[5]:https://www.sonicwall.com/en-us/support/knowledge-base/170505851231244 diff --git a/sources/tech/20180803 SDKMAN - A CLI Tool To Easily Manage Multiple Software Development Kits.md b/sources/tech/20180803 SDKMAN - A CLI Tool To Easily Manage Multiple Software Development Kits.md new file mode 100644 index 0000000000..1fcd5f729b --- /dev/null +++ b/sources/tech/20180803 SDKMAN - A CLI Tool To Easily Manage Multiple Software Development Kits.md @@ -0,0 +1,308 @@ +SDKMAN – A CLI Tool To Easily Manage Multiple Software Development Kits +====== + +![](https://www.ostechnix.com/wp-content/uploads/2018/08/sdkman-720x340.png) + +Are you a developer who often install and test applications on different SDKs? I’ve got a good news for you! Say hello to **SDKMAN** , a CLI tool that helps you to easily manage multiple software development kits. It provides a convenient way to install, switch, list and remove candidates. Using SDKMAN, you can now manage parallel versions of multiple SDKs easily on any Unix-like operating system. It allows the developers to install Software Development Kits for the JVM such as Java, Groovy, Scala, Kotlin and Ceylon. Ant, Gradle, Grails, Maven, SBT, Spark, Spring Boot, Vert.x and many others are also supported. SDKMAN is free, light weight, open source and written in **Bash**. + +### Installing SDKMAN + +Installing SDKMAN is trivial. First, make sure you have installed **zip** and **unzip** applications. It is available in the default repositories of most Linux distributions. For instance, to install unzip on Debian-based systems, simply run: +``` +$ sudo apt-get install zip unzip + +``` + +Then, install SDKMAN using command: +``` +$ curl -s "https://get.sdkman.io" | bash + +``` + +It’s that simple. Once the installation is completed, run the following command: +``` +$ source "$HOME/.sdkman/bin/sdkman-init.sh" + +``` + +If you want to install it in a custom location of your choice other than **$HOME/.sdkman** , for example **/usr/local/** , do: +``` +$ export SDKMAN_DIR="/usr/local/sdkman" && curl -s "https://get.sdkman.io" | bash + +``` + +Make sure your user has full access rights to this folder. + +Finally, check if the installation is succeeded using command: +``` +$ sdk version +==== BROADCAST ================================================================= +* 01/08/18: Kotlin 1.2.60 released on SDKMAN! #kotlin +* 31/07/18: Sbt 1.2.0 released on SDKMAN! #sbt +* 31/07/18: Infrastructor 0.2.1 released on SDKMAN! #infrastructor +================================================================================ + +SDKMAN 5.7.2+323 + +``` + +Congratulations! SDKMAN has been installed. Let us go ahead and see how to install and manage SDKs. + +### Manage Multiple Software Development Kits + +To view the list of available candidates(SDKs), run: +``` +$ sdk list + +``` + +Sample output would be: +``` +================================================================================ +Available Candidates +================================================================================ +q-quit /-search down +j-down ?-search up +k-up h-help + +-------------------------------------------------------------------------------- +Ant (1.10.1) https://ant.apache.org/ + +Apache Ant is a Java library and command-line tool whose mission is to drive +processes described in build files as targets and extension points dependent +upon each other. The main known usage of Ant is the build of Java applications. +Ant supplies a number of built-in tasks allowing to compile, assemble, test and +run Java applications. Ant can also be used effectively to build non Java +applications, for instance C or C++ applications. More generally, Ant can be +used to pilot any type of process which can be described in terms of targets and +tasks. + +: $ sdk install ant + +``` + +As you can see, SDKMAN list one candidate at a time along with the description of the candidate and it’s official website and the installation command. Press ENTER key to list the next candidates. + +To install a SDK, for example Java JDK, run: +``` +$ sdk install java + +``` + +Sample output: +``` +Downloading: java 8.0.172-zulu + +In progress... + +######################################################################################## 100.0% + +Repackaging Java 8.0.172-zulu... + +Done repackaging... + +Installing: java 8.0.172-zulu +Done installing! + +Setting java 8.0.172-zulu as default. + +``` + +If you have multiple SDKs, it will prompt if you want the currently installed version to be set as **default**. Answering **Yes** will set the currently installed version as default. + +To install particular version of a SDK, do: +``` +$ sdk install ant 1.10.1 + +``` + +If you already have local installation of a specific candidate, you can set it as local version like below. +``` +$ sdk install groovy 3.0.0-SNAPSHOT /path/to/groovy-3.0.0-SNAPSHOT + +``` + +To list a particular candidates versions: +``` +$ sdk list ant + +``` + +Sample output: +``` +================================================================================ +Available Ant Versions +================================================================================ +> * 1.10.1 +1.10.0 +1.9.9 +1.9.8 +1.9.7 + +================================================================================ ++ - local version +* - installed +> - currently in use +================================================================================ + +``` + +Like I already said, If you have installed multiple versions, SDKMAN will prompt you if you want the currently installed version to be set as **default**. You can answer Yes to set it as default. Also, you can do that later by using the following command: +``` +$ sdk default ant 1.9.9 + +``` + +The above command will set Apache Ant version 1.9.9 as default. + +You can choose which version of an installed candidate to use by using the following command: +``` +$ sdk use ant 1.9.9 + +``` + +To check what is currently in use for a Candidate, for example Java, run: +``` +$ sdk current java + +Using java version 8.0.172-zulu + +``` + +To check what is currently in use for all Candidates, for example Java, run: +``` +$ sdk current + +Using: + +ant: 1.10.1 +java: 8.0.172-zulu + +``` + +To upgrade an outdated candidate, do: +``` +$ sdk upgrade scala + +``` + +You can also check what is outdated for all Candidates as well. +``` +$ sdk upgrade + +``` + +SDKMAN has offline mode feature that allows the SDKMAN to function when working offline. You can enable or disable the offline mode at any time by using the following commands: +``` +$ sdk offline enable + +$ sdk offline disable + +``` + +To remove an installed SDK, run: +``` +$ sdk uninstall ant 1.9.9 + +``` + +For more details, check the help section. +``` +$ sdk help + +Usage: sdk [candidate] [version] +sdk offline + +commands: +install or i [version] +uninstall or rm +list or ls [candidate] +use or u [version] +default or d [version] +current or c [candidate] +upgrade or ug [candidate] +version or v +broadcast or b +help or h +offline [enable|disable] +selfupdate [force] +update +flush + +candidate : the SDK to install: groovy, scala, grails, gradle, kotlin, etc. + use list command for comprehensive list of candidates + eg: $ sdk list + +version : where optional, defaults to latest stable if not provided + eg: $ sdk install groovy + +``` + +### Update SDKMAN + +The following command installs a new version of SDKMAN if it is available. +``` +$ sdk selfupdate + +``` + +SDKMAN will also periodically check for any updates and let you know with instruction on how to update. +``` +WARNING: SDKMAN is out-of-date and requires an update. + +$ sdk update +Adding new candidates(s): scala + +``` + +### Remove cache + +It is recommended to clean the cache that contains the downloaded SDK binaries for time to time. To do so, simply run: +``` +$ sdk flush archives + +``` + +It is also good to clean temporary folder to save up some space: +``` +$ sdk flush temp + +``` + +### Uninstall SDKMAN + +If you don’t need SDKMAN or don’t like it, remove as shown below. +``` +$ tar zcvf ~/sdkman-backup_$(date +%F-%kh%M).tar.gz -C ~/ .sdkman +$ rm -rf ~/.sdkman + +``` + +Finally, open your **.bashrc** , **.bash_profile** and/or **.profile** files and find and remove the following lines. +``` +#THIS MUST BE AT THE END OF THE FILE FOR SDKMAN TO WORK!!! +export SDKMAN_DIR="/home/sk/.sdkman" +[[ -s "/home/sk/.sdkman/bin/sdkman-init.sh" ]] && source "/home/sk/.sdkman/bin/sdkman-init.sh" + +``` + +If you use ZSH, remove the above line from the **.zshrc** file. + +And, that’s all for today. I hope you find SDKMAN useful. More good stuffs to come. Stay tuned! + +Cheers! + + + +-------------------------------------------------------------------------------- + +via: https://www.ostechnix.com/sdkman-a-cli-tool-to-easily-manage-multiple-software-development-kits/ + +作者:[SK][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.ostechnix.com/author/sk/ diff --git a/sources/tech/20180806 GPaste Is A Great Clipboard Manager For Gnome Shell.md b/sources/tech/20180806 GPaste Is A Great Clipboard Manager For Gnome Shell.md new file mode 100644 index 0000000000..c3b2d2b77e --- /dev/null +++ b/sources/tech/20180806 GPaste Is A Great Clipboard Manager For Gnome Shell.md @@ -0,0 +1,96 @@ +GPaste Is A Great Clipboard Manager For Gnome Shell +====== +**[GPaste][1] is a clipboard management system that consists of a library, daemon, and interfaces for the command line and Gnome (using a native Gnome Shell extension).** + +A clipboard manager allows keeping track of what you're copying and pasting, providing access to previously copied items. GPaste, with its native Gnome Shell extension, makes the perfect addition for those looking for a Gnome clipboard manager. + +[![GPaste Gnome Shell extension Ubuntu 18.04][2]][3] +GPaste Gnome Shell extension +**Using GPaste in Gnome, you get a configurable, searchable clipboard history, available with a click on the top panel. GPaste remembers not only the text you copy, but also file paths and images** (the latter needs to be enabled from its settings as it's disabled by default). + +What's more, GPaste can detect growing lines, meaning it can detect when a new text copy is an extension of another and replaces it if it's true, useful for keeping your clipboard clean. + +From the extension menu you can pause GPaste from tracking the clipboard, and remove items from the clipboard history or the whole history. You'll also find a button that launches the GPaste user interface window. + +**If you prefer to use the keyboard, you can use a key shortcut to open the GPaste history from the top bar** (`Ctrl + Alt + H`), **or open the full GPaste GUI** (`Ctrl + Alt + G`). + +The tool also incorporates keyboard shortcuts to (can be changed): + + * delete the active item from history: `Ctrl + Alt + V` + + * **mark the active item as being a password (which obfuscates the clipboard entry in GPaste):** `Ctrl + Alt + S` + + * sync the clipboard to the primary selection: `Ctrl + Alt + O` + + * sync the primary selection to the clipboard: `Ctrl + Alt + P` + + * upload the active item to a pastebin service: `Ctrl + Alt + U` + +[![][4]][5] +GPaste GUI + +The GPaste interface window provides access to the clipboard history (with options to clear, edit or upload items), which can be searched, an option to pause GPaste from tracking the clipboard, restart the GPaste daemon, backup current clipboard history, as well as to its settings. + +[![][6]][7] +GPaste GUI + +From the GPaste UI you can change settings like: + + * Enable or disable the Gnome Shell extension + * Sync the daemon state with the extension's one + * Primary selection affects history + * Synchronize clipboard with primary selection + * Image support + * Trim items + * Detect growing lines + * Save history + * History settings like max history size, memory usage, max text item length, and more + * Keyboard shortcuts + + + +### Download GPaste + +[Download GPaste](https://github.com/Keruspe/GPaste) + +The Gpaste project page does not link to any GPaste binaries, and only source installation instructions. Users running Linux distributions other than Debian or Ubuntu (for which you'll find GPaste installation instructions below) can search their distro repositories for GPaste. + +Do not confuse GPaste with the GPaste Integration extension posted on the Gnome Shell extension website. That is a Gnome Shell extension that uses GPaste daemon, which is no longer maintained. The native Gnome Shell extension built into GPaste is still maintained. + +#### Install GPaste in Ubuntu (18.04, 16.04) or Debian (Jessie and newer) + +**For Debian, GPaste is available for Jessie and newer, while for Ubuntu, GPaste is in the repositories for 16.04 and newer (so it's available in the Ubuntu 18.04 Bionic Beaver).** + +**You can install GPaste (the daemon and the Gnome Shell extension) in Debian or Ubuntu using this command:** +``` +sudo apt install gnome-shell-extensions-gpaste gpaste + +``` + +After the installation completes, restart Gnome Shell by pressing `Alt + F2` and typing `r` , then pressing the `Enter` key. The GPaste Gnome Shell extension should now be enabled and its icon should show up on the top Gnome Shell panel. If it's not, use Gnome Tweaks (Gnome Tweak Tool) to enable the extension. + +**The GPaste 3.28.0 package from[Debian][8] and [Ubuntu][9] has a bug that makes it crash if the image support option is enabled, so do not enable this feature for now.** This was marked as + + +-------------------------------------------------------------------------------- + +via: https://www.linuxuprising.com/2018/08/gpaste-is-great-clipboard-manager-for.html + +作者:[Logix][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://plus.google.com/118280394805678839070 +[1]:https://github.com/Keruspe/GPaste +[2]:https://2.bp.blogspot.com/-2ndArDBcrwY/W2gyhMc1kEI/AAAAAAAABS0/ZAe_onuGCacMblF733QGBX3XqyZd--WuACLcBGAs/s400/gpaste-gnome-shell-extension-ubuntu1804.png (Gpaste Gnome Shell) +[3]:https://2.bp.blogspot.com/-2ndArDBcrwY/W2gyhMc1kEI/AAAAAAAABS0/ZAe_onuGCacMblF733QGBX3XqyZd--WuACLcBGAs/s1600/gpaste-gnome-shell-extension-ubuntu1804.png +[4]:https://2.bp.blogspot.com/-7FBRsZJvYek/W2gyvzmeRxI/AAAAAAAABS4/LhokMFSn8_kZndrNB-BTP4W3e9IUuz9BgCLcBGAs/s640/gpaste-gui_1.png +[5]:https://2.bp.blogspot.com/-7FBRsZJvYek/W2gyvzmeRxI/AAAAAAAABS4/LhokMFSn8_kZndrNB-BTP4W3e9IUuz9BgCLcBGAs/s1600/gpaste-gui_1.png +[6]:https://4.bp.blogspot.com/-047ShYc6RrQ/W2gyz5FCf_I/AAAAAAAABTA/-o6jaWzwNpsSjG0QRwRJ5Xurq_A6dQ0sQCLcBGAs/s640/gpaste-gui_2.png +[7]:https://4.bp.blogspot.com/-047ShYc6RrQ/W2gyz5FCf_I/AAAAAAAABTA/-o6jaWzwNpsSjG0QRwRJ5Xurq_A6dQ0sQCLcBGAs/s1600/gpaste-gui_2.png +[8]:https://packages.debian.org/buster/gpaste +[9]:https://launchpad.net/ubuntu/+source/gpaste +[10]:https://www.imagination-land.org/posts/2018-04-13-gpaste-3.28.2-released.html diff --git a/sources/tech/20180806 How ProPublica Illinois uses GNU Make to load 1.4GB of data every day.md b/sources/tech/20180806 How ProPublica Illinois uses GNU Make to load 1.4GB of data every day.md new file mode 100644 index 0000000000..f5cd367985 --- /dev/null +++ b/sources/tech/20180806 How ProPublica Illinois uses GNU Make to load 1.4GB of data every day.md @@ -0,0 +1,126 @@ +How ProPublica Illinois uses GNU Make to load 1.4GB of data every day +====== + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/data_metrics_analytics_desktop_laptop.png?itok=9QXd7AUr) + +I avoided using GNU Make in my data journalism work for a long time, partly because the documentation was so obtuse that I couldn’t see how Make, one of many extract-transform-load (ETL) processes, could help my day-to-day data reporting. But this year, to build [The Money Game][1], I needed to load 1.4GB of Illinois political contribution and spending data every day, and the ETL process was taking hours, so I gave Make another chance. + +Now the same process takes less than 30 minutes. + +Here’s how it all works, but if you want to skip directly to the code, [we’ve open-sourced it here][2]. + +Fundamentally, Make lets you say: + + * File X depends on a transformation applied to file Y + * If file X doesn’t exist, apply that transformation to file Y and make file X + + + +This “start with file Y to get file X” pattern is a daily reality of data journalism, and using Make to load political contribution and spending data was a great use case. The data is fairly large, accessed via a slow FTP server, has a quirky format, has just enough integrity issues to keep things interesting, and needs to be compatible with a legacy codebase. To tackle it, I needed to start from the beginning. + +### Overview + +The financial disclosure data we’re using is from the Illinois State Board of Elections, but the [Illinois Sunshine project][3] had released open source code (no longer available) to handle the ETL process and fundraising calculations. Using their code, the ETL process took about two hours to run on robust hardware and over five hours on our servers, where it would sometimes fail for reasons I never quite understood. I needed it to work better and work faster. + +The process looks like this: + + * **Download** data files via FTP from Illinois State Board Of Elections. + * **Clean** the data using Python to resolve integrity issues and create clean versions of the data files. + * **Load** the clean data into PostgreSQL using its highly efficient but finicky “\copy” command. + * **Transform** the data in the database to clean up column names and provide more immediately useful forms of the data using “raw” and “public” PostgreSQL schemas and materialized views (essentially persistently cached versions of standard SQL views). + + + +The cleaning step must happen before any data is loaded into the database, so we can take advantage of PostgreSQL’s efficient import tools. If a single row has a string in a column where it’s expecting an integer, the whole operation fails. + +GNU Make is well-suited to this task. Make’s model is built around describing the output files your ETL process should produce and the operations required to go from a set of original source files to a set of output files. + +As with any ETL process, the goal is to preserve your original data, keep operations atomic and provide a simple and repeatable process that can be run over and over. + +Let’s examine a few of the steps: + +### Download and pre-import cleaning + +Take a look at this snippet, which could be a standalone Makefile: +``` +data/download/%.txt : aria2c -x5 -q -d data/download --ftp-user="$(ILCAMPAIGNCASH_FTP_USER)" --ftp-passwd="$(ILCAMPAIGNCASH_FTP_PASSWD)" ftp://ftp.elections.il.gov/CampDisclDataFiles/$*.txt data/processed/%.csv : data/download/%.txt python processors/clean_isboe_tsv.py $< $* > $@ + +``` + +This snippet first downloads a file via FTP and then uses Python to process it. For example, if “Expenditures.txt” is one of my source data files, I can run `make data/processed/Expenditures.csv` to download and process the expenditure data. + +There are two things to note here. + +The first is that we use [Aria2][4] to handle FTP duties. Earlier versions of the script used other FTP clients that were either slow as molasses or painful to use. After some trial and error, I found Aria2 did the job better than lftp (which is fast but fussy) or good old ftp (which is both slow and fussy). I also found some incantations that took download times from roughly an hour to less than 20 minutes. + +Second, the cleaning step is crucial for this dataset. It uses a simple class-based Python validation scheme you can [see here][5]. The important thing to note is that while Python is pretty slow generally, Python 3 is fast enough for this. And as long as you are [only processing row-by-row][6] without any objects accumulating in memory or doing any extra disk writes, performance is fine, even on low-resource machines like the servers in ProPublica’s cluster, and there aren’t any unexpected quirks. + +### Loading + +Make is built around file inputs and outputs. But what happens if our data is both in files and database tables? Here are a few valuable tricks I learned for integrating database tables into Makefiles: + +**One SQL file per table / transform** : Make loves both files and simple mappings, so I created individual files with the schema definitions for each table or any other atomic table-level operation. The table names match the SQL filenames, the SQL filenames match the source data filenames. You can see them [here][7]. + +**Use exit code magic to make tables look like files to Make** : Hannah Cushman and Forrest Gregg from DataMade [introduced me to this trick on Twitter][8]. Make can be fooled into treating tables like files if you prefix table level commands with commands that emit appropriate exit codes. If a table exists, emit a successful code. If it doesn’t, emit an error. + +Beyond that, loading consists solely of the highly efficient PostgreSQL `\copy` command. While the `COPY` command is even more efficient, it doesn’t play nicely with Amazon RDS. Even if ProPublica moved to a different database provider, I’d continue to use `\copy` for portability unless eking out a little more performance was mission-critical. + +There’s one last curveball: The loading step imports data to a PostgreSQL schema called `raw` so that we can cleanly transform the data further. Postgres schemas provide a useful way of segmenting data within a single database — instead of a single namespace with tables like `raw_contributions` and `clean_contributions`, you can keep things simple and clear with an almost folder-like structure of `raw.contributions` and `public.contributions`. + +### Post-import transformations + +The Illinois Sunshine code also renames columns and slightly reshapes the data for usability and performance reasons. Column aliasing is useful for end users and the intermediate tables are required for compatibility with the legacy code. + +In this case, the loader imports into a schema called `raw` that is as close to the source data as humanly possible. + +The data is then transformed by creating materialized views of the raw tables that rename columns and handle some light post-processing. This is enough for our purposes, but more elaborate transformations could be applied without sacrificing clarity or obscuring the source data. Here’s a snippet of one of these view definitions: +``` +CREATE MATERIALIZED VIEW d2_reports AS SELECT id as id, committeeid as committee_id, fileddocid as filed_doc_id, begfundsavail as beginning_funds_avail, indivcontribi as individual_itemized_contrib, indivcontribni as individual_non_itemized_contrib, xferini as transfer_in_itemized, xferinni as transfer_in_non_itemized, # …. FROM raw.d2totals WITH DATA; +``` + +These transformations are very simple, but simply using more readable column names is a big improvement for end-users. + +As with table schema definitions, there is a file for each table that describes the transformed view. We use materialized views, which, again, are essentially persistently cached versions of standard SQL views, because storage is cheap and they are faster than traditional SQL views. + +### A note about security + +You’ll notice we use environment variables that are expanded inline when the commands are run. That’s useful for debugging and helps with portability. But it’s not a good idea if you think log files or terminal output could be compromised or people who shouldn’t know these secrets have access to logs or shared systems. For more security, you could use a system like the PostgreSQL `pgconf` file and remove the environment variable references. + +### Makefiles for the win + +My only prior experience with Make was in a computational math course 15 years ago, where it was a frustrating and poorly explained footnote. The combination of obtuse documentation, my bad experience in school and an already reliable framework kept me away. Plus, my shell scripts and Python Fabric/Invoke code were doing a fine job building reliable data processing pipelines based on the same principles for the smaller, quick turnaround projects I was doing. + +But after trying Make for this project, I was more than impressed with the results. It’s concise and expressive. It enforces atomic operations, but rewards them with dead simple ways to handle partial builds, which is a big deal during development when you really don’t want to be repeating expensive operations to test individual components. Combined with PostgreSQL’s speedy import tools, schemas, and materialized views, I was able to load the data in a fraction of the time. And just as important, the performance of the new process is less sensitive to varying system resources. + +If you’re itching to get started with Make, here are a few additional resources: + ++ [Making Data, The Datamade Way][9], by Hannah Cushman. My original inspiration. ++ [“Why Use Make”][10] by Mike Bostock. ++ [“Practical Makefiles, by example”][11] by John Tsiombikas is a nice resource if you want to dig deeper, but Make’s documentation is intimidating. + + +In the end, the best build/processing system is any system that never alters source data, clearly shows transformations, uses version control and can be easily run over and over. Grunt, Gulp, Rake, Make, Invoke … you have options. As long as you like what you use and use it religiously, your work will benefit. + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/8/how-propublica-illinois-uses-gnu-make + +作者:[David Eads][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://opensource.com/users/eads +[1]:https://www.propublica.org/article/illinois-governors-race-campaign-widget-update +[2]:https://github.com/propublica/ilcampaigncash/ +[3]:https://illinoissunshine.org/ +[4]:https://aria2.github.io/ +[5]:https://github.com/propublica/ilcampaigncash/blob/master/processors/lib/models.py +[6]:https://github.com/propublica/ilcampaigncash/blob/master/processors/clean_isboe_tsv.py#L13 +[7]:https://github.com/propublica/ilcampaigncash/tree/master/sql/tables +[8]:https://twitter.com/eads/status/968970130427404293 +[9]: https://github.com/datamade/data-making-guidelines +[10]: https://bost.ocks.org/mike/make/ +[11]: http://nuclear.mutantstargoat.com/articles/make/ diff --git a/sources/tech/20180806 Recreate Famous Data Decryption Effect Seen On Sneakers Movie.md b/sources/tech/20180806 Recreate Famous Data Decryption Effect Seen On Sneakers Movie.md new file mode 100644 index 0000000000..9deb3242db --- /dev/null +++ b/sources/tech/20180806 Recreate Famous Data Decryption Effect Seen On Sneakers Movie.md @@ -0,0 +1,110 @@ +Recreate Famous Data Decryption Effect Seen On Sneakers Movie +====== + +![](https://www.ostechnix.com/wp-content/uploads/2018/08/sneakers-720x340.jpg) + +A while ago, we published a guide that described how to [**turn your Ubuntu Linux console into a veritable Hollywood technical melodrama hacker interface**][1] using **Hollywood** utility which is written by **Dustin Kirkland** from Canonical. Today, I have stumbled upon a similar CLI utility named “ **N** o **M** ore **S** ecrets”, shortly **nms**. Like Hollywood utility, the nms utility is also **USELESS** (Sorry!). You can use it just for fun. The nms will recreate the famous data decryption effect seen on Sneakers, released in 1992. + +[**Sneakers**][2] is a comedy and crime-thriller genre movie, starred by **Robert Redford** among other famous actors named **Dan Aykroyd** , **David Strathairn** and **Ben Kingsley**. This movie is one of the popular hacker movie released in 1990s. If you haven’t watched it already, there is [**a scene**][3] in Sneakers movie where a group of experts who specialize in testing security systems will recover a top secret black box that has the ability to decrypt all existing encryption systems around the world. The nms utility simply simulates how exactly the data decryption effect scene looks like on Sneakers movie in your Terminal. + +### Installing Nms + +The nms project has no dependencies, but it relies on ANSI/VT100 terminal escape sequences to recreate the effect. Most modern terminal programs support these sequences by default. Just in case, if your Terminal doesn’t support these sequences, install **ncurses**. Ncurses is available in the default repositories of most Linux distributions. We are going to compile and install nms from source. So, just make sure you have installed the development tools in your Linux box. If you haven’t installed them already, refer the following links. + +After installing, git, make, and gcc development tools, run the following commands one by one to compile and install nms utility. +``` +$ git clone https://github.com/bartobri/no-more-secrets.git +$ cd ./no-more-secrets +$ make nms +$ make sneakers +$ sudo make install + +``` + +Finally, check if the installation was successful using command: +``` +$ nms -v +nms version 0.3.3 + +``` + +Alternatively, you can install nms using [**Linuxbrew**][4] package manager as shown below. +``` +$ brew install no-more-secrets + +``` + +Now it is time to run nms. + +### Recreate Famous Data Decryption Effect Seen On Sneakers Movie Using Nms + +The nms utility works on piped data. Pipe any Linux command’s output to nms tool like below and enjoy the effect right from your Terminal. Have a look at the following command: +``` +$ ls -l | nms + +``` + +By default, after the initial encrypted characters are displayed, the **nms** utility will wait for the user to press a key to start the decryption sequence. This is how the it is depicted in the Sneakers movie. Just press any key to start the decryption sequence to reveal the original plaintext characters. + +If you don’t want to press any key, you can auto-initiate the decryption sequence using **-a** flag. +``` +$ ls -l | nms -a + +``` + +You can also set a foreground color, for example green, use **-f ** option as shown below. +``` +$ ls -l | nms -f green + +``` + +Remember If you don’t specify **-a** flag, you must press any key to initiate the decryption sequence. + +To clear the screen before starting encryption and decryption processes, use **-c** flag. +``` +$ ls -l | nms -c + +``` + +To mask single blank space characters, use -s flag. Please note that other space characters such as tabs and newlines will not be masked. +``` +$ ls -l | nms -s + +``` + +You can also view the actual decryption effect scene in the Sneakers movie using the following command: +``` +$ sneakers + +``` + +Choose any option given to exit this utility. + +Don’t like it? Sorry about that. Go to the nms project folder and simply run the following command to remove it. +``` +$ sudo make uninstall + +``` + +And, that’s all for now. More good stuffs to come. Stay tuned! + +Cheers! + + + +-------------------------------------------------------------------------------- + +via: https://www.ostechnix.com/no-more-secrets-recreate-famous-data-decryption-effect-seen-on-sneakers-movie/ + +作者:[SK][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.ostechnix.com/author/sk/ +[1]:https://www.ostechnix.com/turn-ubuntu-terminal-hollywood-technical-melodrama-hacker-interface/ +[2]:https://www.imdb.com/title/tt0105435/ +[3]:https://www.youtube.com/watch?v=F5bAa6gFvLs&t=35 +[4]:https://www.ostechnix.com/linuxbrew-common-package-manager-linux-mac-os-x/ diff --git a/sources/tech/20180806 Systemd Timers- Three Use Cases.md b/sources/tech/20180806 Systemd Timers- Three Use Cases.md new file mode 100644 index 0000000000..7d1d4cac97 --- /dev/null +++ b/sources/tech/20180806 Systemd Timers- Three Use Cases.md @@ -0,0 +1,220 @@ +Systemd Timers: Three Use Cases +====== + +![](https://www.linux.com/sites/lcom/files/styles/rendered_file/public/timer-analogue-1078057.jpg?itok=IKS4TrkE) + +In this systemd tutorial series, we have[ already talked about systemd timer units to some degree][1], but, before moving on to the sockets, let's look at three examples that illustrate how you can best leverage these units. + +### Simple _cron_ -like behavior + +This is something I have to do: collect [popcon data from Debian][2] every week, preferably at the same time so I can see how the downloads for certain applications evolve. This is the typical thing you can have a _cron_ job do, but a systemd timer can do it too: +``` +# cron-like popcon.timer + +[Unit] +Description= Says when to download and process popcons + +[Timer] +OnCalendar= Thu *-*-* 05:32:07 +Unit= popcon.service + +[Install] +WantedBy= basic.target + +``` + +The actual _popcon.service_ runs a regular _wget_ job, so nothing special. What is new in here is the `OnCalendar=` directive. This is what lets you set a service to run on a certain date at a certain time. In this case, `Thu` means " _run on Thursdays_ " and the `*-*-*` means " _the exact date, month and year don't matter_ ", which translates to " _run on Thursday, regardless of the date, month or year_ ". + +Then you have the time you want to run the service. I chose at about 5:30 am CEST, which is when the server is not very busy. + +If the server is down and misses the weekly deadline, you can also work an _anacron_ -like functionality into the same timer: +``` +# popcon.timer with anacron-like functionality + +[Unit] +Description=Says when to download and process popcons + +[Timer] +Unit=popcon.service +OnCalendar=Thu *-*-* 05:32:07 +Persistent=true + +[Install] +WantedBy=basic.target + +``` + +When you set the `Persistent=` directive to true, it tells systemd to run the service immediately after booting if the server was down when it was supposed to run. This means that if the machine was down, say for maintenance, in the early hours of Thursday, as soon as it is booted again, _popcon.service_ will be run immediately and then it will go back to the routine of running the service every Thursday at 5:32 am. + +So far, so straightforward. + +### Delayed execution + +But let's kick thing up a notch and "improve" the [systemd-based surveillance system][3]. Remember that the system started taking pictures the moment you plugged in a camera. Suppose you don't want pictures of your face while you install the camera. You will want to delay the start up of the picture-taking service by a minute or two so you can plug in the camera and move out of frame. + +To do this; first change the Udev rule so it points to a timer: +``` +ACTION=="add", SUBSYSTEM=="video4linux", ATTRS{idVendor}=="03f0", +ATTRS{idProduct}=="e207", TAG+="systemd", ENV{SYSTEMD_WANTS}="picchanged.timer", +SYMLINK+="mywebcam", MODE="0666" + +``` + +The timer looks like this: +``` +# picchanged.timer + +[Unit] +Description= Runs picchanged 1 minute after the camera is plugged in + +[Timer] +OnActiveSec= 1 m +Unit= picchanged.path + +[Install] +WantedBy= basic.target + +``` + +The Udev rule gets triggered when you plug the camera in and it calls the timer. The timer waits for one minute after it starts (`OnActiveSec= 1 m`) and then runs _picchanged.path_ , which [monitors to see if the master image changes][4]. The _picchanged.path_ is also in charge of pulling in the _webcam.service_ , the service that actually takes the picture. + +### Start and stop Minetest server at a certain time every day + +In the final example, let's say you have decided to delegate parenting to systemd. I mean, systemd seems to be already taking over most of your life anyway. Why not embrace the inevitable? + +So you have your Minetest service set up for your kids. You also want to give some semblance of caring about their education and upbringing and have them do homework and chores. What you want to do is make sure Minetest is only available for a limited time (say from 5 pm to 7 pm) every evening. + +This is different from " _starting a service at certain time_ " in that, writing a timer to start the service at 5 pm is easy...: +``` +# minetest.timer + +[Unit] +Description= Runs the minetest.service at 5pm everyday + +[Timer] +OnCalendar= *-*-* 17:00:00 +Unit= minetest.service + +[Install] +WantedBy= basic.target + +``` + +... But writing a counterpart timer that shuts down a service at a certain time needs a bigger dose of lateral thinking. + +Let's start with the obvious -- the timer: +``` +# stopminetest.timer + +[Unit] +Description= Stops the minetest.service at 7 pm everyday + +[Timer] +OnCalendar= *-*-* 19:05:00 +Unit= stopminetest.service + +[Install] +WantedBy= basic.target + +``` + +The tricky part is how to tell _stopminetest.service_ to actually, you know, stop the Minetest. There is no way to pass the PID of the Minetest server from _minetest.service_. and there are no obvious commands in systemd's unit vocabulary to stop or disable a running service. + +The trick is to use systemd's `Conflicts=` directive. The `Conflicts=` directive is similar to systemd's `Wants=` directive, in that it does _exactly the opposite_. If you have `Wants=a.service` in a unit called _b.service_ , when it starts, _b.service_ will run _a.service_ if it is not running already. Likewise, if you have a line that reads `Conflicts= a.service` in your _b.service_ unit, as soon as _b.service_ starts, systemd will stop _a.service_. + +This was created for when two services could clash when trying to take control of the same resource simultaneously, say when two services needed to access your printer at the same time. By putting a `Conflicts=` in your preferred service, you could make sure it would override the least important one. + +You are going to use `Conflicts=` a bit differently, however. You will use `Conflicts=` to close down cleanly the _minetest.service_ : +``` +# stopminetest.service + +[Unit] +Description= Closes down the Minetest service +Conflicts= minetest.service + +[Service] +Type= oneshot +ExecStart= /bin/echo "Closing down minetest.service" + +``` + +The _stopminetest.service_ doesn't do much at all. Indeed, it could do nothing at all, but just because it contins that `Conflicts=` line in there, when it is started, systemd will close down _minetest.service_. + +There is one last wrinkle in your perfect Minetest set up: What happens if you are late home from work, it is past the time when the server should be up but playtime is not over? The `Persistent=` directive (see above) that runs a service if it has missed its start time is no good here, because if you switch the server on, say at 11 am, it would start Minetest and that is not what you want. What you really want is a way to make sure that systemd will only start Minetest between the hours of 5 and 7 in the evening: +``` +# minetest.timer + +[Unit] +Description= Runs the minetest.service every minute between the hours of 5pm and 7pm + +[Timer] +OnCalendar= *-*-* 17..19:*:00 +Unit= minetest.service + +[Install] +WantedBy= basic.target + +``` + +The line `OnCalendar= *-*-* 17..19:*:00` is interesting for two reasons: (1) `17..19` is not a point in time, but a period of time, in this case the period of time between the times of 17 and 19; and (2) the `*` in the minute field indicates that the service must be run every minute. Hence, you would read this as " _run the minetest.service every minute between 5 and 7 pm_ ". + +There is still one catch, though: once the _minetest.service_ is up and running, you want _minetest.timer_ to stop trying to run it again and again. You can do that by including a `Conflicts=` directive into _minetest.service_ : +``` +# minetest.service + +[Unit] +Description= Runs Minetest server +Conflicts= minetest.timer + +[Service] +Type= simple +User= + +ExecStart= /usr/bin/minetest --server +ExecStop= /bin/kill -2 $MAINPID + +[Install] +WantedBy= multi-user.targe + +``` + +The `Conflicts=` directive shown above makes sure _minetest.timer_ is stopped as soon as the _minetest.service_ is successfully started. + +Now enable and start _minetest.timer_ : +``` +systemctl enable minetest.timer +systemctl start minetest.timer + +``` + +And, if you boot the server at, say, 6 o'clock, _minetest.timer_ will start up and, as the time falls between 5 and 7, _minetest.timer_ will try and start _minetest.service_ every minute. But, as soon as _minetest.service_ is running, systemd will stop _minetest.timer_ because it "conflicts" with _minetest.service_ , thus avoiding the timer from trying to start the service over and over when it is already running. + +It is a bit counterintuitive that you use the service to kill the timer that started it up in the first place, but it works. + +### Conclusion + +You probably think that there are better ways of doing all of the above. I have heard the term "overengineered" in regard to these articles, especially when using systemd timers instead of cron. + +But, the purpose of this series of articles is not to provide the best solution to any particular problem. The aim is to show solutions that use systemd units as much as possible, even to a ridiculous length. The aim is to showcase plenty of examples of how the different types of units and the directives they contain can be leveraged. It is up to you, the reader, to find the real practical applications for all of this. + +Be that as it may, there is still one more thing to go: next time, we'll be looking at _sockets_ and _targets_ , and then we'll be done with systemd units. + +Learn more about Linux through the free ["Introduction to Linux" ][5]course from The Linux Foundation and edX. + +-------------------------------------------------------------------------------- + +via: https://www.linux.com/blog/intro-to-linux/2018/8/systemd-timers-two-use-cases-0 + +作者:[Paul Brown][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.linux.com/users/bro66 +[1]:https://www.linux.com/blog/learn/intro-to-linux/2018/7/setting-timer-systemd-linux +[2]:https://popcon.debian.org/ +[3]:https://www.linux.com/blog/intro-to-linux/2018/6/systemd-services-reacting-change +[4]:https://www.linux.com/blog/learn/intro-to-linux/2018/6/systemd-services-monitoring-files-and-directories +[5]:https://training.linuxfoundation.org/linux-courses/system-administration-training/introduction-to-linux diff --git a/sources/tech/20180806 Use Gstreamer and Python to rip CDs.md b/sources/tech/20180806 Use Gstreamer and Python to rip CDs.md new file mode 100644 index 0000000000..7b78184ad9 --- /dev/null +++ b/sources/tech/20180806 Use Gstreamer and Python to rip CDs.md @@ -0,0 +1,312 @@ +Use Gstreamer and Python to rip CDs +====== + +![](https://fedoramagazine.org/wp-content/uploads/2018/08/cd-rip-2-816x345.jpg) + +In a previous article, you learned how to use the MusicBrainz service to provide tag information for your audio files, using a simple Python script. This article shows you how to also script an all-in-one solution to copy your CDs down to a music library folder in your choice of formats. + +Unfortunately, the powers that be make it impossible for Fedora to carry the necessary bits to encode MP3 in official repos. So that part is left as an exercise for the reader. But if you use a cloud service such as Google Play to host your music, this script makes audio files you can upload easily. + +The script will record your CD down to one of the following file formats: + + * Uncompressed WAV, which you can further encode or play with. + * Compressed but lossless FLAC. Lossless files preserve all the fidelity of the original audio. + * Compressed, lossy Ogg Vorbis. Like MP3 and Apple’s AAC, Ogg Vorbis uses special algorithms and psychoacoustic properties to sound close to the original audio. However, Ogg Vorbis usually produces superior results to those other compressed formats at the same file sizes. You can[read more about it here][1] if you like technical details. + + + +### The components + +The first element of the script is a [GStreamer][2] pipeline. GStreamer is a full featured multimedia framework included in Fedora. It comes [installed by default in Workstation][3], too. GStreamer is used behind the scene by many multimedia apps in Fedora. It lets apps manipulate all kinds of video and audio files. + +The second major component in this script is choosing, and using, a multimedia tagging library. In this case [the mutagen library][4] makes it easy to tag many kinds of multimedia files. The script in this article uses mutagen to tag Ogg Vorbis or FLAC files. + +Finally, the script uses [Python’s argparse, part of the standard library][5], for some easy to use options and help text. The argparse library is useful for most Python scripts where you expect the user to provide parameters. This article won’t cover this part of the script in great detail. + +### The script + +You may recall [the previous article][6] that used MusicBrainz to fetch tag information. This script includes that code, with some tweaks to make it integrate better with the new functions. (You may find it easier to read this script if you copy and paste it into your favorite editor.) +``` +#!/usr/bin/python3 + +import os, sys +import subprocess +from argparse import ArgumentParser +import libdiscid +import musicbrainzngs as mb +import requests +import json +from getpass import getpass + +parser = ArgumentParser() +parser.add_argument('-f', '--flac', action='store_true', dest='flac', + default=False, help='Rip to FLAC format') +parser.add_argument('-w', '--wav', action='store_true', dest='wav', + default=False, help='Rip to WAV format') +parser.add_argument('-o', '--ogg', action='store_true', dest='ogg', + default=False, help='Rip to Ogg Vorbis format') +options = parser.parse_args() + +# Set up output varieties +if options.wav + options.ogg + options.flac > 1: + raise parser.error("Only one of -f, -o, -w please") +if options.wav: + fmt = 'wav' + encoding = 'wavenc' +elif options.flac: + fmt = 'flac' + encoding = 'flacenc' + from mutagen.flac import FLAC as audiofile +elif options.ogg: + fmt = 'oga' + quality = 'quality=0.3' + encoding = 'vorbisenc {} ! oggmux'.format(quality) + from mutagen.oggvorbis import OggVorbis as audiofile + +# Get MusicBrainz info +this_disc = libdiscid.read(libdiscid.default_device()) +mb.set_useragent(app='get-contents', version='0.1') +mb.auth(u=input('Musicbrainz username: '), p=getpass()) + +release = mb.get_releases_by_discid(this_disc.id, includes=['artists', + 'recordings']) +if release.get('disc'): + this_release=release['disc']['release-list'][0] + + album = this_release['title'] + artist = this_release['artist-credit'][0]['artist']['name'] + year = this_release['date'].split('-')[0] + + for medium in this_release['medium-list']: + for disc in medium['disc-list']: + if disc['id'] == this_disc.id: + tracks = medium['track-list'] + break + + # We assume here the disc was found. If you see this: + # NameError: name 'tracks' is not defined + # ...then the CD doesn't appear in MusicBrainz and can't be + # tagged. Use your MusicBrainz account to create a release for + # the CD and then try again. + + # Get cover art to cover.jpg + if this_release['cover-art-archive']['artwork'] == 'true': + url = 'http://coverartarchive.org/release/' + this_release['id'] + art = json.loads(requests.get(url, allow_redirects=True).content) + for image in art['images']: + if image['front'] == True: + cover = requests.get(image['image'], allow_redirects=True) + fname = '{0} - {1}.jpg'.format(artist, album) + print('Saved cover art as {}'.format(fname)) + f = open(fname, 'wb') + f.write(cover.content) + f.close() + break + +for trackn in range(len(tracks)): + track = tracks[trackn]['recording']['title'] + + # Output file name based on MusicBrainz values + outfname = '{:02} - {}.{}'.format(trackn+1, track, fmt).replace('/', '-') + + print('Ripping track {}...'.format(outfname)) + cmd = 'gst-launch-1.0 cdiocddasrc track={} ! '.format(trackn+1) + \ + 'audioconvert ! {} ! '.format(encoding) + \ + 'filesink location="{}"'.format(outfname) + msgs = subprocess.getoutput(cmd) + + if not options.wav: + audio = audiofile(outfname) + print('Tagging track {}...'.format(outfname)) + audio['TITLE'] = track + audio['TRACKNUMBER'] = str(trackn+1) + audio['ARTIST'] = artist + audio['ALBUM'] = album + audio['DATE'] = year + audio.save() + +``` + +#### Determining output format + +This part of the script lets the user decide how to format the output files: +``` +parser = ArgumentParser() +parser.add_argument('-f', '--flac', action='store_true', dest='flac', + default=False, help='Rip to FLAC format') +parser.add_argument('-w', '--wav', action='store_true', dest='wav', + default=False, help='Rip to WAV format') +parser.add_argument('-o', '--ogg', action='store_true', dest='ogg', + default=False, help='Rip to Ogg Vorbis format') +options = parser.parse_args() + +# Set up output varieties +if options.wav + options.ogg + options.flac > 1: + raise parser.error("Only one of -f, -o, -w please") +if options.wav: + fmt = 'wav' + encoding = 'wavenc' +elif options.flac: + fmt = 'flac' + encoding = 'flacenc' + from mutagen.flac import FLAC as audiofile +elif options.ogg: + fmt = 'oga' + quality = 'quality=0.3' + encoding = 'vorbisenc {} ! oggmux'.format(quality) + from mutagen.oggvorbis import OggVorbis as audiofile + +``` + +The parser, built from the argparse library, gives you a built in –help function: +``` +$ ipod-cd --help +usage: ipod-cd [-h] [-b BITRATE] [-w] [-o] + +optional arguments: + -h, --help show this help message and exit + -b BITRATE, --bitrate BITRATE + Set a target bitrate + -w, --wav Rip to WAV format + -o, --ogg Rip to Ogg Vorbis format + +``` + +The script allows the user to use -f, -w, or -o on the command line to choose a format. Since these are stored as True (a Python boolean value), they can also be treated as the integer value 1. If more than one is selected, the parser generates an error. + +Otherwise, the script sets an appropriate encoding string to be used with GStreamer later in the script. Notice the Ogg Vorbis selection also includes a quality setting, which is then included in the encoding. Care to try your hand at an easy change? Try making a parser argument and additional formatting code so the user can select a quality value between -0.1 and 1.0. + +Notice also that for each of the file formats that allows tagging (WAV does not), the script imports a different tagging class. This way the script can have simpler, less confusing tagging code later in the script. In this script, both Ogg Vorbis and FLAC are using classes from the mutagen library. + +#### Getting CD info + +The next section of the script attempts to load MusicBrainz info for the disc. You’ll find that audio files ripped with this script have data not included in the Python code here. This is because GStreamer is also capable of detecting CD-Text that’s included on some discs during the mastering and manufacturing process. Often, though, this data is in all capitals (like “TRACK TITLE”). MusicBrainz info is more compatible with modern apps and other platforms. + +For more information on this section, [refer to the previous article here on the Magazine][6]. A few trivial changes appear here to make the script work better as a single process. + +One item to note is this warning: +``` +# We assume here the disc was found. If you see this: +# NameError: name 'tracks' is not defined +# ...then the CD doesn't appear in MusicBrainz and can't be +# tagged. Use your MusicBrainz account to create a release for +# the CD and then try again. + +``` + +The script as shown doesn’t include a way to handle cases where CD information isn’t found. This is on purpose. If it happens, take a moment to help the community by [entering CD information on MusicBrainz][7], using your login account. + +#### Ripping and labeling tracks + +The next section of the script actually does the work. It’s a simple loop that iterates through the track list found via MusicBrainz. + +First, the script sets the output filename for the individual track based on the format the user selected: +``` +for trackn in range(len(tracks)): + track = tracks[trackn]['recording']['title'] + + # Output file name based on MusicBrainz values + outfname = '{:02} - {}.{}'.format(trackn+1, track, fmt) + +``` + +Then, the script calls a CLI GStreamer utility to perform the ripping and encoding process. That process turns each CD track into an audio file in your current directory: +``` + print('Ripping track {}...'.format(outfname)) + cmd = 'gst-launch-1.0 cdiocddasrc track={} ! '.format(trackn+1) + \ + 'audioconvert ! {} ! '.format(encoding) + \ + 'filesink location="{}"'.format(outfname) + msgs = subprocess.getoutput(cmd) + +``` + +The complete GStreamer pipeline would look like this at a command line: +``` +gst-launch-1.0 cdiocddasrc track=1 ! audioconvert ! vorbisenc quality=0.3 ! oggmux ! filesink location="01 - Track Name.oga" + +``` + +GStreamer has Python libraries to let you use the framework in interesting ways directly without using subprocess. To keep this article less complex, the script calls the command line utility from Python to do the multimedia work. + +Finally, the script labels the output file if it’s not a WAV file. Both Ogg Vorbis and FLAC use similar methods in their mutagen classes. That means this code can remain very simple: +``` + if not options.wav: + audio = audiofile(outfname) + print('Tagging track {}...'.format(outfname)) + audio['TITLE'] = track + audio['TRACKNUMBER'] = str(trackn+1) + audio['ARTIST'] = artist + audio['ALBUM'] = album + audio['DATE'] = year + audio.save() + +``` + +If you decide to write code for another file format, you need to import the correct class earlier, and then perform the tagging correctly. You don’t have to use the mutagen class. For instance, you might choose to use eyed3 for tagging MP3 files. In that case, the tagging code might look like this: +``` +... +# In the parser handling for MP3 format +from eyed3 import load as audiofile +... +# In the handling for MP3 tags +audio.tag.version = (2, 3, 0) +audio.tag.artist = artist +audio.tag.title = track +audio.tag.album = album +audio.tag.track_num = (trackn+1, len(tracks)) +audio.tag.save() + +``` + +(Note the encoding function is up to you to provide.) + +### Running the script + +Here’s an example output of the script: +``` +$ ipod-cd -o +Ripping track 01 - Shout, Pt. 1.oga... +Tagging track 01 - Shout, Pt. 1.oga... +Ripping track 02 - Stars of New York.oga... +Tagging track 02 - Stars of New York.oga... +Ripping track 03 - Breezy.oga... +Tagging track 03 - Breezy.oga... +Ripping track 04 - Aeroplane.oga... +Tagging track 04 - Aeroplane.oga... +Ripping track 05 - Minor Is the Lonely Key.oga... +Tagging track 05 - Minor Is the Lonely Key.oga... +Ripping track 06 - You Can Come Round If You Want To.oga... +Tagging track 06 - You Can Come Round If You Want To.oga... +Ripping track 07 - I'm Gonna Haunt This Place.oga... +Tagging track 07 - I'm Gonna Haunt This Place.oga... +Ripping track 08 - Crash That Piano.oga... +Tagging track 08 - Crash That Piano.oga... +Ripping track 09 - Save Yourself.oga... +Tagging track 09 - Save Yourself.oga... +Ripping track 10 - Get on Home.oga... +Tagging track 10 - Get on Home.oga... + +``` + +Enjoy burning your old CDs into easily portable audio files! + + +-------------------------------------------------------------------------------- + +via: https://fedoramagazine.org/use-gstreamer-python-rip-cds/ + +作者:[Paul W. Frields][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://fedoramagazine.org/author/pfrields/ +[1]:https://xiph.org/vorbis/ +[2]:https://gstreamer.freedesktop.org/ +[3]:https://getfedora.org/workstation +[4]:https://mutagen.readthedocs.io/en/latest/ +[5]:https://docs.python.org/3/library/argparse.html +[6]:https://fedoramagazine.org/use-musicbrainz-get-cd-information/ +[7]:https://musicbrainz.org/ diff --git a/sources/tech/20180807 5 reasons the i3 window manager makes Linux better.md b/sources/tech/20180807 5 reasons the i3 window manager makes Linux better.md new file mode 100644 index 0000000000..8ad6a4ac7d --- /dev/null +++ b/sources/tech/20180807 5 reasons the i3 window manager makes Linux better.md @@ -0,0 +1,111 @@ +5 reasons the i3 window manager makes Linux better +====== + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/cloud-windows.png?itok=jd5sBNQH) + +One of the nicest things about Linux (and open source software in general) is the freedom to choose among different alternatives to address our needs. + +I've been using Linux for a long time, but I was never entirely happy with the desktop environment options available. Until last year, [Xfce][1] was the closest to what I consider a good compromise between features and performance. Then I found [i3][2], an amazing piece of software that changed my life. + +I3 is a tiling window manager. The goal of a window manager is to control the appearance and placement of windows in a windowing system. Window managers are often used as part a full-featured desktop environment (such as GNOME or Xfce), but some can also be used as standalone applications. + +A tiling window manager automatically arranges the windows to occupy the whole screen in a non-overlapping way. Other popular tiling window managers include [wmii][3] and [xmonad][4]. + +![i3 tiled window manager screenshot][6] + +Screenshot of i3 with three tiled windows + +Following are the top five reasons I use the i3 window manager and recommend it for a better Linux desktop experience. + +### 1\. Minimalism + +I3 is fast. It is neither bloated nor fancy. It is designed to be simple and efficient. As a developer, I value these features, as I can use the extra capacity to power my favorite development tools or test stuff locally using containers or virtual machines. + +In addition, i3 is a window manager and, unlike full-featured desktop environments, it does not dictate the applications you should use. Do you want to use Thunar from Xfce as your file manager? GNOME's gedit to edit text? I3 does not care. Pick the tools that make the most sense for your workflow, and i3 will manage them all in the same way. + +### 2\. Screen real estate + +As a tiling window manager, i3 will automatically "tile" or position the windows in a non-overlapping way, similar to laying tiles on a wall. Since you don't need to worry about window positioning, i3 generally makes better use of your screen real estate. It also allows you to get to what you need faster. + +There are many useful cases for this. For example, system administrators can open several terminals to monitor or work on different remote systems simultaneously; and developers can use their favorite IDE or editor and a few terminals to test their programs. + +In addition, i3 is flexible. If you need more space for a particular window, enable full-screen mode or switch to a different layout, such as stacked or tabbed. + +### 3\. Keyboard-driven workflow + +I3 makes extensive use of keyboard shortcuts to control different aspects of your environment. These include opening the terminal and other programs, resizing and positioning windows, changing layouts, and even exiting i3. When you start using i3, you need to memorize a few of those shortcuts to get around and, with time, you'll use more of them. + +The main benefit is that you don't often need to switch contexts from the keyboard to the mouse. With practice, it means you'll improve the speed and efficiency of your workflow. + +For example, to open a new terminal, press `+`. Since the windows are automatically positioned, you can start typing your commands right away. Combine that with a nice terminal-driven text editor (e.g., Vim) and a keyboard-focused browser for a fully keyboard-driven workflow. + +In i3, you can define shortcuts for everything. Here are some examples: + + * Open terminal + * Open browser + * Change layouts + * Resize windows + * Control music player + * Switch workspaces + + + +Now that I am used to this workflow, I can't see myself going back to a regular desktop environment. + +### 4\. Flexibility + +I3 strives to be minimal and use few system resources, but that does not mean it can't be pretty. I3 is flexible and can be customized in several ways to improve the visual experience. Because i3 is a window manager, it doesn't provide tools to enable customizations; you need external tools for that. Some examples: + + * Use `feh` to define a background picture for your desktop. + * Use a compositor manager such as `compton` to enable effects like window fading and transparency. + * Use `dmenu` or `rofi` to enable customizable menus that can be launched from a keyboard shortcut. + * Use `dunst` for desktop notifications. + + + +I3 is fully configurable, and you can control every aspect of it by updating the default configuration file. From changing all keyboard shortcuts, to redefining the name of the workspaces, to modifying the status bar, you can make i3 behave in any way that makes the most sense for your needs. + +![i3 with rofi menu and dunst desktop notifications][8] + +i3 with `rofi` menu and `dunst` desktop notifications + +Finally, for more advanced users, i3 provides a full interprocess communication ([IPC][9]) interface that allows you to use your favorite language to develop scripts or programs for even more customization options. + +### 5\. Workspaces + +In i3, a workspace is an easy way to group windows. You can group them in different ways according to your workflow. For example, you can put the browser on one workspace, the terminal on another, an email client on a third, etc. You can even change i3's configuration to always assign specific applications to their own workspaces. + +Switching workspaces is quick and easy. As usual in i3, do it with a keyboard shortcut. Press `+num` to switch to workspace `num`. If you get into the habit of always assigning applications/groups of windows to the same workspace, you can quickly switch between them, which makes workspaces a very useful feature. + +In addition, you can use workspaces to control multi-monitor setups, where each monitor gets an initial workspace. If you switch to that workspace, you switch to that monitor—without moving your hand off the keyboard. + +Finally, there is another, special type of workspace in i3: the scratchpad. It is an invisible workspace that shows up in the middle of the other workspaces by pressing a shortcut. This is a convenient way to access windows or programs that you frequently use, such as an email client or your music player. + +### Give it a try + +If you value simplicity and efficiency and are not afraid of working with the keyboard, i3 is the window manager for you. Some say it is for advanced users, but that is not necessarily the case. You need to learn a few basic shortcuts to get around at the beginning, but they'll soon feel natural and you'll start using them without thinking. + +This article just scratches the surface of what i3 can do. For more details, consult [i3's documentation][10]. + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/8/i3-tiling-window-manager + +作者:[Ricardo Gerardi][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://opensource.com/users/rgerardi +[1]:https://xfce.org/ +[2]:https://i3wm.org/ +[3]:https://code.google.com/archive/p/wmii/ +[4]:https://xmonad.org/ +[5]:/file/406476 +[6]:https://opensource.com/sites/default/files/uploads/i3_screenshot.png (i3 tiled window manager screenshot) +[7]:/file/405161 +[8]:https://opensource.com/sites/default/files/uploads/rofi_dunst.png (i3 with rofi menu and dunst desktop notifications) +[9]:https://i3wm.org/docs/ipc.html +[10]:https://i3wm.org/docs/userguide.html diff --git a/sources/tech/20180809 Getting started with Postfix, an open source mail transfer agent.md b/sources/tech/20180809 Getting started with Postfix, an open source mail transfer agent.md new file mode 100644 index 0000000000..a98065489d --- /dev/null +++ b/sources/tech/20180809 Getting started with Postfix, an open source mail transfer agent.md @@ -0,0 +1,334 @@ +Getting started with Postfix, an open source mail transfer agent +====== + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/email_mail_box_envelope_send.jpg?itok=bbJOPIWl) + +[Postfix][1] is a great program that routes and delivers email to accounts that are external to the system. It is currently used by approximately [33% of internet mail servers][2]. In this article, I'll explain how you can use Postfix to send mail using Gmail with two-factor authentication enabled. + +Before you get Postfix up and running, however, you need to have some items lined up. Following are instructions on how to get it working on a number of distros. + +### Prerequisites + + * An installed OS (Ubuntu/Debian/Fedora/Centos/Arch/FreeBSD/OpenSUSE) + * A Google account with two-factor authentication + * A working internet connection + + + +### Step 1: Prepare Google + +Open a web browser and log into your Google account. Once you’re in, go to your settings by clicking your picture and selecting "Google Account.” Click “Sign-in & security” and scroll down to "App passwords.” Use your password to log in. Then you can create a new app password (I named mine "postfix Setup”). + +![](https://opensource.com/sites/default/files/uploads/google_setup_1_app_passwords.png) + +Note the crazy password (shown below), which I will use throughout this article. + +![](https://opensource.com/sites/default/files/uploads/google_setup_2_generated_password.png) + +### Step 2: Install Postfix + +Before you can configure the mail client, you need to install it. You must also install either the `mailutils` or `mailx` utility, depending on the OS you're using. Here's how to install it for each OS: + +**Debian/Ubuntu** : +``` +apt-get update && apt-get install postfix mailutils + +``` + +**Fedora** : +``` +dnf update && dnf install postfix mailx + +``` + +**Centos** : +``` +yum update && yum install postfix mailx cyrus-sasl cyrus-sasl-plain + +``` + +**Arch** : +``` +pacman -Sy postfix mailutils + +``` + +**FreeBSD** : +``` +portsnap fetch extract update + +cd /usr/ports/mail/postfix + +make config + +``` + +In the configuration dialog, select "SASL support." All other options can remain the same. + +From there: `make install clean` + +Install `mailx` from the binary package: `pkg install mailx` + +**OpenSUSE** : +``` +zypper update && zypper install postfix mailx cyrus-sasl + +``` + +### Step 3: Set up Gmail authentication + +Once you've installed Postfix, you can set up Gmail authentication. Since you have created the app password, you need to put it in a configuration file and lock it down so no one else can see it. Fortunately, this is simple to do: + +**Ubuntu/Debian/Fedora/Centos/Arch/OpenSUSE** : +``` +vim /etc/postfix/sasl_passwd + +``` + +Add this line: +``` +[smtp.gmail.com]:587   ben.heffron@gmail.com:thgcaypbpslnvgce + +``` + +Save and close the file. Since your Gmail password is stored as plaintext, make the file accessible only by root to be extra safe. +``` +chmod 600 /etc/postfix/sasl_passwd + +``` + +**FreeBSD** : +``` +vim /usr/local/etc/postfix/sasl_passwd + +``` + +Add this line: +``` +[smtp.gmail.com]:587    ben.heffron@gmail.com:thgcaypbpslnvgce + +``` + +Save and close the file. Since your Gmail password is stored as plaintext, make the file accessible only by root to be extra safe. +``` +chmod 600 /usr/local/etc/postfix/sasl_passwd + +``` + +![](https://opensource.com/sites/default/files/uploads/google_setup_3_vim_config.png) + +### Step 4: Get Postfix moving + +This step is the "meat and potatoes"—everything you've done so far has been preparation. + +Postfix gets its configuration from the `main.cf` file, so the settings in this file are critical. For Google, it is mandatory to enable the correct SSL settings. + +Here are the six options you need to enter or update on the `main.cf` to make it work with Gmail (from the [SASL readme][3]): + + * The **smtp_sasl_auth_enable** setting enables client-side authentication. We will configure the client’s username and password information in the second part of the example. + * The **relayhost** setting forces the Postfix SMTP to send all remote messages to the specified mail server instead of trying to deliver them directly to their destination. + * With the **smtp_sasl_password_maps** parameter, we configure the Postfix SMTP client to send username and password information to the mail gateway server. + * Postfix SMTP client SASL security options are set using **smtp_sasl_security_options** , with a whole lot of options. In this case, it will be nothing; otherwise, Gmail won’t play nicely with Postfix. + * The **smtp_tls_CAfile** is a file containing CA certificates of root CAs trusted to sign either remote SMTP server certificates or intermediate CA certificates. + * From the [configure settings page:][4] **stmp_use_tls** uses TLS when a remote SMTP server announces STARTTLS support, the default is not using TLS. + + + +**Ubuntu/Debian/Arch** + +These three OSes keep their files (certificates and `main.cf`) in the same location, so this is all you need to put in there: +``` +vim /etc/postfix/main.cf + +``` + +If the following values aren’t there, add them: +``` +relayhost = [smtp.gmail.com]:587 + +smtp_use_tls = yes + +smtp_sasl_auth_enable = yes + +smtp_sasl_security_options = + +smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd + +smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt + +``` + +Save and close the file. + +**Fedora/CentOS** + +These two OSes are based on the same underpinnings, so they share the same updates. +``` +vim /etc/postfix/main.cf + +``` + +If the following values aren’t there, add them: +``` +relayhost = [smtp.gmail.com]:587 + +smtp_use_tls = yes + +smtp_sasl_auth_enable = yes + +smtp_sasl_security_options = + +smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd + +smtp_tls_CAfile = /etc/ssl/certs/ca-bundle.crt + +``` + +Save and close the file. + +**OpenSUSE** +``` +vim /etc/postfix/main.cf + +``` + +If the following values aren’t there, add them: +``` +relayhost = [smtp.gmail.com]:587 + +smtp_use_tls = yes + +smtp_sasl_auth_enable = yes + +smtp_sasl_security_options = + +smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd + +smtp_tls_CAfile = /etc/ssl/ca-bundle.pem + +``` + +Save and close the file. + +OpenSUSE also requires that you modify the Postfix master process configuration file `master.cf`. Open it for editing: +``` +vim /etc/postfix/master.cf + +``` + +Uncomment the line that reads: +``` +#tlsmgr unix - - n 1000? 1 tlsmg + +``` + +It should look like this: +``` +tlsmgr unix - - n 1000? 1 tlsmg + +``` + +Save and close the file. + +**FreeBSD** +``` +vim /usr/local/etc/postfix/main.cf + +``` + +If the following values aren’t there, add them: +``` +relayhost = [smtp.gmail.com]:587 + +smtp_use_tls = yes + +smtp_sasl_auth_enable = yes + +smtp_sasl_security_options = + +smtp_sasl_password_maps = hash:/usr/local/etc/postfix/sasl_passwd + +smtp_tls_CAfile = /etc/mail/certs/cacert.pem + +``` + +Save and close the file. + +### Step 5: Set up the password file + +Remember that password file you created? Now you need to feed it into Postfix using `postmap`. This is part of the `mailutils` or `mailx` utilities. + +**Debian, Ubuntu, Fedora, CentOS, OpenSUSE, Arch Linux** +``` +postmap /etc/postfix/sasl_passwd + +``` + +**FreeBSD** +``` +postmap /usr/local/etc/postfix/sasl_passwd + +``` + +### Step 6: Get Postfix grooving + +To get all the settings and configurations working, you must restart Postfix. + +**Debian, Ubuntu, Fedora, CentOS, OpenSUSE, Arch Linux** + +These guys make it simple to restart: +``` +systemctl restart postfix.service + +``` + +**FreeBSD** + +To start Postfix at startup, edit `/etc/rc.conf`: +``` +vim /etc/rc.conf + +``` + +Add the line: +``` +postfix_enable=YES + +``` + +Save and close the file. Then start Postfix by running: +``` +service postfix start + +``` + +### Step 7: Test it + +Now for the big finale—time to test it to see if it works. The `mail` command is another tool installed with `mailutils` or `mailx`. +``` +echo    Just testing my sendmail gmail relay" | mail -s "Sendmail gmail Relay" ben.heffron@gmail.com + +``` + +This is what I used to test my settings, and then it came up in my Gmail. + +![](https://opensource.com/sites/default/files/uploads/google_setup_4_gmail.png) + +Now you can use Gmail with two-factor authentication in your Postfix setup. + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/8/postfix-open-source-mail-transfer-agent + +作者:[Ben Heffron][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://opensource.com/users/elheffe +[1]:http://www.postfix.org/start.html +[2]:http://www.securityspace.com/s_survey/data/man.201806/mxsurvey.html +[3]:http://www.postfix.org/SASL_README.html +[4]:http://www.postfix.org/postconf.5.html#smtp_tls_security_level diff --git a/sources/tech/20180809 Perform robust unit tests with PyHamcrest.md b/sources/tech/20180809 Perform robust unit tests with PyHamcrest.md new file mode 100644 index 0000000000..1c7d7e9226 --- /dev/null +++ b/sources/tech/20180809 Perform robust unit tests with PyHamcrest.md @@ -0,0 +1,176 @@ +Perform robust unit tests with PyHamcrest +====== + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/web_browser_desktop_devlopment_design_system_computer.jpg?itok=pfqRrJgh) + +At the base of the [testing pyramid][1] are unit tests. Unit tests test one unit of code at a time—usually one function or method. + +Often, a single unit test is designed to test one particular flow through a function, or a specific branch choice. This enables easy mapping of a unit test that fails and the bug that made it fail. + +Ideally, unit tests use few or no external resources, isolating them and making them faster. + +_Good_ tests increase developer productivity by catching bugs early and making testing faster. _Bad_ tests decrease developer productivity. + +Unit test suites help maintain high-quality products by signaling problems early in the development process. An effective unit test catches bugs before the code has left the developer machine, or at least in a continuous integration environment on a dedicated branch. This marks the difference between good and bad unit tests:tests increase developer productivity by catching bugs early and making testing faster.tests decrease developer productivity. + +Productivity usually decreases when testing _incidental features_. The test fails when the code changes, even if it is still correct. This happens because the output is different, but in a way that is not part of the function's contract. + +A good unit test, therefore, is one that helps enforce the contract to which the function is committed. + +If a unit test breaks, the contract is violated and should be either explicitly amended (by changing the documentation and tests), or fixed (by fixing the code and leaving the tests as is). + +While limiting tests to enforce only the public contract is a complicated skill to learn, there are tools that can help. + +One of these tools is [Hamcrest][2], a framework for writing assertions. Originally invented for Java-based unit tests, today the Hamcrest framework supports several languages, including [Python][3]. + +Hamcrest is designed to make test assertions easier to write and more precise. +``` +def add(a, b): + +    return a + b + + + +from hamcrest import assert_that, equal_to + + + +def test_add(): + +    assert_that(add(2, 2), equal_to(4))   + +``` + +This is a simple assertion, for simple functionality. What if we wanted to assert something more complicated? +``` +def test_set_removal(): + +    my_set = {1, 2, 3, 4} + +    my_set.remove(3) + +    assert_that(my_set, contains_inanyorder([1, 2, 4])) + +    assert_that(my_set, is_not(has_item(3))) + +``` + +Note that we can succinctly assert that the result has `1`, `2`, and `4` in any order since sets do not guarantee order. + +We also easily negate assertions with `is_not`. This helps us write _precise assertions_ , which allow us to limit ourselves to enforcing public contracts of functions. + +Sometimes, however, none of the built-in functionality is _precisely_ what we need. In those cases, Hamcrest allows us to write our own matchers. + +Imagine the following function: +``` +def scale_one(a, b): + +    scale = random.randint(0, 5) + +    pick = random.choice([a,b]) + +    return scale * pick + +``` + +We can confidently assert that the result divides into at least one of the inputs evenly. + +A matcher inherits from `hamcrest.core.base_matcher.BaseMatcher`, and overrides two methods: +``` +class DivisibleBy(hamcrest.core.base_matcher.BaseMatcher): + + + +    def __init__(self, factor): + +        self.factor = factor + + + +    def _matches(self, item): + +        return (item % self.factor) == 0 + + + +    def describe_to(self, description): + +        description.append_text('number divisible by') + +        description.append_text(repr(self.factor)) + +``` + +Writing high-quality `describe_to` methods is important, since this is part of the message that will show up if the test fails. +``` +def divisible_by(num): + +    return DivisibleBy(num) + +``` + +By convention, we wrap matchers in a function. Sometimes this gives us a chance to further process the inputs, but in this case, no further processing is needed. +``` +def test_scale(): + +    result = scale_one(3, 7) + +    assert_that(result, + +                any_of(divisible_by(3), + +                       divisible_by(7))) + +``` + +Note that we combined our `divisible_by` matcher with the built-in `any_of` matcher to ensure that we test only what the contract commits to. + +While editing this article, I heard a rumor that the name "Hamcrest" was chosen as an anagram for "matches". Hrm... +``` +>>> assert_that("matches", contains_inanyorder(*"hamcrest") + +Traceback (most recent call last): + +  File "", line 1, in + +  File "/home/moshez/src/devops-python/build/devops/lib/python3.6/site-packages/hamcrest/core/assert_that.py", line 43, in assert_that + +    _assert_match(actual=arg1, matcher=arg2, reason=arg3) + +  File "/home/moshez/src/devops-python/build/devops/lib/python3.6/site-packages/hamcrest/core/assert_that.py", line 57, in _assert_match + +    raise AssertionError(description) + +AssertionError: + +Expected: a sequence over ['h', 'a', 'm', 'c', 'r', 'e', 's', 't'] in any order + +      but: no item matches: 'r' in ['m', 'a', 't', 'c', 'h', 'e', 's'] + +``` + +Researching more, I found the source of the rumor: It is an anagram for "matchers". +``` +>>> assert_that("matchers", contains_inanyorder(*"hamcrest")) + +>>> + +``` + +If you are not yet writing unit tests for your Python code, now is a good time to start. If you are writing unit tests for your Python code, using Hamcrest will allow you to make your assertion _precise_ —neither more nor less than what you intend to test. This will lead to fewer false positives when modifying code and less time spent modifying tests for working code. + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/8/robust-unit-tests-hamcrest + +作者:[Moshe Zadka][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://opensource.com/users/moshez +[1]:https://martinfowler.com/bliki/TestPyramid.html +[2]:http://hamcrest.org/ +[3]:https://www.python.org/ diff --git a/sources/tech/20180810 How To Quickly Serve Files And Folders Over HTTP In Linux.md b/sources/tech/20180810 How To Quickly Serve Files And Folders Over HTTP In Linux.md new file mode 100644 index 0000000000..c4adc3ac07 --- /dev/null +++ b/sources/tech/20180810 How To Quickly Serve Files And Folders Over HTTP In Linux.md @@ -0,0 +1,168 @@ +How To Quickly Serve Files And Folders Over HTTP In Linux +====== + +![](https://www.ostechnix.com/wp-content/uploads/2018/08/http-720x340.png) + +Today, I came across a whole bunch of methods to serve a single file or entire directory with other systems in your local area network via a web browser. I tested all of them in my Ubuntu test machine, and everything worked just fine as described below. If you ever wondered how to easily and quickly serve files and folders over HTTP in Unix-like operating systems, one of the following methods will definitely help. + +### Serve Files And Folders Over HTTP In Linux + +**Disclaimer:** All the methods given here are meant to be used within a secure local area network. Since these methods doesn’t have any security mechanism, it is **not recommended to use them in production**. You have been warned! + +#### Method 1 – Using simpleHTTPserver (Python) + +We already have written a brief guide to setup a simple http server to share files and directories instantly in the following link. If you have a system with Python installed, this method is quite handy. + +#### Method 2 – Using Quickserve (Python) + +This method is specifically for Arch Linux and its variants. Check the following link for more details. + +#### Method 3 – Using Ruby** + +In this method, we use Ruby to serve files and folders over HTTP in Unix-like systems. Install Ruby and Rails as described in the following link. + +Once Ruby installed, go to the directory, for example ostechnix, that you want to share over the network: +``` +$ cd ostechnix + +``` + +And, run the following command: +``` +$ ruby -run -ehttpd . -p8000 +[2018-08-10 16:02:55] INFO WEBrick 1.4.2 +[2018-08-10 16:02:55] INFO ruby 2.5.1 (2018-03-29) [x86_64-linux] +[2018-08-10 16:02:55] INFO WEBrick::HTTPServer#start: pid=5859 port=8000 + +``` + +Make sure the port 8000 is opened in your router or firewall . If the port has already been used by some other services use different port. + +You can now access the contents of this folder from any remote system using URL – **http:// :8000/**. + +![](https://www.ostechnix.com/wp-content/uploads/2018/08/ruby-http-server.png) + +To stop sharing press **CTRL+C**. + +#### Method 4 – Using Http-server (NodeJS) + +[**Http-server**][1] is a simple, production ready command line http-server written in NodeJS. It requires zero configuration and can be used to instantly share files and directories via web browser. + +Install NodeJS as described below. + +Once NodeJS installed, run the following command to install http-server. +``` +$ npm install -g http-server + +``` + +Now, go to any directory and share its contents over HTTP as shown below. +``` +$ cd ostechnix + +$ http-server -p 8000 +Starting up http-server, serving ./ +Available on: + http://127.0.0.1:8000 + http://192.168.225.24:8000 + http://192.168.225.20:8000 +Hit CTRL-C to stop the server + +``` + +Now, you can access the contents of this directory from local or remote systems in the network using URL – **http:// :8000**. + +![](http://www.ostechnix.com/wp-content/uploads/2018/08/nodejs-http-server.png) + +To stop sharing, press **CTRL+C**. + +#### Method 5 – Using Miniserve (Rust) + +[**Miniserve**][2] is yet another command line utility that allows you to quickly serve files over HTTP. It is very fast, easy-to-use, and cross-platform utility written in **Rust** programming language. Unlike the above utilities/methods, it provides authentication support, so you can setup username and password to the shares. + +Install Rust in your Linux system as described in the following link. + +After installing Rust, run the following command to install miniserve: +``` +$ cargo install miniserve + +``` + +Alternatively, you can download the binaries from [**the releases page**][3] and make it executable. +``` +$ chmod +x miniserve-linux + +``` + +And, then you can run it using command (assuming miniserve binary file is downloaded in the current working directory): +``` +$ ./miniserve-linux + +``` + +**Usage** + +To serve a directory: +``` +$ miniserve + +``` + +**Example:** +``` +$ miniserve /home/sk/ostechnix/ +miniserve v0.2.0 +Serving path /home/sk/ostechnix at http://[::]:8080, http://localhost:8080 +Quit by pressing CTRL-C + +``` + +Now, you can access the share from local system itself using URL – **** and/or from remote system with URL – **http:// :8080**. + +To serve a single file: +``` +$ miniserve + +``` + +**Example:** +``` +$ miniserve ostechnix/file.txt + +``` + +Serve file/folder with username and password: +``` +$ miniserve --auth joe:123 + +``` + +Bind to multiple interfaces: +``` +$ miniserve -i 192.168.225.1 -i 10.10.0.1 -i ::1 -- + +``` + +As you can see, I have given only 5 methods. But, there are few more methods given in the link attached at the end of this guide. Go and test them as well. Also, bookmark and revisit it from time to time to check if there are any new additions to the list in future. + +And, that’s all for now. Hope this was useful. More good stuffs to come. Stay tuned! + +Cheers! + + + +-------------------------------------------------------------------------------- + +via: https://www.ostechnix.com/how-to-quickly-serve-files-and-folders-over-http-in-linux/ + +作者:[SK][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.ostechnix.com/author/sk/ +[1]:https://www.npmjs.com/package/http-server +[2]:https://github.com/svenstaro/miniserve +[3]:https://github.com/svenstaro/miniserve/releases diff --git a/sources/tech/20180810 How To Remove Or Disable Ubuntu Dock.md b/sources/tech/20180810 How To Remove Or Disable Ubuntu Dock.md new file mode 100644 index 0000000000..65816f7d5c --- /dev/null +++ b/sources/tech/20180810 How To Remove Or Disable Ubuntu Dock.md @@ -0,0 +1,142 @@ +How To Remove Or Disable Ubuntu Dock +====== + +![](https://1.bp.blogspot.com/-pClnjEJfPQc/W21nHNzU2DI/AAAAAAAABV0/HGXuQOYGzokyrGYQtRFeF_hT3_3BKHupQCLcBGAs/s640/ubuntu-dock.png) + +**If you want to replace the Ubuntu Dock in Ubuntu 18.04 with some other dock (like Plank dock for example) or panel, and you want to remove or disable the Ubuntu Dock, here's what you can do and how.** + +Ubuntu Dock - the bar on the left-hand side of the screen which can be used to pin applications and access installed applications - + + +### How to access the Activities Overview without Ubuntu Dock + +Without Ubuntu Dock, you may have no way of accessing the Activities / installed application list (which can be accessed from Ubuntu Dock by clicking on Show Applications button at the bottom of the dock). For example if you want to use Plank dock. + +Obviously, that's not the case if you install Dash to Panel extension to use it instead Ubuntu Dock, because Dash to Panel provides a button to access the Activities Overview / installed applications. + +Depending on what you plan to use instead of Ubuntu Dock, if there's no way of accessing the Activities Overview, you can enable the Activities Overview Hot Corner option and simply move your mouse to the upper left corner of the screen to open the Activities. Another way of accessing the installed application list is using a keyboard shortcut: `Super + A` . + +If you want to enable the Activities Overview hot corner, use this command: +``` +gsettings set org.gnome.shell enable-hot-corners true + +``` + +If later you want to undo this and disable the hot corners, you need to use this command: +``` +gsettings set org.gnome.shell enable-hot-corners false + +``` + +You can also enable or disable the Activities Overview Hot Corner option by using the Gnome Tweaks application (the option is in the `Top Bar` section of Gnome Tweaks), which can be installed by using this command: +``` +sudo apt install gnome-tweaks + +``` + +### How to remove or disable Ubuntu Dock + +Below you'll find 4 ways of getting rid of Ubuntu Dock which work in Ubuntu 18.04. + +**Option 1: Remove the Gnome Shell Ubuntu Dock package.** + +The easiest way of getting rid of the Ubuntu Dock is to remove the package. + +This completely removes the Ubuntu Dock extension from your system, but it also removes the `ubuntu-desktop` meta package. There's no immediate issue if you remove the `ubuntu-desktop` meta package because does nothing by itself. The `ubuntu-meta` package depends on a large number of packages which make up the Ubuntu Desktop. Its dependencies won't be removed and nothing will break. The issue is that if you want to upgrade to a newer Ubuntu version, any new `ubuntu-desktop` dependencies won't be installed. + +As a way around this, you can simply install the `ubuntu-desktop` meta package before upgrading to a newer Ubuntu version (for example if you want to upgrade from Ubuntu 18.04 to 18.10). + +If you're ok with this and want to remove the Ubuntu Dock extension package from your system, use the following command: +``` +sudo apt remove gnome-shell-extension-ubuntu-dock + +``` + +If later you want to undo the changes, simply install the extension back using this command: +``` +sudo apt install gnome-shell-extension-ubuntu-dock + +``` + +Or to install the `ubuntu-desktop` meta package back (this will install any ubuntu-desktop dependencies you may have removed, including Ubuntu Dock), you can use this command: +``` +sudo apt install ubuntu-desktop + +``` + +**Option 2: Install and use the vanilla Gnome session instead of the default Ubuntu session.** + +Another way to get rid of Ubuntu Dock is to install and use the vanilla Gnome session. Installing the vanilla Gnome session will also install other packages this session depends on, like Gnome Documents, Maps, Music, Contacts, Photos, Tracker and more. + +By installing the vanilla Gnome session, you'll also get the default Gnome GDM login / lock screen theme instead of the Ubuntu defaults as well as Adwaita Gtk theme and icons. You can easily change the Gtk and icon theme though, by using the Gnome Tweaks application. + +Furthermore, the AppIndicators extension will be disabled by default (so applications that make use of the AppIndicators tray won't show up on the top panel), but you can enable this by using Gnome Tweaks (under Extensions, enable the Ubuntu appindicators extension). + +In the same way, you can also enable or disable Ubuntu Dock from the vanilla Gnome session, which is not possible if you use the Ubuntu session (disabling Ubuntu Dock from Gnome Tweaks when using the Ubuntu session does nothing). + +If you don't want to install these extra packages required by the vanilla Gnome session, this option of removing Ubuntu Dock is not for you so check out the other options. + +If you are ok with this though, here's what you need to do. To install the vanilla Gnome session in Ubuntu, use this command: +``` +sudo apt install vanilla-gnome-desktop + +``` + +After the installation finishes, reboot your system and on the login screen, after you click on your username, click the gear icon next to the `Sign in` button, and select `GNOME` instead of `Ubuntu` , then proceed to login: + +![](https://4.bp.blogspot.com/-mc-6H2MZ0VY/W21i_PIJ3pI/AAAAAAAABVo/96UvmRM1QJsbS2so1K8teMhsu7SdYh9zwCLcBGAs/s640/vanilla-gnome-session-ubuntu-login-screen.png) + +In case you want to undo this and remove the vanilla Gnome session, you can purge the vanilla Gnome package and then remove the dependencies it installed (second command) using the following commands: +``` +sudo apt purge vanilla-gnome-desktop +sudo apt autoremove + +``` + +Then reboot and select Ubuntu in the same way, from the GDM login screen. + +**Option 3: Permanently hide the Ubuntu Dock from your desktop instead of removing it.** + +If you prefer to permanently hide the Ubuntu Dock from showing up on your desktop instead of uninstalling it or using the vanilla Gnome session, you can easily do this using Dconf Editor. The drawback to this is that Ubuntu Dock will still use some system resources even though you're not using in on your desktop, but you'll also be able to easily revert this without installing or removing any packages. + +Ubuntu Dock is only hidden from your desktop though. When you go in overlay mode (Activities), you'll still see and be able to use Ubuntu Dock from there. + +To permanently hide Ubuntu Dock, use Dconf Editor to navigate to `/org/gnome/shell/extensions/dash-to-dock` and disable (set them to false) the following options: `autohide` , `dock-fixed` and `intellihide` . + +You can achieve this from the command line if you wish, buy running the commands below: +``` +gsettings set org.gnome.shell.extensions.dash-to-dock autohide false +gsettings set org.gnome.shell.extensions.dash-to-dock dock-fixed false +gsettings set org.gnome.shell.extensions.dash-to-dock intellihide false + +``` +In case you change your mind and you want to undo this, you can either use Dconf Editor and re-enable (set them to true) autohide, dock-fixed and intellihide from `/org/gnome/shell/extensions/dash-to-dock` , or you can use these commands: +``` +gsettings set org.gnome.shell.extensions.dash-to-dock autohide true +gsettings set org.gnome.shell.extensions.dash-to-dock dock-fixed true +gsettings set org.gnome.shell.extensions.dash-to-dock intellihide true + +``` + +**Option 4: Use Dash to Panel extension.** + +You can install Dash to Panel from + +If you change your mind and you want Ubuntu Dock back, you can either disable Dash to Panel by using Gnome Tweaks app, or completely remove Dash to Panel by clicking the X button next to it from here: + + +-------------------------------------------------------------------------------- + +via: https://www.linuxuprising.com/2018/08/how-to-remove-or-disable-ubuntu-dock.html + +作者:[Logix][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://plus.google.com/118280394805678839070 +[1]:https://bugs.launchpad.net/ubuntu/+source/gnome-tweak-tool/+bug/1713020 +[2]:https://www.linuxuprising.com/2018/05/gnome-shell-dash-to-panel-v14-brings.html +[3]:https://extensions.gnome.org/extension/1160/dash-to-panel/ diff --git a/sources/tech/20180810 Strawberry- Quality sound, open source music player.md b/sources/tech/20180810 Strawberry- Quality sound, open source music player.md new file mode 100644 index 0000000000..6cc72dccfb --- /dev/null +++ b/sources/tech/20180810 Strawberry- Quality sound, open source music player.md @@ -0,0 +1,105 @@ +Strawberry: Quality sound, open source music player +====== + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/video_editing_folder_music_wave_play.png?itok=-J9rs-My) + +I recently received an email from [Jonas Kvinge][1] who forked the [Clementine open source music player][2]. Jonas writes: + +I started working on a modified version of Clementine already in 2013, but because of other priorities, I did not pick up the work again before last year. I had not decided then if I was creating a fork, or contributing to Clementine. I ended up doing both. I started to see that I wanted the program development in a different direction. My focus was to create a music player for playing local music files, and not having to maintain support for multiple internet features that I did not use, and some which I did not want in the program at all… I also saw more and more that I disagree with the authors of Clementine and some statements that have been made regarding high-resolution audio. + +Jonas and I are definitely working from the same perspective, at least in relation to high-resolution music files. Back in late 2016, [I looked at Clementine][3], and though it was in many ways delightful, it definitely missed the boat with respect to working with a dedicated high-resolution digital-analog converter (DAC) for music enjoyment. But that’s OK; Clementine just wasn’t built for me. Nor, it appears, was it for Jonas. + +So, given that Jonas and I share an interest in being able to play back high-resolution audio on a dedicated listening device, I thought I’d best give [Strawberry][4], Jonas’ fork of Clementine, a try. I grabbed the [2018/07/16 release for Ubuntu][5] from Jonas’ site. It was a .deb and very straightforward to install. +``` +sudo dpkg -i strawberry_0.2.1-27-gb2c26eb_amd64.deb + +``` + +As usual, some necessary packages weren’t installed on my system, so I used `apt install -f` to remedy that. + +Apt recommended the following packages: +``` +graphicsmagick-dbg gxine xine-ui + +``` + +and installed the following packages: +``` +libgraphicsmagick-q16-3 libiso9660-10 liblastfm5-1 libqt5concurrent5 libvcdinfo0 libxine2 libxine2-bin libxine2-doc libxine2-ffmpeg libxine2-misc-plugins libxine2-plugins + +``` + +Once that was all in hand, I started up Strawberry and saw this: + +![](https://opensource.com/sites/default/files/uploads/1806-1_html_53455474cece6e43_0.png) + +I verified that I could point Strawberry at ALSA in general and at my dedicated DAC in particular. + +![](https://opensource.com/sites/default/files/uploads/1806-1_html_1b8f42a0fbbc251c_0.png) + +![](https://opensource.com/sites/default/files/uploads/1806-1_html_641ffad17267dec0_0.png) + +Then I was ready to update my collection, which took less than a minute (Clementine was similarly fast). + +The only thing I noticed that seemed a little odd was that Strawberry provided a software volume control, which isn’t of great interest to me (my hardware has a nice shiny knob on top for just that purpose). + +![](https://opensource.com/sites/default/files/uploads/1806-1_html_cb207c425e02621c_0.png) + +And then I got down to some quality listening. One of the things I found I liked right away is the status button (see the strawberry at the top left of the UI). This verifies the details of the currently playing track, as shown in the screen capture to the left. Note that the effective bit rate, bit rate, and word length are shown, as well as other useful information. + +The sound is glorious, as is customary with well-recorded high-resolution material (for those of you inclined to argue about the merits of high-resolution audio, before you post your opinions, whether pro or con, please read [this article][6], which actually treats the topic in a scientific fashion). + +What’s cool about Strawberry, besides audio quality? Well, it’s fun to see the spectrum analyzer operating on the bottom of the screen. The overall responsiveness is smooth and quick; the album cover slides up once the music starts. There isn’t a lot of wasted space in the UI. And, as Jonas says: + +For many people, Clementine will still be a better choice since it has features such as scrobbling and internet services, which Strawberry lacks and I do not plan to include. + +Evidently, this is a player focused on the quality of the music, rather than the quantity. I’ll be using this player more in the future; it’s right up my alley. + +### Fine sound collections + +On the topic of music, especially interesting and unusual music, many thanks to [Michael Lavorgna over at Audiostream][7], who mentions these two fine online sound collections: [Cultural Equity][8] and [Smithsonian Folkways Recordings][9]. What great sources for stuff that is of historical interest and just plain fun. + +Also thanks to Michael for reminding me about [Ektoplazm][10], a fine free music portal for those interested in “psytrance, techno, and downtempo music.” I’ve downloaded a few albums from this site in the past, and when the mood strikes, I really appreciate what it has to offer. It's especially wonderful that the music files are available in [FLAC][11]. + +### And more music… + +In my last article, I spent so much time building that I didn’t have any time for listening. But since then, I’ve been to my favorite record store and picked up four new albums, some of which came with downloads. First up is [Jon Hopkins’][12] [Singularity][12]. I’ve been picking up the odd Jon Hopkins album since [Linn Records][13] (by the way, a great site for Linux users to buy downloads since no bloatware is required) was experimenting with a more broad-based music offering and introduced me to Jon. Some of his work is [available on Bandcamp][14] these days (including Singularity) which is a fine Linux-friendly site. For me, this is a great album—not really ambient, not really beatless, not really anything except what it is. Huge powerful swaths of music, staggering bass. Great fun! Go listen on [Bandcamp][14]. + +And if, like me, you have bought a few [Putumayo Music][15] albums over the years, keep your eyes peeled for Putumayo’s absolutely wonderful vinyl LP release of [_Vintage Latino_][16]. This great LP of vintage salsa and cha-cha is also available there to buy as a CD; you can listen to [1:00 clips on Bandcamp][17]. + +[Bombino][18] was in town last night. I had other stuff to do, but a friend went to the concert and loved it. I have three of his albums now; the last two I purchased on that fine open source medium, the vinyl LP, which came with downloads as well. His most recent album, _Deran_ , is more than worth it; check it out on the link above. + + +Last but by no means least, I managed to find a copy of [Nils Frahm’s _All Melody_][19] on vinyl (which includes a download code). I’ve been enjoying the high-resolution digital version of this album that I bought earlier this year, but it’s great fun to have it on vinyl. + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/8/strawberry-new-open-source-music-player + +作者:[Chris Hermansen][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://opensource.com/users/clhermansen +[1]:https://github.com/jonaski +[2]:https://www.clementine-player.org/ +[3]:https://opensource.com/life/16/10/4-open-music-players-compared +[4]:http://www.strawbs.org/ +[5]:http://builds.jkvinge.net/ubuntu/bionic/strawberry_0.2.1-27-gb2c26eb_amd64.deb +[6]:http://www.aes.org/e-lib/browse.cfm?elib=18296 +[7]:https://www.audiostream.com/content/alan-lomax-17000-sound-recordings-online-free +[8]:http://research.culturalequity.org/audio-guide.jsp +[9]:https://folkways.si.edu/radio-and-playlists/smithsonian +[10]:http://www.ektoplazm.com/ +[11]:https://xiph.org/flac/ +[12]:https://pitchfork.com/reviews/albums/jon-hopkins-singularity/ +[13]:http://www.linnrecords.com/ +[14]:https://jonhopkins.bandcamp.com/album/singularity +[15]:https://www.putumayo.com/ +[16]:https://www.putumayo.com/product-page/vintage-latino +[17]:https://putumayo.bandcamp.com/album/vintage-latino +[18]:http://www.bombinomusic.com/ +[19]:https://www.youtube.com/watch?v=1PTj1qIqcWM diff --git a/sources/tech/20180810 Use Plank On Multiple Monitors Without Creating Multiple Docks With autoplank.md b/sources/tech/20180810 Use Plank On Multiple Monitors Without Creating Multiple Docks With autoplank.md new file mode 100644 index 0000000000..29164e3510 --- /dev/null +++ b/sources/tech/20180810 Use Plank On Multiple Monitors Without Creating Multiple Docks With autoplank.md @@ -0,0 +1,77 @@ +Use Plank On Multiple Monitors Without Creating Multiple Docks With autoplank +====== + +![](https://3.bp.blogspot.com/-BNHa6rP_kGk/W22cJrT3ghI/AAAAAAAABWA/TAKZgxJfYuwz-Me-M135-LWYl5qvs6cIwCLcBGAs/s640/plank-dock.png) + +**[autoplank][1] is a small tool written in Go which adds multi-monitor support to Plank dock without having to create [multiple][2] docks.** + +**When you move your mouse cursor to the bottom of a monitor, autoplank detect your mouse movement using** `xdotool` and it automatically moves Plank to that monitor. This tool **only works if Plank is set to run at the bottom of the screen** , at least for now. + +There's a slight delay until Plank actually shows up on the monitor where the mouse is though. The developer says this is intentional, to make sure you actually want to access Plank on that monitor. The time delay before showing plank is not currently configurable, but that may change in the future. + +autoplank should work with elementary OS, as well as any desktop environment or Linux distribution you use Plank dock on. + +Plank is a simple dock that shows icons of running applications / windows. The application allows pinning applications to the dock, and comes with a few built-in simple "docklets": a clipboard manager, clock, CPU monitor, show desktop and trash. To access its settings, hold down the `Ctrl` key while right clicking anywhere on the Plank dock, and then clicking on `Preferences` . + +Plank is used by default in elementary OS, but it can be used on any desktop environment or Linux distribution you wish. + +### Install autoplank + +On its GitHub page, it's mentioned that you need Go 1.8 or newer to build autoplank but I was able to successfully build it with Go 1.6 in Ubuntu 16.04 (elementary OS 0.4 Loki). + +The developer has said on + +**1\. Install required dependencies.** + +To build autoplank you'll need Go (`golang-go` in Debian, Ubuntu, elementary OS, etc.). To get the latest Git code you'll also need `git` , and for detecting the monitor on which you move the mose, you'll also need to install `xdotool` . + +Install these in Ubuntu, Debian, elementary OS and so on, by using this command: +``` +sudo apt install git golang-go xdotool + +``` + +**2\. Get the latest autoplank from[Git][1], build it, and install it in** `/usr/local/bin` : +``` +git clone https://github.com/abiosoft/autoplank +cd autoplank +go build -o autoplank +sudo mv autoplank /usr/local/bin/ + +``` + +You can remove the autoplank folder from your home directory now. + +When you want to uninstall autoplank, simply remove the `/usr/local/bin/autoplank` binary (`sudo rm /usr/local/bin/autoplank`). + +**3\. Add autoplank to startup.** + +If you want to try autoplank before adding it to startup or creating a systemd service for it, you can simply type `autoplank` in a terminal to start it. + +To have autoplank work between reboots, you'll need to add it to your startup applications. The exact steps for doing this depend on your desktop environments, so I won't tell you exactly how to do that for every desktop environment, but remember to use `/usr/local/bin/autoplank` as the executable in Startup Applications. + +In elementary OS, you can open `System Settings` , then in `Applications` , on the `Startup` tab, click the `+` button in the bottom left-hand side corner of the window, then add `/usr/local/bin/autoplank` in the `Type in a custom command` field: + +![](https://4.bp.blogspot.com/-hbh1PLDX-0A/W22eIhEQ1iI/AAAAAAAABWM/GkgrzaPPjA8CHnxF5L4UPPUG_vPa9VT-gCLcBGAs/s640/autoplank-startup-elementaryos.png) + +**Another way of using autoplank is by creating a systemd service for it, as explained[here][3].** Using a systemd service for autoplank has the advantage of restarting autoplank if it crashes for whatever reason. Use either the systemd service or add autoplank to your startup applications (don't use both). + +**4\. After you do this, logout, login and autoplank should be running so you can move the mouse at the bottom of a monitor to move Plank dock there.** + + +-------------------------------------------------------------------------------- + +via: https://www.linuxuprising.com/2018/08/use-plank-on-multiple-monitors-without.html + +作者:[Logix][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://plus.google.com/118280394805678839070 +[1]:https://github.com/abiosoft/autoplank +[2]:https://answers.launchpad.net/plank/+question/204593 +[3]:https://github.com/abiosoft/autoplank#optional-create-a-service +[4]:https://www.reddit.com/r/elementaryos/comments/95a879/autoplank_use_plank_on_multimonitor_setup/e3r9saq/ diff --git a/sources/tech/20180814 5 open source strategy and simulation games for Linux.md b/sources/tech/20180814 5 open source strategy and simulation games for Linux.md new file mode 100644 index 0000000000..1f7e94c22f --- /dev/null +++ b/sources/tech/20180814 5 open source strategy and simulation games for Linux.md @@ -0,0 +1,111 @@ +5 open source strategy and simulation games for Linux +====== + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/arcade_game_gaming.jpg?itok=84Rjk_32) + +Gaming has traditionally been one of Linux's weak points. That has changed somewhat in recent years thanks to Steam, GOG, and other efforts to bring commercial games to multiple operating systems, but those games are often not open source. Sure, the games can be played on an open source operating system, but that is not good enough for an open source purist. + +So, can someone who only uses free and open source software find games that are polished enough to present a solid gaming experience without compromising their open source ideals? Absolutely. While open source games are unlikely ever to rival some of the AAA commercial games developed with massive budgets, there are plenty of open source games, in many genres, that are fun to play and can be installed from the repositories of most major Linux distributions. Even if a particular game is not packaged for a particular distribution, it is usually easy to download the game from the project's website to install and play it. + +This article looks at strategy and simulation games. I have already written about [arcade-style games][1], [board & card games][2], [puzzle games][3], [racing & flying games][4], and [role-playing games][5]. + +### Freeciv + +![](https://opensource.com/sites/default/files/uploads/freeciv.png) + +[Freeciv][6] is an open source version of the [Civilization series][7] of computer games. Gameplay is most similar to the earlier games in the Civilization series, and Freeciv even has options to use Civilization 1 and Civilization 2 rule sets. Freeciv involves building cities, exploring the world map, developing technologies, and competing with other civilizations trying to do the same. Victory conditions include defeating all the other civilizations, developing a space colony, or hitting deadline if neither of the first two conditions are met. The game can be played against AI opponents or other human players. Different tile-sets are available to change the look of the game's map. + +To install Freeciv, run the following command: + + * On Fedora: `dnf install freeciv` + * On Debian/Ubuntu: `apt install freeciv` + + + +### MegaGlest + +![](https://opensource.com/sites/default/files/uploads/megaglest.png) + +[MegaGlest][8] is an open source real-time strategy game in the style of Blizzard Entertainment's [Warcraft][9] and [StarCraft][10] games. Players control one of several different factions, building structures and recruiting units to explore the map and battle their opponents. At the beginning of the match, a player can build only the most basic buildings and recruit the weakest units. To build and recruit better things, players must work their way up their factions technology tree by building structures and recruiting units that unlock more advanced options. Combat units will attack when enemy units come into range, but for optimal strategy, it is best to manage the battle directly by controlling the units. Simultaneously managing the construction of new structures, recruiting new units, and managing battles can be a challenge, but that is the point of a real-time strategy game. MegaGlest provides a nice variety of factions, so there are plenty of reasons to try new and different strategies. + +To install MegaGlest, run the following command: + + * On Fedora: `dnf install megaglest` + * On Debian/Ubuntu: `apt install megaglest` + + + +### OpenTTD + +![](https://opensource.com/sites/default/files/uploads/openttd.png) + +[OpenTTD][11] (see also [our review][12]) is an open source implementation of [Transport Tycoon Deluxe][13]. The object of the game is to create a transportation network and earn money, which allows the player to build an even bigger transportation network. The network can include boats, buses, trains, trucks, and planes. By default, gameplay takes place between 1950 and 2050, with players aiming to get the highest performance rating possible before time runs out. The performance rating is based on things like the amount of cargo delivered, the number of vehicles they have, and how much money they earned. + +To install OpenTTD, run the following command: + + * On Fedora: `dnf install openttd` + * On Debian/Ubuntu: `apt install openttd` + + + +### The Battle for Wesnoth + +![](https://opensource.com/sites/default/files/uploads/the_battle_for_wesnoth.png) + +[The Battle for Wesnoth][14] is one of the most polished open source games available. This turn-based strategy game has a fantasy setting. Play takes place on a hexagonal grid, where individual units battle each other for control. Each type of unit has unique strengths and weaknesses, which requires players to plan their attacks accordingly. There are many different campaigns available for The Battle for Wesnoth, each with different objectives and storylines. The Battle for Wesnoth also comes with a map editor for players interested in creating their own maps or campaigns. + +To install The Battle for Wesnoth, run the following command: + + * On Fedora: `dnf install wesnoth` + * On Debian/Ubuntu: `apt install wesnoth` + + + +### UFO: Alien Invasion + +![](https://opensource.com/sites/default/files/uploads/ufo_alien_invasion.png) + +[UFO: Alien Invasion][15] is an open source tactical strategy game inspired by the [X-COM series][20]. There are two distinct gameplay modes: geoscape and tactical. In geoscape mode, the player takes control of the big picture and deals with managing their bases, researching new technologies, and controlling overall strategy. In tactical mode, the player controls a squad of soldiers and directly confronts the alien invaders in a turn-based battle. Both modes provide different gameplay styles, but both require complex strategy and tactics. + +To install UFO: Alien Invasion, run the following command: + + * On Debian/Ubuntu: `apt install ufoai` + + + +Unfortunately, UFO: Alien Invasion is not packaged for Fedora. + +Did I miss one of your favorite open source strategy or simulation games? Share it in the comments below. + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/8/strategy-simulation-games-linux + +作者:[Joshua Allen Holm][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://opensource.com/users/holmja +[1]:https://opensource.com/article/18/1/arcade-games-linux +[2]:https://opensource.com/article/18/3/card-board-games-linux +[3]:https://opensource.com/article/18/6/puzzle-games-linux +[4]:https://opensource.com/article/18/7/racing-flying-games-linux +[5]:https://opensource.com/article/18/8/role-playing-games-linux +[6]:http://www.freeciv.org/ +[7]:https://en.wikipedia.org/wiki/Civilization_(series) +[8]:https://megaglest.org/ +[9]:https://en.wikipedia.org/wiki/Warcraft +[10]:https://en.wikipedia.org/wiki/StarCraft +[11]:https://www.openttd.org/ +[12]:https://opensource.com/life/15/7/linux-game-review-openttd +[13]:https://en.wikipedia.org/wiki/Transport_Tycoon#Transport_Tycoon_Deluxe +[14]:https://www.wesnoth.org/ +[15]:https://ufoai.org/ +[16]:https://opensource.com/downloads/cheat-sheets?intcmp=7016000000127cYAAQ +[17]:https://opensource.com/alternatives?intcmp=7016000000127cYAAQ +[18]:https://opensource.com/tags/linux?intcmp=7016000000127cYAAQ +[19]:https://developers.redhat.com/cheat-sheets/advanced-linux-commands/?intcmp=7016000000127cYAAQ +[20]:https://en.wikipedia.org/wiki/X-COM diff --git a/sources/tech/20180814 HTTP request routing and validation with gorilla-mux.md b/sources/tech/20180814 HTTP request routing and validation with gorilla-mux.md new file mode 100644 index 0000000000..410f692ad9 --- /dev/null +++ b/sources/tech/20180814 HTTP request routing and validation with gorilla-mux.md @@ -0,0 +1,674 @@ +HTTP request routing and validation with gorilla/mux +====== + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/data_metrics_analytics_desktop_laptop.png?itok=9QXd7AUr) + +The Go networking library includes the `http.ServeMux` structure type, which supports HTTP request multiplexing (routing): A web server routes an HTTP request for a hosted resource, with a URI such as /sales4today, to a code handler; the handler performs the appropriate logic before sending an HTTP response, typically an HTML page. Here’s a sketch of the architecture: +``` +                 +------------+     +--------+     +---------+ +HTTP request---->| web server |---->| router |---->| handler | +                 +------------+     +--------+     +---------+ +``` + +In a call to the `ListenAndServe` method to start an HTTP server +``` +http.ListenAndServe(":8888", nil) // args: port & router +``` + +a second argument of `nil` means that the `DefaultServeMux` is used for request routing. + +The `gorilla/mux` package has a `mux.Router` type as an alternative to either the `DefaultServeMux` or a customized request multiplexer. In the `ListenAndServe` call, a `mux.Router` instance would replace `nil` as the second argument. What makes the `mux.Router` so appealing is best shown through a code example: + +### 1\. A sample crud web app + +The crud web application (see below) supports the four CRUD (Create Read Update Delete) operations, which match four HTTP request methods: POST, GET, PUT, and DELETE, respectively. In the crud app, the hosted resource is a list of cliche pairs, each a cliche and a conflicting cliche such as this pair: +``` +Out of sight, out of mind. Absence makes the heart grow fonder. + +``` + +New cliche pairs can be added, and existing ones can be edited or deleted. + +**The crud web app** +``` +package main + +import ( +   "gorilla/mux" +   "net/http" +   "fmt" +   "strconv" +) + +const GETALL string = "GETALL" +const GETONE string = "GETONE" +const POST string   = "POST" +const PUT string    = "PUT" +const DELETE string = "DELETE" + +type clichePair struct { +   Id      int +   Cliche  string +   Counter string +} + +// Message sent to goroutine that accesses the requested resource. +type crudRequest struct { +   verb     string +   cp       *clichePair +   id       int +   cliche   string +   counter  string +   confirm  chan string +} + +var clichesList = []*clichePair{} +var masterId = 1 +var crudRequests chan *crudRequest + +// GET / +// GET /cliches +func ClichesAll(res http.ResponseWriter, req *http.Request) { +   cr := &crudRequest{verb: GETALL, confirm: make(chan string)} +   completeRequest(cr, res, "read all") +} + +// GET /cliches/id +func ClichesOne(res http.ResponseWriter, req *http.Request) { +   id := getIdFromRequest(req) +   cr := &crudRequest{verb: GETONE, id: id, confirm: make(chan string)} +   completeRequest(cr, res, "read one") +} + +// POST /cliches + +func ClichesCreate(res http.ResponseWriter, req *http.Request) { + +   cliche, counter := getDataFromRequest(req) + +   cp := new(clichePair) + +   cp.Cliche = cliche + +   cp.Counter = counter + +   cr := &crudRequest{verb: POST, cp: cp, confirm: make(chan string)} + +   completeRequest(cr, res, "create") + +} + + + +// PUT /cliches/id + +func ClichesEdit(res http.ResponseWriter, req *http.Request) { + +   id := getIdFromRequest(req) + +   cliche, counter := getDataFromRequest(req) + +   cr := &crudRequest{verb: PUT, id: id, cliche: cliche, counter: counter, confirm: make(chan string)} + +   completeRequest(cr, res, "edit") + +} + + + +// DELETE /cliches/id + +func ClichesDelete(res http.ResponseWriter, req *http.Request) { + +   id := getIdFromRequest(req) + +   cr := &crudRequest{verb: DELETE, id: id, confirm: make(chan string)} + +   completeRequest(cr, res, "delete") + +} + + + +func completeRequest(cr *crudRequest, res http.ResponseWriter, logMsg string) { + +   crudRequests<-cr + +   msg := <-cr.confirm + +   res.Write([]byte(msg)) + +   logIt(logMsg) + +} + + + +func main() { + +   populateClichesList() + + + +   // From now on, this gorountine alone accesses the clichesList. + +   crudRequests = make(chan *crudRequest, 8) + +   go func() { // resource manager + +      for { + +         select { + +         case req := <-crudRequests: + +         if req.verb == GETALL { + +            req.confirm<-readAll() + +         } else if req.verb == GETONE { + +            req.confirm<-readOne(req.id) + +         } else if req.verb == POST { + +            req.confirm<-addPair(req.cp) + +         } else if req.verb == PUT { + +            req.confirm<-editPair(req.id, req.cliche, req.counter) + +         } else if req.verb == DELETE { + +            req.confirm<-deletePair(req.id) + +         } + +      } + +   }() + +   startServer() + +} + + + +func startServer() { + +   router := mux.NewRouter() + + + +   // Dispatch map for CRUD operations. + +   router.HandleFunc("/", ClichesAll).Methods("GET") + +   router.HandleFunc("/cliches", ClichesAll).Methods("GET") + +   router.HandleFunc("/cliches/{id:[0-9]+}", ClichesOne).Methods("GET") + + + +   router.HandleFunc("/cliches", ClichesCreate).Methods("POST") + +   router.HandleFunc("/cliches/{id:[0-9]+}", ClichesEdit).Methods("PUT") + +   router.HandleFunc("/cliches/{id:[0-9]+}", ClichesDelete).Methods("DELETE") + + + +   http.Handle("/", router) // enable the router + + + +   // Start the server. + +   port := ":8888" + +   fmt.Println("\nListening on port " + port) + +   http.ListenAndServe(port, router); // mux.Router now in play + +} + + + +// Return entire list to requester. + +func readAll() string { + +   msg := "\n" + +   for _, cliche := range clichesList { + +      next := strconv.Itoa(cliche.Id) + ": " + cliche.Cliche + "  " + cliche.Counter + "\n" + +      msg += next + +   } + +   return msg + +} + + + +// Return specified clichePair to requester. + +func readOne(id int) string { + +   msg := "\n" + "Bad Id: " + strconv.Itoa(id) + "\n" + + + +   index := findCliche(id) + +   if index >= 0 { + +      cliche := clichesList[index] + +      msg = "\n" + strconv.Itoa(id) + ": " + cliche.Cliche + "  " + cliche.Counter + "\n" + +   } + +   return msg + +} + + + +// Create a new clichePair and add to list + +func addPair(cp *clichePair) string { + +   cp.Id = masterId + +   masterId++ + +   clichesList = append(clichesList, cp) + +   return "\nCreated: " + cp.Cliche + " " + cp.Counter + "\n" + +} + + + +// Edit an existing clichePair + +func editPair(id int, cliche string, counter string) string { + +   msg := "\n" + "Bad Id: " + strconv.Itoa(id) + "\n" + +   index := findCliche(id) + +   if index >= 0 { + +      clichesList[index].Cliche = cliche + +      clichesList[index].Counter = counter + +      msg = "\nCliche edited: " + cliche + " " + counter + "\n" + +   } + +   return msg + +} + + + +// Delete a clichePair + +func deletePair(id int) string { + +   idStr := strconv.Itoa(id) + +   msg := "\n" + "Bad Id: " + idStr + "\n" + +   index := findCliche(id) + +   if index >= 0 { + +      clichesList = append(clichesList[:index], clichesList[index + 1:]...) + +      msg = "\nCliche " + idStr + " deleted\n" + +   } + +   return msg + +} + + + +//*** utility functions + +func findCliche(id int) int { + +   for i := 0; i < len(clichesList); i++ { + +      if id == clichesList[i].Id { + +         return i; + +      } + +   } + +   return -1 // not found + +} + + + +func getIdFromRequest(req *http.Request) int { + +   vars := mux.Vars(req) + +   id, _ := strconv.Atoi(vars["id"]) + +   return id + +} + + + +func getDataFromRequest(req *http.Request) (string, string) { + +   // Extract the user-provided data for the new clichePair + +   req.ParseForm() + +   form := req.Form + +   cliche := form["cliche"][0]    // 1st and only member of a list + +   counter := form["counter"][0]  // ditto + +   return cliche, counter + +} + + + +func logIt(msg string) { + +   fmt.Println(msg) + +} + + + +func populateClichesList() { + +   var cliches = []string { + +      "Out of sight, out of mind.", + +      "A penny saved is a penny earned.", + +      "He who hesitates is lost.", + +   } + +   var counterCliches = []string { + +      "Absence makes the heart grow fonder.", + +      "Penny-wise and dollar-foolish.", + +      "Look before you leap.", + +   } + + + +   for i := 0; i < len(cliches); i++ { + +      cp := new(clichePair) + +      cp.Id = masterId + +      masterId++ + +      cp.Cliche = cliches[i] + +      cp.Counter = counterCliches[i] + +      clichesList = append(clichesList, cp) + +   } + +} + +``` + +To focus on request routing and validation, the crud app does not use HTML pages as responses to requests. Instead, requests result in plaintext response messages: A list of the cliche pairs is the response to a GET request, confirmation that a new cliche pair has been added to the list is a response to a POST request, and so on. This simplification makes it easy to test the app, in particular, the `gorilla/mux` components, with a command-line utility such as [curl][1]. + +The `gorilla/mux` package can be installed from [GitHub][2]. The crud app runs indefinitely; hence, it should be terminated with a Control-C or equivalent. The code for the crud app, together with a README and sample curl tests, is available on [my website][3]. + +### 2\. Request routing + +The `mux.Router` extends REST-style routing, which gives equal weight to the HTTP method (e.g., GET) and the URI or path at the end of a URL (e.g., /cliches). The URI serves as the noun for the HTTP verb (method). For example, in an HTTP request a startline such as +``` +GET /cliches + +``` + +means get all of the cliche pairs, whereas a startline such as +``` +POST /cliches + +``` + +means create a cliche pair from data in the HTTP body. + +In the crud web app, there are five functions that act as request handlers for five variations of an HTTP request: +``` +ClichesAll(...)    # GET: get all of the cliche pairs + +ClichesOne(...)    # GET: get a specified cliche pair + +ClichesCreate(...) # POST: create a new cliche pair + +ClichesEdit(...)   # PUT: edit an existing cliche pair + +ClichesDelete(...) # DELETE: delete a specified cliche pair + +``` + +Each function takes two arguments: an `http.ResponseWriter` for sending a response back to the requester, and a pointer to an `http.Request`, which encapsulates information from the underlying HTTP request. The `gorilla/mux` package makes it easy to register these request handlers with the web server, and to perform regex-based validation. + +The `startServer` function in the crud app registers the request handlers. Consider this pair of registrations, with `router` as a `mux.Router` instance: +``` +router.HandleFunc("/", ClichesAll).Methods("GET") + +router.HandleFunc("/cliches", ClichesAll).Methods("GET") + +``` + +These statements mean that a GET request for either the single slash / or /cliches should be routed to the `ClichesAll` function, which then handles the request. For example, the curl request (with % as the command-line prompt) +``` +% curl --request GET localhost:8888/ + +``` + +produces this response: +``` +1: Out of sight, out of mind.  Absence makes the heart grow fonder. + +2: A penny saved is a penny earned.  Penny-wise and dollar-foolish. + +3: He who hesitates is lost.  Look before you leap. + +``` + +The three cliche pairs are the initial data in the crud app. + +In this pair of registration statements +``` +router.HandleFunc("/cliches", ClichesAll).Methods("GET") + +router.HandleFunc("/cliches", ClichesCreate).Methods("POST") + +``` + +the URI is the same (/cliches) but the verbs differ: GET in the first case, and POST in the second. This registration exemplifies REST-style routing because the difference in the verbs alone suffices to dispatch the requests to two different handlers. + +More than one HTTP method is allowed in a registration, although this strains the spirit of REST-style routing: +``` +router.HandleFunc("/cliches", DoItAll).Methods("POST", "GET") + +``` + +HTTP requests can be routed on features besides the verb and the URI. For example, the registration +``` +router.HandleFunc("/cliches", ClichesCreate).Schemes("https").Methods("POST") + +``` + +requires HTTPS access for a POST request to create a new cliche pair. In similar fashion, a registration might require a request to have a specified HTTP header element (e.g., an authentication credential). + +### 3\. Request validation + +The `gorilla/mux` package takes an easy, intuitive approach to request validation through regular expressions. Consider this request handler for a get one operation: +``` +router.HandleFunc("/cliches/{id:[0-9]+}", ClichesOne).Methods("GET") + +``` + +This registration rules out HTTP requests such as +``` +% curl --request GET localhost:8888/cliches/foo + +``` + +because foo is not a decimal numeral. The request results in the familiar 404 (Not Found) status code. Including the regex pattern in this handler registration ensures that the `ClichesOne` function is called to handle a request only if the request URI ends with a decimal integer value: +``` +% curl --request GET localhost:8888/cliches/3  # ok + +``` + +As a second example, consider the request +``` +% curl --request PUT --data "..." localhost:8888/cliches + +``` + +This request results in a status code of 405 (Bad Method) because the /cliches URI is registered, in the crud app, only for GET and POST requests. A PUT request, like a GET one request, must include a numeric id at the end of the URI: +``` +router.HandleFunc("/cliches/{id:[0-9]+}", ClichesEdit).Methods("PUT") + +``` + +### 4\. Concurrency issues + +The `gorilla/mux` router executes each call to a registered request handler as a separate goroutine, which means that concurrency is baked into the package. For example, if there are ten simultaneous requests such as +``` +% curl --request POST --data "..." localhost:8888/cliches + +``` + +then the `mux.Router` launches ten goroutines to execute the `ClichesCreate` handler. + +Of the five request operations GET all, GET one, POST, PUT, and DELETE, the last three alter the requested resource, the shared `clichesList` that houses the cliche pairs. Accordingly, the crudapp needs to guarantee safe concurrency by coordinating access to the `clichesList`. In different but equivalent terms, the crud app must prevent a race condition on the `clichesList`. In a production environment, a database system might be used to store a resource such as the `clichesList`, and safe concurrency then could be managed through database transactions. + +The crud app takes the recommended Go approach to safe concurrency: + + * Only a single goroutine, the resource manager started in the crud app `startServer` function, has access to the `clichesList` once the web server starts listening for requests. + * The request handlers such as `ClichesCreate` and `ClichesAll` send a (pointer to) a `crudRequest` instance to a Go channel (thread-safe by default), and the resource manager alone reads from this channel. The resource manager then performs the requested operation on the `clichesList`. + + + +The safe-concurrency architecture can be sketched as follows: +``` +                 crudRequest                   read/write + +request handlers------------->resource manager------------>clichesList + +``` + +With this architecture, no explicit locking of the `clichesList` is needed because only one goroutine, the resource manager, accesses the `clichesList` once CRUD requests start coming in. + +To keep the crud app as concurrent as possible, it’s essential to have an efficient division of labor between the request handlers, on the one side, and the single resource manager, on the other side. Here, for review, is the `ClichesCreate` request handler: +``` +func ClichesCreate(res http.ResponseWriter, req *http.Request) { + +   cliche, counter := getDataFromRequest(req) + +   cp := new(clichePair) + +   cp.Cliche = cliche + +   cp.Counter = counter + +   cr := &crudRequest{verb: POST, cp: cp, confirm: make(chan string)} + +   completeRequest(cr, res, "create") + +}ClichesCreateres httpResponseWriterreqclichecountergetDataFromRequestreqcpclichePaircpClicheclichecpCountercountercr&crudRequestverbPOSTcpcpconfirmcompleteRequestcrres + +``` + +`ClichesCreate` calls the utility function `getDataFromRequest`, which extracts the new cliche and counter-cliche from the POST request. The `ClichesCreate` function then creates a new `ClichePair`, sets two fields, and creates a `crudRequest` to be sent to the single resource manager. This request includes a confirmation channel, which the resource manager uses to return information back to the request handler. All of the setup work can be done without involving the resource manager because the `clichesList` is not being accessed yet. + +The request handlercalls the utility function, which extracts the new cliche and counter-cliche from the POST request. Thefunction then creates a new, sets two fields, and creates ato be sent to the single resource manager. This request includes a confirmation channel, which the resource manager uses to return information back to the request handler. All of the setup work can be done without involving the resource manager because theis not being accessed yet. + +The `completeRequest` utility function called at the end of the `ClichesCreate` function and the other request handlers +``` +completeRequest(cr, res, "create") // shown above + +``` + +brings the resource manager into play by putting a `crudRequest` into the `crudRequests` channel: +``` +func completeRequest(cr *crudRequest, res http.ResponseWriter, logMsg string) { + +   crudRequests<-cr          // send request to resource manager + +   msg := <-cr.confirm       // await confirmation string + +   res.Write([]byte(msg))    // send confirmation back to requester + +   logIt(logMsg)             // print to the standard output + +} + +``` + +For a POST request, the resource manager calls the utility function `addPair`, which changes the `clichesList` resource: +``` +func addPair(cp *clichePair) string { + +   cp.Id = masterId  // assign a unique ID + +   masterId++        // update the ID counter + +   clichesList = append(clichesList, cp) // update the list + +   return "\nCreated: " + cp.Cliche + " " + cp.Counter + "\n" + +} + +``` + +The resource manager calls similar utility functions for the other CRUD operations. It’s worth repeating that the resource manager is the only goroutine to read or write the `clichesList` once the web server starts accepting requests. + +For web applications of any type, the `gorilla/mux` package provides request routing, request validation, and related services in a straightforward, intuitive API. The crud web app highlights the package’s main features. Give the package a test drive, and you’ll likely be a buyer. + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/8/http-request-routing-validation-gorillamux + +作者:[Marty Kalin][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://opensource.com/users/mkalindepauledu +[1]:https://curl.haxx.se/ +[2]:https://github.com/gorilla/mux +[3]:http://condor.depaul.edu/mkalin diff --git a/sources/tech/20180814 Top Linux developers- recommended programming books.md b/sources/tech/20180814 Top Linux developers- recommended programming books.md new file mode 100644 index 0000000000..d9337ed319 --- /dev/null +++ b/sources/tech/20180814 Top Linux developers- recommended programming books.md @@ -0,0 +1,95 @@ +Top Linux developers' recommended programming books +====== +Without question, Linux was created by brilliant programmers who employed good computer science knowledge. Let the Linux programmers whose names you know share the books that got them started and the technology references they recommend for today's developers. How many of them have you read? + +Linux is, arguably, the operating system of the 21st century. While Linus Torvalds made a lot of good business and community decisions in building the open source community, the primary reason networking professionals and developers adopted Linux is the quality of its code and its usefulness. While Torvalds is a programming genius, he has been assisted by many other brilliant developers. + +I asked Torvalds and other top Linux developers which books helped them on their road to programming excellence. This is what they told me. + +### By shining C + +Linux was developed in the 1990s, as were other fundamental open source applications. As a result, the tools and languages the developers used reflected the times, which meant a lot of C programming language. While [C is no longer as popular][1], for many established developers it was their first serious language, which is reflected in their choice of influential books. + +“You shouldn't start programming with the languages I started with or the way I did,” says Torvalds. He started with BASIC, moved on to machine code (“not even assembly language, actual ‘just numbers’ machine code,” he explains), then assembly language and C. + +“None of those languages are what anybody should begin with anymore,” Torvalds says. “Some of them make no sense at all today (BASIC and machine code). And while C is still a major language, I don't think you should begin with it.” + +It's not that he dislikes C. After all, Linux is written in [GNU C][2]. "I still think C is a great language with a pretty simple syntax and is very good for many things,” he says. But the effort to get started with it is much too high for it to be a good beginner language by today's standards. “I suspect you'd just get frustrated. Going from your first ‘Hello World’ program to something you might actually use is just too big of a step." + +From that era, the only programming book that stood out for Torvalds is Brian W. Kernighan and Dennis M. Ritchie's [C Programming Language][3], known in serious programming circles as K&R. “It was small, clear, concise,” he explains. “But you need to already have a programming background to appreciate it." + +Torvalds is not the only open source developer to recommend K&R. Several others cite their well-thumbed copies as influential references, among them Wim Coekaerts, senior vice president for Linux and virtualization development at Oracle; Linux developer Alan Cox; Google Cloud CTO Brian Stevens; and Pete Graner, Canonical's vice president of technical operations. + +If you want to tackle C today, Jeremy Allison, co-founder of Samba, recommends [21st Century C][4]. Then, Allison suggests, follow it up with the older but still thorough [Expert C Programming][5] as well as the 20-year-old [Programming with POSIX Threads][6]. + +### If not C, what? + +Linux developers’ recommendations for current programming books naturally are an offshoot of the tools and languages they think are most suitable for today’s development projects. They also reflect the developers’ personal preferences. For example, Allison thinks young developers would be well served by learning Go with the help of [The Go Programming Language][7] and Rust with [Programming Rust][8]. + +But it may make sense to think beyond programming languages (and thus books to teach you their techniques). To do something meaningful today, “start from some environment with a toolkit that does 99 percent of the obscure details for you, so that you can script things around it," Torvalds recommends. + +"Honestly, the language itself isn't nearly as important as the infrastructure around it,” he continues. “Maybe you'd start with Java or Kotlin—not because of those languages per se, but because you want to write an app for your phone and the Android SDK ends up making those better choices. Or, maybe you're interested in games, so you start with one of the game engines, which often have some scripting language of their own." + +That infrastructure includes programming books specific to the operating system itself. Graner followed K&R by reading W. Richard Stevens' [Unix Network Programming][10] books. In particular, Stevens' [TCP/IP Illustrated, Volume 1: The Protocols][11] is considered still relevant even though it's almost 30 years old. Because Linux development is largely [relevant to networking infrastructure][12], Graner also recommends the many O’Reilly books on [Sendmail][13], [Bash][14], [DNS][15], and [IMAP/POP][16]. + +Coekaerts is also fond of Maurice Bach's [The Design of the Unix Operating System][17]. So is James Bottomley, a Linux kernel developer who used Bach's tome to pull apart Linux when the OS was new. + +### Design knowledge never goes stale + +But even that may be too tech-specific. "All developers should start with design before syntax,” says Stevens. “[The Design of Everyday Things][18] is one of my favorites.” + +Coekaerts likes Kernighan and Rob Pike's [The Practice of Programming][19]. The design-practice book wasn't around when Coekaerts was in school, “but I recommend it to everyone to read," he says. + +Whenever you ask serious long-term developers about their favorite books, sooner or later someone's going to mention Donald Knuth’s [The Art of Computer Programming][20]. Dirk Hohndel, VMware's chief open source officer, considers it timeless though, admittedly, “not necessarily super-useful today." + +### Read code. Lots of code + +While programming books can teach you a lot, don’t miss another opportunity that is unique to the open source community: [reading the code][21]. There are untold megabytes of examples of how to solve a given programming problem—and how you can get in trouble, too. Stevens says his No. 1 “book” for honing programming skills is having access to the Unix source code. + +Don’t overlook the opportunity to learn in person, too. “I learned BASIC by being in a computer club with other people all learning together,” says Cox. “In my opinion, that is still by far the best way to learn." He learned machine code from [Mastering Machine Code on Your ZX81][22] and the Honeywell L66 B compiler manuals, but working with other developers made a big difference. + +“I still think the way to learn best remains to be with a group of people having fun and trying to solve a problem you care about together,” says Cox. “It doesn't matter if you are 5 or 55." + +What struck me the most about these recommendations is how often the top Linux developers started at a low level—not just C or assembly language but machine language. Obviously, it’s been very useful in helping developers understand how computing works at a very basic level. + +So, ready to give hard-core Linux development a try? Greg Kroah-Hartman, the Linux stable branch kernel maintainer, recommends Steve Oualline's [Practical C Programming][23] and Samuel Harbison and Guy Steele's [C: A Reference Manual][24]. Next, read "[HOWTO do Linux kernel development][25]." Then, says Kroah-Hartman, you'll be ready to start. + +In the meantime, study hard, program lots, and best of luck to you in following the footsteps of Linux's top programmers. + +-------------------------------------------------------------------------------- + +via: https://www.hpe.com/us/en/insights/articles/top-linux-developers-recommended-programming-books-1808.html + +作者:[Steven Vaughan-Nichols][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.hpe.com/us/en/insights/contributors/steven-j-vaughan-nichols.html +[1]:https://www.codingdojo.com/blog/7-most-in-demand-programming-languages-of-2018/ +[2]:https://www.gnu.org/software/gnu-c-manual/ +[3]:https://amzn.to/2nhyjEO +[4]:https://amzn.to/2vsL8k9 +[5]:https://amzn.to/2KBbWn9 +[6]:https://amzn.to/2M0rfeR +[7]:https://amzn.to/2nhyrnMe +[8]:http://shop.oreilly.com/product/0636920040385.do +[9]:https://www.hpe.com/us/en/resources/storage/containers-for-dummies.html?jumpid=in_510384402_linuxbooks_containerebook0818 +[10]:https://amzn.to/2MfpbyC +[11]:https://amzn.to/2MpgrTn +[12]:https://www.hpe.com/us/en/insights/articles/how-to-see-whats-going-on-with-your-linux-system-right-now-1807.html +[13]:http://shop.oreilly.com/product/9780596510299.do +[14]:http://shop.oreilly.com/product/9780596009656.do +[15]:http://shop.oreilly.com/product/9780596100575.do +[16]:http://shop.oreilly.com/product/9780596000127.do +[17]:https://amzn.to/2vsCJgF +[18]:https://amzn.to/2APzt3Z +[19]:https://www.amazon.com/Practice-Programming-Addison-Wesley-Professional-Computing/dp/020161586X/ref=as_li_ss_tl?ie=UTF8&linkCode=sl1&tag=thegroovycorpora&linkId=e6bbdb1ca2182487069bf9089fc8107e&language=en_US +[20]:https://amzn.to/2OknFsJ +[21]:https://amzn.to/2M4VVL3 +[22]:https://amzn.to/2OjccJA +[23]:http://shop.oreilly.com/product/9781565923065.do +[24]:https://amzn.to/2OjzgrT +[25]:https://www.kernel.org/doc/html/v4.16/process/howto.html diff --git a/sources/tech/20180815 Happy birthday, GNOME- 6 reasons to love this Linux desktop.md b/sources/tech/20180815 Happy birthday, GNOME- 6 reasons to love this Linux desktop.md new file mode 100644 index 0000000000..590a83a62d --- /dev/null +++ b/sources/tech/20180815 Happy birthday, GNOME- 6 reasons to love this Linux desktop.md @@ -0,0 +1,71 @@ +Happy birthday, GNOME: 6 reasons to love this Linux desktop +====== + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/happy_birthday_anniversary_celebrate_hats_cake.jpg?itok=Zfsv6DE_) + +GNOME has been my favorite [desktop environment][1] for quite some time. While I always make it a point to check out other environments from time to time, there are some aspects of the GNOME desktop that are hard to live without. While there are many great desktop environments out there, [GNOME][2] feels like home to me. Here are some of the features I enjoy most about GNOME. + +### Stability + +Having a stable working environment is the most important aspect of a desktop for me. After all, the feature set of an environment doesn't matter at all if it crashes constantly and you lose work. For me, GNOME is rock-solid. I have heard of others experiencing crashes and instability, but it always seems to be due to either the user running GNOME on unsupported hardware or due to faulty extensions (more on that later). On my end, I run GNOME primarily on hardware that is known to be well-supported in Linux ([System76][3], for example). I also have a few systems that are not as well supported (a custom-built desktop and a Dell Latitude laptop), and I actually don't have any issues there either. For me, GNOME is rock-solid. I have compared stability in other well-known desktop environments, and I had unfortunate results. Nothing comes close to GNOME when it comes to stability. + +### Extensions + +I really enjoy being able to add additional functionality to my environment. I don't necessarily require any extensions, because I am perfectly fine with stock-GNOME with no extensions whatsoever. However, having the ability to add a few things here and there, is welcome. GNOME features various extensions to do things such as add a weather display to your panel, and much more. This adds a level of customization that is not typical of other environments. That said, proceed with caution. Sometimes extensions are of varying quality and may lead to stability issues. I find though that if you only install extensions you absolutely need, and you make sure they're kept up to date (and aren't abandoned by the developer) you'll generally be in good shape. + +### Activities overview + +Activities overview is quite possibly the easiest feature to use in GNOME, and it's barely detailed enough to justify its own section in this article. However, when I use other desktop environments, I miss this feature the most. + +The thing is, I am very busy, with multiple projects going on at any one time, and dozens of different windows open. To access the activities overview, I simply press the Super key. Immediately, my workspace is "zoomed out" and I see all of my windows side-by-side. This is often a faster way to locate a window that is hidden behind others, and a good way overall to see what exactly is running on any given workspace. + +When using other desktop environments, I will often find myself pressing the Super key out of habit, only to remember that I'm not using GNOME at the time. There are ways of achieving similar behavior in other environments (such as installing and tweaking Compiz), but in GNOME this feature is built-in. + +### Dynamic workspaces + +While working, I am not sure up-front how many workspaces I will need. Sometimes I can be working on three projects at a time, or as many as ten. With most desktop environments, I can access the settings screen and add or remove workspaces as needed. But with GNOME, I have exactly as many workspaces as I need at any given time. Every time I open applications on a workspace, I am given another blank one that I can switch to in order to start another project. Typically, I keep all windows related to a specific project on their own workspace, so it makes it very easy to locate my workflow for a given project. + +Other desktop environments have really good implementations of the concept of workspaces, but GNOME's implementation works best for me. + +### Simplicity + +Another thing I love about GNOME is that it's simple and straight to the point. By default, there is only one panel, and it's at the top of the screen. This panel shows you a small amount of information, such as the date, time, and battery usage. GNOME 2 had two panels, so seeing GNOME stripped down to a single panel is welcome and saves room on the screen. Most of the things you don't need to see all the time are hidden within the Activities overview, leaving you with the maximum amount of screen space for the application(s) you are working on. GNOME just stays out of the way and lets you focus on getting your work done, and stays away from fancy widgets and desktop gadgets that just aren't necessary. + + +In addition, GNOME has really great support for keyboard shortcuts. Most of GNOME's features I can access without needing to touch my mouse, such as SUPER+Page Up and Super Page Down to switch workspaces, Super+Up arrow to maximize windows, etc. In addition, I am able to easily create my own keyboard shortcuts for all of my favorite applications. + +### GNOME Boxes + +GNOME's Boxes app is an underrated gem. This utility makes it very easy to spin up a virtual machine, which is a godsend among developers and those that like to test configurations on multiple distributions and platforms. With Boxes, you can spin up a virtual machine at any time, and it will even automate the installation process for you. For example, if you want a new Ubuntu VM, you simply choose Ubuntu as your desired platform, fill out your username and any related information, and you will have a new Ubuntu VM in a few minutes. When you're done with it, you can power it down or trash it. + +For me, I do a lot of DevOps-style work as well as system administration. Being able to test a configuration on a virtual machine before deploying to another environment is great. Sure, you can do the exact same thing in VirtualBox, and VirtualBox is a great piece of software. However, Boxes is built right into GNOME, and desktop environments generally don't offer their own solution for virtualization. + +### GNOME Music + +While I work, I have difficulty tuning out noise in my environment. Therefore, I like to listen to music while I complete projects and tune out the rest of the world. GNOME's Music app is very simplistic and works very well. With most of the music industry gravitating toward streaming music online, and many once-popular [open source music players][7] becoming abandoned projects, it's nice to see GNOME support a built-in music player that can play my music collection. It's great to listen to my music collection while I work, and it helps me zone-in to what I am doing. + +### GNOME Games + +When work is done for the day, it's time to play! There's nothing like playing a classic game such as Final Fantasy VI or Super Metroid after a hard day's work. The thing is, I am a huge fan of classic gaming, and I have 22 working gaming consoles and somewhere near 1,000 physical games in my collection. But I may not always have a moment to hook up one of my retro-consoles, so GNOME Games allows me quick-access to emulated versions of my collection. In addition to that, it also works with Libretro cores as well, so it seems to me that the developers of this application have really thought-out what fans of classic gaming like me are looking for in a frontend for gaming. + +These are the major features I enjoy most in the GNOME desktop. What are some of yours? + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/8/what-i-love-about-gnome + +作者:[Jay LaCroix][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://opensource.com/users/jlacroix +[1]:https://opensource.com/article/18/8/how-navigate-your-gnome-linux-desktop-only-keyboard +[2]:https://opensource.com/article/17/8/reasons-i-come-back-gnome +[3]:https://opensource.com/article/16/12/open-gaming-news-december-31 +[4]:https://opensource.com/file/407221 +[5]:https://opensource.com/sites/default/files/uploads/gnome3-cheatsheet.png (GNOME 3 Cheat Sheet) +[6]:https://opensource.com/downloads/cheat-sheet-gnome-3 +[7]:https://opensource.com/article/18/6/open-source-music-players diff --git a/sources/tech/20180815 How to Create M3U Playlists in Linux [Quick Tip].md b/sources/tech/20180815 How to Create M3U Playlists in Linux [Quick Tip].md new file mode 100644 index 0000000000..3c0b63d63b --- /dev/null +++ b/sources/tech/20180815 How to Create M3U Playlists in Linux [Quick Tip].md @@ -0,0 +1,84 @@ +translating by lujun9972 +How to Create M3U Playlists in Linux [Quick Tip] +====== +**Brief: A quick tip on how to create M3U playlists in Linux terminal from unordered files to play them in a sequence.** + +![Create M3U playlists in Linux Terminal][1] + +I am a fan of foreign tv series and it’s not always easy to get them on DVD or on streaming services like [Netflix][2]. Thankfully, you can find some of them on YouTube and [download them from YouTube][3]. + +Now there comes a problem. Your files might not be sorted in a particular order. In GNU/Linux files are not naturally sort ordered by number sequencing so I had to make a .m3u playlist so [MPV video player][4] would play the videos in sequence and not out of sequence. + +Also sometimes the numbers are in the middle or the end like ‘My Web Series S01E01.mkv’ as an example. The episode information here is in the middle of the filename, the ‘S01E01’ which tells us, humans, which is the first episode and which needs to come in next. + +So what I did was to generate an m3u playlist in the video directory and tell MPV to play the .m3u playlist and it would take care of playing them in the sequence. + +### What is an M3U file? + +[M3U][5] is basically a text file that contains filenames in a specific order. When a player like MPV or VLC opens an M3U file, it tries to play the specified files in the given sequence. + +### Creating M3U to play audio/video files in a sequence + +In my case, I used the following command: +``` +$/home/shirish/Videos/web-series-video/$ ls -1v |grep .mkv > /tmp/1.m3u && mv /tmp/1.m3u . + +``` + +Let’s break it down a bit and see each bit as to what it means – + +**ls -1v** = This is using the plain ls or listing entries in the directory. The -1 means list one file per line. while -v natural sort of (version) numbers within text + +**| grep .mkv** = It’s basically telling `ls` to look for files which are ending in .mkv . It could be .mp4 or any other media file format that you want. + +It’s usually a good idea to do a dry run by running the command on the console: +``` +ls -1v |grep .mkv +My Web Series S01E01 [Episode 1 Name] Multi 480p WEBRip x264 - xRG.mkv +My Web Series S01E02 [Episode 2 Name] Multi 480p WEBRip x264 - xRG.mkv +My Web Series S01E03 [Episode 3 Name] Multi 480p WEBRip x264 - xRG.mkv +My Web Series S01E04 [Episode 4 Name] Multi 480p WEBRip x264 - xRG.mkv +My Web Series S01E05 [Episode 5 Name] Multi 480p WEBRip x264 - xRG.mkv +My Web Series S01E06 [Episode 6 Name] Multi 480p WEBRip x264 - xRG.mkv +My Web Series S01E07 [Episode 7 Name] Multi 480p WEBRip x264 - xRG.mkv +My Web Series S01E08 [Episode 8 Name] Multi 480p WEBRip x264 - xRG.mkv + +``` + +This tells me that what I’m trying to do is correct. Now just have to make that the output is in the form of a .m3u playlist which is the next part. +``` +ls -1v |grep .mkv > /tmp/web_playlist.m3u && mv /tmp/web_playlist.m3u . + +``` + +This makes the .m3u generate in the current directory. The .m3u playlist is nothing but a .txt file with the same contents as above with the .m3u extension. You can edit it manually as well and add the exact filenames in an order you desire. + +After that you just have to do something like this: +``` +mpv web_playlist.m3u + +``` + +The great thing about MPV and the playlists, in general, is that you don’t have to binge-watch. You can see however much you want to do in one sitting and see the rest in the next session or the session after that. + +I hope to do articles featuring MPV as well as how to make mkv files embedding subtitles in a media file but that’s in the future. + +Note: It’s FOSS doesn’t encourage piracy. + +-------------------------------------------------------------------------------- + +via: https://itsfoss.com/create-m3u-playlist-linux/ + +作者:[Shirsh][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://itsfoss.com/author/shirish/ +[1]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/08/Create-M3U-Playlists.jpeg +[2]:https://itsfoss.com/netflix-open-source-ai/ +[3]:https://itsfoss.com/download-youtube-linux/ +[4]:https://itsfoss.com/mpv-video-player/ +[5]:https://en.wikipedia.org/wiki/M3U diff --git a/sources/tech/20180816 An introduction to the Django Python web app framework.md b/sources/tech/20180816 An introduction to the Django Python web app framework.md new file mode 100644 index 0000000000..ab7dba9526 --- /dev/null +++ b/sources/tech/20180816 An introduction to the Django Python web app framework.md @@ -0,0 +1,1250 @@ +Translating by MjSeven + + +An introduction to the Django Python web app framework +====== + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/web-spider-frame-framework.png?itok=Rl2AG2Dc) + +In the first three articles of this four-part series comparing different Python web frameworks, we covered the [Pyramid][1], [Flask][2], and [Tornado][3] web frameworks. We've built the same app three times and have finally made our way to [Django][4]. Django is, by and large, the major web framework for Python developers these days and it's not too hard to see why. It excels in hiding a lot of the configuration logic and letting you focus on being able to build big, quickly. + +That said, when it comes to small projects, like our To-Do List app, Django can be a bit like bringing a firehose to a water gun fight. Let's see how it all comes together. + +### About Django + +Django styles itself as "a high-level Python web framework that encourages rapid development and clean, pragmatic design. Built by experienced developers, it takes care of much of the hassle of web development, so you can focus on writing your app without needing to reinvent the wheel." And they really mean it! This massive web framework comes with so many batteries included that oftentimes during development it can be a mystery as to how everything manages to work together. + +In addition to the framework itself being large, the Django community is absolutely massive. In fact, it's so big and active that there's [a whole website][5] devoted to the third-party packages people have designed to plug into Django to do a whole host of things. This includes everything from authentication and authorization, to full-on Django-powered content management systems, to e-commerce add-ons, to integrations with Stripe. Talk about not re-inventing the wheel; chances are if you want something done with Django, someone has already done it and you can just pull it into your project. + +For this purpose, we want to build a REST API with Django, so we'll leverage the always popular [Django REST framework][6]. Its job is to turn the Django framework, which was made to serve fully rendered HTML pages built with Django's own templating engine, into a system specifically geared toward effectively handling REST interactions. Let's get going with that. + +### Django startup and configuration +``` +$ mkdir django_todo + +$ cd django_todo + +$ pipenv install --python 3.6 + +$ pipenv shell + +(django-someHash) $ pipenv install django djangorestframework + +``` + +For reference, we're working with `django-2.0.7` and `djangorestframework-3.8.2`. + +Unlike Flask, Tornado, and Pyramid, we don't need to write our own `setup.py` file. We're not making an installable Python distribution. As with many things, Django takes care of that for us in its own Django way. We'll still need a `requirements.txt` file to track all our necessary installs for deployment elsewhere. However, as far as targeting modules within our Django project goes, Django will let us list the subdirectories we want access to, then allow us to import from those directories as if they're installed packages. + +First, we have to create a Django project. + +When we installed Django, we also installed the command-line script `django-admin`. Its job is to manage all the various Django-related commands that help put our project together and maintain it as we continue to develop. Instead of having us build up the entire Django ecosystem from scratch, the `django-admin` will allow us to get started with all the absolutely necessary files (and more) we need for a standard Django project. + +The syntax for invoking `django-admin`'s start-project command is `django-admin startproject `. We want the files to exist in our current working directory, so: +``` +(django-someHash) $ django-admin startproject django_todo . + +``` + +Typing `ls` will show one new file and one new directory. +``` +(django-someHash) $ ls + +manage.py   django_todo + +``` + +`manage.py` is a command-line-executable Python file that ends up just being a wrapper around `django-admin`. As such, its job is the same: to help us manage our project. Hence the name `manage.py`. + +The directory it created, the `django_todo` inside of `django_todo`, represents the configuration root for our project. Let's dig into that now. + +### Configuring Django + +By calling the `django_todo` directory the "configuration root," we mean this directory holds the files necessary for generally configuring our Django project. Pretty much everything outside this directory will be focused solely on the "business logic" associated with the project's models, views, routes, etc. All points that connect the project together will lead here. + +Calling `ls` within `django_todo` reveals four files: +``` +(django-someHash) $ cd django_todo + +(django-someHash) $ ls + +__init__.py settings.py urls.py     wsgi.py + +``` + + * `__init__.py` is empty, solely existing to turn this directory into an importable Python package. + * `settings.py` is where most configuration items will be set, like whether the project's in DEBUG mode, what databases are in use, where Django should look for files, etc. It is the "main configuration" part of the configuration root, and we'll dig into that momentarily. + * `urls.py` is, as the name implies, where the URLs are set. While we don't have to explicitly write every URL for the project in this file, we **do** need to make this file aware of any other places where URLs have been declared. If this file doesn't point to other URLs, those URLs don't exist. **Period.** + * `wsgi.py` is for serving the application in production. Just like how Pyramid, Tornado, and Flask exposed some "app" object that was the configured application to be served, Django must also expose one. That's done here. It can then be served with something like [Gunicorn][7], [Waitress][8], or [uWSGI][9]. + + + +#### Setting the settings + +Taking a look inside `settings.py` will reveal its considerable size—and these are just the defaults! This doesn't even include hooks for the database, static files, media files, any cloud integration, or any of the other dozens of ways that a Django project can be configured. Let's see, top to bottom, what we've been given: + + * `BASE_DIR` sets the absolute path to the base directory, or the directory where `manage.py` is located. This is useful for locating files. + * `SECRET_KEY` is a key used for cryptographic signing within the Django project. In practice, it's used for things like sessions, cookies, CSRF protection, and auth tokens. As soon as possible, preferably before the first commit, the value for `SECRET_KEY` should be changed and moved into an environment variable. + * `DEBUG` tells Django whether to run the project in development mode or production mode. This is an extremely critical distinction. + * In development mode, when an error pops up, Django will show the full stack trace that led to the error, as well as all the settings and configurations involved in running the project. This can be a massive security issue if `DEBUG` was set to `True` in a production environment. + * In production, Django shows a plain error page when things go wrong. No information is given beyond an error code. + * A simple way to safeguard our project is to set `DEBUG` to an environment variable, like `bool(os.environ.get('DEBUG', ''))`. + * `ALLOWED_HOSTS` is the literal list of hostnames from which the application is being served. In development this can be empty, but in production our Django project will not run if the host that serves the project is not among the list of ALLOWED_HOSTS. Another thing for the box of environment variables. + * `INSTALLED_APPS` is the list of Django "apps" (think of them as subdirectories; more on this later) that our Django project has access to. We're given a few by default to provide… + * The built-in Django administrative website + * Django's built-in authentication system + * Django's one-size-fits-all manager for data models + * Session management + * Cookie and session-based messaging + * Usage of static files inherent to the site, like `css` files, `js` files, any images that are a part of our site's design, etc. + * `MIDDLEWARE` is as it sounds: the middleware that helps our Django project run. Much of it is for handling various types of security, although we can add others as we need them. + * `ROOT_URLCONF` sets the import path of our base-level URL configuration file. That `urls.py` that we saw before? By default, Django points to that file to gather all our URLs. If we want Django to look elsewhere, we'll set the import path to that location here. + * `TEMPLATES` is the list of template engines that Django would use for our site's frontend if we were relying on Django to build our HTML. Since we're not, it's irrelevant. + * `WSGI_APPLICATION` sets the import path of our WSGI application—the thing that gets served when in production. By default, it points to an `application` object in `wsgi.py`. This rarely, if ever, needs to be modified. + * `DATABASES` sets which databases our Django project will access. The `default` database must be set. We can set others by name, as long as we provide the `HOST`, `USER`, `PASSWORD`, `PORT`, database `NAME`, and appropriate `ENGINE`. As one might imagine, these are all sensitive pieces of information, so it's best to hide them away in environment variables. [Check the Django docs][10] for more details. + * Note: If instead of providing individual pieces of a database's location, you'd rather provide the full database URL, check out [dj_database_url][11]. + * `AUTH_PASSWORD_VALIDATORS` is effectively a list of functions that run to check input passwords. We get a few by default, but if we had other, more complex validation needs—more than merely checking if the password matches a user's attribute, if it exceeds the minimum length, if it's one of the 1,000 most common passwords, or if the password is entirely numeric—we could list them here. + * `LANGUAGE_CODE` will set the language for the site. By default it's US English, but we could switch it up to be other languages. + * `TIME_ZONE` is the time zone for any autogenerated timestamps in our Django project. I cannot stress enough how important it is that we stick to UTC and perform any time zone-specific processing elsewhere instead of trying to reconfigure this setting. As [this article][12] states, UTC is the common denominator among all time zones because there are no offsets to worry about. If offsets are that important, we could calculate them as needed with an appropriate offset from UTC. + * `USE_I18N` will let Django use its own translation services to translate strings for the front end. I18N = internationalization (18 characters between "i" and "n") + * `USE_L10N` (L10N = localization [10 characters between "l" and "n"]) will use the common local formatting of data if set to `True`. A great example is dates: in the US it's MM-DD-YYYY. In Europe, dates tend to be written DD-MM-YYYY + * `STATIC_URL` is part of a larger body of settings for serving static files. We'll be building a REST API, so we won't need to worry about static files. In general, this sets the root path after the domain name for every static file. So, if we had a logo image to serve, it'd be `http:////logo.gif` + + + +These settings are pretty much ready to go by default. One thing we'll have to change is the `DATABASES` setting. First, we create the database that we'll be using with: +``` +(django-someHash) $ createdb django_todo + +``` + +We want to use a PostgreSQL database like we did with Flask, Pyramid, and Tornado. That means we'll have to change the `DATABASES` setting to allow our server to access a PostgreSQL database. First: the engine. By default, the database engine is `django.db.backends.sqlite3`. We'll be changing that to `django.db.backends.postgresql`. + +For more information about Django's available engines, [check the docs][13]. Note that while it is technically possible to incorporate a NoSQL solution into a Django project, out of the box, Django is strongly biased toward SQL solutions. + +Next, we have to specify the key-value pairs for the different parts of the connection parameters. + + * `NAME` is the name of the database we just created. + * `USER` is an individual's Postgres database username + * `PASSWORD` is the password needed to access the database + * `HOST` is the host for the database. `localhost` or `127.0.0.1` will work, as we're developing locally. + * `PORT` is whatever PORT we have open for Postgres; it's typically `5432`. + + + +`settings.py` expects us to provide string values for each of these keys. However, this is highly sensitive information. That's not going to work for any responsible developer. There are several ways to address this problem, but we'll just set up environment variables. +``` +DATABASES = { + +    'default': { + +        'ENGINE': 'django.db.backends.postgresql', + +        'NAME': os.environ.get('DB_NAME', ''), + +        'USER': os.environ.get('DB_USER', ''), + +        'PASSWORD': os.environ.get('DB_PASS', ''), + +        'HOST': os.environ.get('DB_HOST', ''), + +        'PORT': os.environ.get('DB_PORT', ''), + +    } + +} + +``` + +Before going forward, make sure to set the environment variables or Django will not work. Also, we need to install `psycopg2` into this environment so we can talk to our database. + +### Django routes and views + +Let's make something function inside this project. We'll be using Django REST Framework to construct our REST API, so we have to make sure we can use it by adding `rest_framework` to the end of `INSTALLED_APPS` in `settings.py`. +``` +INSTALLED_APPS = [ + +    'django.contrib.admin', + +    'django.contrib.auth', + +    'django.contrib.contenttypes', + +    'django.contrib.sessions', + +    'django.contrib.messages', + +    'django.contrib.staticfiles', + +    'rest_framework' + +] + +``` + +While Django REST Framework doesn't exclusively require class-based views (like Tornado) to handle incoming requests, it is the preferred method for writing views. Let's define one. + +Let's create a file called `views.py` in `django_todo`. Within `views.py`, we'll create our "Hello, world!" view. +``` +# in django_todo/views.py + +from rest_framework.response import JsonResponse + +from rest_framework.views import APIView + + + +class HelloWorld(APIView): + +    def get(self, request, format=None): + +        """Print 'Hello, world!' as the response body.""" + +        return JsonResponse("Hello, world!") + +``` + +Every Django REST Framework class-based view inherits either directly or indirectly from `APIView`. `APIView` handles a ton of stuff, but for our purposes it does these specific things: + + * Sets up the methods needed to direct traffic based on the HTTP method (e.g. GET, POST, PUT, DELETE) + * Populates the `request` object with all the data and attributes we'll need for parsing and processing any incoming request + * Takes the `Response` or `JsonResponse` that every dispatch method (i.e., methods named `get`, `post`, `put`, `delete`) returns and constructs a properly formatted HTTP response. + + + +Yay, we have a view! On its own it does nothing. We need to connect it to a route. + +If we hop into `django_todo/urls.py`, we reach our default URL configuration file. As mentioned earlier: If a route in our Django project is not included here, it doesn't exist. + +We add desired URLs by adding them to the given `urlpatterns` list. By default, we get a whole set of URLs for Django's built-in site administration backend. We'll delete that completely. + +We also get some very helpful doc strings that tell us exactly how to add routes to our Django project. We'll need to provide a call to `path()` with three parameters: + + * The desired route, as a string (without the leading slash) + * The view function (only ever a function!) that will handle that route + * The name of the route in our Django project + + + +Let's import our `HelloWorld` view and attach it to the home route `"/"`. We can also remove the path to the `admin` from `urlpatterns`, as we won't be using it. +``` +# django_todo/urls.py, after the big doc string + +from django.urls import path + +from django_todo.views import HelloWorld + + + +urlpatterns = [ + +    path('', HelloWorld.as_view(), name="hello"), + +] + +``` + +Well, this is different. The route we specified is just a blank string. Why does that work? Django assumes that every path we declare begins with a leading slash. We're just specifying routes to resources after the initial domain name. If a route isn't going to a specific resource and is instead just the home page, the route is just `""`, or effectively "no resource." + +The `HelloWorld` view is imported from that `views.py` file we just created. In order to do this import, we need to update `settings.py` to include `django_todo` in the list of `INSTALLED_APPS`. Yeah, it's a bit weird. Here's one way to think about it. + +`INSTALLED_APPS` refers to the list of directories or packages that Django sees as importable. It's Django's way of treating individual components of a project like installed packages without going through a `setup.py`. We want the `django_todo` directory to be treated like an importable package, so we include that directory in `INSTALLED_APPS`. Now, any module within that directory is also importable. So we get our view. + +The `path` function will ONLY take a view function as that second argument, not just a class-based view on its own. Luckily, all valid Django class-based views include this `.as_view()` method. Its job is to roll up all the goodness of the class-based view into a view function and return that view function. So, we never have to worry about making that translation. Instead, we only have to think about the business logic, letting Django and Django REST Framework handle the rest. + +Let's crack this open in the browser! + +Django comes packaged with its own local development server, accessible through `manage.py`. Let's navigate to the directory containing `manage.py` and type: +``` +(django-someHash) $ ./manage.py runserver + +Performing system checks... + + + +System check identified no issues (0 silenced). + +August 01, 2018 - 16:47:24 + +Django version 2.0.7, using settings 'django_todo.settings' + +Starting development server at http://127.0.0.1:8000/ + +Quit the server with CONTROL-C. + +``` + +When `runserver` is executed, Django does a check to make sure the project is (more or less) wired together correctly. It's not fool-proof, but it does catch some glaring issues. It also notifies us if our database is out of sync with our code. Undoubtedly ours is because we haven't committed any of our application's stuff to our database, but that's fine for now. Let's visit `http://127.0.0.1:8000` to see the output of the `HelloWorld` view. + +Huh. That's not the plaintext data we saw in Pyramid, Flask, and Tornado. When Django REST Framework is used, the HTTP response (when viewed in the browser) is this sort of rendered HTML, showing our actual JSON response in red. + +But don't fret! If we do a quick `curl` looking at `http://127.0.0.1:8000` in the command line, we don't get any of that fancy HTML. Just the content. +``` +# Note: try this in a different terminal window, outside of the virtual environment above + +$ curl http://127.0.0.1:8000 + +"Hello, world!" + +``` + +Bueno! + +Django REST Framework wants us to have a human-friendly interface when using the browser. This makes sense; if JSON is viewed in the browser, it's typically because a human wants to check that it looks right or get a sense of what the JSON response will look like as they design some consumer of an API. It's a lot like what you'd get from a service like [Postman][14]. + +Either way, we know our view is working! Woo! Let's recap what we've done: + + 1. Started the project with `django-admin startproject ` + 2. Updated the `django_todo/settings.py` to use environment variables for `DEBUG`, `SECRET_KEY`, and values in the `DATABASES` dict + 3. Installed `Django REST Framework` and added it to the list of `INSTALLED_APPS` + 4. Created `django_todo/views.py` to include our first view class to say Hello to the World + 5. Updated `django_todo/urls.py` with a path to our new home route + 6. Updated `INSTALLED_APPS` in `django_todo/settings.py` to include the `django_todo` package + + + +### Creating models + +Let's create our data models now. + +A Django project's entire infrastructure is built around data models. It's written so each data model can have its own little universe with its own views, its own set of URLs that concern its resources, and even its own tests (if we are so inclined). + +If we wanted to build a simple Django project, we could circumvent this by just writing our own `models.py` file in the `django_todo` directory and importing it into our views. However, we're trying to write a Django project the "right" way, so we should divide up our models as best we can into their own little packages The Django Way™. + +The Django Way involves creating what are called Django "apps." Django "apps" aren't separate applications per se; they don't have their own settings and whatnot (although they can). They can, however, have just about everything else one might think of being in a standalone application: + + * Set of self-contained URLs + * Set of self-contained HTML templates (if we want to serve HTML) + * One or more data models + * Set of self-contained views + * Set of self-contained tests + + + +They are made to be independent so they can be easily shared like standalone applications. In fact, Django REST Framework is an example of a Django app. It comes packaged with its own views and HTML templates for serving up our JSON. We just leverage that Django app to turn our project into a full-on RESTful API with less hassle. + +To create the Django app for our To-Do List items, we'll want to use the `startapp` command with `manage.py`. +``` +(django-someHash) $ ./manage.py startapp todo + +``` + +The `startapp` command will succeed silently. We can check that it did what it should've done by using `ls`. +``` +(django-someHash) $ ls + +Pipfile      Pipfile.lock django_todo  manage.py    todo + +``` + +Look at that: We've got a brand new `todo` directory. Let's look inside! +``` +(django-someHash) $ ls todo + +__init__.py admin.py    apps.py     migrations  models.py   tests.py    views.py + +``` + +Here are the files that `manage.py startapp` created: + + * `__init__.py` is empty; it exists so this directory can be seen as a valid import path for models, views, etc. + * `admin.py` is not quite empty; it's used for formatting this app's models in the Django admin, which we're not getting into in this article. + * `apps.py` … not much work to do here either; it helps with formatting models for the Django admin. + * `migrations` is a directory that'll contain snapshots of our data models; it's used for updating our database. This is one of the few frameworks that comes with database management built-in, and part of that is allowing us to update our database instead of having to tear it down and rebuild it to change the schema. + * `models.py` is where the data models live. + * `tests.py` is where tests would go—if we wrote any. + * `views.py` is for the views we write that pertain to the models in this app. They don't have to be written here. We could, for example, write all our views in `django_todo/views.py`. It's here, however, so it's easier to separate our concerns. This becomes far more relevant with sprawling applications that cover many conceptual spaces. + + + +What hasn't been created for us is a `urls.py` file for this app. We can make that ourselves. +``` +(django-someHash) $ touch todo/urls.py + +``` + +Before moving forward we should do ourselves a favor and add this new Django app to our list of `INSTALLED_APPS` in `django_todo/settings.py`. +``` +# in settings.py + +INSTALLED_APPS = [ + +    'django.contrib.admin', + +    'django.contrib.auth', + +    'django.contrib.contenttypes', + +    'django.contrib.sessions', + +    'django.contrib.messages', + +    'django.contrib.staticfiles', + +    'rest_framework', + +    'django_todo', + +    'todo' # <--- the line was added + +] + +``` + +Inspecting `todo/models.py` shows that `manage.py` already wrote a bit of code for us to get started. Diverging from how models were created in the Flask, Tornado, and Pyramid implementations, Django doesn't leverage a third party to manage database sessions or the construction of its object instances. It's all rolled into Django's `django.db.models` submodule. + +The way a model is built, however, is more or less the same. To create a model in Django, we'll need to build a `class` that inherits from `models.Model`. All the fields that will apply to instances of that model should appear as class attributes. Instead of importing columns and field types from SQLAlchemy like we have in the past, all of our fields will come directly from `django.db.models`. +``` +# todo/models.py + +from django.db import models + + + +class Task(models.Model): + +    """Tasks for the To Do list.""" + +    name = models.CharField(max_length=256) + +    note = models.TextField(blank=True, null=True) + +    creation_date = models.DateTimeField(auto_now_add=True) + +    due_date = models.DateTimeField(blank=True, null=True) + +    completed = models.BooleanField(default=False) + +``` + +While there are some definite differences between what Django needs and what SQLAlchemy-based systems need, the overall contents and structure are more or less the same. Let's point out the differences. + +We no longer need to declare a separate field for an auto-incremented ID number for our object instances. Django builds one for us unless we specify a different field as the primary key. + +Instead of instantiating `Column` objects that are passed datatype objects, we just directly reference the datatypes as the columns themselves. + +The `Unicode` field became either `models.CharField` or `models.TextField`. `CharField` is for small text fields of a specific maximum length, whereas `TextField` is for any amount of text. + +The `TextField` should be able to be blank, and we specify this in TWO ways. `blank=True` says that when an instance of this model is constructed, and the data attached to this field is being validated, it's OK for that data to be empty. This is different from `null=True`, which says when the table for this model class is constructed, the column corresponding to `note` will allow for blank or `NULL` entries. So, to sum that all up, `blank=True` controls how data gets added to model instances while `null=True` controls how the database table holding that data is constructed in the first place. + +The `DateTime` field grew some muscle and became able to do some work for us instead of us having to modify the `__init__` method for the class. For the `creation_date` field, we specify `auto_now_add=True`. What this means in a practical sense is that when a new model instance is created Django will automatically record the date and time of now as that field's value. That's handy! + +When neither `auto_now_add` nor its close cousin `auto_now` are set to `True`, `DateTimeField` will expect data like any other field. It'll need to be fed with a proper `datetime` object to be valid. The `due_date` column has `blank` and `null` both set to `True` so that an item on the To-Do List can just be an item to be done at some point in the future, with no defined date or time. + +`BooleanField` just ends up being a field that can take one of two values: `True` or `False`. Here, the default value is set to be `False`. + +#### Managing the database + +As mentioned earlier, Django has its own way of doing database management. Instead of having to write… really any code at all regarding our database, we leverage the `manage.py` script that Django provided on construction. It'll manage not just the construction of the tables for our database, but also any updates we wish to make to those tables without necessarily having to blow the whole thing away! + +Because we've constructed a new model, we need to make our database aware of it. First, we need to put into code the schema that corresponds to this model. The `makemigrations` command of `manage.py` will take a snapshot of the model class we built and all its fields. It'll take that information and package it into a Python script that'll live in this particular Django app's `migrations` directory. There will never be a reason to run this migration script directly. It'll exist solely so that Django can use it as a basis to update our database table or to inherit information when we update our model class. +``` +(django-someHash) $ ./manage.py makemigrations + +Migrations for 'todo': + +  todo/migrations/0001_initial.py + +    - Create model Task + +``` + +This will look at every app listed in `INSTALLED_APPS` and check for models that exist in those apps. It'll then check the corresponding `migrations` directory for migration files and compare them to the models in each of those `INSTALLED_APPS` apps. If a model has been upgraded beyond what the latest migration says should exist, a new migration file will be created that inherits from the most recent one. It'll be automatically named and also be given a message that says what changed since the last migration. + +If it's been a while since you last worked on your Django project and can't remember if your models were in sync with your migrations, you have no need to fear. `makemigrations` is an idempotent operation; your `migrations` directory will have only one copy of the current model configuration whether you run `makemigrations` once or 20 times. Even better than that, when we run `./manage.py runserver`, Django will detect that our models are out of sync with our migrations, and it'll just flat out tell us in colored text so we can make the appropriate choice. + +This next point is something that trips everybody up at least once: Creating a migration file does not immediately affect our database. When we ran `makemigrations`, we prepared our Django project to define how a given table should be created and end up looking. It's still on us to apply those changes to our database. That's what the `migrate` command is for. +``` +(django-someHash) $ ./manage.py migrate + +Operations to perform: + +  Apply all migrations: admin, auth, contenttypes, sessions, todo + +Running migrations: + +  Applying contenttypes.0001_initial... OK + +  Applying auth.0001_initial... OK + +  Applying admin.0001_initial... OK + +  Applying admin.0002_logentry_remove_auto_add... OK + +  Applying contenttypes.0002_remove_content_type_name... OK + +  Applying auth.0002_alter_permission_name_max_length... OK + +  Applying auth.0003_alter_user_email_max_length... OK + +  Applying auth.0004_alter_user_username_opts... OK + +  Applying auth.0005_alter_user_last_login_null... OK + +  Applying auth.0006_require_contenttypes_0002... OK + +  Applying auth.0007_alter_validators_add_error_messages... OK + +  Applying auth.0008_alter_user_username_max_length... OK + +  Applying auth.0009_alter_user_last_name_max_length... OK + +  Applying sessions.0001_initial... OK + +  Applying todo.0001_initial... OK + +``` + +When we apply our migrations, Django first checks to see if the other `INSTALLED_APPS` have migrations to be applied. It checks them in roughly the order they're listed. We want our app to be listed last, because we want to make sure that, in case our model depends on any of Django's built-in models, the database updates we make don't suffer from dependency problems. + +We have another model to build: the User model. However, the game has changed a bit since we're using Django. So many applications require some sort of User model that Django's `django.contrib.auth` package built its own for us to use. If it weren't for the authentication token we require for our users, we could just move on and use it instead of reinventing the wheel. + +However, we need that token. There are a couple of ways we can handle this. + + * Inherit from Django's `User` object, making our own object that extends it by adding a `token` field + * Create a new object that exists in a one-to-one relationship with Django's `User` object, whose only purpose is to hold a token + + + +I'm in the habit of building object relationships, so let's go with the second option. Let's call it an `Owner` as it basically has a similar connotation as a `User`, which is what we want. + +Out of sheer laziness, we could just include this new `Owner` object in `todo/models.py`, but let's refrain from that. `Owner` doesn't explicitly have to do with the creation or maintenance of items on the task list. Conceptually, the `Owner` is simply the owner of the task. There may even come a time where we want to expand this `Owner` to include other data that has absolutely nothing to do with tasks. + +Just to be safe, let's make an `owner` app whose job is to house and handle this `Owner` object. +``` +(django-someHash) $ ./manage.py startapp owner + +``` + +Don't forget to add it to the list of `INSTALLED_APPS` in `settings.py`. +``` +INSTALLED_APPS = [ + +    'django.contrib.admin', + +    'django.contrib.auth', + +    'django.contrib.contenttypes', + +    'django.contrib.sessions', + +    'django.contrib.messages', + +    'django.contrib.staticfiles', + +    'rest_framework', + +    'django_todo', + +    'todo', + +    'owner' + +] + +``` + +If we look at the root of our Django project, we now have two Django apps: +``` +(django-someHash) $ ls + +Pipfile      Pipfile.lock django_todo  manage.py    owner        todo + +``` + +In `owner/models.py`, let's build this `Owner` model. As mentioned earlier, it'll have a one-to-one relationship with Django's built-in `User` object. We can enforce this relationship with Django's `models.OneToOneField` +``` +# owner/models.py + +from django.db import models + +from django.contrib.auth.models import User + +import secrets + + + +class Owner(models.Model): + +    """The object that owns tasks.""" + +    user = models.OneToOneField(User, on_delete=models.CASCADE) + +    token = models.CharField(max_length=256) + + + +    def __init__(self, *args, **kwargs): + +        """On construction, set token.""" + +        self.token = secrets.token_urlsafe(64) + +        super().__init__(*args, **kwargs) + +``` + +This says the `Owner` object is linked to the `User` object, with one `owner` instance per `user` instance. `on_delete=models.CASCADE` dictates that if the corresponding `User` gets deleted, the `Owner` instance it's linked to will also get deleted. Let's run `makemigrations` and `migrate` to bake this new model into our database. +``` +(django-someHash) $ ./manage.py makemigrations + +Migrations for 'owner': + +  owner/migrations/0001_initial.py + +    - Create model Owner + +(django-someHash) $ ./manage.py migrate + +Operations to perform: + +  Apply all migrations: admin, auth, contenttypes, owner, sessions, todo + +Running migrations: + +  Applying owner.0001_initial... OK + +``` + +Now our `Owner` needs to own some `Task` objects. It'll be very similar to the `OneToOneField` seen above, except that we'll stick a `ForeignKey` field on the `Task` object pointing to an `Owner`. +``` +# todo/models.py + +from django.db import models + +from owner.models import Owner + + + +class Task(models.Model): + +    """Tasks for the To Do list.""" + +    name = models.CharField(max_length=256) + +    note = models.TextField(blank=True, null=True) + +    creation_date = models.DateTimeField(auto_now_add=True) + +    due_date = models.DateTimeField(blank=True, null=True) + +    completed = models.BooleanField(default=False) + +    owner = models.ForeignKey(Owner, on_delete=models.CASCADE) + +``` + +Every To-Do List task has exactly one owner who can own multiple tasks. When that owner is deleted, any task they own goes with them. + +Let's now run `makemigrations` to take a new snapshot of our data model setup, then `migrate` to apply those changes to our database. +``` +(django-someHash) django $ ./manage.py makemigrations + +You are trying to add a non-nullable field 'owner' to task without a default; we can't do that (the database needs something to populate existing rows). + +Please select a fix: + + 1) Provide a one-off default now (will be set on all existing rows with a null value for this column) + + 2) Quit, and let me add a default in models.py + +``` + +Oh no! We have a problem! What happened? Well, when we created the `Owner` object and added it as a `ForeignKey` to `Task`, we basically required that every `Task` requires an `Owner`. However, the first migration we made for the `Task` object didn't include that requirement. So, even though there's no data in our database's table, Django is doing a pre-check on our migrations to make sure they're compatible and this new migration we're proposing is not. + +There are a few ways to deal with this sort of problem: + + 1. Blow away the current migration and build a new one that includes the current model configuration + 2. Add a default value to the `owner` field on the `Task` object + 3. Allow tasks to have `NULL` values for the `owner` field. + + + +Option 2 wouldn't make much sense here; we'd be proposing that any `Task` that was created would, by default, be linked to some default owner despite none necessarily existing. + +Option 1 would require us to destroy and rebuild our migrations. We should leave those alone. + +Let's go with option 3. In this circumstance, it won't be the end of the world if we allow the `Task` table to have null values for the owners; any tasks created from this point forward will necessarily have an owner. If you're in a situation where that isn't an acceptable schema for your database table, blow away your migrations, drop the table, and rebuild the migrations. +``` +# todo/models.py + +from django.db import models + +from owner.models import Owner + + + +class Task(models.Model): + +    """Tasks for the To Do list.""" + +    name = models.CharField(max_length=256) + +    note = models.TextField(blank=True, null=True) + +    creation_date = models.DateTimeField(auto_now_add=True) + +    due_date = models.DateTimeField(blank=True, null=True) + +    completed = models.BooleanField(default=False) + +    owner = models.ForeignKey(Owner, on_delete=models.CASCADE, null=True) + +(django-someHash) $ ./manage.py makemigrations + +Migrations for 'todo': + +  todo/migrations/0002_task_owner.py + +    - Add field owner to task + +(django-someHash) $ ./manage.py migrate + +Operations to perform: + +  Apply all migrations: admin, auth, contenttypes, owner, sessions, todo + +Running migrations: + +  Applying todo.0002_task_owner... OK + +``` + +Woo! We have our models! Welcome to the Django way of declaring objects. + +For good measure, let's ensure that whenever a `User` is made, it's automatically linked with a new `Owner` object. We can do this using Django's `signals` system. Basically, we say exactly what we intend: "When we get the signal that a new `User` has been constructed, construct a new `Owner` and set that new `User` as that `Owner`'s `user` field." In practice that looks like: +``` +# owner/models.py + +from django.contrib.auth.models import User + +from django.db import models + +from django.db.models.signals import post_save + +from django.dispatch import receiver + + + +import secrets + + + + + +class Owner(models.Model): + +    """The object that owns tasks.""" + +    user = models.OneToOneField(User, on_delete=models.CASCADE) + +    token = models.CharField(max_length=256) + + + +    def __init__(self, *args, **kwargs): + +        """On construction, set token.""" + +        self.token = secrets.token_urlsafe(64) + +        super().__init__(*args, **kwargs) + + + + + +@receiver(post_save, sender=User) + +def link_user_to_owner(sender, **kwargs): + +    """If a new User is saved, create a corresponding Owner.""" + +    if kwargs['created']: + +        owner = Owner(user=kwargs['instance']) + +        owner.save() + +``` + +We set up a function that listens for signals to be sent from the `User` object built into Django. It's waiting for just after a `User` object has been saved. This can come from either a new `User` or an update to an existing `User`; we discern between the two scenarios within the listening function. + +If the thing sending the signal was a newly created instance, `kwargs['created']` will have the value of `True`. We only want to do something if this is `True`. If it's a new instance, we create a new `Owner`, setting its `user` field to be the new `User` instance that was created. After that, we `save()` the new `Owner`. This will commit our change to the database if all is well. It'll fail if the data doesn't validate against the fields we declared. + +Now let's talk about how we're going to access the data. + +### Accessing model data + +In the Flask, Pyramid, and Tornado frameworks, we accessed model data by running queries against some database session. Maybe it was attached to a `request` object, maybe it was a standalone `session` object. Regardless, we had to establish a live connection to the database and query on that connection. + +This isn't the way Django works. Django, by default, doesn't leverage any third-party object-relational mapping (ORM) to converse with the database. Instead, Django allows the model classes to maintain their own conversations with the database. + +Every model class that inherits from `django.db.models.Model` will have attached to it an `objects` object. This will take the place of the `session` or `dbsession` we've become so familiar with. Let's open the special shell that Django gives us and investigate how this `objects` object works. +``` +(django-someHash) $ ./manage.py shell + +Python 3.7.0 (default, Jun 29 2018, 20:13:13) + +[Clang 9.1.0 (clang-902.0.39.2)] on darwin + +Type "help", "copyright", "credits" or "license" for more information. + +(InteractiveConsole) + +>>> + +``` + +The Django shell is different from a normal Python shell in that it's aware of the Django project we've been building and can do easy imports of our models, views, settings, etc. without having to worry about installing a package. We can access our models with a simple `import`. +``` +>>> from owner.models import Owner + +>>> Owner + + + +``` + +Currently, we have no `Owner` instances. We can tell by querying for them with `Owner.objects.all()`. +``` +>>> Owner.objects.all() + + + +``` + +Anytime we run a query method on the `.objects` object, we'll get a `QuerySet` back. For our purposes, it's effectively a `list`, and this `list` is showing us that it's empty. Let's make an `Owner` by making a `User`. +``` +>>> from django.contrib.auth.models import User + +>>> new_user = User(username='kenyattamurphy', email='kenyatta.murphy@gmail.com') + +>>> new_user.set_password('wakandaforever') + +>>> new_user.save() + +``` + +If we query for all of our `Owner`s now, we should find Kenyatta. +``` +>>> Owner.objects.all() + +]> + +``` + +Yay! We've got data! + +### Serializing models + +We'll be passing data back and forth beyond just "Hello World." As such, we'll want to see some sort of JSON-ified output that represents that data well. Taking that object's data and transforming it into a JSON object for submission across HTTP is a version of data serialization. In serializing data, we're taking the data we currently have and reformatting it to fit some standard, more-easily-digestible form. + +If I were doing this with Flask, Pyramid, and Tornado, I'd create a new method on each model to give the user direct access to call `to_json()`. The only job of `to_json()` would be to return a JSON-serializable (i.e. numbers, strings, lists, dicts) dictionary with whatever fields I want to be displayed for the object in question. + +It'd probably look something like this for the `Task` object: +``` +class Task(Base): + +    ...all the fields... + + + +    def to_json(self): + +        """Convert task attributes to a JSON-serializable dict.""" + +        return { + +            'id': self.id, + +            'name': self.name, + +            'note': self.note, + +            'creation_date': self.creation_date.strftime('%m/%d/%Y %H:%M:%S'), + +            'due_date': self.due_date.strftime('%m/%d/%Y %H:%M:%S'), + +            'completed': self.completed, + +            'user': self.user_id + +        } + +``` + +It's not fancy, but it does the job. + +Django REST Framework, however, provides us with an object that'll not only do that for us but also validate inputs when we want to create new object instances or update existing ones. It's called the [ModelSerializer][15]. + +Django REST Framework's `ModelSerializer` is effectively documentation for our models. They don't have lives of their own if there are no models attached (for that there's the [Serializer][16] class). Their main job is to accurately represent our model and make the conversion to JSON thoughtless when our model's data needs to be serialized and sent over a wire. + +Django REST Framework's `ModelSerializer` works best for simple objects. As an example, imagine that we didn't have that `ForeignKey` on the `Task` object. We could create a serializer for our `Task` that would convert its field values to JSON as necessary with the following declaration: +``` +# todo/serializers.py + +from rest_framework import serializers + +from todo.models import Task + + + +class TaskSerializer(serializers.ModelSerializer): + +    """Serializer for the Task model.""" + + + +    class Meta: + +        model = Task + +        fields = ('id', 'name', 'note', 'creation_date', 'due_date', 'completed') + +``` + +Inside our new `TaskSerializer`, we create a `Meta` class. `Meta`'s job here is just to hold information (or metadata) about the thing we're attempting to serialize. Then, we note the specific fields that we want to show. If we wanted to show all the fields, we could just shortcut the process and use `'__all__'`. We could, alternatively, use the `exclude` keyword instead of `fields` to tell Django REST Framework that we want every field except for a select few. We can have as many serializers as we like, so maybe we want one for a small subset of fields and one for all the fields? Go wild here. + +In our case, there is a relation between each `Task` and its owner `Owner` that must be reflected here. As such, we need to borrow the `serializers.PrimaryKeyRelatedField` object to specify that each `Task` will have an `Owner` and that relationship is one-to-one. Its owner will be found from the set of all owners that exists. We get that set by doing a query for those owners and returning the results we want to be associated with this serializer: `Owner.objects.all()`. We also need to include `owner` in the list of fields, as we always need an `Owner` associated with a `Task` +``` +# todo/serializers.py + +from rest_framework import serializers + +from todo.models import Task + +from owner.models import Owner + + + +class TaskSerializer(serializers.ModelSerializer): + +    """Serializer for the Task model.""" + +    owner = serializers.PrimaryKeyRelatedField(queryset=Owner.objects.all()) + + + +    class Meta: + +        model = Task + +        fields = ('id', 'name', 'note', 'creation_date', 'due_date', 'completed', 'owner') + +``` + +Now that this serializer is built, we can use it for all the CRUD operations we'd like to do for our objects: + + * If we want to `GET` a JSONified version of a specific `Task`, we can do `TaskSerializer(some_task).data` + * If we want to accept a `POST` with the appropriate data to create a new `Task`, we can use `TaskSerializer(data=new_data).save()` + * If we want to update some existing data with a `PUT`, we can say `TaskSerializer(existing_task, data=data).save()` + + + +We're not including `delete` because we don't really need to do anything with information for a `delete` operation. If you have access to an object you want to delete, just say `object_instance.delete()`. + +Here is an example of what some serialized data might look like: +``` +>>> from todo.models import Task + +>>> from todo.serializers import TaskSerializer + +>>> from owner.models import Owner + +>>> from django.contrib.auth.models import User + +>>> new_user = User(username='kenyatta', email='kenyatta@gmail.com') + +>>> new_user.save_password('wakandaforever') + +>>> new_user.save() # creating the User that builds the Owner + +>>> kenyatta = Owner.objects.first() # grabbing the Owner that is kenyatta + +>>> new_task = Task(name="Buy roast beef for the Sunday potluck", owner=kenyatta) + +>>> new_task.save() + +>>> TaskSerializer(new_task).data + +{'id': 1, 'name': 'Go to the supermarket', 'note': None, 'creation_date': '2018-07-31T06:00:25.165013Z', 'due_date': None, 'completed': False, 'owner': 1} + +``` + +There's a lot more you can do with the `ModelSerializer` objects, and I suggest checking [the docs][17] for those greater capabilities. Otherwise, this is as much as we need. It's time to dig into some views. + +### Views for reals + +We've built the models and the serializers, and now we need to set up the views and URLs for our application. After all, we can't do anything with an application that has no views. We've already seen an example with the `HelloWorld` view above. However, that's always a contrived, proof-of-concept example and doesn't really show what can be done with Django REST Framework's views. Let's clear out the `HelloWorld` view and URL so we can start fresh with our views. + +The first view we'll build is the `InfoView`. As in the previous frameworks, we just want to package and send out a dictionary of our proposed routes. The view itself can live in `django_todo.views` since it doesn't pertain to a specific model (and thus doesn't conceptually belong in a specific app). +``` +# django_todo/views.py + +from rest_framework.response import JsonResponse + +from rest_framework.views import APIView + + + +class InfoView(APIView): + +    """List of routes for this API.""" + +    def get(self, request): + +        output = { + +            'info': 'GET /api/v1', + +            'register': 'POST /api/v1/accounts', + +            'single profile detail': 'GET /api/v1/accounts/', + +            'edit profile': 'PUT /api/v1/accounts/', + +            'delete profile': 'DELETE /api/v1/accounts/', + +            'login': 'POST /api/v1/accounts/login', + +            'logout': 'GET /api/v1/accounts/logout', + +            "user's tasks": 'GET /api/v1/accounts//tasks', + +            "create task": 'POST /api/v1/accounts//tasks', + +            "task detail": 'GET /api/v1/accounts//tasks/', + +            "task update": 'PUT /api/v1/accounts//tasks/', + +            "delete task": 'DELETE /api/v1/accounts//tasks/' + +        } + +        return JsonResponse(output) + +``` + +This is pretty much identical to what we had in Tornado. Let's hook it up to an appropriate route and be on our way. For good measure, we'll also remove the `admin/` route, as we won't be using the Django administrative backend here. +``` +# in django_todo/urls.py + +from django_todo.views import InfoView + +from django.urls import path + + + +urlpatterns = [ + +    path('api/v1', InfoView.as_view(), name="info"), + +] + +``` + +#### Connecting models to views + +Let's figure out the next URL, which will be the endpoint for either creating a new `Task` or listing a user's existing tasks. This should exist in a `urls.py` in the `todo` app since this has to deal specifically with `Task` objects instead of being a part of the whole project. +``` +# in todo/urls.py + +from django.urls import path + +from todo.views import TaskListView + + + +urlpatterns = [ + +    path('', TaskListView.as_view(), name="list_tasks") + +] + +``` + +What's the deal with this route? We didn't specify a particular user or much of a path at all. Since there would be a couple of routes requiring the base path `/api/v1/accounts//tasks`, why write it again and again when we can just write it once? + +Django allows us to take a whole suite of URLs and import them into the base `django_todo/urls.py` file. We can then give every one of those imported URLs the same base path, only worrying about the variable parts when, you know, they vary. +``` +# in django_todo/urls.py + +from django.urls import include, path + +from django_todo.views import InfoView + + + +urlpatterns = [ + +    path('api/v1', InfoView.as_view(), name="info"), + +    path('api/v1/accounts//tasks', include('todo.urls')) + +] + +``` + +And now every URL coming from `todo/urls.py` will be prefixed with the path `api/v1/accounts//tasks`. + +Let's build out the view in `todo/views.py` +``` +# todo/views.py + +from django.shortcuts import get_object_or_404 + +from rest_framework.response import JsonResponse + +from rest_framework.views import APIView + + + +from owner.models import Owner + +from todo.models import Task + +from todo.serializers import TaskSerializer + + + + + +class TaskListView(APIView): + +    def get(self, request, username, format=None): + +        """Get all of the tasks for a given user.""" + +        owner = get_object_or_404(Owner, user__username=username) + +        tasks = Task.objects.filter(owner=owner).all() + +        serialized = TaskSerializer(tasks, many=True) + +        return JsonResponse({ + +            'username': username, + +            'tasks': serialized.data + +        }) + +``` + +There's a lot going on here in a little bit of code, so let's walk through it. + +We start out with the same inheritance of the `APIView` that we've been using, laying the groundwork for what will be our view. We override the same `get` method we've overridden before, adding a parameter that allows our view to receive the `username` from the incoming request. + +Our `get` method will then use that `username` to grab the `Owner` associated with that user. This `get_object_or_404` function allows us to do just that, with a little something special added for ease of use. + +It would make sense that there's no point in looking for tasks if the specified user can't be found. In fact, we'd want to return a 404 error. `get_object_or_404` gets a single object based on whatever criteria we pass in and either returns that object or raises an [Http404 exception][18]. We can set that criteria based on attributes of the object. The `Owner` objects are all attached to a `User` through their `user` attribute. We don't have a `User` object to search with, though. We only have a `username`. So, we say to `get_object_or_404` "when you look for an `Owner`, check to see that the `User` attached to it has the `username` that I want" by specifying `user__username`. That's TWO underscores. When filtering through a QuerySet, the two underscores mean "attribute of this nested object." Those attributes can be as deeply nested as needed. + +We now have the `Owner` corresponding to the given username. We use that `Owner` to filter through all the tasks, only retrieving the ones it owns with `Task.objects.filter`. We could've used the same nested-attribute pattern that we did with `get_object_or_404` to drill into the `User` connected to the `Owner` connected to the `Tasks` (`tasks = Task.objects.filter(owner__user__username=username).all()`) but there's no need to get that wild with it. + +`Task.objects.filter(owner=owner).all()` will provide us with a `QuerySet` of all the `Task` objects that match our query. Great. The `TaskSerializer` will then take that `QuerySet` and all its data, along with the flag of `many=True` to notify it as being a collection of items instead of just one item, and return a serialized set of results. Effectively a list of dictionaries. Finally, we provide the outgoing response with the JSON-serialized data and the username used for the query. + +#### Handling the POST request + +The `post` method will look somewhat different from what we've seen before. +``` +# still in todo/views.py + +# ...other imports... + +from rest_framework.parsers import JSONParser + +from datetime import datetime + + + +class TaskListView(APIView): + +    def get(self, request, username, format=None): + +        ... + + + +    def post(self, request, username, format=None): + +        """Create a new Task.""" + +        owner = get_object_or_404(Owner, user__username=username) + +        data = JSONParser().parse(request) + +        data['owner'] = owner.id + +        if data['due_date']: + +            data['due_date'] = datetime.strptime(data['due_date'], '%d/%m/%Y %H:%M:%S') + + + +        new_task = TaskSerializer(data=data) + +        if new_task.is_valid(): + +            new_task.save() + +            return JsonResponse({'msg': 'posted'}, status=201) + + + +        return JsonResponse(new_task.errors, status=400) + +``` + +When we receive data from the client, we parse it into a dictionary using `JSONParser().parse(request)`. We add the owner to the data and format the `due_date` for the task if one exists. + +Our `TaskSerializer` does the heavy lifting. It first takes in the incoming data and translates it into the fields we specified on the model. It then validates that data to make sure it fits the specified fields. If the data being attached to the new `Task` is valid, it constructs a new `Task` object with that data and commits it to the database. We then send back an appropriate "Yay! We made a new thing!" response. If not, we collect the errors that `TaskSerializer` generated and send those back to the client with a `400 Bad Request` status code. + +If we were to build out the `put` view for updating a `Task`, it would look very similar to this. The main difference would be that when we instantiate the `TaskSerializer`, instead of just passing in the new data, we'd pass in the old object and the new data for that object like `TaskSerializer(existing_task, data=data)`. We'd still do the validity check and send back the responses we want to send back. + +### Wrapping up + +Django as a framework is highly customizable, and everyone has their own way of stitching together a Django project. The way I've written it out here isn't necessarily the exact way that a Django project needs to be set up; it's just a) what I'm familiar with, and b) what leverages Django's management system. Django projects grow in complexity as you separate concepts into their own little silos. You do that so it's easier for multiple people to contribute to the overall project without stepping on each other's toes. + +The vast map of files that is a Django project, however, doesn't make it more performant or naturally predisposed to a microservice architecture. On the contrary, it can very easily become a confusing monolith. That may still be useful for your project. It may also make it harder for your project to be manageable, especially as it grows. + +Consider your options carefully and use the right tool for the right job. For a simple project like this, Django likely isn't the right tool. + +Django is meant to handle multiple sets of models that cover a variety of different project areas that may share some common ground. This project is a small, two-model project with a handful of routes. If we were to build this out more, we'd only have seven routes and still the same two models. It's hardly enough to justify a full Django project. + +It would be a great option if we expected this project to expand. This is not one of those projects. This is choosing a flamethrower to light a candle. It's absolute overkill. + +Still, a web framework is a web framework, regardless of which one you use for your project. It can take in requests and respond as well as any other, so you do as you wish. Just be aware of what overhead comes with your choice of framework. + +That's it! We've reached the end of this series! I hope it has been an enlightening adventure and will help you make more than just the most-familiar choice when you're thinking about how to build out your next project. Make sure to read the documentation for each framework to expand on anything covered in this series (as it's not even the least bit comprehensive). There's a wide world of stuff to get into for each. Happy coding! + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/8/django-framework + +作者:[Nicholas Hunt-Walker][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://opensource.com/users/nhuntwalker +[1]:https://opensource.com/article/18/5/pyramid-framework +[2]:https://opensource.com/article/18/4/flask +[3]:https://opensource.com/article/18/6/tornado-framework +[4]:https://www.djangoproject.com +[5]:https://djangopackages.org/ +[6]:http://www.django-rest-framework.org/ +[7]:http://gunicorn.org/ +[8]:https://docs.pylonsproject.org/projects/waitress/en/latest/ +[9]:https://uwsgi-docs.readthedocs.io/en/latest/ +[10]:https://docs.djangoproject.com/en/2.0/ref/settings/#databases +[11]:https://pypi.org/project/dj-database-url/ +[12]:http://yellerapp.com/posts/2015-01-12-the-worst-server-setup-you-can-make.html +[13]:https://docs.djangoproject.com/en/2.0/ref/settings/#std:setting-DATABASE-ENGINE +[14]:https://www.getpostman.com/ +[15]:http://www.django-rest-framework.org/api-guide/serializers/#modelserializer +[16]:http://www.django-rest-framework.org/api-guide/serializers/ +[17]:http://www.django-rest-framework.org/api-guide/serializers/#serializers +[18]:https://docs.djangoproject.com/en/2.0/topics/http/views/#the-http404-exception diff --git a/sources/tech/20180816 Designing your garden with Edraw Max - FOSS adventures.md b/sources/tech/20180816 Designing your garden with Edraw Max - FOSS adventures.md new file mode 100644 index 0000000000..bcd5c0bda8 --- /dev/null +++ b/sources/tech/20180816 Designing your garden with Edraw Max - FOSS adventures.md @@ -0,0 +1,74 @@ +Designing your garden with Edraw Max – FOSS adventures +====== + +I watch a lot of [BBC Gardeners World][1], which gives me a lot of inspiration for making changes to my own garden. I tried looking for a free and open source program for designing gardens in the openSUSE [package search][2]. The only application that I found was Rosegarden, a MIDI and Audio Sequencer and Notation Editor. Using google, I found [Edraw Max][3], an all-in-one diagram software. This included a Floor planner, including templates for garden design. And there are download options for various Linux distributions, including openSUSE. + +### Installation + +You can download a 14-day free trial from the Edraw Max [website][4]. + +![][5] + +The next thing to do, is use Dolphin and browse to your Downloads folder. Find the zipped package and double click it. Ark will automatically load it. Then click on the Extract button. + +![][6] + +Now you can press F4 in Dolphin to open the integrated terminal. If you type in the commands as listed on the Edraw website, the application will install without an issue. + +![][7] + +### Experience + +From the application launcher (start menu), you can now type Edraw Max and launch the application. Go to New and then Floor Plan and click on Garden Design. + +![][8] + +On the left side, there is a side pane with a lot of elements that you can use for drawing (see picture below). Start with measuring your garden and with the walls, you can ‘draw’ the borders of your garden. On the right side, there is a side pane where you can adjust the properties of these elements. For instance you can edit the fill (color) of the element, the border (color) of the element and adjust the properties. I didn’t need the other parts of this right side pane (which included shadow, insert picture, layer, hyperlink, attachment and comments). + +![][9] + +Now you can make various different garden designs! This is one of the 6 designs that I created for my own garden. + +![][10] + +The last feature that I like to mention is the export possibilities. There is a lot of export options here, including Jpeg, Tiff, PDF, PS, EPS, Word, PowerPoint, Excel, HTML, SVG and Visio. In the unlicensed version, all exports work except for the Visio export. In the PDF you will see a watermark “Created by Unlicensed Version”. + +![][11] + +### Conclusion + +As this is proprietary software, you will have to pay for it after 14 days. Unfortunately, the price is quite high. As a Linux user, you can only select the [Lifetime license][12], which currently costs $ 245. It is a very complete package (280 different types of diagrams), but I find the pricing too high for my purposes. And there is no option to pay less. For professional users I can imagine that this price would not be a big issue, as the software will pay itself back when you get payed for making designs. For me personally, it was a very nice experience to use this limited trial and it helped me to think of different ways in which I can redesign my garden. + +**Published on: 16 august 2018** + +### A FOSS alternative found! + +Thanks to reddit user compairelapin, I have found an open source alternative. It is called Sweet Home 3D and its available in the [openSUSE package search][13]. In a future post, I will take a look at this software and compare it to Edraw Max. + +**Updated on: 17 august 2018** + +-------------------------------------------------------------------------------- + +via: https://www.fossadventures.com/designing-your-garden-with-edraw-max/ + +作者:[Martin De Boer][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.fossadventures.com/author/martin_de_boer/ +[1]:https://www.bbc.co.uk/programmes/b006mw1h +[2]:https://software.opensuse.org/ +[3]:https://www.edrawsoft.com/edraw-max.php +[4]:https://www.edrawsoft.com/download-edrawmax.php +[5]:https://www.fossadventures.com/wp-content/uploads/2018/08/Edraw-Max-01-1024x463.jpeg +[6]:https://www.fossadventures.com/wp-content/uploads/2018/08/Edraw-Max-03.jpeg +[7]:https://www.fossadventures.com/wp-content/uploads/2018/08/Edraw-Max-04.jpeg +[8]:https://www.fossadventures.com/wp-content/uploads/2018/08/Edraw-Max-05.jpeg +[9]:https://www.fossadventures.com/wp-content/uploads/2018/08/Edraw-Max-06.jpeg +[10]:https://www.fossadventures.com/wp-content/uploads/2018/08/Edraw-Max-07.jpeg +[11]:https://www.fossadventures.com/wp-content/uploads/2018/08/Edraw-Max-08.jpeg +[12]:https://www.edrawsoft.com/orderedrawmax.php +[13]:https://software.opensuse.org/package/SweetHome3D diff --git a/sources/tech/20180816 Garbage collection in Perl 6.md b/sources/tech/20180816 Garbage collection in Perl 6.md new file mode 100644 index 0000000000..725d0f6f50 --- /dev/null +++ b/sources/tech/20180816 Garbage collection in Perl 6.md @@ -0,0 +1,121 @@ +Garbage collection in Perl 6 +====== + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/garbage-trash-waste.png?itok=2jisoOXn) + +In the [first article][1] in this series on migrating Perl 5 code to Perl 6, we looked into some of the issues you might encounter when porting your code. In this second article, we’ll get into how garbage collection differs in Perl 6. + +There is no timely destruction of objects in Perl 6. This revelation usually comes as quite a shock to people used to the semantics of object destruction in Perl 5. But worry not, there are other ways in Perl 6 to get the same behavior, albeit requiring a little more thought by the developer. Let’s first examine a little background on the situation in Perl 5. + +### Reference counting + +In Perl 5, timely destruction of objects “going out of scope” is achieved by [reference counting][2]. When something is created in Perl 5, it has a reference count of 1 or more, which keeps it alive. In its simplest case it looks like this: +``` +{ + +    my $a = 42;  # reference count of $a = 1, because lives in lexical pad + +} + +# lexical pad is gone, reference count to 0 + +``` + +In Perl 5, if the value is an object (aka blessed), the `DESTROY` method will be called on it. +``` +{ + +    my $a = Foo->new; + +} + +# $a->DESTROY called + +``` + +If no external resources are involved, timely destruction is just another way of managing memory used by a program. And you, as a programmer, shouldn’t need to care about how and when things get recycled. Having said that, timely destruction is a very nice feature to have if you need to deal with external resources, such as database handles (of which there are generally only a limited number provided by the database server). And reference counting can provide that. + +However, reference counting has several drawbacks. It has taken Perl 5 core developers many years to get reference counting working correctly. And if you’re working in [XS][3], you always need to be aware of reference counting to prevent memory leakage or premature destruction. + +Keeping things in sync gets more difficult in a multi-threaded environment, as you do not want to lose any updates to references made from multiple threads at the same time (as that would cause memory leakage and/or external resources to not be released). To circumvent that, some kind of locking or atomic updates would be needed, neither of which are cheap. + +> Please note that Perl 5 ithreads are more like an in-memory fork with unshared memory between interpreters than threads in programming languages such as C. So, it still doesn’t need any locking for its reference counting. + +Reference counting also has the basic drawback that if two objects contain references to each other, they will never be destroyed as they keep each other’s reference count above 0 (a circular reference). In practice, this often goes much deeper, more like `A -> B -> C -> A`, where A, B, and C are all keeping each other alive. + +The concept of a weak reference was developed to circumvent these situations in Perl 5. Although this can fix the circular reference issue, it has performance implications and doesn’t fix the problem of having (and finding) circular references in the first place. You need to be able to find out where a weak reference can be used in the best way; otherwise, you might get unwanted premature object destruction. + +### Reachability analysis + +Since Perl 6 is multi-threaded in its core, it was decided at a very early stage that reference counting would be problematic performance-wise and maintenance-wise. Instead, objects are evicted from memory when more memory is needed and the object can be safely removed. + +`DESTROY` method, just as you can in Perl 5. But you cannot be sure when (if ever) it will be called. + +In Perl 6 you can create amethod, just as you can in Perl 5. But you cannot be sure when (if ever) it will be called. + +Without getting into [too much detail][4], objects in Perl 6 are destroyed only when a garbage collection run is initiated, e.g., when a certain memory limit has been reached. Only then, if an object cannot be reached anymore by other objects in memory and it has a `DESTROY` method, will it be called just prior to the object being removed. + +No garbage collection is done by Perl 6 when a program exits. Applicable [phasers][5] (such as `LEAVE` and `END`) will get called, but no garbage collection will be done other than what is (indirectly) initiated by the code run in the phasers. + +If you always need an orderly shutdown of external resources used by your program (such as database handles), you can use a phaser to make sure the external resource is freed in a proper and timely manner. + +For example, you can use the `END` phaser (known as an `END` block in Perl 5) to disconnect properly from a database when the program exits (for whatever reason): +``` +my $dbh = DBIish.connect( ... ) or die "Couldn't connect"; + +END $dbh.disconnect;DBIishENDdisconnect + +``` + +Note that the `END` phaser does not need to have a block (like `{ ... }`) in Perl 6. If it doesn’t, the code in the phaser shares the lexical pad (lexpad) with the surrounding code. + +There is one flaw in the code above: If the program exits before the database connection is made or if the database connection failed for whatever reason, it will still attempt to call the `.disconnect` method on whatever is in `$dbh`, which will result in an execution error. There is however a simple idiom to circumvent this situation in Perl 6 [using with][6]. +``` +END .disconnect with $dbh; + +``` + +The postfix `with` matches only if the given value is defined (generally, an instantiated object) and then topicalizes it to `$_`. The `.disconnect` is short for `$_.disconnect`. + +If you would like to have an external resource clean up whenever a specific scope is exited, you can use the `LEAVE` phaser inside that scope. +``` +if DBIish.connect( ... ) -> $dbh { + +    LEAVE $dbh.disconnect;  # no need for `with` here + +    # do your stuff with the database + +} + +else { + +    say "Could not do the stuff that needed to be done"; + +}DBIishLEAVEdisconnectsay + +``` + +Whenever the scope of the `if` is left, any `LEAVE` phaser will be executed. Thus the database resource will be freed whenever the code has run in that scope. + +### Summary + +Even though Perl 6 does not have the timely destruction of objects that Perl 5 users are used to, it does have easy-to-use alternative ways to ensure management of external resources, similar to those in Perl 5. + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/8/garbage-collection-perl-6 + +作者:[Elizabeth Mattijsen][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://opensource.com/users/lizmat +[1]:https://opensource.com/article/18/7/migrating-perl-5-perl-6 +[2]:https://en.wikipedia.org/wiki/Reference_counting +[3]:https://en.wikipedia.org/wiki/XS_%28Perl%29 +[4]:https://github.com/MoarVM/MoarVM/blob/master/docs/gc.markdown +[5]:https://docs.perl6.org/language/phasers +[6]:https://docs.perl6.org/syntax/with%20orwith%20without diff --git a/sources/tech/20180817 AryaLinux- A Distribution and a Platform.md b/sources/tech/20180817 AryaLinux- A Distribution and a Platform.md new file mode 100644 index 0000000000..7e2509948a --- /dev/null +++ b/sources/tech/20180817 AryaLinux- A Distribution and a Platform.md @@ -0,0 +1,224 @@ +AryaLinux: A Distribution and a Platform +====== + +![](https://www.linux.com/sites/lcom/files/styles/rendered_file/public/arya-desktop.jpg?itok=pQdYoZ5O) + +Most Linux distributions are simply that: A distribution of Linux that offers a variation on an open source theme. You can download any of those distributions, install it, and use it. Simple. There’s very little mystery to using Linux these days, as the desktop is incredibly easy to use and server distributions are required in business. + +But not every Linux distribution ends with that idea; some go one step further and create both a distribution and a platform. Such is the case with [AryaLinux][1]. What does that mean? Easy. AryaLinux doesn’t only offer an installable, open source operating system, they offer a platform with which users can build a complete GNU/Linux operating system. The provided scripts were created based on the instructions from [Linux From Scratch][2] and [Beyond Linux From Scratch][3]. + +If you’ve ever attempted to build you own Linux distribution, you probably know how challenging it can be. AryaLinux has made that process quite a bit less stressful. In fact, although the build can take quite a lot of time (up to 48 hours), the process of building the AryaLinux platform is quite easy. + +But don’t think that’s the only way you can have this distribution. You can download a live version of AryaLinux and install as easily as if you were working with Ubuntu, Linux Mint, or Elementary OS. + +Let’s get AryaLinux up and running from the live distribution and then walk through the process of building the platform, using the special builder image. + +### The Live distribution + +From the [AryaLinux download pag][4]e, you can get a version of the operating system that includes either [GNOME][5] or [Xfce][6]. I chose the GNOME route and found it to be configured to include Dash to dock and Applications menu extensions. Both of these will please most average GNOME users. Once you’ve downloaded the ISO image, burn it to either a DVD/CD or to a USB flash drive and boot up the live instance. Do note, you need to have at least 25GB of space on a drive to install AryaLinux. If you’re planning on testing this out as a virtual machine, create a 30-40 GB virtual drive, otherwise the installer will fail every time. + +Once booted, you will be presented with a login screen, with the default user selected. Simply click the user and login (there is no password required). + +To locate the installer, click the Applications menu, click Activities Overview, type “installer” and click on the resulting entry. This will launch the AryaLinux installer … one that looks very familiar to many Linux installers (Figure 1). + +![AryaLinux installer][8] + +Figure 1: The AryaLinux installer is quite easy to navigate. + +[Used with permission][9] + +In the next window (Figure 2), you are required to define a root partition. To do this, type “/” (no quotes) in the Choose the root partition section. + +![root partition][11] + +Figure 2: Defining your root partition for the AryaLinux installation. + +[Used with permission][9] + +If you don’t define a home partition, it will be created for you. If you don’t define a swap partition, none will be created. If you have a need to create a home partition outside of the standard /home, do it here. The next installation windows have you do the following: + + * Create a standard user. + + * Create an administrative password. + + * Choose locale and keyboard. + + * Choose your timezone. + + + + +That’s all there is to the installation. Once it completes, reboot, remove the media (or delete the .iso from your Virtual Machine storage listing), and boot into your newly-installed AryaLinux operating system. + +### What’s there? + +Out of the box, you should find everything necessary to use AryaLinux as a full-functioning desktop distribution. Included is: + + * LibreOffice + + * Rhythmbox + + * Files + + * GNOME Maps + + * GIMP + + * Simple Scan + + * Chromium + + * Transmission + + * Avahi SSH/VNC Server Browser + + * Qt5 Assistant/Designer/Linguist/QDbusViewer + + * Brasero + + * Cheese + + * Echomixer + + * VLC + + * Network Tools + + * GParted + + * dconf Editor + + * Disks + + * Disk Usage Analyzer + + * Document Viewer + + * And more + + + + +### The caveats + +It should be noted that this is the first official release of AryaLinux, so there will be issues. Right off the bat I realized that no matter what I tried, I could not get the terminal to open. Unfortunately, the terminal is a necessary tool for this distribution, as there is no GUI for updating or installing packages. In order to get to a bash prompt, I had to use a virtual screen. That’s when the next caveat came into play. The package manager for AryaLinux is alps, but its primary purpose is working in conjunction with the build scripts to install the platform. Unfortunately there is no included man page for alps on AryaLinux and the documentation is very scarce. Fortunately, the developers did think to roll in Flatpak support, so if you’re a fan of Flatpak, you can install anything you need (so long as it’s available as a flatpak package) using that system. + +### Building the platform + +Let’s talk about building the AryaLinux platform. This isn’t much harder than installing the standard distribution, only it’s done via the command line. Here’s what you do: + + 1. Download the [AryaLinux Builder Disk][12]. + + 2. Burn the ISO to either DVD/CD or USB flash drive. + + 3. Boot the live image. + + 4. Once you reach the desktop, open a terminal window from the menu. + + 5. Change to the root user with the command sudo su. + + 6. Change directories with the command cd aryalinux/base-system + + 7. Run the build script with the command ./build-arya + + + + +You will first be asked if you want to start a fresh build or resume a build (Figure 3). Remember, the AryaLinux build takes a LOT of time, so there might be an instance where you’ve started a build and need to resume. + +![AryaLinux build][14] + +Figure 3: Running the AryaLinux build script. + +[Used with permission][9] + +To start a new build, type “1” and then hit Enter on your keyboard. You will now be asked to define a number of options (in order to fulfill the build script requirements). Those options are: + + * Bootloader Device + + * Root Partition + + * Home Partition + + * Locale + + * OS Name + + * OS Version + + * OS Codename + + * Domain Name + + * Keyboard Layout + + * Printer Paper Size + + * Enter Full Name + + * Username + + * Computer Name + + * Use multiple cores for build (y/n) + + * Create backups (y/n) + + * Install X Server (y/n) + + * Install Desktop Environment (y/n) + + * Choose Desktop Environment (XFCE, Mate, KDE, GNOME) + + * Do you want to configure advanced options (y/n) + + * Create admin password + + * Create password for standard user + + * Install bootloader (y/n) + + * Create Live ISO (y/n) + + * Select a timezone + + + + +After you’ve completed the above, the build will start. Don’t bother watching it, as it will take a very long time to complete (depending upon your system and network connection). In fact, the build can take anywhere from 8-48 hours. After the build completes, reboot and log into your newly built AryaLinux platform. + +### Who is AryaLinux for? + +I’ll be honest, if you’re just a standard desktop user, AryaLinux is not for you. Although you can certainly get right to work on the desktop, if you need anything outside of the default applications, you might find it a bit too much trouble to bother with. If, on the other hand, you’re a developer, AryaLinux might be a great platform for you. Or, if you just want to see what it’s like to build a Linux distribution from scratch, AryaLinux is a pretty easy route. + +Even with its quirks, AryaLinux holds a lot of promise as both a Linux distribution and platform. If the developers can see to it to build a GUI front-end for the alps package manager, AryaLinux could make some serious noise. + +Learn more about Linux through the free ["Introduction to Linux" ][15]course from The Linux Foundation and edX. + +-------------------------------------------------------------------------------- + +via: https://www.linux.com/learn/intro-to-linux/2018/8/aryalinux-distribution-and-platform + +作者:[Jack Wallen][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.linux.com/users/jlwallen +[1]:http://aryalinux.org +[2]:http://www.linuxfromscratch.org/ +[3]:http://www.linuxfromscratch.org/blfs/ +[4]:http://aryalinux.org/downloads/ +[5]:https://sourceforge.net/projects/aryalinux/files/releases/1.0/aryalinux-gnome-1.0-x86_64-fixed.iso +[6]:https://sourceforge.net/projects/aryalinux/files/releases/1.0/aryalinux-xfce-1.0-x86_64.iso +[7]:/files/images/aryalinux1jpg +[8]:https://www.linux.com/sites/lcom/files/styles/rendered_file/public/aryalinux_1.jpg?itok=vR11z5So (AryaLinux installer) +[9]:/licenses/category/used-permission +[10]:/files/images/aryalinux2jpg +[11]:https://www.linux.com/sites/lcom/files/styles/rendered_file/public/aryalinux_2.jpg?itok=Lm50af-y (root partition) +[12]:https://sourceforge.net/projects/aryalinux/files/releases/1.0/aryalinux-builder-1.0-x86_64.iso +[13]:/files/images/aryalinux3jpg +[14]:https://www.linux.com/sites/lcom/files/styles/rendered_file/public/aryalinux_3.jpg?itok=J-GUq99C (AryaLinux build) +[15]:https://training.linuxfoundation.org/linux-courses/system-administration-training/introduction-to-linux diff --git a/sources/tech/20180817 Cloudgizer- An introduction to a new open source web development tool.md b/sources/tech/20180817 Cloudgizer- An introduction to a new open source web development tool.md new file mode 100644 index 0000000000..3692ad05c5 --- /dev/null +++ b/sources/tech/20180817 Cloudgizer- An introduction to a new open source web development tool.md @@ -0,0 +1,282 @@ +Cloudgizer: An introduction to a new open source web development tool +====== + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/bus_cloud_database.png?itok=lhhU42fg) + +[Cloudgizer][1] is a free open source tool for building web applications. It combines the ease of scripting languages with the performance of [C][2], helping manage the development effort and run-time resources for cloud applications. + +Cloudgizer works on [Red Hat][3]/[CentOS][4] Linux with the [Apache web server][5] and [MariaDB database][6]. It is licensed under [Apache License version 2][7]. + +### Hello World + +In this example, we output an [HTTP][8] header and Hello World, followed by a horizontal line: +``` +#include "cld.h" + +void home() +{ +   /*< +   output-http-header + +   Hello World! +   
+   >*/ +} +``` + +Cloudgizer code is written as a C comment with `/*<` and `>*/` at the beginning and ending, respectively. + +Writing output to the web client is as simple as directly writing [HTML][9] code in your source. There are no API calls or special markups for that—simplicity is good because HTML (or [JavaScript][10], [CSS][11], etc.) will probably comprise a good chunk of your code. + +### How it works + +Cloudgizer source files (with a `.v` extension) are translated into C code by the `cld` command-line tool. C code is then compiled and linked with the web server and your application is ready to be used. For instance, generated code for the source file named `home.v` would be `__home.c`, if you'd like to examine it. + +Much of your code will be written as "markups," small snippets of intuitive and descriptive code that let you easily do things like the following: + + * database queries + * web programming + * encoding and encryption + * executing programs + * safe string manipulation + * file operations + * sending emails + + + +and other common tasks. For less common tasks, there is an API that covers broader functionality. And ultimately, you can write any C code and use any libraries you wish to complete your task. + +The `main()` function is generated by Cloudgizer and is a part of the framework, which provides Apache and database integration and other services. One such service is tracing and debugging (including memory garbage collection, underwrite/overwrite detection, run-time HTML linting, etc.). A program crash produces a full stack, including the source code lines, and the crash report is emailed to you the moment it happens. + +A Cloudgizer application is linked with the Apache server as an Apache module in a pre-fork configuration. This means the Apache web server will pre-fork a number of processes and direct incoming requests to them. The Apache module mechanism provides high-performance request handling for applications. + +All Cloudgizer applications run under the same Linux user, with each application separated under its own application directory. This user is also the Apache user; i.e., the user running the web server. + +Each application has its own database with the name matching that of the application. Cloudgizer establishes and maintains database connections across requests, increasing performance. + +### Development process + +The process of compiling your source code and building an installation file is automated. By using the `cldpackapp` script, you’ll transform your code into pure C code and create an installation file (a [.tar.gz file][12]). The end user will install this file with the help of a configuration file called `appinfo`, producing a working web application. This process is straightforward: + +![](https://opensource.com/sites/default/files/uploads/process_cloudgizer.jpg) + +The deployment process is designed to be automated if needed, with configurable parameters. + +### Getting started + +The development starts with installing [the Example application][13]. This sets up the development environment; you start with a Hello World and build up your application from there. + +The Example application also serves as a smoke test because it has a number of code snippets that test various Cloudgizer features. It also gives you a good amount of example code (hence the name). + +There are two files to be aware of as you start: + + * `cld_handle_request.v` is where incoming requests (such as `GET`, `POST`, or a command-line execution) are processed. + * `sourcelist` lists all your source code so that Cloudgizer can make your application. + + + +In addition to `cld_handle_request.v`, `oops.v` implements an error handler, and `file_too_large.v` implements a response to an upload that's too large. These are already implemented in the Example application, and you can keep them as they are or tweak them. + +Use `cldbuild` to recompile source-file (`.v`) changes, and `cldpackapp` to create an installer file for testing or release delivery via `cldgoapp`: + +![](https://opensource.com/sites/default/files/uploads/how_0_0.jpg) + +Deployment via `cldgoapp` lets you install an application from scratch or update from one version to another. + +### Example + +Here's a stock-ticker application that updates and reports on ticker prices. It is included in the Example application. + +#### The code + +The request handler checks the URL query parameter page, and if it's `stock`, it calls `function stock()`: +``` +#include "cld.h" + +void cld_handle_request() +{ +  /*< +  input-param page +  +  if-string page="stock" +      c stock (); +  else +      report-error "Unrecognized page %s", page +  end-if +  >*/ +} +``` + +The implementation of function `stock()` would be in file `stock.v`. The code adds a stock ticker if the URL query parameter action is `add` or shows all stock tickers if it is `show`. +``` +#include "cld.h" + +void stock() +{ +   /*< + +   output-http-header + +    +        +       input-param action + +       if-string action="add" +           input-param stock_name +           input-param stock_price + +           run-query#add_data = "insert into stock \ +               (stock_name, stock_price) values \ +               (, ) \ +               on duplicate key update \ +               stock_price=" + +               query-result#add_data, error as \ +                   define err + +               if atoi(err) != 0 +                   report-error "Cannot update \ +                       stock price, error [%s]",err +               end-if +           end-query + +           
+               Stock price updated! +           
+       else-if-string action="show" +            +                +                    +                    +                +           run-query#show_data = "select stock_name, \ +               stock_price from stock" + +                +                    +                    +                +           end-query +           
Stock nameStock price
+                   query-result#show_data, stock_name +                    +                   query-result#show_data, stock_price +                   
+       else +           
Unrecognized request!
+       end-if +        +    +   >*/ +} +``` + +#### The database table + +The SQL table used would be: +``` +create table stock (stock_name varchar(100) primary key, stock_price bigint); +``` + +#### Making and packaging + +To include `stock.v` in your Cloudgizer application, simply add it to the sourcelist file: +``` +SOURCE_FILES=stock.v .... +... +stock.o : stock.v $(CLDINCLUDE)/cld.h $(HEADER_FILES) +... +``` + +To recompile changes to your code, use: +``` +cldbuild +``` + +To package your application for deployment, use: +``` +cldpackapp +``` + +When packaging an application, all additional objects you create (other than source code files), should be included in the `create.sh` file. This file sets up anything that the Cloudgizer application installer doesn't do; in this case, create the above SQL table. For example, the following code in your `create.sh` might suffice: +``` +echo -e "drop table if exists stock;\ncreate table stock (stock_name varchar(100) primary key, stock_price bigint);" | mysql -u root -p$CLD_DB_ROOT_PWD -D $CLD_APP_NAME +``` + +In `create.sh`, you can use any variables from the `appinfo` file (an installation configuration file). Those variables always include `CLD_DB_ROOT_PWD` (the root password database, which is always automatically cleared after installation for security), `CLD_APP_NAME` (the application and database name), `CLD_SERVER` (the URL of the installation server), `CLD_EMAIL` (the administration and notification email address), and others. You also have `CLD_APP_HOME_DIR` (the application's home directory) and `CLD_APP_INSTALL_DIR` (the location where the installation .tar.gz file had been unzipped so you can copy files from it). You can include any other variables in the `appinfo` file that you find useful. + +#### Using the application + +If your application name is 'myapp' running on myserver.com, then the URL to update a stock ticker would be this: +``` +https://myserver.com/go.myapp?page=stock&action=add&stock_name=RHT&stock_price=500 +``` + +and the URL to show all stock tickers would be this: +``` +https://myserver.com/go.myapp?page=stock&action=show +``` + +(The URL path for all Cloudgizer applications always starts with `go.`; in this case, `go.myapp`.) + +### Download and more examples + +For more examples or download and installation details, visit [Zigguro.org/cloudgizer][14]. You'll also find the above example included in the installation (see [the Example application source code][15]). + +For a much larger real-world example, check out the [source code][16] for [Rentomy][17], a free open source cloud application for rental property managers, written entirely in Cloudgizer and consisting of over 32,000 lines of code. + +### Why use Cloudgizer? + +Here's why Rentomy is written in Cloudgizer: + +Originally, the goal was to use one of the popular [scripting languages][18] or [process virtual machines][19] like [Java][20], and to host Rentomy as a [Software-as-a-Service][21] (Saas) free of charge. + +Since there are nearly 50 million rental units in the US alone, a free service like this needs superior software performance. + +So squeezing more power from CPUs and using less RAM became very important. And with [Moore's Law slowing down][22], the bloat of popular web languages is costing more computing resources—we're talking about process-virtual machines, interpreters, [p-code generators][23], etc. + +Debugging can be a pain because more layers of abstraction exist between you and what's really going on. Not every library can be easily used, so some functional and interoperability limitations remain. + +On the other hand, in terms of big performance and a small footprint, there is no match for C. Most libraries are written in C for the same reason, so virtually any library you need is available, and debugging is straightforward. + +However, C has issues with memory and overall safety (overwrites, underwrites, garbage collection, etc.), usability (it is low-level), application packaging, etc. And equally important, much of the development cost lies in the ease of writing and debugging the code and in its accessibility to novices. + +From this perspective, Cloudgizer was born. Greater performance and a smaller footprint mean cheaper computing power. Easy, stable coding brings Zen to the development process, as does the ability to manage it better. + +In hindsight, using Cloudgizer to build Rentomy was like using a popular scripting language without the issues. + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/8/cloudgizer-intro + +作者:[Sergio Mijares][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://opensource.com/users/sergio-mijares +[1]:https://zigguro.org/cloudgizer/ +[2]:https://en.wikipedia.org/wiki/C_%28programming_language%29 +[3]:https://www.redhat.com/en +[4]:https://www.centos.org/ +[5]:http://httpd.apache.org/ +[6]:https://mariadb.com/ +[7]:http://www.apache.org/licenses/LICENSE-2.0 +[8]:https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol +[9]:https://en.wikipedia.org/wiki/HTML +[10]:https://en.wikipedia.org/wiki/JavaScript +[11]:https://en.wikipedia.org/wiki/Cascading_Style_Sheets +[12]:https://opensource.com/article/17/7/how-unzip-targz-file +[13]:https://zigguro.org/cloudgizer/#install +[14]:https://zigguro.org/cloudgizer +[15]:https://bitbucket.org/zigguro/cloudgizer_example/src +[16]:https://bitbucket.org/zigguro/rentomy/src +[17]:https://zigguro.org/rentomy/ +[18]:https://en.wikipedia.org/wiki/Scripting_language +[19]:https://en.wikipedia.org/wiki/Virtual_machine +[20]:https://www.java.com/en/ +[21]:https://en.wikipedia.org/wiki/Software_as_a_service +[22]:https://www.engineering.com/ElectronicsDesign/ElectronicsDesignArticles/ArticleID/17209/DARPAs-100-Million-Programs-for-a-Silicon-Compiler-and-a-New-Open-Hardware-Ecosystem.aspx +[23]:https://en.wikipedia.org/wiki/P-code_machine diff --git a/sources/tech/20180817 How To Lock The Keyboard And Mouse, But Not The Screen In Linux.md b/sources/tech/20180817 How To Lock The Keyboard And Mouse, But Not The Screen In Linux.md new file mode 100644 index 0000000000..d3c729f1d0 --- /dev/null +++ b/sources/tech/20180817 How To Lock The Keyboard And Mouse, But Not The Screen In Linux.md @@ -0,0 +1,190 @@ +How To Lock The Keyboard And Mouse, But Not The Screen In Linux +====== + +![](https://www.ostechnix.com/wp-content/uploads/2017/09/Lock-The-Keyboard-And-Mouse-720x340.jpg) + +My 4-years-old niece is a curious-kid. She loves “Avatar” movie very much. When the Avatar movie is on, she became so focused and her eyes are glued to the screen. But the problem is she often touches a key in the keyboard or move the mouse or click the mouse button while watching the movie. Sometimes, she accidentally close or pause the movie by pressing a key in the keyboard. So I was looking for a way to lock down both the keyboard and mouse, but not the screen. Luckily, I came across a perfect solution in Ubuntu forum. If you don’t want your cat or puppy walking on your keyboard or your kid messing up with the keyboard and mouse while you watching something important on the screen, I suggest you to try **“xtrlock”** utility. It is a simple, yet useful utility to lock the X display till the user enters their password at the keyboard. In this brief tutorial, I will show you how to lock the keyboard and mouse, but not the screen in Linux. This trick will work on all Linux operating systems. + +### Install xtrlock + +The xtrlock package is available in the default repositories of most Linux operating systems. So, you can install it using your distribution’s package manager. + +On **Arch Linux** and derivatives, run the following command to install it. +``` +$ sudo pacman -S xtrlock + +``` + +On **Fedora** : +``` +$ sudo dnf install xtrlock + +``` + +On **RHEL, CentOS** : +``` +$ sudo yum install xtrlock + +``` + +On **SUSE/openSUSE** : +``` +$ sudo zypper install xtrlock + +``` + +On **Debian, Ubuntu, Linux Mint** : +``` +$ sudo apt-get install xtrlock + +``` + +### Lock the Keyboard and Mouse, but not the Screen using xtrlock + +Once xtrlock installed, create a keyboard shortcut. You need this to lock the keyboard and mouse using the key combination of your choice. + +Create a new file called **lockkbmouse** in **/usr/local/bin**. +``` +$ sudo vi /usr/local/bin/lockkbmouse + +``` + +Add the following lines into it. +``` +#!/bin/bash +sleep 1 && xtrlock + +``` + +Save the file and close the file. + +Make it as executable using the following command: +``` +$ sudo chmod a+x /usr/local/bin/lockkbmouse + +``` + +Next, we need to create keyboard a shortcut. + +**In Arch Linux MATE desktop:** + +Go to **System - > Preferences -> Hardware -> keyboard Shortcuts**. + +Click **Add** to create a new shortcut. + +![][2] + +Enter the name for your shortcut and add the following line in the command box, and click **Apply** button. +``` +bash -c "sleep 1 && xtrlock" + +``` + +![][3] + +To assign the shortcut key, just select or double click on it and type the key combination of your choice. For example, I use **Alt+k**. + +![][4] + +To clear the key combination, press BACKSPACE key. Once you finished, close the Keyboard Settings window. + +**In Ubuntu GNOME DE:** + +Go to **System Settings - > Devices -> Keyboard**. Click the **+** symbol at the end. + +Enter the name for your shortcut and add the following line in the command box, and click **Add** button. +``` +bash -c "sleep 1 && xtrlock" + +``` + +![][5] + +Next, assign the shortcut key to the newly created shortcut. To do so, just select or double click on it and click on **“Set shortcut”** button. + +![][6] + +You will now see the following screen. + +![][7] + +Type the key combination of your choice. For example, I use **Alt+k**. + +![][8] + +To clear the key combination, press BACKSPACE key. The shortcut key has been assigned. Once you finished, close the Keyboard Settings window. + +From now on, whenever you press the keyboard shortcut key (ALT+k in our case), the mouse pointer will turn into a a padlock. Now, the keyboard and mouse have been locked, so you can freely watch the movies or whatever you want to. Even your kid or pet touches some keys on the keyboard or clicks a mouse button, they won’t work. + +Here is xtrclock in action. + +![][9] + +Do you see the a small lock button? It means that the keyboard and mouse have been locked. Even if you move the lock button, nothing will happen. The task in the background will keep running until you unlock your screen and manually close the running task. + +### Unlock keyboard and mouse + +To unlock the keyboard and mouse, simply type your password and hit “Enter”. You will not see the password as you type it. Just type the password anyway and hit ENTER key. The mouse and keyboard will start to work after you entered the correct password. If you entered an incorrect password, you will hear a bell sound. Press **ESC** key to clear the incorrect password and re-enter the correct password again. To remove one character of a partially typed password, press either **BACKSPACE** or **DELETE** keys. + +### What if I permanently get locked out of the screen? + +The xtrclock tool may not work on some DEs, for example GDM. It may permanently lock you out of the screen. Please test it in a virtual machine and then try it in your personal or official desktop if it really works. I tested this on Arch Linux MATE desktop and Ubuntu 18.04 GNOME desktop. It worked just fine. + +Just in case, you are locked out of the screen permanently, switch to the TTY (CTRL+ALT+F2) then run: +``` +$ sudo killall xtrlock + +``` + +Alternatively, you can use the **chvt** command to switch between TTY and X session. + +For example, to switch to TTY1, run: +``` +$ sudo chvt 1 + +``` + +To switch back to the X session again, type: +``` +$ sudo chvt 7 + +``` + +Different distros uses different key combinations to switch between TTYs. Please refer your distribution’s official website for more details. + +For more details about xtrlock, refer man pages. +``` +$ man xtrlock + +``` + +And, that’s all for now. Hope this helps. If you find our guides useful, please spend a moment to share them on your social, professional networks and support OSTechNix. + +**Resource:** + + * [**Ubuntu forum**][10] + + + +-------------------------------------------------------------------------------- + +via: https://www.ostechnix.com/lock-keyboard-mouse-not-screen-linux/ + +作者:[SK][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.ostechnix.com/author/sk/ +[1]:data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7 +[2]:http://www.ostechnix.com/wp-content/uploads/2017/09/Keyboard-Shortcuts_001.png +[3]:http://www.ostechnix.com/wp-content/uploads/2017/09/Keyboard-Shortcuts_002.png +[4]:http://www.ostechnix.com/wp-content/uploads/2017/09/Keyboard-Shortcuts_003.png +[5]:http://www.ostechnix.com/wp-content/uploads/2018/01/Add-xtrlock-shortcut.png +[6]:http://www.ostechnix.com/wp-content/uploads/2018/01/set-shortcut-key-1.png +[7]:http://www.ostechnix.com/wp-content/uploads/2018/01/set-shortcut-key-2.png +[8]:http://www.ostechnix.com/wp-content/uploads/2018/01/set-shortcut-key-3.png +[9]:http://www.ostechnix.com/wp-content/uploads/2018/01/xtrclock-1.png +[10]:https://ubuntuforums.org/showthread.php?t=993800 diff --git a/sources/tech/20180820 How To Disable Ads In Terminal Welcome Message In Ubuntu Server.md b/sources/tech/20180820 How To Disable Ads In Terminal Welcome Message In Ubuntu Server.md new file mode 100644 index 0000000000..8f6ef80dbe --- /dev/null +++ b/sources/tech/20180820 How To Disable Ads In Terminal Welcome Message In Ubuntu Server.md @@ -0,0 +1,120 @@ +How To Disable Ads In Terminal Welcome Message In Ubuntu Server +====== + +![](https://www.ostechnix.com/wp-content/uploads/2018/08/disable-ads-in-Terminal-welcome-message-in-Ubuntu-720x340.jpg) + +If you’re using any latest Ubuntu server edition, you might have noticed some promotional links in welcome message which are not relevant to Ubuntu server platform. As you might already know **MOTD** , abbreviation of **M** essage **O** f **T** he **D** ay, displays a welcome message at every login in Linux systems. Usually, the welcome message contains the version of your OS, basic system information, official documentation link, and the links to read about the latest security updates etc. This is what we usually see at every time we login either via SSH or on the local machine. However, there some additional links started to appear in the terminal welcome message lately. I have already noticed this link few times, but I didn’t care about it and never clicked it though. Here is the Terminal welcome message shown in my Ubuntu 18.04 LTS server. + +![](http://www.ostechnix.com/wp-content/uploads/2018/08/Ubuntu-Terminal-welcome-message.png) + +As you can see in the above screenshot, there is also a bit.ly link and Ubuntu wiki link in the welcome message. Some of you may surprise and wondering what this is. There is nothing to worry about the links in the welcome message. It may look sort of ad-like, but those are not really commercial ads. The links are actually pointing to [**Ubuntu official blog**][1] and [**Ubuntu wiki**][2]. As I said earlier, one of link is not relevant and doesn’t has any details related to Ubuntu server. That’s why I called them ads in the first place. + +Even though most of us won’t visit bit.ly links, but some people may visit those links out of curiosity and ended up disappointed realizing that it simply points you to an external link. You can use any URL unshortners services, such as unshorten.it, to see where they lead before visiting the actual link. Alternatively, you can just type a plus sign ( **+** ) at the end of the bit.ly link to see where they lead and some statistics about the link. + +![](http://www.ostechnix.com/wp-content/uploads/2018/08/shortlink.png) + +### What is MOTD and how it works? + +Back in 2009, **Dustin Kirkland** from Canonical introduced the concept of MOTD in Ubuntu. It’s a flexible framework that enables the administrators or distro packages to add executable scripts in /etc/update-motd.d/* location to generate informative, interesting messages displayed at login. It was originally implemented for Landscape (a commercial service from Canonical), however other distribution maintainers found it useful and adopted this feature in their own distributions as well. + +If you look in **/etc/update-motd.d/** location in your Ubuntu system, you’ll see a set of scripts. One prints the generic “welcome” banner. The next one prints 3 links showing where to find help for the OS. The other one counts and displays the number of package updates available for the local system. Another one tells you if a reboot is required and so on. + +From Ubuntu 17.04 onwards, the developers have added **/etc/update-motd.d/50-motd-news** , a script to include some additional information in the welcome message. They additional information are; + + 1. Important critical information, such as + +ShellShock, Heartbleed etc. + + 2. End-of-Life (EOL) messages, new feature availability, etc. + + 3. Some fun and informative posts published in Ubuntu official blog and other news about Ubuntu. + + + + +Asynchronously, about 60 seconds after boot, a systemd timer runs “/etc/update-motd.d/50-motd-news –force” script. It sources 3 config variables defined in /etc/default/motd-news script. The default values are: ENABLED=1, URLS=”, WAIT=”5″. + +Here is the contents of /etc/default/motd-news file: +``` +$ cat /etc/default/motd-news +# Enable/disable the dynamic MOTD news service +# This is a useful way to provide dynamic, informative +# information pertinent to the users and administrators +# of the local system +ENABLED=1 + +# Configure the source of dynamic MOTD news +# White space separated list of 0 to many news services +# For security reasons, these must be https +# and have a valid certificate +# Canonical runs a service at motd.ubuntu.com, and you +# can easily run one too +URLS="https://motd.ubuntu.com" + +# Specify the time in seconds, you're willing to wait for +# dynamic MOTD news +# Note that news messages are fetched in the background by +# a systemd timer, so this should never block boot or login +WAIT=5 + +``` + +Good thing is MOTD is fully customizable, so you can disable it entirely (ENABLED=0), change or add scripts as per your wish, and change the wait time in seconds + +If MOTD is enabled, that systemd timer job will loop over each of the URLS, trim them to 80 characters per line, and a maximum of 10 lines, and concatenate them to a cache file in /var/cache/motd-news. This systemd timer job will re-run and update the /var/cache/motd-news every 12 hours. Upon user login, the contents of /var/cache/motd-news is just printed to screen. This is how MOTD works. + +Also, a custom user-agent string is included in **/etc/update-motd.d/50-motd-news** file to report information about your computer. If you look into **/etc/update-motd.d/50-motd-news** file, you will see the following code. +``` +# Piece together the user agent +USER_AGENT="curl/$curl_ver $lsb $platform $cpu $uptime" + +``` + +That means, the MOTD retriever reports your **operating system release** , **hardware platform** , **CPU type** and **uptime** to Canonical. + +Hope you got the basic idea about MOTD. + +Let us now get back to the topic. I don’t want this feature. How do I disable it? If the promotional links in the welcome message still bothers you and you wanted to disable them permanently, here is a quick way to disable it. + +### Disable Ads In Terminal Welcome Message In Ubuntu Server + +To disable these ads, edit file: +``` +$ sudo vi /etc/default/motd-news + +``` + +Find the following line and set its value as 0 (zero). +``` +[...] +ENABLED=0 +[...] + +``` + +Save and close the file. Now, reboot your system and see if the welcome message stills showing the links from Ubuntu blog. + +![](https://www.ostechnix.com/wp-content/uploads/2018/08/Ubuntu-Terminal-welcome-message-1.png) + +See? There are no links from Ubuntu blog and Ubuntu wiki now. + +And, that’s all for now. Hope this helps. More good stuffs to come. Stay tuned! + +Cheers! + + + +-------------------------------------------------------------------------------- + +via: https://www.ostechnix.com/how-to-disable-ads-in-terminal-welcome-message-in-ubuntu-server/ + +作者:[SK][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.ostechnix.com/author/sk/ +[1]:https://blog.ubuntu.com/ +[2]:https://wiki.ubuntu.com/ diff --git a/sources/tech/20180820 Keeping patient data safe with open source tools.md b/sources/tech/20180820 Keeping patient data safe with open source tools.md new file mode 100644 index 0000000000..decdffd487 --- /dev/null +++ b/sources/tech/20180820 Keeping patient data safe with open source tools.md @@ -0,0 +1,51 @@ +Keeping patient data safe with open source tools +====== + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/health_heartbeat.png?itok=P-GXea-p) + +Healthcare is experiencing a revolution. In a tightly regulated and ancient industry, the use of free and open source software make it uniquely positioned to see a great deal of progress. + +I work at a [scrappy healthcare startup][1] where cost savings are a top priority. Our primary challenge is how to safely and efficiently manage personally identifying information (PII), like names, addresses, insurance information, etc., and personal health information (PHI), like the reason for a recent clinical visit, under the regulations of the Health Insurance Portability and Accountability Act of 1996, [HIPAA][2], which became mandatory in the United States in 2003. + +Briefly, HIPAA is a set of U.S. regulations that were created in response to the need for safety in healthcare data transmission and security. Titles 1, 3, 4, and 5 relate to the healthcare industry and insurance regulation, and Title 2 protects patient privacy and the security of the PHI/PII. Title 2 dictates how and to whom medical information can be disclosed (patients, medical providers, and relevant staff members), and it also loosely describes technological security that must be used, with many suggestions. + +The law was written to manage digital data portability through some amount of time (though several updates have been added to the original legislation), but it couldn’t have anticipated the kinds of technological advancements that have been introduced, so it often lacks detail on exactly how to keep patient data safe. Auditors want to see best-effort, authentically crafted and respected documentation—an often vague but compelling and ever-present challenge. But no regulation says we can’t use open source software, which makes our lives much easier. + +Our stack consists of Python, with readily available open source security and cryptography packages that are typically already baked into the requirements of Python web frameworks (which in our case is Klein, a framework built with Twisted, an asynchronous networking framework for Python). On the front end, we’ve got [AngularJS][3]. Some of the free security Python packages we use are [cryptography][4], [itsdangerous][5], [pycrypto][6], and somewhat unrelatedly, [magic-wormhole][7], a fairly cryptographically secure file sending tool that my team and I love, built on Twisted and the Python cryptography packages. + +These tools are integral to our HIPAA compliance on both the front-end and server side, as described in the example below. With the maturity and funding of FOSS (shout-out to the Mozilla Foundation for [funding the PyPI project][8], the packaging repository all Python developers depend on), it’s possible for a for-profit business to not only use and contribute to a significant amount of open source but also make it secure. + +One of our early challenges was how to use Amazon Web Services' (AWS) message queuer, [SQS][9] (Simple Queueing Service), to transmit data from our application server to our data interface server (before SQS encrypted traffic end to end). We separate the data intake/send instance from the web application instance to make the data and the application incommunicable to one another. This reduces the security surface should an attacker gain access. The purpose of SQS, then, is to transmit data we receive from partners for continuing care and store it temporarily in application memory, and data that we send back to our data and interface engine from the application to add to patient’s chart on the healthcare network’s medical records system. + +A typical HIPAA-compliant installation requires all data in transit to be encrypted, but at the time, SQS had no HIPAA-compliant option. So we use [GNU Privacy Guard][10] (GnuPG), which can be difficult to use but is reliable and cryptographically secure when applied correctly. This ensures that any data housed on the application server for any period of time is encrypted with a key we created for this service. While data is in transit from the application to the data interface, we encrypt and decrypt it with keys that live only on the two components. + +While it’s easier than ever to use open source software, we are still working on contributing back. Even as the company attorneys and marketing folks determine the best and safest way to publicize our OSS projects, we’ve had some nibbles at our pip packages and repositories from others looking for the exact solution we present. I’m excited to make the [projects][11] [we've][12] [issued][13] better known, to steward more of our open source code to those who want it, and to encourage others to contribute back in kind. + +There are a number of hurdles to this innovation in healthcare, and I recommend the excellent [EMR & HIPAA][14] blog, which offers a terrific, accessible daily newsletter on how many organizations are addressing these hurdles technically, logistically, and interpersonally. + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/8/foss-hippa-healthcare-open-source-tools + +作者:[Rachel Kelly][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://opensource.com/users/rachelkelly +[1]:http://bright.md/ +[2]:https://www.hhs.gov/hipaa/for-individuals/guidance-materials-for-consumers/index.html +[3]:https://angularjs.org/ +[4]:https://pypi.org/project/cryptography/ +[5]:https://pypi.org/project/itsdangerous/ +[6]:https://pypi.org/project/pycrypto/ +[7]:https://github.com/warner/magic-wormhole +[8]:http://pyfound.blogspot.com/2017/11/the-psf-awarded-moss-grant-pypi.html +[9]:https://aws.amazon.com/sqs/ +[10]:https://gnupg.org/ +[11]:https://github.com/Brightmd/txk8s +[12]:https://github.com/Brightmd/hoursofoperation +[13]:https://github.com/Brightmd/yamlschema +[14]:https://www.emrandhipaa.com/ diff --git a/sources/tech/20180821 A checklist for submitting your first Linux kernel patch.md b/sources/tech/20180821 A checklist for submitting your first Linux kernel patch.md new file mode 100644 index 0000000000..1fc4677491 --- /dev/null +++ b/sources/tech/20180821 A checklist for submitting your first Linux kernel patch.md @@ -0,0 +1,170 @@ +A checklist for submitting your first Linux kernel patch +====== + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/linux_penguin_green.png?itok=ENdVzW22) + +One of the biggest—and the fastest moving—open source projects, the Linux kernel, is composed of about 53,600 files and nearly 20-million lines of code. With more than 15,600 programmers contributing to the project worldwide, the Linux kernel follows a maintainer model for collaboration. + +![](https://opensource.com/sites/default/files/karnik_figure1.png) + +In this article, I'll provide a quick checklist of steps involved with making your first kernel contribution, and look at what you should know before submitting a patch. For a more in-depth look at the submission process for contributing your first patch, read the [KernelNewbies First Kernel Patch tutorial][1]. + +### Contributing to the kernel + +#### Step 1: Prepare your system. + +Steps in this article assume you have the following tools on your system: + ++ Text editor ++ Email client ++ Version control system (e.g., git) + +#### Step 2: Download the Linux kernel code repository`:` +``` +git clone -b staging-testing + +git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging.git + +``` + +### Copy your current config: ```` +``` +cp /boot/config-`uname -r`* .config + +``` + +### Step 3: Build/install your kernel. +``` +make -jX + +sudo make modules_install install + +``` + +### Step 4: Make a branch and switch to it. +``` +git checkout -b first-patch + +``` + +### Step 5: Update your kernel to point to the latest code base. +``` +git fetch origin + +git rebase origin/staging-testing + +``` + +### Step 6: Make a change to the code base. + +Recompile using `make` command to ensure that your change does not produce errors. + +### Step 7: Commit your changes and create a patch. +``` +git add + +git commit -s -v + +git format-patch -o /tmp/ HEAD^ + +``` + +![](https://opensource.com/sites/default/files/karnik_figure2.png) + +The subject consists of the path to the file name separated by colons, followed by what the patch does in the imperative tense. After a blank line comes the description of the patch and the mandatory signed off tag and, lastly, a diff of your patch. + +Here is another example of a simple patch: + +![](https://opensource.com/sites/default/files/karnik_figure3.png) + +Next, send the patch [using email from the command line][2] (in this case, Mutt): `` +``` +mutt -H /tmp/0001- + +``` + +To know the list of maintainers to whom to send the patch, use the [get_maintainer.pl script][11]. + + +### What to know before submitting your first patch + + * [Greg Kroah-Hartman][3]'s [staging tree][4] is a good place to submit your [first patch][1] as he accepts easy patches from new contributors. When you get familiar with the patch-sending process, you could send subsystem-specific patches with increased complexity. + + * You also could start with correcting coding style issues in the code. To learn more, read the [Linux kernel coding style documentation][5]. + + * The script [checkpatch.pl][6] detects coding style errors for you. For example, run: + ``` + perl scripts/checkpatch.pl -f drivers/staging/android/* | less + + ``` + + * You could complete TODOs left incomplete by developers: + ``` + find drivers/staging -name TODO + ``` + + * [Coccinelle][7] is a helpful tool for pattern matching. + + * Read the [kernel mailing archives][8]. + + * Go through the [linux.git log][9] to see commits by previous authors for inspiration. + + * Note: Do not top-post to communicate with the reviewer of your patch! Here's an example: + +**Wrong way:** + +Chris, +_Yes let’s schedule the meeting tomorrow, on the second floor._ +> On Fri, Apr 26, 2013 at 9:25 AM, Chris wrote: +> Hey John, I had some questions: +> 1\. Do you want to schedule the meeting tomorrow? +> 2\. On which floor in the office? +> 3\. What time is suitable to you? + +(Notice that the last question was unintentionally left unanswered in the reply.) + +**Correct way:** + +Chris, +See my answers below... +> On Fri, Apr 26, 2013 at 9:25 AM, Chris wrote: +> Hey John, I had some questions: +> 1\. Do you want to schedule the meeting tomorrow? +_Yes tomorrow is fine._ +> 2\. On which floor in the office? +_Let's keep it on the second floor._ +> 3\. What time is suitable to you? +_09:00 am would be alright._ + +(All questions were answered, and this way saves reading time.) + + * The [Eudyptula challenge][10] is a great way to learn kernel basics. + + +To learn more, read the [KernelNewbies First Kernel Patch tutorial][1]. After that, if you still have any questions, ask on the [kernelnewbies mailing list][12] or in the [#kernelnewbies IRC channel][13]. + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/8/first-linux-kernel-patch + +作者:[Sayli Karnik][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://opensource.com/users/sayli +[1]:https://kernelnewbies.org/FirstKernelPatch +[2]:https://opensource.com/life/15/8/top-4-open-source-command-line-email-clients +[3]:https://twitter.com/gregkh +[4]:https://www.kernel.org/doc/html/v4.15/process/2.Process.html +[5]:https://www.kernel.org/doc/html/v4.10/process/coding-style.html +[6]:https://github.com/torvalds/linux/blob/master/scripts/checkpatch.pl +[7]:http://coccinelle.lip6.fr/ +[8]:linux-kernel@vger.kernel.org +[9]:https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/log/ +[10]:http://eudyptula-challenge.org/ +[11]:https://github.com/torvalds/linux/blob/master/scripts/get_maintainer.pl +[12]:https://kernelnewbies.org/MailingList +[13]:https://kernelnewbies.org/IRC diff --git a/sources/tech/20180821 How I recorded user behaviour on my competitor-s websites.md b/sources/tech/20180821 How I recorded user behaviour on my competitor-s websites.md new file mode 100644 index 0000000000..b4729d730e --- /dev/null +++ b/sources/tech/20180821 How I recorded user behaviour on my competitor-s websites.md @@ -0,0 +1,117 @@ +How I recorded user behaviour on my competitor’s websites +====== + +### Update + +Google’s team has tracked down my test site, most likely using the source code I shared and de-indexed the whole domain. + +Last time [I publicly exposed a flaw][1], Google issued a [manual penalty][2] and devalued a single offending page. This time, there is no notice in Search Console. The site is completely removed from their index without any notification. + +I’ve received a lot of criticism in the way I’ve handled this. Many are suggesting the right way is to approach Google directly with security flaws like this instead of writing about it publicly. Others are suggesting I acted unethically, or even illegally by running this test. I think it should be obvious that if I intended to exploit this method I wouldn’t write about it. With so much risk and so little gain, is this even worth doing in practice? Of course not. I’d be more concerned about those who do unethical things and don’t write about it. + +### My wish list: + +a) Manipulating the back button in Chrome shouldn’t be possible in 2018 +b) Websites that employ this tactic should be detected and penalised by Google’s algorithms +c) If still found in Google’s results, such pages should be labelled with “this page may be harmful” notice. + +### Here’s what I did: + + 1. User lands on my page (referrer: google) + 2. When they hit “back” button in Chrome, JS sends them to my copy of SERP + 3. Click on any competitor takes them to my mirror of competitor’s site (noindex) + 4. Now I generate heatmaps, scrollmaps, records screen interactions and typing. + +![][3] + +![script][4] +![][5] +![][6] + +Interestingly, only about 50% of users found anything suspicious, partly due to the fact that I used https on all my pages, which is one of the main [trust factors on the web][7]. + +Many users are just happy to see the “padlock” in their browser. + +At this point I was able to: + + * Generate heatmaps (clicks, moves, scroll depth) + * Record actual sessions (mouse movement, clicks, typing) + + + +I gasped when I realised I can actually **capture all form submissions and send them to my own email**. + +Note: I never actually tried that. + +Yikes! + +### Wouldn’t a website doing this be penalised? + +You would think so. + +I had this implemented for a **very brief period of time** (and for ethical reasons took it down almost immediately, realising that this may cause trouble). After that I changed the topic of the page completely and moved the test to one of my disposable domains where **remained** for five years and ranked really well, though for completely different search terms with rather low search volumes. Its new purpose was to mess with conspiracy theory people. + +### Alternative Technique + +You don’t have to spoof Google SERPs to generate competitor’s heatmaps, you can simply A/B test your landing page VS your clone of theirs through paid traffic (e.g. social media). Is the A/B testing version of this ethically OK? I don’t know, but it may get you in legal trouble depending on where you live. + +### What did I learn? + +Users seldom read home page “fluff” and often look for things like testimonials, case studies, pricing levels and staff profiles / company information in search for credibility and trust. One of my upcoming tests will be to combine home page with “about us”, “testimonials”, “case studies” and “packages”. This would give users all they really want on a single page. + +### Reader Suggestions + +“I would’ve thrown in an exit pop-up to let users know what they’d just been subjected to.” + + +### From Hacker News + +> Howdy, former Matasano pentester here. +> FWIW, I would probably have done something similar to them before I’d worked in the security industry. It’s an easy mistake to make, because it’s one you make by default: intellectual curiosity doesn’t absolve you from legal judgement, and people on the internet tend to flip out if you do something illegal and say anything but “You’re right, I was mistaken. I’ve learned my lesson.” +> +> To the author: The reason you pattern-matched into the blackhat category instead of whitehat/grayhat (grayhat?) category is that in the security industry, whenever we discover a vuln, we PoC it and then write it up in the report and tell them immediately. The report typically includes background info, reproduction steps, and recommended actions. The whole thing is typically clinical and detached. +> +> Most notably, the PoC is usually as simple as possible. alert(1) suffices to demonstrate XSS, for example, rather than implementing a fully-working cookie swipe. The latter is more fun, but the former is more impactful. +> +> One interesting idea would’ve been to create a fake competitor — e.g. “VirtualBagel: Just download your bagels and enjoy.” Once it’s ranking on Google, run this same experiment and see if you could rank higher. +> +> That experiment would demonstrate two things: (1) the history vulnerability exists, and (2) it’s possible for someone to clone a competitor and outrank them with this vulnerability, thereby raising it from sev:low to sev:hi. +> +> So to be clear, the crux of the issue was running the exploit on a live site without their blessing. +> +> But again, don’t worry too much. I would have made similar errors without formal training. It’s easy for everyone to say “Oh well it’s obvious,” but when you feel like you have good intent, it’s not obvious at all. +> +> I remind everyone that RTM once ran afoul of the law due to similar intellectual curiosity. (In fairness, his experiment exploded half the internet, but still.) + +Source: + + +### About the author + +[Dan Petrovic][9] + +Dan Petrovic, the managing director of DEJAN, is Australia’s best-known name in the field of search engine optimisation. Dan is a web author, innovator and a highly regarded search industry event speaker. + + +-------------------------------------------------------------------------------- + +via: https://dejanseo.com.au/competitor-hack/ + +作者:[Dan Petrovic][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://dejanseo.com.au/dan-petrovic/ +[1]:https://dejanseo.com.au/hijack/ +[2]:https://dejanseo.com.au/google-against-content-scrapers/ +[3]:https://dejanseo.com.au/wp-content/uploads/2018/08/step-1.png +[4]:https://dejanseo.com.au/wp-content/uploads/2018/08/script.gif +[5]:https://dejanseo.com.au/wp-content/uploads/2018/08/step-2.png +[6]:https://dejanseo.com.au/wp-content/uploads/2018/08/step-3.png +[7]:https://dejanseo.com.au/trust/ +[8]:https://secure.gravatar.com/avatar/9068275e6d3863b7dc11f7dff0974ced?s=100&d=mm&r=g +[9]:https://dejanseo.com.au/dan-petrovic/ (Dan Petrovic) +[10]:https://dejanseo.com.au/author/admin/ (More posts by Dan Petrovic) diff --git a/sources/tech/20180822 9 flowchart and diagramming tools for Linux.md b/sources/tech/20180822 9 flowchart and diagramming tools for Linux.md new file mode 100644 index 0000000000..853cd1b7c3 --- /dev/null +++ b/sources/tech/20180822 9 flowchart and diagramming tools for Linux.md @@ -0,0 +1,186 @@ +9 flowchart and diagramming tools for Linux +====== + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/BUSINESS_orgchart1.png?itok=tukiFj89) + +Flowcharts are a great way to formalize the methodology for a new project. My team at work uses them as a tool in our brainstorming sessions and—once the ideation event wraps up—the flowchart becomes the project methodology (at least until someone changes it). My project methodology flowcharts are high-level and pretty straightforward—typically they contain just process, decision, and terminator objects—though they can be composed of many tens of these objects. + +I work primarily in my Linux desktop environment, and most of my office colleagues use Windows. However, we're increasing our use of G Suite in part because it minimizes distractions related to our various desktop environments. Even so, I would prefer to find an open source tool—preferably a standalone app, rather than one that's part of another suite—that offers great support for flowcharts and is available on all the desktops our team uses. + +It's been over four years since [Máirin Duffy reviewed Linux diagramming tools][1], so I decided to take a look at what's out there now for open source flowchart makers. I identified the following nine candidates: + +| Candidate name | Linux desktop | Available for Windows? | Available for MacOS? | +|-----------------------| --------------|------------------------|----------------------| +| [Dia][2] | GNOME | Yes | Yes | +| [LibreOffice Draw][3] | GNOME | Yes | Yes | +| [Inkscape][4] | GNOME | Yes | Yes | +| [Calligra Flow][5] | KDE | Preliminary | Preliminary | +| [Diagramo][6] | Browser | Browser | Browser | +| [Pencil][7] | ? | Yes | Yes | +| [Graphviz][8] | CLI | Yes | Yes | +| [Umbrello][9] | KDE | Yes | Yes | +| [Draw.io][10] | Browser | Browser | Browser | + +I'll share a bit of information about each below. + +### Dia + +![](https://opensource.com/sites/default/files/uploads/flowcharting_dia.png) + +I reviewed Dia 0.97.3 from the Ubuntu 18.04 repository; you can [download it here][2]. + +Dia is a standalone drawing tool. It offers some additional components, such as `dia-rib-network` for network diagrams and `dia2cod` for converting [UML][11] to code. + +The installation process dragged in a few other packages, including: `dia-common`, `dia-shapes`, `gsfonts-x11`, `libpython-stdlib`, `python`, `python-cairo`, and `python-gobject2`. + +[Dia's documentation][12] is quite thorough and available in English, German, French, Polish, and Basque. It includes information on related utilities; versions for Linux, Windows, and MacOS; a lot of stuff related to shapes; and much more. The bug tracker on the project's website is disabled, but bug reports are accepted on [GNOME Bugzilla][13]. + +Dia has complete support for making flowcharts—appropriate symbols, connectors, lots of connection points on objects, annotation for objects, etc. Even so, Dia's user experience (UX) feels unusual. For example, double-clicking on an object brings up properties and metadata, rather than the object's annotation; to edit annotation, you must select the object and click on Tools > Edit Text (or use the F2 key). The default text size, 22.68pt, or about 8mm, seems a bit weird. The text padding default is very large (0.50), and even when it's reduced by a factor of 10 (to 0.05), it still may leave a wide gap around the text (for example in the diamond decision object). You must also select the object before you can right-click on it. Cutting and pasting are somewhat limited—I couldn't copy text from my browser (with the standard Ctrl+C) and paste it into Dia. Dia launches ready to work with a multipage drawing, which is pretty handy if you need to make a 1x2 meter drawing and your printer accommodates only letter-size paper. + +In general terms, performance is very snappy. Interaction can seem a bit odd (see above), but it doesn't require huge adjustments to get the hang of it. On the downside, the Help menu did not link properly to documentation, and I couldn't find a spell checker. Finally, from what I can tell, there is no active development on Dia. + +### LibreOffice Draw + +![](https://opensource.com/sites/default/files/uploads/flowcharting_libreofficedraw.png) + +I reviewed [LibreOffice Draw][3] version 6.0.4.2, which was installed by default on my Ubuntu 18.04 desktop. + +Since LibreOffice Draw is part of the LibreOffice suite, the UX will be familiar to anyone who uses LibreOffice Writer, Calc, or Impress. However, if you are looking for a standalone flowcharting tool and don't already use LibreOffice, this is likely to be a large [install][14]. + +The application includes an extensive help facility that is accessible from the Help menu, and you can find a great deal of information by searching online. + +LibreOffice Draw has a set of predefined flowchart shapes that support annotation as well as connectors. Connection points are limited—all the shapes I use have just four points. Draw's UX will feel familiar to LibreOffice users; for example, double-clicking an object opens the object's annotation. Text wraps automatically when its length exceeds the width of a text box. However, annotation entered in a drawing object does not wrap; you must manually break the lines. Default text size, spacing, etc. are reasonable and easily changed. Draw permits multiple pages (which are called slides), but it doesn't support multipage drawings as easily as Dia does. + +In general terms, LibreOffice Draw provides good, basic flowcharting capability with no UX surprises. It performs well, at least on smaller flowcharts, and standard LibreOffice writing tools, such as spell check, are available. + +### Inkscape + +![](https://opensource.com/sites/default/files/uploads/flowcharting_inkscape.png) + +I reviewed [Inkscape][4] version 0.92.3 from the Ubuntu 18.04 repositories; you can [download it here][15]. + +Inkscape is a standalone tool, and it is waaaaaay more than a flowchart drawing utility. + +The installation process dragged in several other packages, including: `fig2dev`, `gawk`, `libgtkspell0`, `libimage-magick-perl`, `libimage-magick-q16-perl`, `libmagick+±6.q16-7`, `libpotrace0`, `libsigsegv2`, `libwmf-bin`, `python-scour`, `python3-scour`, `scour`, and `transfig`. + +There is a great deal of Inkscape documentation available, including the Inkscape Manual available from the Help menu. This [tutorial][16] made it easier to get started with my first Inkscape flowchart. + +Getting my first rectangle on the screen was pretty straightforward with the Create Rectangles and Squares toolbar item. I changed the shape's background color by using the color swatches across the bottom of the screen. However, it seems text is separate from other objects, i.e., there doesn't appear to be a concept of geometric objects with annotation, so I created the text first, then added the surrounding object, and finally put in connectors. Default text sizes were odd (30pt, if I recall correctly) but you can change the default. Bottom line: I could make the diagram, but—based on what I could learn in a few minutes—it was more of a diagram than a flowchart. + +In general terms, Inkscape is an extremely full-featured vector drawing program with a learning curve. It's probably not the best tool for users who just want to draw a quick flowchart. There seems to be a spell checker available, although I didn't try it. + +### Calligra Flow + +From [the Calligra website][5]: + +> Calligra Flow is an easy to use diagramming and flowcharting application with tight integration to the other Calligra applications. It enables you to create network diagrams, organisation charts, flowcharts, and more. + +I could not find Calligra Flow in my repositories. Because of that and its tight integration with Calligra, which is oriented toward KDE users, I decided not to review it now. Based on its website, it looks like it's geared toward flowcharting, which could make it a good choice if you're using KDE. + +### Diagramo + +![](https://opensource.com/sites/default/files/uploads/flowcharting_diagramo.png) + +I reviewed [Diagramo][6] build number 2.4.0-3c215561787f-2014-07-01, accessed through [Try It Now!][17] on the Diagramo website using the Firefox browser. + +Diagramo is standalone, web-based flowcharting software. It claims to be pure HTML5 and GPL, but the [source code repository][18] states the code is available under the Apache License 2.0. + +The tool is accessible through a web browser, so no installation is required. (I didn't download the source code and try to install it locally.) + +I couldn't find any documentation for Diagramo. The application's Help button allows bug filing and turning on the debugger, and the build number is available under About. + +Diagramo offers several collections of drawing objects: Basic, Experimental, Network, Secondary, and UML State Machine. I limited my testing to the Basic set, which contained enough objects for me. To create a chart, you drag objects from the menu on the left and drop them on the canvas. You can set the canvas size in the options panel on the right. Sizes are in pixels, which is OK, although I prefer to work in points. The default text attributes were: 12px, Arial font, center alignment, with options to underline and change the text color. You can see the attributes in a popup menu above the text by double-clicking the default annotation, which is set to Text. You have to manually break lines of text, similar to in LibreOffice Draw. Objects have multiple connection points (I counted 12 on the rectangles and five on the diamonds). Connectors are separate from shapes and appear in the top toolbar. I couldn't save my test flowchart to my computer. + +In general terms, Diagramo provides good basic flowcharting capability with no UX surprises. It performs well, at least on smaller flowcharts, but doesn't seem to take advantage of Firefox's spell checker. + +### Pencil + +![](https://opensource.com/sites/default/files/uploads/flowcharting_pencil.png) + +I reviewed [Pencil][7] version 3.0.4, which I [downloaded][19] from the Pencil project website. I used `dpkg` to install the 64-bit .deb package file. It installed cleanly with no missing packages. + +Pencil is a standalone drawing tool. Documentation and tutorials are available on [the project website][7]. + +To make my sample flowchart, I selected the flowchart shape set from the far-left menu panel. From there, I could drag Process, Decision, and Straight Connector shapes onto the page. I added annotation by double-clicking on the object and typing in the text. (Copy/paste also works.) You can drag the connector endpoints near the desired attachment point and they automatically attach. The default font setting (Arial, 12pt) is a good choice, but I couldn't find a spell check function. + +In general, using Pencil is very simple and straightforward. It offers solid flowcharting capability with no UX surprises and performs well, at least on smaller flowcharts. + +### Graphviz + +According to the [Graphviz documentation][20]: + +> The Graphviz layout programs take descriptions of graphs in a simple text language and make diagrams in useful formats, such as images and SVG for web pages; PDF or Postscript for inclusion in other documents; or display in an interactive graph browser. Graphviz has many useful features for concrete diagrams, such as options for colors, fonts, tabular node layouts, line styles, hyperlinks, and custom shapes. + +I didn't do a full review of Graphviz. It looks like a very interesting package for converting text to graphical representations, and I might try it at some point. However, I don't see it as a good tool for people who are used to a more interactive UX. If you'd like to know more about it, [Stack Overflow][21] offers a quick overview of constructing a simple flowchart in Graphviz. + +### Umbrello + +I spotted [Umbrello][9] in my repositories, where I read: + +> Umbrello UML Modeller is a Unified Modelling Language diagram editor for KDE. It can create diagrams of software and other systems in the industry-standard UML format, and can also generate code from UML diagrams in a variety of programming languages. This package is part of the KDE Software Development Kit module. + +Because of its focus on UML rather than flowcharting and its KDE orientation, I decided to leave Umbrello to evaluate later. + +### Draw.io + +![](https://opensource.com/sites/default/files/uploads/flowcharting_draw-io.png) + +I reviewed [Draw.io][22] version 8.9.7, which I accessed through its website. + +Draw.io is standalone, web-based drawing software, and a desktop version is available. Since it runs in the browser, there's no installation required. + +[Documentation][23] is available on the Draw.io website. + +Draw.io launches with a set of general flowchart drawing objects on the left and context-sensitive properties on the right. (It's reminiscent of the Properties window in LibreOffice.) Clicking on a shape makes it appear on the page. Text defaults to centered 12pt Helvetica. Double-clicking on the drawing object opens the annotation editor. Draw.io automatically splits long lines of text, but the splitting isn't perfect in the diamond object. Objects have a decent number of connection points (I count 12 on the rectangle and eight on the diamond). Similar to Google Draw, as objects are dragged around, alignment aids help square up the diagram. I saved my work to an .xml file on my computer, which is a cool option for a web-based service. Diagrams can also be shared. + +In general terms, Draw.io provides solid flowcharting capability with no UX surprises, but no spell checker that I could find. It performs well, at least on smaller flowcharts, and the collaboration ability is nice. + +### What's the verdict? + +So, which of these flowcharting tools do I like best? + +Bearing in mind that I was leaning toward a standalone tool that could operate on any desktop, Draw.io and Diagramo appealed to me for their simplicity and browser-based operation (which means no installation is necessary). I also really liked Pencil, although it must be installed. + +Conversely, I felt Dia's UX was just a bit clunky and old-fashioned, although it certainly has great functionality. + +LibreOffice Draw and Calligra Flow, due to their integration in their respective office suites, didn't achieve my goal for a standalone, lightweight tool. + +Inkscape, Graphviz, and Umbrello seem like great tools in their own right, but trying to use them as simple, standalone flowchart creation tools seems like a real stretch. + +Will any of these replace G Suite's drawing capability in our office? I think Draw.io, Diagramo and Pencil could. We shall see! + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/8/flowchart-diagramming-linux + +作者:[Chris Hermansen][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://opensource.com/users/clhermansen +[1]:https://opensource.com/life/14/6/tools-diagramming-fedora +[2]:http://dia-installer.de/ +[3]:https://www.libreoffice.org/discover/draw/ +[4]:https://inkscape.org/en/ +[5]:https://www.calligra.org/flow/ +[6]:http://diagramo.com/ +[7]:https://pencil.evolus.vn/ +[8]:http://graphviz.org/ +[9]:https://umbrello.kde.org/ +[10]:https://about.draw.io/about-us/ +[11]:https://en.wikipedia.org/wiki/Unified_Modeling_Language +[12]:http://dia-installer.de/doc/index.html.en +[13]:https://bugzilla.gnome.org/query.cgi?format=specific&product=dia&bug_status=__all__ +[14]:https://www.libreoffice.org/download/download/ +[15]:https://inkscape.org/en/release/0.92.3/ +[16]:http://goinkscape.com/create-beautiful-diagrams-in-inkscape/ +[17]:http://diagramo.com/editor/editor.php +[18]:https://bitbucket.org/scriptoid/diagramo/src/33c88ca45ee942bf0b16f19879790c361fc9709d/LICENSE.txt?at=default&fileviewer=file-view-default +[19]:https://pencil.evolus.vn/Downloads.html +[20]:https://graphviz.gitlab.io/documentation/ +[21]:https://stackoverflow.com/questions/46365855/create-simple-flowchart-with-graphviz +[22]:http://Draw.io +[23]:https://about.draw.io/tag/user-documentation/ diff --git a/sources/tech/20180823 CLI- improved.md b/sources/tech/20180823 CLI- improved.md new file mode 100644 index 0000000000..d06bb1b2aa --- /dev/null +++ b/sources/tech/20180823 CLI- improved.md @@ -0,0 +1,297 @@ +CLI: improved +====== +I'm not sure many web developers can get away without visiting the command line. As for me, I've been using the command line since 1997, first at university when I felt both super cool l33t-hacker and simultaneously utterly out of my depth. + +Over the years my command line habits have improved and I often search for smarter tools for the jobs I commonly do. With that said, here's my current list of improved CLI tools. + + +### Ignoring my improvements + +In a number of cases I've aliased the new and improved command line tool over the original (as with `cat` and `ping`). + +If I want to run the original command, which is sometimes I do need to do, then there's two ways I can do this (I'm on a Mac so your mileage may vary): +``` +$ \cat # ignore aliases named "cat" - explanation: https://stackoverflow.com/a/16506263/22617 +$ command cat # ignore functions and aliases + +``` + +### bat > cat + +`cat` is used to print the contents of a file, but given more time spent in the command line, features like syntax highlighting come in very handy. I found [ccat][3] which offers highlighting then I found [bat][4] which has highlighting, paging, line numbers and git integration. + +The `bat` command also allows me to search during output (only if the output is longer than the screen height) using the `/` key binding (similarly to `less` searching). + +![Simple bat output][5] + +I've also aliased `bat` to the `cat` command: +``` +alias cat='bat' + +``` + +💾 [Installation directions][4] + +### prettyping > ping + +`ping` is incredibly useful, and probably my goto tool for the "oh crap is X down/does my internet work!!!". But `prettyping` ("pretty ping" not "pre typing"!) gives ping a really nice output and just makes me feel like the command line is a bit more welcoming. + +![/images/cli-improved/ping.gif][6] + +I've also aliased `ping` to the `prettyping` command: +``` +alias ping='prettyping --nolegend' + +``` + +💾 [Installation directions][7] + +### fzf > ctrl+r + +In the terminal, using `ctrl+r` will allow you to [search backwards][8] through your history. It's a nice trick, albeit a bit fiddly. + +The `fzf` tool is a **huge** enhancement on `ctrl+r`. It's a fuzzy search against the terminal history, with a fully interactive preview of the possible matches. + +In addition to searching through the history, `fzf` can also preview and open files, which is what I've done in the video below: + +For this preview effect, I created an alias called `preview` which combines `fzf` with `bat` for the preview and a custom key binding to open VS Code: +``` +alias preview="fzf --preview 'bat --color \"always\" {}'" +# add support for ctrl+o to open selected file in VS Code +export FZF_DEFAULT_OPTS="--bind='ctrl-o:execute(code {})+abort'" + +``` + +💾 [Installation directions][9] + +### htop > top + +`top` is my goto tool for quickly diagnosing why the CPU on the machine is running hard or my fan is whirring. I also use these tools in production. Annoyingly (to me!) `top` on the Mac is vastly different (and inferior IMHO) to `top` on linux. + +However, `htop` is an improvement on both regular `top` and crappy-mac `top`. Lots of colour coding, keyboard bindings and different views which have helped me in the past to understand which processes belong to which. + +Handy key bindings include: + + * P - sort by CPU + * M - sort by memory usage + * F4 - filter processes by string (to narrow to just "node" for instance) + * space - mark a single process so I can watch if the process is spiking + + + +![htop output][10] + +There is a weird bug in Mac Sierra that can be overcome by running `htop` as root (I can't remember exactly what the bug is, but this alias fixes it - though annoying that I have to enter my password every now and again): +``` +alias top="sudo htop" # alias top and fix high sierra bug + +``` + +💾 [Installation directions][11] + +### diff-so-fancy > diff + +I'm pretty sure I picked this one up from Paul Irish some years ago. Although I rarely fire up `diff` manually, my git commands use diff all the time. `diff-so-fancy` gives me both colour coding but also character highlight of changes. + +![diff so fancy][12] + +Then in my `~/.gitconfig` I have included the following entry to enable `diff-so-fancy` on `git diff` and `git show`: +``` +[pager] + diff = diff-so-fancy | less --tabs=1,5 -RFX + show = diff-so-fancy | less --tabs=1,5 -RFX + +``` + +💾 [Installation directions][13] + +### fd > find + +Although I use a Mac, I've never been a fan of Spotlight (I found it sluggish, hard to remember the keywords, the database update would hammer my CPU and generally useless!). I use [Alfred][14] a lot, but even the finder feature doesn't serve me well. + +I tend to turn the command line to find files, but `find` is always a bit of a pain to remember the right expression to find what I want (and indeed the Mac flavour is slightly different non-mac find which adds to frustration). + +`fd` is a great replacement (by the same individual who wrote `bat`). It is very fast and the common use cases I need to search with are simple to remember. + +A few handy commands: +``` +$ fd cli # all filenames containing "cli" +$ fd -e md # all with .md extension +$ fd cli -x wc -w # find "cli" and run `wc -w` on each file + +``` + +![fd output][15] + +💾 [Installation directions][16] + +### ncdu > du + +Knowing where disk space is being taking up is a fairly important task for me. I've used the Mac app [Disk Daisy][17] but I find that it can be a little slow to actually yield results. + +The `du -sh` command is what I'll use in the terminal (`-sh` means summary and human readable), but often I'll want to dig into the directories taking up the space. + +`ncdu` is a nice alternative. It offers an interactive interface and allows for quickly scanning which folders or files are responsible for taking up space and it's very quick to navigate. (Though any time I want to scan my entire home directory, it's going to take a long time, regardless of the tool - my directory is about 550gb). + +Once I've found a directory I want to manage (to delete, move or compress files), I'll use the cmd + click the pathname at the top of the screen in [iTerm2][18] to launch finder to that directory. + +![ncdu output][19] + +There's another [alternative called nnn][20] which offers a slightly nicer interface and although it does file sizes and usage by default, it's actually a fully fledged file manager. + +My `ncdu` is aliased to the following: +``` +alias du="ncdu --color dark -rr -x --exclude .git --exclude node_modules" + +``` + +The options are: + + * `--color dark` \- use a colour scheme + * `-rr` \- read-only mode (prevents delete and spawn shell) + * `--exclude` ignore directories I won't do anything about + + + +💾 [Installation directions][21] + +### tldr > man + +It's amazing that nearly every single command line tool comes with a manual via `man `, but navigating the `man` output can be sometimes a little confusing, plus it can be daunting given all the technical information that's included in the manual output. + +This is where the TL;DR project comes in. It's a community driven documentation system that's available from the command line. So far in my own usage, I've not come across a command that's not been documented, but you can [also contribute too][22]. + +![TLDR output for 'fd'][23] + +As a nicety, I've also aliased `tldr` to `help` (since it's quicker to type!): +``` +alias help='tldr' + +``` + +💾 [Installation directions][24] + +### ack || ag > grep + +`grep` is no doubt a powerful tool on the command line, but over the years it's been superseded by a number of tools. Two of which are `ack` and `ag`. + +I personally flitter between `ack` and `ag` without really remembering which I prefer (that's to say they're both very good and very similar!). I tend to default to `ack` only because it rolls of my fingers a little easier. Plus, `ack` comes with the mega `ack --bar` argument (I'll let you experiment)! + +Both `ack` and `ag` will (by default) use a regular expression to search, and extremely pertinent to my work, I can specify the file types to search within using flags like `--js` or `--html` (though here `ag` includes more files in the js filter than `ack`). + +Both tools also support the usual `grep` options, like `-B` and `-A` for before and after context in the grep. + +![ack in action][25] + +Since `ack` doesn't come with markdown support (and I write a lot in markdown), I've got this customisation in my `~/.ackrc` file: +``` +--type-set=md=.md,.mkd,.markdown +--pager=less -FRX + +``` + +💾 Installation directions: [ack][26], [ag][27] + +[Futher reading on ack & ag][28] + +### jq > grep et al + +I'm a massive fanboy of [jq][29]. At first I struggled with the syntax, but I've since come around to the query language and use `jq` on a near daily basis (whereas before I'd either drop into node, use grep or use a tool called [json][30] which is very basic in comparison). + +I've even started the process of writing a jq tutorial series (2,500 words and counting) and have published a [web tool][31] and a native mac app (yet to be released). + +`jq` allows me to pass in JSON and transform the source very easily so that the JSON result fits my requirements. One such example allows me to update all my node dependencies in one command (broken into multiple lines for readability): +``` +$ npm i $(echo $(\ + npm outdated --json | \ + jq -r 'to_entries | .[] | "\(.key)@\(.value.latest)"' \ +)) + +``` + +The above command will list all the node dependencies that are out of date, and use npm's JSON output format, then transform the source JSON from this: +``` +{ + "node-jq": { + "current": "0.7.0", + "wanted": "0.7.0", + "latest": "1.2.0", + "location": "node_modules/node-jq" + }, + "uuid": { + "current": "3.1.0", + "wanted": "3.2.1", + "latest": "3.2.1", + "location": "node_modules/uuid" + } +} + +``` + +…to this: + +That result is then fed into the `npm install` command and voilà, I'm all upgraded (using the sledgehammer approach). + +### Honourable mentions + +Some of the other tools that I've started poking around with, but haven't used too often (with the exception of ponysay, which appears when I start a new terminal session!): + + * [ponysay][32] > cowsay + * [csvkit][33] > awk et al + * [noti][34] > `display notification` + * [entr][35] > watch + + + +### What about you? + +So that's my list. How about you? What daily command line tools have you improved? I'd love to know. + + +-------------------------------------------------------------------------------- + +via: https://remysharp.com/2018/08/23/cli-improved + +作者:[Remy Sharp][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://remysharp.com +[1]: https://remysharp.com/images/terminal-600.jpg +[2]: https://training.leftlogic.com/buy/terminal/cli2?coupon=READERS-DISCOUNT&utm_source=blog&utm_medium=banner&utm_campaign=remysharp-discount +[3]: https://github.com/jingweno/ccat +[4]: https://github.com/sharkdp/bat +[5]: https://remysharp.com/images/cli-improved/bat.gif (Sample bat output) +[6]: https://remysharp.com/images/cli-improved/ping.gif (Sample ping output) +[7]: http://denilson.sa.nom.br/prettyping/ +[8]: https://lifehacker.com/278888/ctrl%252Br-to-search-and-other-terminal-history-tricks +[9]: https://github.com/junegunn/fzf +[10]: https://remysharp.com/images/cli-improved/htop.jpg (Sample htop output) +[11]: http://hisham.hm/htop/ +[12]: https://remysharp.com/images/cli-improved/diff-so-fancy.jpg (Sample diff output) +[13]: https://github.com/so-fancy/diff-so-fancy +[14]: https://www.alfredapp.com/ +[15]: https://remysharp.com/images/cli-improved/fd.png (Sample fd output) +[16]: https://github.com/sharkdp/fd/ +[17]: https://daisydiskapp.com/ +[18]: https://www.iterm2.com/ +[19]: https://remysharp.com/images/cli-improved/ncdu.png (Sample ncdu output) +[20]: https://github.com/jarun/nnn +[21]: https://dev.yorhel.nl/ncdu +[22]: https://github.com/tldr-pages/tldr#contributing +[23]: https://remysharp.com/images/cli-improved/tldr.png (Sample tldr output for 'fd') +[24]: http://tldr-pages.github.io/ +[25]: https://remysharp.com/images/cli-improved/ack.png (Sample ack output with grep args) +[26]: https://beyondgrep.com +[27]: https://github.com/ggreer/the_silver_searcher +[28]: http://conqueringthecommandline.com/book/ack_ag +[29]: https://stedolan.github.io/jq +[30]: http://trentm.com/json/ +[31]: https://jqterm.com +[32]: https://github.com/erkin/ponysay +[33]: https://csvkit.readthedocs.io/en/1.0.3/ +[34]: https://github.com/variadico/noti +[35]: http://www.entrproject.org/ diff --git a/sources/tech/20180823 Getting started with Sensu monitoring.md b/sources/tech/20180823 Getting started with Sensu monitoring.md new file mode 100644 index 0000000000..7d0a65e306 --- /dev/null +++ b/sources/tech/20180823 Getting started with Sensu monitoring.md @@ -0,0 +1,290 @@ +Getting started with Sensu monitoring +====== +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/rh_003601_05_mech_osyearbook2016_cloud_cc.png?itok=XSV7yR9e) + +Sensu is an open source infrastructure and application monitoring solution that monitors servers, services, and application health, and sends alerts and notifications with third-party integration. Written in Ruby, Sensu can use either [RabbitMQ][1] or [Redis][2] to handle messages. It uses Redis to store data. + +If you want to monitor your cloud infrastructure in a simple and efficient manner, Sensu is a good option. It can be integrated with many of the modern DevOps stacks your organization may already be using, such as [Slack][3], [HipChat][4], or [IRC][5], and it can even send mobile/pager alerts with [PagerDuty][6]. + +Sensu's [modular architecture][7] means every component can be installed on the same server or on completely separate machines. + +### Architecture + +Sensu's main communication mechanism is the Transport. Every Sensu component must connect to the Transport in order to send messages to each other. Transport can use either RabbitMQ (recommended in production) or Redis. + +Sensu Server processes event data and takes action. It registers clients and processes check results and monitoring events using filters, mutators, and handlers. The server publishes check definitions to the clients and the Sensu API provides a RESTful API, providing access to monitoring data and core functionality. + +[Sensu Client][8] executes checks either scheduled by Sensu Server or local checks definitions. Sensu uses a data store (Redis) to keep all the persistent data. Finally, [Uchiwa][9] is the web interface to communicate with Sensu API. + +![sensu_system.png][11] + +### Installing Sensu + +#### Prerequisites + + * One Linux installation to act as the server node (I used CentOS 7 for this article) + + * One or more Linux machines to monitor (clients) + + + + +#### Server side + +Sensu requires Redis to be installed. To install Redis, enable the EPEL repository: +``` +$ sudo yum install epel-release -y + +``` + +Then install Redis: +``` +$ sudo yum install redis -y + +``` + +Modify `/etc/redis.conf` to disable protected mode, listen on every interface, and set a password: +``` +$ sudo sed -i 's/^protected-mode yes/protected-mode no/g' /etc/redis.conf + +$ sudo sed -i 's/^bind 127.0.0.1/bind 0.0.0.0/g' /etc/redis.conf + +$ sudo sed -i 's/^# requirepass foobared/requirepass password123/g' /etc/redis.conf + +``` + +Enable and start Redis service: +``` +$ sudo systemctl enable redis +$ sudo systemctl start redis +``` + +Redis is now installed and ready to be used by Sensu. + +Now let’s install Sensu. + +First, configure the Sensu repository and install the packages: +``` +$ sudo tee /etc/yum.repos.d/sensu.repo << EOF +[sensu] +name=sensu +baseurl=https://sensu.global.ssl.fastly.net/yum/\$releasever/\$basearch/ +gpgcheck=0 +enabled=1 +EOF + +$ sudo yum install sensu uchiwa -y +``` + +Let’s create the bare minimum configuration files for Sensu: +``` +$ sudo tee /etc/sensu/conf.d/api.json << EOF +{ +  "api": { +        "host": "127.0.0.1", +        "port": 4567 +  } +} +EOF +``` + +Next, configure `sensu-api` to listen on localhost, with Port 4567: +``` +$ sudo tee /etc/sensu/conf.d/redis.json << EOF +{ +  "redis": { +        "host": "", +        "port": 6379, +        "password": "password123" +  } +} +EOF + + +$ sudo tee /etc/sensu/conf.d/transport.json << EOF +{ +  "transport": { +        "name": "redis" +  } +} +EOF +``` + +In these two files, we configure Sensu to use Redis as the transport mechanism and the address where Redis will listen. Clients need to connect directly to the transport mechanism. These two files will be required on each client machine. +``` +$ sudo tee /etc/sensu/uchiwa.json << EOF +{ +   "sensu": [ +        { +        "name": "sensu", +        "host": "127.0.0.1", +        "port": 4567 +        } +   ], +   "uchiwa": { +        "host": "0.0.0.0", +        "port": 3000 +   } +} +EOF +``` + +In this file, we configure Uchiwa to listen on every interface (0.0.0.0) on Port 3000. We also configure Uchiwa to use `sensu-api` (already configured). + +For security reasons, change the owner of the configuration files you just created: +``` +$ sudo chown -R sensu:sensu /etc/sensu +``` + +Enable and start the Sensu services: +``` +$ sudo systemctl enable sensu-server sensu-api sensu-client +$ sudo systemctl start sensu-server sensu-api sensu-client +$ sudo systemctl enable uchiwa +$ sudo systemctl start uchiwa +``` + +Try accessing the Uchiwa website: http://:3000 + +For production environments, it’s recommended to run a cluster of RabbitMQ as the Transport instead of Redis (a Redis cluster can be used in production too), and to run more than one instance of Sensu Server and API for load balancing and high availability. + +Sensu is now installed. Now let’s configure the clients. + +#### Client side + +To add a new client, you will need to enable Sensu repository on the client machines by creating the file `/etc/yum.repos.d/sensu.repo`. +``` +$ sudo tee /etc/yum.repos.d/sensu.repo << EOF +[sensu] +name=sensu +baseurl=https://sensu.global.ssl.fastly.net/yum/\$releasever/\$basearch/ +gpgcheck=0 +enabled=1 +EOF +``` + +With the repository enabled, install the package Sensu: +``` +$ sudo yum install sensu -y +``` + +To configure `sensu-client`, create the same `redis.json` and `transport.json` created in the server machine, as well as the `client.json` configuration file: +``` +$ sudo tee /etc/sensu/conf.d/client.json << EOF +{ +  "client": { +        "name": "rhel-client", +        "environment": "development", +        "subscriptions": [ +        "frontend" +        ] +  } +} +EOF +``` + +In the name field, specify a name to identify this client (typically the hostname). The environment field can help you filter, and subscription defines which monitoring checks will be executed by the client. + +Finally, enable and start the services and check in Uchiwa, as the new client will register automatically: +``` +$ sudo systemctl enable sensu-client +$ sudo systemctl start sensu-client +``` + +### Sensu checks + +Sensu checks have two components: a plugin and a definition. + +Sensu is compatible with the [Nagios check plugin specification][12], so any check for Nagios can be used without modification. Checks are executable files and are run by the Sensu client. + +Check definitions let Sensu know how, where, and when to run the plugin. + +#### Client side + +Let’s install one check plugin on the client machine. Remember, this plugin will be executed on the clients. + +Enable EPEL and install `nagios-plugins-http` : +``` +$ sudo yum install -y epel-release +$ sudo yum install -y nagios-plugins-http +``` + +Now let’s explore the plugin by executing it manually. Try checking the status of a web server running on the client machine. It should fail as we don’t have a web server running: +``` +$ /usr/lib64/nagios/plugins/check_http -I 127.0.0.1 +connect to address 127.0.0.1 and port 80: Connection refused +HTTP CRITICAL - Unable to open TCP socket +``` + +It failed, as expected. Check the return code of the execution: +``` +$ echo $? +2 + +``` + +The Nagios check plugin specification defines four return codes for the plugin execution: + +| **Plugin return code** | **State** | +|------------------------|-----------| +| 0 | OK | +| 1 | WARNING | +| 2 | CRITICAL | +| 3 | UNKNOWN | + +With this information, we can now create the check definition on the server. + +#### Server side + +On the server machine, create the file `/etc/sensu/conf.d/check_http.json`: +``` +{ +  "checks": { +    "check_http": { +      "command": "/usr/lib64/nagios/plugins/check_http -I 127.0.0.1", +      "interval": 10, +      "subscribers": [ +        "frontend" +      ] +    } +  } +} +``` + +In the command field, use the command we tested before. `Interval` will tell Sensu how frequently, in seconds, this check should be executed. Finally, `subscribers` will define the clients where the check will be executed. + +Restart both sensu-api and sensu-server and confirm that the new check is available in Uchiwa. +``` +$ sudo systemctl restart sensu-api sensu-server +``` + +### What’s next? + +Sensu is a powerful tool, and this article covers just a glimpse of what it can do. See the [documentation][13] to learn more, and visit the Sensu site to learn more about the [Sensu community][14]. + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/8/getting-started-sensu-monitoring-solution + +作者:[Michael Zamot][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://opensource.com/users/mzamot +[1]:https://www.rabbitmq.com/ +[2]:https://redis.io/topics/config +[3]:https://slack.com/ +[4]:https://en.wikipedia.org/wiki/HipChat +[5]:http://www.irc.org/ +[6]:https://www.pagerduty.com/ +[7]:https://docs.sensu.io/sensu-core/1.4/overview/architecture/ +[8]:https://docs.sensu.io/sensu-core/1.4/installation/install-sensu-client/ +[9]:https://uchiwa.io/#/ +[10]:/file/406576 +[11]:https://opensource.com/sites/default/files/uploads/sensu_system.png (sensu_system.png) +[12]:https://assets.nagios.com/downloads/nagioscore/docs/nagioscore/4/en/pluginapi.html +[13]:https://docs.sensu.io/ +[14]:https://sensu.io/community diff --git a/sources/tech/20180823 How To Easily And Safely Manage Cron Jobs In Linux.md b/sources/tech/20180823 How To Easily And Safely Manage Cron Jobs In Linux.md new file mode 100644 index 0000000000..aa4ec0a655 --- /dev/null +++ b/sources/tech/20180823 How To Easily And Safely Manage Cron Jobs In Linux.md @@ -0,0 +1,131 @@ +How To Easily And Safely Manage Cron Jobs In Linux +====== + +![](https://www.ostechnix.com/wp-content/uploads/2018/08/Crontab-UI-720x340.jpg) + +When it comes to schedule tasks in Linux, which utility comes to your mind first? Yeah, you guessed it right. **Cron!** The cron utility helps you to schedule commands/tasks at specific time in Unix-like operating systems. We already published a [**beginners guides to Cron jobs**][1]. I have a few years experience in Linux, so setting up cron jobs is no big deal for me. But, it is not piece of cake for newbies. The noobs may unknowingly do small mistakes while editing plain text crontab and bring down all cron jobs. Just in case, if you think you might mess up with your cron jobs, there is a good alternative way. Say hello to **Crontab UI** , a web-based tool to easily and safely manage cron jobs in Unix-like operating systems. + +You don’t need to manually edit the crontab file to create, delete and manage cron jobs. Everything can be done via a web browser with a couple mouse clicks. Crontab UI allows you to easily create, edit, pause, delete, backup cron jobs, and even import, export and deploy jobs on other machines without much hassle. Error log, mailing and hooks support also possible. It is free, open source and written using NodeJS. + +### Installing Crontab UI + +Installing Crontab UI is just a one-liner command. Make sure you have installed NPM. If you haven’t install npm yet, refer the following link. + +Next, run the following command to install Crontab UI. +``` +$ npm install -g crontab-ui + +``` + +It’s that simple. Let us go ahead and see how to manage cron jobs using Crontab UI. + +### Easily And Safely Manage Cron Jobs In Linux + +To launch Crontab UI, simply run: +``` +$ crontab-ui + +``` + +You will see the following output: +``` +Node version: 10.8.0 +Crontab UI is running at http://127.0.0.1:8000 + +``` + +Now, open your web browser and navigate to ****. Make sure the port no 8000 is allowed in your firewall/router. + +Please note that you can only access Crontab UI web dashboard within the local system itself. + +If you want to run Crontab UI with your system’s IP and custom port (so you can access it from any remote system in the network), use the following command instead: +``` +$ HOST=0.0.0.0 PORT=9000 crontab-ui +Node version: 10.8.0 +Crontab UI is running at http://0.0.0.0:9000 + +``` + +Now, Crontab UI can be accessed from the any system in the nework using URL – **http:// :9000**. + +This is how Crontab UI dashboard looks like. + +![](https://www.ostechnix.com/wp-content/uploads/2018/08/crontab-ui-dashboard.png) + +As you can see in the above screenshot, Crontab UI dashbaord is very simply. All options are self-explanatory. + +To exit Crontab UI, press **CTRL+C**. + +**Create, edit, run, stop, delete a cron job** + +To create a new cron job, click on “New” button. Enter your cron job details and click Save. + + 1. Name the cron job. It is optional. + 2. The full command you want to run. + 3. Choose schedule time. You can either choose the quick schedule time, (such as Startup, Hourly, Daily, Weekly, Monthly, Yearly) or set the exact time to run the command. After you choosing the schedule time, the syntax of the cron job will be shown in **Jobs** field. + 4. Choose whether you want to enable error logging for the particular job. + + + +Here is my sample cron job. + +![](https://www.ostechnix.com/wp-content/uploads/2018/08/create-new-cron-job.png) + +As you can see, I have setup a cron job to clear pacman cache at every month. + +Similarly, you can create any number of jobs as you want. You will see all cron jobs in the dashboard. + +![](https://www.ostechnix.com/wp-content/uploads/2018/08/crontab-ui-dashboard-1.png) + +If you wanted to change any parameter in a cron job, just click on the **Edit** button below the job and modify the parameters as you wish. To run a job immediately, click on the button that says **Run**. To stop a job, click **Stop** button. You can view the log details of any job by clicking on the **Log** button. If the job is no longer required, simply press **Delete** button. + +**Backup cron jobs** + +To backup all cron jobs, press the Backup from main dashboard and choose OK to confirm the backup. + +![](https://www.ostechnix.com/wp-content/uploads/2018/08/backup-cron-jobs.png) + +You can use this backup in case you messed with the contents of the crontab file. + +**Import/Export cron jobs to other systems** + +Another notable feature of Crontab UI is you can import, export and deploy cron jobs to other systems. If you have multiple systems on your network that requires the same cron jobs, just press **Export** button and choose the location to save the file. All contents of crontab file will be saved in a file named **crontab.db**. + +Here is the contents of the crontab.db file. +``` +$ cat Downloads/crontab.db +{"name":"Remove Pacman Cache","command":"rm -rf /var/cache/pacman","schedule":"@monthly","stopped":false,"timestamp":"Thu Aug 23 2018 10:34:19 GMT+0000 (Coordinated Universal Time)","logging":"true","mailing":{},"created":1535020459093,"_id":"lcVc1nSdaceqS1ut"} + +``` + +Then you can transfer the entire crontab.db file to some other system and import its to the new system. You don’t need to manually create cron jobs in all systems. Just create them in one system and export and import all of them to every system on the network. + +**Get the contents from or save to existing crontab file** + +There are chances that you might have already created some cron jobs using **crontab** command. If so, you can retrieve contents of the existing crontab file by click on the **“Get from crontab”** button in main dashboard. + +![](https://www.ostechnix.com/wp-content/uploads/2018/08/get-from-crontab.png) + +Similarly, you can save the newly created jobs using Crontab UI utility to existing crontab file in your system. To do so, just click **Save to crontab** option in the dashboard. + +See? Managing cron jobs is not that complicated. Any newbie user can easily maintain any number of jobs without much hassle using Crontab UI. Give it a try and let us know what do you think about this tool. I am all ears! + +And, that’s all for now. Hope this was useful. More good stuffs to come. Stay tuned! + +Cheers! + + + +-------------------------------------------------------------------------------- + +via: https://www.ostechnix.com/how-to-easily-and-safely-manage-cron-jobs-in-linux/ + +作者:[SK][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.ostechnix.com/author/sk/ +[1]:https://www.ostechnix.com/a-beginners-guide-to-cron-jobs/ diff --git a/sources/tech/20180824 Add free books to your eReader- Formatting tips.md b/sources/tech/20180824 Add free books to your eReader- Formatting tips.md new file mode 100644 index 0000000000..bbafc0023d --- /dev/null +++ b/sources/tech/20180824 Add free books to your eReader- Formatting tips.md @@ -0,0 +1,183 @@ +Add free books to your eReader: Formatting tips +====== + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/books_library_reading_list_colorful.jpg?itok=jJtnyniB) + +In my recent article, [A handy way to add free books to your eReader][1], I explained how to convert the plaintext indexes at [Project Gutenberg][2] to HTML and then EPUBs. But as one commenter noted, there is a problem in older indexes, where individual books are not always separated by an extra newline character. + +I saw quite vividly the extent of the problem when I was working on the index for 2007, where you see things like this: +``` +Audio: The General Epistle of James                                      22931 +Audio: The Epistle to the Hebrews                                        22930 +Audio: The Epistle of Philemon                                           22929 + +Sacrifice, by Stephen French Whitman                                     22928 +The Atlantic Monthly, Volume 18, No. 105, July 1866, by Various          22927 +The Continental Monthly, Vol. 6, No 3,  September 1864, by Various       22926 + +The Story of Young Abraham Lincoln, by Wayne Whipple                     22925 +Pathfinder, by Alan Douglas                                              22924 +  [Subtitle: or, The Missing Tenderfoot] +Pieni helmivyo, by Various                                               22923 +  [Subtitle: Suomen runoja koulunuorisolle] +  [Editor: J. Waananen]  [Language: Finnish] +The Posy Ring, by Various                                                22922 +``` + +My first reaction was, "Well, how bad can it be to just add newlines where needed?" The answer: "Really bad." After days of working this way and stopping only when the cramps in my hand became too annoying, I decided to revisit the problem. I thought I might need to do multiple Find-Replace passes, maybe keyed on things like `[Language: Finnish] `or maybe just the `]` bracket, but this seemed almost as laborious as the manual method. + +Then I noticed a particular feature: For most instances where a newline was needed, a newline character was immediately followed by the capital letter of the next title. For lines where there was still more information about the book, the newline was followed by spaces. So I tried this: In the Find text box in [KWrite][3] (remember, we’re using regex), I put: +``` +(\n[A-Z]) + +``` + +and in Replace, I put: +``` +\n\1 + +``` + +For every match inside the parentheses, I added a preceding newline, retaining whatever the capital letter was. This worked extremely well. The few instances where it failed involved book titles beginning with a number or with quotes. I fixed these manually, but I could have put this: +``` +(\n[0-9]) + +``` + +In Find and run Replace All again. Later, I also tried it with the quotes—this requires a backslash, like this: +``` +(\n\”) and (\n\’) + +``` + +One side effect is that a number of the listings were separated by three newline characters. Not an issue for XHTML, but easily fixed by putting in Find: +``` +\n\n\n + +``` + +and in Replace: +``` +\n\n + +``` + +To review the process with the new features: + + 1. Remove the preamble and other text you don’t want + 2. Add extra newlines with the method shown above + 3. Convert three consecutive newlines to two (optional) + 4. Add the appropriate HTML tags at the beginning and end + 5. Create the links based on finding `(\d\d\d\d\d)`, replacing with `
\1` + 6. Add paragraph tags by finding `\n\n` and replacing with `

\n\n

` + 7. Add a `

` just before the `` tag at the end + 8. Fix the headers, preceding each with `

` and changing the `

` to `

` – the older indexes have only a single header + 9. Save the file with an `.xhtml` suffix, then import to [Sigil][4] to make your EPUB. + + + +The next issue that comes up is when the eBook numbers include only four digits. This is a problem since there are many four-digit numbers in the listings, many of which are dates. The answer comes from modifying our strategy in point 5 in the above listing. + +In Find, put: + +`(\d\d\d\d)\n` + +and in Replace, put: + +`\1\n` + +Notice that the `\n` is outside the parentheses; therefore, we need to add it at the end of the new replacement. Now we see another problem resulting from this new method: Some of the eBook numbers are followed by C (copyrighted). So we need to do another pass in Find: + +`(\d\d\d\d)C\n` + +and in Replace: + +`\1C\n` + +I noticed that as of the 2002 index, the lack of extra newlines between listings was no longer a problem, and this continued all the way to the very first index, so steps 2 and 3 became unnecessary. + +I’ve now taken the process all the way to the beginning, GUTINDEX.1996, and this process works all the way. At one point three-digit eBook numbers appear, so you must begin to Find: + +`(\d\d\d)\n` and then `(\d\d\d)C\n` + +Then later: + +`(\d\d)\n` and then `(\d\d)C\n` + +And finally: + +`(\d)\n` + +The only glitch was in one book, eBook number 2, where the date "1798" was snagged by the three-digit search. At this point, I now have eBooks of the entire Gutenberg catalog, not counting new books presently being added. + +### Troubleshooting and a bonus + +I strongly advise you to test your XHTML files by trying to load them in a browser. Your browser should tell you if your XHTML is not properly formatted, in which case the file won’t show in your browser window. Two particular problems I found, having initially ignored my own advice, resulting from improper characters. I copied the link specification tags from my first article. If you do that, you will find that the typewriter quotes are substituted with typographic (curly) quotes. Fixing this was just a matter of doing a Find/Replace. + +Second, there are a number of ampersands (&) in the listings, and these need to be replaced by & for the browser to make sense of them. Some recent listings also use the Unicode non-breaking space, and these should be replaced with a regular space. (Hint: Copy one, put it in Find, put a regular space in Replace, then Replace All) + +Finally, there may be some accented characters lurking, and the browser feedback should help locate them. Example: Ibáñez needed to be Ibáñez. + +And now the bonus: Once your XHTML is well-formed, you can use your browser to comb Project Gutenberg just like on your e-reader. I also found that [Calibre][5] would not make the links properly until the quotes were fixed. + +Finally, here is a template for a separate web page you can place on your system to easily link to each year’s listing on your system. Make sure you fix the locations for your personal directory structure and filenames. Also, make sure all these quotes are typewriter quotes, not curly quotes. +``` + + + + + +GutIndexes + + +

GutIndexes

+ + + + + + + + + + + + + + + + + + + + + + + + + + +
19961997199819992000
20012002200320042005
20062007200820092010
20112012201320142015
201620172018
+
+ + +``` + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/8/more-books-your-ereader + +作者:[Greg Pittman][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://opensource.com/users/greg-p +[1]:https://opensource.com/article/18/4/browse-project-gutenberg-library +[2]:https://www.gutenberg.org/ +[3]:https://www.kde.org/applications/utilities/kwrite/ +[4]:https://sigil-ebook.com/ +[5]:https://calibre-ebook.com/ diff --git a/sources/tech/20180824 Joplin- Encrypted Open Source Note Taking And To-Do Application.md b/sources/tech/20180824 Joplin- Encrypted Open Source Note Taking And To-Do Application.md new file mode 100644 index 0000000000..5c520c8021 --- /dev/null +++ b/sources/tech/20180824 Joplin- Encrypted Open Source Note Taking And To-Do Application.md @@ -0,0 +1,78 @@ +Joplin: Encrypted Open Source Note Taking And To-Do Application +====== +**[Joplin][1] is a free and open source note taking and to-do application available for Linux, Windows, macOS, Android and iOS. Its key features include end-to-end encryption, Markdown support, and synchronization via third-party services like NextCloud, Dropbox, OneDrive or WebDAV.** + +![](https://1.bp.blogspot.com/-vLLYx1Pfmb0/W3_wq_B0avI/AAAAAAAABb8/B9pe5NXVzg83A6Lm6_0ORMe9aWqtfTn4gCLcBGAs/s640/joplin-notes.png) + +With Joplin you can write your notes in the **Markdown format** (with support for math notations and checkboxes) and the desktop app comes with 3 views: Markdown code, Markdown preview, or both side by side. **You can add attachments to your notes (with image previews) or edit them in an external Markdown editor** and have them automatically updated in Joplin each time you save the file. + +The application should handle a large number of notes pretty well by allowing you to **organizing notes into notebooks, add tags, and search in notes**. You can also sort notes by updated date, creation date or title. **Each notebook can contain notes, to-do items, or both** , and you can easily add links to other notes (in the desktop app right click on a note and select `Copy Markdown link` , then paste the link in a note). + +**Do-do items in Joplin support alarms** , but this feature didn't work for me on Ubuntu 18.04. + +**Other Joplin features include:** + + * **Optional Web Clipper extension** for Firefox and Chrome (in the Joplin desktop application go to `Tools > Web clipper options` to enable the clipper service and find download links for the Chrome / Firefox extension) which can clip simplified or complete pages, clip a selection or screenshot. + + * **Optional command line client**. + + * **Import Enex files (Evernote export format) and Markdown files**. + + * **Export JEX files (Joplin Export format), PDF and raw files**. + + * **Offline first, so the entire data is always available on the device even without an internet connection**. + + * **Geolocation support**. + + + +[![Joplin notes checkboxes link to other note][2]][3] +Joplin with hidden sidebar showing checkboxes and a link to another note + +While it doesn't offer as many features as Evernote, Joplin is a robust open source Evernote alternative. Joplin includes all the basic features, and on top of that it's open source software, it includes encryption support, and you also get to choose the service you want to use for synchronization. + +The application was actually designed as an Evernote alternative so it can import complete Evernote notebooks, notes, tags, attachments, and note metadata like the author, creation and updated time, or geolocation. + +Another aspect on which the Joplin development was focused was to avoid being tied to a particular company or service. This is why the application offers multiple synchronization solutions, like NextCloud, Dropbox, oneDrive and WebDav, while also making it easy to support new services. It's also easy to switch from one service to another if you change your mind. + +**I should note that Joplin doesn't use encryption by default and you must enable this from its settings. Go to** `Tools > Encryption options` and enable the Joplin end-to-end encryption from there. + +### Download Joplin + +[Download Joplin][7] + +**Joplin is available for Linux, Windows, macOS, Android and iOS. On Linux, there's an AppImage as well as an Aur package available.** + +To run the Joplin AppImage on Linux, double click it and select `Make executable and run` if your file manager supports this. If not, you'll need to make it executable either using your file manager (should be something like: `right click > Properties > Permissions > Allow executing file as program` , but this may vary depending on the file manager you use), or from the command line: +``` +chmod +x /path/to/Joplin-*-x86_64.AppImage + +``` + +Replacing `/path/to/` with the path to where you downloaded Joplin. Now you can double click the Joplin Appimage file to launch it. + +**TIP:** If you integrate Joplin to your menu and `~/.local/share/applications/appimagekit-joplin.desktop`) and adding `StartupWMClass=Joplin` at the end of the file on a new line, without modifying anything else. + +Joplin has a **command line client** that can be [installed using npm][5] (for Debian, Ubuntu or Linux Mint, see [how to install and configure Node.js and npm][6] ). + + +-------------------------------------------------------------------------------- + +via: https://www.linuxuprising.com/2018/08/joplin-encrypted-open-source-note.html + +作者:[Logix][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://plus.google.com/118280394805678839070 +[1]:https://joplin.cozic.net/ +[2]:https://3.bp.blogspot.com/-y9JKL1F89Vo/W3_0dkZjzQI/AAAAAAAABcI/hQI7GAx6i_sMcel4mF0x4uxBrMO88O59wCLcBGAs/s640/joplin-notes-markdown.png (Joplin notes checkboxes link to other note) +[3]:https://3.bp.blogspot.com/-y9JKL1F89Vo/W3_0dkZjzQI/AAAAAAAABcI/hQI7GAx6i_sMcel4mF0x4uxBrMO88O59wCLcBGAs/s1600/joplin-notes-markdown.png +[4]:https://github.com/laurent22/joplin/issues/338 +[5]:https://joplin.cozic.net/terminal/ +[6]:https://www.linuxuprising.com/2018/04/how-to-install-and-configure-nodejs-and.html + +[7]: https://joplin.cozic.net/#installation diff --git a/sources/tech/20180824 What Stable Kernel Should I Use.md b/sources/tech/20180824 What Stable Kernel Should I Use.md new file mode 100644 index 0000000000..bfd64a2ec2 --- /dev/null +++ b/sources/tech/20180824 What Stable Kernel Should I Use.md @@ -0,0 +1,139 @@ +What Stable Kernel Should I Use? +====== +I get a lot of questions about people asking me about what stable kernel should they be using for their product/device/laptop/server/etc. all the time. Especially given the now-extended length of time that some kernels are being supported by me and others, this isn’t always a very obvious thing to determine. So this post is an attempt to write down my opinions on the matter. Of course, you are free to use what ever kernel version you want, but here’s what I recommend. + +As always, the opinions written here are my own, I speak for no one but myself. + +### What kernel to pick + +Here’s the my short list of what kernel you should use, raked from best to worst options. I’ll go into the details of all of these below, but if you just want the summary of all of this, here it is: + +Hierarchy of what kernel to use, from best solution to worst: + + * Supported kernel from your favorite Linux distribution + * Latest stable release + * Latest LTS release + * Older LTS release that is still being maintained + + + +What kernel to never use: + + * Unmaintained kernel release + + + +To give numbers to the above, today, as of August 24, 2018, the front page of kernel.org looks like this: + +![][1] + +So, based on the above list that would mean that: + + * 4.18.5 is the latest stable release + * 4.14.67 is the latest LTS release + * 4.9.124, 4.4.152, and 3.16.57 are the older LTS releases that are still being maintained + * 4.17.19 and 3.18.119 are “End of Life” kernels that have had a release in the past 60 days, and as such stick around on the kernel.org site for those who still might want to use them. + + + +Quite easy, right? + +Ok, now for some justification for all of this: + +### Distribution kernels + +The best solution for almost all Linux users is to just use the kernel from your favorite Linux distribution. Personally, I prefer the community based Linux distributions that constantly roll along with the latest updated kernel and it is supported by that developer community. Distributions in this category are Fedora, openSUSE, Arch, Gentoo, CoreOS, and others. + +All of these distributions use the latest stable upstream kernel release and make sure that any needed bugfixes are applied on a regular basis. That is the one of the most solid and best kernel that you can use when it comes to having the latest fixes ([remember all fixes are security fixes][2]) in it. + +There are some community distributions that take a bit longer to move to a new kernel release, but eventually get there and support the kernel they currently have quite well. Those are also great to use, and examples of these are Debian and Ubuntu. + +Just because I did not list your favorite distro here does not mean its kernel is not good. Look on the web site for the distro and make sure that the kernel package is constantly updated with the latest security patches, and all should be well. + +Lots of people seem to like the old, “traditional” model of a distribution and use RHEL, SLES, CentOS or the “LTS” Ubuntu release. Those distros pick a specific kernel version and then camp out on it for years, if not decades. They do loads of work backporting the latest bugfixes and sometimes new features to these kernels, all in a Quixote quest to keep the version number from never being changed, despite having many thousands of changes on top of that older kernel version. This work is a truly thankless job, and the developers assigned to these tasks do some wonderful work in order to achieve these goals. If you like never seeing your kernel version number change, then use these distributions. They usually cost some money to use, but the support you get from these companies is worth it when something goes wrong. + +So again, the best kernel you can use is one that someone else supports, and you can turn to for help. Use that support, usually you are already paying for it (for the enterprise distributions), and those companies know what they are doing. + +But, if you do not want to trust someone else to manage your kernel for you, or you have hardware that a distribution does not support, then you want to run the Latest stable release: + +### Latest stable release + +This kernel is the latest one from the Linux kernel developer community that they declare as “stable”. About every three months, the community releases a new stable kernel that contains all of the newest hardware support, the latest performance improvements, as well as the latest bugfixes for all parts of the kernel. Over the next 3 months, bugfixes that go into the next kernel release to be made are backported into this stable release, so that any users of this kernel are sure to get them as soon as possible. + +This is usually the kernel that most community distributions use as well, so you can be sure it is tested and has a large audience of users. Also, the kernel community (all 4000+ developers) are willing to help support users of this release, as it is the latest one that they made. + +After 3 months, a new kernel is released and you should move to it to ensure that you stay up to date, as support for this kernel is usually dropped a few weeks after the newer release happens. + +If you have new hardware that is purchased after the last LTS release came out, you almost are guaranteed to have to run this kernel in order to have it supported. So for desktops or new servers, this is usually the recommended kernel to be running. + +### Latest LTS release + +If your hardware relies on a vendors out-of-tree patch in order to make it work properly (like almost all embedded devices these days), then the next best kernel to be using is the latest LTS release. That release gets all of the latest kernel fixes that goes into the stable releases where applicable, and lots of users test and use it. + +Note, no new features and almost no new hardware support is ever added to these kernels, so if you need to use a new device, it is better to use the latest stable release, not this release. + +Also this release is common for users that do not like to worry about “major” upgrades happening on them every 3 months. So they stick to this release and upgrade every year instead, which is a fine practice to follow. + +The downsides of using this release is that you do not get the performance improvements that happen in newer kernels, except when you update to the next LTS kernel, potentially a year in the future. That could be significant for some workloads, so be very aware of this. + +Also, if you have problems with this kernel release, the first thing that any developer whom you report the issue to is going to ask you to do is, “does the latest stable release have this problem?” So you will need to be aware that support might not be as easy to get as with the latest stable releases. + +Now if you are stuck with a large patchset and can not update to a new LTS kernel once a year, perhaps you want the older LTS releases: + +### Older LTS release + +These releases have traditionally been supported by the community for 2 years, sometimes longer for when a major distribution relies on this (like Debian or SLES). However in the past year, thanks to a lot of suport and investment in testing and infrastructure from Google, Linaro, Linaro member companies, [kernelci.org][3], and others, these kernels are starting to be supported for much longer. + +Here’s the latest LTS releases and how long they will be supported for, as shown at [kernel.org/category/releases.html][4] on August 24, 2018: + +![][5] + +The reason that Google and other companies want to have these kernels live longer is due to the crazy (some will say broken) development model of almost all SoC chips these days. Those devices start their development lifecycle a few years before the chip is released, however that code is never merged upstream, resulting in a brand new chip being released based on a 2 year old kernel. These SoC trees usually have over 2 million lines added to them, making them something that I have started calling “Linux-like” kernels. + +If the LTS releases stop happening after 2 years, then support from the community instantly stops, and no one ends up doing bugfixes for them. This results in millions of very insecure devices floating around in the world, not something that is good for any ecosystem. + +Because of this dependency, these companies now require new devices to constantly update to the latest LTS releases as they happen for their specific release version (i.e. every 4.9.y release that happens). An example of this is the Android kernel requirements for new devices shipping for the “O” and now “P” releases specified the minimum kernel version allowed, and Android security releases might start to require those “.y” releases to happen more frequently on devices. + +I will note that some manufacturers are already doing this today. Sony is one great example of this, updating to the latest 4.4.y release on many of their new phones for their quarterly security release. Another good example is the small company Essential which has been tracking the 4.4.y releases faster than anyone that I know of. + +There is one huge caveat when using a kernel like this. The number of security fixes that get backported are not as great as with the latest LTS release, because the traditional model of the devices that use these older LTS kernels is a much more reduced user model. These kernels are not to be used in any type of “general computing” model where you have untrusted users or virtual machines, as the ability to do some of the recent Spectre-type fixes for older releases is greatly reduced, if present at all in some branches. + +So again, only use older LTS releases in a device that you fully control, or lock down with a very strong security model (like Android enforces using SELinux and application isolation). Never use these releases on a server with untrusted users, programs, or virtual machines. + +Also, support from the community for these older LTS releases is greatly reduced even from the normal LTS releases, if available at all. If you use these kernels, you really are on your own, and need to be able to support the kernel yourself, or rely on you SoC vendor to provide that support for you (note that almost none of them do provide that support, so beware…) + +### Unmaintained kernel release + +Surprisingly, many companies do just grab a random kernel release, slap it into their product and proceed to ship it in hundreds of thousands of units without a second thought. One crazy example of this would be the Lego Mindstorm systems that shipped a random -rc release of a kernel in their device for some unknown reason. A -rc release is a development release that not even the Linux kernel developers feel is ready for everyone to use just yet, let alone millions of users. + +You are of course free to do this if you want, but note that you really are on your own here. The community can not support you as no one is watching all kernel versions for specific issues, so you will have to rely on in-house support for everything that could go wrong. Which for some companies and systems, could be just fine, but be aware of the “hidden” cost this might cause if you do not plan for this up front. + +### Summary + +So, here’s a short list of different types of devices, and what I would recommend for their kernels: + + * Laptop / Desktop: Latest stable release + * Server: Latest stable release or latest LTS release + * Embedded device: Latest LTS release or older LTS release if the security model used is very strong and tight. + + + +And as for me, what do I run on my machines? My laptops run the latest development kernel (i.e. Linus’s development tree) plus whatever kernel changes I am currently working on and my servers run the latest stable release. So despite being in charge of the LTS releases, I don’t run them myself, except in testing systems. I rely on the development and latest stable releases to ensure that my machines are running the fastest and most secure releases that we know how to create at this point in time. + +-------------------------------------------------------------------------------- + +via: http://kroah.com/log/blog/2018/08/24/what-stable-kernel-should-i-use/ + +作者:[Greg Kroah-Hartman][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:http://kroah.com +[1]:https://s3.amazonaws.com/kroah.com/images/kernel.org_2018_08_24.png +[2]:http://kroah.com/log/blog/2018/02/05/linux-kernel-release-model/ +[3]:https://kernelci.org/ +[4]:https://www.kernel.org/category/releases.html +[5]:https://s3.amazonaws.com/kroah.com/images/kernel.org_releases_2018_08_24.png diff --git a/sources/tech/20180827 4 tips for better tmux sessions.md b/sources/tech/20180827 4 tips for better tmux sessions.md new file mode 100644 index 0000000000..b6d6a3e4fe --- /dev/null +++ b/sources/tech/20180827 4 tips for better tmux sessions.md @@ -0,0 +1,89 @@ +translating by lujun9972 +4 tips for better tmux sessions +====== + +![](https://fedoramagazine.org/wp-content/uploads/2018/08/tmux-4-tips-816x345.jpg) + +The tmux utility, a terminal multiplexer, lets you treat your terminal as a multi-paned window into your system. You can arrange the configuration, run different processes in each, and generally make better use of your screen. We introduced some readers to this powerful tool [in this earlier article][1]. Here are some tips that will help you get more out of tmux if you’re getting started. + +This article assumes your current prefix key is Ctrl+b. If you’ve remapped that prefix, simply substitute your prefix in its place. + +### Set your terminal to automatically use tmux + +One of the biggest benefits of tmux is being able to disconnect and reconnect to sesions at wilI. This makes remote login sessions more powerful. Have you ever lost a connection and wished you could get back the work you were doing on the remote system? With tmux this problem is solved. + +However, you may sometimes find yourself doing work on a remote system, and realize you didn’t start a session. One way to avoid this is to have tmux start or attach every time you login to a system with in interactive shell. + +Add this to your remote system’s ~/.bash_profile file: + +``` +if [ -z "$TMUX" ]; then + tmux attach -t default || tmux new -s default +fi +``` + +Then logout of the remote system, and log back in with SSH. You’ll find you’re in a tmux session named default. This session will be regenerated at next login if you exit it. But more importantly, if you detach from it as normal, your work is waiting for you next time you login — especially useful if your connection is interrupted. + +Of course you can add this to your local system as well. Note that terminals inside most GUIs won’t use the default session automatically, because they aren’t login shells. While you can change that behavior, it may result in nesting that makes the session less usable, so proceed with caution. + +### Use zoom to focus on a single process + +While the point of tmux is to offer multiple windows, panes, and processes in a single session, sometimes you need to focus. If you’re in a process and need more space, or to focus on a single task, the zoom command works well. It expands the current pane to take up the entire current window space. + +Zoom can be useful in other situations too. For instance, imagine you’re using a terminal window in a graphical desktop. Panes can make it harder to copy and paste multiple lines from inside your tmux session. If you zoom the pane, you can do a clean copy/paste of multiple lines of data with ease. + +To zoom into the current pane, hit Ctrl+b, z. When you’re finished with the zoom function, hit the same key combo to unzoom the pane. + +### Bind some useful commands + +By default tmux has numerous commands available. But it’s helpful to have some of the more common operations bound to keys you can easily remember. Here are some examples you can add to your ~/.tmux.conf file to make sessions more enjoyable: + +``` +bind r source-file ~/.tmux.conf \; display "Reloaded config" +``` + +This command rereads the commands and bindings in your config file. Once you add this binding, exit any tmux sessions and then restart one. Now after you make any other future changes, simply run Ctrl+b, r and the changes will be part of your existing session. + +``` +bind V split-window -h +bind H split-window +``` + +These commands make it easier to split the current window across a vertical axis (note that’s Shift+V) or across a horizontal axis (Shift+H). + +If you want to see how all keys are bound, use Ctrl+B, ? to see a list. You may see keys bound in copy-mode first, for when you’re working with copy and paste inside tmux. The prefix mode bindings are where you’ll see ones you’ve added above. Feel free to experiment with your own! + +### Use powerline for great justice + +[As reported in a previous Fedora Magazine article][2], the powerline utility is a fantastic addition to your shell. But it also has capabilities when used with tmux. Because tmux takes over the entire terminal space, the powerline window can provide more than just a better shell prompt. + + [![Screenshot of tmux powerline in git folder](https://fedoramagazine.org/wp-content/uploads/2018/08/Screenshot-from-2018-08-25-19-36-53-1024x690.png)][3] + +If you haven’t already, follow the instructions in the [Magazine’s powerline article][4] to install that utility. Then, install the addon [using sudo][5]: + +``` +sudo dnf install tmux-powerline +``` + +Now restart your session, and you’ll see a spiffy new status line at the bottom. Depending on the terminal width, the default status line now shows your current session ID, open windows, system information, date and time, and hostname. If you change directory into a git-controlled project, you’ll see the branch and color-coded status as well. + +Of course, this status bar is highly configurable as well. Enjoy your new supercharged tmux session, and have fun experimenting with it. + + +-------------------------------------------------------------------------------- + +via: https://fedoramagazine.org/4-tips-better-tmux-sessions/ + +作者:[Paul W. Frields][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[lujun9972](https://github.com/lujun9972) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://fedoramagazine.org/author/pfrields/ +[1]:https://fedoramagazine.org/use-tmux-more-powerful-terminal/ +[2]:https://fedoramagazine.org/add-power-terminal-powerline/ +[3]:https://fedoramagazine.org/wp-content/uploads/2018/08/Screenshot-from-2018-08-25-19-36-53.png +[4]:https://fedoramagazine.org/add-power-terminal-powerline/ +[5]:https://fedoramagazine.org/howto-use-sudo/ diff --git a/sources/tech/20180827 A sysadmin-s guide to containers.md b/sources/tech/20180827 A sysadmin-s guide to containers.md new file mode 100644 index 0000000000..a6529d8842 --- /dev/null +++ b/sources/tech/20180827 A sysadmin-s guide to containers.md @@ -0,0 +1,59 @@ +A sysadmin's guide to containers +====== + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/toolbox-learn-draw-container-yearbook.png?itok=xDbwz1pP) + +The term "containers" is heavily overused. Also, depending on the context, it can mean different things to different people. + +Traditional Linux containers are really just ordinary processes on a Linux system. These groups of processes are isolated from other groups of processes using resource constraints (control groups [cgroups]), Linux security constraints (Unix permissions, capabilities, SELinux, AppArmor, seccomp, etc.), and namespaces (PID, network, mount, etc.). + +If you boot a modern Linux system and took a look at any process with `cat /proc/PID/cgroup`, you see that the process is in a cgroup. If you look at `/proc/PID/status`, you see capabilities. If you look at `/proc/self/attr/current`, you see SELinux labels. If you look at `/proc/PID/ns`, you see the list of namespaces the process is in. So, if you define a container as a process with resource constraints, Linux security constraints, and namespaces, by definition every process on a Linux system is in a container. This is why we often say [Linux is containers, containers are Linux][1]. **Container runtimes** are tools that modify these resource constraints, security, and namespaces and launch the container. + +Docker introduced the concept of a **container image** , which is a standard TAR file that combines: + + * **Rootfs (container root filesystem):** A directory on the system that looks like the standard root (`/`) of the operating system. For example, a directory with `/usr`, `/var`, `/home`, etc. + * **JSON file (container configuration):** Specifies how to run the rootfs; for example, what **command** or **entrypoint** to run in the rootfs when the container starts; **environment variables** to set for the container; the container's **working directory** ; and a few other settings. + + + +Docker "`tar`'s up" the rootfs and the JSON file to create the **base image**. This enables you to install additional content on the rootfs, create a new JSON file, and `tar` the difference between the original image and the new image with the updated JSON file. This creates a **layered image**. + +The definition of a container image was eventually standardized by the [Open Container Initiative (OCI)][2] standards body as the [OCI Image Specification][3]. + +Tools used to create container images are called **container image builders**. Sometimes container engines perform this task, but several standalone tools are available that can build container images. + +Docker took these container images ( **tarballs** ) and moved them to a web service from which they could be pulled, developed a protocol to pull them, and called the web service a **container registry**. + +**Container engines** are programs that can pull container images from container registries and reassemble them onto **container storage**. Container engines also launch **container runtimes** (see below). + +![](https://opensource.com/sites/default/files/linux_container_internals_2.0_-_hosts.png) + +Container storage is usually a **copy-on-write** (COW) layered filesystem. When you pull down a container image from a container registry, you first need to untar the rootfs and place it on disk. If you have multiple layers that make up your image, each layer is downloaded and stored on a different layer on the COW filesystem. The COW filesystem allows each layer to be stored separately, which maximizes sharing for layered images. Container engines often support multiple types of container storage, including `overlay`, `devicemapper`, `btrfs`, `aufs`, and `zfs`. + + +After the container engine downloads the container image to container storage, it needs to create aThe runtime configuration combines input from the caller/user along with the content of the container image specification. For example, the caller might want to specify modifications to a running container's security, add additional environment variables, or mount volumes to the container. + +The layout of the container runtime configuration and the exploded rootfs have also been standardized by the OCI standards body as the [OCI Runtime Specification][4]. + +Finally, the container engine launches a **container runtime** that reads the container runtime specification; modifies the Linux cgroups, Linux security constraints, and namespaces; and launches the container command to create the container's **PID 1**. At this point, the container engine can relay `stdin`/`stdout` back to the caller and control the container (e.g., stop, start, attach). + +Note that many new container runtimes are being introduced to use different parts of Linux to isolate containers. People can now run containers using KVM separation (think mini virtual machines) or they can use other hypervisor strategies (like intercepting all system calls from processes in containers). Since we have a standard runtime specification, these tools can all be launched by the same container engines. Even Windows can use the OCI Runtime Specification for launching Windows containers. + +At a much higher level are **container orchestrators.** Container orchestrators are tools used to coordinate the execution of containers on multiple different nodes. Container orchestrators talk to container engines to manage containers. Orchestrators tell the container engines to start containers and wire their networks together. Orchestrators can monitor the containers and launch additional containers as the load increases. + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/8/sysadmins-guide-containers + +作者:[Daniel J Walsh][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://opensource.com/users/rhatdan +[1]:https://www.redhat.com/en/blog/containers-are-linux +[2]:https://www.opencontainers.org/ +[3]:https://github.com/opencontainers/image-spec/blob/master/spec.md +[4]:https://github.com/opencontainers/runtime-spec diff --git a/sources/tech/20180827 Solve -error- failed to commit transaction (conflicting files)- In Arch Linux.md b/sources/tech/20180827 Solve -error- failed to commit transaction (conflicting files)- In Arch Linux.md new file mode 100644 index 0000000000..bb0479e7fe --- /dev/null +++ b/sources/tech/20180827 Solve -error- failed to commit transaction (conflicting files)- In Arch Linux.md @@ -0,0 +1,50 @@ +translating by lujun9972 +Solve "error: failed to commit transaction (conflicting files)" In Arch Linux +====== + +![](https://www.ostechnix.com/wp-content/uploads/2018/06/arch_linux_wallpaper-720x340.png) + +It’s been a month since I upgraded my Arch Linux desktop. Today, I tried to update my Arch Linux system, and ran into an error that said **“error: failed to commit transaction (conflicting files) stfl: /usr/lib/libstfl.so.0 exists in filesystem”**. It looks like one library (/usr/lib/libstfl.so.0) that exists on my filesystem and pacman can’t upgrade it. If you’re encountered with the same error, here is a quick fix to resolve it. + +### Solve “error: failed to commit transaction (conflicting files)” In Arch Linux + +You have three options. + +1. Simply ignore the problematic **stfl** library from being upgraded and try to update the system again. Refer this guide to know [**how to ignore package from being upgraded**][1]. + +2. Overwrite the package using command: +``` +$ sudo pacman -Syu --overwrite /usr/lib/libstfl.so.0 +``` + +3. Remove stfl library file manually and try to upgrade the system again. Please make sure the intended package is not a dependency to any important package. and check the archlinux.org whether are mentions of this conflict. +``` +$ sudo rm /usr/lib/libstfl.so.0 +``` + +Now, try to update the system: +``` +$ sudo pacman -Syu +``` + +I chose the third option and just deleted the file and upgraded my Arch Linux system. It works now! + +Hope this helps. More good stuffs to come. Stay tuned! + +Cheers! + + + +-------------------------------------------------------------------------------- + +via: https://www.ostechnix.com/how-to-solve-error-failed-to-commit-transaction-conflicting-files-in-arch-linux/ + +作者:[SK][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[lujun9972](https://github.com/lujun9972) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.ostechnix.com/author/sk/ +[1]:https://www.ostechnix.com/safely-ignore-package-upgraded-arch-linux/ diff --git a/sources/tech/20180827 Top 10 Raspberry Pi blogs to follow.md b/sources/tech/20180827 Top 10 Raspberry Pi blogs to follow.md new file mode 100644 index 0000000000..a6f4e965c5 --- /dev/null +++ b/sources/tech/20180827 Top 10 Raspberry Pi blogs to follow.md @@ -0,0 +1,94 @@ +Translating by jlztan + +Top 10 Raspberry Pi blogs to follow +====== + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/raspberry-pi-juggle.png?itok=oTgGGSRA) + +There are plenty of great Raspberry Pi fan sites, tutorials, repositories, YouTube channels, and other resources on the web. Here are my top 10 favorite Raspberry Pi blogs, in no particular order. + +### 1. Raspberry Pi Spy + +Raspberry Pi fan Matt Hawkins has been writing a broad range of comprehensive and informative tutorials on his site, Raspberry Pi Spy, since the early days. I have learned a lot directly from this site, and Matt always seems to be the first to cover many topics. I have reached out for help many times in my first three years in the world of hacking and making with Raspberry Pi. + +Fortunately for everyone, this early adopter site is still going strong. I hope to see it live on, giving new community members a helping hand when they need it. + +### 2. Adafruit + +Adafruit is one of the biggest names in hardware hacking. The company makes and sells beautiful hardware and provides excellent tutorials written by staff, community members, and even the wonderful Lady Ada herself. + +As well as being a webshop, Adafruit also run a blog, which is full to the brim of great content from around the world. Check out the Raspberry Pi category, especially at the end of the work week, as [Friday is Pi Day][1] at Adafruit Towers. + +### 3. Recantha's Raspberry Pi Pod + +Mike Horne (Recantha) is a key Pi community member in the UK who runs the [CamJam and Potton Pi & Pint][2] (two Raspberry Jams in Cambridge) and [Pi Wars][3] (an annual Pi robotics competition). He gives advice to others setting up Jams and always has time to help beginners. With his co-organizer Tim Richardson, Horne developed the CamJam Edu Kit (a series of small and affordable kits for beginners to learn physical computing with Python). + +On top of all this, he runs the Pi Pod, a blog full of anything and everything Pi-related from around the world. It's probably the most regularly updated Pi blog on this list, so it's a great way to keep your finger on the pulse of the Pi community. + +### 4. Raspberry Pi blog + +Not forgetting the official [Raspberry Pi Foundation][4], this blog covers a range of content from the Foundation's world of hardware, software, education, community, and charity and youth coding clubs. Big themes on the blog are digital making at home, empowerment through education, as well as official news on hardware releases and software updates. + +The blog has been running [since 2011][5] and provides an [archive][6] of all 1800+ posts since that time. You can also follow [@raspberrypi_otd][7] on Twitter, which is a bot I created in [Python][8] (for an [Opensource.com tutorial][9], of course). The bot tweets links to blog posts from the current day in previous years from the Raspberry Pi blog archive. + +### 5. RasPi.tv + +Another seminal Raspberry Pi community member is Alex Eames, who got on board early on with his blog and YouTube channel, RasPi.tv. The site is packed with high-quality, well-produced video tutorials and written guides covering maker projects for all. + +Alex makes a series of add-on boards and accessories for the Pi as [RasP.iO][10], including a handy GPIO port label, reference rulers, and more. His blog branches out into [Arduino][11], [WEMO][12], and other small boards too. + +### 6. pyimagesearch + +Though not strictly a Raspberry Pi blog (the "py" in the name is for "Python," not "Raspberry Pi"), this site features an extensive [Raspberry Pi category][13]. Adrian Rosebrock earned a PhD studying the fields of computer vision and machine learning. His blog aims to share the machine learning tricks he's picked up while studying and making his own computer vision projects. + +If you want to learn about facial or object recognition using the Pi camera module, this is the place to be. Adrian's knowledge and practical application of deep learning and AI for image recognition is second to none—and he writes up his projects so that anyone can try. + +### 7. Raspberry Pi Roundup + +One of the UK's official Raspberry Pi resellers, The Pi Hut, maintains a blog curating the finds of the week. It's another great resource to keep up with what's on in the Pi world, and worth looking back through past issues. + +### 8. Dave Akerman + +A leading expert in high-altitude ballooning, Dave Akerman shares his knowledge and experience with balloon launches at minimal cost using Raspberry Pi. He publishes writeups of his launches with photos from the stratosphere and offers tips on how to launch a Pi balloon yourself. + +Check out Dave's blogfor amazing photography from near space. + +### 9. Pimoroni + +A world-renowned Raspberry Pi reseller based in Sheffield in the UK, Pimoroni made the famous [Pibow Rainbow case][14] and followed it up with a host of incredible custom add-on boards and accessories. + +Pimoroni's blog is laid out as beautifully as its hardware design and branding, and it provides great content for makers and hobbyists at home. The blog accompanies their entertaining YouTube channel [Bilge Tank][15]. + +### 10. Stuff About Code + +Martin O'Hanlon is a Pi community member-turned-Foundation employee who started out hacking Minecraft on the Pi for fun and recently joined the Foundation as a content writer. Luckily, Martin's new job hasn't stopped him from updating his blog and sharing useful tidbits with the world. As well as lots on Minecraft, you'll find stuff on the Python libraries, [Blue Dot][16], and [guizero][17], along with general Raspberry Pi tips. + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/8/top-10-raspberry-pi-blogs-follow + +作者:[Ben Nuttall][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://opensource.com/users/bennuttall +[1]:https://blog.adafruit.com/category/raspberry-pi/ +[2]:https://camjam.me/?page_id=753 +[3]:https://piwars.org/ +[4]:https://www.raspberrypi-spy.co.uk/ +[5]:https://www.raspberrypi.org/blog/first-post/ +[6]:https://www.raspberrypi.org/blog/archive/ +[7]:https://twitter.com/raspberrypi_otd +[8]:https://github.com/bennuttall/rpi-otd-bot/blob/master/src/bot.py +[9]:https://opensource.com/article/17/8/raspberry-pi-twitter-bot +[10]:https://rasp.io/ +[11]:https://www.arduino.cc/ +[12]:http://community.wemo.com/ +[13]:https://www.pyimagesearch.com/category/raspberry-pi/ +[14]:https://shop.pimoroni.com/products/pibow-for-raspberry-pi-3-b-plus +[15]:https://www.youtube.com/channel/UCuiDNTaTdPTGZZzHm0iriGQ +[16]:https://bluedot.readthedocs.io/en/latest/# +[17]:https://lawsie.github.io/guizero/ diff --git a/sources/tech/20180828 An Introduction to Quantum Computing with Open Source Cirq Framework.md b/sources/tech/20180828 An Introduction to Quantum Computing with Open Source Cirq Framework.md new file mode 100644 index 0000000000..8cec20916d --- /dev/null +++ b/sources/tech/20180828 An Introduction to Quantum Computing with Open Source Cirq Framework.md @@ -0,0 +1,228 @@ +An Introduction to Quantum Computing with Open Source Cirq Framework +====== +As the title suggests what we are about to begin discussing, this article is an effort to understand how far we have come in Quantum Computing and where we are headed in the field in order to accelerate scientific and technological research, through an Open Source perspective with Cirq. + +First, we will introduce you to the world of Quantum Computing. We will try our best to explain the basic idea behind the same before we look into how Cirq would be playing a significant role in the future of Quantum Computing. Cirq, as you might have heard of recently, has been breaking news in the field and in this Open Science article, we will try to find out why. + + + +Before we start with what Quantum Computing is, it is essential to get to know about the term Quantum, that is, a [subatomic particle][1] referring to the smallest known entity. The word [Quantum][2] is based on the Latin word Quantus, meaning, “how little”, as described in this short video: + + + +It will be easier for us to understand Quantum Computing by comparing it first to Classical Computing. Classical Computing refers to how today’s conventional computers are designed to work. The device with which you are reading this article right now, can also be referred to as a Classical Computing Device. + +### Classical Computing + +Classical Computing is just another way to describe how a conventional computer works. They work via a binary system, i.e, information is stored using either 1 or 0. Our Classical computers cannot understand any other form. + +In literal terms inside the computer, a transistor can be either on (1) or off (0). Whatever information we provide input to, is translated into 0s and 1s, so that the computer can understand and store that information. Everything is represented only with the help of a combination of 0s and 1s. + + + +### Quantum Computing + +Quantum Computing, on the other hand, does not follow an “on or off” model like Classical Computing. Instead, it can simultaneously handle multiple states of information with help of two phenomena called [superimposition and entanglement][3], thus accelerating computing at a much faster rate and also facilitating greater productivity in information storage. + +Please note that superposition and entanglement are [not the same phenomena][4]. + + + +![][5] + +So, if we have bits in Classical Computing, then in the case of Quantum Computing, we would have qubits (or Quantum bits) instead. To know more about the vast difference between the two, check this [page][6] from where the above pic was obtained for explanation. + +Quantum Computers are not going to replace our Classical Computers. But, there are certain humongous tasks that our Classical Computers will never be able to accomplish and that is when Quantum Computers would prove extremely resourceful. The following video describes the same in detail while also describing how Quantum Computers work: + + + +A comprehensive video on the progress in Quantum Computing so far: + + + +### Noisy Intermediate Scale Quantum + +According to the very recently updated research paper (31st July 2018), the term “Noisy” refers to inaccuracy because of producing an incorrect value caused by imperfect control over qubits. This inaccuracy is why there will be serious limitations on what Quantum devices can achieve in the near term. + +“Intermediate Scale” refers to the size of Quantum Computers which will be available in the next few years, where the number of qubits can range from 50 to a few hundred. 50 qubits is a significant milestone because that’s beyond what can be simulated by [brute force][7] using the most powerful existing digital [supercomputers][8]. Read more in the paper [here][9]. + +With the advent of Cirq, a lot is about to change. + +### What is Cirq? + +Cirq is a python framework for creating, editing, and invoking Noisy Intermediate Scale Quantum (NISQ) circuits that we just talked about. In other words, Cirq can address challenges to improve accuracy and reduce noise in Quantum Computing. + +Cirq does not necessarily require an actual Quantum Computer for execution. Cirq can also use a simulator-like interface to perform Quantum circuit simulations. + +Cirq is gradually grabbing a lot of pace, with one of its first users being [Zapata][10], formed last year by a [group of scientists][11] from Harvard University focused on Quantum Computing. + +### Getting started with Cirq on Linux + +The developers of the Open Source [Cirq library][12] recommend the installation in a [virtual python environment][13] like [virtualenv][14]. The developers’ installation guide for Linux can be found [here][15]. + +However, we successfully installed and tested Cirq directly for Python3 on an Ubuntu 16.04 system via the following steps: + +#### Installing Cirq on Ubuntu + +![Cirq Framework for Quantum Computing in Linux][16] + +First, we would require pip or pip3 to install Cirq. [Pip][17] is a tool recommended for installing and managing Python packages. + +For Python 3.x versions, Pip can be installed with: +``` +sudo apt-get install python3-pip + +``` + +Python3 packages can be installed via: +``` +pip3 install + +``` + +We went ahead and installed the Cirq library with Pip3 for Python3: +``` +pip3 install cirq + +``` + +#### Enabling Plot and PDF generation (optional) + +Optional system dependencies not install-able with pip can be installed with: +``` +sudo apt-get install python3-tk texlive-latex-base latexmk + +``` + + * python3-tk is Python’s own graphic library which enables plotting functionality. + * texlive-latex-base and latexmk enable PDF writing functionality. + + + +Later, we successfully tested Cirq with the following command and code: +``` +python3 -c 'import cirq; print(cirq.google.Foxtail)' + +``` + +We got the resulting output as: + +![][18] + +#### Configuring Pycharm IDE for Cirq + +We also configured a Python IDE [PyCharm on Ubuntu][19] to test the same results: + +Since we installed Cirq for Python3 on our Linux system, we set the path to the project interpreter in the IDE settings to be: +``` +/usr/bin/python3 + +``` + +![][20] + +In the output above, you can note that the path to the project interpreter that we just set, is shown along with the path to the test program file (test.py). An exit code of 0 shows that the program has finished executing successfully without errors. + +So, that’s a ready-to-use IDE environment where you can import the Cirq library to start programming with Python and simulate Quantum circuits. + +#### Get started with Cirq + +A good place to start are the [examples][21] that have been made available on Cirq’s Github page. + +The developers have included this [tutorial][22] on GitHub to get started with learning Cirq. If you are serious about learning Quantum Computing, they recommend an excellent book called [“Quantum Computation and Quantum Information” by Nielsen and Chuang][23]. + +#### OpenFermion-Cirq + +[OpenFermion][24] is an open source library for obtaining and manipulating representations of fermionic systems (including Quantum Chemistry) for simulation on Quantum Computers. Fermionic systems are related to the generation of [fermions][25], which according to [particle physics][26], follow [Fermi-Dirac statistics][27]. + +OpenFermion has been hailed as [a great practice tool][28] for chemists and researchers involved with [Quantum Chemistry][29]. The main focus of Quantum Chemistry is the application of [Quantum Mechanics][30] in physical models and experiments of chemical systems. Quantum Chemistry is also referred to as [Molecular Quantum Mechanics][31]. + +The advent of Cirq has now made it possible for OpenFermion to extend its functionality by providing routines and tools for using Cirq to compile and compose circuits for Quantum simulation algorithms. + +#### Google Bristlecone + +On March 5, 2018, Google presented [Bristlecone][32], their new Quantum processor, at the annual [American Physical Society meeting][33] in Los Angeles. The [gate-based superconducting system][34] provides a test platform for research into [system error rates][35] and [scalability][36] of Google’s [qubit technology][37], along-with applications in Quantum [simulation][38], [optimization][39], and [machine learning.][40] + +In the near future, Google wants to make its 72 qubit Bristlecone Quantum processor [cloud accessible][41]. Bristlecone will gradually become quite capable to perform a task that a Classical Supercomputer would not be able to complete in a reasonable amount of time. + +Cirq would make it easier for researchers to directly write programs for Bristlecone on the cloud, serving as a very convenient interface for real-time Quantum programming and testing. + +Cirq will allow us to: + + * Fine tune control over Quantum circuits, + * Specify [gate][42] behavior using native gates, + * Place gates appropriately on the device & + * Schedule the timing of these gates. + + + +### The Open Science Perspective on Cirq + +As we all know Cirq is Open Source on GitHub, its addition to the Open Source Scientific Communities, especially those which are focused on Quantum Research, can now efficiently collaborate to solve the current challenges in Quantum Computing today by developing new ways to reduce error rates and improve accuracy in the existing Quantum models. + +Had Cirq not followed an Open Source model, things would have definitely been a lot more challenging. A great initiative would have been missed out and we would not have been one step closer in the field of Quantum Computing. + +### Summary + +To summarize in the end, we first introduced you to the concept of Quantum Computing by comparing it to existing Classical Computing techniques followed by a very important video on recent developmental updates in Quantum Computing since last year. We then briefly discussed Noisy Intermediate Scale Quantum, which is what Cirq is specifically built for. + +We saw how we can install and test Cirq on an Ubuntu system. We also tested the installation for usability on an IDE environment with some resources to get started to learn the concept. + +Finally, we also saw two examples of how Cirq would be an essential advantage in the development of research in Quantum Computing, namely OpenFermion and Bristlecone. We concluded the discussion by highlighting some thoughts on Cirq with an Open Science Perspective. + +We hope we were able to introduce you to Quantum Computing with Cirq in an easy to understand manner. If you have any feedback related to the same, please let us know in the comments section. Thank you for reading and we look forward to see you in our next Open Science article. + +-------------------------------------------------------------------------------- + +via: https://itsfoss.com/qunatum-computing-cirq-framework/ + +作者:[Avimanyu Bandyopadhyay][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://itsfoss.com/author/avimanyu/ +[1]:https://en.wikipedia.org/wiki/Subatomic_particle +[2]:https://en.wikipedia.org/wiki/Quantum +[3]:https://www.clerro.com/guide/491/quantum-superposition-and-entanglement-explained +[4]:https://physics.stackexchange.com/questions/148131/can-quantum-entanglement-and-quantum-superposition-be-considered-the-same-phenom +[5]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/08/bit-vs-qubit.jpg +[6]:http://www.rfwireless-world.com/Terminology/Difference-between-Bit-and-Qubit.html +[7]:https://en.wikipedia.org/wiki/Proof_by_exhaustion +[8]:https://www.explainthatstuff.com/how-supercomputers-work.html +[9]:https://arxiv.org/abs/1801.00862 +[10]:https://www.xconomy.com/san-francisco/2018/07/19/google-partners-with-zapata-on-open-source-quantum-computing-effort/ +[11]:https://www.zapatacomputing.com/about/ +[12]:https://github.com/quantumlib/Cirq +[13]:https://itsfoss.com/python-setup-linux/ +[14]:https://virtualenv.pypa.io +[15]:https://cirq.readthedocs.io/en/latest/install.html#installing-on-linux +[16]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/08/cirq-framework-linux.jpeg +[17]:https://pypi.org/project/pip/ +[18]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/08/cirq-test-output.jpg +[19]:https://itsfoss.com/install-pycharm-ubuntu/ +[20]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/08/cirq-tested-on-pycharm.jpg +[21]:https://github.com/quantumlib/Cirq/tree/master/examples +[22]:https://github.com/quantumlib/Cirq/blob/master/docs/tutorial.md +[23]:http://mmrc.amss.cas.cn/tlb/201702/W020170224608149940643.pdf +[24]:http://openfermion.org +[25]:https://en.wikipedia.org/wiki/Fermion +[26]:https://en.wikipedia.org/wiki/Particle_physics +[27]:https://en.wikipedia.org/wiki/Fermi-Dirac_statistics +[28]:https://phys.org/news/2018-03-openfermion-tool-quantum-coding.html +[29]:https://en.wikipedia.org/wiki/Quantum_chemistry +[30]:https://en.wikipedia.org/wiki/Quantum_mechanics +[31]:https://ocw.mit.edu/courses/chemical-engineering/10-675j-computational-quantum-mechanics-of-molecular-and-extended-systems-fall-2004/lecture-notes/ +[32]:https://techcrunch.com/2018/03/05/googles-new-bristlecone-processor-brings-it-one-step-closer-to-quantum-supremacy/ +[33]:http://meetings.aps.org/Meeting/MAR18/Content/3475 +[34]:https://en.wikipedia.org/wiki/Superconducting_quantum_computing +[35]:https://en.wikipedia.org/wiki/Quantum_error_correction +[36]:https://en.wikipedia.org/wiki/Scalability +[37]:https://research.googleblog.com/2015/03/a-step-closer-to-quantum-computation.html +[38]:https://research.googleblog.com/2017/10/announcing-openfermion-open-source.html +[39]:https://research.googleblog.com/2016/06/quantum-annealing-with-digital-twist.html +[40]:https://arxiv.org/abs/1802.06002 +[41]:https://www.computerworld.com.au/article/644051/google-launches-quantum-framework-cirq-plans-bristlecone-cloud-move/ +[42]:https://en.wikipedia.org/wiki/Logic_gate diff --git a/sources/tech/20180828 Linux for Beginners- Moving Things Around.md b/sources/tech/20180828 Linux for Beginners- Moving Things Around.md new file mode 100644 index 0000000000..abefc7c6f5 --- /dev/null +++ b/sources/tech/20180828 Linux for Beginners- Moving Things Around.md @@ -0,0 +1,201 @@ +Linux for Beginners: Moving Things Around +====== + +![](https://www.linux.com/sites/lcom/files/styles/rendered_file/public/filesystem-linux.jpg?itok=NQCoYl1f) + +In previous installments of this series, [you learned about directories][1] and how [permissions to access directories work][2]. Most of what you learned in those articles can be applied to files, except how to make a file executable. + +So let's deal with that before moving on. + +### No _.exe_ Needed + +In other operating systems, the nature of a file is often determined by its extension. If a file has a _.jpg_ extension, the OS guesses it is an image; if it ends in _.wav_ , it is an audio file; and if it has an _.exe_ tacked onto the end of the file name, it is a program you can execute. + +This leads to serious problems, like trojans posing as documents. Fortunately, that is not how things work in Linux. Sure, you may see occasional executable file endings in _.sh_ that indicate they are runnable shell scripts, but this is mostly for the benefit of humans eyeballing files, the same way when you use `ls --color`, the names of executable files show up in bright green. + +The fact is most applications have no extension at all. What determines whether a file is really program is the _x_ (for _executable_ ) bit. You can make any file executable by running +``` +chmod a+x some_program + +``` + +regardless of its extension or lack thereof. The `x` in the command above sets the _x_ bit and the `a` says you are setting it for _all_ users. You could also set it only for the group of users that own the file (`g+x`), or for only one user, the owner (`u+x`). + +Although we will be covering creating and running scripts from the command line later in this series, know that you can run a program by writing the path to it and then tacking on the name of the program on the end: +``` +path/to/directory/some_program + +``` + +Or, if you are currently in the same directory, you can use: +``` +./some_program + +``` + +There are other ways of making your program available from anywhere in the directory tree (hint: look up the `$PATH` environment variable), but you will be reading about those when we talk about shell scripting. + +### Copying, Moving, Linking + +Obviously, there are more ways of modifying and handling files from the command line than just playing around with their permissions. Most applications will create a new file if you still try to open a file that doesn't exist. Both +``` +nano test.txt + +``` + +and +``` +vim test.txt + +``` + +([nano][3] and [vim][4] being to popular command line text editors) will create an empty _test.txt_ file for you to edit if _test.txt_ didn't exist beforehand. + +You can also create an empty file by _touching_ it: +``` +touch test.txt + +``` + +Will create a file, but not open it in any application. + +You can use `cp` to make a copy of a file in another location or under a new name: +``` +cp test.txt copy_of_test.txt + +``` + +You can also copy a whole bunch of files: +``` +cp *.png /home/images + +``` + +The instruction above copies all the PNG files in the current directory into an _images/_ directory hanging off of your home directory. The _images/_ directory has to exist before you try this, or `cp` will show an error. Also, be warned that, if you copy a file to a directory that contains another file with the same name, `cp` will silently overwrite the old file with the new one. + +You can use +``` +cp -i *.png /home/images + +``` + +If you want `cp` to warn you of any dangers (the `-i` options stands for _interactive_ ). + +You can also copy whole directories, but you need the `-r` option for that: +``` +cp -rv directory_a/ directory_b + +``` + +The `-r` option stands for _recursive_ , meaning that `cp` will drill down into _directory_a_ , copying over all the files and subdirectories contained within. I personally like to include the `-v` option, as it makes `cp` _verbose_ , meaning that it will show you what it is doing instead of just copying silently and then exiting. + +The `mv` command moves stuff. That is, it changes files from one location to another. In its simplest form, `mv` looks a lot like `cp`: +``` +mv test.txt new_test.txt + +``` + +The command above makes _new_test.txt_ appear and _test.txt_ disappear. +``` +mv *.png /home/images + +``` + +Moves all the PNG files in the current directory to a directory called _images/_ hanging of your home directory. Again you have to be careful you do not overwrite existing files by accident. Use +``` +mv -i *.png /home/images + +``` + +the same way you would with `cp` if you want to be on the safe side. + +Apart from moving versus copying, another difference between `mv` and `cp`is when you move a directory: +``` +mv directory_a/ directory_b + +``` + +No need for a recursive flag here. This is because what you are really doing is renaming the directory, the same way in the first example, you were renaming the file*. In fact, even when you "move" a file from one directory to another, as long as both directories are on the same storage device and partition, you are renaming the file. + +You can do an experiment to prove it. `time` is a tool that lets you measure how long a command takes to execute. Look for a hefty file, something that weighs several hundred MBs or even some GBs (say, something like a long video) and try copying it from one directory to another like this: +``` +$ time cp hefty_file.mkv another_directory/ +real 0m3,868s +user 0m0,016s +sys 0m0,887s + +``` + +In bold is what you have to type into the terminal and below what `time` outputs. The number to focus on is the one on the first line, _real_ time. It takes nearly 4 seconds to copy the 355 MBs of _hefty_file.mkv_ to _another_directory/_. + +Now let's try moving it: +``` +$ time mv hefty_file.mkv another_directory/ +real 0m0,004s +user 0m0,000s +sys 0m0,003s + +``` + +Moving is nearly instantaneous! This is counterintuitive, since it would seem that `mv` would have to copy the file and then delete the original. That is two things `mv` has to do versus `cp`'s one. But, somehow, `mv` is 1000 times faster. + +That is because the file system's structure, with all its tree of directories, only exists for the users convenience. At the beginning of each partition there is something called a _partition table_ that tells the operating system where to find each file on the actual physical disk. On the disk, data is not split up into directories or even files. [There are tracks, sectors and clusters instead][5]. When you "move" a file within the same partition, what the operating system does is just change the entry for that file in the partition table, but it still points to the same cluster of information on the disk. + +Yes! Moving is a lie! At least within the same partition that is. If you try and move a file to a different partition or a different device, `mv` is still fast, but is noticeably slower than moving stuff around within the same partition. That is because this time there is actually copying and erasing of data going on. + +### Renaming + +There are several distinct command line `rename` utilities around. None are fixtures like `cp` or `mv` and they can work in slightly different ways. What they all have in common is that they are used to change _parts_ of the names of files. + +In Debian and Ubuntu, the default `rename` utility uses [regular expressions][6] (patterns of strings of characters) to mass change files in a directory. The instruction: +``` +rename 's/\.JPEG$/.jpg/' * + +``` + +will change all the extensions of files with the extension _JPEG_ to _jpg_. The file _IMG001.JPEG_ becomes _IMG001.jpg_ , _my_pic.JPEG_ becomes _my_pic.jpg_ , and so on. + +Another version of `rename` available by default in Manjaro, a derivative of Arch, is much simpler, but arguably less powerful: +``` +rename .JPEG .jpg * + +``` + +This does the same renaming as you saw above. In this version, `.JPEG` is the string of characters you want to change, `.jpg` is what you want to change it to, and `*` represents all the files in the current directory. + +The bottom line is that you are better off using `mv` if all you want to do is rename one file or directory, and that's because `mv` is realiably the same in all distributions everywhere. + +### Learning more + +Check out the both `mv` and `cp`'s _man_ pages to learn more. Run +``` +man cp + +``` + +or +``` +man mv + +``` + +to read about all the options these commands come with and which make them more powerful and safer to use. + +-------------------------------------------------------------------------------- + +via: https://www.linux.com/blog/2018/8/linux-beginners-moving-things-around + +作者:[Paul Brown][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://www.linux.com/users/bro66 +[1]: https://www.linux.com/blog/learn/2018/5/manipulating-directories-linux +[2]: https://www.linux.com/blog/learn/intro-to-linux/2018/7/users-groups-and-other-linux-beasts-part-2 +[3]: https://www.nano-editor.org/ +[4]: https://www.vim.org/ +[5]: https://en.wikipedia.org/wiki/Disk_sector +[6]: https://en.wikipedia.org/wiki/Regular_expression diff --git a/sources/tech/20180828 Orion Is A QML - C-- Twitch Desktop Client With VODs And Chat Support.md b/sources/tech/20180828 Orion Is A QML - C-- Twitch Desktop Client With VODs And Chat Support.md new file mode 100644 index 0000000000..c87ec64e73 --- /dev/null +++ b/sources/tech/20180828 Orion Is A QML - C-- Twitch Desktop Client With VODs And Chat Support.md @@ -0,0 +1,126 @@ +Orion Is A QML / C++ Twitch Desktop Client With VODs And Chat Support +====== +**[Orion][1] is a free and open source QML / C++ client for [Twitch.tv][2] which can use multiple player backends (including [mpv][3]). The application runs on Linux, Windows, macOS and Android.** + +Using Orion you can watch live Twitch streams and past broadcasts, and browse or search games and channels using a nice material user interface. What's more, Orion lets you login to Twitch, so you can chat and follow channels (and receive notifications when a channel you follow goes online). + +The application allows customizing various aspects, like changing the stream quality, switching between light and dark user interface themes, and changing the chat position and font size. + +![](https://3.bp.blogspot.com/-mRODHpN_DOs/W4VLENlBAEI/AAAAAAAABdI/eLrcj_93aEgvoH2urX6CzIeEW_44MoprwCLcBGAs/s640/orion-twitch-client.png) + +**Main Orion Twitch client features:** + + * **Play live Twitch streams or past VODs using one of 3 backends: mpv, QtAV or Qt5 Multimedia (mpv is default)** + * **Browse and search Twitch games and channels** + * **Login using your Twitch credentials** + * **Desktop notifications when a followed channel comes online (including an option to show offline notifications)** + * **Chat support** + * **Light and Dark themes with configurable font** + * **Change chat position (right, left or bottom)** + * **Options to start minimized, close to tray and keep on top** + + + +Here's how Orion works. When you go to the channels list, you'll notice that each channel uses its icon as a thumbnail, with the channel name in an overlay on top of the icon: + +![](https://2.bp.blogspot.com/-gMn58o2ICnU/W4VDod1B7HI/AAAAAAAABco/00PNn2dwq6oHwY9DS2lZdhOXlFMsS0umwCLcBGAs/s640/orion-channel-list_1.png) + +I would have liked to see the stream title, number of current viewers, and a preview in the channel list, or have an option for this. These are available, but not directly in the channel list. You can see a channel preview on mouse over, while the stream title and viewer count are available after you click on a channel: + +![](https://4.bp.blogspot.com/-Cpb8STUIeHc/W4VDtfPQS6I/AAAAAAAABcs/2j-dxwMgChUqzxi5PiZFqn1942SkdsHmQCLcBGAs/s640/orion-overlay-channel-info_2.png) + +From this bottom overlay (which is displayed after you click on a channel) you can start playing the stream, follow or unfollow the channel, open the chat without watching the stream, or access past videos. You can also right click a channel to access these options. + +In the player view you'll find the regular video player controls, along with the quality selector (with source as the default quality) at the bottom, while the top overlay lets you follow / unfollow a channel or toggle the chat, which is displayed on the right-hand side of the screen by default: + +![](https://3.bp.blogspot.com/-2I3B8fT_BkA/W4VLfmzWiCI/AAAAAAAABdQ/xS8Vbs2XLiwizo7IrFeBqnW5bCmoJTKWACLcBGAs/s640/orion-twitch-player-overlays.png) + +The chat panel uses autohide by default, but you can force it to always be displayed by clicking the lock icon its upper left corner. When the chat is locked (set to always visible), the video is shifted to the left so the chat isn't displayed on top of the video, and the chat width is resizable. + +### Download Orion + +[Download Orion(binaries for Windows or macOS)][13] + +The Orion GitHub project page doesn't offer any Linux binaries for download, but there are packages out there for multiple Linux distributions: + + * **Arch Linux** AUR packages for the latest Orion [stable][4] or [Git][5]. + * **Ubuntu 18.04 / Linux Mint 19** : [here's][6] the latest Orion Twitch client as a DEB package (if you want to add the PPA you can find it [here][7]). There's [another][8] PPA which has the latest Orion for Ubuntu 18.04 and an older Orion version for Ubuntu 16.04 - I only tried the Ubuntu 18.04 package from this second PPA but the Orion window is very small upon launching the application, that's why I prefer the first package. + * **Fedora 29, 28 and 27** have Orion in its [repositories][9]. + * **openSUSE Tumbleweed and Leap 15.0** have Orion in the official [repositories][10]. + + + +In case you're using a different Linux distribution, you'll need to search for Orion packages for yourself or build it from + +**If you prefer to build Orion from source on Debian/Ubuntu-based Linux distributions** (with mpv as the backend), **here's how to compile it. Orion requires Qt 5.8 or newer!** That means you'll need Ubuntu 18.04 / Linux Mint 19 to build it, or if you want to compile it in an older Ubuntu version, you'll need to install a newer Qt version from a PPA, etc. + +1\. Install the required dependencies on your Debian/Ubuntu-based Linux distribution: +``` +sudo apt install qt5-default qtdeclarative5-dev qtquickcontrols2-5-dev libqt5svg5-dev libmpv-dev mesa-common-dev libgl1-mesa-dev libpulse-dev + +``` + +2\. Download (using wget), build and install Orion: +``` +cd && wget https://github.com/alamminsalo/orion/archive/1.6.5.tar.gz +tar -xvf 1.6.5.tar.gz +cd orion-1.6.5 +mkdir build && cd build +qmake ../ +make && sudo make install + +``` + +If you want to build a different Orion version, make sure you adjust the first 3 commands with the exact file/version name. + + +### Fixing the default Orion theme when using QT_STYLE_OVERRIDE (not required in most cases) + +I use `QT_STYLE_OVERRIDE` . Due to this, Orion does not use its default theme which causes some fonts to be invisible or hard to read. + +This is how Orion looks when used with Kvantum set as the `QT_STYLE_OVERRIDE` : + +![](https://4.bp.blogspot.com/-NbjalKcD4jw/W4VFngEYOtI/AAAAAAAABc8/4Q85I0mNamw2U7CL58dueFt7BS8oPZ4VwCLcBGAs/s640/orion-theme-issues.png) + +If you're in the same situation, you can fix the Orion theme by launching the application like this: +``` +QT_STYLE_OVERRIDE= orion + +``` + +To change the Orion desktop file to include this so you can launch Orion from your menu and have it use the correct theme, copy the Orion desktop file from `/usr/share/applications/` to `~/.local/share/applications/` , edit it in this second location and change `Exec=orion` to `Exec=env QT_STYLE_OVERRIDE= orion` + +You can do all of this from a terminal using these commands: +``` +cp /usr/share/applications/Orion.desktop ~/.local/share/applications/ + +sed -i 's/Exec=orion/Exec=env QT_STYLE_OVERRIDE= orion/' ~/.local/share/applications/Orion.desktop + +``` + + +-------------------------------------------------------------------------------- + +via: https://www.linuxuprising.com/2018/08/orion-is-qml-c-twitch-desktop-client.html + +作者:[Logix][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://plus.google.com/118280394805678839070 +[1]: https://alamminsalo.github.io/orion/ +[2]: https://www.twitch.tv/ +[3]: https://mpv.io/ +[4]: https://aur.archlinux.org/packages/orion/ +[5]: https://aur.archlinux.org/packages/orion-git/ +[6]: http://ppa.launchpad.net/mortigar/orion/ubuntu/pool/main/o/orion/ +[7]: https://launchpad.net/~mortigar/+archive/ubuntu/orion +[8]: https://launchpad.net/~rakslice/+archive/ubuntu/orion +[9]: https://apps.fedoraproject.org/packages/orion +[10]: https://software.opensuse.org/package/orion +[11]: https://github.com/alamminsalo/orion#building-on-linux +[12]: https://www.linuxuprising.com/2018/05/use-custom-themes-for-qt-applications.html +[13]: https://github.com/alamminsalo/orion/releases diff --git a/sources/tech/20180829 4 open source monitoring tools.md b/sources/tech/20180829 4 open source monitoring tools.md new file mode 100644 index 0000000000..a5b8bf6806 --- /dev/null +++ b/sources/tech/20180829 4 open source monitoring tools.md @@ -0,0 +1,143 @@ +4 open source monitoring tools +====== + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/mistake_bug_fix_find_error.png?itok=PZaz3dga) + +Isn’t monitoring just monitoring? Doesn’t it include logging, visualization, and time-series data? + +The terminology around monitoring has caused a lot of confusion over the years and has led to some poor tools that tout the ability to do everything in one format. Observability proponents recognize there are many levels for observing a system. Metrics aggregation is primarily time-series data, and that’s what we’ll discuss in this article. + +### Features of time-series data + +#### Counters + +A counter is a metric that represents a numeric value that will only increase. (In other words, a counter should never decrease.) Counters accumulate values and present the current total when requested. These are commonly used for things like the total number of web requests, number of errors, number of visitors, etc. This is analogous to the person with a counter device standing at the entrance to an event counting all the people entering. There is generally no option to decrement the counter without resetting it. + +#### Gauges + +A gauge is similar to a counter in that it represents a single numeric value, but it can also decrease. It is essentially a representation of some value at a point in time. A thermometer is a good example of a gauge: It moves up and down with the temperature and offers a point-in-time reading. Other uses include CPU usage, memory usage, network usage, and number of threads. + +#### Quantiles + +Quantiles aren’t a type of metric, but they’re germane to the next two sections: histograms and summaries. Let’s clarify our understanding of quantiles with an example: + +A percentile is a type of quantile. Percentiles are something we see regularly, and they should help us understand the general concept more easily. A percentile has 100 “buckets” of values. We often see them related to testing or performance and generally stated as someone scoring, for example, within the 85th percentile or some other value. This means the person scoring within that percentile had a real value that fell within the bucket between the 85th and 86th percentile. This person also scored in the top 15% of all students. We don’t know the scores in the bucket based off this metric, but that can be derived based on the sum of all scores in the bucket divided by the count of those scores. + +Quantiles allow us to understand our data better than using a mean or some other statistical function that doesn’t take into account outliers and uneven distributions. + +#### Histograms + +A histogram is a little more complicated than a counter or a gauge. It is a sample of observations. It consists of a counter, which counts all the observations, and what is essentially a gauge that sums the values of the observations. It uses “buckets” or groupings to segment the values in order to bound the datasets in a productive way. This is commonly seen with quantiles related to request service-level agreements (SLAs). Let’s say we want to ensure that 95% of our requests are below 500ms. We could use a bucket with an upper bound of 0.5s to collect all values that fall under 500ms. We would then be able to determine how many of the total requests have fallen into that bucket. We can also determine how far we are from our SLA, but this can be difficult to do (as is explained more in the [Prometheus documentation][1]). + +Histograms are aggregate metrics that are accumulated from multiple instances into a central server. This provides an opportunity to understand the system as a whole rather than on a node-by-node basis. + +#### Summaries + +Summaries are similar to histograms in that they are a sample of observations, but the aggregation occurs on the server side. Also, the estimate of the quantile is more accurate than in a histogram. A summary uses a sliding time window, so it serves a slightly different case than a histogram but is generally used for the same types of metrics. I normally use a histogram unless I need a very accurate measure of the quantile. + +### Push/pull + +No article can be written about metrics aggregation tools without addressing the push vs. pull debate. + +The debate centers around whether it is better for your metrics aggregation system to have data pushed to it or to have your metrics aggregation system reach out and gather the data by scraping an endpoint. Multiple articles discuss this (like [this one][2] and [this one][3]). My perspective is that it mostly doesn’t matter. Additional research is left to the reader’s discretion. + +### Tool options + +There are many tools available, both open source and commercial. We will focus on open source tools, but some of these have an open core model with a paid component. + +Some of these tools feature additional components of observability—principally alerting and visualizations. These will be covered in this section as additional features and won’t be covered in subsequent articles. + +#### Prometheus + +This is the most well-recognized time-series monitoring solution for cloud-native applications. It is hosted within the [Cloud Native Computing Foundation][4] (CNCF), but it was created by Matt Proud and Julius Volz and sponsored by [SoundCloud][5], with external contributors coming in early to help develop it. Brian Brazil of [Robust Perception][6] has built a business of helping companies adopt Prometheus. He also has an excellent [blog][7] on his website. The [Prometheus documentation][8] is extensive and provides a lot of detail for understanding and using the tool. + +[Prometheus][9] is a pull-based system that uses local configuration to describe the endpoints to collect from and the interval desired for collection. Each endpoint has a client collecting the data and updating that representation upon each request (or however the client is configured). This data is collected and saved in a highly efficient storage engine on local disk. The storage system uses an append-only file per metric. This storage isn’t lossy, which means the fidelity of data from a year ago is as high as the data you are collecting today. However, you may not want to keep that much data locally. Fortunately, there is an option for remote storage for long-term retention and analysis. + +Prometheus includes an advanced expression language for selecting and presenting data called [PromQL][10]. This data can be displayed graphically, tabularly, or used by external systems through a REST API. The expression language allows a user to create regressions, analyze real-time data, or trend historical data. Labels are also a great tool for filtering and querying data. Labels can be associated with each metric name. + +Prometheus also offers a federation model, which encourages more localized control by allowing teams to have their own [Prometheis][11] while central teams can also have their own. The central systems could scrape the same endpoints as the local Prometheis, but they can also scrape the local Prometheis to get the aggregated data that the local instances are collecting. This reduces overhead on the endpoints. This federation model also allows local instances to collect data from each other. + +Prometheus comes with [AlertManager][12] to handle alerts. This system allows for aggregation of alerts as well as more complex flows to limit when an alert is sent. + +Let’s say 10 nodes suddenly go down at the same time a switch goes down. You probably don’t need to send an alert about the 10 nodes, as everyone who receives them will likely be unable to do anything until the switch is fixed. With the AlertManager, it’s possible to send an alert only to the networking team for the switch and include additional information about other systems that might be affected. It’s also possible to send an email (rather than a page) to the systems team so they know those nodes are down and they don’t need to respond unless the systems don’t come up after the switch is repaired. If that occurs, then AlertManager will reactivate those alerts that were suppressed by the switch alert. + +#### Graphite + +[Graphite][13] has been around for a long time, and James Turnbull's recent book [_The Art of Monitoring_][14] covers Graphite in detail. Graphite has become ubiquitous in the industry, with many large companies using it at scale. + +Graphite is a push-based system that receives data from applications by having the application push the data into Graphite’s Carbon component. Carbon stores this data in the Whisper database, and that database and Carbon are read by the Graphite web component that allows a user to graph their data in a browser or pull it through an API. A really cool feature is the ability to export these graphs as images or data files to easily embed them in other applications. + +Whisper is a fixed-size database that provides fast, reliable storage of numeric data over time. It is a lossy database, which means the resolution of your metrics will degrade over time. It will provide high-fidelity metrics for the most recent collections and gradually reduce that fidelity over time. + +Graphite also uses dot-separated naming, which implies dimensionality. This dimensionality allows for some creative aggregation of metrics and relationships between metrics. This enables aggregation of services across different versions or data centers and (getting more specific) a single version running in one data center in a specific Kubernetes cluster. Granular-level comparisons can also be made to determine if a particular cluster is underperforming. + +Another interesting feature of Graphite is the ability to store arbitrary events that should be related to time-series metrics. In particular, application or infrastructure deployments can be added and tracked within Graphite. This allows the operator or developer troubleshooting an issue to have more context about what has happened in the environment related to the anomalous behavior being investigated. + +Graphite also has a substantial [list of functions][15] that can be applied to metrics series. However, it lacks a powerful query language, which some other tools include. It also lacks any alerting functionality or built-in alerting system. + +#### InfluxDB + +[InfluxDB][16] is a relatively new entrant, newer than Prometheus. It uses an open core model, which means scaling and clustering cost extra. InfluxDB is part of the larger [TICK stack][17] (of Telegraf, InfluxDB, Chronograf, and Kapacitor), so we will include all those components’ features in this analysis. + +InfluxDB uses a key-value pair system called tags to add dimensionality to metrics, similar to Prometheus and Graphite. The results are similar to what we discussed previously for the other systems. The metric data can be of type **float64** , **int64** , **bool** , and **string** with nanosecond resolution. This is a broader range than most other tools in this space. In fact, the TICK stack is more of an event-aggregation platform than a native time-series metrics-aggregation system. + +InfluxDB uses a system similar to a log-structured merge tree for storage. It is called a time-structured merge tree in this context. It uses a write-ahead log and a collection of read-only data files, which are similar to Sorted Strings Tables but have series data rather than pure log data. These files are sharded per block of time. To learn more, check out [this great resource][18] on the InfluxData website. + +The architecture of the TICK stack is different depending on if it’s the open source or commercial version. The open source InfluxDB system is self-contained within a single host, while the commercial version is inherently distributed. This is true of the other central components as well. In the open source version, everything runs on a single host. No data or configuration is stored on external systems, so it is fairly easy to manage, but it isn’t as robust as the commercial version. + +InfluxDB includes a SQL-like language called InfluxQL for querying data from the databases. The primary means for querying data is the HTTP API. The query language doesn’t have as many built-in helper functions as Prometheus, but those familiar with SQL will likely feel more comfortable with the language. + +The TICK stack also includes an alerting system. This system can do some mild aggregation but doesn’t have the full capabilities of Prometheus’ AlertManager. It does offer many integrations, though. Also, to reduce load on InfluxDB, continuous queries can be scheduled to store results of queries that Kapacitor will pick up for alerting. + +#### OpenTSDB + +[OpenTSDB][19] is an open source time-series database, as its name implies. It’s unique in this collection of tools in that it stores its metrics in Hadoop. This means it is inherently scalable. If you already have a Hadoop cluster, this might be a good option for metrics you want to store over the long term. If you don’t have a Hadoop cluster, the operational overhead might be too large of a burden for you to bear. However, OpenTSDB now supports Google’s [Bigtable][20] as a backend, which is a cloud service you don’t have to operate. + +OpenTSDB shares a lot of features with the other systems. It uses a key-value pairing system it calls tags for identifying metrics and adding dimensionality. It has a query language, but it is more limited than Prometheus’ PromQL. It does, however, have several built-in functions that help with learning and usage. The API is the main entry point for querying, similar to InfluxDB. This system also stores all data forever, unless there’s a time-to-live set in HBase, so you don't have to worry about fidelity degradation. + +OpenTSDB doesn’t offer an alerting capability, which will make it harder to integrate with your incident response process. This type of system might be great for long-term Prometheus data storage and for performing more historical analytics to reveal systemic issues, rather than as a tool to quickly identify and respond to acute concerns. + +### OpenMetrics standard + +[OpenMetrics][21] is a working group seeking to establish a standard exposition format for metrics data. It is influenced by Prometheus. If this initiative is successful, we’ll have an industry-wide abstraction that would allow us to switch between tools and providers with ease. Leading companies like [Datadog][22] have already started offering tools that can consume the Prometheus exposition format, which will be easy to convert to the OpenMetrics standard once it’s released. + +It’s also important to note that the contributors to this project include Google and InfluxData (among others). This likely means InfluxDB will eventually adopt the OpenMetrics standard. This may also mean that one of the three largest cloud providers will adopt it if Google’s involvement is an indicator. Of course, the exposition format is already being used in the Google-created [Kubernetes][23] project. [SolarWinds][24], [Robust Perception][6], and [SpaceNet][25] are also involved. + + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/8/open-source-monitoring-tools + +作者:[Dan barker][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://opensource.com/users/barkerd427 +[1]: https://prometheus.io/docs/practices/histograms/ +[2]: https://thenewstack.io/exploring-prometheus-use-cases-brian-brazil/ +[3]: https://prometheus.io/blog/2016/07/23/pull-does-not-scale-or-does-it/ +[4]: https://www.cncf.io/ +[5]: https://soundcloud.com/ +[6]: https://www.robustperception.io/ +[7]: https://www.robustperception.io/blog/ +[8]: https://prometheus.io/docs/ +[9]: https://prometheus.io/ +[10]: https://prometheus.io/docs/prometheus/latest/querying/basics/ +[11]: https://prometheus.io/docs/introduction/faq/#what-is-the-plural-of-prometheus +[12]: https://prometheus.io/docs/alerting/alertmanager/ +[13]: https://graphiteapp.org/ +[14]: https://www.artofmonitoring.com/ +[15]: http://graphite.readthedocs.io/en/latest/functions.html +[16]: https://www.influxdata.com/ +[17]: https://www.thoughtworks.com/radar/platforms/tick-stack +[18]: https://docs.influxdata.com/influxdb/v1.5/concepts/storage_engine/ +[19]: http://opentsdb.net/ +[20]: https://cloud.google.com/bigtable/ +[21]: https://github.com/RichiH/OpenMetrics +[22]: https://www.datadoghq.com/blog/monitor-prometheus-metrics/ +[23]: https://opensource.com/resources/what-is-kubernetes +[24]: https://www.solarwinds.com/ +[25]: https://spacenetchallenge.github.io/ diff --git a/sources/tech/20180829 Containers in Perl 6.md b/sources/tech/20180829 Containers in Perl 6.md new file mode 100644 index 0000000000..93c51c201f --- /dev/null +++ b/sources/tech/20180829 Containers in Perl 6.md @@ -0,0 +1,174 @@ +Containers in Perl 6 +====== + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/data_container_block.png?itok=S8MbXEYw) + +In the [first article][1] in this series comparing Perl 5 to Perl 6, we looked into some of the issues you might encounter when migrating code into Perl 6. In the [second article][2], we examined how garbage collection works in Perl 6. Here, in the third article, we'll focus on Perl 5's references and how they're handled in Perl 6, and introduce the concepts of binding and containers. + +### References + +There are no references in Perl 6, which is surprising to many people used to Perl 5's semantics. But worry not: because there are no references, you don't have to worry about whether something should be de-referenced or not. +``` +# Perl 5 +my $foo = \@bar;   # must add reference \ to make $foo a reference to @bar +say @bar[1];       # no dereference needed +say $foo->[1];     # must add dereference -> + +# Perl 6 +my $foo = @bar;    # $foo now contains @bar +say @bar[1];       # no dereference needed, note: sigil does not change +say $foo[1];       # no dereference needed either +``` + +One could argue that everything in Perl 6 is a reference. Coming from Perl 5 (where an object is a blessed reference), this would be a logical conclusion about Perl 6 where everything is an object (or can be considered one). But that wouldn't do justice to the situation in Perl 6 and would hinder you in understanding how things work in Perl 6. Beware of [false friends][3]! + +### Binding + +Before we get to assignment, it is important to understand the concept of binding in Perl 6. You can bind something explicitly to something else using the `:=` operator. When you define a lexical variable, you can bind a value to it: +``` +my $foo := 42;  # note: := instead of = +``` + +Simply put, this creates a key with the name "`$foo`" in the lexical pad (lexpad) (which you could consider a compile-time hash that contains information about things that are visible in that lexical scope) and makes `42` its literal value. Because this is a literal constant, you can't change it. Trying to do so will cause an exception. So don't do that! + +This binding operation is used under the hood in many situations, for instance when iterating: +``` +my @a = 0..9;    # can also be written as ^10 +say @a;          # [0 1 2 3 4 5 6 7 8 9] +for @a { $_++ }  # $_ is bound to each array element and incremented +say @a;          # [1 2 3 4 5 6 7 8 9 10] +``` + +If you try to iterate over a constant list, then `$_` is bound to the literal values, which you can not increment: +``` +for 0..9 { $_++ }  # error: requires mutable arguments +``` + +### Assignment + +If you compare "create a lexical variable and assign to it" in Perl 5 and Perl 6, it looks the same on the outside: +``` +my $bar = 56;  # both Perl 5 and Perl 6 +``` + +In Perl 6, this also creates a key with the name "`$bar`" in the lexpad. But instead of directly binding the value to that lexpad entry, a container (a `Scalar` object) is created for you and that is bound to the lexpad entry of "`$bar`". Then, `56` is stored as the value in that container. In pseudo-code, you can think of this as: +``` +my $bar := Scalar.new( value => 56 ); +``` + +Notice that the `Scalar` object is bound, not assigned. The closest thing to this in Perl 5 is a [tied scalar][4]. But of course "`= 56`" is much less to type! + +Data structures such as `Array` and `Hash` also automatically put values in containers bound to the structure. +``` +my @a;       # empty Array +@a[5] = 42;  # bind a Scalar container to 6th element and put 42 in it +``` + +### Containers + +The `Scalar` container object is invisible for most operations in Perl 6, so most of the time you don't have to think about it. For instance, whenever you call a subroutine (or a method) with a variable as an argument, it will bind to the value in the container. And because you cannot assign to a value, you get: +``` +sub frobnicate($this) { +    $this = 42; +} +my $foo = 666; +frobnicate($foo); # Cannot assign to a readonly variable or a value +``` + +If you want to allow assigning to the outer value, you can add the `is rw` trait to the variable in the signature. This will bind the variable in the signature to the container of the variable specified, thus allowing assignment: +``` +sub oknicate($this is rw) { +    $this = 42; +} +my $foo = 666; +oknicate($foo); # no problem +say $foo;       # 42 +``` + +### Proxy + +Conceptually, the `Scalar` object in Perl 6 has a `FETCH` method (for producing the value in the object) and a `STORE` method (for changing the value in the object), just like a tied scalar in Perl 5. + +Suppose you later assign the value `768` to the `$bar` variable: +``` +$bar = 768; +``` + +What happens is conceptually the equivalent of: +``` +$bar.STORE(768); +``` + +Suppose you want to add `20` to the value in `$bar`: +``` +$bar = $bar + 20; +``` + +What happens conceptually is: +``` +$bar.STORE( $bar.FETCH + 20 ); +``` + +If you like to specify your own `FETCH` and `STORE` methods on a container, you can do that by binding to a [Proxy][5] object. For example, to create a variable that will always report twice the value that was assigned to it: +``` +my $double := do {  # $double now a Proxy, rather than a Scalar container +    my $value; +    Proxy.new( +      FETCH => method ()     { $value + $value }, +      STORE => method ($new) { $value = $new } +    ) +} +``` + +Note that you will need an extra variable to keep the value stored in such a container. + +### Constraints and default + +Apart from the value, a [Scalar][6] also contains extra information such as the type constraint and default value. Take this definition: +``` +my Int $baz is default(42) = 666; +``` + +It creates a Scalar bound with the name "`$baz`" to the lexpad, constrains the values in that container to types that successfully smartmatch with `Int`, sets the default value of the container to `42`, and puts the value `666` in the container. + +Assigning a string to that variable will fail because of the type constraint: +``` +$baz = "foo"; +# Type check failed in assignment to $baz; expected Int but got Str ("foo") +``` + +If you do not give a type constraint when you define a variable, then the `Any` type will be assumed. If you do not specify a default value, then the type constraint will be assumed. + +Assigning `Nil` (the Perl 6 equivalent of Perl 5's `undef`) to that variable will reset it to the default value: +``` +say $baz;   # 666 +$baz = Nil; +say $baz;   # 42 +``` + +### Summary + + +Perl 5 has values and references to values. Perl 6 has no references, but it has values and containers. There are two types of containers in Perl 6: [Proxy][5] (which is much like a tied scalar in Perl 5) and [Scalar][6] . Simply stated, a variable, as well as an element of a [List][7] [Array][8] , or [Hash][9] , is either a value (if it is bound), or a container (if it is assigned). Whenever a subroutine (or method) is called, the given arguments are de-containerized and bound to the parameters of the subroutine (unless told to do otherwise). A container also keeps information such as type constraints and a default value. Assigningto a variable will return it to its default value, which isif you do not specify a type constraint. + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/8/containers-perl-6 + +作者:[Elizabeth Mattijsen][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://opensource.com/users/lizmat +[1]: https://opensource.com/article/18/7/migrating-perl-5-perl-6 +[2]: https://opensource.com/article/18/7/garbage-collection-perl-6 +[3]: https://en.wikipedia.org/wiki/False_friend +[4]: https://metacpan.org/pod/distribution/perl/pod/perltie.pod#Tying-Scalars +[5]: https://docs.perl6.org/type/Proxy +[6]: https://docs.perl6.org/type/Scalar +[7]: https://docs.perl6.org/type/List +[8]: https://docs.perl6.org/type/Array +[9]: https://docs.perl6.org/type/Hash diff --git a/sources/tech/20180830 6 places to host your git repository.md b/sources/tech/20180830 6 places to host your git repository.md new file mode 100644 index 0000000000..671b120a39 --- /dev/null +++ b/sources/tech/20180830 6 places to host your git repository.md @@ -0,0 +1,57 @@ +6 places to host your git repository +====== + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/house_home_colors_live_building.jpg?itok=HLpsIfIL) + +Perhaps you're one of the few people who didn't notice, but a few months back, [Microsoft bought GitHub][1]. Nothing against either company. Microsoft has become a vocal supporter of open source in recent years, and GitHub has been the de facto code repository for a heaping large number of open source projects almost since its inception. + +However, the recent(-ish) purchase may have gotten you a little itchy. After all, there's nothing quite like a corporate buy-out to make you realize you've had your open source code sitting on a commercial platform. Maybe you're not quite ready to jump ship just yet, but it would at least be helpful to know your options. Let's have a look around the web and see what's available. + +### Option 1: GitHub + +Seriously, this is a valid option. [GitHub][2] doesn't have a history of acting in bad faith, and Microsoft certainly has been smiling on open source of late. There's nothing wrong with keeping your project on GitHub and taking a wait-and-see perspective. It's still the largest community website for software development, and it still has some of the best tools for issue tracking, code review, continuous integration, and general code management. And its underpinnings are still on Git, everyone's favorite open source distributed version control system. Your code is still your code. There's nothing wrong with leaving things where they are if nothing is broken. + +### Option 2: GitLab + +[GitLab][3] is probably the leading contender when it comes to alternative code platforms. It's fully open source. You can host your code right on GitLab's site much like you would on GitHub, but you can also choose to self-host a GitLab instance of your own on your own server and have full control over who has access to everything there and how things are managed. GitLab pretty much has feature parity with GitHub, and some folks might even say its continuous integration and testing tools are superior. Although the community of developers on GitLab is certainly smaller than the one on GitHub, it's still nothing to sneeze at. And it's possible that you'll find more like-minded developers among the population there. + +### Option 3: Bitbucket + +[Bitbucket][4] has been around for many years. In some ways, it could serve as a looking glass into the future of GitHub. Bitbucket was acquired by a larger corporation (Atlassian) eight years ago and has already been through some of that change-over process. It's still a commercial platform like GitHub, but it's far from being a startup, and it's on pretty stable footing, organizationally speaking. Bitbucket shares most of the features available on GitHub and GitLab, plus a few novel features of its own, like native support for [Mercurial][5] repositories. + +### Option 4: SourceForge + +The granddaddy of open source code repository sites is [SourceForge][6]. It used to be that if you had an open source project, SourceForge was the place to host your code and share your releases. It took a little while to migrate to Git for version control, and it had its own rash of commercial acquiring and re-acquiring events, coupled with a few unfortunate bundling decisions for a few open source projects. That said, SourceForge seems to have recovered since then, and the site is still a place where quite a few open source projects live. A lot of folks still feel a bit burned, though, and some people aren't huge fans of its various attempts to monetize the platform, so be sure you go in with open eyes. + +### Option 5: Roll your own + +If you want full control of your project's destiny (and no one to blame but yourself), then doing it all yourself may be the best option for you. It is a good alternative for both large and small projects. Git is open source, so it's easily self-hosted. If you want issue tracking and code review, you can run an instance of GitLab or [Phabricator][7]. For continuous integration, you can set up your own instance of the [Jenkins][8] automation server. Yes, you'll need to take responsibility for your own infrastructure overhead and the associated security requirements. However, it's not that hard to get yourself set up. And if you want a sure-fire way to avoid being beholden to the whims of anyone else's platform, this is the way to do it. + +### Option 6: All of the above + +Here's the beauty of all of this: Despite the proprietary drapery strewn over some of these platforms, they're still built on top of solid open source technology. And not just open source, but explicitly designed to be distributed across multiple nodes on a large network (like the internet). You're not required to use just one. You can use a couple… or all of them. Roll your own setup as a guaranteed home base using GitLab and have clone repositories on GitHub and Bitbucket for issue tracking and continuous integration. Keep your main codebase on GitHub but have "backup" clones sitting on GitLab for your own piece of mind. + +The key thing is you have options. And we have those options thanks to open source licensing on very useful and powerful projects. The future is bright. + +Of course, I'm bound to have missed some of the open source options available out there. Feel free to pipe up with your favorites. Are you using multiple platforms? What's your setup? Let everyone know in the comments! + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/8/github-alternatives + +作者:[Jason van Gumster][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://opensource.com/users/mairin +[1]: https://www.theverge.com/2018/6/4/17422788/microsoft-github-acquisition-official-deal +[2]: https://github.com/ +[3]: https://gitlab.com +[4]: https://bitbucket.org +[5]: https://www.mercurial-scm.org/wiki/Repository +[6]: https://sourceforge.net +[7]: https://phacility.com/phabricator/ +[8]: https://jenkins.io diff --git a/sources/tech/20180830 A quick guide to DNF for yum users.md b/sources/tech/20180830 A quick guide to DNF for yum users.md new file mode 100644 index 0000000000..559591b516 --- /dev/null +++ b/sources/tech/20180830 A quick guide to DNF for yum users.md @@ -0,0 +1,131 @@ +A quick guide to DNF for yum users +====== + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/dropbox.jpg?itok=qFwcqboT) + +Dandified yum, better known as [DNF][1], is a software package manager for RPM-based Linux distributions that installs, updates, and removes packages. It was first introduced in Fedora 18 in a testable state (i.e., tech preview), but it's been Fedora's default package manager since Fedora 22. + + * Dependency calculation based on modern dependency-solving technology + * Optimized memory-intensive operations + * The ability to run in Python 2 and Python 3 + * Complete documentation available for Python APIs + + + +Since it is the next-generation version of the traditional yum package manager, it has more advanced and robust features than you'll find in yum. Some of the features that distinguish DNF from yum are: + +DNF uses [hawkey][2] libraries, which resolve RPM dependencies for running queries on client machines. These are built on top of libsolv, a package-dependency solver that uses a satisfiability algorithm. You can find more details on the algorithm in [libsolv's GitHub][3] repository. + +### CLI commands that differ in DNF and yum + +Following are some of the changes to yum's command-line interface (CLI) you will find in DNF. + +**dnf update** or **dnf upgrade:** Executing either dnf update or dnf upgrade has the same effect in the system: both update installed packages. However, dnf upgrade is preferred since it works exactly like **yum --obsoletes update**. + +**resolvedep:** This command doesn't exist in DNF. Instead, execute **dnf provides** to find out which package provides a particular file. + +**deplist:** Yum's deplist command, which lists RPM dependencies, was removed in DNF because it uses the package-dependency solver algorithm to solve the dependency query. + +**dnf remove :** You must specify concrete versions of whatever you want to remove. For example, **dnf remove kernel** will delete all packages called "kernel," so make sure to use something like **dnf remove kernel-4.16.x**. + +**dnf history rollback:** This check, which undoes transactions after the one you specifiy, was dropped since not all the possible changes in the RPM Database Tool are stored in the history of the transaction. + +**--skip-broken:** This install command, which checks packages for dependency problems, is triggered in yum with --skip-broken. However, now it is part of dnf update by default, so there is no longer any need for it. + +**-b, --best:** These switches select the best available package versions in transactions. During dnf upgrade, which by default skips over updates that cannot be installed for dependency reasons, this switch forces DNF to consider only the latest packages. Use **dnf upgrade --best**. + +**--allowerasing:** Allows erasing of installed packages to resolve dependencies. This option could be used as an alternative to the **yum swap X Y** command, in which the packages to remove are not explicitly defined. + +For example: **dnf --allowerasing install Y**. + +**\--enableplugin:** This switch is not recognized and has been dropped. + +### DNF Automatic + +The [DNF Automatic][4] tool is an alternative CLI to dnf upgrade. It can execute automatically and regularly from systemd timers, cron jobs, etc. for auto-notification, downloads, or updates. + +To start, install dnf-automatic rpm and enable the systemd timer unit (dnf-automatic.timer). It behaves as specified by the default configuration file (which is /etc/dnf/automatic.conf). +``` +# yum install dnf-automatic +# systemctl enable dnf-automatic.timer +# systemctl start dnf-automatic.timer +# systemctl status dnf-automatic.timer +``` + +![](https://opensource.com/sites/default/files/uploads/dnf-automatic-timer.png) + +Other timer units that override the default configuration are listed below. Select the one that meets your system requirements. + + * **dnf-automatic-notifyonly.timer:** Notifies the available updates + * **dnf-automatic-download.timer:** Downloads packages, but doesn't install them + * **dnf-automatic-install.timer:** Downloads and installs updates + + + +### Basic DNF commands useful for package management + +**# yum install dnf:** This installs DNF RPM from the yum package manager. + +![](https://opensource.com/sites/default/files/uploads/yum-install-dnf.png) + +**# dnf –version:** This specifies the DNF version. + +![](https://opensource.com/sites/default/files/uploads/dnf-version.png) + +**# dnf list all** or **# dnf list :** This lists all or specific packages; this example lists the kernel RPM available in the system. + +![](https://opensource.com/sites/default/files/uploads/dnf-list-kernel.png) + +**# dnf check-update** or **# dnf check-update kernel:** This views updates in the system. + +![](https://opensource.com/sites/default/files/uploads/dnf-check-update_0.png) + +**# dnf search :** When you search for a specific package via DNF, it will search for an exact match as well as all wildcard searches available in the repository. + +![](https://opensource.com/sites/default/files/uploads/dnf-search.png) + +**# dnf repolist all:** This downloads and lists all enabled repositories in the system. + +![](https://opensource.com/sites/default/files/uploads/dnf-repolist.png) + +**# dnf list --recent** or **# dnf list --recent :** The **\--recent** option dumps all recently added packages in the system. Other list options are **\--extras** , **\--upgrades** , and **\--obsoletes**. + +![](https://opensource.com/sites/default/files/uploads/dnf-list-recent.png) + +**# dnf updateinfo list available** or **# dnf updateinfo list available sec:** These list all the advisories available in the system; including the sec option will list all advisories labeled "security fix." + +![](https://opensource.com/sites/default/files/uploads/dnf-updateinfo-list-available-sec.png) + +**# dnf updateinfo list available sec --sec-severity Critical:** This lists all the security advisories in the system marked "critical." + +![](https://opensource.com/sites/default/files/uploads/dnfupdateinfo-severity-critical.png) + +**# dnf updateinfo FEDORA-2018-a86100a264 –info:** This verifies the information of any advisory via the **\--info** switch. + +![](https://opensource.com/sites/default/files/uploads/dnf-updateinfo-fedora.png) + +**# dnf upgrade --security** or **# dnf upgrade --sec-severity Critical:** This applies all the security advisories available in the system. With the **\--sec-severity** option, you can include the packages with severity marked either Critical, Important, Moderate, or Low. + +![](https://opensource.com/sites/default/files/uploads/dnf-upgrade-security.png) + +### Summary + +These are just a small number of DNF's features, changes, and commands. For complete information about DNF's CLI, new plugins, and hook APIs, refer to the [DNF guide][5]. + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/8/guide-yum-dnf + +作者:[Amit Das][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://opensource.com/users/amit-das +[1]: https://fedoraproject.org/wiki/DNF?rd=Dnf +[2]: https://fedoraproject.org/wiki/Features/Hawkey +[3]: https://github.com/openSUSE/libsolv +[4]: https://dnf.readthedocs.io/en/latest/automatic.html +[5]: https://dnf.readthedocs.io/en/latest/index.html diff --git a/sources/tech/20180830 How to scale your website across all mobile devices.md b/sources/tech/20180830 How to scale your website across all mobile devices.md new file mode 100644 index 0000000000..ad36b9017a --- /dev/null +++ b/sources/tech/20180830 How to scale your website across all mobile devices.md @@ -0,0 +1,85 @@ +How to scale your website across all mobile devices +====== + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/migration_innovation_computer_software.png?itok=VCFLtd0q) + +Most of us surf the internet, make online purchases, and even pay bills using our mobile devices because they are handy and easily accessible. According to a Forrester study, [The Digital Business Imperative][1], 43% of banking customers in the US used mobile phones to complete banking transactions in a three-month period. + +The significant year-over-year growth of online business transactions done via mobile devices has encouraged companies to build websites and e-commerce sites that look, feel, and function identically on computers and smart mobile devices. However, many users still find the experience of browsing a website on a smartphone isn’t the same as on a computer. In order to develop websites that scale effectively and smoothly across different devices, it's important to understand what causes these differences across platforms. + +Web pages are usually composed of one or more of the following components: Header and footer, main content (text), images, forms, videos, and tables. Devices differ on features such as screen dimension (length x width), screen resolution (pixel density), compute power (CPU and memory), and operating system (iOS, Android, Windows, etc.). These differences contribute significantly to the overall performance and rendering of web components such as images, videos, and text across different devices. Another important factor is that mobile users may not always be connected to a high-speed network, so web pages should be carefully designed to work effectively on low-bandwidth connections. + +### The most troublesome issues on mobile platforms + +Here are some of the most common issues that can affect the performance and scalability of websites across devices: + + * **Sites do not automatically adapt to different screen sizes.** Some websites are designed to format for variable screen sizes, but their elements may not auto-scale. This would result in the site automatically adjusting itself for various screen sizes, but the elements in the site may look too large on smaller devices. Some sites may not be designed to adjust for variable screen sizes, causing the elements to look extremely small on devices with smaller screens. + * **Sites have too much content for mobile devices.** Some websites are loaded with content to fill empty space on a desktop screen. Websites developed without considering mobile users generally fall under this category. These sites take more time and bandwidth to load, and if the pages aren’t designed appropriately for mobile devices, some content may not even appear. + * **Sites take too long to load images.** Websites with too many images or heavy image files are likely to take a long time to load, especially if the images were not optimized during the design phase. + * **Data in tables looks complex and takes too long to load.** Many websites present data in a tabular fashion (for example, comparisons of competing products, airfare data from different travel sites, flight schedules, etc.), and on mobile devices, these tables can be slow and difficult to comprehend. + * **Websites host videos that don’t play on some devices.** Not all mobile devices support all video formats. Some websites host media that require licenses, Adobe Flash, or other players that some mobile devices may not support. This causes frustration and a poor overall user experience. + + + +### Design your sites to adapt to different devices + +All these issues can be addressed through proper design and by adopting a [mobile-first][2] approach. When working with limitations such as screen size, bandwidth, etc., focus on the right quantity and quality of content. A mobile-first strategy places content as the primary object and designs for the smallest devices, ensuring that a site includes only the most essential features. Address the design challenges for mobile devices first, and then progressively enhance the design for larger devices. + +Here are a few best practices to consider when designing websites that need to scale on different devices. + +* **Adapting to any screen size**. At a minimum, a web page needs to be scaled to fit the screen size of any mobile device. Today's mobile devices come with very high screen resolutions. The pixel density on mobile devices is much higher than that of desktop screens, so it is important to format pages to match the mobile screen’s width in device-independent pixels. The “meta viewport” tag included in the HTML document addresses this requirement. + +![](https://opensource.com/sites/default/files/uploads/image_1_0.png) + +The meta viewport value, as shown above, helps format the entire HTML page and render the content to match any screen size. + +* **" Content is king."** Content should determine the design of a website, not vice versa. Websites with too many elements such as tables, forms, charts, etc., become challenging when they need to scale on mobile devices. Developers end up hiding content for mobile users, and the desktop version and the mobile version become inconsistent. The design should focus on the core structure and content rather than decorative elements. The mobile-first methodology ensures a single version of content for both desktop and mobile users, so web designers should carefully consider, craft, and optimize content so that it not only satisfies business goals but also appeals to mobile users. Content that doesn’t appear in the mobile version may not even need to appear in the desktop version. +* **Responsive images**. The design should consider small hand-held devices operating in areas with low signal strength. Large photos and complex graphics are not suitable for mobile devices operating under such conditions. Make sure all images are optimized for different sizes of viewports and pixel densities. A recommended approach is [resolution switching][3], which enables the browser to select an appropriately sized image file, depending on the screen size of a device. Resolution switching uses two attributes—`srcset` and `sizes` (shown in the code snippet shown below)—which enable the browser to use the device width to select the most suitable media condition provided in the sizes list, choose the slot size based on that condition, and load the image referenced in the `srcset` that most closely matches the chosen slot size. + +![](https://opensource.com/sites/default/files/uploads/image_2_0.png) + +For example, if a device with a viewport of 320px loads the page, the media condition (max-width: 320px) in the sizes list will be true, and the corresponding 280px slot will be chosen. The width of the first image listed in `srcset` (elephant-320w.jpg) is the closest to this slot. Browsers that don’t support resolution switching display the image listed in the src attribute as the default image. This approach not only picks the right image for your device viewport, but it also prevents loading unnecessarily large images that consume significant bandwidth. + +![](https://opensource.com/sites/default/files/uploads/image_3_0.png) + +* **Responsive tables.** As the world becomes more data-driven, bringing critical, time-sensitive data to handheld devices provides power and freedom to users. The challenge is to present data in a way that is easy to load and read on mobile devices. Some data needs to be presented in the form of a table, but when data tables get too large and unwieldy, it can be frustrating for users to interpret them on a mobile device with a small screen. If the screen is much narrower than the width of the table, for example, users are forced to zoom out, making the text too small to read. Conversely, if the screen is wider than the table, users must zoom in to view the data, which requires constant vertical and horizontal scrolling. + +Fortunately, there are several ways to build [responsive tables][4]. Here is one of the most effective: + + * The table's columns are transposed into rows. Each column is sized to the same width as the screen, preventing the need to scroll horizontally. Use of color helps users clearly distinguish each individual row of data. In this case, for each “cell,” the CSS-generated content `(:before)` should be used to apply the label so that each piece of data can be identified clearly. + * Another approach is to display the data in one of two formats, based on screen width: chart format (for narrow screens) or complete table format (for wider screens). If the user wants to click the chart to see the complete table, the approach described above can be used to show the data in tabular form.(:before) + * A third approach is to show a mini-graphic in a narrow screen to indicate the presence of a table. The user can click on the graphic to expand and display the table. +* **Videos that always play.** [Video files][5] generally won’t play on mobile devices if their formats are unsupported or if they require a proprietary video player. The recommended approach is to use standard HTML5 tags for videos and animations. The video element in HTML5 can be used to load, decode, and play videos on your website. Produce video in multiple formats to suit different mobile platforms, and be sure to size videos appropriately so that they play within their containers. + +The example below shows the use of tags to specify different video formats (indicated by the type element). In this approach, the switch to the correct format happens at the client side, and only one request is made to the server. This reduces network latency and lets the browser select the most appropriate video format without first downloading it. + +![](https://opensource.com/sites/default/files/uploads/image_4_0.png) + +The `videoWidth` and `videoHeight` properties of the video element help identify the encoded size of a video. Video dimensions can be controlled using JavaScript or CSS. `max-width: 100%` helps size the videos to fit the screen. CSS media queries can be used to set the size based on the viewport dimensions. There are also several JavaScript libraries and plugins that can maintain the aspect ratio and size of videos. + +### All things considered… + +These days, users regularly surf the web and perform business transactions with their smartphones and tablets. The web is becoming the primary business channel for many businesses worldwide. Consequently, it is important to develop websites that work and scale well on mobile devices. The goal is to enhance the mobile user experience so that it mirrors the functionality and performance of desktop computers and large monitors. + +The mobile-first approach helps web designers create sites that operate well on small mobile devices. Design should focus on content that satisfies business requirements while also considering technical limitations such as screen size, processor speed, memory, and operating conditions (e.g., poor network signal strength). It must also ensure that pictures, videos, and data are responsive across all mobile devices while remaining sensitive to breakpoints, touch targets, etc. + +A well-designed website that works and scales on a small device can always be progressively enhanced to work on larger devices. + + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/8/how-scale-your-website-across-all-devices + +作者:[Sridhar Asvathanarayanan][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://opensource.com/users/sasvathanarayanangmailcom +[1]: https://www.forrester.com/report/The+Digital+Business+Imperative/-/E-RES115784# +[2]: https://www.uxpin.com/studio/blog/a-hands-on-guide-to-mobile-first-design/ +[3]: https://developer.mozilla.org/en-US/docs/Learn/HTML/Multimedia_and_embedding/Responsive_images +[4]: https://css-tricks.com/responsive-data-tables/ +[5]: https://developers.google.com/web/fundamentals/media/video diff --git a/sources/tech/20180831 3 innovative open source projects for the new school year.md b/sources/tech/20180831 3 innovative open source projects for the new school year.md new file mode 100644 index 0000000000..e8493ed501 --- /dev/null +++ b/sources/tech/20180831 3 innovative open source projects for the new school year.md @@ -0,0 +1,59 @@ +3 innovative open source projects for the new school year +====== + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/desk_clock_job_work.jpg?itok=Nj4fuhl6) + +I first wrote about open source learning software for educators in the fall of 2013. Fast-forward five years—today, open source software and principles have moved from outsiders in the education industry to the popular crowd. + +Since Penn Manor School District has [adopted open software][1] and cultivated a learning community built on trust, we've watched student creativity, ingenuity, and engagement soar. Here are three free and open source software tools we’ve used during the past school year. All three have enabled great student projects and may spark cool classroom ideas for open-minded educators. + +### Catch a wave: Software-defined radio + +Students may love the modern sounds of Spotify and Soundcloud, but there's an old-school charm to snatching noise from the atmosphere. Penn Manor help desk student apprentices had serious fun with [software-defined radio][2] (SDR). With an inexpensive software-defined radio kit, students can capture much more than humdrum FM radio stations. One of our help desk apprentices, JR, discovered everything from local emergency radio chatter to unencrypted pager messages. + +Our basic setup involved a student’s Linux laptop running [gqrx software][3] paired with a [USB RTL-SDR tuner and a simple antenna][4]. It was light enough to fit in a student backpack for SDR on the go. And the kit was great for creative hacking, which JR demonstrated when he improvised all manner of antennas, including a frying pan, in an attempt to capture signals from the U.S. weather satellite [NOAA-18][5]. + +Former Penn Manor IT specialist Tom Swartz maintains an excellent [quick-start resource for SDR][6]. + +### Stream far for a middle school crowd: OBS Studio + +Remember live morning TV announcements in school? Amateur weather reports, daily news updates, middle school puns... In-house video studios are an excellent opportunity for fun collaboration and technical learning. But many schools are stuck running proprietary broadcast and video mixing software, and many more are unable to afford costly production hardware such as [NewTek’s TriCaster][7]. + +Cue [OBS Studio][8], a free, open source, real-time broadcasting program ideally suited for school projects as well as professional video streaming. During the past six months, several Penn Manor schools successfully upgraded to OBS Studio running on Linux. OBS handles our multi-source video and audio mixing, chroma key compositing, transitions, and just about anything else students need to run a surprising polished video broadcast. + +Penn Manor students stream a live morning show via UDP multicast to staff and students tuned in via the [mpv][9] media player. OBS also supports live streaming to YouTube, Facebook Live, and Twitch, which means students can broadcast daily school lunch menus and other vital updates to the world. + +### Self-drive by light: TurtleBot3 and Lidar + +Of course, robots are cool, but robots with lasers are ace. The newest star of the Penn Manor student help desk is Patch, a petite educational robot built with the [TurtleBot3][10] open hardware and software kit. The Turtlebot platform is extensible and great for hardware hacking, but we were most interested in creating a self-driving gadget. + +We used the Turtlebot3 Burger, the entry-level kit powered by a Raspberry PI and loaded with a laser distance sensor. New student tech apprentices Aiden, Alex, and Tristen were challenged to make the robot autonomously navigate down one Penn Manor High School hallway and back to the technology center. It was a tall order: The team spent several months building the bot, and then working through the [ROS][11]-based programming, [rviz][12] (a 3D environment visualizer) and mapping for simultaneous localization and mapping (SLAM). + +Building the robot was a joy, but without a doubt, the programming challenged the students, none of whom had previously touched any of the ROS software tools. However, after much persistence, trial and error, and tenacity, Aiden and Tristen succeeded in achieving both the hallway navigation goal and in confusing fellow students with a tiny robot transversing school corridors and magically avoiding objects and people in its path. + +I recommend the TurtleBot3, but educators should be aware of the cost (approximately US$ 500) and the complexity. However, the kit is an outstanding resource for students aspiring to technology careers or those who want to build something amazing. + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/8/back-school-project-ideas + +作者:[Charlie Reisinger][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://opensource.com/users/charlie +[1]: https://opensource.com/education/14/9/interview-charlie-reisinger-penn-manor +[2]: https://en.wikipedia.org/wiki/Software-defined_radio +[3]: http://gqrx.dk/ +[4]: https://www.amazon.com/JahyShow%C2%AE-RTL2832U-RTL-SDR-Receiver-Compatible/dp/B01H830YQ6 +[5]: https://en.wikipedia.org/wiki/NOAA-18 +[6]: https://github.com/tomswartz07/CPOSC2017 +[7]: https://www.newtek.com/tricaster/ +[8]: https://obsproject.com/ +[9]: https://mpv.io/ +[10]: https://www.turtlebot.com/ +[11]: http://www.ros.org/ +[12]: http://wiki.ros.org/rviz diff --git a/sources/tech/20180831 Publishing Markdown to HTML with MDwiki.md b/sources/tech/20180831 Publishing Markdown to HTML with MDwiki.md new file mode 100644 index 0000000000..c25239b7ba --- /dev/null +++ b/sources/tech/20180831 Publishing Markdown to HTML with MDwiki.md @@ -0,0 +1,73 @@ +Publishing Markdown to HTML with MDwiki +====== + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/coffee_cafe_brew_laptop_desktop.jpg?itok=G-n1o1-o) + +There are plenty of reasons to like Markdown, a simple language with an easy-to-learn syntax that can be used with any text editor. Using tools like [Pandoc][1], you can convert Markdown text to [a variety of popular formats][2], including HTML. You can also automate that conversion process in a web server. An HTML5 and JavaScript application called [MDwiki][3], created by Timo Dörr, can take a stack of Markdown files and turn them into a website when requested from a browser. The MDwiki site includes a how-to guide and other information to help you get started: + +![MDwiki site getting started][5] + +What an Mdwiki site looks like. + +Inside the web server, a basic MDwiki site looks like this: + +![MDwiki site inside web server][7] + +What the webserver folder for that site looks like. + +I renamed the MDwiki HTML file `START.HTML` for this project. There is also one Markdown file that deals with navigation and a JSON file to hold a few configuration settings. Everything else is site content. + +While the overall website design is pretty much fixed by MDwiki, the content, styling, and number of pages are not. You can view a selection of different sites generated by MDwiki at [the MDwiki site][8]. It is fair to say that MDwiki sites lack the visual appeal that a web designer could achieve—but they are functional, and users should balance their simple appearance against the speed and ease of creating and editing them. + +Markdown comes in various flavors that extend a stable core functionality for different specific purposes. MDwiki uses GitHub flavor [Markdown][9], which adds features such as formatted code blocks and syntax highlighting for popular programming languages, making it well-suited for producing program documentation and tutorials. + +MDwiki also supports what it calls "gimmicks," which add extra functionality such as embedding YouTube video content and displaying mathematical formulas. These are worth exploring if you need them for specific projects. I find MDwiki an ideal tool for creating technical documentation and educational resources. I have also discovered some tricks and hacks that might not be immediately apparent. + +MDwiki works with any modern web browser when deployed in a web server; however, you do not need a web server if you access MDwiki with Mozilla Firefox. Most MDwiki users will opt to deploy completed projects on a web server to avoid excluding potential users, but development and testing can be done with just a text editor and Firefox. Completed MDwiki projects that are loaded into a Moodle Virtual Learning Environment (VLE) can be read by any modern browser, which could be useful in educational contexts. (This is probably also true for other VLE software, but you should test that.) + +MDwiki's default color scheme is not ideal for all projects, but you can replace it with another theme downloaded from [Bootswatch.com][10]. To do this, simply open the MDwiki HTML file in an editor, take out the `extlib/css/bootstrap-3.0.0.min.css` code, and insert the downloaded Bootswatch theme. There is also an MDwiki gimmick that lets users choose a Bootswatch theme to replace the default after MDwiki loads in their browser. I often work with users who have visual impairments, and they tend to prefer high-contrast themes, with white text on a dark background. + +![MDwiki screen with Bootswatch Superhero theme][12] + +MDwiki screen using the Bootswatch Superhero theme + +MDwiki, Markdown files, and static images are fine for many purposes. However, you might sometimes want to include, say, a JavaScript slideshow or a feedback form. Markdown files can include HTML code, but mixing Markdown with HTML can get confusing. One solution is to create the feature you want in a separate HTML file and display it inside a Markdown file with an iframe tag. I took this idea from the [Twine Cookbook][13], a support site for the Twine interactive fiction engine. The Twine Cookbook doesn’t actually use MDwiki, but combining Markdown and iframe tags opens up a wide range of creative possibilities. + +Here is an example: + +This HTML will display an HTML page created by the Twine interactive fiction engine inside a Markdown file. +``` + +``` + +The result in an MDwiki-generated site looks like this: + +![](https://opensource.com/sites/default/files/uploads/4_-_mdwiki_site_summary.png) + +In short, MDwiki is an excellent small application that achieves its purpose extremely well. + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/8/markdown-html-publishing + +作者:[Peter Cheer][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://opensource.com/users/petercheer +[1]: https://pandoc.org/ +[2]: https://opensource.com/downloads/pandoc-cheat-sheet +[3]: http://dynalon.github.io/mdwiki/#!index.md +[4]: https://opensource.com/file/407306 +[5]: https://opensource.com/sites/default/files/uploads/1_-_mdwiki_screenshot.png (MDwiki site getting started) +[6]: https://opensource.com/file/407311 +[7]: https://opensource.com/sites/default/files/uploads/2_-_mdwiki_inside_web_server.png (MDwiki site inside web server) +[8]: http://dynalon.github.io/mdwiki/#!examples.md +[9]: https://guides.github.com/features/mastering-markdown/ +[10]: https://bootswatch.com/ +[11]: https://opensource.com/file/407316 +[12]: https://opensource.com/sites/default/files/uploads/3_-_mdwiki_bootswatch_superhero.png (MDwiki screen with Bootswatch Superhero theme) +[13]: https://github.com/iftechfoundation/twine-cookbook diff --git a/sources/tech/20180831 Test containers with Python and Conu.md b/sources/tech/20180831 Test containers with Python and Conu.md new file mode 100644 index 0000000000..e28ca4674e --- /dev/null +++ b/sources/tech/20180831 Test containers with Python and Conu.md @@ -0,0 +1,164 @@ +Test containers with Python and Conu +====== + +![](https://fedoramagazine.org/wp-content/uploads/2018/08/conu-816x345.jpg) + +More and more developers are using containers to develop and deploy their applications. This means that easily testing containers is also becoming important. [Conu][1] (short for container utilities) is a Python library that makes it easy to write tests for your containers. This article shows you how to use it to test your containers. + +### Getting started + +First you need a container application to test. For that, the following commands create a new directory with a container Dockerfile, and a Flask application to be served by the container. +``` +$ mkdir container_test +$ cd container_test +$ touch Dockerfile +$ touch app.py + +``` + +Copy the following code inside the app.py file. This is the customary basic Flask application that returns the string “Hello Container World!” +``` +from flask import Flask +app = Flask(__name__) + +@app.route('/') +def hello_world(): + return 'Hello Container World!' + +if __name__ == '__main__': + app.run(debug=True,host='0.0.0.0') + +``` + +### Create and Build a Test Container + +To build the test container, add the following instructions to the Dockerfile. +``` +FROM registry.fedoraproject.org/fedora-minimal:latest +RUN microdnf -y install python3-flask && microdnf clean all +ADD ./app.py /srv +CMD ["python3", "/srv/app.py"] + +``` + +Then build the container using the Docker CLI tool. +``` +$ sudo dnf -y install docker +$ sudo systemctl start docker +$ sudo docker build . -t flaskapp_container + +``` + +Note : The first two commands are only needed if Docker is not installed on your system. + +After the build use the following command to run the container. +``` +$ sudo docker run -p 5000:5000 --rm flaskapp_container +* Running on http://0.0.0.0:5000/ (Press CTRL+C to quit) +* Restarting with stat +* Debugger is active! +* Debugger PIN: 473-505-51 + +``` + +Finally, use curl to check that the Flask application is correctly running inside the container: +``` +$ curl http://127.0.0.1:5000 +Hello Container World! + +``` + +With the flaskapp_container now running and ready for testing, you can stop it using **Ctrl+C**. + +### Create a test script + +Before you write the test script, you must install conu. Inside the previously created container_test directory run the following commands. +``` +$ python3 -m venv .venv +$ source .venv/bin/activate +(.venv)$ pip install --upgrade pip +(.venv)$ pip install conu + +$ touch test_container.py + +``` + +Then copy and save the following script in the test_container.py file. +``` +import conu + +PORT = 5000 + +with conu.DockerBackend() as backend: + image = backend.ImageClass("flaskapp_container") + options = ["-p", "5000:5000"] + container = image.run_via_binary(additional_opts=options) + + try: + # Check that the container is running and wait for the flask application to start. + assert container.is_running() + container.wait_for_port(PORT) + + # Run a GET request on / port 5000. + http_response = container.http_request(path="/", port=PORT) + + # Check the response status code is 200 + assert http_response.ok + + # Get the response content + response_content = http_response.content.decode("utf-8") + + # Check that the "Hello Container World!" string is served. + assert "Hello Container World!" in response_content + + # Get the logs from the container + logs = [line for line in container.logs()] + # Check the the Flask application saw the GET request. + assert b'"GET / HTTP/1.1" 200 -' in logs[-1] + + finally: + container.stop() + container.delete() + +``` + +#### Test Setup + +The script starts by setting conu to use Docker as a backend to run the container. Then it sets the container image to use the flaskapp_container you built in the first part of this tutorial. + +The next step is to configure the options needed to run the container. In this example, the Flask application serves the content on port 5000. Therefore you need to expose this port and map it to the same port on the host. + +Finally, the script starts the container, and it’s now ready to be tested. + +#### Testing methods + +Before testing a container, check that the container is running and ready. The example script is using container.is_running and container.wait_for_port. These methods ensure the container is running and the service is available on the expected port. + +The container.http_request is a wrapper around the [requests][2] library which makes it convenient to send HTTP requests during the tests. This method returns a [requests.Response][3]object, so it’s easy to access the content of the response for testing. + +Conu also gives access to the container logs. Once again, this can be useful during testing. In the example above, the container.logs method returns the container logs. You can use them to assert that a specific log was printed, or for example that no exceptions were raised during testing. + +Conu provides many other useful methods to interface with containers. A full list of the APIs is available in the [documentation][4]. You can also consult the examples available on [GitHub][5]. + +All the code and files needed to run this tutorial are available on [GitHub][6] as well. For readers who want to take this example further, you can look at using [pytest][7] to run the tests and build a container test suite. + + +-------------------------------------------------------------------------------- + +via: https://fedoramagazine.org/test-containers-python-conu/ + +作者:[Clément Verna][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://fedoramagazine.org/author/cverna/ +[1]: https://github.com/user-cont/conu +[2]: http://docs.python-requests.org/en/master/ +[3]: http://docs.python-requests.org/en/master/api/#requests.Response +[4]: https://conu.readthedocs.io/en/latest/index.html +[5]: https://github.com/user-cont/conu/tree/master/docs/source/examples +[6]: https://github.com/cverna/container_test_script +[7]: https://docs.pytest.org/en/latest/ diff --git a/sources/tech/20180901 Flameshot - A Simple, Yet Powerful Feature-rich Screenshot Tool.md b/sources/tech/20180901 Flameshot - A Simple, Yet Powerful Feature-rich Screenshot Tool.md new file mode 100644 index 0000000000..f6bec82f02 --- /dev/null +++ b/sources/tech/20180901 Flameshot - A Simple, Yet Powerful Feature-rich Screenshot Tool.md @@ -0,0 +1,168 @@ +Flameshot – A Simple, Yet Powerful Feature-rich Screenshot Tool +====== + +![](https://www.ostechnix.com/wp-content/uploads/2018/09/Flameshot-720x340.png) + +Capturing screenshots is part of my job. I have been using Deepin-screenshot tool for taking screenshots. It’s a simple, light-weight and quite neat screenshot tool. It comes with all options such as mart window identification, shortcuts supporting, image editing, delay screenshot, social sharing, smart saving, and image resolution adjusting etc. Today, I stumbled upon yet another screenshot tool that ships with many features. Say hello to **Flameshot** , a simple and powerful, feature-rich screenshot tool for Unix-like operating systems. It is easy to use, customizable and has an option to upload your screenshots to **imgur** , an online image sharing website. And also, Flameshot has a CLI version, so you can take screenshots from commandline as well. Flameshot is completely free and open source tool. In this guide, we will see how to install Flameshot and how to take screenshots using it. + +### Install Flameshot + +**On Arch Linux:** + +Flameshot is available [community] repository in Arch Linux. Make sure you have enabled community repository and install Flameshot using pacman as shown below. +``` +$ sudo pacman -S flameshot + +``` + +It is also available in [**AUR**][1], so you can install it using any AUR helper programs, for example [**Yay**][2], in Arch-based systems. +``` +$ yay -S flameshot-git + +``` + +**On Fedora:** +``` +$ sudo dnf install flameshot + +``` + +On **Debian 10+** and **Ubuntu 18.04+** , install it using APT package manager. +``` +$ sudo apt install flameshot + +``` + +**On openSUSE:** +``` +$ sudo zypper install flameshot + +``` + +On other distributions, compile and install it from source code. The compilation requires **Qt version 5.3** or higher and **GCC 4.9.2** or higher. + +### Usage + +Launch Flameshot from menu or application launcher. On MATE desktop environment, It usually found under **Applications - > Graphics**. + +Once you opened it, you will see Flameshot systray icon in your system’s panel. + +**Note:** + +If you are using Gnome you need to install the [TopIcons][3] extension in order to see the systemtray icon. + +Right click on the tray icon and you’ll see some menu items to open the configuration window and the information window or quit the application. + +To capture screenshot, just click on the tray icon. You will see help window that says how to use Flameshot. Choose an area to capture and hit **ENTER** key to capture the screen. Press right click to show the color picker, hit spacebar to view the side panel. You can use increase or decrease the pointer’s thickness by using the Mouse scroll button. + +Flameshot comes with quite good set of features, such as, + + * Free hand writing + * Line drawing + * Rectangle / Circle drawing + * Rectangle selection + * Arrows + * Marker to highlight important points + * Add text + * Blur the image/text + * Show the dimension of the image + * Undo/Redo the changes while editing images + * Copy the selection to the clipboard + * Save the selection + * Leave the capture screen + * Choose an app to open images + * Upload the selection to imgur site + * Pin image to desktop + + + +Here is a sample demo: + + + +**Keyboard shortcuts** + +Frameshot supports keyboard shortcuts. Right click on Flameshot tray icon and click **Information** window to see all the available shortcuts in the graphical capture mode. Here is the list of available keyboard shortcuts in GUI mode. + +| Keys | Description | +|------------------------|------------------------------| +| ←, ↓, ↑, → | Move selection 1px | +| Shift + ←, ↓, ↑, → | Resize selection 1px | +| Esc | Quit capture | +| Ctrl + C | Copy to clipboard | +| Ctrl + S | Save selection as a file | +| Ctrl + Z | Undo the last modification | +| Right Click | Show color picker | +| Mouse Wheel | Change the tool’s thickness | + +Shift + drag a handler of the selection area: mirror redimension in the opposite handler. + +**Command line options** + +Flameshot also has a set of command line options to delay the screenshots and save images in custom paths. + +To capture screen with Flameshot GUI, run: +``` +$ flameshot gui + +``` + +To capture screen with GUI and save it in a custom path of your choice: +``` +$ flameshot gui -p ~/myStuff/captures + +``` + +To open GUI with a delay of 2 seconds: +``` +$ flameshot gui -d 2000 + +``` + +To capture fullscreen with custom save path (no GUI) with a delay of 2 seconds: +``` +$ flameshot full -p ~/myStuff/captures -d 2000 + +``` + +To capture fullscreen with custom save path copying to clipboard: +``` +$ flameshot full -c -p ~/myStuff/captures + +``` + +To capture the screen containing the mouse and print the image (bytes) in **PNG** format: +``` +$ flameshot screen -r + +``` + +To capture the screen number 1 and copy it to the clipboard: +``` +$ flameshot screen -n 1 -c + +``` + +What do you need? Flameshot has almost all features for capturing pictures, adding annotations, editing images, blur or highlight important points and a lot more. I think I will stick with Flameshot for a while as find it best replacement for my current screenshot tool. Give it a try and you won’t be disappointed. + +And, that’s all for now. More good stuffs to come. Stay tuned! + +Cheers! + + + +-------------------------------------------------------------------------------- + +via: https://www.ostechnix.com/flameshot-a-simple-yet-powerful-feature-rich-screenshot-tool/ + +作者:[SK][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://www.ostechnix.com/author/sk/ +[1]: https://aur.archlinux.org/packages/flameshot-git +[2]: https://www.ostechnix.com/yay-found-yet-another-reliable-aur-helper/ +[3]: https://extensions.gnome.org/extension/1031/topicons/ diff --git a/sources/tech/20180903 A Cross-platform High-quality GIF Encoder.md b/sources/tech/20180903 A Cross-platform High-quality GIF Encoder.md new file mode 100644 index 0000000000..7a7f79064b --- /dev/null +++ b/sources/tech/20180903 A Cross-platform High-quality GIF Encoder.md @@ -0,0 +1,160 @@ +A Cross-platform High-quality GIF Encoder +====== + +![](https://www.ostechnix.com/wp-content/uploads/2018/09/gifski-720x340.png) + +As a content writer, I needed to add images in my articles. Sometimes, it is better to add videos or gif images to explain the concept a bit easier. The readers can easily understand the guide much better by watching the output in video or gif format than the text. The day before, I have written about [**Flameshot**][1], a feature-rich and powerful screenshot tool for Linux. Today, I will show you how to make high quality gif images either from a video or set of images. Meet **Gifski** , a cross-platform, open source, command line High-quality GIF encoder based on **Pngquant**. + +For those wondering, pngquant is a command line lossy PNG image compressor. Trust me, pngquant is one of the best loss-less PNG compressor that I ever use. It compresses PNG images **upto 70%** without losing the original quality and and preserves full alpha transparency. The compressed images are compatible with all web browsers and operating systems. Since Gifski is based on Pngquant, it uses pngquant’s features for creating efficient GIF animations. Gifski is capable of creating animated GIFs that use thousands of colors per frame. Gifski is also requires **ffmpeg** to convert video into PNG images. + +### **Installing Gifski** + +Make sure you have installed FFMpeg and Pngquant. + +FFmpeg is available in the default repositories of most Linux distributions, so you can install it using the default package manager. For installation instructions, refer the following guide. + +Pngquant is available in [**AUR**][2]. To install it in Arch-based systems, use any AUR helper programs like [**Yay**][3]. +``` +$ yay -S pngquant + +``` + +On Debian-based systems, run: +``` +$ sudo apt install pngquant + +``` + +If pngquant is not available for your distro, compile and install it from source. You will need **`libpng-dev`** package installed with development headers. +``` +$ git clone --recursive https://github.com/kornelski/pngquant.git + +$ make + +$ sudo make install + +``` + +After installing the prerequisites, install Gifski. You can install it using **cargo** if you have installed [**Rust**][4] programming language. +``` +$ cargo install gifski + +``` + +You can also get it with [**Linuxbrew**][5] package manager. +``` +$ brew install gifski + +``` + +If you don’t want to install cargo or Linuxbrew, download the latest binary executables from [**releases page**][6] and compile and install gifski manually. + +### Create high-quality GIF animations using Gifski high-quality GIF encoder + +Go to the location where you have kept the PNG images and run the following command to create GIF animation from the set of images: +``` +$ gifski -o file.gif *.png + +``` + +Here file.gif is the final output gif animation. + +Gifski has also some other additional features, like; + + * Create GIF animation with specific dimension + * Show specific number of animations per second + * Encode with a specific quality + * Encode faster + * Encode images exactly in the order given, rather than sorted + + + +To create GIF animation with specific dimension, for example width=800 and height=400, use the following command: +``` +$ gifski -o file.gif -W 800 -H 400 *.png + +``` + +You can set how many number of animation frames per second you want in the gif animation. The default value is **20**. To do so, run: +``` +$ gifski -o file.gif --fps 1 *.png + +``` + +In the above example, I have used one animation frame per second. + +We can encode with specific quality on the scale of 1-100. Obviously, the lower quality may give smaller file and higher quality give bigger seize gif animation. +``` +$ gifski -o file.gif --quality 50 *.png + +``` + +Gifski will take more time when you encode large number of images. To make the encoding process 3 times faster than usual speed, run: +``` +$ gifski -o file.gif --fast *.png + +``` + +Please note that it will reduce quality to 10% and create bigger animation file. + +To encode images exactly in the order given (rather than sorted), use **`--nosort`** option. +``` +$ gifski -o file.gif --nosort *.png + +``` + +If you do not to loop the GIF, simple use **`--once`** option. +``` +$ gifski -o file.gif --once *.png + +``` + +**Create GIF animation from Video file** + +Some times you might want to an animated file from a video. It is also possible. This is where FFmpeg comes in help. First convert the video into PNG frames first like below. +``` +$ ffmpeg -i video.mp4 frame%04d.png + +``` + +The above command makes image files namely “frame0001.png”, “frame0002.png”, “frame0003.png”…, etc. from video.mp4 (%04d makes the frame number) and save them in the current working directory. + +After converting the image files, simply run the following command to make the animated GIF file. +``` +$ gifski -o file.gif *.png + +``` + +For more details, refer the help section. +``` +$ gifski -h + +``` + +Here is the sample animated file created using Gifski. + +As you can see, the quality of the GIF file is really great. + +And, that’s all for now. Hope this was useful. More good stuffs to come. Stay tuned! + +Cheers! + + +-------------------------------------------------------------------------------- + +via: https://www.ostechnix.com/gifski-a-cross-platform-high-quality-gif-encoder/ + +作者:[SK][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://www.ostechnix.com/author/sk/ +[1]: https://www.ostechnix.com/flameshot-a-simple-yet-powerful-feature-rich-screenshot-tool/ +[2]: https://aur.archlinux.org/packages/pngquant/ +[3]: https://www.ostechnix.com/yay-found-yet-another-reliable-aur-helper/ +[4]: https://www.ostechnix.com/install-rust-programming-language-in-linux/ +[5]: https://www.ostechnix.com/linuxbrew-common-package-manager-linux-mac-os-x/ +[6]: https://github.com/ImageOptim/gifski/releases diff --git a/sources/tech/20180905 How To Run MS-DOS Games And Programs In Linux.md b/sources/tech/20180905 How To Run MS-DOS Games And Programs In Linux.md new file mode 100644 index 0000000000..0552fb3d09 --- /dev/null +++ b/sources/tech/20180905 How To Run MS-DOS Games And Programs In Linux.md @@ -0,0 +1,253 @@ +How To Run MS-DOS Games And Programs In Linux +====== + +![](https://www.ostechnix.com/wp-content/uploads/2018/09/dosbox-720x340.png) + +If you ever wanted to try some good-old MS-DOS games and defunct C++ compilers like Turbo C++ in Linux? Good! This tutorial will teach you how to run MS-DOS games and programs under Linux environment using **DOSBox**. It is an x86 PC DOS-emulator that can be used to run classic DOS games or programs. DOSBox emulates an Intel x86 PC with sound, graphics, mouse, joystick, and modem etc., that allows you to run many old MS-DOS games and programs that simply cannot be run on any modern PCs and operating systems, such as Microsoft Windows XP and later, Linux and FreeBSD. It is free, written using C++ programming language and distributed under GPL. + +### Install DOSBox In Linux + +DOSBox is available in the default repositories of most Linux distributions. + +On Arch Linux and its variants like Antergos, Manjaro Linux: +``` +$ sudo pacman -S dosbox + +``` + +On Debian, Ubuntu, Linux Mint: +``` +$ sudo apt-get install dosbox + +``` + +On Fedora: +``` +$ sudo dnf install dosbox + +``` + +### Configure DOSBox + +There is no initial configuration required to use DOSBox and it just works out of the box. The default configuration file named `dosbox-x.xx.conf` exists in your **`~/.dosbox`** folder. In this configuration file, you can edit/modify various settings, such as starting DOSBox in fullscreen mode, use double buffering in fullscreen, set preferred resolution to use for fullscreen, mouse sensitivity, enable or disable sound, speaker, joystick and a lot more. As I mentioned earlier, the default settings will work just fine. You need not to make any changes. + +### Run MS-DOS Games And Programs In Linux + +To launch DOSBox, run the following command from the Terminal: +``` +$ dosbox + +``` + +This is how DOSBox interface looks like. + +![](https://www.ostechnix.com/wp-content/uploads/2018/09/Dosbox-prompt.png) + +As you can see, DOSBox comes with its own DOS-like command prompt with a virtual `Z:\` Drive, so if you’re familiar with MS-DOS, you wouldn’t find any difficulties to work in DOSBox environment. + +Here is the output of `dir`command (Equivalent of `ls` command in Linux) output: + +![](http://www.ostechnix.com/wp-content/uploads/2018/09/dir-command-output.png) + +If you’re a new user and it is the first time you use DOSBox, you can view the short introduction about DOSBox by entering the following command in DOSBox prompt: +``` +intro + +``` + +Press ENTER to go through next page of the introduction section. + +To view the list of most often used commands in DOS, use this command: +``` +help + +``` + +To view list of all supported commands in DOSBox, type: +``` +help /all + +``` + +Remember, these commands should be used in the DOSBox prompt, not in your Linux Terminal. + +DOSBox also supports a good set of keyboard bindings. Here is the default keyboard shortcuts to effectively use DOSBox. + +![](http://www.ostechnix.com/wp-content/uploads/2018/09/Dosbox-keyboard-shortcuts.png) + +To exit from DOSBox, simply type and hit ENTER: +``` +exit + +``` + +By default, DOSBox starts with a normal window-sized screen like above. + +To start dosbox directly in fullscreen, edit your `dosbox-x.xx.conf` file and set the value of **fullscreen** variable as **enable**. Now, DosBox will start in fullscreen mode. To go back to normal screen, press **ALT+ENTER**. + +Hope you get the basic usage of DOSBox. + +Let us go ahead and install some DOS programs and games. + +First, we need to create directories to save the programs and games in our Linux system. I am going to create two directories named **`~/dosprograms`** and **`~/dosgames`** , the first one for storing programs and latter for storing games. +``` +$ mkdir ~/dosprograms ~/dosgames + +``` + +For the purpose of this guide, I will show you how to install **Turbo C++** program and Mario game. First, we will see how to install Turbo. + +Download the latest Turbo C++ compiler, extract it and save the contents file in **`~/dosprograms`** directory. I have save the contents turbo c++ in my **~/dosprograms/TC/** directory. +``` +$ ls dosprograms/tc/ +BGI BIN CLASSLIB DOC EXAMPLES FILELIST.DOC INCLUDE LIB README README.COM + +``` + +Start Dosbox: +``` +$ dosbox + +``` + +And mount the **`~/dosprograms`** directory as virtual drive **C:\** in DOSBox. +``` +Z:\>mount c ~/dosprograms + +``` + +You will see an output something like below. +``` +Drive C is mounted as local directory /home/sk/dosprograms. + +``` + +![](https://www.ostechnix.com/wp-content/uploads/2018/09/Dosbox-prompt-1.png) + +Now, change to the C drive using command: +``` +Z:\>c: + +``` + +And then, switch to **tc/bin** directory: +``` +Z:\>cd tc/bin + +``` + +Finally, run turbo c++ executable file: +``` +Z:\>tc.exe + +``` + +**Note:** Just type first few letters and hit ENTER to autocomplete the file name. + +![](https://www.ostechnix.com/wp-content/uploads/2018/09/Dosbox-prompt-4.png) + +You will now be in Turbo C++ console. + +![](https://www.ostechnix.com/wp-content/uploads/2018/09/Dosbox-prompt-5.png) + +Create new file (ATL+F) and start coding: + +![](https://www.ostechnix.com/wp-content/uploads/2018/09/Dosbox-prompt-6.png) + +Similarly, you can install and run other classic DOS programs. + +**Troubleshooting:** + +You might be encountered with following error while running turbo c++ or any other dos programs: +``` +DOSBox switched to max cycles, because of the setting: cycles=auto. If the game runs too fast try a fixed cycles amount in DOSBox's options. Exit to error: DRC64:Unhandled memory reference + +``` + +To fix this, edit your **~/.dosbox/dosbox-x.xx.conf** file: +``` +$ nano ~/.dosbox/dosbox-0.74.conf + +``` + +Find the following variable and change its value from: +``` +core=auto + +``` + +to +``` +core=normal + +``` + +Save and close the file. Now you can be able to run the dos programs without any problems. + +Now, let us see how to run a dos-based game, for example **Mario Bros VGA**. + +Download Mario game from [**here**][1] and extract the contents in **~/dosgames** directory in your Linux machine. + +Start DOSBox: +``` +$ dosbox + +``` + +We have used virtual drive **c:** for dos programs. For games, let us use **d:** as virtual drive. + +At the DOSBox prompt, run the following command to mount **~/dosgames** directory as virtuald drive **d**. +``` +Z:\>mount d ~/dosgames + +``` + +Switch to D: drive: +``` +Z:\>d: + +``` + +And then go to mario game directory and run the **mario.exe** file to launch the game. +``` +Z:\>cd mario + +Z:\>mario.exe + +``` + +![](https://www.ostechnix.com/wp-content/uploads/2018/09/Dosbox-prompt-7.png) + +Start playing the game: + +![](https://www.ostechnix.com/wp-content/uploads/2018/09/Mario-game-in-dosbox.png) + +Similarly, you can run any dos-based games as described above. You can view the complete list of supported games that can be run using DOSBox [**here**][2]. + +### Conclusion + +Even though DOSBOX is not a complete replacement for MS-DOS and it lacks many of the features found in MS-DOS, it is just enough to install and run most DOS games and programs. + +For more details, refer the official [**DOSBox manual**][3]. + +And, that’s all for now. Hope this was useful. More good stuffs to come. Stay tuned! + +Cheers! + + + +-------------------------------------------------------------------------------- + +via: https://www.ostechnix.com/how-to-run-ms-dos-games-and-programs-in-linux/ + +作者:[SK][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://www.ostechnix.com/author/sk/ +[1]: https://www.dosgames.com/game/mario-bros-vga +[2]: https://www.dosbox.com/comp_list.php +[3]: https://www.dosbox.com/DOSBoxManual.html diff --git a/sources/tech/20180906 How To Limit Network Bandwidth In Linux Using Wondershaper.md b/sources/tech/20180906 How To Limit Network Bandwidth In Linux Using Wondershaper.md new file mode 100644 index 0000000000..11d266e163 --- /dev/null +++ b/sources/tech/20180906 How To Limit Network Bandwidth In Linux Using Wondershaper.md @@ -0,0 +1,196 @@ +How To Limit Network Bandwidth In Linux Using Wondershaper +====== + +![](https://www.ostechnix.com/wp-content/uploads/2018/09/Wondershaper-1-720x340.jpg) + +This tutorial will help you to easily limit network bandwidth and shape your network traffic in Unix-like operating systems. By limiting the network bandwidth usage, you can save unnecessary bandwidth consumption’s by applications, such as package managers (pacman, yum, apt), web browsers, torrent clients, download managers etc., and prevent the bandwidth abuse by a single or multiple users in the network. For the purpose of this tutorial, we will be using a command line utility named **Wondershaper**. Trust me, it is not that hard as you may think. It is one of the easiest and quickest way ever I have come across to limit the Internet or local network bandwidth usage in your own Linux system. Read on. + +Please be mindful that the aforementioned utility can only limit the incoming and outgoing traffic of your local network interfaces, not the interfaces of your router or modem. In other words, Wondershaper will only limit the network bandwidth in your local system itself, not any other systems in the network. These utility is mainly designed for limiting the bandwidth of one or more network adapters in your local system. Hope you got my point. + +Let us see how to use Wondershaper to shape the network traffic. + +### Limit Network Bandwidth In Linux Using Wondershaper + +**Wondershaper** is simple script used to limit the bandwidth of your system’s network adapter(s). It limits the bandwidth iproute’s tc command, but greatly simplifies its operation. + +**Installing Wondershaper** + +To install the latest version, git clone wondershaoer repository: + +``` +$ git clone https://github.com/magnific0/wondershaper.git + +``` + +Go to the wondershaper directory and install it as show below + +``` +$ cd wondershaper + +$ sudo make install + +``` + +And, run the following command to start wondershaper service automatically on every reboot. + +``` +$ sudo systemctl enable wondershaper.service + +$ sudo systemctl start wondershaper.service + +``` + +You can also install using your distribution’s package manager (official or non-official) if you don’t mind the latest version. + +Wondershaper is available in [**AUR**][1], so you can install it in Arch-based systems using AUR helper programs such as [**Yay**][2]. + +``` +$ yay -S wondershaper-git + +``` + +On Debian, Ubuntu, Linux Mint: + +``` +$ sudo apt-get install wondershaper + +``` + +On Fedora: + +``` +$ sudo dnf install wondershaper + +``` + +On RHEL, CentOS, enable EPEL repository and install wondershaper as shown below. + +``` +$ sudo yum install epel-release + +$ sudo yum install wondershaper + +``` + +Finally, start wondershaper service automatically on every reboot. + +``` +$ sudo systemctl enable wondershaper.service + +$ sudo systemctl start wondershaper.service + +``` + +**Usage** + +First, find the name of your network interface. Here are some common ways to find the details of a network card. + +``` +$ ip addr + +$ route + +$ ifconfig + +``` + +Once you find the network card name, you can limit the bandwidth rate as shown below. + +``` +$ sudo wondershaper -a -d -u + +``` + +For instance, if your network card name is **enp0s8** and you wanted to limit the bandwidth to **1024 Kbps** for **downloads** and **512 kbps** for **uploads** , the command would be: + +``` +$ sudo wondershaper -a enp0s8 -d 1024 -u 512 + +``` + +Where, + + * **-a** : network card name + * **-d** : download rate + * **-u** : upload rate + + + +To clear the limits from a network adapter, simply run: + +``` +$ sudo wondershaper -c -a enp0s8 + +``` + +Or + +``` +$ sudo wondershaper -c enp0s8 + +``` + +Just in case, there are more than one network card available in your system, you need to manually set the download/upload rates for each network interface card as described above. + +If you have installed Wondershaper by cloning its GitHub repository, there is a configuration named **wondershaper.conf** exists in **/etc/conf.d/** location. Make sure you have set the download or upload rates by modifying the appropriate values(network card name, download/upload rate) in this file. + +``` +$ sudo nano /etc/conf.d/wondershaper.conf + +[wondershaper] +# Adapter +# +IFACE="eth0" + +# Download rate in Kbps +# +DSPEED="2048" + +# Upload rate in Kbps +# +USPEED="512" + +``` + +Here is the sample before Wondershaper: + +After enabling Wondershaper: + +As you can see, the download rate has been tremendously reduced after limiting the bandwidth using WOndershaper in my Ubuntu 18.o4 LTS server. + +For more details, view the help section by running the following command: + +``` +$ wondershaper -h + +``` + +Or, refer man pages. + +``` +$ man wondershaper + +``` + +As far as tested, Wondershaper worked just fine as described above. Give it a try and let us know what do you think about this utility. + +And, that’s all for now. Hope this was useful. More good stuffs to come. Stay tuned. + +Cheers! + + + +-------------------------------------------------------------------------------- + +via: https://www.ostechnix.com/how-to-limit-network-bandwidth-in-linux-using-wondershaper/ + +作者:[SK][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://www.ostechnix.com/author/sk/ +[1]: https://aur.archlinux.org/packages/wondershaper-git/ +[2]: https://www.ostechnix.com/yay-found-yet-another-reliable-aur-helper/ diff --git a/sources/tech/20180906 What a shell dotfile can do for you.md b/sources/tech/20180906 What a shell dotfile can do for you.md new file mode 100644 index 0000000000..35593e1e32 --- /dev/null +++ b/sources/tech/20180906 What a shell dotfile can do for you.md @@ -0,0 +1,238 @@ +What a shell dotfile can do for you +====== + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/coffee_cafe_brew_laptop_desktop.jpg?itok=G-n1o1-o) + +Ask not what you can do for your shell dotfile, but what a shell dotfile can do for you! + +I've been all over the OS map, but for the past several years my daily drivers have been Macs. For a long time, I used Bash, but when a few friends started proselytizing [zsh][1], I gave it a shot. It didn't take long for me to appreciate it, and several years later, I strongly prefer it for many of the little things that it does. + +I've been using zsh (provided via [Homebrew][2], not the system installed), and the [Oh My Zsh enhancement][3]. + +The examples in this article are for my personal `.zshrc`. Most will work directly in Bash, and I don't believe that any rely on Oh My Zsh, but your mileage may vary. There was a period when I was maintaining a shell dotfile for both zsh and Bash, but I did eventually give up on my `.bashrc`. + +### We're all mad here + +If you want the possibility of using the same dotfile across OS's, you'll want to give your dotfile a little smarts. +``` +### Mac Specifics +if [[ "$OSTYPE" == "darwin"* ]]; then +        # Mac-specific stuff here. +fi +``` + +For instance, I expect the Alt + arrow keys to move the cursor by the word rather than by a single space. To make this happen in [iTerm2][4] (my preferred shell), I add this snippet to the Mac-specific portion of my .zshrc: +``` +### Mac Specifics +if [[ "$OSTYPE" == "darwin"* ]]; then +        ### Mac cursor commands for iTerm2; map ctrl+arrows or alt+arrows to fast-move +        bindkey -e +        bindkey '^[[1;9C' forward-word +        bindkey '^[[1;9D' backward-word +        bindkey '\e\e[D' backward-word +        bindkey '\e\e[C' forward-word +fi +``` + +### What about Bob? + +While I came to love my shell dotfile, I didn't always want the same things available on my home machines as on my work machines. One way to solve this is to have supplementary dotfiles to use at home but not at work. Here's how I accomplished this: +``` +if [[ `egrep 'dnssuffix1|dnssuffix2' /etc/resolv.conf` ]]; then +        if [ -e $HOME/.work ] +                source $HOME/.work +        else +                echo "This looks like a work machine, but I can't find the ~/.work file" +        fi +fi +``` + +In this case, I key off of my work dns suffix (or multiple suffixes, depending on your situation) and source a separate file that makes my life at work a little better. + +### That thing you do + +Now is probably a good time to quit using the tilde (`~`) to represent your home directory when writing scripts. You'll find that there are some contexts where it's not recognized. Getting in the habit of using the environment variable `$HOME` will save you a lot of troubleshooting time and headaches later on. + +The logical extension would be to have OS-specific dotfiles to include if you are so inclined. + +### Memory, all alone in the moonlight + +I've written embarrassing amounts of shell, and I've come to the conclusion that I really don't want to write more. It's not that shell can't do what I need most of the time, but I find that if I'm writing shell, I'm probably slapping together a duct-tape solution rather than permanently solving the problem. + +Likewise, I hate memorizing things, and throughout my career, I have had to do radical context shifting during the course of a day. The practical consequence is that I've had to re-learn many things several times over the years. ("Wait... which for-loop structure does this language use?") + +So, every so often I decide that I'm tired of looking up how to do something again. One way that I improve my life is by adding aliases. + +A common scenario for anyone who works with systems is finding out what's taking up all of the disk. Unfortunately, I have never been able to remember this incantation, so I made a shell alias, creatively called `bigdirs`: +``` +alias bigdirs='du --max-depth=1 2> /dev/null | sort -n -r | head -n20' +``` + +While I could be less lazy and actually memorize it, well, that's just not the Unix way... + +### Typos, and the people who love them + +Another way that using shell aliases improves my life is by saving me from typos. I don't know why, but I've developed this nasty habit of typing a `w` after the sequence `ea`, so if I want to clear my terminal, I'll often type `cleawr`. Unfortunately, that doesn't mean anything to my shell. Until I add this little piece of gold: +``` +alias cleawr='clear' +``` + +In one instance of Windows having an equivalent, but better, command, I find myself typing `cls`. It's frustrating to see your shell throw up its hands, so I add: +``` +alias cls='clear' +``` + +Yes, I'm aware of `ctrl + l`, but I never use it. + +### Amuse yourself + +Work can be stressful. Sometimes you just need to have a little fun. If your shell doesn't know the command that it clearly should just do, maybe you want to shrug your shoulders right back at it! You can do this with a function: +``` +shrug() { echo "¯\_(ツ)_/¯"; } +``` + +If that doesn't work, maybe you need to flip a table: +``` +fliptable() { echo "(╯°□°)╯ ┻━┻"; } # Flip a table. Example usage: fsck -y /dev/sdb1 || fliptable +``` + +Imagine my chagrin and frustration when I needed to flip a desk and I couldn't remember what I had called it. So I added some more shell aliases: +``` +alias flipdesk='fliptable' +alias deskflip='fliptable' +alias tableflip='fliptable' +``` + +And sometimes you need to celebrate: +``` +disco() { +        echo "(•_•)" +        echo "<)   )╯" +        echo " /    \ " +        echo "" +        echo "\(•_•)" +        echo " (   (>" +        echo " /    \ " +        echo "" +        echo " (•_•)" +        echo "<)   )>" +        echo " /    \ " +} +``` + +Typically, I'll pipe the output of these commands to `pbcopy `and paste it into the relevant chat tool I'm using. + +I got this fun function from a Twitter account that I follow called "Command Line Magic:" [@climagic][5]. Since I live in Florida now, I'm very happy that this is the only snow in my life: +``` +snow() { +        clear;while :;do echo $LINES $COLUMNS $(($RANDOM%$COLUMNS));sleep 0.1;done|gawk '{a[$3]=0;for(x in a) {o=a[x];a[x]=a[x]+1;printf "\033[%s;%sH ",o,x;printf "\033[%s;%sH*\033[0;0H",a[x],x;}}' +} + +``` + +### Fun with functions + +We've seen some examples of functions that I use. Since few of these examples require an argument, they could be done as aliases. I use functions out of personal preference when it's more than a single short statement. + +At various times in my career, I've run [Graphite][6], an open-source, scalable, time-series metrics solution. There have been enough instances where I needed to transpose a metric path (delineated with periods) to a filesystem path (delineated with slashes), or vice versa, that it became useful to have dedicated functions for these tasks: +``` +# Useful for converting between Graphite metrics and file paths +function dottoslash() { +        echo $1 | sed 's/\./\//g' +} +function slashtodot() { +        echo $1 | sed 's/\//\./g' +} +``` + +During another time in my career, I was running a lot of Kubernetes. If you aren't familiar with running Kubernetes, you need to write a lot of YAML. Unfortunately, it's not hard to write invalid YAML. Worse, Kubernetes doesn't validate YAML before trying to apply it, so you won't find out it's invalid until you apply it. Unless you validate it first: +``` +function yamllint() { +        for i in $(find . -name '*.yml' -o -name '*.yaml'); do echo $i; ruby -e "require 'yaml';YAML.load_file(\"$i\")"; done +} +``` + +Because I got tired of embarrassing myself and occasionally breaking a customer's setup, I wrote this little snippet and added it as a pre-commit hook to all of my relevant repos. Something similar would be very helpful as part of your continuous integration process, especially if you're working as part of a team. + +### Oh, fingers, where art thou? + +I was once an excellent touch-typist. Those days are long gone. I typo more than I would have believed possible. + +At different times, I have used a fair amount of either Chef or Kubernetes. Fortunately for me, I never used both at the same time. + +Part of the Chef ecosystem is Test Kitchen, a suite of tools that facilitate testing, which is invoked with the commands `kitchen test`. Kubernetes is managed with a CLI tool `kubectl`. Both commands require several subcommands, and neither rolls off the fingers particularly fluidly. + +Rather than create a bunch of "typo aliases," I aliased those commands to `k`: +``` +alias k='kitchen test $@' +``` + +or +``` +alias k='kubectl $@' +``` + +### Timesplitters + +The last half of my career has involved writing more code with other people. I've worked in many environments where we have forked copies of repos on our account and use pull requests as part of the review process. When I want to make sure that my fork of a given repo is up to date with the parent, I use `fetchupstream`: +``` +alias fetchupstream='git fetch upstream && git checkout master && git merge upstream/master && git push' +``` + +### Mine eyes have seen the glory of the coming of color + +I like color. It can make things like diffs easier to use. +``` +alias diff='colordiff' +``` + +I thought that colorized man pages was a neat trick, so I incorporated this function: +``` +# Colorized man pages, from: +# http://boredzo.org/blog/archives/2016-08-15/colorized-man-pages-understood-and-customized +man() { +        env \ +                LESS_TERMCAP_md=$(printf "\e[1;36m") \ +                LESS_TERMCAP_me=$(printf "\e[0m") \ +                LESS_TERMCAP_se=$(printf "\e[0m") \ +                LESS_TERMCAP_so=$(printf "\e[1;44;33m") \ +                LESS_TERMCAP_ue=$(printf "\e[0m") \ +                LESS_TERMCAP_us=$(printf "\e[1;32m") \ +                man "$@" +} +``` + +I love the command `which`. It simply tells you where in the filesystem the command you're running comes from—unless it's a shell function. After multiple cascading dotfiles, sometimes it's not clear where a function is defined or what it does. It turns out that the `whence` and `type` commands can help with that. +``` +# Where is a function defined? +whichfunc() { +        whence -v $1 +        type -a $1 +} +``` + +### Conclusion + +I hope this article helps and inspires you to find ways to improve your daily shell-using experience. They don't need to be huge, novel, or complex. They might solve a minor but frequent bit of friction, create a shortcut, or even offer a solution to reducing common typos. + +You're welcome to look through my [dotfiles repo][7], but I warn you that it could use a lot of cleaning up. Feel free to use anything that you find helpful, and please be excellent to one another. + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/9/shell-dotfile + +作者:[H.Waldo Grunenwald][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://opensource.com/users/gwaldo +[1]: http://www.zsh.org/ +[2]: https://brew.sh/ +[3]: https://github.com/robbyrussell/oh-my-zsh +[4]: https://www.iterm2.com/ +[5]: https://twitter.com/climagic +[6]: https://github.com/graphite-project/ +[7]: https://github.com/gwaldo/dotfiles diff --git a/sources/tech/20180907 6 open source tools for writing a book.md b/sources/tech/20180907 6 open source tools for writing a book.md new file mode 100644 index 0000000000..3a2328e7f1 --- /dev/null +++ b/sources/tech/20180907 6 open source tools for writing a book.md @@ -0,0 +1,68 @@ +KevinSJ 翻译中 +6 open source tools for writing a book +====== + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/osdc-lead-austen-writing-code.png?itok=XPxRMtQ4) + +I first used and contributed to free and open source software in 1993, and since then I've been an open source software developer and evangelist. I've written or contributed to dozens of open source software projects, although the one that I'll be remembered for is the [FreeDOS Project][1], an open source implementation of the DOS operating system. + +I recently wrote a book about FreeDOS. [_Using FreeDOS_][2] is my celebration of the 24th anniversary of FreeDOS. It is a collection of how-to's about installing and using FreeDOS, essays about my favorite DOS applications, and quick-reference guides to the DOS command line and DOS batch programming. I've been working on this book for the last few months, with the help of a great professional editor. + +_Using FreeDOS_ is available under the Creative Commons Attribution (cc-by) International Public License. You can download the EPUB and PDF versions at no charge from the [FreeDOS e-books][2] website. (I'm also planning a print version, for those who prefer a bound copy.) + +The book was produced almost entirely with open source software. I'd like to share a brief insight into the tools I used to create, edit, and produce _Using FreeDOS_. + +### Google Docs + +[Google Docs][3] is the only tool I used that isn't open source software. I uploaded my first drafts to Google Docs so my editor and I could collaborate. I'm sure there are open source collaboration tools, but Google Doc's ability to let two people edit the same document at the same time, make comments, edit suggestions, and change tracking—not to mention its use of paragraph styles and the ability to download the finished document—made it a valuable part of the editing process. + +### LibreOffice + +I started on [LibreOffice][4] 6.0 but I finished the book using LibreOffice 6.1. I love LibreOffice's rich support of styles. Paragraph styles made it easy to apply a style for titles, headers, body text, sample code, and other text. Character styles let me modify the appearance of text within a paragraph, such as inline sample code or a different style to indicate a filename. Graphics styles let me apply certain styling to screenshots and other images. And page styles allowed me to easily modify the layout and appearance of the page. + +### GIMP + +My book includes a lot of DOS program screenshots, website screenshots, and FreeDOS logos. I used [GIMP][5] to modify these images for the book. Usually, this was simply cropping or resizing an image, but as I prepare the print edition of the book, I'm using GIMP to create a few images that will be simpler for print layout. + +### Inkscape + +Most of the FreeDOS logos and fish mascots are in SVG format, and I used [Inkscape][6] for any image tweaking here. And in preparing the PDF version of the ebook, I wanted a simple blue banner at top of the page, with the FreeDOS logo in the corner. After some experimenting, I found it easier to create an SVG image in Inkscape that looked like the banner I wanted, and I pasted that into the header. + +### ImageMagick + +While it's great to use GIMP to do the fine work, sometimes it's faster to run an [ImageMagick][7] command over a set of images, such as to convert into PNG format or to resize images. + +### Sigil + +LibreOffice can export directly to EPUB format, but it wasn't a great transfer. I haven't tried creating an EPUB with LibreOffice 6.1, but LibreOffice 6.0 didn't include my images. It also added styles in a weird way. I used [Sigil][8] to tweak the EPUB file and make everything look right. Sigil even has a preview function so you can see what the EPUB will look like. + +### QEMU + +Because this book is about installing and running FreeDOS, I needed to actually run FreeDOS. You can boot FreeDOS inside any PC emulator, including VirtualBox, QEMU, GNOME Boxes, PCem, and Bochs. But I like the simplicity of [QEMU][9]. And the QEMU console lets you issue a screen dump in PPM format, which is ideal for grabbing screenshots to include in the book. + +Of course, I have to mention running [GNOME][10] on [Linux][11]. I use the [Fedora][12] distribution of Linux. + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/9/writing-book-open-source-tools + +作者:[Jim Hall][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://opensource.com/users/jim-hall +[1]: http://www.freedos.org/ +[2]: http://www.freedos.org/ebook/ +[3]: https://www.google.com/docs/about/ +[4]: https://www.libreoffice.org/ +[5]: https://www.gimp.org/ +[6]: https://inkscape.org/ +[7]: https://www.imagemagick.org/ +[8]: https://sigil-ebook.com/ +[9]: https://www.qemu.org/ +[10]: https://www.gnome.org/ +[11]: https://www.kernel.org/ +[12]: https://getfedora.org/ diff --git a/sources/tech/20180907 How to Use the Netplan Network Configuration Tool on Linux.md b/sources/tech/20180907 How to Use the Netplan Network Configuration Tool on Linux.md new file mode 100644 index 0000000000..a9d3eb0895 --- /dev/null +++ b/sources/tech/20180907 How to Use the Netplan Network Configuration Tool on Linux.md @@ -0,0 +1,230 @@ +LuuMing translating +How to Use the Netplan Network Configuration Tool on Linux +====== + +![](https://www.linux.com/sites/lcom/files/styles/rendered_file/public/netplan.jpg?itok=Gu_ZfNGa) + +For years Linux admins and users have configured their network interfaces in the same way. For instance, if you’re a Ubuntu user, you could either configure the network connection via the desktop GUI or from within the /etc/network/interfaces file. The configuration was incredibly easy and never failed to work. The configuration within that file looked something like this: + +``` +auto enp10s0 + +iface enp10s0 inet static + +address 192.168.1.162 + +netmask 255.255.255.0 + +gateway 192.168.1.100 + +dns-nameservers 1.0.0.1,1.1.1.1 + +``` + +Save and close that file. Restart networking with the command: + +``` +sudo systemctl restart networking + +``` + +Or, if you’re not using a non-systemd distribution, you could restart networking the old fashioned way like so: + +``` +sudo /etc/init.d/networking restart + +``` + +Your network will restart and the newly configured interface is good to go. + +That’s how it’s been done for years. Until now. With certain distributions (such as Ubuntu Linux 18.04), the configuration and control of networking has changed considerably. Instead of that interfaces file and using the /etc/init.d/networking script, we now turn to [Netplan][1]. Netplan is a command line utility for the configuration of networking on certain Linux distributions. Netplan uses YAML description files to configure network interfaces and, from those descriptions, will generate the necessary configuration options for any given renderer tool. + +I want to show you how to use Netplan on Linux, to configure a static IP address and a DHCP address. I’ll be demonstrating on Ubuntu Server 18.04. I will give you one word of warning, the .yaml files you create for Netplan must be consistent in spacing, otherwise they’ll fail to work. You don’t have to use a specific spacing for each line, it just has to remain consistent. + +### The new configuration files + +Open a terminal window (or log into your Ubuntu Server via SSH). You will find the new configuration files for Netplan in the /etc/netplan directory. Change into that directory with the command cd /etc/netplan. Once in that directory, you will probably only see a single file: + +``` +01-netcfg.yaml + +``` + +You can create a new file or edit the default. If you opt to edit the default, I suggest making a copy with the command: + +``` +sudo cp /etc/netplan/01-netcfg.yaml /etc/netplan/01-netcfg.yaml.bak + +``` + +With your backup in place, you’re ready to configure. + +### Network Device Name + +Before you configure your static IP address, you’ll need to know the name of device to be configured. To do that, you can issue the command ip a and find out which device is to be used (Figure 1). + +![netplan][3] + +Figure 1: Finding our device name with the ip a command. + +[Used with permission][4] + +I’ll be configuring ens5 for a static IP address. + +### Configuring a Static IP Address + +Open the original .yaml file for editing with the command: + +``` +sudo nano /etc/netplan/01-netcfg.yaml + +``` + +The layout of the file looks like this: + +network: + +Version: 2 + +Renderer: networkd + +ethernets: + +DEVICE_NAME: + +Dhcp4: yes/no + +Addresses: [IP/NETMASK] + +Gateway: GATEWAY + +Nameservers: + +Addresses: [NAMESERVER, NAMESERVER] + +Where: + + * DEVICE_NAME is the actual device name to be configured. + + * yes/no is an option to enable or disable dhcp4. + + * IP is the IP address for the device. + + * NETMASK is the netmask for the IP address. + + * GATEWAY is the address for your gateway. + + * NAMESERVER is the comma-separated list of DNS nameservers. + + + + +Here’s a sample .yaml file: + +``` +network: + + version: 2 + + renderer: networkd + + ethernets: + + ens5: + + dhcp4: no + + addresses: [192.168.1.230/24] + + gateway4: 192.168.1.254 + + nameservers: + + addresses: [8.8.4.4,8.8.8.8] + +``` + +Edit the above to fit your networking needs. Save and close that file. + +Notice the netmask is no longer configured in the form 255.255.255.0. Instead, the netmask is added to the IP address. + +### Testing the Configuration + +Before we apply the change, let’s test the configuration. To do that, issue the command: + +``` +sudo netplan try + +``` + +The above command will validate the configuration before applying it. If it succeeds, you will see Configuration accepted. In other words, Netplan will attempt to apply the new settings to a running system. Should the new configuration file fail, Netplan will automatically revert to the previous working configuration. Should the new configuration work, it will be applied. + +### Applying the New Configuration + +If you are certain of your configuration file, you can skip the try option and go directly to applying the new options. The command for this is: + +``` +sudo netplan apply + +``` + +At this point, you can issue the command ip a to see that your new address configurations are in place. + +### Configuring DHCP + +Although you probably won’t be configuring your server for DHCP, it’s always good to know how to do this. For example, you might not know what static IP addresses are currently available on your network. You could configure the device for DHCP, get an IP address, and then reconfigure that address as static. + +To use DHCP with Netplan, the configuration file would look something like this: + +``` +network: + + version: 2 + + renderer: networkd + + ethernets: + + ens5: + + Addresses: [] + + dhcp4: true + + optional: true + +``` + +Save and close that file. Test the file with: + +``` +sudo netplan try + +``` + +Netplan should succeed and apply the DHCP configuration. You could then issue the ip a command, get the dynamically assigned address, and then reconfigure a static address. Or, you could leave it set to use DHCP (but seeing as how this is a server, you probably won’t want to do that). + +Should you have more than one interface, you could name the second .yaml configuration file 02-netcfg.yaml. Netplan will apply the configuration files in numerical order, so 01 will be applied before 02. Create as many configuration files as needed for your server. + +### That’s All There Is + +Believe it or not, that’s all there is to using Netplan. Although it is a significant change to how we’re accustomed to configuring network addresses, it’s not all that hard to get used to. But this style of configuration is here to stay… so you will need to get used to it. + +Learn more about Linux through the free ["Introduction to Linux" ][5]course from The Linux Foundation and edX. + +-------------------------------------------------------------------------------- + +via: https://www.linux.com/learn/intro-to-linux/2018/9/how-use-netplan-network-configuration-tool-linux + +作者:[Jack Wallen][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://www.linux.com/users/jlwallen +[1]: https://netplan.io/ +[3]: https://www.linux.com/sites/lcom/files/styles/rendered_file/public/netplan_1.jpg?itok=XuIsXWbV (netplan) +[4]: /licenses/category/used-permission +[5]: https://training.linuxfoundation.org/linux-courses/system-administration-training/introduction-to-linux diff --git a/sources/tech/20180910 How To List An Available Package Groups In Linux.md b/sources/tech/20180910 How To List An Available Package Groups In Linux.md new file mode 100644 index 0000000000..754c2d0c3a --- /dev/null +++ b/sources/tech/20180910 How To List An Available Package Groups In Linux.md @@ -0,0 +1,644 @@ +How To List An Available Package Groups In Linux +====== +As we know, if we want to install any packages in Linux we need to use the distribution package manager to get it done. + +Package manager is playing major role in Linux as this used most of the time by admin. + +If you would like to install group of package in one shot what would be the possible option. + +Is it possible in Linux? if so, what would be the command for it. + +Yes, this can be done in Linux by using the package manager. Each package manager has their own option to perform this task, as i know apt or apt-get package manager doesn’t has this option. + +For Debian based system we need to use tasksel command instead of official package managers called apt or apt-get. + +What is the benefit if we install group of package in Linux? Yes, there is lot of benefit is available in Linux when we install group of package because if you want to install LAMP separately we need to include so many packages but that can be done using single package when we use group of package command. + +Say for example, as you get a request from Application team to install LAMP but you don’t know what are the packages needs to be installed, this is where group of package comes into picture. + +Group option is a handy tool for Linux systems which will install Group of Software in a single click on your system without headache. + +A package group is a collection of packages that serve a common purpose, for instance System Tools or Sound and Video. Installing a package group pulls a set of dependent packages, saving time considerably. + +**Suggested Read :** +**(#)** [How To List Installed Packages By Size (Largest) On Linux][1] +**(#)** [How To View/List The Available Packages Updates In Linux][2] +**(#)** [How To View A Particular Package Installed/Updated/Upgraded/Removed/Erased Date On Linux][3] +**(#)** [How To View Detailed Information About A Package In Linux][4] +**(#)** [How To Search If A Package Is Available On Your Linux Distribution Or Not][5] +**(#)** [Newbies corner – A Graphical frontend tool for Linux Package Manager][6] +**(#)** [Linux Expert should knows, list of Command line Package Manager & Usage][7] + +### How To List An Available Package Groups In CentOS/RHEL Systems + +RHEL & CentOS systems are using RPM packages hence we can use the `Yum Package Manager` to get this information. + +YUM stands for Yellowdog Updater, Modified is an open-source command-line front-end package-management utility for RPM based systems such as Red Hat Enterprise Linux (RHEL) and CentOS. + +Yum is the primary tool for getting, installing, deleting, querying, and managing RPM packages from distribution repositories, as well as other third-party repositories. + +**Suggested Read :** [YUM Command To Manage Packages on RHEL/CentOS Systems][8] + +``` +# yum grouplist +Loaded plugins: fastestmirror, security +Setting up Group Process +Loading mirror speeds from cached hostfile + * epel: epel.mirror.constant.com +Installed Groups: + Base + E-mail server + Graphical Administration Tools + Hardware monitoring utilities + Legacy UNIX compatibility + Milkymist + Networking Tools + Performance Tools + Perl Support + Security Tools +Available Groups: + Additional Development + Backup Client + Backup Server + CIFS file server + Client management tools + Compatibility libraries + Console internet tools + Debugging Tools + Desktop +. +. +Available Language Groups: + Afrikaans Support [af] + Albanian Support [sq] + Amazigh Support [ber] + Arabic Support [ar] + Armenian Support [hy] + Assamese Support [as] + Azerbaijani Support [az] +. +. +Done + +``` + +If you would like to list what are the packages is associated on it, run the below command. In this example we are going to list what are the packages is associated with “Performance Tools” group. + +``` +# yum groupinfo "Performance Tools" +Loaded plugins: fastestmirror, security +Setting up Group Process +Loading mirror speeds from cached hostfile + * epel: ewr.edge.kernel.org + +Group: Performance Tools + Description: Tools for diagnosing system and application-level performance problems. + Mandatory Packages: + blktrace + sysstat + Default Packages: + dstat + iotop + latencytop + latencytop-tui + oprofile + perf + powertop + seekwatcher + Optional Packages: + oprofile-jit + papi + sdparm + sg3_utils + tiobench + tuned + tuned-utils + +``` + +### How To List An Available Package Groups In Fedora + +Fedora system uses DNF package manager hence we can use the Dnf Package Manager to get this information. + +DNF stands for Dandified yum. We can tell DNF, the next generation of yum package manager (Fork of Yum) using hawkey/libsolv library for backend. Aleš Kozumplík started working on DNF since Fedora 18 and its implemented/launched in Fedora 22 finally. + +Dnf command is used to install, update, search & remove packages on Fedora 22 and later system. It automatically resolve dependencies and make it smooth package installation without any trouble. + +Yum replaced by DNF due to several long-term problems in Yum which was not solved. Asked why ? he did not patches the Yum issues. Aleš Kozumplík explains that patching was technically hard and YUM team wont accept the changes immediately and other major critical, YUM is 56K lines but DNF is 29K lies. So, there is no option for further development, except to fork. + +**Suggested Read :** [DNF (Fork of YUM) Command To Manage Packages on Fedora System][9] + +``` +# dnf grouplist +Last metadata expiration check: 0:00:00 ago on Sun 09 Sep 2018 07:10:36 PM IST. +Available Environment Groups: + Fedora Custom Operating System + Minimal Install + Fedora Server Edition + Fedora Workstation + Fedora Cloud Server + KDE Plasma Workspaces + Xfce Desktop + LXDE Desktop + Hawaii Desktop + LXQt Desktop + Cinnamon Desktop + MATE Desktop + Sugar Desktop Environment + Development and Creative Workstation + Web Server + Infrastructure Server + Basic Desktop +Installed Groups: + C Development Tools and Libraries + Development Tools +Available Groups: + 3D Printing + Administration Tools + Ansible node + Audio Production + Authoring and Publishing + Books and Guides + Cloud Infrastructure + Cloud Management Tools + Container Management + D Development Tools and Libraries +. +. + RPM Development Tools + Security Lab + Text-based Internet + Window Managers + GNOME Desktop Environment + Graphical Internet + KDE (K Desktop Environment) + Fonts + Games and Entertainment + Hardware Support + Sound and Video + System Tools + +``` + +If you would like to list what are the packages is associated on it, run the below command. In this example we are going to list what are the packages is associated with “Editor” group. + +``` + +# dnf groupinfo Editors +Last metadata expiration check: 0:04:57 ago on Sun 09 Sep 2018 07:10:36 PM IST. + +Group: Editors + Description: Sometimes called text editors, these are programs that allow you to create and edit text files. This includes Emacs and Vi. + Optional Packages: + code-editor + cssed + emacs + emacs-auctex + emacs-bbdb + emacs-ess + emacs-vm + geany + gobby + jed + joe + leafpad + nedit + poedit + psgml + vim-X11 + vim-enhanced + xemacs + xemacs-packages-base + xemacs-packages-extra + xemacs-xft + xmlcopyeditor + zile +``` + +### How To List An Available Package Groups In openSUSE System + +openSUSE system uses zypper package manager hence we can use the zypper Package Manager to get this information. + +Zypper is a command line package manager for suse & openSUSE distributions. It’s used to install, update, search & remove packages & manage repositories, perform various queries, and more. Zypper command-line interface to ZYpp system management library (libzypp). + +**Suggested Read :** [Zypper Command To Manage Packages On openSUSE & suse Systems][10] + +``` +# zypper patterns +Loading repository data... +Warning: Repository 'Update Repository (Non-Oss)' appears to be outdated. Consider using a different mirror or server. +Warning: Repository 'Main Update Repository' appears to be outdated. Consider using a different mirror or server. +Reading installed packages... +S | Name | Version | Repository | Dependency +---|----------------------|---------------|-----------------------|----------- + | 64bit | 20150918-25.1 | Main Repository (OSS) | + | apparmor | 20150918-25.1 | Main Repository (OSS) | +i | apparmor | 20150918-25.1 | @System | + | base | 20150918-25.1 | Main Repository (OSS) | +i+ | base | 20150918-25.1 | @System | + | books | 20150918-25.1 | Main Repository (OSS) | + | console | 20150918-25.1 | Main Repository (OSS) | + | devel_C_C++ | 20150918-25.1 | Main Repository (OSS) | +i | enhanced_base | 20150918-25.1 | @System | + | enlightenment | 20150918-25.1 | Main Repository (OSS) | + | file_server | 20150918-25.1 | Main Repository (OSS) | + | fonts | 20150918-25.1 | Main Repository (OSS) | +i | fonts | 20150918-25.1 | @System | + | games | 20150918-25.1 | Main Repository (OSS) | +i | games | 20150918-25.1 | @System | + | gnome | 20150918-25.1 | Main Repository (OSS) | + | gnome_basis | 20150918-25.1 | Main Repository (OSS) | +i | imaging | 20150918-25.1 | @System | + | kde | 20150918-25.1 | Main Repository (OSS) | +i+ | kde | 20150918-25.1 | @System | + | kde_plasma | 20150918-25.1 | Main Repository (OSS) | +i | kde_plasma | 20150918-25.1 | @System | + | lamp_server | 20150918-25.1 | Main Repository (OSS) | + | laptop | 20150918-25.1 | Main Repository (OSS) | +i+ | laptop | 20150918-25.1 | @System | + | lxde | 20150918-25.1 | Main Repository (OSS) | + | lxqt | 20150918-25.1 | Main Repository (OSS) | +i | multimedia | 20150918-25.1 | @System | + | network_admin | 20150918-25.1 | Main Repository (OSS) | + | non_oss | 20150918-25.1 | Main Repository (OSS) | +i | non_oss | 20150918-25.1 | @System | + | office | 20150918-25.1 | Main Repository (OSS) | +i | office | 20150918-25.1 | @System | + | print_server | 20150918-25.1 | Main Repository (OSS) | + | remote_desktop | 20150918-25.1 | Main Repository (OSS) | + | x11 | 20150918-25.1 | Main Repository (OSS) | +i+ | x11 | 20150918-25.1 | @System | + | x86 | 20150918-25.1 | Main Repository (OSS) | + | xen_server | 20150918-25.1 | Main Repository (OSS) | + | xfce | 20150918-25.1 | Main Repository (OSS) | + | xfce_basis | 20150918-25.1 | Main Repository (OSS) | + | yast2_basis | 20150918-25.1 | Main Repository (OSS) | +i | yast2_basis | 20150918-25.1 | @System | + | yast2_install_wf | 20150918-25.1 | Main Repository (OSS) | +``` + +If you would like to list what are the packages is associated on it, run the below command. In this example we are going to list what are the packages is associated with “file_server” group. +Additionally zypper command allows a user to perform the same action with different options. + +``` +# zypper info file_server +Loading repository data... +Warning: Repository 'Update Repository (Non-Oss)' appears to be outdated. Consider using a different mirror or server. +Warning: Repository 'Main Update Repository' appears to be outdated. Consider using a different mirror or server. +Reading installed packages... + +Information for pattern file_server: +------------------------------------ +Repository : Main Repository (OSS) +Name : file_server +Version : 20150918-25.1 +Arch : x86_64 +Vendor : openSUSE +Installed : No +Visible to User : Yes +Summary : File Server +Description : + File services to host files so that they may be accessed or retrieved by other computers on the same network. This includes the FTP, SMB, and NFS protocols. +Contents : + S | Name | Type | Dependency + ---|-------------------------------|---------|------------ + i+ | patterns-openSUSE-base | package | Required + | patterns-openSUSE-file_server | package | Required + | nfs-kernel-server | package | Recommended + i | nfsidmap | package | Recommended + i | samba | package | Recommended + i | samba-client | package | Recommended + i | samba-winbind | package | Recommended + | tftp | package | Recommended + | vsftpd | package | Recommended + | yast2-ftp-server | package | Recommended + | yast2-nfs-server | package | Recommended + i | yast2-samba-server | package | Recommended + | yast2-tftp-server | package | Recommended +``` + +If you would like to list what are the packages is associated on it, run the below command. + +``` +# zypper pattern-info file_server +Loading repository data... +Warning: Repository 'Update Repository (Non-Oss)' appears to be outdated. Consider using a different mirror or server. +Warning: Repository 'Main Update Repository' appears to be outdated. Consider using a different mirror or server. +Reading installed packages... + + +Information for pattern file_server: +------------------------------------ +Repository : Main Repository (OSS) +Name : file_server +Version : 20150918-25.1 +Arch : x86_64 +Vendor : openSUSE +Installed : No +Visible to User : Yes +Summary : File Server +Description : + File services to host files so that they may be accessed or retrieved by other computers on the same network. This includes the FTP, SMB, and NFS protocols. +Contents : + S | Name | Type | Dependency + ---|-------------------------------|---------|------------ + i+ | patterns-openSUSE-base | package | Required + | patterns-openSUSE-file_server | package | Required + | nfs-kernel-server | package | Recommended + i | nfsidmap | package | Recommended + i | samba | package | Recommended + i | samba-client | package | Recommended + i | samba-winbind | package | Recommended + | tftp | package | Recommended + | vsftpd | package | Recommended + | yast2-ftp-server | package | Recommended + | yast2-nfs-server | package | Recommended + i | yast2-samba-server | package | Recommended + | yast2-tftp-server | package | Recommended +``` + +If you would like to list what are the packages is associated on it, run the below command. + +``` +# zypper info pattern file_server +Loading repository data... +Warning: Repository 'Update Repository (Non-Oss)' appears to be outdated. Consider using a different mirror or server. +Warning: Repository 'Main Update Repository' appears to be outdated. Consider using a different mirror or server. +Reading installed packages... + +Information for pattern file_server: +------------------------------------ +Repository : Main Repository (OSS) +Name : file_server +Version : 20150918-25.1 +Arch : x86_64 +Vendor : openSUSE +Installed : No +Visible to User : Yes +Summary : File Server +Description : + File services to host files so that they may be accessed or retrieved by other computers on the same network. This includes the FTP, SMB, and NFS protocols. +Contents : + S | Name | Type | Dependency + ---|-------------------------------|---------|------------ + i+ | patterns-openSUSE-base | package | Required + | patterns-openSUSE-file_server | package | Required + | nfs-kernel-server | package | Recommended + i | nfsidmap | package | Recommended + i | samba | package | Recommended + i | samba-client | package | Recommended + i | samba-winbind | package | Recommended + | tftp | package | Recommended + | vsftpd | package | Recommended + | yast2-ftp-server | package | Recommended + | yast2-nfs-server | package | Recommended + i | yast2-samba-server | package | Recommended + | yast2-tftp-server | package | Recommended +``` + +If you would like to list what are the packages is associated on it, run the below command. + +``` +# zypper info -t pattern file_server +Loading repository data... +Warning: Repository 'Update Repository (Non-Oss)' appears to be outdated. Consider using a different mirror or server. +Warning: Repository 'Main Update Repository' appears to be outdated. Consider using a different mirror or server. +Reading installed packages... + + +Information for pattern file_server: +------------------------------------ +Repository : Main Repository (OSS) +Name : file_server +Version : 20150918-25.1 +Arch : x86_64 +Vendor : openSUSE +Installed : No +Visible to User : Yes +Summary : File Server +Description : + File services to host files so that they may be accessed or retrieved by other computers on the same network. This includes the FTP, SMB, and NFS protocols. +Contents : + S | Name | Type | Dependency + ---|-------------------------------|---------|------------ + i+ | patterns-openSUSE-base | package | Required + | patterns-openSUSE-file_server | package | Required + | nfs-kernel-server | package | Recommended + i | nfsidmap | package | Recommended + i | samba | package | Recommended + i | samba-client | package | Recommended + i | samba-winbind | package | Recommended + | tftp | package | Recommended + | vsftpd | package | Recommended + | yast2-ftp-server | package | Recommended + | yast2-nfs-server | package | Recommended + i | yast2-samba-server | package | Recommended + | yast2-tftp-server | package | Recommended +``` + +### How To List An Available Package Groups In Debian/Ubuntu Systems + +Since APT or APT-GET package manager doesn’t offer this option for Debian/Ubuntu based systems hence, we are using tasksel command to get this information. + +[Tasksel][11] is a handy tool for Debian/Ubuntu systems which will install Group of Software in a single click on your system. Tasks are defined in `.desc` files and located at `/usr/share/tasksel`. + +By default, tasksel tool installed on Debian system as part of Debian installer but it’s not installed on Ubuntu desktop editions. This functionality is similar to that of meta-packages, like how package managers have. + +Tasksel tool offer a simple user interface based on zenity (popup Graphical dialog box in command line). + +**Suggested Read :** [Tasksel – Install Group of Software in A Single Click on Debian/Ubuntu][12] + +``` +# tasksel --list-task +u kubuntu-live Kubuntu live CD +u lubuntu-live-gtk Lubuntu live CD (GTK part) +u ubuntu-budgie-live Ubuntu Budgie live CD +u ubuntu-live Ubuntu live CD +u ubuntu-mate-live Ubuntu MATE Live CD +u ubuntustudio-dvd-live Ubuntu Studio live DVD +u vanilla-gnome-live Ubuntu GNOME live CD +u xubuntu-live Xubuntu live CD +u cloud-image Ubuntu Cloud Image (instance) +u dns-server DNS server +u kubuntu-desktop Kubuntu desktop +u kubuntu-full Kubuntu full +u lamp-server LAMP server +u lubuntu-core Lubuntu minimal installation +u lubuntu-desktop Lubuntu Desktop +u lubuntu-gtk-core Lubuntu minimal installation (GTK part) +u lubuntu-gtk-desktop Lubuntu Desktop (GTK part) +u lubuntu-qt-core Lubuntu minimal installation (Qt part) +u lubuntu-qt-desktop Lubuntu Qt Desktop (Qt part) +u mail-server Mail server +u postgresql-server PostgreSQL database +i print-server Print server +u samba-server Samba file server +u tomcat-server Tomcat Java server +u ubuntu-budgie-desktop Ubuntu Budgie desktop +i ubuntu-desktop Ubuntu desktop +u ubuntu-mate-core Ubuntu MATE minimal +u ubuntu-mate-desktop Ubuntu MATE desktop +i ubuntu-usb Ubuntu desktop USB +u ubuntustudio-audio Audio recording and editing suite +u ubuntustudio-desktop Ubuntu Studio desktop +u ubuntustudio-desktop-core Ubuntu Studio minimal DE installation +u ubuntustudio-fonts Large selection of font packages +u ubuntustudio-graphics 2D/3D creation and editing suite +u ubuntustudio-photography Photograph touchup and editing suite +u ubuntustudio-publishing Publishing applications +u ubuntustudio-video Video creation and editing suite +u vanilla-gnome-desktop Vanilla GNOME desktop +u xubuntu-core Xubuntu minimal installation +u xubuntu-desktop Xubuntu desktop +u openssh-server OpenSSH server +u server Basic Ubuntu server +``` + +If you would like to list what are the packages is associated on it, run the below command. In this example we are going to list what are the packages is associated with “file_server” group. + +``` +# tasksel --task-desc "lamp-server" +Selects a ready-made Linux/Apache/MySQL/PHP server. +``` + +### How To List An Available Package Groups In Arch Linux based Systems + +Arch Linux based systems are using pacman package manager hence we can use the pacman Package Manager to get this information. + +pacman stands for package manager utility (pacman). pacman is a command-line utility to install, build, remove and manage Arch Linux packages. pacman uses libalpm (Arch Linux Package Management (ALPM) library) as a back-end to perform all the actions. + +**Suggested Read :** [Pacman Command To Manage Packages On Arch Linux Based Systems][13] + +``` +# pacman -Sg +base-devel +base +multilib-devel +gnome-extra +kde-applications +kdepim +kdeutils +kdeedu +kf5 +kdemultimedia +gnome +plasma +kdegames +kdesdk +kdebase +xfce4 +fprint +kdegraphics +kdenetwork +kdeadmin +kf5-aids +kdewebdev +. +. +dlang-ldc +libretro +ring +lxqt +non-daw +non +alsa +qtcurve +realtime +sugar-fructose +tesseract-data +vim-plugins + +``` + +If you would like to list what are the packages is associated on it, run the below command. In this example we are going to list what are the packages is associated with “gnome” group. + +``` +# pacman -Sg gnome +gnome baobab +gnome cheese +gnome eog +gnome epiphany +gnome evince +gnome file-roller +gnome gdm +gnome gedit +gnome gnome-backgrounds +gnome gnome-calculator +gnome gnome-calendar +gnome gnome-characters +gnome gnome-clocks +gnome gnome-color-manager +gnome gnome-contacts +gnome gnome-control-center +gnome gnome-dictionary +gnome gnome-disk-utility +gnome gnome-documents +gnome gnome-font-viewer +. +. +gnome sushi +gnome totem +gnome tracker +gnome tracker-miners +gnome vino +gnome xdg-user-dirs-gtk +gnome yelp +gnome gnome-boxes +gnome gnome-software +gnome simple-scan + +``` + +Alternatively we can check the same by running following command. + +``` +# pacman -S gnome +:: There are 64 members in group gnome: +:: Repository extra + 1) baobab 2) cheese 3) eog 4) epiphany 5) evince 6) file-roller 7) gdm 8) gedit 9) gnome-backgrounds 10) gnome-calculator 11) gnome-calendar 12) gnome-characters 13) gnome-clocks + 14) gnome-color-manager 15) gnome-contacts 16) gnome-control-center 17) gnome-dictionary 18) gnome-disk-utility 19) gnome-documents 20) gnome-font-viewer 21) gnome-getting-started-docs + 22) gnome-keyring 23) gnome-logs 24) gnome-maps 25) gnome-menus 26) gnome-music 27) gnome-photos 28) gnome-screenshot 29) gnome-session 30) gnome-settings-daemon 31) gnome-shell + 32) gnome-shell-extensions 33) gnome-system-monitor 34) gnome-terminal 35) gnome-themes-extra 36) gnome-todo 37) gnome-user-docs 38) gnome-user-share 39) gnome-video-effects 40) grilo-plugins + 41) gvfs 42) gvfs-afc 43) gvfs-goa 44) gvfs-google 45) gvfs-gphoto2 46) gvfs-mtp 47) gvfs-nfs 48) gvfs-smb 49) mousetweaks 50) mutter 51) nautilus 52) networkmanager 53) orca 54) rygel + 55) sushi 56) totem 57) tracker 58) tracker-miners 59) vino 60) xdg-user-dirs-gtk 61) yelp +:: Repository community + 62) gnome-boxes 63) gnome-software 64) simple-scan + +Enter a selection (default=all): ^C +Interrupt signal received + +``` + +To know exactly how many packages is associated on it, run the following command. + +``` +# pacman -Sg gnome | wc -l +64 + +``` + +-------------------------------------------------------------------------------- + +via: https://www.2daygeek.com/how-to-list-an-available-package-groups-in-linux/ + +作者:[Prakash Subramanian][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://www.2daygeek.com/author/prakash/ +[1]: https://www.2daygeek.com/how-to-list-installed-packages-by-size-largest-on-linux/ +[2]: https://www.2daygeek.com/how-to-view-list-the-available-packages-updates-in-linux/ +[3]: https://www.2daygeek.com/how-to-view-a-particular-package-installed-updated-upgraded-removed-erased-date-on-linux/ +[4]: https://www.2daygeek.com/how-to-view-detailed-information-about-a-package-in-linux/ +[5]: https://www.2daygeek.com/how-to-search-if-a-package-is-available-on-your-linux-distribution-or-not/ +[6]: https://www.2daygeek.com/list-of-graphical-frontend-tool-for-linux-package-manager/ +[7]: https://www.2daygeek.com/list-of-command-line-package-manager-for-linux/ +[8]: https://www.2daygeek.com/yum-command-examples-manage-packages-rhel-centos-systems/ +[9]: https://www.2daygeek.com/dnf-command-examples-manage-packages-fedora-system/ +[10]: https://www.2daygeek.com/zypper-command-examples-manage-packages-opensuse-system/ +[11]: https://wiki.debian.org/tasksel +[12]: https://www.2daygeek.com/tasksel-install-group-of-software-in-a-single-click-or-single-command-on-debian-ubuntu/ +[13]: https://www.2daygeek.com/pacman-command-examples-manage-packages-arch-linux-system/ diff --git a/sources/tech/20180911 Know Your Storage- Block, File - Object.md b/sources/tech/20180911 Know Your Storage- Block, File - Object.md new file mode 100644 index 0000000000..186b41d41a --- /dev/null +++ b/sources/tech/20180911 Know Your Storage- Block, File - Object.md @@ -0,0 +1,63 @@ +translating by name1e5s +Know Your Storage: Block, File & Object +====== + +![](https://www.linux.com/sites/lcom/files/styles/rendered_file/public/block2_1920.jpg?itok=s1y6RLhT) + +Dealing with the tremendous amount of data generated today presents a big challenge for companies who create or consume such data. It’s a challenge for tech companies that are dealing with related storage issues. + +“Data is growing exponentially each year, and we find that the majority of data growth is due to increased consumption and industries adopting transformational projects to expand value. Certainly, the Internet of Things (IoT) has contributed greatly to data growth, but the key challenge for software-defined storage is how to address the use cases associated with data growth,” said Michael St. Jean, principal product marketing manager, Red Hat Storage. + +Every challenge is an opportunity. “The deluge of data being generated by old and new sources today is certainly presenting us with opportunities to meet our customers escalating needs in the areas of scale, performance, resiliency, and governance,” said Tad Brockway, General Manager for Azure Storage, Media and Edge. + +### Trinity of modern software-defined storage + +There are three different kinds of storage solutions -- block, file, and object -- each serving a different purpose while working with the others. + +Block storage is the oldest form of data storage, where data is stored in fixed-length blocks or chunks of data. Block storage is used in enterprise storage environments and usually is accessed using Fibre Channel or iSCSI interface. “Block storage requires an application to map where the data is stored on the storage device,” according to SUSE’s Larry Morris, Sr. Product Manager, Software Defined Storage. + +Block storage is virtualized in storage area network and software defined storage systems, which are abstracted logical devices that reside on a shared hardware infrastructure and are created and presented to the host operating system of a server, virtual server, or hypervisor via protocols like SCSI, SATA, SAS, FCP, FCoE, or iSCSI. + +“Block storage splits a single storage volume (like a virtual or cloud storage node, or a good old fashioned hard disk) into individual instances known as blocks,” said St. Jean. + +Each block exists independently and can be formatted with its own data transfer protocol and operating system — giving users complete configuration autonomy. Because block storage systems aren’t burdened with the same investigative file-finding duties as the file storage systems, block storage is a faster storage system. Pairing that speed with configuration flexibility makes block storage ideal for raw server storage or rich media databases. + +Block storage can be used to host operating systems, applications, databases, entire virtual machines and containers. Traditionally, block storage can only be accessed by individual machine, or machines in a cluster, to which it has been presented. + +### File-based storage + +File-based storage uses a filesystem to map where the data is stored on the storage device. It’s a dominant technology used on direct- and networked-attached storage system, and it takes care of two things: organizing data and representing it to users. “With file storage, data is arranged on the server side in the exact same format as the clients see it. This allows the user to request a file by some unique identifier — like a name, location, or URL — which is communicated to the storage system using specific data transfer protocols,” said St. Jean. + +The result is a type of hierarchical file structure that can be navigated from top to bottom. File storage is layered on top of block storage, allowing users to see and access data as files and folders, but restricting access to the blocks that stand up those files and folders. + +“File storage is typically represented by shared filesystems like NFS and CIFS/SMB that can be accessed by many servers over an IP network. Access can be controlled at a file, directory, and export level via user and group permissions. File storage can be used to store files needed by multiple users and machines, application binaries, databases, virtual machines, and can be used by containers,” explained Brockway. + +### Object storage + +Object storage is the newest form of data storage, and it provides a repository for unstructured data which separates the content from the indexing and allows the concatenation of multiple files into an object. An object is a piece of data paired with any associated metadata that provides context about the bytes contained within the object (things like how old or big the data is). Those two things together — the data and metadata — make an object. + +One advantage of object storage is the unique identifier associated with each piece of data. Accessing the data involves using the unique identifier and does not require the application or user to know where the data is actually stored. Object data is accessed through APIs. + +“The data stored in objects is uncompressed and unencrypted, and the objects themselves are arranged in object stores (a central repository filled with many other objects) or containers (a package that contains all of the files an application needs to run). Objects, object stores, and containers are very flat in nature — compared to the hierarchical structure of file storage systems — which allow them to be accessed very quickly at huge scale,” explained St. Jean. + +Object stores can scale to many petabytes to accommodate the largest datasets and are a great choice for images, audio, video, logs, backups, and data used by analytics services. + +### Conclusion + +Now you know about the various types of storage and how they are used. Stay tuned to learn more about software-defined storage as we examine the topic in the future. + +Join us at [Open Source Summit + Embedded Linux Conference Europe][1] in Edinburgh, UK on October 22-24, 2018, for 100+ sessions on Linux, Cloud, Containers, AI, Community, and more. + +-------------------------------------------------------------------------------- + +via: https://www.linux.com/blog/2018/9/know-your-storage-block-file-object + +作者:[Swapnil Bhartiya][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://www.linux.com/users/arnieswap +[1]: https://events.linuxfoundation.org/events/elc-openiot-europe-2018/ diff --git a/sources/tech/20180912 How subroutine signatures work in Perl 6.md b/sources/tech/20180912 How subroutine signatures work in Perl 6.md new file mode 100644 index 0000000000..79606380bd --- /dev/null +++ b/sources/tech/20180912 How subroutine signatures work in Perl 6.md @@ -0,0 +1,335 @@ +How subroutine signatures work in Perl 6 +====== +In the fourth article in this series comparing Perl 5 to Perl 6, learn how signatures work in Perl 6. + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/collab-team-pair-programming-code-keyboard2.png?itok=WnKfsl-G) + +In the [first article][1] in this series comparing Perl 5 to Perl 6, we looked into some of the issues you might encounter when migrating code into Perl 6. In the [second article][2], we examined how garbage collection works in Perl 6, and in the [third article][3], we looked at how containers replaced references in Perl 6. Here in the fourth article, we will focus on (subroutine) signatures in Perl 6 and how they differ from those in Perl 5. + +### Experimental signatures in Perl 5 + +If you're migrating from Perl 5 code to Perl 6, you're probably not using the [experimental signature feature][4] that became available in Perl 5.20 or any of the older CPAN modules like [signatures][5], [Function::Parameters][6], or any of the other Perl 5 modules on CPAN with ["signature" in their name][7]. + +Also, in my experience, [prototypes][8] haven't been used very often in the Perl programs out in the world (e.g., the [DarkPAN][9] ). + +For these reasons, I will compare Perl 6 functionality only with the most common use of "classic" Perl 5 argument passing. + +### Argument passing in Perl 5 + +All arguments you pass to a Perl 5 subroutine are flattened and put into the automatically defined `@_` array variable inside. That is basically all Perl 5 does with passing arguments to subroutines. Nothing more, nothing less. There are, however, several idioms in Perl 5 that take it from there. The most common (I would say "standard") idiom in my experience is: + +``` +# Perl 5 +sub do_something { +    my ($foo, $bar) = @_; +    # actually do something with $foo and $bar +} +``` + +This idiom performs a list assignment (copy) to two (new) lexical variables. This way of accessing the arguments to a subroutine is also supported in Perl 6, but it's intended just as a way to make migrations easier. + +If you expect a fixed number of arguments followed by a variable number of arguments, the following idiom is typically used: + +``` +# Perl 5 +sub do_something { +    my $foo = shift; +    my $bar = shift; +    for (@_) { +        # do something for each element in @_ +    } +}do_something +``` + +This idiom depends on the magic behavior of [shift][10], which shifts from `@_` in this context. If the subroutine is intended to be called as a method, something like this is usually seen: + +``` +# Perl 5 +sub do_something { +    my $self = shift; +    # do something with $self +}do_something +``` + +as the first argument passed is the [invocant][11] in Perl 5. + +By the way, this idiom can also be written in the first idiom: + +``` +# Perl 5 +sub do_something { +    my ($foo, $bar, @rest) = @_; +    for (@rest) { +        # do something for each element in @rest +    } +} +``` + +But that would be less efficient, as it would involve copying a potentially long list of values. + +The third idiom revolves on directly accessing the `@_` array. + +``` +# Perl 5 +sub sum_two { +    return $_[0] + $_[1];  # return the sum of the two parameters +}sum_two +``` + +This idiom is typically used for small, one-line subroutines, as it is one of the most efficient ways of handling arguments because no copying takes place. + +This idiom is also used if you want to change any variable that is passed as a parameter. Since the elements in `@_` are aliases to any variables specified (in Perl 6 you would say: "are bound to the variables"), it is possible to change the contents: + +``` +# Perl 5 +sub make42 { +    $_[0] = 42; +} +my $a = 666; +make42($a); +say $a;      # 42 +``` + +### Named arguments in Perl 5 + +Named arguments (as such) don't exist in Perl 5. But there is an often-used idiom that effectively mimics named arguments: + +``` +# Perl 5 +sub do_something { +    my %named = @_; +    if (exists %named{bar}) { +        # do stuff if named variable "bar" exists +    } +}do_somethingbar +``` + +This initializes the hash `%named` by alternately taking a key and a value from the `@_` array. If you call a subroutine with arguments using the fat-comma syntax: + +``` +# Perl 5 +frobnicate( bar => 42 ); +``` + +it will pass two values, `"foo"` and `42`, which will be placed into the `%named` hash as the value `42` associated with key `"foo"`. But the same thing would have happened if you had specified: + +``` +# Perl 5 +frobnicate( "bar", 42 ); +``` + +The `=>` is syntactic sugar for automatically quoting the left side. Otherwise, it functions just like a comma (hence the name "fat comma"). + +If a subroutine is called as a method with named arguments, this idiom is combined with the standard idiom: + +``` +# Perl 5 +sub do_something { +    my ($self, %named) = @_; +    # do something with $self and %named +} +``` + +alternatively: + +``` +# Perl 5 +sub do_something { +    my $self  = shift; +    my %named = @_; +    # do something with $self and %named +}do_something +``` + +### Argument passing in Perl 6 + +In their simplest form, subroutine signatures in Perl 6 are very much like the "standard" idiom of Perl 5. But instead of being part of the code, they are part of the definition of the subroutine, and you don't need to do the assignment: + +``` +# Perl 6 +sub do-something($foo, $bar) { +    # actually do something with $foo and $bar +} +``` + +versus: + +``` +# Perl 5 +sub do_something { +    my ($foo, $bar) = @_; +    # actually do something with $foo and $bar +} +``` + +In Perl 6, the `($foo, $bar)` part is called the signature of the subroutine. + +Since Perl 6 has an actual `method` keyword, it is not necessary to take the invocant into account, as that is automatically available with the `self` term: + +``` +# Perl 6 +class Foo { +    method do-something-else($foo, $bar) { +        # do something else with self, $foo and $bar +    } +} +``` + +Such parameters are called positional parameters in Perl 6. Unless indicated otherwise, positional parameters must be specified when calling the subroutine. + +If you need the aliasing behavior of using `$_[0]` directly in Perl 5, you can mark the parameter as writable by specifying the `is rw` trait: + +``` +# Perl 6 +sub make42($foo is rw) { +    $foo = 42; +} +my $a = 666; +make42($a); +say $a;      # 42 +``` + +When you pass an array as an argument to a subroutine, it doesn't get flattened in Perl 6. You only need to accept an array as an array in the signature: + +``` +# Perl 6 +sub handle-array(@a) { +    # do something with @a +} +my @foo = "a" .. "z"; +handle-array(@foo); +``` + +You can pass any number of arrays: + +``` +# Perl 6 +sub handle-two-arrays(@a, @b) { +    # do something with @a and @b +} +my @bar = 1..26; +handle-two-arrays(@foo, @bar); +``` + +If you want the ([variadic][12]) flattening semantics of Perl 5, you can indicate this with a so-called "slurpy array" by prefixing the array with an asterisk in the signature: + +``` +# Perl 6 +sub slurp-an-array(*@values) { +    # do something with @values +} +slurp-an-array("foo", 42, "baz");slurpanarrayslurpanarray +``` + +A slurpy array can occur only as the last positional parameter in a signature. + +If you prefer to use the Perl 5 way of specifying parameters in Perl 6, you can do this by specifying a slurpy array `*@_` in the signature: + +``` +# Perl 6 +sub do-like-5(*@_) { +    my ($foo, $bar) = @_; +} +``` + +### Named arguments in Perl 6 + +On the calling side, named arguments in Perl 6 can be expressed very similarly to how they are expressed in Perl 5: + +``` +# Perl 5 and Perl 6 +frobnicate( bar => 42 ); +``` + +However, on the definition side of the subroutine, things are very different: + +``` +# Perl 6 +sub frobnicate(:$bar) { +    # do something with $bar +} +``` + +The difference between an ordinary (positional) parameter and a named parameter is the colon, which precedes the [sigil][13] and the variable name in the definition: + +``` +$foo      # positional parameter, receives in $foo +:$bar     # named parameter "bar", receives in $bar +``` + +Unless otherwise specified, named parameters are optional. If a named argument is not specified, the associated variable will contain the default value, which usually is the type object `Any`. + +If you want to catch any (other) named arguments, you can use a so-called "slurpy hash." Just like the slurpy array, it is indicated with an asterisk before a hash: + +``` +# Perl 6 +sub slurp-nameds(*%nameds) { +    say "Received: " ~ join ", ", sort keys %nameds; +} +slurp-nameds(foo => 42, bar => 666); # Received: bar, fooslurpnamedssayslurpnamedsfoobar +``` + +As with the slurpy array, there can be only one slurpy hash in a signature, and it must be specified after any other named parameters. + +Often you want to pass a named argument to a subroutine from a variable with the same name. In Perl 5 this looks like: `do_something(bar => $bar)`. In Perl 6, you can specify this in the same way: `do-something(bar => $bar)`. But you can also use a shortcut: `do-something(:$bar)`. This means less typing–and less chance of typos. + +### Default values in Perl 6 + +Perl 5 has the following idiom for making parameters optional with a default value: + +``` +# Perl 5 +sub dosomething_with_defaults { +    my $foo = @_ ? shift : 42; +    my $bar = @_ ? shift : 666; +    # actually do something with $foo and $bar +}dosomething_with_defaults +``` + +In Perl 6, you can specify default values as part of the signature by specifying an equal sign and an expression: + +``` +# Perl 6 +sub dosomething-with-defaults($foo = 42, :$bar = 666) { +    # actually do something with $foo and $bar +} +``` + +Positional parameters become optional if a default value is specified for them. Named parameters stay optional regardless of any default value. + +### Summary + +Perl 6 has a way of describing how arguments to a subroutine should be captured into parameters of that subroutine. Positional parameters are indicated by their name and the appropriate sigil (e.g., `$foo`). Named parameters are prefixed with a colon (e.g. `:$bar`). Positional parameters can be marked as `is rw` to allow changing variables in the caller's scope. + +Positional arguments can be flattened in a slurpy array, which is prefixed by an asterisk (e.g., `*@values`). Unexpected named arguments can be collected using a slurpy hash, which is also prefixed with an asterisk (e.g., `*%nameds`). + +Default values can be specified inside the signature by adding an expression after an equal sign (e.g., `$foo = 42`), which makes that parameter optional. + +Signatures in Perl 6 have many other interesting features, aside from the ones summarized here; if you want to know more about them, check out the Perl 6 [signature object documentation][14]. + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/9/signatures-perl-6 + +作者:[Elizabeth Mattijsen][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://opensource.com/users/lizmat +[1]: https://opensource.com/article/18/7/migrating-perl-5-perl-6 +[2]: https://opensource.com/article/18/7/garbage-collection-perl-6 +[3]: https://opensource.com/article/18/7/containers-perl-6 +[4]: https://metacpan.org/pod/distribution/perl/pod/perlsub.pod#Signatures +[5]: https://metacpan.org/pod/signatures +[6]: https://metacpan.org/pod/Function::Parameters +[7]: https://metacpan.org/search?q=signature +[8]: https://metacpan.org/pod/perlsub#Prototypes +[9]: http://modernperlbooks.com/mt/2009/02/the-darkpan-dependency-management-and-support-problem.html +[10]: https://perldoc.perl.org/functions/shift.html +[11]: https://docs.perl6.org/routine/invocant +[12]: https://en.wikipedia.org/wiki/Variadic_function +[13]: https://www.perl.com/article/on-sigils/ +[14]: https://docs.perl6.org/type/Signature diff --git a/sources/tech/20180912 How to build rpm packages.md b/sources/tech/20180912 How to build rpm packages.md new file mode 100644 index 0000000000..3d14a8c797 --- /dev/null +++ b/sources/tech/20180912 How to build rpm packages.md @@ -0,0 +1,397 @@ +translating by Flowsnow + +How to build rpm packages +====== + +Save time and effort installing files and scripts across multiple hosts. + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/OSDC_gift_giveaway_box_520x292.png?itok=w1YQhNH1) + +I have used rpm-based package managers to install software on Red Hat and Fedora Linux since I started using Linux more than 20 years ago. I have used the **rpm** program itself, **yum** , and **DNF** , which is a close descendant of yum, to install and update packages on my Linux hosts. The yum and DNF tools are wrappers around the rpm utility that provide additional functionality, such as the ability to find and install package dependencies. + +Over the years I have created a number of Bash scripts, some of which have separate configuration files, that I like to install on most of my new computers and virtual machines. It reached the point that it took a great deal of time to install all of these packages, so I decided to automate that process by creating an rpm package that I could copy to the target hosts and install all of these files in their proper locations. Although the **rpm** tool was formerly used to build rpm packages, that function was removed and a new tool,was created to build new rpms. + +When I started this project, I found very little information about creating rpm packages, but I managed to find a book, Maximum RPM, that helped me figure it out. That book is now somewhat out of date, as is the vast majority of information I have found. It is also out of print, and used copies go for hundreds of dollars. The online version of [Maximum RPM][1] is available at no charge and is kept up to date. The [RPM website][2] also has links to other websites that have a lot of documentation about rpm. What other information there is tends to be brief and apparently assumes that you already have a good deal of knowledge about the process. + +In addition, every one of the documents I found assumes that the code needs to be compiled from sources as in a development environment. I am not a developer. I am a sysadmin, and we sysadmins have different needs because we don’t—or we shouldn’t—compile code to use for administrative tasks; we should use shell scripts. So we have no source code in the sense that it is something that needs to be compiled into binary executables. What we have is a source that is also the executable. + +For the most part, this project should be performed as the non-root user student. Rpms should never be built by root, but only by non-privileged users. I will indicate which parts should be performed as root and which by a non-root, unprivileged user. + +### Preparation + +First, open one terminal session and `su` to root. Be sure to use the `-` option to ensure that the complete root environment is enabled. I do not believe that sysadmins should use `sudo` for any administrative tasks. Find out why in my personal blog post: [Real SysAdmins don’t sudo][3]. + +``` +[student@testvm1 ~]$ su - +Password: +[root@testvm1 ~]# +``` + +Create a student user that can be used for this project and set a password for that user. + +``` +[root@testvm1 ~]# useradd -c "Student User" student +[root@testvm1 ~]# passwd student +Changing password for user student. +New password: +Retype new password: +passwd: all authentication tokens updated successfully. +[root@testvm1 ~]# +``` + +Building rpm packages requires the `rpm-build` package, which is likely not already installed. Install it now as root. Note that this command will also install several dependencies. The number may vary, depending upon the packages already installed on your host; it installed a total of 17 packages on my test VM, which is pretty minimal. + +``` +dnf install -y rpm-build +``` + +The rest of this project should be performed as the user student unless otherwise explicitly directed. Open another terminal session and use `su` to switch to that user to perform the rest of these steps. Download a tarball that I have prepared of a development directory structure, utils.tar, from GitHub using the following command: + +``` +wget https://github.com/opensourceway/how-to-rpm/raw/master/utils.tar +``` + +This tarball includes all of the files and Bash scripts that will be installed by the final rpm. There is also a complete spec file, which you can use to build the rpm. We will go into detail about each section of the spec file. + +As user student, using your home directory as your present working directory (pwd), untar the tarball. + +``` +[student@testvm1 ~]$ cd ; tar -xvf utils.tar +``` + +Use the `tree` command to verify that the directory structure of ~/development and the contained files looks like the following output: + +``` +[student@testvm1 ~]$ tree development/ +development/ +├── license +│   ├── Copyright.and.GPL.Notice.txt +│   └── GPL_LICENSE.txt +├── scripts +│   ├── create_motd +│   ├── die +│   ├── mymotd +│   └── sysdata +└── spec +    └── utils.spec + +3 directories, 7 files +[student@testvm1 ~]$ +``` + +The `mymotd` script creates a “Message Of The Day” data stream that is sent to stdout. The `create_motd` script runs the `mymotd` scripts and redirects the output to the /etc/motd file. This file is used to display a daily message to users who log in remotely using SSH. + +The `die` script is my own script that wraps the `kill` command in a bit of code that can find running programs that match a specified string and kill them. It uses `kill -9` to ensure that they cannot ignore the kill message. + +The `sysdata` script can spew tens of thousands of lines of data about your computer hardware, the installed version of Linux, all installed packages, and the metadata of your hard drives. I use it to document the state of a host at a point in time. I can later use it for reference. I used to do this to maintain a record of hosts that I installed for customers. + +You may need to change ownership of these files and directories to student.student. Do this, if necessary, using the following command: + +``` +chown -R student.student development +``` + +Most of the files and directories in this tree will be installed on Fedora systems by the rpm you create during this project. + +### Creating the build directory structure + +The `rpmbuild` command requires a very specific directory structure. You must create this directory structure yourself because no automated way is provided. Create the following directory structure in your home directory: + +``` +~ ─ rpmbuild +    ├── RPMS +    │   └── noarch +    ├── SOURCES +    ├── SPECS +    └── SRPMS +``` + +We will not create the rpmbuild/RPMS/X86_64 directory because that would be architecture-specific for 64-bit compiled binaries. We have shell scripts that are not architecture-specific. In reality, we won’t be using the SRPMS directory either, which would contain source files for the compiler. + +### Examining the spec file + +Each spec file has a number of sections, some of which may be ignored or omitted, depending upon the specific circumstances of the rpm build. This particular spec file is not an example of a minimal file required to work, but it is a good example of a moderately complex spec file that packages files that do not need to be compiled. If a compile were required, it would be performed in the `%build` section, which is omitted from this spec file because it is not required. + +#### Preamble + +This is the only section of the spec file that does not have a label. It consists of much of the information you see when the command `rpm -qi [Package Name]` is run. Each datum is a single line which consists of a tag, which identifies it and text data for the value of the tag. + +``` +############################################################################### +# Spec file for utils +################################################################################ +# Configured to be built by user student or other non-root user +################################################################################ +# +Summary: Utility scripts for testing RPM creation +Name: utils +Version: 1.0.0 +Release: 1 +License: GPL +URL: http://www.both.org +Group: System +Packager: David Both +Requires: bash +Requires: screen +Requires: mc +Requires: dmidecode +BuildRoot: ~/rpmbuild/ + +# Build with the following syntax: +# rpmbuild --target noarch -bb utils.spec +``` + +Comment lines are ignored by the `rpmbuild` program. I always like to add a comment to this section that contains the exact syntax of the `rpmbuild` command required to create the package. The Summary tag is a short description of the package. The Name, Version, and Release tags are used to create the name of the rpm file, as in utils-1.00-1.rpm. Incrementing the release and version numbers lets you create rpms that can be used to update older ones. + +The License tag defines the license under which the package is released. I always use a variation of the GPL. Specifying the license is important to clarify the fact that the software contained in the package is open source. This is also why I included the license and GPL statement in the files that will be installed. + +The URL is usually the web page of the project or project owner. In this case, it is my personal web page. + +The Group tag is interesting and is usually used for GUI applications. The value of the Group tag determines which group of icons in the applications menu will contain the icon for the executable in this package. Used in conjunction with the Icon tag (which we are not using here), the Group tag allows adding the icon and the required information to launch a program into the applications menu structure. + +The Packager tag is used to specify the person or organization responsible for maintaining and creating the package. + +The Requires statements define the dependencies for this rpm. Each is a package name. If one of the specified packages is not present, the DNF installation utility will try to locate it in one of the defined repositories defined in /etc/yum.repos.d and install it if it exists. If DNF cannot find one or more of the required packages, it will throw an error indicating which packages are missing and terminate. + +The BuildRoot line specifies the top-level directory in which the `rpmbuild` tool will find the spec file and in which it will create temporary directories while it builds the package. The finished package will be stored in the noarch subdirectory that we specified earlier. The comment showing the command syntax used to build this package includes the option `–target noarch`, which defines the target architecture. Because these are Bash scripts, they are not associated with a specific CPU architecture. If this option were omitted, the build would be targeted to the architecture of the CPU on which the build is being performed. + +The `rpmbuild` program can target many different architectures, and using the `--target` option allows us to build architecture-specific packages on a host with a different architecture from the one on which the build is performed. So I could build a package intended for use on an i686 architecture on an x86_64 host, and vice versa. + +Change the packager name to yours and the URL to your own website if you have one. + +#### %description + +The `%description` section of the spec file contains a description of the rpm package. It can be very short or can contain many lines of information. Our `%description` section is rather terse. + +``` +%description +A collection of utility scripts for testing RPM creation. +``` + +#### %prep + +The `%prep` section is the first script that is executed during the build process. This script is not executed during the installation of the package. + +This script is just a Bash shell script. It prepares the build directory, creating directories used for the build as required and copying the appropriate files into their respective directories. This would include the sources required for a complete compile as part of the build. + +The $RPM_BUILD_ROOT directory represents the root directory of an installed system. The directories created in the $RPM_BUILD_ROOT directory are fully qualified paths, such as /user/local/share/utils, /usr/local/bin, and so on, in a live filesystem. + +In the case of our package, we have no pre-compile sources as all of our programs are Bash scripts. So we simply copy those scripts and other files into the directories where they belong in the installed system. + +``` +%prep +################################################################################ +# Create the build tree and copy the files from the development directories    # +# into the build tree.                                                         # +################################################################################ +echo "BUILDROOT = $RPM_BUILD_ROOT" +mkdir -p $RPM_BUILD_ROOT/usr/local/bin/ +mkdir -p $RPM_BUILD_ROOT/usr/local/share/utils + +cp /home/student/development/utils/scripts/* $RPM_BUILD_ROOT/usr/local/bin +cp /home/student/development/utils/license/* $RPM_BUILD_ROOT/usr/local/share/utils +cp /home/student/development/utils/spec/* $RPM_BUILD_ROOT/usr/local/share/utils + +exit +``` + +Note that the exit statement at the end of this section is required. + +#### %files + +This section of the spec file defines the files to be installed and their locations in the directory tree. It also specifies the file attributes and the owner and group owner for each file to be installed. The file permissions and ownerships are optional, but I recommend that they be explicitly set to eliminate any chance for those attributes to be incorrect or ambiguous when installed. Directories are created as required during the installation if they do not already exist. + +``` +%files +%attr(0744, root, root) /usr/local/bin/* +%attr(0644, root, root) /usr/local/share/utils/* +``` + +#### %pre + +This section is empty in our lab project’s spec file. This would be the place to put any scripts that are required to run during installation of the rpm but prior to the installation of the files. + +#### %post + +This section of the spec file is another Bash script. This one runs after the installation of files. This section can be pretty much anything you need or want it to be, including creating files, running system commands, and restarting services to reinitialize them after making configuration changes. The `%post` script for our rpm package performs some of those tasks. + +``` +%post +################################################################################ +# Set up MOTD scripts                                                          # +################################################################################ +cd /etc +# Save the old MOTD if it exists +if [ -e motd ] +then +   cp motd motd.orig +fi +# If not there already, Add link to create_motd to cron.daily +cd /etc/cron.daily +if [ ! -e create_motd ] +then +   ln -s /usr/local/bin/create_motd +fi +# create the MOTD for the first time +/usr/local/bin/mymotd > /etc/motd +``` + +The comments included in this script should make its purpose clear. + +#### %postun + +This section contains a script that would be run after the rpm package is uninstalled. Using rpm or DNF to remove a package removes all of the files listed in the `%files` section, but it does not remove files or links created by the `%post` section, so we need to handle that in this section. + +This script usually consists of cleanup tasks that simply erasing the files previously installed by the rpm cannot accomplish. In the case of our package, it includes removing the link created by the `%post` script and restoring the saved original of the motd file. + +``` +%postun +# remove installed files and links +rm /etc/cron.daily/create_motd + +# Restore the original MOTD if it was backed up +if [ -e /etc/motd.orig ] +then +   mv -f /etc/motd.orig /etc/motd +fi +``` + +#### %clean + +This Bash script performs cleanup after the rpm build process. The two lines in the `%clean` section below remove the build directories created by the `rpm-build` command. In many cases, additional cleanup may also be required. + +``` +%clean +rm -rf $RPM_BUILD_ROOT/usr/local/bin +rm -rf $RPM_BUILD_ROOT/usr/local/share/utils +``` + +#### %changelog + +This optional text section contains a list of changes to the rpm and files it contains. The newest changes are recorded at the top of this section. + +``` +%changelog +* Wed Aug 29 2018 Your Name +  - The original package includes several useful scripts. it is +    primarily intended to be used to illustrate the process of +    building an RPM. +``` + +Replace the data in the header line with your own name and email address. + +### Building the rpm + +The spec file must be in the SPECS directory of the rpmbuild tree. I find it easiest to create a link to the actual spec file in that directory so that it can be edited in the development directory and there is no need to copy it to the SPECS directory. Make the SPECS directory your pwd, then create the link. + +``` +cd ~/rpmbuild/SPECS/ +ln -s ~/development/spec/utils.spec +``` + +Run the following command to build the rpm. It should only take a moment to create the rpm if no errors occur. + +``` +rpmbuild --target noarch -bb utils.spec +``` + +Check in the ~/rpmbuild/RPMS/noarch directory to verify that the new rpm exists there. + +``` +[student@testvm1 ~]$ cd rpmbuild/RPMS/noarch/ +[student@testvm1 noarch]$ ll +total 24 +-rw-rw-r--. 1 student student 24364 Aug 30 10:00 utils-1.0.0-1.noarch.rpm +[student@testvm1 noarch]$ +``` + +### Testing the rpm + +As root, install the rpm to verify that it installs correctly and that the files are installed in the correct directories. The exact name of the rpm will depend upon the values you used for the tags in the Preamble section, but if you used the ones in the sample, the rpm name will be as shown in the sample command below: + +``` +[root@testvm1 ~]# cd /home/student/rpmbuild/RPMS/noarch/ +[root@testvm1 noarch]# ll +total 24 +-rw-rw-r--. 1 student student 24364 Aug 30 10:00 utils-1.0.0-1.noarch.rpm +[root@testvm1 noarch]# rpm -ivh utils-1.0.0-1.noarch.rpm +Preparing...                          ################################# [100%] +Updating / installing... +   1:utils-1.0.0-1                    ################################# [100%] +``` + +Check /usr/local/bin to ensure that the new files are there. You should also verify that the create_motd link in /etc/cron.daily has been created. + +Use the `rpm -q --changelog utils` command to view the changelog. View the files installed by the package using the `rpm -ql utils` command (that is a lowercase L in `ql`.) + +``` +[root@testvm1 noarch]# rpm -q --changelog utils +* Wed Aug 29 2018 Your Name +- The original package includes several useful scripts. it is +    primarily intended to be used to illustrate the process of +    building an RPM. + +[root@testvm1 noarch]# rpm -ql utils +/usr/local/bin/create_motd +/usr/local/bin/die +/usr/local/bin/mymotd +/usr/local/bin/sysdata +/usr/local/share/utils/Copyright.and.GPL.Notice.txt +/usr/local/share/utils/GPL_LICENSE.txt +/usr/local/share/utils/utils.spec +[root@testvm1 noarch]# +``` + +Remove the package. + +``` +rpm -e utils +``` + +### Experimenting + +Now you will change the spec file to require a package that does not exist. This will simulate a dependency that cannot be met. Add the following line immediately under the existing Requires line: + +``` +Requires: badrequire +``` + +Build the package and attempt to install it. What message is displayed? + +We used the `rpm` command to install and delete the `utils` package. Try installing the package with yum or DNF. You must be in the same directory as the package or specify the full path to the package for this to work. + +### Conclusion + +There are many tags and a couple sections that we did not cover in this look at the basics of creating an rpm package. The resources listed below can provide more information. Building rpm packages is not difficult; you just need the right information. I hope this helps you—it took me months to figure things out on my own. + +We did not cover building from source code, but if you are a developer, that should be a simple step from this point. + +Creating rpm packages is another good way to be a lazy sysadmin and save time and effort. It provides an easy method for distributing and installing the scripts and other files that we as sysadmins need to install on many hosts. + +### Resources + + * Edward C. Baily, Maximum RPM, Sams Publishing, 2000, ISBN 0-672-31105-4 + + * Edward C. Baily, [Maximum RPM][1], updated online version + + * [RPM Documentation][4]: This web page lists most of the available online documentation for rpm. It includes many links to other websites and information about rpm. + + + + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/9/how-build-rpm-packages + +作者:[David Both][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://opensource.com/users/dboth +[1]: http://ftp.rpm.org/max-rpm/ +[2]: http://rpm.org/index.html +[3]: http://www.both.org/?p=960 +[4]: http://rpm.org/documentation.html diff --git a/sources/tech/20180912 How to turn on an LED with Fedora IoT.md b/sources/tech/20180912 How to turn on an LED with Fedora IoT.md new file mode 100644 index 0000000000..007cfc27ab --- /dev/null +++ b/sources/tech/20180912 How to turn on an LED with Fedora IoT.md @@ -0,0 +1,201 @@ +How to turn on an LED with Fedora IoT +====== + +![](https://fedoramagazine.org/wp-content/uploads/2018/08/LED-IoT-816x345.jpg) + +Do you enjoy running Fedora, containers, and have a Raspberry Pi? What about using all three together to play with LEDs? This article introduces Fedora IoT and shows you how to install a preview image on a Raspberry Pi. You’ll also learn how to interact with GPIO in order to light up an LED. + +### What is Fedora IoT? + +Fedora IoT is one of the current Fedora Project objectives, with a plan to become a full Fedora Edition. The result will be a system that runs on ARM (aarch64 only at the moment) devices such as the Raspberry Pi, as well as on the x86_64 architecture. + +![][1] + +Fedora IoT is based on OSTree, like [Fedora Silverblue][2] and the former [Atomic Host][3]. + +### Download and install Fedora IoT + +The official Fedora IoT images are coming with the Fedora 29 release. However, in the meantime you can download a [Fedora 28-based image][4] for this experiment. + +You have two options to install the system: either flash the SD card using a dd command, or use a fedora-arm-installer tool. The Fedora Wiki offers more information about [setting up a physical device][5] for IoT. Also, remember that you might need to resize the third partition. + +Once you insert the SD card into the device, you’ll need to complete the installation by creating a user. This step requires either a serial connection, or a HDMI display with a keyboard to interact with the device. + +When the system is installed and ready, the next step is to configure a network connection. Log in to the system with the user you have just created choose one of the following options: + + * If you need to configure your network manually, run a command similar to the following. Remember to use the right addresses for your network: +``` + $ nmcli connection add con-name cable ipv4.addresses \ + 192.168.0.10/24 ipv4.gateway 192.168.0.1 \ + connection.autoconnect true ipv4.dns "8.8.8.8,1.1.1.1" \ + type ethernet ifname eth0 ipv4.method manual + +``` + + * If there’s a DHCP service on your network, run a command like this: + +``` + $ nmcli con add type ethernet con-name cable ifname eth0 +``` + + + + +### **The GPIO interface in Fedora** + +Many tutorials about GPIO on Linux focus on a legacy GPIO sysfis interface. This interface is deprecated, and the upstream Linux kernel community plan to remove it completely, due to security and other issues. + +The Fedora kernel is already compiled without this legacy interface, so there’s no /sys/class/gpio on the system. This tutorial uses a new character device /dev/gpiochipN provided by the upstream kernel. This is the current way of interacting with GPIO. + +To interact with this new device, you need to use a library and a set of command line interface tools. The common command line tools such as echo or cat won’t work with this device. + +You can install the CLI tools by installing the libgpiod-utils package. A corresponding Python library is provided by the python3-libgpiod package. + +### **Creating a container with Podman** + +[Podman][6] is a container runtime with a command line interface similar to Docker. The big advantage of Podman is it doesn’t run any daemon in the background. That’s especially useful for devices with limited resources. Podman also allows you to start containerized services with systemd unit files. Plus, it has many additional features. + +We’ll create a container in these two steps: + + 1. Create a layered image containing the required packages. + 2. Create a new container starting from our image. + + + +First, create a file Dockerfile with the content below. This tells podman to build an image based on the latest Fedora image available in the registry. Then it updates the system inside and installs some packages: + +``` +FROM fedora:latest +RUN  dnf -y update +RUN  dnf -y install libgpiod-utils python3-libgpiod + +``` + +You have created a build recipe of a container image based on the latest Fedora with updates, plus packages to interact with GPIO. + +Now, run the following command to build your base image: + +``` +$ sudo podman build --tag fedora:gpiobase -f ./Dockerfile + +``` + +You have just created your custom image with all the bits in place. You can play with this base container images as many times as you want without installing the packages every time you run it. + +### Working with Podman + +To verify the image is present, run the following command: + +``` +$ sudo podman images +REPOSITORY                 TAG        IMAGE ID       CREATED          SIZE +localhost/fedora           gpiobase   67a2b2b93b4b   10 minutes ago  488MB +docker.io/library/fedora   latest     c18042d7fac6   2 days ago     300MB + +``` + +Now, start the container and do some actual experiments. Containers are normally isolated and don’t have an access to the host system, including the GPIO interface. Therefore, you need to mount it inside while starting the container. To do this, use the –device option in the following command: + +``` +$ sudo podman run -it --name gpioexperiment --device=/dev/gpiochip0 localhost/fedora:gpiobase /bin/bash + +``` + +You are now inside the running container. Before you move on, here are some more container commands. For now, exit the container by typing exit or pressing **Ctrl+D**. + +To list the the existing containers, including those not currently running, such as the one you just created, run: + +``` +$ sudo podman container ls -a +CONTAINER ID   IMAGE             COMMAND     CREATED          STATUS                              PORTS   NAMES +64e661d5d4e8   localhost/fedora:gpiobase   /bin/bash 37 seconds ago Exited (0) Less than a second ago           gpioexperiment + +``` + +To create a new container, run this command: + +``` +$ sudo podman run -it --name newexperiment --device=/dev/gpiochip0 localhost/fedora:gpiobase /bin/bash + +``` + +Delete it with the following command: + +``` +$ sudo podman rm newexperiment + +``` + +### **Turn on an LED** + +Now you can use the container you already created. If you exited from the container, start it again with this command: + +``` +$ sudo podman start -ia gpioexperiment + +``` + +As already discussed, you can use the CLI tools provided by the libgpiod-utils package in Fedora. To list the available GPIO chips, run: + +``` +$ gpiodetect +gpiochip0 [pinctrl-bcm2835] (54 lines) + +``` + +To get the list of the lines exposed by a specific chip, run: + +``` +$ gpioinfo gpiochip0 + +``` + +Notice there’s no correlation between the number of physical pins and the number of lines printed by the previous command. What’s important is the BCM number, as shown on [pinout.xyz][7]. It is not advised to play with the lines that don’t have a corresponding BCM number. + +Now, connect an LED to the physical pin 40, that is BCM 21. Remember: the shorter leg of the LED (the negative leg, called the cathode) must be connected to a GND pin of the Raspberry Pi with a 330 ohm resistor, and the long leg (the anode) to the physical pin 40. + +To turn the LED on, run the following command. It will stay on until you press **Ctrl+C** : + +``` +$ gpioset --mode=wait gpiochip0 21=1 + +``` + +To light it up for a certain period of time, add the -b (run in the background) and -s NUM (how many seconds) parameters, as shown below. For example, to light the LED for 5 seconds, run: + +``` +$ gpioset -b -s 5 --mode=time gpiochip0 21=1 + +``` + +Another useful command is gpioget. It gets the status of a pin (high or low), and can be useful to detect buttons and switches. + +![Closeup of LED connection with GPIO][8] + +### **Conclusion** + +You can also play with LEDs using Python — [there are some examples here][9]. And you can also use the i2c devices inside the container as well. In addition, Podman is not strictly related to this Fedora edition. You can install it on any existing Fedora Edition, or try it on the two new OSTree-based systems in Fedora: [Fedora Silverblue][2] and [Fedora CoreOS][10]. + + +-------------------------------------------------------------------------------- + +via: https://fedoramagazine.org/turnon-led-fedora-iot/ + +作者:[Alessio Ciregia][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: http://alciregi.id.fedoraproject.org/ +[1]: https://fedoramagazine.org/wp-content/uploads/2018/08/oled-1024x768.png +[2]: https://teamsilverblue.org/ +[3]: https://www.projectatomic.io/ +[4]: https://kojipkgs.fedoraproject.org/compose/iot/latest-Fedora-IoT-28/compose/IoT/ +[5]: https://fedoraproject.org/wiki/InternetOfThings/GettingStarted#Setting_up_a_Physical_Device +[6]: https://github.com/containers/libpod +[7]: https://pinout.xyz/ +[8]: https://fedoramagazine.org/wp-content/uploads/2018/08/breadboard-1024x768.png +[9]: https://github.com/brgl/libgpiod/tree/master/bindings/python/examples +[10]: https://coreos.fedoraproject.org/ diff --git a/sources/tech/20180914 A day in the life of a log message.md b/sources/tech/20180914 A day in the life of a log message.md new file mode 100644 index 0000000000..8d60ec9fe6 --- /dev/null +++ b/sources/tech/20180914 A day in the life of a log message.md @@ -0,0 +1,57 @@ +A day in the life of a log message +====== + +Navigating a modern distributed system from the perspective of a log message. + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/plane_travel_world_international.png?itok=jG3sYPty) + +Chaotic systems tend to be unpredictable. This is especially evident when architecting something as complex as a distributed system. Left unchecked, this unpredictability can waste boundless amounts of time. This is why every single component of a distributed system, no matter how small, must be designed to fit together in a streamlined way. + +[Kubernetes][1] provides a promising model for abstracting compute resources—but even it must be reconciled with other distributed platforms such as [Apache Kafka][2] to ensure reliable data delivery. If someone were to integrate these two platforms, how would it work? Furthermore, if you were to trace something as simple as a log message through such a system, what would it look like? This article will focus on how a log message from an application running inside [OKD][3], the Origin Community Distribution of Kubernetes that powers Red Hat OpenShift, gets to a data warehouse through Kafka. + +### OKD-defined environment + +Such a journey begins in OKD, since the container platform completely overlays the hardware it abstracts. This means that the log message waits to be written to **stdout** or **stderr** streams by an application residing in a container. From there, the log message is redirected onto the node's filesystem by a container engine such as [CRI-O][4]. + +![](https://opensource.com/sites/default/files/uploads/logmessagepathway.png) + +ithin OpenShift, one or more containers are encapsulated within virtual compute nodes known as pods. In fact, all applications running within OKD are abstracted as pods. This allows the applications to be manipulated in a uniform way. This also greatly simplifies communication between distributed components, since pods are systematically addressable through IP addresses and [load-balanced services][5] . So when the log message is taken from the node's filesystem by a log-collector application, it can easily be delivered to another pod running within OpenShift. + +### Two peas in a pod + +To ensure ubiquitous dispersal of the log message throughout the distributed system, the log collector needs to deliver the log message into a Kafka cluster data hub running within OpenShift. Through Kafka, the log message can be delivered to the consuming applications in a reliable and fault-tolerant way with low latency. However, in order to reap the benefits of Kafka within an OKD-defined environment, Kafka needs to be fully integrated into OKD. + +Running a [Strimzi operator][6] will instantiate all Kafka components as pods and integrate them to run within an OKD environment. This includes Kafka brokers for queuing log messages, Kafka connectors for reading and writing from Kafka brokers, and Zookeeper nodes for managing the Kafka cluster state. Strimzi can also instantiate the log collector to double as a Kafka connector, allowing the log collector to feed the log messages directly into a Kafka broker pod running within OKD. + +### Kafka inside OKD + +When the log-collector pod delivers the log message to a Kafka broker, the collector writes to a single broker partition, appending the message to the end of the partition. One of the advantages of using Kafka is that it decouples the log collector from the log's final destination. Thanks to the decoupling, the log collector doesn't care whether the logs end up in [Elasticsearch][7], Hadoop, Amazon S3, or all of them at the same time. Kafka is well-connected to all infrastructure, so the Kafka connectors can take the log message wherever it needs to go. + +Once written to a Kafka broker's partition, the log message is replicated across the broker partitions within the Kafka cluster. This is a very powerful concept on its own; combined with the self-healing features of the platform, it creates a very resilient distributed system. For example, when a node becomes unavailable, the applications running on the node are almost instantaneously spawned on healthy node(s). So even if a node with the Kafka broker is lost or damaged, the log message is guaranteed to survive as many deaths as it was replicated and a new Kafka broker will quickly take the original's place. + +### Off to storage + +After it is committed to a Kafka topic, the log message waits to be consumed by a Kafka connector sink, which relays the log message to either an analytics engine or logging warehouse. Upon delivery to its final destination, the log message could be studied for anomaly detection, queried for immediate root-cause analysis, or used for other purposes. Either way, the log message is delivered by Kafka to its destination in a safe and reliable manner. + +OKD and Kafka are powerful distributed platforms that are evolving rapidly. It is vital to create systems that can abstract the complicated nature of distributed computing without compromising performance. After all, how can we boast of systemwide efficiency if we cannot simplify the journey of a single log message? + + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/9/life-log-message + +作者:[Josef Karásek][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://opensource.com/users/jkarasek +[1]: https://kubernetes.io/ +[2]: https://kafka.apache.org/ +[3]: https://www.okd.io/ +[4]: http://cri-o.io/ +[5]: https://kubernetes.io/docs/concepts/services-networking/service/ +[6]: http://strimzi.io/ +[7]: https://www.elastic.co/ diff --git a/sources/tech/20180914 Convert files at the command line with Pandoc.md b/sources/tech/20180914 Convert files at the command line with Pandoc.md new file mode 100644 index 0000000000..7b72da76a5 --- /dev/null +++ b/sources/tech/20180914 Convert files at the command line with Pandoc.md @@ -0,0 +1,394 @@ +Convert files at the command line with Pandoc +====== + +This guide shows you how to use Pandoc to convert your documents into many different file formats + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/email_paper_envelope_document.png?itok=uPj_kouJ) + +Pandoc is a command-line tool for converting files from one markup language to another. Markup languages use tags to annotate sections of a document. Commonly used markup languages include Markdown, ReStructuredText, HTML, LaTex, ePub, and Microsoft Word DOCX. + +In plain English, [Pandoc][1] allows you to convert a bunch of files from one markup language into another one. Typical examples include converting a Markdown file into a presentation, LaTeX, PDF, or even ePub. + +This article will explain how to produce documentation in multiple formats from a single markup language (in this case Markdown) using Pandoc. It will guide you through Pandoc installation, show how to create several types of documents, and offer tips on how to write documentation that is easy to port to other formats. It will also explain the value of using meta-information files to create a separation between the content and the meta-information (e.g., author name, template used, bibliographic style, etc.) of your documentation. + +### Installation and requirements + +Pandoc is installed by default in most Linux distributions. This tutorial uses pandoc-2.2.3.2 and pandoc-citeproc-0.14.3. If you don't intend to generate PDFs, those two packages are enough. However, I recommend installing texlive as well, so you have the option to generate PDFs. + +To install these programs on Linux, type the following on the command line: + +``` +sudo apt-get install pandoc pandoc-citeproc texlive +``` + +You can find [installation instructions][2] for other platforms on Pandoc's website. + +I highly recommend installing [pandoc][3][-crossref][3], a "filter for numbering figures, equations, tables, and cross-references to them." The easiest option is to download a [prebuilt executable][4], but you can install it from Haskell's package manager, cabal, by typing: + +``` +cabal update +cabal install pandoc-crossref +``` + +Consult pandoc-crossref's GitHub repository if you need additional Haskell [installation information][5]. + +### Some examples + +I'll demonstrate how Pandoc works by explaining how to produce three types of documents: + + * A website from a LaTeX file containing math formulas + * A Reveal.js slideshow from a Markdown file + * A contract agreement document that mixes Markdown and LaTeX + + + +#### Create a website with math formulas + +One of the ways Pandoc excels is displaying math formulas in different output file formats. For instance, let's generate a website from a LaTeX document (named math.tex) containing some math symbols (written in LaTeX). + +The math.tex document looks like: + +``` +% Pandoc math demos + +$a^2 + b^2 = c^2$ + +$v(t) = v_0 + \frac{1}{2}at^2$ + +$\gamma = \frac{1}{\sqrt{1 - v^2/c^2}}$ + +$\exists x \forall y (Rxy \equiv Ryx)$ + +$p \wedge q \models p$ + +$\Box\diamond p\equiv\diamond p$ + +$\int_{0}^{1} x dx = \left[ \frac{1}{2}x^2 \right]_{0}^{1} = \frac{1}{2}$ + +$e^x = \sum_{n=0}^\infty \frac{x^n}{n!} = \lim_{n\rightarrow\infty} (1+x/n)^n$ +``` + +Convert the LaTeX document into a website named mathMathML.html by entering the following command: + +``` +pandoc math.tex -s --mathml  -o mathMathML.html +``` + +The flag **-s** tells Pandoc to generate a standalone website (instead of a fragment, so it will include the head and body HTML tags), and the **–mathml** flag forces Pandoc to convert the math in LaTeX to MathML, which can be rendered by modern browsers. + +![](https://opensource.com/sites/default/files/uploads/pandoc_math-formulas.png) + +Take a look at the [website result][6] and the [code][7]; the code repository contains a Makefile to make things even simpler. + +#### Make a Reveal.js slideshow + +It's easy to generate simple presentations from a Markdown file using Pandoc. The slides contain top-level slides and nested slides underneath. The presentation can be controlled from the keyboard, and you can jump from one top-level slide to the next top-level slide or show the nested slides on a per-top-level basis. This structure is typical in HTML-based presentation frameworks. + +Let's create a slide document named SLIDES (see the [code repository][8]). First, add the slides' meta-information (e.g., title, author, and date) prepended by the **%** symbol: + +``` +% Case Study +% Kiko Fernandez Reyes +% Sept 27, 2017 +``` + +This meta-information also creates the first slide. To add more slides, declare top-level slides using Markdown heading H1 (line 5 in the example below, [heading 1 in Markdown][9] , designated by). + +For example, if we want to create a presentation with the title Case Study that starts with a top-level slide titled Wine Management System, write: + +``` +% Case Study +% Kiko Fernandez Reyes +% Sept 27, 2017 + +# Wine Management System +``` + +To put content (such as slides that explain a new management system and its implementation) inside this top-level section, use a Markdown header H2. Let's add two more slides (lines 7 and 14 below, [heading 2 in Markdown][9], designated by **##** ): + + * The first second-level slide has the title Idea and shows an image of the Swiss flag + * The second second-level slide has the title Implementation + + + +``` +% Case Study +% Kiko Fernandez Reyes +% Sept 27, 2017 + +# Wine Management System + +## Idea + +## Implementation +``` + +We now have a top-level slide ( **# Wine Management System** ) that contains two slides ( **## Idea** and **## Implementation** ). + +Let's put some content in these two slides using incremental bulleted lists by creating a Markdown list prepended by the symbol **>**. Continuing from above, add two items in the first slide (lines 9–10 below) and five items in the second slide (lines 16–20): + +``` +% Case Study +% Kiko Fernandez Reyes +% Sept 27, 2017 + +# Wine Management System + +## Idea + +>- Swiss love their **wine** and cheese +>- Create a *simple* wine tracker system + +![](img/matterhorn.jpg) + +## Implementation + +>- Bottles have a RFID tag +>- RFID reader (emits and read signal) +>- **Raspberry Pi** +>- **Server (online shop)** +>- Mobile app +``` + +We added an image of the Matterhorn mountain. Your slides can be improved by using plain Markdown or adding plain HTML. + +To generate the slides, Pandoc needs to point to the Reveal.js library, so it must be in the same folder as the SLIDES file. The command to generate the slides is: + +``` +pandoc -t revealjs -s --self-contained SLIDES \ +-V theme=white -V slideNumber=true -o index.html +``` + +![](https://opensource.com/sites/default/files/uploads/pandoc_matterhorn-slide.png) + +The above Pandoc command uses the following flags: + + * **-t revealjs** specifies we are going to output a **revealjs** presentation + * **-s** tells Pandoc to generate a standalone document + * **\--self-contained** produces HTML with no external dependencies + * **-V** sets the following variables: +– **theme=white** sets the theme of the slideshow to **white** +– **slideNumber=true** shows the slide number + * **-o index.html** generates the slides in the file named **index.html** + + + +To make things simpler and avoid typing this long command, create the following Makefile: + +``` +all: generate + +generate: +    pandoc -t revealjs -s --self-contained SLIDES \ +    -V theme=white -V slideNumber=true -o index.html + +clean: index.html +    rm index.html + +.PHONY: all clean generate +``` + +You can find all the code in [this repository][8]. + +#### Make a multi-format contract + +Let's say you are preparing a document and (as things are nowadays) some people want it in Microsoft Word format, others use free software and would like an ODT, and others need a PDF. You do not have to use OpenOffice nor LibreOffice to generate the DOCX or PDF file. You can create your document in Markdown (with some bits of LaTeX if you need advanced formatting) and generate any of these file types. + +As before, begin by declaring the document's meta-information (title, author, and date): + +``` +% Contract Agreement for Software X +% Kiko Fernandez-Reyes +% August 28th, 2018 +``` + +Then write the document in Markdown (and add LaTeX if you require advanced formatting). For example, create a table that needs fixed separation space (declared in LaTeX with **\hspace{3cm}** ) and a line where a client and a contractor should sign (declared in LaTeX with **\hrulefill** ). After that, add a table written in Markdown. + +Here's what the document will look like: + +![](https://opensource.com/sites/default/files/uploads/pandoc_agreement.png) + +The code to create this document is: + +``` +% Contract Agreement for Software X +% Kiko Fernandez-Reyes +% August 28th, 2018 + +... + +### Work Order + +\begin{table}[h] +\begin{tabular}{ccc} +The Contractor & \hspace{3cm} & The Customer \\ +& & \\ +& & \\ +\hrulefill & \hspace{3cm} & \hrulefill \\ +% +Name & \hspace{3cm} & Name \\ +& & \\ +& & \\ +\hrulefill & \hspace{3cm} & \hrulefill \\ +... +\end{tabular} +\end{table} + +\vspace{1cm} + ++--------------------------------------------|----------|-------------+ +| Type of Service                            | Cost     |     Total   | ++:===========================================+=========:+:===========:+ +| Game Engine                                | 70.0     | 70.0        | +|                                            |          |             | ++--------------------------------------------|----------|-------------+ +|                                            |          |             | ++--------------------------------------------|----------|-------------+ +| Extra: Comply with defined API functions   | 10.0     | 10.0        | +|        and expected returned format        |          |             | ++--------------------------------------------|----------|-------------+ +|                                            |          |             | ++--------------------------------------------|----------|-------------+ +| **Total Cost**                             |          | **80.0**    | ++--------------------------------------------|----------|-------------+ +``` + +To generate the three different output formats needed for this document, write a Makefile: + +``` +DOCS=contract-agreement.md + +all: $(DOCS) +    pandoc -s $(DOCS) -o $(DOCS:md=pdf) +    pandoc -s $(DOCS) -o $(DOCS:md=docx) +    pandoc -s $(DOCS) -o $(DOCS:md=odt) + +clean: +    rm *.pdf *.docx *.odt + +.PHONY: all clean +``` + +Lines 4–7 contain the commands to generate the different outputs. + +If you have several Markdown files and want to merge them into one document, issue a command with the files in the order you want them to appear. For example, when writing this article, I created three documents: an introduction document, three examples, and some advanced uses. The following tells Pandoc to merge these files together in the specified order and produce a PDF named document.pdf. + +``` +pandoc -s introduction.md examples.md advanced-uses.md -o document.pdf +``` + +### Templates and meta-information + +Writing a complex document is no easy task. You need to stick to a set of rules that are independent from your content, such as using a specific template, writing an abstract, embedding specific fonts, and maybe even declaring keywords. All of this has nothing to do with your content: simply put, it is meta-information. + +Pandoc uses templates to generate different output formats. There is a template for LaTeX, another for ePub, etc. These templates have unfulfilled variables that are set with the meta-information given to Pandoc. To find out what meta-information is available in a Pandoc template, type: + +``` +pandoc -D FORMAT +``` + +For example, the template for LaTeX would be: + +``` +pandoc -D latex +``` + +Which outputs something along these lines: + +``` +$if(title)$ +\title{$title$$if(thanks)$\thanks{$thanks$}$endif$} +$endif$ +$if(subtitle)$ +\providecommand{\subtitle}[1]{} +\subtitle{$subtitle$} +$endif$ +$if(author)$ +\author{$for(author)$$author$$sep$ \and $endfor$} +$endif$ +$if(institute)$ +\providecommand{\institute}[1]{} +\institute{$for(institute)$$institute$$sep$ \and $endfor$} +$endif$ +\date{$date$} +$if(beamer)$ +$if(titlegraphic)$ +\titlegraphic{\includegraphics{$titlegraphic$}} +$endif$ +$if(logo)$ +\logo{\includegraphics{$logo$}} +$endif$ +$endif$ + +\begin{document} +``` + +As you can see, there are **title** , **thanks** , **author** , **subtitle** , and **institute** template variables (and many others are available). These are easily set using YAML metablocks. In lines 1–5 of the example below, we declare a YAML metablock and set some of those variables (using the contract agreement example above): + +``` +--- +title: Contract Agreement for Software X +author: Kiko Fernandez-Reyes +date: August 28th, 2018 +--- + +(continue writing document as in the previous example) +``` + +This works like a charm and is equivalent to the previous code: + +``` +% Contract Agreement for Software X +% Kiko Fernandez-Reyes +% August 28th, 2018 +``` + +However, this ties the meta-information to the content; i.e., Pandoc will always use this information to output files in the new format. If you know you need to produce multiple file formats, you better be careful. For example, what if you need to produce the contract in ePub and in HTML, and the ePub and HTML need specific and different styling rules? + +Let's consider the cases: + + * If you simply try to embed the YAML variable **css: style-epub.css** , you would be excluding the one from the HTML version. This does not work. + * Duplicating the document is obviously not a good solution either, as changes in one version would not be in sync with the other copy. + * You can add variables to the Pandoc command line as follows: + + + +``` +pandoc -s -V css=style-epub.css document.md document.epub +pandoc -s -V css=style-html.css document.md document.html +``` + +My opinion is that it is easy to overlook these variables from the command line, especially when you need to set tens of these (which can happen in complex documents). Now, if you put them all together under the same roof (a meta.yaml file), you only need to update or create a new meta-information file to produce the desired output. You would then write: + +``` +pandoc -s meta-pub.yaml document.md document.epub +pandoc -s meta-html.yaml document.md document.html +``` + +This is a much cleaner version, and you can update all the meta-information from a single file without ever having to update the content of your document. + +### Wrapping up + +With these basic examples, I have shown how Pandoc can do a really good job at converting Markdown documents into other formats. + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/9/intro-pandoc + +作者:[Kiko Fernandez-Reyes][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://opensource.com/users/kikofernandez +[1]: https://pandoc.org/ +[2]: http://pandoc.org/installing.html +[3]: https://hackage.haskell.org/package/pandoc-crossref +[4]: https://github.com/lierdakil/pandoc-crossref/releases/tag/v0.3.2.1 +[5]: https://github.com/lierdakil/pandoc-crossref#installation +[6]: http://pandoc.org/demo/mathMathML.html +[7]: https://github.com/kikofernandez/pandoc-examples/tree/master/math +[8]: https://github.com/kikofernandez/pandoc-examples/tree/master/slides +[9]: https://daringfireball.net/projects/markdown/syntax#header diff --git a/sources/tech/20180914 Freespire Linux- A Great Desktop for the Open Source Purist.md b/sources/tech/20180914 Freespire Linux- A Great Desktop for the Open Source Purist.md new file mode 100644 index 0000000000..baaf08e92d --- /dev/null +++ b/sources/tech/20180914 Freespire Linux- A Great Desktop for the Open Source Purist.md @@ -0,0 +1,114 @@ +Freespire Linux: A Great Desktop for the Open Source Purist +====== + +![](https://www.linux.com/sites/lcom/files/styles/rendered_file/public/freespire.jpg?itok=ReIrw_11) + +Quick. Click on your Linux desktop menu and scan through the list of installed software. How much of that software is strictly open sources To make matters a bit more complicated, have you installed closed source media codecs (to play the likes of MP3 files perhaps)? Is everything fully open, or do you have a mixture of open and closed source tools? + +If you’re a purist, you probably strive to only use open source tools on your desktop. But how do you know, for certain, that your distribution only includes open source software? Fortunately, a few distributions go out of their way to only include applications that are 100% open. One such distro is [Freespire][1]. + +Does that name sound familiar? It should, as it is closely related to[Linspire][2]. Now we’re talking familiarity. Remember back in the early 2000s, when Walmart sold Linux desktop computers? Those computers were powered by the Linspire operating system. Linspire went above and beyond to create an experience that would be similar to that of Windows—even including the tools to install Windows apps on Linux. That experiment failed, mostly because consumers thought they were getting a Windows desktop machine for a dirt cheap price. After that debacle, Linspire went away for a while. It’s now back, thanks to [PC/OpenSystems LLC][3]. Their goal isn’t to recreate the past but to offer two different flavors of Linux: + + * Linspire—a commercial distribution of Linux that includes proprietary software and does have an associated cost ($39.99 USD for a single license). + + * Freespire—a non-commercial distribution of Linux that only includes open source software and is free to download. + + + + +We’re here to discuss Freespire and why it is an outstanding addition to the Linux community, especially those who strive to use only free and open source software. This version of Freespire (4.0) was released on August 20, 2018, so it’s fresh and ready to go. + +Let’s dig into the operating system and see what makes this a viable candidate for open source fans. + +### Installation + +In keeping with my usual approach, there’s very little reason to even mention the installation of Freespire Linux. There is nothing out of the ordinary here. Download the ISO image, burn it to a USB Drive (or CD/DVD if you’re dealing with older hardware), boot the drive, click the Install icon, answer a few simple questions, and wait for the installation to prompt for a reboot. That’s how far we’ve come with Linux installations… they are simple, and rarely will you have a single issue with the process. In the end, you’ll be presented with a simple (modified) Mate desktop (Figure 1) that makes it easy for any user (of any skill level) to feel right at home. + +![](https://www.linux.com/sites/lcom/files/styles/rendered_file/public/freespire.jpg?itok=ReIrw_11) + +### Software Titles + +Once you’ve logged into the desktop, you’ll find a main menu where you can view all of the installed applications. That list of software includes: + + * Geary + + * Chromium Browser + + * Abiword + + * Gnumeric + + * Calendar + + * Audacious + + * Totem Video Player + + * Software Center + + * Synaptic + + * G-Debi + + + + +Also rolled into the system is support for both Flatpak and Snap applications, so you shouldn’t miss out on any software you need, which brings me to the part when purists might want to look away. + +Just because Freespire is marketed as a purely open source distribution, it doesn’t mean users are locked down to only open source software. In fact, if you open the Software Center, you can do a quick search for Spotify (a closed source application with an available Linux desktop client) and there it is! (Figure 2). + +![Spotify][5] + +Figure 2: The closed source Spotify client available for installation. + +[Used with permission][6] + +Fortunately, for those productive-minded folks, the likes of LibreOffice (which is not installed by default) is open source and can be installed easily from the Software Center. That doesn’t mean you must install other software, but those who need to do serious business-centric work (such as collaborating on documents), will likely want/need to install a more powerful office suite (as Abiword won’t cut it as a business-level word processor). + +For those who tend to work long hours on the Linux desktop and want to protect their eyes from extended strain, Freespire does include a nightlight tool that can adjust the color temperature of the interface. To open this tool, click on the main desktop menu and type night in the Search bar (Figure 3). + +![Night Light][8] + +Figure 3: Opening the Night Light tool. + +[Used with permission][6] + +Once opened, Night Light will automatically adjust the color temperature, based on the time of day. From the notification tray, you can click the icon to suspend Night Light, set it to autostart, and close the service (Figure 4). + +![Night Light controls.][10] + +Figure 4: The Night Light controls. + +[Used with permission][6] + +### Beyond the Mate Desktop + +As is, Mate fans might not exactly recognize the Freespire desktop. The developers have clearly given Mate a significant set of tweaks to make it slightly resemble the Mac OS desktop. It’s not quite as elegant as, say, Elementary OS, but this is certainly an outstanding take on the Linux desktop. Whether you’re a fan of Mate or Mac OS, you should feel immediately at home on the desktop. On the top bar, the developers have included an appmenu that changes, based on what application you have open. Start any app and you’ll find that app’s menu appears in the top bar. This active menu makes the desktop quite efficient. + +### Are you ready for Freespire? + +Every piece of the Freespire puzzle is equally as user-friendly as it is intuitive. The developers of Freespire have gone to great lengths to make this pure open source distribution a treat to use. Even if a 100% open source desktop isn’t your thing, Freespire is still a worthy contender in the world of desktop Linux. It’s clean and stable (as it’s based on Ubuntu 18.04) and able to help you be efficient and productive on the desktop. + +Learn more about Linux through the free ["Introduction to Linux" ][11]course from The Linux Foundation and edX. + +-------------------------------------------------------------------------------- + +via: https://www.linux.com/learn/intro-to-linux/2018/9/freespire-linux-great-desktop-open-source-purist + +作者:[Jack Wallen][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://www.linux.com/users/jlwallen +[1]: https://www.freespirelinux.com/ +[2]: https://www.linspirelinux.com/ +[3]: https://www.pc-opensystems.com +[5]: https://www.linux.com/sites/lcom/files/styles/rendered_file/public/freespire_2.jpg?itok=zcr94Dk6 (Spotify) +[6]: /licenses/category/used-permission +[8]: https://www.linux.com/sites/lcom/files/styles/rendered_file/public/freespire_3.jpg?itok=aZYtBPgE (Night Light) +[9]: /files/images/freespire4jpg +[10]: https://www.linux.com/sites/lcom/files/styles/rendered_file/public/freespire_4.jpg?itok=JCcQwmJ5 (Night Light controls.) +[11]: https://training.linuxfoundation.org/linux-courses/system-administration-training/introduction-to-linux diff --git a/sources/tech/20180918 Cozy Is A Nice Linux Audiobook Player For DRM-Free Audio Files.md b/sources/tech/20180918 Cozy Is A Nice Linux Audiobook Player For DRM-Free Audio Files.md new file mode 100644 index 0000000000..8450d6fd11 --- /dev/null +++ b/sources/tech/20180918 Cozy Is A Nice Linux Audiobook Player For DRM-Free Audio Files.md @@ -0,0 +1,72 @@ +Cozy Is A Nice Linux Audiobook Player For DRM-Free Audio Files +====== +[Cozy][1] **is a free and open source audiobook player for the Linux desktop. The application lets you listen to DRM-free audiobooks (mp3, m4a, flac, ogg and wav) using a modern Gtk3 interface.** + +![](https://4.bp.blogspot.com/-A1TWkOasR7s/W6DevbmTH9I/AAAAAAAABho/VSjQkiDeWK49xzJ2MXvvwk0T_AhGWqQRgCLcBGAs/s1600/cozy-audiobook-player.png) + +You could use any audio player to listen to audiobooks, but a specialized audiobook player like Cozy makes everything easier, by **remembering your playback position and continuing from where you left off for each audiobook** , or by letting you **set the playback speed of each book individually** , among others. + +The Cozy interface lets you browse books by author, reader or recency, while also providing search functionality. **Books front covers are supported by Cozy** \- either by using embedded images, or by adding a cover.jpg or cover.png image in the book folder, which is automatically picked up and displayed by Cozy. + +When you click on an audiobook, Cozy lists the book chapters on the right, while displaying the book cover (if available) on the left, along with the book name, author and the last played time, along with total and remaining time: + +![](https://4.bp.blogspot.com/-hqBITKAiYaM/W6De4HzckRI/AAAAAAAABhs/GxSjfpND4hkk6ZM29TKfwB1zzXPxNa0_gCLcBGAs/s640/cozy-audiobook-player-playback-chapters.png) + +From the application toolbar you can easily **go back 30 seconds** by clicking the rewind icon from its top left-hand side corner. Besides regular controls, cover and title, you'll also find a playback speed button on the toolbar, which lets you increase the playback speed up to 2X. + +**A sleep timer is also available**. It can be set to stop after the current chapter or after a given number of minutes. + +Other Cozy features worth mentioning: + + * **Mpris integration** (Media keys & playback info) + * **Supports multiple storage locations** + * **Drag'n'drop support for importing new audiobooks** + * **Offline Mode**. If your audiobooks are on an external or network drive, you can switch the download button to keep a local cached copy of the book to listen to on the go. To enable this feature you have to set your storage location to external in the settings + * **Prevents your system from suspend during playback** + * **Dark mode** + + + +What I'd like to see in Cozy is a way to get audiobooks metadata, including the book cover, automatically. A feature to retrieve metadata from Audible.com was proposed on the Cozy GitHub project page and the developer seems interested in this, but it's not clear when or if this will be implemented. + +Like I was mentioning in the beginning of the article, Cozy only supports DRM-free audio files. Currently it supports mp3, m4a, flac, ogg and wav. Support for more formats will probably come in the future, with m4b being listed on the Cozy 0.7.0 todo list. + +Cozy cannot play Audible audiobooks due to DRM. But you'll find some solutions out there for converting Audible (.aa/.aax) audiobooks to mp3, like + +### Install Cozy + +**Any Linux distribution / Flatpak** : Cozy is available as a Flatpak on FlatHub. To install it, follow the quick Flatpak [setup][4], then go to the Cozy FlaHub [page][5] and click the install button, or use the install command at the bottom if its page. + +**elementary OS** : Cozy is available in the [AppCenter][6]. + +**Ubuntu 18.04 / Linux Mint 19** : you can install Cozy from its repository: + +``` +wget -nv https://download.opensuse.org/repositories/home:geigi/Ubuntu_18.04/Release.key -O Release.key +sudo apt-key add - < Release.key +sudo sh -c "echo 'deb http://download.opensuse.org/repositories/home:/geigi/Ubuntu_18.04/ /' > /etc/apt/sources.list.d/home:geigi.list" +sudo apt update +sudo apt install com.github.geigi.cozy +``` + +**For other ways of installing Cozy check out its[website][2].** + + +-------------------------------------------------------------------------------- + +via: https://www.linuxuprising.com/2018/09/cozy-is-nice-linux-audiobook-player-for.html + +作者:[Logix][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://plus.google.com/118280394805678839070 +[1]: https://cozy.geigi.de/ +[2]: https://cozy.geigi.de/#how-can-i-get-it +[3]: https://gitlab.com/ReverendJ1/audiblefreedom/blob/master/audiblefreedom +[4]: https://flatpak.org/setup/ +[5]: https://flathub.org/apps/details/com.github.geigi.cozy +[6]: https://appcenter.elementary.io/com.github.geigi.cozy/ diff --git a/sources/tech/20180919 Streama - Setup Your Own Streaming Media Server In Minutes.md b/sources/tech/20180919 Streama - Setup Your Own Streaming Media Server In Minutes.md new file mode 100644 index 0000000000..521a8f5b95 --- /dev/null +++ b/sources/tech/20180919 Streama - Setup Your Own Streaming Media Server In Minutes.md @@ -0,0 +1,171 @@ +Streama – Setup Your Own Streaming Media Server In Minutes +====== + +![](https://www.ostechnix.com/wp-content/uploads/2018/09/streama-720x340.png) + +**Streama** is a free, open source application that helps to setup your own personal streaming media server in minutes in Unix-like operating systems. It’s like Netflix, but self-hostable. You can deploy it on your local system or VPS or dedicated server and stream the media files across multiple devices. The media files can be accessed from a web-browser from any system on your network. If you have deployed on your VPS, you can access it from anywhere. Streama works like your own personal Netflix system to stream your TV shows, videos, audios and movies. Streama is a web-based application written using Grails 3 (server-side) with SpringSecurity and all frond-end components are written in AngularJS. The built-in player is completely HTML5-based. + +### Prominent Features + +Streama ships with a lot features as listed below. + + * Easy to install configure. You can either download docker instance and fire up your media server in minutes or install vanilla version on your local or VPS or dedicated server. + * Drag and drop support to upload media files. + * Live sync watching support. You can watch videos with your friends, family remotely. It doesn’t matter where they are. You can all watch the same video at a time. + * Built-in beautiful video player to watch/listen video and audio. + * Built-in browser to access the media files in the server. + * Multi-user support. You can create individual user accounts to your family members and access the media server simultaneously. + * Streama supports pause-play option. Pause the playback at any time and Streama remembers where you left off last time. + * Streama can be able to detect similar movies and videos and shows for you to add. + * Self-hostable + * It is completely free and open source. + + + +What do you need more? Streama has everything you to need to setup a full-fledged streaming media server in your Linux box. + +### Setup Your Own Streaming Media Server Using Streama + +Streama requires JAVA 8 or later, preferably **OpenJDK**. And, the recommended OS is **Ubuntu**. For the purpose of this guide, I will be using Ubuntu 18.04 LTS. + +By default, the latest Ubuntu 18.04 includes Open JDK 11. To install default openJDK in Ubuntu 18.04 or later, run: + +``` +$ sudo apt install default-jdk + +``` + +Java 8 is the latest stable Long Time Support version. If you prefer to use Java LTS, run: + +``` +$ sudo apt install openjdk-8-jdk +``` + +I have installed openjdk-8-jdk. To check the installed Java version, run: + +``` +$ java -version +openjdk version "1.8.0_181" +OpenJDK Runtime Environment (build 1.8.0_181-8u181-b13-0ubuntu0.18.04.1-b13) +OpenJDK 64-Bit Server VM (build 25.181-b13, mixed mode) +``` + +Once java installed, create a directory to save Streama executable and yml files. + +``` +$ sudo mkdir /data + +$ sudo mkdir /data/streama +``` + +I followed the official documentation, so I used this path – /data/streama. It is optional. You’re free to use any location of your choice. + +Switch to streama directory: + +``` +$ cd /data/streama +``` + +Download the latest Streama executable file from [**releases page**][1]. As of writing this guide, the latest version was **v1.6.0-RC8**. + +``` +$ sudo wget https://github.com/streamaserver/streama/releases/download/v1.6.0-RC8/streama-1.6.0-RC8.war +``` + +Make it executable: + +``` +$ sudo chmod +x streama-1.6.0-RC8.war +``` + +Now, run Streama application using command: + +``` +$ sudo ./streama-1.6.0-RC8.war +``` + +If you an output something like below, Streama is working! + +``` +INFO streama.Application - Starting Application on ubuntuserver with PID 26714 (/data/streama/streama-1.6.0-RC8.war started by root in /data/streama) +DEBUG streama.Application - Running with Spring Boot v1.4.4.RELEASE, Spring v4.3.6.RELEASE +INFO streama.Application - The following profiles are active: production + +Configuring Spring Security Core ... +... finished configuring Spring Security Core + +INFO streama.Application - Started Application in 92.003 seconds (JVM running for 98.66) +Grails application running at http://localhost:8080 in environment: production +``` + +Open your web browser and navigate to URL – **** + +You should see Streama login screen. Login with default credentials – **admin/admin** + +![](https://www.ostechnix.com/wp-content/uploads/2018/09/streama-login-page.png) + +Now, You need to fill out some required base-settings. Click OK button in the next screen and you will be redirected to the settings page. In the Settings page, you need to set some parameters such as the location of the Uploads directory, Streama logo, name of the media server, base URL, allow anonymous access, allow users to download videos. All fields marked with ***** is necessary to fill. Once you provided the details, click **Save settings** button. + +![](http://www.ostechnix.com/wp-content/uploads/2018/09/streama-settings.png) + +Congratulations! Your media server is ready to use! + +Here is how Stream dashboard looks like. + +![](http://www.ostechnix.com/wp-content/uploads/2018/09/Streama-dashboard.png) + +And, this is the contents management page where you can upload movies, shows, access files via file manager, view the notifications and highlights. + +![](https://www.ostechnix.com/wp-content/uploads/2018/09/Manage-contents-in-Streama.png) + +### Adding movies/shows + +Let me show you how to add a movie. + +Go to the **“Manage Content”** page from the dashboard and click **“Create New Movie”** link. + +Enter the movie details, such as name, release date, IMDB ID and movie description and click **Save**. These are all optional, you can simply ignore them if you don’t know about the details. + +![](https://www.ostechnix.com/wp-content/uploads/2018/09/Add-movie-in-Streama-1.png) + +We have added the movie details, but we haven’t added the actual movie yet. To do so, click on the red box in the bottom that says – **“No video file yet! Drop file or Click here to add”**. + +![](https://www.ostechnix.com/wp-content/uploads/2018/09/Add-movie-in-Streama-2.png) + +You could either drag and drop the movie file inside this dashboard or click on the red box to manually upload it. + +Choose the movie file to upload and click Upload. + +![](https://www.ostechnix.com/wp-content/uploads/2018/09/Add-movie-in-Streama-3.png) + +Once the upload is completed, you could see the uploaded movie details. Click on the three horizontal lines next to the movie if you want to edit/modify movie details. + +![](https://www.ostechnix.com/wp-content/uploads/2018/09/Add-movie-in-Streama-4.png) + +Similarly, you can create TV shows, videos and audios. + +![](https://www.ostechnix.com/wp-content/uploads/2018/09/Add-movie-in-Streama-5.png) + +And also the movies/shows are started to appear in the home screen of your dashboard. Simply click on it to play the video and enjoy Netflix experience right from your Linux desktop. + +For more details, refer the product’s official website. + +And, that’s all for now. Hope this was useful. More good stuffs to come. Stay tuned! + +Cheers! + + + +-------------------------------------------------------------------------------- + +via: https://www.ostechnix.com/streama-setup-your-own-streaming-media-server-in-minutes/ + +作者:[SK][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://www.ostechnix.com/author/sk/ +[1]: https://github.com/streamaserver/streama/releases diff --git a/sources/tech/20180920 Distributed tracing in a microservices world.md b/sources/tech/20180920 Distributed tracing in a microservices world.md new file mode 100644 index 0000000000..1b39a5e30a --- /dev/null +++ b/sources/tech/20180920 Distributed tracing in a microservices world.md @@ -0,0 +1,113 @@ +Distributed tracing in a microservices world +====== +What is distributed tracing and why is it so important in a microservices environment? + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/pixelated-world.png?itok=fHjM6m53) + +[Microservices][1] have become the default choice for greenfield applications. After all, according to practitioners, microservices provide the type of decoupling required for a full digital transformation, allowing individual teams to innovate at a far greater speed than ever before. + +Microservices are nothing more than regular distributed systems, only at a larger scale. Therefore, they exacerbate the well-known problems that any distributed system faces, like lack of visibility into a business transaction across process boundaries. + +Given that it's extremely common to have multiple versions of a single service running in production at the same time—be it in a [A/B testing][2] scenario or as part of rolling out a new release following the [Canary release][3] technique—when we account for the fact that we are talking about hundreds of services, it's clear that what we have is chaos. It's almost impossible to map the interdependencies and understand the path of a business transaction across services and their versions. + +### Observability + +This chaos ends up being a good thing, as long as we can observe what's going on and diagnose the problems that will eventually occur. + +A system is said to be observable when we can understand its state based on the [metrics, logs, and traces][4] it emits. Given that we are talking about distributed systems, knowing the state of a single instance of a single service isn't enough; we need to be able to aggregate the metrics for all instances of a given service, perhaps grouped by version. Metrics solutions like [Prometheus][5] are very popular in tackling this aspect of the observability problem. Similarly, we need logs to be stored in a central location, as it's impossible to analyze the logs from the individual instances of each service. [Logstash][6] is usually applied here, in combination with a backing storage like [Elasticsearch][7]. And finally, we need to get end-to-end traces to understand the path a given transaction has taken. This is where distributed tracing solutions come into play. + +### Distributed tracing + +In monolithic web applications, logging frameworks provide enough capabilities to do a basic root-cause analysis when something fails. A developer just needs to place log statements in the code. Information like "context" (usually "thread") and "timestamp" are automatically added to the log entry, making it easier to understand the execution of a given request and correlate the entries. + +``` +Thread-1 2018-09-03T15:52:54+02:00 Request started +Thread-2 2018-09-03T15:52:55+02:00 Charging credit card x321 +Thread-1 2018-09-03T15:52:55+02:00 Order submitted +Thread-1 2018-09-03T15:52:56+02:00 Charging credit card x123 +Thread-1 2018-09-03T15:52:57+02:00 Changing order status +Thread-1 2018-09-03T15:52:58+02:00 Dispatching event to inventory +Thread-1 2018-09-03T15:52:59+02:00 Request finished +``` + +We can safely say that the second log entry above is not related to the other entries, as it's being executed in a different thread. + +In microservices architectures, logging alone fails to deliver the complete picture. Is this service the first one in the call chain? And what happened at the inventory service (where we apparently dispatched an event)? + +A common strategy to answer this question is creating an identifier at the very first building block of our transaction and propagating this identifier across all the calls, probably by sending it as an HTTP header whenever a remote call is made. + +In a central log collector, we could then see entries like the ones below. Note how we could log the correlation ID (the first column in our example), so we know that the second entry is not related to the other entries. + +``` +abc123 Order     2018-09-03T15:52:58+02:00 Dispatching event to inventory +def456 Order     2018-09-03T15:52:58+02:00 Dispatching event to inventory +abc123 Inventory 2018-09-03T15:52:59+02:00 Received `order-submitted` event +abc123 Inventory 2018-09-03T15:53:00+02:00 Checking inventory status +abc123 Inventory 2018-09-03T15:53:01+02:00 Updating inventory +abc123 Inventory 2018-09-03T15:53:02+02:00 Preparing order manifest +``` + +This technique is one of the concepts at the core of any modern distributed tracing solution, but it's not really new; correlating log entries is decades old, probably as old as "distributed systems" itself. + +What sets distributed tracing apart from regular logging is that the data structure that holds tracing data is more specialized, so we can also identify causality. Looking at the log entries above, it's hard to tell if the last step was caused by the previous entry, if they were performed concurrently, or if they share the same caller. Having a dedicated data structure also allows distributed tracing to record not only a message in a single point in time but also the start and end time of a given procedure. + +![Trace showing spans][9] + +Trace showing spans similar to the logs described above + +[Click to enlarge][10] + +Most of the modern distributed tracing tools are inspired by a 2010 [paper about Dapper][11], the distributed tracing solution used at Google. In that paper, the data structure described above was called a span, and you can see nine of them in the image above. This particular "forest" of spans is called a trace and is equivalent to the correlated log entries we've seen before. + +The image above is a screenshot of a trace displayed in [Jaeger][12], an open source distributed tracing solution hosted by the [Cloud Native Computing Foundation (CNCF)][13]. It marks each service with a color to make it easier to see the process boundaries. Timing information can be easily visualized, both by looking at the macro timeline at the top of the screen or at the individual spans, giving a sense of how long each span takes and how impactful it is in this particular execution. It's also easy to observe when processes are asynchronous and therefore may outlive the initial request. + +Like with logging, we need to annotate or instrument our code with the data we want to record. Unlike logging, we record spans instead of messages and do some demarcation to know when the span starts and finishes so we can get accurate timing information. As we would probably like to have our business code independent from a specific distributed tracing implementation, we can use an API such as [OpenTracing][14], leaving the decision about the concrete implementation as a packaging or runtime concern. Following is pseudo-Java code showing such demarcation. + +``` +try (Scope scope = tracer.buildSpan("submitOrder").startActive(true)) { +    scope.span().setTag("order-id", "c85b7644b6b5"); +    chargeCreditCard(); +    changeOrderStatus(); +    dispatchEventToInventory(); +} +``` + +Given the nature of the distributed tracing concept, it's clear the code executed "between" our business services can also be part of the trace. For instance, we could [turn on][15] the distributed tracing integration for [Istio][16], a service mesh solution that helps in the communication between microservices, and we'll suddenly have a better picture about the network latency and routing decisions made at this layer. Another example is the work done in the OpenTracing community to provide instrumentation for popular stacks, frameworks, and APIs, such as Java's [JAX-RS][17], [Spring Cloud][18], or [JDBC][19]. This enables us to see how our business code interacts with the rest of the middleware, understand where a potential problem might be happening, and identify the best areas to improve. In fact, today's middleware instrumentation is so rich that it's common to get started with distributed tracing by using only the so-called "framework instrumentation," leaving the business code free from any tracing-related code. + +While a microservices architecture is almost unavoidable nowadays for established companies to innovate faster and for ambitious startups to achieve web scale, it's easy to feel helpless while conducting a root cause analysis when something eventually fails and the right tools aren't available. The good news is tools like Prometheus, Logstash, OpenTracing, and Jaeger provide the pieces to bring observability to your application. + +Juraci Paixão Kröhling will present [What are My Microservices Doing?][20] at [Open Source Summit Europe][21], October 22-24 in Edinburgh, Scotland. + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/9/distributed-tracing-microservices-world + +作者:[Juraci Paixão Kröhling][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://opensource.com/users/jpkroehling +[1]: https://en.wikipedia.org/wiki/Microservices +[2]: https://en.wikipedia.org/wiki/A/B_testing +[3]: https://martinfowler.com/bliki/CanaryRelease.html +[4]: https://blog.twitter.com/engineering/en_us/a/2016/observability-at-twitter-technical-overview-part-i.html +[5]: https://prometheus.io/ +[6]: https://github.com/elastic/logstash +[7]: https://github.com/elastic/elasticsearch +[8]: /file/409621 +[9]: https://opensource.com/sites/default/files/uploads/distributed-trace.png (Trace showing spans) +[10]: /sites/default/files/uploads/trace.png +[11]: https://ai.google/research/pubs/pub36356 +[12]: https://www.jaegertracing.io/ +[13]: https://www.cncf.io/ +[14]: http://opentracing.io/ +[15]: https://istio.io/docs/tasks/telemetry/distributed-tracing/ +[16]: https://istio.io/ +[17]: https://github.com/opentracing-contrib/java-jaxrs +[18]: https://github.com/opentracing-contrib/java-spring-cloud +[19]: https://github.com/opentracing-contrib/java-jdbc +[20]: https://osseu18.sched.com/event/FxW3/what-are-my-microservices-doing-juraci-paixao-krohling-red-hat# +[21]: https://osseu18.sched.com/ diff --git a/sources/tech/20180920 Record Screen in Ubuntu Linux With Kazam -Beginner-s Guide.md b/sources/tech/20180920 Record Screen in Ubuntu Linux With Kazam -Beginner-s Guide.md new file mode 100644 index 0000000000..a2f57f592a --- /dev/null +++ b/sources/tech/20180920 Record Screen in Ubuntu Linux With Kazam -Beginner-s Guide.md @@ -0,0 +1,185 @@ +Record Screen in Ubuntu Linux With Kazam [Beginner’s Guide] +====== +**This tutorial shows you how to install Kazam screen recorder and explains how to record screen in Ubuntu. The guide also lists useful shortcuts and handy tips for using Kazam.** + +![How to record your screen in Ubuntu Linux with Kazam][1] + +[Kazam][2] is one of the [best screen recorders for Linux][3]. To me, it’s the best screen recording tool. I have been using it for years. All the video tutorials on YouTube have been recorded with Kazam. + +Some of the main features of Kazam are: + + * Record entire screen, part of screen, application window or all screens (for multi-monitor setup) + * Take screenshots + * Keyboard shortcut support for easily pausing and resuming while recording screen + * Record in various file formats such as MP4, AVI and more. + * Capture audio from speaker or microphone while recording the screen + * Capture mouse clicks and key presses + * Capture video from webcam + * Insert a webcam window on the side + * Broadcast to YouTube live video + + + +Like the screenshot tool [Shutter][4], Kazam is also not being actively developed for the last couple of years. And like Shutter, the present Kazam release works just fine. + +I am using Ubuntu in the tutorial. The installation instructions should work for other Ubuntu-based distributions such as Linux Mint, elementary OS etc. For all the other distributions, you can still read about using Kazam and its features. + +### Install Kazam in Ubuntu + +Kazam is available in the official repository in Ubuntu. However, the official repository consists Kazam version 1.4.5, the last stable version of Kazam. + +![Kazam Version 1.4.5][5] +Kazam Version 1.4.5 + +Kazam developer(s) also worked on a newer release, Kazam 1.5.3. The version was almost sable and ready to release, but for unknown reasons, the development stopped after this. There have been [no updates][6] since then. + +You can use either of Kazam 1.4.5 and 1.5.3 without hesitating. Kazam 1.5 provides additional features like recording mouse clicks and key presses, webcam support, live broadcast support, and a refreshed countdown timer. + +![Kazam Version 1.5.3][7] +Kazam Version 1.5.3 + +It’s up to you to decide which version you want to use. I would suggest go for version 1.5.3 because it has more features. + +You can install the older Kazam 1.4.5 from the Software Center. You can also use the command below: + +``` +sudo apt install kazam +``` + +If you want to install the newer Kazam 1.5.3, you can use this [unofficial PPA][8] that is available for Ubuntu 18.04 and 16.04: + +``` +sudo add-apt-repository ppa:sylvain-pineau/kazam +sudo apt-get update +sudo apt install kazam +``` + +You also need to install a few libraries in order to record the mouse clicks and keyboard presses. + +``` +sudo apt install python3-cairo python3-xlib +``` + +### Recording your screen with Kazam + +Once you have installed Kazam, search for it in the application menu and start it. You should see a screen like this with some options on it. You can check the options as per your need and click on capture to start recording screen with Kazam. + +![Screen recording with Kazam][9] +Screen recording with Kazam + +It will show you a countdown before recording the screen. The default wait time is 5 seconds and you can change it from Kazam interface (see the previous image). It gives you a breathing time so that you can prepare for your recording. + +![Countdown before screen recording][10] +Countdown before screen recording + +Once the recording starts,the main Kazam interface disappears and an indicator appears in the panel. If you want to pause the recording or finish the recording, you can do it from this indicator. + +![Pause or finish screen recording][11] +Pause or finish screen recording + +If you choose to finish the recording, it will give you the option to “Save for later”. If you have a [video editor installed in Linux][12], you can also start editing the recording from this point. + +![Save screen recording in Kazam][13] +Save recording + +By default it prompts you to install the recording in Videos folder but you can change the location and save it elsewhere as well. + +That’s the basic you need to know about screen recording in Linux with Kazam. + +Now let me give you a few tips on how to utilize more features in Kazam. + +### Getting more out of Kazam screen recorder + +Kazam is a featureful screen recorder for Linux. You can access its advanced or additional features from the preferences. + +![Accessing Kazam preferences][14] +Accessing Kazam preferences + +#### Autosave screen recording in a specified location + +You can choose to automatically save the screen recordings in Kazam. The default location is Videos but you can change it to any other location. + +![Autosave screen recordings in a chosen location][15] +Autosave in a chosen location + +#### Avoid screen recording in RAW mode + +You can save your screen recordings in file formats like WEBM, MP4, AVI etc. You are free to choose what you want. However, I would advise avoiding RAW (AVI) file format. If you use RAW file format, the recorded files will be in GBs even for a few minutes of recordings. + +It’s wise to verify that Kazam is not using the RAW file format for recording. If you ask my suggestion, prefer H264 with MP4 file format. + +![file format in Kazam][16] +Don’t use RAW files + +#### Capture mouse clicks and key presses while screen recording + +If you want to highlight when a mouse was clicked, you can easily do that in the newer version of Kazam. + +![Record mouse clicks while screen recording with Kazam][17] +Record mouse clicks + +All you have to do is to check the “Key presses and mouse clicks” option on the Kazam interface (the same screen where you press Capture). + +#### Use keyboard shortcuts for more efficient screen recordings + +Imagine you are recording screen in Linux and suddenly you realized that you have to pause the recording for some reasons. Now, you can pause the recording by going to the Kazam indicator and selecting the pause option. But this activity of selecting the pause option will also be recorded. + +You can edit out this part later but it unnecessarily adds to the already cumbersome editing task. + +A better option will be to use the [keyboard shortcuts in Ubuntu][18]. Screen recording becomes a lot better if you use the shortcuts. + +While Kazam is running, you can use the following hotkeys: + + * Super+Ctrl+R: Start recording + * Super+Ctrl+P: Pause recording, press again for resuming the recording + * Super+Ctrl+F: Finish recording + * Super+Ctrl+Q: Quit recording + + + +Super key is the Windows key on your keyboard. + +The most important is Super+Ctrl+P for pausing and resuming the recording. + +You can further explore the Kazam preferences for webcam recording and YouTube live broadcasting options. + +### Do you like Kazam? + +I am repeating myself here. I love Kazam. I have used other screen recorders like [SimpleScreenRecorder][19] or [Green Recorder][20] but I feel a lot more comfortable with Kazam. + +I hope you like Kazam for screen recording in Ubuntu or any other Linux distribution. I have tried highlighting some of the additional features here to help you with a better screen recording. + +What features do you like about Kazam? Do you use some other screen recorder? Do they work better than Kazam? Please share your views in the comments section below. + +-------------------------------------------------------------------------------- + +via: https://itsfoss.com/kazam-screen-recorder/ + +作者:[Abhishek Prakash][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://itsfoss.com/author/abhishek/ +[1]: https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/09/screen-recording-kazam-ubuntu-linux.png +[2]: https://launchpad.net/kazam +[3]: https://itsfoss.com/best-linux-screen-recorders/ +[4]: http://shutter-project.org/ +[5]: https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/09/kazam-1-4-5.png +[6]: https://launchpad.net/~kazam-team/+archive/ubuntu/unstable-series +[7]: https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/09/kazam-1-5-3.png +[8]: https://launchpad.net/~sylvain-pineau/+archive/ubuntu/kazam +[9]: https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/09/kazam-start-recording.png +[10]: https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/09/kazam-countdown.jpg +[11]: https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/09/kazam-finish-recording.png +[12]: https://itsfoss.com/best-video-editing-software-linux/ +[13]: https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/09/kazam-save-recording.jpg +[14]: https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/09/kazam-preferences.png +[15]: https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/09/kazam-auto-save.jpg +[16]: https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/09/select-file-type-kazam.jpg +[17]: https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/09/record-mouse-clicks-kazam.jpeg +[18]: https://itsfoss.com/ubuntu-shortcuts/ +[19]: https://itsfoss.com/record-screen-ubuntu-simplescreenrecorder/ +[20]: https://itsfoss.com/green-recorder-3/ diff --git a/sources/tech/20180921 Clinews - Read News And Latest Headlines From Commandline.md b/sources/tech/20180921 Clinews - Read News And Latest Headlines From Commandline.md new file mode 100644 index 0000000000..b7082ea141 --- /dev/null +++ b/sources/tech/20180921 Clinews - Read News And Latest Headlines From Commandline.md @@ -0,0 +1,138 @@ +translating----geekpi + +Clinews – Read News And Latest Headlines From Commandline +====== + +![](https://www.ostechnix.com/wp-content/uploads/2018/09/clinews-720x340.jpeg) + +A while ago, we have written about a CLI news client named [**InstantNews**][1] that helps you to read news and latest headlines from commandline instantly. Today, I stumbled upon a similar utility named **Clinews** which serves the same purpose – reading news and latest headlines from popular websites, blogs from Terminal. You don’t need to install GUI applications or mobile apps. You can read what’s happening in the world right from your Terminal. It is free, open source utility written using **NodeJS**. + +### Installing Clinews + +Since Clinews is written using NodeJS, you can install it using NPM package manager. If you haven’t install NodeJS, install it as described in the following link. + +Once node installed, run the following command to install Clinews: + +``` +$ npm i -g clinews +``` + +You can also install Clinews using **Yarn** : + +``` +$ yarn global add clinews +``` + +Yarn itself can installed using npm + +``` +$ npm -i yarn +``` + +### Configure News API + +Clinews retrieves all news headlines from [**News API**][2]. News API is a simple and easy-to-use API that returns JSON metadata for the headlines currently published on a range of news sources and blogs. It currently provides live headlines from 70 popular sources, including Ars Technica, BBC, Blooberg, CNN, Daily Mail, Engadget, ESPN, Financial Times, Google News, hacker News, IGN, Mashable, National Geographic, Reddit r/all, Reuters, Speigel Online, Techcrunch, The Guardian, The Hindu, The Huffington Post, The Newyork Times, The Next Web, The Wall street Journal, USA today and [**more**][3]. + +First, you need an API key from News API. Go to [**https://newsapi.org/register**][4] URL and register a free account to get the API key. + +Once you got the API key from News API site, edit your **.bashrc** file: + +``` +$ vi ~/.bashrc + +``` + +Add newsapi API key at the end like below: + +``` +export IN_API_KEY="Paste-API-key-here" + +``` + +Please note that you need to paste the key inside the double quotes. Save and close the file. + +Run the following command to update the changes. + +``` +$ source ~/.bashrc + +``` + +Done. Now let us go ahead and fetch the latest headlines from new sources. + +### Read News And Latest Headlines From Commandline + +To read news and latest headlines from specific new source, for example **The Hindu** , run: + +``` +$ news fetch the-hindu + +``` + +Here, **“the-hindu”** is the new source id (fetch id). + +The above command will fetch latest 10 headlines from The Hindu news portel and display them in the Terminal. Also, it displays a brief description of the news, the published date and time, and the actual link to the source. + +**Sample output:** + +![](https://www.ostechnix.com/wp-content/uploads/2018/09/clinews-1.png) + +To read a news in your browser, hold Ctrl key and click on the URL. It will open in your default web browser. + +To view all the sources you can get news from, run: + +``` +$ news sources + +``` + +**Sample output:** + +![](https://www.ostechnix.com/wp-content/uploads/2018/09/clinews-2.png) + +As you see in the above screenshot, Clinews lists all news sources including the name of the news source, fetch id, description of the site, website URL and the country where it is located. As of writing this guide, Clinews currently supports 70+ news sources. + +Clinews can also able to search for news stories across all sources matching search criteria/term. Say for example, to list all news stories with titles containing the words **“Tamilnadu”** , use the following command: + +``` +$ news search "Tamilnadu" +``` + +This command will scrap all news sources for stories that match term **Tamilnadu**. + +Clinews has some extra flags that helps you to + + * limit the amount of news stories you want to see, + * sort news stories (top, latest, popular), + * display news stories category wise (E.g. business, entertainment, gaming, general, music, politics, science-and-nature, sport, technology) + + + +For more details, see the help section: + +``` +$ clinews -h +``` + +And, that’s all for now. Hope this was useful. More good stuffs to come. Stay tuned! + +Cheers! + + + +-------------------------------------------------------------------------------- + +via: https://www.ostechnix.com/clinews-read-news-and-latest-headlines-from-commandline/ + +作者:[SK][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://www.ostechnix.com/author/sk/ +[1]: https://www.ostechnix.com/get-news-instantly-commandline-linux/ +[2]: https://newsapi.org/ +[3]: https://newsapi.org/sources +[4]: https://newsapi.org/register diff --git a/sources/tech/20180921 Control your data with Syncthing- An open source synchronization tool.md b/sources/tech/20180921 Control your data with Syncthing- An open source synchronization tool.md new file mode 100644 index 0000000000..32be152b4c --- /dev/null +++ b/sources/tech/20180921 Control your data with Syncthing- An open source synchronization tool.md @@ -0,0 +1,108 @@ +Control your data with Syncthing: An open source synchronization tool +====== +Decide how to store and share your personal information. + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/bus_cloud_database.png?itok=lhhU42fg) + +These days, some of our most important possessions—from pictures and videos of family and friends to financial and medical documents—are data. And even as cloud storage services are booming, so there are concerns about privacy and lack of control over our personal data. From the PRISM surveillance program to Google [letting app developers scan your personal emails][1], the news is full of reports that should give us all pause regarding the security of our personal information. + +[Syncthing][2] can help put your mind at ease. An open source peer-to-peer file synchronization tool that runs on Linux, Windows, Mac, Android, and others (sorry, no iOS), Syncthing uses its own protocol, called [Block Exchange Protocol][3]. In brief, Syncthing lets you synchronize your data across many devices without owning a server. + +### Linux + +In this post, I will explain how to install and synchronize files between a Linux computer and an Android phone. + +Syncthing is readily available for most popular distributions. Fedora 28 includes the latest version. + +To install Syncthing in Fedora, you can either search for it in Software Center or execute the following command: + +``` +sudo dnf install syncthing syncthing-gtk + +``` + +Once it’s installed, open it. You’ll be welcomed by an assistant to help configure Syncthing. Click **Next** until it asks to configure the WebUI. The safest option is to keep the option **Listen on localhost**. That will disable the web interface and keep unauthorized users away. + +![Syncthing in Setup WebUI dialog box][5] + +Syncthing in Setup WebUI dialog box + +Close the dialog. Now that Syncthing is installed, it’s time to share a folder, connect a device, and start syncing. But first, let’s continue with your other client. + +### Android + +Syncthing is available in Google Play and in F-Droid app stores. + +![](https://opensource.com/sites/default/files/uploads/syncthing2.png) + +Once the application is installed, you’ll be welcomed by a wizard. Grant Syncthing permissions to your storage. You might be asked to disable battery optimization for this application. It is safe to do so as we will optimize the app to synchronize only when plugged in and connected to a wireless network. + +Click on the main menu icon and go to **Settings** , then **Run Conditions**. Tick **Always run in** **the background** , **Run only when charging** , and **Run only on wifi**. Now your Android client is ready to exchange files with your devices. + +There are two important concepts to remember in Syncthing: folders and devices. Folders are what you want to share, but you must have a device to share with. Syncthing allows you to share individual folders with different devices. Devices are added by exchanging device IDs. A device ID is a unique, cryptographically secure identifier that is created when Syncthing starts for the first time. + +### Connecting devices + +Now let’s connect your Linux machine and your Android client. + +In your Linux computer, open Syncthing, click on the **Settings** icon and click **Show ID**. A QR code will show up. + +In your Android mobile, open Syncthing. In the main screen, click the **Devices** tab and press the **+** symbol. In the first field, press the QR code symbol to open the QR scanner. + +Point your mobile camera to the computer QR code. The Device ID** **field will be populated with your desktop client Device ID. Give it a friendly name and save. Because adding a device goes two ways, you now need to confirm on the computer client that you want to add the Android mobile. It might take a couple of minutes for your computer client to ask for confirmation. When it does, click **Add**. + +![](https://opensource.com/sites/default/files/uploads/syncthing6.png) + +In the **New Device** window, you can verify and configure some options about your new device, like the **Device Name** and **Addresses**. If you keep dynamic, it will try to auto-discover the device IP, but if you want to force one, you can add it in this field. If you already created a folder (more on this later), you can also share it with this new device. + +![](https://opensource.com/sites/default/files/uploads/syncthing7.png) + +Your computer and Android are now paired and ready to exchange files. (If you have more than one computer or mobile phone, simply repeat these steps.) + +### Sharing folders + +Now that the devices you want to sync are already connected, it’s time to share a folder. You can share folders on your computer and the devices you add to that folder will get a copy. + +To share a folder, go to **Settings** and click **Add Shared Folder** : + +![](https://opensource.com/sites/default/files/uploads/syncthing8.png) + +In the next window, enter the information of the folder you want to share: + +![](https://opensource.com/sites/default/files/uploads/syncthing9.png) + +You can use any label you want. **Folder ID** will be generated randomly and will be used to identify the folder between the clients. In **Path** , click **Browse** and locate the folder you want to share. If you want Syncthing to monitor the folder for changes (such as deletes, new files, etc.), click **Monitor filesystem for changes**. + +Remember, when you share a folder, any change that happens on the other clients will be reflected on every single device. That means that if you share a folder containing pictures with other computers or mobile devices, changes in these other clients will be reflected everywhere. If this is not what you want, you can make your folder “Send Only” so it will send files to the clients, but the other clients’ changes won’t be synced. + +When this is done, go to **Share with Devices** and select the hosts you want to sync with your folder: + +All the devices you select will need to accept the share request; you will get a notification from the devices: + +Just as when you shared the folder, you must configure the new shared folder: + +![](https://opensource.com/sites/default/files/uploads/syncthing12.png) + +Again, here you can define any label, but the ID must match each client. In the folder option, select the destination for the folder and its files. Remember that any change done in this folder will be reflected with every device allowed in the folder. + +These are the steps to connect devices and share folders with Syncthing. It might take a few minutes to start copying, depending on your network settings or if you are not on the same network. + +Syncthing offers many more great features and options. Try it—and take control of your data. + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/9/take-control-your-data-syncthing + +作者:[Michael Zamot][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://opensource.com/users/mzamot +[1]: https://gizmodo.com/google-says-it-doesnt-go-through-your-inbox-anymore-bu-1827299695 +[2]: https://syncthing.net/ +[3]: https://docs.syncthing.net/specs/bep-v1.html +[4]: /file/410191 +[5]: https://opensource.com/sites/default/files/uploads/syncthing1.png (Syncthing in Setup WebUI dialog box) diff --git a/sources/tech/20180923 Gunpoint is a Delight for Stealth Game Fans.md b/sources/tech/20180923 Gunpoint is a Delight for Stealth Game Fans.md new file mode 100644 index 0000000000..3ff6857f78 --- /dev/null +++ b/sources/tech/20180923 Gunpoint is a Delight for Stealth Game Fans.md @@ -0,0 +1,104 @@ +Gunpoint is a Delight for Stealth Game Fans +====== +Gunpoint is a 2D stealth game in which you play as a spy stealing secrets and hacking networks like Ethan Hunt of Mission Impossible movie series. + + + +Hi, Fellow Linux gamers. Let’s take a look at a fun stealth game. Let’s take a look at [Gunpoint][1]. + +Gunpoint is neither free nor open source. It is an independent game you can purchase directly from the creator or from Steam. + +![][2] + +### The Interesting History of Gunpoint + +> The instant success of Gunpoint enabled its creator to become a full time game developer. + +Gunpoint is a stealth game created by [Tom Francis][3]. Francis was inspired to create the game after he heard about Spelunky, which was created by one person. Francis played games as part of his day job, as an editor for PC Gamer UK magazine. He had no previous programming experience but used the easy-to-use Game Maker. He planned to create a demo with the hopes of getting a job as a developer. + +He released his first prototype in May 2010 under the name Private Dick. Based on the response, Francis continued to work on the game. The final version was released in June of 2013 to high praise. + +In a [blog post][4] weeks after Gunpoint’s launch, Francis revealed that he made back all the money he spent on development ($30 for Game Maker 8) in 64 seconds. Francis didn’t reveal Gunpoint’s sales figures, but he did quit his job and today creates [games][5] full time. + +### Experiencing the Gunpoint Gameplay + +![Gunpoint Gameplay][6] + +Like I said earlier, Gunpoint is a stealth game. You play a freelance spy named Richard Conway. As Conway, you will use a pair of Bullfrog hypertrousers to infiltrate buildings for clients. The hypertrousers allow you to jump very high, even through windows. You can also cling to walls or ceilings like a ninja. + +Another tool you have is the Crosslink, which allows you to rewire circuits. Often you will need to use the Crosslink to reroute motion detections to unlock doors instead of setting off an alarm or rewire a light switch to turn off the light on another floor to distract a guard. + +When you sneak into a building, your biggest concern is the on-site security guards. If they see Conway, they will shoot and in this game, it’s one shot one kill. You can jump off a three-story building no problem, but bullets will take you down. Thankfully, if Conway is killed you can just jump back a few seconds and try again. + +Along the way, you will earn money to upgrade your tools and unlock new features. For example, I just unlocked the ability to rewire a guard’s gun. Don’t ask me how that works. + +### Minimum System Requirements + +Here are the minimum system requirements for Gunpoint: + +##### Linux + + * Processor: 2GHz + * Memory: 1GB RAM + * Video card: 512MB + * Hard Drive: 700MB HD space + + + +##### Windows + + * OS: Windows XP, Visa, 7 or 8 + * Processor: 2GHz + * Memory: 1GB RAM + * Video card: 512MB + * DirectX®: 9.0 + * Hard Drive: 700MB HD space + + + +##### macOS + + * OS: OS X 10.7 or later + * Processor: 2GHz + * Memory: 1GB RAM + * Video card: 512MB + * Hard Drive: 700MB HD space + + + +### Thoughts on Gunpoint + +![Gunpoint game on Linux][7] +Image Courtesy: Steam Community + +Gunpoint is a very fun game. The early levels are easy to get through, but the later levels make you put your thinking cap on. The hypertrousers and Crosslink are fun to play with. There is nothing like turning the lights off on a guard and bouncing over his head to hack a terminal. + +Besides the fun mechanics, it also has an interesting [noir][8] murder mystery story. Several different (and conflicting) clients hire you to look into different aspects of the case. Some of them seem to have ulterior motives that are not in your best interest. + +I always enjoy good mysteries and this one is no different. If you like noir or platforming games, be sure to check out [Gunpoint][1]. + +Have you every played Gunpoint? What other games should we review for your entertainment? Let us know in the comments below. + +If you found this article interesting, please take a minute to share it on social media, Hacker News or [Reddit][9]. + +-------------------------------------------------------------------------------- + +via: https://itsfoss.com/gunpoint-game-review/ + +作者:[John Paul][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://itsfoss.com/author/john/ +[1]: http://www.gunpointgame.com/ +[2]: https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/08/gunpoint.jpg +[3]: https://www.pentadact.com/ +[4]: https://www.pentadact.com/2013-06-18-gunpoint-recoups-development-costs-in-64-seconds/ +[5]: https://www.pentadact.com/2014-08-09-what-im-working-on-and-what-ive-done/ +[6]: https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/08/gunpoint-gameplay-1.jpeg +[7]: https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/08/gunpoint-game-1.jpeg +[8]: https://en.wikipedia.org/wiki/Noir_fiction +[9]: http://reddit.com/r/linuxusersgroup diff --git a/sources/tech/20180924 5 ways to play old-school games on a Raspberry Pi.md b/sources/tech/20180924 5 ways to play old-school games on a Raspberry Pi.md new file mode 100644 index 0000000000..539ac42082 --- /dev/null +++ b/sources/tech/20180924 5 ways to play old-school games on a Raspberry Pi.md @@ -0,0 +1,169 @@ +5 ways to play old-school games on a Raspberry Pi +====== + +Relive the golden age of gaming with these open source platforms for Raspberry Pi. + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/arcade_game_gaming.jpg?itok=84Rjk_32) + +They don't make 'em like they used to, do they? Video games, I mean. + +Sure, there's a bit more grunt in the gear now. Princess Zelda used to be 16 pixels in each direction; there's now enough graphics power for every hair on her head. Today's processors could beat up 1988's processors in a cage-fight deathmatch without breaking a sweat. + +But you know what's missing? The fun. + +You've got a squillion and one buttons to learn just to get past the tutorial mission. There's probably a storyline, too. You shouldn't need a backstory to kill bad guys. All you need is jump and shoot. So, it's little wonder that one of the most enduring popular uses for a Raspberry Pi is to relive the 8- and 16-bit golden age of gaming in the '80s and early '90s. But where to start? + +There are a few ways to play old-school games on the Pi. Each has its strengths and weaknesses, which I'll discuss here. + +### Retropie + +[Retropie][1] is probably the most popular retro-gaming platform for the Raspberry Pi. It's a solid all-rounder and a great default option for emulating classic desktop and console gaming systems. + +#### What is it? + +Retropie is built to run on [Raspbian][2]. It can also be installed over an existing Raspbian image if you'd prefer. It uses [EmulationStation][3] as a graphical front-end for a library of open source emulators, including the [Libretro][4] emulators. + +You don't need to understand a word of that to play your games, though. + +#### What's great about it + +It's very easy to get started. All you need to do is burn the image to an SD card, configure your controllers, copy your games over, and start killing bad guys. + +The huge user base means that there is a wealth of support and information out there, and active online communities to turn to for questions. + +In addition to the emulators that come installed with the Retropie image, there's a huge library of emulators you can install from the package manager, and it's growing all the time. Retropie also offers a user-friendly menu system to manage this, saving you time. + +From the Retropie menu, it's easy to add Kodi and the Raspbian desktop, which comes with the Chromium web browser. This means your retro-gaming rig is also good for home theatre, [YouTube][5], [SoundCloud][6], and all those other “lounge room computer” goodies. + +Retropie also has a number of other customization options: You can change the graphics in the menus, set up different control pad configurations for different emulators, make your Raspberry Pi file system visible to your local Windows network—all sorts of stuff. + +Retropie is built on Raspbian, which means you have the Raspberry Pi's most popular operating system to explore. Most Raspberry Pi projects and tutorials you find floating around are written for Raspbian, making it easy to customize and install new things on it. I've used my Retropie rig as a wireless bridge, installed MIDI synthesizers on it, taught myself a bit of Python, and more—all without compromising its use as a gaming machine. + +#### What's not so great about it + +Retropie's simple installation and ease of use is, in a way, a double-edged sword. You can go for a long time with Retropie without ever learning simple stuff like `sudo apt-get`, which means you're missing out on a lot of the Raspberry Pi experience. + +It doesn't have to be this way; the command line is still there under the hood when you want it, but perhaps users are a bit too insulated from a Bash shell that's ultimately a lot less scary than it looks. Retropie's main menu is operable only with a control pad, which can be annoying when you don't have one plugged in because you've been using the system for things other than gaming. + +#### Who's it for? + +Anyone who wants to get straight into some gaming, anyone who wants the biggest and best library of emulators, and anyone who wants a great way to start exploring Linux when they're not playing games. + +### Recalbox + +[Recalbox][7] is a newer open source suite of emulators for the Raspberry Pi. It also supports other ARM-based small-board computers. + +#### What is it? + +Like Retropie, Recalbox is built on EmulationStation and Libretro. Where it differs is that it's not built on Raspbian, but on its own flavor of Linux: RecalboxOS. + +#### What's great about it + +The setup for Recalbox is even easier than for Retropie. You don't even need to image an SD card; simply copy some files over and go. It also has out-of-the-box support for some game controllers, getting you to Level 1 that little bit faster. Kodi comes preinstalled. This is a ready-to-go gaming and media rig. + +#### What's not so great about it + +Recalbox has fewer emulators than Retropie, fewer customization options, and a smaller user community. + +Your Recalbox rig is probably always just going to be for emulators and Kodi, the same as when you installed it. If you feel like getting deeper into Linux, you'll probably want a new SD card for Raspbian. + +#### Who's it for? + +Recalbox is great if you want the absolute easiest retro gaming experience and can happily go without some of the more obscure gaming platforms, or if you are intimidated by the idea of doing anything a bit technical (and have no interest in growing out of that). + +For most opensource.com readers, Recalbox will probably come in most handy to recommend to your not-so-technical friend or relative. Its super-simple setup and overall lack of options might even help you avoid having to help them with it. + +### Roll your own + +Ok, if you've been paying attention, you might have noticed that both Retropie and Recalbox are built from many of the same open source components. So what's to stop you from putting them together yourself? + +#### What is it? + +Whatever you want it to be, baby. The nature of open source software means you could use an existing emulator suite as a starting point, or pilfer from them at will. + +#### What's great about it + +If you have your own custom interface in mind, I guess there's nothing to do but roll your sleeves up and get to it. This is also a way to install emulators that haven't quite found their way into Retropie yet, such as [BeebEm][8] or [ArcEm][9]. + +#### What's not so great about it + +Well, it's a bit of work, isn't it? + +#### Who's it for? + +Hackers, tinkerers, builders, seasoned hobbyists, and such. + +### Native RISC OS gaming + +Now here's a dark horse: [RISC OS][10], the original operating system for ARM devices. + +#### What is it? + +Before ARM went on to become the world's most popular CPU architecture, it was originally built to be the heart of the Acorn Archimedes. That's kind of a forgotten beast nowadays, but for a few years it was light years ahead as the most powerful desktop computer in the world, and it attracted a lot of games development. + +Because the ARM processor in the Pi is the great-grandchild of the one in the Archimedes, we can still install RISC OS on it, and with a little bit of work, get these games running. This is different to the emulator options we've covered so far because we're playing our games on the operating system and CPU architecture for which they were written. + +#### What's great about it + +It's the perfect introduction to RISC OS. This is an absolute gem of an operating system and well worth checking out in its own right. + +The fact that you're using much the same operating system as back in the day to load and play your games makes your retro gaming rig just that little bit more of a time machine. This definitely adds some charm and retro value to the project. + +There are a few superb games that were released only on the Archimedes. The massive hardware advantage of the Archimedes also means that it often had the best graphics and smoothest gameplay of a lot of multi-platform titles. The rights holders to many of these games have been generous enough to make them legally available for free download. + +#### What's not so great about it + +Once you have installed RISC OS, it still takes a bit of elbow grease to get the games working. Here's a [guide to getting started][11]. + +This is definitely not a great all-rounder for the lounge room. There's nothing like [Kodi][12]. There's a web browser, [NetSurf][13], but it's struggling to catch up to the modern web. You won't get the range of titles to play as you would with an emulator suite. RISC OS Open is free for hobbyists to download and use and much of the source code has been made open. But despite the name, it's not a 100% open source operating system. + +#### Who's it for? + +This one's for novelty seekers, absolute retro heads, people who want to explore an interesting operating system from the '80s, people who are nostalgic for Acorn machines from back in the day, and people who want a totally different retro gaming project. + +### Command line gaming + +Do you really need to install an emulator or an exotic operating system just to relive the glory days? Why not just install some native linux games from the command line? + +#### What is it? + +There's a whole range of native Linux games tested to work on the [Raspberry Pi][14]. + +#### What's great about it + +You can install most of these from packages using the command line and start playing. Easy. If you've already got Raspbian up and running, it's probably your fastest path to getting a game running. + +#### What's not so great about it + +This isn't, strictly speaking, actual retro gaming. Linux was born in 1991 and took a while longer to come together as a gaming platform. This isn't quite gaming from the classic 8- and 16-bit era; these are ports and retro-influenced games that were built later. + +#### Who's it for? + +If you're just after a bucket of fun, no problem. But if you're trying to relive the actual era, this isn't quite it. + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/9/retro-gaming-raspberry-pi + +作者:[James Mawson][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://opensource.com/users/dxmjames +[1]: https://retropie.org.uk/ +[2]: https://www.raspbian.org/ +[3]: https://emulationstation.org/ +[4]: https://www.libretro.com/ +[5]: https://www.youtube.com/ +[6]: https://soundcloud.com/ +[7]: https://www.recalbox.com/ +[8]: http://www.mkw.me.uk/beebem/ +[9]: http://arcem.sourceforge.net/ +[10]: https://opensource.com/article/18/7/gentle-intro-risc-os +[11]: https://blog.dxmtechsupport.com.au/playing-badass-acorn-archimedes-games-on-a-raspberry-pi/ +[12]: https://kodi.tv/ +[13]: https://www.netsurf-browser.org/ +[14]: https://www.raspberrypi.org/forums/viewtopic.php?f=78&t=51794 diff --git a/sources/tech/20180924 A Simple, Beautiful And Cross-platform Podcast App.md b/sources/tech/20180924 A Simple, Beautiful And Cross-platform Podcast App.md new file mode 100644 index 0000000000..628a805144 --- /dev/null +++ b/sources/tech/20180924 A Simple, Beautiful And Cross-platform Podcast App.md @@ -0,0 +1,114 @@ +translating by Flowsnow + +A Simple, Beautiful And Cross-platform Podcast App +====== + +![](https://www.ostechnix.com/wp-content/uploads/2018/09/cpod-720x340.png) + +Podcasts have become very popular in the last few years. Podcasts are what’s called “infotainment”, they are generally light-hearted, but they generally give you valuable information. Podcasts have blown up in the last few years, and if you like something, chances are there is a podcast about it. There are a lot of podcast players out there for the Linux desktop, but if you want something that is visually beautiful, has slick animations, and works on every platform, there aren’t a lot of alternatives to **CPod**. CPod (formerly known as **Cumulonimbus** ) is an open source and slickest podcast app that works on Linux, MacOS and Windows. + +CPod runs on something called **Electron** – a tool that allows developers to build cross-platform (E.g Windows, MacOs and Linux) desktop GUI applications. In this brief guide, we will be discussing – how to install and use CPod podcast app in Linux. + +### Installing CPod + +Go to the [**releases page**][1] of CPod. Download and Install the binary for your platform of choice. If you use Ubuntu/Debian, you can just download and install the .deb file from the releases page as shown below. + +``` +$ wget https://github.com/z-------------/CPod/releases/download/v1.25.7/CPod_1.25.7_amd64.deb + +$ sudo apt update + +$ sudo apt install gdebi + +$ sudo gdebi CPod_1.25.7_amd64.deb +``` + +If you use any other distribution, you probably should use the **AppImage** in the releases page. + +Download the AppImage file from the releases page. + +Open your terminal, and go to the directory where the AppImage file has been stored. Change the permissions to allow execution: + +``` +$ chmod +x CPod-1.25.7-x86_64.AppImage +``` + +Execute the AppImage File: + +``` +$ ./CPod-1.25.7-x86_64.AppImage +``` + +You’ll be presented a dialog asking whether to integrate the app with the system. Click **Yes** if you want to do so. + +### Features + +**Explore Tab** + +![](https://www.ostechnix.com/wp-content/uploads/2018/09/CPod-features-tab.png) + +CPod uses the Apple iTunes database to find podcasts. This is good, because the iTunes database is the biggest one out there. If there is a podcast out there, chances are it’s on iTunes. To find podcasts, just use the top search bar in the Explore section. The Explore Section also shows a few popular podcasts. + +**Home Tab** + +![](http://www.ostechnix.com/wp-content/uploads/2018/09/CPod-home-tab.png) + +The Home Tab is the tab that opens by default when you open the app. The Home Tab shows a chronological list of all the episodes of all the podcasts that you have subscribed to. + +From the home tab, you can: + + 1. Mark episodes read. + 2. Download them for offline playing + 3. Add them to the queue. + +![](https://www.ostechnix.com/wp-content/uploads/2018/09/The-podcasts-queue.png) + +**Subscriptions Tab** + +![](https://www.ostechnix.com/wp-content/uploads/2018/09/CPod-subscriptions-tab.png) + +You can of course, subscribe to podcasts that you like. A few other things you can do in the Subscriptions Tab is: + + 1. Refresh Podcast Artwork + 2. Export and Import Subscriptions to/from an .OPML file. + + + +**The Player** + +![](https://www.ostechnix.com/wp-content/uploads/2018/09/CPod-Podcast-Player.png) + +The player is perhaps the most beautiful part of CPod. The app changes the overall look and feel according to the banner of the podcast. There’s a sound visualiser at the bottom. To the right, you can see and search for other episodes of this podcast. + +**Cons/Missing Features** + +While I love this app, there are a few features and disadvantages that CPod does have: + + 1. Poor MPRIS Integration – You can play/pause the podcast from the media player dialog of your desktop environment, but not much more. The name of the podcast is not shown, and you can go to the next/previous episode. + 2. No support for chapters. + 3. No auto-downloading – you have to manually download episodes. + 4. CPU usage during use is pretty high (even for an Electron app). + + + +### Verdict + +While it does have its cons, CPod is clearly the most aesthetically pleasing podcast player app out there, and it has most basic features down. If you love using visually beautiful apps, and don’t need the advanced features, this is the perfect app for you. I know for a fact that I’m going to use it. + +Do you like CPod? Please put your opinions on the comments below! + + + +-------------------------------------------------------------------------------- + +via: https://www.ostechnix.com/cpod-a-simple-beautiful-and-cross-platform-podcast-app/ + +作者:[EDITOR][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://www.ostechnix.com/author/editor/ +[1]: https://github.com/z-------------/CPod/releases diff --git a/sources/tech/20180924 Why Linux users should try Rust.md b/sources/tech/20180924 Why Linux users should try Rust.md new file mode 100644 index 0000000000..db60883eb9 --- /dev/null +++ b/sources/tech/20180924 Why Linux users should try Rust.md @@ -0,0 +1,171 @@ +Why Linux users should try Rust +====== + +![](https://images.idgesg.net/images/article/2018/09/rust-rusted-metal-100773678-large.jpg) + +Rust is a fairly young and modern programming language with a lot of features that make it incredibly flexible and very secure. It's also becoming quite popular, having won first place for the "most loved programming language" in the Stack Overflow Developer Survey three years in a row — [2016][1], [2017][2], and [2018][3]. + +Rust is also an _open-source_ language with a suite of special features that allow it to be adapted to many different programming projects. It grew out of what was a personal project of a Mozilla employee back in 2006, was picked up as a special project by Mozilla a few years later (2009), and then announced for public use in 2010. + +Rust programs run incredibly fast, prevent segfaults, and guarantee thread safety. These attributes make the language tremendously appealing to developers focused on application security. Rust is also a very readable language and one that can be used for anything from simple programs to very large and complex projects. + +Rust is: + + * Memory safe — Rust will not suffer from dangling pointers, buffer overflows, or other memory-related errors. And it provides memory safety without garbage collection. + * General purpose — Rust is an appropriate language for any type of programming + * Fast — Rust is comparable in performance to C/C++ but with far better security features. + * Efficient — Rust is built to facilitate concurrent programming. + * Project-oriented — Rust has a built-in dependency and build management system called Cargo. + * Well supported — Rust has an impressive [support community][4]. + + + +Rust also enforces RAII (Resource Acquisition Is Initialization). That means when an object goes out of scope, its destructor will be called and its resources will be freed, providing a shield against resource leaks. It provides functional abstractions and a great [type system][5] together with speed and mathematical soundness. + +In short, Rust is an impressive systems programming language with features that other most languages lack, making it a serious contender for languages like C, C++ and Objective-C that have been used for years. + +### Installing Rust + +Installing Rust is a fairly simple process. + +``` +$ curl https://sh.rustup.rs -sSf | sh +``` + +Once Rust in installed, calling rustc with the **\--version** argument or using the **which** command displays version information. + +``` +$ which rustc +rustc 1.27.2 (58cc626de 2018-07-18) +$ rustc --version +rustc 1.27.2 (58cc626de 2018-07-18) +``` + +### Getting started with Rust + +The simplest code example is not all that different from what you'd enter if you were using one of many scripting languages. + +``` +$ cat hello.rs +fn main() { + // Print a greeting + println!("Hello, world!"); +} +``` + +In these lines, we are setting up a function (main), adding a comment describing the function, and using a println statement to create output. You could compile and then run a program like this using the command shown below. + +``` +$ rustc hello.rs +$ ./hello +Hello, world! +``` + +Alternately, you might create a "project" (generally used only for more complex programs than this one!) to keep your code organized. + +``` +$ mkdir ~/projects +$ cd ~/projects +$ mkdir hello_world +$ cd hello_world +``` + +Notice that even a simple program, once compiled, becomes a fairly large executable. + +``` +$ ./hello +Hello, world! +$ ls -l hello* +-rwxrwxr-x 1 shs shs 5486784 Sep 23 19:02 hello <== executable +-rw-rw-r-- 1 shs shs 68 Sep 23 15:25 hello.rs +``` + +And, of course, that's just a start — the traditional "Hello, world!" program. The Rust language has a suite of features to get you moving quickly to advanced levels of programming skill. + +### Learning Rust + +![rust programming language book cover][6] +No Starch Press + +The Rust Programming Language book by Steve Klabnik and Carol Nichols (2018) provides one of the best ways to learn Rust. Written by two members of the core development team, this book is available in print from [No Starch Press][7] or in ebook format at [rust-lang.org][8]. It has earned its reference as "the book" among the Rust developer community. + +Among the many topics covered, you will learn about these advanced topics: + + * Ownership and borrowing + * Safety guarantees + * Testing and error handling + * Smart pointers and multi-threading + * Advanced pattern matching + * Using Cargo (the built-in package manager) + * Using Rust's advanced compiler + + + +#### Table of Contents + +The table of contents is shown below. + +``` +Foreword by Nicholas Matsakis and Aaron Turon +Acknowledgements +Introduction +Chapter 1: Getting Started +Chapter 2: Guessing Game +Chapter 3: Common Programming Concepts +Chapter 4: Understanding Ownership +Chapter 5: Structs +Chapter 6: Enums and Pattern Matching +Chapter 7: Modules +Chapter 8: Common Collections +Chapter 9: Error Handling +Chapter 10: Generic Types, Traits, and Lifetimes +Chapter 11: Testing +Chapter 12: An Input/Output Project +Chapter 13: Iterators and Closures +Chapter 14: More About Cargo and Crates.io +Chapter 15: Smart Pointers +Chapter 16: Concurrency +Chapter 17: Is Rust Object Oriented? +Chapter 18: Patterns +Chapter 19: More About Lifetimes +Chapter 20: Advanced Type System Features +Appendix A: Keywords +Appendix B: Operators and Symbols +Appendix C: Derivable Traits +Appendix D: Macros +Index + +``` + +[The Rust Programming Language][7] takes you from basic installation and language syntax to complex topics, such as modules, error handling, crates (synonymous with a ‘library’ or ‘package’ in other languages), modules (allowing you to partition your code within the crate itself), lifetimes, etc. + +Probably the most important thing to say is that the book can move you from basic programming skills to building and compiling complex, secure and very useful programs. + +### Wrap-up + +If you're ready to get into some serious programming with a language that's well worth the time and effort to study and becoming increasingly popular, Rust is a good bet! + +Join the Network World communities on [Facebook][9] and [LinkedIn][10] to comment on topics that are top of mind. + +-------------------------------------------------------------------------------- + +via: https://www.networkworld.com/article/3308162/linux/why-you-should-try-rust.html + +作者:[Sandra Henry-Stocker][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://www.networkworld.com/author/Sandra-Henry_Stocker/ +[1]: https://insights.stackoverflow.com/survey/2016#technology-most-loved-dreaded-and-wanted +[2]: https://insights.stackoverflow.com/survey/2017#technology-most-loved-dreaded-and-wanted-languages +[3]: https://insights.stackoverflow.com/survey/2018#technology-most-loved-dreaded-and-wanted-languages +[4]: https://www.rust-lang.org/en-US/community.html +[5]: https://doc.rust-lang.org/reference/type-system.html +[6]: https://images.idgesg.net/images/article/2018/09/rust-programming-language_book-cover-100773679-small.jpg +[7]: https://nostarch.com/Rust +[8]: https://doc.rust-lang.org/book/2018-edition/index.html +[9]: https://www.facebook.com/NetworkWorld/ +[10]: https://www.linkedin.com/company/network-world diff --git a/sources/tech/20180925 9 Easiest Ways To Find Out Process ID (PID) In Linux.md b/sources/tech/20180925 9 Easiest Ways To Find Out Process ID (PID) In Linux.md new file mode 100644 index 0000000000..f542b15808 --- /dev/null +++ b/sources/tech/20180925 9 Easiest Ways To Find Out Process ID (PID) In Linux.md @@ -0,0 +1,209 @@ +【moria(knuth.fan at gmail.com)翻译中】 +9 Easiest Ways To Find Out Process ID (PID) In Linux +====== +Everybody knows about PID, Exactly what is PID? Why you want PID? What are you going to do using PID? Are you having the same questions on your mind? If so, you are in the right place to get all the details. + +Mainly, we are looking PID to kill an unresponsive program and it’s similar to Windows task manager. Linux GUI also offering the same feature but CLI is an efficient way to perform the kill operation. + +### What Is Process ID? + +PID stands for process identification number which is generally used by most operating system kernels such as Linux, Unix, macOS and Windows. It is a unique identification number that is automatically assigned to each process when it is created in an operating system. A process is a running instance of a program. + +**Suggested Read :** +**(#)** [How To Find Out Which Port Number A Process Is Using In Linux][1] +**(#)** [3 Easy Ways To Kill Or Terminate A Process In Linux][2] + +Each time process ID will be getting change to all the processes except init because init is always the first process on the system and is the ancestor of all other processes. It’s PID is 1. + +The default maximum value of PIDs is `32,768`. The same has been verified by running the following command on your system `cat /proc/sys/kernel/pid_max`. On 32-bit systems 32768 is the maximum value but we can set to any value up to 2^22 (approximately 4 million) on 64-bit systems. + +You may ask, why we need such amount of PIDs? because we can’t reused the PIDs immediately that’s why. Also in order to prevent possible errors. + +The PID for the running processes on the system can be found by using the below nine methods such as pidof command, pgrep command, ps command, pstree command, ss command, netstat command, lsof command, fuser command and systemctl command. + +This can be achieved using the below six methods. + + * `pidof:` pidof — find the process ID of a running program. + * `pgrep:` pgre – look up or signal processes based on name and other attributes. + * `ps:` ps – report a snapshot of the current processes. + * `pstree:` pstree – display a tree of processes. + * `ss:` ss is used to dump socket statistics. + * `netstat:` netstat is displays a list of open sockets. + * `lsof:` lsof – list open files. + * `fuser:` fuser – list process IDs of all processes that have one or more files open + * `systemctl:` systemctl – Control the systemd system and service manager + + + +In this tutorial we are going to find out the Apache process id to test this article. Make sure your need to input your process name instead of us. + +### Method-1 : Using pidof Command + +pidof used to find the process ID of a running program. It’s prints those id’s on the standard output. To demonstrate this, we are going to find out the Apache2 process id from Debian 9 (stretch) system. + +``` +# pidof apache2 +3754 2594 2365 2364 2363 2362 2361 + +``` + +From the above output you may face difficulties to identify the Process ID because it’s shows all the PIDs (included Parent and Childs) aginst the process name. Hence we need to find out the parent PID (PPID), which is the one we are looking. It could be the first number. In my case it’s `3754` and it’s shorted in descending order. + +### Method-2 : Using pgrep Command + +pgrep looks through the currently running processes and lists the process IDs which match the selection criteria to stdout. + +``` +# pgrep apache2 +2361 +2362 +2363 +2364 +2365 +2594 +3754 + +``` + +This also similar to the above output but it’s shorting the results in ascending order, which clearly says that the parent PID is the last one. In my case it’s `3754`. + +**Note :** If you have more than one process id of the process, you may face trouble to identify the parent process id when using pidof & pgrep command. + +### Method-3 : Using pstree Command + +pstree shows running processes as a tree. The tree is rooted at either pid or init if pid is omitted. If a user name is specified in the pstree command then it’s shows all the process owned by the corresponding user. + +pstree visually merges identical branches by putting them in square brackets and prefixing them with the repetition count. + +``` +# pstree -p | grep "apache2" + |-apache2(3754)-|-apache2(2361) + | |-apache2(2362) + | |-apache2(2363) + | |-apache2(2364) + | |-apache2(2365) + | `-apache2(2594) + +``` + +To get parent process alone, use the following format. + +``` +# pstree -p | grep "apache2" | head -1 + |-apache2(3754)-|-apache2(2361) + +``` + +pstree command is very simple because it’s segregating the Parent and Child processes separately but it’s not easy when using pidof & pgrep command. + +### Method-4 : Using ps Command + +ps displays information about a selection of the active processes. It displays the process ID (pid=PID), the terminal associated with the process (tname=TTY), the cumulated CPU time in [DD-]hh:mm:ss format (time=TIME), and the executable name (ucmd=CMD). Output is unsorted by default. + +``` +# ps aux | grep "apache2" +www-data 2361 0.0 0.4 302652 9732 ? S 06:25 0:00 /usr/sbin/apache2 -k start +www-data 2362 0.0 0.4 302652 9732 ? S 06:25 0:00 /usr/sbin/apache2 -k start +www-data 2363 0.0 0.4 302652 9732 ? S 06:25 0:00 /usr/sbin/apache2 -k start +www-data 2364 0.0 0.4 302652 9732 ? S 06:25 0:00 /usr/sbin/apache2 -k start +www-data 2365 0.0 0.4 302652 8400 ? S 06:25 0:00 /usr/sbin/apache2 -k start +www-data 2594 0.0 0.4 302652 8400 ? S 06:55 0:00 /usr/sbin/apache2 -k start +root 3754 0.0 1.4 302580 29324 ? Ss Dec11 0:23 /usr/sbin/apache2 -k start +root 5648 0.0 0.0 12784 940 pts/0 S+ 21:32 0:00 grep apache2 + +``` + +From the above output we can easily identify the parent process id (PPID) based on the process start date. In my case apache2 process was started @ `Dec11` which is the parent and others are child’s. PID of apache2 is `3754`. + +### Method-5: Using ss Command + +ss is used to dump socket statistics. It allows showing information similar to netstat. It can display more TCP and state informations than other tools. + +It can display stats for all kind of sockets such as PACKET, TCP, UDP, DCCP, RAW, Unix domain, etc. + +``` +# ss -tnlp | grep apache2 +LISTEN 0 128 :::80 :::* users:(("apache2",pid=3319,fd=4),("apache2",pid=3318,fd=4),("apache2",pid=3317,fd=4)) + +``` + +### Method-6: Using netstat Command + +netstat – Print network connections, routing tables, interface statistics, masquerade connections, and multicast memberships. +By default, netstat displays a list of open sockets. + +If you don’t specify any address families, then the active sockets of all configured address families will be printed. This program is obsolete. Replacement for netstat is ss. + +``` +# netstat -tnlp | grep apache2 +tcp6 0 0 :::80 :::* LISTEN 3317/apache2 + +``` + +### Method-7: Using lsof Command + +lsof – list open files. The Linux lsof command lists information about files that are open by processes running on the system. + +``` +# lsof -i -P | grep apache2 +apache2 3317 root 4u IPv6 40518 0t0 TCP *:80 (LISTEN) +apache2 3318 www-data 4u IPv6 40518 0t0 TCP *:80 (LISTEN) +apache2 3319 www-data 4u IPv6 40518 0t0 TCP *:80 (LISTEN) + +``` + +### Method-8: Using fuser Command + +The fuser utility shall write to standard output the process IDs of processes running on the local system that have one or more named files open. + +``` +# fuser -v 80/tcp + USER PID ACCESS COMMAND +80/tcp: root 3317 F.... apache2 + www-data 3318 F.... apache2 + www-data 3319 F.... apache2 + +``` + +### Method-9: Using systemctl Command + +systemctl – Control the systemd system and service manager. This is the replacement of old SysV init system management and +most of the modern Linux operating systems were adapted systemd. + +``` +# systemctl status apache2 +● apache2.service - The Apache HTTP Server + Loaded: loaded (/lib/systemd/system/apache2.service; disabled; vendor preset: enabled) + Drop-In: /lib/systemd/system/apache2.service.d + └─apache2-systemd.conf + Active: active (running) since Tue 2018-09-25 10:03:28 IST; 3s ago + Process: 3294 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/SUCCESS) + Main PID: 3317 (apache2) + Tasks: 55 (limit: 4915) + Memory: 7.9M + CPU: 71ms + CGroup: /system.slice/apache2.service + ├─3317 /usr/sbin/apache2 -k start + ├─3318 /usr/sbin/apache2 -k start + └─3319 /usr/sbin/apache2 -k start + +Sep 25 10:03:28 ubuntu systemd[1]: Starting The Apache HTTP Server... +Sep 25 10:03:28 ubuntu systemd[1]: Started The Apache HTTP Server. + +``` + + +-------------------------------------------------------------------------------- + +via: https://www.2daygeek.com/9-methods-to-check-find-the-process-id-pid-ppid-of-a-running-program-in-linux/ + +作者:[Magesh Maruthamuthu][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://www.2daygeek.com/author/magesh/ +[1]: https://www.2daygeek.com/how-to-find-out-which-port-number-a-process-is-using-in-linux/ +[2]: https://www.2daygeek.com/kill-terminate-a-process-in-linux-using-kill-pkill-killall-command/ diff --git a/sources/tech/20180925 Hegemon - A Modular System Monitor Application Written In Rust.md b/sources/tech/20180925 Hegemon - A Modular System Monitor Application Written In Rust.md new file mode 100644 index 0000000000..a75c1f3e9a --- /dev/null +++ b/sources/tech/20180925 Hegemon - A Modular System Monitor Application Written In Rust.md @@ -0,0 +1,80 @@ +translating---geekpi + +Hegemon – A Modular System Monitor Application Written In Rust +====== + +![](https://www.ostechnix.com/wp-content/uploads/2018/09/hegemon-720x340.png) + +When it comes to monitor running processes in Unix-like systems, the most commonly used applications are **top** and **htop** , which is an enhanced version of top. My personal favorite is htop. However, the developers are releasing few alternatives to these applications every now and then. One such alternative to top and htop utilities is **Hegemon**. It is a modular system monitor application written using **Rust** programming language. + +Concerning about the features of Hegemon, we can list the following: + + * Hegemon will monitor the usage of CPU, memory and Swap. + * It monitors the system’s temperature and fan speed. + * The update interval time can be adjustable. The default value is 3 seconds. + * We can reveal more detailed graph and additional information by expanding the data streams. + * Unit tests + * Clean interface + * Free and open source. + + + +### Installing Hegemon + +Make sure you have installed **Rust 1.26** or later version. To install Rust in your Linux distribution, refer the following guide: + +[Install Rust Programming Language In Linux][2] + +Also, install [libsensors][1] library. It is available in the default repositories of most Linux distributions. For example, you can install it in RPM based systems such as Fedora using the following command: + +``` +$ sudo dnf install lm_sensors-devel +``` + +On Debian-based systems like Ubuntu, Linux Mint, it can be installed using command: + +``` +$ sudo apt-get install libsensors4-dev +``` + +Once you installed Rust and libsensors, install Hegemon using command: + +``` +$ cargo install hegemon +``` + +Once hegemon installed, start monitoring the running processes in your Linux system using command: + +``` +$ hegemon +``` + +Here is the sample output from my Arch Linux desktop. + +![](https://www.ostechnix.com/wp-content/uploads/2018/09/Hegemon-in-action.gif) + +To exit, press **Q**. + + +Please be mindful that hegemon is still in its early development stage and it is not complete replacement for **top** command. There might be bugs and missing features. If you came across any bugs, report them in the project’s github page. The developer is planning to bring more features in the upcoming versions. So, keep an eye on this project. + +And, that’s all for now. Hope this helps. More good stuffs to come. Stay tuned! + +Cheers! + + + +-------------------------------------------------------------------------------- + +via: https://www.ostechnix.com/hegemon-a-modular-system-monitor-application-written-in-rust/ + +作者:[SK][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://www.ostechnix.com/author/sk/ +[1]: https://github.com/lm-sensors/lm-sensors +[2]: https://www.ostechnix.com/install-rust-programming-language-in-linux/ diff --git a/sources/tech/20180925 How to Boot Ubuntu 18.04 - Debian 9 Server in Rescue (Single User mode) - Emergency Mode.md b/sources/tech/20180925 How to Boot Ubuntu 18.04 - Debian 9 Server in Rescue (Single User mode) - Emergency Mode.md new file mode 100644 index 0000000000..ff33e7c175 --- /dev/null +++ b/sources/tech/20180925 How to Boot Ubuntu 18.04 - Debian 9 Server in Rescue (Single User mode) - Emergency Mode.md @@ -0,0 +1,88 @@ +How to Boot Ubuntu 18.04 / Debian 9 Server in Rescue (Single User mode) / Emergency Mode +====== +Booting a Linux Server into a single user mode or **rescue mode** is one of the important troubleshooting that a Linux admin usually follow while recovering the server from critical conditions. In Ubuntu 18.04 and Debian 9, single user mode is known as a rescue mode. + +Apart from the rescue mode, Linux servers can be booted in **emergency mode** , the main difference between them is that, emergency mode loads a minimal environment with read only root file system file system, also it does not enable any network or other services. But rescue mode try to mount all the local file systems & try to start some important services including network. + +In this article we will discuss how we can boot our Ubuntu 18.04 LTS / Debian 9 Server in rescue mode and emergency mode. + +#### Booting Ubuntu 18.04 LTS Server in Single User / Rescue Mode: + +Reboot your server and go to boot loader (Grub) screen and Select “ **Ubuntu** “, bootloader screen would look like below, + +![](https://www.linuxtechi.com/wp-content/uploads/2018/09/Bootloader-Screen-Ubuntu18-04-Server.jpg) + +Press “ **e** ” and then go the end of line which starts with word “ **linux** ” and append “ **systemd.unit=rescue.target** “. Remove the word “ **$vt_handoff** ” if it exists. + +![](https://www.linuxtechi.com/wp-content/uploads/2018/09/rescue-target-ubuntu18-04.jpg) + +Now Press Ctrl-x or F10 to boot, + +![](https://www.linuxtechi.com/wp-content/uploads/2018/09/rescue-mode-ubuntu18-04.jpg) + +Now press enter and then you will get the shell where all file systems will be mounted in read-write mode and do the troubleshooting. Once you are done with troubleshooting, you can reboot your server using “ **reboot** ” command. + +#### Booting Ubuntu 18.04 LTS Server in emergency mode + +Reboot the server and go the boot loader screen and select “ **Ubuntu** ” and then press “ **e** ” and go to the end of line which starts with word linux, and append “ **systemd.unit=emergency.target** ” + +![](https://www.linuxtechi.com/wp-content/uploads/2018/09/Emergecny-target-ubuntu18-04-server.jpg) + +Now Press Ctlr-x or F10 to boot in emergency mode, you will get a shell and do the troubleshooting from there. As we had already discussed that in emergency mode, file systems will be mounted in read-only mode and also there will be no networking in this mode, + +![](https://www.linuxtechi.com/wp-content/uploads/2018/09/Emergency-prompt-debian9.jpg) + +Use below command to mount the root file system in read-write mode, + +``` +# mount -o remount,rw / + +``` + +Similarly, you can remount rest of file systems in read-write mode . + +#### Booting Debian 9 into Rescue & Emergency Mode + +Reboot your Debian 9.x server and go to grub screen and select “ **Debian GNU/Linux** ” + +![](https://www.linuxtechi.com/wp-content/uploads/2018/09/Debian9-Grub-Screen.jpg) + +Press “ **e** ” and go to end of line which starts with word linux and append “ **systemd.unit=rescue.target** ” to boot the system in rescue mode and to boot in emergency mode then append “ **systemd.unit=emergency.target** ” + +#### Rescue mode : + +![](https://www.linuxtechi.com/wp-content/uploads/2018/09/Rescue-mode-Debian9.jpg) + +Now press Ctrl-x or F10 to boot in rescue mode + +![](https://www.linuxtechi.com/wp-content/uploads/2018/09/Rescue-Mode-Shell-Debian9.jpg) + +Press Enter to get the shell and from there you can start troubleshooting. + +#### Emergency Mode: + +![](https://www.linuxtechi.com/wp-content/uploads/2018/09/Emergency-target-grub-debian9.jpg) + +Now press ctrl-x or F10 to boot your system in emergency mode + +![](https://www.linuxtechi.com/wp-content/uploads/2018/09/Emergency-prompt-debian9.jpg) + +Press enter to get the shell and use “ **mount -o remount,rw /** ” command to mount the root file system in read-write mode. + +**Note:** In case root password is already set in Ubuntu 18.04 and Debian 9 Server then you must enter root password to get shell in rescue and emergency mode + +That’s all from this article, please do share your feedback and comments in case you like this article. + + +-------------------------------------------------------------------------------- + +via: https://www.linuxtechi.com/boot-ubuntu-18-04-debian-9-rescue-emergency-mode/ + +作者:[Pradeep Kumar][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: http://www.linuxtechi.com/author/pradeep/ diff --git a/sources/tech/20180925 How to Replace one Linux Distro With Another in Dual Boot -Guide.md b/sources/tech/20180925 How to Replace one Linux Distro With Another in Dual Boot -Guide.md new file mode 100644 index 0000000000..ab9fa8acc3 --- /dev/null +++ b/sources/tech/20180925 How to Replace one Linux Distro With Another in Dual Boot -Guide.md @@ -0,0 +1,160 @@ +How to Replace one Linux Distro With Another in Dual Boot [Guide] +====== +**If you have a Linux distribution installed, you can replace it with another distribution in the dual boot. You can also keep your personal documents while switching the distribution.** + +![How to Replace One Linux Distribution With Another From Dual Boot][1] + +Suppose you managed to [successfully dual boot Ubuntu and Windows][2]. But after reading the [Linux Mint versus Ubuntu discussion][3], you realized that [Linux Mint][4] is more suited for your needs. What would you do now? How would you [remove Ubuntu][5] and [install Mint in dual boot][6]? + +You might think that you need to uninstall [Ubuntu][7] from dual boot first and then repeat the dual booting steps with Linux Mint. Let me tell you something. You don’t need to do all of that. + +If you already have a Linux distribution installed in dual boot, you can easily replace it with another. You don’t have to uninstall the existing Linux distribution. You simply delete its partition and install the new distribution on the disk space vacated by the previous distribution. + +Another good news is that you may be able to keep your Home directory with all your documents and pictures while switching the Linux distributions. + +Let me show you how to switch Linux distributions. + +### Replace one Linux with another from dual boot + + + +Let me describe the scenario I am going to use here. I have Linux Mint 19 installed on my system in dual boot mode with Windows 10. I am going to replace it with elementary OS 5. I’ll also keep my personal files (music, pictures, videos, documents from my home directory) while switching distributions. + +Let’s first take a look at the requirements: + + * A system with Linux and Windows dual boot + * Live USB of Linux you want to install + * Backup of your important files in Windows and in Linux on an external disk (optional yet recommended) + + + +#### Things to keep in mind for keeping your home directory while changing Linux distribution + +If you want to keep your files from existing Linux install as it is, you must have a separate root and home directory. You might have noticed that in my [dual boot tutorials][8], I always go for ‘Something Else’ option and then manually create root and home partitions instead of choosing ‘Install alongside Windows’ option. This is where all the troubles in manually creating separate home partition pay off. + +Keeping Home on a separate partition is helpful in situations when you want to replace your existing Linux install with another without losing your files. + +Note: You must remember the exact username and password of your existing Linux install in order to use the same home directory as it is in the new distribution. + +If you don’t have a separate Home partition, you may create it later as well BUT I won’t recommend that. That process is slightly complicated and I don’t want you to mess up your system. + +With that much background information, it’s time to see how to replace a Linux distribution with another. + +#### Step 1: Create a live USB of the new Linux distribution + +Alright! I already mentioned it in the requirements but I still included it in the main steps to avoid confusion. + +You can create a live USB using a start up disk creator like [Etcher][9] in Windows or Linux. The process is simple so I am not going to list the steps here. + +#### Step 2: Boot into live USB and proceed to installing Linux + +Since you have already dual booted before, you probably know the drill. Plugin the live USB, restart your system and at the boot time, press F10 or F12 repeatedly to enter BIOS settings. + +In here, choose to boot from the USB. And then you’ll see the option to try the live environment or installing it immediately. + +You should start the installation procedure. When you reach the ‘Installation type’ screen, choose the ‘Something else’ option. + +![Replacing one Linux with another from dual boot][10] +Select ‘Something else’ here + +#### Step 3: Prepare the partition + +You’ll see the partitioning screen now. Look closely and you’ll see your Linux installation with Ext4 file system type. + +![Identifying Linux partition in dual boot][11] +Identify where your Linux is installed + +In the above picture, the Ext4 partition labeled as Linux Mint 19 is the root partition. The second Ext4 partition of 82691 MB is the Home partition. I [haven’t used any swap space][12] here. + +Now, if you have just one Ext4 partition, that means that your home directory is on the same partition as root. In this case, you won’t be able to keep your Home directory. I suggest that you copy the important files to an external disk else you’ll lose them forever. + +It’s time to delete the root partition. Select the root partition and click the – sign. This will create some free space. + +![Delete root partition of your existing Linux install][13] +Delete root partition + +When you have the free space, click on + sign. + +![Create root partition for the new Linux][14] +Create a new root partition + +Now you should create a new partition out of this free space. If you had just one root partition in your previous Linux install, you should create root and home partitions here. You can also create the swap partition if you want to. + +If you had root and home partition separately, just create a root partition from the deleted root partition. + +![Create root partition for the new Linux][15] +Creating root partition + +You may ask why did I use delete and add instead of using the ‘change’ option. It’s because a few years ago, using change didn’t work for me. So I prefer to do a – and +. Is it superstition? Maybe. + +One important thing to do here is to mark the newly created partition for format. f you don’t change the size of the partition, it won’t be formatted unless you explicitly ask it to format. And if the partition is not formatted, you’ll have issues. + +![][16] +It’s important to format the root partition + +Now if you already had a separate Home partition on your existing Linux install, you should select it and click on change. + +![Recreate home partition][17] +Retouch the already existing home partition (if any) + +You just have to specify that you are mounting it as home partition. + +![Specify the home mount point][18] +Specify the home mount point + +If you had a swap partition, you can repeat the same steps as the home partition. This time specify that you want to use the space as swap. + +At this stage, you should have a root partition (with format option selected) and a home partition (and a swap if you want to). Hit the install now button to start the installation. + +![Verify partitions while replacing one Linux with another][19] +Verify the partitions + +The next few screens would be familiar to you. What matters is the screen where you are asked to create user and password. + +If you had a separate home partition previously and you want to use the same home directory, you MUST use the same username and password that you had before. Computer name doesn’t matter. + +![To keep the home partition intact, use the previous user and password][20] +To keep the home partition intact, use the previous user and password + +Your struggle is almost over. You don’t have to do anything else other than waiting for the installation to finish. + +![Wait for installation to finish][21] +Wait for installation to finish + +Once the installation is over, restart your system. You’ll have a new Linux distribution or version. + +In my case, I had the entire home directory of Linux Mint 19 as it is in the elementary OS. All the videos, pictures I had remained as it is. Isn’t that nice? + +-------------------------------------------------------------------------------- + +via: https://itsfoss.com/replace-linux-from-dual-boot/ + +作者:[Abhishek Prakash][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://itsfoss.com/author/abhishek/ +[1]: https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/09/Replace-Linux-Distro-from-dual-boot.png +[2]: https://itsfoss.com/install-ubuntu-1404-dual-boot-mode-windows-8-81-uefi/ +[3]: https://itsfoss.com/linux-mint-vs-ubuntu/ +[4]: https://www.linuxmint.com/ +[5]: https://itsfoss.com/uninstall-ubuntu-linux-windows-dual-boot/ +[6]: https://itsfoss.com/guide-install-linux-mint-16-dual-boot-windows/ +[7]: https://www.ubuntu.com/ +[8]: https://itsfoss.com/guide-install-elementary-os-luna/ +[9]: https://etcher.io/ +[10]: https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/09/replace-linux-with-another-1.jpg +[11]: https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/09/replace-linux-with-another-2.jpg +[12]: https://itsfoss.com/swap-size/ +[13]: https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/09/replace-linux-with-another-3.jpg +[14]: https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/09/replace-linux-with-another-4.jpg +[15]: https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/09/replace-linux-with-another-5.jpg +[16]: https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/09/replace-linux-with-another-6.jpg +[17]: https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/09/replace-linux-with-another-7.jpg +[18]: https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/09/replace-linux-with-another-8.jpg +[19]: https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/09/replace-linux-with-another-9.jpg +[20]: https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/09/replace-linux-with-another-10.jpg +[21]: https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/09/replace-linux-with-another-11.jpg diff --git a/sources/tech/20180925 Taking the Audiophile Linux distro for a spin.md b/sources/tech/20180925 Taking the Audiophile Linux distro for a spin.md new file mode 100644 index 0000000000..1c813cb30a --- /dev/null +++ b/sources/tech/20180925 Taking the Audiophile Linux distro for a spin.md @@ -0,0 +1,161 @@ +Taking the Audiophile Linux distro for a spin +====== + +This lightweight open source audio OS offers a rich feature set and high-quality digital sound. + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/LIFE_givingmusic.jpg?itok=xVKF1dlb) + +I recently stumbled on the [Audiophile Linux project][1], one of a number of special-purpose music-oriented Linux distributions. Audiophile Linux: + + 1. is based on [ArchLinux][2] + + 2. provides a real-time Linux kernel customized for playing music + + 3. uses the lightweight [Fluxbox][3] window manager + + 4. avoids unnecessary daemons and services + + 5. allows playback of DSF and supports the usual PCM formats + + 6. supports various music players, including one of my favorite combos: MPD + Cantata + + + + +The Audiophile Linux site hasn’t shown a lot of activity since April 2017, but it does contain some updates and commentary from this year. Given its orientation and feature set, I decided to take it for a spin on my old Toshiba laptop. + +### Installing Audiophile Linux + +The site provides [a clear set of install instructions][4] that require the use of the terminal. The first step after downloading the .iso is burning it to a USB stick. I used the GNOME Disks utility’s Restore Disk Image for this purpose. Once I had the USB set up and ready to go, I plugged it into the Toshiba and booted it. When the splash screen came up, I set the boot device to the USB stick and a minute or so later, the Arch Grub menu was displayed. I booted Linux from that menu, which put me in a root shell session, where I could carry out the install to the hard drive: + +![](https://opensource.com/sites/default/files/uploads/root_shell_session.jpg) + +I was willing to sacrifice the 320-GB hard drive in the Toshiba for this test, so I was able to use the previous Linux partitioning (from the last experiment). I then proceeded as follows: + +``` +fdisk -l              # find the disk / partition, in my case /dev/sda and /dev/sda1 +mkfs.ext4 /dev/sda1   # build the ext4 filesystem in the root partition +mount /dev/sda1 /mnt  # mount the new file system +time cp -ax / /mnt    # copy over the OS +        # reported back cp -ax / /mnt 1.36s user 136.54s system 88% cpu 2:36.37 total +arch-chroot /mnt /bin/bash # run in the new system root +cd /etc/apl-files +./runme.sh            # do the rest of the install +grub-install --target=i386-pc /dev/sda # make the new OS bootable part 1 +grub-mkconfig -o /boot/grub/grub.cfg   # part 2 +passwd root           # set root’s password +ln -s /usr/share/zoneinfo/America/Vancouver /etc/localtime # set my time zone +hwclock --systohc --utc # update the hardware clock +./autologin.sh        # set the system up so that it automatically logs in +exit                  # done with the chroot session +genfstab -U /mnt >> /mnt/etc/fstab # create the fstab for the new system +``` + +At that point, I was ready to boot the new operating system, so I did—and voilà, up came the system! + +![](https://opensource.com/sites/default/files/uploads/audiophile_linux.jpg) + +### Finishing the configuration + +Once Audiophile Linux was up and running, I needed to [finish the configuration][4] and load some music. Grabbing the application menu by right-clicking on the screen background, I started **X-terminal** and entered the remaining configuration commands: + +``` +ping 8.8.8.8 # check connectivity (works fine) +su # become root +pacman-key –init # create pacman’s encryption data part 1 +pacman-key --populate archlinux # part 2 +pacman -Sy # part 3 +pacman -S archlinux-keyring # part 4 +``` + +At this point, the install instructions note that there is a problem with updating software with the `pacman -Suy` command, and that first the **libxfont** package must be removed using `pacman -Rc libxfont`. I followed this instruction, but the second run of `pacman -Suy` led to another dependency error, this time with the **x265** package. I looked further down the page in the install instructions and saw this recommendation: + +_Again there is an error in upstream repo of Arch packages. Try to remove conflicting packages with “pacman -R ffmpeg2.8” and then do pacman -Suy later._ + +I chose to use `pacman -Rc ffmpeg2.8`, and then reran `pacman -Suy`. (As an aside, typing all these **pacman** commands made me realize how familiar I am with **apt** , and how much this whole process made me feel like I was trying to write an email in some language I don’t know using an online translator.) + +To be clear, here was my sequence of operations: + +``` +pacman -Suy # failed +pacman -Rc libxfont +pacman -Suy # failed, again +pacman -Rc ffmpeg2.8 # uninstalled Cantata, have to fix that later! +pacman -Suy # worked! +``` + +Now back to the rest of the instructions: + +``` +pacman -S terminus-font +pacman -S xorg-server +pacman -S firefox # the docs suggested installing chromium but I prefer FF +reboot +``` + +And the last little bit, fiddling `/etc/fstab` to avoid access time modifications. I also thought I’d try installing [Cantata][5] once more using `pacman -S cantata`, and it worked just fine (no `ffmpeg2.8` problems). + +I found the `DAC Setup > List cards` on the application menu, which showed the built-in Intel sound hardware plus my USB DAC that I had plugged in earlier. Then I selected `DAC Setup > Edit mpd.conf` and adjusted the output stanza of `mpd.conf`. I used `scp` to copy an album over from my main music server into **~/Music**. And finally, I used the application menu `DAC Setup > Restart mpd`. And… nothing… the **conky** info on the screen indicated “MPD not responding”. So I scanned again through the comments at the bottom of the installation instructions and spotted this: + +_After every update of mpd, you have to do: +1. Become root +``` +$su +``` +2. run this commands +``` +# cat /etc/apl-files/mpd.service > /usr/lib/systemd/system/mpd.service +# systemctl daemon-reload +# systemctl restart mpd.service_ +``` +_And this will be fixed._ + +![](https://opensource.com/sites/default/files/uploads/library.png) + +And it works! Right now I’m enjoying [Nils Frahm’s "All Melody"][6] from the album of the same name, playing over my [Schiit Fulla 2][7] in glorious high-resolution sound. Time to copy in some more music so I can give it a better listen. + +So… does it sound better than the same DAC connected to my regular work laptop and playing back through [Guayadeque][8] or [GogglesMM][9]? I’m going to see if I can detect a difference at some point, but right now all I can say is it sounds just wonderful; plus [I like the Cantata / mpd combo a lot][10], and I really enjoy having the heads-up display in the upper right of the screen. + +### As for the music... + +The other day I was reorganizing my work hard drive a bit and I decided to check to make sure that 1) all the music on it was also on the house music servers and 2) _vice versa_ (gotta set up `rsync` for that purpose one day soon). In doing so, I found some music I hadn’t enjoyed for a while, which is kind of like buying a brand-new album, except it costs much less. + +[Six Degrees Records][11] has long been one of my favorite purveyors of unusual music. A great example is the group [Zuco 103][12]'s album [Whaa!][13], whose CD version I purchased from Six Degrees’ online store some years ago. Check out [this fun documentary about the group][14]. + + + +For a completely different experience, take a look at the [Ragazze Quartet’s performance of Terry Riley’s "Four Four Three."][15] I picked up ahigh-resolutionn version of this fascinating music from [Channel Classics][16], which operates a Linux-friendly download store (no bloatware to install on your computer). + +And finally, I was saddened to hear of the recent passing of [Rachid Taha][17], whose wonderful blend of North African and French musical traditions, along with his frank confrontation of the challenges of being North African and living in Europe, has made some powerful—and fun—music. Check out [Taha’s version of "Rock the Casbah."][18] I have a few of his songs scattered around various compilation albums, and some time ago bought the CD version of [Rachid Taha: The Definitive Collection][19], which I’ve been enjoying again recently. + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/9/audiophile-linux-distro + +作者:[Chris Hermansen][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://opensource.com/users/clhermansen +[1]: https://www.ap-linux.com/ +[2]: https://www.archlinux.org/ +[3]: http://fluxbox.org/ +[4]: https://www.ap-linux.com/documentation/ap-linux-v4-install-instructions/ +[5]: https://github.com/CDrummond/cantata +[6]: https://www.youtube.com/watch?v=1PTj1qIqcWM +[7]: https://www.audiostream.com/content/listening-session-history-lesson-bw-schiit-and-shinola-together-last +[8]: http://www.guayadeque.org/ +[9]: https://gogglesmm.github.io/ +[10]: https://opensource.com/article/17/8/cantata-music-linux +[11]: https://www.sixdegreesrecords.com/ +[12]: https://www.sixdegreesrecords.com/?s=zuco+103 +[13]: https://www.musicomh.com/reviews/albums/zuco-103-whaa +[14]: https://www.youtube.com/watch?v=ncaqD92cjQ8 +[15]: https://www.youtube.com/watch?v=DwMaO7bMVD4 +[16]: https://www.channelclassics.com/catalogue/37816-Riley-Four-Four-Three/ +[17]: https://en.wikipedia.org/wiki/Rachid_Taha +[18]: https://www.youtube.com/watch?v=n1p_dkJo6Y8 +[19]: http://www.bbc.co.uk/music/reviews/26rg/ diff --git a/sources/tech/20180926 3 open source distributed tracing tools.md b/sources/tech/20180926 3 open source distributed tracing tools.md new file mode 100644 index 0000000000..9879302d38 --- /dev/null +++ b/sources/tech/20180926 3 open source distributed tracing tools.md @@ -0,0 +1,90 @@ +translating by belitex + +3 open source distributed tracing tools +====== + +Find performance issues quickly with these tools, which provide a graphical view of what's happening across complex software systems. + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/server_data_system_admin.png?itok=q6HCfNQ8) + +Distributed tracing systems enable users to track a request through a software system that is distributed across multiple applications, services, and databases as well as intermediaries like proxies. This allows for a deeper understanding of what is happening within the software system. These systems produce graphical representations that show how much time the request took on each step and list each known step. + +A user reviewing this content can determine where the system is experiencing latencies or blockages. Instead of testing the system like a binary search tree when requests start failing, operators and developers can see exactly where the issues begin. This can also reveal where performance changes might be occurring from deployment to deployment. It’s always better to catch regressions automatically by alerting to the anomalous behavior than to have your customers tell you. + +How does this tracing thing work? Well, each request gets a special ID that’s usually injected into the headers. This ID uniquely identifies that transaction. This transaction is normally called a trace. The trace is the overall abstract idea of the entire transaction. Each trace is made up of spans. These spans are the actual work being performed, like a service call or a database request. Each span also has a unique ID. Spans can create subsequent spans called child spans, and child spans can have multiple parents. + +Once a transaction (or trace) has run its course, it can be searched in a presentation layer. There are several tools in this space that we’ll discuss later, but the picture below shows [Jaeger][1] from my [Istio walkthrough][2]. It shows multiple spans of a single trace. The power of this is immediately clear as you can better understand the transaction’s story at a glance. + +![](https://opensource.com/sites/default/files/uploads/monitoring_guide_jaeger_istio_0.png) + +This demo uses Istio’s built-in OpenTracing implementation, so I can get tracing without even modifying my application. It also uses Jaeger, which is OpenTracing-compatible. + +So what is OpenTracing? Let’s find out. + +### OpenTracing API + +[OpenTracing][3] is a spec that grew out of [Zipkin][4] to provide cross-platform compatibility. It offers a vendor-neutral API for adding tracing to applications and delivering that data into distributed tracing systems. A library written for the OpenTracing spec can be used with any system that is OpenTracing-compliant. Zipkin, Jaeger, and Appdash are examples of open source tools that have adopted the open standard, but even proprietary tools like [Datadog][5] and [Instana][6] are adopting it. This is expected to continue as OpenTracing reaches ubiquitous status. + +### OpenCensus + +Okay, we have OpenTracing, but what is this [OpenCensus][7] thing that keeps popping up in my searches? Is it a competing standard, something completely different, or something complementary? + +The answer depends on who you ask. I will do my best to explain the difference (as I understand it): OpenCensus takes a more holistic or all-inclusive approach. OpenTracing is focused on establishing an open API and spec and not on open implementations for each language and tracing system. OpenCensus provides not only the specification but also the language implementations and wire protocol. It also goes beyond tracing by including additional metrics that are normally outside the scope of distributed tracing systems. + +OpenCensus allows viewing data on the host where the application is running, but it also has a pluggable exporter system for exporting data to central aggregators. The current exporters produced by the OpenCensus team include Zipkin, Prometheus, Jaeger, Stackdriver, Datadog, and SignalFx, but anyone can create an exporter. + +From my perspective, there’s a lot of overlap. One isn’t necessarily better than the other, but it’s important to know what each does and doesn’t do. OpenTracing is primarily a spec, with others doing the implementation and opinionation. OpenCensus provides a holistic approach for the local component with more opinionation but still requires other systems for remote aggregation. + +### Tool options + +#### Zipkin + +Zipkin was one of the first systems of this kind. It was developed by Twitter based on the [Google Dapper paper][8] about the internal system Google uses. Zipkin was written using Java, and it can use Cassandra or ElasticSearch as a scalable backend. Most companies should be satisfied with one of those options. The lowest supported Java version is Java 6. It also uses the [Thrift][9] binary communication protocol, which is popular in the Twitter stack and is hosted as an Apache project. + +The system consists of reporters (clients), collectors, a query service, and a web UI. Zipkin is meant to be safe in production by transmitting only a trace ID within the context of a transaction to inform receivers that a trace is in process. The data collected in each reporter is then transmitted asynchronously to the collectors. The collectors store these spans in the database, and the web UI presents this data to the end user in a consumable format. The delivery of data to the collectors can occur in three different methods: HTTP, Kafka, and Scribe. + +The [Zipkin community][10] has also created [Brave][11], a Java client implementation compatible with Zipkin. It has no dependencies, so it won’t drag your projects down or clutter them with libraries that are incompatible with your corporate standards. There are many other implementations, and Zipkin is compatible with the OpenTracing standard, so these implementations should also work with other distributed tracing systems. The popular Spring framework has a component called [Spring Cloud Sleuth][12] that is compatible with Zipkin. + +#### Jaeger + +[Jaeger][1] is a newer project from Uber Technologies that the [CNCF][13] has since adopted as an Incubating project. It is written in Golang, so you don’t have to worry about having dependencies installed on the host or any overhead of interpreters or language virtual machines. Similar to Zipkin, Jaeger also supports Cassandra and ElasticSearch as scalable storage backends. Jaeger is also fully compatible with the OpenTracing standard. + +Jaeger’s architecture is similar to Zipkin, with clients (reporters), collectors, a query service, and a web UI, but it also has an agent on each host that locally aggregates the data. The agent receives data over a UDP connection, which it batches and sends to a collector. The collector receives that data in the form of the [Thrift][14] protocol and stores that data in Cassandra or ElasticSearch. The query service can access the data store directly and provide that information to the web UI. + +By default, a user won’t get all the traces from the Jaeger clients. The system samples 0.1% (1 in 1,000) of traces that pass through each client. Keeping and transmitting all traces would be a bit overwhelming to most systems. However, this can be increased or decreased by configuring the agents, which the client consults with for its configuration. This sampling isn’t completely random, though, and it’s getting better. Jaeger uses probabilistic sampling, which tries to make an educated guess at whether a new trace should be sampled or not. [Adaptive sampling is on its roadmap][15], which will improve the sampling algorithm by adding additional context for making decisions. + +#### Appdash + +[Appdash][16] is a distributed tracing system written in Golang, like Jaeger. It was created by [Sourcegraph][17] based on Google’s Dapper and Twitter’s Zipkin. Similar to Jaeger and Zipkin, Appdash supports the OpenTracing standard; this was a later addition and requires a component that is different from the default component. This adds risk and complexity. + +At a high level, Appdash’s architecture consists mostly of three components: a client, a local collector, and a remote collector. There’s not a lot of documentation, so this description comes from testing the system and reviewing the code. The client in Appdash gets added to your code. Appdash provides Python, Golang, and Ruby implementations, but OpenTracing libraries can be used with Appdash’s OpenTracing implementation. The client collects the spans and sends them to the local collector. The local collector then sends the data to a centralized Appdash server running its own local collector, which is the remote collector for all other nodes in the system. + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/9/distributed-tracing-tools + +作者:[Dan Barker][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://opensource.com/users/barkerd427 +[1]: https://www.jaegertracing.io/ +[2]: https://www.youtube.com/watch?v=T8BbeqZ0Rls +[3]: http://opentracing.io/ +[4]: https://zipkin.io/ +[5]: https://www.datadoghq.com/ +[6]: https://www.instana.com/ +[7]: https://opencensus.io/ +[8]: https://research.google.com/archive/papers/dapper-2010-1.pdf +[9]: https://thrift.apache.org/ +[10]: https://zipkin.io/pages/community.html +[11]: https://github.com/openzipkin/brave +[12]: https://cloud.spring.io/spring-cloud-sleuth/ +[13]: https://www.cncf.io/ +[14]: https://en.wikipedia.org/wiki/Apache_Thrift +[15]: https://www.jaegertracing.io/docs/roadmap/#adaptive-sampling +[16]: https://github.com/sourcegraph/appdash +[17]: https://about.sourcegraph.com/ diff --git a/sources/tech/20180926 An introduction to swap space on Linux systems.md b/sources/tech/20180926 An introduction to swap space on Linux systems.md new file mode 100644 index 0000000000..da50208533 --- /dev/null +++ b/sources/tech/20180926 An introduction to swap space on Linux systems.md @@ -0,0 +1,302 @@ +heguangzhi Translating + +An introduction to swap space on Linux systems +====== + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/fail_progress_cycle_momentum_arrow.png?itok=q-ZFa_Eh) + +Swap space is a common aspect of computing today, regardless of operating system. Linux uses swap space to increase the amount of virtual memory available to a host. It can use one or more dedicated swap partitions or a swap file on a regular filesystem or logical volume. + +There are two basic types of memory in a typical computer. The first type, random access memory (RAM), is used to store data and programs while they are being actively used by the computer. Programs and data cannot be used by the computer unless they are stored in RAM. RAM is volatile memory; that is, the data stored in RAM is lost if the computer is turned off. + +Hard drives are magnetic media used for long-term storage of data and programs. Magnetic media is nonvolatile; the data stored on a disk remains even when power is removed from the computer. The CPU (central processing unit) cannot directly access the programs and data on the hard drive; it must be copied into RAM first, and that is where the CPU can access its programming instructions and the data to be operated on by those instructions. During the boot process, a computer copies specific operating system programs, such as the kernel and init or systemd, and data from the hard drive into RAM, where it is accessed directly by the computer’s processor, the CPU. + +### Swap space + +Swap space is the second type of memory in modern Linux systems. The primary function of swap space is to substitute disk space for RAM memory when real RAM fills up and more space is needed. + +For example, assume you have a computer system with 8GB of RAM. If you start up programs that don’t fill that RAM, everything is fine and no swapping is required. But suppose the spreadsheet you are working on grows when you add more rows, and that, plus everything else that's running, now fills all of RAM. Without swap space available, you would have to stop working on the spreadsheet until you could free up some of your limited RAM by closing down some other programs. + +The kernel uses a memory management program that detects blocks, aka pages, of memory in which the contents have not been used recently. The memory management program swaps enough of these relatively infrequently used pages of memory out to a special partition on the hard drive specifically designated for “paging,” or swapping. This frees up RAM and makes room for more data to be entered into your spreadsheet. Those pages of memory swapped out to the hard drive are tracked by the kernel’s memory management code and can be paged back into RAM if they are needed. + +The total amount of memory in a Linux computer is the RAM plus swap space and is referred to as virtual memory. + +### Types of Linux swap + +Linux provides for two types of swap space. By default, most Linux installations create a swap partition, but it is also possible to use a specially configured file as a swap file. A swap partition is just what its name implies—a standard disk partition that is designated as swap space by the `mkswap` command. + +A swap file can be used if there is no free disk space in which to create a new swap partition or space in a volume group where a logical volume can be created for swap space. This is just a regular file that is created and preallocated to a specified size. Then the `mkswap` command is run to configure it as swap space. I don’t recommend using a file for swap space unless absolutely necessary. + +### Thrashing + +Thrashing can occur when total virtual memory, both RAM and swap space, become nearly full. The system spends so much time paging blocks of memory between swap space and RAM and back that little time is left for real work. The typical symptoms of this are obvious: The system becomes slow or completely unresponsive, and the hard drive activity light is on almost constantly. + +If you can manage to issue a command like `free` that shows CPU load and memory usage, you will see that the CPU load is very high, perhaps as much as 30 to 40 times the number of CPU cores in the system. Another symptom is that both RAM and swap space are almost completely allocated. + +After the fact, looking at SAR (system activity report) data can also show these symptoms. I install SAR on every system I work on and use it for post-repair forensic analysis. + +### What is the right amount of swap space? + +Many years ago, the rule of thumb for the amount of swap space that should be allocated on the hard drive was 2X the amount of RAM installed in the computer (of course, that was when most computers' RAM was measured in KB or MB). So if a computer had 64KB of RAM, a swap partition of 128KB would be an optimum size. This rule took into account the facts that RAM sizes were typically quite small at that time and that allocating more than 2X RAM for swap space did not improve performance. With more than twice RAM for swap, most systems spent more time thrashing than actually performing useful work. + +RAM has become an inexpensive commodity and most computers these days have amounts of RAM that extend into tens of gigabytes. Most of my newer computers have at least 8GB of RAM, one has 32GB, and my main workstation has 64GB. My older computers have from 4 to 8 GB of RAM. + +When dealing with computers having huge amounts of RAM, the limiting performance factor for swap space is far lower than the 2X multiplier. The Fedora 28 online Installation Guide, which can be found online at [Fedora Installation Guide][1], defines current thinking about swap space allocation. I have included below some discussion and the table of recommendations from that document. + +The following table provides the recommended size of a swap partition depending on the amount of RAM in your system and whether you want sufficient memory for your system to hibernate. The recommended swap partition size is established automatically during installation. To allow for hibernation, however, you will need to edit the swap space in the custom partitioning stage. + +_Table 1: Recommended system swap space in Fedora 28 documentation_ + +| **Amount of system RAM** | **Recommended swap space** | **Recommended swap with hibernation** | +|--------------------------|-----------------------------|---------------------------------------| +| less than 2 GB | 2 times the amount of RAM | 3 times the amount of RAM | +| 2 GB - 8 GB | Equal to the amount of RAM | 2 times the amount of RAM | +| 8 GB - 64 GB | 0.5 times the amount of RAM | 1.5 times the amount of RAM | +| more than 64 GB | workload dependent | hibernation not recommended | + +At the border between each range listed above (for example, a system with 2 GB, 8 GB, or 64 GB of system RAM), use discretion with regard to chosen swap space and hibernation support. If your system resources allow for it, increasing the swap space may lead to better performance. + +Of course, most Linux administrators have their own ideas about the appropriate amount of swap space—as well as pretty much everything else. Table 2, below, contains my recommendations based on my personal experiences in multiple environments. These may not work for you, but as with Table 1, they may help you get started. + +_Table 2: Recommended system swap space per the author_ + +| Amount of RAM | Recommended swap space | +|---------------|------------------------| +| ≤ 2GB | 2X RAM | +| 2GB – 8GB | = RAM | +| >8GB | 8GB | + +One consideration in both tables is that as the amount of RAM increases, beyond a certain point adding more swap space simply leads to thrashing well before the swap space even comes close to being filled. If you have too little virtual memory while following these recommendations, you should add more RAM, if possible, rather than more swap space. As with all recommendations that affect system performance, use what works best for your specific environment. This will take time and effort to experiment and make changes based on the conditions in your Linux environment. + +#### Adding more swap space to a non-LVM disk environment + +Due to changing requirements for swap space on hosts with Linux already installed, it may become necessary to modify the amount of swap space defined for the system. This procedure can be used for any general case where the amount of swap space needs to be increased. It assumes sufficient available disk space is available. This procedure also assumes that the disks are partitioned in “raw” EXT4 and swap partitions and do not use logical volume management (LVM). + +The basic steps to take are simple: + + 1. Turn off the existing swap space. + + 2. Create a new swap partition of the desired size. + + 3. Reread the partition table. + + 4. Configure the partition as swap space. + + 5. Add the new partition/etc/fstab. + + 6. Turn on swap. + + + + +A reboot should not be necessary. + +For safety's sake, before turning off swap, at the very least you should ensure that no applications are running and that no swap space is in use. The `free` or `top` commands can tell you whether swap space is in use. To be even safer, you could revert to run level 1 or single-user mode. + +Turn off the swap partition with the command which turns off all swap space: + +``` +swapoff -a + +``` + +Now display the existing partitions on the hard drive. + +``` +fdisk -l + +``` + +This displays the current partition tables on each drive. Identify the current swap partition by number. + +Start `fdisk` in interactive mode with the command: + +``` +fdisk /dev/ + +``` + +For example: + +``` +fdisk /dev/sda + +``` + +At this point, `fdisk` is now interactive and will operate only on the specified disk drive. + +Use the fdisk `p` sub-command to verify that there is enough free space on the disk to create the new swap partition. The space on the hard drive is shown in terms of 512-byte blocks and starting and ending cylinder numbers, so you may have to do some math to determine the available space between and at the end of allocated partitions. + +Use the `n` sub-command to create a new swap partition. fdisk will ask you the starting cylinder. By default, it chooses the lowest-numbered available cylinder. If you wish to change that, type in the number of the starting cylinder. + +The `fdisk` command now allows you to enter the size of the partitions in a number of formats, including the last cylinder number or the size in bytes, KB or MB. Type in 4000M, which will give about 4GB of space on the new partition (for example), and press Enter. + +Use the `p` sub-command to verify that the partition was created as you specified it. Note that the partition will probably not be exactly what you specified unless you used the ending cylinder number. The `fdisk` command can only allocate disk space in increments on whole cylinders, so your partition may be a little smaller or larger than you specified. If the partition is not what you want, you can delete it and create it again. + +Now it is necessary to specify that the new partition is to be a swap partition. The sub-command `t` allows you to specify the type of partition. So enter `t`, specify the partition number, and when it asks for the hex code partition type, type 82, which is the Linux swap partition type, and press Enter. + +When you are satisfied with the partition you have created, use the `w` sub-command to write the new partition table to the disk. The `fdisk` program will exit and return you to the command prompt after it completes writing the revised partition table. You will probably receive the following message as `fdisk` completes writing the new partition table: + +``` +The partition table has been altered! +Calling ioctl() to re-read partition table. +WARNING: Re-reading the partition table failed with error 16: Device or resource busy. +The kernel still uses the old table. +The new table will be used at the next reboot. +Syncing disks. +``` + +At this point, you use the `partprobe` command to force the kernel to re-read the partition table so that it is not necessary to perform a reboot. + +``` +partprobe +``` + +Now use the command `fdisk -l` to list the partitions and the new swap partition should be among those listed. Be sure that the new partition type is “Linux swap”. + +It will be necessary to modify the /etc/fstab file to point to the new swap partition. The existing line may look like this: + +``` +LABEL=SWAP-sdaX   swap        swap    defaults        0 0 + +``` + +where `X` is the partition number. Add a new line that looks similar this, depending upon the location of your new swap partition: + +``` +/dev/sdaY         swap        swap    defaults        0 0 + +``` + +Be sure to use the correct partition number. Now you can perform the final step in creating the swap partition. Use the `mkswap` command to define the partition as a swap partition. + +``` +mkswap /dev/sdaY + +``` + +The final step is to turn swap on using the command: + +``` +swapon -a + +``` + +Your new swap partition is now online along with the previously existing swap partition. You can use the `free` or `top` commands to verify this. + +#### Adding swap to an LVM disk environment + +If your disk setup uses LVM, changing swap space will be fairly easy. Again, this assumes that space is available in the volume group in which the current swap volume is located. By default, the installation procedures for Fedora Linux in an LVM environment create the swap partition as a logical volume. This makes it easy because you can simply increase the size of the swap volume. + +Here are the steps required to increase the amount of swap space in an LVM environment: + + 1. Turn off all swap. + + 2. Increase the size of the logical volume designated for swap. + + 3. Configure the resized volume as swap space. + + 4. Turn on swap. + + + + +First, let’s verify that swap exists and is a logical volume using the `lvs` command (list logical volume). + +``` +[root@studentvm1 ~]# lvs +  LV     VG                Attr       LSize  Pool   Origin Data%  Meta%  Move Log Cpy%Sync Convert +  home   fedora_studentvm1 -wi-ao----  2.00g                                                       +  pool00 fedora_studentvm1 twi-aotz--  2.00g               8.17   2.93                             +  root   fedora_studentvm1 Vwi-aotz--  2.00g pool00        8.17                                   +  swap   fedora_studentvm1 -wi-ao----  8.00g                                                       +  tmp    fedora_studentvm1 -wi-ao----  5.00g                                                       +  usr    fedora_studentvm1 -wi-ao---- 15.00g                                                       +  var    fedora_studentvm1 -wi-ao---- 10.00g                                                       +[root@studentvm1 ~]# +``` + +You can see that the current swap size is 8GB. In this case, we want to add 2GB to this swap volume. First, stop existing swap. You may have to terminate running programs if swap space is in use. + +``` +swapoff -a + +``` + +Now increase the size of the logical volume. + +``` +[root@studentvm1 ~]# lvextend -L +2G /dev/mapper/fedora_studentvm1-swap +  Size of logical volume fedora_studentvm1/swap changed from 8.00 GiB (2048 extents) to 10.00 GiB (2560 extents). +  Logical volume fedora_studentvm1/swap successfully resized. +[root@studentvm1 ~]# +``` + +Run the `mkswap` command to make this entire 10GB partition into swap space. + +``` +[root@studentvm1 ~]# mkswap /dev/mapper/fedora_studentvm1-swap +mkswap: /dev/mapper/fedora_studentvm1-swap: warning: wiping old swap signature. +Setting up swapspace version 1, size = 10 GiB (10737414144 bytes) +no label, UUID=3cc2bee0-e746-4b66-aa2d-1ea15ef1574a +[root@studentvm1 ~]# +``` + +Turn swap back on. + +``` +[root@studentvm1 ~]# swapon -a +[root@studentvm1 ~]# +``` + +Now verify the new swap space is present with the list block devices command. Again, a reboot is not required. + +``` +[root@studentvm1 ~]# lsblk +NAME                                 MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT +sda                                    8:0    0   60G  0 disk +|-sda1                                 8:1    0    1G  0 part /boot +`-sda2                                 8:2    0   59G  0 part +  |-fedora_studentvm1-pool00_tmeta   253:0    0    4M  0 lvm   +  | `-fedora_studentvm1-pool00-tpool 253:2    0    2G  0 lvm   +  |   |-fedora_studentvm1-root       253:3    0    2G  0 lvm  / +  |   `-fedora_studentvm1-pool00     253:6    0    2G  0 lvm   +  |-fedora_studentvm1-pool00_tdata   253:1    0    2G  0 lvm   +  | `-fedora_studentvm1-pool00-tpool 253:2    0    2G  0 lvm   +  |   |-fedora_studentvm1-root       253:3    0    2G  0 lvm  / +  |   `-fedora_studentvm1-pool00     253:6    0    2G  0 lvm   +  |-fedora_studentvm1-swap           253:4    0   10G  0 lvm  [SWAP] +  |-fedora_studentvm1-usr            253:5    0   15G  0 lvm  /usr +  |-fedora_studentvm1-home           253:7    0    2G  0 lvm  /home +  |-fedora_studentvm1-var            253:8    0   10G  0 lvm  /var +  `-fedora_studentvm1-tmp            253:9    0    5G  0 lvm  /tmp +sr0                                   11:0    1 1024M  0 rom   +[root@studentvm1 ~]# +``` + +You can also use the `swapon -s` command, or `top`, `free`, or any of several other commands to verify this. + +``` +[root@studentvm1 ~]# free +              total        used        free      shared  buff/cache   available +Mem:        4038808      382404     2754072        4152      902332     3404184 +Swap:      10485756           0    10485756 +[root@studentvm1 ~]# +``` + +Note that the different commands display or require as input the device special file in different forms. There are a number of ways in which specific devices are accessed in the /dev directory. My article, [Managing Devices in Linux][2], includes more information about the /dev directory and its contents. + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/9/swap-space-linux-systems + +作者:[David Both][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://opensource.com/users/dboth +[1]: https://docs.fedoraproject.org/en-US/fedora/f28/install-guide/ +[2]: https://opensource.com/article/16/11/managing-devices-linux diff --git a/sources/tech/20180926 How to use the Scikit-learn Python library for data science projects.md b/sources/tech/20180926 How to use the Scikit-learn Python library for data science projects.md new file mode 100644 index 0000000000..e8b108720e --- /dev/null +++ b/sources/tech/20180926 How to use the Scikit-learn Python library for data science projects.md @@ -0,0 +1,260 @@ +translating by Flowsnow + +How to use the Scikit-learn Python library for data science projects +====== + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/brain_data.png?itok=RH6NA32X) + +The Scikit-learn Python library, initially released in 2007, is commonly used in solving machine learning and data science problems—from the beginning to the end. The versatile library offers an uncluttered, consistent, and efficient API and thorough online documentation. + +### What is Scikit-learn? + +[Scikit-learn][1] is an open source Python library that has powerful tools for data analysis and data mining. It's available under the BSD license and is built on the following machine learning libraries: + + * **NumPy** , a library for manipulating multi-dimensional arrays and matrices. It also has an extensive compilation of mathematical functions for performing various calculations. + * **SciPy** , an ecosystem consisting of various libraries for completing technical computing tasks. + * **Matplotlib** , a library for plotting various charts and graphs. + + + +Scikit-learn offers an extensive range of built-in algorithms that make the most of data science projects. + +Here are the main ways the Scikit-learn library is used. + +#### 1. Classification + +The [classification][2] tools identify the category associated with provided data. For example, they can be used to categorize email messages as either spam or not. + + * Support vector machines (SVMs) + * Nearest neighbors + * Random forest + + + +#### 2. Regression + +Classification algorithms in Scikit-learn include: + +Regression involves creating a model that tries to comprehend the relationship between input and output data. For example, regression tools can be used to understand the behavior of stock prices. + +Regression algorithms include: + + * SVMs + * Ridge regression + * Lasso + + + +#### 3. Clustering + +The Scikit-learn clustering tools are used to automatically group data with the same characteristics into sets. For example, customer data can be segmented based on their localities. + +Clustering algorithms include: + + * K-means + * Spectral clustering + * Mean-shift + + + +#### 4. Dimensionality reduction + +Dimensionality reduction lowers the number of random variables for analysis. For example, to increase the efficiency of visualizations, outlying data may not be considered. + +Dimensionality reduction algorithms include: + + * Principal component analysis (PCA) + * Feature selection + * Non-negative matrix factorization + + + +#### 5. Model selection + +Model selection algorithms offer tools to compare, validate, and select the best parameters and models to use in your data science projects. + +Model selection modules that can deliver enhanced accuracy through parameter tuning include: + + * Grid search + * Cross-validation + * Metrics + + + +#### 6. Preprocessing + +The Scikit-learn preprocessing tools are important in feature extraction and normalization during data analysis. For example, you can use these tools to transform input data—such as text—and apply their features in your analysis. + +Preprocessing modules include: + + * Preprocessing + * Feature extraction + + + +### A Scikit-learn library example + +Let's use a simple example to illustrate how you can use the Scikit-learn library in your data science projects. + +We'll use the [Iris flower dataset][3], which is incorporated in the Scikit-learn library. The Iris flower dataset contains 150 details about three flower species: + + * Setosa—labeled 0 + * Versicolor—labeled 1 + * Virginica—labeled 2 + + + +The dataset includes the following characteristics of each flower species (in centimeters): + + * Sepal length + * Sepal width + * Petal length + * Petal width + + + +#### Step 1: Importing the library + +Since the Iris dataset is included in the Scikit-learn data science library, we can load it into our workspace as follows: + +``` +from sklearn import datasets +iris = datasets.load_iris() +``` + +These commands import the **datasets** module from **sklearn** , then use the **load_digits()** method from **datasets** to include the data in the workspace. + +#### Step 2: Getting dataset characteristics + +The **datasets** module contains several methods that make it easier to get acquainted with handling data. + +In Scikit-learn, a dataset refers to a dictionary-like object that has all the details about the data. The data is stored using the **.data** key, which is an array list. + +For instance, we can utilize **iris.data** to output information about the Iris flower dataset. + +``` +print(iris.data) +``` + +Here is the output (the results have been truncated): + +``` +[[5.1 3.5 1.4 0.2] + [4.9 3.  1.4 0.2] + [4.7 3.2 1.3 0.2] + [4.6 3.1 1.5 0.2] + [5.  3.6 1.4 0.2] + [5.4 3.9 1.7 0.4] + [4.6 3.4 1.4 0.3] + [5.  3.4 1.5 0.2] + [4.4 2.9 1.4 0.2] + [4.9 3.1 1.5 0.1] + [5.4 3.7 1.5 0.2] + [4.8 3.4 1.6 0.2] + [4.8 3.  1.4 0.1] + [4.3 3.  1.1 0.1] + [5.8 4.  1.2 0.2] + [5.7 4.4 1.5 0.4] + [5.4 3.9 1.3 0.4] + [5.1 3.5 1.4 0.3] +``` + +Let's also use **iris.target** to give us information about the different labels of the flowers. + +``` +print(iris.target) +``` + +Here is the output: + +``` +[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 + 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 + 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 + 2 2] + +``` + +If we use **iris.target_names** , we'll output an array of the names of the labels found in the dataset. + +``` +print(iris.target_names) +``` + +Here is the result after running the Python code: + +``` +['setosa' 'versicolor' 'virginica'] +``` + +#### Step 3: Visualizing the dataset + +We can use the [box plot][4] to produce a visual depiction of the Iris flower dataset. The box plot illustrates how the data is distributed over the plane through their quartiles. + +Here's how to achieve this: + +``` +import seaborn as sns +box_data = iris.data #variable representing the data array +box_target = iris.target #variable representing the labels array +sns.boxplot(data = box_data,width=0.5,fliersize=5) +sns.set(rc={'figure.figsize':(2,15)}) +``` + +Let's see the result: + +![](https://opensource.com/sites/default/files/uploads/scikit_boxplot.png) + +On the horizontal axis: + + * 0 is sepal length + * 1 is sepal width + * 2 is petal length + * 3 is petal width + + + +The vertical axis is dimensions in centimeters. + +### Wrapping up + +Here is the entire code for this simple Scikit-learn data science tutorial. + +``` +from sklearn import datasets +iris = datasets.load_iris() +print(iris.data) +print(iris.target) +print(iris.target_names) +import seaborn as sns +box_data = iris.data #variable representing the data array +box_target = iris.target #variable representing the labels array +sns.boxplot(data = box_data,width=0.5,fliersize=5) +sns.set(rc={'figure.figsize':(2,15)}) +``` + +Scikit-learn is a versatile Python library you can use to efficiently complete data science projects. + +If you want to learn more, check out the tutorials on [LiveEdu][5], such as Andrey Bulezyuk's video on using the Scikit-learn library to create a [machine learning application][6]. + +Do you have any questions or comments? Feel free to share them below. + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/9/how-use-scikit-learn-data-science-projects + +作者:[Dr.Michael J.Garbade][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://opensource.com/users/drmjg +[1]: http://scikit-learn.org/stable/index.html +[2]: https://blog.liveedu.tv/regression-versus-classification-machine-learning-whats-the-difference/ +[3]: https://en.wikipedia.org/wiki/Iris_flower_data_set +[4]: https://en.wikipedia.org/wiki/Box_plot +[5]: https://www.liveedu.tv/guides/data-science/ +[6]: https://www.liveedu.tv/andreybu/REaxr-machine-learning-model-python-sklearn-kera/oPGdP-machine-learning-model-python-sklearn-kera/ diff --git a/sources/tech/20180927 How To Find And Delete Duplicate Files In Linux.md b/sources/tech/20180927 How To Find And Delete Duplicate Files In Linux.md new file mode 100644 index 0000000000..e3a0a9d561 --- /dev/null +++ b/sources/tech/20180927 How To Find And Delete Duplicate Files In Linux.md @@ -0,0 +1,441 @@ +How To Find And Delete Duplicate Files In Linux +====== + +![](https://www.ostechnix.com/wp-content/uploads/2018/09/Find-And-Delete-Duplicate-Files-720x340.png) + +I always backup the configuration files or any old files to somewhere in my hard disk before edit or modify them, so I can restore them from the backup if I accidentally did something wrong. But the problem is I forgot to clean up those files and my hard disk is filled with a lot of duplicate files after a certain period of time. I feel either too lazy to clean the old files or afraid that I may delete an important files. If you’re anything like me and overwhelming with multiple copies of same files in different backup directories, you can find and delete duplicate files using the tools given below in Unix-like operating systems. + +**A word of caution:** + +Please be careful while deleting duplicate files. If you’re not careful, it will lead you to [**accidental data loss**][1]. I advice you to pay extra attention while using these tools. + +### Find And Delete Duplicate Files In Linux + +For the purpose of this guide, I am going to discuss about three utilities namely, + + 1. Rdfind, + 2. Fdupes, + 3. FSlint. + + + +These three utilities are free, open source and works on most Unix-like operating systems. + +##### 1. Rdfind + +**Rdfind** , stands for **r** edundant **d** ata **find** , is a free and open source utility to find duplicate files across and/or within directories and sub-directories. It compares files based on their content, not on their file names. Rdfind uses **ranking** algorithm to classify original and duplicate files. If you have two or more equal files, Rdfind is smart enough to find which is original file, and consider the rest of the files as duplicates. Once it found the duplicates, it will report them to you. You can decide to either delete them or replace them with [**hard links** or **symbolic (soft) links**][2]. + +**Installing Rdfind** + +Rdfind is available in [**AUR**][3]. So, you can install it in Arch-based systems using any AUR helper program like [**Yay**][4] as shown below. + +``` +$ yay -S rdfind + +``` + +On Debian, Ubuntu, Linux Mint: + +``` +$ sudo apt-get install rdfind + +``` + +On Fedora: + +``` +$ sudo dnf install rdfind + +``` + +On RHEL, CentOS: + +``` +$ sudo yum install epel-release + +$ sudo yum install rdfind + +``` + +**Usage** + +Once installed, simply run Rdfind command along with the directory path to scan for the duplicate files. + +``` +$ rdfind ~/Downloads + +``` + +![](https://www.ostechnix.com/wp-content/uploads/2018/09/rdfind-1.png) + +As you see in the above screenshot, Rdfind command will scan ~/Downloads directory and save the results in a file named **results.txt** in the current working directory. You can view the name of the possible duplicate files in results.txt file. + +``` +$ cat results.txt +# Automatically generated +# duptype id depth size device inode priority name +DUPTYPE_FIRST_OCCURRENCE 1469 8 9 2050 15864884 1 /home/sk/Downloads/tor-browser_en-US/Browser/TorBrowser/Tor/PluggableTransports/fte/tests/dfas/test5.regex +DUPTYPE_WITHIN_SAME_TREE -1469 8 9 2050 15864886 1 /home/sk/Downloads/tor-browser_en-US/Browser/TorBrowser/Tor/PluggableTransports/fte/tests/dfas/test6.regex +[...] +DUPTYPE_FIRST_OCCURRENCE 13 0 403635 2050 15740257 1 /home/sk/Downloads/Hyperledger(1).pdf +DUPTYPE_WITHIN_SAME_TREE -13 0 403635 2050 15741071 1 /home/sk/Downloads/Hyperledger.pdf +# end of file + +``` + +By reviewing the results.txt file, you can easily find the duplicates. You can remove the duplicates manually if you want to. + +Also, you can **-dryrun** option to find all duplicates in a given directory without changing anything and output the summary in your Terminal: + +``` +$ rdfind -dryrun true ~/Downloads + +``` + +Once you found the duplicates, you can replace them with either hardlinks or symlinks. + +To replace all duplicates with hardlinks, run: + +``` +$ rdfind -makehardlinks true ~/Downloads + +``` + +To replace all duplicates with symlinks/soft links, run: + +``` +$ rdfind -makesymlinks true ~/Downloads + +``` + +You may have some empty files in a directory and want to ignore them. If so, use **-ignoreempty** option like below. + +``` +$ rdfind -ignoreempty true ~/Downloads + +``` + +If you don’t want the old files anymore, just delete duplicate files instead of replacing them with hard or soft links. + +To delete all duplicates, simply run: + +``` +$ rdfind -deleteduplicates true ~/Downloads + +``` + +If you do not want to ignore empty files and delete them along with all duplicates, run: + +``` +$ rdfind -deleteduplicates true -ignoreempty false ~/Downloads + +``` + +For more details, refer the help section: + +``` +$ rdfind --help + +``` + +And, the manual pages: + +``` +$ man rdfind + +``` + +##### 2. Fdupes + +**Fdupes** is yet another command line utility to identify and remove the duplicate files within specified directories and the sub-directories. It is free, open source utility written in **C** programming language. Fdupes identifies the duplicates by comparing file sizes, partial MD5 signatures, full MD5 signatures, and finally performing a byte-by-byte comparison for verification. + +Similar to Rdfind utility, Fdupes comes with quite handful of options to perform operations, such as: + + * Recursively search duplicate files in directories and sub-directories + * Exclude empty files and hidden files from consideration + * Show the size of the duplicates + * Delete duplicates immediately as they encountered + * Exclude files with different owner/group or permission bits as duplicates + * And a lot more. + + + +**Installing Fdupes** + +Fdupes is available in the default repositories of most Linux distributions. + +On Arch Linux and its variants like Antergos, Manjaro Linux, install it using Pacman like below. + +``` +$ sudo pacman -S fdupes + +``` + +On Debian, Ubuntu, Linux Mint: + +``` +$ sudo apt-get install fdupes + +``` + +On Fedora: + +``` +$ sudo dnf install fdupes + +``` + +On RHEL, CentOS: + +``` +$ sudo yum install epel-release + +$ sudo yum install fdupes + +``` + +**Usage** + +Fdupes usage is pretty simple. Just run the following command to find out the duplicate files in a directory, for example **~/Downloads**. + +``` +$ fdupes ~/Downloads + +``` + +Sample output from my system: + +``` +/home/sk/Downloads/Hyperledger.pdf +/home/sk/Downloads/Hyperledger(1).pdf + +``` + +As you can see, I have a duplicate file in **/home/sk/Downloads/** directory. It shows the duplicates from the parent directory only. How to view the duplicates from sub-directories? Just use **-r** option like below. + +``` +$ fdupes -r ~/Downloads + +``` + +Now you will see the duplicates from **/home/sk/Downloads/** directory and its sub-directories as well. + +Fdupes can also be able to find duplicates from multiple directories at once. + +``` +$ fdupes ~/Downloads ~/Documents/ostechnix + +``` + +You can even search multiple directories, one recursively like below: + +``` +$ fdupes ~/Downloads -r ~/Documents/ostechnix + +``` + +The above commands searches for duplicates in “~/Downloads” directory and “~/Documents/ostechnix” directory and its sub-directories. + +Sometimes, you might want to know the size of the duplicates in a directory. If so, use **-S** option like below. + +``` +$ fdupes -S ~/Downloads +403635 bytes each: +/home/sk/Downloads/Hyperledger.pdf +/home/sk/Downloads/Hyperledger(1).pdf + +``` + +Similarly, to view the size of the duplicates in parent and child directories, use **-Sr** option. + +We can exclude empty and hidden files from consideration using **-n** and **-A** respectively. + +``` +$ fdupes -n ~/Downloads + +$ fdupes -A ~/Downloads + +``` + +The first command will exclude zero-length files from consideration and the latter will exclude hidden files from consideration while searching for duplicates in the specified directory. + +To summarize duplicate files information, use **-m** option. + +``` +$ fdupes -m ~/Downloads +1 duplicate files (in 1 sets), occupying 403.6 kilobytes + +``` + +To delete all duplicates, use **-d** option. + +``` +$ fdupes -d ~/Downloads + +``` + +Sample output: + +``` +[1] /home/sk/Downloads/Hyperledger Fabric Installation.pdf +[2] /home/sk/Downloads/Hyperledger Fabric Installation(1).pdf + +Set 1 of 1, preserve files [1 - 2, all]: + +``` + +This command will prompt you for files to preserve and delete all other duplicates. Just enter any number to preserve the corresponding file and delete the remaining files. Pay more attention while using this option. You might delete original files if you’re not be careful. + +If you want to preserve the first file in each set of duplicates and delete the others without prompting each time, use **-dN** option (not recommended). + +``` +$ fdupes -dN ~/Downloads + +``` + +To delete duplicates as they are encountered, use **-I** flag. + +``` +$ fdupes -I ~/Downloads + +``` + +For more details about Fdupes, view the help section and man pages. + +``` +$ fdupes --help + +$ man fdupes + +``` + +##### 3. FSlint + +**FSlint** is yet another duplicate file finder utility that I use from time to time to get rid of the unnecessary duplicate files and free up the disk space in my Linux system. Unlike the other two utilities, FSlint has both GUI and CLI modes. So, it is more user-friendly tool for newbies. FSlint not just finds the duplicates, but also bad symlinks, bad names, temp files, bad IDS, empty directories, and non stripped binaries etc. + +**Installing FSlint** + +FSlint is available in [**AUR**][5], so you can install it using any AUR helpers. + +``` +$ yay -S fslint + +``` + +On Debian, Ubuntu, Linux Mint: + +``` +$ sudo apt-get install fslint + +``` + +On Fedora: + +``` +$ sudo dnf install fslint + +``` + +On RHEL, CentOS: + +``` +$ sudo yum install epel-release + +``` + +$ sudo yum install fslint + +Once it is installed, launch it from menu or application launcher. + +This is how FSlint GUI looks like. + +![](http://www.ostechnix.com/wp-content/uploads/2018/09/fslint-1.png) + +As you can see, the interface of FSlint is user-friendly and self-explanatory. In the **Search path** tab, add the path of the directory you want to scan and click **Find** button on the lower left corner to find the duplicates. Check the recurse option to recursively search for duplicates in directories and sub-directories. The FSlint will quickly scan the given directory and list out them. + +![](https://www.ostechnix.com/wp-content/uploads/2018/09/fslint-2.png) + +From the list, choose the duplicates you want to clean and select any one of them given actions like Save, Delete, Merge and Symlink. + +In the **Advanced search parameters** tab, you can specify the paths to exclude while searching for duplicates. + +![](http://www.ostechnix.com/wp-content/uploads/2018/09/fslint-3.png) + +**FSlint command line options** + +FSlint provides a collection of the following CLI utilities to find duplicates in your filesystem: + + * **findup** — find DUPlicate files + * **findnl** — find Name Lint (problems with filenames) + * **findu8** — find filenames with invalid utf8 encoding + * **findbl** — find Bad Links (various problems with symlinks) + * **findsn** — find Same Name (problems with clashing names) + * **finded** — find Empty Directories + * **findid** — find files with dead user IDs + * **findns** — find Non Stripped executables + * **findrs** — find Redundant Whitespace in files + * **findtf** — find Temporary Files + * **findul** — find possibly Unused Libraries + * **zipdir** — Reclaim wasted space in ext2 directory entries + + + +All of these utilities are available under **/usr/share/fslint/fslint/fslint** location. + +For example, to find duplicates in a given directory, do: + +``` +$ /usr/share/fslint/fslint/findup ~/Downloads/ + +``` + +Similarly, to find empty directories, the command would be: + +``` +$ /usr/share/fslint/fslint/finded ~/Downloads/ + +``` + +To get more details on each utility, for example **findup** , run: + +``` +$ /usr/share/fslint/fslint/findup --help + +``` + +For more details about FSlint, refer the help section and man pages. + +``` +$ /usr/share/fslint/fslint/fslint --help + +$ man fslint + +``` + +##### Conclusion + +You know now about three tools to find and delete unwanted duplicate files in Linux. Among these three tools, I often use Rdfind. It doesn’t mean that the other two utilities are not efficient, but I am just happy with Rdfind so far. Well, it’s your turn. Which is your favorite tool and why? Let us know them in the comment section below. + +And, that’s all for now. Hope this was useful. More good stuffs to come. Stay tuned! + +Cheers! + + + +-------------------------------------------------------------------------------- + +via: https://www.ostechnix.com/how-to-find-and-delete-duplicate-files-in-linux/ + +作者:[SK][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://www.ostechnix.com/author/sk/ +[1]: https://www.ostechnix.com/prevent-files-folders-accidental-deletion-modification-linux/ +[2]: https://www.ostechnix.com/explaining-soft-link-and-hard-link-in-linux-with-examples/ +[3]: https://aur.archlinux.org/packages/rdfind/ +[4]: https://www.ostechnix.com/yay-found-yet-another-reliable-aur-helper/ +[5]: https://aur.archlinux.org/packages/fslint/ diff --git a/sources/tech/20180928 10 handy Bash aliases for Linux.md b/sources/tech/20180928 10 handy Bash aliases for Linux.md new file mode 100644 index 0000000000..7ae1070997 --- /dev/null +++ b/sources/tech/20180928 10 handy Bash aliases for Linux.md @@ -0,0 +1,118 @@ +translating---geekpi + +10 handy Bash aliases for Linux +====== +Get more efficient by using condensed versions of long Bash commands. + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/bash_command_line.png?itok=k4z94W2U) + +How many times have you repeatedly typed out a long command on the command line and wished there was a way to save it for later? This is where Bash aliases come in handy. They allow you to condense long, cryptic commands down to something easy to remember and use. Need some examples to get you started? No problem! + +To use a Bash alias you've created, you need to add it to your .bash_profile file, which is located in your home folder. Note that this file is hidden and accessible only from the command line. The easiest way to work with this file is to use something like Vi or Nano. + +### 10 handy Bash aliases + + 1. How many times have you needed to unpack a .tar file and couldn't remember the exact arguments needed? Aliases to the rescue! Just add the following to your .bash_profile file and then use **untar FileName** to unpack any .tar file. + + + +``` +alias untar='tar -zxvf ' + +``` + + 2. Want to download something but be able to resume if something goes wrong? + + + +``` +alias wget='wget -c ' + +``` + + 3. Need to generate a random, 20-character password for a new online account? No problem. + + + +``` +alias getpass="openssl rand -base64 20" + +``` + + 4. Downloaded a file and need to test the checksum? We've got that covered too. + + + +``` +alias sha='shasum -a 256 ' + +``` + + 5. A normal ping will go on forever. We don't want that. Instead, let's limit that to just five pings. + + + +``` +alias ping='ping -c 5' + +``` + + 6. Start a web server in any folder you'd like. + + + +``` +alias www='python -m SimpleHTTPServer 8000' + +``` + + 7. Want to know how fast your network is? Just download Speedtest-cli and use this alias. You can choose a server closer to your location by using the **speedtest-cli --list** command. + + + +``` +alias speed='speedtest-cli --server 2406 --simple' + +``` + + 8. How many times have you needed to know your external IP address and had no idea how to get that info? Yeah, me too. + + + +``` +alias ipe='curl ipinfo.io/ip' + +``` + + 9. Need to know your local IP address? + + + +``` +alias ipi='ipconfig getifaddr en0' + +``` + + 10. Finally, let's clear the screen. + + + +``` +alias c='clear' + +``` + +As you can see, Bash aliases are a super-easy way to simplify your life on the command line. Want more info? I recommend a quick Google search for "Bash aliases" or a trip to GitHub. + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/9/handy-bash-aliases + +作者:[Patrick H.Mullins][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://opensource.com/users/pmullins diff --git a/sources/tech/20180928 A Free And Secure Online PDF Conversion Suite.md b/sources/tech/20180928 A Free And Secure Online PDF Conversion Suite.md new file mode 100644 index 0000000000..afb66e43ee --- /dev/null +++ b/sources/tech/20180928 A Free And Secure Online PDF Conversion Suite.md @@ -0,0 +1,111 @@ +A Free And Secure Online PDF Conversion Suite +====== + +![](https://www.ostechnix.com/wp-content/uploads/2018/09/easypdf-720x340.jpg) + +We are always in search for a better and more efficient solution that can make our lives more convenient. That is why when you are working with PDF documents you need a fast and reliable tool that you can use in every situation. Therefore, we wanted to introduce you to **EasyPDF** Online PDF Suite for every occasion. The promise behind this tool is that it can make your PDF management easier and we tested it to check that claim. + +But first, here are the most important things you need to know about EasyPDF: + + * EasyPDF is free and anonymous online PDF Conversion Suite. + * Convert PDF to Word, Excel, PowerPoint, AutoCAD, JPG, GIF and Text. + * Create PDF from Word, PowerPoint, JPG, Excel files and many other formats. + * Manipulate PDFs with PDF Merge, Split and Compress. + * OCR conversion of scanned PDFs and images. + * Upload files from your device or the Cloud (Google Drive and DropBox). + * Available on Windows, Linux, Mac, and smartphones via any browser. + * Multiple languages supported. + + + +### EasyPDF User Interface + +![](http://www.ostechnix.com/wp-content/uploads/2018/09/easypdf-interface.png) + +One of the first things that catches your eye is the sleek user interface which gives the tool clean and functional environment in where you can work comfortably. The whole experience is even better because there are no ads on a website at all. + +All different types of conversions have their dedicated menu with a simple box to add files, so you don’t have to wonder about what you need to do. + +Most websites aren’t optimized to work well and run smoothly on mobile phones, but EasyPDF is an exception from that rule. It opens almost instantly on smartphone and is easy to navigate. You can also add it as the shortcut on your home screen from the **three dots menu** on the Chrome app. + +![](http://www.ostechnix.com/wp-content/uploads/2018/09/EasyPDF-fs8.png) + +### Functionality + +Apart from looking nice, EasyPDF is pretty straightforward to use. You **don’t need to register** or leave an **email** to use the tool. It is completely anonymous. Additionally, it doesn’t put any limitations to the number or size of files for conversion. No installation required either! Cool, yeah? + +You choose a desired conversion format, for example, PDF to Word. Select the PDF file you want to convert. You can upload a file from the device by either drag & drop or selecting the file from the folder. There is also an option to upload a document from [**Google Drive**][1] or [**Dropbox**][2]. + +After you choose the file, press the Convert button to start the conversion process. You won’t wait for a long time to get your file because conversion will finish in a minute. If you have some more files to convert, remember to download the file before you proceed further. If you don’t download the document first, you will lose it. + +![](https://www.ostechnix.com/wp-content/uploads/2018/09/EasyPDF1.png) + +For a different type of conversion, return to the homepage. + +The currently available types of conversions are: + + * **PDF to Word** – Convert PDF documents to Word documents + + * **PDF to PowerPoint** – Convert PDF documents to PowerPoint Presentations + + * **PDF to Excel** – Convert PDF documents to Excel documents + + * **PDF Creation** – Create PDF documents from any type of file (E.g text, doc, odt) + + * **Word to PDF** – Convert Word documents to PDF documents + + * **JPG to PDF** – Convert JPG images to PDF documents + + * **PDF to AutoCAD** – Convert PDF documents to .dwg format (DWG is native format for CAD packages) + + * **PDF to Text** – Convert PDF documents to Text documents + + * **PDF Split** – Split PDF files into multiple parts + + * **PDF Merge** – Merge multiple PDF files into one + + * **PDF Compress** – Compress PDF documents + + * **PDF to JPG** – Convert PDF documents to JPG images + + * **PDF to PNG** – Convert PDF documents to PNG images + + * **PDF to GIF** – Convert PDF documents to GIF files + + * **OCR Online** – + +Convert scanned paper documents + +to editable files (E.g Word, Excel, Text) + + + + +Want to give it a try? Great! Click the following link and start converting! + +[![](https://www.ostechnix.com/wp-content/uploads/2018/09/EasyPDF-online-pdf.png)][https://easypdf.com/] + +### Conclusion + +EasyPDF lives up to its name and enables easier PDF management. As far as I tested EasyPDF service, It offers out of the box conversion feature completely **FREE!** It is fast, secure and reliable. You will find the quality of services most satisfying without having to pay anything or leaving your personal data like email address. Give it a try and who knows maybe you will find your new favorite PDF tool. + +And, that’s all for now. More good stuffs to come. Stay tuned! + +Cheers! + + + +-------------------------------------------------------------------------------- + +via: https://www.ostechnix.com/easypdf-a-free-and-secure-online-pdf-conversion-suite/ + +作者:[SK][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://www.ostechnix.com/author/sk/ +[1]: https://www.ostechnix.com/how-to-mount-google-drive-locally-as-virtual-file-system-in-linux/ +[2]: https://www.ostechnix.com/install-dropbox-in-ubuntu-18-04-lts-desktop/ diff --git a/sources/tech/20180928 How to Install Popcorn Time on Ubuntu 18.04 and Other Linux Distributions.md b/sources/tech/20180928 How to Install Popcorn Time on Ubuntu 18.04 and Other Linux Distributions.md new file mode 100644 index 0000000000..578624aba4 --- /dev/null +++ b/sources/tech/20180928 How to Install Popcorn Time on Ubuntu 18.04 and Other Linux Distributions.md @@ -0,0 +1,233 @@ +Translating by dianbanjiu How to Install Popcorn Time on Ubuntu 18.04 and Other Linux Distributions +====== +**Brief: This tutorial shows you how to install Popcorn Time on Ubuntu and other Linux distributions. Some handy Popcorn Time tips have also been discussed.** + +[Popcorn Time][1] is an open source [Netflix][2] inspired [torrent][3] streaming application for Linux, Mac and Windows. + +With the regular torrents, you have to wait for the download to finish before you could watch the videos. + +[Popcorn Time][4] is different. It uses torrent underneath but allows you to start watching the videos (almost) immediately. It’s like you are watching videos on streaming websites like YouTube or Netflix. You don’t have to wait for the download to finish here. + +![Popcorn Time in Ubuntu Linux][5] +Popcorn Time + +If you want to watch movies online without those creepy ads, Popcorn Time is a good alternative. Keep in mind that the streaming quality depends on the number of available seeds. + +Popcorn Time also provides a nice user interface where you can browse through available movies, tv-series and other contents. If you ever used [Netflix on Linux][6], you will find it’s somewhat a similar experience. + +Using torrent to download movies is illegal in several countries where there are strict laws against piracy. In countries like the USA, UK and West European you may even get legal notices. That said, it’s up to you to decide if you want to use it or not. You have been warned. +(If you still want to take the risk and use Popcorn Time, you should use a VPN service like [Ivacy][7] that has been specifically designed for using Torrents and protecting your identity. Even then it’s not always easy to avoid the snooping authorities.) + +Some of the main features of Popcorn Time are: + + * Watch movies and TV Series online using Torrent + * A sleek user interface lets you browse the available movies and TV series + * Change streaming quality + * Bookmark content for watching later + * Download content for offline viewing + * Ability to enable subtitles by default, change the subtitles size etc + * Keyboard shortcuts to navigate through Popcorn Time + + + +### How to install Popcorn Time on Ubuntu and other Linux Distributions + +I am using Ubuntu 18.04 in this tutorial but you can use the same instructions for other Linux distributions such as Linux Mint, Debian, Manjaro, Deepin etc. + +Let’s see how to install Popcorn time on Linux. It’s really easy actually. Simply follow the instructions and copy paste the commands I have mentioned. + +#### Step 1: Download Popcorn Time + +You can download Popcorn Time from its official website. The download link is present on the homepage itself. + +[Get Popcorn Time](https://popcorntime.sh/) + +#### Step 2: Install Popcorn Time + +Once you have downloaded Popcorn Time, it’s time to use it. The downloaded file is a tar file that consists of an executable among other files. While you can extract this tar file anywhere, the [Linux convention is to install additional software in][8] /[opt directory.][8] + +Create a new directory in /opt: + +``` +sudo mkdir /opt/popcorntime +``` + +Now go to the Downloads directory. + +``` +cd ~/Downloads +``` + +Extract the downloaded Popcorn Time files into the newly created /opt/popcorntime directory. + +``` +sudo tar Jxf Popcorn-Time-* -C /opt/popcorntime +``` + +#### Step 3: Make Popcorn Time accessible for everyone + +You would want every user on your system to be able to run Popcorn Time without sudo access, right? To do that, you need to create a [symbolic link][9] to the executable in /usr/bin directory. + +``` +ln -sf /opt/popcorntime/Popcorn-Time /usr/bin/Popcorn-Time +``` + +#### Step 4: Create desktop launcher for Popcorn Time + +So far so good. But you would also like to see Popcorn Time in the application menu, add it to your favorite application list etc. + +For that, you need to create a desktop entry. + +Open a terminal and create a new file named popcorntime.desktop in /usr/share/applications. + +You can use any [command line based text editor][10]. Ubuntu has [Nano][11] installed by default so you can use that. + +``` +sudo nano /usr/share/applications/popcorntime.desktop +``` + +Insert the following lines here: + +``` +[Desktop Entry] +Version = 1.0 +Type = Application +Terminal = false +Name = Popcorn Time +Exec = /usr/bin/Popcorn-Time +Icon = /opt/popcorntime/popcorn.png +Categories = Application; +``` + +If you used Nano editor, save it using shortcut Ctrl+X. When asked for saving, enter Y and then press enter again to save and exit. + +We are almost there. One last thing to do here is to have the correct icon for Popcorn Time. For that, you can download a Popcorn Time icon and save it as popcorn.png in /opt/popcorntime directory. + +You can do that using the command below: + +``` +sudo wget -O /opt/popcorntime/popcorn.png https://upload.wikimedia.org/wikipedia/commons/d/df/Pctlogo.png + +``` + +That’s it. Now you can search for Popcorn Time and click on it to launch it. + +![Popcorn Time installed on Ubuntu][12] +Search for Popcorn Time in Menu + +On the first launch, you’ll have to accept the terms and conditions. + +![Popcorn Time in Ubuntu Linux][13] +Accept the Terms of Service + +Once you do that, you can enjoy the movies and TV shows. + +![Watch movies on Popcorn Time][14] + +Well, that’s all you needed to install Popcorn Time on Ubuntu or any other Linux distribution. You can start watching your favorite movies straightaway. + +However, if you are interested, I would suggest reading these Popcorn Time tips to get more out of it. + +[![][15]][16] +![][17] + +### 7 Tips for using Popcorn Time effectively + +Now that you have installed Popcorn Time, I am going to tell you some nifty Popcorn Time tricks. I assure you that it will enhance your experience with Popcorn Time multiple folds. + +#### 1\. Use advanced settings + +Always have the advanced settings enabled. It gives you more options to tweak Popcorn Time. Go to the top right corner and click on the gear symbol. Click on it and check advanced settings on the next screen. + +![](https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2015/01/Popcorn_Time_Tricks.jpeg) + +#### 2\. Watch the movies in VLC or other players + +Did you know that you can choose to watch a file in your preferred media player instead of the default Popcorn Time player? Of course, that media player should have been installed in the system. + +Now you may ask why would one want to use another player. And my answer is because other players like VLC has hidden features which you might not find in the Popcorn Time player. + +For example, if a file has very low volume, you can use VLC to enhance the audio by 400 percent. You can also [synchronize incoherent subtitles with VLC][18]. You can switch between media players before you start to play a file: + +![](https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2015/01/Pocorn_Time_Tricks_1.png) + +#### 3\. Bookmark movies and watch it later + +Just browsing through movies and TV series but don’t have time or mood to watch those? No issues. You can add the movies to the bookmark and can access these bookmarked videos from the Favorites tab. This enables you to create a list of movies you would watch later. + +![](https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2015/01/Pocorn_Time_Tricks2.png) + +#### 4\. Check torrent health and seed information + +As I had mentioned earlier, your viewing experience in Popcorn Times depends on torrent speed. Good thing is that Popcorn time shows the health of the torrent file so that you can be aware of the streaming speed. + +You will see a green/yellow/red dot on the file. Green means there are plenty of seeds and the file will stream easily. Yellow means a medium number of seeds, streaming should be okay. Red means there are very few seeds available and the streaming will be poor or won’t work at all. + +![](https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2015/01/Pocorn_Time_Tricks3.jpg) + +#### 5\. Add custom subtitles + +If you need subtitles and it is not available in your preferred language, you can add custom subtitles downloaded from external websites. Get the .srt files and use it inside Popcorn Time: + +![](https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2015/01/Pocporn_Time_Tricks5.png) + +This is where VLC comes handy as you can [download subtitles automatically with VLC][19]. + + +#### 6\. Save the files for offline viewing + +When Popcorn Times stream a content, it downloads it and store temporarily. When you close the app, it’s cleaned out. You can change this behavior so that the downloaded file remains there for your future use. + +In the advanced settings, scroll down a bit. Look for Cache directory. You can change this to some other directory like Downloads. This way, even if you close Popcorn Time, the file will be available for viewing. + +![](https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2015/01/Popcorn_Time_Tips.jpg) + +#### 7\. Drag and drop external torrent files to play immediately + +I bet you did not know about this one. If you don’t find a certain movie on Popcorn Time, download the torrent file from your favorite torrent website. Open Popcorn Time and just drag and drop the torrent file in Popcorn Time. It will start playing the file, depending upon seeds. This way, you don’t need to download the entire file before watching it. + +When you drag and drop the torrent file in Popcorn Time, it will give you the option to choose which video file should it play. If there are subtitles in it, it will play automatically or else, you can add external subtitles. + +![](https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2015/01/Pocorn_Time_Tricks4.png) + +There are plenty of other features in Popcorn Time. But I’ll stop with my list here and let you explore Popcorn Time on Ubuntu Linux. I hope you find these Popcorn Time tips and tricks useful. + +I am repeating again. Using Torrents is illegal in many countries. If you do that, take precaution and use a VPN service. If you are looking for my recommendation, you can go for [Swiss-based privacy company ProtonVPN][20] (of [ProtonMail][21] fame). Singapore based [Ivacy][7] is another good option. If you think these are expensive, you can look for [cheap VPN deals on It’s FOSS Shop][22]. + +Note: This article contains affiliate links. Please read our [affiliate policy][23]. + +-------------------------------------------------------------------------------- + +via: https://itsfoss.com/popcorn-time-ubuntu-linux/ + +作者:[Abhishek Prakash][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://itsfoss.com/author/abhishek/ +[1]: https://popcorntime.sh/ +[2]: https://netflix.com/ +[3]: https://en.wikipedia.org/wiki/Torrent_file +[4]: https://en.wikipedia.org/wiki/Popcorn_Time +[5]: https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/09/popcorn-time-linux.jpeg +[6]: https://itsfoss.com/netflix-firefox-linux/ +[7]: https://billing.ivacy.com/page/23628 +[8]: http://tldp.org/LDP/Linux-Filesystem-Hierarchy/html/opt.html +[9]: https://en.wikipedia.org/wiki/Symbolic_link +[10]: https://itsfoss.com/command-line-text-editors-linux/ +[11]: https://itsfoss.com/nano-3-release/ +[12]: https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/09/popcorn-time-ubuntu-menu.jpg +[13]: https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/09/popcorn-time-ubuntu-license.jpeg +[14]: https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/09/popcorn-time-watch-movies.jpeg +[15]: https://ivacy.postaffiliatepro.com/accounts/default1/vdegzkxbw/7f82d531.png +[16]: https://billing.ivacy.com/page/23628/7f82d531 +[17]: http://ivacy.postaffiliatepro.com/scripts/vdegzkxiw?aff=23628&a_bid=7f82d531 +[18]: https://itsfoss.com/how-to-synchronize-subtitles-with-movie-quick-tip/ +[19]: https://itsfoss.com/download-subtitles-automatically-vlc-media-player-ubuntu/ +[20]: https://protonvpn.net/?aid=chmod777 +[21]: https://itsfoss.com/protonmail/ +[22]: https://shop.itsfoss.com/search?utf8=%E2%9C%93&query=vpn +[23]: https://itsfoss.com/affiliate-policy/ diff --git a/sources/tech/20180928 Quiet log noise with Python and machine learning.md b/sources/tech/20180928 Quiet log noise with Python and machine learning.md new file mode 100644 index 0000000000..f1fe2f1b7f --- /dev/null +++ b/sources/tech/20180928 Quiet log noise with Python and machine learning.md @@ -0,0 +1,110 @@ +Quiet log noise with Python and machine learning +====== + +Logreduce saves debugging time by picking out anomalies from mountains of log data. + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/sound-radio-noise-communication.png?itok=KMNn9QrZ) + +Continuous integration (CI) jobs can generate massive volumes of data. When a job fails, figuring out what went wrong can be a tedious process that involves investigating logs to discover the root cause—which is often found in a fraction of the total job output. To make it easier to separate the most relevant data from the rest, the [Logreduce][1] machine learning model is trained using previous successful job runs to extract anomalies from failed runs' logs. + +This principle can also be applied to other use cases, for example, extracting anomalies from [Journald][2] or other systemwide regular log files. + +### Using machine learning to reduce noise + +A typical log file contains many nominal events ("baselines") along with a few exceptions that are relevant to the developer. Baselines may contain random elements such as timestamps or unique identifiers that are difficult to detect and remove. To remove the baseline events, we can use a [k-nearest neighbors pattern recognition algorithm][3] (k-NN). + +![](https://opensource.com/sites/default/files/uploads/ml-generic-workflow.png) + +Log events must be converted to numeric values for k-NN regression. Using the generic feature extraction tool [HashingVectorizer][4] enables the process to be applied to any type of log. It hashes each word and encodes each event in a sparse matrix. To further reduce the search space, tokenization removes known random words, such as dates or IP addresses. + +![](https://opensource.com/sites/default/files/uploads/hashing-vectorizer.png) + +Once the model is trained, the k-NN search tells us the distance of each new event from the baseline. + +![](https://opensource.com/sites/default/files/uploads/kneighbors.png) + +This [Jupyter notebook][5] demonstrates the process and graphs the sparse matrix vectors. + +![](https://opensource.com/sites/default/files/uploads/anomaly-detection-with-scikit-learn.png) + +### Introducing Logreduce + +The Logreduce Python software transparently implements this process. Logreduce's initial goal was to assist with [Zuul CI][6] job failure analyses using the build database, and it is now integrated into the [Software Factory][7] development forge's job logs process. + +At its simplest, Logreduce compares files or directories and removes lines that are similar. Logreduce builds a model for each source file and outputs any of the target's lines whose distances are above a defined threshold by using the following syntax: **distance | filename:line-number: line-content**. + +``` +$ logreduce diff /var/log/audit/audit.log.1 /var/log/audit/audit.log +INFO  logreduce.Classifier - Training took 21.982s at 0.364MB/s (1.314kl/s) (8.000 MB - 28.884 kilo-lines) +0.244 | audit.log:19963:        type=USER_AUTH acct="root" exe="/usr/bin/su" hostname=managesf.sftests.com +INFO  logreduce.Classifier - Testing took 18.297s at 0.306MB/s (1.094kl/s) (5.607 MB - 20.015 kilo-lines) +99.99% reduction (from 20015 lines to 1 + +``` + +A more advanced Logreduce use can train a model offline to be reused. Many variants of the baselines can be used to fit the k-NN search tree. + +``` +$ logreduce dir-train audit.clf /var/log/audit/audit.log.* +INFO  logreduce.Classifier - Training took 80.883s at 0.396MB/s (1.397kl/s) (32.001 MB - 112.977 kilo-lines) +DEBUG logreduce.Classifier - audit.clf: written +$ logreduce dir-run audit.clf /var/log/audit/audit.log +``` + +Logreduce also implements interfaces to discover baselines for Journald time ranges (days/weeks/months) and Zuul CI job build histories. It can also generate HTML reports that group anomalies found in multiple files in a simple interface. + +![](https://opensource.com/sites/default/files/uploads/html-report.png) + +### Managing baselines + +The key to using k-NN regression for anomaly detection is to have a database of known good baselines, which the model uses to detect lines that deviate too far. This method relies on the baselines containing all nominal events, as anything that isn't found in the baseline will be reported as anomalous. + +CI jobs are great targets for k-NN regression because the job outputs are often deterministic and previous runs can be automatically used as baselines. Logreduce features Zuul job roles that can be used as part of a failed job post task in order to issue a concise report (instead of the full job's logs). This principle can be applied to other cases, as long as baselines can be constructed in advance. For example, a nominal system's [SoS report][8] can be used to find issues in a defective deployment. + +![](https://opensource.com/sites/default/files/uploads/baselines.png) + +### Anomaly classification service + +The next version of Logreduce introduces a server mode to offload log processing to an external service where reports can be further analyzed. It also supports importing existing reports and requests to analyze a Zuul build. The services run analyses asynchronously and feature a web interface to adjust scores and remove false positives. + +![](https://opensource.com/sites/default/files/uploads/classification-interface.png) + +Reviewed reports can be archived as a standalone dataset with the target log files and the scores for anomalous lines recorded in a flat JSON file. + +### Project roadmap + +Logreduce is already being used effectively, but there are many opportunities for improving the tool. Plans for the future include: + + * Curating many annotated anomalies found in log files and producing a public domain dataset to enable further research. Anomaly detection in log files is a challenging topic, and having a common dataset to test new models would help identify new solutions. + * Reusing the annotated anomalies with the model to refine the distances reported. For example, when users mark lines as false positives by setting their distance to zero, the model could reduce the score of those lines in future reports. + * Fingerprinting archived anomalies to detect when a new report contains an already known anomaly. Thus, instead of reporting the anomaly's content, the service could notify the user that the job hit a known issue. When the issue is fixed, the service could automatically restart the job. + * Supporting more baseline discovery interfaces for targets such as SOS reports, Jenkins builds, Travis CI, and more. + + + +If you are interested in getting involved in this project, please contact us on the **#log-classify** Freenode IRC channel. Feedback is always appreciated! + +Tristan Cacqueray will present [Reduce your log noise using machine learning][9] at the [OpenStack Summit][10], November 13-15 in Berlin. + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/9/quiet-log-noise-python-and-machine-learning + +作者:[Tristan de Cacqueray][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://opensource.com/users/tristanc +[1]: https://pypi.org/project/logreduce/ +[2]: http://man7.org/linux/man-pages/man8/systemd-journald.service.8.html +[3]: https://en.wikipedia.org/wiki/K-nearest_neighbors_algorithm +[4]: http://scikit-learn.org/stable/modules/generated/sklearn.feature_extraction.text.HashingVectorizer.html +[5]: https://github.com/TristanCacqueray/anomaly-detection-workshop-opendev/blob/master/datasets/notebook/anomaly-detection-with-scikit-learn.ipynb +[6]: https://zuul-ci.org +[7]: https://www.softwarefactory-project.io +[8]: https://sos.readthedocs.io/en/latest/ +[9]: https://www.openstack.org/summit/berlin-2018/summit-schedule/speakers/4307 +[10]: https://www.openstack.org/summit/berlin-2018/ diff --git a/sources/tech/20180928 Using Grails with jQuery and DataTables.md b/sources/tech/20180928 Using Grails with jQuery and DataTables.md new file mode 100644 index 0000000000..9a9ad08fb0 --- /dev/null +++ b/sources/tech/20180928 Using Grails with jQuery and DataTables.md @@ -0,0 +1,544 @@ +Using Grails with jQuery and DataTables +====== + +Learn to build a Grails-based data browser that lets users visualize complex tabular data. + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/data_container_block.png?itok=S8MbXEYw) + +I’m a huge fan of [Grails][1]. Granted, I’m mostly a data person who likes to explore and analyze data using command-line tools. But even data people sometimes need to _look at_ the data, and sometimes using data means having a great data browser. With Grails, [jQuery][2], and the [DataTables jQuery plugin][3], we can make really nice tabular data browsers. + +The [DataTables website][3] offers a lot of decent “recipe-style” documentation that shows how to put together some fine sample applications, and it includes the necessary JavaScript, HTML, and occasional [PHP][4] to accomplish some pretty spiffy stuff. But for those who would rather use Grails as their backend, a bit of interpretation is necessary. Also, the sample application data used is a single flat table of employees of a fictional company, so the complexity of dealing with table relations serves as an exercise for the reader. + +In this article, we’ll fill those two gaps by creating a Grails application with a slightly more complex data structure and a DataTables browser. In doing so, we’ll cover Grails criteria, which are [Groovy][5] -fied Java Hibernate criteria. I’ve put the code for the application on [GitHub][6] , so this article is oriented toward explaining the nuances of the code. + +For prerequisites, you will need Java, Groovy, and Grails environments set up. With Grails, I tend to use a terminal window and [Vim][7], so that’s what’s used here. To get a modern Java, I suggest downloading and installing the [Open Java Development Kit][8] (OpenJDK) provided by your Linux distro (which should be Java 8, 9, 10 or 11; at the time of writing, I’m working with Java 8). From my point of view, the best way to get up-to-date Groovy and Grails is to use [SDKMAN!][9]. + +Readers who have never tried Grails will probably need to do some background reading. As a starting point, I recommend [Creating Your First Grails Application][10]. + +### Getting the employee browser application + +As mentioned above, I’ve put the source code for this sample employee browser application on [GitHub][6]. For further explanation, the application **embrow** was built using the following commands in a Linux terminal window: + +``` +cd Projects +grails create-app com.nuevaconsulting.embrow +``` + +The domain classes and unit tests are created as follows: + +``` +grails create-domain-class com.nuevaconsulting.embrow.Position +grails create-domain-class com.nuevaconsulting.embrow.Office +grails create-domain-class com.nuevaconsulting.embrow.Employeecd embrowgrails createdomaincom.grails createdomaincom.grails createdomaincom. +``` + +The domain classes built this way have no attributes, so they must be edited as follows: + +The Position domain class: + +``` +package com.nuevaconsulting.embrow +  +class Position { + +    String name +    int starting + +    static constraints = { +        name nullable: false, blank: false +        starting nullable: false +    } +}com.Stringint startingstatic constraintsnullableblankstarting nullable +``` + +The Office domain class: + +``` +package com.nuevaconsulting.embrow +  +class Office { + +    String name +    String address +    String city +    String country + +    static constraints = { +        name nullable: false, blank: false +        address nullable: false, blank: false +        city nullable: false, blank: false +        country nullable: false, blank: false +    } +} +``` + +And the Employee domain class: + +``` +package com.nuevaconsulting.embrow +  +class Employee { + +    String surname +    String givenNames +    Position position +    Office office +    int extension +    Date hired +    int salary +    static constraints = { +        surname nullable: false, blank: false +        givenNames nullable: false, blank: false +        : false +        office nullable: false +        extension nullable: false +        hired nullable: false +        salary nullable: false +    } +} +``` + +Note that whereas the Position and Office domain classes use predefined Groovy types String and int, the Employee domain class defines fields that are of type Position and Office (as well as the predefined Date). This causes the creation of the database table in which instances of Employee are stored to contain references, or foreign keys, to the tables in which instances of Position and Office are stored. + +Now you can generate the controllers, views, and various other test components: + +``` +-all com.nuevaconsulting.embrow.Position +grails generate-all com.nuevaconsulting.embrow.Office +grails generate-all com.nuevaconsulting.embrow.Employeegrails generateall com.grails generateall com.grails generateall com. +``` + +At this point, you have a basic create-read-update-delete (CRUD) application ready to go. I’ve included some base data in the **grails-app/init/com/nuevaconsulting/BootStrap.groovy** to populate the tables. + +If you run the application with the command: + +``` +grails run-app +``` + +you will see the following screen in the browser at **** + +![Embrow home screen][12] + +The Embrow application home screen + +Clicking on the link for the OfficeController gives you a screen that looks like this: + +![Office list][14] + +The office list + +Note that this list is generated by the **OfficeController index** method and displayed by the view `office/index.gsp`. + +Similarly, clicking on the **EmployeeController** gives a screen that looks like this: + +![Employee controller][16] + +The employee controller + +Ok, that’s pretty ugly—what’s with the Position and Office links? + +Well, the views generated by the `generate-all` commands above create an **index.gsp** file that uses the Grails tag that by default shows the class name ( **com.nuevaconsulting.embrow.Position** ) and the persistent instance identifier ( **30** ). This behavior can be customized to yield something better looking, and there is some pretty neat stuff with the autogenerated links, the autogenerated pagination, and the autogenerated sortable columns. + +But even when it's fully cleaned up, this employee browser offers limited functionality. For example, what if you want to find all employees whose position includes the text “dev”? What if you want to combine columns for sorting so that the primary sort key is a surname and the secondary sort key is an office name? Or what if you want to export a sorted subset to a spreadsheet or PDF to email to someone who doesn’t have access to the browser? + +The jQuery DataTables plugin provides this kind of extra functionality and allows you to create a full-fledged tabular data browser. + +### Creating the employee browser view and controller methods + +In order to create an employee browser based on jQuery DataTables, you must complete two tasks: + + 1. Create a Grails view that incorporates the HTML and JavaScript required to enable the DataTables + + 2. Add a method to the Grails controller to handle the new view + + + + +#### The employee browser view + +In the directory **embrow/grails-app/views/employee** , start by making a copy of the **index.gsp** file, calling it **browser.gsp** : + +``` +cd Projects +cd embrow/grails-app/views/employee +cp gsp browser.gsp +``` + +At this point, you want to customize the new **browser.gsp** file to add the relevant jQuery DataTables code. + +As a rule, I like to grab my JavaScript and CSS from a content provider when feasible; to do so in this case, after the line: + +``` +<g:message code="default.list.label" args="[entityName]" /> +``` + +insert the following lines: + +``` + + + + + + + + + + + + +``` + +Next, remove the code that provided the data pagination in **index.gsp** : + +``` +
+

+ +
${flash.message}
+
+ + + +
+``` + +and insert the code that materializes the jQuery DataTables. + +The first part to insert is the HTML that creates the basic tabular structure of the browser. For the application where DataTables talks to a database backend, provide only the table headers and footers; the DataTables JavaScript takes care of the table contents. + +``` +
+

Employee Browser

+ + + + + + + + + + + + + + + + + + + + + + + +
SurnameGiven name(s)PositionOfficeExtensionHiredSalary
SurnameGiven name(s)PositionOfficeExtensionHiredSalary
+
+``` + +Next, insert a JavaScript block, which serves three primary functions: It sets the size of the text boxes shown in the footer for column filtering, it establishes the DataTables table model, and it creates a handler to do the column filtering. + +``` + +$('#employee_dt tfoot th').each( function() {javascript +``` + +The code below handles sizing the filter boxes at the bottoms of the table columns: + +``` +var title = $(this).text(); +if (title == 'Extension' || title == 'Hired') +$(this).html(''); +else +$(this).html(''); +});titletitletitletitletitle +``` + +Next, define the table model. This is where all the table options are provided, including the scrolling, rather than paginated, nature of the interface, the cryptic decorations to be provided according to the dom string, the ability to export data to CSV and other formats, as well as where the Ajax connection to the server is established. Note that the URL is created with a Groovy GString call to the Grails **createLink()** method, referring to the **browserLister** action in the **EmployeeController**. Also of interest is the definition of the columns of the table. This information is sent across to the back end, which queries the database and returns the appropriate records. + +``` +var table = $('#employee_dt').DataTable( { +"scrollY": 500, +"deferRender": true, +"scroller": true, +"dom": "Brtip", +"buttons": [ 'copy', 'csv', 'excel', 'pdf', 'print' ], +"processing": true, +"serverSide": true, +"ajax": { +"url": "${createLink(controller: 'employee', action: 'browserLister')}", +"type": "POST", +}, +"columns": [ +{ "data": "surname" }, +{ "data": "givenNames" }, +{ "data": "position" }, +{ "data": "office" }, +{ "data": "extension" }, +{ "data": "hired" }, +{ "data": "salary" } +] +}); +``` + +Finally, monitor the filter columns for changes and use them to apply the filter(s). + +``` +table.columns().every(function() { +var that = this; +$('input', this.footer()).on('keyup change', function(e) { +if (that.search() != this.value && 8 < e.keyCode && e.keyCode < 32) +that.search(this.value).draw(); +}); +``` + +And that’s it for the JavaScript. This completes the changes to the view code. + +``` +}); + +``` + +Here’s a screenshot of the UI this view creates: + +![](https://opensource.com/sites/default/files/uploads/screen_4.png) + +Here’s another screenshot showing the filtering and multi-column sorting at work (looking for employees whose positions include the characters “dev”, ordering first by office, then by surname): + +![](https://opensource.com/sites/default/files/uploads/screen_5.png) + +Here’s another screenshot, showing what happens when you click on the CSV button: + +![](https://opensource.com/sites/default/files/uploads/screen6.png) + +And finally, here’s a screenshot showing the CSV data opened in LibreOffice: + +![](https://opensource.com/sites/default/files/uploads/screen7.png) + +Ok, so the view part looked pretty straightforward; therefore, the controller action must do all the heavy lifting, right? Let’s see… + +#### The employee controller browserLister action + +Recall that we saw this string + +``` +"${createLink(controller: 'employee', action: 'browserLister')}" +``` + +as the URL used for the Ajax calls from the DataTables table model. [createLink() is the method][17] behind a Grails tag that is used to dynamically generate a link as the HTML is preprocessed on the Grails server. This ends up generating a link to the **EmployeeController** , located in + +``` +embrow/grails-app/controllers/com/nuevaconsulting/embrow/EmployeeController.groovy +``` + +and specifically to the controller method **browserLister()**. I’ve left some print statements in the code so that the intermediate results can be seen in the terminal window where the application is running. + +``` +    def browserLister() { +        // Applies filters and sorting to return a list of desired employees +``` + +First, print out the parameters passed to **browserLister()**. I usually start building controller methods with this code so that I’m completely clear on what my controller is receiving. + +``` +      println "employee browserLister params $params" +        println() +``` + +Next, process those parameters to put them in a more usable shape. First, the jQuery DataTables parameters, a Groovy map called **jqdtParams** : + +``` +def jqdtParams = [:] +params.each { key, value -> + def keyFields = key.replace(']','').split(/\[/) + def table = jqdtParams + for (int f = 0; f < keyFields.size() - 1; f++) { + def keyField = keyFields[f] + if (!table.containsKey(keyField)) + table[keyField] = [:] + table = table[keyField] + } + table[keyFields[-1]] = value +} +println "employee dataTableParams $jqdtParams" +println() +``` + +Next, the column data, a Groovy map called **columnMap** : + +``` +def columnMap = jqdtParams.columns.collectEntries { k, v -> + def whereTerm = null + switch (v.data) { + case 'extension': + case 'hired': + case 'salary': + if (v.search.value ==~ /\d+(,\d+)*/) + whereTerm = v.search.value.split(',').collect { it as Integer } + break + default: + if (v.search.value ==~ /[A-Za-z0-9 ]+/) + whereTerm = "%${v.search.value}%" as String + break + } + [(v.data): [where: whereTerm]] +} +println "employee columnMap $columnMap" +println() +``` + +Next, a list of all column names, retrieved from **columnMap** , and a corresponding list of how those columns should be ordered in the view, Groovy lists called **allColumnList** and **orderList** , respectively: + +``` +def allColumnList = columnMap.keySet() as List +println "employee allColumnList $allColumnList" +def orderList = jqdtParams.order.collect { k, v -> [allColumnList[v.column as Integer], v.dir] } +println "employee orderList $orderList" +``` + +We’re going to use Grails’ implementation of Hibernate criteria to actually carry out the selection of elements to be displayed as well as their ordering and pagination. Criteria requires a filter closure; in most examples, this is given as part of the creation of the criteria instance itself, but here we define the filter closure beforehand. Note in this case the relatively complex interpretation of the “date hired” filter, which is treated as a year and applied to establish date ranges, and the use of **createAlias** to allow us to reach into related classes Position and Office: + +``` +def filterer = { + createAlias 'position', 'p' + createAlias 'office', 'o' + + if (columnMap.surname.where) ilike 'surname', columnMap.surname.where + if (columnMap.givenNames.where) ilike 'givenNames', columnMap.givenNames.where + if (columnMap.position.where) ilike 'p.name', columnMap.position.where + if (columnMap.office.where) ilike 'o.name', columnMap.office.where + if (columnMap.extension.where) inList 'extension', columnMap.extension.where + if (columnMap.salary.where) inList 'salary', columnMap.salary.where + if (columnMap.hired.where) { + if (columnMap.hired.where.size() > 1) { + or { + columnMap.hired.where.each { + between 'hired', Date.parse('yyyy/MM/dd',"${it}/01/01" as String), + Date.parse('yyyy/MM/dd',"${it}/12/31" as String) + } + } + } else { + between 'hired', Date.parse('yyyy/MM/dd',"${columnMap.hired.where[0]}/01/01" as String), + Date.parse('yyyy/MM/dd',"${columnMap.hired.where[0]}/12/31" as String) + } + } +} +``` + +At this point, it’s time to apply the foregoing. The first step is to get a total count of all the Employee instances, required by the pagination code: + +``` +        def recordsTotal = Employee.count() +        println "employee recordsTotal $recordsTotal" +``` + +Next, apply the filter to the Employee instances to get the count of filtered results, which will always be less than or equal to the total number (again, this is for the pagination code): + +``` +        def c = Employee.createCriteria() +        def recordsFiltered = c.count { +            filterer.delegate = delegate +            filterer() +        } +        println "employee recordsFiltered $recordsFiltered" + +``` + +Once you have those two counts, you can get the actual filtered instances using the pagination and ordering information as well. + +``` + def orderer = Employee.withCriteria { + filterer.delegate = delegate + filterer() + orderList.each { oi -> + switch (oi[0]) { + case 'surname': order 'surname', oi[1]; break + case 'givenNames': order 'givenNames', oi[1]; break + case 'position': order 'p.name', oi[1]; break + case 'office': order 'o.name', oi[1]; break + case 'extension': order 'extension', oi[1]; break + case 'hired': order 'hired', oi[1]; break + case 'salary': order 'salary', oi[1]; break + } + } + maxResults (jqdtParams.length as Integer) + firstResult (jqdtParams.start as Integer) + } +``` + +To be completely clear, the pagination code in JTables manages three counts: the total number of records in the data set, the number resulting after the filters are applied, and the number to be displayed on the page (whether the display is scrolling or paginated). The ordering is applied to all the filtered records and the pagination is applied to chunks of those filtered records for display purposes. + +Next, process the results returned by the orderer, creating links to the Employee, Position, and Office instance in each row so the user can click on these links to get all the detail on the relevant instance: + +``` +        def dollarFormatter = new DecimalFormat('$##,###.##') +        def employees = orderer.collect { employee -> +            ['surname': "${employee.surname}", +                'givenNames': employee.givenNames, +                'position': "${employee.position?.name}", +                'office': "${employee.office?.name}", +                'extension': employee.extension, +                'hired': employee.hired.format('yyyy/MM/dd'), +                'salary': dollarFormatter.format(employee.salary)] +        } +``` + +And finally, create the result you want to return and give it back as JSON, which is what jQuery DataTables requires. + +``` + def result = [draw: jqdtParams.draw, recordsTotal: recordsTotal, recordsFiltered: recordsFiltered, data: employees] + render(result as JSON) + } +``` + +That’s it. + +If you’re familiar with Grails, this probably seems like more work than you might have originally thought, but there’s no rocket science here, just a lot of moving parts. However, if you haven’t had much exposure to Grails (or to Groovy), there’s a lot of new stuff to understand—closures, delegates, and builders, among other things. + +In that case, where to start? The best place is to learn about Groovy itself, especially [Groovy closures][18] and [Groovy delegates and builders][19]. Then go back to the reading suggested above on Grails and Hibernate criteria queries. + +### Conclusions + +jQuery DataTables make awesome tabular data browsers for Grails. Coding the view isn’t too tricky, but the PHP examples provided in the DataTables documentation take you only so far. In particular, they aren’t written with Grails programmers in mind, nor do they explore the finer details of using elements that are references to other classes (essentially lookup tables). + +I’ve used this approach to make a couple of data browsers that allow the user to select which columns to view and accumulate record counts, or just to browse the data. The performance is good even in million-row tables on a relatively modest VPS. + +One caveat: I have stumbled upon some problems with the various Hibernate criteria mechanisms exposed in Grails (see my other GitHub repositories), so care and experimentation is required. If all else fails, the alternative approach is to build SQL strings on the fly and execute them instead. As of this writing, I prefer to work with Grails criteria, unless I get into messy subqueries, but that may just reflect my relative lack of experience with subqueries in Hibernate. + +I hope you Grails programmers out there find this interesting. Please feel free to leave comments or suggestions below. + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/9/using-grails-jquery-and-datatables + +作者:[Chris Hermansen][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://opensource.com/users/clhermansen +[1]: https://grails.org/ +[2]: https://jquery.com/ +[3]: https://datatables.net/ +[4]: http://php.net/ +[5]: http://groovy-lang.org/ +[6]: https://github.com/monetschemist/grails-datatables +[7]: https://www.vim.org/ +[8]: http://openjdk.java.net/ +[9]: http://sdkman.io/ +[10]: http://guides.grails.org/creating-your-first-grails-app/guide/index.html +[11]: https://opensource.com/file/410061 +[12]: https://opensource.com/sites/default/files/uploads/screen_1.png (Embrow home screen) +[13]: https://opensource.com/file/410066 +[14]: https://opensource.com/sites/default/files/uploads/screen_2.png (Office list screenshot) +[15]: https://opensource.com/file/410071 +[16]: https://opensource.com/sites/default/files/uploads/screen3.png (Employee controller screenshot) +[17]: https://gsp.grails.org/latest/ref/Tags/createLink.html +[18]: http://groovy-lang.org/closures.html +[19]: http://groovy-lang.org/dsls.html diff --git a/sources/tech/20180928 What containers can teach us about DevOps.md b/sources/tech/20180928 What containers can teach us about DevOps.md new file mode 100644 index 0000000000..610a68b2d1 --- /dev/null +++ b/sources/tech/20180928 What containers can teach us about DevOps.md @@ -0,0 +1,99 @@ +What containers can teach us about DevOps +====== + +The use of containers supports the three pillars of DevOps practices: flow, feedback, and continual experimentation and learning. + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/LAW-patent_reform_520x292_10136657_1012_dc.png?itok=Cd2PmDWf) + +One can argue that containers and DevOps were made for one another. Certainly, the container ecosystem benefits from the skyrocketing popularity of DevOps practices, both in design choices and in DevOps’ use by teams developing container technologies. Because of this parallel evolution, the use of containers in production can teach teams the fundamentals of DevOps and its three pillars: [The Three Ways][1]. + +### Principles of flow + +**Container flow** + +A container can be seen as a silo, and from inside, it is easy to forget the rest of the system: the host node, the cluster, the underlying infrastructure. Inside the container, it might appear that everything is functioning in an acceptable manner. From the outside perspective, though, the application inside the container is a part of a larger ecosystem of applications that make up a service: the web API, the web app user interface, the database, the workers, and caching services and garbage collectors. Teams put constraints on the container to limit performance impact on infrastructure, and much has been done to provide metrics for measuring container performance because overloaded or slow container workloads have downstream impact on other services or customers. + +**Real-world flow** + +This lesson can be applied to teams functioning in a silo as well. Every process (be it code release, infrastructure creation or even, say, manufacturing of [Spacely’s Sprockets][2]), follows a linear path from conception to realization. In technology, this progress flows from development to testing to operations and release. If a team working alone becomes a bottleneck or introduces a problem, the impact is felt all along the entire pipeline. A defect passed down the line destroys productivity downstream. While the broken process within the scope of the team itself may seem perfectly correct, it has a negative impact on the environment as a whole. + +**DevOps and flow** + +The first way of DevOps, principles of flow, is about approaching the process as a whole, striving to comprehend how the system works together and understanding the impact of issues on the entire process. To increase the efficiency of the process, pain points and waste are identified and removed. This is an ongoing process; teams must continually strive to increase visibility into the process and find and fix trouble spots and waste. + +> “The outcomes of putting the First Way into practice include never passing a known defect to downstream work centers, never allowing local optimization to create global degradation, always seeking to increase flow, and always seeking to achieve a profound understanding of the system (as per Deming).” + +–Gene Kim, [The Three Ways: The Principles Underpinning DevOps][3], IT Revolution, 25 Apr. 2017 + +### Principles of feedback + +**Container feedback** + +In addition to limiting containers to prevent impact elsewhere, many products have been created to monitor and trend container metrics in an effort to understand what they are doing and notify when they are misbehaving. [Prometheus][4], for example, is [all the rage][5] for collecting metrics from containers and clusters. Containers are excellent at separating applications and providing a way to ship an environment together with the code, sometimes at the cost of opacity, so much is done to try to provide rapid feedback so issues can be addressed promptly within the silo. + +**Real-world feedback** + +The same is necessary for the flow of the system. From inception to realization, an efficient process quickly provides relevant feedback to identify when there is an issue. The key words here are “quick” and “relevant.” Burying teams in thousands of irrelevant notifications make it difficult or even impossible to notice important events that need immediate action, and receiving even relevant information too late may allow small, easily solved issues to move downstream and become bigger problems. Imagine [if Lucy and Ethel][6] had provided immediate feedback that the conveyor belt was too fast—there would have been no problem with the chocolate production (though that would not have been nearly as funny). + +**DevOps and feedback** + +The Second Way of DevOps, principles of feedback, is all about getting relevant information quickly. With immediate, useful feedback, problems can be identified as they happen and addressed before impact is felt elsewhere in the development process. DevOps teams strive to “optimize for downstream” and immediately move to fix problems that might impact other teams that come after them. As with flow, feedback is a continual process to identify ways to quickly get important data and act on problems as they occur. + +> “Creating fast feedback is critical to achieving quality, reliability, and safety in the technology value stream.” + +–Gene Kim, et al., The DevOps Handbook: How to Create World-Class Agility, Reliability, and Security in Technology Organizations, IT Revolution Press, 2016 + +### Principles of continual experimentation and learning + +**Container continual experimentation and learning** + +It is a bit more challenging applying operational learning to the Third Way of DevOps:continual experimentation and learning. Trying to salvage what we can grasp of the very edges of the metaphor, containers make development easy, allowing developers and operations teams to test new code or configurations locally and safely outside of production and incorporate discovered benefits into production in a way that was difficult in the past. Changes can be radical and still version-controlled, documented, and shared quickly and easily. + +**Real-world continual experimentation and learning** + +For example, consider this anecdote from my own experience: Years ago, as a young, inexperienced sysadmin (just three weeks into the job), I was asked to make changes to an Apache virtual host running the website of the central IT department for a university. Without an easy-to-use test environment, I made a configuration change to the production site that I thought would accomplish the task and pushed it out. Within a few minutes, I overheard coworkers in the next cube: + +“Wait, is the website down?” + +“Hrm, yeah, it looks like it. What the heck?” + +There was much eye-rolling involved. + +Mortified (the shame is real, folks), I sunk down as far as I could into my seat and furiously tried to back out the changes I’d introduced. Later that same afternoon, the director of the department—the boss of my boss’s boss—appeared in my cube to talk about what had happened. “Don’t worry,” she told me. “We’re not mad at you. It was a mistake and now you have learned.” + +In the world of containers, this could have been easily changed and tested on my own laptop and the broken configuration identified by more skilled team members long before it ever made it into production. + +**DevOps continual experimentation and learning** + +A real culture of experimentation promotes the individual’s ability to find where a change in the process may be beneficial, and to test that assumption without the fear of retaliation if they fail. For DevOps teams, failure becomes an educational tool that adds to the knowledge of the individual and organization, rather than something to be feared or punished. Individuals in the DevOps team dedicate themselves to continuous learning, which in turn benefits the team and wider organization as that knowledge is shared. + +As the metaphor completely falls apart, focus needs to be given to a specific point: The other two principles may appear at first glance to focus entirely on process, but continual learning is a human task—important for the future of the project, the person, the team, and the organization. It has an impact on the process, but it also has an impact on the individual and other people. + +> “Experimentation and risk-taking are what enable us to relentlessly improve our system of work, which often requires us to do things very differently than how we’ve done it for decades.” + +–Gene Kim, et al., [The Phoenix Project: A Novel about IT, DevOps, and Helping Your Business Win][7], IT Revolution Press, 2013 + +### Containers can teach us DevOps + +Learning to work effectively with containers can help teach DevOps and the Three Ways: principles of flow, principles of feedback, and principles of continuous experimentation and learning. Looking holistically at the application and infrastructure rather than putting on blinders to everything outside the container teaches us to take all parts of the system and understand their upstream and downstream impacts, break out of silos, and work as a team to increase global performance and deep understanding of the entire system. Working to provide timely and accurate feedback teaches us to create effective feedback patterns within our organizations to identify problems before their impact grows. Finally, providing a safe environment to try new ideas and learn from them teaches us to create a culture where failure represents a positive addition to our knowledge and the ability to take big chances with educated guesses can result in new, elegant solutions to complex problems. + + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/9/containers-can-teach-us-devops + +作者:[Chris Hermansen][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://opensource.com/users/clhermansen +[1]: https://itrevolution.com/the-three-ways-principles-underpinning-devops/ +[2]: https://en.wikipedia.org/wiki/The_Jetsons +[3]: http://itrevolution.com/the-three-ways-principles-underpinning-devops +[4]: https://prometheus.io/ +[5]: https://opensource.com/article/18/9/prometheus-operational-advantage +[6]: https://www.youtube.com/watch?v=8NPzLBSBzPI +[7]: https://itrevolution.com/book/the-phoenix-project/ diff --git a/sources/tech/20180929 Use Cozy to Play Audiobooks in Linux.md b/sources/tech/20180929 Use Cozy to Play Audiobooks in Linux.md new file mode 100644 index 0000000000..8e6583f046 --- /dev/null +++ b/sources/tech/20180929 Use Cozy to Play Audiobooks in Linux.md @@ -0,0 +1,138 @@ +Use Cozy to Play Audiobooks in Linux +====== +**We review Cozy, an audiobook player for Linux. Read to find out if it’s worth to install Cozy on your Linux system or not.** + +![Audiobook player for Linux][1] + +Audiobooks are a great way to consume literature. Many people who don’t have time to read, choose to listen. Most people, myself included, just use a regular media player like VLC or [MPV][2] for listening to audiobooks on Linux. + +Today, we will look at a Linux application built solely for listening to audiobooks. + +![][3]Cozy Audiobook Player + +### Cozy Audiobook Player for Linux + +The [Cozy Audiobook Player][4] is created by [Julian Geywitz][5] from Germany. It is built using both Python and GTK+ 3. According to the site, Julian wrote Cozy on Fedora and optimized it for [elementary OS][6]. + +The player borrows its layout from iTunes. The player controls are placed along the top of the application The library takes up the rest. You can sort all of your audiobooks based on the title, author and reader, and search very quickly. + +![][7]Initial setup + +When you first launch [Cozy][8], you are given the option to choose where you will store your audiobook files. Cozy will keep an eye on that folder and update your library as you add new audiobooks. You can also set it up to use an external or network drive. + +#### Features of Cozy + +Here is a full list of the features that [Cozy][9] has to offer. + + * Import all your audiobooks into Cozy to browse them comfortably + * Sort your audiobooks by author, reader & title + * Remembers your playback position + * Sleep timer + * Playback speed control + * Search your audiobook library + * Add multiple storage locations + * Drag & Drop to import new audio books + * Support for DRM free mp3, m4a (aac, ALAC, …), flac, ogg, wav files + * Mpris integration (Media keys & playback info for the desktop environment) + * Developed on Fedora and tested under elementaryOS + + + +#### Experiencing Cozy + +![][10]Audiobook library + +At first, I was excited to try our Cozy because I like to listen to audiobooks. However, I ran into a couple of issues. There is no way to edit the information of an audiobook. For example, I downloaded a couple audiobooks from [LibriVox][11] to test it. All three audiobooks were listed under “Unknown” for the reader. There was nothing to edit or change the audiobook info. I guess you could edit all of the files, but that would take quite a bit of time. + +When I listen to an audiobook, I like to know what track is currently playing. Cozy only has a single progress bar for the whole audiobook. I know that Cozy is designed to remember where you left off in an audiobook, but if I was going to continue to listen to the audiobook on my phone, I would like to know what track I am on. + +![][12]Settings + +There was also an option in the setting menu to turn on a dark theme. As you can see in the screenshots, the application has a black theme, to begin with. I turned the option on, but nothing happened. There isn’t even an option to add a theme or change any of the colors. Overall, the application had a feeling of not being finished. + +#### Installing Cozy on Linux + +If you would like to install Cozy, you have several options for different distros. + +##### Ubuntu, Debian, openSUSE, Fedora + +Julian used the [openSUSE Build Service][13] to create custom repos for Ubuntu, Debian, openSUSE and Fedora. Each one only takes a couple terminal commands to install. + +##### Install Cozy using Flatpak on any Linux distribution (including Ubuntu) + +If your [distro supports Flatpak][14], you can install Cozy using the following commands: + +``` +flatpak remote-add --user --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo +flatpak install --user flathub com.github.geigi.cozy +``` + +##### Install Cozy on elementary OS + +If you have elementary OS installed, you can install Cozy from the [built-in App Store][15]. + +##### Install Cozy on Arch Linux + +Cozy is available in the [Arch User Repository][16]. All you have to do is search for `cozy-audiobooks`. + +### Where to find free Audiobooks? + +In order to try out this application, you will need to find some audiobooks to listen to. My favorite site for audiobooks is [LibriVox][11]. Since [LibriVox][17] depends on volunteers to record audiobooks, the quality can vary. However, there are a number of very talented readers. + +Here is a list of free audiobook sources: + ++ [Open Culture][20] ++ [Project Gutenberg][21] ++ [Digitalbook.io][22] ++ [FreeClassicAudioBooks.com][23] ++ [MindWebs][24] ++ [Scribl][25] + + +### Final Thoughts on Cozy + +For now, I think I’ll stick with my preferred audiobook software (VLC) for now. Cozy just doesn’t add anything. I won’t call it a [must-have application for Linux][18] just yet. There is no compelling reason for me to switch. Maybe, I’ll revisit it again in the future, maybe when it hits 1.0. + +Take Cozy for a spin. You might come to a different conclusion. + +Have you ever used Cozy? If not, what is your favorite audiobook player? What is your favorite source for free audiobooks? Let us know in the comments below. + +If you found this article interesting, please take a minute to share it on social media, Hacker News or [Reddit][19]. + +-------------------------------------------------------------------------------- + +via: https://itsfoss.com/cozy-audiobook-player/ + +作者:[John Paul][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://itsfoss.com/author/john/ +[1]: https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/09/audiobook-player-linux.png +[2]: https://itsfoss.com/mpv-video-player/ +[3]: https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/09/cozy3.jpg +[4]: https://cozy.geigi.de/ +[5]: https://github.com/geigi +[6]: https://elementary.io/ +[7]: https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/09/cozy1.jpg +[8]: https://github.com/geigi/cozy +[9]: https://www.patreon.com/geigi +[10]: https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/09/cozy2.jpg +[11]: https://librivox.org/ +[12]: https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/09/cozy4.jpg +[13]: https://software.opensuse.org//download.html?project=home%3Ageigi&package=com.github.geigi.cozy +[14]: https://itsfoss.com/flatpak-guide/ +[15]: https://elementary.io/store/ +[16]: https://aur.archlinux.org/ +[17]: https://archive.org/details/librivoxaudio +[18]: https://itsfoss.com/essential-linux-applications/ +[19]: http://reddit.com/r/linuxusersgroup +[20]: http://www.openculture.com/freeaudiobooks +[21]: http://www.gutenberg.org/browse/categories/1 +[22]: https://www.digitalbook.io/ +[23]: http://freeclassicaudiobooks.com/ +[24]: https://archive.org/details/MindWebs_201410 +[25]: https://scribl.com/ diff --git a/translated/talk/20180107 7 leadership rules for the DevOps age.md b/translated/talk/20180107 7 leadership rules for the DevOps age.md deleted file mode 100644 index 587d7761fb..0000000000 --- a/translated/talk/20180107 7 leadership rules for the DevOps age.md +++ /dev/null @@ -1,119 +0,0 @@ -DevOps时代的7个领导准则 -====== - -![](https://enterprisersproject.com/sites/default/files/styles/620x350/public/images/CIO_DigitalAcumen_2.png?itok=TGeMQYs4) - -如果[DevOps]最终更多的是关于文化而不是任何其他的技术或者平台,那么请记住:没有终点线。而是继续改变和提高--而且最高管理层并没有通过。 - -然而,如果期望DevOps能够帮助获得更多的成果,领导者需要[修订他们的一些传统的方法][2]让我们考虑7个在DevOps时代更有效的IT领导的想法。 - -### 1. 向失败说“是的” - -“失败”这个词在IT领域中一直包含着特殊的内涵,而且通常是糟糕的意思:服务器失败,备份失败,硬盘驱动器失败-你得了解这些情况。 - -然而一种健康的DevOps文化取决于重新定义失败-IT领导者在他们的字典里应该重新定义这个单词将它的含义和“机会”对等起来。 - -“在DevOps之前,我们曾有一种惩罚失败者的文化,”罗伯特·里夫斯说,[Datical][3]的首席技术官兼联合创始人。“我们学到的仅仅是去避免错误。在IT领域避免错误的首要措施就是不要去改变任何东西:不要加速版本迭代的日程,不要迁移到云中,不要去做任何不同的事” - -那是过去的一个时代的剧本,里夫斯坦诚的说,它已经不起作用了,事实上,那种停滞是失败的。 - -“那些缓慢的释放并逃避云的公司被恐惧所麻痹-他们将会走向失败,”里夫斯说道。“IT领导者必须拥抱失败并把它当做成一个机遇。人们不仅仅从他们的过错中学习,也会从其他的错误中学习。一种开放和[安全心里][4]的文化促进学习和提高” -**[相关文章:[为什么敏捷领导者谈论“失败”必须超越它本义]] -### 2. 在管理层渗透开发运营的理念 - -尽管DevOps文化可以在各个方向有机的发展,那些正在从整体中转变,孤立的IT实践,而且可能遭遇逆风的公司-需要执行领导层的全面支持。你正在传达模糊的信息 -而且可能会鼓励那些愿意推一把的人,这是我们一贯的做事方式。[改变文化是困难的][6];人们需要看到领导层完全投入进去并且知道改变已经实际发生了。 - -“为了成功的实现利益的兑现高层管理必须全力支持DevOps,”来自[Rainforest QA][7]的首席技术官说道。 - -成为一个DevOps商店。德里克指出,涉及到公司的一切,从技术团队到工具到进程到规则和责任。 - -"没有高层管理的统一赞助支持,DevOps的实施将很难成功,"德里克说道。"因此,在转变到DevOps之前在高层中有支持的领导同盟是很重要的。" - -### 3. 不要只是声明“DevOps”-要明确它 -即使IT公司也已经开始拥抱欢迎DevOps,每个人可能不是在同一个进程上。 -**[参考我们的相关文章,**][**3 阐明了DevOps和首席技术官们必须在同一进程上**][8] **.]** - -造成这种脱节的一个根本原因是:人们对这个术语的有着不同的定义理解。 - -“DevOps 对不同的人可能意味着不同的含义,”德里克解释道。“对高管层和副总裁层来说,执行明确的DevOps的目标,清楚的声明期望的成果,充分理解带来的成果将如何使公司的商业受益并且能够衡量和报告成功的过程。” - -事实上,在基线和视野之上,DevOps要求正在进行频繁的交流,不是仅仅在小团队里,而是要贯穿到整个组织。IT领导者必须为它设置优先级。 - -“不可避免的,将会有些阻碍,在商业中将会存在失败和破坏,”德里克说道。“领导者名需要清楚的将这个过程向公司的其他人阐述清楚告诉他们他们作为这个过程的一份子能够期待的结果。” - -### 4. DevOps和技术同样重要 - -IT领导者们成功的将DevOps商店的这种文化和实践当做一项商业策略,与构建和运营软件的方法相结合。DevOps是将IT从支持部门转向战略部门的推动力。 - -IT领导者们必须转变他们的思想和方法,从成本和服务中心转变到驱动商业成果,而且DevOps的文化能够通过自动化和强大的协作加速收益。来自[CYBRIC][9]的首席技术官和联合创始人迈克说道。 - -事实上,这是一个强烈的趋势通过更多的这些规则在DevOps时代走在前沿。 - -“促进创新并且鼓励团队成员去聪明的冒险是DevOps文化的一个关键部分,IT领导者们需要在一个持续的基础上清楚的和他们交流,”凯尔说道。 - -“一个高效的IT领导者需要比以往任何时候都要积极的参与到商业中去,”来自[West Monroe Partners][10]的性能服务部门的主任埃文说道。“每年或季度回顾的日子一去不复返了-你需要欢迎每两周一次的待办事项。[11]你需要有在年度水平上的思考战略能力,在冲刺阶段的互动能力,在商业期望满足时将会被给予一定的奖励。” - -### 5. 改变妨碍DevOps目标的任何事情 - -虽然DevOps的老兵们普遍认为DevOps更多的是一种文化而不是技术,成功取决于通过正确的过程和工具激活文化。当你声称自己的部门是一个DevOps商店却拒绝对进程或技术做必要的改变,这就是你买了辆法拉利却使用了用过20年的引擎,每次转动钥匙都会冒烟。 - -展览 A: [自动化][12].这是DevOps成功的重要并行策略。 - -“IT领导者需要重点强调自动化,”卡伦德说。“这将是DevOps的前期投资,但是如果没有它,DevOps将会很容易被低效吞噬自己而且将会无法完整交付。” - -自动化是基石,但改变不止于此。 - -“领导者们需要推动自动化,监控和持续的交付过程。这意着对现有的实践,过程,团队架构以及规则的很多改变,”Choy说。“领导者们需要改变一切会阻碍隐藏团队去全利实现自动化的因素。” - -### 6. 重新思考团队架构和能力指标 - -当你想改变时...如果你桌面上的组织结构图和你过去大部分时候嵌入的名字都是一样的,那么你是时候该考虑改革了。 - -“在这个DevOps的新时代文化中,IT执行者需要采取一个全新的方法来组织架构。”Kail说。“消除组织的边界限制,它会阻碍团队间的合作,允许团队自我组织,敏捷管理。” - -Kail告诉我们在DevOps时代,这种反思也应该拓展应用到其他领域,包括你怎样衡量个人或者团队的成功,甚至是你和人们的互动。 - -“根据业务成果和总体的积极影响来衡量主动性,”Kail建议。“最后,我认为管理中最重要的一个方面是:有同理心。” - -注意很容易收集的到测量值不是DevOps真正的指标,[Red Hat]的技术专员Gardon Half写到,“DevOps应该把指标以某种形式和商业成果绑定在一起,”他指出。“你可能真的不在乎开发者些了多少代码,是否有一台服务器在深夜硬件损坏,或者是你的测试是多么的全面。你甚至都不直接关注你的网站的响应情况或者是你更新的速度。但是你要注意的是这些指标可能和顾客放弃购物车去竞争对手那里有关,”参考他的文章,[DevOps 指标:你在测量什么?] - -### 7. 丢弃传统的智慧 - -如果DevOps时代要求关于IT领导能力的新的思考方式,那么也就意味着一些旧的方法要被淘汰。但是是哪些呢? - -“是实话,是全部,”Kail说道。“要摆脱‘因为我们一直都是以这种方法做事的’的心态。过渡到DevOps文化是一种彻底的思维模式的转变,不是对瀑布式的过去和变革委员会的一些细微改变。” - -事实上,IT领导者们认识到真正的变革要求的不只是对旧方法的小小接触。它更多的是要求对之前的进程或者策略的一个重新启动。 - -West Monroe Partners的卡伦德分享了一个阻碍DevOps的领导力的例子:未能拥抱IT混合模型和现代的基础架构比如说容器和微服务 - -“我所看到的一个大的规则就是架构整合,或者认为在一个同质的环境下长期的维护会更便宜,”卡伦德说。 - -**想要更多像这样的智慧吗?[注册我们的每周邮件新闻报道][15].** --------------------------------------------------------------------------------- - -via: https://enterprisersproject.com/article/2018/1/7-leadership-rules-devops-age - -作者:[Kevin Casey][a] -译者:[译者FelixYFZ](https://github.com/FelixYFZ) -校对:[校对者ID](https://github.com/校对者ID) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 - -[a]:https://enterprisersproject.com/user/kevin-casey -[1]:https://enterprisersproject.com/tags/devops -[2]:https://enterprisersproject.com/article/2017/7/devops-requires-dumping-old-it-leadership-ideas -[3]:https://www.datical.com/ -[4]:https://rework.withgoogle.com/guides/understanding-team-effectiveness/steps/foster-psychological-safety/ -[5]:https://enterprisersproject.com/article/2017/10/why-agile-leaders-must-move-beyond-talking-about-failure?sc_cid=70160000000h0aXAAQ -[6]:https://enterprisersproject.com/article/2017/10/how-beat-fear-and-loathing-it-change -[7]:https://www.rainforestqa.com/ -[8]:https://enterprisersproject.com/article/2018/1/3-areas-where-devops-and-cios-must-get-same-page -[9]:https://www.cybric.io/ -[10]:http://www.westmonroepartners.com/ -[11]:https://www.scrumalliance.org/community/articles/2017/february/product-backlog-grooming -[12]:https://www.redhat.com/en/topics/automation?intcmp=701f2000000tjyaAAA -[13]:https://www.redhat.com/en?intcmp=701f2000000tjyaAAA -[14]:https://enterprisersproject.com/article/2017/7/devops-metrics-are-you-measuring-what-matters -[15]:https://enterprisersproject.com/email-newsletter?intcmp=701f2000000tsjPAAQ diff --git a/translated/talk/20180115 Why DevSecOps matters to IT leaders.md b/translated/talk/20180115 Why DevSecOps matters to IT leaders.md deleted file mode 100644 index aaf03510a7..0000000000 --- a/translated/talk/20180115 Why DevSecOps matters to IT leaders.md +++ /dev/null @@ -1,86 +0,0 @@ -为什么DevSecOps对领导来说如此重要 -====== - -![](https://enterprisersproject.com/sites/default/files/styles/620x350/public/images/TEP_SecurityTraining1_620x414_1014.png?itok=zqxqJGDG) - -如果[DevOps][1] 最终是关于创造更好的软件,那也就意味着是更安全的软件。 - -输入术语“DevSecOps.”像任何其他IT术语一样,DevSecOps - 一个整容后的DevOps的后代 -可能容易被炒作和盗用。但这个术语对那些拥抱DevOps文化的领导者们,帮助他们实现其承诺的实践和工具来说具有重要的意义。 - -说道这里:“DevSecOps”是什么意思? - -“DevSecOps是开发、安全、运营的混合,”来自[Datical][2]的首席技术官和联合创始人罗伯特说。“这提醒我们安全对我们的应用程序来说和创建并部署应用到生产中一样重要。” -**[想阅读其他首席技术官的DevOps文章吗?查阅我们广泛的资源,[DevOps:IT领导者的指南][3].]** - -向非技术人员解释DevSecOps的一个简单的方法是:它是指将安全有意并提前加入到开发过程中。 - -”安全团队从历史上一直都被从开发团队中所孤立-每个团队在IT的不同领域都开发了很强的专业能力,”来自红帽安全策的专家Kirsten最近告诉我们。“它不需要这样,非常关注安全也关注他们通过软件来兑现商业价值的能力的企业正在寻找能够在应用开发生命周期中加入安全的方法。他们通过在整个CI/CD管道中集成安全实践,工具和自动化来采用DevSecOps.” - -"为了能够做的更好,他们正在整合他们的团队-专业的安全人员从开始设计到部署到生产中都嵌入到了应开发团队中了,"她说。“双方都收获了价值-每个团队都拓展了他们的技能和基础知识,使他们自己都成更有价值的技术人员。DevOps做的很正确-或者说DevSecOps-提高了IT的安全性。” - -IT团队比任何以往都要求要快速频繁的交付服务。DevOps在某种程度上可以成为一个很棒的推动者,因为它能够消除开发和运营之间通常遇到的一些摩擦,运营一直被排挤在整个过程之外直到要部署的时候,开发者把代码随便一放之后就不再去管理,他们承担更少的基础架构的责任。那种孤立的方法引起了很多问题,委婉的说,在数字时代,如果将安全孤立起来同样的情况也会发生。 - -“我们已经采用了DevOps因为它已经被证明通过移除开发和运营之间的阻碍来提高IT的绩效,”Reevess说。“就像我们不应该在开发周期要结束时才加入运营,我们不应该在快要结束时才加入安全。” - -### 为什么DevSecOps在此停留 -或许会把DevSecOps看作是另一个时髦词,但对于安全意识很强的IT领导者来说,它是一个实质性的术语:在软件开发管道中安全必须是第一流的公民,而不是部署前的最后一步的螺栓,或者更糟的是,作为一个团队只有当一个实际的事故发生的时候安全人员才会被重用争抢。 - -“DevSecOps不只是一个时髦的术语-因为多种原因它是现在和未来IT将呈现的状态,”来自[Sumo Logic]的安全和合规副总裁George说道,“最重要的好处是将安全融入到开发和运营当中开提供保护的能力” - -此外,DevSecOps的出现可能是DevOps自身逐渐成熟并扎根于IT之中的一个征兆。 - -“企业中的DevOps文化就在这里,而且那意味着开发者们正以不断增长的速度交付功能和更新,特别是自我管理的组织对合作和衡量的结果更加满意时,”来自[CYBRIC] -的首席技术官和联合创始人Mike说道。 - -在实施DevOps的同时继续保留原有安全措施的团队和公司,随着他们继续部署的更快更频繁可能正在经历越来越多的安全管理风险上的痛苦。 - -“现在的手工的安全测试方法会继续远远被甩在后面。” - -“如今,手动的安全测试方法正被甩得越来越远,利用自动化和协作将安全测试转移到软件开发生命周期中,因此推动DevSecOps的文化是IT领导者们增加整体的灵活性提供安全保证的唯一途径,”Kail说。 - -转移安全测试也使开发者受益:而不是在一个新的服务或者更新部署之前在他们的代码中发现一个明显的漏洞,他们能够在开放的较早的阶段验证并解决潜在的问题-经常 -是很少需要或者甚至不需要安全人员的介入。 - -“做的正确,DevSecOps能够将安全融入到开发生命周期中,允许开发者们在没有安全中断的情况下更加快速容易的保证他们应用的安全,”来自[SAS][8]的首席信息安全员Wilson说道。 - -Wilson指出静态(SAST)和源组合工具(SCA),集成到团队的持续交付管道中,作为有用的技术通过给予开发者关于他们的代码中的潜在问题和第三方依赖中的漏洞的反馈 -来使之逐渐成为可能。 - -“因此,开发者们能够主动和迭代的缓解应用安全的问题,然后在不需要安全人员介入的情况下重新进行安全扫描。”Wilson说。他同时指出DevSecOps能够帮助开发者简化更新和打补丁。 - -DevSecOps并不意味着你不再需要安全组的意见了,就如同DevOps并不意味着你不再需要基础架构专家;它只是帮助减少在生产中发现缺陷的可能性,或者减少导致是降低部署的速度的阻碍,因为缺陷已经在开放周期中被发现解决了。 - -“如果他们有问题或者需要帮助,我们就在这儿,但是因为已经给了开发者他们需要的保护他们应用安全的工具,我们很少在一个深入的测试中发现一个导致中断的问题,”Wilson说道。 - -### DevSecOps 遇到危机 - -Sumo Locic's的Gerchow向我们分享了一个在运转中的DevSecOps文化的一个及时的案列:当最近[危机和幽灵]的消息传来的时候,团队的DevSecOps方法使得有了一个快速的响应来减轻风险,没有任何的通知去打扰内部或者外部的顾客,Gerchow所说的这点对原生云高监管的公司来说特别的重要。 - -第一步:Gerchow的小的安全团队,都具有一定的开发能力,能够通过Slack和它的主要云供应商协同工作来确保它的基础架构能够在24小时之内完成修复。 - -“接着我的团队立即开始进行系统级的修复,实现终端客户的零停机时间,不需要去开单给工程师,如果那样那意味着你需要等待很长的变更过程。所有的变更都是通过Slack自动jira票据进行,通过我们的日志监控和分析解决方案,”Gerchow解释道。 - -在本质上,它听起来非常像DevOps的文化,匹配正确的人员,进程和工具,但它明确的包括了安全作为文化中的一部分进行混合。 - -“在传统的环境中,这将花费数周或数月的停机时间来处理,因为开发,运维和安全三者是相互独立的,”Gerchow说道."通过一个DevSecOps的过程和习惯,终端用户可以通过简单的沟通和当日修复获得无缝的体验。" - --------------------------------------------------------------------------------- - -via: https://enterprisersproject.com/article/2018/1/why-devsecops-matters-it-leaders - -作者:[Kevin Casey][a] -译者:[FelixYFZ](https://github.com/FelixYFZ) -校对:[校对者ID](https://github.com/校对者ID) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 - -[a]:https://enterprisersproject.com/user/kevin-casey -[1]:https://enterprisersproject.com/tags/devops -[2]:https://www.datical.com/ -[3]:https://enterprisersproject.com/devops?sc_cid=70160000000h0aXAAQ -[4]:https://www.redhat.com/en?intcmp=701f2000000tjyaAAA -[5]:https://enterprisersproject.com/article/2017/10/what-s-next-devops-5-trends-watch -[6]:https://www.sumologic.com/ -[7]:https://www.cybric.io/ -[8]:https://www.sas.com/en_us/home.html -[9]:https://www.redhat.com/en/blog/what-are-meltdown-and-spectre-heres-what-you-need-know?intcmp=701f2000000tjyaAAA diff --git a/translated/talk/20180117 How to get into DevOps.md b/translated/talk/20180117 How to get into DevOps.md new file mode 100644 index 0000000000..ec169be76f --- /dev/null +++ b/translated/talk/20180117 How to get into DevOps.md @@ -0,0 +1,145 @@ + +DevOps 实践指南 +====== + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/rh_003784_02_os.comcareers_resume_rh1x.png?itok=S3HGxi6E) + +在去年大概一年的时间里,我注意到对“Devops 实践”感兴趣的开发人员和系统管理员突然有了明显的增加。这样的变化也合理:现在开发者只要花很少的钱,调用一些 API, 就能单枪匹马地在一整套分布式基础设施上运行自己的应用, 在这个时代,开发和运维的紧密程度前所未有。我看过许多博客和文章介绍很酷的 DevOps 工具和相关思想,但是给那些希望践行 DevOps 的人以指导和建议的内容,我却很少看到。 + +这篇文章的目的就是描述一下如何去实践。我的想法基于 Reddit 上 [devops][1] 的一些访谈、聊天和深夜讨论,还有一些随机谈话,一般都发生在享受啤酒和美食的时候。如果你已经开始这样实践,我对你的反馈很感兴趣,请通过 [我的博客][2] 或者 [Twitter][3] 联系我,也可以直接在下面评论。我很乐意听到你们的想法和故事。 + +### 古代的 IT + +了解历史是搞清楚未来的关键,DevOps 也不例外。想搞清楚 DevOps 运动的普及和流行,去了解一下上世纪 90 年代后期和 21 世纪前十年 IT 的情况会有帮助。这是我的经验。 + +我的第一份工作是在一家大型跨国金融服务公司做 Windows 系统管理员。当时给计算资源扩容需要给 Dell 打电话 (或者像我们公司那样打给 CDW ),并下一个价值数十万美元的订单,包含服务器、网络设备、电缆和软件,所有这些都要运到在线或离线的数据中心去。虽然 VMware 仍在尝试说服企业使用虚拟机运行他们的“性能敏感”型程序是更划算的,但是包括我们在内的很多公司都还忠于使用他们的物理机运行应用。 + +在我们技术部门,有一个专门做数据中心工程和操作的完整团队,他们的工作包括价格谈判,让荒唐的租赁月费能够下降一点点,还包括保证我们的系统能够正常冷却(如果设备太多,这个事情的难度会呈指数增长)。如果这个团队足够幸运足够有钱,境外数据中心的工作人员对我们所有的服务器型号又都有足够的了解,就能避免在盘后交易中不小心扯错东西。那时候亚马逊 AWS 和 Rackspace 逐渐开始加速扩张,但还远远没到临界规模。 + +当时我们还有专门的团队来保证硬件上运行着的操作系统和软件能够按照预期工作。这些工程师负责设计可靠的架构以方便给系统打补丁,监控和报警,还要定义基础镜像 (gold image) 的内容。这些大都是通过很多手工实验完成的,很多手工实验是为了编写一个运行说明书 (runbook) 来描述要做的事情,并确保按照它执行后的结果确实在预期内。在我们这么大的组织里,这样做很重要,因为一线和二线的技术支持都是境外的,而他们的培训内容只覆盖到了这些运行说明而已。 + +(这是我职业生涯前三年的世界。我那时候的梦想是成为制定金本位制的人!) + +软件发布则完全是另外一头怪兽。无可否认,我在这方面并没有积累太多经验。但是,从我收集的故事(和最近的经历)来看,当时大部分软件开发的日常大概是这样: + + * 开发人员按照技术和功能需求来编写代码,这些需求来自于业务分析人员的会议,但是会议并没有邀请开发人员参加。 + * 开发人员可以选择为他们的代码编写单元测试,以确保在代码里没有任何明显的疯狂行为,比如除以 0 但不抛出异常。 + * 然后开发者会把他们的代码标记为 "Ready for QA."(准备好了接受测试),质量保障的成员会把这个版本的代码发布到他们自己的环境中,这个环境和生产环境可能相似,也可能不相似,甚至和开发环境相比也不一定相似。 + * 故障会在几天或者几个星期内反馈到开发人员那里,这个时长取决于其他业务活动和优先事项。 + + + +虽然系统管理员和开发人员经常有不一致的意见,但是对“变更管理”的痛恨却是一致的。变更管理由高度规范的(就我当时的雇主而言)和非常有必要的规则和程序组成,用来管理一家公司应该什么时候做技术变更,以及如何做。很多公司都按照 [ITIL][4] 来操作, 简单的说,ITIL 问了很多和事情发生的原因、时间、地点和方式相关的问题,而且提供了一个过程,对产生最终答案的决定做审计跟踪。 + +你可能从我的简短历史课上了解到,当时 IT 的很多很多事情都是手工完成的。这导致了很多错误。错误又导致了很多财产损失。变更管理的工作就是尽量减少这些损失,它常常以这样的形式出现:不管变更的影响和规模大小,每两周才能发布部署一次。周五下午 4 点到周一早上 5 点 59 分这段时间,需要排队等候发布窗口。(讽刺的是,这种流程导致了更多错误,通常还是更严重的那种错误) + +### DevOps 不是专家团 + +你可能在想 "Carlos 你在讲啥啊,什么时候才能说到 Ansible playbooks? ",我热爱 Ansible, 但是请再等一会;下面这些很重要。 + +你有没有过被分配到过需要跟"DevOps"小组打交道的项目?你有没有依赖过“配置管理”或者“持续集成/持续交付”小组来保证业务流水线设置正确?你有没有在代码开发完的数周之后才参加发布部署的会议? + +如果有过,那么你就是在重温历史,这个历史是由上面所有这些导致的。 + +出于本能,我们喜欢和像自己的人一起工作,这会导致[筒仓][5]的行成。很自然,这种人类特质也会在工作场所表现出来是不足为奇的。我甚至在一个 250 人的创业公司里见到过这样的现象,当时我在那里工作。刚开始的时候,开发人员都在聚在一起工作,彼此深度协作。随着代码变得复杂,开发相同功能的人自然就坐到了一起,解决他们自己的复杂问题。然后按功能划分的小组很快就正式形成了。 + +在我工作过的很多公司里,系统管理员和开发人员不仅像这样形成了天然的筒仓,而且彼此还有激烈的对抗。开发人员的环境出问题了或者他们的权限太小了,就会对系统管理员很恼火。系统管理员怪开发者无时不刻的不在用各种方式破坏他们的环境,怪开发人员申请的计算资源严重超过他们的需要。双方都不理解对方,更糟糕的是,双方都不愿意去理解对方。 + +大部分开发人员对操作系统,内核或计算机硬件都不感兴趣。同样的,大部分系统管理员,即使是 Linux 的系统管理员,也都不愿意学习编写代码,他们在大学期间学过一些 C 语言,然后就痛恨它,并且永远都不想再碰 IDE. 所以,开发人员把运行环境的问题甩给围墙外的系统管理员,系统管理员把这些问题和甩过来的其他上百个问题放在一起,做一个优先级安排。每个人都很忙,心怀怨恨的等待着。DevOps 的目的就是解决这种矛盾。 + +DevOps 不是一个团队,CI/CD 也不是 Jira 系统的一个用户组。DevOps 是一种思考方式。根据这个运动来看,在理想的世界里,开发人员、系统管理员和业务相关人将作为一个团队工作。虽然他们可能不完全了解彼此的世界,可能没有足够的知识去了解彼此的积压任务,但他们在大多数情况下能有一致的看法。 + +把所有基础设施和业务逻辑都代码化,再串到一个发布部署流水线里,就像是运行在这之上的应用一样。这个理念的基础就是 DevOps. 因为大家都理解彼此,所以人人都是赢家。聊天机器人和易用的监控工具、可视化工具的兴起,背后的基础也是 DevOps. + +[Adam Jacob][6] 说的最好:"DevOps 就是企业往软件导向型过渡时我们用来描述操作的词" + +### 要实践 DevOps 我需要知道些什么 + +我经常被问到这个问题,它的答案,和同属于开放式的其他大部分问题一样:视情况而定。 + +现在“DevOps 工程师”在不同的公司有不同的含义。在软件开发人员比较多但是很少有人懂基础设施的小公司,他们很可能是在找有更多系统管理经验的人。而其他公司,通常是大公司或老公司或又大又老的公司,已经有一个稳固的系统管理团队了,他们在向类似于谷歌 [SRE][7] 的方向做优化,也就是“设计操作功能的软件工程师”。但是,这并不是金科玉律,就像其他技术类工作一样,这个决定很大程度上取决于他的招聘经理。 + +也就是说,我们一般是在找对深入学习以下内容感兴趣的工程师: + + * 如何管理和设计安全、可扩展的云上的平台(通常是在 AWS 上,不过微软的 Azure, 谷歌的 Cloud Platform,还有 DigitalOcean 和 Heroku 这样的 PaaS 提供商,也都很流行) + * 如何用流行的 [CI/CD][8] 工具,比如 Jenkins,Gocd,还有基于云的 Travis CI 或者 CircleCI,来构造一条优化的发布部署流水线,和发布部署策略。 + * 如何在你的系统中使用基于时间序列的工具,比如 Kibana,Grafana,Splunk,Loggly 或者 Logstash,来监控,记录,并在变化的时候报警,还有 + * 如何使用配置管理工具,例如 Chef,Puppet 或者 Ansible 做到“基础设施即代码”,以及如何使用像 Terraform 或 CloudFormation 的工具发布这些基础设施。 + + + +容器也变得越来越受欢迎。尽管有人对大规模使用 Docker 的现状[表示不满][9],但容器正迅速地成为一种很好的方式来实现在更少的操作系统上运行超高密度的服务和应用,同时提高它们的可靠性。(像 Kubernetes 或者 Mesos 这样的容器编排工具,能在宿主机故障的时候,几秒钟之内重新启动新的容器。)考虑到这些,掌握 Docker 或者 rkt 以及容器编排平台的知识会对你大有帮助。 + +如果你是希望做 DevOps 实践的系统管理员,你还需要知道如何写代码。Python 和 Ruby 是 DevOps 领域的流行语言,因为他们是可移植的(也就是说可以在任何操作系统上运行),快速的,而且易读易学。它们还支撑着这个行业最流行的配置管理工具(Ansible 是使用 Python 写的,Chef 和 Puppet 是使用 Ruby 写的)以及云平台的 API 客户端(亚马逊 AWS, 微软 Azure, 谷歌 Cloud Platform 的客户端通常会提供 Python 和 Ruby 语言的版本)。 + +如果你是开发人员,也希望做 DevOps 的实践,我强烈建议你去学习 Unix,Windows 操作系统以及网络基础知识。虽然云计算把很多系统管理的难题抽象化了,但是对慢应用的性能做 debug 的时候,你知道操作系统如何工作的就会有很大的帮助。下文包含了一些这个主题的图书。 + +如果你觉得这些东西听起来内容太多,大家都是这么想的。幸运的是,有很多小项目可以让你开始探索。其中一个启动项目是 Gary Stafford 的[选举服务](https://github.com/garystafford/voter-service), 一个基于 Java 的简单投票平台。我们要求面试候选人通过一个流水线将该服务从 GitHub 部署到生产环境基础设施上。你可以把这个服务与 Rob Mile 写的了不起的 DevOps [入门教程](https://github.com/maxamg/cd-office-hours)结合起来,学习如何编写流水线。 + +还有一个熟悉这些工具的好方法,找一个流行的服务,然后只使用 AWS 和配置管理工具来搭建这个服务所需要的基础设施。第一次先手动搭建,了解清楚要做的事情,然后只用 CloudFormation (或者 Terraform) 和 Ansible 重写刚才的手动操作。令人惊讶的是,这就是我们基础设施开发人员为客户所做的大部分日常工作,我们的客户认为这样的工作非常有意义! + +### 需要读的书 + +如果你在找 DevOps 的其他资源,下面这些理论和技术书籍值得一读。 + +#### 理论书籍 + + * Gene Kim 写的 [The Phoenix Project (凤凰项目)][10]。这是一本很不错的书,内容涵盖了我上文解释过的历史(写的更生动形象),描述了一个运行在敏捷和 DevOps 之上的公司向精益前进的过程。 + * Terrance Ryan 写的 [Driving Technical Change (布道之道)][11]。非常好的一小本书,讲了大多数技术型组织内的常见性格特点以及如何和他们打交道。这本书对我的帮助比我想象的更多。 + * Tom DeMarco 和 Tim Lister 合著的 [Peopleware (人件)][12]。管理工程师团队的经典图书,有一点过时,但仍然很有价值。 + * Tom Limoncelli 写的 [Time Management for System Administrators (时间管理: 给系统管理员)][13]。这本书主要面向系统管理员,它对很多大型组织内的系统管理员生活做了深入的展示。如果你想了解更多系统管理员和开发人员之间的冲突,这本书可能解释了更多。 + * Eric Ries 写的 [The Lean Startup (精益创业)][14]。描述了 Eric 自己的 3D 虚拟形象公司,IMVU, 发现了如何精益工作,快速失败和更快盈利。 + * Jez Humble 和他的朋友写的[Lean Enterprise (精益企业)][15]。这本书是对精益创业做的改编,以更适应企业,两本书都很棒,都很好的解释了 DevOps 背后的商业动机。 + * Kief Morris 写的 [Infrastructure As Code (基础设施即代码)][16]。关于 "基础设施即代码" 的非常好的入门读物!很好的解释了为什么所有公司都有必要采纳这种做法。 + * Betsy Beyer, Chris Jones, Jennifer Petoff 和 Niall Richard Murphy 合著的 [Site Reliability Engineering (站点可靠性工程师)][17]。一本解释谷歌 SRE 实践的书,也因为是 "DevOps 诞生之前的 DevOps" 被人熟知。在如何处理运行时间、时延和保持工程师快乐方面提供了有趣的看法。 + + + +#### 技术书籍 + +如果你想找的是让你直接跟代码打交道的书,看这里就对了。 + + * W. Richard Stevens 的 [TCP/IP Illustrated (TCP/IP 详解)][18]。这是一套经典的(也可以说是最全面的)讲解基本网络协议的巨著,重点介绍了 TCP/IP 协议族。如果你听说过 1,2, 3,4 层网络,而且对深入学习他们感兴趣,那么你需要这本书。 + * Evi Nemeth, Trent Hein 和 Ben Whaley 合著的 [UNIX and Linux System Administration Handbook (UNIX/Linux 系统管理员手册)][19]。一本很好的入门书,介绍 Linux/Unix 如何工作以及如何使用。 + * Don Jones 和 Jeffrey Hicks 合著的 [Learn Windows Powershell In A Month of Lunches (Windows PowerShell实战指南)][20]. 如果你在 Windows 系统下做自动化任务,你需要学习怎么使用 Powershell。这本书能够帮助你。Don Jones 是这方面著名的 MVP。 + * 几乎所有 [James Turnbull][21] 写的东西,针对流行的 DevOps 工具,他发表了很好的技术入门读物。 + + + +不管是在那些把所有应用都直接部署在物理机上的公司,(现在很多公司仍然有充分的理由这样做)还是在那些把所有应用都做成 serverless 的先驱公司,DevOps 都很可能会持续下去。这部分工作很有趣,产出也很有影响力,而且最重要的是,它搭起桥梁衔接了技术和业务之间的缺口。DevOps 是一个值得期待的美好事物。 + +首次发表在 [Neurons Firing on a Keyboard][22]。使用 CC-BY-SA 协议。 + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/1/getting-devops + +作者:[Carlos Nunez][a] +译者:[belitex](https://github.com/belitex) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://opensource.com/users/carlosonunez +[1]:https://www.reddit.com/r/devops/ +[2]:https://carlosonunez.wordpress.com/ +[3]:https://twitter.com/easiestnameever +[4]:https://en.wikipedia.org/wiki/ITIL +[5]:https://www.psychologytoday.com/blog/time-out/201401/getting-out-your-silo +[6]:https://twitter.com/adamhjk/status/572832185461428224 +[7]:https://landing.google.com/sre/interview/ben-treynor.html +[8]:https://en.wikipedia.org/wiki/CI/CD +[9]:https://thehftguy.com/2016/11/01/docker-in-production-an-history-of-failure/ +[10]:https://itrevolution.com/book/the-phoenix-project/ +[11]:https://pragprog.com/book/trevan/driving-technical-change +[12]:https://en.wikipedia.org/wiki/Peopleware:_Productive_Projects_and_Teams +[13]:http://shop.oreilly.com/product/9780596007836.do +[14]:http://theleanstartup.com/ +[15]:https://info.thoughtworks.com/lean-enterprise-book.html +[16]:http://infrastructure-as-code.com/book/ +[17]:https://landing.google.com/sre/book.html +[18]:https://en.wikipedia.org/wiki/TCP/IP_Illustrated +[19]:http://www.admin.com/ +[20]:https://www.manning.com/books/learn-windows-powershell-in-a-month-of-lunches-third-edition +[21]:https://jamesturnbull.net/ +[22]:https://carlosonunez.wordpress.com/2017/03/02/getting-into-devops/ diff --git a/translated/talk/20180128 Being open about data privacy.md b/translated/talk/20180128 Being open about data privacy.md deleted file mode 100644 index 9d7e4bd87b..0000000000 --- a/translated/talk/20180128 Being open about data privacy.md +++ /dev/null @@ -1,95 +0,0 @@ -对数据隐私持开放的态度 -====== -![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/GOV_opendata.png?itok=M8L2HGVx) - - -Image by : opensource.com - -今天是[数据隐私日][1],(在欧洲叫"数据保护日"),你可能会认为现在我们处于一个开源的世界中,所有的数据都应该免费,[就像人们想的那样][2],但是现实并没那么简单。主要有两个原因: -1. 我们中的大多数(不仅仅是在开源中)认为至少有些关于我们自己的数据是不愿意分享出去的(我在之前发表的一篇文章中列举了一些列子[3]) -2. 我们很多人虽然在开源中工作,但事实上是为了一些商业公司或者其他一些组织工作,也是在合法的要求范围内分享数据。 - -所以实际上,数据隐私对于每个人来说是很重要的。 - -事实证明,在美国和欧洲之间,人们和政府认为让组织使用的数据的起点是有些不同的。前者通常为实体提供更多的自由度,更愤世嫉俗的是--大型的商业体利用他们收集到的关于我们的数据。在欧洲,完全是另一观念,一直以来持有的多是有更多约束限制的观念,而且在5月25日,欧洲的观点可以说取得了胜利。 - -## 通用数据保护条例的影响 - -那是一个相当全面的声明,其实事实上就是欧盟在2016年通过的一项关于通用数据保护的立法,使它变得可实施。数据通用保护条例在私人数据怎样才能被保存,如何才能被使用,谁能使用,能被持有多长时间这些方面设置了严格的规则。它描述了什么数据属于私人数据--而且涉及的条目范围非常广泛,从你的姓名家庭住址到你的医疗记录以及接通你电脑的IP地址。 - -通用数据保护条例的重要之处是他并不仅仅适用于欧洲的公司,如果你是阿根廷人,日本人,美国人或者是俄罗斯的公司而且你正在收集涉及到欧盟居民的数据,你就要受到这个条例的约束管辖。 - -“哼!” 你可能会这样说,“我的业务不在欧洲:他们能对我有啥约束?” 答案很简答:如果你想继续在欧盟做任何生意,你最好遵守,因为一旦你违反了通用数据保护条例的规则,你将会受到你全球总收入百分之四的惩罚。是的,你没听错,是全球总收入不是仅仅在欧盟某一国家的的收入,也不只是净利润,而是全球总收入。这将会让你去叮嘱告知你的法律团队,他们就会知会你的整个团队,同时也会立即去指引你的IT团队,确保你的行为相当短的时间内是符合要求的。 - -看上去这和欧盟之外的城市没有什么相关性,但其实不然,对大多数公司来说,对所有的他们的顾客、合作伙伴以及员工实行同样的数据保护措施是件既简单又有效的事情,而不是只是在欧盟的城市实施,这将会是一件很有利的事情。2 - -然而,数据通用保护条例不久将在全球实施并不意味着一切都会变的很美好:事实并非如此,我们一直在丢弃关于我们自己的信息--而且允许公司去使用它。 - -有一句话是这么说的(尽管很争议):“如果你没有在付费,那么你就是产品。”这句话的意思就是如果你没有为某一项服务付费,那么其他的人就在付费使用你的数据。 -你有付费使用Facebook、推特?谷歌邮箱?你觉得他们是如何赚钱的?大部分是通过广告,一些人会争论那是他们向你提供的一项服务而已,但事实上是他们在利用你的数据从广告商里获取收益。你不是一个真正的广告的顾客-只有当你从看了广告后买了他们的商品之后你才变成了他们的顾客,但直到这个发生之前,都是广告平台和广告商的关系。 - -有些服务是允许你通过付费来消除广告的(流媒体音乐平台声破天就是这样的),但从另一方面来讲,即使你认为付费的服务也可以启用广告(列如,亚马逊正在允许通过Alexa广告)除非我们想要开始为这些所有的免费服务付费,我们需要清除我们所放弃的,而且在我们想要揭发和不想的里面做一些选择。 - -### 谁是顾客? - -关于数据的另一个问题一直在困扰着我们,它是产生的数据量的直接结果。有许多组织一直在产生巨量的数据,包括公共的组织比如大学、医院或者是政府部门4-- -而且他们没有能力去储存这些数据。如果这些数据没有长久的价值也就没什么要紧的,但事实正好相反,随着处理大数据的工具正在开发中,而且这些组织也认识到他们现在以及在不久的将来将能够去开采这些数据。 - -然而他们面临的是,随着数据的增长和存储量的不足他们是如何处理的。幸运--而且我是带有讽刺意味的使用了这个词,5大公司正在介入去帮助他们。“把你们的数据给我们,”他们说,“我们将免费保存。我们甚至让你随时能够使用你所收集到的数据!”这听起来很棒,是吗?这是大公司的一个极具代表性的列子,站在慈善的立场上帮助公共组织管理他们收集到的关于我们的数据。 - -不幸的是,慈善不是唯一的理由。他们是附有条件的:作为同意保存数据的交换条件,这些公司得到了将数据访问权限出售非第三方的权利。你认为公共组织,或者是被收集数据的人在数据被出售使用权使给第三方在他们如何使用上面能有发言权吗?我将把这个问题当做一个练习留给读者去思考。7 - -### 开放和积极 - -然而并不只有坏消息。政府中有一项在逐渐发展起来的“开放数据”运动鼓励部门能够将免费开放他们的数据给公众或者其他组织。这项行动目前正在被实施立法。许多 -支援组织--尤其是那些收到公共基金的--正在开始推动同样的活动。即使商业组织也有些许的兴趣。而且,在技术上已经可行了,例如围绕不同的隐私和多方计算上,正在允许我们根据数据设置和不揭露太多关于个人的前提下开采数据--一个历史性的计算问题比你想象的要容易处理的多。 - -这些对我们来说意味着什么呢?我之前在网站Opensource.com上写过关于[开源的共享福利][4],而且我越来越相信我们需要把我们的视野从软件拓展到其他区域:硬件,组织,和这次讨论有关的,数据。让我们假设一下你是A公司要提向另一家公司提供一项服务,客户B。在游戏中有四种不同类型的数据: - 1. 数据完全开放:对A和B都是可得到的,世界上任何人都可以得到 - 2. 数据是已知的,共享的,和机密的:A和B可得到,但其他人不能得到。 - 3. 数据是公司级别上保密的:A公司可以得到,但B顾客不能 - 4. 数据是顾客级别保密的:B顾客可以得到,但A公司不能 - -首先,也许我们对数据应该更开放些,将数据默认放到选项一中。如果那些数据对所有人开放--在无人驾驶、语音识别,矿藏以及人口数据统计会有相当大的作用的,9 -如果我们能够找到方法将数据放到选项2,3和4中,不是很好嘛--或者至少它们中的一些--在选项一中是可以实现的,同时仍将细节保密?这就是研究这些新技术的希望。 -然而又很长的路要走,所以不要太兴奋,同时,开始考虑将你的的一些数据默认开放。 - -### 一些具体的措施 - -我们如何处理数据的隐私和开放?下面是我想到的一些具体的措施:欢迎大家评论做出更多的贡献。 - * 检查你的组织是否正在认真严格的执行通用数据保护条例。如果没有,去推动实施它。 - * 要默认去加密敏感数据(或者适当的时候用散列算法),当不再需要的时候及时删掉--除非数据正在被处理使用否则没有任何借口让数据清晰可见。 - * 当你注册一个服务的时候考虑一下你公开了什么信息,特别是社交媒体类的。 - * 和你的非技术朋友讨论这个话题。 - * 教育你的孩子,你朋友的孩子以及他们的朋友。然而最好是去他们的学校和他们的老师交谈在他们的学校中展示。 - * 鼓励你工作志愿服务的组织,或者和他们互动推动数据的默认开放。不是去思考为什么我要使数据开放而是以我为什么不让数据开放开始。 - * 尝试去访问一些开源数据。开采使用它。开发应用来使用它,进行数据分析,画漂亮的图,10 制作有趣的音乐,考虑使用它来做些事。告诉组织去使用它们,感谢它们,而且鼓励他们去做更多。 - - - -1. 我承认你可能尽管不会 -2. 假设你坚信你的个人数据应该被保护。 -3. 如果你在思考“极好的”的寓意,在这点上你并不孤独。 -4. 事实上这些机构能够有多开放取决于你所居住的地方。 -5. 假设我是英国人,那是非常非常大的剂量。 -6. 他们可能是巨大的公司:没有其他人能够负担得起这么大的存储和基础架构来使数据保持可用。 -7. 不,答案是“不”。 -8. 尽管这个列子也同样适用于个人。看看:A可能是Alice,B 可能是BOb... -9. 并不是说我们应该暴露个人的数据或者是这样的数据应该被保密,当然--不是那类的数据。 -10. 我的一个朋友当她接孩子放学的时候总是下雨,所以为了避免确认失误,她在整个学年都访问天气信息并制作了图表分享到社交媒体上。 --------------------------------------------------------------------------------- - -via: https://opensource.com/article/18/1/being-open-about-data-privacy - -作者:[Mike Bursell][a] -译者:[译者ID](https://github.com/译者ID) -校对:[校对者FelixYFZ](https://github.com/FelixYFZ) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 - -[a]:https://opensource.com/users/mikecamel -[1]:https://en.wikipedia.org/wiki/Data_Privacy_Day -[2]:https://en.wikipedia.org/wiki/Information_wants_to_be_free -[3]:https://aliceevebob.wordpress.com/2017/06/06/helping-our-governments-differently/ -[4]:https://opensource.com/article/17/11/commonwealth-open-source -[5]:http://www.outpost9.com/reference/jargon/jargon_40.html#TAG2036 diff --git a/translated/talk/20180305 What-s next in IT automation- 6 trends to watch.md b/translated/talk/20180305 What-s next in IT automation- 6 trends to watch.md deleted file mode 100644 index f5e93d0a0c..0000000000 --- a/translated/talk/20180305 What-s next in IT automation- 6 trends to watch.md +++ /dev/null @@ -1,130 +0,0 @@ -IT自动化的下一步是什么: 6 大趋势 -====== - -![](https://enterprisersproject.com/sites/default/files/styles/620x350/public/cio_ai_artificial_intelligence.png?itok=o0csm9l2) - -我们最近介绍了 [促进自动化的因素][1] ,目前正在被人们采用的 [趋势][2], 以及那些刚开始使用自动化部分流程组织 [有用的技巧][3] 。 - -噢, 我们也分享了在你的公司[如何使用自动化的案例][4] , 以及 [长期成功的关键][5]. - -现在, 只有一个问题: 自动化的下一步是什么? 我们邀请一系列专家分享一下 [自动化][6]不远的将来。 以下是他们建议IT领域领导需密切关注的六大趋势。 - -### 1. 机器学习的成熟 - -对于关于 [机器学习][7]的讨论 (与“自我学习系统”相似的定义),对于绝大多数组织的项目来说,实际执行起来它仍然为时过早。但预计这将发生变化,机器学习将在下一次IT自动化浪潮中将扮演着至关重要的角色。 - -[Advanced Systems Concepts, Inc.][8]公司工程总监 Mehul Amin 指出机器学习是IT自动化下一个关键增长领域之一。 - -“随着数据化的发展, 自动化软件理应可以自我决策,否则这就是开发人员的责任了”, Amin 说。 “例如, 开发者需要执行构建内容, 但是识别系统最佳执行流程的,可能是由系统内软件分析完成。” - -假设将这个系统延伸到其他地方中。Amin 指出,机器学习可以使自动化系统在必要的时候提供额外的资源,以需要满足时间线或SLA,同样在不需要资源的时候退出以及其他的可能性。 - -显然不只有 Amin 一个人这样认为。 - -[Sungard Availability Services][9] 公司首席架构师 Kiran Chitturi 表示,“IT自动化正在走向自我学习的方向” 。“系统将会能测试和监控自己,加强业务流程和软件交付能力。” - -Chitturi 指出自动化测试就是个例子。脚本测试已经被广泛采用,但很快这些自动化测试流程将会更容易学习,更快发展,例如开发出新的代码或将更为广泛地影响生产环境。 - -### 2. 人工智能催生的自动化 - -上述原则同样适合 [人工智能][10](但是为独立)的领域。假定新兴的人工智能技术将也会产生新的自动化机会。根据对人工智能的定义,机器学习在短时间内可能会对IT领域产生巨大的影响(并且我们可能会看到这两个领域的许多重叠的定义和理解)。 - -[SolarWinds][11]公司技术负责人 Patrick Hubbard说,“人工智能(AI)和机器学习的整合普遍被认为对未来几年的商业成功起至关重要的作用。” - -### 3. 这并不意味着不再需要人力 - -让我们试着安慰一下那些不知所措的人:前两种趋势并不一定意味着我们将失去工作。 - -这很可能意味着各种角色的改变以及[全新角色][12]的创造。 - -但是在可预见的将来,至少,你不必需要机器人鞠躬。 - -“一台机器只能运行在给定的环境变量中它不能选择包含新的变量,在今天只有人类可以这样做,” Hubbard 解释说。“但是,对于IT专业人员来说,这将是需要培养AI和自动化技能的时代。如对程序设计、编程、管理人工智能和机器学习功能算法的基本理解,以及用强大的安全状态面对更复杂的网络攻击。” - -Hubbard 分享一些新的工具或功能例子,例如支持人工智能的安全软件或机器学习的应用程序,这些应用程序可以远程发现石油管道中的维护需求。两者都可以提高效益和效果,自然不会代替需要信息安全或管道维护的人员。 - -“许多新功能仍需要人工监控,”Hubbard 说。“例如,为了让机器确定一些‘预测’是否可能成为‘规律’,人为的管理是必要的。” - -即使你把机器学习和AI先放在一边,看待一般地IT自动化,同样原理也是成立的,尤其是在软件开发生命周期中。 - -[Juniper Networks][13]公司自动化首席架构师 Matthew Oswalt ,指出IT自动化增长的根本原因是它通过减少操作基础设施所需的人工工作量来创造直接价值。 - -在代码上,操作工程师可以使用事件驱动的自动化提前定义他们的工作流程,而不是在凌晨3点来应对基础设施的问题。 - -“它也将操作工作流程作为代码而不再是容易过时的文档或系统知识阶段,”Oswalt解释说。“操作人员仍然需要在[自动化]工具响应事件方面后发挥积极作用。采用自动化的下一个阶段是建立一个能够跨IT频谱识别发生的有趣事件的系统,并以自主方式进行响应。在代码上,操作工程师可以使用事件驱动的自动化提前定义他们的工作流程,而不是在凌晨3点来应对基础设施的问题。他们可以依靠这个系统在任何时候以同样的方式作出回应。” - -### 4. 对自动化的焦虑将会减少 - -SolarWinds公司的 Hubbard 指出,“自动化”一词本身就产生大量的不确定性和担忧,不仅仅是在IT领域,而且是跨专业领域,他说这种担忧是合理的。但一些随之而来的担忧可能被夸大了,甚至是科技产业本身。现实可能实际上是这方面的镇静力:当自动化的实际实施和实践帮助人们认识到这个列表中的“3”时,我们将看到“4”的出现。 - -“今年我们可能会看到对自动化焦虑的减少,更多的组织开始接受人工智能和机器学习作为增加现有人力资源的一种方式,”Hubbard说。“自动化历史上的今天为更多的工作创造了空间,通过降低成本和时间来完成较小任务,并将劳动力重新集中到无法自动化并需要人力的事情上。人工智能和机器学习也是如此。” - -自动化还将减少IT领导者神经紧张主题的一些焦虑:安全。正如[红帽][14]公司首席架构师 Matt Smith 最近[指出][15]的那样,自动化将越来越多地帮助IT部门降低与维护任务相关的安全风险。 - -他的建议是:“首先在维护活动期间记录和自动化IT资产之间的交互。通过依靠自动化,您不仅可以消除历史上需要大量手动操作和手术技巧的任务,还可以降低人为错误的风险,并展示当您的IT组织采纳变更和新工作方法时可能发生的情况。最终,这将迅速减少对应用安全补丁的抵制。而且它还可以帮助您的企业在下一次重大安全事件中摆脱头条新闻。” - -**[ 阅读全文: [12个企业安全坏习惯要打破。][16] ] ** - -### 5. 脚本和自动化工具将持续发展 - -看到许多组织增加自动化的第一步 - 通常以脚本或自动化工具(有时称为配置管理工具)的形式 - 作为“早期”工作。 - -但是随着各种自动化技术的使用,对这些工具的观点也在不断发展。 - -[DataVision][18]首席运营官 Mark Abolafia 表示:“数据中心环境中存在很多重复性过程,容易出现人为错误,[Ansible][17]等技术有助于缓解这些问题。“通过 Ansible ,人们可以为一组操作编写特定的步骤,并输入不同的变量,例如地址等,使过去长时间的过程链实现自动化,而这些过程以前都需要人为触摸和更长的交货时间。” - -**[想了解更多关于Ansible这个方面的知识吗?阅读相关文章:[使用Ansible时的成功秘诀][19]。 ]** - -另一个因素是:工具本身将继续变得更先进。 - -“使用先进的IT自动化工具,开发人员将能够在更短的时间内构建和自动化工作流程,减少易出错的编码,” ASCI 公司的 Amin 说。“这些工具包括预先构建的,预先测试过的拖放式集成,API作业,丰富的变量使用,参考功能和对象修订历史记录。” - -### 6. 自动化开创了新的指标机会 - -正如我们在此前所说的那样,IT自动化不是万能的。它不会修复被破坏的流程,或者以其他方式为您的组织提供全面的灵丹妙药。这也是持续不断的:自动化并不排除衡量性能的必要性。 - -**[ 参见我们的相关文章 [DevOps指标:你在衡量什么重要吗?][20] ]** - -实际上,自动化应该打开新的机会。 - -[Janeiro Digital][21]公司架构师总裁 Josh Collins 说,“随着越来越多的开发活动 - 源代码管理,DevOps管道,工作项目跟踪 - 转向API驱动的平台 - 将这些原始数据拼接在一起以描绘组织效率提升的机会和图景”。 - -Collins 认为这是一种可能的新型“开发组织度量指标”。但不要误认为这意味着机器和算法可以突然预测IT所做的一切。 - -“无论是衡量个人资源还是整体团队,这些指标都可以很强大 - 但应该用大量的背景来衡量。”Collins说,“将这些数据用于高层次趋势并确认定性观察 - 而不是临床评级你的团队。” - -**想要更多这样知识, IT领导者?[注册我们的每周电子邮件通讯][22]。** - --------------------------------------------------------------------------------- - -via: https://enterprisersproject.com/article/2018/3/what-s-next-it-automation-6-trends-watch - -作者:[Kevin Casey][a] -译者:[MZqk](https://github.com/MZqk) -校对:[校对者ID](https://github.com/校对者ID) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 - -[a]:https://enterprisersproject.com/user/kevin-casey -[1]:https://enterprisersproject.com/article/2017/12/5-factors-fueling-automation-it-now -[2]:https://enterprisersproject.com/article/2017/12/4-trends-watch-it-automation-expands -[3]:https://enterprisersproject.com/article/2018/1/getting-started-automation-6-tips -[4]:https://enterprisersproject.com/article/2018/1/how-make-case-it-automation -[5]:https://enterprisersproject.com/article/2018/1/it-automation-best-practices-7-keys-long-term-success -[6]:https://enterprisersproject.com/tags/automation -[7]:https://enterprisersproject.com/article/2018/2/how-spot-machine-learning-opportunity -[8]:https://www.advsyscon.com/en-us/ -[9]:https://www.sungardas.com/en/ -[10]:https://enterprisersproject.com/tags/artificial-intelligence -[11]:https://www.solarwinds.com/ -[12]:https://enterprisersproject.com/article/2017/12/8-emerging-ai-jobs-it-pros -[13]:https://www.juniper.net/ -[14]:https://www.redhat.com/en?intcmp=701f2000000tjyaAAA -[15]:https://enterprisersproject.com/article/2018/2/12-bad-enterprise-security-habits-break -[16]:https://enterprisersproject.com/article/2018/2/12-bad-enterprise-security-habits-break?sc_cid=70160000000h0aXAAQ -[17]:https://opensource.com/tags/ansible -[18]:https://datavision.com/ -[19]:https://opensource.com/article/18/2/tips-success-when-getting-started-ansible?intcmp=701f2000000tjyaAAA -[20]:https://enterprisersproject.com/article/2017/7/devops-metrics-are-you-measuring-what-matters?sc_cid=70160000000h0aXAAQ -[21]:https://www.janeirodigital.com/ -[22]:https://enterprisersproject.com/email-newsletter?intcmp=701f2000000tsjPAAQ diff --git a/translated/tech/20140114 Caffeinated 6.828:Lab 2 Memory Management.md b/translated/tech/20140114 Caffeinated 6.828:Lab 2 Memory Management.md new file mode 100644 index 0000000000..0e2a348679 --- /dev/null +++ b/translated/tech/20140114 Caffeinated 6.828:Lab 2 Memory Management.md @@ -0,0 +1,232 @@ +# Caffeinated 6.828:实验 2:内存管理 + +### 简介 + +在本实验中,你将为你的操作系统写内存管理方面的代码。内存管理有两部分组成。 + +第一部分是内核的物理内存分配器,内核通过它来分配内存,以及在不需要时释放所分配的内存。分配器以页为单位分配内存,每个页的大小为 4096 字节。你的任务是去维护那个数据结构,它负责记录物理页的分配和释放,以及每个分配的页有多少进程共享它。本实验中你将要写出分配和释放内存页的全套代码。 + +第二个部分是虚拟内存的管理,它负责由内核和用户软件使用的虚拟内存地址到物理内存地址之间的映射。当使用内存时,x86 架构的硬件是由内存管理单元(MMU)负责执行映射操作来查阅一组页表。接下来你将要修改 JOS,以根据我们提供的特定指令去设置 MMU 的页表。 + +### 预备知识 + +在本实验及后面的实验中,你将逐步构建你的内核。我们将会为你提供一些附加的资源。使用 Git 去获取这些资源、提交自实验 1 以来的改变(如有需要的话)、获取课程仓库的最新版本、以及在我们的实验 2 (origin/lab2)的基础上创建一个称为 lab2 的本地分支: + +``` +athena% cd ~/6.828/lab +athena% add git +athena% git pull +Already up-to-date. +athena% git checkout -b lab2 origin/lab2 +Branch lab2 set up to track remote branch refs/remotes/origin/lab2. +Switched to a new branch "lab2" +athena% +``` + +现在,你需要将你在 lab1 分支中的改变合并到 lab2 分支中,命令如下: + +``` +athena% git merge lab1 +Merge made by recursive. + kern/kdebug.c | 11 +++++++++-- + kern/monitor.c | 19 +++++++++++++++++++ + lib/printfmt.c | 7 +++---- + 3 files changed, 31 insertions(+), 6 deletions(-) +athena% +``` + +实验 2 包含如下的新源代码,后面你将遍历它们: + +- inc/memlayout.h +- kern/pmap.c +- kern/pmap.h +- kern/kclock.h +- kern/kclock.c + +`memlayout.h` 描述虚拟地址空间的布局,这个虚拟地址空间是通过修改 `pmap.c`、`memlayout.h` 和 `pmap.h` 所定义的 *PageInfo* 数据结构来实现的,这个数据结构用于跟踪物理内存页面是否被释放。`kclock.c` 和 `kclock.h` 维护 PC 基于电池的时钟和 CMOS RAM 硬件,在 BIOS 中记录了 PC 上安装的物理内存数量,以及其它的一些信息。在 `pmap.c` 中的代码需要去读取这个设备硬件信息,以算出在这个设备上安装了多少物理内存,这些只是由你来完成的一部分代码:你不需要知道 CMOS 硬件工作原理的细节。 + +特别需要注意的是 `memlayout.h` 和 `pmap.h`,因为本实验需要你去使用和理解的大部分内容都包含在这两个文件中。你或许还需要去复习 `inc/mmu.h` 这个文件,因为它也包含了本实验中用到的许多定义。 + +开始本实验之前,记得去添加 `exokernel` 以获取 QEMU 的 6.828 版本。 + +### 实验过程 + +在你准备进行实验和写代码之前,先添加你的 `answers-lab2.txt` 文件到 Git 仓库,提交你的改变然后去运行 `make handin`。 + +``` +athena% git add answers-lab2.txt +athena% git commit -am "my answer to lab2" +[lab2 a823de9] my answer to lab2 4 files changed, 87 insertions(+), 10 deletions(-) +athena% make handin +``` + +### 第 1 部分:物理页面管理 + +操作系统必须跟踪物理内存页是否使用的状态。JOS 以页为最小粒度来管理 PC 的物理内存,以便于它使用 MMU 去映射和保护每个已分配的内存片段。 + +现在,你将要写内存的物理页分配器的代码。它使用链接到 `PageInfo` 数据结构的一组列表来保持对物理页的状态跟踪,每个列表都对应到一个物理内存页。在你能够写出剩下的虚拟内存实现之前,你需要先写出物理内存页面分配器,因为你的页表管理代码将需要去分配物理内存来存储页表。 + +> 练习 1 +> +> 在文件 `kern/pmap.c` 中,你需要去实现以下函数的代码(或许要按给定的顺序来实现)。 +> +> boot_alloc() +> +> mem_init()(只要能够调用 check_page_free_list() 即可) +> +> page_init() +> +> page_alloc() +> +> page_free() +> +> `check_page_free_list()` 和 `check_page_alloc()` 可以测试你的物理内存页分配器。你将需要引导 JOS 然后去看一下 `check_page_alloc()` 是否报告成功即可。如果没有报告成功,修复你的代码直到成功为止。你可以添加你自己的 `assert()` 以帮助你去验证是否符合你的预期。 + +本实验以及所有的 6.828 实验中,将要求你做一些检测工作,以便于你搞清楚它们是否按你的预期来工作。这个任务不需要详细描述你添加到 JOS 中的代码的细节。查找 JOS 源代码中你需要去修改的那部分的注释;这些注释中经常包含有技术规范和提示信息。你也可能需要去查阅 JOS、和 Intel 的技术手册、以及你的 6.004 或 6.033 课程笔记的相关部分。 + +### 第 2 部分:虚拟内存 + +在你开始动手之前,需要先熟悉 x86 内存管理架构的保护模式:即分段和页面转换。 + +> 练习 2 +> +> 如果你对 x86 的保护模式还不熟悉,可以查看 Intel 80386 参考手册的第 5 章和第 6 章。阅读这些章节(5.2 和 6.4)中关于页面转换和基于页面的保护。我们建议你也去了解关于段的章节;在虚拟内存和保护模式中,JOS 使用了分页、段转换、以及在 x86 上不能禁用的基于段的保护,因此你需要去理解这些基础知识。 + +### 虚拟地址、线性地址和物理地址 + +在 x86 的专用术语中,一个虚拟地址是由一个段选择器和在段中的偏移量组成。一个线性地址是在页面转换之前、段转换之后得到的一个地址。一个物理地址是段和页面转换之后得到的最终地址,它最终将进入你的物理内存中的硬件总线。 + +![屏幕快照 2018-09-04 11.22.20](https://ws1.sinaimg.cn/large/0069RVTdly1fuxgrc398jj30gx04bgm1.jpg) + +回顾实验 1 中的第 3 部分,我们安装了一个简单的页表,这样内核就可以在 0xf0100000 链接的地址上运行,尽管它实际上是加载在 0x00100000 处的 ROM BIOS 的物理内存上。这个页表仅映射了 4MB 的内存。在实验中,你将要为 JOS 去设置虚拟内存布局,我们将从虚拟地址 0xf0000000 处开始扩展它,首先将物理内存扩展到 256MB,并映射许多其它区域的虚拟内存。 + +> 练习 3 +> +> 虽然 GDB 能够通过虚拟地址访问 QEMU 的内存,它经常用于在配置虚拟内存期间检查物理内存。在实验工具指南中复习 QEMU 的监视器命令,尤其是 `xp` 命令,它可以让你去检查物理内存。访问 QEMU 监视器,可以在终端中按 `Ctrl-a c`(相同的绑定返回到串行控制台)。 +> +> 使用 QEMU 监视器的 `xp` 命令和 GDB 的 `x` 命令去检查相应的物理内存和虚拟内存,以确保你看到的是相同的数据。 +> +> 我们的打过补丁的 QEMU 版本提供一个非常有用的 `info pg` 命令:它可以展示当前页表的一个简单描述,包括所有已映射的内存范围、权限、以及标志。Stock QEMU 也提供一个 `info mem` 命令用于去展示一个概要信息,这个信息包含了已映射的虚拟内存范围和使用了什么权限。 + +在 CPU 上运行的代码,一旦处于保护模式(这是在 boot/boot.S 中所做的第一件事情)中,是没有办法去直接使用一个线性地址或物理地址的。所有的内存引用都被解释为虚拟地址,然后由 MMU 来转换,这意味着在 C 语言中的指针都是虚拟地址。 + +例如在物理内存分配器中,JOS 内存经常需要在不反向引用的情况下,去维护作为地址的一个很难懂的值或一个整数。有时它们是虚拟地址,而有时是物理地址。为便于在代码中证明,JOS 源文件中将它们区分为两种:类型 `uintptr_t` 表示一个难懂的虚拟地址,而类型 `physaddr_trepresents` 表示物理地址。这些类型其实不过是 32 位整数(uint32_t)的同义词,因此编译器不会阻止你将一个类型的数据指派为另一个类型!因为它们都是整数(而不是指针)类型,如果你想去反向引用它们,编译器将报错。 + +JOS 内核能够通过将它转换为指针类型的方式来反向引用一个 `uintptr_t` 类型。相反,内核不能反向引用一个物理地址,因为这是由 MMU 来转换所有的内存引用。如果你转换一个 `physaddr_t` 为一个指针类型,并反向引用它,你或许能够加载和存储最终结果地址(硬件将它解释为一个虚拟地址),但你并不会取得你想要的内存位置。 + +总结如下: + +| C type | Address type | +| ------------ | ------------ | +| `T*` | Virtual | +| `uintptr_t` | Virtual | +| `physaddr_t` | Physical | + +>问题: +> +>假设下面的 JOS 内核代码是正确的,那么变量 `x` 应该是什么类型?uintptr_t 还是 physaddr_t ? +> +>![屏幕快照 2018-09-04 11.48.54](https://ws3.sinaimg.cn/large/0069RVTdly1fuxgrbkqd3j30m302bmxc.jpg) +> + +JOS 内核有时需要去读取或修改它知道物理地址的内存。例如,添加一个映射到页表,可以要求分配物理内存去存储一个页目录,然后去初始化它们。然而,内核也和其它的软件一样,并不能跳过虚拟地址转换,内核并不能直接加载和存储物理地址。一个原因是 JOS 将重映射从虚拟地址 0xf0000000 处物理地址 0 开始的所有的物理地址,以帮助内核去读取和写入它知道物理地址的内存。为转换一个物理地址为一个内核能够真正进行读写操作的虚拟地址,内核必须添加 0xf0000000 到物理地址以找到在重映射区域中相应的虚拟地址。你应该使用 KADDR(pa) 去做那个添加操作。 + +JOS 内核有时也需要能够通过给定的内核数据结构中存储的虚拟地址找到内存中的物理地址。内核全局变量和通过 `boot_alloc()` 分配的内存是加载到内核的这些区域中,从 0xf0000000 处开始,到全部物理内存映射的区域。因此,在这些区域中转变一个虚拟地址为物理地址时,内核能够只是简单地减去 0xf0000000 即可得到物理地址。你应该使用 PADDR(va) 去做那个减法操作。 + +### 引用计数 + +在以后的实验中,你将会经常遇到多个虚拟地址(或多个环境下的地址空间中)同时映射到相同的物理页面上。你将在 PageInfo 数据结构中用 pp_ref 字段来提供一个引用到每个物理页面的计数器。如果一个物理页面的这个计数器为 0,表示这个页面已经被释放,因为它不再被使用了。一般情况下,这个计数器应该等于相应的物理页面出现在所有页表下面的 UTOP 的次数(UTOP 上面的映射大都是在引导时由内核设置的,并且它从不会被释放,因此不需要引用计数器)。我们也使用它去跟踪到页目录的指针数量,反过来就是,页目录到页表的数量。 + +使用 `page_alloc` 时要注意。它返回的页面引用计数总是为 0,因此,一旦对返回页做了一些操作(比如将它插入到页表),`pp_ref` 就应该增加。有时这需要通过其它函数(比如,`page_instert`)来处理,而有时这个函数是直接调用 `page_alloc` 来做的。 + +### 页表管理 + +现在,你将写一套管理页表的代码:去插入和删除线性地址到物理地址的映射表,并且在需要的时候去创建页表。 + +> 练习 4 +> +> 在文件 `kern/pmap.c` 中,你必须去实现下列函数的代码。 +> +> pgdir_walk() +> +> boot_map_region() +> +> page_lookup() +> +> page_remove() +> +> page_insert() +> +> `check_page()`,调用 `mem_init()`,测试你的页表管理动作。在进行下一步流程之前你应该确保它成功运行。 + +### 第 3 部分:内核地址空间 + +JOS 分割处理器的 32 位线性地址空间为两部分:用户环境(进程),我们将在实验 3 中开始加载和运行,它将控制其上的布局和低位部分的内容,而内核总是维护对高位部分的完全控制。线性地址的定义是在 `inc/memlayout.h` 中通过符号 ULIM 来划分的,它为内核保留了大约 256MB 的虚拟地址空间。这就解释了为什么我们要在实验 1 中给内核这样的一个高位链接地址的原因:如是不这样做的话,内核的虚拟地址空间将没有足够的空间去同时映射到下面的用户空间中。 + +你可以在 `inc/memlayout.h` 中找到一个图表,它有助于你去理解 JOS 内存布局,这在本实验和后面的实验中都会用到。 + +### 权限和缺页隔离 + +由于内核和用户的内存都存在于它们各自环境的地址空间中,因此我们需要在 x86 的页表中使用权限位去允许用户代码只能访问用户所属地址空间的部分。否则的话,用户代码中的 bug 可能会覆写内核数据,导致系统崩溃或者发生各种莫名其妙的的故障;用户代码也可能会偷窥其它环境的私有数据。 + +对于 ULIM 以上部分的内存,用户环境没有任何权限,只有内核才可以读取和写入这部分内存。对于 [UTOP,ULIM] 地址范围,内核和用户都有相同的权限:它们可以读取但不能写入这个地址范围。这个地址范围是用于向用户环境暴露某些只读的内核数据结构。最后,低于 UTOP 的地址空间是为用户环境所使用的;用户环境将为访问这些内核设置权限。 + +### 初始化内核地址空间 + +现在,你将去配置 UTOP 以上的地址空间:内核部分的地址空间。`inc/memlayout.h` 中展示了你将要使用的布局。我将使用函数去写相关的线性地址到物理地址的映射配置。 + +> 练习 5 +> +> 完成调用 `check_page()` 之后在 `mem_init()` 中缺失的代码。 + +现在,你的代码应该通过了 `check_kern_pgdir()` 和 `check_page_installed_pgdir()` 的检查。 + +> 问题: +> +> ​ 1、在这个时刻,页目录中的条目(行)是什么?它们映射的址址是什么?以及它们映射到哪里了?换句话说就是,尽可能多地填写这个表: +> +> EntryBase Virtual AddressPoints to (logically): +> +> 1023 ? Page table for top 4MB of phys memory +> +> 1022 ? ? +> +> . ? ? +> +> . ? ? +> +> . ? ? +> +> 2 0x00800000 ? +> +> 1 0x00400000 ? +> +> 0 0x00000000 [see next question] +> +> ​ 2、(来自课程 3) 我们将内核和用户环境放在相同的地址空间中。为什么用户程序不能去读取和写入内核的内存?有什么特殊机制保护内核内存? +> +> ​ 3、这个操作系统能够支持的最大的物理内存数量是多少?为什么? +> +> ​ 4、我们真实地拥有最大数量的物理内存吗?管理内存的开销有多少?这个开销可以减少吗? +> +> ​ 5、复习在 `kern/entry.S` 和 `kern/entrypgdir.c` 中的页表设置。一旦我们打开分页,EIP 中是一个很小的数字(稍大于 1MB)。在什么情况下,我们转而去运行在 KERNBASE 之上的一个 EIP?当我们启用分页并开始在 KERNBASE 之上运行一个 EIP 时,是什么让我们能够持续运行一个很低的 EIP?为什么这种转变是必需的? + +### 地址空间布局的其它选择 + +在 JOS 中我们使用的地址空间布局并不是我们唯一的选择。一个操作系统可以在低位的线性地址上映射内核,而为用户进程保留线性地址的高位部分。然而,x86 内核一般并不采用这种方法,而 x86 向后兼容模式是不这样做的其中一个原因,这种模式被称为“虚拟 8086 模式”,处理器使用线性地址空间的最下面部分是“不可改变的”,所以,如果内核被映射到这里是根本无法使用的。 + +虽然很困难,但是设计这样的内核是有这种可能的,即:不为处理器自身保留任何固定的线性地址或虚拟地址空间,而有效地允许用户级进程不受限制地使用整个 4GB 的虚拟地址空间 —— 同时还要在这些进程之间充分保护内核以及不同的进程之间相互受保护! + +将内核的内存分配系统进行概括类推,以支持二次幂为单位的各种页大小,从 4KB 到一些你选择的合理的最大值。你务必要有一些方法,将较大的分配单位按需分割为一些较小的单位,以及在需要时,将多个较小的分配单位合并为一个较大的分配单位。想一想在这样的一个系统中可能会出现些什么样的问题。 + +这个实验做完了。确保你通过了所有的等级测试,并记得在 `answers-lab2.txt` 中写下你对上述问题的答案。提交你的改变(包括添加 `answers-lab2.txt` 文件),并在 `lab` 目录下输入 `make handin` 去提交你的实验。 + +------ + +via: + +作者:[Mit][] +译者:[qhwdw](https://github.com/qhwdw) +校对:[校对者ID](https://github.com/%E6%A0%A1%E5%AF%B9%E8%80%85ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 \ No newline at end of file diff --git a/translated/tech/20171003 Streams a new general purpose data structure in Redis.md b/translated/tech/20171003 Streams a new general purpose data structure in Redis.md deleted file mode 100644 index 39da54d0cf..0000000000 --- a/translated/tech/20171003 Streams a new general purpose data structure in Redis.md +++ /dev/null @@ -1,165 +0,0 @@ -streams:一个新的 Redis 通用数据结构 -================================== - -直到几个月以前,对于我来说,在消息传递的环境中,streams 只是一个有趣且相对简单的概念。在 Kafka 流行这个概念之后,我主要研究它们在 Disque 实例中的用途。Disque 是一个将会转化为 Redis 4.2 的模块的消息队列。后来我发现 Disque 全都是 AP 消息,它将在不需要客户端过多参与的情况下实现容错和保证送达,因此,我认为 streams 的概念在那种情况下并不适用。 - -但是,在 Redis 中有一个问题,那就是缺省情况下导出数据结构并不轻松。它在 Redis 列表、排序集和发布/订阅(Pub/Sub)能力上有某些缺陷。你可以合适地使用这些工具去模拟一个消息或事件的序列,而有所权衡。排序集是大量耗费内存的,不能自然的模拟一次又一次的相同消息的传递,客户端不能阻塞新消息。因为一个排序集并不是一个序列化的数据结构,它是一个根据它们量的变化而移动的元素集:它不是很像时间系列一样的东西。列表有另外的问题,它在某些特定的用例中产生类似的适用性问题:你无法浏览列表中部是什么,因为在那种情况下,访问时间是线性的。此外,没有任何的指定输出功能,列表上的阻塞操作仅为单个客户端提供单个元素。列表中没有固定的元素标识,也就是说,不能指定从哪个元素开始给我提供内容。对于一到多的工作负载,这里有发布/订阅,它在大多数情况下是非常好的,但是,对于某些不想“即发即弃”的东西:保留一个历史是很重要的,而不是断开之后重新获得消息,也因为某些消息列表,像时间系列,在用范围查询浏览时,是非常重要的:在这 10 秒范围内我的温度读数是多少? - -这有一种方法可以尝试处理上面的问题,我计划对排序集进行通用化,并列入一个唯一的、更灵活的数据结构,然而,我的设计尝试最终以生成一个比当前的数据结构更加矫揉造作的结果而结束。一个关于 Redis 数据结构导出的更好的想法是,让它更像天然的计算机科学的数据结构,而不是,“Salvatore 发明的 API”。因此,在最后我停止了我的尝试,并且说,“ok,这是我们目前能提供的”,或许,我将为发布/订阅增加一些历史信息,或者将来对列表访问增加一些更灵活的方式。然而,每次在会议上有用户对我说“你如何在 Redis 中模拟时间系列” 或者类似的问题时,我的脸就绿了。 - -### 起源 - -在将 Redis 4.0 中的模块介绍完之后,用户开始去看他们自己怎么去修复这些问题。他们之一,Timothy Downs,通过 IRC 写信给我: - - 这个模块,我计划去增加一个事务日志式的数据类型 - 这意味着大量的订阅者可以在没有大量的内存增加的情况下做一些像发布/订阅那样的事情 - 订阅者保持他在消息队列中的位置,而不是在 Redis 上维护每个客户和复制消息的每个订阅者 - -这激发了我的想像力。我想了几天,并且意识到这可能是我们立刻同时解决上面的问题的契机。我需要去重新想像 “日志” 的概念是什么。它是个基本的编程元素,每个人都使用到它,因为它是非常简单地在追加模式中打开一个文件并以一定的格式写入数据,数据结构必须是抽象的。然而 Redis ,它们在内存中,并且我们使用 RAM 并不是因为我们懒,但是,因为使用一些指针,我们可以概念化数据结构并让他们抽象,并允许他们去摆脱明显的限制。对于实例,正常的日志有几个问题:偏移不是逻辑的,但是,它是一个真实的字节偏移,如果你想逻辑偏移是什么,那是与条目插入的时间相关的,我们有范围查询可用。同样的,一个日志通常很难收集:在一个只追加的数据结构中怎么去删除旧的元素?好吧,在我们理想的日志中,我们只是说,我想要最大的条目数,而旧的元素一个也不要,等等。 - -当我从 Timothy 的想法,去尝试着写一个规范的时候,我使用了 radix 树去实现,它是用于 Redis 集群的,去优化它内部的某些部分。这为实现一个有效的空间日志提供了基础。它在对数的时间(logarithmic time)内得到范围是仍然可访问的。同时,我开始去读关于 Kafka 流,去得到另外的创意,它也非常适合我的设计,并且产生了一个 Kafka 客户组的概念,并且,将它理想化用于 Redis 和内存中(in-memory)使用的案例。然而,该规范仅保留了几个月,在一段时间后,我积累了与别人讨论的即将增加到 Redis 中的内容,为了升级它,使用了许多提示(hint)几乎从头到尾重写了一遍。我想 Redis 流尤其对于时间系列是非常有用的,而不仅是用于事件和消息类的应用程序。 - -让我们写一些代码 -===================== - -从 Redis 会议回来后,在整个夏天,我实现了一个称为 “listpack” 的库。这个库是 ziplist.c 的继承者,那是一个表示在单个分配中字符串元素的列表的数据结构。它是一个非常专业的序列化格式,有在相反的顺序中可解析的特性,从右到左: 在所有的用户案例中用于替代 ziplists 中所需的某些东西。 - -结合 radix 树 + listpacks,它可以很容易地去构建一个日志,它同时也是非常高效的,并且是索引化的,意味着,允许通过 IDs 和时间进行随机访问。自从实现这个方法后,为了实现流数据结构,我开始去写一些代码。我直到完成实现,不管怎样,在这个时候,在 Github 上的 Redis 内部的 “streams” 分支,去启动共同开发并接受订阅已经足够了。我并没有声称那个 API 是最终版本,但是,这有两个有趣的事实:一是,在那时,仅客户组是缺失的,加上一些不那么重要的命令去操作流,但是,所有的大的方面都已经实现了。二是,一旦各个方面比较稳定了之后 ,决定将所有的流的工作移植到 4.0 分支,它大约两个月后发布。这意味着 Redis 用户为了使用流,不用等待 Redis 4.2,它们将对生产使用的 ASAP 可用。这是可能的,因为有一个新的数据结构,几乎所有的代码改变都是独立于新代码的。除了阻塞列表操作之外 :代码都重构了,因此,我们和流共享了相同的代码,并且,列表阻塞操作在 Redis 内部进行了大量的简化。 - -教程:欢迎使用 Redis 流 -================================== - -在某种程序上,你应该感谢流作为 Redis 列表的一个增强版本。流元素不再是一个单一的字符串,它们更多是一个域(fields)和值(values)组成的对象。范围查询更适用而且更快。流中的每个条目都有一个 ID,它是一个逻辑偏移量。不同的客户端可以阻塞等待(blocking-wait)比指定的 IDs 更大的元素。Redis 流的一个基本的命令是 XADD。是的,所有的 Redis 命令都是以一个“X”为前缀的。 - -> XADD mystream * sensor-id 1234 temperature 10.5 -1506871964177.0 - -这个 XADD 命令将追加指定的条目作为一个新元素到一个指定的流 “mystream” 中。在上面的示例中的这个条目有两个域:sensor-id 和 temperature,然而,每个条目在同一个流中可以有不同的域。使用相同的域名字将导致更多的内存使用。一个有趣的事情是,域的排序是保证保存的。XADD 仅返回插入的条目的 ID,因为在第三个参数中有星号(*),我们请求命令去自动生成 ID。这几乎总是你想要的,但是,它也可能去强制指定一个 ID,实例为了去复制这个命令到被动服务器和 AOF 文件。 - -这个 ID 是由两部分组成的:一个毫秒时间和一个序列号。1506871964177 是毫秒时间,它仅是一个使用毫秒解决方案的 UNIX 时间。圆点(.)后面的数字 0,是一个序列号,它是为了区分相同毫秒数的条目增加上去的。所有的数字都是 64 位的无符号整数。这意味着在流中,我们可以增加所有我们想要的条目,在相同毫秒数中的事件。ID 的毫秒部分使用 Redis 服务器的当前本地时间生成的 ID 和流中的最后一个条目之间的最大值来获取。因此,对实例来说,即使是计算机时间向后跳,这个 IDs 仍然是增加的。在某些情况下,你可能想流条目的 IDs 作为完整的 128 位数字。然而,现实是,它们与被添加的实例的本地时间有关,意味着我们有毫秒级的精确的范围查询。 - -如你想像的那样,以一个快速的方式去添加两个条目,结果是仅序列号增加。我可以使用一个 MULTI/EXEC 块去简单模拟“快速插入”,如下: - -> MULTI -OK -> XADD mystream * foo 10 -QUEUED -> XADD mystream * bar 20 -QUEUED -> EXEC -1) 1506872463535.0 -2) 1506872463535.1 - -在上面的示例中,也展示了无需在开始时指定任何模式(schema)的情况下,对不同的条目,使用不同的域。会发生什么呢?每个块(它通常包含 50 - 150 个消息范围的内容)的每一个信息被用作参考。并且,有相同域的连续条目被使用一个标志进行压缩,这个标志表明“这个块中的第一个条目的相同域”。因此,对于连续消息使用相同域可以节省许多内存,即使是域的集合随着时间发生缓慢变化。 - -为了从流中检索数据,这里有两种方法:范围查询,它是通过 XRANGE 命令实现的,并且对于正在变化的流,通过 XREAD 命令去实现。XRANGE 命令仅取得包括从开始到停止范围内的条目。因此,对于实例,如果我知道它的 ID,我可以取得单个条目,像这样: - -> XRANGE mystream 1506871964177.0 1506871964177.0 -1) 1) 1506871964177.0 - 2) 1) "sensor-id" - 2) "1234" - 3) "temperature" - 4) "10.5" - -然而,你可以使用指定的开始符号 “-” 和停止符号 “+” 去表示可能的最小和最大 ID。为了限制返回条目的数量,它也可以使用 COUNT 选项。下面是一个更复杂的 XRANGE 示例: - -> XRANGE mystream - + COUNT 2 -1) 1) 1506871964177.0 - 2) 1) "sensor-id" - 2) "1234" - 3) "temperature" - 4) "10.5" -2) 1) 1506872463535.0 - 2) 1) "foo" - 2) "10" - -这里我们讲的是 IDs 的范围,然后,为了在一个给定时间范围内取得特定元素的范围,你可以使用 XRANGE,因为你可以省略 IDs 的“序列” 部分。因此,你可以做的仅是指定“毫秒”时间,下面的命令的意思是: “从 UNIX 时间 1506872463 开始给我 10 个条目”: - -127.0.0.1:6379> XRANGE mystream 1506872463000 + COUNT 10 -1) 1) 1506872463535.0 - 2) 1) "foo" - 2) "10" -2) 1) 1506872463535.1 - 2) 1) "bar" - 2) "20" - -关于 XRANGE 注意的最重要的事情是,由于我们在回复中收到了 IDs,并且连续 ID 是无法直接获得的,因为 ID 的序列部分是增加的,它可以使用 XRANGE 去遍历整个流,接收每个调用的元素的特定个数。在 Redis 中的*SCAN*系列命令之后,那是允许 Redis 数据结构迭代的,尽管事实上它们不是为迭代设计的,我以免再次产生相同的错误。 - -使用 XREAD 处理变化的流:阻塞新的数据 -=========================================== - -XRANGE 用于,当我们想通过 ID 或时间去访问流中的一个范围或者是通过 ID 去得到单个元素时,是非常完美的。然而,在当数据到达时,不同的客户端必须同时使用流的情况下,它就不是一个很好的解决方案,并且它是需要某种形式的“池”的。(对于*某些*应用程序来说,这可能是个好主意,因为它们仅是偶尔连接取数的)。 - -XREAD 命令是为读设计的,同时从多个流中仅指定我们得到的流中的最后条目的 ID。此外,如果没有数据可用,我们可以要求阻塞,当数据到达时,去解除阻塞。类似于阻塞列表操作产生的效果,但是,这里的数据是从流中得到的。并且多个客户端可以在同时访问相同的数据。 - -这里有一个关于 XREAD 调用的规范示例: - -> XREAD BLOCK 5000 STREAMS mystream otherstream $ $ - -它的意思是:从 “mystream” 和 “otherstream” 取得数据。如果没有数据可用,阻塞客户端 5000 毫秒。之后我们用关键字 STREAMS 指定我们想要监听的流,和最后的 ID,指定的 ID “$” 意思是:假设我现在已经有了流中的所有元素,因此,从下一个到达的元素开始给我。 - -如果,从另外一个客户端,我发出这样的命令: - -> XADD otherstream * message “Hi There” - -在 XREAD 侧会出现什么情况呢? - -1) 1) "otherstream" - 2) 1) 1) 1506935385635.0 - 2) 1) "message" - 2) "Hi There" - -和到过的数据一起,我们得到了最新到达的数据的 key,在下次的调用中,我们将使用接收到的最新消息的 ID: - -> XREAD BLOCK 5000 STREAMS mystream otherstream $ 1506935385635.0 - -依次类推。然而需要注意的是使用方式,有可能客户端在一个非常大的延迟(因为它处理消息需要时间,或者其它什么原因)之后再次连接。在这种情况下,同时会有很多消息堆积,为了确保客户端不被消息淹没,并且服务器不会丢失太多时间的提供给单个客户端的大量消息,所以,总是使用 XREAD 的 COUNT 选项是明智的。 - -流封顶 -============== - -到现在为止,一直还都不错… 然而,有些时候,流需要去删除一些旧的消息。幸运的是,这可以使用 XADD 命令的 MAXLEN 选项去做: - -> XADD mystream MAXLEN 1000000 * field1 value1 field2 value2 - -它是基本意思是,如果流添加的新元素被发现超过 1000000 个消息,那么,删除旧的消息,以便于长度回到 1000000 个元素以内。它很像是使用 RPUSH + LTRIM 的列表,但是,这是我们使用了一个内置机制去完成的。然而,需要注意的是,上面的意思是每次我们增加一个新的消息时,我们还需要另外的工作去从流中删除旧的消息。这将使用一些 CPU 资源,所以,在计算 MAXLEN 的之前,尽可能使用 “~” 符号,为了表明我们不是要求非常*精确*的 1000000 个消息。但是,这里有很多,它还不是一个大的问题: - -> XADD mystream MAXLEN ~ 1000000 * foo bar - -这种方式的 XADD 删除消息,仅用于当它可以删除整个节点的时候。相比 vanilla XADD,这种方式几乎可以自由地对流进行封顶。 - -(进程内工作的)客户组 -================================== - -这是不在 Redis 中实现的第一个特性,但是,它是在进程内工作的。它也是来自 Kafka 的灵感,尽管在这里以不同的方式去实现的。重点是使用了 XREAD,客户端也可以增加一个 “GROUP ” 选项。 在相同组的所有客户端自动调用,以得到*不同的*消息。当然,这里不能从同一个流中被多个组读。在这种情况下,所有的组将收到流中到达的消息的相同副本。但是,在不同的组,消息是不会重复的。 - -当指定组时,尽可能指定一个 “RETRY ” 选项去扩展组:在这种情况下,如果消息没有使用 XACK 去进行确认,它将在指定的毫秒数后进行再次投递。这种情况下,客户端没有私有的方法去标记已处理的消息,这也是一项正在进行中的工作。 - -内存使用和节省的加载时间 -===================================== - -因为被设计用来模拟 Redis 流,所以,根据它们的域的数量、值和长度,内存使用是显著降低的。但对于简单的消息,每 100 MB 内存使用可以有几百万条消息,此外,设想中的格式去需要极少的系列化:是存储为 radix 树节点的 listpack 块,在磁盘上和内存中是用同一个来表示的,因此,它们被琐碎地存储和读取。在一个实例中,Redis 能在 0.3 秒内可以从 RDB 文件中读取 500 万个条目。这使的流的复制和持久存储是非常高效的。 - -它也被计划允许从条目中间删除。现在仅部分实现,策略是整个条目标记中删除的条目被标记为已删除条目,并且,当达到设置的已删除条目占全部条目的比例时,这个块将被回收重写,并且,如果需要,它将被连到相邻的另一个块上,以避免碎片化。 - -最终发布时间的结论 -=================== - -Redis 流将包含在年底前推出的 Redis 4.0 系列的稳定版中。我认为这个通用的数据结构将为 Redis 提供一个巨大的补丁,为了用于解决很多现在很难去解决的情况:那意味着你需要创造性地滥用当前提供的数据结构去解决那些问题。一个非常重要的使用情况是时间系列,但是,我的感觉是,对于其它案例来说,通过 TREAD 来传递消息将是非常有趣的,因为它可以替代那些需要更高可靠性的发布/订阅的应用程序,而不是“即用即弃”,以及全新的使用案例。现在,如果你想在你的有问题的环境中,去评估新的数据结构的能力,可以在 GitHub 上去获得 “streams” 分支,开始去玩吧。欢迎向我们报告所有的 bug 。 :-) - -如果你喜欢这个视频,展示这个 streams 的实时会话在这里: https://www.youtube.com/watch?v=ELDzy9lCFHQ - - --------------------------------------------------------------------------------- - -via: http://antirez.com/news/114 - -作者:[antirez ][a] -译者:[qhwdw](https://github.com/qhwdw) -校对:[校对者ID](https://github.com/校对者ID) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 - -[a]:http://antirez.com/ -[1]:http://antirez.com/news/114 -[2]:http://antirez.com/user/antirez -[3]:https://www.youtube.com/watch?v=ELDzy9lCFHQ diff --git a/translated/tech/20171009 Considering Pythons Target Audience.md b/translated/tech/20171009 Considering Pythons Target Audience.md deleted file mode 100644 index 60cf84ca5e..0000000000 --- a/translated/tech/20171009 Considering Pythons Target Audience.md +++ /dev/null @@ -1,283 +0,0 @@ -[谁是 Python 的目标受众?][40] -============================================================ - -Python 是为谁设计的? - -* [Python 使用情况的参考][8] - -* [CPython 主要服务于哪些受众?][9] - -* [这些相关问题的原因是什么?][10] - -* [适合进入 PyPI 规划的方面有哪些?][11] - -* [当增加它到标准库中时,为什么一些 APIs 会被改变?][12] - -* [为什么一些 API 是以临时(provisional)的形式被增加的?][13] - -* [为什么只有一些标准库 APIs 被升级?][14] - -* [标准库任何部分都有独立的版本吗?][15] - -* [这些注意事项为什么很重要?][16] - -几年前, 我在 python-dev 邮件列表中、活跃的 CPython 核心开发人员、以及决定参与该过程的人员中[强调][38]说,“CPython 的动作太快了也太慢了”,作为这种冲突的一个主要原因是,它们不能有效地使用他们的个人时间和精力。 - -我一直在考虑这种情况,在参与的这几年,我也花费了一些时间去思考这一点,在我写那篇文章的时候,我还在波音防务澳大利亚公司(Boeing Defence Australia)工作。下个月,我将离开波音进入红帽亚太(Red Hat Asia-Pacific),并且开始在大企业的[开源供应链管理][39]上获得重分发者(redistributor)级别的观点。 - -### [Python 使用情况的参考][17] - -我将分解 CPython 的使用情况如下,它虽然有些过于简化(注意,这些分类并不是很清晰,他们仅关注影响新软件特性和版本的部署不同因素): - -* 教育类:教育工作者的主要兴趣在于建模方法的教学和计算操作方面,_不_ 写或维护软件产品。例如: - * 澳大利亚的 [数字课程][1] - - * Lorena A. Barba 的 [AeroPython][2] - -* 个人的自动化爱好者的项目:主要的是软件,经常是只有软件,而且用户通常是写它的人。例如: - * my Digital Blasphemy [image download notebook][3] - - * Paul Fenwick's (Inter)National [Rick Astley Hotline][4] - -* 组织(organisational)过程的自动化:主要是软件,经常是只有软件,用户是为了利益而编写它的组织。例如: - * CPython 的 [核发工作流工具][5] - - * Linux 发行版的开发、构建&发行工具 - -* “一劳永逸(Set-and-forget)” 的基础设施中:这里是软件,(这种说法有时候有些争议),在生命周期中软件几乎不会升级,但是,在底层平台可能会升级。例如: - * 大多数的自我管理的企业或机构的基础设施(在那些资金充足的可持续工程计划中,这是让人非常不安的) - - * 拨款资助的软件(当最初的拨款耗尽时,维护通常会终止) - - * 有严格认证要求的软件(如果没有绝对必要的话,从经济性考虑,重新认证比常规更新来说要昂贵很多) - - * 没有自动升级功能的嵌入式软件系统 - -* 持续升级的基础设施:具有健壮的持续工程化模型的软件,对于依赖和平台升级被认为是例行的,而不去关心其它的代码改变。例如: - * Facebook 的 Python 服务基础设施 - - * 滚动发布的 Linux 分发版 - - * 大多数的公共 PaaS 无服务器环境(Heroku、OpenShift、AWS Lambda、Google Cloud Functions、Azure Cloud Functions等等) - -* 间歇性升级的标准的操作环境:对其核心组件进行常规升级,但这些升级以年为单位进行,而不是周或月。例如: - * [VFX 平台][6] - - * 长周期支持的 Linux 分发版 - - * CPython 和 Python 标准库 - - * 基础设施管理 & 业务流程工具(比如 OpenStack、 Ansible) - - * 硬件控制系统 - -* 短生命周期的软件:软件仅被使用一次,然后就丢弃或忽略,而不是随后接着升级。例如: - * 临时(Ad hoc)自动脚本 - - * 被确定为 “终止” 的单用户游戏(你玩它们一次后,甚至都忘了去卸载它,或许在一个新的设备上都不打算再去安装它) - - * 短暂的或非持久状态的单用户游戏(如果你卸载并重安装它们,你的游戏体验也不会有什么大的变化) - - * 特定事件的应用程序(这些应用程序与特定的物理事件捆绑,一旦事件结束,这些应用程序就不再有用了) - -* 定期使用的应用程序:部署后定期升级的软件。例如: - * 业务管理软件 - - * 个人 & 专业的生产力应用程序(比如,Blender) - - * 开发工具 & 服务(比如,Mercurial、 Buildbot、 Roundup) - - * 多用户游戏,和其它明显的处于持续状态的还没有被定义为 “终止” 的游戏 - - * 有自动升级功能的嵌入式软件系统 - -* 共享的抽象层:软件组件的设计使它能够在特定的问题域有效地工作,即使你没有亲自掌握该领域的所有错综复杂的东西。例如: - * 大多数的运行时库和归入这一类的框架(比如,Django、Flask、Pyramid、SQL Alchemy、NumPy、SciPy、requests) - - * 也适合归入这里的许多测试和类型引用工具(比如,pytest、Hypothesis、vcrpy、behave、mypy) - - * 其它应用程序的插件(比如,Blender plugins、OpenStack hardware adapters) - - * 本身就代表了 “Python 世界” 的基准的标准库(那是一个 [难以置信的复杂][7] 的世界观) - -### [CPython 主要服务于哪些受众?][18] - -最终,CPython 和标准库的主要受众是哪些,不论什么原因,一个更多的有限的标准库和从 PyPI 安装的显式声明的第三方库的组合,提供的服务是不够的。 - -为了更一步简化上面回顾的不同用法和部署模式,为了尽可能的总结,将最大的 Python 用户群体分开来看,一种是,在一些环境中将 Python 作为一种_脚本语言_使用的,另外一种是将它用作一个_应用程序开发语言_,最终发布的是一种产品而不是他们的脚本。 - -当把 Python 作为一种脚本语言来使用时,它们典型的开发者特性包括: - -* 主要的处理单元是由一个 Python 文件组成的(或 Jupyter notebook !),而不是一个 Python 目录和元数据文件 - -* 没有任何形式的单独的构建步骤 - 是_作为_一个脚本分发的,类似于分发一个单独的 shell 脚本的方法。 - -* 没有单独的安装步骤(除了下载这个文件到一个合适的位置),除了在目标系统上要求预配置运行时环境 - -* 没有显式的规定依赖关系,除了最低的 Python 版本,或一个预期的运行环境声明。如果需要一个标准库以外的依赖项,他们会通过一个环境脚本去提供(无论是操作系统、数据分析平台、还是嵌入 Python 运行时的应用程序) - -* 没有单独的测试套件,使用 "通过你给定的输入,这个脚本是否给出了你期望的结果?" 这种方式来进行测试 - -* 如果在执行前需要测试,它将以 “dry run” 和 “预览” 模式来向用户展示软件_将_怎样运行 - -* 如果可以完全使用静态代码分析工具,它是通过集成进用户的软件开发环境的,而不是为个别的脚本单独设置的。 - -相比之下,使用 Python 作为一个应用程序开发语言的开发者特征包括: - -* 主要的工作单元是由 Python 的目录和元数据文件组成的,而不是单个 Python 文件 - -* 在发布之前有一个单独的构建步骤去预处理应用程序,即使是把它的这些文件一起打包进一个 Python sdist、wheel 或 zipapp 文档 - -* 是否有独立的安装步骤去预处理将要使用的应用程序,取决于应用程序是如何打包的,和支持的目标环境 - -* 外部的依赖直接在项目目录中的一个元数据文件中表示(比如,`pyproject.toml`、`requirements.txt`、`Pipfile`),或作为生成的发行包的一部分(比如,`setup.py`、`flit.ini`) - -* 存在一个独立的测试套件,或者作为一个 Python API 的一个测试单元、功能接口的集成测试、或者是两者的一个结合 - -* 静态分析工具的使用是在项目级配置的,作为测试管理的一部分,而不是依赖 - -作为以上分类的一个结果,CPython 和标准库最终提供的主要用途是,在合适的 CPython 特性发布后3 - 5年,为教育和临时(ad hoc)的 Python 脚本环境的呈现的功能,定义重新分发的独立基准。 - -对于临时(ad hoc)脚本使用的情况,这个 3-5 年的延迟是由于新版本重分发给用户的延迟组成的,以及那些重分发版的用户花在修改他们的标准操作环境上的时间。 - -在教育环境中的情况,教育工作者需要一些时间去评估新特性,和决定是否将它们包含进提供给他们的学生的课程中。 - -### [这些相关问题的原因是什么?][19] - -这篇文章很大程序上是受 Twitter 上 [我的评论][20] 的讨论鼓舞的,定义在 [PEP 411][21] 中引用临时(Provisional)的 API 的情形,作为一个开源项目发行的例子,一个真实的被邀请用户,作为共同开发者去积极参与设计和开发过程,而不是仅被动使用已准备好的最终设计。 - -这些回复包括一些在更高级别的库中支持的临时(Provisional) API 的一些相关的沮丧的表述,这些库没有临时(Provisional)状态的传递,以及因此而被限制为只有最新版本的临时(Provisional) API 支持这些相关特性,而不是任何的早期迭代版本。 - -我的 [主要反应][22] 是去建议,开源提供者应该努力加强他们需要的有限支持,以加强他们的维护工作的可持续性。这意味着,如果支持老版本的临时(Provisional) API 是非常痛苦的,然后,只有项目开发人员自己需要时,或者,有人为此支付费用时,他们才会去提供支持。这类似于我的观点,志愿者提供的项目是否应该免费支持老的商业的长周期支持的 Python 发行版,这对他们来说是非常麻烦的事,我[不认他们应该去做][23],正如我所期望的那样,大多数这样的需求都来自于管理差劲的习以为常的惯性,而不是真正的需求(真正的需求,它应该去支付费用来解决问题) - -然而,我的[第二个反应][24]是,去认识到这一点,尽管多年来一直在讨论这个问题(比如,在上面链接中 2011 的一篇年的文章中,以及在 Python 3 问答的回答中 [在这里][25]、[这里][26]、和[这里][27],和在去年的 [Python 包生态系统][28]上的一篇文章中的一小部分),我从来没有真实尝试直接去解释过它对标准库设计过程中的影响。 - -如果没有这些背景,设计过程中的一些方面,如临时(Provisional) API 的介绍,或者是受到不同的启发(inspired-by-not-the-same-as)的介绍,看起来似乎是很荒谬的,因为它们似乎是在试图标准化 API,而实际上并没有对 API 进行标准化。 - -### [适合进入 PyPI 规划的方面有哪些?][29] - -提交给 python-ideas 或 python-dev 的_任何_建议的第一个门槛就是,清楚地回答这个问题,“为什么 PyPI 上的一个模块不够好?”。绝大多数的建议都在这一步失败了,但通过他们得到了几个共同的主题: - -* 大多数新手可能经常是从互联网上去 “复制粘贴” 错误的建议,而不是去下载一个合适的第三方库。(比如,这就是为什么存在 `secrets` 库的原因:使得很少的人去使用 `random` 模块,因为安全敏感的原因,这是用于游戏和统计模拟的) - -* 这个模块是用于提供一个实现的参考,并去允许与其它的相互竞争的实现之间提供互操作性,而不是对所有人的所有事物都是必要的。(比如,`asyncio`、`wsgiref`、`unittest`、和 `logging` 全部都是这种情况) - -* 这个模块是用于标准库的其它部分(比如,`enum` 就是这种情况,像`unittest`一样) - -* 这个模块是被设计去支持语言之外的一些语法(比如,`contextlib`、`asyncio` 和 `typing` 模块,就是这种情况) - -* 这个模块只是普通的临时(ad hoc)脚本用途(比如,`pathlib` 和 `ipaddress` 就是这种情况) - -* 这个模块被用于一个教育环境(比如,`statistics` 模块允许进行交互式地探索统计的概念,尽管你不会用它来做全部的统计分析) - -通过前面的 “PyPI 是不是明显不够好” 的检查,一个模块还不足以确保被接收到标准库中,但它已经足够转变问题为 “在接下来的几年中,你所推荐的要包含的库能否对一般的 Python 开发人员的经验有所改提升?” - -标准库中的 `ensurepip` 和 `venv` 模块的介绍也明确地告诉分发者,我们期望的 Python 级别的打包和安装工具在任何平台的特定分发机制中都予以支持。 - -### [当增加它到标准库中时,为什么一些 APIs 会被改变?][30] - -现在已经存在的第三方模块有时候会被批量地采用到标准库中,在其它情况下,实际上增加进行的是重新设计和重新实现的 API,只是它参照了现有 API 的用户体验,但是,根据另外的设计参考,删除或修改了一些细节,和附属于语言参考实现部分的权限。 - -例如,不像广受欢迎的第三方库的前身 `path.py`,`pathlib` 并_不_规定字符串子类,而是独立的类型。作为解决文件互操作性问题的结果,是定义了文件系统路径协议,它允许与文件系统路径一起使用的接口,去使用更大范围的对象。 - -为 `ipaddress` 模块设计的 API 是为教学 IP 地址概念,从定义的地址和网络中,为显式的单独主机接口调整的(IP 地址关联到特定的 IP 网络),为了提供一个最佳的教学工具,而最原始的 “ipaddr” 模块中,使用网络术语的方式不那么严谨。 - -在其它情况下,标准库被构建为多种现有方法的一个综合,而且,还有可能依赖于定义现有库的 API 时不存在的特性。应用于 `asyncio` 和 `typing` 模块的所有的这些考虑,虽然后来考虑适用于 `dataclasses` 的 API 被认为是 PEP 557 (它可以被总结为 “像属性一样,但是使用变量注释作为字段声明”)。 - -这类改变的工作原理是,这类库不会消失,而且,它们的维护者经常并不关心与标准库相关的限制(特别是,相对缓慢的发行节奏)。在这种情况下,对于标准库版本的文档来说,使用 “See Also” 链接指向原始模块是很常见的,特别是,如果第三方版本提供了标准库模块中忽略的其他特性和灵活性时。 - -### [为什么一些 API 是以临时(provisional)的形式被增加的?][31] - -虽然 CPython 确实设置了 API 的弃用策略,但我们通常不希望在没有令人信服的理由的情况下去使用它(在其他项目试图与 Python 2.7 保持兼容性时,尤其如此)。 - -然而,当增加一个受已有的第三方启发去设计的而不是去拷贝的新的 API 时,在设计实践中,有些设计实践可能会出现问题,这比平常的风险要高。 - -当我们考虑这种改变的风险比平常要高,我们将相关的 API 标记为临时(provisional),表示保守的终端用户可以希望避免完全依赖他们,并且,共享抽象层的开发者可能希望考虑,对他们准备支持的临时(provisional) API 的版本实施比平时更严格的限制。 - -### [为什么只有一些标准库 APIs 被升级?][32] - -这里简短的回答升级的主要 APIs 有哪些?: - -* 不适合外部因素驱动的补充更新 - -* 无论是临时(ad hoc)脚本使用情况,还是为促进将来的多个第三方解决方案之间的互操作性,都有明显好外的 - -* 对这方面感兴趣的人提交了一个可接受的建议 - -如果一个用于应用程序开发的模块存在一个非常明显的限制(limitations),比如,`datetime`,如果重分发版通过替代一个现成的第三方模块有所改善,比如,`requests`,或者,如果标准库的发布节奏与需要的有问题的包之间有真正的冲突,比如,`certifi`,那么,计划对标准库版本进行改变的因素将显著减少。 - -从本质上说,这和关于 PyPI 上面的问题是相反的:因为,PyPI 分发机制对增强应用程序开发人员经验来说,通常_是_足够好的,这样的改进是有意义的,允许重分发者和平台提供者自行决定将哪些内容作为缺省提供的一部分。 - -当改变后的能力(capabilities)假设在 3-5 年内缺省出现时被认为是有价值的,才会将这些改变进入到 CPython 和标准库中。 - -### [标准库任何部分都有独立的版本吗?][33] - -是的,它就像是 `ensurepip` 使用的捆绑模式( CPython 发行了一个 `pip` 的最新捆绑版本,而并没有把它放进标准库中),将来可能被应用到其它模块中。 - -最有可能的第一个候选者是 `distutils` 构建系统,因为切换到这种模式将允许构建系统在多个发行版本之间保持一致。 - -这种处理方式的其它可能的候选对象是 Tcl/Tk graphics 捆绑和 IDLE 编辑器,它们已经被拆分,并且通过一些重分发程序转换成安装可选项。 - -### [这些注意事项为什么很重要?][34] - -从本质上说,那些积极参与开源开发的人就是那些致力于开源应用程序和共享抽象层的人。 - -写一些临时(ad hoc)脚本和为学生设计一些教学习题的人,通常不会认为他们是软件开发人员 —— 他们是教师、系统管理员、数据分析人员、金融工程师、流行病学家、物理学家、生物学家、商业分析师、动画师、架构设计师、等等。 - -当所有我们的担心是,语言是开发人员的经验时,那么,我们可以简单假设人们知道一些什么,他们使用的工具,所遵循的开发流程,以及构建和部署他们软件的方法。 - -当一个应用程序运行时(runtime),_也_作为一个脚本引擎广为流行时,事情将变的更加复杂。在一个项目中去平衡两种需求,就会导致双方的不理解和怀疑,做任何一件事都将变得很困难。 - -这篇文章不是为了说,我们在开发 CPython 过程中从来没有做出过不正确的决定 —— 它只是指出添加到 Python 标准库中的看上去很荒谬的特性的最合理的反应(reaction),它将是 “我不是那个特性的预期目标受众的一部分”,而不是 “我对它没有兴趣,因此,它对所有人都是毫无用处和没有价值的,添加它纯属骚扰我”。 - --------------------------------------------------------------------------------- - -via: http://www.curiousefficiency.org/posts/2017/10/considering-pythons-target-audience.html - -作者:[Nick Coghlan ][a] -译者:[qhwdw](https://github.com/qhwdw) -校对:[校对者ID](https://github.com/校对者ID) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 - -[a]:http://www.curiousefficiency.org/pages/about.html -[1]:https://aca.edu.au/#home-unpack -[2]:https://github.com/barbagroup/AeroPython -[3]:https://nbviewer.jupyter.org/urls/bitbucket.org/ncoghlan/misc/raw/default/notebooks/Digital%20Blasphemy.ipynb -[4]:https://github.com/pjf/rickastley -[5]:https://github.com/python/core-workflow -[6]:http://www.vfxplatform.com/ -[7]:http://www.curiousefficiency.org/posts/2015/10/languages-to-improve-your-python.html#broadening-our-horizons -[8]:http://www.curiousefficiency.org/posts/2017/10/considering-pythons-target-audience.html#use-cases-for-python-s-reference-interpreter -[9]:http://www.curiousefficiency.org/posts/2017/10/considering-pythons-target-audience.html#which-audience-does-cpython-primarily-serve -[10]:http://www.curiousefficiency.org/posts/2017/10/considering-pythons-target-audience.html#why-is-this-relevant-to-anything -[11]:http://www.curiousefficiency.org/posts/2017/10/considering-pythons-target-audience.html#where-does-pypi-fit-into-the-picture -[12]:http://www.curiousefficiency.org/posts/2017/10/considering-pythons-target-audience.html#why-are-some-apis-changed-when-adding-them-to-the-standard-library -[13]:http://www.curiousefficiency.org/posts/2017/10/considering-pythons-target-audience.html#why-are-some-apis-added-in-provisional-form -[14]:http://www.curiousefficiency.org/posts/2017/10/considering-pythons-target-audience.html#why-are-only-some-standard-library-apis-upgraded -[15]:http://www.curiousefficiency.org/posts/2017/10/considering-pythons-target-audience.html#will-any-parts-of-the-standard-library-ever-be-independently-versioned -[16]:http://www.curiousefficiency.org/posts/2017/10/considering-pythons-target-audience.html#why-do-these-considerations-matter -[17]:http://www.curiousefficiency.org/posts/2017/10/considering-pythons-target-audience.html#id1 -[18]:http://www.curiousefficiency.org/posts/2017/10/considering-pythons-target-audience.html#id2 -[19]:http://www.curiousefficiency.org/posts/2017/10/considering-pythons-target-audience.html#id3 -[20]:https://twitter.com/ncoghlan_dev/status/916994106819088384 -[21]:https://www.python.org/dev/peps/pep-0411/ -[22]:https://twitter.com/ncoghlan_dev/status/917092464355241984 -[23]:http://www.curiousefficiency.org/posts/2015/04/stop-supporting-python26.html -[24]:https://twitter.com/ncoghlan_dev/status/917088410162012160 -[25]:http://python-notes.curiousefficiency.org/en/latest/python3/questions_and_answers.html#wouldn-t-a-python-2-8-release-help-ease-the-transition -[26]:http://python-notes.curiousefficiency.org/en/latest/python3/questions_and_answers.html#doesn-t-this-make-python-look-like-an-immature-and-unstable-platform -[27]:http://python-notes.curiousefficiency.org/en/latest/python3/questions_and_answers.html#what-about-insert-other-shiny-new-feature-here -[28]:http://www.curiousefficiency.org/posts/2016/09/python-packaging-ecosystem.html -[29]:http://www.curiousefficiency.org/posts/2017/10/considering-pythons-target-audience.html#id4 -[30]:http://www.curiousefficiency.org/posts/2017/10/considering-pythons-target-audience.html#id5 -[31]:http://www.curiousefficiency.org/posts/2017/10/considering-pythons-target-audience.html#id6 -[32]:http://www.curiousefficiency.org/posts/2017/10/considering-pythons-target-audience.html#id7 -[33]:http://www.curiousefficiency.org/posts/2017/10/considering-pythons-target-audience.html#id8 -[34]:http://www.curiousefficiency.org/posts/2017/10/considering-pythons-target-audience.html#id9 -[35]:http://www.curiousefficiency.org/posts/2017/10/considering-pythons-target-audience.html# -[36]:http://www.curiousefficiency.org/posts/2017/10/considering-pythons-target-audience.html#disqus_thread -[37]:http://www.curiousefficiency.org/posts/2017/10/considering-pythons-target-audience.rst -[38]:http://www.curiousefficiency.org/posts/2011/04/musings-on-culture-of-python-dev.html -[39]:http://community.redhat.com/blog/2015/02/the-quid-pro-quo-of-open-infrastructure/ -[40]:http://www.curiousefficiency.org/posts/2017/10/considering-pythons-target-audience.html# diff --git a/translated/tech/20171022 Review- Algorithms to Live By by Brian Christian - Tom Griffiths.md b/translated/tech/20171022 Review- Algorithms to Live By by Brian Christian - Tom Griffiths.md new file mode 100644 index 0000000000..eec0d29397 --- /dev/null +++ b/translated/tech/20171022 Review- Algorithms to Live By by Brian Christian - Tom Griffiths.md @@ -0,0 +1,44 @@ +书评|算法之美 +====== +![](https://www.eyrie.org/~eagle/reviews/covers/1-62779-037-3.jpg) + +又一次为了工作图书俱乐部而读书。除了其它我亲自推荐的书,这是我至今最喜爱的书。 + +作为计算机科学基础之一的研究领域是算法:我们如何高效地用计算机程序解决问题?这基本上属于数学领域,但是这很少关于理想的或理论上的解决方案,而是更在于最高效地利用有限的资源获得一个充足(如果不能完美)的答案。其中许多问题要么是日常的生活问题,要么与人们密切相关。毕竟,计算机科学的目的是为了用计算机解决实际问题。《算法之美》提出的问题是:“我们可以反过来吗”--我们可以通过学习计算机科学解决问题的方式来帮助我们做出日常决定吗? + +本书的十一个章节有很多有趣的内容,但也有一个有趣的主题:人类早已擅长这一点。很多章节以一个算法研究和对问题的数学分析作为开始,接着深入到探讨如何利用这些结果做出更好的决策,然后讨论关于人类真正会做出的决定的研究,之后,考虑到典型生活情境的限制,会发现人类早就在应用我们提出的最佳算法的特殊版本了。这往往会破坏本书的既定目标,值得庆幸的是,它决不会破坏对一般问题的有趣讨论,即计算机科学如何解决它们,以及我们对这些问题的数学和技术形态的了解。我认为这本书的自助效用比作者打算的少一些,但有很多可供思考的东西。 + +(也就是说,值得考虑这种一致性是否太少了,因为人类已经擅长这方面了,更因为我们的算法是根据人类直觉设计的。可能我们的最佳算法只是反映了人类的思想。在某些情况下,我们发现我们的方案和数学上的典范不一样, 但是在另一些情况下,它们仍然是我们当下最好的猜想。) + +这是那种章节列表是书评里重要部分的书。这里讨论的算法领域有最优停止、探索和利用决策(什么时候带着你发现的最好东西走以及什么时候寻觅更好的东西),以及排序、缓存、调度、贝叶斯定理(一般还有预测)、创建模型时的过拟合、放松(解决容易的问题而不是你的实际问题)、随机算法、一系列网络算法,最后还有游戏理论。其中每一项都有有用的见解和发人深省的讨论--这些有时显得十分理论化的概念令人吃惊地很好地映射到了日常生活。这本书以一段关于“可计算的善意”的讨论结束:鼓励减少你自己和你交往的人所需的计算和复杂性惩罚。 + +如果你有计算机科学背景(就像我一样),其中许多都是熟悉的概念,而且你因为被普及了很多新东西或许会有疑惑。然而,请给这本书一个机会,类比法没你担忧的那么令人紧张。作者既小心又聪明地应用了这些原则。这本书令人惊喜地通过了一个重要的合理性检查:涉及到我知道或反复思考过的主题的章节很少有或没有明显的错误,而且能讲出有用和重要的事情。比如,调度的那一章节毫不令人吃惊地和时间管理有关,通过直接跳到时间管理问题的核心而胜过了半数时间管理类书籍:如果你要做一个清单上的所有事情,你做这些事情的顺序很少要紧,所以最难的调度问题是决定不做哪些事情而不是做这些事情的顺序。 + +作者在贝叶斯定理这一章节中的观点完全赢得了我的心。本章的许多内容都是关于贝叶斯先验的,以及一个人对过去事件的了解为什么对分析未来的概率很重要。作者接着讨论了著名的棉花糖实验。即给了儿童一个棉花糖以后,儿童被研究者告知如果他们能够克制自己不吃这个棉花糖,等到研究者回来时,会给他们两个棉花糖。克制自己不吃棉花糖(在心理学文献中叫作“延迟满足”)被发现与未来几年更好的生活有关。这个实验多年来一直被引用和滥用于各种各样的宣传,关于选择未来的收益放弃即时的快乐从而拥有成功的生活,以及生活中的失败是因为无法延迟满足。更多的邪恶分析(当然)将这种能力与种族联系在一起,带有可想而知的种族主义结论。 + +我对棉花糖实验有点兴趣。这是一个百分百让我愤怒咆哮的话题。 + +《算法之美》是我读过的唯一提到了棉花糖实验并应用了我认为更有说服力的分析的书。这不是一个关于儿童天赋的实验,这是一个关于他们的贝叶斯先验的实验。什么时候立即吃棉花糖而不是等待奖励是完全合理的?当他们过去的经历告诉他们成年人不可靠,不可信任,会在不可预测的时间内消失并且撒谎的时候。而且,更好的是,作者用我之前没有听说过的后续研究和观察支持了这一分析,观察到的内容是,一些孩子会等待一段时间然后“放弃”。如果他们下意识地使用具有较差先验的贝叶斯模型,这就完全合情合理。 + +这是一本很好的书。它可能在某些地方的尝试有点太勉强(数学上最优停止对于日常生活的适用性比我认为作者想要表现的更加偶然和牵强附会),如果你学过算法,其中一些内容会感到熟悉,但是它的行文思路清晰,简洁,而且编辑得非常好。这本书没有哪一部分对不起它所受的欢迎,书中的讨论贯穿始终。如果你发现自己“已经知道了这一切”,你可能还会在接下来几页中遇到一个新的概念或一个简洁的解释。有时作者会做一些我从没想到但是回想起来正确的联系,比如将网络协议中的指数退避和司法系统中的选择惩罚联系起来。还有意识到我们的现代通信世界并不是一直联系的,它是不断缓冲的,我们中的许多人正深受缓冲膨胀这一独特现象的苦恼。 + +我认为你并不必须是计算机科学专业或者精通数学才能读这本书。如果你想深入,每章的结尾都有许多数学上的细节,但是正文总是易读而清晰,至少就我所知是这样(作为一个以计算机科学为专业并学到了很多数学知识的人,你至少可以有保留地相信我)。即使你已经钻研了多年的算法,这本书仍然可以提供很多东西。 + +这本书我读得越多越喜欢。如果你喜欢阅读这种对生活的分析,我当然是赞成的。 + +Rating: 9 out of 10 + +Reviewed: 2017-10-22 + +-------------------------------------------------------------------------------- + +via: https://www.eyrie.org/~eagle/reviews/books/1-62779-037-3.html + +作者:[Brian Christian;Tom Griffiths][a] +译者:[GraveAccent](https://github.com/GraveAccent) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.eyrie.org +[1]:https://www.eyrie.org1-59184-679-X.html diff --git a/translated/tech/20171129 How to Install and Use Wireshark on Debian and Ubuntu 16.04_17.10.md b/translated/tech/20171129 How to Install and Use Wireshark on Debian and Ubuntu 16.04_17.10.md new file mode 100644 index 0000000000..0bcbe0d3e5 --- /dev/null +++ b/translated/tech/20171129 How to Install and Use Wireshark on Debian and Ubuntu 16.04_17.10.md @@ -0,0 +1,183 @@ +在 Debian 9 / Ubuntu 16.04 / 17.10 中如何安装并使用 Wireshark +====== + +作者 [Pradeep Kumar][1],首发于 2017 年 11 月 29 日,更新于 2017 年 11 月 29 日 + +[![wireshark-Debian-9-Ubuntu 16.04 -17.10](https://www.linuxtechi.com/wp-content/uploads/2017/11/wireshark-Debian-9-Ubuntu-16.04-17.10.jpg)][2] + +Wireshark 是免费的,开源的,跨平台的基于 GUI 的网络数据包分析器,可用于 Linux, Windows, MacOS, Solaris 等。它可以实时捕获网络数据包,并以人性化的格式呈现。Wireshark 允许我们监控网络数据包上升到微观层面。Wireshark 还有一个名为 `tshark` 的命令行实用程序,它与 Wireshark 执行相同的功能,但它是通过终端而不是 GUI。 + +Wireshark 可用于网络故障排除,分析,软件和通信协议开发以及用于教育目的。Wireshark 使用 `pcap` 库来捕获网络数据包。 + +Wireshark 具有许多功能: + +* 支持数百项协议检查 + +* 能够实时捕获数据包并保存,以便以后进行离线分析 + +* 许多用于分析数据的过滤器 + +* 捕获的数据可以被压缩和解压缩(to 校正:on the fly 什么意思?) + +* 支持各种文件格式的数据分析,输出也可以保存为 XML, CSV 和纯文本格式 + +* 数据可以从以太网,wifi,蓝牙,USB,帧中继,令牌环等多个接口中捕获 + +在本文中,我们将讨论如何在 Ubuntu/Debian 上安装 Wireshark,并将学习如何使用 Wireshark 捕获网络数据包。 + +#### 在 Ubuntu 16.04 / 17.10 上安装 Wireshark + +Wireshark 在 Ubuntu 默认仓库中可用,只需使用以下命令即可安装。但有可能得不到最新版本的 wireshark。 + +``` +linuxtechi@nixworld:~$ sudo apt-get update +linuxtechi@nixworld:~$ sudo apt-get install wireshark -y +``` + +因此,要安装最新版本的 wireshark,我们必须启用或配置官方 wireshark 仓库。 + +使用下面的命令来配置仓库并安装最新版本的 wireshark 实用程序。 + +``` +linuxtechi@nixworld:~$ sudo add-apt-repository ppa:wireshark-dev/stable +linuxtechi@nixworld:~$ sudo apt-get update +linuxtechi@nixworld:~$ sudo apt-get install wireshark -y +``` + +一旦安装了 wireshark,执行以下命令,以便非 root 用户也可以捕获接口的实时数据包。 + +``` +linuxtechi@nixworld:~$ sudo setcap 'CAP_NET_RAW+eip CAP_NET_ADMIN+eip' /usr/bin/dumpcap +``` + +#### 在 Debian 9 上安装 Wireshark + +Wireshark 包及其依赖项已存在于 debian 9 的默认仓库中,因此要在 Debian 9 上安装最新且稳定版本的 Wireshark,请使用以下命令: + +``` +linuxtechi@nixhome:~$ sudo apt-get update +linuxtechi@nixhome:~$ sudo apt-get install wireshark -y +``` + +在安装过程中,它会提示我们为非超级用户配置 dumpcap, + +选择 `yes` 并回车。 + +[![Configure-Wireshark-Debian9](https://www.linuxtechi.com/wp-content/uploads/2017/11/Configure-Wireshark-Debian9-1024x542.jpg)][3] + +安装完成后,执行以下命令,以便非 root 用户也可以捕获接口的实时数据包。 + +``` +linuxtechi@nixhome:~$ sudo chmod +x /usr/bin/dumpcap +``` + +我们还可以使用最新的源代码包在 Ubuntu/Debian 和其它 Linux 发行版上安装 wireshark。 + +#### 在 Debian / Ubuntu 系统上使用源代码安装 Wireshark + +首先下载最新的源代码包(写这篇文章时它的最新版本是 2.4.2),使用以下命令: + +``` +linuxtechi@nixhome:~$ wget https://1.as.dl.wireshark.org/src/wireshark-2.4.2.tar.xz +``` + +然后解压缩包,进入解压缩的目录: + +``` +linuxtechi@nixhome:~$ tar -xf wireshark-2.4.2.tar.xz -C /tmp +linuxtechi@nixhome:~$ cd /tmp/wireshark-2.4.2 +``` + +现在我们使用以下命令编译代码: + +``` +linuxtechi@nixhome:/tmp/wireshark-2.4.2$ ./configure --enable-setcap-install +linuxtechi@nixhome:/tmp/wireshark-2.4.2$ make +``` + +最后安装已编译的软件包以便在系统上安装 Wireshark: + +``` +linuxtechi@nixhome:/tmp/wireshark-2.4.2$ sudo make install +linuxtechi@nixhome:/tmp/wireshark-2.4.2$ sudo ldconfig +``` + +在安装后,它将创建一个单独的 Wireshark 组,我们现在将我们的用户添加到组中,以便它可以与 Wireshark 一起使用,否则在启动 wireshark 时可能会出现 `permission denied(权限被拒绝)`错误。 + +要将用户添加到 wireshark 组,执行以下命令: + +``` +linuxtechi@nixhome:~$ sudo usermod -a -G wireshark linuxtechi +``` + +现在我们可以使用以下命令从 GUI 菜单或终端启动 wireshark: + +``` +linuxtechi@nixhome:~$ wireshark +``` + +#### 在 Debian 9 系统上使用 Wireshark + +[![Access-wireshark-debian9](https://www.linuxtechi.com/wp-content/uploads/2017/11/Access-wireshark-debian9-1024x664.jpg)][4] + +点击 Wireshark 图标 + +[![Wireshark-window-debian9](https://www.linuxtechi.com/wp-content/uploads/2017/11/Wireshark-window-debian9-1024x664.jpg)][5] + +#### 在 Ubuntu 16.04 / 17.10 上使用 Wireshark + +[![Access-wireshark-Ubuntu](https://www.linuxtechi.com/wp-content/uploads/2017/11/Access-wireshark-Ubuntu-1024x664.jpg)][6] + +点击 Wireshark 图标 + +[![Wireshark-window-Ubuntu](https://www.linuxtechi.com/wp-content/uploads/2017/11/Wireshark-window-Ubuntu-1024x664.jpg)][7] + +#### 捕获并分析数据包 + +一旦 wireshark 启动,我们就会看到 wireshark 窗口,上面有 Ubuntu 和 Debian 系统的示例。 + +[![wireshark-Linux-system](https://www.linuxtechi.com/wp-content/uploads/2017/11/wireshark-Linux-system.jpg)][8] + +所有这些都是我们可以捕获网络数据包的接口。根据你系统上的界面,此屏幕可能与你的不同。 + +我们选择 `enp0s3` 来捕获该接口的网络流量。选择接口后,在我们网络上所有设备的网络数据包开始填充(参考下面的屏幕截图): + +[![Capturing-Packet-from-enp0s3-Ubuntu-Wireshark](https://www.linuxtechi.com/wp-content/uploads/2017/11/Capturing-Packet-from-enp0s3-Ubuntu-Wireshark-1024x727.jpg)][9] + +第一次看到这个屏幕,我们可能会被这个屏幕上显示的数据所淹没,并且可能已经想过如何整理这些数据,但不用担心,Wireshark 的最佳功能之一就是它的过滤器。 + +我们可以根据 IP 地址,端口号,也可以使用来源和目标过滤器,数据包大小等对数据进行排序和过滤,也可以将两个或多个过滤器组合在一起以创建更全面的搜索。我们也可以在 `Apply a Display Filter(应用显示过滤器)`选项卡中编写过滤规则,也可以选择已创建的规则。要选择之前构建的过滤器,请单击 `Apply a Display Filter(应用显示过滤器)`选项卡旁边的 `flag` 图标。 + +[![Filter-in-wireshark-Ubuntu](https://www.linuxtechi.com/wp-content/uploads/2017/11/Filter-in-wireshark-Ubuntu-1024x727.jpg)][10] + +我们还可以根据颜色编码过滤数据,默认情况下,浅紫色是 TCP 流量,浅蓝色是 UDP 流量,黑色标识有错误的数据包,看看这些编码是什么意思,点击 `View -> Coloring Rules`,我们也可以改变这些编码。 + +[![Packet-Colouring-Wireshark](https://www.linuxtechi.com/wp-content/uploads/2017/11/Packet-Colouring-Wireshark-1024x682.jpg)][11] + +在我们得到我们需要的结果之后,我们可以点击任何捕获的数据包以获得有关该数据包的更多详细信息,这将显示该网络数据包的所有数据。 + +Wireshark 是一个非常强大的工具,需要一些时间来习惯并对其进行命令操作,本教程将帮助你入门。请随时在下面的评论框中提出你的疑问或建议。 + + +-------------------------------------------------------------------------------- + +via: https://www.linuxtechi.com + +作者:[Pradeep Kumar][a] +译者:[MjSeven](https://github.com/MjSeven) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.linuxtechi.com/author/pradeep/ +[1]:https://www.linuxtechi.com/author/pradeep/ +[2]:https://www.linuxtechi.com/wp-content/uploads/2017/11/wireshark-Debian-9-Ubuntu-16.04-17.10.jpg +[3]:https://www.linuxtechi.com/wp-content/uploads/2017/11/Configure-Wireshark-Debian9.jpg +[4]:https://www.linuxtechi.com/wp-content/uploads/2017/11/Access-wireshark-debian9.jpg +[5]:https://www.linuxtechi.com/wp-content/uploads/2017/11/Wireshark-window-debian9.jpg +[6]:https://www.linuxtechi.com/wp-content/uploads/2017/11/Access-wireshark-Ubuntu.jpg +[7]:https://www.linuxtechi.com/wp-content/uploads/2017/11/Wireshark-window-Ubuntu.jpg +[8]:https://www.linuxtechi.com/wp-content/uploads/2017/11/wireshark-Linux-system.jpg +[9]:https://www.linuxtechi.com/wp-content/uploads/2017/11/Capturing-Packet-from-enp0s3-Ubuntu-Wireshark.jpg +[10]:https://www.linuxtechi.com/wp-content/uploads/2017/11/Filter-in-wireshark-Ubuntu.jpg +[11]:https://www.linuxtechi.com/wp-content/uploads/2017/11/Packet-Colouring-Wireshark.jpg diff --git a/translated/tech/20180201 Conditional Rendering in React using Ternaries and.md b/translated/tech/20180201 Conditional Rendering in React using Ternaries and.md new file mode 100644 index 0000000000..aa7ba0017e --- /dev/null +++ b/translated/tech/20180201 Conditional Rendering in React using Ternaries and.md @@ -0,0 +1,205 @@ +在 React 条件渲染中使用三元表达式和 “&&” +============================================================ + +![](https://cdn-images-1.medium.com/max/2000/1*eASRJrCIVgsy5VbNMAzD9w.jpeg) +Photo by [Brendan Church][1] on [Unsplash][2] + +React 组件可以通过多种方式决定渲染内容。你可以使用传统的 if 语句或 switch 语句。在本文中,我们将探讨一些替代方案。但要注意,如果你不小心,有些方案会带来自己的陷阱。 + +### 三元表达式 vs if/else + +假设我们有一个组件被传进来一个 `name` prop。 如果这个字符串非空,我们会显示一个问候语。否则,我们会告诉用户他们需要登录。 + +这是一个只实现了如上功能的无状态函数式组件。 + +``` +const MyComponent = ({ name }) => { + if (name) { + return ( +
+ Hello {name} +
+ ); + } + return ( +
+ Please sign in +
+ ); +}; +``` + +这个很简单但是我们可以做得更好。这是使用三元运算符编写的相同组件。 + +``` +const MyComponent = ({ name }) => ( +
+ {name ? `Hello ${name}` : 'Please sign in'} +
+); +``` + +请注意这段代码与上面的例子相比是多么简洁。 + +有几点需要注意。因为我们使用了箭头函数的单语句形式,所以隐含了return语句。另外,使用三元运算符允许我们省略掉重复的 `
` 标记。🎉 + +### 三元表达式 vs && + +正如您所看到的,三元表达式用于表达 if/else 条件式非常好。但是对于简单的 if 条件式怎么样呢? + +让我们看另一个例子。如果 isPro(一个布尔值)为真,我们将显示一个奖杯表情符号。我们也要渲染星星的数量(如果不是0)。我们可以这样写。 + +``` +const MyComponent = ({ name, isPro, stars}) => ( +
+
+ Hello {name} + {isPro ? '🏆' : null} +
+ {stars ? ( +
+ Stars:{'⭐️'.repeat(stars)} +
+ ) : null} +
+); +``` + +请注意 “else” 条件返回 null 。 这是因为三元表达式要有"否则"条件。 + +对于简单的 “if” 条件式,我们可以使用更合适的东西:&& 运算符。这是使用 “&&” 编写的相同代码。 + +``` +const MyComponent = ({ name, isPro, stars}) => ( +
+
+ Hello {name} + {isPro && '🏆'} +
+ {stars && ( +
+ Stars:{'⭐️'.repeat(stars)} +
+ )} +
+); +``` + +没有太多区别,但是注意我们消除了每个三元表达式最后面的 `: null` (else 条件式)。一切都应该像以前一样渲染。 + + +嘿!约翰得到了什么?当什么都不应该渲染时,只有一个0。这就是我上面提到的陷阱。这里有解释为什么。 + +[根据 MDN][3],一个逻辑运算符“和”(也就是`&&`): + +> `expr1 && expr2` + +> 如果 `expr1` 可以被转换成 `false` ,返回 `expr1`;否则返回 `expr2`。 如此,当与布尔值一起使用时,如果两个操作数都是 true,`&&` 返回 `true` ;否则,返回 `false`。 + +好的,在你开始拔头发之前,让我为你解释它。 + +在我们这个例子里, `expr1` 是变量 `stars`,它的值是 `0`,因为0是 falsey 的值, `0` 会被返回和渲染。看,这还不算太坏。 + +我会简单地这么写。 + +> 如果 `expr1` 是 falsey,返回 `expr1` ,否则返回 `expr2` + +所以,当对非布尔值使用 “&&” 时,我们必须让 falsy 的值返回 React 无法渲染的东西,比如说,`false` 这个值。 + +我们可以通过几种方式实现这一目标。让我们试试吧。 + +``` +{!!stars && ( +
+ {'⭐️'.repeat(stars)} +
+)} +``` + +注意 `stars` 前的双感叹操作符( `!!`)(呃,其实没有双感叹操作符。我们只是用了感叹操作符两次)。 + +第一个感叹操作符会强迫 `stars` 的值变成布尔值并且进行一次“非”操作。如果 `stars` 是 `0` ,那么 `!stars` 会 是 `true`。 + +然后我们执行第二个`非`操作,所以如果 `stars` 是0,`!!stars` 会是 `false`。正好是我们想要的。 + +如果你不喜欢 `!!`,那么你也可以强制转换出一个布尔数比如这样(这种方式我觉得有点冗长)。 + +``` +{Boolean(stars) && ( +``` + +或者只是用比较符产生一个布尔值(有些人会说这样甚至更加语义化)。 + +``` +{stars > 0 && ( +``` + +#### 关于字符串 + +空字符串与数字有一样的毛病。但是因为渲染后的空字符串是不可见的,所以这不是那种你很可能会去处理的难题,甚至可能不会注意到它。然而,如果你是完美主义者并且不希望DOM上有空字符串,你应采取我们上面对数字采取的预防措施。 + +### 其它解决方案 + +一种可能的将来可扩展到其他变量的解决方案,是创建一个单独的 `shouldRenderStars` 变量。然后你用“&&”处理布尔值。 + +``` +const shouldRenderStars = stars > 0; +``` + +``` +return ( +
+ {shouldRenderStars && ( +
+ {'⭐️'.repeat(stars)} +
+ )} +
+); +``` + +之后,在将来,如果业务规则要求你还需要已登录,拥有一条狗以及喝淡啤酒,你可以改变 `shouldRenderStars` 的得出方式,而返回的内容保持不变。你还可以把这个逻辑放在其它可测试的地方,并且保持渲染明晰。 + +``` +const shouldRenderStars = + stars > 0 && loggedIn && pet === 'dog' && beerPref === 'light`; +``` + +``` +return ( +
+ {shouldRenderStars && ( +
+ {'⭐️'.repeat(stars)} +
+ )} +
+); +``` + +### 结论 + +我认为你应该充分利用这种语言。对于 JavaScript,这意味着为 `if/else` 条件式使用三元表达式,以及为 `if` 条件式使用 `&&` 操作符。 + +我们可以回到每处都使用三元运算符的舒适区,但你现在消化了这些知识和力量,可以继续前进 && 取得成功了。 + +-------------------------------------------------------------------------------- + +作者简介: + +美国运通工程博客的执行编辑 http://aexp.io 以及 @AmericanExpress 的工程总监。MyViews !== ThoseOfMyEmployer. + +---------------- + +via: https://medium.freecodecamp.org/conditional-rendering-in-react-using-ternaries-and-logical-and-7807f53b6935 + +作者:[Donavon West][a] +译者:[GraveAccent](https://github.com/GraveAccent) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://medium.freecodecamp.org/@donavon +[1]:https://unsplash.com/photos/pKeF6Tt3c08?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText +[2]:https://unsplash.com/search/photos/road-sign?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText +[3]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_Operators diff --git a/translated/tech/20180320 Migrating to Linux- Installing Software.md b/translated/tech/20180320 Migrating to Linux- Installing Software.md deleted file mode 100644 index 68a9939a9d..0000000000 --- a/translated/tech/20180320 Migrating to Linux- Installing Software.md +++ /dev/null @@ -1,85 +0,0 @@ -迁移到 Linux 之安装软件 -===== - -![](https://www.linux.com/sites/lcom/files/styles/rendered_file/public/birds-1835510_1920.jpg?itok=8i6mBStG) -你看到的所有有关 Linux 的关注,以及它在互联网,以及 Arduino, Beagle 和 Raspberry Pi boards(树莓派板)等设备上的使用,或许你正在考虑是时候尝试一下 Linux 了。本系列将帮助你成功过渡到 Linux。如果你错过了本系列的早期文章,可以在这里找到它们: - -[Part 1 - 介绍][1] - -[Part 2 - 磁盘、文件和文件系统][2] - -[Part 3 - 图形界面][3] - -[Part 4 - 命令行][4] - -[Part 5 - 使用 sudo][5] - -### 安装软件 - -要在你的计算机上获得新软件,通常的方法是从供应商处获得软件产品,然后运行一个安装程序。过去,软件产品会像 CD-ROM 或 DVD 一样出现在物理媒介上。而现在我们经常从网上下载软件产品。 - -使用 Linux,安装软件就像在你的智能手机上安装一样。就像去你的手机应用商店一样,在 Linux 上有个开源软件工具和程序的中央仓库,几乎任何你可能想要的程序都会在你可安装的可用软件包列表中。 - -没有为每个程序运行的单独安装程序。相反,你可以使用 Linux 发行版附带的软件包管理工具。(请记住,Linux 发行版是你安装的 Linux,例如 Ubuntu, Fedora, Debian 等)每个发行版在 Internet 上都有自己的集中位置(称为仓库),用于存储数千个预先安装的应用程序。 - -你可能会注意到,在 Linux 上安装软件有几个例外。有时候,你仍然需要去供应商处获取他们的软件,因为该程序不存在于你发行版的中央仓库中。当软件不是开源和/或免费(自由)的时候,通常就是这种情况。 - -另外请记住,如果你最终想要安装一个不在发行版仓库中的程序,事情就不是那么简单了,即使你正在安装免费(自由)和开源程序。这篇文章没有涉及到这些更复杂的情况,最好遵循在线引导。 - -有了所有的 Linux 包管理系统和工具,接下来干什么可能仍然令人困惑。本文应该有助于澄清一些事情。 - -### 包管理 - -一些用于管理、安装和删除软件的包管理系统在 Linux 发行版中竞争。那个发行版背后的人都选择一个包管理系统来使用。Red Hat, Fedora, CentOS, Scientific Linux, SUSE 等使用 Red Hat 包管理(RPM)。Debian, Ubuntu, Linux Mint 等等都使用 Debian 包管理系统,简称 DPKG。其他包管理系统也存在,但 RPM 和 DPKG 是最常见的。 - -![](https://www.linux.com/sites/lcom/files/styles/floated_images/public/package-installer.png?itok=V9OU1Q0u) -图 1: Package installers - -无论你使用的软件包管理是什么,它们通常都附带一组工具,它们是分层的(图 1)。最底层是一个命令行工具,它可以让你做任何事情以及与安装软件相关的一切。你可以列出已安装的程序,删除程序,安装软件包文件等等。 - -这个底层工具并不总是最方便使用的,所以通常会有一个命令行工具,它可以在发行版的中央仓库中找到软件包,并使用单个命令下载和安装它以及任何依赖项。最后,通常会有一个图形应用程序,让你使用鼠标选择任何想要的内容,然后单击 “install” 按钮。 -![](https://www.linux.com/sites/lcom/files/styles/rendered_file/public/package-kit.png?itok=YimOq2Je) -图 2: PackageKit - -对于基于 Red Hat 的发行版,包括 Fedora, CentOS, Scientific Linux 等。它们的底层工具是 rpm,高级工具叫做 dnf(在旧系统上是 yum)。图形安装程序称为 PackageKit(图 2),它可能在系统管理下显示为 “Add/Remove Software(添加/删除软件)”。 -![](https://www.linux.com/sites/lcom/files/styles/rendered_file/public/ubuntu-software.png?itok=5QSctLEW) -图 3: Ubuntu Software - -对于基于 Debian 的发行版,包括 Debian, Ubuntu, Linux Mint, Elementary OS 等。它们的底层命令行工具是 dpkg,高级工具称为 apt。在 Ubuntu 上管理已安装软件的图形工具是 Ubuntu Software(图 3)。对于 Debian 和 Linux Mint,图形工具称为 Synaptic,它也可以安装在 Ubuntu 上。 - -你也可以在 Debian 相关发行版上安装基于文本的图形工具 aptitude。它比 Synaptic(新立得)更强大,并且即使你只能访问命令行也能工作。如果你想获得所有花里胡哨的东西,(to 校正者:这句话仔细考虑一下)你可以试试那个,尽管有更多的选择,但使用起来比 Synaptic(新立得)更复杂。其他发行版可能有自己独特的工具。 - -### 命令行工具 - -在 Linux 上安装软件的在线说明通常描述在命令行中键入的命令。这些指令通常更容易理解,并且可以在不出错的情况下,将命令复制粘贴到命令行窗口中。这与下面的说明相反:“打开这个菜单,选择这个程序,输入这个搜索模式,点击这个标签,选择这个程序,然后点击这个按钮”,这经常在翻译中丢失。 - -有时你正在使用的 Linux 没有图形环境,因此熟悉从命令行安装软件包是件好事。表 1 和表 2 列出了基于 RPM 和 DPKG 系统的一下常见操作及其相关命令。 - -![](https://www.linux.com/sites/lcom/files/styles/rendered_file/public/table_1_0.png?itok=hQ_o5Oh2) - -![](https://www.linux.com/sites/lcom/files/styles/rendered_file/public/table_2.png?itok=yl3UPQDw) - -请注意 SUSE,它像 RedHat 和 Fedora 一样使用 RPM,却没有 dnf 或 yum。相反,它使用一个名为 zypper 的程序作为高级命令行工具。其他发行版也可能有不同的工具,例如 Arch Linux 上的 pacman 或 Gentoo 上的 emerge。有很多包工具,所以你可能需要查找哪个适用于你的发行版。 - -这些技巧应该能让你更好地了解如何在新的 Linux 中安装程序,以及更好地了解 Linux 中各种软件包方法如何相互关联。 - -通过 Linux 基金会和 edX 的免费 [“Linux 入门”][6]课程了解有关 Linux 的更多信息。 - - --------------------------------------------------------------------------------- - -via: https://www.linux.com/blog/learn/2018/3/migrating-linux-installing-software - -作者:[JOHN BONESIO][a] -译者:[MjSeven](https://github.com/MjSeven) -校对:[校对者ID](https://github.com/校对者ID) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 - -[a]:https://www.linux.com/users/johnbonesio -[1]:https://www.linux.com/blog/learn/intro-to-linux/2017/10/migrating-linux-introduction -[2]:https://www.linux.com/blog/learn/intro-to-linux/2017/11/migrating-linux-disks-files-and-filesystems -[3]:https://www.linux.com/blog/learn/2017/12/migrating-linux-graphical-environments -[4]:https://www.linux.com/blog/learn/2018/1/migrating-linux-command-line -[5]:https://www.linux.com/blog/learn/2018/3/migrating-linux-using-sudo -[6]:https://training.linuxfoundation.org/linux-courses/system-administration-training/introduction-to-linux diff --git a/translated/tech/20180429 Passwordless Auth- Client.md b/translated/tech/20180429 Passwordless Auth- Client.md deleted file mode 100644 index e2faf2cb6e..0000000000 --- a/translated/tech/20180429 Passwordless Auth- Client.md +++ /dev/null @@ -1,338 +0,0 @@ -无密码验证:客户端 -====== -我们继续 [无密码验证][1] 的文章。上一篇文章中,我们用 Go 写了一个 HTTP 服务,用这个服务来做无密码验证 API。今天,我们为它再写一个 JavaScript 客户端。 - -我们将使用 [这里的][2] 这个单页面应用程序(SPA)来展示使用的技术。如果你还没有读过它,请先读它。 - -我们将根据验证的状态分别使用两个不同的根 URL(`/`):一个是访问状态的页面或者是欢迎已验证用户的页面。另一个页面是验证失败后重定向到验证页面。 - -### Serving - -我们将使用相同的 Go 服务器来为客户端提供服务,因此,在我们前面的 `main.go` 中添加一些路由: -``` -router.Handle("GET", "/js/", http.FileServer(http.Dir("static"))) -router.HandleFunc("GET", "/...", serveFile("static/index.html")) - -``` - -这个伺服文件在 `static/js` 下,而 `static/index.html` 文件是为所有的访问提供服务的。 - -你可以使用你自己的服务器,但是你得在服务器上启用 [CORS][3]。 - -### HTML - -我们来看一下那个 `static/index.html` 文件。 -``` - - - - - - Passwordless Demo - - - - - - -``` - -单页面应用程序剩余的渲染由 JavaScript 来完成,因此,我们使用了一个空的 body 部分和一个 `main.js` 文件。 - -我们将使用 [上篇文章][2] 中的 Router。 - -### Rendering - -现在,我们使用下面的内容来创建一个 `static/js/main.js` 文件: -``` -import Router from 'https://unpkg.com/@nicolasparada/router' -import { isAuthenticated } from './auth.js' - -const router = new Router() - -router.handle('/', guard(view('home'))) -router.handle('/callback', view('callback')) -router.handle(/^\//, view('not-found')) - -router.install(async resultPromise => { - document.body.innerHTML = '' - document.body.appendChild(await resultPromise) -}) - -function view(name) { - return (...args) => import(`/js/pages/${name}-page.js`) - .then(m => m.default(...args)) -} - -function guard(fn1, fn2 = view('welcome')) { - return (...args) => isAuthenticated() - ? fn1(...args) - : fn2(...args) -} - -``` - -与上篇文章不同的是,我们实现了一个 `isAuthenticated()` 函数和一个 `guard()` 函数,使用它去渲染两种验证状态的页面。因此,当用户访问 `/` 时,它将根据用户是否通过了验证来展示 home 页面或者是欢迎页面。 - -### Auth - -现在,我们来编写 `isAuthenticated()` 函数。使用下面的内容来创建一个 `static/js/auth.js` 文件: -``` -export function getAuthUser() { - const authUserItem = localStorage.getItem('auth_user') - const expiresAtItem = localStorage.getItem('expires_at') - - if (authUserItem !== null && expiresAtItem !== null) { - const expiresAt = new Date(expiresAtItem) - - if (!isNaN(expiresAt.valueOf()) && expiresAt > new Date()) { - try { - return JSON.parse(authUserItem) - } catch (_) { } - } - } - - return null -} - -export function isAuthenticated() { - return localStorage.getItem('jwt') !== null && getAuthUser() !== null -} - -``` - -当有人登入时,我们将保存 JSON 格式的 web 令牌、过期日期、以及在 `localStorage` 上的当前已验证用户。这个模块就是这个用处。 - - * `getAuthUser()` 用于从 `localStorage` 获取已认证的用户,以确认 JSON 格式的 Web 令牌没有过期。 - * `isAuthenticated()` 在前面的函数中用于去检查它是否返回了 `null`。 - - - -### Fetch - -在继续这个页面之前,我将写一些与服务器 API 一起使用的 HTTP 工具。 - -我们使用以下的内容去创建一个 `static/js/http.js` 文件: -``` -import { isAuthenticated } from './auth.js' - -function get(url, headers) { - return fetch(url, { - headers: Object.assign(getAuthHeader(), headers), - }).then(handleResponse) -} - -function post(url, body, headers) { - return fetch(url, { - method: 'POST', - headers: Object.assign(getAuthHeader(), { 'content-type': 'application/json' }, headers), - body: JSON.stringify(body), - }).then(handleResponse) -} - -function getAuthHeader() { - return isAuthenticated() - ? { authorization: `Bearer ${localStorage.getItem('jwt')}` } - : {} -} - -export async function handleResponse(res) { - const body = await res.clone().json().catch(() => res.text()) - const response = { - url: res.url, - statusCode: res.status, - statusText: res.statusText, - headers: res.headers, - body, - } - if (!res.ok) throw Object.assign( - new Error(body.message || body || res.statusText), - response - ) - return response -} - -export default { - get, - post, -} - -``` - -这个模块导出了 `get()` 和 `post()` 函数。它们是 `fetch` API 的封装。当用户是已验证的,这二个函数注入一个 `Authorization: Bearer ` 头到请求中;这样服务器就能对我们进行身份验证。 - -### Welcome Page - -我们现在来到欢迎页面。用如下的内容创建一个 `static/js/pages/welcome-page.js` 文件: -``` -const template = document.createElement('template') -template.innerHTML = ` -

Passwordless Demo

-

Access

-
- - -
-` - -export default function welcomePage() { - const page = template.content.cloneNode(true) - - page.getElementById('access-form') - .addEventListener('submit', onAccessFormSubmit) - - return page -} - -``` - -正如你所见,这个页面使用一个 `HTMLTemplateElement`。这是一个只输入用户 email 的简单表格。 - -为了不让代码太乏味,我将跳过错误处理部分,只是将它们输出到控制台上。 - -现在,我们来写 `onAccessFormSubmit()` 函数。 -``` -import http from '../http.js' - -function onAccessFormSubmit(ev) { - ev.preventDefault() - - const form = ev.currentTarget - const input = form.querySelector('input') - const email = input.value - - sendMagicLink(email).catch(err => { - console.error(err) - if (err.statusCode === 404 && wantToCreateAccount()) { - runCreateUserProgram(email) - } - }) -} - -function sendMagicLink(email) { - return http.post('/api/passwordless/start', { - email, - redirectUri: location.origin + '/callback', - }).then(() => { - alert('Magic link sent. Go check your email inbox.') - }) -} - -function wantToCreateAccount() { - return prompt('No user found. Do you want to create an account?') -} - -``` - -它使用 email 做了一个 `POST` 请求到 `/api/passwordless/start`,然后在 body 中做了 URI 转向。在本例中使用 `404 Not Found` 状态码返回,我们将创建一个用户。 -``` -function runCreateUserProgram(email) { - const username = prompt("Enter username") - if (username === null) return - - http.post('/api/users', { email, username }) - .then(res => res.body) - .then(user => sendMagicLink(user.email)) - .catch(console.error) -} - -``` - -这个用户创建程序,首先询问用户名,然后使用 email 和用户名,在 body 中做一个 `POST` 请求到 `/api/users`。成功之后,给创建的用户发送一个魔法链接。 - -### Callback Page - -这就是访问表格的所有功能,现在我们来做回调页面。使用如下的内容来创建一个 `static/js/pages/callback-page.js` 文件: -``` -import http from '../http.js' - -const template = document.createElement('template') -template.innerHTML = ` -

Authenticating you 👀

-` - -export default function callbackPage() { - const page = template.content.cloneNode(true) - - const hash = location.hash.substr(1) - const fragment = new URLSearchParams(hash) - for (const [k, v] of fragment.entries()) { - fragment.set(decodeURIComponent(k), decodeURIComponent(v)) - } - const jwt = fragment.get('jwt') - const expiresAt = fragment.get('expires_at') - - http.get('/api/auth_user', { authorization: `Bearer ${jwt}` }) - .then(res => res.body) - .then(authUser => { - localStorage.setItem('jwt', jwt) - localStorage.setItem('auth_user', JSON.stringify(authUser)) - localStorage.setItem('expires_at', expiresAt) - - location.replace('/') - }) - .catch(console.error) - - return page -} - -``` - -请记住 … 当点击魔法链接时,我们来到 `/api/passwordless/verify_redirect`,我们通过 (`/callback`)在 URL 的哈希中传递 JWT 和过期日期,将我们转向到重定向 URI。 - -回调页面解码 URL 中的哈希,提取这些参数去做一个 `GET` 请求到 `/api/auth_user`,用 JWT 保存所有数据到 `localStorage` 中。最后,重定向到主页面。 - -### Home Page - -创建如下内容的 `static/pages/home-page.js` 文件: -``` -import { getAuthUser } from '../auth.js' - -export default function homePage() { - const authUser = getAuthUser() - - const template = document.createElement('template') - template.innerHTML = ` -

Passwordless Demo

-

Welcome back, ${authUser.username} 👋

- - ` - - const page = template.content - - page.getElementById('logout-button') - .addEventListener('click', logout) - - return page -} - -function logout() { - localStorage.clear() - location.reload() -} - -``` - -这个页面欢迎已验证用户,同时也有一个登出按钮。`logout()` 函数的功能只是清理掉 `localStorage` 并重载这个页面。 - -这就是全部内容了。我敢说你在此之前已经看过这个 [demo][4] 了。当然,这些源代码也在同一个 [仓库][5] 中。 - -👋👋👋 - --------------------------------------------------------------------------------- - -via: https://nicolasparada.netlify.com/posts/passwordless-auth-client/ - -作者:[Nicolás Parada][a] -选题:[lujun9972](https://github.com/lujun9972) -译者:[qhwdw](https://github.com/qhwdw) -校对:[校对者ID](https://github.com/校对者ID) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 - -[a]:https://nicolasparada.netlify.com/ -[1]:https://nicolasparada.netlify.com/posts/passwordless-auth-server/ -[2]:https://nicolasparada.netlify.com/posts/javascript-client-router/ -[3]:https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS -[4]:https://go-passwordless-demo.herokuapp.com/ -[5]:https://github.com/nicolasparada/go-passwordless-demo diff --git a/translated/tech/20180522 Free Resources for Securing Your Open Source Code.md b/translated/tech/20180522 Free Resources for Securing Your Open Source Code.md new file mode 100644 index 0000000000..4e63a64e43 --- /dev/null +++ b/translated/tech/20180522 Free Resources for Securing Your Open Source Code.md @@ -0,0 +1,83 @@ +一些提高你开源源码安全性的工具 +====== + +![](https://www.linux.com/sites/lcom/files/styles/rendered_file/public/open-security.jpg?itok=R3M5LDrb) + +虽然目前开源依然发展势头较好,并被广大的厂商所采用,然而最近由 Black Duck 和 Synopsys 发布的[2018开源安全与风险评估报告][1]指出了一些存在的风险并重点阐述了对于健全安全措施的需求。这份报告的分析资料素材来自经过脱敏后的 1100 个商业代码库,这些代码所涉及:自动化、大数据、企业级软件、金融服务业、健康医疗、物联网、制造业等多个领域。 + +这份报告强调开源软件正在被大量的使用,扫描结果中有 96% 的应用都使用了开源组件。然而,报告还指出许多其中存在很多漏洞。具体在 [这里][2]: + + * 令人担心的是扫描的所有结果中,有 78% 的代码库存在至少一个开源的漏洞,平均每个代码库有 64 个漏洞。 + + * 在经过代码审计过后代码库中,发现超过 54% 的漏洞经验证是高危漏洞。 + + * 17% 的代码库包括一种已经早已公开的漏洞,包括:Heartbleed、Logjam、Freak、Drown、Poddle。 + + + + +Tim Mackey,Synopsys 旗下 Black Duck 的技术负责人称,"这份报告清楚的阐述了:随着开源软件正在被企业广泛的使用,企业与组织也应当使用一些工具来检测可能出现在这些开源软件中的漏洞,并且管理其所使用的开源软件的方式是否符合相应的许可证规则" + +确实,随着越来越具有影响力的安全威胁出现,历史上从未有过我们目前对安全工具和实践的需求。大多数的组织已经意识到网络与系统管理员需要具有相应的较强的安全技能和安全证书。[在这篇文章中,][3] 我们给出一些具有较大影响力的工具、认证和实践。 + +Linux 基金会已经在安全方面提供了许多关于安全的信息与教育资源。比如,Linux 社区提供许多免费的用来针对一些平台的工具,其中[Linux 服务器安全检查表][4] 其中提到了很多有用的基础信息。线上的一些发表刊物也可以提升用户针对某些平台对于漏洞的保护,如:[Fedora 安全指南][5],[Debian 安全手册][6]。 + +目前被广泛使用的私有云平台 OpenStack 也加强了关于基于云的智能安全需求。根据 Linux 基金会发布的 [公有云指南][7]:“据 Gartner 的调研结果,尽管公有云的服务商在安全和审查方面做的都还不错,安全问题是企业考虑向公有云转移的最重要的考量之一” + +无论是对于组织还是个人,千里之堤毁于蚁穴,这些“蚁穴”无论是来自路由器、防火墙、VPNs或虚拟机都可能导致灾难性的后果。以下是一些免费的工具可能对于检测这些漏洞提供帮助: + + * [Wireshark][8], 流量包分析工具 + + * [KeePass Password Safe][9], 免费开源的密码管理器 + + * [Malwarebytes][10], 免费的反病毒和勒索软件工具 + + * [NMAP][11], 安全扫描器 + + * [NIKTO][12], 开源 web 扫描器 + + * [Ansible][13], 自动化的配置运维工具,可以辅助做安全基线 + + * [Metasploit][14], 渗透测试工具,可辅助理解攻击向量 + + + +这里有一些对上面工具讲解的视频。比如[Metasploit 教学][15]、[Wireshark 教学][16]。还有一些传授安全技能的免费电子书,比如:由 Ibrahim Haddad 博士和 Linux 基金会共同出版的[并购过程中的开源审计][17],里面阐述了多条在技术平台合并过程中,因没有较好的进行开源审计,从而引发的安全问题。当然,书中也记录了如何在这一过程中进行代码合规检查、准备以及文档编写。 + +同时,我们 [之前提到的一个免费的电子书][18], 由来自[The New Stack][19] 编写的“Docker与容器中的网络、安全和存储”,里面也提到了关于加强容器网络安全的最新技术,以及Docker本身可提供的关于,提升其网络的安全与效率的最佳实践。这本电子书还记录了关于如何构建安全容器集群的最佳实践。 + +所有这些工具和资源,可以在很大的程度上预防安全问题,正如人们所说的未雨绸缪,考虑到一直存在的安全问题,现在就应该开始学习这些安全合规资料与工具。 +想要了解更多的安全、合规以及开源项目问题,点击[这里][20] + +-------------------------------------------------------------------------------- + +via: https://www.linux.com/blog/2018/5/free-resources-securing-your-open-source-code + +作者:[Sam Dean][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/sd886393) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.linux.com/users/sam-dean +[1]:https://www.blackducksoftware.com/open-source-security-risk-analysis-2018 +[2]:https://www.prnewswire.com/news-releases/synopsys-report-finds-majority-of-software-plagued-by-known-vulnerabilities-and-license-conflicts-as-open-source-adoption-soars-300648367.html +[3]:https://www.linux.com/blog/sysadmin-ebook/2017/8/future-proof-your-sysadmin-career-locking-down-security +[4]:http://go.linuxfoundation.org/ebook_workstation_security +[5]:https://docs.fedoraproject.org/en-US/Fedora/19/html/Security_Guide/index.html +[6]:https://www.debian.org/doc/manuals/securing-debian-howto/index.en.html +[7]:https://www.linux.com/publications/2016-guide-open-cloud +[8]:https://www.wireshark.org/ +[9]:http://keepass.info/ +[10]:https://www.malwarebytes.com/ +[11]:http://searchsecurity.techtarget.co.uk/tip/Nmap-tutorial-Nmap-scan-examples-for-vulnerability-discovery +[12]:https://cirt.net/Nikto2 +[13]:https://www.ansible.com/ +[14]:https://www.metasploit.com/ +[15]:http://www.computerweekly.com/tutorial/The-Metasploit-Framework-Tutorial-PDF-compendium-Your-ready-reckoner +[16]:https://www.youtube.com/watch?v=TkCSr30UojM +[17]:https://www.linuxfoundation.org/resources/open-source-audits-merger-acquisition-transactions/ +[18]:https://www.linux.com/news/networking-security-storage-docker-containers-free-ebook-covers-essentials +[19]:http://thenewstack.io/ebookseries/ +[20]:https://www.linuxfoundation.org/projects/security-compliance/ diff --git a/translated/tech/20180528 What is behavior-driven Python.md b/translated/tech/20180528 What is behavior-driven Python.md new file mode 100644 index 0000000000..16edc3c802 --- /dev/null +++ b/translated/tech/20180528 What is behavior-driven Python.md @@ -0,0 +1,237 @@ +什么是行为驱动的Python? +====== +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/checklist_hands_team_collaboration.png?itok=u82QepPk) + +您是否听说过[行为驱动开发][1](BDD),并想知道所有的新奇事物是什么? 也许你已经发现了团队成员在使用“gherkin”了,并感到被排除在外无法参与其中。 或许你是一个Python爱好者,正在寻找更好的方法来测试你的代码。 无论在什么情况下,了解BDD都可以帮助您和您的团队实现更好的协作和测试自动化,而Python的`行为`框架是一个很好的起点。 + +### 什么是BDD? + + * 在网站上提交表单 + * 搜索想要的结果 + * 保存文档 + * 进行REST API调用 + * 运行命令行界面命令 + +在软件中,行为是指在明确定义的输入,行为和结果场景中功能是如何运转的。 产品可以表现出无数的行为,例如: + +根据产品的行为定义产品的功能可以更容易地描述产品,并对其进行开发和测试。 BDD的核心是:使行为成为软件开发的焦点。 在开发早期使用示例语言的规范来定义行为。 最常见的行为规范语言之一是Gherkin,Cucumber项目中的Given-When-Then场景格式。 行为规范基本上是对行为如何工作的简单语言描述,具有一致性和焦点的一些正式结构。 通过将步骤文本“粘合”到代码实现,测试框架可以轻松地自动化这些行为规范。 + +下面是用Gherkin编写的行为规范的示例: + +根据产品的行为定义产品的功能可以更容易地描述产品,开发产品并对其进行测试。 这是BDD的核心:使行为成为软件开发的焦点。 在开发早期使用[示例规范][2]的语言来定义行为。 最常见的行为规范语言之一是[Gherkin][3],[Cucumber][4]项目中的Given-When-Then场景格式。 行为规范基本上是对行为如何工作的简单语言描述,具有一致性和焦点的一些正式结构。 通过将步骤文本“粘合”到代码实现,测试框架可以轻松地自动化这些行为规范。 + +下面是用Gherkin编写的行为规范的示例: + +``` +Scenario: Basic DuckDuckGo Search + Given the DuckDuckGo home page is displayed + When the user searches for "panda" + Then results are shown for "panda" +``` + +快速浏览一下,行为是直观易懂的。 除少数关键字外,该语言为自由格式。 场景简洁而有意义。 一个真实的例子说明了这种行为。 步骤以声明的方式表明应该发生什么——而不会陷入如何如何的细节中。 + +[BDD的主要优点][5]是良好的协作和自动化。 每个人都可以为行为开发做出贡献,而不仅仅是程序员。 从流程开始就定义并理解预期的行为。 测试可以与它们涵盖的功能一起自动化。 每个测试都包含一个单一的,独特的行为,以避免重复。 最后,现有的步骤可以通过新的行为规范重用,从而产生雪球效果。 + +### Python的behave框架 + +`behave`是Python中最流行的BDD框架之一。 它与其他基于Gherkin的Cucumber框架非常相似,尽管没有得到官方的Cucumber定名。 `behave`有两个主要层: + +1. 用Gherkin的`.feature`文件编写的行为规范 +2. 用Python模块编写的步骤定义和钩子,用于实现Gherkin步骤 + +如上例所示,Gherkin场景有三部分格式: + +1. 鉴于一些初始状态 +2. 当行为发生时 +3. 然后验证结果 + +当`behave`运行测试时,每个步骤由装饰器“粘合”到Python函数。 + +### 安装 + +作为先决条件,请确保在你的计算机上安装了Python和`pip`。 我强烈建议使用Python 3.(我还建议使用[`pipenv`][6],但以下示例命令使用更基本的`pip`。) + +`behave`框架只需要一个包: + +``` +pip install behave +``` + +其他包也可能有用,例如: +``` +pip install requests    # 用于调用REST API +pip install selenium    # 用于web浏览器交互 +``` + +GitHub上的[behavior-driven-Python][7]项目包含本文中使用的示例。 + +### Gherkin特点 + +`behave`框架使用的Gherkin语法实际上是符合官方的Cucumber Gherkin标准的。 `.feature`文件包含功能Feature部分,而Feature部分又包含具有Given-When-Then步骤的场景Scenario部分。 以下是一个例子: + +``` +Feature: Cucumber Basket +  As a gardener, +  I want to carry many cucumbers in a basket, +  So that I don’t drop them all. + +  @cucumber-basket +  Scenario: Add and remove cucumbers +    Given the basket is empty +    When "4" cucumbers are added to the basket +    And "6" more cucumbers are added to the basket +    But "3" cucumbers are removed from the basket +    Then the basket contains "7" cucumbers +``` + +这里有一些重要的事情需要注意: + +- Feature和Scenario部分都有[简短的描述性标题][8]。 +- 紧跟在Feature标题后面的行是会被`behave`框架忽略掉的注释。将功能描述放在那里是一种很好的做法。 +- Scenarios和Features可以有标签(注意`@cucumber-basket`标记)用于钩子和过滤(如下所述)。 +- 步骤都遵循[严格的Given-When-Then顺序][9]。 +- 使用`And`和`Bu`t可以为任何类型添加附加步骤。 +- 可以使用输入对步骤进行参数化——注意双引号里的值。 + +通过使用场景大纲,场景也可以写为具有多个输入组合的模板: + +``` +Feature: Cucumber Basket + + @cucumber-basket + Scenario Outline: Add cucumbers + Given the basket has “” cucumbers + When "" cucumbers are added to the basket + Then the basket contains "" cucumbers + + Examples: Cucumber Counts + | initial | more | total | + | 0 | 1 | 1 | + | 1 | 2 | 3 | + | 5 | 4 | 9 | +``` + +场景大纲总是有一个Examples表,其中第一行给出列标题,后续每一行给出一个输入组合。 只要列标题出现在由尖括号括起的步骤中,行值就会被替换。 在上面的示例中,场景将运行三次,因为有三行输入组合。 场景大纲是避免重复场景的好方法。 + +Gherkin语言还有其他元素,但这些是主要的机制。 想了解更多信息,请阅读Automation Panda这个网站的文章[Gherkin by Example][10]和[Writing Good Gherkin][11]。 + +### Python机制 + +每个Gherkin步骤必须“粘合”到步骤定义,即提供了实现的Python函数。 每个函数都有一个带有匹配字符串的步骤类型装饰器。 它还接收共享的上下文和任何步骤参数。 功能文件必须放在名为`features/`的目录中,而步骤定义模块必须放在名为`features/steps/`的目录中。 任何功能文件都可以使用任何模块中的步骤定义——它们不需要具有相同的名称。 下面是一个示例Python模块,其中包含cucumber basket功能的步骤定义。 + +``` +from behave import * +from cucumbers.basket import CucumberBasket + +@given('the basket has "{initial:d}" cucumbers') +def step_impl(context, initial): + context.basket = CucumberBasket(initial_count=initial) + +@when('"{some:d}" cucumbers are added to the basket') +def step_impl(context, some): + context.basket.add(some) + +@then('the basket contains "{total:d}" cucumbers') +def step_impl(context, total): + assert context.basket.count == total +``` + +可以使用三个[步骤匹配器][12]:`parse`,`cfparse`和`re`。默认和最简单的匹配器是`parse`,如上例所示。注意如何解析参数化值并将其作为输入参数传递给函数。一个常见的最佳实践是在步骤中给参数加双引号。 + +每个步骤定义函数还接收一个[上下文][13]变量,该变量保存当前正在运行的场景的数据,例如`feature`, `scenario`和`tags`字段。也可以添加自定义字段,用于在步骤之间共享数据。始终使用上下文来共享数据——永远不要使用全局变量! + +`behave`框架还支持[钩子][14]来处理Gherkin步骤之外的自动化问题。钩子是一个将在步骤,场景,功能或整个测试套件之前或之后运行的功能。钩子让人联想到[面向方面的编程][15]。它们应放在`features/`目录下的特殊`environment.py`文件中。钩子函数也可以检查当前场景的标签,因此可以有选择地应用逻辑。下面的示例显示了如何使用钩子为标记为`@web`的任何场景生成和销毁一个Selenium WebDriver实例。 + +``` +from selenium import webdriver + +def before_scenario(context, scenario): + if 'web' in context.tags: + context.browser = webdriver.Firefox() + context.browser.implicitly_wait(10) + +def after_scenario(context, scenario): + if 'web' in context.tags: + context.browser.quit() +``` + +注意:也可以使用[fixtures][16]进行构建和清理。 + +要了解一个`behave`项目应该是什么样子,这里是示例项目的目录结构: + +![](https://opensource.com/sites/default/files/uploads/behave_dir_layout.png) + +任何Python包和自定义模块都可以与`behave`框架一起使用。 使用良好的设计模式构建可扩展的测试自动化解决方案。步骤定义代码应简明扼要。 + +### 运行测试 + +要从命令行运行测试,请切换到项目的根目录并运行`behave`命令。 使用`-help`选项查看所有可用选项。 + +以下是一些常见用例: + +``` +# run all tests +behave + +# run the scenarios in a feature file +behave features/web.feature + +# run all tests that have the @duckduckgo tag +behave --tags @duckduckgo + +# run all tests that do not have the @unit tag +behave --tags ~@unit + +# run all tests that have @basket and either @add or @remove +behave --tags @basket --tags @add,@remove +``` + +为方便起见,选项可以保存在[config][17]文件中。 + +### 其他选择 + +`behave`不是Python中唯一的BDD测试框架。其他好的框架包括: + +- `pytest-bdd`,`pytest`的插件,和`behave`一样,它使用Gherkin功能文件和步骤定义模块,但它也利用了`pytest`的所有功能和插件。例如,它可以使用`pytest-xdist`并行运行Gherkin场景。 BDD和非BDD测试也可以与相同的过滤器一起执行。 `pytest-bdd`还提供更灵活的目录布局。 +- `radish`是一个“Gherkin增强版”框架——它将Scenario循环和前提条件添加到标准的Gherkin语言中,这使得它对程序员更友好。它还提供丰富的命令行选项,如`behave`。 +- `lettuce`是一种较旧的BDD框架,与`behave`非常相似,在框架机制方面存在细微差别。然而,GitHub最近显示该项目的活动很少(截至2018年5月)。 + +任何这些框架都是不错的选择。 + +另外,请记住,Python测试框架可用于任何黑盒测试,即使对于非Python产品也是如此! BDD框架非常适合Web和服务测试,因为它们的测试是声明性的,而Python是一种[很好的测试自动化语言][18]。 + +本文基于作者的[PyCon Cleveland 2018][19]演讲,[行为驱动的Python][20]。 + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/5/behavior-driven-python + +作者:[Andrew Knight][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[Flowsnow](https://github.com/Flowsnow) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://opensource.com/users/andylpk247 +[1]:https://automationpanda.com/bdd/ +[2]:https://en.wikipedia.org/wiki/Specification_by_example +[3]:https://automationpanda.com/2017/01/26/bdd-101-the-gherkin-language/ +[4]:https://cucumber.io/ +[5]:https://automationpanda.com/2017/02/13/12-awesome-benefits-of-bdd/ +[6]:https://docs.pipenv.org/ +[7]:https://github.com/AndyLPK247/behavior-driven-python +[8]:https://automationpanda.com/2018/01/31/good-gherkin-scenario-titles/ +[9]:https://automationpanda.com/2018/02/03/are-gherkin-scenarios-with-multiple-when-then-pairs-okay/ +[10]:https://automationpanda.com/2017/01/27/bdd-101-gherkin-by-example/ +[11]:https://automationpanda.com/2017/01/30/bdd-101-writing-good-gherkin/ +[12]:http://behave.readthedocs.io/en/latest/api.html#step-parameters +[13]:http://behave.readthedocs.io/en/latest/api.html#detecting-that-user-code-overwrites-behave-context-attributes +[14]:http://behave.readthedocs.io/en/latest/api.html#environment-file-functions +[15]:https://en.wikipedia.org/wiki/Aspect-oriented_programming +[16]:http://behave.readthedocs.io/en/latest/api.html#fixtures +[17]:http://behave.readthedocs.io/en/latest/behave.html#configuration-files +[18]:https://automationpanda.com/2017/01/21/the-best-programming-language-for-test-automation/ +[19]:https://us.pycon.org/2018/ +[20]:https://us.pycon.org/2018/schedule/presentation/87/ diff --git a/translated/tech/20180615 4 tools for building embedded Linux systems.md b/translated/tech/20180615 4 tools for building embedded Linux systems.md deleted file mode 100644 index 8845badac3..0000000000 --- a/translated/tech/20180615 4 tools for building embedded Linux systems.md +++ /dev/null @@ -1,212 +0,0 @@ -4种用于构建嵌入式Linux系统的工具 -====== -![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/desk_clock_job_work.jpg?itok=Nj4fuhl6) - - - Linux被部署到比Linus Torvalds在他的宿舍里工作时所预期的更广泛的设备。对各种芯片的支持是令人震惊的,使得Linux应用在大大小小的设备上: -从[IBM的巨型机][1]到[微型设备][2],没有比他们的连接端口和其间的任何东西都大。它被用于大型企业数据中心,互联网基础设施设备和个人开发系统。 -它还为消费电子产品、移动电话和许多物联网设备提供动力。 - - 在为桌面和企业级设备构建Linux软件时,开发者典型的在他们的构建机器上使用桌面发行版,如[Ubuntu][3] 以便尽可能与被部署的机器相似。工具 -如[VirtualBox][4] and [Docker][5]使得开发测试和生成环境更好的保持一致 - -### 什么是嵌入式系统? - - 维基百科将[嵌入式系统] [6]定义为:“在更大的机械或电气系统中具有专用功能的计算机系统,往往伴随着实时计算限制。 - 我觉得很简单,可以说嵌入式系统是大多数人不认为是计算机的计算机。它的主要作用是作为某种设备,它不被视为通用计算平台。 - - 嵌入式系统编程中的开发环境通常与测试和生产环境大不相同。他们可能会使用不同的芯片架构,软件堆栈甚至操作系统。开发工作流程对于嵌入式开发 -人员与桌面和Web开发人员来说是非常不同通常,构建输出将包含目标设备的整个软件映像,包括内核,设备驱动程序,库和应用程序软件(有时也包括引导 -加载程序)。 - - 在本文中,我将对构建嵌入式Linux系统的四种常用选项进行纵览。我将介绍一下每种产品的工作原理,并提供足够的信息来帮助读者确定使用哪种工具 -进行设计。我不会教你如何使用它们中的任何一个;一旦缩小了选择范围,就有大量深入的在线学习资源。没有任何选择适用于所有用例,我希望提供足够的 -细节来指导您的决定。 -### Yocto - - [Yocto] [7]项目[定义] [8]是:一个开源协作项目,提供模板,工具和方法,帮助您为嵌入式产品创建定制的基于Linux的系统,而不管硬件架构如何。 -它是用于创建定制的Linux运行时映像的配方,配置值和依赖关系的集合,可根据您的特定需求进行定制。 -完全公开:我在嵌入式Linux中的大部分工作都集中在Yocto项目上,而且我对这个系统的认识和偏见可能很明显。 -Yocto使用[Openembedded] [9]作为其构建系统。从技术上讲,这两个是独立的项目;然而,在实践中,用户不需要了解区别,项目名称经常可以互换使用。 - -Yocto项目的输出大致由三部分组成: - -  * **目标运行时二进制文件:**这些包括引导加载程序,内核,内核模块,根文件系统映像。以及将Linux部署到目标平台所需的任何其他辅助文件。 -  * **包流:**这是可以安装在目标上的软件包集合。您可以根据需要选择软件包格式(例如,deb,rpm,ipk)。其中一些可能预先安装在目标运行时 -二进制文件中,但可以构建用于安装到已部署系统的软件包。 -  * **目标SDK:**这些是表示安装在目标上的软件的库和头文件的集合。应用程序开发人员在构建代码时使用它们,以确保它们与适当的库链接 - -#### 优点 - - Yocto项目在行业中得到广泛应用,并得到许多有影响力的公司的支持。此外,它还拥有一个庞大且充满活力的开发人员[社区] [10]和[生态系统] [11]。 -开源爱好者和企业赞助商的结合有助于推动Yocto项目。 - Yocto获得支持有很多选择。如果您想自己动手,还有书籍和其他培训材料。如果您想获得专业知识,许多有Yocto经验的工程师都可以使用。许多商业组 -织为您的设计提供基于Yocto的Turnkey产品或基于服务的实施和定制。 -Yocto项目很容易通过[layer] [12]进行扩展,它可以独立发布以添加额外的功能,将目标平台定位到项目发布中不可用的平台,或存储系统特有的自定义项。 -layer可以添加到您的配置中,以添加未特别包含在市面上版本中的独特功能;例如,[meta-browser] [13] layer包含Web浏览器的清单,可以轻松为您 -的系统进行构建。因为它们是独立维护的,所以layer可以在不同的发布时间安排上(根据layer的开发速度)而不是标准的Yocto版本。 - - Yocto可以说是本文讨论的任何选项中最广泛的设备支持。由于许多半导体和电路板制造商的支持,Yocto很可能会支持您选择的任何目标平台。 -主版本Yocto [分支] [14]仅支持少数几块主板(以便进行正确的测试和发布周期),但是,标准工作模式是使用外部主板支持layer。 - - 最后,Yocto非常灵活和可定制。您的特定应用程序的自定义可以存储在一个layer进行封装和隔离。通常将要素layer特有的自定义项存储为layer本身 -的一部分,这可以将相同的设置同时应用于多个系统配置。 Yocto还提供了一个定义良好的layer优先和覆盖功能。这使您可以定义layer应用和搜索元数 -据的顺序。它还使您可以覆盖具有更高优先级的layer的设置;例如,现有清单的许多自定义功能都将保留 - -#### 缺点 - - Yocto项目最大的缺点是学习曲线。 学习系统并真正理解系统需要花费大量的时间和精力。 根据您的需求,这可能对您的应用程序不重要的技术和能力 -投入太大。 在这种情况下,与其中一家商业供应商合作可能是一个不错的选择。 - - Yocto项目的开发时间和资源相当高。 需要构建的包(包括工具链,内核和所有目标运行时组件)的数量非常重要。 Yocto开发人员的开发工作站往往是 -大型系统。 不建议使用小型笔记本电脑。 这可以通过使用许多提供商提供的基于云的构建服务器来缓解。 另外,Yocto有一个内置的缓存机制,当它确定 -用于构建特定包的参数没有改变时,它允许它重新使用先前构建的组件。 - -#### 建议 - - 为您的下一个嵌入式Linux设计使用Yocto项目是一个强有力的选择。 在这里介绍的选项中,无论您的目标用例如何,它都是最广泛适用的。 广泛的行业 -支持,积极的社区和广泛的平台支持使其成为必须设计师的不错选择。 - -### Buildroot - - [Buildroot] [15]项目被定义为:通过交叉编译生成嵌入式Linux系统的简单,高效且易于使用的工具。它与Yocto项目具有许多相同的目标,但它注重 -简单性和简约性。一般来说,Buildroot会禁用所有软件包的所有可选编译时设置(有一些值得注意的例外),从而导致尽可能小的系统。系统设计人员需要 -启用适用于给定设备的设置。 - - Buildroot从源代码构建所有组件,但不支持按目标包管理。因此,它有时称为固件生成器,因为镜像在构建时大部分是固定的。应用程序可以更新目标 -文件系统,但是没有机制将新软件包安装到正在运行的系统中。 -Buildroot输出主要由三部分组成: - -  *将Linux部署到目标平台所需的根文件系统映像和任何其他辅助文件 -  *适用于目标硬件的内核,引导加载程序和内核模块 -  *用于构建所有目标二进制文件的工具链。 - -### 优点 - - Buildroot对简单性的关注意味着,一般来说,它比Yocto更容易学习。核心构建系统用Make编写,并且足够短以允许开发人员了解整个系统,同时可扩展 -到足以满足嵌入式Linux开发人员的需求。 Buildroot核心通常只处理常见用例,但它可以通过脚本进行扩展。Buildroot系统使用普通的Makefile和Kconfig -语言来进行配置。 Kconfig由Linux内核社区开发,广泛用于开源项目,使得许多开发人员都熟悉它。 - 由于禁用所有可选构建时间设置的设计目标,Buildroot通常会使用开箱即用的配置生成尽可能最小的镜像。一般来说,构建时间和构建主机资源的规模 -将比Yocto项目的规模更小。 - -####缺点 - - 关注简单性和最小化启用的构建选项意味着您可能需要执行重要的自定义来为应用程序配置Buildroot构建。此外,所有配置选项都存储在单个文件中, -这意味着如果您有多个硬件平台,则需要为每个平台进行每个定制更改。对系统配置文件的任何更改都需要全部重新构建所有软件包。与Yocto相比,这可以 -通过最小的镜像大小和构建时间进行缓解,但在您调整配置时可能会导致构建时间过长。 - - 中间软件包状态缓存默认情况下未启用,并且不像Yocto实施那么彻底。这意味着,虽然第一次构建可能比等效的Yocto构建短,但后续构建可能需要重建 -许多组件。 - -####建议 - - 对于大多数应用程序,使用Buildroot进行下一个嵌入式Linux设计是一个不错的选择。如果您的设计需要多种硬件类型或其他差异,但由于同步多个配置 -的复杂性,您可能需要重新考虑,但对于由单一设置组成的系统,Buildroot可能适合您。 - - [OpenWRT] [16]项目开始为消费者路由器开发定制固件。您当地零售商提供的许多低成本路由器都可以运行Linux系统,但可能无法使用。这些路由器的 -制造商可能无法提供频繁的更新来解决新的威胁,即使他们这样做,安装更新镜像的机制也很困难且容易出错。 OpenWRT项目为许多已被其制造商放弃的 -设备生成更新的固件镜像,并让这些设备更加有效。 - - OpenWRT项目的主要交付物是大量商业设备的二进制镜像。有网络可访问的软件包存储库,允许设备最终用户将新软件添加到他们的系统中。 OpenWRT构建 -系统是一个通用构建系统,它允许开发人员创建自定义版本以满足他们自己的需求并添加新软件包,但其主要重点是目标二进制文件。 - -#### 优点 - -如果您正在寻找商业设备的替代固件,则OpenWRT应位于您的选项列表中。它的维护良好,可以保护您免受制造商固件无法解决的问题。您也可以添加额外的功能,使您的设备更有用。 - -如果您的嵌入式设计专注于网络,则OpenWRT是一个不错的选择。网络应用程序是OpenWRT的主要用例,您可能会发现许多可用的软件包。 - -####缺点 - - OpenWRT对您的设计施加重大决策(与Yocto和Buildroot相比)。如果这些决定不符合您的设计目标,则可能需要进行非平凡的修改。 - - 在部署的设备中允许基于软件包的更新很难管理。按照定义,这会导致与您的QA团队测试的软件负载不同。此外,很难保证大多数软件包管理器的原子安装, -以及错误的电源循环可能会使您的设备处于不可预知的状态。 - -####建议 - - OpenWRT是爱好者项目或重复使用商用硬件的不错选择。它也是网络应用程序的不错选择。如果您需要从默认设置进行大量定制,您可能更喜欢Buildroot或Yocto - -### Desktop distros - - 设计嵌入式Linux系统的一种常见方法是从桌面发行版开始,例如[Debian] [17]或[Red Hat] [18],并在安装的镜像符合目标设备的占用空间之前删除 -不需要的组件。这是[Raspberry Pi] [20]平台流行的[Raspbian] [19]分发方法。 - -### 优点 - - 这种方法的主要优点是熟悉。通常,嵌入式Linux开发人员也是桌面Linux用户,并且精通他们的选择发行版。在目标上使用类似的环境可能会让开发人员 -更快地入门。根据所选的分布,可以使用apt和yum等标准封装工具安装许多其他工具。 - - 可以将显示器和键盘连接到目标设备,并直接在那里进行所有的开发。对于不熟悉嵌入式空间的开发人员来说,这可能是一个更为熟悉的环境,无需配置和 -使用棘手的跨开发设置。 - - 大多数桌面发行版可用的软件包数量通常大于前面讨论的嵌入式特定的构建器可用软件包数量。由于较大的用户群和更广泛的用例,您可能能够找到您的 -应用程序所需的所有运行时包,这些包已经构建并可供使用。 - -####缺点 - - 将目标作为您的主要开发环境可能会很慢。运行编译器工具是一项资源密集型操作,根据您构建的代码的多少,可能会妨碍您的性能。 - - 除了一些例外情况,桌面分布的设计并不适合低资源系统,并且可能难以充分修剪目标图像。同样,桌面环境中的预期工作流程对于大多数嵌入式设计来说 -都不理想。以这种方式获得可重复的环境很困难。手动添加和删除软件包很容易出错。这可以使用特定于发行版的工具进行脚本化,例如基于Debian系统 -的[debootstrap] [21]。为了进一步提高[可重复性] [21],您可以使用配置管理工具,如[CFEngine] [22](我的雇主[Mender.io] [23]完整披露了 -这一工具)。但是,您仍然受分发提供商的支配,他们将更新软件包以满足他们的需求,而不是您的需求。 - -####建议 - - 对于您打算推向市场的产品,请谨慎使用此方法。这对于爱好者应用程序来说是一个很好的模型;但是,对于需要支持的产品,这种方法很可能会遇到麻烦。 -虽然您可能能够获得更快的起步,但从长远来看,您可能会花费您的时间和精力。 - -###其他考虑 - - 这个讨论集中在构建系统的功能上,但通常有非功能性需求可能会影响您的决定。如果您已经选择了片上系统(SoC)或电路板,则您的选择很可能由供应商 -决定。如果您的供应商为特定系统提供板级支持包(BSP),使用它通常会节省相当多的时间,但请研究BSP的质量以避免在开发周期后期发生问题。 - - 如果您的预算允许,您可能需要考虑为目标操作系统使用商业供应商。有些公司会为这里讨论的许多选项提供经过验证和支持的配置,除非您拥有嵌入式 -Linux构建系统方面的专业知识,否则这是一个不错的选择,可以让您专注于核心能力。 - - 作为替代,您可以考虑为您的开发人员进行商业培训。这可能比商业OS提供商便宜,并且可以让你更加自给自足。这是快速找到您选择的构建系统基础知识 -的学习曲线。 - - 最后,您可能已经有一些开发人员拥有一个或多个系统的经验。如果你有工程师有偏好,当你做出决定时,肯定值得考虑。 - -###总结 - - 构建嵌入式Linux系统有多种选择,每种都有优点和缺点。将这部分设计放在优先位置至关重要,因为在以后的过程中切换系统的成本非常高。除了这些 -选择之外,新系统一直在开发中。希望这次讨论能够为审查新系统(以及这里提到的系统)提供一些背景,并帮助您为下一个项目做出坚实的决定。 - --------------------------------------------------------------------------------- - -via: https://opensource.com/article/18/6/embedded-linux-build-tools - -作者:[Drew Moseley][a] -选题:[lujun9972](https://github.com/lujun9972) -译者:[LHRChina](https://github.com/LHRChina) -校对:[校对者ID](https://github.com/校对者ID) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 - -[a]:https://opensource.com/users/drewmoseley -[1]:https://en.wikipedia.org/wiki/Linux_on_z_Systems -[2]:http://www.picotux.com/ -[3]:https://www.ubuntu.com/ -[4]:https://www.virtualbox.org/ -[5]:https://www.docker.com/ -[6]:https://en.wikipedia.org/wiki/Embedded_system -[7]:https://yoctoproject.org/ -[8]:https://www.yoctoproject.org/about/ -[9]:https://www.openembedded.org/ -[10]:https://www.yoctoproject.org/community/ -[11]:https://www.yoctoproject.org/ecosystem/participants/ -[12]:https://layers.openembedded.org/layerindex/branch/master/layers/ -[13]:https://layers.openembedded.org/layerindex/branch/master/layer/meta-browser/ -[14]:https://yoctoproject.org/downloads -[15]:https://buildroot.org/ -[16]:https://openwrt.org/ -[17]:https://www.debian.org/ -[18]:https://www.redhat.com/ -[19]:https://www.raspbian.org/ -[20]:https://www.raspberrypi.org/ -[21]:https://wiki.debian.org/Debootstrap -[22]:https://cfengine.com/ -[23]:http://Mender.io diff --git a/translated/tech/20180615 BLUI- An easy way to create game UI.md b/translated/tech/20180615 BLUI- An easy way to create game UI.md deleted file mode 100644 index 5fdb1e5094..0000000000 --- a/translated/tech/20180615 BLUI- An easy way to create game UI.md +++ /dev/null @@ -1,57 +0,0 @@ -BLUI:创建游戏 UI 的简单方法 -====== - -![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/gaming_plugin_blui_screenshot.jpg?itok=91nnYCt_) - -游戏开发引擎在过去几年中变得越来越易于​​使用。像 Unity 这样一直免费使用的引擎,以及最近从基于订阅的服务切换到免费服务的 Unreal,允许独立开发者使用 AAA 发布商使用的相同行业标准工具。虽然这些引擎都不是开源的,但每个引擎都能够促进其周围的开源生态系统的发展。 - -这些引擎中包含的插件允许开发人员通过添加特定程序来增强引擎的基本功能。这些程序的范围可以从简单的资源包到更复杂的事物,如人工智能 (AI) 集成。这些插件来自不同的创作者。有些是由引擎开发工作室和有些是个人提供的。后者中的很多是开源插件。 - -### 什么是 BLUI? - -作为独立游戏开发工作室的一部分,我体验到了在专有游戏引擎上使用开源插件的好处。Aaron Shea 开发的一个开源插件 [BLUI][1] 对我们团队的开发过程起到了重要作用。它允许我们使用基于 Web 的编程(如 HTML/CSS 和 JavaScript)创建用户界面 (UI) 组件。尽管虚幻引擎(我们选择的引擎)有一个内置的 UI 编辑器实现了类似目的,我们也选择使用这个开源插件。我们选择使用开源替代品有三个主要原因:它们的可访问性、易于实现以及伴随的开源程序活跃的、支持性好的在线社区。 - -在虚幻引擎的最早版本中,我们在游戏中创建 UI 的唯一方法是通过引擎的原生 UI 集成,使用 Autodesk 的 Scaleform 程序,或通过在虚幻社区中传播的一些选定的基于订阅的 Unreal 集成。在这些情况下,这些解决方案要么不能为独立开发者提供有竞争力的 UI 解决方案,要么对于小型团队来说太昂贵,要么只能为大型团队和 AAA 开发者提供。 - -在商业产品和 Unreal 的原生整合失败后,我们向独立社区寻求解决方案。我们在那里发现了 BLUI。它不仅与虚幻引擎无缝集成,而且还保持了一个强大且活跃的社区,经常推出更新并确保独立开发人员可以轻松访问文档。BLUI 使开发人员能够将 HTML 文件导入虚幻引擎,并在程序内部对其进行编程。这使得通过网络语言创建的 UI 能够集成到游戏的代码、资源和其他元素中,并拥有所有 HTML、CSS、Javascript 和其他网络语言的能力。它还为开源 [Chromium Embedded Framework][2] 提供全面支持。 - -### 安装和使用 BLUI - -使用 BLUI 的基本过程包括首先通过 HTML 创建 UI。开发人员可以使用任何工具来实现此目的,包括自举 JavaScript 代码,外部 API 或任何数据库代码。一旦这个 HTML 页面完成,你可以像安装任何 Unreal 插件那样安装它并加载或创建一个项目。项目加载后,你可以将 BLUI 函数放在 Unreal UI 图纸中的任何位置,或者通过 C++ 进行硬编码。开发人员可以通过其 HTML 页面调用函数,或使用 BLUI 的内部函数轻松更改变量。 - -![Integrating BLUI into Unreal Engine 4 blueprints][4] - -将 BLUI 集成到虚幻 4 图纸中。 - -在我们当前的项目中,我们使用 BLUI 将 UI 元素与游戏中的音轨同步,为游戏机制的节奏方面提供视觉反馈。将定制引擎编程与 BLUI 插件集成很容易。 - -![Using BLUI to sync UI elements with the soundtrack.][6] - -使用 BLUI 将 UI 元素与音轨同步。 - -通过 BLUI GitHub 页面上的[文档][7],将 BLUI 集成到虚幻 4 中是一个微不足道的过程。还有一个由支援虚幻引擎开发人员组成的[论坛][8],他们乐于询问和回答关于插件以及实现该工具时出现的任何问题。 - -### 开源优势 - -开源插件可以在专有游戏引擎的范围内扩展创意。他们继续降低进入游戏开发的障碍,并且可以产生前所未有的游戏内机制和资源。随着对专有游戏开发引擎的访问持续增长,开源插件社区将变得更加重要。不断增长的创造力必将超过专有软件,开源代码将会填补这些空白,并促进开发真正独特的游戏。而这种新颖性正是让独立游戏如此美好的原因! - --------------------------------------------------------------------------------- - -via: https://opensource.com/article/18/6/blui-game-development-plugin - -作者:[Uwana lkaiddi][a] -选题:[lujun9972](https://github.com/lujun9972) -译者:[geekpi](https://github.com/geekpi) -校对:[校对者ID](https://github.com/校对者ID) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 - -[a]:https://opensource.com/users/uwikaiddi -[1]:https://github.com/AaronShea/BLUI -[2]:https://bitbucket.org/chromiumembedded/cef -[3]:/file/400616 -[4]:https://opensource.com/sites/default/files/uploads/blui_gaming_plugin-integratingblui.png (Integrating BLUI into Unreal Engine 4 blueprints) -[5]:/file/400621 -[6]:https://opensource.com/sites/default/files/uploads/blui_gaming_plugin-syncui.png (Using BLUI to sync UI elements with the soundtrack.) -[7]:https://github.com/AaronShea/BLUI/wiki -[8]:https://forums.unrealengine.com/community/released-projects/29036-blui-open-source-html5-js-css-hud-ui diff --git a/translated/tech/20180618 What-s all the C Plus Fuss- Bjarne Stroustrup warns of dangerous future plans for his C.md b/translated/tech/20180618 What-s all the C Plus Fuss- Bjarne Stroustrup warns of dangerous future plans for his C.md new file mode 100644 index 0000000000..42bd3d3dd9 --- /dev/null +++ b/translated/tech/20180618 What-s all the C Plus Fuss- Bjarne Stroustrup warns of dangerous future plans for his C.md @@ -0,0 +1,163 @@ +# 关于 C ++ 的所有争论?Bjarne Stroustrup 警告他的 C++ 未来的计划很危险 + +![](https://regmedia.co.uk/2018/06/15/shutterstock_38621860.jpg?x=442&y=293&crop=1) + +今年早些时候,我们**访谈**了 Bjarne Stroustrup,他是 C++ 语言的创始人,摩根士丹利技术部门的董事总经理,美国哥伦比亚大学计算机科学的客座教授,他写了[一封信][1]邀请那些关注编程语言演进的人去“想想瓦萨号!” + +毫无疑问,对于丹麦人来说,这句话很容易理解,而那些对于 17 世纪的斯堪的纳维亚历史了解不多的人,还需要展开说一下。瓦萨号是一艘瑞典军舰,由国王 Gustavus Adolphus 委托建造。它是在 1628 年 8 月 10 日首航时,当时波罗的海国家中最强大的军舰,但是它在首航几分钟之后就沉没了。 + +巨大的瓦萨号有一个难以解决的设计缺陷:头重脚轻,以至于它被[一阵狂风刮翻了][2]。通过这段翻船历史的回忆,Stroustrup 警示了 C++ 所面临的风险,因为现在越来越多的特性被添加到了 C++ 中。 + +现在已经提议了不少这样的特性。Stroustrup 在他的信中引用了 43 条提议。他认为那些参与 C++ 语言 ISO 标准演进的人(指众所周知的 [WG21][3]),正在努力地让语言更高级,但他们的努力方向却并不一致。 + +在他的信中,他写道: + +> 分开来看,许多提议都很有道理。但将它们综合到一起,这些提议是很愚蠢的,将危害 C++ 的未来。 + +他明确表示,不希望 C++ 重蹈瓦萨号的覆辙,这种渐近式的改进将敲响 C++ 的丧钟。相反,应该吸取瓦萨号的教训,构建一个坚实的基础,吸取经验教训,并做彻底的测试。 + +在瑞士拉普斯威尔(Rapperswill)召开的 C++ 标准化委员会会议之后,本月早些时候,Stroustrup 接受了_《The Register》_ 的采访,回答了有关 C++ 语言下一步发展方向方面的几个问题。(最新版是 C++17,它去年刚发布;下一个版本是 C++20,它正在开发中,预计于 2020 年发布。) + +**Register:在你的信件《想想瓦萨号!》中,你写道:** + +> 在 C++11 开始基础不再完整,而 C++17 中在使基础更加稳固、规范和完整方面几乎没有改善。相反地,却增加了重要接口的复杂度,让人们需要学习的特性数量越来越多。C++ 可能在这种提议的重压之下崩溃 —— 这些提议大多数都不成熟。我们不应该花费大量的时间为专家级用户们(比如我们自己)去创建越来越复杂的东西。~~(还要考虑普通用户的学习曲线,越复杂的东西越不易普及。)~~ + +**对新人来说,C++ 很难吗?如果是这样,你认为怎样的特性让新人更易理解?** + +**Stroustrup:**C++ 的有些东西对于新人来说确实很难。 + +换句话说,C++ 中有些东西对于新人来说,比起 C 或上世纪九十年代的 C++ 更容易理解了。而难点是让大型社区专注于这些部分,并且帮助新手和普通 C++ 用户去规避那些对高级库实现提供支持的部分。 + +我建议使用 [C++ 核心准则][4] 作为实现上述目标的一个辅助。 + +此外,我的 “C++ 教程” 也可以帮助人们在使用现代 C++ 时走上正确的方向,而不会迷失在自上世纪九十年代以来的复杂性中,或困惑于只有专家级的用户才能理解的东西中。第二版的 “C++ 教程” 涵盖了 C++17 和部分 C++20 的内容,这本书即将要出版了。 + +我和其他人给没有编程经验的大一新生教过 C++,只要你不去深挖编程语言的每个晦涩难懂的角落,把注意力集中到 C++ 中最主流的部分,在三个月内新可以学会 C++。 + +“让简单的东西保持简单” 是我长期追求的目标。比如 C++11 的 `range-for` 循环: + +``` +for (int& x : v) ++x; // increment each element of the container v + +``` + +`v` 的位置可以是任何容器。在 C 和 C 风格的 C++ 中,它可能看到的是这样: + +``` +for (int i=0; i> ~/.ssh/authorized_keys +``` + +在远程系统上重启 ssh 服务。现在,你可以在新的客户端上 SSH 远程服务端了。 + +如果觉得手动添加 ssh 公钥有些困难,在远程系统上暂时性启用密码认证,使用 “ssh-copy-id“ 命令从本地系统上拷贝密钥,最后关闭密码认证。 + +**推荐阅读:** + +(译者注:在原文中此处有超链接) + +好了,到此为止。基于密钥认证的 SSH 提供了一层防止暴力破解的额外保护。如你所见,配置密钥认证一点也不困难。这是一个非常好的方法让你的 Linux 服务端安全可靠。 + +不久我就会带来另一篇有用的文章。到那时,继续关注 OSTechNix。 + +干杯! + +-------------------------------------------------------------------------------- + +via: https://www.ostechnix.com/configure-ssh-key-based-authentication-linux/ + +作者:[SK][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[LuuMing](https://github.com/LuuMing) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.ostechnix.com/author/sk/ +[1]:https://www.ostechnix.com/cdn-cgi/l/email-protection diff --git a/translated/tech/20180813 5 of the Best Linux Educational Software and Games for Kids.md b/translated/tech/20180813 5 of the Best Linux Educational Software and Games for Kids.md new file mode 100644 index 0000000000..3a1981f0bc --- /dev/null +++ b/translated/tech/20180813 5 of the Best Linux Educational Software and Games for Kids.md @@ -0,0 +1,80 @@ +# 5 个给孩子的非常好的 Linux 教育软件和游戏 + +![](https://www.maketecheasier.com/assets/uploads/2018/07/Linux-educational-programs-for-kids-featured.jpg) + +Linux 是一个非常强大的操作系统,因此因特网上的大多数服务器都使用它。尽管它算不上是对用户友好的最佳操作系统,但它的多元化还是值的称赞的。对于 Linux 来说,每个人都能在它上面找到他们自己的所需。不论你是用它来写代码、还是用于教学或物联网(IoT),你总能找到一个适合你用的 Linux 发行版。为此,许多人认为 Linux 是未来计算的最佳操作系统。 + +未来是属于孩子们的,让孩子们了解 Linux 是他们掌控未来的最佳方式。这个操作系统上或许并没有一些像 FIFA 或 PES 那样的声名赫赫的游戏;但是,它为孩子们提供了一些非常好的教育软件和游戏。这里有五款最好的 Linux 教育软件,可以让你的孩子远离游戏。 + +**相关阅读**:[使用一个 Linux 发行版的新手指南][1] + +### 1. GCompris + +如果你正在为你的孩子寻找一款最佳的教育软件,[GCompris][2] 将是你的最好的开端。这款软件专门为 2 到 10 岁的孩子所设计。作为所有的 Linux 教育软件套装的巅峰之作,GCompris 为孩子们提供了大约 100 项活动。它囊括了你期望你的孩子学习的所有内容,从阅读材料到科学、地理、绘画、代数、测验、等等。 + +![Linux educational software and games][3] + +GCompris 甚至有一项活动可以帮你的孩子学习计算机的相关知识。如果你的孩子还很小,你希望他去学习字母、颜色、和形状,GCompris 也有这方面的相关内容。更重要的是,它也为孩子们准备了一些益智类游戏,比如国际象棋、井字棋、好记性、以及猜词游戏。GCompris 并不是一个仅在 Linux 上可运行的游戏。它也可以运行在 Windows 和 Android 上。 + +### 2. TuxMath + +很多学生认为数学是们非常难的课程。你可以通过 Linux 教育软件如 [TuxMath][4] 来让你的孩子了解数学技能,从而来改变这种看法。TuxMath 是为孩子开发的顶级的数学教育辅助游戏。在这个游戏中,你的角色是在如雨点般下降的数学问题中帮助 Linux 企鹅 Tux 来保护它的星球。 + +![linux-educational-software-tuxmath-1][5] + +在它们落下来毁坏 Tux 的星球之前,找到问题的答案,就可以使用你的激光去帮助 Tux 拯救它的星球。数字问题的难度每过一关就会提升一点。这个游戏非常适合孩子,因为它可以让孩子们去开动脑筋解决问题。而且还有助他们学好数学,以及帮助他们开发智力。 + +### 3. Sugar on a Stick + +[Sugar on a Stick][6] 是献给孩子们的学习程序 —— 一个广受好评的全新教学法。这个程序为你的孩子提供一个成熟的教学平台,在那里,他们可以收获创造、探索、发现和思考方面的技能。和 GCompris 一样,Sugar on a Stick 为孩子们带来了包括游戏和谜题在内的大量学习资源。 + +![linux-educational-software-sugar-on-a-stick][7] + +关于 Sugar on a Stick 最大的一个好处是你可以将它配置在一个 U 盘上。你只要有一台 X86 的 PC,插入那个 U 盘,然后就可以从 U 盘引导这个发行版。Sugar on a Stick 是由 Sugar 实验室提供的一个项目 —— 这个实验室是一个由志愿者运作的非盈利组织。 + +### 4. KDE Edu Suite + +[KDE Edu Suite][8] 是一个用途与众不同的软件包。带来了大量不同领域的应用程序,KDE 社区已经证实,它不仅是一系列成年人授权的问题;它还关心年青一代如何适应他们周围的一切。它囊括了一系列孩子们使用的应用程序,从科学到数学、地理等等。 + +![linux-educational-software-kde-1][9] + +KDE Edu 套件根据长大后所必需的知识为基础,既能够用作学校的教学软件,也能够作为孩子们的学习 APP。它提供了大量的可免费下载的软件包。KDE Edu 套件在主流的 GNU/Linux 发行版都能安装。 + +### 5. Tux Paint + +![linux-educational-software-tux-paint-2][10] + +[Tux Paint][11] 是给孩子们的另一个非常好的 Linux 教育软件。这个屡获殊荣的绘画软件在世界各地被用于帮助培养孩子们的绘画技能,它有一个简洁的、易于使用的界面和有趣的音效,可以高效地帮助孩子去使用这个程序。它也有一个卡通吉祥物去鼓励孩子们使用这个程序。Tux Paint 中有许多绘画工具,它们可以帮助孩子们放飞他们的创意。 + +### 总结 + +由于这些教育软件深受孩子们的欢迎,许多学校和幼儿园都使用这些程序进行辅助教学。典型的一个例子就是 [Edubuntu][12],它是儿童教育领域中广受老师和家长们欢迎的一个基于 Ubuntu 的发行版。 + +Tux Paint 是另一个非常好的例子,它在这些年越来越流行,它大量地用于学校中教孩子们如何绘画。以上的这个清单并不很详细。还有成百上千的对孩子有益的其它 Linux 教育软件和游戏。 + +如果你还知道给孩子们的其它非常好的 Linux 教育软件和游戏,在下面的评论区分享给我们吧。 + +------ + +via: https://www.maketecheasier.com/5-best-linux-software-packages-for-kids/ + +作者:[Kenneth Kimari][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[qhwdw](https://github.com/qhwdw) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://www.maketecheasier.com/author/kennkimari/ +[1]: https://www.maketecheasier.com/beginner-guide-to-using-linux-distro/ "The Beginner’s Guide to Using a Linux Distro" +[2]: http://www.gcompris.net/downloads-en.html +[3]: https://www.maketecheasier.com/assets/uploads/2018/07/Linux-educational-software-gcompris.jpg "Linux educational software and games" +[4]: https://tuxmath.en.uptodown.com/ubuntu +[5]: https://www.maketecheasier.com/assets/uploads/2018/07/Linux-educational-software-tuxmath-1.jpg "linux-educational-software-tuxmath-1" +[6]: http://wiki.sugarlabs.org/go/Sugar_on_a_Stick/Downloads +[7]: https://www.maketecheasier.com/assets/uploads/2018/07/Linux-educational-software-sugar-on-a-stick.png "linux-educational-software-sugar-on-a-stick" +[8]: https://edu.kde.org/ +[9]: https://www.maketecheasier.com/assets/uploads/2018/07/Linux-educational-software-kde-1.jpg "linux-educational-software-kde-1" +[10]: https://www.maketecheasier.com/assets/uploads/2018/07/Linux-educational-software-tux-paint-2.jpg "linux-educational-software-tux-paint-2" +[11]: http://www.tuxpaint.org/ +[12]: http://edubuntu.org/ \ No newline at end of file diff --git a/translated/tech/20180814 Automating backups on a Raspberry Pi NAS.md b/translated/tech/20180814 Automating backups on a Raspberry Pi NAS.md new file mode 100644 index 0000000000..111b508245 --- /dev/null +++ b/translated/tech/20180814 Automating backups on a Raspberry Pi NAS.md @@ -0,0 +1,229 @@ +Part-II 树莓派自建 NAS 云盘之数据自动备份 +====== + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/brain_data.png?itok=RH6NA32X) + +在《树莓派自建 NAS 云盘》系列的 [第一篇][1] 文章中,我们讨论了建立 NAS 的一些基本步骤,添加了两块 1TB 的存储硬盘驱动(一个用于数据存储,一个用于数据备份),并且通过 网络文件系统(NFS)将数据存储盘挂载到远程终端上。本文是此系列的第二篇文章,我们将探讨数据自动备份。数据自动备份保证了数据的安全,为硬件损坏后的数据恢复提供便利以及减少了文件误操作带来的不必要的麻烦。 + + + +![](https://opensource.com/sites/default/files/uploads/nas_part2.png) + + + +### 备份策略 + +我们就从为小型 NAS 构想一个备份策略着手开始吧。我建议每天有时间节点有计划的去备份数据,以防止干扰到我们正常的访问 NAS,比如备份时间点避开正在访问 NAS 并写入文件的时间点。举个例子,你可以每天凌晨 2 点去进行数据备份。 + +另外,你还得决定每天的备份需要被保留的时间长短,因为如果没有时间限制,存储空间很快就会被用完。一般每天的备份保留一周便可以,如果数据出了问题,你便可以很方便的从备份中恢复出来原数据。但是如果需要恢复数据到更久之前怎么办?可以将每周一的备份文件保留一个月、每个月的备份保留更长时间。让我们把每月的备份保留一年时间,每一年的备份保留更长时间、例如五年。 + +这样,五年内在备份盘上产生大量备份: + +* 每周 7 个日备份 +* 每月 4 个周备份 +* 每年 12 个月备份 +* 每五年 5 个年备份 + + +你应该还记得,我们搭建的备份盘和数据盘大小相同(每个 1 TB)。如何将不止 10 个 1TB 数据的备份从数据盘存放到只有 1TB 大小的备份盘呢?如果你创建的是完整备份,这显然不可能。因此,你需要创建增量备份,它是每一份备份都基于上一份备份数据而创建的。增量备份方式不会每隔一天就成倍的去占用存储空间,它每天只会增加一点占用空间。 + +以下是我的情况:我的 NAS 自 2016 年 8 月开始运行,备份盘上有 20 个备份。目前,我在数据盘上存储了 406GB 的文件。我的备份盘用了 726GB。当然,备份盘空间使用率在很大程度上取决于数据的更改频率,但正如你所看到的,增量备份不会占用 20 个完整备份所需的空间。然而,随着时间的推移,1TB 空间也可能不足以进行备份。一旦数据增长接近 1TB 限制(或任何备份盘容量),应该选择更大的备份盘空间并将数据移动转移过去。 + +### 利用 rsync 进行数据备份 + +利用 rsync 命令行工具可以生成完整备份。 + +``` +pi@raspberrypi:~ $ rsync -a /nas/data/ /nas/backup/2018-08-01 + +``` + +这段命令将挂载在 /nas/data/ 目录下的数据盘中的数据进行了完整的复制备份。备份文件保存在 /nas/backup/2018-08-01 目录下。`-a` 参数是以归档模式进行备份,这将会备份所有的元数据,例如文件的修改日期、权限、拥有者以及软连接文件。 + +现在,你已经在 8 月 1 日创建了完整的初始备份,你将在 8 月 2 日创建第一个增量备份。 + +``` +pi@raspberrypi:~ $ rsync -a --link-dest /nas/backup/2018-08-01/ /nas/data/ /nas/backup/2018-08-02 + +``` + +上面这行代码又创建了一个关于 `/nas/data` 目录中数据的备份。备份路径是 `/nas/backup/2018-08-02`。这里的参数 `--link-dest` 指定了一个备份文件所在的路径。这样,这次备份会与 `/nas/backup/2018-08-01` 的备份进行比对,只备份已经修改过的文件,未做修改的文件将不会被复制,而是创建一个到上一个备份文件中它们的硬链接。 + +使用备份文件中的硬链接文件时,你一般不会注意到硬链接和初始拷贝之间的差别。它们表现的完全一样,如果删除其中一个硬链接或者文件,其他的依旧存在。你可以把它们看做是同一个文件的两个不同入口。下面就是一个例子: + +![](https://opensource.com/sites/default/files/uploads/backup_flow.png) + +左侧框是在进行了第二次备份后的原数据状态。中间的盒子是昨天的备份。昨天的备份中只有图片 `file1.jpg` 并没有 `file2.txt` 。右侧的框反映了今天的增量备份。增量备份命令创建昨天不存在的 `file2.txt`。由于 `file1.jpg` 自昨天以来没有被修改,所以今天创建了一个硬链接,它不会额外占用磁盘上的空间。 + +### 自动化备份 + +你肯定也不想每天凌晨去输入命令进行数据备份吧。你可以创建一个任务定时去调用下面的脚本让它自动化备份 + +``` +#!/bin/bash + + + +TODAY=$(date +%Y-%m-%d) + +DATADIR=/nas/data/ + +BACKUPDIR=/nas/backup/ + +SCRIPTDIR=/nas/data/backup_scripts + +LASTDAYPATH=${BACKUPDIR}/$(ls ${BACKUPDIR} | tail -n 1) + +TODAYPATH=${BACKUPDIR}/${TODAY} + +if [[ ! -e ${TODAYPATH} ]]; then + +        mkdir -p ${TODAYPATH} + +fi + + + +rsync -a --link-dest ${LASTDAYPATH} ${DATADIR} ${TODAYPATH} $@ + + + +${SCRIPTDIR}/deleteOldBackups.sh + +``` + +第一段代码指定了数据路径、备份路劲、脚本路径以及昨天和今天的备份路径。第二段代码调用 rsync 命令。最后一段代码执行 `deleteOldBackups.sh` 脚本,它会清除一些过期的没有必要的备份数据。如果不想频繁的调用 `deleteOldBackups.sh`,你也可以手动去执行它。 + +下面是今天讨论的备份策略的一个简单完整的示例脚本。 + +``` +#!/bin/bash + +BACKUPDIR=/nas/backup/ + + + +function listYearlyBackups() { + +        for i in 0 1 2 3 4 5 + +                do ls ${BACKUPDIR} | egrep "$(date +%Y -d "${i} year ago")-[0-9]{2}-[0-9]{2}" | sort -u | head -n 1 + +        done + +} + + + +function listMonthlyBackups() { + +        for i in 0 1 2 3 4 5 6 7 8 9 10 11 12 + +                do ls ${BACKUPDIR} | egrep "$(date +%Y-%m -d "${i} month ago")-[0-9]{2}" | sort -u | head -n 1 + +        done + +} + + + +function listWeeklyBackups() { + +        for i in 0 1 2 3 4 + +                do ls ${BACKUPDIR} | grep "$(date +%Y-%m-%d -d "last monday -${i} weeks")" + +        done + +} + + + +function listDailyBackups() { + +        for i in 0 1 2 3 4 5 6 + +                do ls ${BACKUPDIR} | grep "$(date +%Y-%m-%d -d "-${i} day")" + +        done + +} + + + +function getAllBackups() { + +        listYearlyBackups + +        listMonthlyBackups + +        listWeeklyBackups + +        listDailyBackups + +} + + + +function listUniqueBackups() { + +        getAllBackups | sort -u + +} + + + +function listBackupsToDelete() { + +        ls ${BACKUPDIR} | grep -v -e "$(echo -n $(listUniqueBackups) |sed "s/ /\\\|/g")" + +} + + + +cd ${BACKUPDIR} + +listBackupsToDelete | while read file_to_delete; do + +        rm -rf ${file_to_delete} + +done + +``` + +这段脚本会首先根据你的备份策略列出所有需要保存的备份文件,然后它会删除那些再也不需要了的备份目录。 + +下面创建一个定时任务去执行上面这段代码。以 root 用户权限打开 `crontab -e`,输入以下这段命令,它将会创建一个每天凌晨 2 点去执行 `/nas/data/backup_scripts/daily.sh` 的定时任务。 + +``` +0 2 * * * /nas/data/backup_scripts/daily.sh + +``` + +有关创建定时任务请参考 [cron 创建定时任务][2]。 + +* 当没有备份任务时,卸载你的备份盘或者将它挂载为只读盘; +* 利用远程服务器作为你的备份盘,这样就可以通过互联网同步数据 + +你也可用下面的方法来加强你的备份策略,以防止备份数据的误删除或者被破坏: + +本文中备份策略示例是备份一些我觉得有价值的数据,你也可以根据个人需求去修改这些策略。 + +我将会在 《树莓派自建 NAS 云盘》 系列的第三篇文章中讨论 [Nextcloud][3]。Nextcloud 提供了更方便的方式去访问 NAS 云盘上的数据并且它还提供了离线操作,你还可以在客户端中同步你的数据。 + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/8/automate-backups-raspberry-pi + +作者:[Manuel Dewald][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[jrg](https://github.com/jrglinux) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://opensource.com/users/ntlx +[1]: https://opensource.com/article/18/7/network-attached-storage-Raspberry-Pi +[2]: https://opensource.com/article/17/11/how-use-cron-linux +[3]: https://nextcloud.com/ + diff --git a/translated/tech/20180816 Add YouTube Player Controls To Your Linux Desktop With browser-mpris2 (Chrome Extension).md b/translated/tech/20180816 Add YouTube Player Controls To Your Linux Desktop With browser-mpris2 (Chrome Extension).md new file mode 100644 index 0000000000..a72b4cdd8d --- /dev/null +++ b/translated/tech/20180816 Add YouTube Player Controls To Your Linux Desktop With browser-mpris2 (Chrome Extension).md @@ -0,0 +1,76 @@ +使用 browser-mpris2(Chrome 扩展)将 YouTube 播放器控件添加到 Linux 桌面 +====== +一个我怀念的 Unity 功能(虽然只使用了一小段时间)是在 Web 浏览器中访问 YouTube 等网站时自动获取 Ubuntu 声音指示器中的播放器控件,因此你可以直接从顶部栏暂停或停止视频,以及浏览视频/歌曲信息和预览。 + +这个 Unity 功能已经消失很久了,但我正在为 Gnome Shell 寻找类似的东西,然后我遇到了 **[browser-mpris2][1],这是一个为 Google Chrome/Chromium 实现 MPRIS v2 接口的扩展,目前只支持 YouTube**,我想可能会有一些 Linux Uprising 的读者会喜欢这个。 + +**该扩展还适用于 Opera 和 Vivaldi 等基于 Chromium 的 Web 浏览器。** +** +** **browser-mpris2 也支持 Firefox,但因为通过 about:debugging 加载扩展是临时的,而这是 browser-mpris2 所需要的,因此本文不包括 Firefox 的指导。开发人员[打算][2]将来将扩展提交到 Firefox 插件网站上。** + +**使用此 Chrome 扩展,你可以在支持 MPRIS2 的 applets 中获得 YouTube 媒体播放器控件(播放、暂停、停止和查找 +)**。例如,如果你使用 Gnome Shell,你可将 YouTube 媒体播放器控件作为永久通知,或者你可以使用 Media Player Indicator 之类的扩展来实现此目的。在 Cinnamon /Linux Mint with Cinnamon 中,它出现在声音 Applet 中。 + +**我无法在 Unity 上用它**,我不知道为什么。我没有在不同桌面环境(KDE、Xfce、MATE 等)中使用其他支持 MPRIS2 的 applet 尝试此扩展。如果你尝试过,请告诉我们它是否适用于你的桌面环境/支持 MPRIS2 的 applet。 + +以下是在使用 Gnome Shell 的 Ubuntu 18.04 并装有 Chromium 浏览器的[媒体播放器指示器][3]的截图,其中显示了有关当前正在播放的 YouTube 视频的信息及其控件(播放/暂停,停止和查找): + +![](https://1.bp.blogspot.com/-rsc4FpYBSrI/W3VtPphfdOI/AAAAAAAABXY/YfKV6pBncs0LAwTwYSS0tKRJADDfZDBfwCLcBGAs/s640/browser-mpris2-gnome-shell-sound-indicator.png) + +在 Linux Mint 19 Cinnamon 中使用其默认声音 applet 和 Chromium 浏览器的截图: + + +![](https://2.bp.blogspot.com/-I2DuYetv7eQ/W3VtUUcg26I/AAAAAAAABXc/Tv-RemkyO60k6CC_mYUxewG-KfVgpFefACLcBGAs/s1600/browser-mpris2-cinnamon-linux-mint.png) + +### 如何为 Google Chrom/Chromium安装 browser-mpris2 + +**1\. 如果你还没有安装 Git 就安装它** + +在 Debian/Ubuntu/Linux Mint 中,使用此命令安装 git: +``` +sudo apt install git + +``` + +**2\. 下载并安装 [browser-mpris2][1] 所需文件。** + +下面的命令克隆了 browser-mpris2 的 Git 仓库并将 chrome-mpris2 安装到 `/usr/local/bin/`(在一个你可以保存 browser-mpris2 文件夹的地方运行 “git clone ...” 命令,由于它会被 Chrome/Chromium 使用,你不能删除它): +``` +git clone https://github.com/otommod/browser-mpris2 +sudo install browser-mpris2/native/chrome-mpris2 /usr/local/bin/ + +``` + +**3\. 在基于 Chrome/Chromium 的 Web 浏览器中加载此扩展。** + +![](https://3.bp.blogspot.com/-yEoNFj2wAXM/W3Vvewa979I/AAAAAAAABXo/dmltlNZk3J4sVa5jQenFFrT28ecklY92QCLcBGAs/s640/browser-mpris2-chrome-developer-load-unpacked.png) + +打开 Goog​​le Chrome、Chromium、Opera 或 Vivaldi 浏览器,进入 Extensions 页面(在 URL 栏中输入 `chrome://extensions`),在屏幕右上角切换到`开发者模式`。然后选择 `Load Unpacked` 并选择 chrome-mpris2 目录(确保没有选择子文件夹)。 + +复制扩展 ID 并保存它,因为你以后需要它(它类似于这样:`emngjajgcmeiligomkgpngljimglhhii`,但它会与你的不一样,因此确保使用你计算机中的 ID!)。 + +**4\. 运行 **`install-chrome.py`**(在 `browser-mpris2/native` 文件夹中),指定扩展 id 和 chrome-mpris2 路径。 + +在终端中使用此命令(将 `REPLACE-THIS-WITH-EXTENSION-ID` 替换为上一步中 `chrome://extensions` 下显示的 browser-mpris2 扩展 ID)安装此扩展: +``` +browser-mpris2/native/install-chrome.py REPLACE-THIS-WITH-EXTENSION-ID /usr/local/bin/chrome-mpris2 + +``` + +你只需要运行此命令一次,无需将其添加到启动或其他类似的地方。你在 Google Chrome 或 Chromium 浏览器中播放的任何 YouTube 视频都应显示在你正在使用的任何 MPRISv2 applet 中。你无需重启 Web 浏览器。 + +-------------------------------------------------------------------------------- + +via: https://www.linuxuprising.com/2018/08/add-youtube-player-controls-to-your.html + +作者:[Logix][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[geekpi](https://github.com/geekpi) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://plus.google.com/118280394805678839070 +[1]:https://github.com/otommod/browser-mpris2 +[2]:https://github.com/otommod/browser-mpris2/issues/11 +[3]:https://extensions.gnome.org/extension/55/media-player-indicator/ diff --git a/translated/tech/20180824 5 cool music player apps.md b/translated/tech/20180824 5 cool music player apps.md new file mode 100644 index 0000000000..fb301ed4dd --- /dev/null +++ b/translated/tech/20180824 5 cool music player apps.md @@ -0,0 +1,108 @@ +5 个很酷的音乐播放器 +====== + +![](https://fedoramagazine.org/wp-content/uploads/2018/08/5-cool-music-apps-816x345.jpg) +你喜欢音乐吗?那么 Fedora 中可能有你正在寻找的东西。本文介绍在 Fedora 上运行的不同音乐播放器。无论你有大量的音乐库,还是小型音乐库,或者根本没有音乐库,你都会被覆盖到。这里有四个图形程序和一个基于终端的音乐播放器,可以让你挑选。 + +### Quod Libet + +Quod Libet 是你的大型音频库的管理员。如果你有一个大量的音频库,你不想只听,但也要管理,Quod Libet 可能是一个很好的选择。 + +![][1] + +Quod Libet 可以从磁盘上的多个位置导入音乐,并允许你编辑音频文件的标签 - 因此一切都在你的控制之下。额外地,它还有各种插件可用,从简单的均衡器到 [last.fm][2] 同步。你也可以直接从 [Soundcloud][3] 搜索和播放音乐。 + +Quod Libet 在 HiDPI 屏幕上工作得很好,它有 Fedora 的 RPM 包,如果你运行[Silverblue][5],它在 [Flathub][4] 中也有。使用 Gnome Software 或命令行安装它: +``` +$ sudo dnf install quodlibet + +``` + +### Audacious + +如果你喜欢简单的音乐播放器,甚至可能看起来像传说中的 Winamp,Audacious 可能是你的不错选择。 + +![][6] + +Audacious 可能不会立即管理你的所有音乐,但你如果想将音乐组织为文件,它能做得很好。你还可以导出和导入播放列表,而无需重新组织音乐文件本身。 + +额外地,你可以让它看起来像 Winamp。要让它与上面的截图相同,请进入 “Settings/Appearance,”,选择顶部的 “Winamp Classic Interface”,然后选择右下方的 “Refugee” 皮肤。而鲍勃是你的叔叔!这就完成了。 + +Audacious 在 Fedora 中作为 RPM 提供,可以使用 Gnome Software 或在终端运行以下命令安装: +``` +$ sudo dnf install audacious + +``` + +### Lollypop + +Lollypop 是一个音乐播放器,它与 GNOME 集成良好。如果你喜欢 GNOME 的外观,并且想要一个集成良好的音乐播放器,Lollypop 可能适合你。 + +![][7] + +除了与 GNOME Shell 的良好视觉集成之外,它还可以很好地用于 HiDPI 屏幕,并支持黑暗主题。 + +额外地,Lollypop 有一个集成的封面下载器和一个所谓的派对模式(右上角的音符按钮),它可以自动选择和播放音乐。它还集成了 [last.fm][2] 或 [libre.fm][8] 等在线服务。 + +它有 Fedora 的 RPM 也有用于 [Silverblue][5] 工作站的 [Flathub][4],使用 Gnome Software 或终端进行安装: +``` +$ sudo dnf install lollypop + +``` + +### Gradio + +如果你没有任何音乐但仍喜欢听怎么办?或者你只是喜欢收音机?Gradio 就是为你准备的。 + +![][9] + +Gradio 是一个简单的收音机,它允许你搜索和播放网络电台。你可以按国家、语言或直接搜索找到它们。额外地,它可视化地集成到了 GNOME Shell 中,可以与 HiDPI 屏幕配合使用,并且可以选择黑暗主题。 + +可以在 [Flathub][4] 中找到 Gradio,它同时可以运行在 Fedora Workstation 和 [Silverblue][5] 中。使用 Gnome Software 安装它 + +### sox + +你喜欢使用终端在工作时听一些音乐吗?多亏有了 sox,你不必离开终端。 + +![][10] + +sox 是一个非常简单的基于终端的音乐播放器。你需要做的就是运行如下命令: +``` +$ play file.mp3 + +``` + +接着 sox 就会为你播放。除了单独的音频文件外,sox 还支持 m3u 格式的播放列表。 + +额外地,因为 sox 是基于终端的程序,你可以在 ssh 中运行它。你有一个带扬声器的家用服务器吗?或者你想从另一台电脑上播放音乐吗?尝试将它与 [tmux][11] 一起使用,这样即使会话关闭也可以继续听。 + +sox 在 Fedora 中以 RPM 提供。运行下面的命令安装: +``` +$ sudo dnf install sox + +``` + + +-------------------------------------------------------------------------------- + +via: https://fedoramagazine.org/5-cool-music-player-apps/ + +作者:[Adam Šamalík][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[geekpi](https://github.com/geekpi) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://fedoramagazine.org/author/asamalik/ +[1]:https://fedoramagazine.org/wp-content/uploads/2018/08/qodlibet-300x217.png +[2]:https://last.fm +[3]:https://soundcloud.com/ +[4]:https://flathub.org/home +[5]:https://teamsilverblue.org/ +[6]:https://fedoramagazine.org/wp-content/uploads/2018/08/audacious-300x136.png +[7]:https://fedoramagazine.org/wp-content/uploads/2018/08/lollypop-300x172.png +[8]:https://libre.fm +[9]:https://fedoramagazine.org/wp-content/uploads/2018/08/gradio.png +[10]:https://fedoramagazine.org/wp-content/uploads/2018/08/sox-300x179.png +[11]:https://fedoramagazine.org/use-tmux-more-powerful-terminal/ diff --git a/translated/tech/20180901 5 Ways to Take Screenshot in Linux GUI and Terminal.md b/translated/tech/20180901 5 Ways to Take Screenshot in Linux GUI and Terminal.md new file mode 100644 index 0000000000..b8872981fe --- /dev/null +++ b/translated/tech/20180901 5 Ways to Take Screenshot in Linux GUI and Terminal.md @@ -0,0 +1,211 @@ +5 种在 Linux 图形界面或命令行界面截图的方法 +====== +下面介绍几种获取屏幕截图并对其编辑的方法,而且其中的屏幕截图工具在 Ubuntu 和其它主流 Linux 发行版中都能够使用。 + +![在 Ubuntu Linux 中如何获取屏幕截图][1] + +当我的主力操作系统从 Windows 转换到 Ubuntu 的时候,首要考虑的就是屏幕截图工具的可用性。尽管使用默认的键盘快捷键也可以获取屏幕截图,但如果使用屏幕截图工具,可以更方便地对屏幕截图进行编辑。 + +本文将会介绍在不适用第三方工具的情况下,如何通过系统自带的方法和工具获取屏幕截图,另外还会介绍一些可用于 Linux 的最佳截图工具。 + +### 方法 1: 在 Linux 中截图的默认方式 + +你是否需要截取整个屏幕?屏幕中的某个区域?某个特定的窗口? + +如果只需要获取一张屏幕截图,不对其进行编辑的话,那么键盘的默认快捷键就可以满足要求了。而且不仅仅是 Ubuntu ,绝大部分的 Linux 发行版和桌面环境都支持以下这些快捷键: + +**PrtSc** – 获取整个屏幕的截图并保存到 Pictures 目录。 +**Shift + PrtSc** – 获取屏幕的某个区域截图并保存到 Pictures 目录。 +**Alt + PrtSc** –获取当前窗口的截图并保存到 Pictures 目录。 +**Ctrl + PrtSc** – 获取整个屏幕的截图并存放到剪贴板。 +**Shift + Ctrl + PrtSc** – 获取屏幕的某个区域截图并存放到剪贴板。 +**Ctrl + Alt + PrtSc** – 获取当前窗口的 截图并存放到剪贴板。 + +如上所述,在 Linux 中使用默认的快捷键获取屏幕截图是相当简单的。但如果要在不把屏幕截图导入到其它应用程序的情况下对屏幕截图进行编辑,还是使用屏幕截图工具比较方便。 + +#### **方法 2: 在 Linux 中使用 Flameshot 获取屏幕截图并编辑** + +![flameshot][2] + +功能概述 + + * 注释 (高亮、标示、添加文本、框选) + * 图片模糊 + * 图片裁剪 + * 上传到 Imgur + * 用另一个应用打开截图 + + + +Flameshot 在去年发布到 [GitHub][3],并成为一个引人注目的工具。如果你需要的是一个能够用于标注、模糊、上传到 imgur 的新式截图工具,那么 Flameshot 是一个好的选择。 + +下面将会介绍如何安装 Flameshot 并根据你的偏好进行配置。 + +如果你用的是 Ubuntu,那么只需要在 Ubuntu 软件中心上搜索,就可以找到 Flameshot 进而完成安装了。要是你想使用终端来安装,可以执行以下命令: +``` +sudo apt install flameshot + +``` + +如果你在安装过程中遇到问题,可以按照[官方的安装说明][4]进行操作。安装完成后,你还需要进行配置。尽管可以通过搜索来随时启动 Flameshot,但如果想使用 PrtSc 键触发启动,则需要指定对应的键盘快捷键。以下是相关配置步骤: + + * 进入系统设置中的键盘设置 + * 页面中会列出所有现有的键盘快捷键,拉到底部就会看见一个 **+** 按钮 + * 点击 “+” 按钮添加自定义快捷键并输入以下两个字段: +**名称:** 任意名称均可 +**命令:** /usr/bin/flameshot gui + * 最后将这个快捷操作绑定到 **PrtSc** 键上,可能会提示与系统的截图功能相冲突,但可以忽略掉这个警告。 + + + +配置之后,你的自定义快捷键页面大概会是以下这样: + +![][5] +将键盘快捷键映射到 Flameshot + +### **方法 3: 在 Linux 中使用 Shutter 获取屏幕截图并编辑** + +![][6] + +功能概述: + + * 注释 (高亮、标示、添加文本、框选) + * 图片模糊 + * 图片裁剪 + * 上传到图片网站 + + + +[Shutter][7] 是一个对所有主流 Linux 发行版都适用的屏幕截图工具。尽管最近已经不太更新了,但仍然是操作屏幕截图的一个优秀工具。 + +在使用过程中可能会遇到这个工具的一些缺陷。Shutter 在任何一款最新的 Linux 发行版上最常见的问题就是由于缺少了任务栏上的程序图标,导致默认禁用了编辑屏幕截图的功能。 对于这个缺陷,还是有解决方案的。下面介绍一下如何[在 Shutter 中重新打开这个功能并将程序图标在任务栏上显示出来][8]。问题修复后,就可以使用 Shutter 来快速编辑屏幕截图了。 + +同样地,在软件中心搜索也可以找到进而安装 Shutter,也可以在基于 Ubuntu 的发行版中执行以下命令使用命令行安装: +``` +sudo apt install shutter + +``` + +类似 Flameshot,你可以通过搜索 Shutter 手动启动它,也可以按照相似的方式设置自定义快捷方式以 **PrtSc** 键唤起 Shutter。 + +如果要指定自定义键盘快捷键,只需要执行以下命令: +``` +shutter -f + +``` + +### 方法 4: 在 Linux 中使用 GIMP 获取屏幕截图 + +![][9] + +功能概述: + + * 高级图像编辑功能(缩放、添加滤镜、颜色校正、添加图层、裁剪等) + * 截取某一区域的屏幕截图 + + + +如果需要对屏幕截图进行一些预先编辑,GIMP 是一个不错的选择。 + +通过软件中心可以安装 GIMP。如果在安装时遇到问题,可以参考其[官方网站的安装说明][10]。 + +要使用 GIMP 获取屏幕截图,需要先启动程序,然后通过 **File-> Create-> Screenshot** 导航。 + +打开 Screenshot 选项后,会看到几个控制点来控制屏幕截图范围。点击 **Snap** 截取屏幕截图,图像将自动显示在 GIMP 中可供编辑。 + +### 方法 5: 在 Linux 中使用命令行工具获取屏幕截图 + +这一节内容仅适用于终端爱好者。如果你也喜欢使用终端,可以使用 **GNOME 截图工具**或 **ImageMagick** 或 **Deepin Scrot**,大部分流行的 Linux 发行版中都自带这些工具。 + +要立即获取屏幕截图,可以执行以下命令: + +#### GNOME Screenshot(可用于 GNOME 桌面) +``` +gnome-screenshot + +``` + +GNOME Screenshot 是使用 GNOME 桌面的 Linux 发行版中都自带的一个默认工具。如果需要延时获取屏幕截图,可以执行以下命令(这里的 **5** 是需要延迟的秒数): + +``` +gnome-screenshot -d -5 + +``` + +#### ImageMagick + +如果你的操作系统是 Ubuntu、Mint 或其它流行的 Linux 发行版,一般会自带 [ImageMagick][11] 这个工具。如果没有这个工具,也可以按照[官方安装说明][12]使用安装源来安装。你也可以在终端中执行这个命令: +``` +sudo apt-get install imagemagick + +``` + +安装完成后,执行下面的命令就可以获取到屏幕截图(截取整个屏幕): + +``` +import -window root image.png + +``` + +这里的“image.png”就是屏幕截图文件保存的名称。 + +要获取屏幕一个区域的截图,可以执行以下命令: +``` +import image.png + +``` + +#### Deepin Scrot + +Deepin Scrot 是基于终端的一个较新的截图工具。和前面两个工具类似,一般自带于 Linux 发行版中。如果需要自行安装,可以执行以下命令: +``` +sudo apt-get install scrot + +``` + +安装完成后,使用下面这些命令可以获取屏幕截图。 + +获取整个屏幕的截图: +``` +scrot myimage.png + +``` + +获取屏幕某一区域的截图: +``` +scrot -s myimage.png + +``` + +### 总结 + +以上是一些在 Linux 上的优秀截图工具。当然还有很多截图工具没有提及(例如 [Spectacle][13] for KDE-distros),但相比起来还是上面几个工具更为好用。 + +如果你有比文章中提到的更好的截图工具,欢迎讨论! + +-------------------------------------------------------------------------------- + +via: https://itsfoss.com/take-screenshot-linux/ + +作者:[Ankush Das][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://itsfoss.com/author/ankush/ +[1]: https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/09/Taking-Screenshots-in-Linux.png +[2]: https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/08/flameshot-pic.png +[3]: https://github.com/lupoDharkael/flameshot +[4]: https://github.com/lupoDharkael/flameshot#installation +[5]: https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/08/flameshot-config-default.png +[6]: https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/08/shutter-screenshot.jpg +[7]: http://shutter-project.org/ +[8]: https://itsfoss.com/shutter-edit-button-disabled/ +[9]: https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/08/gimp-screenshot.jpg +[10]: https://www.gimp.org/downloads/ +[11]: https://www.imagemagick.org/script/index.php +[12]: https://www.imagemagick.org/script/install-source.php +[13]: https://www.kde.org/applications/graphics/spectacle/ + diff --git a/translated/tech/20180913 ScreenCloud- The Screenshot-- App.md b/translated/tech/20180913 ScreenCloud- The Screenshot-- App.md new file mode 100644 index 0000000000..a7002183c3 --- /dev/null +++ b/translated/tech/20180913 ScreenCloud- The Screenshot-- App.md @@ -0,0 +1,77 @@ +ScreenCloud:一个截屏程序 +====== +[ScreenCloud][1]是一个很棒的小程序,你甚至不知道你需要它。桌面 Linux 的默认屏幕截图流程很好(Prt Scr 按钮),我们甚至有一些[强大的截图工具][2],如 [Shutter][3]。但是,ScreenCloud 有一个非常简单但非常方便的功能,让我爱上了它。在我们深入它之前,让我们先看一个背景故事。 + +我截取了很多截图。远远超过平均水平。收据、注册详细信息、开发工作、文章中程序的截图等等。我接下来要做的就是打开浏览器,浏览我最喜欢的云存储并将重要的内容转储到那里,以便我可以在手机上以及 PC 上的多个操作系统上访问它们。这也让我可以轻松与我的团队分享我正在使用的程序的截图。 + +我对这个标准的截图流程没有抱怨,打开浏览器并登录我的云,然后手动上传屏幕截图,直到我遇到 ScreenCloud。 + +### ScreenCloud + +ScreenCloud 是跨平台的程序,它提供简单的屏幕截图和灵活的[云备份选项][4]管理。这包括使用你自己的[ FTP 服务器][5]。 + +![][6] + +ScreenCloud 很精简,投入了大量的注意力给小的东西。它为你提供了非常容易记住的热键来捕获全屏、活动窗口或捕获用鼠标选择的区域。 + +![][7]ScreenCloud 的默认键盘快捷键 + +截取屏幕截图后,你可以设置 ScreenCloud 如何处理图像或直接将其上传到你选择的云服务。它甚至支持 SFTP。截图上传后(通常在几秒钟内),图像链接就会被自动复制到剪贴板,这让你可以轻松共享。 + +![][8] + +你还可以使用 ScreenCloud 进行一些基本编辑。为此,你需要将 “Save to” 设置为 “Ask me”。此设置在下拉框中有并且通常是默认设置。当使用它时,当你截取屏幕截图时,你会看到编辑文件的选项。在这里,你可以在屏幕截图中添加箭头、文本和数字。 + +![Editing screenshots with ScreenCloud][9]Editing screenshots with ScreenCloud + +### 在 Linux 上安装 ScreenCloud + +ScreenCloud 可在[ Snap 商店][10]中找到。因此,你可以通过访问[ Snap 商店][12]或运行以下命令,轻松地将其安装在 Ubuntu 和其他[启用 Snap ][11]的发行版上。 + +``` +sudo snap install screencloud + +``` + +对于无法通过 Snap 安装程序的 Linux 发行版,你可以[在这里][1]下载 AppImage。进入下载文件夹,右键单击并在那里打开终端。然后运行以下命令。 + +``` +sudo chmod +x ScreenCloud-v1.4.0-x86_64.AppImage + +``` + +然后,你可以通过双击下载的文件来启动程序。 + +![][13] + +### 总结 + +ScreenCloud 适合所有人吗?可能不会。它比默认屏幕截图更好吗?可能是。如果你正在截某些屏幕,有可能它是重要的或是你想分享的。ScreenCloud 可以更轻松,更快速地备份或共享屏幕截图。所以,如果你想要这些功能,你应该试试 ScreenCloud。 + +欢迎在用下面的评论栏提出你的想法和意见。还有不要忘记与朋友分享这篇文章。干杯。 + +-------------------------------------------------------------------------------- + +via: https://itsfoss.com/screencloud-app/ + +作者:[Aquil Roshan][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[geekpi](https://github.com/geekpi) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://itsfoss.com/author/aquil/ +[1]: https://screencloud.net +[2]: https://itsfoss.com/take-screenshot-linux/ +[3]: http://shutter-project.org +[4]: https://itsfoss.com/cloud-services-linux/ +[5]: https://itsfoss.com/set-ftp-server-linux/ +[6]: https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/09/screencloud3.jpg +[7]: https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/09/screencloud2.jpg +[8]: https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/09/ScrenCloud6.jpg +[9]: https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/09/editing-with-screencloud.png +[10]: https://snapcraft.io/ +[11]: https://itsfoss.com/install-snap-linux/ +[12]: https://snapcraft.io/screencloud +[13]: https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/09/ScrenCloud4.jpg diff --git a/translated/tech/20180915 Backup Installed Packages And Restore Them On Freshly Installed Ubuntu.md b/translated/tech/20180915 Backup Installed Packages And Restore Them On Freshly Installed Ubuntu.md new file mode 100644 index 0000000000..1b21607ee9 --- /dev/null +++ b/translated/tech/20180915 Backup Installed Packages And Restore Them On Freshly Installed Ubuntu.md @@ -0,0 +1,107 @@ +备份安装包并在全新安装的 Ubuntu 上恢复它们 +====== + +![](https://www.ostechnix.com/wp-content/uploads/2018/09/apt-clone-720x340.png) + +在多个 Ubuntu 系统上安装同一组软件包是一项耗时且无聊的任务。你不会想花时间在多个系统上反复安装相同的软件包。在类似架构的 Ubuntu 系统上安装软件包时,有许多方法可以使这项任务更容易。你可以方便地通过 [**Aptik**][1] 并点击几次鼠标将以前的 Ubuntu 系统的应用程序、设置和数据迁移到新安装的系统中。或者,你可以使用软件包管理器(例如 APT)获取[**备份的已安装软件包的完整列表**][2],然后在新安装的系统上安装它们。今天,我了解到还有另一个专用工具可以完成这项工作。来看一下 **apt-clone**,这是一个简单的工具,可以让你为 Debian/Ubuntu 系统创建一个已安装的软件包列表,这些软件包可以在新安装的系统或容器上或目录中恢复。 + +Apt-clone 会帮助你处理你想要的情况, + + * 在运行类似 Ubuntu(及衍生版)的多个系统上安装一致的应用程序。 +  * 经常在多个系统上安装相同的软件包。 +  * 备份已安装的应用程序的完整列表,并在需要时随时随地恢复它们。 + + + +在本简要指南中,我们将讨论如何在基于 Debian 的系统上安装和使用 Apt-clone。我在 Ubuntu 18.04 LTS 上测试了这个程序,但它应该适用于所有基于 Debian 和 Ubuntu 的系统。 + +### 备份已安装的软件包并在新安装的 Ubuntu 上恢复它们 + +Apt-clone 在默认仓库中有。要安装它,只需在终端输入以下命令: + +``` +$ sudo apt install apt-clone +``` + +安装后,只需创建已安装软件包的列表,并将其保存在你选择的任何位置。 + +``` +$ mkdir ~/mypackages + +$ sudo apt-clone clone ~/mypackages +``` + +上面的命令将我的 Ubuntu 中所有已安装的软件包保存在 **~/mypackages** 目录下名为 **apt-clone-state-ubuntuserver.tar.gz** 的文件中。 + +要查看备份文件的详细信息,请运行: + +``` +$ apt-clone info mypackages/apt-clone-state-ubuntuserver.tar.gz +Hostname: ubuntuserver +Arch: amd64 +Distro: bionic +Meta: +Installed: 516 pkgs (33 automatic) +Date: Sat Sep 15 10:23:05 2018 +``` + +如你所见,我的 Ubuntu 服务器总共有 516 个包。 + +现在,将此文件复制到 USB 或外部驱动器上,并转至要安装同一套软件包的任何其他系统。或者,你也可以将备份文件传输到网络上的系统,并使用以下命令安装软件包: + +``` +$ sudo apt-clone restore apt-clone-state-ubuntuserver.tar.gz +``` + +请注意,此命令将覆盖你现有的 **/etc/apt/sources.list** 并将安装/删除软件包。警告过你了!此外,只需确保目标系统是相同的架构和操作系统。例如,如果源系统是 18.04 LTS 64位,那么目标系统必须也是相同的。 + +如果你不想在系统上恢复软件包,可以使用 `--destination /some/location` 选项将克隆复制到这个文件夹中。 + +``` +$ sudo apt-clone restore apt-clone-state-ubuntuserver.tar.gz --destination ~/oldubuntu +``` + +在此例中,上面的命令将软件包恢复到 **~/oldubuntu** 中。 + +有关详细信息,请参阅帮助部分: + +``` +$ apt-clone -h +``` + +或者手册页: + +``` +$ man apt-clone +``` + +**建议阅读:** + ++ [Systemback - 将 Ubuntu 桌面版和服务器版恢复到以前的状态][3] ++ [Cronopete - Linux 下的苹果时间机器][4] + +就是这些了。希望这个有用。还有更多好东西。敬请期待! + +干杯! + + + + +-------------------------------------------------------------------------------- + +via: https://www.ostechnix.com/backup-installed-packages-and-restore-them-on-freshly-installed-ubuntu-system/ + +作者:[SK][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[geekpi](https://github.com/geekpi) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://www.ostechnix.com/author/sk/ +[1]: https://www.ostechnix.com/how-to-migrate-system-settings-and-data-from-an-old-system-to-a-newly-installed-ubuntu-system/ +[2]: https://www.ostechnix.com/create-list-installed-packages-install-later-list-centos-ubuntu/#comment-12598 + +[3]: https://www.ostechnix.com/systemback-restore-ubuntu-desktop-and-server-to-previous-state/ + +[4]: https://www.ostechnix.com/cronopete-apples-time-machine-clone-linux/ diff --git a/translated/tech/20180917 4 scanning tools for the Linux desktop.md b/translated/tech/20180917 4 scanning tools for the Linux desktop.md new file mode 100644 index 0000000000..89aaad3a89 --- /dev/null +++ b/translated/tech/20180917 4 scanning tools for the Linux desktop.md @@ -0,0 +1,72 @@ +用于Linux桌面的4个扫描工具 +====== +使用其中一个开源软件驱动扫描仪来实现无纸化办公。 + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/osdc-photo-camera-blue.png?itok=AsIMZ9ga) + +尽管无纸化世界还没有到来,但越来越多的人通过扫描文件和照片来摆脱纸张的束缚。不过,仅仅拥有一台扫描仪还不足够。你还需要软件来驱动扫描仪。 + +然而问题是许多扫描仪制造商没有将Linux版本的软件与他们的设备适配在一起。不过在大多数情况下,即使没有也没多大关系。因为在linux桌面上已经有很好的扫描软件了。它们能够与许多扫描仪配合很好的完成工作。 + +现在就让我们看看四个简单又灵活的开源Linux扫描工具。我已经使用过了下面这些工具(甚至[早在2014年][1]写过关于其中三个工具的文章)并且觉得它们非常有用。希望你也会这样认为。 + +### Simple Scan + +这是我最喜欢的一个软件之一,[Simple Scan][2]小巧,迅速,高效,且易于使用。如果你以前见过它,那是因为Simple Scan是GNOME桌面上的默认扫描程序应用程序,也是许多Linux发行版的默认扫描程序。 + +你只需单击一下就能扫描文档或照片。扫描过某些内容后,你可以旋转或裁剪它并将其另存为图像(仅限JPEG或PNG格式)或PDF格式。也就是说Simple Scan可能会很慢,即使你用较低分辨率来扫描文档。最重要的是,Simple Scan在扫描时会使用一组全局的默认值,例如150dpi用于文本,300dpi用于照片。你需要进入Simple Scan的首选项才能更改这些设置。 + +如果你扫描的内容超过了几页,还可以在保存之前重新排序页面。如果有必要的话 - 假如你正在提交已签名的表格 - 你可以使用Simple Scan来发送电子邮件。 + +### Skanlite + +从很多方面来看,[Skanlite][3]是Simple Scan在KDE世界中的表兄弟。虽然Skanlite功能很少,但它可以出色的完成工作。 + +你可以自己配置这个软件的选项,包括自动保存扫描文件,设置扫描质量以及确定扫描保存位置。 Skanlite可以保存为以下图像格式:JPEG,PNG,BMP,PPM,XBM和XPM。 + +其中一个很棒的功能是Skanlite能够将你扫描的部分内容保存到单独的文件中。当你想要从照片中删除某人或某物时,这就派上用场了。 + +### Gscan2pdf + +这是我另一个最爱的老软件,[gscan2pdf][4]可能会显得很老旧了,但它仍然包含一些比这里提到的其他软件更好的功能。即便如此,gscan2pdf仍然显得很轻便。 + +除了以各种图像格式(JPEG,PNG和TIFF)保存扫描外,gscan2pdf还将它们保存为PDF或[DjVu][5]文件。你可以在单击“扫描”按钮之前设置扫描的分辨率,无论是黑白,彩色还是纸张大小,每当你想要更改任何这些设置时,这都会进入gscan2pdf的首选项。你还可以旋转,裁剪和删除页面。 + +虽然这些都不是真正的杀手级功能,但它们会给你带来更多的灵活性。 + +### GIMP + +你大概会知道[GIMP][6]是一个图像编辑工具。但是你恐怕不知道可以用它来驱动你的扫描仪吧。 + +你需要安装[XSane][7]扫描软件和GIMP XSane插件。这两个应该都可以从你的Linux发行版的包管理器中获得。在软件里,选择文件>创建>扫描仪/相机。单击扫描仪,然后单击扫描按钮即可进行扫描。 + +如果这不是你想要的,或者它不起作用,你可以将GIMP和一个叫作[QuiteInsane][8]的插件结合起来。使用任一插件,都能使GIMP成为一个功能强大的扫描软件,它可以让你设置许多选项,如是否扫描彩色或黑白,扫描的分辨率,以及是否压缩结果等。你还可以使用GIMP的工具来修改或应用扫描后的效果。这使得它非常适合扫描照片和艺术品。 + +### 它们真的能够工作吗? + +所有的这些软件在大多数时候都能够在各种硬件上运行良好。我将它们与我过去几年来拥有的多台多功能打印机一起使用 - 无论是使用USB线连接还是通过无线连接。 + +你可能已经注意到我在前一段中写过“大多数时候运行良好”。这是因为我确实遇到过一个例外:一个便宜的canon多功能打印机。我使用的软件都没有检测到它。最后我不得不下载并安装canon的Linux扫描仪软件才使它工作。 + +你最喜欢的Linux开源扫描工具是什么?发表评论,分享你的选择。 + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/9/linux-scanner-tools + +作者:[Scott Nesbitt][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[way-ww](https://github.com/way-ww) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://opensource.com/users/scottnesbitt +[1]: https://opensource.com/life/14/8/3-tools-scanners-linux-desktop +[2]: https://gitlab.gnome.org/GNOME/simple-scan +[3]: https://www.kde.org/applications/graphics/skanlite/ +[4]: http://gscan2pdf.sourceforge.net/ +[5]: http://en.wikipedia.org/wiki/DjVu +[6]: http://www.gimp.org/ +[7]: https://en.wikipedia.org/wiki/Scanner_Access_Now_Easy#XSane +[8]: http://sourceforge.net/projects/quiteinsane/ diff --git a/translated/tech/20180917 Getting started with openmediavault- A home NAS solution.md b/translated/tech/20180917 Getting started with openmediavault- A home NAS solution.md new file mode 100644 index 0000000000..833180811a --- /dev/null +++ b/translated/tech/20180917 Getting started with openmediavault- A home NAS solution.md @@ -0,0 +1,74 @@ +openmediavault入门:一个家庭NAS解决方案 +====== +这个网络附加文件服务提供了一序列功能,并且易于安装和配置。 + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/bus-cloud.png?itok=vz0PIDDS) + +面对许多可供选择的云存储方案,一些人可能会质疑一个家庭网络附加存储服务的价值。毕竟,当所有你的文件存储在云上,你不需要为你自己云服务的维护,更新,和安全担忧。 + +但是,这不完全对,是不是?你有一个家庭网络,所以你不得不负责维护网络的健康和安全。假定你已经维护一个家庭网络,那么[一个家庭NAS][1]并不会增加额外负担。反而你能从少量的工作中得到许多的好处。 + +你可以为你家里所有的计算机备份(你也可以备份离线网站).构架一个存储电影,音乐和照片的媒体服务器,无需担心网络连接是否连接。在家里的多台计算机处理大型文件,不需要等待从网络其他随机的计算机传输这些文件过来。另外,可以让NAS与其他服务一起进行双重任务,如托管本地邮件或者家庭Wiki。也许最重要的是,构架家庭NAS,数据完全是你的,始终在控制下和随时可访问的。 + +接下来的问题是如何选择NAS方案。当然,你可以购买预先建立的解决方案,并在某一天打电话购买,但是这会有什么乐趣呢?实际上,尽管拥有一个能处理一切的设备很棒,但最好还是有一个可以修复和升级的钻机。这是一个我近期发现的解决方案。我选择安装和配置[openmediavault][2]。 + +### 为什么选择openmediavault? + +市面上有不少开源的NAS解决方案,其中有些无可争议的比openmediavault流行。当我询问周遭,例如,[freeNAS][3]最常被推荐给我。那么为什么我不采纳他们的建议呢?毕竟,它被大范围的使用,包含很多的功能,并且提供许多支持选项,[基于FreeNAS官网的一份对比数据][4]。当然这些全部是对的。但是openmediavault也不差。它是基于FreeNAS早期版本,虽然它在下载和功能方面的数量较低,但是对于我的需求而言,它已经相当足够了。 + +另外一个因素是它让我感到很舒适。openmediavault的底层操作系统是[Debian][5],然而FreeNAS是[FreeBSD][6]。由于我个人对FressBSD不是很熟悉,因此如果我的NAS出现故障,必定会很难在FreeBSD上修复故障。同样的,也会让我觉得很难微调配置或添加服务到机器上。当然,我可以学习FreeBSD和更熟悉它,但是我已经在家里构架了这个NAS;我发现,如果限制给定自己完成构建NAS的“学习机会”的数量,构建NAS往往会更成功。 + +当然,每个情况都不同,所以你要自己调研,然后作出最适合自己方案的决定。FreeNAS对于许多人似乎都是不错的解决方案。Openmediavault正是适合我的解决方案。 + +### 安装与配置 + +在[openmediavault文档]里详细记录了安装步骤,所以我不在这里重述了。如果你曾经安装过任何一个linux版本,大部分安装步骤都是很类似的(虽然在相对丑陋的[Ucurses][9]界面,不像你可能在现代版本的相对美观的安装界面)。我通过使用[专用驱动器][9]指令来安装它。然而,这些指令不但很好,而且相当精炼的。当你搞定这些指令,你安装了一个基本的系统,但是你还需要做很多才能真正构建好NAS来存储任何文件。例如,专用驱动器指令在硬盘驱动上安装openmediavault,但那是操作系统的驱动,而不是和网络上其他计算机共享空间的那个驱动。你需要自己把这些建立起来并且配置好。 + +你要做的第一件事是加载用来管理的网页界面和修改默认密码。这个密码和之前你安装过程设置的根密码是不同的。这是网页洁面的管理员账号,和默认的账户和密码分别是 `admin` 和 `openmediavault`,当你登入后自然而然地会修改这些配置属性。 + +#### 设置你的驱动 + +一旦你安装好openmediavault,你需要它为你做一些工作。逻辑上的第一个步骤是设置好你即将用来作为存储的驱动。在这里,我假定你已经物理上安装好它们了,所以接下来你要做的就是让openmediavault识别和配置它们。第一步是确保这些磁盘是可见的。侧边栏菜单有很多选项,而且被精心的归类了。选择**存储 - > 磁盘**。一旦你点击该菜单,你应该能够看到所有你已经安装到该服务器的驱动,包括那个你已经用来安装openmediavault的驱动。如果你没有在那里看到所有驱动,点击扫描按钮去看它能够接载它们。通常,这不会是一个问题。 + +当你的文件共享时,你可以独立的挂载和设置这些驱动,但是对于一个文件服务器,你将想要一些冗余驱动。你想要能够把很多驱动当作一个单一卷和能够在某一个驱动出现故障或者空间不足下安装新驱动的情况下恢复你的数据。这意味你将需要一个[RAID][10]。你想要的什么特定类型的RAID的主题是一个深深的兔子洞,是一个值得另写一片文章专门来讲述它(而且已经有很多关于该主题的文章了),但是简而言之是你将需要不仅仅一个驱动和最好的情况下,你的所有驱动都存储一样数量的数据。 + +openmedia支持所有标准的RAID级别,所以多了解RAID对你很有好处的。可以在**存储 - > RAID管理**配置你的RAID。配置是相当简单:点击创建按钮,在你的RAID阵列里选择你想要的磁盘和你想要使用的RAID级别,和给这个阵列一个名字。openmediavault为你处理剩下的工作。没有混乱的命令行,试图记住‘mdadm'命令的一些标志参数。在我特别的例子,我有六个2TB驱动,并被设置为RAID 10. + +当你的RAID构建好了,基本上你已经有一个地方可以存储东西了。你仅仅需要设置一个文件系统。正如你的桌面系统,一个硬盘驱动在没有格式化情况下是没什么用处的。所以下一个你要去的地方的是位于openmediavault控制面板里的 **存储 - > 文件系统**。和配置你的RAID一样,点击创建按钮,然后跟着提示操作。如果你只有一个RAID在你的服务器上,你应该可以看到一个像 `md0`的东西。你也需要选择文件系统的类别。如果你不能确定,选择标准的ext4类型即可。 + +#### 定义你的共享 + +亲爱的!你有个地方可以存储文件了。现在你只需要让它在你的家庭网络中可见。可以从在openmediavault控制面板上的**服务**部分上配置。当谈到在网络上设置文件共享,有两个主要的选择:NFS或者SMB/CIFS. 根据以往经验,如果你网络上的所有计算机都是Linux系统,那么你使用NFS会更好。然而,当你家庭网络是一个混合环境,是一个包含Linux,Windows,苹果系统和嵌入式设备的组合,那么SMB/CIF可能会是你合适的选择。 + +这些选项不是互斥的。实际上,你可以在服务器上运行这些服务和同时拥有这些服务的好处。或者你可以混合起来,如果你有一个特定的设备做特定的任务。不管你的使用场景是怎样,配置这些服务是相当简单。点击你想要的服务,从它配置中激活它,和在网络中设定你想要的共享文件夹为可见。在基于SMB/CIFS共享的情况下,相对于NFS多了一些可用的配置,但是一般用默认配置就挺好的,接着可以在默认基础上修改配置。最酷的事情是它很容易配置,同时也很容易在需要的时候修改配置。 + +#### 用户配置 + +基本上已将完成了。你已经在RAID配置你的驱动。你已经用一种文件系统格式化了RAID。和你已经在格式化的RAID上设定了共享文件夹。剩下来的一件事情是配置那些人可以访问这些共享和可以访问多少。这个可以在 **访问权限管理** 配置区设置。使用 **用户** 和 **群组** 选项来设定可以连接到你共享文件加的用户和设定这些共享文件的访问权限。 + +一旦你完成用户配置,你几乎准备好了。你需要从不同客户端机器访问你的共享,但是这是另外一个可以单独写个文章的话题了。 + +玩得开心! + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/9/openmediavault + +作者:[Jason van Gumster][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[jamelouis](https://github.com/jamelouis) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://opensource.com/users/mairin +[1]: https://opensource.com/article/18/8/automate-backups-raspberry-pi +[2]: https://openmediavault.org +[3]: https://freenas.org +[4]: http://www.freenas.org/freenas-vs-openmediavault/ +[5]: https://www.debian.org/ +[6]: https://www.freebsd.org/ +[7]: https://openmediavault.readthedocs.io/en/latest/installation/index.html +[8]: https://invisible-island.net/ncurses/ +[9]: https://openmediavault.readthedocs.io/en/latest/installation/via_iso.html +[10]: https://en.wikipedia.org/wiki/RAID diff --git a/translated/tech/20180918 Linux firewalls- What you need to know about iptables and firewalld.md b/translated/tech/20180918 Linux firewalls- What you need to know about iptables and firewalld.md new file mode 100644 index 0000000000..c3ecb7b1d3 --- /dev/null +++ b/translated/tech/20180918 Linux firewalls- What you need to know about iptables and firewalld.md @@ -0,0 +1,178 @@ +Linux 防火墙: 关于 iptables 和 firewalld,你需要知道些什么 +====== + +以下是如何使用 iptables 和 firewalld 工具来管理 Linux 防火墙规则。 + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/openwires_fromRHT_520_0612LL.png?itok=PqZi55Ab) +这篇文章摘自我的书[Linux in Action][1],第二 Manning project 尚未发布。 + +### 防火墙 + + +防火墙是一组规则。当数据包进出受保护的网络时,进出内容(特别是关于其来源、目标和使用的协议等信息)会根据防火墙规则进行检测,以确定是否允许其通过。下面是一个简单的例子: + + +![防火墙过滤请求] [3] + +防火墙可以根据协议或基于目标的规则过滤请求。 + +一方面, [iptables][4] 是 Linux 机器上管理防火墙规则的工具。 + +另一方面,[firewalld][5]也是 Linux 机器上管理防火墙规则的工具。 + +你有什么问题吗?如果我告诉你还有另外一种工具,叫做 [nftables][6],这会不会糟蹋你的一天呢? + +好吧,我承认整件事确实有点好笑,所以让我解释一下了。这一切都从 Netfilter 开始,在 Linux 内核模块级别, Netfilter 控制访问网络栈。几十年来,管理 Netfilter 钩子的主要命令行工具是 iptables 规则集。 + +因为调用这些规则所需的语法看起来有点晦涩难懂,所以各种用户友好的实现方式,如[ufw][7] 和 firewalld 被引入作,并为更高级别的 Netfilter 解释器。然而,Ufw 和 firewalld 主要是为解决独立计算机面临的各种问题而设计的。构建全方面的网络解决方案通常需要 iptables,或者从2014年起,它的替代品 nftables (nft 命令行工具)。 + + +iptables 没有消失,仍然被广泛使用着。事实上,在未来的许多年里,作为一名管理员,你应该会使用 iptables 来保护的网络。但是nftables 通过操作经典的 Netfilter 工具集带来了一些重要的崭新的功能。 + + +从现在开始,我将通过示例展示 firewalld 和 iptables 如何解决简单的连接问题。 + +### 使用 firewalld 配置 HTTP 访问 + +正如你能从它的名字中猜到的,firewalld 是 [systemd][8] 家族的一部分。Firewalld 可以安装在 Debian/Ubuntu 机器上,不过, 它默认安装在 RedHat 和 CentOS 上。如果您的计算机上运行着像 Apache 这样的 web 服务器,您可以通过浏览服务器的 web 根目录来确认防火墙是否正在工作。如果网站不可访问,那么 firewalld 正在工作。 + +你可以使用 `firewall-cmd` 工具从命令行管理 firewalld 设置。添加 `–state` 参数将返回当前防火墙的状态: + +``` +# firewall-cmd --state +running +``` + +默认情况下,firewalld 将处于运行状态,并将拒绝所有传入流量,但有几个例外,如 SSH。这意味着你的网站不会有太多的访问者,这无疑会为你节省大量的数据传输成本。然而,这不是你对 web 服务器的要求,你希望打开 HTTP 和 HTTPS 端口,按照惯例,这两个端口分别被指定为80和443。firewalld 提供了两种方法来实现这个功能。一个是通过 `–add-port` 参数,该参数直接引用端口号及其将使用的网络协议(在本例中为TCP )。 另外一个是通过`–permanent` 参数,它告诉 firewalld 在每次服务器启动时加载此规则: + + +``` +# firewall-cmd --permanent --add-port=80/tcp +# firewall-cmd --permanent --add-port=443/tcp +``` + + `–reload` 参数将这些规则应用于当前会话: + +``` +# firewall-cmd --reload +``` + +查看当前防火墙上的设置, 运行 `–list-services` : + +``` +# firewall-cmd --list-services +dhcpv6-client http https ssh +``` + +假设您已经如前所述添加了浏览器访问,那么 HTTP、HTTPS 和 SSH 端口现在都应该是开放的—— `dhcpv6-client` ,它允许 Linux 从本地 DHCP 服务器请求 IPv6 IP地址。 + +### 使用 iptables 配置锁定的客户信息亭 + +我相信你已经看到了信息亭——它们是放在机场、图书馆和商务场所的盒子里的平板电脑、触摸屏和ATM类电脑,邀请顾客和路人浏览内容。大多数信息亭的问题是,你通常不希望用户像在自己家一样,把他们当成自己的设备。它们通常不是用来浏览、观看 YouTube 视频或对五角大楼发起拒绝服务攻击的。因此,为了确保它们没有被滥用,你需要锁定它们。 + + +一种方法是应用某种信息亭模式,无论是通过巧妙使用Linux显示管理器还是在浏览器级别。但是为了确保你已经堵塞了所有的漏洞,你可能还想通过防火墙添加一些硬网络控制。在下一节中,我将讲解如何使用iptables 来完成。 + + +关于使用iptables,有两件重要的事情需要记住:你给规则的顺序非常关键,iptables 规则本身在重新启动后将无法存活。我会一次一个地在解释这些。 + +### 信息亭项目 + +为了说明这一切,让我们想象一下,我们为一家名为 BigMart 的大型连锁商店工作。它们已经存在了几十年;事实上,我们想象中的祖父母可能是在那里购物并长大的。但是这些天,BigMart 公司总部的人可能只是在数着亚马逊将他们永远赶下去的时间。 + +尽管如此,BigMart 的IT部门正在尽他们最大努力提供解决方案,他们向你发放了一些具有 WiFi 功能信息亭设备,你在整个商店的战略位置使用这些设备。其想法是,登录到 BigMart.com 产品页面,允许查找商品特征、过道位置和库存水平。信息亭还允许进入 bigmart-data.com,那里储存着许多图像和视频媒体信息。 + +除此之外,您还需要允许下载软件包更新。最后,您还希望只允许从本地工作站访问SSH,并阻止其他人登录。下图说明了它将如何工作: + +![信息亭流量IP表] [10] + +信息亭业务流由 iptables 控制。 + +### 脚本 + +以下是 Bash 脚本内容: + +``` +#!/bin/bash +iptables -A OUTPUT -p tcp -d bigmart.com -j ACCEPT +iptables -A OUTPUT -p tcp -d bigmart-data.com -j ACCEPT +iptables -A OUTPUT -p tcp -d ubuntu.com -j ACCEPT +iptables -A OUTPUT -p tcp -d ca.archive.ubuntu.com -j ACCEPT +iptables -A OUTPUT -p tcp --dport 80 -j DROP +iptables -A OUTPUT -p tcp --dport 443 -j DROP +iptables -A INPUT -p tcp -s 10.0.3.1 --dport 22 -j ACCEPT +iptables -A INPUT -p tcp -s 0.0.0.0/0 --dport 22 -j DROP +``` + +我们从基本规则 `-A` 开始分析,它告诉iptables 我们要添加规则。`OUTPUT` 意味着这条规则应该成为输出的一部分。`-p` 表示该规则仅使用TCP协议的数据包,正如`-d` 告诉我们的,目的地址是 [bigmart.com][11]。`-j` 参数作用为数据包符合规则时要采取的操作是 `ACCEPT`。第一条规则表示允许或接受请求。但,最后一条规则表示删除或拒绝的请求。 + +规则顺序是很重要的。iptables 仅仅允许匹配规则的内容请求通过。一个向外发出的浏览器请求,比如访问[youtube.com][12] 是会通过的,因为这个请求匹配第四条规则,但是当它到达“dport 80”或“dport 443”规则时——取决于是HTTP还是HTTPS请求——它将被删除。iptables不再麻烦检查了,因为那是一场比赛。 + +另一方面,向ubuntu.com 发出软件升级的系统请求,只要符合其适当的规则,就会通过。显然,我们在这里做的是,只允许向我们的 BigMart 或 Ubuntu 发送 HTTP 或 HTTPS 请求,而不允许向其他目的地发送。 + +最后两条规则将处理 SSH 请求。因为它不使用端口80或443端口,而是使用22端口,所以之前的两个丢弃规则不会拒绝它。在这种情况下,来自我的工作站的登录请求将被接受,但是对其他任何地方的请求将被拒绝。这一点很重要:确保用于端口22规则的IP地址与您用来登录的机器的地址相匹配——如果不这样做,将立即被锁定。当然,这没什么大不了的,因为按照目前的配置方式,只需重启服务器,iptables 规则就会全部丢失。如果使用 LXC 容器作为服务器并从 LXC 主机登录,则使用主机 IP 地址连接容器,而不是其公共地址。 + +如果机器的IP发生变化,请记住更新这个规则;否则,你会被拒绝访问。 + +在家玩(是在某种性虚拟机上)?太好了。创建自己的脚本。现在我可以保存脚本,使用`chmod` 使其可执行,并以`sudo` 的形式运行它。不要担心 `igmart-data.com没找到`错误——当然没找到;它不存在。 + +``` +chmod +X scriptname.sh +sudo ./scriptname.sh +``` + +你可以使用`cURL` 命令行测试防火墙。请求 ubuntu.com 奏效,但请求 [manning.com][13]是失败的 。 + + +``` +curl ubuntu.com +curl manning.com +``` + +### 配置 iptables 以在系统启动时加载 + +现在,我如何让这些规则在每次 kiosk 启动时自动加载?第一步是将当前规则保存。使用`iptables-save` 工具保存规则文件。将在根目录中创建一个包含规则列表的文件。管道后面跟着 tee 命令,是将我的`sudo` 权限应用于字符串的第二部分:将文件实际保存到否则受限的根目录。 + +然后我可以告诉系统每次启动时运行一个相关的工具,叫做`iptables-restore` 。我们在上一模块中看到的常规cron 作业,因为它们在设定的时间运行,但是我们不知道什么时候我们的计算机可能会决定崩溃和重启。 + +有许多方法来处理这个问题。这里有一个: + + +在我的 Linux 机器上,我将安装一个名为 [anacron][14] 的程序,该程序将在 /etc/ 目录中为我们提供一个名为anacrondab 的文件。我将编辑该文件并添加这个 `iptables-restore` 命令,告诉它加载该文件的当前值。引导后一分钟,规则每天(必要时)加载到 iptables 中。我会给作业一个标识符( `iptables-restore` ),然后添加命令本身。如果你在家和我一起这样,你应该通过重启系统来测试一下。 + +``` +sudo iptables-save | sudo tee /root/my.active.firewall.rules +sudo apt install anacron +sudo nano /etc/anacrontab +1 1 iptables-restore iptables-restore < /root/my.active.firewall.rules + +``` + +我希望这些实际例子已经说明了如何使用 iptables 和 firewalld 来管理基于Linux的防火墙上的连接问题。 + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/9/linux-iptables-firewalld + +作者:[David Clinton][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[heguangzhi](https://github.com/heguangzhi) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://opensource.com/users/remyd +[1]: https://www.manning.com/books/linux-in-action?a_aid=bootstrap-it&a_bid=4ca15fc9&chan=opensource +[2]: /file/409116 +[3]: https://opensource.com/sites/default/files/uploads/iptables1.jpg (firewall filtering request) +[4]: https://en.wikipedia.org/wiki/Iptables +[5]: https://firewalld.org/ +[6]: https://wiki.nftables.org/wiki-nftables/index.php/Main_Page +[7]: https://en.wikipedia.org/wiki/Uncomplicated_Firewall +[8]: https://en.wikipedia.org/wiki/Systemd +[9]: /file/409121 +[10]: https://opensource.com/sites/default/files/uploads/iptables2.jpg (kiosk traffic flow ip tables) +[11]: http://bigmart.com/ +[12]: http://youtube.com/ +[13]: http://manning.com/ +[14]: https://sourceforge.net/projects/anacron/ diff --git a/translated/tech/20180918 Top 3 Python libraries for data science.md b/translated/tech/20180918 Top 3 Python libraries for data science.md new file mode 100644 index 0000000000..4026b751d5 --- /dev/null +++ b/translated/tech/20180918 Top 3 Python libraries for data science.md @@ -0,0 +1,246 @@ +3 个用于数据科学的顶级 Python 库 +====== + +>使用这些库把 Python 变成一个科学数据分析和建模工具。 + +![][7] + +Python 的许多特性,比如开发效率、代码可读性、速度等使之成为了数据科学爱好者的首选编程语言。对于想要升级应用程序功能的数据科学家和机器学习专家来说,Python 通常是最好的选择(比如,Andrey Bulezyuk 使用 Python 语言创造了一个优秀的[机器学习应用程序][1])。 + +由于 Python 的广泛使用,因此它拥有大量的库,使得数据科学家能够很容易地完成复杂的任务,而且不会遇到许多编码困难。下面列出 3 个用于数据科学的顶级 Python 库。如果你想在数据科学这一领域开始你的职业生涯,就去了解一下它们吧。 + +### NumPy + +[NumPy][2](数值 Python 的简称)是其中一个顶级数据科学库,它拥有许多有用的资源,从而帮助数据科学家把 Python 变成一个强大的科学分析和建模工具。NumPy 是在 BSD 许可证的许可下开源的,它是在科学计算中执行任务的基础 Python 库。SciPy 是一个更大的基于 Python 生态系统的开源工具,而 NumPy 是 SciPy 非常重要的一部分。 + +NumPy 为 Python 提供了大量数据结构,从而能够轻松地执行多维数组和矩阵运算。除了用于求解线性代数方程和其它数学计算之外,NumPy 还可以用做不同类型通用数据的多维容器。 + +此外,NumPy 还可以和其他编程语言无缝集成,比如 C/C++ 和 Fortran。NumPy 的多功能性使得它可以简单而快速地与大量数据库和工具结合。比如,让我们来看一下如何使用 NumPy(缩写成 `np`)来实现两个矩阵的乘法运算。 + +我们首先导入 NumPy 库(在这些例子中,我将使用 Jupyter notebook): + +``` +import numpy as np +``` + +接下来,使用 `eye()` 函数来生成指定维数的单位矩阵: + +``` +matrix_one = np.eye(3) +matrix_one +``` + +输出如下: + +``` +array([[1., 0., 0.], +       [0., 1., 0.], +       [0., 0., 1.]]) +``` + +让我们生成另一个 3x3 矩阵。 + +我们使用 `arange([starting number], [stopping number])` 函数来排列数字。注意,函数中的第一个参数是需要列出的初始数字,而后一个数字不包含在生成的结果中。 + +另外,使用 `reshape()` 函数把原始生成的矩阵的维度改成我们需要的维度。为了使两个矩阵“可乘”,它们需要有相同的维度。 + +``` +matrix_two = np.arange(1,10).reshape(3,3) +matrix_two +``` + +Here is the output: +输出如下: + +``` +array([[1, 2, 3], +       [4, 5, 6], +       [7, 8, 9]]) +``` + +接下来,使用 `dot()` 函数将两个矩阵相乘。 + +``` +matrix_multiply = np.dot(matrix_one, matrix_two) + +matrix_multiply + +``` + +相乘后的输出如下: + +``` +array([[1., 2., 3.], +       [4., 5., 6.], +       [7., 8., 9.]]) +``` + +太好了! + +我们成功使用 NumPy 完成了两个矩阵的相乘,而不是使用普通冗长vanilla的 Python 代码。 + +下面是这个例子的完整代码: + +``` +import numpy as np +#生成一个 3x3 单位矩阵 +matrix_one = np.eye(3) +matrix_one +#生成另一个 3x3 矩阵以用来做乘法运算 +matrix_two = np.arange(1,10).reshape(3,3) +matrix_two +#将两个矩阵相乘 +matrix_multiply = np.dot(matrix_one, matrix_two) +matrix_multiply +``` + +### Pandas + +[Pandas][3] 是另一个可以提高你的 Python 数据科学技能的优秀库。就和 NumPy 一样,它属于 SciPy 开源软件家族,可以在 BSD 免费许可证许可下使用。 + +Pandas 提供了多功能并且很强大的工具用于管理数据结构和执行大量数据分析。该库能够很好的处理不完整、非结构化和无序的真实世界数据,并且提供了用于整形、聚合、分析和可视化数据集的工具 + +Pandas 中有三种类型的数据结构: + + * Series: 一维、相同数据类型的数组 + * DataFrame: 二维异型矩阵 + * Panel: 三维大小可变数组 + + + +例如,我们来看一下如何使用 Panda 库(缩写成 `pd`)来执行一些描述性统计计算。 + +首先导入该库: + +``` +import pandas as pd +``` + +然后,创建一个序列series字典: + +``` +d = {'Name':pd.Series(['Alfrick','Michael','Wendy','Paul','Dusan','George','Andreas', +   'Irene','Sagar','Simon','James','Rose']), +   'Years of Experience':pd.Series([5,9,1,4,3,4,7,9,6,8,3,1]), +   'Programming Language':pd.Series(['Python','JavaScript','PHP','C++','Java','Scala','React','Ruby','Angular','PHP','Python','JavaScript']) +    } +``` + +接下来,再创建一个数据框DataFrame: + +``` +df = pd.DataFrame(d) +``` + +输出是一个非常规整的表: + +``` +      Name Programming Language  Years of Experience +0   Alfrick               Python                    5 +1   Michael           JavaScript                    9 +2     Wendy                  PHP                    1 +3      Paul                  C++                    4 +4     Dusan                 Java                    3 +5    George                Scala                    4 +6   Andreas                React                    7 +7     Irene                 Ruby                    9 +8     Sagar              Angular                    6 +9     Simon                  PHP                    8 +10    James               Python                    3 +11     Rose           JavaScript                    1 +``` + +下面是这个例子的完整代码: + +``` +import pandas as pd +#创建一个序列字典 +d = {'Name':pd.Series(['Alfrick','Michael','Wendy','Paul','Dusan','George','Andreas', +   'Irene','Sagar','Simon','James','Rose']), +   'Years of Experience':pd.Series([5,9,1,4,3,4,7,9,6,8,3,1]), +   'Programming Language':pd.Series(['Python','JavaScript','PHP','C++','Java','Scala','React','Ruby','Angular','PHP','Python','JavaScript']) +    } + +#创建一个数据框 +df = pd.DataFrame(d) +print(df) +``` + +### Matplotlib + +[Matplotlib][4] 也是 Scipy 核心包的一部分,并且在 BSD 许可证下可用。它是一个非常流行的科学库,用于实现简单而强大的可视化。你可以使用这个 Python 数据科学框架来生成曲线图、柱状图、直方图以及各种不同形状的图表,并且不用担心需要写很多行的代码。例如,我们来看一下如何使用 Matplotlib 库来生成一个简单的柱状图。 + +首先导入该库: + +``` +from matplotlib import pyplot as plt +``` + +然后生成 x 轴和 y 轴的数值: + +``` +x = [2, 4, 6, 8, 10] +y = [10, 11, 6, 7, 4] +``` + +接下来,调用函数来绘制柱状图: + +``` +plt.bar(x,y) +``` + +最后,显示图表: + +``` +plt.show() +``` + +柱状图如下: + +![][6] + +下面是这个例子的完整代码: + +``` +#导入 Matplotlib 库 +from matplotlib import pyplot as plt +#和 import matplotlib.pyplot as plt 一样 +  +#生成 x 轴的数值 +x = [2, 4, 6, 8, 10] +  +#生成 y 轴的数值 +y = [10, 11, 6, 7, 4] +  +#调用函数来绘制柱状图 +plt.bar(x,y) +  +#显示图表 +plt.show() +``` + +### 总结 + +Python 编程语言非常擅长数据处理和准备,但是在科学数据分析和建模方面就没有那么优秀了。幸好有这些用于[数据科学][5]的顶级 Python 框架填补了这一空缺,从而你能够进行复杂的数学计算以及创建复杂模型,进而让数据变得更有意义。 + +你还知道其它的 Python 数据挖掘库吗?你的使用经验是什么样的?请在下面的评论中和我们分享。 + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/9/top-3-python-libraries-data-science + +作者:[Dr.Michael J.Garbade][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[ucasFL](https://github.com/ucasFL) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://opensource.com/users/drmjg +[1]: https://www.liveedu.tv/andreybu/REaxr-machine-learning-model-python-sklearn-kera/oPGdP-machine-learning-model-python-sklearn-kera/ +[2]: http://www.numpy.org/ +[3]: http://pandas.pydata.org/ +[4]: https://matplotlib.org/ +[5]: https://www.liveedu.tv/guides/data-science/ +[6]: https://opensource.com/sites/default/files/uploads/matplotlib_barchart.png +[7]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/data_metrics_analytics_desktop_laptop.png?itok=9QXd7AUr diff --git a/translated/tech/20180919 Host your own cloud with Raspberry Pi NAS.md b/translated/tech/20180919 Host your own cloud with Raspberry Pi NAS.md new file mode 100644 index 0000000000..312fed7c4c --- /dev/null +++ b/translated/tech/20180919 Host your own cloud with Raspberry Pi NAS.md @@ -0,0 +1,112 @@ +Part-III 树莓派自建 NAS 云盘之云盘构建 +====== + +用树莓派 NAS 云盘来保护数据的安全! + +在前面两篇文章中(译注:文章链接 [Part-I][1],[Part-II][2]),我们讨论了用树莓派搭建一个 NAS(network-attached storage) 所需要的一些 [软硬件环境及其操作步骤][1]。我们还制定了适当的 [备份策略][2] 来保护NAS上的数据。本文中,我们将介绍讨论利用 [Nestcloud][3] 来方便快捷的存储、获取以及分享你的数据。 + +### 必要的准备工作 + +想要方便的使用 Nextcloud,需要一些必要的准备工作。首先,你需要一个指向 Nextcloud 的域名。方便起见,本文将使用 **nextcloud.pi-nas.com** 。如果你是在家庭网络里运行,你需要为该域名配置 DNS 服务(动态域名解析服务)并在路由器中开启 80 端口和 443 端口转发功能(如果需要使用 https,则需要开启 443 端口转发,如果只用 http,80 端口足以)。 + +你可以使用 [ddclient][4] 在树莓派中自动更新 DNS。 + +### 安装 Nextcloud + +为了在树莓派(参考 [Part-I][1] 中步骤设置)中运行 Nextcloud,首先用命令 **apt** 安装 以下的一些依赖软件包。 + +``` +sudo apt install unzip wget php apache2 mysql-server php-zip php-mysql php-dom php-mbstring php-gd php-curl +``` + +其次,下载 Nextcloud。在树莓派中利用 **wget** 下载其 [最新的版本][5]。在 [Part-I] 文章中,我们将两个磁盘驱动器连接到树莓派,一个用于存储当前数据,另一个用于备份。这里在数据存储盘上安装 Nextcloud,以确保每晚自动备份数据。 + +``` +sudo mkdir -p /nas/data/nextcloud +sudo chown pi /nas/data/nextcloud +cd /nas/data/ +wget https://download.nextcloud.com/server/releases/nextcloud-14.0.0.zip -O /nas/data/nextcloud.zip +unzip nextcloud.zip +sudo ln -s /nas/data/nextcloud /var/www/nextcloud +sudo chown -R www-data:www-data /nas/data/nextcloud +``` + +截止到写作本文时,Nextcloud 最新版更新到如上述代码中所示的 14.0.0 版本。Nextcloud 正在快速的迭代更新中,所以你可以在你的树莓派中安装更新一点的版本。 + +### 配置数据库 + +如上所述,Nextcloud 安装完毕。之前安装依赖软件包时就已经安装了 MySQL 数据库来存储 Nextcloud 的一些重要数据(例如,那些你创建的可以访问 Nextcloud 的用户的信息)。如果你更愿意使用 Pstgres 数据库,则上面的依赖软件包需要做一些调整。 + +以 root 权限启动 MySQL: + +``` +sudo mysql +``` + +这将会打开 SQL 提示符界面,在那里可以插入如下指令--使用数据库连接密码替换其中的占位符--为 Nextcloud 创建一个数据库。 + +``` +CREATE USER nextcloud IDENTIFIED BY ''; +CREATE DATABASE nextcloud; +GRANT ALL ON nextcloud.* TO nextcloud; +``` + +按 **Ctrl+D** 或输入 **quit** 退出 SQL 提示符界面。 + +### Web 服务器配置 + +Nextcloud 可以配置以适配于 Nginx 服务器或者其他 Web 服务器运行的环境。但本文中,我决定在我的树莓派 NAS 中运行 Apache 服务器(如果你有其他效果更好的服务器选择方案,不妨也跟我分享一下)。 + +首先为你的 Nextcloud 域名创建一个虚拟主机,创建配置文件 **/etc/apache2/sites-available/001-netxcloud.conf**,在其中输入下面的参数内容。修改其中 ServerName 为你的域名。 + +``` + +ServerName nextcloud.pi-nas.com +ServerAdmin admin@pi-nas.com +DocumentRoot /var/www/nextcloud/ + + +AllowOverride None + + +``` + +使用下面的命令来启动该虚拟主机。 + +``` +a2ensite 001-nextcloud +sudo systemctl reload apache2 +``` + +现在,你应该可以通过浏览器中输入域名访问到 web 服务器了。这里我推荐使用 HTTPS 协议而不是 HTTP 协议来访问 Nextcloud。一个简单而且免费的方法就是利用 [Certbot][7] 下载 [Let's Encrypt][6] 证书,然后设置定时任务自动刷新。这样就避免了自签证书等的麻烦。参考 [如何在树莓派中安装][8] Certbot 。在配置 Certbot 的时候,你甚至可以配置将 HTTP 自动转到 HTTPS ,例如访问 **** 自动跳转到 ****。注意,如果你的树莓派 NAS 运行在家庭路由器的下面,别忘了设置路由器的 443 端口和 80 端口转发。 + +### 配置 Nextcloud + +最后一步,通过浏览器访问 Nextcloud 来配置它。在浏览器中输入域名地址,插入上文中的数据库设置信息。这里,你可以创建 Nextcloud 管理员用户。默认情况下,数据保存目录在在 Nextcloud 目录下,所以你也无需修改我们在 [Part-II][2] 一文中设置的备份策略。 + +然后,页面会跳转到 Nextcloud 登陆界面,用刚才创建的管理员用户登陆。在设置页面中会有基础操作教程和安全安装教程(这里是访问 settings/admin)。 + +恭喜你,到此为止,你已经成功在树莓派中安装了你自己的云 Nextcloud。去 Nextcloud 主页 [下载 Nextcloud 客户端][9],客户端可以同步数据并且离线访问服务器。移动端甚至可以上传图片等资源,然后电脑桌面都可以去访问它们。 + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/9/host-cloud-nas-raspberry-pi + +作者:[Manuel Dewald][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[jrg](https://github.com/jrglinux) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://opensource.com/users/ntlx +[1]: https://opensource.com/article/18/7/network-attached-storage-Raspberry-Pi +[2]: https://opensource.com/article/18/8/automate-backups-raspberry-pi +[3]: https://nextcloud.com/ +[4]: https://sourceforge.net/p/ddclient/wiki/Home/ +[5]: https://nextcloud.com/install/#instructions-server +[6]: https://letsencrypt.org/ +[7]: https://certbot.eff.org/ +[8]: https://certbot.eff.org/lets-encrypt/debianother-apache +[9]: https://nextcloud.com/install/#install-clients + diff --git a/translated/tech/20180920 8 Python packages that will simplify your life with Django.md b/translated/tech/20180920 8 Python packages that will simplify your life with Django.md new file mode 100644 index 0000000000..f242007433 --- /dev/null +++ b/translated/tech/20180920 8 Python packages that will simplify your life with Django.md @@ -0,0 +1,121 @@ +简化 Django 开发的八个 Python 包 +====== + +这个月的 Python 专栏将介绍一些 Django 包,它们有益于你的工作,以及你的个人或业余项目。 + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/water-stone-balance-eight-8.png?itok=1aht_V5V) + +Django 开发者们,在这个月的 Python 专栏中,我们会介绍一些能帮助你们的软件包。这些软件包是我们最喜欢的 [Django][1] 库,能够节省开发时间,减少样板代码,通常来说,这会让我们的生活更加轻松。我们为 Django 应用准备了六个包,为 Django 的 REST 框架准备了两个包。几乎所有我们的项目里,都用到了这些包,真的,不是说笑。 + +不过在继续阅读之前,请先看看我们关于[让 Django 管理后台更安全][2]的几个提示,以及这篇关于 [5 个最受欢迎的开源 Django 包][3] 的文章。 + +### 有用又省时的工具集合:django-extensions + +[Django-extensions][4] 这个 Django 包非常受欢迎,全是有用的工具,比如下面这些管理命令: + + * **shell_plus** 打开 Django 的管理 shell,这个 shell 已经自动导入了所有的数据库模型。在测试复杂的数据关系时,就不需要再从几个不同的应用里做 import 的操作了。 + * **clean_pyc** 删除项目目录下所有位置的 .pyc 文件 + * **create_template_tags** 在指定的应用下,创建模板标签的目录结构。 + * **describe_form** 输出模型的表单定义,可以粘贴到 forms.py 文件中。(需要注意的是,这种方法创建的是普通 Django 表单,而不是模型表单。) + * **notes** 输出你项目里所有带 TODO,FIXME 等标记的注释。 + +Django-extensions 还包括几个有用的抽象基类,在定义模型时,它们能满足常见的模式。当你需要以下模型时,可以继承这些基类: + + + * **TimeStampedModel** : 这个模型的基类包含了 **created** 字段和 **modified** 字段,还有一个 **save()** 方法,在适当的场景下,该方法自动更新 created 和 modified 字段的值。 + * **ActivatorModel** : 如果你的模型需要像 **status**,**activate_date** 和 **deactivate_date** 这样的字段,可以使用这个基类。它还自带了一个启用 **.active()** 和 **.inactive()** 查询集的 manager。 + * **TitleDescriptionModel** 和 **TitleSlugDescriptionModel** : 这两个模型包括了 **title** 和 **description** 字段,其中 description 字段还包括 **slug**,它根据 **title** 字段自动产生。 + +Django-extensions 还有其他更多的功能,也许对你的项目有帮助,所以,去浏览一下它的[文档][5]吧! + +### 12 因子应用的配置:django-environ + +在 Django 项目的配置方面,[Django-environ][6] 提供了符合 [12 因子应用][7] 方法论的管理方法。它是其他一些库的集合,包括 [envparse][8] 和 [honcho][9] 等。安装了 django-environ 之后,在项目的根目录创建一个 .env 文件,用这个文件去定义那些随环境不同而不同的变量,或者需要保密的变量。(比如 API keys,是否启用 debug,数据库的 URLs 等) + +然后,在项目的 settings.py 中引入 **environ**,并参考[官方文档的例子][10]设置好 **environ.PATH()** 和 **environ.Env()**。就可以通过 **env('VARIABLE_NAME')** 来获取 .env 文件中定义的变量值了。 + +### 创建出色的管理命令:django-click + +[Django-click][11] 是基于 [Click][12] 的, ( 我们[之前推荐过][13]… [两次][14] Click),它对编写 Django 管理命令很有帮助。这个库没有很多文档,但是代码仓库中有个存放[测试命令][15]的目录,非常有参考价值。 Django-click 基本的 Hello World 命令是这样写的: + +``` +# app_name.management.commands.hello.py +import djclick as click + +@click.command() +@click.argument('name') +def command(name): + click.secho(f'Hello, {name}') +``` + +在命令行下调用它,这样执行即可: + +``` +>> ./manage.py hello Lacey +Hello, Lacey +``` + +### 处理有限状态机:django-fsm + +[Django-fsm][16] 给 Django 的模型添加了有限状态机的支持。如果你管理一个新闻网站,想用类似于“写作中”,“编辑中”,“已发布”来流转文章的状态,django-fsm 能帮你定义这些状态,还能管理状态变化的规则与限制。 + +Django-fsm 为模型提供了 FSMField 字段,用来定义模型实例的状态。用 django-fsm 的 **@transition** 修饰符,可以定义状态变化的方法,并处理状态变化的任何副作用。 + +虽然 django-fsm 文档很轻量,不过 [Django 中的工作流(状态)][17] 这篇 GitHubGist 对有限状态机和 django-fsm 做了非常好的介绍。 + +### 联系人表单:#django-contact-form + +联系人表单可以说是网站的标配。但是不要自己去写全部的样板代码,用 [django-contact-form][18] 在几分钟内就可以搞定。它带有一个可选的能过滤垃圾邮件的表单类(也有不过滤的普通表单类)和一个 **ContactFormView** 基类,基类的方法可以覆盖或自定义修改。而且它还能引导你完成模板的创建,好让表单正常工作。 + +### 用户注册和认证:django-allauth + +[Django-allauth][19] 是一个 Django 应用,它为用户注册,登录注销,密码重置,还有第三方用户认证(比如 GitHub 或 Twitter)提供了视图,表单和 URLs,支持邮件地址作为用户名的认证方式,而且有大量的文档记录。第一次用的时候,它的配置可能会让人有点晕头转向;请仔细阅读[安装说明][20],在[自定义你的配置][21]时要专注,确保启用某个功能的所有配置都用对了。 + +### 处理 Django REST 框架的用户认证:django-rest-auth + +如果 Django 开发中涉及到对外提供 API,你很可能用到了 [Django REST Framework][22] (DRF)。如果你在用 DRF,那么你应该试试 django-rest-auth,它提供了用户注册,登录/注销,密码重置和社交媒体认证的 endpoints (是通过添加 django-allauth 的支持来实现的,这两个包协作得很好)。 + +### Django REST 框架的 API 可视化:django-rest-swagger + +[Django REST Swagger][24] 提供了一个功能丰富的用户界面,用来和 Django REST 框架的 API 交互。你只需要安装 Django REST Swagger,把它添加到 Django 项目的 installed apps 中,然后在 urls.py 中添加 Swagger 的视图和 URL 模式就可以了,剩下的事情交给 API 的 docstring 处理。 + +![](https://opensource.com/sites/default/files/uploads/swagger-ui.png) + +API 的用户界面按照 app 的维度展示了所有 endpoints 和可用方法,并列出了这些 endpoints 的可用操作,而且它提供了和 API 交互的功能(比如添加/删除/获取记录)。django-rest-swagger 从 API 视图中的 docstrings 生成每个 endpoint 的文档,通过这种方法,为你的项目创建了一份 API 文档,这对你,对前端开发人员和用户都很有用。 + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/9/django-packages + +作者:[Jeff Triplett][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[belitex](https://github.com/belitex) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://opensource.com/users/laceynwilliams +[1]: https://www.djangoproject.com/ +[2]: https://opensource.com/article/18/1/10-tips-making-django-admin-more-secure +[3]: https://opensource.com/business/15/12/5-favorite-open-source-django-packages +[4]: https://django-extensions.readthedocs.io/en/latest/ +[5]: https://django-extensions.readthedocs.io/ +[6]: https://django-environ.readthedocs.io/en/latest/ +[7]: https://www.12factor.net/ +[8]: https://github.com/rconradharris/envparse +[9]: https://github.com/nickstenning/honcho +[10]: https://django-environ.readthedocs.io/ +[11]: https://github.com/GaretJax/django-click +[12]: http://click.pocoo.org/5/ +[13]: https://opensource.com/article/18/9/python-libraries-side-projects +[14]: https://opensource.com/article/18/5/3-python-command-line-tools +[15]: https://github.com/GaretJax/django-click/tree/master/djclick/test/testprj/testapp/management/commands +[16]: https://github.com/viewflow/django-fsm +[17]: https://gist.github.com/Nagyman/9502133 +[18]: https://django-contact-form.readthedocs.io/en/1.5/ +[19]: https://django-allauth.readthedocs.io/en/latest/ +[20]: https://django-allauth.readthedocs.io/en/latest/installation.html +[21]: https://django-allauth.readthedocs.io/en/latest/configuration.html +[22]: http://www.django-rest-framework.org/ +[23]: https://django-rest-auth.readthedocs.io/ +[24]: https://django-rest-swagger.readthedocs.io/en/latest/ \ No newline at end of file diff --git a/translated/tech/20180924 How To Find Out Which Port Number A Process Is Using In Linux.md b/translated/tech/20180924 How To Find Out Which Port Number A Process Is Using In Linux.md new file mode 100644 index 0000000000..ed3402e0fa --- /dev/null +++ b/translated/tech/20180924 How To Find Out Which Port Number A Process Is Using In Linux.md @@ -0,0 +1,270 @@ +如何在 Linux 中查看进程占用的端口号 +====== +对于 Linux 系统管理员来说,清楚某个服务是否正确地绑定或监听某个端口,是至关重要的。如果你需要处理端口相关的问题,这篇文章可能会对你有用。 + +端口是 Linux 系统上特定进程之间逻辑连接的标识,包括物理端口和软件端口。由于 Linux 操作系统是一个软件,因此本文只讨论软件端口。软件端口始终与主机的 IP 地址和相关的通信协议相关联,因此端口常用于区分应用程序。大部分涉及到网络的服务都必须打开一个套接字来监听传入的网络请求,而每个服务都使用一个独立的套接字。 + +**推荐阅读:** +**(#)** [在 Linux 上查看进程 ID 的 4 种方法][1] +**(#)** [在 Linux 上终止进程的 3 种方法][2] + +套接字是和 IP 地址,软件端口和协议结合起来使用的,而端口号对传输控制协议(Transmission Control Protocol, TCP)和 用户数据报协议(User Datagram Protocol, UDP)协议都适用,TCP 和 UDP 都可以使用0到65535之间的端口号进行通信。 + +以下是端口分配类别: + + * `0-1023:` 常用端口和系统端口 + * `1024-49151:` 软件的注册端口 + * `49152-65535:` 动态端口或私有端口 + + + +在 Linux 上的 `/etc/services` 文件可以查看到更多关于保留端口的信息。 + +``` +# less /etc/services +# /etc/services: +# $Id: services,v 1.55 2013/04/14 ovasik Exp $ +# +# Network services, Internet style +# IANA services version: last updated 2013-04-10 +# +# Note that it is presently the policy of IANA to assign a single well-known +# port number for both TCP and UDP; hence, most entries here have two entries +# even if the protocol doesn't support UDP operations. +# Updated from RFC 1700, ``Assigned Numbers'' (October 1994). Not all ports +# are included, only the more common ones. +# +# The latest IANA port assignments can be gotten from +# http://www.iana.org/assignments/port-numbers +# The Well Known Ports are those from 0 through 1023. +# The Registered Ports are those from 1024 through 49151 +# The Dynamic and/or Private Ports are those from 49152 through 65535 +# +# Each line describes one service, and is of the form: +# +# service-name port/protocol [aliases ...] [# comment] + +tcpmux 1/tcp # TCP port service multiplexer +tcpmux 1/udp # TCP port service multiplexer +rje 5/tcp # Remote Job Entry +rje 5/udp # Remote Job Entry +echo 7/tcp +echo 7/udp +discard 9/tcp sink null +discard 9/udp sink null +systat 11/tcp users +systat 11/udp users +daytime 13/tcp +daytime 13/udp +qotd 17/tcp quote +qotd 17/udp quote +msp 18/tcp # message send protocol (historic) +msp 18/udp # message send protocol (historic) +chargen 19/tcp ttytst source +chargen 19/udp ttytst source +ftp-data 20/tcp +ftp-data 20/udp +# 21 is registered to ftp, but also used by fsp +ftp 21/tcp +ftp 21/udp fsp fspd +ssh 22/tcp # The Secure Shell (SSH) Protocol +ssh 22/udp # The Secure Shell (SSH) Protocol +telnet 23/tcp +telnet 23/udp +# 24 - private mail system +lmtp 24/tcp # LMTP Mail Delivery +lmtp 24/udp # LMTP Mail Delivery + +``` + +可以使用以下六种方法查看端口信息。 + + * `ss:` ss 可以用于转储套接字统计信息。 + * `netstat:` netstat 可以显示打开的套接字列表。 + * `lsof:` lsof 可以列出打开的文件。 + * `fuser:` fuser 可以列出那些打开了文件的进程的进程 ID。 + * `nmap:` nmap 是网络检测工具和端口扫描程序。 + * `systemctl:` systemctl 是 systemd 系统的控制管理器和服务管理器。 + + + +以下我们将找出 `sshd` 守护进程所使用的端口号。 + +### 方法1:使用 ss 命令 + +`ss` 一般用于转储套接字统计信息。它能够输出类似于 `netstat` 输出的信息,但它可以比其它工具显示更多的 TCP 信息和状态信息。 + +它还可以显示所有类型的套接字统计信息,包括 PACKET、TCP、UDP、DCCP、RAW、Unix 域等。 + + +``` +# ss -tnlp | grep ssh +LISTEN 0 128 *:22 *:* users:(("sshd",pid=997,fd=3)) +LISTEN 0 128 :::22 :::* users:(("sshd",pid=997,fd=4)) +``` + +也可以使用端口号来检查。 + +``` +# ss -tnlp | grep ":22" +LISTEN 0 128 *:22 *:* users:(("sshd",pid=997,fd=3)) +LISTEN 0 128 :::22 :::* users:(("sshd",pid=997,fd=4)) +``` + +### 方法2:使用 netstat 命令 + +`netstat` 能够显示网络连接、路由表、接口统计信息、伪装连接以及多播成员。 + +默认情况下,`netstat` 会列出打开的套接字。如果不指定任何地址族,则会显示所有已配置地址族的活动套接字。但 `netstat` 已经过时了,一般会使用 `ss` 来替代。 + +``` +# netstat -tnlp | grep ssh +tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 997/sshd +tcp6 0 0 :::22 :::* LISTEN 997/sshd +``` + +也可以使用端口号来检查。 + +``` +# netstat -tnlp | grep ":22" +tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1208/sshd +tcp6 0 0 :::22 :::* LISTEN 1208/sshd +``` + +### 方法3:使用 lsof 命令 + +`lsof` 能够列出打开的文件,并列出系统上被进程打开的文件的相关信息。 + +``` +# lsof -i -P | grep ssh +COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME +sshd 11584 root 3u IPv4 27625 0t0 TCP *:22 (LISTEN) +sshd 11584 root 4u IPv6 27627 0t0 TCP *:22 (LISTEN) +sshd 11592 root 3u IPv4 27744 0t0 TCP vps.2daygeek.com:ssh->103.5.134.167:49902 (ESTABLISHED) +``` + +也可以使用端口号来检查。 + +``` +# lsof -i tcp:22 +COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME +sshd 1208 root 3u IPv4 20919 0t0 TCP *:ssh (LISTEN) +sshd 1208 root 4u IPv6 20921 0t0 TCP *:ssh (LISTEN) +sshd 11592 root 3u IPv4 27744 0t0 TCP vps.2daygeek.com:ssh->103.5.134.167:49902 (ESTABLISHED) +``` + +### 方法4:使用 fuser 命令 + +`fuser` 工具会将本地系统上打开了文件的进程的进程 ID 显示在标准输出中。 + +``` +# fuser -v 22/tcp + USER PID ACCESS COMMAND +22/tcp: root 1208 F.... sshd + root 12388 F.... sshd + root 49339 F.... sshd +``` + +### 方法5:使用 nmap 命令 + +`nmap`(“Network Mapper”)是一款用于网络检测和安全审计的开源工具。它最初用于对大型网络进行快速扫描,但它对于单个主机的扫描也有很好的表现。 + +`nmap` 使用原始 IP 数据包来确定网络上可用的主机,这些主机的服务(包括应用程序名称和版本)、主机运行的操作系统(包括操作系统版本等信息)、正在使用的数据包过滤器或防火墙的类型,以及很多其它信息。 + +``` +# nmap -sV -p 22 localhost + +Starting Nmap 6.40 ( http://nmap.org ) at 2018-09-23 12:36 IST +Nmap scan report for localhost (127.0.0.1) +Host is up (0.000089s latency). +Other addresses for localhost (not scanned): 127.0.0.1 +PORT STATE SERVICE VERSION +22/tcp open ssh OpenSSH 7.4 (protocol 2.0) + +Service detection performed. Please report any incorrect results at http://nmap.org/submit/ . +Nmap done: 1 IP address (1 host up) scanned in 0.44 seconds +``` + +### 方法6:使用 systemctl 命令 + +`systemctl` 是 systemd 系统的控制管理器和服务管理器。它取代了旧的 SysV init 系统管理,目前大多数现代 Linux 操作系统都采用了 systemd。 + +**推荐阅读:** +**(#)** [chkservice – Linux 终端上的 systemd 单元管理工具][3] +**(#)** [如何查看 Linux 系统上正在运行的服务][4] + +``` +# systemctl status sshd +● sshd.service - OpenSSH server daemon + Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; vendor preset: enabled) + Active: active (running) since Sun 2018-09-23 02:08:56 EDT; 6h 11min ago + Docs: man:sshd(8) + man:sshd_config(5) + Main PID: 11584 (sshd) + CGroup: /system.slice/sshd.service + └─11584 /usr/sbin/sshd -D + +Sep 23 02:08:56 vps.2daygeek.com systemd[1]: Starting OpenSSH server daemon... +Sep 23 02:08:56 vps.2daygeek.com sshd[11584]: Server listening on 0.0.0.0 port 22. +Sep 23 02:08:56 vps.2daygeek.com sshd[11584]: Server listening on :: port 22. +Sep 23 02:08:56 vps.2daygeek.com systemd[1]: Started OpenSSH server daemon. +Sep 23 02:09:15 vps.2daygeek.com sshd[11589]: Connection closed by 103.5.134.167 port 49899 [preauth] +Sep 23 02:09:41 vps.2daygeek.com sshd[11592]: Accepted password for root from 103.5.134.167 port 49902 ssh2 +``` + +以上输出的内容显示了最近一次启动 `sshd` 服务时 `ssh` 服务的监听端口。但它不会将最新日志更新到输出中。 + +``` +# systemctl status sshd +● sshd.service - OpenSSH server daemon + Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; vendor preset: enabled) + Active: active (running) since Thu 2018-09-06 07:40:59 IST; 2 weeks 3 days ago + Docs: man:sshd(8) + man:sshd_config(5) + Main PID: 1208 (sshd) + CGroup: /system.slice/sshd.service + ├─ 1208 /usr/sbin/sshd -D + ├─23951 sshd: [accepted] + └─23952 sshd: [net] + +Sep 23 12:50:36 vps.2daygeek.com sshd[23909]: Invalid user pi from 95.210.113.142 port 51666 +Sep 23 12:50:36 vps.2daygeek.com sshd[23909]: input_userauth_request: invalid user pi [preauth] +Sep 23 12:50:37 vps.2daygeek.com sshd[23911]: pam_unix(sshd:auth): check pass; user unknown +Sep 23 12:50:37 vps.2daygeek.com sshd[23911]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=95.210.113.142 +Sep 23 12:50:37 vps.2daygeek.com sshd[23909]: pam_unix(sshd:auth): check pass; user unknown +Sep 23 12:50:37 vps.2daygeek.com sshd[23909]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=95.210.113.142 +Sep 23 12:50:39 vps.2daygeek.com sshd[23911]: Failed password for invalid user pi from 95.210.113.142 port 51670 ssh2 +Sep 23 12:50:39 vps.2daygeek.com sshd[23909]: Failed password for invalid user pi from 95.210.113.142 port 51666 ssh2 +Sep 23 12:50:40 vps.2daygeek.com sshd[23911]: Connection closed by 95.210.113.142 port 51670 [preauth] +Sep 23 12:50:40 vps.2daygeek.com sshd[23909]: Connection closed by 95.210.113.142 port 51666 [preauth] +``` + +大部分情况下,以上的输出不会显示进程的实际端口号。这时更建议使用以下这个 `journalctl` 命令检查日志文件中的详细信息。 + +``` +# journalctl | grep -i "openssh\|sshd" +Sep 23 02:08:56 vps138235.vps.ovh.ca sshd[997]: Received signal 15; terminating. +Sep 23 02:08:56 vps138235.vps.ovh.ca systemd[1]: Stopping OpenSSH server daemon... +Sep 23 02:08:56 vps138235.vps.ovh.ca systemd[1]: Starting OpenSSH server daemon... +Sep 23 02:08:56 vps138235.vps.ovh.ca sshd[11584]: Server listening on 0.0.0.0 port 22. +Sep 23 02:08:56 vps138235.vps.ovh.ca sshd[11584]: Server listening on :: port 22. +Sep 23 02:08:56 vps138235.vps.ovh.ca systemd[1]: Started OpenSSH server daemon. +``` + +-------------------------------------------------------------------------------- + +via: https://www.2daygeek.com/how-to-find-out-which-port-number-a-process-is-using-in-linux/ + +作者:[Prakash Subramanian][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[HankChow](https://github.com/HankChow) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://www.2daygeek.com/author/prakash/ +[1]: https://www.2daygeek.com/how-to-check-find-the-process-id-pid-ppid-of-a-running-program-in-linux/ +[2]: https://www.2daygeek.com/kill-terminate-a-process-in-linux-using-kill-pkill-killall-command/ +[3]: https://www.2daygeek.com/chkservice-a-tool-for-managing-systemd-units-from-linux-terminal/ +[4]: https://www.2daygeek.com/how-to-check-all-running-services-in-linux/ + diff --git a/translated/tech/20180924 Make The Output Of Ping Command Prettier And Easier To Read.md b/translated/tech/20180924 Make The Output Of Ping Command Prettier And Easier To Read.md new file mode 100644 index 0000000000..efca96da23 --- /dev/null +++ b/translated/tech/20180924 Make The Output Of Ping Command Prettier And Easier To Read.md @@ -0,0 +1,128 @@ +如何让 Ping 的输出更简单易读 +====== + +![](https://www.ostechnix.com/wp-content/uploads/2018/09/prettyping-720x340.png) + +众所周知,`ping` 命令可以用来检查目标主机是否可达。使用 `ping` 命令的时候,会发送一个 ICMP Echo 请求,通过目标主机的响应与否来确定目标主机的状态。如果你经常使用 `ping` 命令,你可以尝试一下 `prettyping`。Prettyping 只是将一个标准的 ping 工具增加了一层封装,在运行标准 ping 命令的同时添加了颜色和 unicode 字符解析输出,所以它的输出更漂亮紧凑、清晰易读。它是用 `bash` 和 `awk` 编写的免费开源工具,支持大部分类 Unix 操作系统,包括 GNU/Linux、FreeBSD 和 Mac OS X。Prettyping 除了美化 ping 命令的输出,还有很多值得注意的功能。 + + * 检测丢失的数据包并在输出中标记出来。 + * 显示实时数据。每次收到响应后,都会更新统计数据,而对于普通 ping 命令,只会在执行结束后统计。 + * 能够在输出结果不混乱的前提下灵活处理“未知信息”(例如错误信息)。 + * 能够避免输出重复的信息。 + * 兼容常用的 ping 工具命令参数。 + * 能够由普通用户执行。 + * 可以将输出重定向到文件中。 + * 不需要安装,只需要下载二进制文件,赋予可执行权限即可执行。 + * 快速且轻巧。 + * 输出结果清晰直观。 + + + +### 安装 Prettyping + +如上所述,Prettyping 是一个绿色软件,不需要任何安装,只要使用以下命令下载 Prettyping 二进制文件: + +``` +$ curl -O https://raw.githubusercontent.com/denilsonsa/prettyping/master/prettyping +``` + +将二进制文件放置到 `$PATH`(例如 `/usr/local/bin`)中: + +``` +$ sudo mv prettyping /usr/local/bin +``` + +然后对其赋予可执行权限: + +``` +$ sudo chmod +x /usr/local/bin/prettyping +``` + +就可以使用了。 + +### 让 ping 的输出清晰易读 + +安装完成后,通过 `prettyping` 来 ping 任何主机或 IP 地址,就可以以图形方式查看输出。 + +``` +$ prettyping ostechnix.com +``` + +输出效果大概会是这样: + +![](https://www.ostechnix.com/wp-content/uploads/2018/09/prettyping-in-action.gif) + +如果你不带任何参数执行 `prettyping`,它就会一直运行直到被 ctrl + c 中断。 + +由于 Prettyping 只是一个对普通 ping 命令的封装,所以常用的 ping 参数也是有效的。例如使用 `-c 5` 来指定 ping 一台主机的 5 次: + +``` +$ prettyping -c 5 ostechnix.com +``` + +Prettyping 默认会使用彩色输出,如果你不喜欢彩色的输出,可以加上 `--nocolor` 参数: + +``` +$ prettyping --nocolor ostechnix.com +``` + +同样的,也可以用 `--nomulticolor` 参数禁用多颜色支持: + +``` +$ prettyping --nomulticolor ostechnix.com +``` + +使用 `--nounicode` 参数禁用 unicode 字符: + +![](https://www.ostechnix.com/wp-content/uploads/2018/09/prettyping-without-unicode-support.png) + +如果你的终端不支持 **UTF-8**,或者无法修复系统中的 unicode 字体,只需要加上 `--nounicode` 参数就能轻松解决。 + +Prettyping 支持将输出的内容重定向到文件中,例如执行以下这个命令会将 `prettyping ostechnix.com` 的输出重定向到 `ostechnix.txt` 中: + +``` +$ prettyping ostechnix.com | tee ostechnix.txt +``` + +Prettyping 还有很多选项帮助你完成各种任务,例如: + + * 启用/禁用延时图例(默认启用) + * 强制按照终端的格式输出(默认自动) + * 在统计数据中统计最后的 n 次 ping(默认 60 次) + * 覆盖对终端尺寸的检测 + * 覆盖 awk 解释器(默认不覆盖) + * 覆盖 ping 工具(默认不覆盖) + + + +查看帮助文档可以了解更多: + +``` +$ prettyping --help +``` + +尽管 prettyping 没有添加任何额外功能,但我个人喜欢它的这些优点: + + * 实时统计 - 可以随时查看所有实时统计信息,标准 `ping` 命令只会在命令执行结束后才显示统计信息。 + * 紧凑的显示 - 可以在终端看到更长的时间跨度。 + * 检测丢失的数据包并显示出来。 + + + +如果你一直在寻找可视化显示 `ping` 命令输出的工具,那么 Prettyping 肯定会有所帮助。尝试一下,你不会失望的。 + + + +-------------------------------------------------------------------------------- + +via: https://www.ostechnix.com/prettyping-make-the-output-of-ping-command-prettier-and-easier-to-read/ + +作者:[SK][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[HankChow](https://github.com/HankChow) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://www.ostechnix.com/author/sk/ + diff --git a/translated/tech/20180927 How to Use RAR files in Ubuntu Linux.md b/translated/tech/20180927 How to Use RAR files in Ubuntu Linux.md new file mode 100644 index 0000000000..3521b21a8a --- /dev/null +++ b/translated/tech/20180927 How to Use RAR files in Ubuntu Linux.md @@ -0,0 +1,98 @@ +如何在 Ubuntu Linux 中使用 RAR 文件 +====== +[RAR][1] 是一种非常好的归档文件格式。但相比之下 7-zip 能提供了更好的压缩率,并且默认情况下还可以在多个平台上轻松支持 Zip 文件。不过 RAR 仍然是最流行的归档格式之一。然而 [Ubuntu][2] 自带的归档管理器却不支持提取 RAR 文件,也不允许创建 RAR 文件。 + +方法总比问题多。只要安装 `unrar` 这款由 [RARLAB][3] 提供的免费软件,就能在 Ubuntu 上支持提取RAR文件了。你也可以试安装 `rar` 来创建和管理 RAR 文件。 + +![RAR files in Ubuntu Linux][4] + +### 提取 RAR 文件 + +在未安装 unrar 的情况下,提取 RAR 文件会报出“未能提取”错误,就像下面这样(以 [Ubuntu 18.04][5] 为例): + +![Error in RAR extraction in Ubuntu][6] + +如果要解决这个错误并提取 RAR 文件,请按照以下步骤安装 unrar: + +打开终端并输入: + +``` + sudo apt-get install unrar + +``` + +安装 unrar 后,直接输入 `unrar` 就可以看到它的用法以及如何使用这个工具处理 RAR 文件。 + +最常用到的功能是提取 RAR 文件。因此,可以**通过右键单击 RAR 文件并执行提取**,也可以借助此以下命令通过终端执行操作: + +``` +unrar x FileName.rar + +``` + +结果类似以下这样: + +![Using unrar in Ubuntu][7] + +如果家目录中不存在对应的文件,就必须使用 `cd` 命令移动到目标目录下。例如 RAR 文件如果在 `Music` 目录下,只需要使用 `cd Music` 就可以移动到相应的目录,然后提取 RAR 文件。 + +### 创建和管理 RAR 文件 + +![Using rar archive in Ubuntu Linux][8] + +`unrar` 不允许创建 RAR 文件。因此还需要安装 `rar` 命令行工具才能创建 RAR 文件。 + +要创建 RAR 文件,首先需要通过以下命令安装 rar: + +``` +sudo apt-get install rar + +``` + +按照下面的命令语法创建 RAR 文件: + +``` +rar a ArchiveName File_1 File_2 Dir_1 Dir_2 + +``` + +按照这个格式输入命令时,它会将目录中的每个文件添加到 RAR 文件中。如果需要某一个特定的文件,就要指定文件确切的名称或路径。 + +默认情况下,RAR 文件会放置在**家目录**中。 + +以类似的方式,可以更新或管理 RAR 文件。同样是使用以下的命令语法: + +``` +rar u ArchiveName Filename + +``` + +在终端输入 `rar` 就可以列出 RAR 工具的相关命令。 + +### 总结 + +现在你已经知道如何在 Ubuntu 上管理 RAR 文件了,你会更喜欢使用 7-zip、Zip 或 Tar.xz 吗? + +欢迎在评论区中评论。 + +-------------------------------------------------------------------------------- + +via: https://itsfoss.com/use-rar-ubuntu-linux/ + +作者:[Ankush Das][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[HankChow](https://github.com/HankChow) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://itsfoss.com/author/ankush/ +[1]: https://www.rarlab.com/rar_file.htm +[2]: https://www.ubuntu.com/ +[3]: https://www.rarlab.com/ +[4]: https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/09/rar-ubuntu-linux.png +[5]: https://itsfoss.com/things-to-do-after-installing-ubuntu-18-04/ +[6]: https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/08/extract-rar-error.jpg +[7]: https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/08/unrar-rar-extraction.jpg +[8]: https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/09/rar-update-create.jpg +