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,268 | 如何在 Ubuntu 上用 Yocto 创建你自己的嵌入式 Linux 发行版 | https://www.howtoforge.com/tutorial/how-to-create-your-own-linux-distribution-with-yocto-on-ubuntu/ | 2017-03-05T19:35:00 | [
"发行版",
"嵌入式",
"Yocto",
"poky"
] | https://linux.cn/article-8268-1.html | 本文主要聚焦在如何使用 Yocto 在 Ubuntu 上创建一个最小化的 Linux 发行版。Yocto 项目在嵌入式 Linux 的世界非常著名,这是因为它用起来非常灵活、方便。Yocto 的目标是为嵌入式软硬件开发商创建自己的 Linux 发行版。本文我们将会创建一个可以运行在 QEMU 上的最小化的 Linux,并且在 QEMU 上实际运行。

### 开发机的基本条件
* 最少 4-6 GB 内存
* 最新版的 Ubuntu 系统(本文使用了 16.04 LTS)
* 磁盘剩余空间至少 60-80 GB
* 在创建 Linux 发行版之前先安装下面的软件包
* 下载最新的 Yocto(Poky 是其最小开发环境)稳定分支
```
apt-get update
```
```
apt-get install wget git-core unzip make gcc g++ build-essential subversion sed autoconf automake texi2html texinfo coreutils diffstat python-pysqlite2 docbook-utils libsdl1.2-dev libxml-parser-perl libgl1-mesa-dev libglu1-mesa-dev xsltproc desktop-file-utils chrpath groff libtool xterm gawk fop
```

如下所示,开发环境要安装的软件包将近 1GB 大小。

在这个教程中,系统上克隆的是 poky 的 `morty` 稳定分支。
```
git clone -b morty git://git.yoctoproject.org/poky.git
```

进入 `poky` 目录,然后运行下面的命令为 Yocto 开发环境设置(设置/导出)一些环境变量。
```
source oe-init-build-env
```
如下所示,在运行了 open embedded (oe) 的构建环境脚本之后,终端里的路径会自动切换到 `build` 目录,以便进行之后行发行版的的配置和构建。

上面的截屏展示了在 `conf` 目录下创建的文件 `local.conf`。这是 Yocto 用来设置目标机器细节和 SDK 的目标架构的配置文件。
如下所示,这里设置的目标机器是 `qemux86-64`。

如下面截图所示,在 `local.conf` 中取消下面参数的注释符号。
```
DL_DIR ?= "${TOPDIR}/downloads"
```

```
SSTATE_DIR ?= "${TOPDIR}/sstate-cache"
```

```
TMPDIR ?= "${TOPDIR}/tmp"
```

```
PACKAGE_CLASSES ?= "package_rpm"
SDKMACHINE ?= "i686"
```

如下所示,在 `local.conf` 中为基于 Yocto 的 Linux 设置空密码和后续的一些参数。否则的话用户就不能登录进新的发行版。
```
EXTRA_IMAGE_FEATURES ?= "debug-tweaks"
```

我们并不准备使用任何图形化工具来创建 Linux OS,比如 `toaster` (`hob` 已经不再支持了)。
### Yocto 编译构建过程
现在运行下面的 `bitbake` 工具命令开始为选定的目标机器下载和编译软件包。
```
bitbake core-image-minimal
```

**非常重要的是要在普通 Linux 用户下运行上面的命令,而不是使用 root 用户**。如下面截图所示,当你在 root 用户下运行 bitbake 命令会产生下面所示的错误。

再一次运行导出环境变量的脚本(`oe-init-build-env`),重新执行相同的命令来启动下载和编译过程。

如下所示,构建脚本组件的第一步工作是解析配置(`recipe`)。

下面的截图展示了构建脚本的解析过程。同时也显示了用来构建你的新的基于 yocto 的发行版的构建系统的细节。

在下载了 SDK 和必要的库之后,下一步工作是下载并编译软件包。如下截图展示了为构建新发行版而执行的任务。这一步将会执行 2-3 小时,因为首先要下载需要的软件包,然后还要为新的 Linux 发行版编译这些软件包。

下面的截图表明了任务列表执行完毕。

为目标机器类型 `qemux86-64` 编译好的新镜像位于 `build/tmp/deploy/images/qemux86-64`:

如下所示,上面的命令如果运行在 `Putty` 上会产生一个错误。

通过 `rdp` 在 Ubuntu 平台上再次运行上面的命令。

为运行新的基于 Yocto 的 Linux 发行版的 qemu 打开一个新屏幕。

下面展示了新发行版的登录界面,同时也显示了使用的 yocto 项目的版本号。默认的用户名是 `root` ,密码为空。

最后使用 `root` 用户名和空密码登录新发行版。如下截图所示,在这个最小版本的 Linux 上运行了基本的命令(`data` 、 `ifconfig` 和 `uname`)。

本文的目标是理解使用 Yocto 创建新的 Linux 发行版的过程。
---
via: <https://www.howtoforge.com/tutorial/how-to-create-your-own-linux-distribution-with-yocto-on-ubuntu/>
作者:[Ahmad](https://www.howtoforge.com/tutorial/how-to-create-your-own-linux-distribution-with-yocto-on-ubuntu/) 译者:[Ezio](https://github.com/oska874) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 200 | OK | # How to create your own Linux Distribution with Yocto on Ubuntu
In this article, our focus is the creation of a minimal Linux distribution using the Yocto project on the Ubuntu platform. The Yocto project is very famous in the embedded Linux world because of its flexibility and ease of use. The purpose of the Yocto project is to create a Linux distro for manufacturers of embedded hardware and software. A new minimal Linux distro will be created for qemu as the (qemu is a basic software emulator) target machine and we will run it in qemu.
## Prerequisites for the development machine
- At least 4 - 6 GB RAM.
- Recent Ubuntu OS (16.04 LTS in this case).
- At least 60-80 GB free space on the disk.
- Installation of following packages before creation of new Linux distro.
- Download latest Yocto (Poky which is minimal development environment) stable branch.
apt-get update
apt-get install wget git-core unzip make gcc g++ build-essential subversion sed autoconf automake texi2html texinfo coreutils diffstat python-pysqlite2 docbook-utils libsdl1.2-dev libxml-parser-perl libgl1-mesa-dev libglu1-mesa-dev xsltproc desktop-file-utils chrpath groff libtool xterm gawk fop
As shown below, almost 1 GB size is required to install required development packages.
In this tutorial, the "morty" stable release of poky is cloned on the system.
git clone -b morty git://git.yoctoproject.org/poky.git
Go inside the "poky" directory and run the following command to set/export some variables for yocto development.
source oe-init-build-env
As shown below, after running the open embedded (oe) build environment script, the path location in the terminal will be changed to a "build" directory for the further configuration and compilation of new distribution.
The above screenshot shows that the "local.conf" file is created inside the "conf" directory. This is the configuration file for yocto which specifies details of the target machine and SDK for desired architecture etc.
As shown below, setting target machine "qemux86-64".
Uncomment following parameters in "local.conf" file as shown in the screenshots.
DL_DIR ?= "${TOPDIR}/downloads"
SSTATE_DIR ?= "${TOPDIR}/sstate-cache"
TMPDIR ?= "${TOPDIR}/tmp"
PACKAGE_CLASSES ?= "package_rpm"
SDKMACHINE ?= "i686"
As shown below, set a blank password for the Yocto based Linux and include the following parameters in the local.conf file. Otherwise, the user will not be able to login in the new distro.
EXTRA_IMAGE_FEATURES ?= "debug-tweaks"
We are not using any GUI tool such as toaster (hob is no more supported) to create Linux OS.
## Yocto Compilation and Building Process
Now run the following command of the bitbake utility to start the download and compilation of packages for the selected target machine.
bitbake core-image-minimal
It is important to run the above command as a normal Linux user and not the root user. As shown in the following sscreenshot, an error is generated when you run the bitbake command as root user.
Again, run the export of environment variables script (oe-init-build-env) and re-run the same command to start the downloading and compilation process.
As shown below, the first step of build script utility is to parse the recipe.
The following screenshot shows the completion of the parsing step of the build script. It also shows the details of the build system on which the new yocto based distro will be generated.
After downloading the SDK and necessary libraries, the next step is to download and compile the packages. The following screenshot shows the task for the new distribution. This step will take 2-3 hours because first, it downloads the required packages and then compiles for the new Linux distribution.
The following screenshot shows the completion of the task list.
The compiled new images for the target machine type "qemux86-64" is inside the "build/tmp/deploy/images/qemux86-64" path as shown below.
As shown below, above command will produce an error if run in the Putty.
Above command is again run inside the terminal via rdp on Ubuntu platform.
Another screen is opened for the qemu emulator for new yocto based Linux distro.
The login screen of the new distro is shown below which also shows the reference version of the yocto project. The default username is root and a blank password.
Finally, login in the new distro with root username and an empty password. As shown in the following screenshot, basic commands (date,ifconfig and uname) are run in the minimal version of Linux.
The purpose of this article is to understand the procedure for the creation of new Linux distribution using yocto project. |
8,269 | 为何 Linux 安装器需要添加安全功能? | http://www.datamation.com/security/why-linux-installers-need-to-add-security-features.html | 2017-03-06T08:49:00 | [
"安全",
"安装器"
] | https://linux.cn/article-8269-1.html |
>
> 由于安全问题越来越严重,Linux 发行版需要在安装程序中突出显示基本安全选项,而不是让用户稍后手动添加这些选项。
>
>
>

十二年前,Linux 发行版努力使安装变得简单。在 Ubuntu 和 Fedora 的引领下,它们很早就实现了这一目标。现在,随着对安全性越来越关注,它们需要稍微转变下方向,并在安装程序中突出显示基本安全选项,而不是让用户稍后手动添加这些选项。
当然,即便是在最好的情况下,说服用户来设置安全功能都是困难的。太多用户甚至不愿意添加如非特权用户帐户或密码这样简单的功能,他们显然更喜欢用重装或者以每小时 80 美元的价格咨询专家来减少风险。
然而,即便一般用户不会专门注意安全,但他也可能会在安装过程中注意。他们可能永远不会再想到它,但也许在安装过程中,当他们的注意力集中时,特别是如果有可见的在线帮助来解释其好处时,他们可能被说服选择一个复选框。
这种转变也并不伟大。许多安装程序已经提供了自动登录的选择 - 这对于不包含个人数据的安装来说或许是可以接受的功能,但更可能会被那些觉得登录不方便的用户使用。同样感谢 Ubuntu,它选择加密文件系统 - 至少在主目录中是这样 - 它已经成为许多安装程序的标准。我真正建议的也是这样的。
此外,外部安装程序如 Firefox 已经无缝合并了隐私浏览,而 [Signal Private Messenger](https://whispersystems.org/) 则是一个可替代标准 的 Android 手机和联系人的应用程序。
这些建议远不算激进。它只需要意志和想象力来实现它。
### Linux 安全第一步
应该将什么类型的安全功能添加到安装程序呢?
首先是防火墙。有许多图形界面程序可以设置防火墙。尽管十七年的经验,但是就像拜伦对柯尔律治的形而上的思想的讨论一样,我有时还是希望有人能来解释一下。
尽管出于好意,大多数防火墙工具对 iptables 的处理看起来都很直接。有一个现在已经停止维护的加固系统 [Bastille Linux](http://bastille-linux.sourceforge.net/) 可以用于安装一个基本的防火墙,我看不出为什么其他发行版做不到同样的事情。
一些工具可以用于安装后处理,并且对于安装器而言可以毫无困难地添加使用。例如,对于 [Grub 2](https://help.ubuntu.com/community/Grub2/Passwords),这个大多数发行版使用的引导管理器包含了基本密码保护。诚然,密码可以通过 Live CD 绕过,但它仍然在包括远程登录在内的日常情况下提供一定程度的保护。
类似地,一个类似于 [pwgen](http://pwgen-win.sourceforge.net/downloads.html) 的密码生成器也可以添加到安装程序设置帐户的环节。这些工具强制可接受密码的长度、以及它们的大小写字母、数字和特殊字符的组合。它们许多都可以为你生成密码,有些甚至可以使生成的密码可拼读,以便你记住密码。
还有些工具也可以添加到安装过程的这个部分。例如,安装程序可以请求定期备份的计划,并添加一个计划任务和一个类似 [kbackup](http://kbackup.sourceforge.net/) 的简单的备份工具。
那么加密电子邮件怎么办?如今最流行的邮件阅读器包括了加密邮件的能力,但是设置和使用加密需要用户采取额外的设置,这使常见的任务复杂化,以至于用户会忽略它。然而,看看 Signal 在手机上的加密有多么简单,很显然,在笔记本电脑和工作站上加密会更容易。大多数发行版可能都喜欢对等加密,而不喜欢 Signal 那样的集中式服务器,但像 [Ring](https://savannah.gnu.org/projects/ring/) 这样的程序可以提供这种功能。
无论在安装程序中添加了什么功能,也许这些预防措施也可以扩展到生产力软件,如 LibreOffice。大多数安全工作都集中在电子邮件、网络浏览和聊天中,但文字处理程序和电子表格及其宏语言,是一个明显的恶意软件感染的来源和隐私关注点。除了像 [Qubes OS](https://www.qubes-os.org/) 或 [Subgraph](https://subgraph.com/sgos/) 这样的几个例外之外,很少有人努力将生产力软件纳入其安全预防措施 - 这可能会留下一个安全漏洞空缺。
### 适应现代
当然,在意安全的用户也许会采取一些安全的方法,这样的用户可以为自己负责。
我关心的是那些不太了解安全或不太愿意自己做修补的用户。我们越来越需要易于使用的安全性,并且亟待解决。
这些例子只是开始。所需要的工具大多数已经存在,只是需要以这样的方式来实现它们,使得用户不能忽略它们,并且能够不用懂什么就可以使用它们。可能实现所有这些只需要一个人月而已,包括原型、UI 设计和测试等等。
然而,在添加这些功能前,大多数主流的 Linux 发行版几乎不能说是关注到了安全性。毕竟,如果用户从不使用它们,那怎么会是好工具?
---
via: <http://www.datamation.com/security/why-linux-installers-need-to-add-security-features.html>
作者:[Bruce Byfield](http://www.datamation.com/author/Bruce-Byfield-6030.html) 译者:[geekpi](https://github.com/geekpi) 校对:[Bestony](https://github.com/Bestony), [wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
8,270 | 使用 Elizabeth 为应用生成随机样本数据 | https://opensource.com/article/17/2/elizabeth-python-library | 2017-03-06T09:30:00 | [
"Elizabeth",
"随机"
] | /article-8270-1.html |
>
> Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu.
>
>
>
不,我的文章没有被 [Lorem ipsum](https://en.wikipedia.org/wiki/Lorem_ipsum) 生成器劫持(LCTT 译注:Lorem ipsum,中文又称“乱数假文”,只是一段用来测试排版效果的占位文字,没有实际的含义)。作为本月的 Nooks&Crannies 专栏文章,我发现了一个有趣的小 Python 库,以帮助开发人员为其应用程序生成随机数据。它被称为 [Elizabeth](https://github.com/lk-geimfari/elizabeth)。

它由 Líkið Geimfari 编写,并在 MIT 许可证下发行,Elizabeth 以 21 个不同本地化信息提供了 18 种数据提供器,可用于生成随机信息(LCTT 译注:不仅是随机数),包括姓名和个人特征、地址、文本数据、交通信息、网络和 Internet 社交媒体数据、数字等等。安装它需要 [Python 3.2](https://www.python.org/) 或更高版本,您可以使用 `pip` 或从 `git` 仓库安装它。
在我的测试机上,我在一个全新安装的 [Debian](https://www.debian.org/) Jessie 上使用 pip 来安装它,要做的就是 `apt-get install python3-pip`,它将安装 Python 和所需的依赖项。然后 `pip install elizabeth`,之后就安装好了。
只是为好玩,让我们在 Python 的交互式解释器中为一个人生成一些随机数据:
```
>>> from elizabeth import Personal
>>> p=Personal('en')
>>> p.full_name(gender="male")
'Elvis Herring'
>>> p.blood_type()
'B+'
>>> p.credit_card_expiration_date()
'09/17'
>>> p.email(gender='male')
'[email protected]'
>>> p.favorite_music_genre()
'Ambient'
>>> p.identifier(mask='13064########')
'1306420450944'
>>> p.sexual_orientation()
'Heterosexual'
>>> p.work_experience()
39
>>> p.occupation()
'Senior System Designer'
>>>
```
在代码中使用它就像创建一个对象那样,然后调用要你需要填充数据的对应方法。
Elizabeth 内置了 18 种不同的生成工具,添加新的生成器并不困难;你只需要定义从 JSON 值集合中获取数据的例程。以下是一些随机文本字符串生成,再次打开解释器:
```
>>> from elizabeth import Text
>>> t=Text('en')
>>> t.swear_word()
'Rat-fink'
>>> t.quote()
'Let them eat cake.'
>>> t.words(quantity=20)
['securities', 'keeps', 'accessibility', 'barbara', 'represent', 'hentai', 'flower', 'keys', 'rpm', 'queen', 'kingdom', 'posted', 'wearing', 'attend', 'stack', 'interface', 'quite', 'elementary', 'broadcast', 'holland']
>>> t.sentence()
'She spent her earliest years reading classic literature, and writing poetry.'
```
使用 Elizabeth 填充 [SQLite](https://sqlite.org/) 或其它你可能需要用于开发或测试的数据库并不困难。其介绍文档给出了使用 [Flask](https://flask.pocoo.org/) 这个轻量级 web 框架的一个医疗应用程序示例。
我对 Elizabeth 印象很深刻 - 它超快、轻量级、易于扩展,它的社区虽然小,但是很活跃。截至本文写作时,项目已有 25 名贡献者,并且提交的问题处理迅速。Elizabeth 的[完整文档](http://elizabeth.readthedocs.io/en/latest/index.html)至少对于美国英语而言易于阅读和遵循,并提供了广泛的 API 参考。
我曾尝试通过修改链接来查找该文档是否有其他语言,但没有成功。因为其 API 在非英语区域中是不同的,所以记录这些变化将对用户非常有帮助。公平地说,通过阅读其代码并找出可用的方法并不难,即使你的 Python 功力并不深厚。对我来说,另一个明显的缺陷是缺乏阿拉伯语或希伯来语区域测试数据。这些是著名的从右到左的语言,对于试图使其应用程序国际化的开发者来说,适当地处理这些语言是一个主要的障碍。像 Elizabeth 这种在此方面可以协助的工具是值得拥有的。
对于那些在应用中需要随机样本数据的开发员而言,Elizabeth 是一个有价值的工具,而对于那些试图创建真正多语言、本地化应用程序的开发者来说,它可能是一个宝藏。
---
作者简介:
D Ruth Bavousett - D Ruth Bavousett 作为一名系统管理员和软件开发人员已经很长时间了,她的专业生涯开始于 VAX 11/780。在她的职业生涯(迄今为止)中,她在解决图书馆需求上有大量的经验,她自 2008 年以来一直是 Koha 开源图书馆自动化套件的贡献者。Ruth 目前在休斯敦的 cPanel 任 Perl 开发人员,她也作为首席员工效力于双猫公司。
---
via: <https://opensource.com/article/17/2/elizabeth-python-library>
作者:[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,271 | 浅述内核中“挂起到空闲”的实现 | http://www.linaro.org/blog/suspend-to-idle/ | 2017-03-06T11:34:00 | [
"挂起",
"CPU",
"休眠"
] | https://linux.cn/article-8271-1.html | ### 简介
Linux 内核提供了多种睡眠状态,各个状态通过设置系统中的不同部件进入低耗电模式来节约能源。目前总共有四种睡眠状态,分别是:<ruby> 挂起到空闲 <rp> ( </rp> <rt> suspend to idle </rt> <rp> ) </rp></ruby>、<ruby> 加电待机 <rp> ( </rp> <rt> power-on standby(standby) </rt> <rp> ) </rp></ruby>、<ruby> 挂起到内存 <rp> ( </rp> <rt> suspend to ram </rt> <rp> ) </rp></ruby>和<ruby> 挂起到磁盘 <rp> ( </rp> <rt> suspend to disk </rt> <rp> ) </rp></ruby>。这些状态分别对应 ACPI 的 4 种状态:S0,S1,S3 和 S4。<ruby> 挂起到空闲 <rp> ( </rp> <rt> suspend to idle </rt> <rp> ) </rp></ruby>是纯软件实现的,用于将 CPU 维持在尽可能深的 idle 状态。<ruby> 加电待机 <rp> ( </rp> <rt> power-on standby(standby) </rt> <rp> ) </rp></ruby>则使设备处于低功耗状态,并且关闭所有非引导 CPU。<ruby> 挂起到内存 <rp> ( </rp> <rt> suspend to ram </rt> <rp> ) </rp></ruby>就更进一步,关闭所有 CPU 并且设置 RAM 进入自刷新模式。<ruby> 挂起到磁盘 <rp> ( </rp> <rt> suspend to disk </rt> <rp> ) </rp></ruby>则是最省功耗的模式,关闭尽可能多的系统,包括关闭内存。然后内存中的内容会被写到硬盘,待唤醒计算机的时候将硬盘中的内容重新恢复到内存中。

这篇博文主要介绍<ruby> 挂起到空闲 <rp> ( </rp> <rt> suspend to idle </rt> <rp> ) </rp></ruby>的实现。如上所说,它主要通过软件实现。一般平台的挂起过程包括冻结用户空间并将外围设备调至低耗电模式。但是,系统并不是直接关闭和热插拔掉 CPU,而是静静地强制将 CPU 进入<ruby> 空闲 <rp> ( </rp> <rt> idle </rt> <rp> ) </rp></ruby>状态。随着外围设备进入了低耗电模式,除了唤醒相关的中断外不应有其他中断产生。唤醒中断包括那些设置用于唤醒系统的计时器(比如 RTC,普通计时器等)、或者电源开关、USB 和其它外围设备等。
在冻结过程中,当系统进入空闲状态时会调用一个特殊的 cpu 空闲函数。这个 `enter_freeze()` 函数可以和调用使 cpu 空闲的 `enter()` 函数一样简单,也可以复杂得多。该函数复杂的程度由将 SoC 置为低耗电模式的条件和方法决定。
### 先决条件
#### `platform_suspend_ops`
一般情况,为了支持 S2I,系统必须实现 `platform_suspend_ops` 并提供最低限度的挂起支持。这意味着至少要完成 `platform_suspend_ops` 中的 `valid()` 函数。如果<ruby> 挂起到空闲 <rp> ( </rp> <rt> suspend to idle </rt> <rp> ) </rp></ruby>和<ruby> 挂起到内存 <rp> ( </rp> <rt> suspend to ram </rt> <rp> ) </rp></ruby>都要支持,valid 函数中应使用 `suspend_valid_only_mem`。
不过,最近内核增加了对 S2I 的自动支持。Sudeep Holla 提出了一个变更,可以让系统不需要满足 `platform_suspend_ops` 条件也能提供 S2I 支持。这个补丁已经被接收并将合并在 4.9 版本中,该补丁可从这里获取: <https://lkml.org/lkml/2016/8/19/474>。
如果定义了 `suspend_ops`,那么可以通过查看 `/sys/power/state` 文件得知系统具体支持哪些挂起状态。如下操作:
```
# cat /sys/power/state
freeze mem
```
这个示例的结果显示该平台支持 S0(<ruby> 挂起到空闲 <rp> ( </rp> <rt> suspend to idle </rt> <rp> ) </rp></ruby>)和 S3(<ruby> 挂起到内存 <rp> ( </rp> <rt> suspend to ram </rt> <rp> ) </rp></ruby>)。按 Sudeep 的变更,那些没有实现 `platform_suspend_ops` 的平台将只显示 freeze 状态。
#### 唤醒中断
一旦系统处于某种睡眠状态,系统必须要接收某个唤醒事件才能恢复系统。这些唤醒事件一般由系统的设备产生。因此一定要确保这些设备驱动使用唤醒中断,并且将自身配置为接收唤醒中断后产生唤醒事件。如果没有正确识别唤醒设备,系统收到中断后会继续保持睡眠状态而不会恢复。
一旦设备正确实现了唤醒接口的调用,就可用来生成唤醒事件。请确保 DT 文件正确配置了唤醒源。下面是一个配置唤醒源示例,该文件来自(`arch/arm/boot/dst/am335x-evm.dts`):
```
gpio_keys: volume_keys@0 {
compatible = “gpio-keys”;
#address-cells = <1>;
#size-cells = <0>;
autorepeat;
switch@9 {
label = “volume-up”;
linux,code = <115>;
gpios = <&gpio0 2 GPIO_ACTIVE_LOW>;
wakeup-source;
};
switch@10 {
label = “volume-down”;
linux,code = <114>;
gpios = <&gpio0 3 GPIO_ACTIVE_LOW>;
wakeup-source;
};
};
```
如上所示,有两个 gpio 键被配置为唤醒源,在系统挂起期间,其中任何一个键被按下都会产生一个唤醒事件。
可替代 DT 文件配置的另一个唤醒源配置就是设备驱动,如果设备驱动自身在代码里面配置了唤醒支持,那么就会使用该默认唤醒配置。
### 实施
#### 冻结功能
如果系统希望能够充分使用<ruby> 挂起到空闲 <rp> ( </rp> <rt> suspend to idle </rt> <rp> ) </rp></ruby>,那么应该在 CPU 空闲驱动代码中定义 `enter_freeze()` 函数。`enter_freeze()` 与 `enter()` 的函数原型略有不同。因此,不能将 `enter()` 同时指定给 `enter` 和 `enter_freeze`。至少,系统会直接调用 `enter()`。如果没有定义 `enter_freeze()`,系统会挂起,但是不会触发那些只有当 `enter_freeze()` 定义了才会触发的函数,比如 `tick_freeze()` 和 `stop_critical_timing()` 都不会发生。这会导致计时器中断唤醒系统,但不会导致系统恢复,因为系统处理完中断后会继续挂起。
在挂起过程中,中断越少越好(最好一个也没有)。
下图显示了能耗和时间的对比。图中的两个尖刺分别是挂起和恢复。挂起前后的能耗尖刺是系统退出空闲态进行记录操作,进程调度,计时器处理等。因延迟的缘故,系统进入更深层次空闲状态需要花费一段时间。

*能耗使用时序图*
下图为 ftrace 抓取的 4 核 CPU 在系统挂起和恢复操作之前、之中和之后的活动。可以看到,在挂起期间,没有请求或者中断被处理。

*Ftrace 抓取的挂起/恢复活动图*
#### 空闲状态
你必须确定哪个空闲状态支持冻结。在冻结期间,电源相关代码会决定用哪个空闲状态来实现冻结。这个过程是通过在每个空闲状态中查找谁定义了 `enter_freeze()` 来决定的。CPU 空闲驱动代码或者 SoC 挂起相关代码必须确定哪种空闲状态实现冻结操作,并通过给每个 CPU 的可应用空闲状态指定冻结功能来进行配置。
例如, Qualcomm 会在平台挂起代码的挂起初始化函数处定义 `enter_freeze` 函数。这个工作是在 CPU 空闲驱动已经初始化后进行,以便所有结构已经定义就位。
#### 挂起/恢复相关驱动支持
你可能会在第一次成功挂起操作后碰到驱动相关的 bug。很多驱动开发者没有精力完全测试挂起和恢复相关的代码。你甚至可能会发现挂起操作并没有多少工作可做,因为 `pm_runtime` 已经做了你要做的挂起相关的一切工作。由于用户空间已经被冻结,设备此时已经处于休眠状态并且 `pm_runtime` 已经被禁止。
### 测试相关
测试<ruby> 挂起到空闲 <rp> ( </rp> <rt> suspend to idle </rt> <rp> ) </rp></ruby>可以手动进行,也可以使用脚本/进程等实现自动挂起、自动睡眠,或者使用像 Android 中的 `wakelock` 来让系统挂起。如果手动测试,下面的操作会将系统冻结。
```
/ # echo freeze > /sys/power/state
[ 142.580832] PM: Syncing filesystems … done.
[ 142.583977] Freezing user space processes … (elapsed 0.001 seconds) done.
[ 142.591164] Double checking all user space processes after OOM killer disable… (elapsed 0.000 seconds)
[ 142.600444] Freezing remaining freezable tasks … (elapsed 0.001 seconds) done.
[ 142.608073] Suspending console(s) (use no_console_suspend to debug)
[ 142.708787] mmc1: Reset 0x1 never completed.
[ 142.710608] msm_otg 78d9000.phy: USB in low power mode
[ 142.711379] PM: suspend of devices complete after 102.883 msecs
[ 142.712162] PM: late suspend of devices complete after 0.773 msecs
[ 142.712607] PM: noirq suspend of devices complete after 0.438 msecs
< system suspended >
….
< wake irq triggered >
[ 147.700522] PM: noirq resume of devices complete after 0.216 msecs
[ 147.701004] PM: early resume of devices complete after 0.353 msecs
[ 147.701636] msm_otg 78d9000.phy: USB exited from low power mode
[ 147.704492] PM: resume of devices complete after 3.479 msecs
[ 147.835599] Restarting tasks … done.
/ #
```
在上面的例子中,需要注意 MMC 驱动的操作占了 102.883ms 中的 100ms。有些设备驱动在挂起的时候有很多工作要做,比如将数据刷出到硬盘,或者其他耗时的操作等。
如果系统定义了<ruby> 冻结 <rp> ( </rp> <rt> freeze </rt> <rp> ) </rp></ruby>,那么系统将尝试挂起操作,如果没有冻结功能,那么你会看到下面的提示:
```
/ # echo freeze > /sys/power/state
sh: write error: Invalid argument
/ #
```
### 未来的发展
目前在 ARM 平台上的<ruby> 挂起到空闲 <rp> ( </rp> <rt> suspend to idle </rt> <rp> ) </rp></ruby>有两方面的工作需要做。第一方面工作在前面 `platform_suspend_ops` 小节中提到过,是总允许接受冻结状态以及合并到 4.9 版本内核中的工作。另一方面工作是冻结功能的支持。
如果你希望设备有更好的响应及表现,那么应该继续完善冻结功能的实现。然而,由于很多 SoC 会使用 ARM 的 CPU 空闲驱动,这使得 ARM 的 CPU 空闲驱动完善它自己的通用冻结功能的工作更有意义了。而事实上,ARM 正在尝试添加此通用支持。如果 SoC 供应商希望实现他们自己的 CPU 空闲驱动或者需要在进入更深层次的冻结休眠状态时提供额外的支持,那么只有实现自己的冻结功能。
---
via: <http://www.linaro.org/blog/suspend-to-idle/>
作者:[Andy Gross](http://www.linaro.org/author/andygross/) 译者:[beyondworld](https://github.com/beyondworld) 校对:[jasminepeng](https://github.com/jasminepeng)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
8,272 | 安卓编年史(15):安卓 3.0 蜂巢—平板和设计复兴 | http://arstechnica.com/gadgets/2016/10/building-android-a-40000-word-history-of-googles-mobile-os/16/ | 2017-03-07T08:44:00 | [
"安卓编年史"
] | https://linux.cn/article-8272-1.html | 
### 安卓 3.0 蜂巢—平板和设计复兴
尽管姜饼中做了许多改变,安卓仍然是移动世界里的丑小鸭。相比于 iPhone,它的优雅程度和设计完全抬不起头。另一方面来说,为数不多的能与 iOS 的美学智慧相当的操作系统之一是 Palm 的 WebOS。WebOS 有着优秀的整体设计,创新的功能,而且被寄予期望能够从和 iPhone 的长期竞争中拯救公司。
尽管如此,在 WebOS 发布一年之后,Palm 资金链断裂。Palm 公司未曾看到 iPad 的到来(LCTT 译注:原文为 iPhone,根据时间推断,应该是指 2010 年发布的 iPad),到 WebOS 就绪的时候已经太晚了。2010 年 4 月,惠普花费 10 亿美元收购了 Palm。尽管惠普收购了一个拥有优秀用户界面的产品,但界面的首席设计师,Matias Duarte,并没有加入惠普公司。2010 年 5 月,就在惠普接手 Palm 之前,Duarte 加入了谷歌。惠普买下了面包,但谷歌雇佣了它的烘培师。

*第一部蜂巢设备,摩托罗拉 Xoom 10英寸平板。*
在谷歌,Duarte 被任命为安卓用户体验主管。这是第一次有人公开掌管安卓的外观。尽管 Matias 在安卓 2.2 发布时就来到了谷歌,第一个真正受他影响的安卓版本是 3.0 <ruby> 蜂巢 <rp> ( </rp> <rt> Honeycomb </rt> <rp> ) </rp></ruby>,它在 2011 年 2 月发布。
按谷歌自己的说法,蜂巢是匆忙问世的。10 个月前,苹果发布了 iPad,让平板变得更加现代,谷歌希望能够尽快做出回应。蜂巢就是那个回应,一个运行在 10 英寸触摸屏上的安卓版本。悲伤的是,将这个系统推向市场是如此优先的事项,以至于边边角角都被砍去了以节省时间。
新系统只用于平板——手机不能升级到蜂巢,这加大了谷歌让系统运行在差异巨大的不同尺寸屏幕上的难度。但是,仅支持平板而不支持手机也使得蜂巢源码没有泄露。之前的安卓版本是开源的,这使得黑客社区能够将其最新版本移植到所有的不同设备之上。谷歌不希望应用开发者在支持不完美的蜂巢手机移植版本时感到压力,所以谷歌将源码留在自己手中,并且严格控制能够拥有蜂巢的设备。匆忙的开发还导致了软件问题。在发布时,蜂巢不是特别稳定,SD 卡不能工作,Adobe Flash——安卓最大的特色之一——还不被支持。
[摩托罗拉 Xoom](http://arstechnica.com/gadgets/2011/03/ars-reviews-the-motorola-xoom/) 是为数不多的拥有蜂巢的设备之一,它是这个新系统的旗舰产品。Xoom 是一个 10 英寸,16:9 的平板,拥有 1GB 内存和 1GHz Tegra 2 双核处理器。尽管是由谷歌直接控制更新的新版安卓发布设备,它并没有被叫做“Nexus”。对此最可能的原因是谷歌对它没有足够的信心称其为旗舰。
尽管如此,蜂巢是安卓的一个里程碑。在一个体验设计师的主管之下,整个安卓用户界面被重构,绝大多数奇怪的应用设计都得到改进。安卓的默认应用终于看起来像整体的一部分,不同的界面有着相似的布局和主题。然而重新设计安卓会是一个跨越了多个版本的项目——蜂巢只是将安卓塑造成型的开始。这第一稿为未来版本的安卓将如何运作奠定了基础,但它也用了过多的科幻主题,谷歌将花费接下来的数个版本来淡化它。

*蜂巢和姜饼的主屏幕。 [Ron Amadeo供图]*
姜饼只是在它的光子壁纸上试验了科幻外观,蜂巢整个系统的以电子为灵感的主题让它充满科幻意味。所有东西都是黑色的,如果你需要对比色,你可以从一些不同色调的蓝色中挑选。所有蓝色的东西还有“光晕”效果,让整个系统看起来像是外星科技创造的。默认背景是个六边形的全息方阵(一个蜂巢!明白了吗?),看起来像是一艘飞船上的传送阵的地板。
蜂巢最重要的变化是增加了系统栏。摩托罗拉 Xoom 除了电源和音量键之外没有配备实体按键,所以蜂巢添加了一个大黑色底栏到屏幕底部,用于放置导航按键。这意味着默认安卓界面不再需要特别的实体按键。在这之前,安卓没有实体的返回、菜单和 Home 键就不能正常工作。现在,软件提供了所有必需的按钮,任何带有触摸屏的设备都能够运行安卓。
新软件按键带来的最大的好处是灵活性。新的应用指南表明应用不再必需实体菜单按键,需要用到的时候,蜂巢会自动检测并添加四个按钮到系统栏让应用正常工作。另一个软件按键的灵活属性是它们可以改变设备的屏幕方向。除了电源和音量键之外,Xoom 的方向实际上不是那么重要。从用户的角度来看,系统栏始终处于设备的“底部”。代价是系统栏明显占据了一些屏幕空间。为了在10英寸平板上节省空间,状态栏被合并到了系统栏中。所有的常用状态指示放在了右侧——有电源、连接状态、时间还有通知图标。
主屏幕的整个布局都改变了,用户界面部件放在了设备的四个角落。屏幕底部左侧放置着之前讨论过的导航按键,右侧用于状态指示和通知,顶部左侧显示的是文本搜索和语音搜索,右侧有应用抽屉和添加小部件的按钮。

*新锁屏界面和最近应用界面。 [Ron Amadeo供图]*
(因为 Xoom 是一部 [较重] 的 10 英寸,16:9 平板设备,这意味着它主要是横屏使用。虽然大部分应用还支持竖屏模式,但是到目前为止,由于我们的版式限制,我们大部分使用的是竖屏模式的截图。请记住蜂巢的截图来自于 10 英寸的平板,而姜饼的截图来自 3.7 英寸的手机。二者所展现的信息密度是不能直接比较的。)
解锁界面——从菜单按钮到旋转式拨号盘再到滑动解锁——移除了解锁步骤的任何精度要求,它采用了一个环状解锁盘。从中间向任意方向向外滑动就能解锁设备。就像旋转式解锁,这种解锁方式更加符合人体工程学,而不用强迫你的手指完美地遵循一条笔直的解锁路径。
第二张图中略缩图条带是由新增的“最近应用”按钮打开的界面,现在处在返回键和 Home 键旁边。不像姜饼中长按 Home 键显示一组最近应用的图标,蜂巢在屏幕上显示应用图标和略缩图,使得在任务间切换变得更加方便。“最近应用”的灵感明显来自于 Duarte 在 WebOS 中的“卡片式”多任务管理,其使用全屏略缩图来切换任务。这个设计提供和 WebOS 的任务切换一样的易识别体验,但更小的略缩图允许更多的应用一次性显示在屏幕上。
尽管最近应用的实现看起来和你现在的设备很像,这个版本实际上是非常早期的。这个列表不能滚动,这意味着竖屏下只能显示七个应用,横屏下只能显示五个。任何超出范围的应用会从列表中去除。而且你也不能通过滑动略缩图来关闭应用——这只是个静态的列表。
从这里我们可以看到电子灵感影响的完整主题效果:略缩图的周围有蓝色的轮廓以及神秘的光晕。这张截图还展示软件按键的好处——上下文。返回按钮可以关闭略缩图列表,所以这里的箭头指向下方,而不是通常的样子。
---

[Ron Amadeo](http://arstechnica.com/author/ronamadeo) / Ron是Ars Technica的评论编缉,专注于安卓系统和谷歌产品。他总是在追寻新鲜事物,还喜欢拆解事物看看它们到底是怎么运作的。
[@RonAmadeo](https://twitter.com/RonAmadeo)
---
via: <http://arstechnica.com/gadgets/2016/10/building-android-a-40000-word-history-of-googles-mobile-os/16/>
译者:[alim0x](https://github.com/alim0x) 校对:[Bestony](https://github.com/Bestony)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
8,273 | LXD 2.0 系列(十):LXD 和 Juju | https://www.stgraber.org/2016/06/06/lxd-2-0-lxd-and-juju-1012/ | 2017-03-07T06:04:00 | [
"LXD"
] | https://linux.cn/article-8273-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)

### 介绍
Juju 是 Canonical 的服务建模和部署工具。 它支持非常广泛的云服务提供商,使您能够轻松地在任何云上部署任何您想要的服务。
此外,Juju 2.0 还支持 LXD,既适用于本地部署,也适合开发,并且可以在云实例或物理机上共同协作。
本篇文章将关注本地使用,通过一个没有任何Juju经验的LXD用户来体验。
### 要求
本篇文章假设你已经安装了 LXD 2.0 并且配置完毕(看前面的文章),并且是在 Ubuntu 16.04 LTS 上运行的。
### 设置 Juju
第一件事是在 Ubuntu 16.04 上安装 Juju 2.0。这个很简单:
```
stgraber@dakara:~$ sudo apt install juju
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
juju-2.0
Suggested packages:
juju-core
The following NEW packages will be installed:
juju juju-2.0
0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
Need to get 39.7 MB of archives.
After this operation, 269 MB of additional disk space will be used.
Do you want to continue? [Y/n]
Get:1 http://us.archive.ubuntu.com/ubuntu xenial-updates/main amd64 juju-2.0 amd64 2.0~beta7-0ubuntu1.16.04.1 [39.6 MB]
Get:2 http://us.archive.ubuntu.com/ubuntu xenial-updates/main amd64 juju all 2.0~beta7-0ubuntu1.16.04.1 [9,556 B]
Fetched 39.7 MB in 0s (53.4 MB/s)
Selecting previously unselected package juju-2.0.
(Reading database ... 255132 files and directories currently installed.)
Preparing to unpack .../juju-2.0_2.0~beta7-0ubuntu1.16.04.1_amd64.deb ...
Unpacking juju-2.0 (2.0~beta7-0ubuntu1.16.04.1) ...
Selecting previously unselected package juju.
Preparing to unpack .../juju_2.0~beta7-0ubuntu1.16.04.1_all.deb ...
Unpacking juju (2.0~beta7-0ubuntu1.16.04.1) ...
Processing triggers for man-db (2.7.5-1) ...
Setting up juju-2.0 (2.0~beta7-0ubuntu1.16.04.1) ...
Setting up juju (2.0~beta7-0ubuntu1.16.04.1) ...
```
安装完成后,我们可以使用 LXD 启动一个新的“控制器”。这意味着 Juju 不会修改你主机上的任何东西,它会在 LXD 容器中安装它的管理服务。
现在我们创建一个“test”控制器:
```
stgraber@dakara:~$ juju bootstrap localhost test
Creating Juju controller "local.test" on localhost/localhost
Bootstrapping model "admin"
Starting new instance for initial controller
Launching instance
- juju-745d1be3-e93d-41a2-80d4-fbe8714230dd-machine-0
Installing Juju agent on bootstrap instance
Preparing for Juju GUI 2.1.2 release installation
Waiting for address
Attempting to connect to 10.178.150.72:22
Logging to /var/log/cloud-init-output.log on remote host
Running apt-get update
Running apt-get upgrade
Installing package: curl
Installing package: cpu-checker
Installing package: bridge-utils
Installing package: cloud-utils
Installing package: cloud-image-utils
Installing package: tmux
Fetching tools: curl -sSfw 'tools from %{url_effective} downloaded: HTTP %{http_code}; time %{time_total}s; size %{size_download} bytes; speed %{speed_download} bytes/s ' --retry 10 -o $bin/tools.tar.gz <[https://streams.canonical.com/juju/tools/agent/2.0-beta7/juju-2.0-beta7-xenial-amd64.tgz]>
Bootstrapping Juju machine agent
Starting Juju machine agent (jujud-machine-0)
Bootstrap agent installed
Waiting for API to become available: upgrade in progress (upgrade in progress)
Waiting for API to become available: upgrade in progress (upgrade in progress)
Waiting for API to become available: upgrade in progress (upgrade in progress)
Bootstrap complete, local.test now available.
```
这会花费一点时间,这时你可以看到一个正在运行的一个新的 LXD 容器:
```
stgraber@dakara:~$ lxc list juju-
+-----------------------------------------------------+---------+----------------------+------+------------+-----------+
| NAME | STATE | IPV4 | IPV6 | TYPE | SNAPSHOTS |
+-----------------------------------------------------+---------+----------------------+------+------------+-----------+
| juju-745d1be3-e93d-41a2-80d4-fbe8714230dd-machine-0 | RUNNING | 10.178.150.72 (eth0) | | PERSISTENT | 0 |
+-----------------------------------------------------+---------+----------------------+------+------------+-----------+
```
在 Juju 这边,你可以确认它是有响应的,并且还没有服务运行:
```
stgraber@dakara:~$ juju status
[Services]
NAME STATUS EXPOSED CHARM
[Units]
ID WORKLOAD-STATUS JUJU-STATUS VERSION MACHINE PORTS PUBLIC-ADDRESS MESSAGE
[Machines]
ID STATE DNS INS-ID SERIES AZ
```
你也可以在浏览器中访问 Juju 的 GUI 界面:
```
stgraber@dakara:~$ juju gui
Opening the Juju GUI in your browser.
If it does not open, open this URL:
https://10.178.150.72:17070/gui/97fa390d-96ad-44df-8b59-e15fdcfc636b/
```

不过我更倾向使用命令行,因此我会在接下来使用。
### 部署一个 minecraft 服务
让我们先来一个简单的,部署在一个容器中使用一个 Juju 单元的服务。
```
stgraber@dakara:~$ juju deploy cs:trusty/minecraft
Added charm "cs:trusty/minecraft-3" to the model.
Deploying charm "cs:trusty/minecraft-3" with the charm series "trusty".
```
命令返回会很快,然而这不意味着服务已经启动并运行了。你应该使用 `juju status` 来查看:
```
stgraber@dakara:~$ juju status
[Services]
NAME STATUS EXPOSED CHARM
minecraft maintenance false cs:trusty/minecraft-3
[Units]
ID WORKLOAD-STATUS JUJU-STATUS VERSION MACHINE PORTS PUBLIC-ADDRESS MESSAGE
minecraft/1 maintenance executing 2.0-beta7 1 10.178.150.74 (install) Installing java
[Machines]
ID STATE DNS INS-ID SERIES AZ
1 started 10.178.150.74 juju-97fa390d-96ad-44df-8b59-e15fdcfc636b-machine-1 trusty
```
我们可以看到它正在忙于在刚刚创建的 LXD 容器中安装 java。
```
stgraber@dakara:~$ lxc list juju-
+-----------------------------------------------------+---------+----------------------+------+------------+-----------+
| NAME | STATE | IPV4 | IPV6 | TYPE | SNAPSHOTS |
+-----------------------------------------------------+---------+----------------------+------+------------+-----------+
| juju-745d1be3-e93d-41a2-80d4-fbe8714230dd-machine-0 | RUNNING | 10.178.150.72 (eth0) | | PERSISTENT | 0 |
+-----------------------------------------------------+---------+----------------------+------+------------+-----------+
| juju-97fa390d-96ad-44df-8b59-e15fdcfc636b-machine-1 | RUNNING | 10.178.150.74 (eth0) | | PERSISTENT | 0 |
+-----------------------------------------------------+---------+----------------------+------+------------+-----------+
```
过一会之后,如我们所见服务就部署完毕了:
```
stgraber@dakara:~$ juju status
[Services]
NAME STATUS EXPOSED CHARM
minecraft active false cs:trusty/minecraft-3
[Units]
ID WORKLOAD-STATUS JUJU-STATUS VERSION MACHINE PORTS PUBLIC-ADDRESS MESSAGE
minecraft/1 active idle 2.0-beta7 1 25565/tcp 10.178.150.74 Ready
[Machines]
ID STATE DNS INS-ID SERIES AZ
1 started 10.178.150.74 juju-97fa390d-96ad-44df-8b59-e15fdcfc636b-machine-1 trusty
```
这时你就可以启动你的 Minecraft 客户端了,将其指向 10.178.150.74,端口是 25565。现在可以在新的 minecraft 服务器上玩了!
当你不再需要它,只需运行:
```
stgraber@dakara:~$ juju destroy-service minecraft
```
只要等待几秒就好了。
### 部署一个更复杂的 web 应用
Juju 的主要工作是建模复杂的服务,并以可扩展的方式部署它们。
为了更好地展示,让我们部署一个 Juju “组合”。 这个组合是由网站,API,数据库,静态 Web 服务器和反向代理组成的基本 Web 服务。
所以这将扩展到 4 个互联的 LXD 容器。
```
stgraber@dakara:~$ juju deploy cs:~charmers/bundle/web-infrastructure-in-a-box
added charm cs:~hp-discover/trusty/node-app-1
service api deployed (charm cs:~hp-discover/trusty/node-app-1 with the series "trusty" defined by the bundle)
annotations set for service api
added charm cs:trusty/mongodb-3
service mongodb deployed (charm cs:trusty/mongodb-3 with the series "trusty" defined by the bundle)
annotations set for service mongodb
added charm cs:~hp-discover/trusty/nginx-4
service nginx deployed (charm cs:~hp-discover/trusty/nginx-4 with the series "trusty" defined by the bundle)
annotations set for service nginx
added charm cs:~hp-discover/trusty/nginx-proxy-3
service nginx-proxy deployed (charm cs:~hp-discover/trusty/nginx-proxy-3 with the series "trusty" defined by the bundle)
annotations set for service nginx-proxy
added charm cs:~hp-discover/trusty/website-3
service website deployed (charm cs:~hp-discover/trusty/website-3 with the series "trusty" defined by the bundle)
annotations set for service website
related mongodb:database and api:mongodb
related website:nginx-engine and nginx:web-engine
related api:website and nginx-proxy:website
related nginx-proxy:website and website:website
added api/0 unit to new machine
added mongodb/0 unit to new machine
added nginx/0 unit to new machine
added nginx-proxy/0 unit to new machine
deployment of bundle "cs:~charmers/bundle/web-infrastructure-in-a-box-10" completed
```
几秒后,你会看到 LXD 容器在运行了:
```
stgraber@dakara:~$ lxc list juju-
+-----------------------------------------------------+---------+-----------------------+------+------------+-----------+
| NAME | STATE | IPV4 | IPV6 | TYPE | SNAPSHOTS |
+-----------------------------------------------------+---------+-----------------------+------+------------+-----------+
| juju-745d1be3-e93d-41a2-80d4-fbe8714230dd-machine-0 | RUNNING | 10.178.150.72 (eth0) | | PERSISTENT | 0 |
+-----------------------------------------------------+---------+-----------------------+------+------------+-----------+
| juju-97fa390d-96ad-44df-8b59-e15fdcfc636b-machine-2 | RUNNING | 10.178.150.98 (eth0) | | PERSISTENT | 0 |
+-----------------------------------------------------+---------+-----------------------+------+------------+-----------+
| juju-97fa390d-96ad-44df-8b59-e15fdcfc636b-machine-3 | RUNNING | 10.178.150.29 (eth0) | | PERSISTENT | 0 |
+-----------------------------------------------------+---------+-----------------------+------+------------+-----------+
| juju-97fa390d-96ad-44df-8b59-e15fdcfc636b-machine-4 | RUNNING | 10.178.150.202 (eth0) | | PERSISTENT | 0 |
+-----------------------------------------------------+---------+-----------------------+------+------------+-----------+
| juju-97fa390d-96ad-44df-8b59-e15fdcfc636b-machine-5 | RUNNING | 10.178.150.214 (eth0) | | PERSISTENT | 0 |
+-----------------------------------------------------+---------+-----------------------+------+------------+-----------+
```
几分钟后,所有的服务应该部署完毕并运行了:
```
stgraber@dakara:~$ juju status
[Services]
NAME STATUS EXPOSED CHARM
api unknown false cs:~hp-discover/trusty/node-app-1
mongodb unknown false cs:trusty/mongodb-3
nginx unknown false cs:~hp-discover/trusty/nginx-4
nginx-proxy unknown false cs:~hp-discover/trusty/nginx-proxy-3
website false cs:~hp-discover/trusty/website-3
[Relations]
SERVICE1 SERVICE2 RELATION TYPE
api mongodb database regular
api nginx-proxy website regular
mongodb mongodb replica-set peer
nginx website nginx-engine subordinate
nginx-proxy website website regular
[Units]
ID WORKLOAD-STATUS JUJU-STATUS VERSION MACHINE PORTS PUBLIC-ADDRESS MESSAGE
api/0 unknown idle 2.0-beta7 2 8000/tcp 10.178.150.98
mongodb/0 unknown idle 2.0-beta7 3 27017/tcp,27019/tcp,27021/tcp,28017/tcp 10.178.150.29
nginx-proxy/0 unknown idle 2.0-beta7 5 80/tcp 10.178.150.214
nginx/0 unknown idle 2.0-beta7 4 10.178.150.202
website/0 unknown idle 2.0-beta7 10.178.150.202
[Machines]
ID STATE DNS INS-ID SERIES AZ
2 started 10.178.150.98 juju-97fa390d-96ad-44df-8b59-e15fdcfc636b-machine-2 trusty
3 started 10.178.150.29 juju-97fa390d-96ad-44df-8b59-e15fdcfc636b-machine-3 trusty
4 started 10.178.150.202 juju-97fa390d-96ad-44df-8b59-e15fdcfc636b-machine-4 trusty
5 started 10.178.150.214 juju-97fa390d-96ad-44df-8b59-e15fdcfc636b-machine-5 trusty
```
这时你就可以在 80 端口访问 http://10.178.150.214,并且会看到一个 Juju 学院页面。
[](https://www.stgraber.org/wp-content/uploads/2016/06/juju-academy.png)
### 清理所有东西
如果你不需要 Juju 创建的容器并且不在乎下次需要再次启动,最简单的方法是:
```
stgraber@dakara:~$ juju destroy-controller test --destroy-all-models
WARNING! This command will destroy the "local.test" controller.
This includes all machines, services, data and other resources.
Continue [y/N]? y
Destroying controller
Waiting for hosted model resources to be reclaimed
Waiting on 1 model, 4 machines, 5 services
Waiting on 1 model, 4 machines, 5 services
Waiting on 1 model, 4 machines, 5 services
Waiting on 1 model, 4 machines, 5 services
Waiting on 1 model, 4 machines, 5 services
Waiting on 1 model, 4 machines, 5 services
Waiting on 1 model, 4 machines
Waiting on 1 model, 4 machines
Waiting on 1 model, 4 machines
Waiting on 1 model, 4 machines
Waiting on 1 model, 4 machines
Waiting on 1 model, 4 machines
Waiting on 1 model, 2 machines
Waiting on 1 model
Waiting on 1 model
All hosted models reclaimed, cleaning up controller machines
```
我们用下面的方式确认:
```
stgraber@dakara:~$ lxc list juju-
+------+-------+------+------+------+-----------+
| NAME | STATE | IPV4 | IPV6 | TYPE | SNAPSHOTS |
+------+-------+------+------+------+-----------+
```
### 总结
Juju 2.0 内置的 LXD 支持使得可以用一种非常干净的方式来测试各种服务。
在 Juju charm store 中有很多预制的“组合”可以用来部署,甚至可以用多个“charm”来组合你想要的架构。
Juju 与 LXD 是一个完美的解决方案,从一个小的 Web 服务到大规模的基础设施都可以简单开发,这些都在你自己的机器上,并且不会在你的系统上造成混乱!
### 额外信息
Juju 网站: http://www.ubuntu.com/cloud/juju
Juju charm store : https://jujucharms.com
LXD 的主站在: https://linuxcontainers.org/lxd
LXD 的 GitHub 仓库: https://github.com/lxc/lxd
LXD 的邮件列表: https://lists.linuxcontainers.org
LXD 的 IRC 频道: #lxcontainers on irc.freenode.net
如果你不想或者不能在你的机器上安装 LXD ,你可以在 web 上试试[在线版的 LXD](https://linuxcontainers.org/lxd/try-it)。
---
作者简介:我是 Stéphane Graber。我是 LXC 和 LXD 项目的领导者,目前在加拿大魁北克蒙特利尔的家所在的Canonical 有限公司担任 LXD 的技术主管。
---
via: <https://www.stgraber.org/2016/06/06/lxd-2-0-lxd-and-juju-1012/>
作者:[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,274 | LXD 2.0 系列(十一):LXD 和 OpenStack | https://www.stgraber.org/2016/10/26/lxd-2-0-lxd-and-openstack-1112/ | 2017-03-08T10:27:00 | [
"OpenStack",
"LXD",
"conjure-up"
] | https://linux.cn/article-8274-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)

### 介绍
首先对这次的延期抱歉。为了让一切正常我花了很长时间。我第一次尝试是使用 devstack 时遇到了一些必须解决问题。 然而即使这样,我还是不能够使网络正常。
我终于放弃了 devstack,并使用用户友好的 Juju 尝试使用 “conjure-up” 部署完整的 Ubuntu OpenStack。它终于工作了!
下面是如何运行一个完整的 OpenStack,使用 LXD 容器而不是 VM,并在 LXD 容器中运行所有这些(嵌套的!)。
### 要求
这篇文章假设你有一个可以工作的 LXD 设置,提供容器网络访问,并且你有一个非常强大的 CPU,大约 50GB 给容器空间和至少 16G B的内存。
记住,我们在这里运行一个完整的 OpenStack,这东西不是很轻量!
### 设置容器
OpenStack 由大量不同做不同事情的组件组成。 一些需要一些额外的特权,为了可以使设置更简单,我们将使用特权容器。
我们将配置支持嵌套的容器,预加载所有需要的内核模块,并允许它访问 `/dev/mem`(显然是需要的)。
请注意,这意味着 LXD 容器的大部分安全特性对该容器被禁用。 然而由 OpenStack 自身产生的容器将是无特权的,并且可以正常使用 LXD 的安全特性。
```
lxc launch ubuntu:16.04 openstack -c security.privileged=true -c security.nesting=true -c "linux.kernel_modules=iptable_nat, ip6table_nat, ebtables, openvswitch"
lxc config device add openstack mem unix-char path=/dev/mem
```
LXD 中有一个小 bug,它会尝试加载已经加载到主机上的内核模块。这已在LXD 2.5中得到修复,并将在LXD 2.0.6 中修复,但在此之前,可以使用以下方法:
```
lxc exec openstack -- ln -s /bin/true /usr/local/bin/modprobe
```
我们需要加几条 PPA 并安装 conjure-up,它是我们用来安装 OpenStack 的部署工具。
```
lxc exec openstack -- apt-add-repository ppa:conjure-up/next -y
lxc exec openstack -- apt-add-repository ppa:juju/stable -y
lxc exec openstack -- apt update
lxc exec openstack -- apt dist-upgrade -y
lxc exec openstack -- apt install conjure-up -y
```
最后一步是在容器内部配置 LXD 网络。
所有问题都选择默认,除了:
* 使用 `dir` 存储后端( `zfs` 不在嵌套容器中用)
* 不要配置 IPv6 网络(conjure-up/juju 不太兼容它)
```
lxc exec openstack -- lxd init
```
现在配置完容器了,现在我们部署 OpenStack!
### 用 conjure-up 部署 OpenStack
如先前提到的,我们用 conjure-up 部署 OpenStack。
这是一个很棒的用户友好的可以与 Juju 交互来部署复杂服务的工具。
首先:
```
lxc exec openstack -- sudo -u ubuntu -i conjure-up
```
* 选择 “OpenStack with NovaLXD”
* 选择 “localhost” 作为部署目标(使用 LXD)
* 点击 “Deploy all remaining applications”
接下来会部署 OpenStack。整个过程会花费一个多小时,这取决于你运行的机器。你将看到所有服务会被分配一个容器,然后部署并最终互连。

部署完成后会显示一个安装完成的界面。它会导入一些初始镜像、设置 SSH 权限、配置网络最后会显示面板的 IP 地址。
### 访问面板并生成一个容器
面板运行在一个容器中,因此你不能直接从浏览器中访问。
最简单的方法是设置一条 NAT 规则:
```
lxc exec openstack -- iptables -t nat -A PREROUTING -p tcp --dport 80 -j DNAT --to <IP>
```
其中 `<ip>` 是 conjure-up 在安装结束时给你的面板 IP 地址。
你现在可以获取 “openstack” 容器的 IP 地址(来自 `lxc info openstack`),并将浏览器指向:http://<container ip>/horizon 。
第一次加载可能需要几分钟。 一旦显示了登录界面,输入默认登录名和密码(admin/openstack),你就会看到OpenStack的欢迎面板!

现在可以选择左边的 “Project” 选项卡,进入 “Instances” 页面。 要启动一个使用 nova-lxd 的新实例,点击 “Launch instance”,选择你想要的镜像,网络等,接着你的实例就产生了。
一旦它运行后,你可以为它分配一个浮动 IP,它将允许你从你的 “openstack” 容器中访问你的实例。
### 总结
OpenStack 是一个非常复杂的软件,你也不会想在家里或在单个服务器上运行它。 但是,不管怎样在你的机器上包含这些服务在一个容器中都是非常有趣的。
conjure-up 是部署这种复杂软件的一个很好的工具,背后使用 Juju 驱动部署,为每个单独的服务使用 LXD 容器,最后是实例本身。
它也是少数几个容器嵌套多层并实际上有意义的情况之一!
### 额外信息
conjure-up 网站: <http://conjure-up.io>
Juju 网站: <http://www.ubuntu.com/cloud/juju>
LXD 的主站在: <https://linuxcontainers.org/lxd>
LXD 的 GitHub 仓库: <https://github.com/lxc/lxd>
LXD 的邮件列表: <https://lists.linuxcontainers.org>
LXD 的 IRC 频道: #lxcontainers on irc.freenode.net
如果你不想或者不能在你的机器上安装 LXD ,你可以在 web 上试试在线版的 LXD。
---
作者简介:我是 Stéphane Graber。我是 LXC 和 LXD 项目的领导者,目前在加拿大魁北克蒙特利尔的家所在的 Canonical 有限公司担任 LXD 的技术主管。
---
via: <https://www.stgraber.org/2016/10/26/lxd-2-0-lxd-and-openstack-1112/>
作者:[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,275 | Git 中的那些可怕的事 | https://www.linux.com/news/event/LinuxCon-Europe/2016/terrible-ideas-git-0 | 2017-03-07T11:13:00 | [
"Git"
] | https://linux.cn/article-8275-1.html | 
在 LinuxCon 北美会议上 FutureAdvisor 的 Corey Quinn 说:“Git 的确让你可以做一些超级强大的事。‘强大’,在这次讲演中,这是一种对愚蠢的委婉说法”。在使用 Git 时,谁没有经历让你感觉自己像个傻子的时刻?当然,Git 是很棒的,每个人都在使用它,你可以用几个基本命令完成你的大部分工作。但它也有一些强大的功能,让我们觉得我们不知道我们在做什么。
但这真的对我们来说不公平。没有人会知道一切,每个人知道的都不同。Quinn 提醒我们:“在我许多讲演的问答部分,人们有时举手说:“嗯,我有一个傻问题。” 你看到人们在那里说:“是啊!这是一个非常愚蠢的问题”。但是当他们得到答案时,那些这么说的人也正在低头记笔记。
Quinn 在演讲的开始做了一些有趣的演示,演示了一些你可以用 Git 做到的可怕的事情,例如变基主干然后进行强制推送来搞乱整个项目、胡乱输入一些命令让 git 吐槽、提交大型二进制文件等。然后他演示了如何使这些可怕的事情不怎么可怕,如更加明智地管理大型二进制文件。“你可以提交大型二进制文件,你可以在 Git 中暴力提交,如果你需要存储大的二进制文件,这里有两个工具会可以加速载入,一个是 git-annex,这是由 Debian 开发人员 Joey Hess 开发的,而 git-lfs 是由 GitHub 支持的。”
你经常同样地错误输入么?例如,当你想要 `git status` 时却输入 `git stitis`?Quinn 有一个方案:“Git 有内置的别名支持,所以你可以将相对较长、复杂的东西命名为一个短的 Git 命令。” 此外,你还可以使用 shell 别名。
Quinn 说:“我们都听说过变基主干然后强制推送这样的搞笑恶作剧,它会改变版本历史,突然发生的事情让所有人都措手不及,每个人都被卷入了这种混乱当中。一群鲸鱼被称为“pod”,一群乌鸦中被称为“谋杀”,一群开发者被称为“合并冲突”……更严重的是,如果有人干了这种事情,你有几个选择。包括从备份中恢复主干,还原提交;或者把责任人从屋顶上尖叫着扔下去。或者,采取一定的预防措施并使用一个并不知名的 Git 功能称为分支保护。启用分支保护后,无法删除或强制推送分支,并且在接受前,<ruby> 拉取请求 <rp> ( </rp> <rt> pull request </rt> <rp> ) </rp></ruby>必须至少有一个审核。”
Quinn 演示了几个更奇妙的有用的工具,使 Git 更高效和万无一失,如 mr、vcsh 和定制的 shell 提示。你可以在下面看到完整的视频,了解更多有趣的事情。
---
via: <https://www.linux.com/news/event/LinuxCon-Europe/2016/terrible-ideas-git-0>
作者:[CARLA SCHRODER](https://www.linux.com/users/cschroder) 译者:[geekpi](https://github.com/geekpi) 校对:[Bestony](https://github.com/Bestony)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
8,278 | sudo 入门指南 | https://www.howtoforge.com/tutorial/sudo-beginners-guide/ | 2017-03-08T07:40:00 | [
"sudo",
"su"
] | https://linux.cn/article-8278-1.html | 
你在使用 Linux 命令行时曾经得到过“<ruby> 拒绝访问 <rp> ( </rp> <rt> Permission denied </rt> <rp> ) </rp></ruby>”的错误提示吗?这可能是因为你正在尝试执行一个需要 root 权限的操作。例如,下面的截图展示了当我尝试复制一个二进制文件到一个系统目录时产生的错误。

那么该怎么解决这个错误?很简单,使用 `sudo` 命令。

用户运行此命令后会被提示输入他们(**自己**)的登录密码。一旦输入了正确的密码,操作将会成功执行。
毫无疑问,`sudo` 是任何在 Linux 上使用命令行的人都必须知道的命令。但是,为了更负责、更有效地使用该命令,你还是要知道一些相关(及深入)的细节。这正是我们将会在这篇文章中讨论的。
*在我们继续之前,值得提一下的是,这篇文章所提到的所有命令指示都已经在 Ubuntu 14.04 LTS 下的 4.3.11 版 Bash 下通过测试。*
### 什么是 sudo
正如你们大部分人所知道的,`sudo` 用来执行需要提升权限(通常是作为 root 用户)的命令。在这篇文章之前的简介部分已经讨论过这样的一个例子。然而,如果你想的话,你能用 `sudo` 以其它(非 root )用户运行命令。
这是由工具提供的 `-u` 命令行选项所实现的。举个例子,如下例所展示的那样,我(`himanshu`)尝试将一个在其他用户(`howtoforge`)的 Home 目录中的文件重命名,但是得到一个“访问拒绝”的错误。然后我加上 `sudo -u howtoforge` 后用同样的“mv”命令,命令成功执行了:

### 任何人都能用 sudo 吗?
不是。一个用户要能使用 `sudo` ,应该在 `/etc/sudoers` 文件里有一条跟该用户相关的信息。下述摘自 Ubuntu 网站的一段能讲得更清楚:
>
> `/etc/sudoers` 文件控制了谁能以哪个用户的身份在哪个机器上运行什么命令,还可以控制特别的情况,例如对于特定的命令是否需要输入密码。这个文件由<ruby> 别名 <rt> aliases </rt></ruby>(基本变量)和<ruby> 用户标识 <rt> user specifications </rt></ruby>(控制谁能运行什么命令)组成。
>
>
>
如果你正在使用 Ubuntu,让一个用户能运行 `sudo` 命令很容易:你所需要做的就是把账户类型改成<ruby> 管理员 <rt> administrator </rt></ruby>。这可直接在 <ruby> 系统设置 <rt> System Settings </rt></ruby> -> <ruby> 用户账户 <rt> User Accounts </rt></ruby>里完成。

首先解锁该窗口:

然后选择你想改变用户类型的用户,然后将类型改成<ruby> 管理员 <rt> administrator </rt></ruby>。

然而,如果你不使用 Ubuntu,或者你的发行版没有提供这个特性,你可以手动编辑 `/etc/sudoers` 文件来实现此改变。要在文件中添加这样的一行:
```
[user] ALL=(ALL:ALL) ALL
```
无需赘言,`[user]` 应该用你想提升 sudo 权限的用户的用户名所代替。在这里值得提到的一件重要的事情是,官方建议通过 `visudo` 命令编辑该文件 —— 你需要做的就是运行下述命令:
```
sudo visudo
```
为了说清究竟是怎么一回事,这里有段从 `visudo` 手册里的摘要:
>
> `visudo` 以安全的模式编辑 `sudoers` 文件。`visudo` 锁定 `sudoers` 文件以防多个编辑同时进行,提供基本的检查(sanity checks)和语法错误检查。如果 `sudoers` 文件现在正在被编辑,你将会收到一个信息提示稍后再试。
>
>
>
关于 visudo 的更多信息,前往[这里](https://www.sudo.ws/man/1.8.17/visudo.man.html)。
### 什么是 sudo 会话
如果你经常使用 `sudo` 命令,你肯定注意到过当你成功输入一次密码后,可以不用输入密码再运行几次 `sudo` 命令。但是一段时间后,`sudo` 命令会再次要求你的密码。
这种现象跟运行 `sudo` 命令数目无关,跟时间有关。是的,`sudo` 默认在输入一次密码后 15 分钟内不会再次要求密码。15 分钟后,你会再次被要求输入密码。
然而,如果你想的话,你能改变这种现象。用以下命令打开 `/etc/sudoers` 文件:
```
sudo visudo
```
找到这一行:
```
Defaults env_reset
```

然后在这行最后添加以下变量:
```
Defaults env_reset,timestamp_timeout=[new-value]
```
`[new-value]` 为想要 `sudo` 会话持续的时间数。例如,设数值为 40。

如果你希望每次使用 `sudo` 命令时都要求输入密码,你可以把这个变量赋值为 0 。想要 `sudo` 会话永远不过时,应赋值为 -1。
注意将 `timestamp_timeout` 的值赋为 “-1” 是强烈不推荐的。
### sudo 密码
你可能注意过,当 `sudo` 要求输入密码然后你开始输入时,不会显示任何东西 —— 甚至连常规的星号都没有。虽然这不是什么大问题,不过一些用户就是希望显示星号。
好消息是那有可能也很容易做到。所有你需要做的就是在 `/etc/sudoers` 文件里将下述的行:
```
Defaults env_reset
```
改成
```
Defaults env_reset,pwfeedback
```
然后保存文件。
现在,无论什么时候输入 `sudo` 密码,星号都会显示。

### 一些重要的 sudo 命令行参数
除了 `-u` 命令行参数(我们已经在这篇教程的开始部分讨论过了),还有其他重要的 `sudo` 命令行参数值得注意。在这部分,我们将会讨论其中一些。
#### -k 参数
考虑下这种情况:输入密码后你刚刚运行了几个 `sudo` 驱动的命令。现在,如你所知,sudo 会话默认保持 15 分钟。假设在这会话期间,你需要让某些人访问你的终端,但你不想让他们可以使用 `sudo` ,你将会怎么做?
还好,有 `-k` 命令行参数允许用户取消 `sudo` 权限。这是 `sudo` <ruby> 帮助页面 <rp> ( </rp> <rt> man page </rt> <rp> ) </rp></ruby>对此的解释:
>
> `-k`, `--reset-timestamp`
>
>
> 不带任何命令使用时,撤销用户缓存的凭据。换句话讲,下一次使用 `sudo` 将会要求输入密码。使用这个参数不需要密码,也可以放到一个 `.logout` 文件中来撤销 sudo 权限。
>
>
> 当与一个命令,或者一个可能需要密码的操作一起用时,这个参数将会导致 `sudo` 忽略用户缓存的凭据。结果是 `sudo` 要求输入密码(如果这是被安全策略所要求的),而且不会更新用户缓存的凭据。
>
>
>
#### -s 参数
有时你的工作要求你运行一堆需要 root 权限的命令,你不想每次都输入密码。你也不想通过改变 `/etc/sudoers` 文件调整 `sudo` 会话的过期时限。
这种情况下,你可以用 `sudo` 的 `-s` 参数。这是 `sudo` 帮助页面对此的解释:
>
> `-s`, `--shell`
>
>
> 如果设置了 SHELL 环境变量或者调用用户的密码数据库指定了 shell,就运行该 shell 。如果指定了命令,命令将会通过 shell 的 `-c` 参数将命令传递给该 shell 执行。如果没有指定命令,会执行一个交互式 shell。
>
>
>
所以,基本上这命令参数做的是:
* 启动一个新的 shell - 至于是哪一个 shell,参照 SHELL 环境变量赋值。如果 `$SHELL` 是空的,将会用 `/etc/passwd` 中定义的 shell。
* 如果你用 `-s` 参数传递了一个命令名(例如 `sudo -s whoami`),实际执行的是 `sudo /bin/bash -c whoami`。
* 如果你没有尝试执行其他命令(也就是说,你只是要运行 `sudo -s`),你将会得到一个有 root 权限的交互式的 shell。
请记住,`-s` 命令行参数给你一个有 root 权限的 shell,但那不是 root 环境 —— 还是执行的你自己的 `.bashrc` 。例如,在 `sudo -s` 运行的新 shell 里,执行 `whoami` 命令仍会返回你的用户名,而非 root 。
#### -i 参数
`-i` 参数跟我们讨论过的 `-s` 参数相像。然而,还是有点区别。一个重要的区别是 `-i` 给你的是 root 环境,意味着你的(用户的)`.bashrc` 被忽略。这就像没有显式地用 root 登录也能成为 root 。此外,你也不用输入 root 用户密码。
**重要**:请注意 `su` 命令也能让你切换用户(默认切换到 root )。这个命令需要你输入 root 密码。为了避免这一点,你可以使用 `sudo` 执行它(`sudo su`),这样你只需要输入你的登录密码。然而,`su` 和 `sudo su` 有隐含的区别 —— 要了解它们,以及它们和 `sudo -i` 的区别,请看[这里](http://unix.stackexchange.com/questions/98531/difference-between-sudo-i-and-sudo-su) 。
### 总结
我希望现在你至少知道了 `sudo` 的基本知识,以及如何调整 `sudo` 的默认行为。请按我们解释过的那样去尝试调整 `/etc/sudoers` 。同时也浏览一下论坛讨论来更深入了解 `sudo` 命令。
---
via: <https://www.howtoforge.com/tutorial/sudo-beginners-guide/>
作者:[Himanshu Arora](https://www.howtoforge.com/tutorial/sudo-beginners-guide/) 译者:[ypingcn](https://ypingcn.github.io/wiki/lctt) 校对:[jasminepeng](https://github.com/jasminepeng)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
8,279 | 哪个 Linux 系统最适合玩游戏? | http://news.softpedia.com/news/the-best-operating-system-for-linux-gaming-which-one-do-you-use-and-why-512861.shtml | 2017-03-08T09:13:00 | [
"游戏"
] | https://linux.cn/article-8279-1.html |
>
> 告诉我们哪个 Linux 发行版对游戏支持的最好
>
>
>
在过去几个月中,出于游戏目的,我们尝试了多种 GNU/Linux 发行版,我们得出的结论是没有专为 Linux 游戏设计的完美的操作系统。

我们都知道,游戏世界分成 Nvidia 和 AMD 两个阵营。现在,如果你使用的是 Nvidia 显卡,即使是五年前的一块显卡,也可以在大多数基于 Linux 的操作系统上使用,因为 Nvidia 差不多为其所有的 GPU 都提供了最新的视频驱动程序。
当然,这意味着如果你有一块 Nvidia GPU,在大多数 GNU/Linux 发行版上你不会有什么大问题。至少与游戏中的图形或其他性能问题无关,这种问题将严重影响你的游戏体验。
### AMD Radeon 用户最好的游戏发行版
如果你使用 AMD Radeon GPU,事情会是完全不同的。我们都知道,AMD 的专有显卡驱动程序仍然需要大量的工作来兼容最新的 GNU/Linux 发行版本。所有的 AMD GPU ,即便是在最新的 X.Org 服务端和 Linux 内核版本上都是这样。
目前,AMDGPU-PRO 视频驱动程序只能在 Ubuntu 16.04 LTS、CentOS 6.8/7.3、Red Hat Enterprise Linux 6.8/7.3、SUSE Linux Enterprise Desktop 和 Server 12 SP2 上运行。除了 Ubuntu 16.04 LTS 之外,我们不知道为什么 AMD 为所有这些面向服务器和企业级的操作系统提供支持。
我们不相信有 Linux 玩家会在这些系统上面玩游戏。[最新的 AMDGPU-PRO 更新](http://news.softpedia.com/news/amdgpu-pro-16-60-linux-driver-finally-adds-amd-radeon-hd-7xxx-8xxx-support-512280.shtml)终于支持了 HD 7xxx 和 8xxx 系列的 AMD Radeon GPU,但是如果我们不想使用 Ubuntu 16.04 LTS 呢?
另外,我们有 Mesa 3D 图形库,这在大多数发行版上都有。Mesa 图形栈为我们的 AMD GPU 提供了功能强大的开源 Radeon 和 AMDGPU 驱动程序,但是为了享受最好的游戏体验,你还需要拥有最新的 X.Org 服务端和 Linux 内核。
并不是所有的 Linux 操作系统都附带最新的 Mesa(13.0)、X.Org 服务端(1.19)和 Linux 内核(4.9)版本,它们支持较旧的 AMD GPU。有些系统只有其中一两种技术,但我们这些都需要,而且内核需要编译进 AMD Radeon Southern Islands 和 Sea Island 驱动来支持 AMDGPU。
我们发现整个情况相当令人沮丧,至少对于一些使用 AMD Radeon 老式显卡的玩家来说是这样的。现在,我们发现,使用 AMD Radeon HD 8xxx GPU 的最佳游戏体验只能通过使用 Git 获取到的 Mesa 17 以及 Linux 内核 4.10 RC 来实现。
所以我们现在请求你 - 如果你找到了玩游戏的完美的 GNU/Linux 发行版,无论你使用的是 AMD Radeon 还是 Nvidia GPU,但我们最感兴趣的是那些使用 AMD GPU 的玩家,请告知我们你使用的是什么发行版,设置是什么,能不能玩最新的游戏,或者有无体验问题。谢谢!
---
via: <http://news.softpedia.com/news/the-best-operating-system-for-linux-gaming-which-one-do-you-use-and-why-512861.shtml>
作者:[Marius Nestor](http://news.softpedia.com/editors/browse/marius-nestor) 译者:[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,282 | LXD 2.0 系列(十二):调试,及给 LXD 做贡献 | https://stgraber.org/2017/02/27/lxd-2-0-debugging-and-contributing-to-lxd-1212/ | 2017-03-09T08:50:00 | [
"LXD"
] | https://linux.cn/article-8282-1.html | ### 介绍
终于要结束了!这个大约一年前开始的这系列文章的最后一篇博文。
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 相当长的时间了,并且非常熟悉它的日常操作和功能。
但如果出现问题怎么办?你可以做什么来自己跟踪问题?如果你不能,你应该记录什么信息,以便上游可以跟踪问题?
如果你想自己解决问题或通过实现你需要的功能来帮助改善LXD怎么办?如何构建,测试和贡献 LXD 代码库?
### 调试 LXD 并填写 bug 报告
#### LXD 日志文件
`/var/log/lxd/lxd.log`:
这是 LXD 日志的主文件。为了避免它快速充满你的磁盘,默认只会记录 `INFO`、`WARNING` 或者 `ERROR` 级别的日志。你可以在 LXD 守护进程中使用 `–debug` 改变其行为。
`/var/log/lxd/CONTAINER/lxc.conf`:
每当你启动容器时,此文件将更新为传递给 LXC 的配置。
这里会展示容器将如何配置,包括其所有的设备、绑定挂载等等。
`/var/log/lxd/CONTAINER/forkexec.log`:
这个文件包含 LXC 命令执行失败时产生的错误。这个情况是非常罕见的,因为 LXD 通常会在发生之前处理大多数错误。
`/var/log/lxd/CONTAINER/forkstart.log`:
这个文件包含 LXC 在启动容器时的错误信息。含 LXC 命令执行失败时产生的错误。
#### CRIU 日志 (对于实时迁移)
如果使用 CRIU 进行容器实时迁移或实时快照,则每次生成 CRIU 转储或恢复转储时都会记录额外的日志文件。
这些日志也可以在 `/var/log/lxd/CONTAINER/` 中找到,并且有时间戳,以便你可以找到与你最近的操作所匹配的那些日志。它们包含 CRIU 转储和恢复的所有内容的详细记录,并且比典型的迁移/快照错误消息更容器理解。
#### LXD 调试消息
如上所述,你可以使用 `-debug` 选项将守护进程切换为执行调试日志记录。另一种方法是连接到守护进程的事件接口,它将显示所有日志条目,而不管配置的日志级别(即使是远程工作)。
举例说,对于 `lxc init ubuntu:16.04 xen` 来说,
`lxd.log` 会是这样:
```
INFO[02-24|18:14:09] Starting container action=start created=2017-02-24T23:11:45+0000 ephemeral=false name=xen stateful=false used=1970-01-01T00:00:00+0000
INFO[02-24|18:14:10] Started container action=start created=2017-02-24T23:11:45+0000 ephemeral=false name=xen stateful=false used=1970-01-01T00:00:00+0000
```
而 `lxc monitor –type=logging` 会是:
```
metadata:
context: {}
level: dbug
message: 'New events listener: 9b725741-ffe7-4bfc-8d3e-fe620fc6e00a'
timestamp: 2017-02-24T18:14:01.025989062-05:00
type: logging
metadata:
context:
ip: '@'
method: GET
url: /1.0
level: dbug
message: handling
timestamp: 2017-02-24T18:14:09.341283344-05:00
type: logging
metadata:
context:
driver: storage/zfs
level: dbug
message: StorageCoreInit
timestamp: 2017-02-24T18:14:09.341536477-05:00
type: logging
metadata:
context:
ip: '@'
method: GET
url: /1.0/containers/xen
level: dbug
message: handling
timestamp: 2017-02-24T18:14:09.347709394-05:00
type: logging
metadata:
context:
ip: '@'
method: PUT
url: /1.0/containers/xen/state
level: dbug
message: handling
timestamp: 2017-02-24T18:14:09.357046302-05:00
type: logging
metadata:
context: {}
level: dbug
message: 'New task operation: 2e2cf904-c4c4-4693-881f-57897d602ad3'
timestamp: 2017-02-24T18:14:09.358387853-05:00
type: logging
metadata:
context: {}
level: dbug
message: 'Started task operation: 2e2cf904-c4c4-4693-881f-57897d602ad3'
timestamp: 2017-02-24T18:14:09.358578599-05:00
type: logging
metadata:
context:
ip: '@'
method: GET
url: /1.0/operations/2e2cf904-c4c4-4693-881f-57897d602ad3/wait
level: dbug
message: handling
timestamp: 2017-02-24T18:14:09.366213106-05:00
type: logging
metadata:
context:
driver: storage/zfs
level: dbug
message: StoragePoolInit
timestamp: 2017-02-24T18:14:09.369636451-05:00
type: logging
metadata:
context:
driver: storage/zfs
level: dbug
message: StoragePoolCheck
timestamp: 2017-02-24T18:14:09.369771164-05:00
type: logging
metadata:
context:
container: xen
driver: storage/zfs
level: dbug
message: ContainerMount
timestamp: 2017-02-24T18:14:09.424696767-05:00
type: logging
metadata:
context:
driver: storage/zfs
name: xen
level: dbug
message: ContainerUmount
timestamp: 2017-02-24T18:14:09.432723719-05:00
type: logging
metadata:
context:
container: xen
driver: storage/zfs
level: dbug
message: ContainerMount
timestamp: 2017-02-24T18:14:09.721067917-05:00
type: logging
metadata:
context:
action: start
created: 2017-02-24 23:11:45 +0000 UTC
ephemeral: "false"
name: xen
stateful: "false"
used: 1970-01-01 00:00:00 +0000 UTC
level: info
message: Starting container
timestamp: 2017-02-24T18:14:09.749808518-05:00
type: logging
metadata:
context:
ip: '@'
method: GET
url: /1.0
level: dbug
message: handling
timestamp: 2017-02-24T18:14:09.792551375-05:00
type: logging
metadata:
context:
driver: storage/zfs
level: dbug
message: StorageCoreInit
timestamp: 2017-02-24T18:14:09.792961032-05:00
type: logging
metadata:
context:
ip: '@'
method: GET
url: /internal/containers/23/onstart
level: dbug
message: handling
timestamp: 2017-02-24T18:14:09.800803501-05:00
type: logging
metadata:
context:
driver: storage/zfs
level: dbug
message: StoragePoolInit
timestamp: 2017-02-24T18:14:09.803190248-05:00
type: logging
metadata:
context:
driver: storage/zfs
level: dbug
message: StoragePoolCheck
timestamp: 2017-02-24T18:14:09.803251188-05:00
type: logging
metadata:
context:
container: xen
driver: storage/zfs
level: dbug
message: ContainerMount
timestamp: 2017-02-24T18:14:09.803306055-05:00
type: logging
metadata:
context: {}
level: dbug
message: 'Scheduler: container xen started: re-balancing'
timestamp: 2017-02-24T18:14:09.965080432-05:00
type: logging
metadata:
context:
action: start
created: 2017-02-24 23:11:45 +0000 UTC
ephemeral: "false"
name: xen
stateful: "false"
used: 1970-01-01 00:00:00 +0000 UTC
level: info
message: Started container
timestamp: 2017-02-24T18:14:10.162965059-05:00
type: logging
metadata:
context: {}
level: dbug
message: 'Success for task operation: 2e2cf904-c4c4-4693-881f-57897d602ad3'
timestamp: 2017-02-24T18:14:10.163072893-05:00
type: logging
```
`lxc monitor` 的格式有点不同于每个条目都缩合成一行的日志文件,但更重要的是,你可以看到所有 `level:dbug` 条目。
### 如何报告 bug
#### LXD 的 bug
最好报告 bug 的地方是 <https://github.com/lxc/lxd/issues>。确保完整填写了 bug 报告模板中的内容,这些信息可以节省我们我们时间来复现环境。
#### Ubuntu 的 bug
如果你发现 Ubuntu 包本身有问题,无法安装、升级或删除。或者遇到 LXD init 脚本的问题。报告此类错误的最好是在 Launchpad 上。
在 Ubuntu 系统上,你可以使用:`ubuntu-bug lxd` ,它将自动包括一些日志文件和包信息供我们查看。
#### CRIU 的 bug
与 CRIU 相关的 Bug,你可以通过 CRIU 的错误输出发现,你应该在 Launchpad 上报告这些:`ubuntu-bug criu`
请注意,通过 LXD 使用 CRIU 属于测试版功能,除非你愿意通过 Canonical 的支持合同付费支持,要么可能需要一段时间才能查看你的错误报告。
### 贡献给 LXD
LXD 用 [Go](https://golang.org/) 写成并[托管在 Github](https://github.com/lxc/lxd)。我们欢迎任外部的贡献。为 LXD 贡献不需要 CLA 或类似的法律协议签署,只是通常的开发者所有权证书(`Signed-off-by:` 行)。
在我们的问题追踪器工具中,我们列有许多潜在的功能需求,新的贡献者可以以此作为良好的起点。通常最好在开始处理代码先发出 issue,这样每个人都知道你正在做这项工作,以便我们可以提供一些早期反馈。
#### 从源码源码构建 LXD
这里有上游的维护说明:<https://github.com/lxc/lxd#building-from-source>
你需要在 Github 上 fork 上游仓库,然后将你的更改推送到你的分支。我们建议每天 rebase 上游的 LXD,因为我们倾向于定期合并更改。
#### 运行测试套件
LXD 维护了两套测试集,单元测试和集成测试。你可以用下面的命令测试所有:
```
sudo -E make check
```
要只运行单元测试,使用:
```
sudo -E go test ./...
```
要运行集成测试,使用:
```
cd test
sudo -E ./main.sh
```
后者支持相当多的环境变量来测试各种存储后端、禁用网络测试、使用 ramdisk 或只是调整日志输出。其中一些是:
* `LXD_BACKEND`:`btrfs`、`dir`、`lvm` 或 `zfs`” 之一(默认为 `dir`)
运行 LXD 存储驱动程序相关的所有测试。
* `LXD_CONCURRENT`:`true` 或 `false`(默认为 `false`)
这启用一些额外的并发测试。
* `LXD_DEBUG`:`true` 或 `false`(默认为 `false`)
记录所有 shell 命令,并在调试模式下运行所有 LXD 命令。
* `LXD_INSPECT`:`true` 或 `false`(默认为 `false`)
测试程序会在故障时挂起,以便你可以检查环境。
* `LXD_LOGS`:将所有 `LXD` 日志文件转储到的目录(默认为 “”)
所有生成的 LXD 守护进程的 `logs` 目录将被复制到此路径。
* `LXD_OFFLINE`:`true` 或 `false`(默认为 `false`)
禁用任何依赖于外部网络连接的测试。
* `LXD_TEST_IMAGE`: unified 格式的 LXD 镜像的路径(默认为 “”)
可以使用自定义测试镜像,而不是默认的最小 busybox 镜像。
* `LXD_TMPFS`:`true` 或 `false`(默认为 `false`)
在 `tmpfs` 安装中运行整个测试套件,这会使用相当多的内存,但会使测试速度明显更快。
* `LXD_VERBOSE`:`true` 或 `false`(默认为 `false`)
不太极端的 `LXD_DEBUG` 版本。shell 命令仍然会记录,但 `-debug` 不会传递给 LXC 命令,LXD 守护进程只能使用 `-verbose` 运行。
测试程序将在实际运行之前提醒你任何缺失的依赖项。在相当快的机器上运行该测试可在 10 分钟内完成。
#### 发送你的分支
发送拉取请求(PR)之前,你需要确认:
* 你已经 rebase 了上游分支
* 你的所有提交信息都包括 `Signed-off-by: First Last <email>` 这行
* 已删除任何你的临时调试代码
* 你已经将相关的提交 squash 在一起,以保持你的分支容易审查
* 单元和集成测试全部通过
一切完成后,在 Github 上发起一个拉取请求。我们的 [Jenkins](https://jenkins.linuxcontainers.org/) 将验证提交是否全部有 `signed-off`,在 MacOS 和 Windows 上的测试将自动执行,如果看起来不错,我们将触发一个完整的 Jenkins 测试,它将在所有存储后端、32 位和 64 位以及我们关心的所有 Go 版本上测试你的分支。
假设我们有人触发了 Jenkins,这通常需要不到一个小时的时间。
一旦所有测试完成,我们对代码本身感到满意,你的分支将会被合并,你的代码会出现在下一个 LXD 发布中。如果更改适用于 LXD stable-2.0 分支,我们将为你向后移植。
### 总结
我希望这个系列的博客文章有助于你了解什么是 LXD,以及它可以做什么!
本系列的范围仅限于 LXD(2.0.x),但我们也为那些想要最新功能的用户提供每月功能版本。你可以找到一些其他涵盖了原来的 [LXD 2.0系列文章](https://stgraber.org/2016/03/11/lxd-2-0-blog-post-series-012/)中列出的功能的博客文章。
### 额外的信息
LXD 的主站在: <https://linuxcontainers.org/lxd>
LXD 的 GitHub 开发仓库: <https://github.com/lxc/lxd>
LXD 的邮件列表: [https://lists.linuxcontainers.org](https://lists.linuxcontainers.org/)
LXD 的 IRC 频道:#lxcontainers on irc.freenode.net
在线尝试 LXD: <https://linuxcontainers.org/lxd/try-it>
---
作者简介:我是 Stéphane Graber。我是 LXC 和 LXD 项目的领导者,目前在加拿大魁北克蒙特利尔的家所在的 Canonical 有限公司担任 LXD 的技术主管。
---
via: <https://stgraber.org/2017/02/27/lxd-2-0-debugging-and-contributing-to-lxd-1212/>
作者:[Stéphane Graber](https://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 twelfth and last blog post in [this series about LXD 2.0](https://www.stgraber.org/2016/03/11/lxd-2-0-blog-post-series-012/).
# Introduction
This is finally it! The last blog post in this [series of 12](https://stgraber.org/2016/03/11/lxd-2-0-blog-post-series-012/) that started almost a year ago.
If you followed the series from the beginning, you should have been using LXD for quite a bit of time now and be pretty familiar with its day to day operation and capabilities.
But what if something goes wrong? What can you do to track down the problem yourself? And if you can’t, what information should you record so that upstream can track down the problem?
And what if you want to fix issues yourself or help improve LXD by implementing the features you need? How do you build, test and contribute to the LXD code base?
# Debugging LXD & filing bug reports
## LXD log files
### /var/log/lxd/lxd.log
This is the main LXD log file. To avoid filling up your disk very quickly, only log messages marked as INFO, WARNING or ERROR are recorded there by default. You can change that behavior by passing “–debug” to the LXD daemon.
### /var/log/lxd/CONTAINER/lxc.conf
Whenever you start a container, this file is updated with the configuration that’s passed to LXC.
This shows exactly how the container will be configured, including all its devices, bind-mounts, …
### /var/log/lxd/CONTAINER/forkexec.log
This file will contain errors coming from LXC when failing to execute a command.
It’s extremely rare for anything to end up in there as LXD usually handles errors much before that.
### /var/log/lxd/CONTAINER/forkstart.log
This file will contain errors coming from LXC when starting the container.
It’s extremely rare for anything to end up in there as LXD usually handles errors much before that.
## CRIU logs (for live migration)
If you are using CRIU for container live migration or live snapshotting there are additional log files recorded every time a CRIU dump is generated or a dump is restored.
Those logs can also be found in /var/log/lxd/CONTAINER/ and are timestamped so that you can find whichever matches your most recent attempt. They will contain a detailed record of everything that’s dumped and restored by CRIU and are far better for understanding a failure than the typical migration/snapshot error message.
## LXD debug messages
As mentioned above, you can switch the daemon to doing debug logging with the –debug option.
An alternative to that is to connect to the daemon’s event interface which will show you all log entries, regardless of the configured log level (even works remotely).
An example for “lxc init ubuntu:16.04 xen” would be:
**lxd.log:**
INFO[02-24|18:14:09] Starting container action=start created=2017-02-24T23:11:45+0000 ephemeral=false name=xen stateful=false used=1970-01-01T00:00:00+0000 INFO[02-24|18:14:10] Started container action=start created=2017-02-24T23:11:45+0000 ephemeral=false name=xen stateful=false used=1970-01-01T00:00:00+0000
**lxc monitor –type=logging:**
metadata: context: {} level: dbug message: 'New events listener: 9b725741-ffe7-4bfc-8d3e-fe620fc6e00a' timestamp: 2017-02-24T18:14:01.025989062-05:00 type: logging metadata: context: ip: '@' method: GET url: /1.0 level: dbug message: handling timestamp: 2017-02-24T18:14:09.341283344-05:00 type: logging metadata: context: driver: storage/zfs level: dbug message: StorageCoreInit timestamp: 2017-02-24T18:14:09.341536477-05:00 type: logging metadata: context: ip: '@' method: GET url: /1.0/containers/xen level: dbug message: handling timestamp: 2017-02-24T18:14:09.347709394-05:00 type: logging metadata: context: ip: '@' method: PUT url: /1.0/containers/xen/state level: dbug message: handling timestamp: 2017-02-24T18:14:09.357046302-05:00 type: logging metadata: context: {} level: dbug message: 'New task operation: 2e2cf904-c4c4-4693-881f-57897d602ad3' timestamp: 2017-02-24T18:14:09.358387853-05:00 type: logging metadata: context: {} level: dbug message: 'Started task operation: 2e2cf904-c4c4-4693-881f-57897d602ad3' timestamp: 2017-02-24T18:14:09.358578599-05:00 type: logging metadata: context: ip: '@' method: GET url: /1.0/operations/2e2cf904-c4c4-4693-881f-57897d602ad3/wait level: dbug message: handling timestamp: 2017-02-24T18:14:09.366213106-05:00 type: logging metadata: context: driver: storage/zfs level: dbug message: StoragePoolInit timestamp: 2017-02-24T18:14:09.369636451-05:00 type: logging metadata: context: driver: storage/zfs level: dbug message: StoragePoolCheck timestamp: 2017-02-24T18:14:09.369771164-05:00 type: logging metadata: context: container: xen driver: storage/zfs level: dbug message: ContainerMount timestamp: 2017-02-24T18:14:09.424696767-05:00 type: logging metadata: context: driver: storage/zfs name: xen level: dbug message: ContainerUmount timestamp: 2017-02-24T18:14:09.432723719-05:00 type: logging metadata: context: container: xen driver: storage/zfs level: dbug message: ContainerMount timestamp: 2017-02-24T18:14:09.721067917-05:00 type: logging metadata: context: action: start created: 2017-02-24 23:11:45 +0000 UTC ephemeral: "false" name: xen stateful: "false" used: 1970-01-01 00:00:00 +0000 UTC level: info message: Starting container timestamp: 2017-02-24T18:14:09.749808518-05:00 type: logging metadata: context: ip: '@' method: GET url: /1.0 level: dbug message: handling timestamp: 2017-02-24T18:14:09.792551375-05:00 type: logging metadata: context: driver: storage/zfs level: dbug message: StorageCoreInit timestamp: 2017-02-24T18:14:09.792961032-05:00 type: logging metadata: context: ip: '@' method: GET url: /internal/containers/23/onstart level: dbug message: handling timestamp: 2017-02-24T18:14:09.800803501-05:00 type: logging metadata: context: driver: storage/zfs level: dbug message: StoragePoolInit timestamp: 2017-02-24T18:14:09.803190248-05:00 type: logging metadata: context: driver: storage/zfs level: dbug message: StoragePoolCheck timestamp: 2017-02-24T18:14:09.803251188-05:00 type: logging metadata: context: container: xen driver: storage/zfs level: dbug message: ContainerMount timestamp: 2017-02-24T18:14:09.803306055-05:00 type: logging metadata: context: {} level: dbug message: 'Scheduler: container xen started: re-balancing' timestamp: 2017-02-24T18:14:09.965080432-05:00 type: logging metadata: context: action: start created: 2017-02-24 23:11:45 +0000 UTC ephemeral: "false" name: xen stateful: "false" used: 1970-01-01 00:00:00 +0000 UTC level: info message: Started container timestamp: 2017-02-24T18:14:10.162965059-05:00 type: logging metadata: context: {} level: dbug message: 'Success for task operation: 2e2cf904-c4c4-4693-881f-57897d602ad3' timestamp: 2017-02-24T18:14:10.163072893-05:00 type: logging
The format from “lxc monitor” is a bit different from what you’d get in a log file where each entry is condense into a single line, but more importantly you see all those “level: dbug” entries
## Where to report bugs
### LXD bugs
The best place to report LXD bugs is upstream at [https://github.com/lxc/lxd/issues](https://github.com/lxc/lxd/issues).
Make sure to fill in everything in the bug reporting template as that information saves us a lot of back and forth to reproduce your environment.
### Ubuntu bugs
If you find a problem with the Ubuntu package itself, failing to install, upgrade or remove. Or run into issues with the LXD init scripts. The best place to report such bugs is on Launchpad.
On an Ubuntu system, you can do so with: ubuntu-bug lxd
This will automatically include a number of log files and package information for us to look at.
### CRIU bugs
Bugs that are related to CRIU which you can spot by the usually pretty visible CRIU error output should be reported on Launchpad with: ubuntu-bug criu
Do note that the use of CRIU through LXD is considered to be a beta feature and unless you are willing to pay for support through a support contract with Canonical, it may take a while before we get to look at your bug report.
# Contributing to LXD
LXD is written in [Go](https://golang.org) and [hosted on Github](https://github.com/lxc/lxd).
We welcome external contributions of any size. There is no CLA or similar legal agreement to sign to contribute to LXD, just the usual Developer Certificate of Ownership (Signed-off-by: line).
We have a number of potential features listed on our issue tracker that can make good starting points for new contributors. It’s usually best to first file an issue before starting to work on code, just so everyone knows that you’re doing that work and so we can give some early feedback.
## Building LXD from source
Upstream maintains up to date instructions here: [https://github.com/lxc/lxd#building-from-source](https://github.com/lxc/lxd#building-from-source)
You’ll want to fork the upstream repository on Github and then push your changes to your branch. We recommend rebasing on upstream LXD daily as we do tend to merge changes pretty regularly.
## Running the testsuite
LXD maintains two sets of tests. Unit tests and integration tests. You can run all of them with:
sudo -E make check
To run the unit tests only, use:
sudo -E go test ./...
To run the integration tests, use:
cd test sudo -E ./main.sh
That latter one supports quite a number of environment variables to test various storage backends, disable network tests, use a ramdisk or just tweak log output. Some of those are:
- LXD_BACKEND: One of “btrfs”, “dir”, “lvm” or “zfs” (defaults to “dir”)
Lets your run the whole testsuite with any of the LXD storage drivers. - LXD_CONCURRENT: “true” or “false” (defaults to “false”)
This enables a few extra concurrency tests. - LXD_DEBUG: “true” or “false” (defaults to “false”)
This will log all shell commands and run all LXD commands in debug mode. - LXD_INSPECT: “true” or “false” (defaults to “false”)
This will cause the testsuite to hang on failure so you can inspect the environment. - LXD_LOGS: A directory to dump all LXD log files into (defaults to “”)
The “logs” directory of all spawned LXD daemons will be copied over to this path. - LXD_OFFLINE: “true” or “false” (defaults to “false”)
Disables any test which relies on outside network connectivity. - LXD_TEST_IMAGE: path to a LXD image in the unified format (defaults to “”)
Lets you use a custom test image rather than the default minimal busybox image. - LXD_TMPFS: “true” or “false” (defaults to “false”)
Runs the whole testsuite within a “tmpfs” mount, this can use quite a bit of memory but makes the testsuite significantly faster. - LXD_VERBOSE: “true” or “false” (defaults to “false”)
A less extreme version of LXD_DEBUG. Shell commands are still logged but –debug isn’t passed to the LXC commands and the LXD daemon only runs with –verbose.
The testsuite will alert you to any missing dependency before it actually runs. A test run on a reasonably fast machine can be done under 10 minutes.
## Sending your branch
Before sending a pull request, you’ll want to confirm that:
- Your branch has been rebased on the upstream branch
- All your commits messages include the “Signed-off-by: First Last <email>” line
- You’ve removed any temporary debugging code you may have used
- You’ve squashed related commits together to keep your branch easily reviewable
- The unit and integration tests all pass
Once that’s all done, open a pull request on Github. Our [Jenkins](https://jenkins.linuxcontainers.org) will validate that the commits are all signed-off, a test build on MacOS and Windows will automatically be performed and if things look good, we’ll trigger a full Jenkins test run that will test your branch on all storage backends, 32bit and 64bit and all the Go versions we care about.
This typically takes less than an hour to happen, assuming one of us is around to trigger Jenkins.
Once all the tests are done and we’re happy with the code itself, your branch will be merged into master and your code will be in the next LXD feature release. If the changes are suitable for the LXD stable-2.0 branch, we’ll backport them for you.
# Conclusion
I hope this series of blog post has been helpful in understanding what LXD is and what it can do!
This series’ scope was limited to the LTS version of LXD (2.0.x) but we also do monthly feature releases for those who want the latest features. You can find a few other blog posts covering such features listed in the original [LXD 2.0 series post](https://stgraber.org/2016/03/11/lxd-2-0-blog-post-series-012/).
# Extra information
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)
Today I set aside most of the day to play with LXD and I am totally hooked. I would like to say thank you to Stephane and the LXD team for your amazing work. Stephane you are an amazing engineer, and a damn good documentation writer (which is a rare trait). Looking forward to my adventures with LXD. |
8,283 | 如何在 Debian 和 Ubuntu 上安装 MariaDB 10 | http://www.tecmint.com/install-mariadb-in-ubuntu-and-debian/ | 2017-03-09T09:38:00 | [
"MySQL",
"MariaDB"
] | https://linux.cn/article-8283-1.html | MariaDB 是深受欢迎的数据库管理服务器软件 MySQL 的一个自由开源的分支。它由 MySQL 的原开发者在 GPLv2(通用公共许可证 2 版)下开发,并保持开源。
它被设计来实现 MySQL 的高兼容性。对于初学者,可以阅读 [MariaDB vs MySQL](https://mariadb.com/kb/en/mariadb/mariadb-vs-mysql-features/) 来了解关于它们的特性的更多信息。更重要的是,它被一些大公司/组织使用,比如 Wikipedia、WordPress.com 和 Google plus ,除此之外还有更多的。
在这篇文章中,我将向你们展示如何在 Debian 和 Ubuntu 发行版中安装 MariaDB 10.1 稳定版。

### 在 Debian 和 Ubuntu 上安装 MariaDB
1、在安装之前 MariaDB 之前,你需要通过下面的命令导入仓库密匙并获取 MariaDB 仓库
**在 Debian Unstable (Sid) 上**
```
$ sudo apt-get install software-properties-common
$ sudo apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 0xF1656F24C74CD1D8
$ sudo add-apt-repository 'deb [arch=amd64,i386] http://www.ftp.saix.net/DB/mariadb/repo/10.1/debian sid main'
```
**在 Debian 9 (Stretch) 上**
```
$ sudo apt-get install software-properties-common
$ sudo apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 0xF1656F24C74CD1D8
$ sudo add-apt-repository 'deb [arch=amd64] http://www.ftp.saix.net/DB/mariadb/repo/10.1/debian stretch main'
```
**在 Debian 8 (Jessie) 上**
```
$ sudo apt-get install software-properties-common
$ sudo apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 0xcbcb082a1bb943db
$ sudo add-apt-repository 'deb [arch=amd64,i386,ppc64el] http://www.ftp.saix.net/DB/mariadb/repo/10.1/debian jessie main'
```
**在 Debian 7 (Wheezy) 上**
```
$ sudo apt-get install python-software-properties
$ sudo apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 0xcbcb082a1bb943db
$ sudo add-apt-repository 'deb [arch=amd64,i386] http://www.ftp.saix.net/DB/mariadb/repo/10.1/debian wheezy main'
```
**在 Ubuntu 16.10 (Yakkety Yak) 上**
```
$ sudo apt-get install software-properties-common
$ sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8
$ sudo add-apt-repository 'deb [arch=amd64,i386] http://www.ftp.saix.net/DB/mariadb/repo/10.1/ubuntu yakkety main'
```
**在 Ubuntu 16.04 (Xenial Xerus) 上**
```
$ sudo apt-get install software-properties-common
$ sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8
$ sudo add-apt-repository 'deb [arch=amd64,i386,ppc64el] http://www.ftp.saix.net/DB/mariadb/repo/10.1/ubuntu xenial main'
```
**在 Ubuntu 14.04 (Trusty) 上**
```
$ sudo apt-get install software-properties-common
$ sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xcbcb082a1bb943db
$ sudo add-apt-repository 'deb [arch=amd64,i386,ppc64el] http://www.ftp.saix.net/DB/mariadb/repo/10.1/ubuntu trusty main'
```
2、 然后,更新系统安装包列表,并像下面这样安装 MariaDB 服务器:
```
$ sudo apt-get update
$ sudo apt-get install mariadb-server
```
安装过程中,将会请求你配置 MariaDB 服务器;在下面的页面中设置一个安全的 root 用户密码:

*为 MariaDB 设置新的 Root 密码*
再次输入密码并按下回车键来继续安装。

*再次输入 MariaDB 密码*
当 MariaDB 安装包安装完成以后,启动数据库服务器守护进程,同时启用它,使得在下次开机时它能够像下面这样自动启动:
```
------------- On SystemD Systems -------------
$ sudo systemctl start mariadb
$ sudo systemctl enable mariadb
$ sudo systemctl status mariadb
------------- On SysVinit Systems -------------
$ sudo service mysql start
$ chkconfig --level 35 mysql on
OR
$ update-rc.d mysql defaults
$ sudo service mysql status
```

*开启 MariaDB 服务*
4、 然后,运行 `mysql_secure_installation` 脚本来保护数据库,在这儿你可以:
1. 设置 root 密码(如果在上面的配置环节你没有进行设置的话)。
2. 禁止远程 root 登录
3. 移除测试数据库
4. 移除匿名用户
5. 重载权限配置
```
$ sudo mysql_secure_installation
```

*保护 MariaDB 安装*
5、 一旦数据库服务器受保护以后,可以使用下面的 shell 命令查看已安装版本和登录 MariaDB:
```
$ mysql -V
$ mysql -u root -p
```

*查看 MariaDB 版本*
开始学习 MySQL/MariaDB, 请阅读:
1. [MySQL / MariaDB 初学者学习指南 — Part 1](http://www.tecmint.com/learn-mysql-mariadb-for-beginners/)
2. [MySQL / MariaDB 初学者学习指南 — Part 2](http://www.tecmint.com/learn-mysql-mariadb-advance-functions-sql-queries/)
3. [MySQL 基本数据库管理命令 — Part III](http://www.tecmint.com/gliding-through-database-mysql-in-a-nutshell-part-i/)
4. [针对数据库管理员的 20 个 MySQL (Mysqladmin) 命令 — Part IV](http://www.tecmint.com/mysqladmin-commands-for-database-administration-in-linux/)
查看在 Linux 中[监控 MySQL/MariaDB 性能](http://www.tecmint.com/mysql-performance-monitoring/)的四个有用的命令行工具,同时浏览 [15 个有用的 MySQL/MariaDB 性能调整和优化技巧](http://www.tecmint.com/mysql-mariadb-performance-tuning-and-optimization/)。
这就是本文的全部内容了。在这篇文章中,我向你们展示了如何在 Debian 和 Ubuntu 的不同发行版中安装 MariaDB 10.1 稳定版。你可以通过下面的评论框给我们提任何问题或者想法。
---
作者简介:
Aaron Kili 是 Linux 和 F.O.S.S 爱好者,将来的 Linux 系统管理员和网络开发人员,目前是 TecMint 的内容创作者,他喜欢用电脑工作,并坚信分享知识。
---
via: <http://www.tecmint.com/install-mariadb-in-ubuntu-and-debian/>
作者:[Aaron Kili](http://www.tecmint.com/author/aaronkili/) 译者:[ucasFL](https://github.com/ucasFL) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
8,284 | 如何在 Ubuntu 中升级到最新内核 | http://www.tecmint.com/upgrade-kernel-in-ubuntu/ | 2017-03-09T09:57:00 | [
"内核",
"升级"
] | https://linux.cn/article-8284-1.html | 每过段时间,就有新的设备和技术出来,因此如果我们想要充分利用它,保持最新的 Linux 内核就显得很重要。此外,更新系统内核将使我们能够利用新的内核优化,并且它还可以帮助我们避免在早期版本中发现的漏洞。

**建议阅读:** [如何升级 CentOS 7内核](http://www.tecmint.com/install-upgrade-kernel-version-in-centos-7/)
准备好了在 Ubuntu 16.04 或其上下游衍生版本(如 Debian 和 Linux Mint)中更新你的内核了么?如果准备好了,请你继续阅读!
### 第一步:检查安装的内核版本
要发现当前系统安装的版本,我们可以:
```
$ uname -sr
```
下面的截图显示了在 Ubuntu 16.04 server 中上面命令的输出:

*在 Ubuntu 中检查内核版本*
### 第二步:在 Ubuntu 16.04 中升级内核
要升级 Ubuntu 16.04 的内核,打开 [http://kernel.ubuntu.com/~kernel-ppa/mainline/](http://kernel.ubuntu.com/%7Ekernel-ppa/mainline/) 并选择列表中需要的版本(发布此文时最新内核是 4.10.1)。
接下来,根据你的系统架构下载 `.deb` 文件:
对于 64 位系统:
```
$ wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.10.1/linux-headers-4.10.1-041001_4.10.1-041001.201702260735_all.deb
$ wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.10.1/linux-headers-4.10.1-041001-generic_4.10.1-041001.201702260735_amd64.deb
$ wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.10.1/linux-image-4.10.1-041001-generic_4.10.1-041001.201702260735_amd64.deb
```
这是 32 位系统:
```
$ wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.10.1/linux-headers-4.10.1-041001_4.10.1-041001.201702260735_all.deb
$ wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.10.1/linux-headers-4.10.1-041001-generic_4.10.1-041001.201702260735_i386.deb
$ wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.10.1/linux-image-4.10.1-041001-generic_4.10.1-041001.201702260735_i386.deb
```
下载完成这些所有内核文件后,如下安装:
```
$ sudo dpkg -i *.deb
```
安装完成后,重启并验证新的内核已经被使用了:
```
$ uname -sr
```
就是这样。你下载就可以使用比 Ubuntu 16.04 默认安装的内核的更新版本了。
### 总结
本文我们展示了如何在 Ubuntu 系统上轻松升级Linux内核。这里还有另一个流程,但我们在这里没有展示,因为它需要从源代码编译内核,这不推荐在生产 Linux 系统上使用。
如果你仍然有兴趣编译内核作为一个学习经验,你可以在 [Kernel Newbies](https://kernelnewbies.org/KernelBuild) 网站中得到指导该如何做。
一如既往,如果你对本文有任何问题或意见,请随时使用下面的评论栏。
---
作者简介:
Gabriel Cánepa - 一位来自阿根廷圣路易斯梅塞德斯镇 (Villa Mercedes, San Luis, Argentina) 的 GNU/Linux 系统管理员,Web 开发者。就职于一家世界领先级的消费品公司,乐于在每天的工作中能使用 FOSS 工具来提高生产力。
---
via: <http://www.tecmint.com/upgrade-kernel-in-ubuntu/>
作者:[Gabriel Cánepa](http://www.tecmint.com/author/gacanepa/) 译者:[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,285 | Linux 发行版简介系列:Linux 是什么? | http://www.techphylum.com/2014/05/what-is-linux-brief-description.html | 2017-03-09T22:17:00 | [
"Linux",
"发行版"
] | https://linux.cn/article-8285-1.html | 正如上面的问题所述,我们将要了解:
### Linux 是什么?

简单来说, Linux 是一个类 Unix 的开源操作系统。
就像 Windows 或者 Mac OS 一样。
1991 年 10 月 5 日, Linus Torvalds 首次发布 Linux 内核。 Linux 内核是 Linux 系统的一个非常重要的组成部分。目前, Linux 主要用于多种服务器和超级计算机等。它也被用于手机操作系统,比如 Android 操作系统是基于 Linux 内核的。
在早期,Linux 作为一个免费的操作系统被用于基于 Intel ×86 的个人电脑上。因为 Linux 是一个开源操作系统,所以它的源代码可以被修改或使用,也可以在有 GPL(通用公共许可证)这样许可证下被任何人发布。简而言之,如果具备一定知识,知道自己在干什么,那么任何人都可以从 Linux 那儿获得自己的操作系统。正因此,才有了许多 Linux 发行版。
### 那么, Linux 发行版是什么?
它是基于 Linux 内核的一个操作系统。它带有用户可以使用的软件集合。更多的,它还包含系统管理包。目前有许多 Linux 发行版。因为我们不能数清目前所有的 Linux 发行版,所以我们来看一下一些有名的版本: Ubuntu、Fedora、Opensuse、Red hat Linux 和 Debian 等是几个非常受欢迎的 Linux 发行版。

*Ubuntu, 一个非常受欢迎的 Linux 发行版和第三受欢迎的操作系统*
Linux 发行版是一个已经准备好可以在个人电脑上安装的完整包。一旦用户在桌面或者服务器上安装了 Linux 发行版,就可以使用各种现成的软件和应用程序。现在,很多 Linux 发行版都具有很好的图形用户界面(GUI),这使得它们成为 Windows 系统或 Mac 系统的一个很好的替代品。
目前, Linux 发行版在性能、界面、可访问性以及最重要的 - 用户友好性等方面都有了很大的提高。一些发行版比如 Ubuntu 和 Linux mint 等,随着用户数量的一天天增加,赢得了很好的市场地位。 Ubuntu 是紧随 Windows 和 Mac 第三受欢迎的操作系统。
对以上做个总结,那就是 Linux 是一个非常强大的操作系统(是的,它很强大)。日复一日,它将获得更多的用户影响力和声誉。所以,如果你还没有在你的电脑上尝试过使用任何 Linux 系统,那么我建议你尝试一下。我们敢保证, Linux 一定不会让你失望的。
---
via: <http://www.techphylum.com/2014/05/what-is-linux-brief-description.html?m=1>
作者:[sumit rohankar](https://plus.google.com/112160169713374382262) 译者:[ucasFL](https://github.com/ucasFL) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
8,286 | 如何在 Linux 启动时自动执行命令或脚本 | http://www.tecmint.com/auto-execute-linux-scripts-during-reboot-or-startup/ | 2017-03-09T22:31:00 | [
"脚本",
"启动"
] | https://linux.cn/article-8286-1.html | 我一直很好奇,在[启动 Linux 系统并登录](http://www.tecmint.com/linux-boot-process/)的过程中到底发生了什么事情。按下开机键或启动一个虚拟机,你就启动了一系列事件,之后会进入到一个功能完备的系统中,有时,这个过程不到一分钟。当你注销或者关机时,也是这样。

更有意思的是,在系统启动以及用户登录或注销时,还可以让系统执行特定的操作。
本文,我们将探讨一下在 Linux 操作系统中实现这些目标的传统方法。
**注意**:我们假定使用的是 **Bash** 作为登录及注销的主 Shell。如果你使用的是其他 Shell,那么有些方法可能会无效。如果有其他的疑问,请参考对应的 Shell 文档。
### 在启动时执行 Linux 脚本
有两种传统的方法可以实现在启动时执行命令或脚本:
#### 方法 #1 - 使用 cron 任务
除了常用格式(分 / 时 / 日 / 月 / 周)外,[cron 调度器](http://www.tecmint.com/11-cron-scheduling-task-examples-in-linux/)还支持 `@reboot` 指令。这个指令后面的参数是脚本(启动时要执行的那个脚本)的绝对路径。
然而,这种方法需要注意两点:
* a) cron 守护进程必须处于运行状态(通常情况下都会运行),同时
* b) 脚本或 crontab 文件必须包含需要的环境变量(如果有的话,参考 StackOverflow 获取更多详细内容)。
#### 方法 #2 - 使用 /etc/rc.d/rc.local
这个方法对于 systemd-based 发行版 Linux 同样有效。不过,使用这个方法,需要授予 `/etc/rc.d/rc.local` 文件执行权限:
```
# chmod +x /etc/rc.d/rc.local
```
然后在这个文件底部添加脚本。
下图说明如何分别使用 cron 任务和 rc.local 运行两个示例脚本(`/home/gacanepa/script1.sh` 和 `/home/gacanepa/script2.sh`)。
script1.sh:
```
#!/bin/bash
DATE=$(date +'%F %H:%M:%S')
DIR=/home/gacanepa
echo "Current date and time: $DATE" > $DIR/file1.txt
```
script2.sh:
```
#!/bin/bash
SITE="Tecmint.com"
DIR=/home/gacanepa
echo "$SITE rocks... add us to your bookmarks." > $DIR/file2.txt
```

\*启动时执行 Linux 脚本 \*
记住,一定要提前给两个示例脚本授予执行权限:
```
$ chmod +x /home/gacanepa/script1.sh
$ chmod +x /home/gacanepa/script2.sh
```
### 在登录或注销时执行 Linux 脚本
要在登录或注销时执行脚本,分别需要使用 `~.bash_profile` 和 `~.bash_logout` 文件。多数情况下,后者需要手动创建。在每个文件的底部,添加调用脚本代码,如前面例中所示,就可以实现这个功能。
### 总结
本文主要介绍如何在启动、登录以及注销系统时执行脚本。如果你有其他的方法可以补充,请使用下面的评论表给我们指出,我们期待您的回应!
---
作者简介:
Gabriel Cánepa 是 GNU/Linux 系统管理员, 阿根廷圣路易斯 Villa Mercedes 的 web 开发人员。他为一家国际大型消费品公司工作,在日常工作中使用 FOSS 工具以提高生产力,并从中获得极大乐趣。
---
via: <http://www.tecmint.com/auto-execute-linux-scripts-during-reboot-or-startup/>
作者:[Gabriel Cánepa](http://www.tecmint.com/author/gacanepa/) 译者:[zhb127](https://github.com/zhb127) 校对:[jasminepeng](https://github.com/jasminepeng)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
8,287 | 使用 Orange Pi 搭建 Time Machine 服务器 | http://piboards.com/2017/02/13/orange-pi-as-time-machine-server/ | 2017-03-10T08:47:11 | [
"Time Machine",
"备份",
"Mac",
"Orange Pi"
] | https://linux.cn/article-8287-1.html | 
我的工作之一是为各类家用计算机安排进行自动备份,包括存放重要数据的一组 Mac 计算机。我决定使用运行 [Armbian Linux](https://www.armbian.com/) 的便宜的 [Orange Pi](https://www.amazon.com/gp/product/B018W6OTIM/ref=as_li_tl?ie=UTF8&tag=piboards-20&camp=1789&creative=9325&linkCode=as2&creativeASIN=B018W6OTIM&linkId=08bd6573c99ddb8a79746c8590776c39) 做实验,目的是希望 [Time Machine](https://support.apple.com/kb/PH25710?locale=en_US) 可以通过网络使用挂载在 Orange Pi 主板上的 USB 驱动器。在这种情况下,我找到并成功地安装了 Netatalk。
[Netatalk](http://netatalk.sourceforge.net/) 是一个用作苹果文件服务器的开源软件。通过 [Avahi](https://en.wikipedia.org/wiki/Avahi_(software)) 和 Netatalk 配合运行,你的 Mac 设备能够识别网络上的 Orange Pi 设备,甚至会将 Orange pi 设备当作 “Mac” 类型的设备。这使得你能够手动连接到该网络设备,更重要的是使得 Time Machine 能够发现并使用远程驱动器。如果你想在 Mac 上设置类似的备份机制,下面的指南也许能够帮到你。
### 准备工作
为了配置该 USB 驱动器,我首先尝试了 HFS+ 格式文件系统,不幸的是我没能成功写入。所以我选择创建一个 EXT4 文件系统,并确保用户 `pi` 有读写权限。Linux 有很多格式化磁盘的方法,但是我最喜欢(而且推荐)的仍然是 [gparted](http://gparted.org/)。由于 gparted 已经集成在 Armbian 桌面了,所以我直接使用了该工具。
我需要当 Orange Pi 启动或者 USB 驱动连接的时候,这个设备能够自动挂载到相同的位置。于是我创建了一个目录(`timemachine`)用于挂载:在其下新建一个 `tm` 目录用于真正的备份路径,并将 `tm` 的所有者更改为用户 `pi`。
```
cd /mnt
sudo mkdir timemachine
cd timemachine
sudo mkdir tm
sudo chown pi:pi tm
```
下一步,我打开一个终端并编辑 `/etc/fstab` 文件。
```
sudo nano /etc/fstab
```
并在该文件末尾添加了一行我的设备信息(根据我的设备情况,设置为 `sdc2`):
```
/dev/sdc2 /mnt/timemachine ext4 rw,user,exec 0 0
```
你需要通过命令行预装一些包,可能其中一些已经安装在你的系统上了:
```
sudo apt-get install build-essential libevent-dev libssl-dev libgcrypt11-dev libkrb5-dev libpam0g-dev libwrap0-dev libdb-dev libtdb-dev libmysqlclient-dev avahi-daemon libavahi-client-dev libacl1-dev libldap2-dev libcrack2-dev systemtap-sdt-dev libdbus-1-dev libdbus-glib-1-dev libglib2.0-dev libio-socket-inet6-perl tracker libtracker-sparql-1.0-dev libtracker-miner-1.0-dev hfsprogs hfsutils avahi-daemon
```
### 安装并配置 Netatalk
下一步是下载 Netatalk,解压下载的文件,然后切换到 Netatalk 目录:
```
wget https://sourceforge.net/projects/netatalk/files/netatalk/3.1.10/netatalk-3.1.10.tar.bz2
tar xvf netatalk-3.1.10.tar.bz2
cd netatalk-3.1.10
```
然后需要顺序执行 `./configure`,`make`,`make install` 命令安装软件。在 netatalk-3.1.10 目录中执行 如下的 `./configure` 命令,这个命令需要花点时间才能执行完。
```
./configure --with-init-style=debian-systemd --without-libevent --without-tdb --with-cracklib --enable-krbV-uam --with-pam-confdir=/etc/pam.d --with-dbus-daemon=/usr/bin/dbus-daemon --with-dbus-sysconf-dir=/etc/dbus-1/system.d --with-tracker-pkgconfig-version=1.0
```
`./configure` 运行完成后执行 `make`:
```
make
```
执行完 `make` 命令需要花较长时间,可以考虑喝杯咖啡或者做点其他什么。之后,执行以下命令:
```
sudo make install
```
这个命令能够快速执行完成。现在你可以通过下面两个命令验证安装是否成功,同时找到配置文件位置。
```
sudo netatalk -V
sudo afpd -V
```
然后你需要编辑 `afp.conf` 配置文件并在其中指定 Time Machine 备份路径,可以访问的帐号名并指定是否使用 [Spotlight](https://support.apple.com/en-us/HT204014) 为备份建立索引。
```
sudo nano /usr/local/etc/afp.conf
```
下面是 `afp.conf` 的配置示例:
```
[My Time Machine Volume]
path = /mnt/timemachine/tm
valid users = pi
time machine = yes
spotlight = no
```
最后,启用 Avahi 和 Netatalk 并启动它们。
```
sudo systemctl enable avahi-daemon
sudo systemctl enable netatalk
sudo systemctl start avahi-daemon
sudo systemctl start netatalk
```
### 连接到网络驱动器
此时,你的 Mac 可能已经发现并识别了你的 Pi 设备和网络驱动器。打开 Mac 中的 Finder,看看是否有像下面的内容:

当然你也可以通过主机名或者 ip 地址访问,比如:
```
afp://192.168.1.25
```
### Time Machine 备份
最后,打开 Mac 上的 Time Machine,然后“选择备份硬盘”,选择你的 Orange pi。

这样设置肯定有效,Orange Pi 能够很好的处理进程,不过这可能并不是最快速的备份方式。但是,这个方法比较简单且便宜,并且正如其展示的一样能够正常工作。如果对这些设置你已经成功或者进行了改进,请在下面留言或者发送消息给我。

Amazon 上有售卖 Orange Pi 主板。
---
via: <http://piboards.com/2017/02/13/orange-pi-as-time-machine-server/>
作者:[MIKE WILMOTH](http://piboards.com/author/piguy/) 译者:[beyondworld](https://github.com/beyondworld) 校对:[jasminepeng](https://github.com/jasminepeng)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 302 | Found | null |
8,288 | 超酷的 Vim 搜索技巧 | https://www.howtoforge.com/tutorial/perform-search-operations-in-vim/ | 2017-03-10T09:26:16 | [
"Vim",
"搜索"
] | https://linux.cn/article-8288-1.html | 尽管目前我们已经[涉及](/article-8224-1.html) Vim 的多种特性,但此编辑器的特性集如此庞大,不管我们学习多少,似乎仍然远远不足。承接我们的 Vim 教程系列,本文我们将讨论 Vim 提供的多种搜索技术。
不过在此之前,请注意文中涉及到的所有的例子、命令、指令均是在 Ubuntu 14.04,Vim 7.4 下测试的。

### Vim 中的基础搜索操作
当你在 Vim 中打开一个文件并且想要搜索一个特定的单词或模板,第一步你必须要先按下 `Esc` 键从插入模式中退出(如果你正处于插入模式中)。之后输入 `/` 并紧接着输入你要搜索的单词或搜索模式。
例如,如果你想要搜索的单词是 `linux`,下图显示的就是在 Vim 窗口底部的搜索命令:

敲击回车键之后,你会看到 Vim 会将光标停留在从光标在插入模式中的位置开始,找到的包含此单词的第一行。如果你刚刚打开一个文件并且立即开始了搜索操作,搜索将从文件的首行开始。
如果想要移动到下一处包含被搜索单词位置,按 `n` 键。当你遍历完所有被搜索模板所在之处,继续按 `n` 键 Vim 将重复搜索操作,光标将回到第一次搜索结果出现位置。

在遍历搜索结果时,如果你想要回到上一匹配处,按 `N` (即 `shift` + `n`)。同时,值得注意的是不管在什么时候,你都可以输入 `ggn` 来跳转到第一个匹配处,或者 `GN` 来跳转到最后一处。
当你恰好在文件的底部,而且想要逆向搜索的情况下,使用 `?` 代替 `/` 来开始搜索。下图是一个例子:

### 自定义你的搜索
#### 1、 高亮搜索结果
尽管通过 `n` 或 `N` 从被搜索单词或模式的匹配处跳转到另一处很简单,但是如果匹配处能够高亮就更加人性化了。例如,请看下附截图:

这可以通过设置 `hlsearch` 变量来实现,例如在普通/命令行模式中执行下述命令:
```
:set hlsearch
```

#### 2、使搜索不区分大小写
在 Vim 中进行搜索默认是区分大小写的。这就意味着如果我要搜索 `linux`,那么 `Linux` 是不会匹配的。然而,如果这不是你想要的搜索方式,你可以使用如下命令来使搜索变得不区分大小写:
```
:set ignorecase
```
所以当我设置 `ignorecase` 变量后再使用前边提到的命令,搜索 `linux`,那么 `Linux` 所在处也会被高亮。

#### 3、智能大小写搜索
Vim 提供了一个功能,只有当要搜索的单词 / 模板包含大写字母时,编辑器才会区分大小写。要想实现这种功能,必须先设置 `ignorecase`,再接着设置 `smartcase` 变量。
```
:set ignorecase
:set smartcase
```
例如,如果一个文件中既包含 `LINUX` 也包含 `linux`,在开启智能大小写搜索功能时,如果使用 `/LINUX` 进行搜索,只有单词 `LINUX` 处会被搜到。反之,如果搜索 `/linux`,那么不论大小写的搜索结果都会被匹配。
#### 4、递进搜索
就如谷歌一样,随着你输入查询字串(字串随你每输入一个字符不断更新)显示不同的搜索结果,Vim 也同样提供了递进搜索。要想使用这种特性,你必须在搜索前执行下述命令:
```
:set incsearch
```
### 一些很酷的在 Vim 中搜索的小技巧
你可能会发现还有一些其他的与搜索相关的小技巧很有用。
开始吧!如果你想要搜索一个文件中的一个单词,但是又不想输入它,你只需要将你的光标移到这个单词下然后按 `*` (或者 `shift` + `8`)。如果你想要启动一次部分搜索(例如:同时搜索 `in` 和 `terminal`),那你需要将光标移到到单词(在本例中, `in`)下,然后通过在键盘上按 `g*` (按一次 `g` 然后不断按 `*` )。
注意:如果你想要逆向搜索,按 `#` 或者 `g#` 。
这里有个视频,你可以看看:
下一个,只要你想要,你可以获得所有被搜索单词或模式匹配处所在的行和行号的一个列表。这可以在你开始搜索后通过按 `[I` 来实现。如下图是一个列表结果如何在 Vim 窗口底部被分组和显示的例子:

接下来,你可能已经得知,Vim 默认是环形搜索的,意味着在到达文件结尾处(或者被搜索单词的最后一处匹配)时,如果继续按 “搜索下一个” 会将光标再次带回第一处匹配处。如果你希望禁止环形搜索,可以使用如下命令:
```
:set nowrapscan
```
再次开启环形搜索,使用如下命令即可:
```
:set wrapscan
```
最后,假设你想要对文件中已经存在的单词做一点小小的修改,然后对修改后的单词执行搜索操作,一种方法是输入 `/` 与要搜索的单词。但是如果这个单词又长又复杂,那么可能需要一点时间来输入它。
一个简单的办法是将光标移到你想要略微修改的单词下,按 `/` 之后再按 `Ctrl` + `r` 最后按 `Ctrl` + `w`。这个在光标下的单词不仅仅会被拷贝,也会被复制到 `/` 后,允许你对它进行修改并且继续进行搜索操作。
如果想要获得更多小技巧(包括如何使用鼠标来使在 Vim 中的操作变得简单),请前往 [Vim 官方文档](http://vim.wikia.com/wiki/Searching)。
### 结语
当然,没有人希望你死记硬背这里提到的所有小技巧。你应该做的是,从一个你认为对你最有益的技巧开始不断练习。当它成为一种习惯并且嵌入你的记忆后,重新来这儿找找你应该开始学习的下一个技巧。
你知道其他像这样的技巧吗?并且希望能够和大家一起分享?那就在下边留言吧!
---
via: <https://www.howtoforge.com/tutorial/perform-search-operations-in-vim/>
作者:[Himanshu Arora](https://www.howtoforge.com/tutorial/perform-search-operations-in-vim/) 译者:[xiaow6](https://github.com/xiaow6) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 200 | OK | # How to perform search operations in Vim
While we've already [covered](https://www.howtoforge.com/tutorial/vim-editor-modes-explained/) several features of Vim until now, the editor's feature-set is so vast that no matter how much you learn, it doesn't seem to be enough. So continuing with our Vim tutorial series, in this write-up, we will discuss the various search techniques that the editor offers.
`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.`
## Basic search operations in Vim
If you have opened a file in the Vim editor, and want to search a particular word or pattern, the first step that you have to do is to come out of the Insert mode (if you that mode is currently active). Once that is done, type '**/**' (without quotes) followed by the word/pattern that you want to search.
For example, if the word you want to search is 'linux', here's how it will appear at the bottom of your Vim window:
After this, just hit the Enter key and you'll see that Vim will place the cursor on the first line (containing the word) that it encounters beginning from the line where the cursor was when you were in Insert mode. If you've just opened a file and began searching then the search operation will start from the very first line of the file.
To move on to the next line containing the searched word, press the '**n**' key. When you've traversed through all the lines containing the searched pattern, pressing the '**n**' key again will make the editor to repeat the search, and you'll be back to the first searched occurrence again.
While traversing the searched occurrences, if you want to go back to the previous occurrence, press '**N**' (shift+n). Also, it's worth mentioning that at any point in time, you can type '**ggn**' to jump to the first match, or '**GN**' to jump to the last.
In case you are at the bottom of a file, and want to search backwards, then instead of initiating the search with ** /**, use
**. Here's an example:**
*?*## Customize your search
### 1. Search highlighting
While jumping from one occurrence of the searched word/pattern to another is easy using 'n' or 'N,' things become more user-friendly if the searched occurrences get highlighted. For example, see the screenshot below:
This can be made possible by setting the 'hlsearch' variable, something which you can do by writing the following in the normal/command mode:
:set hlsearch
### 2. Making search case-insensitive
By default, the search you do in Vim is case-sensitive. This means that if I am searching for 'linux', then 'Linux' won't get matched. However, if that's not what you are looking for, then you can make the search case-insensitive using the following command:
:set ignorecase
So after I set the 'ignorecase' variable using the aforementioned command, and searched for 'linux', the occurrences of 'LINUX' were also highlighted:
### 3. Smartcase search
Vim also offers you a feature using which you can ask the editor to be case-sensitive only when the searched word/pattern contains an uppercase character. For this you need to first set the 'ignorecase' variable and then set the 'smartcase' variable.
:set ignorecase
:set smartcase
For example, if a file contains both 'LINUX' and 'linux,' and smartcase is on, then only occurrences of the word LINUX will be searched if you search using '/LINUX'. However, if the search is '/linux', then all the occurrences will get matched irrespective of whether they are in caps or not.
### 4. Incremental search
Just like, for example, Google, which shows search results as you type your query (updating them with each alphabet you type), Vim also provides incremental search. To access the feature, you'll have to execute the following command before you start searching:
:set incsearch
## Some other cool Vim search tips/tricks
There are several other search-related tips tricks that you may find useful.
To start off, if you want to search for a word that's there in the file, but you don't want to type it, you can just bring your cursor below it and press ***** (or **shift+8**). And if you want to launch a partial search (for example: search both '*in'* and 'term*in*al'), then you can bring the cursor under the word (in our example, *in*) and search by pressing **g*** (press 'g' once and then keep pressing *) on the keyboard.
Note: Press **#** or **g#** in case you want to search backwards.
Next up, if you want, you can get a list of all occurrences of the searched word/pattern along with the respective lines and line numbers at one place. This can be done by type **[I** after you've initiated the search. Following is an example of how the results are grouped and displayed at the bottom of Vim window:
Moving on, as you might already know, the Vim search wraps by default, meaning after reaching the end of the file (or to the last occurrence of the searched word), pressing "search next" brings the cursor to the first occurrence again. If you want, you can disable this search wrapping by running the following command:
:set nowrapscan
To enable wrap scan again, use the following command:
:set wrapscan
Finally, suppose you want to make a slight change to an already existing word in the file, and then perform the search operation, then one way is to type **/** followed by that word. But if the word in long or complicated, then it may take time to type it.
An easy way out is to bring the cursor under the word you want to slightly edit, then press '/' and then press Ctrl-r followed by Ctrl-w. The word under the cursor will not only get copied, it will be pasted after '/' as well, allowing you to easily edit it and go ahead with the search operation.
For more tricks (including how you can use your mouse to make things easier in Vim), head to the [official Vim documentation](http://vim.wikia.com/wiki/Searching).
## Conclusion
Of course, nobody expects you to mug up all the tips/tricks mentioned here. What you can do is, start with the one you think will be the most beneficial to you, and practice it regularly. Once it gets embedded in your memory and becomes a habit, come here again, and see which one you should learn next.
Do you know any more such tricks? Want to share it with everyone in the HTF community? Then leave it as a comment below. |
8,289 | Linux 中 7 个判断文件系统类型的方法 | http://www.tecmint.com/find-linux-filesystem-type/ | 2017-03-11T08:39:00 | [
"文件系统"
] | https://linux.cn/article-8289-1.html | 文件通过文件系统在磁盘及分区上命名、存储、检索以及更新,文件系统是在磁盘上组织文件的方式。
文件系统分为两个部分:用户数据和元数据(文件名、创建时间、修改时间、大小以及目录层次结构中的位置等)。
在本指南中,我们将用 7 种方法来识别你的 Linux 文件系统类型,如 Ext2、Ext3、Ext4、BtrFS、GlusterFS 等等。

### 1、 使用 df 命令
`df` 命令报告文件系统磁盘空间利用率,要显示特定的磁盘分区的文件系统类型,像下面那样使用 `-T` 标志:
```
$ df -Th
或者
$ df -Th | grep "^/dev"
```

*df 命令 – 找出文件系统类型*
要更好理解 `df` 命令,阅读下面的文章:
1. [12 个有用的 df 命令来检查 Linux 中的磁盘空间](http://www.tecmint.com/how-to-check-disk-space-in-linux/)
2. [Pydf - 一个替代 df 的命令,用颜色显示磁盘使用率](http://www.tecmint.com/pyd-command-to-check-disk-usage/)
### 2、 使用 fsck 命令
`fsck` 用来检查以及[修复 Linux 文件系统](http://www.tecmint.com/defragment-linux-system-partitions-and-directories/),它也可以输出[指定磁盘分区的文件系统类型](http://www.tecmint.com/manage-file-types-and-set-system-time-in-linux/)。
`-N` 标志禁用检查文件系统错误,它只是显示会做什么(但是我们只需要文件系统类型):
```
$ fsck -N /dev/sda3
$ fsck -N /dev/sdb1
```

*fsck – 打印 Linux 文件系统类型*
### 3、 使用 lsblk 命令
`lsblk` 会显示块设备,当使用 `-f` 选项时,它也会打印分区的文件系统类型:
```
$ lsblk -f
```

*lsblk – 显示 Linux 文件系统类型*
### 4、 使用 mount 命令
`mount` 命令用来[在 Linux 中挂载文件系统](http://www.tecmint.com/sshfs-mount-remote-linux-filesystem-directory-using-ssh/),它也可以用来[挂载一个 ISO 镜像](http://www.tecmint.com/extract-files-from-iso-files-linux/),[挂载远程 Linux 文件系统](http://www.tecmint.com/sshfs-mount-remote-linux-filesystem-directory-using-ssh/)等等。
当不带任何参数运行时,它会打印包含文件系统类型在内的[磁盘分区的信息](http://www.tecmint.com/linux-tools-to-monitor-disk-partition-usage/):
```
$ mount | grep "^/dev"
```

*Mount – 在 Linux 中显示文件系统类型*
### 5、 使用 blkid 命令
`blkid` 命令用来[找出或打印块设备属性](http://www.tecmint.com/find-usb-device-name-in-linux/),只要将磁盘分区作为参数就行了:
```
$ blkid /dev/sda3
```

*blkid – 找出文件系统类型*
### 6、 使用 file 命令
`file` 命令会识别文件类型,使用 `-s` 标志启用读取块设备或字符设备,`-L` 启用符号链接跟随:
```
$ sudo file -sL /dev/sda3
```

*file – 识别文件系统类型*
### 7、 使用 fstab 文件
`/etc/fstab` 是一个静态文件系统信息(比如挂载点、文件系统类型、挂载选项等等)文件:
```
$ cat /etc/fstab
```

*fstab – 显示 Linux 文件系统类型*
就是这样了!在这篇指南中,我们用 7 种方法来识别你的 Linux 文件系统类型。你还知道这里没有提到的其他方法么?在评论中与我们分享。
---
作者简介:
Aaron Kili是一名 Linux 和 F.O.S.S 的爱好者,未来的 Linux 系统管理员、网站开发人员,目前是 TecMint 的内容创作者,他喜欢用电脑工作,并乐于分享知识。
---
via: <http://www.tecmint.com/find-linux-filesystem-type/>
作者:[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,290 | 漫画赏析:Linux 内核到底长啥样 | http://turnoff.us/geek/inside-the-linux-kernel/ | 2017-03-11T18:16:00 | [
"内核",
"漫画"
] | https://linux.cn/article-8290-1.html | 今天,我来为大家解读一幅来自 TurnOff.us 的漫画 “[InSide The Linux Kernel](http://turnoff.us/geek/inside-the-linux-kernel/)” 。 [TurnOff.us](http://turnoff.us/) 是一个极客漫画网站,作者Daniel Stori 画了一些非常有趣的关于编程语言、Web、云计算、Linux 相关的漫画。今天解读的便是其中的一篇。
在开始,我们先来看看这幅漫画的全貌!

这幅漫画是以一个房子的侧方刨面图来绘画的。使用这样的一个房子来代表 Linux 内核。
### 地基
作为一个房子,最重要的莫过于其地基,在这个图片里,我们也从最下面的地基开始看起:

地基(底层)由一排排的文件柜组成,井然有序,文件柜里放置着“文件”——电脑中的文件。左上角,有一只胸前挂着 421 号牌的小企鹅,它表示着 PID(<ruby> 进程 ID <rp> ( </rp> <rt> Process ID </rt> <rp> ) </rp></ruby>) 为 421 的进程,它正在查看文件柜中的文件,这代表系统中正有一个进程在访问文件系统。在右下角有一只小狗,它是<ruby> 看门狗 <rp> ( </rp> <rt> watchdog </rt> <rp> ) </rp></ruby> ,这代表对文件系统的监控。

### 一层(地面层)
看完了地基,接下来我们来看地基上面的一层,都有哪些东西。

在这一层,最引人瞩目的莫过于中间的一块垫子,众多小企鹅在围着着桌子坐着。这个垫子的区域代表进程表。
左上角有一个小企鹅,站着,仿佛在说些什么这显然是一位家长式的人物,不过看起来周围坐的那些小企鹅不是很听话——你看有好多走神、自顾自聊天的——“喂喂,说你呢,哇塞娃(171),转过身来”。它代表着 Linux 内核中的初始化(init)进程,也就是我们常说的 PID 为 1 的进程。桌子上坐的小企鹅都在<ruby> 等待状态 <rp> ( </rp> <rt> wait </rt> <rp> ) </rp></ruby>中,等待工作任务。

瞧瞧,垫子(进程表)两旁有两只小狗,它会监控小企鹅的状态(监控进程),当小企鹅们不听话时,它就会汪汪地叫喊起来。

在这层的左侧,有一只号牌为 1341 的小企鹅,守在门口,门上写着 80,说明这个 PID 为 1341 的小企鹅负责接待 80 端口,也就是我们常说的 HTTP (网站)的端口。小企鹅头上有一片羽毛,这片羽毛大有来历,它是著名的 HTTP 服务器 Apache 的 Logo。喏,就是这只:

向右看,我们可以看到这里仍有一扇门,门上写着 21,但是,看起来这扇门似乎年久失修,上面的门牌号都歪了,门口也没人守着。看起来这个 21 端口的 FTP 协议有点老旧了,目前用的人也比以前少了,以至于这里都没人接待了。

而在最右侧的一个门牌号 22 的们的待遇就大为不同,居然有一只带着墨镜的小企鹅在守着,看起来好酷啊,它是黑衣人叔叔吗?为什么要这么酷的一个企鹅呢,因为 22 端口是 SSH 端口,是一个非常重要的远程连接端口,通常通过这个端口进行远程管理,所以对这个端口进来的人要仔细审查。

它的身上写着 52,说明它是第 52 个小企鹅。

在图片的左上角,有一个向下台阶。这个台阶是底层(地基)的文件系统中的,进程们可以通过这个台阶,到文件系统中去读取文件,进行操作。

在这一层中,有一个身上写着 217 的小企鹅,他正满头大汗地看着自己的手表。这只小企鹅就是定时任务(Crontab),他会时刻关注时间,查看是否要去做某个工作。

在图片的中部,有两个小企鹅扛着管道(PipeLine)在行走,一只小企鹅可以把自己手上的东西通过这个管道,传递给后面的小企鹅。不过怎么看起来前面这种(男?)企鹅累得满头大汗,而后面那只(女?)企鹅似乎游刃有余——喂喂,前面那个,裤子快掉了~

在这一层还有另外的一个小企鹅,它手上拿着一杯红酒,身上写着 411,看起来有点不胜酒力。它就是红酒(Wine)小企鹅,它可以干(执行)一些来自 Windows 的任务。
### 跃层
在一层之上,还有一个跃层,这里有很多不同的屏幕,每个屏幕上写着 TTY(这就是对外的终端)。比如说最左边 tty4 上输入了“fre”——这是想输入“freshmeat...”么 :d ;它旁边的 tty2 和 tty3 就正常多了,看起来是比较正常的命令;tty7 显示的图形界面嗳,对,图形界面(X Window)一般就在 7 号终端;tty5 和 tty6 是空的,这表示这两个终端没人用。等等,tty1 呢?

tty(终端)是对外沟通的渠道之一,但是,不是每一个进程都需要 tty,某些进程可以直接通过其他途径(比如端口)来和外部进行通信,对外提供服务的,所以,这一层不是完整的一层,只是个跃层。
好了,我们有落下什么吗?

这小丑是谁啊?
啊哈,我也不知道,或许是病毒?你说呢?
| 301 | Moved Permanently | null |
8,291 | 如何加入一个技术社区 | https://opensource.com/article/17/1/how-join-technical-community | 2017-03-12T08:30:00 | [
"社区"
] | https://linux.cn/article-8291-1.html |
>
> 参照以下几步可以让你很容易地融入社区
>
>
>

加入一个新的社区在很多情况下可能是一个艰巨的任务。当加入一个新的技术社区时,焦虑感可能特别强烈,尤其是一些社区对新成员的严厉甚至讥讽都是有名的。
虽然有可能陷入一个不公正的地方,但是我认为你会发现大多数技术社区是相当合理的,并且以下几个简单的步骤可以缓解从非成员到成员的过渡。
### 冷暖自知
在你开始实际加入社区前,首先你要确保该社区适合你,同时你也是合适该社区。
这听起来很简单,但每个社区都有不同的文化、态度、理念和公认的规范。如果你对某个话题还了解甚少,那么面向行业专业人士的社区可能就不是一个理想的起点。同样,如果你是一个资深专家,希望寻找深入并且极其复杂问题的答案,那么初学者的社区肯定也不太合适。无论哪种方式,两边的不匹配几乎肯定会导致双方的失望。同样,一些社区是非常正规并且面向商业的,而另一些社区将非常宽松和悠闲,也有许多社区的氛围处于二者之间。选择适合你自己的社区,或至少不是让你厌恶的社区,这将有助于确保你的长期参与,可以使你顺利的迈出这一步。
### 潜龙勿用
最初以只读模式围观参与社区是一个好方法。但这并不意味着你不应该立即创建一个帐户或加入,只是你可以通过围观社区得到一个空间感(无论是虚拟的或物理的)。潜伏一段时间有助于你适应社区的规则和文化,以此确定你是否认为这是一个很适合你的平台。
### 毛遂自荐
根据社区的不同,自我介绍的细节将有很大的不同。同样,确保这样做的方式容易被社区接受。
有些社区可能有一个专门的介绍板块,而在另一些社区,它可能是填写你的个人资料等有意义和相关的信息。如果社区是邮件列表或 IRC 频道,在你的首次发问中包含简要介绍可能更有意义。这可以让社区了解你是谁,为什么你想成为社区的一部分,并让他们知道一点关于你自己和你的技术水平的信息。
### 相敬如宾
虽然社区与社区的接受方式有很大的不同,但你应该永远保持尊重。避免争吵和人身攻击,并始终致力于建设。记住,你在互联网上发布的东西,它就会一直在那里,不尽不灭,并为大家所看到。
### 非礼勿言
#### 提问
记住,精心设计的问题可以更快地得到更好的答案,正如我在十月专栏 [The Queue](https://opensource.com/life/16/10/how-ask-technical-questions) 中指出的那样。
#### 回答
一旦遇见了自己很了解的关于基础或非常容易回答的提问时,“尊重”的理念也同样适用,就像提问时一样。一个冗长的并充满优越感的技术上正确的答案,并不是向一个新的社区介绍自己的正确方式。
#### 闲话
即使在技术社区,也并不是所有的讨论都是关于某个问题或答案。在这种情况下,以尊重和周到的、不带有侮辱和人身攻击的方式,提出不同的意见或挑战他人的观点才是健康正确的做法。
### 不亦说乎
长期参加社区最重要的事情是在那里可以满足自己。参与一个充满活力的社区是一个学习、成长、挑战和提升自我的好机会。很多情况下,这并不容易,但它是值得的。
---
作者简介:
Jeremy Garcia - Jeremy Garcia 是 LinuxQuestions.org 的创始人,同时也是一个热情和注重实际的开源拥护者。个人推特: @linuxquestions
---
via: <https://opensource.com/article/17/1/how-join-technical-community>
作者:[Jeremy Garcia](https://opensource.com/users/jeremy-garcia) 译者:[livc](https://github.com/livc) 校对:[Bestony](https://github.com/Bestony), [wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 200 | OK | Joining a new community can be a daunting task for a myriad of reasons. The angst can be especially strong when joining a new technical community, some of which have a reputation for being acrimonious and tough on new members.
While it's possible to stumble into a den of iniquity, I think you'll find most technical communities to be fairly reasonable, and following a few simple steps can ease your transition from non-member to member.
## A good fit
The process begins well before you actually join a community. The first step is to ensure the community is a good fit for you, and you are a good fit for the community.
This sounds simple, but every community has a distinct culture, attitude, philosophy, and accepted norms. If you're new to a topic, a community aimed at industry professionals is not an ideal place to start. Similarly, if you are a grizzled expert looking for an answer to an in-depth, extremely complicated problem, a community for beginners is almost certainly not a good fit. Either way, the impedance mismatch will almost certainly lead to frustration on both sides. Similarly, some communities are going to be very business oriented and formal, while others will be extremely lax and laid back. Many are in the middle. Picking a community that suits your personality, or minimally isn't an anathema to you, will help ensure you enjoy participating long term—which leads me to the first step.
## Lurk around
Browsing around and participating in the community in a read-only mode initially is a good idea. This doesn't mean you shouldn't immediately create an account or join, just that you need to get a feel for a place (be it virtual or physical) by browsing around a bit. Lurking for a little while will help you acclimate to the community's rules and culture, and you can ascertain whether you think it's a good fit for you.
## Introduce yourself
Depending on the venue, the details of what introducing yourself will mean can vary widely. Once again, be sure to do this in a way that is consistent with what is acceptable to the community you're joining.
Some places may have a dedicated outlet for introductions, while in some communities it may imply filling out your profile with meaningful and relevant information. If the community is a mailing list or IRC channel, a brief introduction included with your initial query may make more sense. This will give the community an idea of who you are, why you'd like to be a part of the community, and will also let them know a little about yourself and your level of technical proficiency.
## Be respectful
While what is acceptable will vary largely from community to community, you should always be is respectful. Avoid flame wars and personal attacks, and always try to be constructive. Remember, once you post something on the Internet, it's there forever, and for everyone to see.
## Questions
### Asking
Remember that well-crafted questions receive better answers quicker, as I pointed out in my October column, [The Queue](https://opensource.com/life/16/10/how-ask-technical-questions).
### Answering
Once you know a topic well, forgetting that at some point you didn't know the basics either is all too easy. The "be respectful" mantra applies here just as much when answering a question as it does when asking. A lengthy technically correct answer given in a condescending manner isn't the way you want to introduce yourself to a new community.
### Doing neither
Even in a technical community, not all discussion is a question or an answer. In those cases, remember that differing opinions and challenging others' point of view is healthy when done in a respectful and thoughtful way, and without insult or personal attack.
## Enjoy yourself
The most important thing about participating in a community long term is to remember to enjoy your time there. Participating in a vibrant community is a great opportunity to learn, grow, challenge yourself, and improve. It's not always easy, but it is worth it.
## 1 Comment |
8,292 | 漫画赏析:80 端口之战 | http://turnoff.us/geek/apache-vs-nginx/ | 2017-03-12T10:46:00 | [
"Nginx",
"Apache",
"漫画"
] | https://linux.cn/article-8292-1.html | 嗨,大家好,今天我们来聊聊 80 端口之战。著名的技术漫画站 [turnoff.us](http://turnoff.us/) 有这样的[一副漫画](http://turnoff.us/geek/apache-vs-nginx/),生动的描绘了固守 80 端口的 Apache 和新生代的 Nginx 之间的战争。你知道,80 端口是 Web 端口,就是这个端口构成了我们现在大部分的互联网。

作为新生代的 Nginx 对已经 22 岁之老的 Apache 说,“一边去,老头,这 80 口不用你看着了,你得给新人腾腾地方了!”

头顶羽毛(Apache 的 Logo 形象),身上的写着名字的牌子都是补上去的(a patch,即 Apache 这个词的出处)一脸懵逼,对小毛头 Nginx 说,“放尊重点,你觉得你已经能取代像我这样的老同志了吗?!”

“哈?C10K 你解决了吗?事件驱动呢?这些你行吗?”Nginx 说。(C10K 指并发上万连接,由于服务器和网络性能的提升,现在的服务程序面临着处理更大并发的请求,而一些老旧的应用面对这种大量请求显然有点力不从心)

“嗯,我可以给你一个‘小小’的列表,这都是我支持的模块……” Apache 顾左右而言它。
“这些都过时了!我猜它们根本就没人用过!” Nginx 看着那“小小”的列表,一脸嫌弃的反驳。(讲真,Apache 的很多模块你可能从未用过,尤其是那些内置的模块,而另外一些年久失修的第三方模块,甚至你都不知道能不能用了)

一看这么多模块唬不住 Nginx,Apache 又把 PHP、MySQL 等小弟叫出来助阵,“这些都是我的铁杆兄弟!”
“嘿,谁怕谁啊,谁没兄弟啊,我也有啊” Nginx 拽出来焕发了第二春的 Postgres 数据库和曾经的明日之星 Ruby,不过感觉这些兄弟们有点不太给力 :-d 。

那么你猜猜谁会赢?买定离手啊~

| 301 | Moved Permanently | null |
8,294 | Linux 发行版简介系列:Debian | http://www.techphylum.com/2014/05/what-is-debian-brief-introduction.html | 2017-03-12T09:23:00 | [
"Debian"
] | https://linux.cn/article-8294-1.html | 大家好!!
今天给大家带来点有意思的东西。我们准备给大家仔细讲讲 Linux 世界里的东西。
想必你们对 [Linux 是什么?](/article-8285-1.html)和[怎么在 Linux 下用 screenlets 工具来安装一些桌面小程序](http://www.techphylum.com/2014/05/desktop-gadgets-in-linux-ubuntu.html)这两篇文章也感兴趣。这篇文章作为这一系列的文章的第一部分,来给大家讲讲 Debian 这个 Linux 发行版。作为 Linux 的第一个发行版,Debian 首次发布于 1993 年 9 月。Debian 这个名字来自于 Debian 发行版的创造者 Ian Murdock 及其妻子 Debra。(LCTT 译注:Ian 已经去世)

Debian 是个庞大的开源软件包的集合体。Debian 支持安装非自由的软件包,但是其自由软件包的数量更大。根据 Debian 的官方数据统计,Debian 库里总共囊括了 37500 个自由软件包。这些软件都是由 Debian 官方免费提供的。目前全世界大概有一千多人在为打造一个更好的 Debian 发行版努力。
在写作本文时, Debian 最新的稳定发行版是 7.5 命名为 Wheezy 。给开发测试用的最新的测试发行版 8.0 也出来了,命名为 Jessie(LCTT 译注:翻译本文时,Debian 已经 8.7 了) 。Debian 发行版默认使用 Gnome 做为桌面环境。当然也不是只有 Gnome ,KDE 、Xfce 和 LXDE 这些桌面环境都是可选的。因为 Debian 的安装工具是可视化的图形界面,所以安装 Debian 这事很易容完成。
Debian 是一个稳健而且安全性高的操作系统。Debian 支持绝大部分的架构的硬件平台,所以你们不用担心它能不能在你的 PC 上运行。另外你是不是要问驱动怎么办?想知道从哪里可以找到能和你的 Debian 相匹配的驱动?这些问题都不需要太担心,Debian 社区已经把绝大部分的新老设备的驱动准备好了。这样一来你也不用再等设备生产商给你制作相应的设备驱动了。还有更棒的一点就是,这些驱动都是开源的,都是可以免费获取的。
Debian 是由社区来维护的。因为有了这个社区,你可以相信你在使用 Debian 过程种遇到的问题肯定是可以在社区里找到其它用户来给你提供解决办法的。Debian 软件库里有大把的软件供你选择,而且都是免费的。Debian 是一个非常稳定而功能强大的操作系统,另外它的用户界面也很易用。
我们一般所说的稳定,是指这个系统极少出现崩溃或者挂死现象,还能兼顾高效率。Debian 正是这种系统的代表。Debian 的升级也相当容易实现。Debian 团队已经把软件库里的众多软件件源码包编译好,所以我们可以轻松的找到想要的软件,并且安装到系统里。
不管怎么说,Debian 诞生到现在已经有 20 个年头了。能持续到现在,说明了 Debian 团队一直在为给用户提供一个最好的发行版而不懈努力着。Debian 可以通过购买 DVD 的方式进行安装,也可以直接在网上下载 ISO 镜像来进行安装。所以我们推荐你试一下 Debian。它可以给你提供非常多的东西。
Debian 是我们的“Linux 发行版简介系列”系列里的第一篇文章。我们会接下来会给你们介绍另外一个 Linux 发行版。保持关注哦,后面还有更多内容。到时候再见咯。
---
via: <http://www.techphylum.com/2014/05/what-is-debian-brief-introduction.html>
作者:[sumit rohankar](https://plus.google.com/112160169713374382262) 译者:[zschong](https://github.com/zschong) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
8,295 | 在 Ubuntu 上使用 SSL/TLS 搭建一个安全的 FTP 服务器 | http://www.tecmint.com/secure-ftp-server-using-ssl-tls-on-ubuntu/ | 2017-03-12T13:35:00 | [
"FTPS",
"FTP",
"SSL"
] | https://linux.cn/article-8295-1.html | 在本教程中,我们将介绍如何使用 Ubuntu 16.04 / 16.10 中的 SSL / TLS 保护 FTP 服务器(FTPS)。
如果你想为基于 CentOS 的发行版安装一个安全的 FTP 服务器,你可以阅读 – [在 CentOS 上使用 SSL / TLS 保护 FTP 服务器](http://www.tecmint.com/axel-commandline-download-accelerator-for-linux/)。
在遵循本指南中的各个步骤之后,我们将了解在 FTP 服务器中启用加密服务的基本原理,以确保安全的数据传输至关重要。

### 要求
* 你必须已经[在 Ubuntu 上安装和配置好一个 FTP 服务器](http://www.tecmint.com/install-ftp-server-in-ubuntu/)
在我们进行下一步之前,确保本文中的所有命令都将以root身份或者 [sudo 特权账号](http://www.tecmint.com/sudoers-configurations-for-setting-sudo-in-linux/)运行。
### 第一步:在 Ubuntu 上为 FTP 生成 SSL/TLS 证书
1、我们将首先在 `/etc/ssl/` 下创建一个子目录来存储 SSL/TLS 证书和密钥文件,如果它不存在的话这样做:
```
$ sudo mkdir /etc/ssl/private
```
2、 现在我们在一个单一文件中生成证书和密钥,运行下面的命令:
```
$ sudo openssl req -x509 -nodes -keyout /etc/ssl/private/vsftpd.pem -out /etc/ssl/private/vsftpd.pem -days 365 -newkey rsa:2048
```
上面的命令将提示你回答以下问题,不要忘了输入合适于你情况的值:
```
Country Name (2 letter code) [XX]:IN
State or Province Name (full name) []:Lower Parel
Locality Name (eg, city) [Default City]:Mumbai
Organization Name (eg, company) [Default Company Ltd]:TecMint.com
Organizational Unit Name (eg, section) []:Linux and Open Source
Common Name (eg, your name or your server's hostname) []:tecmint
Email Address []:[email protected]
```
### 第二步:在 Ubuntu 上配置 vsftpd 来使用 SSL/TLS
3、在我们进行 vsftpd 配置之前,对于那些[已启用 UFW 防火墙](/article-8087-1.html)的用户,你们必须打开端口 `990` 和 `40000` - `50000`,来在 vsftpd 配置文件中分别启用 TLS 连接端口和被动端口的端口范围:
```
$ sudo ufw allow 990/tcp
$ sudo ufw allow 40000:50000/tcp
$ sudo ufw status
```
4、现在,打开 vsftpd 配置文件并定义 SSL 详细信息:
```
$ sudo vi /etc/vsftpd/vsftpd.conf
或
$ sudo nano /etc/vsftpd/vsftpd.conf
```
然后,添加或找到选项 `ssl_enable`,并将它的值设置为 `YES` 来激活使用 SSL ,同样,因为 TLS 比 SSL 更安全,我们将通过启用 `ssl_tlsv1` 选项限制 vsftpd 只使用 TLS:
```
ssl_enable=YES
ssl_tlsv1=YES
ssl_sslv2=NO
ssl_sslv3=NO
```
5、 接下来,使用 `#` 字符注释掉下面的行,如下所示:
```
#rsa_cert_file=/etc/ssl/private/ssl-cert-snakeoil.pem
#rsa_private_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
```
然后,添加以下行以定义 SSL 证书和密钥文件的位置(LCTT 译注:或径直修改也可):
```
rsa_cert_file=/etc/ssl/private/vsftpd.pem
rsa_private_key_file=/etc/ssl/private/vsftpd.pem
```
6、现在,我们也可以阻止匿名用户使用 SSL 登录,并且迫使所有的非匿名登录使用安全的 SSL 链接来传输数据和在登录期间发送密码:
```
allow_anon_ssl=NO
force_local_data_ssl=YES
force_local_logins_ssl=YES
```
7、此外,我们可以使用以下选项在 FTP 服务器中添加更多的安全功能 。对于选项 `require_ssl_reuse=YES`,它表示所有的 SSL 数据链接都需重用已经建立的 SSL 会话(需要证明客户端拥有 FTP 控制通道的主密钥),但是一些客户端不支持它,如果没有客户端问题,出于安全原因不应该关闭(默认开启)。(LCTT 译注:原文此处理解有误,译者修改。)
```
require_ssl_reuse=NO
```
此外,我们可以通过 `ssl_ciphers` 选项来设置 vsftpd 允许使用那些加密算法。 这将有助于挫败攻击者使用那些已经发现缺陷的加密算法的尝试:
```
ssl_ciphers=HIGH
```
8、 然后,我们定义被动端口的端口范围(最小和最大端口)。
```
pasv_min_port=40000
pasv_max_port=50000
```
9、 要启用 SSL 调试,把 openSSL 连接诊断记录到 vsftpd 日志文件中,我们可以使用 `debug_ssl` 选项:
```
debug_ssl=YES
```
最后,保存配置文件并且关闭它。然后重启 vsftpd 服务:
```
$ systemctl restart vsftpd
```
### 第三步:在 Ubuntu 上使用 SSL / TLS 连接验证 FTP
10、 执行所有上述配置后,通过尝试[在命令行中使用 FTP](http://www.tecmint.com/sftp-command-examples/) 来测试 vsftpd 是否现在使用了 SSL / TLS 连接,如下所示。
从下面的输出来看,这里有一个错误的信息告诉我们 vsftpd 仅允许用户(非匿名用户)从支持加密服务的安全客户端登录。
```
$ ftp 192.168.56.10
Connected to 192.168.56.10 (192.168.56.10).
220 Welcome to TecMint.com FTP service.
Name (192.168.56.10:root) : ravi
530 Non-anonymous sessions must use encryption.
Login failed.
421 Service not available, remote server has closed connection
ftp>
```
该命令不支持加密服务从而导致了上述错误。因此,要安全连接到启用了加密服务的 FTP 服务器,我们需要一个默认支持 SSL/TLS 连接的 FTP 客户端,例如 FileZilla。
### 第四步:在客户端上安装FileZillaStep来安全地连接FTP
11、FileZilla 是一个强大的,广泛使用的跨平台 FTP 客户端,支持在 SSL/TLS 上的 FTP。为了在 Linux 客户端机器上安装 FileZilla,使用下面的命令。
```
--------- On Debian/Ubuntu ---------
$ sudo apt-get install filezilla
--------- On CentOS/RHEL/Fedora ---------
# yum install epel-release filezilla
--------- On Fedora 22+ ---------
$ sudo dnf install filezilla
```
12、 一旦安装完成,打开它然后点击File=>Sites Manager或者(按Ctrl+S)来获取下面的Site Manager。

*Filezilla Site Manager*
13、 现在,定义主机/站点名字,添加 IP 地址,定义使用的协议,加密和登录类型,如下面的屏幕(使用适用于你方案的值):
点击 New Site 按钮来配置一个新的站点/主机连接。
* Host: 192.168.56.10
* Protocol: FTP – File Transfer Protocol
* Encryption: Require explicit FTP over #推荐
* Logon Type: Ask for password #推荐
* User: 用户名

*在 Filezilla 上配置新的 FTP 站点*
14、 然后从上面的界面单击连接以输入密码,然后验证用于 SSL / TLS 连接的证书,并再次单击确定以连接到 FTP 服务器:

*验证 FTP 的 SSL 证书*
15、现在,你应该通过 TLS 连接成功地登录到了 FTP 服务器,检查连接状态部分,来获取有关下面接口的更多信息。

*连接 Ubuntu 的 FTP 服务器*
16、 最后,让我们在文件夹中从本地的机器传送文件到 FTP 服务器, 查看 FileZilla 界面的下端来查看有关文件传输的报告。

*使用 Filezilla 安全的传输 FTP 文件*
就这样! 始终记住,安装 FTP 服务器而不启用加密服务具有某些安全隐患。 正如我们在本教程中解释的,您可以在 Ubuntu 16.04 / 16.10 中配置 FTP 服务器使用 SSL / TLS 连接来实现安全性。
如果你在 FTP 服务器上设置 SSL/TLS 遇到任何问题,请使用以下评论表单来分享您对本教程/主题的问题或想法。
---
作者简介:
Aaron Kili 是 Linux 和 F.O.S.S 爱好者,即将成为 Linux SysAdmin 和网络开发人员,目前是 TecMint 的内容创作者,他喜欢在电脑上工作,并坚信分享知识。
---
via: <http://www.tecmint.com/secure-ftp-server-using-ssl-tls-on-ubuntu/>
作者:[Aaron Kili](http://www.tecmint.com/author/aaronkili/) 译者:[DockerChen](https://github.com/DockerChen) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
8,296 | 微软爱上 Linux:当 PowerShell 来到 Linux 时 | http://www.tecmint.com/install-powershell-in-linux/ | 2017-03-13T08:40:23 | [
"PowerShell",
"脚本",
"微软"
] | https://linux.cn/article-8296-1.html | 在[微软爱上 Linux](/article-7515-1.html) 之后,**PowerShell** 这个原本只是 Windows 才能使用的组件,于 2016 年 8 月 18 日[开源并且成为跨平台软件](/article-7699-1.html),登陆了 Linux 和 macOS。

**PowerShell** 是一个微软开发的自动化任务和配置管理系统。它基于 .NET 框架,由命令行语言解释器(shell)和脚本语言组成。
PowerShell 提供对 **COM** (<ruby> 组件对象模型 <rt> Component Object Model </rt></ruby>) 和 **WMI** (<ruby> Windows 管理规范 <rt> Windows Management Instrumentation </rt></ruby>) 的完全访问,从而允许系统管理员在本地或远程 Windows 系统中 [执行管理任务](http://www.tecmint.com/using-shell-script-to-automate-linux-system-maintenance-tasks/),以及对 WS-Management 和 CIM(<ruby> 公共信息模型 <rt> Common Information Model </rt></ruby>)的访问,实现对远程 Linux 系统和网络设备的管理。
通过这个框架,管理任务基本上由称为 **cmdlets**(发音 command-lets)的 **.NET** 类执行。就像 Linux 的 shell 脚本一样,用户可以通过按照一定的规则将一组 **cmdlets** 写入文件来制作脚本或可执行文件。这些脚本可以用作独立的[命令行程序或工具](http://www.tecmint.com/tag/commandline-tools/)。
### 在 Linux 系统中安装 PowerShell Core 6.0
要在 Linux 中安装 **PowerShell Core 6.0**,我们将会用到微软软件仓库,它允许我们通过最流行的 Linux 包管理器工具,如 [apt-get](http://www.tecmint.com/useful-basic-commands-of-apt-get-and-apt-cache-for-package-management/)、[yum](http://www.tecmint.com/20-linux-yum-yellowdog-updater-modified-commands-for-package-mangement/) 等来安装。
#### 在 Ubuntu 16.04 中安装
首先,导入该公共仓库的 **GPG** 密钥,然后将 **Microsoft Ubuntu** 仓库注册到 **APT** 的源中来安装 **PowerShell**:
```
$ curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
$ curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list | sudo tee /etc/apt/sources.list.d/microsoft.list
$ sudo apt-get update
$ sudo apt-get install -y powershell
```
#### 在 Ubuntu 14.04 中安裝
```
$ curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
$ curl https://packages.microsoft.com/config/ubuntu/14.04/prod.list | sudo tee /etc/apt/sources.list.d/microsoft.list
$ sudo apt-get update
$ sudo apt-get install -y powershell
```
#### 在 CentOS 7 中安裝
首先,将 **Microsoft RedHat** 仓库注册到 **YUM** 包管理器仓库列表中,然后安装 **PowerShell**:
```
$ sudo curl https://packages.microsoft.com/config/rhel/7/prod.repo > /etc/yum.repos.d/microsoft.repo
$ sudo yum install -y powershell
```
### 如何在 Linux 中使用 PowerShell Core 6.0
在这一节中,我们将会简单介绍下 **PowerShell**;我们将会看到如何启动 PowerShell,运行一些基础命令,操作文件、目录和进程。然后学习怎样列出所有可用的命令、显示命令帮助和别名。
输入以下命令来启动 PowerShell:
```
$ powershell
```

*在 Linux 中启动 PowerShell*
你可以通过以下命令来查看 PowerShell 版本:
```
$PSVersionTable
```

*查看 PowerShell 版本*
在 Linux 中运行基本的 PowerShell 命令。
```
get-date [# 显示当前日期]
get-uptime [# 显示开机时间]
get-location [# 显示当前工作目录]
```
#### 在 PowerShell 中操作文件和目录
1、 可以通过两种方法创建空文件:
```
new-item tecmint.tex
或者
"">tecmint.tex
```
然后往里面添加内容并查看文件内容。
```
set-content tecmint.tex -value "TecMint Linux How Tos Guides"
get-content tecmint.tex
```

*在 PowerShell 中创建新文件*
2、 在 PowerShell 中删除一个文件
```
remove-item tecmint.tex
get-content tecmint.tex
```

*在 PowerShell 中删除一个文件*
3、 创建目录
```
mkdir tecmint-files
cd tecmint-files
“”>domains.list
ls
```

*在 PowerShell 中创建目录*
4、 执行长格式的列表操作,列出文件/目录详细情况,包括模式(文件类型)、最后修改时间等,使用以下命令:
```
dir
```

*Powershell 中列出目录长列表*
5、 显示系统中所有的进程:
```
get-process
```

*在 PowerShell 中显示运行中的进程*
6、 通过给定的名称查看正在运行的进程/进程组细节,将进程名作为参数传给上面的命令,如下:
```
get-process apache2
```

*在 PowerShell 中查看指定的进程*
输出中各部分的含义:
* NPM(K) – 进程使用的非分页内存,单位:Kb。
* PM(K) – 进程使用的可分页内存,单位:Kb。
* WS(K) – 进程的工作集大小,单位:Kb,工作集由进程所引用到的内存页组成。
* CPU(s) – 进程在所有处理器上所占用的处理器时间,单位:秒。
* ID – 进程 ID (PID).
* ProcessName – 进程名称。
7、 想要了解更多,获取 PowerShell 命令列表:
```
get-command
```

*列出 PowerShell 的命令*
8、 想知道如何使用一个命令,查看它的帮助(类似于 Unix/Linux 中的 man);举个例子,你可以这样获取命令 **Describe** 的帮助:
```
get-help Describe
```

*PowerShell 帮助手册*
9、 显示所有命令的别名,輸入:
```
get-alias
```

*列出 PowerShell 命令别名*
10、 最后,不过也很重要,显示命令历史记录(曾运行过的命令的列表):
```
history
```

*显示 PowerShell 命令历史记录*
就是这些了!在这篇文章里,我们展示了如何在 Linux 中安装**微软的 PowerShell Core 6.0**。在我看来,与传统 Unix/Linux 的 shell 相比,PowerShell 还有很长的路要走。目前看来,PowerShell 还需要在命令行操作机器,更重要的是,编程(写脚本)等方面,提供更好、更多令人激动和富有成效的特性。
查看 PowerShell 的 GitHub 仓库:<https://github.com/PowerShell/PowerShell>。
请在评论中分享你的观点。
---
作者简介:
Aaron Kili 是一个 Linux 和 F.O.S.S 狂热爱好者,将来的 Linux 系统管理员、web 开发者,目前是 TecMint 的内容编辑,是一个热爱研究计算机与坚定的分享知识的人。
---
via: <http://www.tecmint.com/install-powershell-in-linux/>
作者:[Aaron Kili](http://www.tecmint.com/author/aaronkili/) 译者:[zijung](https://github.com/zijung) 校对:[jasminepeng](https://github.com/jasminepeng)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
8,297 | 支持 Linux 和开源的公司: VMware 成为 Linux 基金会金牌会员 | https://www.linux.com/blog/Linux-Foundation-member/2017/3/companies-support-linux-and-open-source-vmware | 2017-03-13T09:26:00 | [
"VMware",
"Linux 基金会"
] | https://linux.cn/article-8297-1.html | 
[VMware](http://www.vmware.com/) 是云基础架构和企业移动性的全球领导者,多年来一直积极参与开源开发。
**该公司通过 Linux 基金会项目(如 ONAP、Cloud Native Computing Foundation(CNCF)、Cloud Foundry、Open vSwitch 等)稳步提高了开源的参与度。 它刚刚增加了对开源和 Linux 基金会的资金承诺,成为金牌会员。**
VMware 的首席开源官 Dirk Hohndel 在下面的问答中说,开源软件帮助 VMware 加速其开发过程,并为其客户提供更好的解决方案。
“我们认为开源组件是我们产品的重要组成部分,并积极参与许多上游项目,” Hohndel 说。 “我们还继续创造我们自己的新颖有趣的开源项目。”
Hohndel 领导 VMware 的开源项目办公室,对围绕开源项目使用和贡献的努力和战略进行指导,以及在整个公司推动 VMware 与开源社区互动的共同价值观和流程。 加入 VMware 之前,他担任英特尔首席 Linux 和开源技术专家近 15 年,从 20 世纪 90 年代初以来,他一直是 Linux 和开源软件的积极开发者和贡献者。
下面,Hohndel 告诉我们更多关于 VMware 的情况;Linux 和开源如何成为其业务的不可分割的一部分; 以及他们如何参与开源社区。
**Linux.com:VMware 主要做什么?**
Dirk Hohndel:VMware 是云基础设施和数字化工作区技术的全球领导者。 我们帮助客户构建和发展可扩展的生产 IT 环境,作为满足他们需求的内部部署或混合云解决方案。 此外,我们为客户提供现代化的终端用户计算解决方案,使用户能够使用任何设备或平台访问关键应用程序,桌面和服务。
**Linux.com:你们是如何使用 Linux 和开源的?为什么要使用?**
Hohndel:VMware 使用许多开源组件作为我们为客户提供的解决方案的一部分。 Linux 是我们所支持的关键的客户机(和主机)的操作系统,也是在我们的基础架构上运行的许多客户解决方案的基础。
我们认为开源组件是我们产品的重要组成部分,并积极参与许多上游项目。 我们还继续创建我们自己的新颖有趣的开源项目,如 [Project Clarity 设计系统](https://vmware.github.io/clarity/)或 [Project Harbor 容器镜像注册库](https://vmware.github.io/harbor/)。
**Linux.com:你们为什么要增加对 Linux 基金会的资金承诺?**
Hohndel:我们认为 Linux 基金会是更广泛的开源生态系统中的关键联盟之一。 与此同时,在过去几年中,我们稳步增加了与 ONAP、CNCF、Cloud Foundry 等其他项目和基金会的合作。 考虑到它的项目在我们的业务中的作用,增加我们对 Linux 基金会的参与和支持是有意义的。
**Linux.com:你目睹了什么有趣或创新的技术趋势,Linux 和开源软件在这些技术趋势中扮演了什么角色? VMware 如何参与其中?**
Hohndel:IT 基础设施行业正在不断发展。 越来越多的相关解决方案堆栈是围绕开源组件构建的,许多公司正在合作加速整个行业垂直行业的转型。 最近推出的 ONAP 项目是这个趋势的一个很好的例子,VMware 是这个项目的创始白金赞助商之一。
**Linux.com:参与 Linux 和开源社区是如何对您的公司产生改变的?**
Hohndel:VMware 是一家工程驱动的公司。 我们与 Linux 和开源社区的合作帮助我们加速了我们的开发过程,并允许我们与这个领域的其他合作伙伴和客户合作,提供更好的解决方案。
**Linux.com:还有什么重要或即将到来的好消息可以分享?**
Hohndel:对于 VMware,升级到 Linux 基金会的金牌赞助是我们的开源战略的重要组成部分,也是我们迈向更开放,更协作的未来的关键一步。 我们期待在许多 Linux 基金会项目中工作,以创建令客户满意的解决方案。
| 301 | Moved Permanently | null |
8,299 | Linux 中六个最佳 PDF 页面裁剪工具 | http://www.tecmint.com/best-pdf-page-cropping-tools-for-linux/ | 2017-03-15T08:34:00 | [
"PDF"
] | https://linux.cn/article-8299-1.html | PDF(<ruby> <strong> 可移植文档格式 </strong> <rt> Portable Document Format </rt></ruby>)可谓是众所周知,并且可能是当今使用最广泛的文档类型,特别是在可靠呈现和分享文档、软硬件及系统无关性等方面有着很大优势。
事实上,它已经成为了电子文档的业界标准,特别是在互联网上。由于这样的原因,以及越来越多的电子信息分享,很多人从 PDF 文档中得到他们想要的有用信息。

**建议阅读:** [Linux 中的八大 PDF 阅读器](http://www.tecmint.com/linux-pdf-viewers-and-readers-tools/)。
在本文中,我将列举 Linux 系统中最好的六个 PDF 页面裁剪工具。
### 1、 Master PDF 编辑器
[Master PDF 编辑器](https://code-industry.net/masterpdfeditor/) 是一个简单易用、方便却强大的多功能 PDF 编辑器,可以帮助你很好的处理 PDF 文档。
[](http://www.tecmint.com/wp-content/uploads/2017/03/Master-PDF-Editor.png)
*Master PDF 编辑器*
使用它可以很容易地查看、创建和修改 PDF 文件。它还可以将几个文档合成一个文件,以及 [将源文档分割成多个文档](http://www.tecmint.com/split-large-tar-into-multiple-files-of-certain-size/)。
此外,Master PDF 编辑器还可以帮你对 PDF 文档进行注释、签名和加密等等。
#### Master PDF 编辑器的特性
1. 跨平台,可以运行于 Linux、Windows 以及 MacOS
2. 可以创建 PDF 文档
3. 允许修改 PDF 文档中的文本和对象
4. 支持 PDF 文档注释
5. 支持 PDF 创建和填充表单
6. 支持光学文本识别(OCR)
7. 支持多页面操作
8. 支持书签和数字签名
9. 搭载有一个虚拟 PDF 打印机
### 2、 PDF Quench
[PDF Quench](https://github.com/linuxerwang/pdf-quench) 是一个用于 PDF 页面裁剪的图形化 Python 应用。
[](http://www.tecmint.com/wp-content/uploads/2017/03/PDF-Quench.png)
*PDF Quench 编辑器*
它可以让用户以合适的旋转角度来裁剪页面,将裁剪框定义为与 meda 框相同的位置,这有助于处理第二次裁剪的问题。
### 3、 PDF Shuffler
[PDF-Shuffler](https://github.com/jeromerobert/pdfshuffler) 是一个小巧、简单和免费的 python-gtk 应用,由 python-pyPdf 进行图形界面封装而来。
[](http://www.tecmint.com/wp-content/uploads/2017/03/PDF-Shuffler.png)
*PDF Shuffler 编辑器*
通过 PDF-Shuffler,你可以使用一个直观的交互式图形用户界面,来合并或者分割 PDF 文档,以及旋转、裁剪和重组页面。
### 4、 Krop
[Krop](http://arminstraub.com/software/krop) 是一个简单、免费的图形用户界面应用,用于裁剪 PDF 文件页面。它是使用 Python 编写的,并且只能运行于 Linux 系统。
[](http://www.tecmint.com/wp-content/uploads/2017/03/Krop-PDF-Editor.png)
*Krop PDF 编辑器*
它依赖于 PyQT、python-poppler-qt4 和 pyPdf 或 PyPDF2 来支持自身的全部功能。其主要特性之一就是可以如同 eReaders 一样,将页面分为多个子页面以适应设备屏幕尺寸的限制。
### 5、 Briss
[Briss](http://briss.sourceforge.net/) 是一个简单、免费的跨平台程序,用于裁剪 PDF 文档,它可以工作于 Linux、Windows 和 Mac OSX。
[](http://www.tecmint.com/wp-content/uploads/2017/03/Briss-PDF-Editor.png)
*Briss PDF 编辑器*
其中,有一个显著的特性是其直观的图形用户界面允许你直接以可视的方式在页面上调整矩形框来精确定义裁剪区域,当然还有其他更多有用的特性。
### 6、 PDFCrop
[PDFCrop](http://pdfcrop.sourceforge.net/) 是一个 Linux 平台的 PDF 裁剪应用,使用 Perl 语言编写。它要求系统已安装好 ghostscript (用于寻找 PDF 文件的页面边界框) 和 PDFedit (用于裁剪和重设页面尺寸)。
它能让你裁剪掉 PDF 页面中的白色边界,并重新调整页面大小以适应标准尺寸的纸张;所得到的页面打印后通常更具可读性和引人注目。
它主要用于学术界人士,使他们能够用习惯的方式来打印下载的期刊论文。PDFCrop 也适用于这些人:他们经常接收到以信纸大小来组织页面的 PDF 文档,但却需要打印为 A4 纸大小 (或者是相反的情况)。
至此,文毕。在本文中,我列举了在 Linux 中六个最好用的 PDF 页面裁剪工具及其主要特性。是不是还有其他的工具被我遗漏了呢?请通过评论向我分享哦。
---
作者简介:
Aaron Kili 是一名 Linux 和 F.O.S.S 忠实拥护者、高级 Linux 系统管理员、Web 开发者,目前在 TecMint 是一名活跃的博主,热衷于计算机并有着强烈的知识分享意愿。
---
译者简介:
[GHLandy](http://GHLandy.com) —— 生活中所有欢乐与苦闷都应藏在心中,有些事儿注定无人知晓,自己也无从说起。
---
via: <http://www.tecmint.com/best-pdf-page-cropping-tools-for-linux/>
作者:[Aaron Kili](http://www.tecmint.com/author/aaronkili/) 译者:[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,300 | 如何写出绝佳的发行说明 | https://opensource.com/article/17/3/how-to-improve-release-notes | 2017-03-16T08:07:00 | [
"发现",
"公告"
] | https://linux.cn/article-8300-1.html | 
*图像来源: opensource.com*
恭喜你!你已经准备发布你的软件包的最新版本了。现在,你需要保证你的发行说明整洁有序。当然,你可以写上一句“bug 修复以及性能改进”然后就算完成,但这并不能给你的用户传达任何信息。
发行说明同时用于支持和营销。它可以告诉你的的用户,为什么这个发布版本对他们很重要,并可以向潜在用户展示你的软件。所以,你会希望它的内容简洁、易懂,最重要的是:目的明确。写发行说明的方式不止一种,所以本文只是一般提议,并不是一个强制要求。
现在一个流行的趋势,是将发行说明写成包含一堆蠢事的叙事文。如果你想这么写,那请自便 —— 不过要记住,笑话通常是上下文相关的,你觉得很滑稽的内容,可能在你的读者眼里会变得索然无味。而且,不要忘了将那些重要信息写进来。
### 入门
你能从本文里学到的最主要的经验,可能就是这一条:你的发行说明要写给读它的人看。对于面向用户的软件,发行说明中要注重面向用户的行为,而不是软件的内部实现。举个例子:写“点击‘取消’按钮会把你的电脑点着”,而不要写“在 cancelThatThing 函数中,thermalEventTrigger 的默认值被设为 True”。
尝试将每一条说明限制在一到两句话。重点在于突出强调重要部分,而不是给出详尽的解释。如果你有一个公开的问题追踪页面,你可以在说明中包含问题链接(或者问题编号),这样关注此问题的读者可以通过链接来查看问题的详细内容。
你并不需要严格按照这种方法来写发行说明,但我比较喜欢下面的格式。开头写上版本号,以及发布日期。对于主要版本,你可能要再写几句话,来突出本次发布的主题。比如,“本次发布的重点在于添加了邮件客户端,因为这是所有软件的最终结束状态。”
### 兼容性更改
如果新版本中包含兼容性或默认行为的变更,你最好将它们着重写出。你的用户、以及提供用户支持的人会感谢你的。在发行说明中描述会遇到行为变更的场景,如何处理变更,以及如果用户对变更不采取行动会导致的后果。对于某些次要版本,你可能没有任何会导致不兼容的变更,那你可以省略此部分。
### 功能及改进
现在,你该炫耀你的软件包含的那些酷的、新奇的东西了,但是要记得站在用户的角度来写。比如,“该软件现在支持自动发现午餐照片,并将其发布到 Instagram 上。”
### 已解决的问题
没有软件是完美的,所以在这部分中你需要告诉读者,你的团队为了使这个项目更好一点而做的所有努力工作。因为那些不好的行为已经被解决了,所以应该用过去式来写这一部分。如果某个 bug 的产生原因很明确,写上相关信息。一些项目还在文档此节中包含修复的 bug。
### 已知问题
因为没有软件是完美的,所以永远会存在未解决的 bug。在这一节中,你需要列出这些已知的问题。你不需要列出所有的问题;主要是影响功能的错误,尤其是那些在上个版本发布后发现的 bug。这一部分的文字用将来时态写出。当你把这些问题解决,你只需要改变动词的时态,然后把它们移到上个部分即可。
---
作者简介:
Ben Cotten - Ben Cotten 是一个受过专业训练的气象学家,但他现在是一位高性能计算工程师。Ben 是一位[循环计算](https://cyclecomputing.com/)领域的布道者。他是 Fedora 的用户及贡献者,与他人一同创办了一个本地开源会议组,是开源计划的成员,还是软件自由保护的支持者。你可以在 Twitter 上找到他(@FunnelFiasco)。
---
译者简介:
[StdioA](https://www.stdioa.com/) —— Pythoner, Player.
---
via: <https://opensource.com/article/17/3/how-to-improve-release-notes>
作者:[Ben Cotton](https://opensource.com/users/bcotton) 译者:[StdioA](https://github.com/StdioA) 校对:[jasminepeng](https://github.com/jasminepeng)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 200 | OK | Congratulations! You're ready to ship the latest release of your software package. Now you need to make sure your release notes are in order. Sure, you could just slap "bug fixes and performance improvements" on the box and call it a day, but that doesn't really tell your users anything.
Release notes are for both support and marketing. They tell your current users why this new release is important to them and showcase your software to potential users. Thus, you want to make the content clear, understandable, and most importantly, relevant. There's no one way to write release notes, so this is general advice, not an edict.
One popular trend is to make the release notes a narrative that includes a lot of silliness. If that's your thing, go for it—just remember that jokes are often context-sensitive, and what you think is hilarious might be totally lost on your readers. And, of course, you can't forget to include the important information.
## Getting started
Perhaps the single most important takeaway from this article is to write your release notes for the people who will read them. For user-facing software, focus on the user-facing behavior instead of the internal implementation. For example, say, "Clicking the 'Cancel' button will light your computer on fire," instead of "thermalEventTrigger defaulted to True in the cancelThatThing function."
Try to limit each note to a sentence or two. The point is to highlight the important part, not give a detailed explanation. If you have a public issue tracker, include a link (or at least an issue number) where readers can go find details if they're so inclined.
You don't have to lay out your release notes this way, but I like the following format. Start with the version number and release date. For major releases, you might also include a few sentences to highlight the major theme. For example, "This release focuses on adding an email client, because that's the eventual end state of all software."
## Compatibility changes
If the new release introduces changes in compatibility or default behavior, highlight those explicitly. Your users will thank you, as will anyone who provides user support. Describe the cases where the behavior change will be encountered, how to address the change, and what happens if the user doesn't act on the change. For minor releases, you probably don't have any incompatible changes, so you can leave out this section.
## Features and enhancements
Now is the time to brag about all of the cool, new stuff your software does, but remember to focus on the user's perspective. For example, "The software now supports the automatic detection of pictures of lunch and posts them to Instagram."
## Issues resolved
No software is perfect, and this is the section where you tell readers about all of the hard work your team did to make the project a little better. Write these notes in the past tense, because the bad behavior is dead and gone. If it's clear where the bug was introduced, include that information. Some projects include bugs in the documentation in this section as well.
## Known issues
Because no software is perfect, there are always bugs left unsquashed. This section is the place to list those. You don't have to confess everything; focus on the bugs that impact functionality, especially if they were discovered since the last release. Write these in the future tense, and when you've addressed it, you just have to change the verb tense and it's ready to move up a section.
## 6 Comments |
8,301 | 如何在 Linux 中重置 MySQL 或者 MariaDB 的 root 密码 | http://www.tecmint.com/reset-mysql-or-mariadb-root-password/ | 2017-03-17T08:55:00 | [
"MySQL",
"MariaDB",
"密码"
] | https://linux.cn/article-8301-1.html | 如果你是第一次设置 MySQL 或 MariaDB 数据库,你可以直接运行 `mysql_secure_installation` 来实现基本的安全设置。

其中一项是设置数据库 root 帐户的密码 - 你必须保持私密,并仅在绝对需要时使用。如果你忘记了密码或需要重置密码(例如,当数据库管理员换人或被裁员!),这篇文章会派上用场。我们将解释如何在 Linux 中重置或恢复 MySQL 或 MariaDB 的 root 密码。
**建议阅读:** [更改 MySQL 或 MariaDB 的 root 密码](/article-8328-1.html)。
虽然我们将在本文中使用 MariaDB,但这些说明同样也适用于 MySQL。
### 恢复 MySQL 或者 MariaDB 的 root 密码
开始之前,先停止数据库服务并检查服务状态,我们应该可以看到先前设置的环境变量:
```
------------- SystemD -------------
# systemctl stop mariadb
------------- SysVinit -------------
# /etc/init.d/mysqld stop
```
接下来,用 `--skip-grant-tables` 选项启动服务:
```
------------- SystemD -------------
# systemctl set-environment MYSQLD_OPTS="--skip-grant-tables"
# systemctl start mariadb
# systemctl status mariadb
------------- SysVinit -------------
# mysqld_safe --skip-grant-tables &
```

*使用 skip tables 启动 MySQL/MariaDB*
这可以让你不用 root 密码就能连接到数据库(你也许需要切换到另外一个终端上):
```
# mysql -u root
```
接下来,按照下面列出的步骤来。
```
MariaDB [(none)]> USE mysql;
MariaDB [(none)]> UPDATE user SET password=PASSWORD('YourNewPasswordHere') WHERE User='root' AND Host = 'localhost';
MariaDB [(none)]> FLUSH PRIVILEGES;
```
最后,停止服务,取消环境变量设置并再次启动服务:
```
------------- SystemD -------------
# systemctl stop mariadb
# systemctl unset-environment MYSQLD_OPTS
# systemctl start mariadb
------------- SysVinit -------------
# /etc/init.d/mysql stop
# /etc/init.d/mysql start
```
这可以让先前的改变生效,允许你使用新的密码连接到数据库。
### 总结
本文我们讨论了如何重置 MariaDB/MySQL 的 root 密码。一如往常,如果你有任何问题或反馈请在评论栏中给我们留言。我们期待听到你的声音。
---
作者简介:
Gabriel Cánepa - 一位来自阿根廷圣路易斯梅塞德斯镇 (Villa Mercedes, San Luis, Argentina) 的 GNU/Linux 系统管理员,Web 开发者。就职于一家世界领先级的消费品公司,乐于在每天的工作中能使用 FOSS 工具来提高生产力。
---
via: <http://www.tecmint.com/reset-mysql-or-mariadb-root-password/>
作者:[Gabriel Cánepa](http://www.tecmint.com/author/gacanepa/) 译者:[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,302 | 漫画赏析:孩子眼中的“二叉树” | http://turnoff.us/geek/binary-tree/ | 2017-03-14T09:00:00 | [
"漫画",
"二叉树"
] | https://linux.cn/article-8302-1.html | 著名的 [turnoff.us](http://turnoff.us/) 有很多有趣的漫画,比如这一副《[二叉树](http://turnoff.us/geek/binary-tree/)》。

在孩子的眼中,世界是另外一种样子。可能在我们大人看来,司空见惯的一些事物,已经掩盖了我们的想象力,但是童稚未去的孩子们往往能观察到我们所忽视的一面,所以,多陪陪孩子吧(首先,你得有个……)。
比如上图中,我们看到的是一颗“普普通通”的树,而孩子看到的是“二进制的树”(二叉树)。(LCTT 译注:此处 Binary Tree 做一语双关状,孩子眼中是“二进制树”,而在搞计算机的老爸听来却是“二叉树”)
| 301 | Moved Permanently | null |
8,303 | 如何修改 Linux 的 GRUB 启动背景 | https://www.howtoforge.com/tutorial/how-to-change-the-linux-splash-screen/ | 2017-03-14T08:35:00 | [
"GRUB"
] | https://linux.cn/article-8303-1.html | **何为 GRUB 背景( Splash )?**
GRUB 背景( Splash )只不过是一张图像,在 Linux 系统启动的时候显示为背景。你可能知道 Grub (**GR**and **U**nified **B**ootloader 的简写) 是主流 Linux 发行版中广泛使用的<ruby> 启动装载程序 <rp> ( </rp> <rt> bootloader </rt> <rp> ) </rp></ruby>。以 RedHat 为例,你会发现它在系统启动之时显示为空白或者是一个黑色背景。

GRUB 背景( Splash )的相关定义在 `grub.conf` 文件中,并且 splash 背景图像应该存储在 `/boot` 分区中。如果你觉得默认的空白屏相当无趣,同时又想按照自己的意愿来修改它,那么赶紧阅读下方的每个步骤吧。
### 开始前需要哪些准备工作
1. ImageMagick (仅在命令行中使用) 或者 GIMP (GUI 中使用)
2. 一个样例图像
### 使用 GUI 修改 Grub 的 Splash 背景
首先然我们来使用 GUI 来进行操作吧,这里我们使用 GIMP 来作为图像编辑器。
**步骤 1**、 使用 GIMP 打开图像 (路径为:<ruby> 应用 <rp> ( </rp> <rt> Applications </rt> <rp> ) </rp></ruby> --> <ruby> 图像 <rp> ( </rp> <rt> Graphics </rt> <rp> ) </rp></ruby> --><ruby> GIMP 程序 <rp> ( </rp> <rt> GNU Image Manipulation Program </rt> <rp> ) </rp></ruby>)
**步骤 2**、 现在我们需要按实际情况将图像缩放到 640x480 大小。为此,需要点击 <ruby> 图像 <rp> ( </rp> <rt> Image </rt> <rp> ) </rp></ruby> --> <ruby> 缩放图像 <rp> ( </rp> <rt> Scale Image </rt> <rp> ) </rp></ruby>。记住,要如下图参数进行设置。修改宽度为 640,高度为 480。其他保持不变。

点击<ruby> 缩放 <rp> ( </rp> <rt> Scale </rt> <rp> ) </rp></ruby>按钮
**步骤 3**、 然后,我们需要索引图像,让它仅使用 14 色。为此,点击 <ruby> 图像 <rp> ( </rp> <rt> Image </rt> <rp> ) </rp></ruby> --> <ruby> 模式 <rp> ( </rp> <rt> Mode </rt> <rp> ) </rp></ruby> --> <ruby> 索引 <rp> ( </rp> <rt> Indexed </rt> <rp> ) </rp></ruby>。点选 <ruby> 生成最优调色板 <rp> ( </rp> <rt> generate optimum palette </rt> <rp> ) </rp></ruby> 选项,并设置<ruby> 颜色最大值 <rp> ( </rp> <rt> maximum number of colors </rt> <rp> ) </rp></ruby> 为 14 (如下)。

点击 <ruby> 转换 <rp> ( </rp> <rt> convert </rt> <rp> ) </rp></ruby>按钮
**步骤 4**、 保存文件。这里以文件名为 “UxTechno.xpm” 来保存。

**步骤 5**、 以 Zip 方式压缩文件。为此,转到文件的保存位置 --> 右击并选择<ruby> 压缩 <rp> ( </rp> <rt> Compress </rt> <rp> ) </rp></ruby> 选项,选择 gzip 方法来压缩。
[](https://www.howtoforge.com/images/how_to_change_the_linux_splash_screen/big/compress.JPG)
**步骤 6**、 现在复制或移动 "UxTechno.xpm.gz" 到 `/boot/grub/UxTechno.xpm.gz`。
**步骤 7**、 这一步,打开 `/boot/grub/grub.conf` 文件编辑 `splashimage` 参数如下,并保存文件。
最后,文件的内容应该是像这样的:
```
# grub.conf
generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE: You have a /boot partition. This means
that # all kernel and initrd paths are relative to /boot/, eg. # root
(hd0,0) # kernel /vmlinuz-version ro root=/dev/sda2 # initrd
/initrd-[generic-]version.img #boot=/dev/sda default=0 timeout=5
splashimage=(hd0,0)/grub/UxTechno.xpm.gz
hiddenmenu
title Red Hat Enterprise Linux (2.6.32-220.el6.x86_64)
root (hd0,0)
kernel /vmlinuz-2.6.32-220.el6.x86_64 ro root=UUID=1d8c5075-1a5b-4fdc-ba15-0458b65c6012 rd_NO_LUKS rd_NO_LVM LANG=en_US.UTF-8 rd_NO_MD quiet SYSFONT=latarcyrheb-sun16 rhgb
crashkernel=auto KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM initrd
/initramfs-2.6.32-220.el6.x86_64.img
```
当你重启服务器之后,你讲看到如下效果的 splash 背景图像:

### 使用命令行修改 Grub 的 Splash 背景
如果说你是命令行的超级粉丝,那就使用如下方法吧。
**步骤 1**、 开始之前,我们需要修改图像的像素分辨率。为此,我们还需要在 Linux 系统上安装好 ImageMagick。在 CentOS / RHEL 上使用如下命令来进行交叉检查。
```
# rpm -qa|grep -i ImageMagick
```
如果命令没有返回输出 (即空白),这意味这你的系统上还没有安装 ImageMagick。你必须运行下面的命令来安装它。
```
# yum install ImageMagick
```
安装好了重新复核一下,你会得到类似如下的输出:
```
# rpm -qa|grep -i ImageMagick
ImageMagick-6.5.4.7-5.el6.x86_64
```
然后,继续接下来的配置。这里我使用 UxTechno 的 logo 来做 splash 背景图像。
**步骤 2**、 使用如下命令来转换像素深度。
```
# convert -depth 8 -colors 14 -resize 640x480 uxtechno_logo.jpg uxtechno_logo.xpm
```
上述选项的意义如下:
1. 最大使用 14 色
2. 分辨率为 640x480
3. 使用 xpm 格式
**步骤 3**、 以 Zip 方式压缩文件。
```
# gzip uxtechno_logo.xpm
```
**步骤 4**、 复制文件到 `/boot` 分区。
```
# cp uxtechno_logo.xpm.gz /boot/grub/
```
**步骤 5**、 在 `/boot/grub/grub.conf` 文件中修改 `splashimage` 参数如下,并保存文件。
```
splashimage=(hd0,0)/grub/uxtechno_logo.xpm
```
**步骤 6**、 最后,使用 `reboot` 命令重启服务器。启动界面将显示使用 GUI 方式第 7 步中的图像。
(题图原图在 [wallconvert.com](http://www.wallconvert.com/converted/abstract-world-map-wallpapers-1920x1080-175289.html))
---
译者简介:
[GHLandy](http://GHLandy.com) —— 生活中所有欢乐与苦闷都应藏在心中,有些事儿注定无人知晓,自己也无从说起。
---
via: <https://www.howtoforge.com/tutorial/how-to-change-the-linux-splash-screen/>
作者:[MANMOHAN MIRKAR](https://www.howtoforge.com/tutorial/how-to-change-the-linux-splash-screen/) 译者:[GHLandy](https://github.com/GHLandy) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 200 | OK | # How to change the Linux Boot Splash screen
**What is a Splash screen?**
A splash screen is nothing but the picture that's gets displayed in the background while booting the Linux operating system. You might be knowing that Grub (**GR**and **U**nified **B**ootloader) is the commonly used famous bootloader among major Linux distributions. If you take Redhat as an example, it displays a blank or black background during the booting of the system.
The splash screen definitions are defined in the grub.conf file and the splash screen image file resides in the /boot partition. If you are bored of the default blank screen and want to change it to whatever you like, then just perform the steps below to change it.
## What we need to proceed.
1. ImageMagick (Only required For command Line Method): or GIMP (For GUI Method)
2. A sample image.
Change the Grub splash screen by using the GUI
Let's proceed with the GUI method in which we will use GIMP as image editor.
**Step 1**. Open the image using GIMP (follow the path; Applications --> Graphics --> GNU Image Manipulation Program )
**Step 2**. Now we need to scale the image size to 640 x 480 for proper implementation. For this, go to option Image--> Scale Image. Keep in mind below specs for this. Change Width to 640 and Height to 480. Do not change rest of the things.
Click on the **Scale** button.
**Step 3:** Then we need to index our image so that only 14 colors are used. To do this, go to option Image --> Mode --> Indexed. Tick the "generate optimum palette" option and enter 14 as the maximum number of colors (as shown below).
**Step 4:** Save the file. I'll use the name "UxTechno.xpm" below:
**Step 5: **Zip the file. To do this, go to the location of the file --> Right click on it and select the "Compress" Option. Then select "gzip" as compression method:
**Step 6:** Now copy or move "UxTechno.xpm.gz" file to the location /boot/grub/UxTechno.xpm.gz**Step 7:** Now edit the line splashimage parameter in the /boot/grub/grub.conf File as shown below and save the file. The final content shall look like this:
# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE: You have a /boot partition. This means that # all kernel and initrd paths are relative to /boot/, eg. # root (hd0,0) # kernel /vmlinuz-version ro root=/dev/sda2 # initrd /initrd-[generic-]version.img #boot=/dev/sda default=0 timeout=5 splashimage=(hd0,0)/grub/UxTechno.xpm.gz
hiddenmenu
title Red Hat Enterprise Linux (2.6.32-220.el6.x86_64)
root (hd0,0)
kernel /vmlinuz-2.6.32-220.el6.x86_64 ro root=UUID=1d8c5075-1a5b-4fdc-ba15-0458b65c6012 rd_NO_LUKS rd_NO_LVM LANG=en_US.UTF-8 rd_NO_MD quiet SYSFONT=latarcyrheb-sun16 rhgb crashkernel=auto KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM initrd /initramfs-2.6.32-220.el6.x86_64.img
When you reboot the server, you will see your customized boot splash image as below:
## Change the Grub splash screen on the command line
If you are a big fan of the command line, then follow this method.
**Step 1:**
Before proceeding, we need to change the image pixel resolution. For this purpose, we should have the ImageMagick software installed on the Linux system. Cross check this using below command on CentOS / RHEL.
rpm -qa|grep -i ImageMagick
IWhen the command returns no (blank) output, then this means you don't have ImageMagick installed on your system. You have to install it using the below command.
yum install ImageMagick
When you recheck, you will get similar output as below:
rpm -qa|grep -i ImageMagick
ImageMagick-6.5.4.7-5.el6.x86_64
So let's proceed with the configuration. I have taken the UxTechno Logo as splash screen image.
**Step 2: **Covert the pixel depth using below command:
convert -depth 8 -colors 14 -resize 640x480 uxtechno_logo.jpg uxtechno_logo.xpm
Definition of above option is as follows:
- It has to be max 14 colors.
- It has got to be 640x480 resolution.
- It should be in xpm format.
**Step 3: **Then** **gzip the file.
gzip uxtechno_logo.xpm
**Step 4: **Copy the file to the /boot partition.
cp uxtechno_logo.xpm.gz /boot/grub/
**Step 5: **Change the *splashimage* parameter in the /boot/grub/grub.conf file as below & save the file.
splashimage=(hd0,0)/grub/uxtechno_logo.xpm
**Step 6:** Finally reboot the server using the reboot command. The boot screen will display the splash image as shown in step 7 of the GUI install procedure. |
8,304 | 开源 ERP 软件 Odoo 提速指南 | https://www.rosehosting.com/blog/how-to-speed-up-odoo/ | 2017-03-14T10:00:00 | [
"ERP",
"Odoo",
"openerp"
] | https://linux.cn/article-8304-1.html | 
Odoo 是最流行的 ERP(企业资源计划)软件,它由 Python 编写,使用 PostgreSQL 作为后端数据库。Odoo 社区版是免费的开源软件,它囊括了项目管理,生产、财务、记账和销售管理,仓储管理,人力资源管理,甚至还有更多项目。里面包含了 30 个核心模块,以及超过 3000 个社区模块。Odoo 部署了大量的模块,数据库里也包含了庞大的数据等等,这些都使得这个软件比较复杂,可能会导致效率低下。Odoo 的两个主要瓶颈在于磁盘访问,以及数据库查询时间。
为了提升 Odoo 实例的性能,你可以:
* 使用一个快速磁盘驱动器来存储(最好是 SSD)。
* 使用[内存充足的 Linux VPS](https://www.rosehosting.com/linux-vps-hosting.html)。
* 在 Odoo 中激活<ruby> 多处理器模式 <rt> multiprocessing mode </rt></ruby>。
* 正确配置并优化 PostgreSQL 服务。
### 获得一台有着更多内存的 SSD VPS
正如我们先前提到的,随机磁盘访问速度是 Odoo 的主要瓶颈之一。因此,要确保 Odoo 部署在一台[基于 SSD 的 VPS](https://www.rosehosting.com/linux-vps-hosting.html) 上。由于 Odoo 是一个对资源十分敏感的应用,因此始终要把它安装在一台有着更多 RAM 的 VPS 上,如果可能,将整个 Odoo 实例及其数据库加载到 RAM 中。固态磁盘驱动器尤其以随机存取见长,而且由于 SSD 没有任何活动部件,它们能够取得数百倍于传统机械硬盘驱动器的随机存取 IOPS(LCTT译注:即每秒读写操作的次数)。如果服务器没有采用 SSD 来驱动或提速,那么不管你对 Odoo 做多少优化和配置都无济于事,它仍然会很慢。所以,获得正确的主机来部署 Odoo 是提升其性能的最重要因素。
其它 Odoo 优化包括:
### 在 Odoo 配置中启用多处理器选项
要实现此功能,请定位到 openerp-server 二进制文件:
```
#updatedb
#locate openerp-server
/usr/bin/openerp-server
```
执行以下命令:
```
#/usr/bin/openerp-server --help
```
该命令的输出结果如下:
```
Usage: openerp-server [options]
Options:
--version show program's version number and exit
(...)
Multiprocessing options:
--workers=WORKERS Specify the number of workers, 0 disable prefork mode.
--limit-memory-soft=LIMIT_MEMORY_SOFT
Maximum allowed virtual memory per worker, when
reached the worker be reset after the current request
(default 671088640 aka 640MB).
--limit-memory-hard=LIMIT_MEMORY_HARD
Maximum allowed virtual memory per worker, when
reached, any memory allocation will fail (default
805306368 aka 768MB).
--limit-time-cpu=LIMIT_TIME_CPU
Maximum allowed CPU time per request (default 60).
--limit-time-real=LIMIT_TIME_REAL
Maximum allowed Real time per request (default 120).
--limit-request=LIMIT_REQUEST
Maximum number of request to be processed per worker
(default 8192).
```
工作进程的数量应该和分配到 VPS 的 CPU 核心数一样,或者,如果你想为 PostgreSQL 数据库、cron 任务、或者其它和 Odoo 实例安装在同一台 VPS 上的其它应用预留出一些 CPU 核心,那么你可以将工作进程数设置为一个比 VPS 上可用 CPU 核心更低的值,以避免资源耗尽。
`limit-memory-soft` 和 `limit-memory-hard` 参数不言自明,你可以使用默认值,也可以根据 VPS 上的实际可用 RAM 来进行修改。
例如,如果你的 VPS 有 8 个 CPU 核心,以及 16 GB 内存,那么你可以将工作进程数设置为 17(CPU 核心数 x 2 + 1),`limit-memory-soft` 总值设置为 640 x 17 = 10880 MB,而 `limit-memory-hard` 总数设置为 68MB x 17 = 13056 MB,这样,Odoo 就会有总计达 12.75 GB 的 RAM。
例如,在一台拥有 16 GB RAM 和 8 个 CPU 核心的 VPS 上,编辑 Odoo 配置文件(如 `/etc/odoo-server.conf`),并添加以下行:
```
vi /etc/odoo-server.conf
```
```
workers = 17
limit_memory_hard = 805306368
limit_memory_soft = 671088640
limit_request = 8192
limit_time_cpu = 60
limit_time_real = 120
max_cron_threads = 2
```
别忘了重启 Odoo 让修改生效。
### 正确配置并优化 PostgreSQL
对于 PostgreSQL 优化,及时将它更新到最新版本是一个不错的主意。在 PostgreSQL 配置文件(`pg_hba.conf`)中,有两个设置需要修改:`shared_buffers` 和 `effective_cache_size`。将 `shared_buffers` 设置为可用内存的 20%,`effective_cache_size` 设置为可用内存的 50%。
例如,如果 Odoo 安装到了一台 16 GB RAM 的 SSD VPS 上,那么在 `pg_hba.conf` 中使用如下设置:
```
vi /var/lib/postgresql/data/pg_hba.conf
```
```
shared_buffers = 3072MB
effective_cache_size = 8192MB
```
重启 PostgreSQL 服务来让修改生效。
同时,也别忘了周期性手动执行 ‘**[VACUUM](https://wiki.postgresql.org/wiki/Introduction_to_VACUUM,_ANALYZE,_EXPLAIN,_and_COUNT)**’。此操作会将陈旧或临时数据清理干净,但请牢记,它会大量占用 CPU 和磁盘使用。
---
via: <https://www.rosehosting.com/blog/how-to-speed-up-odoo/>
作者:[rosehosting.com](https://www.rosehosting.com/) 译者:[GOLinux](https://github.com/GOLinux) 校对:[jasminepeng](https://github.com/jasminepeng)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 200 | OK | Odoo is the most popular ERP (Enterprise Resource Planning) software, written in Python and uses PostgreSQL as database back-end. The Odoo community edition is a free and [open source](https://www.rosehosting.com/blog/best-open-source-hosting-control-panels/) software which includes project management, manufacturing, accounting, billing and sales management, warehouse management, human resources and more. There are about 30 core modules and more than 3000 community modules. Odoo is a complex software, and deploying a number of modules, having huge data inside the database etc. could induce a slowdown. The two major Odoo bottlenecks are disk access and database query time. In this tutorial we will show you how how to speed up Odoo.
In order to increase the performance of an Odoo instance, make sure to use:
- a fast disk drive for storage (preferably SSD)
- a
[Linux VPS with lots of RAM](https://www.rosehosting.com/blog/what-is-linux-vps-hosting/). - activate multiprocessing mode in Odoo.
- configure and optimize the PostgreSQL service properly.
Table of Contents
## 1. Get an SSD VPS with more RAM
Like we mentioned previously, the random disk access speed is one of the major Odoo bottlenecks, so make sure to host Odoo on an [SSD based VPS](https://www.rosehosting.com/managed-vps-hosting.html). Always install Odoo on a VPS with more RAM because Odoo is known as resource intensive application, and load the entire Odoo instance and its database into RAM if possible. Solid state disk drives excel especially in random access and they can achieve random access IOPS hundreds of times higher than conventional mechanical har disk drives because SSDs do not have any moving parts. No matter how much optimizations and configurations you do on your Odoo, if the server is not fast or powered by SSD, your Odoo will be slow. Getting the right hosting for your Odoo is the most important factor of your Odoo’s performance.
[ecko_alert color=”blue”]Did we mention that Odoo is a resource-hungry app? It seems so. But fear not, RoseHosting will provide you the ultimate solution – a performance-tailored [Odoo VPS](https://www.rosehosting.com/odoo-hosting.html) optimized to match your most demanding needs. Get an SSD VPS from us and find out what record-breaking Odoo speed really means. [/ecko_alert]
Other Odoo optimizations include:
## 2. Enable the Multiprocessing option in your Odoo configuration
To do so, locate the openerp-server binary file:
#updatedb #locate openerp-server /usr/bin/openerp-server
Run the following command:
#/usr/bin/openerp-server --help
The output of this command should be like this:
Usage: openerp-server [options] Options: --version show program's version number and exit (...) Multiprocessing options: --workers=WORKERS Specify the number of workers, 0 disable prefork mode. --limit-memory-soft=LIMIT_MEMORY_SOFT Maximum allowed virtual memory per worker, when reached the worker be reset after the current request (default 671088640 aka 640MB). --limit-memory-hard=LIMIT_MEMORY_HARD Maximum allowed virtual memory per worker, when reached, any memory allocation will fail (default 805306368 aka 768MB). --limit-time-cpu=LIMIT_TIME_CPU Maximum allowed CPU time per request (default 60). --limit-time-real=LIMIT_TIME_REAL Maximum allowed Real time per request (default 120). --limit-request=LIMIT_REQUEST Maximum number of request to be processed per worker (default 8192).
The number of workers should be equal to a number of CPU cores allocated to the VPS, or if you want to leave some CPU cores exclusively for the PostgreSQL database, cron jobs or other applications installed on the same VPS where the Odoo instance is installed and running, set the number of workers to a lower value than CPU cores available on the VPS to avoid resources exhaustion.
The limit-memory-soft and limit-memory-hard are self-explanatory, and you should leave them to the default value or modify them depending on the RAM available on the actual VPS.
For example, if you have a VPS with 8 CPU cores and 16 GB of RAM, the number of workers should be 17 (CPU cores * 2 + 1), total limit-memory-soft value will be 640 x 17 = 10880 MB , and total limit-memory-hard 768MB x 17 = 13056 MB, so Odoo will use maximum 12.75 GB of RAM.
For example, on a VPS with 16 GB of RAM and 8 CPU cores, edit the Odoo configuration file (e.g. /etc/odoo-server.conf), and add the following lines to it:
vi /etc/odoo-server.conf
workers = 17 limit_memory_hard = 13690208256 limit_memory_soft = 11408506880 limit_request = 8192 limit_time_cpu = 60 limit_time_real = 120 max_cron_threads = 2
Do not forget to restart Odoo for the changes to take effect.
## 3. Properly configure and optimize PostgreSQL
As for the PostgreSQL optimization, it is a good idea to update to the latest PostgreSQL version whenever a new version comes out. There are two settings in PostgreSQL configuration file (pg_hba.conf) which should be modified: shared_buffers and effective_cache_size. Set shared_buffers to 20% of the available memory, and effective_cache_size to 50% of the available memory.
For example, if Odoo is installed on an SSD VPS with 16 GB of RAM, use the following settings in the postgresql.conf file:
vi /var/lib/postgresql/data/postgresql.conf
shared_buffers = 3072MB effective_cache_size = 8192MB
## 4. Restart PostgreSQL
Restart the PostgreSQL service for the changes to take effect.
## 5. Periodically clean up temporary data
Also, do not forget to run ‘[VACUUM](https://wiki.postgresql.org/wiki/Introduction_to_VACUUM,_ANALYZE,_EXPLAIN,_and_COUNT)‘ manually periodically. ‘Vacuuming’ cleans up stale or temporary data, but please keep in mind that it is heavy on both CPU and disk usage.
Of course, you don’t have to speed up Odoo, if you use one of our
[Odoo VPS Hosting](https://www.rosehosting.com/odoo-hosting.html) services, in which case you can simply ask our expert Linux admins to **speed up Odoo** for you. They are available 24×7 and will take care of your request immediately.
**PS.** If you liked this post, on how to speed up Odoo, please share it with your friends on the social networks using the sharing buttons or simply leave a reply below. Thanks.
Hi,
Thank You for this very helpful article. One question: Why we calculate number of workers by multiplying CPU core by 2, and then adding 1?
TIA,
ReplyAnes
That is the general Odoo rule of thumb.
ReplyAren’t the ‘limit_memory_soft’ and the ‘limit_memory_hard’ options set as virtual memory requirements PER worker and not the total memory requirement for ALL workers? Having read the ‘–help’ ouput the above is a bit confusing, just need some clarification.
ReplyOtherwise, some great tips, thank you!
Hi foks
This article is wrong . In the above you have set the soft limit per worker to 10.8 GB . With 17 workers thats alot more than the 16 GB on your box . Hard limit is also wrong .
You should review these figures .
Thanks
Antony
ReplyThe hard and soft limits are correct.
ReplyHi admin
I am afraid they are not .
–limit-memory-soft
Maximum allowed virtual memory per worker. If the limit is exceeded, the worker is killed and recycled at the end of the current request.
Defaults to 640MB.
You have a soft liit of 10.8 GB with 17 workers on a 16 GB server . You are out by a factor of ten .
ReplyHi admin,
Can you clarify about the limit-memory, are they applied PER worker or PER instance? According to odoo.py help page, they are applied per worker.
Thanks
ReplyHi Anes,
Yes, ‘limit-memory’ is the maximum allowed virtual memory per worker.
ReplyWays to speed up your Odoo site is really amazing blog as when one creates the site he has no idea of getting speed to its best so It really proves helpful and amazing for all of them.
ReplyPlease check your cron job. Try to run run it manually and see why it doesn’t stop.
ReplyIt does indeed seem the limits proposed are actually not correct. The parameters for memory limits are per worker. Yet the proposed setting gives the total for all the workers. If you multiply this by the number of workers you exceed the actual RAM available. Otherwise helpful article. Thanks!
ReplyThanks a ton for very helpful blog with details information.it will be good to know that when I’m running odoo server with workers error of ” bus.bus unavailable ” coming continuously.any idea of that ?
ReplyHi Dipak,
If you had a face about bus.bus unavailable is because the system has activated worker > 0, or you open the longpolling port but there is no services to handle that. By activating worker, the system let longpolling port is also active, so you need to third party services to handle that, for example is like nginx, In nginx you can configured to handle port of longpolling, (openerp-gevent), This is to handle IM Bus for Odoo Chat
Thanks
ReplyHi Admin, the rule of thumbs to calculate the worker just for processor multi thread or we could use it for processor not multi thread ?
ReplyThe multiprocessing mode is enabled whenever the worker count is not 0. If you want to run Odoo in multithreaded mode, you will need to leave the worker count to 0, and if you want to enable multiprocessing mode, you will need to set the number of workers higher than 0.
You can still enable multiprocessing mode even with 1 CPU core. The calculation rule
Reply`(CPU cores * 2 + 1)`
still applies. |
8,305 | 小白指南:在 VirtualBox 中安装 Arch Linux 系统 | https://www.howtoforge.com/tutorial/install-arch-linux-on-virtualbox/ | 2017-03-14T11:21:00 | [
"安装",
"VirtualBox",
"Arch Linux"
] | https://linux.cn/article-8305-1.html | Arch Linux 是专门为 i386 和 x86-64 架构的计算机而设计的基于 Linux 内核的操作系统。其特有的软件包管理器使用 `pacman` 进行完整追踪来将系统应用软件升级到最新版本。 Pacman 是一个用于安装、升级和卸载软件包的管理器。这是一款完全自由而开源的软件,由 Linux 开源社区提供支持。
Arch Linux 也因其丰富的 Wiki 帮助文档而大受推崇。该系统基于二进制的软件包,这些软件包主要是为 i386 的 64 位和 32 位的系统而开发的,同时也为现代的硬件系统提供最佳的性能优化。
你可以参考这篇教程直接在你的本地电脑上安装 Arch Linux 系统,或者你也可以使用你的 Windows 电脑中的 VirtualBox 虚拟机来安装。

### Arch Linux 软件仓库
要在 VirtualBox 中安装 Arch Linux 系统,你得了解该系统的基础软件仓库。软件仓库用于在安装的过程中获取软件包。对于 Arch Linux 系统来说,有很多可用的软件仓库,可以使用 pacman 工具来进行维护。下面列出的是在 VirtualBox 中安装 Arch Linux 系统时用到的一些基础软件仓库列表:
* **core** 软件仓库包括所有的用于对系统进行基本设置的一些软件包,比如启动 Arch Linux 系统和编译软件包。
* **extra** 软件仓库包括 core 软件仓库以外的其它软件包以及与桌面环境相关的软件包。
* **community** 软件仓库包含的是由可信任的 Linux 社区用户维护的软件包,其中的大多数的软件包都会被迁移到核心软件仓库或者额外软件仓库中。
* **Multilib** 软件仓库包括 32 位的软件包以及用于在 64 位操作系统中安装 32 位应用程序的类库。
* **testing** 软件仓库包括那些即将成为 core 或 extra 的软件包。
* **community-testing** 软件仓库主要用于 community 类的测试。
* **multilib testing** 软件仓库跟 testing 软件仓库类似,但是它包含 Multilib 类。
* **gnome-unstable** 软件仓库包括最新的 GNOME 桌面环境。
* **kde-unstable** 软件仓库包括 KDE 最新的发布前软件包。
### 在 VirtualBox 虚拟机中安装 Arch Linux 系统
#### 下载 Arch Linux 系统
要在 VirtualBox 虚拟机中安装 Arch Linux 系统,你最好使用[官网](https://www.archlinux.org/)下载的新版 Arch Linux 系统。你可以选择直接下载或是种子方式下载系统文件,这是一个很安全的下载方式。在安装之前,确保你系统中有 20 GB 的剩余空间和 1 GB 的内存。

#### 在 Oracle VirtualBox 虚拟机管理界面初始化系统安装
打开 Oracle VirtualBox 虚拟机管理界面,点击<ruby> 新建 <rp> ( </rp> <rt> new </rt> <rp> ) </rp></ruby>,输入你想创建的新系统的名称;这里输入的是 “Arch Linux” 。系统会自动选择 Arch Linux 的版本和类型,这取决于你的系统配置。单击*下一步*。

为你的新系统分配内存,最好是 1024 MB 。单击*下一步*,然后点击<ruby> 创建 <rp> ( </rp> <rt> create </rt> <rp> ) </rp></ruby>来创建一个虚拟磁盘。

在下一步中,你将会被询问为新系统选择磁盘类型。通常选择<ruby> VirtualBox 磁盘镜像 <rp> ( </rp> <rt> VirtualBox Disk Image,VDI </rt> <rp> ) </rp></ruby>类型。

选择<ruby> 动态分配 <rp> ( </rp> <rt> dynamically allocated </rt> <rp> ) </rp></ruby>,单击*下一步*。

分配 20 GB 的硬盘大小及存放位置。

现在你可以看到 Arch Linux 系统已创建完成了。点击<ruby> 开始 <rp> ( </rp> <rt> start </rt> <rp> ) </rp></ruby>按钮。

单击<ruby> 浏览 <rp> ( </rp> <rt> browser </rt> <rp> ) </rp></ruby>然后选择你从官网下载的启动磁盘。


点击<ruby> 启动 <rp> ( </rp> <rt> start </rt> <rp> ) </rp></ruby>,然后打开全屏模式。


#### 在 VirtualBox 中启动并安装 Arch Linux 系统
你将会看到 Arch Linux 系统第一个打开界面。单击 “Boot Arch Linux (x86\_64)”, 它用于 64 位系统,或者单击 “Boot Arch Linux (i686)”,用于 32 位系统。

当你单击第一个选项后,系统将开始启动。实际上只是进入到一个临时启动状态,即进入到 Arch Linux 的 Live 系统,并以 root 帐号登录了。

输入下面的命令来检查网络连接。
```
ping google.com
```
这个单词 ping 表示网路封包搜寻。你将会看到下面的返回信息,表明 Arch Linux 已经连接到外网了。这是执行安装过程中的很关键的一点。(LCTT 译注:或许你 ping 不到那个不存在的网站,你选个存在的吧。)

输入如下命令清屏:
```
clear
```
在开始安装之前,你得先为硬盘分区。输入 `fdisk -l` ,你将会看到当前系统的磁盘分区情况。注意一开始你给 Arch Linux 系统分配的 20 GB 存储空间。

#### 硬盘分区
我们打算把这个 20 GB 的磁盘分成三个分区。第一个主分区为 root 分区,大小为 10 GB 。第二个分区为 swap 分区,大小为内存的两倍,为 2048 MB 。第三个是逻辑分区,大小为 8 GB 。

输入下面的命令:
```
cfdisk
```
你将看到 `gpt`、`dos`、`sgi` 和 `sun` 类型,选择 `dos` 选项,然后按回车。

这里你将看到主磁盘空间,大小为 20 GB 。在<ruby> 剩余空间 <rp> ( </rp> <rt> free space </rt> <rp> ) </rp></ruby>按回车来修改分区大小,输入 10 GB 。

按回车并单击<ruby> 主分区 <rp> ( </rp> <rt> primary </rt> <rp> ) </rp></ruby> 。

在可引导选项按回车选择<ruby> 可引导 <rp> ( </rp> <rt> bootable </rt> <rp> ) </rp></ruby>类型。

在<ruby> 写入 <rp> ( </rp> <rt> write </rt> <rp> ) </rp></ruby>选项按回车键将分区信息写入磁盘。

之后输入 `yes` 来应用更改。

现在已经创建完成 10 GB 分区。单击<ruby> 剩余空间 <rp> ( </rp> <rt> free space </rt> <rp> ) </rp></ruby>,输入分区大小 2048 M 。

以同样的方式创建逻辑分区。在<ruby> 退出 <rp> ( </rp> <rt> quit </rt> <rp> ) </rp></ruby>选项按回车键,然后输入下面的命令来清屏:
```
clear
```

输入下面的命令来格式化新建的分区:
```
mkfs.ext4 /dev/sda1
```
这里的 `sda1` 是分区名。使用同样的命令来格式化第二个分区 `sda3` :
```
mkfs.ext4 /dev/sda3
```
格式化 swap 分区:
```
mkswap /dev/sda2
```

使用下面的命令来激活 swap 分区:
```
swapon /dev/sda2
```
输入 clear 命令清屏:
```
clear
```

输入下面的命令来挂载主分区以开始系统安装:
```
mount /dev/sda1 /mnt
```

#### 引导 Arch Linux 启动
输入下面的命令来引导系统启动:
```
pacstrap /mnt base base-devel
```
可以看到系统正在同步数据包。

安装将会开始,需要几分钟。

系统基本软件安装完成后,输入下面的命令来创建 fstab 文件:
```
genfstab /mnt>> /mnt/etc/fstab
```

配置区域、时间和 root 帐号密码。
输入下面的命令来更改系统的根目录为 Arch Linux 的安装目录:
```
arch-chroot /mnt /bin/bash
```
现在来更改语言配置:
```
nano /etc/locale.gen
```

通过删除 `#` 以及按 `control + x` ,按 `y` ,然后再按回车来选择下面的语言配置:

输入下面的命令来激活它:
```
locale-gen
```
按回车。

使用下面的命令来创建 `/etc/locale.conf` 配置文件:
```
nano /etc/locale.conf
```
然后按回车。现在你就可以在配置文件中输入下面一行内容来为系统添加语言:
```
LANG=en_US.UTF-8
```
然后按 `control + x` ,按 `y` ,再按回车。

输入下面的命令来同步时区:
```
ls /usr/share/zoneinfo
```
下面你将看到整个世界的时区列表。

输入下面的命令来选择你所在的时区:
```
ln –s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
```
或者你可以从下面的列表中选择其它名称。

使用下面的命令来设置标准时间:
```
hwclock --systohc --utc
```
硬件时钟已同步。

设置 root 帐号密码:
```
passwd
```
按回车。 然而输入你想设置的密码,按回车确认。

#### 设置主机名和网络
使用下面的命令来设置主机名:
```
nano /etc/hostname
```
然后按回车。输入你想设置的主机名称,按 `control + x` ,按 `y` ,再按回车 。

启用 dhcpcd :
```
systemctl enable dhcpcd
```
这样在下一次系统启动时, dhcpcd 将会自动启动,并自动获取一个 IP 地址:

#### 安装引导加载程序
最后一步,输入以下命令来初始化 grub 安装。输入以下命令:
```
pacman –S grub os-rober
```
然后按 `y` ,将会下载相关程序。

使用下面的命令来将启动加载程序安装到硬盘上:
```
grub-install /dev/sda
```
然后进行配置:
```
grub-mkconfig -o /boot/grub/grub.cfg
```

最后重启系统:
```
reboot
```
然后按回车 。

#### 启动进入到已安装完成的 Arch Linux 系统
选择“启动已存在的操作系统”选项来启动 Virtual Box 虚拟机中的 Arch Linux 系统。

使用 root 帐号和密码登录后,你将进入全新安装好的 Arch Linux 操作系统。

---
via: <https://www.howtoforge.com/tutorial/install-arch-linux-on-virtualbox/>
译者简介:
rusking:春城初春/春水初生/春林初盛/春風十裏不如妳
致谢:十分感谢 **[CoinkWang](https://github.com/CoinkWang)** 的[勘误](https://github.com/LCTT/TranslateProject/pull/9490)。
作者:[Dimitris](https://www.howtoforge.com/tutorial/install-arch-linux-on-virtualbox/) 译者:[rusking](https://github.com/rusking) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 200 | OK | # How to install Arch Linux on VirtualBox
Arch Linux is a Linux-based operating system that is designed for i689 and x86-64 computers. Its unique package manager is responsible for providing updates to the latest software applications using “pacman” with complete tracking. Pacman is the package manager that is used to install, update, and remove the software packages. It is designed entirely for free and open-source software, along with the support from the Linux community.
Arch Linux is also popular for having a comprehensive documentation in form of the community wiki known as ArchWiki. This Linux operating system is based on binary packages that are targeted for i832, 64-bit, and 32-bit systems and optimized for the best performance on modern hardware systems.
You can install Arch Linux directly to your home computer by following this guide but you can also install it on a virtual machine on your Windows computer by using VirtualBox.
## Arch Linux Repositories
To install Arch Linux on Virtual Box, you must know the basic repositories of this Linux-based operating system. A repository is a storage location from where the software packages are retrieved during the installation process. There are multiple repositories available for Arch Linux, which are accessible via pacman and maintained by package maintainers. Here is a list of some of the basic repositories used to install Arch Linux on Virtual Box:
The
**core**repository contains all the packages that are needed to setup the base system like booting Arch Linux and building packages.The
**extra**repository contains extra packages that do not fit in the core involving desktop environment.The
**community**repositoryThe
**Multilib**repository contains 32-bit software and libraries for 32-bit application installation on 64-bit system.The
**testing**repository contains packages that are destined for core or extra repositories.The
**community-testing**repository is for the Linux community.The
**multilib testing**repositoryThe
**gnome-unstable**repository has the latest GNOME desktop environment.The
**kde-unstable**repository contains the latest KDE software before they are been released.
## Install Arch Linux on Virtual Box
### Download Arch Linux
To install Arch Linux on Virtual Box, you must have the latest Arch Linux version that you can download from their [official website](https://www.archlinux.org/). You can pick either the direct download option or torrent download, which is on a secure server. Before the installation, make sure you have 20 MB of free disk space and 1 GB of RAM in your system.
### Initializing Installation with Oracle VM VirtualBox Manager
Open the Oracle VM VirtualBox manager, click on new, and type in the name of the new operating system you want to create; in this case, it is Arch Linux. The system will automatically pick up the type and version of the Arch Linux, based on your system’s configuration. Click on *next*.
Allocate the desired RAM size to your new operating system, which is ideally 1024 MB. Click on *next *and then click on *create*, to create a virtual disk now.
On the next page, you will be asked to select the type of hard disk file you want for your new operating system. Select VirtualBox Disk Image usually.
Choose dynamically allocated and click *next*.
Allocate 20 GB hard disk file location and size.
Now you can see that your Arch Linux operating system is created. Now you can click *start*.
Click on 'browser' and select the startup disk, which you downloaded from the Arch Linux official website.
Click on *start* and then open the full-screen view.
**Booting to Install Arch Linux on Virtual Box**
You will see the first opening page of Arch Linux. Click on “Boot Arch Linux (x86_64), which is for 64-bit or click on “Boot Arch Linux (i686)”, which is for 32-bit.
As soon as you click on the first option, the system will start booting. While it completes the temporary boot, we are basically moving into the live version and are logged in as root user.
Check the Internet connection by typing in the following command.
ping google.com
The word ping stands for packet internet gopher. You will soon see the response that means Arch Linux has activated the Internet connection. This is essential to perform certain installation steps.
Clear the command by typing
clear
Before we start the installation, you should partition your drive. Type *# fdisk – l *and you will see the current system’s disk partition. Focus on the 20 GB hard drives that you allocated to Arch in the beginning.
fsdisk -l
### Partition the hard disk
We are going to partition this 20 GB space into three partitions. The first one is the primary root partition that will be of 10 GB. The second will be the swap partition, which will be twice the initial RAM allocation that will be 2048 MB. The third will be the logical partition that will be 8 GB allocated.
Type the command:
cfdisk
You will see gpt, dos, sgi, and sun. Select the *dos *option and press *enter*.
Here you will see the main disk space, which is 20 GB. To change this, press <enter> on the free space and type **10G**.
Press *enter *and then click on the “**primary**” partition.
Now select the “**bootable**” type by pressing enter on bootable.
Go to *write *and press enter, to write partition to disk.
Then type *yes* to make the changes, successfully.
Now the 10 GB partition is created. Click on *free space *and then enter the partition size of 2048 M.
Now follow the same steps to create the logical partition. Then press enter on *quit* and clear the command by typing
clear
Format the newly partitioned disk by typing:
mkfs.ext4 /dev/sda1
Here *sda1 *is the partition name. Repeat this for the second drive by typing:
mkfs.ext4 /dev/sda3
and for the swap partition,
mkswap /dev/sda2
Activate the swap by typing:
swapon /dev/sda2
and clear the command by typing:
clear
Mount the primary partition to start the installation part by typing:
mount /dev/sda1 /mnt
mkdir /mnt/home
mount /dev/sda3 /mnt/home
### Bootstrap Arch Linux
Bootstrap the system by typing:
pacstrap /mnt base base-devel
You can see that it is synchronizing the data packages.
The installation will start and will take a few minutes.
After the base installation create the fstab file by tying:
genfstab /mnt>> /mnt/etc/fstab
Configure locale, time and root password.
Change the system root to the Arch Linux installation directory by typing:
arch-chroot /mnt /bin/bash
Now to configure the language settings:
nano /etc/locale.gen
Select the following language configuration (en_US.UTF-8 UTF-8) by deleting the # and pressing *control + x, *press *y*, and press *enter*.
Now activate it by typing:
locale-gen
and press *enter*.
Create the /etc/locale.conf file by typing:
nano /etc/locale.conf
then press *enter*. Now you can add your language to the system by adding this line to the file:
LANG=en_US.UTF-8
Then press *control + x *and press *y*, and press *enter*.
Synchronize the zone information by typing:
ls /usr/share/zoneinfo
and you will find a list of all the zones of the world.
To select your zone, type:
ln –s /usr/share/zoneinfo/Asia/Kolkata /etc/localtime
or you can select any name from the below list.
Set the time standard using the command.
hwclock --systohc --utc
And the hardware clock is synchronized.
Set the root user password by typing:
passwd
And press *enter*. Then type your password and press enter.
### Setup hostname and networking
Enter the host name of the network by typing:
nano /etc/hostname
and press *enter*. Now type any name and then press *control + x *and press *y*, and press *enter*.
Enable the dhcpcd by typing:
systemctl enable dhcpcd
and it will be started at next boot time to fetch an IP address automatically.
### Install the Bootloader
The final step, initiate the grub installation. Type:
pacman –S grub os-prober
then press *y *and the download part will begin.
Install the grub boot loader to the hard disk by typing:
grub-install /dev/sda
and configure it:
grub-mkconfig –o /boot/grub/grub.cfg
Finally, exit from chroot and then reboot the system by typing:
exit
reboot
and press *enter.*
### Boot into the installed ArchLinux operating system
Choose “Boot Existing OS” to boot Arch Linux on Virtual Box.
Login with your root name and password, and you will enter your new Arch Linux operating system. |
8,306 | 如何定制 SSH 来简化远程访问 | http://www.tecmint.com/configure-custom-ssh-connection-in-linux/ | 2017-03-15T09:07:00 | [
"ssh"
] | https://linux.cn/article-8306-1.html | SSH (指 SSH 客户端)是一个用于访问远程主机的程序,它使得用户能够 在远程主机上执行命令。这是在登录远程主机中的最受推崇的方法之一,因为其设计目的就是在非安全网络环境上为两台非受信主机的通信提供安全加密。
SSH 使用系统全局以及用户指定(用户自定义)的配置文件。在本文中,我们将介绍如何创建一个自定义的 ssh 配置文件,并且通过特定的选项来连接到远程主机。

### 先决条件:
1. 你必须 [在你的桌面 Linux 上安装好 OpenSSH 客户端](http://www.tecmint.com/install-openssh-server-in-linux/)。
2. 了解通过 ssh 进行远程连接的常用选项。
### SSH 客户端配置文件
以下为 ssh 客户端配置文件:
1. `/etc/ssh/ssh_config` 为默认的配置文件,属于系统全局配置文件,包含应用到所有用户的 ssh 客户端的设置。
2. `~/.ssh/config` 或者 `$HOME/.ssh/config` 为用户指定/自定义配置文件,这个文件中的配置只对指定的用户有效,因此,它会覆盖掉默认的系统全局配置文件中的设置。这也是我们要创建和使用的文件。
默认情况下,用户是通过在 ssh 中输入密码来获取验证的,你可以以一个简单的步骤来 [使用 Keygen 来设置 ssh 无密码登录](http://www.tecmint.com/ssh-passwordless-login-using-ssh-keygen-in-5-easy-steps/)。
注:如果你的系统上不存在 `~/.ssh` 目录,那就手动创建它,并设置如下权限:
```
$ mkdir -p ~/.ssh
$ chmod 0700 ~/.ssh
```
以上的 `chmod` 命令表明,只有目录属主对该目录有读取、写入和执行权限,这也是 ssh 所要求的设置。
### 如何创建用户指定的 SSH 配置文件
该文件并不会被默认创建的,所以你需要使用具有读取/写入权限的用户来创建它。
```
$ touch ~/.ssh/config
$ chmod 0700 ~/.ssh/config
```
上述文件包含由特定主机定义的各个部分,并且每个部分只应用到主机定义中相匹配的部分。
`~/.ssh/config` 文件的常见格式如下,其中所有的空行和以 `‘#’` 开头的行为注释:
```
Host host1
ssh_option1=value1
ssh_option2=value1 value2
ssh_option3=value1
Host host2
ssh_option1=value1
ssh_option2=value1 value2
Host *
ssh_option1=value1
ssh_option2=value1 value2
```
如上格式详解:
1. `Host host1` 为关于 host1 的头部定义,主机相关的设置就从此处开始,直到下一个头部定义 `Host host2` 出现,这样形成一个完整的定义。
2. host1 和 host2 是在命令行中使用的主机别名,并非实际的远程主机名。
3. 其中,如 ssh*option1=value1、ssh*option2=value1 value2 等配置选项将应用到相匹配的主机,可以缩进以看起来更整齐些。
4. 对于 ssh\_option2=value1 value2 这样的选项,ssh 执行时会按照顺序优先使用 value1 的值。
5. 头部定义 `Host *` (其中 `*` 为匹配模式/通配符,匹配零个或多个字符) 会匹配零个或者多个主机。
仍旧以上述的格式为例,ssh 也是也这样的形式类读取配置文件的。如果你执行 ssh 命令来访问远程主机 host1,如下:
```
$ ssh host1
```
以上 ssh 命令会进行一下动作:
1. 匹配配置文件中主机别名 host1,并使用头部定义中的各个设置项。
2. 继续匹配下一个主机定义,然后发现命令行中提供的主机名没有匹配的了,所以接下来的各个设置项会被略过。
3. 最后执行到最后一个主机定义 `Host *`, 这会匹配所有的主机。这里,会将接下来的所有设置选项应用到所有的主机连接中。但是它不会覆写之前已经有主机定义的那些选项。
4. ssh host2 与此类似。
### 如何使用用户指定的 SSH 配置文件
在你理解了 ssh 客户端配置文件的工作方式之后,你可以通过如下方式来创建它。记得使用你的服务器环境中对应的选项、值 (主机别名、端口号、用户名等)。
通过你最喜欢的编辑器来打开配置文件:
```
$ vi ~/.ssh/config
```
并定义必要的部分:
```
Host fedora25
HostName 192.168.56.15
Port 22
ForwardX11 no
Host centos7
HostName 192.168.56.10
Port 22
ForwardX11 no
Host ubuntu
HostName 192.168.56.5
Port 2222
ForwardX11 yes
Host *
User tecmint
IdentityFile ~/.ssh/id_rsa
Protocol 2
Compression yes
ServerAliveInterval 60
ServerAliveCountMax 20
LogLevel INFO
```
以上 ssh 配置文件的详细解释:
1. `HostName` - 定义真正要登录的主机名,此外,你也可以使用数字 IP 地址,不管是在命令行或是 HostName 定义中都允许使用其中任一种。
2. `User` – 指定以哪一个用户来登录。
3. `Port` – 设置连接远程主机的端口,默认是 22 端口。但必须是远程主机的 sshd 配置文件中定义的端口号。
4. `Protocol` – 这个选项定义了优先使用 ssh 支持的协议版本。常用的值为 ‘1’ 和 ‘2’,同时使用两个协议版本则必须使用英文逗号隔开。
5. `IdentityFile` – 指定一个用于读取用户 DSA、Ed25519、ECDSA 等授权验证信息的文件。
6. `ForwardX11` – 定义 X11 连接是否自动重定向到安全通道和 DISPLAY 设置。有两个可以设置的值,即 `yes` 或 `no`。
7. `Compression` – 默认值为 `no`,如果设置为 `yes`,则在连接远程主机过程中使用压缩进行传输。
8. `ServerAliveInterval` – 设置当没有收到服务器响应 (或者数据))时的超时时间,单位为秒,ssh 会通过加密信道发送信息,请求服务器响应。默认值为 `0`,这意味着 ssh 不会向服务器发送响应请求;如果定义了 BatchMode 选项,则默认是 300 秒。
9. `ServerAliveCountMax` – 设置服务器在没有接收到服务器的任何响应时,由服务器发送的活动信息数量。
10. `LogLevel` – 定义 ssh 登录信息的的日志冗余级别。允许的值为:`QUIET`、`FATAL`、`ERROR`、`INFO`、`VERBOSE`、`DEBUG`、`DEBUG1`、`DEBUG2` 和 `DEBUG3`,默认为 `INFO`。
连接任意远程主机的标准方法是在上述两个文件中定义第二个部分(我连接的是 CentOS 7)。一般情况下,我们这样输入命令:
```
$ ssh -i ~/.ssh/id_rsa -p 22 [email protected]
```
然而,使用了 ssh 客户端配置文件之后,我们还可以这样:
```
$ ssh centos7
```
你也可以在 man 帮助页面寻找更多的设置选项和使用实例:
```
$man ssh_config
```
至此,文毕。我们在文中向你介绍了在 Linux 中如何使用用户指定 (自定义) 的 ssh 客户端配置文件。通过下方的反馈表单来写一些与本文的相关的想法吧。
---
作者简介:
Aaron Kili 是一名 Linux 和 F.O.S.S 忠实拥护者、高级 Linux 系统管理员、Web 开发者,目前在 TecMint 是一名活跃的博主,热衷于计算机并有着强烈的只是分享意愿。
---
译者简介:
[GHLandy](http://GHLandy.com) —— 生活中所有欢乐与苦闷都应藏在心中,有些事儿注定无人知晓,自己也无从说起。
---
via: <http://www.tecmint.com/configure-custom-ssh-connection-in-linux/>
作者:[Aaron Kili](http://www.tecmint.com/author/aaronkili/) 译者:[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,307 | 如何编写和使用自定义的 Shell 函数和函数库 | http://www.tecmint.com/write-custom-shell-functions-and-libraries-in-linux/ | 2017-03-15T10:38:00 | [
"Shell",
"脚本",
"函数"
] | https://linux.cn/article-8307-1.html | 在 Linux 系统下,Shell 脚本可以在各种不同的情形下帮到我们,例如展示信息,甚至 [自动执行特定的系统管理任务](http://www.tecmint.com/using-shell-script-to-automate-linux-system-maintenance-tasks/),创建简单的命令行工具等等。
在本指南中,我们将向 Linux 新手展示如何可靠地存储自定义的 shell 脚本,解释如何编写 shell 函数和函数库,以及如何在其它的脚本中使用函数库中的函数。

### Shell 脚本要存储在何处
为了在执行你自己的脚本时不必输入脚本所在位置的完整或绝对路径,脚本必须被存储在 `$PATH` 环境变量所定义的路径里的其中一个。
使用下面的命令可以查看你系统中的 `$PATH` 环境变量:
```
$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
```
通常来说,如果在用户的家目录下存在名为 `bin` 的目录,你就可以将 shell 脚本存储在那个目录下,因为那个目录会自动地被包含在用户的 `$PATH` 环境变量中(LCTT 译注:在 Centos 6/7 下是这样的,在 Debian 8 下不是这样的,在 Ubuntu 16.04 下又是这样的)。
因此,在你的主目录下创建 `bin` 目录吧(当然这里也可以用来存储 Perl、Awk 或 Python 的脚本,或者其它程序):
```
$ mkdir ~/bin
```
接着,建立一个名为 `lib`(libraries 的简写)的目录来存放你自己的函数库。你也可以在其中存放其它编程语言的函数库,如 C ,Python 等语言。在 `lib` 目录下建立另一个名为 `sh` 的目录,这个目录将被用来存放你的 shell 函数库:
```
$ mkdir -p ~/lib/sh
```
### 创建你自己的 Shell 函数和函数库
一个 `shell 函数` 就是在脚本中能够完成特定任务的一组命令。它们的工作原理与其他编程语言中的过程(LCTT 译注:可能指的是类似 SQL 中的存储过程之类的吧)、子例程、函数类似。
编写一个函数的语法如下:
```
函数名() { 一系列的命令 }
```
( LCTT 校注:在函数名前可以加上 `function` 关键字,但也可省略不写)
例如,你可以像下面那样在一个脚本中写一个用来显示日期的函数:
```
showDATE() {date;}
```
每当你需要显示日期时,只需调用该函数的函数名即可:
```
$ showDATE
```
简单来说 shell 函数库也是一个 shell 脚本,不过你可以在一个函数库中仅存储其它 shell 脚本中需要调用的函数。
下面展示的是在我的 `~/lib/sh` 目录下一个名为 `libMYFUNCS.sh` 的库函数:
```
#!/bin/bash
### Function to clearly list directories in PATH
showPATH() {
oldifs="$IFS" ### store old internal field separator
IFS=: ### specify a new internal field separator
for DIR in $PATH<br> do<br> echo $DIR<br> done
IFS="$oldifs" ### restore old internal field separator
}
### Function to show logged user
showUSERS() {
echo -e “Below are the user logged on the system:\n”
w
}
### Print a user’s details
printUSERDETS() {
oldifs="$IFS" ### store old internal field separator
IFS=: ### specify a new internal field separator
read -p "Enter user name to be searched:" uname ### read username
echo ""
### read and store from a here string values into variables
### using : as a field delimiter
read -r username pass uid gid comments homedir shell <<< "$(cat /etc/passwd | grep "^$uname")"
### print out captured values
echo -e "Username is : $username\n"
echo -e "User's ID : $uid\n"
echo -e "User's GID : $gid\n"
echo -e "User's Comments : $comments\n"
echo -e "User's Home Dir : $homedir\n"
echo -e "User's Shell : $shell\n"
IFS="$oldifs" ### store old internal field separator
}
```
保存文件并且给脚本添加执行权限。
### 如何从函数库中调用函数
要使用某个 `lib` 目录下的函数,首先你需要按照下面的形式 将包含该函数的函数库导入到需要执行的 shell 脚本中:
```
$ . /path/to/lib
或
$ source /path/to/lib
```
(LCTT 译注:第一行的 `.` 和路径间**必须**是有空格的)
这样你就可以像下面演示的那样,在其它的脚本中使用来自 `~/lib/sh/libMYFUNCS.sh` 的 `printUSERDETS` 函数了。
在下面的脚本中,如果要打印出某个特定用户的详细信息,你不必再一一编写代码,而只需要简单地调用已存在的函数即可。
创建一个名为 `test.sh` 的新文件:
```
#!/bin/bash
### include lib
. ~/lib/sh/libMYFUNCS.sh
### use function from lib
printUSERDETS
### exit script
exit 0
```
保存这个文件,并使得这个脚本可被执行,然后运行它:
```
$ chmod 755 test.sh
$ ./test.sh
```

*编写 shell 函数*
在本文中,我们介绍了在哪里可靠地存储 shell 脚本,如何编写自己的 shell 函数和函数库,以及如何在一个普通的 shell 脚本中从函数库中调用库中的某些函数。
在之后,我们还会介绍一种相当简单直接的方式来将 Vim 配置为一个编写 Bash 脚本的 IDE(集成开发环境)。在那之前,记得要经常关注我们 ,如果能和我们分享你对这份指南的想法就更好了。
---
作者简介:Aaron Kili 是一名 Linux 和 F.O.S.S 爱好者、一名未来的 Linux 系统管理员、web 开发者,目前是一名 TecMint 上的内容创造者,他喜欢计算机相关的工作,并且坚信知识的分享。
---
via: <http://www.tecmint.com/write-custom-shell-functions-and-libraries-in-linux/>
作者:[Aaron Kili](http://www.tecmint.com/author/aaronkili/) 译者:[wcnnbdk1](https://github.com/wcnnbdk1) 校对:[FSSlc](https://github.com/FSSlc)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
8,308 | Orange Pi 新手起步指南 | https://opensource.com/article/17/1/how-to-orange-pi | 2017-03-16T08:39:00 | [
"Orange Pi",
"树莓派"
] | https://linux.cn/article-8308-1.html | 
随着开源驱动的硬件越来越成为主流,比如 [Arduino](https://en.wikipedia.org/wiki/Arduino) 和 [Raspberry Pi](https://en.wikipedia.org/wiki/Raspberry_Pi),这些开源硬件的成本不断下降,给那些全新且具有创新性的[物联网](https://en.wikipedia.org/wiki/Internet_of_things)和[STEM](https://en.wikipedia.org/wiki/Science,_technology,_engineering,_and_mathematics)(LCTT译注:STEM 代表<ruby> 科学 <rp> ( </rp> <rt> Science </rt> <rp> ) </rp></ruby>,<ruby> 技术 <rp> ( </rp> <rt> Technology </rt> <rp> ) </rp></ruby>,<ruby> 工程 <rp> ( </rp> <rt> Engineering </rt> <rp> ) </rp></ruby>,<ruby> 数学 <rp> ( </rp> <rt> Mathematics </rt> <rp> ) </rp></ruby>)类软件打开了大门。我对两者都比较感兴趣,始终保持关注,以便能找到一些可以应用到教育产业的创新点,比如课堂教育和我女儿的[机器人小组](https://opensource.com/education/14/3/fighting-unicorns-robotics-team)。当听说 [Orange Pi 比 Raspberry Pi 更优秀](http://sprtechuk.blogspot.com/2015/09/15-computer-orange-pi-pc-is-powerful.html)时,我便开始关注 Orange Pi了。
尽管 Orange Pi 是个略带酸味儿的名字,但是我仍然被 Orange Pi Zero 迷住了。我最近刚购买了一个 Orange Pi Zero 并将在本文中分享我的第一体验。真情提示:我是真的着迷了。
### 为什么是 Orange Pi?
Orange Pi 是由 Linux 驱动的单板计算机家族的一员,由[深圳迅龙软件有限公司](http://www.xunlong.tv/)生产并在<ruby> <a href="https://www.aliexpress.com/store/1553371"> 全球速卖通 </a> <rp> ( </rp> <rt> AliExpress </rt> <rp> ) </rp></ruby>上售卖。在<ruby> 全球速卖通 <rp> ( </rp> <rt> AliExpress </rt> <rp> ) </rp></ruby>上买东西需要有耐心,提前计划预留出 2 到 4 周的运输时间,因为这些产品都是从中国大陆直接发往全世界其它地方的。
与 Raspberry Pi 不同,Raspberry Pi 家族型号比较少,不过在逐步增加,为单板计算机家族添加了几个具有不同价位及功能特色的型号,但是相对而言 Orange Pi 的型号更丰富。好消息是可以在巨大的软件库中选择你需要的东西,但是坏消息就是选择范围实在太大了。以我的经验来看,使用 [Orange Pi Zero](http://www.orangepi.org/orangepizero/) 的 512 MB 版本足矣,因为该版本很好的平衡了功能与价格,适合中学及学术环境使用。
可以到 [Orange Pi Zero 网站](http://www.orangepi.org/orangepizero/) ,查看高清图及所有规格。
很明确的问题是,我希望这种设备的价格越便宜越好,但是要能做到开箱即用,并且能够直接联网以便 SSH 及物联网应用能正常使用。Orange Pi Zero 拥有板载的10/100 M 以太网及 802.11 b/g/n Wi-Fi 模块可以连接网络以满足需求。它还有 26 个与 Raspberry Pi 兼容的 [GPIO 端口](http://linux-sunxi.org/Xunlong_Orange_Pi_Zero#Expansion_Port),用于连接物联网应用传感器。我使用的是 512 MB 版本的 Orange Pi Zero 而不是 256MB 版本,因为内存大带来的好处很多,并且这两个版本只相差了 2 美元。除此之外,运费还需要 $12.30,这笔花费对于那些鼓励积极实验及创造魔法烟雾的课堂特别划算。(LCTT 译注:“创造魔法烟雾”是幽默的说法,意即因未知原因设备停止工作,原多用于电气工程师和技术员,最近常被程序员们采用)。
与 $5 的 [Raspberry Pi Zero](https://www.raspberrypi.org/products/pi-zero/) 相比,Orange Pi Zero 只贵了几元钱,但是这个开箱后更容易上手使用,因为它拥有板载的 Internet 连接模块及 4 核 CPU,而不是单核。这个板载网口使得 Orange Pi Zero 比 Raspberry Pi Zero 更容易使用,因为 Raspberry Pi Zero 还需要一个 Micro-USB 转 USB 的转换器及一个 USB Wi-Fi 才能连上网。当赠送别人一个物联网设备作为礼物时,你当然希望对方能够尽快且容易的使用该产品,而不是送一个不完整的产品,那么这个礼物就只能躺在阁楼吃灰了。
### 开箱经验
起初对于 Orange Pi,我比较担心的问题是供应商及社区支持没有 Raspberry Pi 基金会和 Raspberry Pi 社区的好,用户不得不自己花费额外的精力把设备跑起来。如果这样的话,我是不会推荐 Orange Pi 作为课堂使用及礼物赠送的。然而好消息是 Orange Pi Zero 工作得非常好,且比 Raspberry 更容易跑起来。
订购两周后,Orange Pi 终于邮寄到家了。我拆开后在几分钟内就把设备运行起来了。其实这大部分时间都是在下载操作系统。Orange Pi 能够运行多种操作系统,从Android 到 Debian 系列都可以。我使用了 Orange Pi 粉丝推崇的 [Armbian](https://www.armbian.com/)。由于 Armbian 支持多种基于 ARM 的单板计算机,你需要选择[适合 Orange Pi Zero 的 Armbian 版本](https://www.armbian.com/orange-pi-zero/)。按照 Armbian 用户指南[开始部分](https://docs.armbian.com/User-Guide_Getting-Started/)操作即可以很容易做一个 microSD 镜像,然后插入 microSD 卡并接上网线,将我在 Raspberry Pi 中用的 3A Micro-USB 电源适配器插上供电,最后 SSH 登录上去即可使用了。

*SSH 登录进 Orange Pi Zero*
通过以太网 SSH 连上后,我可以使用 [nmtui-connect](https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/Networking_Guide/sec-Networking_Config_Using_nmtui.html) 轻松连上我的无线接入点。然后执行 `apt-get update && apt-get upgrade` 命令,这个命令执行速度比 Raspberry Pi Zero 快,基本接近 [Raspberry Pi 3](https://www.raspberrypi.org/products/raspberry-pi-3-model-b/) 的表现了,其他人也[观察到类似的结果](https://openbenchmarking.org/result/1612154-TA-1603058GA04,1612151-MICK-MICKMAK70,1612095-TA-1603058GA97,1612095-TA-1603058GA50)。虽然 Orange Pi Zero 执行速度可能比不过Raspberry Pi 3,但是我也没有打算用它来计算基因排序或者挖比特币矿。Armbian 会自动调整 root 分区来使用整个 microSD 卡空间,而使用 Raspbian 的时候这是手动且很容易忘记的步骤。最后,和价值 $35 的 Raspberry Pi 3 相比,购买 $12 的 Orange Pi Zero 可以使得三倍多的学生有自己的学习工具,也可以将 Orange Pi Zero 作为礼物分享给三倍数量的朋友。

*Orange Pi Zero与 Raspberry Pi 3 尺寸外形的比较*
### 最后的想法
Orange Pi 无疑是解决问题的很好解决方案。鉴于它的低成本、能够更快上手且运行迅速、相对更快速的表现及 GPIO 针脚兼容 Raspberry Pi 的特性,Orange Pi,特别是 Orange Pi Zero,绝对应该列在你工作室、教室或者机器人组的实验器材清单里面。
当然如果你已经厌烦了使用 Orange Pi,希望能够将你不喜欢的原因分享在下面。
---
作者简介:
David Egts - David Egts | 红帽公司北美公共部门首席技术专家。 喜欢玩打鼓,骑摩托车,电脑极客,是一名丈夫,父亲,传授教义者。关注我的推特 @davidegts并查看我正在主持的播客。
---
via: <https://opensource.com/article/17/1/how-to-orange-pi>
作者:[David Egts](https://opensource.com/users/daveegts) 译者:[beyondworld](https://github.com/beyondworld) 校对:[jasminepeng](https://github.com/jasminepeng)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 200 | OK | As open source-powered hardware like [Arduino](https://en.wikipedia.org/wiki/Arduino) and [Raspberry Pi](https://en.wikipedia.org/wiki/Raspberry_Pi) becomes more and more mainstream, its cost keeps dropping, which opens the door to new and innovative [IoT](https://en.wikipedia.org/wiki/Internet_of_things) and [STEM](https://en.wikipedia.org/wiki/Science,_technology,_engineering,_and_mathematics) applications. As someone who's passionate about both, I'm always on the lookout for new innovations that can be applied in industry, the classroom, and [my daughter's robotics team](https://opensource.com/education/14/3/fighting-unicorns-robotics-team). When I heard about the Orange Pi as being a "[Raspberry Pi killer](http://sprtechuk.blogspot.com/2015/09/15-computer-orange-pi-pc-is-powerful.html)," I paused to take notice.
Despite the sour sounding name, the Orange Pi Zero intrigued me. I recently got my hands on one and in this article share my first impressions. Spoiler alert: I was very impressed.
## Why Orange Pi?
Orange Pi is a family of Linux-powered, single board computers manufactured by [Shenzhen Xunlong Software Co., Limited](http://www.xunlong.tv/), and [sold on AliExpress](https://www.aliexpress.com/store/1553371). As with anything sold on AliExpress, be patient and plan ahead for shipping times of two to four or more weeks, because the products are shipped directly from mainland China to locations around the world.
Unlike the Raspberry Pi, which has had a small but growing family of single board computers for different price points, form factors, and features, the number of Orange Pi boards is much larger. The good news is that you have a tremendous amount of choice in the application you want, but the bad news is that amount of choice could be overwhelming. In my case, I went with the [Orange Pi Zero](http://www.orangepi.org/orangepizero/) 512MB version, because it has the right balance of features and is priced for use in high school, academic environments.
To see a high-resolution image with all the specs, go to the [Orange Pi Zero website](http://www.orangepi.org/orangepizero/).
Specifically, I needed the device to be as inexpensive as possible, but still useful out of the box, with Internet connectivity for SSH and IoT applications. The Orange Pi Zero meets these requirements by having onboard 10/100M Ethernet and 802.11 b/g/n Wi-Fi for Internet connectivity. It also has 26 Raspberry Pi-compatible [GPIO ports](http://linux-sunxi.org/Xunlong_Orange_Pi_Zero#Expansion_Port) for connecting sensors for IoT applications. I went with the 512MB version of the Orange Pi Zero over the 256MB version because more memory is typically better and it was only $2 more. Out the door, the unit was US $12.30 shipped, which makes it cost effective for classroom environments where experimentation and creating [magic smoke](https://en.wikipedia.org/wiki/Magic_smoke) is encouraged.
Compared to a $5 [Raspberry Pi Zero](https://www.raspberrypi.org/products/pi-zero/), the Orange Pi Zero is only a few dollars more expensive, but it is much more useful out of the box because it has onboard Internet connectivity and four CPU cores instead of one. This onboard networking capability also makes the Orange Pi Zero a better gift than a Raspberry Pi Zero because the Raspberry Pi Zero needs Micro-USB-to-USB adapters and a Wi-Fi USB adapter to connect to the Internet. When giving IoT devices as gifts, you want the recipient to enjoy the product as quickly and easily as possible, instead of giving something incomplete that will just end up on a shelf.
## Out of the box experience
One of my initial concerns about the Orange Pi is that the vendor and community support wouldn't be as strong as the Raspberry Pi Foundation's and its community's support, leaving the end user all alone putting in extra effort to get the device going. If that's the case, I'd be reluctant to recommend the Orange Pi for classroom use or as a gift. The good news is that the Orange Pi Zero worked well right away and was actually easier to get going than a Raspberry Pi.
The Orange Pi arrived in my mailbox two weeks after ordering. I unpacked it and got it up and running in a matter of minutes. Most of my time was spent downloading the operating system. The Orange Pi can run a variety of operating systems, ranging from Android to Debian variants. I went with [Armbian](https://www.armbian.com/) as it appeared to be the most popular choice for Orange Pi enthusiasts. Since Armbian supports many ARM-based single-board computers, you need to select [the right Armbian build for the Orange Pi Zero](https://www.armbian.com/orange-pi-zero/). By following the [Getting Started section](https://docs.armbian.com/User-Guide_Getting-Started/) of the Armbian User Guide, I was easily able to image a microSD card, insert the microSD card and Ethernet cable, power the unit with an existing 3A Micro-USB power adapter I use with my Raspberry Pis, and SSH into it.
SSHing into the Orange Pi Zero.
Once SSHed in via Ethernet, I was able to connect to my wireless access point easily using [nmtui-connect](https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/Networking_Guide/sec-Networking_Config_Using_nmtui.html). Then I performed an **apt-get update && apt-get upgrade** and noticed that the update ran much faster than a Raspberry Pi Zero and closer to the performance of a [Raspberry Pi 3](https://www.raspberrypi.org/products/raspberry-pi-3-model-b/). Others have [observed similar results](https://openbenchmarking.org/result/1612154-TA-1603058GA04,1612151-MICK-MICKMAK70,1612095-TA-1603058GA97,1612095-TA-1603058GA50), too. It may not be as fast as a Raspberry Pi 3, but I wasn't planning to sequence genomes or mine Bitcoin with it. I also noticed that Armbian automatically resizes the root partition to fill the entire microSD card, which is an explicit, manual, and sometimes forgotten step when using Raspbian. Finally, for the US $12 price, three times as many students can learn on their own Orange Pi Zero as compared to a $35 Raspberry Pi 3, and you can give an Orange Pi Zero to three times as many friends.
The Orange Pi Zero form factor compared with the Raspberry Pi 3.
## Closing thoughts
The Orange Pi is definitely a solution looking for problems. Given its low cost, ability to get up and running quickly, relatively quick performance, and GPIO-pin compatibility with Raspberry Pi, the Orange Pi, and Orange Pi Zero in particular, should definitely be on your short list for experimentation in your workshop, classroom, or robot.
Have you tried the Orange Pi? I'd love to hear about your experiences in the comments below.
## 14 Comments |
8,309 | 5 款值得尝试的 Linux 音乐播放器 | https://www.maketecheasier.com/linux-music-players-to-check-out/ | 2017-03-16T10:01:00 | [
"音乐播放器",
"音乐"
] | https://linux.cn/article-8309-1.html | 
目前 Linux 上有几十个音乐播放器,这使得找到一个最好用的变成很困难。之前我们已经回顾了其中的一些播放器,如 [Cantata](https://www.maketecheasier.com/cantata-new-music-player-for-linux/),[Exaile](https://www.maketecheasier.com/exaile-the-first-media-player-i-dont-hate/),甚至不那么出名的 Clementine,Nightingale 和 Quod Libet。
在本篇文章中我将涵盖更多的 Linux 音乐播放器,在某些方面甚至比之前介绍过的那些播放器表现更好。
### 1、 Qmmp
[Qmmp](http://qmmp.ylsoftware.com/) 并不是特性最丰富的(或最稳定的) Linux 音乐播放器,但却是我最喜欢的一款,这也是为什么我把它放在第一个。我知道有更好的播放器,但我就是喜欢这款并且最常使用它。它确实会崩溃,并且也有许多它不能播放的文件,但不管怎样我依然最爱它。上图!

Qmmp 是 Linux 上的 WinAMP。它(相对)轻量并且具有一个像样的特性集。因为 WinAMP 伴随着我的成长,并且我很喜欢它的键盘快捷键,当在 Linux 上有一个像 WinAMP 的播放器对我来说是个惊喜。对于音频格式,Qmmp 能够播放大部分流行的格式,如 MPEG1 layer 2/3、Ogg Vorbis 和 Opus、原生的 FLAC/Ogg FLAC、Musepack、WavePack、音轨模块(mod、s3m、it、xm 等等)、ADTS AAC、CD 音频、WMA、Monkey’s Audio(以及 FFmpeg 库提供的其他格式)、Midi、SID 和 Chiptune 格式(AY、GBS、GYM、HES、KSS、NSF、NSFE、SAP、SPC、VGM、VGZ 和 VTX)。
### 2、 Amarok
[Amarok](https://amarok.kde.org/) 是 KDE 的音乐播放器,当然你也可以把它用在其他的桌面环境。它是 Linux 上最古老的音乐播放器之一。这也许是它很流行的原因,虽然我个人并不是非常喜欢它。

Amarok 能播放大量的音频格式,但它的主要优势是丰富的插件。这个软件附带大量文档,不过它最近没有更新。Amarok 也由于与各种 Web 服务,如 Ampache、Jamendo Service、Last.fm、Librivox、MP3tunes、Magnatune 以及 OPML 播客目录的整合而闻名。
### 3、 Rhythmbox
既然我刚刚提到了 Amarok 和 KDE 音乐播放器,那接下来让我们转向 Gnome 的默认音乐播放器, [Rhythmbox](https://wiki.gnome.org/Apps/Rhythmbox) 。因为它与 Gnome 一起提供,所以你能猜到它是一款流行的软件。它不仅是一款音乐播放器,同时也是一款音乐管理软件。它支持 MP3 和 OGG,以及十几种其他的文件格式,也包括网络收音机、iPod 服务整合、音频文件播放、音频 CD 刻录和回放、音乐分享以及播客。总而言之,它是款不赖的播放器,但这不意味着你会最喜欢它。试用一下,看看自己是否喜欢。如果不喜欢,就往下看看吧。

### 4、 VLC
虽然 [VLC](http://www.videolan.org/vlc/) 是以视频播放器而闻名,但单从它支持最多的解码器这一点来看,它也是一款非常棒的音乐播放器。它无法播放的文件,你也不太可能能用其他播放器打开。VLC 具有高度定制性,并且拥有很多扩展。它能够在 Windows,Linux,Mac OS X,Unix,iOS,Android 等等平台运行。

我个人不喜欢 VLC 的一点是它占用太多资源。并且我曾用它打开过一些文件,但回放质量离一流水准还差的很远。这个软件在播放一些其他播放器不难应付的文件时,经常会无故关闭。但很可能与播放器没多大关系,可能是文件本身的问题。尽管 VLC 不属于我常用的程序,我仍然由衷的推荐它。
### 5、 Cmus
如果你钟爱命令行程序,那么 [Cmus](https://cmus.github.io/) 会是你的菜。你能用它来播放 Ogg Vorbis、MP3、FLAC、Opus、Musepack、WavPack、WAV、AAC、MP4、音频 CD 以及 ffmpeg 支持的所有格式(WMA、APE、MKA、TTA、SHN 等等)和 libmodplug。你也可以用它来播放 Shoutcast 或者 Icecast 的音频流。它不是特性最丰富的音乐播放器,但它拥有所有的基础及进阶功能。它的主要优势是非常轻量,并且它的内存需求真的很小。

所有的这些音乐播放器都很棒,都有擅长的方面。我没办法说出哪一款是最好的,这更多取决于个人喜好和需要。这些播放器大多要么做为发行版的默认选项安装,要么可以在包管理器中轻松找到。只要打开新立得、软件中心或你的发行版中使用的任意包管理器,搜索并安装它们。你也可以使用命令行,或只要双击从网站上下载的安装文件。使用何种方法取决于你。
等等,这就完了?
不不,我知道你要说啥,作为中国的 Linux 粉丝,你一定会说我丢失了最重要的一个:[网易云音乐](http://music.163.com/#/download),要是我不提的话,你们一定会抗议的。
没错,强烈推荐“网易云音乐”,也为国内厂商支持开源和 Linux 点赞。

详细介绍,请移步:[音乐无界限,听见好时光——网易云音乐 Linux 版震撼来袭!](/article-7387-1.html)
---
via: <https://www.maketecheasier.com/linux-music-players-to-check-out/>
作者:[Ada Ivanova](https://www.maketecheasier.com/author/adaivanoff/) 译者:[cycoe](https://github.com/cycoe) 校对:[jasminepeng](https://github.com/jasminepeng)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 200 | OK | 
There are dozens of Linux music players out there, and this makes it difficult to find the best one for our usage. In the past we’ve reviewed some of these players, such as [Cantata](https://www.maketecheasier.com/cantata-new-music-player-for-linux/), Exaile, or even [the lesser known ones](https://www.maketecheasier.com/linux-music-players-to-check-out/) like Clementine, Nightingale and Quod Libet.
In this article I will be covering more music players for Linux that in some aspects are even better than the ones we’ve already told you about.
## 1. Qmmp
[Qmmp](https://qmmp.ylsoftware.com/) isn’t the most feature-rich (or stable) Linux music player, but it’s my favorite one, and this is why I put it as number one. I know there are better players, but I somehow just love this one and use it most of the time. It does crash, and there are many files it can’t play, but nevertheless I still love it the most. Go figure!

Qmmp is a Winamp port for Linux. It’s (relatively) lightweight and has a decent feature set. Since I grew up with Winamp and loved its keyboard shortcuts, it was a nice surprise that they are present in the Linux version, too. As for formats, Qmmp plays most of the popular ones such as MPEG1 layer 2/3, Ogg Vorbis and Opus, Native FLAC/Ogg FLAC, Musepack, WavePack, tracker modules (mod, s3m, it, xm, etc.), ADTS AAC, CD Audio, WMA, Monkey’s Audio (and other formats provided by FFmpeg library), PCM WAVE (and other formats provided by libsndfile library), Midi, SID, and Chiptune formats (AY, GBS, GYM, HES, KSS, NSF, NSFE, SAP, SPC, VGM, VGZ, and VTX).
## 2. Amarok
[Amarok](https://amarok.kde.org/) is the KDE music player, though you certainly can use it with any other desktop environment. It’s one of the oldest music players for Linux. This is probably one of the reasons why it’s a very popular player, though I personally don’t like it that much.

Amarok plays a huge array of music formats, but its main advantage is the abundance of plugins. The app comes with a lot of documentation, though it hasn’t been updated recently. Amarok is also famous for its integration with various web services such as Ampache, Jamendo Service, Last.fm, Librivox, MP3tunes, Magnatune, and OPML Podcast Directory.
## 3. Rhythmbox
Now that I have mentioned Amarok and the KDE music player, now let’s move to [Rhythmbox](https://wiki.gnome.org/Apps/Rhythmbox), the default Gnome music player. Since it comes with Gnome, you can guess it’s a popular app. It’s not only a music player, but also a music management app. It supports MP3 and OGG, plus about a dozen other file formats, as well as Internet Radio, iPod integration, the playing of audio files, audio CD burning and playback, music sharing, and podcasts. All in all, it’s not a bad player, but this doesn’t mean you will like it the most. Try it and see if this is your player. If you don’t like it, just move on to the next option.

## 4. VLC
Though [VLC](https://www.videolan.org/vlc/) is best known as a movie player, it’s great as a music player, too, simply because it has the largest collection of codecs. If you can’t play a file with it, it’s unlikely you will be able to open it with any other player. VLC is highly customizable, and there are a lot of extensions for it. It runs on Windows, Linux, Mac OS X, Unix, iOS, Android, etc.

What I personally don’t like about VLC is that it’s quite heavy on resources. Also, for some of the files I’ve used it with, the playback quality was far from stellar. The app would often shut down without any obvious reason while playing a file most of the other players wouldn’t struggle with, but it’s quite possible it’s not so much the player, as the file itself. Even though VLC isn’t among the apps I frequently use, I still wholeheartedly recommend it.
## 5. Cmus
If you fancy command line apps, then [Cmus](https://cmus.github.io/) is your Linux music player. You can use it to play Ogg Vorbis, MP3, FLAC, Opus, Musepack, WavPack, WAV, AAC, MP4, audio CD, everything supported by ffmpeg (WMA, APE, MKA, TTA, SHN, etc.) and libmodplug. You can also use it for streaming from Shoutcast or Icecast. It’s not the most feature-rich music player, but it has all the basics and beyond. Its main advantage is that it’s very lightweight, and its memory requirements are really minimal.

All these music players are great – in one aspect or another. I can’t say there is a best among them – this is largely a matter of personal taste and needs. Most of these apps either come installed by default in the distro or can be easily found in the package manager. Simply open Synaptic, Software Center, or whatever package manager your distro is using, search for them and install them from there. You can also use the command line, or simply double-click the install file you download from their site – the choice is yours.
Our latest tutorials delivered straight to your inbox |
8,310 | 如何在 CentOS 7 中安装或升级最新的内核 | http://www.tecmint.com/install-upgrade-kernel-version-in-centos-7/ | 2017-03-17T10:30:00 | [
"内核",
"升级"
] | https://linux.cn/article-8310-1.html | 虽然有些人使用 Linux 来表示整个操作系统,但要注意的是,严格地来说,Linux 只是个内核。另一方面,发行版是一个完整功能的系统,它建立在内核之上,具有各种各样的应用程序工具和库。
在正常操作期间,内核负责执行两个重要任务:
1. 作为硬件和系统上运行的软件之间的接口。
2. 尽可能高效地管理系统资源。
为此,内核通过内置的驱动程序或以后可作为模块安装的驱动程序与硬件通信。
例如,当你计算机上运行的程序想要连接到无线网络时,它会将该请求提交给内核,后者又会使用正确的驱动程序连接到网络。
* **建议阅读:** [如何在 Ubuntu 中升级内核](/article-8284-1.html)
随着新的设备和技术定期出来,如果我们想充分利用它们,保持最新的内核就很重要。此外,更新内核将帮助我们利用新的内核函数,并保护自己免受先前版本中发现的漏洞的攻击。

准备好了在 CentOS 7 或其衍生产品(如 RHEL 7和 Fedora)上更新内核了么?如果是这样,请继续阅读!
### 步骤 1:检查已安装的内核版本
让我们安装了一个发行版,它包含了一个特定版本的内核。为了展示当前系统中已安装的版本,我们可以:
```
# uname -sr
```
下面的图片展示了在一台 CentOS 7 服务器上的输出信息:

*在 CentOS 7 上检查内核版本*
如果我们现在进入 <https://www.kernel.org/>,在撰写本文时,我们看到最新的内核版本是4.10.1(其他版本可以从同一网站获得)。
还要考虑的一个重要的事情是内核版本的生命周期 - 如果你当前使用的版本接近它的生命周期结束,那么在该日期后将不会提供更多的 bug 修复。关于更多信息,请参阅[内核发布](https://www.kernel.org/category/releases.html)页。
### 步骤 2:在 CentOS 7 中升级内核
大多数现代发行版提供了一种使用 [yum 等包管理系统](http://www.tecmint.com/20-linux-yum-yellowdog-updater-modified-commands-for-package-mangement/)和官方支持的仓库升级内核的方法。
但是,这只会升级内核到仓库中可用的最新版本 - 而不是在 <https://www.kernel.org/> 中可用的最新版本。不幸的是,Red Hat 只允许使用前者升级内核。
与 Red Hat 不同,CentOS 允许使用 ELRepo,这是一个第三方仓库,可以将内核升级到最新版本。
要在 CentOS 7 上启用 ELRepo 仓库,请运行:
```
# rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
# rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-2.el7.elrepo.noarch.rpm
```

*在 CentOS 7 启用 ELRepo*
仓库启用后,你可以使用下面的命令列出可用的内核相关包:
```
# yum --disablerepo="*" --enablerepo="elrepo-kernel" list available
```

*yum - 找出可用的内核版本*
接下来,安装最新的主线稳定内核:
```
# yum --enablerepo=elrepo-kernel install kernel-ml
```

*在 CentOS 7 中安装最新的内核版本*
最后,重启机器并应用最新内核,接着运行下面的命令检查最新内核版本:
```
uname -sr
```

*验证内核版本*
### 步骤 3:设置 GRUB 默认的内核版本
为了让新安装的内核成为默认启动选项,你需要如下修改 GRUB 配置:
打开并编辑 `/etc/default/grub` 并设置 `GRUB_DEFAULT=0`。意思是 GRUB 初始化页面的第一个内核将作为默认内核。
```
GRUB_TIMEOUT=5
GRUB_DEFAULT=0
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="console"
GRUB_CMDLINE_LINUX="rd.lvm.lv=centos/root rd.lvm.lv=centos/swap crashkernel=auto rhgb quiet"
GRUB_DISABLE_RECOVERY="true"
```
接下来运行下面的命令来重新创建内核配置。
```
# grub2-mkconfig -o /boot/grub2/grub.cfg
```

*在 GRUB 中设置内核*
重启并验证最新的内核已作为默认内核。

*在 CentOS 7 中启动默认内核版本*
恭喜你!你已经在 CentOS 7 中升级内核了!
### 总结
在本文中,我们解释了如何轻松升级系统上的 Linux 内核。我们还没讲到另外一个方法,因为它涉及从源代码编译内核,这可以写成一本书,并且不推荐在生产系统上这么做。
虽然它是最好的学习体验之一,并且允许细粒度配置内核,但是你可能会让你的系统不可用,并且可能必须从头重新安装它。
如果你仍然有兴趣构建内核作为学习经验,你可以在 [Kernel Newbies](https://kernelnewbies.org/KernelBuild)页面中获得指导。
一如既往,如果你对本文有任何问题或意见,请随时使用下面的评论栏。
---
作者简介:
我是一个计算机上瘾的家伙,并且是开源和 Linux 系统软件的粉丝,有大约 4 年的 Linux 发行版桌面、服务器和 bash 脚本的经验。
---
via: <http://www.tecmint.com/install-upgrade-kernel-version-in-centos-7/>
作者:[Matei Cezar](http://www.tecmint.com/author/cezarmatei/) 译者:[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,311 | 给新手的最佳类 Windows 界面的 Linux 发行版 | http://www.linuxandubuntu.com/home/best-windows-like-linux-distributions-for-new-linux-users | 2017-03-16T09:38:00 | [
"发行版",
"Windows"
] | https://linux.cn/article-8311-1.html | 
Linux 世界的新同学们,大家好,当你看到这么多基于 Linux 内核的发行版后,是不是在选择的过程中无从下手呢。很多同学都是刚刚从熟悉的 Windows 系统来到陌生的 Linux 世界里,都希望使用一款既简单易用,又跟 Windows 长得很像的 Linux 发行版,因此我今天将给大家介绍几款这样的 Linux 发行版,它们的桌面环境跟 Windows 系统界面十分相似,咱们开始吧!
### Linux Mint

我给大家介绍的第一款非常流行的 Linux 发行版就是 “[Linux Mint 操作系统”](http://www.linuxandubuntu.com/home/linux-mint-181-sarah-one-of-the-finest-linux-distro-ever) 。当你决定使用 Linux 系统来代替 Windows 系统时,你应该在某些地方听说过 Linux Mint 这个发行版吧。 Linux Mint 和 Ubuntu 系统一样被公认为是最好用的 Linux 发行版之一, Linux Mint 系统因其简洁易用、功能强大的 Cinnamon 桌面环境而出名。 [Cinnamon](http://www.developer.linuxmint.com/) 使用起来非常简单,而且你还可以使用各种[桌面主题](http://www.linuxandubuntu.com/linux-themes/mintilicious-cinnamon-theme-install-in-linux-mint)、图标库、桌面小工具和应用组件来把 Linux Mint 系统配置得跟 Windows XP 、 Windows 7 、 Winows 8 或者 Windows 10 系统的界面一样。 [Cinnamon](http://www.linuxandubuntu.com/linux-apps-releases/cinnamon-2610) 也是 Linux 系统中非常流行的桌面环境之一。你一定会对这个简单易用、功能强大的桌面环境爱不释手。
同时,你也可以阅读这两篇文章 [Linux Mint 18.1 "Serena" —— 最幽雅的 Linux 发行版之一](http://www.linuxandubuntu.com/home/linux-mint-181-sarah-one-of-the-finest-linux-distro-ever) 以及 [Cinnamon ——给新手的最佳 Linux 桌面环境](http://www.linuxandubuntu.com/home/cinnamon-desktop-the-best-desktop-environment-for-new-linux-user) 来进一步了解 Linux Mint 操作系统和 Cinnamon 桌面环境。
### Zorin OS

[Zorin OS 操作系统](https://zorinos.com/) 也是可以用来替代 Windows 7 系统的一款非常流行的 Linux 发行版。其开始菜单和任务栏非常漂亮,整体界面美观充满活力,而且在速度和稳定性方面也相当出色。如果你喜欢的是 Windows 7 而不是 Windows 10 系统,那么 Zorin OS 将会是你最好的选择。 Zorin OS 同样预安装了很多软件,因此你再也不用费尽周折的去找软件来安装了。其华丽的仿 Windows 7 系统的界面风格更是让人一见如故。大胆去尝试吧。
你还可以阅读[Zorin OS 12 评测 | 本周 Linux 和 Ubuntu 发行版评测](http://www.linuxandubuntu.com/home/zorin-os-12-review-linuxandubuntu-distro-review-of-the-week)这篇文章来进一步了解 Zorin OS 系统。
### Robolinux

[Robolinux 操作系统](https://www.robolinux.org/) 是一个内嵌了 Windows 运行环境(Wine)的 Linux 发行版。它支持用户在 Linux 系统中运行 Windows 应用程序,因此,你再也不用担心自己喜欢的 Windows 应用程序在 Linux 系统中无法使用的问题了。在 Robolinux 系统中,这个特性被称为“[隐形虚拟机(Stealth VM)](https://www.robolinux.org/stealth-vm-info/)”。我对这个新颖独特的功能非常感兴趣。同时, Rololinux 系统还包括其它几个桌面环境,你可以根据自己的喜好选择某一个桌面环境。这个系统中还有一个用于完全备份 C 盘的工具,不会让你丢失任何文件。很独特吧,对不对?
### ChaletOS

大家有谁用过 [ChaletOS 操作系统](https://sites.google.com/site/chaletoslinux/home) 吗?这是一款在界面外观和使用感觉上最接近于 Windows 的 [Linux 发行版](http://www.linuxandubuntu.com/home/how-to-create-a-linux-distro) 之一。上面的截图是在我使用了 Windows 10 图标和主题包后的效果,使用这个主题包后,可以让 ChaletOS 的桌面变得和 Windows 10 界面一样。一些预安装的应用程序也可以帮助你更好的使用 ChaletOS 系统。在使用的过程中你仿佛又回到了熟悉的 Windows 世界里。上面的截图竟然让我的朋友们信以为真了。去试一试吧,你肯定会喜欢这个发行版。
你还可以通过 [ChaletOS —— Linux 发行版中的新秀](http://www.linuxandubuntu.com/home/chaletos-new-beautiful-linux-distribution-based-on-xubuntu-and-a-clone-of-windows) 这篇文章来进一步了解 ChaletOS 系统。
### 总结
这篇文章中列出的发行版我尽量写得简短一些,否则会给新手们在选择的过程中造成太多的困惑,无从下手。还有一些大家正在使用的 Linux 发行版在本文中并未提及。希望你们在下面的评论中提出来,以帮助我们的新朋友们在选择 Linux 发行版的过程中作出正确的选择。
好吧,到此为止吧,这 4 款操作系统都是从 Windows 转向 Linux 的新用户在学习过程中使用最广泛的 **Linux 发行版** ,当然 Kubuntu 和 Elementary OS 系统也不甘示弱。想安装哪个版本,完全由你自己决定。大多数情况下 [Linux Mint 操作系统](http://www.linuxandubuntu.com/home/linux-mint-18-sarah-review) 一直独占鳌头。如果你刚踏入 Linux 的世界,我建议你从 Linux Mint 系统开始。行动起来吧,现在就安装一个自己喜欢的 Linux 系统,勇往直前,成为改变 Linux 开源世界的一员。|
---
via: <http://www.linuxandubuntu.com/home/best-windows-like-linux-distributions-for-new-linux-users>
作者:[linuxandubuntu.com](http://www.linuxandubuntu.com/home/best-windows-like-linux-distributions-for-new-linux-users) 译者:[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,312 | 如何在 Ubuntu 下安装和配置 FTP 服务器 | http://www.tecmint.com/install-ftp-server-in-ubuntu/ | 2017-03-17T08:09:00 | [
"FTP",
"FTPS"
] | https://linux.cn/article-8312-1.html | FTP(文件传输协议)是一个较老且最常用的标准网络协议,用于在两台计算机之间通过网络上传/下载文件。然而, FTP 最初的时候并不安全,因为它仅通过用户凭证(用户名和密码)传输数据,没有进行加密。
警告:如果你打算使用 FTP, 需要考虑通过 SSL/TLS(将在[下篇文章](/article-8295-1.html)中讨论)配置 FTP 连接。否则,使用安全 FTP,比如 [SFTP](http://www.tecmint.com/sftp-command-examples/) 会更好一些。

**推荐阅读:**[如何在 CentOS 7 中安装并保护 FTP 服务器](http://www.tecmint.com/install-ftp-server-in-centos-7/)
在这个教程中,我将向你们展示如何在 Ubuntu 中安装、配置并保护 FTP 服务器(VSFTPD 的全称是 “Very Secure FTP Deamon”),从而拥有强大的安全性,能够防范 FTP 漏洞。
### 第一步:在 Ubuntu 中安装 VSFTPD 服务器
1、首先,我们需要更新系统安装包列表,然后像下面这样安装 VSFTPD 二进制包:
```
$ sudo apt-get update
$ sudo apt-get install vsftpd
```
2、一旦安装完成,初始情况下服务被禁用。因此,我们需要手动开启服务,同时,启动它使得在下次开机时能够自动开启服务:
```
------------- On SystemD -------------
# systemctl start vsftpd
# systemctl enable vsftpd
------------- On SysVInit -------------
# service vsftpd start
# chkconfig --level 35 vsftpd on
```
3、接下来,如果你在服务器上启用了 [UFW 防火墙](/article-8087-1.html)(默认情况下不启用),那么需要打开端口 20 和 21 —— FTP 守护进程正在监听它们——从而才能允许从远程机器访问 FTP 服务,然后,像下面这样添加新的防火墙规则:
```
$ sudo ufw allow 20/tcp
$ sudo ufw allow 21/tcp
$ sudo ufw status
```
### 第二步:在 Ubuntu 中配置并保护 VSFTPD 服务器
4、让我们进行一些配置来设置和保护 FTP 服务器。首先,我们像下面这样创建一个原始配置文件 `/etc/vsftpd/vsftpd.conf` 的备份文件:
```
$ sudo cp /etc/vsftpd.conf /etc/vsftpd.conf.orig
```
接下来,打开 vsftpd 配置文件。
```
$ sudo vi /etc/vsftpd.conf
OR
$ sudo nano /etc/vsftpd.conf
```
把下面的这些选项添加/改成所展示的值:
```
anonymous_enable=NO # 关闭匿名登录
local_enable=YES # 允许本地用户登录
write_enable=YES # 启用可以修改文件的 FTP 命令
local_umask=022 # 本地用户创建文件的 umask 值
dirmessage_enable=YES # 当用户第一次进入新目录时显示提示消息
xferlog_enable=YES # 一个存有详细的上传和下载信息的日志文件
connect_from_port_20=YES # 在服务器上针对 PORT 类型的连接使用端口 20(FTP 数据)
xferlog_std_format=YES # 保持标准日志文件格式
listen=NO # 阻止 vsftpd 在独立模式下运行
listen_ipv6=YES # vsftpd 将监听 ipv6 而不是 IPv4,你可以根据你的网络情况设置
pam_service_name=vsftpd # vsftpd 将使用的 PAM 验证设备的名字
userlist_enable=YES # 允许 vsftpd 加载用户名字列表
tcp_wrappers=YES # 打开 tcp 包装器
```
5、现在,配置 VSFTPD ,基于用户列表文件 `/etc/vsftpd.userlist` 来允许或拒绝用户访问 FTP。
注意,在默认情况下,如果通过 `userlist_enable=YES` 启用了用户列表,且设置 `userlist_deny=YES` 时,那么,用户列表文件 `/etc/vsftpd.userlist` 中的用户是不能登录访问的。
但是,选项 `userlist_deny=NO` 则反转了默认设置,这种情况下只有用户名被明确列出在 `/etc/vsftpd.userlist` 中的用户才允许登录到 FTP 服务器。
```
userlist_enable=YES # vsftpd 将会从所给的用户列表文件中加载用户名字列表
userlist_file=/etc/vsftpd.userlist # 存储用户名字的列表
userlist_deny=NO
```
重要的是,当用户登录 FTP 服务器以后,他们将进入 chrooted 环境,即当在 FTP 会话时,其 root 目录将是其 home 目录。
接下来,我们来看一看两种可能的途径来设置 chrooted(本地 root)目录,正如下面所展示的。
6、这时,让我们添加/修改/取消这两个选项来[将 FTP 用户限制在其 home 目录](http://www.tecmint.com/restrict-sftp-user-home-directories-using-chroot/)
```
chroot_local_user=YES
allow_writeable_chroot=YES
```
选项 `chroot_local_user=YES` 意味着本地用户将进入 chroot 环境,当登录以后默认情况下是其 home 目录。
并且我们要知道,默认情况下,出于安全原因,VSFTPD 不允许 chroot 目录具有可写权限。然而,我们可以通过选项 `allow_writeable_chroot=YES` 来改变这个设置
保存文件然后关闭。现在我们需要重启 VSFTPD 服务从而使上面的这些更改生效:
```
------------- On SystemD -------------
# systemctl restart vsftpd
------------- On SysVInit -------------
# service vsftpd restart
```
### 第三步:在 Ubuntu 上测试 VsFTP 服务器
7、现在,我们通过使用下面展示的 useradd 命令创建一个 FTP 用户来测试 FTP 服务器:
```
$ sudo useradd -m -c "Aaron Kili, Contributor" -s /bin/bash aaronkilik
$ sudo passwd aaronkilik
```
然后,我们需要像下面这样使用 [echo 命令](https://linux.cn/tag-echo.html)和 tee 命令来明确地列出文件 `/etc/vsftpd.userlist` 中的用户 aaronkilik:
```
$ echo "aaronkilik" | sudo tee -a /etc/vsftpd.userlist
$ cat /etc/vsftpd.userlist
```
8、现在,是时候来测试上面的配置是否具有我们想要的功能了。我们首先测试匿名登录;我们可以从下面的输出中很清楚的看到,在这个 FTP 服务器中是不允许匿名登录的:
```
# ftp 192.168.56.102
Connected to 192.168.56.102 (192.168.56.102).
220 Welcome to TecMint.com FTP service.
Name (192.168.56.102:aaronkilik) : anonymous
530 Permission denied.
Login failed.
ftp> bye
221 Goodbye.
```
9、接下来,我们将测试,如果用户的名字没有在文件 `/etc/vsftpd.userlist` 中,是否能够登录。从下面的输出中,我们看到,这是不可以的:
```
# ftp 192.168.56.102
Connected to 192.168.56.102 (192.168.56.102).
220 Welcome to TecMint.com FTP service.
Name (192.168.56.10:root) : user1
530 Permission denied.
Login failed.
ftp> bye
221 Goodbye.
```
10、现在,我们将进行最后一项测试,来确定列在文件 `/etc/vsftpd.userlist` 文件中的用户登录以后,是否实际处于 home 目录。从下面的输出中可知,是这样的:
```
# ftp 192.168.56.102
Connected to 192.168.56.102 (192.168.56.102).
220 Welcome to TecMint.com FTP service.
Name (192.168.56.102:aaronkilik) : aaronkilik
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> ls
```

*在 Ubuntu 中确认 FTP 登录*
警告:设置选项 `allow_writeable_chroot=YES` 是很危险的,特别是如果用户具有上传权限,或者可以 shell 访问的时候,很可能会出现安全问题。只有当你确切的知道你在做什么的时候,才可以使用这个选项。
我们需要注意,这些安全问题不仅会影响到 VSFTPD,也会影响让本地用户进入 chroot 环境的 FTP daemon。
因为这些原因,在下一步中,我将阐述一个更安全的方法,来帮助用户设置一个非可写本地 root 目录。
### 第四步:在 Ubuntu 中配置 FTP 用户的 Home 目录
11、现在,再次打开 VSFTPD 配置文件。
```
$ sudo vi /etc/vsftpd.conf
OR
$ sudo nano /etc/vsftpd.conf
```
然后像下面这样用 `#` 把不安全选项注释了:
```
#allow_writeable_chroot=YES
```
接下来,为用户创建一个替代的本地 root 目录(aaronkilik,你的可能和这不一样),然后设置目录权限,取消其他所有用户对此目录的写入权限:
```
$ sudo mkdir /home/aaronkilik/ftp
$ sudo chown nobody:nogroup /home/aaronkilik/ftp
$ sudo chmod a-w /home/aaronkilik/ftp
```
12、然后,在本地 root 目录下创建一个具有合适权限的目录,用户将在这儿存储文件:
```
$ sudo mkdir /home/aaronkilik/ftp/files
$ sudo chown -R aaronkilk:aaronkilik /home/aaronkilik/ftp/files
$ sudo chmod -R 0770 /home/aaronkilik/ftp/files/
```
之后,将 VSFTPD 配置文件中的下面这些选项添加/修改为相应的值:
```
user_sub_token=$USER # 在本地 root 目录中插入用户名
local_root=/home/$USER/ftp # 定义各个用户的本地 root 目录
```
保存文件并关闭。然后重启 VSFTPD 服务来使上面的设置生效:
```
------------- On SystemD -------------
# systemctl restart vsftpd
------------- On SysVInit -------------
# service vsftpd restart
```
13、现在,让我们来最后检查一下,确保用户的本地 root 目录是我们在他的 Home 目录中创建的 FTP 目录。
```
# ftp 192.168.56.102
Connected to 192.168.56.102 (192.168.56.102).
220 Welcome to TecMint.com FTP service.
Name (192.168.56.10:aaronkilik) : aaronkilik
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> ls
```

*FTP 用户 Home 目录登录*
就是这样的!记得通过下面的评论栏来分享你关于这篇指导的想法,或者你也可以提供关于这一话题的任何重要信息。
最后但不是不重要,请不要错过我的下一篇文章,在下一篇文章中,我将阐述如何[使用 SSL/TLS 来保护连接到 Ubuntu 16.04/16.10 的 FTP 服务器](/article-8295-1.html),在那之前,请始终关注我们。
---
作者简介:
Aaron Kili 是 Linux 和 F.O.S.S 爱好者,即将成为 Linux SysAdmin 和网络开发人员,目前是 TecMint 的内容创作者,他喜欢在电脑上工作,并坚信分享知识。
---
via: <http://www.tecmint.com/install-ftp-server-in-ubuntu/>
作者:[Aaron Kili](http://www.tecmint.com/author/aaronkili/) 译者:[ucasFL](https://github.com/ucasFL) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
8,313 | 使用 chroot 监狱限制 SSH 用户访问指定目录 | http://www.tecmint.com/restrict-ssh-user-to-directory-using-chrooted-jail/ | 2017-03-16T21:53:00 | [
"ssh",
"chroot"
] | https://linux.cn/article-8313-1.html | 将 [SSH 用户会话限制](http://www.tecmint.com/restrict-sftp-user-home-directories-using-chroot/)访问到特定的目录内,特别是在 web 服务器上,这样做有多个原因,但最显而易见的是为了系统安全。为了锁定 SSH 用户在某个目录,我们可以使用 **chroot** 机制。
在诸如 Linux 之类的类 Unix 系统中更改 root(**chroot**)是将特定用户操作与其他 Linux 系统分离的一种手段;使用称为 **chrooted 监狱** 的新根目录更改当前运行的用户进程及其子进程的明显根目录。

在本教程中,我们将向你展示如何限制 SSH 用户访问 Linux 中指定的目录。注意,我们将以 root 用户身份运行所有命令,如果你以普通用户身份登录服务器,请使用 [sudo 命令](https://linux.cn/tag-sudo.html)。
### 步骤 1:创建 SSH chroot 监狱
1、 使用 mkdir 命令开始创建 chroot 监狱:
```
# mkdir -p /home/test
```
2、 接下来,根据 `sshd_config` 手册找到所需的文件,`ChrootDirectory` 选项指定在身份验证后要 chroot 到的目录的路径名。该目录必须包含支持用户会话所必需的文件和目录。
对于交互式会话,这需要至少一个 shell,通常为 `sh` 和基本的 `/dev` 节点,例如 `null`、`zero`、`stdin`、`stdout`、`stderr` 和 `tty` 设备:
```
# ls -l /dev/{null,zero,stdin,stdout,stderr,random,tty}
```

*列出所需文件*
3、 现在,使用 `mknod` 命令创建 `/dev` 下的文件。在下面的命令中,`-m` 标志用来指定文件权限位,`c` 意思是字符文件,两个数字分别是文件指向的主要号和次要号。
```
# mkdir -p /home/test/dev/
# cd /home/test/dev/
# mknod -m 666 null c 1 3
# mknod -m 666 tty c 5 0
# mknod -m 666 zero c 1 5
# mknod -m 666 random c 1 8
```

*创建 /dev 和所需文件*
4、 在此之后,在 chroot 监狱中设置合适的权限。注意 chroot 监狱和它的子目录以及子文件必须被 `root` 用户所有,并且对普通用户或用户组不可写:
```
# chown root:root /home/test
# chmod 0755 /home/test
# ls -ld /home/test
```

*设置目录权限*
### 步骤 2:为 SSH chroot 监狱设置交互式 shell
5、 首先,创建 `bin` 目录并复制 `/bin/bash` 到 `bin` 中:
```
# mkdir -p /home/test/bin
# cp -v /bin/bash /home/test/bin/
```

*复制文件到 bin 目录中*
6、 现在,识别 bash 所需的共享库,如下所示复制它们到 `lib64` 中:
```
# ldd /bin/bash
# mkdir -p /home/test/lib64
# cp -v /lib64/{libtinfo.so.5,libdl.so.2,libc.so.6,ld-linux-x86-64.so.2} /home/test/lib64/
```

*复制共享库文件*
### 步骤 3:创建并配置 SSH 用户
7、 现在,使用 [useradd 命令](http://www.tecmint.com/add-users-in-linux/)创建 SSH 用户,并设置安全密码:
```
# useradd tecmint
# passwd tecmint
```
8、 创建 chroot 监狱通用配置目录 `/home/test/etc` 并复制已更新的账号文件(`/etc/passwd` 和 `/etc/group`)到这个目录中:
```
# mkdir /home/test/etc
# cp -vf /etc/{passwd,group} /home/test/etc/
```

*复制密码文件*
注意:每次向系统添加更多 SSH 用户时,都需要将更新的帐户文件复制到 `/home/test/etc` 目录中。
### 步骤 4:配置 SSH 来使用 chroot 监狱
9、 现在打开 `sshd_config` 文件。
```
# vi /etc/ssh/sshd_config
```
在此文件中添加或修改下面这些行。
```
# 定义要使用 chroot 监狱的用户
Match User tecmint
# 指定 chroot 监狱
ChrootDirectory /home/test
```

*配置 SSH chroot 监狱*
保存文件并退出,重启 sshd 服务:
```
# systemctl restart sshd
或者
# service sshd restart
```
### 步骤 5:测试 SSH 的 chroot 监狱
10、 这次,测试 chroot 监狱的设置是否如希望的那样成功了:
```
# ssh [email protected]
-bash-4.1$ ls
-bash-4.1$ date
-bash-4.1$ uname
```

*测试 SSH 用户 chroot 监狱*
从上面的截图上来看,我们可以看到 SSH 用户被锁定在了 chroot 监狱中,并且不能使用任何外部命令如(`ls`、`date`、`uname` 等等)。
用户只可以执行 `bash` 以及它内置的命令(比如:`pwd`、`history`、`echo` 等等):
```
# ssh [email protected]
-bash-4.1$ pwd
-bash-4.1$ echo "Tecmint - Fastest Growing Linux Site"
-bash-4.1$ history
```

*SSH 内置命令*
### 步骤 6: 创建用户的主目录并添加 Linux 命令
11、 从前面的步骤中,我们可以看到用户被锁定在了 root 目录,我们可以为 SSH 用户创建一个主目录(以及为所有将来的用户这么做):
```
# mkdir -p /home/test/home/tecmint
# chown -R tecmint:tecmint /home/test/home/tecmint
# chmod -R 0700 /home/test/home/tecmint
```

*创建 SSH 用户主目录*
12、 接下来,在 `bin` 目录中安装几个用户命令,如 `ls`、`date`、`mkdir`:
```
# cp -v /bin/ls /home/test/bin/
# cp -v /bin/date /home/test/bin/
# cp -v /bin/mkdir /home/test/bin/
```

*向 SSH 用户添加命令*
13、 接下来,检查上面命令的共享库并将它们移到 chroot 监狱的库目录中:
```
# ldd /bin/ls
# cp -v /lib64/{libselinux.so.1,libcap.so.2,libacl.so.1,libc.so.6,libpcre.so.1,libdl.so.2,ld-linux-x86-64.so.2,libattr.so.1,libpthread.so.0} /home/test/lib64/
```

*复制共享库*
### 步骤 7:测试 sftp 的 用 chroot 监狱
14、 最后用 sftp 做一个测试;测试你先前安装的命令是否可用。
在 `/etc/ssh/sshd_config` 中添加下面的行:
```
# 启用 sftp 的 chroot 监狱
ForceCommand internal-sftp
```
保存并退出文件。接下来重启 sshd 服务:
```
# systemctl restart sshd
或者
# service sshd restart
```
15、 现在使用 ssh 测试,你会得到下面的错误:
```
# ssh [email protected]
```

*测试 SSH Chroot 监狱*
试下使用 sftp:
```
# sftp [email protected]
```

*测试 sFTP SSH 用户*
**建议阅读:** [使用 chroot 监狱将 sftp 用户限制在主目录中](http://www.tecmint.com/restrict-sftp-user-home-directories-using-chroot/)。
就是这样了!在文本中,我们向你展示了如何在 Linux 中限制 ssh 用户到指定的目录中( chroot 监狱)。请在评论栏中给我们提供你的想法。
---
作者简介:
Aaron Kili 是一个 Linux 及 F.O.S.S 热衷者,即将成为 Linux 系统管理员、web 开发者,目前是 TecMint 的内容创作者,他喜欢用电脑工作,并坚信分享知识。
---
via: <http://www.tecmint.com/restrict-ssh-user-to-directory-using-chrooted-jail/>
作者:[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,314 | free:一个在 Linux 中检查内存使用情况的标准命令 | http://www.2daygeek.com/free-command-to-check-memory-usage-statistics-in-linux/ | 2017-03-17T10:09:00 | [
"free",
"内容"
] | https://linux.cn/article-8314-1.html | 我们都知道, IT 基础设施方面的大多数服务器(包括世界顶级的超级计算机)都运行在 Linux 平台上,因为和其他操作系统相比, Linux 更加灵活。有的操作系统对于一些微乎其微的改动和补丁更新都需要重启,但是 Linux 不需要,只有对于一些关键补丁的更新, Linux 才会需要重启。

Linux 系统管理员面临的一大挑战是如何在没有任何停机时间的情况下维护系统的良好运行。管理内存使用是 Linux 管理员又一个具有挑战性的任务。`free` 是 Linux 中一个标准的并且被广泛使用的命令,它被用来分析内存统计(空闲和已用)。今天,我们将要讨论 `free` 命令以及它的一些有用选项。
推荐文章:
* [smem – Linux 下基于进程和用户的内存占用报告](/article-7681-1.html)
* [vmstat:一个标准的报告虚拟内存统计工具](/article-8157-1.html)
### Free 命令是什么
free 命令能够显示系统中物理上的<ruby> 空闲 <rp> ( </rp> <rt> free </rt> <rp> ) </rp></ruby>和<ruby> 已用 <rp> ( </rp> <rt> used </rt> <rp> ) </rp></ruby>内存,还有<ruby> 交换 <rp> ( </rp> <rt> swap </rt> <rp> ) </rp></ruby>内存,同时,也能显示被内核使用的<ruby> 缓冲 <rp> ( </rp> <rt> buffers </rt> <rp> ) </rp></ruby>和<ruby> 缓存 <rp> ( </rp> <rt> caches </rt> <rp> ) </rp></ruby>。这些信息是通过解析文件 `/proc/meminfo` 而收集到的。
### 显示系统内存
不带任何选项运行 `free` 命令会显示系统内存,包括<ruby> 空闲 <rp> ( </rp> <rt> free </rt> <rp> ) </rp></ruby>、<ruby> 已用 <rp> ( </rp> <rt> used </rt> <rp> ) </rp></ruby>、<ruby> 交换 <rp> ( </rp> <rt> swap </rt> <rp> ) </rp></ruby>、<ruby> 缓冲 <rp> ( </rp> <rt> buffers </rt> <rp> ) </rp></ruby>、<ruby> 缓存 <rp> ( </rp> <rt> cached </rt> <rp> ) </rp></ruby>和<ruby> 交换 <rp> ( </rp> <rt> swap </rt> <rp> ) </rp></ruby>的内存总数。
```
# free
total used free shared buffers cached
Mem: 32869744 25434276 7435468 0 412032 23361716
-/+ buffers/cache: 1660528 31209216
Swap: 4095992 0 4095992
```
输出有三行:
* 第一行:表明全部内存、已用内存、空闲内存、共用内存(主要被 tmpfs(`/proc/meminfo` 中的 `Shmem` 项)使用)、用于缓冲的内存以及缓存内容大小。
+ 全部:全部已安装内存(`/proc/meminfo` 中的 `MemTotal` 项)
+ 已用:已用内存(全部计算 - 空闲+缓冲+缓存)
+ 空闲:未使用内存(`/proc/meminfo` 中的 `MemFree` 项)
+ 共用:主要被 tmpfs 使用的内存(`/proc/meminfo` 中的 `Shmem` 项)
+ 缓冲:被内核缓冲使用的内存(`/proc/meminfo` 中的 `Buffers` 项)
+ 缓存:被页面缓存和 slab 使用的内存(`/proc/meminfo` 中的 `Cached` 和 `SSReclaimable` 项)
* 第二行:表明已用和空闲的缓冲/缓存
* 第三行:表明总交换内存(`/proc/meminfo` 中的 `SwapTotal` 项)、空闲内存(`/proc/meminfo` 中的 `SwapFree` 项)和已用交换内存。
### 以 MB 为单位显示系统内存
默认情况下, `free` 命令以 `KB - Kilobytes` 为单位输出系统内存,这对于绝大多数管理员来说会有一点迷糊(当系统内存很大的时候,我们中的许多人需要把输出转化为以 MB 为单位,从而才能够理解内存大小)。为了避免这个迷惑,我们在 `free` 命令后面加上 `-m` 选项,就可以立即得到以 `MB - Megabytes`为单位的输出。
```
# free -m
total used free shared buffers cached
Mem: 32099 24838 7261 0 402 22814
-/+ buffers/cache: 1621 30477
Swap: 3999 0 3999
```
如何从上面的输出中检查剩余多少空闲内存?主要基于<ruby> 已用 <rp> ( </rp> <rt> used </rt> <rp> ) </rp></ruby>和<ruby> 空闲 <rp> ( </rp> <rt> free </rt> <rp> ) </rp></ruby>两列。你可能在想,你只有很低的空闲内存,因为它只有 `10%`, 为什么?
* 全部实际可用内存 = (全部内存 - 第 2 行的已用内存)
+ 全部内存 = 32099
+ 实际已用内存 = 1621 ( = 全部内存 - 缓冲 - 缓存)
* 全部实际可用内存 = 30477
如果你的 Linux 版本是最新的,那么有一个查看实际空闲内存的选项,叫做<ruby> 可用 <rp> ( </rp> <rt> available </rt> <rp> ) </rp></ruby> ,对于旧的版本,请看显示 `-/+ buffers/cache` 那一行对应的空闲(`free`)一列。
如何从上面的输出中检查有多少实际已用内存?基于<ruby> 已用 <rp> ( </rp> <rt> used </rt> <rp> ) </rp></ruby>和<ruby> 空闲 <rp> ( </rp> <rt> free </rt> <rp> ) </rp></ruby>一列。你可能想,你已经使用了超过 `95%` 的内存。
* 全部实际已用内存 = 第一列已用 - (第一列缓冲 + 第一列缓存)
+ 已用内存 = 24838
+ 已用缓冲 = 402
+ 已用缓存 = 22814
* 全部实际已用内存 = 1621
### 以 GB 为单位显示内存
默认情况下, `free` 命令会以 `KB - kilobytes` 为单位显示输出,这对于大多数管理员来说会有一些迷惑,所以我们使用上面的选项来获得以 `MB - Megabytes` 为单位的输出。但是,当服务器的内存很大(超过 100 GB 或 200 GB)时,上面的选项也会让人很迷惑。所以,在这个时候,我们可以在 `free` 命令后面加上 `-g` 选项,从而立即得到以 `GB - Gigabytes` 为单位的输出。
```
# free -g
total used free shared buffers cached
Mem: 31 24 7 0 0 22
-/+ buffers/cache: 1 29
Swap: 3 0 3
```
### 显示全部内存行
默认情况下, `free` 命令的输出只有三行(内存、缓冲/缓存以及交换)。为了统一以单独一行显示(全部(内存+交换)、已用(内存+(已用-缓冲/缓存)+交换)以及空闲(内存+(已用-缓冲/缓存)+交换),在 ‘free’ 命令后面加上 `-t` 选项。
```
# free -t
total used free shared buffers cached
Mem: 32869744 25434276 7435468 0 412032 23361716
-/+ buffers/cache: 1660528 31209216
Swap: 4095992 0 4095992
Total: 36965736 27094804 42740676
```
### 按延迟运行 free 命令以便更好的统计
默认情况下, `free` 命令只会显示一次统计输出,这是不足够进一步排除故障的,所以,可以通过添加延迟(延迟是指在几秒后再次更新)来定期统计内存活动。如果你想以两秒的延迟运行 `free` 命令,可以使用下面的命令(如果你想要更多的延迟,你可以按照你的意愿更改数值)。
下面的命令将会每 2 秒运行一次直到你退出:
```
# free -s 2
total used free shared buffers cached
Mem: 32849392 25935844 6913548 188 182424 24632796
-/+ buffers/cache: 1120624 31728768
Swap: 20970492 0 20970492
total used free shared buffers cached
Mem: 32849392 25935288 6914104 188 182424 24632796
-/+ buffers/cache: 1120068 31729324
Swap: 20970492 0 20970492
total used free shared buffers cached
Mem: 32849392 25934968 6914424 188 182424 24632796
-/+ buffers/cache: 1119748 31729644
Swap: 20970492 0 20970492
```
### 按延迟和具体次数运行 free 命令
另外,你可以按延迟和具体次数运行 `free` 命令,一旦达到某个次数,便自动退出。
下面的命令将会每 2 秒运行一次 free 命令,计数 5 次以后自动退出。
```
# free -s 2 -c 5
total used free shared buffers cached
Mem: 32849392 25931052 6918340 188 182424 24632796
-/+ buffers/cache: 1115832 31733560
Swap: 20970492 0 20970492
total used free shared buffers cached
Mem: 32849392 25931192 6918200 188 182424 24632796
-/+ buffers/cache: 1115972 31733420
Swap: 20970492 0 20970492
total used free shared buffers cached
Mem: 32849392 25931348 6918044 188 182424 24632796
-/+ buffers/cache: 1116128 31733264
Swap: 20970492 0 20970492
total used free shared buffers cached
Mem: 32849392 25931316 6918076 188 182424 24632796
-/+ buffers/cache: 1116096 31733296
Swap: 20970492 0 20970492
total used free shared buffers cached
Mem: 32849392 25931308 6918084 188 182424 24632796
-/+ buffers/cache: 1116088 31733304
Swap: 20970492 0 20970492
```
### 人类可读格式
为了以人类可读的格式输出,在 `free` 命令的后面加上 `-h` 选项,和其他选项比如 `-m` 和 `-g` 相比,这将会更人性化输出(自动使用 GB 和 MB 单位)。
```
# free -h
total used free shared buff/cache available
Mem: 2.0G 1.6G 138M 20M 188M 161M
Swap: 2.0G 1.8G 249M
```
### 取消缓冲区和缓存内存输出
默认情况下,缓冲/缓存内存是同时输出的。为了取消缓冲和缓存内存的输出,可以在 `free` 命令后面加上 `-w` 选项。(该选项在版本 3.3.12 上可用)
注意比较上面有缓冲/缓存的输出。
```
# free -wh
total used free shared buffers cache available
Mem: 2.0G 1.6G 137M 20M 8.1M 183M 163M
Swap: 2.0G 1.8G 249M
```
### 显示最低和最高的内存统计
默认情况下, `free` 命令不会显示最低和最高的内存统计。为了显示最低和最高的内存统计,在 free 命令后面加上 `-l` 选项。
```
# free -l
total used free shared buffers cached
Mem: 32849392 25931336 6918056 188 182424 24632808
Low: 32849392 25931336 6918056
High: 0 0 0
-/+ buffers/cache: 1116104 31733288
Swap: 20970492 0 20970492
```
### 阅读关于 free 命令的更过信息
如果你想了解 free 命令的更多可用选项,只需查看其 [man 手册](https://linux.cn/man/man1/free.1.html)。
```
# free --help
or
# man free
```
---
via: <http://www.2daygeek.com/free-command-to-check-memory-usage-statistics-in-linux/>
作者:[MAGESH MARUTHAMUTHU](http://www.2daygeek.com/author/magesh/) 译者:[ucasFL](https://github.com/ucasFL) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
8,315 | 如何在 Amazon AWS 上设置一台 Linux 服务器 | https://www.howtoforge.com/tutorial/how-to-setup-linux-server-with-aws/ | 2017-03-18T10:04:00 | [
"AWS"
] | https://linux.cn/article-8315-1.html | AWS(Amazon Web Services)是全球领先的云服务器提供商之一。你可以使用 AWS 平台在一分钟内设置完服务器。在 AWS 上,你可以微调服务器的许多技术细节,如 CPU 数量,内存和磁盘空间,磁盘类型(更快的 SSD 或者经典的 IDE)等。关于 AWS 最好的一点是,你只需要为你使用到的服务付费。在开始之前,AWS 提供了一个名为 “Free Tier” 的特殊帐户,你可以免费使用一年的 AWS 技术服务,但会有一些小限制,例如,你每个月使用服务器时长不能超过 750 小时,超过这个他们就会向你收费。你可以在 [aws 官网](http://aws.amazon.com/free/)上查看所有相关的规则。

因为我的这篇文章是关于在 AWS 上创建 Linux 服务器,因此拥有 “Free Tier” 帐户是先决条件。要注册帐户,你可以使用此[链接](http://aws.amazon.com/ec2/)。请注意,你需要在创建帐户时输入信用卡详细信息。
让我们假设你已经创建了 “Free Tier” 帐户。
在继续之前,你必须了解 AWS 中的一些术语以了解设置:
1. EC2(弹性计算云):此术语用于虚拟机。
2. AMI(Amazon 机器镜像):表示操作系统实例。
3. EBS(弹性块存储):AWS 中的一种存储环境类型。
通过以下链接登录 AWS 控制台:<https://console.aws.amazon.com/> 。
AWS 控制台将如下所示:

### 在 AWS 中设置 Linux VM
1、 创建一个 EC2(虚拟机)实例:在开始安装系统之前,你必须在 AWS 中创建一台虚拟机。要创建虚拟机,在“<ruby> 计算 <rt> compute </rt></ruby>”菜单下点击 EC2:

2、 现在在<ruby> 创建实例 <rt> Create instance </rt></ruby>下点击<ruby> “启动实例” <rt> Launch Instance </rt></ruby>按钮。

3、 现在,当你使用的是一个 “Free Tier” 帐号,接着最好选择 “Free Tier” 单选按钮以便 AWS 可以过滤出可以免费使用的实例。这可以让你不用为使用 AWS 的资源而付费。

4、 要继续操作,请选择以下选项:
a、 在经典实例向导中选择一个 AMI(Amazon Machine Image),然后选择使用 **Red Hat Enterprise Linux 7.2(HVM),SSD 存储**
b、 选择 “**t2.micro**” 作为实例详细信息。
c、 **配置实例详细信息**:不要更改任何内容,只需单击下一步。
d、 **添加存储**:不要更改任何内容,只需点击下一步,因为此时我们将使用默认的 10(GiB)硬盘。
e、 **添加标签**:不要更改任何内容只需点击下一步。
f、 **配置安全组**:现在选择用于 ssh 的 22 端口,以便你可以在任何地方访问此服务器。

g、 选择“<ruby> 查看并启动 <rt> Review and Launch </rt></ruby>”按钮。
h、 如果所有的详情都无误,点击 “<ruby> 启动 <rt> Launch </rt></ruby>”按钮。
i、 单击“<ruby> 启动 <rt> Launch </rt></ruby>”按钮后,系统会像下面那样弹出一个窗口以创建“密钥对”:选择选项“<ruby> 创建密钥对 <rt> create a new key pair </rt></ruby>”,并给密钥对起个名字,然后下载下来。在使用 ssh 连接到服务器时,需要此密钥对。最后,单击“<ruby> 启动实例 <rt> Launch Instance </rt></ruby>”按钮。

j、 点击“<ruby> 启动实例 <rt> Launch Instance </rt></ruby>”按钮后,转到左上角的服务。选择“<ruby> 计算 <rt> compute </rt></ruby>”--> “EC2”。现在点击“<ruby> 运行实例 <rt> Running Instances </rt></ruby>”:

k、 现在你可以看到,你的新 VM 的状态是 “<ruby> 运行中 <rt> running </rt></ruby>”。选择实例,请记下登录到服务器所需的 “<ruby> 公开 DNS 名称 <rt> Public DNS </rt></ruby>”。

现在你已完成创建一台运行 Linux 的 VM。要连接到服务器,请按照以下步骤操作。
### 从 Windows 中连接到 EC2 实例
1、 首先,你需要有 putty gen 和 Putty exe 用于从 Windows 连接到服务器(或 Linux 上的 SSH 命令)。你可以通过下面的[链接](http://www.chiark.greenend.org.uk/%7Esgtatham/putty/latest.html)下载 putty。
2、 现在打开 putty gen :`puttygen.exe`。
3、 你需要单击 “Load” 按钮,浏览并选择你从亚马逊上面下载的密钥对文件(pem 文件)。
4、 你需要选择 “ssh2-RSA” 选项,然后单击保存私钥按钮。请在下一个弹出窗口中选择 “yes”。
5、 将文件以扩展名 `.ppk` 保存。
6、 现在你需要打开 `putty.exe`。在左侧菜单中点击 “connect”,然后选择 “SSH”,然后选择 “Auth”。你需要单击浏览按钮来选择我们在步骤 4 中创建的 .ppk 文件。
7、 现在点击 “session” 菜单,并在“host name” 中粘贴在本教程中 “k” 步骤中的 DNS 值,然后点击 “open” 按钮。
8、 在要求用户名和密码时,输入 `ec2-user` 和空白密码,然后输入下面的命令。
```
$ sudo su -
```
哈哈,你现在是在 AWS 云上托管的 Linux 服务器上的主人啦。

---
via: <https://www.howtoforge.com/tutorial/how-to-setup-linux-server-with-aws/>
作者:[MANMOHAN MIRKAR](https://www.howtoforge.com/tutorial/how-to-setup-linux-server-with-aws/) 译者:[geekpi](https://github.com/geekpi) 校对:[jasminepeng](https://github.com/jasminepeng)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 200 | OK | # How to setup a Linux server on Amazon AWS
AWS (Amazon Web Services) is one of the leading cloud server providers worldwide. You can setup a server within a minute using the AWS platform. On AWS, you can fine tune many techncal details of your server like the number of CPU's, Memory and HDD space, type of HDD (SSD which is faster or a classic IDE) and so on. And the best thing about the AWS is that you need to pay only for the services that you have used. To get started, AWS provides a special account called "Free tier" where you can use the AWS technology free for one year with some minor restrictions like you can use the server only upto 750 Hours a month, when you cross this theshold they will charge you. You can check all the rules related this on [aws portal](http://aws.amazon.com/free/).
Since I am writing this post about creating a Linux server on AWS, having a "Free Tier" account is the main pre-requisite. To sign up for this account you can use this [link](http://aws.amazon.com/ec2/). Kindly note that you need to enter your credit card details while creating the account.
So let's assume that you have created the "free tier" account.
Before we proceed, you must know some of the terminologies in AWS to understand the setup:
- EC2 (Elastic compute cloud): This term used for the virtual machine.
- AMI (Amazon machine image): Used for the OS instance.
- EBS (Elastic block storage): one of the type Storage environment in AWS.
Now login to AWS console at below location:
[https://console.aws.amazon.com/](https://console.aws.amazon.com/)
The AWS console will look like this:
## Setup a Linux VM in AWS
1: Create an EC2 (virtual machine) instance: Before installing the OS on you must create a VM in AWS. To create this, click on EC2 under compute menu:
2. Now click on "Launch Instance" Button under Create instance.
3. Now, when you are using a free tier account, then better select the Free Tier radio button so that AWS will filter the instances which are used for free usage. This will keep you aside from paying money to AWS for using billed resources under AWS.
4. To proceed further, select following options:
a. **Choose an AMI in the classic instance wizard: selection --> I'll use Red Hat Enterprise Linux 7.2 (HVM), SSD Volume Type here**
b. Select "**t2.micro**" for the instance details.
c. **Configure Instance Details**: Do not change anything simply click next.
d. **Add Storage: **Do not change anything simply click next as we will using default Size 10 (GiB) Hard disk in this case.
e. **Add Tags**: Do not change anything simply click next.
f. **Configure Security Group**: Now select port 22 which is used for ssh so that you can access this server from anywhere.
g. **Select review and launch button**
h. If all the details are Ok now press the "**Launch**" button,
i. Once you clicked the Launch button, a popup window gets displayed to create a "Key pair" as shown below: Select the option "create a new key pair" and give a name to key pair. Then download the same. You require this key pair while connecting to the server using ssh. At the end, click the "Launch Instance" button.
j. After clicking Launch instance Button, go to services at the left top side. Select Compute--> EC2. Now click on running instance link as below:
k. Now you can see that your new VM is ready with status "running" as shown below. Select the Instance and Please note down the "Public DNS value" which is required for logging on to the server.
Now you are done with creating a sample Linux installed VM. To connect to the server, follow below steps.
## Connect to an EC2 instance from Windows
1. First of all, you need to have putty gen and Putty exe's for connecting to the server from Windows (or the SSH command on Linux). You can download putty by following this [Link](http://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html).
2. Now open the putty gen "puttygen.exe".
3. You need to click on the "Load button", browse and select the keypair file (pem file) that you downloaded above from Amazon.
4. You need to select the "ssh2-RSA" option and click on the save private key button. Kindly select yes on the next pop-up.
5. Save the file with the file extension .ppk.
6. Now you need to open Putty.exe. Go to connection at the left side menu then select "SSH" and then select "Auth". You need to click on the browse button to select the .ppk file that we created in the step 4.
7. Now click on the "session" menu and paste the DNS value captured during the 'k' step of this tutorial in the "host name" box and hit the open button.
8. Upon asking for username and password, enter "**ec2-user**" and blank password and then give below command.
$sudo su -
Hurray, you are now root on the Linux server which is hosted on AWS cloud. |
8,316 | 漫画赏析:Bash 的历史 | http://turnoff.us/geek/bash-history/ | 2017-03-18T20:42:00 | [
"漫画",
"bash"
] | https://linux.cn/article-8316-1.html | 
在 Linux 中,`.bash_history` 原本的功能为存储在 bash 下执行过的命令历史,在这里,引申为 bash 的历史。所以在展示 `.bash_history` 返回了下面的摘自维基百科的内容。
---
via: <http://turnoff.us/geek/bash-history/>
作者:[Daniel Stori](http://turnoff.us/geek/bash-history/) 译者:[name1e5s](https://github.com/name1e5s) 点评:[bestony](https://github.com/bestony) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
8,318 | 漫画赏析:消沉的程序员系列 | http://turnoff.us/geek/the-depressed-developer/ | 2017-03-19T09:19:00 | [
"程序员",
"漫画"
] | https://linux.cn/article-8318-1.html | ### 消沉的程序员 1

很有意思吧,很多看到这样的漫画对话的程序员,应该感觉似曾相识吧。Bug 出现了?
### 消沉的程序员 2

有点疑惑,有好像有点眉目,好像是感觉到哪里错了,是不是要重构。
### 消沉的程序员 3

哎,终于发现错误了,感觉有点可笑,自己居然犯这样的错误,原来是那次急于提交代码造成的。
### 消沉的程序员 4

是啊,在编程里一生戎马,代码编写无数,各种平台、规范等等,到头来也是满身的错误啊。该是技术不行吧!
### 消沉的程序员 5

呀,快要消除错误了,可是,不对。相信事后的 Bug 和 Debug 会是程序员生活中的一个部分。
### 消沉的程序员 6

每个新建的工程都是有美好的设想吧,可后来为什么总是渐行渐远?大多时候的自言自语,总是有人认为是在和代码对话吧?可没有身在其中,别人又怎么懂得!
### 消沉的程序员 7

好吧,产品的上线,总是要经过无数次的创建分支,Bug 和 Debug 总还是程序员的永恒话题。其中,有些东西总免不了自己推翻自己,感觉要从头再来一样。
### 消沉的程序员 10

为了某项专门的研究,学习一门相关的语言,不知道是不是值得?是不是先要思考其必要性呢?最后发现自己并不喜欢这门语言,导致怀疑自己的专业技能,这样大概不好吧!
### 消沉的程序员 11

其实,本来是愉快的蹲个坑,却不自觉的陷入编码的思考。想想,不仅是程序员,很多人有都有类似此景的情况吧,明明在做着某事,却想着另外一件事。
### 后记
看至此处,各位朋友是不是感觉少了系列的第 8 和第 9 篇?起初,译者也这么想,后来问了作者 Daniel Stori 之后,才恍然,原来序号采用了八进制,按照作者说的,一个隐式的玩笑。明白了吗,朋友们?
大伙儿都习惯了日常的十进制。当常态处于优先级的时候,日常一些非常态就如同细枝末节,也就往往容易被人们忽略。大概就是这样吧。
---
译者简介:
[GHLandy](http://GHLandy.com) —— 生活中所有欢乐与苦闷都应藏在心中,有些事儿注定无人知晓,自己也无从说起。
---
via:
* <http://turnoff.us/geek/the-depressed-developer/>
* <http://turnoff.us/geek/the-depressed-developer-2/>
* <http://turnoff.us/geek/the-depressed-developer-3/>
* <http://turnoff.us/geek/the-depressed-developer-4/>
* <http://turnoff.us/geek/the-depressed-developer-5/>
* <http://turnoff.us/geek/the-depressed-developer-6/>
* <http://turnoff.us/geek/the-depressed-developer-7/>
* <http://turnoff.us/geek/the-depressed-developer-10/>
* <http://turnoff.us/geek/the-depressed-developer-11/>
作者:[Daniel Stori](http://turnoff.us/about/) 译者:[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,319 | 如何在 Linux 中安装最新的 Python 3.6 版本 | http://www.tecmint.com/install-python-in-linux/ | 2017-03-19T10:32:00 | [
"Python",
"Python3"
] | https://linux.cn/article-8319-1.html | 在这篇文章中,我将展示如何在 CentOS/RHEL 7、Debian 以及它的衍生版本比如 Ubuntu(最新的 Ubuntu 16.04 LTS 版本已经安装了最新的 Python 版本)或 Linux Mint 上安装和使用 Python 3.x 。我们的重点是安装可用于命令行的核心语言工具。
然后,我们也会阐述如何安装 Python IDLE - 一个基于 GUI 的工具,它允许我们运行 Python 代码和创建独立函数。

### 在 Linux 中安装 Python 3.6
在我写这篇文章的时候(2017 年三月中旬),在 CentOS 和 Debian 8 中可用的最新 Python 版本分别是 Python 3.4 和 Python 3.5 。
虽然我们可以使用 [yum](/tag-yum.html) 和 [aptitude](/tag-aptitude.html)(或 [apt-get](/tag-apt-get.html))安装核心安装包以及它们的依赖,但在这儿,我将阐述如何使用源代码进行安装。
为什么?理由很简单:这样我们能够获取语言的最新的稳定发行版(3.6),并且提供了一种和 Linux 版本无关的安装方法。
在 CentOS 7 中安装 Python 之前,请确保系统中已经有了所有必要的开发依赖:
```
# yum -y groupinstall development
# yum -y install zlib-devel
```
在 Debian 中,我们需要安装 gcc、make 和 zlib 压缩/解压缩库:
```
# aptitude -y install gcc make zlib1g-dev
```
运行下面的命令来安装 Python 3.6:
```
# wget https://www.python.org/ftp/python/3.6.0/Python-3.6.0.tar.xz
# tar xJf Python-3.6.0.tar.xz
# cd Python-3.6.0
# ./configure
# make && make install
```
现在,放松一下,或者饿的话去吃个三明治,因为这可能需要花费一些时间。安装完成以后,使用 `which` 命令来查看主要二进制代码的位置:
```
# which python3
# python3 -V
```
上面的命令的输出应该和这相似:

*查看 Linux 系统中的 Python 版本*
要退出 Python 提示符,只需输入:
```
quit()
或
exit()
```
然后按回车键。
恭喜!Python 3.6 已经安装在你的系统上了。
### 在 Linux 中安装 Python IDLE
Python IDLE 是一个基于 GUI 的 Python 工具。如果你想安装 Python IDLE,请安装叫做 idle(Debian)或 python-tools(CentOS)的包:
```
# apt-get install idle [On Debian]
# yum install python-tools [On CentOS]
```
输入下面的命令启动 Python IDLE:
```
# idle
```
### 总结
在这篇文章中,我们阐述了如何从源代码安装最新的 Python 稳定版本。
最后但不是不重要,如果你之前使用 Python 2,那么你可能需要看一下 [从 Python 2 迁移到 Python 3 的官方文档](https://docs.python.org/3.6/library/2to3.html)。这是一个可以读入 Python 2 代码,然后转化为有效的 Python 3 代码的程序。
你有任何关于这篇文章的问题或想法吗?请使用下面的评论栏与我们联系
---
作者简介:
Gabriel Cánepa - 一位来自<ruby> 阿根廷圣路易斯梅塞德斯镇 <rp> ( </rp> <rt> Villa Mercedes, San Luis, Argentina </rt> <rp> ) </rp></ruby> 的 GNU/Linux 系统管理员,Web 开发者。就职于一家世界领先级的消费品公司,乐于在每天的工作中能使用 FOSS 工具来提高生产力。
---
via: <http://www.tecmint.com/install-python-in-linux/>
作者:[Gabriel Cánepa](http://www.tecmint.com/author/gacanepa/) 译者:[ucasFL](https://github.com/ucasFL) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
8,320 | 如何在 CentOS 7 上安装和安全配置 MariaDB 10 | http://www.tecmint.com/install-mariadb-in-centos-7/ | 2017-03-19T14:40:00 | [
"MySQL",
"MariaDB",
"数据库"
] | https://linux.cn/article-8320-1.html | **MariaDB** 是 MySQL 数据库的自由开源分支,与 MySQL 在设计思想上同出一源,在未来仍将是自由且开源的。
在这篇博文中,我将会介绍如何在当前使用最广的 RHEL/CentOS 和 Fedora 发行版上安装 **MariaDB 10.1** 稳定版。
目前了解到的情况是:Red Hat Enterprise Linux/CentOS 7.0 发行版已将默认的数据库从 MySQL 切换到 MariaDB。
在本文中需要注意的是,我们假定您能够在服务器中使用 root 帐号工作,或者可以使用 [sudo](/tag-sudo.html) 命令运行任何命令。

### 第一步:添加 MariaDB yum 仓库
1、首先在 RHEL/CentOS 和 Fedora 操作系统中添加 MariaDB 的 YUM 配置文件 `MariaDB.repo` 文件。
```
# vi /etc/yum.repos.d/MariaDB.repo
```
根据您操作系统版本,选择下面的相应内容添加到文件的末尾。
#### 在 CentOS 7 中安装
```
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.1/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
```
#### 在 RHEL 7 中安装
```
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.1/rhel7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
```

*添加 MariaDB YUM 仓库*
### 第二步:在 CentOS 7 中安装 MariaDB
2、当 MariaDB 仓库地址添加好后,你可以通过下面的一行命令轻松安装 MariaDB。
```
# yum install MariaDB-server MariaDB-client -y
```

*在 CentOS 7 中安装 MariaDB*
3、 MariaDB 包安装完毕后,立即启动数据库服务守护进程,并可以通过下面的操作设置,在操作系统重启后自动启动服务。
```
# systemctl start mariadb
# systemctl enable mariadb
# systemctl status mariadb
```

*在 CentOS 7 中启动 MariaDB 服务*
### 第三步:在 CentOS 7 中对 MariaDB 进行安全配置
4、 现在可以通过以下操作进行安全配置:设置 MariaDB 的 root 账户密码,禁用 root 远程登录,删除测试数据库以及测试帐号,最后需要使用下面的命令重新加载权限。
```
# mysql_secure_installation
```

*CentOS 7 中的 MySQL 安全配置*
5、 在配置完数据库的安全配置后,你可能想检查下 MariaDB 的特性,比如:版本号、默认参数列表、以及通过 MariaDB 命令行登录。如下所示:
```
# mysql -V
# mysqld --print-defaults
# mysql -u root -p
```

*检查 MySQL 版本信息*
### 第四步:学习 MariaDB 管理
如果你刚开始学习使用 MySQL/MariaDB,可以通过以下指南学习:
1. [新手学习 MySQL / MariaDB(一)](http://www.tecmint.com/learn-mysql-mariadb-for-beginners/)
2. [新手学习 MySQL / MariaDB(二)](http://www.tecmint.com/learn-mysql-mariadb-advance-functions-sql-queries/)
3. [MySQL 数据库基础管理命令(三)](http://www.tecmint.com/gliding-through-database-mysql-in-a-nutshell-part-i/)
4. [20 MySQL 管理命令 Mysqladmin(四)](http://www.tecmint.com/mysqladmin-commands-for-database-administration-in-linux/)
同样查看下面的文档学习如何优化你的 MySQL/MariaDB 服务,并使用工具监控数据库的活动情况。
1. [15 个 MySQL/MariaDB 调优技巧](/article-5730-1.html)
2. [4 监控 MySQL/MariaDB 数据库的工具](http://www.tecmint.com/mysql-performance-monitoring/)
文章到此就结束了,本文内容比较浅显,文中主要展示了如何在 RHEL/CentOS 和 Fefora 操作系统中安装 **MariaDB 10.1** 稳定版。您可以通过下面的联系方式将您遇到的任何问题或者想法发给我们。
---
作者简介: Aaron Kill 是 Linux 和开源软件的狂热爱好者,即将成为一名 Linux 系统管理员和网站开发工程师,现在是 TecMint 的原创作者,喜欢使用电脑工作并且热衷分享知识。
---
via: <http://www.tecmint.com/install-mariadb-in-centos-7/>
作者:[Aaron Kili](http://www.tecmint.com/author/aaronkili/) 译者:[beyondworld](https://github.com/beyondworld) 校对:[jasminepeng](https://github.com/jasminepeng)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
8,322 | Linux 爱好者的飞行棋 | http://turnoff.us/geek/sudo-board-game/ | 2017-03-21T11:57:00 | [
"漫画",
"游戏"
] | https://linux.cn/article-8322-1.html | 
今天为大家带来一款棋盘游戏 **Sudo** ——没错,就是叫 `sudo` 。其得名于一款名为 [Ludo](https://en.wikipedia.org/wiki/Ludo_(board_game)) (印度马棋)的一款棋盘游戏,它是飞行棋的前身。规则与飞行棋大体相同。
我们平时玩的棋子,在这款游戏中叫做**进程**。而我们平时使用的骰子,也变成了二进制的了。
游戏支持 2 ~ 4 人一起玩耍,每一方起始有四枚“进程”。总共有 4 方:CentOS 队、Fedora 队、Ubuntu 队和 Mint 队。
开局时,各方将四枚“进程”放入各自区域的“基地”中,然后轮流掷骰子,掷得最高点数者开局。开局后再次轮流掷骰子,只有掷得 6 点的人才可以将一枚棋子从“基地”移入起始点(**init**),并再掷一次来确定移动步数。
玩家掷骰子之后,可以选择任一已经进入了起始点(**init**)的“进程”移动。没有进入起始点(**init**)的“进程”不可移动。
“进程”从起始点(**init**)沿外侧白色格子盘旋整个棋盘一周后才能回到自己本色的中间那一列(主列)抵达中间区域(**kernel space**)。最终将四枚“进程”全部都移入了中间区域(**kernel space**)的玩家获胜。
具体的规则还有:
* 六点连掷:在游戏过程中,掷得 6 点的玩家可以再次掷骰子,直到不是 6 点;然后就轮到(顺时针)下一位玩家掷骰子;
* 撞击占领:当走到的格子有其它方的“进程”时,将其撞回“基地”,我方的“进程”占领此格子;
* 叠子阻越:格子内已有我方“进程”,则可以叠放;其它方的“进程”不可越过此格子;
* 单撞叠子:当我方掷出骰子数,刚好使我方“进程”可停于他方的两个叠子时,则三个“进程”俱都打回“基地”;
* 无敌叠子:当我方掷出骰子数,刚好使我方“进程”可停于他方的三个叠子时,则只有我方“进程”被打回“基地”;
* 盘旋达阵:中间终点同色格子,当掷出的点数使“进程”刚好到达此处才可放入“kernel space”,否则超过的点数要后退。
(规则参考:[http://oursogo.com/thread-1881293-1-1.html)](http://oursogo.com/thread-1881293-1-1.html%EF%BC%89)
此外,这里还有补充的规则:
* **Kill-9** 格子:Kill-9 会杀掉我们的“进程”。你需要让你的“进程”回到起始点(**init**)格子去。
* **/dev/cool** 格子: /dev/cool 会帮助我们越过长长的区块,一下子就跳到内核的面前。不过,只有在这个区块的颜色和我们的棋子的颜色一致时,才有用。
* **Fork** 格子 : 如果你有一个进程已经抵达了目的地(**kernel space**),当你有别的进程走到 fork 时,你之前的进程就要返回到路上,并移动到这个格子上。
如果你真的对这个游戏很感兴趣,不妨把我们提供的图片打印出来,进行裁剪、黏贴。就可以真正的玩一把 Sudo 游戏啦!
---
via: <http://turnoff.us/geek/sudo-board-game/>
作者:[Daniel Stori](http://turnoff.us/about/) 译者:[Bestony](https://github.com/Bestony) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
8,323 | CentOS 7 上的 FirewallD 简明指南 | https://www.rosehosting.com/blog/set-up-and-configure-a-firewall-with-firewalld-on-centos-7/ | 2017-03-21T15:21:43 | [
"防火墙",
"FirewallD"
] | https://linux.cn/article-8323-1.html | 
FirewallD 是 CentOS 7 服务器上默认可用的防火墙管理工具。基本上,它是 iptables 的封装,有图形配置工具 firewall-config 和命令行工具 `firewall-cmd`。使用 iptables 服务,每次改动都要求刷新旧规则,并且从 `/etc/sysconfig/iptables` 读取新规则,然而 firewalld 只应用改动了的不同部分。
### FirewallD 的<ruby> 区域 <rp> ( </rp> <rt> zone </rt> <rp> ) </rp></ruby>
FirewallD 使用<ruby> 服务 <rp> ( </rp> <rt> service </rt> <rp> ) </rp></ruby> 和<ruby> 区域 <rp> ( </rp> <rt> zone </rt> <rp> ) </rp></ruby>来代替 iptables 的<ruby> 规则 <rp> ( </rp> <rt> rule </rt> <rp> ) </rp></ruby>和<ruby> 链 <rp> ( </rp> <rt> chain </rt> <rp> ) </rp></ruby>。
默认情况下,有以下的<ruby> 区域 <rp> ( </rp> <rt> zone </rt> <rp> ) </rp></ruby>可用:
* **drop** – 丢弃所有传入的网络数据包并且无回应,只有传出网络连接可用。
* **block** — 拒绝所有传入网络数据包并回应一条主机禁止的 ICMP 消息,只有传出网络连接可用。
* **public** — 只接受被选择的传入网络连接,用于公共区域。
* **external** — 用于启用了地址伪装的外部网络,只接受选定的传入网络连接。
* **dmz** — DMZ 隔离区,外部受限地访问内部网络,只接受选定的传入网络连接。
* **work** — 对于处在你工作区域内的计算机,只接受被选择的传入网络连接。
* **home** — 对于处在你家庭区域内的计算机,只接受被选择的传入网络连接。
* **internal** — 对于处在你内部网络的计算机,只接受被选择的传入网络连接。
* **trusted** — 所有网络连接都接受。
要列出所有可用的区域,运行:
```
# firewall-cmd --get-zones
work drop internal external trusted home dmz public block
```
列出默认的区域 :
```
# firewall-cmd --get-default-zone
public
```
改变默认的区域 :
```
# firewall-cmd --set-default-zone=dmz
# firewall-cmd --get-default-zone
dmz
```
### FirewallD 服务
FirewallD 服务使用 XML 配置文件,记录了 firewalld 服务信息。
列出所有可用的服务:
```
# firewall-cmd --get-services
amanda-client amanda-k5-client bacula bacula-client ceph ceph-mon dhcp dhcpv6 dhcpv6-client dns docker-registry dropbox-lansync freeipa-ldap freeipa-ldaps freeipa-replication ftp high-availability http https imap imaps ipp ipp-client ipsec iscsi-target kadmin kerberos kpasswd ldap ldaps libvirt libvirt-tls mdns mosh mountd ms-wbt mysql nfs ntp openvpn pmcd pmproxy pmwebapi pmwebapis pop3 pop3s postgresql privoxy proxy-dhcp ptp pulseaudio puppetmaster radius rpc-bind rsyncd samba samba-client sane smtp smtps snmp snmptrap squid ssh synergy syslog syslog-tls telnet tftp tftp-client tinc tor-socks transmission-client vdsm vnc-server wbem-https xmpp-bosh xmpp-client xmpp-local xmpp-server
```
XML 配置文件存储在 `/usr/lib/firewalld/services/` 和 `/etc/firewalld/services/` 目录下。
### 用 FirewallD 配置你的防火墙
作为一个例子,假设你正在运行一个 web 服务器,SSH 服务端口为 7022 ,以及邮件服务,你可以利用 FirewallD 这样配置你的服务器:
首先设置默认区为 dmz。
```
# firewall-cmd --set-default-zone=dmz
# firewall-cmd --get-default-zone
dmz
```
为 dmz 区添加持久性的 HTTP 和 HTTPS 规则:
```
# firewall-cmd --zone=dmz --add-service=http --permanent
# firewall-cmd --zone=dmz --add-service=https --permanent
```
开启端口 25 (SMTP) 和端口 465 (SMTPS) :
```
firewall-cmd --zone=dmz --add-service=smtp --permanent
firewall-cmd --zone=dmz --add-service=smtps --permanent
```
开启 IMAP、IMAPS、POP3 和 POP3S 端口:
```
firewall-cmd --zone=dmz --add-service=imap --permanent
firewall-cmd --zone=dmz --add-service=imaps --permanent
firewall-cmd --zone=dmz --add-service=pop3 --permanent
firewall-cmd --zone=dmz --add-service=pop3s --permanent
```
因为将 SSH 端口改到了 7022,所以要移除 ssh 服务(端口 22),开启端口 7022:
```
firewall-cmd --remove-service=ssh --permanent
firewall-cmd --add-port=7022/tcp --permanent
```
要应用这些更改,我们需要重新加载防火墙:
```
firewall-cmd --reload
```
最后可以列出这些规则:
```
# firewall-cmd –list-all
dmz
target: default
icmp-block-inversion: no
interfaces:
sources:
services: http https imap imaps pop3 pop3s smtp smtps
ports: 7022/tcp
protocols:
masquerade: no
forward-ports:
sourceports:
icmp-blocks:
rich rules:
```
PS. 如果你喜欢这篇文章,请在下面留下一个回复。谢谢。
---
via: <https://www.rosehosting.com/blog/set-up-and-configure-a-firewall-with-firewalld-on-centos-7/>
译者简介:
[Locez](http://locez.com) 是一个喜欢技术,喜欢折腾的 Linuxer,靠着对 Linux 的兴趣自学了很多 Linux 相关的知识,并且志在于为 Linux 在中国普及出一份力。
作者:[rosehosting.com](https://www.rosehosting.com/blog/set-up-and-configure-a-firewall-with-firewalld-on-centos-7/) 译者:[Locez](https://github.com/locez) 校对:[jasminepeng](https://github.com/jasminepeng)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 200 | OK | We’ll show you,
**how to Set Up FirewallD on CentOS 7**. FirewallD is a firewall management tool available by default on CentOS 7 servers. Basically, it is a wrapper around iptables and it comes with graphical configuration tool firewall-config and command line tool firewall-cmd. With the iptables service, every change requires flushing of the old rules and reading the new rules from the `/etc/sysconfig/iptables` file, while with firewalld only differences are applied. The **setup and configuration of FirewallD on CentOS 7** should take less than 10 minutes and is a fairly easy process.
Table of Contents
## 1. FirewallD zones
FirewallD uses services and zones instead of iptables rules and chains. By default the following zones are available:
**drop**– Drop all incoming network packets with no reply, only outgoing network connections are available.**block**– Reject all incoming network packets with an icmp-host-prohibited message, only outgoing network connections are available.**public**– Only selected incoming connections are accepted, for use in public areas**external**For external networks with masquerading enabled, only selected incoming connections are accepted.**dmz**– DMZ demilitarized zone, publicly-accessible with limited access to the internal network, only selected incoming connections are accepted.**work**– For computers in your home area, only selected incoming connections are accepted.**home**– For computers in your home area, only selected incoming connections are accepted.**internal**-For computers in your internal network, only selected incoming connections are accepted.**trusted**– All network connections are accepted.
To list all available zones run:
# firewall-cmd --get-zones work drop internal external trusted home dmz public block
To list the default zone:
# firewall-cmd --get-default-zone public
To change the default zone:
# firewall-cmd --set-default-zone=dmz # firewall-cmd --get-default-zone dmz
## 2. FirewallD services
FirewallD services are xml configuration files, with information of a service entry for firewalld. TO list all available services run:
# firewall-cmd --get-services amanda-client amanda-k5-client bacula bacula-client ceph ceph-mon dhcp dhcpv6 dhcpv6-client dns docker-registry dropbox-lansync freeipa-ldap freeipa-ldaps freeipa-replication ftp high-availability http https imap imaps ipp ipp-client ipsec iscsi-target kadmin kerberos kpasswd ldap ldaps libvirt libvirt-tls mdns mosh mountd ms-wbt mysql nfs ntp openvpn pmcd pmproxy pmwebapi pmwebapis pop3 pop3s postgresql privoxy proxy-dhcp ptp pulseaudio puppetmaster radius rpc-bind rsyncd samba samba-client sane smtp smtps snmp snmptrap squid ssh synergy syslog syslog-tls telnet tftp tftp-client tinc tor-socks transmission-client vdsm vnc-server wbem-https xmpp-bosh xmpp-client xmpp-local xmpp-server
xml configuration files are stored in the `/usr/lib/firewalld/services/`
and `/etc/firewalld/services/`
directories.
## 3. Configuring your firewall with FirewallD
As an example, here is how you can configure your [RoseHosting VPS](https://www.rosehosting.com/managed-vps-hosting.html) firewall with FirewallD if you were running a web server, SSH on port 7022 and mail server.
First we will set the default zone to dmz.
# firewall-cmd --set-default-zone=dmz # firewall-cmd --get-default-zone dmz
To add permanent service rules for HTTP and HTTPS to the dmz zone, run:
# firewall-cmd --zone=dmz --add-service=http --permanent # firewall-cmd --zone=dmz --add-service=https --permanent
Open port 25 (SMTP) and port 465 (SMTPS) :
firewall-cmd --zone=dmz --add-service=smtp --permanent firewall-cmd --zone=dmz --add-service=smtps --permanent
Open, IMAP, IMAPS, POP3 and POP3S ports:
firewall-cmd --zone=dmz --add-service=imap --permanent firewall-cmd --zone=dmz --add-service=imaps --permanent firewall-cmd --zone=dmz --add-service=pop3 --permanent firewall-cmd --zone=dmz --add-service=pop3s --permanent
## 4. Open port 7022
Since the SSH port is changed to 7022, we will remove the ssh service (port 22) and open port 7022
firewall-cmd --remove-service=ssh --permanent firewall-cmd --add-port=7022/tcp --permanent
## 5. Reload the Firewall
To implement the changes we need to reload the firewall with:
firewall-cmd --reload
## 6. List Firewall Rules
Finally, you can list the rules with:
# firewall-cmd --list-all dmz target: default icmp-block-inversion: no interfaces: sources: services: http https imap imaps pop3 pop3s smtp smtps ports: 7022/tcp protocols: masquerade: no forward-ports: sourceports: icmp-blocks: rich rules:
Of course, you don’t have to
**set up FirewallD on CentOS 7**, if you use one of our [CentOS VPS hosting](https://www.rosehosting.com/centos-hosting.html) services, in which case you can simply ask our expert Linux admins to setup this for you. They are available 24×7 and will take care of your request immediately.
**PS**. If you liked this post, on** installing FirewallD on CentOS 7**, please share it with your friends on the social networks using the sharing buttons or simply leave a reply below. Thanks. |
8,326 | 看漫画学 SELinux 强制策略 | https://opensource.com/business/13/11/selinux-policy-guide | 2017-03-22T08:24:00 | [
"安全",
"SELinux"
] | https://linux.cn/article-8326-1.html | 
今年是我们一起庆祝 SELinux 纪念日的第十个年头了(LCTT 译者注:本文发表于 2013 年)。真是太难以置信了!SELinux 最初在 Fedora Core 3 中被引入,随后加入了红帽企业版 Linux 4。从来没有使用过 SELinux 的家伙,你可要好好儿找个理由了……
SElinux 是一个标签型系统。每一个进程都有一个标签。操作系统中的每一个文件/目录<ruby> 客体 <rp> ( </rp> <rt> object </rt> <rp> ) </rp></ruby>也都有一个标签。甚至连网络端口、设备,乃至潜在的主机名都被分配了标签。我们把控制访问进程的标签的规则写入一个类似文件的客体标签中,这些规则我们称之为<ruby> 策略 <rp> ( </rp> <rt> policy </rt> <rp> ) </rp></ruby>。内核强制实施了这些规则。有时候这种“强制”被称为<ruby> 强制访问控制体系 <rp> ( </rp> <rt> Mandatory Access Control </rt> <rp> ) </rp></ruby>(MAC)。
一个客体的拥有者对客体的安全属性并没有自主权。标准 Linux 访问控制体系,拥有者/分组 + 权限标志如 rwx,常常被称作<ruby> 自主访问控制 <rp> ( </rp> <rt> Discretionary Access Control </rt> <rp> ) </rp></ruby>(DAC)。SELinux 没有文件 UID 或拥有权的概念。一切都被标签控制,这意味着在没有至高无上的 root 权限进程时,也可以设置 SELinux 系统。
**注意:** SELinux 不允许你摒弃 DAC 控制。SELinux 是一个并行的强制模型。一个应用必须同时支持 SELinux 和 DAC 来完成特定的行为。这可能会导致管理员迷惑为什么进程被拒绝访问。管理员被拒绝访问是因为在 DAC 中有些问题,而不是在 SELinux 标签。
### 类型强制
让我们更深入的研究下标签。SELinux 最主要的“模型”或“强制”叫做<ruby> 类型强制 <rp> ( </rp> <rt> type enforcement </rt> <rp> ) </rp></ruby>。基本上这意味着我们根据进程的类型来定义其标签,以及根据文件系统客体的类型来定义其标签。
**打个比方**
想象一下在一个系统里定义客体的类型为猫和狗。猫(CAT)和狗(DOG)都是<ruby> 进程类型 <rp> ( </rp> <rt> process type </rt> <rp> ) </rp></ruby>。

我们有一类希望能与之交互的客体,我们称之为食物。而我希望能够为食物增加类型:`cat_food` (猫的食物)和 `dog_food`(狗的食物)。

作为一个策略制定者,我可以说一只狗有权限去吃狗粮(`dog_chow`),而一只猫有权限去吃猫粮(`cat_chow`)。在 SELinux 中我可以将这条规则写入策略中。

`allow cat cat_chow:food eat;`
`允许 猫 猫粮:食物 吃;`
`allow dog dog_chow:food eat;`
`允许 狗 狗粮:食物 吃;`
有了这些规则,内核会允许猫进程去吃打上猫粮标签 `cat_chow` 的食物,允许狗去吃打上狗粮标签 `dog_chow` 的食物。

此外,在 SELinux 系统中,由于禁止是默认规则,这意味着,如果狗进程想要去吃猫粮 `cat_chow`,内核会阻止它。

同理,猫也不允许去接触狗粮。

**现实例子**
我们将 Apache 进程标为 `httpd_t`,将 Apache 上下文标为 `httpd_sys_content_t` 和 `httpdsys_content_rw_t`。假设我们把信用卡数据存储在 MySQL 数据库中,其标签为 `msyqld_data_t`。如果一个 Apache 进程被劫持,黑客可以获得 `httpd_t` 进程的控制权,从而能够去读取 `httpd_sys_content_t` 文件并向 `httpd_sys_content_rw_t` 文件执行写操作。但是黑客却不允许去读信用卡数据(`mysqld_data_t`),即使 Apache 进程是在 root 下运行。在这种情况下 SELinux 减轻了这次闯入的后果。
### 多类别安全强制
**打个比方**
上面我们定义了狗进程和猫进程,但是如果你有多个狗进程:Fido 和 Spot,而你想要阻止 Fido 去吃 Spot 的狗粮 `dog_chow` 怎么办呢?

一个解决方式是创建大量的新类型,如 `Fido_dog` 和 `Fido_dog_chow`。但是这很快会变得难以驾驭因为所有的狗都有差不多相同的权限。
为了解决这个问题我们发明了一种新的强制形式,叫做<ruby> 多类别安全 <rp> ( </rp> <rt> Multi Category Security </rt> <rp> ) </rp></ruby>(MCS)。在 MCS 中,我们在狗进程和狗粮的标签上增加了另外一部分标签。现在我们将狗进程标记为 `dog:random1(Fido)` 和 `dog:random2(Spot)`。

我们将狗粮标记为 `dog_chow:random1(Fido)` 和 `dog_chow:random2(Spot)`。

MCS 规则声明如果类型强制规则被遵守而且该 MCS 随机标签正确匹配,则访问是允许的,否则就会被拒绝。
Fido (`dog:random1`) 尝试去吃 `cat_chow:food` 被类型强制拒绝了。

Fido (`dog:random1`) 允许去吃 `dog_chow:random1`。

Fido (`dog:random1`) 去吃 spot(`dog_chow:random2`)的食物被拒绝。

**现实例子**
在计算机系统中我们经常有很多具有同样访问权限的进程,但是我们又希望它们各自独立。有时我们称之为<ruby> 多租户环境 <rp> ( </rp> <rt> multi-tenant environment </rt> <rp> ) </rp></ruby>。最好的例子就是虚拟机。如果我有一个运行很多虚拟机的服务器,而其中一个被劫持,我希望能够阻止它去攻击其它虚拟机和虚拟机镜像。但是在一个类型强制系统中 KVM 虚拟机被标记为 `svirt_t` 而镜像被标记为 `svirt_image_t`。 我们允许 `svirt_t` 可以读/写/删除标记为 `svirt_image_t` 的上下文。通过使用 libvirt 我们不仅实现了类型强制隔离,而且实现了 MCS 隔离。当 libvirt 将要启动一个虚拟机时,它会挑选出一个 MCS 随机标签如 `s0:c1,c2`,接着它会将 `svirt_image_t:s0:c1,c2` 标签分发给虚拟机需要去操作的所有上下文。最终,虚拟机以 `svirt_t:s0:c1,c2` 为标签启动。因此,SELinux 内核控制 `svirt_t:s0:c1,c2` 不允许写向 `svirt_image_t:s0:c3,c4`,即使虚拟机被一个黑客劫持并接管,即使它是运行在 root 下。
我们在 OpenShift 中使用[类似的隔离策略](http://people.fedoraproject.org/%7Edwalsh/SELinux/Presentations/openshift_selinux.ogv)。每一个 gear(user/app process)都有相同的 SELinux 类型(`openshift_t`)(LCTT 译注:gear 为 OpenShift 的计量单位)。策略定义的规则控制着 gear 类型的访问权限,而一个独一无二的 MCS 标签确保了一个 gear 不能影响其他 gear。
请观看下面的视频来看 OpenShift gear 切换到 root 会发生什么。
### 多级别安全强制
另外一种不经常使用的 SELinux 强制形式叫做<ruby> 多级别安全 <rp> ( </rp> <rt> Multi Level Security </rt> <rp> ) </rp></ruby>(MLS);它开发于上世纪 60 年代,并且主要使用在受信操作系统上如 Trusted Solaris。
其核心观点就是通过进程使用的数据等级来控制进程。一个 *secret* 进程不能读取 *top secret* 数据。
MLS 很像 MCS,除了它在强制策略中增加了支配的概念。MCS 标签必须完全匹配,但一个 MLS 标签可以支配另一个 MLS 标签并且获得访问。
**打个比方**
不讨论不同名字的狗,我们现在来看不同种类。我们现在有一只格雷伊猎犬和一只吉娃娃。

我们可能想要允许格雷伊猎犬去吃任何狗粮,但是吉娃娃如果尝试去吃格雷伊猎犬的狗粮可能会被呛到。
我们把格雷伊猎犬标记为 `dog:Greyhound`,把它的狗粮标记为 `dog_chow:Greyhound`,把吉娃娃标记为 `dog:Chihuahua`,把它的狗粮标记为 `dog_chow:Chihuahua`。

使用 MLS 策略,我们可以使 MLS 格雷伊猎犬标签支配吉娃娃标签。这意味着 `dog:Greyhound` 允许去吃 `dog_chow:Greyhound` 和 `dog_chow:Chihuahua`。

但是 `dog:Chihuahua` 不允许去吃 `dog_chow:Greyhound`。

当然,由于类型强制, `dog:Greyhound` 和 `dog:Chihuahua` 仍然不允许去吃 `cat_chow:Siamese`,即使 MLS 类型 GreyHound 支配 Siamese。

**现实例子**
有两个 Apache 服务器:一个以 `httpd_t:TopSecret` 运行,一个以 `httpd_t:Secret` 运行。如果 Apache 进程 `httpd_t:Secret` 被劫持,黑客可以读取 `httpd_sys_content_t:Secret` 但会被禁止读取 `httpd_sys_content_t:TopSecret`。
但是如果运行 `httpd_t:TopSecret` 的 Apache 进程被劫持,它可以读取 `httpd_sys_content_t:Secret` 数据和 `httpd_sys_content_t:TopSecret` 数据。
我们在军事系统上使用 MLS,一个用户可能被允许读取 *secret* 数据,但是另一个用户在同一个系统上可以读取 *top secret* 数据。
### 结论
SELinux 是一个功能强大的标签系统,控制着内核授予每个进程的访问权限。最主要的特性是类型强制,策略规则定义的进程访问权限基于进程被标记的类型和客体被标记的类型。也引入了另外两个控制手段,分离有着同样类型进程的叫做 MCS,而 MLS,则允许进程间存在支配等级。
*\*所有的漫画都来自 [Máirín Duffy](https://opensource.com/users/mairin)*
---
作者简介:
Daniel J Walsh - Daniel Walsh 已经在计算机安全领域工作了将近 30 年。Daniel 于 2001 年 8 月加入红帽。
---
via: <https://opensource.com/business/13/11/selinux-policy-guide>
作者:[Daniel J Walsh](https://opensource.com/users/rhatdan) 译者:[xiaow6](https://github.com/xiaow6) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 200 | OK | We are celebrating the SELinux 10th year anversary this year. Hard to believe it. SELinux was first introduced in Fedora Core 3 and later in Red Hat Enterprise Linux 4. For those who have never used SELinux, or would like an explanation...
SElinux is a labeling system. Every process has a label. Every file/directory object in the operating system has a label. Even network ports, devices, and potentially hostnames have labels assigned to them. We write rules to control the access of a process label to an a object label like a file. We call this *policy*. The kernel enforces the rules. Sometimes this enforcement is called Mandatory Access Control (MAC).
The owner of an object does not have discretion over the security attributes of a object. Standard Linux access control, owner/group + permission flags like rwx, is often called Discretionary Access Control (DAC). SELinux has no concept of UID or ownership of files. Everything is controlled by the labels. Meaning an SELinux system can be setup without an all powerful root process.
**Note:** *SELinux does not let you side step DAC Controls. SELinux is a parallel enforcement model. An application has to be allowed by BOTH SELinux and DAC to do certain activities. This can lead to confusion for administrators because the process gets Permission Denied. Administrators see Permission Denied means something is wrong with DAC, not SELinux labels.*
### Type enforcement
Lets look a little further into the labels. The SELinux primary model or enforcement is called *type enforcement*. Basically this means we define the label on a process based on its type, and the label on a file system object based on its type.
*Analogy*
Imagine a system where we define types on objects like cats and dogs. A cat and dog are process types.
**all cartoons by Máirín Duffy*
We have a class of objects that they want to interact with which we call food. And I want to add types to the food, *cat_food* and *dog_food*.
As a policy writer, I would say that a dog has permission to eat *dog_chow* food and a cat has permission to eat *cat_chow* food. In SELinux we would write this rule in policy.
allow cat cat_chow:food eat;
allow dog dog_chow:food eat;
With these rules the kernel would allow the cat process to eat food labeled *cat_chow *and the dog to eat food labeled *dog_chow*.
But in an SELinux system everything is denied by default. This means that if the dog process tried to eat the *cat_chow*, the kernel would prevent it.
Likewise cats would not be allowed to touch dog food.
*Real world*
We label Apache processes as *httpd_t* and we label Apache content as *httpd_sys_content_t *and *httpd_sys_content_rw_t*. Imagine we have credit card data stored in a mySQL database which is labeled *msyqld_data_t*. If an Apache process is hacked, the hacker could get control of the *httpd_t process* and would be allowed to read *httpd_sys_content_t* files and write to *httpd_sys_content_rw_t*. But the hacker would not be allowed to read the credit card data (*mysqld_data_t*) even if the process was running as root. In this case SELinux has mitigated the break in.
### MCS enforcement
*Analogy *
Above, we typed the dog process and cat process, but what happens if you have multiple dogs processes: Fido and Spot. You want to stop Fido from eating Spot's *dog_chow*.
One solution would be to create lots of new types, like *Fido_dog* and *Fido_dog_chow*. But, this will quickly become unruly because all dogs have pretty much the same permissions.
To handle this we developed a new form of enforcement, which we call Multi Category Security (MCS). In MCS, we add another section of the label which we can apply to the dog process and to the dog_chow food. Now we label the dog process as *dog:random1 *(Fido) and *dog:random2* (Spot).
We label the dog chow as *dog_chow:random1 (Fido)* and *dog_chow:random2* (Spot).
MCS rules say that if the type enforcement rules are OK and the random MCS labels match exactly, then the access is allowed, if not it is denied.
Fido (dog:random1) trying to eat *cat_chow:food* is denied by type enforcement.
Fido (dog:random1) is allowed to eat *dog_chow:random1.*
Fido (dog:random1) denied to eat spot's (*dog_chow:random2*) food.
*Real world*
In computer systems we often have lots of processes all with the same access, but we want them separated from each other. We sometimes call this a *multi-tenant environment*. The best example of this is virtual machines. If I have a server running lots of virtual machines, and one of them gets hacked, I want to prevent it from attacking the other virtual machines and virtual machine images. But in a type enforcement system the KVM virtual machine is labeled *svirt_t* and the image is labeled *svirt_image_t*. We have rules that say *svirt_t* can read/write/delete content labeled *svirt_image_t*. With libvirt we implemented not only type enforcement separation, but also MCS separation. When libvirt is about to launch a virtual machine it picks out a random MCS label like *s0:c1,c2*, it then assigns the *svirt_image_t:s0:c1,c2* label to all of the content that the virtual machine is going to need to manage. Finally, it launches the virtual machine as *svirt_t:s0:c1,c2*. Then, the SELinux kernel controls that *svirt_t:s0:c1,c2* can not write to *svirt_image_t:s0:c3,c4*, even if the virtual machine is controled by a hacker and takes it over. Even if it is running as root.
We use [similar separation](http://people.fedoraproject.org/~dwalsh/SELinux/Presentations/openshift_selinux.ogv) in OpenShift. Each gear (user/app process)runs with the same SELinux type (openshift_t). Policy defines the rules controlling the access of the gear type and a unique MCS label to make sure one gear can not interact with other gears.
Watch [this short video](http://people.fedoraproject.org/~dwalsh/SELinux/Presentations/openshift_selinux.ogv) on what would happen if an Openshift gear became root.
### MLS enforcement
Another form of SELinux enforcement, used much less frequently, is called Multi Level Security (MLS); it was developed back in the 60s and is used mainly in trusted operating systems like Trusted Solaris.
The main idea is to control processes based on the level of the data they will be using. A *secret *process can not read *top secret* data.
MLS is very similar to MCS, except it adds a concept of dominance to enforcement. Where MCS labels have to match exactly, one MLS label can dominate another MLS label and get access.
*Analogy*
Instead of talking about different dogs, we now look at different breeds. We might have a Greyhound and a Chihuahua.
We might want to allow the Greyhound to eat any dog food, but a Chihuahua could choke if it tried to eat Greyhound dog food.
We want to label the Greyhound as *dog:Greyhound* and his dog food as *dog_chow:Greyhound, *and label the Chihuahua as *dog:Chihuahua* and his food as *dog_chow:Chihuahua*.
With the MLS policy, we would have the MLS Greyhound label dominate the Chihuahua label. This means *dog:Greyhound* is allowed to eat *dog_chow:Greyhound *and *dog_chow:Chihuahua*.
But *dog:Chihuahua* is not allowed to eat *dog_chow:Greyhound*.
Of course, *dog:Greyhound* and *dog:Chihuahua* are still prevented from eating *cat_chow:Siamese* by type enforcement, even if the MLS type Greyhound dominates Siamese.
*Real world*
I could have two Apache servers: one running as *httpd_t:TopSecret* and another running as *httpd_t:Secret*. If the Apache process *httpd_t:Secret* were hacked, the hacker could read *httpd_sys_content_t:Secret* but would be prevented from reading *httpd_sys_content_t:TopSecret*.
However, if the Apache server running *httpd_t:TopSecret* was hacked, it could read *httpd_sys_content_t:Secret data* as well as *httpd_sys_content_t:TopSecret*.
We use the MLS in military environments where a user might only be allowed to see *secret *data, but another user on the same system could read *top secret* data.
### Conclusion
SELinux is a powerful labeling system, controlling access granted to individual processes by the kernel. The primary feature of this is type enforcement where rules define the access allowed to a process is allowed based on the labeled type of the process and the labeled type of the object. Two additional controls have been added to separate processes with the same type from each other called MCS, total separtion from each other, and MLS, allowing for process domination.
Illustrations by [Máirín Duffy](https://opensource.com/users/mairin). [Get the coloring book](http://blog.linuxgrrl.com/2014/04/16/the-selinux-coloring-book/)!
For more information on SELinux read my blog at [danwalsh.livejournal.com](http://danwalsh.livejournal.com/) and follow me on twitter [@rhatdan](https://twitter.com/rhatdan).
## 27 Comments |
8,328 | 在 Linux 中修改 MySQL 或 MariaDB 的 Root 密码 | http://www.tecmint.com/change-mysql-mariadb-root-password/ | 2017-03-22T14:55:07 | [
"MySQL",
"MariaDB",
"密码"
] | https://linux.cn/article-8328-1.html | 
如果你是第一次[安装 MySQL 或 MariaDB](/article-8320-1.html),你可以执行 `mysql_secure_installation` 脚本来实现基本的安全设置。
其中的一个设置是数据库的 root 密码 —— 该密码必须保密,并且只在必要的时候使用。如果你需要修改它(例如,当数据库管理员换了人 —— 或者被解雇了!)。
**建议阅读:**[在 Linux 中恢复 MySQL 或 MariaDB 的 Root 密码](/article-8301-1.html)
这篇文章迟早会派上用场的。我们讲说明怎样来在 Linux 中修改 MySQL 或 MariaDB 数据库服务器的 root 密码。
尽管我们会在本文中使用 MariaDB 服务器,但本文中的用法说明对 MySQL 也有效。
### 修改 MySQL 或 MariaDB 的 root 密码
你知道 root 密码,但是想要重置它,对于这样的情况,让我们首先确定 MariaDB 正在运行:
```
------------- CentOS/RHEL 7 and Fedora 22+ -------------
# systemctl is-active mariadb
------------- CentOS/RHEL 6 and Fedora -------------
# /etc/init.d/mysqld status
```

*检查 MysQL 状态*
如果上面的命令返回中没有 `active` 这个关键词,那么该服务就是停止状态,你需要在进行下一步之前先启动数据库服务:
```
------------- CentOS/RHEL 7 and Fedora 22+ -------------
# systemctl start mariadb
------------- CentOS/RHEL 6 and Fedora -------------
# /etc/init.d/mysqld start
```
接下来,我们将以 root 登录进数据库服务器:
```
# mysql -u root -p
```
为了兼容不同版本,我们将使用下面的声明来更新 mysql 数据库的用户表。注意,你需要将 `YourPasswordHere` 替换为你为 root 选择的新密码。
```
MariaDB [(none)]> USE mysql;
MariaDB [(none)]> UPDATE user SET password=PASSWORD('YourPasswordHere') WHERE User='root' AND Host = 'localhost';
MariaDB [(none)]> FLUSH PRIVILEGES;
```
要验证是否操作成功,请输入以下命令退出当前 MariaDB 会话。
```
MariaDB [(none)]> exit;
```
然后,敲回车。你现在应该可以使用新密码连接到服务器了。

*修改 MysQL/MariaDB Root 密码*
### 小结
在本文中,我们说明了如何修改 MariaDB / MySQL 的 root 密码 —— 或许你知道当前所讲的这个方法,也可能不知道。
像往常一样,如果你有任何问题或者反馈,请尽管使用下面的评论框来留下你宝贵的意见或建议,我们期待着您的留言。
---
作者简介:
Gabriel Cánepa是一位来自阿根廷圣路易斯的 Villa Mercedes 的 GNU/Linux 系统管理员和 web 开发者。他为世界范围内的主要的消费产品公司工作,也很钟情于在他日常工作的方方面面中使用 FOSS 工具来提高生产效率。
---
via: <http://www.tecmint.com/change-mysql-mariadb-root-password/>
作者:[Gabriel Cánepa](http://www.tecmint.com/author/gacanepa/) 译者:[GOLinux](https://github.com/GOLinux) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
8,330 | Kgif:一个从活动窗口创建 GIF 的简单脚本 | http://www.2daygeek.com/kgif-create-animated-gif-file-active-window-screen-recorder-capture-arch-linux-mint-fedora-ubuntu-debian-opensuse-centos/ | 2017-03-23T07:41:00 | [
"动画",
"Kgif",
"录屏"
] | https://linux.cn/article-8330-1.html | [Kgif](https://github.com/luminousmen/Kgif) 是一个简单的 shell 脚本,它可以从活动窗口创建一个 GIF 文件。我觉得这个程序专门是为捕获终端活动设计的,我经常用于这个。
它将窗口的活动捕获为一系列的 PNG 图片,然后组合在一起创建一个GIF 动画。脚本以 0.5 秒的间隔截取活动窗口。如果你觉得这不符合你的要求,你可以根据你的需要修改脚本。
最初它是为了捕获 tty 输出以及创建 github 项目的预览图创建的。

确保你在运行 Kgif 之前已经安装了 scrot 和 ImageMagick 软件包。
推荐阅读:[Peek - 在 Linux 中创建一个 GIF 动画录像机](http://www.2daygeek.com/kgif-create-animated-gif-file-active-window-screen-recorder-capture-arch-linux-mint-fedora-ubuntu-debian-opensuse-centos/www.2daygeek.com/peek-create-animated-gif-screen-recorder-capture-arch-linux-mint-fedora-ubuntu/)。
什么是 ImageMagick?ImageMagick 是一个命令行工具,用于图像转换和编辑。它支持所有类型的图片格式(超过 200 种),如 PNG、JPEG、JPEG-2000、GIF、TIFF、DPX、EXR、WebP、Postscript、PDF 和 SVG。
什么是 Scrot?Scrot 代表 SCReenshOT,它是一个开源的命令行工具,用于捕获桌面、终端或特定窗口的屏幕截图。
#### 安装依赖
Kgif 需要 scrot 以及 ImageMagick。
对于基于 Debian 的系统:
```
$ sudo apt-get install scrot imagemagick
```
对于基于 RHEL/CentOS 的系统:
```
$ sudo yum install scrot ImageMagick
```
对于 Fedora 系统:
```
$ sudo dnf install scrot ImageMagick
```
对于 openSUSE 系统:
```
$ sudo zypper install scrot ImageMagick
```
对于基于 Arch Linux 的系统:
```
$ sudo pacman -S scrot ImageMagick
```
#### 安装 Kgif 及使用
安装 Kgif 并不困难,因为不需要安装。只需从开发者的 github 页面克隆源文件,你就可以运行 `kgif.sh` 文件来捕获活动窗口了。默认情况下它的延迟为 1 秒,你可以用 `--delay` 选项来修改延迟。最后,按下 `Ctrl + c` 来停止捕获。
```
$ git clone https://github.com/luminousmen/Kgif
$ cd Kgif
$ ./kgif.sh
Setting delay to 1 sec
Capturing...
^C
Stop capturing
Converting to gif...
Cleaning...
Done!
```
检查系统中是否已存在依赖。
```
$ ./kgif.sh --check
OK: found scrot
OK: found imagemagick
```
设置在 N 秒延迟后开始捕获。
```
$ ./kgif.sh --delay=5
Setting delay to 5 sec
Capturing...
^C
Stop capturing
Converting to gif...
Cleaning...
Done!
```
它会将文件保存为 `terminal.gif`,并且每次在生成新文件时都会覆盖。因此,我建议你添加 `--filename` 选项将文件保存为不同的文件名。
```
$ ./kgif.sh --delay=5 --filename=2g-test.gif
Setting delay to 5 sec
Capturing...
^C
Stop capturing
Converting to gif...
Cleaning...
Done!
```
使用 `--noclean` 选项保留 png 截图。
```
$ ./kgif.sh --delay=5 --noclean
```
要了解更多的选项:
```
$ ./kgif.sh --help
usage: ./kgif.sh [--delay] [--filename ] [--gifdelay] [--noclean] [--check] [-h]
-h, --help Show this help, exit
--check Check if all dependencies are installed, exit
--delay= Set delay in seconds to specify how long script will wait until start capturing.
--gifdelay= Set delay in seconds to specify how fast images appears in gif.
--filename= Set file name for output gif.
--noclean Set if you don't want to delete source *.png screenshots.
```
---
via: <http://www.2daygeek.com/kgif-create-animated-gif-file-active-window-screen-recorder-capture-arch-linux-mint-fedora-ubuntu-debian-opensuse-centos/>
作者:[MAGESH MARUTHAMUTHU](http://www.2daygeek.com/author/magesh/) 译者:[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,331 | ELRepo - Enterprise Linux (RHEL、CentOS 及 SL)的社区仓库 | http://www.tecmint.com/enable-elrepo-in-rhel-centos-scientific-linux/ | 2017-03-23T08:33:00 | [
"ELRepo",
"仓库",
"RHEL",
"CentOS"
] | https://linux.cn/article-8331-1.html | 如果你正在使用 Enterprise Linux 发行版(Red Hat Enterprise Linux 或其衍生产品,如 CentOS 或 Scientific Linux),并且需要对特定硬件或新硬件支持,那么你找对地方了。
在本文中,我们将讨论如何启用 [ELRepo]( https://www.elrepo.org) 仓库,该软件源包含文件系统驱动以及网络摄像头驱动程序等等(支持显卡、网卡、声音设备甚至[新内核](/article-8310-1.html))

### 在 Enterprise Linux 中启用 ELRepo
虽然 ELRepo 是第三方仓库,但它有 Freenode(#elrepo)上的一个活跃社区以及用户邮件列表的良好支持。
如果你仍然对在软件源中添加一个独立的仓库表示担心,请注意 CentOS 已在它的 wiki([参见此处](https://wiki.centos.org/AdditionalResources/Repositories))将它列为是可靠的。如果你仍然有疑虑,请随时在评论中提问!
需要注意的是 ELRepo 不仅提供对 Enterprise Linux 7 提供支持,还支持以前的版本。考虑到 CentOS 5 在本月底(2017 年 3 月)结束支持(EOL),这可能看起来并不是一件很大的事,但请记住,CentOS 6 的 EOL 不会早于 2020 年 3 月之前。
不管你用的 EL 是何版本,在实际启用时需要先导入 GPG 密钥:
```
# rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
```
**在 EL5 中启用 ELRepo:**
```
# rpm -Uvh http://www.elrepo.org/elrepo-release-5-5.el5.elrepo.noarch.rpm
```
**在 EL6 中启用 ELRepo:**
```
# rpm -Uvh http://www.elrepo.org/elrepo-release-6-6.el6.elrepo.noarch.rpm
```
**在 EL7 中启用 ELRepo:**
```
# rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-2.el7.elrepo.noarch.rpm
```
这篇文章只会覆盖 EL7,在接下来的小节中分享几个例子。
### 理解 ELRepo 频道
为了更好地组织仓库中的软件,ELRepo 共分为 4 个独立频道:
* elrepo 是主频道,默认情况下启用。它不包含正式发行版中的包。
* elrepo-extras 包含可以替代发行版提供的软件包。默认情况下不启用。为了避免混淆,当需要从该仓库中安装或更新软件包时,可以通过以下方式临时启用该频道(将软件包替换为实际软件包名称):`# yum --enablerepo=elrepo-extras install package`
* elrepo-testing 提供将放入主频道中,但是仍在测试中的软件包。
* elrepo-kernel 提供长期及稳定的主线内核,它们已经特别为 EL 配置过。
默认情况下,elrepo-testing 和 elrepo-kernel 都被禁用,如果我们[需要从中安装或更新软件包](http://www.tecmint.com/auto-install-security-patches-updates-on-centos-rhel/),可以像 elrepo-extras 那样启用它们。
要列出每个频道中的可用软件包,请运行以下命令之一:
```
# yum --disablerepo="*" --enablerepo="elrepo" list available
# yum --disablerepo="*" --enablerepo="elrepo-extras" list available
# yum --disablerepo="*" --enablerepo="elrepo-testing" list available
# yum --disablerepo="*" --enablerepo="elrepo-kernel" list available
```
下面的图片说明了第一个例子:

*列出 ELRepo 可用的软件包*
##### 总结
本篇文章中,我们已经解释 ELRepo 是什么,以及你从如何将它们添加到你的软件源。
如果你对本文有任何问题或意见,请随时在评论栏中联系我们。我们期待你的回音!
---
作者简介:
Gabriel Cánepa - 一位来自阿根廷圣路易斯梅塞德斯镇 (Villa Mercedes, San Luis, Argentina) 的 GNU/Linux 系统管理员,Web 开发者。就职于一家世界领先级的消费品公司,乐于在每天的工作中能使用 FOSS 工具来提高生产力。
---
via: <http://www.tecmint.com/enable-elrepo-in-rhel-centos-scientific-linux/>
作者:[Gabriel Cánepa](http://www.tecmint.com/author/gacanepa/) 译者:[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,332 | 如何更改 Linux 的 I/O 调度器 | http://linuxroutes.com/change-io-scheduler-linux/ | 2017-03-24T08:15:00 | [
"I/O",
"调度器"
] | https://linux.cn/article-8332-1.html | Linux 的 I/O 调度器是一个以块式 I/O 访问存储卷的进程,有时也叫磁盘调度器。Linux I/O 调度器的工作机制是控制块设备的请求队列:确定队列中哪些 I/O 的优先级更高以及何时下发 I/O 到块设备,以此来减少磁盘寻道时间,从而提高系统的吞吐量。

目前 Linux 上有如下几种 I/O 调度算法:
1. noop - 通常用于内存存储的设备。
2. cfq - 完全公平调度器。进程平均使用IO带宽。
3. Deadline - 针对延迟的调度器,每一个 I/O,都有一个最晚执行时间。
4. Anticipatory - 启发式调度,类似 Deadline 算法,但是引入预测机制提高性能。
查看设备当前的 I/O 调度器:
```
# cat /sys/block/<Disk_Name>/queue/scheduler
```
假设磁盘名称是 `/dev/sdc`:
```
# cat /sys/block/sdc/queue/scheduler
noop anticipatory deadline [cfq]
```
### 如何改变硬盘设备 I/O 调度器
使用如下指令:
```
# echo {SCHEDULER-NAME} > /sys/block/<Disk_Name>/queue/scheduler
```
比如设置 noop 调度器:
```
# echo noop > /sys/block/sdc/queue/scheduler
```
以上设置重启后会失效,要想重启后配置仍生效,需要在内核启动参数中将 `elevator=noop` 写入 `/boot/grub/menu.lst`:
#### 1. 备份 menu.lst 文件
```
cp -p /boot/grub/menu.lst /boot/grub/menu.lst-backup
```
#### 2. 更新 /boot/grub/menu.lst
将 `elevator=noop` 添加到文件末尾,比如:
```
kernel /vmlinuz-2.6.16.60-0.91.1-smp root=/dev/sysvg/root splash=silent splash=off showopts elevator=noop
```
---
via: <http://linuxroutes.com/change-io-scheduler-linux/>
作者:[UX Techno](http://linuxroutes.com/change-io-scheduler-linux/) 译者:[honpey](https://github.com/honpey) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 302 | Found | null |
8,333 | CentOS 与 Ubuntu 有什么不同? | http://www.linuxandubuntu.com/home/centos-vs-ubuntu | 2017-03-23T09:01:20 | [
"Ubuntu",
"CentOS",
"发行版"
] | https://linux.cn/article-8333-1.html | 
Linux 中的可选项似乎“无穷无尽”,因为每个人都可以通过修改一个已经发行的版本或者新的[白手起家的版本](/article-5865-1.html) (LFS) 来构建 Linux。
关于 Linux 发行版的选择,我们关注的因素包括用户界面、文件系统、软件包分发、新的特性以及更新周期和可维护性等。
在这篇文章中,我们会讲到两个较为熟知的 Linux 发行版,实际上,更多的是介绍两者之间的不同,以及在哪些方面一方比另一方更好。
### 什么是 CentOS?
[CentOS](/article-3351-1.html)(Community Enterprise Operating System)是脱胎于 Red Hat Enterprise Linux ([RHEL](/article-3349-1.html)) 并与之兼容的由社区支持的克隆版 Linux 发行版,所以我们可以认为 CentOS 是 RHEL 的一个免费版。CentOS 的每一套发行版都有 10 年的维护期,每个新版本的释出周期为 2 年。在 2014 年 1 月 8 日,[CentOS 声明正式加入红帽](/article-2453-1.html),为新的 CentOS 董事会所管理,但仍然保持与 RHEL 的独立性。
扩展阅读:[如何安装 CentOS?](/article-8048-1.html)
#### CentOS 的历史和第一次释出
CentOS 第一次释出是在 2004 年,当时名叫 cAOs Linux;它是由社区维护和管理的一套基于 RPM 的发行版。
CentOS 结合了包括 Debian、Red Hat Linux/Fedora 和 FreeBSD 等在内的许多方面,使其能够令服务器和集群稳定工作 3 到 5 年的时间。它有一群开源软件开发者作为拥趸,是一个大型组织(CAOS 基金会)的一部分。
在 2006 年 6 月,David Parsley 宣布由他开发的 TAO Linux(另一个 RHEL 克隆版本)退出历史舞台并全力转入 CentOS 的开发工作。不过,他的领域转移并不会影响之前的 TAO 用户, 因为他们可以通过使用 `yum update` 来更新系统以迁移到 CentOS。
2014 年 1 月,红帽开始赞助 CentOS 项目,并移交了所有权和商标。
#### CentOS 设计
确切地说,CentOS 是付费 RHEL (Red Had Enterprise Edition) 版本的克隆。RHEL 提供源码以供之后 CentOS 修改和变更(移除商标和 logo)并完善为最终的成品。
### Ubuntu
Ubuntu 是一个基于 Debian 的 Linux 操作系统,应用于桌面、服务器、智能手机和平板电脑等多个领域。Ubuntu 是由一个英国的名为 Canonical Ltd. 的公司发行的,由南非的 Mark Shuttleworth 创立并赞助。
扩展阅读:[安装完 Ubuntu 16.10 必须做的 10 件事](http://www.linuxandubuntu.com/home/10-things-to-do-after-installing-ubuntu-16-04-xenial-xerus)
#### Ubuntu 的设计
Ubuntu 是一个在全世界的开发者共同努力下生成的开源发行版。在这些年的悉心经营下,Ubuntu 的界面变得越来越现代化和人性化,整个系统运行也更加流畅、安全,并且有成千上万的应用可供下载。
由于它是基于 [Debian](https://www.debian.org/) 的,因此它也支持 .deb 包、较新的包系统和更为安全的 [snap 包格式 (snappy)](https://en.wikipedia.org/wiki/Snappy_(package_manager))。
这种新的打包系统允许分发的应用自带满足所需的依赖性。
扩展阅读:[点评 Ubuntu 16.10 中的 Unity 8](http://www.linuxandubuntu.com/home/linuxandubuntu-review-of-unity-8-preview-in-ubuntu-1610)
### CentOS 与 Ubuntu 的区别
* Ubuntu 基于 Debian,CentOS 基于 RHEL;
* Ubuntu 使用 .deb 和 .snap 的软件包,CentOS 使用 .rpm 和 flatpak 软件包;
* Ubuntu 使用 apt 来更新,CentOS 使用 yum;
* CentOS 看起来会更稳定,因为它不会像 Ubuntu 那样对包做常规性更新,但这并不意味着 Ubuntu 就不比 CentOS 安全;
* Ubuntu 有更多的文档和免费的问题、信息支持;
* Ubuntu 服务器版本在云服务和容器部署上的支持更多。
### 结论
不论你的选择如何,**是 Ubuntu 还是 CentOS**,两者都是非常优秀稳定的发行版。如果你想要一个发布周期更短的版本,那么就选 Ubuntu;如果你想要一个不经常变更包的版本,那么就选 CentOS。在下方留下的评论,说出你更钟爱哪一个吧!
---
via: <http://www.linuxandubuntu.com/home/centos-vs-ubuntu>
作者:[linuxandubuntu.com](http://www.linuxandubuntu.com/home/centos-vs-ubuntu) 译者:[Meditator-hkx](http://www.kaixinhuang.com) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
8,334 | 在独立的 Root 和 Home 硬盘驱动器上安装 Ubuntu | https://www.maketecheasier.com/install-ubuntu-with-different-root-home-hard-drives/ | 2017-03-24T09:26:00 | [
"Ubuntu",
"安装"
] | https://linux.cn/article-8334-1.html | 
安装 Linux 系统时,可以有两种不同的方式。第一种方式是在一个超快的固态硬盘上进行安装,这样可以保证迅速开机和高速访问数据。第二种方式是在一个较慢但很强大的普通硬盘驱动器上安装,这样的硬盘转速快并且存储容量大,从而可以存储大量的应用程序和数据。
然而,一些 Linux 用户都知道,固态硬盘很棒,但是又很贵,而普通硬盘容量很大但速度较慢。如果我告诉你,可以同时利用两种硬盘来安装 Linux 系统,会怎么样?一个超快、现代化的固态硬盘驱动 Linux 内核,一个容量很大的普通硬盘来存储其他数据。
在这篇文章中,我将阐述如何通过分离 Root 目录和 Home 目录安装 Ubuntu 系统 — Root 目录存于 SSD(固态硬盘)中,Home 目录存于普通硬盘中。
### 没有多余的硬盘驱动器?尝试一下 SD 卡(内存卡)!

在多个驱动器上安装 Linux 系统是很不错的,并且每一个高级用户都应该学会这样做。然而,还有一种情况使得用户应该这样安装 Linux 系统 - 在低存储容量的笔记本电脑上安装系统。可能你有一台很便宜、没有花费太多的笔记本电脑,上面安装了 Linux 系统,电脑上没有多余的硬盘驱动,但有一个 SD 卡插槽。
这篇教程也是针对这种类型的电脑的。跟随这篇教程,可以为笔记本电脑买一个高速的 SD 卡来存储 Home 目录,而不是使用另一个硬盘驱动。本教程也适用于这种使用情况。
### 制作 USB 启动盘
首先去[这个网站](http://ubuntu.com/download)下载最新的 Ubuntu Linux 版本。然后下载 [Etcher](https://etcher.io/)- USB 镜像制作工具。这是一个使用起来很简单的工具,并且支持所有主流的操作系统。你还需要一个至少有 2GB 大小的 USB 驱动器。

安装好 Etcher 以后,直接打开。点击 <ruby> 选择镜像 <rt> Select Image </rt></ruby> 按钮来制作镜像。这将提示用户浏览、寻找 ISO 镜像,找到前面下载的 Ubuntu ISO 文件并选择。然后,插入 USB 驱动器,Etcher 应该会自动选择它。之后,点击 “Flash!” 按钮,Ubuntu 启动盘的制作过程就开始了。
为了能够启动 Ubuntu 系统,需要配置 BIOS。这是必需的,这样计算机才能启动新创建的 Ubuntu 启动盘。为了进入 BIOS,在插入 USB 的情况下重启电脑,然后按正确的键(Del、F2 或者任何和你的电脑相应的键)。找到从 USB 启动的选项,然后启用这个选项。
如果你的个人电脑不支持 USB 启动,那么把 Ubuntu 镜像刻入 DVD 中。
### 安装
当用启动盘第一次加载 Ubuntu 时,欢迎界面会出现两个选项。请选择 “安装 Ubuntu” 选项。在下一页中,Ubiquity 安装工具会请求用户选择一些选项。这些选项不是强制性的,可以忽略。然而,建议两个选项都勾选,因为这样可以节省安装系统以后的时间,特别是安装 MP3 解码器和更新系统。(LCTT 译注:当然如果你的网速不够快,还是不要勾选的好。)

勾选了<ruby> “准备安装 Ubuntu” <rt> Preparing to install Ubuntu </rt></ruby>页面中的两个选项以后,需要选择安装类型了。有许多种安装类型。然而,这个教程需要选择自定义安装类型。为了进入自定义安装页面,勾选<ruby> “其他” <rt> something else </rt></ruby>选项,然后点击“继续”。
现在将显示 Ubuntu 自定义安装分区工具。它将显示任何/所有能够安装 Ubuntu 系统的磁盘。如果两个硬盘均可用,那么它们都会显示。如果插有 SD 卡,那么它也会显示。
选择用于 Root 文件系统的硬盘驱动器。如果上面已经有分区表,编辑器会显示出来,请使用分区工具把它们全部删除。如果驱动没有格式化也没有分区,那么使用鼠标选择驱动器,然后点击<ruby> “新建分区表” <rt> new partition table </rt></ruby>。对所有驱动器执行这个操作,从而使它们都有分区表。(LCTT 译注:警告,如果驱动器上有你需要的数据,请先备份,否则重新分区后将永远丢失。)

现在所有分区都有了分区表(并已删除分区),可以开始进行配置了。在第一个驱动器下选择空闲空间,然后点击加号按钮来创建新分区。然后将会出现一个“创建分区窗口”。允许工具使用整个硬盘。然后转到<ruby> “挂载点” <rt> Mount Point </rt></ruby>下拉菜单。选择 `/` (Root)作为挂载点,之后点击 OK 按钮确认设置。
对第二个驱动器做相同的事,这次选择 `/home` 作为挂载点。两个驱动都设置好以后,选择要放入引导装载器的驱动器,然后点击 <ruby> “现在安装” <rt> install now </rt></ruby>,安装进程就开始了。

从这以后的安装进程是标准安装。创建用户名、选择时区等。
**注:** 你是以 UEFI 模式进行安装吗?如果是,那么需要给 boot 创建一个 512 MB 大小的 FAT32 分区。在创建其他任何分区前做这件事。确保选择 “/boot” 作为这个分区的挂载点。(有的发行版不允许使用 FAT32 的分区作为 /boot ,而是将 UEFI 分区放到 /boot/efi 下,因此将 /boot 单独放一个分区或置入 / 分区下比较稳妥。)
如果你需要一个交换分区,那么,在创建用于 `/` 的分区前,在第一个驱动器上进行创建。可以通过点击 ‘+’ 按钮,然后输入所需大小,选择下拉菜单中的<ruby> “交换区域” <rt> swap area </rt></ruby>来创建交换分区。
### 结论
Linux 最好的地方就是可以自己按需配置。有多少其他操作系统可以让你把文件系统分割在不同的硬盘驱动上?并不多,这是肯定的。我希望有了这个指南,你将意识到 Ubuntu 能够提供的真正力量。
安装 Ubuntu 系统时你会用多个驱动器吗?请在下面的评论中让我们知道。
---
via: <https://www.maketecheasier.com/install-ubuntu-with-different-root-home-hard-drives/>
作者:[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 | 
When building a Linux installation, there are two options. The first option is to find a super-fast solid state drive. This will ensure very fast boot times and overall speed when accessing data. The second option is to go for a slower but beefier spinning disk hard drive – one with fast RPMs and a large amount of storage. This ensures a massive amount of storage for applications and data.
However, as some Linux users are aware, solid state drives are nice, but expensive, and spinning disk drives have a lot of storage but tend to be slow. What if I told you that it was possible to have both? A super-fast, modern solid state drive powering the core of your Linux and a large spinning disk drive for all the data.
In this article we’ll go over how to install Ubuntu Linux with separate root and home hard drives – with root folder in the SSD and home folder in the spinning disk hard drive.
## No extra hard drives? Try SD cards!
Setting up a multi-drive Linux installation is great and something advanced users should get behind. However, there is another reason for users to do a setup like this – low-storage-capacity laptops. Maybe you have a cheap laptop that didn’t cost much, and Linux was installed on it. It’s not much, but the laptop has an SD card slot.
This guide is for those types of computers as well. Follow this guide, and instead of a second hard drive, maybe go out and buy a fast and speedy SD card for the laptop, and use that as a home folder. This tutorial will work for that use case too!
## Making the USB disk
Start out by heading over to [this website](https://ubuntu.com/download) to download the latest version of Ubuntu Linux. Then [download](https://etcher.io/) the Etcher USB imaging tool. This is a very easy-to-use tool and supports all major operating systems. You will also need a USB drive of at least 2 GB in size.
Install Etcher, then launch it. Make an image by clicking the “Select Image” button. This will prompt the user to browse for the ISO image. Find the Ubuntu ISO file downloaded earlier and select it. From here, insert the USB drive. Etcher should automatically select it. Then, click the “Flash!” button. The Ubuntu live disk creation process will begin.
To boot into Ubuntu, configure the BIOS. This is needed so that the computer will boot the newly-created Ubuntu live USB. To get into the BIOS, reboot with the USB in, and press the correct key (Del, F2, or whatever the key is on your particular machine). Find where the option is to enable booting from USB and enable it.
If your PC does not support booting from USB, burn the Ubuntu image to a DVD.
## Installation
When Ubuntu first loads, the welcome screen appears with two options. Select the “Install Ubuntu” button to proceed. On the next page the Ubiquity installation tool asks the user to select some options. These options aren’t mandatory and can be ignored. However, it is recommended that both boxes be checked, as they save time after the installation, specifically with the installation of MP3 codecs and updating the system.
After selecting both boxes in the “Preparing to install Ubuntu” page, it will be time to select the installation type. There are many. However, with this tutorial the option required is the custom one. To get to the custom installation page, select the “something else” box, then click continue.
This reveals Ubuntu’s custom installation partitioning tool. It will show any and all disks that can install Ubuntu. If two hard drives are available, they will appear. If an SD card is plugged in, it will appear.
Select the hard drive that you plan to use for the [root file system](https://www.maketecheasier.com/use-chroot-linux/). If there is already a partition table on it, the editor will show partitions. Delete all of them, using the tool. If the drive isn’t formatted and has no partitions, select the drive with the mouse, then click “new partition table.” Do this for all drives so that they both have partition tables.
Now that both drives have partition tables (and partitions deleted), the configuration can begin. Select the free space under drive one, then click the plus sign button to create a new partition. This will bring up the “Create partition window.” Allow the tool to use the entire hard drive, then go to the “Mount Point” drop-down menu. Select `/`
as the mount point, then the OK button to confirm the settings.
Do the same with the second drive. This time select `/home`
as the mount point. With both drives set up, select the correct drive the boot loader will go to, then click the “install now” button to start the installation process.
The installation process from here is the standard installation. Create a username, select the timezone, etc.
**Notes:** Are you installing in UEFI mode? A 512 MB, FAT32 partition will need to be created for boot. Do this before creating any other partitions. Be sure to select “/boot” as the mount point for this partition as well.
If you require Swap, create a partition on the first drive before making the partition used for `/`
. This can be done by clicking the “+” (plus) button, entering the desired size, and selecting “swap area” in the drop-down.
## Conclusion
The best thing about Linux is how configurable it is. How many other operating systems let you split up the file system onto separate hard drives? Not many, that’s for sure! I hope that with this guide you’ll realize the true power Ubuntu can offer!
Would you use multiple drives in your Ubuntu installation? Let us know below in the comments.
Our latest tutorials delivered straight to your inbox |
8,335 | Linux 命令行工具使用小贴士及技巧(一) | https://www.howtoforge.com/tutorial/linux-command-line-navigation-tips-and-tricks-part-1/ | 2017-03-25T08:16:00 | [
"命令行"
] | https://linux.cn/article-8335-1.html | ### 相关内容
如果你刚开始在 Linux 系统中使用命令行工具,那么你应该知道它是 Linux 操作系统中功能最强大和有用的工具之一。学习的难易程度跟你想研究的深度有关。但是,无论你的技术能力水平怎么样,这篇文章中的一些小贴士和技巧都会对你有所帮助。
在本系列的文章中,我们将会讨论一些非常有用的命令行工具使用小技巧,希望你的命令行使用体验更加愉快。
**但是在开始下一步之前,我得强调一点,这篇文章中的测试实例都是在 Ubuntu 14.04LTS 系统下测试通过的。我们使用命令行 Shell 版本是 bash 4.3.11 。**
****
### Linux 命令行工具使用的一些小技巧
我们假设你已经掌握了一些 Linux 命令行的基础知识,比如什么是 root 账号及 home 目录,什么是环境变量,如何查看目录内容等等。说明这些小技巧的同时也会介绍涉及到的概念,如果有的话。
#### 轻松切换目录 —— 快捷方式
假设你正在命令行下做一些操作,并且你需要经常在两个目录间来回切换。而且这两个目录在完全不同的两个路径下,比如说,分别在 `/home/` 和 `/usr/` 下。你会怎么做呢?
其中,最简单直接的方式就是输入这些目录的全路径。虽然这种方式本身没什么问题,但是却很浪费时间。另外一种方式就是打开两个终端窗口分别进行操作。但是这两种方式使用起来既不方便,也显得没啥技术含量。
你应该感到庆幸的是,还有另外一种更为简捷的方法来解决这个问题。你需要做的就是先手动切换到这两个目录(通过 `cd` 命令分别加上各自的路径),之后你就可以使用 `cd -` 命令在两个目录之间来回快速切换了。
例如:
我现在在下面的目录:
```
$ pwd
/home/himanshu/Downloads
```
然后,我切换到 `/usr/` 路径下的其它目录:
```
cd /usr/lib/
```
现在,我可以很方便的使用下面的命令来向前、向后快速地切换到两个目录:
```
cd -
```
下面是 `cd -` 命令的操作截图:

有一点我得跟大家强调下,如果你在操作的过程中使用 `cd` 加路径的方式切换到第三个目录下,那么 `cd -` 命令将应用于当前目录及第三个目录之间进行切换。
#### 轻松切换目录 —— 相关细节
对于那些有强烈好奇心的用户,他们想搞懂 `cd -` 的工作原理,解释如下:如大家所知道的那样, `cd` 命令需要加上一个路径作为它的参数。现在,当 `-` 符号作为参数传输给 `cd` 命令时,它将被 `OLDPWD` 环境变量的值所替代。

现在应该明白了吧, `OLDPWD` 环境变量存储的是前一个操作目录的路径。这个解释在 `cd` 命令的 man 帮助文档中有说明,但是,很遗憾的是你的系统中可能没有预先安装 `man` 命令帮助工具(至少在 Ubuntu 系统下没有安装)。
但是,安装这个 man 帮助工具也很简单,你只需要执行下的安装命令即可:
```
sudo apt-get install manpages-posix
```
然后做如下操作:
```
man cd
```
打开 man 帮助文档主页后,你将会看到下面很明确的解释:
```
—— 当 - 符号被用作 cd 命令的参数值时,将等同于下面的操作命令:
cd "$OLDPWD" && pwd
```
毫无疑问, `cd` 命令设置了 `OLDPWD` 环境变量值。因此每一次你切换操作目录时,上一个目录的路径就会被保存到这个变量里。这还让我们看到很重要的一点就是:任何时候启动一个新的 shell 实例(包括手动执行或是使用 shell 脚本),都不存在 ‘上一个工作目录’。

这也很符合逻辑,因为 `cd` 命令设置了 `OLDPWD` 环境变量值。因此,除非你至少执行了一次 `cd` 命令,否则 `OLDPWD` 环境变量不会包含任何值。
继续,尽管这有些难以理解, `cd -` 和 `cd $OLDWPD` 命令的执行结果并非在所有环境下都相同。比如说,你重新打开一个新的 shell 窗口时。

从上面的截图可以清楚的看出,当执行 `cd -` 命令提示未设置 `OLDPWD` 值时, `cd $OLDPWD` 命令没有报任何错;实际上,它把当前的工作目录改变到用户的 home 目录里。
那是因为 `OLDPWD` 变量目前还没有被设置, `$OLDPWD` 仅仅是一个空字符串。因此, `cd $OLDPWD` 命令跟 `cd` 命令的执行结果是一致的,默认情况下,会把用户当前的工作目录切换到用户的 home 目录里。
最后,我还遇到过这样的要求,需要让 `cd -` 命令执行的结果不显示出来。我的意思是,有这样的情况(比如说,在写 shell 脚本的时候),你想让 `cd -` 命令的执行结果不要把目录信息显示出来。那种情况下,你就可以使用下面的命令方式了:
```
cd - &>/dev/null
```
上面的命令把文件描述符 2(标准错误)和 1(标准输出)的结果重定向到 [`/dev/null`](https://en.wikipedia.org/wiki/Null_device) 目录。这意味着,这个命令产生的所有的错误不会显示出来。但是,你也可以使用通用的 [`$?` 方式](http://askubuntu.com/questions/29370/how-to-check-if-a-command-succeeded)来检查这个命令的执行是否异常。如果这个命令执行报错, `echo $?` 将会返回 `1`,否则返回 `0`。
或者说,如果你觉得 `cd -` 命令出错时输出信息没有关系,你也可以使用下面的命令来代替:
```
cd - > /dev/null
```
这个命令仅用于将文件描述符 1 (标准输出)重定向到 `/dev/null` 。
### 总结
遗憾的是,这篇文章仅包含了一个跟命令行相关的小技巧,但是,我们已经地对 `cd -` 命令的使用进行了深入地探讨。建议你在自己的 Linux 系统的命令行终端中测试本文中的实例。此外,也强烈建议你查看 man 帮助文档,然后对 cd 命令进行全面测试。
如果你对这篇文章有什么疑问,请在下面的评论区跟大家交流。同时,敬请关注下一篇文章,我们将以同样的方式探讨更多有用的命令行使用技巧。
---
via: <https://www.howtoforge.com/tutorial/linux-command-line-navigation-tips-and-tricks-part-1/>
作者:[Ansh](https://www.howtoforge.com/tutorial/linux-command-line-navigation-tips-and-tricks-part-1/) 译者:[rusking](https://github.com/rusking) 校对:[jasminepeng](https://github.com/jasminepeng)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 200 | OK | # Linux Command Line Navigation Tips and Tricks - Part 1
If you've just started using the command line in Linux, then it's worth knowing that it is one of the most powerful and useful features of the OS. The learning curve may or may not be steep depending on how deep you want to dive into the topic. However, there are some Linux command line tips/tricks that'll always be helpful regardless of your level of expertise.
In this article series, we'll be discussing several such tips/tricks, hoping that they'll make your command line experience even more pleasant.
## Linux command line tips/tricks
Please note that we've assumed that you know the basics of the command line in Linux, like what root and home directory are, what are environment variables, how to navigate directories, and more. Also, keep in mind that tips/tricks will be accompanied by the how and why of the concept involved (wherever applicable).
### Easily switch between two directories - the quick tip
Suppose you are doing some work on the command line that requires you to switch between two directories multiple times. And these two directories are located in completely different branches, say, under /home/ and under /usr/, respectively. What would you do?
One, and the most straightforward, option is to switch by typing the complete paths to these directories. While there's no problem with the approach per se, it's very time-consuming. Another option could be to open two separate terminals and carry on with your work. But again, neither this approach is convenient, nor it looks elegant.
You'll be glad to know that there exists an easy solution to this problem. All you have to do is to first switch between the two directories manually (by passing their respective paths to the **cd** command), and then subsequent switches can be accomplished using the **cd -** command.
For example:
I am in the following directory:
$ pwd
/home/himanshu/Downloads
And then I switched to some other directory in the /usr/ branch:
cd /usr/lib/
Now, I can easily switch back and forth using the following command:
cd -
Here's a screenshot showing the **cd -** command in action.
An important point worth mentioning here is that if you make a switch to a third directory in between all this, then the [cd command](https://www.howtoforge.com/linux-cd-command/) will work for the new directory and the directory from which the switch was made.
### Easily switch between two directories - related details
For the curious bunch, who want to know how the **cd -** command works, here's the explanation: As we all know, the cd command requires a path as its argument. Now, when a hyphen (-) is passed as an argument to the command, it's replaced by the value that OLDPWD environment variable contains at that moment.
As it would be clear by now, the OLDPWD environment variable stores the path of the previous working directory. This explanation is there is the man page of the cd command, but sadly, it's likely that you'll not find the man page pre-installed on your system (it's not there on Ubuntu at least).
However, installing it is not a big deal, all you have to do is to run the following command:
sudo apt-get install manpages-posix
And then do:
man cd
Once the man page opens, you'll see that it clearly says:
`- When a hyphen is used as the operand, this shall be equivalent`
to the command:
cd "$OLDPWD" && pwd
Needless to say, it's the cd command that sets the OLDPWD variable. So every time you change the directory, the previous working directory gets stored in this variable. This brings us to another important point here: whenever a new shell instance is launched (both manually or through a script), it does not have a 'previous working directory.'
That's logical because it's the cd command which sets this variable. So until you run the cd command at-least once, the OLDPWD environment variable will not contain any value.
Moving on, while it may seem counterintuitive, the **cd -** and **cd $OLDWPD** commands do not produce same results in all situations. Case in point, when a new shell has just been launched.
As clear from the screenshot above, while the **cd -** command complained about the OLDPWD variable not being set, the **cd $OLDPWD** command did not produce any error; in fact it changed the present working directory to the user's home directory.
That's because given that the OLDPWD variable is currently not set, $OLDPWD is nothing but an empty string. So, the **cd $OLDPWD** command is as good as just running **cd**, which - by default - takes you to your home directory.
Finally, I've also been through situations where-in it's desirable to suppress the output the **cd -** command produces. What I mean is, there can be cases (for example, while writing a shell script), where-in you'll want the **cd -** command to not produce the usual directory path in output. For those situations, you can use the command in the following way:
cd - &>/dev/null
The above command will redirect both file descriptor 2 (STDERR) and descriptor 1 (STDOUT) to [/dev/null](https://en.wikipedia.org/wiki/Null_device). This means that any error the command produces will also be suppressed. However, you'll still be able to check the success of failure of the command using the generic [$? technique](http://askubuntu.com/questions/29370/how-to-check-if-a-command-succeeded) - the command **echo $?** will produce '1' if there was some error, and '0' otherwise.
Alternatively, if you're ok with the **cd -** command producing an output in error cases, then you can use the following command instead:
cd - > /dev/null
This command will only redirect the file descriptor 1 (STDOUT) to `/dev/null`
.
## Conclusion
Sadly, we could only cover one command line-related tip here, but the good thing is that we managed to discuss a lot of in-depth stuff about the **cd -** command. You are advised to go through the tutorial thoroughly and test everything - that we've discussed here - on your Linux box's command line terminal. Also, do go through the command's man page, and try out all the features documented there.
In case you face any issues or have some doubts, do share them with us in the comments below. Meanwhile, wait for the [second part](https://www.howtoforge.com/tutorial/linux-command-line-tips-tricks-part-2/), where-in we'll discuss some more useful command line-related tips/tricks in the same manner as has been done here. |
8,336 | EPEL-5 走向终点 | https://fedoramagazine.org/the-end-of-the-line-for-epel-5/ | 2017-03-25T10:14:00 | [
"RHEL",
"EPEL",
"Fedora"
] | https://linux.cn/article-8336-1.html | 
在过去十年中,Fedora 项目一直都在为另外一个操作系统构建相同软件包。**然而,到 2017 年 3 月 31 日,它将会随着 Red Hat Enterprise Linux(RHEL)5 一起停止这项工作**。
### EPEL 的简短历史
RHEL 是 Fedora 发布版本的一个子集的下游重建版本,Red Hat 愿为之支持好多年。虽然那些软件包构成了完整的操作系统,但系统管理员一直都需要“更多”软件包。在 RHEL-5 之前,许多那些软件包会由不同的人打包并提供。随着 Fedora Extras 逐渐包含了更多软件包,并有几位打包者加入了 Fedora,随之出现了一个想法,结合力量并创建一个专门的子项目,重建特定于 RHEL 版本的 Fedora 软件包,然后从 Fedora 的中心化服务器上分发。
经过多次讨论,然而还是未能提出一个引人注目的名称之后,Fedora 创建了子项目 Extra Packages for Enterprise Linux(简称 EPEL)。在首次为 RHEL-4 重建软件包时,其主要目标是在 RHEL-5 发布时提供尽可能多的用于 RHEL-5 的软件包。打包者做了很多艰苦的工作,但大部分工作是在制定 EPEL 在未来十年的规则以及指导。[从所有人能够看到的邮件归档中](https://www.redhat.com/archives/epel-devel-list/2007-March/thread.html)我们可以看到 Fedora 贡献者的激烈讨论,它们担心将 Fedora 的发布重心转移到外部贡献者会与已经存在的软件包产生冲突。
最后,EPEL-5 在 2007 年 4 月的某个时候上线了,在接下来的十年中,它已经成长为一个拥有 5000 多个源码包的仓库,并且每天会有 20 万个左右独立 IP 地址检查软件包,并在 2013 年初达到 24 万的高峰。虽然为 EPEL 构建的每个包都是使用 RHEL 软件包完成的,但所有这些软件包可以用于 RHEL 的各种社区重建版本(CentOS、Scientific Linux、Amazon Linux)。这意味着随着这些生态系统的增长,给 EPEL 带来了更多的用户,并在随后的 RHEL 版本发布时帮助打包。然而,随着新版本以及重建版本的使用量越来越多,EPEL-5 的用户数量逐渐下降为每天大约 16 万个独立 IP 地址。此外,在此期间,开发人员支持的软件包数量已经下降,仓库大小已缩小到 2000 个源代码包。
收缩的部分原因是由于 2007 年的原始规定。当时,Red Hat Enterprise Linux 被认为只有 6 年活跃的生命周期。有人认为,在这样一个“有限”的周期中,软件包可能就像在 RHEL 中那样在 EPEL 中被“冻结”。这意味着无论何时有可能的修复需要向后移植,也不允许有主要的修改。因为没有人来打包,软件包将不断从 EPEL-5 中移除,因为打包者不再想尝试并向后移植。尽管各种规则被放宽以允许更大的更改,Fedora 使用的打包规则从 2007 年开始不断地改变和改进。这使得在较旧的操作系统上尝试重新打包一个较新的版本变得越来越难。
### 2017 年 3 月 31 日会发生什么
如上所述,3 月 31 日,红帽将终止 RHEL-5 的支持并不再为普通客户提供更新。这意味着 Fedora 和各种重建版本将开始各种归档流程。对于 EPEL 项目,这意味着我们将跟随 Fedora 发行版每年发布的步骤。
1. 在 3 月 27 日,任何新版本将不会被允许推送到 EPEL-5,以便仓库本质上被冻结。这允许镜像拥有一个清晰的文件树。
2. EPEL-5 中的所有包将从主镜像 `/pub/epel/5/` 以及 `/pub/epel/testing/5/` 移动到 `/pub/archives/epel/`。 这将会在 27 号开始,因此所有的归档镜像站点可以用它写入磁盘。
3. 因为 3 月 31 日是星期五,系统管理员并不喜欢周五惊喜,所以它不会有变化。4 月 3 日,镜像管理器将更新指向归档。
4. 4 月 6 日,`/pub/epel/5/` 树将被删除,镜像也将相应更新。
对于使用 cron 执行 yum 更新的系统管理员而言,这应该只是一个小麻烦。系统能继续更新甚至安装归档中的任何软件包。那些直接使用脚本从镜像下载的系统管理员会有点麻烦,需要将脚本更改到 `/pub/archive/epel/5/` 这个新的位置。
虽然令人讨厌,但是对于仍使用旧版 Linux 的许多系统管理员也许算是好事吧。由于软件包不断地从 EPEL-5 中删除,各种支持邮件列表以及 irc 频道都有系统管理员惊奇他们需要的哪些软件包消失到哪里了。归档完成后,这将不会是一个问题,因为不会更多的包会被删除了 :)。
对于受此问题影响的系统管理员,较旧的 EPEL 软件包仍然可用,但速度较慢。所有 EPEL 软件包都是在 Fedora Koji 系统中构建的,所以你可以使用 [Koji 搜索](https://koji.fedoraproject.org/koji/search)到较旧版本的软件包。
---
via: <https://fedoramagazine.org/the-end-of-the-line-for-epel-5/>
作者:[smooge](http://smooge.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 the last 10 years, the Fedora Project has been building packages for the same release of another operating system. **However on March 31st, 2017, that will come to an end** when Red Hat Enterprise Linux (RHEL) version 5 moves out of production.
### A Short History of EPEL
RHEL is a downstream rebuild of a subset of Fedora releases that Red Hat feels it can adequetely support over a multi-year lifetime. While these packages make for a full operating system, there have always been a need by system administrators for ‘more’ packages. Before RHEL-5, many of these packages would be built and supplied by various rebuilders. With Fedora Extras growing to include many of the packages, and several of the rebuilders having joined Fedora, there was an idea of combining forces and creating a dedicated sub-project who would rebuild Fedora packages with specific RHEL releases and then distribute them from Fedora’s centralized servers.
After much debate and a failure to come up with a catchy name, the Extra Packages for Enterprise Linux (or EPEL) sub-project of Fedora was created. While at first rebuilding packages for RHEL-4, the main goal was to have as many packages available for RHEL-5 when it arrived. It took a lot of hard work getting the plague builders in place, but most of the work was in crafting the rules and guidelines that EPEL would use for the next 10 years. [As anyone can see from the old mail archives](https://www.redhat.com/archives/epel-devel-list/2007-March/thread.html), the debates were fierce from both various Fedora contributors feeling this took away focus from moving Fedora releases forward to outside contributors worried about conflicts with existing installed packages.
In the end, EPEL-5 went live sometime in April of 2007 and over the next 10 years grew to a repository of over 5000 source packages and 200,000 unique ip addresses checking in per day at its peak of 240,000 in early 2013. While every package built for EPEL is done with the RHEL packages, all of these packages have been useful for the various community rebuilds (CentOS, Scientific Linux, Amazon Linux) of RHEL. This meant that growth in those eco-systems brought more users into using EPEL and helping on packaging as later RHEL releases came out. However as these newer releases and rebuilds grew in usage, the number of EPEL-5 users has gradually fallen to around 160,000 unique ip addresses per day. Also over that time, the number of packages supported by developers has fallen and the repository has shrunk in size to 2000 source packages.<>
Part of the shrinkage was due to the original rules put in place back in 2007. At that time, Red Hat Enterprise Linux releases were only thought to have an active life time of 6 years before being end of lifed. It was thought that for such a ‘limited’ lifetime, packages could be ‘frozen’ in EPEL like they were in the RHEL release. This meant that whenever possible fixes should be backported and major changes would not be allowed. Time and packaging stands still for no human, and packages would be continually pruned from EPEL-5 as packagers no longer wanted to try and backport fixes. While various rules were loosened to allow for larger changes in packages, the packaging rules that Fedora used have continually moved and improved from 2007. This has made trying to rebuild a package from newer releases harder and harder with the older operating systems.
### What Happens on March 31st 2017
As stated before, on March 31st Red Hat will end of life and no longer put updates out for RHEL-5 for regular customers. This means that
Fedora and the various rebuild distributors will start various archive processes. For the EPEL project this means that we will follow the steps that happen every year with Fedora releases.
- On
**March 27th**, no new builds will be allowed to be pushed for EPEL-5 so that the repository is essentially frozen. This will allow mirrors to have a clear tree of all files. - All packages in EPEL-5 will be hardlinked on the master mirror from
/pub/epel/5/
and
/pub/epel/testing/5/to
/pub/archives/epel/.
**This will start happening on the 27th**so all mirrors of archives can populate their disks. - Because March 31st happens on a Friday, and system administrators do not like Friday surprises, there will be no change then. On
**April 3rd**, mirrormanager will be updated to point to the archives. - On
**April 6th**, the /pub/epel/5/ trees will be removed and mirrors will update accordingly.
For a system administrator who has cron jobs which do yum updates, there should be minimal hassle. The systems will continue to update and even install any packages which were in the archives at that time. There will be breakage for system administrators who have scripts which directly download files from mirrors. Those scripts will need to change to the new canonical location of /pub/archive/epel/5/.
While irksome, this is a blessing in disguise for many system administrators who will still be using an older Linux. Because packages have been regularly removed from EPEL-5, the various support mailing lists and irc channels have regular requests from system administrators wondering where some package they needed has gone. After the archive is done, this won’t be a problem because no more packages will be removed :).
For system administrators who have been hit by this problem, the older EPEL packages are still available though in a much slower method. All EPEL packages are built in the Fedora Koji system, and so older builds of packages can be found using [Koji search.](https://koji.fedoraproject.org/koji/search)
## Aurelie Deromedis
Nice article, I didn’t know the full story behind EPEL. Thank you, interesting reading.
Aurelie
## Volunteer
good foresight on avoiding April 1st. |
8,337 | 如何从 Vim 中访问 shell 或者运行外部命令 | https://www.howtoforge.com/tutorial/how-to-access-shell-or-run-external-commands-from-within-vim/ | 2017-03-25T11:09:43 | [
"vim"
] | https://linux.cn/article-8337-1.html | Vim——正如你可能已经了解的那样——是一个包含很多特性的强大的编辑器。我们已经写了好多关于 Vim 的教程,覆盖了 [基本用法](https://www.howtoforge.com/vim-basics)、 [插件](https://www.howtoforge.com/tutorial/vim-editor-plugins-for-software-developers-3/), 还有一些 [其他的](https://www.howtoforge.com/tutorial/vim-modeline-settings/) [有用的](/article-8224-1.html) 特性。鉴于 Vim 提供了多如海洋的特性,我们总能找到一些有用的东西来和我们的读者分享。

在这篇教程中,我们将会重点关注你如何在编辑窗口执行外部的命令,并且访问命令行 shell。
但是在我们开始之前,很有必要提醒一下,在这篇教程中提及到的所有例子、命令行和说明,我们已经在 Ubuntu 14.04 上测试过,我们使用的的 Vim 版本是 7.4 。
### 在 Vim 中执行外部命令
有的时候,你可能需要在 Vim 编辑窗口中执行外部的命令。例如,想象一下这种场景:你已经在 Vim 中打开了一个文件,并做了一些修改,然后等你尝试保存这些修改的时候,Vim 抛出一个错误说你没有足够的权限。

现在,退出当前的 vim 会话,重新使用足够的权限打开文件将意味着你会丢失所做的所有修改,所以,你可能赞同,在大多数情况不是只有一个选择。像这样的情况,在编辑器内部运行外部命令的能力将会派上用场。
稍后我们再回来上面的用例,但是现在,让我们了解下如何在 vim 中运行基本的命令。
假设你在编辑一个文件,希望知道这个文件包含的行数、单词数和字符数。为了达到这个目的,在 vim 的命令行模式下,只需要输入冒号 `:`,接下来一个感叹号 `!`,最后是要执行的命令(这个例子中使用的是 `wc`)和紧接着的文件名(使用 `%` 表示当前文件)。
```
:! wc %
```
这是一个例子:
填入的上面提及的命令行准备执行:

下面是终端上的输出:

在你看到输出之后,输入回车键,你将会退回到你的 vim 会话中。
你正在编写代码或者脚本,并且希望尽快知道这段代码或者脚本是否包含编译时错误或者语法错误,这个时候,这种特性真的很方便。
继续,如果需求是添加输出到文件中,使用 `:read !` 命令。接下来是一个例子:
```
:read ! wc %
```
`read` 命令会把外部命令的输出作为新的一行插入到编辑的文件中的当前行的下面一行。如果你愿意,你也可以指定一个特定的行号——输出将会添加到特定行之后。
例如,下面的命令将会在文件的第二行之后添加 `wc` 的输出。
```
:2read ! wc %
```
**注意**: 使用 `$` 在最后一行插入, `0` 在第一行前面插入。
现在,回到最开始我们讨论的一个用例,下面的命令将会帮助你保存文件而不需要先关闭文件(这将意味着没有保存的内容不会丢失)然后使用 [sudo](/tag-sudo.html) 命令重新打开。
```
:w ! sudo tee %
```

### 在 Vim 中访问 shell
除了可以执行单独的命令,你也可以在 vim 中放入自己新创建的 shell。为了达到这种目的,在编辑器中你必须要做的是运行以下的命令:
```
:shell
```
或者:
```
:sh
```
当你执行完了你的 shell 任务,输入 `exit` —— 这将带你回到原来离开的 Vim 会话中。
### 要谨记的漏洞
虽然在真实世界中,能够访问的 shell 绝对符合它们的用户权限,但是它也可以被用于提权技术。正如我们在早期的一篇文章(在 sudoedit 上)解释的那样,即使你提供给一个用户 `sudo` 的权限只是通过 Vim 编辑一个文件,他们仍可以使用这项技术从编辑器中运行一个新的 shell,而且他们可以做 `root` 用户或者管理员用户可以做的所有内容。
### 总结
能够在 Vim 中运行外部命令在好多场景中(有些场景我们已经在这篇文章中提及了)都是一个很有用的特性。这个功能的学习曲线并不麻烦,所以初学者和有经验的用户都可以好好使用它。
你现在使用这个特性有一段时间了吗?你是否有一些东西想分享呢?请在下面的评论中留下你的想法。
---
via: <https://www.howtoforge.com/tutorial/how-to-access-shell-or-run-external-commands-from-within-vim/>
作者:[Himanshu Arora](https://www.howtoforge.com/tutorial/how-to-access-shell-or-run-external-commands-from-within-vim/) 译者:[yangmingming](https://github.com/yangmingming) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 200 | OK | # How to access shell or run external commands from within Vim
Vim, as you might already know, is a feature-packed and powerful editor. Here at HowtoForge, we've written several tutorials on Vim, covering its [basic usage](https://www.howtoforge.com/vim-basics), [plugins](https://www.howtoforge.com/tutorial/vim-editor-plugins-for-software-developers-3/), as well as some [other](https://www.howtoforge.com/tutorial/vim-modeline-settings/) [useful](https://www.howtoforge.com/tutorial/vim-editor-modes-explained/) features. But given the sea of features Vim offers, we always find something useful to share with our readership.
In this tutorial, we will focus on how you can execute external commands as well as access the command line shell from within the editor window.
## Execute external commands in Vim
Sometimes you might want to execute external commands from within the Vim editor window. For example, consider a situation where-in you've opened a file in Vim, made some changes, and then while trying to save those changes, Vim throws an error saying you don't have sufficient permissions.
Now, exiting the current vim session and again opening the file with sufficient privileges will mean loss of all the changes you've done, so that'd, you'll agree, not be an option in most cases. It's situations like these where the ability to run external commands from within the editor comes in handy.
We'll come back to the above use case later(**), but for now, let's understand how you can run basic commands from within vim.
Suppose while editing a file, you want to know the number of lines, words, and characters the file contains. To do this, in the command mode of Vim, just input colon (:) followed by a bang (!) and finally the command ('wc' in this case) followed by the file name (use % for current file).
:! wc %
Here's an example:
File with the aforementioned command ready to be executed:
and here's the output on the terminal:
After you are done seeing the output, press the Enter key and you'll be taken back to your Vim session.
This feature can come in really handy in situations where, say, you are writing a code or script, and want to quickly know whether or not the code/script contains any compile-time or syntax errors.
Moving on, in case the requirement is to add the output to the file, use the ':read !' command. Here's an example:
:read ! wc %
The 'read' command inserts the output of the external command on a new line below the current line in the file being edited. If you want, you can also specify a particular line number - the output will be added after that particular line.
For example, the following command will add the output of 'wc' after the second line the file.
:2read ! wc %
**Note**: *Use '$' to insert after the last line and '0' to insert before the first line.*
Now, coming back to the use case we discussed in the beginning (**), here's the command that'll help you save the file without needing to close it first (which means no loss of unsaved changes) and then open it with, say, [sudo](https://www.howtoforge.com/tutorial/sudo-beginners-guide/).
`:w ! sudo tee %`
## Access Shell in Vim
In addition to executing individual commands, you can also have yourself dropped in a newly-launched shell from within Vim. For this, all you have to do is to run the following command from the editor:
:shell
or
:sh
and type 'exit' when you are done with the shell work - this will bring you back into the Vim session from where you left initially.
## The loophole to keep in mind
While the ability to access a shell definitely has its own uses in the real world, it can also be used as a privilege escalation technique. As we have explained in one of our earlier tutorials (on sudoedit), even if you provide a user sudo access to only edit one file through Vim, they may launch a new shell from within the editor using this technique, and will then be able to do anything as 'root' or superuser.
# Conclusion
The ability to run external commands from within Vim is an important feature that can come in handy in many situations (some of which we have mentioned in this tutorial). The learning curve for this feature isn't steep, so both beginners, as well as experienced users, can take advantage of it.
Have you been using this feature for quite some time now? Do you have something to share? Please leave your thoughts in the comments below. Maybe you are interested in the [Linux tee command](https://www.howtoforge.com/linux-tee-command/) too. |
8,338 | 让你的 Linux 远离黑客(二):另外三个建议 | https://www.linux.com/news/webinar/2017/how-keep-hackers-out-your-linux-machine-part-2-three-more-easy-security-tips | 2017-03-26T18:32:54 | [
"安全",
"黑客"
] | https://linux.cn/article-8338-1.html | 
在这个系列中, 我们会讨论一些阻止黑客入侵你的系统的重要信息。观看这个免费的网络点播研讨会获取更多的信息。
在这个系列的[第一部分](/article-8189-1.html)中,我分享过两种简单的方法来阻止黑客黑掉你的 Linux 主机。这里是另外三条来自于我最近在 Linux 基金会的网络研讨会上的建议,在这次研讨会中,我分享了更多的黑客用来入侵你的主机的策略、工具和方法。完整的[网络点播研讨会](http://portal.on24.com/view/channel/index.html?showId=1101876&showCode=linux&partnerref=linco)视频可以在网上免费观看。
### 简单的 Linux 安全提示 #3
**Sudo。**
Sudo 非常、非常的重要。我认为这只是很基本的东西,但就是这些基本的东西会让我的黑客生涯会变得更困难一些。如果你没有配置 sudo,还请配置好它。
还有,你主机上所有的用户必须使用他们自己的密码。不要都免密码使用 sudo 执行所有命令。当我有一个可以无需密码而可以 sudo 任何命令的用户,只会让我的黑客活动变得更容易。如果我可以无需验证就可以 sudo ,同时当我获得你的没有密码的 SSH 密钥后,我就能十分容易的开始任何黑客活动。这样,我就拥有了你机器的 root 权限。
保持较低的超时时间。我们喜欢劫持用户的会话,如果你的某个用户能够使用 sudo,并且设置的超时时间是 3 小时,当我劫持了你的会话,那么你就再次给了我一个自由的通道,哪怕你需要一个密码。
我推荐的超时时间大约为 10 分钟,甚至是 5 分钟。用户们将需要反复地输入他们的密码,但是,如果你设置了较低的超时时间,你将减少你的受攻击面。
还要限制可以访问的命令,并禁止通过 sudo 来访问 shell。大多数 Linux 发行版目前默认允许你使用 sudo bash 来获取一个 root 身份的 shell,当你需要做大量的系统管理的任务时,这种机制是非常好的。然而,应该对大多数用户实际需要运行的命令有一个限制。你对他们限制越多,你主机的受攻击面就越小。如果你允许我 shell 访问,我将能够做任何类型的事情。
### 简单的 Linux 安全提示 #4
**限制正在运行的服务。**
防火墙很好,你的边界防火墙非常的强大。当流量流经你的外部网络时,有几家防火墙产品可以帮你很好的保护好自己。但是防火墙内的人呢?
你正在使用基于主机的防火墙或者基于主机的入侵检测系统吗?如果是,请正确配置好它。怎样可以知道你的正在受到保护的东西是否出了问题呢?
答案是限制当前正在运行的服务。不要在不需要提供 MySQL 服务的机器上运行它。如果你有一个默认会安装完整的 LAMP 套件的 Linux 发行版,而你不会在它上面运行任何东西,那么卸载它。禁止那些服务,不要开启它们。
同时确保用户不要使用默认的身份凭证,确保那些内容已被安全地配置。如何你正在运行 Tomcat,你不应该可以上传你自己的小程序(applets)。确保它们不会以 root 的身份运行。如果我能够运行一个小程序,我不会想着以管理员的身份来运行它,我能访问就行。你对人们能够做的事情限制越多,你的机器就将越安全。
### 简单的 Linux 安全提示 #5
**小心你的日志记录。**
看看它们,认真地,小心你的日志记录。六个月前,我们遇到一个问题。我们的一个顾客从来不去看日志记录,尽管他们已经拥有了很久、很久的日志记录。假如他们曾经看过日志记录,他们就会发现他们的机器早就已经被入侵了,并且他们的整个网络都是对外开放的。我在家里处理的这个问题。每天早上起来,我都有一个习惯,我会检查我的 email,我会浏览我的日志记录。这仅会花费我 15 分钟,但是它却能告诉我很多关于什么正在发生的信息。
就在这个早上,机房里的三台电脑死机了,我不得不去重启它们。我不知道为什么会出现这样的情况,但是我可以从日志记录里面查出什么出了问题。它们是实验室的机器,我并不在意它们,但是有人会在意。
通过 Syslog、Splunk 或者任何其他日志整合工具将你的日志进行集中是极佳的选择。这比将日志保存在本地要好。我最喜欢做是事情就是修改你的日志记录让你不知道我曾经入侵过你的电脑。如果我能这么做,你将不会有任何线索。对我来说,修改集中的日志记录比修改本地的日志更难。
它们就像你的很重要的人,送给它们鲜花——磁盘空间。确保你有足够的磁盘空间用来记录日志。由于磁盘满而变成只读的文件系统并不是一件愉快的事情。
还需要知道什么是不正常的。这是一件非常困难的事情,但是从长远来看,这将使你日后受益匪浅。你应该知道什么正在进行和什么时候出现了一些异常。确保你知道那。
在[第三篇也是最后的一篇文章](https://www.linux.com/news/webinar/2017/how-keep-hackers-out-your-linux-machine-part-3-your-questions-answered)里,我将就这次研讨会中问到的一些比较好的安全问题进行回答。[现在开始看这个完整的免费的网络点播研讨会](http://bit.ly/2j89ISJ)吧。
Mike Guthrie 就职于能源部,主要做红队交战和渗透测试。
---
via: <https://www.linux.com/news/webinar/2017/how-keep-hackers-out-your-linux-machine-part-2-three-more-easy-security-tips>
作者:[MIKE GUTHRIE](https://www.linux.com/users/anch) 译者:[zhousiyu325](https://github.com/zhousiyu325) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
8,339 | FTPS(基于 SSL 的FTP)与 SFTP(SSH 文件传输协议)对比 | http://www.techmixer.com/ftps-sftp/ | 2017-03-26T18:48:00 | [
"SSH",
"SFTP",
"FTPS",
"FTP"
] | https://linux.cn/article-8339-1.html | 
<ruby> SSH 文件传输协议 <rt> SSH File transfer protocol </rt></ruby>(SFTP)也称为<ruby> 通过安全套接层的文件传输协议 <rt> File Transfer protocol via Secure Socket Layer </rt></ruby>, 以及 FTPS 都是最常见的安全 FTP 通信技术,用于通过 TCP 协议将计算机文件从一个主机传输到另一个主机。SFTP 和 FTPS 都提供高级别文件传输安全保护,通过强大的算法(如 AES 和 Triple DES)来加密传输的数据。
但是 SFTP 和 FTPS 之间最显着的区别是如何验证和管理连接。
### FTPS
FTPS 是使用安全套接层(SSL)证书的 FTP 安全技术。整个安全 FTP 连接使用用户 ID、密码和 SSL 证书进行身份验证。一旦建立 FTPS 连接,[FTP 客户端软件](http://www.techmixer.com/free-ftp-file-transfer-protocol-softwares/)将检查目标 [FTP 服务器](http://www.techmixer.com/free-ftp-server-best-windows-ftp-server-download/)证书是否可信的。
如果证书由已知的证书颁发机构(CA)签发,或者证书由您的合作伙伴自己签发,并且您的信任密钥存储区中有其公开证书的副本,则 SSL 证书将被视为受信任的证书。FTPS 所有的用户名和密码信息将通过安全的 FTP 连接加密。
以下是 FTPS 的优点和缺点:
优点:
* 通信可以被人们读取和理解
* 提供服务器到服务器文件传输的服务
* SSL/TLS 具有良好的身份验证机制(X.509 证书功能)
* FTP 和 SSL 支持内置于许多互联网通信框架中
缺点:
* 没有统一的目录列表格式
* 需要辅助数据通道(DATA),这使得难以通过防火墙使用
* 没有定义文件名字符集(编码)的标准
* 并非所有 FTP 服务器都支持 SSL/TLS
* 没有获取和更改文件或目录属性的标准方式
### SFTP
SFTP 或 SSH 文件传输协议是另一种安全的安全文件传输协议,设计为 SSH 扩展以提供文件传输功能,因此它通常仅使用 SSH 端口用于数据传输和控制。当 [FTP 客户端](http://www.techmixer.com/best-free-mac-ftp-client-connect-ftp-server/)软件连接到 SFTP 服务器时,它会将公钥传输到服务器进行认证。如果密钥匹配,提供任何用户/密码,身份验证就会成功。
以下是 SFTP 优点和缺点:
优点:
* 只有一个连接(不需要 DATA 连接)。
* FTP 连接始终保持安全
* FTP 目录列表是一致的和机器可读的
* FTP 协议包括操作权限和属性操作,文件锁定和更多的功能。
缺点:
* 通信是二进制的,不能“按原样”记录下来用于人类阅读,
* SSH 密钥更难以管理和验证。
* 这些标准定义了某些可选或推荐的选项,这会导致不同供应商的不同软件之间存在某些兼容性问题。
* 没有服务器到服务器的复制和递归目录删除操作
* 在 VCL 和 .NET 框架中没有内置的 SSH/SFTP 支持。
### 对比
大多数 FTP 服务器软件这两种安全 FTP 技术都支持,以及强大的身份验证选项。
但 SFTP 显然是赢家,因为它适合防火墙。SFTP 只需要通过防火墙打开一个端口(默认为 22)。此端口将用于所有 SFTP 通信,包括初始认证、发出的任何命令以及传输的任何数据。
FTPS 通过严格安全的防火墙相对难以实现,因为 FTPS 使用多个网络端口号。每次进行文件传输请求(get,put)或目录列表请求时,需要打开另一个端口号。因此,必须在您的防火墙中打开一系列端口以允许 FTPS 连接,这可能是您的网络的安全风险。
支持 FTPS 和 SFTP 的 FTP 服务器软件:
1. [Cerberus FTP 服务器](http://www.cerberusftp.com/)
2. [FileZilla - 最著名的免费 FTP 和 FTPS 服务器软件](http://www.techmixer.com/free-ftp-server-best-windows-ftp-server-download/)
3. [Serv-U FTP 服务器](http://www.serv-u.com/)
---
via: <http://www.techmixer.com/ftps-sftp/>
作者:[Techmixer.com](http://www.techmixer.com/) 译者:[Yuan0302](https://github.com/Yuan0302) 校对:[jasminepeng](https://github.com/jasminepeng)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 200 | OK | **SSH File transfer protocol, SFTP** or **File Transfer protocol via Secure Socket Layer, **FTPS are the most common secure FTP communication technologies used to transfer computer files from one host to another host over a TCP networks. Both SFTP and FTPS offer a high level file transfer security protection with strong algorithms such as AES and Triple DES to encrypt any data transferred.
But the most notable differences between SFTP and FTPS is how connections are authenticated and managed.
FTPS is FTP utilising Secure Secure Layer (SSL) certificate for Security. The entire secure FTP connection is authenticated using an User ID, Password and SSL certificate. Once FTPS connection established, [FTP client software](https://www.techmixer.com/free-ftp-file-transfer-protocol-softwares/) will check destination [FTP server ](https://www.techmixer.com/free-ftp-server-best-windows-ftp-server-download/)if the server’s certificate is trusted.
The SSL certificate will considered trusted if either the certificate was signed off by a known certificate authority (CA) or if the certificate was self-signed (by your partner) and you have a copy of their public certificate in your trusted key store. All username and password information for FTPS will be encrypted through secure FTP connection.
## Below are the FTPS pros and cons:
Pros:
- The communication can be read and understood by a human
- Provides services for server-to-server file transfer
- SSL/TLS has good authentication mechanisms (X.509 certificate features)
- FTP and SSL support is built into many internet communications frameworks
Cons:
- Does not have a uniform directory listing format
- Requires a secondary DATA channel, which makes it hard to use behind firewalls
- Does not define a standard for file name character sets (encodings)
- Not all FTP servers support SSL/TLS
- Does not have a standard way to get and change file or directory attributes
SFTP or SSH File Transfer Protocol is another secure Secure File Transfer Protocol is designed as a SSH extension to provide file transfer capability, so it usually uses only the SSH port for both data and control. When your [FTP client](https://www.techmixer.com/best-free-mac-ftp-client-connect-ftp-server/) software connect to SFTP server, it will transmit public key to the server for authentication. If the keys match, along with any user/password supplied, then the authentication will succeed.
## Below are the SFTP Pros and Cons:
Pros:
- Has only one connection (no need for a DATA connection).
- FTP connection is always secured
- FTP directory listing is uniform and machine-readable
- FTP protocol includes operations for permission and attribute manipulation, file locking, and more functionality.
Cons:
- The communication is binary and can not be logged “as is” for human reading
SSH keys are harder to manage and validate. - The standards define certain things as optional or recommended, which leads to certain compatibility problems between different software titles from different vendors.
- No server-to-server copy and recursive directory removal operations
- No built-in SSH/SFTP support in VCL and .NET frameworks.
Overall most of FTP server software support both secure FTP technologies with strong authentication options.
But SFTP will be clear winner since it’s very firewall friendly. SFTP only needs a single port number (default of 22) to be opened through the firewall. This port will be used for all SFTP communications, including the initial authentication, any commands issued, as well as any data transferred.
FTPS will be more difficult to implement through a tightly secure firewall since FTPS uses multiple network port numbers. Every time a file transfer request (get, put) or directory listing request is made, another port number needs to be opened. Therefore it have to open a range of ports in your firewalls to allow for FTPS connections, which can be a security risk for your network.
FTP Server software that supports FTPS and SFTP: |
8,340 | Linux Deepin :一个拥有独特风格的发行版 | http://www.techphylum.com/2014/08/linux-deepin-distro-with-unique-style.html | 2017-03-26T19:14:41 | [
"发行版",
"深度"
] | https://linux.cn/article-8340-1.html | **编者注:本文原文完成于 2014 年,现在的深度 Linux 发行版已经在此基础上获得更多改进,翻译分享此文是为了让大家看看国外的开源社区对一款来自中国的发行版是如何看的。**
这是本系列的第六篇 **Linux Deepin。**这个发行版真的是非常有意思,它有着许多吸引眼球的地方。许许多多的发行版,它们仅仅将已有的应用放入它的应用市场中,使得它们的应用市场十分冷清。但是 Deepin 却将一切变得不同,虽然这个发行版是基于 Debian 的,但是它提供了属它自己的桌面环境。只有很少的发行版能够将它自己创造的软件做得很好。上次我们曾经提到了 **Elementary OS** 有着自己的 Pantheon 桌面环境。让我们来看看 Deepin 做得怎么样。

首先,在你登录你的账户后,你会在你设计良好的桌面上看到一个欢迎界面和一个精美的 Dock。这个 Dock 是可定制的,根据你放到上面的软件,它可以有着各种特效。

可以看到 Dock 上有着一个启动器图标,但是还有一个办法可以打开启动器,就是将指针移动到左上角。启动器界面优雅,并且可以分类浏览。

你可以做上面的截图中看到,启动器中的应用被分类得井井有条。还有一个好的地方是当你用鼠标点击到左下角,所有桌面上的应用将会最小化。再次点击则会回复原样。

如果你点击右下角,它将会滑出控制中心。这里可以更改所有电脑上的设置。

你可以看到截屏中的控制中心,设计得非常棒而且也是分类得井井有条,你可以在这里设置所有电脑上的项目。甚至可以自定义你的启动界面的壁纸。

Deepin 有一个自己的应用市场。你可以在这里找到绝大多数软件,并且它们很容易安装。应用市场也被设计得很好,分类齐全易于导航。

另一个亮点是 Deepin 的游戏。它提供许多免费的可联网玩耍的游戏,它们非常的有意思可以很好的用于消磨时光。

Deepin 也提供一个好用的音乐播放软件,它有着网络电台点播功能。如果你本地没有音乐你也不用害怕,你可以调到网络电台模式来享受音乐。
总的来说,Deepin 知道如何让用户享受它的产品。就像它们的座右铭那样:“要做,就做出风格”。它们提供的支持服务也非常棒。尽管是个中国的发行版,但是英语支持得也很好,不用担心语言问题。它的安装镜像大约 1.5 GB。你的访问它们的**[官网](http://www.linuxdeepin.com/index.en.html)**来获得更多信息或者下载。我们非常的推荐你试试这个发行版。
这就是本篇 **Linux 发行版介绍**的全部内容了,我们将会继续介绍其它的发行版。下次再见!
---
via: <http://www.techphylum.com/2014/08/linux-deepin-distro-with-unique-style.html>
作者:[sumit rohankar](https://plus.google.com/112160169713374382262) 译者:[Chao-zhi](https://github.com/Chao-zhi) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
8,341 | 为什么(大多数)高级语言运行效率较慢 | https://www.sebastiansylvan.com/post/why-most-high-level-languages-are-slow | 2017-03-27T09:27:00 | [
"编程语言"
] | https://linux.cn/article-8341-1.html | 在近一两个月中,我多次的和线上线下的朋友讨论了这个话题,所以我干脆直接把它写在博客中,以便以后查阅。
大部分高级语言运行效率较慢的原因通常有两点:
1. 没有很好的利用缓存;
2. 垃圾回收机制性能消耗高。
但事实上,这两个原因可以归因于:高级语言强烈地鼓励编程人员分配很多的内存。

首先,下文内容主要讨论客户端应用。如果你的程序有 99.9% 的时间都在等待网络 I/O,那么这很可能不是拖慢语言运行效率的原因——优先考虑的问题当然是优化网络。在本文中,我们主要讨论程序在本地执行的速度。
我将选用 C# 语言作为本文的参考语言,其原因有二:首先它是我常用的高级语言;其次如果我使用 Java 语言,许多使用 C# 的朋友会告诉我 C# 不会有这些问题,因为它有值类型(但这是错误的)。
接下来我将会讨论,出于编程习惯编写的代码、使用<ruby> 普遍编程方法 <rp> ( </rp> <rt> with the grain </rt> <rp> ) </rp></ruby>的代码或使用库或教程中提到的常用代码来编写程序时会发生什么。我对那些使用难搞的办法来解决语言自身毛病以“证明”语言没毛病这事没兴趣,当然你可以和语言抗争来避免它的毛病,但这并不能说明语言本身是没有问题的。
### 回顾缓存消耗问题
首先我们先来回顾一下合理使用缓存的重要性。下图是基于在 Haswell 架构下内存延迟对 CPU 影响的 [数据](http://www.7-cpu.com/cpu/Haswell.html):

针对这款 CPU 读取内存的延迟,CPU 需要消耗近 230 个运算周期从内存读取数据,同时需要消耗 4 个运算周期来读取 L1 缓冲区。因此错误的去使用缓存可导致运行速度拖慢近 50 倍。还好这并不是最糟糕的——在现代 CPU 中它们能同时地做多种操作,所以当你加载 L1 缓冲区内容的同时这个内容已经进入到了寄存器,因此数据从 L1 缓冲区加载这个过程的性能消耗就被部分或完整的掩盖了起来。
撇开选择合理的算法不谈,不夸张地讲,在性能优化中你要考虑的最主要因素其实是缓存未命中。当你能够有效的访问一个数据时候,你才需要考虑优化你的每个具体的操作。与缓存未命中的问题相比,那些次要的低效问题对运行速度并没有什么过多的影响。
这对于编程语言的设计者来说是一个好消息!你都*不必*去编写一个最高效的编译器,你可以完全摆脱一些额外的开销(比如:数组边界检查),你只需要专注怎么设计语言能高效地编写代码来访问数据,而不用担心与 C 语言代码比较运行速度。
### 为什么 C# 存在缓存未命中问题
坦率地讲 C# 在设计时就没打算在现代缓存中实现高效运行。我又一次提到程序语言设计的局限性以及其带给程序员无法编写高效的代码的“压力”。大部分的理论上的解决方法其实都非常的不便,这里我说的是那些编程语言“希望”你这样编写的惯用写法。
C# 最基本的问题是对<ruby> 基础值类型 <rp> ( </rp> <rt> value-based </rt> <rp> ) </rp></ruby>低下的支持性。其大部分的数据结构都是“内置”在语言内定义的(例如:栈,或其他内置对象)。但这些具有帮助性的内置结构体有一些大问题,以至于更像是创可贴而不是解决方案。
* 你得把自己定义的结构体类型在最先声明——这意味着你如果需要用到这个类型作为堆分配,那么所有的结构体都会被堆分配。你也可以使用一些类包装器来打包你的结构体和其中的成员变量,但这十分的痛苦。如果类和结构体可以相同的方式声明,并且可根据具体情况来使用,这将是更好的。当数据可以作为值地存储在自定义的栈中,当这个数据需要被堆分配时你就可以将其定义为一个对象,比如 C++ 就是这样工作的。因为只有少数的内容需要被堆分配,所以我们不鼓励所有的内容都被定义为对象类型。
* *引用* 值被苛刻的限制。你可以将一个引用值传给函数,但只能这样。你不能直接引用 `List<int>` 中的元素,你必须先把所有的引用和索引全部存储下来。你不能直接取得指向栈、对象中的变量(或其他变量)的指针。你只能把它们复制一份,除了将它们传给一个函数(使用引用的方式)。当然这也是可以理解的。如果类型安全是一个先驱条件,灵活的引用变量和保证类型安全这两项要同时支持太难了(虽然不是不可能)。这些限制背后的理念并不能改变限制存在的事实。
* [固定大小的缓冲区](https://msdn.microsoft.com/en-us/library/vstudio/zycewsya(v=vs.100).aspx) 不支持自定义类型,而且还必须使用 `unsafe` 关键字。
* 有限的“数组切片”功能。虽然有提供 `ArraySegment` 类,但并没有人会使用它,这意味着如果只需要传递数组的一部分,你必须去创建一个 `IEnumerable` 对象,也就意味着要分配大小(包装)。就算接口接受 `ArraySegment` 对象作为参数,也是不够的——你只能用普通数组,而不能用 `List<T>`,也不能用 [栈数组](https://msdn.microsoft.com/en-us/library/vstudio/cx9s2sy4(v=vs.100).aspx) 等等。
最重要的是,除了非常简单的情况之外,C# 非常惯用堆分配。如果所有的数据都被堆分配,这意味着被访问时会造成缓存未命中(从你无法决定对象是如何在堆中存储开始)。所以当 C++ 程序面临着如何有效的组织数据在缓存中的存储这个挑战时,C# 则鼓励程序员去将数据分开地存放在一个个堆分配空间中。这就意味着程序员无法控制数据存储方式了,也开始产生不必要的缓存未命中问题,而导致性能急速的下降。[C# 已经支持原生编译](https://msdn.microsoft.com/en-us/vstudio/dotnetnative.aspx) 也不会提升太多性能——毕竟在内存不足的情况下,提高代码质量本就杯水车薪。
再加上存储是有开销的。在 64 位的机器上每个地址值占 8 位内存,而每次分配都会有存储元数据而产生的开销。与存储着少量大数据(以固定偏移的方式存储在其中)的堆相比,存储着大量小数据的堆(并且其中的数据到处都被引用)会产生更多的内存开销。尽管你可能不怎么关心内存怎么用,但事实上就是那些头部内容和地址信息导致堆变得臃肿,也就是在浪费缓存了,所以也造成了更多的缓存未命中,降低了代码性能。
当然有些时候也是有办法的,比如你可以使用一个很大的 `List<T>` 来构造数据池以存储分配你需要的数据和自己的结构体。这样你就可以方便的遍历或者批量更新你的数据池中的数据了。但这也会很混乱,因为无论你在哪要引用什么对象都要先能引用这个池,然后每次引用都需要做数组索引。从上文可以得出,在 C# 中做类似这样的处理的痛感比在 C++ 中做来的更痛,因为 C# 在设计时就是这样。此外,通过这种方式来访问池中的单个对象比直接将这个对象分配到内存来访问更加的昂贵——前者你得先访问池(这是个类)的地址,这意味着可能产生 *2* 次缓存未命中。你还可以通过复制 `List<T>` 的结构形式来避免更多的缓存未命中问题,但这就更难搞了。我就写过很多类似的代码,自然这样的代码只会水平很低而且容易出错。
最后,我想说我指出的问题不仅是那些“热门”的代码。惯用手段编写的 C# 代码倾向于几乎所有地方都用类和引用。意思就是在你的代码中会频率均匀地随机出现数百次的运算周期损耗,使得操作的损耗似乎降低了。这虽然也可以被找出来,但你优化了这问题后,这还是一个 [均匀变慢](http://c2.com/cgi/wiki?UniformlySlowCode) 的程序。
### 垃圾回收
在读下文之前我会假设你已经知道为什么在许多用例中垃圾回收是影响性能问题的重要原因。播放动画时总是随机的暂停通常都是大家都不能接受的吧。我会继续解释为什么设计语言时还加剧了这个问题。
因为 C# 在处理变量上的一些局限性,它强烈不建议你去使用大内存块分配来存储很多里面是内置对象的变量(可能存在栈中),这就使得你必须使用很多分配在堆中的小型类对象。说白了就是内存分配越多会导致花在垃圾回收上的时间就越多。
有些测评说 C# 或者 Java 是怎么在一些特定的例子中打败 C++ 的,其实是因为内存分配器都基于一种吞吐还算不错的垃圾回收机制(廉价的分配,允许统一的释放分配)。然而,这些测试场景都太特殊了。想要使 C# 的程序的内存分配率变得和那些非常普通的 C++ 程序都能达到的一样就必须要耗费更大的精力来编写它,所以这种比较就像是拿一个高度优化的管理程序和一个最简单原生的程序相比较一样。当你花同样的精力来写一个 C++ 程序时,肯定比你用 C# 来写性能好的多。
我还是相信你可以写出一套适用于高性能低延迟的应用的垃圾回收机制的(比如维护一个增量的垃圾回收,每次消耗固定的时间来做回收),但这还是不够的,大部分的高级语言在设计时就没考虑程序启动时就会产生大量的垃圾,这将会是最大的问题。当你就像写 C 一样习惯的去少去在 C# 分配内存,垃圾回收在高性能应用中可能就不会暴露出很多的问题了。而就算你 *真的* 去实现了一个增量垃圾回收机制,这意味着你还可能需要为其做一个写屏障——这就相当于又消耗了一些性能了。
看看 `.Net` 库里那些基本类,内存分配几乎无处不在!我数了下,在 [.Net 核心框架](https://github.com/dotnet/corefx) 中公共类比结构体的数量多出 19 倍之多,为了使用它们,你就得把这些东西全都弄到内存中去。就算是 `.Net` 框架的创造者们也无法抵抗设计语言时的警告啊!我都不知道怎么去统计了,使用基础类库时,你会很快意识到这不仅仅是值或对象的选择问题了,就算如此也还是 *伴随* 着超级多的内存分配。这一切都让你觉得分配内存好像很容易一样,其实怎么可能呢,没有内存分配你连一个整型值都没法输出!不说这个,就算你使用预分配的 `StringBuilder`,你要是不用标准库来分配内存,也还不是连个整型都存不住。你要这么问我那就挺蠢的了。
当然还不仅仅是标准库,其他的 C# 库也一样。就算是 `Unity`(一个 *游戏引擎*,可能能更多的关心平均性能问题)也会有一些全局返回已分配对象(或数组)的接口,或者强制调用时先将其分配内存再使用。举个例子,在一个 `GameObject` 中要使用 `GetComponents` 来调用一个数组,`Unity` 会强制地分配一个数组以便调用。就此而言,其实有许多的接口可以采用,但他们不选择,而去走常规路线来直接使用内存分配。写 `Unity` 的同胞们写的一手“好 C#”呀,但就是不那么高性能罢了。
### 结语
如果你在设计一门新的语言,拜托你可以考虑一下我提到的那些性能问题。在你创造出一款“足够聪明的编译器”之后这些都不是什么难题了。当然,没有垃圾回收器就要求类型安全很难。当然,没有一个规范的数据表示就创造一个垃圾回收器很难。当然,出现指向随机值的指针时难以去推出其作用域规则。当然,还有大把大把的问题摆在那里,然而解决了这些所有的问题,设计出来的语言就会是我们想的那样吗?那为什么这么多主要的语言都是在那些六十年代就已经被设计出的语言的基础上迭代的呢?
尽管你不能修复这些问题,但也许你可以尽可能的靠近?或者可以使用域类型(比如 `Rust` 语言)去保证其类型安全。或者也许可以考虑直接放弃“类型安全成本”去使用更多的运行时检查(如果这不会造成更多的缓存未命中的话,这其实没什么所谓。其实 C# 也有类似的东西,叫协变式数组,严格上讲是违背系统数据类型的,会导致一些运行时异常)。
如果你想在高性能场景中替代 C++,最基本的一点就是要考虑数据的存放布局和存储方式。
---
作者简介:
我叫 Sebastian Sylvan。我来自瑞典,目前居住在西雅图。我在微软工作,研究全息透镜。诚然我的观点仅代表本人,与微软公司无关。
我的博客以图像、编程语言、性能等内容为主。联系我请点击我的 Twitter 或 E-mail。
---
via: <https://www.sebastiansylvan.com/post/why-most-high-level-languages-are-slow>
作者:[Sebastian Sylvan](https://www.sebastiansylvan.com/about/) 译者:[kenxx](https://github.com/kenxx) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
8,342 | 漫画赏析: Vi 还是不 Vi,这是个问题 | http://turnoff.us/geek/to-vi-or-not-to-vi/ | 2017-03-27T10:11:00 | [
"漫画"
] | https://linux.cn/article-8342-1.html | LCTT/comic 组成立之前,已有几篇 turnoff.us 漫画发布于 Linux.中国。随着之前的“[消沉的程序员](/article-8318-1.html)”系列漫画的汉化完成,LCTT/comic 翻译仓库也随之建立完成。
那么,本期是 GHLandy 给大家带来的 turnoff.us 上 “<ruby> Vi 还是不 Vi,这是个问题 <rp> ( </rp> <rt> to vi or not to vi </rt> <rp> ) </rp></ruby>” 的汉化版漫画。如下:

上图展示了一个小伙子在有人注视自己工作的时候,使用 Vi 来编辑配置文件,装了一波十三。然后,在人离开后有赶紧拿起趁手的 Sublime 来使用。可能这幅漫画也是很多人的真实写照吧。
相信大家都有各自喜爱的文本编辑器,或者说是开发环境吧。就 GHLandy 本人,也就在文本模式下使用 Vim,然后 GUI 模式使用 Atom 和 notepad++。那么,各位小伙伴,你们各自使用的什么编辑器呢。
感觉这幅漫画要引发激烈争论,快来畅所欲言吧!
---
via: <http://turnoff.us/geek/to-vi-or-not-to-vi/>
作者:[Daniel Stori](https://turnoff.us/about/) 译者:[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,343 | 如何在 Linux 桌面上使用 Gifine 录制 GIF 动画? | https://www.howtoforge.com/tutorial/record-screen-to-animated-gif-on-linux/ | 2017-03-27T10:45:44 | [
"动画",
"录屏",
"Gifine"
] | https://linux.cn/article-8343-1.html | 不用我说,你也知道 GIF 动画在过去几年发展迅速。人们经常在线上文字交流时使用动画增添趣味,同时这些动画在很多其他地方也显得非常有用。
在技术领域使用动画能够很快的描述出现的问题或者返回的错误。它也能很好的展现出一个软件应用产品的特性。你可以在进行线上座谈会或者在进行公司展示时使用 GIF 动画,当然,你可以在更多的地方用到它。
现在,假设你的电脑桌面上打开了多个应用程序,或者无论出于什么目的,你想制作一个 GIF 动画来记录桌面上一个应用程序窗口的操作过程。你应该怎么做呢?显然,你需要一个工具来完成这件事。
如果你正在寻找了这样一个可以记录桌面上部分区域的工具,并且它可以自动把录屏转化成 GIF 动画; 现在,本教程会介绍一个 Linux 命令行工具来实现你的需求。
开始之前,你必须知道在本教程中所有的例子都是在 Ubuntu 14.04 上测试过的,它的 Bash 版本是 4.3.11(1) 。

### Gifine
这个工具的主页是 [Gifine](https://github.com/leafo/gifine) 。它基于 GTK 工具包,是用 MoonScript 使用 lgi 库编写的。Gifine 不仅能够录屏、创建动画或视频,而且能够用它来把几个小型动画或视频拼接在一起。
引述这个工具的开发者的话:“你可以加载一个视频帧的目录或者选择一个桌面的区域进行录屏。你加载了一些视频帧后,可以连续查看它们,并裁剪掉不需要的部分。最终完成录屏后可以导出为 gif 或者 mp4 文件。”
### Gifine 下载/安装/配置
在指引你下载和安装 Gifine 之前,应该指出安装这个工具时需要安装的依赖包。
首先需要安装的依赖包是 FFmpeg , 这个软件包是一种记录、转化和流化音频以及视频的跨平台解决方案。使用下列命令安装这个工具;
```
sudo apt-get install ffmpeg
```
接下来是图像处理系统 GraphicsMagick。这个工具的官网说:“它提供了一个稳健且高效的工具和库的集合,支持读写并且可以操作超过 88 种主要的图像格式,比如:DPX、 GIF、 JPEG、 JPEG-2000、 PNG、 PDF、 PNM 以及 TIFF 等。”
通过下面的命令安装:
```
sudo apt-get install graphicsmagick
```
接下来的需要的工具是 XrectSel 。在你移动鼠标选择区域的时候,它会显示矩形区域的坐标位置。我们只能通过源码安装 XrectSel ,你可以从 [这里](https://github.com/lolilolicon/xrectsel) 下载它。
如果你下载了源码,接下来就可以解压下载的文件,进入解压后的目录中。然后,运行下列命令:
```
./bootstrap
```
如果 `configure` 文件不存在,就需要使用上面的命令
```
./configure --prefix /usr
make
make DESTDIR="$directory" install
```
最后的依赖包是 Gifsicle 。这是一个命令行工具,可以创建、编辑、查看 GIF 图像和动画的属性信息。下载和安装 Gifsicle 相当容易,你只需要运行下列命令:
```
sudo apt-get install gifsicle
```
这些是所有的依赖包。现在,我们开始安装 Gifine 。使用下面的命令完成安装。
```
sudo apt-get install luarocks
sudo luarocks install --server=http://luarocks.org/dev gifine
```
请注意第二个命令可能会返回下列错误:
```
No package 'gobject-introspection-1.0' found
```
你可以用下列命令安装这个包:
```
sudo apt-get install libgirepository1.0-dev
```
然后,再一次运行 `luarocks install` 命令。
### Gifine 使用
完成安装之后可以使用下面的命令运行这个工具:
```
gifine
```
这个应用程序的 UI 是这样的:

这里你可以进行两种操作:录视频帧或者加载视频帧。如果你单击了<ruby> 录制矩形区域 <rp> ( </rp> <rt> Record rectange </rt> <rp> ) </rp></ruby>按钮,你的鼠标指针处会变成一个 `+` ,这样便可以在你的屏幕上选择一个矩形区域。一旦你选择了一个区域,录屏就开始了,<ruby> 录制矩形区域 <rp> ( </rp> <rt> Record rectange </rt> <rp> ) </rp></ruby>按钮就会变成<ruby> 停止录制 <rp> ( </rp> <rt> Stop recording </rt> <rp> ) </rp></ruby>按钮。

单击<ruby> 停止录制 <rp> ( </rp> <rt> Stop recording </rt> <rp> ) </rp></ruby>完成录屏,会在 Gifine 窗口出现一些按钮。

用户界面的上半部分显示已经录制的视频帧,你可以使用它下面的滑块进行逐帧浏览。如果你想要删除第 5 帧之前或第 50 帧之后的所有帧数,你可以使用<ruby> 裁剪左边 <rp> ( </rp> <rt> Trim left of </rt> <rp> ) </rp></ruby> 和<ruby> 裁剪右边 <rp> ( </rp> <rt> Trim rigth of </rt> <rp> ) </rp></ruby>按钮进行裁剪。也有可以删除特定帧数和减半删除帧数的按钮,当然,你可以重置所有的裁剪操作。
完成了所有的裁剪后,可以使用<ruby> 保存 GIF <rp> ( </rp> <rt> Save GIF... </rt> <rp> ) </rp></ruby>或<ruby> 保存 MP4 <rp> ( </rp> <rt> Save MP4... </rt> <rp> ) </rp></ruby>按钮将录屏保存为动画或者视频;你会看到可以设置帧延迟、帧率以及循环次数的选项。
记住,“录屏帧不会自动清除。如果你想重新加载,可以在初始屏幕中使用<ruby> 加载目录 <rp> ( </rp> <rt> load directory </rt> <rp> ) </rp></ruby>按钮在 '/tmp' 目录中找到它们。“
### 总结
Gifine 的学习曲线并不陡峭 —— 所有的功能都会以按钮、文本的形式体现出来。
对我来说,最大的问题是安装 —— 需要一个个安装它的依赖包,还要处理可能出现的错误,这会困扰很多人。否则,从整体上看,Gifine 绝对称得上是一个不错的工具,如果你正在寻找这样的工具,不妨一试。
已经是 Gifine 用户?到目前为止你得到了什么经验?在评论区告诉我们。
---
via: <https://www.howtoforge.com/tutorial/record-screen-to-animated-gif-on-linux/>
作者:[Ansh](https://www.howtoforge.com/tutorial/record-screen-to-animated-gif-on-linux/) 译者:[vim-kakali](https://github.com/vim-kakali) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 200 | OK | # How to record a region of your desktop as animated GIF on Linux
It won't be a stretch to say - and you'll likely agree - that animated gifs have become a rage in the past few years. While one of the most popular uses of animated gifs is to add humor to the text-based conversation that people usually have online, there are many other areas where these animations prove to be really useful.
Those in technical spheres usually use animated gifs to quickly describe how a problem or an error gets triggered. It's also a useful way of explaining how a particular feature in a software application works. You can easily use gifs in online forums, your company presentations, and more.
Now, suppose you have various applications opened on your Linux desktop, and for whatever purpose, you want to create an animated gif out of your activity with a particular application that's occupying only a small area of your desktop. What would you do? Obviously, look for a tool that lets you do the same.
If you've been looking for one such tool that lets you record a particular region of you desktop and then automatically convert the recording into an animated gif, then look no further, as in this tutorial, we will discuss a Linux command line utility that lets you do just that.
*Before we proceed, keep in mind that all the examples in this tutorial have been tested on Ubuntu 14.04 with Bash version 4.3.11(1).*
* *
## Gifine
The tool in question is [Gifine](https://github.com/leafo/gifine). It is is basically a GTK application implemented in MoonScript using lgi. Gifine not only lets you record your desktop screen and create animated gifs or video, but also lets you stitch together short gifs or videos.
According to the application's developer: "You can either load a directory of frames, or select a region of your desktop to record. After loading some frames, you can scroll through them and trim out what isn't necessary. When you've finalized the video you can export to gif or mp4.".
## Gifine Download/Installation/Setup
Before we go ahead and tell you the steps to download and install Gifine, it's worth mentioning that the tool has several dependencies that you need to install before installing the tool itself.
The first dependency that you need to install is FFmpeg, which is basically a cross-platform solution to record, convert and stream audio and video. Following is the command that should install the tool:
sudo apt-get install ffmpeg
Next up is GraphicsMagick, which is basically an image processing system. "It provides a robust and efficient collection of tools and libraries which support reading, writing, and manipulating an image in over 88 major formats including important formats like DPX, GIF, JPEG, JPEG-2000, PNG, PDF, PNM, and TIFF," the tool's official website says.
Following is the command to download and install it:
sudo apt-get install graphicsmagick
Next up is a tool dubbed XrectSel. It's basically an application that tells you the geometry of a rectangular screen region which you have selected by dragging the mouse/pointer. The only way to install XrectSel is from source, which you can download by heading [here](https://github.com/lolilolicon/xrectsel).
Once you've downloaded theXrectSel source code on your system, the next step is extract the downloaded archive and enter the top-level directory on a command line terminal. Once there, run the following commands:
./bootstrap
The above command is required if ./configure is not present
./configure --prefix /usr
make
make DESTDIR="$directory" install
Moving on, the last dependency is Gifsicle. It's a command-line tool for creating, editing, and getting information about GIF images and animations. Downloading and installing Gifsicle is quite easy - all you need to do is to run the following command:
sudo apt-get install gifsicle
So that was all about the dependencies. Now, let us come to the installation of Gifine. The following two commands will do the needful:
sudo apt-get install luarocks
sudo luarocks install --server=http://luarocks.org/dev gifine
Please note that the second command above may give you the following error:
No package 'gobject-introspection-1.0' found
In that case, you need to install the package using the following command:
sudo apt-get install libgirepository1.0-dev
And then run the 'luarocks install' command again.
## Gifine Usage
Once you're done with the installation part, you can launch the tool using the following command:
gifine
The application's UI looks like this:
So you have a couple of options here: record frames and load frames. If you click the *Record rectangle* button, then your mouse pointer gets converted into a +, allowing you to select a rectangular area on your screen. As soon as you are done selecting an area, the recording begins, and the 'Record rectangle' button is replaced by a 'Stop recording' button.
As soon as you are done with the recording, click the 'Stop recording' button and you'll see that the Gifine window shows several buttons.
The upper part of the UI contains the recording, which you can see frame by frame using the slider below it. Suppose you want to delete all the frames before frame 5 or after frame 50, then this can be done using the *Trim left of* and *Trim right of* buttons. Then there are also buttons to delete a particular frame, half the number of frames, as well as reset any frame cuts that you've made.
Once you are done with all the editing part, use the *Save GIF...* or *Save MP4...* buttons to save the recording as an animated gif or a video. There are options to set frame delay, frame rate, and number of loops as well.
Please keep in mind that "the recorded frames recorded aren't automatically cleaned up. You can find them in your `/tmp`
dir if you want to reload a session. Use the *load directory* button on the initial screen.".
## Conclusion
There's not much of a learning curve associated with Gifine - all the features are available in the form of buttons, and the text on them makes their functionality self explanatory.
The only issue for me was the installation part - installing so many dependencies one by one and then dealing with errors that may pop up could be a big no no for many. But otherwise, on the whole, Gifine is a nice tool that does what it promises, and if that's what you were looking for, do give it a try.
Already a Gifine user? How has your experience been so far? Let us known in comments below. |
8,344 | 一个可对显示器造成物理伤害的 Xfce Bug | http://www.omgubuntu.co.uk/2017/03/xfce-wallpaper-cat-bug | 2017-03-27T11:19:00 | [
"Bug",
"Xfce"
] | https://linux.cn/article-8344-1.html | Linux 上使用 Xfce 桌面环境或许是又快又灵活的 — 但是它目前在遭受着一个很严重的缺陷影响。
使用这个轻量级 GNOME 和 KDE 替代品 Xfce 桌面的用户报告说,其选用的默认壁纸会造成**笔记本电脑显示器和液晶显示器的损坏**!!!
有确凿的照片证据来支持此观点。
### Xfce Bug #12117
*“桌面默认开机画面造成显示器损坏!”* 某用户在 Xfce 的 Bugzilla [Bug 提交区](https://bugzilla.xfce.org/show_bug.cgi?id=12117)尖叫道。
*“默认桌面壁纸导致我的动物去抓它,从我的液晶显示器掉落下来塑料!能让我们选择不同的壁纸吗?我不想再有划痕,谁想呢?让我们结束这老鼠游戏吧。”* (LCTT 译注:原文是 whu not,可能想打 who not,也许因屏幕坏了太激动打错字了)

这<ruby> 缺陷 <rp> ( </rp> <rt> flaw </rt> <rp> ) </rp></ruby> — 或者说是这<ruby> 爪爪 <rp> ( </rp> <rt> claw </rt> <rp> ) </rp></ruby>? — 不是个别用户的桌面遇到问题。其他用户也重现了这个问题,尽管不太一样,在这第二个例子,是 <ruby> 红迪网友 <rt> Redditor </rt></ruby> 的不同图片证实的:

目前不知道这锅是 Xfce 的还是猫猫的。如果是后者就没希望修复了,就像便宜的 Android 手机商品(LCTT 译注:原文这里是用 cats 这个单词,是 catalogues 的缩写,一语双关“猫”。原文作者也是个猫奴,#TeamCat 成员)从来得不到他们的 OEM 厂商的升级。
值得庆幸的是 Xubuntu 用户们并没有受到这“爪爪”问题的影响。这是因为它这个基于 Xfce 的 Ubuntu 特色版带有自己的非老鼠的桌面壁纸。
对其他 Linux 发行版的 Xfce 用户来说,“爪爪们”显然对其桌面倒不是那么感兴趣。
已经有人已经提出了一个补丁修复这个问题,但是上游尚未接受。如果你们关注了 [bug #12117](https://bugzilla.xfce.org/show_bug.cgi?id=12117) ,就可以在你们自己的系统上手动应用这个补丁,去下载以下图片并设置成桌面壁纸。

---
via: <http://www.omgubuntu.co.uk/2017/03/xfce-wallpaper-cat-bug>
作者:[JOEY SNEDDON](https://plus.google.com/117485690627814051450/?rel=author) 译者:[ddvio](https://github.com/ddvio) 校对:[jasminepeng](https://github.com/jasminepeng)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
8,345 | Go 语言编译期断言 | http://commaok.xyz/post/compile-time-assertions | 2017-03-28T08:12:00 | [
"Go",
"断言"
] | https://linux.cn/article-8345-1.html | 这篇文章是关于一个鲜为人知的让 Go 在编译期断言的方法。你可能不会使用它,但是了解一下也很有趣。

作为一个热身,来看一个在 Go 中熟知的编译期断言:接口满意度检查。
在这段代码([playground](https://play.golang.org/p/MJ6zF1oNsX))中,`var _ =` 行确保类型 `W` 是一个 `stringWriter`,其由 [`io.WriteString`](https://golang.org/pkg/io/#WriteString) 检查。
```
package main
import "io"
type W struct{}
func (w W) Write(b []byte) (int, error) { return len(b), nil }
func (w W) WriteString(s string) (int, error) { return len(s), nil }
type stringWriter interface {
WriteString(string) (int, error)
}
var _ stringWriter = W{}
func main() {
var w W
io.WriteString(w, "very long string")
}
```
如果你注释掉了 `W` 的 `WriteString` 方法,代码将无法编译:
```
main.go:14: cannot use W literal (type W) as type stringWriter in assignment:
W does not implement stringWriter (missing WriteString method)
```
这是很有用的。对于大多数同时满足 `io.Writer` 和 `stringWriter` 的类型,如果你删除 `WriteString` 方法,一切都会像以前一样继续工作,但性能较差。
你可以使用编译期断言保护你的代码,而不是试图使用[`testing.T.AllocsPerRun'](https://golang.org/pkg/testing/#AllocsPerRun)为性能回归编写一个脆弱的测试。
这是[一个实际的 io 包中的技术例子](https://github.com/golang/go/blob/go1.8rc2/src/io/multi.go#L72)。
---
好的,让我们低调一点!
接口满意检查是很棒的。但是如果你想检查一个简单的布尔表达式,如 `1 + 1 == 2` ?
考虑这个代码([playground](https://play.golang.org/p/mjIMWsWu4V)):
```
package main
import "crypto/md5"
type Hash [16]byte
func init() {
if len(Hash{}) < md5.Size {
panic("Hash is too small")
}
}
func main() {
// ...
}
```
`Hash` 可能是某种抽象的哈希结果。`init` 函数确保它将与 [crypto/md5](https://golang.org/pkg/crypto/md5/) 一起工作。如果你改变 `Hash` 为(比如说)`[8]byte`,它会在进程启动时发生崩溃。但是,这是一个运行时检查。如果我们想要早点发现怎么办?
如下。(没有 playground 链接,因为这在 playground 上不起作用。)
```
package main
import "C"
import "crypto/md5"
type Hash [16]byte
func hashIsTooSmall()
func init() {
if len(Hash{}) < md5.Size {
hashIsTooSmall()
}
}
func main() {
// ...
}
```
现在如果你改变 `Hash` 为 `[8]byte`,它将在编译过程中失败。(实际上,它在链接过程中失败。足够接近我们的目标了。)
```
$ go build .
# demo
main.hashIsTooSmall: call to external function
main.init.1: relocation target main.hashIsTooSmall not defined
main.init.1: undefined: "main.hashIsTooSmall"
```
这里发生了什么?
`hashIsTooSmall` 是[一个没有函数体的声明](https://golang.org/ref/spec#Function_declarations)。编译器假定别人将提供一个实现,也许是一个汇编程序。
当编译器可以证明 `len(Hash {})< md5.Size` 时,它消除了 if 语句中的代码。结果,没有人使用函数 `hashIsTooSmall`,所以链接器会消除它。没有其他损害。一旦断言失败,if 语句中的代码将被保留。不会消除 `hashIsTooSmall`。链接器然后注意到没有人提供了函数的实现然后链接失败,并出现错误,这是我们的目标。
最后一个奇怪的点:为什么是 `import "C"`? go 工具知道在正常的 Go 代码中,所有函数都必须有主体,并指示编译器强制执行。通过切换到 cgo,我们删除该检查。(如果你在上面的代码中运行 `go build -x`,而没有添加 `import "C"` 这行,你会看到编译器是用 `-complete` 标志调用的。)另一种方法是添加 `import "C"` 来[向包中添加一个名为 `foo.s` 的空文件](https://github.com/golang/go/blob/go1.8rc2/src/os/signal/sig.s)。
我仅见过一次这种技术的使用,是在[编译器测试套件](https://github.com/golang/go/blob/go1.8rc2/test/fixedbugs/issue9608.dir/issue9608.go)中。还有其他[可以发挥想象力的使用](https://github.com/golang/go/blob/go1.8rc2/src/runtime/hashmap.go#L261),但我还没见到过。
可能就是这样吧。 :)
---
via: <http://commaok.xyz/post/compile-time-assertions>
作者:[Josh Bleecher Snyder](https://twitter.com/commaok) 译者:[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,346 | NMAP 常用扫描简介(一) | https://www.linuxforum.com/threads/nmap-common-scans-part-one.3637/ | 2017-03-28T09:05:14 | [
"nmap",
"扫描"
] | /article-8346-1.html | 
我们之前在 [NMAP 的安装](https://www.linuxforum.com/threads/nmap-installation.3431/)一文中,列出了 10 种不同的 ZeNMAP 扫描模式。大多数的模式使用了各种参数。各种参数代表了执行不同的扫描模式。这篇文章将介绍其中的四种通用的扫描类型。
### 四种通用扫描类型
下面列出了最常使用的四种扫描类型:
1. PING 扫描 (`-sP`)
2. TCP SYN 扫描 (`-sS`)
3. TCP Connect() 扫描 (`-sT`)
4. UDP 扫描 (`-sU`)
当我们利用 NMAP 来执行扫描的时候,这四种扫描类型是我们需要熟练掌握的。更重要的是需要知道这些命令做了什么并且需要知道这些命令是怎么做的。本文将介绍 PING 扫描和 UDP 扫描。在之后的文中会介绍 TCP 扫描。
### PING 扫描 (-sP)
某些扫描会造成网络拥塞,然而 Ping 扫描在网络中最多只会产生两个包。当然这两个包不包括可能需要的 DNS 搜索和 ARP 请求。每个被扫描的 IP 最少只需要一个包来完成 Ping 扫描。
通常 Ping 扫描是用来查看在指定的 IP 地址上是否有在线的主机存在。例如,当我拥有网络连接却连不上一台指定的网络服务器的时候,我就可以使用 PING 来判断这台服务器是否在线。PING 同样也可以用来验证我的当前设备与网络服务器之间的路由是否正常。
**注意:** 当我们讨论 TCP/IP 的时候,相关信息在使用 TCP/IP 协议的互联网与局域网(LAN)中都是相当有用的。这些程序都能工作。同样在广域网(WAN)也能工作得相当好。
当参数给出的是一个域名的时候,我们就需要域名解析服务来找到相对应的 IP 地址,这个时候将会生成一些额外的包。例如,当我们执行 `ping linuxforum.com` 的时候,需要首先请求域名(linuxforum.com)的 IP 地址(98.124.199.63)。当我们执行 `ping 98.124.199.63` 的时候 DNS 查询就不需要了。当 MAC 地址未知的时候,就需要发送 ARP 请求来获取指定 IP 地址的 MAC 地址了(LCTT 译注:这里的指定 IP 地址,未必是目的 IP)。
Ping 命令会向指定的 IP 地址发送一个英特网信息控制协议(ICMP)包。这个包是需要响应的 ICMP Echo 请求。当服务器系统在线的状态下我们会得到一个响应包。当两个系统之间存在防火墙的时候,PING 请求包可能会被防火墙丢弃。一些服务器也会被配置成不响应 PING 请求来避免可能发生的死亡之 PING。(LCTT 译注:现在的操作系统似乎不太可能)
**注意:** 死亡之 PING 是一种恶意构造的 PING 包当它被发送到系统的时候,会造成被打开的连接等待一个 rest 包。一旦有一堆这样的恶意请求被系统响应,由于所有的可用连接都已经被打开,所以系统将会拒绝所有其它的连接。技术上来说这种状态下的系统就是不可达的。
当系统收到 ICMP Echo 请求后它将会返回一个 ICMP Echo 响应。当源系统收到 ICMP Echo 响应后我们就能知道目的系统是在线可达的。
使用 NMAP 的时候你可以指定单个 IP 地址也可以指定某个 IP 地址段。当被指定为 PING 扫描(`-sP`)的时候,会对每一个 IP 地址执行 PING 命令。
在图 1 中你可以看到我执行 `nmap -sP 10.0.0.1-10` 命令后的结果。程序会试着联系 IP 地址 10.0.0.1 到 10.0.0.10 之间的每个系统。对每个 IP 地址都要发出三个 ARP 请求。在我们的例子中发出了三十个请求,这 10 个 IP 地址里面有两个有回应。(LCTT 译注:此处原文存疑。)

*图 1*
图 2 中展示了网络上另一台计算机利用 Wireshark 抓取的发出的请求——没错,是在 Windows 系统下完成这次抓取的。第一行展示了发出的第一条请求,广播请求的是 IP 地址 10.0.0.2 对应 MAC 地址。由于 NMAP 是在 10.0.0.1 这台机器上执行的,因此 10.0.0.1 被略过了。由于本机 IP 地址被略过,我们现在可以看到总共只发出了 27 个 ARP 请求。第二行展示了 10.0.0.2 这台机器的 ARP 响应。第三行到第十行是其它八个 IP 地址的 ARP 请求。第十一行是由于 10.0.0.2 没有收到请求系统(10.0.0.1)的反馈所以(重新)发送的另一个 ARP 响应。第十二行是源系统向 10.0.0.2 发起的 HTTP 连接的 ‘SYN’ 和 Sequence 0。第十三行和第十四行的两次 Restart(RST)和 Synchronize(SYN)响应是用来关闭(和重发)第十二行所打开的连接的。注意 Sequence ID 是 ‘1’ - 是源 Sequence ID + 1。第十五行开始就是类似相同的内容。(LCTT 译注:此处原文有误,根据情况已经修改。)

*图 2*
回到图 1 中我们可以看到有两台主机在线。其中一台是本机(10.0.0.1)另一台是(10.0.0.2)。整个扫描花费了 14.40 秒。
PING 扫描是一种用来发现在线主机的快速扫描方式。扫描结果中没有关于网络、系统的其它信息。这是一种较好的初步发现网络上在线主机的方式,接着你就可以针对在线系统执行更加复杂的扫描了。你可能还会发现一些不应该出现在网络上的系统。出现在网络上的流氓软件是很危险的,他们可以很轻易的收集内网信息和相关的系统信息。
一旦你获得了在线系统的列表,你就可以使用 UDP 扫描来查看哪些端口是可能开启了的。
### UDP 扫描 (-sU)
现在你已经知道了有那些系统是在线的,你的扫描就可以聚焦在这些 IP 地址之上。在整个网络上执行大量的没有针对性的扫描活动可不是一个好主意,系统管理员可以使用程序来监控网络流量当有大量异常活动发生的时候就会触发警报。
用户数据报协议(UDP)在发现在线系统的开放端口方面十分有用。由于 UDP 不是一个面向连接的协议,因此是不需要响应的。这种扫描方式可以向指定的端口发送一个 UDP 包。如果目标系统没有回应那么这个端口可能是关闭的也可能是被过滤了的。如果端口是开放状态的那么应该会有一个响应。在大多数的情况下目标系统会返回一个 ICMP 信息说端口不可达。ICMP 信息让 NMAP 知道端口是被关闭了。如果端口是开启的状态那么目标系统应该响应 ICMP 信息来告知 NMAP 端口可达。
**注意:** 只有最前面的 1024 个常用端口会被扫描。(LCTT 译注:这里将 1000 改成了1024,因为手册中写的是默认扫描 1 到 1024 端口)在后面的文章中我们会介绍如何进行深度扫描。
由于我知道 10.0.0.2 这个主机是在线的,因此我只会针对这个 IP 地址来执行扫描。扫描过程中总共收发了 3278 个包。`sudo nmap -sU 10.0.0.2` 这个命令的输出结果在图 3 中展现。

*图 3*
在这副图中你可以看见端口 137(netbios-ns)被发现是开放的。在图 4 中展示了 Wireshark 抓包的结果。不能看到所有抓取的包,但是可以看到一长串的 UDP 包。

*图 4*
如果我把目标系统上的防火墙关闭之后会发生什么呢?我的结果有那么一点的不同。NMAP 命令的执行结果在图 5 中展示。

*图 5*
**注意:** 当你执行 UDP 扫描的时候是需要 root 权限的。
会产生大量的包是由于我们使用了 UDP。当 NMAP 发送 UDP 请求时它是不保证数据包会被收到的。因为数据包可能会在中途丢失因此它会多次发送请求。
---
via: <https://www.linuxforum.com/threads/nmap-common-scans-part-one.3637/>
作者:[Jarret](https://www.linuxforum.com/members/jarret.268/) 译者:[wcnnbdk1](https://github.com/wcnnbdk1) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| null | HTTPSConnectionPool(host='www.linuxforum.com', port=443): Max retries exceeded with url: /threads/nmap-common-scans-part-one.3637/ (Caused by NameResolutionError("<urllib3.connection.HTTPSConnection object at 0x7b8327581c60>: Failed to resolve 'www.linuxforum.com' ([Errno -2] Name or service not known)")) | null |
8,347 | LaTeXila 简介:Linux 上的一个多语言 LaTeX 编辑器 | https://www.howtoforge.com/tutorial/introduction-to-latexila-latex-editor/ | 2017-03-28T17:05:00 | [
"LaTeX",
"排版"
] | https://linux.cn/article-8347-1.html | LaTeXila 是一个多语言 LaTeX 编辑器,专为那些偏爱 GTK+ 外观的 Linux 用户设计。这个软件简单,但又足够强大,可定制性良好,所以如果你对 LaTeX 感兴趣,那么你就应该尝试一下这个工具。

在下面的快速指南中,我将展示如何使用 LaTeXila 并介绍其主要功能。但在开始之前你可能要问:
### 为何选择使用 LaTeX?
假如我想创建一个文本文档,为什么我不使用 LibreOffice 或者 Abiword 这些常规的工具呢?原因是相比于常规的文本编辑器,LaTeX 编辑器一般来说都会提供更多功能强大的格式化工具,让你在写作期间专注于文档的内容。LaTeX 是一个文档准备系统,目的是简化大多数常见出版物的处理过程,例如书籍或者科学报告,它们通常都包含很多数学公式,多语言排版元素,交叉引用及引文,参考文献等等需要处理的元素。尽管上面的那些元素也可以用 LibreOffice 来处理,使用 LaTeXila 要相对简单一些,同时处理得当的话你最后得到的会是一份高质量的文档。
### 在一个新文档上开始工作并设定文章结构
首先,我们需要在 LaTeXila 中创建一个新文件,这个可以通过点击位于左上角的 “新建文件” 图标来实现,接着它将打开一个对话框,让我们选择一个模板从而快速地开始写作。

在这里假设我将写一本书,所以我选择一个书籍模板,像下面的截图那样在相应的括号中添上标题和作者:

现在就让我来解释一些关于文章结构的事情。我知道这看起来就像编代码,如果你是一位作家而非程序员,那么像下面那样工作或许很是奇怪,但请先容我讲完,我将对此进行解释。
在第一行和第九行之间,我们已经写好了书写整个文档所需的所有基本要素。例如在第一行中,我们可以通过修改 `[a4paper,11pt]` 来定义纸张和字体的大小,在这个方括号中,我们可以添加更多的选项,选项之间以英文逗号来分隔。
在第二行和第四行之间,我们可以看到一些条目,它们都以 `\userpackage` 打头,紧接着的是用方括号包裹的选项和用括号包裹的命令。这些命令都是一些增强宏包,LaTeXila 默认已经安装它们到我们的系统上了,并且在大多数模板中都将使用它们。需要特别注意的是字体编码,字符编码和字体的类型。
紧接着让我们看看 `\maketitle` 这一行,这里我们可以添加一个单独的标题页,且默认情况下标题的内容将被放置在第一页的顶部。类似的,包含 `\tableofcontents` 的那行将会自动生成书籍的目录。
最后,我们可以自己命名章节的名称,这可以通过在 `\chapter` 后的括号中添加章节名称来实现。第一个章节将会被自动地标记为第一章。你可以在接下来的行中添加内容,一直到下一个以 `\chapter` 开头的新行为止,这些都将是这个章节的内容。新的章节将会被自动地标记为第二章,以此类推。

章节之间还可以用命令 `\section` 来划分为更小的块,甚至还可以使用 `\subsection` 来划分为更小的部分。各个小节和章都将被 `\tableofcontents` 自动检测到,并将使用它们的标题和页码来填充目录的内容。看看下面的截图就可以看到章和小节是如何在你的书中被排版的。

假如你想浏览结构,你可以将左边的工具栏更换到<ruby> “结构” <rt> Structure </rt></ruby>选项,并确保所有的结构与预期相符。在这里,你还可以控制各小节中的任意数据表格和图片。

讲到这里,有人或许想将表格和图片的位置也包含在目录中。要达到此目的,你需要将下面的两行添加到 `\tableofcontents` 之后:
```
\listoffigures
\listoftables
```
最后标志着书籍结束的信号是 `\end{document}`。你的布局应该总是以此为结尾。
### LaTeXila 简单易用,公式齐全
LaTeX 是一个基于命令的文档生成系统,它与使用的编辑器没有多少关联。这里需要强调的是 LaTeXila 提供了一系列强大的工具,使得在你书写报告或书籍时能够节省一些时间和精力。例如对于 LaTex 命令,它提供了自动补全功能,这个功能将在你每次开始输入命令时被激活。

LaTeXila 还集成有基于 gspell 的拼写检测系统,你可以在最上面的“工具”菜单中设定合适的语言。最上面的工具栏里几乎包含了你要用到的所有按钮。从左到右,你可以完成添加章节,交叉引用,调整字符的大小,格式化被选取的部分,添加无序列表和数学函数等等。这些都可以手动地输入,但通过点击相应按钮来完成或许更加方便。
对于生成数学公式,结合侧边栏上的工具栏选项,你只需轻轻一点就可以添加相应的数学符号。点击位于左边的侧边栏中<ruby> “符号” <rt> Symbols </rt></ruby>框,你就可以看到相关的符号分类,例如“关系运算符”,“希腊字母”,“运算符”等等。下面的截图就是一些符号的示例:

这些符号的图形化列表使得公式和数学表达式的生成犹如在公园中散步那样舒适。
### 将 .tex 文件转换为 .rtf 文件
默认情况下,LaTeXila 会将你的文档保存为标准的 `.tex` 文档,而我们可以使用 `.tex` 文档来生成一个<ruby> “富文本” <rt> rich text format </rt></ruby>文档,这些富文本文档可以使用像 LibreOffice 那样的文本编辑器打开。要达到此目的,我们需要安装一个名为 `latex2rtf` 的工具,它在所有的 Linux 发行版本中都可以被获取到。在文本所在的目录打开虚拟终端, 并输入 `latex2rtf 文件名称`,如下所示 :

当然 LaTeXila 也提供了它自己的构建工具,这些工具可以在上面的工具栏或者最上面的面板(构建)中看到。但我向你推荐 latex2rtf 是以防它们在其他的操作系统上出现某些意想不到的问题,比如在我的系统上就不能正常工作。
### 结论
假如上面的介绍激发了你探索 LaTeX 的兴趣,那就再好不过了。我写这篇文章的目的是向新手介绍一款简单易用且适合他们写作的工具。要是 LaTeXila 还带有实时预览的双屏模式的话,它就更加完美了...
---
via: <https://www.howtoforge.com/tutorial/introduction-to-latexila-latex-editor/>
作者:[Bill Toulas](https://www.howtoforge.com/tutorial/introduction-to-latexila-latex-editor/) 译者:[FSSlc](https://github.com/FSSlc) 校对:[jasminepeng](https://github.com/jasminepeng)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 200 | OK | # Introduction to LaTeXila - a multi-language LaTeX editor for Linux
LaTeXila is a multi-language LaTeX editor for Linux users who prefer the GTK+ looks. The software is simple, easy to use, adequately powerful and customizable, so if you’re interested in LaTeX you should give this tool a try. In the following quick guide, I will showcase how to get started with LaTeXila and what its main features are. But first...
## Why LaTeX?
So, if I want to create a text document, why wouldn’t I simply use the standard LibreOffice or Abiword tools? The answer is because LaTeX editors in general offer more powerful formatting tools than your standard text editor, while the process of writing the content remains simple and pivotal. LaTeX is a document preparation system that is actually meant to simplify the formatting procedures for the most common forms of publishing like books and scientific reports that may contain a lot of mathematical formulas, multi-lingual typesetting elements, cross-references and citations, indexes, bibliographies, etc. While all of these things can actually be done in LibreOffice, they are way easier in LaTeXila while the end result is bound to be of a higher quality if done right.
## Starting work on a new document and setting up the structure
First, we need to create a new file on LaTeXila, and this can be done by clicking on the “New File” icon located on the upper left. This will open a dialog that allows us to select a template and get started quickly.
Let’s suppose that I will write a book so I select the book template, add the title and author in the corresponding brackets as shown in the following screenshot:
Now let me explain a few things about the structure. I know it looks like coding, and if you are a writer and not a coder it may look strange to work like that but bear with me and I’ll explain.
Between the first line and the ninth line, we have all the stuff that define some basic factors for the whole document. In the first line for example, we can define the paper format and the font size by changing the “[a4paper,11pt]” accordingly. More options can be added inside this particular square brackets space separated by commas.
Between lines two and four, we can see entries that start with “\userpackage” followed by the options in square brackets and the command in brackets. These are enhancement packages that LaTeXila has installed by default in our system and uses them by default in most templates. The particular ones concern the font encoding, character encoding, and fonts quality respectively.
Proceeding to the “\maketitle” row, here we can add a separate title page beyond the first one that will be placed on the top by default. Similarly, the row containing the “\tableofcontents” command is for the automatic creation of a table of contents for the book.
Finally, we can name the chapter as we like by adding a title in the brackets next to the “\chapter”. This first chapter will be automatically marked as chapter one. You may add your content in the following lines, and the chapter ends when the next one begins by \chapter again on a new line. This new chapter will be automatically marked as chapter two, and so on.
Chapters can also be separated into smaller chunks by using the command “\section” and then even more with the command “\subsection”. Both sections and chapters should be automatically detected by the “\tableofcontents” command which will use their title and page number. See the following screenshot to correlate the way chapters and sections work for your book.
If you want to get an overview of the structure, you may change the left sidebar to the “Structure” setting and ensure that all is structured as intended. From the same tool, you may control any data tables or images that are placed in each section.
Talking about these, some people want to include the location of tables and images into their table of contents. To do this, you may add the following lines below the “\tableofcontents”:
\listoffigures
\listoftables
The final command that signifies the end of the book is the “\end{document}” so your structure must always end with this.
## LaTeXila ease of use and mathematics
While LaTeX is a document creation system based on commands that are independent of the editor one uses, it is important to note that LaTeXila offers a set of helpful tools that will save you time and effort while writing your report or book. For example, there’s an auto-completion function for LaTeX commands as that is conveniently activated every time you start typing a command.
There’s an integrated spell checking system based on gspell that you may set to the right language from the “Tools” menu on the top bar, and there’s the top toolbar that contains buttons for almost anything that you’ll need. From left to right, you can add chapters and parts, add cross-references, fiddle with the character size and styling for a selected part, add bullet lists, and mathematical functions. These can be done manually, but it is always nicer to have them one click away instead.
For the creation of the mathematical formulas, you can use a combination of the toolbar options with the sidebar characters that are added with a simple click. Just select the “Symbols” in the left sidebar and you’ll find the relevant categories of “Relations”, “Greek symbols”, “Operators” etc. See the following screenshot as an example of what can be done:
These graphical lists of symbols really make the creation of formulas and mathematical expressions a walk in the park.
## From .tex to .rtf
By default, LaTeXila saves your work in the standard “.tex” format which we can use to build a “rich text format” document that we can open with a word editor like LibreOffice. To do this, we need to install a package named “latex2rtf” which is available in all distributions. We then hop into the file destination, open a terminal there and type “latex2rtf filename” as shown:
Of course, LaTeXila offers its own building tools that you can access from the top toolbar or the top panel (Build), but I am giving you latex2rtf in case something goes wrong with the other system which in my case didn’t work.
## Conclusion
If the above sparked your interest to go ahead and discover the power of LaTeX, then good. My intention was to present a tool that is good for newcomers in the sense that it is easy to use and write on. If only LaTeXila had a dual screen mode with a live previewer, and it would be perfect… |
8,348 | Windows 赢了桌面,而 Linux 赢得整个世界 | http://www.zdnet.com/article/windows-wins-the-desktop-but-linux-takes-the-world/ | 2017-03-29T08:47:00 | [
"Linux",
"Windows",
"慕尼黑"
] | https://linux.cn/article-8348-1.html |
>
> 最坚决推行 Linux 桌面系统项目的城市正在转回 Windows 阵营,但 Linux 的命运已经不再与 PC 休戚相关。
>
>
>

>
> 慕尼黑的 Linux 项目只是开源软件故事中的一小部分
>
>
>
在实施从 Windows 系统迁移到 Linux 系统这一项目接近十年之久后,慕尼黑却突然走上了一条戏剧性的转弯。据说是到 2021 年,该城市的地方议会就会开始用 [Windows 10](http://www.techrepublic.com/article/linux-champion-munich-takes-decisive-step-towards-returning-to-windows/) 替换运行 LiMux (Ubuntu 的一种自定义版本)的 PC 机。
若是回到 15 或者 20 年前,人们可能会争论什么时候 Linux 将会在桌面上取代 Windows。例如,当 Ubuntu 于 2004 年问世时,它是带着 [终结 Windows 的抱负](http://www.techrepublic.com/article/how-mark-shuttleworth-became-the-first-african-in-space-and-launched-a-software-revolution/) 而被设计为标准的桌面操作系统的。
剧透:这一切并没有发生。
桌面上的 Linux 在今天占有约为 2% 的市场,很多人都认为它复杂晦涩。与此同时,Windows 则航行无虞,在 PC 市场笑傲群雄,天下十有其九。但在商业领域中总还有些许 Linux 桌面的身影,它仍被需要——尤其是对开发者和数据科学家而言。
但遗憾的是,它永远也不会成为历史的主流。
慕尼黑的 Linux 项目因其规模之大,引起了许多人的兴趣。几乎没有哪家大型组织会做出从 Windows 到 Linux 的迁移,一些个别的案例像 [法国宪兵队和都灵市](http://www.techrepublic.com/pictures/10-projects-ditching-microsoft-for-open-source-plus-one-switching-back/) 曾有类似之举。然而,[慕尼黑作为模范](http://www.techrepublic.com/article/how-munich-rejected-steve-ballmer-and-kicked-microsoft-out-of-the-city/):在这一事件上的失败将会大大打击那些仍在 [试图用 Linux 将 Windows 取而代之的信徒们](http://www.techrepublic.com/resource-library/whitepapers/why-munich-made-the-switch-from-windows-to-linux-and-may-be-reversing-course/)。
但现实就是如此,绝大多数公司乐于去使用主流的桌面操作系统,因为它具有完整一致、用户友好这种优势。
工作人员所抱怨的问题中,有多少是归咎于 LiMux 软件以及多少是操作系统无端被责备的,已经不可计数。但重要的是,无论慕尼黑最后何去何从,Linux 的命运都已经脱离了桌面 —— 是的,Linux 在多年前就已经输掉了桌面战争。
但这对 Linux 来说无伤大雅,因为它赢得了智能手机之战,并且在云端和物联网之战上也是捷报连连。
你的口袋里,有七八成可能装的是一个 Linux 驱动的智能手机(Android 基于 Linux 内核)。你的身边,更是有成千上万 Linux 驱动的设备,虽然这些也许你甚至都没注意到。
[像树莓派](http://www.zdnet.com/article/hands-on-raspberry-pi-7-inch-touch-display-and-case/)这样运行大量不同类型 Linux 的设备,正在创建一个充满热情和活力的开发者社区,并且提供给初创公司一种低成本的驱动新设备的方法。
大部分公有云也是以这样或那样的形式在 Linux 上运行的;即便是微软,也已经敞开大门,拥抱开源软件。无论你站在哪一个软件平台的立场,不可否认地,开发者和用户拥有更多丰富的可选项是一件好事,对决策来说,抑或是对创新来说,都是如此。
桌面的主导地位早已不再是当年模样了:它现在只是许多计算平台中的一个。事实上,PC 的软件也已经变得越来越不相关,因为更多的应用程序都在与设备和操作系统解耦,驻留在云中。
虽然慕尼黑传奇的曲折变换与 Linux 在桌面上的冒险耐人寻味,但它们却并未给你呈现出一个完整的故事。
*同意? 还是不同意? 在下面添加你的评论来加入讨论吧!*
(题图: Getty Images/iStockphoto)
---
via: <http://www.zdnet.com/article/windows-wins-the-desktop-but-linux-takes-the-world/>
作者:[Steve Ranger](http://www.zdnet.com/meet-the-team/uk/steve-ranger/) 译者:[Meditator-hkx](https://github.com/Meditator-hkx) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
8,349 | 使用开源工具探索气候数据的奥秘 | https://opensource.com/article/17/1/apache-open-climate-workbench | 2017-03-29T17:02:35 | [
"气候",
"OCW"
] | /article-8349-1.html | 
如今你看地球上的任何地方,都可以找到天气变化的证据,每个月,无论是事实还是数据都在向我们诠释一点 —— 全球变暖。
气候学家如是告诫我们,如今的不作为,对于我们的将来可能是致命的。五角大楼的军事战略家[最近警告](https://www.scientificamerican.com/article/military-leaders-urge-trump-to-see-climate-as-a-security-threat/)当选总统的川普,向他申明如果不对气候变化有所动作,可能会造成威胁国家安全的灾难。愈趋减少的的水供应和微薄的降雨量会导致作物歉收,这将迫使大量的移民逃往世界各地,到那些可以维持他们生计的地方去。
遍览 NASA、美国国防部,以及其他机构针对气候的研究成果,我的心中有个疑惑。那就是是否有开源的工具,使对此感兴趣的人们能够自行去探索气候数据的奥秘,并总结出我们自己的结论。我在网上快速的检索了一下,然后找到了 [Open Climate Workbench (开源气候工作台)](https://climate.apache.org/),这是 [Apache 软件基金会](https://www.apache.org/)旗下的一个工程。
Open Climate Workbench (缩写 OCW) 开发该软件,对来自 [<ruby> 地球系统网格联盟 <rt> Earth System Grid Federation </rt></ruby>](http://esgf.llnl.gov/)(缩写 ESGF)、[<ruby> 协调区域气候降尺度实验 <rt> Coordinated Regional Climate Downscaling Experiment </rt></ruby>](http://www.cordex.org/)(缩写 CORDEX)、美国全球变化研究项目的[<ruby> 国家气候研究 <rt> National Climate Assessment </rt></ruby>](http://nca2014.globalchange.gov/)、[<ruby> 北美区域气候评估计划 <rt> North American Regional Climate Assessment Program </rt></ruby>](http://www.narccap.ucar.edu/),以及 NASA、NOAA 和其他组织或机构的数据进行气候模型评价。
你可下载 OCW 的 [tar 包](http://climate.apache.org/downloads.html) 并将它安装到满足其[条件](http://climate.apache.org/downloads.html#prerequsites)的 Linux 电脑上。也可以使用 Vagrant 或者 VirtualBox 将 OCW 安装到虚拟机中,详见 OCW 的[虚拟机指南](https://cwiki.apache.org/confluence/display/CLIMATE/OCW+VM+-+A+Self+Contained+OCW+Environment)。
个人觉得想要了解 OCW 是如何工作的,最便捷的方式就是到 <ruby> 区域气候模式评价系统 <rt> Regional Climate Model Evaluation System </rt></ruby> (缩写 RCMES),下载一个[虚拟机镜像](https://rcmes.jpl.nasa.gov/RCMES_Turtorial_data/RCMES_June09-2016.ova)。
从 RCMES 的网站上看,他们旨在通过为一系列广泛而全面的观测(例如,卫星观测,重新分析,现场观测)和建模资源(例如,[ESGF](http://esgf.org/) 上的 [CMIP](http://cmip-pcmdi.llnl.gov/) 和 [CORDEX](http://www.cordex.org/))提供标准化的访问,以及常规分析和可视化任务的工具(例如,OCW),来促进气候和地球系统模型的区域规模评估。
你需要在宿主机上安装 VirtualBox 和 Vagrant。通过它们,你就能看到一个超赞的 OCW 作业示例。RCMES 为下载、导入、运行虚拟机提供了[详细的说明](https://rcmes.jpl.nasa.gov/content/running-rcmes-virtual-machine)。当你的虚拟机开始工作时,你可以用以下身份登陆。
**用户名:vagrant,密码:vagrant。**

*RCMES 数据样图*
RCMES 网页上的[教程](https://rcmes.jpl.nasa.gov/content/tutorials-overview)能帮助你迅速上手该软件。他们的[社区](http://climate.apache.org/community/get-involved.html)十分活跃,而且在寻找更多的[开发者](https://cwiki.apache.org/confluence/display/CLIMATE/Developer+Getting+Started+Guide)。 你也可以订阅他们[邮件列表](http://climate.apache.org/community/mailing-lists.html)。
该工程的[源代码](https://github.com/apache/climate)部署在 GitHub 上,遵寻 Apache License, Version 2.0。
(题图源自: [Flickr user: theaucitron](https://www.flickr.com/photos/theaucitron/5810163712/in/photolist-5p9nh3-6EkSKG-6EgGEF-9hYBcr-abCSpq-9zbjDz-4PVqwm-9RqBfq-abA2T4-4nXfwv-9RQkdN-dmjSdA-84o2ER-abA2Wp-ehyhPC-7oFYrc-4nvqBz-csMQXb-nRegFf-ntS23C-nXRyaB-6Xw3Mq-cRMaCq-b6wkkP-7u8sVQ-yqcg-6fTmk7-bzm3vU-6Xw3vL-6EkzCQ-d3W8PG-5MoveP-oMWsyY-jtMME6-XEMwS-2SeRXT-d2hjzJ-p2ZZVZ-7oFYoX-84r6Mo-cCizvm-gnnsg5-77YfPx-iDjqK-8gszbW-6MUZEZ-dhtwtk-gmpTob-6TBJ8p-mWQaAC/) (CC BY-SA 2.0))
---
作者简介:
Don Watkins(唐 沃特金斯) - 教育家,教育技术专家,企业家,开源支持者。教育心理学硕士,Linux 系统管理员,CCNA,使用 Virtual Box 实现虚拟化。twitter 关注 @Don\_Watkins。
---
via: <https://opensource.com/article/17/1/apache-open-climate-workbench>
作者:[Don Watkins](https://opensource.com/users/don-watkins) 译者:[martin2011qi](https://github.com/martin2011qi) 校对:[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,350 | 如何在 Ubuntu 以及 Debian 中安装 DHCP 服务器 | http://www.tecmint.com/install-dhcp-server-in-ubuntu-debian/ | 2017-03-29T17:14:59 | [
"DHCP"
] | https://linux.cn/article-8350-1.html | **动态主机配置协议(DHCP)** 是一种用于使主机能够从服务器自动分配 IP 地址和相关的网络配置的网络协议。
DHCP 服务器分配给 DHCP 客户端的 IP 地址处于“租用”状态,租用时间通常取决于客户端计算机要求连接的时间或 DHCP 服务器配置的时间。

#### DHCP 如何工作?
以下是 DHCP 实际工作原理的简要说明:
* 一旦客户端(配置为使用 DHCP 的机器)连接到网络后,它会向 DHCP 服务器发送 **DHCPDISCOVER** 数据包。
* 当 DHCP 服务器收到 **DHCPDISCOVER** 请求报文后会使用 **DHCPOFFER** 包进行回复。
* 然后客户端获取到 **DHCPOFFER** 数据包,并向服务器发送一个 **DHCPREQUEST** 包,表示它已准备好接收 **DHCPOFFER** 包中提供的网络配置信息。
* 最后,DHCP 服务器从客户端收到 **DHCPREQUEST** 报文后,发送 **DHCPACK** 报文,表示现在允许客户端使用分配给它的 IP 地址。
在本文中,我们将介绍如何在 Ubuntu/Debian Linux 中设置 DHCP 服务器,我们将使用 [sudo 命令](https://linux.cn/tag-sudo.html)来运行所有命令,以获得 root 用户权限。
### 测试环境设置
在这步中我们会使用如下的测试环境。
* DHCP Server - Ubuntu 16.04
* DHCP Clients - CentOS 7 and Fedora 25
### 步骤 1:在 Ubuntu 中安装 DHCP 服务器
1、 运行下面的命令来安装 DHCP 服务器包,也就是 **dhcp3-server**。
```
$ sudo apt install isc-dhcp-server
```
2、 安装完成后,编辑 `/etc/default/isc-dhcp-server` 使用 `INTERFACES` 选项定义 DHCPD 响应 DHCP 请求所使用的接口。
比如,如果你想让 DHCPD 守护进程监听 `eth0`,按如下设置:
```
INTERFACES="eth0"
```
同样记得为上面的接口[配置静态地址](http://www.tecmint.com/set-add-static-ip-address-in-linux/)。
### 步骤 2:在 Ubuntu 中配置 DHCP 服务器
3、 DHCP 配置的主文件是 `/etc/dhcp/dhcpd.conf`, 你必须填写会发送到客户端的所有网络信息。
并且 DHCP 配置中定义了两种不同的声明,它们是:
* `parameters` - 指定如何执行任务、是否执行任务,还有指定要发送给 DHCP 客户端的网络配置选项。
* `declarations` - 定义网络拓扑、指定客户端、为客户端提供地址,或将一组参数应用于一组声明。
4、 现在打开并修改主文件,定义 DHCP 服务器选项:
```
$ sudo vi /etc/dhcp/dhcpd.conf
```
在文件顶部设置以下全局参数,它们将应用于下面的所有声明(请指定适用于你情况的值):
```
option domain-name "tecmint.lan";
option domain-name-servers ns1.tecmint.lan, ns2.tecmint.lan;
default-lease-time 3600;
max-lease-time 7200;
authoritative;
```
5、 现在定义一个子网,这里我们为 `192.168.10.0/24` 局域网设置 DHCP (请使用适用你情况的参数):
```
subnet 192.168.10.0 netmask 255.255.255.0 {
option routers 192.168.10.1;
option subnet-mask 255.255.255.0;
option domain-search "tecmint.lan";
option domain-name-servers 192.168.10.1;
range 192.168.10.10 192.168.10.100;
range 192.168.10.110 192.168.10.200;
}
```
### 步骤 3:在 DHCP 客户端上配置静态地址
6、 要给特定的客户机分配一个固定的(静态)的 IP,你需要显式将这台机器的 MAC 地址以及静态分配的地址添加到下面这部分。
```
host centos-node {
hardware ethernet 00:f0:m4:6y:89:0g;
fixed-address 192.168.10.105;
}
host fedora-node {
hardware ethernet 00:4g:8h:13:8h:3a;
fixed-address 192.168.10.106;
}
```
保存并关闭文件。
7、 接下来,启动 DHCP 服务,并让它下次开机自启动,如下所示:
```
------------ SystemD ------------
$ sudo systemctl start isc-dhcp-server.service
$ sudo systemctl enable isc-dhcp-server.service
------------ SysVinit ------------
$ sudo service isc-dhcp-server.service start
$ sudo service isc-dhcp-server.service enable
```
8、 接下来不要忘记允许 DHCP 服务(DHCP 守护进程监听 67 UDP 端口)的防火墙权限:
```
$ sudo ufw allow 67/udp
$ sudo ufw reload
$ sudo ufw show
```
### 步骤 4:配置 DHCP 客户端
9、 此时,你可以将客户端计算机配置为自动从 DHCP 服务器接收 IP 地址。
登录到客户端并编辑以太网接口的配置文件(注意接口名称/号码):
```
$ sudo vi /etc/network/interfaces
```
定义如下选项:
```
auto eth0
iface eth0 inet dhcp
```
保存文件并退出。重启网络服务(或重启系统):
```
------------ SystemD ------------
$ sudo systemctl restart networking
------------ SysVinit ------------
$ sudo service networking restart
```
另外你也可以使用 GUI 来在进行设置,如截图所示(在 Fedora 25 桌面中)设置将方式设为自动(DHCP)。

*在 Fedora 中设置 DHCP 网络*
此时,如果所有设置完成了,你的客户端应该可以自动从 DHCP 服务器接收 IP 地址了。
就是这样了!在本篇教程中,我们向你展示了如何在 Ubuntu/Debian 设置 DHCP 服务器。在反馈栏中分享你的想法。如果你正在使用基于 Fedora 的发行版,请阅读如何在 CentOS/RHEL 中设置 DHCP 服务器。
---
作者简介:
Aaron Kili 是 Linux 和 F.O.S.S 爱好者,将来的 Linux SysAdmin 和 web 开发人员,目前是 TecMint 的内容创建者,他喜欢用电脑工作,并坚信分享知识。
---
via: <http://www.tecmint.com/install-dhcp-server-in-ubuntu-debian/>
作者:[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,356 | 如何在 CentOS 7 中在 HHVM 和 Nginx 之上安装 WordPress | https://www.howtoforge.com/tutorial/how-to-install-wordpress-with-hhvm-and-nginx-on-centos-7/ | 2017-03-30T15:40:48 | [
"WordPress",
"HHVM",
"PHP",
"SELinux"
] | https://linux.cn/article-8356-1.html | HHVM (HipHop Virtual Machine) 是一个用于执行以 PHP 和 Hack 语言编写的代码的虚拟环境。它是由 Facebook 开发的,提供了当前 PHP 7 的大多数功能。要在你的服务器上运行 HHVM,你需要使用 FastCGI 来将 HHVM 和 Nginx 或 Apache 衔接起来,或者你也可以使用 HHVM 中的内置 Web 服务器 Proxygen。

在这篇教程中,我将展示给你如何在 Nginx Web 服务器的 HHVM 上安装 WordPress。这里我使用 CentOS 7 作为操作系统,所以你需要懂一点 CentOS 操作的基础。
**先决条件**
* CentOS 7 - 64位
* Root 权限
### 步骤 1 - 配置 SELinux 并添加 EPEL 仓库
在本教程中,我们将使用 SELinux 的强制模式,所以我们需要在系统上安装一个 SELinux 管理工具。这里我们使用 `setools` 和 `setrobleshoot` 来管理 SELinux 的各项配置。
CentOS 7 已经默认启用 SELinux,我们可以通过以下命令来确认:
```
# sestatus
# getenforce
```

如图,你能够看到,SELinux 已经开启了强制模式。
接下来就是使用 `yum` 来安装 `setools` 和 `setroubleshoot` 了。
```
# yum -y install setroubleshoot setools net-tools
```
安装好这两个后,再安装 EPEL 仓库。
```
# yum -y install epel-release
```
### 步骤 2 - 安装 Nginx
Nginx (发音:engine-x) 是一个高性能、低内存消耗的轻量级 Web 服务器软件。在 CentOS 中可以使用 `yum` 命令来安装 Nginx 包。确保你以 root 用户登录系统。
使用 `yum` 命令从 CentOS 仓库中安装 nginx。
```
# yum -y install nginx
```
现在可以使用 `systemctl` 命令来启动 Nginx,同时将其设置为跟随系统启动。
```
# systemctl start nginx
# systemctl enable nginx
```
为确保 Nginx 已经正确运行于服务器中,在浏览器上输入服务器的 IP,或者如下使用 `curl` 命令检查显示结果。
```
# curl 192.168.1.110
```
我这里使用浏览器来验证。

### 步骤 3 - 安装并配置 MariaDB
MariaDB 是由原 MySQL 开发者 Monty Widenius 开发的一款开源数据库软件,它由 MySQL 分支而来,与 MySQL 的主要功能保持一致。在这一步中,我们要安装 MariaDB 数据库并为之配置好 root 密码,然后再为所要安装的 WordPress 创建一个新的数据库和用户。
安装 mariadb 和 mariadb-server:
```
# yum -y install mariadb mariadb-server
```
启动 MariaDB 并添加为服务,以便随系统启动。
```
# systemctl start mariadb
# systemctl enable mariadb
```
现在 MariaDB 已经启动了,还需要为 mariadb/mysql 数据库配置 root 用户密码。输入以下命令来设置 MariaDB root 密码。
```
# mysql_secure_installation
```
提示设置 root 用户密码时,输入新密码进行设置:
```
Set root password? [Y/n] Y
New password:
Re-enter new password:
Remove anonymous users? [Y/n] Y
... Success!
Disallow root login remotely? [Y/n] Y
... Success!
Remove test database and access to it? [Y/n] Y
Reload privilege tables now? [Y/n] Y
... Success!
```
这样就设置好了 MariaDB 的 root 密码。现在登录到 MariaDB/MySQL shell 并为 WordPress 的安装创建一个新数据库 `wordpressdb` 和新用户 `wpuser`,密码设置为 `wpuser@`。为你的设置选用一个安全的密码。
登录到 MariaDB/MySQL shell:
```
# mysql -u root -p
```
接着输入你刚刚设置的 root 用户密码。
创建数据库和用户:
```
MariaDB [(none)]> create database wordpressdb;
MariaDB [(none)]> create user wpuser@localhost identified by 'wpuser@';
MariaDB [(none)]> grant all privileges on wordpressdb.* to wpuser@localhost identified by 'wpuser@';
MariaDB [(none)]> flush privileges;
MariaDB [(none)]> \q
```

现在安装好了 MariaDB,并为 WordPress 创建好了数据库。
### 步骤 4 - 安装 HHVM
对于 HHVM,我们需要安装大量的依赖项。作为选择,你可以从 GitHub 下载 HHVM 的源码来编译安装,也可以从网络上获取预编译的包进行安装。在本教程中,我使用的是预编译的安装包。
为 HHVM 安装依赖项:
```
# yum -y install cpp gcc-c++ cmake git psmisc {binutils,boost,jemalloc,numactl}-devel \
> {ImageMagick,sqlite,tbb,bzip2,openldap,readline,elfutils-libelf,gmp,lz4,pcre}-devel \
> lib{xslt,event,yaml,vpx,png,zip,icu,mcrypt,memcached,cap,dwarf}-devel \
> {unixODBC,expat,mariadb}-devel lib{edit,curl,xml2,xslt}-devel \
> glog-devel oniguruma-devel ocaml gperf enca libjpeg-turbo-devel openssl-devel \
> mariadb mariadb-server libc-client make
```
然后是使用 `rpm` 安装从 [HHVM 预编译包镜像站点](http://mirrors.linuxeye.com/hhvm-repo/7/x86_64/) 下载的 HHVM 预编译包。
```
# rpm -Uvh http://mirrors.linuxeye.com/hhvm-repo/7/x86_64/hhvm-3.15.2-1.el7.centos.x86_64.rpm
# ln -s /usr/local/bin/hhvm /bin/hhvm
```
安装好 HHVM 之后使用如下命令按了验证:
```
# hhvm --version
```
为了能使用 PHP 命令,可以把 `hhvm` 命令设置为 `php`。这样在 shell 中输入 `php` 命令的时候,你会看到和输入 `hhvm` 命令一样的结果。
```
# sudo update-alternatives --install /usr/bin/php php /usr/bin/hhvm 60
# php --version
```

### 步骤 5 - 配置 HHVM
这一步中,我们来配置 HHVM 以系统服务来运行。我们不通过端口这种常规的方式来运行它,而是选择使用 unix socket 文件的方式,这样运行的更快速一点。
进入 systemd 配置目录,并创建一个 `hhvm.service` 文件。
```
# cd /etc/systemd/system/
# vim hhvm.service
```
复制粘贴如下配置到文件中去。
```
[Unit]
Description=HHVM HipHop Virtual Machine (FCGI)
After=network.target nginx.service mariadb.service
[Service]
ExecStart=/usr/local/bin/hhvm --config /etc/hhvm/server.ini --user nginx --mode daemon -vServer.Type=fastcgi -vServer.FileSocket=/var/run/hhvm/hhvm.sock
[Install]
WantedBy=multi-user.target
```
保存文件退出 vim。
接下来,进入 `hhvm` 目录并编辑 `server.ini` 文件。
```
# cd /etc/hhvm/
# vim server.ini
```
将第 7 行 `hhvm.server.port` 替换为 unix socket,如下:
```
hhvm.server.file_socket = /var/run/hhvm/hhvm.sock
```
保存文件并退出编辑器。
我们已在 hhvm 服务文件中定义了 hhvm 以 `nginx` 用户身份运行,所以还需要把 socket 文件目录的属主变更为 `nginx`。然后我们还必须在 SELinux 中修改 hhvm 目录的权限上下文以便让它可以访问这个 socket 文件。
```
# chown -R nginx:nginx /var/run/hhvm/
# semanage fcontext -a -t httpd_var_run_t "/var/run/hhvm(/.*)?"
# restorecon -Rv /var/run/hhvm
```
服务器重启之后,hhvm 将不能运行,因为没有存储 socket 文件的目录,所有还必须在启动的时候自动创建一个。
使用 vim 编辑 `rc.local` 文件。
```
# vim /etc/rc.local
```
将以下配置粘贴到文件末行。
```
# mkdir -p /var/run/hhvm/
# chown -R nginx:nginx /var/run/hhvm/
# semanage fcontext -a -t httpd_var_run_t "/var/run/hhvm(/.*)?"
# restorecon -Rv /var/run/hhvm
```
保存文件并退出 vim。然后给文件赋予执行权限。
```
# chmod +x /etc/rc.local
```
重新加载 systemd 服务,启动 hhvm 并设置为随系统启动。
```
# systemctl daemon-reload
# systemctl start hhvm
# systemctl enable hhvm
```
要确保无误,使用 `netstat` 命令验证 hhvm 运行于 socket 文件。
```
# netstat -pl | grep hhvm
```

### 步骤 6 - 配置 HHVM 和 Nginx
在这个步骤中,我们将配置 HHVM 已让它运行在 Nginx Web 服务中,这需要在 Nginx 目录创建一个 hhvm 的配置文件。
进入 `/etc/nginx` 目录,创建 `hhvm.conf` 文件。
```
# cd /etc/nginx/
# vim hhvm.conf
```
粘贴以下内容到文件中。
```
location ~ \.(hh|php)$ {
root /usr/share/nginx/html;
fastcgi_keep_conn on;
fastcgi_pass unix:/var/run/hhvm/hhvm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
```
然后,保存并退出。
接下来,编辑 `nginx.conf` 文件,添加 hhvm 配置文件到 `include` 行。
```
# vim nginx.conf
```
添加配置到第 57 行的 `server` 指令中。
```
include /etc/nginx/hhvm.conf;
```
保存并退出。
然后修改 SELinux 中关于 hhvm 配置文件的权限上下文。
```
# semanage fcontext -a -t httpd_config_t /etc/nginx/hhvm.conf
# restorecon -v /etc/nginx/hhvm.conf
```
测试 Nginx 配置并重启服务。
```
# nginx -t
# systemctl restart nginx
```
记住确保测试配置没有错误。
### 步骤 7 - 通过 HHVM 和 Nginx 创建虚拟主机
在这一步中,我们要为 Nginx 和 hhvm 创建一个新的虚拟主机配置文件。这里我使用域名 `natsume.co` 来作为例子,你可以使用你主机喜欢的域名,并在配置文件中相应位置以及 WordPress 安装过程中进行替换。
进入 nginx 的 `conf.d` 目录,我们将在该目录存储虚拟主机文件。
```
# cd /etc/nginx/conf.d/
```
使用 vim 创建一个名为 `natsume.conf` 的配置文件。
```
# vim natsume.conf
```
粘贴以下内容到虚拟主机配置文件中。
```
server {
listen 80;
server_name natsume.co;
# note that these lines are originally from the "location /" block
root /var/www/hakase;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ =404;
}
error_page 404 /404.html;
location = /50x.html {
root /var/www/hakase;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/hhvm/hhvm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
```
保存并退出。
在这个虚拟主机配置文件中,我们定义该域名的 Web 根目录为 `/var/www/hakase`。目前该目录还不存在,所有我们要创建它,并变更属主为 nginx 用户和组。
```
# mkdir -p /var/www/hakase
# chown -R nginx:nginx /var/www/hakase
```
接下来,为该文件和目录配置 SELinux 上下文。
```
# semanage fcontext -a -t httpd_config_t "/etc/nginx/conf.d(/.*)?"
# restorecon -Rv /etc/nginx/conf.d
```
最后,测试 nginx 配置文件以确保没有错误后,重启 nginx:
```
# nginx -t
# systemctl restart nginx
```
### 步骤 8 - 安装 WordPress
在步骤 5 的时候,我们已经为 WordPress 配置好了虚拟主机,现在只需要下载 WordPress 和使用我们在步骤 3 的时候创建的数据库和用户来编辑数据库配置就好了。
进入 Web 根目录 `/var/www/hakase` 并使用 Wget 命令下载 WordPress:
```
# cd /var/www/hakase
# wget wordpress.org/latest.tar.gz
```
解压 `latest.tar.gz` 并将 `wordpress` 文件夹中所有的文件和目录移动到当前目录:
```
# tar -xzvf latest.tar.gz
# mv wordpress/* .
```
下一步,复制一份 `wp-config-sample.php` 并更名为 `wp-config.php`,然后使用 vim 进行编辑:
```
# cp wp-config-sample.php wp-config.php
# vim wp-config.php
```
将 `DB_NAME` 设置为 `wordpressdb`、`DB_USER` 设置为 `wpuser` 以及 `DB_PASSWORD` 设置为 `wpuser@`。
```
define('DB_NAME', 'wordpressdb');
define('DB_USER', 'wpuser');
define('DB_PASSWORD', 'wpuser@');
define('DB_HOST', 'localhost');
```
保存并退出。

修改关于 WordPress 目录的 SELinux 上下文。
```
# semanage fcontext -a -t httpd_sys_content_t "/var/www/hakase(/.*)?"
# restorecon -Rv /var/www/hakase
```
现在打开 Web 浏览器,在地址栏输入你之前为 WordPress 设置的域名,我这里是 `natsume.co`。
选择语言并点击<ruby> 继续 <rt> Continue </rt></ruby>。

根据自身要求填写站点标题和描述并点击<ruby> 安装 Wordpress <rt> Install Wordpress </rt></ruby>"。

耐心等待安装完成。你会见到如下页面,点击<ruby> 登录 <rt> Log In </rt></ruby>来登录到管理面板。

输入你设置的管理员用户账号和密码,在此点击<ruby> 登录 <rt> Log In </rt></ruby>。

现在你已经登录到 WordPress 的管理面板了。

Wordpress 的主页:

至此,我们已经在 CentOS 7 上通过 Nginx 和 HHVM 成功安装 Wordpress。
### 参考链接
* <https://www.nginx.com/blog/nginx-se-linux-changes-upgrading-rhel-6-6/>
---
译者简介:
[GHLandy](http://GHLandy.com) —— 划不完粉腮柳眉泣别离。
---
via: <https://www.howtoforge.com/tutorial/how-to-install-wordpress-with-hhvm-and-nginx-on-centos-7/>
作者:[Muhammad Arul](https://www.howtoforge.com/tutorial/how-to-install-wordpress-with-hhvm-and-nginx-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 WordPress with HHVM and Nginx on CentOS 7
HHVM (HipHop Virtual Machine) is an open source virtual machine for executing programs written in PHP and Hack language. HHVM has been developed by Facebook, it provides most features of the current PHP 7 version. To run HHVM on your server, you can use a FastCGI to connect HHVM with a Nginx or Apache web server, or you can use the web server built into HHVM called "Proxygen".
In this tutorial, I will show you how to install WordPress with HHVM and Nginx as web server. I will use CentOS 7 as the operating system, so basic knowledge of CentOS is required.
**Prerequisite**
- CentOS 7 - 64bit
- Root privileges
## Step 1 - Configure SELinux and add the Epel Repository
In this tutorial, we will use SELinux in enforcing mode, so we need the SELinux management tools installed on the system. We will use setools and setrobleshoot to manage SELinux policies.
By default, SELinux is enabled on CentOS 7, We can check that for with command below:
sestatus
getenforce
You can see SELinux is enabled with enforcing mode.
Next, Install setools and setroubleshoot with the yum command.
yum -y install setroubleshoot setools net-tools
When the installation has been completed, you can install the EPEL repository.
yum -y install epel-release
## Step 2 - Install Nginx
Nginx or engine-x is a lightweight web server with high performance and low memory consumption. On CentOS, we can use yum to install the Nginx packages. Make sure you are logged in as root user!
Install nginx with this yum command from the CentOS repository:
yum -y install nginx
Now start Nginx and enable it to be started at boot time with the systemctl command:
systemctl start nginx
systemctl enable nginx
To ensure Nginx is running on our server, visit the server IP address with your browser, or use the curl command as shown below to get the results:
curl 192.168.1.110
I'll cehck it with my web browser here:
## Step 3 - Install and Configure MariaDB
MariaDB is an open source database developed by the original MySQL developer Monty Widenius, it has been forked from the MySQL database but stays compatible with it in its major functions. In this step, we will install MariaDB and configure the root password for the MariaDB database. Then we will create a new database and new user that are required for our WordPress installation.
Install mariadb and mariadb-server:
yum -y install mariadb mariadb-server
Start MariaDB and add the service to be automatically started at boot time:
systemctl start mariadb
systemctl enable mariadb
MariaDB has been started, and now we have to configure the root password for the mariadb/mysql database. Type in the command below to setup the MariaDB root password.
mysql_secure_installation
Type in your new password for the MariaDB root user when requested.
Set root password? [Y/n] Y
New password:
Re-enter new password:
Remove anonymous users? [Y/n] Y
... Success!
Disallow root login remotely? [Y/n] Y
... Success!
Remove test database and access to it? [Y/n] Y
Reload privilege tables now? [Y/n] Y
... Success!
The MariaDB root password has been configured. Now login to the MariaDB/MySQL shell and create a new database **"wordpressdb"** and a new user **"wpuser"** with password **"wpuser@"** for our WordPress installation. Choose a secure password for your installation!
Login to the MariaDB/MySQL shell:
mysql -u root -p
TYPE YOUR PASSWORD
Create a new database and new user:
create database wordpressdb;
create user wpuser@localhost identified by 'wpuser@';
grant all privileges on wordpressdb.* to wpuser@localhost identified by 'wpuser@';
flush privileges;
\q
MariaDB has been installed and the new database for our WordPress installation has been created.
## Step 4 - Install HHVM
For the HHVM installation, we need to install many dependencies. We can install HHVM from source by downloading the source from github, or installing prebuilt packages that are available on the internet. In this tutorial, I will install HHVM from prebuilt packages.
Install the dependencies for the HHVM installation
yum -y install cpp gcc-c++ cmake git psmisc {binutils,boost,jemalloc,numactl}-devel \
{ImageMagick,sqlite,tbb,bzip2,openldap,readline,elfutils-libelf,gmp,lz4,pcre}-devel \
lib{xslt,event,yaml,vpx,png,zip,icu,mcrypt,memcached,cap,dwarf}-devel \
{unixODBC,expat,mariadb}-devel lib{edit,curl,xml2,xslt}-devel \
glog-devel oniguruma-devel ocaml gperf enca libjpeg-turbo-devel openssl-devel \
mariadb mariadb-server libc-client make
Then install the HHVM prebuilt packages from [this site](http://mirrors.linuxeye.com/hhvm-repo/7/x86_64/) with the rpm command.
rpm -Uvh http://mirrors.linuxeye.com/hhvm-repo/7/x86_64/hhvm-3.15.2-1.el7.centos.x86_64.rpm
ln -s /usr/local/bin/hhvm /bin/hhvm
HHVM has been installed, check it with the command below:
hhvm --version
In order to use the php command, we can set the hhvm command as php. So when you type 'php' on the shell, you will see the same result as from the hhvm command.
sudo update-alternatives --install /usr/bin/php php /usr/bin/hhvm 60
php --version
## Step 5 - Configure HHVM
In this step, we will configure HHVM. We will run hhvm as a systemd service. Instead of running it on a system port, we will run hhvm on a unix socket file which is faster.
Go to the systemd directory and create the hhvm.service file.
cd /etc/systemd/system/
vim hhvm.service
Paste the service configuration belowinto that file.
[Unit]
Description=HHVM HipHop Virtual Machine (FCGI)
After=network.target nginx.service mariadb.service
[Service]
ExecStart=/usr/local/bin/hhvm --config /etc/hhvm/server.ini --user nginx --mode daemon -vServer.Type=fastcgi -vServer.FileSocket=/var/run/hhvm/hhvm.sock
[Install]
WantedBy=multi-user.target
Save the file and exit vim.
Next, go to the hhvm directory and edit the server.ini file.
cd /etc/hhvm/
vim server.ini
Replace the hhvm.server.port on line 7 with unix socket configuration below:
hhvm.server.file_socket = /var/run/hhvm/hhvm.sock
Save the file and exit th editor.
In the hhvm service file, we've defined that hhvm is running under the 'nginx' user, so we must change the owner of the socket file directory to the 'nginx' user. Then we must change the SELinux context of the hhvm directoryto allow access to the socket file.
chown -R nginx:nginx /var/run/hhvm/
semanage fcontext -a -t httpd_var_run_t "/var/run/hhvm(/.*)?"
restorecon -Rv /var/run/hhvm
After rebooting the server, hhvm will not be running because there is no directory for the socket file, so we must create it automatically at the boot time.
Edit the rc.local file with vim.
vim /etc/rc.local
Paste configuration below to the end of line.
mkdir -p /var/run/hhvm/
chown -R nginx:nginx /var/run/hhvm/
semanage fcontext -a -t httpd_var_run_t "/var/run/hhvm(/.*)?"
restorecon -Rv /var/run/hhvm
Save the file and exit vim. Make the file executable.
chmod +x /etc/rc.local
Reload the systemd service, start hhvm and add it to be started at boot time.
systemctl daemon-reload
systemctl start hhvm
systemctl enable hhvm
Make sure that there is no error. Check that hhvm is running under the socket file with the netstat command.
netstat -pl | grep hhvm
## Step 6 - Configure HHVM and Nginx
In this step, we will configure HHVM to run with the Nginx web server. We need to create a new hhvm configuration file in the Nginx directory.
Go to the /etc/nginx directory and create a hhvm.conf file.
cd /etc/nginx/
vim hhvm.conf
Paste the configuration below:
location ~ \.(hh|php)$ {
root /usr/share/nginx/html;
fastcgi_keep_conn on;
fastcgi_pass unix:/var/run/hhvm/hhvm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
Save and exit.
Next, edit the nginx.conf file and add the hhvm configuration include line.
vim nginx.conf
Add the configuration to the server directive line 57.
include /etc/nginx/hhvm.conf;
Save and exit.
Then change the SELinux context of the hhvm configuration file.
semanage fcontext -a -t httpd_config_t /etc/nginx/hhvm.conf
restorecon -v /etc/nginx/hhvm.conf
Test the Nginx configuration and restart the service.
nginx -t
systemctl restart nginx
Make sure there is no error.
## Step 7 - Create a Virtual Host with HHVM and Nginx
In this step, we will create a new virtual host configuration with Nginx and hhvm. I will use the domain name **"natsume.co"** for this example. Please use your own domain name and replace it in the configuration files and WordPress installation wherever it appears.
Go to the nginx conf.d directory where we will store virtual host file:
cd /etc/nginx/conf.d/
Create the new configuration "natsume.conf" with vim:
vim natsume.conf
Paste the virtual host configuration below:
server { listen 80; server_name natsume.co; # note that these lines are originally from the "location /" block root /var/www/hakase; index index.php index.html index.htm; location / { try_files $uri $uri/ =404; } error_page 404 /404.html; location = /50x.html { root /var/www/hakase; } location ~ \.php$ { try_files $uri =404; fastcgi_pass unix:/var/run/hhvm/hhvm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } }
Save and exit.
In our virtual host configuration, we've defined the web root directory for the domain name to be the "/var/www/hakase" directory. That directory does not exist yet, so we have to create it and change the ownership to the nginx user and group.
mkdir -p /var/www/hakase
chown -R nginx:nginx /var/www/hakase
Next, configure the SELinux context for the file and directory.
semanage fcontext -a -t httpd_config_t "/etc/nginx/conf.d(/.*)?"
restorecon -Rv /etc/nginx/conf.d
Finally, test the nginx configuration to ensure there is no error, then restart nginx:
nginx -t
systemctl restart nginx
## Step 8 - Install WordPress
In step 5 we've created the virtual host configuration for our WordPress installation. Now we just have to download WordPress and edit the database configuration by using the database and user that we've created in step 3.
Go to the web root directory "/var/www/hakase" and download WordPress with the wget command:
cd /var/www/hakase
wget wordpress.org/latest.tar.gz
Extract "latest.tar.gz" and move all WordPress files and directories to the current directory:
tar -xzvf latest.tar.gz
mv wordpress/* .
Next, copy "wp-config-sample.php" file to "wp-config.php" and edit it with vim:
cp wp-config-sample.php wp-config.php
vim wp-config.php
Set DB_NAME to **"wordpressdb"**, DB_USER to **"wpuser"** and DB_PASSWORD to **"wpuser@"**.
define('DB_NAME', 'wordpressdb'); define('DB_USER', 'wpuser'); define('DB_PASSWORD', 'wpuser@'); define('DB_HOST', 'localhost');
Save and exit.
Change the SELinux context for the WordPress directory.
semanage fcontext -a -t httpd_sys_content_t "/var/www/hakase(/.*)?"
restorecon -Rv /var/www/hakase
Now open a web browser and type in the domain name of your wordpress domain into the address bar, mine is "natsume.co".
Choose English language and click on '*Continue*'.
Fill in the site title and description with your info and click "Install Wordpress".
Wait until the installation is finished. You will see the page below, click on "Log In" to log in to the WordPress admin dashboard:
Type in your admin user and password, then click "Log In" again.
Now you're on the WordPress admin dashboard.
Wordpress Home Page.
Wordpress with Nginx and HHVM on CentOS 7 has been installed successfully. |
8,358 | Samba 系列(五):将另一台 Ubuntu DC 服务器加入到 Samba DC 实现双域控主机模式 | http://www.tecmint.com/join-additional-ubuntu-dc-to-samba4-ad-dc-failover-replication/ | 2017-03-31T09:28:00 | [
"Samba"
] | https://linux.cn/article-8358-1.html | 这篇文章将讲解如何使用 **Ubuntu 16.04** 服务器版系统来创建第二台 **Samba4** 域控制器,并将其加入到已创建好的 **Samba AD DC** 林环境中,以便为一些关键的 AD DC 服务提供负载均衡及故障切换功能,尤其是为那些重要的服务,比如 DNS 服务和使用 SAM 数据库的 AD DC LDAP 模式。

### 需求
这篇文章是 **Samba4 AD DC** 系列的第**五**篇,前边几篇如下:
1、[在 Ubuntu 系统上使用 Samba4 来创建活动目录架构](/article-8065-1.html)
2、[在 Linux 命令行下管理 Samba4 AD 架构](/article-8070-1.html)
3、[使用 Windows 10 的 RSAT 工具来管理 Samba4 活动目录架构](/article-8097-1.html)
4、[在 Windows 下管理 Samba4 AD 域管制器 DNS 和组策略](/article-8258-1.html)
### 第一步:为设置 Samba4 进行初始化配置
1、在开始把第二个 DC 服务器加入到 **Samba4 AD DC** 域环境之前,你需要注意一些初始化设置信息,首先,确保这个新系统的**主机名**包含描述性名称。
假设第一个域服务器的主机名叫做 `adc1` ,你可以把第二个域服务器命名为 `adc2`,以保持域控制器名称的一致性。
执行下面的命令来修改系统**主机名**:
```
# hostnamectl set-hostname adc2
```
或者你也可以手动编辑 `/etc/hostname` 文件,在新的一行输入你想设置的主机名。
```
# nano /etc/hostname
```
这里添加主机名。
```
adc2
```
2、下一步,打开本地系统解析文件并添加一个条目,包含主域控制器的 IP 地址和 FQDN 名称。如下图所示:
在这篇教程中,主域控服务器的主机名为 `adc1.tecmint.lan` ,其对应的 IP 地址为 192.168.1.254 。
```
# nano /etc/hosts
```
添加如下行:
```
IP_of_main_DC FQDN_of_main_DC short_name_of_main_DC
```

*为 Samba4 AD DC 服务器设置主机名*
3、下一步,打开 `/etc/network/interfaces` 配置文件并设置一个静态 IP 地址,如下图所示:
注意 `dns-nameservers` 和 `dns-search` 这两个参数的值。为了使 DNS 解析正常工作,需要把这两个值设置成主 Samba4 AD DC 服务器的 IP 地址和域名。
重启网卡服务以让修改的配置生效。检查 `/etc/resolv.conf` 文件,确保该网卡上配置的这两个 DNS 的值已更新到这个文件。
```
# nano /etc/network/interfaces
```
编辑并替换你自定义的 IP 设置:
```
auto ens33
iface ens33 inet static
address 192.168.1.253
netmask 255.255.255.0
brodcast 192.168.1.1
gateway 192.168.1.1
dns-nameservers 192.168.1.254
dns-search tecmint.lan
```
重启网卡服务并确认生效。
```
# systemctl restart networking.service
# cat /etc/resolv.conf
```

*配置 Samba4 AD 服务器的 DNS*
当你通过简写名称(用于构建 FQDN 名)查询主机名时, `dns-search` 值将会自动把域名添加上。
4、为了测试 DNS 解析是否正常,使用一系列 ping 命令测试,命令后分别为简写名, FQDN 名和域名,如下图所示:
在所有测试用例中,**Samba4 AD DC DNS** 服务器都应该返回主域控服务器的 IP 地址。

*验证 Samba4 AD 环境 DNS 解析是否正常*
5、最后你需要注意的是确保这个主机跟域控服务器时间同步。你可以通过下面的命令在系统上安装 **NTP** 客户端工具来实现时间同步功能:
```
# apt-get install ntpdate
```
6、假设你想手动强制本地服务器与 **samba4 AD DC** 服务器时间同步,使用 `ntpdate` 命令加上主域控服务器的主机名,如下所示:
```
# ntpdate adc1
```

*与 Samba4 AD 服务器进行时间同步*
### 第 2 步:安装 Samba4 必须的依赖包
7、为了让 **Ubuntu 16.04** 系统加入到你的域中,你需要通过下面的命令从 Ubuntu 官方软件库中安装 **Samba4 套件、 Kerberos 客户端** 和其它一些重要的软件包以便将来使用:
```
# apt-get install samba krb5-user krb5-config winbind libpam-winbind libnss-winbind
```

*在 Ubuntu 系统中安装 Samba4*
8、在安装的过程中,你需要提供 Kerberos 域名。输入大写的域名然后按回车键完成安装过程。

*为 Samba4 配置 Kerberos 认证*
9、所有依赖包安装完成后,通过使用 `kinit` 命令为域管理员请求一个 Kerberos 票据以验证设置是否正确。使用 `klist` 命令来列出已授权的 kerberos 票据信息。
```
# kinit domain-admin-user@YOUR_DOMAIN.TLD
# klist
```

*在 Samba4 域环境中验证 Kerberos*
### 第 3 步:以域控制器的身份加入到 Samba4 AD DC
10、在把你的机器集成到 **Samba4 DC** 环境之前,先把系统中所有运行着的 Samba4 服务停止,并且重命名默认的 Samba 配置文件以便从头开始。在域控制器配置的过程中, Samba 将会创建一个新的配置文件。
```
# systemctl stop samba-ad-dc smbd nmbd winbind
# mv /etc/samba/smb.conf /etc/samba/smb.conf.initial
```
11、在准备加入域前,先启动 **samba-ad-dc** 服务,之后使用域管理员账号运行 `samba-tool` 命令将服务器加入到域。
```
# samba-tool domain join your_domain -U "your_domain_admin"
```
加入域过程部分截图:
```
# samba-tool domain join tecmint.lan DC -U "tecmint_user"
```
输出示例:
```
Finding a writeable DC for domain 'tecmint.lan'
Found DC adc1.tecmint.lan
Password for [WORKGROUP\tecmint_user]:
workgroup is TECMINT
realm is tecmint.lan
checking sAMAccountName
Deleted CN=ADC2,CN=Computers,DC=tecmint,DC=lan
Adding CN=ADC2,OU=Domain Controllers,DC=tecmint,DC=lan
Adding CN=ADC2,CN=Servers,CN=Default-First-Site-Name,CN=Sites,CN=Configuration,DC=tecmint,DC=lan
Adding CN=NTDS Settings,CN=ADC2,CN=Servers,CN=Default-First-Site-Name,CN=Sites,CN=Configuration,DC=tecmint,DC=lan
Adding SPNs to CN=ADC2,OU=Domain Controllers,DC=tecmint,DC=lan
Setting account password for ADC2$
Enabling account
Calling bare provision
Looking up IPv4 addresses
Looking up IPv6 addresses
No IPv6 address will be assigned
Setting up share.ldb
Setting up secrets.ldb
Setting up the registry
Setting up the privileges database
Setting up idmap db
Setting up SAM db
Setting up sam.ldb partitions and settings
Setting up sam.ldb rootDSE
Pre-loading the Samba 4 and AD schema
A Kerberos configuration suitable for Samba 4 has been generated at /var/lib/samba/private/krb5.conf
Provision OK for domain DN DC=tecmint,DC=lan
Starting replication
Schema-DN[CN=Schema,CN=Configuration,DC=tecmint,DC=lan] objects[402/1550] linked_values[0/0]
Schema-DN[CN=Schema,CN=Configuration,DC=tecmint,DC=lan] objects[804/1550] linked_values[0/0]
Schema-DN[CN=Schema,CN=Configuration,DC=tecmint,DC=lan] objects[1206/1550] linked_values[0/0]
Schema-DN[CN=Schema,CN=Configuration,DC=tecmint,DC=lan] objects[1550/1550] linked_values[0/0]
Analyze and apply schema objects
Partition[CN=Configuration,DC=tecmint,DC=lan] objects[402/1614] linked_values[0/0]
Partition[CN=Configuration,DC=tecmint,DC=lan] objects[804/1614] linked_values[0/0]
Partition[CN=Configuration,DC=tecmint,DC=lan] objects[1206/1614] linked_values[0/0]
Partition[CN=Configuration,DC=tecmint,DC=lan] objects[1608/1614] linked_values[0/0]
Partition[CN=Configuration,DC=tecmint,DC=lan] objects[1614/1614] linked_values[28/0]
Replicating critical objects from the base DN of the domain
Partition[DC=tecmint,DC=lan] objects[97/97] linked_values[24/0]
Partition[DC=tecmint,DC=lan] objects[380/283] linked_values[27/0]
Done with always replicated NC (base, config, schema)
Replicating DC=DomainDnsZones,DC=tecmint,DC=lan
Partition[DC=DomainDnsZones,DC=tecmint,DC=lan] objects[45/45] linked_values[0/0]
Replicating DC=ForestDnsZones,DC=tecmint,DC=lan
Partition[DC=ForestDnsZones,DC=tecmint,DC=lan] objects[18/18] linked_values[0/0]
Committing SAM database
Sending DsReplicaUpdateRefs for all the replicated partitions
Setting isSynchronized and dsServiceName
Setting up secrets database
Joined domain TECMINT (SID S-1-5-21-715537322-3397311598-55032968) as a DC
```

*把域加入到 Samba4 AD DC*
12、在已安装了 Samba4 套件的 Ubuntu 系统加入域之后,打开 Samba 主配置文件添加如下行:
```
# nano /etc/samba/smb.conf
```
添加以下内容到 `smb.conf` 配置文件中。
```
dns forwarder = 192.168.1.1
idmap_ldb:use rfc2307 = yes
template shell = /bin/bash
winbind use default domain = true
winbind offline logon = false
winbind nss info = rfc2307
winbind enum users = yes
winbind enum groups = yes
```
使用你自己的 **DNS 转发器 IP** 地址替换掉上面 `dns forwarder` 地址。 Samba 将会把域权威区之外的所有 DNS 解析查询转发到这个 IP 地址。
13、最后,重启 samba 服务以使修改的配置生效,然后执行如下命令来检查活动目录复制功能是否正常。
```
# systemctl restart samba-ad-dc
# samba-tool drs showrepl
```

*配置 Samba4 DNS*
14、另外,还需要重命名原来的 `/etc`下的 kerberos 配置文件,并使用在加入域的过程中 Samba 生成的新配置文件 krb5.conf 替换它。
Samba 生成的新配置文件在 `/var/lib/samba/private` 目录下。使用 Linux 的符号链接将该文件链接到 `/etc` 目录。
```
# mv /etc/krb6.conf /etc/krb5.conf.initial
# ln -s /var/lib/samba/private/krb5.conf /etc/
# cat /etc/krb5.conf
```

*配置 Kerberos*
15、同样,使用 samba 的 `krb5.conf` 配置文件验证 Kerberos 认证是否正常。通过以下命令来请求一个管理员账号的票据并且列出已缓存的票据信息。
```
# kinit administrator
# klist
```

*使用 Samba 验证 Kerberos 认证是否正常*
### 第 4 步:验证其它域服务
16、你首先要做的一个测试就是验证 **Samba4 DC DNS** 解析服务是否正常。要验证域 DNS 解析情况,使用 `host` 命令,加上一些重要的 AD DNS 记录,进行域名查询,如下图所示:
每一次查询,DNS 服务器都应该返回两个 IP 地址。
```
# host your_domain.tld
# host -t SRV _kerberos._udp.your_domain.tld # UDP Kerberos SRV record
# host -t SRV _ldap._tcp.your_domain.tld # TCP LDAP SRV record
```

\*验证 Samba4 DC DNS \*
17、这些 DNS 记录也可以从注册过的[已安装了 RSAT 工具的 Windows 机器](/article-8097-1.html)上查询到。打开 DNS 管理器,展开到你的域 tcp 记录,如下图所示:

*通过 Windows RSAT 工具来验证 DNS 记录*
18、下一个验证是检查域 LDAP 复制同步是否正常。使用 `samba-tool` 工具,在第二个域控制器上创建一个账号,然后检查该账号是否自动同步到第一个 Samba4 AD DC 服务器上。
在 adc2 上:
```
# samba-tool user add test_user
```
在 adc1 上:
```
# samba-tool user list | grep test_user
```

*在 Samba4 AD 服务器上创建账号*

*在 Samba4 AD 服务器上验证同步功能*
19、你也可以从 **Microsoft AD DC** 控制台创建一个账号,然后验证该账号是否都出现在两个域控服务器上。
默认情况下,这个账号都应该在两个 samba 域控制器上自动创建完成。在 `adc1` 服务器上使用 `wbinfo` 命令查询该账号名。

*从 Microsoft AD UC 创建账号*

*在 Samba4 AD 服务器上验证账号同步功能*
20、实际上,打开 Windows 机器上的 **AD DC** 控制台,展开到域控制器,你应该看到两个已注册的 DC 服务器。

*验证 Samba4 域控制器*
### 第 5 步:启用 Samba4 AD DC 服务
21、要在整个系统启用 Samba4 AD DC 的服务,首先你得禁用原来的不需要的 Samba 服务,然后执行如下命令仅启用 samba-ad-dc 服务:
```
# systemctl disable smbd nmbd winbind
# systemctl enable samba-ad-dc
```

*启用 Samba4 AD DC 服务*
22、如果你从 Microsoft 客户端远程管理 Samba4 域控制器,或者有其它 Linux 或 Windows 客户机集成到当前域中,请确保在它们的网卡 DNS 服务器地址设置中提及 `adc2` 服务器的 IP 地址,以实现某种程序上的冗余。
下图显示 Windows 和 Debian/Ubuntu 客户机的网卡配置要求。

*配置 Windows 客户端来管理 Samba4 DC*

*配置 Linux 客户端来管理 Samba4 DC*
如果第一台 DC 服务器 192.168.1.254 网络不通,则调整配置文件中 DNS 服务器 IP 地址的顺序,以免先查询这台不可用的 DNS 服务器。
最后,如果你想在 Linux 系统上使用 Samba4 活动目录账号来进行本地认证,或者为 AD LDAP 账号授予 root 权限,请查看[在 Linux 命令行下管理 Samba4 AD 架构](/article-8070-1.html) 这篇教程的 第 2 步和第 3 步。
---
作者简介:
我叫 Ravi Saive,TecMint 网站博主。一个喜欢在网上分享技术知识及经验的电脑极客和 Linux 系统专家。我的大多数的服务器都运行在 Linux 开源平台上。关注我:Twitter ,Facebook 和 Google+ 。
---
via: <http://www.tecmint.com/join-additional-ubuntu-dc-to-samba4-ad-dc-failover-replication/>
作者:[Ravi Saive](http://www.tecmint.com/author/admin/) 译者:[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,359 | 在 Kali Linux 中更改 GRUB2 背景的 5 种方式 | https://www.blackmoreops.com/2015/11/27/change-grub-background-in-kali-linux/ | 2017-03-31T10:54:00 | [
"背景",
"引导",
"GRUB"
] | https://linux.cn/article-8359-1.html | 这是一个关于如何在 Kali Linux 中更改 GRUB 背景的简单指南(实际上它是 Kali Linux 的 GRUB 启动图像)。 Kali 开发团队在这方面做的不多,他们好像太忙了,所以在这篇文章中,我会对 GRUB 解释一二,但是不会冗长到我失去写作的激情。 那么我们开始吧……

这通常是所有人首先会遇到的一个问题,在哪里设置?有很多方法来查找 GRUB 设置。每个人都可能有自己的方法,但我发现 `update-grub` 是最简单的。如果在 VMWare 或 VirtualBox 中执行 `update-grub`,你将看到如下所示的内容:
```
root@kali:~# update-grub
Generating grub configuration file ...
Found background image: /usr/share/images/desktop-base/desktop-grub.png
Found linux image: /boot/vmlinuz-4.0.0-kali1-amd64
Found initrd image: /boot/initrd.img-4.0.0-kali1-amd64
No volume groups found
done
root@kali:~#
```
如果您是双系统,或者三系统,那么您将看到 GRUB 以及其他操作系统入口。然而,我们感兴趣的部分是背景图像,这是在我这里看到的(你会看到完全相同的内容):
```
Found background image: /usr/share/images/desktop-base/desktop-grub.png
```
### GRUB 启动图像搜索顺序
在 grub-2.02 中,对基于 Debian 的系统来说,它将按照以下顺序搜索启动背景:
1. `/etc/default/grub` 里的 `GRUB_BACKGROUND` 行
2. 在 `/boot/grub/` 里找到的第一个图像(如果发现多张,将以字母顺序排序)
3. 在 `/usr/share/desktop-base/grub_background.sh` 中指定的
4. 在 `/etc/grub.d/05_debian_theme` 里 `WALLPAPER` 行列出的
现在将此信息留在这里,我们会尽快重新检查它。
### Kali Linux GRUB 启动图像
在我使用 Kali Linux 时(因为我喜欢用它做事),会发现 Kali 正在使用这里的背景图像:`/usr/share/images/desktop-base/desktop-grub.png`
为了确定,我们来检查一下这个 `.png` 文件的属性。
```
root@kali:~#
root@kali:~# ls -l /usr/share/images/desktop-base/desktop-grub.png
lrwxrwxrwx 1 root root 30 Oct 8 00:31 /usr/share/images/desktop-base/desktop-grub.png -> /etc/alternatives/desktop-grub
root@kali:~#
```

什么?它只是 `/etc/alternatives/desktop-grub` 的一个符号链接? 但是 `/etc/alternatives/desktop-grub` 不是图片文件。看来我也要检查一下它的属性。
```
root@kali:~#
root@kali:~# ls -l /etc/alternatives/desktop-grub
lrwxrwxrwx 1 root root 44 Oct 8 00:27 /etc/alternatives/desktop-grub -> /usr/share/images/desktop-base/kali-grub.png
root@kali:~#
```

好吧,真让人费解。 `/etc/alternatives/desktop-grub` 也是一个符号链接,它指向 `/usr/share/images/desktop-base/kali-grub.png`,来自最初同样的文件夹。呃! 无语。 但是现在我们至少可以替换该文件并将其解决。
在替换之前,我们需要检查 `/usr/share/images/desktop-base/kali-grub.png` 的属性,以确保下载相同类型和大小的文件。
```
root@kali:~#
root@kali:~# file /usr/share/images/desktop-base/kali-grub.png
/usr/share/images/desktop-base/kali-grub.png: PNG image data, 640 x 480, 8-bit/color RGB, non-interlaced
root@kali:~#
```
可以确定这是一个 PNG 图像文件,像素尺寸为 640 x 480。
### GRUB 背景图像属性
可以使用 `PNG`, `JPG`/`JPEG` 以及 `TGA` 类型的图像文件作为 GRUB 2 的背景。必须符合以下规范:
* `JPG`/`JPEG` 图像必须是 `8-bit` (256 色)
* 图像应该是非索引的,`RGB`
默认情况下,如果安装了 `desktop-base` 软件包,符合上述规范的图像将放在 `/usr/share/images/desktop-base/` 目录中。在谷歌上很容易找到类似的文件。我也找了一个。
```
root@kali:~#
root@kali:~# file Downloads/wallpaper-1.png
Downloads/wallpaper-1.png: PNG image data, 640 x 480, 8-bit/color RGB, non-interlaced
root@kali:~#
```

### 方式 1:替换图像
现在我们只需简单的用新文件将 `/usr/share/images/desktop-base/kali-grub.png` 替换掉。值得注意这是最简单的方法,不需要修改 `grub-config` 文件。 如果你对 GRUB 很熟,建议你简单的修改 GRUB 的默认配置文件,然后执行 `update-grub`。
像往常一样,我会将原文件重命名为 `kali-grub.png.bkp` 进行备份。
```
root@kali:~#
root@kali:~# mv /usr/share/images/desktop-base/kali-grub.png /usr/share/images/desktop-base/kali-grub.png.bkp
root@kali:~#
```

现在我们将下载的文件重命名为 `kali-grub.png`。
```
root@kali:~#
root@kali:~# cp Downloads/wallpaper-1.png /usr/share/images/desktop-base/kali-grub.png
root@kali:~#
```

最后执行命令 `update-grub`:
```
root@kali:~# update-grub
Generating grub configuration file ...
Found background image: /usr/share/images/desktop-base/desktop-grub.png
Found linux image: /boot/vmlinuz-4.0.0-kali1-amd64
Found initrd image: /boot/initrd.img-4.0.0-kali1-amd64
No volume groups found
done
root@kali:~#
```

下次重新启动你的 Kali Linux 时,你会看到 GRUB 背景变成了你自己的图像(GRUB 启动界面)。
下面是我现在正在使用的新 GRUB 启动背景。你呢?要不要试试这个办法?

这是最简单最安全的办法,最糟的情况也不过是在 GRUB 看到一个蓝色的背景,但你依然可以登录后修复它们。现在如果你有信心,让我们尝试一个改变 GRUB 设置的更好的方法(有点复杂)。后续步骤更加有趣,而且可以在任何使用 GRUB 引导的 Linux 上使用。
现在回忆一下 GRUB 在哪 4 个地方寻找启动背景图像?再看一遍:
1. `/etc/default/grub` 里的 `GRUB_BACKGROUND` 行
2. 在 `/boot/grub/` 里找到的第一个图像(如果发现多张,将以字母顺序排序)
3. 在 `/usr/share/desktop-base/grub_background.sh` 中指定的
4. 在 `/etc/grub.d/05_debian_theme` 里 WALLPAPER 行列出的
那么我们再在 Kali Linux 上(或任意使用 GRUB2 的 Linux系统)试一下新的选择。
### 方式 2:在 GRUB\_BACKGROUND 中定义图像路径
所以你可以根据上述的查找优先级使用上述任一项,将 GRUB 背景图像改为自己的。以下是我自己系统上 `/etc/default/grub` 的内容。
```
root@kali:~# vi /etc/default/grub
```
按照 `GRUB_BACKGROUND="/root/World-Map.jpg"` 的格式添加一行,其中 World-Map.jpg 是你要作为 GRUB 背景的图像文件。
```
# If you change this file, run 'update-grub' afterwards to update
# /boot/grub/grub.cfg.
# For full documentation of the options in this file, see:
# info -f grub -n 'Simple configuration'
GRUB_DEFAULT=0
GRUB_TIMEOUT=15
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
GRUB_CMDLINE_LINUX_DEFAULT="quiet"
GRUB_CMDLINE_LINUX="initrd=/install/gtk/initrd.gz"
GRUB_BACKGROUND="/root/World-Map.jpg"
```
一旦使用上述方式完成更改,务必执行 `update-grub` 命令,如下所示。
```
root@kali:~# update-grub
Generating grub configuration file ...
Found background: /root/World-Map.jpg
Found background image: /root/World-Map.jpg
Found linux image: /boot/vmlinuz-4.0.0-kali1-amd64
Found initrd image: /boot/initrd.img-4.0.0-kali1-amd64
No volume groups found
done
root@kali:~#
```
现在重启机器,你会在 GRUB 看到自定义的图像。
### 方式 3:把图像文件放到 /boot/grub/ 文件夹
如果没有在 `/etc/default/grub` 文件中指定 `GRUB_BACKGROUND` 项,理论上 GRUB 应当使用在 `/boot/grub/` 文件夹找到的第一个图像文件作为背景。如果 GRUB 在 `/boot/grub/` 找到多个图像文件,它会按字母排序并使用第一个图像文件。
### 方式 4:在 grub\_background.sh 指定图像路径
如果没有在 `/etc/default/grub` 文件中指定 `GRUB_BACKGROUND` 项,而且 `/boot/grub/` 目录下没有图像文件,GRUB 将会开始在 `/usr/share/desktop-base/grub_background.sh` 文件中指定的图像路径中搜索。Kali Linux 是在这里指定的。每个 Linux 发行版都有自己的特色。
### 方式 5:在 /etc/grub.d/05\_debian\_theme 文件的 WALLPAPER 一行指定图像
这是 GRUB 搜寻背景图像的最后一个位置。如果在其他部分都没有找到,它将会在这里查找。
### 结论
这篇文章较长,但我想介绍一些基础但很重要的东西。如果你有仔细阅读,你会理解如何在 Kali Linux 上来回跟踪符号链接。当你需要在一些 Linux 系统上查找 GRUB 背景图像的位置时,你会感到得心应手。只要再多阅读一点来理解 GRUB 颜色的工作方式,你就是行家了。
---
via: <https://www.blackmoreops.com/2015/11/27/change-grub-background-in-kali-linux/>
作者:[https://www.blackmoreops.com/](https://www.blackmoreops.com/2015/11/27/change-grub-background-in-kali-linux/) 译者:[fuowang](https://github.com/fuowang) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 200 | OK | This is a simple guide on how to change GRUB background in Kali Linux (i.e. it’s actually Kali Linux GRUB splash image). Kali dev team did few things that seems almost too much work, so in this article I will explain one of two things about GRUB and somewhat make this post little unnecessarily long and boring cause I like to write! So here goes …
## Finding GRUB settings
This is usually the first issue everyone faces, where do I look? There’s a many ways to find GRUB settings. Users might have their own opinion but I always found that `update-grub`
is the easiest way. If you run `update-grub`
in a VMWare/VirtualBox, you will see something like this:
root@kali:~# update-grub Generating grub configuration file ... Found background image: /usr/share/images/desktop-base/desktop-grub.png Found linux image: /boot/vmlinuz-4.0.0-kali1-amd64 Found initrd image: /boot/initrd.img-4.0.0-kali1-amd64 No volume groups found done root@kali:~#
If you’re using a Dual Boot, Triple Boot then you will see GRUB goes in and finds other OS’es as well. However, the part we’re interested is the background image part, in my case this is what I see (you will see exactly the same thing):
Found background image: /usr/share/images/desktop-base/desktop-grub.png
## GRUB splash image search order
In grub-2.02, it will search for the splash image in the following order for a Debian based system:
- GRUB_BACKGROUND line in
`/etc/default/grub`
- First image found in
`/boot/grub/`
( more images found, it will be taken alphanumerically ) - The image specified in
`/usr/share/desktop-base/grub_background.sh`
- The file listed in the WALLPAPER line in
`/etc/grub.d/05_debian_theme`
Now hang onto this info and we will soon revisit it.
## Kali Linux GRUB splash image
As I use Kali Linux (cause I like to test things), I found that Kali is using a background image from here: `/usr/share/images/desktop-base/desktop-grub.png`
Just to be sure, let’s check that `.png`
file and it’s properties.
root@kali:~# root@kali:~# ls -l /usr/share/images/desktop-base/desktop-grub.png lrwxrwxrwx 1 root root 30 Oct 8 00:31 /usr/share/images/desktop-base/desktop-grub.png -> /etc/alternatives/desktop-grub root@kali:~#
What? It’s just a symbolic link to `/etc/alternatives/desktop-grub`
file? But `/etc/alternatives/desktop-grub`
is not an image file. Looks like I need to check that file and it’s properties as well.
root@kali:~# root@kali:~# ls -l /etc/alternatives/desktop-grub lrwxrwxrwx 1 root root 44 Oct 8 00:27 /etc/alternatives/desktop-grub -> /usr/share/images/desktop-base/kali-grub.png root@kali:~#
Alright, that’s confusing as! So `/etc/alternatives/desktop-grub`
is another symbolic link which points back to
`/usr/share/images/desktop-base/kali-grub.png`
which is in the same folder we started from. doh! That’s all I can say. But at least now we can just replace that file and get it over with.
Before we do that we need to check the properties of this file `/usr/share/images/desktop-base/kali-grub.png`
and ensure that we will download same type and dimension file.
root@kali:~# root@kali:~# file /usr/share/images/desktop-base/kali-grub.png /usr/share/images/desktop-base/kali-grub.png: PNG image data, 640 x 480, 8-bit/color RGB, non-interlaced root@kali:~#
So this file is DEFINITELY a PNG image data, 640 x 480 dimension.
## GRUB background image properties
GRUB 2 can use `PNG`
, `JPG`
/`JPEG`
and `TGA`
images for the background. The image must meet the following specifications:
`JPG`
/`JPEG`
images must be`8-bit`
(`256 color`
)- Images should be non-indexed,
`RGB`
By default, if `desktop-base`
package is installed, images conforming to the above specification will be located in `/usr/share/images/desktop-base/`
directory. A quick Google search found similar files. Out of those, I picked one.
root@kali:~# root@kali:~# file Downloads/wallpaper-1.png Downloads/wallpaper-1.png: PNG image data, 640 x 480, 8-bit/color RGB, non-interlaced root@kali:~#
## Option 1: replace the image
Now we simply need to replace this `/usr/share/images/desktop-base/kali-grub.png`
file with our new file. Note that this is the easiest way without mucking around `grub-config`
files. If you are familiar with GRUB, then go ahead and simpy modify GRUB default config and run `update-grub`
.
As usual, I will make a backup of the original file by renaming it to `kali-grub.png.bkp`
root@kali:~# root@kali:~# mv /usr/share/images/desktop-base/kali-grub.png /usr/share/images/desktop-base/kali-grub.png.bkp root@kali:~#
Now let’s copy our downloaded file and rename that to `kali-grub.png.bkp`
.
root@kali:~# root@kali:~# cp Downloads/wallpaper-1.png /usr/share/images/desktop-base/kali-grub.png root@kali:~#
And finally run `update-grub`
root@kali:~# update-grub Generating grub configuration file ... Found background image: /usr/share/images/desktop-base/desktop-grub.png Found linux image: /boot/vmlinuz-4.0.0-kali1-amd64 Found initrd image: /boot/initrd.img-4.0.0-kali1-amd64 No volume groups found done root@kali:~#
Next time you restart your Kali Linux, you will see your own image as the GRUB background. (GRUB splash image).
Following is what my new GRUB splash image looks like in Kali Linux now. What about you? Tried this method yet?
This was the easiest and safest way, if you muck it up the worst, you will see a Blue background in GRUB but will still be able to login and fix things later. Now if you’re confident, lets move to better ways (bit complex) of changing GRUB settings. Next steps are more fun and works with any Linux using GRUB bootloader.
[2](https://www.blackmoreops.com/2015/11/27/change-grub-background-in-kali-linux/2/)
Just in time.. Upgraded to sana yesterday, today was thinking of changing grub background, and now saw it in mail !
Great!! how to change fontsize?
Where can I get the image as of yours GRUB Background
12minets in google > world-map -> abstract…
http://www.wallconvert.com/converted/abstract-world-map-wallpapers-1920×1080-175289.html
and dont forgot
“Whait for MidNight rebooT and start doing evil plans for world domination”
;) |
8,360 | 在 Linux 上用火狐浏览器保护你的隐私 | https://linuxconfig.org/protecting-your-privacy-with-firefox-on-linux | 2017-03-31T14:44:30 | [
"Firefox",
"浏览器",
"安全",
"隐私"
] | https://linux.cn/article-8360-1.html | ### 介绍
隐私和安全正在逐渐成为一个重要的话题。虽然不可能做到 100% 安全,但是,还是能采取一些措施,特别是在 Linux 上,在你浏览网页的时候保护你的在线隐私安全。

基于这些目的选择浏览器的时候,火狐或许是你的最佳选择。谷歌 Chrome 不能信任。它是属于谷歌的,一个众所周知的数据收集公司,而且它是闭源的。 Chromium 或许还可以,但并不能保证。只有火狐保持了一定程度的用户权利承诺。
### 火狐设置
火狐里有几个你能设定的设置,能更好地保护你的隐私。这些设置唾手可得,能帮你控制那些在你浏览的时候分享的数据。
#### 健康报告
你首先可以设置的是对火狐健康报告发送的限制,以限制数据发送量。当然,这些数据只是被发送到 Mozilla,但这也是传输数据。
打开火狐的菜单,点击<ruby> “选项” <rt> Preferences </rt></ruby>。来到侧边栏里的<ruby> “高级” <rt> Advanced </rt></ruby>选项卡,点击<ruby> “数据选项” <rt> Data Choices </rt></ruby>。这里你能禁用任意数据的报告。
#### 搜索
新版的火狐浏览器默认使用雅虎搜索引擎。一些发行版会更改设置,替代使用的是谷歌。两个方法都不理想。火狐可以使用 DuckDuckGo 作为默认选项。

为了启用 DuckDuckGo,你得打开火狐菜单点击<ruby> “选项” <rt> Preferences </rt></ruby>。直接来到侧边栏的<ruby> “搜索” <rt> Search </rt></ruby>选项卡。然后,在<ruby> “默认搜索引擎” <rt> Default Search Engine </rt></ruby>的下拉菜单中选择 DuckDuckGo 。
#### <ruby> 请勿跟踪 <rt> Do Not Track </rt></ruby>
这个功能并不完美,但它确实向站点发送了一个信号,告诉它们不要使用分析工具来记录你的活动。这些网页或许会遵从,会许不会。但是,最好启用请勿跟踪,也许它们会遵从呢。

再次打开火狐的菜单,点击<ruby> “选项” <rt> Preferences </rt></ruby>,然后是<ruby> “隐私” <rt> Privacy </rt></ruby>。页面的最上面有一个<ruby> “跟踪” <rt> Tracking </rt></ruby>部分。点击那一行写着<ruby> “您还可以管理您的‘请勿跟踪’设置” <rt> You can also manage your Do Not Track settings </rt></ruby>的链接。会出现一个有复选框的弹出窗口,那里允许你启用“请勿跟踪”设置。
#### 禁用 Pocket
没有任何证据显示 Pocket 正在做一些不好的事情,但是禁用它或许更好,因为它确实连接了一个专有的应用。
禁用 Pocket 不是太难,但是你得注意只改变 Pocket 相关设置。要访问你所需的配置页面,在火狐的地址栏里输入`about:config`。
页面会加载一个设置表格,在表格的最上面是搜索栏,在那儿搜索 Pocket 。
你将会看到一个包含结果的新表格。找一下名为 `extensions.pocket.enabled` 的设置。当你找到它的时候,双击使其转变为“否”。你也能在这儿编辑 Pocket 的其他相关设置。不过没什么必要。注意不要编辑那些跟 Pocket 扩展不直接相关的任何东西。

### <ruby> 附加组件 <rt> Add-ons </rt></ruby>

火狐最有效地保护你隐私和安全的方式来自附加组件。火狐有大量的附加组件库,其中很多是免费、开源的。在这篇指导中着重提到的附加组件,在使浏览器更安全方面是名列前茅的。
#### HTTPS Everywhere
针对大量没有使用 SSL 证书的网页、许多不使用 `https` 协议的链接、指引用户前往不安全版本的网页等现状,<ruby> 电子前线基金会 <rt> Electronic Frontier Foundation </rt></ruby>开发了 HTTPS Everywhere。HTTPS Everywhere 确保了如果该链接存在有一个加密的版本,用户将会使用它。
给火狐设计的 [HTTPS Everywhere](https://addons.mozilla.org/en-us/firefox/addon/https-everywhere/) 已经可以使用,在火狐的附加组件搜索网页上。(LCTT 译注:对应的[中文页面](https://addons.mozilla.org/zh-CN/firefox/addon/https-everywhere/)。)
#### Privacy Badger
电子前线基金会同样开发了 Privacy Badger。 [Privacy Badger](https://addons.mozilla.org/en-us/firefox/addon/privacy-badger17) 旨在通过阻止不想要的网页跟踪,弥补“请勿跟踪”功能的不足之处。它同样能通过火狐附加组件仓库安装。。(LCTT 译注:对应的[中文页面](https://addons.mozilla.org/zh-CN/firefox/addon/privacy-badger17/)。)
#### uBlock Origin
现在有一类更通用的的隐私附加组件,屏蔽广告。这里的选择是 uBlock Origin,uBlock Origin 是个更轻量级的广告屏蔽插件,几乎不遗漏所有它会屏蔽的广告。 [uBlock Origin](https://addons.mozilla.org/en-us/firefox/addon/ublock-origin/) 将主要屏蔽各种广告,特别是侵入性的广告。你能在这儿找到它。。(LCTT 译注:对应的[中文页面](https://addons.mozilla.org/zh-CN/firefox/addon/ublock-origin/)。)
#### NoScript
阻止 JavaScript 是有点争议, JavaScript 虽说支撑了那么多的网站,但还是臭名昭著,因为 JavaScript 成为侵略隐私和攻击的媒介。NoScript 是应对 JavaScript 的绝佳方案。

NoScript 是一个 JavaScript 的白名单,它会屏蔽所有 JavaScript,除非该站点被添加进白名单中。可以通过插件的“选项”菜单,事先将一个站点加入白名单,或者通过在页面上点击 NoScript 图标的方式添加。

通过火狐附加组件仓库可以安装 [NoScript](https://addons.mozilla.org/en-US/firefox/addon/noscript/) 如果网页提示不支持你使用的火狐版本,点<ruby> “无论如何下载” <rt> Download Anyway </rt></ruby>。这已经在 Firefox 51 上测试有效。
#### Disconnect
[Disconnect](https://addons.mozilla.org/en-US/firefox/addon/disconnect/) 做的事情很多跟 Privacy Badger 一样,它只是提供了另一个保护的方法。你能在附加组件仓库中找到它 (LCTT 译注:对应的[中文页面](https://addons.mozilla.org/zh-CN/firefox/addon/disconnect/))。如果网页提示不支持你使用的火狐版本,点<ruby> “无论如何下载” <rt> Download Anyway </rt></ruby>。这已经在 Firefox 51 上测试有效。
#### Random Agent Spoofer
Random Agent Spoofer 能改变火狐浏览器的签名,让浏览器看起来像是在其他任意平台上的其他任意浏览器。虽然有许多其他的用途,但是它也能用于预防浏览器指纹侦查。
<ruby> 浏览器指纹侦查 <rt> Browser Fingerprinting </rt></ruby>是网站基于所使用的浏览器和操作系统来跟踪用户的另一个方式。相比于 Windows 用户,浏览器指纹侦查更多影响到 Linux 和其他替代性操作系统用户,因为他们的浏览器特征更独特。
你能通过火狐附加插件仓库添加 [Random Agent Spoofer](https://addons.mozilla.org/en-us/firefox/addon/random-agent-spoofer/)。(LCTT 译注:对应的[中文页面](https://addons.mozilla.org/zh-CN/firefox/addon/random-agent-spoofer/))。像其他附加组件那样,页面或许会提示它不兼容最新版的火狐。再说一次,那并不是真的。

你可以通过点击火狐菜单栏上的图标来使用 Random Agent Spoofer。点开后将会出现一个下拉菜单,有不同模拟的浏览器选项。最好的选项之一是选择"Random Desktop" 和任意的切换时间。这样,就绝对没有办法来跟踪你了,也保证了你只能获得网页的桌面版本。
### 系统设置
#### 私人 DNS
请避免使用公共或者 ISP 的 DNS 服务器!即使你配置你的浏览器满足绝对的隐私标准,你向公共 DNS 服务器发出的 DNS 请求却暴露了所有你访问过的网页。诸如谷歌公共 DNS(IP:8.8.8.8 、8.8.4.4)这类的服务将会记录你的 IP 地址、你的 ISP 和地理位置信息。这些信息或许会被任何合法程序或者强制性的政府请求所分享。
>
> **当我在使用谷歌公共 DNS 服务时,谷歌会记录什么信息?**
>
>
> 谷歌公共 DNS 隐私页面有一个完整的收集信息列表。谷歌公共 DNS 遵循谷歌的主隐私政策,在<ruby> “隐私中心” <rt> Privacy Center </rt></ruby>可以看到。 用户的客户端 IP 地址是唯一会被临时记录的(一到两天后删除),但是为了让我们的服务更快、更好、更安全,关于 ISP 和城市/都市级别的信息将会被保存更长的时间。 参考资料: `https://developers.google.com/speed/public-dns/faq#privacy`
>
>
>
由于以上原因,如果可能的话,配置并使用你私人的非转发 DNS 服务器。现在,这项任务或许跟在本地部署一些预先配置好的 DNS 服务器的 Docker 容器一样简单。例如,假设 Docker 服务已经在你的系统安装完成,下列命令将会部署你的私人本地 DNS 服务器:
```
# docker run -d --name bind9 -p 53:53/udp -p 53:53 fike/bind9
```
DNS 服务器现在已经启动并正在运行:
```
# dig @localhost google.com
; <<>> DiG 9.9.5-9+deb8u6-Debian <<>> @localhost google.com
; (2 servers found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 51110
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 4, ADDITIONAL: 5
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;google.com. IN A
;; ANSWER SECTION:
google.com. 242 IN A 216.58.199.46
```
现在,在 `/etc/resolv.conf` 里设置你的域名服务器:
```
nameserver 127.0.0.1
```
### 结束语
没有完美的安全隐私解决方案。虽然本篇指导里的步骤可以明显改进它们。如果你真的很在乎隐私,[Tor 浏览器](https://www.torproject.org/projects/torbrowser.html.en) 是最佳选择。Tor 对于日常使用有点过犹不及,但是它的确使用了这篇指导里列出的一些措施。
---
via: <https://linuxconfig.org/protecting-your-privacy-with-firefox-on-linux>
作者:[Nick Congleton](https://linuxconfig.org/protecting-your-privacy-with-firefox-on-linux) 译者:[ypingcn](https://ypingcn.github.io/wiki/lctt) 校对:[jasminepeng](https://github.com/jasminepeng)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 403 | Forbidden | null |
8,361 | 3 个开源的链接缩短器 | https://opensource.com/article/17/3/url-link-shortener | 2017-04-01T07:42:00 | [
"链接",
"短链接"
] | https://linux.cn/article-8361-1.html |
>
> 想要构建你自己的 URL 缩短器?这些开源项目使这个变得简单。
>
>
>

没有人喜欢一个非常长的 URL。
它们很难解析。但有时候,站点的深层目录结构还有最后加上的大量参数使得 URL 开始变得冗长。在 Twitter 添加自己的链接缩短服务之前的那些日子里,一个长的 URL 意味着不得不削减推文中珍贵的字符。
如今,因为很多原因,人们开始使用链接缩短器。这样人们可以更容易地输入或记住另一个冗长的网址。它们可以为社交媒体帐户带来一贯的品牌建设。它们使对一组网址进行分析变得更轻松。它们使得为频繁变化的网站 URL 提供统一的入口成为可能。
URL 缩短器确实有一些不足。在点击之前很难知道链接实际指向哪里,而且如果提供短网址服务消失,就会导致<ruby> <a href="https://en.wikipedia.org/wiki/Linkrot"> 烂链 </a> <rp> ( </rp> <rt> linkrot </rt> <rp> ) </rp></ruby>。但是尽管面临这些挑战,URL 缩短器不会消失。
但是,既然已经有这么多免费链接缩短服务,为什么还要自己构建?简而言之:方便控制。虽然有些服务可以让你选择自己的域名来使用,但得到的定制级别不同。使用自托管服务,你可以自己决定服务的运行时间、URL 的格式以及决定谁可以访问你的分析。这是你自己拥有并且可以操作的。
幸运的是,如果你想建立下一个 bit.ly、goo.gl 或 ow.ly,你可以有很多开源选项。你可以考虑下面几个。
### Lessn More
[Lessn More](https://lessnmore.net/) 是一个个人 URL 缩短器,用 PHP 写成,并从一个名为 Buttered URL 的较旧项目 fork 而来,而 Buttered URL 又是从一个名为 Lessn 的项目的分支衍生而来。Lessn More 能提供你对 URL 缩短器所预期的大部分功能:API 和书签支持、自定义 URL 等。还有一些有用的功能,比如可以让 Lessn More 使用单词黑名单来避免不小心创建不适当的 URL、避免“看着相似”的字符来使 URL 更易读、能够选择是否使用混合大小写的字符,以及一些其它有用的功能。
[Lessn More](https://lessnmore.net/) 在 GitHub 上以三句版 [BSD](https://github.com/alanhogan/lessnmore/blob/master/LICENSE.txt) 许可证公布了[源代码](https://github.com/alanhogan/lessnmore)。
### Polr
[Polr](https://project.polr.me/) 将自己描述为“现代、强大、可靠的 URL 缩短器”。它具有相当直接但现代化的界面,像我们这里详细介绍的其他选择那样,还提供了一个 API 来允许你从其他程序中使用它。在这三个可选品中,它在功能上是最轻量级的,但如果你正在寻找一个简单但功能完整的选择,那么这可能是你不错的选择。下载之前你可以查看[在线演示](http://demo.polr.me/)。
Polr 的[源代码](https://github.com/cydrobolt/polr) 在 GitHub 中以 [GPLv2](https://github.com/cydrobolt/polr/blob/master/LICENSE) 许可证公布。
### YOURLS
[YOURLS](https://yourls.org/),是 “Your Own URL Shortener”(你自己的 URL 缩短器)的缩写,它是我最熟悉的选择。我在个人网站上已经运行了好几年,并且对其功能非常满意。
它是用 PHP 编写的,YOURLS 功能非常丰富并且可以很好地开箱即用。你可以将其配置为任何人可公开使用,或只允许某些用户使用它。它支持自定义 URL,拥有书签功能,使得共享很容易,它还具有非常强大的内置统计信息,并支持可插拔的架构,以允许其他人添加功能。它还有一个 API,可以轻松地用它创建其他程序。
你可以在 Github 中找到 [MIT 许可证](https://github.com/YOURLS/YOURLS/blob/master/LICENSE.md)下的 YOURLS [源代码](https://github.com/YOURLS/YOURLS)。
---
这些选择都不喜欢么?看下互联网,你会发现还有其他几个选择:[shuri](https://github.com/pips-/shuri)、[Nimbus](https://github.com/ethanal/nimbus)、[Lstu](https://github.com/ldidry/lstu) 等等。除了这些选择外,构建链接缩短器可以作为帮助了解新语言或 Web 框架的第一次编程项目。毕竟,它的核心功能非常简单:以 URL 作为输入,并重定向到另一个 URL。除此之外,它取决于你自己想要添加的功能。
你有喜欢但没有在这里列出的 URL 缩短器吗?请在评论栏中让我们知道你的想法。
---
作者简介:
Jason Baker - Jason 热衷于使用技术使世界更加开放,从软件开发到阳光政府行动。Linux 桌面爱好者、地图/地理空间爱好者、树莓派工匠、数据分析和可视化极客、偶尔的码农、云本土主义者。在 Twitter 上关注他 @jehb。
---
via: <https://opensource.com/article/17/3/url-link-shortener>
作者:[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/) 荣誉推出
| 200 | OK | Nobody likes an impossibly long URL.
They're hard to decipher. But sometimes, between a deep directory structure on a site, plus a large number of parameters tacked on to the end, URLs just begin to get unwieldy. And back in the days before Twitter added their own link shortener to their service, a long URL meant taking precious characters away from your tweets.
Today, people use link shorteners for a slew of reasons. They can make it much easier to type, or remember, an otherwise lengthy bare URL. They can bring a consistent branding to a social media account. They make it easier to perform analytics across a group of URLs. They make it possible to provide a consistent entryway to a URL that may change frequently on the other side.
There are some challenges to URL shorteners, to be sure. They make it challenging to figure out where a link is actually taking you before you click, and they're vulnerable to [linkrot](https://en.wikipedia.org/wiki/Linkrot), should the service providing the short URL for you ever disappear. But despite these challenges, URL shorteners aren't going anywhere anytime soon.
But with so many free link shortening services out there, why roll your own? In short: control. While some services will let you pick your own domain to use, sometimes, that's about the level of customization you're going to get. With a self-hosted service, you decide how long your service operates for. You decide what format your URLs take. You decide who has access to your analytics. It's yours to own and operate as you please.
Fortunately, there are many open source options out there if you want to build the next bit.ly, goo.gl, or ow.ly yourself. Here are a few you might consider.
## Lessn More
[Lessn More](https://lessnmore.net/) is a personal URL shortener, built in PHP and forked off of an older project called Buttered URLs, which itself was derived from a fork of a project called Lessn. Lessn More provides most of the features you would expect from a URL shortener: API and bookmarklet support, custom URLs, etc. Some helpful features that set Lessn More apart are the ability to use a banned-words list to avoid creating an accidentally-inappropriate URL, the ability to avoid "lookalike" characters to make URLs more readable, the ability to choose whether or not to use mixed-case characters, and a few other helpful features.
[Lessn More](https://lessnmore.net/) provides its [source code](https://github.com/alanhogan/lessnmore) on GitHub under a 3-clause [BSD](https://github.com/alanhogan/lessnmore/blob/master/LICENSE.txt) license.
## Polr
[Polr](https://project.polr.me/) describes itself as a "modern, powerful, and robust URL shortener." It has a fairly straight-forward but modern interface, and like our other options detailed here comes with an API to allow you to use it from within other programs. Of the three presented here, it's the lightest on features, but if you're looking for a simple but functional option it may be a good choice for you. Check out the [online demo](http://demo.polr.me) before you download.
The [source code](https://github.com/cydrobolt/polr) for Polr can be found on GitHub under a [GPLv2](https://github.com/cydrobolt/polr/blob/master/LICENSE) license.
## YOURLS
[YOURLS](https://yourls.org/), short for Your Own URL Shortener, is the option I am most familiar with. In full disclosure, I ran it for several years in production on a personal site, and was very happy with its capabilities.
Written in PHP, YOURLS is a pretty feature-rich option that works well out of the box. You can configure it to be publicly usable by anyone, or only allow certain users to use it. It supports custom URLs, comes with a bookmarklet to make sharing easy, has pretty robust built-in stats, and supports a pluggable architecture to allow others to add to it. It also has an API, making it easy to create other programs which interface with it.
You can find the [source code](https://github.com/YOURLS/YOURLS) for YOURLS on GitHub under an [MIT license](https://github.com/YOURLS/YOURLS/blob/master/LICENSE.md).
Don't like any of these options? Take a look around the Internet and you can find several other choices: [shuri](https://github.com/pips-/shuri), [Nimbus](https://github.com/ethanal/nimbus), [Lstu](https://github.com/ldidry/lstu), and many others. And beyond the options already available, building a link shortener is a good first programming project to get to know a new language or web framework. After all, the core functionality is very simple: Take a URL as input, and issue a redirect to another URL. Beyond that, it's up to you what bells and whistles to add.
Do you have a favorite we didn't list here? Let us know in the comments below
## 2 Comments |
8,362 | wkhtmltopdf:一个 Linux 中将网页转成 PDF 的智能工具 | http://www.tecmint.com/wkhtmltopdf-convert-website-html-page-to-pdf-linux/ | 2017-04-01T08:02:00 | [
"PDF",
"wkhtmltopdf"
] | https://linux.cn/article-8362-1.html | wkhtmltopdf 是一个开源、简单而有效的命令行 shell 程序,它可以将任何 HTML (网页)转换为 PDF 文档或图像(jpg、png 等)。
wkhtmltopdf 是用 C++ 编写的,并在 GNU/GPL (通用公共许可证)下发布。它使用 WebKit 渲染引擎将 HTML 页面转换为 PDF 文档且不会丢失页面的质量。这是一个用于实时创建和存储网页快照的非常有用且可信赖的解决方案。

### wkhtmltopdf 的功能
1. 开源并且跨平台。
2. 使用 WebKit 引擎将任意 HTML 网页转换为 PDF 文件。
3. 添加页眉和页脚的选项
4. 目录生成 (TOC) 选项。
5. 提供批量模式转换。
6. 通过绑定 libwkhtmltox 来支持 PHP 或 Python。
在本文中,我们将介绍如何在 Linux 系统下使用 tar 包来安装 wkhtmltopdf。
### 安装 Evince (PDF 浏览器)
让我们在 Linux 系统中安装 evince (一个 PDF 阅读器)来浏览 PDF 文件。
```
$ sudo yum install evince [RHEL/CentOS and Fedora]
$ sudo dnf install evince [On Fedora 22+ versions]
$ sudo apt-get install evince [On Debian/Ubuntu systems]
```
### 下载 wkhtmltopdf 源码文件
使用 [wget 命令](/tag-wget.html)根据你的 Linux 架构来下载 wkhtmltopdf 源码文件,或者你也可以在 [wkhtmltopdf 下载页](http://wkhtmltopdf.org/downloads.html)下载最新的版本(目前最新的稳定版是 0.12.4)
在 64 位 Linux 系统中:
```
$ wget http://download.gna.org/wkhtmltopdf/0.12/0.12.4/wkhtmltox-0.12.4_linux-generic-amd64.tar.xz
```
在 32 位 Linux 系统中:
```
$ wget http://download.gna.org/wkhtmltopdf/0.12/0.12.4/wkhtmltox-0.12.4_linux-generic-i386.tar.xz
```
### 在 Linux 中安装 wkhtmltopdf
使用 [tar 命令](/tag-tar.html)解压文件到当前目录中。
```
------ On 64-bit Linux OS ------
$ sudo tar -xvf wkhtmltox-0.12.4_linux-generic-amd64.tar.xz
------ On 32-bit Linux OS ------
$ sudo tar -xvzf wkhtmltox-0.12.4_linux-generic-i386.tar.xz
```
为了能从任意路径执行程序,将 wkhtmltopdf 安装到 `/usr/bin` 目录下。
```
$ sudo cp wkhtmltox/bin/wkhtmltopdf /usr/bin/
```
### 如何使用 wkhtmltopdf?
我们会看到如何将远程的 HTML 页面转换成 PDF 文件、验证信息、使用 evince 在 GNOME 桌面中浏览创建的文件。
#### 将 HTML 网页转成 PDF 文件
要将任意 HTML 页面转换成 PDF,运行下面的命令。它会在当前目录下将页面转换成 [10-Sudo-Configurations.pdf](http://www.tecmint.com/sudoers-configurations-for-setting-sudo-in-linux/)。
```
# wkhtmltopdf http://www.tecmint.com/sudoers-configurations-for-setting-sudo-in-linux/ 10-Sudo-Configurations.pdf
```
示例输出:
```
Loading pages (1/6)
Counting pages (2/6)
Resolving links (4/6)
Loading headers and footers (5/6)
Printing pages (6/6)
Done
```
#### 浏览生成的 PDF 文件
为了验证创建的文件,使用下面的命令。
```
$ file 10-Sudo-Configurations.pdf
```
示例输出:
```
10-Sudo-Configurations.pdf: PDF document, version 1.4
```
#### 浏览生成的 PDF 文件细节
要浏览生成的文件信息,运行下面的命令。
```
$ pdfinfo 10-Sudo-Configurations.pdf
```
示例输出:
```
Title: 10 Useful Sudoers Configurations for Setting 'sudo' in Linux
Creator: wkhtmltopdf 0.12.4
Producer: Qt 4.8.7
CreationDate: Sat Jan 28 13:02:58 2017
Tagged: no
UserProperties: no
Suspects: no
Form: none
JavaScript: no
Pages: 13
Encrypted: no
Page size: 595 x 842 pts (A4)
Page rot: 0
File size: 697827 bytes
Optimized: no
PDF version: 1.4
```
#### 浏览创建的文件
在桌面中使用 evince 查看最新生成的 PDF 文件。
```
$ evince 10-Sudo-Configurations.pdf
```
示例截图:
在我的 Linux Mint 17 中看起来很棒。

*在 PDF 中浏览网页*
### 给 PDF 创建页面的 <ruby> 目录 <rp> ( </rp> <rt> Table Of Content </rt> <rp> ) </rp></ruby>(TOC)
要创建一个 PDF 文件的目录,使用 toc 选项。
```
$ wkhtmltopdf toc http://www.tecmint.com/sudoers-configurations-for-setting-sudo-in-linux/ 10-Sudo-Configurations.pdf
```
示例输出:
```
Loading pages (1/6)
Counting pages (2/6)
Loading TOC (3/6)
Resolving links (4/6)
Loading headers and footers (5/6)
Printing pages (6/6)
Done
```
要查看已创建文件的 TOC,再次使用 evince。
```
$ evince 10-Sudo-Configurations.pdf
```
示例截图:
看一下下面的图。它上看去比上面的更好。

*在 PDF 中创建网页的目录*
#### wkhtmltopdf 选项及使用
更多关于 wkhtmltopdf 的使用及选项,使用下面的帮助命令。它会显示出所有可用的选项。
```
$ wkhtmltopdf --help
```
---
作者简介:
我是 Ravi Saive,TecMint 的创建者。一个爱在网上分享的技巧和提示的电脑极客和 Linux 专家。我的大多数服务器运行在名为 Linux 的开源平台上。请在 Twitter、 Facebook 和 Google+ 等上关注我。
---
via: <http://www.tecmint.com/wkhtmltopdf-convert-website-html-page-to-pdf-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,363 | 一个值得推荐的发行版:Manjaro Linux | http://www.techphylum.com/2016/07/manjaro-linux-explained.html | 2017-04-01T08:52:02 | [
"Manjaro",
"Arch"
] | https://linux.cn/article-8363-1.html | 在这个系列的第七篇,我们来说一说什么是 Manjaro。[Manjaro](https://manjaro.org/) 是基于 Arch Linux 并且拥有一个漂亮的用户界面的操作系统。 Manjaro 并不像 Debian 或者 Arch 这些 Linux 发行版一样历史悠久,但是它依然十分的稳定而可靠,从而在各色发行版中显得鹤立鸡群。2011 年 Manjaro 才推出了第一个版本。从那以后它一直在不断的进步,今天最新的版本为 16.06.1,代号为 “Daniella”。(LCTT 译注:本文写作于 2016 年,当下最新版本是:17.0 )

**为什么我认为 Manjaro 超越了其他的发行版?** 我并没有强求你使用 Manjaro 来替代其他发行版,但是我会尝试说服你来使用 Manjaro。那么让我开始吧!
### 基于 Arch
就像许多人已经知道的那样,不开玩笑的说 Arch 绝对是一个优秀的发行版。但是它对于新手来说十分难以使用。许多新手根本就无法在非图形界面下完成 Arch 的安装。与之相反,Manjaro 有着一个好用的图形安装界面。所以那些想要尝试 Arch 但是又被它的高难度操作所困扰的人们可以去试试 Manjaro。Manjaro 很容易安装并且有着一个友好的用户界面。
### 桌面环境
Manjaro 在桌面环境上有着许多选择,比如 Xfce、KDE、Deepin、BspWM、Budgie、i3、LXDE、Cinnamon、Enlightenment、Netbook、Fluxbox、Gnome、JWM、LXQT、MATE、Openbox 和 PekWM。所有这些桌面环境在 Manjaro 中都十分漂亮。Manjaro 官方的桌面环境是 Xfce 和 KDE,而其他桌面环境则是社区支持的,我现在就是在 Manjaro 16.06.1 中使用 KDE Plasma 桌面环境。

*运行着 KDE plasma 5.6.5 的 Manjaro 16.06.1*
如果你不喜欢 Manjaro 中的 KDE 或者 Xfce,不用担心,你可以从软件包管理器中随时安装其他桌面环境。

*从软件包管理器中下载 Budgie 桌面环境。*
### 稳定并且独特的包管理机制
虽然 Manjaro 很新,但是它也很稳定。Manjaro 的最后一个版本装载的是Linux 内核 4.6.2。Manjaro 不仅仅稳定,更新也比较快。软件更新不久后,就会被它编译到它的库中。Manjaro 用 pacman 来管理它的软件包。Arch Linux 因 Pacman 而名震天下 (当然也饱受争议)。Manjaro 则使用 Octopi 来使其变得更加用户友好,Octopi 是一个用 Qt 编写的 pacman 的图形前端。Manjaro 很好的维护了他自己的库,这也是它的一个优势。

*Octopi 软件包管理器*
### 社区支持
和其他发行版一样,Manjaro 也是一个基于社区的 linux 发行版。当你需要的时候,社区里总是会有人来帮助你。除了 Xfce 和 KDE 是官方支持的以外,其他所有桌面的编译和维护都是由社区完成的。任何用户有了疑问都可以到社区来寻求帮助,这里总是会有真实的 Manjaro 用户来帮助你。
在这里,我仅仅只列出了这么几点原因,但是如果你开始使用它了,你会发现更多惊喜的。
**还在考虑是否安装它?** 如果你还在彷徨与是否使用 Manjaro 你可以先在 Virtualbox 中试试它,然后再考虑在实体机中安装它。如果你喜欢它,请在这个话题下评论吧,欢迎点赞,关注,丢香蕉给我们,么么哒。
---
原文: <http://www.techphylum.com/2016/07/manjaro-linux-explained.html>
作者:[sumit rohankar](https://plus.google.com/112160169713374382262) 译者:[Chao-zhi](https://github.com/Chao-zhi) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
8,364 | 10 个常见的 Linux 终端仿真器 | http://www.linuxandubuntu.com/home/10-best-linux-terminals-for-ubuntu-and-fedora | 2017-04-01T09:10:05 | [
"终端",
"终端模拟器"
] | https://linux.cn/article-8364-1.html | 
对于 Linux 用户来说,最重要的应用程序之一就是终端仿真器。它允许每个用户获得对 shell 的访问。而 Bash 是 Linux 和 UNIX 发行版中最常用的 shell,它很强大,对于新手和高级用户来说,掌握 bash 都很有必要。因此,在这篇文章中,你可以了解 Linux 用户有哪些优秀的终端仿真器可以选择。
### 1、Terminator
这个项目的目标是创造一个能够很好排列终端的有用工具。它受到一些如 gnome-multi-term、quadkonsole 等程序的启发,重点是以网格的形式排列终端。
#### 特性浏览
* 以网格形式排列终端
* Tab 设定
* 通过拖放重新排布终端
* 大量的快捷键
* 通过 GUI 参数编辑器保存多个布局和配置文件
* 同时对任意组合的终端进行输入

你可以通过下面的命令安装 Terminator:
```
sudo apt-get install terminator
```
### 2、Tilda - 一个可以下拉的终端
**Tilda** 的独特之处在于它不像一个普通的窗口,相反,你可以使用一个特殊的热键从屏幕的顶部拉下和收回它。 另外,Tilda 是高度可配置的,可以自定义绑定热键,改变外观,以及其他许多能够影响 Tilda 特性的选项。
在 Ubuntu 和 Fedora 上都可以使用包管理器安装 Tilda,当然,你也可以查看它的 [GitHub 仓库](https://github.com/lanoxx/tilda)。

### 3、Guake
Guake 是一个和 Tilda 或 yakuake 类似的下拉式终端仿真器。如果你知道一些关于 Python、Git 和 GTK 的知识的话,你可以给 Guake 添加一些新的特性。 Guake 在许多发行版上均可用,所以如果你想安装它,你可以查看你的版本仓库。
#### 特性浏览
* 轻量
* 简单易用且优雅
* 将终端自然地集成到 GUI 之中
* 当你使用的时候出现,一旦按下预定义热键便消失(默认情况下是 F12)
* 支持Compiz 透明
* 多重 Tab
* 丰富的调色板
* 还有更多……
主页:<http://guake-project.org/>
### 4、ROXTerm
如果你正在寻找一个轻量型、高度可定制的终端仿真器,那么 ROXTerm 就是专门为你准备的。这是一个旨在提供和 gnome-terminal 相似特性的终端仿真器,它们都基于相同的 VTE 库。它的最初设计是只占用很小的资源并且能够快速启动,它具有比 gnome-terminal 更强的可配置性,更加针对经常使用终端的 “Power” 用户。

主页:[http://roxterm.sourceforge.net/index.php?page=index&lang=en](http://roxterm.sourceforge.net/index.php?page=index&lang=en)
### 5、XTerm
Xterm 是 Linux 和 UNIX 系统上最受欢迎的终端仿真器,因为它是 X 窗口系统的默认终端仿真器,并且很轻量、很简单。
[](http://www.linuxandubuntu.com/uploads/2/1/1/5/21152474/xterm-linux-terminal_orig.png)
### 6、Eterm
如果你正在寻找一个漂亮、强大的终端仿真器,那么 Eterm 是你最好的选择。Eterm 是一个彩色 vt102 终端仿真器,被当作是 Xterm 的替代品。它按照自由选择的哲学思想进行设计,将尽可能多的权利、灵活性和自由交到用户手中。

主页: <http://www.eterm.org/>
### 7、Gnome Terminal
Gnome Terminal 是最受欢迎的终端仿真器之一,它被许多 Linux 用户使用,因为它默认安装在 Gnome 桌面环境中,而 Gnome 桌面很常用。它有许多特性并且支持大量主题。
在许多 Linux 发行版中都默认安装有 Gnome Terminal,但你如果没有的话,也可以使用你的包管理器来安装它。

### 8、Sakura
Sakura 是一个基于 GTK 和 VTE 的终端仿真器。它是一个只有很少依赖的终端仿真器,所以你不需要先安装一个完整的 GNOME 桌面才能有一个像样的终端仿真器。
你可以使用你的包管理器来安装它,因为 Sakura 在绝大多数发行版中都是可用的。
### 9、LilyTerm
LilyTerm 是一个基于 libvte 的终端仿真器,旨在快速和轻量,是 GPLv3 授权许可的。
#### 特性浏览
* 低资源占用
* 多重 Tab
* 配色方案丰富
* 支持超链接
* 支持全屏
* 还有更多的……

### 10、Konsole
如果你是一名 KDE 或 Plasma 用户,那么你一定知道 Konsole,因为它是 KDE 桌面的默认终端仿真器,也是我最喜爱的终端仿真器之一,因为它很舒适易用。
它在 Ubuntu 和 fedora 上均可用,但如果你在使用 Ubuntu (Unity),那么你需要选择别的终端仿真器,或者你可以考虑使用 Kubuntu 。

### 结论
我们是 Linux 用户,根据自己的需求,可以有许多选择来挑选更好的应用。因此,你可以选择**最好的终端**来满足个人需求,虽然你也可以选择另一个 shell 来满足个人需求,比如你也可以使用 fish shell。
---
via: <http://www.linuxandubuntu.com/home/10-best-linux-terminals-for-ubuntu-and-fedora>
作者:[Mohd Sohail](https://disqus.com/by/MohdSohail1/) 译者:[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,365 | 漫画赏析:用户空间选举大会 | http://turnoff.us/geek/user-space-election/ | 2017-04-01T09:17:04 | [
"漫画"
] | https://linux.cn/article-8365-1.html | 继上篇“[漫画赏析: Vi 还是不 Vi,这是个问题](/article-8342-1.html)”,已经有一段日子。于是,昨天 (2017 年 03 月 28 日) 翻了翻 [Daniel](http://turnoff.us/about/) 的漫画,看到了这篇有点委婉的漫画,遂将之进行汉化并分享给大家。

如上图,用户空间选举大会中,各大进程都参与竞选。但是呢,结果出乎大家意料,这个大家都不熟悉的 Prumt 先生赢得了主席之位。
在这位 Prumt 主席上位之后,他高调宣布了一些决定:废除 Unicode 编码,重新启用使用范围较小的 ASCII 编码。
这是不是很排外呢?看到这幅漫画的小伙伴,你想到了什么呢?
---
via: <http://turnoff.us/geek/user-space-election/>
作者:[Daniel Stori](https://turnoff.us/about/) 译者:[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,367 | 开发者的实用 Vim 插件(三) | https://www.howtoforge.com/tutorial/vim-editor-plugins-for-software-developers-3/ | 2017-04-02T09:03:13 | [
"Vim",
"开发",
"插件"
] | https://linux.cn/article-8367-1.html | 目前为止,在一系列介绍 vim 插件文章中,我们介绍了使用 Pathogen 插件管理包安装基本的 vim 插件,也提及了另外三个插件:[Tagbar、delimitMate](/article-7901-1.html) 和 [Syntastic](/article-7909-1.html)。现在,在最后一部分,我们将介绍另一个十分有用的插件 a.vim。
请注意所有本篇教程所提及的例子、命令和指导,它们已经在 Ubuntu 16.04 测试完毕,vim 使用版本为 vim7.4 (LCTT 译注:Ubuntu 16.04 的默认版本)。

### A.vim
如果你一直用像 C、C++ 这样的语言进行开发工作,你一定有这样的感触:我特么已经数不清我在头文件和源代码之间切换过多少次了。我想说的是,确实,这个操作十分基本,十分频繁。
尽管使用基于 GUI(图形界面)的 IDE(集成开发环境)非常容易通过鼠标的双击切换文件,但是如果你是资深 vim 粉,习惯用命令工作就有点尴尬了。但是不要害怕,我有秘籍--插件 a.vim。它可以让你解决尴尬,专治各种文件切换。
在我们介绍这个神器用法之前,我必须强调一点:这个插件的安装过程和我们其他篇介绍的不太一样,步骤如下:
* 首先,你需要下载两个文件(`a.vim` 和 `alternate.txt`),你可以在[这里](http://www.vim.org/scripts/script.php?script_id=31)找到它们。
* 接下来,创建如下目录:`~/.vim/bundle/avim`、`~/.vim/bundle/avim/doc`、 `~/.vim/bundle/avim/plugin` 和 `~/.vim/bundle/autoload`。
* 创建好目录之后,将 `a.vim` 放到 `~/.vim/bundle/avim/plugin` 和 `~/.vim/bundle/autoload`,以及将 `alternate.txt` 放到 `~/.vim/bundle/avim/doc`。
就是这样,如果上述步骤被你成功完成,你的系统就会安装好这个插件。
使用这个插件十分简单,你仅仅需要运行这个命令 `:A` 如果目前的文件是源文件(比如 `test.c`),这个神器就会帮你打开 `test.c` 对应的头文件(`test.h`),反之亦然。
当然咯,不是每个文件对应的头文件都存在。这种情况下,如果那你运行 `:A` 命令,神器就会为你新建一个文件。比如,如果 `test.h` 不存在,那么运行此命令就会帮你创建一个 `test.h`,然后打开它。
如果你不想要神器开启此功能,你可以在你的家目录的隐藏文件 `.vimrc` 中写入 `g:alternateNonDefaultAlternate` 变量,并且赋给它一个非零值即可。
还有一种情况也很普遍,你需要打开的文件并非是当前源代码的头文件。比如你目前在 `test.c` 你想打开 `men.h` 这个头文件,那么你可以输入这个命令 `:IH <filename>` ,毋需赘言,你肯定要在后面输入你要打开的的文件名称 `<filename>`。
目前为止,我们讨论的功能都仅限于你当前文件和要操作的文件都在同一个目录去实现。但是,你也知道,我们还有特殊情况,我是说,许多项目中头文件与对应的源文件并不一定在同一目录下。
为了搞定这个问题,你要使用这个 `g:alternateSearchPath` 这个变量。官方文档是这么[解释](https://github.com/csliu/a.vim/blob/master/doc/alternate.txt)的:
>
> 这个插件可以让用户配置它的搜索源文件和头文件的搜索路径。这个搜索路径可以通过设置 `g:alternateSearchPath` 这个变量的值指定。默认的设定如下:
>
>
>
> ```
> g:alternateSearchPath = 'sfr:../source,sfr:../src,sfr:../include,sfr:../inc'
>
> ```
>
> 使用这个代码表示神器将搜索 `../source`、`../src`、`../include` 和 `../inc` 下所有与目标文件相关的文件。 `g:alternateSearchPath` 变量的值由前缀和路径组成,每个单元用逗号隔开。 `sfr` 前缀是指后面的路径是相对于目前文件的,`wdr` 前缀是指目录是相对于目前的工作目录, `abs` 是指路径是绝对路径。如果不指定前缀,那么默认为 `sfr`。
>
>
>
如果我们前文所提及的特性就能让你觉得很炫酷,那我不得不告诉你,这才哪跟哪。还有一个十分有用的功能是分割 Vim 屏幕,这样你就可以同时看到头文件和相应的源文件。
哦,还有,你还可以选择垂直或者水平分割。全凭你心意。使用 `:AS` 命令可以水平分割,使用 `:AV` 可以垂直分割。


使用 `:A` 命令在已经打开的文件中切换。
这个插件还可以让你在同一个 Vim 窗口中不同选项卡中打开多个相应的文件,你键入这个命令 `:AT`。

当然,你可以用这些命令 `:AV`、`:AS` 和 `:AT`,也可以使用这些命令 `:IHV`、`:IHS` 和 `:IHT`。
### 最后
还有许多和编程相关的 Vim 的插件,我们在这个三篇系列主要讨论的是,如果你为你的软件开发工作安装了合适的插件,你就会明白为什么 vim 被叫做编辑器之神。
当然,我们在这只关注编程方面,对于那些把 Vim 当做日常文档编辑器的人来说,你也应该了解一些 Vim 的插件,让你的编辑更好,更高效.我们就改日再谈这个问题吧。
---
via: <https://www.howtoforge.com/tutorial/vim-editor-plugins-for-software-developers-3/>
作者:[Ansh](https://www.howtoforge.com/tutorial/vim-editor-plugins-for-software-developers-3/) 译者:[Taylor1024](https://github.com/Taylor1024) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 200 | OK | # Useful Vim editor plugins for software developers - part 3: a.vim
Up until now, in this series of articles covering programming-related plugins for Vim, we discussed basics of Vim plugin installation using Pathogen plugin manager, and covered a total of three plugins - namely [Tagbar, delimitMate](https://www.howtoforge.com/tutorial/vim-editor-plugins-for-software-developers/), and [Syntastic](https://www.howtoforge.com/tutorial/vim-editor-plugins-for-software-developers-2-syntastic/). Now, in this third and the final part, we will discuss another very useful plugin dubbed **a.vim**.
Please note that all the examples, commands, and instructions mentioned in this tutorial have been tested on Ubuntu 16.04, and the Vim version we've used is 7.4.
## A.vim
If you are into software development and work with programming languages like C and C++, you'd agree that it's practically impossible to tell how many times you have to switch between source and header files. What I mean to say is that it's a very basic task that's done very frequently.
While it's easy to switch between files when using a GUI-based IDE (as you just have to do a couple of mouse clicks), things get a bit difficult if you are using a command line IDE like Vim. However, as you'd have guessed by now, there exists a plugin - called a.vim - that makes life easier for you especially when it comes to switching between source and header files.
Before we jump over to the usage, it's worth mentioning that installation process for this plugin is different from the way we've be installing the other plugins discussed in this article series. Following are the steps involved in this case:
- Firstly, you need to download a couple of files (a.vim and alternate.txt), which you can do by heading
[here](http://www.vim.org/scripts/script.php?script_id=31). - Next, create the following directories:
*~/*.,`vim/bundle/avim`
*~/*.,`vim/bundle/avim/doc`
*~/*., and`vim/bundle/avim/plugin`
*~/*.*vim/bundle/autoload*. - Once the directory creation is done, put a.vim into
*~/.vim/bundle/avim/plugin*as well as*~/.vim/bundle/autoload*, and alternate.txt into*~/.vim/bundle/avim/doc*.
That's it. If all the aforementioned steps are completed successfully, the plugin will be installed on your system.
Using the plugin is very simple: All you have to do is to run the **:A** command - if the current file is a source file (say test.c), the plugin will open the corresponding header file (test.h) for you (vice-versa is true as well).
Obviously, not every time a corresponding file with the same name exists. In these cases, running **:A** will create a new file with that name. For example, if test.h doesn't exist, a file with that name will be created and opened for you.
In case you want to disable this behavior, you can set the *g:alternateNoDefaultAlternate* variable (give it a non-zero value) in the *.vimrc* file present in your home directory.
Moving on, it's pretty normal to refer to a non-corresponding header file from a source file as well. For example, if you are in test.c, and want to switch to some other header file (say mem.h) and not test.h, then you can do that by running the :**IH <filename>** command in Vim. Needless to say, you'll have to replace <filename> with the actual name of the file you need to open.
Up until now, whatever functionality we discussed is assuming that the file that you intend to open is present in the same directory as the current file. However, as you'd agree, it's not always the case. What I mean to say is that in many projects the location of the source files and the corresponding header files is not always the same directory.
To handle such situations, you need to use the *g:alternateSearchPath* variable. This is what the official documentation [says](https://github.com/csliu/a.vim/blob/master/doc/alternate.txt) about this variable:
"This plugin allows the search path it uses to locate source and header files to be configured. The search path is specified by setting the g:alternateSearchPath variable. The default setting is as follows:"
`g:alternateSearchPath = 'sfr:../source,sfr:../src,sfr:../include,sfr:../inc' `
"This indicates that the corresponding file will be searched for in ../source, ../src. ../include and ../inc all relative to the current file being switched from. The value of the g:alternateSearchPath variable is simply a comma separated list of prefixes and directories. The "sfr:" prefix indicates that the path is relative to the file. Other prefixes are "wdr:" which indicates that the directory is relative to the current working directory and "abs:" which indicates the path is absolute. If no prefix is specified "sfr:" is assumed."
If all the aforementioned features of this plugin have already made you go "wow," let me tell you that's not all. Another extremely useful functionality the plugin offers is the ability to split your Vim screen so that both source and its corresponding header file can be viewed simultaneously.
What more, you can split the screen both horizontally and vertically, depending upon what fits best for you. Use **:AS** command to split the screen horizontally and **:AV** command for vertical split.
Use **:A** command to switch between opened files.
The plugin also lets you open a corresponding file in a separate tab within the same Vim window. You can do this by running the **:AT** command.
Of course, like **:AV**, **:AS**, and **:AT**, you can use **:IHV**, **:IHS**, and **:IHT** commands as well.
## Conclusion
While there are many programming-related Vim plugins available to use, the ones that we discussed in this three-part series should be enough to give you an idea about how powerful the editor becomes if you have the correct plugins enabled for your software development work.
**Of course, we've only focused on the programming part here. For those of you who use Vim as you daily text editor, you should know that there are a plethora of plugins available that add to Vim's text editing functionality and make it even better. But we'll leave this discussion for some other day.** |
8,368 | 为什么使用 Go 语言? | https://dave.cheney.net/2017/03/20/why-go | 2017-04-02T18:04:00 | [
"编程语言",
"Go"
] | https://linux.cn/article-8368-1.html | 几个星期前,我一个朋友问我:“为什么要关心 Go 语言”? 因为他们知道我热衷于 Go 语言,但他们想知道为什么我认为*其他人*也应该关心。本文包含三个我认为 Go 是重要的编程语言的原因。

### 安全
个人而言,你和我或许完全有能力在 C 中编写程序,既不会泄漏内存,也不会不安全地重复使用内存。然而,整体上,即使有超过 [40 年](https://en.wikipedia.org/wiki/C_(programming_language))的经验,用 C 的程序员也无法可靠地这样做。
尽管静态代码分析、valgrind、tsan 以及 “-Werror” 已经存在了几十年,却很少有证据表明这些工具被广泛认可,更不用说广泛采用。总而言之,事实表明,程序员根本无法安全地管理自己的内存。现在是离开 C 的时候了。
Go 不需要程序员直接管理内存,所有内存分配都由语言运行时自行管理,使用前初始化,必要时检查边界。它肯定不是提供这些安全保障的第一个主流语言,Java(1995)可能是该冠军的竞争者。关键是,世界对不安全的编程语言没有胃口,所以人们默认认为,Go 是内存安全的。
### 开发人员生产力
从 20 世纪 70 年代末,开发人员的时间变得比硬件所耗费的时间更昂贵了。开发人员的生产力是一个不断扩展的话题,但它归结为这一点:你花了多少时间做有用的工作,又有多少时间等待编译器或者失望地迷失在外部代码库中。
有个笑话说 Go 是在等待 [C ++ 程序编译](https://commandcenter.blogspot.com.au/2012/06/less-is-exponentially-more.html)时开发的。快速编译是 Go 的一个重要功能,也是吸引新开发人员的关键工具。虽然编译速度仍然是一个[永久的战场](https://dave.cheney.net/2016/11/19/go-1-8-toolchain-improvements),但公平地说,在其他语言中需要几分钟的编译,在 Go 中只需要几秒钟。
Go 程序员意识到生产力的更根本的问题是代码是**为了读而写的**,所以将[代码的阅读行为放在编写之上](https://twitter.com/rob_pike/status/791326139012620288)。Go 通过工具和自定义来强制所有代码格式化成特定的样式。这消除了学习项目特定语言的方言时的困难,并有助于发现错误,因为它们**看上去**就是不正确。
由于专注于分析和机器辅助,Go 开发人员开始采用越来越多的工具来发现常见的编码错误,这种工具从来没有在 C 语言开发者中产生共鸣 - Go 开发人员**希望**工具帮助他们保持代码清洁。
### 并发性
十多年来,芯片设计师一直在警告[免费午餐将会结束](http://www.gotw.ca/publications/concurrency-ddj.htm)。从最低端的手机到最耗电的服务器,硬件的并行性以[更多、更慢、堆砌 cpu 内核](https://www.technologyreview.com/s/601441/moores-law-is-dead-now-what/)的形式出现,但只有**当**你的语言可以利用它们才有意义。因此,并发特性需要内置到我们编写的要在今天的硬件上运行的软件中。
通过提供一种基于协程的[轻量级并发模型](https://blog.golang.org/concurrency-is-not-parallelism),或者是 Go 中已知的 goroutines,Go 超越了那些暴露操作系统的多进程或多线程并行模型的语言。goroutines 允许程序员避开复杂的回调,而语言运行时确保有足够的线程来保持你的内核的活跃。
### 总结
我给朋友推荐 Go 有三个原因:安全性、生产力和并发性。有些语言可以涵盖一个也有可能是两个方面,但是这三个方面的结合使得 Go 成为主流程序员的绝佳选择。
### 相关文章:
1. [为什么 Go 和 Rust 不是竞争对手](https://dave.cheney.net/2015/07/02/why-go-and-rust-are-not-competitors)
2. [听听我在 OSCON 上谈 Go 语言性能](https://dave.cheney.net/2015/05/31/hear-me-speak-about-go-performance-at-oscon)
3. [我在 GopherChina 和 GopherCon Singapore 中的演讲](https://dave.cheney.net/2017/02/09/im-speaking-at-gopherchina-and-gophercon-singapore)
4. [压力测试你 Go 包](https://dave.cheney.net/2013/06/19/stress-test-your-go-packages)
---
via: <https://dave.cheney.net/2017/03/20/why-go>
作者:[Dave Cheney](https://dave.cheney.net/) 译者:[geekpi](https://github.com/geekpi) 校对:[jasminepeng](https://github.com/jasminepeng)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 200 | OK | A few weeks ago I was asked by a friend, “why should I care about Go”? They knew that I was passionate about Go, but wanted to know why I thought *other people* should care. This article contains three salient reasons why I think Go is an important programming language.
# Safety
As individuals, you and I may be perfectly capable of writing a program in C that neither leaks memory or reuses it unsafely. However, with more than [40 years](https://en.wikipedia.org/wiki/C_(programming_language)) of experience, it is clear that programmers working in C are unable to reliably do so *en masse*.
Despite tools such as static code analysis, valgrind, tsan, and `-Werror`
being available for a decades, there is scant evidence those tools have achieved widespread acknowledgement, let alone widespread adoption. In aggregate, programmers have shown they simply cannot safely manage their own memory.
Go does not rely on the programmer to manage memory directly, instead all memory allocation is managed by the language runtime, initialized before use, and bounds checked when necessary. It’s certainly not the first mainstream language that offered these safety guarantees, Java (1995) is probably a contender for that crown. The point being, the world has no appetite for unsafe programming languages, thus Go is memory safe by default.
# Developer productivity
The point at which developer time became more expensive than hardware time was crossed back in the late 1970s. Developer productivity is a sprawling topic but it boils down to this; how much time do you spend doing useful work vs waiting for the compiler or hopelessly lost in a foreign codebase.
The joke goes that Go was developed while waiting for a [C++ program to compile](https://commandcenter.blogspot.com.au/2012/06/less-is-exponentially-more.html). Fast compilation is a key feature of Go and a key recruiting tool to attract new developers. While compilation speed remains a [constant battleground](https://dave.cheney.net/2016/11/19/go-1-8-toolchain-improvements), it is fair to say that compilations which take minutes in other languages, take seconds in Go.
More fundamental to the question of developer productivity, Go programmers realise that code is *written to be read* and so place the [act of reading code above the act of writing it](https://twitter.com/rob_pike/status/791326139012620288). Go goes so far as to enforce, via tooling and custom, that all code by formatted in a specific style. This removes the friction of learning a project specific language sub-dialect and helps spot mistakes because they just *look incorrect.*
Due to a focus on analysis and mechanical assistance, a growing set of tools that exist to spot common coding errors have been adopted by Go developers in a way that never struck a chord with C programmers—Go developers *want* tools to help them keep their code clean.
# Concurrency
For more than a decade, chip designers have been warning that the [free lunch is over](http://www.gotw.ca/publications/concurrency-ddj.htm). Hardware parallelism, from the lowliest mobile phone to the most power hungry server, in the form of [more, slower, cpu cores](https://www.technologyreview.com/s/601441/moores-law-is-dead-now-what/), is only available *if* your language can utilise them. Therefore, concurrency needs to be built into the software we write to run on today’s hardware.
Go takes a step beyond languages that expose the operating system’s multi-process or multi-threading parallelism models by offering a [lightweight concurrency model based on coroutines](https://blog.golang.org/concurrency-is-not-parallelism), or goroutines as they are known in Go. Goroutines allows the programmer to eschew convoluted callback styles while the language runtime makes sure that there will be just enough threads to keep your cores active.
# The rule of three
These were my three reasons for recommending Go to my friend; safety, productivity, and concurrency. Individually, there are languages that cover one, possibly two of these domains, but it is the combination of all three that makes Go an excellent choice for mainstream programmers today. |
8,369 | CxO 们的容器实践指南 | https://opensource.com/article/17/1/container-strategy-for-executives | 2017-04-03T08:43:00 | [
"云服务",
"容器",
"微服务"
] | https://linux.cn/article-8369-1.html | 
与互联网领域的领导们关于"容器"的讨论通常被总结如下:
*作为一名 CxO,我面临杠杆时间术的持续的压力。IT 预算不断减少,我只有有限的资源。然而,交付的工作量却比以往更多。我花费太多的时间致力于解决预算的约束。另外,互联网的格局正在经历一个快速的改变,而且新的技术一直在被引进。我从我最信任的顾问那听来的最新的话题是一个“容器策略”的实现。我想理解:*
1. *什么是容器?*
2. *过渡到容器的企业价值是什么?*
3. *为什么我现在应该转移到容器?如果我不采纳会有一些坏处吗?*
4. *容器是否已经足够成熟用于企业消费?*
5. *我如何让我的企业因使用容器而快速地发展?*
让我们从最开头开始。
### 容器
在过去的 10 年左右,企业已经从物理基础设施转向了虚拟机(VM)。转向 VM 的关键优势是可以减少数据中心的用量。通过在同一个物理机器上运行多个虚拟机,你可以在更少数量的物理机器上安装更多的应用程序。使用容器是另一种更轻量地打包应用程序的方式,而且其交付模式更快。它们是一种在单一的机器里运行多个应用程序进程的奇特方式,无论那个机器是一个虚拟机还是一个物理机。另外,容器在 DevOps 、微服务和云战略场景方面也扮演了重要角色。
### 容器 vs 虚拟机
容器和虚拟机在一些方面并不相同。一台虚拟机尽管不是物理机,但是它表现地就像是一台物理机。虚拟机是一个包含所有东西的独立的环境,是一个完整的(来宾)操作系统。在另一方面,容器是一个共享同一个物理机或虚拟机上资源的进程。容器显然更加有趣,因为:
* 相比较而言,虚拟机要重一些,而容器更轻。因为容器只包括了它们所运行的程序所需要的库。
* 虚拟机需要花费几分钟来启动,而容器在几秒钟内就可以启动。
* 通常,相比虚拟机,你的基础设施中可以容纳更多的容器。

技术已经发展到足以保持这些容器安全、彼此独立,而且正确的设计选择可以保证那些坏掉的容器不会影响运行在同一个机器里的其他容器的性能。实际上,操作系统天生就是被用来构建成优化和运行容器的。
然而,当你转向容器时,你需要做出正确的选择。你需要做足够的尽职调查,以便你选择合适的技术合作伙伴和能够制作容器的制造商。开源技术起着很关键的作用。开源的 [Docker 项目](https://opensource.com/resources/what-docker)使得分层格式的容器很容易构建和使用。[开放容器计划](https://opensource.com/business/16/8/inside-look-future-linux-containers)(OCI)已经成为被所有主要技术供应商所支持的开源容器标准。如 Red Hat 这样的开源技术提供商提供了为容器而准备的安全的操作系统。例如, Red Hat Enterprise Linux 7.x (包括 Red Hat Enterprise Linux 原子主机)进行了优化以原生地运行容器,同时也提供监控和管理容器的工具。其他的开源项目如来自 Tectonic 的 CoreOS 也正在进入市场。的确,容器正等着被企业所采用。
### 容器平台
容器平台让容器成为企业消耗品。在过去这些年中,你可能在你的企业里处理过虚拟机散乱的问题,容器散乱比那要糟糕好几倍。在你的数据中心横跨不同主机运行不同规模的容器,尽管容器故障仍然保证你的应用程序的高可用性,自动化健康检查和基于流入的工作载荷的自动化容器缩放等等,这些是你能期待容器平台应该有的一些关键特性。
当在一个被定位为容器即服务模型(CaaS)的平台上运行容器时,这些平台的一些其它特性如自动化生成和部署使这个平台成为平台即服务模型(PaaS)。虽然 CaaS 能让你规模化运行容器,但是,PaaS 可以让你利用你的源代码编译、创建容器,为你运行那些容器。另外,这些平台提供了完整操作管理特性,例如,集群的管理和监控、容器的安全缺陷检测,以及安全地运行容器、跟踪日志和度量等等。
尽管一些技术供应商正在使用他们的专有技术来构建容器平台,但总的来说,企业们正在围绕建立在 [Kubernetes](https://opensource.com/resources/what-is-kubernetes)(K8S)的基础上的开源技术而进行标准化。K8S 是一项由 Google 发起的开源项目,现在很多大平台的供应商也支持它。K8S 也是[云端原生计算基金会](https://www.cncf.io/)(CNCF)的一部分,CNCF 正在发展成以云为中心技术的标准体。当你在容器平台上做出选择时,围绕开源流程编排技术的标准化是非常重要的。它基本上允许你移植到不同的容器平台,如果你不喜欢你第一次做的选择的话。K8S 还允许你的容器工作载荷可跨越不同的公有云进行迁移。这些就是为什么我们会看到越来越多的技术公司正在使用 Kubernetes 的原因。
一些企业正在试图通过拼接几个包括 K8S 在内开源项目来打造他们自己 DIY 的容器平台。这确实是比继续跟随专有技术要更好的一种解决方案,但是要完成这项工作也仍然包含很多需要探讨的地方。然而,一个企业的维护和保持这样的 DIY 平台的能力应该被认真评估。许多企业并不是想做创建 IT 平台的工作,而是他们希望运行自己的主流业务。有很多可行的基于 K8S 的解决方案,比如[红帽 OpenShift 平台容器](https://www.openshift.com/container-platform/)、[Apprenda](https://apprenda.com/)、[Deis](http://deis.io/) 和 [Rancher](http://rancher.com/),它们提供一个企业级平台,这些解决方案中的每种都有不同完整程度的功能。
这些解决方案是由供应商认证和支持。有些方案是完全的开源 PaaS 解决方案,而另外一些可能是 CaaS。根据你的企业的需求,这些解决方案可能是比 DIY 容器平台更好的替代品。
### 企业的担忧和它们与容器的关系
今天,几乎每个企业都正在与数字时代转型打交道,这些转型影响包括 DevOps 战略、微服务和云等多个领域。容器在这些领域中的每一个中都起着相当重要的作用。
### DevOps 策略
IT 组织被分成运维和应用开发,他们作为两个独立的团队运作,每一队都只有他们自己的一套目标。大多数企业为了将这两个团队联合起来正在朝 DevOps 的方向前进。
容器在 DevOps 倡议的成功中发挥着重要的作用。在 DevOps 中成功的关键标准之一是增加开发人员在运营中的份额。开发人员不仅应该把代码交给运维人员,而且他们还应该考虑他们的代码是如何在生产环境中运行的。普遍的技术是采用“架构即代码”,而不是提供几页容易出错的安装说明指示,开发团队应该提供像编程时的环境配置。
这恰恰就是容器可以解决的问题。可以作为容器的模版的容器镜像包括了从基本操作系统到应用程序代码的整个环境堆栈。利用容器,开发人员将不再只是从 Dev 到 QA 再到 Prod 这样生成应用程序;相反,他们将传递一个版本化的容器镜像,这个镜像包括生成的运行程序和它运行需要的环境。容器是包罗万象的,从操作系统库到中间件再到应用程序的所有东西都被整合进一个镜像里面。因此,容器在开发环境运行的方式和它在质量保证环境和生产环境下运行的方式完全一样。容器是 DevOps 成功的重要因素。

另外,容器平台正在进一步发展。典型的持续集成和交付(CICD)工具,如 [Jenkins](https://jenkins.io/),可以作为容器,这个容器能在容器平台本身运行整个 CICD 过程,而不需要额外的基础设施。现在你可以使用 PaaS 平台来生成和运行你的 CICD 管道。
### 微服务策略
微服务是今天 IT 领域的另一个热门话题。应用程序是这样被设计的:把应用程序分解为离散化的小的服务,每个服务完成一个小任务。这些服务中的每一个都可以根据合适的技术用不同的编程语言进行编写。它们可以由小团队(双比萨团队)创建和管理,并且可以迅速地改变它们。所有这些要求再次需要用到容器。容器足够小到成为微服务的基础。容器能够支持任何你选择的技术和语言,容器易于创建和运行,并且可以快速地改变。微服务和容器现在已经不分彼此,如果有人说不使用容器来实现微服务,他们将会受到别人奇怪的表情。
实际情况是,虽然微服务有望让情况变得简单,但是它们的扩张也增加了复杂性。有几个微服务的设计和开发模式将能使它们易于实现。这意味着开发人员现在急需这样一个开发平台,在这个平台下,开发人员可以轻松地部署和组织微服务,而且还能:
* 以一种语言不可知的方式实现这些微服务设计模式。
* 不会因代码侵入而增加代码的复杂性,以便开发人员能将许多模式的代码包括进他们的业务逻辑中。
* 足够灵活以便部署在你所选择的基础设施上,并且不会把你捆绑在特定的云上。
这就是选择一个正确的容器平台所起作用的地方。在具体的基础设施上按照某一特定供应商的方法来实现这些微服务将会把你的应用程序捆绑在那些供应商的平台上。使用类似兼容 OCI 的容器的容器化微服务将可以保证你的微服务能够被运行在任何兼容 OCI 的平台上。
选择正确的容器平台来运行你的微服务是需要做的另一个重要的决定。今天,有很少的选择和许多的 FUD。如果你作出选择时不足够慎重,其中一些选择会把你带到非标准的、特定供应商的路线上。
### 云策略
云战略是 IT 领域的又一个热门话题。无论你是否喜欢,服务化模型都是不可避免的变化。如果你不将其作为 IT 服务进行提供,你的开发团队将可能会找到创建“shadow IT”的方法来访问云。另外,尽管使用云技术将会让你从资本支出转移到运营支出,但是,管理云支出是一个不断的挑战。
云可以提供虚拟机,在你添加额外的虚拟机之前,你要确认这个云上的 CPU、内存和网络等资源都处于最佳使用状态。容器在这个地方扮演着很重要的角色。因为容器比虚拟机要小得多。并且,如果你的应用程序正运行在容器中,你可以在虚拟机中安装更多的容器,这比在每台虚拟机中运行一个应用程序组件要多很多。
公有云供应商有很多,其中 Amazon Web Services(AWS)、Microsoft Azure 和 Google Cloud 最受欢迎。另外,你可能想在你的基于 OpenStack 的数据中心里拥有你自己的私有云。这些云环境中的每一个都有它们自己的协议、API 和工具。当你想让你的应用程序在云上运行时,你不会想要让您的应用编排被云供应商所制约,也不会想要维护任何特定云的代码。在你的技术上与特定的云供应商锁定就像在未来几年内向供应商签署空白支票。
云的可移植性对您的云战略至关重要。你可以编写应用程序,而不用担心它们在哪里运行,容器平台可以将你和特定的云供应商协议隔离开来,从而避免你与一个云供应商锁定。
### 传统系统
微服务架构带给开发的优势很多,但并不是每个应用程序都可以重构它们自己,有些只能重构一部分。传统的应用程序被普遍接受,它们需要维护和管理。虽然容器可以实现微服务,但容器不仅仅只是微服务。可以想象,你可以将大型应用程序和微服务作为容器来运行,因此只要你选择正确的容器技术和正确的应用程序平台,就可以将许多(如果不是所有)的传统的应用程序作为容器运行。
### 总结
我希望这篇对各种策略和容器的深入剖析有助于你的公司对下一步进行评估。让我在评论里面了解您公司学习到的经验,或者说没能大步向前跨越,他们还需要我再提供一些什么信息。
(题图来源:[Maersk Line](https://www.flickr.com/photos/maerskline/6955071566). [CC SA-BY 4.0](https://creativecommons.org/licenses/by-sa/4.0/))
---
作者简介:
Veer Muchandi -- 开源爱好者,容器和PaaS倡导者,喜欢学习和分享。
---
via: <https://opensource.com/article/17/1/container-strategy-for-executives>
作者:[Veer Muchandi](https://opensource.com/users/veermuchandi) 译者:[zhousiyu325](https://github.com/zhousiyu) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 200 | OK | Discussions with IT leaders about "[containers](https://opensource.com/resources/what-are-linux-containers)" can often be summarized as this:
*As a CxO, I face the constant challenge of doing more with less. IT budgets continue to decrease and I have less resources, yet the amount of work to deliver is greater than ever before. I spend far too many hours dedicated to resolving budgetary constraints. In addition, the IT landscape is undergoing a rapid change and new technologies are being introduced all the time. The latest topic I hear from my trusted advisors is the implementation of a "container strategy." I want to understand: *
*What are containers?**What is the enterprise value to transitioning to containers?**Why should I shift to containers now? Are there disadvantages if we don't adopt?**Are containers mature enough for enterprise consumption?**How do I get my enterprise up to speed with container adoption?*
Let's start at the beginning.
## Containers
In the past 10 years or so, enterprises have moved from physical infrastructure to virtual machines (VMs). The key advantage of moving towards VMs is a reduction in the datacenter footprint. You can fit more applications on fewer physical machines by running multiple VMs on the same physical box. Using containers is another way of packing applications in a much lighter weight and with a much faster delivery model. They are a fancy way of running multiple application processes on a single box, regardless of whether that box is a VM or a physical machine. In addition, containers also play a major role in the context of fulfilling DevOps, microservices, and cloud strategy.
## Containers versus VMs
Containers differ from VMs in a few simple ways. A VM, while not a physical machine, behaves just like one. It is an isolated environment that includes everything, starting with a complete (guest) operating system. On the other hand, containers are processes that share the resources on the same machine, which could be physical or virtual. Containers are notably interesting because:
- VMs are heavy, comparatively. Containers are light because they only include those libraries needed by the applications they run.
- VMs take minutes to start up. Containers start up in seconds.
- Typically, many more containers fit into your infrastructure than VMs.
The technology has evolved enough to keep these containers secure, isolated from each other, and "with right design choices" to make sure that bad containers don't affect the performance of other containers running on the same box. In fact, operating systems are built to optimize and run containers natively.
Still, you need to make the right choices when moving toward containers. You need to do enough due diligence so you choose the right technology partners and vendors to enable containers. Open source technologies play a key role. The open source [Docker project](https://opensource.com/resources/what-docker) has made containers with a layering format that is easy to build and use. The [Open Container Initiative](https://opensource.com/business/16/8/inside-look-future-linux-containers) (OCI) has become an open source standard for containers supported by all major technology vendors. Open source technology providers like Red Hat make container-ready, secure operating systems available. For example, Red Hat Enterprise Linux 7.x , including Red Hat Enterprise Linux Atomic Host, are optimized to run containers natively and also provide tools to monitor and manage containers. Other open source projects such as CoreOS from Tectonic are also coming into the market. Indeed, containers are ready for adoption by enterprises.
## Container platforms
Container platforms make containers enterprise-consumable. You may have dealt with VM sprawl in your enterprises over the past decade, and container sprawl can be many times worse. Running your containers at scale across the various hosts in your datacenter, ensuring high availability for your applications despite container failure, automated health checks, automated scaling of containers based on incoming workloads, etc., are some of the key features you can expect from a container platform.
While running containers on such a platform is positioned as Container-as-a-Service model (CaaS), some additional features of these platforms, such as build and deployment automation, make this platform a full-fledged Platform-as-a-Service (PaaS). While CaaS can run containers for you at scale, PaaS would take your source code, build it, create containers, and run those containers for you. In addition, these platforms provide complete operations management features, such as management and monitoring of the cluster, detection of security flaws with the containers and run safe containers, tracking logs and metrics, etc.
While some vendors are using their proprietary technologies to build container platforms, in general, companies are standardizing them around open source technologies built around [Kubernetes](https://opensource.com/resources/what-is-kubernetes) (or K8S in short). K8S is an open source project that was started by Google, and many large platform vendors now support it. K8S is also part of [Cloud Native Computing Foundation](https://www.cncf.io/) (CNCF), which is evolving as a standards body for cloud-centric technologies. Standardization around open source orchestration technologies is very important when you make your choices on a container platform. It basically allows you be portable across container platforms if you don't like the choice you made the first time. K8S also allows your container workloads to be portable across different public clouds. These are the reasons why we see more and more technology companies using Kubernetes.
A few enterprises are trying to build their own DIY container platforms by stitching together several open source projects that include K8S. This is definitely a better solution than going with proprietary technologies, but it also includes lot of plumbing to get it to work. However, an enterprise's ability to sustain and maintain such DIY platforms should be considered seriously. Many enterprises are not in the job of creating IT Platforms, rather they wish to run their mainstream business. There are many K8S-based solutions available, such as [Red Hat's OpenShift Container Platform](https://www.openshift.com/container-platform/), [Apprenda](https://apprenda.com/), [Deis](http://deis.io/), [Rancher](http://rancher.com/), etc., which provide enterprise-ready versions of a platform, each with different levels of maturity in terms of features they provide.
These solutions are certified and supported by vendors. Some of these are comprehensive open source PaaS solutions, while others may be CaaS. Based on your enterprise needs, these solutions may serve as better alternatives than a DIY container platform.
## Enterprise concerns and their relationship to containers
Today, almost every enterprise is dealing with a digital transformation that impacts multiple areas, including strategies for DevOps, microservices, and the cloud. Containers play a particular role in each of these areas.
## DevOps strategy
IT organizations are divided into operations and application development. They operate as two separate teams, and each has its own set of goals. Most of the enterprises are moving in the direction of DevOps to bring these two teams together.
Containers have a major role to play in the success of DevOps initiatives. One of the key success criteria in DevOps is to increase the developer's stake in operations. Developers should not only hand off code to operations, but also, they should be concerned about how their code runs in the production. The common technique is to treat "infrastructure as code." Rather than provide pages of installation instructions that are error prone, the development team should provide the environment setup as code.
This is the exact problem that containers solve. Container images, which are templates for containers, include the entire stack, starting from the base operating system through to the application code. With containers, developers would not just build an application artifact (such as a .jar file) from Dev to QA to Prod; instead, they would pass a versioned container image that includes both the built artifact and the environment in which the artifact runs. The container is all inclusive, with everything from operating system libraries to middleware to the application bundled into one image. Therefore, the way the container runs in Development is the same exact way it runs in QA and Production. Containers are essential ingredients for DevOps success.
In addition, container platforms are going a step further. Typical Continuous Integration and Delivery (CICD) tools, such as [Jenkins](https://jenkins.io/), are available as containers that run the entire CICD process on the container platform itself without the need for additional infrastructure. Now, you can use the PaaS platform to build and run your CICD pipelines.
## Microservices strategy
[Microservices](https://opensource.com/resources/what-are-microservices) are another hot topic in IT today. Breaking down applications into discrete, small services, each of which do a small job, pretty well, is how applications are being designed. Each of these microservices could be written in a different language based on the technology suitable. They would be created and managed by small (two-pizza fed) teams and they can be changed fast. All these requirements again allude to containers. Containers are small enough to be the foundation for microservices. Containers can support any technology and language of your choice. They are easy to create and run and can be changed fast. Microservices and containers are considered married now, and if people talk of implementing microservices without using containers, they are often given a strange look.
The reality is that while microservices promise simplicity, their proliferation also increases complexity. Several microservices design and deployment patterns are coming up to ease their implementation. This means developers are now in need of a platform where they can deploy and orchestrate these microservices with ease and that:
- Implements these microservices design patterns, in a language agnostic way
- Does not increase the complexity of code with code intrusion so that developers have to include a great deal of pattern code into their business logic
- Is flexible enough to deploy on the infrastructure of your choice and not does not tie you to particular clouds
This is where choosing a right container platform comes into play. Implementing these microservices on specific infrastructures in a particular vendor's way will tie your applications to those vendor platforms. Containerizing microservices using standard technologies such as OCI-compliant containers will ensure your microservices can be run on any OCI-compliant platform.
Choosing the right container platform to run your microservices is another important decision to make. Today there are very few choices and a lot of FUD. Some of these choices would take you down the non-standard, vendor-specific route if you are not diligent enough when making this choice.
## Cloud strategy
Cloud strategy is one more hot topic in IT. Whether you like it or not, the "as-a-Service" model is an inevitable change. If you don't provide this as a service from IT, your development teams will probably find ways to create shadow IT to get to the cloud. In addition, while using the cloud will move you from capital expenditure to operating expenditure, managing cloud expenditure is a constant challenge.
Cloud provides VMs, and you want to make sure that the CPU, memory and network resources on this cloud are used optimally before you spin up additional VMs. Containers play an important role here. Because containers are much smaller than VMs, and if your applications are run in containers, you can fit more containers in VMs than running one application component per VM.
Public cloud vendors are numerous, with Amazon Web Services (AWS), Microsoft Azure, and Google Cloud being a few of the more popular ones. In addition, you may want your own private cloud in your datacenter based on OpenStack. Each of these cloud environments have their own protocols, APIs, and tools. While you want your applications to run on the cloud, you don't want to make your application orchestration be cloud vendor specific and you don't want to maintain any cloud-specific code. Locking in your technology with a specific cloud vendor is like signing blank checks to the vendor for years to come.
Portability across the cloud is important to your cloud strategy. You can write your applications without worrying about where they run, and the container platform shields you from specific cloud vendor protocols, preventing you from being locked in with one cloud vendor.
## Legacy systems
The pluses brought to development by the microservices architecture are many, but not every application can be refactored into them and some only in part. Traditional applications are here to stay and they need to be maintained and managed. While containers enable microservices, containers are not *just* microservices. Conceivably, you can run large applications and non-microservices as containers, so as long as you choose the right container technology and the right application platform, you can run many, if not all, legacy applications as containers.
## Wrapping up
I hope this deep dive into various strategies and containers helps your company evaluate your next step. Let me know in the comments lessons your company has learned or if they haven't taken the leap, what information they need I haven't provided.
## 5 Comments |
8,370 | 4 个开源在线调查工具 | https://opensource.com/article/17/2/tools-online-surveys-polls | 2017-04-03T10:00:00 | [
"调查",
"问卷"
] | https://linux.cn/article-8370-1.html | 
啊,一个好的调查,能够以快速、简单、便宜、有效的方式收集朋友、家人、同学、同事、客户、读者和其他人的意见。
许多人开始使用专有工具,如 SurveyGizmo、Polldaddy、SurveyMonkey 甚至 Google 表单来设置他们的调查。但是如果你不仅是对这些应用还有你自己收集到的数据有更多的控制,那么你会希望使用开源工具。
让我们来看看四个开源调查工具,无论需求简单还是复杂,它们都可以满足你的需求。
### LimeSurvey
[LimeSurvey](https://www.limesurvey.org/) 是一个可以满足你几乎所有需求的调查工具。你可以使用 LimeSurvey 进行简单的调查和投票,以及跨越多个页面的更复杂的调查和投票。如果你使用多种语言,LimeSurvey 支持其中的 80 种。
LimeSurvey 还允许你使用自己的 JavaScript、照片和视频自定义调查,甚至直接编辑调查的 HTML。所有这一切只是[它的功能](https://www.limesurvey.org/about-limesurvey/features)的一部分。
你可以在自己的服务器上安装 LimeSurvey,或者[购买一个托管计划](https://www.limesurvey.org/services),这将使你每年花费数百欧元(尽管还有一个免费选项)。
### JD Esurvey
如果 LimeSurvey 没有为你提供足够的功能,并且对 Java 驱动的 web 程序感兴趣,那么我推荐 [JD Esurvey](https://www.jdsoft.com/jd-esurvey.html)。它被称为“一个开源的企业调查 web 应用”。它绝对强大,并满足了那些寻找大容量、健壮的调查工具的组织的很多需求。
使用 JD Esurvey,你可以收集一系列信息,包括 “是/否” 问题的答案以及产品和服务的星级。你甚至可以处理带有多个部分答案的问题。JD Esurvey 支持使用平板电脑和智能手机创建和管理调查,你发布的调查也是移动友好的。根据开发者的说法,该程序[残疾人也可使用](https://www.ada.gov/508/)。
要使用它,你可以[在 GitHub 上 fork JD Esurvey](https://github.com/JD-Software/JDeSurvey) 或者[下载并安装](https://github.com/JD-Software/JDeSurvey/wiki/Download-and-Installation)程序的预编译版本。
### Quick Survey
对于很多人来说,像 LimeSurvey 和 JD Esurvey 这样的工具过于复杂了。我们只是想要一个快速、简单易行的方式来收集意见或反馈。这里推荐 [Quick Survey](https://github.com/simonv3/quick-survey/)。
Quick Survey 只允许你创建问答和多选调查列表。你可以添加问题或创建列表,然后发布并共享网址。你可以根据需要在调查中添加任意数量的条目,回复将显示在 Quick Survey 的管理页面上。你也可以将调查结果下载为 CSV 文件。
虽然你可以从 GitHub 下载 Quick Survey 的代码,但它目前针对 [Sandstorm.io](http://sandstorm.io/) 和 [Sandstorm Oasis](http://oasis.sandstorm.io/) 进行了优化,你可以从 [Sandstorm 应用市场](https://apps.sandstorm.io/app/wupmzqk4872vgsye9t9x5dmrdw17mad97dk21jvcm2ph4jataze0)中获取。
### TellForm
在功能方面,[TellForm](https://www.tellform.com/) 介于 LimeSurvey 和 Quick Survey 之间。它适合那些功能需求超出最小需求,但无需完整功能的人使用。
除了有 11 种不同类型的调查之外,TellForm 还有很好的分析功能。你可以轻松地自定义调查的外观和感觉,而且程序的界面简单干净。
如果你想自己托管 TellForm,你可以从 [GitHub 仓库](https://github.com/whitef0x0/tellform)中获取代码。或者,你可以注册[免费托管帐户](https://admin.tellform.com/#!/signup)。
---
你有你最喜欢的的做在线调查的开源工具么?请在评论区与我们的社区分享。
---
作者简介:
Scott Nesbitt - 作家、编辑、雇佣兵(Soldier of fortune)、豹猫牧人(Ocelot wrangler)、丈夫和父亲、博客主、陶器收藏家。Scott 是以上的混合体。他也是一个自由/开源软件的长期用户,他为此写了很多[博客](https://apps.sandstorm.io/app/wupmzqk4872vgsye9t9x5dmrdw17mad97dk21jvcm2ph4jataze0)。你可以在 [Twitter](https://www.tellform.com/)、[GitHub](https://github.com/whitef0x0/tellform) 找到他。
---
via: <https://opensource.com/article/17/2/tools-online-surveys-polls>
作者:[Scott Nesbitt](https://opensource.com/users/scottnesbitt) 译者:[geekpi](https://github.com/geekpi) 校对:[jasminepeng](https://github.com/jasminepeng)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 200 | OK | Ah, the venerable survey. It can be a fast, simple, cheap, and effective way gather the opinions of friends, family, classmates, co-workers, customers, readers, and others.
Millions turn to proprietary tools like SurveyGizmo, Polldaddy, SurveyMonkey, or even Google Forms to set up their surveys. But if you want more control, not just over the application but also the data you collect, then you'll want to go open source.
Let's take a look at four open source survey tools that can suit your needs, no matter how simple or complex those needs are.
## LimeSurvey
[LimeSurvey](https://www.limesurvey.org/) is where you turn to when you want a survey tool that can do just about everything you want it to do. You can use LimeSurvey for doing simple surveys and polls, and more complex ones that span multiple pages. If you work in more than one language, LimeSurvey supports 80 of them.
LimeSurvey also lets you customize your surveys with your own JavaScript, photos, and videos, and even by editing your survey's HTML directly. And all that is only scratching the surface of [its features](https://www.limesurvey.org/about-limesurvey/features).
You can install LimeSurvey on your own server, or [get a hosted plan](https://www.limesurvey.org/services) that will set you back a few hundred euros a year (although there is a free option too).
## JD Esurvey
If LimeSurvey doesn't pack enough features for you and Java-powered web applications are your thing, then give [JD Esurvey ](https://www.jdsoft.com/jd-esurvey.html) a look. It's described as "an open source enterprise survey web application." It's definitely powerful, and ticks a number of boxes for organizations looking for a high-volume, robust survey tool.
Using JD Esurvey, you can collect a range of information including answers to "Yes/No" questions and star ratings for products and services. You can even process answers to questions with multiple parts. JD Esurvey supports creating and managing surveys with tablets and smartphones, and your published surveys are mobile friendly too. According to the developer, the application is usable by [people with disabilities](https://www.ada.gov/508/).
To give it a go, you can either [fork JD Esurvey on GitHub](https://github.com/JD-Software/JDeSurvey) or [download and install](https://github.com/JD-Software/JDeSurvey/wiki/Download-and-Installation) a pre-compiled version of the application.
## Quick Survey
For many of us, tools like LimeSurvey and JD Esurvey are overkill. We just want a quick and dirty way to gather opinions or feedback. That's where [Quick Survey](https://github.com/simonv3/quick-survey/) comes in.
Quick Survey only lets you create question-and-answer or multiple choice list surveys. You add your questions or create your list, then publish it and share the URL. You can add as many items to your survey as you need to, and the responses appear on Quick Survey's admin page. You can download the results of your surveys as a CSV file, too.
While you can download the code for Quick Survey from GitHub, it's currently optimized for [Sandstorm.io](http://sandstorm.io) and [Sandstorm Oasis](http://oasis.sandstorm.io) where you can grab it from the [Sandstorm App Market](https://apps.sandstorm.io/app/wupmzqk4872vgsye9t9x5dmrdw17mad97dk21jvcm2ph4jataze0).
## TellForm
In terms of features, [TellForm](https://www.tellform.com/) lies somewhere between LimeSurvey and Quick Survey. It's one of those tools for people who need more than a minimal set of functions, but who don't need everything and the kitchen sink.
In addition to having 11 different types of surveys, TellForm has pretty good analytics attached to its surveys. You can easily customize the look and feel of your surveys, and the application's interface is simple and clean.
If you want to host TellForm yourself, you can grab the code from the [GitHub repository](https://github.com/whitef0x0/tellform). Or, you can sign up for a [free hosted account](https://admin.tellform.com/#!/signup).
Do you have a favorite open source tool for doing online surveys? Feel free to share it with our community by leaving a comment.
## 2 Comments |
8,371 | Linux 命令行工具使用小贴士及技巧(二) | https://www.howtoforge.com/tutorial/linux-command-line-tips-tricks-part-2/ | 2017-04-03T11:15:00 | [
"命令行",
"pushd",
"popd",
"dirs"
] | https://linux.cn/article-8371-1.html | 在本系列的[第一部分](/article-8335-1.html)中,我们通过讨论 `cd -` 命令的用法,重点介绍了 Linux 中的命令行导航。还讨论了一些其他相关要点/概念。现在进一步讨论,在本文中,我们将讨论如何使用 `pushd` 和 `popd` 命令在 Linux 命令行上获得更快的导航体验。
在我们开始之前,值得说明的一点是,此后提到的所有指导和命令已经在 Ubuntu 14.04 和 Bash shell(4.3.11)上测试过。

### pushd 和 popd 命令基础
为了更好地理解 `pushd` 和 `popd` 命令的作用,让我们先讨论堆栈的概念。想象你厨房案板上有一个空白区域,你想在上面放一套盘子。你会怎么做?很简单,一个接一个地放在上面。
所以在整个过程的最后,案板上的第一个盘子是盘子中的最后一个,你手中最后一个盘子是盘子堆中的第一个。现在当你需要一个盘子时,你选择在堆的顶部的那个盘子并使用它,然后需要时选择下一个。
`pushd` 和 `popd` 命令是类似的概念。在 Linux 系统上有一个目录堆栈,你可以堆叠目录路径以供将来使用。你可以使用 `dirs` 命令来在任何时间点快速查看堆栈的内容。
下面的例子显示了在命令行终端启动后立即在我的系统上使用 dirs 命令的输出:
```
$ dirs
~
```
输出中的波浪号(`~`)表示目录堆栈当前仅包含用户的主目录。
继续下去,使用 `pushd` 和 `popd` 命令来执行存储目录路径并删除它的操作。使用 `pushd` 非常容易 - 只需将要存储在目录堆栈中的路径作为此命令的参数传递。这里有一个例子:
```
pushd /home/himanshu/Downloads/
```
上述命令的作用是,将当前工作目录更改为你作为参数传递的目录,并且还将路径添加到目录堆栈中。为了方便用户,`pushd` 命令在其输出中产生目录堆栈的内容。因此,当运行上面的命令时,产生了以下输出:
```
~/Downloads ~
```
输出显示现在堆栈中有两个目录路径:一个是用户的主目录,还有用户的下载目录。它们的保存顺序是:主目录位于底部,新添加的 `Downloads` 目录位于其上。
要验证 `pushd` 的输出是正确的,你还可以使用 `dirs` 命令:
```
$ dirs
~/Downloads ~
```
因此你可以看到 `dirs` 命令同样产生相同的输出。
让我们再使用下 `pushd` 命令:
```
$ pushd /usr/lib/; pushd /home/himanshu/Desktop/
/usr/lib ~/Downloads ~
~/Desktop /usr/lib ~/Downloads ~
```
所以目录堆栈现在包含总共四个目录路径,其中主目录(`~`)在底部,并且用户的桌面目录在顶部。
一定要记住的是堆栈的头是你当前的目录。这意味着现在我们当前的工作目录是 `~/Desktop`。
现在,假设你想回到 `/usr/lib` 目录,所以你所要做的就是执行 `popd` 命令:
```
$ popd
/usr/lib ~/Downloads ~
```
`popd` 命令不仅会将当前目录切换到 `/usr/lib`,它还会从目录堆栈中删除 `~/Desktop`,这一点可以从命令输出中看出。这样,popd 命令将允许你以相反的顺序浏览这些目录。
### 一些高级用法
现在我们已经讨论了 `pushd` 和 `popd` 命令的基础知识,让我们继续讨论与这些命令相关的一些其它细节。首先,这些命令还允许你操作目录堆栈。例如,假设你的目录堆栈看起来像这样:
```
$ dirs
~/Desktop /usr/lib ~ ~/Downloads
```
现在,我们的要求是改变堆栈中目录路径的顺序,最上面的元素(`~/Desktop`)放到底部,剩下的每个都向上移动一个位置。这可以使用以下命令实现:
```
pushd +1
```
上面的命令对目录堆栈做的结果:
```
$ dirs
/usr/lib ~ ~/Downloads ~/Desktop
```
因此,我们看到目录堆栈中的元素顺序已经改变,并且现在和我们想要的一样。当然,你可以让目录堆栈元素移动任何次数。例如,以下命令会将它们向上移动两次:
```
$ pushd +2
~/Downloads ~/Desktop /usr/lib ~
```
你也可以使用负的索引值:
```
$ pushd -1
/usr/lib ~ ~/Downloads ~/Desktop
```
相似地,你可以在 `popd` 命令中使用此技术来从目录堆栈删除任何条目,而不用离开当前工作目录。例如,如果要使用 `popd` 从顶部(目前是 `~/Downloads`)删除第三个条目,你可以运行以下命令:
```
popd +2
```
记住堆栈索引的初始值是 `0`,因此我们使用 `2` 来访问第三个条目。
因此目录堆栈现在包含:
```
$ dirs
/usr/lib ~ ~/Desktop
```
确认条目已经被移除了。
如果由于某些原因,你发现你很难记住元素在目录堆栈中的位置以及它们的索引,你则可以对在 `dirs` 命令中使用 `-v` 选项。这里有一个例子:
```
$ dirs -v
0 /usr/lib
1 ~
2 ~/Desktop
```
你可能已经猜到了,左边的数字是索引,接下来跟的是这个索引对应的目录路径。
**注意**: 在 `dir` 中使用 `-c` 选项清除目录堆栈。
现在让我们简要地讨论一下 `popd` 和 `pushd` 命令的实际用法。虽然它们第一眼看起来可能有点复杂,但是这些命令在编写 shell 脚本时会派上用场 - 你不需要记住你从哪里来;只要执行一下 `popd`,你就能回到你来的目录。
经验丰富的脚本编写者通常以以下方式使用这些命令:
```
popd >/dev/null 2>&1
```
上述命令确保 `popd` 保持静默(不产生任何输出)。同样,你也可以静默 `pushd`。
`pushd` 和 `popd` 命令也被 Linux 服务器管理员使用,他们通常在几个相同的目录之间移动。 在[这里](http://unix.stackexchange.com/questions/77077/how-do-i-use-pushd-and-popd-commands)介绍了一些其他有用的使用场景。
### 总结
我同意 `pushd` 和 `popd` 的概念不是很直接。但是,它需要的只是一点练习 - 是的,你需要多实践。花一些时间在这些命令上,你就会开始喜欢它们,特别是当它们提供了方便时。
---
via: <https://www.howtoforge.com/tutorial/linux-command-line-tips-tricks-part-2/>
作者:[Ansh](https://www.howtoforge.com/tutorial/linux-command-line-tips-tricks-part-2/) 译者:[geekpi](https://github.com/geekpi) 校对:[jasminepeng](https://github.com/jasminepeng)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 200 | OK | # Linux Command Line Navigation Tips: The Basics of pushd and popd Command
In the [first part](https://www.howtoforge.com/tutorial/linux-command-line-navigation-tips-and-tricks-part-1/) of this series, we focused on the command line navigation aspect in Linux by discussing the usage of the **cd -** command. Some other related points/concepts were also discussed. Taking the discussion further, in this article, we will be discussing how you can have a faster navigation experience on the Linux command line using the pushd and popd commands.
## The basics of pushd and popd commands
To better understand what exactly pushd and popd commands do, let's first discuss the concept of stack. Imagine an empty area on your kitchen slab, and now imagine a set of plates that you want to keep there. What will you do? Simple, keep them one over the other.
So at the end of the whole process, the first plate that you kept on the slab ends up being the last plate in the pile, and the last plate that you had in your hand ends up being the first plate in the pile. Now, when you require a plate, you pick the one which is at the top of the pile, use it, and then pick the next one when required.
Similar is the concept of pushd and popd commands. There's a directory stack on your Linux system where you can pile up directory paths for future use. You can quickly see the contents of the stack at any point in time using the **dirs** command or [cd command](https://www.howtoforge.com/linux-cd-command/).
Here's an example that shows the output of the dirs command on my system immediately after the command line terminal was launched:
$ dirs
~
The tilde (~) in the output means the directory stack currently only contains the user's home directory.
Moving on, the operation of storing a directory path and removing it is performed using the pushd and popd commands. Using pushd is very easy - just pass the path that you want to store in the directory stack as an argument to this command. Here's an example:
pushd /home/himanshu/Downloads/
What the above command does is, it changes your present working directory to the directory that you've passed as the argument, and also adds the path to the directory stack. To make things convenient for the user, the pushd command produces the contents of the directory stack in its output. So, when the above command was run, the following output was produced:
~/Downloads ~
The output reveals that now there are two directory paths in the stack: one is the user's home directory and the other is the user's Downloads directory. The order in which they are kept is: the home directory is at the bottom and the newly-added Downloads directory is above it.
To verify that what pushd is saying in its output is true, you can also use the dirs command:
$ dirs
~/Downloads ~
So you can see that the dirs command also produced the same output.
Let's issue a couple of more pushd commands:
$ pushd /usr/lib/; pushd /home/himanshu/Desktop/
/usr/lib ~/Downloads ~
~/Desktop /usr/lib ~/Downloads ~
So the directory stack now contains a total of four directory paths, where the home directory (~) is at the bottom, and the user's Desktop directory is at the top.
Always keep in mind that the head of the stack is the directory that you're currently in. This means that now our current working directory is ~/Desktop.
Now, suppose you want to go back to the /usr/lib directory, so all you have to do is to execute the popd command:
$ popd
/usr/lib ~/Downloads ~
The popd command will not only switch your current directory to /usr/lib, it'll also remove ~/Desktop from the directory stack - as evidenced by the output the command produced. This way, the popd command will let you navigate these directories in reverse order.
## Some advanced points
Now that we have discussed the basics of pushd and popd commands, let's move on to some other details related to these commands. To begin with, these commands also let you manipulate the directory stack. For example, suppose here's what your directory stack looks like:
$ dirs
~/Desktop /usr/lib ~ ~/Downloads
Now, let's say the requirement is to change the order of the directory paths in the stack in a way that the topmost element (~/Desktop) comes at the bottom and rest all move up by one place each. This can be achieved using the following command:
`pushd +1`
And here's what the above command does to the directory stack:
$ dirs
/usr/lib ~ ~/Downloads ~/Desktop
So we see that the order of elements in directory stack has been changed, and is now the same as we wanted. Of course, you can make the directory stack elements move any number of times. For example, the following command will move them up two times:
$ pushd +2
~/Downloads ~/Desktop /usr/lib ~
You can use negative indexes as well:
$ pushd -1
/usr/lib ~ ~/Downloads ~/Desktop
Similarly, you can use this technique with the popd command to remove any entry from the directory stack without leaving your current working directory. For example, if you want to remove the third entry from top (which is ~/Downloads currently) using popd, you can run the following command:
popd +2
Keep in mind that the stack index begins with 0, so we've used 2 to access third entry.
So the directory stack now contains:
$ dirs
/usr/lib ~ ~/Desktop
Confirming that the entry has been removed.
If, for some reason, you find it difficult to remember the order in which elements are positioned in the directory stack as well as the indexes they carry, you can use the -v command line option with the dirs command. Here's an example:
$ dirs -v
0 /usr/lib
1 ~
2 ~/Desktop
As you would have probably guessed, the numbers on the left are indexes and what follows them is the directory path positioned at that index.
**Note**: Use the -c command line option with the dirs command to clear the directory stack.
Now let's briefly discuss the practical usage of popd and pushd commands. While they may seem a bit complicated to use at first glance, these commands come in handy while writing shell scripts - you don't need to remember where you're coming from; just do a popd and you're back to the directory where you came from.
Experienced script writers usually use these commands in the following way:
`popd >/dev/null 2>&1`
The aforementioned command makes sure that popd remains silent (do not produce any output). Similarly, you can silent pushd as well.
The pushd and popd command are also used by Linux server administrators, who usually move around between a handful of same directories all the time. Some other really informative use-cases are explained [here](http://unix.stackexchange.com/questions/77077/how-do-i-use-pushd-and-popd-commands).
## Conclusion
Agreed, the concept of pushd and popd isn't very straightforward. But, all it requires is a bit of practice - yes, you need to get your hands dirty. Spend some time with these commands and you'll start liking them, especially if there's a use-case where-in they make life easy for you. Here you can find the [third part of the series](https://www.howtoforge.com/tutorial/linux-command-line-tips-tricks-part-3-cdpath/). |
8,372 | 在 shell 中使用 vi 模式 | https://opensource.com/article/17/3/fun-vi-mode-your-shell | 2017-04-04T08:22:00 | [
"命令行",
"Emacs",
"Vim"
] | https://linux.cn/article-8372-1.html |
>
> 介绍在命令行编辑中使用 vi 模式。
>
>
>

作为一名大型开源社区的参与者,更确切地说,作为 [Fedora 项目](https://getfedora.org/)的成员,我有机会与许多人会面并讨论各种有趣的技术主题。我最喜欢的主题是“命令行”或者说 [shell](https://opensource.com/business/16/3/top-linux-shells),因为了解人们如何熟练使用 shell 可以让你深入地了解他们的想法,他们喜欢什么样的工作流程,以及某种程度上是什么激发了他们的灵感。许多开发和运维人员在互联网上公开分享他们的“ dot 文件”(他们的 shell 配置文件的常见俚语),这将是一个有趣的协作机会,让每个人都能从对命令行有丰富经验的人中学习提示和技巧并分享快捷方式以及有效率的技巧。
今天我在这里会为你介绍 shell 中的 vi 模式。
在计算和操作系统的庞大生态系统中有[很多 shell](https://opensource.com/business/16/3/top-linux-shells)。然而,在 Linux 世界中,[bash](https://tiswww.case.edu/php/chet/bash/bashtop.html) 已经成为事实上的标准,并在在撰写本文时,它是所有主要 Linux 发行版上的默认 shell。因此,它就是我所说的 shell。需要注意的是,bash 在其他类 UNIX 操作系统上也是一个相当受欢迎的选项,所以它可能跟你用的差别不大(对于 Windows 用户,可以用 [cygwin](http://cygwin.org/))。
在探索 shell 时,首先要做的是在其中输入命令并得到输出,如下所示:
```
$ echo "Hello World!"
Hello World!
```
这是常见的练习,可能每个人都做过。没接触过的人和新手可能没有意识到 [bash](https://tiswww.case.edu/php/chet/bash/bashtop.html) shell 的默认输入模式是 [Emacs](https://www.gnu.org/software/emacs/) 模式,也就是说命令行中所用的行编辑功能都将使用 [Emacs 风格的“键盘快捷键”](https://en.wikipedia.org/wiki/GNU_Readline#Emacs_keyboard_shortcuts)。(行编辑功能实际上是由 [GNU Readline](http://cnswww.cns.cwru.edu/php/chet/readline/rltop.html) 进行的。)
例如,如果你输入了 `echo "Hello Wrld!"`,并意识到你想要快速跳回一个单词(空格分隔)来修改打字错误,而无需按住左箭头键,那么你可以同时按下 `Alt+b`,光标会将向后跳到 `W`。
```
$ echo "Hello Wrld!"
^
Cursor is here.
```
这只是使用提供给 shell 用户的诸多 Emacs 快捷键组合之一完成的。还有其他更多东西,如复制文本、粘贴文本、删除文本以及使用快捷方式来编辑文本。使用复杂的快捷键组合并记住可能看起来很愚蠢,但是在使用较长的命令或从 shell 历史记录中调用一个命令并想再次编辑执行时,它们可能会非常强大。
尽管 Emacs 的键盘绑定都不错,如果你对 Emacs 编辑器熟悉或者发现它们很容易使用也不错,但是仍有一些人觉得 “vi 风格”的键盘绑定更舒服,因为他们经常使用 vi 编辑器(通常是 [vim](http://www.vim.org/) 或 [nvim](https://neovim.io/))。bash shell(再说一次,通过 GNU Readline)可以为我们提供这个功能。要启用它,需要执行命令 `$ set -o vi`。
就像魔术一样,你现在处于 vi 模式了,现在可以使用 vi 风格的键绑定来轻松地进行编辑,以便复制文本、删除文本、并跳转到文本行中的不同位置。这与 Emacs 模式在功能方面没有太大的不同,但是它在你*如何*与 shell 进行交互执行操作上有一些差别,根据你的喜好这是一个强大的选择。
我们来看看先前的例子,但是在这种情况下一旦你在 shell 中进入 vi 模式,你就处于 INSERT 模式中,这意味着你可以和以前一样输入命令,现在点击 **Esc** 键,你将处于 NORMAL 模式,你可以自由浏览并进行文字修改。
看看先前的例子,如果你输入了 `echo "Hello Wrld!"`,并意识到你想跳回一个单词(再说一次,用空格分隔的单词)来修复那个打字错误,那么你可以点击 `Esc` 从 INSERT 模式变为 NORMAL 模式。然后,您可以输入 `B`(即 `Shift+b`),光标就能像以前那样回到前面了。(有关 vi 模式的更多信息,请参阅[这里](https://en.wikibooks.org/wiki/Learning_the_vi_Editor/Vim/Modes)。):
```
$ echo "Hello Wrld!"
^
Cursor is here.
```
现在,对于 vi/vim/nvim 用户来说,你会惊喜地发现你可以一直使用相同的快捷键,而不仅仅是在编辑器中编写代码或文档的时候。如果你从未了解过这些,并且想要了解更多,那么我可能会建议你看看这个[交互式 vim 教程](http://www.openvim.com/tutorial.html),看看 vi 风格的编辑是否有你所不知道的。
如果你喜欢在此风格下与 shell 交互,那么你可以在主目录中的 `~/.bashrc` 文件底部添加下面的行来持久设置它。
```
set -o vi
```
对于 emacs 模式的用户,希望这可以让你快速并愉快地看到 shell 的“另一面”。在结束之前,我认为每个人都应该使用任意一个让他们更有效率的编辑器和 shell 行编辑模式,如果你使用 vi 模式并且这篇文章给你展开了新的一页,那么恭喜你!现在就变得更有效率吧。
玩得愉快!
---
作者简介:
Adam Miller 是 Fedora 工程团队成员,专注于 Fedora 发布工程。他的工作包括下一代构建系统、自动化、RPM 包维护和基础架构部署。Adam 在山姆休斯顿州立大学完成了计算机科学学士学位与信息保障与安全科学硕士学位。他是一名红帽认证工程师(Cert#110-008-810),也是开源社区的活跃成员,并对 Fedora 项目(FAS 帐户名称:maxamillion)贡献有着悠久的历史。
---
via: <https://opensource.com/article/17/3/fun-vi-mode-your-shell>
作者:[Adam Miller](https://opensource.com/users/maxamillion) 译者:[geekpi](https://github.com/geekpi) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 200 | OK | As a participant in the greater open source community, and more specifically as a member of the [Fedora Project](https://getfedora.org/), I have the opportunity to meet with many people and talk about all kinds of interesting technical topics. One of my favorites is the "command line," or [shell](https://opensource.com/business/16/3/top-linux-shells), because learning about how people use the shell proficiently can give you an insight into how they think, what kind of workflows they favor, and to some extent what makes them tick. Many developers and systems operators share their "dot files" (a common slang term for their shell's configuration files) publicly out on the Internet, which leads to an interesting collaboration opportunity that allows everyone to learn tips and tricks from seasoned veterans of the command line as well as share common shortcuts and productivity boosters.
I'll introduce one for you here by showing the shell's vi-mode.
In the large ecosystem of computing and operating systems, there are [many shells](https://opensource.com/business/16/3/top-linux-shells). However, in the Linux world, the de facto standard has become [bash](https://tiswww.case.edu/php/chet/bash/bashtop.html) and it is the default shell installed on all major Linux distributions at of the time of this writing. As such, that is the shell I'll be talking about today. Something to note, though, is that bash is also a reasonably popular option on other UNIX-style operating systems, so it's likely not far from your reach (and for you Windows users out there, there's always [cygwin](http://cygwin.org/)).
While exploring the shell, the first thing you do is type commands into it and most often get output, like so:
```
``````
$ echo "Hello World!"
Hello World!
```
This is common practice and is probably something everyone reading this has done. Something that newcomers and novices alike might not realize is that the default input mode for the [bash](https://tiswww.case.edu/php/chet/bash/bashtop.html) shell is [Emacs](https://www.gnu.org/software/emacs/), which means that all line-editing functions you will carry out on commands will use ["Emacs-style" keyboard combinations](https://en.wikipedia.org/wiki/GNU_Readline#Emacs_keyboard_shortcuts). (For those interested in the nuts and bolts of things, the function of line-editing is actually carried out by [GNU Readline](http://cnswww.cns.cwru.edu/php/chet/readline/rltop.html).)
For example, if you had typed **echo "Hello Wrld!"** and realized that you wanted to quickly jump back one word (space delimited) to fix that typo without having to hold down your left arrow key then you would hit the **Alt+b** keys together and the cursor would jump backward to the **W**.
```
``````
$ echo "Hello Wrld!"
^
Cursor is here.
```
This was done using only one of the many Emacs keyboard combinations that is offered to the user of the shell. There are many more available for all kinds of things, such as copying text, pasting text, removing text, and using shortcuts to edit text. Using complex keyboard combinations and committing them to memory may seem silly, but they can be extremely powerful when working with longer commands or recalling a command from your shell history yet wanting to edit a couple things before executing the command again.
While Emacs key bindings are all well and good if you're familiar with the Emacs text editor or otherwise find them convenient to use, there are those who are more comfortable using "vi-style" keyboard bindings because of their time spent in the vi text editor (normally via [vim](http://www.vim.org/) or [nvim](https://neovim.io/) these days). The bash shell (again, via GNU Readline) is able to provide this functionality for us. In order to enable it, you run the command **$ ****set**** -o vi**.
Just like magic, you're now in vi-mode and can easily line-edit using vi-style key bindings in order to copy text, remove text, and jump around to different positions in the line of text. This isn't much different in terms of capabilities of Emacs-mode but it's *how* you interact with the shell to perform these actions that changes, which is a powerful option pending your specific preference.
Let's take a look at the same example as before, but with the context that as soon as you land in vi-mode in your shell you're in INSERT mode, which means you can type commands just you did before but you can now hit the **Esc** key on your keyboard and you'll be in NORMAL mode, which is where you can navigate around freely and make text modifications.
Looking at the same example as before, if you had typed **echo "Hello Wrld!"** and realized you wanted to jump back one word (again, space delimited) to fix up that typo, then you would hit **Esc** to change from INSERT to NORMAL mode. Then you can type **B** (**Shift+b** for those following along at home), which would move the cursor back much like it did before. (For more information on vi-modes, go [here](https://en.wikibooks.org/wiki/Learning_the_vi_Editor/Vim/Modes).):
```
``````
$ echo "Hello Wrld!"
^
Cursor is here.
```
Now, for the vi/vim/nvim users out there this is hopefully a fun "ah ha!" moment when you realize the potential of keeping your tried and true keyboard shortcuts close by at all times and not just while your writing things like code or documentation in your editor. If this is all new to you and you want to learn more, then I might suggest taking a trip to this [interactive vim tutorial](http://www.openvim.com/tutorial.html) and see if the vi style of editing text is something you find useful.
If you enjoy interacting with your shell in this mode, you can set that persistently by editing the **~/.bashrc** file in your home directory and adding the following line at the bottom.
**set -o vi**
For the emacs mode users, hopefully this was a quick and fun look into "the other side" of your shell. At the end of the day I think everyone should use whatever editor and shell line-editing mode that makes them most productive and if that's vi-mode and this article was news to you, then congratulations! Now go forth and be productive.
Happy hacking...
## 10 Comments |
8,373 | 如何在 Vim 中进行文本选择操作和使用标志 | https://www.howtoforge.com/tutorial/how-to-use-markers-and-perform-text-selection-in-vim/ | 2017-04-05T08:50:00 | [
"Vim"
] | https://linux.cn/article-8373-1.html | 基于图形界面的文本或源代码编辑器,提供了一些诸如文本选择的功能。我是想说,可能大多数人不觉得这是一个功能。不过像 Vim 这种基于命令行的编辑器就不是这样。当你仅使用键盘操作 Vim 的时候,就需要学习特定的命令来选择你想要的文本。在这个教程中,我们将详细讨论文本选择这一功能以及 Vim 中的标志功能。

在此之前需要说明的是,本教程中所提到的例子、命令和指令都是在 Ubuntu 16.04 的环境下测试的。Vim 的版本是 7.4。
### Vim 的文本选择功能
我们假设你已经具备了 Vim 编辑器的基本知识(如果没有,可以先阅读[这篇文章](/article-8143-1.html))。你应该知道,`d` 命令能够剪切/删除一行内容。如果你想要剪切 3 行的话,可以重复命令 3 次。不过,如果需要剪切 15 行呢?重复 `d` 命令 15 次是个实用的解决方法吗?
显然不是。这种情况下的最佳方法是,选中你想要剪切/删除的行,再运行 `d` 命令。举个例子:
假如我想要剪切/删除下面截图中 INTRODUCTION 小节的第一段:
[](https://www.howtoforge.com/images/how-to-use-markers-and-perform-text-selection-in-vim/big/vim-select-example.png)
那么我的做法是:将光标放在第一行的开始,(确保退出了 Insert 模式)按下 `V`(即 `Shift+v`)命令。这时 Vim 会开启视图模式,并选中第一行。
[](https://www.howtoforge.com/images/how-to-use-markers-and-perform-text-selection-in-vim/big/vim-select-initiated.png)
现在,我可以使用方向键“下”,来选中整个段落。
[](https://www.howtoforge.com/images/how-to-use-markers-and-perform-text-selection-in-vim/big/vim-select-working.png)
这就是我们想要的,对吧!现在只需按 `d` 键,就可以剪切/删除选中的段落了。当然,除了剪切/删除,你可以对选中的文本做任何操作。
这给我们带来了另一个重要的问题:当我们不需要删除整行的时候,该怎么做呢?也就是说,我们刚才讨论的解决方法,仅适用于想要对整行做操作的情况。那么如果我们只想删除段落的前三句话呢?
其实也有相应的命令 - 只需用小写 `v` 来代替大写 `V` 即可。在下面的例子中,我使用 `v` 来选中段落的前三句话:
[](https://www.howtoforge.com/images/how-to-use-markers-and-perform-text-selection-in-vim/big/vim-select-partial-lines.png)
有时候,你需要处理的数据由单独的列组成,你的需求可能是选择特定的一列。考虑下面的截图:
[](https://www.howtoforge.com/images/how-to-use-markers-and-perform-text-selection-in-vim/big/vim-select-columns.png)
假设我们只需选择文本的第二列,即国家的名字。这种情况下,你可以将光标放在这一列的第一个字母上,按 `Ctrl+v` 一次。然后,按方向键“下”,选中每个国家名字的第一个字母:
[](https://www.howtoforge.com/images/how-to-use-markers-and-perform-text-selection-in-vim/big/vim-select-column-1.png)
然后按方向键“右”,选中这一列。
[](https://www.howtoforge.com/images/how-to-use-markers-and-perform-text-selection-in-vim/big/vim-select-column-2.png)
**小窍门**:如果你之前选中了某个文本块,现在想重新选中那个文本块,只需在命令模式下按 `gv` 即可。
### 使用标志
有时候,你在处理一个很大的文件(例如源代码文件或者一个 shell 脚本),可能想要切换到一个特定的位置,然后再回到刚才所在的行。如果这两行的位置不远,或者你并不常做这类操作,那么这不是什么问题。
但是,如果你需要频繁地在当前位置和一些较远的行之间切换,那么最好的方法就是使用标志。你只需标记当前的位置,然后就能够通过标志名,从文件的任意位置回到当前的位置。
在 Vim 中,我们使用 `m` 命令紧跟一个字母来标记一行(字母表示标志名,可用小写的 `a` - `z`)。例如 `ma`。然后你可以使用命令 `'a` (包括左侧的单引号)回到标志为 `a` 的行。
**小窍门**:你可以使用“单引号” `'` 来跳转到标志行的第一个字符,或使用“反引号” ``` 来跳转到标志行的特定列。
Vim 的标志功能还有很多其他的用法。例如,你可以先标记一行,然后将光标移到其他行,运行下面的命令:
```
d'[标志名]
```
来删除当前位置和标志行之间的所有内容。
在 Vim 官方文档中,有一个重要的内容:
>
> 每个文件有一些由小写字母(`a`-`z`)定义的标志。此外,还存在一些由大写字母(`A`-`Z`)定义的全局标志,它们定义了一个特定文件的某个位置。例如,你可能在同时编辑十个文件,每个文件都可以有标志 `a`,但是只有一个文件能够有标志 `A`。
>
>
>
我们已经讨论了使用小写字母作为 Vim 标志的基本用法,以及它们的便捷之处。下面的这段摘录讲解的足够清晰:
>
> 由于种种局限性,大写字母标志可能乍一看不如小写字母标志好用,但它可以用作一种快速的文件书签。例如,打开 `.vimrc` 文件,按下 `mV`,然后退出。下次再想要编辑 `.vimrc` 文件的时候,按下 `'V` 就能够打开它。
>
>
>
最后,我们使用 `delmarks` 命令来删除标志。例如:
```
:delmarks a
```
这一命令将从文件中删除一个标志。当然,你也可以删除标志所在的行,这样标志将被自动删除。你可以在 [Vim 文档](http://vim.wikia.com/wiki/Using_marks) 中找到关于标志的更多信息。
### 总结
当你开始使用 Vim 作为首选编辑器的时候,类似于这篇教程中提到的功能将会是非常有用的工具,能够节省大量的时间。你得承认,这里介绍的文本选择和标志功能几乎不怎么需要学习,所需要的只是一点练习。
---
via: <https://www.howtoforge.com/tutorial/how-to-use-markers-and-perform-text-selection-in-vim/>
作者:[Himanshu Arora](https://www.howtoforge.com/tutorial/how-to-use-markers-and-perform-text-selection-in-vim/) 译者:[Cathon](https://github.com/Cathon) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 200 | OK | # How to use markers and perform text selection in Vim
When using GUI-based text/source code editors, some features are a given, such as selecting text. I mean, most of us won't even consider this a feature anymore. But that's not the case with command line based editors like Vim. Specifically for Vim, when only using keyboard, you'll have to learn certain commands in order to select text the way you want. In this tutorial we will discuss this feature as well as the 'marks' feature of Vim in detail.
`But before we start doing that, it's worth mentioning that all the examples, commands, and instructions mentioned in this tutorial have been tested on Ubuntu 16.04, and the Vim version we've used is 7.4.`
# Text selection options in Vim
Assuming that you have the basic knowledge about the Vim editor (No? no problem, just head [here](https://www.howtoforge.com/vim-basics)), you would be knowing that the 'd' command lets you cut/delete a line. But what if you want to cut, say, 3 lines? Your answer could be: 'repeat the command thrice'. Fine, but what if the requirement is to cut a complete paragraph (or, say, a couple of them)? Is first counting the number of lines manually and then running the 'd' command (even if you use '[n]dd') a practical solution?
No, it's not. A better solution, in this case, would be to select the lines you want to cut/delete, and then run the 'd' command just once. Here's an example:
Suppose I want to cut/delete the complete first paragraph of the INTRODUCTION section shown in the screenshot below:
So what I'll do is, I'll bring the cursor in the beginning of the first line, and (making sure I am out of Insert mode) type the 'V' (Shift+v) command. This will result in the first line being selected and Vim enabling the Visual Line mode.
Now, all I have to do is to use the down arrow key to select the whole paragraph.
So that's what we wanted, right? Now just press 'd' and the selected paragraph will be cut/deleted. Needless to say, aside from cut/delete, you can perform any other option on the selected text.
This brings us to another important aspect: not every time we need to delete the complete line or lines; what to do in those cases? What that means is, the solution we just discussed only works when you want to perform operation on complete line(s). What if the requirement is to delete the first three sentences in a paragraph?
Well, there's a command for this as well - just use 'v' instead of 'V' (without single quotes of course). Following is an example where-in I used 'v' and then selected the first three sentences in the paragraph:
Moving on, sometimes the data you are dealing with consists of separate columns, and the requirement may be to select a particular column. For example, consider the following screenshot:
Suppose the requirement is to only select the name of countries, which mean the second column of the text. So what you can do in this case is, bring your cursor under the first element of the column in question and press Ctrl+v once. Now, using the down arrow key, select the first letter of each country name:
And then using the right arrow key, select the complete column, or the whole names.
**Tip**: In case you de-selected a block of text for some reason, and now want to again select it, just press 'gv' in the command mode.
# Using marks
Sometimes, while working on a large file (say, a source code file or a shell script), you might want to switch to particular location and then come back to the line where you were originally. That's not an issue if the lines in question aren't far away, or you have to do this occasionally.
But what is it's the other way round - you have to frequently jump between your present location and various far off lines in the file. Well, the solution in that case is to use marks. Just mark your current location, then come back to this location from anywhere in the file by just mentioning the name of the mark.
To mark a line in vim, use the *m* command followed by an alphabet that represents the name of the mark (available options are a-z in lowercase). For example, *ma*. Now, to come back to the mark *a*, use the *'a* command (single quote included).
**Tip**: *You can use apostrophe ( ') or backtick (`) depending on whether you want to jump to the beginning of the marked line, or specifically to the line and column of the mark.*
There can be various other useful applications of Vim markers. For example, you can put a mark on a line, then go to some other line and run the following command:
d'[mark-name]
to delete everything between your current position and the marked line.
Moving on, here's an important tid-bid from the Vim's official documentation:
Each file has a set of marks identified by lowercase letters (a-z). In addition there is a global set of marks identified by uppercase letters (A-Z) that identify a position within a particular file. For example, you may be editing ten files. Each file could have marka, but only one file can have markA.
So while we have discussed the basic usage of lowercase alphabets as Vim marks, how and where the uppercase letters are useful. Well, the following excerpt makes it amply clear:
Because of their limitations, uppercase marks may at first glance seem less versatile than their lowercase counterpart, but this feature allows them to be used as a quick sort of "file bookmark." For example, open your .[vimrc], press mV, and close Vim. The next time you want to edit your .vimrc, just press 'V to open it.
And finally, to delete a mark, use the 'delmarks' command. For example:
:delmarks a
The aforementioned command will delete the mark *a* from the file. Of course, if you delete a line containing a mark, then that mark is also deleted automatically. For more information on marks, head to the [Vim documentation](http://vim.wikia.com/wiki/Using_marks).
# Conclusion
As you start using Vim as your primary editor, features like the ones explained in this tutorial become useful tools that save a lot of your time. As you'd agree, there's not much of a learning curve involved with selection and marks features explained here - all that's required is a bit of practice.
*For the complete coverage of Vim-related articles on HowtoForge, head here.* |
8,374 | 使用极简的 Min 浏览器消除 web 噪音 | http://www.linuxinsider.com/story/84212.html | 2017-04-04T09:12:00 | [
"Min",
"浏览器"
] | https://linux.cn/article-8374-1.html | 
[Min](https://github.com/minbrowser/min/releases/) 是一款精简设计的 web 浏览器,功能简便,响应迅速。
在软件设计中,“简单”并不意味着功能低级、有待改进。你如果喜欢花哨工具比较少的文本编辑器和笔记程序,那么在 Min 浏览器中会有同样舒适的感觉。
我经常在台式机和笔记本电脑上使用 Google Chrome、Chromium 和 Firefox。我研究了它们的很多附加功能,所以我在长期的研究和工作中可以享用它们的特色服务。
然而,有时我希望有个快速、整洁的替代品来上网。随着多个项目的进行,我需要一个可以很快打开一大批选项卡甚至是独立窗口的强大浏览器。
我试过其他浏览器但很少能令我满意。替代品通常有一套独特的花哨的附件和功能,它们会让我开小差。
Min 浏览器就不这样。它是一个易于使用,并在 GitHub 开源的 web 浏览器,不会使我分心。

*Min 浏览器是精简的浏览器,提供了简单的功能以及快速的响应。只是不要指望马上能上手。*
### 它做些什么
Min 浏览器提供了 Debian Linux、Windows 和 Mac 机器的版本。它不能与功能众多的主流跨平台 web 浏览器竞争。
但它不必竞争,它很有名的原因应该是补充而不是取代那些主流浏览器。
其中一个主要原因是其内置的广告拦截功能。开箱即用的 Min 浏览器不需要配置或寻找兼容的第三方应用程序来拦截广告。
在 Edit/Preferences 菜单中,你可以通过三个选项来设置阻止的内容。它很容易修改屏蔽策略来满足你的喜好。阻止跟踪器和广告选项使用 EasyList 和 EasyPrivacy。 如果没有其他原因,请保持此选项选中。
你还可以阻止脚本和图像。这样做可以最大限度地提高网站加载速度,并能有效防御恶意代码。
### 按你的方式搜索
如果你在搜索上花费大量时间,你会喜欢 Min 处理搜索的方式。这是一个顶级的功能。
可以直接在浏览器的网址栏中使用搜索功能。Min 使用搜索引擎 DuckDuckGo 和维基百科的内容进行搜索。你可以直接在 web 地址栏中输入要搜索的东西。
这种方法很节省时间,因为你不必先进入搜索引擎窗口。 还有一个好处是可以搜索你的书签。
在 Edit/Preferences 菜单中,可以选择默认的搜索引擎。该列表包括 DuckDuckGo、Google、Bing、Yahoo、Baidu、Wikipedia 和 Yandex。
尝试将 DuckDuckGo 作为默认搜索引擎。 Min 默认使用这个引擎,但你也能更换。

*Min 浏览器的搜索功能是 URL 栏的一部分。Min 会使用搜索引擎 DuckDuckGo 和维基百科的内容。你可以直接在 web 地址栏中输入要搜索的东西。*
搜索栏会非常快速地显示问题的答案。它会使用 DuckDuckGo 的信息,包括维基百科条目、计算器和其它的内容。
它能快速提供片段、答案和网络建议。它有点像不是基于 Goolge 环境的替代品。
### 导航辅助
Min 允许你使用模糊搜索快速跳转到任何网站。它能立即向你提出建议。
我喜欢在当前标签旁边打开标签的方式。你不必设置此选项。它在默认情况下没有其他选择,但这也有道理。

*Min 的一个很酷的功能是将标签整理到任务栏中,这样你随时都可以搜索。*
不点击标签,过一会儿它就会消失。这使你可以专注于当前的任务,而不会分心。
Min 不需要附加工具来控制多个标签。浏览器会显示标签列表,并允许你将它们分组。
### 保持专注
Min 在“视图”菜单中有一个可选的“聚焦模式”。启用后,除了你打开的选项卡外,它会隐藏其它所有选项卡。 你必须返回到菜单,关闭“聚焦模式”,才能打开新选项卡。
任务功能还可以帮助你保持专注。你可以在 File 菜单或使用 `Ctrl+Shift+N` 创建任务。如果要打开新选项卡,可以在 File 菜单中选择该选项,或使用 `Control+T`。
按照你的风格打开新任务。我喜欢按组来管理和显示标签,这组标签与工作项目或研究的某些部分相关。我可以在任何时间重新打开整个列表,从而轻松快速的方式找到我的浏览记录。
另一个好用的功能是可以在选项卡区域找到段落对齐按钮。单击它启用阅读模式。此模式会保存文章以供将来参考,并删除页面上的一切,以便你可以专注于阅读任务。
### 并不完美
Min 浏览器并不是强大的,功能丰富的完美替代品。它有一些明显的缺点,开发人员花了很多时间也没有修正。
例如,它缺乏一个支持论坛和详细用户指南的开发人员网站。可能部分原因是它的官网在 GitHub,而不是一个独立的开发人员网站。尽管如此,对新用户而言这是一个缺点。
没有网站支持,用户被迫在 GitHub 上寻找自述文件和各种目录列表。你也可以在 Min 浏览器的帮助菜单中访问它们 - 但这没有太多帮助。
一个例子是当你启动浏览器时,屏幕会显示欢迎界面。它会显示两个按钮,一个人是 “Start Browsing”,另一个是 “Take a Tour.”。但是没有一个按钮可以使用。
但是,你可以通过单击 Min 窗口顶部的菜单栏开始浏览。但是,还没有解决缺少概览办法。
### 底线
Min 并不是一个功能完善、丰富的 web 浏览器。你在功能完善的主流浏览器中所用的插件和其它许多功能都不是 Min 的设计目标。然而,Min 在快速响应和免打扰方面很有用。
我越使用 Min 浏览器,我越觉得它高效 - 但是当你第一次使用它时要小心。
Min 并不复杂,也不难操作 - 它只是有点古怪。你必须要体验一下才能明白它如何使用。
### 想要提建议么?
可以使用下方的读者评论功能说出你的想法!
---
作者简介:
Jack M. Germain 从苹果 II 和 PC 的早期起就一直在写关于计算机技术。他仍然有他原来的 IBM PC-Jr 和一些其他遗留的 DOS 和 Windows 机器。他为 Linux 桌面的开源世界留下过共享软件。他运行几个版本的 Windows 和 Linux 操作系统,还通常不能决定是否用他的平板电脑、上网本或 Android 智能手机,还是用他的台式机或笔记本电脑。你可以在 Google+ 上与他联系。
---
via: <http://www.linuxinsider.com/story/84212.html?rss=1>
作者:[Jack M. Germain](http://www.linuxinsider.com/story/84212.html?rss=1#searchbyline) 译者:[geekpi](https://github.com/geekpi) 校对:[GitFuture](https://github.com/GitFuture)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
8,375 | 用 Apache Calcite 构建强大的实时流式应用 | https://www.linux.com/news/build-strong-real-time-streaming-apps-apache-calcite | 2017-04-04T11:33:00 | [
"数据库",
"Calcite"
] | https://linux.cn/article-8375-1.html | 
Calcite 是一个数据框架,它允许你创建自定义数据库功能,微软开发者 Atri Sharma 在 Apache 2016 年 11 月 14-16 日在西班牙塞维利亚举行的 Big Data Europe 中对此进行了讲演。
[Apache Calcite](https://calcite.apache.org/) 数据管理框架包含了典型的数据库管理系统的许多部分,但省略了如数据的存储和处理数据的算法等其他部分。 Microsoft 的 Azure Data Lake 的软件工程师 Atri Sharma 在西班牙塞维利亚的 [Apache:Big Data](http://events.linuxfoundation.org/events/apache-big-data-europe) 会议上的演讲中讨论了使用 [Apache Calcite](https://calcite.apache.org/) 的高级查询规划能力。我们与 Sharma 讨论了解有关 Calcite 的更多信息,以及现有程序如何利用其功能。
**Linux.com:**你能提供一些关于 Apache Calcite 的背景吗? 它有什么作用?
Atri Sharma:Calcite 是一个框架,它是许多数据库内核的基础。Calcite 允许你构建自定义的数据库功能来使用 Calcite 所需的资源。例如,Hive 使用 Calcite 进行基于成本的查询优化、Drill 和 Kylin 使用 Calcite 进行 SQL 解析和优化、Apex 使用 Calcite 进行流式 SQL。
**Linux.com:**有哪些是使得 Apache Calcite 与其他框架不同的特性?
Atri:Calcite 是独一无二的,它允许你建立自己的数据平台。 Calcite 不直接管理你的数据,而是允许你使用 Calcite 的库来定义你自己的组件。 例如,它允许使用 Calcite 中可用的 Planner 定义你的自定义查询优化器,而不是提供通用查询优化器。
**Linux.com:**Apache Calcite 本身不会存储或处理数据。 它如何影响程序开发?
Atri:Calcite 是数据库内核中的依赖项。它针对的是希望扩展其功能,而无需从头开始编写大量功能的的数据管理平台。
**Linux.com:**谁应该使用它? 你能举几个例子吗?\*\*
Atri:任何旨在扩展其功能的数据管理平台都应使用 Calcite。 我们是你下一个高性能数据库的基础!
具体来说,我认为最大的例子是 Hive 使用 Calcite 用于查询优化、Flink 解析和流 SQL 处理。 Hive 和 Flink 是成熟的数据管理引擎,并将 Calcite 用于相当专业的用途。这是对 Calcite 应用进一步加强数据管理平台核心的一个好的案例研究。
**Linux.com:**你有哪些期待的新功能?
Atri:流式 SQL 增强是令我非常兴奋的事情。这些功能令人兴奋,因为它们将使 Calcite 的用户能够更快地开发实时流式应用程序,并且这些程序的强大和功能将是多方面的。流式应用程序是新的事实,并且在流式 SQL 中具有查询优化的优点对于大部分人将是非常有用的。此外,关于暂存表的讨论还在进行,所以请继续关注!
---
via: <https://www.linux.com/news/build-strong-real-time-streaming-apps-apache-calcite>
作者:[AMBER ANKERHOLZ](https://www.linux.com/users/aankerholz) 译者:[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,376 | 漫画赏析:Linux 版 SQL Server | https://turnoff.us/geek/sql-server-on-linux/ | 2017-04-05T09:19:00 | [
"漫画",
"SQL Server"
] | https://linux.cn/article-8376-1.html | ### Linux 版 SQL Server (一)

在 Linux 内核之中,大家正在静静的等待进程的创建。每个创建的进程会被分配一个进程 ID (PID)。
在那个 Apache 进程高高兴兴的走出去之后,下一位却被要求创建 [Linux 版的 SQL Server](/article-7967-1.html),这简直让人气的跳起来!
这个愤怒的进程宣称,“我将占用所有的 CPU 和内存!”面对其它面面相觑的进程们,内核无奈的宣布,“伙计们,我们打烊了……”
与其用 Linux 版 SQL Server,[何不用 MySQL / MariaDB 呢?](/article-8073-1.html) 大家使用过 Linux 版 SQL Server 吗?体验如何?欢迎评论。
### Linux 版 SQL Server (二)

Clark,嗯,就是那个贪婪的 Linux 版的 SQL Server,它要把 Linux 服务器撑破了,内核已经陷入崩溃了,急切需要重启。
等等,似乎我们找到了一个好办法,把 Clark 关到盒子里面去。
看起来不错哦,果然鲸鱼的大肚子能装啊——内核长吁一口气。
---
via:
* <https://turnoff.us/geek/sql-server-on-linux/>
* <https://turnoff.us/geek/sql-server-on-linux-2/>
作者:[Daniel Stori](https://turnoff.us/about/) 译者:[GHLandy](https://github.com/GHLandy) 校对&点评:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 200 | OK | # sql server on linux


### Comics Related
-
[Blue Screen of Death](/geek/bsod/) -
[don't share a pipe with cut](/geek/linux-cut-command/) -
[wc](/geek/linux-wc/) -
[permission issue](/geek/permission-issue/) -
[world backup day 2024](/geek/world-backup-day-2024/) -
[xz backdoor](/geek/xz-backdoor/) -
[pid 1](/geek/pid1/) -
[tar.gz](/geek/tar.gz/) -
[at malloc room](/geek/at-malloc-room/) -
[just compile it](/geek/just-compile-it/) -
[highest score](/geek/highest-score/) -
[chroot](/geek/chroot/) -
[full table scan](/geek/full-table-scan/) -
[shutdown!](/geek/linux-shutdown-2024/) -
[just touch it](/geek/just-touch-it/) -
[market driven humor](/geek/market-driven-humor/) -
[the real reason not to use sigkill (revamp)](/geek/the-real-reason-not-to-use-sigkill/) -
[linux free command](/geek/linux-free-command/) -
[linux top explained](/geek/linux-top-explained/) -
[hackerman](/geek/hackerman/) -
[signals](/geek/signals/) -
[mtu](/geek/mtu/) -
[unzip](/geek/unzip/) -
[skype for linux](/geek/skype-for-linux/) -
[bad malloc](/geek/bad-malloc/) -
[to save the devops world](/geek/linux-containers/) -
[beware of dog](/geek/beware-of-dog/) -
[sudo prank](/geek/sudo-prank/) -
[checksum](/geek/file-checksum/) -
[sysadmin](/geek/sysadmin/) -
[hello world!](/geek/hello-world/) -
[valentine's day at the kernel](/geek/valentines-day/) -
[what processes do when they're idle](/geek/idle/) -
[first time](/geek/first-time/) -
[kernel economics](/geek/kernel-economics/) -
[disney buys linux](/geek/disney-buys-linux/) -
[terminal transparency](/geek/terminal-transparency/) -
[the war for port 80 - epilogue](/geek/apache-vs-nginx-epilogue/) -
[terminal password typing](/geek/terminal-password-typing/) -
[forked!](/geek/forked/) -
[the chroot case](/geek/the-chroot-case/) -
[smart windows](/geek/smart-windows/) -
[windows update](/geek/windows-update/) -
[super power](/geek/super-power/) -
[escape room](/geek/escape-room/) -
[when you tail -f but forget to grep](/geek/tail-no-grep/) -
[we need to talk about ssl](/geek/we-need-to-talk-about-ssl/) -
[chown - chmod](/geek/chown-chmod/) -
[solution escalation](/geek/solution-escalation/) -
[when you hire the wrong architect](/geek/wrong-architect/) -
[ghost in the shell](/geek/ghost-in-the-shell/) -
[linus torvald's house](/geek/linus-torvalds-house/) -
[sudo (board game)](/geek/sudo-board-game/) -
[the jealous process](/geek/the-jealous-process/) -
[#!s](/geek/shebang/) -
[user space election](/geek/user-space-election/) -
[the war for port 80](/geek/apache-vs-nginx/) -
[adopt a good cause, don't sigkill](/geek/dont-sigkill-2/) -
[bash history](/geek/bash-history/) -
[the real reason not to share a mutable state](/geek/dont-share-mutable-state/) -
[one last question](/geek/one-last-question/) -
[protocols](/geek/protocols/) -
[life of embedded processes](/geek/ubuntu-core-2/) -
[ubuntu core](/geek/ubuntu-core/) -
[inside the linux kernel](/geek/inside-the-linux-kernel/) -
[zombie processes](/geek/zombie-processes/) -
[poprocks and coke](/geek/poprocks-and-coke/) -
[stranger things - in the sysadmin's world](/geek/stranger-things-sysadmin-world/) -
[who killed mysql? - epilogue](/geek/who-killed-mysql-epilogue/) -
[dotnet on linux](/geek/dotnet-on-linux/) -
[who killed mysql?](/geek/who-killed-mysql/) -
[to vi or not to vi](/geek/to-vi-or-not-to-vi/) -
[brothers conflict (at linux kernel)](/geek/brothers-conflict/) -
[introducing the oom killer](/geek/oom-killer/) -
[how i met your mother](/geek/how-i-met-your-mother/) -
[bash on windows](/geek/bash-on-windows/) -
[ubuntu updates](/geek/ubuntu-updates/) -
[sql server on linux part 2](/geek/sql-server-on-linux-2/) -
[the real reason to not use sigkill](/geek/dont-sigkill/) -
[i love windows powershell](/geek/love-powershell/) -
[linux master hero](/geek/linux-master-hero/) -
[tcp buddies](/geek/tcp-buddies/) |
8,378 | 深入点评联想 Yoga 900 笔记本安装 Arch Linux 系统 | http://keithcu.com/wordpress/?p=3739 | 2017-04-06T09:33:00 | [
"Yoga",
"Arch"
] | https://linux.cn/article-8378-1.html | *注意:这篇文章比较长,有一万多字,而且还有很多非常有意思的链接,因此,你最好还是先给自己准备点喝的吧,然后再花时间来阅读。*
在 [联想 Yoga 2 笔记本电脑](http://keithcu.com/wordpress/?p=3270) 上使用了 3 年多的 Arch Linux 系统后,我决定换个新的 Yoga 900 笔记本电脑来安装 Arch Linux 系统:

*联想 Yoga 900 笔记本电脑在[亚马逊网站上的特价](https://www.amazon.com/Lenovo-13-3-inch-Multitouch-Convertible-Platinum/dp/B01NA6ANNK/) 为 925 美元 —— 8GB 内存, 256 GB 固态硬盘, 3200×1800 的分辨率,处理器为 Skylake 3.2GHz , Iris Graphics 显卡。*
同等配置的戴尔笔记本电脑 [XPS 13](http://configure.us.dell.com/dellstore/config.aspx?oc=cax13w10ph5122&model_id=xps-13-9360-laptop&c=us&l=en&s=bsd&cs=04) 搭载新一代 Inter 处理器,售价 1650 美元。 Yoga 910 为当前最新款,价格为 1300 美元。但是,我压根就不会考虑这一款,因为它的键盘设计得太狗屎了。很多评论都从其外观颜色及材质方面大作文章,但是我偏偏从它的键盘设计上来挑刺。
### 键盘
Yoga 2 Pro 和 Yoga 900 这两款笔记本电脑从外观上看没啥区别。它的键盘设计跟曾经光鲜亮丽的 IBM Thinkpad 的键盘比起来可真是差远了,但是这还不算是最狗屎的键盘,好歹我还用了三年多的 Yoga 2 ,而且早已经习惯了。不幸的是,新款 Yoga 910 的键盘设计更是糟糕透了。

*Yoga 2 和 Yoga 900 的键盘布局*

*Yoga 910 的键盘*
Yoga 910 键盘的问题是它的 右-shift 按键位置不合理,你不挪动手根本就按不到那个键。这个键的位置非常特殊,可以说是跟我上 9 年级打字课时所用的 IBM 打字机键盘到目前为止用过的所有键盘都不一样。我宁愿看到这个失误出现在华硕或是戴尔公司的电脑上,而不是来自于曾经让一代代美国人学习和工作并且创造了打印机传奇历史的 IBM 公司。(LCTT 译注:联想的 Yoga 还和 IBM 有什么关系么?)
Yoga 团队每一年都会更改键盘布局。想象一下,如果 IBM 公司在 20 世纪的时候也不断改变他们的打印机键盘布局,而且还吹嘘这是为了提高"[工作效率]"[4](http://blog.lenovo.com/en/blog/why-you-should-give-in-to-the-new-thinkpad-keyboard)。那么这个公司可能早就倒闭了!
我基本上还能习惯 Yoga 910 的向上/向下翻页键跟方向键整合到一起,其它的一些改变也无大碍,但是 shift 键就是设计上的一个败笔,我太讨厌因为某些东西而改变自己的使用习惯了。
其实,联想笔记本电脑在键盘的设计上还有很多地方需要改进,比如说,让音量增加键与应用程序关闭键不要靠得太近。尽管目前已经有一个降低亮度的开关了,他们也可以重新考虑设计一个更简单的方式来快速关闭显示器。他们还应该设计一个重叠式的数字小键盘。难道联想的工程师觉得只有在商务工作中才会使用到数字小键盘吗?
Yoga 910 的键盘布局改变得太多了,也许再也回不到曾经的老式键盘了。我希望 Yoga 的键盘不要再随便改了。我更愿意拥有一个比电脑更高效 10 倍的键盘。
我在联想官网的评论中看到有些用户由于对 Yoga 910 的键使用不习惯的原因而申请退货。我觉得联想公司应该制定这样一条规定:如果某个工程师想更改键盘布局,他们必须给出一个**非常充分**的理由,如果这种设计给用户在使用方面造成了巨大的不便,那么将以剁其一根手指的代价来让他也体会下这种痛苦。如果真有这样一条规则,那么将会大大减少那些毫无意义的更改键盘的行为。 Yoga 910 笔记本电脑可以说是联想公司呕心沥血之杰作了,但是其输入系统却是一大败笔。
### 总体评价
Yoga 2 对于我的任何操作,其反应速度都非常快。它的固态硬盘也非常给力,但是用在 Arch Linux 系统下就有些大材小用了。那些只使用 Windows 系统的用户就不会体会到他们的系统有多么的庞大臃肿:
[](/article-8376-1.html)
在 90 年代时期,由于处理器的性能每隔 18 个月翻一倍,并且软件的大小也经常成倍的增长,因此,一款新的电脑每隔几年就会发布出来。现在早已发生了翻天覆地的变化。新款的 Yoga 900 笔记本电脑在运行性能测试的过程中,速度比我的 Yoga 2 还要快 30% 。 Yoga 900 的 CPU 主频为 3.2 GHz ,老款的 Yoga 2 主频为 2.6 GHz ,因此, Yoga 900 最大的亮点是更快的 CPU 处理频率。
Haswell 处理器架构发布于 2013 年,而 Skylake 处理器架构在 2015 年才发布,因此,经过两年的发展,处理器性能有了很大的改善。新一代的处理器最大的改进是采用 14 纳米工艺制造技术来代替原先的 22 纳米工艺技术,这意味着新款笔记本电脑散热更小,电池使用时间更长。我的老款的 Yoga 2 笔记本在中等亮度的情况下,电池使用时长只有 3 个半小时左右,但是新款 Yoga 900 的电池使用时长高达 7 小时。
Yoga 2 的转轴已经开始松动和裂开了,我也没有一个好的办法来拧紧,只能从网上找新的配件来更换或者发给联想售后进行维修了。

Yoga 的转轴用于将笔记本电脑放平,甚至是将电脑合起来作为平板电脑使用,但是我觉得这样用起来很笨重,所以也就不想去自找麻烦。这么多年来,只要它在日常工作中能够正常打开和合拢,我就已经很高兴了。
Yoga 900 坚固的表链式铰链应该更耐用:

有一个很明显的小毛病就是如果你摇晃笔记本电脑时,其格格作响的声音会让你误以为是内部的零部件损坏了,你自然会担心电子器件短路的危险!然而,这只不过是 800 多片钢片构成的仿表带铰链发出的声音。
Yoga 2 总的来说是一款设计精良的产品,但是如果我将显示器展平,然后单手拖住的时候,它会有一点向下弯曲,而且有时候键盘背光灯也会熄灭。两款 Yoga 笔记本电脑都很轻薄,但是 Yoga 900 看起来更坚固耐用一些。
### 触摸板
Yoga 2 最严重的问题出现在触摸板上。这不是硬件导致的,而是驱动程序自身的问题,由于触摸板驱动程序本身没人在维护,因此存在一些缺陷。很遗憾, Synaptics 公司本来可以很轻易地安排一个工程师来维护这几千行的代码,但是联想重新写了另外一个版本的驱动程序,但是还没有开源发布出来,以便可以包括到系统内核中。
因此,为了让触摸板设备和其它输入设备的管理和使用更加方便简捷,建立了一个叫做 [Libinput](https://www.freedesktop.org/wiki/Software/libinput/) 的新软件库。 Libinput 最好的一点就是,维护人员会修复各种缺陷。还有一个很实用的功能就是如果你左指尖触摸鼠标单击区域,它现在会通过你的右指尖记录指针移动轨迹。但是,让人难以接受的事情是, Synaptics 的这个基本的功能在 Linux 系统中很多年前就无法使用了。
触摸板设备一直运行正常,但是它不再像以前那样发出敲击声了。实际上这也不是什么问题,但是这会让我担心我在触摸板上的操作是否正确。老款的 Thinkpad 笔记本电脑有好几个左右按键,因此,如果其中一个损坏了,你可以使用另外一个,但是 Yoga 笔记本只有一个鼠标左右按键,如果损坏了就只能插入鼠标来代替使用了。(联想还巴不得你的电脑赶紧坏了好换新的。)
### 内核支持
当年我购买 Haswell 处理器的笔记本电脑时,硬件都是最新的,因此,我折腾了好几个月才把 Linux 驱动程序相关的问题解决了。而现在我使用的新一代的 Skylake 处理器的笔记本电脑,在[处理器发布 8 个多月后](https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=762ce4458974534a2407cc924db05840c89105df),其内核崩溃的问题才被修复了。以前老款笔记本电脑的 [电源管理](https://mjg59.dreamwidth.org/41713.html) 一直运行不正常,但是从新款笔记本电脑使用来看,以前的问题大都不存在了,而且有了很大的改善。如果用户不进行任何操作,这个笔记本电脑会自动进入到低功耗的 C6 - C10 状态。(这个功能是由 Linux 系统中的 **powertop 省电工具** 进行控制的。)
电源管理这个功能非常重要,它不仅会影响到电池的使用寿命,而且由于[电解迁移](https://en.wikipedia.org/wiki/Electromigration)的原因,那些微小电路会逐渐耗尽。英特尔公司甚至发出公告:”电池使用的长期可靠性是无法保障的,除非所有程序都运行在低功耗的空闲状态。“通过让程序运行在低功耗模式下,以使用更小的电路,从而让电池使用寿命更长。
现在 Haswell 处理器架构对 Linux 系统的支持性已经非常好了,但是之前的很长一段时间,它的支持性都很差。刚开始那一年,我提出了很多 Haswell 处理器相关的问题,但是现在可以看出这两款处理器在对 Linux 系统的支持上都有了很大的改善。
### 联想笔记本的 BIOS 不兼容 Linux 系统
在 Yoga 900 电脑上安装 Arch Linux 系统之前,我得在 Windows 系统中再刷一个新的 BIOS 。实际上,我的电脑中得有 2 个 BIOS。最新版本的 Yoga 900 BIOS [不包括](http://support.lenovo.com/us/en/products/Laptops-and-netbooks/Yoga-Series/yoga-900-13isk2/80UE/downloads/DS112754)我需要的必备修补程序,所以在挠头了一会之后,我恍然大悟,然后我 [安装](http://support.lenovo.com/us/en/products/laptops-and-netbooks/yoga-series/yoga-900-13isk2/downloads/ds119354)了一个单独的“仅 Linux 系统”的 BIOS 更新,这样我的联想电脑就不再支持 Windows 系统了:“你不[可怜](https://linux.slashdot.org/comments.pl?sid=9861381&cid=53241071)下我吗?”
那些经常关注 Linux 系统的用户就很清楚, Yoga 900 和其它最新款的联想笔记本电脑无法安装 Linux 系统,因为它甚至不能[检测到硬盘](https://www.reddit.com/r/linux/comments/54gtpc/letter_to_the_federal_trade_commission_regarding/)。联想最初回复其笔记本电脑已不再支持 Linux 系统了,因为它使用的是[新型的 RAID 控制器模式](http://venturebeat.com/2016/09/21/lenovo-confirms-that-linux-wont-work-on-yoga-900-and-900s-laptops/) 。然而,实现 RAID 机制就意味着更多的磁盘,而笔记本电脑实际上只有一个硬盘,并且也没有多余的空间来安装另外一块磁盘了。
下面是联想给出的[官方解释](http://venturebeat.com/2016/09/21/lenovo-confirms-that-linux-wont-work-on-yoga-900-and-900s-laptops/):
>
> “为了更好地支持 Yoga 系列产品以及行业领先的 360 度铰链转轴设计技术的发展,我们采用了一种存储控制器模式,很遗憾,这种模式不支持 Linux 系统,不能够安装 Linux 系统。”
>
>
>
我觉得很搞笑,为了转轴而采用特殊的存储控制器!这就好比一个汽车制造公司宣称由于新型的广播设备,他们必须改变汽车的轮胎一样。
这引发了巨大的争议,感谢 Reddit 网站的 [BaronHK](https://www.reddit.com/user/baronhk/) 的努力,他为媒体提供了大量的信息,并联系了伊利诺斯州检查院。搜索 "[联想 Yoga 的 Linux 兼容性](https://duckduckgo.com/?q=lenovo+yoga+linux+compatibility&t=hs&ia=web)" 出现 300,000 条结果。联想或许会因为销售不允许用户安装自己的操作系统的“通用”PC 而触犯法律。对于我来说,为电脑设置默认的操作系统是毫无意义的。
技术高手们也被卷入到这场“战争”中进来,他们最终发现通过设置 UEFI ,这款笔记本也能够支持 AHCI 控制器模式,只是默认被禁用了。简单来说,联想故意取消对 Linux 系统的支持没啥好处。因为大家都已经明白事实真相了,如果这件事闹到法庭上,联想也只能自取其辱。
幸运的是,这些新闻引起了他们的关注,并且他们最终更新了 BIOS 。这篇文章就是在运行着 Linux 系统的 Yoga 900 笔记本电脑上写的,因此,我们应该庆祝下这个伟大的胜利。大家都希望联想从中受到教训,但是我并不看好。他们本来就应该为你的电脑提供一个选择操作系统的机会。他们应该在用户之前就发现了这个缺陷了。我将等待一周左右的时间才能拿到定制化的电脑。他们应该把分区设置好,并且让用户定制很多东西,安装最新版的软件,而不是使用一个需要很多更新的老镜像文件。
一些钟爱联想电脑的用户认为这是 Linux 系统自己的问题,是 Linux 系统本身就不支持最新的 RAID 驱动模式导致的问题。然而, AHCI 控制器模式本来是一个非常流行的标准,而由于英特尔公司为这种新的 RAID 硬件写的代码“[太糟糕](https://www.spinics.net/lists/linux-ide/msg53370.html)”而被 Linux 系统内核开发团队拒绝了。该团队要求英特尔公司提供这种硬件的详细设计说明,但是他们一直没有给出任何答复。
### 散热
当 CPU 占用很高时, Yoga 2 笔记本会变得很烫。有一次我把笔记本放到毯子上编译 LibreOffice 软件时就把底部的塑料壳烧焦了,这实在是太丑陋了,这让我看上去像是一个很穷酸的程序员。我试着用铁刷子和松脂油来擦除烧焦的部分,但是也没什么鸟用。

新款的笔记本电脑使用金属外壳,不容易褪色,并且 Skylake 处理器架构比 Haswell 的要强劲得多。把散热口设计了跟转轴融合在一起,这是一个非常明智及巧妙的做法,如果散热口在下方则可能被堵塞住。
用了很多年的 Yoga 2 ,我觉得最烦人的一件事就是它的风扇里累积了厚厚的尘埃,运行时听上去就像是沙子摩擦的声音!这些尘埃分布得很广,使用时产生的声音也大,让人容易分心。我把笔记本电脑拆开来清除里面的尘埃,但是风扇的叶片是隐藏的,无法进行清除。我只能把整个风扇替换掉了。在 Yoga2 上完成简单的工作,比如文字处理和浏览器上网时,风扇不会旋转,但是当它旋转时,如果不带耳机会感到很烦人。
Yoga 900 的风扇叶片密度很高,而且运行的很平稳,也不会让人分心。 Yoga 900 的风扇好像一直都在旋转,但是速度非常慢,而且声音很小也很安静。我家里电冰箱和空气净化器的声音都要比它大得多,除了笔记本电脑在高负载的情况下声音有点大,不过那也不影响我工作。
### 显示器
Yoga 2 的显示屏很大气,但是也同样存在大家所熟知的问题,比如屏幕上的黄色看上去更像是橙色。然而,整体画质看起来还算细腻,其它颜色方面也不错。 Yoga 900 的屏幕已经修复了那个黄颜色的问题。它不是一个真正的 4K 屏,实际上仅有 3200×1800 的分辨率,但是从 15.6 寸的显示屏上看,它的像素要比真正的 4K 屏要细腻得多,所以显示效果超级锐利。有些人说这屏幕分辨率是假的,因为它使用了“[RG/BW Pentile 矩阵](http://i.imgur.com/8pYBfcU.png)”,但是对我来说,高分辨率的图片看起来就很棒,何况文本。
当年我购买 Yoga 2 笔记本电脑时,由于其使用的是当时最新的 Haswell 处理器架构,所以我遇到了各种英特尔显卡显示异常的问题,这些问题过了几个月后才被解决。之后,我还发现了一个会导致 Linux 系统崩溃的内存泄漏问题,并且这个缺陷好多年都没被处理。
我在 VLC 播放器中使用 shift + 箭头键快进视频时,遇到了好几次内存耗尽的问题。系统也没显示 VLC 播放器占用了多少的内存,但是电脑内存却耗尽了。很明显这是内核导致的内存泄漏问题。我创建了一个 swap 文件作为虚拟内存使用,以减少内存耗尽的时间,但是有好几次我没注意时,这个文件又被占满了。几年后,这个问题逐渐消失了,而且现在 Linux 系统也运行得很稳定。
大家都认为英特尔公司为 Linux 系统开发的驱动程序是最好的,但是他们更像是微软内部的一个秘密的臭鼬工厂项目。英特尔公司的驱动程序开发人员都很专业,就是人员不够多。在发布硬件之前,他们都竭力让驱动程序做得更完美。 英特尔公司生产的 [113 款处理器](http://ark.intel.com/products/codename/37572/Skylake) 都是基于 Skylake 处理器架构的,只是在特性上有细微的区别。听起来你会觉得有很多类型的处理器,但是在 [Haswell 处理器](http://ark.intel.com/products/codename/42174/Haswell#@All) 时期,英特尔公司生产了 256 款芯片。10 年前我听一个英特尔公司的员工说过,相对于 Windows 来说,他们仅投入了 1% 到 Linux 系统上,从现在的情形来看,确实是那样的。
在我使用 Yoga 2 的过程中唯一遇到的性能问题是无法正常播放 4K 视频,屏幕经常出现卡顿,或是出现每秒才播放 5 帧的现象:

Yoga 2 甚至是在播放 1920×1080 分辨率的视频时有时候也显得很吃力,看样子它最多只能以 60fps 的速度来播放视频。出现这样的情况也可能是因为我一直在运行着其它的应用程序,比如 Firefox 浏览器和 LibreOffice 办公软件。
Skylake 处理器主要用于在 60fps 的速度下使用 H.264 、 VP9 以及其它编解码方式来播放 4K 视频。实际上这款处理器中有很多硬件专门用于加速[多媒体特性](http://www.anandtech.com/show/9562/intels-skylake-gpu-analyzing-the-media-capabilities)。我尝试使用 **ffmpeg 软件** 来处理 H264 格式的硬件编码,我发现即使只使用一个 CPU 的情况下,其处理速度也比原来的处理器快 4 倍。这种性能太棒了。不爽的是,在设置的过程中有点麻烦,因为你必须使用很多命令行参数:
```
-threads 1 -vaapi_device /dev/dri/renderD128 -vcodec h264_vaapi -vf format='nv12|vaapi,hwupload'
```
我尝试找到一种方法让 **ffmpeg 软件** 保存这些命令,这样我就不用每次都手动输入这么多参数了,但是最后发现根本行不通。而且无论怎样,在整个过程中也不能自动传递这些参数。我还发现在使用这个硬件的的过程中不能缩放视频尺寸,它会忽略该操作,因此,我很少会用这个工具。如果 **ffmpeg 软件** 可以实现这一点就完美了。由于很多用户都不了解,或者是不想太麻烦,所以还有很多未使用的硬件资源。这个软件有很多跟 Linux 系统和 Windows 系统相关的应用接口,如果要进行视频编码和解码,将会是[一件麻烦事](https://trac.ffmpeg.org/wiki/HWAccelIntro)。
Skylake 处理器架构在播放 4K 视频方面表现得更出色,但是有时候它也会出现卡顿现象,然后瞬间降到 10fps 的播放速度。我想起其中一部分卡顿现象就是在播放《X 战警》的过程中。我尝试在 Wayland 下播放 4K 视频时却很流畅,这让我非常满意。很高兴看到 OpenGL 给予的大力支持。在硬件方面, 英特尔公司 2014 年以来支持的最新版本是 4.5 。
我的 Yoga 900 (-13ISK2)笔记本电脑实际上是一个升级版,使用比 520 [更快](http://www.game-debate.com/gpu/index.php?gid=3295&gid2=3285&compare=iris-graphics-540-mobile-vs-intel-hd-graphics-520-mobile) 的 Iris 540 图像协同处理器,而且它的流处理器多达 24 个。然而,它只能用来玩 SuperTuxKart 游戏,而且还得将游戏显示效果设置为中等,分辨率调整为 1600×900 ,速度为 20fps ,我也不想在这里吹什么牛。说真的,这款游戏比前几年改善了很多,而且游戏界面也漂亮得多。

英特尔公司在中国有一个团队致力于[使](https://www.freedesktop.org/wiki/Software/Beignet/) 该显卡支持 OpenCL。但是,我从未看到 Blender 的任何用户使用它,因此我怀疑这个团队是不是作摆设用的。英特尔公司已经很长时间都没有支持 OpenCL 了,那些使用 Blender 软件处理重要工作的用户早已换成 Nvidia 或者 AMD 显卡,即使英特尔公司后来重新写了代码,大家也没太多的兴趣做测试。
有一件事让我感到非常意外,我在另外一台机器上做光线追踪测试时发现,一个四核的处理器比使用循环引擎的 NVidia 960M 的处理器要快得多。很明显,在处理那个任务时, 640 CUDA 多核心处理器也比不上 4 个英特尔公司的 CPU 。更高级的英特尔处理器有 2000 多个核心,性能更强悍。
### HiDPI 高分辨率支持
最近这三年来, Linux 系统在高分辨率屏幕方面已经做得越来越好了,但是仍然有很长的路要走。还好目前的 Gnome 版本对 HiDPI 的支持也算完美。如果你把火狐浏览器的 **layout.css.devPixelsPerPx** 这个参数值设置为 2 ,其显示效果更美观。然而这个 13.3 寸的屏幕分辨率还是显得略小了些,我还安装了一个无斜视加强版(No-Squint Plus)插件,这让屏幕在 120 度范围内看起来更方便。
很高兴地看到 LibreOffice 办公软件的界面在当前设置的屏幕下变得更加美观,因为我安装了 2014 年 4 月份发布的[一些补丁](http://keithcu.com/wordpress/?p=3444),而且这些功能还一直在不断的完善中。最大的问题是 LibreOffice 软件界面的工具图标重叠起来了。有很多主题都包括 SVG 图标,但是这些图标不会跟产品一起发布出来。跟 PNG 类型的图标相比, SVG 图标加载更慢,而且还要缓存才行。[Tomaž Vajngerl 在这方面投入很多的精力](https://cgit.freedesktop.org/libreoffice/core/log/?qt=grep&q=hidpi),但是还未发布出来。尽管这样, LibreOffice 比那些没有易识别图标的 Linux 系统应用程序要漂亮得多。
应用程序在高分辨率屏幕中的检测与应用方面正在不断的完善,但是还有其它一些很流行的程序,比如 Gimp ,Audacity 和 Inkscape 仍然不能使用高分辨率屏幕。我为 Gimp 软件安装了一个很强大的定制化主题,但是所有的图标都变得大不一样,尽管这些图标已经显示得够大了,但是也很难识别出来。
Linux 系统占有了 1.5% 的市场份额,遗憾的是这些问题并没有得到更多的重视。虽然很多应用软件逐步使用 GTK 3 来开发它们的图形界面,但是比如说 Audacity 这款音频处理软件好像是已经[终止](http://wiki.audacityteam.org/wiki/Linux_Issues#Hi-DPI)开发了。在我的第一篇评论中我发现,那些提供长期支持的应用程序仍然有很多地方需要改进,但是 3 年多过去了,即使是那些很出名的软件也没做到位。
### SSD 固态硬盘
由于我平时对系统做了各种各样的优化,尤其是对火狐浏览器做的优化,因此我的老款电脑的硬盘仍然可以正常工作。还记得我的 **/tmp** 目录被我自动设置为 RAM 设备,因此,我经常把文件默认下载到那里。有时候我要把一个 500 MB 的视频剪辑成 20 MB 的小视频,或者是转换成另外的格式,因此我在 /tmp 目录下做这些工作节约了大量的写入操作。这样做需要更多的工作量,也可能没必要,但是在 RAM 存储中运行速度更快。
在这三年里,我几乎对每个硬盘的存储单元做了 25 次写入,这意味着这块硬盘可以使用 350 年左右。绝大部分的写操作都用于 Arch Linux 系统的更新。我每个月都会构建新的 LibreOffice 软件,每周都会更新“稳定”版系统内核。实时把系统升级到最新棒真的让人很爽,但是与 Debian 的稳定版系统相比起来,这将会进行 100 多次写入操作。然而,能够让每一个系统组件都升级到最新版,这也是值得的。
新的三星硬盘诊断工具无法检测出每个硬盘存储单元的写次数。事实上,我也不能确定这个硬盘的存储单元类型是什么以及在处理任务的过程中写了多少次。我相信从“已用百分比“这个数据可以看到硬盘的使用时长,但是也许这只跟空闲的存储单元有关。我没有找到任何相关文档,因此我只能猜测到大致跟下面的数据差不多了:
| **型号:** | **SAMSUNG MZVLV256HCHP-000L2** |
| --- | --- |
| **固件版本(0x06):** | **3 Slots** |
| **可用空间:** | **100%** |
| **可用的空闲阈值:** | **10%** |
| **已用百分比:** | **0%** |
| **读取的数据单元:** | **198,997 [101 GB]** |
| **写入的数据单元:** | **305,302 [156 GB]** |
| **主机读命令:** | **3,480,816** |
| **主机写命令:** | **10,176,457** |
| **错误日志条目:** | **5** |
### 损坏的左 Ctrl 键
在使用了几个小时之后,我发现一个问题,如果我按键盘左上角时,左 Ctrl 键会弹起来:

*损坏的 Yoga 900 按键:注意跟右侧对比下,你会发现左侧少了个小圆柱体形状的东西:*
Yoga 900 键盘布局跟 Yoga 2 Pro 版一致,但是内部结构不同。 Yoga 2 Pro 版的键盘不能单独移除和替换按键,而且你也没有办法撬起任何按键,除非那个按键被你彻底搞坏了。 Yoga 900 的按键跟老款的 Thinpad 笔记本一样的:每个按键都是分开的,你可以单独取下来进行更换。
然而,还有一个小毛病,每个键轴有 4 个小圆筒状的凹槽部件,如果不小心丢失了一个,那么该按键就只有三个接触点了,如果你不敲击到按键的中间位置,那么这个按键的键帽将会逐渐脱落下来。
我把这个问题反馈给联想。尽管这些按键还能使用,也可以替换成新的,但是他们只替换整个键盘,不会寄送任何零散部件。他们建议我把笔记本电脑寄给联想售后中心进行维修,或者是送到极客小组服务中心。我知道寄到联想售后的话至少要 2 周的时间,因此我咨询了当地的商店,看他们是否有 Yoga 笔记本的键盘配件。他们告诉我,他们不维修电脑,只负责把它寄到亚特兰大。那里曾经有很多地方可以维修 IBM 的各种笔记本电脑,而且也有各种配件,但是现在已经是不可能的了。
我用了好几个小时后才注意到了这个问题,我确信那是生产笔记本电脑过程中的疏忽导致的。这是一块非常小的塑料块,在装配的过程中就早已变形或损坏了。
尽管这个电脑还在保修期,可以免费进行维修,我可不想为这些小事情耽搁太多时间,因此我在网上找到一个叫做 laptopkey.com 的网站,然后订购了一个换键和支架。真是太诡异了,竟然有三种类型的支架!我花了好一会才搞明白我的电脑适合哪一种类型,因为这三种类型太难区分了:

因此我预定了这个配件,但是还得花费至少一个星期的时间才到收到。这真是太让我抓狂了,因为我每次使用复制粘贴、视频跳跃或者是在编辑器里按单词移动及其它相关操作时,只能使用右 Ctrl 键。我觉得我可以把右边的 Ctrl 键更换到左边来,但是我从未这么弄过。
因此,我尝试跟着网上找到的视频步骤把这个键弄下来:我先用指甲扣起左上角到一定高度。然后用同样的方式操作右上角,但是另外一个小塑料片被折断了,因此我弄坏了两个键轴。如果不损坏这些非常细小的塑料夹片,根本不可能把按键撬下来。这种类型的键盘只不过是理论上可以进行更换吧。
因此,我决定采用笨办法,使用强力胶。我情愿让这个该死的按键就这样固定死了,我暂时没有一个紧急的方法来替换它们。这真是太折腾了,因为我只需要大概直径 1mm 的胶水:如果弄太多的胶水可能会让情况变得更糟糕。
我维修小型遥控飞机的经验在维修电脑上也非常有帮助,我修好它了,而且左边的 Ctrl 键也固定好了。右边的那个 Ctrl 键还处于分离状态,但是我几乎用不到。我的心情又好起来了,真是柳暗花明又一村啊,但是懂得如何维修电脑也是个非常重要的技能。
### Antergos 与 Arch Linux 系统对比
在我使用了 3 年多的 Arch Linux 系统之后,我再也没兴趣去尝试其它操作系统了。虽然英特尔公司更新驱动程序的步伐有些落后,但是无论怎样,在日常工作中使用 Arch Linux 系统还是挺让人愉快的,而且每一个星期都有所进步。实时更新任何程序真的让人很爽。我经常使用比 Ubuntu 系统发布时间还要新的软件包。虽然 Ubuntu 用户可以在自定义的 PPA 中找到更新的软件包,但是这种软件包都没有经过任何测试或修复,因此用户在使用过程中会遇到各种各样的问题。
也有用户抱怨 Ubuntu 系统升级时会导致机器自动重启或者强制用户重新安装软件,因此,即使安装的过程很快,之后却需要很长的时间来维护。我每次听到有人抱怨 Arch 系统的安装过程时,最终的原因总是归结为他们自己操作不当或是类似 btrfs 文件系统损坏的问题。
我曾经想尝试安装 [Antergos 系统](https://antergos.com/),那是一款基于 Arch Linux 并搭载了桌面环境的 Linux 发行版。然而,安装过程中的设置界面在显示器上看不清楚,而且最小化安装后也识别不到触摸板,那是由于我仅有一个有可用空间的老式 1 GB U 盘了。因此,我决定还是重新安装原来的 Arch Linux 系统。还好 Yoga 笔记本仍然支持传统的 BIOS 启动方式,这样我就不用再去折腾 [UEFI](https://wiki.archlinux.org/index.php/Unified_Extensible_Firmware_Interface) 了。
很遗憾我没能试用 Antergos 系统,因为我觉得对于那些技术水平一般的用户或是想快速入门 Arch Linux 系统的用户来说, Antergos 算是一个非常强大的 Linux 发行版了。 Arch 在维基上有丰富的文档新资料教你如何完美地使用这个 Linux 系统。我喜欢优化,比如每周定时对固态硬盘做优化、[用户配置文件-同步-进程](https://wiki.archlinux.org/index.php/Profile-sync-daemon)脚本、对安卓系统的支持以及在视频播放中使用硬件加速等等。在 Linux 系统中有很多大家都需要去折腾的功能特性,只需要输入几行命令就可以搞定了。
Manjaro 也是一款非常流行的基于 Arch Linux 并搭载了桌面环境的 Linux 发行版,但是用了 3 年多的 Arch Linux 系统后,我更信任 Arch 的封包人会解决组件之间的问题。我在 Reddit 网站看到一些评论,有用户反映说 Manjaro 系统升级后就崩溃了。
我对 Arch Linux 系统唯一不爽的一点就是它丑陋而看不懂的引导加载界面。还好我只需要使用老电脑中的 **grub.cfg** 配置文件来替换掉就可以了。
### 安装 Arch Linux 系统
起初我只想简单地把硬盘从老的笔记本电脑移植到新的笔记本电脑上,这样我就不用安装任何东西了,但是拆开电脑后,我发现 M.2 接口的固态硬盘形状很特殊。本来我也可以使用一个低级块复制方法来完成移植,但是这一次是一个很好的回顾安装过程的机会,所以我决定从头再来一遍。 3 年多的时间里,我安装了很多没用的应用程序,即使有些被我卸载了,系统中还存在很多的遗留文件。
由于 Arch 900 笔记本电脑已经发布出来一段时间了,其硬件也不是最新的,所以安装 Arch Linux 系统的过程进行得很顺利。我仍然需要使用 **rfkill 工具来开启无线上网** 功能,除此之外,系统都正常运行了。显然, Linux 系统下还不能正确读取该型号的 rfkill 信息。幸运的是在启动 rfkill 工具时, **systemd** 会自动恢复 rfkill 的数据。
### 内核故障列表
有一件事让我非常惊讶, Linux 操作系统的缺陷列表太混乱了。我知道有很多的用户参与其中,其变化频率也很高,但是,最糟糕的事情却是系统缺陷报告依然如故。我搞不懂为什么有些系统缺陷已经存在好多年了,但是却丝毫没有修复的迹象。
我在上次的评论中打过一个很好的比方。假设航空公司花了一两年的时间才把你丢失的行李找回来了。还你会信任那家公司吗?实际上,如果你还有几千个已知的系统缺陷和上百次系统性能回退,那么你发布新的发行版有什么意义呢?如果波音公司的每一架飞机都有 1% 的坠机概率,那他们会这么多年都置之不理吗?
也许 Linux 系统基金会应该雇佣一些专职的工程师来修复那些看似被遗忘的系统缺陷问题。有很多人从事 Linux 系统工作,大家都清楚该系统有很多历史缺陷未修复——通常情况下,这些问题都是由普通用户自己处理的。我觉得目前的 Linux 系统就不要发布任何更新了,先花几个月的时间去修复那些系统缺陷,直到缺陷数量小于 50 个时,再发布新版本,这样的系统内核会更稳定。现在还有 [4672 个](http://bit.ly/LinuxBugs)系统缺陷问题未解决,这才是一个非常好的改变发行版主版本号的理由。
有些东西跟每周发布一个新的稳定版本是相悖的,但是这种方式还持续了这么多年了,而且他们每次都发布一些重要补丁,因此他们也算是做了一些非常有意义的工作。内核的开发速度很快,也变得越来越好,因此早已超出我吐槽的范围了,但是我还是觉得他们应该尝试换个思路。
至少,系统缺陷问题应该在规定的时间内处理。如果超出指定时间,这个系统缺陷应该提交给到维护者并逐渐发送给 Linus 本人。如果某个领域内存在很多的历史缺陷也没人去修复,那么 Linus 应该公开并严厉批评相关组织机构。他们更应该像波音公司那样去思考解决问题。
### 联想公司
很多 Linux 用户都痛击联想公司对定制化的笔记本缺少支持,好在他们创造了性价比较高的硬件。正如我多年前写的一样,很明显,联想公司在发布 Yoga 2 之前就没人安装过 Linux 系统来进行测试, Yoga 900 笔记本也是如此,因为这是根本不可能的事情。
我觉得他们公司的每个员工都应该安装双系统。这在设置上并不难,用户也更希望他们这样做。联想有 60000 多员工。至少他们应该在公司内部成立一个 Yoga 团队,然后招一些人来着手处理 **Linux 系统** 问题。Windows 系统在很多方面比 Linux 系统更难用。Windows 系统虽然能够运行更多的应用程序,但是我觉得也许他们一半的用户还是更乐于使用合理配置的 Linux 系统吧。
尽管现在联想对 Linux 系统很不屑,他们制造的麻烦比软件方面还多。在很多型号的笔记本电脑中, RAM 芯片被焊接固定了。他们只允许白名单设备和预授权的卡可以安装到联想笔记本电脑中。 Yoga 笔记本也没有独立显卡,而且联想公司本来也不支持更新主板上的卡。我想有人会把这些矛头指向联想公司的 CEO 。
### 总结
Yoga 900 笔记本电脑的售价确实让人激动不已,而且相对于前一款 Yoga 2 来说,其改进方面也是有目共睹的。相近配置的苹果 Macbook Pro 笔记本电脑价格为 1500 美元,但是像素却比 Yoga 900 少了 40% 。
Windows 系统从 Linux 系统中汲取了很多特性,但是 Windows 系统一直没有一个包管理器来对那些非常有趣的且免费的预编译软件组件提供本地支持。因为 ffmpeg 工具使用很多的[依赖包](https://ffmpeg.zeranoe.com/builds/),所以在 Windows 系统中安装 \**ffmpeg \** 工具就是一件很头疼的事,
微软建立了 Windows 应用商店,这有点类似 Linux 系统中的软件仓库,但是它不会处理软件包之间的依赖性,而且也不允许用户设置个人软件仓库。微软还开发了一个新的包管理器,叫做 [NuGet](https://www.nuget.org/),但是它主要用于 .Net 语言开发的软件。也包括 ffmpeg 工具的安装包,但是没有与该代码相关的任何依赖包,因此即使安装完成后也没啥用。
去年 3 月份,[微软公司宣布](https://blogs.windows.com/buildingapps/2016/03/30/run-bash-on-ubuntu-on-windows/) Windows 系统支持运行 Ubuntu 的命令行及应用程序,这的确是一个革命性的转折点。([他们本应该先支持 Debian 系统](http://keithcu.com/wordpress/?page_id=558)。)甚至还有[热议](https://github.com/Microsoft/BashOnWindows/issues/992)声称 Windows 系统将会支持更多的 Linux 发行版,这真是太让人激动了。
至少对于我来说,我不需要使用任何 Windows 的应用程序,也不需要浪费额外的时间去维护了。在 Windows 系统中修复问题时,你可以到很多不同的地方查询解决问题的方法。 Linux 系统有很多的地方要进行配置,但是总的来说,这已经很简单了。
我有个朋友为了更新驱动程序,需要在 Windows 下安装第三方软件,因为更新这种操作需要从微软网站以及其它更多的网站来抓取代码。 Windows 系统已经比前几年做得更好了,有更多的游戏和桌面应用程序,但是它仍然是一个封闭式老系统。
我发现 Gnome 经典桌面给人一种简洁性的体验。我希望它不是使用很繁杂的[流行 Javascript 脚本](http://notes.ericjiang.com/posts/751)语言编写的,他们还要重新建立一个关于定制化主题和颜色主题的社区。 Gnome 2 和 Windows 10 系统中的有些非常有用的功能也消失了,而且也没有老版本的稳定。 2011 年发布的 Gnome 3.0 完全就是走回头路,但是 6 年后的 Gnome 3.22 终于再续辉煌。
Gnome 经典桌面环境是最优秀的图形化界面之一,[很多优秀的特性](https://wiki.archlinux.org/index.php/Desktop_environment)都变得越来越好了。已安装完成 Arch Linux 系统的 Yoga 900 笔记本电脑现在都运行正常了,我期待着 Linux 系统对 HiDPI 模式和其它方面的改进!我迫不及待地想深入学习 LibreOffice 办公软件里的语法检查特性。
---
via: <http://keithcu.com/wordpress/?p=3739>
作者:[keithccurtis](http://twitter.com/keithccurtis) 译者:[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,379 | 如何挑选你的第一门编程语言 | https://opensource.com/article/17/1/choosing-your-first-programming-language | 2017-04-06T16:26:43 | [
"编程语言"
] | https://linux.cn/article-8379-1.html | 想学编程的原因有很多,你也许是想要做一个程序,又或者你只是想投身于这个行业,所以,在选择你的第一门编程语言之前,问问你自己:你想要在哪里运行程序?你想要程序来完成什么工作?

你学习编程的原因将会决定你的第一门编程语言的选择。
在这篇文章里,我会交替使用<ruby> “编码” <rp> ( </rp> <rt> code </rt> <rp> ) </rp></ruby>、<ruby> “编程” <rp> ( </rp> <rt> program </rt> <rp> ) </rp></ruby>、<ruby> “开发” <rp> ( </rp> <rt> develop </rt> <rp> ) </rp></ruby> 等动词,<ruby> “代码” <rp> ( </rp> <rt> code </rt> <rp> ) </rp></ruby>、<ruby> “程序” <rp> ( </rp> <rt> program </rt> <rp> ) </rp></ruby>、<ruby> “应用程序” <rp> ( </rp> <rt> application </rt> <rp> ) </rp></ruby>、<ruby> “应用” <rp> ( </rp> <rt> app </rt> <rp> ) </rp></ruby>等名词。这是考虑到了你可能听过的语言用法。
### 了解你的设备
在你编程语言的选择上,你的程序将运行在何处是个决定性因素。
桌面应用是运行在台式机或者笔记本电脑上的传统软件程序。这样你编写的代码在同一时间内只能在一台电脑上运行。移动应用,也就是我们所熟知的“app”,运行在使用 IOS 、Android 或者其他操作系统的移动设备上。网页应用是功能像应用的网页。
按互联网的 客户-服务器(C/S)架构分,网页开发者经常被分为两类:
* 前端开发,就是编写运行在浏览器里面的代码。这是个面对用户的部分,或者说是程序的前脸。有时候被称为“客户端编程”,因为浏览器是网站的客户-服务器架构的客户端部分。浏览器会运行在你本地的电脑或者设备上。
* 后台开发,也就是大家所熟知的“服务器端开发”,编写的代码运行在你无法实际接触的服务器上。
### 创造什么
编程是一门广泛的学科,能应用在不同的领域。常见的应用有:
* 数据科学
* 网页开发
* 游戏开发,以及
* 不同类型的工作自动化
现在我们已经讨论了为什么你要编程,你要程序运行在哪里,让我们看一下两门对于新手来说不错的编程语言吧。
### Python
[Python](https://www.python.org/about/) 是对于第一次编程的人来说是最为流行的编程语言之一,而且这不是巧合。Python 是一门通用的编程语言。这意味着它能应用在广泛的编程任务上。几乎**没有**你不能用 Python 完成的工作。这一点使得很多新手能在实际中应用这门编程语言。另外, Python 有两个重要的设计特征,使得其对于新手更友好:清晰、类似于英语的[语法](https://en.wikipedia.org/wiki/Python_syntax_and_semantics),和强调代码的[可读性](https://en.wikipedia.org/wiki/Python_syntax_and_semantics#Indentation)。
从本质上讲,一门编程语言的语法就是你所输入的能让这编程语言执行的内容。这包括单词,特殊字符(例如 `;`、`$`、`%` 或者 `{}`),空格或者以上任意的组合。Python 尽可能地使用英语,不像其他编程语言那样经常使用标点符号或者特殊的字符。所以,Python 阅读起来更自然、更像是人类语言。这一点帮助新的编程人员可以聚焦于解决问题,而能花费更少的时间纠结于语言自身的特性上。
清晰语法的同时注重于可读性。在编写代码的时候,你所创造的代码的逻辑“块”,就是一些为了相关联目标而共同工作的代码。在许多编程语言里,这些块用特殊字符所标记(或限定)。它们或许被 `{}` 或者其他字符所包住。块分割字符和你写代码的能力,这两者不管怎么结合起来都会降低可读性。让我们来看一个例子。
这有个被称为 `fun` 的简短函数。它要求输入一个数字,`x` 就是它的输入。如果 `x` 等于 `0`,它将会运行另一个被称为`no_fun` 的函数(这函数做了些很无趣的事情)。新函数不需要输入。反之,简短函数将会运行一个使用输入 `x` 的名为 `big_fun` 的函数。
这个函数用 [C 语言](https://en.wikipedia.org/wiki/C_(programming_language) 将会是这样写的:
```
void fun(int x)
{
if (x == 0) {
no_fun();
} else {
big_fun(x);
}
}
```
或者,像是这样:
```
void fun(int x) { if (x == 0) {no_fun(); } else {big_fun(x); }}
```
功能上两者等价,而且都能运行。`{}` 和 `;` 告诉我们哪里是代码块的不同部分。然而,第一个对于人们来说*明显*更容易阅读。相比之下完成相同功能的 Python 是这样的:
```
def fun(x):
if x == 0:
no_fun()
else:
big_fun(x)
```
在这里,只有一个选择。如果代码不是这样排列的,它将无法工作。如果你编写了可以工作的代码,你就有了可阅读的代码。同样也留意一下两者在语法上的差异。不同的是 `def` ,在 Python 代码中这个词是英语单词,大家都很熟悉这单词的含义(LCTT 译注:def 是 definition 的缩写,定义的意思)。在 C 语言的例子中 `void` 和 `int` 就没有那么直观。
Python 也有个优秀的生态系统。这有两层意思,第一,你有一个使用该语言的庞大、活跃的社区,当你需要帮助指导的时候,你能向他们求助。第二,它有大量早已存在的库,库是指完成特定功能的代码集合。从高级数学运算、图形到计算机视觉,甚至是你能想象到的任何事情。
Python 作为你第一门编程语言有两个缺点。第一是它有时候安装起来很复杂,特别是在运行着 Windows 的电脑上。(如果你有一台 Mac 或者 Linux 的电脑,Python 默认已经安装好了。)虽然这问题不是不能克服,而且情况总在改善,但是这对于一些人来说还是个阻碍。第二个缺点是,对于那些明确想要建设网站的人来讲,虽然有很多用 Python 写的项目(例如 [Django](https://www.djangoproject.com/) 和[Flask](http://flask.pocoo.org/) ),但是编写运行在浏览器上的 Python 代码却没有什么好的选择。它主要是后台或者服务器端语言。
### JavaScript
如果你知道你学习编程的主要原因是建设网站的话,[JavaScript](https://en.wikipedia.org/wiki/JavaScript) 或许是你的最佳选择。 JavaScript 是关于网页的编程语言。除了是网页的默认编程语言之外, JavaScript 作为初学的语言有几点优点。
第一,无须安装任何东西。你可以打开文本编辑器(例如 Windows 上的记事本,但不是一个文字处理软件,例如 Microsoft Word)然后开始输入 JavaScript 。代码将在你的浏览器中运行。最顶尖的浏览器内置了JavaScript 引擎,所以你的代码将可以运行在几乎所有的电脑和很多的移动设备上。事实上,能马上在浏览器中运行代码为编程人员提供了一个非常*快*的反馈,这对于新手来说是很好的。你能尝试一些事情然后很快地看到结果。
开始 JavaScript 是作为前端语言的,不过一个名为 [Node.js](https://nodejs.org/en/) 的环境能让你编写运行在浏览器或者服务器上的代码。现在 JavaScript 能当作前端或者后台语言使用。这增加了它的使用人数。JavaScript 也有大量能提供除核心功能外的额外功能的包,这使得它能当作一门通用语言来使用。JavaScript 不只是网页开发语言,就像 Python 那样,它也有个充满生气的、活跃的生态系统。
尽管有这些优点,但是 JavaScript 对于新手来说并非十全十美。[JavaScript 的语法](https://en.wikipedia.org/wiki/JavaScript_syntax#Basics)并不像 Python 那样清晰,也不怎么像英语。更像是之前例子里提到的 C 语言。它并不是把可读性当作主要的设计特性。
### 做出选择
选 Python 或者 JavaScript 作为入门语言都没有问题。关键是你打算做什么。为什么你要学习编程?你的回答很大程度上影响你的决定。如果你是想为开源做贡献,你将会找到*大量*用这两门语言编写的项目。另外,许多主要不是用 JavaScript 写的项目仍使用 JavaScript 用作前端组件。当你做决定时,别忘了你本地的社区。你有在使用其中一门语言的朋友或者同事吗?对于一个新手来说,有实时的帮助是非常重要的。
祝好运,开心编程。
---
作者简介:
Kojo Idrissa - 我是一个新晋的软件开发者(1 年),从会计和大学教学转型而来。自从有开源软件以来,我就是它的一个粉丝。但是在我之前的事业中并不需要做很多的编程工作。技术上,我专注于 Python ,自动化测试和学习 Django 。我希望我能尽快地学更多的 JavaScript 。话题上,我专注于帮助刚开始学习编程或想参与为开源项目做贡献的人们。我也关注在技术领域的包容文化。
---
via: <https://opensource.com/article/17/1/choosing-your-first-programming-language>
作者:[Kojo Idrissa](https://opensource.com/users/transitionkojo) 译者:[ypingcn](https://github.com/ypingcn) 校对:[bestony](https://github.com/bestony)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 200 | OK | The reasons for learning to program are as a varied as the people who want to learn. You might have a program you want to make, or maybe you just want to jump in. So, before choosing your first programming language, ask yourself: Where do you want that program to run? What do you want that program to do?
Your reasons for learning to code should inform your choice of a first language.
*In this article, I use "code," "program," and "develop" interchangeably as verbs, while "code," "program," "application," and "app" interchangeably as nouns. This is to reflect language usage you may hear.*
## Know your device
Where your programs will run is a defining factor in your choice of language.
Desktop applications are the traditional software programs that run on a desktop or laptop computer. For these you'll be writing code that only runs on a single computer at a time. Mobile applications, known as apps, run on portable communications devices using iOS, Android, or other operating systems. Web applications are websites that function like applications.
Web development is often broken into two subcategories, based on the web's client-server architecture:
-
Front-end programming, which is writing code that runs in the web browser itself. This is the part that faces the user, or the "front end" of the program. It's sometimes called "client-side" programming, because the web browser is the client half of the web's client-server architecture. The web browser runs on your local computer or device.
-
Back-end programming, which is also known as "server-side" programming, the code written runs on a server, which is a computer you don't have physical access to.
## What to create
Programming is a broad discipline and can be used in a variety of fields. Common examples include:
- data science,
- web development,
- game development, and
- work automation of various types.
Now that we've looked at why and where you want to program, let's look at two great languages for beginners.
## Python
[Python](https://www.python.org/about/) is one of the most popular languages for first-time programmers, and that is not by accident. Python is a general-purpose language. This means it can be used for a wide range of programming tasks. There's almost *nothing* you can't do with Python. This lets a wide range of beginners make practical use of the language. Additionally, Python has two key design features that make it great for new programmers: a clear, English-like [syntax](https://en.wikipedia.org/wiki/Python_syntax_and_semantics) and an emphasis on code [readability](https://en.wikipedia.org/wiki/Python_syntax_and_semantics#Indentation).
A language's syntax is essentially what you type to make the language perform. This can include words, special characters (like `;`
, `$`
, `%`
, or `{}`
), white space, or any combination. Python uses English for as much of this as possible, unlike other languages, which often use punctuation or special characters. As a result, Python reads much more like a natural, human language. This helps new programmers focus on solving problems, and they spend less time struggling with the specifics of the language itself.
Combined with that clear syntax is a focus on readability. When writing code, you'll create logical "blocks" of code, sections of code that work together for some related purpose. In many languages, those blocks are marked (or delimited) by special characters. They may be enclosed in `{}`
or some other character. The combination of block-delimiting characters and your ability to write your code in almost any fashion can decrease readability. Let's look at an example.
Here's a small function, called "fun," which takes a number, `x`
as its input. If `x`
equals **0**, it runs another function called `no_fun`
(which does something that's no fun). That function takes no input. Otherwise, it runs the function `big_fun`
, using the same input, `x`
.
This function defined in the ["C" language](https://en.wikipedia.org/wiki/C_(programming_language) could be written like this:
```
``````
void fun(int x)
{
if (x == 0) {
no_fun();
} else {
big_fun(x);
}
}
```
or, like this:
```
````void fun(int x) { if (x == 0) {no_fun(); } else {big_fun(x); }}`
Both are functionally equivalent and both will run. The `{}`
and `;`
tell us where different parts of the block are; however, one is *clearly* more readable to a human. Contrast that with the same function in Python:
```
``````
def fun(x):
if x == 0:
no_fun()
else:
big_fun(x)
```
In this case, there's only one option. If the code isn't structured this way, it won't work, so if you have code that works, you have code that's readable. Also, notice the difference in syntax. Other than `def`
, the words in the Python code are English and would be clear to a broad audience. In the C language example `void`
and `int`
are less intuitive.
Python also has an excellent ecosystem. This means two things. First, you have a large, active community of people using the language you can turn to when you need help and guidance. Second, it has a large number of preexisiting libraries, which are chunks of code that perform special functions. These range from advanced mathematical processing to graphics to computer vision to almost anything you can imagine.
Python has two drawbacks to it being your first language. The first is that it can sometimes be tricky to install, especially on computers running Windows. (If you have a Mac or a Linux computer, Python is already installed.) Although this issue isn't insurmountable, and the situation is improving all the time, it can be a deterrent for some people. The second drawback is for people who specifically want to build websites. While there are projects written in Python (like [Django](https://www.djangoproject.com/) and [Flask](http://flask.pocoo.org/)) that let you build websites, there aren't many options for writing Python that will run in a web browser. It is primarily a back-end or server-side language.
## JavaScript
If you know your primary reason for learning to program is to build websites, [JavaScript](https://en.wikipedia.org/wiki/JavaScript) may be the best choice for you. JavaScript is *the* language of the web. Besides being the default language of the web, JavaScript has a few advantages as a beginner language.
First, there's nothing to install. You can open any text editor (like Notepad on Windows, but not a word processor like Microsoft Word) and start typing JavaScript. The code will run in your web browser. Most modern web browsers have a JavaScript engine built in, so your code will run on almost any computer and a lot of mobile devices. The fact that you can run your code immediately in a web browser provides a *very* fast feedback loop, which is good for new coders. You can try something and see the results very quickly.
While JavaScript started life as a front-end language, an environment called [Node.js](https://nodejs.org/en/) lets you write code that runs in a web browser or on a server. Now JavaScript can be used as a front-end or back-end language. This has led to an increase in its popularity. JavaScript also has a huge number of packages that provide added functionality to the core language, allowing it to be used as a general-purpose language, and not just as the language of web development. Like Python, JavaScript has a vibrant, active ecosystem.
Despite these strengths, JavaScript is not without its drawbacks for new programmers. The [syntax of JavaScript](https://en.wikipedia.org/wiki/JavaScript_syntax#Basics) is not as clear or English-like as Python. It's much more like the C example above. It also doesn't have readability as a key design principle.
## Making a choice
It's hard to go wrong with either Python or JavaScript as your first language. The key factor is what you intend to do. Why are you learning to code? Your answer should influence your decision most heavily. If you're looking to make contributions to open source, you will find a *huge* number of projects written in both languages. In addition, many projects that aren't primarily written in JavaScript still make use of it for their front-end component. As you're making a choice, don't forget about your local community. Do you have friends or co-workers who use either of these languages? For a new coder, having live support is very important.
Good luck and happy coding.
## 5 Comments |
8,380 | 如何在 Linux 中列出通过 RPM 或者 DEB 包安装的文件 | http://www.tecmint.com/list-files-installed-from-rpm-deb-package-in-linux/ | 2017-04-06T17:34:26 | [
"yum",
"rpm",
"dpkg"
] | https://linux.cn/article-8380-1.html | 你是否想要了解安装包中各个文件在 Linux 系统中安装(位于)的位置?我们将在本文介绍如何列出文件的来源,或存在于某个特定包或者一组软件包中的文件。

这篇文章可以帮你轻松地找到重要的软件包文件,如配置文件、帮助文档等。我们来看看找出文件在哪个包中或者从哪个包中安装的几个方法:
### 如何列出 Linux 中全部已安装软件包的文件
你可以使用 [repoquery 命令](http://www.tecmint.com/list-installed-packages-in-rhel-centos-fedora/),它是 [yum-utils](http://www.tecmint.com/linux-yum-package-management-with-yum-utils/) 的一部分,用来列出给定的软件包在 CentOS/RHEL 系统上安装的文件。
要安装并使用 yum-utils,运行下面的命令:
```
# yum update
# yum install yum-utils
```
现在你可以列出一个已安装包的文件了,比如 httpd 服务器 (注意包名是大小写敏感的)。`--installed` 表示已经安装的包,`-l` 列出所有的文件:
```
# repoquery --installed -l httpd
# dnf repoquery --installed -l httpd [On Fedora 22+ versions]
```

*repoquery 列出 httpd 安装的文件*
重要:在 Fedora 22 以上的版本中,`repoquery` 命令在基于 RPM 的发行版中已经与 [dnf 包管理器](http://www.tecmint.com/dnf-commands-for-fedora-rpm-package-management/)整合,可以用上面的方法列出安装的文件。
除此之外,你也可以使用下面的 [rpm 命令](http://www.tecmint.com/20-practical-examples-of-rpm-commands-in-linux/)列出 .rpm 包中或已经安装的 .rpm 包的文件,下面的 `-q` 和 `-l` 表示列出其后跟着的包中的文件:
```
# rpm -ql httpd
```

*rpm 查询已安装程序的安装包*
另外一个有用的建议是使用 `-p` 在安装之前列出 `.rpm` 中的文件。
```
# rpm -qlp telnet-server-1.2-137.1.i586.rpm
```
在 Debian/Ubuntu 发行版中,你可以使用 [dpkg 命令](http://www.tecmint.com/dpkg-command-examples/)带上 `-L` 标志在 Debian 系统或其衍生版本中列出给定 .deb 包的安装的文件。
在这个例子中,我们会列出 apache2 Web 服务器安装的文件:
```
$ dpkg -L apache2
```

*dpkg 列出安装的包*
不要忘记查看其它有关在 Linux 中软件包管理的文章。
1. [20 个有用的 yum 包管理命令](http://www.tecmint.com/20-linux-yum-yellowdog-updater-modified-commands-for-package-mangement/)
2. [20 个有用的 rpm 包管理命令](http://www.tecmint.com/20-practical-examples-of-rpm-commands-in-linux/)
3. [15 个 Ubuntu 中有用的 apt 包管理命令](http://www.tecmint.com/apt-advanced-package-command-examples-in-ubuntu/)
4. [15 个 Ubuntu 中有用的 dpkg命令](http://www.tecmint.com/dpkg-command-examples/)
5. [5 个最佳的对 Linux 新手的包管理器](http://www.tecmint.com/linux-package-managers/)
就是这样了!在本文中,我们向你展示了如何在 Linux 中列出/找到给定的软件包或软件包组安装的所有文件。在下面的评论栏中分享你的想法。
---
作者简介:
Aaron Kili 是 Linux 和 F.O.S.S 的爱好者,目前任 TecMint 的作者,志向是一名 Linux 系统管理员、web 开发者。他喜欢用电脑工作,并热衷于分享知识。
---
via: <http://www.tecmint.com/list-files-installed-from-rpm-deb-package-in-linux/>
作者:[Aaron Kili](http://www.tecmint.com/author/aaronkili/) 译者:[geekpi](https://github.com/geekpi) 校对:[ezio](https://github.com/oska874)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
8,381 | 连接到 Linux 服务器时首先要运行的 5 个命令 | https://www.linux.com/blog/first-5-commands-when-i-connect-linux-server | 2017-04-07T10:17:00 | [
"服务器",
"命令"
] | https://linux.cn/article-8381-1.html | 
作为一个系统管理员/SRE 工作 5 年后,我知道当我连接到一台 Linux 服务器时我首先应该做什么。这里有一系列关于服务器你必须了解的信息,以便你可以(在大部分时间里)更好的调试该服务器。
### 连上 Linux 服务器的第一分钟
这些命令对于有经验的软件工程师来说都非常熟悉,但我意识到对于一个刚开始接触 Linux 系统的初学者来说,例如我在 [Holberton 学校](https://www.holbertonschool.com/)任教的学生,却并非如此。这也是我为什么决定分享当我连上 Linux 服务器首先要运行的前 5 个命令的原因。
```
w
history
top
df
netstat
```
这 5 个命令在任何一个 Linux 发行版中都有,因此不需要额外的安装步骤你就可以直接使用它们。
### w:
```
[ubuntu@ip-172-31-48-251 ~]$ w
23:40:25 up 273 days, 20:52, 2 users, load average: 0.33, 0.14, 0.12
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
ubuntu pts/0 104-7-14-91.ligh 23:39 0.00s 0.02s 0.00s w
root pts/1 104-7-14-91.ligh 23:40 5.00s 0.01s 0.03s sshd: root [priv]
[ubuntu@ip-172-31-48-251 ~]$
```
这里列出了很多有用的信息。首先,你可以看到服务器运行时间 [uptime](http://whatis.techtarget.com/definition/uptime-and-downtime),也就是服务器持续运行的时间。然后你可以看到有哪些用户连接到了服务器,当你要确认你没有影响你同事工作的时候这非常有用。最后 [load average](http://blog.scoutapp.com/articles/2009/07/31/understanding-load-averages) 能很好的向你展示服务器的健康状态。
### history
```
[ubuntu@ip-172-31-48-251 ~]$ history
1 cd /var/app/current/log/
2 ls -al
3 tail -n 3000 production.log
4 service apache2 status
5 cat ../../app/services/discourse_service.rb
```
`history` 能告诉你当前连接的用户之前运行了什么命令。你可以看到很多关于这台机器之前在执行什么类型的任务、可能出现了什么错误、可以从哪里开始调试工作等信息。
### top
```
top - 23:47:54 up 273 days, 21:00, 2 users, load average: 0.02, 0.07, 0.10
Tasks: 79 total, 2 running, 77 sleeping, 0 stopped, 0 zombie
Cpu(s): 1.0%us, 0.0%sy, 0.0%ni, 98.7%id, 0.0%wa, 0.0%hi, 0.0%si, 0.3%st
Mem: 3842624k total, 3128036k used, 714588k free, 148860k buffers
Swap: 0k total, 0k used, 0k free, 1052320k cached
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
21095 root 20 0 513m 21m 4980 S 1.0 0.6 1237:05 python
1380 healthd 20 0 669m 36m 5712 S 0.3 1.0 265:43.82 ruby
19703 dd-agent 20 0 142m 25m 4912 S 0.3 0.7 11:32.32 python
1 root 20 0 19596 1628 1284 S 0.0 0.0 0:10.64 init
2 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kthreadd
3 root 20 0 0 0 0 S 0.0 0.0 27:31.42 ksoftirqd/0
4 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kworker/0:0
5 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kworker/0:0H
7 root 20 0 0 0 0 S 0.0 0.0 42:51.60 rcu_sched
8 root 20 0 0 0 0 S 0.0 0.0 0:00.00 rcu_bh
```
你想知道的下一个信息:服务器当前在执行什么工作。使用 `top` 命令你可以看到所有正在执行的进程,然后可以按照 CPU、内存使用进行排序,并找到占用资源的进程。
### df
```
[ubuntu@ip-172-31-48-251 ~]$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/xvda1 7.8G 4.5G 3.3G 58% /
devtmpfs 1.9G 12K 1.9G 1% /dev
tmpfs 1.9G 0 1.9G 0% /dev/shm
```
你服务器正常工作需要的下一个重要资源就是磁盘空间。磁盘空间消耗完是非常典型的问题。
### netstat
```
[ubuntu@ip-172-31-48-251 ec2-user]# netstat -lp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 *:http *:* LISTEN 1637/nginx
tcp 0 0 *:ssh *:* LISTEN 1209/sshd
tcp 0 0 localhost:smtp *:* LISTEN 1241/sendmail
tcp 0 0 localhost:17123 *:* LISTEN 19703/python
tcp 0 0 localhost:22221 *:* LISTEN 1380/puma 2.11.1 (t
tcp 0 0 *:4242 *:* LISTEN 18904/jsvc.exec
tcp 0 0 *:ssh *:* LISTEN 1209/sshd
```
计算机已成为我们世界的重要一部分,因为它们有通过网络进行相互交流的能力。知道你的服务器正在监听什么端口、IP地址是什么、以及哪些进程在使用它们,这对于你来说都非常重要。
显然这个列表会随着你的目的和你已有的信息而变化。例如,当你需要调试性能的时候,[Netflix 就有一个自定义的列表](http://techblog.netflix.com/2015/11/linux-performance-analysis-in-60s.html)。你有任何不在我 Top 5 中的有用命令吗?在评论部分和我们一起分享吧!
---
via: <https://www.linux.com/blog/first-5-commands-when-i-connect-linux-server>
作者:[SYLVAIN KALACHE](https://www.linux.com/users/sylvainkalache) 译者:[ictlyh](https://github.com/ictlyh) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
8,382 | 用 Winetricks 配置 WINE | https://linuxconfig.org/configuring-wine-with-winetricks | 2017-04-07T10:38:00 | [
"Wine",
"winetricks",
"winecfg"
] | https://linux.cn/article-8382-1.html | ### 简介
如果 `winecfg` (WINE 的配置工具)是一把螺丝刀,那么 `winetricks` 就是一个钻床。它们各有特长,但是 `winetricks` 真的是一个强大的多的工具。实际上,它甚至可以启动 `winecfg`。

`winecfg` 让你可以改变 WINE 本身的设置,而 `winetricks` 则可以让你改造实际的 Windows 层,它可以让你安装 Windows 重要的系统组件,比如 .dll 文件和系统字体,还可以允许你修改 Windows 注册表的信息。它还有任务管理器、卸载工具和文件浏览器。
尽管 `winetricks` 可以做以上这些工作,但是大部分时间我们用到的功能也就是管理 `dll` 文件和 Windows 组件。
### 安装
和 `winecfg` 不同,`winetricks` 不是集成在 WINE 中的。这样也没什么问题,由于它实际上只是个脚本文件,你可以在各种发行版上很轻松地下载和使用它。现在,许多发行版把 `winetricks` 打包。只要你喜欢,你也可以下载打包后的版本。不过,有些包可能会比较老旧,所以本指南将使用脚本,毕竟脚本通用且更新及时。默认情况下,它的图形界面有些丑,所以你要是想个性化界面,最好通过你的发行版的包管理器安装一个 `zenity`。
现在假定你想在你的 `/home` 目录下配置 `winetricks`。 `cd` 到此,然后 `wget` 这个脚本。
```
$ cd ~
$ wget https://raw.githubusercontent.com/Winetricks/winetricks/master/src/winetricks
```
然后,给这个脚本可执行权限。
```
$ chmod+x winetricks
```
`winetricks` 可以通过命令行运行,在行末指定要安装的东西。但是大部分情况下,你都不知道 .dll 文件或者是你想安装字体确切的名字,那么,这时候最好利用图形界面程序。启动这个程序和其他程序没什么不同,就是在末尾什么都别输入就行了。
```
$ ~/winetricks
```

当窗口第一次打开时候,将会给你一个有 <ruby> “查看帮助” <rt> View help </rt></ruby> 和 <ruby> “安装应用” <rt> Install an application </rt></ruby> 选项的菜单。一般情况下,我们选择 <ruby> “选择默认的 wineprefix” <rt> Select the default wineprefix </rt></ruby>,这将是你主要使用的选项。其他的也能用,但是不推荐使用。接下来,单击 “OK”,你就会进入到 WINE prefix 的配置菜单,你可以在这完成所有你要使用 `winetricks` 完成的事情。

### 字体

字体一直很重要,一些应用程序没有字体就没法正常的加载。`winetricks` 可以轻松地安装许多常用 Windows 字体.在配置菜单中,选中 <ruby> “安装字体” <rt> Install a font </rt></ruby> 单选按钮,然后点击 “OK” 即可。
然后你就会得到一列字体清单,它们都有着相对应的复选框。你很难确切知道你到底需要什么字体,所以一般按每个应用决定使用什么字体,我们可以先安装一款插件 `corefonts`,它包含了大多数 Windows 系统中应用程序所设定的字体。安装它也十分简单,所以可以试试。
要安装 `corefonts` ,请选择相应的复选框,然后点击 “OK”,你就会看到和在 Windows 下差不多的提示,字体就会被安装了。完成了这个插件的安装,你就会回到先前的菜单界面。接下来就是安装你需要的别的插件,步骤相同。
### .dll 文件和组件

`winetricks` 安装 Windows 下的 .dll 文件和别的组件也十分简单。如果你需要安装的话,在菜单页选择 <ruby> “安装 Windows DLL 或组件” <rt> Install a Windows DLL or component </rt></ruby>,然后点击 “OK”。
窗口就会进入到另一个菜单界面,其中包含可用的 dll 和其他 Windows 组件。在相应的复选框进行选择,点击 “OK”。脚本就会下载你选择的组件,接着通过 Windows 一般的安装进程进行安装。像 Windows 机器上安装那样跟着提示往下走。可能会有报错信息。很多时候,Windows 安装程序会报错,但是你接着会收到来自 `winetricks` 窗口的消息,说明它正在绕过此问题。这很正常。由于组件之间的相互依赖关系,你可能会也可能不会看到成功安装的信息。只要确保安装完成时候,菜单页中你的选项仍旧处于被选中状态就行了。
### 注册表

你不需要常常编辑注册表中 WINE 对应的值,但是对于有些程序确实需要。技术层面来讲,`winetricks` 不向用户提供注册表编辑器,但是要访问编辑器也很容易。在菜单页选中<ruby> “运行注册表编辑” <rt> Run regedit </rt></ruby>,点击 “OK”,你就可以打开一个简单的注册表编辑器。事实上,写入注册表的值有点超出本篇引导文章的范围了,但是我还要多说一句,如果你已经知道你在干什么,增加一个注册表条目不是很难。注册表有点像电子表格,你可以将正确的值填入右面的格子中。这个说的有点过于简单,但是就是这样的。你可以在以下地址精准地找到你需要在 WINE Appdp 所要填入或编辑的东西。 [https://appdb.winehq.org。](https://appdb.winehq.org%E3%80%82)
### 结束语
很明显 `winetricks` 还有许多许多强大的功能,但是本篇指南的目的只是给你一点基础知识,以使用这个强大的工具,使你的程序通过 WINE 运行。WINE Appdb 对每个程序都有相应的设置,将来会越来越丰富。
---
via: <https://linuxconfig.org/configuring-wine-with-winetricks>
作者:Nick Congleton 译者:[Taylor1024](https://github.com/Taylor1024) 校对:[jasminepeng](https://github.com/jasminepeng)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 403 | Forbidden | null |
8,383 | JavaScript 即未来:介绍 14 个 JavaScript 的框架和库 | https://opensource.com/article/16/11/15-javascript-frameworks-libraries | 2017-04-07T21:06:00 | [
"JavaScript"
] | /article-8383-1.html |
>
> JavaScript 即未来趋势所在。
>
>
>
Javascript 得到了众多的技术领导者的拥护和支持,其中一位就是 WordPress 的作者 Matt Mullenweg , 他表示 [WordPress 开发者](http://wesbos.com/learn-javascript/) 应该学习 JavaScript , 这也清晰地向 WordPress 社区传达了 JavaScript 在未来的重要性。 同时,这一观点也被普遍接受。向着更先进的技术靠拢与过渡也同时保证了 WordPress 在未来的挑战中不会落于人后。
JavaScript 同时也是众多站在开源立场的技术中的佼佼者。与现在所流行的观点相反,JavaScript 不是一个工程,而是一个由其核心团队共同制定和维护的开放标准。[ECMAScript](http://stackoverflow.com/questions/5520245/is-javascript-an-open-source-project) , 这是另一个和 JavaScript 相关的名字, 它虽然不是开源的,但它也有一个开放的标准。

当你在浏览 GitHub 的时候你就可以发现 JavaScript 在当今有多么流行了。而且就[仓库的数量](https://github.com/blog/2047-language-trends-on-github) 而言,JavaScript 绝对位于所有的编程语言当中最顶尖的那一层次。 同时,在 Livecoding.tv 上你也能看出 JavaScript 有多么突出,这里的用户发布的关于 JavaScript 的视频的数量比其他的话题多得多。在写这篇文章的时候(2016 年底),Livecoding.tv 上已经有 [45,919 个 用户原创的 JavaScript 视频教程](https://www.livecoding.tv/learn/javascript/) 。
### 热门的开源 JavaScript 框架和库
回归到主题, 庞大的社区是 JavaScript 的一个得天独厚的优势,同时这也推动了 JavaScript 的蓬勃发展。这里有数以百千计的成熟的 JavaScript 框架和库供开发者使用,同时这些最优秀的框架和库都是开源的。对当前的 JavaScript 开发者来说,能够使用这些优秀的框架和库来进行快速开发已经是必须技能了。当今的市场需要快速开发,但是,重复造轮子是没有必要的。不论你是一个 JavaScript 新手还是一个资深的 JavaScript 开发者,使用框架和库都能极大提高你的工作效率。
好了,让我们开始吧!
#### 1. Angular.js
[Angular.js](https://opensource.com/article/16/11/www.angularjs.org) 是目前最热门的 JavaScript 框架之一。它用于开发者构建复杂的 web 应用。Angular.js 背后的思想是它的单页应用 model。同时它 也支持 MVC 架构。在 Angular.js 中 ,开发者可以在前端中使用 JavaScript 代码,并从字面上扩展 HTML 词汇。
Angular.js 自 2009 年出现以来已经有了很大的改进。Angular 1 当前的稳定版本是 1.5.8/1.2.30 。你也可以试一试 Angular 2 ,相对于 Angular 1 来说它有了重大的改进,但这个新版本仍未在全球范围内被普遍使用。
在 Angular.js 中,数据绑定是完成工作的一个重要概念。在用户与接口的交互中,当交互完成,view 就会自动更新,随即新值与 model 交互以确保一切都是同步的。底层的逻辑在 model 中执行完成后,DOM 也会随即更新。
#### 2. Backbone.js
复杂 web 应用并不适用于所有场景。一些较简单的 web 应用框架例如 [Backbone.js](https://opensource.com/article/16/11/www.backbone.js) 就非常适合学习 web app 开发。Backbone.js 是一个简单的框架,可以快速方便地构建简单的 web 应用。和 Angular.js 一样,Backbone.js 也支持 MVC 。Backbone.js 还有一些其它关键特性如路由,RESTful API 支持,适当的状态管理等等。你甚至还可以用 Backbone.js 来构建单页应用。
当前的稳定版本是 1.3.3,可以在 [GitHub](https://github.com/jashkenas/backbone/) 中找到。
#### 3. D3.js
[D3.js](https://opensource.com/article/16/11/www.d3js.org) 是一个优秀的 JavaScript 库,它允许开发者创建具有数据处理功能的富 web 页面。D3.js 使用 SVG、HTML 和 CSS 来实现这一切功能。使用 D3.js ,你可以更轻松地将数据绑定到 DOM 及启用数据驱动事件。使用 D3.js ,你还可以创建高质量的数据驱动的 web 页面来提供一个更易于理解的视觉效果来呈现数据。查看示例 : [LCF 符号哈密顿图](http://christophermanning.org/projects/building-cubic-hamiltonian-graphs-from-lcf-notation) ,由 D3.js 强力驱动。
#### 4. React.js
[React.js](https://facebook.github.io/react/) 是一个使用起来很有趣的 JavaScript 框架。和其它的 JavaScript 框架不同,React.js 志在构建一个高可扩展的前端用户界面。React.js 出现于 2013 年,它采用了 BSD 开源协议。它因其能够开发复杂且漂亮的用户界面所带来的优势而迅速发展壮大。
React.js 背后的核心思想是虚拟 DOM 。虚拟 DOM 在客户端和服务端之间扮演着一个中间人的角色并带来了显著的性能提升。虚拟 DOM 的改变和服务器端 DOM 一样,只需要更新所需的元素,相对于传统的 UI 渲染来说极大提升了渲染速度。
你还可以使用 Recat 来实现 meterial 风格的设计,使你能够开发具有无与伦比的性能的 web 应用。
#### 5. jQuery
[jQuery](http://jquery.com/) 是一个非常流行的 JavaScript 库,它拥有众多特性例如事件处理、动画等。当你在做一个 web 项目的时候,你不会想要把时间浪费在为一些简单的功能写代码上。jQuery 为减少你的工作量提供了一些易于使用的 API 。这些 API 在所有的常见的浏览器中都能够使用。使用 jQuery, 你可以无缝地控制 DOM 以及 Ajax 这样在近几年来拥有大量需求的任务。使用 jQuery,开发者不必担心一些低级的交互,同时可以使他们的 web 应用的开发更加容易与迅速。
jQuery 同时便于分离 HTML 和 JavaScript 代码,使开发者能够编写简洁而跨浏览器兼容的代码。并且使用 jQuery 创建的 web 应用在将来也易于改善和扩展。
#### 6. Ember.js
[Ember.js](http://emberjs.com/) 是一个 Angular.js 和 React.js 的功能混合体。当你在浏览社区的时候你能明显地感受到 Ember.js 的热门程度。Ember.js 的新特性也不断地在添加。它在数据同步方面与 Angular.js 很像。 双向的数据交换可以确保应用的快速性和可扩展性。同时,它还能够帮助开发者创建一些前端元素。
和 React.js 的相似之处在于,Ember.js 提供了同样的服务器端虚拟 DOM 以确保高性能和高可扩展。同时, Ember.js 提倡简化代码,提供了丰富的 API。Ember.js 还有非常优秀的社区。
#### 7. Polymer.js
如果你曾想过创建你自己的 HTML5 元素,那么你可以使用 [Polymer.js](https://www.polymer-project.org/1.0/) 来做这些事。 Polymer 主要集中于通过给 web 开发者提供创建自己的标签的功能来提供扩展功能。例如,你可以创建一个和 HTML5 中的 <video> 类似的具有自己的功能的 <my\_video> 元素。
Polymer 在 2013 年被 Google 引入并以 [三句版 BSD](https://en.wikipedia.org/wiki/BSD_licenses#3-clause) 协议发布。
#### 8. Three.js
[Three.js](https://threejs.org/) 又是另一个 JavaScript 库,主要用于 3D 效果开发。如果你在做游戏开发的动画效果,那么你可以利用 Three.js 的优势。Three.js 在底层中使用 WebGL 使 Three.js 可以轻松地被用于在屏幕上渲染 3D 物体。举一个比较知名的使用 Three.js 的例子就是 HexGLA,这是一个未来派赛车游戏。
#### 9. PhantomJS
使用 JavaScript 工作就意味着和不同的浏览器打交道,同时,当提及浏览器的时候,就不得不讨论资源管理。在 [PhantomJS](https://phantomjs.org/) 中,由于有 Headless WebKit 的支持,所以你可以随时监测你的 web 应用。Headless WebKit 是 Chrome 和 Safari 使用的渲染引擎中的一部分。
这整个过程是自动化的,你所需要做的只是使用这个 API 来构建你的 web 应用。
#### 10. BabylonJS
[BabylonJS](http://www.babylonjs.com/) 与 Three.js 不相伯仲, 提供了创建平滑而强大的 3D web 应用的 JavaScript API。它是开源的,且基于 JavaScript 和 WebGL 。创建一个简单的 3D 物体,比如一个球体是非常简单的,你只需要写短短几行代码。通过这个库提供的 [文档](https://doc.babylonjs.com/),你可以很好地掌握它的内容。 同时 BabylonJS 的主页上也提供了一些优秀的 demo 来当作参考。在其官网上你可以找到这些 Demo。
#### 11. Boba.js
Web 应用总是有一个共通的需求,那就是分析。如果你还在苦于将数据的分析与统计插入到 JavaScript 的 web 应用中,那么你可以试一下 [Boba.js](http://boba.space150.com/)。Boba.js 可以帮助你将分析的数据插入到你的 web 应用中并且支持旧的 ga.js 。你甚至可以把数据指标和 Boba.js 集成在一起,只需要依赖 jQuery 即可。
#### 12. Underscore.js
[Underscore.js](http://underscorejs.org/) 解决了 “当我面对一个空白 HTML 页面并希望即刻开始工作,我需要什么” 这个问题。当你刚开始一个项目,你可能会感到失落或者重复一系列你在之前项目中常做的步骤。 为了简化开启一个项目的过程和给你起个头,Underscore.js 这个 JavaScript 库给你提供了一系列的方法。例如,你可以使用你在之前项目中常用的 Backbone.js 中的 suspender 或者 jQuery 的一些方法。
一些实用的帮助例如 “filter” 和 “invoke the map” 可以给你起个好头,以助于你尽可能快的投入到工作中。 Underscore.js 同时还自带了一个套件来简化你的测试工作。
#### 13. Meteor.js
[Meteor.js](https://www.meteor.com/) 是一个快速构建 JavaScript 应用的框架。它是开源的且它能够用于构建桌面应用、移动应用和 web 应用。Meteor.js 是一个全栈的框架同时允许多平台的端到端开发。 你可以使用 Meteor.js 来实现前端和后端功能,同时它也能密切监视应用的性能。Meteor.js 的社区非常庞大,所以它会有不断的新特性更新或者是 bug 修复。Meteor.js 也是模块化的,同时它能配合一些其它的优秀的 API 使用。
#### 14. Knockout.js
[Knockout.js](http://knockoutjs.com/) 在这些库中可能是最被低估的一个。它是一个基于 MIT 开源协议的开源 JavaScript 框架。作者是 [Steve Sanderson](http://blog.stevensanderson.com/)。它基于 MVVM 模式。
#### 值得注意的是: Node.js
[Node.js](https://nodejs.org/en/) 是一个强有力的 JavaScript 运行时环境。它可以被用于使用真实世界数据来构建快速且可扩展的应用。它既不是一个框架也不是一个库,而是一个基于 Google Chrome 的 V8 引擎的运行时环境。你可以用 Node.js 来创建多元化的 JavaScript 应用,包括单页应用、即时 web 应用等等。从技术层面上来讲,由于它的事件驱动式架构,所以 Node.js 支持异步 I/O 。这种做法使得它成为开发高可扩展应用的一个极好的解决方案的选择。查看 [Node.js](https://www.livecoding.tv/learn/node-js/)在 livecoding.tv 上的视频。
### 总结
JavaScript 是 web 开发中的通用语言。它之所以快速发展不仅仅是因为它所提供的内容,更多的是因为它的庞大的开源社区的支持。以上提到的框架和库对任何一个 JavaScript 开发者来说都是必须知道的。它们都提供了一些途径来探索 JavaScript 和前端开发。上面提及的大部分框架和库频繁地在 Livecoding.tv 上出现,其大部分来自对 JavaScript 及其相关技术感兴趣的软件工程师。
---
via: <https://opensource.com/article/16/11/15-javascript-frameworks-libraries>
作者:[Dr. Michael J. Garbade](https://opensource.com/users/drmjg) 译者:[chenxinlong](https://github.com/chenxinlong) 校对:[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,384 | Samba 系列(六):使用 Rsync 命令同步两个 Samba4 AD DC 之间的 SysVol 目录 | http://www.tecmint.com/samba4-ad-dc-sysvol-replication/ | 2017-04-08T10:32:19 | [
"Samba"
] | https://linux.cn/article-8384-1.html | 
这篇文章讲的是在两个 **Samba4 活动目录域控制器**之间,通过一些强大的 Linux 工具来完成 SysVol 的复制操作,比如 [Rsync 数据同步工具](http://www.tecmint.com/rsync-local-remote-file-synchronization-commands/),[Cron 任务调度进程](http://www.tecmint.com/11-cron-scheduling-task-examples-in-linux/)和 [SSH 协议](http://www.tecmint.com/5-best-practices-to-secure-and-protect-ssh-server/)。
### 需求:
1、[在 Ubuntu 系统上使用 Samba4 来创建活动目录架构](/article-8065-1.html)
2、[在 Linux 命令行下管理 Samba4 AD 架构](/article-8070-1.html)
3、[使用 Windows 10 的 RSAT 工具来管理 Samba4 活动目录架构](/article-8097-1.html)
4、[在 Windows 下管理 Samba4 AD 域管制器 DNS 和组策略](/article-8258-1.html)
5、[将另一台 Ubuntu DC 服务器加入到 Samba4 AD DC 实现双域控主机模式](/article-8358-1.html)
### 第一步:配置 DC 服务器时间同步
1、在两个域控制器之间复制 **sysvol** 目录的内容之前,你得保证这两个服务器时间设置准确且一致。
如果这两个服务器的时间延迟大于 5 分钟,并且时钟也不同步,你将会遇到 AD 账号和域复制的各种问题。
为了解决多个域控制器之间时间漂移的问题,你需要在服务器上执行如下命令来[安装和配置 NTP 服务](http://www.tecmint.com/install-and-configure-ntp-server-client-in-debian/)。
```
# apt-get install ntp
```
2、在 NTP 服务安装完成之后,打开主配置文件,把默认的 pool 值注释(在每行 pool 参数前添加 # ),并且添加新的 pool 值,指向已安装了 **NTP** 服务端的主 **Samba4 AD DC FQDN**,如下所示。
```
# nano /etc/ntp.conf
```
把下面几行添加到 `ntp.conf` 配置文件。
```
pool 0.ubuntu.pool.ntp.org iburst
#pool 1.ubuntu.pool.ntp.org iburst
#pool 2.ubuntu.pool.ntp.org iburst
#pool 3.ubuntu.pool.ntp.org iburst
pool adc1.tecmint.lan
# Use Ubuntu's ntp server as a fallback.
pool ntp.ubuntu.com
```

*Samba4 配置 NTP 服务*
3、先不要关闭该文件,在文件末尾添加如下内容,这是为了让其它客户端能够查询并[与这个 NTP 服务器同步时间](http://www.tecmint.com/how-to-synchronize-time-with-ntp-server-in-ubuntu-linux-mint-xubuntu-debian/),并发出 NTP 签署请求,以防主 DC 离线:
```
restrict source notrap nomodify noquery mssntp
ntpsigndsocket /var/lib/samba/ntp_signd/
```
4、最后,关闭并保存该配置文件,然后重启 NTP 服务以应用更改。等待几分钟后时间同步完成,执行 `ntpq` 命令打印出 **adc1** 时间同步情况。
```
# systemctl restart ntp
# ntpq -p
```

*与 Samba4 AD 同步 NTP 时间*
### 第二步:通过 Rsync 命令来复制第一个 DC 服务器上的 SysVol 目录
默认情况下,**Samba4 AD DC** 不会通过 **DFS-R**(<ruby> 分布式文件系统复制 <rt> Distributed File System Replication </rt></ruby>)或者 **FRS**(<ruby> 文件复制服务 <rt> File Replication Service </rt></ruby>)来复制 SysVol 目录。
这意味着只有在第一个域控制器联机时,<ruby> <strong> 组策略对象 </strong> <rt> Group Policy objects </rt></ruby>才可用。否则组策略设置和登录脚本不会应用到已加入域的 Windosws 机器上。
为了克服这个障碍,以及基本实现 SysVol 目录复制的目的,我们通过执行一个[基于 SSH 的身份认证](http://www.tecmint.com/ssh-passwordless-login-using-ssh-keygen-in-5-easy-steps/)并使用 SSH 加密通道的[Linux 同步命令](http://www.tecmint.com/rsync-local-remote-file-synchronization-commands/)来从第一个域控制器安全地传输 **GPO** 对象到第二个域控制器。
这种方式能够确保 **GPO** 对象在域控制器之间的一致性,但是也有一个很大的缺点。它只能进行单向同步,因为在同步 GPO 目录的时候, **rsync** 命令会从源 DC 服务器传输所有的更改到目标 DC 服务器,
源 DC 服务器上不存在的组策略对象也会从目标 DC 服务器上删除,为了限制并避免任何冲突,所有的 GPO 编辑操作只能在第一个 DC 服务器上执行。
5、要进行 **SysVol** 复制,先到[第一个 AD DC 服务器上生成 SSH 密钥](http://www.tecmint.com/ssh-passwordless-login-using-ssh-keygen-in-5-easy-steps/),然后使用下面的命令把该密钥传输到第二个 DC 服务器。
在生成密钥的过程中不要设置密码,以便在无用户干预的情况下进行传输。
```
# ssh-keygen -t RSA
# ssh-copy-id root@adc2
# ssh adc2
# exit
```

*在 Samba4 DC 服务器上生成 SSH 密钥*
6、 当你确认 root 用户可以从第一个 **DC** 服务器以免密码方式登录到第二个 **DC** 服务器时,执行下面的 `rsync` 命令,加上 `--dry-run` 参数来模拟 SysVol 复制过程。注意把对应的参数值替换成你自己的数据。
```
# rsync --dry-run -XAavz --chmod=775 --delete-after --progress --stats /var/lib/samba/sysvol/ root@adc2:/var/lib/samba/sysvol/
```
7、如果模拟复制过程正常,那么再次执行去掉 `--dry-run` 参数的 `rsync` 命令,来真实的在域控制器之间复制 GPO 对象。
```
# rsync -XAavz --chmod=775 --delete-after --progress --stats /var/lib/samba/sysvol/ root@adc2:/var/lib/samba/sysvol/
```

*Samba4 AD DC SysVol 复制*
8、在 SysVol 复制完成之后,登录到目标域控制器,然后执行下面的命令来列出其中一个 GPO 对象目录的内容。
从第一个 DC 服务器上执行这个命令时,列出的 GPO 对象也要相同。
```
# ls -alh /var/lib/samba/sysvol/your_domain/Policiers/
```

*验证 Samba4 DC SysVol 复制结果是否正常*
9、为了自动完成**组策略**复制的过程(通过网络传输 sysvol 目录),你可以使用 root 账号设置一个任务来执行同步命令,如下所示,设置为每隔 5 分钟执行一次该命令。
```
# crontab -e
```
添加一条每隔 5 分钟运行的同步命令,并把执行结果以及错误信息输出到日志文件 `/var/log/sysvol-replication.log` 。如果执行命令异常,你可以查看该文件来定位问题。
```
*/5 * * * * rsync -XAavz --chmod=775 --delete-after --progress --stats /var/lib/samba/sysvol/ root@adc2:/var/lib/samba/sysvol/ > /var/log/sysvol-replication.log 2>&1
```
10、如果以后 **SysVol ACL** 权限有问题,你可以通过下面的命令来检测和修复这些异常。
```
# samba-tool ntacl sysvolcheck
# samba-tool ntacl sysvolreset
```

*修复 SysVol ACL 权限问题*
11、如果第一个 **Samba4 AD DC** 的 **FSMO** 角色,即“PDC 模拟器”不可用,你可以强制 **Microsoft Windows** 系统上的**组策略管理控制台**只连接到第二个域控制器,通过选择更改域控制器选项和手动选择目标机器,如下图所示。

*更改 Samba4 域控制器*

*选择 Samba4 域控制器*
当你从**组策略管理控制台**连接到第二个 **DC** 服务器时,你应该避免对**组策略**做任何更改。否则,当第一个 **DC** 服务器恢复正常后, **rsync 命令**将会删除在第二个 DC 服务器上所做的更改。
---
作者简介:
Matei Cezar -- 我是一个电脑迷,开源软件和 Linux 系统爱好者,有超过 4 年的 Linux 桌面、服务器版本系统和 bash 编程经验。
---
via: <http://www.tecmint.com/samba4-ad-dc-sysvol-replication/>
作者:[Matei Cezar](http://www.tecmint.com/author/cezarmatei/) 译者:[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,387 | Linux 命令行工具使用小贴士及技巧(三) | https://www.howtoforge.com/tutorial/linux-command-line-tips-tricks-part-3-cdpath/ | 2017-04-08T20:12:00 | [
"命令行",
"导航"
] | https://linux.cn/article-8387-1.html | 在这个系列的[第一部分](/article-8335-1.html),我们详细地讨论了 `cd -` 命令,在[第二部分](/article-8371-1.html),我们深入探究了 `pushd` 和 `popd` 两个命令,以及它们使用的场景。

继续对命令行的讨论,在这篇教程中,我们将会通过简单易懂的实例来讨论 `CDPATH` 这个环境变量。我们也会讨论关于此变量的一些进阶细节。
*在这之前,先声明一下此教程中的所有实例都已经在 Ubuntu 14.04 和 4.3.11(1) 版本的 Bash 下测试过。*
### 环境变量 CDPATH
即使你的命令行所有操作都在特定的目录下 - 例如你的主目录,然而在你切换目录时也不得不提供绝对路径。比如,考虑我现在的情况,就是在 `/home/himanshu/Downloads` 目录下:
```
$ pwd
/home/himanshu/Downloads
```
现在要求切换至 `/home/himanshu/Desktop` 目录,我一般会这样做:
```
cd /home/himanshu/Desktop/
```
或者
```
cd ~/Desktop/
```
或者
```
cd ../Desktop/
```
能不能只是运行以下命令就能简单地实现呢:
```
cd Desktop
```
是的,这完全有可能。这就是环境变量 `CDPATH` 出现的时候了。你可使用这个变量来为 `cd` 命令定义基础目录。
如果你尝试打印它的值,你会看见这个环境变量默认是空值的:
```
$ echo $CDPATH
```
现在 ,考虑到上面提到的场景,我们使用这个环境变量,将 `/home/himanshu` 作为 `cd` 命令的基础目录来使用。
最简单的做法这样:
```
export CDPATH=/home/himanshu
```
现在,我能做到之前所不能做到的事了 - 当前工作目录在 `/home/himanshu/Downloads` 目录里时,成功地运行了 `cd Desktop` 命令。
```
$ pwd
/home/himanshu/Downloads
$ cd Desktop/
/home/himanshu/Desktop
$
```
这表明了我可以使用 `cd` 命令来到达 `/home/himanshu` 下的任意一个目录,而不需要在 `cd` 命令中显式地指定 `/home/himanshu` 或者 `~`,又或者是 `../` (或者多个 `../`)。
### 要点
现在你应该知道了怎样利用环境变量 `CDPATH` 在 `/home/himanshu/Downloads` 和 `/home/himanshu/Desktop` 之间轻松切换。现在,考虑以下这种情况, 在 `/home/himanshu/Desktop` 目录里包含一个名字叫做 `Downloads` 的子目录,这是将要切换到的目录。
但突然你会意识到 `cd Downloads` 会切换到 `/home/himanshu/Downloads`。所以,为了确保这不会发生,你可以这样做:
```
cd ./Downloads
```
虽然上述命令本身没有问题,但你还是需要耗费点额外的精力(虽然很小),尤其是每次这种情况发生时你都不得不这样做。所以,有一个更加优雅的解决方案来处理,就是以如下方式来设定 `CDPATH` 环境变量。
```
export CDPATH=".:/home/himanshu"
```
它的意思是告诉 `cd` 命令先在当前的工作目录查找该目录,然后再尝试搜寻 `/home/himanshu` 目录。当然, `cd` 命令是否以这样的方式运行,完全取决于你的偏好和要求 - 讨论这一点的目的是为了让你知道这种情况可能会发生。
就如你现在所知道的,一旦环境变量 `CDPATH` 被设置,它的值 - 或者它所包含的路径集合 - 就是系统中 `cd` 命令搜索目录的地方 ( 当然除了使用绝对路径的场景 )。所以,完全取决于你来确保该命令行为的一致性。
继续说,如果一个 bash 脚本以相对路径使用 `cd` 命令,最好还是先清除或者重置环境变量 `CDPATH`,除非你觉得遇上不可预测的麻烦也无所谓。还有一个可选的方法,比起在终端使用 `export` 命令来设置 `CDPATH`,你可以在测试完当前的 shell 是交互式还是非交互式之后,再在你的 `.bashrc` 文件里设置环境变量,这样可以确保你对环境变量的改动只对交互式 shell 生效。
环境变量中,路径出现的顺序同样也是很重要。举个例子,如果当前目录是在 `/home/himanshu` 目录之前列出来,`cd` 命令就会先搜索当前的工作目录然后才会搜索 `/home/himanshu` 目录。然而,如果该值为 `/home/himanshu:.`,搜索就首先从 `/home/himanshu` 开始,然后到当前目录。不用说,这会影响 `cd` 命令的行为,并且不注意路径的顺序可能会导致一些麻烦。
要牢记在心的是,环境变量 `CDPATH`,就像其名字表达的,只对 `cd` 命令有作用。意味着在 `/home/himanshu/Downloads` 目录里面时,你能运行 `cd Desktop` 命令来切换到 `/home/himanshu/Desktop` 目录,但你不能使用 `ls`。以下是一个例子:
```
$ pwd
/home/himanshu/Downloads
$ ls Desktop
ls: cannot access Desktop: No such file or directory
$
```
然而,这还是有简单的变通处理的。例如,我们可以用以下不怎么费力的方式来达到目的:
```
$ cd Desktop/;ls
/home/himanshu/Desktop
backup backup~ Downloads gdb.html outline~ outline.txt outline.txt~
```
不过,不是每种情况就能变通处理的。
另一个重点是:就像你可能已经观察到的,每次你使用 `CDPATH` 环境变量集来运行 `cd` 命令时,该命令都会在输出里显示你切换到的目录的完整路径。不用说,不是所有人都想在每次运行 `cd` 命令时看到这些信息。
为了确保该输出被制止,你可以使用以下命令:
```
alias cd='>/dev/null cd'
```
如果 `cd` 命令运行成功,上述命令不会输出任何东西,如果失败,则允许产生错误信息。
最后,假如你遇到设置 `CDPATH` 环境变量后,不能使用 shell 的 tab 自动补全功能的问题,可以尝试安装并启用 bash 自动补全(bash-completion)。更多请参考 [这里](http://bash-completion.alioth.debian.org/)。
### 总结
`CDPATH` 环境变量时一把双刃剑,如果没有掌握完善的知识和随意使用,可能会令你陷入困境,并花费你大量宝贵时间去解决问题。当然,这不代表你不应该去试一下;只需要了解一下所有的可用选项,如果你得出结论,使用 `CDPATH` 会带来很大的帮助,就继续使用它吧。
你已经能够熟练地使用 `CDPATH` 了吗?你有更多的贴士要分享?请在评论区里发表一下你的想法吧。
(高清版题图:<http://anguerde.com/TTF-222621-archlinux.html> )
---
via: <https://www.howtoforge.com/tutorial/linux-command-line-tips-tricks-part-3-cdpath/>
作者:[Ansh](https://www.howtoforge.com/tutorial/linux-command-line-tips-tricks-part-3-cdpath/) 译者:[HaitaoBio](https://github.com/HaitaoBio) 校对:[jasminepeng](https://github.com/jasminepeng)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 200 | OK | # Linux command line navigation tips/tricks 3 - the CDPATH environment variable
In the first part of this series, we discussed the **cd -** command in detail, and the in the second part, we took an in-depth look into the **pushd** and **popd** commands as well as the scenarios where-in they come in handy.
Continuing with our discussion on the command line navigation aspects, in this tutorial, we'll discuss the **CDPATH** environment variable through easy-to-understand examples. We'll also discuss some advanced details related to this variable.
## The CDPATH environment variable
Even if your command line work involves performing all operations under a particular directory - say your home directory - then also you have to provide absolute paths while switching directories. For example, consider a situation where-in I am in */home/himanshu/Downloads* directory:
$ pwd
/home/himanshu/Downloads
And the requirement is to switch to the */home/himanshu/Desktop* directory. To do this, usually, I'll have to either run:
cd /home/himanshu/Desktop/
or
cd ~/Desktop/
or
cd ../Desktop/
Wouldn't it be easy if I could just run the following command:
cd Desktop
Yes, that's possible. And this is where the CDPATH environment variable comes in.You can use this variable to define the base directory for the **cd** command.
If you try printing its value, you'll see that this env variable is empty by default:
$ echo $CDPATH
$
Now, considering the case we've been discussing so far, let's use this environment variable to define */home/himanshu* as the base directory for the [cd command](https://www.howtoforge.com/linux-cd-command/).
The easiest way to do this is:
export CDPATH=/home/himanshu
And now, I can do what I wasn't able to do earlier - from within the */home/himanshu/Downloads* directory, run the *cd Desktop* command successfully.
$ pwd
/home/himanshu/Downloads
$cd Desktop//home/himanshu/Desktop
$
This means that I can now do a cd to any directory under */home/himanshu* without explicitly specifying */home/himanshu* or *~* or *../* (or multiple *../*)in the cd command.
## Points to keep in mind
So you now know how we used the CDPATH environment variable to easily switch to/from */home/himanshu/Downloads* from/to */home/himanshu/Desktop*. Now, consider a situation where-in the */home/himanshu/Desktop* directory contains a subdirectory named *Downloads*, and it's the latter where you intend to switch.
But suddenly you realize that doing a *cd Desktop* will take you to */home/himanshu/Desktop*. So, to make sure that doesn't happen, you do:
cd ./Downloads
While there's no problem in the aforementioned command per se, that's an extra effort on your part (howsoever little it may be), especially considering that you'll have to do this each time such a situation arises. A more elegant solution to this problem can be to originally set the CDPATH variable in the following way:
export CDPATH=".:/home/himanshu"
This means you're telling the cd command to first look for the directory in the current working directory, and then try searching the */home/himanshu* directory. Of course, whether or not you want the cd command to behave this way depends entirely on your preference or requirement - my idea behind discussing this point was to let you know that this kind of situation may arise.
As you would have understood by now, once the CDPATH env variable is set, it's value - or the set of paths it contains - are the only places on the system where the cd command searches for directories (except of course the scenarios where-in you use absolute paths). So, it's entirely up to you to make sure that the behavior of the command remains consistent.
Moving on, if there's a bash script that uses the cd command with relative paths, then it's better to clear or unset the CDPATH environment variable first, unless you are ok with getting trapped into unforeseen problems. Alternatively, rather than using the *export* command on the terminal to set CDPATH, you can set the environment variable in your `.bashrc`
file after testing for interactive/non-interactive shells to make sure that the change you're trying to make is only reflected in interactive shells.
The order in which paths appear in the environment variable's value is also important. For example, if the current directory is listed before */home/himanshu*, then the cd command will first search for a directory in the present working directory and then move on to */home/himanshu*. However, if the value is *"/home/himanshu:."* then the first search will be made in */home/himanshu* and after that the current directory. Needless to say, this will effect what the cd command does and may cause problems if you aren't aware of the order of paths.
Always keep in mind that the CDPATH environment variable, as the name suggests, works only for the cd command. This means that while inside the */home/himanshu/Downloads* directory, you can run the *cd Desktop* command to switch to */home/himanshu/Desktop* directory, but you can't do an *ls*. Here's an example:
$ pwd
/home/himanshu/Downloads$ ls Desktopls: cannot access Desktop: No such file or directory
$
However, there could be some simple workarounds. For example, we can achieve what we want with minimal effort in the following way:
$cd Desktop/;ls
/home/himanshu/Desktop
backup backup~ Downloads gdb.html outline~ outline.txt outline.txt~
But yeah, there might not be a workaround for every situation.
Another important point: as you might have observed, whenever you use the cd command with the CDPATH environment variable set, the command produces the full path of directory you are switching to in the output. Needless to say, not everybody would want to have this information each time they run the cd command on their machine.
To make sure this output gets suppressed, you can use the following command:
alias cd='>/dev/null cd'
The aforementioned command will mute the output whenever the cd command is successful, but will allow the error messages to be produced whenever the command fails.
Lastly, in case you face a problem where-in after setting the CDPATH environment variable, you can't use the shell's tab completion feature, then you can try installing and enabling bash-completion - more on it [here](http://bash-completion.alioth.debian.org/).
## Conclusion
The CDPATH environment variable is a double-edged sword - if not used with caution and complete knowledge, it may land you in some complex traps that may require a lot of your time precious time to get resolved. Of course, that doesn't mean you should never give it a try; just evaluate all the available options and if you conclude that using CDPATH would be of great help, then do go ahead and use it.
Have you been using CDPATH like a pro? Do you have some more tips to share? Please share your thoughts in the comments below. |
8,388 | 如何安装 Debian 的非 systemd 复刻版本 Devuan Linux | http://www.tecmint.com/installation-of-devuan-linux/ | 2017-04-09T09:07:00 | [
"Devuan",
"Debian"
] | https://linux.cn/article-8388-1.html | [Devuan Linux](https://devuan.org/) 是 Debian 最新的复刻版本,是基于 Debian 的一个被设计为完全去除了 systemd 的版本。
Devuan 宣布于 2014 年底,并经过了一段活跃的开发。最新的发行版本是 beta2,发行代号为: Jessie (没错,和当前 Debian 的稳定版同名)。
当前稳定版的最后发行据说会在 2017 年初。如果想了解关于该项目的更多信息,请访问社区官网:<https://devuan.org/> 。

本文将阐述 Devuan 当前发行版的安装。在 Debian 上可用的大多数软件包在 Devuan 上也是可用的,这有利于用户从 Debian 到 Devuan 的无缝过渡,他们应该更喜欢自由选择自己的初始化系统。
### 系统要求
Devuan 和 Debian 类似,对系统的要求非常低。最大的决定性因素是,用户希望使用什么样的桌面环境。这篇指南假设用户将使用一个“俗气的”桌面环境,建议至少满足下面所示的最低系统要求:
1. 至少 15GB 的硬盘空间;强烈鼓励有更大空间
2. 至少 2GB 的内存空间;鼓励更多
3. 支持 USB 或 CD/DVD 启动
4. 网络连接;安装过程中将会从网上下载文件
### Devuan Linux 安装
正如所有的指南一样,这篇指南假设你有一个 USB 驱动器,可作为安装媒介。注意,USB 驱动器应该有大约 4GB 或 8 GB 大,**并且需要删除所有数据**。
作者在使用太大的 USB 驱动器遇到过问题,不过你的也许可以工作。无论如何,在接下来的一些步骤中,**将导致 USB 驱动上的数据全部丢失**。
在开始准备安装之前,请先备份 USB 驱动器上的所有数据。这个可启动的 Linux USB 启动器要在另一个 Linux 系统上创建。
1、首先,从 <https://devuan.org/> 获取最新发行版的 Devuan 安装镜像,或者,你也可以在 Linux 终端上输入下面的命令来获取安装镜像:
```
$ cd ~/Downloads
$ wget -c https://files.devuan.org/devuan_jessie_beta/devuan_jessie_1.0.0-beta2_amd64_CD.iso
```
2、上面的命令将会把安装镜像文件下载到用户的 `Downloads` 目录。下一步是把安装镜像写入 USB 驱动器中,从而启动安装程序。
为了写入镜像,需要使用一个在 Linux 中叫做 `dd` 的工具。首先,需要使用 [lsblk 命令](http://www.tecmint.com/find-usb-device-name-in-linux/)来定位硬盘名字:
```
$ lsblk
```

*找到 Linux 中的设备名字*
USB 驱动器的名字为 `/dev/sdc`,现在,可以使用 `dd` 工具把 Devuan 镜像写入驱动器中:
```
$ sudo dd if=~/Downloads/devuan_jessie_1.0.0-beta2_amd64_CD.iso of=/dev/sdc
```
重点:上面的命令需要有 root 权限,你可以使用 `sudo` 或者以 root 用户登录来运行命令。同时,这个命令将会删除 USB 驱动器上的所有数据,所以请确保备份了需要的数据。
3、当镜像写入 USB 驱动器以后,把 USB 驱动器插入要安装 Devuan 的电脑上,然后从 USB 驱动器启动电脑。
从 USB 驱动器成功启动以后,将会出现下面所示的屏幕,你需要在 “Install” 和 “Graphical Install” 这两个选项间选择一个继续安装进程。
在这篇指南中,我将使用 “Graphical Install” 方式。

*Devuan Graphic 安装*
4、当安装程序启动到“本地化”菜单以后,将会提示用户选择键盘布局和语言。只需选择你想要的选项,然后继续安装。

*Devuan 语言选择*

*Devuan 地区选择*

*Devuan 键盘配置*
5、下一步是向安装程序提供主机名和该机器所属的域名。
需要填写一个唯一的主机名,但如果电脑不属于任何域,那么域名可以不填。

*设置 Devuan Linux 的主机名*

*设置 Devuan Linux 的域名*
6、填好主机名和域名信息以后,需要提供一个 root 用户密码。
请务必记住这个密码,因为当你在这台 Devuan 机器上执行管理任务时需要提供这个密码。默认情况下, Devuan 不会安装 sudo 包,所以当安装完成以后,管理用户就是 root 用户。

*设置 Devuan Linux Root 用户*
7、下一步需要做的事情是创建一个非 root 用户。在任何可能的情况下,避免以 root 用户使用系统总是更好的。此时,安装程序将会提示你创建一个非 root 用户。

*创建 Devuan Linux 用户账户*
8、一旦输入 root 用户密码,提示非 root 用户已经创建好以后,安装程序将会请求[通过 NTP 设置时钟](http://www.tecmint.com/install-and-configure-ntp-server-client-in-debian/)。
这时需要再次连接网络,大多数系统都需要这样。

*设置 Devuan Linux 的时区*
9、下一步需要做的是系统分区。对于绝大多数用户来说,选择“Guided – use entire disk”就够了。然而,如果需要进行高级分区,就需要进行分区。

*Devuan Linux 分区*
在上面点击 “continue” 以后,请确认分区更改,从而把分区信息写入硬盘。
10、分区完成以后,安装程序为 Devuan 安装一些基础文件。这个过程将会花费几分钟时间,直到系统开始配置网络镜像(软件库)才会停下来。当提示使用网络镜像时,通常点击 “yes”。

*Devuan Linux 配置包管理器*
点击 “yes” 以后将会给用户呈现一系列以国家分类的网络镜像。通常最好选择地理位置上离你的机器最近的镜像。

*Devuan Linux 镜像选择*

*Devuan Linux 镜像*
11、下一步是设置 Debian 传统的 “popularity contest”,它能够追踪已下载包的使用统计。
在安装过程中,可以在管理员首选项中启用或禁用该功能。

*配置 Devuan Linux 的 Popularity Contest*
12、在简单浏览仓库和一些包的更新以后,安装程序会给用户展示一系列软件包,安装这些包可以提供一个桌面环境、SSH 访问和其它系统工具。
Devuan 会列举出一些主流桌面环境,但应该指出的是,并不是所有的桌面在 Devuan 上均可用。作者在 Devuan 上成功使用过 Xfce 、LXDE 和 Mate(未来的文章将会探究如何从源代码安装这些桌面环境)。
如果想要安装别的桌面环境,不要勾选 “Devuan Desktop Environment” 复选框。

*Devuan Linux 软件选择*
根据在上面的安装屏幕中选择的项目数,可能需要几分钟的时间来下载和安装软件。
当所有的软件都安装好以后,安装程序将会提示用户选择 grub 的安装位置。典型情况是选择安装在 `/dev/sda` 目录下。

*Devuan Linux 安装 grub 引导程序*

*Devuan Linux Grub 程序的安装硬盘*
13、当 GRUB 程序成功安装到引导驱动器以后,安装程序将会提示用户安装已经完成,请重启系统。

*Devuan Linux 安装完成*
14、如果安装顺利完成了,那么系统要么启动到选择桌面环境,或者如果没有选择桌面环境的话,会启动到一个基于文本的控制台。

Devuan Linux 控制台。
这篇文章总结了最新版本的 Devuan Linux 的安装。在这个系列的下一篇文章将会阐述[如何从源代码为 Devuan Linux 安装 Enlightenment 桌面环境](http://www.tecmint.com/install-enlightenment-on-devuan-linux/)。如果你有任何问题或疑问,请记得让我们知道。
---
作者简介:
作者是 Ball 州立大学的计算机系讲师,目前教授计算机系的所有 Linux 课程,同时也教授 Cisco 网络课程。他是 Debian 以及其他 Debian 的衍生版比如 Mint、Ubuntu 和 Kali 的狂热用户。他拥有信息学和通信科学的硕士学位,同时获得了 Cisco、EC 理事会和 Linux 基金会的行业认证。
---
via: <http://www.tecmint.com/installation-of-devuan-linux/>
作者:[Rob Turner](http://www.tecmint.com/author/robturner/) 译者:[ucasFL](https://github.com/ucasFL) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
8,389 | 微软 Office 在线版变得更好 - 在 Linux 上亦然 | http://www.dedoimedo.com/computers/office-online-linux-better.html | 2017-04-09T22:06:00 | [
"微软",
"Office"
] | https://linux.cn/article-8389-1.html | 对于 Linux 用户,影响 Linux 使用体验的主要因素之一便是缺少微软 Office 套装。如果你非得靠 Office 谋生,而它被绝大多数人使用,你可能不能承受使用开源产品的代价。理解矛盾之所在了吗?
的确, LibreOffice 是一个 [很棒的](http://www.ocsmag.com/2015/02/16/libreoffice-4-4-review-finally-it-rocks/) 自由程序,但如果你的客户、顾客或老板需要 Word 和 Excel 文件呢? 你确定能 [承担任何](http://www.ocsmag.com/2014/03/14/libreoffice-vs-microsoft-office-part-deux/) 将这些文件从 ODT 或别的格式转换到 DOCX 之类时的失误、错误或小问题吗, 反之亦然。这是一系列难办的问题。 不幸的是,在技术在层面上对大多数人而言,Linux 超出了能力范围。当然,这不是绝对。

### 加入微软 Office 在线, 加入 Linux
众所周知,微软拥有自己的 Office 云服务多年。通过任何现代浏览器都可以使用使得它很棒且具有意义,并且这意味着在 Linux 上也能使用!我前阵子刚测试了这个[方法](http://www.dedoimedo.com/computers/office-online-linux.html)并且它表现出色。我能够轻松使用这个产品,以原本的格式保存文件,或是转换为我的 ODF 格式,这真的很棒。
我决定再次使用这个套装看看它在过去几年的进步以及是否依旧对 Linux 友好。我使用 [Fedora 25](http://www.dedoimedo.com/computers/fedora-25-gnome.html) 作为例子。我同时也去测试了 [SoftMaker Office 2016](http://www.ocsmag.com/2017/01/18/softmaker-office-2016-your-alternative-to-libreoffice/)。 听起来有趣,也确实如此。
### 第一印象
我得说,我感到很高兴。Office 不需要任何特别的插件。没有 Silverlight 或 Flash 之类的东西。 单纯而大量的 HTML 和 Javascript 。 同时,交互界面反应极其迅速。唯一我不喜欢的就是 Word 文档的灰色背景,它让人很快感到疲劳。除了这个,整个套装工作流畅,没有延迟、行为古怪之处及意料之外的错误。接下来让我们放慢脚步。
这个套装需要你用在线账户或者手机号登录——不必是 Live 或 Hotmail 邮箱。任何邮箱都可以。如果你有微软 [手机](http://www.dedoimedo.com/computers/microsoft-lumia-640.html), 那么你可以用相同的账户并且可以同步你的数据。账户也会免费分配 5GB OneDrive 的储存空间。这很有条理,不是优秀或令人超级兴奋而是非常得当。

你可以使用各种各样的程序,包括必需的三件套 - Word、Excel 和 Powerpoint,并且其它的东西也可使用,包括一些新奇事物。文档会自动保存,但你也可以下载副本并转换成其它格式,比如 PDF 和 ODF。
对我来说这简直完美。分享一个自己的小故事。我用 LibreOffice 写一本 [奇幻类的](http://www.thelostwordsbooks.com/)书,之后当我需要将它们送去出版社编辑或者校对,我需要把它们转换成 DOCX 格式。唉,这需要微软 office。从我的 [Linux 问题解决大全](http://www.dedoimedo.com/computers/linux-problem-solving-book.html)得知,我得一开始就使用 Word,因为有一堆工作要与我的编辑合作完成,而他们使用专有软件。没有任何情面可讲,只有出于对冷酷的金钱和商业的考量。错误是不容许接受的。

使用 Office 在线版能给很多偶尔需要使用的人以自由空间。偶尔使用 Word、Excel 等,不需要购买整个完整的套装。如果你表面上是 LibreOffice 的忠实粉丝,你也可以暗地里“加入微软 Office 负心者俱乐部”而不必感到愧疚。有人传给你一个 Word 或 PPT 文件,你可以上传然后在线操作它们,然后转换成所需要的。这样的话你就可以在线生成你的工作,发送给那些严格要求的人,同时自己留一个 ODF 格式的备份,有需要的话就用 LibreOffice 操作。虽然这种方法的灵活性很是实用,但这不应该成为你的主要手段。对于 Linux 用户,这给予了很多他们平时所没有的自由,毕竟即使你想用微软 Office 也不好安装。

### 特性、选项、工具
我开始琢磨一个文档——考虑到这其中各种细枝末节。写点文本,用一种或三种风格,链接某些文本,嵌入图片,加上脚注,评论自己的文章甚至作为一个多重人格的极客巧妙地回复自己的评论。
除了灰色背景——我们得学会很好地完成一项无趣工作,即便是像臭鼬工厂那样的工作方式,因为浏览器里没有选项调整背景颜色——其实也还好啦。
Skype 甚至也整合到了其中,你可以边沟通边协作,或者在协作中倾听。其色调相当一致。鼠标右键可以选择一些快捷操作,包括链接、评论和翻译。不过需要改进的地方还有不少,它并没有给我想要的,翻译有差错。




你也可以加入图片——包括默认嵌入的必应搜索可以基于它们的许可证和分发权来筛选图片。这很棒,特别是当你想要创作文档而又想避免版权纷争时。

### 关于追踪多说几句
说老实话,很实用。这个产品基于在线使用使得默认情况下可以跟踪更改和编辑,所以你就有了基本的版本控制功能。不过如果直接关闭而不保存的话,阶段性的编辑会遗失。


看到一个错误——如果你试着在 Linux 上(本地)编辑 Word 或 Excel 文件,会被提示你很调皮,因为这明显是个不支持的操作。

### Excel
实际工作流程不止使用 Word。我也使用 Excel,众所周知,它包含了很多整齐有效的模板之类的。好用而且在更新单元格和公式时没有任何延迟,它涵盖了你所需要的大多数功能。



### OneDrive
在这里你可以新建文件夹和文件、移动文件、给你的朋友(如果你需要的话)和同事们分享文件。5 GB 免费,当然,收费增容。总的来说,做的不错。在更新和展示内容上会花费一定时间。打开了的文档不能被删除,这可能看起来像一个漏洞,但从计算机角度来看是完美的体验。

### 帮助
如果你感到疑惑——比如被人工智能戏耍,可以向微软的云智囊团寻求帮助。 虽然这种方式不那么直接,但至少好用,结果往往也能令人满意。

### 问题
在我三个小时的摸索中,我只遇到了两个小问题。一是文件编辑的时候浏览器会有警告(黄色三角),提醒我在 HTTPS 会话中加载了不安全的元素。二是创建 Excel 文件失败,只出现过一次。

### 结论
微软 Office 在线版是一个优秀的产品,与我两年前测试相比较,它变得更好了。外观出色,表现良好,使用期间错误很少,完美兼容,甚至对于 Linux 用户,使之具有个人意义和商业价值。我不能说它是自 VHS (Video Home System,家用录像系统)出现以来最好的东西,但一定是很棒的,它架起了 Linux 用户与微软 Office 之间的桥梁,解决了 Linux 用户长期以来的问题,方便且很好的支持 ODF 。
现在我们来让事情变得更有趣些,如果你喜欢云概念的事物,那你可能对 [Open365](http://www.ocsmag.com/2016/08/17/open365/) 感兴趣,这是一个基于 LibreOfiice 的办公软件,加上额外的邮件客户端和图像处理软件,还有 20 GB 的免费存储空间。最重要的是,你可以用浏览器同时完成这一切,只需要多开几个窗口。
回到微软,如果你是 Linux 用户,如今可能确实需要微软 Office 产品。在线 Office 套装无疑是更方便的使用方法——或者至少不需要更改操作系统。它免费、优雅、透明度高。值得一提的是,你可以把思维游戏放在一边,享受你的云端生活。
干杯~
---
作者简介:
我的名字是 Igor Ljubuncic. 38 岁左右,已婚未育。现在是一家云技术公司的首席工程师,这是一个新的领域。到 2015 年初之前,我作为团队中的一名系统工程师就职于世界上最大的信息技术公司之一,开发新的 Linux 解决方案、完善内核、研究 linux。在这之前,我是创新设计团队的技术指导,致力于高性能计算环境的创新解决方案。还有一些像系统专家、系统程序员之类的新奇的名字。这些全是我的爱好,直到 2008 年,变成了工作,还有什么能比这更令人满意呢?
从 2004 到 2008,我作为物理学家在医学影像行业谋生。我专攻解决问题和发展算法,后来大量使用 Matlab 处理信号和图像。另外我考了很多工程计算方法的认证,包括 MEDIC Six Sigma Green Belt,实验设计和数据化工程。
我也开始写书,包括奇幻类和 Linux 上的技术性工作。彼此交融。
---
via: <http://www.dedoimedo.com/computers/office-online-linux-better.html>
作者:[Igor Ljubuncic](http://www.dedoimedo.com/faq.html) 译者:[XYenChi](https://github.com/XYenChi) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://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.