diff --git a/published/20060430 Linux Find Out Last System Reboot Time and Date Command.md b/published/20060430 Linux Find Out Last System Reboot Time and Date Command.md new file mode 100644 index 0000000000..9569c998f4 --- /dev/null +++ b/published/20060430 Linux Find Out Last System Reboot Time and Date Command.md @@ -0,0 +1,199 @@ +如何在 Linux 系统查询机器最近重启时间 +====== + +在你的 Linux 或类 UNIX 系统中,你是如何查询系统上次重新启动的日期和时间?怎样显示系统关机的日期和时间? `last` 命令不仅可以按照时间从近到远的顺序列出该会话的特定用户、终端和主机名,而且还可以列出指定日期和时间登录的用户。输出到终端的每一行都包括用户名、会话终端、主机名、会话开始和结束的时间、会话持续的时间。要查看 Linux 或类 UNIX 系统重启和关机的时间和日期,可以使用下面的命令。 + +- `last` 命令 +- `who` 命令 + + +### 使用 who 命令来查看系统重新启动的时间/日期 + +你需要在终端使用 [who][1] 命令来打印有哪些人登录了系统,`who` 命令同时也会显示上次系统启动的时间。使用 `last` 命令来查看系统重启和关机的日期和时间,运行: + +``` +$ who -b +``` + +示例输出: + +``` +system boot 2017-06-20 17:41 +``` + +使用 `last` 命令来查询最近登录到系统的用户和系统重启的时间和日期。输入: + +``` +$ last reboot | less +``` + +示例输出: + +[![Fig.01: last command in action][2]][2] + +或者,尝试输入: + +``` +$ last reboot | head -1 +``` + +示例输出: + +``` +reboot system boot 4.9.0-3-amd64 Sat Jul 15 19:19 still running +``` + +`last` 命令通过查看文件 `/var/log/wtmp` 来显示自 wtmp 文件被创建时的所有登录(和登出)的用户。每当系统重新启动时,这个伪用户 `reboot` 就会登录。因此,`last reboot` 命令将会显示自该日志文件被创建以来的所有重启信息。 + +### 查看系统上次关机的时间和日期 + +可以使用下面的命令来显示上次关机的日期和时间: + +``` +$ last -x|grep shutdown | head -1 +``` + +示例输出: + +``` +shutdown system down 2.6.15.4 Sun Apr 30 13:31 - 15:08 (01:37) +``` + +命令中, + +* `-x`:显示系统关机和运行等级改变信息 + + +这里是 `last` 命令的其它的一些选项: + +``` +$ last +$ last -x +$ last -x reboot +$ last -x shutdown +``` + +示例输出: + +![Fig.01: How to view last Linux System Reboot Date/Time ][3] + +### 查看系统正常的运行时间 + +评论区的读者建议的另一个命令如下: + +``` +$ uptime -s +``` + +示例输出: + +``` +2017-06-20 17:41:51 +``` + +### OS X/Unix/FreeBSD 查看最近重启和关机时间的命令示例 + +在终端输入下面的命令: + +``` +$ last reboot +``` + +在 OS X 示例输出结果如下: + +``` +reboot ~ Fri Dec 18 23:58 +reboot ~ Mon Dec 14 09:54 +reboot ~ Wed Dec 9 23:21 +reboot ~ Tue Nov 17 21:52 +reboot ~ Tue Nov 17 06:01 +reboot ~ Wed Nov 11 12:14 +reboot ~ Sat Oct 31 13:40 +reboot ~ Wed Oct 28 15:56 +reboot ~ Wed Oct 28 11:35 +reboot ~ Tue Oct 27 00:00 +reboot ~ Sun Oct 18 17:28 +reboot ~ Sun Oct 18 17:11 +reboot ~ Mon Oct 5 09:35 +reboot ~ Sat Oct 3 18:57 + + +wtmp begins Sat Oct 3 18:57 +``` + +查看关机日期和时间,输入: + +``` +$ last shutdown +``` + +示例输出: + +``` +shutdown ~ Fri Dec 18 23:57 +shutdown ~ Mon Dec 14 09:53 +shutdown ~ Wed Dec 9 23:20 +shutdown ~ Tue Nov 17 14:24 +shutdown ~ Mon Nov 16 21:15 +shutdown ~ Tue Nov 10 13:15 +shutdown ~ Sat Oct 31 13:40 +shutdown ~ Wed Oct 28 03:10 +shutdown ~ Sun Oct 18 17:27 +shutdown ~ Mon Oct 5 09:23 + + +wtmp begins Sat Oct 3 18:57 +``` + +### 如何查看是谁重启和关闭机器? + +你需要[启用 psacct 服务然后运行下面的命令][4]来查看执行过的命令(包括用户名),在终端输入 [lastcomm][5] 命令查看信息 + +``` +# lastcomm userNameHere +# lastcomm commandNameHere +# lastcomm | more +# lastcomm reboot +# lastcomm shutdown +### 或者查看重启和关机时间 +# lastcomm | egrep 'reboot|shutdown' +``` + +示例输出: + +``` +reboot S X root pts/0 0.00 secs Sun Dec 27 23:49 +shutdown S root pts/1 0.00 secs Sun Dec 27 23:45 +``` + +我们可以看到 root 用户在当地时间 12 月 27 日星期二 23:49 在 pts/0 重新启动了机器。 + +### 参见 + +* 更多信息可以查看 man 手册(`man last`)和参考文章 [如何在 Linux 服务器上使用 tuptime 命令查看历史和统计的正常的运行时间][6]。 + +### 关于作者 + +作者是 nixCraft 的创立者,同时也是一名经验丰富的系统管理员,也是 Linux,类 Unix 操作系统 shell 脚本的培训师。他曾与全球各行各业的客户工作过,包括 IT,教育,国防和空间研究以及非营利部门等等。你可以在 [Twitter][7]、[Facebook][8]、[Google+][9] 关注他。 + + +-------------------------------------------------------------------------------- + +via: https://www.cyberciti.biz/tips/linux-last-reboot-time-and-date-find-out.html + +作者:[Vivek Gite][a] +译者:[amwps290](https://github.com/amwps290) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.cyberciti.biz/ +[1]:https://www.cyberciti.biz/faq/unix-linux-who-command-examples-syntax-usage/ "See Linux/Unix who command examples for more info" +[2]:https://www.cyberciti.biz/tips/wp-content/uploads/2006/04/last-reboot.jpg +[3]:https://www.cyberciti.biz/media/new/tips/2006/04/check-last-time-system-was-rebooted.jpg +[4]:https://www.cyberciti.biz/tips/howto-log-user-activity-using-process-accounting.html +[5]:https://www.cyberciti.biz/faq/linux-unix-lastcomm-command-examples-usage-syntax/ "See Linux/Unix lastcomm command examples for more info" +[6]:https://www.cyberciti.biz/hardware/howto-see-historical-statistical-uptime-on-linux-server/ +[7]:https://twitter.com/nixcraft +[8]:https://facebook.com/nixcraft +[9]:https://plus.google.com/+CybercitiBiz diff --git a/translated/tech/20070129 How To Debug a Bash Shell Script Under Linux or UNIX.md b/published/20070129 How To Debug a Bash Shell Script Under Linux or UNIX.md similarity index 67% rename from translated/tech/20070129 How To Debug a Bash Shell Script Under Linux or UNIX.md rename to published/20070129 How To Debug a Bash Shell Script Under Linux or UNIX.md index 4cc979015b..1517fc151d 100644 --- a/translated/tech/20070129 How To Debug a Bash Shell Script Under Linux or UNIX.md +++ b/published/20070129 How To Debug a Bash Shell Script Under Linux or UNIX.md @@ -1,32 +1,35 @@ 如何在 Linux 或者 UNIX 下调试 Bash Shell 脚本 ====== + 来自我的邮箱: -**我写了一个你好世界的小脚本。我如何能调试运行在 Linux 或者类 UNIX 的系统上的 bash shell 脚本呢?** + +> 我写了一个 hello world 小脚本。我如何能调试运行在 Linux 或者类 UNIX 的系统上的 bash shell 脚本呢? + 这是 Linux / Unix 系统管理员或新用户最常问的问题。shell 脚本调试可能是一项繁琐的工作(不容易阅读)。调试 shell 脚本有多种方法。 -您需要传递 -X 或 -V 参数,以在 bash shell 中浏览每行代码。 +您需要传递 `-x` 或 `-v` 参数,以在 bash shell 中浏览每行代码。 [![如何在 Linux 或者 UNIX 下调试 Bash Shell 脚本][1]][1] 让我们看看如何使用各种方法调试 Linux 和 UNIX 上运行的脚本。 -``` ### -x 选项来调试脚本 -用 -x 选项来运行脚本 +用 `-x` 选项来运行脚本: + ``` $ bash -x script-name $ bash -x domains.sh ``` - ### 使用 set 内置命令 bash shell 提供调试选项,可以打开或关闭使用 [set 命令][2]: - * **set -x** : 显示命令及其执行时的参数。 - * **set -v** : 显示 shell 输入行作为它们读取的 +* `set -x` : 显示命令及其执行时的参数。 +* `set -v` : 显示 shell 输入行作为它们读取的 + +可以在 shell 脚本本身中使用上面的两个命令: -可以在shell脚本本身中使用上面的两个命令: ``` #!/bin/bash clear @@ -43,18 +46,28 @@ ls # more commands ``` -你可以代替 [标准 Shebang][3] 行: -`#!/bin/bash` -用一下代码(用于调试): -`#!/bin/bash -xv` +你可以代替 [标准释伴][3] 行: + +``` +#!/bin/bash +``` + +用以下代码(用于调试): + +``` +#!/bin/bash -xv +``` ### 使用智能调试功能 -首先添加一个叫做 _DEBUG 的特殊变量。当你需要调试脚本的时候,设置 _DEBUG 为 'on': -`_DEBUG="on"` +首先添加一个叫做 `_DEBUG` 的特殊变量。当你需要调试脚本的时候,设置 `_DEBUG` 为 `on`: +``` +_DEBUG="on" +``` 在脚本的开头放置以下函数: + ``` function DEBUG() { @@ -62,11 +75,14 @@ function DEBUG() } ``` -function DEBUG() { [ "$_DEBUG" == "on" ] && $@ } +现在,只要你需要调试,只需使用 `DEBUG` 函数如下: + +``` +DEBUG echo "File is $filename" +``` + +或者: -现在,只要你需要调试,只需使用 DEBUG 函数如下: -`DEBUG echo "File is $filename"` -或者 ``` DEBUG set -x Cmd1 @@ -74,11 +90,14 @@ Cmd2 DEBUG set +x ``` -当调试完(在移动你的脚本到生产环境之前)设置 _DEBUG 为 'off'。不需要删除调试行。 -`_DEBUG="off" # 设置为非 'on' 的任何字符` +当调试完(在移动你的脚本到生产环境之前)设置 `_DEBUG` 为 `off`。不需要删除调试行。 +``` +_DEBUG="off" # 设置为非 'on' 的任何字符 +``` 示例脚本: + ``` #!/bin/bash _DEBUG="on" @@ -102,8 +121,13 @@ echo "$a + $b = $c" ``` 保存并关闭文件。运行脚本如下: -`$ ./script.sh` -输出: + +``` +$ ./script.sh +``` + +输出: + ``` Reading files Found in xyz.txt file @@ -114,31 +138,43 @@ Found in xyz.txt file + '[' on == on ']' + set +x 2 + 3 = 5 - ``` -现在设置 DEBUG 为关闭(你需要编辑文件): -`_DEBUG="off"` -运行脚本: -`$ ./script.sh` -输出: +现在设置 `_DEBUG` 为 `off`(你需要编辑该文件): + +``` +_DEBUG="off" +``` + +运行脚本: + +``` +$ ./script.sh +``` + +输出: + ``` Found in xyz.txt file 2 + 3 = 5 - ``` -以上是一个简单但非常有效的技术。还可以尝试使用 DEBUG 作为别名替代函数。 +以上是一个简单但非常有效的技术。还可以尝试使用 `DEBUG` 作为别名而不是函数。 ### 调试 Bash Shell 的常见错误 Bash 或者 sh 或者 ksh 在屏幕上给出各种错误信息,在很多情况下,错误信息可能不提供详细的信息。 #### 跳过在文件上应用执行权限 -When you [write your first hello world bash shell script][4], you might end up getting an error that read as follows: + 当你 [编写你的第一个 hello world 脚本][4],您可能会得到一个错误,如下所示: -`bash: ./hello.sh: Permission denied` -设置权限使用 chmod 命令: + +``` +bash: ./hello.sh: Permission denied +``` + +设置权限使用 `chmod` 命令: + ``` $ chmod +x hello.sh $ ./hello.sh @@ -147,21 +183,21 @@ $ bash hello.sh #### 文件结束时发生意外的错误 -如果您收到文件结束意外错误消息,请打开脚本文件,并确保它有打开和关闭引号。在这个例子中,echo 语句有一个开头引号,但没有结束引号: +如果您收到文件结束意外错误消息,请打开脚本文件,并确保它有打开和关闭引号。在这个例子中,`echo` 语句有一个开头引号,但没有结束引号: + ``` #!/bin/bash - ... .... - echo 'Error: File not found ^^^^^^^ missing quote ``` -还要确保你检查缺少的括号和大括号 ({}): +还要确保你检查缺少的括号和大括号 `{}`: + ``` #!/bin/bash ..... @@ -172,7 +208,9 @@ echo 'Error: File not found ``` #### 丢失像 fi,esac,;; 等关键字。 -如果你缺少了结尾的关键字,如 fi 或 ;; 你会得到一个错误,如 “XXX 意外”。因此,确保所有嵌套的 if 和 case 语句以适当的关键字结束。有关语法要求的页面。在本例中,缺少 fi: + +如果你缺少了结尾的关键字,如 `fi` 或 `;;` 你会得到一个错误,如 “XXX 意外”。因此,确保所有嵌套的 `if` 和 `case` 语句以适当的关键字结束。有关语法要求的页面。在本例中,缺少 `fi`: + ``` #!/bin/bash echo "Starting..." @@ -189,16 +227,23 @@ do echo $f done -# 注意 fi 已经丢失 +# 注意 fi 丢失了 ``` #### 在 Windows 或 UNIX 框中移动或编辑 shell 脚本 -不要在 Linux 上创建脚本并移动到 Windows。另一个问题是编辑 Windows 10上的 shell 脚本并将其移动到 UNIX 服务器上。这将导致一个错误的命令没有发现由于回车返回(DOS CR-LF)。你可以 [将 DOS 换行转换为 CR-LF 的Unix/Linux 格式][5] 使用下列命令: -`dos2unix my-script.sh` +不要在 Linux 上创建脚本并移动到 Windows。另一个问题是编辑 Windows 10上的 shell 脚本并将其移动到 UNIX 服务器上。这将由于换行符不同而导致命令没有发现的错误。你可以使用下列命令 [将 DOS 换行转换为 CR-LF 的Unix/Linux 格式][5] : + +``` +dos2unix my-script.sh +``` + +### 技巧 + +#### 技巧 1 - 发送调试信息输出到标准错误 -### 提示1 - 发送调试信息输出到标准错误 [标准错误] 是默认错误输出设备,用于写所有系统错误信息。因此,将消息发送到默认的错误设备是个好主意: + ``` # 写错误到标准输出 echo "Error: $1 file not found" @@ -208,17 +253,19 @@ echo "Error: $1 file not found" echo "Error: $1 file not found" 1>&2 ``` -### 提示2 - 在使用 vim 文本编辑器时,打开语法高亮。 -大多数现代文本编辑器允许设置语法高亮选项。这对于检测语法和防止常见错误如打开或关闭引号非常有用。你可以在不同的颜色中看到。这个特性简化了 shell 脚本结构中的编写,语法错误在视觉上截然不同。强调不影响文本本身的意义,它只为你编写。在这个例子中,我的脚本使用了 vim 语法高亮: +#### 技巧 2 - 在使用 vim 文本编辑器时,打开语法高亮 + +大多数现代文本编辑器允许设置语法高亮选项。这对于检测语法和防止常见错误如打开或关闭引号非常有用。你可以在不同的颜色中看到。这个特性简化了 shell 脚本结构中的编写,语法错误在视觉上截然不同。高亮不影响文本本身的意义,它只为你提示而已。在这个例子中,我的脚本使用了 vim 语法高亮: + [!如何调试 Bash Shell 脚本,在 Linux 或者 UNIX 使用 Vim 语法高亮特性][7]][7] -### 提示3 - 使用 shellcheck 检查脚本 -[shellcheck 是一个用于静态分析 shell 脚本的工具][8]。可以使用它来查找 shell 脚本中的错误。这是用 Haskell 编写的。您可以使用这个工具找到警告和建议。让我们看看如何在 Linux 或 类UNIX 系统上安装和使用 shellcheck 来改善你的 shell 脚本,避免错误和高效。 +#### 技巧 3 - 使用 shellcheck 检查脚本 -### 关于作者 -发表者: +[shellcheck 是一个用于静态分析 shell 脚本的工具][8]。可以使用它来查找 shell 脚本中的错误。这是用 Haskell 编写的。您可以使用这个工具找到警告和建议。你可以看看如何在 Linux 或 类UNIX 系统上安装和使用 shellcheck 来改善你的 shell 脚本,避免错误和高效。 -作者是 nixCraft 创造者,一个经验丰富的系统管理员和一个练习 Linux 操作系统/ UNIX shell 脚本的教练。他曾与全球客户和各种行业,包括 IT,教育,国防和空间研究,以及非营利部门。跟随他 [推特][9],[脸谱网][10],[谷歌+ ][11]。 +作者:Vivek Gite + +作者是 nixCraft 创造者,一个经验丰富的系统管理员和一个练习 Linux 操作系统/ UNIX shell 脚本的教练。他曾与全球客户和各种行业,包括 IT,教育,国防和空间研究,以及非营利部门。关注他的 [推特][9],[脸谱网][10],[谷歌+ ][11]。 -------------------------------------------------------------------------------- @@ -226,7 +273,7 @@ via: https://www.cyberciti.biz/tips/debugging-shell-script.html 作者:[Vivek Gite][a] 译者:[zjon](https://github.com/zjon) -校对:[校对者ID](https://github.com/校对者ID) +校对:[wxy](https://github.com/wxy) 本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 diff --git a/published/20071007 Linux Check IDE - SATA SSD Hard Disk Transfer Speed.md b/published/20071007 Linux Check IDE - SATA SSD Hard Disk Transfer Speed.md new file mode 100644 index 0000000000..c7aab5ed81 --- /dev/null +++ b/published/20071007 Linux Check IDE - SATA SSD Hard Disk Transfer Speed.md @@ -0,0 +1,158 @@ +在 Linux 上检测 IDE/SATA SSD 硬盘的传输速度 +====== + +你知道你的硬盘在 Linux 下传输有多快吗?不打开电脑的机箱或者机柜,你知道它运行在 SATA I (150 MB/s) 、 SATA II (300 MB/s) 还是 SATA III (6.0Gb/s) 呢? + +你能够使用 `hdparm` 和 `dd` 命令来检测你的硬盘速度。它为各种硬盘的 ioctls 提供了命令行界面,这是由 Linux 系统的 ATA / IDE / SATA 设备驱动程序子系统所支持的。有些选项只能用最新的内核才能正常工作(请确保安装了最新的内核)。我也推荐使用最新的内核源代码的包含头文件来编译 `hdparm` 命令。 + +### 如何使用 hdparm 命令来检测硬盘的传输速度 + +以 root 管理员权限登录并执行命令: + +``` +$ sudo hdparm -tT /dev/sda +``` + +或者, + +``` +$ sudo hdparm -tT /dev/hda +``` + +输出: + +``` +/dev/sda: + Timing cached reads: 7864 MB in 2.00 seconds = 3935.41 MB/sec + Timing buffered disk reads: 204 MB in 3.00 seconds = 67.98 MB/sec +``` + +为了检测更精准,这个操作应该**重复2-3次** 。这显示了无需访问磁盘,直接从 Linux 缓冲区缓存中读取的速度。这个测量实际上是被测系统的处理器、高速缓存和存储器的吞吐量的指标。这是一个 [for 循环的例子][1],连续运行测试 3 次: + +``` +for i in 1 2 3; do hdparm -tT /dev/hda; done +``` + +这里, + + * `-t` :执行设备读取时序 + * `-T` :执行缓存读取时间 + * `/dev/sda` :硬盘设备文件 + + +要 [找出 SATA 硬盘的连接速度][2] ,请输入: + +``` +sudo hdparm -I /dev/sda | grep -i speed +``` + +输出: + +``` + * Gen1 signaling speed (1.5Gb/s) + * Gen2 signaling speed (3.0Gb/s) + * Gen3 signaling speed (6.0Gb/s) + +``` + +以上输出表明我的硬盘可以使用 1.5Gb/s、3.0Gb/s 或 6.0Gb/s 的速度。请注意,您的 BIOS/主板必须支持 SATA-II/III 才行: + +``` +$ dmesg | grep -i sata | grep 'link up' +``` + +[![Linux Check IDE SATA SSD Hard Disk Transfer Speed][3]][3] + +### dd 命令 + +你使用 `dd` 命令也可以获取到相应的速度信息: + +``` +dd if=/dev/zero of=/tmp/output.img bs=8k count=256k +rm /tmp/output.img +``` + +输出: + +``` +262144+0 records in +262144+0 records out +2147483648 bytes (2.1 GB) copied, 23.6472 seconds, `90.8 MB/s` +``` + +下面是 [推荐的 dd 命令参数][4]: + +``` +dd if=/dev/input.file of=/path/to/output.file bs=block-size count=number-of-blocks oflag=dsync + +## GNU dd syntax ## +dd if=/dev/zero of=/tmp/test1.img bs=1G count=1 oflag=dsync + +## OR alternate syntax for GNU/dd ## +dd if=/dev/zero of=/tmp/testALT.img bs=1G count=1 conv=fdatasync +``` + +这是上面命令的第三个命令的输出结果: + +``` +1+0 records in +1+0 records out +1073741824 bytes (1.1 GB, 1.0 GiB) copied, 4.23889 s, 253 MB/s +``` + +### “磁盘与存储” - GUI 工具 + +您还可以使用位于“系统>管理>磁盘实用程序”菜单中的磁盘实用程序。请注意,在最新版本的 Gnome 中,它简称为“磁盘”。 + +#### 如何使用 Linux 上的“磁盘”测试我的硬盘的性能? + +要测试硬盘的速度: + + 1. 从“活动概览”中打开“磁盘”(按键盘上的 super 键并键入“disks”) + 2. 从“左侧窗格”的列表中选择“磁盘” + 3. 选择菜单按钮并从菜单中选择“测试磁盘性能……” + 4. 单击“开始性能测试……”并根据需要调整传输速率和访问时间参数。 + 5. 选择“开始性能测试”来测试从磁盘读取数据的速度。需要管理权限请输入密码。 + +以上操作的快速视频演示: + +https://www.cyberciti.biz/tips/wp-content/uploads/2007/10/disks-performance.mp4 + +#### 只读 Benchmark (安全模式下) + +然后,选择 > 只读: + +![Fig.01: Linux Benchmarking Hard Disk Read Only Test Speed][5] + +上述选项不会销毁任何数据。 + +#### 读写的 Benchmark(所有数据将丢失,所以要小心) + +访问“系统>管理>磁盘实用程序菜单>单击性能测试>单击开始读/写性能测试按钮: + +![Fig.02:Linux Measuring read rate, write rate and access time][6] + +### 作者 + +作者是 nixCraft 的创造者,是经验丰富的系统管理员,也是 Linux 操作系统/ Unix shell 脚本的培训师。他曾与全球客户以及 IT,教育,国防和空间研究以及非营利部门等多个行业合作。在Twitter,Facebook和Google+上关注他。 + +-------------------------------------------------------------------------------- + +via: https://www.cyberciti.biz/tips/how-fast-is-linux-sata-hard-disk.html + +作者:[Vivek Gite][a] +译者:[MonkeyDEcho](https://github.com/MonkeyDEcho) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.cyberciti.biz/ +[1]:https://www.cyberciti.biz/faq/bash-for-loop/ +[2]:https://www.cyberciti.biz/faq/linux-command-to-find-sata-harddisk-link-speed/ +[3]:https://www.cyberciti.biz/tips/wp-content/uploads/2007/10/Linux-Check-IDE-SATA-SSD-Hard-Disk-Transfer-Speed.jpg +[4]:https://www.cyberciti.biz/faq/howto-linux-unix-test-disk-performance-with-dd-command/ +[5]:https://www.cyberciti.biz/media/new/tips/2007/10/Linux-Hard-Disk-Speed-Benchmark.png (Linux Benchmark Hard Disk Speed) +[6]:https://www.cyberciti.biz/media/new/tips/2007/10/Linux-Hard-Disk-Read-Write-Benchmark.png (Linux Hard Disk Benchmark Read / Write Rate and Access Time) +[7]:https://twitter.com/nixcraft +[8]:https://facebook.com/nixcraft +[9]:https://plus.google.com/+CybercitiBiz diff --git a/published/20141029 What does an idle CPU do.md b/published/20141029 What does an idle CPU do.md new file mode 100644 index 0000000000..d5259385c5 --- /dev/null +++ b/published/20141029 What does an idle CPU do.md @@ -0,0 +1,89 @@ +当 CPU 空闲时它都在做什么? +============================================================ + +在 [上篇文章中][2] 我说了操作系统行为的基本原理是,*在任何一个给定的时刻*,在一个 CPU 上**有且只有一个任务是活动的**。但是,如果 CPU 无事可做的时候,又会是什么样的呢? + +事实证明,这种情况是非常普遍的,对于绝大多数的个人电脑来说,这确实是一种常态:大量的睡眠进程,它们都在等待某种情况下被唤醒,差不多在 100% 的 CPU 时间中,都处于虚构的“空闲任务”中。事实上,如果一个普通用户的 CPU 处于持续的繁忙中,它可能意味着有一个错误、bug、或者运行了恶意软件。 + +因为我们不能违反我们的原理,*一些任务需要在一个 CPU 上激活*。首先是因为,这是一个良好的设计:持续很长时间去遍历内核,检查是否*有*一个活动任务,这种特殊情况是不明智的做法。最好的设计是*没有任何例外的情况*。无论何时,你写一个 `if` 语句,Nyan Cat 就会喵喵喵。其次,我们需要使用空闲的 CPU 去做*一些事情*,让它们充满活力,你懂得,就是创建天网计划呗。 + +因此,保持这种设计的连续性,并领先于那些邪恶计划一步,操作系统开发者创建了一个**空闲任务**,当没有其它任务可做时就调度它去运行。我们可以在 Linux 的 [引导过程][3] 中看到,这个空闲任务就是进程 0,它是由计算机打开电源时运行的第一个指令直接派生出来的。它在 [rest_init][4] 中初始化,在 [init_idle_bootup_task][5] 中初始化空闲调度类scheduling class。 + +简而言之,Linux 支持像实时进程、普通用户进程等等的不同调度类。当选择一个进程变成活动任务时,这些类按优先级进行查询。通过这种方式,核反应堆的控制代码总是优先于 web 浏览器运行。尽管在通常情况下,这些类返回 `NULL`,意味着它们没有合适的任务需要去运行 —— 它们总是处于睡眠状态。但是空闲调度类,它是持续运行的,从不会失败:它总是返回空闲任务。 + +好吧,我们来看一下这个空闲任务*到底做了些什么*。下面是 [cpu_idle_loop][6],感谢开源能让我们看到它的代码: + +``` +while (1) { + while(!need_resched()) { + cpuidle_idle_call(); + } + + /* + [Note: Switch to a different task. We will return to this loop when the idle task is again selected to run.] + */ + schedule_preempt_disabled(); +} +``` + +*cpu_idle_loop* + +我省略了很多的细节,稍后我们将去了解任务切换,但是,如果你阅读了这些源代码,你就会找到它的要点:由于这里不需要重新调度(即改变活动任务),它一直处于空闲状态。以所经历的时间来计算,这个循环和其它操作系统中它的“堂兄弟们”相比,在计算的历史上它是运行的最多的代码片段。对于 Intel 处理器来说,处于空闲状态意味着运行着一个 [halt][7] 指令: + +``` +static inline void native_halt(void) + { + asm volatile("hlt": : :"memory"); + } +``` + +*native_halt* + +`hlt` 指令停止处理器中的代码执行,并将它置于 `halt` 的状态。奇怪的是,全世界各地数以百万计的 Intel 类的 CPU 们花费大量的时间让它们处于 `halt` 的状态,甚至它们在通电的时候也是如此。这并不是高效、节能的做法,这促使芯片制造商们去开发处理器的深度睡眠状态,以带来着更少的功耗和更长休眠时间。内核的 [cpuidle 子系统][8] 是这些节能模式能够产生好处的原因。 + +现在,一旦我们告诉 CPU 去 `halt`(睡眠)之后,我们需要以某种方式让它醒来。如果你读过 [上篇文章《你的操作系统什么时候运行?》][9] ,你可能会猜到*中断*会参与其中,而事实确实如此。中断促使 CPU 离开 `halt` 状态返回到激活状态。因此,将这些拼到一起,下图是当你阅读一个完全呈现的 web 网页时,你的系统主要做的事情: + +![](https://manybutfinite.com/img/os/idle.png) + +除定时器中断外的其它中断也会使处理器再次发生变化。如果你再次点击一个 web 页面就会产生这种变化,例如:你的鼠标发出一个中断,它的驱动会处理它,并且因为它产生了一个新的输入,突然进程就可运行了。在那个时刻, `need_resched()` 返回 `true`,然后空闲任务因你的浏览器而被踢出而终止运行。 + +如果我们呆呆地看着这篇文章,而不做任何事情。那么随着时间的推移,这个空闲循环就像下图一样: + +![](https://manybutfinite.com/img/os/idleCycles.png) + +在这个示例中,由内核计划的定时器中断会每 4 毫秒发生一次。这就是滴答tick周期。也就是说每秒钟将有 250 个滴答,因此,这个*滴答速率(频率)*是 250 Hz。这是运行在 Intel 处理器上的 Linux 的典型值,而其它操作系统喜欢使用 100 Hz。这是由你构建内核时在 `CONFIG_HZ` 选项中定义的。 + +对于一个*空闲 CPU* 来说,它看起来似乎是个无意义的工作。如果外部世界没有新的输入,在你的笔记本电脑的电池耗尽之前,CPU 将始终处于这种每秒钟被唤醒 250 次的地狱般折磨的小憩中。如果它运行在一个虚拟机中,那我们正在消耗着宿主机 CPU 的性能和宝贵的时钟周期。 + +在这里的解决方案是 [动态滴答][10],当 CPU 处于空闲状态时,定时器中断被 [暂停或重计划][11],直到内核*知道*将有事情要做时(例如,一个进程的定时器可能要在 5 秒内过期,因此,我们不能再继续睡眠了),定时器中断才会重新发出。这也被称为*无滴答模式*。 + +最后,假设在一个系统中你有一个*活动进程*,例如,一个长时间运行的 CPU 密集型任务。那样几乎就和一个空闲系统是相同的:这些示意图仍然是相同的,只是将空闲任务替换为这个进程,并且相应的描述也是准确的。在那种情况下,每 4 毫秒去中断一次任务仍然是无意义的:它只是操作系统的性能抖动,甚至会使你的工作变得更慢而已。Linux 也可以在这种单一进程的场景中停止这种固定速率的滴答,这被称为 [自适应滴答][12] 模式。最终,这种固定速率的滴答可能会 [完全消失][13]。 + +对于阅读一篇文章来说,CPU 基本是无事可做的。内核的这种空闲行为是操作系统难题的一个重要部分,并且它与我们看到的其它情况非常相似,因此,这将帮助我们理解一个运行中的内核。更多的内容将发布在下周的 [RSS][14] 和 [Twitter][15] 上。 + +-------------------------------------------------------------------------------- + +via: https://manybutfinite.com/post/what-does-an-idle-cpu-do/ + +作者:[Gustavo Duarte][a] +译者:[qhwdw](https://github.com/qhwdw) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:http://duartes.org/gustavo/blog/about/ +[1]:https://manybutfinite.com/post/what-does-an-idle-cpu-do/ +[2]:https://linux.cn/article-9095-1.html +[3]:https://manybutfinite.com/post/kernel-boot-process +[4]:https://github.com/torvalds/linux/blob/v3.17/init/main.c#L393 +[5]:https://github.com/torvalds/linux/blob/v3.17/kernel/sched/core.c#L4538 +[6]:https://github.com/torvalds/linux/blob/v3.17/kernel/sched/idle.c#L183 +[7]:https://github.com/torvalds/linux/blob/v3.17/arch/x86/include/asm/irqflags.h#L52 +[8]:http://lwn.net/Articles/384146/ +[9]:https://linux.cn/article-9095-1.html +[10]:https://github.com/torvalds/linux/blob/v3.17/Documentation/timers/NO_HZ.txt#L17 +[11]:https://github.com/torvalds/linux/blob/v3.17/Documentation/timers/highres.txt#L215 +[12]:https://github.com/torvalds/linux/blob/v3.17/Documentation/timers/NO_HZ.txt#L100 +[13]:http://lwn.net/Articles/549580/ +[14]:https://manybutfinite.com/feed.xml +[15]:http://twitter.com/manybutfinite \ No newline at end of file diff --git a/translated/tech/20170707 Lessons from my first year of live coding on Twitch.md b/published/20170707 Lessons from my first year of live coding on Twitch.md similarity index 86% rename from translated/tech/20170707 Lessons from my first year of live coding on Twitch.md rename to published/20170707 Lessons from my first year of live coding on Twitch.md index 7a2f0aa98a..042603760b 100644 --- a/translated/tech/20170707 Lessons from my first year of live coding on Twitch.md +++ b/published/20170707 Lessons from my first year of live coding on Twitch.md @@ -1,10 +1,11 @@ -我在 Twitch 平台直播编程的第一年 +我在 Twitch 平台直播编程的经验 ============================================================ -去年 7 月我进行了第一次直播。不像大多数人那样在 Twitch 上进行游戏直播,我想直播的内容是我利用个人时间进行的开源工作。我对 NodeJS 硬件库有一定的研究(其中大部分是靠我自学的)。考虑到我已经在 Twitch 上有了一个直播间,为什么不再建一个更小更专业的直播间,比如使用 JavaScript 驱动硬件JavaScript powered hardware 来建立直播间 :) 我注册了 [我自己的频道][1] ,从那以后我就开始定期直播。 + +去年 7 月我进行了第一次直播。不像大多数人那样在 Twitch 上进行游戏直播,我想直播的内容是我利用个人时间进行的开源工作。我对 NodeJS 硬件库有一定的研究(其中大部分是靠我自学的)。考虑到我已经在 Twitch 上有了一个直播间,为什么不再建一个更小更专业的直播间,比如 由 JavaScript 驱动的硬件JavaScript powered hardware ;) 我注册了 [我自己的频道][1] ,从那以后我就开始定期直播。 我当然不是第一个这么做的人。[Handmade Hero][2] 是我最早看到的几个在线直播编程的程序员之一。很快这种直播方式被 Vlambeer 发扬光大,他在 Twitch 的 [Nuclear Throne live][3] 直播间进行直播。我对 Vlambeer 尤其着迷。 -我的朋友 [Nolan Lawson][4] 让我 _真正开始做_ 这件事,而不只是单纯地 _想要做_ 。我看了他 [在周末直播开源工作][5] ,做得棒极了。他解释了他当时做的每一件事。每一件事。回复 GitHub 上的 问题issues ,鉴别 bug ,在 分支branches 中调试程序,你知道的。这令我着迷,因为 Nolan 使他的开源库得到了广泛的使用。他的开源生活和我的完全不一样。 +我的朋友 [Nolan Lawson][4] 让我 _真正开始做_ 这件事,而不只是单纯地 _想要做_ 。我看了他 [在周末直播开源工作][5] ,做得棒极了。他解释了他当时做的每一件事。是的,每一件事,包括回复 GitHub 上的 问题issues ,鉴别 bug ,在 分支branches 中调试程序,你知道的。这令我着迷,因为 Nolan 使他的开源库得到了广泛的使用。他的开源生活和我的完全不一样。 你甚至可以看到我在他视频下的评论: @@ -14,27 +15,27 @@ 那个星期六我极少的几个听众给了我很大的鼓舞,因此我坚持了下去。现在我有了超过一千个听众,他们中的一些人形成了一个可爱的小团体,他们会定期观看我的直播,我称呼他们为 “noopkat 家庭” 。 -我们很开心。我想称呼这个即时编程部分为“多玩家在线组队编程”。我真的被他们每个人的热情和才能触动了。一次,一个团体成员指出我的 Arduino 开发板没有连接上软件,因为板子上的芯片丢了。这真是最有趣的时刻之一。 +我们很开心。我想称呼这个即时编程部分为“多玩家在线组队编程”。我真的被他们每个人的热情和才能触动了。一次,一个团体成员指出我的 Arduino 开发板不能随同我的软件工作,因为板子上的芯片丢了。这真是最有趣的时刻之一。 -我经常暂停直播,检查我的收件箱,看看有没有人对我提过的,不再有时间完成的工作发起 拉取请求pull request 。感谢我 Twitch 社区对我的帮助和鼓励。 +我经常暂停直播,检查我的收件箱,看看有没有人对我提及过但没有时间完成的工作发起 拉取请求pull request 。感谢我 Twitch 社区对我的帮助和鼓励。 -我很想聊聊 Twitch 直播给我带来的好处,但它的内容太多了,我应该会在我下一个博客里介绍。我在这里想要分享的,是我学习的关于如何自己实现直播编程的课程。最近几个开发者问我怎么开始自己的直播,因此我在这里想大家展示我给他们的建议! +我很想聊聊 Twitch 直播给我带来的好处,但它的内容太多了,我应该会在我下一篇博客里介绍。我在这里想要分享的,是我学习的关于如何自己实现直播编程的课程。最近几个开发者问我怎么开始自己的直播,因此我在这里想大家展示我给他们的建议! 首先,我在这里贴出一个给过我很大帮助的教程 [“Streaming and Finding Success on Twitch”][7] 。它专注于 Twitch 与游戏直播,但也有很多和我们要做的东西相关的部分。我建议首先阅读这个教程,然后再考虑一些建立直播频道的细节(比如如何选择设备和软件)。 -下面我列出我自己的配置。这些配置是从我多次的错误经验中总结出来的,其中要感谢我的直播同行的智慧与建议(对,你们知道就是你们!)。 +下面我列出我自己的配置。这些配置是从我多次的错误经验中总结出来的,其中要感谢我的直播同行的智慧与建议。(对,你们知道就是你们!) ### 软件 -有很多免费的直播软件。我用的是 [Open Broadcaster Software (OBS)][8] 。它适用于大多数的平台。我觉得它十分直观且易于入门,但掌握其他的进阶功能则需要一段时间的学习。学好它你会获得很多好处!这是今天我直播时 OBS 的桌面截图(点击查看大图): +有很多免费的直播软件。我用的是 [Open Broadcaster Software (OBS)][8] 。它适用于大多数的平台。我觉得它十分直观且易于入门,但掌握其他的进阶功能则需要一段时间的学习。学好它你会获得很多好处!这是今天我直播时 OBS 的桌面截图: ![](https://cdn-images-1.medium.com/max/1600/0*s4wyeYuaiThV52q5.png) -你直播时需要在不用的“场景”中进行切换。一个“场景”是多个“素材”通过堆叠和组合产生的集合。一个“素材”可以是照相机,麦克风,你的桌面,网页,动态文本,图片等等。 OBS 是一个很强大的软件。 +你直播时需要在不用的“场景scenes”中进行切换。一个“场景”是多个“素材sources”通过堆叠和组合产生的集合。一个“素材”可以是照相机、麦克风、你的桌面、网页、动态文本、图片等等。 OBS 是一个很强大的软件。 最上方的桌面场景是我编程的环境,我直播的时候主要停留在这里。我使用 iTerm 和 vim ,同时打开一个可以切换的浏览器窗口来查阅文献或在 GitHub 上分类检索资料。 -底部的黑色长方形是我的网络摄像头,人们可以通过这种个人化的连接方式来观看我工作。 +底部的黑色长方形是我的网络摄像头,人们可以通过这种更个人化的连接方式来观看我工作。 我的场景中有一些“标签”,很多都与状态或者顶栏信息有关。顶栏只是添加了个性化信息,它在直播时是一个很好的连续性素材。这是我在 [GIMP][9] 里制作的图片,在你的场景里它会作为一个素材来加载。一些标签是从文本文件里添加的动态内容(例如最新粉丝)。另一个标签是一个 [custom one I made][10] ,它可以展示我直播的房间的动态温度与湿度。 @@ -62,7 +63,7 @@ ### 硬件 -我从使用便宜的器材开始,当我意识到我会长期坚持直播之后,才将他们逐渐换成更好的。开始的时候尽量使用你现有的器材,即使是只用电脑内置的摄像头与麦克风。 +我从使用便宜的器材开始,当我意识到我会长期坚持直播之后,才将它们逐渐换成更好的。开始的时候尽量使用你现有的器材,即使是只用电脑内置的摄像头与麦克风。 现在我使用 Logitech Pro C920 网络摄像头,和一个固定有支架的 Blue Yeti 麦克风。花费是值得的。我直播的质量完全不同了。 @@ -116,7 +117,7 @@ 当你即将开始的时候,你会感觉很奇怪,不适应。你会在人们看着你写代码的时候感到紧张。这很正常!尽管我之前有过公共演说的经历,我一开始的时候还是感到陌生而不适应。我感觉我无处可藏,这令我害怕。我想:“大家可能都觉得我的代码很糟糕,我是一个糟糕的开发者。”这是一个困扰了我 _整个职业生涯_ 的想法,对我来说不新鲜了。我知道带着这些想法,我不能在发布到 GitHub 之前仔细地再检查一遍代码,而这样做更有利于我保持我作为开发者的声誉。 -我从 Twitch 直播中发现了很多关于我代码风格的东西。我知道我的风格绝对是“先让它跑起来,然后再考虑可读性,然后再考虑运行速度”。我不再在前一天晚上提前排练好直播的内容(一开始的三四次直播我都是这么做的),所以我在 Twitch 上写的代码是相当粗糙的,我还得保证它们运行起来没问题。当我不看别人的聊天和讨论的时候,我可以写出我最好的代码,这样是没问题的。但我总会忘记我使用过无数遍的方法的名字,而且每次直播的时候都会犯“愚蠢的”错误。一般来说,这不是一个让你能达到你最好状态的生产环境。 +我从 Twitch 直播中发现了很多关于我代码风格的东西。我知道我的风格绝对是“先让它跑起来,然后再考虑可读性,然后再考虑运行速度”。我不再在前一天晚上提前排练好直播的内容(一开始的三、四次直播我都是这么做的),所以我在 Twitch 上写的代码是相当粗糙的,我还得保证它们运行起来没问题。当我不看别人的聊天和讨论的时候,我可以写出我最好的代码,这样是没问题的。但我总会忘记我使用过无数遍的方法的名字,而且每次直播的时候都会犯“愚蠢的”错误。一般来说,这不是一个让你能达到你最好状态的生产环境。 我的 Twitch 社区从来不会因为这个苛求我,反而是他们帮了我很多。他们理解我正同时做着几件事,而且真的给了很多务实的意见和建议。有时是他们帮我找到了解决方法,有时是我要向他们解释为什么他们的建议不适合解决这个问题。这真的很像一般意义的组队编程! @@ -128,7 +129,7 @@ 如果你周日想要加入我的直播,你可以 [订阅我的 Twitch 频道][13] :) -最后我想说一下,我个人十分感谢 [Mattias Johansson][14] 在我早期开始直播的时候给我的建议和鼓励。他的 [FunFunFunction YouTube channel][15] 也是一个令人激动的定期直播频道。 +最后我想说一下,我自己十分感谢 [Mattias Johansson][14] 在我早期开始直播的时候给我的建议和鼓励。他的 [FunFunFunction YouTube channel][15] 也是一个令人激动的定期直播频道。 另:许多人问过我的键盘和其他工作设备是什么样的, [这是我使用的器材的完整列表][16] 。感谢关注! @@ -136,9 +137,9 @@ via: https://medium.freecodecamp.org/lessons-from-my-first-year-of-live-coding-on-twitch-41a32e2f41c1 -作者:[ Suz Hinton][a] +作者:[Suz Hinton][a] 译者:[lonaparte](https://github.com/lonaparte) -校对:[校对者ID](https://github.com/校对者ID) +校对:[wxy](https://github.com/wxy) 本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 diff --git a/published/20170915 How To Install And Setup Vagrant.md b/published/20170915 How To Install And Setup Vagrant.md new file mode 100644 index 0000000000..92d56ab7b8 --- /dev/null +++ b/published/20170915 How To Install And Setup Vagrant.md @@ -0,0 +1,269 @@ +如何安装并设置 Vagrant +============================= + +Vagrant 对于虚拟机来说是一个强大的工具,在这里我们将研究如何在 Ubuntu 上设置和使用 Virtualbox 和 Vagrant 来提供可复制的虚拟机。 + +### 虚拟机,并不复杂 + +多年来,开发人员一直使用虚拟机作为其工作流程的一部分,允许他们交换和更改运行软件的环境,这通常是为了防止项目之间的冲突,例如需要 php 5.3 的项目 A 和需要 php 5.4 的项目 B。 + +并且使用虚拟机意味着你只需要你正在使用的计算机就行,而不需要专用硬件来镜像你的生产环境。 + +当多个开发人员在一个项目上工作时,它也很方便,他们都可以运行一个包含所有需求的环境,但是维护多台机器并确保所有的需求都具有相同的版本是非常困难的,这时 Vagrant 就能派上用场了。 + +#### 使用虚拟机的好处 + +- 你的虚拟机与主机环境是分开的 +- 你可以根据你代码的要求裁剪一个定制虚拟机 +- 不会影响其他虚拟机 +- 可以运行在你的主机上无法运行的程序,例如在 Ubuntu 中运行一些只能在 Windows 运行的软件 + +### 什么是 Vagrant + +简而言之,这是一个与虚拟机一起工作的工具,可以让你自动创建和删除虚拟机。 + +它围绕一个名为 `VagrantFile` 的配置文件而工作,这个配置文件告诉 Vagrant 你想要安装的操作系统,以及一些其他选项,如 IP 和目录同步。 你还可以在虚拟机上添加一个命令的配置脚本。 + +通过共享这个 `VagrantFile`,项目的所有开发人员全可以使用完全相同的虚拟机。 + +### 安装要求 + +#### 安装 VirtualBox + +VirtualBox 是运行虚拟机的程序,它可以从 Ubuntu 仓库中安装。 + +``` +sudo apt-get install virtualbox +``` + +#### 安装 Vagrant + +对于 Vagrant 本身,你要前往 [https://www.vagrantup.com/downloads.html ](https://www.vagrantup.com/downloads.html) 查看适用于你的操作系统的安装软件包。 + +#### 安装增强功能 + +如果你打算与虚拟机共享任何文件夹,则需要安装以下插件。 + +``` +vagrant plugin install vagrant-vbguest +``` + +### 配置 Vagrant + +首先我们需要为 Vagrant 创建一个文件夹。 + +``` +mkdir ~/Vagrant/test-vm +cd ~/Vagrant/test-vm +``` + +创建 VagrantFile: + +``` +vagrant init +``` + +开启虚拟机: + +``` +vagrant up +``` + +登录机器: + +``` +vagrant-ssh +``` + +此时,你将拥有一个基本的 vagrant 机器,以及一个名为 `VagrantFile` 的文件。 + +### 定制 + +在上面的步骤中创建的 `VagrantFile` 看起来类似于以下内容 + +VagrantFile: + +``` +# -*- mode: ruby -*- +# vi: set ft=ruby : +# All Vagrant configuration is done below. The "2" in Vagrant.configure +# configures the configuration version (we support older styles for +# backwards compatibility). Please don't change it unless you know what +# you're doing. +Vagrant.configure("2") do |config| + # The most common configuration options are documented and commented below. + # For a complete reference, please see the online documentation at + # https://docs.vagrantup.com. + + # Every Vagrant development environment requires a box. You can search for + # boxes at https://vagrantcloud.com/search. + config.vm.box = "base" + + # Disable automatic box update checking. If you disable this, then + # boxes will only be checked for updates when the user runs + # `vagrant box outdated`. This is not recommended. + # config.vm.box_check_update = false + + # Create a forwarded port mapping which allows access to a specific port + # within the machine from a port on the host machine. In the example below, + # accessing "localhost:8080" will access port 80 on the guest machine. + # NOTE: This will enable public access to the opened port + # config.vm.network "forwarded_port", guest: 80, host: 8080 + + # Create a forwarded port mapping which allows access to a specific port + # within the machine from a port on the host machine and only allow access + # via 127.0.0.1 to disable public access + # config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "127.0.0.1" + + # Create a private network, which allows host-only access to the machine + # using a specific IP. + # config.vm.network "private_network", ip: "192.168.33.10" + + # Create a public network, which generally matched to bridged network. + # Bridged networks make the machine appear as another physical device on + # your network. + # config.vm.network "public_network" + + # Share an additional folder to the guest VM. The first argument is + # the path on the host to the actual folder. The second argument is + # the path on the guest to mount the folder. And the optional third + # argument is a set of non-required options. + # config.vm.synced_folder "../data", "/vagrant_data" + + # Provider-specific configuration so you can fine-tune various + # backing providers for Vagrant. These expose provider-specific options. + # Example for VirtualBox: + # + # config.vm.provider "virtualbox" do |vb| + # # Display the VirtualBox GUI when booting the machine + # vb.gui = true + # + # # Customize the amount of memory on the VM: + # vb.memory = "1024" + # end + # + # View the documentation for the provider you are using for more + # information on available options. + + # Enable provisioning with a shell script. Additional provisioners such as + # Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the + # documentation for more information about their specific syntax and use. + # config.vm.provision "shell", inline: <<-SHELL + # apt-get update + # apt-get install -y apache2 + # SHELL +end +``` + +现在这个 `VagrantFile` 将创建基本的虚拟机。但 Vagrant 背后的理念是让虚拟机为我们的特定任务而配置,所以我们删除注释和调整配置。 + +VagrantFile: + +``` +# -*- mode: ruby -*- +# vi: set ft=ruby : + +Vagrant.configure("2") do |config| + # Set the Linux Version to Debian Jessie + config.vm.box = "debian/jessie64" + # Set the IP of the Box + config.vm.network "private_network", ip: "192.168.33.10" + # Sync Our Projects Directory with the WWW directory + config.vm.synced_folder "~/Projects", "/var/www/" + # Run the following to Provision + config.vm.provision "shell", path: "install.sh" +end +``` + +现在我们有一个简单的 `VagrantFile`,它将 Linux 版本设置为 debian jessie,设置一个 IP 给我们使用,同步我们感兴趣的文件夹,并最后运行 `install.sh`,这是我们可以运行 shell 命令的地方。 + +install.sh: + +``` +#! /usr/bin/env bash +# Variables +DBHOST=localhost +DBNAME=dbname +DBUSER=dbuser +DBPASSWD=test123 + +echo "[ Provisioning machine ]" +echo "1) Update APT..." +apt-get -qq update + +echo "1) Install Utilities..." +apt-get install -y tidy pdftk curl xpdf imagemagick openssl vim git + +echo "2) Installing Apache..." +apt-get install -y apache2 + +echo "3) Installing PHP and packages..." +apt-get install -y php5 libapache2-mod-php5 libssh2-php php-pear php5-cli php5-common php5-curl php5-dev php5-gd php5-imagick php5-imap php5-intl php5-mcrypt php5-memcached php5-mysql php5-pspell php5-xdebug php5-xmlrpc +#php5-suhosin-extension, php5-mysqlnd + +echo "4) Installing MySQL..." +debconf-set-selections <<< "mysql-server mysql-server/root_password password secret" +debconf-set-selections <<< "mysql-server mysql-server/root_password_again password secret" +apt-get install -y mysql-server +mysql -uroot -p$DBPASSWD -e "CREATE DATABASE $DBNAME" +mysql -uroot -p$DBPASSWD -e "grant all privileges on $DBNAME.* to '$DBUSER'@'localhost' identified by '$DBPASSWD'" + +echo "5) Generating self signed certificate..." +mkdir -p /etc/ssl/localcerts +openssl req -new -x509 -days 365 -nodes -subj "/C=US/ST=Denial/L=Springfield/O=Dis/CN=www.example.com" -out /etc/ssl/localcerts/apache.pem -keyout /etc/ssl/localcerts/apache.key +chmod 600 /etc/ssl/localcerts/apache* + +echo "6) Setup Apache..." +a2enmod rewrite +> /etc/apache2/sites-enabled/000-default.conf +echo " + + ServerAdmin webmaster@localhost + DocumentRoot /var/www/ + ErrorLog ${APACHE_LOG_DIR}/error.log + CustomLog ${APACHE_LOG_DIR}/access.log combined + + +" >> /etc/apache2/sites-enabled/000-default.conf +service apache2 restart + +echo "7) Composer Install..." +curl --silent https://getcomposer.org/installer | php +mv composer.phar /usr/local/bin/composer + +echo "8) Install NodeJS..." +curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash - +apt-get -qq update +apt-get -y install nodejs + +echo "9) Install NPM Packages..." +npm install -g gulp gulp-cli + +echo "Provisioning Completed" +``` + +通过上面的步骤,在你的目录中会有 `VagrantFile` 和 `install.sh`,运行 vagrant 会做下面的事情: + +- 采用 Debian Jessie 来创建虚拟机 +- 将机器的 IP 设置为 192.168.33.10 +- 同步 `~/Projects` 和 `/var/www/` 目录 +- 安装并设置 Apache、Mysql、PHP、Git、Vim +- 安装并运行 Composer +- 安装 Nodejs 和 gulp +- 创建一个 MySQL 数据库 +- 创建自签名证书 + +通过与其他人共享 `VagrantFile` 和 `install.sh`,你可以在两台不同的机器上使用完全相同的环境。 + +-------------------------------------------------------------------------------- + +via: https://www.chris-shaw.com/blog/how-to-install-and-setup-vagrant + +作者:[Christopher Shaw][a] +译者:[MjSeven](https://github.com/MjSeven) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.chris-shaw.com +[1]:/cdn-cgi/l/email-protection diff --git a/published/20171005 Reasons Kubernetes is cool.md b/published/20171005 Reasons Kubernetes is cool.md new file mode 100644 index 0000000000..15f17d827f --- /dev/null +++ b/published/20171005 Reasons Kubernetes is cool.md @@ -0,0 +1,134 @@ +为什么 Kubernetes 很酷 +============================================================ + +在我刚开始学习 Kubernetes(大约是一年半以前吧?)时,我真的不明白为什么应该去关注它。 + +在我使用 Kubernetes 全职工作了三个多月后,我才逐渐明白了为什么我应该使用它。(我距离成为一个 Kubernetes 专家还很远!)希望这篇文章对你理解 Kubernetes 能做什么会有帮助! + +我将尝试去解释我对 Kubernetes 感兴趣的一些原因,而不去使用 “原生云cloud native”、“编排系统orchestration”、“容器container”,或者任何 Kubernetes 专用的术语 :)。我去解释的这些观点主要来自一位 Kubernetes 操作者/基础设施工程师,因为,我现在的工作就是去配置 Kubernetes 和让它工作的更好。 + +我不会去尝试解决一些如 “你应该在你的生产系统中使用 Kubernetes 吗?”这样的问题。那是非常复杂的问题。(不仅是因为“生产系统”根据你的用途而总是有不同的要求) + +### Kubernetes 可以让你无需设置一台新的服务器即可在生产系统中运行代码 + +我首次被说教使用 Kubernetes 是与我的伙伴 Kamal 的下面的谈话: + +大致是这样的: + +* Kamal: 使用 Kubernetes 你可以通过一条命令就能设置一台新的服务器。 +* Julia: 我觉得不太可能吧。 +* Kamal: 像这样,你写一个配置文件,然后应用它,这时候,你就在生产系统中运行了一个 HTTP 服务。 +* Julia: 但是,现在我需要去创建一个新的 AWS 实例,明确地写一个 Puppet 清单,设置服务发现,配置负载均衡,配置我们的部署软件,并且确保 DNS 正常工作,如果没有什么问题的话,至少在 4 小时后才能投入使用。 +* Kamal: 是的,使用 Kubernetes 你不需要做那么多事情,你可以在 5 分钟内设置一台新的 HTTP 服务,并且它将自动运行。只要你的集群中有空闲的资源它就能正常工作! +* Julia: 这儿一定是一个“坑”。 + +这里有一种陷阱,设置一个生产用 Kubernetes 集群(在我的经险中)确实并不容易。(查看 [Kubernetes 艰难之旅][3] 中去开始使用时有哪些复杂的东西)但是,我们现在并不深入讨论它。 + +因此,Kubernetes 第一个很酷的事情是,它可能使那些想在生产系统中部署新开发的软件的方式变得更容易。那是很酷的事,而且它真的是这样,因此,一旦你使用一个运作中的 Kubernetes 集群,你真的可以仅使用一个配置文件就在生产系统中设置一台 HTTP 服务(在 5 分钟内运行这个应用程序,设置一个负载均衡,给它一个 DNS 名字,等等)。看起来真的很有趣。 + +### 对于运行在生产系统中的代码,Kubernetes 可以提供更好的可见性和可管理性 + +在我看来,在理解 etcd 之前,你可能不会理解 Kubernetes 的。因此,让我们先讨论 etcd! + +想像一下,如果现在我这样问你,“告诉我你运行在生产系统中的每个应用程序,它运行在哪台主机上?它是否状态很好?是否为它分配了一个 DNS 名字?”我并不知道这些,但是,我可能需要到很多不同的地方去查询来回答这些问题,并且,我需要花很长的时间才能搞定。我现在可以很确定地说不需要查询,仅一个 API 就可以搞定它们。 + +在 Kubernetes 中,你的集群的所有状态 – 运行中的应用程序 (“pod”)、节点、DNS 名字、 cron 任务、 等等 —— 都保存在一个单一的数据库中(etcd)。每个 Kubernetes 组件是无状态的,并且基本是通过下列方式工作的: + +* 从 etcd 中读取状态(比如,“分配给节点 1 的 pod 列表”) +* 产生变化(比如,“在节点 1 上运行 pod A”) +* 更新 etcd 中的状态(比如,“设置 pod A 的状态为 ‘running’”) + +这意味着,如果你想去回答诸如 “在那个可用区中有多少台运行着 nginx 的 pod?” 这样的问题时,你可以通过查询一个统一的 API(Kubernetes API)去回答它。并且,你可以在每个其它 Kubernetes 组件上运行那个 API 去进行同样的访问。 + +这也意味着,你可以很容易地去管理每个运行在 Kubernetes 中的任何东西。比如说,如果你想要: + +* 部署实现一个复杂的定制的部署策略(部署一个东西,等待 2 分钟,部署 5 个以上,等待 3.7 分钟,等等) +* 每当推送到 github 上一个分支,自动化 [启动一个新的 web 服务器][1] +* 监视所有你的运行的应用程序,确保它们有一个合理的内存使用限制。 + +这些你只需要写一个程序与 Kubernetes API(“controller”)通讯就可以了。 + +另一个关于 Kubernetes API 的令人激动的事情是,你不会局限于 Kubernetes 所提供的现有功能!如果对于你要部署/创建/监视的软件有你自己的方案,那么,你可以使用 Kubernetes API 去写一些代码去达到你的目的!它可以让你做到你想做的任何事情。 + +### 即便每个 Kubernetes 组件都“挂了”,你的代码将仍然保持运行 + +关于 Kubernetes 我(在各种博客文章中 :))承诺的一件事情是,“如果 Kubernetes API 服务和其它组件‘挂了’也没事,你的代码将一直保持运行状态”。我认为理论上这听起来很酷,但是我不确定它是否真是这样的。 + +到目前为止,这似乎是真的! + +我已经断开了一些正在运行的 etcd,发生了这些情况: + +1. 所有的代码继续保持运行状态 +2. 不能做 _新的_ 事情(你不能部署新的代码或者生成变更,cron 作业将停止工作) +3. 当它恢复时,集群将赶上这期间它错过的内容 + +这样做意味着如果 etcd 宕掉,并且你的应用程序的其中之一崩溃或者发生其它事情,在 etcd 恢复之前,它不能够恢复。 + +### Kubernetes 的设计对 bug 很有弹性 + +与任何软件一样,Kubernetes 也会有 bug。例如,到目前为止,我们的集群控制管理器有内存泄漏,并且,调度器经常崩溃。bug 当然不好,但是,我发现 Kubernetes 的设计可以帮助减轻它的许多核心组件中的错误的影响。 + +如果你重启动任何组件,将会发生: + +* 从 etcd 中读取所有的与它相关的状态 +* 基于那些状态(调度 pod、回收完成的 pod、调度 cron 作业、按需部署等等),它会去做那些它认为必须要做的事情 + +因为,所有的组件并不会在内存中保持状态,你在任何时候都可以重启它们,这可以帮助你减轻各种 bug 的影响。 + +例如,如果在你的控制管理器中有内存泄露。因为,控制管理器是无状态的,你可以每小时定期去重启它,或者,在感觉到可能导致任何不一致的问题发生时重启它。又或者,在调度器中遇到了一个 bug,它有时忘记了某个 pod,从来不去调度它们。你可以每隔 10 分钟来重启调度器来缓减这种情况。(我们并不会这么做,而是去修复这个 bug,但是,你_可以这样做_ :)) + +因此,我觉得即使在它的核心组件中有 bug,我仍然可以信任 Kubernetes 的设计可以让我确保集群状态的一致性。并且,总在来说,随着时间的推移软件质量会提高。唯一你必须去操作的有状态的东西就是 etcd。 + +不用过多地讨论“状态”这个东西 —— 而我认为在 Kubernetes 中很酷的一件事情是,唯一需要去做备份/恢复计划的东西是 etcd (除非为你的 pod 使用了持久化存储的卷)。我认为这样可以使 Kubernetes 运维比你想的更容易一些。 + +### 在 Kubernetes 之上实现新的分布式系统是非常容易的 + +假设你想去实现一个分布式 cron 作业调度系统!从零开始做工作量非常大。但是,在 Kubernetes 里面实现一个分布式 cron 作业调度系统是非常容易的!(仍然没那么简单,毕竟它是一个分布式系统) + +我第一次读到 Kubernetes 的 cron 作业控制器的代码时,我对它是如此的简单感到由衷高兴。去读读看,其主要的逻辑大约是 400 行的 Go 代码。去读它吧! => [cronjob_controller.go][4] <= + +cron 作业控制器基本上做的是: + +* 每 10 秒钟: + * 列出所有已存在的 cron 作业 + * 检查是否有需要现在去运行的任务 + * 如果有,创建一个新的作业对象去调度,并通过其它的 Kubernetes 控制器实际运行它 + * 清理已完成的作业 + * 重复以上工作 + +Kubernetes 模型是很受限制的(它有定义在 etcd 中的资源模式,控制器读取这个资源并更新 etcd),我认为这种相关的固有的/受限制的模型,可以使它更容易地在 Kubernetes 框架中开发你自己的分布式系统。 + +Kamal 给我说的是 “Kubernetes 是一个写你自己的分布式系统的很好的平台” ,而不是“ Kubernetes 是一个你可以使用的分布式系统”,并且,我觉得它真的很有意思。他做了一个 [为你推送到 GitHub 的每个分支运行一个 HTTP 服务的系统][5] 的原型。这花了他一个周末的时间,大约 800 行 Go 代码,我认为它真不可思议! + +### Kubernetes 可以使你做一些非常神奇的事情(但并不容易) + +我一开始就说 “kubernetes 可以让你做一些很神奇的事情,你可以用一个配置文件来做这么多的基础设施,它太神奇了”。这是真的! + +为什么说 “Kubernetes 并不容易”呢?是因为 Kubernetes 有很多部分,学习怎么去成功地运营一个高可用的 Kubernetes 集群要做很多的工作。就像我发现它给我了许多抽象的东西,我需要去理解这些抽象的东西才能调试问题和正确地配置它们。我喜欢学习新东西,因此,它并不会使我发狂或者生气,但是我认为了解这一点很重要 :) + +对于 “我不能仅依靠抽象概念” 的一个具体的例子是,我努力学习了许多 [Linux 上网络是如何工作的][6],才让我对设置 Kubernetes 网络稍有信心,这比我以前学过的关于网络的知识要多很多。这种方式很有意思但是非常费时间。在以后的某个时间,我或许写更多的关于设置 Kubernetes 网络的困难/有趣的事情。 + +或者,为了成功设置我的 Kubernetes CA,我写了一篇 [2000 字的博客文章][7],述及了我不得不学习 Kubernetes 不同方式的 CA 的各种细节。 + +我觉得,像 GKE (Google 的 Kubernetes 产品) 这样的一些监管的 Kubernetes 的系统可能更简单,因为,他们为你做了许多的决定,但是,我没有尝试过它们。 + +-------------------------------------------------------------------------------- + +via: https://jvns.ca/blog/2017/10/05/reasons-kubernetes-is-cool/ + +作者:[Julia Evans][a] +译者:[qhwdw](https://github.com/qhwdw) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://jvns.ca/about +[1]:https://github.com/kamalmarhubi/kubereview +[2]:https://jvns.ca/categories/kubernetes +[3]:https://github.com/kelseyhightower/kubernetes-the-hard-way +[4]:https://github.com/kubernetes/kubernetes/blob/e4551d50e57c089aab6f67333412d3ca64bc09ae/pkg/controller/cronjob/cronjob_controller.go +[5]:https://github.com/kamalmarhubi/kubereview +[6]:https://jvns.ca/blog/2016/12/22/container-networking/ +[7]:https://jvns.ca/blog/2017/08/05/how-kubernetes-certificates-work/ + + diff --git a/published/20171103 How To Fully Update And Upgrade Offline Debian-based Systems.md b/published/20171103 How To Fully Update And Upgrade Offline Debian-based Systems.md new file mode 100644 index 0000000000..e5d9adc1e6 --- /dev/null +++ b/published/20171103 How To Fully Update And Upgrade Offline Debian-based Systems.md @@ -0,0 +1,127 @@ +怎样完整地离线更新并升级基于 Debian 的操作系统 +====== + +![](https://www.ostechnix.com/wp-content/uploads/2017/11/Upgrade-Offline-Debian-based-Systems-2-720x340.png) + +不久之前我已经向你展示了如何在任意离线的 [Ubuntu][1] 和 [Arch Linux][2] 操作系统上安装软件。 今天,我们将会看看如何完整地离线更新并升级基于 Debian 的操作系统。 和之前所述方法的不同之处在于,这次我们将会升级整个操作系统,而不是单个的软件包。这个方法在你没有网络链接或拥有的网络速度很慢的时候十分有用。 + +### 完整地离线更新并升级基于 Debian 的操作系统 + +首先假设,你在单位拥有正在运行并配置有高速互联网链接的系统(Windows 或者 Linux),而在家有一个没有网络链接或网络很慢(例如拨号网络)的 Debian 或其衍生的操作系统。现在如果你想要离线更新你家里的操作系统怎么办?购买一个更加高速的网络链接?不,根本不需要!你仍然可以通过互联网离线更新升级你的操作系统。这正是 **Apt-Offline**工具可以帮助你做到的。 + +正如其名,apt-offline 是一个为 Debian 及其衍生发行版(诸如 Ubuntu、Linux Mint 这样基于 APT 的操作系统)提供的离线 APT 包管理器。使用 apt-offline,我们可以完整地更新/升级我们的 Debian 系统而不需要网络链接。这个程序是由 Python 编程语言写成的兼具 CLI 和图形界面的跨平台工具。 + +#### 准备工作 + +* 一个已经联网的操作系统(Windows 或者 Linux)。在这份指南中,为了便于理解,我们将之称为在线操作系统。 +* 一个离线操作系统(Debian 及其衍生版本)。我们称之为离线操作系统。 +* 有足够空间容纳所有更新包的 USB 驱动器或者外接硬盘。 + +#### 安装 + +Apt-Offline 可以在 Debian 及其衍生版本的默认仓库中获得。如果你的在线操作系统是运行的 Debian、Ubuntu、Linux Mint,及其它基于 DEB 的操作系统,你可以通过下面的命令安装 Apt-Offline: + +``` +sudo apt-get install apt-offline +``` + +如果你的在线操作系统运行的是非 Debian 类的发行版,使用 `git clone` 获取 Apt-Offline 仓库: + +``` +git clone https://github.com/rickysarraf/apt-offline.git +``` + +切换到克隆的目录下并在此处运行: + +``` +cd apt-offline/ +sudo ./apt-offline +``` + +#### 在离线操作系统(没有联网的操作系统)上的步骤 + +到你的离线操作系统上创建一个你想存储签名文件的目录: + +``` +mkdir ~/tmp +cd ~/tmp/ +``` + +你可以自己选择使用任何目录。接下来,运行下面的命令生成签名文件: + +``` +sudo apt-offline set apt-offline.sig +``` + +示例输出如下: + +``` +Generating database of files that are needed for an update. +Generating database of file that are needed for operation upgrade +``` + +默认条件下,apt-offline 将会生成需要更新和升级的相关文件的数据库。你可以使用 `--update` 或者 `--upgrade` 选项相应创建。 + +拷贝完整的 `tmp` 目录到你的 USB 驱动器或者或者外接硬盘上,然后换到你的在线操作系统(有网络链接的操作系统)。 + +#### 在在线操作系统上的步骤 + +插入你的 USB 驱动器然后进入 `tmp` 文件夹: + +``` +cd tmp/ +``` + +然后,运行如下命令: + +``` +sudo apt-offline get apt-offline.sig --threads 5 --bundle apt-offline-bundle.zip +``` + +在这里的 `-threads 5` 代表着(并发连接的) APT 仓库的数目。如果你想要从更多的仓库下载软件包,你可以增加这里的数值。然后 `-bundle apt-offline-bundle.zip` 选项表示所有的软件包将会打包到一个叫做 `apt-offline-bundle.zip` 的单独存档中。这个存档文件将会被保存在你的当前工作目录中(LCTT 译注:即 `tmp` 目录)。 + +上面的命令将会按照之前在离线操作系统上生成的签名文件下载数据。 + +![][4] + +根据你的网络状况,这个操作将会花费几分钟左右的时间。请记住,apt-offline 是跨平台的,所以你可以在任何操作系统上使用它下载包。 + +一旦下载完成,拷贝 `tmp` 文件夹到你的 USB 或者外接硬盘上并且返回你的离线操作系统(LCTT 译注:此处的复制操作似不必要,因为我们一直在 USB 存储器的 `tmp` 目录中操作)。千万保证你的 USB 驱动器上有足够的空闲空间存储所有的下载文件,因为所有的包都放在 `tmp` 文件夹里了。 + +#### 离线操作系统上的步骤 + +把你的设备插入你的离线操作系统,然后切换到你之前下载了所有包的 `tmp`目录下。 + +``` +cd tmp +``` + +然后,运行下面的命令来安装所有下载好的包。 + +``` +sudo apt-offline install apt-offline-bundle.zip +``` + +这个命令将会更新 APT 数据库,所以 APT 将会在 APT 缓冲里找所有需要的包。 + +**注意事项:** 如果在线和离线操作系统都在同一个局域网中,你可以通过 `scp` 或者其他传输应用程序将 `tmp` 文件传到离线操作系统中。如果两个操作系统在不同的位置(LCTT 译注:意指在不同的局域网),那就使用 USB 设备来拷贝。 + +好了大伙儿,现在就这么多了。 希望这篇指南对你有用。还有更多好东西正在路上。敬请关注! + +祝你愉快! + +-------------------------------------------------------------------------------- + +via: https://www.ostechnix.com/fully-update-upgrade-offline-debian-based-systems/ + +作者:[SK][a] +译者:[leemeans](https://github.com/leemeans) +校对:[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-softwares-offline-ubuntu-16-04/ +[2]:https://www.ostechnix.com/install-packages-offline-arch-linux/ +[3]:data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7 +[4]:http://www.ostechnix.com/wp-content/uploads/2017/11/apt-offline.png diff --git a/translated/tech/20171112 Step by Step guide for creating Master Slave replication in MariaDB.md b/published/20171112 Step by Step guide for creating Master Slave replication in MariaDB.md similarity index 59% rename from translated/tech/20171112 Step by Step guide for creating Master Slave replication in MariaDB.md rename to published/20171112 Step by Step guide for creating Master Slave replication in MariaDB.md index 397843785e..e00a2615a6 100644 --- a/translated/tech/20171112 Step by Step guide for creating Master Slave replication in MariaDB.md +++ b/published/20171112 Step by Step guide for creating Master Slave replication in MariaDB.md @@ -1,27 +1,26 @@ -一步一步学习如何在 MariaDB 中配置主从复制 +循序渐进学习如何在 MariaDB 中配置主从复制 ====== -在我们前面的教程中,我们已经学习了 [**如何安装和配置 MariaDB**][1],也学习了 [**管理 MariaDB 的一些基础命令**][2]。现在我们来学习,如何在 MariaDB 服务器上配置一个主从复制。 -复制是用于为我们的数据库去创建多个副本,这些副本可以在其它数据库上用于运行查询,像一些非常繁重的查询可能会影响主数据库服务器的性能,或者我们可以使用它来做数据冗余,或者兼具以上两个目的。我们可以将这个过程自动化,即主服务器到从服务器的复制过程自动进行。执行备份而不影响在主服务器上的写操作。 +在我们前面的教程中,我们已经学习了 [如何安装和配置 MariaDB][1],也学习了 [管理 MariaDB 的一些基础命令][2]。现在我们来学习,如何在 MariaDB 服务器上配置一个主从复制。 + +复制是用于为我们的数据库创 建多个副本,这些副本可以在其它数据库上用于运行查询,像一些非常繁重的查询可能会影响主数据库服务器的性能,或者我们可以使用它来做数据冗余,或者兼具以上两个目的。我们可以将这个过程自动化,即主服务器到从服务器的复制过程自动进行。执行备份而不影响在主服务器上的写操作。 因此,我们现在去配置我们的主-从复制,它需要两台安装了 MariaDB 的机器。它们的 IP 地址如下: - **主服务器 -** 192.168.1.120 **主机名** master.ltechlab.com +- **主服务器 -** 192.168.1.120 **主机名 -** master.ltechlab.com +- **从服务器 -** 192.168.1.130 **主机名 -** slave.ltechlab.com - **从服务器 -** 192.168.1.130 **主机名 -** slave.ltechlab.com +MariaDB 安装到这些机器上之后,我们继续进行本教程。如果你需要安装和配置 MariaDB 的教程,请查看[**这个教程**][1]。 -MariaDB 安装到这些机器上之后,我们继续进行本教程。如果你需要安装和配置 MariaDB 的教程,请查看[ **这个教程**][1]。 +### 第 1 步 - 主服务器配置 - -### **第 1 步 - 主服务器配置** - -我们现在进入到 MariaDB 中的一个命名为 ' **important '** 的数据库,它将被复制到我们的从服务器。为开始这个过程,我们编辑名为 ' **/etc/my.cnf** ' 的文件,它是 MariaDB 的配置文件。 +我们现在进入到 MariaDB 中的一个命名为 `important` 的数据库,它将被复制到我们的从服务器。为开始这个过程,我们编辑名为 `/etc/my.cnf` 的文件,它是 MariaDB 的配置文件。 ``` $ vi /etc/my.cnf ``` -在这个文件中找到 [mysqld] 节,然后输入如下内容: +在这个文件中找到 `[mysqld]` 节,然后输入如下内容: ``` [mysqld] @@ -43,7 +42,7 @@ $ systemctl restart mariadb $ mysql -u root -p ``` -在它上面创建一个命名为 'slaveuser' 的为主从复制使用的新用户,然后运行如下的命令为它分配所需要的权限: +在它上面创建一个命名为 `slaveuser` 的为主从复制使用的新用户,然后运行如下的命令为它分配所需要的权限: ``` STOP SLAVE; @@ -53,19 +52,19 @@ FLUSH TABLES WITH READ LOCK; SHOW MASTER STATUS; ``` -**注意: ** 我们配置主从复制需要 **MASTER_LOG_FILE 和 MASTER_LOG_POS ** 的值,它可以通过 'show master status' 来获得,因此,你一定要确保你记下了它们的值。 +**注意:** 我们配置主从复制需要 `MASTER_LOG_FILE` 和 `MASTER_LOG_POS` 的值,它可以通过 `show master status` 来获得,因此,你一定要确保你记下了它们的值。 -这些命令运行完成之后,输入 'exit' 退出这个会话。 +这些命令运行完成之后,输入 `exit` 退出这个会话。 ### 第 2 步 - 创建一个数据库备份,并将它移动到从服务器上 -现在,我们需要去为我们的数据库 'important' 创建一个备份,可以使用 'mysqldump' 命令去备份。 +现在,我们需要去为我们的数据库 `important` 创建一个备份,可以使用 `mysqldump` 命令去备份。 ``` $ mysqldump -u root -p important > important_backup.sql ``` -备份完成后,我们需要重新登陆到 MariaDB 数据库,并解锁我们的表。 +备份完成后,我们需要重新登录到 MariaDB 数据库,并解锁我们的表。 ``` $ mysql -u root -p @@ -78,7 +77,7 @@ $ UNLOCK TABLES; ### 第 3 步:配置从服务器 -我们再次去编辑 '/etc/my.cnf' 文件,找到配置文件中的 [mysqld] 节,然后输入如下内容: +我们再次去编辑(从服务器上的) `/etc/my.cnf` 文件,找到配置文件中的 `[mysqld]` 节,然后输入如下内容: ``` [mysqld] @@ -93,7 +92,7 @@ replicate-do-db=important $ mysql -u root -p < /data/ important_backup.sql ``` -当这个恢复过程结束之后,我们将通过登入到从服务器上的 MariaDB,为数据库 'important' 上的用户 'slaveuser' 授权。 +当这个恢复过程结束之后,我们将通过登入到从服务器上的 MariaDB,为数据库 `important` 上的用户 'slaveuser' 授权。 ``` $ mysql -u root -p @@ -110,9 +109,9 @@ FLUSH PRIVILEGES; $ systemctl restart mariadb ``` -### **第 4 步:启动复制** +### 第 4 步:启动复制 -记住,我们需要 **MASTER_LOG_FILE 和 MASTER_LOG_POS** 变量的值,它可以通过在主服务器上运行 'SHOW MASTER STATUS' 获得。现在登入到从服务器上的 MariaDB,然后通过运行下列命令,告诉我们的从服务器它应该去哪里找主服务器。 +记住,我们需要 `MASTER_LOG_FILE` 和 `MASTER_LOG_POS` 变量的值,它可以通过在主服务器上运行 `SHOW MASTER STATUS` 获得。现在登入到从服务器上的 MariaDB,然后通过运行下列命令,告诉我们的从服务器它应该去哪里找主服务器。 ``` STOP SLAVE; @@ -131,13 +130,13 @@ SHOW SLAVE STATUS\G; $ mysql -u root -p ``` -选择数据库为 'important': +选择数据库为 `important`: ``` use important; ``` -在这个数据库上创建一个名为 ‘test’ 的表: +在这个数据库上创建一个名为 `test` 的表: ``` create table test (c int); @@ -175,10 +174,10 @@ via: http://linuxtechlab.com/creating-master-slave-replication-mariadb/ 作者:[Shusain][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]:http://linuxtechlab.com/author/shsuain/ -[1]:http://linuxtechlab.com/installing-configuring-mariadb-rhelcentos/ -[2]:http://linuxtechlab.com/mariadb-administration-commands-beginners/ +[1]:https://linux.cn/article-8320-1.html +[2]:https://linux.cn/article-9306-1.html diff --git a/translated/tech/20171127 Protecting Your Website From Application Layer DOS Attacks With mod.md b/published/20171127 Protecting Your Website From Application Layer DOS Attacks With mod.md similarity index 61% rename from translated/tech/20171127 Protecting Your Website From Application Layer DOS Attacks With mod.md rename to published/20171127 Protecting Your Website From Application Layer DOS Attacks With mod.md index 7913acd02c..869e02b6c7 100644 --- a/translated/tech/20171127 Protecting Your Website From Application Layer DOS Attacks With mod.md +++ b/published/20171127 Protecting Your Website From Application Layer DOS Attacks With mod.md @@ -1,12 +1,12 @@ -用 mod 保护您的网站免受应用层 DOS 攻击 +用 Apache 服务器模块保护您的网站免受应用层 DOS 攻击 ====== -有多种恶意攻击网站的方法,比较复杂的方法要涉及数据库和编程方面的技术知识。一个更简单的方法被称为“拒绝服务”或“DOS”攻击。这个攻击方法的名字来源于它的意图:使普通客户或网站访问者的正常服务请求被拒绝。 +有多种可以导致网站下线的攻击方法,比较复杂的方法要涉及数据库和编程方面的技术知识。一个更简单的方法被称为“拒绝服务Denial Of Service”(DOS)攻击。这个攻击方法的名字来源于它的意图:使普通客户或网站访问者的正常服务请求被拒绝。 一般来说,有两种形式的 DOS 攻击: - 1. OSI 模型的三、四层,即网络层攻击 - 2. OSI 模型的七层,即应用层攻击 +1. OSI 模型的三、四层,即网络层攻击 +2. OSI 模型的七层,即应用层攻击 第一种类型的 DOS 攻击——网络层,发生于当大量的垃圾流量流向网页服务器时。当垃圾流量超过网络的处理能力时,网站就会宕机。 @@ -14,174 +14,172 @@ 本文将着眼于缓解应用层攻击,因为减轻网络层攻击需要大量的可用带宽和上游提供商的合作,这通常不是通过配置网络服务器就可以做到的。 -通过配置普通的网页服务器,可以保护网页免受应用层攻击,至少是适度的防护。防止这种形式的攻击是非常重要的,因为 [Cloudflare][1] 最近 [报道][2] 了网络层攻击的数量正在减少,而应用层攻击的数量则在增加。 +通过配置普通的网页服务器,可以保护网页免受应用层攻击,至少是适度的防护。防止这种形式的攻击是非常重要的,因为 [Cloudflare][1] 最近 [报告称][2] 网络层攻击的数量正在减少,而应用层攻击的数量则在增加。 -本文将根据 [zdziarski 的博客][4] 来解释如何使用 Apache2 的模块 [mod_evasive][3]。 +本文将介绍如何使用 [zdziarski][4] 开发的 Apache2 的模块 [mod_evasive][3]。 -另外,mod_evasive 会阻止攻击者试图通过尝试数百个组合来猜测用户名和密码,即暴力攻击。 +另外,mod_evasive 会阻止攻击者通过尝试数百个用户名和密码的组合来进行猜测(即暴力攻击)的企图。 -Mod_evasive 会记录来自每个 IP 地址的请求的数量。当这个数字超过相应 IP 地址的几个阈值之一时,会出现一个错误页面。错误页面所需的资源要比一个能够响应合法访问的在线网站少得多。 +mod_evasive 会记录来自每个 IP 地址的请求的数量。当这个数字超过相应 IP 地址的几个阈值之一时,会出现一个错误页面。错误页面所需的资源要比一个能够响应合法访问的在线网站少得多。 ### 在 Ubuntu 16.04 上安装 mod_evasive -Ubuntu 16.04 默认的软件库中包含了 mod_evasive,名称为“libapache2-mod-evasive”。您可以使用 `apt-get` 来完成安装: +Ubuntu 16.04 默认的软件库中包含了 mod_evasive,名称为 “libapache2-mod-evasive”。您可以使用 `apt-get` 来完成安装: + ``` apt-get update apt-get upgrade apt-get install libapache2-mod-evasive - ``` 现在我们需要配置 mod_evasive。 它的配置文件位于 `/etc/apache2/mods-available/evasive.conf`。默认情况下,所有模块的设置在安装后都会被注释掉。因此,在修改配置文件之前,模块不会干扰到网站流量。 + ``` - - #DOSHashTableSize 3097 - #DOSPageCount 2 - #DOSSiteCount 50 - #DOSPageInterval 1 - #DOSSiteInterval 1 - #DOSBlockingPeriod 10 - - #DOSEmailNotify you@yourdomain.com - #DOSSystemCommand "su - someuser -c '/sbin/... %s ...'" - #DOSLogDir "/var/log/mod_evasive" + + #DOSHashTableSize 3097 + #DOSPageCount 2 + #DOSSiteCount 50 + #DOSPageInterval 1 + #DOSSiteInterval 1 + #DOSBlockingPeriod 10 + + #DOSEmailNotify you@yourdomain.com + #DOSSystemCommand "su - someuser -c '/sbin/... %s ...'" + #DOSLogDir "/var/log/mod_evasive" - ``` 第一部分的参数的含义如下: - * **DOSHashTableSize** - 正在访问网站的 IP 地址列表及其请求数。 - * **DOSPageCount** - 在一定的时间间隔内,每个的页面的请求次数。时间间隔由 DOSPageInterval 定义。 - * **DOSPageInterval** - mod_evasive 统计页面请求次数的时间间隔。 - * **DOSSiteCount** - 与 DOSPageCount 相同,但统计的是网站内任何页面的来自相同 IP 地址的请求数量。 - * **DOSSiteInterval** - mod_evasive 统计网站请求次数的时间间隔。 - * **DOSBlockingPeriod** - 某个 IP 地址被加入黑名单的时长(以秒为单位)。 - + * `DOSHashTableSize` - 正在访问网站的 IP 地址列表及其请求数的当前列表。 + * `DOSPageCount` - 在一定的时间间隔内,每个页面的请求次数。时间间隔由 DOSPageInterval 定义。 + * `DOSPageInterval` - mod_evasive 统计页面请求次数的时间间隔。 + * `DOSSiteCount` - 与 `DOSPageCount` 相同,但统计的是来自相同 IP 地址对网站内任何页面的请求数量。 + * `DOSSiteInterval` - mod_evasive 统计网站请求次数的时间间隔。 + * `DOSBlockingPeriod` - 某个 IP 地址被加入黑名单的时长(以秒为单位)。 如果使用上面显示的默认配置,则在如下情况下,一个 IP 地址会被加入黑名单: * 每秒请求同一页面超过两次。 * 每秒请求 50 个以上不同页面。 - 如果某个 IP 地址超过了这些阈值,则被加入黑名单 10 秒钟。 这看起来可能不算久,但是,mod_evasive 将一直监视页面请求,包括在黑名单中的 IP 地址,并重置其加入黑名单的起始时间。只要一个 IP 地址一直尝试使用 DOS 攻击该网站,它将始终在黑名单中。 其余的参数是: - * **DOSEmailNotify** - 用于接收 DOS 攻击信息和 IP 地址黑名单的电子邮件地址。 - * **DOSSystemCommand** - 检测到 DOS 攻击时运行的命令。 - * **DOSLogDir** - 用于存放 mod_evasive 的临时文件的目录。 - + * `DOSEmailNotify` - 用于接收 DOS 攻击信息和 IP 地址黑名单的电子邮件地址。 + * `DOSSystemCommand` - 检测到 DOS 攻击时运行的命令。 + * `DOSLogDir` - 用于存放 mod_evasive 的临时文件的目录。 ### 配置 mod_evasive -默认的配置是一个很好的开始,因为它的黑名单里不该有任何合法的用户。取消配置文件中的所有参数(DOSSystemCommand 除外)的注释,如下所示: +默认的配置是一个很好的开始,因为它不会阻塞任何合法的用户。取消配置文件中的所有参数(`DOSSystemCommand` 除外)的注释,如下所示: + ``` - - DOSHashTableSize 3097 - DOSPageCount 2 - DOSSiteCount 50 - DOSPageInterval 1 - DOSSiteInterval 1 - DOSBlockingPeriod 10 - - DOSEmailNotify JohnW@example.com - #DOSSystemCommand "su - someuser -c '/sbin/... %s ...'" - DOSLogDir "/var/log/mod_evasive" + + DOSHashTableSize 3097 + DOSPageCount 2 + DOSSiteCount 50 + DOSPageInterval 1 + DOSSiteInterval 1 + DOSBlockingPeriod 10 + + DOSEmailNotify JohnW@example.com + #DOSSystemCommand "su - someuser -c '/sbin/... %s ...'" + DOSLogDir "/var/log/mod_evasive" - ``` -必须要创建日志目录并且要赋予其与 apache 进程相同的所有者。这里创建的目录是 `/var/log/mod_evasive` ,并且在 Ubuntu 上将该目录的所有者和组设置为 `www-data` ,与 Apache 服务器相同: +必须要创建日志目录并且要赋予其与 apache 进程相同的所有者。这里创建的目录是 `/var/log/mod_evasive` ,并且在 Ubuntu 上将该目录的所有者和组设置为 `www-data` ,与 Apache 服务器相同: + ``` mkdir /var/log/mod_evasive chown www-data:www-data /var/log/mod_evasive - ``` 在编辑了 Apache 的配置之后,特别是在正在运行的网站上,在重新启动或重新加载之前,最好检查一下语法,因为语法错误将影响 Apache 的启动从而使网站宕机。 Apache 包含一个辅助命令,是一个配置语法检查器。只需运行以下命令来检查您的语法: + ``` apachectl configtest - ``` 如果您的配置是正确的,会得到如下结果: + ``` Syntax OK - ``` 但是,如果出现问题,您会被告知在哪部分发生了什么错误,例如: + ``` AH00526: Syntax error on line 6 of /etc/apache2/mods-enabled/evasive.conf: DOSSiteInterval takes one argument, Set site interval Action 'configtest' failed. The Apache error log may have more information. - ``` 如果您的配置通过了 configtest 的测试,那么这个模块可以安全地被启用并且 Apache 可以重新加载: + ``` a2enmod evasive systemctl reload apache2.service - ``` -Mod_evasive 现在已配置好并正在运行了。 +mod_evasive 现在已配置好并正在运行了。 ### 测试 为了测试 mod_evasive,我们只需要向服务器提出足够的网页访问请求,以使其超出阈值,并记录来自 Apache 的响应代码。 一个正常并成功的页面请求将收到如下响应: + ``` HTTP/1.1 200 OK - ``` 但是,被 mod_evasive 拒绝的将返回以下内容: + ``` HTTP/1.1 403 Forbidden - ``` 以下脚本会尽可能迅速地向本地主机(127.0.0.1,localhost)的 80 端口发送 HTTP 请求,并打印出每个请求的响应代码。 你所要做的就是把下面的 bash 脚本复制到一个文件中,例如 `mod_evasive_test.sh`: + ``` -#!/bin/bash -set -e - -for i in {1..50}; do - curl -s -I 127.0.0.1 | head -n 1 +#!/bin/bash +set -e + +for i in {1..50}; do + curl -s -I 127.0.0.1 | head -n 1 done - ``` 这个脚本的部分含义如下: - * curl - 这是一个发出网络请求的命令。 - * -s - 隐藏进度表。 - * -I - 仅显示响应头部信息。 - * head - 打印文件的第一部分。 - * -n 1 - 只显示第一行。 + * `curl` - 这是一个发出网络请求的命令。 + * `-s` - 隐藏进度表。 + * `-I` - 仅显示响应头部信息。 + * `head` - 打印文件的第一部分。 + * `-n 1` - 只显示第一行。 然后赋予其执行权限: + ``` chmod 755 mod_evasive_test.sh - ``` -在启用 mod_evasive **之前**,脚本运行时,将会看到 50 行“HTTP / 1.1 200 OK”的返回值。 +在启用 mod_evasive **之前**,脚本运行时,将会看到 50 行 “HTTP / 1.1 200 OK” 的返回值。 但是,启用 mod_evasive 后,您将看到以下内容: + ``` HTTP/1.1 200 OK HTTP/1.1 200 OK @@ -191,13 +189,11 @@ HTTP/1.1 403 Forbidden HTTP/1.1 403 Forbidden HTTP/1.1 403 Forbidden ... - ``` 前两个请求被允许,但是在同一秒内第三个请求发出时,mod_evasive 拒绝了任何进一步的请求。您还将收到一封电子邮件(邮件地址在选项 `DOSEmailNotify` 中设置),通知您有 DOS 攻击被检测到。 -Mod_evasive 现在已经在保护您的网站啦! - +mod_evasive 现在已经在保护您的网站啦! -------------------------------------------------------------------------------- @@ -205,7 +201,7 @@ via: https://bash-prompt.net/guides/mod_proxy/ 作者:[Elliot Cooper][a] 译者:[jessie-pang](https://github.com/jessie-pang) -校对:[校对者ID](https://github.com/校对者ID) +校对:[wxy](https://github.com/wxy) 本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 diff --git a/published/20171202 MariaDB administration commands for beginners.md b/published/20171202 MariaDB administration commands for beginners.md new file mode 100644 index 0000000000..4650044649 --- /dev/null +++ b/published/20171202 MariaDB administration commands for beginners.md @@ -0,0 +1,174 @@ +为初学者准备的 MariaDB 管理命令 +====== + +之前我们学过了[在 Centos/RHEL 7 上安装 MariaDB 服务器并保证其安全][1],使之成为了 RHEL/CentOS 7 的默认数据库。现在我们再来看看一些有用的 MariaDB 管理命令。这些都是使用 MariaDB 最基础的命令,而且它们对 MySQL 也同样适合,因为 Mariadb 就是 MySQL 的一个分支而已。 + +**(推荐阅读:[在 RHEL/CentOS 上安装并配置 MongoDB][2])** + +### MariaDB 管理命令 + +#### 1、查看 MariaDB 安装的版本 + +要查看所安装数据库的当前版本,在终端中输入下面命令: + +``` +$ mysql -version +``` + +该命令会告诉你数据库的当前版本。此外你也可以运行下面命令来查看版本的详细信息: + +``` +$ mysqladmin -u root -p version +``` + +#### 2、登录 MariaDB + +要登录 MariaDB 服务器,运行: + +``` +$ mysql -u root -p +``` + +然后输入密码登录。 + +#### 3、列出所有的数据库 + +要列出 MariaDB 当前拥有的所有数据库,在你登录到 MariaDB 中后运行: + +``` +> show databases; +``` + +(LCTT 译注:`$` 这里代表 shell 的提示符,`>` 这里代表 MariaDB shell 的提示符。) + +#### 4、创建新数据库 + +在 MariaDB 中创建新数据库,登录 MariaDB 后运行: + +``` +> create database dan; +``` + +若想直接在终端创建数据库,则运行: + +``` +$ mysqladmin -u user -p create dan +``` + +这里,`dan` 就是新数据库的名称。 + +#### 5、删除数据库 + +要删除数据库,在已登录的 MariaDB 会话中运行: + +``` +> drop database dan; +``` + +此外你也可以运行, + +``` +$ mysqladmin -u root -p drop dan +``` + +**注意:** 若在运行 `mysqladmin` 命令时提示 “access denied” 错误,这应该是由于我们没有给 root 授权。要对 root 授权,请参照第 7 点方法,只是要将用户改成 root。 + +#### 6、创建新用户 + +为数据库创建新用户,运行: + +``` +> CREATE USER 'dan'@'localhost' IDENTIFIED BY 'password'; +``` + +#### 7、授权用户访问某个数据库 + +授权用户访问某个数据库,运行: + +``` +> GRANT ALL PRIVILEGES ON test.* to 'dan'@'localhost'; +``` + +这会赋予用户 `dan` 对名为 `test` 的数据库完全操作的权限。我们也可以限定为用户只赋予 `SELECT`、`INSERT`、`DELETE` 权限。 + +要赋予访问所有数据库的权限,将 `test` 替换成 `*` 。像这样: + +``` +> GRANT ALL PRIVILEGES ON *.* to 'dan'@'localhost'; +``` + +#### 8、备份/导出数据库 + +要创建单个数据库的备份,在终端窗口中运行下列命令, + +``` +$ mysqldump -u root -p database_name>db_backup.sql +``` + +若要一次性创建多个数据库的备份则运行: + +``` +$ mysqldump -u root -p --databases db1 db2 > db12_backup.sql +``` + +要一次性导出多个数据库,则运行: + +``` +$ mysqldump -u root -p --all-databases > all_dbs.sql +``` + +#### 9、从备份中恢复数据库 + +要从备份中恢复数据库,运行: + +``` +$ mysql -u root -p database_name < db_backup.sql +``` + +但这条命令成功的前提是预先没有存在同名的数据库。如果想要恢复数据库数据到已经存在的数据库中,则需要用到 `mysqlimport` 命令: + +``` +$ mysqlimport -u root -p database_name < db_backup.sql +``` + +#### 10、更改 mariadb 用户的密码 + +本例中我们会修改 `root` 的密码,但修改其他用户的密码也是一样的过程。 + +登录 mariadb 并切换到 'mysql' 数据库: + +``` +$ mysql -u root -p +> use mysql; +``` + +然后运行下面命令: + +``` +> update user set password=PASSWORD('your_new_password_here') where User='root'; +``` + +下一步,重新加载权限: + +``` +> flush privileges; +``` + +然后退出会话。 + +我们的教程至此就结束了,在本教程中我们学习了一些有用的 MariaDB 管理命令。欢迎您的留言。 + + +-------------------------------------------------------------------------------- + +via: http://linuxtechlab.com/mariadb-administration-commands-beginners/ + +作者:[Shusain][a] +译者:[lujun9972](https://github.com/lujun9972) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:http://linuxtechlab.com/author/shsuain/ +[1]:http://linuxtechlab.com/installing-configuring-mariadb-rhelcentos/ +[2]:http://linuxtechlab.com/mongodb-installation-configuration-rhelcentos/ diff --git a/published/20171212 How To Count The Number Of Files And Folders-Directories In Linux.md b/published/20171212 How To Count The Number Of Files And Folders-Directories In Linux.md new file mode 100644 index 0000000000..3f8b2c6312 --- /dev/null +++ b/published/20171212 How To Count The Number Of Files And Folders-Directories In Linux.md @@ -0,0 +1,201 @@ +如何统计 Linux 中文件和文件夹/目录的数量 +====== + +嗨,伙计们,今天我们再次带来一系列可以多方面帮助到你的复杂的命令。 通过操作命令,可以帮助您计数当前目录中的文件和目录、递归计数,统计特定用户创建的文件列表等。 + +在本教程中,我们将向您展示如何使用多个命令,并使用 `ls`、`egrep`、`wc` 和 `find` 命令执行一些高级操作。 下面的命令将可用在多个方面。 + +为了实验,我打算总共创建 7 个文件和 2 个文件夹(5 个常规文件和 2 个隐藏文件)。 下面的 `tree` 命令的输出清楚的展示了文件和文件夹列表。 + +``` +# tree -a /opt +/opt +├── magi +│   └── 2g +│   ├── test5.txt +│   └── .test6.txt +├── test1.txt +├── test2.txt +├── test3.txt +├── .test4.txt +└── test.txt + +2 directories, 7 files +``` + +### 示例-1 + +统计当前目录的文件(不包括隐藏文件)。 运行以下命令以确定当前目录中有多少个文件,并且不计算点文件(LCTT 译注:点文件即以“.” 开头的文件,它们在 Linux 默认是隐藏的)。 + +``` +# ls -l . | egrep -c '^-' +4 +``` + +**细节:** + + * `ls` : 列出目录内容 + * `-l` : 使用长列表格式 + * `.` : 列出有关文件的信息(默认为当前目录) + * `|` : 将一个程序的输出发送到另一个程序进行进一步处理的控制操作符 + * `egrep` : 打印符合模式的行 + * `-c` : 通用输出控制 + * `'^-'` : 以“-”开头的行(`ls -l` 列出长列表时,行首的 “-” 代表普通文件) + +### 示例-2 + +统计当前目录包含隐藏文件在内的文件。 包括当前目录中的点文件。 + +``` +# ls -la . | egrep -c '^-' +5 +``` + +### 示例-3 + +运行以下命令来计数当前目录的文件和文件夹。 它会计算所有的文件和目录。 + +``` +# ls -l | wc -l +5 +``` + +**细节:** + + * `ls` : 列出目录内容 + * `-l` : 使用长列表格式 + * `|` : 将一个程序的输出发送到另一个程序进行进一步处理的控制操作符 + * `wc` : 这是一个统计每个文件的换行符、单词和字节数的命令 + * `-l` : 输出换行符的数量 + +### 示例-4 + +统计当前目录包含隐藏文件和目录在内的文件和文件夹。 + +``` +# ls -la | wc -l +8 +``` + +### 示例-5 + +递归计算当前目录的文件,包括隐藏文件。 + +``` +# find . -type f | wc -l +7 +``` + +**细节 :** + + * `find` : 搜索目录结构中的文件 + * `-type` : 文件类型 + * `f` : 常规文件 + * `wc` : 这是一个统计每个文件的换行符、单词和字节数的命令 + * `-l` : 输出换行符的数量 + +### 示例-6 + +使用 `tree` 命令输出目录和文件数(不包括隐藏文件)。 + +``` +# tree | tail -1 +2 directories, 5 files +``` + +### 示例-7 + +使用包含隐藏文件的 `tree` 命令输出目录和文件计数。 + +``` +# tree -a | tail -1 +2 directories, 7 files +``` + +### 示例-8 + +运行下面的命令递归计算包含隐藏目录在内的目录数。 + +``` +# find . -type d | wc -l +3 +``` + +### 示例-9 + +根据文件扩展名计数文件数量。 这里我们要计算 `.txt` 文件。 + +``` +# find . -name "*.txt" | wc -l +7 +``` + +### 示例-10 + +组合使用 `echo` 命令和 `wc` 命令统计当前目录中的所有文件。 `4` 表示当前目录中的文件数量。 + +``` +# echo *.* | wc +1 4 39 +``` + +### 示例-11 + +组合使用 `echo` 命令和 `wc` 命令来统计当前目录中的所有目录。 第二个 `1` 表示当前目录中的目录数量。 + +``` +# echo */ | wc +1 1 6 +``` + +### 示例-12 + +组合使用 `echo` 命令和 `wc` 命令来统计当前目录中的所有文件和目录。 `5` 表示当前目录中的目录和文件的数量。 + +``` +# echo * | wc +1 5 44 +``` + +### 示例-13 + +统计系统(整个系统)中的文件数。 + +``` +# find / -type f | wc -l +69769 +``` + +### 示例-14 + +统计系统(整个系统)中的文件夹数。 + +``` +# find / -type d | wc -l +8819 +``` + +### 示例-15 + +运行以下命令来计算系统(整个系统)中的文件、文件夹、硬链接和符号链接数。 + +``` +# find / -type d -exec echo dirs \; -o -type l -exec echo symlinks \; -o -type f -links +1 -exec echo hardlinks \; -o -type f -exec echo files \; | sort | uniq -c + 8779 dirs + 69343 files + 20 hardlinks + 11646 symlinks +``` + +-------------------------------------------------------------------------------- + +via: https://www.2daygeek.com/how-to-count-the-number-of-files-and-folders-directories-in-linux/ + +作者:[Magesh Maruthamuthu][a] +译者:[Flowsnow](https://github.com/Flowsnow) +校对:[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/empty-a-file-delete-contents-lines-from-a-file-remove-matching-string-from-a-file-remove-empty-blank-lines-from-a-file/ diff --git a/published/20171215 Linux Vs Unix.md b/published/20171215 Linux Vs Unix.md new file mode 100644 index 0000000000..953c14610d --- /dev/null +++ b/published/20171215 Linux Vs Unix.md @@ -0,0 +1,70 @@ +Linux 与 Unix 之差异 +============== + +[![Linux vs. Unix](http://www.linuxandubuntu.com/uploads/2/1/1/5/21152474/unix-vs-linux_orig.jpg)][1] + +在计算机时代,相当一部分的人错误地认为 **Unix** 和 **Linux** 操作系统是一样的。然而,事实恰好相反。让我们仔细看看。 + +### 什么是 Unix? + +[![what is unix](http://www.linuxandubuntu.com/uploads/2/1/1/5/21152474/unix_orig.png)][2] + +在 IT 领域,以操作系统而为人所知的 Unix,是 1969 年 AT&T 公司在美国新泽西所开发的(目前它的商标权由国际开放标准组织所拥有)。大多数的操作系统都受到了 Unix 的启发,而 Unix 也受到了未完成的 Multics 系统的启发。Unix 的另一版本是来自贝尔实验室的 Play 9。 + +#### Unix 被用于哪里? + +作为一个操作系统,Unix 大多被用在服务器、工作站,现在也有用在个人计算机上。它在创建互联网、计算机网络或客户端/服务器模型方面发挥着非常重要的作用。 + +#### Unix 系统的特点 + +* 支持多任务 +* 相比 Multics 操作更加简单 +* 所有数据以纯文本形式存储 +* 采用单一根文件的树状存储 +* 能够同时访问多用户账户 + +#### Unix 操作系统的组成 + +**a)** 单核操作系统,负责低级操作以及由用户发起的操作,内核之间的通信通过系统调用进行。 +**b)** 系统工具 +**c)** 其他应用程序 + +### 什么是 Linux? + +[![what is linux](http://www.linuxandubuntu.com/uploads/2/1/1/5/21152474/linux_orig.png)][4] + +这是一个基于 Unix 操作系统原理的开源操作系统。正如开源的含义一样,它是一个可以自由下载的系统。它也可以通过编辑、添加及扩充其源代码而定制该系统。这是它最大的好处之一,而不像今天的其它操作系统(Windows、Mac OS X 等)需要付费。Unix 系统不是创建新系统的唯一模版,另外一个重要的因素是 MINIX 系统,不像 Linus,此版本被其缔造者(Andrew Tanenbaum)用于商业系统。 + +Linux 由 Linus Torvalds 开发于 1991 年,这是一个其作为个人兴趣的操作系统。为什么 Linux 借鉴 Unix 的一个主要原因是因为其简洁性。Linux 第一个官方版本(0.01)发布于 1991 年 9 月 17 日。虽然这个系统并不是很完美和完善,但 Linus 对它产生很大的兴趣,并在几天内,Linus 发出了一些关于 Linux 源代码扩展以及其他想法的电子邮件。 + +#### Linux 的特点 + +Linux 的基石是 Unix 内核,其基于 Unix 的基本特点以及 **POSIX** 和单独的 **UNIX 规范标准**。看起来,该操作系统官方名字取自于 **Linus**,其中其操作系统名称的尾部的 “x” 和 **Unix 系统**相联系。 + +#### 主要功能 + +* 同时运行多任务(多任务) +* 程序可以包含一个或多个进程(多用途系统),且每个进程可能有一个或多个线程。 +* 多用户,因此它可以运行多个用户程序。 +* 个人帐户受适当授权的保护。 +* 因此账户准确地定义了系统控制权。 + +**企鹅 Tux** 的 Logo 作者是 Larry Ewing,他选择这个企鹅作为他的开源 **Linux 操作系统**的吉祥物。**Linux Torvalds** 最初提出这个新的操作系统的名字为 “Freax” ,即为 “自由(free)” + “奇异(freak)” + x(UNIX 系统)的结合字,而不像存放它的首个版本的 FTP 服务器上所起的名字(Linux)。 + + +-------------------------------------------------------------------------------- + +via: http://www.linuxandubuntu.com/home/linux-vs-unix + +作者:[linuxandubuntu][a] +译者:[HardworkFish](https://github.com/HardworkFish) +校对:[imquanquan](https://github.com/imquanquan), [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/linux-vs-unix +[2]:http://www.linuxandubuntu.com/uploads/2/1/1/5/21152474/unix_orig.png +[3]:http://www.unix.org/what_is_unix.html +[4]:http://www.linuxandubuntu.com/uploads/2/1/1/5/21152474/linux_orig.png +[5]:https://www.linux.com diff --git a/published/20171218 Internet Chemotherapy.md b/published/20171218 Internet Chemotherapy.md new file mode 100644 index 0000000000..faac86eceb --- /dev/null +++ b/published/20171218 Internet Chemotherapy.md @@ -0,0 +1,76 @@ +互联网化疗 +====== + +> LCTT 译注:本文作者 janit0r 被认为是 BrickerBot 病毒的作者。此病毒会攻击物联网上安全性不足的设备并使其断开和其他网络设备的连接。janit0r 宣称他使用这个病毒的目的是保护互联网的安全,避免这些设备被入侵者用于入侵网络上的其他设备。janit0r 称此项目为“互联网化疗”。janit0r 决定在 2017 年 12 月终止这个项目,并在网络上发表了这篇文章。 + +> —— 12/10 2017 + +### --[ 1 互联网化疗 + +互联网化疗Internet Chemotherapy是在 2016 年 11 月 到 2017 年 12 月之间的一个为期 13 个月的项目。它曾被称为 “BrickerBot”、“错误的固件升级”、“勒索软件”、“大规模网络瘫痪”,甚至 “前所未有的恐怖行为”。最后一个有点伤人了,费尔南德斯(LCTT 译注:委内瑞拉电信公司 CANTV 的光纤网络曾在 2017 年 8 月受到病毒攻击,公司董事长曼努埃尔·费尔南德斯称这次攻击为[“前所未有的恐怖行为”][1]),但我想我大概不能让所有人都满意吧。 + +你可以从 http://91.215.104.140/mod_plaintext.py 下载我的代码模块,它可以基于 http 和 telnet 发送恶意请求(LCTT 译注:这个链接已经失效,不过在 [Github][2] 上有备份)。因为平台的限制,模块里是代码混淆过的单线程 Python 代码,但载荷payload(LCTT 译注:payload,指实质的攻击/利用代码)依然是明文,任何合格的程序员应该都能看得懂。看看这里面有多少载荷、0-day 漏洞和入侵技巧,花点时间让自己接受现实。然后想象一下,如果我是一个黑客,致力于创造出强大的 DDoS 生成器来勒索那些最大的互联网服务提供商(ISP)和公司的话,互联网在 2017 年会受到怎样的打击。我完全可以让他们全部陷入混乱,并同时对整个互联网造成巨大的伤害。 + +我的 ssh 爬虫太危险了,不能发布出来。它包含很多层面的自动化,可以只利用一个被入侵的路由器就能够在设计有缺陷的 ISP 的网络上平行移动并加以入侵。正是因为我可以征用数以万计的 ISP 的路由器,而这些路由器让我知晓网络上发生的事情并给我提供源源不断的节点用来进行入侵行动,我才得以进行我的反物联网僵尸网络项目。我于 2015 年开始了我的非破坏性的 ISP 的网络清理项目,于是当 Mirai 病毒入侵时我已经做好了准备来做出回应。主动破坏其他人的设备仍然是一个困难的决定,但无比危险的 CVE-2016-10372 漏洞让我别无选择。从那时起我就决定一不做二不休。 + +(LCTT 译注:上一段中提到的 Mirai 病毒首次出现在 2016 年 8 月。它可以远程入侵运行 Linux 系统的网络设备并利用这些设备构建僵尸网络。本文作者 janit0r 宣称当 Mirai 入侵时他利用自己的 BrickerBot 病毒强制将数以万计的设备从网络上断开,从而减少 Mirai 病毒可以利用的设备数量。) + +我在此警告你们,我所做的只是权宜之计,它并不足以在未来继续拯救互联网。坏人们正变得更加聪明,潜在存在漏洞的设备数量在持续增加,发生大规模的、能使网络瘫痪的事件只是时间问题。如果你愿意相信,我曾经在一个持续 13 个月的项目中使上千万有漏洞的设备变得无法使用,那么不过分地说,如此严重的事件本已经在 2017 年发生了。 + +__你们应该意识到,只需要再有一两个严重的物联网漏洞,我们的网络就会严重瘫痪。__ 考虑到我们的社会现在是多么依赖数字网络,而计算机安全应急响应组(CERT)、ISP 们和政府们又是多么地忽视这种问题的严重性,这种事件造成的伤害是无法估计的。ISP 在持续地部署暴露了控制端口的设备,而且即使像 Shodan 这样的服务可以轻而易举地发现这些问题,国家 CERT 还是似乎并不在意。而很多国家甚至都没有自己的 CERT 。世界上许多最大的 ISP 都没有雇佣任何熟知计算机安全问题的人,而是在出现问题的时候依赖于外来的专家来解决。我曾见识过大型 ISP 在我的僵尸网络的调节之下连续多个月持续受损,但他们还是不能完全解决漏洞(几个好的例子是 BSNL、Telkom ZA、PLDT、某些时候的 PT Telkom,以及南半球大部分的大型 ISP )。只要看看 Telkom ZA 解决他们的 Aztech 调制解调器问题的速度有多慢,你就会开始理解现状有多么令人绝望。在 99% 的情况下,要解决这个问题只需要 ISP 部署合理的访问控制列表,并把部署在用户端的设备(CPE)单独分段就行,但是几个月过去之后他们的技术人员依然没有弄明白。如果 ISP 在经历了几周到几个月的针对他们设备的蓄意攻击之后仍然无法解决问题,我们又怎么能期望他们会注意到并解决 Mirai 在他们网络上造成的问题呢?世界上许多最大的 ISP 对这些事情无知得令人发指,而这毫无疑问是最大的危险,但奇怪的是,这应该也是最容易解决的问题。 + +我已经尽自己的责任试着去让互联网多坚持一段时间,但我已经尽力了。接下来要交给你们了。即使很小的行动也是非常重要的。你们能做的事情有: + +* 使用像 Shodan 之类的服务来检查你的 ISP 的安全性,并驱使他们去解决他们网络上开放的 telnet、http、httpd、ssh 和 tr069 等端口。如果需要的话,可以把这篇文章给他们看。从来不存在什么好的理由来让这些端口可以从外界访问。暴露控制端口是业余人士的错误。如果有足够的客户抱怨,他们也许真的会采取行动! +* 用你的钱包投票!拒绝购买或使用任何“智能”产品,除非制造商保证这个产品能够而且将会收到及时的安全更新。在把你辛苦赚的钱交给提供商之前,先去查看他们的安全记录。为了更好的安全性,可以多花一些钱。 +* 游说你本地的政治家和政府官员,让他们改进法案来规范物联网设备,包括路由器、IP 照相机和各种“智能”设备。不论私有还是公有的公司目前都没有足够的动机去在短期内解决该问题。这件事情和汽车或者通用电器的安全标准一样重要。 +* 考虑给像 GDI 基金会或者 Shadowserver 基金会这种缺少支持的白帽黑客组织贡献你的时间或者其他资源。这些组织和人能产生巨大的影响,并且他们可以很好地发挥你的能力来帮助互联网。 +* 最后,虽然希望不大,但可以考虑通过设立法律先例来让物联网设备成为一种“诱惑性危险品attractive nuisance”(LCTT 译注:attractive nuisance 是美国法律中的一个原则,意思是如果儿童在私人领地上因为某些对儿童有吸引力的危险物品而受伤,领地的主人需要负责,无论受伤的儿童是否是合法进入领地)。如果一个房主可以因为小偷或者侵入者受伤而被追责,我不清楚为什么设备的主人(或者 ISP 和设备制造商)不应该因为他们的危险的设备被远程入侵所造成的伤害而被追责。连带责任原则应该适用于对设备应用层的入侵。如果任何有钱的大型 ISP 不愿意为设立这样的先例而出钱(他们也许的确不会,因为他们害怕这样的先例会反过来让自己吃亏),我们甚至可以在这里还有在欧洲为这个行动而进行众筹。 ISP 们:把你们在用来应对 DDoS 的带宽上省下的可观的成本当做我为这个目标的间接投资,也当做它的好处的证明吧。 + +### --[ 2 时间线 + +下面是这个项目中一些值得纪念的事件: + +* 2016 年 11 月底的德国电信 Mirai 事故。我匆忙写出的最初的 TR069/64 请求只执行了 `route del default`,不过这已经足够引起 ISP 去注意这个问题,而它引发的新闻头条警告了全球的其他 ISP 来注意这个迫近的危机。 +* 大约 1 月 11 日 到 12 日,一些位于华盛顿特区的开放了 6789 控制端口的硬盘录像机被 Mirai 入侵并瘫痪,这上了很多头条新闻。我要给 Vemulapalli 点赞,她居然认为 Mirai 加上 `/dev/urandom` 一定是“非常复杂的勒索软件”(LCTT 译注:Archana Vemulapalli 当时是华盛顿市政府的 CTO)。欧洲的那两个可怜人又怎么样了呢? +* 2017 年 1 月底发生了第一起真正的大规模 ISP 下线事件。Rogers Canada 的提供商 Hitron 非常粗心地推送了一个在 2323 端口上监听的无验证的 root shell(这可能是一个他们忘记关闭的 debug 接口)。这个惊天的失误很快被 Mirai 的僵尸网络所发现,造成大量设备瘫痪。 +* 在 2017 年 2 月,我注意到 Mirai 在这一年里的第一次扩张,Netcore/Netis 以及 Broadcom 的基于 CLI (命令行接口)的调制解调器都遭受了攻击。BCM CLI 后来成为了 Mirai 在 2017 年的主要战场,黑客们和我自己都在这一年的余下时间里花大量时间寻找无数 ISP 和设备制造商设置的默认密码。前面代码中的“broadcom” 载荷也许看上去有点奇怪,但它们是统计角度上最可能禁用那些大量的有问题的 BCM CLI 固件的序列。 +* 在 2017 年 3 月,我大幅提升了我的僵尸网络的节点数量并开始加入更多的网络载荷。这是为了应对包括 Imeij、Amnesia 和 Persirai 在内的僵尸网络的威胁。大规模地禁用这些被入侵的设备也带来了新的一些问题。比如在 Avtech 和 Wificam 设备所泄露的登录信息当中,有一些用户名和密码非常像是用于机场和其他重要设施的,而英国政府官员大概在 2017 年 4 月 1 日关于针对机场和核设施的“实际存在的网络威胁”做出过警告。哎呀。 +* 这种更加激进的扫描还引起了民间安全研究者的注意,安全公司 Radware 在 2017 年 4 月 6 日发表了一篇关于我的项目的文章。这个公司把它叫做“BrickerBot”。显然,如果我要继续增加我的物联网防御措施的规模,我必须想出更好的网络映射与检测方法来应对蜜罐或者其他有风险的目标。 +* 2017 年 4 月 11 日左右的时候发生了一件非常不寻常的事情。一开始这看上去和许多其他的 ISP 下线事件相似,一个叫 Sierra Tel 的半本地 ISP 在一些 Zyxel 设备上使用了默认的 telnet 用户名密码 supervisor/zyad1234。一个 Mirai 运行器发现了这些有漏洞的设备,我的僵尸网络紧随其后,2017 年精彩绝伦的 BCM CLI 战争又开启了新的一场战斗。这场战斗并没有持续很久。它本来会和 2017 年的其他数百起 ISP 下线事件一样,如果不是在尘埃落定之后发生的那件非常不寻常的事情的话。令人惊奇的是,这家 ISP 并没有试着把这次网络中断掩盖成某种网络故障、电力超额或错误的固件升级。他们完全没有对客户说谎。相反,他们很快发表了新闻公告,说他们的调制解调器有漏洞,这让他们的客户们得以评估自己可能遭受的风险。这家全世界最诚实的 ISP 为他们值得赞扬的公开行为而收获了什么呢?悲哀的是,它得到的只是批评和不好的名声。这依然是我记忆中最令人沮丧的“为什么我们得不到好东西”的例子,这很有可能也是为什么 99% 的安全错误都被掩盖而真正的受害者被蒙在鼓里的最主要原因。太多时候,“有责任心的信息公开”会直接变成“粉饰太平”的委婉说法。 +* 在 2017 年 4 月 14 日,国土安全部关于“BrickerBot 对物联网的威胁”做出了警告,我自己的政府把我作为一个网络威胁这件事让我觉得他们很不公平而且目光短浅。跟我相比,对美国人民威胁最大的难道不应该是那些部署缺乏安全性的网络设备的提供商和贩卖不成熟的安全方案的物联网设备制造商吗?如果没有我,数以百万计的人们可能还在用被入侵的设备和网络来处理银行业务和其他需要保密的交易。如果国土安全部里有人读到这篇文章,我强烈建议你重新考虑一下保护国家和公民究竟是什么意思。 +* 在 2017 年 4 月底,我花了一些时间改进我的 TR069/64 攻击方法,然后在 2017 年 5 月初,一个叫 Wordfence 的公司(现在叫 Defiant)报道称一个曾给 Wordpress 网站造成威胁的基于入侵 TR069 的僵尸网络很明显地衰减了。值得注意的是,同一个僵尸网络在几星期后使用了一个不同的入侵方式暂时回归了(不过这最终也同样被化解了)。 +* 在 2017 年 5 月,主机托管公司 Akamai 在它的 2017 年第一季度互联网现状报告中写道,相比于 2016 年第一季度,大型(超过 100 Gbps)DDoS 攻击数减少了 89%,而总体 DDoS 攻击数减少了 30%。鉴于大型 DDoS 攻击是 Mirai 的主要手段,我觉得这给这些月来我在物联网领域的辛苦劳动提供了实际的支持。 +* 在夏天我持续地改进我的入侵技术军火库,然后在 7 月底我针对亚太互联网络信息中心(APNIC)的 ISP 进行了一些测试。测试结果非常令人吃惊。造成的影响之一是数十万的 BSNL 和 MTNL 调制解调器被禁用,而这次中断事故在印度成为了头条新闻。考虑到当时在印度和中国之间持续升级的地缘政治压力,我觉得这个事故有很大的风险会被归咎于中国所为,于是我很罕见地决定公开承认是我所做。Catalin,我很抱歉你在报道这条新闻之后突然被迫放的“两天的假期”。 +* 在处理过亚太互联网络信息中心(APNIC)和非洲互联网络信息中心(AfriNIC)的之后,在 2017 年 8 月 9 日我又针对拉丁美洲与加勒比地区互联网络信息中心(LACNIC)进行了大规模的清理,给这个大洲的许多提供商造成了问题。在数百万的 Movilnet 的手机用户失去连接之后,这次攻击在委内瑞拉被大幅报道。虽然我个人反对政府监管互联网,委内瑞拉的这次情况值得注意。许多拉美与加勒比地区的提供商与网络曾在我的僵尸网络的持续调节之下连续数个月逐渐衰弱,但委内瑞拉的提供商很快加强了他们的网络防护并确保了他们的网络设施的安全。我认为这是由于委内瑞拉相比于该地区的其他国家来说进行了更具侵入性的深度包检测。值得思考一下。 +* F5 实验室在 2017 年 8 月发布了一个题为“狩猎物联网:僵尸物联网的崛起”的报告,研究者们在其中对近期 telnet 活动的平静表达了困惑。研究者们猜测这种活动的减少也许证实了一个或多个非常大型的网络武器正在成型(我想这大概确实是真的)。这篇报告是在我印象中对我的项目的规模最准确的评估,但神奇的是,这些研究者们什么都推断不出来,尽管他们把所有相关的线索都集中到了一页纸上。 +* 2017 年 8 月,Akamai 的 2017 年第二季度互联网现状报告宣布这是三年以来首个该提供商没有发现任何大规模(超过 100 Gbps)攻击的季度,而且 DDoS 攻击总数相比 2017 年第一季度减少了 28%。这看上去给我的清理工作提供了更多的支持。这个出奇的好消息被主流媒体所完全忽视了,这些媒体有着“流血的才是好新闻”的心态,即使是在信息安全领域。这是我们为什么不能得到好东西的又一个原因。 +* 在 CVE-2017-7921 和 7923 于 2017 年 9 月公布之后,我决定更密切地关注海康威视公司的设备,然后我惊恐地发现有一个黑客们还没有发现的方法可以用来入侵有漏洞的固件。于是我在 9 月中旬开启了一个全球范围的清理行动。超过一百万台硬盘录像机和摄像机(主要是海康威视和大华出品)在三周内被禁用,然后包括 IPVM.com 在内的媒体为这些攻击写了多篇报道。大华和海康威视在新闻公告中提到或暗示了这些攻击。大量的设备总算得到了固件升级。看到这次清理活动造成的困惑,我决定给这些闭路电视制造商写一篇[简短的总结][3](请原谅在这个粘贴板网站上的不和谐的语言)。这令人震惊的有漏洞而且在关键的安全补丁发布之后仍然在线的设备数量应该能够唤醒所有人,让他们知道现今的物联网补丁升级过程有多么无力。 +* 2017 年 9 月 28 日左右,Verisign 发表了报告称 2017 年第二季度的 DDoS 攻击数相比第一季度减少了 55%,而且攻击峰值大幅减少了 81%。 +* 2017 年 11 月 23 日,CDN 供应商 Cloudflare 报道称“近几个月来,Cloudflare 看到试图用垃圾流量挤满我们的网络的简单进攻尝试有了大幅减少”。Cloudflare 推测这可能和他们的政策变化有一定关系,但这些减少也和物联网清理行动有着明显的重合。 +* 2017 年 11 月底,Akamai 的 2017 年第三季度互联网现状报告称 DDoS 攻击数较前一季度小幅增加了 8%。虽然这相比 2016 年的第三季度已经减少了很多,但这次小幅上涨提醒我们危险仍然存在。 +* 作为潜在危险的更进一步的提醒,一个叫做“Satori”的新的 Mirai 变种于 2017 年 11 月至 12 月开始冒头。这个僵尸网络仅仅通过一个 0-day 漏洞而达成的增长速度非常值得注意。这起事件凸显了互联网的危险现状,以及我们为什么距离大规模的事故只差一两起物联网入侵。当下一次威胁发生而且没人阻止的时候,会发生什么?Sinkholing 和其他的白帽或“合法”的缓解措施在 2018 年不会有效,就像它们在 2016 年也不曾有效一样。也许未来各国政府可以合作创建一个国际范围的反黑客特别部队来应对特别严重的会影响互联网存续的威胁,但我并不抱太大期望。 +* 在年末出现了一些危言耸听的新闻报道,有关被一个被称作“Reaper”和“IoTroop”的新的僵尸网络。我知道你们中有些人最终会去嘲笑那些把它的规模估算为一两百万的人,但你们应该理解这些网络安全研究者们对网络上发生的事情以及不由他们掌控的硬件的事情都是一知半解。实际来说,研究者们不可能知道或甚至猜测到大部分有漏洞的设备在僵尸网络出现时已经被禁用了。给“Reaper”一两个新的未经处理的 0-day 漏洞的话,它就会变得和我们最担心的事情一样可怕。 + +### --[ 3 临别赠言 + +我很抱歉把你们留在这种境况当中,但我的人身安全受到的威胁已经不允许我再继续下去。我树了很多敌人。如果你想要帮忙,请看前面列举的该做的事情。祝你好运。 + +也会有人批评我,说我不负责任,但这完全找错了重点。真正的重点是如果一个像我一样没有黑客背景的人可以做到我所做到的事情,那么一个比我厉害的人可以在 2017 年对互联网做比这要可怕太多的事情。我并不是问题本身,我也不是来遵循任何人制定的规则的。我只是报信的人。你越早意识到这点越好。 + +-Dr Cyborkian 又名 janit0r,“病入膏肓”的设备的调节者。 + +-------------------------------------------------------------------------------- + +via:https://ghostbin.com/paste/q2vq2 + +作者:janit0r +译者:[yixunx](https://github.com/yixunx) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译, +[Linux中国](https://linux.cn/) 荣誉推出 + +[1]:https://www.telecompaper.com/news/venezuelan-operators-hit-by-unprecedented-cyberattack--1208384 +[2]:https://github.com/JeremyNGalloway/mod_plaintext.py +[3]:http://depastedihrn3jtw.onion.link/show.php?md5=62d1d87f67a8bf485d43a05ec32b1e6f \ No newline at end of file diff --git a/published/20090127 Anatomy of a Program in Memory.md b/published/201801/20090127 Anatomy of a Program in Memory.md similarity index 100% rename from published/20090127 Anatomy of a Program in Memory.md rename to published/201801/20090127 Anatomy of a Program in Memory.md diff --git a/published/20090718 Vmware Linux Guest Add a New Hard Disk Without Rebooting Guest.md b/published/201801/20090718 Vmware Linux Guest Add a New Hard Disk Without Rebooting Guest.md similarity index 100% rename from published/20090718 Vmware Linux Guest Add a New Hard Disk Without Rebooting Guest.md rename to published/201801/20090718 Vmware Linux Guest Add a New Hard Disk Without Rebooting Guest.md diff --git a/published/201801/20111124 How to find hidden processes and ports on Linux-Unix-Windows.md b/published/201801/20111124 How to find hidden processes and ports on Linux-Unix-Windows.md new file mode 100644 index 0000000000..4bdf16485c --- /dev/null +++ b/published/201801/20111124 How to find hidden processes and ports on Linux-Unix-Windows.md @@ -0,0 +1,243 @@ +如何在 Linux/Unix/Windows 中发现隐藏的进程和端口 +============== + +`unhide` 是一个小巧的网络取证工具,能够发现那些借助 rootkit、LKM 及其它技术隐藏的进程和 TCP/UDP 端口。这个工具在 Linux、UNIX 类、MS-Windows 等操作系统下都可以工作。根据其 man 页面的说明: + +> Unhide 通过下述三项技术来发现隐藏的进程。 +> 1. 进程相关的技术,包括将 `/proc` 目录与 [/bin/ps][1] 命令的输出进行比较。 +> 2. 系统相关的技术,包括将 [/bin/ps][1] 命令的输出结果同从系统调用方面得到的信息进行比较。 +> 3. 穷举法相关的技术,包括对所有的进程 ID 进行暴力求解,该技术仅限于在基于 Linux2.6 内核的系统中使用。 + +绝大多数的 Rootkit 工具或者恶意软件借助内核来实现进程隐藏,这些进程只在内核内部可见。你可以使用 `unhide` 或者诸如 [rkhunter 等工具,扫描 rootkit 程序 、后门程序以及一些可能存在的本地漏洞][2]。 + +![本文讲解如何在多个操作系统下安装和使用unhide][3] + +这篇文章描述了如何安装 unhide 并搜索隐藏的进程和 TCP/UDP 端口。 + +### 如何安装 unhide + +首先建议你在只读介质上运行这个工具。如果使用的是 Ubuntu 或者 Debian 发行版,输入下述的 [apt-get][4]/[apt][5] 命令以安装 Unhide: + +``` +$ sudo apt-get install unhide +``` + +一切顺利的话你的命令行会输出以下内容: + +``` +[sudo] password for vivek: +Reading package lists... Done +Building dependency tree +Reading state information... Done +Suggested packages: + rkhunter +The following NEW packages will be installed: + unhide +0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded. +Need to get 46.6 kB of archives. +After this operation, 136 kB of additional disk space will be used. +Get:1 http://in.archive.ubuntu.com/ubuntu artful/universe amd64 unhide amd64 20130526-1 [46.6 kB] +Fetched 46.6 kB in 0s (49.0 kB/s) +Selecting previously unselected package unhide. +(Reading database ... 205367 files and directories currently installed.) +Preparing to unpack .../unhide_20130526-1_amd64.deb ... +Unpacking unhide (20130526-1) ... +Setting up unhide (20130526-1) ... +Processing triggers for man-db (2.7.6.1-2) ... +``` + +### 如何在 RHEL/CentOS/Oracle/Scientific/Fedora 上安装 unhide + +输入下列 yum Type the following yum command (first turn on EPLE repo on a CentOS/RHEL version 6.x or version 7.x): + +输入以下的 [yum][6] 命令(CentOS/RHEL [6.x][7] 或 [7.x][8] 上首先打开 EPEL 仓库): + +``` +$ sudo yum install unhide +``` + +在 Fedora 上则使用以下 dnf 命令: + +``` +$ sudo dnf install unhide +``` + +### 如何在 Arch 上安装 unhide + +键入以下 pacman 命令安装: + +``` +$ sudo pacman -S unhide +``` + +### 如何在 FreeBSD 上安装 unhide + +可以通过以下的命令使用 port 来安装 unhide: + +``` +# cd /usr/ports/security/unhide/ +# make install clean +``` + +或者可以通过二进制文件安装 hide,使用 pkg 命令安装: + +``` +# pkg install unhide +``` + +### 如何使用 unhide 工具? + +unhide 的语法是: + +``` +unhide [options] test_list +``` + +`test_list` 参数可以是以下测试列表中的一个或者多个标准测试: + + +1. brute +2. proc +3. procall +4. procfs +5. quick +6. reverse +7. sys + +或基本测试: + +1. checkbrute +2. checkchdir +3. checkgetaffinity +4. checkgetparam +5. checkgetpgid +6. checkgetprio +7. checkRRgetinterval +8. checkgetsched +9. checkgetsid +10. checkkill +11. checknoprocps +12. checkopendir +13. checkproc +14. checkquick +15. checkreaddir +16. checkreverse +17. checksysinfo +18. checksysinfo2 +19. checksysinfo3 + +你可以通过以下示例命令使用 `unhide`: + +``` +# unhide proc +# unhide sys +# unhide quick +``` + +示例输出: + +``` +Unhide 20130526 +Copyright © 2013 Yago Jesus & Patrick Gouin +License GPLv3+ : GNU GPL version 3 or later +http://www.unhide-forensics.info + +NOTE : This version of unhide is for systems using Linux >= 2.6 + +Used options: +[*]Searching for Hidden processes through comparison of results of system calls, proc, dir and ps +``` + +### 如何使用 unhide-tcp 工具辨明 TCP/UDP 端口的身份 + +以下是来自 man 页面的介绍: + +> `unhide-tcp` 取证工具通过对所有可用的 TCP/IP 端口进行暴力求解的方式,辨别所有正在监听,却没有列入 [/bin/netstat][9] 或者 [/bin/ss][10] 命令输出的 TCP/IP 端口身份。 + +> 注一:对于 FreeBSD、OpenBSD系统,一般使用 netstat 命令取代在这些操作系统上不存在的 iproute2,此外,sockstat 命令也用于替代 fuser。 + +> 注二:如果操作系统不支持 iproute2 命令,在使用 `unhide` 时需要在命令上加上 `-n` 或者 `-s` 选项。 + +``` +# unhide-tcp +``` + +示例输出: + +``` +Unhide 20100201 +http://www.security-projects.com/?Unhide + +Starting TCP checking + +Starting UDP checking +``` + +上述操作中,没有发现隐藏的端口。 + +但在下述示例中,我展示了一些有趣的事。 + +``` +# unhide-tcp +``` + +示例输出: + +``` +Unhide 20100201 +http://www.security-projects.com/?Unhide + + +Starting TCP checking + +Found Hidden port that not appears in netstat: 1048 +Found Hidden port that not appears in netstat: 1049 +Found Hidden port that not appears in netstat: 1050 +Starting UDP checking +``` + +可以看到 `netstat -tulpn` 和 `ss` 命令确实没有反映出这三个隐藏的端口: + +``` +# netstat -tulpn | grep 1048 +# ss -lp +# ss -l | grep 1048 +``` + +通过下述的 man 命令可以更多地了解 `unhide`: + +``` +$ man unhide +$ man unhide-tcp +``` + +### Windows 用户如何安装使用 unhide + +你可以通过这个[页面][13]获取 Windows 版本的 unhide。 + +---- + +via: https://www.cyberciti.biz/tips/linux-unix-windows-find-hidden-processes-tcp-udp-ports.html + +作者:[Vivek Gite][a] +译者:[ljgibbslf](https://github.com/ljgibbslf) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.cyberciti.biz +[1]:https://www.cyberciti.biz/faq/show-all-running-processes-in-linux/ (Linux / Unix ps command) +[2]:https://www.cyberciti.biz/faq/howto-check-linux-rootkist-with-detectors-software/ +[3]:https://www.cyberciti.biz/tips/wp-content/uploads/2011/11/Linux-FreeBSD-Unix-Windows-Find-Hidden-Process-Ports.jpg +[4]:https://www.cyberciti.biz/tips/linux-debian-package-management-cheat-sheet.html (See Linux/Unix apt-get command examples for more info) +[5]://www.cyberciti.biz/faq/ubuntu-lts-debian-linux-apt-command-examples/ (See Linux/Unix apt command examples for more info) +[6]:https://www.cyberciti.biz/faq/rhel-centos-fedora-linux-yum-command-howto/ (See Linux/Unix yum command examples for more info) +[7]:https://www.cyberciti.biz/faq/fedora-sl-centos-redhat6-enable-epel-repo/ +[8]:https://www.cyberciti.biz/faq/installing-rhel-epel-repo-on-centos-redhat-7-x/ +[9]:https://www.cyberciti.biz/tips/linux-display-open-ports-owner.html (Linux netstat command) +[10]:https://www.cyberciti.biz/tips/linux-investigate-sockets-network-connections.html +[11]:https://www.cyberciti.biz/tips/netstat-command-tutorial-examples.html +[12]:https://www.cyberciti.biz/tips/linux-investigate-sockets-network-connections.html +[13]:http://www.unhide-forensics.info/?Windows:Download diff --git a/published/20120611 30 Handy Bash Shell Aliases For Linux - Unix - Mac OS X.md b/published/201801/20120611 30 Handy Bash Shell Aliases For Linux - Unix - Mac OS X.md similarity index 100% rename from published/20120611 30 Handy Bash Shell Aliases For Linux - Unix - Mac OS X.md rename to published/201801/20120611 30 Handy Bash Shell Aliases For Linux - Unix - Mac OS X.md diff --git a/translated/tech/20121211 Python Nmon Analyzer- moving away from excel macros.md b/published/201801/20121211 Python Nmon Analyzer- moving away from excel macros.md similarity index 51% rename from translated/tech/20121211 Python Nmon Analyzer- moving away from excel macros.md rename to published/201801/20121211 Python Nmon Analyzer- moving away from excel macros.md index c772ceff73..351c9c1f75 100644 --- a/translated/tech/20121211 Python Nmon Analyzer- moving away from excel macros.md +++ b/published/201801/20121211 Python Nmon Analyzer- moving away from excel macros.md @@ -1,36 +1,40 @@ Python 版的 Nmon 分析器:让你远离 excel 宏 ====== -[Nigel's monitor][1],也叫做 "Nmon",是一个很好的监控,记录和分析 Linux/*nix 系统性能随时间变化的工具。Nmon 最初由 IBM 开发并于 2009 年夏天开源。时至今日 Nmon 已经在所有 linux 平台和架构上都可用了。它提供了大量的实时工具来可视化当前系统统计信息,这些统计信息包括 CPU,RAM,网络和磁盘 I/O。然而,Nmon 最棒的特性是可以随着时间的推移记录系统性能快照。 -比如:`nmon -f -s 1`。 -![nmon CPU and Disk utilization][2] -会创建一个日志文件,该日志文件最开头是一些系统的元数据 T( 章节 AAA - BBBV),后面是定时抓取的监控系统属性的快照,比如 CPU 和内存的使用情况。这个文件很难直接由电子表格应用来处理,因此诞生了 [Nmon_Analyzer][3] excel 宏。如果你用的是 Windows/Mac 并安装了 Microsoft Office,那么这个工具非常不错。如果没有这个环境那也可以使用 Nmon2rrd 工具,这个工具能将日志文件转换 RRD 输入文件,进而生成图形。这个过程很死板而且有点麻烦。现在出现了一个更灵活的工具,像你们介绍一下 pyNmonAnalyzer,它一个可定制化的解决方案来生成结构化的 CSV 文件和基于 [matplotlib][4] 生成图片的简单 HTML 报告。 -### 入门介绍: +[Nigel's monitor][1],也叫做 “Nmon”,是一个很好的监控、记录和分析 Linux/*nix 系统性能随时间变化的工具。Nmon 最初由 IBM 开发并于 2009 年夏天开源。时至今日 Nmon 已经在所有 Linux 平台和架构上都可用了。它提供了很棒的当前系统统计信息的基于命令行的实时可视化报告,这些统计信息包括 CPU、RAM、网络和磁盘 I/O。然而,Nmon 最棒的特性是可以随着时间的推移记录系统性能快照。 + +比如:`nmon -f -s 1`。 + +![nmon CPU and Disk utilization][2] + +会创建一个日志文件,该日志文件最开头是一些系统的元数据(AAA - BBBV 部分),后面是所监控的系统属性的定时快照,比如 CPU 和内存的使用情况。这个输出的文件很难直接由电子表格应用来处理,因此诞生了 [Nmon_Analyzer][3] excel 宏。如果你用的是 Windows/Mac 并安装了 Microsoft Office,那么这个工具非常不错。如果没有这个环境那也可以使用 Nmon2rrd 工具,这个工具能将日志文件转换 RRD 输入文件,进而生成图形。这个过程很死板而且有点麻烦。现在出现了一个更灵活的工具,我向你们介绍一下 pyNmonAnalyzer,它提供了一个可定制化的解决方案来生成结构化的 CSV 文件和带有用 [matplotlib][4] 生成的图片的简单 HTML 报告。 + +### 入门介绍 系统需求: + 从名字中就能看出我们需要有 python。此外 pyNmonAnalyzer 还依赖于 matplotlib 和 numpy。若你使用的是 debian 衍生的系统,则你需要先安装这些包: -``` -$> sudo apt-get install python-numpy python-matplotlib ``` - -##### 获取 pyNmonAnalyzer: - -你可页克隆 git 仓库: -``` -$> git clone git@github.com:madmaze/pyNmonAnalyzer.git - +$ sudo apt-get install python-numpy python-matplotlib ``` -或者 +#### 获取 pyNmonAnalyzer: -直接从这里下载:[pyNmonAnalyzer-0.1.zip][5] +你可以克隆 git 仓库: -接下来我们需要一个 Nmon 文件,如果没有的话,可以使用发行版中提供的实例或者自己录制一个样本:`nmon -F test.nmon -s 1 -c 120`,会录制每个 1 秒录制一次,供录制 120 个快照道 test.nmon 文件中 .nmon。 +``` +$ git clone git@github.com:madmaze/pyNmonAnalyzer.git +``` + +或者,直接从这里下载:[pyNmonAnalyzer-0.1.zip][5] 。 + +接下来我们需要一个 Nmon 文件,如果没有的话,可以使用发行版中提供的实例或者自己录制一个样本:`nmon -F test.nmon -s 1 -c 120`,会录制 120 个快照,每秒一个,存储到 test.nmon 文件中。 让我们来看看基本的帮助信息: + ``` -$> ./pyNmonAnalyzer.py -h +$ ./pyNmonAnalyzer.py -h usage: pyNmonAnalyzer.py [-h] [-x] [-d] [-o OUTDIR] [-c] [-b] [-r CONFFNAME] input_file @@ -53,30 +57,29 @@ optional arguments: -r CONFFNAME, --reportConfig CONFFNAME Report config file, if none exists: we will write the default config file out (Default: ./report.config) - ``` 该工具有两个主要的选项 - 1。将 nmon 文件传唤成一系列独立的 CSV 文件 - 2。使用 matplotlib 生成带图形的 HTML 报告 - +1. 将 nmon 文件传唤成一系列独立的 CSV 文件 +2. 使用 matplotlib 生成带图形的 HTML 报告 下面命令既会生成 CSV 文件,也会生成 HTML 报告: -``` -$> ./pyNmonAnalyzer.py -c -b test.nmon +``` +$ ./pyNmonAnalyzer.py -c -b test.nmon ``` -这会常见一个 `。/data` 目录,其中有一个存放 CSV 文件的目录 ("。/data/csv/"),一个存放 PNG 图片的目录 ("。/data/img/") 以及一个 HTML 报告 ("。/data/report.html")。 +这会创建一个 `./data` 目录,其中有一个存放 CSV 文件的目录 (`./data/csv/`),一个存放 PNG 图片的目录 (`./data/img/`) 以及一个 HTML 报告 (`./data/report.html`)。 -默认情况下,HTML 报告中会用图片展示 CPU,磁盘繁忙度,内存使用情况和网络传输情况。所有这些都定义在一个自解释的配置文件中 ("report.config")。目前这个工具 h 那不是特别的灵活,因为 CPU 和 MEM 除了 on 和 off 外,无法做其他的配置。不过下一步将会改进作图的方法并允许用户灵活地指定针对哪些数据使用哪种作图方法。 +默认情况下,HTML 报告中会用图片展示 CPU、磁盘繁忙程度、内存使用情况和网络传输情况。所有这些都定义在一个不言自明的配置文件中 (`report.config`)。目前这个工具还不是特别的灵活,因为 CPU 和 MEM 除了 `on` 和 `off` 外,无法做其他的配置。不过下一步将会改进作图的方法并允许用户灵活地指定针对哪些数据使用哪种作图方法。 -### 报告的例子: +### 报告的例子 -[![pyNmonAnalyzer Graph output][6] -**Click to see the full Report**][7] +![pyNmonAnalyzer Graph output][6] + +[点击查看完整报告][7] 目前这些报告还十分的枯燥而且只能打印出基本的几种标记图表,不过它的功能还在不断的完善中。目前在开发的是一个向导来让配置调整变得更容易。如果有任何建议,找到任何 bug 或者有任何功能需求,欢迎与我交流。 @@ -86,7 +89,7 @@ via: https://matthiaslee.com/python-nmon-analyzer-moving-away-from-excel-macros/ 作者:[Matthias Lee][a] 译者:[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/20140210 Three steps to learning GDB.md b/published/201801/20140210 Three steps to learning GDB.md similarity index 100% rename from published/20140210 Three steps to learning GDB.md rename to published/201801/20140210 Three steps to learning GDB.md diff --git a/published/20160117 How to use curl command with proxy username-password on Linux- Unix.md b/published/201801/20160117 How to use curl command with proxy username-password on Linux- Unix.md similarity index 100% rename from published/20160117 How to use curl command with proxy username-password on Linux- Unix.md rename to published/201801/20160117 How to use curl command with proxy username-password on Linux- Unix.md diff --git a/published/20160625 Trying out LXD containers on our Ubuntu.md b/published/201801/20160625 Trying out LXD containers on our Ubuntu.md similarity index 100% rename from published/20160625 Trying out LXD containers on our Ubuntu.md rename to published/201801/20160625 Trying out LXD containers on our Ubuntu.md diff --git a/published/20160808 Top 10 Command Line Games For Linux.md b/published/201801/20160808 Top 10 Command Line Games For Linux.md similarity index 100% rename from published/20160808 Top 10 Command Line Games For Linux.md rename to published/201801/20160808 Top 10 Command Line Games For Linux.md diff --git a/published/20161004 What happens when you start a process on Linux.md b/published/201801/20161004 What happens when you start a process on Linux.md similarity index 100% rename from published/20161004 What happens when you start a process on Linux.md rename to published/201801/20161004 What happens when you start a process on Linux.md diff --git a/published/20170131 Book review Ours to Hack and to Own.md b/published/201801/20170131 Book review Ours to Hack and to Own.md similarity index 100% rename from published/20170131 Book review Ours to Hack and to Own.md rename to published/201801/20170131 Book review Ours to Hack and to Own.md diff --git a/published/20170209 INTRODUCING DOCKER SECRETS MANAGEMENT.md b/published/201801/20170209 INTRODUCING DOCKER SECRETS MANAGEMENT.md similarity index 100% rename from published/20170209 INTRODUCING DOCKER SECRETS MANAGEMENT.md rename to published/201801/20170209 INTRODUCING DOCKER SECRETS MANAGEMENT.md diff --git a/published/20170319 ftrace trace your kernel functions.md b/published/201801/20170319 ftrace trace your kernel functions.md similarity index 100% rename from published/20170319 ftrace trace your kernel functions.md rename to published/201801/20170319 ftrace trace your kernel functions.md diff --git a/published/20170426 Important Docker commands for Beginners.md b/published/201801/20170426 Important Docker commands for Beginners.md similarity index 100% rename from published/20170426 Important Docker commands for Beginners.md rename to published/201801/20170426 Important Docker commands for Beginners.md diff --git a/published/20170502 A beginner-s guide to Raspberry Pi 3.md b/published/201801/20170502 A beginner-s guide to Raspberry Pi 3.md similarity index 100% rename from published/20170502 A beginner-s guide to Raspberry Pi 3.md rename to published/201801/20170502 A beginner-s guide to Raspberry Pi 3.md diff --git a/published/20170512 Which Official Ubuntu Flavor Is Best for You.md b/published/201801/20170512 Which Official Ubuntu Flavor Is Best for You.md similarity index 100% rename from published/20170512 Which Official Ubuntu Flavor Is Best for You.md rename to published/201801/20170512 Which Official Ubuntu Flavor Is Best for You.md diff --git a/published/20170515 Commands to check System & Hardware Information.md b/published/201801/20170515 Commands to check System & Hardware Information.md similarity index 100% rename from published/20170515 Commands to check System & Hardware Information.md rename to published/201801/20170515 Commands to check System & Hardware Information.md diff --git a/published/20170524 View Counting at Reddit.md b/published/201801/20170524 View Counting at Reddit.md similarity index 100% rename from published/20170524 View Counting at Reddit.md rename to published/201801/20170524 View Counting at Reddit.md diff --git a/published/20170524 Working with Vi-Vim Editor - Advanced concepts.md b/published/201801/20170524 Working with Vi-Vim Editor - Advanced concepts.md similarity index 100% rename from published/20170524 Working with Vi-Vim Editor - Advanced concepts.md rename to published/201801/20170524 Working with Vi-Vim Editor - Advanced concepts.md diff --git a/translated/tech/20170526 Creating a YUM repository from ISO - Online repo.md b/published/201801/20170526 Creating a YUM repository from ISO - Online repo.md similarity index 56% rename from translated/tech/20170526 Creating a YUM repository from ISO - Online repo.md rename to published/201801/20170526 Creating a YUM repository from ISO - Online repo.md index a483766ddf..2e11780ac4 100644 --- a/translated/tech/20170526 Creating a YUM repository from ISO - Online repo.md +++ b/published/201801/20170526 Creating a YUM repository from ISO - Online repo.md @@ -1,18 +1,18 @@ -从 ISO 和在线仓库创建一个 YUM 仓库 +从 ISO 和在线仓库创建一个 Yum 仓库 ====== -YUM 是 Centos/RHEL/Fedora 中最重要的工具之一。尽管在 Fedora 的最新版本中,它已经被 DNF 所取代,但这并不意味着它已经成功了。它仍然被广泛用于安装 rpm 包,我们已经在前面的教程([**在这里阅读**] [1])中用示例讨论了 YUM。 +Yum 是 Centos/RHEL/Fedora 中最重要的工具之一。尽管在 Fedora 的最新版本中,它已经被 DNF 所取代,但这并不意味着它自生自灭了。它仍然被广泛用于安装 rpm 包,我们已经在前面的教程([**在这里阅读**] [1])中用示例讨论了 Yum。 -在本教程中,我们将学习创建一个本地 YUM 仓库,首先使用系统的 ISO 镜像,然后创建一个在线 yum 仓库的镜像。 +在本教程中,我们将学习创建一个本地 Yum 仓库,首先使用系统的 ISO 镜像,然后创建一个在线 Yum 仓库的镜像。 -### 用 DVD ISO 创建 YUM +### 用 DVD ISO 创建 Yum 我们在本教程中使用 Centos 7 dvd,同样的过程也应该可以用在 RHEL 7 上。 -首先在根文件夹中创建一个名为 YUM 的目录 +首先在根文件夹中创建一个名为 Yum 的目录 ``` -$ mkdir /YUM- +$ mkdir /YUM ``` 然后挂载 Centos 7 ISO: @@ -21,7 +21,7 @@ $ mkdir /YUM- $ mount -t iso9660 -o loop /home/dan/Centos-7-x86_x64-DVD.iso /mnt/iso/ ``` -接下来,从挂载的 ISO 中复制软件包到 /YUM 中。当所有的软件包都被复制到系统中后,我们将安装创建 YUM 所需的软件包。打开 /YUM 并安装以下 RPM 包: +接下来,从挂载的 ISO 中复制软件包到 `/YUM` 中。当所有的软件包都被复制到系统中后,我们将安装创建 Yum 所需的软件包。打开 `/YUM` 并安装以下 RPM 包: ``` $ rpm -ivh deltarpm @@ -29,7 +29,7 @@ $ rpm -ivh python-deltarpm $ rpm -ivh createrepo ``` -安装完成后,我们将在 **/etc/yum.repos.d** 中创建一个名 为 **“local.repo”** 的文件,其中包含所有的 yum 信息。 +安装完成后,我们将在 `/etc/yum.repos.d` 中创建一个名 为 `local.repo` 的文件,其中包含所有的 Yum 信息。 ``` $ vi /etc/yum.repos.d/local.repo @@ -49,28 +49,28 @@ enabled=1 $ createrepo -v /YUM ``` -创建仓库数据需要一些时间。一切完成后,请运行 +创建仓库数据需要一些时间。一切完成后,请运行: ``` $ yum clean all ``` -清理缓存,然后运行 +清理缓存,然后运行: ``` $ yum repolist ``` -检查所有仓库列表。你应该在列表中看到 “local.repo”。 +检查所有仓库列表。你应该在列表中看到 `local.repo`。 -### 使用在线仓库创建镜像 YUM 仓库 +### 使用在线仓库创建镜像 Yum 仓库 -创建在线 yum 的过程与使用 ISO 镜像创建 yum 类似,只是我们将从在线仓库而不是 ISO 中获取 rpm 软件包。 +创建在线 Yum 的过程与使用 ISO 镜像创建 Yum 类似,只是我们将从在线仓库而不是 ISO 中获取 rpm 软件包。 -首先,我们需要找到一个在线仓库来获取最新的软件包。建议你找一个离你位置最近的在线 yum 仓库,以优化下载速度。我们将使用下面的镜像,你可以从[ CENTOS 镜像列表][2]中选择一个离你最近的镜像。 +首先,我们需要找到一个在线仓库来获取最新的软件包。建议你找一个离你位置最近的在线 Yum 仓库,以优化下载速度。我们将使用下面的镜像,你可以从 [CENTOS 镜像列表][2]中选择一个离你最近的镜像。 -选择镜像之后,我们将使用 rsync 将该镜像与我们的系统同步,但在此之前,请确保你服务器上有足够的空间。 +选择镜像之后,我们将使用 `rsync` 将该镜像与我们的系统同步,但在此之前,请确保你服务器上有足够的空间。 ``` $ rsync -avz rsync://mirror.fibergrid.in/centos/7.2/os/x86_64/Packages/s/ /YUM @@ -96,9 +96,9 @@ $ crontab -e 30 12 * * * rsync -avz http://mirror.centos.org/centos/7/os/x86_64/Packages/ /YUM ``` -这会在每晚 12:30 同步 yum。还请记住在 /etc/yum.repos.d 中创建仓库配置文件,就像我们上面所做的一样。 +这会在每晚 12:30 同步 Yum。还请记住在 `/etc/yum.repos.d` 中创建仓库配置文件,就像我们上面所做的一样。 -就是这样,你现在有你自己的 yum 仓库来使用。如果你喜欢它,请分享这篇文章,并在下面的评论栏留下你的意见/疑问。 +就是这样,你现在使用你自己的 Yum 仓库了。如果你喜欢它,请分享这篇文章,并在下面的评论栏留下你的意见/疑问。 -------------------------------------------------------------------------------- @@ -107,7 +107,7 @@ via: http://linuxtechlab.com/creating-yum-repository-iso-online-repo/ 作者:[Shusain][a] 译者:[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/20170607 Why Car Companies Are Hiring Computer Security Experts.md b/published/201801/20170607 Why Car Companies Are Hiring Computer Security Experts.md similarity index 100% rename from published/20170607 Why Car Companies Are Hiring Computer Security Experts.md rename to published/201801/20170607 Why Car Companies Are Hiring Computer Security Experts.md diff --git a/published/20170802 Creating SWAP partition using FDISK - FALLOCATE commands.md b/published/201801/20170802 Creating SWAP partition using FDISK - FALLOCATE commands.md similarity index 100% rename from published/20170802 Creating SWAP partition using FDISK - FALLOCATE commands.md rename to published/201801/20170802 Creating SWAP partition using FDISK - FALLOCATE commands.md diff --git a/published/20170804 Add speech to your Fedora system.md b/published/201801/20170804 Add speech to your Fedora system.md similarity index 100% rename from published/20170804 Add speech to your Fedora system.md rename to published/201801/20170804 Add speech to your Fedora system.md diff --git a/published/20170820 How To Display Date And Time In History Command.md b/published/201801/20170820 How To Display Date And Time In History Command.md similarity index 100% rename from published/20170820 How To Display Date And Time In History Command.md rename to published/201801/20170820 How To Display Date And Time In History Command.md diff --git a/published/20170828 How To Use YUM History Command To Rollback An Updates In RHEL-CentOS Systems.md b/published/201801/20170828 How To Use YUM History Command To Rollback An Updates In RHEL-CentOS Systems.md similarity index 100% rename from published/20170828 How To Use YUM History Command To Rollback An Updates In RHEL-CentOS Systems.md rename to published/201801/20170828 How To Use YUM History Command To Rollback An Updates In RHEL-CentOS Systems.md diff --git a/published/20170915 12 ip Command Examples for Linux Users.md b/published/201801/20170915 12 ip Command Examples for Linux Users.md similarity index 100% rename from published/20170915 12 ip Command Examples for Linux Users.md rename to published/201801/20170915 12 ip Command Examples for Linux Users.md diff --git a/published/20170915 Fake A Hollywood Hacker Screen in Linux Terminal.md b/published/201801/20170915 Fake A Hollywood Hacker Screen in Linux Terminal.md similarity index 100% rename from published/20170915 Fake A Hollywood Hacker Screen in Linux Terminal.md rename to published/201801/20170915 Fake A Hollywood Hacker Screen in Linux Terminal.md diff --git a/published/20170916 How To Auto Logout Inactive Users After A Period Of Time In Linux.md b/published/201801/20170916 How To Auto Logout Inactive Users After A Period Of Time In Linux.md similarity index 100% rename from published/20170916 How To Auto Logout Inactive Users After A Period Of Time In Linux.md rename to published/201801/20170916 How To Auto Logout Inactive Users After A Period Of Time In Linux.md diff --git a/published/20170918 3 text editor alternatives to Emacs and Vim.md b/published/201801/20170918 3 text editor alternatives to Emacs and Vim.md similarity index 100% rename from published/20170918 3 text editor alternatives to Emacs and Vim.md rename to published/201801/20170918 3 text editor alternatives to Emacs and Vim.md diff --git a/published/20170918 Linux fmt command - usage and examples.md b/published/201801/20170918 Linux fmt command - usage and examples.md similarity index 100% rename from published/20170918 Linux fmt command - usage and examples.md rename to published/201801/20170918 Linux fmt command - usage and examples.md diff --git a/published/20170919 What Are Bitcoins.md b/published/201801/20170919 What Are Bitcoins.md similarity index 100% rename from published/20170919 What Are Bitcoins.md rename to published/201801/20170919 What Are Bitcoins.md diff --git a/published/20170920 Easy APT Repository - Iain R. Learmonth.md b/published/201801/20170920 Easy APT Repository - Iain R. Learmonth.md similarity index 100% rename from published/20170920 Easy APT Repository - Iain R. Learmonth.md rename to published/201801/20170920 Easy APT Repository - Iain R. Learmonth.md diff --git a/translated/tech/20170921 Mastering file searches on Linux.md b/published/201801/20170921 Mastering file searches on Linux.md similarity index 58% rename from translated/tech/20170921 Mastering file searches on Linux.md rename to published/201801/20170921 Mastering file searches on Linux.md index e964a35a64..2740e6a783 100644 --- a/translated/tech/20170921 Mastering file searches on Linux.md +++ b/published/201801/20170921 Mastering file searches on Linux.md @@ -7,52 +7,49 @@ * 快速搜索 * 更复杂的搜索条件 - * 连接条件 + * 组合条件 * 反转条件 * 简单和详细的回应 * 寻找重复的文件 -有很多有用的命令可以搜索文件,**find** 命令可能是其中最有名的,但它不是唯一的命令,也不一定总是找到目标文件的最快方法。 +有很多有用的命令可以搜索文件,`find` 命令可能是其中最有名的,但它不是唯一的命令,也不一定总是找到目标文件的最快方法。 ### 快速搜索命令:which 和 locate -搜索文件的最简单的命令可能就是 **which** 和 **locate** 了,但二者都有一些局限性。**which** 命令只会在系统定义的搜索路径中,查找可执行的文件,通常用于识别命令。如果您对输入 which 时会运行的命令感到好奇,您可以使用命令 which which,它会指向对应的可执行文件。 +搜索文件的最简单的命令可能就是 `which` 和 `locate` 了,但二者都有一些局限性。`which` 命令只会在系统定义的搜索路径中,查找可执行的文件,通常用于识别命令。如果您对输入 `which` 时会运行哪个命令感到好奇,您可以使用命令 `which which`,它会指出对应的可执行文件。 ``` $ which which /usr/bin/which - ``` -**which** 命令会显示它找到的第一个以相应名称命名的可执行文件(也就是使用该命令时将运行的那个文件),然后停止。 +`which` 命令会显示它找到的第一个以相应名称命名的可执行文件(也就是使用该命令时将运行的那个文件),然后停止。 -**locate** 命令更大方一点,它可以查找任意数量的文件,但它也有一个限制:仅当文件名被包含在由 **updatedb** 命令准备的数据库时才有效。该文件可能会存储在某个位置,如 /var/lib/mlocate/mlocate.db,但不能用 locate 以外的任何命令读取。这个文件的更新通常是通过每天通过 cron 运行的 updatedb 进行的。 +`locate` 命令更大方一点,它可以查找任意数量的文件,但它也有一个限制:仅当文件名被包含在由 `updatedb` 命令构建的数据库时才有效。该文件可能会存储在某个位置,如 `/var/lib/mlocate/mlocate.db`,但不能用 `locate` 以外的任何命令读取。这个文件的更新通常是通过每天通过 cron 运行的 `updatedb` 进行的。 -简单的 **find** 命令不需要太多限制,不过它需要搜索的起点和指定搜索条件。最简单的 find 命令:按文件名搜索文件。如下所示: +简单的 `find` 命令没有太多限制,不过它需要指定搜索的起点和搜索条件。最简单的 `find` 命令:按文件名搜索文件。如下所示: ``` $ find . -name runme ./bin/runme - ``` 如上所示,通过文件名搜索文件系统的当前位置将会搜索所有子目录,除非您指定了搜索深度。 ### 不仅仅是文件名 -**find** 命令允许您搜索除文件名以外的多种条件,包括文件所有者、组、权限、大小、修改时间、缺少所有者或组和文件类型等。除了查找文件外,您还可以删除文件、对其进行重命名、更改所有者、更改权限和对文件运行几乎任何命令。 +`find` 命令允许您搜索除文件名以外的多种条件,包括文件所有者、组、权限、大小、修改时间、缺少所有者或组,和文件类型等。除了查找文件外,您还可以删除文件、对其进行重命名、更改所有者、更改权限和对找到的文件运行几乎任何命令。 -下面两条命令会查找:在当前目录中 root 用户拥有的文件,以及非指定用户(在本例中为 shs)拥有的文件。在这个例子中,两个输出是一样的,但并不总是如此。 +下面两条命令会查找:在当前目录中 root 用户拥有的文件,以及不被指定用户(在本例中为 shs)所拥有的文件。在这个例子中,两个输出是一样的,但并不总是如此。 ``` $ find . -user root -ls 396926 0 lrwxrwxrwx 1 root root 21 Sep 21 09:03 ./xyz -> /home/peanut/xyz $ find . ! -user shs -ls 396926 0 lrwxrwxrwx 1 root root 21 Sep 21 09:03 ./xyz -> /home/peanut/xyz - ``` -感叹号“!”字符代表“非”:反转跟随其后的条件。 +感叹号 `!` 字符代表“非”:反转跟随其后的条件。 下面的命令将查找具有特定权限的文件: @@ -61,7 +58,6 @@ $ find . -perm 750 -ls 397176 4 -rwxr-x--- 1 shs shs 115 Sep 14 13:52 ./ll 398209 4 -rwxr-x--- 1 shs shs 117 Sep 21 08:55 ./get-updates 397145 4 drwxr-x--- 2 shs shs 4096 Sep 14 15:42 ./newdir - ``` 接下来的命令显示具有 777 权限的非符号链接文件: @@ -70,19 +66,17 @@ $ find . -perm 750 -ls $ sudo find /home -perm 777 ! -type l -ls 397132 4 -rwxrwxrwx 1 shs shs 18 Sep 15 16:06 /home/shs/bin/runme 396949 4 -rwxrwxrwx 1 root root 558 Sep 21 11:21 /home/oops - ``` -以下命令将查找大小超过千兆字节的文件。请注意,我们找到了一个非常有趣的文件。它在 ELF 核心文件格式中代表该系统的物理内存。 +以下命令将查找大小超过千兆字节的文件。请注意,我们找到了一个非常有趣的文件。它以 ELF core 文件格式表示了该系统的物理内存。 ``` $ sudo find / -size +1G -ls 4026531994 0 -r-------- 1 root root 140737477881856 Sep 21 11:23 /proc/kcore 1444722 15332 -rw-rw-r-- 1 shs shs 1609039872 Sep 13 15:55 /home/shs/Downloads/ubuntu-17.04-desktop-amd64.iso - ``` -只要您知道 find 命令是如何描述文件类型的,就可以通过文件类型来查找文件。 +只要您知道 `find` 命令是如何描述文件类型的,就可以通过文件类型来查找文件。 ``` b = 块设备文件 @@ -93,7 +87,6 @@ f = 常规文件 l = 符号链接 s = 套接字 D = 门(仅限 Solaris) - ``` 在下面的命令中,我们要寻找符号链接和套接字: @@ -103,28 +96,25 @@ $ find . -type l -ls 396926 0 lrwxrwxrwx 1 root root 21 Sep 21 09:03 ./whatever -> /home/peanut/whatever $ find . -type s -ls 395256 0 srwxrwxr-x 1 shs shs 0 Sep 21 08:50 ./.gnupg/S.gpg-agent - ``` -您还可以根据 inode 数字来搜索文件: +您还可以根据 inode 号来搜索文件: ``` $ find . -inum 397132 -ls 397132 4 -rwx------ 1 shs shs 18 Sep 15 16:06 ./bin/runme - ``` -另一种通过 inode 搜索文件的方法是使用 **debugfs** 命令。在大的文件系统上,这个命令可能比 find 快得多,您可能需要安装 icheck。 +另一种通过 inode 搜索文件的方法是使用 `debugfs` 命令。在大的文件系统上,这个命令可能比 `find` 快得多,您可能需要安装 icheck。 ``` $ sudo debugfs -R 'ncheck 397132' /dev/sda1 debugfs 1.42.13 (17-May-2015) Inode Pathname 397132 /home/shs/bin/runme - ``` -在下面的命令中,我们从主目录(〜)开始,限制搜索的深度(是我们将搜索子目录的层数),并只查看在最近一天内创建或修改的文件(mtime 设置)。 +在下面的命令中,我们从主目录(`~`)开始,限制搜索的深度(即我们将搜索子目录的层数),并只查看在最近一天内创建或修改的文件(`mtime` 设置)。 ``` $ find ~ -maxdepth 2 -mtime -1 -ls @@ -132,29 +122,28 @@ $ find ~ -maxdepth 2 -mtime -1 -ls 394006 8 -rw------- 1 shs shs 5909 Sep 21 08:18 /home/shs/.bash_history 399612 4 -rw------- 1 shs shs 53 Sep 21 08:50 /home/shs/.Xauthority 399615 4 drwxr-xr-x 2 shs shs 4096 Sep 21 09:32 /home/shs/Downloads - ``` ### 不仅仅是列出文件 -使用 **-exec** 选项,在您使用 find 命令找到文件后可以以某种方式更改文件。您只需参照 -exec 选项即可运行相应的命令。 +使用 `-exec` 选项,在您使用 `find` 命令找到文件后可以以某种方式更改文件。您只需参照 `-exec` 选项即可运行相应的命令。 ``` $ find . -name runme -exec chmod 700 {} \; $ find . -name runme -ls 397132 4 -rwx------ 1 shs shs 18 Sep 15 16:06 ./bin/runme - ``` -在这条命令中,“{}”代表文件名。此命令将更改当前目录和子目录中任何名为“runme”的文件的权限。 +在这条命令中,`{}` 代表文件名。此命令将更改当前目录和子目录中任何名为 `runme` 的文件的权限。 -把您想运行的任何命令放在 -exec 选项之后,并使用类似于上面命令的语法即可。 +把您想运行的任何命令放在 `-exec` 选项之后,并使用类似于上面命令的语法即可。 ### 其他搜索条件 如上面的例子所示,您还可以通过其他条件进行搜索:文件的修改时间、所有者、权限等。以下是一些示例。 #### 根据用户查找文件 + ``` $ sudo find /home -user peanut /home/peanut @@ -162,23 +151,22 @@ $ sudo find /home -user peanut /home/peanut/.bash_logout /home/peanut/.profile /home/peanut/examples.desktop - ``` -#### 根据权限查找文件 +#### 根据权限查找文件 + ``` $ sudo find /home -perm 777 /home/shs/whatever /home/oops - ``` #### 根据修改时间查找文件 + ``` $ sudo find /home -mtime +100 /home/shs/.mozilla/firefox/krsw3giq.default/gmp-gmpopenh264/1.6/gmpopenh264.info /home/shs/.mozilla/firefox/krsw3giq.default/gmp-gmpopenh264/1.6/libgmpopenh264.so - ``` #### 通过比较修改时间查找文件 @@ -188,12 +176,11 @@ $ sudo find /home -mtime +100 ``` $ sudo find /var/log -newer /var/log/syslog /var/log/auth.log - ``` ### 寻找重复的文件 -如果您正在清理磁盘空间,则可能需要删除较大的重复文件。确定文件是否真正重复的最好方法是使用 **fdupes** 命令。此命令使用 md5 校验和来确定文件是否具有相同的内容。使用 -r(递归)选项,fdupes 将在一个目录下并查找具有相同校验和而被确定为内容相同的文件。 +如果您正在清理磁盘空间,则可能需要删除较大的重复文件。确定文件是否真正重复的最好方法是使用 `fdupes` 命令。此命令使用 md5 校验和来确定文件是否具有相同的内容。使用 `-r`(递归)选项,`fdupes` 将在一个目录下并查找具有相同校验和而被确定为内容相同的文件。 如果以 root 身份运行这样的命令,您可能会发现很多重复的文件,但是很多文件都是创建时被添加到主目录的启动文件。 @@ -209,25 +196,23 @@ $ sudo find /var/log -newer /var/log/syslog /home/tsmith/.bashrc /home/peanut/.bashrc /home/rocket/.bashrc - ``` -同样,您可能会在 /usr 中发现很多重复的但不该删除的配置文件。所以,请谨慎利用 fdupes 的输出。 +同样,您可能会在 `/usr` 中发现很多重复的但不该删除的配置文件。所以,请谨慎利用 `fdupes` 的输出。 -fdupes 命令并不总是很快,但是要记住,它正在对许多文件运行校验和来做比较,你可能会意识到它的有效性。 +`fdupes` 命令并不总是很快,但是要记住,它正在对许多文件运行校验和来做比较,你可能会意识到它是多么有效。 ### 总结 有很多方法可以在 Linux 系统上查找文件。如果您可以描述清楚您正在寻找什么,上面的命令将帮助您找到目标。 - -------------------------------------------------------------------------------- via: https://www.networkworld.com/article/3227075/linux/mastering-file-searches-on-linux.html 作者:[Sandra Henry-Stocker][a] 译者:[jessie-pang](https://github.com/jessie-pang) -校对:[校对者ID](https://github.com/校对者ID) +校对:[wxy](https://github.com/wxy) 本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 diff --git a/published/20170924 Simulate System Loads.md b/published/201801/20170924 Simulate System Loads.md similarity index 100% rename from published/20170924 Simulate System Loads.md rename to published/201801/20170924 Simulate System Loads.md diff --git a/published/20170925 A Commandline Fuzzy Search Tool For Linux.md b/published/201801/20170925 A Commandline Fuzzy Search Tool For Linux.md similarity index 100% rename from published/20170925 A Commandline Fuzzy Search Tool For Linux.md rename to published/201801/20170925 A Commandline Fuzzy Search Tool For Linux.md diff --git a/published/20170925 Linux Free Command Explained for Beginners (6 Examples).md b/published/201801/20170925 Linux Free Command Explained for Beginners (6 Examples).md similarity index 100% rename from published/20170925 Linux Free Command Explained for Beginners (6 Examples).md rename to published/201801/20170925 Linux Free Command Explained for Beginners (6 Examples).md diff --git a/published/20170927 How To Easily Find Awesome Projects And Resources Hosted In GitHub.md b/published/201801/20170927 How To Easily Find Awesome Projects And Resources Hosted In GitHub.md similarity index 100% rename from published/20170927 How To Easily Find Awesome Projects And Resources Hosted In GitHub.md rename to published/201801/20170927 How To Easily Find Awesome Projects And Resources Hosted In GitHub.md diff --git a/published/20170927 Microservices and containers- 5 pitfalls to avoid.md b/published/201801/20170927 Microservices and containers- 5 pitfalls to avoid.md similarity index 100% rename from published/20170927 Microservices and containers- 5 pitfalls to avoid.md rename to published/201801/20170927 Microservices and containers- 5 pitfalls to avoid.md diff --git a/published/20171002 Connect To Wifi From The Linux Command Line.md b/published/201801/20171002 Connect To Wifi From The Linux Command Line.md similarity index 100% rename from published/20171002 Connect To Wifi From The Linux Command Line.md rename to published/201801/20171002 Connect To Wifi From The Linux Command Line.md diff --git a/published/20171004 How To Create A Video From PDF Files In Linux.md b/published/201801/20171004 How To Create A Video From PDF Files In Linux.md similarity index 100% rename from published/20171004 How To Create A Video From PDF Files In Linux.md rename to published/201801/20171004 How To Create A Video From PDF Files In Linux.md diff --git a/published/20171005 python-hwinfo - Display Summary Of Hardware Information In Linux.md b/published/201801/20171005 python-hwinfo - Display Summary Of Hardware Information In Linux.md similarity index 100% rename from published/20171005 python-hwinfo - Display Summary Of Hardware Information In Linux.md rename to published/201801/20171005 python-hwinfo - Display Summary Of Hardware Information In Linux.md diff --git a/published/20171008 The most important Firefox command line options.md b/published/201801/20171008 The most important Firefox command line options.md similarity index 100% rename from published/20171008 The most important Firefox command line options.md rename to published/201801/20171008 The most important Firefox command line options.md diff --git a/published/20171011 What is a firewall.md b/published/201801/20171011 What is a firewall.md similarity index 100% rename from published/20171011 What is a firewall.md rename to published/201801/20171011 What is a firewall.md diff --git a/published/20171012 Install and Use YouTube-DL on Ubuntu 16.04.md b/published/201801/20171012 Install and Use YouTube-DL on Ubuntu 16.04.md similarity index 100% rename from published/20171012 Install and Use YouTube-DL on Ubuntu 16.04.md rename to published/201801/20171012 Install and Use YouTube-DL on Ubuntu 16.04.md diff --git a/published/20171013 Get Your Weather Forecast From the Linux CLI.md b/published/201801/20171013 Get Your Weather Forecast From the Linux CLI.md similarity index 100% rename from published/20171013 Get Your Weather Forecast From the Linux CLI.md rename to published/201801/20171013 Get Your Weather Forecast From the Linux CLI.md diff --git a/published/20171016 Fixing vim in Debian - There and back again.md b/published/201801/20171016 Fixing vim in Debian - There and back again.md similarity index 100% rename from published/20171016 Fixing vim in Debian - There and back again.md rename to published/201801/20171016 Fixing vim in Debian - There and back again.md diff --git a/published/20171017 check_mk error Cannot fetch deployment URL via curl error.md b/published/201801/20171017 check_mk error Cannot fetch deployment URL via curl error.md similarity index 100% rename from published/20171017 check_mk error Cannot fetch deployment URL via curl error.md rename to published/201801/20171017 check_mk error Cannot fetch deployment URL via curl error.md diff --git a/published/20171019 3 Simple Excellent Linux Network Monitors.md b/published/201801/20171019 3 Simple Excellent Linux Network Monitors.md similarity index 100% rename from published/20171019 3 Simple Excellent Linux Network Monitors.md rename to published/201801/20171019 3 Simple Excellent Linux Network Monitors.md diff --git a/published/20171024 Run Linux On Android Devices, No Rooting Required.md b/published/201801/20171024 Run Linux On Android Devices, No Rooting Required.md similarity index 100% rename from published/20171024 Run Linux On Android Devices, No Rooting Required.md rename to published/201801/20171024 Run Linux On Android Devices, No Rooting Required.md diff --git a/published/20171028 Let Us Play Piano In Terminal Using Our PC Keyboard.md b/published/201801/20171028 Let Us Play Piano In Terminal Using Our PC Keyboard.md similarity index 100% rename from published/20171028 Let Us Play Piano In Terminal Using Our PC Keyboard.md rename to published/201801/20171028 Let Us Play Piano In Terminal Using Our PC Keyboard.md diff --git a/published/20171030 How To Create Custom Ubuntu Live CD Image.md b/published/201801/20171030 How To Create Custom Ubuntu Live CD Image.md similarity index 100% rename from published/20171030 How To Create Custom Ubuntu Live CD Image.md rename to published/201801/20171030 How To Create Custom Ubuntu Live CD Image.md diff --git a/published/20171031 Migrating to Linux- An Introduction.md b/published/201801/20171031 Migrating to Linux- An Introduction.md similarity index 100% rename from published/20171031 Migrating to Linux- An Introduction.md rename to published/201801/20171031 Migrating to Linux- An Introduction.md diff --git a/published/20171106 Autorandr- automatically adjust screen layout.md b/published/201801/20171106 Autorandr- automatically adjust screen layout.md similarity index 100% rename from published/20171106 Autorandr- automatically adjust screen layout.md rename to published/201801/20171106 Autorandr- automatically adjust screen layout.md diff --git a/translated/tech/20171107 How To Protect Server Against Brute Force Attacks With Fail2ban On Linux.md b/published/201801/20171107 How To Protect Server Against Brute Force Attacks With Fail2ban On Linux.md similarity index 63% rename from translated/tech/20171107 How To Protect Server Against Brute Force Attacks With Fail2ban On Linux.md rename to published/201801/20171107 How To Protect Server Against Brute Force Attacks With Fail2ban On Linux.md index 1d90ea333c..2a4547fef3 100644 --- a/translated/tech/20171107 How To Protect Server Against Brute Force Attacks With Fail2ban On Linux.md +++ b/published/201801/20171107 How To Protect Server Against Brute Force Attacks With Fail2ban On Linux.md @@ -1,64 +1,65 @@ -如何在Linux上用Fail2ban保护服务器免受暴力攻击 +如何在 Linux 上用 Fail2Ban 保护服务器免受暴力攻击 ====== -Linux管理员的一个重要任务是保护服务器免受非法攻击或访问。 默认情况下,Linux系统带有配置良好的防火墙,比如Iptables,Uncomplicated Firewall(UFW),ConfigServer Security Firewall(CSF)等,可以防止多种攻击。 +Linux 管理员的一个重要任务是保护服务器免受非法攻击或访问。 默认情况下,Linux 系统带有配置良好的防火墙,比如iptables、Uncomplicated Firewall(UFW),ConfigServer Security Firewall(CSF)等,可以防止多种攻击。 -任何连接到互联网的机器都是恶意攻击的潜在目标。 有一个名为fail2ban的工具可用来缓解服务器上的非法访问。 +任何连接到互联网的机器都是恶意攻击的潜在目标。 有一个名为 Fail2Ban 的工具可用来缓解服务器上的非法访问。 -### 什么是Fail2ban? +### 什么是 Fail2Ban? -[Fail2ban][1]是一款入侵防御软件,可以保护服务器免受暴力攻击。 它是用Python编程语言编写的。 Fail2ban基于auth日志文件工作,默认情况下它会扫描所有auth日志文件,如`/var/log/auth.log`,`/var/log/apache/access.log`等,并禁止带有恶意标志的IP,比如密码失败太多,寻找漏洞等等标志。 +[Fail2Ban][1] 是一款入侵防御软件,可以保护服务器免受暴力攻击。 它是用 Python 编程语言编写的。 Fail2Ban 基于auth 日志文件工作,默认情况下它会扫描所有 auth 日志文件,如 `/var/log/auth.log`、`/var/log/apache/access.log` 等,并禁止带有恶意标志的IP,比如密码失败太多,寻找漏洞等等标志。 -通常,fail2Ban用于更新防火墙规则,用于在指定的时间内拒绝IP地址。 它也会发送邮件通知。 Fail2Ban为各种服务提供了许多过滤器,如ssh,apache,nginx,squid,named,mysql,nagios等。 +通常,Fail2Ban 用于更新防火墙规则,用于在指定的时间内拒绝 IP 地址。 它也会发送邮件通知。 Fail2Ban 为各种服务提供了许多过滤器,如 ssh、apache、nginx、squid、named、mysql、nagios 等。 -Fail2Ban能够降低错误认证尝试的速度,但是它不能消除弱认证带来的风险。 这只是服务器防止暴力攻击的安全手段之一。 +Fail2Ban 能够降低错误认证尝试的速度,但是它不能消除弱认证带来的风险。 这只是服务器防止暴力攻击的安全手段之一。 -### 如何在Linux中安装Fail2ban +### 如何在 Linux 中安装 Fail2Ban -Fail2ban已经与大部分Linux发行版打包在一起了,所以只需使用你的发行包版的包管理器来安装它。 +Fail2Ban 已经与大部分 Linux 发行版打包在一起了,所以只需使用你的发行包版的包管理器来安装它。 -对于**`Debian / Ubuntu`**,使用[APT-GET命令][2]或[APT命令][3]安装。 +对于 Debian / Ubuntu,使用 [APT-GET 命令][2]或 [APT 命令][3]安装。 ``` $ sudo apt install fail2ban ``` -对于**`Fedora`**,使用[DNF命令][4]安装。 +对于 Fedora,使用 [DNF 命令][4]安装。 ``` $ sudo dnf install fail2ban ``` -对于 **`CentOS/RHEL`**,启用[EPEL库][5]或[RPMForge][6]库,使用[YUM命令][7]安装。 +对于 CentOS/RHEL,启用 [EPEL 库][5]或 [RPMForge][6] 库,使用 [YUM 命令][7]安装。 ``` $ sudo yum install fail2ban ``` -对于**`Arch Linux`**,使用[Pacman命令][8]安装。 +对于 Arch Linux,使用 [Pacman 命令][8]安装。 ``` $ sudo pacman -S fail2ban ``` -对于 **`openSUSE`** , 使用[Zypper命令][9]安装. +对于 openSUSE , 使用 [Zypper命令][9]安装。 + ``` $ sudo zypper in fail2ban ``` -### 如何配置Fail2ban +### 如何配置 Fail2Ban -默认情况下,Fail2ban将所有配置文件保存在`/etc/fail2ban/` 目录中。 主配置文件是`jail.conf`,它包含一组预定义的过滤器。 所以,不要编辑文件,这是不可取的,因为只要有新的更新配置就会重置为默认值。 +默认情况下,Fail2Ban 将所有配置文件保存在 `/etc/fail2ban/` 目录中。 主配置文件是 `jail.conf`,它包含一组预定义的过滤器。 所以,不要编辑该文件,这是不可取的,因为只要有新的更新,配置就会重置为默认值。 -只需在同一目录下创建一个名为`jail.local`的新配置文件,并根据您的意愿进行修改。 +只需在同一目录下创建一个名为 `jail.local` 的新配置文件,并根据您的意愿进行修改。 ``` # cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local ``` -默认情况下,大多数选项都已经配置的很完美了,如果要启用对任何特定IP的访问,则可以将IP地址添加到`ignoreip` 区域,对于多个ip的情况,用空格隔开ip地址。 +默认情况下,大多数选项都已经配置的很完美了,如果要启用对任何特定 IP 的访问,则可以将 IP 地址添加到 `ignoreip` 区域,对于多个 IP 的情况,用空格隔开 IP 地址。 -配置文件中的`DEFAULT`部分包含Fail2Ban遵循的基本规则集,您可以根据自己的意愿调整任何参数。 +配置文件中的 `DEFAULT` 部分包含 Fail2Ban 遵循的基本规则集,您可以根据自己的意愿调整任何参数。 ``` # nano /etc/fail2ban/jail.local @@ -71,16 +72,14 @@ maxretry = 3 destemail = 2daygeek@gmail.com ``` - * **ignoreip:**本部分允许我们列出IP地址列表,Fail2ban不会禁止与列表中的地址匹配的主机 -* **bantime:**主机被禁止的秒数 -* **findtime:**如果在上次“findtime”秒期间已经发生了“maxretry”次重试,则主机会被禁止 -* **maxretry:**“maxretry”是主机被禁止之前的失败次数 - - +* `ignoreip`:本部分允许我们列出 IP 地址列表,Fail2Ban 不会禁止与列表中的地址匹配的主机 +* `bantime`:主机被禁止的秒数 +* `findtime`:如果在最近 `findtime` 秒期间已经发生了 `maxretry` 次重试,则主机会被禁止 +* `maxretry`:是主机被禁止之前的失败次数 ### 如何配置服务 -Fail2ban带有一组预定义的过滤器,用于各种服务,如ssh,apache,nginx,squid,named,mysql,nagios等。 我们不希望对配置文件进行任何更改,只需在服务区域中添加`enabled = true`这一行就可以启用任何服务。 禁用服务时将true改为false即可。 +Fail2Ban 带有一组预定义的过滤器,用于各种服务,如 ssh、apache、nginx、squid、named、mysql、nagios 等。 我们不希望对配置文件进行任何更改,只需在服务区域中添加 `enabled = true` 这一行就可以启用任何服务。 禁用服务时将 `true` 改为 `false` 即可。 ``` # SSH servers @@ -91,16 +90,15 @@ logpath = %(sshd_log)s backend = %(sshd_backend)s ``` - * **enabled:** 确定服务是打开还是关闭。 -* **port :**指的是特定的服务。 如果使用默认端口,则服务名称可以放在这里。 如果使用非传统端口,则应该是端口号。 -* **logpath:**提供服务日志的位置 -* **backend:**“后端”指定用于获取文件修改的后端。 +* `enabled`: 确定服务是打开还是关闭。 +* `port`:指明特定的服务。 如果使用默认端口,则服务名称可以放在这里。 如果使用非传统端口,则应该是端口号。 +* `logpath`:提供服务日志的位置 +* `backend`:指定用于获取文件修改的后端。 +### 重启 Fail2Ban +进行更改后,重新启动 Fail2Ban 才能生效。 -### 重启Fail2Ban - -进行更改后,重新启动Fail2Ban才能生效。 ``` [For SysVinit Systems] # service fail2ban restart @@ -109,9 +107,10 @@ backend = %(sshd_backend)s # systemctl restart fail2ban.service ``` -### 验证Fail2Ban iptables规则 +### 验证 Fail2Ban iptables 规则 + +你可以使用下面的命令来确认是否在防火墙中成功添加了Fail2Ban iptables 规则。 -你可以使用下面的命令来确认是否在防火墙中成功添加了Fail2Ban iptables规则。 ``` # iptables -L Chain INPUT (policy ACCEPT) @@ -135,9 +134,9 @@ target prot opt source destination RETURN all -- anywhere anywhere ``` -### 如何测试Fail2ban +### 如何测试 Fail2Ban -我做了一些失败的尝试来测试这个。 为了证实这一点,我要验证`/var/log/fail2ban.log` 文件。 +我做了一些失败的尝试来测试这个。 为了证实这一点,我要验证 `/var/log/fail2ban.log` 文件。 ``` 2017-11-05 14:43:22,901 fail2ban.server [7141]: INFO Changed logging target to /var/log/fail2ban.log for Fail2ban v0.9.6 @@ -184,6 +183,7 @@ RETURN all -- anywhere anywhere ``` 要查看启用的监狱列表,请运行以下命令。 + ``` # fail2ban-client status Status @@ -191,7 +191,8 @@ Status `- Jail list: apache-auth, sshd ``` -通过运行以下命令来获取禁止的IP地址。 +通过运行以下命令来获取禁止的 IP 地址。 + ``` # fail2ban-client status ssh Status for the jail: ssh @@ -205,18 +206,19 @@ Status for the jail: ssh `- Total banned: 1 ``` -要从Fail2Ban中删除禁止的IP地址,请运行以下命令。 +要从 Fail2Ban 中删除禁止的 IP 地址,请运行以下命令。 + ``` # fail2ban-client set ssh unbanip 192.168.1.115 ``` -------------------------------------------------------------------------------- -via: https://www.2daygeek.com/how-to-install-setup-configure-fail2ban-on-linux/# +via: https://www.2daygeek.com/how-to-install-setup-configure-fail2ban-on-linux/ 作者:[Magesh Maruthamuthu][a] 译者:[Flowsnow](https://github.com/Flowsnow) -校对:[校对者ID](https://github.com/校对者ID) +校对:[wxy](https://github.com/wxy) 本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 diff --git a/published/20171107 The long goodbye to C.md b/published/201801/20171107 The long goodbye to C.md similarity index 100% rename from published/20171107 The long goodbye to C.md rename to published/201801/20171107 The long goodbye to C.md diff --git a/published/20171109 Learn how to use tcpdump command with examples.md b/published/201801/20171109 Learn how to use tcpdump command with examples.md similarity index 100% rename from published/20171109 Learn how to use tcpdump command with examples.md rename to published/201801/20171109 Learn how to use tcpdump command with examples.md diff --git a/translated/tech/20171112 Love Your Bugs.md b/published/201801/20171112 Love Your Bugs.md similarity index 97% rename from translated/tech/20171112 Love Your Bugs.md rename to published/201801/20171112 Love Your Bugs.md index 9203cf52bb..b983fae177 100644 --- a/translated/tech/20171112 Love Your Bugs.md +++ b/published/201801/20171112 Love Your Bugs.md @@ -15,19 +15,17 @@ 好,让我们直接来看第一个 bug。这是我在 Dropbox 工作时遇到的一个 bug。你们或许听说过,Dropbox 是一个将你的文件从一个电脑上同步到云端和其他电脑上的应用。 - - ``` +--------------+ +---------------+ | | | | - | METASERVER | | BLOCKSERVER | + | 元数据服务器 | | 块服务器 | | | | | +-+--+---------+ +---------+-----+ ^ | ^ | | | | | +----------+ | | +---> | | | - | | CLIENT +--------+ + | | 客户端 +--------+ +--------+ | +----------+ ``` @@ -79,7 +77,7 @@ l \x0c < $ ( . - ``` -英文逗号的 ASCII 码是44。`l` 的 ASCII 码是 108。它们的二进制表示如下: +英文逗号的 ASCII 码是 44。`l` 的 ASCII 码是 108。它们的二进制表示如下: ``` bin(ord(',')): 0101100 @@ -101,8 +99,7 @@ $ : 0100100 - : 0101101 ``` - -### 位反转是真的! +#### 位反转是真的! 我爱这个 bug 因为它证明了位反转是可能真实发生的事情,而不只是一个理论上的问题。实际上,它在某些情况下会比平时更容易发生。其中一种情况是用户使用的是低配或者老旧的硬件,而运行 Dropbox 的电脑很多都是这样。另外一种会造成很多位反转的地方是外太空——在太空中没有大气层来保护你的内存不受高能粒子和辐射的影响,所以位反转会十分常见。 @@ -110,31 +107,31 @@ $ : 0100100 在刚才那种情况下,Dropbox 并不需要处理位反转。出现内存损坏的是用户的电脑,所以即使我们可以检测到逗号字符的位反转,但如果这发生在其他字符上我们就不一定能检测到了,而且如果从硬盘中读取的文件本身发生了位反转,那我们根本无从得知。我们能改进的地方很少,于是我们决定无视这个异常并继续程序的运行。这种 bug 一般都会在客户端重启之后自动解决。 -### 不常见的 bug 并非不可能发生 +#### 不常见的 bug 并非不可能发生 这是我最喜欢的 bug 之一,有几个原因。第一,它提醒我注意不常见和不可能之间的区别。当规模足够大的时候,不常见的现象会以值得注意的频率发生。 -### 覆盖面广的 bug +#### 覆盖面广的 bug 这个 bug 第二个让我喜欢的地方是它覆盖面非常广。每当桌面客户端和服务器交流的时候,这个 bug 都可能悄然出现,而这可能会发生在系统里很多不同的端点和组件当中。这意味着许多不同的 Dropbox 工程师会看到这个 bug 的各种版本。你第一次看到它的时候,你 _真的_ 会满头雾水,但在那之后诊断这个 bug 就变得很容易了,而调查过程也非常简短:你只需找到中间的字母,看它是不是个 `l`。 -### 文化差异 +#### 文化差异 这个 bug 的一个有趣的副作用是它展示了服务器组和客户端组之间的文化差异。有时候这个 bug 会被服务器组的成员发现并展开调查。如果你的 _服务器_ 上发生了位反转,那应该不是个偶然——这很可能是内存损坏,你需要找到受影响的主机并尽快把它从集群中移除,不然就会有损坏大量用户数据的风险。这是个事故,而你必须迅速做出反应。但如果是用户的电脑在破坏数据,你并没有什么可以做的。 -### 分享你的 bug +#### 分享你的 bug 如果你在调试一个难搞的 bug,特别是在大型系统中,不要忘记跟别人讨论。也许你的同事以前就遇到过类似的 bug。若是如此,你可能会节省很多时间。就算他们没有见过,也不要忘记在你解决了问题之后告诉他们解决方法——写下来或者在组会中分享。这样下次你们组遇到类似的问题时,你们都会早有准备。 ### Bug 如何帮助你进步 -### Recurse Center +#### Recurse Center 在加入 Dropbox 之前,我曾在 Recurse Center 工作。它的理念是建立一个社区让正在自学的程序员们聚到一起来提高能力。这就是 Recurse Center 的全部了:我们没有大纲、作业、截止日期等等。唯一的前提条件是我们都想要成为更好的程序员。参与者中有的人有计算机学位但对自己的实际编程能力不够自信,有的人已经写了十年 Java 但想学 Clojure 或者 Haskell,还有各式各样有着其他的背景的参与者。 我在那里是一位导师,帮助人们更好地利用这个自由的环境,并参考我们从以前的参与者那里学到的东西来提供指导。所以我的同事们和我本人都非常热衷于寻找对成年自学者最有帮助的学习方法。 -### 刻意练习 +#### 刻意练习 在学习方法这个领域有很多不同的研究,其中我觉得最有意思的研究之一是刻意练习的概念。刻意练习理论意在解释专业人士和业余爱好者的表现的差距。它的基本思想是如果你只看内在的特征——不论先天与否——它们都无法非常好地解释这种差距。于是研究者们,包括最初的 Ericsson、Krampe 和 Tesch-Romer,开始寻找能够解释这种差距的理论。他们最终的答案是在刻意练习上所花的时间。 @@ -189,18 +186,15 @@ $ : 0100100 所有这些 bug 都很容易修复。前两个 bug 出在客户端上,所以我们在 alpha 版本修复了它们,但大部分的客户端还没有获得这些改动。我们在服务器代码中修复了第三个 bug 并部署了新版的服务器。 -### 📈 +#### 激增 突然日志服务器集群的流量开始激增。客服团队找到我们并问我们是否知道原因。我花了点时间把所有的部分拼到一起。 在修复之前,这四件事情会发生: 1. 日志文件从最早的开始发送 - 2. 日志文件从最新的开始删除 - 3. 如果服务器无法解码日志文件,它会返回 500 - 4. 如果客户端收到 500,它会停止发送日志 一个存有损坏的日志文件的客户端会试着发送这个文件,服务器会返回 500,客户端会放弃发送日志。在下一次运行时,它会尝试再次发送同样的文件,再次失败,并再次放弃。最终日志目录会被填满,然后客户端会开始删除最新的日志文件,而把损坏的文件继续保留在硬盘上。 @@ -209,27 +203,27 @@ $ : 0100100 问题是,处于这种状态的客户端比我们想象的要多很多。任何有一个损坏文件的客户端都会像被关在堤坝里一样,无法再发送日志。现在这个堤坝被清除了,所有这些客户端都开始发送它们的日志目录的剩余内容。 -### 我们的选择 +#### 我们的选择 -好的,现在文件从世界各地的电脑如洪水般涌来。我们能做什么?(当你在一个有 Dropbox 这种规模,尤其是这种桌面客户端的规模的公司工作时,会遇到这种有趣的事情:你可以非常轻易地对自己造成 DDOS 攻击)。 +好的,现在文件从世界各地的电脑如洪水般涌来。我们能做什么?(当你在一个有 Dropbox 这种规模,尤其是这种桌面客户端的规模的公司工作时,会遇到这种有趣的事情:你可以非常轻易地对自己造成 DDoS 攻击)。 当你部署的新版本发生问题时,第一个选项是回滚。这是非常合理的选择,但对于这个问题,它无法帮助我们。我们改变的不是服务器的状态而是客户端的——我们删除了那些出错文件。将服务器回滚可以防止更多客户端进入这种状态,但它并不能解决根本问题。 -那扩大日志集群的规模呢?我们试过了——然后因为处理能力增加了,我们开始收到更多的请求。我们又扩大了一次,但你不可能一直这么下去。为什么不能?因为这个集群并不是独立的。它会向另一个集群发送请求,在这里是为了处理异常。如果你的一个集群正在被 DDOS,而你持续扩大那个集群,你最终会把它依赖的集群也弄坏,然后你就有两个问题了。 +那扩大日志集群的规模呢?我们试过了——然后因为处理能力增加了,我们开始收到更多的请求。我们又扩大了一次,但你不可能一直这么下去。为什么不能?因为这个集群并不是独立的。它会向另一个集群发送请求,在这里是为了处理异常。如果你的一个集群正在被 DDoS,而你持续扩大那个集群,你最终会把它依赖的集群也弄坏,然后你就有两个问题了。 我们考虑过的另一个选择是减低负载——你不需要每一个日志文件,所以我们可以直接无视一些请求。一个难点是我们并没有一个很好的方法来区分好的请求和坏的请求。我们无法快速地判断哪些日志文件是旧的,哪些是新的。 我们最终使用的是一个 Dropbox 里许多不同场合都用过的一个解决方法:我们有一个自定义的头字段,`chillout`,全世界所有的客户端都遵守它。如果客户端收到一个有这个头字段的响应,它将在字段所标注的时间内不再发送任何请求。很早以前一个英明的程序员把它加到了 Dropbox 客户端里,在之后这些年中它已经不止一次地起了作用。 -### 了解你的系统 +#### 了解你的系统 这个 bug 的第一个教训是要了解你的系统。我对于客户端和服务器之间的交互有不错的理解,但我并没有考虑到当服务器和所有这些客户端同时交互的时候会发生什么。这是一个我没有完全搞懂的层面。 -### 了解你的工具 +#### 了解你的工具 第二个教训是要了解你的工具。如果出了差错,你有哪些选项?你能撤销你做的迁移吗?你如何知道事情出了差错,你又如何发现更多信息?所有这些事情都应该在危机发生之前就了解好——但如果你没有,你会在危机发生时学到它们并不会再忘记。 -### 功能开关 & 服务器端功能控制 +#### 功能开关 & 服务器端功能控制 第三个教训是专门针对移动端和桌面应用开发者的:_你需要服务器端功能控制和功能开关_。当你发现一个问题时如果你没有服务器端的功能控制,你可能需要几天或几星期来推送新版本或者提交新版本到应用商店中,然后问题才能得到解决。这是个很糟糕的处境。Dropbox 桌面客户端不需要经过应用商店的审查过程,但光是把一个版本推送给上千万的用户就已经要花很多时间。相比之下,如果你能在新功能遇到问题的时候在服务器上翻转一个开关:十分钟之后你的问题就已经解决了。 @@ -237,7 +231,7 @@ $ : 0100100 但是它的好处——啊,当你需要它的时候,你真的是很需要它。 -# 如何去爱 bug +### 如何去爱 bug 我讲了几个我爱的 bug,也讲了为什么要爱 bug。现在我想告诉你如何去爱 bug。如果你现在还不爱 bug,我知道唯一一种改变的方法,那就是要有成长型心态。 @@ -261,7 +255,7 @@ Dweck 发现一个人看待智力的方式——固定型还是成长型心态 这些发现表明成长型心态对 debug 至关重要。我们必须从从困惑中重整旗鼓,诚实地面对我们理解上的不足,并时不时地在寻找答案的路上努力奋斗——成长型心态会让这些都变得更简单而且不那么痛苦。 -### 热爱你的 bug +#### 热爱你的 bug 我在 Recurse Center 工作时会直白地欢迎挑战,我就是这样学会热爱我的 bug 的。有时参与者会坐到我身边说“唉,我觉得我遇到了个奇怪的 Python bug”,然后我会说“太棒了,我 _爱_ 奇怪的 Python bug!” 首先,这百分之百是真的,但更重要的是,我这样是在对参与者强调,找到让自己觉得困难的事情是一种成就,而他们做到了这一点,这是件好事。 @@ -274,22 +268,18 @@ Dweck 发现一个人看待智力的方式——固定型还是成长型心态 在此向给我的演讲提出反馈以及给我的演讲提供其他帮助的人士表示感谢: * Sasha Laundy - * Amy Hanlon - * Julia Evans - * Julian Cooper - * Raphael Passini Diniz 以及其他的 Python Brasil 组织团队成员 -------------------------------------------------------------------------------- via: http://akaptur.com/blog/2017/11/12/love-your-bugs/ -作者:[Allison Kaptur ][a] +作者:[Allison Kaptur][a] 译者:[yixunx](https://github.com/yixunx) -校对:[校对者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/20171114 Restore Corrupted USB Drive To Original State In Linux.md b/published/201801/20171114 Restore Corrupted USB Drive To Original State In Linux.md similarity index 72% rename from translated/tech/20171114 Restore Corrupted USB Drive To Original State In Linux.md rename to published/201801/20171114 Restore Corrupted USB Drive To Original State In Linux.md index 71aa6d05ec..fd6422e2b9 100644 --- a/translated/tech/20171114 Restore Corrupted USB Drive To Original State In Linux.md +++ b/published/201801/20171114 Restore Corrupted USB Drive To Original State In Linux.md @@ -1,8 +1,6 @@ 在 Linux 上恢复一个损坏的 USB 设备至初始状态 ====== - - ![](http://www.linuxandubuntu.com/uploads/2/1/1/5/21152474/restore-corrupted-usb-drive-to-original-state-in-linux_orig.jpg) 很多时候我们诸如 SD 卡和 U 盘这样的储存器可能会被损坏,并且因此或其他原因不能继续使用。 @@ -13,56 +11,52 @@ [![Linux 系统磁盘管理器](http://www.linuxandubuntu.com/uploads/2/1/1/5/21152474/published/usb.png?1510665746)][1] -警告:接下来的操作会将你设备上的所有数据格式化 +**警告:接下来的操作会将你设备上的所有数据格式化。** +无论是上面提及的什么原因,最终的结果是我们无法继续使用这个设备。 - -无论什么原因,最终的结果是我们无法继续使用这个设备。 - -所以这里是一个恢复一个 USB 设备或者是 SD 卡到出厂状态的方法。 +所以这里有一个恢复 USB 设备或者是 SD 卡到出厂状态的方法。 大多数时候通过文件浏览器进行一次简单格式化可以解决问题,但是在一些极端情况下,比如文件管理器没有作用,而你又需要你的设备可以继续工作时,你可以使用下面的指导: -我们将会使用一个叫做 mkusb 的小工具来实现目标,这个工具的安装非常简单。 +我们将会使用一个叫做 `mkusb` 的小工具来实现目标,这个工具的安装非常简单。 +添加 mkusb 的仓库: +``` +sudo apt add repository ppa:mkusb/ppa +``` +现在更新你的包列表: +``` +sudo apt-get update +``` -1. 添加 mkusb 的仓库 +安装 `mkusb: -`sudo apt add repository ppa:mkusb/ppa` +``` +sudo apt-get install mkusb +``` -2. 现在更新你的包列表 - -`sudo apt-get update` - -3. 安装 mkusb - -`sudo apt-get install mkusb` - -现在运行 mkusb 你将会看到这个提示,点击 ‘Yes’。 +现在运行 `mkusb` 你将会看到这个提示,点击 ‘Yes’。 [![运行 mkusb dus](http://www.linuxandubuntu.com/uploads/2/1/1/5/21152474/editor/run-mkusb.png?1510498592)][2] -现在 mkusb 将会最后一次询问你是否希望继续格式化你的数据,‘Stop’是被默认选择的,你现在选择 ‘Go’并点击‘OK’。 +现在 `mkusb` 将会最后一次询问你是否希望继续格式化你的数据,‘Stop’是被默认选择的,你现在选择 ‘Go’ 并点击 ‘OK’。 [![Linux mkusb](http://www.linuxandubuntu.com/uploads/2/1/1/5/21152474/editor/final-checkpoint_1.png?1510499627)][3] -窗口将会关闭,摒弃人此时你的终端看起来是这样的。 +窗口将会关闭,此时你的终端看起来是这样的。 [![mkusb usb 控制台](http://www.linuxandubuntu.com/uploads/2/1/1/5/21152474/editor/mkusb.png?1510499982)][4] 在几秒钟之后,整个过程将会完成,并且你将看到一个这样的弹出窗口。 - - [![恢复损坏的 USB 设备](http://www.linuxandubuntu.com/uploads/2/1/1/5/21152474/editor/usb_1.png?1510500412)][5] 你现在需要把你的设备从系统推出,然后再重新插进去。你的设备将被恢复成为一个普通设备而且还能像原来一样的工作。 - - [![Linux 磁盘管理器](http://www.linuxandubuntu.com/uploads/2/1/1/5/21152474/editor/usb_2.png?1510500457)][6] 我们现在所做的操作本可以通过终端命令或是 gparted 或者其他的软件来完成,但是那将会需要一些关于分区管理的知识。 @@ -71,23 +65,19 @@ ### 结论 -**mkusb** - -是一个很容易使用的程序,它可以修复你的 USB 储存设备和 SD 卡。mkusb通过 mkusb 的 PPA 来下载。所有在 mkusb 上的操作都需要超级管理员的权限,并且你在这个设备上的所有数据将会被格式化。 +`mkusb` 是一个很容易使用的程序,它可以修复你的 USB 储存设备和 SD 卡。`mkusb` 通过 mkusb 的 PPA 来下载。所有在 `mkusb` 上的操作都需要超级管理员的权限,并且你在这个设备上的所有数据将会被格式化。 一旦操作完成,你将会重置这个设备并让它继续工作。 如果你感到任何疑惑,你可以在下面的评论栏里免费发表。 - - -------------------------------------------------------------------------------- via: http://www.linuxandubuntu.com/home/restore-corrupted-usb-drive-to-original-state-in-linux 作者:[LINUXANDUBUNTU][a] 译者:[Drshu](https://github.com/Drshu) -校对:[校对者ID](https://github.com/校对者ID) +校对:[wxy](https://github.com/wxy) 本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 diff --git a/published/20171115 How to Fix the ‘No Space Left on Device- Error on Linux.md b/published/201801/20171115 How to Fix the ‘No Space Left on Device- Error on Linux.md similarity index 100% rename from published/20171115 How to Fix the ‘No Space Left on Device- Error on Linux.md rename to published/201801/20171115 How to Fix the ‘No Space Left on Device- Error on Linux.md diff --git a/published/20171115 Security Jobs Are Hot Get Trained and Get Noticed.md b/published/201801/20171115 Security Jobs Are Hot Get Trained and Get Noticed.md similarity index 100% rename from published/20171115 Security Jobs Are Hot Get Trained and Get Noticed.md rename to published/201801/20171115 Security Jobs Are Hot Get Trained and Get Noticed.md diff --git a/published/20171119 10 Best LaTeX Editors For Linux.md b/published/201801/20171119 10 Best LaTeX Editors For Linux.md similarity index 100% rename from published/20171119 10 Best LaTeX Editors For Linux.md rename to published/201801/20171119 10 Best LaTeX Editors For Linux.md diff --git a/published/20171120 Adopting Kubernetes step by step.md b/published/201801/20171120 Adopting Kubernetes step by step.md similarity index 100% rename from published/20171120 Adopting Kubernetes step by step.md rename to published/201801/20171120 Adopting Kubernetes step by step.md diff --git a/published/20171120 Save Files Directly To Google Drive And Download 10 Times Faster.md b/published/201801/20171120 Save Files Directly To Google Drive And Download 10 Times Faster.md similarity index 100% rename from published/20171120 Save Files Directly To Google Drive And Download 10 Times Faster.md rename to published/201801/20171120 Save Files Directly To Google Drive And Download 10 Times Faster.md diff --git a/translated/tech/20171123 Check Cryptocurrency Prices From Commandline.md b/published/201801/20171123 Check Cryptocurrency Prices From Commandline.md similarity index 65% rename from translated/tech/20171123 Check Cryptocurrency Prices From Commandline.md rename to published/201801/20171123 Check Cryptocurrency Prices From Commandline.md index ba4a7bdefe..ec340bb0a5 100644 --- a/translated/tech/20171123 Check Cryptocurrency Prices From Commandline.md +++ b/published/201801/20171123 Check Cryptocurrency Prices From Commandline.md @@ -1,13 +1,16 @@ -从命令行查看加密货币价格 +用命令行查看比特币等加密货币的价格 ====== + ![配图](https://www.ostechnix.com/wp-content/uploads/2017/11/bitcoin-1-720x340.jpg) -前段时间,我们发布了一个关于 **[Cli-Fyi][1] ** 的指南 - 一个潜在有用的命令行查询工具。使用 Cli-Fyi,我们可以很容易地了解加密货币的最新价格和许多其他有用的细节。今天,我们将看到另一个名为 **“Coinmon”** 的加密货币价格查看工具。不像 Cli.Fyi,Coinmon 只能用来查看不同加密货币的价格。没有其他功能!Coinmon 会检查加密货币的价格,并立即直接从你的终端修改价格。它将从 [coinmarketcap.com][2] API 获取所有详细信息。对于那些 **加密货币投资者**和**工程师**来说是非常有用的。 + +前段时间,我们发布了一个关于 [Cli-Fyi][1] 的指南 - 一个可能有用的命令行查询工具。使用 Cli-Fyi,我们可以很容易地了解加密货币的最新价格和许多其他有用的细节。今天,我们将看到另一个名为 “Coinmon” 的加密货币价格查看工具。不像 Cli.Fyi,Coinmon 只能用来查看不同加密货币的价格。没有其他功能!Coinmon 会在终端上检查加密货币的价格。它将从 [coinmarketcap.com][2] API 获取所有详细信息。对于那些 **加密货币投资者**和**工程师**来说是非常有用的。 ### 安装 Coinmon 确保你的系统上安装了 Node.js 和 Npm。如果你的机器上没有安装 Node.js 和/或 npm,请参考以下链接进行安装。 安装完 Node.js 和 Npm 后,从终端运行以下命令安装 Coinmon。 + ``` sudo npm install -g coinmon ``` @@ -15,38 +18,42 @@ sudo npm install -g coinmon ### 从命令行查看加密货币价格 运行以下命令查看市值排名的前 10 位的加密货币: + ``` coinmon ``` 示例输出: -[![][3]][4] +![][4] + +如我所说,如果你不带任何参数运行 Coinmon,它将显示前 10 位加密货币。你还可以使用 `-t` 标志查看最高的 n 位加密货币,例如 20。 -如我所说,如果你不带任何参数运行 coinmon,它将显示前 10 位加密货币。你还可以使用 “-t” 标志查看最高的 n 位加密货币,例如 20。 ``` coinmon -t 20 ``` -所有价格默认以美元显示。你还可以使用 “-c” 标志将价格从美元转换为另一种货币。 +所有价格默认以美元显示。你还可以使用 `-c` 标志将价格从美元转换为另一种货币。 例如,要将价格转换为 INR(印度卢比),运行: + ``` coinmon -c inr ``` -[![][3]][5] +![][5] 目前,Coinmon 支持 AUD、BRL、CAD、CHF、CLP、CNY、CZK、DKK、EUR、GBP、HKD、HUF、IDR、ILS、INR、JPY、KRW、MXN、MYR、NOK、NZD、PHP、PKR、PLN、RUB、SEK、SGD、THB、TRY、TWD、ZAR 这些货币。 也可以使用加密货币的符号来搜索价格。 + ``` coinmon -f btc ``` -这里,**btc** 是比特币的符号。你可以在[**这**][6]查看所有可用的加密货币的符号。 +这里,`btc` 是比特币的符号。你可以在[**这里**][6]查看所有可用的加密货币的符号。 -有关更多详情,请参阅coinmon的帮助部分: +有关更多详情,请参阅 coinmon 的帮助部分: ``` $ coinmon -h @@ -67,15 +74,13 @@ Options: 干杯! - - -------------------------------------------------------------------------------- via: https://www.ostechnix.com/coinmon-check-cryptocurrency-prices-commandline/ 作者:[SK][a] 译者:[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/) 荣誉推出 @@ -83,6 +88,6 @@ via: https://www.ostechnix.com/coinmon-check-cryptocurrency-prices-commandline/ [1]:https://www.ostechnix.com/cli-fyi-quick-easy-way-fetch-information-ips-emails-domains-lots/ [2]:https://coinmarketcap.com/ [3]:data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7 -[4]:http://www.ostechnix.com/wp-content/uploads/2017/11/coinmon-1.png () -[5]:http://www.ostechnix.com/wp-content/uploads/2017/11/coinmon-2.png () +[4]:http://www.ostechnix.com/wp-content/uploads/2017/11/coinmon-1.png +[5]:http://www.ostechnix.com/wp-content/uploads/2017/11/coinmon-2.png [6]:https://en.wikipedia.org/wiki/List_of_cryptocurrencies diff --git a/published/20171127 Migrating to Linux Disks Files and Filesystems.md b/published/201801/20171127 Migrating to Linux Disks Files and Filesystems.md similarity index 100% rename from published/20171127 Migrating to Linux Disks Files and Filesystems.md rename to published/201801/20171127 Migrating to Linux Disks Files and Filesystems.md diff --git a/published/20171128 A generic introduction to Gitlab CI.md b/published/201801/20171128 A generic introduction to Gitlab CI.md similarity index 100% rename from published/20171128 A generic introduction to Gitlab CI.md rename to published/201801/20171128 A generic introduction to Gitlab CI.md diff --git a/published/20171201 Launching an Open Source Project A Free Guide.md b/published/201801/20171201 Launching an Open Source Project A Free Guide.md similarity index 100% rename from published/20171201 Launching an Open Source Project A Free Guide.md rename to published/201801/20171201 Launching an Open Source Project A Free Guide.md diff --git a/published/20171205 How to Use the Date Command in Linux.md b/published/201801/20171205 How to Use the Date Command in Linux.md similarity index 100% rename from published/20171205 How to Use the Date Command in Linux.md rename to published/201801/20171205 How to Use the Date Command in Linux.md diff --git a/published/20171205 Using sudo to delegate permissions in Linux.md b/published/201801/20171205 Using sudo to delegate permissions in Linux.md similarity index 100% rename from published/20171205 Using sudo to delegate permissions in Linux.md rename to published/201801/20171205 Using sudo to delegate permissions in Linux.md diff --git a/published/20171207 Cheat – A Collection Of Practical Linux Command Examples.md b/published/201801/20171207 Cheat – A Collection Of Practical Linux Command Examples.md similarity index 100% rename from published/20171207 Cheat – A Collection Of Practical Linux Command Examples.md rename to published/201801/20171207 Cheat – A Collection Of Practical Linux Command Examples.md diff --git a/published/20171207 How To Find Files Based On their Permissions.md b/published/201801/20171207 How To Find Files Based On their Permissions.md similarity index 100% rename from published/20171207 How To Find Files Based On their Permissions.md rename to published/201801/20171207 How To Find Files Based On their Permissions.md diff --git a/published/20171212 How to Search PDF Files from the Terminal with pdfgrep.md b/published/201801/20171212 How to Search PDF Files from the Terminal with pdfgrep.md similarity index 100% rename from published/20171212 How to Search PDF Files from the Terminal with pdfgrep.md rename to published/201801/20171212 How to Search PDF Files from the Terminal with pdfgrep.md diff --git a/published/20171213 How To Allow-Permit User To Access A Specific File or Folder In Linux Using ACL.md b/published/201801/20171213 How To Allow-Permit User To Access A Specific File or Folder In Linux Using ACL.md similarity index 100% rename from published/20171213 How To Allow-Permit User To Access A Specific File or Folder In Linux Using ACL.md rename to published/201801/20171213 How To Allow-Permit User To Access A Specific File or Folder In Linux Using ACL.md diff --git a/published/20171214 A step-by-step guide to building open culture.md b/published/201801/20171214 A step-by-step guide to building open culture.md similarity index 100% rename from published/20171214 A step-by-step guide to building open culture.md rename to published/201801/20171214 A step-by-step guide to building open culture.md diff --git a/published/20171214 How to Install Moodle on Ubuntu 16.04.md b/published/201801/20171214 How to Install Moodle on Ubuntu 16.04.md similarity index 100% rename from published/20171214 How to Install Moodle on Ubuntu 16.04.md rename to published/201801/20171214 How to Install Moodle on Ubuntu 16.04.md diff --git a/published/20171214 How to squeeze the most out of Linux file compression.md b/published/201801/20171214 How to squeeze the most out of Linux file compression.md similarity index 100% rename from published/20171214 How to squeeze the most out of Linux file compression.md rename to published/201801/20171214 How to squeeze the most out of Linux file compression.md diff --git a/published/20171214 The Most Famous Classic Text-based Adventure Game.md b/published/201801/20171214 The Most Famous Classic Text-based Adventure Game.md similarity index 100% rename from published/20171214 The Most Famous Classic Text-based Adventure Game.md rename to published/201801/20171214 The Most Famous Classic Text-based Adventure Game.md diff --git a/published/20171215 5 of the Best Bitcoin Clients for Linux.md b/published/201801/20171215 5 of the Best Bitcoin Clients for Linux.md similarity index 100% rename from published/20171215 5 of the Best Bitcoin Clients for Linux.md rename to published/201801/20171215 5 of the Best Bitcoin Clients for Linux.md diff --git a/published/20171215 How to find and tar files into a tar ball.md b/published/201801/20171215 How to find and tar files into a tar ball.md similarity index 100% rename from published/20171215 How to find and tar files into a tar ball.md rename to published/201801/20171215 How to find and tar files into a tar ball.md diff --git a/published/20171216 Saving window position in Xfce session.md b/published/201801/20171216 Saving window position in Xfce session.md similarity index 100% rename from published/20171216 Saving window position in Xfce session.md rename to published/201801/20171216 Saving window position in Xfce session.md diff --git a/published/20171218 How to Create a .Desktop File For Your Application in Linux.md b/published/201801/20171218 How to Create a .Desktop File For Your Application in Linux.md similarity index 100% rename from published/20171218 How to Create a .Desktop File For Your Application in Linux.md rename to published/201801/20171218 How to Create a .Desktop File For Your Application in Linux.md diff --git a/published/201801/20171219 Migrating to Linux- Graphical Environments.md b/published/201801/20171219 Migrating to Linux- Graphical Environments.md new file mode 100644 index 0000000000..2a8991b8bf --- /dev/null +++ b/published/201801/20171219 Migrating to Linux- Graphical Environments.md @@ -0,0 +1,118 @@ +迁移到 Linux:图形操作环境 +====== + +![](https://www.linux.com/sites/lcom/files/styles/rendered_file/public/linux-migration_0.jpg?itok=0tviWTqd) + +> 这篇文章对 Linux 图形环境做了一番介绍,展示了在不同的 Linux 发行版上的各种选择。 + +这是我们迁移到 Linux 系统系列的第三篇文章。如果你错过了先前的两篇,这里有两文的链接《[入门介绍][1]》 和 《[磁盘、文件、和文件系统][2]》。本文中,我们将讨论图形操作环境。在 Linux 系统中,你可以依照喜好选择并且定制一个图形界面,你有很大的选择余地,这也是 Linux 优越的体验之一。 + +一些主流的 Linux 图形界面包括:Cinnamon、Gnome、KDE Plasma、Xfce 和 MATE,总之这里有很多选择。 + +有一点经常混淆 Linux 新手,虽然某个 Linux 系统分配了一个缺省的图形环境,但是一般你可以随时更换这个图形界面。这和 Windows 或 Mac OS 的惯用者的定势思维不同。安装图形环境是一件独立的事情,很多时候,Linux 和其图形环境的连接并不紧密。此外,你在一个图形环境构建运行的程序同样适用于另一个图形环境。比如说一个为 KDE Plasma 图形环境编写的应用程序完全适用于 Gnome 桌面图形环境。 + +由于人们熟悉 Windows 和 MacOS 系统,部分 Linux 操作系统的图形环境在一定程度上尝试着去模仿它们,但另一些 Linux 图形界面则是独特的。 + +下面,我将就一些不同的 Linux 发行版,展示几个 Linux 图形环境。如果你不确定应该采用那个 Linux 发行版,那我建议你从 [Ubuntu][3] 开始,获取其长期支持(LTS)的版本(Ubuntu 16.04.3 LTS 正在开发)。Ubuntu 稳定且真的非常好用。 + +### 由 Mac 过渡 + +Elementary OS 发行版提供了和 Mac 系统风格很接近的界面。它的默认图形环境被称作 Pantheon,是一款很适合 Mac 用户过渡使用的图形环境。这款图形界面发行版的屏幕底部有一个停靠栏,专为极简者使用而设计。为了保持简约的风格,很多默认的应用程序甚至都不会有自己的菜单。相反,它们的按钮和控件在应用程序的标题栏上(图 1)。 + +![Elementary OS][5] + +*图 1: Elementary OS Pantheon.* + +Ubuntu 发行版提供的一个默认的图形界面,也和 Mac 相似。Ubuntu 17.04 或者更老的版本都使用 Unity 图形环境,Unity 停靠栏的默认位置在屏幕的左边,屏幕顶部有一个全局应用程序共享的菜单栏。 + +### 由 Windows 过渡 + +ChaletOS 亦步亦趋模仿 Windows 界面,可以帮助 Windows 用户轻松的过渡到 Linux。ChaletOS 使用的图形环境是 Xfce(图 2)。在屏幕的左下角有一个开始(主)菜单和搜索栏。屏幕的右下角是一个桌面图标和一些通知信息。这看起来和 Windows 非常像,乍一看,可能都会以为桌面跑的是 Windows。 + +![ChaletOS][6] + +*图 2: ChaletOS with Xfce.* + +Zorin OS 发行版同样尝试模仿 Windows。 Zorin OS 使用的 Gnome 的改进桌面,工作起来和 Windows 的图形界面很相似。左下角的开始按钮、右下角的通知栏和信息通知栏。开始按钮会弹出一个和 Windows 无异的应用程序列表和搜索框。 + +### 独有的图形环境 + +Gnome 桌面(图 3)是最常用的图形环境之一。许多发行版将 Gnome 作为默认的图形环境。Gnome 并不打算模仿 Windows 或是 MacOS,而是以其自身的优雅和易用为目标。 + +![][7] + +*图 3:openSUSE with Gnome.* + +Gnome 桌面环境从版本 2 到 版本 3 发生了巨变,Cinnamon 环境为消除该改变带来的不利影响而创造。尽管 Cinnamon 和前辈 Gnome 2 外观不相似,但是它依旧尝试提供一个简约的界面,而且它的功能和 Windows XP 类似。 + +MATE 图形环境直接模仿于 Gnome 2,在它的屏幕顶部有一个用作设置和存放应用的菜单栏,底部提供了一个应用程序运行选项卡和一些其他组件。 + +KDE plasma 围绕组件界面而构建,组件可以安装在桌面或是面板上(图 4)。 + +![KDE Plasma][8] + +*图 4: 安装了 KDE Plasma 的 Kubuntu 操作系统。* + +没有那个图形环境比另外一个更好。不同的风格适用不同的用户风格。另外,如果选择太多无从下手,那就从 [Ubuntu][3] 开始吧。 + +### 相似与不同 + +不同的操作系统处理方式不同,这会给使用者的过渡带来挑战。比如说,菜单栏可能出现在不同的位置,然后设置有可能用不同的选项入口路径。我列举了一些相似或不同地方来帮助减少 Linux 调整。 + +#### 鼠标 + +Linux 的鼠标通常和 Windows 与 MacOS 的工作方式有所差异。在 Windows 或 Mac,双击标签,你几乎可以打开任何事物,而这在 Linux 图形界面中很多都被设置为单击。 + +此外在 Windows 系统中,你通常通过单击窗口获取焦点。在 Linux,很多窗口的焦点获取方式被设置为鼠标悬停,即便鼠标悬停下的窗口并不在屏幕顶端。这种微妙的差异有时候会让人很吃惊。比如说,在 Windows 中,假如有一个后台应用(不在屏幕顶层),你移动鼠标到它的上面,不点击鼠标仅仅转动鼠标滚轮,顶层窗口会滚动。而在 Linux 中,后台窗口(鼠标悬停的那个窗口)会滚动。 + +#### 菜单 + +应用菜单是电脑程序的一个主要集中位置,最近似乎可以调整移动菜单栏到不碍事的地方,甚至干脆完全删除。大概,当你迁移到 Linux,你可能找不到你期待的菜单。应用程序菜单会像 MacOS一样出现在全局共享菜单栏内。和很多移动应用程序一样,该菜单可能在“更多选项”的图标里。或者,这个菜单干脆被完全移除被一个按钮取代,正如在 Elementary OS Pantheon 环境里的一些程序一样。 + +#### 工作空间 + +很多 Linux 图形环境提供了多个工作空间。一个工作空间包含的正在运行的程序窗口充盈了整个屏幕。切换到不同的工作空间将会改变程序的可见性。这个概念是把当前项目运行使用的全部应用程序分组到一个工作空间,而一些为另一个项目使用的应用程序会被分组到不同的工作空间。 + +不是每一个人都需要甚至是喜欢工作空间,但是我提到它是因为,作为一个新手,你可能无意间通过一个组合键切换了工作空间,然后,“喂!我的应用程序哪去了?” 如果你看到的还是你熟悉的桌面壁纸,那你可能只是切换了工作空间,你所有的应用程序还在一个工作空间运行,只是现在不可见而已。在很多 Linux 环境中,通过敲击 `Alt+Ctrl` 和一个箭头(上、下、左或右)可以切换工作空间。很有可能发现你的应用程序一直都在另一个工作空间里运行。 + +当然,如果你刚好喜欢工作空间(很多人都喜欢),然后你就发现了一个 Linux 很有用的默认功能。 + +#### 设置 + +许多 Linux 图形环境提供一些类型的设置程序或是面板让你在机器上配置设置。值得注意的是类似 Windows 和 MacOS,Linux 可以配置好很多细节,但不是所有的详细设置都可以在设置程序上找到。但是这些设置项已经足够满足大部分典型的桌面系统,比如选择桌面壁纸,改变熄屏时间,连接打印机等其他一些设置。 + +和 Windows 或者 MacOS 相比,Linux 的应用程序设置的分组或是命名都有不同的方式。甚至同是 Linux 系统,不同的图形界面也会出现不同的设置,这可能需要时间适应。当然,在你的图形环境中设置配置的问题可以通过在线查询这样不错的方法解决。 + +#### 应用程序 + +最后,Linux 的应用程序也可能不同。你可能会发现一些熟悉的应用程序,但是对你来说更多的将会是崭新的应用。比如说,你能在 Linux 上找到 Firefox、Chrome 和 Skype。如果不能找到特定的应用程序,通常你能使用一些替代程序。如果还是不能,那你可以使用 WINE 这样的兼容层来运行 Windows 的应用程序。 + +在很多 Linux 图形环境中,你可以通过敲击 Windows 的标志键来打开应用程序菜单栏。在其他一些情况中,你不得不点击开始(主)按钮或应用程序菜单。很多图形环境中,你可以通过分类搜索到应用程序而不一定需要它的特定程序名。比如说,你要使用一个你不清楚名字的编辑器程序,这时候,你可以在应用程序菜单栏键的搜索框中键入“editor”字样,它将为你展示一个甚至更多的被认为是编辑器类的应用程序。 + +为帮你起步,这里列举了一点可能成为 Linux 系统使用的替代程序。 + +![linux][10] + +请注意,Linux 提供了大量的满足你需求的选择,这张表里列举的一点也不完整。 + +-------------------------------------------------------------------------------- + +via: https://www.linux.com/blog/learn/2017/12/migrating-linux-graphical-environments + +作者:[John Bonesio][a] +译者:[CYLeft](https://github.com/CYLeft) +校对:[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://www.evernote.com/OutboundRedirect.action?dest=https%3A%2F%2Fwww.ubuntu.com%2Fdownload%2Fdesktop +[5]:https://www.linux.com/sites/lcom/files/styles/rendered_file/public/elementaryos.png?itok=kJk2-BsL (Elementary OS) +[6]:https://www.linux.com/sites/lcom/files/styles/rendered_file/public/chaletos.png?itok=Zdm2rRgu +[7]:https://www.linux.com/sites/lcom/files/styles/rendered_file/public/opensuse.png?itok=TM0Q9AyH +[8]:https://www.linux.com/sites/lcom/files/styles/rendered_file/public/kubuntu.png?itok=a2E7ttaa (KDE Plasma) +[9]:https://training.linuxfoundation.org/linux-courses/system-administration-training/introduction-to-linux + +[10]: https://www.linux.com/sites/lcom/files/styles/rendered_file/public/linux-options.png?itok=lkqD1UMj diff --git a/published/20171219 Surf anonymously- Learn to install TOR network on Linux.md b/published/201801/20171219 Surf anonymously- Learn to install TOR network on Linux.md similarity index 100% rename from published/20171219 Surf anonymously- Learn to install TOR network on Linux.md rename to published/201801/20171219 Surf anonymously- Learn to install TOR network on Linux.md diff --git a/published/20171219 The Linux commands you should NEVER use.md b/published/201801/20171219 The Linux commands you should NEVER use.md similarity index 100% rename from published/20171219 The Linux commands you should NEVER use.md rename to published/201801/20171219 The Linux commands you should NEVER use.md diff --git a/published/20171220 The current state of kernel page-table isolation.md b/published/201801/20171220 The current state of kernel page-table isolation.md similarity index 100% rename from published/20171220 The current state of kernel page-table isolation.md rename to published/201801/20171220 The current state of kernel page-table isolation.md diff --git a/published/20171226 Check Linux filesystem for errors- FSCK command with examples.md b/published/201801/20171226 Check Linux filesystem for errors- FSCK command with examples.md similarity index 100% rename from published/20171226 Check Linux filesystem for errors- FSCK command with examples.md rename to published/201801/20171226 Check Linux filesystem for errors- FSCK command with examples.md diff --git a/published/20171226 How to Configure Linux for Children.md b/published/201801/20171226 How to Configure Linux for Children.md similarity index 100% rename from published/20171226 How to Configure Linux for Children.md rename to published/201801/20171226 How to Configure Linux for Children.md diff --git a/published/20171226 How to use-run bash aliases over ssh based session.md b/published/201801/20171226 How to use-run bash aliases over ssh based session.md similarity index 100% rename from published/20171226 How to use-run bash aliases over ssh based session.md rename to published/201801/20171226 How to use-run bash aliases over ssh based session.md diff --git a/published/20171227 Best Programming Languages To Learn In 2018.md b/published/201801/20171227 Best Programming Languages To Learn In 2018.md similarity index 100% rename from published/20171227 Best Programming Languages To Learn In 2018.md rename to published/201801/20171227 Best Programming Languages To Learn In 2018.md diff --git a/published/201801/20171228 How to exclude file when using scp command recursively.md b/published/201801/20171228 How to exclude file when using scp command recursively.md new file mode 100644 index 0000000000..20523b6c7c --- /dev/null +++ b/published/201801/20171228 How to exclude file when using scp command recursively.md @@ -0,0 +1,102 @@ +如何在使用 scp 命令时递归地排除文件 +====== + +Q:我需要将所有包含 *.c 文件的文件夹从名为 hostA 的本地笔记本复制到 hostB。我使用的是下面的 `scp` 命令,但不知道如何排除特定的文件(如 *.out): + +``` +$ scp -r ~/projects/ user@hostB:/home/delta/projects/ +``` + +如何告诉 `scp` 命令在 Linux/Unix 命令行中排除特定的文件或目录? + +人们可以使用 `scp` 命令在网络主机之间安全地复制文件。它使用 ssh 进行数据传输和身份验证。典型的语法是: + +``` +scp file1 user@host:/path/to/dest/ +scp -r /path/to/source/ user@host:/path/to/dest/ +``` + +### scp 排除文件 + +我不认为你可以在使用 scp 命令时过滤或排除文件。但是,有一个很好的解决方法来排除文件并使用 ssh 安全地复制它。本页面说明如何在使用 `scp` 递归复制目录时过滤或排除文件。 + +### 如何使用 rsync 命令排除文件 + +语法是: + +``` +rsync av -e ssh --exclude='*.out' /path/to/source/ user@hostB:/path/to/dest/ +``` + +这里: + +1. `-a` :递归到目录,即复制所有文件和子目录。另外,打开归档模式和所有其他选项(相当于 `-rlptgoD`) +2. `-v` :详细输出 +3. `-e ssh` :使用 ssh 作为远程 shell,这样所有的东西都被加密 +4. `--exclude='*.out'` :排除匹配模式的文件,例如 *.out 或 *.c 等。 + + +### rsync 命令的例子 + +在这个例子中,从 `~/virt/` 目录递归地复制所有文件,但排除所有 *.new 文件: + +``` +$ rsync -av -e ssh --exclude='*.new' ~/virt/ root@centos7:/tmp +``` + +示例输出: + +[![Scp exclude files but using rsync exclude command][2]][2] + +如果远程服务器上找不到 `rsync`,那么 `rsync` 命令将失败。在这种情况下,请尝试使用以下 `scp` 命令,该命令在当前目录中使用 [bash shell 模式匹配] [3] (它不能与 `-r` 选项一起使用): + +``` +$ ls +``` + +示例输出: + +``` +centos71.log centos71.qcow2 centos71.qcow2.new centos71.v2.qcow2.new meta-data user-data +``` + +复制除 .new 之外的当前目录中的所有内容: + +``` +$ shopt -s extglob +$ scp !(*.new) root@centos7:/tmp/ +``` + +示例输出: + +``` +centos71.log 100 % 4262 1.3MB/s 00:00 +centos71.qcow2 100 % 836MB 32.7MB/s 00: 25 +meta-data 100 % 47 18.5KB/s 00:00 +user-data 100 % 1543 569.7KB/s 00:00 +``` + +有关更多信息,请参阅以下手册页: + +``` +$ man rsync +$ man bash +$ man scp +``` + +-------------------------------------------------------------------------------- + +via: https://www.cyberciti.biz/faq/scp-exclude-files-when-using-command-recursively-on-unix-linux/ + +作者:[Vivek Gite][a] +译者:[geekpi](https://github.com/geekpi) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.cyberciti.biz +[1]:https://www.cyberciti.biz/cdn-cgi/l/email-protection +[2]:https://www.cyberciti.biz/media/new/faq/2017/12/scp-exclude-files-on-linux-unix-macos-bash-shell-command-line.jpg +[3]:https://www.gnu.org/software/bash/manual/html_node/Pattern-Matching.html#Pattern-Matching +[4]:https://www.samba.org/ftp/rsync/rsync.html +[5]:https://man.openbsd.org/scp diff --git a/published/20171229 Set Ubuntu Derivatives Back to Default with Resetter.md b/published/201801/20171229 Set Ubuntu Derivatives Back to Default with Resetter.md similarity index 100% rename from published/20171229 Set Ubuntu Derivatives Back to Default with Resetter.md rename to published/201801/20171229 Set Ubuntu Derivatives Back to Default with Resetter.md diff --git a/published/20171230 How To Sync Time Between Linux And Windows Dual Boot.md b/published/201801/20171230 How To Sync Time Between Linux And Windows Dual Boot.md similarity index 100% rename from published/20171230 How To Sync Time Between Linux And Windows Dual Boot.md rename to published/201801/20171230 How To Sync Time Between Linux And Windows Dual Boot.md diff --git a/published/20180101 The mysterious case of the Linux Page Table Isolation patches.md b/published/201801/20180101 The mysterious case of the Linux Page Table Isolation patches.md similarity index 100% rename from published/20180101 The mysterious case of the Linux Page Table Isolation patches.md rename to published/201801/20180101 The mysterious case of the Linux Page Table Isolation patches.md diff --git a/published/201801/20180103 Linux-Unix desktop fun- Simulates the display from -The Matrix.md b/published/201801/20180103 Linux-Unix desktop fun- Simulates the display from -The Matrix.md new file mode 100644 index 0000000000..14efe969de --- /dev/null +++ b/published/201801/20180103 Linux-Unix desktop fun- Simulates the display from -The Matrix.md @@ -0,0 +1,139 @@ +Linux/Unix 桌面盛典:模仿 “黑客帝国” 界面! +====== + +《黑客帝国》是 1999 年,由 Wachowki 兄弟编导的科幻动作片。这部电影的荧屏里有无尽的绿色字符降落。数字雨模拟着《黑客帝国》中的虚拟现实活动。现在,Linux 和 Unix 终端上,你也可以通过 CMatrix 模仿出矩阵数字雨。 + +### 安装 cmatrix + +根据你的 Linux/Unix 发行版或操作系统安装并且设置 CMatrix。 + +#### 如何在 Debian/Ubuntu Linux 发行版中安装 cmatrix + +在 Debian/Ubuntu/Mint 系统中键入以下命令 [apt-get 命令][1]/[apt 命令][2]: + +``` +$ sudo apt install cmatrix +``` + +示例输出: + +``` +[sudo] password for vivek: +Reading package lists... Done +Building dependency tree +Reading state information... Done +Suggested packages: + cmatrix-xfont +The following NEW packages will be installed: + cmatrix +0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded. +Need to get 15.8 kB of archives. +After this operation, 50.2 kB of additional disk space will be used. +Get:1 http://in.archive.ubuntu.com/ubuntu artful/universe amd64 cmatrix amd64 1.2a-5build2 [15.8 kB] +Fetched 15.8 kB in 0s (19.7 kB/s) +Selecting previously unselected package cmatrix. +(Reading database ... 205388 files and directories currently installed.) +Preparing to unpack .../cmatrix_1.2a-5build2_amd64.deb ... +Unpacking cmatrix (1.2a-5build2) ... +Setting up cmatrix (1.2a-5build2) ... +Processing triggers for man-db (2.7.6.1-2) ... +``` + +#### 如何在 Arch Linux 发行版安装 cmatrix + +键入 pacman 命令: + +``` +$ sudo pacman -S cmatrix +``` + +#### 如何在 FreeBCD 系统中安装 cmatrix + +运行如下命令安装 port: + +``` +# cd /usr/ports/misc/cmatrix/ && make install clean +``` + +或者使用 pkg 命令添加二进制包: + +``` +# pkg install cmatrix +``` + +#### 如何在 macOS Unix 发行版中安装 cmatrix + +键入下列命令: + +``` +$ brew install cmatrix +``` + +#### 如何在 OpenBSD 系统中安装 cmatrix + +键入 pkg_add 命令: + +``` +# pkg_add cmatrix +``` + +### 使用 cmatrix + +简单键入命令: + +``` +$ cmatrix +``` + +[![cmtarix 运转中][3]][3] + +#### 使用键盘 + +在执行期间,下列按键有效(`-s` 模式下,按键无效): + +| 按键 | 说明 | +|---|---| +| `a` | 切换异步滚动 | +| `b` | 随机字符加粗 | +| `B` | 全部字符加粗 | +| `n` | 关闭字符加粗 | +| `0`-`9` | 调整更新时间 | +| `!` `@` `#` `$` `%` `^` `&` `)` | 改变对应的矩阵颜色: `!` – 红、`@` – 绿、`#` – 黄、`$` – 蓝、`%` – 洋红、`^` – 青、 `&` – 白、 `)` – 黑。 | +| `q` | 退出程序 | + +你可以通过以下命令获取 cmatrix 选项: + +``` +$ cmatrix -h +``` + +- `-a`: 异步滚动 +- `-b`: 开启字符加粗 +- `-B`: 所有字符加粗(优先于 -b 选项) +- `-f`: 强制开启 Linux $TERM 模式 +- `-l`: Linux 模式(使用 matrix 控制台字体) +- `-o`: 启用旧式滚动 +- `-h`: 输出使用说明并退出 +- `-n`: 关闭字符加粗 (优先于 -b and -B,默认) +- `-s`: “屏保”模式, 第一次按键时退出 +- `-x`: X 窗口模式,如果你使用的时 mtx.pcf 终端 +- `-V`: 输出版本信息并且退出 +- `-u delay` (0 - 10,默认 4): 屏幕更新延时 +- `-C [color]`: 调整 matrix 颜色(默认绿色) + +现在,你拥有了一款最炫酷的终端应用! + +-------------------------------------------------------------------------------- + +via: https://www.cyberciti.biz/open-source/command-line-hacks/matrix-digital-rain-on-linux-macos-unix-terminal/ + +作者:[nixCraft][a] +译者:[CYLeft](https://github.com/CYLeft) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.cyberciti.biz +[1]:https://www.cyberciti.biz/tips/linux-debian-package-management-cheat-sheet.html (See Linux/Unix apt-get command examples for more info) +[2]:https://www.cyberciti.biz/faq/ubuntu-lts-debian-linux-apt-command-examples/ (See Linux/Unix apt command examples for more info) +[3]:https://www.cyberciti.biz/media/new/cms/2018/01/small-cmtarix-file.gif diff --git a/published/20180104 4 artificial intelligence trends to watch.md b/published/201801/20180104 4 artificial intelligence trends to watch.md similarity index 100% rename from published/20180104 4 artificial intelligence trends to watch.md rename to published/201801/20180104 4 artificial intelligence trends to watch.md diff --git a/published/20180105 yum find out path where is package installed to on CentOS-RHEL.md b/published/201801/20180105 yum find out path where is package installed to on CentOS-RHEL.md similarity index 100% rename from published/20180105 yum find out path where is package installed to on CentOS-RHEL.md rename to published/201801/20180105 yum find out path where is package installed to on CentOS-RHEL.md diff --git a/published/20180112 City of Barcelona Kicks Out Microsoft in Favor of Linux and Open Source.md b/published/201801/20180112 City of Barcelona Kicks Out Microsoft in Favor of Linux and Open Source.md similarity index 100% rename from published/20180112 City of Barcelona Kicks Out Microsoft in Favor of Linux and Open Source.md rename to published/201801/20180112 City of Barcelona Kicks Out Microsoft in Favor of Linux and Open Source.md diff --git a/published/20180119 No More Ubuntu Debian is the New Choice For Googles In-house Linux Distribution.md b/published/201801/20180119 No More Ubuntu Debian is the New Choice For Googles In-house Linux Distribution.md similarity index 100% rename from published/20180119 No More Ubuntu Debian is the New Choice For Googles In-house Linux Distribution.md rename to published/201801/20180119 No More Ubuntu Debian is the New Choice For Googles In-house Linux Distribution.md diff --git a/published/201801/20180123 What Is bashrc and Why Should You Edit It.md b/published/201801/20180123 What Is bashrc and Why Should You Edit It.md new file mode 100644 index 0000000000..0b80202140 --- /dev/null +++ b/published/201801/20180123 What Is bashrc and Why Should You Edit It.md @@ -0,0 +1,113 @@ +什么是 .bashrc,为什么要编辑 .bashrc? +====== + +![](https://www.maketecheasier.com/assets/uploads/2018/01/what-is-bashrc-hero.png) + +你的 home 目录下藏着很多隐藏文件。如果你在运行 macOS 或者主流的 Linux 发行版的话,你就会在靠近隐藏文件列表的上方看见一个名为 `.bashrc` 的文件。那么什么是 `.bashrc`,编辑 `.bashrc` 又有什么用呢? + +![finder-find-bashrc][1] + +如果你运行一个基于 Unix 或者类 Unix 的操作系统,bash 很有可能是作为默认终端被安装的。虽然存在很多[不同的 shell][2],bash 却是最常见或许也是最主流的。如果你不明白那意味着什么,bash 是一个能解释你输入进终端程序的东西,并且基于你的输入来运行命令。它在一定程度上支持使用脚本来定制功能,这时候就要用到 `.bashrc` 了。 + +为了加载你的配置,bash 在每次启动时都会加载 `.bashrc` 文件的内容。每个用户的 home 目录都有这个 shell 脚本。它用来存储并加载你的终端配置和环境变量。 + +终端配置可以包含很多不同的东西。最常见的,`.bashrc` 文件包含用户想要用的别名。别名允许用户通过更短的名字或替代的名字来指向命令,对于经常在终端下工作的人来说这可是一个省时利器。 + +![terminal-edit-bashrc-1][3] + +你可以在任何终端文本编辑器上编辑 `.bashrc`。在接下来的例子中我们将使用 `nano`。 + +要使用 `nano` 来编辑 `.bashrc`,在终端中调用以下命令: + +``` +nano ~/.bashrc +``` + +如果你之前从没有编辑过 `.bashrc` 的话,你也许会发现它是空的。这没关系!如果不是的话,你可以随意在任一行添加你的配置。 + +你对 bashrc 所做的任何修改将在下一次启动终端时生效。如果你想立刻生效的话,运行下面的命令: + +``` +source ~/.bashrc +``` + +你可以添加到任何 `.bashrc` 的位置,随意使用命令(通过 `#`)来组织你的代码。 + +编辑 `.bashrc` 需要遵循 [bash 脚本格式][4]。如果你不知道如何用 bash 编写脚本的话,有很多在线资料可供查阅。这是一本相当全面的[介绍指南][5],包含一些我们没能在这里提及的 bashrc 的方面。 + +**相关**: [如何在 Linux 启动时以 root 权限运行 bash 脚本][6] + +有一些有用的小技巧能使你的终端体验将更高效,也更用户友好。 + +### 为什么我要编辑 bashrc ? + +#### Bash 提示符 + +bash 提示符允许你自定义你的终端,并让它在你运行命令时显示提示。自定义的 bash 提示符着实能提高你在终端的工作效率。 + +看看这些即[有用][7]又[有趣][8]的 bash 提示符,你可以把它们添加到你的 `.bashrc` 里。 + +#### 别名 + +![terminal-edit-bashrc-3][9] + +别名允许你使用简写的代码来执行你想要的某种格式的某个命令。让我们用 `ls` 命令来举个例子吧。`ls` 命令默认显示你目录里的内容。这挺有用的,不过显示目录的更多信息,或者显示目录下的隐藏内容,往往更加有用。因此,有个常见的别名就是 `ll`,用来运行 `ls -lha` 或者其他类似的命令。这样就能显示文件的大部分信息,找出隐藏的文件,并能以“能被人类阅读”的单位显示文件大小,而不是用“块”作为单位。 + +你需要按照下面这样的格式书写别名: + +``` +alias ll = "ls -lha" +``` + +左边输入你想设置的别名,右边引号里是要执行的命令。你可以用这种方法来创建命令的短版本,防止出现常见的拼写错误,或者让一个命令总是带上你想要的参数来运行。你也可以用你喜欢的缩写来规避讨厌或容易忘记的语法。这是一些[常见的别名的用法][10],你可以添加到你的 `.bashrc` 里。 + +#### 函数 + +![terminal-edit-bashrc-2][11] + +除了缩短命令名,你也可以用 bash 函数组合多个命令到一个操作。这些命令可以很复杂,但是它们大多遵循这种语法: + +``` +function_name () { + command_1 + command_2 +} +``` + +下面的命令组合了 `mkdir` 和 `cd` 命令。输入 `md folder_name` 可以在你的工作目录创建一个名为“folder_name”的目录并立刻导航进入。 + +``` +md () { + mkdir -p $1 + cd $1 +} +``` + +如你所见,函数中的 `$1` 代表第一个参数,就是你在函数名后紧跟着输入的文本。 + +### 总结 + +不像某些自定义终端的方法,变动 bashrc 是非常直接且低风险的。即使你一不小心全搞砸了,你也可以随时删掉 bashrc 文件然后重新来一遍。试试看吧,你会惊叹于你提高的生产力的。 + +-------------------------------------------------------------------------------- + +via: https://www.maketecheasier.com/what-is-bashrc/ + +作者:[Alexander Fox][a] +译者:[heart4lor](https://github.com/heart4lor) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.maketecheasier.com/author/alexfox/ +[1]:https://www.maketecheasier.com/assets/uploads/2018/01/finder-find-bashrc.png "finder-find-bashrc" +[2]:https://www.maketecheasier.com/alternative-linux-shells/ +[3]:https://www.maketecheasier.com/assets/uploads/2018/01/terminal-edit-bashrc-1.png "terminal-edit-bashrc-1" +[4]:http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html +[5]:https://www.digitalocean.com/community/tutorials/an-introduction-to-useful-bash-aliases-and-functions +[6]:https://www.maketecheasier.com/run-bash-script-as-root-during-startup-linux/ "How to Run Bash Script as Root During Startup on Linux" +[7]:https://www.maketecheasier.com/8-useful-and-interesting-bash-prompts/ +[8]:https://www.maketecheasier.com/more-useful-and-interesting-bash-prompts/ +[9]:https://www.maketecheasier.com/assets/uploads/2018/01/terminal-edit-bashrc-3.png "terminal-edit-bashrc-3" +[10]:https://www.maketecheasier.com/install-software-in-various-linux-distros/#aliases +[11]:https://www.maketecheasier.com/assets/uploads/2018/01/terminal-edit-bashrc-2.png "terminal-edit-bashrc-2" diff --git a/published/20180103 Creating an Offline YUM repository for LAN.md b/published/20180103 Creating an Offline YUM repository for LAN.md new file mode 100644 index 0000000000..5a0695cb97 --- /dev/null +++ b/published/20180103 Creating an Offline YUM repository for LAN.md @@ -0,0 +1,106 @@ +创建局域网内的离线 Yum 仓库 +====== + +在早先的教程中,我们讨论了[如何使用 ISO 镜像和在线 Yum 仓库的方式来创建自己的 Yum 仓库 ][1]。创建自己的 Yum 仓库是一个不错的想法,但若网络中只有 2-3 台 Linux 机器那就没啥必要了。不过若你的网络中有大量的 Linux 服务器,而且这些服务器还需要定时进行升级,或者你有大量服务器无法直接访问互联网,那么创建自己的 Yum 仓库就很有必要了。 + +当我们有大量的 Linux 服务器,而每个服务器都直接从互联网上升级系统时,数据消耗会很可观。为了节省数据量,我们可以创建个离线 Yum 源并将之分享到本地网络中。网络中的其他 Linux 机器就可以直接从本地 Yum 上获取系统更新,从而节省数据量,而且传输速度也会很好。 + +我们可以使用下面两种方法来分享 Yum 仓库: + +* 使用 Web 服务器(Apache) +* 使用 FTP 服务器(VSFTPD) + +在开始讲解这两个方法之前,我们需要先根据[之前的教程][1]创建一个 Yum 仓库。 + +### 使用 Web 服务器 + +首先在 Yum 服务器上安装 Web 服务器(Apache),我们假设服务器 IP 是 `192.168.1.100`。我们已经在这台系统上配置好了 Yum 仓库,现在我们来使用 `yum` 命令安装 Apache Web 服务器, + +``` +$ yum install httpd +``` + +下一步,拷贝所有的 rpm 包到默认的 Apache 根目录下,即 `/var/www/html`,由于我们已经将包都拷贝到了 `/YUM` 下,我们也可以创建一个软连接来从 `/var/www/html` 指向 `/YUM`。 + +``` +$ ln -s /var/www/html/Centos /YUM +``` + +重启 Web 服务器应用改变: + +``` +$ systemctl restart httpd +``` + +#### 配置客户端机器 + +服务端的配置就完成了,现在需要配置下客户端来从我们创建的离线 Yum 中获取升级包,这里假设客户端 IP 为 `192.168.1.101`。 + +在 `/etc/yum.repos.d` 目录中创建 `offline-yum.repo` 文件,输入如下信息, + +``` +$ vi /etc/yum.repos.d/offline-yum.repo +``` + +``` +name=Local YUM +baseurl=http://192.168.1.100/CentOS/7 +gpgcheck=0 +enabled=1 +``` + +客户端也配置完了。试一下用 `yum` 来安装/升级软件包来确认仓库是正常工作的。 + +### 使用 FTP 服务器 + +在 FTP 上分享 Yum,首先需要安装所需要的软件包,即 vsftpd。 + +``` +$ yum install vsftpd +``` + +vsftp 的默认根目录为 `/var/ftp/pub`,因此你可以拷贝 rpm 包到这个目录,或者为它创建一个软连接: + +``` +$ ln -s /var/ftp/pub /YUM +``` + +重启服务应用改变: + +``` +$ systemctl restart vsftpd +``` + +#### 配置客户端机器 + +像上面一样,在 `/etc/yum.repos.d` 中创建 `offline-yum.repo` 文件,并输入下面信息, + +``` +$ vi /etc/yum.repos.d/offline-yum.repo +``` + +``` +[Offline YUM] +name=Local YUM +baseurl=ftp://192.168.1.100/pub/CentOS/7 +gpgcheck=0 +enabled=1 +``` + +现在客户机可以通过 ftp 接收升级了。要配置 vsftpd 服务器为其他 Linux 系统分享文件,请[阅读这篇指南][2]。 + +这两种方法都很不错,你可以任意选择其中一种方法。有任何疑问或这想说的话,欢迎在下面留言框中留言。 + +-------------------------------------------------------------------------------- + +via: http://linuxtechlab.com/offline-yum-repository-for-lan/ + +作者:[Shusain][a] +译者:[lujun9972](https://github.com/lujun9972) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:http://linuxtechlab.com/author/shsuain/ +[1]:https://linux.cn/article-9296-1.html +[2]:http://linuxtechlab.com/ftp-secure-installation-configuration/ diff --git a/published/20180111 Multimedia Apps for the Linux Console.md b/published/20180111 Multimedia Apps for the Linux Console.md new file mode 100644 index 0000000000..fde4ea0470 --- /dev/null +++ b/published/20180111 Multimedia Apps for the Linux Console.md @@ -0,0 +1,116 @@ +Linux 终端下的多媒体应用 +====== + +![](https://www.linux.com/sites/lcom/files/styles/rendered_file/public/multimedia.jpg?itok=v-XrnKRB) + +> Linux 终端是支持多媒体的,所以你可以在终端里听音乐,看电影,看图片,甚至是阅读 PDF。 + +在我的上一篇文章里,我们了解到 Linux 终端是可以支持多媒体的。是的,这是真的!你可以使用 Mplayer、fbi 和 fbgs 来实现不打开 X 会话就听音乐、看电影、看照片,甚至阅读 PDF。此外,你还可以通过 CMatrix 来体验黑客帝国(Matrix)风格的屏幕保护。 + +不过你可能需要对系统进行一些修改才能达到前面这些目的。下文的操作都是在 Ubuntu 16.04 上进行的。 + +### MPlayer + +你可能会比较熟悉功能丰富的 MPlayer。它支持几乎所有格式的视频与音频,并且能在绝大部分现有的平台上运行,像 Linux、Android、Windows、Mac、Kindle、OS/2 甚至是 AmigaOS。不过,要在你的终端运行 MPlayer 可能需要多做一点工作,这些工作与你使用的 Linux 发行版有关。来,我们先试着播放一个视频: + +``` +$ mplayer [视频文件名] +``` + +如果上面的命令正常执行了,那么很好,接下来你可以把时间放在了解 MPlayer 的常用选项上了,譬如设定视频大小等。但是,有些 Linux 发行版在对帧缓冲framebuffer的处理方式上与早期的不同,那么你就需要进行一些额外的设置才能让其正常工作了。下面是在最近的 Ubuntu 发行版上需要做的一些操作。 + +首先,将你自己添加到 `video` 用户组。 + +其次,确认 `/etc/modprobe.d/blacklist-framebuffer.conf` 文件中包含这样一行:`#blacklist vesafb`。这一行应该默认被注释掉了,如果不是的话,那就手动把它注释掉。此外的其他模块行需要确认没有被注释,这样设置才能保证其他那些模块不会被载入。注:如果你想要更深入的利用帧缓冲framebuffer,这些针对你的显卡的模块可以使你获得更好的性能。 + +然后,在 `/etc/initramfs-tools/modules` 的结尾增加两个模块:`vesafb` 和 `fbcon`,并且更新 iniramfs 镜像: + +``` +$ sudo nano /etc/initramfs-tools/modules + # List of modules that you want to include in your initramfs. + # They will be loaded at boot time in the order below. + fbcon + vesafb + +$ sudo update-initramfs -u +``` + +[fbcon][1] 是 Linux 帧缓冲framebuffer终端,它运行在帧缓冲framebuffer之上并为其增加图形功能。而它需要一个帧缓冲framebuffer设备,这则是由 `vesafb` 模块来提供的。 + +接下来,你需要修改你的 GRUB2 配置。在 `/etc/default/grub` 中你将会看到类似下面的一行: + +``` +GRUB_CMDLINE_LINUX_DEFAULT="quiet splash" +``` + +它也可能还会有一些别的参数,不用管它,在其后加上 `vga=789`: + +``` +GRUB_CMDLINE_LINUX_DEFAULT="quiet splash vga=789" +``` + +重启之后进入你的终端(`Ctrl+Alt+F1`)(LCTT 译注:在某些发行版中 `Ctrl+Alt+F1` 默认为图形界面,可以尝试 `Ctrl+Alt+F2`),然后就可以尝试播放一个视频了。下面的命令指定了 `fbdev2` 为视频输出设备,虽然我还没弄明白如何去选择用哪个输入设备,但是我用它成功过。默认的视频大小是 320x240,在此我给缩放到了 960: + +``` +$ mplayer -vo fbdev2 -vf scale -zoom -xy 960 AlienSong_mp4.mov +``` + +来看图 1。粗糙的画面是由于我原视频的质量不高,而不是 MPlayer 的显示问题。 + +![图 1 播放视频](https://www.linux.com/sites/lcom/files/styles/floated_images/public/fig-1_3.jpg?itok=PtSoKepn) + +MPlayer 可以播放 CD、DVD 以及网络视频流,并且还有一系列的回放选项,这些将作为作业留给大家自己去发现。 + +### fbi 图片查看器 + +`fbi` 是一个帧缓冲图片查看器。在大部分的 Linux 发行版中,它被包含在 [fbida][2] 包里。它原生支持一些常见的图片格式,而如果你安装了 `convert`(来自于 Image Magick),那么它还能借此打开一些其他格式。最简单的用法是用来查看一个图片文件: + +``` +$ fbi 文件名 +``` + +你可以使用方向键来在大图片中移动视野,使用 `+` 和 `-` 来缩放,或者使用 `r` 或 `l` 来向右或向左旋转 90 度。`Escape` 键则可以关闭查看的图片。此外,你还可以给 `fbi` 一个文件列表来实现幻灯播放: + +``` +$ fbi --list 文件列表.txt +``` + +`fbi` 还支持自动缩放。还可以使用 `-a` 选项来控制缩放比例。`--autoup` 和 `--autodown` 则是用于告知 `fbi` 只进行放大或者缩小。要调整图片切换时淡入淡出的时间则可以使用 `--blend [时间]` 来指定一个以毫秒为单位的时间长度。使用 `k` 和 `j` 键则可以切换文件列表中的上一张或下一张图片。 + +`fbi` 还提供了命令来为你浏览过的文件创建文件列表,或者将你的命令导出到文件中,以及一系列其它很棒的选项。你可以通过 `man fbi` 来查阅完整的选项列表。 + +### CMatrix 终端屏保 + +黑客帝国The Matrix屏保仍然是我非常喜欢的屏保之一(如图 2),仅次于弹跳牛bouncing cow。[CMatrix][3] 可以在终端运行。要运行它只需输入 `cmatrix`,然后可以用 `Ctrl+C` 来停止运行。执行 `cmatrix -s` 则会启动屏保模式,这样的话,按任意键都会直接退出。`-C` 参数可以设定颜色,譬如绿色(`green`)、红色(`red`)、蓝色(`blue`)、黄色(`yellow`)、白色(`white`)、紫色(`magenta`)、青色(`cyan`)或者黑色(`black`)。 + +![图 2 黑客帝国屏保](https://www.linux.com/sites/lcom/files/styles/floated_images/public/fig-2_0.jpg?itok=E3f26R7w) + +CMatrix 还支持异步按键,这意味着你可以在它运行的时候改变设置选项。 + +`-B` 设置全部使用粗体,而 `-b`(LCTT 译注:原文误为 `-B`)则可以设置部分字体加粗。 + +### fbgs PDF 阅读器 + +看起来,PDF 文档是普遍流行且无法避免的,而且 PDF 比它之前的功能好了很多,譬如超链接、复制粘贴以及更好的文本搜索功能等。`fbgs` 是 `fbida` 包中提供的一个 PDF 阅读器。它可以设置页面大小、分辨率、指定页码以及绝大部分 `fbi` 所提供的选项,当然除了一些在 `man fbgs` 中列举出来的不可用选项。我主要用到的选项是页面大小,你可以选择 `-l`、`xl` 或者 `xxl`: + +``` +$ fbgs -xl annoyingpdf.pdf +``` + +欢迎通过 Linux 基金会与 edX 免费提供的[“Linux 入门”][4]课程学习更多 Linux 知识。 + +-------------------------------------------------------------------------------- + +via: https://www.linux.com/learn/intro-to-linux/2018/1/multimedia-apps-linux-console + +作者:[Carla Schroder][a] +译者:[Yinr](https://github.com/Yinr) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.linux.com/users/cschroder +[1]:https://www.mjmwired.net/kernel/Documentation/fb/fbcon.txt +[2]:https://www.kraxel.org/blog/linux/fbida/ +[3]:http://www.asty.org/cmatrix/ +[4]:https://training.linuxfoundation.org/linux-courses/system-administration-training/introduction-to-linux diff --git a/published/20180122 Linux rm Command Explained for Beginners (8 Examples).md b/published/20180122 Linux rm Command Explained for Beginners (8 Examples).md new file mode 100644 index 0000000000..d484a436c0 --- /dev/null +++ b/published/20180122 Linux rm Command Explained for Beginners (8 Examples).md @@ -0,0 +1,170 @@ +8 个你不一定全都了解的 rm 命令示例 +====== + +删除文件和复制/移动文件一样,都是很基础的操作。在 Linux 中,有一个专门的命令 `rm`,可用于完成所有删除相关的操作。在本文中,我们将用些容易理解的例子来讨论这个命令的基本使用。 + +但在我们开始前,值得指出的是本文所有示例都在 Ubuntu 16.04 LTS 中测试过。 + +### Linux rm 命令概述 + +通俗的讲,我们可以认为 `rm` 命令是用于删除文件和目录的。下面是此命令的语法: + +``` +rm [选项]... [要删除的文件/目录]... +``` + +下面是命令使用说明: + +> GUN 版本 `rm` 命令的手册文档。`rm` 删除每个指定的文件,默认情况下不删除目录。 + +> 当删除的文件超过三个或者提供了选项 `-r`、`-R` 或 `--recursive`(LCTT 译注:表示递归删除目录中的文件)时,如果给出 `-I`(LCTT 译注:大写的 I)或 `--interactive=once` 选项(LCTT 译注:表示开启交互一次),则 `rm` 命令会提示用户是否继续整个删除操作,如果用户回应不是确认(LCTT 译注:即没有回复 `y`),则整个命令立刻终止。 + +> 另外,如果被删除文件是不可写的,标准输入是终端,这时如果没有提供 `-f` 或 `--force` 选项,或者提供了 `-i`(LCTT 译注:小写的 i) 或 `--interactive=always` 选项,`rm` 会提示用户是否要删除此文件,如果用户回应不是确认(LCTT 译注:即没有回复 `y`),则跳过此文件。 + + +下面这些问答式例子会让你更好的理解这个命令的使用。 + +### Q1. 如何用 rm 命令删除文件? + +这是非常简单和直观的。你只需要把文件名(如果文件不是在当前目录中,则还需要添加文件路径)传入给 `rm` 命令即可。 + +(LCTT 译注:可以用空格隔开传入多个文件名称。) + +``` +rm 文件1 文件2 ... +``` +如: + +``` +rm testfile.txt +``` + +[![How to remove files using rm command][1]][2] + +### Q2. 如何用 `rm` 命令删除目录? + +如果你试图删除一个目录,你需要提供 `-r` 选项。否则 `rm` 会抛出一个错误告诉你正试图删除一个目录。 + +(LCTT 译注:`-r` 表示递归地删除目录下的所有文件和目录。) + +``` +rm -r [目录名称] +``` + +如: + +``` +rm -r testdir +``` + +[![How to remove directories using rm command][3]][4] + +### Q3. 如何让删除操作前有确认提示? + +如果你希望在每个删除操作完成前都有确认提示,可以使用 `-i` 选项。 + +``` +rm -i [文件/目录] +``` + +比如,你想要删除一个目录“testdir”,但需要每个删除操作都有确认提示,你可以这么做: + +``` +rm -r -i testdir +``` + +[![How to make rm prompt before every removal][5]][6] + +### Q4. 如何让 rm 忽略不存在的文件或目录? + +如果你删除一个不存在的文件或目录时,`rm` 命令会抛出一个错误,如: + +[![Linux rm command example][7]][8] + +然而,如果你愿意,你可以使用 `-f` 选项(LCTT 译注:即 “force”)让此次操作强制执行,忽略错误提示。 + +``` +rm -f [文件...] +``` + +[![How to force rm to ignore nonexistent files][9]][10] + +### Q5. 如何让 rm 仅在某些场景下确认删除? + +选项 `-I`,可保证在删除超过 3 个文件时或递归删除时(LCTT 译注: 如删除目录)仅提示一次确认。 + +比如,下面的截图展示了 `-I` 选项的作用——当两个文件被删除时没有提示,当超过 3 个文件时会有提示。 + +[![How to make rm prompt only in some scenarios][11]][12] + +### Q6. 当删除根目录是 rm 是如何工作的? + +当然,删除根目录(`/`)是 Linux 用户最不想要的操作。这也就是为什么默认 `rm` 命令不支持在根目录上执行递归删除操作。(LCTT 译注:早期的 `rm` 命令并无此预防行为。) + +[![How rm works when dealing with root directory][13]][14] + +然而,如果你非得完成这个操作,你需要使用 `--no-preserve-root` 选项。当提供此选项,`rm` 就不会特殊处理根目录(`/`)了。 + +假如你想知道在哪些场景下 Linux 用户会删除他们的根目录,点击[这里][15]。 + +### Q7. 如何让 rm 仅删除空目录? + +假如你需要 `rm` 在删除目录时仅删除空目录,你可以使用 `-d` 选项。 + +``` +rm -d [目录] +``` + +下面的截图展示 `-d` 选项的用途——仅空目录被删除了。 + +[![How to make rm only remove empty directories][16]][17] + +### Q8. 如何让 rm 显示当前删除操作的详情? + +如果你想 rm 显示当前操作完成时的详细情况,使用 `-v` 选项可以做到。 + +``` +rm -v [文件/目录] +``` + +如: + +[![How to force rm to emit details of operation it is performing][18]][19] + +### 结论 + +考虑到 `rm` 命令提供的功能,可以说其是 Linux 中使用频率最高的命令之一了(就像 [cp][20] 和 `mv` 一样)。在本文中,我们涉及到了其提供的几乎所有主要选项。`rm` 命令有些学习曲线,因此在你日常工作中开始使用此命令之前 +你将需要花费些时间去练习它的选项。更多的信息,请点击此命令的 [man 手册页][21]。 + +-------------------------------------------------------------------------------- + +via: https://www.howtoforge.com/linux-rm-command/ + +作者:[Himanshu Arora][a] +译者:[yizhuoyan](https://github.com/yizhuoyan) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.howtoforge.com +[1]:https://www.howtoforge.com/images/command-tutorial/rm-basic-usage.png +[2]:https://www.howtoforge.com/images/command-tutorial/big/rm-basic-usage.png +[3]:https://www.howtoforge.com/images/command-tutorial/rm-r.png +[4]:https://www.howtoforge.com/images/command-tutorial/big/rm-r.png +[5]:https://www.howtoforge.com/images/command-tutorial/rm-i-option.png +[6]:https://www.howtoforge.com/images/command-tutorial/big/rm-i-option.png +[7]:https://www.howtoforge.com/images/command-tutorial/rm-non-ext-error.png +[8]:https://www.howtoforge.com/images/command-tutorial/big/rm-non-ext-error.png +[9]:https://www.howtoforge.com/images/command-tutorial/rm-f-option.png +[10]:https://www.howtoforge.com/images/command-tutorial/big/rm-f-option.png +[11]:https://www.howtoforge.com/images/command-tutorial/rm-I-option.png +[12]:https://www.howtoforge.com/images/command-tutorial/big/rm-I-option.png +[13]:https://www.howtoforge.com/images/command-tutorial/rm-root-default.png +[14]:https://www.howtoforge.com/images/command-tutorial/big/rm-root-default.png +[15]:https://superuser.com/questions/742334/is-there-a-scenario-where-rm-rf-no-preserve-root-is-needed +[16]:https://www.howtoforge.com/images/command-tutorial/rm-d-option.png +[17]:https://www.howtoforge.com/images/command-tutorial/big/rm-d-option.png +[18]:https://www.howtoforge.com/images/command-tutorial/rm-v-option.png +[19]:https://www.howtoforge.com/images/command-tutorial/big/rm-v-option.png +[20]:https://www.howtoforge.com/linux-cp-command/ +[21]:https://linux.die.net/man/1/rm diff --git a/sources/tech/20180124 8 ways to generate random password in Linux.md b/published/20180124 8 ways to generate random password in Linux.md similarity index 59% rename from sources/tech/20180124 8 ways to generate random password in Linux.md rename to published/20180124 8 ways to generate random password in Linux.md index ee60df826b..cb91d79d57 100644 --- a/sources/tech/20180124 8 ways to generate random password in Linux.md +++ b/published/20180124 8 ways to generate random password in Linux.md @@ -1,87 +1,90 @@ -8 ways to generate random password in Linux +八种在 Linux 上生成随机密码的方法 ====== -Learn 8 different ways to generate random password in Linux using Linux native commands or third party utilities. + +> 学习使用 8 种 Linux 原生命令或第三方实用程序来生成随机密码。 ![][1] -In this article, we will walk you through various different ways to generate random password in Linux terminal. Few of them are using native Linux commands and others are using third party tools or utilities which can easily be installed on Linux machine. Here we are looking at native commands like `openssl`, [dd][2], `md5sum`, `tr`, `urandom` and third party tools like mkpasswd, randpw, pwgen, spw, gpg, xkcdpass, diceware, revelation, keepaasx, passwordmaker. +在这篇文章中,我们将引导你通过几种不同的方式在 Linux 终端中生成随机密码。其中几种利用原生 Linux 命令,另外几种则利用极易在 Linux 机器上安装的第三方工具或实用程序实现。在这里我们利用像 `openssl`, [dd][2], `md5sum`, `tr`, `urandom` 这样的原生命令和 mkpasswd,randpw,pwgen,spw,gpg,xkcdpass,diceware,revelation,keepaasx,passwordmaker 这样的第三方工具。 -These are actually ways to get some random alphanumeric string which can be utilized as password. Random passwords can be used for new users so that there will be uniqueness no matter how large your user base is. Without any further delay lets jump into those 15 different ways to generate random password in Linux. +其实这些方法就是生成一些能被用作密码的随机字母字符串。随机密码可以用于新用户的密码,不管用户基数有多大,这些密码都是独一无二的。话不多说,让我们来看看 8 种不同的在 Linux 上生成随机密码的方法吧。 -##### Generate password using mkpasswd utility +### 使用 mkpasswd 实用程序生成密码 -`mkpasswd` comes with install of `expect` package on RHEL based systems. On Debian based systems `mkpasswd` comes with package `whois`. Trying to install `mkpasswd` package will results in error - +`mkpasswd` 在基于 RHEL 的系统上随 `expect` 软件包一起安装。在基于 Debian 的系统上 `mkpasswd` 则在软件包 `whois` 中。直接安装 `mkpasswd` 软件包将会导致错误: -No package mkpasswd available. on RHEL system and E: Unable to locate package mkpasswd in Debian based. +- RHEL 系统:软件包 mkpasswd 不可用。 +- Debian 系统:错误:无法定位软件包 mkpasswd。 -So install their parent packages as mentioned above and you are good to go. +所以按照上面所述安装他们的父软件包,就没问题了。 -Run `mkpasswd` to get passwords +运行 `mkpasswd` 来获得密码 -``` +```bash root@kerneltalks# mkpasswd << on RHEL zt*hGW65c - -root@kerneltalks# mkpas + +root@kerneltalks# mkpasswd teststring << on Ubuntu +XnlrKxYOJ3vik ``` -Command behaves differently on different systems so work accordingly. There are many switches which can be used to control length etc parameters. You can explore them from man pages. +这个命令在不同的系统上表现得不一样,所以工作方式各异。你也可以通过参数来控制长度等选项,可以查阅 man 手册来探索。 -##### Generate password using openssl +### 使用 openssl 生成密码 -Openssl comes in build with almost all the Linux distributions. We can use its random function to get alphanumeric string generated which can be used as password. +几乎所有 Linux 发行版都包含 openssl。我们可以利用它的随机功能来生成可以用作密码的随机字母字符串。 -``` +```bash root@kerneltalks # openssl rand -base64 10 nU9LlHO5nsuUvw== ``` -Here, we are using `base64` encoding with random function and last digit for argument to `base64` encoding. +这里我们使用 `base64` 编码随机函数,最后一个数字参数表示长度。 -##### Generate password using urandom +### 使用 urandom 生成密码 -Device file `/dev/urandom` is another source of getting random characters. We are using `tr` function and trimming output to get random string to use as password. +设备文件 `/dev/urandom` 是另一个获得随机字符串的方法。我们使用 `tr` 功能并裁剪输出来获得随机字符串,并把它作为密码。 -``` +```bash root@kerneltalks # strings /dev/urandom |tr -dc A-Za-z0-9 | head -c20; echo UiXtr0NAOSIkqtjK4c0X ``` -##### dd command to generate password +### 使用 dd 命令生成密码 -We can even use /dev/urandom device along with [dd command ][2]to get string of random characters. +我们甚至可以使用 `/dev/urandom` 设备配合 [dd 命令][2] 来获取随机字符串。 -``` -oot@kerneltalks# dd if=/dev/urandom bs=1 count=15|base64 -w 0 +```bash +root@kerneltalks# dd if=/dev/urandom bs=1 count=15|base64 -w 0 15+0 records in 15+0 records out 15 bytes (15 B) copied, 5.5484e-05 s, 270 kB/s QMsbe2XbrqAc2NmXp8D0 ``` -We need to pass output through `base64` encoding to make it human readable. You can play with count value to get desired length. For much cleaner output, redirect std2 to `/dev/null`. Clean command will be - +我们需要将结果通过 `base64` 编码使它能被人类可读。你可以使用数值来获取想要的长度。想要获得更简洁的输出的话,可以将“标准错误输出”重定向到 `/dev/null`。简洁输出的命令是: -``` -oot@kerneltalks # dd if=/dev/urandom bs=1 count=15 2>/dev/null|base64 -w 0 +```bash +root@kerneltalks # dd if=/dev/urandom bs=1 count=15 2>/dev/null|base64 -w 0 F8c3a4joS+a3BdPN9C++ ``` -##### Using md5sum to generate password +### 使用 md5sum 生成密码 -Another way to get array of random characters which can be used as password is to calculate MD5 checksum! s you know checksum value is indeed looks like random characters grouped together we can use it as password. Make sure you use source as something variable so that you get different checksum every time you run command. For example `date` ! [date command][3] always yields changing output. +另一种获取可用作密码的随机字符串的方法是计算 MD5 校验值!校验值看起来确实像是随机字符串组合在一起,我们可以用作密码。确保你的计算源是个变量,这样的话每次运行命令时生成的校验值都不一样。比如 `date` ![date 命令][3] 总会生成不同的输出。 -``` +```bash root@kerneltalks # date |md5sum 4d8ce5c42073c7e9ca4aeffd3d157102 - ``` -Here we passed `date` command output to `md5sum` and get the checksum hash! You can use [cut command][4] to get desired length of output. +在这里我们将 `date` 命令的输出通过 `md5sum` 得到了校验和!你也可以用 [cut 命令][4] 裁剪你需要的长度。 -##### Generate password using pwgen +### 使用 pwgen 生成密码 -`pwgen` package comes with [repositories like EPEL][5]. `pwgen` is more focused on generating passwords which are pronounceable but not a dictionary word or not in plain English. You may not find it in standard distribution repo. Install the package and run `pwgen` command. Boom ! +`pwgen` 软件包在类似 [EPEL 软件仓库][5](LCTT 译注:企业版 Linux 附加软件包)中。`pwgen` 更专注于生成可发音的密码,但它们不在英语词典中,也不是纯英文的。标准发行版仓库中可能并不包含这个工具。安装这个软件包然后运行 `pwgen` 命令行。Boom ! -``` +```bash root@kerneltalks # pwgen thu8Iox7 ahDeeQu8 Eexoh0ai oD8oozie ooPaeD9t meeNeiW2 Eip6ieph Ooh1tiet cootad7O Gohci0vo wah9Thoh Ohh3Ziur Ao1thoma ojoo6aeW Oochai4v ialaiLo5 @@ -89,28 +92,31 @@ aic2OaDa iexieQu8 Aesoh4Ie Eixou9ph ShiKoh0i uThohth7 taaN3fuu Iege0aeZ cah3zaiW Eephei0m AhTh8guo xah1Shoo uh8Iengo aifeev4E zoo4ohHa fieDei6c aorieP7k ahna9AKe uveeX7Hi Ohji5pho AigheV7u Akee9fae aeWeiW4a tiex8Oht ``` -You will be presented with list of passwords at your terminal! What else you want? Ok. You still want to explore, `pwgen` comes with many custom options which can be referred for man page. -##### Generate password using gpg tool +你的终端会呈现出一个密码列表!你还想要什么呢?好吧。你还想再仔细探索的话, `pwgen` 还有很多自定义选项,这些都可以在 man 手册里查阅到。 -GPG is a OpenPGP encryption and signing tool. Mostly gpg tool comes pre-installed (at least it is on my RHEL7). But if not you can look for `gpg` or `gpg2` package and [install][6] it. +### 使用 gpg 工具生成密码 -Use below command to generate password from gpg tool. +GPG 是一个遵循 OpenPGP 标准的加密及签名工具。大部分 gpg 工具都预先被安装好了(至少在我的 RHEL7 上是这样)。但如果没有的话你可以寻找 `gpg` 或 `gpg2` 软件包并[安装][6]它。 -``` +使用下面的命令以从 gpg 工具生成密码。 + +```bash root@kerneltalks # gpg --gen-random --armor 1 12 mL8i+PKZ3IuN6a7a ``` -Here we are passing generate random byte sequence switch (`--gen-random`) of quality 1 (first argument) with count of 12 (second argument). Switch `--armor` ensures output is `base64` encoded. +这里我们传了生成随机字节序列选项(`--gen-random`),质量为 1(第一个参数),次数 12 (第二个参数)。选项 `--armor` 保证以 `base64` 编码输出。 -##### Generate password using xkcdpass +### 使用 xkcdpass 生成密码 -Famous geek humor website [xkcd][7], published a very interesting post about memorable but still complex passwords. You can view it [here][8]. So `xkcdpass` tool took inspiration from this post and did its work! Its a python package and available on python's official website [here][9] +著名的极客幽默网站 [xkcd][7],发表了一篇非常有趣的文章,是关于好记但又复杂的密码的。你可以在[这里][8]阅读。所以 `xkcdpass` 工具就受这篇文章启发,做了这样的工作!这是一个 Python 软件包,可以在[这里][9]的 Python 的官网上找到它。 -All installation and usage instructions are mentioned on that page. Here is install steps and outputs from my test RHEL server for your reference. +![](https://imgs.xkcd.com/comics/password_strength.png) -``` +所有的安装使用说明都在上面那个页面提及了。这里是安装步骤和我的测试 RHEL 服务器的输出,以供参考。 + +```bash root@kerneltalks # wget https://pypi.python.org/packages/b4/d7/3253bd2964390e034cf0bba227db96d94de361454530dc056d8c1c096abc/xkcdpass-1.14.3.tar.gz#md5=5f15d52f1d36207b07391f7a25c7965f --2018-01-23 19:09:17-- https://pypi.python.org/packages/b4/d7/3253bd2964390e034cf0bba227db96d94de361454530dc056d8c1c096abc/xkcdpass-1.14.3.tar.gz Resolving pypi.python.org (pypi.python.org)... 151.101.32.223, 2a04:4e42:8::223 @@ -226,33 +232,34 @@ Processing dependencies for xkcdpass==1.14.3 Finished processing dependencies for xkcdpass==1.14.3 ``` -Now running xkcdpass command will give you random set of dictionary words like below - +现在运行 `xkcdpass` 命令,将会随机给出你几个像下面这样的字典单词: -``` +```bash root@kerneltalks # xkcdpass broadside unpadded osmosis statistic cosmetics lugged ``` -You can use these words as input to other commands like `md5sum` to get random password (like below) or you can even use Nth letter of each words to form your password! +你可以用这些单词作为其他命令,比如 `md5sum` 的输入,来获取随机密码(就像下面这样),甚至你也可以用每个单词的第 N 个字母来生成你的密码! -``` -oot@kerneltalks # xkcdpass |md5sum +```bash +root@kerneltalks # xkcdpass |md5sum 45f2ec9b3ca980c7afbd100268c74819 - root@kerneltalks # xkcdpass |md5sum ad79546e8350744845c001d8836f2ff2 - ``` -Or even you can use all those words together as such a long password which is easy to remember for a user and very hard to crack using computer program. -There are tools like [Diceware][10], [KeePassX][11], [Revelation][12], [PasswordMaker][13] for Linux which can be considered for making strong random passwords. +或者你甚至可以把所有单词串在一起作为一个超长的密码,不仅非常好记,也不容易被电脑程序攻破。 + +Linux 上还有像 [Diceware][10]、 [KeePassX][11]、 [Revelation][12]、 [PasswordMaker][13] 这样的工具,也可以考虑用来生成强随机密码。 -------------------------------------------------------------------------------- via: https://kerneltalks.com/tips-tricks/8-ways-to-generate-random-password-in-linux/ 作者:[kerneltalks][a] -译者:[译者ID](https://github.com/译者ID) -校对:[校对者ID](https://github.com/校对者ID) +译者:[heart4lor](https://github.com/heart4lor) +校对:[Locez](https://github.com/locez) 本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 diff --git a/published/20180125 A step-by-step guide to Git.md b/published/20180125 A step-by-step guide to Git.md new file mode 100644 index 0000000000..665e5e6832 --- /dev/null +++ b/published/20180125 A step-by-step guide to Git.md @@ -0,0 +1,138 @@ +手把手指导您使用 Git +====== + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/lightbulb-idea-think-yearbook-lead.png?itok=5ZpCm0Jh) + +如果您从未使用过 [Git][1],甚至可能从未听说过它。莫慌张,只需要一步步地跟着这篇入门教程,很快您就会在 [GitHub][2] 上拥有一个全新的 Git 仓库。 + +在开始之前,让我们先理清一个常见的误解:Git 并不是 GitHub。Git 是一套版本控制系统(或者说是一款软件),能够协助您跟踪计算机程序和文件在任何时间的更改。它同样允许您在程序、代码和文件操作上与同事协作。GitHub 以及类似服务(包括 GitLab 和 BitBucket)都属于部署了 Git 程序的网站,能够托管您的代码。 + +### 步骤 1:申请一个 GitHub 账户 + +在 [GitHub.com][3] 网站上(免费)创建一个账户是最简单的方式。 + +![](https://opensource.com/sites/default/files/u128651/git_guide1.png) + +选择一个用户名(比如说,octocat123),输入您的邮箱地址和密码,然后点击 **Sign up for GitHub**。进入之后,您将看到下方插图的界面: + +![](https://opensource.com/sites/default/files/u128651/git_guide2.png) + +### 步骤 2:创建一个新的仓库 + +一个仓库( repository),类似于能储存物品的场所或是容器;在这里,我们创建仓库存储代码。在 `+` 符号(在插图的右上角,我已经选中它了) 的下拉菜单中选择 **New Repository**。 + +![](https://opensource.com/sites/default/files/u128651/git_guide3.png) + +给您的仓库命名(比如说,Demo)然后点击 **Create Repository**。无需考虑本页面的其他选项。 + +恭喜!您已经在 GitHub.com 中建立了您的第一个仓库。 + +### 步骤 3: 创建文件 + +当仓库创建完毕后,界面将和下方一致: + +![](https://opensource.com/sites/default/files/u128651/git_guide4.png) + +不必惊慌,它比看上去简单。跟紧步骤。忽略其他内容,注意截图上的 “...or create a new repository on the command line,”。 + +在您的计算机中打开终端。 + +![](https://opensource.com/sites/default/files/u128651/git_guide5.png) + +键入 `git` 然后回车。如果命令行显示 `bash: git: command not found`,在您的操作系统或发行版 [安装 Git][4] 命令。键入 `git` 并回车检查是否成功安装;如果安装成功,您将看见大量关于使用该命令的说明信息。 + +在终端内输入: + +``` +mkdir Demo +``` + +这个命令将会创建一个名为 Demo 的目录(文件夹)。 + +如下命令将会切换终端目录,跳转到 Demo 目录: + +``` +cd Demo +``` + +然后输入: + +``` +echo "#Demo" >> README.md +``` + +创建一个名为 `README.md` 的文件,并写入 `#Demo`。检查文件是否创建成功,请输入: + +``` +cat README.md +``` + +这将会为您显示 `README.md` 文件的内容,如果文件创建成功,您的终端会有如下显示: + +![](https://opensource.com/sites/default/files/u128651/git_guide7.png) + +使用 Git 程序告诉您的电脑,Demo 是一个被 Git 管理的目录,请输入: + +``` +git init +``` + +然后,告诉 Git 程序您关心的文件并且想在此刻起跟踪它的任何改变,请输入: + +``` +git add README.md +``` + +### 步骤 4:创建一次提交 + +目前为止,您已经创建了一个文件,并且已经通知了 Git,现在,是时候创建一次提交commit了。提交可以看作是一个里程碑。每当完成一些工作之时,您都可以创建一次提交,保存文件当前版本,这样一来,您可以返回之前的版本,并且查看那时候的文件内容。无论何时您修改了文件,都可以对文件创建一个上一次的不一样的新版本。 + +创建一次提交,请输入: + +``` +git commit -m "first commit" +``` + +就是这样!刚才您创建了包含一条注释为 “first commit” 的 Git 提交。每次提交,您都必须编辑注释信息;它不仅能协助您识别提交,而且能让您理解此时您对文件做了什么修改。这样到了明天,如果您在文件中添加新的代码,您可以写一句提交信息:“添加了新的代码”,然后当您一个月后回来查看提交记录或者 Git 日志(即提交列表),您还能知道当时的您在文件夹里做了什么。 + +### 步骤 5: 将您的计算机与 GitHub 仓库相连接 + +现在,是时候用如下命令将您的计算机连接到 GitHub 仓库了: + +``` +git remote add origin https://github.com//Demo.git +``` + +让我们一步步的分析这行命令。我们通知 Git 去添加一个叫做 `origin` (起源)的,拥有地址为 `https://github.com//Demo.git`(它也是您的仓库的 GitHub 地址) 的 `remote` (远程仓库)。当您提交代码时,这允许您在 GitHub.com 和 Git 仓库交互时使用 `origin` 这个名称而不是完整的 Git 地址。为什么叫做 `origin`?当然,您可以叫点别的,只要您喜欢(惯例而已)。 + +现在,我们已经将本地 Demo 仓库副本连接到了其在 GitHub.com 远程副本上。您的终端看起来如下: + +![](https://opensource.com/sites/default/files/u128651/git_guide8.png) + +此刻我们已经连接到远程仓库,可以推送我们的代码 到 GitHub.com(例如上传 `README.md` 文件)。 + +执行完毕后,您的终端会显示如下信息: + +![](https://opensource.com/sites/default/files/u128651/git_guide9.png) + +然后,如果您访问 `https://github.com//Demo`,您会看到截图内显示的情况: + +![](https://opensource.com/sites/default/files/u128651/git_guide10.png) + +就是这么回事!您已经创建了您的第一个 GitHub 仓库,连接到了您的电脑,并且从你的计算机推送(或者称:上传)一个文件到 GitHub.com 名叫 Demo 的远程仓库上了。下一次,我将编写关于 Git 复制(从 GitHub 上下载文件到你的计算机上)、添加新文件、修改现存文件、推送(上传)文件到 GitHub。 + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/1/step-step-guide-git + +作者:[Kedar Vijay Kulkarni][a] +译者:[CYLeft](https://github.com/CYLeft) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://opensource.com/users/kkulkarn +[1]:https://opensource.com/resources/what-is-git +[2]:https://opensource.com/life/15/11/short-introduction-github +[3]:https://github.com/ +[4]:https://www.linuxbabe.com/linux-server/install-git-verion-control-on-linux-debianubuntufedoraarchlinux#crt-2 diff --git a/published/20180131 Why you should use named pipes on Linux.md b/published/20180131 Why you should use named pipes on Linux.md new file mode 100644 index 0000000000..ac50e96c9a --- /dev/null +++ b/published/20180131 Why you should use named pipes on Linux.md @@ -0,0 +1,103 @@ +为什么应该在 Linux 上使用命名管道 +====== + +> 命名管道并不常用,但是它们为进程间通讯提供了一些有趣的特性。 + +![](https://images.techhive.com/images/article/2017/05/blue-1845806_1280-100722976-large.jpg) + +估计每一位 Linux 使用者都熟悉使用 “|” 符号将数据从一个进程传输到另一个进程的操作。它使用户能简便地从一个命令输出数据到另一个命令,并筛选出想要的数据而无须写脚本进行选择、重新格式化等操作。 + +还有另一种管道, 虽然也叫“管道”这个名字却有着非常不同的性质。即您可能尚未使用甚至尚未知晓的——命名管道。 + +普通管道与命名管道的一个主要区别就是命名管道是以文件形式实实在在地存在于文件系统中的,没错,它们表现出来就是文件。但是与其它文件不同的是,命名管道文件似乎从来没有文件内容。即使用户往命名管道中写入大量数据,该文件看起来还是空的。 + +### 如何在 Linux 上创建命名管道 + +在我们研究这些空空如也的命名管道之前,先追根溯源来看看命名管道是如何被创建的。您应该使用名为 `mkfifo` 的命令来创建它们。为什么提及“FIFO”?是因为命名管道也被认为是一种 FIFO 特殊文件。术语 “FIFO” 指的是它的先进先出first-in, first-out特性。如果你将冰淇淋盛放到碟子中,然后可以品尝它,那么你执行的就是一个LIFO(后进先出last-in, first-out操作。如果你通过吸管喝奶昔,那你就在执行一个 FIFO 操作。好,接下来是一个创建命名管道的例子。 + +``` +$ mkfifo mypipe +$ ls -l mypipe +prw-r-----. 1 shs staff 0 Jan 31 13:59 mypipe +``` + +注意一下特殊的文件类型标记 “p” 以及该文件大小为 0。您可以将重定向数据写入命名管道文件,而文件大小依然为 0。 + +``` +$ echo "Can you read this?" > mypipe +``` + +正如上面所说,敲击回车后似乎什么都没有发生(LCTT 译注:没有返回命令行提示符)。 + +另外再开一个终端,查看该命名管道的大小,依旧是 0: + +``` +$ ls -l mypipe +prw-r-----. 1 shs staff 0 Jan 31 13:59 mypipe +``` + +也许这有违直觉,用户输入的文本已经进入该命名管道,而你仍然卡在输入端。你或者其他人应该等在输出端,并准备读取放入管道的数据。现在让我们读取看看。 + +``` +$ cat mypipe +Can you read this? +``` + +一旦被读取之后,管道中的内容就没有了。 + +另一种研究命名管道如何工作的方式是通过将放入数据的操作置入后台来执行两个操作(将数据放入管道,而在另外一段读取它)。 + +``` +$ echo "Can you read this?" > mypipe & +[1] 79302 +$ cat mypipe +Can you read this? +[1]+ Done echo "Can you read this?" > mypipe +``` + +一旦管道被读取或“耗干”,该管道就清空了,尽管我们还能看见它并再次使用。可为什么要费此周折呢? + +### 为何要使用命名管道? + +命名管道很少被使用的理由似乎很充分。毕竟在 Unix 系统上,总有多种不同的方式完成同样的操作。有多种方式写文件、读文件、清空文件,尽管命名管道比它们来得更高效。 + +值得注意的是,命名管道的内容驻留在内存中而不是被写到硬盘上。数据内容只有在输入输出端都打开时才会传送。用户可以在管道的输出端打开之前向管道多次写入。通过使用命名管道,用户可以创建一个进程写入管道并且另外一个进程读取管道的流程,而不用关心协调二者时间上的同步。 + +用户可以创建一个单纯等待数据出现在管道输出端的进程,并在拿到输出数据后对其进行操作。下列命令我们采用 `tail` 来等待数据出现。 + +``` +$ tail -f mypipe +``` + +一旦供给管道数据的进程结束了,我们就可以看到一些输出。 + +``` +$ tail -f mypipe +Uranus replicated to WCDC7 +Saturn replicated to WCDC8 +Pluto replicated to WCDC9 +Server replication operation completed +``` + +如果研究一下向命名管道写入的进程,用户也许会惊讶于它的资源消耗之少。在下面的 `ps` 命令输出中,唯一显著的资源消耗是虚拟内存(VSZ 那一列)。 + +``` +ps u -P 80038 +USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND +shs 80038 0.0 0.0 108488 764 pts/4 S 15:25 0:00 -bash +``` + +命名管道与 Unix/Linux 系统上更常用的管道相比足以不同到拥有另一个名号,但是“管道”确实能反映出它们如何在进程间传送数据的形象,故将称其为“命名管道”还真是恰如其分。也许您在执行操作时就能从这个聪明的 Unix/Linux 特性中获益匪浅呢。 + +-------------------------------------------------------------------------------- + +via: https://www.networkworld.com/article/3251853/linux/why-use-named-pipes-on-linux.html + +作者:[Sandra Henry-Stocker][a] +译者:[YPBlib](https://github.com/YPBlib) +校对:[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]:http://www.networkworld.com/article/2926630/linux/11-pointless-but-awesome-linux-terminal-tricks.html#tk.nww-fsb diff --git a/sources/talk/20160605 Manjaro Gaming- Gaming on Linux Meets Manjaro-s Awesomeness.md b/sources/talk/20160605 Manjaro Gaming- Gaming on Linux Meets Manjaro-s Awesomeness.md deleted file mode 100644 index 78e700de26..0000000000 --- a/sources/talk/20160605 Manjaro Gaming- Gaming on Linux Meets Manjaro-s Awesomeness.md +++ /dev/null @@ -1,115 +0,0 @@ -Manjaro Gaming: Gaming on Linux Meets Manjaro’s Awesomeness -====== -[![Meet Manjaro Gaming, a Linux distro designed for gamers with the power of Manjaro][1]][1] - -[Gaming on Linux][2]? Yes, that's very much possible and we have a dedicated new Linux distribution aiming for gamers. - -Manjaro Gaming is a Linux distro designed for gamers with the power of Manjaro. Those who have used Manjaro Linux before, know exactly why it is a such a good news for gamers. - -[Manjaro][3] is a Linux distro based on one of the most popular distro - [Arch Linux][4]. Arch Linux is widely known for its bleeding-edge nature offering a lightweight, powerful, extensively customizable and up-to-date experience. And while all those are absolutely great, the main drawback is that Arch Linux embraces the DIY (do it yourself) approach where users need to possess a certain level of technical expertise to get along with it. - -Manjaro strips that requirement and makes Arch accessible to newcomers, and at the same time provides all the advanced and powerful features of Arch for the experienced users as well. In short, Manjaro is an user-friendly Linux distro that works straight out of the box. - -The reasons why Manjaro makes a great and extremely suitable distro for gaming are: - - * Manjaro automatically detects computer's hardware (e.g. Graphics cards) - * Automatically installs the necessary drivers and software (e.g. Graphics drivers) - * Various codecs for media files playback comes pre-installed with it - * Has dedicated repositories that deliver fully tested and stable packages - - - -Manjaro Gaming is packed with all of Manjaro's awesomeness with the addition of various tweaks and software packages dedicated to make gaming on Linux smooth and enjoyable. - -![Inside Manjaro Gaming][5] - -#### Tweaks - -Some of the tweaks made on Manjaro Gaming are: - - * Manjaro Gaming uses highly customizable XFCE desktop environment with an overall dark theme. - * Sleep mode is disabled for preventing computers from sleeping while playing games with GamePad or watching long cutscenes. - - - -#### Softwares - -Maintaining Manjaro's tradition of working straight out of the box, Manjaro Gaming comes bundled with various Open Source software to provide often needed functionalities for gamers. Some of the software included are: - - * [**KdenLIVE**][6]: Videos editing software for editing gaming videos - * [**Mumble**][7]: Voice chatting software for gamers - * [**OBS Studio**][8]: Software for video recording and live streaming games videos on [Twitch][9] - * **[OpenShot][10]** : Powerful video editor for Linux - * [**PlayOnLinux**][11]: For running Windows games on Linux with [Wine][12] backend - * [**Shutter**][13]: Feature-rich screenshot tool - - - -#### Emulators - -Manjaro Gaming comes with a long list of gaming emulators: - - * **[DeSmuME][14]** : Nintendo DS emulator - * **[Dolphin Emulator][15]** : GameCube and Wii emulator - * [**DOSBox**][16]: DOS Games emulator - * **[FCEUX][17]** : Nintendo Entertainment System (NES), Famicom, and Famicom Disk System (FDS) emulator - * **Gens/GS** : Sega Mega Drive emulator - * **[PCSXR][18]** : PlayStation Emulator - * [**PCSX2**][19]: Playstation 2 emulator - * [**PPSSPP**][20]: PSP emulator - * **[Stella][21]** : Atari 2600 VCS emulator - * [**VBA-M**][22]: Gameboy and GameboyAdvance emulator - * [**Yabause**][23]: Sega Saturn Emulator - * **[ZSNES][24]** : Super Nintendo emulator - - - -#### Others - -There are some terminal add-ons - Color, ILoveCandy and Screenfetch. [Conky Manager][25] with Retro Conky theme is also included. - -**Point to be noted: Not all the features mentioned are included in the current release of Manjaro Gaming (which is 16.03). Some of them are scheduled to be included in the next release - Manjaro Gaming 16.06.** - -### Downloads - -Manjaro Gaming 16.06 is going to be the first proper release of Manjaro Gaming. But if you are interested enough to try it now, Manjaro Gaming 16.03 is available for downloading on the Sourceforge [project page][26]. Go there and grab the ISO. - -How do you feel about this new Gaming Linux distro? Are you thinking of giving it a try? Let us know! - --------------------------------------------------------------------------------- - -via: https://itsfoss.com/manjaro-gaming-linux/ - -作者:[Munif Tanjim][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/munif/ -[1]:https://itsfoss.com/wp-content/uploads/2016/06/Manjaro-Gaming.jpg -[2]:https://itsfoss.com/linux-gaming-guide/ -[3]:https://manjaro.github.io/ -[4]:https://www.archlinux.org/ -[5]:https://itsfoss.com/wp-content/uploads/2016/06/Manjaro-Gaming-Inside-1024x576.png -[6]:https://kdenlive.org/ -[7]:https://www.mumble.info -[8]:https://obsproject.com/ -[9]:https://www.twitch.tv/ -[10]:http://www.openshot.org/ -[11]:https://www.playonlinux.com -[12]:https://www.winehq.org/ -[13]:http://shutter-project.org/ -[14]:http://desmume.org/ -[15]:https://dolphin-emu.org -[16]:https://www.dosbox.com/ -[17]:http://www.fceux.com/ -[18]:https://pcsxr.codeplex.com -[19]:http://pcsx2.net/ -[20]:http://www.ppsspp.org/ -[21]:http://stella.sourceforge.net/ -[22]:http://vba-m.com/ -[23]:https://yabause.org/ -[24]:http://www.zsnes.com/ -[25]:https://itsfoss.com/conky-gui-ubuntu-1304/ -[26]:https://sourceforge.net/projects/mgame/ diff --git a/sources/talk/20170915 Deep learning wars- Facebook-backed PyTorch vs Google-s TensorFlow.md b/sources/talk/20170915 Deep learning wars- Facebook-backed PyTorch vs Google-s TensorFlow.md deleted file mode 100644 index 31dbeb394b..0000000000 --- a/sources/talk/20170915 Deep learning wars- Facebook-backed PyTorch vs Google-s TensorFlow.md +++ /dev/null @@ -1,77 +0,0 @@ -Translating by Wuod3n -Deep learning wars: Facebook-backed PyTorch vs Google's TensorFlow -====== -The rapid rise of tools and techniques in Artificial Intelligence and Machine learning of late has been astounding. Deep Learning, or "Machine learning on steroids" as some say, is one area where data scientists and machine learning experts are spoilt for choice in terms of the libraries and frameworks available. A lot of these frameworks are Python-based, as Python is a more general-purpose and a relatively easier language to work with. [Theano][1], [Keras][2] [TensorFlow][3] are a few of the popular deep learning libraries built on Python, developed with an aim to make the life of machine learning experts easier. - -Google's TensorFlow is a widely used machine learning and deep learning framework. Open sourced in 2015 and backed by a huge community of machine learning experts, TensorFlow has quickly grown to be THE framework of choice by many organizations for their machine learning and deep learning needs. PyTorch, on the other hand, a recently developed Python package by Facebook for training neural networks is adapted from the Lua-based deep learning library Torch. PyTorch is one of the few available DL frameworks that uses tape-based autograd system to allow building dynamic neural networks in a fast and flexible manner. - -In this article, we pit PyTorch against TensorFlow and compare different aspects where one edges the other out. - -Let's get started! - -### What programming languages support PyTorch and TensorFlow? - -Although primarily written in C++ and CUDA, Tensorflow contains a Python API sitting over the core engine, making it easier for Pythonistas to use. Additional APIs for C++, Haskell, Java, Go, and Rust are also included which means developers can code in their preferred language. - -Although PyTorch is a Python package, there's provision for you to code using the basic C/ C++ languages using the APIs provided. If you are comfortable using Lua programming language, you can code neural network models in PyTorch using the Torch API. - -### How easy are PyTorch and TensorFlow to use? - -TensorFlow can be a bit complex to use if used as a standalone framework, and can pose some difficulty in training Deep Learning models. To reduce this complexity, one can use the Keras wrapper which sits on top of TensorFlow's complex engine and simplifies the development and training of deep learning models. TensorFlow also supports [Distributed training][4], which PyTorch currently doesn't. Due to the inclusion of Python API, TensorFlow is also production-ready i.e., it can be used to train and deploy enterprise-level deep learning models. - -PyTorch was rewritten in Python due to the complexities of Torch. This makes PyTorch more native to developers. It has an easy to use framework that provides maximum flexibility and speed. It also allows quick changes within the code during training without hampering its performance. If you already have some experience with deep learning and have used Torch before, you will like PyTorch even more, because of its speed, efficiency, and ease of use. PyTorch includes custom-made GPU allocator, which makes deep learning models highly memory efficient. Due to this, training large deep learning models becomes easier. Hence, large organizations such as Facebook, Twitter, Salesforce, and many more are embracing Pytorch. - -### Training Deep Learning models with PyTorch and TensorFlow - -Both TensorFlow and PyTorch are used to build and train Neural Network models. - -TensorFlow works on SCG (Static Computational Graph) that includes defining the graph statically before the model starts execution. However, once the execution starts the only way to tweak changes within the model is using [tf.session and tf.placeholder tensors][5]. - -PyTorch is well suited to train RNNs( Recursive Neural Networks) as they run faster in [PyTorch ][6]than in TensorFlow. It works on DCG (Dynamic Computational Graph) and one can define and make changes within the model on the go. In a DCG, each block can be debugged separately, which makes training of neural networks easier. - -TensorFlow has recently come up with TensorFlow Fold, a library designed to create TensorFlow models that works on structured data. Like PyTorch, it implements the DCGs and gives massive computational speeds of up to 10x on CPU and more than 100x on GPU! With the help of [Dynamic Batching][7], you can now implement deep learning models which vary in size as well as structure. - -### Comparing GPU and CPU optimizations - -TensorFlow has faster compile times than PyTorch and provides flexibility for building real-world applications. It can run on literally any kind of processor from a CPU, GPU, TPU, mobile devices, to a Raspberry Pi (IoT Devices). - -PyTorch, on the other hand, includes Tensor computations which can speed up deep neural network models upto [50x or more][8] using GPUs. These tensors can dwell on CPU or GPU. Both CPU and GPU are written as independent libraries; making PyTorch efficient to use, irrespective of the Neural Network size. - -### Community Support - -TensorFlow is one of the most popular Deep Learning frameworks today, and with this comes a huge community support. It has great documentation, and an eloquent set of online tutorials. TensorFlow also includes numerous pre-trained models which are hosted and available on [github][9]. These models aid developers and researchers who are keen to work with TensorFlow with some ready-made material to save their time and efforts. - -PyTorch, on the other hand, has a relatively smaller community since it has been developed fairly recently. As compared to TensorFlow, the documentation isn't that great, and codes are not readily available. However, PyTorch does allow individuals to share their pre-trained models with others. - -### PyTorch and TensorFlow - A David & Goliath story - -As it stands, Tensorflow is clearly favoured and used more than PyTorch for a variety of reasons. - -Tensorflow is vast, experienced, and best suited for practical purposes. It is easily the obvious choice of most of the machine learning and deep learning experts because of the vast array of features it offers, and most importantly, its maturity in the market. It has a better community support along with multiple language APIs available. It has a good documentation and is production-ready due to the availability of ready-to-use code. Hence, it is better suited for someone who wants to get started with Deep Learning, or for organizations wanting to productize their Deep Learning models. - -Although PyTorch is relatively newer and has a smaller community, it is fast and efficient. In short, it gives you all the power of Torch wrapped in the usefulness and ease of Python. Because of its efficiency and speed, it is a good option to have for small, research based projects. As mentioned earlier, companies such as Facebook, Twitter, and many others are using Pytorch to train deep learning models. However, its adoption is yet to go mainstream. The potential is evident, PyTorch is just not ready yet to challenge the beast that is TensorFlow. However considering its growth, the day is not far when PyTorch is further optimized and offers more functionalities - to the point that it becomes the David to TensorFlow's Goliath. - -### Savia Lobo -A Data science fanatic. Loves to be updated with the tech happenings around the globe. Loves singing and composing songs. Believes in putting the art in smart. - - --------------------------------------------------------------------------------- - -via: https://datahub.packtpub.com/deep-learning/dl-wars-pytorch-vs-tensorflow/ - -作者:[Savia Lobo][a] -译者:[译者ID](https://github.com/译者ID) -校对:[校对者ID](https://github.com/校对者ID) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 - -[a]:https://datahub.packtpub.com/author/savial/ -[1]:https://www.packtpub.com/web-development/deep-learning-theano -[2]:https://www.packtpub.com/big-data-and-business-intelligence/deep-learning-keras -[3]:https://www.packtpub.com/big-data-and-business-intelligence/deep-learning-tensorflow -[4]:https://www.tensorflow.org/deploy/distributed -[5]:https://www.tensorflow.org/versions/r0.12/get_started/basic_usage -[6]:https://www.reddit.com/r/MachineLearning/comments/66rriz/d_rnns_are_much_faster_in_pytorch_than_tensorflow/ -[7]:https://arxiv.org/abs/1702.02181 -[8]:https://github.com/jcjohnson/pytorch-examples#pytorch-tensors -[9]:https://github.com/tensorflow/models diff --git a/sources/talk/20171128 Your API is missing Swagger.md b/sources/talk/20171128 Your API is missing Swagger.md new file mode 100644 index 0000000000..af0106a121 --- /dev/null +++ b/sources/talk/20171128 Your API is missing Swagger.md @@ -0,0 +1,56 @@ +Your API is missing Swagger +====== + +![](https://ryanmccue.ca/content/images/2017/11/top-20mobileapps--3-.png) + +We have all struggled through thrown together, convoluted API documentation. It is frustrating, and in the worst case, can lead to bad requests. The process of understanding an API is something most developers go through on a regular basis, so it is any wonder that the majority of APIs have horrific documentation. + +[Swagger][1] is the solution to this problem. Swagger came out in 2011 and is an open source software framework which has many tools that help developers design, build, document, and consume RESTful APIs. Designing an API using Swagger, or documenting it after with Swagger helps everyone consumers of your API seamlessly. One of the amazing features which many people do not know about Swagger is that you can actually **generate** a client from it! That's right, if a service you're consuming has Swagger documentation you can generate a client to consume it! + +All major languages support Swagger and connect it to your API. Depending on the language you're writing your API in you can have the Swagger documentation generated from the actual code. Here are some of the standout Swagger libraries I've seen recently. + +### Golang + +Golang has a couple great tools for integrating Swagger into your API. The first is [go-swagger][2], which is a tool that lets you generate the scaffolding for an API from a Swagger file. This is a fundamentally different way of thinking about APIs. Instead of building the endpoints and thinking about new ones on the fly, go-swagger gets you to think through your API before you write a single line of code. This can help visualize what you want the API to do first. Another tool which Golang has is called [Goa][3]. A quote from their website sums up what Goa is: + +> goa provides a novel approach for developing microservices that saves time when working on independent services and helps with keeping the overall system consistent. goa uses code generation to handle both the boilerplate and ancillary artifacts such as documentation, client modules, and client tools. + +They take designing the API before implementing it to a new level. Goa has a DSL to help you programmatically describe your entire API, from endpoints to payloads, to responses. From this DSL Goa generates a Swagger file for anyone that consumes your API, and it will enforce your endpoints output the correct data, which will keep your API and documentation in sync. This is counter-intuitive when you start, but after actually implementing an API with Goa, you will not know how you ever did it before. + +### Python + +[Flask][4] has a great extension for building an API with Swagger called [Flask-RESTPlus][5]. + +> If you are familiar with Flask, Flask-RESTPlus should be easy to pick up. It provides a coherent collection of decorators and tools to describe your API and expose its documentation properly using Swagger. + +It uses python decorators to generate swagger documentation and can be used to enforce endpoint output similar to Goa. It can be very powerful and makes generating swagger from an API stupid easy. + +### NodeJS + +Finally, NodeJS has a powerful tool for working with Swagger called [swagger-js-codegen][6]. It can generate both servers and clients from a swagger file. + +> This package generates a nodejs, reactjs or angularjs class from a swagger specification file. The code is generated using mustache templates and is quality checked by jshint and beautified by js-beautify. + +It is not quite as easy to use as Goa and Flask-RESTPlus, but if Node is your thing, this will do the job. It shines when it comes to generating frontend code to interface with your API, which is perfect if you're developing a web app to go along with the API. + +### Conclusion + +Swagger is a simple yet powerful representation of your RESTful API. When used properly it can help flush out your API design and make it easier to consume. Harnessing its full power can save you time by forming and visualizing your API before you write a line of code, then generate the boilerplate surrounding the core logic. And with tools like [Goa][3], [Flask-RESTPlus][5], and [swagger-js-codegen][6] which will make the whole experience of architecting and implementing an API painless, there is no excuse not to have Swagger. + +-------------------------------------------------------------------------------- + +via: https://ryanmccue.ca/your-api-is-missing-swagger/ + +作者:[Ryan McCue][a] +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://ryanmccue.ca/author/ryan/ +[1]:http://swagger.io +[2]:https://github.com/go-swagger/go-swagger +[3]:https://goa.design/ +[4]:http://flask.pocoo.org/ +[5]:https://github.com/noirbizarre/flask-restplus +[6]:https://github.com/wcandillon/swagger-js-codegen diff --git a/sources/talk/20171201 5 Podcasts Every Dev Should Listen to.md b/sources/talk/20171201 5 Podcasts Every Dev Should Listen to.md new file mode 100644 index 0000000000..72586c8f35 --- /dev/null +++ b/sources/talk/20171201 5 Podcasts Every Dev Should Listen to.md @@ -0,0 +1,54 @@ +5 Podcasts Every Dev Should Listen to +====== + +![](https://ryanmccue.ca/content/images/2017/11/Electric-Love.png) + +Being a developer is a tough job, the landscape is constantly changing, and new frameworks and best practices come out every month. Having a great go-to list of podcasts keeping you up to date on the industry can make a huge difference. I've done some of the hard work and created a list of the top 5 podcasts I personally listen too. + +### This Developer's Life + +Unlike many developer-focused podcasts, there is no talk of code or explanations of software architecture in [This Developer's Life][1]. There are just relatable stories from other developers. This Developer's Life dives into the issues developers face in their daily lives, from a developers point of view. [Rob Conery][2] and [Scott Hanselman][3] host the show and it focuses on all aspects of a developers life. For example, what it feels like to get fired. To hit a home run. To be competitive. It is a very well made podcast and isn't just for developers, but it can also be enjoyed by those that love and live with them. + +### Developer Tea + +Don’t have a lot of time? [Developer Tea][4] is "A podcast for developers designed to fit inside your tea break." The podcast exists to help driven developers connect with their purpose and excel at their work so that they can make an impact. Hosted by [Jonathan Cutrell][5], the director of technology at Whiteboard, Developer Tea breaks down the news and gives useful insights into all aspects of a developers life in and out of work. Cutrell explains listener questions mixed in with news, interviews, and career advice during his show, which releases multiple episodes every week. + +### Software Engineering Today + +[Software Engineering Daily][6] is a daily podcast which focuses on heavily technical topics like software development and system architecture. It covering a range of topics from load balancing at scale and serverless event-driven architecture to augmented reality. Hosted by [Jeff Meyerson][7], this podcast is great for developers who have a passion for learning about complicated software topics to expand their knowledge base. + +### Talking Code + +The [Talking Code][8] podcast is from 2015, and contains 24 episodes which have "short expert interviews that help you decode what developers are saying." The hosts, [Josh Smith][9] and [Venkat Dinavahi][10], talk about diverse web development topics like how to become an effective junior developer and how to go from junior to senior developer, to topics like building modern web applications and making the most out of your analytics. This podcast is perfect for those getting into web development and those who look to level up their web development skills. + +### The Laracasts Snippet + +[The Laracasts Snippet][11] is a bite-size podcast where each episode offers a single thought on some aspect of web development. The host, [Jeffrey Way][12], is a prominent character in the Laravel community and runs the site [Laracasts][12]. His insights are broad and are useful for developers of all backgrounds. + +### Conclusion + +Podcasts are on the rise and more and more developers are listening to them. With such a rapidly expanding list of new podcasts coming out it can be tough to pick the top 5, but if you listen to these podcasts, you will have a competitive edge as a developer. + +-------------------------------------------------------------------------------- + +via: https://ryanmccue.ca/podcasts-every-developer-should-listen-too/ + +作者:[Ryan McCue][a] +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://ryanmccue.ca/author/ryan/ +[1]:http://thisdeveloperslife.com/ +[2]:https://rob.conery.io/ +[3]:https://www.hanselman.com/ +[4]:https://developertea.com/ +[5]:http://jonathancutrell.com/ +[6]:https://softwareengineeringdaily.com/ +[7]:http://jeffmeyerson.com/ +[8]:http://talkingcode.com/ +[9]:https://twitter.com/joshsmith +[10]:https://twitter.com/venkatdinavahi +[11]:https://laracasts.simplecast.fm/ +[12]:https://laracasts.com diff --git a/sources/talk/20171215 Blueprint for Simple Scalable Microservices.md b/sources/talk/20171215 Blueprint for Simple Scalable Microservices.md new file mode 100644 index 0000000000..8b79458501 --- /dev/null +++ b/sources/talk/20171215 Blueprint for Simple Scalable Microservices.md @@ -0,0 +1,48 @@ +Blueprint for Simple Scalable Microservices +====== + +![](https://ryanmccue.ca/content/images/2017/12/Copy-of-Copy-of-Electric-Love--1-.png) + +When you're building a microservice, what do you value? A fully managed and scalable system? It's hard to know where to start with AWS; there are so many options for hosting code, you can use EC2, ECS, Elastic Beanstalk, Lambda. Everyone has patterns for deploying microservices. Using the pattern below will provide a great structure for a scalable microservice architecture. + +### Elastic Beanstalk + +The first and most important piece is [Elastic Beanstalk][1]. It is a great, simple way to deploy auto-scaling microservices. All you need to do is upload your code to Elastic Beanstalk via their command line tool or management console. Once it's in Elastic Beanstalk the deployment, capacity provisioning, load balancing, auto-scaling is handled by AWS. + +### S3 + +Another important service is [S3][2]; it is an object storage built to store and retrieve data. S3 has lots of uses, from storing images, to backups. Particular use cases are storing sensitive files such as private keys, environment variable files which will be accessed and used by multiple instances or services. Finally, using S3 for less sensitive, publically accessible files like configuration files, Dockerfiles, and images. + +### Kinesis + +[Kinesis][3] is a tool which allows for microservices to communicate with each other and other projects like Lambda, which we will discuss farther down. Kinesis does this by real-time, persistent data streaming, which enables microservices to emit events. Data can be persisted for up to 7 days for persistent and batch processing. + +### RDS + +[Amazon RDS][4] is a great, fully managed relational database hosted by AWS. Using RDS over your own database server is beneficial because AWS manages everything. It makes it easy to set up, operate, and scale a relational databases. + +### Lambda + +Finally, [AWS Lambda][5] lets you run code without provisioning or managing servers. Lambda has many uses; you can even create the whole APIs with it. Some great uses for it in a microservice architecture are cron jobs and image manipulation. Crons can be scheduled with [CloudWatch][6]. + +### Conclusion + +These AWS products you can create fully scalable, stateless microservices that can communicate with each other. Using Elastic Beanstalk to run microservices, S3 to store files, Kinesis to emit events and Lambdas to subscribe to them and run other tasks. Finally, RDS for easily managing and scaling relational databases. + +-------------------------------------------------------------------------------- + +via: https://ryanmccue.ca/blueprint-for-simple-scalable-microservices/ + +作者:[Ryan McCue][a] +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://ryanmccue.ca/author/ryan/ +[1]:https://aws.amazon.com/elasticbeanstalk/?nc2=h_m1 +[2]:https://aws.amazon.com/s3/?nc2=h_m1 +[3]:https://aws.amazon.com/kinesis/?nc2=h_m1 +[4]:https://aws.amazon.com/rds/?nc2=h_m1 +[5]:https://aws.amazon.com/lambda/?nc2=h_m1 +[6]:https://aws.amazon.com/cloudwatch/?nc2=h_m1 diff --git a/sources/talk/20171223 5 Things to Look for When You Contract Out the Backend of Your App.md b/sources/talk/20171223 5 Things to Look for When You Contract Out the Backend of Your App.md new file mode 100644 index 0000000000..e7319850be --- /dev/null +++ b/sources/talk/20171223 5 Things to Look for When You Contract Out the Backend of Your App.md @@ -0,0 +1,60 @@ +5 Things to Look for When You Contract Out the Backend of Your App +====== + +![](https://ryanmccue.ca/content/images/2017/12/Copy-of-Copy-of-Copy-of-Copy-of-Copy-of-Electric-Love.png) + +For many app developers, it can be hard to know what to do when it comes to the backend of your app. There are a few options, Firebase, throw together a quick Node API, contract it out. I am going to make a blog post soon weighing the pros and cons of each of these options, but for now, let's assume you want the API done professionally. + +You are going to want to look for specific things before you give the contract to some freelancer or agency. + +### 1. Documentation + +Documentation is one of the most important pieces here, the API could be amazing, but if it is impossible to understand which endpoints are available, what parameters they provide, and what they respond with you won't have much luck integrating the API into your app. Surprisingly this is one of the pieces with most contractors get wrong. + +So what are you looking for? First, make sure they understand the importance of documentation, this alone makes a huge difference. Second, the should preferably be using an open standard like [Swagger][1] for documentation. If they do both of these things, you should have documentation covered. + +### 2. Communication + +You know the saying "communication is key," well that applies to API development. This is harder to gauge, but sometimes a developer will get the contract, and then disappear. This doesn't mean they aren't working on it, but it means there isn't a good feedback loop to sort out problems before they get too large. + +A good way to get around this is to have a weekly, or however often you want, meeting to go over progress and make sure the API is shaping up the way you want. Even if the meeting is just going over the endpoints and confirming they are returning the data you need. + +### 3. Error Handling + +Error handling is crucial, this basically means if there is an error on the backend, whether it's an invalid request or an unexpected internal server error, it will be handled properly and a useful response is given to the client. It's important that they are handled gracefully. Often this can get overlooked in the API development process. + +This is a tricky thing to look out for, but by letting them know you expect useful error messages and maybe put it into the contract, you should get the error messages you need. This may seem like a small thing but being able to present the user of your app with the actual thing they've done wrong, like "Passwords must be between 6-64 characters" improves the UX immensely. + +### 4. Database + +This section may be a bit controversial, but I think that 90% of apps really just need a SQL database. I know NoSQL is sexy, but you get so many extra benefits from using SQL I feel that's what you should use for the backend of your app. Of course, there are cases where NoSQL is the better option, but broadly speaking you should probably just use a SQL database. + +SQL adds so much added flexibility by being able to add, modify, and remove columns. The option to aggregate data with a simple query is also immensely useful. And finally, the ability to do transactions and be sure all your data is valid will help you sleep better at night. + +The reason I say all the above is because I would recommend looking for someone who is willing to build your API with a SQL database. + +### 5. Infrastructure + +The last major thing to look for when contracting out your backend is infrastructure. This is essential because you want your app to scale. If you get 10,000 users join your app in one day for some reason, you want your backend to handle that. Using services like [AWS Elastic Beanstalk][2] or [Heroku][3] you can create APIs which will scale up automatically with load. That means if your app takes off overnight your API will scale with the load and not buckle under it. + +Making sure your contractor is building it with scalability in mind is key. I wrote a [post on scalable APIs][4] if you're interested in learning more about a good AWS stack. + +### Conclusion + +It is important to get a quality backend when you contract it out. You're paying for a professional to design and build the backend of your app, so if they're lacking in any of the above points it will reduce the chance of success for but the backend, but for your app. If you make a checklist with these points and go over them with contractors, you should be able to weed out the under-qualified applicants and focus your attention on the contractors that know what they're doing. + +-------------------------------------------------------------------------------- + +via: https://ryanmccue.ca/things-to-look-for-when-you-contract-out-the-backend-your-app/ + +作者:[Ryan McCue][a] +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://ryanmccue.ca/author/ryan/ +[1]:https://swagger.io/ +[2]:https://aws.amazon.com/elasticbeanstalk/ +[3]:https://www.heroku.com/ +[4]:https://ryanmccue.ca/blueprint-for-simple-scalable-microservices/ diff --git a/sources/talk/20171225 Where to Get Your App Backend Built.md b/sources/talk/20171225 Where to Get Your App Backend Built.md new file mode 100644 index 0000000000..35d07bac18 --- /dev/null +++ b/sources/talk/20171225 Where to Get Your App Backend Built.md @@ -0,0 +1,88 @@ +Where to Get Your App Backend Built +====== + +![](https://ryanmccue.ca/content/images/2017/12/Copy-of-Copy-of-Copy-of-Copy-of-Copy-of-Copy-of-Electric-Love.png) + +Building a great app takes lots of work. From designing the views to adding the right transitions and images. One thing which is often overlooked is the backend, connecting your app to the outside world. A backend which is not up to the same quality as your app can wreck even the most perfect user interface. That is why choosing the right option for your backend budget and needs is essential. + +There are three main choices you have when you're getting it built. First, you have agencies, they are a company with salespeople, project managers, and developers. Second, you have market rate freelancers, they are developers who charge market rate for their work and are often in North America or western Europe. Finally, there are budget freelancers, they are inexpensive and usually in parts of Asia and South America. + +I am going to break down the pros and cons of each of these options. + +### Agency + +Agencies are often a safe bet if you're looking for a more hands-off approach agencies are often the way to go, they have project managers who will manage your project and communicate your requirements to developers. This takes some of the work off of your plate and can free it up to work on your app. Agencies also often have a team of developers at their disposal, so if the developer working on your project takes a vacation, they can swap another developer in without much hassle. + +With all these upsides there is a downside. Price. Having a sales team, a project management team, and a developer team isn't cheap. Agencies often cost quite a bit of money compared to freelancers. + +So in summary: + +#### Pros + + * Hands Off + * No Single Point of Failure + + + +#### Cons + + * Very expensive + + + +### Market Rate Freelancer + +Another option you have are market rate freelancers, these are highly skilled developers who often have worked in agencies, but decided to go their own way and get clients themselves. They generally produce high-quality work at a lower cost than agencies. + +The downside to freelancers is since they're only one person they might not be available right away to start your work. Especially high demand freelancers you may have to wait a few weeks or months before they start development. They also are hard to replace, if they get sick or go on vacation, it can often be hard to find someone to continue the work, unless you get a good recommendation from the freelancer. + +#### Pros + + * Cost Effective + * Similar quality to agency + * Great for short term + + + +#### Cons + + * May not be available + * Hard to replace + + + +### Budget Freelancer + +The last option I'm going over is budget freelancers who are often found on job boards such as Fiverr and Upwork. They work for very cheap, but that often comes at the cost of quality and communication. Often you will not get what you're looking for, or it will be very brittle code which buckles under strain. + +If you're on a very tight budget, it may be worth rolling the dice on a highly rated budget freelancer, although you must be okay with the risk of potentially throwing the code away. + +#### Pros + + * Very cheap + + + +#### Cons + + * Often low quality + * May not be what you asked for + + + +### Conclusion + +Getting the right backend for your app is important. It is often a good idea to stick with agencies or market rate freelancers due to the predictability and higher quality code, but if you're on a very tight budget rolling the dice with budget freelancers could pay off. At the end of the day, it doesn't matter where the code is from, as long as it works and does what it's supposed to do. + + +-------------------------------------------------------------------------------- + +via: https://ryanmccue.ca/where-to-get-your-app-backend-built/ + +作者:[Ryan McCue][a] +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://ryanmccue.ca/author/ryan/ diff --git a/sources/talk/20180110 Why isn-t open source hot among computer science students.md b/sources/talk/20180110 Why isn-t open source hot among computer science students.md deleted file mode 100644 index 282d723949..0000000000 --- a/sources/talk/20180110 Why isn-t open source hot among computer science students.md +++ /dev/null @@ -1,84 +0,0 @@ -Why isn't open source hot among computer science students? -====== - -![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/EDU_OSDC_OpenClass_520x292_FINAL_JD.png?itok=ly78pMqu) - -Image by : opensource.com - -The technical savvy and inventive energy of young programmers is alive and well. - -This was clear from the diligent work that I witnessed while participating in this year's [PennApps][1], the nation's largest college hackathon. Over the course of 48 hours, my high school- and college-age peers created projects ranging from a [blink-based communication device for shut-in patients][2] to a [burrito maker with IoT connectivity][3]. The spirit of open source was tangible throughout the event, as diverse groups bonded over a mutual desire to build, the free flow of ideas and tech know-how, fearless experimentation and rapid prototyping, and an overwhelming eagerness to participate. - -Why then, I wondered, wasn't open source a hot topic among my tech geek peers? - -To learn more about what college students think when they hear "open source," I surveyed several college students who are members of the same professional computer science organization I belong to. All members of this community must apply during high school or college and are selected based on their computer science-specific achievements and leadership--whether that means leading a school robotics team, founding a nonprofit to bring coding into insufficiently funded classrooms, or some other worthy endeavor. Given these individuals' accomplishments in computer science, I thought that their perspectives would help in understanding what young programmers find appealing (or unappealing) about open source projects. - -The online survey I prepared and disseminated included the following questions: - - * Do you like to code personal projects? Have you ever contributed to an open source project? - * Do you feel like it's more beneficial to you to start your own programming projects, or to contribute to existing open source efforts? - * How would you compare the prestige associated with coding for an organization that produces open source software versus proprietary software? - - - -Though the overwhelming majority said that they at least occasionally enjoyed coding personal projects in their spare time, most had never contributed to an open source project. When I further explored this trend, a few common preconceptions about open source projects and organizations came to light. To persuade my peers that open source projects are worth their time, and to provide educators and open source organizations insight on their students, I'll address the three top preconceptions. - -### Preconception #1: Creating personal projects from scratch is better experience than contributing to an existing open source project. - -Of the college-age programmers I surveyed, 24 out of 26 asserted that starting their own personal projects felt potentially more beneficial than building on open source ones. - -As a bright-eyed freshman in computer science, I believed this too. I had often heard from older peers that personal projects would make me more appealing to intern recruiters. No one ever mentioned the possibility of contributing to open source projects--so in my mind, it wasn't relevant. - -I now realize that open source projects offer powerful preparation for the real world. Contributing to open source projects cultivates [an awareness of how tools and languages piece together][4] in a way that even individual projects cannot. Moreover, open source is an exercise in coordination and collaboration, building students' [professional skills in communication, teamwork, and problem-solving. ][5] - -### Preconception #2: My coding skills just won't cut it. - -A few respondents said they were intimidated by open source projects, unsure of where to contribute, or fearful of stunting project progress. Unfortunately, feelings of inferiority, which too often especially affect female programmers, do not stop at the open source community. In fact, "Imposter Syndrome" may even be magnified, as [open source advocates typically reject bureaucracy][6]--and as difficult as bureaucracy makes internal mobility, it helps newcomers know their place in an organization. - -I remember how intimidated I felt by contribution guidelines while looking through open source projects on GitHub for the first time. However, guidelines are not intended to encourage exclusivity, but to provide a [guiding hand][7]. To that end, I think of guidelines as a way of establishing expectations without relying on a hierarchical structure. - -Several open source projects actively carve a place for new project contributors. [TEAMMATES][8], an educational feedback management tool, is one of the many open source projects that marks issues "up for grabs" for first-timers. In the comments, programmers of all skill levels iron out implementation details, demonstrating that open source is a place for eager new programmers and seasoned software veterans alike. For young programmers who are still hesitant, [a few open source projects][9] have been thoughtful enough to adopt an [Imposter Syndrome disclaimer][10]. - -### Preconception #3: Proprietary software firms do better work than open source software organizations. - -Only five of the 26 respondents I surveyed thought that open and proprietary software organizations were considered equal in prestige. This is likely due to the misperception that "open" means "profitless," and thus low-quality (see [Doesn't 'open source' just mean something is free of charge?][11]). - -However, open source software and profitable software are not mutually exclusive. In fact, small and large businesses alike often pay for free open source software to receive technical support services. As [Red Hat CEO Jim Whitehurst explains][12], "We have engineering teams that track every single change--a bug fix, security enhancement, or whatever--made to Linux, and ensure our customers' mission-critical systems remain up-to-date and stable." - -Moreover, the nature of openness facilitates rather than hinders quality by enabling more people to examine source code. [Igor Faletski, CEO of Mobify][13], writes that Mobify's team of "25 software developers and quality assurance professionals" is "no match for the all the software developers in the world who might make use of [Mobify's open source] platform. Each of them is a potential tester of, or contributor to, the project." - -Another problem may be that young programmers are not aware of the open source software they interact with every day. I used many tools--including MySQL, Eclipse, Atom, Audacity, and WordPress--for months or even years without realizing they were open source. College students, who often rush to download syllabus-specified software to complete class assignments, may be unaware of which software is open source. This makes open source seem more foreign than it is. - -So students, don't knock open source before you try it. Check out this [list of beginner-friendly projects][14] and [these six starting points][15] to begin your open source journey. - -Educators, remind your students of the open source community's history of successful innovation, and lead them toward open source projects outside the classroom. You will help develop sharper, better-prepared, and more confident students. - -### About the author -Susie Choi - Susie is an undergraduate student studying computer science at Duke University. She is interested in the implications of technological innovation and open source principles for issues relating to education and socioeconomic inequality. - --------------------------------------------------------------------------------- - -via: https://opensource.com/article/17/12/students-and-open-source-3-common-preconceptions - -作者:[Susie Choi][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/susiechoi -[1]:http://pennapps.com/ -[2]:https://devpost.com/software/blink-9o2iln -[3]:https://devpost.com/software/daburrito -[4]:https://hackernoon.com/benefits-of-contributing-to-open-source-2c97b6f529e9 -[5]:https://opensource.com/education/16/8/5-reasons-student-involvement-open-source -[6]:https://opensource.com/open-organization/17/7/open-thinking-curb-bureaucracy -[7]:https://opensource.com/life/16/3/contributor-guidelines-template-and-tips -[8]:https://github.com/TEAMMATES/teammates/issues?q=is%3Aissue+is%3Aopen+label%3Ad.FirstTimers -[9]:https://github.com/adriennefriend/imposter-syndrome-disclaimer/blob/master/examples.md -[10]:https://github.com/adriennefriend/imposter-syndrome-disclaimer -[11]:https://opensource.com/resources/what-open-source -[12]:https://hbr.org/2013/01/yes-you-can-make-money-with-op -[13]:https://hbr.org/2012/10/open-sourcing-may-be-worth -[14]:https://github.com/MunGell/awesome-for-beginners -[15]:https://opensource.com/life/16/1/6-beginner-open-source diff --git a/sources/talk/20180117 How to get into DevOps.md b/sources/talk/20180117 How to get into DevOps.md index 09e50ae4f2..b549c3b32e 100644 --- a/sources/talk/20180117 How to get into DevOps.md +++ b/sources/talk/20180117 How to get into DevOps.md @@ -1,3 +1,4 @@ +XLCYun 翻译中 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) diff --git a/sources/talk/20180122 How to price cryptocurrencies.md b/sources/talk/20180122 How to price cryptocurrencies.md index 061090db5a..19d785164c 100644 --- a/sources/talk/20180122 How to price cryptocurrencies.md +++ b/sources/talk/20180122 How to price cryptocurrencies.md @@ -1,3 +1,4 @@ +translating by wyxplus How to price cryptocurrencies ====== 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 6acd6e53f2..74bf66df68 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,3 +1,4 @@ +translating by leowang Moving to Linux from dated Windows machines ====== diff --git a/sources/talk/20180127 Write Dumb Code.md b/sources/talk/20180127 Write Dumb Code.md new file mode 100644 index 0000000000..acc647b0e5 --- /dev/null +++ b/sources/talk/20180127 Write Dumb Code.md @@ -0,0 +1,54 @@ +Write Dumb Code +====== +The best way you can contribute to an open source project is to remove lines of code from it. We should endeavor to write code that a novice programmer can easily understand without explanation or that a maintainer can understand without significant time investment. + +As students we attempt increasingly challenging problems with increasingly sophisticated technologies. We first learn loops, then functions, then classes, etc.. We are praised as we ascend this hierarchy, writing longer programs with more advanced technology. We learn that experienced programmers use monads while new programmers use for loops. + +Then we graduate and find a job or open source project to work on with others. We search for something that we can add, and implement a solution pridefully, using the all the tricks that we learned in school. + +Ah ha! I can extend this project to do X! And I can use inheritance here! Excellent! + +We implement this feature and feel accomplished, and with good reason. Programming in real systems is no small accomplishment. This was certainly my experience. I was excited to write code and proud that I could show off all of the things that I knew how to do to the world. As evidence of my historical love of programming technology, here is a [linear algebra language][1] built with a another meta-programming language. Notice that no one has touched this code in several years. + +However after maintaining code a bit more I now think somewhat differently. + + 1. We should not seek to build software. Software is the currency that we pay to solve problems, which is our actual goal. We should endeavor to build as little software as possible to solve our problems. + 2. We should use technologies that are as simple as possible, so that as many people as possible can use and extend them without needing to understand our advanced techniques. We should use advanced techniques only when we are not smart enough to figure out how to use more common techniques. + + + +Neither of these points are novel. Most people I meet agree with them to some extent, but somehow we forget them when we go to contribute to a new project. The instinct to contribute by building and to demonstrate sophistication often take over. + +### Software is a cost + +Every line that you write costs people time. It costs you time to write it of course, but you are willing to make this personal sacrifice. However this code also costs the reviewers their time to understand it. It costs future maintainers and developers their time as they fix and modify your code. They could be spending this time outside in the sunshine or with their family. + +So when you add code to a project you should feel meek. It should feel as though you are eating with your family and there isn't enough food on the table. You should take only what you need and no more. The people with you will respect you for your efforts to restrict yourself. Solving problems with less code is a hard, but it is a burden that you take on yourself to lighten the burdens of others. + +### Complex technologies are harder to maintain + +As students, we demonstrate merit by using increasingly advanced technologies. Our measure of worth depends on our ability to use functions, then classes, then higher order functions, then monads, etc. in public projects. We show off our solutions to our peers and feel pride or shame according to our sophistication. + +However when working with a team to solve problems in the world the situation is reversed. Now we strive to solve problems with code that is as simple as possible. When we solve a problem simply we enable junior programmers to extend our solution to solve other problems. Simple code enables others and boosts our impact. We demonstrate our value by solving hard problems with only basic techniques. + +Look! I replaced this recursive function with a for loop and it still does everything that we need it to. I know it's not as clever, but I noticed that the interns were having trouble with it and I thought that this change might help. + +If you are a good programmer then you don't need to demonstrate that you know cool tricks. Instead, you can demonstrate your value by solving a problem in a simple way that enables everyone on your team to contribute in the future. + +### But moderation, of course + +That being said, over-adherence to the "build things with simple tools" dogma can be counter productive. Often a recursive solution can be much simpler than a for-loop solution and often times using a Class or a Monad is the right approach. But we should be mindful when using these technologies that we are building for ourselves our own system; a system with which others have had no experience. + + +-------------------------------------------------------------------------------- + +via: http://matthewrocklin.com/blog/work/2018/01/27/write-dumb-code + +作者:[Matthew Rocklin][a] +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:http://matthewrocklin.com +[1]:https://github.com/mrocklin/matrix-algebra diff --git a/sources/talk/20180128 Being open about data privacy.md b/sources/talk/20180128 Being open about data privacy.md new file mode 100644 index 0000000000..2deb88922b --- /dev/null +++ b/sources/talk/20180128 Being open about data privacy.md @@ -0,0 +1,107 @@ +Being open about data privacy +====== +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/GOV_opendata.png?itok=M8L2HGVx) + + +Image by : opensource.com + +Today is [Data Privacy Day][1], ("Data Protection Day" in Europe), and you might think that those of us in the open source world should think that all data should be free, [as information supposedly wants to be][2], but life's not that simple. That's for two main reasons: + + 1. Most of us (and not just in open source) believe there's at least some data about us that we might not feel happy sharing (I compiled an example list in [a post][3] I published a while ago). + 2. Many of us working in open source actually work for commercial companies or other organisations subject to legal requirements around what they can share. + + + +So actually, data privacy is something that's important for pretty much everybody. + +It turns out that the starting point for what data people and governments believe should be available for organisations to use is somewhat different between the U.S. and Europe, with the former generally providing more latitude for entities--particularly, the more cynical might suggest, large commercial entities--to use data they've collected about us as they will. Europe, on the other hand, has historically taken a more restrictive view, and on the 25th of May, Europe's view arguably will have triumphed. + +### The impact of GDPR + +That's a rather sweeping statement, but the fact remains that this is the date on which a piece of legislation called the General Data Protection Regulation (GDPR), enacted by the European Union in 2016, becomes enforceable. The GDPR basically provides a stringent set of rules about how personal data can be stored, what it can be used for, who can see it, and how long it can be kept. It also describes what personal data is--and it's a pretty broad set of items, from your name and home address to your medical records and on through to your computer's IP address. + +What is important about the GDPR, though, is that it doesn't apply just to European companies, but to any organisation processing data about EU citizens. If you're an Argentinian, Japanese, U.S., or Russian company and you're collecting data about an EU citizen, you're subject to it. + +"Pah!" you may say,1 "I'm not based in the EU: what can they do to me?" The answer is simple: If you want to continue doing any business in the EU, you'd better comply, because if you breach GDPR rules, you could be liable for up to four percent of your global revenues. Yes, that's global revenues: not just revenues in a particular country in Europe or across the EU, not just profits, but global revenues. Those are the sorts of numbers that should lead you to talk to your legal team, who will direct you to your exec team, who will almost immediately direct you to your IT group to make sure you're compliant in pretty short order. + +This may seem like it's not particularly relevant to non-EU citizens, but it is. For most companies, it's going to be simpler and more efficient to implement the same protection measures for data associated with all customers, partners, and employees they deal with, rather than just targeting specific measures at EU citizens. This has got to be a good thing.2 + +However, just because GDPR will soon be applied to organisations across the globe doesn't mean that everything's fine and dandy3: it's not. We give away information about ourselves all the time--and permission for companies to use it. + +There's a telling (though disputed) saying: "If you're not paying, you're the product." What this suggests is that if you're not paying for a service, then somebody else is paying to use your data. Do you pay to use Facebook? Twitter? Gmail? How do you think they make their money? Well, partly through advertising, and some might argue that's a service they provide to you, but actually that's them using your data to get money from the advertisers. You're not really a customer of advertising--it's only once you buy something from the advertiser that you become their customer, but until you do, the relationship is between the the owner of the advertising platform and the advertiser. + +Some of these services allow you to pay to reduce or remove advertising (Spotify is a good example), but on the other hand, advertising may be enabled even for services that you think you do pay for (Amazon is apparently working to allow adverts via Alexa, for instance). Unless we want to start paying to use all of these "free" services, we need to be aware of what we're giving up, and making some choices about what we expose and what we don't. + +### Who's the customer? + +There's another issue around data that should be exercising us, and it's a direct consequence of the amounts of data that are being generated. There are many organisations out there--including "public" ones like universities, hospitals, or government departments4--who generate enormous quantities of data all the time, and who just don't have the capacity to store it. It would be a different matter if this data didn't have long-term value, but it does, as the tools for handling Big Data are developing, and organisations are realising they can be mining this now and in the future. + +The problem they face, though, as the amount of data increases and their capacity to store it fails to keep up, is what to do with it. Luckily--and I use this word with a very heavy dose of irony,5 big corporations are stepping in to help them. "Give us your data," they say, "and we'll host it for free. We'll even let you use the data you collected when you want to!" Sounds like a great deal, yes? A fantastic example of big corporations6 taking a philanthropic stance and helping out public organisations that have collected all of that lovely data about us. + +Sadly, philanthropy isn't the only reason. These hosting deals come with a price: in exchange for agreeing to host the data, these corporations get to sell access to it to third parties. And do you think the public organisations, or those whose data is collected, will get a say in who these third parties are or how they will use it? I'll leave this as an exercise for the reader.7 + +### Open and positive + +It's not all bad news, however. There's a growing "open data" movement among governments to encourage departments to make much of their data available to the public and other bodies for free. In some cases, this is being specifically legislated. Many voluntary organisations--particularly those receiving public funding--are starting to do the same. There are glimmerings of interest even from commercial organisations. What's more, there are techniques becoming available, such as those around differential privacy and multi-party computation, that are beginning to allow us to mine data across data sets without revealing too much about individuals--a computing problem that has historically been much less tractable than you might otherwise expect. + +What does this all mean to us? Well, I've written before on Opensource.com about the [commonwealth of open source][4], and I'm increasingly convinced that we need to look beyond just software to other areas: hardware, organisations, and, relevant to this discussion, data. Let's imagine that you're a company (A) that provides a service to another company, a customer (B).8 There are four different types of data in play: + + 1. Data that's fully open: visible to A, B, and the rest of the world + 2. Data that's known, shared, and confidential: visible to A and B, but nobody else + 3. Data that's company-confidential: visible to A, but not B + 4. Data that's customer-confidential: visible to B, but not A + + + +First of all, maybe we should be a bit more open about data and default to putting it into bucket 1. That data--on self-driving cars, voice recognition, mineral deposits, demographic statistics--could be enormously useful if it were available to everyone.9 Also, wouldn't it be great if we could find ways to make the data in buckets 2, 3, and 4--or at least some of it--available in bucket 1, whilst still keeping the details confidential? That's the hope for some of these new techniques being researched. They're a way off, though, so don't get too excited, and in the meantime, start thinking about making more of your data open by default. + +### Some concrete steps + +So, what can we do around data privacy and being open? Here are a few concrete steps that occurred to me: please use the comments to contribute more. + + * Check to see whether your organisation is taking GDPR seriously. If it isn't, push for it. + * Default to encrypting sensitive data (or hashing where appropriate), and deleting when it's no longer required--there's really no excuse for data to be in the clear to these days except for when it's actually being processed. + * Consider what information you disclose when you sign up to services, particularly social media. + * Discuss this with your non-technical friends. + * Educate your children, your friends' children, and their friends. Better yet, go and talk to their teachers about it and present something in their schools. + * Encourage the organisations you work for, volunteer for, or interact with to make data open by default. Rather than thinking, "why should I make this public?" start with "why shouldn't I make this public?" + * Try accessing some of the open data sources out there. Mine it, create apps that use it, perform statistical analyses, draw pretty graphs,10 make interesting music, but consider doing something with it. Tell the organisations that sourced it, thank them, and encourage them to do more. + + + +1. Though you probably won't, I admit. + +2. Assuming that you believe that your personal data should be protected. + +3. If you're wondering what "dandy" means, you're not alone at this point. + +4. Exactly how public these institutions seem to you will probably depend on where you live: [YMMV][5]. + +5. And given that I'm British, that's a really very, very heavy dose. + +6. And they're likely to be big corporations: nobody else can afford all of that storage and the infrastructure to keep it available. + +7. No. The answer's "no." + +8. Although the example works for people, too. Oh, look: A could be Alice, B could be Bob… + +9. Not that we should be exposing personal data or data that actually needs to be confidential, of course--not that type of data. + +10. A friend of mine decided that it always seemed to rain when she picked her children up from school, so to avoid confirmation bias, she accessed rainfall information across the school year and created graphs that she shared on social media. + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/1/being-open-about-data-privacy + +作者:[Mike Bursell][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/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/sources/talk/20180131 An old DOS BBS in a Docker container.md b/sources/talk/20180131 An old DOS BBS in a Docker container.md new file mode 100644 index 0000000000..769b5db1bd --- /dev/null +++ b/sources/talk/20180131 An old DOS BBS in a Docker container.md @@ -0,0 +1,51 @@ +An old DOS BBS in a Docker container +====== +Awhile back, I wrote about [my Debian Docker base images][1]. I decided to extend this concept a bit further: to running DOS applications in Docker. + +But first, a screenshot: + +![][2] + +It turns out this is possible, but difficult. I went through all three major DOS emulators available (dosbox, qemu, and dosemu). I got them all running inside the Docker container, but had a number of, er, fun issues to resolve. + +The general thing one has to do here is present a fake modem to the DOS environment. This needs to be exposed outside the container as a TCP port. That much is possible in various ways -- I wound up using tcpser. dosbox had a TCP modem interface, but it turned out to be too buggy for this purpose. + +The challenge comes in where you want to be able to accept more than one incoming telnet (or TCP) connection at a time. DOS was not a multitasking operating system, so there were any number of hackish solutions back then. One might have had multiple physical computers, one for each incoming phone line. Or they might have run multiple pseudo-DOS instances under a multitasking layer like [DESQview][3], OS/2, or even Windows 3.1. + +(Side note: I just learned of [DESQview/X][4], which integrated DESQview with X11R5 and [replaced the Windows 3 drivers][5] to allow running Windows as an X application). + +For various reasons, I didn't want to try running one of those systems inside Docker. That left me with emulating the original multiple physical node setup. In theory, pretty easy -- spin up a bunch of DOS boxes, each using at most 1MB of emulated RAM, and go to town. But here came the challenge. + +In a multiple-physical-node setup, you need some sort of file sharing, because your nodes have to access the shared message and file store. There were a myriad of clunky ways to do this in the old DOS days - [Netware][6], [LAN manager][7], even some PC NFS clients. I didn't have access to Netware. I tried the Microsoft LM client in DOS, talking to a Samba server running inside the Docker container. This I got working, but the LM client used so much RAM that, even with various high memory tricks, BBS software wasn't going to run. I couldn't just mount an underlying filesystem in multiple dosbox instances either, because dosbox did caching that wasn't going to be compatible. + +This is why I wound up using dosemu. Besides being a more complete emulator than dosbox, it had a way of sharing the host's filesystems that was going to work. + +So, all of this wound up with this: [jgoerzen/docker-bbs-renegade][8]. + +I also prepared building blocks for others that want to do something similar: [docker-dos-bbs][9] and the lower-level [docker-dosemu][10]. + +As a side bonus, I also attempted running this under Joyent's Triton (SmartOS, Solaris-based). I was pleasantly impressed that I got it all almost working there. So yes, a Renegade DOS BBS running under a Linux-based DOS emulator in a container on a Solaris machine. + + + +-------------------------------------------------------------------------------- + +via: http://changelog.complete.org/archives/9836-an-old-dos-bbs-in-a-docker-container + +作者:[John Goerzen][a] +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:http://changelog.complete.org/archives/author/jgoerzen +[1]:https://changelog.complete.org/archives/9794-fixing-the-problems-with-docker-images +[2]:https://raw.githubusercontent.com/jgoerzen/docker-bbs-renegade/master/renegade-login.png +[3]:https://en.wikipedia.org/wiki/DESQview +[4]:http://toastytech.com/guis/dvx.html +[5]:http://toastytech.com/guis/dvx3.html +[6]:https://en.wikipedia.org/wiki/NetWare +[7]:https://en.wikipedia.org/wiki/LAN_Manager +[8]:https://github.com/jgoerzen/docker-bbs-renegade +[9]:https://github.com/jgoerzen/docker-dos-bbs +[10]:https://github.com/jgoerzen/docker-dosemu diff --git a/sources/talk/20180201 6 pivotal moments in open source history.md b/sources/talk/20180201 6 pivotal moments in open source history.md new file mode 100644 index 0000000000..2d0f80dd1f --- /dev/null +++ b/sources/talk/20180201 6 pivotal moments in open source history.md @@ -0,0 +1,94 @@ +6 pivotal moments in open source history +============================================================ + +### Here's how open source developed from a printer jam solution at MIT to a major development model in the tech industry today. + +![6 pivotal moments in open source history](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/welcome-open-sign-door-osdc-lead.png?itok=i9jCnaiu "6 pivotal moments in open source history") +Image credits : [Alan Levine][4]. [CC0 1.0][5] + +Open source has taken a prominent role in the IT industry today. It is everywhere from the smallest embedded systems to the biggest supercomputer, from the phone in your pocket to the software running the websites and infrastructure of the companies we engage with every day. Let's explore how we got here and discuss key moments from the past 40 years that have paved a path to the current day. + +### 1\. RMS and the printer + +In the late 1970s, [Richard M. Stallman (RMS)][6] was a staff programmer at MIT. His department, like those at many universities at the time, shared a PDP-10 computer and a single printer. One problem they encountered was that paper would regularly jam in the printer, causing a string of print jobs to pile up in a queue until someone fixed the jam. To get around this problem, the MIT staff came up with a nice social hack: They wrote code for the printer driver so that when it jammed, a message would be sent to everyone who was currently waiting for a print job: "The printer is jammed, please fix it." This way, it was never stuck for long. + +In 1980, the lab accepted a donation of a brand-new laser printer. When Stallman asked for the source code for the printer driver, however, so he could reimplement the social hack to have the system notify users on a paper jam, he was told that this was proprietary information. He heard of a researcher in a different university who had the source code for a research project, and when the opportunity arose, he asked this colleague to share it—and was shocked when they refused. They had signed an NDA, which Stallman took as a betrayal of the hacker culture. + +The late '70s and early '80s represented an era where software, which had traditionally been given away with the hardware in source code form, was seen to be valuable. Increasingly, MIT researchers were starting software companies, and selling licenses to the software was key to their business models. NDAs and proprietary software licenses became the norms, and the best programmers were hired from universities like MIT to work on private development projects where they could no longer share or collaborate. + +As a reaction to this, Stallman resolved that he would create a complete operating system that would not deprive users of the freedom to understand how it worked, and would allow them to make changes if they wished. It was the birth of the free software movement. + +### 2\. Creation of GNU and the advent of free software + +By late 1983, Stallman was ready to announce his project and recruit supporters and helpers. In September 1983, [he announced the creation of the GNU project][7] (GNU stands for GNU's Not Unix—a recursive acronym). The goal of the project was to clone the Unix operating system to create a system that would give complete freedom to users. + +In January 1984, he started working full-time on the project, first creating a compiler system (GCC) and various operating system utilities. Early in 1985, he published "[The GNU Manifesto][8]," which was a call to arms for programmers to join the effort, and launched the Free Software Foundation in order to accept donations to support the work. This document is the founding charter of the free software movement. + +### 3\. The writing of the GPL + +Until 1989, software written and released by the [Free Software Foundation][9] and RMS did not have a single license. Emacs was released under the Emacs license, GCC was released under the GCC license, and so on; however, after a company called Unipress forced Stallman to stop distributing copies of an Emacs implementation they had acquired from James Gosling (of Java fame), he felt that a license to secure user freedoms was important. + +The first version of the GNU General Public License was released in 1989, and it encapsulated the values of copyleft (a play on words—what is the opposite of copyright?): You may use, copy, distribute, and modify the software covered by the license, but if you make changes, you must share the modified source code alongside the modified binaries. This simple requirement to share modified software, in combination with the advent of the internet in the 1990s, is what enabled the decentralized, collaborative development model of the free software movement to flourish. + +### 4\. "The Cathedral and the Bazaar" + +By the mid-1990s, Linux was starting to take off, and free software had become more mainstream—or perhaps "less fringe" would be more accurate. The Linux kernel was being developed in a way that was completely different to anything people had been seen before, and was very successful doing it. Out of the chaos of the kernel community came order, and a fast-moving project. + +In 1997, Eric S. Raymond published the seminal essay, "[The Cathedral and the Bazaar][10]," comparing and contrasting the development methodologies and social structure of GCC and the Linux kernel and talking about his own experiences with a "bazaar" development model with the Fetchmail project. Many of the principles that Raymond describes in this essay will later become central to agile development and the DevOps movement—"release early, release often," refactoring of code, and treating users as co-developers are all fundamental to modern software development. + +This essay has been credited with bringing free software to a broader audience, and with convincing executives at software companies at the time that releasing their software under a free software license was the right thing to do. Raymond went on to be instrumental in the coining of the term "open source" and the creation of the Open Source Institute. + +"The Cathedral and the Bazaar" was credited as a key document in the 1998 release of the source code for the Netscape web browser Mozilla. At the time, this was the first major release of an existing, widely used piece of desktop software as free software, which brought it further into the public eye. + +### 5\. Open source + +As far back as 1985, the ambiguous nature of the word "free", used to describe software freedom, was identified as problematic by RMS himself. In the GNU Manifesto, he identified "give away" and "for free" as terms that confused zero price and user freedom. "Free as in freedom," "Speech not beer," and similar mantras were common when free software hit a mainstream audience in the late 1990s, but a number of prominent community figures argued that a term was needed that made the concept more accessible to the general public. + +After Netscape released the source code for Mozilla in 1998 (see #4), a group of people, including Eric Raymond, Bruce Perens, Michael Tiemann, Jon "Maddog" Hall, and many of the leading lights of the free software world, gathered in Palo Alto to discuss an alternative term. The term "open source" was [coined by Christine Peterson][11] to describe free software, and the Open Source Institute was later founded by Bruce Perens and Eric Raymond. The fundamental difference with proprietary software, they argued, was the availability of the source code, and so this was what should be put forward first in the branding. + +Later that year, at a summit organized by Tim O'Reilly, an extended group of some of the most influential people in the free software world at the time gathered to debate various new brands for free software. In the end, "open source" edged out "sourceware," and open source began to be adopted by many projects in the community. + +There was some disagreement, however. Richard Stallman and the Free Software Foundation continued to champion the term "free software," because to them, the fundamental difference with proprietary software was user freedom, and the availability of source code was just a means to that end. Stallman argued that removing the focus on freedom would lead to a future where source code would be available, but the user of the software would not be able to avail of the freedom to modify the software. With the advent of web-deployed software-as-a-service and open source firmware embedded in devices, the battle continues to be waged today. + +### 6\. Corporate investment in open source—VA Linux, Red Hat, IBM + +In the late 1990s, a series of high-profile events led to a huge increase in the professionalization of free and open source software. Among these, the highest-profile events were the IPOs of VA Linux and Red Hat in 1999\. Both companies had massive gains in share price on their opening days as publicly traded companies, proving that open source was now going commercial and mainstream. + +Also in 1999, IBM announced that they were supporting Linux by investing $1 billion in its development, making is less risky to traditional enterprise users. The following year, Sun Microsystems released the source code to its cross-platform office suite, StarOffice, and created the [OpenOffice.org][12] project. + +The combined effect of massive Silicon Valley funding of open source projects, the attention of Wall Street for young companies built around open source software, and the market credibility that tech giants like IBM and Sun Microsystems brought had combined to create the massive adoption of open source, and the embrace of the open development model that helped it thrive have led to the dominance of Linux and open source in the tech industry today. + + _Which pivotal moments would you add to the list? Let us know in the comments._ + +### About the author + + [![](https://opensource.com/sites/default/files/styles/profile_pictures/public/pictures/picture-11423-8ecef7f357341aaa7aee8b43e9b530c9.png?itok=n1snBFq3)][13] Dave Neary - Dave Neary is a member of the Open Source and Standards team at Red Hat, helping make Open Source projects important to Red Hat be successful. Dave has been around the free and open source software world, wearing many different hats, since sending his first patch to the GIMP in 1999.[More about me][2] + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/2/pivotal-moments-history-open-source + +作者:[Dave Neary ][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/dneary +[1]:https://opensource.com/article/18/2/pivotal-moments-history-open-source?rate=gsG-JrjfROWACP7i9KUoqmH14JDff8-31C2IlNPPyu8 +[2]:https://opensource.com/users/dneary +[3]:https://opensource.com/user/16681/feed +[4]:https://www.flickr.com/photos/cogdog/6476689463/in/photolist-aSjJ8H-qHAvo4-54QttY-ofm5ZJ-9NnUjX-tFxS7Y-bPPjtH-hPYow-bCndCk-6NpFvF-5yQ1xv-7EWMXZ-48RAjB-5EzYo3-qAFAdk-9gGty4-a2BBgY-bJsTcF-pWXATc-6EBTmq-SkBnSJ-57QJco-ddn815-cqt5qG-ddmYSc-pkYxRz-awf3n2-Rvnoxa-iEMfeG-bVfq5-jXy74D-meCC1v-qx22rx-fMScsJ-ci1435-ie8P5-oUSXhp-xJSm9-bHgApk-mX7ggz-bpsxd7-8ukud7-aEDmBj-qWkytq-ofwhdM-b7zSeD-ddn5G7-ddn5gb-qCxnB2-S74vsk +[5]:https://creativecommons.org/publicdomain/zero/1.0/ +[6]:https://en.wikipedia.org/wiki/Richard_Stallman +[7]:https://groups.google.com/forum/#!original/net.unix-wizards/8twfRPM79u0/1xlglzrWrU0J +[8]:https://www.gnu.org/gnu/manifesto.en.html +[9]:https://www.fsf.org/ +[10]:https://en.wikipedia.org/wiki/The_Cathedral_and_the_Bazaar +[11]:https://opensource.com/article/18/2/coining-term-open-source-software +[12]:http://www.openoffice.org/ +[13]:https://opensource.com/users/dneary +[14]:https://opensource.com/users/dneary +[15]:https://opensource.com/users/dneary +[16]:https://opensource.com/article/18/2/pivotal-moments-history-open-source#comments +[17]:https://opensource.com/tags/licensing \ No newline at end of file diff --git a/sources/talk/20180201 How I coined the term open source.md b/sources/talk/20180201 How I coined the term open source.md new file mode 100644 index 0000000000..5af8d69de7 --- /dev/null +++ b/sources/talk/20180201 How I coined the term open source.md @@ -0,0 +1,103 @@ +How I coined the term 'open source' +============================================================ + +### Christine Peterson finally publishes her account of that fateful day, 20 years ago. + +![How I coined the term 'open source'](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/hello-name-sticker-badge-tag.png?itok=fAgbMgBb "How I coined the term 'open source'") +Image by : opensource.com + +In a few days, on February 3, the 20th anniversary of the introduction of the term "[open source software][6]" is upon us. As open source software grows in popularity and powers some of the most robust and important innovations of our time, we reflect on its rise to prominence. + +I am the originator of the term "open source software" and came up with it while executive director at Foresight Institute. Not a software developer like the rest, I thank Linux programmer Todd Anderson for supporting the term and proposing it to the group. + +This is my account of how I came up with it, how it was proposed, and the subsequent reactions. Of course, there are a number of accounts of the coining of the term, for example by Eric Raymond and Richard Stallman, yet this is mine, written on January 2, 2006. + +It has never been published, until today. + +* * * + +The introduction of the term "open source software" was a deliberate effort to make this field of endeavor more understandable to newcomers and to business, which was viewed as necessary to its spread to a broader community of users. The problem with the main earlier label, "free software," was not its political connotations, but that—to newcomers—its seeming focus on price is distracting. A term was needed that focuses on the key issue of source code and that does not immediately confuse those new to the concept. The first term that came along at the right time and fulfilled these requirements was rapidly adopted: open source. + +This term had long been used in an "intelligence" (i.e., spying) context, but to my knowledge, use of the term with respect to software prior to 1998 has not been confirmed. The account below describes how the term [open source software][7] caught on and became the name of both an industry and a movement. + +### Meetings on computer security + +In late 1997, weekly meetings were being held at Foresight Institute to discuss computer security. Foresight is a nonprofit think tank focused on nanotechnology and artificial intelligence, and software security is regarded as central to the reliability and security of both. We had identified free software as a promising approach to improving software security and reliability and were looking for ways to promote it. Interest in free software was starting to grow outside the programming community, and it was increasingly clear that an opportunity was coming to change the world. However, just how to do this was unclear, and we were groping for strategies. + +At these meetings, we discussed the need for a new term due to the confusion factor. The argument was as follows: those new to the term "free software" assume it is referring to the price. Oldtimers must then launch into an explanation, usually given as follows: "We mean free as in freedom, not free as in beer." At this point, a discussion on software has turned into one about the price of an alcoholic beverage. The problem was not that explaining the meaning is impossible—the problem was that the name for an important idea should not be so confusing to newcomers. A clearer term was needed. No political issues were raised regarding the free software term; the issue was its lack of clarity to those new to the concept. + +### Releasing Netscape + +On February 2, 1998, Eric Raymond arrived on a visit to work with Netscape on the plan to release the browser code under a free-software-style license. We held a meeting that night at Foresight's office in Los Altos to strategize and refine our message. In addition to Eric and me, active participants included Brian Behlendorf, Michael Tiemann, Todd Anderson, Mark S. Miller, and Ka-Ping Yee. But at that meeting, the field was still described as free software or, by Brian, "source code available" software. + +While in town, Eric used Foresight as a base of operations. At one point during his visit, he was called to the phone to talk with a couple of Netscape legal and/or marketing staff. When he was finished, I asked to be put on the phone with them—one man and one woman, perhaps Mitchell Baker—so I could bring up the need for a new term. They agreed in principle immediately, but no specific term was agreed upon. + +Between meetings that week, I was still focused on the need for a better name and came up with the term "open source software." While not ideal, it struck me as good enough. I ran it by at least four others: Eric Drexler, Mark Miller, and Todd Anderson liked it, while a friend in marketing and public relations felt the term "open" had been overused and abused and believed we could do better. He was right in theory; however, I didn't have a better idea, so I thought I would try to go ahead and introduce it. In hindsight, I should have simply proposed it to Eric Raymond, but I didn't know him well at the time, so I took an indirect strategy instead. + +Todd had agreed strongly about the need for a new term and offered to assist in getting the term introduced. This was helpful because, as a non-programmer, my influence within the free software community was weak. My work in nanotechnology education at Foresight was a plus, but not enough for me to be taken very seriously on free software questions. As a Linux programmer, Todd would be listened to more closely. + +### The key meeting + +Later that week, on February 5, 1998, a group was assembled at VA Research to brainstorm on strategy. Attending—in addition to Eric Raymond, Todd, and me—were Larry Augustin, Sam Ockman, and attending by phone, Jon "maddog" Hall. + +The primary topic was promotion strategy, especially which companies to approach. I said little, but was looking for an opportunity to introduce the proposed term. I felt that it wouldn't work for me to just blurt out, "All you technical people should start using my new term." Most of those attending didn't know me, and for all I knew, they might not even agree that a new term was greatly needed, or even somewhat desirable. + +Fortunately, Todd was on the ball. Instead of making an assertion that the community should use this specific new term, he did something less directive—a smart thing to do with this community of strong-willed individuals. He simply used the term in a sentence on another topic—just dropped it into the conversation to see what happened. I went on alert, hoping for a response, but there was none at first. The discussion continued on the original topic. It seemed only he and I had noticed the usage. + +Not so—memetic evolution was in action. A few minutes later, one of the others used the term, evidently without noticing, still discussing a topic other than terminology. Todd and I looked at each other out of the corners of our eyes to check: yes, we had both noticed what happened. I was excited—it might work! But I kept quiet: I still had low status in this group. Probably some were wondering why Eric had invited me at all. + +Toward the end of the meeting, the [question of terminology][8] was brought up explicitly, probably by Todd or Eric. Maddog mentioned "freely distributable" as an earlier term, and "cooperatively developed" as a newer term. Eric listed "free software," "open source," and "sourceware" as the main options. Todd advocated the "open source" model, and Eric endorsed this. I didn't say much, letting Todd and Eric pull the (loose, informal) consensus together around the open source name. It was clear that to most of those at the meeting, the name change was not the most important thing discussed there; a relatively minor issue. Only about 10% of my notes from this meeting are on the terminology question. + +But I was elated. These were some key leaders in the community, and they liked the new name, or at least didn't object. This was a very good sign. There was probably not much more I could do to help; Eric Raymond was far better positioned to spread the new meme, and he did. Bruce Perens signed on to the effort immediately, helping set up [Opensource.org][9] and playing a key role in spreading the new term. + +For the name to succeed, it was necessary, or at least highly desirable, that Tim O'Reilly agree and actively use it in his many projects on behalf of the community. Also helpful would be use of the term in the upcoming official release of the Netscape Navigator code. By late February, both O'Reilly & Associates and Netscape had started to use the term. + +### Getting the name out + +After this, there was a period during which the term was promoted by Eric Raymond to the media, by Tim O'Reilly to business, and by both to the programming community. It seemed to spread very quickly. + +On April 7, 1998, Tim O'Reilly held a meeting of key leaders in the field. Announced in advance as the first "[Freeware Summit][10]," by April 14 it was referred to as the first "[Open Source Summit][11]." + +These months were extremely exciting for open source. Every week, it seemed, a new company announced plans to participate. Reading Slashdot became a necessity, even for those like me who were only peripherally involved. I strongly believe that the new term was helpful in enabling this rapid spread into business, which then enabled wider use by the public. + +A quick Google search indicates that "open source" appears more often than "free software," but there still is substantial use of the free software term, which remains useful and should be included when communicating with audiences who prefer it. + +### A happy twinge + +When an [early account][12] of the terminology change written by Eric Raymond was posted on the Open Source Initiative website, I was listed as being at the VA brainstorming meeting, but not as the originator of the term. This was my own fault; I had neglected to tell Eric the details. My impulse was to let it pass and stay in the background, but Todd felt otherwise. He suggested to me that one day I would be glad to be known as the person who coined the name "open source software." He explained the situation to Eric, who promptly updated his site. + +Coming up with a phrase is a small contribution, but I admit to being grateful to those who remember to credit me with it. Every time I hear it, which is very often now, it gives me a little happy twinge. + +The big credit for persuading the community goes to Eric Raymond and Tim O'Reilly, who made it happen. Thanks to them for crediting me, and to Todd Anderson for his role throughout. The above is not a complete account of open source history; apologies to the many key players whose names do not appear. Those seeking a more complete account should refer to the links in this article and elsewhere on the net. + +### About the author + + [![photo of Christine Peterson](https://opensource.com/sites/default/files/styles/profile_pictures/public/pictures/cp2016_crop2_185.jpg?itok=vUkSjFig)][13] Christine Peterson - Christine Peterson writes, lectures, and briefs the media on coming powerful technologies, especially nanotechnology, artificial intelligence, and longevity. She is Cofounder and Past President of Foresight Institute, the leading nanotech public interest group. Foresight educates the public, technical community, and policymakers on coming powerful technologies and how to guide their long-term impact. She serves on the Advisory Board of the [Machine Intelligence... ][2][more about Christine Peterson][3][More about me][4] + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/2/coining-term-open-source-software + +作者:[ Christine Peterson][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/christine-peterson +[1]:https://opensource.com/article/18/2/coining-term-open-source-software?rate=HFz31Mwyy6f09l9uhm5T_OFJEmUuAwpI61FY-fSo3Gc +[2]:http://intelligence.org/ +[3]:https://opensource.com/users/christine-peterson +[4]:https://opensource.com/users/christine-peterson +[5]:https://opensource.com/user/206091/feed +[6]:https://opensource.com/resources/what-open-source +[7]:https://opensource.org/osd +[8]:https://wiki2.org/en/Alternative_terms_for_free_software +[9]:https://opensource.org/ +[10]:http://www.oreilly.com/pub/pr/636 +[11]:http://www.oreilly.com/pub/pr/796 +[12]:https://ipfs.io/ipfs/QmXoypizjW3WknFiJnKLwHCnL72vedxjQkDDP1mXWo6uco/wiki/Alternative_terms_for_free_software.html +[13]:https://opensource.com/users/christine-peterson +[14]:https://opensource.com/users/christine-peterson +[15]:https://opensource.com/users/christine-peterson +[16]:https://opensource.com/article/18/2/coining-term-open-source-software#comments \ No newline at end of file diff --git a/sources/talk/20180201 IT automation- How to make the case.md b/sources/talk/20180201 IT automation- How to make the case.md new file mode 100644 index 0000000000..4b70fbff49 --- /dev/null +++ b/sources/talk/20180201 IT automation- How to make the case.md @@ -0,0 +1,95 @@ +IT automation: How to make the case +====== +At the start of any significant project or change initiative, IT leaders face a proverbial fork in the road. + +Path #1 might seem to offer the shortest route from A to B: Simply force-feed the project to everyone by executive mandate, essentially saying, “You’re going to do this – or else.” + +Path #2 might appear less direct, because on this journey you take the time to explain the strategy and the reasons behind it. In fact, you’re going to be making pit stops along this route, rather than marathoning from start to finish: “Here’s what we’re doing – and why we’re doing it.” + +Guess which path bears better results? + +If you said #2, you’ve traveled both paths before – and experienced the results first-hand. Getting people on board with major changes beforehand is almost always the smarter choice. + +IT leaders know as well as anyone that with significant change often comes [significant fear][1], skepticism, and other challenges. It may be especially true with IT automation. The term alone sounds scary to some people, and it is often tied to misconceptions. Helping people understand the what, why, and how of your company’s automation strategy is a necessary step to achieving your goals associated with that strategy. + +[ **Read our related article,** [**IT automation best practices: 7 keys to long-term success**][2]. ] + +With that in mind, we asked a variety of IT leaders for their advice on making the case for automation in your organization: + +## 1. Show people what’s in it for them + +Let’s face it: Self-interest and self-preservation are natural instincts. Tapping into that human tendency is a good way to get people on board: Show people how your automation strategy will benefit them and their jobs. Will automating a particular process in the software pipeline mean fewer middle-of-the-night calls for team members? Will it enable some people to dump low-skill, manual tasks in favor of more strategic, higher-order work – the sort that helps them take the next step in their career? + +“Convey what’s in it for them, and how it will benefit clients and the whole company,” advises Vipul Nagrath, global CIO at [ADP][3]. “Compare the current state to a brighter future state, where the company enjoys greater stability, agility, efficiency, and security.” + +The same approach holds true when making the case outside of IT; just lighten up on the jargon when explaining the benefits to non-technical stakeholders, Nagrath says. + +Setting up a before-and-after picture is a good storytelling device for helping people see the upside. + +“You want to paint a picture of the current state that people can relate to,” Nagrath says. “Present what’s working, but also highlight what’s causing teams to be less than agile.” Then explain how automating certain processes will improve that current state. + +## 2. Connect automation to specific business goals + +Part of making a strong case entails making sure people understand that you’re not just trend-chasing. If you’re automating simply for the sake of automating, people will sniff that out and become more resistant – perhaps especially within IT. + +“The case for automation needs to be driven by a business demand signal, such as revenue or operating expense,” says David Emerson, VP and deputy CISO at [Cyxtera][4]. “No automation endeavor is self-justifying, and no technical feat, generally, should be a means unto itself, unless it’s a core competency of the company.” + +Like Nagrath, Emerson recommends promoting the incentives associated with achieving the business goals of automation, and working toward these goals (and corresponding incentives) in an iterative, step-by-step fashion. + +## 3. Break the automation plan into manageable pieces + +Even if your automation strategy is literally “automate everything,” that’s a tough sell (and probably unrealistic) for most organizations. You’ll make a stronger case with a plan that approaches automation manageable piece by manageable piece, and that enables greater flexibility to adapt along the way. + +“When making a case for automation, I recommend clearly illustrating the incentive to move to an automated process, and allowing iteration toward that goal to introduce and prove the benefits at lower risk,” Emerson says. + +Sergey Zuev, founder at [GA Connector][5], shares an in-the-trenches account of why automating incrementally is crucial – and how it will help you build a stronger, longer-lasting argument for your strategy. Zuev should know: His company’s tool automates the import of data from CRM applications into Google Analytics. But it was actually the company’s internal experience automating its own customer onboarding process that led to a lightbulb moment. + +“At first, we tried to build the whole onboarding funnel at once, and as a result, the project dragged [on] for months,” Zuev says. “After realizing that it [was] going nowhere, we decided to select small chunks that would have the biggest immediate effect, and start with that. As a result, we managed to implement one of the email sequences in just a week, and are already reaping the benefits of the desecrated manual effort.” + +## 4. Sell the big-picture benefits too + +A step-by-step approach does not preclude painting a bigger picture. Just as it’s a good idea to make the case at the individual or team level, it’s also a good idea for help people understand the company-wide benefits. + +“If we can accelerate the time it takes for the business to get what it needs, it will silence the skeptics.” + +Eric Kaplan, CTO at [AHEAD][6], agrees that using small wins to show automation’s value is a smart strategy for winning people over. But the value those so-called “small” wins reveal can actually help you sharpen the big picture for people. Kaplan points to the value of individual and organizational time as an area everyone can connect with easily. + +“The best place to do this is where you can show savings in terms of time,” Kaplan says. “If we can accelerate the time it takes for the business to get what it needs, it will silence the skeptics.” + +Time and scalability are powerful benefits business and IT colleagues, both charged with growing the business, can grasp. + +“The result of automation is scalability – less effort per person to maintain and grow your IT environment, as [Red Hat][7] VP, Global Services John Allessio recently [noted][8]. “If adding manpower is the only way to grow your business, then scalability is a pipe dream. Automation reduces your manpower requirements and provides the flexibility required for continued IT evolution.” (See his full article, [What DevOps teams really need from a CIO][8].) + +## 5. Promote the heck out of your results + +At the outset of your automation strategy, you’ll likely be making the case based on goals and the anticipated benefits of achieving those goals. But as your automation strategy evolves, there’s no case quite as convincing as one grounded in real-world results. + +“Seeing is believing,” says Nagrath, ADP’s CIO. “Nothing quiets skeptics like a track record of delivery.” + +That means, of course, not only achieving your goals, but also doing so on time – another good reason for the iterative, step-by-step approach. + +While quantitative results such as percentage improvements or cost savings can speak loudly, Nagrath advises his fellow IT leaders not to stop there when telling your automation story. + +“Making a case for automation is also a qualitative discussion, where we can promote the issues prevented, overall business continuity, reductions in failures/errors, and associates taking on [greater] responsibility as they tackle more value-added tasks.” + + +-------------------------------------------------------------------------------- + +via: https://enterprisersproject.com/article/2018/1/how-make-case-it-automation + +作者:[Kevin Casey][a] +译者:[译者ID](https://github.com/译者ID) +校对:[校对者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/10/how-beat-fear-and-loathing-it-change +[2]:https://enterprisersproject.com/article/2018/1/it-automation-best-practices-7-keys-long-term-success?sc_cid=70160000000h0aXAAQ +[3]:https://www.adp.com/ +[4]:https://www.cyxtera.com/ +[5]:http://gaconnector.com/ +[6]:https://www.thinkahead.com/ +[7]:https://www.redhat.com/en?intcmp=701f2000000tjyaAAA +[8]:https://enterprisersproject.com/article/2017/12/what-devops-teams-really-need-cio +[9]:https://enterprisersproject.com/email-newsletter?intcmp=701f2000000tsjPAAQ diff --git a/sources/talk/20180202 -Open source is 20- How it changed programming and business forever.md b/sources/talk/20180202 -Open source is 20- How it changed programming and business forever.md new file mode 100644 index 0000000000..1b7e6b6c37 --- /dev/null +++ b/sources/talk/20180202 -Open source is 20- How it changed programming and business forever.md @@ -0,0 +1,108 @@ +​Open source is 20: How it changed programming and business forever +====== +![][1] + +Every company in the world now uses open-source software. Microsoft, once its greatest enemy, is [now an enthusiastic open supporter][2]. Even [Windows is now built using open-source techniques][3]. And if you ever searched on Google, bought a book from Amazon, watched a movie on Netflix, or looked at your friend's vacation pictures on Facebook, you're an open-source user. Not bad for a technology approach that turns 20 on February 3. + +Now, free software has been around since the first computers, but the philosophy of both free software and open source are both much newer. In the 1970s and 80s, companies rose up which sought to profit by making proprietary software. In the nascent PC world, no one even knew about free software. But, on the Internet, which was dominated by Unix and ITS systems, it was a different story. + +In the late 70s, [Richard M. Stallman][6], also known as RMS, then an MIT programmer, created a free printer utility based on its source code. But then a new laser printer arrived on the campus and he found he could no longer get the source code and so he couldn't recreate the utility. The angry [RMS created the concept of "Free Software."][7] + +RMS's goal was to create a free operating system, [Hurd][8]. To make this happen in September 1983, [he announced the creation of the GNU project][9] (GNU stands for GNU's Not Unix -- a recursive acronym). By January 1984, he was working full-time on the project. To help build it he created the grandfather of all free software/open-source compiler system [GCC][10] and other operating system utilities. Early in 1985, he published "[The GNU Manifesto][11]," which was the founding charter of the free software movement and launched the [Free Software Foundation (FSF)][12]. + +This went well for a few years, but inevitably, [RMS collided with proprietary companies][13]. The company Unipress took the code to a variation of his [EMACS][14] programming editor and turned it into a proprietary program. RMS never wanted that to happen again so he created the [GNU General Public License (GPL)][15] in 1989. This was the first copyleft license. It gave users the right to use, copy, distribute, and modify a program's source code. But if you make source code changes and distribute it to others, you must share the modified code. While there had been earlier free licenses, such as [1980's four-clause BSD license][16], the GPL was the one that sparked the free-software, open-source revolution. + +In 1997, [Eric S. Raymond][17] published his vital essay, "[The Cathedral and the Bazaar][18]." In it, he showed the advantages of the free-software development methodologies using GCC, the Linux kernel, and his experiences with his own [Fetchmail][19] project as examples. This essay did more than show the advantages of free software. The programming principles he described led the way for both [Agile][20] development and [DevOps][21]. Twenty-first century programming owes a large debt to Raymond. + +Like all revolutions, free software quickly divided its supporters. On one side, as John Mark Walker, open-source expert and Strategic Advisor at Glyptodon, recently wrote, "[Free software is a social movement][22], with nary a hint of business interests -- it exists in the realm of religion and philosophy. Free software is a way of life with a strong moral code." + +On the other were numerous people who wanted to bring "free software" to business. They would become the founders of "open source." They argued that such phrases as "Free as in freedom" and "Free speech, not beer," left most people confused about what that really meant for software. + +The [release of the Netscape web browser source code][23] sparked a meeting of free software leaders and experts at [a strategy session held on February 3rd][24], 1998 in Palo Alto, CA. There, Eric S. Raymond, Michael Tiemann, Todd Anderson, Jon "maddog" Hall, Larry Augustin, Sam Ockman, and Christine Peterson hammered out the first steps to open source. + +Peterson created the "open-source term." She remembered: + +> [The introduction of the term "open source software" was a deliberate effort][25] to make this field of endeavor more understandable to newcomers and to business, which was viewed as necessary to its spread to a broader community of users. The problem with the main earlier label, "free software," was not its political connotations, but that -- to newcomers -- its seeming focus on price is distracting. A term was needed that focuses on the key issue of source code and that does not immediately confuse those new to the concept. The first term that came along at the right time and fulfilled these requirements was rapidly adopted: open source. + +To help clarify what open source was, and wasn't, Raymond and Bruce Perens founded the [Open Source Initiative (OSI)][26]. Its purpose was, and still is, to define what are real open-source software licenses and what aren't. + +Stallman was enraged by open source. He wrote: + +> The two terms describe almost the same method/category of software, but they stand for [views based on fundamentally different values][27]. Open source is a development methodology; free software is a social movement. For the free software movement, free software is an ethical imperative, essential respect for the users' freedom. By contrast, the philosophy of open source considers issues in terms of how to make software 'better' -- in a practical sense only. It says that non-free software is an inferior solution to the practical problem at hand. Most discussion of "open source" pays no attention to right and wrong, only to popularity and success. + +He saw open source as kowtowing to business and taking the focus away from the personal freedom of being able to have free access to the code. Twenty years later, he's still angry about it. + +In a recent e-mail to me, Stallman said, it is a "common error is connecting me or my work or free software in general with the term 'Open Source.' That is the slogan adopted in 1998 by people who reject the philosophy of the Free Software Movement." In another message, he continued, "I rejected 'open source' because it was meant to bury the "free software" ideas of freedom. Open source inspired the release ofu seful free programs, but what's missing is the idea that users deserve control of their computing. We libre-software activists say, 'Software you can't change and share is unjust, so let's escape to our free replacement.' Open source says only, 'If you let users change your code, they might fix bugs.' What it does says is not wrong, but weak; it avoids saying the deeper point." + +Philosophical conflicts aside, open source has indeed become the model for practical software development. Larry Augustin, CEO of [SugarCRM][28], the open-source customer relationship management (CRM) Software-as-a-Service (SaaS), was one of the first to practice open-source in a commercial software business. Augustin showed that a successful business could be built on open-source software. + +Other companies quickly embraced this model. Besides Linux companies such as [Canonical][29], [Red Hat][30] and [SUSE][31], technology businesses such as [IBM][32] and [Oracle][33] also adopted it. This, in turn, led to open source's commercial success. More recently companies you would never think of for a moment as open-source businesses like [Wal-Mart][34] and [Verizon][35], now rely on open-source programs and have their own open-source projects. + +As Jim Zemlin, director of [The Linux Foundation][36], observed in 2014: + +> A [new business model][37] has emerged in which companies are joining together across industries to share development resources and build common open-source code bases on which they can differentiate their own products and services. + +Today, Hall looked back and said "I look at 'closed source' as a blip in time." Raymond is unsurprised at open-source's success. In an e-mail interview, Raymond said, "Oh, yeah, it *has* been 20 years -- and that's not a big deal because we won most of the fights we needed to quite a while ago, like in the first decade after 1998." + +"Ever since," he continued, "we've been mainly dealing with the problems of success rather than those of failure. And a whole new class of issues, like IoT devices without upgrade paths -- doesn't help so much for the software to be open if you can't patch it." + +In other words, he concludes, "The reward of victory is often another set of battles." + +These are battles that open source is poised to win. Jim Whitehurst, Red Hat's CEO and president told me: + +> The future of open source is bright. We are on the cusp of a new wave of innovation that will come about because information is being separated from physical objects thanks to the Internet of Things. Over the next decade, we will see entire industries based on open-source concepts, like the sharing of information and joint innovation, become mainstream. We'll see this impact every sector, from non-profits, like healthcare, education and government, to global corporations who realize sharing information leads to better outcomes. Open and participative innovation will become a key part of increasing productivity around the world. + +Others see open source extending beyond software development methods. Nick Hopman, Red Hat's senior director of emerging technology practices, said: + +> Open-source is much more than just a process to develop and expose technology. Open-source is a catalyst to drive change in every facet of society -- government, policy, medical diagnostics, process re-engineering, you name it -- and can leverage open principles that have been perfected through the experiences of open-source software development to create communities that drive change and innovation. Looking forward, open-source will continue to drive technology innovation, but I am even more excited to see how it changes the world in ways we have yet to even consider. + +Indeed. Open source has turned twenty, but its influence, and not just on software and business, will continue on for decades to come. + +-------------------------------------------------------------------------------- + +via: http://www.zdnet.com/article/open-source-turns-20/ + +作者:[Steven J. Vaughan-Nichols][a] +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:http://www.zdnet.com/meet-the-team/us/steven-j-vaughan-nichols/ +[1]:https://zdnet1.cbsistatic.com/hub/i/r/2018/01/08/d9527281-2972-4cb7-bd87-6464d8ad50ae/thumbnail/570x322/9d4ef9007b3a3ce34de0cc39d2b15b0c/5a4faac660b22f2aba08fc3f-1280x7201jan082018150043poster.jpg +[2]:http://www.zdnet.com/article/microsoft-the-open-source-company/ +[3]:http://www.zdnet.com/article/microsoft-uses-open-source-software-to-create-windows/ +[4]:https://zdnet1.cbsistatic.com/hub/i/r/2016/11/18/a55b3c0c-7a8e-4143-893f-44900cb2767a/resize/220x165/6cd4e37b1904743ff1f579cb10d9e857/linux-open-source-money-penguin.jpg +[5]:http://www.zdnet.com/article/how-do-linux-and-open-source-companies-make-money-from-free-software/ +[6]:https://stallman.org/ +[7]:https://opensource.com/article/18/2/pivotal-moments-history-open-source +[8]:https://www.gnu.org/software/hurd/hurd.html +[9]:https://groups.google.com/forum/#!original/net.unix-wizards/8twfRPM79u0/1xlglzrWrU0J +[10]:https://gcc.gnu.org/ +[11]:https://www.gnu.org/gnu/manifesto.en.html +[12]:https://www.fsf.org/ +[13]:https://www.free-soft.org/gpl_history/ +[14]:https://www.gnu.org/s/emacs/ +[15]:https://www.gnu.org/licenses/gpl-3.0.en.html +[16]:http://www.linfo.org/bsdlicense.html +[17]:http://www.catb.org/esr/ +[18]:http://www.catb.org/esr/writings/cathedral-bazaar/ +[19]:http://www.fetchmail.info/ +[20]:https://www.agilealliance.org/agile101/ +[21]:https://aws.amazon.com/devops/what-is-devops/ +[22]:https://opensource.com/business/16/11/open-source-not-free-software?sc_cid=70160000001273HAAQ +[23]:http://www.zdnet.com/article/the-beginning-of-the-peoples-web-20-years-of-netscape/ +[24]:https://opensource.org/history +[25]:https://opensource.com/article/18/2/coining-term-open-source-software +[26]:https://opensource.org +[27]:https://www.gnu.org/philosophy/open-source-misses-the-point.html +[28]:https://www.sugarcrm.com/ +[29]:https://www.canonical.com/ +[30]:https://www.redhat.com/en +[31]:https://www.suse.com/ +[32]:https://developer.ibm.com/code/open/ +[33]:http://www.oracle.com/us/technologies/open-source/overview/index.html +[34]:http://www.zdnet.com/article/walmart-relies-on-openstack/ +[35]:https://www.networkworld.com/article/3195490/lan-wan/verizon-taps-into-open-source-white-box-fervor-with-new-cpe-offering.html +[36]:http://www.linuxfoundation.org/ +[37]:http://www.zdnet.com/article/it-takes-an-open-source-village-to-make-commercial-software/ diff --git a/sources/talk/20180205 Security Is Not an Absolute - System Overlord.md b/sources/talk/20180205 Security Is Not an Absolute - System Overlord.md new file mode 100644 index 0000000000..d0bd003c8f --- /dev/null +++ b/sources/talk/20180205 Security Is Not an Absolute - System Overlord.md @@ -0,0 +1,62 @@ +Security Is Not an Absolute +====== + +If there’s one thing I wish people from outside the security industry knew when dealing with information security, it’s that **Security is not an absolute**. Most of the time, it’s not even quantifiable. Even in the case of particular threat models, it’s often impossible to make statements about the security of a system with certainty. + +At work, I deal with a lot of very smart people who are not “security people”, but are well-meaning and trying to do the right thing. Online, I sometimes find myself in conversations on [/r/netsec][1], [/r/netsecstudents][2], [/r/asknetsec][3], or [security.stackexchange][4] where someone wants to know something about information security. Either way, it’s quite common that someone asks the fateful question: “Is this secure?”. There are actually only two answers to this question, and neither one is “Yes.” + +The first answer is, fairly obviously, “No.” There are some ideas that are not secure under any reasonable definition of security. Imagine an employer that makes the PIN for your payroll system the day and month on which you started your new job. Clearly, all it takes is someone posting “started my new job today!” to social media, and their PIN has been outed. Consider transporting an encrypted hard drive with the password on a sticky note attached to the outside of the drive. Both of these systems have employed some form of “security control” (even if I use the term loosely), and both are clearly insecure to even the most rudimentary of attacker. Consequently, answering “Is this secure?” with a firm “No” seems appropriate. + +The second answer is more nuanced: “It depends.” What it depends on, and whether those conditions exist in the system in use, are what many security professionals get paid to evaluate. For example, consider the employer in the previous paragraph. Instead of using a fixed scheme for PINs, they now generate a random 4-digit PIN and mail it to each new employee. Is this secure? That all depends on the threat model being applied to the scenario. If we allow an attacker unlimited attempts to log in as that user, then no 4 digit PIN (random or deterministic) is reasonably secure. On average, an attacker will need no more than 5000 requests to find the valid PIN. That can be done by a very basic script in 10s of minutes. If, on the other hand, we lock the account after 10 failed attempts, then we’ve reduced the attacker to a 0.1% chance of success for a given account. Is this secure? For a single account, this is probably reasonably secure (although most users might be uncomfortable at even a 1 in 1000 chance of an attacker succeeding against their personal account) but what if the attacker has a list of 1000 usernames? The attacker now has a **64%** chance of successfully accessing at least 1 account. I think most businesses would find those odds very much against their favor. + +So why can’t we ever come up with an answer of “Yes, this is a secure system”? Well, there’s several factors at play here. The first is that very little in life in general is an absolute: + + * Your doctor cannot tell you with certainty that you will be alive tomorrow. + * A seismologist can’t say that there absolutely won’t be a 9.0 earthquake that levels a big chunk of the West Coast. + * Your car manufacturer cannot guarantee that the 4 wheels on your car do not fall of on your way to work tomorrow. + + + +However, all of these possibilities are very remote events. Most people are comfortable with these probabilities, largely because they do not think much about them, but even if they did, they would believe that it would not happen to them. (And almost always, they would be correct in that assumption.) + +Unfortunately, in information security, we have three things working against us: + + * The risks are much less understood by those seeking to understand them. + * The reality is that there are enough security threats that are **much** more common than the events above. + * The threats against which security must guard are **adaptive**. + + + +Because most people have a hard time reasoning about the likelihood of attacks and threats against them, they seek absolute reassurance. They don’t want to be told “it depends”, they just want to hear “yes, you’re fine.” Many of these individuals are the hypochondriacs of the information security world – they think every possible attack will get them, and they want absolute reassurance they’re safe from those attacks. Alternatively, they don’t understand that there are degrees of security and threat models, and just want to be reassured that they are perfectly secure. Either way, the effect is the same – they don’t understand, but are afraid, and so want the reassurance of complete security. + +We’re in an era where security breaches are unfortunately common, and developers and users alike are hearing about these vulnerabilities and breaches all the time. This causes them to pay far more attention to security then they otherwise would. By itself, this isn’t bad – all of us in the industry have been trying to get everyone’s attention about security issues for decades. Getting it now is better late than never. But because we’re so far behind the curve, the breaches being common, everytone is rushing to find out their risk and get reassurance now. Rather than consider the nuances of the situation, they just want a simple answer to “Am I secure?” + +The last of these issues, however, is also the most unique to information security. For decades, we’ve looked for the formula to make a system perfectly secure. However, each countermeasure or security system is quickly defeated by attackers. We’re in a cat-and-mouse game, rather than an engineering discipline. + +This isn’t to say that security is not an engineering practice – it certainly is in many ways (and my official title claims that I am an engineer), but just that it differs from other engineering areas. The forces faced by a building do not change in face of design changes by the structural engineer. Gravity remains a constant, wind forces are predictible for a given design, the seismic nature of an area is approximately known. Making the building have stronger doors does not suddenly increase the wind forces on the windows. In security, however, when we “strengthen the doors”, the attackers do turn to the “windows” of our system. Our threats are **adaptive** – for each control we implement, they adapt to attempt to circumvent that control. For this reason, a system that was believed secure against the known threats one year is completely broken the next. + +Another form of the security absolutism is those that realize there are degrees of security, but want to take it to an almost ridiculous level of paranoia. Nearly always, these seem to be interested in forms of cryptography – perhaps because cryptography offers numbers that can be tweaked, giving an impression of differing levels of security. + + * Generating RSA encryption keys of over 4k bits in length, even though all cryptographers agree this is pointless. + * Asking why AES-512 doesn’t exist, even though SHA-512 does. (Because the length of a hash and the length of a key do not equal in effective strength against attacks.) + * Setting up bizarre browser settings and then complaining about websites being broken. (Disabling all JavaScript, all cookies, all ciphers that are less than 256 bits and not perfect forward secrecy, etc.) + + + +So the next time you want to know “Is this secure?”, consider the threat model: what are you trying to defend against? Recognize that there are no security absolutes and guarantees, and that good security engineering practice often involves compromise. Sometimes the compromise is one of usability or utility, sometimes the compromise involves working in a less-than-perfect world. + +-------------------------------------------------------------------------------- + +via: https://systemoverlord.com/2018/02/05/security-is-not-an-absolute.html + +作者:[David][a] +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://systemoverlord.com/about +[1]:https://reddit.com/r/netsec +[2]:https://reddit.com/r/netsecstudents +[3]:https://reddit.com/r/asknetsec +[4]:https://security.stackexchange.com diff --git a/sources/tech/20070810 How to use lftp to accelerate ftp-https download speed on Linux-UNIX.md b/sources/tech/20070810 How to use lftp to accelerate ftp-https download speed on Linux-UNIX.md new file mode 100644 index 0000000000..52a9c4c89f --- /dev/null +++ b/sources/tech/20070810 How to use lftp to accelerate ftp-https download speed on Linux-UNIX.md @@ -0,0 +1,84 @@ +translating---geekpi + +How to use lftp to accelerate ftp/https download speed on Linux/UNIX +====== +lftp is a file transfer program. It allows sophisticated FTP, HTTP/HTTPS, and other connections. If the site URL is specified, then lftp will connect to that site otherwise a connection has to be established with the open command. It is an essential tool for all a Linux/Unix command line users. I have already written about [Linux ultra fast command line download accelerator][1] such as Axel and prozilla. lftp is another tool for the same job with more features. lftp can handle seven file access methods: + + 1. ftp + 2. ftps + 3. http + 4. https + 5. hftp + 6. fish + 7. sftp + 8. file + + + +### So what is unique about lftp? + + * Every operation in lftp is reliable, that is any not fatal error is ignored, and the operation is repeated. So if downloading breaks, it will be restarted from the point automatically. Even if FTP server does not support REST command, lftp will try to retrieve the file from the very beginning until the file is transferred completely. + * lftp has shell-like command syntax allowing you to launch several commands in parallel in the background. + * lftp has a builtin mirror which can download or update a whole directory tree. There is also a reverse mirror (mirror -R) which uploads or updates a directory tree on the server. The mirror can also synchronize directories between two remote servers, using FXP if available. + + + +### How to use lftp as download accelerator + +lftp has pget command. It allows you download files in parallel. The syntax is +`lftp -e 'pget -n NUM -c url; exit'` +For example, download file using pget in 5 parts: +``` +$ cd /tmp +$ lftp -e 'pget -n 5 -c http://kernel.org/pub/linux/kernel/v2.6/linux-2.6.22.2.tar.bz2' +``` +Sample outputs: +``` +45108964 bytes transferred in 57 seconds (775.3K/s) +lftp :~>quit + +``` + +Where, + + 1. pget – Download files in parallel + 2. -n 5 – Set maximum number of connections to 5 + 3. -c – Continue broken transfer if lfile.lftp-pget-status exists in the current directory + + + +### How to use lftp to accelerate ftp/https download on Linux/Unix + +Another try with added exit command: +`$ lftp -e 'pget -n 10 -c https://cdn.kernel.org/pub/linux/kernel/v4.x/linux-4.15.tar.xz; exit'` + +[Linux-lftp-command-demo][https://www.cyberciti.biz/tips/wp-content/uploads/2007/08/Linux-lftp-command-demo.mp4] + +### A note about parallel downloading + +Please note that by using download accelerator you are going to put a load on remote host. Also note that lftp may not work with sites that do not support multi-source downloads or blocks such requests at firewall level. + +NA command offers many other features. Refer to [lftp][2] man page for more information: +`man lftp` + +### 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][3], [Facebook][4], [Google+][5]. Get the **latest tutorials on SysAdmin, Linux/Unix and open source topics via[my RSS/XML feed][6]**. + +-------------------------------------------------------------------------------- + +via: https://www.cyberciti.biz/tips/linux-unix-download-accelerator.html + +作者:[Vivek Gite][a] +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.cyberciti.biz +[1]:https://www.cyberciti.biz/tips/download-accelerator-for-linux-command-line-tools.html +[2]:https://lftp.yar.ru/ +[3]:https://twitter.com/nixcraft +[4]:https://facebook.com/nixcraft +[5]:https://plus.google.com/+CybercitiBiz +[6]:https://www.cyberciti.biz/atom/atom.xml diff --git a/sources/tech/20090518 How to use yum-cron to automatically update RHEL-CentOS Linux.md b/sources/tech/20090518 How to use yum-cron to automatically update RHEL-CentOS Linux.md new file mode 100644 index 0000000000..b0ca149c3e --- /dev/null +++ b/sources/tech/20090518 How to use yum-cron to automatically update RHEL-CentOS Linux.md @@ -0,0 +1,141 @@ +How to use yum-cron to automatically update RHEL/CentOS Linux +====== +The yum command line tool is used to install and update software packages under RHEL / CentOS Linux server. I know how to apply updates using [yum update command line][1], but I would like to use cron to update packages where appropriate manually. How do I configure yum to install software patches/updates [automatically with cron][2]? + +You need to install yum-cron package. It provides files needed to run yum updates as a cron job. Install this package if you want auto yum updates nightly via cron. + +### How to install yum cron on a CentOS/RHEL 6.x/7.x + +Type the following [yum command][3] on: +`$ sudo yum install yum-cron` +![](https://www.cyberciti.biz/media/new/faq/2009/05/How-to-install-yum-cron-on-CentOS-RHEL-server.jpg) + +Turn on service using systemctl command on **CentOS/RHEL 7.x** : +``` +$ sudo systemctl enable yum-cron.service +$ sudo systemctl start yum-cron.service +$ sudo systemctl status yum-cron.service +``` +If you are using **CentOS/RHEL 6.x** , run: +``` +$ sudo chkconfig yum-cron on +$ sudo service yum-cron start +``` +![](https://www.cyberciti.biz/media/new/faq/2009/05/How-to-turn-on-yum-cron-service-on-CentOS-or-RHEL-server.jpg) + +yum-cron is an alternate interface to yum. Very convenient way to call yum from cron. It provides methods to keep repository metadata up to date, and to check for, download, and apply updates. Rather than accepting many different command line arguments, the different functions of yum-cron can be accessed through config files. + +### How to configure yum-cron to automatically update RHEL/CentOS Linux + +You need to edit /etc/yum/yum-cron.conf and /etc/yum/yum-cron-hourly.conf files using a text editor such as vi command: +`$ sudo vi /etc/yum/yum-cron.conf` +Make sure updates should be applied when they are available +`apply_updates = yes` +You can set the address to send email messages from. Please note that ‘localhost’ will be replaced with the value of system_name. +`email_from = root@localhost` +List of addresses to send messages to. +`email_to = your-it-support@some-domain-name` +Name of the host to connect to to send email messages. +`email_host = localhost` +If you [do not want to update kernel package add the following on CentOS/RHEL 7.x][4]: +`exclude=kernel*` +For RHEL/CentOS 6.x add [the following to exclude kernel package from updating][5]: +`YUM_PARAMETER=kernel*` +[Save and close the file in vi/vim][6]. You also need to update /etc/yum/yum-cron-hourly.conf file if you want to apply update hourly. Otherwise /etc/yum/yum-cron.conf will run on daily using the following cron job (us [cat command][7]: +`$ cat /etc/cron.daily/0yum-daily.cron` +Sample outputs: +``` +#!/bin/bash +  +# Only run if this flag is set. The flag is created by the yum-cron init +# script when the service is started -- this allows one to use chkconfig and +# the standard "service stop|start" commands to enable or disable yum-cron. +if [[ ! -f /var/lock/subsys/yum-cron ]]; then + exit 0 +fi +  +# Action! +exec /usr/sbin/yum-cron /etc/yum/yum-cron-hourly.conf +[root@centos7-box yum]# cat /etc/cron.daily/0yum-daily.cron +#!/bin/bash +  +# Only run if this flag is set. The flag is created by the yum-cron init +# script when the service is started -- this allows one to use chkconfig and +# the standard "service stop|start" commands to enable or disable yum-cron. +if [[ ! -f /var/lock/subsys/yum-cron ]]; then + exit 0 +fi +  +# Action! +exec /usr/sbin/yum-cron +``` + +That is all. Now your system will update automatically everyday using yum-cron. See man page of yum-cron for more details: +`$ man yum-cron` + +### Method 2 – Use shell scripts + +**Warning** : The following method is outdated. Do not use it on RHEL/CentOS 6.x/7.x. I kept it below for historical reasons only when I used it on CentOS/RHEL version 4.x/5.x. + +Let us see how to configure CentOS/RHEL for yum automatic update retrieval and installation of security packages. You can use yum-updatesd service provided with CentOS / RHEL servers. However, this service provides a few overheads. You can create daily or weekly updates with the following shell script. Create + + * **/etc/cron.daily/yumupdate.sh** to apply updates one a day. + * **/etc/cron.weekly/yumupdate.sh** to apply updates once a week. + + + +#### Sample shell script to update system + +A shell script that instructs yum to update any packages it finds via [cron][8]: +``` +#!/bin/bash +YUM=/usr/bin/yum +$YUM -y -R 120 -d 0 -e 0 update yum +$YUM -y -R 10 -e 0 -d 0 update +``` + +(Code listing -01: /etc/cron.daily/yumupdate.sh) + +Where, + + 1. First command will update yum itself and next will apply system updates. + 2. **-R 120** : Sets the maximum amount of time yum will wait before performing a command + 3. **-e 0** : Sets the error level to 0 (range 0 – 10). 0 means print only critical errors about which you must be told. + 4. -d 0 : Sets the debugging level to 0 – turns up or down the amount of things that are printed. (range: 0 – 10). + 5. **-y** : Assume yes; assume that the answer to any question which would be asked is yes. + + + +Make sure you setup executable permission: +`# chmod +x /etc/cron.daily/yumupdate.sh` + + +### about the author + +Posted by: + +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][9], [Facebook][10], [Google+][11]. Get the **latest tutorials on SysAdmin, Linux/Unix and open source topics via[my RSS/XML feed][12]**. + +-------------------------------------------------------------------------------- + +via: https://www.cyberciti.biz/faq/fedora-automatic-update-retrieval-installation-with-cron/ + +作者:[Vivek Gite][a] +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.cyberciti.biz/ +[1]:https://www.cyberciti.biz/faq/rhel-centos-fedora-linux-yum-command-howto/ +[2]:https://www.cyberciti.biz/faq/how-do-i-add-jobs-to-cron-under-linux-or-unix-oses +[3]:https://www.cyberciti.biz/faq/rhel-centos-fedora-linux-yum-command-howto/ (See Linux/Unix yum command examples for more info) +[4]:https://www.cyberciti.biz/faq/yum-update-except-kernel-package-command/ +[5]:https://www.cyberciti.biz/faq/redhat-centos-linux-yum-update-exclude-packages/ +[6]:https://www.cyberciti.biz/faq/linux-unix-vim-save-and-quit-command/ +[7]:https://www.cyberciti.biz/faq/linux-unix-appleosx-bsd-cat-command-examples/ (See Linux/Unix cat command examples for more info) +[8]:https://www.cyberciti.biz/faq/how-do-i-add-jobs-to-cron-under-linux-or-unix-oses +[9]:https://twitter.com/nixcraft +[10]:https://facebook.com/nixcraft +[11]:https://plus.google.com/+CybercitiBiz +[12]:https://www.cyberciti.biz/atom/atom.xml diff --git a/sources/tech/20120624 6 Best Open Source Alternatives to Microsoft Office for Linux.md b/sources/tech/20120624 6 Best Open Source Alternatives to Microsoft Office for Linux.md index 400a800899..4964cda8cb 100644 --- a/sources/tech/20120624 6 Best Open Source Alternatives to Microsoft Office for Linux.md +++ b/sources/tech/20120624 6 Best Open Source Alternatives to Microsoft Office for Linux.md @@ -1,4 +1,4 @@ -6 Best Open Source Alternatives to Microsoft Office for Linux +6 Best Open Source Alternatives to Microsoft Office for Linux ====== **Brief: Looking for Microsoft Office in Linux? Here are the best free and open source alternatives to Microsoft Office for Linux.** diff --git a/sources/tech/20140225 How To Safely Generate A Random Number - Quarrelsome.md b/sources/tech/20140225 How To Safely Generate A Random Number - Quarrelsome.md new file mode 100644 index 0000000000..39314e7ab4 --- /dev/null +++ b/sources/tech/20140225 How To Safely Generate A Random Number - Quarrelsome.md @@ -0,0 +1,94 @@ +How To Safely Generate A Random Number — Quarrelsome +====== +### Use urandom + +Use [urandom][1]. Use [urandom][2]. Use [urandom][3]. Use [urandom][4]. Use [urandom][5]. Use [urandom][6]. + +### But what about for crypto keys? + +Still [urandom][6]. + +### Why not {SecureRandom, OpenSSL, havaged, &c}? + +These are userspace CSPRNGs. You want to use the kernel’s CSPRNG, because: + + * The kernel has access to raw device entropy. + + * It can promise not to share the same state between applications. + + * A good kernel CSPRNG, like FreeBSD’s, can also promise not to feed you random data before it’s seeded. + + + + +Study the last ten years of randomness failures and you’ll read a litany of userspace randomness failures. [Debian’s OpenSSH debacle][7]? Userspace random. Android Bitcoin wallets [repeating ECDSA k’s][8]? Userspace random. Gambling sites with predictable shuffles? Userspace random. + +Userspace OpenSSL also seeds itself from “from uninitialized memory, magical fairy dust and unicorn horns” generators almost always depend on the kernel’s generator anyways. Even if they don’t, the security of your whole system sure does. **A userspace CSPRNG doesn’t add defense-in-depth; instead, it creates two single points of failure.** + +### Doesn’t the man page say to use /dev/random? + +You But, more on this later. Stay your pitchforks. should ignore the man page. Don’t use /dev/random. The distinction between /dev/random and /dev/urandom is a Unix design wart. The man page doesn’t want to admit that, so it invents a security concern that doesn’t really exist. Consider the cryptographic advice in random(4) an urban legend and get on with your life. + +### But what if I need real random values, not psuedorandom values? + +Both urandom and /dev/random provide the same kind of randomness. Contrary to popular belief, /dev/random doesn’t provide “true random” data. For cryptography, you don’t usually want “true random”. + +Both urandom and /dev/random are based on a simple idea. Their design is closely related to that of a stream cipher: a small secret is stretched into an indefinite stream of unpredictable values. Here the secrets are “entropy”, and the stream is “output”. + +Only on Linux are /dev/random and urandom still meaningfully different. The Linux kernel CSPRNG rekeys itself regularly (by collecting more entropy). But /dev/random also tries to keep track of how much entropy remains in its kernel pool, and will occasionally go on strike if it decides not enough remains. This design is as silly as I’ve made it sound; it’s akin to AES-CTR blocking based on how much “key” is left in the “keystream”. + +If you use /dev/random instead of urandom, your program will unpredictably (or, if you’re an attacker, very predictably) hang when Linux gets confused about how its own RNG works. Using /dev/random will make your programs less stable, but it won’t make them any more cryptographically safe. + +### There’s a catch here, isn’t there? + +No, but there’s a Linux kernel bug you might want to know about, even though it doesn’t change which RNG you should use. + +On Linux, if your software runs immediately at boot, and/or the OS has just been installed, your code might be in a race with the RNG. That’s bad, because if you win the race, there could be a window of time where you get predictable outputs from urandom. This is a bug in Linux, and you need to know about it if you’re building platform-level code for a Linux embedded device. + +This is indeed a problem with urandom (and not /dev/random) on Linux. It’s also a [bug in the Linux kernel][9]. But it’s also easily fixed in userland: at boot, seed urandom explicitly. Most Linux distributions have done this for a long time. But don’t switch to a different CSPRNG. + +### What about on other operating systems? + +FreeBSD and OS X do away with the distinction between urandom and /dev/random; the two devices behave identically. Unfortunately, the man page does a poor job of explaining why this is, and perpetuates the myth that Linux urandom is scary. + +FreeBSD’s kernel crypto RNG doesn’t block regardless of whether you use /dev/random or urandom. Unless it hasn’t been seeded, in which case both block. This behavior, unlike Linux’s, makes sense. Linux should adopt it. But if you’re an app developer, this makes little difference to you: Linux, FreeBSD, iOS, whatever: use urandom. + +### tl;dr + +Use urandom. + +### Epilog + +[ruby-trunk Feature #9569][10] + +> Right now, SecureRandom.random_bytes tries to detect an OpenSSL to use before it tries to detect /dev/urandom. I think it should be the other way around. In both cases, you just need random bytes to unpack, so SecureRandom could skip the middleman (and second point of failure) and just talk to /dev/urandom directly if it’s available. + +Resolution: + +> /dev/urandom is not suitable to be used to generate directly session keys and other application level random data which is generated frequently. +> +> [the] random(4) [man page] on GNU/Linux [says]… + +Thanks to Matthew Green, Nate Lawson, Sean Devlin, Coda Hale, and Alex Balducci for reading drafts of this. Fair warning: Matthew only mostly agrees with me. + +-------------------------------------------------------------------------------- + +via: https://sockpuppet.org/blog/2014/02/25/safely-generate-random-numbers/ + +作者:[Thomas;Erin;Matasano][a] +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://sockpuppet.org/blog +[1]:http://blog.cr.yp.to/20140205-entropy.html +[2]:http://cr.yp.to/talks/2011.09.28/slides.pdf +[3]:http://golang.org/src/pkg/crypto/rand/rand_unix.go +[4]:http://security.stackexchange.com/questions/3936/is-a-rand-from-dev-urandom-secure-for-a-login-key +[5]:http://stackoverflow.com/a/5639631 +[6]:https://twitter.com/bramcohen/status/206146075487240194 +[7]:http://research.swtch.com/openssl +[8]:http://arstechnica.com/security/2013/08/google-confirms-critical-android-crypto-flaw-used-in-5700-bitcoin-heist/ +[9]:https://factorable.net/weakkeys12.extended.pdf +[10]:https://bugs.ruby-lang.org/issues/9569 diff --git a/sources/tech/20140523 Tail Calls Optimization and ES6.md b/sources/tech/20140523 Tail Calls Optimization and ES6.md deleted file mode 100644 index 2999c606d2..0000000000 --- a/sources/tech/20140523 Tail Calls Optimization and ES6.md +++ /dev/null @@ -1,173 +0,0 @@ -#Translating by qhwdw [Tail Calls, Optimization, and ES6][1] - - -In this penultimate post about the stack, we take a quick look at tail calls, compiler optimizations, and the proper tail calls landing in the newest version of JavaScript. - -A tail call happens when a function F makes a function call as its final action. At that point F will do absolutely no more work: it passes the ball to whatever function is being called and vanishes from the game. This is notable because it opens up the possibility of tail call optimization: instead of [creating a new stack frame][6] for the function call, we can simply reuse F's stack frame, thereby saving stack space and avoiding the work involved in setting up a new frame. Here are some examples in C and their results compiled with [mild optimization][7]: - -Simple Tail Calls[download][2] - -``` -int add5(int a) -{ - return a + 5; -} - -int add10(int a) -{ - int b = add5(a); // not tail - return add5(b); // tail -} - -int add5AndTriple(int a){ - int b = add5(a); // not tail - return 3 * add5(a); // not tail, doing work after the call -} - -int finicky(int a){ - if (a > 10){ - return add5AndTriple(a); // tail - } - - if (a > 5){ - int b = add5(a); // not tail - return finicky(b); // tail - } - - return add10(a); // tail -} -``` - -You can normally spot tail call optimization (hereafter, TCO) in compiler output by seeing a [jump][8] instruction where a [call][9] would have been expected. At runtime TCO leads to a reduced call stack. - -A common misconception is that tail calls are necessarily [recursive][10]. That's not the case: a tail call may be recursive, such as in finicky() above, but it need not be. As long as caller F is completely done at the call site, we've got ourselves a tail call. Whether it can be optimized is a different question whose answer depends on your programming environment. - -"Yes, it can, always!" is the best answer we can hope for, which is famously the case for Scheme, as discussed in [SICP][11] (by the way, if when you program you don't feel like "a Sorcerer conjuring the spirits of the computer with your spells," I urge you to read that book). It's also the case for [Lua][12]. And most importantly, it is the case for the next version of JavaScript, ES6, whose spec does a good job defining [tail position][13] and clarifying the few conditions required for optimization, such as [strict mode][14]. When a language guarantees TCO, it supports proper tail calls. - -Now some of us can't kick that C habit, heart bleed and all, and the answer there is a more complicated "sometimes" that takes us into compiler optimization territory. We've seen the [simple examples][15] above; now let's resurrect our factorial from [last post][16]: - -Recursive Factorial[download][3] - -``` -#include - -int factorial(int n) -{ - int previous = 0xdeadbeef; - - if (n == 0 || n == 1) { - return 1; - } - - previous = factorial(n-1); - return n * previous; -} - -int main(int argc) -{ - int answer = factorial(5); - printf("%d\n", answer); -} -``` - -So, is line 11 a tail call? It's not, because of the multiplication by n afterwards. But if you're not used to optimizations, gcc's [result][17] with [O2 optimization][18] might shock you: not only it transforms factorial into a [recursion-free loop][19], but the factorial(5) call is eliminated entirely and replaced by a [compile-time constant][20] of 120 (5! == 120). This is why debugging optimized code can be hard sometimes. On the plus side, if you call this function it will use a single stack frame regardless of n's initial value. Compiler algorithms are pretty fun, and if you're interested I suggest you check out [Building an Optimizing Compiler][21] and [ACDI][22]. - -However, what happened here was not tail call optimization, since there was no tail call to begin with. gcc outsmarted us by analyzing what the function does and optimizing away the needless recursion. The task was made easier by the simple, deterministic nature of the operations being done. By adding a dash of chaos (e.g., getpid()) we can throw gcc off: - -Recursive PID Factorial[download][4] - -``` -#include -#include -#include - -int pidFactorial(int n) -{ - if (1 == n) { - return getpid(); // tail - } - - return n * pidFactorial(n-1) * getpid(); // not tail -} - -int main(int argc) -{ - int answer = pidFactorial(5); - printf("%d\n", answer); -} -``` - -Optimize that, unix fairies! So now we have a regular [recursive call][23] and this function allocates O(n) stack frames to do its work. Heroically, gcc still does [TCO for getpid][24] in the recursion base case. If we now wished to make this function tail recursive, we'd need a slight change: - -tailPidFactorial.c[download][5] - -``` -#include -#include -#include - -int tailPidFactorial(int n, int acc) -{ - if (1 == n) { - return acc * getpid(); // not tail - } - - acc = (acc * getpid() * n); - return tailPidFactorial(n-1, acc); // tail -} - -int main(int argc) -{ - int answer = tailPidFactorial(5, 1); - printf("%d\n", answer); -} -``` - -The accumulation of the result is now [a loop][25] and we've achieved true TCO. But before you go out partying, what can we say about the general case in C? Sadly, while good C compilers do TCO in a number of cases, there are many situations where they cannot do it. For example, as we saw in our [function epilogues][26], the caller is responsible for cleaning up the stack after a function call using the standard C calling convention. So if function F takes two arguments, it can only make TCO calls to functions taking two or fewer arguments. This is one among many restrictions. Mark Probst wrote an excellent thesis discussing [Proper Tail Recursion in C][27] where he discusses these issues along with C stack behavior. He also does [insanely cool juggling][28]. - -"Sometimes" is a rocky foundation for any relationship, so you can't rely on TCO in C. It's a discrete optimization that may or may not take place, rather than a language feature like proper tail calls, though in practice the compiler will optimize the vast majority of cases. But if you must have it, say for transpiling Scheme into C, you will [suffer][29]. - -Since JavaScript is now the most popular transpilation target, proper tail calls become even more important there. So kudos to ES6 for delivering it along with many other significant improvements. It's like Christmas for JS programmers. - -This concludes our brief tour of tail calls and compiler optimization. Thanks for reading and see you next time. - --------------------------------------------------------------------------------- - -via:https://manybutfinite.com/post/tail-calls-optimization-es6/ - -作者:[Gustavo Duarte][a] -译者:[译者ID](https://github.com/译者ID) -校对:[校对者ID](https://github.com/校对者ID) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 - -[a]:http://duartes.org/gustavo/blog/about/ -[1]:https://manybutfinite.com/post/tail-calls-optimization-es6/ -[2]:https://manybutfinite.com/code/x86-stack/tail.c -[3]:https://manybutfinite.com/code/x86-stack/factorial.c -[4]:https://manybutfinite.com/code/x86-stack/pidFactorial.c -[5]:https://manybutfinite.com/code/x86-stack/tailPidFactorial.c -[6]:https://manybutfinite.com/post/journey-to-the-stack -[7]:https://github.com/gduarte/blog/blob/master/code/x86-stack/asm-tco.sh -[8]:https://github.com/gduarte/blog/blob/master/code/x86-stack/tail-tco.s#L27 -[9]:https://github.com/gduarte/blog/blob/master/code/x86-stack/tail.s#L37-L39 -[10]:https://manybutfinite.com/post/recursion/ -[11]:http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-11.html -[12]:http://www.lua.org/pil/6.3.html -[13]:https://people.mozilla.org/~jorendorff/es6-draft.html#sec-tail-position-calls -[14]:https://people.mozilla.org/~jorendorff/es6-draft.html#sec-strict-mode-code -[15]:https://github.com/gduarte/blog/blob/master/code/x86-stack/tail.c -[16]:https://manybutfinite.com/post/recursion/ -[17]:https://github.com/gduarte/blog/blob/master/code/x86-stack/factorial-o2.s -[18]:https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html -[19]:https://github.com/gduarte/blog/blob/master/code/x86-stack/factorial-o2.s#L16-L19 -[20]:https://github.com/gduarte/blog/blob/master/code/x86-stack/factorial-o2.s#L38 -[21]:http://www.amazon.com/Building-Optimizing-Compiler-Bob-Morgan-ebook/dp/B008COCE9G/ -[22]:http://www.amazon.com/Advanced-Compiler-Design-Implementation-Muchnick-ebook/dp/B003VM7GGK/ -[23]:https://github.com/gduarte/blog/blob/master/code/x86-stack/pidFactorial-o2.s#L20 -[24]:https://github.com/gduarte/blog/blob/master/code/x86-stack/pidFactorial-o2.s#L43 -[25]:https://github.com/gduarte/blog/blob/master/code/x86-stack/tailPidFactorial-o2.s#L22-L27 -[26]:https://manybutfinite.com/post/epilogues-canaries-buffer-overflows/ -[27]:http://www.complang.tuwien.ac.at/schani/diplarb.ps -[28]:http://www.complang.tuwien.ac.at/schani/jugglevids/index.html -[29]:http://en.wikipedia.org/wiki/Tail_call#Through_trampolining \ No newline at end of file diff --git a/sources/tech/20150615 Let-s Build A Simple Interpreter. Part 1..md b/sources/tech/20150615 Let-s Build A Simple Interpreter. Part 1..md index 9a815f2852..592e43e067 100644 --- a/sources/tech/20150615 Let-s Build A Simple Interpreter. Part 1..md +++ b/sources/tech/20150615 Let-s Build A Simple Interpreter. Part 1..md @@ -1,4 +1,5 @@ -// Translating by Linchenguang.... +BriFuture is translating this article + Let’s Build A Simple Interpreter. Part 1. ====== diff --git a/sources/tech/20150812 Let-s Build A Simple Interpreter. Part 3..md b/sources/tech/20150812 Let-s Build A Simple Interpreter. Part 3..md deleted file mode 100644 index d9deb9f50e..0000000000 --- a/sources/tech/20150812 Let-s Build A Simple Interpreter. Part 3..md +++ /dev/null @@ -1,342 +0,0 @@ -BriFuture is Translating this article - -Let’s Build A Simple Interpreter. Part 3. -====== - -I woke up this morning and I thought to myself: "Why do we find it so difficult to learn a new skill?" - -I don't think it's just because of the hard work. I think that one of the reasons might be that we spend a lot of time and hard work acquiring knowledge by reading and watching and not enough time translating that knowledge into a skill by practicing it. Take swimming, for example. You can spend a lot of time reading hundreds of books about swimming, talk for hours with experienced swimmers and coaches, watch all the training videos available, and you still will sink like a rock the first time you jump in the pool. - -The bottom line is: it doesn't matter how well you think you know the subject - you have to put that knowledge into practice to turn it into a skill. To help you with the practice part I put exercises into [Part 1][1] and [Part 2][2] of the series. And yes, you will see more exercises in today's article and in future articles, I promise :) - -Okay, let's get started with today's material, shall we? - - -So far, you've learned how to interpret arithmetic expressions that add or subtract two integers like "7 + 3" or "12 - 9". Today I'm going to talk about how to parse (recognize) and interpret arithmetic expressions that have any number of plus or minus operators in it, for example "7 - 3 + 2 - 1". - -Graphically, the arithmetic expressions in this article can be represented with the following syntax diagram: - -![][3] - -What is a syntax diagram? A **syntax diagram** is a graphical representation of a programming language 's syntax rules. Basically, a syntax diagram visually shows you which statements are allowed in your programming language and which are not. - -Syntax diagrams are pretty easy to read: just follow the paths indicated by the arrows. Some paths indicate choices. And some paths indicate loops. - -You can read the above syntax diagram as following: a term optionally followed by a plus or minus sign, followed by another term, which in turn is optionally followed by a plus or minus sign followed by another term and so on. You get the picture, literally. You might wonder what a "term" is. For the purpose of this article a "term" is just an integer. - -Syntax diagrams serve two main purposes: - - * They graphically represent the specification (grammar) of a programming language. - * They can be used to help you write your parser - you can map a diagram to code by following simple rules. - - - -You've learned that the process of recognizing a phrase in the stream of tokens is called **parsing**. And the part of an interpreter or compiler that performs that job is called a **parser**. Parsing is also called **syntax analysis** , and the parser is also aptly called, you guessed it right, a **syntax analyzer**. - -According to the syntax diagram above, all of the following arithmetic expressions are valid: - - * 3 - * 3 + 4 - * 7 - 3 + 2 - 1 - - - -Because syntax rules for arithmetic expressions in different programming languages are very similar we can use a Python shell to "test" our syntax diagram. Launch your Python shell and see for yourself: -``` ->>> 3 -3 ->>> 3 + 4 -7 ->>> 7 - 3 + 2 - 1 -5 -``` - -No surprises here. - -The expression "3 + " is not a valid arithmetic expression though because according to the syntax diagram the plus sign must be followed by a term (integer), otherwise it's a syntax error. Again, try it with a Python shell and see for yourself: -``` ->>> 3 + - File "", line 1 - 3 + - ^ -SyntaxError: invalid syntax -``` - -It's great to be able to use a Python shell to do some testing but let's map the above syntax diagram to code and use our own interpreter for testing, all right? - -You know from the previous articles ([Part 1][1] and [Part 2][2]) that the expr method is where both our parser and interpreter live. Again, the parser just recognizes the structure making sure that it corresponds to some specifications and the interpreter actually evaluates the expression once the parser has successfully recognized (parsed) it. - -The following code snippet shows the parser code corresponding to the diagram. The rectangular box from the syntax diagram (term) becomes a term method that parses an integer and the expr method just follows the syntax diagram flow: -``` -def term(self): - self.eat(INTEGER) - -def expr(self): - # set current token to the first token taken from the input - self.current_token = self.get_next_token() - - self.term() - while self.current_token.type in (PLUS, MINUS): - token = self.current_token - if token.type == PLUS: - self.eat(PLUS) - self.term() - elif token.type == MINUS: - self.eat(MINUS) - self.term() -``` - -You can see that expr first calls the term method. Then the expr method has a while loop which can execute zero or more times. And inside the loop the parser makes a choice based on the token (whether it's a plus or minus sign). Spend some time proving to yourself that the code above does indeed follow the syntax diagram flow for arithmetic expressions. - -The parser itself does not interpret anything though: if it recognizes an expression it's silent and if it doesn't, it throws out a syntax error. Let's modify the expr method and add the interpreter code: -``` -def term(self): - """Return an INTEGER token value""" - token = self.current_token - self.eat(INTEGER) - return token.value - -def expr(self): - """Parser / Interpreter """ - # set current token to the first token taken from the input - self.current_token = self.get_next_token() - - result = self.term() - while self.current_token.type in (PLUS, MINUS): - token = self.current_token - if token.type == PLUS: - self.eat(PLUS) - result = result + self.term() - elif token.type == MINUS: - self.eat(MINUS) - result = result - self.term() - - return result -``` - -Because the interpreter needs to evaluate an expression the term method was modified to return an integer value and the expr method was modified to perform addition and subtraction at the appropriate places and return the result of interpretation. Even though the code is pretty straightforward I recommend spending some time studying it. - -Le's get moving and see the complete code of the interpreter now, okay? - -Here is the source code for your new version of the calculator that can handle valid arithmetic expressions containing integers and any number of addition and subtraction operators: -``` -# Token types -# -# EOF (end-of-file) token is used to indicate that -# there is no more input left for lexical analysis -INTEGER, PLUS, MINUS, EOF = 'INTEGER', 'PLUS', 'MINUS', 'EOF' - - -class Token(object): - def __init__(self, type, value): - # token type: INTEGER, PLUS, MINUS, or EOF - self.type = type - # token value: non-negative integer value, '+', '-', or None - self.value = value - - def __str__(self): - """String representation of the class instance. - - Examples: - Token(INTEGER, 3) - Token(PLUS, '+') - """ - return 'Token({type}, {value})'.format( - type=self.type, - value=repr(self.value) - ) - - def __repr__(self): - return self.__str__() - - -class Interpreter(object): - def __init__(self, text): - # client string input, e.g. "3 + 5", "12 - 5 + 3", etc - self.text = text - # self.pos is an index into self.text - self.pos = 0 - # current token instance - self.current_token = None - self.current_char = self.text[self.pos] - - ########################################################## - # Lexer code # - ########################################################## - def error(self): - raise Exception('Invalid syntax') - - def advance(self): - """Advance the `pos` pointer and set the `current_char` variable.""" - self.pos += 1 - if self.pos > len(self.text) - 1: - self.current_char = None # Indicates end of input - else: - self.current_char = self.text[self.pos] - - def skip_whitespace(self): - while self.current_char is not None and self.current_char.isspace(): - self.advance() - - def integer(self): - """Return a (multidigit) integer consumed from the input.""" - result = '' - while self.current_char is not None and self.current_char.isdigit(): - result += self.current_char - self.advance() - return int(result) - - def get_next_token(self): - """Lexical analyzer (also known as scanner or tokenizer) - - This method is responsible for breaking a sentence - apart into tokens. One token at a time. - """ - while self.current_char is not None: - - if self.current_char.isspace(): - self.skip_whitespace() - continue - - if self.current_char.isdigit(): - return Token(INTEGER, self.integer()) - - if self.current_char == '+': - self.advance() - return Token(PLUS, '+') - - if self.current_char == '-': - self.advance() - return Token(MINUS, '-') - - self.error() - - return Token(EOF, None) - - ########################################################## - # Parser / Interpreter code # - ########################################################## - def eat(self, token_type): - # compare the current token type with the passed token - # type and if they match then "eat" the current token - # and assign the next token to the self.current_token, - # otherwise raise an exception. - if self.current_token.type == token_type: - self.current_token = self.get_next_token() - else: - self.error() - - def term(self): - """Return an INTEGER token value.""" - token = self.current_token - self.eat(INTEGER) - return token.value - - def expr(self): - """Arithmetic expression parser / interpreter.""" - # set current token to the first token taken from the input - self.current_token = self.get_next_token() - - result = self.term() - while self.current_token.type in (PLUS, MINUS): - token = self.current_token - if token.type == PLUS: - self.eat(PLUS) - result = result + self.term() - elif token.type == MINUS: - self.eat(MINUS) - result = result - self.term() - - return result - - -def main(): - while True: - try: - # To run under Python3 replace 'raw_input' call - # with 'input' - text = raw_input('calc> ') - except EOFError: - break - if not text: - continue - interpreter = Interpreter(text) - result = interpreter.expr() - print(result) - - -if __name__ == '__main__': - main() -``` - -Save the above code into the calc3.py file or download it directly from [GitHub][4]. Try it out. See for yourself that it can handle arithmetic expressions that you can derive from the syntax diagram I showed you earlier. - -Here is a sample session that I ran on my laptop: -``` -$ python calc3.py -calc> 3 -3 -calc> 7 - 4 -3 -calc> 10 + 5 -15 -calc> 7 - 3 + 2 - 1 -5 -calc> 10 + 1 + 2 - 3 + 4 + 6 - 15 -5 -calc> 3 + -Traceback (most recent call last): - File "calc3.py", line 147, in - main() - File "calc3.py", line 142, in main - result = interpreter.expr() - File "calc3.py", line 123, in expr - result = result + self.term() - File "calc3.py", line 110, in term - self.eat(INTEGER) - File "calc3.py", line 105, in eat - self.error() - File "calc3.py", line 45, in error - raise Exception('Invalid syntax') -Exception: Invalid syntax -``` - - -Remember those exercises I mentioned at the beginning of the article: here they are, as promised :) - -![][5] - - * Draw a syntax diagram for arithmetic expressions that contain only multiplication and division, for example "7 0_sync_master.sh 1_add_new_article_manual.sh 1_add_new_article_newspaper.sh 2_start_translating.sh 3_continue_the_work.sh 4_finish.sh 5_pause.sh base.sh env format.test lctt.cfg parse_url_by_manual.sh parse_url_by_newspaper.py parse_url_by_newspaper.sh README.org reformat.sh 4 / 2 0_sync_master.sh 1_add_new_article_manual.sh 1_add_new_article_newspaper.sh 2_start_translating.sh 3_continue_the_work.sh 4_finish.sh 5_pause.sh base.sh env format.test lctt.cfg parse_url_by_manual.sh parse_url_by_newspaper.py parse_url_by_newspaper.sh README.org reformat.sh 3". Seriously, just grab a pen or a pencil and try to draw one. - * Modify the source code of the calculator to interpret arithmetic expressions that contain only multiplication and division, for example "7 0_sync_master.sh 1_add_new_article_manual.sh 1_add_new_article_newspaper.sh 2_start_translating.sh 3_continue_the_work.sh 4_finish.sh 5_pause.sh base.sh env format.test lctt.cfg parse_url_by_manual.sh parse_url_by_newspaper.py parse_url_by_newspaper.sh README.org reformat.sh 4 / 2 * 3". - * Write an interpreter that handles arithmetic expressions like "7 - 3 + 2 - 1" from scratch. Use any programming language you're comfortable with and write it off the top of your head without looking at the examples. When you do that, think about components involved: a lexer that takes an input and converts it into a stream of tokens, a parser that feeds off the stream of the tokens provided by the lexer and tries to recognize a structure in that stream, and an interpreter that generates results after the parser has successfully parsed (recognized) a valid arithmetic expression. String those pieces together. Spend some time translating the knowledge you've acquired into a working interpreter for arithmetic expressions. - - - -**Check your understanding.** - - 1. What is a syntax diagram? - 2. What is syntax analysis? - 3. What is a syntax analyzer? - - - - -Hey, look! You read all the way to the end. Thanks for hanging out here today and don't forget to do the exercises. :) I'll be back next time with a new article - stay tuned. - - --------------------------------------------------------------------------------- - -via: https://ruslanspivak.com/lsbasi-part3/ - -作者:[Ruslan Spivak][a] -译者:[译者ID](https://github.com/译者ID) -校对:[校对者ID](https://github.com/校对者ID) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 - -[a]:https://ruslanspivak.com -[1]:http://ruslanspivak.com/lsbasi-part1/ (Part 1) -[2]:http://ruslanspivak.com/lsbasi-part2/ (Part 2) -[3]:https://ruslanspivak.com/lsbasi-part3/lsbasi_part3_syntax_diagram.png -[4]:https://github.com/rspivak/lsbasi/blob/master/part3/calc3.py -[5]:https://ruslanspivak.com/lsbasi-part3/lsbasi_part3_exercises.png diff --git a/sources/tech/20160606 Learn your tools Navigating your Git History.md b/sources/tech/20160606 Learn your tools Navigating your Git History.md new file mode 100644 index 0000000000..2d17cac30b --- /dev/null +++ b/sources/tech/20160606 Learn your tools Navigating your Git History.md @@ -0,0 +1,161 @@ +Learn your tools: Navigating your Git History +============================================================ + +Starting a greenfield application everyday is nearly impossible, especially in your daily job. In fact, most of us are facing (somewhat) legacy codebases on a daily basis, and regaining the context of why some feature, or line of code exists in the codebase is very important. This is where `git`, the distributed version control system, is invaluable. Let’s dive in and see how we can use our `git` history and easily navigate through it. + +### Git history + +First and foremost, what is `git` history? As the name says, it is the commit history of a `git` repo. It contains a bunch of commit messages, with their authors’ name, the commit hash and the date of the commit. The easiest way to see the history of a `git`repo, is the `git log` command. + +Sidenote: For the purpose of this post, we will use Ruby on Rails’ repo, the `master`branch. The reason behind this is because Rails has a very good `git` history, with nice commit messages, references and explanations behind every change. Given the size of the codebase, the age and the number of maintainers, it’s certainly one of the best repositories that I have seen. Of course, I am not saying there are no other repositories built with good `git` practices, but this is one that has caught my eye. + +So back to Rails’ repo. If you run `git log` in the Rails’ repo, you will see something like this: + +``` +commit 66ebbc4952f6cfb37d719f63036441ef98149418Author: Arthur Neves Date: Fri Jun 3 17:17:38 2016 -0400 Dont re-define class SQLite3Adapter on test We were declaring in a few tests, which depending of the order load will cause an error, as the super class could change. see https://github.com/rails/rails/commit/ac1c4e141b20c1067af2c2703db6e1b463b985da#commitcomment-17731383commit 755f6bf3d3d568bc0af2c636be2f6df16c651eb1Merge: 4e85538 f7b850eAuthor: Eileen M. Uchitelle Date: Fri Jun 3 10:21:49 2016 -0400 Merge pull request #25263 from abhishekjain16/doc_accessor_thread [skip ci] Fix grammarcommit f7b850ec9f6036802339e965c8ce74494f731b4aAuthor: Abhishek Jain Date: Fri Jun 3 16:49:21 2016 +0530 [skip ci] Fix grammarcommit 4e85538dddf47877cacc65cea6c050e349af0405Merge: 082a515 cf2158cAuthor: Vijay Dev Date: Fri Jun 3 14:00:47 2016 +0000 Merge branch 'master' of github.com:rails/docrails Conflicts: guides/source/action_cable_overview.mdcommit 082a5158251c6578714132e5c4f71bd39f462d71Merge: 4bd11d4 3bd30d9Author: Yves Senn Date: Fri Jun 3 11:30:19 2016 +0200 Merge pull request #25243 from sukesan1984/add_i18n_validation_test Add i18n_validation_testcommit 4bd11d46de892676830bca51d3040f29200abbfaMerge: 99d8d45 e98caf8Author: Arthur Nogueira Neves Date: Thu Jun 2 22:55:52 2016 -0400 Merge pull request #25258 from alexcameron89/master [skip ci] Make header bullets consistent in engines.mdcommit e98caf81fef54746126d31076c6d346c48ae8e1bAuthor: Alex Kitchens Date: Thu Jun 2 21:26:53 2016 -0500 [skip ci] Make header bullets consistent in engines.md +``` + +As you can see, the `git log` shows the commit hash, the author and his email and the date of when the commit was created. Of course, `git` being super customisable, it allows you to customise the output format of the `git log` command. Let’s say, we want to just see the first line of the commit message, we could run `git log --oneline`, which will produce a more compact log: + +``` +66ebbc4 Dont re-define class SQLite3Adapter on test755f6bf Merge pull request #25263 from abhishekjain16/doc_accessor_threadf7b850e [skip ci] Fix grammar4e85538 Merge branch 'master' of github.com:rails/docrails082a515 Merge pull request #25243 from sukesan1984/add_i18n_validation_test4bd11d4 Merge pull request #25258 from alexcameron89/mastere98caf8 [skip ci] Make header bullets consistent in engines.md99d8d45 Merge pull request #25254 from kamipo/fix_debug_helper_test818397c Merge pull request #25240 from matthewd/reloadable-channels2c5a8ba Don't blank pad day of the month when formatting dates14ff8e7 Fix debug helper test +``` + +To see all of the `git log` options, I recommend checking out manpage of `git log`, available in your terminal via `man git-log` or `git help log`. A tip: if `git log` is a bit scarse or complicated to use, or maybe you are just bored, I recommend checking out various `git` GUIs and command line tools. In the past I’ve used [GitX][1] which was very good, but since the command line feels like home to me, after trying [tig][2] I’ve never looked back. + +### Finding Nemo + +So now, since we know the bare minimum of the `git log` command, let’s see how we can explore the history more effectively in our everyday work. + +Let’s say, hypothetically, we are suspecting an unexpected behaviour in the`String#classify` method and we want to find how and where it has been implemented. + +One of the first commands that you can use, to see where the method is defined, is `git grep`. Simply said, this command prints out lines that match a certain pattern. Now, to find the definition of the method, it’s pretty simple - we can grep for `def classify` and see what we get: + +``` +➜ git grep 'def classify'activesupport/lib/active_support/core_ext/string/inflections.rb: def classifyactivesupport/lib/active_support/inflector/methods.rb: def classify(table_name)tools/profile: def classify +``` + +Now, although we can already see where our method is created, we are not sure on which line it is. If we add the `-n` flag to our `git grep` command, `git` will provide the line numbers of the match: + +``` +➜ git grep -n 'def classify'activesupport/lib/active_support/core_ext/string/inflections.rb:205: def classifyactivesupport/lib/active_support/inflector/methods.rb:186: def classify(table_name)tools/profile:112: def classify +``` + +Much better, right? Having the context in mind, we can easily figure out that the method that we are looking for lives in `activesupport/lib/active_support/core_ext/string/inflections.rb`, on line 205\. The `classify` method, in all of it’s glory looks like this: + +``` +# Creates a class name from a plural table name like Rails does for table names to models.# Note that this returns a string and not a class. (To convert to an actual class# follow +classify+ with +constantize+.)## 'ham_and_eggs'.classify # => "HamAndEgg"# 'posts'.classify # => "Post"def classify ActiveSupport::Inflector.classify(self)end +``` + +Although the method we found is the one we usually call on `String`s, it invokes another method on the `ActiveSupport::Inflector`, with the same name. Having our `git grep` result available, we can easily navigate there, since we can see the second line of the result being`activesupport/lib/active_support/inflector/methods.rb` on line 186\. The method that we are are looking for is: + +``` +# Creates a class name from a plural table name like Rails does for table# names to models. Note that this returns a string and not a Class (To# convert to an actual class follow +classify+ with #constantize).## classify('ham_and_eggs') # => "HamAndEgg"# classify('posts') # => "Post"## Singular names are not handled correctly:## classify('calculus') # => "Calculus"def classify(table_name) # strip out any leading schema name camelize(singularize(table_name.to_s.sub(/.*\./, ''.freeze)))end +``` + +Boom! Given the size of Rails, finding this should not take us more than 30 seconds with the help of `git grep`. + +### So, what changed last? + +Now, since we have the method available, we need to figure out what were the changes that this file has gone through. The since we know the correct file name and line number, we can use `git blame`. This command shows what revision and author last modified each line of a file. Let’s see what were the latest changes made to this file: + +``` +git blame activesupport/lib/active_support/inflector/methods.rb +``` + +Whoa! Although we get the last change of every line in the file, we are more interested in the specific method (lines 176 to 189). Let’s add a flag to the `git blame` command, that will show the blame of just those lines. Also, we will add the `-s` (suppress) option to the command, to skip the author names and the timestamp of the revision (commit) that changed the line: + +``` +git blame -L 176,189 -s activesupport/lib/active_support/inflector/methods.rb9fe8e19a 176) # Creates a class name from a plural table name like Rails does for table5ea3f284 177) # names to models. Note that this returns a string and not a Class (To9fe8e19a 178) # convert to an actual class follow +classify+ with #constantize).51cd6bb8 179) #6d077205 180) # classify('ham_and_eggs') # => "HamAndEgg"9fe8e19a 181) # classify('posts') # => "Post"51cd6bb8 182) #51cd6bb8 183) # Singular names are not handled correctly:5ea3f284 184) #66d6e7be 185) # classify('calculus') # => "Calculus"51cd6bb8 186) def classify(table_name)51cd6bb8 187) # strip out any leading schema name5bb1d4d2 188) camelize(singularize(table_name.to_s.sub(/.*\./, ''.freeze)))51cd6bb8 189) end +``` + +The output of the `git blame` command now shows all of the file lines and their respective revisions. Now, to see a specific revision, or in other words, what each of those revisions changed, we can use the `git show` command. When supplied a revision hash (like `66d6e7be`) as an argument, it will show you the full revision, with the author name, timestamp and the whole revision in it’s glory. Let’s see what actually changed at the latest revision that changed line 188: + +``` +git show 5bb1d4d2 +``` + +Whoa! Did you test that? If you didn’t, it’s an awesome [commit][3] by [Schneems][4] that made a very interesting performance optimization by using frozen strings, which makes sense in our current context. But, since we are on this hypothetical debugging session, this doesn’t tell much about our current problem. So, how can we see what changes has our method under investigation gone through? + +### Searching the logs + +Now, we are back to the `git` log. The question is, how can we see all the revisions that the `classify` method went under? + +The `git log` command is quite powerful, because it has a rich list of options to apply to it. We can try to see what the `git` log has stored for this file, using the `-p`options, which means show me the patch for this entry in the `git` log: + +``` +git log -p activesupport/lib/active_support/inflector/methods.rb +``` + +This will show us a big list of revisions, for every revision of this file. But, just like before, we are interested in the specific file lines. Let’s modify the command a bit, to show us what we need: + +``` +git log -L 176,189:activesupport/lib/active_support/inflector/methods.rb +``` + +The `git log` command accepts the `-L` option, which takes the lines range and the filename as arguments. The format might be a bit weird for you, but it translates to: + +``` +git log -L ,: +``` + +When we run this command, we can see the list of revisions for these lines, which will lead us to the first revision that created the method: + +``` +commit 51xd6bb829c418c5fbf75de1dfbb177233b1b154Author: Foo Bar Date: Tue Jun 7 19:05:09 2011 -0700 Refactordiff --git a/activesupport/lib/active_support/inflector/methods.rb b/activesupport/lib/active_support/inflector/methods.rb--- a/activesupport/lib/active_support/inflector/methods.rb+++ b/activesupport/lib/active_support/inflector/methods.rb@@ -58,0 +135,14 @@+ # Create a class name from a plural table name like Rails does for table names to models.+ # Note that this returns a string and not a Class. (To convert to an actual class+ # follow +classify+ with +constantize+.)+ #+ # Examples:+ # "egg_and_hams".classify # => "EggAndHam"+ # "posts".classify # => "Post"+ #+ # Singular names are not handled correctly:+ # "business".classify # => "Busines"+ def classify(table_name)+ # strip out any leading schema name+ camelize(singularize(table_name.to_s.sub(/.*\./, '')))+ end +``` + +Now, look at that - it’s a commit from 2011\. Practically, `git` allows us to travel back in time. This is a very good example of why a proper commit message is paramount to regain context, because from the commit message we cannot really regain context of how this method came to be. But, on the flip side, you should **never ever** get frustrated about it, because you are looking at someone that basically gives away his time and energy for free, doing open source work. + +Coming back from that tangent, we are not sure how the initial implementation of the `classify` method came to be, given that the first commit is just a refactor. Now, if you are thinking something within the lines of “but maybe, just maybe, the method was not on the line range 176 to 189, and we should look more broadly in the file”, you are very correct. The revision that we saw said “Refactor” in it’s commit message, which means that the method was actually there, but after that refactor it started to exist on that line range. + +So, how can we confirm this? Well, believe it or not, `git` comes to the rescue again. The `git log` command accepts the `-S` option, which looks for the code change (additions or deletions) for the specified string as an argument to the command. This means that, if we call `git log -S classify`, we can see all of the commits that changed a line that contains that string. + +If you call this command in the Rails repo, you will first see `git` slowing down a bit. But, when you realise that `git` actually parses all of the revisions in the repo to match the string, it’s actually super fast. Again, the power of `git` at your fingertips. So, to find the first version of the `classify` method, we can run: + +``` +git log -S 'def classify' +``` + +This will return all of the revisions where this method has been introduced or changed. If you were following along, the last commit in the log that you will see is: + +``` +commit db045dbbf60b53dbe013ef25554fd013baf88134Author: David Heinemeier Hansson Date: Wed Nov 24 01:04:44 2004 +0000 Initial git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4 5ecf4fe2-1ee6-0310-87b1-e25e094e27de +``` + +How cool is that? It’s the initial commit to Rails, made on a `svn` repo by DHH! This means that `classify` has been around since the beginning of (Rails) time. Now, to see the commit with all of it’s changes, we can run: + +``` +git show db045dbbf60b53dbe013ef25554fd013baf88134 +``` + +Great, we got to the bottom of it. Now, by using the output from `git log -S 'def classify'` you can track the changes that have happened to this method, combined with the power of the `git log -L` command. + +### Until next time + +Sure, we didn’t really fix any bugs, because we were trying some `git` commands and following along the evolution of the `classify` method. But, nevertheless, `git` is a very powerful tool that we all must learn to use and to embrace. I hope this article gave you a little bit more knowledge of how useful `git` is. + +What are your favourite (or, most effective) ways of navigating through the `git`history? + +-------------------------------------------------------------------------------- + +作者简介: + +Backend engineer, interested in Ruby, Go, microservices, building resilient architectures and solving challenges at scale. I coach at Rails Girls in Amsterdam, maintain a list of small gems and often contribute to Open Source. +This is where I write about software development, programming languages and everything else that interests me. + +------ + +via: https://ieftimov.com/learn-your-tools-navigating-git-history + +作者:[Ilija Eftimov ][a] +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://ieftimov.com/ +[1]:http://gitx.frim.nl/ +[2]:https://github.com/jonas/tig +[3]:https://github.com/rails/rails/commit/5bb1d4d288d019e276335465d0389fd2f5246bfd +[4]:https://twitter.com/schneems \ No newline at end of file diff --git a/sources/tech/20161106 Myths about -dev-urandom.md b/sources/tech/20161106 Myths about -dev-urandom.md new file mode 100644 index 0000000000..b00b5863d8 --- /dev/null +++ b/sources/tech/20161106 Myths about -dev-urandom.md @@ -0,0 +1,289 @@ +Myths about /dev/urandom +====== + +There are a few things about /dev/urandom and /dev/random that are repeated again and again. Still they are false. + +I'm mostly talking about reasonably recent Linux systems, not other UNIX-like systems. + +### /dev/urandom is insecure. Always use /dev/random for cryptographic purposes. + +Fact: /dev/urandom is the preferred source of cryptographic randomness on UNIX-like systems. + +### /dev/urandom is a pseudo random number generator, a PRNG, while /dev/random is a “true” random number generator. + +Fact: Both /dev/urandom and /dev/random are using the exact same CSPRNG (a cryptographically secure pseudorandom number generator). They only differ in very few ways that have nothing to do with “true” randomness. + +### /dev/random is unambiguously the better choice for cryptography. Even if /dev/urandom were comparably secure, there's no reason to choose the latter. + +Fact: /dev/random has a very nasty problem: it blocks. + +### But that's good! /dev/random gives out exactly as much randomness as it has entropy in its pool. /dev/urandom will give you insecure random numbers, even though it has long run out of entropy. + +Fact: No. Even disregarding issues like availability and subsequent manipulation by users, the issue of entropy “running low” is a straw man. About 256 bits of entropy are enough to get computationally secure numbers for a long, long time. + +And the fun only starts here: how does /dev/random know how much entropy there is available to give out? Stay tuned! + +### But cryptographers always talk about constant re-seeding. Doesn't that contradict your last point? + +Fact: You got me! Kind of. It is true, the random number generator is constantly re-seeded using whatever entropy the system can lay its hands on. But that has (partly) other reasons. + +Look, I don't claim that injecting entropy is bad. It's good. I just claim that it's bad to block when the entropy estimate is low. + +### That's all good and nice, but even the man page for /dev/(u)random contradicts you! Does anyone who knows about this stuff actually agree with you? + +Fact: No, it really doesn't. It seems to imply that /dev/urandom is insecure for cryptographic use, unless you really understand all that cryptographic jargon. + +The man page does recommend the use of /dev/random in some cases (it doesn't hurt, in my opinion, but is not strictly necessary), but it also recommends /dev/urandom as the device to use for “normal” cryptographic use. + +And while appeal to authority is usually nothing to be proud of, in cryptographic issues you're generally right to be careful and try to get the opinion of a domain expert. + +And yes, quite a few experts share my view that /dev/urandom is the go-to solution for your random number needs in a cryptography context on UNIX-like systems. Obviously, their opinions influenced mine, not the other way around. + +Hard to believe, right? I must certainly be wrong! Well, read on and let me try to convince you. + +I tried to keep it out, but I fear there are two preliminaries to be taken care of, before we can really tackle all those points. + +Namely, what is randomness, or better: what kind of randomness am I talking about here? + +And, even more important, I'm really not being condescending. I have written this document to have a thing to point to, when this discussion comes up again. More than 140 characters. Without repeating myself again and again. Being able to hone the writing and the arguments itself, benefitting many discussions in many venues. + +And I'm certainly willing to hear differing opinions. I'm just saying that it won't be enough to state that /dev/urandom is bad. You need to identify the points you're disagreeing with and engage them. + +### You're saying I'm stupid! + +Emphatically no! + +Actually, I used to believe that /dev/urandom was insecure myself, a few years ago. And it's something you and me almost had to believe, because all those highly respected people on Usenet, in web forums and today on Twitter told us. Even the man page seems to say so. Who were we to dismiss their convincing argument about “entropy running low”? + +This misconception isn't so rampant because people are stupid, it is because with a little knowledge about cryptography (namely some vague idea what entropy is) it's very easy to be convinced of it. Intuition almost forces us there. Unfortunately intuition is often wrong in cryptography. So it is here. + +### True randomness + +What does it mean for random numbers to be “truly random”? + +I don't want to dive into that issue too deep, because it quickly gets philosophical. Discussions have been known to unravel fast, because everyone can wax about their favorite model of randomness, without paying attention to anyone else. Or even making himself understood. + +I believe that the “gold standard” for “true randomness” are quantum effects. Observe a photon pass through a semi-transparent mirror. Or not. Observe some radioactive material emit alpha particles. It's the best idea we have when it comes to randomness in the world. Other people might reasonably believe that those effects aren't truly random. Or even that there is no randomness in the world at all. Let a million flowers bloom. + +Cryptographers often circumvent this philosophical debate by disregarding what it means for randomness to be “true”. They care about unpredictability. As long as nobody can get any information about the next random number, we're fine. And when you're talking about random numbers as a prerequisite in using cryptography, that's what you should aim for, in my opinion. + +Anyway, I don't care much about those “philosophically secure” random numbers, as I like to think of your “true” random numbers. + +### Two kinds of security, one that matters + +But let's assume you've obtained those “true” random numbers. What are you going to do with them? + +You print them out, frame them and hang them on your living-room wall, to revel in the beauty of a quantum universe? That's great, and I certainly understand. + +Wait, what? You're using them? For cryptographic purposes? Well, that spoils everything, because now things get a bit ugly. + +You see, your truly-random, quantum effect blessed random numbers are put into some less respectable, real-world tarnished algorithms. + +Because almost all of the cryptographic algorithms we use do not hold up to ### information-theoretic security**. They can “only” offer **computational security. The two exceptions that come to my mind are Shamir's Secret Sharing and the One-time pad. And while the first one may be a valid counterpoint (if you actually intend to use it), the latter is utterly impractical. + +But all those algorithms you know about, AES, RSA, Diffie-Hellman, Elliptic curves, and all those crypto packages you're using, OpenSSL, GnuTLS, Keyczar, your operating system's crypto API, these are only computationally secure. + +What's the difference? While information-theoretically secure algorithms are secure, period, those other algorithms cannot guarantee security against an adversary with unlimited computational power who's trying all possibilities for keys. We still use them because it would take all the computers in the world taken together longer than the universe has existed, so far. That's the level of “insecurity” we're talking about here. + +Unless some clever guy breaks the algorithm itself, using much less computational power. Even computational power achievable today. That's the big prize every cryptanalyst dreams about: breaking AES itself, breaking RSA itself and so on. + +So now we're at the point where you don't trust the inner building blocks of the random number generator, insisting on “true randomness” instead of “pseudo randomness”. But then you're using those “true” random numbers in algorithms that you so despise that you didn't want them near your random number generator in the first place! + +Truth is, when state-of-the-art hash algorithms are broken, or when state-of-the-art block ciphers are broken, it doesn't matter that you get “philosophically insecure” random numbers because of them. You've got nothing left to securely use them for anyway. + +So just use those computationally-secure random numbers for your computationally-secure algorithms. In other words: use /dev/urandom. + +### Structure of Linux's random number generator + +#### An incorrect view + +Chances are, your idea of the kernel's random number generator is something similar to this: + +![image: mythical structure of the kernel's random number generator][1] + +“True randomness”, albeit possibly skewed and biased, enters the system and its entropy is precisely counted and immediately added to an internal entropy counter. After de-biasing and whitening it's entering the kernel's entropy pool, where both /dev/random and /dev/urandom get their random numbers from. + +The “true” random number generator, /dev/random, takes those random numbers straight out of the pool, if the entropy count is sufficient for the number of requested numbers, decreasing the entropy counter, of course. If not, it blocks until new entropy has entered the system. + +The important thing in this narrative is that /dev/random basically yields the numbers that have been input by those randomness sources outside, after only the necessary whitening. Nothing more, just pure randomness. + +/dev/urandom, so the story goes, is doing the same thing. Except when there isn't sufficient entropy in the system. In contrast to /dev/random, it does not block, but gets “low quality random” numbers from a pseudorandom number generator (conceded, a cryptographically secure one) that is running alongside the rest of the random number machinery. This CSPRNG is just seeded once (or maybe every now and then, it doesn't matter) with “true randomness” from the randomness pool, but you can't really trust it. + +In this view, that seems to be in a lot of people's minds when they're talking about random numbers on Linux, avoiding /dev/urandom is plausible. + +Because either there is enough entropy left, then you get the same you'd have gotten from /dev/random. Or there isn't, then you get those low-quality random numbers from a CSPRNG that almost never saw high-entropy input. + +Devilish, right? Unfortunately, also utterly wrong. In reality, the internal structure of the random number generator looks like this. + +#### A better simplification + +##### Before Linux 4.8 + +![image: actual structure of the kernel's random number generator before Linux 4.8][2] This is a pretty rough simplification. In fact, there isn't just one, but three pools filled with entropy. One primary pool, and one for /dev/random and /dev/urandom each, feeding off the primary pool. Those three pools all have their own entropy counts, but the counts of the secondary pools (for /dev/random and /dev/urandom) are mostly close to zero, and “fresh” entropy flows from the primary pool when needed, decreasing its entropy count. Also there is a lot of mixing and re-injecting outputs back into the system going on. All of this is far more detail than is necessary for this document. + +See the big difference? The CSPRNG is not running alongside the random number generator, filling in for those times when /dev/urandom wants to output something, but has nothing good to output. The CSPRNG is an integral part of the random number generation process. There is no /dev/random handing out “good and pure” random numbers straight from the whitener. Every randomness source's input is thoroughly mixed and hashed inside the CSPRNG, before it emerges as random numbers, either via /dev/urandom or /dev/random. + +Another important difference is that there is no entropy counting going on here, but estimation. The amount of entropy some source is giving you isn't something obvious that you just get, along with the data. It has to be estimated. Please note that when your estimate is too optimistic, the dearly held property of /dev/random, that it's only giving out as many random numbers as available entropy allows, is gone. Unfortunately, it's hard to estimate the amount of entropy. + +The Linux kernel uses only the arrival times of events to estimate their entropy. It does that by interpolating polynomials of those arrival times, to calculate “how surprising” the actual arrival time was, according to the model. Whether this polynomial interpolation model is the best way to estimate entropy is an interesting question. There is also the problem that internal hardware restrictions might influence those arrival times. The sampling rates of all kinds of hardware components may also play a role, because it directly influences the values and the granularity of those event arrival times. + +In the end, to the best of our knowledge, the kernel's entropy estimate is pretty good. Which means it's conservative. People argue about how good it really is, but that issue is far above my head. Still, if you insist on never handing out random numbers that are not “backed” by sufficient entropy, you might be nervous here. I'm sleeping sound because I don't care about the entropy estimate. + +So to make one thing crystal clear: both /dev/random and /dev/urandom are fed by the same CSPRNG. Only the behavior when their respective pool runs out of entropy, according to some estimate, differs: /dev/random blocks, while /dev/urandom does not. + +##### From Linux 4.8 onward + +In Linux 4.8 the equivalency between /dev/urandom and /dev/random was given up. Now /dev/urandom output does not come from an entropy pool, but directly from a CSPRNG. + +![image: actual structure of the kernel's random number generator from Linux 4.8 onward][3] + +We will see shortly why that is not a security problem. + +### What's wrong with blocking? + +Have you ever waited for /dev/random to give you more random numbers? Generating a PGP key inside a virtual machine maybe? Connecting to a web server that's waiting for more random numbers to create an ephemeral session key? + +That's the problem. It inherently runs counter to availability. So your system is not working. It's not doing what you built it to do. Obviously, that's bad. You wouldn't have built it if you didn't need it. + +I'm working on safety-related systems in factory automation. Can you guess what the main reason for failures of safety systems is? Manipulation. Simple as that. Something about the safety measure bugged the worker. It took too much time, was too inconvenient, whatever. People are very resourceful when it comes to finding “inofficial solutions”. + +But the problem runs even deeper: people don't like to be stopped in their ways. They will devise workarounds, concoct bizarre machinations to just get it running. People who don't know anything about cryptography. Normal people. + +Why not patching out the call to `random()`? Why not having some guy in a web forum tell you how to use some strange ioctl to increase the entropy counter? Why not switch off SSL altogether? + +In the end you just educate your users to do foolish things that compromise your system's security without you ever knowing about it. + +It's easy to disregard availability, usability or other nice properties. Security trumps everything, right? So better be inconvenient, unavailable or unusable than feign security. + +But that's a false dichotomy. Blocking is not necessary for security. As we saw, /dev/urandom gives you the same kind of random numbers as /dev/random, straight out of a CSPRNG. Use it! + +### The CSPRNGs are alright + +But now everything sounds really bleak. If even the high-quality random numbers from /dev/random are coming out of a CSPRNG, how can we use them for high-security purposes? + +It turns out, that “looking random” is the basic requirement for a lot of our cryptographic building blocks. If you take the output of a cryptographic hash, it has to be indistinguishable from a random string so that cryptographers will accept it. If you take a block cipher, its output (without knowing the key) must also be indistinguishable from random data. + +If anyone could gain an advantage over brute force breaking of cryptographic building blocks, using some perceived weakness of those CSPRNGs over “true” randomness, then it's the same old story: you don't have anything left. Block ciphers, hashes, everything is based on the same mathematical fundament as CSPRNGs. So don't be afraid. + +### What about entropy running low? + +It doesn't matter. + +The underlying cryptographic building blocks are designed such that an attacker cannot predict the outcome, as long as there was enough randomness (a.k.a. entropy) in the beginning. A usual lower limit for “enough” may be 256 bits. No more. + +Considering that we were pretty hand-wavey about the term “entropy” in the first place, it feels right. As we saw, the kernel's random number generator cannot even precisely know the amount of entropy entering the system. Only an estimate. And whether the model that's the basis for the estimate is good enough is pretty unclear, too. + +### Re-seeding + +But if entropy is so unimportant, why is fresh entropy constantly being injected into the random number generator? + +djb [remarked][4] that more entropy actually can hurt. + +First, it cannot hurt. If you've got more randomness just lying around, by all means use it! + +There is another reason why re-seeding the random number generator every now and then is important: + +Imagine an attacker knows everything about your random number generator's internal state. That's the most severe security compromise you can imagine, the attacker has full access to the system. + +You've totally lost now, because the attacker can compute all future outputs from this point on. + +But over time, with more and more fresh entropy being mixed into it, the internal state gets more and more random again. So that such a random number generator's design is kind of self-healing. + +But this is injecting entropy into the generator's internal state, it has nothing to do with blocking its output. + +### The random and urandom man page + +The man page for /dev/random and /dev/urandom is pretty effective when it comes to instilling fear into the gullible programmer's mind: + +> A read from the /dev/urandom device will not block waiting for more entropy. As a result, if there is not sufficient entropy in the entropy pool, the returned values are theoretically vulnerable to a cryptographic attack on the algorithms used by the driver. Knowledge of how to do this is not available in the current unclassified literature, but it is theoretically possible that such an attack may exist. If this is a concern in your application, use /dev/random instead. + +Such an attack is not known in “unclassified literature”, but the NSA certainly has one in store, right? And if you're really concerned about this (you should!), please use /dev/random, and all your problems are solved. + +The truth is, while there may be such an attack available to secret services, evil hackers or the Bogeyman, it's just not rational to just take it as a given. + +And even if you need that peace of mind, let me tell you a secret: no practical attacks on AES, SHA-3 or other solid ciphers and hashes are known in the “unclassified” literature, either. Are you going to stop using those, as well? Of course not! + +Now the fun part: “use /dev/random instead”. While /dev/urandom does not block, its random number output comes from the very same CSPRNG as /dev/random's. + +If you really need information-theoretically secure random numbers (you don't!), and that's about the only reason why the entropy of the CSPRNGs input matters, you can't use /dev/random, either! + +The man page is silly, that's all. At least it tries to redeem itself with this: + +> If you are unsure about whether you should use /dev/random or /dev/urandom, then probably you want to use the latter. As a general rule, /dev/urandom should be used for everything except long-lived GPG/SSL/SSH keys. + +Fine. I think it's unnecessary, but if you want to use /dev/random for your “long-lived keys”, by all means, do so! You'll be waiting a few seconds typing stuff on your keyboard, that's no problem. + +But please don't make connections to a mail server hang forever, just because you “wanted to be safe”. + +### Orthodoxy + +The view espoused here is certainly a tiny minority's opinions on the Internet. But ask a real cryptographer, you'll be hard pressed to find someone who sympathizes much with that blocking /dev/random. + +Let's take [Daniel Bernstein][5], better known as djb: + +> Cryptographers are certainly not responsible for this superstitious nonsense. Think about this for a moment: whoever wrote the /dev/random manual page seems to simultaneously believe that +> +> * (1) we can't figure out how to deterministically expand one 256-bit /dev/random output into an endless stream of unpredictable keys (this is what we need from urandom), but +> +> * (2) we _can_ figure out how to use a single key to safely encrypt many messages (this is what we need from SSL, PGP, etc.). +> +> + +> +> For a cryptographer this doesn't even pass the laugh test. + +Or [Thomas Pornin][6], who is probably one of the most helpful persons I've ever encountered on the Stackexchange sites: + +> The short answer is yes. The long answer is also yes. /dev/urandom yields data which is indistinguishable from true randomness, given existing technology. Getting "better" randomness than what /dev/urandom provides is meaningless, unless you are using one of the few "information theoretic" cryptographic algorithm, which is not your case (you would know it). +> +> The man page for urandom is somewhat misleading, arguably downright wrong, when it suggests that /dev/urandom may "run out of entropy" and /dev/random should be preferred; + +Or maybe [Thomas Ptacek][7], who is not a real cryptographer in the sense of designing cryptographic algorithms or building cryptographic systems, but still the founder of a well-reputed security consultancy that's doing a lot of penetration testing and breaking bad cryptography: + +> Use urandom. Use urandom. Use urandom. Use urandom. Use urandom. Use urandom. + +### Not everything is perfect + +/dev/urandom isn't perfect. The problems are twofold: + +On Linux, unlike FreeBSD, /dev/urandom never blocks. Remember that the whole security rested on some starting randomness, a seed? + +Linux's /dev/urandom happily gives you not-so-random numbers before the kernel even had the chance to gather entropy. When is that? At system start, booting the computer. + +FreeBSD does the right thing: they don't have the distinction between /dev/random and /dev/urandom, both are the same device. At startup /dev/random blocks once until enough starting entropy has been gathered. Then it won't block ever again. + +In the meantime, Linux has implemented a new syscall, originally introduced by OpenBSD as getentropy(2): getrandom(2). This syscall does the right thing: blocking until it has gathered enough initial entropy, and never blocking after that point. Of course, it is a syscall, not a character device, so it isn't as easily accessible from shell or script languages. It is available from Linux 3.17 onward. + +On Linux it isn't too bad, because Linux distributions save some random numbers when booting up the system (but after they have gathered some entropy, since the startup script doesn't run immediately after switching on the machine) into a seed file that is read next time the machine is booting. So you carry over the randomness from the last running of the machine. + +Obviously that isn't as good as if you let the shutdown scripts write out the seed, because in that case there would have been much more time to gather entropy. The advantage is obviously that this does not depend on a proper shutdown with execution of the shutdown scripts (in case the computer crashes, for example). + +And it doesn't help you the very first time a machine is running, but the Linux distributions usually do the same saving into a seed file when running the installer. So that's mostly okay. + +Virtual machines are the other problem. Because people like to clone them, or rewind them to a previously saved check point, this seed file doesn't help you. + +But the solution still isn't using /dev/random everywhere, but properly seeding each and every virtual machine after cloning, restoring a checkpoint, whatever. + +### tldr; + + Just use /dev/urandom! + + +-------------------------------------------------------------------------------- + +via: https://www.2uo.de/myths-about-urandom/ + +作者:[Thomas Hühn][a] +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.2uo.de/ +[1]:https://www.2uo.de/myths-about-urandom/structure-no.png +[2]:https://www.2uo.de/myths-about-urandom/structure-yes.png +[3]:https://www.2uo.de/myths-about-urandom/structure-new.png +[4]:http://blog.cr.yp.to/20140205-entropy.html +[5]:http://www.mail-archive.com/cryptography@randombit.net/msg04763.html +[6]:http://security.stackexchange.com/questions/3936/is-a-rand-from-dev-urandom-secure-for-a-login-key/3939#3939 +[7]:http://sockpuppet.org/blog/2014/02/25/safely-generate-random-numbers/ diff --git a/sources/tech/20170428 Ultimate guide to securing SSH sessions.md b/sources/tech/20170428 Ultimate guide to securing SSH sessions.md new file mode 100644 index 0000000000..a96c4da6e7 --- /dev/null +++ b/sources/tech/20170428 Ultimate guide to securing SSH sessions.md @@ -0,0 +1,139 @@ +Ultimate guide to securing SSH sessions +====== +Hi Linux-fanatics, in this tutorial we will be discussing some ways with which we make our ssh server more secure. OpenSSH is currently used by default to work on servers as physical access to servers is very limited. We use ssh to copy/backup files/folders, to remotely execute commands etc. But these ssh connections might not be as secure as we believee & we must make some changes to our default settings to make them more secure. + +Here are steps needed to secure our ssh sessions, + +### Use complex username & password + +This is first of the problem that needs to be addressed, I have known users who have '12345' as their password. It seems they are inviting hackers to get themselves hacked. You should always have a complex password. + +It should have at-least 8 characters with numbers & alphabets, lower case & upper case letter, and also special characters. A good example would be " ** ** _vXdrf23#$wd_**** " , it is not a word so dictionary attack will be useless & has uppercase, lowercase characters, numbers & special characters. + +### Limit user logins + +Not all the users are required to have access to ssh in an organization, so we should make changes to our configuration file to limit user logins. Let's say only Bob & Susan are authorized have access to ssh, so open your configuration file + +``` + $ vi /etc/ssh/sshd_config +``` + +& add the allowed users to the bottom of the file + +``` + AllowUsers bob susan +``` + +Save the file & restart the service. Now only Bob & Susan will have access to ssh , others won't be able to access ssh. + +### Configure Idle logout time + + +Once logged into ssh sessions, there is default time before sessions logs out on it own. By default idle logout time is 60 minutes, which according to me is way to much. Consider this, you logged into a session , executed some commands & then went out to get a cup of coffee but you forgot to log-out of the ssh. Just think what could be done in the 60 seconds, let alone in 60 minutes. + +So, its wise to reduce idle log-out time to something around 5 minutes & it can be done in config file only. Open '/etc/ssh/sshd_config' & change the values + +``` +ClientAliveInterval 300 +ClientAliveCountMax 0 +``` + +Its in seconds, so configure them accordingly. + +### Disable root logins + +As we know root have access to anything & everything on the server, so we must disable root access through ssh session. Even if it is needed to complete a task that only root can do, we can escalate the privileges of a normal user. + +To disable root access, open your configuration file & change the following parameter + +``` +PermitRootLogin no +ClientAliveCountMax 0 +``` + +This will disable root access to ssh sessions. + +### Enable Protocol 2 + +SSH protocol 1 had man in the middle attack issues & other security issues as well, all these issues were addressed in Protocol 2. So protocol 1 must not be used at any cost. To change the protocol , open your sshd_config file & change the following parameter + +``` + Protocol 2 +``` + +### Enable a warning screen + +It would be a good idea to enable a warning screen stating a warning about misuse of ssh, just before a user logs into the session. To create a warning screen, create a file named **" warning"** in **/etc/** folder (or any other folder) & write something like "We monitor all our sessions on continuously. Don't misuse your access or else you will be prosecuted" or whatever you wish to warn. You can also consult legal team about this warning to make it more official. + +After this file is create, open sshd_config file & enter the following parameter into the file + +``` + Banner /etc/issue +``` + +now you warning message will be displayed each time someone tries to access the session. + +### Use non-standard ssh port + +By default, ssh uses port 22 & all the brute force scripts are written for port 22 only. So to make your sessions even more secure, use a non-standard port like 15000. But make sure before selecting a port that its not being used by some other service. + +To change port, open sshd_config & change the following parameter + +``` + Port 15000 +``` + +Save & restart the service and you can access the ssh only with this new port. To start a session with custom port use the following command + +``` + $ ssh -p 15000 {server IP} +``` + +** Note:-** If using firewall, open the port on your firewall & we must also change the SELinux settings if using a custom port for ssh. Run the following command to update the SELinux label + +``` +$ semanage port -a -t ssh_port_t -p tcp 15000 +``` + +### Limit IP access + +If you have an environment where your server is accessed by only limited number of IP addresses, you can also allow access to those IP addresses only. Open sshd_config file & enter the following with your custom port + +``` +Port 15000 +ListenAddress 192.168.1.100 +ListenAddress 192.168.1.115 +``` + +Now ssh session will only be available to these mentioned IPs with the custom port 15000. + +### Disable empty passwords + +As mentioned already that you should only use complex username & passwords, so using an empty password for remote login is a complete no-no. To disable empty passwords, open sshd_config file & edit the following parameter + +``` +PermitEmptyPasswords no +``` + +### Use public/private key based authentication + +Using Public/Private key based authentication has its advantages i.e. you no longer need to enter the password when entering into a session (unless you are using a passphrase to decrypt the key) & no one can have access to your server until & unless they have the right authentication key. Process to setup public/private key based authentication is discussed in [**this tutorial here**][1]. + +So, this completes our tutorial on securing your ssh server. If having any doubts or issues, please leave a message in the comment box below. + +-------------------------------------------------------------------------------- + +via: http://linuxtechlab.com/ultimate-guide-to-securing-ssh-sessions/ + +作者:[SHUSAIN][a] +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:http://linuxtechlab.com/author/shsuain/ +[1]:http://linuxtechlab.com/configure-ssh-server-publicprivate-key/ +[2]:https://www.facebook.com/techlablinux/ +[3]:https://twitter.com/LinuxTechLab +[4]:https://plus.google.com/+linuxtechlab +[5]:http://linuxtechlab.com/contact-us-2/ diff --git a/sources/tech/20170429 Monitoring network bandwidth with iftop command.md b/sources/tech/20170429 Monitoring network bandwidth with iftop command.md new file mode 100644 index 0000000000..1eb7ed24a8 --- /dev/null +++ b/sources/tech/20170429 Monitoring network bandwidth with iftop command.md @@ -0,0 +1,97 @@ +translating---geekpi + +Monitoring network bandwidth with iftop command +====== +System Admins are required to monitor IT infrastructure to make sure that everything is up & running. We have to monitor performance of hardware i.e memory, hdds & CPUs etc & so does we have to monitor our network. We need to make sure that our network is not being over utilised or our applications, websites might not work. In this tutorial, we are going to learn to use IFTOP utility. + +( **Recommended read** :[ **Resource monitoring using Nagios**][1], [**Tools for checking system info**,][2] [**Important logs to monitor**][3]) + +Iftop is network monitoring utility that provides real time real time bandwidth monitoring. Iftop measures total data moving in & out of the individual socket connections i.e. it captures packets moving in and out via network adapter & than sums those up to find the bandwidth being utilized. + +## Installation on Debian/Ubuntu + +Iftop is available with default repositories of Debian/Ubuntu & can be simply installed using the command below, + +``` +$ sudo apt-get install iftop +``` + +## Installation on RHEL/Centos using yum + +For installing iftop on CentOS or RHEL, we need to enable EPEL repository. To enable repository, run the following on your terminal, + +### RHEL/CentOS 7 + +``` +$ rpm -Uvh https://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-10.noarch.rpm +``` + +### RHEL/CentOS 6 (64 Bit) + +``` +$ rpm -Uvh http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm +``` + +### RHEL/CentOS 6 (32 Bit) + +``` +$ rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm +``` + +After epel repository has been installed, we can now install iftop by running, + +``` +$ yum install iftop +``` + +This will install iftop utility on your system. We will now use it to monitor our network, + +## Using IFTOP + +You can start using iftop by opening your terminal windown & type, + +``` +$ iftop +``` + +![network monitoring][5] + +You will now be presented with network activity happening on your machine. You can also use + +``` +$ iftop -n +``` + +Which will present the network information on your screen but with '-n' , you will not be presented with the names related to IP addresses but only ip addresses. This option allows for some bandwidth to be saved, which goes into resolving IP addresses to names. + +Now we can also see all the commands that can be used with iftop. Once you have ran iftop, press 'h' button on the keyboard to see all the commands that can be used with iftop. + +![network monitoring][7] + +To monitor a particular network interface, we can mention interface with iftop, + +``` +$ iftop -I enp0s3 +``` + +You can check further options that are used with iftop using help, as mentioned above. But these mentioned examples are only what you might to monitor network. + + +-------------------------------------------------------------------------------- + +via: http://linuxtechlab.com/monitoring-network-bandwidth-iftop-command/ + +作者:[SHUSAIN][a] +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:http://linuxtechlab.com/author/shsuain/ +[1]:http://linuxtechlab.com/installing-configuring-nagios-server/ +[2]:http://linuxtechlab.com/commands-system-hardware-info/ +[3]:http://linuxtechlab.com/important-logs-monitor-identify-issues/ +[4]:https://i1.wp.com/linuxtechlab.com/wp-content/plugins/a3-lazy-load/assets/images/lazy_placeholder.gif?resize=661%2C424 +[5]:https://i0.wp.com/linuxtechlab.com/wp-content/uploads/2017/04/iftop-1.jpg?resize=661%2C424 +[6]:https://i1.wp.com/linuxtechlab.com/wp-content/plugins/a3-lazy-load/assets/images/lazy_placeholder.gif?resize=663%2C416 +[7]:https://i0.wp.com/linuxtechlab.com/wp-content/uploads/2017/04/iftop-help.jpg?resize=663%2C416 diff --git a/sources/tech/20170505 Create your first Ansible server (automation) setup.md b/sources/tech/20170505 Create your first Ansible server (automation) setup.md new file mode 100644 index 0000000000..7bcd2997c8 --- /dev/null +++ b/sources/tech/20170505 Create your first Ansible server (automation) setup.md @@ -0,0 +1,164 @@ +Create your first Ansible server (automation) setup +====== +Automation/configuration management tools are the new craze in the IT world, organizations are moving towards adopting them. There are many tools that are available in market like Puppet, Chef, Ansible etc & in this tutorial, we are going to learn about Ansible. + +Ansible is an open source configuration tool; that is used to deploy, configure & manage servers. Ansible is one of the easiest automation tool to learn and master. It does not require you to learn complicated programming language like ruby (used in puppet & chef) & uses YAML, which is a very simple language. Also it does not require any special agent to be installed on client machines & only requires client machines to have python and ssh installed, both of these are usually available on systems. + +## Pre-requisites + +Before we move onto installation part, let's discuss the pre-requisites for Ansible + + 1. For server, we will need a machine with either CentOS or RHEL 7 installed & EPEL repository enabled + +To enable epel repository, use the commands below, + + **RHEL/CentOS 7** + +``` + $ rpm -Uvh https://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-10.noarch.rpm +``` + + **RHEL/CentOS 6 (64 Bit)** + +``` + $ rpm -Uvh http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm +``` + + **RHEL/CentOS 6 (32 Bit)** + +``` + $ rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm +``` + + 2. For client machines, Open SSH & python should be installed. Also we need to configure password less login for ssh session (create public-private keys). To create public-private keys & configure password less login for ssh session, refer to our article " + +[Setting up SSH Server for Public/Private keys based Authentication (Password-less login)][1]" + + + +## Installation + +Once we have epel repository enabled, we can now install anisble using yum, + +``` + $ yum install ansible +``` + +## Configuring Ansible hosts + +We will now configure hosts that we want Ansible to manage. To do that we need to edit the file **/etc/ansible/host** s & add the clients in following syntax, + +``` +[group-name] +alias ansible_ssh_host=host_IP_address +``` + +where, alias is the alias name given to hosts we adding & it can be anything, + +host_IP_address is where we enter the IP address for the hosts. + +For this tutorial, we are going to add 2 clients/hosts for ansible to manage, so let's create an entry for these two hosts in the configuration file, + +``` + $ vi /etc/ansible/hosts + [test_clients] + client1 ansible_ssh_host=192.168.1.101 + client2 ansible_ssh_host=192.168.1.10 +``` + +Save file & exit it. Now as mentioned in pre-requisites, we should have a password less login to these clients from the ansible server. To check if that's the case, ssh into the clients and we should be able to login without password, + +``` + $ ssh root@192.168.1.101 +``` + +If that's working, then we can move further otherwise we need to create Public/Private keys for ssh session (Refer to article mentioned above in pre-requisites). + +We are using root to login to other servers but we can use other local users as well & we need to define it for Ansible whatever user we will be using. To do so, we will first create a folder named 'group_vars' in '/etc/ansible' + +``` + $ cd /etc/ansible + $ mkdir group_vars +``` + +Next, we will create a file named after the group we have created in 'etc/ansible/hosts' i.e. test_clients + +``` + $ vi test_clients +``` + +& add the ifollowing information about the user, + +``` + -- + ansible_ssh_user:root +``` + + **Note :-** File will start with '--' (minus symbol), so keep not of that. + +If we want to use same user for all the groups created, then we can create only a single file named 'all' to mention the user details for ssh login, instead of creating a file for every group. + +``` + $ vi /etc/ansible/group_vars/all + -- + ansible_ssh_user: root +``` + +Similarly, we can setup files for individual hosts as well. + +Now, the setup for the clients has been done. We will now push some simple commands to all the clients being managed by Ansible. + +## Testing hosts + +To check the connectivity of all the hosts, we will issue a command, + +``` + $ ansible -m ping all +``` + +If all the hosts are properly connected, it should return the following output, + +``` + client1 | SUCCESS = > { + " changed": false, + " ping": "pong" + } + client2 | SUCCESS = > { + " changed": false, + " ping": "pong" + } +``` + +We can also issue command to an individual host, + +``` + $ ansible -m ping client1 +``` + +or to the multiple hosts, + +``` + $ ansible -m ping client1:client2 +``` + +or even to a single group, + +``` + $ ansible -m ping test_client +``` + +This complete our tutorial on setting up an Ansible server, in our future posts we will further explore funtinalities offered by Ansible. If any having doubts or queries regarding this post, use the comment box below. + + +-------------------------------------------------------------------------------- + +via: http://linuxtechlab.com/create-first-ansible-server-automation-setup/ + +作者:[SHUSAIN][a] +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:http://linuxtechlab.com/author/shsuain/ +[1]:http://linuxtechlab.com/configure-ssh-server-publicprivate-key/ diff --git a/sources/tech/20170508 Ansible Tutorial- Intorduction to simple Ansible commands.md b/sources/tech/20170508 Ansible Tutorial- Intorduction to simple Ansible commands.md deleted file mode 100644 index d0300fe6e3..0000000000 --- a/sources/tech/20170508 Ansible Tutorial- Intorduction to simple Ansible commands.md +++ /dev/null @@ -1,158 +0,0 @@ -translating---geekpi - -Ansible Tutorial: Intorduction to simple Ansible commands -====== -In our earlier Ansible tutorial, we discussed [**the installation & configuration of Ansible**][1]. Now in this ansible tutorial, we will learn some basic examples of ansible commands that we will use to manage our infrastructure. So let us start by looking at the syntax of a complete ansible command, - -``` -$ ansible -m -a -``` - -Here, we can also use a single host or all in place of & are optional to provide. Now let's look at some basic commands to use with ansible, - -### Check connectivity of hosts - -We have used this command in our previous tutorial also. The command to check connectivity of hosts is - -``` -$ ansible -m ping -``` - -### Rebooting hosts - -``` -$ ansible -a "/sbin/reboot" -``` - -### Checking host 's system information - -Ansible collects the system's information for all the hosts connected to it. To display the information of hosts, run - -``` -$ ansible -m setup | less -``` - -Secondly, to check a particular info from the collected information by passing an argument, - -``` -$ ansible -m setup -a "filter=ansible_distribution" -``` - -### Transfering files - -For transferring files we use a module 'copy' & complete command that is used is - -``` -$ ansible -m copy -a "src=/home/dan dest=/tmp/home" -``` - -### Manging users - -So to manage the users on the connected hosts, we use a module named 'user' & comamnds to use it are as follows, - -#### Creating a new user - -``` - $ ansible -m user -a "name=testuser password=" -``` - -#### Deleting a user - -``` -$ ansible -m user -a "name=testuser state=absent" -``` - - **Note:-** To create an encrypted password, use the 'mkpasswd -method=sha-512' command. - -### Changing permissions & ownership - -So for changing ownership of files of connected hosts, we use module named 'file' & commands used are - -### Changing permission of a file - -``` -$ ansible -m file -a "dest=/home/dan/file1.txt mode=777" -``` - -### Changing ownership of a file - -``` - $ ansible -m file -a "dest=/home/dan/file1.txt mode=777 owner=dan group=dan" -``` - -### Managing Packages - -So, we can manage the packages installed on all the hosts connected to ansible by using 'yum' & 'apt' modules & the complete commands used are - -#### Check if package is installed & update it - -``` -$ ansible -m yum -a "name=ntp state=latest" -``` - -#### Check if package is installed & don't update it - -``` -$ ansible -m yum -a "name=ntp state=present" -``` - -#### Check if package is at a specific version - -``` -$ ansible -m yum -a "name= ntp-1.8 state=present" -``` - -#### Check if package is not installed - -``` -$ ansible -m yum -a "name=ntp state=absent" -``` - -### Managing services - -So to manage services with ansible, we use a modules 'service' & complete commands that are used are, - -#### Starting a service - -``` -$ansible -m service -a "name=httpd state=started" -``` - -#### Stopping a service - -``` -$ ansible -m service -a "name=httpd state=stopped" -``` - -#### Restarting a service - -``` -$ ansible -m service -a "name=httpd state=restarted" -``` - -So this completes our tutorial of some simple, one line commands that can be used with ansible. Also, for our future tutorials, we will learn to create plays & playbooks that help us manage our hosts more easliy & efficiently. - -If you think we have helped you or just want to support us, please consider these :- - -Connect to us: [Facebook][2] | [Twitter][3] | [Google Plus][4] - -Become a Supporter - [Make a contribution via PayPal][5] - -Linux TechLab is thankful for your continued support. - --------------------------------------------------------------------------------- - -via: http://linuxtechlab.com/ansible-tutorial-simple-commands/ - -作者:[SHUSAIN][a] -译者:[译者ID](https://github.com/译者ID) -校对:[校对者ID](https://github.com/校对者ID) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 - -[a]:http://linuxtechlab.com/author/shsuain/ -[1]:http://linuxtechlab.com/create-first-ansible-server-automation-setup/ -[2]:https://www.facebook.com/linuxtechlab/ -[3]:https://twitter.com/LinuxTechLab -[4]:https://plus.google.com/+linuxtechlab -[5]:http://linuxtechlab.com/contact-us-2/ diff --git a/sources/tech/20170915 How To Install And Setup Vagrant.md b/sources/tech/20170915 How To Install And Setup Vagrant.md deleted file mode 100644 index 1e76600595..0000000000 --- a/sources/tech/20170915 How To Install And Setup Vagrant.md +++ /dev/null @@ -1,265 +0,0 @@ -How To Install And Setup Vagrant -====== -Vagrant is a powerful tool when it comes to virtual machines, here we will look at how to setup and use Vagrant with Virtualbox on Ubuntu to provision reproducible virtual machines. - -## Virtual Machines, not all that complex - -For years, developers have been using virtual machines as part of their workflow, allowing them to swap and change environments that the software is running in, this is generally to prevent conflicts between projects such as project A needing php 5.3 and project b needing php 5.4. - -Also, using Virtual Machines means you only ever need the computer you're working on, you don't need dedicated hardware to mirror the production environment. - -It also comes in handy when multiple developers are working on one project, they can all run an environment which contains all of its requirements, but it can be hard maintaining multiple machines and ensuring all have the same versions of all the requirements, this is where Vagrant comes in. - -### The benefits of using Virtual Machines - - * Your vm is separate from your host environment - * You can have a vm tailor for the requirements of your code - * Anything done in one vm does not effect another VM - * You can run programs in a vm which your host may not be able to run, such as running some windows only software in a - windows vm on top of ubuntu - - - -## What is Vagrant - -In short, it's a tool that works with virtual box to allow you to automate the creation and removal of a virtual machines. - -It revolves around a Config File Called the VagrantFile, which tells vagrant what version of what os you want to install, and some other options such as the IP and Directory Syncing. You can also add a provisioning script of commands to run on the virtual machine. - -By Sharing this VagrantFile around, all developers on a project. You will all be using the exact same virtual machine. - -## Installing the Requirements - -### Install VirtualBox - -VirtualBox is the program which will run the Virtual Machine and is available in the Ubuntu Repos -``` -sudo apt-get install virtualbox -``` - -### Install Vagrant - -For vagrant itself, you need to head to and install the package for your OS. - -### Install Guest Additions - -If you intend to sharing any folders with virtual machine, you need to install the following plugin. -``` -vagrant plugin install vagrant-vbguest -``` - -## Setting Up Vagrant - -### First we need to create an area for vagrant setups. -``` -mkdir ~/Vagrant/test-vm -cd ~/Vagrant/test-vm -``` - -### Create the VagrantFile -``` -vagrant init -``` - -### Start the Virtual Machine -``` -vagrant up -``` - -### Login to the Machine -``` -vagrant-ssh -``` - -By this point you will have the basic vagrant box, and a file called VagrantFile. - -## Customising - -The VagrantFile created in the steps above will look similar to the following - -**VagrantFile** - -``` -# -*- mode: ruby -*- -# vi: set ft=ruby : -# All Vagrant configuration is done below. The "2" in Vagrant.configure -# configures the configuration version (we support older styles for -# backwards compatibility). Please don't change it unless you know what -# you're doing. -Vagrant.configure("2") do |config| - # The most common configuration options are documented and commented below. - # For a complete reference, please see the online documentation at - # https://docs.vagrantup.com. - - # Every Vagrant development environment requires a box. You can search for - # boxes at https://vagrantcloud.com/search. - config.vm.box = "base" - - # Disable automatic box update checking. If you disable this, then - # boxes will only be checked for updates when the user runs - # `vagrant box outdated`. This is not recommended. - # config.vm.box_check_update = false - - # Create a forwarded port mapping which allows access to a specific port - # within the machine from a port on the host machine. In the example below, - # accessing "localhost:8080" will access port 80 on the guest machine. - # NOTE: This will enable public access to the opened port - # config.vm.network "forwarded_port", guest: 80, host: 8080 - - # Create a forwarded port mapping which allows access to a specific port - # within the machine from a port on the host machine and only allow access - # via 127.0.0.1 to disable public access - # config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "127.0.0.1" - - # Create a private network, which allows host-only access to the machine - # using a specific IP. - # config.vm.network "private_network", ip: "192.168.33.10" - - # Create a public network, which generally matched to bridged network. - # Bridged networks make the machine appear as another physical device on - # your network. - # config.vm.network "public_network" - - # Share an additional folder to the guest VM. The first argument is - # the path on the host to the actual folder. The second argument is - # the path on the guest to mount the folder. And the optional third - # argument is a set of non-required options. - # config.vm.synced_folder "../data", "/vagrant_data" - - # Provider-specific configuration so you can fine-tune various - # backing providers for Vagrant. These expose provider-specific options. - # Example for VirtualBox: - # - # config.vm.provider "virtualbox" do |vb| - # # Display the VirtualBox GUI when booting the machine - # vb.gui = true - # - # # Customize the amount of memory on the VM: - # vb.memory = "1024" - # end - # - # View the documentation for the provider you are using for more - # information on available options. - - # Enable provisioning with a shell script. Additional provisioners such as - # Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the - # documentation for more information about their specific syntax and use. - # config.vm.provision "shell", inline: <<-SHELL - # apt-get update - # apt-get install -y apache2 - # SHELL -end -``` - -Now this VagrantFile wll create the basic virtual machine. But the concept behind vagrant is to have the virtual machines set up for our specific tasks. So lets remove the comments and tweak the config. - -**VagrantFile** -``` -# -*- mode: ruby -*- -# vi: set ft=ruby : - -Vagrant.configure("2") do |config| - # Set the Linux Version to Debian Jessie - config.vm.box = "debian/jessie64" - # Set the IP of the Box - config.vm.network "private_network", ip: "192.168.33.10" - # Sync Our Projects Directory with the WWW directory - config.vm.synced_folder "~/Projects", "/var/www/" - # Run the following to Provision - config.vm.provision "shell", path: "install.sh" -end -``` - -Now we have a simple VagrantFile, Which sets the box to debian jessie, sets an IP for us to use, syncs the folders we are interested in, and finally runs an install.sh, which is where our shell commands can go. - -**install.sh** -``` -#! /usr/bin/env bash -# Variables -DBHOST=localhost -DBNAME=dbname -DBUSER=dbuser -DBPASSWD=test123 - -echo "[ Provisioning machine ]" -echo "1) Update APT..." -apt-get -qq update - -echo "1) Install Utilities..." -apt-get install -y tidy pdftk curl xpdf imagemagick openssl vim git - -echo "2) Installing Apache..." -apt-get install -y apache2 - -echo "3) Installing PHP and packages..." -apt-get install -y php5 libapache2-mod-php5 libssh2-php php-pear php5-cli php5-common php5-curl php5-dev php5-gd php5-imagick php5-imap php5-intl php5-mcrypt php5-memcached php5-mysql php5-pspell php5-xdebug php5-xmlrpc -#php5-suhosin-extension, php5-mysqlnd - -echo "4) Installing MySQL..." -debconf-set-selections <<< "mysql-server mysql-server/root_password password secret" -debconf-set-selections <<< "mysql-server mysql-server/root_password_again password secret" -apt-get install -y mysql-server -mysql -uroot -p$DBPASSWD -e "CREATE DATABASE $DBNAME" -mysql -uroot -p$DBPASSWD -e "grant all privileges on $DBNAME.* to '$DBUSER'@'localhost' identified by '$DBPASSWD'" - -echo "5) Generating self signed certificate..." -mkdir -p /etc/ssl/localcerts -openssl req -new -x509 -days 365 -nodes -subj "/C=US/ST=Denial/L=Springfield/O=Dis/CN=www.example.com" -out /etc/ssl/localcerts/apache.pem -keyout /etc/ssl/localcerts/apache.key -chmod 600 /etc/ssl/localcerts/apache* - -echo "6) Setup Apache..." -a2enmod rewrite -> /etc/apache2/sites-enabled/000-default.conf -echo " - - ServerAdmin [[email protected]][1] - DocumentRoot /var/www/ - ErrorLog ${APACHE_LOG_DIR}/error.log - CustomLog ${APACHE_LOG_DIR}/access.log combined - - -" >> /etc/apache2/sites-enabled/000-default.conf -service apache2 restart - -echo "7) Composer Install..." -curl --silent https://getcomposer.org/installer | php -mv composer.phar /usr/local/bin/composer - -echo "8) Install NodeJS..." -curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash - -apt-get -qq update -apt-get -y install nodejs - -echo "9) Install NPM Packages..." -npm install -g gulp gulp-cli - -echo "Provisioning Completed" -``` - -By having the above VagrantFile and Install.sh in your directory, running vagrant up will do the following - - * Create a Virtual Machine Using Debian Jessie - * Set the Machines IP to 192.168.33.10 - * Sync ~/Projects with /var/www/ - * Install and Setup Apache, Mysql, PHP, Git, Vim - * Install and Run Composer - * Install Nodejs and gulp - * Create A MySQL Database - * Create Self Sign Certificates - - - -By sharing the VagrantFile and install.sh with others, you can work on the exact same environment, on two different machines. - - --------------------------------------------------------------------------------- - -via: https://www.chris-shaw.com/blog/how-to-install-and-setup-vagrant - -作者:[Christopher Shaw][a] -译者:[译者ID](https://github.com/译者ID) -校对:[校对者ID](https://github.com/校对者ID) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 - -[a]:https://www.chris-shaw.com -[1]:/cdn-cgi/l/email-protection diff --git a/sources/tech/20170928 How to Use the ZFS Filesystem on Ubuntu Linux.md b/sources/tech/20170928 How to Use the ZFS Filesystem on Ubuntu Linux.md deleted file mode 100644 index 8e0e9df7de..0000000000 --- a/sources/tech/20170928 How to Use the ZFS Filesystem on Ubuntu Linux.md +++ /dev/null @@ -1,131 +0,0 @@ -How to Use the ZFS Filesystem on Ubuntu Linux -====== -There are a myriad of [filesystems available for Linux][1]. So why try a new one? They all work, right? They're not all the same, and some have some very distinct advantages, like ZFS. - -### Why ZFS - -ZFS is awesome. It's a truly modern filesystem with built-in capabilities that make sense for handling loads of data. - -Now, if you're considering ZFS for your ultra-fast NVMe SSD, it might not be the best option. It's slower than others. That's okay, though. It was designed to store huge amounts of data and keep it safe. - -ZFS eliminates the need to set up traditional RAID arrays. Instead, you can create ZFS pools, and even add drives to those pools at any time. ZFS pools behave almost exactly like RAID, but the functionality is built right into the filesystem. - -ZFS also acts like a replacement for LVM, allowing you to partition and manage partitions on the fly without the need to handle things at a lower level and worry about the associated risks. - -It's also a CoW filesystem. Without getting too technical, that means that ZFS protects your data from gradual corruption over time. ZFS creates checksums of files and lets you roll back those files to a previous working version. - -### Installing ZFS - -![Install ZFS on Ubuntu][2] - -Installing ZFS on Ubuntu is very easy, though the process is slightly different for Ubuntu LTS and the latest releases. - - **Ubuntu 16.04 LTS** -``` - sudo apt install zfs -``` - - **Ubuntu 17.04 and Later** -``` - sudo apt install zfsutils -``` - -After you have the utilities installed, you can create ZFS drives and partitions using the tools provided by ZFS. - -### Creating Pools - -![Create ZFS Pool][3] - -Pools are the rough equivalent of RAID in ZFS. They are flexible and can easily be manipulated. - -#### RAID0 - -RAID0 just pools your drives into what behaves like one giant drive. It can increase your drive speeds, but if one of your drives fails, you're probably going to be out of luck. - -To achieve RAID0 with ZFS, just create a plain pool. -``` -sudo zpool create your-pool /dev/sdc /dev/sdd -``` - -#### RAID1/MIRROR - -You can achieve RAID1 functionality with the `mirror` keyword in ZFS. Raid1 creates a 1-to-1 copy of your drive. This means that your data is constantly backed up. It also increases performance. Of course, you use half of your storage to the duplication. -``` -sudo zpool create your-pool mirror /dev/sdc /dev/sdd -``` - -#### RAID5/RAIDZ1 - -ZFS implements RAID5 functionality as RAIDZ1. RAID5 requires drives in multiples of three and allows you to keep 2/3 of your storage space by writing backup parity data to 1/3 of the drive space. If one drive fails, the array will remain online, but the failed drive should be replaced ASAP. -``` -sudo zpool create your-pool raidz1 /dev/sdc /dev/sdd /dev/sde -``` - -#### RAID6/RAIDZ2 - -RAID6 is almost exactly like RAID5, but it works in multiples of four instead of multiples of three. It doubles the parity data to allow up to two drives to fail without bringing the array down. -``` -sudo zpool create your-pool raidz2 /dev/sdc /dev/sdd /dev/sde /dev/sdf -``` - -#### RAID10/Striped Mirror - -RAID10 aims to be the best of both worlds by providing both a speed increase and data redundancy with striping. You need drives in multiples of four and will only have access to half of the space. You can create a pool in RAID10 by creating two mirrors in the same pool command. -``` -sudo zpool create your-pool mirror /dev/sdc /dev/sdd mirror /dev/sde /dev/sdf -``` - -### Working With Pools - -![ZFS pool Status][4] - -There are also some management tools that you have to work with your pools once you've created them. First, check the status of your pools. -``` -sudo zpool status -``` - -#### Updates - -When you update ZFS you'll need to update your pools, too. Your pools will notify you of any updates when you check their status. To update a pool, run the following command. -``` -sudo zpool upgrade your-pool -``` - -You can also upgrade them all. -``` -sudo zpool upgrade -a -``` - -#### Adding Drives - -You can also add drives to your pools at any time. Tell `zpool` the name of the pool and the location of the drive, and it'll take care of everything. -``` -sudo zpool add your-pool /dev/sdx -``` - -### Other Thoughts - -![ZFS in File Browser][5] - -ZFS creates a directory in the root filesystem for your pools. You can browse to them by name using your GUI file manager or the CLI. - -ZFS is awesomely powerful, and there are plenty of other things that you can do with it, too, but these are the basics. It is an excellent filesystem for working with loads of storage, even if it is just a RAID array of hard drives that you use for your files. ZFS works excellently with NAS systems, too. - -Regardless of how stable and robust ZFS is, it's always best to back up your data when you implement something new on your hard drives. - --------------------------------------------------------------------------------- - -via: https://www.maketecheasier.com/use-zfs-filesystem-ubuntu-linux/ - -作者:[Nick Congleton][a] -译者:[译者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/nickcongleton/ -[1]:https://www.maketecheasier.com/best-linux-filesystem-for-ssd/ -[2]:https://www.maketecheasier.com/assets/uploads/2017/09/zfs-install.jpg (Install ZFS on Ubuntu) -[3]:https://www.maketecheasier.com/assets/uploads/2017/09/zfs-create-pool.jpg (Create ZFS Pool) -[4]:https://www.maketecheasier.com/assets/uploads/2017/09/zfs-pool-status.jpg (ZFS pool Status) -[5]:https://www.maketecheasier.com/assets/uploads/2017/09/zfs-pool-open.jpg (ZFS in File Browser) diff --git a/sources/tech/20171101 -dev-[u]random- entropy explained.md b/sources/tech/20171101 -dev-[u]random- entropy explained.md new file mode 100644 index 0000000000..c89ba22465 --- /dev/null +++ b/sources/tech/20171101 -dev-[u]random- entropy explained.md @@ -0,0 +1,108 @@ +/dev/[u]random: entropy explained +====== +### Entropy + +When the topic of /dev/random and /dev/urandom come up, you always hear this word: “Entropy”. Everyone seems to have their own analogy for it. So why not me? I like to think of Entropy as “Random juice”. It is juice, required for random to be more random. + +If you have ever generated an SSL certificate, or a GPG key, you may have seen something like: +``` +We need to generate a lot of random bytes. It is a good idea to perform +some other action (type on the keyboard, move the mouse, utilize the +disks) during the prime generation; this gives the random number +generator a better chance to gain enough entropy. +++++++++++..+++++.+++++++++++++++.++++++++++...+++++++++++++++...++++++ ++++++++++++++++++++++++++++++.+++++..+++++.+++++.+++++++++++++++++++++++++>. +++++++++++>+++++...........................................................+++++ +Not enough random bytes available. Please do some other work to give +the OS a chance to collect more entropy! (Need 290 more bytes) + +``` + + +By typing on the keyboard, and moving the mouse, you help generate Entropy, or Random Juice. + +You might be asking yourself… Why do I need Entropy? and why it is so important for random to be actually random? Well, lets say our Entropy was limited to keyboard, mouse, and disk IO. But our system is a server, so I know there is no mouse and keyboard input. This means the only factor is your IO. If it is a single disk, that was barely used, you will have low Entropy. This means your systems ability to be random is weak. In other words, I could play the probability game, and significantly decrease the amount of time it would take to crack things like your ssh keys, or decrypt what you thought was an encrypted session. + +Okay, but that is pretty unrealistic right? No, actually it isn’t. Take a look at this [Debian OpenSSH Vulnerability][1]. This particular issue was caused by someone removing some of the code responsible for adding Entropy. Rumor has it they removed it because it was causing valgrind to throw warnings. However, in doing that, random is now MUCH less random. In fact, so much less that Brute forcing the private ssh keys generated is now a fesible attack vector. + +Hopefully by now we understand how important Entropy is to security. Whether you realize you are using it or not. + +### /dev/random & /dev/urandom + + +/dev/urandom is a Psuedo Random Number Generator, and it **does not** block if you run out of Entropy. +/dev/random is a True Random Number Generator, and it **does** block if you run out of Entropy. + +Most often, if we are dealing with something pragmatic, and it doesn’t contain the keys to your nukes, /dev/urandom is the right choice. Otherwise if you go with /dev/random, then when the system runs out of Entropy your application is just going to behave funny. Whether it outright fails, or just hangs until it has enough depends on how you wrote your application. + +### Checking the Entropy + +So, how much Entropy do you have? +``` +[root@testbox test]# cat /proc/sys/kernel/random/poolsize +4096 +[root@testbox test]# cat /proc/sys/kernel/random/entropy_avail +2975 +[root@testbox test]# + +``` + +/proc/sys/kernel/random/poolsize, to state the obvious is the size(in bits) of the Entropy Pool. eg: How much random-juice we should save before we stop pumping more. /proc/sys/kernel/random/entropy_avail, is the amount(in bits) of random-juice in the pool currently. + +### How can we influence this number? + +The number is drained as we use it. The most crude example I can come up with is catting /dev/random into /dev/null: +``` +[root@testbox test]# cat /dev/random > /dev/null & +[1] 19058 +[root@testbox test]# cat /proc/sys/kernel/random/entropy_avail +0 +[root@testbox test]# cat /proc/sys/kernel/random/entropy_avail +1 +[root@testbox test]# + +``` + +The easiest way to influence this is to run [Haveged][2]. Haveged is a daemon that uses the processor “flutter” to add Entropy to the systems Entropy Pool. Installation and basic setup is pretty straight forward +``` +[root@b08s02ur ~]# systemctl enable haveged +Created symlink from /etc/systemd/system/multi-user.target.wants/haveged.service to /usr/lib/systemd/system/haveged.service. +[root@b08s02ur ~]# systemctl start haveged +[root@b08s02ur ~]# + +``` + +On a machine with relatively moderate traffic: +``` +[root@testbox ~]# pv /dev/random > /dev/null + 40 B 0:00:15 [ 0 B/s] [ <=> ] + 52 B 0:00:23 [ 0 B/s] [ <=> ] + 58 B 0:00:25 [5.92 B/s] [ <=> ] + 64 B 0:00:30 [6.03 B/s] [ <=> ] +^C +[root@testbox ~]# systemctl start haveged +[root@testbox ~]# pv /dev/random > /dev/null +7.12MiB 0:00:05 [1.43MiB/s] [ <=> ] +15.7MiB 0:00:11 [1.44MiB/s] [ <=> ] +27.2MiB 0:00:19 [1.46MiB/s] [ <=> ] + 43MiB 0:00:30 [1.47MiB/s] [ <=> ] +^C +[root@testbox ~]# + +``` + +Using pv we are able to see how much data we are passing via pipe. As you can see, before haveged, we were getting 2.1 bits per second(B/s). Whereas after starting haveged, and adding processor flutter to our Entropy pool we get ~1.5MiB/sec. + +-------------------------------------------------------------------------------- + +via: http://jhurani.com/linux/2017/11/01/entropy-explained.html + +作者:[James J][a] +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://jblevins.org/log/ssh-vulnkey +[1]:http://jhurani.com/linux/2017/11/01/%22https://jblevins.org/log/ssh-vulnkey%22 +[2]:http://www.issihosts.com/haveged/ diff --git a/sources/tech/20171103 How To Fully Update And Upgrade Offline Debian-based Systems.md b/sources/tech/20171103 How To Fully Update And Upgrade Offline Debian-based Systems.md deleted file mode 100644 index a0fb133043..0000000000 --- a/sources/tech/20171103 How To Fully Update And Upgrade Offline Debian-based Systems.md +++ /dev/null @@ -1,125 +0,0 @@ -How To Fully Update And Upgrade Offline Debian-based Systems -====== -![](https://www.ostechnix.com/wp-content/uploads/2017/11/Upgrade-Offline-Debian-based-Systems-2-720x340.png) - -A while ago we have shown you how to install softwares in any[ **offline Ubuntu**][1] system and any [**offline Arch Linux**][2] system. Today, we will see how to fully update and upgrade offline Debian-based systems. Unlike the previous methods, we do not update/upgrade a single package, but the whole system. This method can be helpful where you don't have an active Internet connection or slow Internet speed. - -### Fully Update And Upgrade Offline Debian-based Systems - -Let us say, you have a system (Windows or Linux) with high-speed Internet connection at work and a Debian or any Debian derived systems with no internet connection or very slow Internet connection(like dial-up) at home. You want to upgrade your offline home system. What would you do? Buy a high speed Internet connection? Not necessary! You still can update or upgrade your offline system with Internet. This is where **Apt-Offline** comes in help. - -As the name says, apt-offline is an Offline APT Package Manager for APT based systems like Debian and Debian derived distributions such as Ubuntu, Linux Mint. Using apt-offline, we can fully update/upgrade our Debian box without the need of connecting it to the Internet. It is cross-platform tool written in the Python Programming Language and has both CLI and graphical interfaces. - -#### Requirements - - * An Internet connected system (Windows or Linux). We call it online system for the sake of easy understanding throughout this guide. - * An Offline system (Debian and Debian derived system). We call it offline system. - * USB drive or External Hard drive with sufficient space to carry all updated packages. - - - -#### Installation - -Apt-Offline is available in the default repositories of Debian and derivatives. If your Online system is running with Debian, Ubuntu, Linux Mint, and other DEB based systems, you can install Apt-Offline using command: -``` -sudo apt-get install apt-offline -``` - -If your Online runs with any other distro than Debian, git clone Apt-Offline repository: -``` -git clone https://github.com/rickysarraf/apt-offline.git -``` - -Go the directory and run it from there. -``` -cd apt-offline/ -``` -``` -sudo ./apt-offline -``` - -#### Steps to do in Offline system (Non-Internet connected system) - -Go to your offline system and create a directory where you want to store the signature file: -``` -mkdir ~/tmp -``` -``` -cd ~/tmp/ -``` - -You can use any directory of your choice. Then, run the following command to generate the signature file: -``` -sudo apt-offline set apt-offline.sig -``` - -Sample output would be: -``` -Generating database of files that are needed for an update. - -Generating database of file that are needed for operation upgrade -``` - -By default, apt-offline will generate database of files that are needed to be update and upgrade. You can use **--` update`** or `**--upgrade** options to create database for either one of these.` - -Copy the entire **tmp** folder in an USB drive or external drive and go to your online system (Internet-enabled system). - -#### Steps to do in Online system - -Plug in your USB drive and go to the temp directory: -``` -cd tmp/ -``` - -Then, run the following command: -``` -sudo apt-offline get apt-offline.sig --threads 5 --bundle apt-offline-bundle.zip -``` - -Here, "-threads 5" represents the number of APT repositories. You can increase the number if you want to download packages from more repositories. And, "-bundle apt-offline-bundle.zip" option represents all packages will be bundled in a single archive file called **apt-offline-bundle.zip**. This archive file will be saved in your current working directory. - -The above command will download data based on the signature file generated earlier in the offline system. - -[![][3]][4] - -This will take several minutes depending upon the Internet connection speed. Please note that apt-offline is cross platform, so you can use it to download packages on any OS. - -Once completed, copy the **tmp** folder to USB or External drive and return back to the offline system. Make sure your USB device has enough free space to keep all downloaded files, because all packages are available in the tmp folder now. - -#### Steps to do in offline system - -Plug in the device in your offline system and go to the **tmp** directory where you have downloaded all packages earlier. -``` -cd tmp -``` - -Then, run the following command to install all download packages. -``` -sudo apt-offline install apt-offline-bundle.zip -``` - -This will update the APT database, so APT will find all required packages in the APT cache. - -**Note:** If both online and offline systems are in the same local network, you can transfer the **tmp** folder to the offline system using "scp" or any other file transfer applications. If both systems are in different places, copy the folder using USB devices. - -And, that's all for now folks. I hope this guide will useful for you. More good stuffs to come. Stay tuned! - -Cheers! - - - --------------------------------------------------------------------------------- - -via: https://www.ostechnix.com/fully-update-upgrade-offline-debian-based-systems/ - -作者:[SK][a] -译者:[译者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-softwares-offline-ubuntu-16-04/ -[2]:https://www.ostechnix.com/install-packages-offline-arch-linux/ -[3]:data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7 -[4]:http://www.ostechnix.com/wp-content/uploads/2017/11/apt-offline.png () diff --git a/sources/tech/20171203 3 Essential Questions to Ask at Your Next Tech Interview.md b/sources/tech/20171203 3 Essential Questions to Ask at Your Next Tech Interview.md deleted file mode 100644 index 891ef48948..0000000000 --- a/sources/tech/20171203 3 Essential Questions to Ask at Your Next Tech Interview.md +++ /dev/null @@ -1,47 +0,0 @@ -3 Essential Questions to Ask at Your Next Tech Interview -====== -![](https://www.linux.com/sites/lcom/files/styles/rendered_file/public/os-jobs_0.jpg?itok=nDf5j7xC) - -Interviewing can be stressful, but 58 percent of companies tell Dice and the Linux Foundation that they need to hire open source talent in the months ahead. Learn how to ask the right questions. - -The Linux Foundation - -The annual [Open Source Jobs Report][1] from Dice and The Linux Foundation reveals a lot about prospects for open source professionals and hiring activity in the year ahead. In this year's report, 86 percent of tech professionals said that knowing open source has advanced their careers. Yet what happens with all that experience when it comes time for advancing within their own organization or applying for a new roles elsewhere? - -Interviewing for a new job is never easy. Aside from the complexities of juggling your current work while preparing for a new role, there's the added pressure of coming up with the necessary response when the interviewer asks "Do you have any questions for me?" - -At Dice, we're in the business of careers, advice, and connecting tech professionals with employers. But we also hire tech talent at our organization to work on open source projects. In fact, the Dice platform is based on a number of Linux distributions and we leverage open source databases as the basis for our search functionality. In short, we couldn't run Dice without open source software, therefore it's vital that we hire professionals who understand, and love, open source. - -Over the years, I've learned the importance of asking good questions during an interview. It's an opportunity to learn about your potential new employer, as well as better understand if they are a good match for your skills. - -Here are three essential questions to ask and the reason they're important: - -**1\. What is the company 's position on employees contributing to open source projects or writing code in their spare time?** - -The answer to this question will tell you a lot about the company you're interviewing with. In general, companies will want tech pros who contribute to websites or projects as long as they don't conflict with the work you're doing at that firm. Allowing this outside the company also fosters an entrepreneurial spirt among the tech organization, and teaches tech skills that you may not otherwise get in the normal course of your day. - -**2\. How are projects prioritized here?** - -As all companies have become tech companies, there is often a division between innovative customer facing tech projects versus those that improve the platform itself. Will you be working on keeping the existing platform up to date? Or working on new products for the public? Depending on where your interests lie, the answer could determine if the company is a right fit for you. - -**3\. Who primarily makes decisions on new products and how much input do developers have in the decision-making process?** - -This question is one part understanding who is responsible for innovation at the company (and how close you'll be working with him/her) and one part discovering your career path at the firm. A good company will talk to its developers and open source talent ahead of developing new products. It seems like a no brainer, but it's a step that's sometimes missed and will mean the difference between a collaborative environment or chaotic process ahead of new product releases. - -Interviewing can be stressful, however as 58 percent of companies tell Dice and The Linux Foundation that they need to hire open source talent in the months ahead, it's important to remember the heightened demand puts professionals like you in the driver's seat. Steer your career in the direction you desire. - -[Download ][2] the full 2017 Open Source Jobs Report now. - --------------------------------------------------------------------------------- - -via: https://www.linux.com/blog/os-jobs/2017/12/3-essential-questions-ask-your-next-tech-interview - -作者:[Brian Hostetter][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/brianhostetter -[1]:https://www.linuxfoundation.org/blog/2017-jobs-report-highlights-demand-open-source-skills/ -[2]:http://bit.ly/2017OSSjobsreport diff --git a/sources/tech/20171204 Tutorial on how to write basic udev rules in Linux.md b/sources/tech/20171204 Tutorial on how to write basic udev rules in Linux.md deleted file mode 100644 index e4f3d6f537..0000000000 --- a/sources/tech/20171204 Tutorial on how to write basic udev rules in Linux.md +++ /dev/null @@ -1,210 +0,0 @@ -# Tutorial on how to write basic udev rules in Linux - -Contents - -* * [1. Objective][4] - - * [2. Requirements][5] - - * [3. Difficulty][6] - - * [4. Conventions][7] - - * [5. Introduction][8] - - * [6. How rules are organized][9] - - * [7. The rules syntax][10] - - * [8. A test case][11] - - * [9. Operators][12] - * * [9.1.1. == and != operators][1] - - * [9.1.2. The assignment operators: = and :=][2] - - * [9.1.3. The += and -= operators][3] - - * [10. The keys we used][13] - -### Objective - -Understanding the base concepts behind udev, and learn how to write simple rules - -### Requirements - -* Root permissions - -### Difficulty - -MEDIUM - -### Conventions - -* **#** - requires given command to be executed with root privileges either directly as a root user or by use of `sudo` command - -* **$** - given command to be executed as a regular non-privileged user - -### Introduction - -In a GNU/Linux system, while devices low level support is handled at the kernel level, the management of events related to them is managed in userspace by `udev`, and more precisely by the `udevd` daemon. Learning how to write rules to be applied on the occurring of those events can be really useful to modify the behavior of the system and adapt it to our needs. - -### How rules are organized - -Udev rules are defined into files with the `.rules` extension. There are two main locations in which those files can be placed: `/usr/lib/udev/rules.d` it's the directory used for system-installed rules, `/etc/udev/rules.d/`is reserved for custom made rules.  - -The files in which the rules are defined are conventionally named with a number as prefix (e.g `50-udev-default.rules`) and are processed in lexical order independently of the directory they are in. Files installed in `/etc/udev/rules.d`, however, override those with the same name installed in the system default path. - -### The rules syntax - -The syntax of udev rules is not very complicated once you understand the logic behind it. A rule is composed by two main sections: the "match" part, in which we define the conditions for the rule to be applied, using a series of keys separated by a comma, and the "action" part, in which we perform some kind of action, when the conditions are met.  - -### A test case - -What a better way to explain possible options than to configure an actual rule? As an example, we are going to define a rule to disable the touchpad when a mouse is connected. Obviously the attributes provided in the rule definition, will reflect my hardware.  - -We will write our rule in the `/etc/udev/rules.d/99-togglemouse.rules` file with the help of our favorite text editor. A rule definition can span over multiple lines, but if that's the case, a backslash must be used before the newline character, as a line continuation, just as in shell scripts. Here is our rule: -``` -ACTION=="add" \ -, ATTRS{idProduct}=="c52f" \ -, ATTRS{idVendor}=="046d" \ -, ENV{DISPLAY}=":0" \ -, ENV{XAUTHORITY}="/run/user/1000/gdm/Xauthority" \ -, RUN+="/usr/bin/xinput --disable 16" -``` -Let's analyze it. - -### Operators - -First of all, an explanation of the used and possible operators: - -#### == and != operators - -The `==` is the equality operator and the `!=` is the inequality operator. By using them we establish that for the rule to be applied the defined keys must match, or not match the defined value respectively. - -#### The assignment operators: = and := - -The `=` assignment operator, is used to assign a value to the keys that accepts one. We use the `:=` operator, instead, when we want to assign a value and we want to make sure that it is not overridden by other rules: the values assigned with this operator, in facts, cannot be altered. - -#### The += and -= operators - -The `+=` and `-=` operators are used respectively to add or to remove a value from the list of values defined for a specific key. - -### The keys we used - -Let's now analyze the keys we used in the rule. First of all we have the `ACTION` key: by using it, we specified that our rule is to be applied when a specific event happens for the device. Valid values are `add`, `remove` and `change`  - -We then used the `ATTRS` keyword to specify an attribute to be matched. We can list a device attributes by using the `udevadm info` command, providing its name or `sysfs` path: -``` -udevadm info -ap /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.2/2-1.2:1.1/0003:046D:C52F.0010/input/input39 - -Udevadm info starts with the device specified by the devpath and then -walks up the chain of parent devices. It prints for every device -found, all possible attributes in the udev rules key format. -A rule to match, can be composed by the attributes of the device -and the attributes from one single parent device. - - looking at device '/devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.2/2-1.2:1.1/0003:046D:C52F.0010/input/input39': - KERNEL=="input39" - SUBSYSTEM=="input" - DRIVER=="" - ATTR{name}=="Logitech USB Receiver" - ATTR{phys}=="usb-0000:00:1d.0-1.2/input1" - ATTR{properties}=="0" - ATTR{uniq}=="" - - looking at parent device '/devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.2/2-1.2:1.1/0003:046D:C52F.0010': - KERNELS=="0003:046D:C52F.0010" - SUBSYSTEMS=="hid" - DRIVERS=="hid-generic" - ATTRS{country}=="00" - - looking at parent device '/devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.2/2-1.2:1.1': - KERNELS=="2-1.2:1.1" - SUBSYSTEMS=="usb" - DRIVERS=="usbhid" - ATTRS{authorized}=="1" - ATTRS{bAlternateSetting}==" 0" - ATTRS{bInterfaceClass}=="03" - ATTRS{bInterfaceNumber}=="01" - ATTRS{bInterfaceProtocol}=="00" - ATTRS{bInterfaceSubClass}=="00" - ATTRS{bNumEndpoints}=="01" - ATTRS{supports_autosuspend}=="1" - - looking at parent device '/devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.2': - KERNELS=="2-1.2" - SUBSYSTEMS=="usb" - DRIVERS=="usb" - ATTRS{authorized}=="1" - ATTRS{avoid_reset_quirk}=="0" - ATTRS{bConfigurationValue}=="1" - ATTRS{bDeviceClass}=="00" - ATTRS{bDeviceProtocol}=="00" - ATTRS{bDeviceSubClass}=="00" - ATTRS{bMaxPacketSize0}=="8" - ATTRS{bMaxPower}=="98mA" - ATTRS{bNumConfigurations}=="1" - ATTRS{bNumInterfaces}==" 2" - ATTRS{bcdDevice}=="3000" - ATTRS{bmAttributes}=="a0" - ATTRS{busnum}=="2" - ATTRS{configuration}=="RQR30.00_B0009" - ATTRS{devnum}=="12" - ATTRS{devpath}=="1.2" - ATTRS{idProduct}=="c52f" - ATTRS{idVendor}=="046d" - ATTRS{ltm_capable}=="no" - ATTRS{manufacturer}=="Logitech" - ATTRS{maxchild}=="0" - ATTRS{product}=="USB Receiver" - ATTRS{quirks}=="0x0" - ATTRS{removable}=="removable" - ATTRS{speed}=="12" - ATTRS{urbnum}=="1401" - ATTRS{version}==" 2.00" - - [...] -``` -Above is the truncated output received after running the command. As you can read it from the output itself, `udevadm` starts with the specified path that we provided, and gives us information about all the parent devices. Notice that attributes of the device are reported in singular form (e.g `KERNEL`), while the parent ones in plural form (e.g `KERNELS`). The parent information can be part of a rule but only one of the parents can be referenced at a time: mixing attributes of different parent devices will not work. In the rule we defined above, we used the attributes of one parent device: `idProduct` and `idVendor`.  - -The next thing we have done in our rule, is to use the `ENV` keyword: it can be used to both set or try to match environment variables. We assigned a value to the `DISPLAY` and `XAUTHORITY` ones. Those variables are essential when interacting with the X server programmatically, to setup some needed information: with the `DISPLAY` variable, we specify on what machine the server is running, what display and what screen we are referencing, and with `XAUTHORITY` we provide the path to the file which contains Xorg authentication and authorization information. This file is usually located in the users "home" directory.  - -Finally we used the `RUN` keyword: this is used to run external programs. Very important: this is not executed immediately, but the various actions are executed once all the rules have been parsed. In this case we used the `xinput` utility to change the status of the touchpad. I will not explain the syntax of xinput here, it would be out of context, just notice that `16` is the id of the touchpad.  - -Once our rule is set, we can debug it by using the `udevadm test` command. This is useful for debugging but it doesn't really run commands specified using the `RUN` key: -``` -$ udevadm test --action="add" /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.2/2-1.2:1.1/0003:046D:C52F.0010/input/input39 -``` -What we provided to the command is the action to simulate, using the `--action` option, and the sysfs path of the device. If no errors are reported, our rule should be good to go. To run it in the real world, we must reload the rules: -``` -# udevadm control --reload -``` -This command will reload the rules files, however, will have effect only on new generated events.  - -We have seen the basic concepts and logic used to create an udev rule, however we only scratched the surface of the many options and possible settings. The udev manpage provides an exhaustive list: please refer to it for a more in-depth knowledge. - --------------------------------------------------------------------------------- - -via: https://linuxconfig.org/tutorial-on-how-to-write-basic-udev-rules-in-linux - -作者:[Egidio Docile ][a] -译者:[译者ID](https://github.com/译者ID) -校对:[校对者ID](https://github.com/校对者ID) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 - -[a]:https://disqus.com/by/egidiodocile/ -[1]:https://linuxconfig.org/tutorial-on-how-to-write-basic-udev-rules-in-linux#h9-1-1-and-operators -[2]:https://linuxconfig.org/tutorial-on-how-to-write-basic-udev-rules-in-linux#h9-1-2-the-assignment-operators-and -[3]:https://linuxconfig.org/tutorial-on-how-to-write-basic-udev-rules-in-linux#h9-1-3-the-and-operators -[4]:https://linuxconfig.org/tutorial-on-how-to-write-basic-udev-rules-in-linux#h1-objective -[5]:https://linuxconfig.org/tutorial-on-how-to-write-basic-udev-rules-in-linux#h2-requirements -[6]:https://linuxconfig.org/tutorial-on-how-to-write-basic-udev-rules-in-linux#h3-difficulty -[7]:https://linuxconfig.org/tutorial-on-how-to-write-basic-udev-rules-in-linux#h4-conventions -[8]:https://linuxconfig.org/tutorial-on-how-to-write-basic-udev-rules-in-linux#h5-introduction -[9]:https://linuxconfig.org/tutorial-on-how-to-write-basic-udev-rules-in-linux#h6-how-rules-are-organized -[10]:https://linuxconfig.org/tutorial-on-how-to-write-basic-udev-rules-in-linux#h7-the-rules-syntax -[11]:https://linuxconfig.org/tutorial-on-how-to-write-basic-udev-rules-in-linux#h8-a-test-case -[12]:https://linuxconfig.org/tutorial-on-how-to-write-basic-udev-rules-in-linux#h9-operators -[13]:https://linuxconfig.org/tutorial-on-how-to-write-basic-udev-rules-in-linux#h10-the-keys-we-used diff --git a/sources/tech/20171211 A tour of containerd 1.0.md b/sources/tech/20171211 A tour of containerd 1.0.md deleted file mode 100644 index 4cf3e2b587..0000000000 --- a/sources/tech/20171211 A tour of containerd 1.0.md +++ /dev/null @@ -1,48 +0,0 @@ -A tour of containerd 1.0 -====== -![containerd][1] - -We have done a few talks in the past on different features of containerd, how it was designed, and some of the problems that we have fixed along the way. Containerd is used by Docker, Kubernetes CRI, and a few other projects but this is a post for people who may not know what containerd actually does within these platforms. I would like to do more posts on the feature set and design of containerd in the future but for now, we will start with the basics. - -I think the container ecosystem can be confusing at times. Especially with the terminology that we use. Whats this? A runtime. And this? A runtime… containerd (pronounced " _container-dee "_) as the name implies, not contain nerd as some would like to troll me with, is a container daemon. It was originally built as an integration point for OCI runtimes like runc but over the past six months it has added a lot of functionality to bring it up to par with the needs of modern container platforms like Docker and orchestration systems like Kubernetes. - -So what do you actually get using containerd? You get push and pull functionality as well as image management. You get container lifecycle APIs to create, execute, and manage containers and their tasks. An entire API dedicated to snapshot management and an openly governed project to depend on. Basically everything that you need to build a container platform without having to deal with the underlying OS details. I think the most important part of containerd is having a versioned and stable API that will have bug fixes and security patches backported. - -![containerd][2] - -Since there is no such thing as Linux containers in the kernel, containers are various kernel features tied together, when you are building a large platform or distributed system you want an abstraction layer between your management code and the syscalls and duct tape of features to run a container. That is where containerd lives. It provides a client a layer of stable types that platforms can build on top of without ever having to drop down to the kernel level. It's so much nicer to work with Container, Task, and Snapshot types than it is to manage calls to clone() or mount(). Balanced with the flexibility to directly interact with the runtime or host-machine, these objects avoid the sacrifice of capabilities that typically come with higher-level abstractions. The result is that easy tasks are simple to complete and hard tasks are possible. - -![containerd][3]Containerd was designed to be used by Docker and Kubernetes as well as any other container system that wants to abstract away syscalls or OS specific functionality to run containers on Linux, Windows, Solaris, or other Operating Systems. With these users in mind, we wanted to make sure that containerd has only what they need and nothing that they don't. Realistically this is impossible but at least that is what we try for. While networking is out of scope for containerd, what it doesn't do lets higher level systems have full control. The reason for this is, when you are building a distributed system, networking is a very central aspect. With SDN and service discovery today, networking is way more platform specific than abstracting away netlink calls on linux. Most of the new overlay networks are route based and require routing tables to be updated each time a new container is created or deleted. Service discovery, DNS, etc all have to be notified of these changes as well. It would be a large chunk of code to be able to support all the different network interfaces, hooks, and integration points to support this if we added networking to containerd. What we did instead is opted for a robust events system inside containerd so that multiple consumers can subscribe to the events that they care about. We also expose a [Task API ][4]that lets users create a running task, have the ability to add interfaces to the network namespace of the container, and then start the container's process without the need for complex hooks in various points of a container's lifecycle. - -Another area that has been added to containerd over the past few months is a complete storage and distribution system that supports both OCI and Docker image formats. You have a complete content addressed storage system across the containerd API that works not only for images but also metadata, checkpoints, and arbitrary data attached to containers. - -We also took the time to [rethink how "graphdrivers" work][5]. These are the overlay or block level filesystems that allow images to have layers and you to perform efficient builds. Graphdrivers were initially written by Solomon and I when we added support for devicemapper. Docker only supported AUFS at the time so we modeled the graphdrivers after the overlay filesystem. However, making a block level filesystem such as devicemapper/lvm act like an overlay filesystem proved to be much harder to do in the long run. The interfaces had to expand over time to support different features than what we originally thought would be needed. With containerd, we took a different approach, make overlay filesystems act like a snapshotter instead of vice versa. This was much easier to do as overlay filesystems provide much more flexibility than snapshotting filesystems like BTRFS, ZFS, and devicemapper as they don't have a strict parent/child relationship. This helped us build out [a smaller interface for the snapshotters][6] while still fulfilling the requirements needed from things [like a builder][7] as well as reduce the amount of code needed, making it much easier to maintain in the long run. - -![][8] - -You can find more details about the architecture of containerd in [Stephen Day's Dec 7th 2017 KubeCon SIG Node presentation][9]. - -In addition to the technical and design changes in the 1.0 codebase, we also switched the containerd [governance model from the long standing BDFL to a Technical Steering Committee][10] giving the community an independent third party resource to rely on. - - --------------------------------------------------------------------------------- - -via: https://blog.docker.com/2017/12/containerd-ga-features-2/ - -作者:[Michael Crosby][a] -译者:[译者ID](https://github.com/译者ID) -校对:[校对者ID](https://github.com/校对者ID) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 - -[a]:https://blog.docker.com/author/michael/ -[1]:https://i0.wp.com/blog.docker.com/wp-content/uploads/950cf948-7c08-4df6-afd9-cc9bc417cabe-6.jpg?resize=400%2C120&ssl=1 -[2]:https://i1.wp.com/blog.docker.com/wp-content/uploads/4a7666e4-ebdb-4a40-b61a-26ac7c3f663e-4.jpg?resize=906%2C470&ssl=1 (containerd) -[3]:https://i1.wp.com/blog.docker.com/wp-content/uploads/2a73a4d8-cd40-4187-851f-6104ae3c12ba-1.jpg?resize=1140%2C680&ssl=1 -[4]:https://github.com/containerd/containerd/blob/master/api/services/tasks/v1/tasks.proto -[5]:https://blog.mobyproject.org/where-are-containerds-graph-drivers-145fc9b7255 -[6]:https://github.com/containerd/containerd/blob/master/api/services/snapshots/v1/snapshots.proto -[7]:https://blog.mobyproject.org/introducing-buildkit-17e056cc5317 -[8]:https://i1.wp.com/blog.docker.com/wp-content/uploads/d0fb5eb9-c561-415d-8d57-e74442a879a2-1.jpg?resize=1140%2C556&ssl=1 -[9]:https://speakerdeck.com/stevvooe/whats-happening-with-containerd-and-the-cri -[10]:https://github.com/containerd/containerd/pull/1748 diff --git a/sources/tech/20171218 Internet Chemotherapy.md b/sources/tech/20171218 Internet Chemotherapy.md deleted file mode 100644 index 2d2b950db5..0000000000 --- a/sources/tech/20171218 Internet Chemotherapy.md +++ /dev/null @@ -1,336 +0,0 @@ -(yixunx translating) -Internet Chemotherapy -====== - -12/10 2017 - -### 1. Internet Chemotherapy - -Internet Chemotherapy was a 13 month project between Nov 2016 - Dec 2017. -It has been known under names such as 'BrickerBot', 'bad firmware -upgrade', 'ransomware', 'large-scale network failure' and even -'unprecedented terrorist actions.' That last one was a little harsh, -Fernandez, but I guess I can't please everybody. - -You can download the module which executes the http and telnet-based -payloads from this router at http://91.215.104.140/mod_plaintext.py. Due to -platform limitations the module is obfuscated single threaded python, but -the payloads are in plain view and should be easy to figure out for any -programmer worth his/her/hir salt. Take a look at the number of payloads, -0-days and techniques and let the reality sink in for a moment. Then -imagine what would've happened to the Internet in 2017 if I had been a -blackhat dedicated to building a massive DDoS cannon for blackmailing the -biggest providers and companies. I could've disrupted them all and caused -extraordinary damage to the Internet in the process. - -My ssh crawler is too dangerous to publish. It contains various levels of -automation for the purpose of moving laterally through poorly designed -ISP networks and taking them over through only a single breached router. -My ability to commandeer and secure hundreds of thousands of ISP routers -was the foundation of my anti-IoT botnet project as it gave me great -visibility of what was happening on the Internet and it gave me an -endless supply of nodes for hacking back. I began my non-destructive ISP -network cleanup project in 2015 and by the time Mirai came around I was -in a good position to react. The decision to willfully sabotage other -people's equipment was nonetheless a difficult one to make, but the -colossally dangerous CVE-2016-10372 situation ultimately left me with no -other choice. From that moment on I was all-in. - -I am now here to warn you that what I've done was only a temporary band- -aid and it's not going to be enough to save the Internet in the future. -The bad guys are getting more sophisticated, the number of potentially -vulnerable devices keep increasing, and it's only a matter of time before -a large scale Internet-disrupting event will occur. If you are willing to -believe that I've disabled over 10 million vulnerable devices over the 13- -month span of the project then it's not far-fetched to say that such a -destructive event could've already happened in 2017. - -YOU SHOULD WAKE UP TO THE FACT THAT THE INTERNET IS ONLY ONE OR TWO -SERIOUS IOT EXPLOITS AWAY FROM BEING SEVERELY DISRUPTED. The damage of -such an event is immeasurable given how digitally connected our societies -have become, yet CERTs, ISPs and governments are not taking the gravity -of the situation seriously enough. ISPs keep deploying devices with -exposed control ports and although these are trivially found using -services like Shodan the national CERTs don't seem to care. A lot of -countries don't even have CERTs. Many of the world's biggest ISPs do not -have any actual security know-how in-house, and are instead relying on -foreign vendors for help in case anything goes wrong. I've watched large -ISPs withering for months under conditioning from my botnet without them -being able to fully mitigate the vulnerabilities (good examples are BSNL, -Telkom ZA, PLDT, from time to time PT Telkom, and pretty much most large -ISPs south of the border). Just look at how slow and ineffective Telkom -ZA was in dealing with its Aztech modem problem and you will begin to -understand the hopelessness of the current situation. In 99% of the -problem cases the solution would have simply been for the ISPs to deploy -sane ACLs and CPE segmentation, yet months later their technical staff -still hasn't figured this out. If ISPs are unable to mitigate weeks and -months of continuous deliberate sabotage of their equipment then what -hope is there that they would notice and fix a Mirai problem on their -networks? Many of the world's biggest ISPs are catastrophically negligent -and this is the biggest danger by a landslide, yet paradoxically it -should also be the easiest problem to fix. - -I've done my part to try to buy the Internet some time, but I've gone as -far as I can. Now it's up to you. Even small actions are important. Among -the things you can do are: - -* Review your own ISP's security through services such as Shodan and take - them to task over exposed telnet, http, httpd, ssh, tr069 etc. ports on - their networks. Refer them to this document if you have to. There's no - good reason why any of these control ports should ever be accessible - from the outside world. Exposing control ports is an amateur mistake. - If enough customers complain they might actually do something about it! - -* Vote with your wallet! Refuse to buy or use 'intelligent' products - unless the manufacturer can prove that the product can and will receive - timely security updates. Find out about the vendor's security track - record before giving them your hard-earned money. Be willing to pay a - little bit more for credible security. - -* Lobby your local politicians and government officials for improved - security legislation for IoT (Internet of Things) devices such as - routers, IP cameras and 'intelligent' devices. Private or public - companies currently lack the incentives for solving this problem in the - immediate term. This matter is as important as minimum safety - requirements for cars and general electrical appliances. - -* Consider volunteering your time or other resources to underappreciated - whitehat organizations such as GDI Foundation or Shadowserver - Foundation. These organizations and people make a big difference and - they can significantly amplify the impact of your skillset in helping - the Internet. - -* Last but not least, consider the long-shot potential of getting IoT - devices designated as an 'attractive nuisance' through precedent- - setting legal action. If a home owner can be held liable for a - burglar/trespasser getting injured then I don't see why a device owner - (or ISP or manufacturer) shouldn't be held liable for the damage that - was caused by their dangerous devices being exploitable through the - Internet. Attribution won't be a problem for Layer 7 attacks. If any - large ISPs with deep pockets aren't willing to fund such precedent - cases (and they might not since they fear that such precedents could - come back to haunt them) we could even crowdfund such initiatives over - here and in the EU. ISPs: consider your volumetric DDoS bandwidth cost - savings in 2017 as my indirect funding of this cause and as evidence - for its potential upside. - -### 2. Timeline - -Here are some of the more memorable events of the project: - -* Deutsche Telekom Mirai disruption in late November 2016. My hastily - assembled initial TR069/64 payload only performed a 'route del default' - but this was enough to get the ISP's attention to the problem and the - resulting headlines alerted other ISPs around the world to the - unfolding disaster. - -* Around January 11-12 some Mirai-infected DVRs with exposed control port - 6789 ended up getting bricked in Washington DC, and this made numerous - headlines. Gold star to Vemulapalli for determining that Mirai combined - with /dev/urandom had to be 'highly sophisticated ransomware'. Whatever - happened to those 2 unlucky souls in Europe? - -* In late January 2017 the first genuine large-scale ISP takedown occured - when Rogers Canada's supplier Hitron carelessly pushed out new firmware - with an unauthenticated root shell listening on port 2323 (presumably - this was a debugging interface that they forgot to disable). This epic - blunder was quickly discovered by Mirai botnets, and the end-result was - a large number of bricked units. - -* In February 2017 I noticed the first Mirai evolution of the year, with - both Netcore/Netis and Broadcom CLI-based modems being attacked. The - BCM CLI would turn out to become one of the main Mirai battlegrounds of - 2017, with both the blackhats and me chasing the massive long tail of - ISP and model-specific default credentials for the rest of the year. - The 'broadcom' payloads in the above source may look strange but - they're statistically the most likely sequences to disable any of the - endless number of buggy BCM CLI firmwares out there. - -* In March 2017 I significantly increased my botnet's node count and - started to add more web payloads in response to the threats from IoT - botnets such as Imeij, Amnesia and Persirai. The large-scale takedown - of these hacked devices created a new set of concerns. For example, - among the leaked credentials of the Avtech and Wificam devices there - were logins which strongly implied airports and other important - facilities, and around April 1 2017 the UK government officials - warned of a 'credible cyber threat' to airports and nuclear - facilities from 'hacktivists.' Oops. - -* The more aggressive scanning also didn't escape the attention of - civilian security researchers, and in April 6 2017 security company - Radware published an article about my project. The company trademarked - it under the name 'BrickerBot.' It became clear that if I were to - continue increasing the scale of my IoT counteroffensive I had to come - up with better network mapping/detection methods for honeypots and - other risky targets. - -* Around April 11th 2017 something very unusual happened. At first it - started like so many other ISP takedowns, with a semi-local ISP called - Sierra Tel running exposed Zyxel devices with the default telnet login - of supervisor/zyad1234. A Mirai runner discovered the exposed devices - and my botnet followed soon after, and yet another clash in the epic - BCM CLI war of 2017 took place. This battle didn't last long. It - would've been just like any of the hundreds of other ISP takedowns in - 2017 were it not for something very unusual occuring right after the - smoke settled. Amazingly, the ISP didn't try to cover up the outage as - some kind of network issue, power spike or a bad firmware upgrade. They - didn't lie to their customers at all. Instead, they promptly published - a press release about their modems having been vulnerable which allowed - their customers to assess their potential risk exposure. What did the - most honest ISP in the world get for its laudable transparency? Sadly - it got little more than criticism and bad press. It's still the most - depressing case of 'why we can't have nice things' to me, and probably - the main reason for why 99% of security mistakes get covered up and the - actual victims get left in the dark. Too often 'responsible disclosure' - simply becomes a euphemism for 'coverup.' - -* On April 14 2017 DHS warned of 'BrickerBot Threat to Internet of - Things' and the thought of my own government labeling me as a cyber - threat felt unfair and myopic. Surely the ISPs that run dangerously - insecure network deployments and the IoT manufacturers that peddle - amateurish security implementations should have been fingered as the - actual threat to Americans rather than me? If it hadn't been for me - millions of us would still be doing their banking and other sensitive - transactions over hacked equipment and networks. If anybody from DHS - ever reads this I urge you to reconsider what protecting the homeland - and its citizens actually means. - -* In late April 2017 I spent some time on improving my TR069/64 attack - methods, and in early May 2017 a company called Wordfence (now Defiant) - reported a significant decline in a TR069-exploiting botnet that had - previously posed a threat to Wordpress installations. It's noteworthy - that the same botnet temporarily returned a few weeks later using a - different exploit (but this was also eventually mitigated). - -* In May 2017 hosting company Akamai reported in its Q1 2017 State of the - Internet report an 89% decrease in large (over 100 Gbps) DDoS attacks - compared with Q1 2016, and a 30% decrease in total DDoS attacks. The - largest attack of Q1 2017 was 120 Gbps vs 517 Gbps in Q4 2016. As large - volumetric DDoS was one of the primary signatures of Mirai this felt - like concrete justification for all the months of hard work in the IoT - trenches. - -* During the summer I kept improving my exploit arsenal, and in late July - I performed some test runs against APNIC ISPs. The results were quite - surprising. Among other outcomes a few hundred thousand BSNL and MTNL - modems were disabled and this outage become headline news in India. - Given the elevated geopolitical tensions between India and China at the - time I felt that there was a credible risk of the large takedown being - blamed on China so I made the rare decision to publically take credit - for it. Catalin, I'm very sorry for the abrupt '2 day vacation' that - you had to take after reporting the news. - -* Previously having worked on APNIC and AfriNIC, on August 9th 2017 I - also launched a large scale cleanup of LACNIC space which caused - problems for various providers across the subcontinent. The attack made - headlines in Venezuela after a few million cell phone users of Movilnet - lost service. Although I'm personally against government surveillance - of the Internet the case of Venezuela is noteworthy. Many of the - LACNIC ISPs and networks have been languishing for months under - persistent conditioning from my botnet, but Venezuelan providers have - been quick to fortify their networks and secure their infrastructure. - I believe this is due to Venezuela engaging in far more invasive deep - packet inspection than the other LACNIC countries. Food for thought. - -* In August 2017 F5 Labs released a report called "The Hunt for IoT: The - Rise of Thingbots" in which the researchers were perplexed over the - recent lull in telnet activity. The researchers speculated that the - lack of activity may be evidence that one or more very large cyber - weapons are being built (which I guess was in fact true). This piece - is to my knowledge the most accurate assessment of the scope of my - project but fascinatingly the researchers were unable to put two and - two together in spite of gathering all the relevant clues on a single - page. - -* In August 2017 Akamai's Q2 2017 State of the Internet report announces - the first quarter in 3 years without the provider observing a single - large (over 100 Gbps) attack, and a 28% decrease in total DDoS attacks - vs Q1 2017. This seems like further validation of the cleanup effort. - This phenomenally good news is completely ignored by the mainstream - media which operates under an 'if it bleeds it leads' mentality even - when it comes to information security. This is yet another reason why - we can't have nice things. - -* After the publication of CVE-2017-7921 and 7923 in September 2017 I - decided to take a closer look at Hikvision devices, and to my horror - I realized that there's a technique for botting most of the vulnerable - firmwares that the blackhats hadn't discovered yet. As a result I - launched a global cleanup initiative around mid-September. Over a - million DVRs and cameras (mainly Hikvision and Dahua) were disabled - over a span of 3 weeks and publications such as IPVM.com wrote several - articles about the attacks. Dahua and Hikvision wrote press releases - mentioning or alluding to the attacks. A huge number of devices finally - got their firmwares upgraded. Seeing the confusion that the cleanup - effort caused I decided to write a quick summary for the CCTV people at - http://depastedihrn3jtw.onion.link/show.php?md5=62d1d87f67a8bf485d43a05ec32b1e6f - (sorry for the NSFW language of the pastebin service). The staggering - number of vulnerable units that were online months after critical - security patches were available should be the ultimate wakeup call to - everyone about the utter dysfunctionality of the current IoT patching - process. - -* Around September 28 2017 Verisign releases a report saying that DDoS - attacks declined 55% in Q2 2017 vs Q1, with a massive 81% attack peak - decline. - -* On November 23rd 2017 the CDN provider Cloudflare reports that 'in - recent months, Cloudflare has seen a dramatic reduction in simple - attempts to flood our network with junk traffic.' Cloudflare speculates - it could've partly been due to their change in policies, but the - reductions also line up well with the IoT cleanup activities. - -* At the end of November 2017 Akamai's Q3 2017 State of the Internet - report sees a small 8% increase in total DDoS attacks for the quarter. - Although this was a significant reduction compared to Q3 2016 the - slight uptick serves as a reminder of the continued risks and dangers. - -* As a further reminder of the dangers a new Mirai strain dubbed 'Satori' - reared its head in November-December of 2017. It's particularly - noteworthy how quickly the botnet managed to grow based on a single - 0-day exploit. This event underlines the current perilous operating - state of the Internet, and why we're only one or two severe IoT - exploits away from widespread disruption. What will happen when nobody - is around to disable the next threat? Sinkholing and other whitehat/ - 'legal' mitigations won't be enough in 2018 just like they weren't - enough in 2016. Perhaps in the future governments will be able to - collaborate on a counterhacking task force with a global mandate for - disabling particularly severe existential threats to the Internet, but - I'm not holding my breath. - -* Late in the year there were also some hysterical headlines regarding a - new botnet that was dubbed 'Reaper' and 'IoTroop'. I know some of you - will eventually ridicule those who estimated its size at 1-2 million - but you should understand that security researchers have very limited - knowledge of what's happening on networks and hardware that they don't - control. In practice the researchers could not possibly have known or - even assumed that most of the vulnerable device pool had already been - disabled by the time the botnet emerged. Give the 'Reaper' one or two - new unmitigated 0-days and it'll become as terrifying as our worst - fears. - -### 3. Parting Thoughts - -I'm sorry to leave you in these circumstances, but the threat to my own -safety is becoming too great to continue. I have made many enemies. If -you want to help look at the list of action items further up. Good luck. - -There will also be those who will criticize me and say that I've acted -irresponsibly, but that's completely missing the point. The real point -is that if somebody like me with no previous hacking background was able -to do what I did, then somebody better than me could've done far worse -things to the Internet in 2017. I'm not the problem and I'm not here to -play by anyone's contrived rules. I'm only the messenger. The sooner you -realize this the better. - --Dr Cyborkian a.k.a. janit0r, conditioner of 'terminally ill' devices. - --------------------------------------------------------------------------------- - -via:https://ghostbin.com/paste/q2vq2 - -作者:janit0r -译者:[译者ID](https://github.com/译者ID) -校对:[校对者ID](https://github.com/校对者ID) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译, -[Linux中国](https://linux.cn/) 荣誉推出 diff --git a/sources/tech/20171231 Why You Should Still Love Telnet.md b/sources/tech/20171231 Why You Should Still Love Telnet.md deleted file mode 100644 index 201ee91bd4..0000000000 --- a/sources/tech/20171231 Why You Should Still Love Telnet.md +++ /dev/null @@ -1,161 +0,0 @@ -XYenChi is translating -Why You Should Still Love Telnet -====== -Telnet, the protocol and the command line tool, were how system administrators used to log into remote servers. However, due to the fact that there is no encryption all communication, including passwords, are sent in plaintext meant that Telnet was abandoned in favour of SSH almost as soon as SSH was created. - -For the purposes of logging into a remote server, you should never, and probably have never considered it. This does not mean that the `telnet` command is not a very useful tool when used for debugging remote connection problems. - -In this guide, we will explore using `telnet` to answer the all too common question, "Why can't I ###### connect‽". - -This frustrated question is usually encountered after installing a application server like a web server, an email server, an ssh server, a Samba server etc, and for some reason, the client won't connect to the server. - -`telnet` isn't going to solve your problem but it will, very quickly, narrow down where you need to start looking to fix your problem. - -`telnet` is a very simple command to use for debugging network related issues and has the syntax: -``` -telnet - -``` - -Because `telnet` will initially simply establish a connection to the port without sending any data it can be used with almost any protocol including encrypted protocols. - -There are four main errors that you will encounter when trying to connect to a problem server. We will look at all four, explore what they mean and look at how you should fix them. - -For this guide we will assume that we have just installed a [Samba][1] server at `samba.example.com` and we can't get a local client to connect to the server. - -### Error 1 - The connection that hangs forever - -First, we need to attempt to connect to the Samba server with `telnet`. This is done with the following command (Samba listens on port 445): -``` -telnet samba.example.com 445 - -``` - -Sometimes, the connection will get to this point stop indefinitely: -``` -telnet samba.example.com 445 -Trying 172.31.25.31... - -``` - -This means that `telnet` has not received any response to its request to establish a connection. This can happen for two reasons: - - 1. There is a router down between you and the server. - 2. There is a firewall dropping your request. - - - -In order to rule out **1.** run a quick [`mtr samba.example.com`][2] to the server. If the server is accessible then it's a firewall (note: it's almost always a firewall). - -Firstly, check if there are any firewall rules on the server itself with the following command `iptables -L -v -n`, if there are none then you will get the following output: -``` -iptables -L -v -n -Chain INPUT (policy ACCEPT 0 packets, 0 bytes) - pkts bytes target prot opt in out source destination - -Chain FORWARD (policy ACCEPT 0 packets, 0 bytes) - pkts bytes target prot opt in out source destination - -Chain OUTPUT (policy ACCEPT 0 packets, 0 bytes) - pkts bytes target prot opt in out source destination - -``` - -If you see anything else then this is likely the problem. In order to check, stop `iptables` for a moment and run `telnet samba.example.com 445` again and see if you can connect. If you still can't connect see if your provider and/or office has a firewall in place that is blocking you. - -### Error 2 - DNS problems - -A DNS issue will occur if the hostname you are using does not resolve to an IP address. The error that you will see is as follows: -``` -telnet samba.example.com 445 -Server lookup failure: samba.example.com:445, Name or service not known - -``` - -The first step here is to substitute the IP address of the server for the hostname. If you can connect to the IP but not the hostname then the problem is the hostname. - -This can happen for many reasons (I have seen all of the following): - - 1. Is the domain registered? Use `whois` to find out if it is. - 2. Is the domain expired? Use `whois` to find out if it is. - 3. Are you using the correct hostname? Use `dig` or `host` to ensure that the hostname you are using resolves to the correct IP. - 4. Is your **A** record correct? Check that you didn 't accidentally create an **A** record for something like `smaba.example.com`. - - - -Always double check the spelling and the correct hostname (is it `samba.example.com` or `samba1.example.com`) as this will often trip you up especially with long, complicated or foreign hostnames. - -### Error 3 - The server isn't listening on that port - -This error occurs when `telnet` is able to reach to the server but there is nothing listening on the port you specified. The error looks like this: -``` -telnet samba.example.com 445 -Trying 172.31.25.31... -telnet: Unable to connect to remote host: Connection refused - -``` - -This can happen for a couple of reasons: - - 1. Are you **sure** you 're connecting to the right server? - 2. Your application server is not listening on the port you think it is. Check exactly what it's doing by running `netstat -plunt` on the server and see what port it is, in fact, listening on. - 3. The application server isn't running. This can happen when the application server exits immediately and silently after you start it. Start the server and run `ps auxf` or `systemctl status application.service` to check it's running. - - - -### Error 4 - The connection was closed by the server - -This error happens when the connection was successful but the application server has a build in security measure that killed the connection as soon as it was made. This error looks like: -``` -telnet samba.example.com 445 -Trying 172.31.25.31... -Connected to samba.example.com. -Escape character is '^]'. -��Connection closed by foreign host. - -``` - -The last line `Connection closed by foreign host.` indicates that the connection was actively terminated by the server. In order to fix this, you need to look at the security configuration of the application server to ensure your IP or user is allowed to connect to it. - -### A successful connection - -This is what a successful `telnet` connection attempt looks like: -``` -telnet samba.example.com 445 -Trying 172.31.25.31... -Connected to samba.example.com. -Escape character is '^]'. - -``` - -The connection will stay open for a while depending on the timeout of the application server you are connected to. - -A telnet connection is closed by typing `CTRL+]` and then when you see the `telnet>` prompt, type "quit" and hit ENTER i.e.: -``` -telnet samba.example.com 445 -Trying 172.31.25.31... -Connected to samba.example.com. -Escape character is '^]'. -^] -telnet> quit -Connection closed. - -``` - -### Conclusion - -There are a lot of reasons that a client application can't connect to a server. The exact reason can be difficult to establish especially when the client is a GUI that offers little or no error information. Using `telnet` and observing the output will allow you to very rapidly narrow down where the problem lies and save you a whole lot of time. - --------------------------------------------------------------------------------- - -via: https://bash-prompt.net/guides/telnet/ - -作者:[Elliot Cooper][a] -译者:[译者ID](https://github.com/译者ID) -校对:[校对者ID](https://github.com/校对者ID) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 - -[a]:https://bash-prompt.net -[1]:https://www.samba.org/ -[2]:https://www.systutorials.com/docs/linux/man/8-mtr/ diff --git a/sources/tech/20180103 How To Find The Installed Proprietary Packages In Arch Linux.md b/sources/tech/20180103 How To Find The Installed Proprietary Packages In Arch Linux.md index 69b523426c..8dc2e92513 100644 --- a/sources/tech/20180103 How To Find The Installed Proprietary Packages In Arch Linux.md +++ b/sources/tech/20180103 How To Find The Installed Proprietary Packages In Arch Linux.md @@ -1,3 +1,4 @@ +Translating by stevenzdg988 How To Find The Installed Proprietary Packages In Arch Linux ====== ![](https://www.ostechnix.com/wp-content/uploads/2018/01/Absolutely-Proprietary-720x340.jpg) diff --git a/sources/tech/20180106 Meltdown and Spectre Linux Kernel Status.md b/sources/tech/20180106 Meltdown and Spectre Linux Kernel Status.md deleted file mode 100644 index d98fddad78..0000000000 --- a/sources/tech/20180106 Meltdown and Spectre Linux Kernel Status.md +++ /dev/null @@ -1,103 +0,0 @@ -translated by hopefully2333 - -Meltdown and Spectre Linux Kernel Status -============================================================ - - -By now, everyone knows that something “big” just got announced regarding computer security. Heck, when the [Daily Mail does a report on it][1] , you know something is bad… - -Anyway, I’m not going to go into the details about the problems being reported, other than to point you at the wonderfully written [Project Zero paper on the issues involved here][2]. They should just give out the 2018 [Pwnie][3] award right now, it’s that amazingly good. - -If you do want technical details for how we are resolving those issues in the kernel, see the always awesome [lwn.net writeup for the details][4]. - -Also, here’s a good summary of [lots of other postings][5] that includes announcements from various vendors. - -As for how this was all handled by the companies involved, well this could be described as a textbook example of how  _NOT_  to interact with the Linux kernel community properly. The people and companies involved know what happened, and I’m sure it will all come out eventually, but right now we need to focus on fixing the issues involved, and not pointing blame, no matter how much we want to. - -### What you can do right now - -If your Linux systems are running a normal Linux distribution, go update your kernel. They should all have the updates in them already. And then keep updating them over the next few weeks, we are still working out lots of corner case bugs given that the testing involved here is complex given the huge variety of systems and workloads this affects. If your distro does not have kernel updates, then I strongly suggest changing distros right now. - -However there are lots of systems out there that are not running “normal” Linux distributions for various reasons (rumor has it that it is way more than the “traditional” corporate distros). They rely on the LTS kernel updates, or the normal stable kernel updates, or they are in-house franken-kernels. For those people here’s the status of what is going on regarding all of this mess in the upstream kernels you can use. - -### Meltdown – x86 - -Right now, Linus’s kernel tree contains all of the fixes we currently know about to handle the Meltdown vulnerability for the x86 architecture. Go enable the CONFIG_PAGE_TABLE_ISOLATION kernel build option, and rebuild and reboot and all should be fine. - -However, Linus’s tree is currently at 4.15-rc6 + some outstanding patches. 4.15-rc7 should be out tomorrow, with those outstanding patches to resolve some issues, but most people do not run a -rc kernel in a “normal” environment. - -Because of this, the x86 kernel developers have done a wonderful job in their development of the page table isolation code, so much so that the backport to the latest stable kernel, 4.14, has been almost trivial for me to do. This means that the latest 4.14 release (4.14.12 at this moment in time), is what you should be running. 4.14.13 will be out in a few more days, with some additional fixes in it that are needed for some systems that have boot-time problems with 4.14.12 (it’s an obvious problem, if it does not boot, just add the patches now queued up.) - -I would personally like to thank Andy Lutomirski, Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, Peter Zijlstra, Josh Poimboeuf, Juergen Gross, and Linus Torvalds for all of the work they have done in getting these fixes developed and merged upstream in a form that was so easy for me to consume to allow the stable releases to work properly. Without that effort, I don’t even want to think about what would have happened. - -For the older long term stable (LTS) kernels, I have leaned heavily on the wonderful work of Hugh Dickins, Dave Hansen, Jiri Kosina and Borislav Petkov to bring the same functionality to the 4.4 and 4.9 stable kernel trees. I had also had immense help from Guenter Roeck, Kees Cook, Jamie Iles, and many others in tracking down nasty bugs and missing patches. I want to also call out David Woodhouse, Eduardo Valentin, Laura Abbott, and Rik van Riel for their help with the backporting and integration as well, their help was essential in numerous tricky places. - -These LTS kernels also have the CONFIG_PAGE_TABLE_ISOLATION build option that should be enabled to get complete protection. - -As this backport is very different from the mainline version that is in 4.14 and 4.15, there are different bugs happening, right now we know of some VDSO issues that are getting worked on, and some odd virtual machine setups are reporting strange errors, but those are the minority at the moment, and should not stop you from upgrading at all right now. If you do run into problems with these releases, please let us know on the stable kernel mailing list. - -If you rely on any other kernel tree other than 4.4, 4.9, or 4.14 right now, and you do not have a distribution supporting you, you are out of luck. The lack of patches to resolve the Meltdown problem is so minor compared to the hundreds of other known exploits and bugs that your kernel version currently contains. You need to worry about that more than anything else at this moment, and get your systems up to date first. - -Also, go yell at the people who forced you to run an obsoleted and insecure kernel version, they are the ones that need to learn that doing so is a totally reckless act. - -### Meltdown – ARM64 - -Right now the ARM64 set of patches for the Meltdown issue are not merged into Linus’s tree. They are [staged and ready to be merged][6] into 4.16-rc1 once 4.15 is released in a few weeks. Because these patches are not in a released kernel from Linus yet, I can not backport them into the stable kernel releases (hey, we have [rules][7] for a reason…) - -Due to them not being in a released kernel, if you rely on ARM64 for your systems (i.e. Android), I point you at the [Android Common Kernel tree][8] All of the ARM64 fixes have been merged into the [3.18,][9] [4.4,][10] and [4.9 branches][11] as of this point in time. - -I would strongly recommend just tracking those branches as more fixes get added over time due to testing and things catch up with what gets merged into the upstream kernel releases over time, especially as I do not know when these patches will land in the stable and LTS kernel releases at this point in time. - -For the 4.4 and 4.9 LTS kernels, odds are these patches will never get merged into them, due to the large number of prerequisite patches required. All of those prerequisite patches have been long merged and tested in the android-common kernels, so I think it is a better idea to just rely on those kernel branches instead of the LTS release for ARM systems at this point in time. - -Also note, I merge all of the LTS kernel updates into those branches usually within a day or so of being released, so you should be following those branches no matter what, to ensure your ARM systems are up to date and secure. - -### Spectre - -Now things get “interesting”… - -Again, if you are running a distro kernel, you  _might_  be covered as some of the distros have merged various patches into them that they claim mitigate most of the problems here. I suggest updating and testing for yourself to see if you are worried about this attack vector - -For upstream, well, the status is there is no fixes merged into any upstream tree for these types of issues yet. There are numerous patches floating around on the different mailing lists that are proposing solutions for how to resolve them, but they are under heavy development, some of the patch series do not even build or apply to any known trees, the series conflict with each other, and it’s a general mess. - -This is due to the fact that the Spectre issues were the last to be addressed by the kernel developers. All of us were working on the Meltdown issue, and we had no real information on exactly what the Spectre problem was at all, and what patches were floating around were in even worse shape than what have been publicly posted. - -Because of all of this, it is going to take us in the kernel community a few weeks to resolve these issues and get them merged upstream. The fixes are coming in to various subsystems all over the kernel, and will be collected and released in the stable kernel updates as they are merged, so again, you are best off just staying up to date with either your distribution’s kernel releases, or the LTS and stable kernel releases. - -It’s not the best news, I know, but it’s reality. If it’s any consolation, it does not seem that any other operating system has full solutions for these issues either, the whole industry is in the same boat right now, and we just need to wait and let the developers solve the problem as quickly as they can. - -The proposed solutions are not trivial, but some of them are amazingly good. The [Retpoline][12] post from Paul Turner is an example of some of the new concepts being created to help resolve these issues. This is going to be an area of lots of research over the next years to come up with ways to mitigate the potential problems involved in hardware that wants to try to predict the future before it happens. - -### Other arches - -Right now, I have not seen patches for any other architectures than x86 and arm64\. There are rumors of patches floating around in some of the enterprise distributions for some of the other processor types, and hopefully they will surface in the weeks to come to get merged properly upstream. I have no idea when that will happen, if you are dependant on a specific architecture, I suggest asking on the arch-specific mailing list about this to get a straight answer. - -### Conclusion - -Again, update your kernels, don’t delay, and don’t stop. The updates to resolve these problems will be continuing to come for a long period of time. Also, there are still lots of other bugs and security issues being resolved in the stable and LTS kernel releases that are totally independent of these types of issues, so keeping up to date is always a good idea. - -Right now, there are a lot of very overworked, grumpy, sleepless, and just generally pissed off kernel developers working as hard as they can to resolve these issues that they themselves did not cause at all. Please be considerate of their situation right now. They need all the love and support and free supply of their favorite beverage that we can provide them to ensure that we all end up with fixed systems as soon as possible. - --------------------------------------------------------------------------------- - -via: http://kroah.com/log/blog/2018/01/06/meltdown-status/ - -作者:[Greg Kroah-Hartman ][a] -译者:[译者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]:http://www.dailymail.co.uk/sciencetech/article-5238789/Intel-says-security-updates-fix-Meltdown-Spectre.html -[2]:https://googleprojectzero.blogspot.fr/2018/01/reading-privileged-memory-with-side.html -[3]:https://pwnies.com/ -[4]:https://lwn.net/Articles/743265/ -[5]:https://lwn.net/Articles/742999/ -[6]:https://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git/log/?h=kpti -[7]:https://www.kernel.org/doc/html/latest/process/stable-kernel-rules.html -[8]:https://android.googlesource.com/kernel/common/ -[9]:https://android.googlesource.com/kernel/common/+/android-3.18 -[10]:https://android.googlesource.com/kernel/common/+/android-4.4 -[11]:https://android.googlesource.com/kernel/common/+/android-4.9 -[12]:https://support.google.com/faqs/answer/7625886 diff --git a/sources/talk/20180108 You GNOME it- Windows and Apple devs get a compelling reason to turn to Linux.md b/sources/tech/20180108 You GNOME it- Windows and Apple devs get a compelling reason to turn to Linux.md similarity index 100% rename from sources/talk/20180108 You GNOME it- Windows and Apple devs get a compelling reason to turn to Linux.md rename to sources/tech/20180108 You GNOME it- Windows and Apple devs get a compelling reason to turn to Linux.md diff --git a/sources/tech/20180111 Multimedia Apps for the Linux Console.md b/sources/tech/20180111 Multimedia Apps for the Linux Console.md deleted file mode 100644 index 6cdd3ef857..0000000000 --- a/sources/tech/20180111 Multimedia Apps for the Linux Console.md +++ /dev/null @@ -1,112 +0,0 @@ -Translating by Yinr - -Multimedia Apps for the Linux Console -====== - -![](https://www.linux.com/sites/lcom/files/styles/rendered_file/public/multimedia.jpg?itok=v-XrnKRB) -The Linux console supports multimedia, so you can enjoy music, movies, photos, and even read PDF files. - -When last we met, we learned that the Linux console supports multimedia. Yes, really! You can enjoy music, movies, photos, and even read PDF files without being in an X session with MPlayer, fbi, and fbgs. And, as a bonus, you can enjoy a Matrix-style screensaver for the console, CMatrix. - -You will probably have make some tweaks to your system to make this work. The examples used here are for Ubuntu Linux 16.04. - -### MPlayer - -You're probably familiar with the amazing and versatile MPlayer, which supports almost every video and audio format, and runs on nearly everything, including Linux, Android, Windows, Mac, Kindle, OS/2, and AmigaOS. Using MPLayer in your console will probably require some tweaking, depending on your Linux distribution. To start, try playing a video: -``` -$ mplayer [video name] - -``` - -If it works, then hurrah, and you can invest your time in learning useful MPlayer options, such as controlling the size of the video screen. However, some Linux distributions are managing the framebuffer differently than in the olden days, and you may have to adjust some settings to make it work. This is how to make it work on recent Ubuntu releases. - -First, add yourself to the video group. - -Second, verify that `/etc/modprobe.d/blacklist-framebuffer.conf` has this line: `#blacklist vesafb`. It should already be commented out, and if it isn't then comment it. All the other module lines should be un-commented, which prevents them from loading. Side note: if you want to dig more deeply into managing your framebuffer, the module for your video card may give better performance. - -Add these two modules to the end of `/etc/initramfs-tools/modules`, `vesafb` and `fbcon`, then rebuild the initramfs image: -``` -$ sudo nano /etc/initramfs-tools/modules - # List of modules that you want to include in your initramfs. - # They will be loaded at boot time in the order below. - fbcon - vesafb - -$ sudo update-initramfs -u - -``` - -[fbcon][1] is the Linux framebuffer console. It runs on top of the framebuffer and adds graphical features. It requires a framebuffer device, which is supplied by the `vesafb` module. - -Now you must edit your GRUB2 configuration. In `/etc/default/grub` you should see a line like this: -``` -GRUB_CMDLINE_LINUX_DEFAULT="quiet splash" - -``` - -It may have some other options, but it should be there. Add `vga=789`: -``` -GRUB_CMDLINE_LINUX_DEFAULT="quiet splash vga=789" - -``` - -Reboot and enter your console (Ctrl+Alt+F1), and try playing a video. This command selects the `fbdev2` video device; I haven't learned yet how to know which one to use, but I had to use it to play the video. The default screen size is 320x240, so I scaled it to 960: -``` -$ mplayer -vo fbdev2 -vf scale -zoom -xy 960 AlienSong_mp4.mov -``` - -And behold Figure 1. It's grainy because I have a low-fi copy of this video, not because MPlayer is making it grainy. - -MPLayer plays CDs, DVDs, network streams, and has a giant batch of playback options, which I shall leave as your homework to explore. - -### fbi Image Viewer - -`fbi`, the framebuffer image viewer, comes in the [fbida][2] package on most Linuxes. It has native support for the common image file formats, and uses `convert` (from Image Magick), if it is installed, for other formats. Its simplest use is to view a single image file: -``` -$ fbi filename - -``` - -Use the arrow keys to scroll a large image, + and - to zoom, and r and l to rotate 90 degress right and left. Press the Escape key to close the image. You can play a slideshow by giving `fbi` a list of files: -``` -$ fbi --list file-list.txt - -``` - -`fbi` supports autozoom. With `-a` `fbi` controls the zoom factor. `--autoup` and `--autodown` tell `fbi` to only zoom up or down. Control the blend time between images with `--blend [time]`, in milliseconds. Press the k and j keys to jump behind and ahead in your file list. - -`fbi` has commands for creating file lists from images you have viewed, and for exporting your commands to a file, and a host of other cool options. Check out `man fbi` for complete options. - -### CMatrix Console Screensaver - -The Matrix screensaver is still my favorite (Figure 2), second only to the bouncing cow. [CMatrix][3] runs on the console. Simply type `cmatrix` to start it, and Ctrl+C stops it. Run `cmatrix -s` to launch it in screensaver mode, which exits on any keypress. `-C` changes the color. Your choices are green, red, blue, yellow, white, magenta, cyan, and black. - -CMatrix supports asynchronous key presses, which means you can change options while it's running. - -`-B` is all bold text, and `-B` is partially bold. - -### fbgs PDF Viewer - -It seems that the addiction to PDF documents is pandemic and incurable, though PDFs are better than they used to be, with live hyperlinks, copy-paste, and good text search. The `fbgs` console PDF viewer is part of the `fbida` package. Options include page size, resolution, page selections, and most `fbi` options, with the exceptions listed in `man fbgs`. The main option I use is page size; you get `-l`, `xl`, and `xxl` to choose from: -``` -$ fbgs -xl annoyingpdf.pdf - -``` - -Learn more about Linux through the free ["Introduction to Linux" ][4]course from The Linux Foundation and edX. - --------------------------------------------------------------------------------- - -via: https://www.linux.com/learn/intro-to-linux/2018/1/multimedia-apps-linux-console - -作者:[Carla Schroder][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/cschroder -[1]:https://www.mjmwired.net/kernel/Documentation/fb/fbcon.txt -[2]:https://www.kraxel.org/blog/linux/fbida/ -[3]:http://www.asty.org/cmatrix/ -[4]:https://training.linuxfoundation.org/linux-courses/system-administration-training/introduction-to-linux diff --git a/sources/tech/20180111 What is the deal with GraphQL.md b/sources/tech/20180111 What is the deal with GraphQL.md new file mode 100644 index 0000000000..c656769269 --- /dev/null +++ b/sources/tech/20180111 What is the deal with GraphQL.md @@ -0,0 +1,43 @@ +translating---geekpi + +What is the deal with GraphQL? +====== + +![](https://ryanmccue.ca/content/images/2018/01/Copy-of-Copy-of-Copy-of-Copy-of-Copy-of-Copy-of-Electric-Love.png) + +There has been lots of talks lately about this thing called [GraphQL][1]. It is a relatively new technology coming out of Facebook and is starting to be widely adopted by large companies like [Github][2], Facebook, Twitter, Yelp, and many others. Basically, GraphQL is an alternative to REST, it replaces many dumb endpoints, `/user/1`, `/user/1/comments` with `/graphql` and you use the post body or query string to request the data you need, like, `/graphql?query={user(id:1){id,username,comments{text}}}`. You pick the pieces of data you need and can nest down to relations to avoid multiple calls. This is a different way of thinking about a backend, but in some situations, it makes practical sense. + +### My Experience with GraphQL + +Originally when I heard about it I was very skeptical, after dabbling in [Apollo Server][3] I was not convinced. Why would you use some silly new technology when you can simply build REST endpoints! But after digging deeper and learning more about its use cases, I came around. I still think REST has a place and will be important for the foreseeable future, but with how bad many APIs and their documentation are, this can be a breath of fresh air... + +### Why Use GraphQL Over REST? + +Although I have used GraphQL, and think it is a compelling and exciting technology, I believe it does not replace REST. That being said there are compelling reasons to pick GraphQL over REST in some situations. When you are building mobile apps or web apps which are made with high mobile traffic in mind GraphQL really shines. The reason for this is mobile data. REST uses many calls and often returns unused data whereas, with GraphQL, you can define precisely what you want to be returned for minimal data usage. + +You can get do all the above with REST by making multiple endpoints available, but that also adds complexity to the project. It also means there will be back and forth between the front and backend teams. + +### What Should You Use? + +GraphQL is a new technology which is now mainstream. But many developers are not aware of it or choose not to learn it because they think it's a fad. I feel like for most projects you can get away using either REST or GraphQL. Developing using GraphQL has great benefits like enforcing documentation, which helps teams work better together, and provides clear expectations for each query. This will likely speed up development after the initial hurdle of wrapping your head around GraphQL. + +Although I have been comparing GraphQL and REST, I think in most cases a mixture of the two will produce the best results. Combine the strengths of both instead of seeing it strightly as just using GraphQL or just using REST. + +### Final Thoughts + +Both technologies are here to stay. And done right both technologies can make fast and efficient backends. GraphQL has an edge up because it allows the client to query only the data they need by default, but that is at a potential sacrifice of endpoint speed. Ultimately, if I were starting a new project, I would go with a mix of both GraphQL and REST. + +-------------------------------------------------------------------------------- + +via: https://ryanmccue.ca/what-is-the-deal-with-graphql/ + +作者:[Ryan McCue][a] +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://ryanmccue.ca/author/ryan/ +[1]:http://graphql.org/ +[2]:https://developer.github.com/v4/ +[3]:https://github.com/apollographql/apollo-server diff --git a/sources/tech/20180115 How To Boot Into Linux Command Line.md b/sources/tech/20180115 How To Boot Into Linux Command Line.md deleted file mode 100644 index 00649cc678..0000000000 --- a/sources/tech/20180115 How To Boot Into Linux Command Line.md +++ /dev/null @@ -1,63 +0,0 @@ -translating---geekpi - -How To Boot Into Linux Command Line -====== -![](http://www.linuxandubuntu.com/uploads/2/1/1/5/21152474/how-to-boot-into-linux-command-line_orig.jpg) - -There may be times where you need or want to boot up a [Linux][1] system without using a GUI, that is with no X, but rather opt for the command line. Whatever the reason, fortunately, booting straight into the Linux **command-line** is very simple. It requires a simple change to the boot parameter after the other kernel options. This change specifies the runlevel to boot the system into. - -### ​Why Do This? - -If your system does not run Xorg because the configuration is invalid, or if the display manager is broken, or whatever may prevent the GUI from starting properly, booting into the command-line will allow you to troubleshoot by logging into a terminal (assuming you know what you’re doing to start with) and do whatever you need to do. Booting into the command-line is also a great way to become more familiar with the terminal, otherwise, you can do it just for fun. - -### ​Accessing GRUB Menu - -On startup, you will need access to the GRUB boot menu. You may need to hold the SHIFT key down before the system boots if the menu isn’t set to display every time the computer is started. In the menu, the [Linux distribution][2] entry must be selected. Once highlighted, press ‘e’ to edit the boot parameters. - - [![zorin os grub menu](http://www.linuxandubuntu.com/uploads/2/1/1/5/21152474/gnu-grub_orig.png)][3] - - Older GRUB versions follow a similar mechanism. The boot manager should provide instructions on how to edit the boot parameters. - -### ​​Specify the Runlevel - -​An editor will appear and you will see the options that GRUB parses to the kernel. Navigate to the line that starts with ‘linux’ (older GRUB versions may be ‘kernel’; select that and follow the instructions). This specifies parameters to parse into the kernel. At the end of that line (may appear to span multiple lines, depending on resolution), you simply specify the runlevel to boot into, which is 3 (multi-user mode, text-only). - - [![customize grub menu](http://www.linuxandubuntu.com/uploads/2/1/1/5/21152474/runlevel_orig.png)][4] - -Pressing Ctrl-X or F10 will boot the system using those parameters. Boot-up will continue as normal. The only thing that has changed is the runlevel to boot into. - -​ - -This is what was started up: - - [![boot linux in command line](http://www.linuxandubuntu.com/uploads/2/1/1/5/21152474/runlevel_1_orig.png)][5] - -### Runlevels - -You can specify different runlevels to boot into with runlevel 5 being the default one. 1 boots into “single-user” mode, which boots into a root shell. 3 provides a multi-user, command-line only system. - -### Switch From Command-Line - -At some point, you may want to run the display manager again to use a GUI, and the quickest way to do that is running this: -``` -$ sudo init 5 -``` - -And it is as simple as that. Personally, I find the command-line much more exciting and hands-on than using GUI tools; however, that’s just my preference. - --------------------------------------------------------------------------------- - -via: http://www.linuxandubuntu.com/home/how-to-boot-into-linux-command-line - -作者:[LinuxAndUbuntu][a] -译者:[译者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/home/category/linux -[2]:http://www.linuxandubuntu.com/home/category/distros -[3]:http://www.linuxandubuntu.com/uploads/2/1/1/5/21152474/gnu-grub_orig.png -[4]:http://www.linuxandubuntu.com/uploads/2/1/1/5/21152474/runlevel_orig.png -[5]:http://www.linuxandubuntu.com/uploads/2/1/1/5/21152474/runlevel_1_orig.png diff --git a/sources/tech/20180117 How To Manage Vim Plugins Using Vundle On Linux.md b/sources/tech/20180117 How To Manage Vim Plugins Using Vundle On Linux.md deleted file mode 100644 index 40f6c926f1..0000000000 --- a/sources/tech/20180117 How To Manage Vim Plugins Using Vundle On Linux.md +++ /dev/null @@ -1,252 +0,0 @@ -translated by cyleft - -How To Manage Vim Plugins Using Vundle On Linux -====== -![](https://www.ostechnix.com/wp-content/uploads/2018/01/Vundle-4-720x340.png) - -**Vim** , undoubtedly, is one of the powerful and versatile tool to manipulate text files, manage the system configuration files and writing code. The functionality of Vim can be extended to different levels using plugins. Usually, all plugins and additional configuration files will be stored in **~/.vim** directory. Since all plugin files are stored in a single directory, the files from different plugins are mixed up together as you install more plugins. Hence, it is going to be a daunting task to track and manage all of them. This is where Vundle comes in help. Vundle, acronym of **V** im B **undle** , is an extremely useful plug-in to manage Vim plugins. - -Vundle creates a separate directory tree for each plugin you install and stores the additional configuration files in the respective plugin directory. Therefore, there is no mix up files with one another. In a nutshell, Vundle allows you to install new plugins, configure existing plugins, update configured plugins, search for installed plugins and clean up unused plugins. All actions can be done in a single keypress with interactive mode. In this brief tutorial, let me show you how to install Vundle and how to manage Vim plugins using Vundle in GNU/Linux. - -### Installing Vundle - -If you need Vundle, I assume you have already installed **vim** on your system. If not, install vim and **git** (to download vundle). Both packages are available in the official repositories of most GNU/Linux distributions.For instance, you can use the following command to install these packages on Debian based systems. -``` -sudo apt-get install vim git -``` - -**Download Vundle** - -Clone Vundle GitHub repository: -``` -git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim -``` - -**Configure Vundle** - -To tell vim to use the new plugin manager, we need to create **~/.vimrc** file. This file is required to install, update, configure and remove plugins. -``` -vim ~/.vimrc -``` - -Put the following lines on the top of this file: -``` -set nocompatible " be iMproved, required -filetype off " required - -" set the runtime path to include Vundle and initialize -set rtp+=~/.vim/bundle/Vundle.vim -call vundle#begin() -" alternatively, pass a path where Vundle should install plugins -"call vundle#begin('~/some/path/here') - -" let Vundle manage Vundle, required -Plugin 'VundleVim/Vundle.vim' - -" The following are examples of different formats supported. -" Keep Plugin commands between vundle#begin/end. -" plugin on GitHub repo -Plugin 'tpope/vim-fugitive' -" plugin from http://vim-scripts.org/vim/scripts.html -" Plugin 'L9' -" Git plugin not hosted on GitHub -Plugin 'git://git.wincent.com/command-t.git' -" git repos on your local machine (i.e. when working on your own plugin) -Plugin 'file:///home/gmarik/path/to/plugin' -" The sparkup vim script is in a subdirectory of this repo called vim. -" Pass the path to set the runtimepath properly. -Plugin 'rstacruz/sparkup', {'rtp': 'vim/'} -" Install L9 and avoid a Naming conflict if you've already installed a -" different version somewhere else. -" Plugin 'ascenator/L9', {'name': 'newL9'} - -" All of your Plugins must be added before the following line -call vundle#end() " required -filetype plugin indent on " required -" To ignore plugin indent changes, instead use: -"filetype plugin on -" -" Brief help -" :PluginList - lists configured plugins -" :PluginInstall - installs plugins; append `!` to update or just :PluginUpdate -" :PluginSearch foo - searches for foo; append `!` to refresh local cache -" :PluginClean - confirms removal of unused plugins; append `!` to auto-approve removal -" -" see :h vundle for more details or wiki for FAQ -" Put your non-Plugin stuff after this line -``` - -The lines which are marked as "required" are Vundle's requirement. The rest of the lines are just examples. You can remove those lines if you don't want to install that specified plugins. Once you finished, type **:wq** to save and close file. - -Finally, open vim: -``` -vim -``` - -And type the following to install the plugins. -``` -:PluginInstall -``` - -[![][1]][2] - -A new split window will open and all the plugins which we added in the .vimrc file will be installed automatically. - -[![][1]][3] - -When the installation is completed, you can delete the buffer cache and close the split window by typing the following command: -``` -:bdelete -``` - -You can also install the plugins without opening vim using the following command from the Terminal: -``` -vim +PluginInstall +qall -``` - -For those using the [**fish shell**][4], add the following line to your **.vimrc** file.`` -``` -set shell=/bin/bash -``` - -### Manage Vim Plugins Using Vundle - -**Add New Plugins** - -First, search for the available plugins using command: -``` -:PluginSearch -``` - -To refresh the local list from the from the vimscripts site, add **"! "** at the end. -``` -:PluginSearch! -``` - -A new split window will open list all available plugins. - -[![][1]][5] - -You can also narrow down your search by using directly specifying the name of the plugin like below. -``` -:PluginSearch vim -``` - -This will list the plugin(s) that contains the words "vim" - -You can, of course, specify the exact plugin name like below. -``` -:PluginSearch vim-dasm -``` - -To install a plugin, move the cursor to the correct line and hit **" i"**. Now, the selected plugin will be installed. - -[![][1]][6] - -Similarly, install all plugins you wanted to have in your system. Once installed, delete the Vundle buffer cache using command: -``` -:bdelete -``` - -Now the plugin is installed. To make it autoload correctly, we need to add the installed plugin name to .vimrc file. - -To do so, type: -``` -:e ~/.vimrc -``` - -Add the following line. -``` -[...] -Plugin 'vim-dasm' -[...] -``` - -Replace vim-dasm with your plugin name. Then, hit ESC key and type **:wq** to save the changes and close the file. - -Please note that all of your Plugins must be added before the following line in your .vimrc file. -``` -[...] -filetype plugin indent on -``` - -**List installed Plugins** - -To list installed plugins, type the following from the vim editor: -``` -:PluginList -``` - -[![][1]][7] - -**Update plugins** - -To update the all installed plugins, type: -``` -:PluginUpdate -``` - -To reinstall all plugins, type: -``` -:PluginInstall! -``` - -**Uninstall plugins** - -First, list out all installed plugins: -``` -:PluginList -``` - -Then place the cursor to the correct line, and press **" SHITF+d"**. - -[![][1]][8] - -Then, edit your .vimrc file: -``` -:e ~/.vimrc -``` - -And delete the Plugin entry. Finally, type **:wq** to save the changes and exit from vim editor. - -Alternatively, you can uninstall a plugin by removing its line from .vimrc file and run: -``` -:PluginClean -``` - -This command will remove all plugins which are no longer present in your .vimrc but still present the bundle directory. - -At this point, you should have learned the basic usage about managing plugins using Vundle. For details, refer the help section by typing the following in your vim editor. -``` -:h vundle -``` - -**Also Read:** - -And, that's all for now. I will be soon here with another useful guide. Until then, stay tuned with OSTechNix! - -Cheers! - -**Resource:** - - - --------------------------------------------------------------------------------- - -via: https://www.ostechnix.com/manage-vim-plugins-using-vundle-linux/ - -作者:[SK][a] -译者:[译者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/01/Vundle-1.png () -[3]:http://www.ostechnix.com/wp-content/uploads/2018/01/Vundle-2.png () -[4]:https://www.ostechnix.com/install-fish-friendly-interactive-shell-linux/ -[5]:http://www.ostechnix.com/wp-content/uploads/2018/01/Vundle-3.png () -[6]:http://www.ostechnix.com/wp-content/uploads/2018/01/Vundle-4-2.png () -[7]:http://www.ostechnix.com/wp-content/uploads/2018/01/Vundle-5-1.png () -[8]:http://www.ostechnix.com/wp-content/uploads/2018/01/Vundle-6.png () diff --git a/sources/tech/20180118 Configuring MSMTP On Ubuntu 16.04 (Again).md b/sources/tech/20180118 Configuring MSMTP On Ubuntu 16.04 (Again).md deleted file mode 100644 index 9ddb25b40b..0000000000 --- a/sources/tech/20180118 Configuring MSMTP On Ubuntu 16.04 (Again).md +++ /dev/null @@ -1,82 +0,0 @@ -Configuring MSMTP On Ubuntu 16.04 (Again) -====== -This post exists as a copy of what I had on my previous blog about configuring MSMTP on Ubuntu 16.04; I'm posting it as-is for posterity, and have no idea if it'll work on later versions. As I'm not hosting my own Ubuntu/MSMTP server anymore I can't see any updates being made to this, but if I ever do have to set this up again I'll create an updated post! Anyway, here's what I had… - -I previously wrote an article around configuring msmtp on Ubuntu 12.04, but as I hinted at in a previous post that sort of got lost when the upgrade of my host to Ubuntu 16.04 went somewhat awry. What follows is essentially the same post, with some slight updates for 16.04. As before, this assumes that you're using Apache as the web server, but I'm sure it shouldn't be too different if your web server of choice is something else. - -I use [msmtp][1] for sending emails from this blog to notify me of comments and upgrades etc. Here I'm going to document how I configured it to send emails via a Google Apps account, although this should also work with a standard Gmail account too. - -To begin, we need to install 3 packages: -`sudo apt-get install msmtp msmtp-mta ca-certificates` -Once these are installed, a default config is required. By default msmtp will look at `/etc/msmtprc`, so I created that using vim, though any text editor will do the trick. This file looked something like this: -``` -# Set defaults. -defaults -# Enable or disable TLS/SSL encryption. -tls on -tls_starttls on -tls_trust_file /etc/ssl/certs/ca-certificates.crt -# Setup WP account's settings. -account -host smtp.gmail.com -port 587 -auth login -user -password -from -logfile /var/log/msmtp/msmtp.log - -account default : - -``` - -Any of the uppercase items (i.e. ``) are things that need replacing specific to your configuration. The exception to that is the log file, which can of course be placed wherever you wish to log any msmtp activity/warnings/errors to. - -Once that file is saved, we'll update the permissions on the above configuration file -- msmtp won't run if the permissions on that file are too open -- and create the directory for the log file. -``` -sudo mkdir /var/log/msmtp -sudo chown -R www-data:adm /var/log/msmtp -sudo chmod 0600 /etc/msmtprc - -``` - -Next I chose to configure logrotate for the msmtp logs, to make sure that the log files don't get too large as well as keeping the log directory a little tidier. To do this, we create `/etc/logrotate.d/msmtp` and configure it with the following file. Note that this is optional, you may choose to not do this, or you may choose to configure the logs differently. -``` -/var/log/msmtp/*.log { -rotate 12 -monthly -compress -missingok -notifempty -} - -``` - -Now that the logging is configured, we need to tell PHP to use msmtp by editing `/etc/php/7.0/apache2/php.ini` and updating the sendmail path from -`sendmail_path =` -to -`sendmail_path = "/usr/bin/msmtp -C /etc/msmtprc -a -t"` -Here I did run into an issue where even though I specified the account name it wasn't sending emails correctly when I tested it. This is why the line `account default : ` was placed at the end of the msmtp configuration file. To test the configuration, ensure that the PHP file has been saved and run `sudo service apache2 restart`, then run `php -a` and execute the following -``` -mail ('personal@email.com', 'Test Subject', 'Test body text'); -exit(); - -``` - -Any errors that occur at this point will be displayed in the output so should make diagnosing any errors after the test relatively easy. If all is successful, you should now be able to use PHPs sendmail (which at the very least WordPress uses) to send emails from your Ubuntu server using Gmail (or Google Apps). - -I make no claims that this is the most secure configuration, so if you come across this and realise it's grossly insecure or something is drastically wrong please let me know and I'll update it accordingly. - - --------------------------------------------------------------------------------- - -via: https://codingproductivity.wordpress.com/2018/01/18/configuring-msmtp-on-ubuntu-16-04-again/ - -作者:[JOE][a] -译者:[译者ID](https://github.com/译者ID) -校对:[校对者ID](https://github.com/校对者ID) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 - -[a]:https://codingproductivity.wordpress.com/author/joeb454/ -[1]:http://msmtp.sourceforge.net/ diff --git a/sources/tech/20180118 Getting Started with ncurses.md b/sources/tech/20180118 Getting Started with ncurses.md deleted file mode 100644 index d02ad61785..0000000000 --- a/sources/tech/20180118 Getting Started with ncurses.md +++ /dev/null @@ -1,213 +0,0 @@ -Getting Started with ncurses -====== -How to use curses to draw to the terminal screen. - -While graphical user interfaces are very cool, not every program needs to run with a point-and-click interface. For example, the venerable vi editor ran in plain-text terminals long before the first GUI. - -The vi editor is one example of a screen-oriented program that draws in "text" mode, using a library called curses, which provides a set of programming interfaces to manipulate the terminal screen. The curses library originated in BSD UNIX, but Linux systems provide this functionality through the ncurses library. - -[For a "blast from the past" on ncurses, see ["ncurses: Portable Screen-Handling for Linux"][1], September 1, 1995, by Eric S. Raymond.] - -Creating programs that use curses is actually quite simple. In this article, I show an example program that leverages curses to draw to the terminal screen. - -### Sierpinski's Triangle - -One simple way to demonstrate a few curses functions is by generating Sierpinski's Triangle. If you aren't familiar with this method to generate Sierpinski's Triangle, here are the rules: - -1. Set three points that define a triangle. - -2. Randomly select a point anywhere (x,y). - -Then: - -1. Randomly select one of the triangle's points. - -2. Set the new x,y to be the midpoint between the previous x,y and the triangle point. - -3. Repeat. - -So with those instructions, I wrote this program to draw Sierpinski's Triangle to the terminal screen using the curses functions: - -``` - - 1 /* triangle.c */ - 2 - 3 #include - 4 #include - 5 - 6 #include "getrandom_int.h" - 7 - 8 #define ITERMAX 10000 - 9 - 10 int main(void) - 11 { - 12 long iter; - 13 int yi, xi; - 14 int y[3], x[3]; - 15 int index; - 16 int maxlines, maxcols; - 17 - 18 /* initialize curses */ - 19 - 20 initscr(); - 21 cbreak(); - 22 noecho(); - 23 - 24 clear(); - 25 - 26 /* initialize triangle */ - 27 - 28 maxlines = LINES - 1; - 29 maxcols = COLS - 1; - 30 - 31 y[0] = 0; - 32 x[0] = 0; - 33 - 34 y[1] = maxlines; - 35 x[1] = maxcols / 2; - 36 - 37 y[2] = 0; - 38 x[2] = maxcols; - 39 - 40 mvaddch(y[0], x[0], '0'); - 41 mvaddch(y[1], x[1], '1'); - 42 mvaddch(y[2], x[2], '2'); - 43 - 44 /* initialize yi,xi with random values */ - 45 - 46 yi = getrandom_int() % maxlines; - 47 xi = getrandom_int() % maxcols; - 48 - 49 mvaddch(yi, xi, '.'); - 50 - 51 /* iterate the triangle */ - 52 - 53 for (iter = 0; iter < ITERMAX; iter++) { - 54 index = getrandom_int() % 3; - 55 - 56 yi = (yi + y[index]) / 2; - 57 xi = (xi + x[index]) / 2; - 58 - 59 mvaddch(yi, xi, '*'); - 60 refresh(); - 61 } - 62 - 63 /* done */ - 64 - 65 mvaddstr(maxlines, 0, "Press any key to quit"); - 66 - 67 refresh(); - 68 - 69 getch(); - 70 endwin(); - 71 - 72 exit(0); - 73 } - -``` - -Let me walk through that program by way of explanation. First, the getrandom_int() is my own wrapper to the Linux getrandom() system call, but it's guaranteed to return a positive integer value. Otherwise, you should be able to identify the code lines that initialize and then iterate Sierpinski's Triangle, based on the above rules. Aside from that, let's look at the curses functions I used to draw the triangle on a terminal. - -Most curses programs will start with these four instructions. 1) The initscr() function determines the terminal type, including its size and features, and sets up the curses environment based on what the terminal can support. The cbreak() function disables line buffering and sets curses to take one character at a time. The noecho() function tells curses not to echo the input back to the screen, and the clear() function clears the screen: - -``` - - 20 initscr(); - 21 cbreak(); - 22 noecho(); - 23 - 24 clear(); - -``` - -The program then sets a few variables to define the three points that define a triangle. Note the use of LINES and COLS here, which were set by initscr(). These values tell the program how many lines and columns exist on the terminal. Screen coordinates start at zero, so the top-left of the screen is row 0, column 0\. The bottom-right of the screen is row LINES - 1, column COLS - 1\. To make this easy to remember, my program sets these values in the variables maxlines and maxcols, respectively. - -Two simple methods to draw text on the screen are the addch() and addstr() functions. To put text at a specific screen location, use the related mvaddch() and mvaddstr() functions. My program uses these functions in several places. First, the program draws the three points that define the triangle, labeled "0", "1" and "2": - -``` - - 40 mvaddch(y[0], x[0], '0'); - 41 mvaddch(y[1], x[1], '1'); - 42 mvaddch(y[2], x[2], '2'); - -``` - -To draw the random starting point, the program makes a similar call: - -``` - - 49 mvaddch(yi, xi, '.'); - -``` - -And to draw each successive point in Sierpinski's Triangle iteration: - -``` - - 59 mvaddch(yi, xi, '*'); - -``` - -When the program is done, it displays a helpful message at the lower-left corner of the screen (at row maxlines, column 0): - -``` - - 65 mvaddstr(maxlines, 0, "Press any key to quit"); - -``` - -It's important to note that curses maintains a version of the screen in memory and updates the screen only when you ask it to. This provides greater performance, especially if you want to display a lot of text to the screen. This is because curses can update only those parts of the screen that changed since the last update. To cause curses to update the terminal screen, use the refresh() function. - -In my example program, I've chosen to update the screen after "drawing" each successive point in Sierpinski's Triangle. By doing so, users should be able to observe each iteration in the triangle. - -Before exiting, I use the getch() function to wait for the user to press a key. Then I call endwin() to exit the curses environment and return the terminal screen to normal control: - -``` - - 69 getch(); - 70 endwin(); - -``` - -### Compiling and Sample Output - -Now that you have your first sample curses program, it's time to compile and run it. Remember that Linux systems implement the curses functionality via the ncurses library, so you need to link with -lncurses when you compile—for example: - -``` - -$ ls -getrandom_int.c getrandom_int.h triangle.c - -$ gcc -Wall -lncurses -o triangle triangle.c getrandom_int.c - -``` - -Running the triangle program on a standard 80x24 terminal is not very interesting. You just can't see much detail in Sierpinski's Triangle at that resolution. If you run a terminal window and set a very small font size, you can see the fractal nature of Sierpinski's Triangle more easily. On my system, the output looks like Figure 1. - -![](http://www.linuxjournal.com/files/linuxjournal.com/ufiles/imagecache/large-550px-centered/u1000009/triangle.png) - -Figure 1. Output of the triangle Program - -Despite the random nature of the iteration, every run of Sierpinski's Triangle will look pretty much the same. The only difference will be where the first few points are drawn to the screen. In this example, you can see the single dot that starts the triangle, near point 1\. It looks like the program picked point 2 next, and you can see the asterisk halfway between the dot and the "2". And it looks like the program randomly picked point 2 for the next random number, because you can see the asterisk halfway between the first asterisk and the "2". From there, it's impossible to tell how the triangle was drawn, because all of the successive dots fall within the triangle area. - -### Starting to Learn ncurses - -This program is a simple example of how to use the curses functions to draw characters to the screen. You can do so much more with curses, depending on what you need your program to do. In a follow up article, I will show how to use curses to allow the user to interact with the screen. If you are interested in getting a head start with curses, I encourage you to read Pradeep Padala's ["NCURSES Programming HOWTO"][2], at the Linux Documentation Project. - -### About the author - -Jim Hall is an advocate for free and open-source software, best known for his work on the FreeDOS Project, and he also focuses on the usability of open-source software. Jim is the Chief Information Officer at Ramsey County, Minn. - --------------------------------------------------------------------------------- - -via: http://www.linuxjournal.com/content/getting-started-ncurses - -作者:[Jim Hall][a] -译者:[译者ID](https://github.com/译者ID) -校对:[校对者ID](https://github.com/校对者ID) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 - -[a]:http://www.linuxjournal.com/users/jim-hall -[1]:http://www.linuxjournal.com/article/1124 -[2]:http://tldp.org/HOWTO/NCURSES-Programming-HOWTO diff --git a/sources/tech/20180118 Rediscovering make- the power behind rules.md b/sources/tech/20180118 Rediscovering make- the power behind rules.md index 2dbddb8949..ea500a2689 100644 --- a/sources/tech/20180118 Rediscovering make- the power behind rules.md +++ b/sources/tech/20180118 Rediscovering make- the power behind rules.md @@ -1,3 +1,5 @@ +Translating by cncuckoo + Rediscovering make: the power behind rules ====== diff --git a/sources/talk/20180119 5 of the Best Linux Dark Themes that Are Easy on the Eyes.md b/sources/tech/20180119 5 of the Best Linux Dark Themes that Are Easy on the Eyes.md similarity index 100% rename from sources/talk/20180119 5 of the Best Linux Dark Themes that Are Easy on the Eyes.md rename to sources/tech/20180119 5 of the Best Linux Dark Themes that Are Easy on the Eyes.md diff --git a/sources/tech/20180119 How to Install Tripwire IDS Intrusion Detection System on Linux.md b/sources/tech/20180119 How to Install Tripwire IDS Intrusion Detection System on Linux.md new file mode 100644 index 0000000000..fb994b7f54 --- /dev/null +++ b/sources/tech/20180119 How to Install Tripwire IDS Intrusion Detection System on Linux.md @@ -0,0 +1,102 @@ +How to Install Tripwire IDS (Intrusion Detection System) on Linux +============================================================ + + +Tripwire is a popular Linux Intrusion Detection System (IDS) that runs on systems in order to detect if unauthorized filesystem changes occurred over time. + +In CentOS and RHEL distributions, tripwire is not a part of official repositories. However, the tripwire package can be installed via [Epel repositories][1]. + +To begin, first install Epel repositories in CentOS and RHEL system, by issuing the below command. + +``` +# yum install epel-release +``` + +After you’ve installed Epel repositories, make sure you update the system with the following command. + +``` +# yum update +``` + +After the update process finishes, install Tripwire IDS software by executing the below command. + +``` +# yum install tripwire +``` + +Fortunately, tripwire is a part of Ubuntu and Debian default repositories and can be installed with following commands. + +``` +$ sudo apt update +$ sudo apt install tripwire +``` + +On Ubuntu and Debian, the tripwire installation will be asked to choose and confirm a site key and local key passphrase. These keys are used by tripwire to secure its configuration files. + + [![Create Tripwire Site and Local Key](https://www.tecmint.com/wp-content/uploads/2018/01/Create-Site-and-Local-key.png)][2] + +Create Tripwire Site and Local Key + +On CentOS and RHEL, you need to create tripwire keys with the below command and supply a passphrase for site key and local key. + +``` +# tripwire-setup-keyfiles +``` + [![Create Tripwire Keys](https://www.tecmint.com/wp-content/uploads/2018/01/Create-Tripwire-Keys.png)][3] + +Create Tripwire Keys + +In order to validate your system, you need to initialize Tripwire database with the following command. Due to the fact that the database hasn’t been initialized yet, tripwire will display a lot of false-positive warnings. + +``` +# tripwire --init +``` + [![Initialize Tripwire Database](https://www.tecmint.com/wp-content/uploads/2018/01/Initialize-Tripwire-Database.png)][4] + +Initialize Tripwire Database + +Finally, generate a tripwire system report in order to check the configurations by issuing the below command. Use `--help` switch to list all tripwire check command options. + +``` +# tripwire --check --help +# tripwire --check +``` + +After tripwire check command completes, review the report by opening the file with the extension `.twr` from /var/lib/tripwire/report/ directory with your favorite text editor command, but before that you need to convert to text file. + +``` +# twprint --print-report --twrfile /var/lib/tripwire/report/tecmint-20170727-235255.twr > report.txt +# vi report.txt +``` + [![Tripwire System Report](https://www.tecmint.com/wp-content/uploads/2018/01/Tripwire-System-Report.png)][5] + +Tripwire System Report + +That’s It! you have successfully installed Tripwire on Linux server. I hope you can now easily configure your [Tripwire IDS][6]. + +-------------------------------------------------------------------------------- + +作者简介: + +I'am a computer addicted guy, a fan of open source and linux based system software, have about 4 years experience with Linux distributions desktop, servers and bash scripting. + +------- + +via: https://www.tecmint.com/install-tripwire-ids-intrusion-detection-system-on-linux/ + +作者:[ Matei Cezar][a] +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.tecmint.com/author/cezarmatei/ +[1]:https://www.tecmint.com/how-to-enable-epel-repository-for-rhel-centos-6-5/ +[2]:https://www.tecmint.com/wp-content/uploads/2018/01/Create-Site-and-Local-key.png +[3]:https://www.tecmint.com/wp-content/uploads/2018/01/Create-Tripwire-Keys.png +[4]:https://www.tecmint.com/wp-content/uploads/2018/01/Initialize-Tripwire-Database.png +[5]:https://www.tecmint.com/wp-content/uploads/2018/01/Tripwire-System-Report.png +[6]:https://www.tripwire.com/ +[7]:https://www.tecmint.com/author/cezarmatei/ +[8]:https://www.tecmint.com/10-useful-free-linux-ebooks-for-newbies-and-administrators/ +[9]:https://www.tecmint.com/free-linux-shell-scripting-books/ \ No newline at end of file diff --git a/sources/tech/20180119 How to install Spotify application on Linux.md b/sources/tech/20180119 How to install Spotify application on Linux.md deleted file mode 100644 index 3050e36199..0000000000 --- a/sources/tech/20180119 How to install Spotify application on Linux.md +++ /dev/null @@ -1,103 +0,0 @@ -translating---geekpi - -How to install Spotify application on Linux -====== - -How do I install Spotify app on Ubuntu Linux desktop to stream music? - -Spotify is a digital music stream service that provides you access to tons of songs. You can stream for free or buy a subscription. Creating a playlist is possible. A subscriber can listen music ad-free. You get better sound quality. This page **shows how to install Spotify on Linux using a snap package manager that works on Ubuntu, Mint, Debian, Fedora, Arch and many other distros**. - -### Installing spotify application on Linux - -The procedure to install spotify on Linux is as follows: - -1. Install snapd -2. Turn on snapd -3. Find Spotify snap: -``` -snap find spotify -``` -4. Install spotify music app: -``` -do snap install spotify -``` -5. Run it: -``` -spotify & -``` - -Let us see all steps and examples in details. - -### Step 1 - Install Snapd - -You need to install snapd package. It is daemon (service) and tooling that enable snap packages on Linux operating system. - -#### Snapd on a Debian/Ubuntu/Mint Linux - -Type the following [apt command][1]/[apt-get command][2] as follows: -`$ sudo apt install snapd` - -#### Install snapd on an Arch Linux - -snapd is available in the Arch User Repository (AUR) only. Run yaourt command (see [how to install yaourt on Archlinux][3]): -``` -$ sudo yaourt -S snapd -$ sudo systemctl enable --now snapd.socket -``` - -#### Get snapd on a Fedora Linux - -Run snapd command -``` -sudo dnf install snapd -sudo ln -s /var/lib/snapd/snap /snap -``` - -#### OpenSUSE install snapd - -Execute the snap command: -`$ snap find spotify` -[![snap search for spotify app command][4]][4] -Install it: -`$ sudo snap install spotify` -[![How to install Spotify application on Linux using snap command][5]][5] - -### Step 3 - Run spotify and enjoy it(译注:原博客中就是这么直接跳到step3的) - -Run it from GUI or simply type: -`$ spotify` -Automatically sign in to your account on startup: -``` -$ spotify --username vivek@nixcraft.com -$ spotify --username vivek@nixcraft.com --password 'myPasswordHere' -``` -Start spotify client with given URI when initialized: -`$ spotify--uri=` -Start with the specified URL: -`$ spotify--url=` -[![Spotify client app running on my Ubuntu Linux desktop][6]][6] - -### 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][7], [Facebook][8], [Google+][9]. - --------------------------------------------------------------------------------- - -via: https://www.cyberciti.biz/faq/how-to-install-spotify-application-on-linux/ - -作者:[Vivek Gite][a] -译者:[译者ID](https://github.com/译者ID) -校对:[校对者ID](https://github.com/校对者ID) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 - -[a]:https://www.cyberciti.biz -[1]:https://www.cyberciti.biz/faq/ubuntu-lts-debian-linux-apt-command-examples/ (See Linux/Unix apt command examples for more info) -[2]:https://www.cyberciti.biz/tips/linux-debian-package-management-cheat-sheet.html (See Linux/Unix apt-get command examples for more info) -[3]:https://www.cyberciti.biz/faq/how-to-install-yaourt-in-arch-linux/ -[4]:https://www.cyberciti.biz/media/new/faq/2018/01/snap-search-for-spotify-app-command.jpg -[5]:https://www.cyberciti.biz/media/new/faq/2018/01/How-to-install-Spotify-application-on-Linux-using-snap-command.jpg -[6]:https://www.cyberciti.biz/media/new/faq/2018/01/Spotify-client-app-running-on-my-Ubuntu-Linux-desktop.jpg -[7]:https://twitter.com/nixcraft -[8]:https://facebook.com/nixcraft -[9]:https://plus.google.com/+CybercitiBiz diff --git a/sources/tech/20180119 Linux mv Command Explained for Beginners (8 Examples).md b/sources/tech/20180119 Linux mv Command Explained for Beginners (8 Examples).md index 786528137f..78cf02f4a9 100644 --- a/sources/tech/20180119 Linux mv Command Explained for Beginners (8 Examples).md +++ b/sources/tech/20180119 Linux mv Command Explained for Beginners (8 Examples).md @@ -1,3 +1,5 @@ +translating by cncuckoo + Linux mv Command Explained for Beginners (8 Examples) ====== diff --git a/sources/talk/20180119 PlayOnLinux For Easier Use Of Wine.md b/sources/tech/20180119 PlayOnLinux For Easier Use Of Wine.md similarity index 100% rename from sources/talk/20180119 PlayOnLinux For Easier Use Of Wine.md rename to sources/tech/20180119 PlayOnLinux For Easier Use Of Wine.md diff --git a/sources/tech/20180120 The World Map In Your Terminal.md b/sources/tech/20180120 The World Map In Your Terminal.md deleted file mode 100644 index edc23edf12..0000000000 --- a/sources/tech/20180120 The World Map In Your Terminal.md +++ /dev/null @@ -1,112 +0,0 @@ -translating---geekpi - -The World Map In Your Terminal -====== -I just stumbled upon an interesting utility. The World map in the Terminal! Yes, It is so cool. Say hello to **MapSCII** , a Braille and ASCII world map renderer for your xterm-compatible terminals. It supports GNU/Linux, Mac OS, and Windows. I thought it is a just another project hosted on GitHub. But I was wrong! It is really impressive what they did there. We can use our mouse pointer to drag and zoom in and out a location anywhere in the world map. The other notable features are; - - * Discover Point-of-Interests around any given location - * Highly customizable layer styling with [Mapbox Styles][1] support - * Connect to any public or private vector tile server - * Or just use the supplied and optimized [OSM2VectorTiles][2] based one - * Work offline and discover local [VectorTile][3]/[MBTiles][4] - * Compatible with most Linux and OSX terminals - * Highly optimizied algorithms for a smooth experience - - - -### Displaying the World Map in your Terminal using MapSCII - -To open the map, just run the following command from your Terminal: -``` -telnet mapscii.me -``` - -Here is the World map from my Terminal. - -[![][5]][6] - -Cool, yeah? - -To switch to Braille view, press **c**. - -[![][5]][7] - -Type **c** again to switch back to the previous format **.** - -To scroll around the map, use arrow keys **up** , **down** , **left** , **right**. To zoom in/out a location, use **a** and **z** keys. Also, you can use the scroll wheel of your mouse to zoom in or out. To quit the map, press **q**. - -Like I already said, don't think it is a simple project. Click on any location on the map and press **" a"** to zoom in. - -Here are some the sample screenshots after I zoomed it. - -[![][5]][8] - -I can be able to zoom to view the states in my country (India). - -[![][5]][9] - -And the districts in a state (Tamilnadu): - -[![][5]][10] - -Even the [Taluks][11] and the towns in a district: - -[![][5]][12] - -And, the place where I completed my schooling: - -[![][5]][13] - -Even though it is just a smallest town, MapSCII displayed it accurately. MapSCII uses [**OpenStreetMap**][14] to collect the data. - -### Install MapSCII locally - -Liked it? Great! You can host it on your own system. - -Make sure you have installed Node.js on your system. If not, refer the following link. - -[Install NodeJS on Linux][15] - -Then, run the following command to install it. -``` -sudo npm install -g mapscii - -``` - -To launch MapSCII, run: -``` -mapscii -``` - -Have fun! More good stuffs to come. Stay tuned! - -Cheers! - - - --------------------------------------------------------------------------------- - -via: https://www.ostechnix.com/mapscii-world-map-terminal/ - -作者:[SK][a] -译者:[译者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.mapbox.com/mapbox-gl-style-spec/ -[2]:https://github.com/osm2vectortiles -[3]:https://github.com/mapbox/vector-tile-spec -[4]:https://github.com/mapbox/mbtiles-spec -[5]:data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7 -[6]:http://www.ostechnix.com/wp-content/uploads/2018/01/MapSCII-1-2.png () -[7]:http://www.ostechnix.com/wp-content/uploads/2018/01/MapSCII-2.png () -[8]:http://www.ostechnix.com/wp-content/uploads/2018/01/MapSCII-3.png () -[9]:http://www.ostechnix.com/wp-content/uploads/2018/01/MapSCII-4.png () -[10]:http://www.ostechnix.com/wp-content/uploads/2018/01/MapSCII-5.png () -[11]:https://en.wikipedia.org/wiki/Tehsils_of_India -[12]:http://www.ostechnix.com/wp-content/uploads/2018/01/MapSCII-6.png () -[13]:http://www.ostechnix.com/wp-content/uploads/2018/01/MapSCII-7.png () -[14]:https://www.openstreetmap.org/ -[15]:https://www.ostechnix.com/install-node-js-linux/ diff --git a/sources/tech/20180121 Shell Scripting a Bunco Game.md b/sources/tech/20180121 Shell Scripting a Bunco Game.md deleted file mode 100644 index 4d5113ec74..0000000000 --- a/sources/tech/20180121 Shell Scripting a Bunco Game.md +++ /dev/null @@ -1,235 +0,0 @@ -translating by wenwensnow -Shell Scripting a Bunco Game -====== -I haven't dug into any game programming for a while, so I thought it was high time to do something in that realm. At first, I thought "Halo as a shell script?", but then I came to my senses. Instead, let's look at a simple dice game called Bunco. You may not have heard of it, but I bet your Mom has—it's a quite popular game for groups of gals at a local pub or tavern. - -Played in six rounds with three dice, the game is simple. You roll all three dice and have to match the current round number. If all three dice match the current round number (for example, three 3s in round three), you score 21\. If all three match but aren't the current round number, it's a Mini Bunco and worth five points. Failing both of those, each die with the same value as the round number is worth one point. - -Played properly, the game also involves teams, multiple tables including a winner's table, and usually cash prizes funded by everyone paying $5 or similar to play and based on specific winning scenarios like "most Buncos" or "most points". I'll skip that part here, however, and just focus on the dice part. - -### Let's Do the Math - -Before I go too far into the programming side of things, let me talk briefly about the math behind the game. Dice are easy to work with because on a properly weighted die, the chance of a particular value coming up is 1:6. - -Random tip: not sure whether your dice are balanced? Toss them in salty water and spin them. There are some really interesting YouTube videos from the D&D world showing how to do this test. - -So what are the odds of three dice having the same value? The first die has a 100% chance of having a value (no leaners here), so that's easy. The second die has a 16.66% chance of being any particular value, and then the third die has the same chance of being that value, but of course, they multiply, so three dice have about a 2.7% chance of all having the same value. - -Then, it's a 16.66% chance that those three dice would be the current round's number—or, in mathematical terms: 0.166 * 0.166 * 0.166 = 0.00462. - -In other words, you have a 0.46% chance of rolling a Bunco, which is a bit less than once out of every 200 rolls of three dice. - -It could be tougher though. If you were playing with five dice, the chance of rolling a Mini Bunco (or Yahtzee) is 0.077%, and if you were trying to accomplish a specific value, say just sixes, then it's 0.00012% likely on any given roll—which is to say, not bloody likely! - -### And So into the Coding - -As with every game, the hardest part is really having a good random number generator that generates truly random values. That's actually hard to affect in a shell script though, so I'm going to sidestep this entire issue and assume that the shell's built-in random number generator will be sufficient. - -What's nice is that it's super easy to work with. Just reference $RANDOM, and you'll have a random value between 0 and MAXINT (32767): - -``` - -$ echo $RANDOM $RANDOM $RANDOM -10252 22142 14863 - -``` - -To constrain that to values between 1–6 use the modulus function: - -``` - -$ echo $(( $RANDOM % 6 )) -3 -$ echo $(( $RANDOM % 6 )) -0 - -``` - -Oops! I forgot to shift it one. Here's another try: - -``` - -$ echo $(( ( $RANDOM % 6 ) + 1 )) -6 - -``` - -That's the dice-rolling feature. Let's make it a function where you can specify the variable you'd like to have the generated value as part of the invocation: - -``` - -rolldie() -{ - local result=$1 - rolled=$(( ( $RANDOM % 6 ) + 1 )) - eval $result=$rolled -} - -``` - -The use of the eval is to ensure that the variable specified in the invocation is actually assigned the calculated value. It's easy to work with: - -``` - -rolldie die1 - -``` - -That will load a random value between 1–6 into the variable die1. To roll your three dice, it's straightforward: - -``` - -rolldie die1 ; rolldie die2 ; rolldie die3 - -``` - -Now to test the values. First, let's test for a Bunco where all three dice have the same value, and it's the value of the current round too: - -``` - -if [ $die1 -eq $die2 ] && [ $die2 -eq $die3 ] ; then - if [ $die1 -eq $round ] ; then - echo "BUNCO!" - score=25 - else - echo "Mini Bunco!" - score=5 - fi - -``` - -That's probably the hardest of the tests, and notice the unusual use of test in the first conditional: [ cond1 ] && [ cond2 ]. If you're thinking that you could also write it as cond1 -a cond2, you're right. As with so much in the shell, there's more than one way to get to the solution. - -The remainder of the code is straightforward; you just need to test for whether the die matches the current round value: - -``` - -if [ $die1 -eq $round ] ; then - score=1 -fi -if [ $die2 -eq $round ] ; then - score=$(( $score + 1 )) -fi -if [ $die3 -eq $round ] ; then - score=$(( $score + 1 )) -fi - -``` - -The only thing to consider here is that you don't want to score die value vs. round if you've also scored a Bunco or Mini Bunco, so the entire second set of tests needs to be within the else clause of the first conditional (to see if all three dice have the same value). - -Put it together and specify the round number on the command line, and here's what you have at this point: - -``` - -$ sh bunco.sh 5 -You rolled: 1 1 5 -score = 1 -$ sh bunco.sh 2 -You rolled: 6 4 3 -score = 0 -$ sh bunco.sh 1 -You rolled: 1 1 1 -BUNCO! -score = 25 - -``` - -A Bunco so quickly? Well, as I said, there might be a slight issue with the randomness of the random number generator in the shell. - -You can test it once you have the script working by running it a few hundred times and then checking to see what percentage are Bunco or Mini Bunco, but I'll leave that as an exercise for you, dear reader. Well, maybe I'll come back to it another time. - -Let's finish up this script by having it accumulate score and run for all six rounds instead of specifying a round on the command line. That's easily done, because it's just a wrapper around the entire script, or, better, the big conditional statement becomes a function all its own: - -``` - -BuncoRound() -{ - # roll, display, and score a round of bunco! - # round is specified when invoked, score added to totalscore - - local score=0 ; local round=$1 ; local hidescore=0 - - rolldie die1 ; rolldie die2 ; rolldie die3 - echo Round $round. You rolled: $die1 $die2 $die3 - - if [ $die1 -eq $die2 ] && [ $die2 -eq $die3 ] ; then - if [ $die1 -eq $round ] ; then - echo " BUNCO!" - score=25 - hidescore=1 - else - echo " Mini Bunco!" - score=5 - hidescore=1 - fi - else - if [ $die1 -eq $round ] ; then - score=1 - fi - if [ $die2 -eq $round ] ; then - score=$(( $score + 1 )) - fi - if [ $die3 -eq $round ] ; then - score=$(( $score + 1 )) - fi - fi - - if [ $hidescore -eq 0 ] ; then - echo " score this round: $score" - fi - - totalscore=$(( $totalscore + $score )) -} - -``` - -I admit, I couldn't resist a few improvements as I went along, including the addition of it showing either Bunco, Mini Bunco or a score value (that's what $hidescore does). - -Invoking it is a breeze, and you'll use a for loop: - -``` - -for round in {1..6} ; do - BuncoRound $round -done - -``` - -That's about the entire program at this point. Let's run it once and see what happens: - -``` - -$ sh bunco.sh 1 -Round 1\. You rolled: 2 3 3 - score this round: 0 -Round 2\. You rolled: 2 6 6 - score this round: 1 -Round 3\. You rolled: 1 2 4 - score this round: 0 -Round 4\. You rolled: 2 1 4 - score this round: 1 -Round 5\. You rolled: 5 5 6 - score this round: 2 -Round 6\. You rolled: 2 1 3 - score this round: 0 -Game over. Your total score was 4 - -``` - -Ugh. Not too impressive, but it's probably a typical round. Again, you can run it a few hundred—or thousand—times, just save the "Game over" line, then do some quick statistical analysis to see how often you score more than 3 points in six rounds. (With three dice to roll a given value, you should hit that 50% of the time.) - -It's not a complicated game by any means, but it makes for an interesting little programming project. Now, what if they used 20-sided die and let you re-roll one die per round and had a dozen rounds? - - --------------------------------------------------------------------------------- - -via: http://www.linuxjournal.com/content/shell-scripting-bunco-game - -作者:[Dave Taylor][a] -译者:[译者ID](https://github.com/译者ID) -校对:[校对者ID](https://github.com/校对者ID) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 - -[a]:http://www.linuxjournal.com/users/dave-taylor diff --git a/sources/talk/20180122 An overview of the Perl 5 engine.md b/sources/tech/20180122 An overview of the Perl 5 engine.md similarity index 100% rename from sources/talk/20180122 An overview of the Perl 5 engine.md rename to sources/tech/20180122 An overview of the Perl 5 engine.md diff --git a/sources/tech/20180122 How to Create a Docker Image.md b/sources/tech/20180122 How to Create a Docker Image.md deleted file mode 100644 index 4894085a8f..0000000000 --- a/sources/tech/20180122 How to Create a Docker Image.md +++ /dev/null @@ -1,197 +0,0 @@ -How to Create a Docker Image -====== - -![](https://www.linux.com/sites/lcom/files/styles/rendered_file/public/container-image_0.jpg?itok=G_Gz80R9) - -In the previous [article][1], we learned about how to get started with Docker on Linux, macOS, and Windows. In this article, we will get a basic understanding of creating Docker images. There are prebuilt images available on DockerHub that you can use for your own project, and you can publish your own image there. - -We are going to use prebuilt images to get the base Linux subsystem, as it's a lot of work to build one from scratch. You can get Alpine (the official distro used by Docker Editions), Ubuntu, BusyBox, or scratch. In this example, I will use Ubuntu. - -Before we start building our images, let's "containerize" them! By this I just mean creating directories for all of your Docker images so that you can maintain different projects and stages isolated from each other. -``` -$ mkdir dockerprojects - -cd dockerprojects - -``` - -Now create a Dockerfile inside the dockerprojects directory using your favorite text editor; I prefer nano, which is also easy for new users. -``` -$ nano Dockerfile - -``` - -And add this line: -``` -FROM Ubuntu - -``` - -![m7_f7No0pmZr2iQmEOH5_ID6MDG2oEnODpQZkUL7][2] - -Save it with Ctrl+Exit then Y. - -Now create your new image and provide it with a name (run these commands within the same directory): -``` -$ docker build -t dockp . - -``` - -(Note the dot at the end of the command.) This should build successfully, so you'll see: -``` -Sending build context to Docker daemon 2.048kB - -Step 1/1 : FROM ubuntu - ----> 2a4cca5ac898 - -Successfully built 2a4cca5ac898 - -Successfully tagged dockp:latest - -``` - -It's time to run and test your image: -``` -$ docker run -it Ubuntu - -``` - -You should see root prompt: -``` -root@c06fcd6af0e8:/# - -``` - -This means you are literally running bare minimal Ubuntu inside Linux, Windows, or macOS. You can run all native Ubuntu commands and CLI utilities. - -![vpZ8ts9oq3uk--z4n6KP3DD3uD_P4EpG7fX06MC3][3] - -Let's check all the Docker images you have in your directory: -``` -$docker images - - -REPOSITORY TAG IMAGE ID CREATED SIZE - -dockp latest 2a4cca5ac898 1 hour ago 111MB - -ubuntu latest 2a4cca5ac898 1 hour ago 111MB - -hello-world latest f2a91732366c 8 weeks ago 1.85kB - -``` - -You can see all three images: dockp, Ubuntu, and hello-world, which I created a few weeks ago when working on the previous articles of this series. Building a whole LAMP stack can be challenging, so we are going create a simple Apache server image with Dockerfile. - -Dockerfile is basically a set of instructions to install all the needed packages, configure, and copy files. In this case, it's Apache and Nginx. - -You may also want to create an account on DockerHub and log into your account before building images, in case you are pulling something from DockerHub. To log into DockerHub from the command line, just run: -``` -$ docker login - -``` - -Enter your username and password and you are logged in. - -Next, create a directory for Apache inside the dockerproject: -``` -$ mkdir apache - -``` - -Create a Dockerfile inside Apache folder: -``` -$ nano Dockerfile - -``` - -And paste these lines: -``` -FROM ubuntu - -MAINTAINER Kimbro Staken version: 0.1 - -RUN apt-get update && apt-get install -y apache2 && apt-get clean && rm -rf /var/lib/apt/lists/* - - -ENV APACHE_RUN_USER www-data - -ENV APACHE_RUN_GROUP www-data - -ENV APACHE_LOG_DIR /var/log/apache2 - - -EXPOSE 80 - - -CMD ["/usr/sbin/apache2", "-D", "FOREGROUND"] - -``` - -Then, build the image: -``` -docker build -t apache . - -``` - -(Note the dot after a space at the end.) - -It will take some time, then you should see successful build like this: -``` -Successfully built e7083fd898c7 - -Successfully tagged ng:latest - -Swapnil:apache swapnil$ - -``` - -Now let's run the server: -``` -$ docker run -d apache - -a189a4db0f7c245dd6c934ef7164f3ddde09e1f3018b5b90350df8be85c8dc98 - -``` - -Eureka. Your container image is running. Check all the running containers: -``` -$ docker ps - -CONTAINER ID IMAGE COMMAND CREATED - -a189a4db0f7 apache "/usr/sbin/apache2ctl" 10 seconds ago - -``` - -You can kill the container with the docker kill command: -``` -$docker kill a189a4db0f7 - -``` - -So, you see the "image" itself is persistent that stays in your directory, but the container runs and goes away. Now you can create as many images as you want and spin and nuke as many containers as you need from those images. - -That's how to create an image and run containers. - -To learn more, you can open your web browser and check out the documentation about how to build more complicated Docker images like the whole LAMP stack. Here is a[ Dockerfile][4] file for you to play with. In the next article, I'll show how to push images to DockerHub. - -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/intro-to-linux/2018/1/how-create-docker-image - -作者:[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/blog/learn/intro-to-linux/how-install-docker-ce-your-desktop -[2]:https://lh6.googleusercontent.com/m7_f7No0pmZr2iQmEOH5_ID6MDG2oEnODpQZkUL7q3GYRB9f1-lvMYLE5f3GBpzIk-ev5VlcB0FHYSxn6NNQjxY4jJGqcgdFWaeQ-027qX_g-SVtbCCMybJeD6QIXjzM2ga8M4l4 -[3]:https://lh3.googleusercontent.com/vpZ8ts9oq3uk--z4n6KP3DD3uD_P4EpG7fX06MC3uFvj2-WaI1DfOfec9ZXuN7XUNObQ2SCc4Nbiqp-CM7ozUcQmtuzmOdtUHTF4Jq8YxkC49o2k7y5snZqTXsueITZyaLiHq8bT -[4]:https://github.com/fauria/docker-lamp/blob/master/Dockerfile -[5]:https://training.linuxfoundation.org/linux-courses/system-administration-training/introduction-to-linux diff --git a/sources/talk/20180122 Ick- a continuous integration system.md b/sources/tech/20180122 Ick- a continuous integration system.md similarity index 100% rename from sources/talk/20180122 Ick- a continuous integration system.md rename to sources/tech/20180122 Ick- a continuous integration system.md diff --git a/sources/tech/20180122 Linux rm Command Explained for Beginners (8 Examples).md b/sources/tech/20180122 Linux rm Command Explained for Beginners (8 Examples).md deleted file mode 100644 index 5ba87a1b7e..0000000000 --- a/sources/tech/20180122 Linux rm Command Explained for Beginners (8 Examples).md +++ /dev/null @@ -1,172 +0,0 @@ -Linux rm Command Explained for Beginners (8 Examples) -====== - -Deleting files is a fundamental operation, just like copying files or renaming/moving them. In Linux, there's a dedicated command - dubbed **rm** \- that lets you perform all deletion-related operations. In this tutorial, we will discuss the basics of this tool along with some easy to understand examples. - -But before we do that, it's worth mentioning that all examples mentioned in the article have been tested on Ubuntu 16.04 LTS. - -#### Linux rm command - -So in layman's terms, we can simply say the rm command is used for removing/deleting files and directories. Following is the syntax of the command: - -``` -rm [OPTION]... [FILE]... -``` - -And here's how the tool's man page describes it: -``` -This manual page documents the GNU version of rm. rm removes each specified file. By default, it -does not remove directories. - -If  the  -I or --interactive=once option is given, and there are more than three files or the -r, --R, or --recursive are given, then rm prompts the user for whether to proceed with the entire -operation. If the response is not affirmative, the entire command is aborted. - -Otherwise, if a file is unwritable, standard input is a terminal, and the -f or --force option is -not given, or the -i or --interactive=always option is given, rm prompts the user for whether to -remove the file. If the response is not affirmative, the file is skipped. -``` - -The following Q&A-styled examples will give you a better idea on how the tool works. - -#### Q1. How to remove files using rm command? - -That's pretty easy and straightforward. All you have to do is to pass the name of the files (along with paths if they are not in the current working directory) as input to the rm command. - -``` -rm [filename] -``` - -For example: - -``` -rm testfile.txt -``` - -[![How to remove files using rm command][1]][2] - -#### Q2. How to remove directories using rm command? - -If you are trying to remove a directory, then you need to use the **-r** command line option. Otherwise, rm will throw an error saying what you are trying to delete is a directory. - -``` -rm -r [dir name] -``` - -For example: - -``` -rm -r testdir -``` - -[![How to remove directories using rm command][3]][4] - -#### Q3. How to make rm prompt before every removal? - -If you want rm to prompt before each delete action it performs, then use the **-i** command line option. - -``` -rm -i [file or dir] -``` - -For example, suppose you want to delete a directory 'testdir' and all its contents, but want rm to prompt before every deletion, then here's how you can do that: - -``` -rm -r -i testdir -``` - -[![How to make rm prompt before every removal][5]][6] - -#### Q4. How to force rm to ignore nonexistent files? - -The rm command lets you know through an error message if you try deleting a non-existent file or directory. - -[![Linux rm command example][7]][8] - -However, if you want, you can make rm suppress such error/notifications - all you have to do is to use the **-f** command line option. - -``` -rm -f [filename] -``` - -[![How to force rm to ignore nonexistent files][9]][10] - -#### Q5. How to make rm prompt only in some scenarios? - -There exists a command line option **-I** , which when used, makes sure the command only prompts once before removing more than three files, or when removing recursively. - -For example, the following screenshot shows this option in action - there was no prompt when two files were deleted, but the command prompted when more than three files were deleted. - -[![How to make rm prompt only in some scenarios][11]][12] - -#### Q6. How rm works when dealing with root directory? - -Of course, deleting root directory is the last thing a Linux user would want. That's why, the rm command doesn't let you perform a recursive delete operation on this directory by default. - -[![How rm works when dealing with root directory][13]][14] - -However, if you want to go ahead with this operation for whatever reason, then you need to tell this to rm by using the **\--no-preserve-root** option. When this option is enabled, rm doesn't treat the root directory (/) specially. - -In case you want to know the scenarios in which a user might want to delete the root directory of their system, head [here][15]. - -#### Q7. How to make rm only remove empty directories? - -In case you want to restrict rm's directory deletion ability to only empty directories, then you can use the -d command line option. - -``` -rm -d [dir] -``` - -The following screenshot shows the -d command line option in action - only empty directory got deleted. - -[![How to make rm only remove empty directories][16]][17] - -#### Q8. How to force rm to emit details of operation it is performing? - -If you want rm to display detailed information of the operation being performed, then this can be done by using the **-v** command line option. - -``` -rm -v [file or directory name] -``` - -For example: - -[![How to force rm to emit details of operation it is performing][18]][19] - -#### Conclusion - -Given the kind of functionality it offers, rm is one of the most frequently used commands in Linux (like [cp][20] and mv). Here, in this tutorial, we have covered almost all major command line options this tool provides. rm has a bit of learning curve associated with, so you'll have to spent some time practicing its options before you start using the tool in your day to day work. For more information, head to the command's [man page][21]. - - --------------------------------------------------------------------------------- - -via: https://www.howtoforge.com/linux-rm-command/ - -作者:[Himanshu Arora][a] -译者:[译者ID](https://github.com/译者ID) -校对:[校对者ID](https://github.com/校对者ID) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 - -[a]:https://www.howtoforge.com -[1]:https://www.howtoforge.com/images/command-tutorial/rm-basic-usage.png -[2]:https://www.howtoforge.com/images/command-tutorial/big/rm-basic-usage.png -[3]:https://www.howtoforge.com/images/command-tutorial/rm-r.png -[4]:https://www.howtoforge.com/images/command-tutorial/big/rm-r.png -[5]:https://www.howtoforge.com/images/command-tutorial/rm-i-option.png -[6]:https://www.howtoforge.com/images/command-tutorial/big/rm-i-option.png -[7]:https://www.howtoforge.com/images/command-tutorial/rm-non-ext-error.png -[8]:https://www.howtoforge.com/images/command-tutorial/big/rm-non-ext-error.png -[9]:https://www.howtoforge.com/images/command-tutorial/rm-f-option.png -[10]:https://www.howtoforge.com/images/command-tutorial/big/rm-f-option.png -[11]:https://www.howtoforge.com/images/command-tutorial/rm-I-option.png -[12]:https://www.howtoforge.com/images/command-tutorial/big/rm-I-option.png -[13]:https://www.howtoforge.com/images/command-tutorial/rm-root-default.png -[14]:https://www.howtoforge.com/images/command-tutorial/big/rm-root-default.png -[15]:https://superuser.com/questions/742334/is-there-a-scenario-where-rm-rf-no-preserve-root-is-needed -[16]:https://www.howtoforge.com/images/command-tutorial/rm-d-option.png -[17]:https://www.howtoforge.com/images/command-tutorial/big/rm-d-option.png -[18]:https://www.howtoforge.com/images/command-tutorial/rm-v-option.png -[19]:https://www.howtoforge.com/images/command-tutorial/big/rm-v-option.png -[20]:https://www.howtoforge.com/linux-cp-command/ -[21]:https://linux.die.net/man/1/rm diff --git a/sources/tech/20180123 Installing Awstat for analyzing Apache logs.md b/sources/tech/20180123 Installing Awstat for analyzing Apache logs.md new file mode 100644 index 0000000000..b635417a47 --- /dev/null +++ b/sources/tech/20180123 Installing Awstat for analyzing Apache logs.md @@ -0,0 +1,117 @@ +Installing Awstat for analyzing Apache logs +====== +AWSTAT is free an very powerful log analyser tool for apache log files. After analyzing logs from apache, it present them in easy to understand graphical format. Awstat is short for Advanced Web statistics & it works on command line interface or on CGI. + +In this tutorial, we will be installing AWSTAT on our Centos 7 machine for analyzing apache logs. + +( **Recommended read** :[ **Scheduling important jobs with crontab**][1]) + +### Pre-requisites + + **1-** A website hosted on apache web server, to create one read below mentioned tutorials on apache web servers, + +( **Recommended reads** - [**installing Apache**][2], [**Securing apache with SSL cert**][3] & **hardening tips for apache** ) + + **2-** Epel repository enabled on the system, as Awstat packages are not available on default repositories. To enable epel-repo , run + +``` +$ rpm -Uvh https://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-10.noarch.rpm +``` + +### Installing Awstat + +Once the epel-repository has been enabled on the system, awstat can be installed by running, + +``` + $ yum install awstat +``` + +When awstat is installed, it creates a file for apache at '/etc/httpd/conf.d/awstat.conf' with some configurations. These configurations are good to be used incase web server &awstat are configured on the same machine but if awstat is on different machine than the webserver, then some changes are to be made to the file. + +#### Configuring Apache for Awstat + +To configure awstat for a remote web server, open /etc/httpd/conf.d/awstat.conf, & update the parameter 'Allow from' with the IP address of the web server + +``` +$ vi /etc/httpd/conf.d/awstat.conf + + +Options None +AllowOverride None + +# Apache 2.4 +Require local + + +# Apache 2.2 +Order allow,deny +Allow from 127.0.0.1 +Allow from 192.168.1.100 + + +``` + +Save the file & restart the apache services to implement the changes, + +``` + $ systemctl restart httpd +``` + +#### Configuring AWSTAT + +For every website that we add to awstat, a different configuration file needs to be created with the website information . An example file is created in folder '/etc/awstats' by the name 'awstats.localhost.localdomain.conf', we can make copies of it & configure our website with this, + +``` +$ cd /etc/awstats +$ cp awstats.localhost.localdomain.conf awstats.linuxtechlab.com.conf +``` + +Now open the file & edit the following three parameters to match your website, + +``` +$ vi awstats.linuxtechlab.com.conf + +LogFile="/var/log/httpd/access.log" +SiteDomain="linuxtechlab.com" +HostAliases=www.linuxtechlab.com localhost 127.0.0.1 +``` + +Last step is to update the configuration file, which can be done executing the command below, + +``` +/usr/share/awstats/wwwroot/cgi-bin/awstats.pl -config=linuxtechlab.com -update +``` + +#### Checking the awstat page + +To test/check the awstat page, open web-browser & enter the following URL in the address bar, +**https://linuxtechlab.com/awstats/awstats.pl?config=linuxtechlab.com** + +![awstat][5] + +**Note-** we can also schedule a cron job to update the awstat on regular basis. An example for the crontab + +``` +$ crontab -e +0 1 * * * /usr/share/awstats/wwwroot/cgi-bin/awstats.pl -config=linuxtechlab.com–update +``` + +We now end our tutorial on installing Awstat for analyzing apache logs, please leave your comments/queries in the comment box below. + + +-------------------------------------------------------------------------------- + +via: http://linuxtechlab.com/installing-awstat-analyzing-apache-logs/ + +作者:[SHUSAIN][a] +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:http://linuxtechlab.com/author/shsuain/ +[1]:http://linuxtechlab.com/scheduling-important-jobs-crontab/ +[2]:http://linuxtechlab.com/beginner-guide-configure-apache/ +[3]:http://linuxtechlab.com/create-ssl-certificate-apache-server/ +[4]:https://i1.wp.com/linuxtechlab.com/wp-content/plugins/a3-lazy-load/assets/images/lazy_placeholder.gif?resize=602%2C312 +[5]:https://i0.wp.com/linuxtechlab.com/wp-content/uploads/2017/04/awstat.jpg?resize=602%2C312 diff --git a/sources/tech/20180123 What Is bashrc and Why Should You Edit It.md b/sources/tech/20180123 What Is bashrc and Why Should You Edit It.md deleted file mode 100644 index 93b8b5dc7f..0000000000 --- a/sources/tech/20180123 What Is bashrc and Why Should You Edit It.md +++ /dev/null @@ -1,108 +0,0 @@ -What Is bashrc and Why Should You Edit It -====== - -![](https://www.maketecheasier.com/assets/uploads/2018/01/what-is-bashrc-hero.png) - -There are a number of hidden files tucked away in your home directory. If you run macOS or a popular Linux distribution, you'll see a file named ".bashrc" up near the top of your hidden files. What is bashrc, and why is editing bashrc useful? - -![finder-find-bashrc][1] - -If you run a Unix-based or Unix-like operating system, you likely have bash installed as your default terminal. While many [different shells][2] exist, bash is both the most common and, likely, the most popular. If you don't know what that means, bash interprets your typed input in the Terminal program and runs commands based on your input. It allows for some degree of customization using scripting, which is where bashrc comes in. - -In order to load your preferences, bash runs the contents of the bashrc file at each launch. This shell script is found in each user's home directory. It's used to save and load your terminal preferences and environmental variables. - -Terminal preferences can contain a number of different things. Most commonly, the bashrc file contains aliases that the user always wants available. Aliases allow the user to refer to commands by shorter or alternative names, and can be a huge time-saver for those that work in a terminal regularly. - -![terminal-edit-bashrc-1][3] - -You can edit bashrc in any terminal text editor. We will use `nano` in the following examples. - -To edit bashrc using `nano`, invoke the following command in Terminal: -``` -nano ~/.bashrc -``` - -If you've never edited your bashrc file before, you might find that it's empty. That's fine! If not, you can feel free to put your additions on any line. - -Any changes you make to bashrc will be applied next time you launch terminal. If you want to apply them immediately, run the command below: -``` -source ~/.bashrc -``` - -You can add to bashrc where ever you like, but feel free to use command (proceeded by `#`) to organize your code. - -Edits in bashrc have to follow [bash's scripting format][4]. If you don't know how to script with bash, there are a number of resources you can use online. This guide represents a fairly [comprehensive introduction][5] into the aspects of bashrc that we couldn't mention here. - - **Related** : [How to Run Bash Script as Root During Startup on Linux][6] - -There's a couple of useful tricks you can do to make your terminal experience more efficient and user-friendly. - -### Why should I edit bashrc? - -#### Bash Prompt - -The bash prompt allows you to style up your terminal and have it to show prompts when you run a command. A customized bash prompt can indeed make your work on the terminal more productive and efficient. - -Check out some of the [useful][7] and [interesting][8] bash prompts you can add to your bashrc. - -#### Aliases - -![terminal-edit-bashrc-3][9] - -Aliases can also allow you to access a favored form of a command with a shorthand code. Let's take the command `ls` as an example. By default, `ls` displays the contents of your directory. That's useful, but it's often more useful to know more about the directory, or know the hidden contents of the directory. As such, a common alias is `ll`, which is set to run `ls -lha` or something similar. That will display the most details about files, revealing hidden files and showing file sizes in "human readable" units instead of blocks. - -You'll need to format your aliases like so: -``` -alias ll = "ls -lha" -``` - -Type the text you want to replace on the left, and the command on the right between quotes. You can use to this to create shorter versions of command, guard against common typos, or force a command to always run with your favored flags. You can also circumvent annoying or easy-to-forget syntax with your own preferred shorthand. Here are some of the [commonly used aliases][10] you can add to your bashrc. - -#### Functions - -![terminal-edit-bashrc-2][11] - -In addition to shorthand command names, you can combine multiple commands into a single operation using bash functions. They can get pretty complicated, but they generally follow this syntax: -``` -function_name () { - command_1 - command_2 -} -``` - -The command below combines `mkdir` and `cd`. Typing `md folder_name` creates a directory named "folder_name" in your working directory and navigates into it immediately. -``` -md () { - mkdir -p $1 - cd $1 -} -``` - -The `$1` you see in the function represents the first argument, which is the text you type immediately after the function name. - -### Conclusion - -Unlike some terminal customization tricks, messing with bashrc is fairly straight-forward and low risk. If you mess anything up, you can always delete the bashrc file completely and start over again. Try it out now and you will be amazed at your improved productivity. - --------------------------------------------------------------------------------- - -via: https://www.maketecheasier.com/what-is-bashrc/ - -作者:[Alexander Fox][a] -译者:[译者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/alexfox/ -[1]:https://www.maketecheasier.com/assets/uploads/2018/01/finder-find-bashrc.png (finder-find-bashrc) -[2]:https://www.maketecheasier.com/alternative-linux-shells/ -[3]:https://www.maketecheasier.com/assets/uploads/2018/01/terminal-edit-bashrc-1.png (terminal-edit-bashrc-1) -[4]:http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html -[5]:https://www.digitalocean.com/community/tutorials/an-introduction-to-useful-bash-aliases-and-functions -[6]:https://www.maketecheasier.com/run-bash-script-as-root-during-startup-linux/ (How to Run Bash Script as Root During Startup on Linux) -[7]:https://www.maketecheasier.com/8-useful-and-interesting-bash-prompts/ -[8]:https://www.maketecheasier.com/more-useful-and-interesting-bash-prompts/ -[9]:https://www.maketecheasier.com/assets/uploads/2018/01/terminal-edit-bashrc-3.png (terminal-edit-bashrc-3) -[10]:https://www.maketecheasier.com/install-software-in-various-linux-distros/#aliases -[11]:https://www.maketecheasier.com/assets/uploads/2018/01/terminal-edit-bashrc-2.png (terminal-edit-bashrc-2) diff --git a/sources/tech/20180124 4 cool new projects to try in COPR for January.md b/sources/tech/20180124 4 cool new projects to try in COPR for January.md deleted file mode 100644 index 53e8f362a0..0000000000 --- a/sources/tech/20180124 4 cool new projects to try in COPR for January.md +++ /dev/null @@ -1,85 +0,0 @@ -translating---geekpi - -4 cool new projects to try in COPR for January -====== - -![](https://fedoramagazine.org/wp-content/uploads/2017/08/4-copr-945x400.jpg) - -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. - -### Elisa - -[Elisa][2] is a minimal music player. It lets you browse music by albums, artists or tracks. It automatically detects all playable music in your ~/Music directory, thus it requires no set up at all - neither does it offer any. Currently, Elisa focuses on being a simple music player, so it offers no tools for managing your music collection. - -![][3] - -#### Installation instructions - -The repo currently provides Elisa for Fedora 26, 27 and Rawhide. To install Elisa, use these commands: -``` -sudo dnf copr enable eclipseo/elisa -sudo dnf install elisa -``` - -### Bing Wallpapers - -[Bing Wallpapers][4] is a simple program that downloads Bing's wallpaper of the day and sets it as a desktop wallpaper or a lock screen image. The program can rotate over pictures in its directory in set intervals as well as delete old pictures after a set amount of time. - -#### Installation instructions - -The repo currently provides Bing Wallpapers for Fedora 25, 26, 27 and Rawhide. To install Bing Wallpapers, use these commands: -``` -sudo dnf copr enable julekgwa/Bingwallpapers -sudo dnf install bingwallpapers -``` - -### Polybar - -[Polybar][5] is a tool for creating status bars. It has a lot of customization options as well as built-in functionality to display information about commonly used services, such as systray icons, window title, workspace and desktop panel for [bspwm][6], [i3][7], and more. You can also configure your own modules for your status bar. See [Polybar's wiki][8] for more information about usage and configuration. - -#### Installation instructions - -The repo currently provides Polybar for Fedora 27. To install Polybar, use these commands: -``` -sudo dnf copr enable tomwishaupt/polybar -sudo dnf install polybar -``` - -### Netdata - -[Netdata][9] is a distributed monitoring system. It can run on all your systems including PCs, servers, containers and IoT devices, from which it collects metrics in real time. All the information then can be accessed using netdata's web dashboard. Additionally, Netdata provides pre-configured alarms and notifications for detecting performance issue, as well as templates for creating your own alarms. - -![][10] - -#### Installation instructions - -The repo currently provides netdata for EPEL 7, Fedora 27 and Rawhide. To install netdata, use these commands: -``` -sudo dnf copr enable recteurlp/netdata -sudo dnf install netdata -``` - - --------------------------------------------------------------------------------- - -via: https://fedoramagazine.org/4-cool-new-projects-to-try-in-copr-for-january/ - -作者:[Dominik Turecek][a] -译者:[译者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]:https://community.kde.org/Elisa -[3]:https://fedoramagazine.org/wp-content/uploads/2018/01/elisa.png -[4]:http://bingwallpapers.lekgoara.com/ -[5]:https://github.com/jaagr/polybar -[6]:https://github.com/baskerville/bspwm -[7]:https://i3wm.org/ -[8]:https://github.com/jaagr/polybar/wiki -[9]:http://my-netdata.io/ -[10]:https://fedoramagazine.org/wp-content/uploads/2018/01/netdata.png diff --git a/sources/tech/20180124 Containers the GPL and copyleft No reason for concern.md b/sources/tech/20180124 Containers the GPL and copyleft No reason for concern.md deleted file mode 100644 index 0578bdd642..0000000000 --- a/sources/tech/20180124 Containers the GPL and copyleft No reason for concern.md +++ /dev/null @@ -1,61 +0,0 @@ -Containers, the GPL, and copyleft: No reason for concern -============================================================ - -### Wondering how open source licensing affects Linux containers? Here's what you need to know. - - -![Containers, the GPL, and copyleft: No reason for concern](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/LAW_patents4abstract_B.png?itok=6RHeRaYh "Containers, the GPL, and copyleft: No reason for concern") -Image by : opensource.com - -Though open source is thoroughly mainstream, new software technologies and old technologies that get newly popularized sometimes inspire hand-wringing about open source licenses. Most often the concern is about the GNU General Public License (GPL), and specifically the scope of its copyleft requirement, which is often described (somewhat misleadingly) as the GPL’s derivative work issue. - -One imperfect way of framing the question is whether GPL-licensed code, when combined in some sense with proprietary code, forms a single modified work such that the proprietary code could be interpreted as being subject to the terms of the GPL. While we haven’t yet seen much of that concern directed to Linux containers, we expect more questions to be raised as adoption of containers continues to grow. But it’s fairly straightforward to show that containers do  _not_  raise new or concerning GPL scope issues. - -Statutes and case law provide little help in interpreting a license like the GPL. On the other hand, many of us give significant weight to the interpretive views of the Free Software Foundation (FSF), the drafter and steward of the GPL, even in the typical case where the FSF is not a copyright holder of the software at issue. In addition to being the author of the license text, the FSF has been engaged for many years in providing commentary and guidance on its licenses to the community. Its views have special credibility and influence based on its public interest mission and leadership in free software policy. - -The FSF’s existing guidance on GPL interpretation has relevance for understanding the effects of including GPL and non-GPL code in containers. The FSF has placed emphasis on the process boundary when considering copyleft scope, and on the mechanism and semantics of the communication between multiple software components to determine whether they are closely integrated enough to be considered a single program for GPL purposes. For example, the [GNU Licenses FAQ][4] takes the view that pipes, sockets, and command-line arguments are mechanisms that are normally suggestive of separateness (in the absence of sufficiently "intimate" communications). - -Consider the case of a container in which both GPL code and proprietary code might coexist and execute. A container is, in essence, an isolated userspace stack. In the [OCI container image format][5], code is packaged as a set of filesystem changeset layers, with the base layer normally being a stripped-down conventional Linux distribution without a kernel. As with the userspace of non-containerized Linux distributions, these base layers invariably contain many GPL-licensed packages (both GPLv2 and GPLv3), as well as packages under licenses considered GPL-incompatible, and commonly function as a runtime for proprietary as well as open source applications. The ["mere aggregation" clause][6] in GPLv2 (as well as its counterpart GPLv3 provision on ["aggregates"][7]) shows that this type of combination is generally acceptable, is specifically contemplated under the GPL, and has no effect on the licensing of the two programs, assuming incompatibly licensed components are separate and independent. - -Of course, in a given situation, the relationship between two components may not be "mere aggregation," but the same is true of software running in non-containerized userspace on a Linux system. There is nothing in the technical makeup of containers or container images that suggests a need to apply a special form of copyleft scope analysis. - -It follows that when looking at the relationship between code running in a container and code running outside a container, the "separate and independent" criterion is almost certainly met. The code will run as separate processes, and the whole technical point of using containers is isolation from other software running on the system. - -Now consider the case where two components, one GPL-licensed and one proprietary, are running in separate but potentially interacting containers, perhaps as part of an application designed with a [microservices][8] architecture. In the absence of very unusual facts, we should not expect to see copyleft scope extending across multiple containers. Separate containers involve separate processes. Communication between containers by way of network interfaces is analogous to such mechanisms as pipes and sockets, and a multi-container microservices scenario would seem to preclude what the FSF calls "[intimate][9]" communication by definition. The composition of an application using multiple containers may not be dispositive of the GPL scope issue, but it makes the technical boundaries between the components more apparent and provides a strong basis for arguing separateness. Here, too, there is no technical feature of containers that suggests application of a different and stricter approach to copyleft scope analysis. - -A company that is overly concerned with the potential effects of distributing GPL-licensed code might attempt to prohibit its developers from adding any such code to a container image that it plans to distribute. Insofar as the aim is to avoid distributing code under the GPL, this is a dubious strategy. As noted above, the base layers of conventional container images will contain multiple GPL-licensed components. If the company pushes a container image to a registry, there is normally no way it can guarantee that this will not include the base layer, even if it is widely shared. - -On the other hand, the company might decide to embrace containerization as a means of limiting copyleft scope issues by isolating GPL and proprietary code—though one would hope that technical benefits would drive the decision, rather than legal concerns likely based on unfounded anxiety about the GPL. While in a non-containerized setting the relationship between two interacting software components will often be mere aggregation, the evidence of separateness that containers provide may be comforting to those who worry about GPL scope. - -Open source license compliance obligations may arise when sharing container images. But there’s nothing technically different or unique about containers that changes the nature of these obligations or makes them harder to satisfy. With respect to copyleft scope, containerization should, if anything, ease the concerns of the extra-cautious. - - -### About the author - - [![](https://opensource.com/sites/default/files/styles/profile_pictures/public/pictures/picture-216.jpg?itok=R8W7jae8)][10] Richard Fontana - Richard is Senior Commercial Counsel on the Products and Technologies team in Red Hat's legal department. Most of his work focuses on open source-related legal issues.[More about me][2] - --------------------------------------------------------------------------------- - -via: https://opensource.com/article/18/1/containers-gpl-and-copyleft - -作者:[Richard Fontana ][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/fontana -[1]:https://opensource.com/article/18/1/containers-gpl-and-copyleft?rate=qTlANxnuA2tf0hcGE6Po06RGUzcbB-cBxbU3dCuCt9w -[2]:https://opensource.com/users/fontana -[3]:https://opensource.com/user/10544/feed -[4]:https://www.gnu.org/licenses/gpl-faq.en.html#MereAggregation -[5]:https://github.com/opencontainers/image-spec/blob/master/spec.md -[6]:https://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html#section2 -[7]:https://www.gnu.org/licenses/gpl.html#section5 -[8]:https://www.redhat.com/en/topics/microservices -[9]:https://www.gnu.org/licenses/gpl-faq.en.html#GPLPlugins -[10]:https://opensource.com/users/fontana -[11]:https://opensource.com/users/fontana -[12]:https://opensource.com/users/fontana -[13]:https://opensource.com/tags/licensing -[14]:https://opensource.com/tags/containers diff --git a/sources/tech/20180125 A step-by-step guide to Git.md b/sources/tech/20180125 A step-by-step guide to Git.md deleted file mode 100644 index cf43f625ce..0000000000 --- a/sources/tech/20180125 A step-by-step guide to Git.md +++ /dev/null @@ -1,130 +0,0 @@ -A step-by-step guide to Git -====== - -![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/lightbulb-idea-think-yearbook-lead.png?itok=5ZpCm0Jh) - -If you've never used [Git][1], you may be nervous about it. There's nothing to worry about--just follow along with this step-by-step getting-started guide, and you will soon have a new Git repository hosted on [GitHub][2]. - -Before we dive in, let's clear up a common misconception: Git isn't the same thing as GitHub. Git is a version-control system (i.e., a piece of software) that helps you keep track of your computer programs and files and the changes that are made to them over time. It also allows you to collaborate with your peers on a program, code, or file. GitHub and similar services (including GitLab and BitBucket) are websites that host a Git server program to hold your code. - -### Step 1: Create a GitHub account - -The easiest way to get started is to create an account on [GitHub.com][3] (it's free). - -![](https://opensource.com/sites/default/files/u128651/git_guide1.png) - -Pick a username (e.g., octocat123), enter your email address and a password, and click **Sign up for GitHub**. Once you are in, it will look something like this: - -![](https://opensource.com/sites/default/files/u128651/git_guide2.png) - -### Step 2: Create a new repository - -A repository is like a place or a container where something is stored; in this case we're creating a Git repository to store code. To create a new repository, select **New Repository** from the `+` sign dropdown menu (you can see I've selected it in the upper-right corner in the image above). - -![](https://opensource.com/sites/default/files/u128651/git_guide3.png) - -Enter a name for your repository (e.g, "Demo") and click **Create Repository**. Don't worry about changing any other options on this page. - -Congratulations! You have set up your first repo on GitHub.com. - -### Step 3: Create a file - -Once your repo is created, it will look like this: - -![](https://opensource.com/sites/default/files/u128651/git_guide4.png) - -Don't panic, it's simpler than it looks. Stay with me. Look at the section that starts "...or create a new repository on the command line," and ignore the rest for now. - -Open the Terminal program on your computer. - -![](https://opensource.com/sites/default/files/u128651/git_guide5.png) - -Type `git` and hit **Enter**. If it says command `bash: git: command not found`, then [install Git][4] with the command for your Linux operating system or distribution. Check the installation by typing `git` and hitting **Enter** ; if it's installed, you should see a bunch of information about how you can use the command. - -In the terminal, type: -``` -mkdir Demo -``` - -This command will create a directory (or folder) named Demo. - -Change your terminal to the Demo directory with the command: -``` -cd Demo -``` - -Then enter: -``` -echo "#Demo" >> README.md -``` - -This creates a file named `README.md` and writes `#Demo` in it. To check that the file was created successfully, enter: -``` -cat README.md -``` - -This will show you what is inside the `README.md` file, if the file was created correctly. Your terminal will look like this: - -![](https://opensource.com/sites/default/files/u128651/git_guide7.png) - -To tell your computer that Demo is a directory managed by the Git program, enter: -``` -git init -``` - -Then, to tell the Git program you care about this file and want to track any changes from this point forward, enter: -``` -git add README.md -``` - -### Step 4: Make a commit - -So far you've created a file and told Git about it, and now it's time to create a commit. Commit can be thought of as a milestone. Every time you accomplish some work, you can write a Git commit to store that version of your file, so you can go back later and see what it looked like at that point in time. Whenever you make a change to your file, you create a new version of that file, different from the previous one. - -To make a commit, enter: -``` -git commit -m "first commit" -``` - -That's it! You just created a Git commit and included a message that says first commit. You must always write a message in commit; it not only helps you identify a commit, but it also enables you to understand what you did with the file at that point. So tomorrow, if you add a new piece of code in your file, you can write a commit message that says, Added new code, and when you come back in a month to look at your commit history or Git log (the list of commits), you will know what you changed in the files. - -### Step 5: Connect your GitHub repo with your computer - -Now, it's time to connect your computer to GitHub with the command: -``` -git remote add origin https://github.com//Demo.git -``` - -Let's look at this command step by step. We are telling Git to add a `remote` called `origin` with the address `https://github.com//Demo.git` (i.e., the URL of your Git repo on GitHub.com). This allows you to interact with your Git repository on GitHub.com by typing `origin` instead of the full URL and Git will know where to send your code. Why `origin`? Well, you can name it anything else if you'd like. - -Now we have connected our local copy of the Demo repository to its remote counterpart on GitHub.com. Your terminal looks like this: - -![](https://opensource.com/sites/default/files/u128651/git_guide8.png) - -Now that we have added the remote, we can push our code (i.e., upload our `README.md` file) to GitHub.com. - -Once you are done, your terminal will look like this: - -![](https://opensource.com/sites/default/files/u128651/git_guide9.png) - -And if you go to `https://github.com//Demo` you will see something like this: - -![](https://opensource.com/sites/default/files/u128651/git_guide10.png) - -That's it! You have created your first GitHub repo, connected it to your computer, and pushed (or uploaded) a file from your computer to your repository called Demo on GitHub.com. Next time, I will write about Git cloning (downloading your code from GitHub to your computer), adding new files, modifying existing files, and pushing (uploading) files to GitHub. - --------------------------------------------------------------------------------- - -via: https://opensource.com/article/18/1/step-step-guide-git - -作者:[Kedar Vijay Kulkarni][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/kkulkarn -[1]:https://opensource.com/resources/what-is-git -[2]:https://opensource.com/life/15/11/short-introduction-github -[3]:https://github.com/ -[4]:https://www.linuxbabe.com/linux-server/install-git-verion-control-on-linux-debianubuntufedoraarchlinux#crt-2 diff --git a/sources/tech/20180125 BUILDING A FULL-TEXT SEARCH APP USING DOCKER AND ELASTICSEARCH.md b/sources/tech/20180125 BUILDING A FULL-TEXT SEARCH APP USING DOCKER AND ELASTICSEARCH.md new file mode 100644 index 0000000000..d064544e1f --- /dev/null +++ b/sources/tech/20180125 BUILDING A FULL-TEXT SEARCH APP USING DOCKER AND ELASTICSEARCH.md @@ -0,0 +1,1382 @@ +BUILDING A FULL-TEXT SEARCH APP USING DOCKER AND ELASTICSEARCH +============================================================ + + _How does Wikipedia sort though 5+ million articles to find the most relevant one for your research?_ + + _How does Facebook find the friend who you're looking for (and whose name you've misspelled), across a userbase of 2+ billion people?_ + + _How does Google search the entire internet for webpages relevant to your vague, typo-filled search query?_ + +In this tutorial, we'll walk through setting up our own full-text search application (of an admittedly lesser complexity than the systems in the questions above). Our example app will provide a UI and API to search the complete texts of 100 literary classics such as  _Peter Pan_ ,  _Frankenstein_ , and  _Treasure Island_ . + +You can preview a completed version of the tutorial app here - [https://search.patricktriest.com][6] + +![preview webapp](https://cdn.patricktriest.com/blog/images/posts/elastic-library/sample_4_0.png) + +The source code for the application is 100% open-source and can be found at the GitHub repository here - [https://github.com/triestpa/guttenberg-search][7] + +Adding fast, flexible full-text search to apps can be a challenge. Most mainstream databases, such as [PostgreSQL][8] and [MongoDB][9], offer very basic text searching capabilities due to limitations on their existing query and index structures. In order to implement high quality full-text search, a separate datastore is often the best option. [Elasticsearch][10] is a leading open-source datastore that is optimized to perform incredibly flexible and fast full-text search. + +We'll be using [Docker][11] to setup our project environment and dependencies. Docker is a containerization engine used by the likes of [Uber][12], [Spotify][13], [ADP][14], and [Paypal][15]. A major advantage of building a containerized app is that the project setup is virtually the same on Windows, macOS, and Linux - which makes writing this tutorial quite a bit simpler for me. Don't worry if you've never used Docker, we'll go through the full project configuration further down. + +We'll also be using [Node.js][16] (with the [Koa][17] framework), and [Vue.js][18] to build our search API and frontend web app respectively. + +### 1 - WHAT IS ELASTICSEARCH? + +Full-text search is a heavily requested feature in modern applications. Search can also be one of the most difficult features to implement competently - many popular websites have subpar search functionality that returns results slowly and has trouble finding non-exact matches. Often, this is due to limitations in the underlying database: most standard relational databases are limited to basic `CONTAINS` or `LIKE`SQL queries, which provide only the most basic string matching functionality. + +We'd like our search app to be : + +1. **Fast** - Search results should be returned almost instantly, in order to provide a responsive user experience. + +2. **Flexible** - We'll want to be able to modify how the search is performed, in order to optimize for different datasets and use cases. + +3. **Forgiving** - If a search contains a typo, we'd still like to return relevant results for what the user might have been trying to search for. + +4. **Full-Text** - We don't want to limit our search to specific matching keywords or tags - we want to search  _everything_  in our datastore (including large text fields) for a match. + +![Elastic Search Logo](https://storage.googleapis.com/cdn.patricktriest.com/blog/images/posts/elastic-library/Elasticsearch-Logo.png) + +In order to build a super-powered search feature, it’s often most ideal to use a datastore that is optimized for the task of full-text search. This is where [Elasticsearch][19]comes into play; Elasticsearch is an open-source in-memory datastore written in Java and originally built on the [Apache Lucene][20] library. + +Here are some examples of real-world Elasticsearch use cases from the official [Elastic website][21]. + +* Wikipedia uses Elasticsearch to provide full-text search with highlighted search snippets, and search-as-you-type and did-you-mean suggestions. + +* The Guardian uses Elasticsearch to combine visitor logs with social -network data to provide real-time feedback to its editors about the public’s response to new articles. + +* Stack Overflow combines full-text search with geolocation queries and uses more-like-this to find related questions and answers. + +* GitHub uses Elasticsearch to query 130 billion lines of code. + +### What makes Elasticsearch different from a "normal" database? + +At its core, Elasticsearch is able to provide fast and flexible full-text search through the use of  _inverted indices_ . + +An "index" is a data structure to allow for ultra-fast data query and retrieval operations in databases. Databases generally index entries by storing an association of fields with the matching table rows. By storing the index in a searchable data structure (often a [B-Tree][22]), databases can achieve sub-linear time on optimized queries (such as “Find the row with ID = 5”). + +![Relational Index](https://cdn.patricktriest.com/blog/images/posts/elastic-library/db_index.png) + +We can think of a database index like an old-school library card catalog - it tells you precisely where the entry that you're searching for is located, as long as you already know the title and author of the book. Database tables generally have multiple indices in order to speed up queries on specific fields (i.e. an index on the `name`column would greatly speed up queries for rows with a specific name). + +Inverted indexes work in a substantially different manner. The content of each row (or document) is split up, and each individual entry (in this case each word) points back to any documents that it was found within. + +![Inverted Index](https://cdn.patricktriest.com/blog/images/posts/elastic-library/invertedIndex.jpg) + +This inverted-index data structure allows us to very quickly find, say, all of the documents where “football” was mentioned. Through the use of a heavily optimized in-memory inverted index, Elasticsearch enables us to perform some very powerful and customizable full-text searches on our stored data. + +### 2 - PROJECT SETUP + +### 2.0 - Docker + +We'll be using [Docker][23] to manage the environments and dependencies for this project. Docker is a containerization engine that allows applications to be run in isolated environments, unaffected by the host operating system and local development environment. Many web-scale companies run a majority of their server infrastructure in containers now, due to the increased flexibility and composability of containerized application components. + +![Docker Logo](https://storage.googleapis.com/cdn.patricktriest.com/blog/images/posts/elastic-library/docker.png) + +The advantage of using Docker for me, as the friendly author of this tutorial, is that the local environment setup is minimal and consistent across Windows, macOS, and Linux systems. Instead of going through divergent installation instructions for Node.js, Elasticsearch, and Nginx, we can instead just define these dependencies in Docker configuration files, and then run our app anywhere using this configuration. Furthermore, since each application component will run in it's own isolated container, there is much less potential for existing junk on our local machines to interfere, so "But it works on my machine!" types of scenarios will be much more rare when debugging issues. + +### 2.1 - Install Docker & Docker-Compose + +The only dependencies for this project are [Docker][24] and [docker-compose][25], the later of which is an officially supported tool for defining multiple container configurations to  _compose_  into a single application stack. + +Install Docker - [https://docs.docker.com/engine/installation/][26] +Install Docker Compose - [https://docs.docker.com/compose/install/][27] + +### 2.2 - Setup Project Directories + +Create a base directory (say `guttenberg_search`) for the project. To organize our project we'll work within two main subdirectories. + +* `/public` - Store files for the frontend Vue.js webapp. + +* `/server` - Server-side Node.js source code + +### 2.3 - Add Docker-Compose Config + +Next, we'll create a `docker-compose.yml` file to define each container in our application stack. + +1. `gs-api` - The Node.js container for the backend application logic. + +2. `gs-frontend` - An Ngnix container for serving the frontend webapp files. + +3. `gs-search` - An Elasticsearch container for storing and searching data. + +``` +version: '3' + +services: + api: # Node.js App + container_name: gs-api + build: . + ports: + - "3000:3000" # Expose API port + - "9229:9229" # Expose Node process debug port (disable in production) + environment: # Set ENV vars + - NODE_ENV=local + - ES_HOST=elasticsearch + - PORT=3000 + volumes: # Attach local book data directory + - ./books:/usr/src/app/books + + frontend: # Nginx Server For Frontend App + container_name: gs-frontend + image: nginx + volumes: # Serve local "public" dir + - ./public:/usr/share/nginx/html + ports: + - "8080:80" # Forward site to localhost:8080 + + elasticsearch: # Elasticsearch Instance + container_name: gs-search + image: docker.elastic.co/elasticsearch/elasticsearch:6.1.1 + volumes: # Persist ES data in seperate "esdata" volume + - esdata:/usr/share/elasticsearch/data + environment: + - bootstrap.memory_lock=true + - "ES_JAVA_OPTS=-Xms512m -Xmx512m" + - discovery.type=single-node + ports: # Expose Elasticsearch ports + - "9300:9300" + - "9200:9200" + +volumes: # Define seperate volume for Elasticsearch data + esdata: + +``` + +This file defines our entire application stack - no need to install Elasticsearch, Node, or Nginx on your local system. Each container is forwarding ports to the host system (`localhost`), in order for us to access and debug the Node API, Elasticsearch instance, and fronted web app from our host machine. + +### 2.4 - Add Dockerfile + +We are using official prebuilt images for Nginx and Elasticsearch, but we'll need to build our own image for the Node.js app. + +Define a simple `Dockerfile` configuration in the application root directory. + +``` +# Use Node v8.9.0 LTS +FROM node:carbon + +# Setup app working directory +WORKDIR /usr/src/app + +# Copy package.json and package-lock.json +COPY package*.json ./ + +# Install app dependencies +RUN npm install + +# Copy sourcecode +COPY . . + +# Start app +CMD [ "npm", "start" ] + +``` + +This Docker configuration extends the official Node.js image, copies our application source code, and installs the NPM dependencies within the container. + +We'll also add a `.dockerignore` file to avoid copying unneeded files into the container. + +``` +node_modules/ +npm-debug.log +books/ +public/ + +``` + +> Note that we're not copying the `node_modules` directory into our container - this is because we'll be running `npm install` from within the container build process. Attempting to copy the `node_modules` from the host system into a container can cause errors since some packages need to be specifically built for certain operating systems. For instance, installing the `bcrypt` package on macOS and attempting to copy that module directly to an Ubuntu container will not work because `bcyrpt`relies on a binary that needs to be built specifically for each operating system. + +### 2.5 - Add Base Files + +In order to test out the configuration, we'll need to add some placeholder files to the app directories. + +Add this base HTML file at `public/index.html` + +``` +Hello World From The Frontend Container + +``` + +Next, add the placeholder Node.js app file at `server/app.js`. + +``` +const Koa = require('koa') +const app = new Koa() + +app.use(async (ctx, next) => { + ctx.body = 'Hello World From the Backend Container' +}) + +const port = process.env.PORT || 3000 + +app.listen(port, err => { + if (err) console.error(err) + console.log(`App Listening on Port ${port}`) +}) + +``` + +Finally, add our `package.json` Node app configuration. + +``` +{ + "name": "guttenberg-search", + "version": "0.0.1", + "description": "Source code for Elasticsearch tutorial using 100 classic open source books.", + "scripts": { + "start": "node --inspect=0.0.0.0:9229 server/app.js" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/triestpa/guttenberg-search.git" + }, + "author": "patrick.triest@gmail.com", + "license": "MIT", + "bugs": { + "url": "https://github.com/triestpa/guttenberg-search/issues" + }, + "homepage": "https://github.com/triestpa/guttenberg-search#readme", + "dependencies": { + "elasticsearch": "13.3.1", + "joi": "13.0.1", + "koa": "2.4.1", + "koa-joi-validate": "0.5.1", + "koa-router": "7.2.1" + } +} + +``` + +This file defines the application start command and the Node.js package dependencies. + +> Note - You don't have to run `npm install` - the dependencies will be installed inside the container when it is built. + +### 2.6 - Try it Out + +Everything is in place now to test out each component of the app. From the base directory, run `docker-compose build`, which will build our Node.js application container. + +![docker build output](https://cdn.patricktriest.com/blog/images/posts/elastic-library/sample_0_3.png) + +Next, run `docker-compose up` to launch our entire application stack. + +![docker compose output](https://cdn.patricktriest.com/blog/images/posts/elastic-library/sample_0_2.png) + +> This step might take a few minutes since Docker has to download the base images for each container. In subsequent runs, starting the app should be nearly instantaneous, since the required images will have already been downloaded. + +Try visiting `localhost:8080` in your browser - you should see a simple "Hello World" webpage. + +![frontend sample output](https://cdn.patricktriest.com/blog/images/posts/elastic-library/sample_0_0.png) + +Visit `localhost:3000` to verify that our Node server returns it's own "Hello World" message. + +![backend sample output](https://cdn.patricktriest.com/blog/images/posts/elastic-library/sample_0_1.png) + +Finally, visit `localhost:9200` to check that Elasticsearch is running. It should return information similar to this. + +``` +{ + "name" : "SLTcfpI", + "cluster_name" : "docker-cluster", + "cluster_uuid" : "iId8e0ZeS_mgh9ALlWQ7-w", + "version" : { + "number" : "6.1.1", + "build_hash" : "bd92e7f", + "build_date" : "2017-12-17T20:23:25.338Z", + "build_snapshot" : false, + "lucene_version" : "7.1.0", + "minimum_wire_compatibility_version" : "5.6.0", + "minimum_index_compatibility_version" : "5.0.0" + }, + "tagline" : "You Know, for Search" +} + +``` + +If all three URLs display data successfully, congrats! The entire containerized stack is running, so now we can move on to the fun part. + +### 3 - CONNECT TO ELASTICSEARCH + +The first thing that we'll need to do in our app is connect to our local Elasticsearch instance. + +### 3.0 - Add ES Connection Module + +Add the following Elasticsearch initialization code to a new file `server/connection.js`. + +``` +const elasticsearch = require('elasticsearch') + +// Core ES variables for this project +const index = 'library' +const type = 'novel' +const port = 9200 +const host = process.env.ES_HOST || 'localhost' +const client = new elasticsearch.Client({ host: { host, port } }) + +/** Check the ES connection status */ +async function checkConnection () { + let isConnected = false + while (!isConnected) { + console.log('Connecting to ES') + try { + const health = await client.cluster.health({}) + console.log(health) + isConnected = true + } catch (err) { + console.log('Connection Failed, Retrying...', err) + } + } +} + +checkConnection() + +``` + +Let's rebuild our Node app now that we've made changes, using `docker-compose build`. Next, run `docker-compose up -d` to start the application stack as a background daemon process. + +With the app started, run `docker exec gs-api "node" "server/connection.js"` on the command line in order to run our script within the container. You should see some system output similar to the following. + +``` +{ cluster_name: 'docker-cluster', + status: 'yellow', + timed_out: false, + number_of_nodes: 1, + number_of_data_nodes: 1, + active_primary_shards: 1, + active_shards: 1, + relocating_shards: 0, + initializing_shards: 0, + unassigned_shards: 1, + delayed_unassigned_shards: 0, + number_of_pending_tasks: 0, + number_of_in_flight_fetch: 0, + task_max_waiting_in_queue_millis: 0, + active_shards_percent_as_number: 50 } + +``` + +Go ahead and remove the `checkConnection()` call at the bottom before moving on, since in our final app we'll be making that call from outside the connection module. + +### 3.1 - Add Helper Function To Reset Index + +In `server/connection.js` add the following function below `checkConnection`, in order to provide an easy way to reset our Elasticsearch index. + +``` +/** Clear the index, recreate it, and add mappings */ +async function resetIndex (index) { + if (await client.indices.exists({ index })) { + await client.indices.delete({ index }) + } + + await client.indices.create({ index }) + await putBookMapping() +} + +``` + +### 3.2 - Add Book Schema + +Next, we'll want to add a "mapping" for the book data schema. Add the following function below `resetIndex` in `server/connection.js`. + +``` +/** Add book section schema mapping to ES */ +async function putBookMapping () { + const schema = { + title: { type: 'keyword' }, + author: { type: 'keyword' }, + location: { type: 'integer' }, + text: { type: 'text' } + } + + return client.indices.putMapping({ index, type, body: { properties: schema } }) +} + +``` + +Here we are defining a mapping for the `book` index. An Elasticsearch `index` is roughly analogous to a SQL `table` or a MongoDB `collection`. Adding a mapping allows us to specify each field and datatype for the stored documents. Elasticsearch is schema-less, so we don't technically need to add a mapping, but doing so will give us more control over how the data is handled. + +For instance - we're assigning the `keyword` type to the "title" and "author" fields, and the `text` type to the "text" field. Doing so will cause the search engine to treat these string fields differently - During a search, the engine will search  _within_  the `text` field for potential matches, whereas `keyword` fields will be matched based on their full content. This might seem like a minor distinction, but it can have a huge impact on the behavior and speed of different searches. + +Export the exposed properties and functions at the bottom of the file, so that they can be accessed by other modules in our app. + +``` +module.exports = { + client, index, type, checkConnection, resetIndex +} + +``` + +### 4 - LOAD THE RAW DATA + +We'll be using data from [Project Gutenberg][28] - an online effort dedicated to providing free, digital copies of books within the public domain. For this project, we'll be populating our library with 100 classic books, including texts such as  _The Adventures of Sherlock Holmes_ ,  _Treasure Island_ ,  _The Count of Monte Cristo_ ,  _Around the World in 80 Days_ ,  _Romeo and Juliet_ , and  _The Odyssey_ . + +![Book Covers](https://storage.googleapis.com/cdn.patricktriest.com/blog/images/posts/elastic-library/books.jpg) + +### 4.1 - Download Book Files + +I've zipped the 100 books into a file that you can download here - +[https://cdn.patricktriest.com/data/books.zip][29] + +Extract this file into a `books/` directory in your project. + +If you want, you can do this by using the following commands (requires [wget][30] and ["The Unarchiver" CLI][31]). + +``` +wget https://cdn.patricktriest.com/data/books.zip +unar books.zip + +``` + +### 4.2 - Preview A Book + +Try opening one of the book files, say `219-0.txt`. You'll notice that it starts with an open access license, followed by some lines identifying the book title, author, release dates, language and character encoding. + +``` +Title: Heart of Darkness + +Author: Joseph Conrad + +Release Date: February 1995 [EBook #219] +Last Updated: September 7, 2016 + +Language: English + +Character set encoding: UTF-8 + +``` + +After these lines comes `*** START OF THIS PROJECT GUTENBERG EBOOK HEART OF DARKNESS ***`, after which the book content actually starts. + +If you scroll to the end of the book you'll see the matching message `*** END OF THIS PROJECT GUTENBERG EBOOK HEART OF DARKNESS ***`, which is followed by a much more detailed version of the book's license. + +In the next steps, we'll programmatically parse the book metadata from this header and extract the book content from between the `*** START OF` and `***END OF` place markers. + +### 4.3 - Read Data Dir + +Let's write a script to read the content of each book and to add that data to Elasticsearch. We'll define a new Javascript file `server/load_data.js` in order to perform these operations. + +First, we'll obtain a list of every file within the `books/` data directory. + +Add the following content to `server/load_data.js`. + +``` +const fs = require('fs') +const path = require('path') +const esConnection = require('./connection') + +/** Clear ES index, parse and index all files from the books directory */ +async function readAndInsertBooks () { + try { + // Clear previous ES index + await esConnection.resetIndex() + + // Read books directory + let files = fs.readdirSync('./books').filter(file => file.slice(-4) === '.txt') + console.log(`Found ${files.length} Files`) + + // Read each book file, and index each paragraph in elasticsearch + for (let file of files) { + console.log(`Reading File - ${file}`) + const filePath = path.join('./books', file) + const { title, author, paragraphs } = parseBookFile(filePath) + await insertBookData(title, author, paragraphs) + } + } catch (err) { + console.error(err) + } +} + +readAndInsertBooks() + +``` + +We'll use a shortcut command to rebuild our Node.js app and update the running container. + +Run `docker-compose up -d --build` to update the application. This is a shortcut for running `docker-compose build` and `docker-compose up -d`. + +![docker build output](https://cdn.patricktriest.com/blog/images/posts/elastic-library/sample_1_0.png) + +Run`docker exec gs-api "node" "server/load_data.js"` in order to run our `load_data` script within the container. You should see the Elasticsearch status output, followed by `Found 100 Books`. + +After this, the script will exit due to an error because we're calling a helper function (`parseBookFile`) that we have not yet defined. + +![docker exec output](https://cdn.patricktriest.com/blog/images/posts/elastic-library/sample_1_1.png) + +### 4.4 - Read Data File + +Next, we'll read the metadata and content for each book. + +Define a new function in `server/load_data.js`. + +``` +/** Read an individual book text file, and extract the title, author, and paragraphs */ +function parseBookFile (filePath) { + // Read text file + const book = fs.readFileSync(filePath, 'utf8') + + // Find book title and author + const title = book.match(/^Title:\s(.+)$/m)[1] + const authorMatch = book.match(/^Author:\s(.+)$/m) + const author = (!authorMatch || authorMatch[1].trim() === '') ? 'Unknown Author' : authorMatch[1] + + console.log(`Reading Book - ${title} By ${author}`) + + // Find Guttenberg metadata header and footer + const startOfBookMatch = book.match(/^\*{3}\s*START OF (THIS|THE) PROJECT GUTENBERG EBOOK.+\*{3}$/m) + const startOfBookIndex = startOfBookMatch.index + startOfBookMatch[0].length + const endOfBookIndex = book.match(/^\*{3}\s*END OF (THIS|THE) PROJECT GUTENBERG EBOOK.+\*{3}$/m).index + + // Clean book text and split into array of paragraphs + const paragraphs = book + .slice(startOfBookIndex, endOfBookIndex) // Remove Guttenberg header and footer + .split(/\n\s+\n/g) // Split each paragraph into it's own array entry + .map(line => line.replace(/\r\n/g, ' ').trim()) // Remove paragraph line breaks and whitespace + .map(line => line.replace(/_/g, '')) // Guttenberg uses "_" to signify italics. We'll remove it, since it makes the raw text look messy. + .filter((line) => (line && line.length !== '')) // Remove empty lines + + console.log(`Parsed ${paragraphs.length} Paragraphs\n`) + return { title, author, paragraphs } +} + +``` + +This function performs a few important tasks. + +1. Read book text from the file system. + +2. Use regular expressions (check out [this post][1] for a primer on using regex) to parse the book title and author. + +3. Identify the start and end of the book content, by matching on the all-caps "Project Guttenberg" header and footer. + +4. Extract the book text content. + +5. Split each paragraph into its own array. + +6. Clean up the text and remove blank lines. + +As a return value, we'll form an object containing the book's title, author, and an array of paragraphs within the book. + +Run `docker-compose up -d --build` and `docker exec gs-api "node" "server/load_data.js"` again, and you should see the same output as before, this time with three extra lines at the end of the output. + +![docker exec output](https://cdn.patricktriest.com/blog/images/posts/elastic-library/sample_2_0.png) + +Success! Our script successfully parsed the title and author from the text file. The script will again end with an error since we still have to define one more helper function. + +### 4.5 - Index Datafile in ES + +As a final step, we'll bulk-upload each array of paragraphs into the Elasticsearch index. + +Add a new `insertBookData` function to `load_data.js`. + +``` +/** Bulk index the book data in Elasticsearch */ +async function insertBookData (title, author, paragraphs) { + let bulkOps = [] // Array to store bulk operations + + // Add an index operation for each section in the book + for (let i = 0; i < paragraphs.length; i++) { + // Describe action + bulkOps.push({ index: { _index: esConnection.index, _type: esConnection.type } }) + + // Add document + bulkOps.push({ + author, + title, + location: i, + text: paragraphs[i] + }) + + if (i > 0 && i % 500 === 0) { // Do bulk insert in 500 paragraph batches + await esConnection.client.bulk({ body: bulkOps }) + bulkOps = [] + console.log(`Indexed Paragraphs ${i - 499} - ${i}`) + } + } + + // Insert remainder of bulk ops array + await esConnection.client.bulk({ body: bulkOps }) + console.log(`Indexed Paragraphs ${paragraphs.length - (bulkOps.length / 2)} - ${paragraphs.length}\n\n\n`) +} + +``` + +This function will index each paragraph of the book, with author, title, and paragraph location metadata attached. We are inserting the paragraphs using a bulk operation, which is much faster than indexing each paragraph individually. + +> We're bulk indexing the paragraphs in batches, instead of inserting all of them at once. This was a last minute optimization which I added in order for the app to run on the low-ish memory (1.7 GB) host machine that serves `search.patricktriest.com`. If you have a reasonable amount of RAM (4+ GB), you probably don't need to worry about batching each bulk upload, + +Run `docker-compose up -d --build` and `docker exec gs-api "node" "server/load_data.js"` one more time - you should now see a full output of 100 books being parsed and inserted in Elasticsearch. This might take a minute or so. + +![data loading output](https://cdn.patricktriest.com/blog/images/posts/elastic-library/sample_3_0.png) + +### 5 - SEARCH + +Now that Elasticsearch has been populated with one hundred books (amounting to roughly 230,000 paragraphs), let's try out some search queries. + +### 5.0 - Simple HTTP Query + +First, let's just query Elasticsearch directly using it's HTTP API. + +Visit this URL in your browser - `http://localhost:9200/library/_search?q=text:Java&pretty` + +Here, we are performing a bare-bones full-text search to find the word "Java" within our library of books. + +You should see a JSON response similar to the following. + +``` +{ + "took" : 11, + "timed_out" : false, + "_shards" : { + "total" : 5, + "successful" : 5, + "skipped" : 0, + "failed" : 0 + }, + "hits" : { + "total" : 13, + "max_score" : 14.259304, + "hits" : [ + { + "_index" : "library", + "_type" : "novel", + "_id" : "p_GwFWEBaZvLlaAUdQgV", + "_score" : 14.259304, + "_source" : { + "author" : "Charles Darwin", + "title" : "On the Origin of Species", + "location" : 1080, + "text" : "Java, plants of, 375." + } + }, + { + "_index" : "library", + "_type" : "novel", + "_id" : "wfKwFWEBaZvLlaAUkjfk", + "_score" : 10.186235, + "_source" : { + "author" : "Edgar Allan Poe", + "title" : "The Works of Edgar Allan Poe", + "location" : 827, + "text" : "After many years spent in foreign travel, I sailed in the year 18-- , from the port of Batavia, in the rich and populous island of Java, on a voyage to the Archipelago of the Sunda islands. I went as passenger--having no other inducement than a kind of nervous restlessness which haunted me as a fiend." + } + }, + ... + ] + } +} + +``` + +The Elasticseach HTTP interface is useful for testing that our data is inserted successfully, but exposing this API directly to the web app would be a huge security risk. The API exposes administrative functionality (such as directly adding and deleting documents), and should ideally not ever be exposed publicly. Instead, we'll write a simple Node.js API to receive requests from the client, and make the appropriate query (within our private local network) to Elasticsearch. + +### 5.1 - Query Script + +Let's now try querying Elasticsearch from our Node.js application. + +Create a new file, `server/search.js`. + +``` +const { client, index, type } = require('./connection') + +module.exports = { + /** Query ES index for the provided term */ + queryTerm (term, offset = 0) { + const body = { + from: offset, + query: { match: { + text: { + query: term, + operator: 'and', + fuzziness: 'auto' + } } }, + highlight: { fields: { text: {} } } + } + + return client.search({ index, type, body }) + } +} + +``` + +Our search module defines a simple `search` function, which will perform a `match`query using the input term. + +Here are query fields broken down - + +* `from` - Allows us to paginate the results. Each query returns 10 results by default, so specifying `from: 10` would allow us to retrieve results 10-20. + +* `query` - Where we specify the actual term that we are searching for. + +* `operator` - We can modify the search behavior; in this case, we're using the "and" operator to prioritize results that contain all of the tokens (words) in the query. + +* `fuzziness` - Adjusts tolerance for spelling mistakes, `auto` defaults to `fuzziness: 2`. A higher fuzziness will allow for more corrections in result hits. For instance, `fuzziness: 1` would allow `Patricc` to return `Patrick` as a match. + +* `highlights` - Returns an extra field with the result, containing HTML to display the exact text subset and terms that were matched with the query. + +Feel free to play around with these parameters, and to customize the search query further by exploring the [Elastic Full-Text Query DSL][32]. + +### 6 - API + +Let's write a quick HTTP API in order to access our search functionality from a frontend app. + +### 6.0 - API Server + +Replace our existing `server/app.js` file with the following contents. + +``` +const Koa = require('koa') +const Router = require('koa-router') +const joi = require('joi') +const validate = require('koa-joi-validate') +const search = require('./search') + +const app = new Koa() +const router = new Router() + +// Log each request to the console +app.use(async (ctx, next) => { + const start = Date.now() + await next() + const ms = Date.now() - start + console.log(`${ctx.method} ${ctx.url} - ${ms}`) +}) + +// Log percolated errors to the console +app.on('error', err => { + console.error('Server Error', err) +}) + +// Set permissive CORS header +app.use(async (ctx, next) => { + ctx.set('Access-Control-Allow-Origin', '*') + return next() +}) + +// ADD ENDPOINTS HERE + +const port = process.env.PORT || 3000 + +app + .use(router.routes()) + .use(router.allowedMethods()) + .listen(port, err => { + if (err) throw err + console.log(`App Listening on Port ${port}`) + }) + +``` + +This code will import our server dependencies and set up simple logging and error handling for a [Koa.js][33] Node API server. + +### 6.1 - Link endpoint with queries + +Next, we'll add an endpoint to our server in order to expose our Elasticsearch query function. + +Insert the following code below the `// ADD ENDPOINTS HERE` comment in `server/app.js`. + +``` +/** + * GET /search + * Search for a term in the library + */ +router.get('/search', async (ctx, next) => { + const { term, offset } = ctx.request.query + ctx.body = await search.queryTerm(term, offset) + } +) + +``` + +Restart the app using `docker-compose up -d --build`. In your browser, try calling the search endpoint. For example, this request would search the entire library for passages mentioning "Java" - `http://localhost:3000/search?term=java` + +The result will look quite similar to the response from earlier when we called the Elasticsearch HTTP interface directly. + +``` +{ + "took": 242, + "timed_out": false, + "_shards": { + "total": 5, + "successful": 5, + "skipped": 0, + "failed": 0 + }, + "hits": { + "total": 93, + "max_score": 13.356944, + "hits": [{ + "_index": "library", + "_type": "novel", + "_id": "eHYHJmEBpQg9B4622421", + "_score": 13.356944, + "_source": { + "author": "Charles Darwin", + "title": "On the Origin of Species", + "location": 1080, + "text": "Java, plants of, 375." + }, + "highlight": { + "text": ["Java, plants of, 375."] + } + }, { + "_index": "library", + "_type": "novel", + "_id": "2HUHJmEBpQg9B462xdNg", + "_score": 9.030668, + "_source": { + "author": "Unknown Author", + "title": "The King James Bible", + "location": 186, + "text": "10:4 And the sons of Javan; Elishah, and Tarshish, Kittim, and Dodanim." + }, + "highlight": { + "text": ["10:4 And the sons of Javan; Elishah, and Tarshish, Kittim, and Dodanim."] + } + } + ... + ] + } +} + +``` + +### 6.2 - Input validation + +This endpoint is still brittle - we are not doing any checks on the request parameters, so invalid or missing values would result in a server error. + +We'll add some middleware to the endpoint in order to validate input parameters using [Joi][34] and the [Koa-Joi-Validate][35] library. + +``` +/** + * GET /search + * Search for a term in the library + * Query Params - + * term: string under 60 characters + * offset: positive integer + */ +router.get('/search', + validate({ + query: { + term: joi.string().max(60).required(), + offset: joi.number().integer().min(0).default(0) + } + }), + async (ctx, next) => { + const { term, offset } = ctx.request.query + ctx.body = await search.queryTerm(term, offset) + } +) + +``` + +Now, if you restart the server and make a request with a missing term(`http://localhost:3000/search`), you will get back an HTTP 400 error with a relevant message, such as `Invalid URL Query - child "term" fails because ["term" is required]`. + +To view live logs from the Node app, you can run `docker-compose logs -f api`. + +### 7 - FRONT-END APPLICATION + +Now that our `/search` endpoint is in place, let's wire up a simple web app to test out the API. + +### 7.0 - Vue.js App + +We'll be using Vue.js to coordinate our frontend. + +Add a new file, `/public/app.js`, to hold our Vue.js application code. + +``` +const vm = new Vue ({ + el: '#vue-instance', + data () { + return { + baseUrl: 'http://localhost:3000', // API url + searchTerm: 'Hello World', // Default search term + searchDebounce: null, // Timeout for search bar debounce + searchResults: [], // Displayed search results + numHits: null, // Total search results found + searchOffset: 0, // Search result pagination offset + + selectedParagraph: null, // Selected paragraph object + bookOffset: 0, // Offset for book paragraphs being displayed + paragraphs: [] // Paragraphs being displayed in book preview window + } + }, + async created () { + this.searchResults = await this.search() // Search for default term + }, + methods: { + /** Debounce search input by 100 ms */ + onSearchInput () { + clearTimeout(this.searchDebounce) + this.searchDebounce = setTimeout(async () => { + this.searchOffset = 0 + this.searchResults = await this.search() + }, 100) + }, + /** Call API to search for inputted term */ + async search () { + const response = await axios.get(`${this.baseUrl}/search`, { params: { term: this.searchTerm, offset: this.searchOffset } }) + this.numHits = response.data.hits.total + return response.data.hits.hits + }, + /** Get next page of search results */ + async nextResultsPage () { + if (this.numHits > 10) { + this.searchOffset += 10 + if (this.searchOffset + 10 > this.numHits) { this.searchOffset = this.numHits - 10} + this.searchResults = await this.search() + document.documentElement.scrollTop = 0 + } + }, + /** Get previous page of search results */ + async prevResultsPage () { + this.searchOffset -= 10 + if (this.searchOffset < 0) { this.searchOffset = 0 } + this.searchResults = await this.search() + document.documentElement.scrollTop = 0 + } + } +}) + +``` + +The app is pretty simple - we're just defining some shared data properties, and adding methods to retrieve and paginate through search results. The search input is debounced by 100ms, to prevent the API from being called with every keystroke. + +Explaining how Vue.js works is outside the scope of this tutorial, but this probably won't look too crazy if you've used Angular or React. If you're completely unfamiliar with Vue, and if you want something quick to get started with, I would recommend the official quick-start guide - [https://vuejs.org/v2/guide/][36] + +### 7.1 - HTML + +Replace our placeholder `/public/index.html` file with the following contents, in order to load our Vue.js app and to layout a basic search interface. + +``` + + + + + Elastic Library + + + + + + + + +
+ +
+
+ + +
+
+ + +
+
{{ numHits }} Hits
+
Displaying Results {{ searchOffset }} - {{ searchOffset + 9 }}
+
+ + +
+ + +
+ + +
+
+
+
+
{{ hit._source.title }} - {{ hit._source.author }}
+
Location {{ hit._source.location }}
+
+
+ + +
+ + +
+ + +
+ + + + + + + +``` + +### 7.2 - CSS + +Add a new file, `/public/styles.css`, with some custom UI styling. + +``` +body { font-family: 'EB Garamond', serif; } + +.mui-textfield > input, .mui-btn, .mui--text-subhead, .mui-panel > .mui--text-headline { + font-family: 'Open Sans', sans-serif; +} + +.all-caps { text-transform: uppercase; } +.app-container { padding: 16px; } +.search-results em { font-weight: bold; } +.book-modal > button { width: 100%; } +.search-results .mui-divider { margin: 14px 0; } + +.search-results { + display: flex; + flex-direction: row; + flex-wrap: wrap; + justify-content: space-around; +} + +.search-results > div { + flex-basis: 45%; + box-sizing: border-box; + cursor: pointer; +} + +@media (max-width: 600px) { + .search-results > div { flex-basis: 100%; } +} + +.paragraphs-container { + max-width: 800px; + margin: 0 auto; + margin-bottom: 48px; +} + +.paragraphs-container .mui--text-body1, .paragraphs-container .mui--text-body2 { + font-size: 1.8rem; + line-height: 35px; +} + +.book-modal { + width: 100%; + height: 100%; + padding: 40px 10%; + box-sizing: border-box; + margin: 0 auto; + background-color: white; + overflow-y: scroll; + position: fixed; + top: 0; + left: 0; +} + +.pagination-panel { + display: flex; + justify-content: space-between; +} + +.title-row { + display: flex; + justify-content: space-between; + align-items: flex-end; +} + +@media (max-width: 600px) { + .title-row{ + flex-direction: column; + text-align: center; + align-items: center + } +} + +.locations-label { + text-align: center; + margin: 8px; +} + +.modal-footer { + position: fixed; + bottom: 0; + left: 0; + width: 100%; + display: flex; + justify-content: space-around; + background: white; +} + +``` + +### 7.3 - Try it out + +Open `localhost:8080` in your web browser, you should see a simple search interface with paginated results. Try typing in the top search bar to find matches from different terms. + +![preview webapp](https://cdn.patricktriest.com/blog/images/posts/elastic-library/sample_4_0.png) + +> You  _do not_  have to re-run the `docker-compose up` command for the changes to take effect. The local `public` directory is mounted to our Nginx fileserver container, so frontend changes on the local system will be automatically reflected in the containerized app. + +If you try clicking on any result, nothing happens - we still have one more feature to add to the app. + +### 8 - PAGE PREVIEWS + +It would be nice to be able to click on each search result and view it in the context of the book that it's from. + +### 8.0 - Add Elasticsearch Query + +First, we'll need to define a simple query to get a range of paragraphs from a given book. + +Add the following function to the `module.exports` block in `server/search.js`. + +``` +/** Get the specified range of paragraphs from a book */ +getParagraphs (bookTitle, startLocation, endLocation) { + const filter = [ + { term: { title: bookTitle } }, + { range: { location: { gte: startLocation, lte: endLocation } } } + ] + + const body = { + size: endLocation - startLocation, + sort: { location: 'asc' }, + query: { bool: { filter } } + } + + return client.search({ index, type, body }) +} + +``` + +This new function will return an ordered array of paragraphs between the start and end locations of a given book. + +### 8.1 - Add API Endpoint + +Now, let's link this function to an API endpoint. + +Add the following to `server/app.js`, below the original `/search` endpoint. + +``` +/** + * GET /paragraphs + * Get a range of paragraphs from the specified book + * Query Params - + * bookTitle: string under 256 characters + * start: positive integer + * end: positive integer greater than start + */ +router.get('/paragraphs', + validate({ + query: { + bookTitle: joi.string().max(256).required(), + start: joi.number().integer().min(0).default(0), + end: joi.number().integer().greater(joi.ref('start')).default(10) + } + }), + async (ctx, next) => { + const { bookTitle, start, end } = ctx.request.query + ctx.body = await search.getParagraphs(bookTitle, start, end) + } +) + +``` + +### 8.2 - Add UI functionality + +Now that our new endpoint is in place, let's add some frontend functionality to query and display full pages from the book. + +Add the following functions to the `methods` block of `/public/app.js`. + +``` + /** Call the API to get current page of paragraphs */ + async getParagraphs (bookTitle, offset) { + try { + this.bookOffset = offset + const start = this.bookOffset + const end = this.bookOffset + 10 + const response = await axios.get(`${this.baseUrl}/paragraphs`, { params: { bookTitle, start, end } }) + return response.data.hits.hits + } catch (err) { + console.error(err) + } + }, + /** Get next page (next 10 paragraphs) of selected book */ + async nextBookPage () { + this.$refs.bookModal.scrollTop = 0 + this.paragraphs = await this.getParagraphs(this.selectedParagraph._source.title, this.bookOffset + 10) + }, + /** Get previous page (previous 10 paragraphs) of selected book */ + async prevBookPage () { + this.$refs.bookModal.scrollTop = 0 + this.paragraphs = await this.getParagraphs(this.selectedParagraph._source.title, this.bookOffset - 10) + }, + /** Display paragraphs from selected book in modal window */ + async showBookModal (searchHit) { + try { + document.body.style.overflow = 'hidden' + this.selectedParagraph = searchHit + this.paragraphs = await this.getParagraphs(searchHit._source.title, searchHit._source.location - 5) + } catch (err) { + console.error(err) + } + }, + /** Close the book detail modal */ + closeBookModal () { + document.body.style.overflow = 'auto' + this.selectedParagraph = null + } + +``` + +These five functions provide the logic for downloading and paginating through pages (ten paragraphs each) in a book. + +Now we just need to add a UI to display the book pages. Add this markup below the `` comment in `/public/index.html`. + +``` + +
+
+ +
+
{{ selectedParagraph._source.title }}
+
{{ selectedParagraph._source.author }}
+
+
+
+
Locations {{ bookOffset - 5 }} to {{ bookOffset + 5 }}
+
+
+ + +
+
+ {{ paragraph._source.text }} +
+
+ {{ paragraph._source.text }} +
+
+
+
+ + + +
+ +``` + +Restart the app server (`docker-compose up -d --build`) again and open up `localhost:8080`. When you click on a search result, you are now able to view the surrounding paragraphs. You can now even read the rest of the book to completion if you're entertained by what you find. + +![preview webapp book page](https://cdn.patricktriest.com/blog/images/posts/elastic-library/sample_5_0.png) + +Congrats, you've completed the tutorial application! + +Feel free to compare your local result against the completed sample hosted here - [https://search.patricktriest.com/][37] + +### 9 - DISADVANTAGES OF ELASTICSEARCH + +### 9.0 - Resource Hog + +Elasticsearch is computationally demanding. The [official recommendation][38] is to run ES on a machine with 64 GB of RAM, and they strongly discourage running it on anything with under 8 GB of RAM. Elasticsearch is an  _in-memory_  datastore, which allows it to return results extremely quickly, but also results in a very significant system memory footprint. In production, [it is strongly recommended to run multiple Elasticsearch nodes in a cluster][39] to allow for high server availability, automatic sharding, and data redundancy in case of a node failure. + +I've got our tutorial application running on a $15/month GCP compute instance (at [search.patricktriest.com][40]) with 1.7 GB of RAM, and it  _just barely_  is able to run the Elasticsearch node; sometimes the entire machine freezes up during the initial data-loading step. Elasticsearch is, in my experience, much more of a resource hog than more traditional databases such as PostgreSQL and MongoDB, and can be significantly more expensive to host as a result. + +### 9.1 - Syncing with Databases + +In most applications, storing all of the data in Elasticsearch is not an ideal option. It is possible to use ES as the primary transactional database for an app, but this is generally not recommended due to the lack of ACID compliance in Elasticsearch, which can lead to lost write operations when ingesting data at scale. In many cases, ES serves a more specialized role, such as powering the text searching features of the app. This specialized use requires that some of the data from the primary database is replicated to the Elasticsearch instance. + +For instance, let's imagine that we're storing our users in a PostgreSQL table, but using Elasticsearch to power our user-search functionality. If a user, "Albert", decides to change his name to "Al", we'll need this change to be reflected in both our primary PostgreSQL database and in our auxiliary Elasticsearch cluster. + +This can be a tricky integration to get right, and the best answer will depend on your existing stack. There are a multitude of open-source options available, from [a process to watch a MongoDB operation log][41] and automatically sync detected changes to ES, to a [PostgresSQL plugin][42] to create a custom PSQL-based index that communicates automatically with Elasticsearch. + +If none of the available pre-built options work, you could always just add some hooks into your server code to update the Elasticsearch index manually based on database changes. I would consider this final option to be a last resort, since keeping ES in sync using custom business logic can be complex, and is likely to introduce numerous bugs to the application. + +The need to sync Elasticsearch with a primary database is more of an architectural complexity than it is a specific weakness of ES, but it's certainly worth keeping in mind when considering the tradeoffs of adding a dedicated search engine to your app. + +### CONCLUSION + +Full-text search is one of the most important features in many modern applications - and is one of the most difficult to implement well. Elasticsearch is a fantastic option for adding fast and customizable text search to your application, but there are alternatives. [Apache Solr][43] is a similar open source search platform that is built on Apache Lucene - the same library at the core of Elasticsearch. [Algolia][44] is a search-as-a-service web platform which is growing quickly in popularity and is likely to be easier to get started with for beginners (but as a tradeoff is less customizable and can get quite expensive). + +"Search-bar" style features are far from the only use-case for Elasticsearch. ES is also a very common tool for log storage and analysis, commonly used in an ELK (Elasticsearch, Logstash, Kibana) stack configuration. The flexible full-text search allowed by Elasticsearch can also be very useful for a wide variety of data science tasks - such as correcting/standardizing the spellings of entities within a dataset or searching a large text dataset for similar phrases. + +Here are some ideas for your own projects. + +* Add more of your favorite books to our tutorial app and create your own private library search engine. + +* Create an academic plagiarism detection engine by indexing papers from [Google Scholar][2]. + +* Build a spell checking application by indexing every word in the dictionary to Elasticsearch. + +* Build your own Google-competitor internet search engine by loading the [Common Crawl Corpus][3] into Elasticsearch (caution - with over 5 billion pages, this can be a very expensive dataset play with). + +* Use Elasticsearch for journalism: search for specific names and terms in recent large-scale document leaks such as the [Panama Papers][4] and [Paradise Papers][5]. + +The source code for this tutorial application is 100% open-source and can be found at the GitHub repository here - [https://github.com/triestpa/guttenberg-search][45] + +I hope you enjoyed the tutorial! Please feel free to post any thoughts, questions, or criticisms in the comments below. + + +-------------------------------------------------------------------------------- + +作者简介: + +Full-stack engineer, data enthusiast, insatiable learner, obsessive builder. You can find me wandering on a mountain trail, pretending not to be lost. + +------------- + + +via: https://blog.patricktriest.com/text-search-docker-elasticsearch/ + +作者:[Patrick Triest][a] +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://blog.patricktriest.com/author/patrick/ +[1]:https://blog.patricktriest.com/you-should-learn-regex/ +[2]:https://scholar.google.com/ +[3]:https://aws.amazon.com/public-datasets/common-crawl/ +[4]:https://en.wikipedia.org/wiki/Panama_Papers +[5]:https://en.wikipedia.org/wiki/Paradise_Papers +[6]:https://search.patricktriest.com/ +[7]:https://github.com/triestpa/guttenberg-search +[8]:https://www.postgresql.org/ +[9]:https://www.mongodb.com/ +[10]:https://www.elastic.co/ +[11]:https://www.docker.com/ +[12]:https://www.uber.com/ +[13]:https://www.spotify.com/us/ +[14]:https://www.adp.com/ +[15]:https://www.paypal.com/us/home +[16]:https://nodejs.org/en/ +[17]:http://koajs.com/ +[18]:https://vuejs.org/ +[19]:https://www.elastic.co/ +[20]:https://lucene.apache.org/core/ +[21]:https://www.elastic.co/guide/en/elasticsearch/guide/2.x/getting-started.html +[22]:https://en.wikipedia.org/wiki/B-tree +[23]:https://www.docker.com/ +[24]:https://www.docker.com/ +[25]:https://docs.docker.com/compose/ +[26]:https://docs.docker.com/engine/installation/ +[27]:https://docs.docker.com/compose/install/ +[28]:https://www.gutenberg.org/ +[29]:https://cdn.patricktriest.com/data/books.zip +[30]:https://www.gnu.org/software/wget/ +[31]:https://theunarchiver.com/command-line +[32]:https://www.elastic.co/guide/en/elasticsearch/reference/current/full-text-queries.html +[33]:http://koajs.com/ +[34]:https://github.com/hapijs/joi +[35]:https://github.com/triestpa/koa-joi-validate +[36]:https://vuejs.org/v2/guide/ +[37]:https://search.patricktriest.com/ +[38]:https://www.elastic.co/guide/en/elasticsearch/guide/current/hardware.html +[39]:https://www.elastic.co/guide/en/elasticsearch/guide/2.x/distributed-cluster.html +[40]:https://search.patricktriest.com/ +[41]:https://github.com/mongodb-labs/mongo-connector +[42]:https://github.com/zombodb/zombodb +[43]:https://lucene.apache.org/solr/ +[44]:https://www.algolia.com/ +[45]:https://github.com/triestpa/guttenberg-search +[46]:https://blog.patricktriest.com/tag/guides/ +[47]:https://blog.patricktriest.com/tag/javascript/ +[48]:https://blog.patricktriest.com/tag/nodejs/ +[49]:https://blog.patricktriest.com/tag/web-development/ +[50]:https://blog.patricktriest.com/tag/devops/ \ No newline at end of file diff --git a/sources/tech/20180125 Building a Linux-based HPC system on the Raspberry.md b/sources/tech/20180125 Building a Linux-based HPC system on the Raspberry.md new file mode 100644 index 0000000000..eab5ac90b3 --- /dev/null +++ b/sources/tech/20180125 Building a Linux-based HPC system on the Raspberry.md @@ -0,0 +1,153 @@ +Building a Linux-based HPC system on the Raspberry Pi with Ansible +============================================================ + +### Create a high-performance computing cluster with low-cost hardware and open source software. + +![Building a Linux-based HPC system on the Raspberry Pi with Ansible](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/code_computer_development_programming.png?itok=4OM29-82 "Building a Linux-based HPC system on the Raspberry Pi with Ansible") +Image by : opensource.com + +In my [previous article for Opensource.com][14], I introduced the [OpenHPC][15] project, which aims to accelerate innovation in high-performance computing (HPC). This article goes a step further by using OpenHPC's capabilities to build a small HPC system. To call it an  _HPC system_  might sound bigger than it is, so maybe it is better to say this is a system based on the [Cluster Building Recipes][16] published by the OpenHPC project. + +The resulting cluster consists of two Raspberry Pi 3 systems acting as compute nodes and one virtual machine acting as the master node: + + +![Map of HPC cluster](https://opensource.com/sites/default/files/u128651/hpc_with_pi-1.png "Map of HPC cluster") + +My master node is running CentOS on x86_64 and my compute nodes are running a slightly modified CentOS on aarch64. + +This is what the setup looks in real life: + + +![HPC hardware setup](https://opensource.com/sites/default/files/u128651/hpc_with_pi-2.jpg "HPC hardware setup") + +To set up my system like an HPC system, I followed some of the steps from OpenHPC's Cluster Building Recipes [install guide for CentOS 7.4/aarch64 + Warewulf + Slurm][17] (PDF). This recipe includes provisioning instructions using [Warewulf][18]; because I manually installed my three systems, I skipped the Warewulf parts and created an [Ansible playbook][19] for the steps I took. + + +Once my cluster was set up by the [Ansible][26] playbooks, I could start to submit jobs to my resource manager. The resource manager, [Slurm][27] in my case, is the instance in the cluster that decides where and when my jobs are executed. One possibility to start a simple job on the cluster is: +``` +[ohpc@centos01 ~]$ srun hostname +calvin +``` + +If I need more resources, I can tell Slurm that I want to run my command on eight CPUs: + +``` +[ohpc@centos01 ~]$ srun -n 8 hostname +hobbes +hobbes +hobbes +hobbes +calvin +calvin +calvin +calvin +``` + +In the first example, Slurm ran the specified command (`hostname`) on a single CPU, and in the second example Slurm ran the command on eight CPUs. One of my compute nodes is named `calvin` and the other is named `hobbes`; that can be seen in the output of the above commands. Each of the compute nodes is a Raspberry Pi 3 with four CPU cores. + +Another way to submit jobs to my cluster is the command `sbatch`, which can be used to execute scripts with the output written to a file instead of my terminal. + +``` +[ohpc@centos01 ~]$ cat script1.sh +#!/bin/sh +date +hostname +sleep 10 +date +[ohpc@centos01 ~]$ sbatch script1.sh +Submitted batch job 101 +``` + +This will create an output file called `slurm-101.out` with the following content: + +``` +Mon 11 Dec 16:42:31 UTC 2017 +calvin +Mon 11 Dec 16:42:41 UTC 2017 +``` + +To demonstrate the basic functionality of the resource manager, simple and serial command line tools are suitable—but a bit boring after doing all the work to set up an HPC-like system. + +A more interesting application is running an [Open MPI][20] parallelized job on all available CPUs on the cluster. I'm using an application based on [Game of Life][21], which was used in a [video][22] called "Running Game of Life across multiple architectures with Red Hat Enterprise Linux." In addition to the previously used MPI-based Game of Life implementation, the version now running on my cluster colors the cells for each involved host differently. The following script starts the application interactively with a graphical output: + +``` +$ cat life.mpi +#!/bin/bash + +module load gnu6 openmpi3 + +if [[ "$SLURM_PROCID" != "0" ]]; then +    exit +fi + +mpirun ./mpi_life -a -p -b +``` + +I start the job with the following command, which tells Slurm to allocate eight CPUs for the job: + +``` +$ srun -n 8 --x11 life.mpi +``` + +For demonstration purposes, the job has a graphical interface that shows the current result of the calculation: + + +![](https://opensource.com/sites/default/files/u128651/hpc_with_pi-3.png) + +The position of the red cells is calculated on one of the compute nodes, and the green cells are calculated on the other compute node. I can also tell the Game of Life program to color the cell for each used CPU (there are four per compute node) differently, which leads to the following output: + + +![](https://opensource.com/sites/default/files/u128651/hpc_with_pi-4.png) + +Thanks to the installation recipes and the software packages provided by OpenHPC, I was able to set up two compute nodes and a master node in an HPC-type configuration. I can submit jobs to my resource manager, and I can use the software provided by OpenHPC to start MPI applications utilizing all my Raspberry Pis' CPUs. + +* * * + + _To learn more about using OpenHPC to build a Raspberry Pi cluster, please attend Adrian Reber's talks at [DevConf.cz 2018][10], January 26-28, in Brno, Czech Republic, and at the [CentOS Dojo 2018][11], on February 2, in Brussels._ + +### About the author + + [![](https://opensource.com/sites/default/files/styles/profile_pictures/public/pictures/gotchi-square.png?itok=PJKu7LHn)][23] Adrian Reber - Adrian is a Senior Software Engineer at Red Hat and is migrating processes at least since 2010\. He started to migrate processes in a high performance computing environment and at some point he migrated so many processes that he got a PhD for that and since he joined Red Hat he started to migrate containers. Occasionally he still migrates single processes and is still interested in high performance computing topics.[More about me][12] + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/1/how-build-hpc-system-raspberry-pi-and-openhpc + +作者:[Adrian Reber ][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/adrianreber +[1]:https://opensource.com/resources/what-are-linux-containers?utm_campaign=containers&intcmp=70160000000h1s6AAA +[2]:https://opensource.com/resources/what-docker?utm_campaign=containers&intcmp=70160000000h1s6AAA +[3]:https://opensource.com/resources/what-is-kubernetes?utm_campaign=containers&intcmp=70160000000h1s6AAA +[4]:https://developers.redhat.com/blog/2016/01/13/a-practical-introduction-to-docker-container-terminology/?utm_campaign=containers&intcmp=70160000000h1s6AAA +[5]:https://opensource.com/file/384031 +[6]:https://opensource.com/file/384016 +[7]:https://opensource.com/file/384021 +[8]:https://opensource.com/file/384026 +[9]:https://opensource.com/article/18/1/how-build-hpc-system-raspberry-pi-and-openhpc?rate=l9n6B6qRcR20LJyXEoUoWEZ4mb2nDc9sFZ1YSPc60vE +[10]:https://devconfcz2018.sched.com/event/DJYi/openhpc-introduction +[11]:https://wiki.centos.org/Events/Dojo/Brussels2018 +[12]:https://opensource.com/users/adrianreber +[13]:https://opensource.com/user/188446/feed +[14]:https://opensource.com/article/17/11/openhpc +[15]:https://openhpc.community/ +[16]:https://openhpc.community/downloads/ +[17]:https://github.com/openhpc/ohpc/releases/download/v1.3.3.GA/Install_guide-CentOS7-Warewulf-SLURM-1.3.3-aarch64.pdf +[18]:https://en.wikipedia.org/wiki/Warewulf +[19]:http://people.redhat.com/areber/openhpc/ansible/ +[20]:https://www.open-mpi.org/ +[21]:https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life +[22]:https://www.youtube.com/watch?v=n8DvxMcOMXk +[23]:https://opensource.com/users/adrianreber +[24]:https://opensource.com/users/adrianreber +[25]:https://opensource.com/users/adrianreber +[26]:https://www.ansible.com/ +[27]:https://slurm.schedmd.com/ +[28]:https://opensource.com/tags/raspberry-pi +[29]:https://opensource.com/tags/programming +[30]:https://opensource.com/tags/linux +[31]:https://opensource.com/tags/ansible \ No newline at end of file diff --git a/sources/tech/20180125 Linux whereis Command Explained for Beginners (5 Examples).md b/sources/tech/20180125 Linux whereis Command Explained for Beginners (5 Examples).md deleted file mode 100644 index 45107b050c..0000000000 --- a/sources/tech/20180125 Linux whereis Command Explained for Beginners (5 Examples).md +++ /dev/null @@ -1,108 +0,0 @@ -Linux whereis Command Explained for Beginners (5 Examples) -====== - -Sometimes, while working on the command line, we just need to quickly find out the location of the binary file for a command. Yes, the [find][1] command is an option in this case, but it's a bit time consuming and will likely produce some non-desired results as well. There's a specific command that's designed for this purpose: **whereis**. - -In this article, we will discuss the basics of this command using some easy to understand examples. But before we do that, it's worth mentioning that all examples in this tutorial have been tested on Ubuntu 16.04LTS. - -### Linux whereis command - -The whereis command lets users locate binary, source, and manual page files for a command. Following is its syntax: - -``` -whereis [options] [-BMS directory... -f] name... -``` - -And here's how the tool's man page explains it: -``` -whereis locates the binary, source and manual files for the specified command names. The supplied -names are first stripped of leading pathname components and any (single) trailing extension of the -form .ext (for example: .c) Prefixes of s. resulting from use of source code control are also dealt -with. whereis then attempts to locate the desired program in the standard Linux places, and in the -places specified by $PATH and $MANPATH. -``` - -The following Q&A-styled examples should give you a good idea on how the whereis command works. - -### Q1. How to find location of binary file using whereis? - -Suppose you want to find the location for, let's say, the whereis command itself. Then here's how you can do that: - -``` -whereis whereis -``` - -[![How to find location of binary file using whereis][2]][3] - -Note that the first path in the output is what you are looking for. The whereis command also produces paths for manual pages and source code (if available, which isn't in this case). So the second path you see in the output above is the path to the whereis manual file(s). - -### Q2. How to specifically search for binaries, manuals, or source code? - -If you want to search specifically for, say binary, then you can use the **-b** command line option. For example: - -``` -whereis -b cp -``` - -[![How to specifically search for binaries, manuals, or source code][4]][5] - -Similarly, the **-m** and **-s** options are used in case you want to find manuals and sources. - -### Q3. How to limit whereis search as per requirement? - -By default whereis tries to find files from hard-coded paths, which are defined with glob patterns. However, if you want, you can limit the search using specific command line options. For example, if you want whereis to only search for binary files in /usr/bin, then you can do this using the **-B** command line option. - -``` -whereis -B /usr/bin/ -f cp -``` - -**Note** : Since you can pass multiple paths this way, the **-f** command line option terminates the directory list and signals the start of file names. - -Similarly, if you want to limit manual or source searches, you can use the **-M** and **-S** command line options. - -### Q4. How to see paths that whereis uses for search? - -There's an option for this as well. Just run the command with **-l**. - -``` -whereis -l -``` - -Here is the list (partial) it produced for us: - -[![How to see paths that whereis uses for search][6]][7] - -### Q5. How to find command names with unusual entries? - -For whereis, a command becomes unusual if it does not have just one entry of each explicitly requested type. For example, commands with no documentation available, or those with documentation in multiple places are considered unusual. The **-u** command line option, when used, makes whereis show the command names that have unusual entries. - -For example, the following command should display files in the current directory which have no documentation file, or more than one. - -``` -whereis -m -u * -``` - -### Conclusion - -Agreed, whereis is not the kind of command line tool that you'll require very frequently. But when the situation arises, it definitely makes your life easy. We've covered some of the important command line options the tool offers, so do practice them. For more info, head to its [man page][8]. - - --------------------------------------------------------------------------------- - -via: https://www.howtoforge.com/linux-whereis-command/ - -作者:[Himanshu Arora][a] -译者:[译者ID](https://github.com/译者ID) -校对:[校对者ID](https://github.com/校对者ID) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 - -[a]:https://www.howtoforge.com -[1]:https://www.howtoforge.com/tutorial/linux-find-command/ -[2]:https://www.howtoforge.com/images/command-tutorial/whereis-basic-usage.png -[3]:https://www.howtoforge.com/images/command-tutorial/big/whereis-basic-usage.png -[4]:https://www.howtoforge.com/images/command-tutorial/whereis-b-option.png -[5]:https://www.howtoforge.com/images/command-tutorial/big/whereis-b-option.png -[6]:https://www.howtoforge.com/images/command-tutorial/whereis-l.png -[7]:https://www.howtoforge.com/images/command-tutorial/big/whereis-l.png -[8]:https://linux.die.net/man/1/whereis diff --git a/sources/tech/20180126 An introduction to the Web Simple Perl module a minimalist web framework.md b/sources/tech/20180126 An introduction to the Web Simple Perl module a minimalist web framework.md new file mode 100644 index 0000000000..ab8c29b2b6 --- /dev/null +++ b/sources/tech/20180126 An introduction to the Web Simple Perl module a minimalist web framework.md @@ -0,0 +1,106 @@ +An introduction to the Web::Simple Perl module, a minimalist web framework +============================================================ + +### Perl module Web::Simple is easy to learn and packs a big enough punch for a variety of one-offs and smaller services. + + +![An introduction to the Web::Simple Perl module, a minimalist web framework](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/openweb-osdc-lead.png?itok=yjU4KliG "An introduction to the Web::Simple Perl module, a minimalist web framework") +Image credits : [You as a Machine][10]. Modified by Rikki Endsley. [CC BY-SA 2.0][11]. + +One of the more-prominent members of the Perl community is [Matt Trout][12], technical director at [Shadowcat Systems][13]. He's been building core tools for Perl applications for years, including being a co-maintaner of the [Catalyst][14] MVC (Model, View, Controller) web framework, creator of the [DBIx::Class][15] object-management system, and much more. In person, he's energetic, interesting, brilliant, and sometimes hard to keep up with. When Matt writes code…well, think of a runaway chainsaw, with the trigger taped down and the safety features disabled. He's off and running, and you never quite know what will come out. Two things are almost certain: the module will precisely fit the purpose Matt has in mind, and it will show up on CPAN for others to use. + + +One of Matt's special-purpose modules is [Web::Simple][23]. Touted as "a quick and easy way to build simple web applications," it is a stripped-down, minimalist web framework, with an easy to learn interface. Web::Simple is not at all designed for a large-scale application; however, it may be ideal for a small tool that does one or two things in a lower-traffic environment. I can also envision it being used for rapid prototyping if you wanted to create quick wireframes of a new application for demonstrations. + +### Installation, and a quick "Howdy!" + +You can install the module using `cpan` or `cpanm`. Once you've got it installed, you're ready to write simple web apps without having to hassle with managing the connections or any of that—just your functionality. Here's a quick example: + +``` +#!/usr/bin/perl +package HelloReader; +use Web::Simple; + +sub dispatch_request { +  GET => sub { +    [ 200, [ 'Content-type', 'text/plain' ], [ 'Howdy, Opensource.com reader!' ] ] +  }, +  '' => sub { +    [ 405, [ 'Content-type', 'text/plain' ], [ 'You cannot do that, friend. Sorry.' ] ] +  } +} + +HelloReader->run_if_script; +``` + +There are a couple of things to notice right off. For one, I didn't `use strict` and `use warnings` like I usually would. Web::Simple imports those for you, so you don't have to. It also imports [Moo][16], a minimalist OO framework, so if you know Moo and want to use it here, you can! The heart of the system lies in the `dispatch_request`method, which you must define in your application. Each entry in the method is a match string, followed by a subroutine to respond if that string matches. The subroutine must return an array reference containing status, headers, and content of the reply to the request. + +### Matching + +The matching system in Web::Simple is powerful, allowing for complicated matches, passing parameters in a URL, query parameters, and extension matches, in pretty much any combination you want. As you can see in the example above, starting with a capital letter will match on the request method, and you can combine that with a path match easily: + +``` +'GET + /person/*' => sub { +  my ($self, $person) = @_; +  # write some code to retrieve and display a person +  }, +'POST + /person/* + %*' => sub { +  my ($self, $person, $params) = @_; +  # write some code to modify a person, perhaps +  } +``` + +In the latter case, the third part of the match indicates that we should pick up all the POST parameters and put them in a hashref called `$params` for use by the subroutine. Using `?` instead of `%` in that part of the match would pick up query parameters, as normally used in a GET request. There's also a useful exported subroutine called `redispatch_to`. This tool lets you redirect, without using a 3xx redirect; it's handled internally, invisible to the user. So: + +``` +'GET + /some/url' => sub { +  redispatch_to '/some/other/url'; +} +``` + +A GET request to `/some/url` would get handled as if it was sent to `/some/other/url`, without a redirect, and the user won't see a redirect in their browser. + +I've just scratched the surface with this module. If you're looking for something production-ready for larger projects, you'll be better off with [Dancer][17] or [Catalyst][18]. But with its light weight and built-in Moo integration, Web::Simple packs a big enough punch for a variety of one-offs and smaller services. + +### About the author + + [![](https://opensource.com/sites/default/files/styles/profile_pictures/public/pictures/dsc_0028.jpg?itok=RS0GBh25)][19] Ruth Holloway - Ruth Holloway has been a system administrator and software developer for a long, long time, getting her professional start on a VAX 11/780, way back when. She spent a lot of her career (so far) serving the technology needs of libraries, and has been a contributor since 2008 to the Koha open source library automation suite.Ruth is currently a Perl Developer at cPanel in Houston, and also serves as chief of staff for an obnoxious cat. In her copious free time, she occasionally reviews old romance... [more about Ruth Holloway][7][More about me][8] + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/1/introduction-websimple-perl-module-minimalist-web-framework + +作者:[Ruth Holloway ][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/druthb +[1]:https://opensource.com/tags/python?src=programming_resource_menu1 +[2]:https://opensource.com/tags/javascript?src=programming_resource_menu2 +[3]:https://opensource.com/tags/perl?src=programming_resource_menu3 +[4]:https://developers.redhat.com/?intcmp=7016000000127cYAAQ&src=programming_resource_menu4 +[5]:http://perldoc.perl.org/functions/package.html +[6]:https://opensource.com/article/18/1/introduction-websimple-perl-module-minimalist-web-framework?rate=ICN35y076ElpInDKoMqp-sN6f4UVF-n2Qt6dL6lb3kM +[7]:https://opensource.com/users/druthb +[8]:https://opensource.com/users/druthb +[9]:https://opensource.com/user/36051/feed +[10]:https://www.flickr.com/photos/youasamachine/8025582590/in/photolist-decd6C-7pkccp-aBfN9m-8NEffu-3JDbWb-aqf5Tx-7Z9MTZ-rnYTRu-3MeuPx-3yYwA9-6bSLvd-irmvxW-5Asr4h-hdkfCA-gkjaSQ-azcgct-gdV5i4-8yWxCA-9G1qDn-5tousu-71V8U2-73D4PA-iWcrTB-dDrya8-7GPuxe-5pNb1C-qmnLwy-oTxwDW-3bFhjL-f5Zn5u-8Fjrua-bxcdE4-ddug5N-d78G4W-gsYrFA-ocrBbw-pbJJ5d-682rVJ-7q8CbF-7n7gDU-pdfgkJ-92QMx2-aAmM2y-9bAGK1-dcakkn-8rfyTz-aKuYvX-hqWSNP-9FKMkg-dyRPkY +[11]:https://creativecommons.org/licenses/by/2.0/ +[12]:https://shadow.cat/resources/bios/matt_short/ +[13]:https://shadow.cat/ +[14]:https://metacpan.org/pod/Catalyst +[15]:https://metacpan.org/pod/DBIx::Class +[16]:https://metacpan.org/pod/Moo +[17]:http://perldancer.org/ +[18]:http://www.catalystframework.org/ +[19]:https://opensource.com/users/druthb +[20]:https://opensource.com/users/druthb +[21]:https://opensource.com/users/druthb +[22]:https://opensource.com/article/18/1/introduction-websimple-perl-module-minimalist-web-framework#comments +[23]:https://metacpan.org/pod/Web::Simple +[24]:https://opensource.com/tags/perl +[25]:https://opensource.com/tags/programming +[26]:https://opensource.com/tags/perl-column +[27]:https://opensource.com/tags/web-development \ No newline at end of file diff --git a/sources/tech/20180126 Creating an Adventure Game in the Terminal with ncurses.md b/sources/tech/20180126 Creating an Adventure Game in the Terminal with ncurses.md new file mode 100644 index 0000000000..221c53a4ed --- /dev/null +++ b/sources/tech/20180126 Creating an Adventure Game in the Terminal with ncurses.md @@ -0,0 +1,324 @@ +Creating an Adventure Game in the Terminal with ncurses +====== +How to use curses functions to read the keyboard and manipulate the screen. + +My [previous article][1] introduced the ncurses library and provided a simple program that demonstrated a few curses functions to put text on the screen. In this follow-up article, I illustrate how to use a few other curses functions. + +### An Adventure + +When I was growing up, my family had an Apple II computer. It was on this machine that my brother and I taught ourselves how to write programs in AppleSoft BASIC. After writing a few math puzzles, I moved on to creating games. Having grown up in the 1980s, I already was a fan of the Dungeons and Dragons tabletop games, where you role-played as a fighter or wizard on some quest to defeat monsters and plunder loot in strange lands. So it shouldn't be surprising that I also created a rudimentary adventure game. + +The AppleSoft BASIC programming environment supported a neat feature: in standard resolution graphics mode (GR mode), you could probe the color of a particular pixel on the screen. This allowed a shortcut to create an adventure game. Rather than create and update an in-memory map that was transferred to the screen periodically, I could rely on GR mode to maintain the map for me, and my program could query the screen as the player's character moved around the screen. Using this method, I let the computer do most of the hard work. Thus, my top-down adventure game used blocky GR mode graphics to represent my game map. + +My adventure game used a simple map that represented a large field with a mountain range running down the middle and a large lake on the upper-left side. I might crudely draw this map for a tabletop gaming campaign to include a narrow path through the mountains, allowing the player to pass to the far side. + +![](http://www.linuxjournal.com/files/linuxjournal.com/ufiles/imagecache/large-550px-centered/u1000009/quest-map.jpg) + +Figure 1. A simple Tabletop Game Map with a Lake and Mountains + +You can draw this map in cursesusing characters to represent grass, mountains and water. Next, I describe how to do just that using curses functions and how to create and play a similar adventure game in the Linux terminal. + +### Constructing the Program + +In my last article, I mentioned that most curses programs start with the same set of instructions to determine the terminal type and set up the curses environment: + +``` +initscr(); +cbreak(); +noecho(); + +``` + +For this program, I add another statement: + +``` +keypad(stdscr, TRUE); + +``` + +The TRUE flag allows curses to read the keypad and function keys from the user's terminal. If you want to use the up, down, left and right arrow keys in your program, you need to use keypad(stdscr, TRUE) here. + +Having done that, you now can start drawing to the terminal screen. The curses functions include several ways to draw text on the screen. In my previous article, I demonstrated the addch() and addstr() functions and their associated mvaddch() and mvaddstr() counterparts that first moved to a specific location on the screen before adding text. To create the adventure game map on the terminal, you can use another set of functions: vline() and hline(), and their partner functions mvvline() and mvhline(). These mv functions accept screen coordinates, a character to draw and how many times to repeat that character. For example, mvhline(1, 2, '-', 20) will draw a line of 20 dashes starting at line 1, column 2. + +To draw the map to the terminal screen programmatically, let's define this draw_map() function: + +``` +#define GRASS ' ' +#define EMPTY '.' +#define WATER '~' +#define MOUNTAIN '^' +#define PLAYER '*' + +void draw_map(void) +{ + int y, x; + + /* draw the quest map */ + + /* background */ + + for (y = 0; y < LINES; y++) { + mvhline(y, 0, GRASS, COLS); + } + + /* mountains, and mountain path */ + + for (x = COLS / 2; x < COLS * 3 / 4; x++) { + mvvline(0, x, MOUNTAIN, LINES); + } + + mvhline(LINES / 4, 0, GRASS, COLS); + + /* lake */ + + for (y = 1; y < LINES / 2; y++) { + mvhline(y, 1, WATER, COLS / 3); + } +} + +``` + +In drawing this map, note the use of mvvline() and mvhline() to fill large chunks of characters on the screen. I created the fields of grass by drawing horizontal lines (mvhline) of characters starting at column 0, for the entire height and width of the screen. I added the mountains on top of that by drawing vertical lines (mvvline), starting at row 0, and a mountain path by drawing a single horizontal line (mvhline). And, I created the lake by drawing a series of short horizontal lines (mvhline). It may seem inefficient to draw overlapping rectangles in this way, but remember that curses doesn't actually update the screen until I call the refresh() function later. + +Having drawn the map, all that remains to create the game is to enter a loop where the program waits for the user to press one of the up, down, left or right direction keys and then moves a player icon appropriately. If the space the player wants to move into is unoccupied, it allows the player to go there. + +You can use curses as a shortcut. Rather than having to instantiate a version of the map in the program and replicate this map to the screen, you can let the screen keep track of everything for you. The inch() function, and associated mvinch() function, allow you to probe the contents of the screen. This allows you to query curses to find out whether the space the player wants to move into is already filled with water or blocked by mountains. To do this, you'll need a helper function that you'll use later: + +``` +int is_move_okay(int y, int x) +{ + int testch; + + /* return true if the space is okay to move into */ + + testch = mvinch(y, x); + return ((testch == GRASS) || (testch == EMPTY)); +} + +``` + +As you can see, this function probes the location at column y, row x and returns true if the space is suitably unoccupied, or false if not. + +That makes it really easy to write a navigation loop: get a key from the keyboard and move the user's character around depending on the up, down, left and right arrow keys. Here's a simplified version of that loop: + +``` + + do { + ch = getch(); + + /* test inputted key and determine direction */ + + switch (ch) { + case KEY_UP: + if ((y > 0) && is_move_okay(y - 1, x)) { + y = y - 1; + } + break; + case KEY_DOWN: + if ((y < LINES - 1) && is_move_okay(y + 1, x)) { + y = y + 1; + } + break; + case KEY_LEFT: + if ((x > 0) && is_move_okay(y, x - 1)) { + x = x - 1; + } + break; + case KEY_RIGHT + if ((x < COLS - 1) && is_move_okay(y, x + 1)) { + x = x + 1; + } + break; + } + } + while (1); + +``` + +To use this in a game, you'll need to add some code inside the loop to allow other keys (for example, the traditional WASD movement keys), provide a method for the user to quit the game and move the player's character around the screen. Here's the program in full: + +``` + +/* quest.c */ + +#include +#include + +#define GRASS ' ' +#define EMPTY '.' +#define WATER '~' +#define MOUNTAIN '^' +#define PLAYER '*' + +int is_move_okay(int y, int x); +void draw_map(void); + +int main(void) +{ + int y, x; + int ch; + + /* initialize curses */ + + initscr(); + keypad(stdscr, TRUE); + cbreak(); + noecho(); + + clear(); + + /* initialize the quest map */ + + draw_map(); + + /* start player at lower-left */ + + y = LINES - 1; + x = 0; + + do { + /* by default, you get a blinking cursor - use it to indicate player */ + + mvaddch(y, x, PLAYER); + move(y, x); + refresh(); + + ch = getch(); + + /* test inputted key and determine direction */ + + switch (ch) { + case KEY_UP: + case 'w': + case 'W': + if ((y > 0) && is_move_okay(y - 1, x)) { + mvaddch(y, x, EMPTY); + y = y - 1; + } + break; + case KEY_DOWN: + case 's': + case 'S': + if ((y < LINES - 1) && is_move_okay(y + 1, x)) { + mvaddch(y, x, EMPTY); + y = y + 1; + } + break; + case KEY_LEFT: + case 'a': + case 'A': + if ((x > 0) && is_move_okay(y, x - 1)) { + mvaddch(y, x, EMPTY); + x = x - 1; + } + break; + case KEY_RIGHT: + case 'd': + case 'D': + if ((x < COLS - 1) && is_move_okay(y, x + 1)) { + mvaddch(y, x, EMPTY); + x = x + 1; + } + break; + } + } + while ((ch != 'q') && (ch != 'Q')); + + endwin(); + + exit(0); +} + +int is_move_okay(int y, int x) +{ + int testch; + + /* return true if the space is okay to move into */ + + testch = mvinch(y, x); + return ((testch == GRASS) || (testch == EMPTY)); +} + +void draw_map(void) +{ + int y, x; + + /* draw the quest map */ + + /* background */ + + for (y = 0; y < LINES; y++) { + mvhline(y, 0, GRASS, COLS); + } + + /* mountains, and mountain path */ + + for (x = COLS / 2; x < COLS * 3 / 4; x++) { + mvvline(0, x, MOUNTAIN, LINES); + } + + mvhline(LINES / 4, 0, GRASS, COLS); + + /* lake */ + + for (y = 1; y < LINES / 2; y++) { + mvhline(y, 1, WATER, COLS / 3); + } +} + +``` + +In the full program listing, you can see the complete arrangement of curses functions to create the game: + +1) Initialize the curses environment. + +2) Draw the map. + +3) Initialize the player coordinates (lower-left). + +4) Loop: + +* Draw the player's character. + +* Get a key from the keyboard. + +* Adjust the player's coordinates up, down, left or right, accordingly. + +* Repeat. + +5) When done, close the curses environment and exit. + +### Let's Play + +When you run the game, the player's character starts in the lower-left corner. As the player moves around the play area, the program creates a "trail" of dots. This helps show where the player has been before, so the player can avoid crossing the path unnecessarily. + +![](http://www.linuxjournal.com/files/linuxjournal.com/ufiles/imagecache/large-550px-centered/u1000009/quest-start.png) + +Figure 2\. The player starts the game in the lower-left corner. + +![](http://www.linuxjournal.com/files/linuxjournal.com/ufiles/imagecache/large-550px-centered/u1000009/quest-1.png) + +Figure 3\. The player can move around the play area, such as around the lake and through the mountain pass. + +To create a complete adventure game on top of this, you might add random encounters with various monsters as the player navigates his or her character around the play area. You also could include special items the player could discover or loot after defeating enemies, which would enhance the player's abilities further. + +But to start, this is a good program for demonstrating how to use the curses functions to read the keyboard and manipulate the screen. + +### Next Steps + +This program is a simple example of how to use the curses functions to update and read the screen and keyboard. You can do so much more with curses, depending on what you need your program to do. In a follow up article, I plan to show how to update this sample program to use colors. In the meantime, if you are interested in learning more about curses, I encourage you to read Pradeep Padala's [NCURSES Programming HOWTO][2] at the Linux Documentation Project. + + +-------------------------------------------------------------------------------- + +via: http://www.linuxjournal.com/content/creating-adventure-game-terminal-ncurses + +作者:[Jim Hall][a] +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:http://www.linuxjournal.com/users/jim-hall +[1]:http://www.linuxjournal.com/content/getting-started-ncurses +[2]:http://tldp.org/HOWTO/NCURSES-Programming-HOWTO diff --git a/sources/tech/20180126 How To Manage NodeJS Packages Using Npm.md b/sources/tech/20180126 How To Manage NodeJS Packages Using Npm.md new file mode 100644 index 0000000000..ac27816a7b --- /dev/null +++ b/sources/tech/20180126 How To Manage NodeJS Packages Using Npm.md @@ -0,0 +1,372 @@ +How To Manage NodeJS Packages Using Npm +====== + +![](https://www.ostechnix.com/wp-content/uploads/2018/01/npm-720x340.png) + +A while ago, we have published a guide to [**manage Python packages using PIP**][1]. Today, we are going to discuss how to manage NodeJS packages using Npm. NPM is the largest software registry that contains over 600,000 packages. Everyday, developers across the world shares and downloads packages through npm. In this guide, I will explain the the basics of working with npm, such as installing packages(locally and globally), installing certain version of a package, updating, removing and managing NodeJS packages and so on. + +### Manage NodeJS Packages Using Npm + +##### Installing NPM + +Since npm is written in NodeJS, we need to install NodeJS in order to use npm. To install NodeJS on different Linux distributions, refer the following link. + +Once installed, ensure that NodeJS and NPM have been properly installed. There are couple ways to do this. + +To check where node has been installed: +``` +$ which node +/home/sk/.nvm/versions/node/v9.4.0/bin/node +``` + +Check its version: +``` +$ node -v +v9.4.0 +``` + +Log in to Node REPL session: +``` +$ node +> .help +.break Sometimes you get stuck, this gets you out +.clear Alias for .break +.editor Enter editor mode +.exit Exit the repl +.help Print this help message +.load Load JS from a file into the REPL session +.save Save all evaluated commands in this REPL session to a file +> .exit +``` + +Check where npm installed: +``` +$ which npm +/home/sk/.nvm/versions/node/v9.4.0/bin/npm +``` + +And the version: +``` +$ npm -v +5.6.0 +``` + +Great! Node and NPM have been installed and are working! As you may have noticed, I have installed NodeJS and NPM in my $HOME directory to avoid permission issues while installing modules globally. This is the recommended method by NodeJS team. + +Well, let us go ahead to see managing NodeJS modules (or packages) using npm. + +##### Installing NodeJS modules + +NodeJS modules can either be installed locally or globally(system wide). Now I am going to show how to install a package locally. + +**Install packages locally** + +To manage packages locally, we normally use **package.json** file. + +First, let us create our project directory. +``` +$ mkdir demo +``` +``` +$ cd demo +``` + +Create a package.json file inside your project's directory. To do so, run: +``` +$ npm init +``` + +Enter the details of your package such as name, version, author, github page etc., or just hit ENTER key to accept the default values and type **YES** to confirm. +``` +This utility will walk you through creating a package.json file. +It only covers the most common items, and tries to guess sensible defaults. + +See `npm help json` for definitive documentation on these fields +and exactly what they do. + +Use `npm install ` afterwards to install a package and +save it as a dependency in the package.json file. + +Press ^C at any time to quit. +package name: (demo) +version: (1.0.0) +description: demo nodejs app +entry point: (index.js) +test command: +git repository: +keywords: +author: +license: (ISC) +About to write to /home/sk/demo/package.json: + +{ + "name": "demo", + "version": "1.0.0", + "description": "demo nodejs app", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "", + "license": "ISC" +} + +Is this ok? (yes) yes +``` + +The above command initializes your project and create package.json file. + +You can also do this non-interactively using command: +``` +npm init --y +``` + +This will create a package.json file quickly with default values without the user interaction. + +Now let us install package named [**commander**][2]. +``` +$ npm install commander +``` + +Sample output: +``` +npm notice created a lockfile as package-lock.json. You should commit this file. +npm WARN demo@1.0.0 No repository field. + ++ commander@2.13.0 +added 1 package in 2.519s +``` + +This will create a directory named **" node_modules"** (if it doesn't exist already) in the project's root directory and download the packages in it. + +Let us check the package.json file. +``` +$ cat package.json +{ + "name": "demo", + "version": "1.0.0", + "description": "demo nodejs app", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "", + "license": "ISC", + **"dependencies": {** +**"commander": "^2.13.0"** + } +} +``` + +You will see the dependencies have been added. The caret ( **^** ) at the front of the version number indicates that when installing, npm will pull the highest version of the package it can find. +``` +$ ls node_modules/ +commander +``` + +The advantage of package.json file is if you had the package.json file in your project's directory, you can just type "npm install", then npm will look into the dependencies that listed in the file and download all of them. You can even share it with other developers or push into your GitHub repository, so when they type "npm install", they will get all the same packages that you have. + +You may also noticed another json file named **package-lock.json**. This file ensures that the dependencies remain the same on all systems the project is installed on. + +To use the installed package in your program, create a file **index.js** (or any name of you choice) in the project's directory with the actual code, and then run it using command: +``` +$ node index.js +``` + +**Install packages globally** + +If you want to use a package as a command line tool, then it is better to install it globally. This way, it works no matter which directory is your current directory. +``` +$ npm install async -g ++ async@2.6.0 +added 2 packages in 4.695s +``` + +Or, +``` +$ npm install async --global +``` + +To install a specific version of a package, we do: +``` +$ npm install async@2.6.0 --global +``` + +##### Updating NodeJS modules + +To update the local packages, go the the project's directory where the package.json is located and run: +``` +$ npm update +``` + +Then, run the following command to ensure all packages were updated. +``` +$ npm outdated +``` + +If there is no update, then it returns nothing. + +To find out which global packages need to be updated, run: +``` +$ npm outdated -g --depth=0 +``` + +If there is no output, then all packages are updated. + +To update the a single global package, run: +``` +$ npm update -g +``` + +To update all global packages, run: +``` +$ npm update -g +``` + +##### Listing NodeJS modules + +To list the local packages, go the project's directory and run: +``` +$ npm list +demo@1.0.0 /home/sk/demo +└── commander@2.13.0 +``` + +As you see, I have installed "commander" package in local mode. + +To list global packages, run this command from any location: +``` +$ npm list -g +``` + +Sample output: +``` +/home/sk/.nvm/versions/node/v9.4.0/lib +├─┬ async@2.6.0 +│ └── lodash@4.17.4 +└─┬ npm@5.6.0 + ├── abbrev@1.1.1 + ├── ansi-regex@3.0.0 + ├── ansicolors@0.3.2 + ├── ansistyles@0.1.3 + ├── aproba@1.2.0 + ├── archy@1.0.0 +[...] +``` + +This command will list all modules and their dependencies. + +To list only the top level modules, use -depth=0 option: +``` +$ npm list -g --depth=0 +/home/sk/.nvm/versions/node/v9.4.0/lib +├── async@2.6.0 +└── npm@5.6.0 +``` + +##### Searching NodeJS modules + +To search for a module, use "npm search" command: +``` +npm search +``` + +Example: +``` +$ npm search request +``` + +This command will display all modules that contains the search string "request". + +##### Removing NodeJS modules + +To remove a local package, go to the project's directory and run following command to remove the package from your **node_modules** directory: +``` +$ npm uninstall +``` + +To remove it from the dependencies in **package.json** file, use the **save** flag like below: +``` +$ npm uninstall --save + +``` + +To remove the globally installed packages, run: +``` +$ npm uninstall -g +``` + +##### Cleaning NPM cache + +By default, NPM keeps the copy of a installed package in the cache folder named npm in your $HOME directory when installing it. So, you can install it next time without having to download again. + +To view the cached modules: +``` +$ ls ~/.npm +``` + +The cache folder gets flooded with all old packages over time. It is better to clean the cache from time to time. + +As of npm@5, the npm cache self-heals from corruption issues and data extracted from the cache is guaranteed to be valid. If you want to make sure everything is consistent, run: +``` +$ npm cache verify +``` + +To clear the entire cache, run: +``` +$ npm cache clean --force +``` + +##### Viewing NPM configuration + +To view the npm configuration, type: +``` +$ npm config list +``` + +Or, +``` +$ npm config ls +``` + +Sample output: +``` +; cli configs +metrics-registry = "https://registry.npmjs.org/" +scope = "" +user-agent = "npm/5.6.0 node/v9.4.0 linux x64" + +; node bin location = /home/sk/.nvm/versions/node/v9.4.0/bin/node +; cwd = /home/sk +; HOME = /home/sk +; "npm config ls -l" to show all defaults. +``` + +To display the current global location: +``` +$ npm config get prefix +/home/sk/.nvm/versions/node/v9.4.0 +``` + +And, that's all for now. What we have just covered here is just the basics. NPM is a vast topic. For more details, head over to the the [**NPM Getting Started**][3] guide. + +Hope this was useful. More good stuffs to come. Stay tuned! + +Cheers! + + + +-------------------------------------------------------------------------------- + +via: https://www.ostechnix.com/manage-nodejs-packages-using-npm/ + +作者:[SK][a] +译者:[译者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.npmjs.com/package/commander +[3]:https://docs.npmjs.com/getting-started/ diff --git a/sources/tech/20180126 How to Make a Minecraft Server - ThisHosting.Rocks.md b/sources/tech/20180126 How to Make a Minecraft Server - ThisHosting.Rocks.md new file mode 100644 index 0000000000..30c6ccc54e --- /dev/null +++ b/sources/tech/20180126 How to Make a Minecraft Server - ThisHosting.Rocks.md @@ -0,0 +1,418 @@ +translating by heart4lor + +How to Make a Minecraft Server – ThisHosting.Rocks +====== +We’ll show you how to make a Minecraft server with beginner-friendly step-by-step instructions. It will be a persistent multiplayer server that you can play on with your friends from all around the world. You don’t have to be in a LAN. + +### How to Make a Minecraft Server – Quick Guide + +This is our “Table of contents” if you’re in a hurry and want to go straight to the point. We recommend reading everything though. + +* [Learn stuff][1] (optional) + +* [Learn more stuff][2] (optional) + +* [Requirements][3] (required) + +* [Install and start the Minecraft server][4] (required) + +* [Run the server even after you log out of your VPS][5] (optional) + +* [Make the server automatically start at boot][6] (optional) + +* [Configure your Minecraft server][7] (required) + +* [FAQs][8] (optional) + +Before going into the actual instructions, a few things you should know: + +#### Reasons why you would NOT use a specialized Minecraft server hosting provider + +Since you’re here, you’re obviously interested in hosting your own Minecraft server. There are more reasons why you would not use a specialized Minecraft hosting provider, but here are a few: + +* They’re slow most of the time. This is because you actually share the resources with multiple users. It becomes overloaded at some point. Most of them oversell their servers too. + +* You don’t have full control over the Minecraft server or the actual server. You cannot customize anything you want to. + +* You’re limited. Those kinds of hosting plans are always limited in one way or another. + +Of course, there are positives to using a Minecraft hosting provider. The best upside is that you don’t actually have to do all the stuff we’ll write about below. But where’s the fun in that? +![🙂](https://s.w.org/images/core/emoji/2.3/svg/1f642.svg) + +#### Why you should NOT use your personal computer to make a Minecraft server + +We noticed lots of tutorials showing you how to host a server on your own computer. There are downsides to doing that, like: + +* Your home internet is not secured enough to handle DDoS attacks. Game servers are often prone to DDoS attacks, and your home network setup is most probably not secured enough to handle them. It’s most likely not powerful enough to handle a small attack. + +* You’ll need to handle port forwarding. If you’ve tried making a Minecraft server on your home network, you’ve surely stumbled upon port forwarding and had issues with it. + +* You’ll need to keep your computer on at all times. Your electricity bill will sky-rocket and you’ll add unnecessary load to your hardware. The hardware most servers use is enterprise-grade and designed to handle loads, with improved stability and longevity. + +* Your home internet is not fast enough. Home networks are not designed to handle multiplayer games. You’ll need a much larger internet plan to even consider making a small server. Luckily, data centers have multiple high-speed, enterprise-grade internet connections making sure they have (or strive to have) 100% uptime. + +* Your hardware is most likely not good enough. Again, servers use enterprise-grade hardware, latest and fastest CPUs, SSDs, and much more. Your personal computer most likely does not. + +* You probably use Windows/MacOS on your personal computer. Though this is debatable, we believe that Linux is much better for game hosting. Don’t worry, you don’t really need to know everything about Linux to make a Minecraft server (though it’s recommended). We’ll show you everything you need to know. + +Our tip is not to use your personal computer, though technically you can. It’s not expensive to buy a cloud server. We’ll show you how to make a Minecraft server on cloud hosting below. It’s easy if you carefully follow the steps. + +### Making a Minecraft Server – Requirements + +There are a few requirements. You should have and know all of this before continuing to the tutorial: + +* You’ll need a [Linux cloud server][9]. We recommend [Vultr][10]. Their prices are cheap, services are high-quality, customer support is great, all server hardware is high-end. Check the [Minecraft server requirements][11] to find out what kind of server you should get (resources like RAM and Disk space). We recommend getting the $20 per month server. They support hourly pricing so if you only need the server temporary for playing with friends, you’ll pay less. Choose the Ubuntu 16.04 distro during signup. Choose the closest server location to where your players live during the signup process. Keep in mind that you’ll be responsible for your server. So you’ll have to secure it and manage it. If you don’t want to do that, you can get a [managed server][12], in which case the hosting provider will likely make a Minecraft server for you. + +* You’ll need an SSH client to connect to the Linux cloud server. [PuTTy][13] is often recommended for beginners, but we also recommend [MobaXTerm][14]. There are many other SSH clients to choose from, so pick your favorite. + +* You’ll need to setup your server (basic security setup at least). Google it and you’ll find many tutorials. You can use [Linode’s Security Guide][15] and follow the exact steps on your [Vultr][16] server. + +* We’ll handle the software requirements like Java below. + +And finally, onto our actual tutorial: + +### How to Make a Minecraft Server on Ubuntu (Linux) + +These instructions are written for and tested on an Ubuntu 16.04 server from [Vultr][17]. Though they’ll also work on Ubuntu 14.04, [Ubuntu 18.04][18], and any other Ubuntu-based distro, and any other server provider. + +We’re using the default Vanilla server from Minecraft. You can use alternatives like CraftBukkit or Spigot that allow more customizations and plugins. Though if you use too many plugins you’ll essentially ruin the server. There are pros and cons to each one. Nevertheless, the instructions below are for the default Vanilla server to keep things simple and beginner-friendly. We may publish a tutorial for CraftBukkit soon if there’s an interest. + +#### 1. Login to your server + +We’ll use the root user. If you use a limited-user, you’ll have to execute most commands with ‘sudo’. You’ll get a warning if you’re doing something you don’t have enough permissions for. + +You can login to your server via your SSH client. Use your server IP and your port (most likely 22). + +After you log in, make sure you [secure your server][19]. + +#### 2. Update Ubuntu + +You should always first update your Ubuntu before you do anything else. You can update it with the following commands: + +``` +apt-get update && apt-get upgrade +``` + +Hit “enter” and/or “y” when prompted. + +#### 3. Install necessary tools + +You’ll need a few packages and tools for various things in this tutorial like text editing, making your server persistent etc. Install them with the following command: + +``` +apt-get install nano wget screen bash default-jdk ufw +``` + +Some of them may already be installed. + +#### 4. Download Minecraft Server + +First, create a directory where you’ll store your Minecraft server and all other files: + +``` +mkdir /opt/minecraft +``` + +And navigate to the new directory: + +``` +cd /opt/minecraft +``` + +Now you can download the Minecraft Server file. Go to the [download page][20] and get the link there. Download the file with wget: + +``` +wget https://s3.amazonaws.com/Minecraft.Download/versions/1.12.2/minecraft_server.1.12.2.jar +``` + +#### 5. Install the Minecraft server + +Once you’ve downloaded the server .jar file, you need to run it once and it will generate some files, including an eula.txt license file. The first time you run it, it will return an error and exit. That’s supposed to happen. Run in with the following command: + +``` +java -Xms2048M -Xmx3472M -jar minecraft_server.1.12.2.jar nogui +``` + +“-Xms2048M” is the minimum RAM that your Minecraft server can use and “-Xmx3472M” is the maximum. [Adjust][21] this based on your server’s resources. If you got the 4GB RAM server from [Vultr][22] you can leave them as-is, if you don’t use the server for anything else other than Minecraft. + +After that command ends and returns an error, a new eula.txt file will be generated. You need to accept the license in that file. You can do that by adding “eula=true” to the file with the following command: + +``` +sed -i.orig 's/eula=false/eula=true/g' eula.txt +``` + +You can now start the server again and access the Minecraft server console with that same java command from before: + +``` +java -Xms2048M -Xmx3472M -jar minecraft_server.1.12.2.jar nogui +``` + +Make sure you’re in the /opt/minecraft directory, or the directory where you installed your MC server. + +You’re free to stop here if you’re just testing this and need it for the short-term. If you’re having trouble loggin into the server, you’ll need to [configure your firewall][23]. + +The first time you successfully start the server it will take a bit longer to generate + +We’ll show you how to create a script so you can start the server with it. + +#### 6. Start the Minecraft server with a script, make it persistent, and enable it at boot + +To make things easier, we’ll create a bash script that will start the server automatically. + +So first, create a bash script with nano: + +``` +nano /opt/minecraft/startminecraft.sh +``` + +A new (blank) file will open. Paste the following: + +``` +#!/bin/bash +cd /opt/minecraft/ && java -Xms2048M -Xmx3472M -jar minecraft_server.1.12.2.jar nogui +``` + +If you’re new to nano – you can save and close the file with “CTRL + X”, then “Y”, and hitting enter. This script navigates to your Minecraft server directory you created previously and runs the java command for starting the server. You need to make it executable with the following command: + +``` +chmod +x startminecraft.sh +``` + +Then, you can start the server anytime with the following command: + +``` +/opt/minecraft/startminecraft.sh +``` + +But, if/when you log out of the SSH session the server will turn off. To keep the server up without being logged in all the time, you can use a screen session. A screen session basically means that it will keep running until the actual server reboots or turns off. + +Start a screen session with this command: + +``` +screen -S minecraft +``` + +Once you’re in the screen session (looks like you would start a new ssh session), you can use the bash script from earlier to start the server: + +``` +/opt/minecraft/startminecraft.sh +``` + +To get out of the screen session, you should press CTRL + A-D. Even after you get out of the screen session (detach), the server will keep running. You can safely log off your Ubuntu server now, and the Minecraft server you created will keep running. + +But, if the Ubuntu server reboots or shuts off, the screen session won’t work anymore. So **to do everything we did before automatically at boot** , do the following: + +Open the /etc/rc.local file: + +``` +nano /etc/rc.local +``` + +and add the following line above the “exit 0” line: + +``` +screen -dm -S minecraft /opt/minecraft/startminecraft.sh +exit 0 +``` + +Save and close the file. + +To access the Minecraft server console, just run the following command to attach to the screen session: + +``` +screen -r minecraft +``` + +That’s it for now. Congrats and have fun! You can now connect to your Minecraft server or configure/modify it. + +### Configure your Ubuntu Server + +You’ll, of course, need to set up your Ubuntu server and secure it if you haven’t already done so. Follow the [guide we mentioned earlier][24] and google it for more info. The configurations you need to do for your Minecraft server on your Ubuntu server are: + +#### Enable and configure the firewall + +First, if it’s not already enabled, you should enable UFW that you previously installed: + +``` +ufw enable +``` + +You should allow the default Minecraft server port: + +``` +ufw allow 25565/tcp +``` + +You should allow and deny other rules depending on how you use your server. You should deny ports like 80 and 443 if you don’t use the server for hosting websites. Google a UFW/Firewall guide for Ubuntu and you’ll get recommendations. Be careful when setting up your firewall, you may lock yourself out of your server if you block the SSH port. + +Since this is the default port, it often gets automatically scanned and attacked. You can prevent attacks by blocking access to anyone that’s not of your whitelist. + +First, you need to enable the whitelist mode in your [server.properties][25] file. To do that, open the file: + +``` +nano /opt/minecraft/server.properties +``` + +And change “white-list” line to “true”: + +``` +white-list=true +``` + +Save and close the file. + +Then restart your server (either by restarting your Ubuntu server or by running the start bash script again): + +``` +/opt/minecraft/startminecraft.sh +``` + +Access the Minecraft server console: + +``` +screen -r minecraft +``` + +And if you want someone to be able to join your server, you need to add them to the whitelist with the following command: + +``` +whitelist add PlayerUsername +``` + +To remove them from the whitelist, use: + +``` +whitelist remove PlayerUsername +``` + +Exit the screen session (server console) with CTRL + A-D. It’s worth noting that this will deny access to everyone but the whitelisted usernames. + + [![how to create a minecraft server](https://thishosting.rocks/wp-content/uploads/2018/01/create-a-minecraft-server.jpg)][26] + +### How to Make a Minecraft Server – FAQs + +We’ll answer some frequently asked questions about Minecraft Servers and our guide. + +#### How do I restart the Minecraft server? + +If you followed every step from our tutorial, including enabling the server to start on boot, you can just reboot your Ubuntu server. If you didn’t set it up to start at boot, you can just run the start script again which will restart the Minecraft server: + +``` +/opt/minecraft/startminecraft.sh +``` + +#### How do I configure my Minecraft server? + +You can configure your server using the [server.properties][27] file. Check the Minecraft Wiki for more info, though you can leave everything as-is and it will work perfectly fine. + +If you want to change the game mode, difficulty and stuff like that, you can use the server console. Access the server console by running: + +``` +screen -r minecraft +``` + +And execute [commands][28] there. Commands like: + +``` +difficulty hard +``` + +``` +gamemode survival @a +``` + +You may need to restart the server depending on what command you used. There are many more commands you can use, check the [wiki][29] for more. + +#### How do I upgrade my Minecraft server? + +If there’s a new release, you need to do this: + +Navigate to the minecraft directory: + +``` +cd /opt/minecraft +``` + +Download the latest version, example 1.12.3 with wget: + +``` +wget https://s3.amazonaws.com/Minecraft.Download/versions/1.12.3/minecraft_server.1.12.3.jar +``` + +Next, run and build the new server: + +``` +java -Xms2048M -Xmx3472M -jar minecraft_server.1.12.3.jar nogui +``` + +Finally, update your start script: + +``` +nano /opt/minecraft/startminecraft.sh +``` + +And update the version number accordingly: + +``` +#!/bin/bash +cd /opt/minecraft/ && java -Xms2048M -Xmx3472M -jar minecraft_server.1.12.3.jar nogui +``` + +Now you can restart the server and everything should go well. + +#### Why is your Minecraft server tutorial so long, and yet others are only 2 lines long?! + +We tried to make this beginner-friendly and be as detailed as possible. We also showed you how to make the Minecraft server persistent and start it automatically at boot, we showed you how to configure your server and everything. I mean, sure, you can start a Minecraft server with a couple of lines, but it would definitely suck, for more than one reason. + +#### I don’t know Linux or anything you wrote about here, how do I make a Minecraft server? + +Just read all of our article and copy and paste the commands. If you really don’t know how to do it all, [we can do it for you][30], or just get a [managed][31] server [provider][32] and let them do it for you. + +#### How do I install mods on my server? How do I install plugins? + +Our article is intended to be a starting guide. You should check the [Minecraft wiki][33] for more info, or just google it. There are plenty of tutorials online + +-------------------------------------------------------------------------------- + +via: https://thishosting.rocks/how-to-make-a-minecraft-server/ + +作者:[ThisHosting.Rocks][a] +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://thishosting.rocks +[1]:https://thishosting.rocks/how-to-make-a-minecraft-server/#reasons +[2]:https://thishosting.rocks/how-to-make-a-minecraft-server/#not-pc +[3]:https://thishosting.rocks/how-to-make-a-minecraft-server/#requirements +[4]:https://thishosting.rocks/how-to-make-a-minecraft-server/#make-minecraft-server +[5]:https://thishosting.rocks/how-to-make-a-minecraft-server/#persistent +[6]:https://thishosting.rocks/how-to-make-a-minecraft-server/#boot +[7]:https://thishosting.rocks/how-to-make-a-minecraft-server/#configure-minecraft-server +[8]:https://thishosting.rocks/how-to-make-a-minecraft-server/#faqs +[9]:https://thishosting.rocks/cheap-cloud-hosting-providers-comparison/ +[10]:https://thishosting.rocks/go/vultr/ +[11]:https://minecraft.gamepedia.com/Server/Requirements/Dedicated +[12]:https://thishosting.rocks/best-cheap-managed-vps/ +[13]:https://www.chiark.greenend.org.uk/~sgtatham/putty/ +[14]:https://mobaxterm.mobatek.net/ +[15]:https://www.linode.com/docs/security/securing-your-server/ +[16]:https://thishosting.rocks/go/vultr/ +[17]:https://thishosting.rocks/go/vultr/ +[18]:https://thishosting.rocks/ubuntu-18-04-new-features-release-date/ +[19]:https://www.linode.com/docs/security/securing-your-server/ +[20]:https://minecraft.net/en-us/download/server +[21]:https://minecraft.gamepedia.com/Commands +[22]:https://thishosting.rocks/go/vultr/ +[23]:https://thishosting.rocks/how-to-make-a-minecraft-server/#configure-minecraft-server +[24]:https://www.linode.com/docs/security/securing-your-server/ +[25]:https://minecraft.gamepedia.com/Server.properties +[26]:https://thishosting.rocks/wp-content/uploads/2018/01/create-a-minecraft-server.jpg +[27]:https://minecraft.gamepedia.com/Server.properties +[28]:https://minecraft.gamepedia.com/Commands +[29]:https://minecraft.gamepedia.com/Commands +[30]:https://thishosting.rocks/support/ +[31]:https://thishosting.rocks/best-cheap-managed-vps/ +[32]:https://thishosting.rocks/best-cheap-managed-vps/ +[33]:https://minecraft.gamepedia.com/Minecraft_Wiki diff --git a/sources/tech/20180126 Linux kill Command Tutorial for Beginners (5 Examples).md b/sources/tech/20180126 Linux kill Command Tutorial for Beginners (5 Examples).md new file mode 100644 index 0000000000..8fcdedef0e --- /dev/null +++ b/sources/tech/20180126 Linux kill Command Tutorial for Beginners (5 Examples).md @@ -0,0 +1,113 @@ +Linux kill Command Tutorial for Beginners (5 Examples) +====== + +Sometimes, while working on a Linux machine, you'll see that an application or a command line process gets stuck (becomes unresponsive). Then in those cases, terminating it is the only way out. Linux command line offers a utility that you can use in these scenarios. It's called **kill**. + +In this tutorial, we will discuss the basics of kill using some easy to understand examples. But before we do that, it's worth mentioning that all examples in the article have been tested on an Ubuntu 16.04 machine. + +#### Linux kill command + +The kill command is usually used to kill a process. Internally it sends a signal, and depending on what you want to do, there are different signals that you can send using this tool. Following is the command's syntax: + +``` +kill [options] [...] +``` + +And here's how the tool's man page describes it: +``` +The default signal for kill is TERM. Use -l or -L to list available signals. Particularly useful +signals include HUP, INT, KILL, STOP, CONT, and 0. Alternate signals may be specified in three ways: +-9, -SIGKILL or -KILL. Negative PID values may be used to choose whole process groups; see the PGID +column in ps command output.  A PID of -1 is special; it indicates all processes except the kill +process  itself and init. +``` + +The following Q&A-styled examples should give you a better idea of how the kill command works. + +#### Q1. How to terminate a process using kill command? + +This is very easy - all you need to do is to get the pid of the process you want to kill, and then pass it to the kill command. + +``` +kill [pid] +``` + +For example, I wanted to kill the 'gthumb' process on my system. So i first used the ps command to fetch the application's pid, and then passed it to the kill command to terminate it. Here's the screenshot showing all this: + +[![How to terminate a process using kill command][1]][2] + +#### Q2. How to send a custom signal? + +As already mentioned in the introduction section, TERM is the default signal that kill sends to the application/process in question. However, if you want, you can send any other signal that kill supports using the **-s** command line option. + +``` +kill -s [signal] [pid] +``` + +For example, if a process isn't responding to the TERM signal (which allows the process to do final cleanup before quitting), you can go for the KILL signal (which doesn't let process do any cleanup). Following is the command you need to run in that case. + +``` +kill -s KILL [pid] +``` + +#### Q3. What all signals you can send using kill? + +Of course, the next logical question that'll come to your mind is how to know which all signals you can send using kill. Well, thankfully, there exists a command line option **-l** that lists all supported signals. + +``` +kill -l +``` + +Following is the output the above command produced on our system: + +[![What all signals you can send using kill][3]][4] + +#### Q4. What are the other ways in which signal can be sent? + +In one of the previous examples, we told you if you want to send the KILL signal, you can do it in the following way: + +``` +kill -s KILL [pid] +``` + +However, there are a couple of other alternatives as well: + +``` +kill -s SIGKILL [pid] + +kill -s 9 [pid] +``` + +The corresponding number can be known using the -l option we've already discussed in the previous example. + +#### Q5. How to kill all running process in one go? + +In case a user wants to kill all processes that they can (this depends on their privilege level), then instead of specifying a large number of process IDs, they can simply pass the -1 option to kill. + +For example: + +``` +kill -s KILL -1 +``` + +#### Conclusion + +The kill command is pretty straightforward to understand and use. There's a slight learning curve in terms of the list of signal options it offers, but as we explained in here, there's an option to take a quick look at that list as well. Just practice whatever we've discussed and you should be good to go. For more information, head to the tool's [man page][5]. + + +-------------------------------------------------------------------------------- + +via: https://www.howtoforge.com/linux-kill-command/ + +作者:[Himanshu Arora][a] +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.howtoforge.com +[1]:https://www.howtoforge.com/images/usage_of_pfsense_to_block_dos_attack_/kill-default.png +[2]:https://www.howtoforge.com/images/usage_of_pfsense_to_block_dos_attack_/big/kill-default.png +[3]:https://www.howtoforge.com/images/usage_of_pfsense_to_block_dos_attack_/kill-l-option.png +[4]:https://www.howtoforge.com/images/usage_of_pfsense_to_block_dos_attack_/big/kill-l-option.png +[5]:https://linux.die.net/man/1/kill diff --git a/sources/tech/20180126 Running a Python application on Kubernetes.md b/sources/tech/20180126 Running a Python application on Kubernetes.md new file mode 100644 index 0000000000..4ce9f38726 --- /dev/null +++ b/sources/tech/20180126 Running a Python application on Kubernetes.md @@ -0,0 +1,280 @@ +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 \ No newline at end of file diff --git a/sources/tech/20180127 How to install KVM on CentOS 7 - RHEL 7 Headless Server.md b/sources/tech/20180127 How to install KVM on CentOS 7 - RHEL 7 Headless Server.md new file mode 100644 index 0000000000..6dce30d6dc --- /dev/null +++ b/sources/tech/20180127 How to install KVM on CentOS 7 - RHEL 7 Headless Server.md @@ -0,0 +1,342 @@ +How to install KVM on CentOS 7 / RHEL 7 Headless Server +====== + + +How do I install and configure KVM (Kernel-based Virtual Machine) on a CentOS 7 or RHEL (Red Hat Enterprise Linux) 7 server? How can I setup KMV on a CentOS 7 and use cloud images/cloud-init for installing guest VM? + + +Kernel-based Virtual Machine (KVM) is virtualization software for CentOS or RHEL 7. KVM turn your server into a hypervisor. This page shows how to setup and manage a virtualized environment with KVM in CentOS 7 or RHEL 7. It also described how to install and administer Virtual Machines (VMs) on a physical server using the CLI. Make sure that **Virtualization Technology (VT)** is enabled in your server 's BIOS. You can also run the following command [to test if CPU Support Intel VT and AMD-V Virtualization tech][1] +``` +$ lscpu | grep Virtualization +Virtualization: VT-x +``` + + + +### Follow installation steps of KVM on CentOS 7/RHEL 7 headless sever + +#### Step 1: Install kvm + +Type the following [yum command][2]: +`# yum install qemu-kvm libvirt libvirt-python libguestfs-tools virt-install` +[![How to install KVM on CentOS 7 RHEL 7 Headless Server][3]][3] +Start the libvirtd service: +``` +# systemctl enable libvirtd +# systemctl start libvirtd +``` + +#### Step 2: Verify kvm installation + +Make sure KVM module loaded using lsmod command and [grep command][4]: +`# lsmod | grep -i kvm` + +#### Step 3: Configure bridged networking + +By default dhcpd based network bridge configured by libvirtd. You can verify that with the following commands: +``` +# brctl show +# virsh net-list +``` +[![KVM default networking][5]][5] +All VMs (guest machine) only have network access to other VMs on the same server. A private network 192.168.122.0/24 created for you. Verify it: +`# virsh net-dumpxml default` +If you want your VMs avilable to other servers on your LAN, setup a a network bridge on the server that connected to the your LAN. Update your nic config file such as ifcfg-enp3s0 or em1: +`# vi /etc/sysconfig/network-scripts/enp3s0 ` +Add line: +``` +BRIDGE=br0 +``` + +[Save and close the file in vi][6]. Edit /etc/sysconfig/network-scripts/ifcfg-br0 and add: +`# vi /etc/sysconfig/network-scripts/ifcfg-br0` +Append the following: +``` +DEVICE="br0" +# I am getting ip from DHCP server # +BOOTPROTO="dhcp" +IPV6INIT="yes" +IPV6_AUTOCONF="yes" +ONBOOT="yes" +TYPE="Bridge" +DELAY="0" +``` + +Restart the networking service (warning ssh command will disconnect, it is better to reboot the box): +`# systemctl restart NetworkManager` +Verify it with brctl command: +`# brctl show` + +#### Step 4: Create your first virtual machine + +I am going to create a CentOS 7.x VM. First, grab CentOS 7.x latest ISO image using the wget command: +``` +# cd /var/lib/libvirt/boot/ +# wget https://mirrors.kernel.org/centos/7.4.1708/isos/x86_64/CentOS-7-x86_64-Minimal-1708.iso +``` +Verify ISO images: +``` +# wget https://mirrors.kernel.org/centos/7.4.1708/isos/x86_64/sha256sum.txt +# sha256sum -c sha256sum.txt +``` + +##### Create CentOS 7.x VM + +In this example, I'm creating CentOS 7.x VM with 2GB RAM, 2 CPU core, 1 nics and 40GB disk space, enter: +``` +# virt-install \ +--virt-type=kvm \ +--name centos7 \ +--ram 2048 \ +--vcpus=1 \ +--os-variant=centos7.0 \ +--cdrom=/var/lib/libvirt/boot/CentOS-7-x86_64-Minimal-1708.iso \ +--network=bridge=br0,model=virtio \ +--graphics vnc \ +--disk path=/var/lib/libvirt/images/centos7.qcow2,size=40,bus=virtio,format=qcow2 +``` +To configure vnc login from another terminal over ssh and type: +``` +# virsh dumpxml centos7 | grep vnc + +``` +Please note down the port value (i.e. 5901). You need to use an SSH client to setup tunnel and a VNC client to access the remote vnc server. Type the following SSH port forwarding command from your client/desktop/macbook pro system: +`$ ssh vivek@server1.cyberciti.biz -L 5901:127.0.0.1:5901` +Once you have ssh tunnel established, you can point your VNC client at your own 127.0.0.1 (localhost) address and port 5901 as follows: +[![][7]][7] +You should see CentOS Linux 7 guest installation screen as follows: +[![][8]][8] +Now just follow on screen instructions and install CentOS 7. Once installed, go ahead and click the reboot button. The remote server closed the connection to our VNC client. You can reconnect via KVM client to configure the rest of the server including SSH based session or firewall. + +#### Step 5: Using cloud images + +The above installation method is okay for learning purpose or a single VM. Do you need to deploy lots of VMs? Try cloud images. You can modify pre built cloud images as per your needs. For example, add users, ssh keys, setup time zone, and more using [Cloud-init][9] which is the defacto multi-distribution package that handles early initialization of a cloud instance. Let us see how to create CentOS 7 vm with 1024MB ram, 20GB disk space, and 1 vCPU. + +##### Grab CentOS 7 cloud image + +``` +# cd /var/lib/libvirt/boot +# wget http://cloud.centos.org/centos/7/images/CentOS-7-x86_64-GenericCloud.qcow2 +``` + +##### Create required directories + +``` +# D=/var/lib/libvirt/images +# VM=centos7-vm1 ## vm name ## +# mkdir -vp $D/$VM +mkdir: created directory '/var/lib/libvirt/images/centos7-vm1' +``` + +##### Create meta-data file + +``` +# cd $D/$VM +# vi meta-data +``` +Append the following: +``` +instance-id: centos7-vm1 +local-hostname: centos7-vm1 +``` + +##### Crete user-data file + +I am going to login into VM using ssh keys. So make sure you have ssh-keys in place: +`# ssh-keygen -t ed25519 -C "VM Login ssh key"` +[![ssh-keygen command][10]][11] +See "[How To Setup SSH Keys on a Linux / Unix System][12]" for more info. Edit user-data as follows: +``` +# cd $D/$VM +# vi user-data +``` +Add as follows (replace hostname, users, ssh-authorized-keys as per your setup): +``` +#cloud-config + +# Hostname management +preserve_hostname: False +hostname: centos7-vm1 +fqdn: centos7-vm1.nixcraft.com + +# Users +users: + - default + - name: vivek + groups: ['wheel'] + shell: /bin/bash + sudo: ALL=(ALL) NOPASSWD:ALL + ssh-authorized-keys: + - ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIIMP3MOF2ot8MOdNXCpHem0e2Wemg4nNmL2Tio4Ik1JY VM Login ssh key + +# Configure where output will go +output: + all: ">> /var/log/cloud-init.log" + +# configure interaction with ssh server +ssh_genkeytypes: ['ed25519', 'rsa'] + +# Install my public ssh key to the first user-defined user configured +# in cloud.cfg in the template (which is centos for CentOS cloud images) +ssh_authorized_keys: + - ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIIMP3MOF2ot8MOdNXCpHem0e2Wemg4nNmL2Tio4Ik1JY VM Login ssh key + +# set timezone for VM +timezone: Asia/Kolkata + +# Remove cloud-init +runcmd: + - systemctl stop network && systemctl start network + - yum -y remove cloud-init +``` + +##### Copy cloud image + +``` +# cd $D/$VM +# cp /var/lib/libvirt/boot/CentOS-7-x86_64-GenericCloud.qcow2 $VM.qcow2 +``` + +##### Create 20GB disk image + +``` +# cd $D/$VM +# export LIBGUESTFS_BACKEND=direct +# qemu-img create -f qcow2 -o preallocation=metadata $VM.new.image 20G +# virt-resize --quiet --expand /dev/sda1 $VM.qcow2 $VM.new.image +``` +[![Set VM image disk size][13]][13] +Overwrite it resized image: +``` +# cd $D/$VM +# mv $VM.new.image $VM.qcow2 +``` + +##### Creating a cloud-init ISO + +`# mkisofs -o $VM-cidata.iso -V cidata -J -r user-data meta-data` +[![Creating a cloud-init ISO][14]][14] + +##### Creating a pool + +``` +# virsh pool-create-as --name $VM --type dir --target $D/$VM +Pool centos7-vm1 created +``` + +##### Installing a CentOS 7 VM + +``` +# cd $D/$VM +# virt-install --import --name $VM \ +--memory 1024 --vcpus 1 --cpu host \ +--disk $VM.qcow2,format=qcow2,bus=virtio \ +--disk $VM-cidata.iso,device=cdrom \ +--network bridge=virbr0,model=virtio \ +--os-type=linux \ +--os-variant=centos7.0 \ +--graphics spice \ +--noautoconsole +``` +Delete unwanted files: +``` +# cd $D/$VM +# virsh change-media $VM hda --eject --config +# rm meta-data user-data centos7-vm1-cidata.iso +``` + +##### Find out IP address of VM + +`# virsh net-dhcp-leases default` +[![CentOS7-VM1- Created][15]][15] + +##### Log in to your VM + +Use ssh command: +`# ssh vivek@192.168.122.85` +[![Sample VM session][16]][16] + +### Useful commands + +Let us see some useful commands for managing VMs. + +#### List all VMs + +`# virsh list --all` + +#### Get VM info + +``` +# virsh dominfo vmName +# virsh dominfo centos7-vm1 +``` + +#### Stop/shutdown a VM + +`# virsh shutdown centos7-vm1` + +#### Start VM + +`# virsh start centos7-vm1` + +#### Mark VM for autostart at boot time + +`# virsh autostart centos7-vm1` + +#### Reboot (soft & safe reboot) VM + +`# virsh reboot centos7-vm1` +Reset (hard reset/not safe) VM +`# virsh reset centos7-vm1` + +#### Delete VM + +``` +# virsh shutdown centos7-vm1 +# virsh undefine centos7-vm1 +# virsh pool-destroy centos7-vm1 +# D=/var/lib/libvirt/images +# VM=centos7-vm1 +# rm -ri $D/$VM +``` +To see a complete list of virsh command type +``` +# virsh help | less +# virsh help | grep reboot +``` + + +### 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][17], [Facebook][18], [Google+][19]. + +-------------------------------------------------------------------------------- + +via: https://www.cyberciti.biz/faq/how-to-install-kvm-on-centos-7-rhel-7-headless-server/ + +作者:[Vivek Gite][a] +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.cyberciti.biz +[1]:https://www.cyberciti.biz/faq/linux-xen-vmware-kvm-intel-vt-amd-v-support/ +[2]:https://www.cyberciti.biz/faq/rhel-centos-fedora-linux-yum-command-howto/ (See Linux/Unix yum command examples for more info) +[3]:https://www.cyberciti.biz/media/new/faq/2018/01/How-to-install-KVM-on-CentOS-7-RHEL-7-Headless-Server.jpg +[4]:https://www.cyberciti.biz/faq/howto-use-grep-command-in-linux-unix/ (See Linux/Unix grep command examples for more info) +[5]:https://www.cyberciti.biz/media/new/faq/2018/01/KVM-default-networking.jpg +[6]:https://www.cyberciti.biz/faq/linux-unix-vim-save-and-quit-command/ +[7]:https://www.cyberciti.biz/media/new/faq/2016/01/vnc-client.jpg +[8]:https://www.cyberciti.biz/media/new/faq/2016/01/centos7-guest-vnc.jpg +[9]:https://cloudinit.readthedocs.io/en/latest/index.html +[10]:https://www.cyberciti.biz/media/new/faq/2018/01/ssh-keygen-pub-key.jpg +[11]:https://www.cyberciti.biz/faq/linux-unix-generating-ssh-keys/ +[12]:https://www.cyberciti.biz/faq/how-to-set-up-ssh-keys-on-linux-unix/ +[13]:https://www.cyberciti.biz/media/new/faq/2018/01/Set-VM-image-disk-size.jpg +[14]:https://www.cyberciti.biz/media/new/faq/2018/01/Creating-a-cloud-init-ISO.jpg +[15]:https://www.cyberciti.biz/media/new/faq/2018/01/CentOS7-VM1-Created.jpg +[16]:https://www.cyberciti.biz/media/new/faq/2018/01/Sample-VM-session.jpg +[17]:https://twitter.com/nixcraft +[18]:https://facebook.com/nixcraft +[19]:https://plus.google.com/+CybercitiBiz diff --git a/sources/tech/20180127 Your instant Kubernetes cluster.md b/sources/tech/20180127 Your instant Kubernetes cluster.md new file mode 100644 index 0000000000..b17619762a --- /dev/null +++ b/sources/tech/20180127 Your instant Kubernetes cluster.md @@ -0,0 +1,171 @@ +Your instant Kubernetes cluster +============================================================ + + +This is a condensed and updated version of my previous tutorial [Kubernetes in 10 minutes][10]. I've removed just about everything I can so this guide still makes sense. Use it when you want to create a cluster on the cloud or on-premises as fast as possible. + +### 1.0 Pick a host + +We will be using Ubuntu 16.04 for this guide so that you can copy/paste all the instructions. Here are several environments where I've tested this guide. Just pick where you want to run your hosts. + +* [DigitalOcean][1] - developer cloud + +* [Civo][2] - UK developer cloud + +* [Packet][3] - bare metal cloud + +* 2x Dell Intel i7 boxes - at home + +> Civo is a relatively new developer cloud and one thing that I really liked was how quickly they can bring up hosts - in about 25 seconds. I'm based in the UK so I also get very low latency. + +### 1.1 Provision the machines + +You can get away with a single host for testing but I'd recommend at least three so we have a single master and two worker nodes. + +Here are some other guidelines: + +* Pick dual-core hosts with ideally at least 2GB RAM + +* If you can pick a custom username when provisioning the host then do that rather than root. For example Civo offers an option of `ubuntu`, `civo` or `root`. + +Now run through the following steps on each machine. It should take you less than 5-10 minutes. If that's too slow for you then you can use my utility script [kept in a Gist][11]: + +``` +$ curl -sL https://gist.githubusercontent.com/alexellis/e8bbec45c75ea38da5547746c0ca4b0c/raw/23fc4cd13910eac646b13c4f8812bab3eeebab4c/configure.sh | sh + +``` + +### 1.2 Login and install Docker + +Install Docker from the Ubuntu apt repository. This will be an older version of Docker but as Kubernetes is tested with old versions of Docker it will work in our favour. + +``` +$ sudo apt-get update \ + && sudo apt-get install -qy docker.io + +``` + +### 1.3 Disable the swap file + +This is now a mandatory step for Kubernetes. The easiest way to do this is to edit `/etc/fstab` and to comment out the line referring to swap. + +To save a reboot then type in `sudo swapoff -a`. + +> Disabling swap memory may appear like a strange requirement at first. If you are curious about this step then [read more here][4]. + +### 1.4 Install Kubernetes packages + +``` +$ sudo apt-get update \ + && sudo apt-get install -y apt-transport-https \ + && curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add - + +$ echo "deb http://apt.kubernetes.io/ kubernetes-xenial main" \ + | sudo tee -a /etc/apt/sources.list.d/kubernetes.list \ + && sudo apt-get update + +$ sudo apt-get update \ + && sudo apt-get install -y \ + kubelet \ + kubeadm \ + kubernetes-cni + +``` + +### 1.5 Create the cluster + +At this point we create the cluster by initiating the master with `kubeadm`. Only do this on the master node. + +> Despite any warnings I have been assured by [Weaveworks][5] and Lucas (the maintainer) that `kubeadm` is suitable for production use. + +``` +$ sudo kubeadm init + +``` + +If you missed a step or there's a problem then `kubeadm` will let you know at this point. + +Take a copy of the Kube config: + +``` +mkdir -p $HOME/.kube +sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config +sudo chown $(id -u):$(id -g) $HOME/.kube/config + +``` + +Make sure you note down the join token command i.e. + +``` +$ sudo kubeadm join --token c30633.d178035db2b4bb9a 10.0.0.5:6443 --discovery-token-ca-cert-hash sha256: + +``` + +### 2.0 Install networking + +Many networking providers are available for Kubernetes, but none are included by default, so let's use Weave Net from [Weaveworks][12] which is one of the most popular options in the Kubernetes community. It tends to work out of the box without additional configuration. + +``` +$ kubectl apply -f "https://cloud.weave.works/k8s/net?k8s-version=$(kubectl version | base64 | tr -d '\n')" + +``` + +If you have private networking enabled on your host then you may need to alter the private subnet that Weavenet uses for allocating IP addresses to Pods (containers). Here's an example of how to do that: + +``` +$ curl -SL "https://cloud.weave.works/k8s/net?k8s-version=$(kubectl version | base64 | tr -d '\n')&env.IPALLOC_RANGE=172.16.6.64/27" \ +| kubectl apply -f - + +``` + +> Weave also have a very cool visualisation tool called Weave Cloud. It's free and will show you the path traffic is taking between your Pods. [See here for an example with the OpenFaaS project][6]. + +### 2.2 Join the worker nodes to the cluster + +Now you can switch to each of your workers and use the `kubeadm join` command from 1.5\. Once you run that log out of the workers. + +### 3.0 Profit + +That's it - we're done. You have a cluster up and running and can deploy your applications. If you need to setup a dashboard UI then consult the [Kubernetes documentation][13]. + +``` +$ kubectl get nodes +NAME STATUS ROLES AGE VERSION +openfaas1 Ready master 20m v1.9.2 +openfaas2 Ready 19m v1.9.2 +openfaas3 Ready 19m v1.9.2 + +``` + +If you want to see my running through creating a cluster step-by-step and showing you how `kubectl` works then checkout my video below and make sure you subscribe + + +You can also get an "instant" Kubernetes cluster on your Mac for development using Minikube or Docker for Mac Edge edition. [Read my review and first impressions here][14]. + + +-------------------------------------------------------------------------------- + +via: https://blog.alexellis.io/your-instant-kubernetes-cluster/ + +作者:[Alex Ellis ][a] +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://blog.alexellis.io/author/alex/ +[1]:https://www.digitalocean.com/ +[2]:https://www.civo.com/ +[3]:https://packet.net/ +[4]:https://github.com/kubernetes/kubernetes/issues/53533 +[5]:https://weave.works/ +[6]:https://www.weave.works/blog/openfaas-gke +[7]:https://blog.alexellis.io/tag/kubernetes/ +[8]:https://blog.alexellis.io/tag/k8s/ +[9]:https://blog.alexellis.io/tag/cloud-native/ +[10]:https://www.youtube.com/watch?v=6xJwQgDnMFE +[11]:https://gist.github.com/alexellis/e8bbec45c75ea38da5547746c0ca4b0c +[12]:https://weave.works/ +[13]:https://kubernetes.io/docs/tasks/access-application-cluster/web-ui-dashboard/ +[14]:https://blog.alexellis.io/docker-for-mac-with-kubernetes/ +[15]:https://blog.alexellis.io/your-instant-kubernetes-cluster/# \ No newline at end of file diff --git a/sources/tech/20180128 Getting Linux Jobs.md b/sources/tech/20180128 Getting Linux Jobs.md new file mode 100644 index 0000000000..a7f1a075a5 --- /dev/null +++ b/sources/tech/20180128 Getting Linux Jobs.md @@ -0,0 +1,98 @@ +Getting Linux Jobs +====== + +In a qualitative review of job posting websites, even highly skilled Linux administrators would be hamstrung to succeed in getting to the stage of an interview. + +All of this results in hundreds of decent and skilled people being snubbed without cause simply because today's job market requires a few extra tools to increase the odds. + +I have two colleagues and a cousin who have all received certifications with RedHat, managed quite extensive server rooms, and received earnest recommendations from former employers. + +All of these skills, certifications and experience come to naught as they apply to employer ads that are crudely constructed by someone hurriedly cutting and pasting snippets of "skill words" from a list of technical terms. + +Not surprisingly, today's politeness has gone the way of the bird, and a **non-response** from companies posting ads seems to be the new way of communicating. + +Unfortunately, it also means that these recruiters/HR personnel probably did **not** get the best candidate. + +The reason I can say this with such conviction is because of the type of buffoonery that takes place so often when creating job ads in the first place. + +Walter, another [Reallylinux.com][3] guest writer, presented how [**Job Want Ads Have Gone Mad**][4]. + +Perhaps he's right. However, I believe every Linux job seeker can avoid pitfalls of a job hunt by keeping in mind **three key facts** about job ads. + +First, few advertisements for Linux administrators are exclusively about Linux. + +Bear in mind the occasional Linux system administrator job, where you would actually be using Linux on servers. Instead, many jobs that rise up on a "Linux administrator" search are actually referring to a plethora of 'NX operating systems. + +For example, here is a quote from a **"Linux Administrator"** job posting: +This role will provide support for build system integration, especially operating system installation support for BSD applications... + +Or another ad declares in the bowels of its content: +Windows administration experience required. + +Ironically, if you show up to interview for any of these types of jobs and focus on Linux, they probably will not choose you. + +Even more importantly, if you simply include Linux as your expertise, they may not even bother with your resume, because they can't tell the difference between UNIX, BSD, Linux, etc. + +As a result, if you are conscientious and only include Linux on your resume, you are automatically out. But change that Linux to UNIX/Linux and you end up getting a bit farther in the human resources bureaucracy. + +I had two colleagues that ended up changing this on their resumes and getting a much better hit ratio for interviews, which were still slim pickings because most job ads are tailored with some particular person already in mind. The main intent behind such job ads being a cover for the ass of the department making the claim of having an open job. + +Second, the only person at the company who cares at all about the system administrator position is the technical lead/manager hiring for the slot. Others at the company, including the HR contact or the management could not care less. + +I remember sitting in a board room as a fly on the wall, hearing one executive vice president refer to server administrators as "dime a dozen geeks." How wrong they are to suggest this. + +Ironically, one day should the mail system fail, or the PBX connectivity hiccup, or perhaps core business files disappear from the intranet, these same executives are the first to get on the phone and threaten to fire the system admins. + +Perhaps if they would stop leaving so many hot air telephone messages, or filling their emails with 35MB photographs of another vice president's fishing trip and wife, the servers wouldn't be so problematic. + +Be aware that a Linux administrator ad, or any job posting for server administrator is placed because someone at the TECHNICAL level sees an urgent need for staffing. You're not going to get any empathy talking to HR or any leader of the company. Instead, take the time to find out who the hiring technical manager is and try to telephone them. + +You can always call them directly because you have some "specific technical questions" you know the HR person could not answer. This opens the dialogue with the person who actually cares that the position is filled and ensures you get a foot in because you took the time for personal contact, even if it was a 60 second phone call. + +What if the HR beauracracy won't let you through? + +Start asking as many tech questions as possible direct to the HR hiring contact, such as how their Linux clusters are setup and do they run VMs exclusively? Anything relatively technical will send these HR people in a tizzy and allow you the question: "may I contact the technical manager of the team?" + +If the response is a fluffy "maybe" or "I'll get back to you on that" they already filled the slot in their mind with someone else two weeks earlier, such as the HR staff member's fiance. They simply wanted it to look less like nepotism and more like indeterminism with a dash of egoism. + +``` +"They simply wanted it to look less like nepotism and more like indeterminism with a dash of egoism." +``` + +So take the time to find out who is the direct TECHNICAL leader hiring for the position and talk to them. It can make a difference and get you past some of the baloney. + +Third, few job ads today include any semblance of reality. + +I've seen enough ads requiring a junior system administrator with expertise that senior level experts don't have, to know the plan is to list the blue sky wish list and then find out who applies. + +In this situation, the Linux administrator ad you apply for, should include some key phrases for which you already have experience or certifications. + +The trick is to so overload your resume with the key phrases that MATCH their ad, it becomes almost impossible for them to determine which phrases you left out. + +This doesn't necessarily translate to a job, but it often adds enough intrigue to get you an interview, which now a days is a major step. + +By understanding and applying these three techniques, hopefully those seeking Linux administrator jobs have a head start on those who have only a slim chance in hell. + +Even if these tips don't get you interviews right away, you can use the experience and awareness when you go to the next trade show, or company sponsored technical conference. + +I strongly recommend you regularly attend these as well, especially if they are reasonably close, as they always provide a kick start to networking. + +Remember that job networking now a days is a pseudonym for "getting the gossip on which companies are actually hiring and which ones are just lying about jobs to give the appearance of growth for shareholders." + + + +-------------------------------------------------------------------------------- + +via: http://reallylinux.com/docs/gettinglinuxjobs.shtml + +作者:[Andrea W.Codingly][a] +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:http://reallylinux.com +[1]:http://www.reallylinux.com +[2]:http://reallylinux.com/docs/linuxrecessionproof.shtml +[3]:http://reallylinux.com +[4]:http://reallylinux.com/docs/wantadsmad.shtml diff --git a/sources/tech/20180128 How to add network bridge with nmcli (NetworkManager) on Linux.md b/sources/tech/20180128 How to add network bridge with nmcli (NetworkManager) on Linux.md new file mode 100644 index 0000000000..bf7772ef1a --- /dev/null +++ b/sources/tech/20180128 How to add network bridge with nmcli (NetworkManager) on Linux.md @@ -0,0 +1,146 @@ +How to add network bridge with nmcli (NetworkManager) on Linux +====== + +I am using Debian Linux 9 "stretch" on the desktop. I would like to create network bridge with NetworkManager. But, I am unable to find the option to add br0. How can I create or add network bridge with nmcli for NetworkManager on Linux? + +A bridge is nothing but a device which joins two local networks into one network. It works at the data link layer, i.e., layer 2 of the OSI model. Network bridge often used with virtualization and other software. Disabling NetworkManager for a simple bridge especially on Linux Laptop/desktop doesn't make any sense. The nmcli tool can create Persistent bridge configuration without editing any files. **This page shows how to create a bridge interface using the Network Manager command line tool called nmcli**. + + + +### How to create/add network bridge with nmcli + +The procedure to add a bridge interface on Linux is as follows when you want to use Network Manager: + +1. Open the Terminal app +2. Get info about the current connection: +``` +nmcli con show +``` +3. Add a new bridge: +``` +nmcli con add type bridge ifname br0 +``` +4. Create a slave interface: +``` +nmcli con add type bridge-slave ifname eno1 master br0 +``` +5. Turn on br0: +``` +nmcli con up br0 +``` + +Let us see how to create a bridge, named br0 in details. + +### Get current network config + +You can view connection from the Network Manager GUI in settings: +[![Getting Network Info on Linux][1]][1] +Another option is to type the following command: +``` +$ nmcli con show +$ nmcli connection show --active +``` +[![View the connections with nmcli][2]][2] +I have a "Wired connection 1" which uses the eno1 Ethernet interface. My system has a VPN interface too. I am going to setup a bridge interface named br0 and add, (or enslave) an interface to eno1. + +### How to create a bridge, named br0 + +``` +$ sudo nmcli con add ifname br0 type bridge con-name br0 +$ sudo nmcli con add type bridge-slave ifname eno1 master br0 +$ nmcli connection show +``` +[![Create bridge interface using nmcli on Linux][3]][3] +You can disable STP too: +``` +$ sudo nmcli con modify br0 bridge.stp no +$ nmcli con show +$ nmcli -f bridge con show br0 +``` +The last command shows the bridge settings including disabled STP: +``` +bridge.mac-address: -- +bridge.stp: no +bridge.priority: 32768 +bridge.forward-delay: 15 +bridge.hello-time: 2 +bridge.max-age: 20 +bridge.ageing-time: 300 +bridge.multicast-snooping: yes +``` + + +### How to turn on bridge interface + +You must turn off "Wired connection 1" and turn on br0: +``` +$ sudo nmcli con down "Wired connection 1" +$ sudo nmcli con up br0 +$ nmcli con show +``` +Use [ip command][4] to view the IP settings: +``` +$ ip a s +$ ip a s br0 +``` +[![Build a network bridge with nmcli on Linux][5]][5] + +### Optional: How to use br0 with KVM + +Now you can connect VMs (virtual machine) created with KVM/VirtualBox/VMware workstation to a network directly without using NAT. Create a file named br0.xml for KVM using vi command or [cat command][6]: +`$ cat /tmp/br0.xml` +Append the following code: +``` + + br0 + + + +``` + +Run virsh command as follows: +``` +# virsh net-define /tmp/br0.xml +# virsh net-start br0 +# virsh net-autostart br0 +# virsh net-list --all +``` +Sample outputs: +``` + Name State Autostart Persistent +---------------------------------------------------------- + br0 active yes yes + default inactive no yes +``` + + +For more info read the following man page: +``` +$ man ip +$ man nmcli +``` + +### 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][7], [Facebook][8], [Google+][9]. + +-------------------------------------------------------------------------------- + +via: https://www.cyberciti.biz/faq/how-to-add-network-bridge-with-nmcli-networkmanager-on-linux/ + +作者:[Vivek Gite][a] +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.cyberciti.biz +[1]:https://www.cyberciti.biz/media/new/faq/2018/01/Getting-Network-Info-on-Linux.jpg +[2]:https://www.cyberciti.biz/media/new/faq/2018/01/View-the-connections-with-nmcli.jpg +[3]:https://www.cyberciti.biz/media/new/faq/2018/01/Create-bridge-interface-using-nmcli-on-Linux.jpg +[4]:https://www.cyberciti.biz/faq/linux-ip-command-examples-usage-syntax/ (See Linux/Unix ip command examples for more info) +[5]:https://www.cyberciti.biz/media/new/faq/2018/01/Build-a-network-bridge-with-nmcli-on-Linux.jpg +[6]:https://www.cyberciti.biz/faq/linux-unix-appleosx-bsd-cat-command-examples/ (See Linux/Unix cat command examples for more info) +[7]:https://twitter.com/nixcraft +[8]:https://facebook.com/nixcraft +[9]:https://plus.google.com/+CybercitiBiz diff --git a/sources/tech/20180129 5 Real World Uses for Redis.md b/sources/tech/20180129 5 Real World Uses for Redis.md new file mode 100644 index 0000000000..61f7c09b3b --- /dev/null +++ b/sources/tech/20180129 5 Real World Uses for Redis.md @@ -0,0 +1,109 @@ +5 Real World Uses for Redis +============================================================ + + +Redis is a powerful in-memory data structure store which has many uses including a database, a cache, and a message broker. Most people often think of it a simple key-value store, but it has so much more power. I will be going over some real world examples of some of the many things Redis can do for you. + +### 1\. Full Page Cache + +The first thing is full page caching. If you are using server-side rendered content, you do not want to re-render each page for every single request. Using a cache like Redis, you can cache regularly requested content and drastically decrease latency for your most requested pages, and most frameworks have hooks for caching your pages with Redis. +Simple Commands + +``` +// Set the page that will last 1 minute +SET key "..." EX 60 + +// Get the page +GET key + +``` + +### 2\. Leaderboard + +One of the places Redis shines is for leaderboards. Because Redis is in-memory, it can deal with incrementing and decrementing very fast and efficiently. Compare this to running a SQL query every request the performance gains are huge! This combined with Redis's sorted sets means you can grab only the highest rated items in the list in milliseconds, and it is stupid easy to implement. +Simple Commands + +``` +// Add an item to the sorted set +ZADD sortedSet 1 "one" + +// Get all items from the sorted set +ZRANGE sortedSet 0 -1 + +// Get all items from the sorted set with their score +ZRANGE sortedSet 0 -1 WITHSCORES + +``` + +### 3\. Session Storage + +The most common use for Redis I have seen is session storage. Unlike other session stores like Memcache, Redis can persist data so in the situation where your cache goes down when it comes back up all the data will still be there. Although this isn't mission critical to be persisted, this feature can save your users lots of headaches. No one likes their session to be randomly dropped for no reason. +Simple Commands + +``` +// Set session that will last 1 minute +SET randomHash "{userId}" EX 60 + +// Get userId +GET randomHash + +``` + +### 4\. Queue + +One of the less common, but very useful things you can do with Redis is queue things. Whether it's a queue of emails or data to be consumed by another application, you can create an efficient queue it in Redis. Using this functionality is easy and natural for any developer who is familiar with Stacks and pushing and popping items. +Simple Commands + +``` +// Add a Message +HSET messages +ZADD due + +// Recieving Message +ZRANGEBYSCORE due -inf LIMIT 0 1 +HGET messages + +// Delete Message +ZREM due +HDEL messages + +``` + +### 5\. Pub/Sub + +The final real world use for Redis I am going to bring up in this post is pub/sub. This is one of the most powerful features Redis has built in; the possibilities are limitless. You can create a real-time chat system with it, trigger notifications for friend requests on social networks, etc... This feature is one of the most underrated features Redis offers but is very powerful, yet simple to use. +Simple Commands + +``` +// Add a message to a channel +PUBLISH channel message + +// Recieve messages from a channel +SUBSCRIBE channel + +``` + +### Conclusion + +I hope you enjoyed this list of some of the many real world uses for Redis. This is just scratching the surface of what Redis can do for you, but I hope it gave you some ideas of how you can use the full potential Redis has to offer. + +-------------------------------------------------------------------------------- + +作者简介: + +Hi, my name is Ryan! I am a Software Developer with experience in many web frameworks and libraries including NodeJS, Django, Golang, and Laravel. + + +------------------- + + +via: https://ryanmccue.ca/5-real-world-uses-for-redis/ + +作者:[Ryan McCue ][a] +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://ryanmccue.ca/author/ryan/ +[1]:https://ryanmccue.ca/author/ryan/ \ No newline at end of file diff --git a/sources/tech/20180129 A look inside Facebooks open source program.md b/sources/tech/20180129 A look inside Facebooks open source program.md new file mode 100644 index 0000000000..3610cec043 --- /dev/null +++ b/sources/tech/20180129 A look inside Facebooks open source program.md @@ -0,0 +1,68 @@ +A look inside Facebook's open source program +============================================================ + +### Facebook developer Christine Abernathy discusses how open source helps the company share insights and boost innovation. + +![A look inside Facebook's open source program](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/LAW-Internet_construction_9401467_520x292_0512_dc.png?itok=RPkPPtDe "A look inside Facebook's open source program") +Image by : opensource.com + + +Open source becomes more ubiquitous every year, appearing everywhere from [government municipalities][11] to [universities][12]. Companies of all sizes are also increasingly turning to open source software. In fact, some companies are taking open source a step further by supporting projects financially or working with developers. + +Facebook's open source program, for example, encourages others to release their code as open source, while working and engaging with the community to support open source projects. [Christine Abernathy][13], a Facebook developer, open source advocate, and member of the company's open source team, visited the Rochester Institute of Technology last November, presenting at the [November edition][14] of the FOSS Talks speaker series. In her talk, Abernathy explained how Facebook approaches open source and why it's an important part of the work the company does. + +### Facebook and open source + +Abernathy said that open source plays a fundamental role in Facebook's mission to create community and bring the world closer together. This ideological match is one motivating factor for Facebook's participation in open source. Additionally, Facebook faces unique infrastructure and development challenges, and open source provides a platform for the company to share solutions that could help others. Open source also provides a way to accelerate innovation and create better software, helping engineering teams produce better software and work more transparently. Today, Facebook's 443 projects on GitHub comprise 122,000 forks, 292,000 commits, and 732,000 followers. + + + +![open source projects by Facebook](https://opensource.com/sites/default/files/images/life-uploads/blog-article-facebook-open-source-projects.png "open source projects by Facebood") + +Some of the Facebook projects released as open source include React, GraphQL, Caffe2, and others. (Image by Christine Abernathy, used with permission) + +### Lessons learned + +Abernathy emphasized that Facebook has learned many lessons from the open source community, and it looks forward to learning many more. She identified the three most important ones: + +* Share what's useful + +* Highlight your heroes + +* Fix common pain points + + _Christine Abernathy visited RIT as part of the FOSS Talks speaker series. Every month, a guest speaker from the open source world shares wisdom, insight, and advice about the open source world with students interested in free and open source software. The [FOSS @ MAGIC][3] community is thankful to have Abernathy attend as a speaker._ + +### About the author + + [![Picture of Justin W. Flory](https://opensource.com/sites/default/files/styles/profile_pictures/public/pictures/october_2017_cropped_0.jpg?itok=gV-RgINC)][15] Justin W. Flory - Justin is a student at the [Rochester Institute of Technology][4]majoring in Networking and Systems Administration. He is currently a contributor to the [Fedora Project][5]. In Fedora, Justin is the editor-in-chief of the [Fedora Magazine][6], the lead of the [Community... ][7][more about Justin W. Flory][8][More about me][9] + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/1/inside-facebooks-open-source-program + +作者:[Justin W. Flory ][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/jflory +[1]:https://opensource.com/file/383786 +[2]:https://opensource.com/article/18/1/inside-facebooks-open-source-program?rate=H9_bfSwXiJfi2tvOLiDxC_tbC2xkEOYtCl-CiTq49SA +[3]:http://foss.rit.edu/ +[4]:https://www.rit.edu/ +[5]:https://fedoraproject.org/wiki/Overview +[6]:https://fedoramagazine.org/ +[7]:https://fedoraproject.org/wiki/CommOps +[8]:https://opensource.com/users/jflory +[9]:https://opensource.com/users/jflory +[10]:https://opensource.com/user/74361/feed +[11]:https://opensource.com/article/17/8/tirana-government-chooses-open-source +[12]:https://opensource.com/article/16/12/2016-election-night-hackathon +[13]:https://twitter.com/abernathyca +[14]:https://www.eventbrite.com/e/fossmagic-talks-open-source-facebook-with-christine-abernathy-tickets-38955037566# +[15]:https://opensource.com/users/jflory +[16]:https://opensource.com/users/jflory +[17]:https://opensource.com/users/jflory +[18]:https://opensource.com/article/18/1/inside-facebooks-open-source-program#comments \ No newline at end of file diff --git a/sources/tech/20180129 Advanced Python Debugging with pdb.md b/sources/tech/20180129 Advanced Python Debugging with pdb.md new file mode 100644 index 0000000000..80f17e23a3 --- /dev/null +++ b/sources/tech/20180129 Advanced Python Debugging with pdb.md @@ -0,0 +1,363 @@ +translating by lujun9972 +Advanced Python Debugging with pdb +====== + +![](https://process.filestackapi.com/cache=expiry:max/resize=width:700/compress/nygTCcWMQuyCFaOrlEnh) + +Python's built-in [`pdb`][1] module is extremely useful for interactive debugging, but has a bit of a learning curve. For a long time, I stuck to basic `print`-debugging and used `pdb` on a limited basis, which meant I missed out on a lot of features that would have made debugging faster and easier. + +In this post I will show you a few tips I've picked up over the years to level up my interactive debugging skills. + +## Print debugging vs. interactive debugging + +First, why would you want to use an interactive debugger instead of inserting `print` or `logging` statements into your code? + +With `pdb`, you have a lot more flexibility to run, resume, and alter the execution of your program without touching the underlying source. Once you get good at this, it means more time spent diving into issues and less time context switching back and forth between your editor and the command line. + +Also, by not touching the underlying source code, you will have the ability to step into third party code (e.g. modules installed from PyPI) and the standard library. + +## Post-mortem debugging + +The first workflow I used after moving away from `print` debugging was `pdb`'s "post-mortem debugging" mode. This is where you run your program as usual, but whenever an unhandled exception is thrown, you drop down into the debugger to poke around in the program state. After that, you attempt to make a fix and repeat the process until the problem is resolved. + +You can run an existing script with the post-mortem debugger by using Python's `-mpdb` option: +``` +python3 -mpdb path/to/script.py + +``` + +From here, you are dropped into a `(Pdb)` prompt. To start execution, you use the `continue` or `c` command. If the program executes successfully, you will be taken back to the `(Pdb)` prompt where you can restart the execution again. At this point, you can use `quit` / `q` or Ctrl+D to exit the debugger. + +If the program throws an unhandled exception, you'll also see a `(Pdb)` prompt, but with the program execution stopped at the line that threw the exception. From here, you can run Python code and debugger commands at the prompt to inspect the current program state. + +## Testing our basic workflow + +To see how these basic debugging steps work, I'll be using this (buggy) program: +``` +import random + +MAX = 100 + +def main(num_loops=1000): + for i in range(num_loops): + num = random.randint(0, MAX) + denom = random.randint(0, MAX) + result = num / denom + print("{} divided by {} is {:.2f}".format(num, denom, result)) + +if __name__ == "__main__": + import sys + arg = sys.argv[-1] + if arg.isdigit(): + main(arg) + else: + main() + +``` + +We're expecting the program to do some basic math operations on random numbers in a loop and print the result. Try running it normally and you will see one of the bugs: +``` +$ python3 script.py +2 divided by 30 is 0.07 +65 divided by 41 is 1.59 +0 divided by 70 is 0.00 +... +38 divided by 26 is 1.46 +Traceback (most recent call last): + File "script.py", line 16, in + main() + File "script.py", line 7, in main + result = num / denom +ZeroDivisionError: division by zero + +``` + +Let's try post-mortem debugging this error: +``` +$ python3 -mpdb script.py +> ./src/script.py(1)() +-> import random +(Pdb) c +49 divided by 46 is 1.07 +... +Traceback (most recent call last): + File "/usr/lib/python3.4/pdb.py", line 1661, in main + pdb._runscript(mainpyfile) + File "/usr/lib/python3.4/pdb.py", line 1542, in _runscript + self.run(statement) + File "/usr/lib/python3.4/bdb.py", line 431, in run + exec(cmd, globals, locals) + File "", line 1, in + File "./src/script.py", line 1, in + import random + File "./src/script.py", line 7, in main + result = num / denom +ZeroDivisionError: division by zero +Uncaught exception. Entering post mortem debugging +Running 'cont' or 'step' will restart the program +> ./src/script.py(7)main() +-> result = num / denom +(Pdb) num +76 +(Pdb) denom +0 +(Pdb) random.randint(0, MAX) +56 +(Pdb) random.randint(0, MAX) +79 +(Pdb) random.randint(0, 1) +0 +(Pdb) random.randint(1, 1) +1 + +``` + +Once the post-mortem debugger kicks in, we can inspect all of the variables in the current frame and even run new code to help us figure out what's wrong and attempt to make a fix. + +## Dropping into the debugger from Python code using `pdb.set_trace` + +Another technique that I used early on, after starting to use `pdb`, was forcing the debugger to run at a certain line of code before an error occurred. This is a common next step after learning post-mortem debugging because it feels similar to debugging with `print` statements. + +For example, in the above code, if we want to stop execution before the division operation, we could add a `pdb.set_trace` call to our program here: +``` + import pdb; pdb.set_trace() + result = num / denom + +``` + +And then run our program without `-mpdb`: +``` +$ python3 script.py +> ./src/script.py(10)main() +-> result = num / denom +(Pdb) num +94 +(Pdb) denom +19 + +``` + +The problem with this method is that you have to constantly drop these statements into your source code, remember to remove them afterwards, and switch between running your code with `python` vs. `python -mpdb`. + +Using `pdb.set_trace` gets the job done, but **breakpoints** are an even more flexible way to stop the debugger at any line (even third party or standard library code), without needing to modify any source code. Let's learn about breakpoints and a few other useful commands. + +## Debugger commands + +There are over 30 commands you can give to the interactive debugger, a list that can be seen by using the `help` command when at the `(Pdb)` prompt: +``` +(Pdb) help + +Documented commands (type help ): +======================================== +EOF c d h list q rv undisplay +a cl debug help ll quit s unt +alias clear disable ignore longlist r source until +args commands display interact n restart step up +b condition down j next return tbreak w +break cont enable jump p retval u whatis +bt continue exit l pp run unalias where + +``` + +You can use `help ` for more information on a given command. + +Instead of walking through each command, I'll list out the ones I've found most useful and what arguments they take. + +**Setting breakpoints** : + + * `l(ist)`: displays the source code of the currently running program, with line numbers, for the 10 lines around the current statement. + * `l 1,999`: displays the source code of lines 1-999. I regularly use this to see the source for the entire program. If your program only has 20 lines, it'll just show all 20 lines. + * `b(reakpoint)`: displays a list of current breakpoints. + * `b 10`: set a breakpoint at line 10. Breakpoints are referred to by a numeric ID, starting at 1. + * `b main`: set a breakpoint at the function named `main`. The function name must be in the current scope. You can also set breakpoints on functions in other modules in the current scope, e.g. `b random.randint`. + * `b script.py:10`: sets a breakpoint at line 10 in `script.py`. This gives you another way to set breakpoints in another module. + * `clear`: clears all breakpoints. + * `clear 1`: clear breakpoint 1. + + + +**Stepping through execution** : + + * `c(ontinue)`: execute until the program finishes, an exception is thrown, or a breakpoint is hit. + * `s(tep)`: execute the next line, whatever it is (your code, stdlib, third party code, etc.). Use this when you want to step down into function calls you're interested in. + * `n(ext)`: execute the next line in the current function (will not step into downstream function calls). Use this when you're only interested in the current function. + * `r(eturn)`: execute the remaining lines in the current function until it returns. Use this to skip over the rest of the function and go up a level. For example, if you've stepped down into a function by mistake. + * `unt(il) [lineno]`: execute until the current line exceeds the current line number. This is useful when you've stepped into a loop but want to let the loop continue executing without having to manually step through every iteration. Without any argument, this command behaves like `next` (with the loop skipping behavior, once you've stepped through the loop body once). + + + +**Moving up and down the stack** : + + * `w(here)`: shows an annotated view of the stack trace, with your current frame marked by `>`. + * `u(p)`: move up one frame in the current stack trace. For example, when post-mortem debugging, you'll start off on the lowest level of the stack and typically want to move `up` a few times to help figure out what went wrong. + * `d(own)`: move down one frame in the current stack trace. + + + +**Additional commands and tips** : + + * `pp `: This will "pretty print" the result of the given expression using the [`pprint`][2] module. Example: + + +``` +(Pdb) stuff = "testing the pp command in pdb with a big list of strings" +(Pdb) pp [(i, x) for (i, x) in enumerate(stuff.split())] +[(0, 'testing'), + (1, 'the'), + (2, 'pp'), + (3, 'command'), + (4, 'in'), + (5, 'pdb'), + (6, 'with'), + (7, 'a'), + (8, 'big'), + (9, 'list'), + (10, 'of'), + (11, 'strings')] + +``` + + * `!`: sometimes the Python code you run in the debugger will be confused for a command. For example `c = 1` will trigger the `continue` command. To force the debugger to execute Python code, prefix the line with `!`, e.g. `!c = 1`. + + * Pressing the Enter key at the `(Pdb)` prompt will execute the previous command again. This is most useful after the `s`/`n`/`r`/`unt` commands to quickly step through execution line-by-line. + + * You can run multiple commands on one line by separating them with `;;`, e.g. `b 8 ;; c`. + + * The `pdb` module can take multiple `-c` arguments on the command line to execute commands as soon as the debugger starts. + + + + +Example: +``` +python3 -mpdb -cc script.py # run the program without you having to enter an initial "c" at the prompt +python3 -mpdb -c "b 8" -cc script.py # sets a breakpoint on line 8 and runs the program + +``` + +## Restart behavior + +Another thing that can shave time off debugging is understanding how `pdb`'s restart behavior works. You may have noticed that after execution stops, `pdb` will give a message like, "The program finished and will be restarted," or "The script will be restarted." When I first started using `pdb`, I would always quit and re-run `python -mpdb ...` to make sure that my code changes were getting picked up, which was unnecessary in most cases. + +When `pdb` says it will restart the program, or when you use the `restart` command, code changes to the script you're debugging will be reloaded automatically. Breakpoints will still be set after reloading, but may need to be cleared and re-set due to line numbers shifting. Code changes to other imported modules will not be reloaded -- you will need to `quit` and re-run the `-mpdb` command to pick those up. + +## Watches + +One feature you may miss from other interactive debuggers is the ability to "watch" a variable change throughout the program's execution. `pdb` does not include a watch command by default, but you can get something similar by using `commands`, which lets you run arbitrary Python code whenever a breakpoint is hit. + +To watch what happens to the `denom` variable in our example program: +``` +$ python3 -mpdb script.py +> ./src/script.py(1)() +-> import random +(Pdb) b 9 +Breakpoint 1 at ./src/script.py:9 +(Pdb) commands +(com) silent +(com) print("DENOM: {}".format(denom)) +(com) c +(Pdb) c +DENOM: 77 +71 divided by 77 is 0.92 +DENOM: 27 +100 divided by 27 is 3.70 +DENOM: 10 +82 divided by 10 is 8.20 +DENOM: 20 +... + +``` + +We first set a breakpoint (which is assigned ID 1), then use `commands` to start entering a block of commands. These commands function as if you had typed them at the `(Pdb)` prompt. They can be either Python code or additional `pdb` commands. + +Once we start the `commands` block, the prompt changes to `(com)`. The `silent` command means the following commands will not be echoed back to the screen every time they're executed, which makes reading the output a little easier. + +After that, we run a `print` statement to inspect the variable, similar to what we might do when `print` debugging. Finally, we end with a `c` to continue execution, which ends the command block. Typing `c` again at the `(Pdb)` prompt starts execution and we see our new `print` statement running. + +If you'd rather stop execution instead of continuing, you can use `end` instead of `c` in the command block. + +## Running pdb from the interpreter + +Another way to run `pdb` is via the interpreter, which is useful when you're experimenting interactively and would like to drop into `pdb` without running a standalone script. + +For post-mortem debugging, all you need is a call to `pdb.pm()` after an exception has occurred: +``` +$ python3 +>>> import script +>>> script.main() +17 divided by 60 is 0.28 +... +56 divided by 94 is 0.60 +Traceback (most recent call last): + File "", line 1, in + File "./src/script.py", line 9, in main + result = num / denom +ZeroDivisionError: division by zero +>>> import pdb +>>> pdb.pm() +> ./src/script.py(9)main() +-> result = num / denom +(Pdb) num +4 +(Pdb) denom +0 + +``` + +If you want to step through normal execution instead, use the `pdb.run()` function: +``` +$ python3 +>>> import script +>>> import pdb +>>> pdb.run("script.main()") +> (1)() +(Pdb) b script:6 +Breakpoint 1 at ./src/script.py:6 +(Pdb) c +> ./src/script.py(6)main() +-> for i in range(num_loops): +(Pdb) n +> ./src/script.py(7)main() +-> num = random.randint(0, MAX) +(Pdb) n +> ./src/script.py(8)main() +-> denom = random.randint(0, MAX) +(Pdb) n +> ./src/script.py(9)main() +-> result = num / denom +(Pdb) n +> ./src/script.py(10)main() +-> print("{} divided by {} is {:.2f}".format(num, denom, result)) +(Pdb) n +66 divided by 70 is 0.94 +> ./src/script.py(6)main() +-> for i in range(num_loops): + +``` + +This one is a little trickier than `-mpdb` because you don't have the ability to step through an entire program. Instead, you'll need to manually set a breakpoint, e.g. on the first statement of the function you're trying to execute. + +## Conclusion + +Hopefully these tips have given you a few new ideas on how to use `pdb` more effectively. After getting a handle on these, you should be able to pick up the [other commands][3] and start customizing `pdb` via a `.pdbrc` file ([example][4]). + +You can also look into other front-ends for debugging, like [pdbpp][5], [pudb][6], and [ipdb][7], or GUI debuggers like the one included in PyCharm. Happy debugging! + +-------------------------------------------------------------------------------- + +via: https://www.codementor.io/stevek/advanced-python-debugging-with-pdb-g56gvmpfa + +作者:[Steven Kryskalla][a] +译者:[lujun9972](https://github.com/lujun9972) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.codementor.io/stevek +[1]:https://docs.python.org/3/library/pdb.html +[2]:https://docs.python.org/3/library/pprint.html +[3]:https://docs.python.org/3/library/pdb.html#debugger-commands +[4]:https://nedbatchelder.com/blog/200704/my_pdbrc.html +[5]:https://pypi.python.org/pypi/pdbpp/ +[6]:https://pypi.python.org/pypi/pudb/ +[7]:https://pypi.python.org/pypi/ipdb diff --git a/sources/tech/20180129 CopperheadOS Security features installing apps and more.md b/sources/tech/20180129 CopperheadOS Security features installing apps and more.md new file mode 100644 index 0000000000..fd6e110d35 --- /dev/null +++ b/sources/tech/20180129 CopperheadOS Security features installing apps and more.md @@ -0,0 +1,245 @@ +CopperheadOS: Security features, installing apps, and more +============================================================ + +### Fly your open source flag proudly with Copperhead, a mobile OS that takes its FOSS commitment seriously. + + +![Android security and privacy](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/android_security_privacy.png?itok=MPHAV5mL "Android security and privacy") +Image by : Norebbo via [Flickr][15] (Original: [public domain][16]). Modified by Opensource.com. [CC BY-SA 4.0][17]. + + _Editor's note: CopperheadOS is [licensed][11] under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 license (userspace) and GPL2 license (kernel). It is also based on Android Open Source Project (AOSP)._ + +Several years ago, I made the decision to replace proprietary technologies (mainly Apple products) with technology that ran on free and open source software (FOSS). I can't say it was easy, but I now happily use FOSS for pretty much everything. + +The hardest part involved my mobile handset. There are basically only two choices today for phones and tablets: Apple's iOS or Google's Android. Since Android is open source, it seemed the obvious choice, but I was frustrated by both the lack of open source applications on Android and the pervasiveness of Google on those devices. + +So I entered the world of custom ROMs. These are projects that take the base [Android Open Source Project][18] (AOSP) and customize it. Almost all these projects allow you to install the standard Google applications as a separate package, called GApps, and you can have as much or as little Google presence on your phone as you like. GApps packages come in a number of flavors, from the full suite of apps that Google ships with its devices to a "pico" version that includes just the minimal amount of software needed to run the Google Play Store, and from there you can add what you like. + +I started out using CyanogenMod, but when that project went in a direction I didn't like, I switched to OmniROM. I was quite happy with it, but still wondered what information I was sending to Google behind the scenes. + +Then I found out about [CopperheadOS][19]. Copperhead is a version of AOSP that focuses on delivering the most secure Android experience possible. I've been using it for a year now and have been quite happy with it. + +Unlike other custom ROMs that strive to add lots of new functionality, Copperhead runs a pretty vanilla version of AOSP. Also, while the first thing you usually do when playing with a custom ROM is to add root access to the device, not only does Copperhead prevent that, it also requires that you have a device that has verified boot, so there's no unlocking the bootloader. This is to prevent malicious code from getting access to the handset. + +Copperhead starts with a hardened version of the AOSP baseline, including full encryption, and then adds a [ton of stuff][20] I can only pretend to understand. It also applies a number of kernel and Android patches before they are applied to the mainline Android releases. + +### [copperos_extrapatches.png][1] + +![About phone with extra patches](https://opensource.com/sites/default/files/u128651/copperos_extrapatches.png "About phone with extra patches") + +It has a couple of more obvious features that I like. If you use a PIN to unlock your device, there is an option to scramble the digits. + +### [copperos_scrambleddigits.png][2] + +![Option to scramble digits](https://opensource.com/sites/default/files/u128651/copperos_scrambleddigits.png "Option to scramble digits") + +This should prevent any casual shoulder-surfer from figuring out your PIN, although it can make it a bit more difficult to unlock your device while, say, driving (but no one should be using their handset in the car, right?). + +Another issue it addresses involves tracking people by monitoring their WiFi MAC address. Most devices that use WiFi perform active scanning for wireless access points. This protocol includes the MAC address of the interface, and there are a number of ways people can use [mobile location analytics][21] to track your movement. Copperhead has an option to randomize your MAC address, which counters this process. + +### [copperos_randommac.png][3] + +![Randomize MAC address](https://opensource.com/sites/default/files/u128651/copperos_randommac.png "Randomize MAC address") + +### Installing apps + +This all sounds pretty good, right? Well, here comes the hard part. While Android is open source, much of the Google code, including the [Google Play Store][22], is not. If you install the Play Store and the code necessary for it to work, you allow Google to install software without your permission. [Google Play's terms of service][23] says: + +> "Google may update any Google app or any app you have downloaded from Google Play to a new version of such app, irrespective of any update settings that you may have selected within the Google Play app or your Device, if Google determines that the update will fix a critical security vulnerability related to the app." + +This is not acceptable from a security standpoint, so you cannot install Google applications on a Copperhead device. + +This took some getting used to, as I had come to rely on things such as Google Maps. The default application repository that ships with Copperhead is [F-Droid][24], which contains only FOSS applications. While I previously used many FOSS applications on Android, it took some effort to use  _nothing but_  free software. I did find some ways to cheat this system, and I'll cover that below. First, here are some of the applications I've grown to love from F-Droid. + +### F-Droid favorites + +**K-9 Mail** + +### [copperheados_k9mail.png][4] + +![K-9 Mail](https://opensource.com/sites/default/files/u128651/copperheados_k9mail.png "K-9 Mail") + +Even before I started using Copperhead, I loved [K-9 Mail][25]. This is simply the best mobile email client I've found, period, and it is one of the first things I install on any new device. I even use it to access my Gmail account, via IMAP and SMTP. + +**Open Camera** + +### [copperheados_cameraapi.png][5] + +![Open Camera](https://opensource.com/sites/default/files/u128651/copperheados_cameraapi.png "Open Camera") + +Copperhead runs only on rather new hardware, and I was consistently disappointed in the quality of the pictures from its default camera application. Then I discovered [Open Camera][26]. A full-featured camera app, it allows you to enable an advanced API to take advantage of the camera hardware. The only thing I miss is the ability to take a panoramic photo. + +**Amaze** + +### [copperheados_amaze.png][6] + +![Amaze](https://opensource.com/sites/default/files/u128651/copperheados_amaze.png "Amaze") + +[Amaze][27] is one of the best file managers I've ever used, free or not. When I need to navigate the filesystem, Amaze is my go-to app. + +**Vanilla Music** + +### [copperheados_vanillamusic.png][7] + +![Vanilla Music](https://opensource.com/sites/default/files/u128651/copperheados_vanillamusic.png "Vanilla Music") + +I was unhappy with the default music player, so I checked out a number of them on F-Droid and settled on [Vanilla Music][28]. It has an easy-to-use interface and interacts well with my Bluetooth devices. + +**OCReader** + +### [coperheados_ocreader.png][8] + +![OCReader](https://opensource.com/sites/default/files/u128651/coperheados_ocreader.png "OCReader") + +I am a big fan of [Nextcloud][29], particularly [Nextcloud News][30], a replacement for the now-defunct [Google Reader][31]. While I can access my news feeds through a web browser, I really missed the ability to manage them through a dedicated app. Enter [OCReader][32]. While it stands for "ownCloud Reader," it works with Nextcloud, and I've had very few issues with it. + +**Noise** + +The SMS/MMS application of choice for most privacy advocates is [Signal][33] by [Open Whisper Systems][34]. Endorsed by [Edward Snowden][35], Signal allows for end-to-end encrypted messaging. If the person you are messaging is also on Signal, your messages will be sent, encrypted, over a data connection facilitated by centralized servers maintained by Open Whisper Systems. It also, until recently, relied on [Google Cloud Messaging][36] (GCM) for notifications, which requires Google Play Services. + +The fact that Signal requires a centralized server bothered some people, so the default application on Copperhead is a fork of Signal called [Silence][37]. This application doesn't use a centralized server but does require that all parties be on Silence for encryption to work. + +Well, no one I know uses Silence. At the moment you can't even get it from the Google Play Store in the U.S. due to a trademark issue, and there is no iOS client. An encrypted SMS client isn't very useful if you can't use it for encryption. + +Enter [Noise][38]. Noise is another application maintained by Copperhead that is a fork of Signal that removes the need for GCM. While not available in the standard F-Droid repositories, Copperhead includes their own repository in the version of F-Droid they ship, which at the moment contains only the Noise application. This app will let you communicate securely with anyone else using Noise or Signal. + +### F-Droid workarounds + +**FFUpdater** + +Copperhead ships with a hardened version of the Chromium web browser, but I am a Firefox fan. Unfortunately, [Firefox is no longer included][39] in the F-Droid repository. Apps on F-Droid are all built by the F-Droid maintainers, so the process for getting into F-Droid can be complicated. The [Compass app for OpenNMS][40] isn't in F-Droid because, at the moment, it does not support builds using the [Ionic Framework][41], which Compass uses. + +Luckily, there is a simple workaround: Install the [FFUpdater][42] app on F-Droid. This allows me to install Firefox and keep it up to date through the browser itself. + +**Amazon Appstore** + +This brings me to a cool feature of Android 8, Oreo. In previous versions of Android, you had a single "known source" for software, usually the Google Play Store, and if you wanted to install software from another repository, you had to go to settings and allow "Install from Unknown Sources." I always had to remember to turn that off after an install to prevent malicious code from being able to install software on my device. + +### [copperheados_sources.png][9] + +![Allowing sources to install apps](https://opensource.com/sites/default/files/u128651/copperheados_sources.png "Allowing sources to install apps") + +With Oreo, you can permanently allow a specified application to install applications. For example, I use some applications from the [Amazon Appstore][43] (such as the Amazon Shopping and Kindle apps). When I download and install the Amazon Appstore Android package (APK), I am prompted to allow the application to install apps and then I'm not asked again. Of course, this can be turned on and off on a per-application basis. + +The Amazon Appstore has a number of useful apps, such as [IMDB][44] and [eBay][45]. Many of them don't require Google Services, but some do. For example, if I install the [Skype][46] app via Amazon, it starts up, but then complains about the operating system. The American Airlines app would start, then complain about an expired certificate. (I contacted them and was told they were no longer maintaining the version in the Amazon Appstore and it would be removed.) In any case, I can pretty simply install a couple of applications I like without using Google Play. + +**Google Play** + +Well, what about those apps you love that don't use Google Play Services but are only available through the Google Play Store? There is yet another way to safely get those apps on your Copperhead device. + +This does require some technical expertise and another device. On the second device, install the [TWRP][47] recovery application. This is usually a key first step in installing any custom ROM, and TWRP is supported on a large number of devices. You will also need the Android Debug Bridge ([ADB][48]) application from the [Android SDK][49], which can be downloaded at no cost. + +On the second device, use the Google Play Store to install the applications you want. Then, reboot into recovery. You can mount the system partition via TWRP; plug the device into a computer via a USB cable and you should be able to see it via ADB. There is a system directory called `/data/app`, and in it you will find all the APK files for your applications. Copy those you want to your computer (I use the ADB `pull`command and copy over the whole directory). + +Disconnect that phone and connect your Copperhead device. Enable the "Transfer files" option, and you should see the storage directory mounted on your computer. Copy over the APK files for the applications you want, then install them via the Amaze file manager (just navigate to the APK file and click on it). + +Note that you can do this for any application, and it might even be possible to install Google Play Services this way on Copperhead, but that kind of defeats the purpose. I use this mainly to get the [Electric Sheep][50] screensaver and a guitar tuning app I like called [Cleartune][51]. Be aware that if you install TWRP, especially on a Google Pixel, security updates may not work, as they'll expect the stock recovery. In this case you can always use [fastboot][52] to access TWRP, but leave the default recovery in place. + +### Must-have apps without a workaround + +Unfortunately, there are still a couple of Google apps I find it hard to live without. Google Maps is probably the main Google application I use, and yes, while I know I'm giving up my location to Google, it has saved hours of my life by routing me around traffic issues. [OpenStreetMap][53] has an app available via F-Droid, but it doesn't have the real-time information that makes Google Maps so useful. I also use Skype on occasion, usually when I am out of the country and have only a data connection (i.e., through a hotel WiFi network). It lets me call home and other places at a very affordable price. + +My workaround is to carry two phones. I know this isn't an option for most people, but it is the only one I've found for now. I use my Copperhead phone for anything personal (email, contacts, calendars, pictures, etc.) and my "Googlephone" for Maps, Skype, and various games. + +My dream would be for someone to perfect a hypervisor on a handset. Then I could run Copperhead and stock Google Android on the same device. I don't think anyone has a strong business reason to do it, but I do hope it happens. + +### Devices that support Copperhead + +Before you rush out to install Copperhead, there are some hurdles you'll have to jump. First, it is supported on only a [limited number of handsets][54], almost all of them late-model Google devices. The logic behind this is simple: Google tends to release Android security updates for its devices quickly, and I've found that Copperhead is able to follow suit within a day, if not within hours. Second, like any open source project, it has limited resources and it is difficult to support even a fraction of the devices now available to end users. Finally, if you want to run Copperhead on handsets like the Pixel and Pixel XL, you'll either have to build from source or [buy a device][55] from Copperhead directly. + +When I discovered Copperhead, I had a Nexus 6P, which (along with the Nexus 5X) is one of the supported devices. This allowed me to play with and get used to the operating system. I liked it so much that I donated some money to the project, but I kind of balked at the price they were asking for Pixel and Pixel XL handsets. + +Recently, though, I ended up purchasing a Pixel XL directly from Copperhead. There were a couple of reasons. One, since all of the code is available on GitHub, I set out to do [my own build][56] for a Pixel device. That process (which I never completed) made me appreciate the amount of work Copperhead puts into its project. Two, there was an article on [Slashdot][57] discussing how people were selling devices with Copperhead pre-installed and using Copperhead's update servers. I didn't appreciate that very much. Finally, I support FOSS not only by being a vocal user but also with my wallet. + +### Putting the "libre" back into free + +Another thing I love about FOSS is that I have options. There is even a new option to Copperhead being developed called [Eelo][58]. Created by [Gaël Duval][59], the developer of Mandrake Linux, this is a privacy-based Android operating system based on [LineageOS][60] (the descendant of CyanogenMod). While it should be supported on more handsets than Copperhead is, it is still in the development stage, and Copperhead is very stable and mature. I am eager to check it out, though. + +For the year I've used CopperheadOS, I've never felt safer when using a mobile device to connect to a network. I've found the open source replacements for my old apps to be more than adequate, if not better than the original apps. I've also rediscovered the browser. Where I used to have around three to four tabs open, I now have around 10, because I've found that I usually don't need to install an app to easily access a site's content. + +With companies like Google and Apple trying more and more to insinuate themselves into the lives of their users, it is nice to have an option that puts the "libre" back into free. + + +### About the author + + [![](https://opensource.com/sites/default/files/styles/profile_pictures/public/balog_tarus_-_julian_-_square.jpg?itok=ZA6yem3I)][61] + +Tarus Balog - Having been kicked out of some of the best colleges and universities in the country, I managed after seven years to get a BSEE and entered the telecommunications industry. I always ended up working on projects where we were trying to get the phone switch to talk to PCs. This got me interested in the creation and management of large communication networks. So I moved into the data communications field (they were separate back then) and started working with commercial network management tools... [more about Tarus Balog][12][More about me][13] + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/1/copperheados-delivers-mobile-freedom-privacy-and-security + +作者:[Tarus Balog ][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/sortova +[1]:https://opensource.com/file/384496 +[2]:https://opensource.com/file/384501 +[3]:https://opensource.com/file/384506 +[4]:https://opensource.com/file/384491 +[5]:https://opensource.com/file/384486 +[6]:https://opensource.com/file/384481 +[7]:https://opensource.com/file/384476 +[8]:https://opensource.com/file/384471 +[9]:https://opensource.com/file/384466 +[10]:https://opensource.com/article/18/1/copperheados-delivers-mobile-freedom-privacy-and-security?rate=P32BmRpJF5bYEYTHo4mW3Hp4XRk34Eq3QqMDf2oOGnw +[11]:https://copperhead.co/android/docs/building#redistribution +[12]:https://opensource.com/users/sortova +[13]:https://opensource.com/users/sortova +[14]:https://opensource.com/user/11447/feed +[15]:https://www.flickr.com/photos/mstable/17517955832 +[16]:https://creativecommons.org/publicdomain/mark/1.0/ +[17]:https://creativecommons.org/licenses/by-sa/4.0/ +[18]:https://en.wikipedia.org/wiki/Android_(operating_system)#AOSP +[19]:https://copperhead.co/ +[20]:https://copperhead.co/android/docs/technical_overview +[21]:https://en.wikipedia.org/wiki/Mobile_location_analytics +[22]:https://en.wikipedia.org/wiki/Google_Play#Compatibility +[23]:https://play.google.com/intl/en-us_us/about/play-terms.html +[24]:https://en.wikipedia.org/wiki/F-Droid +[25]:https://f-droid.org/en/packages/com.fsck.k9/ +[26]:https://f-droid.org/en/packages/net.sourceforge.opencamera/ +[27]:https://f-droid.org/en/packages/com.amaze.filemanager/ +[28]:https://f-droid.org/en/packages/ch.blinkenlights.android.vanilla/ +[29]:https://nextcloud.com/ +[30]:https://github.com/nextcloud/news +[31]:https://en.wikipedia.org/wiki/Google_Reader +[32]:https://f-droid.org/packages/email.schaal.ocreader/ +[33]:https://en.wikipedia.org/wiki/Signal_(software) +[34]:https://en.wikipedia.org/wiki/Open_Whisper_Systems +[35]:https://en.wikipedia.org/wiki/Edward_Snowden +[36]:https://en.wikipedia.org/wiki/Google_Cloud_Messaging +[37]:https://f-droid.org/en/packages/org.smssecure.smssecure/ +[38]:https://github.com/copperhead/Noise +[39]:https://f-droid.org/wiki/page/org.mozilla.firefox +[40]:https://compass.opennms.io/ +[41]:https://ionicframework.com/ +[42]:https://f-droid.org/en/packages/de.marmaro.krt.ffupdater/ +[43]:https://www.amazon.com/gp/feature.html?docId=1000626391 +[44]:https://www.imdb.com/ +[45]:https://www.ebay.com/ +[46]:https://www.skype.com/ +[47]:https://twrp.me/ +[48]:https://en.wikipedia.org/wiki/Android_software_development#ADB +[49]:https://developer.android.com/studio/index.html +[50]:https://play.google.com/store/apps/details?id=com.spotworks.electricsheep&hl=en +[51]:https://play.google.com/store/apps/details?id=com.bitcount.cleartune&hl=en +[52]:https://en.wikipedia.org/wiki/Android_software_development#Fastboot +[53]:https://f-droid.org/packages/net.osmand.plus/ +[54]:https://copperhead.co/android/downloads +[55]:https://copperhead.co/android/store +[56]:https://copperhead.co/android/docs/building +[57]:https://news.slashdot.org/story/17/11/12/024231/copperheados-fights-unlicensed-installations-on-nexus-phones +[58]:https://eelo.io/ +[59]:https://en.wikipedia.org/wiki/Ga%C3%ABl_Duval +[60]:https://en.wikipedia.org/wiki/LineageOS +[61]:https://opensource.com/users/sortova +[62]:https://opensource.com/users/sortova +[63]:https://opensource.com/users/sortova +[64]:https://opensource.com/article/18/1/copperheados-delivers-mobile-freedom-privacy-and-security#comments +[65]:https://opensource.com/tags/mobile +[66]:https://opensource.com/tags/android \ No newline at end of file diff --git a/sources/tech/20180129 How To Resume Partially Transferred Files Over SSH Using Rsync.md b/sources/tech/20180129 How To Resume Partially Transferred Files Over SSH Using Rsync.md new file mode 100644 index 0000000000..5e0583ab4f --- /dev/null +++ b/sources/tech/20180129 How To Resume Partially Transferred Files Over SSH Using Rsync.md @@ -0,0 +1,101 @@ +How To Resume Partially Transferred Files Over SSH Using Rsync +====== + +![](https://www.ostechnix.com/wp-content/uploads/2016/02/Resume-Partially-Transferred-Files-Over-SSH-Using-Rsync.png) + +There are chances that the large files which are being copied over SSH using SCP command might be interrupted or cancelled or broken due to various reasons such as power failure or network failure or user intervention. The other day I was copying the Ubuntu 16.04 ISO file to my remote system. Unfortunately, the power is gone, and the network connection is dropped immediately. The result? The copy process is terminated! This is just a simple example. The Ubuntu ISO is not so big, and I could restart the copy process as soon as the power is restored. But in production environment, you might not want to do it while you're transferring large files. + +Also, you can't always resume the aborted process using **scp** command. Because, If you do, It will simply overwrite the existing files. What would you do in such situations? No worries! This is where **Rsync** utility comes in handy! Rsync can help you to resume the interrupted copy or download process where you left it off. For those wondering, Rsync is a fast, versatile file copying utility that can be used to copy and transfer files or folders to and from remote and local systems. + +It offers a large number of options that control every aspect of its behavior and permit very flexible specification of the set of files to be copied. It is famous for its delta-transfer algorithm, which reduces the amount of data sent over the network by sending only the differences between the source files and the existing files in the destination. Rsync is widely used for backups and mirroring and as an improved copy command for everyday use. + +Just like SCP, rsync will also copy files over SSH. In case you wanted to download or transfer a big files and folders over SSH, I recommend you to use rsync utility. Be mindful that the **rsync utility should be installed on both sides** (remote and local systems) in order to resume partially transferred files. + +### Resume Partially Transferred Files Using Rsync + +Well, let me show you an example. I am going to copy Ubuntu 16.04 ISO from my local system to remote system with command: + +``` +$ scp Soft_Backup/OS\ Images/Linux/ubuntu-16.04-desktop-amd64.iso sk@192.168.43.2:/home/sk/ +``` + +Here, + + * **sk** is my remote system 's username + * **192.168.43.2** is the IP address of the remote machine. + + + +Now, I terminated it by pressing **CTRL+c**. + +**Sample output:** + +``` +sk@192.168.43.2's password: +ubuntu-16.04-desktop-amd64.iso 26% 372MB 26.2MB/s 00:39 ETA^c +``` + +[![][1]][2] + +As you see in the above output, I terminated the copy process when it reached 26%. + +If I re-run the above command, it will simply overwrite the existing file. In other words, the copy process will not resume where I left it off. + +In order to resume the copy process, we can use **rsync** command as shown below. + +``` +$ rsync -P -rsh=ssh Soft_Backup/OS\ Images/Linux/ubuntu-16.04-desktop-amd64.iso sk@192.168.43.2:/home/sk/ +``` + +**Sample output:** +``` +sk@192.168.1.103's password: +sending incremental file list +ubuntu-16.04-desktop-amd64.iso +                   380.56M 26% 41.05MB/s 0:00:25 +``` + +[![][1]][4] + +See? Now, the copying process is resumed where we left it off earlier. You also can use "-partial" instead of parameter "-P" like below. +``` +$ rsync --partial -rsh=ssh Soft_Backup/OS\ Images/Linux/ubuntu-16.04-desktop-amd64.iso sk@192.168.43.2:/home/sk/ +``` + +Here, the parameter "-partial" or "-P" tells the rsync command to keep the partial downloaded file and resumes the process. + +Alternatively, we can use the following commands as well to resume partially transferred files over SSH. + +``` +$ rsync -avP Soft_Backup/OS\ Images/Linux/ubuntu-16.04-desktop-amd64.iso sk@192.168.43.2:/home/sk/ +``` + +Or, + +``` +rsync -av --partial Soft_Backup/OS\ Images/Linux/ubuntu-16.04-desktop-amd64.iso sk@192.168.43.2:/home/sk/ +``` + +That's it. You know now how to resume the cancelled, interrupted, and partially downloaded files using rsync command. As you can see, it is not so difficult either. If rsync is installed on both systems, we can easily resume the copy process as described above. + +If you find this tutorial helpful, please share it on your social, professional networks and support OSTechNix. More good stuffs to come. Stay tuned! + +Cheers! + + + +-------------------------------------------------------------------------------- + +via: https://www.ostechnix.com/how-to-resume-partially-downloaded-or-transferred-files-using-rsync/ + +作者:[SK][a] +译者:[译者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/02/scp.png () +[3]:/cdn-cgi/l/email-protection +[4]:http://www.ostechnix.com/wp-content/uploads/2016/02/rsync.png () diff --git a/sources/tech/20180129 How programmers learn to code.md b/sources/tech/20180129 How programmers learn to code.md new file mode 100644 index 0000000000..c741c01161 --- /dev/null +++ b/sources/tech/20180129 How programmers learn to code.md @@ -0,0 +1,63 @@ +How programmers learn to code +============================================================ + + [![How programmers learn to code](https://mybroadband.co.za/news/wp-content/uploads/2016/01/Programmer-working-computer-code.jpg)][8] + + +HackerRank recently published the results of its 2018 Developer Skills Report, in which it asked programmers when they started coding. + +39,441 professional and student developers completed the online survey from 16 October to 1 November 2016, with over 25% of the developers surveyed writing their first piece of code before they were 16 years old. + +### How programmers learn + +In terms of how programmers learnt to code, self-teaching is the norm for developers of all ages, stated the report. + +“Even though 67% of developers have computer science degrees, roughly 74% said they were at least partially self-taught.” + +On average, developers know four languages, but they want to learn four more. + +The thirst for learning varies by generations – developers between 18 and 24 plan to learn six languages, whereas developers older than 35 only plan to learn three. + + [![HackerRank 2018 how did you learn to code](https://mybroadband.co.za/news/wp-content/uploads/2018/01/HackerRank-2018-how-did-you-learn-to-code.jpg)][5] + +### What programmers want + +HackerRank also looked at what developers want most from an employer. + +On average, a good work-life balance, closely followed by professional growth and learning, was the most desired requirement. + +Segmenting the data by region revealed that Americans crave work-life balance more than developers Asia and Europe. + +Students tend to rank growth and learning over work-life balance, while professionals rate compensation more highly than students do. + +People who work in smaller companies tended to rank work-life balance lower, but it was still in their top three. + +Age also made a difference, with developers 25 and older rating work-life balance as most important, while those between 18 and 24 rate it as less important. + +“In some ways, we’ve discovered a slight contradiction here. Developers want work-life balance, but they also have an insatiable thirst and need for learning,” said HackerRank. + +It advised that focusing on doing what you enjoy, as opposed to trying to learning everything, can help strike a better work-life balance. + + [![HackerRank 2018 what do developers want most](https://mybroadband.co.za/news/wp-content/uploads/2018/01/HackerRank-2018-what-do-developers-want-most-640x342.jpg)][6] + + [![HackerRank 2018 how to improve work-life balance](https://mybroadband.co.za/news/wp-content/uploads/2018/01/HackerRank-2018-how-to-improve-work-life-balance-378x430.jpg)][7] + +-------------------------------------------------------------------------------- + +via: https://mybroadband.co.za/news/smartphones/246583-how-programmers-learn-to-code.html + +作者:[Staff Writer ][a] +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://mybroadband.co.za/news/author/staff-writer +[1]:https://mybroadband.co.za/news/author/staff-writer +[2]:https://twitter.com/intent/tweet/?text=How+programmers+learn+to+code%20https://mybroadband.co.za/news/smartphones/246583-how-programmers-learn-to-code.html&via=mybroadband +[3]:mailto:?subject=How%20programmers%20learn%20to%20code&body=HackerRank%20recently%20published%20the%20results%20of%20its%202018%20Developer%20Skills%20Report.%0A%0Ahttps%3A%2F%2Fmybroadband.co.za%2Fnews%2Fsmartphones%2F246583-how-programmers-learn-to-code.html +[4]:https://mybroadband.co.za/news/smartphones/246583-how-programmers-learn-to-code.html#disqus_thread +[5]:https://mybroadband.co.za/news/wp-content/uploads/2018/01/HackerRank-2018-how-did-you-learn-to-code.jpg +[6]:https://mybroadband.co.za/news/wp-content/uploads/2018/01/HackerRank-2018-what-do-developers-want-most.jpg +[7]:https://mybroadband.co.za/news/wp-content/uploads/2018/01/HackerRank-2018-how-to-improve-work-life-balance.jpg +[8]:https://mybroadband.co.za/news/smartphones/246583-how-programmers-learn-to-code.html \ No newline at end of file diff --git a/sources/tech/20180129 How to Use DockerHub.md b/sources/tech/20180129 How to Use DockerHub.md new file mode 100644 index 0000000000..3793a6b718 --- /dev/null +++ b/sources/tech/20180129 How to Use DockerHub.md @@ -0,0 +1,135 @@ +How to Use DockerHub +====== + +![](https://www.linux.com/sites/lcom/files/styles/rendered_file/public/dockerhub-container.jpg?itok=tvraxGzh) + +In the previous articles, we learned the basics of [Docker terminology][1], [how to install Docker][2] on desktop Linux, macOS, and Windows, and [how to create container images][3] and run them on your system. In this last article in the series, we will talk about using images from DockerHub and publishing your own images to DockerHub. + +First things first: what is DockerHub and why is it important? DockerHub is a cloud-based repository run and managed by Docker Inc. It's an online repository where Docker images can be published and used by other users. There are both public and private repositories. If you are a company, you can have a private repository for use within your own organization, whereas public images can be used by anyone. + +You can also use official Docker images that are published publicly. I use many such images, including for my test WordPress installations, KDE plasma apps, and more. Although we learned last time how to create your own Docker images, you don't have to. There are thousands of images published on DockerHub for you to use. DockerHub is hardcoded into Docker as the default registry, so when you run the docker pull command against any image, it will be downloaded from DockerHub. + +### Download images from Docker Hub and run locally + +Please check out the previous articles in the series to get started. Then, once you have Docker running on your system, you can open the terminal and run: +``` +$ docker images +``` + +This command will show all the docker images currently on your system. Let's say you want to deploy Ubuntu on your local machine; you would do: +``` +$ docker pull ubuntu +``` + +If you already have Ubuntu image on your system, the command will automatically update that image to the latest version. So, if you want to update the existing images, just run the docker pull command, easy peasy. It's like apt-get upgrade without any muss and fuss. + +You already know how to run an image: +``` +$ docker run -it + +$ docker run -it ubuntu +``` + +The command prompt should change to something like this: +``` +root@1b3ec4621737:/# +``` + +Now you can run any command and utility that you use on Ubuntu. It's all safe and contained. You can run all the experiments and tests you want on that Ubuntu. Once you are done testing, you can nuke the image and download a new one. There is no system overhead that you would get with a virtual machine. + +You can exit that container by running the exit command: +``` +$ exit +``` + +Now let's say you want to install Nginx on your system. Run search to find the desired image: +``` +$ docker search nginx + +aizMFFysICAEsgDDYrsrlqwoCgGbWVHtcOzgV9mA +``` + +As you can see, there are many images of Nginx on DockerHub. Why? Because anyone can publish an image. Various images are optimized for different projects, so you can choose the appropriate image. You just need to install the appropriate image for your use-case. + +Let's say you want to pull Bitnami's Nginx container: +``` +$ docker pull bitnami/nginx +``` + +Now run it with: +``` +$ docker run -it bitnami/nginx +``` + +### How to publish images to Docker Hub? + +Previously, [we learned how to create a Docker image][3], and we can easily publish that image to DockerHub. First, you need to log into DockerHub. If you don't already have an account, please [create one][5]. Then, you can open terminal app and log in: +``` +$ docker login --username= +``` + +Replace with the name of your username for Docker Hub. In my case it's arnieswap: +``` +$ docker login --username=arnieswap> +``` + +Enter the password, and you are logged in. Now run the docker images command to get the ID of the image that you created last time. +``` +$ docker images + +tW1jDOugkX7J2FfyFyToM6B8m5OYFwMba-Ag5aez +``` + +Now, suppose you want to push the ng image to DockerHub. First, we need to tag that image ([learn more about tags][1]): +``` +$ docker tag e7083fd898c7 arnieswap/my_repo:testing +``` + +Now push that image: +``` +$ docker push arnieswap/my_repo +``` + +The push refers to repository [docker.io/arnieswap/my_repo] +``` +12628b20827e: Pushed + +8600ee70176b: Mounted from library/ubuntu + +2bbb3cec611d: Mounted from library/ubuntu + +d2bb1fc88136: Mounted from library/ubuntu + +a6a01ad8b53f: Mounted from library/ubuntu + +833649a3e04c: Mounted from library/ubuntu + +testing: digest: sha256:286cb866f34a2aa85c9fd810ac2cedd87699c02731db1b8ca1cfad16ef17c146 size: 1569 + +``` + +Eureka! Your image is being uploaded. Once finished, open DockerHub, log into your account, and you can see your very first Docker image. Now anyone can deploy your image. It's the easiest and fastest way to develop and distribute software. Whenever you update the image, users can simply run: +``` +$ docker run arnieswap/my_repo +``` + +Now you know why people love Docker containers. They solve many problems that traditional workloads face and allow you develop, test, and deploy applications in no time. And, by following the steps in this series, you can try them out for yourself. + + +-------------------------------------------------------------------------------- + +via: https://www.linux.com/blog/learn/intro-to-linux/2018/1/how-use-dockerhub + +作者:[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/blog/intro-to-linux/2017/12/container-basics-terms-you-need-know +[2]:https://www.linux.com/blog/learn/intro-to-linux/how-install-docker-ce-your-desktop +[3]:https://www.linux.com/blog/learn/intro-to-linux/2018/1/how-create-docker-image +[4]:https://lh3.googleusercontent.com/aizMFFysICAEsgDDYrsrlqwoCgGbWVHtcOzgV9mAtV8IdBZgHPJTdHIZhWBNCRvOyJb108ZBajJ_Nz10yCxGSvk-AF-yvFxpojLdVu3Jjihcwaup6CQLc67A5nglBuGDaOZWcrbV +[5]:https://hub.docker.com/ +[6]:https://lh6.googleusercontent.com/tW1jDOugkX7J2FfyFyToM6B8m5OYFwMba-Ag5aezVGf2A5gsKJ47QrCh_TOKWgIKfE824Uc2Cwwwj9jWps1yJlUZqDyIceVQs-nEbKavFDxuUxLyd4thBA4_rsXrQH4r7hrG8FnD diff --git a/sources/tech/20180129 How to make your LXD containers get IP addresses from your LAN using a bridge.md b/sources/tech/20180129 How to make your LXD containers get IP addresses from your LAN using a bridge.md new file mode 100644 index 0000000000..6f26f182b8 --- /dev/null +++ b/sources/tech/20180129 How to make your LXD containers get IP addresses from your LAN using a bridge.md @@ -0,0 +1,173 @@ +How to make your LXD containers get IP addresses from your LAN using a bridge +====== +**Background** : LXD is a hypervisor that manages machine containers on Linux distributions. You install LXD on your Linux distribution and then you can launch machine containers into your distribution running all sort of (other) Linux distributions. + +In the previous post, we saw how to get our LXD container to receive an IP address from the local network (instead of getting the default private IP address), using **macvlan**. + +In this post, we are going to see how to use a **bridge** to make our containers get an IP address from the local network. Specifically, we are going to see how to do this using NetworkManager. If you have several public IP addresses, you can use this method (or the other with the **macvlan** ) in order to expose your LXD containers directly to the Internet. + +### Creating the bridge with NetworkManager + +See this post [How to configure a Linux bridge with Network Manager on Ubuntu][1] on how to create the bridge with NetworkManager. It explains that you + + 1. Use **NetworkManager** to **Add a New Connection** , a **Bridge**. + 2. When configuring the **Bridge** , you specify the real network connection (the device, like **eth0** or **enp3s12** ) that will be **the slave of the bridge**. You can verify the device of the network connection if you run **ip route list 0.0.0.0/0**. + 3. Then, you can remove the old network connection and just keep the slave. The slave device ( **bridge0** ) will now be the device that gets you your LAN IP address. + + + +At this point you would have again network connectivity. Here is the new device, **bridge0**. +``` +$ ifconfig bridge0 +bridge0 Link encap:Ethernet HWaddr 00:e0:4b:e0:a8:c2 + inet addr:192.168.1.64 Bcast:192.168.1.255 Mask:255.255.255.0 + inet6 addr: fe80::d3ca:7a11:f34:fc76/64 Scope:Link + UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 + RX packets:9143 errors:0 dropped:0 overruns:0 frame:0 + TX packets:7711 errors:0 dropped:0 overruns:0 carrier:0 + collisions:0 txqueuelen:1000 + RX bytes:7982653 (7.9 MB) TX bytes:1056263 (1.0 MB) +``` + +### Creating a new profile in LXD for bridge networking + +In LXD, there is a default profile and then you can create additional profile that either are independent from the default (like in the **macvlan** post), or can be chained with the default profile. Now we see the latter. + +First, create a new and empty LXD profile, called **bridgeprofile**. +``` +$ lxc create profile bridgeprofile +``` + +Here is the fragment to add to the new profile. The **eth0** is the interface name in the container, so for the Ubuntu containers it does not change. Then, **bridge0** is the interface that was created by NetworkManager. If you created that bridge by some other way, add here the appropriate interface name. The **EOF** at the end is just a marker when we copy and past to the profile. +``` +description: Bridged networking LXD profile +devices: + eth0: + name: eth0 + nictype: bridged + parent: bridge0 + type: nic +**EOF** +``` + +Paste the fragment to the new profile. +``` +$ cat <:] [:][] [--ephemeral|-e] [--profile|-p ...] [--config|-c ...] [--type|-t ] + +Create and start containers from images. + +Not specifying -p will result in the default profile. +Specifying "-p" with no argument will result in no profile. + +Examples: + lxc launch ubuntu:16.04 u1 + +Options: + -c, --config (= map[]) Config key/value to apply to the new container + --debug (= false) Enable debug mode + -e, --ephemeral (= false) Ephemeral container + --force-local (= false) Force using the local unix socket + --no-alias (= false) Ignore aliases when determining what command to run + -p, --profile (= []) Profile to apply to the new container +**-t (= "") Instance type** + --verbose (= false) Enable verbose mode +``` + +What do we put for Instance type? Here is the documentation, + + + +Simply put, an instance type is just a mnemonic shortcut for specific pair of CPU cores and RAM memory settings. For CPU you specify the number of cores and for RAM memory the amount in GB (assuming your own computer has enough cores and RAM so that LXD can allocate them to the newly created container). + +You would need an instance type if you want to create a machine container that resembles in the specs as close as possible what you will be installing later on, on AWS (Amazon), Azure (Microsoft) or GCE (Google). + +The instance type can have any of the following forms, + + * `` for example: **t2.micro** (LXD figures out that this refers to AWS t2.micro, therefore 1 core, 1GB RAM). + * `:` for example, **aws:t2.micro** (LXD quickly looks into the AWS types, therefore 1core, 1GB RAM). + * `c-m` for example, **c1-m1** (LXD explicitly allocates one core, and 1GB RAM). + + + +Where do these mnemonics like **t2.micro** come from? The documentation says from + +[![][1]][2] + +There are three sets of instance types, **aws** , **azure** and **gce**. Their names are listed in [the LXD instance type index file ][3]**.yaml,** +``` +aws: "aws.yaml" +gce: "gce.yaml" +azure: "azure.yaml" + +``` + +Over there, there are YAML configuration files for each of AWS, Azure and GCE, and in them there are settings for CPU cores and RAM memory. + +The actual URLs that the LXD client will be using, are + + + +Sample for AWS: +``` +t2.large: + cpu: 2.0 + mem: 8.0 +t2.medium: + cpu: 2.0 + mem: 4.0 +t2.micro: + cpu: 1.0 + mem: 1.0 +t2.nano: + cpu: 1.0 + mem: 0.5 +t2.small: + cpu: 1.0 + mem: 2.0 +``` + + + +Sample for Azure: +``` +ExtraSmall: + cpu: 1.0 + mem: 0.768 +Large: + cpu: 4.0 + mem: 7.0 +Medium: + cpu: 2.0 + mem: 3.5 +Small: + cpu: 1.0 + mem: 1.75 +Standard_A1_v2: + cpu: 1.0 + mem: 2.0 +``` + + + +Sample for GCE: +``` +f1-micro: + cpu: 0.2 + mem: 0.6 +g1-small: + cpu: 0.5 + mem: 1.7 +n1-highcpu-16: + cpu: 16.0 + mem: 14.4 +n1-highcpu-2: + cpu: 2.0 + mem: 1.8 +n1-highcpu-32: + cpu: 32.0 + mem: 28.8 +``` + +Let's see an example. Here, all of the following are all equivalent! Just run one of them to get a 1 CPU core/1GB RAM container. +``` +$ lxc launch ubuntu:x -t t2.micro aws-t2-micro + +$ lxc launch ubuntu:x -t aws:t2.micro aws-t2-micro + +$ lxc launch ubuntu:x -t c1-m1 aws-t2-micro +``` + +Let's verify that the constraints have been actually set for the container. +``` +$ lxc config get aws-t2-micro limits.cpu +1 + +$ lxc config get aws-t2-micro limits.cpu.allowance + + +$ lxc config get aws-t2-micro limits.memory +1024MB + +$ lxc config get aws-t2-micro limits.memory.enforce + + +``` + +There are generic limits for 1 CPU core and 1024MB/1GB RAM. For more, see [LXD resource control][4]. + +If you already have a running container and you wanted to set limits live (no need to restart it), here is how you would do that. +``` +$ lxc launch ubuntu:x mycontainer +Creating mycontainer +Starting mycontainer + +$ lxc config set mycontainer limits.cpu 1 +$ lxc config set mycontainer limits.memory 1GB +``` + +Let's see the config with the limits, +``` +$ lxc config show mycontainer +architecture: x86_64 +config: + image.architecture: amd64 + image.description: ubuntu 16.04 LTS amd64 (release) (20180126) + image.label: release + image.os: ubuntu + image.release: xenial + image.serial: "20180126" + image.version: "16.04" + limits.cpu: "1" + limits.memory: 1GB +... +``` + +### Troubleshooting + +#### I tried to the the memory limit but I get an error! + +I got this error, +``` +$ lxc config set mycontainer limits.memory 1 +error: Failed to set cgroup memory.limit_in_bytes="1": setting cgroup item for the container failed +Exit 1 +``` + +When you set the memory limit ( **limits.memory** ), you need to append a specifier like **GB** (as in 1GB). Because the number there is in bytes if no specifier is present, and one byte of memory is not going to work. + +#### I cannot set the limits in lxc launch -config! + +How do I use **lxc launch -config ConfigurationGoesHere**? + +Here is the documentation: +``` +$ lxc launch --help +Usage: lxc launch [ :] ... [--config|-c ...] +``` + +Here it is, +``` +$ lxc launch ubuntu:x --config limits.cpu=1 --config limits.memory=1GB mycontainer +Creating mycontainer +Starting mycontainer +``` + +That is, use multiple **- config** parameters. + + +-------------------------------------------------------------------------------- + +via: https://blog.simos.info/how-to-use-lxd-instance-types/ + +作者:[Simos Xenitellis][a] +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://blog.simos.info/author/simos/ +[1]:https://i1.wp.com/blog.simos.info/wp-content/uploads/2018/01/lxd-instance-types.png?resize=750%2C277&ssl=1 +[2]:https://i1.wp.com/blog.simos.info/wp-content/uploads/2018/01/lxd-instance-types.png?ssl=1 +[3]:https://uk.images.linuxcontainers.org/meta/instance-types/.yaml +[4]:https://stgraber.org/2016/03/26/lxd-2-0-resource-control-412/ diff --git a/sources/tech/20180129 Install Zabbix Monitoring Server and Agent on Debian 9.md b/sources/tech/20180129 Install Zabbix Monitoring Server and Agent on Debian 9.md new file mode 100644 index 0000000000..308b6f1341 --- /dev/null +++ b/sources/tech/20180129 Install Zabbix Monitoring Server and Agent on Debian 9.md @@ -0,0 +1,401 @@ +Install Zabbix Monitoring Server and Agent on Debian 9 +====== + +Monitoring tools are used to continuously keep track of the status of the system and send out alerts and notifications if anything goes wrong. Also, monitoring tools help you to ensure that your critical systems, applications and services are always up and running. Monitoring tools are a supplement for your network security, allowing you to detect malicious traffic, where it's coming from and how to cancel it. + +Zabbix is a free, open source and the ultimate enterprise-level monitoring tool designed for real-time monitoring of millions of metrics collected from tens of thousands of servers, virtual machines and network devices. Zabbix has been designed to skill from small environment to large environment. Its web front-end is written in PHP, backend is written in C and uses MySQL, PostgreSQL, SQLite, Oracle or IBM DB2 to store data. Zabbix provides graphing functionality that allows you to get an overview of the current state of specific nodes and the network + +Some of the major features of the Zabbix are listed below: + + * Monitoring Servers, Databases, Applications, Network Devices, Vmware hypervisor, Virtual Machines and much more. + * Special designed to support small to large environments to improve the quality of your services and reduce operating costs by avoiding downtime. + * Fully open source, so you don't need to pay anything. + * Provide user friendly web interface to do everything from a central location. + * Comes with SNMP to monitor Network device and IPMI to monitor Hardware device. + * Web-based front end that allows full system control from a browser. + +This tutorial will walk you through the step by step instruction of how to install Zabbix Server and Zabbix agent on Debian 9 server. We will also explain how to add the Zabbix agent to the Zabbix server for monitoring. + +#### Requirements + + * Two system with Debian 9 installed. + * Minimum 1 GB of RAM and 10 DB of disk space required. Amount of RAM and Disk space depends on the number of hosts and the parameters that are being monitored. + * A non-root user with sudo privileges setup on your server. + + + +#### Getting Started + +Before starting, it is necessary to update your server's package repository to the latest stable version. You can update it by just running the following command on both instances: + +``` +sudo apt-get update -y +sudo apt-get upgrade -y +``` + +Next, restart your system to apply these changes. + +#### Install Apache, PHP and MariaDB + +Zabbix runs on Apache web server, written in PHP and uses MariaDB/MySQL to store their data. So in order to install Zabbix, you will require Apache, MariaDB and PHP to work. First, install Apache, PHP and Other PHP modules by running the following command: + +``` +sudo apt-get install apache2 libapache2-mod-php7.0 php7.0 php7.0-xml php7.0-bcmath php7.0-mbstring -y +``` + +Next, you will need to add MariaDB repository to your system. Because, latest version of the MariaDB is not available in Debian 9 default repository. + +You can add the repository by running the following command: + +``` +sudo apt-get install software-properties-common -y +sudo apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 0xF1656F24C74CD1D8 +sudo add-apt-repository 'deb [arch=amd64] http://www.ftp.saix.net/DB/mariadb/repo/10.1/debian stretch main' +``` + +Next, update the repository by running the following command: + +``` +sudo apt-get update -y +``` + +Finally, install the MariaDB server with the following command: + +``` +sudo apt-get install mariadb-server -y +``` + +By default, MariaDB installation is not secured. So you will need to secure it first. You can do this by running the mysql_secure_installation script. + +``` +sudo mysql_secure_installation +``` + +Answer all the questions as shown below: +``` + +Enter current password for root (enter for none): Enter +Set root password? [Y/n]: Y +New password: +Re-enter new password: +Remove anonymous users? [Y/n]: Y +Disallow root login remotely? [Y/n]: Y +Remove test database and access to it? [Y/n]: Y +Reload privilege tables now? [Y/n]: Y + +``` + +The above script will set the root password, remove test database, remove anonymous user and Disallow root login from a remote location. + +Once the MariaDB installation is secured, start the Apache and MariaDB service and enable them to start on boot time by running the following command: + +``` +sudo systemctl start apache2 +sudo systemctl enable apache2 +sudo systemctl start mysql +sudo systemctl enable mysql +``` + +#### Installing Zabbix Server + +By default, Zabbix is available in the Debian 9 repository, but it might be outdated. So it is recommended to install most recent version from the official Zabbix repositories. You can download and add the latest version of the Zabbix repository with the following command: + +``` +wget http://repo.zabbix.com/zabbix/3.0/debian/pool/main/z/zabbix-release/zabbix-release_3.0-2+stretch_all.deb +``` + +Next, install the downloaded repository with the following command: + +``` +sudo dpkg -i zabbix-release_3.0-2+stretch_all.deb +``` + +Next, update the package cache and install Zabbix server with web front-end and Mysql support by running the following command: + +``` +sudo apt-get update -y +sudo apt-get install zabbix-server-mysql zabbix-frontend-php -y +``` + +You will also need to install the Zabbix agent to collect data about the Zabbix server status itself: + +``` +sudo apt-get install zabbix-agent -y +``` + +After installing Zabbix agent, start the Zabbix agent service and enable it to start on boot time by running the following command: + +``` +sudo systemctl start zabbix-agent +sudo systemctl enable zabbix-agent +``` + +#### Configuring Zabbix Database + +Zabbix uses MariaDB/MySQL as a database backend. So, you will need to create a MySQL database and User for zabbix installation: + +First, log into MySQL shell with the following command: + +``` +mysql -u root -p +``` + +Enter your root password, then create a database for Zabbix with the following command: + +``` +MariaDB [(none)]> CREATE DATABASE zabbixdb character set utf8 collate utf8_bin; +``` + +Next, create a user for Zabbix, assign a password and grant all privileges on Zabbix database with the following command: + +``` +MariaDB [(none)]> CREATE user zabbix identified by 'password'; +MariaDB [(none)]> GRANT ALL PRIVILEGES on zabbixdb.* to zabbixuser@localhost identified by 'password'; +``` + +Next, flush the privileges with the following command: + +``` +MariaDB [(none)]> FLUSH PRIVILEGES; +``` + +Finally, exit from the MySQL shell with the following command: + +``` +MariaDB [(none)]> exit; +``` + +Next, import initial schema and data to the newly created database with the following command: + +``` +cd /usr/share/doc/zabbix-server-mysql*/ +zcat create.sql.gz | mysql -u zabbix -p zabbixdb +``` + +#### Configuring Zabbix + +Zabbix creates its own configuration file at `/etc/zabbix/apache.conf`. Edit this file and update the Timezone and PHP setting as per your need: + +``` +sudo nano /etc/zabbix/apache.conf +``` + +Change the file as shown below: +``` + php_value max_execution_time 300 + php_value memory_limit 128M + php_value post_max_size 32M + php_value upload_max_filesize 8M + php_value max_input_time 300 + php_value always_populate_raw_post_data -1 + php_value date.timezone Asia/Kolkata + +``` + +Save the file when you are finished. + +Next, you will need to update the database details for Zabbix. You can do this by editing `/etc/zabbix/zabbix_server.conf` file: + +``` +sudo nano /etc/zabbix/zabbix_server.conf +``` + +Change the following lines: +``` +DBHost=localhost +DBName=zabbixdb +DBUser=zabbixuser +DBPassword=password + +``` + +Save and close the file when you are finished. Then restart all the services with the following command: + +``` +sudo systemctl restart apache2 +sudo systemctl restart mysql +sudo systemctl restart zabbix-server +``` + +#### Configuring Firewall + +Before proceeding, you will need to configure the UFW firewall to secure Zabbix server. + +First, make sure UFW is installed on your system. Otherewise, you can install it by running the following command: + +``` +sudo apt-get install ufw -y +``` + +Next, enable the UFW firewall: + +``` +sudo ufw enable +``` + +Next, allow port 10050, 10051 and 80 through UFW with the following command: + +``` +sudo ufw allow 10050/tcp +sudo ufw allow 10051/tcp +sudo ufw allow 80/tcp +``` + +Finally, reload the firewall to apply these changes with the following command: + +``` +sudo ufw reload +``` + +Once the UFW firewall is configured you can proceed to install the Zabbix server via web interface. + +#### Accessing Zabbix Web Installation Wizard + +Once everything is fine, it's time to access Zabbix web installation wizard. + +Open your web browser and navigate the URL , you will be redirected to the following page: + +[![Zabbix 3.0][2]][3] + +Click on the **Next step** button, you should see the following page: + +[![Zabbix Prerequisites][4]][5] + +Here, all the Zabbix pre-requisites are checked and verified, then click on the **Next step** button you should see the following page: + +[![Database Configuration][6]][7] + +Here, provide the Zabbix database name, database user and password then click on the **Next step** button, you should see the following page: + +[![Zabbix Server Details][8]][9] + +Here, specify the Zabbix server details and Port number then click on the **Next step** button, you should see the pre-installation summary of Zabbix Server in following page: + +[![Installation summary][10]][11] + +Next, click on the **Next step** button to start the Zabbix installation. Once the Zabbix installation is completed successfully, you should see the following page: + +[![Zabbix installed successfully][12]][13] + +Here, click on the **Finish** button, it will redirect to the Zabbix login page as shown below: + +[![Login to Zabbix][14]][15] + +Here, provide username as Admin and password as zabbix then click on the **Sign in** button. You should see the Zabbix server dashboard in the following image: + +[![Zabbix Dashboard][16]][17] + +Your Zabbix web installation is now finished. + +#### Install Zabbix Agent + +Now your Zabbix server is up and functioning. It's time to add Zabbix agent node to the Zabbix Server for Monitoring. + +First, log into Zabbix agent instance and add the Zabbix repository with the following command: + +``` +wget http://repo.zabbix.com/zabbix/3.0/debian/pool/main/z/zabbix-release/zabbix-release_3.0-2+stretch_all.deb +sudo dpkg -i zabbix-release_3.0-2+stretch_all.deb +sudo apt-get update -y +``` + +Once you have configured Zabbix repository on your system, install the Zabbix agent by just running the following command: + +``` +sudo apt-get install zabbix-agent -y +``` + +Once the Zabbix agent is installed, you will need to configure Zabbix agent to communicate with Zabbix server. You can do this by editing the Zabbix agent configuration file: + +``` +sudo nano /etc/zabbix/zabbix_agentd.conf +``` + +Change the file as shown below: +``` + #Zabbix Server IP Address / Hostname + + Server=192.168.0.103 + + #Zabbix Agent Hostname + + Hostname=zabbix-agent + + +``` + +Save and close the file when you are finished, then restart the Zabbix agent service and enable it to start on boot time with the following command: + +``` +sudo systemctl restart zabbix-agent +sudo systemctl enable zabbix-agent +``` + +#### Add Zabbix Agent Node to Zabbix Server + +Next, you will need to add the Zabbix agent node to the Zabbix server for monitoring. First, log in to the Zabbix server web interface. + +[![Zabbix UI][18]][19] + +Next, Click on **Configuration --> Hosts -> Create Host**, you should see the following page: + +[![Create Host in Zabbix][20]][21] + +Here, specify the Hostname, IP address and Group names of Zabbix agent. Then navigate to Templates tab, you should see the following page: + +[![specify the Hostname, IP address and Group name][22]][23] + +Here, search appropriate templates and click on **Add** button, you should see the following page: + +[![OS Template][24]][25] + +Finally, click on **Add** button again. You will see your new host with green labels indicating that everything is working fine. + +[![Hast successfully added to Zabbix][26]][27] + +If you have extra servers and network devices that you want to monitor, log into each host, install the Zabbix agent and add each host from the Zabbix web interface. + +#### Conclusion + +Congratulations! you have successfully installed the Zabbix server and Zabbix agent in Debian 9 server. You have also added Zabbix agent node to the Zabbix server for monitoring. You can now easily list the current issue and past history, get the latest data of hosts, list the current problems and also visualized the collected resource statistics such as CPU load, CPU utilization, Memory usage, etc via graphs. I hope you can now easily install and configure Zabbix on Debian 9 server and deploy it on production environment. Compared to other monitoring software, Zabbix allows you to build your own maps of different network segments while monitoring many hosts. You can also monitor Windows host using Zabbix windows agent. For more information, you can refer the [Zabbix Documentation Page][28]. Feel free to ask me if you have any questions. + + +-------------------------------------------------------------------------------- + +via: https://www.howtoforge.com/tutorial/install-zabbix-monitoring-server-and-agent-on-debian-9/ + +作者:[Hitesh Jethva][a] +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.howtoforge.com +[1]:/cdn-cgi/l/email-protection +[2]:https://www.howtoforge.com/images/install_zabbix_monitoring_server_and_agent_on_debian_9/Screenshot-of-zabbix-welcome-page.png +[3]:https://www.howtoforge.com/images/install_zabbix_monitoring_server_and_agent_on_debian_9/big/Screenshot-of-zabbix-welcome-page.png +[4]:https://www.howtoforge.com/images/install_zabbix_monitoring_server_and_agent_on_debian_9/Screenshot-of-zabbix-pre-requisite-check-page.png +[5]:https://www.howtoforge.com/images/install_zabbix_monitoring_server_and_agent_on_debian_9/big/Screenshot-of-zabbix-pre-requisite-check-page.png +[6]:https://www.howtoforge.com/images/install_zabbix_monitoring_server_and_agent_on_debian_9/Screenshot-of-zabbix-db-config-page.png +[7]:https://www.howtoforge.com/images/install_zabbix_monitoring_server_and_agent_on_debian_9/big/Screenshot-of-zabbix-db-config-page.png +[8]:https://www.howtoforge.com/images/install_zabbix_monitoring_server_and_agent_on_debian_9/Screenshot-of-zabbix-server-details.png +[9]:https://www.howtoforge.com/images/install_zabbix_monitoring_server_and_agent_on_debian_9/big/Screenshot-of-zabbix-server-details.png +[10]:https://www.howtoforge.com/images/install_zabbix_monitoring_server_and_agent_on_debian_9/Screenshot-of-pre-installation-summary.png +[11]:https://www.howtoforge.com/images/install_zabbix_monitoring_server_and_agent_on_debian_9/big/Screenshot-of-pre-installation-summary.png +[12]:https://www.howtoforge.com/images/install_zabbix_monitoring_server_and_agent_on_debian_9/Screenshot-of-zabbix-install-success.png +[13]:https://www.howtoforge.com/images/install_zabbix_monitoring_server_and_agent_on_debian_9/big/Screenshot-of-zabbix-install-success.png +[14]:https://www.howtoforge.com/images/install_zabbix_monitoring_server_and_agent_on_debian_9/Screenshot-of-zabbix-login-page.png +[15]:https://www.howtoforge.com/images/install_zabbix_monitoring_server_and_agent_on_debian_9/big/Screenshot-of-zabbix-login-page.png +[16]:https://www.howtoforge.com/images/install_zabbix_monitoring_server_and_agent_on_debian_9/Screenshot-of-zabbix-welcome-dashboard.png +[17]:https://www.howtoforge.com/images/install_zabbix_monitoring_server_and_agent_on_debian_9/big/Screenshot-of-zabbix-welcome-dashboard.png +[18]:https://www.howtoforge.com/images/install_zabbix_monitoring_server_and_agent_on_debian_9/Screenshot-of-zabbix-welcome-dashboard1.png +[19]:https://www.howtoforge.com/images/install_zabbix_monitoring_server_and_agent_on_debian_9/big/Screenshot-of-zabbix-welcome-dashboard1.png +[20]:https://www.howtoforge.com/images/install_zabbix_monitoring_server_and_agent_on_debian_9/Screenshot-of-zabbix-agent-host1.png +[21]:https://www.howtoforge.com/images/install_zabbix_monitoring_server_and_agent_on_debian_9/big/Screenshot-of-zabbix-agent-host1.png +[22]:https://www.howtoforge.com/images/install_zabbix_monitoring_server_and_agent_on_debian_9/Screenshot-of-zabbix-agent-add-templates.png +[23]:https://www.howtoforge.com/images/install_zabbix_monitoring_server_and_agent_on_debian_9/big/Screenshot-of-zabbix-agent-add-templates.png +[24]:https://www.howtoforge.com/images/install_zabbix_monitoring_server_and_agent_on_debian_9/Screenshot-of-zabbix-agent-select-templates.png +[25]:https://www.howtoforge.com/images/install_zabbix_monitoring_server_and_agent_on_debian_9/big/Screenshot-of-zabbix-agent-select-templates.png +[26]:https://www.howtoforge.com/images/install_zabbix_monitoring_server_and_agent_on_debian_9/Screenshot-of-zabbix-agent-dashboard.png +[27]:https://www.howtoforge.com/images/install_zabbix_monitoring_server_and_agent_on_debian_9/big/Screenshot-of-zabbix-agent-dashboard.png +[28]:https://www.zabbix.com/documentation/3.2/ diff --git a/sources/tech/20180129 Parsing HTML with Python.md b/sources/tech/20180129 Parsing HTML with Python.md new file mode 100644 index 0000000000..d0dbee596f --- /dev/null +++ b/sources/tech/20180129 Parsing HTML with Python.md @@ -0,0 +1,212 @@ +Parsing HTML with Python +====== + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/bus_html_code.png?itok=VjUmGsnl) + +Image by : Jason Baker for Opensource.com. + +As a long-time member of the documentation team at Scribus, I keep up-to-date with the latest updates of the source so I can help make updates and additions to the documentation. When I recently did a "checkout" using Subversion on a computer I had just upgraded to Fedora 27, I was amazed at how long it took to download the documentation, which consists of HTML pages and associated images. I became concerned that the project's documentation seemed much larger than it should be and suspected that some of the content was "zombie" documentation--HTML files that aren't used anymore and images that have lost all references in the currently used HTML. + +I decided to create a project for myself to figure this out. One way to do this is to search for existing image files that aren't used. If I could scan through all the HTML files for image references, then compare that list to the actual image files, chances are I would see a mismatch. + +Here is a typical image tag: +``` +Edit examples +``` + +I'm interested in the part between the first set of quotation marks, after `src=`. After some searching for a solution, I found a Python module called [BeautifulSoup][1]. The tasty part of the script I wrote looks like this: +``` +soup = BeautifulSoup(all_text, 'html.parser') +match = soup.findAll("img") +if len(match) > 0: + for m in match: + imagelist.append(str(m)) +``` + +We can use this `findAll` method to pluck out the image tags. Here is a tiny piece of the output: +``` + + +GSview - Advanced Options PanelScribus External Tools Preferences +``` + +So far, so good. I thought that the next step might be to just carve this down, but when I tried some string methods in the script, it returned errors about this being tags and not strings. I saved the output to a file and went through the process of editing in [KWrite][2]. One nice thing about KWrite is that you can do a "find & replace" using regular expressions (regex), so I could replace `', all_text) +if len(match)>0: + for m in match: + imagelist.append(m) +``` + +And a tiny piece of its output looks like this: +``` +images/cmcanvas.png" title="Context Menu for the document canvas" alt="Context Menu for the document canvas" />
+``` + +I decided to home in on the `src=` piece. One way would be to wait for an occurrence of `s`, then see if the next character is `r`, the next `c`, and the next `=`. If so, bingo! Then what follows between two sets of double quotation marks is what I need. The problem with this is the structure it takes to hang onto these. One way of looking at a string of characters representing a line of HTML text would be: +``` +for c in all_text: +``` + +But the logic was just too messy to hang onto the previous `c`, and the one before that, the one before that, and the one before that. + +In the end, I decided to focus on the `=` and to use an indexing method whereby I could easily reference any prior or future character in the string. Here is the searching part: +``` + index = 3 + while index < linelength: + if (all_text[index] == '='): + if (all_text[index-3] == 's') and (all_text[index-2] == 'r') and (all_text[index-1] == 'c'): + imagefound(all_text, imagelist, index) + index += 1 + else: + index += 1 + else: + index += 1 +``` + +I start the search with the fourth character (indexing starts at 0), so I don't get an indexing error down below, and realistically, there will not be an equal sign before the fourth character of a line. The first test is to see if we find `=` as we're marching through the string, and if not, we march on. If we do see one, then we ask if the three previous characters were `s`, `r`, and `c`, in that order. If that happens, we call the function `imagefound`: +``` +def imagefound(all_text, imagelist, index): + end = 0 + index += 2 + newimage = '' + while end == 0: + if (all_text[index] != '"'): + newimage = newimage + all_text[index] + index += 1 + else: + newimage = newimage + '\n' + imagelist.append(newimage) + end = 1 + return +``` + +We're sending the function the current index, which represents the `=`. We know the next character will be `"`, so we jump two characters and begin adding characters to a holding string named `newimage`, until we reach the following `"`, at which point we're done. We add the string plus a `newline` character to our list `imagelist` and `return`, keeping in mind there may be more image tags in this remaining string of HTML, so we're right back in the middle of our searching loop. + +Here's what our output looks like now: +``` +images/text-frame-link.png +images/text-frame-unlink.png +images/gimpoptions1.png +images/gimpoptions3.png +images/gimpoptions2.png +images/fontpref3.png +images/font-subst.png +images/fontpref2.png +images/fontpref1.png +images/dtp-studio.png +``` + +Ahhh, much cleaner, and this only took a few seconds to run. I could have jumped seven more index spots to cut out the `images/` part, but I like having it there to make sure I haven't chopped off the first letter of the image filename, and this is so easy to edit out with KWrite--you don't even need regex. After doing that and saving the file, the next step was to run another script I wrote called `sortlist.py`: +``` +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# sortlist.py + +import os + +imagelist = [] +for line in open('/tmp/imagelist_parse4.txt').xreadlines(): + imagelist.append(line) + +imagelist.sort() + +outfile = open('/tmp/imagelist_parse4_sorted.txt', 'w') +outfile.writelines(imagelist) +outfile.close() +``` + +This pulls in the file contents as a list, sorts it, then saves it as another file. After that I could just do the following: +``` +ls /home/gregp/development/Scribus15x/doc/en/images/*.png > '/tmp/actual_images.txt' +``` + +Then I need to run `sortlist.py` on that file too, since the method `ls` uses to sort is different from Python. I could have run a comparison script on these files, but I preferred to do this visually. In the end, I ended up with 42 images that had no HTML reference from the documentation. + +Here is my parsing script in its entirety: +``` +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# parseimg4.py + +import os + +def imagefound(all_text, imagelist, index): + end = 0 + index += 2 + newimage = '' + while end == 0: + if (all_text[index] != '"'): + newimage = newimage + all_text[index] + index += 1 + else: + newimage = newimage + '\n' + imagelist.append(newimage) + end = 1 + return + +htmlnames = [] +imagelist = [] +tempstring = '' +filenames = os.listdir('/home/gregp/development/Scribus15x/doc/en/') +for name in filenames: + if name.endswith('.html'): + htmlnames.append(name) +#print htmlnames +for htmlfile in htmlnames: + all_text = open('/home/gregp/development/Scribus15x/doc/en/' + htmlfile).read() + linelength = len(all_text) + index = 3 + while index < linelength: + if (all_text[index] == '='): + if (all_text[index-3] == 's') and (all_text[index-2] == 'r') and +(all_text[index-1] == 'c'): + imagefound(all_text, imagelist, index) + index += 1 + else: + index += 1 + else: + index += 1 + +outfile = open('/tmp/imagelist_parse4.txt', 'w') +outfile.writelines(imagelist) +outfile.close() +imageno = len(imagelist) +print str(imageno) + " images were found and saved" +``` + +Its name, `parseimg4.py`, doesn't really reflect the number of scripts I wrote along the way, with both minor and major rewrites, plus discards and starting over. Notice that I've hardcoded these directory and filenames, but it would be easy enough to generalize, asking for user input for these pieces of information. Also as they were working scripts, I sent the output to `/tmp`, so they disappear once I reboot my system. + +This wasn't the end of the story, since the next question was: What about zombie HTML files? Any of these files that are not used might reference images not picked up by the previous method. We have a `menu.xml` file that serves as the table of contents for the online manual, but I also needed to consider that some files listed in the TOC might reference files not in the TOC, and yes, I did find some. + +I'll conclude by saying that this was a simpler task than this image search, and it was greatly helped by the processes I had already developed. + + +### About the author + + [![](https://opensource.com/sites/default/files/styles/profile_pictures/public/20150529_gregp.jpg?itok=nv02g6PV)][7] Greg Pittman - Greg is a retired neurologist in Louisville, Kentucky, with a long-standing interest in computers and programming, beginning with Fortran IV in the 1960s. When Linux and open source software came along, it kindled a commitment to learning more, and eventually contributing. He is a member of the Scribus Team.[More about me][8] + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/1/parsing-html-python + +作者:[Greg Pittman][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/greg-p +[1]:https://www.crummy.com/software/BeautifulSoup/ +[2]:https://www.kde.org/applications/utilities/kwrite/ +[7]:https://opensource.com/users/greg-p +[8]:https://opensource.com/users/greg-p diff --git a/sources/tech/20180129 Rapid, Secure Patching- Tools and Methods.md b/sources/tech/20180129 Rapid, Secure Patching- Tools and Methods.md new file mode 100644 index 0000000000..9ac7340c14 --- /dev/null +++ b/sources/tech/20180129 Rapid, Secure Patching- Tools and Methods.md @@ -0,0 +1,583 @@ +Rapid, Secure Patching: Tools and Methods +====== + +It was with some measure of disbelief that the computer science community greeted the recent [EternalBlue][1]-related exploits that have torn through massive numbers of vulnerable systems. The SMB exploits have kept coming (the most recent being [SMBLoris][2] presented at the last DEF CON, which impacts multiple SMB protocol versions, and for which Microsoft will issue no corrective patch. Attacks with these tools [incapacitated critical infrastructure][3] to the point that patients were even turned away from the British National Health Service. + +It is with considerable sadness that, during this SMB catastrophe, we also have come to understand that the famous Samba server presented an exploitable attack surface on the public internet in sufficient numbers for a worm to propagate successfully. I previously [have discussed SMB security][4] in Linux Journal, and I am no longer of the opinion that SMB server processes should run on Linux. + +In any case, systems administrators of all architectures must be able to down vulnerable network servers and patch them quickly. There is often a need for speed and competence when working with a large collection of Linux servers. Whether this is due to security situations or other concerns is immaterial—the hour of greatest need is not the time to begin to build administration tools. Note that in the event of an active intrusion by hostile parties, [forensic analysis][5] may be a legal requirement, and no steps should be taken on the compromised server without a careful plan and documentation. Especially in this new era of the black hats, computer professionals must step up their game and be able to secure vulnerable systems quickly. + +### Secure SSH Keypairs + +Tight control of a heterogeneous UNIX environment must begin with best-practice use of SSH authentication keys. I'm going to open this section with a simple requirement. SSH private keys must be one of three types: Ed25519, ECDSA using the E-521 curve or RSA keys of 3072 bits. Any key that does not meet those requirements should be retired (in particular, DSA keys must be removed from service immediately). + +The [Ed25519][6] key format is associated with Daniel J. Bernstein, who has such a preeminent reputation in modern cryptography that the field is becoming a DJB [monoculture][7]. The Ed25519 format is deigned for speed, security and size economy. If all of your SSH servers are recent enough to support Ed25519, then use it, and consider nothing else. + +[Guidance on creating Ed25519 keys][8] suggests 100 rounds for a work factor in the "-o" secure format. Raising the number of rounds raises the strength of the encrypted key against brute-force attacks (should a file copy of the private key fall into hostile hands), at the cost of more work and time in decrypting the key when ssh-add is executed. Although there always is [controversy and discussion][9] with security advances, I will repeat the guidance here and suggest that the best format for a newly created SSH key is this: + +``` + +ssh-keygen -a 100 -t ed25519 + +``` + +Your systems might be too old to support Ed25519—Oracle/CentOS/Red Hat 7 have this problem (the 7.1 release introduced support). If you cannot upgrade your old SSH clients and servers, your next best option is likely E-521, available in the ECDSA key format. + +The ECDSA curves came from the US government's National Institute of Standards (NIST). The best known and most implemented of all of the NIST curves are P-256, P-384 and E-521\. All three curves are approved for secret communications by a variety of government entities, but a number of cryptographers have [expressed growing suspicion][10] that the P-256 and P-384 curves are tainted. Well known cryptographer Bruce Schneier [has remarked][11]: "I no longer trust the constants. I believe the NSA has manipulated them through their relationships with industry." However, DJB [has expressed][12] limited praise of the E-521 curve: "To be fair I should mention that there's one standard NIST curve using a nice prime, namely 2521 – 1; but the sheer size of this prime makes it much slower than NIST P-256." All of the NIST curves have greater issues with "side channel" attacks than Ed25519—P-521 is certainly a step down, and many assert that none of the NIST curves are safe. In summary, there is a slight risk that a powerful adversary exists with an advantage over the P-256 and P-384 curves, so one is slightly inclined to avoid them. Note that even if your OpenSSH (source) release is capable of E-521, it may be [disabled by your vendor][13] due to patent concerns, so E-521 is not an option in this case. If you cannot use DJB's 2255 – 19 curve, this command will generate an E-521 key on a capable system: + +``` + +ssh-keygen -o -a 100 -b 521 -t ecdsa + +``` + +And, then there is the unfortunate circumstance with SSH servers that support neither ECDSA nor Ed25519\. In this case, you must fall back to RSA with much larger key sizes. An absolute minimum is the modern default of 2048 bits, but 3072 is a wiser choice: + +``` + +ssh-keygen -o -a 100 -b 3072 -t rsa + +``` + +Then in the most lamentable case of all, when you must use old SSH clients that are not able to work with private keys created with the -o option, you can remove the password on id_rsa and create a naked key, then use OpenSSL to encrypt it with AES256 in the PKCS#8 format, as [first documented by Martin Kleppmann][14]. Provide a blank new password for the keygen utility below, then supply a new password when OpenSSL reprocesses the key: + +``` + +$ cd ~/.ssh + +$ cp id_rsa id_rsa-orig + +$ ssh-keygen -p -t rsa +Enter file in which the key is (/home/cfisher/.ssh/id_rsa): +Enter old passphrase: +Key has comment 'cfisher@localhost.localdomain' +Enter new passphrase (empty for no passphrase): +Enter same passphrase again: +Your identification has been saved with the new passphrase. + +$ openssl pkcs8 -topk8 -v2 aes256 -in id_rsa -out id_rsa-strong +Enter Encryption Password: +Verifying - Enter Encryption Password: + +mv id_rsa-strong id_rsa +chmod 600 id_rsa + +``` + +After creating all of these keys on a newer system, you can compare the file sizes: + +``` + +$ ll .ssh +total 32 +-rw-------. 1 cfisher cfisher 801 Aug 10 21:30 id_ecdsa +-rw-r--r--. 1 cfisher cfisher 283 Aug 10 21:30 id_ecdsa.pub +-rw-------. 1 cfisher cfisher 464 Aug 10 20:49 id_ed25519 +-rw-r--r--. 1 cfisher cfisher 111 Aug 10 20:49 id_ed25519.pub +-rw-------. 1 cfisher cfisher 2638 Aug 10 21:45 id_rsa +-rw-------. 1 cfisher cfisher 2675 Aug 10 21:42 id_rsa-orig +-rw-r--r--. 1 cfisher cfisher 583 Aug 10 21:42 id_rsa.pub + +``` + +Although they are relatively enormous, all versions of OpenSSH that I have used have been compatible with the RSA private key in PKCS#8 format. The Ed25519 public key is now small enough to fit in 80 columns without word wrap, and it is as convenient as it is efficient and secure. + +Note that PuTTY may have problems using various versions of these keys, and you may need to remove passwords for a successful import into the PuTTY agent. + +These keys represent the most secure formats available for various OpenSSH revisions. They really aren't intended for PuTTY or other general interactive activity. Although one hopes that all users create strong keys for all situations, these are enterprise-class keys for major systems activities. It might be wise, however, to regenerate your system host keys to conform to these guidelines. + +These key formats may soon change. Quantum computers are causing increasing concern for their ability to run [Shor's Algorithm][15], which can be used to find prime factors to break these keys in reasonable time. The largest commercially available quantum computer, the [D-Wave 2000Q][16], effectively [presents under 200 qubits][17] for this activity, which is not (yet) powerful enough for a successful attack. NIST [announced a competition][18] for a new quantum-resistant public key system with a deadline of November 2017 In response, a team including DJB has released source code for [NTRU Prime][19]. It does appear that we will likely see a post-quantum public key format for OpenSSH (and potentially TLS 1.3) released within the next two years, so take steps to ease migration now. + +Also, it's important for SSH servers to restrict their allowed ciphers, MACs and key exchange lest strong keys be wasted on broken crypto (3DES, MD5 and arcfour should be long-disabled). My [previous guidance][20] on the subject involved the following (three) lines in the SSH client and server configuration (note that formatting in the sshd_config file requires all parameters on the same line with no spaces in the options; line breaks have been added here for clarity): + +``` + +Ciphers chacha20-poly1305@openssh.com, + aes256-gcm@openssh.com, + aes128-gcm@openssh.com, + aes256-ctr, + aes192-ctr, + aes128-ctr + +MACs hmac-sha2-512-etm@openssh.com, + hmac-sha2-256-etm@openssh.com, + hmac-ripemd160-etm@openssh.com, + umac-128-etm@openssh.com, + hmac-sha2-512, + hmac-sha2-256, + hmac-ripemd160, + umac-128@openssh.com + +KexAlgorithms curve25519-sha256@libssh.org, + diffie-hellman-group-exchange-sha256 + +``` + +Since the previous publication, RIPEMD160 is likely no longer safe and should be removed. Older systems, however, may support only SHA1, MD5 and RIPEMD160\. Certainly remove MD5, but users of PuTTY likely will want to retain SHA1 when newer MACs are not an option. Older servers can present a challenge in finding a reasonable Cipher/MAC/KEX when working with modern systems. + +At this point, you should have strong keys for secure clients and servers. Now let's put them to use. + +### Scripting the SSH Agent + +Modern OpenSSH distributions contain the ssh-copy-id shell script for easy key distribution. Below is an example of installing a specific, named key in a remote account: + +``` + +$ ssh-copy-id -i ~/.ssh/some_key.pub person@yourserver.com +ssh-copy-id: INFO: Source of key(s) to be installed: + "/home/cfisher/.ssh/some_key.pub" +ssh-copy-id: INFO: attempting to log in with the new key(s), + to filter out any that are already installed +ssh-copy-id: INFO: 1 key(s) remain to be installed -- + if you are prompted now it is to install the new keys +person@yourserver.com's password: + +Number of key(s) added: 1 + +Now try logging into the machine, with: + "ssh 'person@yourserver.com'" +and check to make sure that only the key(s) you wanted were added. + +``` + +If you don't have the ssh-copy-id script, you can install a key manually with the following command: + +``` + +$ ssh person@yourserver.com 'cat >> ~/.ssh/authorized_keys' < \ + ~/.ssh/some_key.pub + +``` + +If you have SELinux enabled, you might have to mark a newly created authorized_keys file with a security type; otherwise, the sshd server dæmon will be prevented from reading the key (the syslog may report this issue): + +``` + +$ ssh person@yourserver.com 'chcon -t ssh_home_t + ↪~/.ssh/authorized_keys' + +``` + +Once your key is installed, test it in a one-time use with the -i option (note that you are entering a local key password, not a remote authentication password): + +``` + +$ ssh -i ~/.ssh/some_key person@yourserver.com +Enter passphrase for key '/home/v-fishecj/.ssh/some_key': +Last login: Wed Aug 16 12:20:26 2017 from 10.58.17.14 +yourserver $ + +``` + +General, interactive users likely will cache their keys with an agent. In the example below, the same password is used on all three types of keys that were created in the previous section: + +``` + +$ eval $(ssh-agent) +Agent pid 4394 + +$ ssh-add +Enter passphrase for /home/cfisher/.ssh/id_rsa: +Identity added: ~cfisher/.ssh/id_rsa (~cfisher/.ssh/id_rsa) +Identity added: ~cfisher/.ssh/id_ecdsa (cfisher@init.com) +Identity added: ~cfisher/.ssh/id_ed25519 (cfisher@init.com) + +``` + +The first command above launches a user agent process, which injects environment variables (named SSH_AGENT_SOCK and SSH_AGENT_PID) into the parent shell (via eval). The shell becomes aware of the agent and passes these variables to the programs that it runs from that point forward. + +When launched, the ssh-agent has no credentials and is unable to facilitate SSH activity. It must be primed by adding keys, which is done with ssh-add. When called with no arguments, all of the default keys will be read. It also can be called to add a custom key: + +``` + +$ ssh-add ~/.ssh/some_key +Enter passphrase for /home/cfisher/.ssh/some_key: +Identity added: /home/cfisher/.ssh/some_key + ↪(cfisher@localhost.localdomain) + +``` + +Note that the agent will not retain the password on the key. ssh-add uses any and all passwords that you enter while it runs to decrypt keys that it finds, but the passwords are cleared from memory when ssh-add terminates (they are not sent to ssh-agent). This allows you to upgrade to new key formats with minimal inconvenience, while keeping the keys reasonably safe. + +The current cached keys can be listed with ssh-add -l (from, which you can deduce that "some_key" is an Ed25519): + +``` + +$ ssh-add -l +3072 SHA256:cpVFMZ17oO5n/Jfpv2qDNSNcV6ffOVYPV8vVaSm3DDo + /home/cfisher/.ssh/id_rsa (RSA) +521 SHA256:1L9/CglR7cstr54a600zDrBbcxMj/a3RtcsdjuU61VU + cfisher@localhost.localdomain (ECDSA) +256 SHA256:Vd21LEM4lixY4rIg3/Ht/w8aoMT+tRzFUR0R32SZIJc + cfisher@localhost.localdomain (ED25519) +256 SHA256:YsKtUA9Mglas7kqC4RmzO6jd2jxVNCc1OE+usR4bkcc + cfisher@localhost.localdomain (ED25519) + +``` + +While a "primed" agent is running, the SSH clients may use (trusting) remote servers fluidly, with no further prompts for credentials: + +``` + +$ sftp person@yourserver.com +Connected to yourserver.com. +sftp> quit + +$ scp /etc/passwd person@yourserver.com:/tmp +passwd 100% 2269 65.8KB/s 00:00 + +$ ssh person@yourserver.com + (motd for yourserver.com) +$ ls -l /tmp/passwd +-rw-r--r-- 1 root wheel 2269 Aug 16 09:07 /tmp/passwd +$ rm /tmp/passwd +$ exit +Connection to yourserver.com closed. + +``` + +The OpenSSH agent can be locked, preventing any further use of the credentials that it holds (this might be appropriate when suspending a laptop): + +``` + +$ ssh-add -x +Enter lock password: +Again: +Agent locked. + +$ ssh yourserver.com +Enter passphrase for key '/home/cfisher/.ssh/id_rsa': ^C + +``` + +It will provide credentials again when it is unlocked: + +``` + +$ ssh-add -X +Enter lock password: +Agent unlocked. + +``` + +You also can set ssh-agent to expire keys after a time limit with the -t option, which may be useful for long-lived agents that must clear keys after a set daily shift. + +General shell users may cache many types of keys with a number of differing agent implementations. In addition to the standard OpenSSH agent, users may rely upon PuTTY's pageant.exe, GNOME keyring or KDE Kwallet, among others (the use of the PUTTY agent could likely fill an article on its own). + +However, the goal here is to create "enterprise" keys for critical server controls. You likely do not want long-lived agents in order to limit the risk of exposure. When scripting with "enterprise" keys, you will run an agent only for the duration of the activity, then kill it at completion. + +There are special options for accessing the root account with OpenSSH—the PermitRootLogin parameter can be added to the sshd_config file (usually found in /etc/ssh). It can be set to a simple yes or no, forced-commands-only, which will allow only explicitly-authorized programs to be executed, or the equivalent options prohibit-password or without-password, both of which will allow access to the keys generated here. + +Many hold that root should not be allowed any access. [Michael W. Lucas][21] addresses the question in SSH Mastery: + +> Sometimes, it seems that you need to allow users to SSH in to the system as root. This is a colossally bad idea in almost all environments. When users must log in as a regular user and then change to root, the system logs record the user account, providing accountability. Logging in as root destroys that audit trail....It is possible to override the security precautions and make sshd permit a login directly as root. It's such a bad idea that I'd consider myself guilty of malpractice if I told you how to do it. Logging in as root via SSH almost always means you're solving the wrong problem. Step back and look for other ways to accomplish your goal. + +When root action is required quickly on more than a few servers, the above advice can impose painful delays. Lucas' direct criticism can be addressed by allowing only a limited set of "bastion" servers to issue root commands over SSH. Administrators should be forced to log in to the bastions with unprivileged accounts to establish accountability. + +However, one problem with remotely "changing to root" is the [statistical use of the Viterbi algorithm][22] Short passwords, the su - command and remote SSH calls that use passwords to establish a trinary network configuration are all uniquely vulnerable to timing attacks on a user's keyboard movement. Those with the highest security concerns will need to compensate. + +For the rest of us, I recommend that PermitRootLogin without-password be set for all target machines. + +Finally, you can easily terminate ssh-agent interactively with the -k option: + +``` + +$ eval $(ssh-agent -k) +Agent pid 4394 killed + +``` + +With these tools and the intended use of them in mind, here is a complete script that runs an agent for the duration of a set of commands over a list of servers for a common named user (which is not necessarily root): + +``` + +# cat artano + +#!/bin/sh + +if [[ $# -lt 1 ]]; then echo "$0 - requires commands"; exit; fi + +R="-R5865:127.0.0.1:5865" # set to "-2" if you don't want + ↪port forwarding + +eval $(ssh-agent -s) + +function cleanup { eval $(ssh-agent -s -k); } + +trap cleanup EXIT + +function remsh { typeset F="/tmp/${1}" h="$1" p="$2"; + ↪shift 2; echo "#$h" + if [[ "$ARTANO" == "PARALLEL" ]] + then ssh "$R" -p "$p" "$h" "$@" < /dev/null >>"${F}.out" + ↪2>>"${F}.err" & + else ssh "$R" -p "$p" "$h" "$@" + fi } # HOST PORT CMD + +if ssh-add ~/.ssh/master_key +then remsh yourserver.com 22 "$@" + remsh container.yourserver.com 2200 "$@" + remsh anotherserver.com 22 "$@" + # Add more hosts here. +else echo Bad password - killing agent. Try again. +fi + +wait + +####################################################################### +# Examples: # Artano is an epithet of a famous mythical being +# artano 'mount /patchdir' # you will need an fstab entry for this +# artano 'umount /patchdir' +# artano 'yum update -y 2>&1' +# artano 'rpm -Fvh /patchdir/\*.rpm' +####################################################################### + +``` + +This script runs all commands in sequence on a collection of hosts by default. If the ARTANO environment variable is set to PARALLEL, it instead will launch them all as background processes simultaneously and append their STDOUT and STDERR to files in /tmp (this should be no problem when dealing with fewer than a hundred hosts on a reasonable server). The PARALLEL setting is useful not only for pushing changes faster, but also for collecting audit results. + +Below is an example using the yum update agent. The source of this particular invocation had to traverse a firewall and relied on a proxy setting in the /etc/yum.conf file, which used the port-forwarding option (-R) above: + +``` + +# ./artano 'yum update -y 2>&1' +Agent pid 3458 +Enter passphrase for /root/.ssh/master_key: +Identity added: /root/.ssh/master_key (/root/.ssh/master_key) +#yourserver.com +Loaded plugins: langpacks, ulninfo +No packages marked for update +#container.yourserver.com +Loaded plugins: langpacks, ulninfo +No packages marked for update +#anotherserver.com +Loaded plugins: langpacks, ulninfo +No packages marked for update +Agent pid 3458 killed + +``` + +The script can be used for more general maintenance functions. Linux installations running the XFS filesystem should "defrag" periodically. Although this normally would be done with cron, it can be a centralized activity, stored in a separate script that includes only on the appropriate hosts: + +``` + +&1' +Agent pid 7897 +Enter passphrase for /root/.ssh/master_key: +Identity added: /root/.ssh/master_key (/root/.ssh/master_key) +#yourserver.com +#container.yourserver.com +#anotherserver.com +Agent pid 7897 killed + +``` + +An easy method to collect the contents of all authorized_keys files for all users is the following artano script (this is useful for system auditing and is coded to remove file duplicates): + +``` + +artano 'awk -F: {print\$6\"/.ssh/authorized_keys\"} \ + /etc/passwd | sort -u | xargs grep . 2> /dev/null' + +``` + +It is convenient to configure NFS mounts for file distribution to remote nodes. Bear in mind that NFS is clear text, and sensitive content should not traverse untrusted networks while unencrypted. After configuring an NFS server on host 1.2.3.4, I add the following line to the /etc/fstab file on all the clients and create the /patchdir directory. After the change, the artano script can be used to mass-mount the directory if the network configuration is correct: + +``` + +# tail -1 /etc/fstab +1.2.3.4:/var/cache/yum/x86_64/7Server/ol7_latest/packages + ↪/patchdir nfs4 noauto,proto=tcp,port=2049 0 0 + +``` + +Assuming that the NFS server is mounted, RPMs can be upgraded from images stored upon it (note that Oracle Spacewalk or Red Hat Satellite might be a more capable patch method): + +``` + +# ./artano 'rpm -Fvh /patchdir/\*.rpm' +Agent pid 3203 +Enter passphrase for /root/.ssh/master_key: +Identity added: /root/.ssh/master_key (/root/.ssh/master_key) +#yourserver.com +Preparing... ######################## +Updating / installing... +xmlsec1-1.2.20-7.el7_4 ######################## +xmlsec1-openssl-1.2.20-7.el7_4 ######################## +Cleaning up / removing... +xmlsec1-openssl-1.2.20-5.el7 ######################## +xmlsec1-1.2.20-5.el7 ######################## +#container.yourserver.com +Preparing... ######################## +Updating / installing... +xmlsec1-1.2.20-7.el7_4 ######################## +xmlsec1-openssl-1.2.20-7.el7_4 ######################## +Cleaning up / removing... +xmlsec1-openssl-1.2.20-5.el7 ######################## +xmlsec1-1.2.20-5.el7 ######################## +#anotherserver.com +Preparing... ######################## +Updating / installing... +xmlsec1-1.2.20-7.el7_4 ######################## +xmlsec1-openssl-1.2.20-7.el7_4 ######################## +Cleaning up / removing... +xmlsec1-openssl-1.2.20-5.el7 ######################## +xmlsec1-1.2.20-5.el7 ######################## +Agent pid 3203 killed + +``` + +I am assuming that my audience is already experienced with package tools for their preferred platforms. However, to avoid criticism that I've included little actual discussion of patch tools, the following is a quick reference of RPM manipulation commands, which is the most common package format on enterprise systems: + +* rpm -Uvh package.i686.rpm — install or upgrade a package file. + +* rpm -Fvh package.i686.rpm — upgrade a package file, if an older version is installed. + +* rpm -e package — remove an installed package. + +* rpm -q package — list installed package name and version. + +* rpm -q --changelog package — print full changelog for installed package (including CVEs). + +* rpm -qa — list all installed packages on the system. + +* rpm -ql package — list all files in an installed package. + +* rpm -qpl package.i686.rpm — list files included in a package file. + +* rpm -qi package — print detailed description of installed package. + +* rpm -qpi package — print detailed description of package file. + +* rpm -qf /path/to/file — list package that installed a particular file. + +* rpm --rebuild package.src.rpm — unpack and build a binary RPM under /usr/src/redhat. + +* rpm2cpio package.src.rpm | cpio -icduv — unpack all package files in the current directory. + +Another important consideration for scripting the SSH agent is limiting the capability of an authorized key. There is a [specific syntax][23] for such limitations Of particular interest is the from="" clause, which will restrict logins on a key to a limited set of hosts. It is likely wise to declare a set of "bastion" servers that will record non-root logins that escalate into controlled users who make use of the enterprise keys. + +An example entry might be the following (note that I've broken this line, which is not allowed syntax but done here for clarity): + +``` + +from="*.c2.security.yourcompany.com,4.3.2.1" ssh-ed25519 + ↪AAAAC3NzaC1lZDI1NTE5AAAAIJSSazJz6A5x6fTcDFIji1X+ +↪svesidBonQvuDKsxo1Mx + +``` + +A number of other useful restraints can be placed upon authorized_keys entries. The command="" will restrict a key to a single program or script and will set the SSH_ORIGINAL_COMMAND environment variable to the client's attempted call—scripts can set alarms if the variable does not contain approved contents. The restrict option also is worth consideration, as it disables a large set of SSH features that can be both superfluous and dangerous. + +Although it is possible to set server identification keys in the known_hosts file to a @revoked status, this cannot be done with the contents of authorized_keys. However, a system-wide file for forbidden keys can be set in the sshd_config with RevokedKeys. This file overrides any user's authorized_keys. If set, this file must exist and be readable by the sshd server process; otherwise, no keys will be accepted at all (so use care if you configure it on a machine where there are obstacles to physical access). When this option is set, use the artano script to append forbidden keys to the file quickly when they should be disallowed from the network. A clear and convenient file location would be /etc/ssh/revoked_keys. + +It is also possible to establish a local Certificate Authority (CA) for OpenSSH that will [allow keys to be registered with an authority][24] with expiration dates. These CAs can [become quite elaborate][25] in their control over an enterprise. Although the maintenance of an SSH CA is beyond the scope of this article, keys issued by such CAs should be strong by adhering to the requirements for Ed25519/E-521/RSA-3072. + +### pdsh + +Many higher-level tools for the control of collections of servers exist that are much more sophisticated than the script I've presented here. The most famous is likely [Puppet][26], which is a Ruby-based configuration management system for enterprise control. Puppet has a somewhat short list of supported operating systems. If you are looking for low-level control of Android, Tomato, Linux smart terminals or other "exotic" POSIX, Puppet is likely not the appropriate tool. Another popular Ruby-based tool is [Chef][27], which is known for its complexity. Both Puppet and Chef require Ruby installations on both clients and servers, and they both will catalog any SSH keys that they find, so this key strength discussion is completely applicable to them. + +There are several similar Python-based tools, including [Ansible][28], [Bcfg2][29], [Fabric][30] and [SaltStack][31]. Of these, only Ansible can run "agentless" over a bare SSH connection; the rest will require agents that run on target nodes (and this likely includes a Python runtime). + +Another popular configuration management tool is [CFEngine][32], which is coded in C and claims very high performance. [Rudder][33] has evolved from portions of CFEngine and has a small but growing user community. + +Most of the previously mentioned packages are licensed commercially and some are closed source. + +The closest low-level tool to the activities presented here is the Parallel Distributed Shell (pdsh), which can be found in the [EPEL repository][34]. The pdsh utilities grew out of an IBM-developed package named dsh designed for the control of compute clusters. Install the following packages from the repository to use pdsh: + +``` + +# rpm -qa | grep pdsh +pdsh-2.31-1.el7.x86_64 +pdsh-rcmd-ssh-2.31-1.el7.x86_64 + +``` + +An SSH agent must be running while using pdsh with encrypted keys, and there is no obvious way to control the destination port on a per-host basis as was done with the artano script. Below is an example using pdsh to run a command on three remote servers: + +``` + +# eval $(ssh-agent) +Agent pid 17106 + +# ssh-add ~/.ssh/master_key +Enter passphrase for /root/.ssh/master_key: +Identity added: /root/.ssh/master_key (/root/.ssh/master_key) + +# pdsh -w hosta.com,hostb.com,hostc.com uptime +hosta: 13:24:49 up 13 days, 2:13, 6 users, load avg: 0.00, 0.01, 0.05 +hostb: 13:24:49 up 7 days, 21:15, 5 users, load avg: 0.05, 0.04, 0.05 +hostc: 13:24:49 up 9 days, 3:26, 3 users, load avg: 0.00, 0.01, 0.05 + +# eval $(ssh-agent -k) +Agent pid 17106 killed + +``` + +The -w option above defines a host list. It allows for limited arithmetic expansion and can take the list of hosts from standard input if the argument is a dash (-). The PDSH_SSH_ARGS and PDSH_SSH_ARGS_APPEND environment variables can be used to pass custom options to the SSH call. By default, 32 sessions will be launched in parallel, and this "fanout/sliding window" will be maintained by launching new host invocations as existing connections complete and close. You can adjust the size of the "fanout" either with the -f option or the FANOUT environment variable. It's interesting to note that there are two file copy commands: pdcp and rpdcp, which are analogous to scp. + +Even a low-level utility like pdsh lacks some flexibility that is available by scripting OpenSSH, so prepare to feel even greater constraints as more complicated tools are introduced. + +### Conclusion + +Modern Linux touches us in many ways on diverse platforms. When the security of these systems is not maintained, others also may touch our platforms and turn them against us. It is important to realize the maintenance obligations when you add any Linux platform to your environment. This obligation always exists, and there are consequences when it is not met. + +In a security emergency, simple, open and well understood tools are best. As tool complexity increases, platform portability certainly declines, the number of competent administrators also falls, and this likely impacts speed of execution. This may be a reasonable trade in many other aspects, but in a security context, it demands a much more careful analysis. Emergency measures must be documented and understood by a wider audience than is required for normal operations, and using more general tools facilitates that discussion. + +I hope the techniques presented here will prompt that discussion for those who have not yet faced it. + +### Disclaimer + +The views and opinions expressed in this article are those of the author and do not necessarily reflect those of Linux Journal. + +### Note: + +An exploit [compromising Ed25519][35] was recently demonstrated that relies upon custom hardware changes to derive a usable portion of a secret key. Physical hardware security is a basic requirement for encryption integrity, and many common algorithms are further vulnerable to cache timing or other side channel attacks that can be performed by the unprivileged processes of other users. Use caution when granting access to systems that process sensitive data. + + +-------------------------------------------------------------------------------- + +via: http://www.linuxjournal.com/content/rapid-secure-patching-tools-and-methods + +作者:[Charles Fisher][a] +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:http://www.linuxjournal.com/users/charles-fisher +[1]:https://en.wikipedia.org/wiki/EternalBlue +[2]:http://securityaffairs.co/wordpress/61530/hacking/smbloris-smbv1-flaw.html +[3]:http://www.telegraph.co.uk/news/2017/05/13/nhs-cyber-attack-everything-need-know-biggest-ransomware-offensive +[4]:http://www.linuxjournal.com/content/smbclient-security-windows-printing-and-file-transfer +[5]:https://staff.washington.edu/dittrich/misc/forensics +[6]:https://ed25519.cr.yp.to +[7]:http://www.metzdowd.com/pipermail/cryptography/2016-March/028824.html +[8]:https://blog.g3rt.nl/upgrade-your-ssh-keys.html +[9]:https://news.ycombinator.com/item?id=12563899 +[10]:http://safecurves.cr.yp.to/rigid.html +[11]:https://en.wikipedia.org/wiki/Curve25519 +[12]:http://blog.cr.yp.to/20140323-ecdsa.html +[13]:https://lwn.net/Articles/573166 +[14]:http://martin.kleppmann.com/2013/05/24/improving-security-of-ssh-private-keys.html +[15]:https://en.wikipedia.org/wiki/Shor's_algorithm +[16]:https://www.dwavesys.com/d-wave-two-system +[17]:https://crypto.stackexchange.com/questions/40893/can-or-can-not-d-waves-quantum-computers-use-shors-and-grovers-algorithm-to-f +[18]:https://yro.slashdot.org/story/16/12/21/2334220/nist-asks-public-for-help-with-quantum-proof-cryptography +[19]:https://ntruprime.cr.yp.to/index.html +[20]:http://www.linuxjournal.com/content/cipher-security-how-harden-tls-and-ssh +[21]:https://www.michaelwlucas.com/tools/ssh +[22]:https://people.eecs.berkeley.edu/~dawnsong/papers/ssh-timing.pdf +[23]:https://man.openbsd.org/sshd#AUTHORIZED_KEYS_FILE_FORMAT +[24]:https://ef.gy/hardening-ssh +[25]:https://code.facebook.com/posts/365787980419535/scalable-and-secure-access-with-ssh +[26]:https://puppet.com +[27]:https://www.chef.io +[28]:https://www.ansible.com +[29]:http://bcfg2.org +[30]:http://www.fabfile.org +[31]:https://saltstack.com +[32]:https://cfengine.com +[33]:http://www.rudder-project.org/site +[34]:https://fedoraproject.org/wiki/EPEL +[35]:https://research.kudelskisecurity.com/2017/10/04/defeating-eddsa-with-faults diff --git a/sources/tech/20180129 WebSphere MQ programming in Python with Zato.md b/sources/tech/20180129 WebSphere MQ programming in Python with Zato.md new file mode 100644 index 0000000000..3e53d67201 --- /dev/null +++ b/sources/tech/20180129 WebSphere MQ programming in Python with Zato.md @@ -0,0 +1,262 @@ +WebSphere MQ programming in Python with Zato +====== +[WebSphere MQ][1] is a messaging middleware product by IBM - a message queue server - and this post shows how to integrate with MQ from Python and [Zato][2]. + +The article will go through a short process that will let you: + + * Send messages to queues in 1 line of Python code + * Receive messages from queues without coding + * Seamlessly integrate with Java JMS applications - frequently found in WebSphere MQ environments + * Push MQ messages from [Django][3] or [Flask][4] + + + +### Prerequisites + + * [Zato][2] 3.0+ (e.g. from [source code][5]) + * WebSphere MQ 6.0+ + + + +### Preliminary steps + + * Obtain connection details and credentials to the queue manager that you will be connecting to: + + * host, e.g. 10.151.13.11 + * port, e.g. 1414 + * channel name, e.g. DEV.SVRCONN.1 + * queue manager name (optional) + * username (optional) + * password (optional) + * Install [Zato][6] + + * On the same system that Zato is on, install a [WebSphere MQ Client][7] \- this is an umbrella term for a set of development headers and libraries that let applications connect to remote queue managers + + * Install [PyMQI][8] \- an additional dependency implementing the low-level proprietary MQ protocol. Note that you need to use the pip command that Zato ships with: + + + +``` +# Assuming Zato is in /opt/zato/current +zato$ cd /opt/zato/current/bin +zato$ ./pip install pymqi + +``` + + * That is it - everything is installed and the rest is a matter of configuration + + + +### Understanding definitions, outgoing connections and channels + +Everything in Zato revolves around re-usability and hot-reconfiguration - each individual piece of configuration can be changed on the fly, while servers are running, without restarts. + +Note that the concepts below are presented in the context of WebSphere MQ but they apply to other connection types in Zato too. + + * **Definitions** \- encapsulate common details that apply to other parts of configuration, e.g. a connection definition may contain remote host and port + * **Outgoing connections** \- objects through which data is sent to remote resources, such as MQ queues + * **Channels** \- objects through which data can be received, for instance, from MQ queues + + + +It is usually most convenient to configure environments during development using [web-admin GUI][9] but afterwards this can be automated with [enmasse][10], [API][11] or [command-line interface][12]. + +Once configuration is defined, it can be used from Zato services which in turn represent APIs that Zato clients invoke. Then, external applications, such as a Django or Flask, will connect using HTTP to a Zato service which will on their behalf send messages to MQ queues. + +Let's use web-admin to define all the Zato objects required for MQ integrations. (Hint: web-admin by default runs on ) + +### Definition + + * Go to Connections -> Definitions -> WebSphere MQ + * Fill out the form and click OK + * Observe the 'Use JMS' checkbox - more about it later on + + + +![Screenshots][13] + + * Note that a password is by default set to an unusable one (a random UUID4) so once a definition is created, click on Change password to set it to a required one + + + +![Screenshots][14] + + * Click Ping to confirm that connections to the remote queue manager can be established + + + +![Screenshots][15] + +### Outgoing connection + + * Go to Connections -> Outgoing -> WebSphere MQ + * Fill out the form - the connection's name is just a descriptive label + * Note that you do not specify a queue name here - this is because a single connection can be used with as many queues as needed + + + +![Screenshots][16] + + * You can now send a test MQ message directly from web-admin after click Send a message + + + +![Screenshots][17] + +![Screenshots][18] + +### API services + + * Having carried out the steps above, you can now send messages to queue managers from web-admin, which is a great way to confirm MQ-level connectivity but the crucial point of using Zato is to offer API services to client applications so let's create two services now, one for sending messages to MQ and one that will receive them. + + + +``` +# -*- coding: utf-8 -*- + +from __future__ import absolute_import, division, print_function, unicode_literals + +# Zato +from zato.server.service import Service + +class MQSender(Service): + """ Sends all incoming messages as they are straight to a remote MQ queue. + """ + def handle(self): + + # This single line suffices + self.out.wmq.send(self.request.raw_request, 'customer.updates', 'CUSTOMER.1') +``` + + * In practice, a service such as the one above could perform transformation on incoming messages or read its destination queue names from configuration files but it serves to illustrate the point that literally 1 line of code is needed to send MQ messages + + * Let's create a channel service now - one that will act as a callback invoked for each message consumed off a queue: + + + +``` +# -*- coding: utf-8 -*- + +from __future__ import absolute_import, division, print_function, unicode_literals + +# Zato +from zato.server.service import Service + +class MQReceiver(Service): + """ Invoked for each message taken from a remote MQ queue + """ + def handle(self): + self.logger.info(self.request.raw_request) +``` + +But wait - if this is the service that is a callback one then how does it know which queue to get messages from? + +That is the key point of Zato architecture - services do not need to know it and unless you really need it, they won't ever access this information. + +Such configuration details are configured externally (for instance, in web-admin) and a service is just a black box that receives some input, operates on it and produces output. + +In fact, the very same service could be mounted not only on WebSphere MQ ones but also on REST or AMQP channels. + +Without further ado, let's create a channel in that case, but since this is an article about MQ, only this connection type will be shown even if the same principle applies to other channel types. + +### Channel + + * Go to Connections -> Channels -> WebSphere MQ + * Fill out the form and click OK + * Data format may be JSON, XML or blank if no automatic de-serialization is required + + + +![Screenshots][19] + +After clicking OK a lightweight background task will start to listen for messages pertaining to a given queue and upon receiving any, the service configured for channel will be invoked. + +You can start as many channels as there are queues to consume messages from, that is, each channel = one input queue and each channel may declare a different service. + +### JMS Java integration + +In many MQ environments the majority of applications will be based on Java JMS and Zato implements the underlying wire-level MQ JMS protocol to let services integrate with such systems without any effort from a Python programmer's perspective. + +When creating connection definitions, merely check Use JMS and everything will be taken care of under the hood - all the necessary wire headers will be added or removed when it needs to be done. + +![Screenshots][20] + +### No restarts required + +It's worth to emphasize again that at no point are server restarts required to reconfigure connection details. + +No matter how many definitions, outgoing connections, channels there are, and no matter of what kind they are (MQ or not), changing any of them will only update that very one across the whole cluster of Zato servers without interrupting other API services running concurrently. + +### Configuration wrap-up + + * MQ connection definitions are re-used across outgoing connections and channels + * Outgoing connections are used by services to send messages to queues + * Data from queues is read through channels that invoke user-defined services + * Everything is reconfigurable on the fly + + + +Let's now check how to add a REST channel for the MQSender service thus letting Django and Flask push MQ messages. + +### Django and Flask integration + + * Any Zato-based API service can be mounted on a channel + * For Django and Flask, it is most convenient to mount one's services on REST channels and invoke them using the [zato-client][21] from PyPI + * zato-client is a set of convenience clients that lets any Python application, including ones based on Django or Flask, to invoke Zato services in just a few steps + * There is [a dedicated chapter][22] in documentation about Django and Flask, including a sample integration scenario + * It's recommended to go through the chapter step-by-step - since all Zato configuration objects share the same principles, the whole of its information applies to any sort of technology that Django or Flask may need to integrate with, including WebSphere MQ + * After completing that chapter, to push messages to MQ, you will only need to: + * Create a security definition for a new REST channel for Django or Flask + * Create the REST channel itself + * Assign a service to it (e.g. MQSender) + * Use a Python client from zato-client to invoke that channel from Django or Flask + * And that is it - no MQ programming is needed to send messages to MQ queues from any Python application :-) + + + +### Summary + + * Zato lets Python programmers integrate with WebSphere MQ with little to no effort + * Built-in support for JMS lets one integrate with existing Java applications in a transparent manner + * Built-in Python clients offer trivial access to Zato-based API services from other Python applications, including Django or Flask + + + +Where to next? Start off with the [tutorial][23], then consult the [documentation][24], there is a lot of information for all types of API and integration projects, and have a look at [support options][25] in case you need absolutely any sort of assistance! + +-------------------------------------------------------------------------------- + +via: https://zato.io/blog/posts/websphere-mq-python-zato.html + +作者:[zato][a] +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://zato.io +[1]:https://en.wikipedia.org/wiki/IBM_WebSphere_MQ +[2]:https://zato.io/docs +[3]:https://www.djangoproject.com/ +[4]:http://flask.pocoo.org/ +[5]:https://zato.io/docs/admin/guide/install/source.html +[6]:https://zato.io/docs/admin/guide/install/index.html +[7]:https://www.ibm.com/support/knowledgecenter/en/SSFKSJ_7.0.1/com.ibm.mq.csqzaf.doc/cs10230_.htm +[8]:https://github.com/dsuch/pymqi/ +[9]:https://zato.io/docs/web-admin/intro.html +[10]:https://zato.io/docs/admin/guide/enmasse.html +[11]:https://zato.io/docs/public-api/intro.html +[12]:https://zato.io/docs/admin/cli/index.html +[13]:https://zato.io/blog/images/wmq-python-zato/def-create.png +[14]:https://zato.io/blog/images/wmq-python-zato/def-options.png +[15]:https://zato.io/blog/images/wmq-python-zato/def-ping.png +[16]:https://zato.io/blog/images/wmq-python-zato/outconn-create.png +[17]:https://zato.io/blog/images/wmq-python-zato/outconn-options.png +[18]:https://zato.io/blog/images/wmq-python-zato/outconn-send.png +[19]:https://zato.io/blog/images/wmq-python-zato/channel-create.png +[20]:https://zato.io/blog/images/wmq-python-zato/def-create-jms.png +[21]:https://pypi.python.org/pypi/zato-client +[22]:https://zato.io/docs/progguide/clients/django-flask.html +[23]:https://zato.io/docs/tutorial/01.html +[24]:https://zato.io/docs/ +[25]:https://zato.io/support.html diff --git a/sources/tech/20180129 What Happens When You Want to Create a Special Fille with All Special Characters in Linux.md b/sources/tech/20180129 What Happens When You Want to Create a Special Fille with All Special Characters in Linux.md new file mode 100644 index 0000000000..60e923fd46 --- /dev/null +++ b/sources/tech/20180129 What Happens When You Want to Create a Special Fille with All Special Characters in Linux.md @@ -0,0 +1,189 @@ +What Happens When You Want to Create a Special File with All Special Characters in Linux? +============================================================ + + +![special chars](https://www.linux.com/sites/lcom/files/styles/rendered_file/public/special-chars.png?itok=EEvlt5Nw "special chars") +Learn how to handle creation of a special file filled with special characters.[Used with permission][1] + +I recently joined Holberton School as a student, hoping to learn full-stack software development. What I did not expect was that in two weeks I would be pretty much proficient with creating shell scripts that would make my coding life easy and fast! + +So what is the post about? It is about a novel problem that my peers and I faced when we were asked to create a file with no regular alphabets/ numbers but instead special characters!! Just to give you a look at what kind of file name we were dealing with — + +### \*\\’”Holberton School”\’\\*$\?\*\*\*\*\*:) + +What a novel file name! Of course, this question was met with the collective groaning and long drawn sighs of all 55 (batch #5) students! + +![1*Lf_XPhmgm-RB5ipX_lBjsQ.gif](https://cdn-images-1.medium.com/max/1600/1*Lf_XPhmgm-RB5ipX_lBjsQ.gif) + +Some proceeded to make their lives easier by breaking the file name into pieces on a doc file and adding in the **“\\” or “\”** in front of certain special character which kind of resulted in this format - + +#### \\*\\\\’\”Holberton School\”\\’\\\\*$\\?\\*\\*\\*\\*\\*:) + +![1*p6s8WlysClalj0x2fQhGOg.gif](https://cdn-images-1.medium.com/max/1600/1*p6s8WlysClalj0x2fQhGOg.gif) + +Everyone trying to get the \\ right + +bamboozled? me, too! I did not want to believe that this was the only way to solve this, as I was getting frustrated with every “\\” or “\” that was required to escape and print those special characters as normal characters! + +If you’re new to shell scripting, here is a quick walk through on why so many “\\” , “\” were required and where. + +In shell scripting “ ” and ‘ ’ have special usage and once you understand and remember when and where to use them it can make your life easier! + +#### Double Quoting + +The first type of quoting we will look at is double quotes. **If you place text inside double quotes, all the special characters used by the shell lose their special meaning and are treated as ordinary characters. The exceptions are “$”, “\” (backslash), and “`” (back- quote).**This means that word-splitting, pathname expansion, tilde expansion, and brace expansion are suppressed, but parameter expansion, arithmetic expansion, and command substitution are still carried out. Using double quotes, we can cope with filenames containing embedded spaces. + +So this means that you can create file with names that have spaces between words — if that is your thing, but I would suggest you to not do that as it is inconvenient and rather an unpleasant experience for you to try to find that file when you need ! + +**Quoting “THE” guide for linux I follow and read like it is the Harry Potter of the linux coding world —** + +Say you were the unfortunate victim of a file called two words.txt. If you tried to use this on the command line, word-splitting would cause this to be treated as two separate arguments rather than the desired single argument: + +**[[me@linuxbox][3] me]$ ls -l two words.txt** + +``` +ls: cannot access two: No such file or directory +ls: cannot access words.txt: No such file or directory +``` + +By using double quotes, you can stop the word-splitting and get the desired result; further, you can even repair the damage: + +``` +[me@linuxbox me]$ ls -l “two words.txt” +-rw-rw-r — 1 me me 18 2008–02–20 13:03 two words.txt +[me@linuxbox me]$ mv “two words.txt” two_words.t +``` + +There! Now we don’t have to keep typing those pesky double quotes. + +Now, let us talk about single quotes and what is their significance in shell — + +#### Single Quotes + +Enclosing characters in single quotes (‘’’) preserves the literal value of each character within the quotes. A single quote may not occur between single quotes, even when preceded by a backslash. + +Yes! that got me and I was wondering how will I use it, apparently when I was googling to find and easier way to do it I stumbled across this piece of information on the internet — + +### Strong quoting + +Strong quoting is very easy to explain: + +Inside a single-quoted string **nothing** is interpreted, except the single-quote that closes the string. + +``` +echo 'Your PATH is: $PATH' +``` + +`$PATH` won't be expanded, it's interpreted as ordinary text because it's surrounded by strong quotes. + +In practice that means to produce a text like `Here's my test…` as a single-quoted string, **you have to leave and re-enter the single quoting to get the character "`'`" as literal text:** + +``` +# WRONG +echo 'Here's my test...' +``` + +``` +# RIGHT +echo 'Here'\''s my test...' +``` + +``` +# ALTERNATIVE: It's also possible to mix-and-match quotes for readability: +echo "Here's my test" +``` + +Well now you’re wondering — “well that explains the quotes but what about the “\”??” + +So for certain characters we need a special way to escape those pesky “\” we saw in that file name. + +#### Escaping Characters + +Sometimes you only want to quote a single character. To do this, you can precede a character with a backslash, which in this context is called the  _escape character_ . Often this is done inside double quotes to selectively prevent an expansion: + +``` +[me@linuxbox me]$ echo “The balance for user $USER is: \$5.00” +The balance for user me is: $5.00 +``` + +It is also common to use escaping to eliminate the special meaning of a character in a filename. For example, it is possible to use characters in filenames that normally have special meaning to the shell. These would include “$”, “!”, “&”, “ “, and others. To include a special character in a filename you can to this: + +``` +[me@linuxbox me]$ mv bad\&filename good_filename +``` + +> _**To allow a backslash character to appear, escape it by typing “\\”. Note that within single quotes, the backslash loses its special meaning and is treated as an ordinary character.**_ + +Looking at the filename now we can understand better as to why the “\\” were used in front of all those “\”s. + +So, to print the file name without losing “\” and other special characters what others did was to suppress the “\” with “\\” and to print the single quotes there are a few ways you can do that. + +``` +1. echo $'It\'s Shell Programming' # ksh, bash, and zsh only, does not expand variables +2. echo "It's Shell Programming" # all shells, expands variables +3. echo 'It'\''s Shell Programming' # all shells, single quote is outside the quotes +4\. echo 'It'"'"'s Shell Programming' # all shells, single quote is inside double quotes +``` + +``` +for further reading please follow this link +``` + +Looking at option 3, I realized this would mean that I would only need to use “\” and single quotes at certain places to be able to write the whole file without getting frustrated with “\\” placements. + +So with the hope in mind and lesser trial and errors I was actually able to print out the file name like this: + +#### ‘\*\\’\’’”Holberton School”\’\’’\\*$\?\*\*\*\*\*:)’ + +to understand better I have added an **“a”** instead of my single quotes so that the file name and process becomes more clearer. For a better understanding, I’ll break them down into modules: + +![1*hP1gmzbn7G7gUEhoynj1ew.gif](https://cdn-images-1.medium.com/max/1600/1*hP1gmzbn7G7gUEhoynj1ew.gif) + +#### a\*\\a \’ a”Holberton School”\a \’ a\\*$\?\*\*\*\*\*:)a + +#### Module 1 — a\*\\a + +Here the use of single quote (a) creates a safe suppression for \*\\ and as mentioned before in strong quoting, the only way we can print the ‘ is to leave and re-enter the single quoting to get the character. + +#### Module 2 , 4— \’ + +The \ suppresses the single quote as a standalone module. + +#### Module 3 — a”Holberton School”\a + +Here the use of single quote (a) creates a safe suppression for double quotes and \ along with regular text. + +#### Module 5 — a\\*$\?\*\*\*\*\*:)a + +Here the use of single quote (a) creates a safe suppression for all special characters being used such as *, \, $, ?, : and ). + +so in the end I was able to be lazy and maintain my sanity, and got away with only using single quotes to create small modules and “\” in certain places. + +![1*rO34jp-bYSkCnHSdwoO3qQ.gif](https://cdn-images-1.medium.com/max/1600/1*rO34jp-bYSkCnHSdwoO3qQ.gif) + +And, that is how I was able to get the file to work right! After a few misses, it felt amazing and it was great to learn a new way to do things! + +![1*PE9_VtcfGGQjnYMwJ8YB1A.gif](https://cdn-images-1.medium.com/max/1600/1*PE9_VtcfGGQjnYMwJ8YB1A.gif) + +Handled that curve-ball pretty well! Hope this helps you in the future when, someday you might need to create a special file for a special reason in shell! + + _**Mitali Sengupta **is a former digital marketing professional, currently enrolled as a full-stack engineering student at Holberton School. She is passionate about innovation in AI and Blockchain technologies.. You can contact Mitali on [Twitter][4], [LinkedIn][5] or [GitHub][6]._ + +-------------------------------------------------------------------------------- + +via: https://www.linux.com/blog/what-happens-when-you-want-create-special-file-all-special-characters-linux + +作者:[MITALI SENGUPTA ][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/mitalisengupta +[1]:https://www.linux.com/licenses/category/used-permission +[2]:https://www.linux.com/files/images/special-charspng +[3]:mailto:me@linuxbox +[4]:https://twitter.com/aadhiBangalan +[5]:https://www.linkedin.com/in/mitali-sengupta-auger +[6]:https://github.com/MitaliSengupta +[7]:http://mywiki.wooledge.org/Quotes#Examples \ No newline at end of file diff --git a/sources/tech/20180130 An introduction to the DomTerm terminal emulator for Linux.md b/sources/tech/20180130 An introduction to the DomTerm terminal emulator for Linux.md new file mode 100644 index 0000000000..4553570166 --- /dev/null +++ b/sources/tech/20180130 An introduction to the DomTerm terminal emulator for Linux.md @@ -0,0 +1,126 @@ +An introduction to the DomTerm terminal emulator for Linux +====== +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/osdc_terminals.png?itok=CfBqYBah) + +[DomTerm][1] is a modern terminal emulator that uses a browser engine as a "GUI toolkit." This enables some neat features, such as embeddable graphics and links, HTML rich text, and foldable (show/hide) commands. Otherwise it looks and feels like a feature-full, standalone terminal emulator, with excellent xterm compatibility (including mouse handling and 24-bit color), and appropriate "chrome" (menus). In addition, there is built-in support for session management and sub-windows (as in `tmux` and `GNU screen`), basic input editing (as in `readline`), and paging (as in `less`). + +![](https://opensource.com/sites/default/files/u128651/domterm1.png) +Image 1: The DomTerminal terminal emulator. View larger image. + +Below we'll look more at these features. We'll assume you have `domterm` installed (skip to the end of this article if you need to get and build DomTerm). First, though, here's a quick overview of the technology. + +### Frontend vs. backend + +Most of DomTerm is written in JavaScript and runs in a browser engine. This can be a desktop web browser, such as Chrome or Firefox (see image 3), or it can be an embedded browser. Using a general web browser works fine, but the user experience isn't as nice (as the menus are designed for general browsing, not for a terminal emulator), and the security model gets in the way, so using an embedded browser is nicer. + +The following are currently supported: + + * `qtdomterm`, which uses the Qt toolkit and `QtWebEngine` + * An `[Electron][2]` embedding (see image 1) + * `atom-domterm` runs DomTerm as a package in the [Atom text editor][3] (which is also based on Electron) and integrates with the Atom pane system (see image 2) + * A wrapper for JavaFX's `WebEngine`, which is useful for code written in Java (see image 4) + * Previously, the preferred frontend used [Firefox-XUL][4], but Mozilla has since dropped XUL + + + +![DomTerm terminal panes in Atom editor][6] + +Image 2: DomTerm terminal panes in Atom editor. [View larger image.][7] + +Currently, the Electron frontend is probably the nicest option, closely followed by the Qt frontend. If you use Atom, `atom-domterm` works pretty well. + +The backend server is written in C. It manages pseudo terminals (PTYs) and sessions. It is also an HTTP server that provides the JavaScript and other files to the frontend. The `domterm` command starts terminal jobs and performs other requests. If there is no server running, `domterm` daemonizes itself. Communication between the backend and the server is normally done using WebSockets (with [libwebsockets][8] on the server). However, the JavaFX embedding uses neither WebSockets nor the DomTerm server; instead Java applications communicate directly using the Java-JavaScript bridge. + +### A solid xterm-compatible terminal emulator + +DomTerm looks and feels like a modern terminal emulator. It handles mouse events, 24-bit color, Unicode, double-width (CJK) characters, and input methods. DomTerm does a very good job on the [vttest testsuite][9]. + +Unusual features include: + +**Show/hide buttons ("folding"):** The little triangles (seen in image 2 above) are buttons that hide/show the corresponding output. To create the buttons, just add certain [escape sequences][10] in the [prompt text][11]. + +**Mouse-click support for`readline` and similar input editors:** If you click in the (yellow) input area, DomTerm will send the right sequence of arrow-key keystrokes to the application. (This is enabled by escape sequences in the prompt; you can also force it using Alt+Click.) + +**Style the terminal using CSS:** This is usually done in `~/.domterm/settings.ini`, which is automatically reloaded when saved. For example, in image 2, terminal-specific background colors were set. + +### A better REPL console + +A classic terminal emulator works on rectangular grids of character cells. This works for a REPL (command shell), but it is not ideal. Here are some DomTerm features useful for REPLs that are not typically found in terminal emulators: + +**A command can "print" an image, a graph, a mathematical formula, or a set of clickable links:** An application can send an escape sequence containing almost any HTML. (The HTML is scrubbed to remove JavaScript and other dangerous features.) + +The image 3 shows a fragment from a [`gnuplot`][12] session. Gnuplot (2.1 or later) supports `domterm` as a terminal type. Graphical output is converted to an [SVG image][13], which is then printed to the terminal. My blog post [Gnuplot display on DomTerm][14] provides more information on this. + +![](https://opensource.com/sites/default/files/dt-gnuplot.png) +Image 3: Gnuplot screenshot. View larger image. + +The [Kawa][15] language has a library for creating and transforming [geometric picture values][16]. If you print such a picture value to a DomTerm terminal, the picture is converted to SVG and embedded in the output. + +![](https://opensource.com/sites/default/files/dt-kawa1.png) +Image 4: Computable geometry in Kawa. View larger image. + +**Rich text in output:** Help messages are more readable and look nicer with HTML styling. The lower pane of image 1 shows the ouput from `domterm help`. (The output is plaintext if not running under DomTerm.) Note the `PAUSED` message from the built-in pager. + +**Error messages can include clickable links:** DomTerm recognizes the syntax `filename:line:column:` and turns it into a link that opens the file and line in a configurable text editor. (This works for relative filenames if you use `PROMPT_COMMAND` or similar to track directories.) + +A compiler can detect that it is running under DomTerm and directly emit file links in an escape sequence. This is more robust than depending on DomTerm's pattern matching, as it handles spaces and other special characters, and it does not depend on directory tracking. In image 4, you can see error messages from the [Kawa compiler][15]. Hovering over the file position causes it to be underlined, and the `file:` URL shows in the `atom-domterm` message area (bottom of the window). (When not using `atom-domterm`, such messages are shown in an overlay box, as seen for the `PAUSED` message in image 1.) + +The action when clicking on a link is configurable. The default action for a `file:` link with a `#position` suffix is to open the file in a text editor. + +**Structured internal representation:** The following are all represented in the internal node structure: Commands, prompts, input lines, normal and error output, tabs, and preserving the structure if you "Save as HTML." The HTML file is compatible with XML, so you can use XML tools to search or transform the output. The command `domterm view-saved` opens a saved HTML file in a way that enables command folding (show/hide buttons are active) and reflow on window resize. + +**Built-in Lisp-style pretty-printing:** You can include pretty-printing directives (e.g., grouping) in the output such that line breaks are recalculated on window resize. See my article [Dynamic pretty-printing in DomTerm][17] for a deeper discussion. + +**Basic built-in line editing** with history (like `GNU readline`): This uses the browser's built-in editor, so it has great mouse and selection handling. You can switch between normal character-mode (most characters typed are sent directly to the process); or line-mode (regular characters are inserted while control characters cause editing actions, with Enter sending the edited line to the process). The default is automatic mode, where DomTerm switches between character-mode and line-mode depending on whether the PTY is in raw or canonical mode. + +**A built-in pager** (like a simplified `less`): Keyboard shortcuts will control scrolling. In "paging mode," the output pauses after each new screen (or single line, if you move forward line-by-line). The paging mode is unobtrusive and smart about user input, so you can (if you wish) run it without it interfering with interactive programs. + +### Multiplexing and sessions + +**Tabs and tiling:** Not only can you create multiple terminal tabs, you can also tile them. You can use either the mouse or a keyboard shortcut to move between panes and tabs as well as create new ones. They can be rearranged and resized with the mouse. This is implemented using the [GoldenLayout][18] JavaScript library. [Image 1][19] shows a window with two panes. The top one has two tabs, with one running [Midnight Commander][20]; the bottom pane shows `domterm help` output as HTML. However, on Atom we instead use its built-in draggable tiles and tabs; you can see this in image 2. + +**Detaching and reattaching to sessions:** DomTerm supports sessions arrangement, similar to `tmux` and GNU `screen`. You can even attach multiple windows or panes to the same session. This supports multi-user session sharing and remote connections. (For security, all sessions of the same server need to be able to read a Unix domain socket and a local file containing a random key. This restriction will be lifted when we have a good, safe remote-access story.) + +**The** **`domterm`** **command** is also like `tmux` or GNU `screen` in that has multiple options for controlling or starting a server that manages one or more sessions. The major difference is that, if it's not already running under DomTerm, the `domterm` command creates a new top-level window, rather than running in the existing terminal. + +The `domterm` command has a number of sub-commands, similar to `tmux` or `git`. Some sub-commands create windows or sessions. Others (such as "printing" an image) only work within an existing DomTerm session. + +The command `domterm browse` opens a window or pane for browsing a specified URL, such as when browsing documentation. + +### Getting and installing DomTerm + +DomTerm is available from its [GitHub repository][21]. Currently, there are no prebuilt packages, but there are [detailed instructions][22]. All prerequisites are available on Fedora 27, which makes it especially easy to build. + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/1/introduction-domterm-terminal-emulator + +作者:[Per Bothner][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/perbothner +[1]:http://domterm.org/ +[2]:https://electronjs.org/ +[3]:https://atom.io/ +[4]:https://en.wikipedia.org/wiki/XUL +[5]:/file/385346 +[6]:https://opensource.com/sites/default/files/images/dt-atom1.png (DomTerm terminal panes in Atom editor) +[7]:https://opensource.com/sites/default/files/images/dt-atom1.png +[8]:https://libwebsockets.org/ +[9]:http://invisible-island.net/vttest/ +[10]:http://domterm.org/Wire-byte-protocol.html +[11]:http://domterm.org/Shell-prompts.html +[12]:http://www.gnuplot.info/ +[13]:https://developer.mozilla.org/en-US/docs/Web/SVG +[14]:http://per.bothner.com/blog/2016/gnuplot-in-domterm/ +[15]:https://www.gnu.org/software/kawa/ +[16]:https://www.gnu.org/software/kawa/Composable-pictures.html +[17]:http://per.bothner.com/blog/2017/dynamic-prettyprinting/ +[18]:https://golden-layout.com/ +[19]:https://opensource.com/sites/default/files/u128651/domterm1.png +[20]:https://midnight-commander.org/ +[21]:https://github.com/PerBothner/DomTerm +[22]:http://domterm.org/Downloading-and-building.html diff --git a/sources/tech/20180130 Ansible- Making Things Happen.md b/sources/tech/20180130 Ansible- Making Things Happen.md new file mode 100644 index 0000000000..88210cd20c --- /dev/null +++ b/sources/tech/20180130 Ansible- Making Things Happen.md @@ -0,0 +1,174 @@ +Ansible: Making Things Happen +====== +In my [last article][1], I described how to configure your server and clients so you could connect to each client from the server. Ansible is a push-based automation tool, so the connection is initiated from your "server", which is usually just a workstation or a server you ssh in to from your workstation. In this article, I explain how modules work and how you can use Ansible in ad-hoc mode from the command line. + +Ansible is supposed to make your job easier, so the first thing you need to learn is how to do familiar tasks. For most sysadmins, that means some simple command-line work. Ansible has a few quirks when it comes to command-line utilities, but it's worth learning the nuances, because it makes for a powerful system. + +### Command Module + +This is the safest module to execute remote commands on the client machine. As with most Ansible modules, it requires Python to be installed on the client, but that's it. When Ansible executes commands using the Command Module, it does not process those commands through the user's shell. This means some variables like $HOME are not available. It also means stream functions (redirects, pipes) don't work. If you don't need to redirect output or to reference the user's home directory as a shell variable, the Command Module is what you want to use. To invoke the Command Module in ad-hoc mode, do something like this: + +``` + +ansible host_or_groupname -m command -a "whoami" + +``` + +Your output should show SUCCESS for each host referenced and then return the user name that the user used to log in. You'll notice that the user is not root, unless that's the user you used to connect to the client computer. + +If you want to see the elevated user, you'll add another argument to the ansible command. You can add -b in order to "become" the elevated user (or the sudo user). So, if you were to run the same command as above with a "-b" flag: + +``` + +ansible host_or_groupname -b -m command -a "whoami" + +``` + +you should see a similar result, but the whoami results should say root instead of the user you used to connect. That flag is important to use, especially if you try to run remote commands that require root access! + +### Shell Module + +There's nothing wrong with using the Shell Module to execute remote commands. It's just important to know that since it uses the remote user's environment, if there's something goofy with the user's account, it might cause problems that the Command Module avoids. If you use the Shell Module, however, you're able to use redirects and pipes. You can use the whoami example to see the difference. This command: + +``` + +ansible host_or_groupname -m command -a "whoami > myname.txt" + +``` + +should result in an error about > not being a valid argument. Since the Command Module doesn't run inside any shell, it interprets the greater-than character as something you're trying to pass to the whoami command. If you use the Shell Module, however, you have no problems: + +``` + +ansible host_or_groupname -m shell -a "whom > myname.txt" + +``` + +This should execute and give you a SUCCESS message for each host, but there should be nothing returned as output. On the remote machine, however, there should be a file called myname.txt in the user's home directory that contains the name of the user. My personal policy is to use the Command Module whenever possible and to use the Shell Module if needed. + +### The Raw Module + +Functionally, the Raw Module works like the Shell Module. The key difference is that Ansible doesn't do any error checking, and STDERR, STDOUT and Return Code is returned. Other than that, Ansible has no idea what happens, because it just executes the command over SSH directly. So while the Shell Module will use /bin/sh by default, the Raw Module just uses whatever the user's personal default shell might be. + +Why would a person decide to use the Raw Module? It doesn't require Python on the remote computer—at all. Although it's true that most servers have Python installed by default, or easily could have it installed, many embedded devices don't and can't have Python installed. For most configuration management tools, not having an agent program installed means the remote device can't be managed. With Ansible, if all you have is SSH, you still can execute remote commands using the Raw Module. I've used the Raw Module to manage Bitcoin miners that have a very minimal embedded environment. It's a powerful tool, and when you need it, it's invaluable! + +### Copy Module + +Although it's certainly possible to do file and folder manipulation with the Command and Shell Modules, Ansible includes a module specifically for copying files to the server. Even though it requires learning a new syntax for copying files, I like to use it because Ansible will check to see whether a file exists, and whether it's the same file. That means it copies the file only if it needs to, saving time and bandwidth. It even will make backups of existing files! I can't tell you how many times I've used scp and sshpass in a Bash FOR loop and dumped files on servers, even if they didn't need them. Ansible makes it easy and doesn't require FOR loops and IP iterations. + +The syntax is a little more complicated than with Command, Shell or Raw. Thankfully, as with most things in the Ansible world, it's easy to understand—for example: + +``` + +ansible host_or_groupname -b -m copy \ + -a "src=./updated.conf dest=/etc/ntp.conf \ + owner=root group=root mode=0644 backup=yes" + +``` + +This will look in the current directory (on the Ansible server/workstation) for a file called updated.conf and then copy it to each host. On the remote system, the file will be put in /etc/ntp.conf, and if a file already exists, and it's different, the original will be backed up with a date extension. If the files are the same, Ansible won't make any changes. + +I tend to use the Copy Module when updating configuration files. It would be perfect for updating configuration files on Bitcoin miners, but unfortunately, the Copy Module does require that the remote machine has Python installed. Nevertheless, it's a great way to update common files on many remote machines with one simple command. It's also important to note that the Copy Module supports copying remote files to other locations on the remote filesystem using the remote_src=true directive. + +### File Module + +The File Module has a lot in common with the Copy Module, but if you try to use the File Module to copy a file, it doesn't work as expected. The File Module does all its actions on the remote machine, so src and dest are all references to the remote filesystem. The File Module often is used for creating directories, creating links or deleting remote files and folders. The following will simply create a folder named /etc/newfolder on the remote servers and set the mode: + +``` + +ansible host_or_groupname -b -m file \ + -a "path=/etc/newfolder state=directory mode=0755" + +``` + +You can, of course, set the owner and group, along with a bunch of other options, which you can learn about on the Ansible doc site. I find I most often will either create a folder or symbolically link a file using the File Module. To create a symlink: + +``` + +sensible host_or_groupname -b -m file \ + -a "src=/etc/ntp.conf dest=/home/user/ntp.conf \ + owner=user group=user state=link" + +``` + +Notice that the state directive is how you inform Ansible what you actually want to do. There are several state options: + +* link — create symlink. + +* directory — create directory. + +* hard — create hardlink. + +* touch — create empty file. + +* absent — delete file or directory recursively. + +This might seem a bit complicated, especially when you easily could do the same with a Command or Shell Module command, but the clarity of using the appropriate module makes it more difficult to make mistakes. Plus, learning these commands in ad-hoc mode will make playbooks, which consist of many commands, easier to understand (I plan to cover this in my next article). + +### File Management + +Anyone who manages multiple distributions knows it can be tricky to handle the various package managers. Ansible handles this in a couple ways. There are specific modules for apt and yum, but there's also a generic module called "package" that will install on the remote computer regardless of whether it's Red Hat- or Debian/Ubuntu-based. + +Unfortunately, while Ansible usually can detect the type of package manager it needs to use, it doesn't have a way to fix packages with different names. One prime example is Apache. On Red Hat-based systems, the package is "httpd", but on Debian/Ubuntu systems, it's "apache2". That means some more complex things need to happen in order to install the correct package automatically. The individual modules, however, are very easy to use. I find myself just using apt or yum as appropriate, just like when I manually manage servers. Here's an apt example: + +``` + +ansible host_or_groupname -b -m apt \ + -a "update_cache=yes name=apache2 state=latest" + +``` + +With this one simple line, all the host machines will run apt-get update (that's the update_cache directive at work), then install apache2's latest version including any dependencies required. Much like the File Module, the state directive has a few options: + +* latest — get the latest version, upgrading existing if needed. + +* absent — remove package if installed. + +* present — make sure package is installed, but don't upgrade existing. + +The Yum Module works similarly to the Apt Module, but I generally don't bother with the update_cache directive, because yum updates automatically. Although very similar, installing Apache on a Red Hat-based system looks like this: + +``` + +ansible host_or_groupname -b -m yum \ + -a "name=httpd state=present" + +``` + +The difference with this example is that if Apache is already installed, it won't update, even if an update is available. Sometimes updating to the latest version isn't want you want, so this stops that from accidentally happening. + +### Just the Facts, Ma'am + +One frustrating thing about using Ansible in ad-hoc mode is that you don't have access to the "facts" about the remote systems. In my next article, where I plan to explore creating playbooks full of various tasks, you'll see how you can reference the facts Ansible learns about the systems. It makes Ansible far more powerful, but again, it can be utilized only in playbook mode. Nevertheless, it's possible to use ad-hoc mode to peek at the sorts information Ansible gathers. If you run the setup module, it will show you all the details from a remote system: + +``` + +ansible host_or_groupname -b -m setup + +``` + +That command will spew a ton of variables on your screen. You can scroll through them all to see the vast amount of information Ansible pulls from the host machines. In fact, it shows so much information, it can be overwhelming. You can filter the results: + +``` + +ansible host_or_groupname -b -m setup -a "filter=*family*" + +``` + +That should just return a single variable, ansible_os_family, which likely will be Debian or Red Hat. When you start building more complex Ansible setups with playbooks, it's possible to insert some logic and conditionals in order to use yum where appropriate and apt where the system is Debian-based. Really, the facts variables are incredibly useful and make building playbooks that much more exciting. + +But, that's for another article, because you've come to the end of the second installment. Your assignment for now is to get comfortable using Ansible in ad-hoc mode, doing one thing at a time. Most people think ad-hoc mode is just a stepping stone to more complex Ansible setups, but I disagree. The ability to configure hundreds of servers consistently and reliably with a single command is nothing to scoff at. I love making elaborate playbooks, but just as often, I'll use an ad-hoc command in a situation that used to require me to ssh in to a bunch of servers to do simple tasks. Have fun with Ansible; it just gets more interesting from here! + + +-------------------------------------------------------------------------------- + +via: http://www.linuxjournal.com/content/ansible-making-things-happen + +作者:[Shawn Powers][a] +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:http://www.linuxjournal.com/users/shawn-powers +[1]:http://www.linuxjournal.com/content/ansible-automation-framework-thinks-sysadmin diff --git a/sources/tech/20180130 Create and manage MacOS LaunchAgents using Go.md b/sources/tech/20180130 Create and manage MacOS LaunchAgents using Go.md new file mode 100644 index 0000000000..8bd6b8bf64 --- /dev/null +++ b/sources/tech/20180130 Create and manage MacOS LaunchAgents using Go.md @@ -0,0 +1,305 @@ +Create and manage MacOS LaunchAgents using Go +============================================================ + +If you have ever tried writing a daemon for MacOS you have met with `launchd`. For those that don’t have the experience, think of it as a framework for starting, stopping and managing daemons, applications, processes, and scripts. If you have any *nix experience the word daemon should not be too alien to you. + +For those unfamiliar, a daemon is a program running in the background without requiring user input. A typical daemon might, for instance, perform daily maintenance tasks or scan a device for malware when connected. + +This post is aimed at folks that know a little bit about what daemons are, what is the common way of using them and know a bit about Go. Also, if you have ever written a daemon for any other *nix system, you will have a good idea of what we are going to talk here. If you are an absolute beginner in Go or systems this might prove to be an overwhelming article. Still, feel free to give it a shot and let me know how it goes. + +If you ever find yourself wanting to write a MacOS daemon with Go you would like to know most of the stuff we are going to talk about in this article. Without further ado, let’s dive in. + +### What is `launchd` and how it works? + +`launchd` is a unified service-management framework, that starts, stops and manages daemons, applications, processes, and scripts in MacOS. + +One of its key features is that it differentiates between agents and daemons. In `launchd` land, an agent runs on behalf of the logged in user while a daemon runs on behalf of the root user or any specified user. + +### Defining agents and daemons + +An agent/daemon is defined in an XML file, which states the properties of the program that will execute, among a list of other properties. Another aspect to keep in mind is that `launchd` decides if a program will be treated as a daemon or an agent by where the program XML is located. + +Over at [launchd.info][3], there’s a simple table that shows where you would (or not) place your program’s XML: + +``` ++----------------+-------------------------------+----------------------------------------------------+| Type | Location | Run on behalf of |+----------------+-------------------------------+----------------------------------------------------+| User Agents | ~/Library/LaunchAgents | Currently logged in user || Global Agents | /Library/LaunchAgents | Currently logged in user || Global Daemons | /Library/LaunchDaemons | root or the user specified with the key 'UserName' || System Agents | /System/Library/LaunchAgents | Currently logged in user || System Daemons | /System/Library/LaunchDaemons | root or the user specified with the key 'UserName' |+----------------+-------------------------------+----------------------------------------------------+ +``` + +This means that when we set our XML file in, for example, the `/Library/LaunchAgents` path our process will be treated as a global agent. The main difference between the daemons and agents is that LaunchDaemons will run as root, and are generally background processes. On the other hand, LaunchAgents are jobs that will run as a user or in the context of userland. These may be scripts or other foreground items and they also have access to the MacOS UI (e.g. you can send notifications, control the windows, etc.) + +So, how do we define an agent? Let’s take a look at a simple XML file that `launchd`understands: + +``` + Label com.example.app Program /Users/Me/Scripts/cleanup.sh RunAtLoad +``` + +The XML is quite self-explanatory, unless it’s the first time you are seeing an XML file. The file has three main properties, with values. In fact, if you take a better look you will see the `dict` keyword which means `dictionary`. This actually means that the XML represents a key-value structure, so in Go it would look like: + +``` +map[string]string{ "Label": "com.example.app", "Program": "/Users/Me/Scripts/cleanup.sh", "RunAtLoad": "true",} +``` + +Let’s look at each of the keys: + +1. `Label` - The job definition or the name of the job. This is the unique identifier for the job within the `launchd` instance. Usually, the label (and hence the name) is written in [Reverse domain name notation][1]. + +2. `Program` - This key defines what the job should start, in our case a script with the path `/Users/Me/Scripts/cleanup.sh`. + +3. `RunAtLoad` - This key specifies when the job should be run, in this case right after it’s loaded. + +As you can see, the keys used in this XML file are quite self-explanatory. This is the case for the remaining 30-40 keys that `launchd` supports. Last but not least these files although have an XML syntax, in fact, they have a `.plist` extension (which means `Property List`). Makes a lot of sense, right? + +### `launchd` v.s. `launchctl` + +Before we continue with our little exercise of creating daemons/agents with Go, let’s first see how `launchd` allows us to control these jobs. While `launchd`’s job is to boot the system and to load and maintain services, there is a different command used for jobs management - `launchctl`. With `launchd` facilitating jobs, the control of services is centralized in the `launchctl` command. + +`launchctl` has a long list of subcommands that we can use. For example, loading or unloading a job is done via: + +``` +launchctl unload/load ~/Library/LaunchAgents/com.example.app.plist +``` + +Or, starting/stopping a job is done via: + +``` +launchctl start/stop ~/Library/LaunchAgents/com.example.app.plist +``` + +To get any confusion out of the way, `load` and `start` are different. While `start`only starts the agent/daemon, `load` loads the job and it might also start it if the job is configured to run on load. This is achieved by setting the `RunAtLoad` property in the property list XML of the job: + +``` + Label com.example.app Program /Users/Me/Scripts/cleanup.sh RunAtLoad +``` + +If you would like to see what other commands `launchctl` supports, you can run`man launchctl` in your terminal and see the options in detail. + +### Automating with Go + +After getting the basics of `launchd` and `launctl` out of the way, why don’t we see how we can add an agent to any Go package? For our example, we are going to write a simple way of plugging in a `launchd` agent for any of your Go packages. + +As we already established before, `launchd` speaks in XML. Or, rather, it understands XML files, called  _property lists_  (or `.plist`). This means, for our Go package to have an agent running on MacOS, it will need to tell `launchd` “hey, `launchd`, run this thing!”. And since `launch` speaks only in `.plist`, that means our package needs to be capable of generating XML files. + +### Templates in Go + +While one could have a hardcoded `.plist` file in their project and copy it across to the `~/Library/LaunchAgents` path, a more programmatical way to do this would be to use a template to generate these XML files. The good thing is Go’s standard library has us covered - the `text/template` package ([docs][4]) does exactly what we need. + +In a nutshell, `text/template` implements data-driven templates for generating textual output. Or in other words, you give it a template and a data structure, it will mash them up together and produce a nice and clean text file. Perfect. + +Let’s say the `.plist` we need to generate in our case is the following: + +``` + LabelTicker Program/usr/local/bin/ticker StandardOutPath/tmp/ticker.out.log StandardErrorPath/tmp/ticker.err.log KeepAlive RunAtLoad +``` + +We want to keep it quite simple in our little exercise. It will contain only six properties: `Label`, `Program`, `StandardOutPath`, `StandardErrorPath`, `KeepAlive` and `RunAtLoad`. To generate such a XML, its template would look something like this: + +``` + + + + + Label{{.Label}} + Program{{.Program}} + StandardOutPath/tmp/{{.Label}}.out.log + StandardErrorPath/tmp/{{.Label}}.err.log + KeepAlive<{{.KeepAlive}}/> + RunAtLoad<{{.RunAtLoad}}/> + + + +``` + +As you can see, the difference between the two XMLs is that the second one has the double curly braces with expressions in them in places where the first XML has some sort of a value. These are called “actions”, which can be data evaluations or control structures and are delimited by “ and “. Any of the text outside actions is copied to the output untouched. + +### Injecting your data + +Now that we have our template with its glorious XML and curly braces (or actions), let’s see how we can inject our data into it. Since things are generally simple in Go, especially when it comes to its standard library, you should not worry - this will be easy! + +To keep thing simple, we will store the whole XML template in a plain old string. Yes, weird, I know. The best way would be to store it in a file and read it from there, or embed it in the binary itself, but in our little example let’s keep it simple: + +``` +// template.go +package main + +func Template() string { + return ` + + + + + Label{{.Label}} + Program{{.Program}} + StandardOutPath/tmp/{{.Label}}.out.log + StandardErrorPath/tmp/{{.Label}}.err.log + KeepAlive<{{.KeepAlive}}/> + RunAtLoad<{{.RunAtLoad}}/> + + +` +} + +``` + +And the program that will use our little template function: + +``` +// main.gopackage mainimport ( "log" "os" "text/template")func main() { data := struct { Label string Program string KeepAlive bool RunAtLoad bool }{ Label: "ticker", Program: "/usr/local/bin/ticker", KeepAlive: true, RunAtLoad: true, } t := template.Must(template.New("launchdConfig").Parse(Template())) err := t.Execute(os.Stdout, data) if err != nil { log.Fatalf("Template generation failed: %s", err) }} +``` + +So, what happens there, in the `main` function? It’s actually quite simple: + +1. We declare a small `struct`, which has only the properties that will be needed in the template, and we immediately initialize it with the values for our program. + +2. We build a new template, using the `template.New` function, with the name`launchdConfig`. Then, we invoke the `Parse` function on it, which takes the XML template as an argument. + +3. We invoke the `template.Must` function, which takes our built template as argument. From the documentation, `template.Must` is a helper that wraps a call to a function returning `(*Template, error)` and panics if the error is non-`nil`. Actually, `template.Must` is built to, in a way, validate if the template can be understood by the `text/template` package. + +4. Finally, we invoke `Execute` on our built template, which takes a data structure and applies its attributes to the actions in the template. Then it sends the output to `os.Stdout`, which does the trick for our example. Of course, the output can be sent to any struct that implements the `io.Writer` interface, like a file (`os.File`). + +### Make and load my `.plist` + +Instead of sending all this nice XML to standard out, let’s throw in an open file descriptor to the `Execute` function and finally save our `.plist` file in`~/Library/LaunchAgents`. There are a couple of main points we need to change. + +First, getting the location of the binary. Since it’s a Go binary, and we will install it via `go install`, we can assume that the path will be at `$GOPATH/bin`. Second, since we don’t know the actual `$HOME` of the current user, we will have to get it through the environment. Both of these can be done via `os.Getenv` ([docs][5]) which takes a variable name and returns its value. + +``` +// main.gopackage mainimport ( "log" "os" "text/template")func main() { data := struct { Label string Program string KeepAlive bool RunAtLoad bool }{ Label: "com.ieftimov.ticker", // Reverse-DNS naming convention Program: fmt.Sprintf("%s/bin/ticker", os.Getenv("GOPATH")), KeepAlive: true, RunAtLoad: true, } plistPath := fmt.Sprintf("%s/Library/LaunchAgents/%s.plist", os.Getenv("HOME"), data.Label) f, err := os.Open(plistPath) t := template.Must(template.New("launchdConfig").Parse(Template())) err := t.Execute(f, data) if err != nil { log.Fatalf("Template generation failed: %s", err) }} +``` + +That’s about it. The first part, about setting the correct `Program` property, is done by concatenating the name of the program and `$GOPATH`: + +``` +fmt.Sprintf("%s/bin/ticker", os.Getenv("GOPATH"))// Output: /Users//go/bin/ticker +``` + +The second part is slightly more complex, and it’s done by concatenating three strings, the `$HOME` environment variable, the `Label` property of the program and the `/Library/LaunchAgents` string: + +``` +fmt.Sprintf("%s/Library/LaunchAgents/%s.plist", os.Getenv("HOME"), data.Label)// Output: /Users//Library/LaunchAgents/com.ieftimov.ticker.plist +``` + +By having these two paths, opening the file and writing to it is very trivial - we open the file via `os.Open` and we pass in the `os.File` structure to `t.Execute` which writes to the file descriptor. + +### What about the Launch Agent? + +We will keep this one simple as well. Let’s throw in a command to our package, make it installable via `go install` (not that there’s much to it) and make it runnable by our `.plist` file: + +``` +// cmd/ticker/main.gopackage tickerimport ( "time" "fmt")func main() { for range time.Tick(30 * time.Second) { fmt.Println("tick!") }} +``` + +This the `ticker` program will use `time.Tick`, to execute an action every 30 seconds. Since this will be an infinite loop, `launchd` will kick off the program on boot (because `RunAtLoad` is set to `true` in the `.plist` file) and will keep it running. But, to make the program controllable from the operating system, we need to make the program react to some OS signals, like `SIGINT` or `SIGTERM`. + +### Understanding and handling OS signals + +While there’s quite a bit to be learned about OS signals, in our example we will scratch a bit off the surface. (If you know a lot about inter-process communication this might be too much of an oversimplification to you - and I apologize up front. Feel free to drop some links on the topic in the comments so others can learn more!) + +The best way to think about a signal is that it’s a message from the operating system or another process, to a process. It is an asynchronous notification sent to a process or to a specific thread within the same process to notify it of an event that occurred. + +There are quite a bit of various signals that can be sent to a process (or a thread), like `SIGKILL` (which kills a process), `SIGSTOP` (stop), `SIGTERM` (termination), `SIGILL`and so on and so forth. There’s an exhaustive list of signal types on [Wikipedia’s page][6]on signals. + +To get back to `launchd`, if we look at its documentation about stopping a job we will notice the following: + +> Stopping a job will send the signal `SIGTERM` to the process. Should this not stop the process launchd will wait `ExitTimeOut` seconds (20 seconds by default) before sending `SIGKILL`. + +Pretty self-explanatory, right? We need to handle one signal - `SIGTERM`. Why not `SIGKILL`? Because `SIGKILL` is a special signal that cannot be caught - it kills the process without any chance for a graceful shutdown, no questions asked. That’s why there’s a termination signal and a “kill” signal. + +Let’s throw in a bit of signal handling in our code, so our program knows that it needs to exit when it gets told to do so: + +``` +package mainimport ( "fmt" "os" "os/signal" "syscall" "time")func main() { sigs := make(chan os.Signal, 1) signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM) go func() { <-sigs os.Exit(0) }() for range time.Tick(30 * time.Second) { fmt.Println("tick!") }} +``` + +In the new version, the agent program has two new packages imported: `os/signal`and `syscall`. `os/signal` implements access to incoming signals, that are primarily used on Unix-like systems. Since in this article we are specifically interested in MacOS, this is exactly what we need. + +Package `syscall` contains an interface to the low-level operating system primitives. An important note about `syscall` is that it is locked down since Go v1.4\. This means that any code outside of the standard library that uses the `syscall` package should be migrated to use the new `golang.org/x/sys` [package][7]. Since we are using **only**the signals constants of `syscall` we can get away with this. + +(If you want to read more about the package lockdown, you can see [the rationale on locking it down][8] by the Go team and the new [golang.org/s/sys][9] package.) + +Having the basics of the packages out of the way, let’s go step by step through the new lines of code added: + +1. We make a buffered channel of type `os.Signal`, with a size of `1`. `os.Signal`is a type that represents an operating system signal. + +2. We call `signal.Notify` with the new channel as an argument, plus`syscall.SIGINT` and `syscall.SIGTERM`. This function states “when the OS sends a `SIGINT` or a `SIGTERM` signal to this program, send the signal to the channel”. This allows us to somehow handle the sent OS signal. + +3. The new goroutine that we spawn waits for any of the signals to arrive through the channel. Since we know that any of the signals that will arrive are about shutting down the program, after receiving any signal we use `os.Exit(0)`([docs][2]) to gracefully stop the program. One caveat here is that if we had any `defer`red calls they would not be run. + +Now `launchd` can run the agent program and we can `load` and `unload`, `start`and `stop` it using `launchctl`. + +### Putting it all together + +Now that we have all the pieces ready, we need to put them together to a good use. Our application will consist of two binaries - a CLI tool and an agent (daemon). Both of the programs will be stored in separate subdirectories of the `cmd` directory. + +The CLI tool: + +``` +// cmd/cli/main.gopackage mainimport ( "log" "os" "text/template")func main() { data := struct { Label string Program string KeepAlive bool RunAtLoad bool }{ Label: "com.ieftimov.ticker", // Reverse-DNS naming convention Program: fmt.Sprintf("%s/bin/ticker", os.Getenv("GOPATH")), KeepAlive: true, RunAtLoad: true, } plistPath := fmt.Sprintf("%s/Library/LaunchAgents/%s.plist", os.Getenv("HOME"), data.Label) f, err := os.Open(plistPath) t := template.Must(template.New("launchdConfig").Parse(Template())) err := t.Execute(f, data) if err != nil { log.Fatalf("Template generation failed: %s", err) }} +``` + +And the ticker program: + +``` +// cmd/ticker/main.gopackage mainimport ( "fmt" "os" "os/signal" "syscall" "time")func main() { sigs := make(chan os.Signal, 1) signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM) go func() { <-sigs os.Exit(0) }() for range time.Tick(30 * time.Second) { fmt.Println("tick!") }} +``` + +To install them both, we need to run `go install ./...` in the project root. The command will install all the sub-packages that are located within the project. This will leave us with two available binaries, installed in the `$GOPATH/bin` path. + +To install our launch agent, we need to run only the CLI tool, via the `cli` command. This will generate the `.plist` file and place it in the `~/Library/LaunchAgents`path. We don’t need to touch the `ticker` binary - that one will be managed by `launchd`. + +To load the newly created `.plist` file, we need to run: + +``` +launchctl load ~/Library/LaunchAgents/com.ieftimov.ticker.plist +``` + +When we run it, we will not see anything immediately, but after 30 seconds the ticker will add a `tick!` line in `/tmp/ticker.out.log`. We can `tail` the file to see the new lines being added. If we want to unload the agent, we can use: + +``` +launchctl unload ~/Library/LaunchAgents/com.ieftimov.ticker.plist +``` + +This will unload the launch agent and will stop the ticker from running. Remember the signal handling we added? This is the case where it’s being used! Also, we could have automated the (un)loading of the file via the CLI tool but for simplicity, we left it out. You can try to improve the CLI tool by making it a bit smarter with subcommands and flags, as a follow-up exercise from this tutorial. + +Finally, if you decide to completely delete the launch agent, you can remove the`.plist` file: + +``` +rm ~/Library/LaunchAgents/com.ieftimov.ticker.plist +``` + +### In closing + +As part of this (quite long!) article, we saw how we can work with `launchd` and Golang. We took a detour, like learning about `launchd` and `launchctl`, generating XML files using the `text/template` package, we took a look at OS signals and how we can gracefully shutdown a Go program by handling the `SIGINT` and `SIGTERM`signals. There was quite a bit to learn and see, but we got to the end. + +Of course, we only scratched the surface with this article. For example, `launchd` is quite an interesting tool. You can use it also like `crontab` because it allows running programs at explicit time/date combinations or on specific days. Or, for example, the XML template can be embedded in the program binary using tools like [`go-bindata`][10], instead of hardcoding it in a function. Also, you explore more about signals, how they work and how Go implements these low-level primitives so you can use them with ease in your programs. The options are plenty, feel free to explore! + +If you have found any mistakes in the article, feel free to drop a comment below - I will appreciate it a ton. I find learning through teaching (blogging) a very pleasant experience and would like to have all the details fully correct in my posts. + +-------------------------------------------------------------------------------- + +作者简介: + +Backend engineer, interested in Ruby, Go, microservices, building resilient architectures and solving challenges at scale. I coach at Rails Girls in Amsterdam, maintain a list of small gems and often contribute to Open Source. +This is where I write about software development, programming languages and everything else that interests me. + +--------------------- + + +via: https://ieftimov.com/create-manage-macos-launchd-agents-golang + +作者:[Ilija Eftimov ][a] +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://ieftimov.com/about +[1]:https://ieftimov.com/en.wikipedia.org/wiki/Reverse_domain_name_notation +[2]:https://godoc.org/os#Exit +[3]:https://launchd.info/ +[4]:https://godoc.org/text/template +[5]:https://godoc.org/os#Getenv +[6]:https://en.wikipedia.org/wiki/Signal_(IPC) +[7]:https://golang.org/x/sys +[8]:https://docs.google.com/document/d/1QXzI9I1pOfZPujQzxhyRy6EeHYTQitKKjHfpq0zpxZs/edit +[9]:https://golang.org/x/sys +[10]:https://github.com/jteeuwen/go-bindata \ No newline at end of file diff --git a/sources/tech/20180130 Graphics and music tools for game development.md b/sources/tech/20180130 Graphics and music tools for game development.md new file mode 100644 index 0000000000..7414e89704 --- /dev/null +++ b/sources/tech/20180130 Graphics and music tools for game development.md @@ -0,0 +1,179 @@ +Graphics and music tools for game development +====== + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/OSDC_Life_opengame.png?itok=JPxruL3k) + +In early October, our club, [Geeks and Gadgets][1] from Marshall University, participated in the inaugural [Open Jam][2], a game jam that celebrated the best of open source tools. Game jams are events where participants work as teams to develop computer games for fun. Jams tend to be very short--only three days long--and very exhausting. Opensource.com [announced][3] Open Jam in late August, and more than [three dozen games][4] were entered into the competition. + +Our club likes to create and use open source software in our projects, so Open Jam was naturally the jam we wanted to participate in. Our submission was an experimental game called [Mark My Words][5]. We used a variety of free and open source (FOSS) tools to develop it; in this article we'll discuss some of the tools we used and potential stumbling blocks to be aware of. + +### Audio tools + +#### MilkyTracker + +[MilkyTracker][6] is one of the best software packages available for composing old-style video game music. It is an example of a [music tracker][7], a powerful MOD and XM file creator with a characteristic grid-based pattern editor. We used it to compose most of the musical pieces in our game. One of the great things about this program is that it consumed much less disk space and RAM than most of our other tools. Even so, MilkyTracker is still extremely powerful. + +![](https://opensource.com/sites/default/files/u128651/mtracker.png) + +The user interface took a while to get used to, so here are some pointers for any musician who wants to try out MilkyTracker: + + * Go to Config > Misc. and set the edit mode control style to "MilkyTracker." This will give you modern keyboard shortcuts for almost everything + * Undo with Ctrl+Z + * Redo with Ctrl+Y + * Toggle pattern-edit mode with the Spacebar + * Delete the previous note with the Backspace key + * Insert a row with the Insert key + * By default, a note will continue playing until it is replaced on that channel. You can end a note explicitly by inserting a KeyOff note with the backquote (`) key + * You will have to create or find samples before you can start composing. We recommend finding [Creative Commons][8] licensed samples at websites such as [Freesound][9] or [ccMixter][10] + + + +In addition, keep the [MilkyTracker documentation page][11] handy. It contains links to numerous tutorials and manuals. A good starting point is the [MilkyTracker Guide][12] on the project's wiki. + +#### LMMS + +Two of our musicians used the versatile and modern music creation tool [LMMS][13]. It comes with a library of cool samples and effects, plus a variety of flexible plugins for generating unique sounds. The learning curve for LMMS was surprisingly low, in part due to the nice beat/bassline editor. + +![](https://opensource.com/sites/default/files/u128651/lmms_plugins.png) + +We have one suggestion for musicians trying out LMMS: Use the plugins. For [chiptune][14]-style music, we recommend [sfxr][15], [BitInvader][16], and [FreeBoy][17]. For other styles, [ZynAddSubFX][18] is a good choice. It comes with a wide range of synthesized instruments that can be altered however you see fit. + +### Graphics tools + +#### Tiled + +[Tiled][19] is a popular tilemap editor in open source game development. We used it to assemble consistent, retro-looking backgrounds for our in-game scenes. + +![](https://opensource.com/sites/default/files/u128651/tiled.png) + +Tiled can export maps as XML, JSON, or as flattened images. It is stable and cross-platform. + +One of Tiled's features, which we did not use during the jam, allows you to define and place arbitrary game objects, such as coins and powerups, onto the map. All you have to do is load the object's graphics as a tileset, then place them using Insert Tile. + +Overall, Tiled is a stellar piece of software that we recommend for any project that needs a map editor. + +#### Piskel + +[Piskel][20] is a pixel art editor whose source code is licensed under the [Apache License, Version 2.0][21]. We used Piskel for almost all our graphical assets during the jam, and we will certainly be using it in future projects as well. + +Two features of Piskel that helped us immensely during the jam are onion skin and spritesheet exporting. + +##### Onion skin + +The onion skin feature will make Piskel show a ghostly overlay of the previous and next frames of your animation as you edit, like this: + +![](https://opensource.com/sites/default/files/u128651/onionshow.gif) + +Onion skin is handy because it serves as a drawing guide and helps you maintain consistent shapes and volumes on your characters throughout the animation process. To enable it, just click the onion-shaped icon underneath the preview window on the top-right of the screen. + +![](https://opensource.com/sites/default/files/u128651/onionenable.png) + +##### Spritesheet exporting + +Piskel's ability to export animations as a spritesheet was also very helpful. A spritesheet is a single raster image that contains all the frames of an animation. For example, here is a spritesheet we exported from Piskel: + +![](https://opensource.com/sites/default/files/u128651/sprite-artist.png) + +The spritesheet consists of two frames. One frame is in the top half of the image and the other frame is in the bottom half of the image. Spritesheets greatly simplify a game's code by enabling an entire animation to be loaded from a single file. Here is an animated version of the above spritesheet: + +![](https://opensource.com/sites/default/files/u128651/sprite-artist-anim.gif) + +##### Unpiskel.py + +There were several times during the jam when we wanted to batch convert Piskel files into PNGs. Since the Piskel file format is based on JSON, we wrote a small GPLv3-licensed Python script called [unpiskel.py][22] to do the conversion. + +It is invoked like this: +``` + + +python unpiskel.py input.piskel +``` + +The script will extract the PNG data frames and layers from a Piskel file (here `input.piskel`) and store them in their own files. The files follow the pattern `NAME_XX_YY.png` where `NAME` is the truncated name of the Piskel file, `XX` is the frame number, and `YY` is the layer number. + +Because the script can be invoked from a shell, it can be used on a whole list of files. +``` +for f in *.piskel; do python unpiskel.py "$f"; done +``` + +### Python, Pygame, and cx_Freeze + +#### Python and Pygame + +We used the [Python][23] language to make our game. It is a scripting language that is commonly used for text processing and desktop app development. It can also be used for game development, as projects like [Angry Drunken Dwarves][24] and [Ren'Py][25] have shown. Both of these projects use a Python library called [Pygame][26] to display graphics and produce sound, so we decided to use this library in Open Jam, too. + +Pygame turned out to be both stable and featureful, and it was great for the arcade-style game we were creating. The library's speed was fast enough at low resolutions, but its CPU-only rendering starts to slow down at higher resolutions. This is because Pygame does not use hardware-accelerated rendering. However, the infrastructure is there for developers to take full advantage of OpenGL. + +If you're looking for a good 2D game programming library, Pygame is one to keep your eye on. Its website has [a good tutorial][27] to get started. Be sure to check it out! + +#### cx_Freeze + +Prepping our game for distribution was interesting. We knew that Windows users were unlikely to have a Python installation, and asking them to install it would have been too much. On top of that, they would have had to also install Pygame, which is not an intuitive task on Windows. + +One thing was clear: We had to put our game into a more convenient form. Many of the other Open Jam participants used the proprietary game engine Unity, which enabled their games to be played in the web browser. This made them extremely convenient to play. Convenience was one thing our game didn't have even a sliver of. But, thanks to a vibrant Python ecosystem, we had options. Tools exist to help Python programmers prepare their programs for distribution on Windows. The two that we considered were [cx_Freeze][28] and [Pygame2exe][29] (which uses [py2exe][30]). We decided on cx_Freeze because it was cross-platform. + +In cx_Freeze, you can pack a single-script game for distribution just by running a command like this in the shell: +``` +cxfreeze main.py --target-dir dist +``` + +This invocation of `cxfreeze` will take your script (here `main.py`) and the Python interpreter on your system and bundle them up into the `dist` directory. Once this is done, all you have to do is manually copy your game's data files into the `dist` directory. You will find that the `dist` directory contains an executable file that can be run to start your game. + +There is a more involved way to use cx_Freeze that allows you to automate the copying of data files, but we found the straightforward invocation of `cxfreeze` to be good enough for our needs. Thanks to this tool, we made our game a little more convenient to play. + +### Celebrating open source + +Open Jam is important because it celebrates the open source model of software development. This is an opportunity to analyze the current state of open source tools and what we need to work on in the future. Game jams are perhaps the best time for game devs to try to push their tools to the limit, to learn what must be improved for the good of future game devs. + +Open source tools enable people to explore their creativity without compromising their freedom and without investing money upfront. Although we might not become professional game developers, we were still able to get a small taste of it with our short, experimental game called [Mark My Words][5]. It is a linguistically themed game that depicts the evolution of a fictional writing system throughout its history. There were many other delightful submissions to Open Jam, and they are all worth checking out. Really, [go look][31]! + +Before closing, we would like to thank all the [club members who participated][32] and made this experience truly worthwhile. We would also like to thank [Michael Clayton][33], [Jared Sprague][34], and [Opensource.com][35] for hosting Open Jam. It was a blast. + +Now, we have some questions for readers. Are you a FOSS game developer? What are your tools of choice? Be sure to leave a comment below! + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/1/graphics-music-tools-game-dev + +作者:[Charlie Murphy][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/rsg167 +[1]:http://mugeeks.org/ +[2]:https://itch.io/jam/open-jam-1 +[3]:https://opensource.com/article/17/8/open-jam-announcement +[4]:https://opensource.com/article/17/11/open-jam +[5]:https://mugeeksalpha.itch.io/mark-omy-words +[6]:http://milkytracker.titandemo.org/ +[7]:https://en.wikipedia.org/wiki/Music_tracker +[8]:https://creativecommons.org/ +[9]:https://freesound.org/ +[10]:http://ccmixter.org/view/media/home +[11]:http://milkytracker.titandemo.org/documentation/ +[12]:https://github.com/milkytracker/MilkyTracker/wiki/MilkyTracker-Guide +[13]:https://lmms.io/ +[14]:https://en.wikipedia.org/wiki/Chiptune +[15]:https://github.com/grimfang4/sfxr +[16]:https://lmms.io/wiki/index.php?title=BitInvader +[17]:https://lmms.io/wiki/index.php?title=FreeBoy +[18]:http://zynaddsubfx.sourceforge.net/ +[19]:http://www.mapeditor.org/ +[20]:https://www.piskelapp.com/ +[21]:https://github.com/piskelapp/piskel/blob/master/LICENSE +[22]:https://raw.githubusercontent.com/MUGeeksandGadgets/MarkMyWords/master/tools/unpiskel.py +[23]:https://www.python.org/ +[24]:https://www.sacredchao.net/~piman/angrydd/ +[25]:https://renpy.org/ +[26]:https://www.Pygame.org/ +[27]:http://Pygame.org/docs/tut/PygameIntro.html +[28]:https://anthony-tuininga.github.io/cx_Freeze/ +[29]:https://Pygame.org/wiki/Pygame2exe +[30]:http://www.py2exe.org/ +[31]:https://itch.io/jam/open-jam-1/entries +[32]:https://github.com/MUGeeksandGadgets/MarkMyWords/blob/3e1e8aed12ebe13acccf0d87b06d4f3bd124b9db/README.md#credits +[33]:https://twitter.com/mwcz +[34]:https://twitter.com/caramelcode +[35]:https://opensource.com/ diff --git a/sources/tech/20180130 Install AWFFull web server log analysis application on ubuntu 17.10.md b/sources/tech/20180130 Install AWFFull web server log analysis application on ubuntu 17.10.md new file mode 100644 index 0000000000..03e15878b9 --- /dev/null +++ b/sources/tech/20180130 Install AWFFull web server log analysis application on ubuntu 17.10.md @@ -0,0 +1,95 @@ +Install AWFFull web server log analysis application on ubuntu 17.10 +====== + + +AWFFull is a web server log analysis program based on "The Webalizer".AWFFull produces usage statistics in HTML format for viewing with a browser. The results are presented in both columnar and graphical format, which facilitates interpretation. Yearly, monthly, daily and hourly usage statistics are presented, along with the ability to display usage by site, URL, referrer, user agent (browser), user name,search strings, entry/exit pages, and country (some information may not be available if not present in the log file being processed). + + + +AWFFull supports CLF (common log format) log files, as well as Combined log formats as defined by NCSA and others, and variations of these which it attempts to handle intelligently. In addition, AWFFull also supports wu-ftpd xferlog formatted log files, allowing analysis of ftp servers, and squid proxy logs. Logs may also be compressed, via gzip. + +AWFFull is a web server log analysis program based on "The Webalizer".AWFFull produces usage statistics in HTML format for viewing with a browser. The results are presented in both columnar and graphical format, which facilitates interpretation. Yearly, monthly, daily and hourly usage statistics are presented, along with the ability to display usage by site, URL, referrer, user agent (browser), user name,search strings, entry/exit pages, and country (some information may not be available if not present in the log file being processed).AWFFull supports CLF (common log format) log files, as well as Combined log formats as defined by NCSA and others, and variations of these which it attempts to handle intelligently. In addition, AWFFull also supports wu-ftpd xferlog formatted log files, allowing analysis of ftp servers, and squid proxy logs. Logs may also be compressed, via gzip. + +If a compressed log file is detected, it will be automatically uncompressed while it is read. Compressed logs must have the standard gzip extension of .gz. + +### Changes from Webalizer + +AWFFull is based on the Webalizer code and has a number of large and small changes. These include: + +o Beyond the raw statistics: Making use of published formulae to provide additional insights into site usage. + +o GeoIP IP Address look-ups for more accurate country detection. + +o Resizable graphs. + +o Integration with GNU gettext allowing for ease of translations.Currently 32 languages are supported. + +o Display more than 12 months of the site history on the front page. + +o Additional page count tracking and sort by same. + +o Some minor visual tweaks, including Geolizer's use of Kb, Mb etc for Volumes. + +o Additional Pie Charts for URL counts, Entry and Exit Pages, and Sites. + +o Horizontal lines on graphs that are more sensible and easier to read. + +o User Agent and Referral tracking is now calculated via PAGES not HITS. + +o GNU style long command line options are now supported (eg --help). + +o Can choose what is a page by excluding "what isn't" vs the original "what is" method. + +o Requests to the site being analysed are displayed with the matching referring URL. + +o A Table of 404 Errors, and the referring URL can be generated. + +o An external CSS file can be used with the generated html. + +o Manual performance optimisation of the config file is now easier with a post analysis summary output. + +o Specified IP's & Addresses can be assigned to a given country. + +o Additional Dump options for detailed analysis with other tools. + +o Lotus Domino v6 logs are now detected and processed. + +**Install awffull on ubuntu 17.10** + +> sudo apt-get install awffull + +### Configuring AWFFULL + +You have to edit awffull config file at /etc/awffull/awffull.conf. If you have multiple virtual websites running in the same machine, you can make several copies of the default config file. + +> sudo vi /etc/awffull/awffull.conf + +Make sure the following lines are there + +> LogFile /var/log/apache2/access.log.1 +> OutputDir /var/www/html/awffull + +Save and exit the file + +You can run the awffull config using the following command + +> awffull -c [your config file name] + +This will create all the required files under /var/www/html/awffull directory so you can access your webserver stats using http://serverip/awffull/ + +You should see similar to the following screen + +If you have more site and you can automate the process using shell script and cron job. + + +-------------------------------------------------------------------------------- + +via: http://www.ubuntugeek.com/install-awffull-web-server-log-analysis-application-on-ubuntu-17-10.html + +作者:[ruchi][a] +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:http://www.ubuntugeek.com/author/ubuntufix diff --git a/sources/tech/20180130 Introduction to AWS for Data Scientists.md b/sources/tech/20180130 Introduction to AWS for Data Scientists.md new file mode 100644 index 0000000000..ada3585745 --- /dev/null +++ b/sources/tech/20180130 Introduction to AWS for Data Scientists.md @@ -0,0 +1,212 @@ +Introduction to AWS for Data Scientists +====== +![sky-690293_1920][1] + +These days, many businesses use cloud based services; as a result various companies have started building and providing such services. Amazon [began the trend][2], with Amazon Web Services (AWS). While AWS began in 2006 as a side business, it now makes [$14.5 billion in revenue each year][3]. + +Other leaders in this area include: + + * Google--Google Cloud Platform (GCP) + * Microsoft--Azure Cloud Services + * IBM--IBM Cloud + + + +Cloud services are useful to businesses of all sizes--small companies benefit from the low cost, as compared to buying servers. Larger companies gain reliability and productivity, with less cost, since the services run on optimum energy and maintenance. + +These services are also powerful tools that you can use to ease your work. Setting up a Hadoop cluster to work with Spark manually could take days if it's your first time, but AWS sets that up for you in minutes. + +We are going to focus on AWS here because it comes with more products relevant to data scientists. In general, we can say familiarity with AWS helps data scientists to: + + 1. Prepare the infrastructure they need for their work (e.g. Hadoop clusters) with ease + 2. Easily set up necessary tools (e.g. Spark) + 3. Decrease expenses significantly--such as by paying for huge Hadoop clusters only when needed + 4. Spend less time on maintenance, as there's no need for tasks like manually backing up data + 5. Develop products and features that are ready to launch without needing help from engineers (or, at least, needing very little help) + + + +In this post, I'll give an overview of useful AWS services for data scientists -- what they are, why they're useful, and how much they cost. + +### Elastic Compute Cloud (EC2) + +Many other AWS services are built around EC2, making it a core piece of AWS. EC2s are in fact (virtual) servers that you can rent from Amazon and set up or run any program/application on it. These servers come in different operating systems and Amazon charges you based on the computing power and capacity of the server (i.e. Hard Drive capacity, CPU, Memory, etc.) and the duration the server been up. + +#### EC2 benefits + +For example, you can rent a Linux or Windows server with computation power and storage capacity that fits your specific needs and Amazon charges you based on these specifications and the duration you use the server. Note that previously AWS charged at least for one hour for each instance you run, but they recently changed their policy to [per-second billing][4]. + +One of the good things about EC2 is its scalability--by changing memory, number of vCPUs, bandwidth, and so on, you can easily scale your system up or down. Therefore, if you think a system doesn't have enough power for running a specific task or a calculation in your project is taking too long, you can scale up to finish your work and later scale down again to reduce the cost. EC2 is also very reliable, since Amazon takes care of the maintenance. + +#### EC2 cost + +EC2 instances are relatively low-cost, and there are different types of instances for different use cases. For example, there are instances that are optimized for computation and those have relatively lower cost on CPU usage. Or those optimized for memory have lower cost on memory usage. + +To give you an idea on EC2 cost, a general purpose medium instance with 2 vCPUs and 4 GIG of memory (at the time of writing this article) costs $0.0464 per hour for a linux server, see [Amazon EC2 Pricing][5] for prices and more information. AWS also now has [spot instance pricing][6], which calculates the price based on supply/demand at the time and provides up to a 90% discount for short term usages depending on the time you want to use the instance. For example, the same instance above costs $0.0173 per hour on spot pricing plan. + +Note that you have to add storage costs to the above as well. Most EC2 instances use Elastic Block Store (EBS) systems, which cost around $0.1/GIG/month; see the prices [here][7]. [Storage optimized instances][8] use Solid State Drive (SSD) systems, which are more expensive. + +![Ec2cost][9] + +EBS acts like an external hard drive. You can attach it to an instance, de-attach it, and re-attach it to another instance. You can also stop or terminate an instance after your work is done and not pay for the instance when it is idle. + +If you stop an instance, AWS will still keep the EBS live and as a result the data you have on the hard drive will remain intact (it's like powering off your computer). Later you can restart stopped instances and get access to the data you generated, or even tools you installed there in the previous sessions. However, when you stop an instance instead of terminating it, Amazon will still charge you for the attached EBS (~$0.1/GIG/month). If you terminate the instance, the EBS will get cleaned so you will lose all the data on that instance, but you no longer need to pay for the EBS. + +If you need to keep the data on EBS for your future use (let's say you have custom tools installed on that instance and you don't want to redo your work again later) you can make a snapshot of the EBS and can later restore it in a new EBS and attach it to a new instance. + +Snapshots get stored on S3 (Amazon's cheap storage system; we will get to it later) so it will cost you less ($0.05 per GB-month) to keep the data in EBS like that. However, it takes time (depending on the size of the EBS) to get snapshot and restoring it. Besides, reattaching a restored EBS to EC2 instance is not that straight forward, so it only make sense to use a snapshot like that if you know you are not going to use that EBS for a while. + +Note that to scale an instance up or down, you have to first stop the instance and then change the instance specifications. You can't decrease the EBS size, only increase it, and it's more difficult. You have to: + + 1. Stop the instance + 2. Make a snapshot out of the EBS + 3. Restore the snapshot in an EBS with the new size + 4. De-attach previous EBS + 5. Attach the new one. + + + +### Simple Storage Service (S3) + +S3 is AWS object (file) storage service. S3 is like Dropbox or Google drive, but way more scalable and is made particularly to work with codes and applications. + +S3 doesn't provide a user friendly interface since it is designed to work with online applications, not the end user. Therefore, working with S3 through APIs is easier than through its web console and there are many libraries and APIs developed (in various languages) to work with this service. For example, [Boto3][10] is a S3 library written in Python (in fact Boto3 is suitable for working with many other AWS services as well) . + +S3 stores files based on `bucket`s and `key`s. Buckets are similar to root folders, and keys are similar to subfolders and files. So if you store a file named `my_file.txt` on s3 like `myproject/mytextfiles/my_file.txt`, then "myproject" is the bucket you are using and then `mytextfiles/my_file.txt` is the key to that file. This is important to know since APIs will ask for the bucket and key separately when you want to retrieve your file from s3. + +#### S3 benefits + +There is no limit on the size of data you can store on S3--you just have to pay for the storage based on the size you need per month. + +S3 is also very reliable and "[it is designed to deliver 99.999999999% durability][11]". However, the service may not be always up. On February 28th, 2017 some of s3 servers went down for couple of hours and that disrupted many applications such as Slack, Trello, etc. see [these][12] [articles][13] for more information on this incident. + +#### S3 cost + +The cost is low, starting at $0.023 per GB per month for standard access, if you want to get access to these files regularly. It could go down even lower if you don't need to load data too frequently. See [Amazon S3 Pricing][14] for more information. + +AWS may charge you for other S3 related actions such as requests through APIs, but the cost for those are insignificant (less than $0.05 per 1,000 requests in most cases). + +### Relational Database Service (RDS) + +AWS RDS is a relational database service in the cloud. RDS currently supports SQL Server, MySQL, PostgreSQL, ORACLE, and a couple of other SQL-based frameworks. AWS sets up the system you need and configures the parameters so you can have a relational database up and running in minutes. RDS also handles backup, recovery, software patching, failure detection, and repairs by itself so you don't need to maintain the system. + +#### RDS benefits + +RDS is scalable, both computing power and the storage capacity can be scaled up or down easily. RDS system runs on EC2 servers (as I mentioned EC2 servers are the core of most of AWS services, including RDS service) so by computing power here we mean the computing power of the EC2 server our RDS service is running on, and you can scale up the computing power of this system up to 32 vCPUs and 244 GiB of RAM and changing the scale would not take more than few minutes. + +Scaling the storage requirements up or down is also possible. [Amazon Aurora][15] is a version of MySQL and PostgreSQL with some additional features, and can automatically scale up when more storage space is needed (you can define the maximum). The MySQL, MariaDB, Oracle, and PostgreSQL engines allow you to scale up on the fly without downtime. + +#### RDS cost + +The [cost of RDS servers][16] is based on three factors: computational power, storage, and data transfer. + +![RDSpricing][17] + +For example, a PostgreSQL system with medium computational power (2 vCPUs and 8 gig of memory) costs $0.182 per hour; you can pay less if you go under a one- or three-year contract. + +For storage, there are a [variety of options and prices][18]. If you choose single availability zone General Purpose SSD Storage (gp2), a good option for data scientists, the cost for a server in north Virginia at the time of writing this article is $0.115 per GB-month, and you can select from 5 GB to 16 TB of SSD. + +For data transfer, the cost varies a little based on the source and destination of data (one of which is RDS). For example, all data transferred from the internet into RDS is free. The first gig of data transferred from RDS to the internet is free as well, and for the next 10 terabytes of data in a month it costs $0.09 per GB; the cost decreases for transfering more data than that. + +### Redshift + +Redshift is Amazon's data warehouse service; it is a distributed system (something like the Hadoop framework) which lets you store huge amounts of data and get queries. The difference between this service and RDS is its high capacity and ability to work with big data (terabytes and petabytes). You can use simple SQL queries on Redshift as well. + +Redshift works on a distributed framework--data is distributed on different nodes (servers) connected on a cluster. Simply put, queries on a distributed system run in parallel on all the nodes and then the results get collected from each node and get summarized. + +#### Redshift benefits + +Redshift is highly scalable, meaning in theory (depending on the query, network structure and design, service specification, etc.) the speed of getting query out of 1 terabyte of data and 1 petabyte of data can match by scaling up (adding more cluster to) the system. + +When you create a table on Redshift, you can choose one of three distribution styles: EVEN, KEY, or ALL. + + * EVEN means the table rows will get distributed over all the nodes evenly. Then queries involving that table get distributed over the cluster and run in parallel, summarized at the end. Per Amazon's documentation, "[EVEN distribution is appropriate when a table does not participate in joins][19]". + + * ALL means that on each node there will be a copy of this table, so if you query for a join on that table, the table is already there on all the nodes and there is no need for copying the required data across the network from node to node. The problem is "[ALL distribution multiplies the storage required by the number of nodes in the cluster, and so it takes much longer to load, update, or insert data into multiple tables][19]". + + * In the KEY style, distribution rows of the table are distributed based on the values in one column, in an attempt to keep the rows with the same value of that column in the same node. Physically storing matching values on the same nodes make joining on that specific column faster in parallel systems, see more information [here][19]. + + + + +#### Redshift cost + +Redshift has two types of instances: Dense Compute or Dense Storage. Dense Compute is optimized for fast querying and it is cost effective for less than 500GB of data in size (~$5,500/TB/Year for a three-year contract with partial upfront). + +Dense Storage is optimized for high size storage (~$1,000/TB/Year for a three-year contract with partial upfront) and is cost effective for +500GB, but it is slower. You can find more general pricing [here][20]. + +You can also save a large amount of data on S3 and use [Amazon Redshift Spectrum][21] to run SQL query on that data. For Redshift Spectrum, AWS charges you by the number of bytes scanned by Redshift Spectrum per query; and $5 per terabyte of data scanned (10 megabyte minimum per query). + +### Elastic MapReduce (EMR) + +EMR is suitable for setting up Hadoop clusters with Spark and other distributed type applications. A Hadoop cluster can be used as a compute engine or a (distributed) storage system. However, if the data is so big that you need a distributed system to handle it, Redshift is more suitable and way cheaper than storing in EMR. + +There are three types of [nodes][22] on a cluster: + + * The master node (you only have one) is responsible for managing the cluster. It distributes the workloads to the core and task nodes, tracks the status of tasks, and monitors the health of the cluster. + * Core nodes run tasks and store the data. + * Task nodes can only run tasks. + + + +#### EMR benefits + +Since you can set EMR to install Apache Spark, this service is good for for cleaning, reformatting, and analyzing big data. You can use EMR on-demand, meaning you can set it to grab the code and data from a source (e.g. S3 for the code, and S3 or RDS for the data), run the task on the cluster, and store the results somewhere (again s3, RDS, or Redshift) and terminate the cluster. + +By using the service in such a way, you can reduce the cost of your cluster significantly. In my opinion, EMR is one of the most useful AWS services for data scientists. + +To setup an EMR cluster, you need to first configure applications you want to have on the cluster. Note that different versions of EMR come with different versions of the applications. For example, if you configure EMR version 5.10.0 to install Spark, the default version of the Spark for this version is 2.2.0. So if your code works only on Spark 1.6, you need to run EMR on the 4.x version. EMR will set up the network and configures all the nodes on the cluster along with needed tools. + +An EMR cluster comes with one master instance and a number of core nodes (slave instances). You can choose the number of core nodes, and can even select to have no core node and only use the master server for your work. Like other services, you can choose the computational power of the servers and the storage size available on each node. You can use autoscale option for your core nodes, meaning you can add rules to the system to add/remove core node (up to a maximum number you choose) if needed while running your code. See [Using Automatic Scaling in Amazon EMR][23] for more information on auto scaling. + +#### EMR pricing + +EMR pricing is based on the computational power you choose for different instances (master, core and task nodes). Basically, it is the cost of the EC2 servers plus the cost of EMR. You can find detailed pricing [here][24]. + +![EMRpricing][25] + +### Conclusion + +I have developed many end-to-end data-driven products (including reporting, machine learning models, and product health checking systems) for our company using Python and Spark on AWS, which later became good sources of income for the company. + +Experience working with cloud services, especially a well-known one like AWS, is a huge plus in your data scientist career. Many companies depend on these services now and use them constantly, so you being familiar with these services will give them the confidence that you need less training to get on board. With more and more people moving into data science, you want your resume to stand out as much as possible. + +Do you have cloud tips to add? [Let us know][26]. + +-------------------------------------------------------------------------------- + +via: https://www.dataquest.io/blog/introduction-to-aws-for-data-scientists/ + +作者:[Read More][a] +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.dataquest.io/blog/author/armin/ +[1]:/blog/content/images/2018/01/sky-690293_1920.jpg +[2]:http://www.computerweekly.com/feature/A-history-of-cloud-computing +[3]:https://www.forbes.com/sites/bobevans1/2017/07/28/ibm-beats-amazon-in-12-month-cloud-revenue-15-1-billion-to-14-5-billion/#53c3e14c39d6 +[4]:https://aws.amazon.com/blogs/aws/new-per-second-billing-for-ec2-instances-and-ebs-volumes/ +[5]:https://aws.amazon.com/ec2/pricing/on-demand/ +[6]:https://aws.amazon.com/ec2/spot/pricing/ +[7]:https://aws.amazon.com/ebs/pricing/ +[8]:https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/storage-optimized-instances.html +[9]:/blog/content/images/2018/01/Ec2cost.png +[10]:https://boto3.readthedocs.io +[11]:https://aws.amazon.com/s3/ +[12]:https://aws.amazon.com/message/41926/ +[13]:https://venturebeat.com/2017/02/28/aws-is-investigating-s3-issues-affecting-quora-slack-trello/ +[14]:https://aws.amazon.com/s3/pricing/ +[15]:https://aws.amazon.com/rds/aurora/ +[16]:https://aws.amazon.com/rds/postgresql/pricing/ +[17]:/blog/content/images/2018/01/RDSpricing.png +[18]:https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_Storage.html +[19]:http://docs.aws.amazon.com/redshift/latest/dg/c_choosing_dist_sort.html +[20]:https://aws.amazon.com/redshift/pricing/ +[21]:https://aws.amazon.com/redshift/spectrum/ +[22]:http://docs.aws.amazon.com/emr/latest/DeveloperGuide/emr-nodes.html +[23]:https://docs.aws.amazon.com/emr/latest/ManagementGuide/emr-automatic-scaling.html +[24]:https://aws.amazon.com/emr/pricing/ +[25]:/blog/content/images/2018/01/EMRpricing.png +[26]:https://twitter.com/dataquestio diff --git a/sources/tech/20180130 Mitigating known security risks in open source libraries.md b/sources/tech/20180130 Mitigating known security risks in open source libraries.md new file mode 100644 index 0000000000..adb1491e7d --- /dev/null +++ b/sources/tech/20180130 Mitigating known security risks in open source libraries.md @@ -0,0 +1,249 @@ +Mitigating known security risks in open source libraries +============================================================ + +>Fixing vulnerable open source packages. + + +![Machine](https://d3tdunqjn7n0wj.cloudfront.net/360x240/machine-2881186_1920-aa3ebed0567d4ab0a107baa640661e35.jpg) + +Machine (source: [Skitterphoto][9]) + + +This is an excerpt from [Securing Open Source Libraries][13], by Guy Podjarny.  +[Read the preceding chapter][14] or [view the full report][15]. + + +### Fixing Vulnerable Packages + +Finding out if you’re using vulnerable packages is an important step, but it’s not the real goal. The real goal is to fix those issues! + +This chapter focuses on all you should know about fixing vulnerable packages, including remediation options, tooling, and various nuances. Note that SCA tools traditionally focused on finding or preventing vulnerabilities, and most put little emphasis on fix beyond providing advisory information or logging an issue. Therefore, you may need to implement some of these remediations yourself, at least until more SCA solutions expand to include them. + +There are several ways to fix vulnerable packages, but upgrading is the best choice. If that is not possible, patching offers a good alternative. The following sections discuss each of these options, and we will later take a look at what you can do in situations where neither of these solutions is possible. + +### Upgrading + +As I’ve previously stated, a vulnerability is a type of bug, and the best way to address a bug is to use a newer version where it is fixed. And so, the best way to fix a vulnerable dependency is to upgrade to a newer version. Statistically, most disclosed vulnerabilities are eventually fixed. In npm, 59% of reported vulnerabilities have a fix. In Maven, 90% are remediable, while that portion is 85% in RubyGems.[1][4] In other words, more often than not, there is a version of your library where the vulnerability is fixed. + +Finding a vulnerable package requires knowledge of which versions are vulnerable. This means that, at the very least, every tool that finds issues can tell which versions are vulnerable, allowing you to look for newer versions of the library and upgrade. Most tools also take the minor extra step of determining the minimal fixed version, and noting it in the advisory. + +Upgrading is therefore the best way to make a vulnerability go away. It’s technically easy (update a manifest or lock file), and it’s something dev teams are very accustomed to doing. That said, upgrading still holds some complexity. + +### Major Upgrades + +While most issues are fixed, very often the fix is only applied to the latest and greatest version of the library. If you’re still using an older version of the library, upgrading may mean switching to a new major version. Major upgrades are typically not backward compatible, introducing more risk and requiring more dev effort. + +Another reason for fixing an issue only in the next major version is that sometimes fixing a vulnerability means reducing functionality. For instance, fixing a certain [XSS vulnerability in a jQuery 2.x codebase][5] requires a change to the way certain selectors are interpreted. The jQuery team determined too many people are relying on this functionality to deem this a non-breaking change, and so only fixed the vulnerability in their 3.x stream. + +For these reasons, a major upgrade can often be difficult, but if you can accept it, it’s still the best way to fix a vulnerability. + +### Indirect Dependency Upgrade + +If you’re consuming a dependency directly, upgrading is relatively straightforward. But what happens when one of your dependencies is the one who pulled in the vulnerable package? Most dependencies are in fact indirect dependencies (a.k.a. transitive dependencies), making upgrades a bit more complex. + +The cleanest way to perform an indirect upgrade is through a direct one. If your app uses `A@1`, which uses a vulnerable `B@1`, it’s possible that upgrading to `A@2` will trigger a downstream upgrade to `B@2` and fix the issue. Applying such an upgrade is easy (it’s essentially a direct upgrade), but discovering  _which_  upgrade to do (and whether one even exists) is time consuming. While not common, some SCA tools can determine and advise on the  _direct_  upgrades you need to make to fix an  _indirect_  vulnerability. If your tooling doesn’t support it, you’ll need to do the searching manually. + +Old vulnerabilities in indirect libraries can often be fixed with a direct upgrade, but such upgrades are frequently unavailable for new issues. When a new vulnerability is disclosed, even if the offending package releases a fix right away, it takes a while for the dependency chain to catch up. If you can’t find a path to an indirect upgrade for a newly disclosed flaw, be sure to recheck frequently as one may show up soon. Once again, some SCA tools will do this monitoring for you and alert you when new remediations are available. + + +![The direct vulnerable EJS can be upgraded, but indirect instance cannot currently be upgraded](https://d3ansictanv2wj.cloudfront.net/sosl_0301-d3ce5b0bf64893e26ee74627bfba5300.png) +Figure 1-1. The direct vulnerable EJS can be upgraded, but indirect instance cannot currently be upgraded + +### Conflicts + +Another potential obstacle to upgrading is a conflict. Many languages, such as Ruby and Python, require dependencies to be global, and clients such as Ruby’s bundler and Python’s pip determine the mix of library versions that can co-exist. As a result, upgrading one library may trigger a conflict with another. While developers are adept at handling such conflicts, there are times when such issues simply cannot be resolved. + +On the positive side, global dependency managers, such as Ruby’s bundler, allow the parent app to add a constraint. For instance, if a downstream `B@1` gem is vulnerable, you can add `B@^2` to your Gemfile, and have bundler sort out the surrounding impact. Adding such constraints is a safe and legitimate solution, as long as your ecosystem tooling can figure out a conflict-free combination of libraries. + +### Is a Newer Version Always Safer? + +The conversation about upgrading begs a question: can a vulnerability also be fixed by downgrading? + +For the most part, the answer is no. Vulnerabilities are bugs, and bugs are typically fixed in a newer version, not an older one. In general, maintaining a good upgrade cadence and keeping your dependencies up to date is a good preventative measure to reduce the risk of vulnerabilities. + +However, in certain cases, code changes or (more often) new features are the ones that trigger a vulnerability. In those cases, it’s indeed possible that downgrading will fix the discovered flaw. The advisory should give you the information you need about which versions are affected by the vulnerability. That said, note that downgrading a package puts you at higher risk of being exposed to new issues, and can make it harder to upgrade when that happens. I suggest you see downgrading as a temporary and rarely used remediation path. + +### There Is No Fixed Version + +Last on the list of reasons preventing you from upgrading to a safe version is such a version not existing in the first place! + +While most vulnerabilities are fixed, many remain unfixed. This is sometimes a temporary situation—for instance, when a vulnerability was made public without waiting for a fix to be released. Other times, it may be a more long-term scenario, as many repositories fall into a poor maintenance state, and don’t fix reported issues nor accept community patches. + +In the following sections I’ll discuss some options for when you cannot upgrade a vulnerability away. + +### Patching + +Despite all the complexity it may involve, upgrading is the best way to fix an issue. However, if you cannot upgrade, patching the vulnerability is the next best option. + +Patching means taking a library as is, including its vulnerabilities, and then modifying it to fix a vulnerability it holds. Patching should apply the minimal set of changes to the library, so as to keep its functionality unharmed and only address the issue at hand. + +Patching inevitably holds a certain amount of risk. When you use a package downloaded millions of time a month, you have some assurance that bugs in it will be discovered, reported, and often fixed. When you download that package and modify it, your version of the code will not be quite as battle tested. + +Patching is therefore an exercise in risk management. What presents a greater risk: having the vulnerability, or applying the patch? For well-managed patches, especially for ones small in scope, I believe it’s almost always better to have a patch than a vulnerability. + +It’s worth noting that patching application dependencies is a relatively new concept, but an old hat in the operating system world. When dealing with operating system dependencies, we’re accustomed to consuming a feed of fixes by running `apt-get upgrade` or an equivalent command, often remaining unaware of which issues we fixed. What most don’t know is that many of the fixes you pull down are in fact back-ported versions of the original OS author code changes, created and tested by Canonical, RedHat, and the like. A safe registry that feeds you the non-vulnerable variants of your dependencies doesn’t exist yet in the application libraries world, but patching is sometimes doable in other ways. + +### Sourcing Patches + +To create a patch, you first need to have a fix for the vulnerability! You could write one yourself, but patches are more often sourced from existing community fixes. + +The first place to look for a patch is a new version of the vulnerable package. Most often the vulnerability  _was_  fixed by the maintainers of the library, but that fix may be in an out-of-reach indirect dependency, or perhaps was only fitted back into the latest major version. Those fixes can be extracted from the original repo and stored into their own patch file, as well as back-ported into older versions if need be. + +Another common source for patches are external pull requests (PRs). Open source maintenance is a complicated topic, and it’s not uncommon for repos to go inactive. In such repos, you may find community pull requests that fix a vulnerability, have been commented on and perhaps vetted by others, but are not merged and published into the main stream. Such PRs are a good starting point—if not the full solution—for creating a patch. For instance, an XSS issue in the popular JavaScript Markdown parsing library marked had an [open fix PR][6] for nearly a year before it was incorporated into a new release. During this period, you could use the fix PR code to patch the issue in your apps. + +Snyk maintains its own set of patches in its [open source database][7]. Most of those patches are captures or back-ports of original fixes, a few are packaged pull requests, and even fewer are written by the Snyk security research team. + +### Depend on GitHub Hash + +In very specific cases, you may be able to patch without storing any code changes. This is only possible if the vulnerable dependency is a direct dependency of your app, and the public repo holding the package has a commit that fixes the issue (often a pull request, as mentioned before). + +If that’s the case, most package managers allow you to change your manifest file to point to the GitHub commit instead of naming your package and version. Git hashes are immutable, so you’ll know exactly what you’re getting, even if the pull request evolved. However, the commit may be deleted, introducing certain reliability concerns. + +### Fork and Patch + +When patching a vulnerability in a direct dependency, assuming you don’t want to depend on an external commit or have none to use, you can create one of your own. Doing so typically means forking the GitHub repository to a user you control, and patching it. Once done, you can modify your manifest to point to your fixed repository. + +Forking is a fairly common way of fixing different bugs in dependencies, and also carries some nice reliability advantages, as the code you use is now in your own control. It has the downside of breaking off the normal version stream of the dependency, but it’s a decent short-term solution to vulnerabilities in direct dependencies. Unfortunately, forking is not a viable option for patching indirect dependencies. + +### Static Patching at Build Time + +Another opportunity to patch a dependency is during build time. This type of patching is more complicated, as it requires: + +1. Storing a patch in a file (often a  _.patch_  file, or an alternative JAR file with the issue fixed) + +2. Installing the dependencies as usual + +3. Determining where the dependency you’d like to patch was installed + +4. Applying the patch by modifying or swapping out the risky code + +These steps are not trivial, but they’re also usually doable using package manager commands. If a vulnerability is worth fixing, and there are no easier means to fix it, this approach should be considered. + +This is a classic problem for tools to address, as patches can be reused and their application can be repeated. However, at the time of this writing, Snyk is the only SCA tool that maintains patches in its DB and lets you apply them in your pipeline. I predict over time more and more tools will adopt this approach. + +### Dynamic Patching at Boot Time + +In certain programming languages, classes can also be modified at runtime, a technique often referred to as "monkey patching." Monkey patching can be used to fix vulnerabilities, though that practice has not become the norm in any ecosystem. The most prevalent use of monkey patching to fix vulnerabilities is in Ruby on Rails, where the Rails team has often released patches for vulnerabilities in the libraries it maintains. + +### Other Remediation Paths + +So far, I’ve stated upgrades are the best way to address a vulnerability, and patching the second best. However, what should you do when you cannot (or will not) upgrade nor patch? + +In those cases, you have no choice but to dig deeper. You need to understand the vulnerability better, and how it plays into your application. If it indeed puts your application at notable risk, there are a few steps you can take. + +### Removal + +Removing a dependency is a very effective way of fixing its vulnerabilities. Unfortunately, you’ll be losing its functionality at the same time. + +Dropping a dependency is often hard, as it by definition requires changes to your actual code. That said, such removal may turn out to be easy—for instance, when a dependency was used for convenience and can be rewritten instead, or when a comparable alternative exists in the ecosystem. + +Easy or hard, removing a dependency should always be considered an option, and weighed against the risk of keeping it. + +### External Mitigation + +If you can’t fix the vulnerable code, you can try to block attacks that attempt to exploit it instead. Introducing a rule in a web app firewall, modifying the parts of your app that accept related user input, or even blocking a port are all potential ways to mitigate a vulnerability. + +Whether you can mitigate and how to do so depends on the specific vulnerability and application, and in many cases such protection is impossible or high risk. That said, the most trivially exploited vulnerabilities, such as the March 2017 Struts2 RCE and ImageTragick, are often the ones most easily identified and blocked, so this approach is definitely worth exploring. + +###### Tip + +### Protecting Against Unknown Vulnerabilities + +Once you’re aware of a known vulnerability, your best move is to fix it, and external mitigation is a last resort. However, security controls that protect against unknown vulnerabilities, ranging from web app firewalls to sandboxed processes to ensuring least privilege, can often protect you from known vulnerabilities as well. + +### Log Issue + +Last but not least, even if you choose not to remediate the issue, the least you can do is create an issue for it. Beyond its risk management advantages, logging the issue will remind you to re-examine the remediation options over time—for instance, looking for newly available upgrades or patches that can help. + +If you have a security operations team, make sure to make them aware of vulnerabilities you are not solving right now. This information can prove useful when they triage suspicious behavior on the network, as such behavior may come down to this security hole being exploited. + +### Remediation Process + +Beyond the specific techniques, there are few broader guidelines when it comes to remediating issues. + +### Ignoring Issues + +If you choose not to fix an issue, or to fix it through a custom path, you’ll need to tell your SCA tool you did. Otherwise, the tool will continue to indicate this problem. + +All OSS security tools support ignoring a vulnerability, but have slightly different capabilities. You should consider the following, and try to note that in your tool of choice: + +* Are you ignoring the issue because it doesn’t affect you (perhaps you’ve mitigated it another way) or because you’ve accepted the risk? This may reflect differently in your top-level reports. + +* Do you want to mute the issue indefinitely, or just "snooze" it? Ignoring temporarily is common for low-severity issues that don’t yet have an upgrade, where you’re comfortable taking the risk for a bit and anticipate an upgrade will show up soon. + +* Do you want to ignore all instances of this known vulnerability (perhaps it doesn’t apply to your system), or only certain vulnerable paths (which, after a careful vetting process, you’ve determined to be non-exploitable)? + +Properly tagging the reason for muting an alert helps manage these vulnerabilities over time and across projects, and reduces the chance of an issue being wrongfully ignored and slipping through the cracks. + +### Fix All Vulnerable Paths + +For all the issues you’re not ignoring, remember that remediation has to be done for  _every vulnerable path_ . + +This is especially true for upgrades, as every path must be assessed for upgrade separately, but also applies to patches in many ecosystems. + +### Track Remediations Over Time + +As already mentioned, a fix is typically issued for the vulnerable package first, and only later propagates through the dependency chain as other libraries upgrade to use the newer (and safer) version. Similarly, community or author code contributions are created constantly, addressing issues that weren’t previously fixable. + +Therefore, it’s worth tracking remediation options over time. For ignored issues, periodically check if an easy fix is now available. For patched issues, track potential updates you can switch to. Certain SCA tools automate this tracking and notify you (or open automated pull requests) when such new remediations are available. + +### Invest in Making Fixing Easy + +The unfortunate reality is that new vulnerabilities in libraries are discovered all the time. This is a fact of life—code will have bugs, some of those bugs are security bugs (vulnerabilities), and some of those are disclosed. Therefore, you and your team should expect to get a constant stream of vulnerability notifications, which you need to act on. + +If fixing these vulnerabilities isn’t easy, your team will not do it. Fixing these issues competes with many priorities, and its oh-so-easy to put off this invisible risk. If each alert requires a lot of time to triage and determine a fix for, the ensuing behavior would likely be to either put it off or try to convince yourself it’s not a real problem. + +In the world of operating systems, fixing has become the default action. In fact, "patching your servers" means taking in a feed of fixes, often without ever knowing which vulnerabilities we fix. We should strive to achieve at least this level of simplicity when dealing with vulnerable app dependencies too. + +Part of this effort is on tooling providers. SCA tools should let you fix vulnerabilities with a click or proactive pull requests, or patch them with a single command like `apt-get upgrade` does on servers. The other part of the effort is on you. Consider it a high priority to make vulnerability remediation easy, choose priority, choose your tools accordingly, and put in the effort to enrich or adapt those tools to fit your workflow. + +### Summary + +You should always keep in mind that finding these vulnerabilities isn’t the goal—fixing them is. Because fixing vulnerabilities is something your team will need to do often, defining the processes and tools to get that done is critical. + +A great way to get started with remediation is to find vulnerabilities that can be fixed with a non-breaking upgrade, and get those upgrades done. While not entirely risk-free, these upgrades should be backward compatible, and getting these security holes fixed gets you off to a very good start. + +[1][8]Stats based on vulnerabilities curated in the Snyk vulnerability DB. + + +This is an excerpt from [Securing Open Source Libraries][16], by Guy Podjarny.  +[Read the preceding chapter][17] or [view the full report][18]. + + + +------------------------------------- + +作者简介: + +Guy Podjarny (Guypo) is a web performance researcher/evangelist and Akamai's Web CTO, focusing primarily on Mobile and Front-End performance. As a researcher, Guy frequently runs large scale tests, exploring performance in the real world and matching it to how browsers behave, and was one of the first to highlight the performance implications of Responsive Web Design. Guy is also the author of Mobitest, a free mobile measurement tool, and contributes to various open source tools. Guy was previously the co-founder and CTO of blaze.io, ac... + +-------------------------------------------------------------------------------- + +via: https://www.oreilly.com/ideas/mitigating-known-security-risks-in-open-source-libraries + +作者:[ Guy Podjarny][a] +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.oreilly.com/people/4dda0-guy-podjarny +[1]:https://www.safaribooksonline.com/home/?utm_source=newsite&utm_medium=content&utm_campaign=lgen&utm_content=security-post-safari-right-rail-cta +[2]:https://www.safaribooksonline.com/home/?utm_source=newsite&utm_medium=content&utm_campaign=lgen&utm_content=security-post-safari-right-rail-cta +[3]:https://www.safaribooksonline.com/home/?utm_source=newsite&utm_medium=content&utm_campaign=lgen&utm_content=security-post-safari-right-rail-cta +[4]:https://www.oreilly.com/ideas/mitigating-known-security-risks-in-open-source-libraries#id-xJ0u4SBFphz +[5]:https://snyk.io/vuln/npm:jquery:20150627 +[6]:https://github.com/chjj/marked/pull/592 +[7]:https://github.com/snyk/vulnerabilitydb +[8]:https://www.oreilly.com/ideas/mitigating-known-security-risks-in-open-source-libraries#id-xJ0u4SBFphz-marker +[9]:https://pixabay.com/en/machine-mill-industry-steam-2881186/ +[10]:https://www.oreilly.com/ideas/mitigating-known-security-risks-in-open-source-libraries +[11]:https://www.oreilly.com/people/4dda0-guy-podjarny +[12]:https://www.oreilly.com/people/4dda0-guy-podjarny +[13]:https://www.safaribooksonline.com/library/view/securing-open-source/9781491996980/?utm_source=oreilly&utm_medium=newsite&utm_campaign=fixing-vulnerable-open-source-packages +[14]:https://www.oreilly.com/ideas/finding-vulnerable-open-source-packages?utm_source=oreilly&utm_medium=newsite&utm_campaign=fixing-vulnerable-open-source-packages +[15]:https://www.safaribooksonline.com/library/view/securing-open-source/9781491996980/?utm_source=oreilly&utm_medium=newsite&utm_campaign=fixing-vulnerable-open-source-packages +[16]:https://www.safaribooksonline.com/library/view/securing-open-source/9781491996980/?utm_source=oreilly&utm_medium=newsite&utm_campaign=fixing-vulnerable-open-source-packages +[17]:https://www.oreilly.com/ideas/finding-vulnerable-open-source-packages?utm_source=oreilly&utm_medium=newsite&utm_campaign=fixing-vulnerable-open-source-packages +[18]:https://www.safaribooksonline.com/library/view/securing-open-source/9781491996980/?utm_source=oreilly&utm_medium=newsite&utm_campaign=fixing-vulnerable-open-source-packages +[19]:https://pixabay.com/en/machine-mill-industry-steam-2881186/ \ No newline at end of file diff --git a/sources/tech/20180130 Python - Memcached- Efficient Caching in Distributed Applications - Real Python.md b/sources/tech/20180130 Python - Memcached- Efficient Caching in Distributed Applications - Real Python.md new file mode 100644 index 0000000000..647a5968e6 --- /dev/null +++ b/sources/tech/20180130 Python - Memcached- Efficient Caching in Distributed Applications - Real Python.md @@ -0,0 +1,239 @@ +Python + Memcached: Efficient Caching in Distributed Applications – Real Python +====== + +When writing Python applications, caching is important. Using a cache to avoid recomputing data or accessing a slow database can provide you with a great performance boost. + +Python offers built-in possibilities for caching, from a simple dictionary to a more complete data structure such as [`functools.lru_cache`][2]. The latter can cache any item using a [Least-Recently Used algorithm][3] to limit the cache size. + +Those data structures are, however, by definition local to your Python process. When several copies of your application run across a large platform, using a in-memory data structure disallows sharing the cached content. This can be a problem for large-scale and distributed applications. + +![](https://files.realpython.com/media/python-memcached.97e1deb2aa17.png) + +Therefore, when a system is distributed across a network, it also needs a cache that is distributed across a network. Nowadays, there are plenty of network servers that offer caching capability—we already covered [how to use Redis for caching with Django][4]. + +As you’re going to see in this tutorial, [memcached][5] is another great option for distributed caching. After a quick introduction to basic memcached usage, you’ll learn about advanced patterns such as “cache and set” and using fallback caches to avoid cold cache performance issues. + +### Installing memcached + +Memcached is [available for many platforms][6]: + + * If you run **Linux** , you can install it using `apt-get install memcached` or `yum install memcached`. This will install memcached from a pre-built package but you can alse build memcached from source, [as explained here][6]. + * For **macOS** , using [Homebrew][7] is the simplest option. Just run `brew install memcached` after you’ve installed the Homebrew package manager. + * On **Windows** , you would have to compile memcached yourself or find [pre-compiled binaries][8]. + + + +Once installed, memcached can simply be launched by calling the `memcached` command: +``` +$ memcached + +``` + +Before you can interact with memcached from Python-land you’ll need to install a memcached client library. You’ll see how to do this in the next section, along with some basic cache access operations. + +### Storing and Retrieving Cached Values Using Python + +If you never used memcached, it is pretty easy to understand. It basically provides a giant network-available dictionary. This dictionary has a few properties that are different from a classical Python dictionnary, mainly: + + * Keys and values have to be bytes + * Keys and values are automatically deleted after an expiration time + + + +Therefore, the two basic operations for interacting with memcached are `set` and `get`. As you might have guessed, they’re used to assign a value to a key or to get a value from a key, respectively. + +My preferred Python library for interacting with memcached is [`pymemcache`][9]—I recommend using it. You can simply [install it using pip][10]: +``` +$ pip install pymemcache + +``` + +The following code shows how you can connect to memcached and use it as a network-distributed cache in your Python applications: +``` +>>> from pymemcache.client import base + +# Don't forget to run `memcached' before running this next line: +>>> client = base.Client(('localhost', 11211)) + +# Once the client is instantiated, you can access the cache: +>>> client.set('some_key', 'some value') + +# Retrieve previously set data again: +>>> client.get('some_key') +'some value' + +``` + +memcached network protocol is really simple an its implementation extremely fast, which makes it useful to store data that would be otherwise slow to retrieve from the canonical source of data or to compute again: + +While straightforward enough, this example allows storing key/value tuples across the network and accessing them through multiple, distributed, running copies of your application. This is simplistic, yet powerful. And it’s a great first step towards optimizing your application. + +### Automatically Expiring Cached Data + +When storing data into memcached, you can set an expiration time—a maximum number of seconds for memcached to keep the key and value around. After that delay, memcached automatically removes the key from its cache. + +What should you set this cache time to? There is no magic number for this delay, and it will entirely depend on the type of data and application that you are working with. It could be a few seconds, or it might be a few hours. + +Cache invalidation, which defines when to remove the cache because it is out of sync with the current data, is also something that your application will have to handle. Especially if presenting data that is too old or or stale is to be avoided. + +Here again, there is no magical recipe; it depends on the type of application you are building. However, there are several outlying cases that should be handled—which we haven’t yet covered in the above example. + +A caching server cannot grow infinitely—memory is a finite resource. Therefore, keys will be flushed out by the caching server as soon as it needs more space to store other things. + +Some keys might also be expired because they reached their expiration time (also sometimes called the “time-to-live” or TTL.) In those cases the data is lost, and the canonical data source must be queried again. + +This sounds more complicated than it really is. You can generally work with the following pattern when working with memcached in Python: +``` +from pymemcache.client import base + + +def do_some_query(): + # Replace with actual querying code to a database, + # a remote REST API, etc. + return 42 + + +# Don't forget to run `memcached' before running this code +client = base.Client(('localhost', 11211)) +result = client.get('some_key') + +if result is None: + # The cache is empty, need to get the value + # from the canonical source: + result = do_some_query() + + # Cache the result for next time: + client.set('some_key', result) + +# Whether we needed to update the cache or not, +# at this point you can work with the data +# stored in the `result` variable: +print(result) + +``` + +> **Note:** Handling missing keys is mandatory because of normal flush-out operations. It is also obligatory to handle the cold cache scenario, i.e. when memcached has just been started. In that case, the cache will be entirely empty and the cache needs to be fully repopulated, one request at a time. + +This means you should view any cached data as ephemeral. And you should never expect the cache to contain a value you previously wrote to it. + +### Warming Up a Cold Cache + +Some of the cold cache scenarios cannot be prevented, for example a memcached crash. But some can, for example migrating to a new memcached server. + +When it is possible to predict that a cold cache scenario will happen, it is better to avoid it. A cache that needs to be refilled means that all of the sudden, the canonical storage of the cached data will be massively hit by all cache users who lack a cache data (also known as the [thundering herd problem][11].) + +pymemcache provides a class named `FallbackClient` that helps in implementing this scenario as demonstrated here: +``` +from pymemcache.client import base +from pymemcache import fallback + + +def do_some_query(): + # Replace with actual querying code to a database, + # a remote REST API, etc. + return 42 + + +# Set `ignore_exc=True` so it is possible to shut down +# the old cache before removing its usage from +# the program, if ever necessary. +old_cache = base.Client(('localhost', 11211), ignore_exc=True) +new_cache = base.Client(('localhost', 11212)) + +client = fallback.FallbackClient((new_cache, old_cache)) + +result = client.get('some_key') + +if result is None: + # The cache is empty, need to get the value + # from the canonical source: + result = do_some_query() + + # Cache the result for next time: + client.set('some_key', result) + +print(result) + +``` + +The `FallbackClient` queries the old cache passed to its constructor, respecting the order. In this case, the new cache server will always be queried first, and in case of a cache miss, the old one will be queried—avoiding a possible return-trip to the primary source of data. + +If any key is set, it will only be set to the new cache. After some time, the old cache can be decommissioned and the `FallbackClient` can be replaced directed with the `new_cache` client. + +### Check And Set + +When communicating with a remote cache, the usual concurrency problem comes back: there might be several clients trying to access the same key at the same time. memcached provides a check and set operation, shortened to CAS, which helps to solve this problem. + +The simplest example is an application that wants to count the number of users it has. Each time a visitor connects, a counter is incremented by 1. Using memcached, a simple implementation would be: +``` +def on_visit(client): + result = client.get('visitors') + if result is None: + result = 1 + else: + result += 1 + client.set('visitors', result) + +``` + +However, what happens if two instances of the application try to update this counter at the same time? + +The first call `client.get('visitors')` will return the same number of visitors for both of them, let’s say it’s 42. Then both will add 1, compute 43, and set the number of visitors to 43. That number is wrong, and the result should be 44, i.e. 42 + 1 + 1. + +To solve this concurrency issue, the CAS operation of memcached is handy. The following snippet implements a correct solution: +``` +def on_visit(client): + while True: + result, cas = client.gets('visitors') + if result is None: + result = 1 + else: + result += 1 + if client.cas('visitors', result, cas): + break + +``` + +The `gets` method returns the value, just like the `get` method, but it also returns a CAS value. + +What is in this value is not relevant, but it is used for the next method `cas` call. This method is equivalent to the `set` operation, except that it fails if the value has changed since the `gets` operation. In case of success, the loop is broken. Otherwise, the operation is restarted from the beginning. + +In the scenario where two instances of the application try to update the counter at the same time, only one succeeds to move the counter from 42 to 43. The second instance gets a `False` value returned by the `client.cas` call, and have to retry the loop. It will retrieve 43 as value this time, will increment it to 44, and its `cas` call will succeed, thus solving our problem. + +Incrementing a counter is interesting as an example to explain how CAS works because it is simplistic. However, memcached also provides the `incr` and `decr` methods to increment or decrement an integer in a single request, rather than doing multiple `gets`/`cas` calls. In real-world applications `gets` and `cas` are used for more complex data type or operations + +Most remote caching server and data store provide such a mechanism to prevent concurrency issues. It is critical to be aware of those cases to make proper use of their features. + +### Beyond Caching + +The simple techniques illustrated in this article showed you how easy it is to leverage memcached to speed up the performances of your Python application. + +Just by using the two basic “set” and “get” operations you can often accelerate data retrieval or avoid recomputing results over and over again. With memcached you can share the cache accross a large number of distributed nodes. + +Other, more advanced patterns you saw in this tutorial, like the Check And Set (CAS) operation allow you to update data stored in the cache concurrently across multiple Python threads or processes while avoiding data corruption. + +If you are interested into learning more about advanced techniques to write faster and more scalable Python applications, check out [Scaling Python][12]. It covers many advanced topics such as network distribution, queuing systems, distributed hashing, and code profiling. + +-------------------------------------------------------------------------------- + +via: https://realpython.com/blog/python/python-memcache-efficient-caching/ + +作者:[Julien Danjou][a] +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://realpython.com/team/jdanjou/ +[1]:https://realpython.com/blog/categories/python/ +[2]:https://docs.python.org/3/library/functools.html#functools.lru_cache +[3]:https://en.wikipedia.org/wiki/Cache_replacement_policies#Least_Recently_Used_(LRU) +[4]:https://realpython.com/blog/python/caching-in-django-with-redis/ +[5]:http://memcached.org +[6]:https://github.com/memcached/memcached/wiki/Install +[7]:https://brew.sh/ +[8]:https://commaster.net/content/installing-memcached-windows +[9]:https://pypi.python.org/pypi/pymemcache +[10]:https://realpython.com/learn/python-first-steps/#11-pythons-power-packagesmodules +[11]:https://en.wikipedia.org/wiki/Thundering_herd_problem +[12]:https://scaling-python.com diff --git a/sources/tech/20180130 Quick Look at the Arch Based Indie Linux Distribution- MagpieOS.md b/sources/tech/20180130 Quick Look at the Arch Based Indie Linux Distribution- MagpieOS.md new file mode 100644 index 0000000000..a850a8fd33 --- /dev/null +++ b/sources/tech/20180130 Quick Look at the Arch Based Indie Linux Distribution- MagpieOS.md @@ -0,0 +1,78 @@ +Quick Look at the Arch Based Indie Linux Distribution: MagpieOS +====== +Most of the Linux distros that are in use today are either created and developed in the US or Europe. A young developer from Bangladesh wants to change all that. + +### Who is Rizwan? + +[Rizwan][1] is a computer science student from Bangladesh. He is currently studying to become a profession Python programmer. He started using Linux back in 2015. Working with Linux inspired him to create this own Linux distribution. He also wants to let the rest of the world know that Bangladesh is upgrading to Linux. + +He has also worked on creating a [live version of Linux From Scratch][2]. + +## ![MagpieOS Linux][3] + +### What is MagpieOS? + +Rizwan's new distro is named MagpieOS. [MagpieOS][4] is very simple. It is basically Arch with the GNOME3 desktop environment. MagpieOS also includes a custom repo with icons and themes (claimed to be) not available on other Arch-based distros or AUR. + +Here is a list of the software included with MagpieOS: Firefox, LibreOffice, Uget, Bleachbit, Notepadqq, SUSE Studio Image Writer, Pamac Package Manager, Gparted, Gimp, Rhythmbox, Simple Screen Recorder, all default GNOME software including Totem Video Player, and a new set of custom wallpaper. + +Currently, MagpieOS only supported the GNOME desktop environment. Rizwan picked it because it is his favorite. However, he plans to add more desktop environments in the future. + +Unfortunately, MagpieOS does not support the Bangla language or any other local languages. It supports GNOME's default language like English, Hindi etc. + +Rizwan named his distro MagpieOS because the [magpie][5] is the official bird of Bangladesh. + +## ![MagpieOS Linux][6] + +### Why Arch? + +Like most people, Rizwan started his Linux journey by using [Ubuntu][7]. In the beginning, he was happy with it. However, sometimes the software he wanted to install was not available in the repos and he had to hunt through Google looking for the correct PPA. He decided to switch to [Arch][8] because Arch has many packages that were not available on Ubuntu. Rizwan also liked the fact that Arch is a rolling release and would always be up-to-date. + +The problem with Arch is that it is complicated and time-consuming to install. So, Rizwan tried out several Arch-based distros and was not happy with any of them. He didn't like [Manjaro][9] because they did not have permission to use Arch's repos. Also, Arch repo mirrors are faster than Manjaro's and have more software. He liked [Antergos][10], but to install you need a constant internet connection. If your connection fails during installation, you have to start over. + +Because of these issues, Rizwan decided to create a simple distro that would give him and others an Arch install without all the hassle. He also hopes to get developers from his home country to switch from Ubuntu to Arch by using his distro. + +### How to Help Rizwan with MagpieOS + +If you are interested in helping Rizwan develop MagpieOS, you can contact him via the [MagpieOS website][4]. You can also check out the project's [GitHub page][11]. Rizwan said that he is not looking for financial support at the moment. + +## ![MagpieOS Linux][12] + +### Final Thoughts + +I installed MagpieOS to give it a quick once-over. It uses the [Calamares installer][13], which means installing it was relatively quick and painless. After I rebooted, I was greeted by an audio message welcoming me to MagpieOS. + +To be honest, it was the first time I have heard a post-install greeting. (Windows 10 might have one, but I'm not sure.) There was also a Mac OS-esque application dock at the bottom of the screen. Other than that, it felt like any other GNOME 3 desktop I have used. + +Considering that it's an indie project at the nascent stage, I won't recommend it using as your main OS. But if you are a distrohopper, you can surely give it a try. + +That being said, this is a good first try for a student seeking to put his country on the technological map. All the best, Rizwan. + +Have you already heard of MagpieOS? What is your favorite region or locally made Linux distro? Please let us know in the comments below. + +If you found this article interesting, please take a minute to share it on social media. + +-------------------------------------------------------------------------------- + +via: https://itsfoss.com/magpieos/ + +作者:[John Paul][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://twitter.com/Linux_Saikat +[2]:https://itsfoss.com/linux-from-scratch-live-cd/ +[3]:https://itsfoss.com/wp-content/uploads/2018/01/magpieos1.jpg +[4]:http://www.magpieos.net +[5]:https://en.wikipedia.org/wiki/Magpie +[6]:https://itsfoss.com/wp-content/uploads/2018/01/magpieos2.jpg +[7]:https://www.ubuntu.com +[8]:https://www.archlinux.org +[9]:http://manjaro.org +[10]:https://antergos.com +[11]:https://github.com/Rizwan-Hasan/MagpieOS +[12]:https://itsfoss.com/wp-content/uploads/2018/01/magpieos3.png +[13]:https://calamares.io diff --git a/sources/tech/20180130 Reckoning The Spectre And Meltdown Performance Hit.md b/sources/tech/20180130 Reckoning The Spectre And Meltdown Performance Hit.md new file mode 100644 index 0000000000..d7140a21cf --- /dev/null +++ b/sources/tech/20180130 Reckoning The Spectre And Meltdown Performance Hit.md @@ -0,0 +1,85 @@ +Reckoning The Spectre And Meltdown Performance Hit For HPC +============================================================ + +![](https://3s81si1s5ygj3mzby34dq6qf-wpengine.netdna-ssl.com/wp-content/uploads/2015/03/intel-chip-logo-bw-200x147.jpg) + +While no one has yet created an exploit to take advantage of the Spectre and Meltdown speculative execution vulnerabilities that were exposed by Google six months ago and that were revealed in early January, it is only a matter of time. The [patching frenzy has not settled down yet][2], and a big concern is not just whether these patches fill the security gaps, but at what cost they do so in terms of application performance. + +To try to ascertain the performance impact of the Spectre and Meltdown patches, most people have relied on comments from Google on the negligible nature of the performance hit on its own applications and some tests done by Red Hat on a variety of workloads, [which we profiled in our initial story on the vulnerabilities][3]. This is a good starting point, but what companies really need to do is profile the performance of their applications before and after applying the patches – and in such a fine-grained way that they can use the data to debug the performance hit and see if there is any remediation they can take to alleviate the impact. + +In the meantime, we are relying on researchers and vendors to figure out the performance impacts. Networking chip maker Mellanox Technologies, always eager to promote the benefits of the offload model of its switch and network interface chips, has run some tests to show the effects of the Spectre and Meltdown patches on high performance networking for various workloads and using various networking technologies, including its own Ethernet and InfiniBand devices and Intel’s OmniPath. Some HPC researchers at the University of Buffalo have also done some preliminary benchmarking of selected HPC workloads to see the effect on compute and network performance. This is a good starting point, but is far from a complete picture of the impact that might be seen on HPC workloads after organization deploy the Spectre and Meltdown patches to their systems. + +To recap, here is what Red Hat found out when it tested the initial Spectre and Meltdown patches running its Enterprise Linux 7 release on servers using Intel’s “Haswell” Xeon E5 v3, “Broadwell” Xeon E5 v4, and “Skylake” Xeon SP processors: + +* **Measurable, 8 percent to 19 percent:** Highly cached random memory, with buffered I/O, OLTP database workloads, and benchmarks with high kernel-to-user space transitions are impacted between 8 percent and 19 percent. Examples include OLTP Workloads (TPC), sysbench, pgbench, netperf (< 256 byte), and fio (random I/O to NvME). + +* **Modest, 3 percent to 7 percent:** Database analytics, Decision Support System (DSS), and Java VMs are impacted less than the Measurable category. These applications may have significant sequential disk or network traffic, but kernel/device drivers are able to aggregate requests to moderate level of kernel-to-user transitions. Examples include SPECjbb2005, Queries/Hour and overall analytic timing (sec). + +* **Small, 2 percent to 5 percent:** HPC CPU-intensive workloads are affected the least with only 2 percent to 5 percent performance impact because jobs run mostly in user space and are scheduled using CPU pinning or NUMA control. Examples include Linpack NxN on X86 and SPECcpu2006. + +* **Minimal impact:** Linux accelerator technologies that generally bypass the kernel in favor of user direct access are the least affected, with less than 2% overhead measured. Examples tested include DPDK (VsPERF at 64 byte) and OpenOnload (STAC-N). Userspace accesses to VDSO like get-time-of-day are not impacted. We expect similar minimal impact for other offloads. + +And just to remind you, according to Red Hat containerized applications running atop Linux do not incur an extra Spectre or Meltdown penalty compared to applications running on bare metal because they are implemented as generic Linux processes themselves. But applications running inside virtual machines running atop hypervisors, Red Hat does expect that, thanks to the increase in the frequency of user-to-kernel transitions, the performance hit will be higher. (How much has not yet been revealed.) + +Gilad Shainer, the vice president of marketing for the InfiniBand side of the Mellanox house, shared some initial performance data from the company’s labs with regard to the Spectre and Meltdown patches. ([The presentation is available online here.][4]) + +In general, Shainer tells  _The Next Platform_ , the offload model that Mellanox employs in its InfiniBand switches (RDMA is a big component of this) and in its Ethernet (The RoCE clone of RDMA is used here) are a very big deal given the fact that the network drivers bypass the operating system kernels. The exploits take advantage, in one of three forms, of the porous barrier between the kernel and user spaces in the operating systems, so anything that is kernel heavy will be adversely affected. This, says Shainer, includes the TCP/IP protocol that underpins Ethernet as well as the OmniPath protocol, which by its nature tries to have the CPUs in the system do a lot of the network processing. Intel and others who have used an onload model have contended that this allows for networks to be more scalable, and clearly there are very scalable InfiniBand and OmniPath networks, with many thousands of nodes, so both approaches seem to work in production. + +Here are the feeds and speeds on the systems that Mellanox tested on two sets of networking tests. For the comparison of Ethernet with RoCE added and standard TCP over Ethernet, the hardware was a two-socket server using Intel’s Xeon E5-2697A v4 running at 2.60 GHz. This machine was configured with Red Hat Enterprise Linux 7.4, with kernel versions 3.10.0-693.11.6.el7.x86_64 and 3.10.0-693.el7.x86_64\. (Those numbers  _are_  different – there is an  _11.6_  in the middle of the second one.) The machines were equipped with ConnectX-5 server adapters with firmware 16.22.0170 and the MLNX_OFED_LINUX-4.3-0.0.5.0 driver. The workload that was tested was not a specific HPC application, but rather a very low level, homegrown interconnect benchmark that is used to stress switch chips and NICs to see their peak  _sustained_  performance, as distinct from peak  _theoretical_ performance, which is the absolute ceiling. This particular test was run on a two-node cluster, passing data from one machine to the other. + +Here is how the performance stacked up before and after the Spectre and Meltdown patches were added to the systems: + + [![](https://3s81si1s5ygj3mzby34dq6qf-wpengine.netdna-ssl.com/wp-content/uploads/2018/01/mellanox-spectre-meltdown-roce-versus-tcp.jpg)][5] + +As you can see, at this very low level, there is no impact on network performance between two machines supporting RoCE on Ethernet, but running plain vanilla TCP without an offload on top of Ethernet, there are some big performance hits. Interestingly, on this low-level test, the impact was greatest on small message sizes in the TCP stack and then disappeared as the message sizes got larger. + +On a separate round of tests pitting InfiniBand from Mellanox against OmniPath from Intel, the server nodes were configured with a pair of Intel Xeon SP Gold 6138 processors running at 2 GHz, also with Red Hat Enterprise Linux 7.4 with the 3.10.0-693.el7.x86_64 and 3.10.0-693.11.6.el7.x86_64          kernel versions. The OmniPath adapter uses the IntelOPA-IFS.RHEL74-x86_64.10.6.1.0.2 driver and the Mellanox ConnectX-5 adapter uses the MLNX_OFED 4.2 driver. + +Here is how the InfiniBand and OmniPath protocols did on the tests before and after the patches: + + [![](https://3s81si1s5ygj3mzby34dq6qf-wpengine.netdna-ssl.com/wp-content/uploads/2018/01/mellanox-spectre-meltdown-infiniband-versus-omnipath.jpg)][6] + +Again, thanks to the offload model and the fact that this was a low level benchmark that did not hit the kernel very much (and some HPC applications might cross that boundary and therefore invoke the Spectre and Meltdown performance penalties), there was no real effect on the two-node cluster running InfiniBand. With the OmniPath system, the impact was around 10 percent for small message sizes, and then grew to 25 percent or so once the message sizes transmitted reached 512 bytes. + +We have no idea what the performance implications are for clusters of more than two machines using the Mellanox approach. It would be interesting to see if the degradation compounds or doesn’t. + +### Early HPC Performance Tests + +While such low level benchmarks provide some initial guidance on what the effect might be of the Spectre and Meltdown patches on HPC performance, what you really need is a benchmark run of real HPC applications running on clusters of various sizes, both before and after the Spectre and Meltdown patches are applied to the Linux nodes. A team of researchers led by Nikolay Simakov at the Center For Computational Research at SUNY Buffalo fired up some HPC benchmarks and a performance monitoring tool derived from the National Science Foundation’s Extreme Digital (XSEDE) program to see the effect of the Spectre and Meltdown patches on how much work they could get done as gauged by wall clock time to get that work done. + +The paper that Simakov and his team put together on the initial results [is found here][7]. The tool that was used to monitor the performance of the systems was called XD Metrics on Demand, or XDMoD, and it was open sourced and is available for anyone to use. (You might consider [Open XDMoD][8] for your own metrics to determine the performance implications of the Spectre and Meltdown patches.) The benchmarks tested by the SUNY Buffalo researchers included the NAMD molecular dynamics and NWChem computational chemistry applications, as well as the HPC Challenge suite, which itself includes the STREAM memory bandwidth test and the NASA Parallel Benchmarks (NPB), the Interconnect MPI Benchmarks (IMB). The researchers also tested the IOR file reading and the MDTest metadata benchmark tests from Lawrence Livermore National Laboratory. The IOR and MDTest benchmarks were run in local mode and in conjunction with a GPFS parallel file system running on an external 3 PB storage cluster. (The tests with a “.local” suffix in the table are run on storage in the server nodes themselves.) + +SUNY Buffalo has an experimental cluster with two-socket machines based on Intel “Nehalem” Xeon L5520 processors, which have eight cores and which are, by our reckoning, very long in the tooth indeed in that they are nearly nine years old. Each node has 24 GB of main memory and has 40 Gb/sec QDR InfiniBand links cross connecting them together. The systems are running the latest CentOS 7.4.1708 release, without and then with the patches applied. (The same kernel patches outlined above in the Mellanox test.) Simakov and his team ran each benchmark on a single node configuration and then ran the benchmark on a two node configuration, and it shows the difference between running a low-level benchmark and actual applications when doing tests. Take a look at the table of results: + + [![](https://3s81si1s5ygj3mzby34dq6qf-wpengine.netdna-ssl.com/wp-content/uploads/2018/01/suny-buffalo-spectre-meltdown-test-table.jpg)][9] + +The before runs of each application tested were done on around 20 runs, and the after was done on around 50 runs. For the core HPC applications – NAMD, NWChem, and the elements of HPCC – the performance degradation was between 2 percent and 3 percent, consistent with what Red Hat told people to expect back in the first week that the Spectre and Meltdown vulnerabilities were revealed and the initial patches were available. However, moving on to two-node configurations, where network overhead was taken into account, the performance impact ranged from 5 percent to 11 percent. This is more than you would expect based on the low level benchmarks that Mellanox has done. Just to make things interesting, on the IOR and MDTest benchmarks, moving from one to two nodes actually lessened the performance impact; running the IOR test on the local disks resulted in a smaller performance hit then over the network for a single node, but was not as low as for a two-node cluster running out to the GPFS file system. + +There is a lot of food for thought in this data, to say the least. + +What we want to know – and what the SUNY Buffalo researchers are working on – is what happens to performance on these HPC applications when the cluster is scaled out. + +“We will know that answer soon,” Simakov tells  _The Next Platform_ . “But there are only two scenarios that are possible. Either it is going to get worse or it is going to stay about the same as a two-node cluster. We think that it will most likely stay the same, because all of the MPI communication happens through the shared memory on a single node, and when you get to two nodes, you get it into the network fabric and at that point, you are probably paying all of the extra performance penalties.” + +We will update this story with data on larger scale clusters as soon as Simakov and his team provide the data. + +-------------------------------------------------------------------------------- + +via: https://www.nextplatform.com/2018/01/30/reckoning-spectre-meltdown-performance-hit-hpc/ + +作者:[Timothy Prickett Morgan][a] +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.nextplatform.com/author/tpmn/ +[1]:https://www.nextplatform.com/author/tpmn/ +[2]:https://www.nextplatform.com/2018/01/18/datacenters-brace-spectre-meltdown-impact/ +[3]:https://www.nextplatform.com/2018/01/08/cost-spectre-meltdown-server-taxes/ +[4]:http://www.mellanox.com/related-docs/presentations/2018/performance/Spectre-and-Meltdown-Performance.pdf?homepage +[5]:https://3s81si1s5ygj3mzby34dq6qf-wpengine.netdna-ssl.com/wp-content/uploads/2018/01/mellanox-spectre-meltdown-roce-versus-tcp.jpg +[6]:https://3s81si1s5ygj3mzby34dq6qf-wpengine.netdna-ssl.com/wp-content/uploads/2018/01/mellanox-spectre-meltdown-infiniband-versus-omnipath.jpg +[7]:https://arxiv.org/pdf/1801.04329.pdf +[8]:http://open.xdmod.org/7.0/index.html +[9]:https://3s81si1s5ygj3mzby34dq6qf-wpengine.netdna-ssl.com/wp-content/uploads/2018/01/suny-buffalo-spectre-meltdown-test-table.jpg \ No newline at end of file diff --git a/sources/tech/20180130 Refreshing old computers with Linux.md b/sources/tech/20180130 Refreshing old computers with Linux.md new file mode 100644 index 0000000000..0a9f49c1d4 --- /dev/null +++ b/sources/tech/20180130 Refreshing old computers with Linux.md @@ -0,0 +1,104 @@ +Refreshing old computers with Linux +============================================================ + +### A middle school's Tech Stewardship program is now an elective class for science and technology students. + + +![Refreshing old computers with Linux](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/idea_innovation_kid_education.png?itok=3lRp6gFa "Refreshing old computers with Linux") +Image by : opensource.com + +It's nearly impossible to enter a school these days without seeing an abundance of technology. Despite this influx of computers into education, funding inequity forces school systems to make difficult choices. Some educators see things as they are and wonder, "Why?" while others see problems as opportunities and think, "Why not?" + +​[Andrew Dobbie ][31]is one of those visionaries who saw his love of Linux and computer reimaging as a unique learning opportunity for his students. + +Andrew teaches sixth grade at Centennial Senior Public School in Brampton, Ontario, Canada, and is a[Google Certified Innovator][16]. Andrew said, "Centennial Senior Public School hosts a special regional science & technology program that invites students from throughout the region to spend three years learning Ontario curriculum through the lens of science and technology." However, the school's students were in danger of falling prey to the digital divide that's exacerbated by hardware and software product lifecycles and inadequate funding. + +![Tech Stewardship students working on a computer](https://opensource.com/sites/default/files/u128651/techstewardship_students.jpg "Tech Stewardship students working on a computer") + +Image courtesy of [Affordable Tech for All][6] + +Although there was a school-wide need for access to computers in the classrooms, Andrew and his students discovered that dozens of old computers were being shipped out of the school because they were too old and slow to keep up with the latest proprietary operating systems or function on the school's network. + +Andrew saw this problem as a unique learning opportunity for his students and created the [Tech Stewardship][17] program. He works in partnership with two other teachers, Mike Doiu and Neil Lyons, and some students, who "began experimenting with open source operating systems like [Lubuntu][18] and [CubLinux][19] to help develop a solution to our in-class computer problem," he says. + +The sixth-grade students deployed the reimaged computers into classrooms throughout the school. When they exhausted the school's supply of surplus computers, they sourced more free computers from a local nonprofit organization called [Renewed Computer Technology Ontario][20]. In all, the Tech Stewardship program has provided more than 200 reimaged computers for students to use in classrooms throughout the school. + + +![Tech Stewardship students](https://opensource.com/sites/default/files/u128651/techstewardship_class.jpg "Tech Stewardship students") + +Image courtesy of [Affordable Tech for All][7] + +The Tech Stewardship program is now an elective class for the school's science and technology students in grades six, seven, and eight. Not only are the students learning about computer reimaging, they're also giving back to their local communities through this open source outreach program. + +### A broad impact + +The Tech Stewardship program is linked directly to the school's curriculum, especially in social studies by teaching the [United Nations' Sustainable Development Goals][21] (SDGs). The program is a member of [Teach SDGs][22], and Andrew serves as a Teach SDGs ambassador. Also, as a Google Certified Innovator, Andrew partners with Google and the [EdTechTeam][23], and Tech Stewardship has participated in Ontario's [Bring it Together][24] conference for educational technology. + +Andrew's students also serve as mentors to their fellow students. In one instance, a group of girls taught a grade 3 class about effective use of Google Drive and helped these younger students to make the best use of their Linux computers. Andrew said, "outreach and extension of learning beyond the classroom at Centennial is a major goal of the Tech Stewardship program." + +### What the students say + +Linux and open source are an integral part of the program. A girl named Ashna says, "In grade 6, Mr. Dobbie had shown us how to reimage a computer into Linux to use it for educational purposes. Since then, we have been learning more and growing." Student Shradhaa says, "At the very beginning, we didn't even know how to reimage with Linux. Mr. Dobbie told us to write steps for how to reimage Linux devices, and using those steps we are trying to reimage the computers." + + +![Tech Stewardship student upgrading memory](https://opensource.com/sites/default/files/u128651/techstewardship_upgrading-memory.jpg "Tech Stewardship student upgrading memory") + +Image courtesy of [Affordable Tech for All][8] + +The students were quick to add that Tech Stewardship has become a portal for discussion about being advocates for the change they want to see in the world. Through their hands-on activity, students learn to support the United Nations Sustainable Development goals. They also learn lessons far beyond the curriculum itself. For example, a student named Areez says he has learned how to find other resources, including donations, that allow the project to expand, since the class work upfitting older computers doesn't produce an income stream. + +Another student, Harini, thinks the Tech Stewardship program has demonstrated to other students what is possible and how one small initiative can change the world. After learning about the program, 40 other schools and individuals are reimaging computers with Linux. Harini says, "The more people who use them for educational purposes, the more outstanding the future will become since those educated people will lead out new, amazing lives with jobs." + +Joshua, another student in the program, sees it this way: "I thought of it as just a fun experience, but as it went on, we continued learning and understanding how what we were doing was making such a big impact on the world!" Later, he says, "a school reached out to us and asked us if we could reimage some computers for them. We went and completed the task. Then it continued to grow, as people from Europe came to see how we were fixing broken computers and started doing it when they went back." + +Andrew Dobbie is keen to share his experience with schools and interested individuals. You can contact him on [Twitter][25] or through his [website][26]. + + +### About the author + + [![](https://opensource.com/sites/default/files/styles/profile_pictures/public/donw2-crop.jpg?itok=OqOYd3A8)][27] Don Watkins - Educator, education technology specialist,  entrepreneur, open source advocate. M.A. in Educational Psychology, MSED in Educational Leadership, Linux system administrator, CCNA, virtualization using Virtual Box. Follow me at [@Don_Watkins .][13][More about me][14] + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/1/new-linux-computers-classroom + +作者:[Don Watkins ][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/don-watkins +[1]:https://opensource.com/resources/what-is-linux?intcmp=70160000000h1jYAAQ&utm_source=intcallout&utm_campaign=linuxcontent +[2]:https://opensource.com/resources/what-are-linux-containers?intcmp=70160000000h1jYAAQ&utm_source=intcallout&utm_campaign=linuxcontent +[3]:https://developers.redhat.com/promotions/linux-cheatsheet/?intcmp=70160000000h1jYAAQ&utm_source=intcallout&utm_campaign=linuxcontent +[4]:https://developers.redhat.com/cheat-sheet/advanced-linux-commands-cheatsheet?intcmp=70160000000h1jYAAQ&utm_source=intcallout&utm_campaign=linuxcontent +[5]:https://opensource.com/tags/linux?intcmp=70160000000h1jYAAQ&utm_source=intcallout&utm_campaign=linuxcontent +[6]:https://photos.google.com/share/AF1QipPnm-q9OIQnrzDD4n7oWIBBIE7RQ6BI9lv486RaU5lKBrs88pq3gPKM8VAgY0prkw?key=cS1RdEZ3ZHdXLWp0bUwzMEk3UnFQRkUwbWl1dWhn +[7]:https://photos.google.com/share/AF1QipPnm-q9OIQnrzDD4n7oWIBBIE7RQ6BI9lv486RaU5lKBrs88pq3gPKM8VAgY0prkw?key=cS1RdEZ3ZHdXLWp0bUwzMEk3UnFQRkUwbWl1dWhn +[8]:https://photos.google.com/share/AF1QipPnm-q9OIQnrzDD4n7oWIBBIE7RQ6BI9lv486RaU5lKBrs88pq3gPKM8VAgY0prkw?key=cS1RdEZ3ZHdXLWp0bUwzMEk3UnFQRkUwbWl1dWhn +[9]:https://opensource.com/file/384581 +[10]:https://opensource.com/file/384591 +[11]:https://opensource.com/file/384586 +[12]:https://opensource.com/article/18/1/new-linux-computers-classroom?rate=bK5X7pRc5y9TyY6jzOZeLDW6ehlWmNPXuP38DYsQ-6I +[13]:https://twitter.com/Don_Watkins +[14]:https://opensource.com/users/don-watkins +[15]:https://opensource.com/user/15542/feed +[16]:https://edutrainingcenter.withgoogle.com/certification_innovator +[17]:https://sites.google.com/view/mrdobbie/tech-stewardship +[18]:https://lubuntu.net/ +[19]:https://en.wikipedia.org/wiki/Cub_Linux +[20]:http://www.rcto.ca/ +[21]:http://www.un.org/sustainabledevelopment/sustainable-development-goals/ +[22]:http://www.teachsdgs.org/ +[23]:https://www.edtechteam.com/team/ +[24]:http://bringittogether.ca/ +[25]:https://twitter.com/A_Dobbie11 +[26]:http://bit.ly/linuxresources +[27]:https://opensource.com/users/don-watkins +[28]:https://opensource.com/users/don-watkins +[29]:https://opensource.com/users/don-watkins +[30]:https://opensource.com/article/18/1/new-linux-computers-classroom#comments +[31]:https://twitter.com/A_Dobbie11 +[32]:https://opensource.com/tags/education +[33]:https://opensource.com/tags/linux \ No newline at end of file diff --git a/sources/tech/20180130 Trying Other Go Versions.md b/sources/tech/20180130 Trying Other Go Versions.md new file mode 100644 index 0000000000..731747d19a --- /dev/null +++ b/sources/tech/20180130 Trying Other Go Versions.md @@ -0,0 +1,112 @@ +Trying Other Go Versions +============================================================ + +While I generally use the current release of Go, sometimes I need to try a different version. For example, I need to check that all the examples in my [Guide to JSON][2] work with [both the supported releases of Go][3](1.8.6 and 1.9.3 at time of writing) along with go1.10rc1. + +I primarily use the current version of Go, updating it when new versions are released. I try out other versions as needed following the methods described in this article. + +### Trying Betas and Release Candidates[¶][4] + +When [go1.8beta2 was released][5], a new tool for trying the beta and release candidates was also released that allowed you to `go get` the beta. It allowed you to easily run the beta alongside your Go installation by getting the beta with: + +``` +go get golang.org/x/build/version/go1.8beta2 +``` + +This downloads and builds a small program that will act like the `go` tool for that specific version. The full release can then be downloaded and installed with: + +``` +go1.8beta2 download +``` + +This downloads the release from [https://golang.org/dl][6] and installs it into `$HOME/sdk` or `%USERPROFILE%\sdk`. + +Now you can use `go1.8beta2` as if it were the normal Go command. + +This method works for [all the beta and release candidates][7] released after go1.8beta2. + +### Trying a Specific Release[¶][8] + +While only beta and release candidates are provided, they can easily be adapted to work with any released version. For example, to use go1.9.2: + +``` +package main + +import ( + "golang.org/x/build/version" +) + +func main() { + version.Run("go1.9.2") +} +``` + +Replace `go1.9.2` with the release you want to run and build/install as usual. + +Since the program I use to build my [Guide to JSON][9] calls `go` itself (for each example), I build this as `go` and prepend the directory to my `PATH` so it will use this one instead of my normal version. + +### Trying Any Release[¶][10] + +This small program can be extended so you can specify the release to use instead of having to maintain binaries for each version. + +``` +package main + +import ( + "fmt" + "os" + + "golang.org/x/build/version" +) + +func main() { + if len(os.Args) < 2 { + fmt.Printf("USAGE: %v [commands as normal]\n", + os.Args[0]) + os.Exit(1) + } + + v := os.Args[1] + os.Args = append(os.Args[0:1], os.Args[2:]...) + + version.Run("go" + v) +} +``` + +I have this installed as `gov` and run it like `gov 1.8.6 version`, using the version I want to run. + +### Trying a Source Build (e.g., tip)[¶][11] + +I also use this same infrastructure to manage source builds of Go, such as tip. There’s just a little trick to it: + +* use the directory `$HOME/sdk/go` (e.g., `$HOME/sdk/gotip`) + +* [build as normal][1] + +* `touch $HOME/sdk/go/.unpacked-success` This is an empty file used as a sentinel to indicate the download and unpacking was successful. + +(On Windows, replace `$HOME/sdk` with `%USERPROFILE%\sdk`) + + +-------------------------------------------------------------------------------- + +via: https://pocketgophers.com/trying-other-versions/ + +作者:[Nathan Kerr ][a] +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:nathan@pocketgophers.com +[1]:https://golang.org/doc/install/source +[2]:https://pocketgophers.com/guide-to-json/ +[3]:https://pocketgophers.com/when-should-you-upgrade-go/ +[4]:https://pocketgophers.com/trying-other-versions/#trying-betas-and-release-candidates +[5]:https://groups.google.com/forum/#!topic/golang-announce/LvfYP-Wk1s0 +[6]:https://golang.org/dl +[7]:https://godoc.org/golang.org/x/build/version#pkg-subdirectories +[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 diff --git a/sources/tech/20180130 Use of du - df commands (with examples).md b/sources/tech/20180130 Use of du - df commands (with examples).md new file mode 100644 index 0000000000..ac284b0025 --- /dev/null +++ b/sources/tech/20180130 Use of du - df commands (with examples).md @@ -0,0 +1,112 @@ +translating---geekpi + +Use of du & df commands (with examples) +====== +In this article I will discuss du & df commands. Both du & df commands are important utilities of Linux system & shows disk usage of Linux filesystem. Here we will share usage of both commands with some examples. + +**(Recommended Read:[Files transfer using scp & rsync commands][1])** + + **(Also Read:[Cloning Disks using dd & cat commands for Linux systems][2])** + +### du COMMAND + +du command (short for disk usage) is useful command which is used to find disk usage for files & directories. du command when used with various options provides results in many formats. + +Some of the examples are mentioned below:- + + **1- To find out summary of disk usage for a directory with all its sub-directories** + +``` + $ du /home +``` + +![du command][4] + +Output of the command shows all the files & directories in /home with block size. + +**2- Disk usage with file/directory sizes in human readable format I.e. in kb, mb etc** + +``` + $ du -h /home +``` + +![du command][6] + +**3- Total disk size of a directory** + +``` + $ du -s /home +``` + +![du command][8] + +It will total size of /home directory. + +### df COMMAND + +df command (short for disk filesystem) is used to show disk utilization for a Linux system. + +Some examples are shared below. + + **1- To display information of device name, total blocks, total disk space, used disk space, available disk space and mount points on a file system.** + +``` + $ df +``` + + +![df command][10] + +**2- Information in human readable format** + +``` + $ df -h +``` + +![df command][12] + +Above command displays information in human readable format. + +**3- Display information of a particular partition** + +``` + $ df -hT /etc +``` + +![df command][14] + +Using -hT with a target directory will show information of /etc/ in human readable format. + +Though there are many more options that can be used with du & df commands, but these should get you started. If you don't find what you are looking for here then you can always refer to man pages for the concerned command. + +Also, read my other posts [**HERE**][15] where i have shared some other important & frequently used Linux. + +And as always your comments/queries are really appreciated, so please leave your comments/queries down below & I will get back to you. + + +-------------------------------------------------------------------------------- + +via: http://linuxtechlab.com/du-df-commands-examples/ + +作者:[SHUSAIN][a] +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:http://linuxtechlab.com/author/shsuain/ +[1]:http://linuxtechlab.com/files-transfer-scp-rsync-commands/ +[2]:http://linuxtechlab.com/linux-cloning-disks-using-dd-cat-commands/ +[3]:https://i1.wp.com/linuxtechlab.com/wp-content/plugins/a3-lazy-load/assets/images/lazy_placeholder.gif?resize=453%2C162 +[4]:https://i2.wp.com/linuxtechlab.com/wp-content/uploads/2017/02/du1.jpg?resize=453%2C162 +[5]:https://i1.wp.com/linuxtechlab.com/wp-content/plugins/a3-lazy-load/assets/images/lazy_placeholder.gif?resize=491%2C163 +[6]:https://i1.wp.com/linuxtechlab.com/wp-content/uploads/2017/02/du2.jpg?resize=491%2C163 +[7]:https://i1.wp.com/linuxtechlab.com/wp-content/plugins/a3-lazy-load/assets/images/lazy_placeholder.gif?resize=584%2C61 +[8]:https://i0.wp.com/linuxtechlab.com/wp-content/uploads/2017/02/du3.jpg?resize=584%2C61 +[9]:https://i1.wp.com/linuxtechlab.com/wp-content/plugins/a3-lazy-load/assets/images/lazy_placeholder.gif?resize=638%2C157 +[10]:https://i0.wp.com/linuxtechlab.com/wp-content/uploads/2017/02/df1.jpg?resize=638%2C157 +[11]:https://i1.wp.com/linuxtechlab.com/wp-content/plugins/a3-lazy-load/assets/images/lazy_placeholder.gif?resize=641%2C149 +[12]:https://i0.wp.com/linuxtechlab.com/wp-content/uploads/2017/02/df2.jpg?resize=641%2C149 +[13]:https://i1.wp.com/linuxtechlab.com/wp-content/plugins/a3-lazy-load/assets/images/lazy_placeholder.gif?resize=638%2C62 +[14]:https://i0.wp.com/linuxtechlab.com/wp-content/uploads/2017/02/df3-1.jpg?resize=638%2C62 +[15]:http://linuxtechlab.com/tips-tricks/ diff --git a/sources/tech/20180130 tmux - A Powerful Terminal Multiplexer For Heavy Command-Line Linux User.md b/sources/tech/20180130 tmux - A Powerful Terminal Multiplexer For Heavy Command-Line Linux User.md new file mode 100644 index 0000000000..4adaa7a2bc --- /dev/null +++ b/sources/tech/20180130 tmux - A Powerful Terminal Multiplexer For Heavy Command-Line Linux User.md @@ -0,0 +1,259 @@ +tmux – A Powerful Terminal Multiplexer For Heavy Command-Line Linux User +====== +tmux stands for terminal multiplexer, it allows users to create/enable multiple terminals (vertical & horizontal) in single window, this can be accessed and controlled easily from single window when you are working with different issues. + +It uses a client-server model, which allows you to share sessions between users, also you can attach terminals to a tmux session back. We can easily move or rearrange the virtual console as per the need. Terminal sessions can freely rebound from one virtual console to another. + +tmux depends on libevent and ncurses libraries. tmux offers status-line at the bottom of the screen which display information about your current tmux session suc[]h as current window number, window name, username, hostname, current time, and current date. + +When tmux is started it creates a new session with a single window and displays it on screen. It allows users to create Any number of windows in the same session. + +Many of us says it's similar to screen but i'm not since this offers wide range of configuration options. + +**Make a note:** `Ctrl+b` is the default prefix in tmux so, to perform any action in tumx, you have to type the prefix first then required options. + +**Suggested Read :** [List Of Terminal Emulator For Linux][1] + +### tmux Features + + * Create any number of windows + * Create any number of panes in the single window + * It allows vertical and horizontal splits + * Detach and Re-attach window + * Server-client architecture which allows users to share sessions between users + * tmux offers wide range of configuration hacks + + + +**Suggested Read :** +**(#)** [tmate - Instantly Share Your Terminal Session To Anyone In Seconds][2] +**(#)** [Teleconsole - A Tool To Share Your Terminal Session Instantly To Anyone In Seconds][3] + +### How to Install tmux Command + +tmux command is pre-installed by default in most of the Linux systems. If no, follow the below procedure to get installed. + +For **`Debian/Ubuntu`** , use [APT-GET Command][4] or [APT Command][5] to install tmux. +``` +$ sudo apt install tmux + +``` + +For **`RHEL/CentOS`** , use [YUM Command][6] to install tmux. +``` +$ sudo yum install tmux + +``` + +For **`Fedora`** , use [DNF Command][7] to install tmux. +``` +$ sudo dnf install tmux + +``` + +For **`Arch Linux`** , use [Pacman Command][8] to install tmux. +``` +$ sudo pacman -S tmux + +``` + +For **`openSUSE`** , use [Zypper Command][9] to install tmux. +``` +$ sudo zypper in tmux + +``` + +### How to Use tmux + +kick start the tmux session by running following command on terminal. When tmux is started it creates a new session with a single window and will automatically login to your default shell with your user account. +``` +$ tmux + +``` + +[![][10]![][10]][11] + +You will get similar to above screenshot like us. tmux comes with status bar which display an information's about current sessions details, date, time, etc.,. + +The status bar information's are below: + + * **`0 :`** It is indicating the session number which was created by the tmux server. By default it starts with 0. + * **`0:username@host: :`** 0 is indicating the session number. Username and Hostname which is holding the current window. + * **`~ :`** It is indicating the current directory (We are in the Home directory) + * **`* :`** This indicate that the window is active now. + * **`Hostname :`** This shows fully qualified hostname of the server + * **`Date& Time:`** It shows current date and time + + + +### How to Split Window + +tmux allows users to split window vertically and horizontally. Let 's see how to do that. + +Press `**(Ctrl+b), %**` to split the pane vertically. +[![][10]![][10]][13] + +Press `**(Ctrl+b), "**` to split the pane horizontally. +[![][10]![][10]][14] + +### How to Move Between Panes + +Lets say, we have created few panes and want to move between them. How to do that? If you don 't know how to do, then there is no purpose to use tmux. Use the following control keys to perform the actions. There are many ways to move between panes. + +Press `(Ctrl+b), Left arrow` - To Move Left + +Press `(Ctrl+b), Right arrow` - To Move Right + +Press `(Ctrl+b), Up arrow` - To Move Up + +Press `(Ctrl+b), Down arrow` - To Move Down + +Press `(Ctrl+b), {` - To Move Left + +Press `(Ctrl+b), }` - To Move Right + +Press `(Ctrl+b), o` - Switch to next pane (left-to-right, top-down) + +Press `(Ctrl+b), ;` - Move to the previously active pane. + +For testing purpose, we are going to move between panes. Now, we are in the `pane2` which shows `lsb_release -a` command output. +[![][10]![][10]][15] + +And we are going to move to `pane0` which shows `uname -a` command output. +[![][10]![][10]][16] + +### How to Open/Create New Window + +You can open any number of windows within one terminal. Terminal window can be split vertically & horizontally which is called `panes`. Each pane will contain its own, independently running terminal instance. + +Press `(Ctrl+b), c` to create a new window. + +Press `(Ctrl+b), n` move to the next window. + +Press `(Ctrl+b), p` to move to the previous window. + +Press `(Ctrl+b), (0-9)` to immediately move to a specific window. + +Press `(Ctrl+b), l` Move to the previously selected window. + +I have two windows, first window has three panes which contains operating system distribution information, top command output & kernal information. +[![][10]![][10]][17] + +And second window has two panes which contains Linux distributions logo information. Use the following commands perform the action. +[![][10]![][10]][18] + +Press `(Ctrl+b), w` Choose the current window interactively. +[![][10]![][10]][19] + +### How to Zoom Panes + +You are working in some pane which is very small and you want to zoom it out for further work. To do use the following key binds. + +Currently we have three panes and i'm working in `pane1` which shows system activity using **Top** command and am going to zoom that. +[![][10]![][10]][17] + +When you zoom a pane, it will hide all other panes and display only the zoomed pane in the window. +[![][10]![][10]][20] + +Press `(Ctrl+b), z` to zoom the pane and press it again, to bring the zoomed pane back. + +### Display Pane Information + +To know about pane number and it's size, run the following command. + +Press `(Ctrl+b), q` to briefly display pane indexes. +[![][10]![][10]][21] + +### Display Window Information + +To know about window number, layout size, number of panes associated with the window and it's size, etc., run the following command. + +Just run `tmux list-windows` to view window information. +[![][10]![][10]][22] + +### How to Resize Panes + +You may want to resize the panes to fit your requirement. You have to press `(Ctrl+b), :` then type the following details on the `yellow` color bar in the bottom of the page. +[![][10]![][10]][23] + +In the previous section we have print pane index which shows panes size as well. To test this we are going to increase `10 cells UPward`. See the following output that has increased the pane1 & pane2 size from `55x21` to `55x31`. +[![][10]![][10]][24] + +**Syntax:** `(Ctrl+b), :` then type `resize-pane [options] [cells size]` + +`(Ctrl+b), :` then type `resize-pane -D 10` to resize the current pane Down for 10 cells. + +`(Ctrl+b), :` then type `resize-pane -U 10` to resize the current pane UPward for 10 cells. + +`(Ctrl+b), :` then type `resize-pane -L 10` to resize the current pane Left for 10 cells. + +`(Ctrl+b), :` then type `resize-pane -R 10` to resize the current pane Right for 10 cells. + +### Detaching and Re-attaching tmux Session + +One of the most powerful features of tmux is the ability to detach and reattach session whenever you need. + +Run a long running process and press `Ctrl+b` followed by `d` to detach your tmux session safely by leaving the running process. + +**Suggested Read :** [How To Keep A Process/Command Running After Disconnecting SSH Session][25] + +Now, run a long running process. For demonstration purpose, we are going to move this server backup to another remote server for disaster recovery (DR) purpose. + +You will get similar output like below after detached tmux session. +``` +[detached (from session 0)] + +``` + +Run the following command to list the available tmux sessions. +``` +$ tmux ls +0: 3 windows (created Tue Jan 30 06:17:47 2018) [109x45] + +``` + +Now, re-attach the tmux session using an appropriate session ID as follow. +``` +$ tmux attach -t 0 + +``` + +### How to Close Panes & Window + +Just type `exit` or hit `Ctrl-d` in the corresponding pane to close it. It's similar to terminal close. To close window, press `(Ctrl+b), &`. + +-------------------------------------------------------------------------------- + +via: https://www.2daygeek.com/tmux-a-powerful-terminal-multiplexer-emulator-for-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/category/terminal-emulator/ +[2]:https://www.2daygeek.com/tmate-instantly-share-your-terminal-session-to-anyone-in-seconds/ +[3]:https://www.2daygeek.com/teleconsole-share-terminal-session-instantly-to-anyone-in-seconds/ +[4]:https://www.2daygeek.com/apt-get-apt-cache-command-examples-manage-packages-debian-ubuntu-systems/ +[5]:https://www.2daygeek.com/apt-command-examples-manage-packages-debian-ubuntu-systems/ +[6]:https://www.2daygeek.com/yum-command-examples-manage-packages-rhel-centos-systems/ +[7]:https://www.2daygeek.com/dnf-command-examples-manage-packages-fedora-system/ +[8]:https://www.2daygeek.com/pacman-command-examples-manage-packages-arch-linux-system/ +[9]:https://www.2daygeek.com/zypper-command-examples-manage-packages-opensuse-system/ +[10]:data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7 +[11]:https://www.2daygeek.com/wp-content/uploads/2018/01/tmux-a-powerful-terminal-multiplexer-emulator-for-linux-1.png +[13]:https://www.2daygeek.com/wp-content/uploads/2018/01/tmux-a-powerful-terminal-multiplexer-emulator-for-linux-2.png +[14]:https://www.2daygeek.com/wp-content/uploads/2018/01/tmux-a-powerful-terminal-multiplexer-emulator-for-linux-3.png +[15]:https://www.2daygeek.com/wp-content/uploads/2018/01/tmux-a-powerful-terminal-multiplexer-emulator-for-linux-4.png +[16]:https://www.2daygeek.com/wp-content/uploads/2018/01/tmux-a-powerful-terminal-multiplexer-emulator-for-linux-5.png +[17]:https://www.2daygeek.com/wp-content/uploads/2018/01/tmux-a-powerful-terminal-multiplexer-emulator-for-linux-8.png +[18]:https://www.2daygeek.com/wp-content/uploads/2018/01/tmux-a-powerful-terminal-multiplexer-emulator-for-linux-6.png +[19]:https://www.2daygeek.com/wp-content/uploads/2018/01/tmux-a-powerful-terminal-multiplexer-emulator-for-linux-7.png +[20]:https://www.2daygeek.com/wp-content/uploads/2018/01/tmux-a-powerful-terminal-multiplexer-emulator-for-linux-9.png +[21]:https://www.2daygeek.com/wp-content/uploads/2018/01/tmux-a-powerful-terminal-multiplexer-emulator-for-linux-10.png +[22]:https://www.2daygeek.com/wp-content/uploads/2018/01/tmux-a-powerful-terminal-multiplexer-emulator-for-linux-14.png +[23]:https://www.2daygeek.com/wp-content/uploads/2018/01/tmux-a-powerful-terminal-multiplexer-emulator-for-linux-11.png +[24]:https://www.2daygeek.com/wp-content/uploads/2018/01/tmux-a-powerful-terminal-multiplexer-emulator-for-linux-13.png +[25]:https://www.2daygeek.com/how-to-keep-a-process-command-running-after-disconnecting-ssh-session/ diff --git a/sources/tech/20180131 10 things I love about Vue.md b/sources/tech/20180131 10 things I love about Vue.md new file mode 100644 index 0000000000..55b9007ce1 --- /dev/null +++ b/sources/tech/20180131 10 things I love about Vue.md @@ -0,0 +1,128 @@ +10 things I love about Vue +============================================================ + +![](https://cdn-images-1.medium.com/max/1600/1*X4ipeKVYzmY2M3UPYgUYuA.png) + +I love Vue. When I first looked at it in 2016, perhaps I was coming from a perspective of JavaScript framework fatigue. I’d already had experience with Backbone, Angular, React, among others and I wasn’t overly enthusiastic to try a new framework. It wasn’t until I read a comment on hacker news describing Vue as the ‘new jquery’ of JavaScript, that my curiosity was piqued. Until that point, I had been relatively content with React — it is a good framework based on solid design principles centred around view templates, virtual DOM and reacting to state, and Vue also provides these great things. In this blog post, I aim to explore why Vue is the framework for me. I choose it above any other that I have tried. Perhaps you will agree with some of my points, but at the very least I hope to give you some insight into what it is like to develop modern JavaScript applications with Vue. + +1\. Minimal Template Syntax + +The template syntax which you are given by default from Vue is minimal, succinct and extendable. Like many parts of Vue, it’s easy to not use the standard template syntax and instead use something like JSX (there is even an official page of documentation about how to do this), but I don’t know why you would want to do that to be honest. For all that is good about JSX, there are some valid criticisms: by blurring the line between JavaScript and HTML, it makes it a bit too easy to start writing complex code in your template which should instead be separated out and written elsewhere in your JavaScript view code. + +Vue instead uses standard HTML to write your templates, with a minimal template syntax for simple things such as iteratively creating elements based on the view data. + +``` + + + + + +``` + + +I also like the short-bindings provided by Vue, ‘:’ for binding data variables into your template and ‘@’ for binding to events. It’s a small thing, but it feels nice to type and keeps your components succinct. + +2\. Single File Components + +When most people write Vue, they do so using ‘single file components’. Essentially it is a file with the suffix .vue containing up to 3 parts (the css, html and javascript) for each component. + +This coupling of technologies feels right. It makes it easy to understand each component in a single place. It also has the nice side effect of encouraging you to keep your code short for each component. If the JavaScript, CSS and HTML for your component is taking up too many lines then it might be time to modularise further. + +When it comes to the . + +* Linked stylesheet: We write styles of all the elements in a separate file with .css extension. This file is called Stylesheet. + +Let’s have a look at how we defined the inline style of the “div” until now: + +``` +
+``` + +We can write this same style inside `` like this: + +``` +div{ + width:550px; +} +``` + +In embedded styling, the styles we write are separate from the elements. So we need a way to relate the element and its style. The first word “div” does exactly that. It lets the browser know that whatever style is inside the curly braces `{…}` belongs to the “div” element. Since this phrase determines which element to apply the style to, it’s called a selector. + +The way we write style remains same: property(width) and value(550px) separated by a colon(:) and ended by a semicolon(;). + +Let’s remove inline style from our “div” and “img” element and write it inside the ` +``` + +``` +
+

Bat Letter

+ +

+ After all the battles we faught together, after all the difficult times we saw together, after all the good and bad moments we've been through, I think it's time I let you know how I feel about you. +

+``` + +``` +

You are the light of my life

+

+ You complete my darkness with your light. I love: +

+
    +
  • the way you see good in the worse
  • +
  • the way you handle emotionally difficult situations
  • +
  • the way you look at Justice
  • +
+

+ I have learned a lot from you. You have occupied a special place in my heart over the time. +

+

I have a confession to make

+

+ It feels like my chest does have a heart. You make my heart beat. Your smile brings smile on my face, your pain brings pain to my heart. +

+

+ I don't show my emotions, but I think this man behind the mask is falling for you. +

+

I love you Superman.

+

+ Your not-so-secret-lover,
+ Batman +

+
+``` + +Save and refresh, and the result should remain the same. + +There is one big problem though — what if there is more than one “div” and “img” element in our HTML file? The styles that we defined for div and img inside the “style” element will apply to every div and img on the page. + +If you add another div in your code in the future, then that div will also become 550px wide. We don’t want that. + +We want to apply our styles to the specific div and img that we are using right now. To do this, we need to give our div and img element unique ids. Here’s how you can give an id to an element using its “id” attribute: + +``` +
+``` + +and here’s how to use this id in our embedded style as a selector: + +``` +#letter-container{ + ... +} +``` + +Notice the “#” symbol. It indicates that it is an id, and the styles inside {…} should apply to the element with that specific id only. + +Let’s apply this to our code: + +``` + +``` + +``` +
+

Bat Letter

+ +

+ After all the battles we faught together, after all the difficult times we saw together, after all the good and bad moments we've been through, I think it's time I let you know how I feel about you. +

+``` + +``` +

You are the light of my life

+

+ You complete my darkness with your light. I love: +

+
    +
  • the way you see good in the worse
  • +
  • the way you handle emotionally difficult situations
  • +
  • the way you look at Justice
  • +
+

+ I have learned a lot from you. You have occupied a special place in my heart over the time. +

+

I have a confession to make

+

+ It feels like my chest does have a heart. You make my heart beat. Your smile brings smile on my face, your pain brings pain to my heart. +

+

+ I don't show my emotions, but I think this man behind the mask is falling for you. +

+

I love you Superman.

+

+ Your not-so-secret-lover,
+ Batman +

+
+``` + +Our HTML is ready with embedded styling. + +However, you can see that as we include more styles, the will get bigger. This can quickly clutter our main html file. So let’s go one step further and use linked styling by copying the content inside our style tag to a new file. + +Create a new file in the project root directory and save it as style.css: + +``` +#letter-container{ + width:550px; +} +#header-bat-logo{ + width:100%; +} +``` + +We don’t need to write `` in our CSS file. + +We need to link our newly created CSS file to our HTML file using the ``tag in our html file. Here’s how we can do that: + +``` + +``` + +We use the link element to include external resources inside your HTML document. It is mostly used to link Stylesheets. The three attributes that we are using are: + +* rel: Relation. What relationship the linked file has to the document. The file with the .css extension is called a stylesheet, and so we keep rel=“stylesheet”. + +* type: the Type of the linked file; it’s “text/css” for a CSS file. + +* href: Hypertext Reference. Location of the linked file. + +There is no at the end of the link element. So, is also a self-closing tag. + +``` + +``` + +If only getting a Girlfriend was so easy :D + +Nah, that’s not gonna happen, let’s move on. + +Here’s the content of our loveletter.html: + +``` + +
+

Bat Letter

+ +

+ After all the battles we faught together, after all the difficult times we saw together, after all the good and bad moments we've been through, I think it's time I let you know how I feel about you. +

+

You are the light of my life

+

+ You complete my darkness with your light. I love: +

+
    +
  • the way you see good in the worse
  • +
  • the way you handle emotionally difficult situations
  • +
  • the way you look at Justice
  • +
+

+ I have learned a lot from you. You have occupied a special place in my heart over the time. +

+

I have a confession to make

+

+ It feels like my chest does have a heart. You make my heart beat. Your smile brings smile on my face, your pain brings pain to my heart. +

+

+ I don't show my emotions, but I think this man behind the mask is falling for you. +

+

I love you Superman.

+

+ Your not-so-secret-lover,
+ Batman +

+
+``` + +and our style.css: + +``` +#letter-container{ + width:550px; +} +#header-bat-logo{ + width:100%; +} +``` + +Save both the files and refresh, and your output in the browser should remain the same. + +### A Few Formalities + +Our love letter is almost ready to deliver to Batman, but there are a few formal pieces remaining. + +Like any other programming language, HTML has also gone through many versions since its birth year(1990). The current version of HTML is HTML5. + +So, how would the browser know which version of HTML you are using to code your page? To tell the browser that you are using HTML5, you need to include `` at top of the page. For older versions of HTML, this line used to be different, but you don’t need to learn that because we don’t use them anymore. + +Also, in previous HTML versions, we used to encapsulate the entire document inside `` tag. The entire file was divided into two major sections: Head, inside ``, and Body, inside ``. This is not required in HTML5, but we still do this for compatibility reasons. Let’s update our code with ``, ``, `` and ``: + +``` + + + + + + +
+

Bat Letter

+ +

+ After all the battles we faught together, after all the difficult times we saw together, after all the good and bad moments we've been through, I think it's time I let you know how I feel about you. +

+

You are the light of my life

+

+ You complete my darkness with your light. I love: +

+
    +
  • the way you see good in the worse
  • +
  • the way you handle emotionally difficult situations
  • +
  • the way you look at Justice
  • +
+

+ I have learned a lot from you. You have occupied a special place in my heart over the time. +

+

I have a confession to make

+

+ It feels like my chest does have a heart. You make my heart beat. Your smile brings smile on my face, your pain brings pain to my heart. +

+

+ I don't show my emotions, but I think this man behind the mask is falling for you. +

+

I love you Superman.

+

+ Your not-so-secret-lover,
+ Batman +

+
+ + +``` + +The main content goes inside `` and meta information goes inside ``. So we keep the div inside `` and load the stylesheets inside ``. + +Save and refresh, and your HTML page should display the same as earlier. + +### Title in HTML + +This is the last change. I promise. + +You might have noticed that the title of the tab is displaying the path of the HTML file: + + +![](https://cdn-images-1.medium.com/max/1000/1*PASKm4ji29hbcZXVSP8afg.jpeg) + +We can use `` tag to define a title for our HTML file. The title tag also, like the link tag, goes inside head. Let’s put “Bat Letter” in our title: + +``` +<!DOCTYPE html> +<html> +<head> + <title>Bat Letter + + + +
+

Bat Letter

+ +

+ After all the battles we faught together, after all the difficult times we saw together, after all the good and bad moments we've been through, I think it's time I let you know how I feel about you. +

+

You are the light of my life

+

+ You complete my darkness with your light. I love: +

+
    +
  • the way you see good in the worse
  • +
  • the way you handle emotionally difficult situations
  • +
  • the way you look at Justice
  • +
+

+ I have learned a lot from you. You have occupied a special place in my heart over the time. +

+

I have a confession to make

+

+ It feels like my chest does have a heart. You make my heart beat. Your smile brings smile on my face, your pain brings pain to my heart. +

+

+ I don't show my emotions, but I think this man behind the mask is falling for you. +

+

I love you Superman.

+

+ Your not-so-secret-lover,
+ Batman +

+
+ + +``` + +Save and refresh, and you will see that instead of the file path, “Bat Letter” is now displayed on the tab. + +Batman’s Love Letter is now complete. + +Congratulations! You made Batman’s Love Letter in HTML. + + +![](https://cdn-images-1.medium.com/max/1000/1*qC8qtrYtxAB6cJfm9aVOOQ.jpeg) + +### What we learned + +We learned the following new concepts: + +* The structure of an HTML document + +* How to write elements in HTML (

) + +* How to write styles inside the element using the style attribute (this is called inline styling, avoid this as much as you can) + +* How to write styles of an element inside (this is called embedded styling) + +* How to write styles in a separate file and link to it in HTML using (this is called a linked stylesheet) + +* What is a tag name, attribute, opening tag, and closing tag + +* How to give an id to an element using id attribute + +* Tag selectors and id selectors in CSS + +We learned the following HTML tags: + +*

: for paragraphs + +*
: for line breaks + +*

    ,
  • : to display lists + +*
    : for grouping elements of our letter + +*

    ,

    : for heading and sub heading + +* : to insert an image + +* , : for bold and italic text styling + +*