mirror of
https://github.com/LCTT/TranslateProject.git
synced 2026-08-23 04:03:29 +08:00
Merge remote-tracking branch 'LCTT/master'
This commit is contained in:
254
published/20190830 How to Create and Use Swap File on Linux.md
Normal file
254
published/20190830 How to Create and Use Swap File on Linux.md
Normal file
@@ -0,0 +1,254 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (heguangzhi)
|
||||
[#]: reviewer: (wxy)
|
||||
[#]: publisher: (wxy)
|
||||
[#]: url: (https://linux.cn/article-11341-1.html)
|
||||
[#]: subject: (How to Create and Use Swap File on Linux)
|
||||
[#]: via: (https://itsfoss.com/create-swap-file-linux/)
|
||||
[#]: author: (Abhishek Prakash https://itsfoss.com/author/abhishek/)
|
||||
|
||||
如何在 Linux 上创建和使用交换文件
|
||||
======
|
||||
|
||||
本教程讨论了 Linux 中交换文件的概念,为什么使用它以及它相对于传统交换分区的优势。你将学习如何创建交换文件和调整其大小。
|
||||
|
||||
### 什么是 Linux 的交换文件?
|
||||
|
||||
交换文件允许 Linux 将磁盘空间模拟为内存。当你的系统开始耗尽内存时,它会使用交换空间将内存的一些内容交换到磁盘空间上。这样释放了内存,为更重要的进程服务。当内存再次空闲时,它会从磁盘交换回数据。我建议[阅读这篇文章,了解 Linux 上的交换空间的更多内容][1]。
|
||||
|
||||
传统上,交换空间是磁盘上的一个独立分区。安装 Linux 时,只需创建一个单独的分区进行交换。但是这种趋势在最近几年发生了变化。
|
||||
|
||||
使用交换文件,你不再需要单独的分区。你会根目录下创建一个文件,并告诉你的系统将其用作交换空间就行了。
|
||||
|
||||
使用专用的交换分区,在许多情况下,调整交换空间的大小是一个可怕而不可能的任务。但是有了交换文件,你可以随意调整它们的大小。
|
||||
|
||||
最新版本的 Ubuntu 和其他一些 Linux 发行版已经开始 [默认使用交换文件][2]。甚至如果你没有创建交换分区,Ubuntu 也会自己创建一个 1GB 左右的交换文件。
|
||||
|
||||
让我们看看交换文件的更多信息。
|
||||
|
||||

|
||||
|
||||
### 检查 Linux 的交换空间
|
||||
|
||||
在你开始添加交换空间之前,最好检查一下你的系统中是否已经有了交换空间。
|
||||
|
||||
你可以用[Linux 上的 free 命令][4]检查它。就我而言,我的[戴尔 XPS][5]有 14GB 的交换容量。
|
||||
|
||||
```
|
||||
free -h
|
||||
total used free shared buff/cache available
|
||||
Mem: 7.5G 4.1G 267M 971M 3.1G 2.2G
|
||||
Swap: 14G 0B 14G
|
||||
```
|
||||
|
||||
`free` 命令给出了交换空间的大小,但它并没有告诉你它是真实的交换分区还是交换文件。`swapon` 命令在这方面会更好。
|
||||
|
||||
```
|
||||
swapon --show
|
||||
NAME TYPE SIZE USED PRIO
|
||||
/dev/nvme0n1p4 partition 14.9G 0B -2
|
||||
```
|
||||
|
||||
如你所见,我有 14.9GB 的交换空间,它在一个单独的分区上。如果是交换文件,类型应该是 `file` 而不是 `partition`。
|
||||
|
||||
```
|
||||
swapon --show
|
||||
NAME TYPE SIZE USED PRIO
|
||||
/swapfile file 2G 0B -2
|
||||
```
|
||||
|
||||
如果你的系统上没有交换空间,它应该显示如下内容:
|
||||
|
||||
```
|
||||
free -h
|
||||
total used free shared buff/cache available
|
||||
Mem: 7.5G 4.1G 267M 971M 3.1G 2.2G
|
||||
Swap: 0B 0B 0B
|
||||
```
|
||||
|
||||
而 `swapon` 命令不会显示任何输出。
|
||||
|
||||
|
||||
### 在 Linux 上创建交换文件
|
||||
|
||||
如果你的系统没有交换空间,或者你认为交换空间不足,你可以在 Linux 上创建交换文件。你也可以创建多个交换文件。
|
||||
|
||||
让我们看看如何在 Linux 上创建交换文件。我在本教程中使用 Ubuntu 18.04,但它也应该适用于其他 Linux 发行版本。
|
||||
|
||||
#### 步骤 1:创建一个新的交换文件
|
||||
|
||||
首先,创建一个具有所需交换空间大小的文件。假设我想给我的系统增加 1GB 的交换空间。使用`fallocate` 命令创建大小为 1GB 的文件。
|
||||
|
||||
```
|
||||
sudo fallocate -l 1G /swapfile
|
||||
```
|
||||
|
||||
建议只允许 `root` 用户读写该交换文件。当你尝试将此文件用于交换区域时,你甚至会看到类似“不安全权限 0644,建议 0600”的警告。
|
||||
|
||||
```
|
||||
sudo chmod 600 /swapfile
|
||||
```
|
||||
|
||||
请注意,交换文件的名称可以是任意的。如果你需要多个交换空间,你可以给它任何合适的名称,如 `swap_file_1`、`swap_file_2` 等。它们只是一个预定义大小的文件。
|
||||
|
||||
#### 步骤 2:将新文件标记为交换空间
|
||||
|
||||
你需要告诉 Linux 系统该文件将被用作交换空间。你可以用 [mkswap][7] 工具做到这一点。
|
||||
|
||||
```
|
||||
sudo mkswap /swapfile
|
||||
```
|
||||
|
||||
你应该会看到这样的输出:
|
||||
|
||||
```
|
||||
Setting up swapspace version 1, size = 1024 MiB (1073737728 bytes)
|
||||
no label, UUID=7e1faacb-ea93-4c49-a53d-fb40f3ce016a
|
||||
```
|
||||
|
||||
#### 步骤 3:启用交换文件
|
||||
|
||||
现在,你的系统知道文件 `swapfile` 可以用作交换空间。但是还没有完成。你需要启用该交换文件,以便系统可以开始使用该文件作为交换。
|
||||
|
||||
```
|
||||
sudo swapon /swapfile
|
||||
```
|
||||
|
||||
现在,如果你检查交换空间,你应该会看到你的 Linux 系统会识别并使用它作为交换空间:
|
||||
|
||||
```
|
||||
swapon --show
|
||||
NAME TYPE SIZE USED PRIO
|
||||
/swapfile file 1024M 0B -2
|
||||
```
|
||||
|
||||
#### 步骤 4:让改变持久化
|
||||
|
||||
迄今为止你所做的一切都是暂时的。重新启动系统,所有更改都将消失。
|
||||
|
||||
你可以通过将新创建的交换文件添加到 `/etc/fstab` 文件来使更改持久化。
|
||||
|
||||
对 `/etc/fstab` 文件进行任何更改之前,最好先进行备份。
|
||||
|
||||
```
|
||||
sudo cp /etc/fstab /etc/fstab.back
|
||||
```
|
||||
|
||||
现在将以下行添加到 `/etc/fstab` 文件的末尾:
|
||||
|
||||
```
|
||||
/swapfile none swap sw 0 0
|
||||
```
|
||||
|
||||
你可以使用[命令行文本编辑器][8]手动操作,或者使用以下命令:
|
||||
|
||||
```
|
||||
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
|
||||
```
|
||||
|
||||
现在一切都准备好了。即使在重新启动你的 Linux 系统后,你的交换文件也会被使用。
|
||||
|
||||
### 调整 swappiness 参数
|
||||
|
||||
`swappiness` 参数决定了交换空间的使用频率。`swappiness` 值的范围从 0 到 100。较高的值意味着交换空间将被更频繁地使用。
|
||||
|
||||
Ubuntu 桌面的默认的 `swappiness` 是 60,而服务器的默认 `swappiness` 是 1。你可以使用以下命令检查 `swappiness`:
|
||||
|
||||
```
|
||||
cat /proc/sys/vm/swappiness
|
||||
```
|
||||
|
||||
为什么服务器应该使用低的 `swappiness` 值?因为交换空间比内存慢,为了获得更好的性能,应该尽可能多地使用内存。在服务器上,性能因素至关重要,因此 `swappiness` 应该尽可能低。
|
||||
|
||||
你可以使用以下系统命令动态更改 `swappiness`:
|
||||
|
||||
```
|
||||
sudo sysctl vm.swappiness=25
|
||||
```
|
||||
|
||||
这种改变只是暂时的。如果要使其永久化,可以编辑 `/etc/sysctl.conf` 文件,并在文件末尾添加`swappiness` 值:
|
||||
|
||||
```
|
||||
vm.swappiness=25
|
||||
```
|
||||
|
||||
### 在 Linux 上调整交换空间的大小
|
||||
|
||||
在 Linux 上有几种方法可以调整交换空间的大小。但是在你看到这一点之前,你应该了解一些关于它的事情。
|
||||
|
||||
当你要求系统停止将交换文件用于交换空间时,它会将所有数据(确切地说是内存页)传输回内存。所以你应该有足够的空闲内存,然后再停止交换。
|
||||
|
||||
这就是为什么创建和启用另一个临时交换文件是一个好的做法的原因。这样,当你关闭原来的交换空间时,你的系统将使用临时交换文件。现在你可以调整原来的交换空间的大小。你可以手动删除临时交换文件或留在那里,下次启动时会自动删除(LCTT 译注:存疑?)。
|
||||
|
||||
如果你有足够的可用内存或者创建了临时交换空间,那就关闭你原来的交换文件。
|
||||
|
||||
```
|
||||
sudo swapoff /swapfile
|
||||
```
|
||||
|
||||
现在你可以使用 `fallocate` 命令来更改文件的大小。比方说,你将其大小更改为 2GB:
|
||||
|
||||
```
|
||||
sudo fallocate -l 2G /swapfile
|
||||
```
|
||||
|
||||
现在再次将文件标记为交换空间:
|
||||
|
||||
```
|
||||
sudo mkswap /swapfile
|
||||
```
|
||||
|
||||
并再次启用交换文件:
|
||||
|
||||
```
|
||||
sudo swapon /swapfile
|
||||
```
|
||||
|
||||
你也可以选择同时拥有多个交换文件。
|
||||
|
||||
### 删除 Linux 中的交换文件
|
||||
|
||||
你可能有不在 Linux 上使用交换文件的原因。如果你想删除它,该过程类似于你刚才看到的调整交换大小的过程。
|
||||
|
||||
首先,确保你有足够的空闲内存。现在关闭交换文件:
|
||||
|
||||
```
|
||||
sudo swapoff /swapfile
|
||||
```
|
||||
|
||||
下一步是从 `/etc/fstab` 文件中删除相应的条目。
|
||||
|
||||
最后,你可以删除该文件来释放空间:
|
||||
|
||||
```
|
||||
sudo rm /swapfile
|
||||
```
|
||||
|
||||
### 你用了交换空间了吗?
|
||||
|
||||
我想你现在已经很好地理解了 Linux 中的交换文件概念。现在,你可以根据需要轻松创建交换文件或调整它们的大小。
|
||||
|
||||
如果你对这个话题有什么要补充的或者有任何疑问,请在下面留下评论。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://itsfoss.com/create-swap-file-linux/
|
||||
|
||||
作者:[Abhishek Prakash][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[heguangzhi](https://github.com/heguangzhi)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://itsfoss.com/author/abhishek/
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://itsfoss.com/swap-size/
|
||||
[2]: https://help.ubuntu.com/community/SwapFaq
|
||||
[3]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2019/08/swap-file-linux.png?resize=800%2C450&ssl=1
|
||||
[4]: https://linuxhandbook.com/free-command/
|
||||
[5]: https://itsfoss.com/dell-xps-13-ubuntu-review/
|
||||
[6]: https://itsfoss.com/fix-missing-system-settings-ubuntu-1404-quick-tip/
|
||||
[7]: http://man7.org/linux/man-pages/man8/mkswap.8.html
|
||||
[8]: https://itsfoss.com/command-line-text-editors-linux/
|
||||
[9]: https://itsfoss.com/replace-linux-from-dual-boot/
|
||||
@@ -0,0 +1,64 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Can AMD convert its growing GPU presence into a data center play?)
|
||||
[#]: via: (https://www.networkworld.com/article/3438098/can-amd-convert-its-growing-gpu-presence-into-a-data-center-play.html)
|
||||
[#]: author: (Andy Patrizio https://www.networkworld.com/author/Andy-Patrizio/)
|
||||
|
||||
Can AMD convert its growing GPU presence into a data center play?
|
||||
======
|
||||
AMD has scored high-performance computing deals recently, but to truly compete with Nvidia it needs to develop an alternative to Nvidia’s CUDA language.
|
||||
AMD
|
||||
|
||||
AMD's $5.4 billion purchase of ATI Technologies in 2006 seemed like an odd match. Not only were the companies in separate markets, but they were on separate coasts, with ATI in the Toronto, Canada, region and AMD in Sunnyvale, California.
|
||||
|
||||
They made it work, and arguably it saved AMD from extinction because it was the graphics business that kept the company afloat while the Athlon/Opteron business was going nowhere. There were many quarters where graphics brought in more revenue than CPUs and likely saved the company from bankruptcy.
|
||||
|
||||
But those days are over, and AMD is once again a highly competitive CPU company, and quarterly sales are getting very close to the $2 billion mark. While the CPU business is on fire, the GPU business continues to do well.
|
||||
|
||||
**Also read: [AI boosts data-center availability and efficiency][1]**
|
||||
|
||||
For the second quarter of 2019, AMD's GPU shipments increased 9.8% vs. Q1, while Nvidia's were flat and Intel's shipments decreased -1.4%, according to Jon Peddie Research. An increase over the first quarter is a very good showing because Q2 typically drops from Q1.
|
||||
|
||||
AMD and Nvidia don't break out market segments, nor do they say what percentage comes from enterprise/HPC/supercomputing sales. The challenge for AMD, then, is to translate its gaming popularity into enterprise sales.
|
||||
|
||||
### Competing in the high-performance computing space
|
||||
|
||||
In high-performance computing (HPC), which includes artificial intelligence (AI), Nvidia clearly dominates. AMD has no answer for Nvidia's RTX 270/280 or the Tesla T4, but that hasn't stopped AMD from racking up the occasional win. The Oak Ridge National Lab plans to build an exascale supercomputer called Frontier in 2021 using AMD Epyc processors and Radeon GPUs.
|
||||
|
||||
AMD CEO Lisa Su talked about it at the recent Hot Chips semiconductor conference, where she said Frontier would feature "highly optimized CPU, highly optimized GPU, highly optimized coherent interconnect between CPU and GPU, [and] working together with Cray on the node to node latency characteristics really enables us to put together a leadership system.”
|
||||
|
||||
AMD has also scored deals with Google to power its cloud-based Stadia game console, providing 10.7Tflops/sec., more than the Microsoft and Sony consoles combined. And AMD has had a deal with China's Baidu to provide GPU-based computing for two years.
|
||||
|
||||
The problem, according to Peddie, isn't so much the hardware as it is the software. Nvidia has a special language called CUDA, first developed by Stanford professor Ian Buck, who is now head of Nvidia's AI efforts. It allows developers to write apps that fully utilize the GPU with a familiar C++ syntax. Nvidia then went to hundreds of universities and set them up to teach CUDA to students.
|
||||
|
||||
"The net result is universities around the world are cranking out thousands of grads who know CUDA, and AMD has no equivalent," said Peddie.
|
||||
|
||||
The result is it's much harder to code for a Radeon than a Tesla/Volta. AMD supports the open-standard OpenCL library and the open-source project [HIP][2], which converts CUDA to portable C++ code.
|
||||
|
||||
The OpenCL standard was developed by Apple but is now maintained by the [Khronos Group][3], and if there is one way for a standard to go nowhere, it's to put it in the hands of a standards group. Look what it did for OpenGL. It had the lead decades ago, then Microsoft came out with DirectX and obliterated OpenGL. The unfortunate fact is standards always fare better when there is a company behind it with something to gain.
|
||||
|
||||
For AMD to gain ground in the data center and HPC/AI against Nvidia, it needs a competitor to CUDA. Up until two years ago, that simply wasn't possible because AMD was fighting for its life. But now, with hot new silicon, the time is right for the company to push into software and give Nvidia the same fits it is giving Intel.
|
||||
|
||||
Join the Network World communities on [Facebook][4] and [LinkedIn][5] to comment on topics that are top of mind.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.networkworld.com/article/3438098/can-amd-convert-its-growing-gpu-presence-into-a-data-center-play.html
|
||||
|
||||
作者:[Andy Patrizio][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://www.networkworld.com/author/Andy-Patrizio/
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://www.networkworld.com/article/3274654/ai-boosts-data-center-availability-efficiency.html
|
||||
[2]: https://github.com/ROCm-Developer-Tools/HIP
|
||||
[3]: https://www.khronos.org/opencl/
|
||||
[4]: https://www.facebook.com/NetworkWorld/
|
||||
[5]: https://www.linkedin.com/company/network-world
|
||||
67
sources/talk/20190911 How Linux came to the mainframe.md
Normal file
67
sources/talk/20190911 How Linux came to the mainframe.md
Normal file
@@ -0,0 +1,67 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (How Linux came to the mainframe)
|
||||
[#]: via: (https://opensource.com/article/19/9/linux-mainframes-part-1)
|
||||
[#]: author: (Elizabeth K. Joseph https://opensource.com/users/pleia2https://opensource.com/users/sethhttps://opensource.com/users/sethhttps://opensource.com/users/jhibbetshttps://opensource.com/users/jimmyolano)
|
||||
|
||||
How Linux came to the mainframe
|
||||
======
|
||||
Linux's emergence on the mainframe is indebted to the external developer
|
||||
community working with IBM.
|
||||
![Person typing on a 1980's computer][1]
|
||||
|
||||
Despite my 15 years of experience in the Linux infrastructure space, if you had asked me a year ago what a mainframe was, I'd be hard-pressed to give a satisfying technical answer. I was surprised to learn that the entire time I'd been toiling away on x86 machines in various systems administration roles, Linux was running on the s390x architecture for mainframes. In fact, 2019 marks 20 years of IBM's involvement in Linux on the mainframe, with purely community efforts predating that by a year.
|
||||
|
||||
### What is a mainframe?
|
||||
|
||||
You can think of a mainframe as a big, enterprise-grade server. Everything from the custom s390x CPUs to memory and power, coupled with external storage arrays, is highly redundant and even built to survive earthquakes (check out the [z13 Earthquake Shake Test][2] on YouTube). Built-in hardware-based encryption allows for end-to-end encryption of your data without taking general processing power away from your workloads. Essentially, if you want your workloads and data to be safe and secure, it still makes sense to invest in a mainframe.
|
||||
|
||||
The traditional mainframe operating system is z/OS, which has a long history and still gets regular releases to add functionality, security, and stability. The [Open Mainframe Project][3] hosts a collection of open source projects, largely built around z/OS, to further modernize the platform. This includes [Zowe][4], which brings modern API, shell, automation, and scripting tooling to the mainframe. Systems administrators who are looking at mainframes now have a modern, familiar toolset to work with. Add support for Linux in the mix? Suddenly you have an incredibly powerful addition to infrastructure, and it supports all the tools you're familiar with.
|
||||
|
||||
### The origins of Linux on the mainframe
|
||||
|
||||
To get a real picture of how Linux got to the mainframe, I'll take you back in time. The first IBM mainframe, the IBM System/360, was introduced in 1964. Before this, computers were purpose-built for specific clients and industries. The S/360 was built to be a multi-purpose computer, able to cover a variety of computing needs across industries. Fast-forward to 1972, and we have what's really a pivotal moment in modern computing: the introduction of VM/370.
|
||||
|
||||
VM stands for the same thing it means today, virtual machine, and this was the first virtualization technology for the mainframe. Time-sharing on the mainframe had been an idea in whitepapers dating back to the 1950s, but VM/370 brought that to another level. If you're interested in why this was revolutionary and the technical history of the components and teams that made this happen, read Melinda Varian's fascinating article _[VM and the VM Community: Past, Present, and Future][5]_.
|
||||
|
||||
As a long-time open source enthusiast, I found one of the most interesting things about the development of the VM was how community-driven it was. People from various universities and companies outside IBM were driving the efforts and giving their feedback to IBM to push development forward. While learning about the history, I identified key people inside IBM—I would call them the first developer advocates—who went out of their way to support external developers on the platform and advocate for their needs internally to drive change at IBM.
|
||||
|
||||
Fast-forward to 1994, and we reach another milestone that helped pave the way for Linux on the mainframe: experimental TCP/IP support in VMs. Mainframes have supported a series of network-type interfaces; TCP/IP was just one, but for the purposes of porting Linux to the mainframe, it was a key one.
|
||||
|
||||
It was 1998 when a fellow named Linas Vepstas started the "Bigfoot" effort to see if he could get Linux running on a mainframe using a VM. I love this part of the history, partially because it goes back to the community driving development, but also because of his [_Why port Linux to the mainframe?_][6] page. His first four points really spoke to me as an infrastructure geek:
|
||||
|
||||
* Stunt
|
||||
* To learn
|
||||
* Because it's there
|
||||
* Because it's knarly, duude!
|
||||
|
||||
|
||||
|
||||
Linas fleshes these points out—and reading them showed me immediately that I had found a kindred spirit. His list continues into more practical things: I/O, address spaces and access lists, VM, and the business model. But given how he orders his points, I think I know where his real motivations are.
|
||||
|
||||
But when did IBM join in and offer official support? I'll explain next week in part two of this history.
|
||||
|
||||
We got a chance to send a few questions to Jim Zemlin, executive director of the Linux Foundation...
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/19/9/linux-mainframes-part-1
|
||||
|
||||
作者:[Elizabeth K. Joseph][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/pleia2https://opensource.com/users/sethhttps://opensource.com/users/sethhttps://opensource.com/users/jhibbetshttps://opensource.com/users/jimmyolano
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/1980s-computer-yearbook.png?itok=eGOYEKK- (Person typing on a 1980's computer)
|
||||
[2]: https://www.youtube.com/watch?v=kmMn5Q_lnkk
|
||||
[3]: https://www.openmainframeproject.org/
|
||||
[4]: https://www.openmainframeproject.org/projects/zowe
|
||||
[5]: http://www.leeandmelindavarian.com/Melinda/25paper.pdf
|
||||
[6]: https://linas.org/linux/i370-why.html
|
||||
@@ -0,0 +1,66 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (To secure industrial IoT, use segmentation instead of firewalls)
|
||||
[#]: via: (https://www.networkworld.com/article/3437956/to-secure-industrial-iot-use-segmentation-instead-of-firewalls.html)
|
||||
[#]: author: (Zeus Kerravala https://www.networkworld.com/author/Zeus-Kerravala/)
|
||||
|
||||
To secure industrial IoT, use segmentation instead of firewalls
|
||||
======
|
||||
Firewalls have been the de facto standard for securing internal devices for years, but the industrial internet of things (IIoT) will change that.
|
||||
Jiraroj Praditcharoenkul / Getty Images
|
||||
|
||||
The internet of things (IoT) has been top of mind for network and security professionals for the better part of the past five years. This has been particularly true for the area of industrial IoT (IIoT). Connected industrial devices are nothing new, but most IT people aren’t familiar with them because they have been managed by operational technology (OT) teams. More and more, though, business leaders want to bring OT and IT together to drive better insights from the combined data set.
|
||||
|
||||
While there are many advantages to merging IT and OT and having IIoT fall under IT ownership, it has a profound impact on the cybersecurity team because it introduces several new security threats. Each connected endpoint, if breached, creates a backdoor into the other systems.
|
||||
|
||||
**[ Also read: [A corporate guide to addressing IoT security][1] ]**
|
||||
|
||||
### Internal firewalls an expensive, complex option for IIoT
|
||||
|
||||
One way to protect IIoT environments is to use internal firewalls. This may seem like an obvious choice because internal firewalls have become the de facto standard for securing almost anything. However, in an IIoT environment, firewalls are perhaps the worst choice because of cost and complexity.
|
||||
|
||||
Historically, internal firewalls were deployed where traffic moved in a “north-south” direction and would pass through a single ingress/egress point, such as a core switch. Also, the devices connected were all known and managed by IT. With IIoT, connections can be much more dynamic and traffic can flow between devices in an “east-west” pattern, bypassing where the firewalls are located. That means security teams would need to deploy an internal firewall at every possible IIoT connection point and then manage the policies and configurations across hundreds, possibly thousands of firewalls, creating an almost unmanageable situation.
|
||||
|
||||
To get a better understanding of the magnitude of this problem, I talked with Jeff Hussey, president and CEO of Tempered Networks, which specializes in IIoT security solutions, and he told me about one of the company’s customers that explored using internal firewalls. After doing an extensive evaluation of where all the internal firewalls would need to go, the business estimated that the total cost of firewalls would be about $100 million. Even if a business could afford that, there’s another layer of challenges associated with the operational side.
|
||||
|
||||
Hussey then told me about a healthcare customer that’s trying to use a combination of firewall rules, ACL, VLANs, and VPNs to secure their environment, but, as he put it, “the complexity was killing them” and makes it impossible to get anything done because of the operational overhead.
|
||||
|
||||
I also spoke with Derek Harp, founder and chairman of the [Control System Cyber Security Association International][2] (CS2AI), who does a lot of work in the IIoT area. He described the current IIoT environments as getting “more porous” as networks continue to evolve and become more open as third parties need access to data from internal systems. Toss in the advanced skill level of threat actors, and it’s easy to see how this isn’t a fight that cybersecurity teams can fight with traditional network security.
|
||||
|
||||
**[ [Prepare to become a Certified Information Security Systems Professional with this comprehensive online course from PluralSight. Now offering a 10-day free trial!][3] ]**
|
||||
|
||||
### Micro-segmentation preferred over internal firewalls for IIoT
|
||||
|
||||
Instead of using internal firewalls, security professionals should turn towards IIoT micro-segmentation. Segmentation is similar to the use of VLANs and ACLs, but the environmental separation is done at the device level and managed with rules instead of at the network layer. With VLANs and ACLs, all devices, including IIoT endpoints, would need to be assigned to a VLAN. If the endpoint moves, the network then needs to be reconfigured to accommodate. If it’s not, the device either can’t connect or is on the same network as devices where bad things could happen if it were breached.
|
||||
|
||||
The Target breach of a few years ago is an excellent example of this where the retailer's HVAC system was compromised, and that created a back door into the point-of-sale (PoS) system. Traditional security works great in highly static environments, but IIoT can be highly dynamic with devices routinely joining and leaving the network.
|
||||
|
||||
### Segmentation operates at the device layer
|
||||
|
||||
The benefit of segmentation is that it’s done in software and operates at the device connectivity layer, so policies follow the endpoints. For example, a rule could be created where all medical devices are in a particular segment and isolated from the rest of the connected nodes. If a medical device moves, the policy goes with it and there’s no need to reconfigure things. If Target had been using IIoT micro-segmentation and the HVAC and PoS systems were in separate segments (which they should be from a best practice standpoint), the worst that could have happened is the stores got too warm.
|
||||
|
||||
Micro-segmentation has been used in data centers to secure lateral traffic that flows between virtual machines and containers. Cybersecurity teams should now look to extend the technology out to the broader network, with the first use case being to secure IIoT endpoints. This will let businesses move forward with digital transformation plans without putting their companies at risk.
|
||||
|
||||
Join the Network World communities on [Facebook][4] and [LinkedIn][5] to comment on topics that are top of mind.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.networkworld.com/article/3437956/to-secure-industrial-iot-use-segmentation-instead-of-firewalls.html
|
||||
|
||||
作者:[Zeus Kerravala][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://www.networkworld.com/author/Zeus-Kerravala/
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://www.networkworld.com/article/3269165/internet-of-things/a-corporate-guide-to-addressing-iot-security-concerns.html
|
||||
[2]: https://www.cs2ai.org/
|
||||
[3]: https://pluralsight.pxf.io/c/321564/424552/7490?u=https%3A%2F%2Fwww.pluralsight.com%2Fpaths%2Fcertified-information-systems-security-professional-cisspr
|
||||
[4]: https://www.facebook.com/NetworkWorld/
|
||||
[5]: https://www.linkedin.com/company/network-world
|
||||
@@ -0,0 +1,147 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (3 ways to handle transient faults for DevOps)
|
||||
[#]: via: (https://opensource.com/article/19/9/transient-faults-devops)
|
||||
[#]: author: (Willy-Peter Schaub https://opensource.com/users/wpschaubhttps://opensource.com/users/wpschaubhttps://opensource.com/users/wpschaub)
|
||||
|
||||
3 ways to handle transient faults for DevOps
|
||||
======
|
||||
DevOps is about delighting our stakeholders with continuous business
|
||||
value, and how we manage transient faults is part of that.
|
||||
![Bright gears connecting][1]
|
||||
|
||||
In electrical engineering, a _transient fault_ is defined as an error condition that vanishes after the power is disconnected and restored. This is also a workaround many of us unconsciously use when we forcefully power our physical devices off and on when they're performing poorly or frozen on a blue crash screen filled with gibberish.
|
||||
|
||||
In cloud computing, we are faced with increased complexity, known unknowns, or worse, unknown unknowns with infrastructure we will never touch as well as technology that's evolving at an exponential rate and disparate solutions connecting an expanding digital world. Today's virtual users' tolerance for unresponsive, unreliable, and underperforming products is zero—everyone wants 24x7 uptime and solutions that evolve and blend into their lifestyle.
|
||||
|
||||
In this new virtual world, we cannot just walk up and reboot a machine, at least not without impacting hundreds, thousands, or even millions of users. And loyalty to brands and products is dwindling fast in today's competitive world; users would probably look for an alternative service at a click of a keystroke and never return rather than put up with any measurable amount of downtime.
|
||||
|
||||
Let's take a quick look at two events that were _humbling_ reminders that today's transient faults can occur in a heartbeat, are complex to identify and resolve, and have a profound impact on our stakeholders.
|
||||
|
||||
* [**A Rough Patch**][2]**:** "_We've had some issues with the service over the past week and a half. I feel terrible about it, and I can't apologize enough. It's the biggest incident we've had since the instability created by our service refactoring,"_ wrote Microsoft corporate VP of cloud developer services Brian Harry on his blog. After weeks of sleepless nights, the root cause was identified as a storm of requests to the access control service (ACS) that exhausted Source Network Address Translation (SNAT) ports, prevented authentications, and impacted our stakeholders.
|
||||
* **[503 Error][3]:** _"Setting up monitoring from the beginning of the implementation of our Azure function confirms the importance of monitoring in the DevOps process,"_ reported Cellenza's Mikael Krief on the ALM DevOps Rangers blog. Again, we spent sleepless nights finding the root cause of why our refactored extension spawned a storm of connections and threads, imploded our Azure service, and frustrated our stakeholders with 503 Service Unavailable errors.
|
||||
|
||||
|
||||
|
||||
We can set up failure and disaster recovery for our cloud applications to help minimize, not eliminate, the impact of an outage caused by resource failures or natural disasters. However, for solutions that use remote resources or communicate with remote services, we need to add a pinch of sensitivity to transient faults. Well-designed solutions detect and attempt to self-correct transient faults before sounding an alarm—or worse, becoming unresponsive and failing.
|
||||
|
||||
There are a handful of transient fault handling patterns, including the three shown on the following whiteboard: **retry**, **throttling**, and **circuit breaker**.
|
||||
|
||||
![transient fault handling patterns][4]
|
||||
|
||||
### Retry pattern
|
||||
|
||||
The retry pattern is the simplest of the three transient fault handling patterns and something we do naturally in everyday life. It can be effective in solutions that communicate across distributed networks to handle transient faults caused by issues such as network latency, service overloads, and power outages.
|
||||
|
||||
![Retry pattern][5]
|
||||
|
||||
**Pseudocode**
|
||||
|
||||
Set failure_count = 0
|
||||
**Call** the [micro] service
|
||||
If (fail) failure_count++
|
||||
If (failure_count > retry_limit) or (not transient failure) FAIL
|
||||
**Delay** (delay_time)
|
||||
Increase delay_time by factor of failure_count
|
||||
**Retry** step 2
|
||||
|
||||
The pattern ensures that a user's request eventually succeeds during less-than-ideal situations where transient failures would otherwise result in immediate and frequent failures. See open source implementations such as [java-design-patterns][6] and [transient-fault-handling-application-block][7] for details.
|
||||
|
||||
### Throttling pattern
|
||||
|
||||
We need to protect our services against clients that are overutilizing our solution or have gone rogue due to a system or logic failure. Like a four-lane tunnel servicing a six-lane freeway, we must manage the flow of requests (cars) and throttle endpoints (lanes) that are exceeding the maximum throughput (tunnel).
|
||||
|
||||
![Throttling pattern][8]
|
||||
|
||||
**Pseudocode**
|
||||
|
||||
Increment request_count
|
||||
// Limit – Maximum requests within an interval
|
||||
// Degrade – Fail with “slow down” error or pause operation
|
||||
If (request_count > limit) **degrade** service
|
||||
**Call** the [micro] service
|
||||
|
||||
The pattern helps us meet service level agreements, prevent a single user from overutilizing the system, optimize request flows, and deal with bursts of unexpected requests. One of the reasons we need to increase the delay between retries in the previous pattern is to ensure that we do not inadvertently exceed the throughput of the system and trigger degradation of service. See open source implementations such as [WebApiThrottle][9] and [Core.Throttling][10] for more details.
|
||||
|
||||
### Circuit breaker pattern
|
||||
|
||||
Like circuit breakers in your home, the circuit breaker pattern is your last defense. While the retry pattern helps to autocorrect brief transient faults, this pattern is more suited for transient faults that take a longer period to resolve. When dealing with network or service outages, such as the [Rough Patch][2] event, retrying a failing service operation could worsen the situation, lead to cascading failures, and eventually trigger a solution meltdown. The hypothesis of the circuit breaker pattern is that the failed service call is likely to succeed if (and only if) it is automatically retried after a significant delay.
|
||||
|
||||
Like when you stagger into your basement in the dark to find your circuit breaker cabinet, you are allowing the electrical system and potential static charges to recover before you flip the switch.
|
||||
|
||||
![Circuit breaker pattern][11]
|
||||
|
||||
**Pseudocode**
|
||||
|
||||
// Circuit breaker has not tripped
|
||||
If (circuit_state == open)
|
||||
|
||||
**Call** the [micro] service
|
||||
If (fail) fail_count++
|
||||
If (fail_count > limit) circuit_state = **closed**
|
||||
|
||||
// Circuit breaker tripped
|
||||
Else
|
||||
|
||||
If (circuit_state == closed) Start Timer
|
||||
|
||||
// Call back for timer event
|
||||
On Timer timeout
|
||||
|
||||
**Call** the [micro] service
|
||||
If (success) circuit_state == **open**
|
||||
|
||||
See open source implementations such as [Hystrix][12], [circuit-breaker][13], and [Polly][14] for more details.
|
||||
|
||||
### Don't fear faults
|
||||
|
||||
Remember to include unit and integration tests for all known faults and implemented handling patterns. Your unit tests must validate that your solution reacts appropriately when your fault-handling logic is triggered. On the other hand, your integration tests must simulate resilient faults to verify that your solution of collective services can deal with the fault effectively. You can simulate services, transient faults, and degrading services by using service virtualization such as [Hoverfly][15]. Your stakeholders will not be amused if your solution and associated fault handling patterns fail to deliver the promise of self-healing and avoidance of catastrophic meltdowns.
|
||||
|
||||
So, faults, like failures, are a [feature in blameless DevOps][16] and we should [not fear them][17]. To remain competitive, we must raise the quality bar of our infrastructures, solutions, and accountability to detect, remediate at the root-cause level, and self-correct to maintain an acceptable service level.
|
||||
|
||||
For example, in the following illustration, microservice #7 has imploded, triggering circuit breakers and traffic throttling and allowing the system to recover while continuing to service the users. What is evident from this simple illustration is that the combination of faults and the difficulty of dealing with them can become complex at the flip of a switch of a feature flag.
|
||||
|
||||
![Transient fault example][18]
|
||||
|
||||
These and other patterns are powerful allies for one of the [core values of a healthy DevOps mindset][19] to "_improve beyond the limits of today's processes—strive to always innovate and improve beyond repeatable processes and frameworks._" They help us raise the quality bar and continuously deliver business value and delight our stakeholders.
|
||||
|
||||
* * *
|
||||
|
||||
_Special thanks to [Brent Reed][20] for his candid review and feedback that help us improve and share our insights._
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/19/9/transient-faults-devops
|
||||
|
||||
作者:[Willy-Peter Schaub][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/wpschaubhttps://opensource.com/users/wpschaubhttps://opensource.com/users/wpschaub
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/devop.png?itok=Yicb2nnZ (Bright gears connecting)
|
||||
[2]: https://aka.ms/bh-ff-sos
|
||||
[3]: https://aka.ms/vsar-ff-sos
|
||||
[4]: https://opensource.com/sites/default/files/uploads/handlingtransientfaults_1.jpg (transient fault handling patterns)
|
||||
[5]: https://opensource.com/sites/default/files/uploads/handlingtransientfaults_2.png (Retry pattern)
|
||||
[6]: https://github.com/iluwatar/java-design-patterns
|
||||
[7]: https://github.com/microsoftarchive/transient-fault-handling-application-block
|
||||
[8]: https://opensource.com/sites/default/files/uploads/handlingtransientfaults_3.png (Throttling pattern)
|
||||
[9]: https://github.com/stefanprodan/WebApiThrottle
|
||||
[10]: https://github.com/SharePoint/PnP/tree/master/Samples/Core.Throttling
|
||||
[11]: https://opensource.com/sites/default/files/uploads/handlingtransientfaults_4.png (Circuit breaker pattern)
|
||||
[12]: https://github.com/Netflix/Hystrix/wiki
|
||||
[13]: https://github.com/josephwilk/circuit-breaker
|
||||
[14]: https://github.com/App-vNext/Polly
|
||||
[15]: https://github.com/SpectoLabs/hoverfly
|
||||
[16]: https://opensource.com/article/19/8/failure-feature-blameless-devops
|
||||
[17]: https://opensource.com/article/19/8/why-fear-failure-silent-devops-virus
|
||||
[18]: https://opensource.com/sites/default/files/uploads/handlingtransientfaults_5.png (Transient fault example)
|
||||
[19]: https://agents-of-chaos.org/2019/05/12/five-essential-values-for-the-devops-mindset/
|
||||
[20]: https://opensource.com/users/brentaaronreed
|
||||
@@ -0,0 +1,120 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (A Virtual WAN: Moving closer to the enterprise)
|
||||
[#]: via: (https://www.networkworld.com/article/3438357/a-virtual-wan-moving-closer-to-the-enterprise.html)
|
||||
[#]: author: (Matt Conran https://www.networkworld.com/author/Matt-Conran/)
|
||||
|
||||
A Virtual WAN: Moving closer to the enterprise
|
||||
======
|
||||
Virtual WAN will radically change the telecom environment, including how circuits are procured and who procures them.
|
||||
BlueBay2014 / Getty Images
|
||||
|
||||
Microsoft has introduced a new virtual WAN as a competitive differentiator and is getting enough tracking that AWS and Google may follow. At present, Microsoft is the only company to offer a virtual WAN of this kind. This made me curious to discover the highs and lows of this technology. So I sat down with [Sorell Slaymaker][1], Principal Consulting Analyst at TechVision Research to discuss. The following is a summary of our discussion.
|
||||
|
||||
But before we proceed, let’s gain some understanding of the cloud connectivity.
|
||||
|
||||
Cloud connectivity has evolved over time. When the cloud was introduced about a decade ago, let’s say, if you were an enterprise, you would connect to what's known as a cloud service provider (CSP). However, over the last 10 years, many providers like Equinix have started to offer carrier-neutral collocations. Now, there is the opportunity to meet a variety of cloud companies in a carrier-neutral colocation. On the other hand, there are certain limitations as well as cloud connectivity.
|
||||
|
||||
[NEWSLETTERS: Get the latest tech news sent directly to your in-box][2]
|
||||
|
||||
Undoubtedly, carrier-neutral colocation has fetched many advantages. However, even with this enhanced and flexible connectivity model, the pain-point for the majority of cloud companies is still the network connectivity. The network presents a number of challenges. Firstly, it will slow you down and secondly, from a security perspective, it makes you susceptible to vulnerabilities.
|
||||
|
||||
### The connectivity transition
|
||||
|
||||
We are now entering into a new phase, taking the cloud connectivity to the next level. Primarily, the cloud is moving closer to the enterprise, as opposed to the enterprise moving closer to the cloud. So, where will this approach lead us to?
|
||||
|
||||
Eventually, we will see the removal of the CSP, where the connectivity is serviced directly into the enterprise. We have already witnessed this transition with AWS. AWS now allows the companies to run AWS infrastructure in their own private data centers. This, ultimately, enables the organization to connect the various VPCs together.
|
||||
|
||||
With this paradigm, the cloud meets the customer in the enterprise as opposed to the enterprise coming to the cloud, or to a carrier-neutral colocation. This will radically change the telecom environment; especially how circuits are procured and who procures them.
|
||||
|
||||
### Cloud connectivity
|
||||
|
||||
First, let’s recap some basics. The connectivity to any cloud can be done via the internet or a private direct connection. The internet is untrusted and public, where an IPsec tunnel is created. It may be cheap and quick to provision logical tunnels, but this comes with certain drawbacks, such as security, uptime, latency, packet loss and jitter.
|
||||
|
||||
All such hindrances can degrade the application’s performance severely. This can be critical to support the sensitive and hybrid applications requiring real-time backend on-premise communications. For direct connectivity, most cloud providers have a more stable solution rather than relying solely on the Internet.
|
||||
|
||||
For example, AWS has a product called AWS Direct Connect, whereas Microsoft has a product known as Azure ExpressRoute. Both products have the same end goal: cloud and on-premise endpoint connectivity that is not over the Internet.
|
||||
|
||||
With Microsoft's Azure ExpressRoute, you get a private connection with guaranteed service level agreement (SLA). It's like a natural extension to the on-premise data center that offers lower latency, higher throughput and better reliability than the Internet has to offer. However, there are some drawbacks to this mechanism.
|
||||
|
||||
Even though ExpressRoute provides a private connection, enforcing end-to-end QoS is quite challenging. How Microsoft would label the packet will be different from how the service providers label based on their standard MPLS links. The other challenge is the lack of efficient load balancing due to separate BGP domains. Since ExpressRoute is not delivered end-to-end, so you are basically doing a cross-connect or meeting the service provider at a point where there is already another BGP domain available.
|
||||
|
||||
As a result, if you want to do equal-cost multipath (ECMP), complex failover and dynamic routing around congestion and configurations can get complex. This surfaces the demand for a change. Since Microsoft is aware of this need, therefore, they are evolving this ExpressRoute into what they are calling as the “Azure Virtual WAN.” A virtual WAN, as you might expect, provides a massive scale during the software-defined connectivity.
|
||||
|
||||
### What the virtual WAN offers?
|
||||
|
||||
The Azure Virtual WAN brings together many Azure cloud connectivity services, such as site-to-site VPN and ExpressRoute into a single operational interface. Now connectivity can leverage the Azure backbone to connect the branches and enjoy the branch-to-VNet connectivity. We will learn more about the new connectivity options later. The virtual WAN is purposely designed to provide large-scale site-to-site connectivity. It is built to offer throughput, scalability and ease of use.
|
||||
|
||||
Microsoft has virtual WAN locations that connect to the Microsoft virtual network. This network consists of 130 connections in 50 countries. This pushes the cloud connectivity model closer to the edge. Therefore, if you are using Azure or Office 365, connectivity is closer, as compared to doing a global backhaul. Microsoft's primary objective is to be within 30 ms of the consumer.
|
||||
|
||||
Microsoft also gives the option to do hop-on and hop-off, so that you can use the Microsoft global backbone as your WAN. In the case of remote offices in different locations, you only need to provide local circuits to the Microsoft edge point in that country. This eliminates the need for purchasing large WAN circuits.
|
||||
|
||||
This significantly allows you to have a global WAN where you don't have to pay for the expensive WAN circuits between or within counties.
|
||||
|
||||
Virtual WAN offers the following advantages:
|
||||
|
||||
* **Integrated connectivity solutions in the hub-and-spoke:** You can automate the site-to-site configuration and connectivity between the on-premises sites and an Azure hub.
|
||||
* **Automated spoke setup and configuration:** You can connect your virtual networks and workloads to the Azure hub seamlessly.
|
||||
* **Intuitive troubleshooting:** You can see the end-to-end flow within Azure, and then use this information to take action when required
|
||||
|
||||
|
||||
|
||||
### The partners and virtual Hub
|
||||
|
||||
Typically, virtual WAN lets you connect and configure the branch devices to communicate with Azure. This can be done in two ways, either manually, or by using the provider devices offered through a virtual WAN partner.
|
||||
|
||||
The partner devices allow ease of use, simplification of connectivity and configuration management. The connectivity from the on-premise device is established in an automated way to the virtual hub. Fundamentally, a virtual hub is a Microsoft-managed virtual network.
|
||||
|
||||
### The global transit network
|
||||
|
||||
The virtual WAN helps in laying the foundation of a global transit network architecture by enabling ubiquitous, any-to-any connectivity between distributed VNets, sites, applications and users.
|
||||
|
||||
In the WAN architecture, Azure regions serve as hubs, from which you can choose to connect your branches. Once the branches are connected, you can leverage the Azure backbone to establish, for example, branch-to-VNet and branch-to-branch connectivity.
|
||||
|
||||
The virtual WAN supports the following; global transit connectivity paths, branch to VNets, branch to branch, the remote user to VNet, the remote user to branch, VNet to VNet by using VNet peering and ExpressRoute global reach.
|
||||
|
||||
### The WAN architecture
|
||||
|
||||
The architecture is based on a hub-and-spoke model where the Microsoft cloud-hosted network acts as the hub. This enables transitive connectivity between endpoints that may be distributed across different types of spokes.
|
||||
|
||||
A spoke can be a VNets, physical branch site, remote user and internet. Global transit network architecture enables any-to-any connectivity via a central network hub. Largely, this architecture eliminates or reduces the need for full-mesh or partial mesh connectivity models that are complex to build and maintain.
|
||||
|
||||
Routing control in mesh networks is easier to configure and maintain through the hub-and-spoke model. The Microsoft any-to-any connectivity enables an enterprise with globally distributed users, branches, data centers, VNets and applications to connect to each other through the Microsoft transit hub. In essence, it is this transit hub that acts as the global system.
|
||||
|
||||
Mainly, you can establish a virtual WAN by creating a single Virtual WAN hub in the region that has the largest number of spokes that can take the form of branches, VNets and users. Then you can connect the spokes that are in other regions of the hub. An alternative design would occur if the spokes are geographically distributed, you can also instantiate regional hubs and interconnect the hubs. The hubs are all part of the same virtual WAN, but the best part is that they can be associated with different regional policies.
|
||||
|
||||
### Virtual WAN SD-WAN capabilities
|
||||
|
||||
Currently, SD-WAN is not fully integrated. Microsoft offers SD-WAN services from a couple of SD-WAN vendors including Citrix, GloudGenix and 128 technologies as part of the overall virtual WAN offering.
|
||||
|
||||
Under this model, you could, for example, have a 1G connection to Azure and you can run the SD-WAN vendor software within the location. You can use that software to route to other Azure locations. Now since you are using the SD-WAN, you get all the SD-WAN services on top of the Microsoft virtual WAN i.e. route around congestion and another brownout. This is contrary to the typical protocol that routes only around blackouts.
|
||||
|
||||
Citrix WAN optimization features allow you to tune and configure the WAN to have more control as opposed to relying on the underlying network. Although, Citrix is very strong with WAN optimization, but it is IPsec based. Therefore, its overall scaling is eventually limited to the limitations of scaling IPsec. On the other hand, an SD-WAN offering from 128 technologies is not IPsec tunnel-based and doesn't have the overhead. Thence, it can more intelligently route traffic in a one-to-many vs tunnels that are point-to-point.
|
||||
|
||||
Regarding in-built security on the WAN backbone, Microsoft provides the connectivity to integrate the security solution according to your choice. If you want security to be over and above, you can service-chain a firewall vendor or leverage security in place of an SD-WAN service. The majority of SD-WAN players have layer 1 to layer 4 built into them. They don't have the proxies or the Layer 5 or higher than the security solutions that you get from security companies, such as Pao Alto but you always have the option to service-chain.
|
||||
|
||||
**This article is published as part of the IDG Contributor Network. [Want to Join?][3]**
|
||||
|
||||
Join the Network World communities on [Facebook][4] and [LinkedIn][5] to comment on topics that are top of mind.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.networkworld.com/article/3438357/a-virtual-wan-moving-closer-to-the-enterprise.html
|
||||
|
||||
作者:[Matt Conran][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://www.networkworld.com/author/Matt-Conran/
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://techvisionresearch.com/sorell-slaymaker/
|
||||
[2]: https://www.networkworld.com/newsletters/signup.html
|
||||
[3]: https://www.networkworld.com/contributor-network/signup.html
|
||||
[4]: https://www.facebook.com/NetworkWorld/
|
||||
[5]: https://www.linkedin.com/company/network-world
|
||||
@@ -0,0 +1,62 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (How 6G will work: Terahertz-to-fiber conversion)
|
||||
[#]: via: (https://www.networkworld.com/article/3438337/how-6g-will-work-terahertz-to-fiber-conversion.html)
|
||||
[#]: author: (Patrick Nelson https://www.networkworld.com/author/Patrick-Nelson/)
|
||||
|
||||
How 6G will work: Terahertz-to-fiber conversion
|
||||
======
|
||||
For 6G wireless to become a reality, it must overcome a few technical hurdles, such as connecting terahertz spectrum to hard, optical transmission lines. Researchers at the Karlsruhe Institute of Technology say they have solved the problem.
|
||||
Nelli Velichko / Getty Images
|
||||
|
||||
Upcoming 6G wireless, superseding 5G and arriving possibly by 2030, is envisaged to function at hundreds of gigabits per second. Slowly, the technical advances needed are being made.
|
||||
|
||||
A hole in the tech development thus far has been at the interface between terahertz spectrum and hard, optical transmission lines. How does one connect terahertz (THz), which is basically through-the-air spectrum found between microwave and infrared, to the transmission lines that will be needed for the longer-distance data sends? The curvature of the Earth, for one thing, limits line of sight, so hard-wiring is necessary for distances. Short distances, too, can be impeded by environmental obstructions: blocking by objects, even rain or fog, becomes more apparent the higher in spectrum one goes, as wavelengths get shorter.
|
||||
|
||||
Researchers at the Karlsruhe Institute of Technology (KIT) say they know how to make the fiber link. They say, in a [press release][1], that one must develop modulators that operate on plasmonic nanophotonics, which is nano-scale, light-trapping technology (in this case, made with silicon) that will “directly couple the receiver antenna to a glass fiber.” The radio becomes part of the cable, in other words. It will “enable terahertz connections with very high data rates. Several hundred gigabits per second are feasible,” the researchers say.
|
||||
|
||||
**Read also: [6G will achieve terabits-per-second speeds][2] | Get regularly scheduled insights: [Sign up for Network World newsletters][3] **
|
||||
|
||||
In tests, the research team demonstrated a terahertz link that was “seamlessly integrated” into fiber using a link at the terahertz receiver. They performed a terahertz-to-optical transmission rate of 50 gigabits per second. For comparison, current over-air wireless data rates with LTE technology and using radio are often around 20 megabits per second (Mbps)—nowhere near what the team produced. Verizon, now launching millimeter wave 5G in the U.S., [says typical speeds, for its fixed 5G service will be around 300 Mbps][4].
|
||||
|
||||
### Other 6G challenges
|
||||
|
||||
The fiber-terahertz connection in 6G, though, isn’t the only area that must be addressed over the next few years. [Spatial multiplexing also needs to be mastered at terahertz to get the kinds of throughputs desired][5], experts say. Spatial multiplexing is where individual data signals are beamed out in streams. Every bit of the bandwidth thus gets used and reused continually, introducing bandwidth efficiency.
|
||||
|
||||
Efficiency gains will also need to be obtained with more advanced MIMO antennas. That’s where antennas take advantage of multipath—signals sent over more than one route.
|
||||
|
||||
Penetration loss also needs to be addressed. That’s the difference between the signal strength as it enters a building or structure and air. The loss increases with higher frequencies, as terahertz is; however, the amount of loss is dependent on the material that needs penetrating. Clear glass, for example, has less penetration loss overall than drywall, for example. That means construction materials used for upcoming buildings could be reimagined with new materials science to take advantage of 6G data throughput.
|
||||
|
||||
**[ [Take this mobile device management course from PluralSight and learn how to secure devices in your company without degrading the user experience.][6] ]**
|
||||
|
||||
In March, [the FCC announced a new category of experimental spectrum licenses][7] for frequencies between 95 GHz and 3 THz. That’s so that telcos and scientists can work on the spectrum.
|
||||
|
||||
We think “6G will emerge around 2030,” Ari Pouttu, a professor at the University of Oulu and a 5G system architect, [told me when I met him in Finland last year][2]. “It will eventually offer terabits per second,” along with millionth-of-a-second (microsecond) latency.
|
||||
|
||||
Join the Network World communities on [Facebook][8] and [LinkedIn][9] to comment on topics that are top of mind.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.networkworld.com/article/3438337/how-6g-will-work-terahertz-to-fiber-conversion.html
|
||||
|
||||
作者:[Patrick Nelson][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://www.networkworld.com/author/Patrick-Nelson/
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: http://www.kit.edu/kit/english/pi_2019_095_technologies-for-the-sixth-generation-cellular-network.php
|
||||
[2]: https://www.networkworld.com/article/3305359/6g-will-achieve-terabits-per-second-speeds.html
|
||||
[3]: https://www.networkworld.com/newsletters/signup.html
|
||||
[4]: https://www.verizonwireless.com/support/5g-home-faqs/
|
||||
[5]: https://www.networkworld.com/article/3285112/get-ready-for-upcoming-6g-wireless-too.html
|
||||
[6]: https://pluralsight.pxf.io/c/321564/424552/7490?u=https%3A%2F%2Fwww.pluralsight.com%2Fcourses%2Fmobile-device-management-big-picture
|
||||
[7]: https://www.fcc.gov/document/fcc-opens-spectrum-horizons-new-services-technologies
|
||||
[8]: https://www.facebook.com/NetworkWorld/
|
||||
[9]: https://www.linkedin.com/company/network-world
|
||||
@@ -0,0 +1,118 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (How to use Terminator on Linux to run multiple terminals in one window)
|
||||
[#]: via: (https://www.networkworld.com/article/3436784/how-to-use-terminator-on-linux-to-run-multiple-terminals-in-one-window.html)
|
||||
[#]: author: (Sandra Henry-Stocker https://www.networkworld.com/author/Sandra-Henry_Stocker/)
|
||||
|
||||
How to use Terminator on Linux to run multiple terminals in one window
|
||||
======
|
||||
Providing an option for multiple GNOME terminals within a single window frame, Terminator lets you flexibly align your workspace to suit your needs.
|
||||
Sandra Henry-Stocker
|
||||
|
||||
If you’ve ever wished that you could line up multiple terminal windows and organize them in a single window frame, we may have some good news for you. The Linux **Terminator** can do this for you. No problemo!
|
||||
|
||||
### Splitting windows
|
||||
|
||||
Terminator will initially open like a terminal window with a single window. Once you mouse click within that window, however, it will bring up an options menu that gives you the flexibility to make changes. You can choose “**split horizontally**” or “**split vertically**” to split the window you are currently position in into two smaller windows. In fact, with these menu choices, complete with tiny illustrations of the resultant split (resembling **=** and **||**), you can split windows repeatedly if you like. Of course, if you split the overall window into more than six or nine sections, you might just find that they're too small to be used effectively.
|
||||
|
||||
**[ Two-Minute Linux Tips: [Learn how to master a host of Linux commands in these 2-minute video tutorials][1] ]**
|
||||
|
||||
Using ASCII art to illustrate the process of splitting windows, you might see something like this:
|
||||
|
||||
```
|
||||
+-------------------+ +-------------------+ +-------------------+
|
||||
| | | | | |
|
||||
| | | | | |
|
||||
| | ==> |-------------------| ==> |-------------------|
|
||||
| | | | | | |
|
||||
| | | | | | |
|
||||
+-------------------+ +-------------------+ +-------------------+
|
||||
Original terminal Split horizontally Split vertically
|
||||
```
|
||||
|
||||
Another option for splitting windows is to use control sequences like **Ctrl+Shift+e** to split a window vertically and **Ctrl+Shift+o** (“o" as in “open”) to split the screen horizontally.
|
||||
|
||||
Once Terminator has split into smaller windows for you, you can click in any window to use it and move from window to window as your work dictates.
|
||||
|
||||
### Maximizing a window
|
||||
|
||||
If you want to ignore all but one of your windows for a while and focus on just one, you can click in that window and select the "**Maximize**" option from the menu. That window will then grow to claim all of the space. Click again and select "**Restore all terminals**" to return to the multi-window display. **Ctrl+Shift+x** will toggle between the normal and maximized settings.
|
||||
|
||||
The window size indicators (e.g., 80x15) on window labels display the number of characters per line and the number of lines per window that each window provides.
|
||||
|
||||
### Closing windows
|
||||
|
||||
To close any window, bring up the Terminator menu and select **Close**. Other windows will adjust themselves to take up the space until you close the last remaining window.
|
||||
|
||||
### Saving your customized setup(s)
|
||||
|
||||
Setting up your customized terminator settings as your default once you've split your overall window into multiple segments is quite easy. Select **Preferences** from the pop-up menu and then **Layouts** from the tab along the top of the window that opens. You should then see **New Layout** listed. Just click on the **Save** option at the bottom and **Close** on the bottom right. Terminator will save your settings in **~/.config/terminator/config** and will then use this file every time you use it.
|
||||
|
||||
You can also enlarge your overall window by stretching it with your mouse. Again, if you want to retain the changes, select **Preferences** from the menu, **Layouts** and then **Save** and **Close** again.
|
||||
|
||||
### Choosing between saved configurations
|
||||
|
||||
If you like, you can set up multiple options for your Terminator window arrangements by maintaining a number of config files, renaming each afterwards (e.g., config-1, config-2) and then moving your choice into place as **~/.config/terminator/config** when you want to use that layout. Here's an example script for doing something like this script. It lets you choose between three pre-configured window arrangements:
|
||||
|
||||
```
|
||||
#!/bin/bash
|
||||
|
||||
PS3='Terminator options: '
|
||||
options=("Split 1" "Split 2" "Split 3" "Quit")
|
||||
select opt in "${options[@]}"
|
||||
do
|
||||
case $opt in
|
||||
"Split 1")
|
||||
config=config-1
|
||||
break
|
||||
;;
|
||||
"Split 2")
|
||||
config=config-2
|
||||
break
|
||||
;;
|
||||
"Split 3")
|
||||
config=config-3
|
||||
break
|
||||
;;
|
||||
*)
|
||||
exit
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
cd ~/.config/terminator
|
||||
cp config config-
|
||||
cp $config config
|
||||
cd
|
||||
terminator &
|
||||
```
|
||||
|
||||
You could give the options more meaningful names than "config-1" if that helps.
|
||||
|
||||
### Wrap-up
|
||||
|
||||
Terminator is a good choice for setting up multiple windows to work on related tasks. If you've never used it, you'll probably need to install it first with a command such as "sudo apt install terminator" or "sudo yum install -y terminator".
|
||||
|
||||
Hopefully, you will enjoy using Terminator. And, as another character of the same name might say, "I'll be back!"
|
||||
|
||||
Join the Network World communities on [Facebook][2] and [LinkedIn][3] to comment on topics that are top of mind.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.networkworld.com/article/3436784/how-to-use-terminator-on-linux-to-run-multiple-terminals-in-one-window.html
|
||||
|
||||
作者:[Sandra Henry-Stocker][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://www.networkworld.com/author/Sandra-Henry_Stocker/
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://www.youtube.com/playlist?list=PL7D2RMSmRO9J8OTpjFECi8DJiTQdd4hua
|
||||
[2]: https://www.facebook.com/NetworkWorld/
|
||||
[3]: https://www.linkedin.com/company/network-world
|
||||
381
sources/tech/20190911 10 Ansible modules you need to know.md
Normal file
381
sources/tech/20190911 10 Ansible modules you need to know.md
Normal file
@@ -0,0 +1,381 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (10 Ansible modules you need to know)
|
||||
[#]: via: (https://opensource.com/article/19/9/must-know-ansible-modules)
|
||||
[#]: author: (DirectedSoul https://opensource.com/users/directedsoulhttps://opensource.com/users/markphttps://opensource.com/users/rich-butkevichttps://opensource.com/users/jairojuniorhttps://opensource.com/users/marcobravohttps://opensource.com/users/johnsimcall)
|
||||
|
||||
10 Ansible modules you need to know
|
||||
======
|
||||
See examples and learn the most important modules for automating
|
||||
everyday tasks with Ansible.
|
||||
![Text editor on a browser, in blue][1]
|
||||
|
||||
[Ansible][2] is an open source IT configuration management and automation platform. It uses human-readable YAML templates so users can program repetitive tasks to happen automatically without having to learn an advanced programming language.
|
||||
|
||||
Ansible is agentless, which means the nodes it manages do not require any software to be installed on them. This eliminates potential security vulnerabilities and makes overall management smoother.
|
||||
|
||||
Ansible [modules][3] are standalone scripts that can be used inside an Ansible playbook. A playbook consists of a play, and a play consists of tasks. These concepts may seem confusing if you're new to Ansible, but as you begin writing and working more with playbooks, they will become familiar.
|
||||
|
||||
There are some modules that are frequently used in automating everyday tasks; those are the ones that we will cover in this article.
|
||||
|
||||
Ansible has three main files that you need to consider:
|
||||
|
||||
* **Host/inventory file:** Contains the entry of the nodes that need to be managed
|
||||
* **Ansible.cfg file:** Located by default at **/etc/ansible/ansible.cfg**, it has the necessary privilege escalation options and the location of the inventory file
|
||||
* **Main file:** A playbook that has modules that perform various tasks on a host listed in an inventory or host file
|
||||
|
||||
|
||||
|
||||
### Module 1: Package management
|
||||
|
||||
There is a module for most popular package managers, such as DNF and APT, to enable you to install any package on a system. Functionality depends entirely on the package manager, but usually these modules can install, upgrade, downgrade, remove, and list packages. The names of relevant modules are easy to guess. For example, the DNF module is [dnf_module][4], the old YUM module (required for Python 2 compatibility) is [yum_module][5], while the APT module is [apt_module][6], the Slackpkg module is [slackpkg_module][7], and so on.
|
||||
|
||||
Example 1:
|
||||
|
||||
|
||||
```
|
||||
\- name: install the latest version of Apache and MariaDB
|
||||
dnf:
|
||||
name:
|
||||
- httpd
|
||||
- mariadb-server
|
||||
state: latest
|
||||
```
|
||||
|
||||
This installs the Apache web server and the MariaDB SQL database.
|
||||
|
||||
#### Example 2:
|
||||
|
||||
|
||||
```
|
||||
\- name: Install a list of packages
|
||||
yum:
|
||||
name:
|
||||
- nginx
|
||||
- postgresql
|
||||
- postgresql-server
|
||||
state: present
|
||||
```
|
||||
|
||||
This installs the list of packages and helps download multiple packages.
|
||||
|
||||
### Module 2: Service
|
||||
|
||||
After installing a package, you need a module to start it. The [service module][8] enables you to start, stop, and reload installed packages; this comes in pretty handy.
|
||||
|
||||
#### Example 1:
|
||||
|
||||
|
||||
```
|
||||
\- name: Start service foo, based on running process /usr/bin/foo
|
||||
service:
|
||||
name: foo
|
||||
pattern: /usr/bin/foo
|
||||
state: started
|
||||
```
|
||||
|
||||
This starts the service **foo**.
|
||||
|
||||
#### Example 2:
|
||||
|
||||
|
||||
```
|
||||
\- name: Restart network service for interface eth0
|
||||
service:
|
||||
name: network
|
||||
state: restarted
|
||||
args: eth0
|
||||
```
|
||||
|
||||
This restarts the network service of the interface **eth0**.
|
||||
|
||||
### Module 3: Copy
|
||||
|
||||
The [copy module][9] copies a file from the local or remote machine to a location on the remote machine.
|
||||
|
||||
#### Example 1:
|
||||
|
||||
|
||||
```
|
||||
\- name: Copy a new "ntp.conf file into place, backing up the original if it differs from the copied version
|
||||
copy:
|
||||
src: /mine/ntp.conf
|
||||
dest: /etc/ntp.conf
|
||||
owner: root
|
||||
group: root
|
||||
mode: '0644'
|
||||
backup: yes
|
||||
```
|
||||
|
||||
#### Example 2:
|
||||
|
||||
|
||||
```
|
||||
\- name: Copy file with owner and permission, using symbolic representation
|
||||
copy:
|
||||
src: /srv/myfiles/foo.conf
|
||||
dest: /etc/foo.conf
|
||||
owner: foo
|
||||
group: foo
|
||||
mode: u=rw,g=r,o=r
|
||||
```
|
||||
|
||||
### Module 4: Debug
|
||||
|
||||
The [debug module][10] prints statements during execution and can be useful for debugging variables or expressions without having to halt the playbook.
|
||||
|
||||
#### Example 1:
|
||||
|
||||
|
||||
```
|
||||
\- name: Display all variables/facts known for a host
|
||||
debug:
|
||||
var: hostvars[inventory_hostname]
|
||||
verbosity: 4
|
||||
```
|
||||
|
||||
This displays all the variable information for a host that is defined in the inventory file.
|
||||
|
||||
#### Example 2:
|
||||
|
||||
|
||||
```
|
||||
\- name: Write some content in a file /tmp/foo.txt
|
||||
copy:
|
||||
dest: /tmp/foo.txt
|
||||
content: |
|
||||
Good Morning!
|
||||
Awesome sunshine today.
|
||||
register: display_file_content
|
||||
\- name: Debug display_file_content
|
||||
debug:
|
||||
var: display_file_content
|
||||
verbosity: 2
|
||||
```
|
||||
|
||||
This registers the content of the copy module output and displays it only when you specify verbosity as 2. For example:
|
||||
|
||||
|
||||
```
|
||||
`ansible-playbook demo.yaml -vv`
|
||||
```
|
||||
|
||||
### Module 5: File
|
||||
|
||||
The [file module][11] manages the file and its properties.
|
||||
|
||||
* It sets attributes of files, symlinks, or directories.
|
||||
* It also removes files, symlinks, or directories.
|
||||
|
||||
|
||||
|
||||
#### Example 1:
|
||||
|
||||
|
||||
```
|
||||
\- name: Change file ownership, group and permissions
|
||||
file:
|
||||
path: /etc/foo.conf
|
||||
owner: foo
|
||||
group: foo
|
||||
mode: '0644'
|
||||
```
|
||||
|
||||
This creates a file named **foo.conf** and sets the permission to **0644**.
|
||||
|
||||
#### Example 2:
|
||||
|
||||
|
||||
```
|
||||
\- name: Create a directory if it does not exist
|
||||
file:
|
||||
path: /etc/some_directory
|
||||
state: directory
|
||||
mode: '0755'
|
||||
```
|
||||
|
||||
This creates a directory named **some_directory** and sets the permission to **0755**.
|
||||
|
||||
### Module 6: Lineinfile
|
||||
|
||||
The [lineinfile module][12] manages lines in a text file.
|
||||
|
||||
* It ensures a particular line is in a file or replaces an existing line using a back-referenced regular expression.
|
||||
* It's primarily useful when you want to change just a single line in a file.
|
||||
|
||||
|
||||
|
||||
#### Example 1:
|
||||
|
||||
|
||||
```
|
||||
\- name: Ensure SELinux is set to enforcing mode
|
||||
lineinfile:
|
||||
path: /etc/selinux/config
|
||||
regexp: '^SELINUX='
|
||||
line: SELINUX=enforcing
|
||||
```
|
||||
|
||||
This sets the value of **SELINUX=enforcing**.
|
||||
|
||||
#### Example 2:
|
||||
|
||||
|
||||
```
|
||||
\- name: Add a line to a file if the file does not exist, without passing regexp
|
||||
lineinfile:
|
||||
path: /etc/resolv.conf
|
||||
line: 192.168.1.99 foo.lab.net foo
|
||||
create: yes
|
||||
```
|
||||
|
||||
This adds an entry for the IP and hostname in the **resolv.conf** file.
|
||||
|
||||
### Module 7: Git
|
||||
|
||||
The [git module][13] manages git checkouts of repositories to deploy files or software.
|
||||
|
||||
#### Example 1:
|
||||
|
||||
|
||||
```
|
||||
# Example Create git archive from repo
|
||||
\- git:
|
||||
repo: <https://github.com/ansible/ansible-examples.git>
|
||||
dest: /src/ansible-examples
|
||||
archive: /tmp/ansible-examples.zip
|
||||
```
|
||||
|
||||
#### Example 2:
|
||||
|
||||
|
||||
```
|
||||
\- git:
|
||||
repo: <https://github.com/ansible/ansible-examples.git>
|
||||
dest: /src/ansible-examples
|
||||
separate_git_dir: /src/ansible-examples.git
|
||||
```
|
||||
|
||||
This clones a repo with a separate Git directory.
|
||||
|
||||
### Module 8: Cli_command
|
||||
|
||||
The [cli_command module][14], first available in Ansible 2.7, provides a platform-agnostic way of pushing text-based configurations to network devices over the **network_cli connection** plugin.
|
||||
|
||||
#### Example 1:
|
||||
|
||||
|
||||
```
|
||||
\- name: commit with comment
|
||||
cli_config:
|
||||
config: set system host-name foo
|
||||
commit_comment: this is a test
|
||||
```
|
||||
|
||||
This sets the hostname for a switch and exits with a commit message.
|
||||
|
||||
#### Example 2:
|
||||
|
||||
|
||||
```
|
||||
\- name: configurable backup path
|
||||
cli_config:
|
||||
config: "{{ lookup('template', 'basic/config.j2') }}"
|
||||
backup: yes
|
||||
backup_options:
|
||||
filename: backup.cfg
|
||||
dir_path: /home/user
|
||||
```
|
||||
|
||||
This backs up a config to a different destination file.
|
||||
|
||||
### Module 9: Archive
|
||||
|
||||
The [archive module][15] creates a compressed archive of one or more files. By default, it assumes the compression source exists on the target.
|
||||
|
||||
#### Example 1:
|
||||
|
||||
|
||||
```
|
||||
\- name: Compress directory /path/to/foo/ into /path/to/foo.tgz
|
||||
archive:
|
||||
path: /path/to/foo
|
||||
dest: /path/to/foo.tgz
|
||||
```
|
||||
|
||||
#### Example 2:
|
||||
|
||||
|
||||
```
|
||||
\- name: Create a bz2 archive of multiple files, rooted at /path
|
||||
archive:
|
||||
path:
|
||||
- /path/to/foo
|
||||
- /path/wong/foo
|
||||
dest: /path/file.tar.bz2
|
||||
format: bz2
|
||||
```
|
||||
|
||||
### Module 10: Command
|
||||
|
||||
One of the most basic but useful modules, the [command module][16] takes the command name followed by a list of space-delimited arguments.
|
||||
|
||||
#### Example 1:
|
||||
|
||||
|
||||
```
|
||||
\- name: return motd to registered var
|
||||
command: cat /etc/motd
|
||||
register: mymotd
|
||||
```
|
||||
|
||||
#### Example 2:
|
||||
|
||||
|
||||
```
|
||||
\- name: Change the working directory to somedir/ and run the command as db_owner if /path/to/database does not exist.
|
||||
command: /usr/bin/make_database.sh db_user db_name
|
||||
become: yes
|
||||
become_user: db_owner
|
||||
args:
|
||||
chdir: somedir/
|
||||
creates: /path/to/database
|
||||
```
|
||||
|
||||
### Conclusion
|
||||
|
||||
There are tons of modules available in Ansible, but these ten are the most basic and powerful ones you can use for an automation job. As your requirements change, you can learn about other useful modules by entering **ansible-doc <module-name>** on the command line or refer to the [official documentation][17].
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/19/9/must-know-ansible-modules
|
||||
|
||||
作者:[DirectedSoul][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/directedsoulhttps://opensource.com/users/markphttps://opensource.com/users/rich-butkevichttps://opensource.com/users/jairojuniorhttps://opensource.com/users/marcobravohttps://opensource.com/users/johnsimcall
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/browser_blue_text_editor_web.png?itok=lcf-m6N7 (Text editor on a browser, in blue)
|
||||
[2]: https://www.ansible.com/
|
||||
[3]: https://docs.ansible.com/ansible/latest/user_guide/modules.html
|
||||
[4]: https://docs.ansible.com/ansible/latest/modules/dnf_module.html
|
||||
[5]: https://docs.ansible.com/ansible/latest/modules/yum_module.html
|
||||
[6]: https://docs.ansible.com/ansible/latest/modules/apt_module.html
|
||||
[7]: https://docs.ansible.com/ansible/latest/modules/slackpkg_module.html
|
||||
[8]: https://docs.ansible.com/ansible/latest/modules/service_module.html
|
||||
[9]: https://docs.ansible.com/ansible/latest/modules/copy_module.html
|
||||
[10]: https://docs.ansible.com/ansible/latest/modules/debug_module.html
|
||||
[11]: https://docs.ansible.com/ansible/latest/modules/file_module.html
|
||||
[12]: https://docs.ansible.com/ansible/latest/modules/lineinfile_module.html
|
||||
[13]: https://docs.ansible.com/ansible/latest/modules/git_module.html#git-module
|
||||
[14]: https://docs.ansible.com/ansible/latest/modules/cli_command_module.html
|
||||
[15]: https://docs.ansible.com/ansible/latest/modules/archive_module.html
|
||||
[16]: https://docs.ansible.com/ansible/latest/modules/command_module.html
|
||||
[17]: https://docs.ansible.com/
|
||||
90
sources/tech/20190911 4 open source cloud security tools.md
Normal file
90
sources/tech/20190911 4 open source cloud security tools.md
Normal file
@@ -0,0 +1,90 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (4 open source cloud security tools)
|
||||
[#]: via: (https://opensource.com/article/19/9/open-source-cloud-security)
|
||||
[#]: author: (Alison NaylorAaron Rinehart https://opensource.com/users/asnaylorhttps://opensource.com/users/ansilvahttps://opensource.com/users/sethhttps://opensource.com/users/bretthunoldtcomhttps://opensource.com/users/aaronrineharthttps://opensource.com/users/marcobravo)
|
||||
|
||||
4 open source cloud security tools
|
||||
======
|
||||
Find and eliminate vulnerabilities in the data you store in AWS and
|
||||
GitHub.
|
||||
![Tools in a cloud][1]
|
||||
|
||||
If your day-to-day as a developer, system administrator, full-stack engineer, or site reliability engineer involves Git pushes, commits, and pulls to and from GitHub and deployments to Amazon Web Services (AWS), security is a persistent concern. Fortunately, open source tools are available to help your team avoid common mistakes that could cost your organization thousands of dollars.
|
||||
|
||||
This article describes four open source tools that can help improve your security practices when you're developing on GitHub and AWS. Also, in the spirit of open source, I've joined forces with three security experts—[Travis McPeak][2], senior cloud security engineer at Netflix; [Rich Monk][3], senior principal information security analyst at Red Hat; and [Alison Naylor][4], principal information security analyst at Red Hat—to contribute to this article.
|
||||
|
||||
We've separated each tool by scenario, but they are not mutually exclusive.
|
||||
|
||||
### 1\. Find sensitive data with Gitrob
|
||||
|
||||
You need to find any potentially sensitive information present in your team's Git repos so you can remove it. It may make sense for you to use tools that are focused towards attacking an application or a system using a red/blue team model, in which an infosec team is divided in two: an attack team (a.k.a. a red team) and a defense team (a.k.a. a blue team). Having a red team to try to penetrate your systems and applications is lots better than waiting for an adversary to do so. Your red team might try using [Gitrob][5], a tool that can clone and crawl through your Git repositories looking for credentials and sensitive files.
|
||||
|
||||
Even though tools like Gitrob could be used for harm, the idea here is for your infosec team to use it to find inadvertently disclosed sensitive data that belongs to your organization (such as AWS keypairs or other credentials that were committed by mistake). That way, you can get your repositories fixed and sensitive data expunged—hopefully before an adversary finds them. Remember to remove not only the affected files but [also their history][6]!
|
||||
|
||||
### 2\. Avoid committing sensitive data with git-secrets
|
||||
|
||||
While it's important to find and remove sensitive information in your Git repos, wouldn't it be better to avoid committing those secrets in the first place? Mistakes happen, but you can protect yourself from public embarrassment by using [git-secrets][7]. This tool allows you to set up hooks that scan your commits, commit messages, and merges looking for common patterns for secrets. Choose patterns that match the credentials your team uses, such as AWS access keys and secret keys. If it finds a match, your commit is rejected and a potential crisis averted.
|
||||
|
||||
It's simple to set up git-secrets for your existing repos, and you can apply a global configuration to protect all future repositories you initialize or clone. You can also use git-secrets to scan your repos (and all previous revisions) to search for secrets before making them public.
|
||||
|
||||
### 3\. Create temporary credentials with Key Conjurer
|
||||
|
||||
It's great to have a little extra insurance to prevent inadvertently publishing stored secrets, but maybe we can do even better by not storing credentials at all. Keeping track of credentials generally—including who has access to them, where they are stored, and when they were last rotated—is a hassle. However, programmatically generating temporary credentials can avoid a lot of those issues altogether, neatly side-stepping the issue of storing secrets in Git repos. Enter [Key Conjurer][8], which was created to address this need. For more on why Riot Games created Key Conjurer and how they developed it, read _[Key conjurer: our policy of least privilege][9]_.
|
||||
|
||||
### 4\. Apply least privilege automatically with Repokid
|
||||
|
||||
Anyone who has taken a security 101 course knows that least privilege is the best practice for role-based access control configuration. Sadly, outside school, it becomes prohibitively difficult to apply least-privilege policies manually. An application's access requirements change over time, and developers are too busy to trim back their permissions manually. [Repokid][10] uses data that AWS provides about identity and access management (IAM) use to automatically right-size policies. Repokid helps even the largest organizations apply least privilege automatically in AWS.
|
||||
|
||||
### Tools, not silver bullets
|
||||
|
||||
These tools are by no means silver bullets, but they are just that: tools! So, make sure you work with the rest of your organization to understand the use cases and usage patterns for your cloud services before trying to implement any of these tools or other controls.
|
||||
|
||||
Becoming familiar with the best practices documented by all your cloud and code repository services should be taken seriously as well. The following articles will help you do so.
|
||||
|
||||
**For AWS:**
|
||||
|
||||
* [Best practices for managing AWS access keys][11]
|
||||
* [AWS security audit guidelines][12]
|
||||
|
||||
|
||||
|
||||
**For GitHub:**
|
||||
|
||||
* [Introducing new ways to keep your code secure][13]
|
||||
* [GitHub Enterprise security best practices][14]
|
||||
|
||||
|
||||
|
||||
Last but not least, reach out to your infosec team; they should be able to provide you with ideas, recommendations, and guidelines for your team's success. Always remember: security is everyone's responsibility, not just theirs.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/19/9/open-source-cloud-security
|
||||
|
||||
作者:[Alison NaylorAaron Rinehart][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/asnaylorhttps://opensource.com/users/ansilvahttps://opensource.com/users/sethhttps://opensource.com/users/bretthunoldtcomhttps://opensource.com/users/aaronrineharthttps://opensource.com/users/marcobravo
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/cloud_tools_hardware.png?itok=PGjJenqT (Tools in a cloud)
|
||||
[2]: https://twitter.com/travismcpeak?lang=en
|
||||
[3]: https://github.com/rmonk
|
||||
[4]: https://www.linkedin.com/in/alperkins/
|
||||
[5]: https://github.com/michenriksen/gitrob
|
||||
[6]: https://help.github.com/en/articles/removing-sensitive-data-from-a-repository
|
||||
[7]: https://github.com/awslabs/git-secrets
|
||||
[8]: https://github.com/RiotGames/key-conjurer
|
||||
[9]: https://technology.riotgames.com/news/key-conjurer-our-policy-least-privilege
|
||||
[10]: https://github.com/Netflix/repokid
|
||||
[11]: https://docs.aws.amazon.com/general/latest/gr/aws-access-keys-best-practices.html
|
||||
[12]: https://docs.aws.amazon.com/general/latest/gr/aws-security-audit-guide.html
|
||||
[13]: https://github.blog/2019-05-23-introducing-new-ways-to-keep-your-code-secure/
|
||||
[14]: https://github.blog/2015-10-09-github-enterprise-security-best-practices/
|
||||
166
sources/tech/20190912 An introduction to Markdown.md
Normal file
166
sources/tech/20190912 An introduction to Markdown.md
Normal file
@@ -0,0 +1,166 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (An introduction to Markdown)
|
||||
[#]: via: (https://opensource.com/article/19/9/introduction-markdown)
|
||||
[#]: author: (Juan Islas https://opensource.com/users/xislashttps://opensource.com/users/mbbroberghttps://opensource.com/users/scottnesbitthttps://opensource.com/users/scottnesbitthttps://opensource.com/users/f%C3%A1bio-emilio-costahttps://opensource.com/users/don-watkinshttps://opensource.com/users/greg-phttps://opensource.com/users/marcobravohttps://opensource.com/users/alanfdosshttps://opensource.com/users/scottnesbitthttps://opensource.com/users/jamesf)
|
||||
|
||||
An introduction to Markdown
|
||||
======
|
||||
Write once and convert your text into multiple formats. Here's how to
|
||||
get started with Markdown.
|
||||
![Woman programming][1]
|
||||
|
||||
For a long time, I thought all the files I saw on GitLab and GitHub with an **.md** extension were written in a file type exclusively for developers. That changed a few weeks ago when I started using Markdown. It quickly became the most important tool in my daily work.
|
||||
|
||||
Markdown makes my life easier. I just need to add a few symbols to what I'm already writing and, with the help of a browser extension or an open source program, I can transform my text into a variety of commonly used formats such as ODT, email (more on that later), PDF, and EPUB.
|
||||
|
||||
### What is Markdown?
|
||||
|
||||
A friendly reminder from [Wikipedia][2]:
|
||||
|
||||
> Markdown is a lightweight markup language with plain text formatting syntax.
|
||||
|
||||
What this means to you is that by using just a few extra symbols in your text, Markdown helps you create a document with an explicit structure. When you take notes in plain text (in a notepad application, for example), there's nothing to indicate which text is meant to be bold or italic. In ordinary text, you might write a link as **<http://example.com>** one time, then as just **example.com**, and later **go to the website (example.com)**. There's no internal consistency.
|
||||
|
||||
But if you write the way Markdown prescribes, your text has internal consistency. Computers like consistency because it enables them to follow strict instructions without worrying about exceptions.
|
||||
|
||||
Trust me; once you learn to use Markdown, every writing task will be, in some way, easier and better than before. So let's learn it.
|
||||
|
||||
### Markdown basics
|
||||
|
||||
The following rules are the basics for writing in Markdown.
|
||||
|
||||
1. Create a text file with an **.md** extension (for example, **example.md**.) You can use any text editor (even a word processor like LibreOffice or Microsoft Word), as long as you remember to save it as a _text_ file.
|
||||
|
||||
|
||||
|
||||
![Names of Markdown files][3]
|
||||
|
||||
2. Write whatever you want, just as you usually do:
|
||||
|
||||
|
||||
```
|
||||
Lorem ipsum
|
||||
|
||||
Consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
|
||||
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
|
||||
Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
|
||||
|
||||
De Finibus Bonorum et Malorum
|
||||
|
||||
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo.
|
||||
Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt.
|
||||
|
||||
Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem.
|
||||
```
|
||||
|
||||
3. Make sure to place an empty line between paragraphs. That might feel unnatural if you're used to writing business letters or traditional prose, where paragraphs have only one new line and maybe even an indentation before the first word. For Markdown, an empty line (some word processors mark this with **¶**, called a Pilcrow symbol) guarantees a new paragraph is created when you convert it to another format like HTML.
|
||||
|
||||
4. Designate titles and subtitles. For the document's title, add a pound or hash (**#**) symbol and a space before the text (e.g., **# Lorem ipsum**). The first subtitle level uses two (**## De Finibus Bonorum et Malorum**), the next level gets three (**### Third Subtitle**), and so on. Note that there is a space between the pound sign and the first word.
|
||||
|
||||
|
||||
```
|
||||
# Lorem ipsum
|
||||
|
||||
Consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
|
||||
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
|
||||
Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
|
||||
|
||||
## De Finibus Bonorum et Malorum
|
||||
|
||||
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo.
|
||||
Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt.
|
||||
|
||||
Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem.
|
||||
```
|
||||
|
||||
5. If you want **bold** letters, just place the letters between two asterisks (stars) with no spaces: ****This will be in bold****.
|
||||
|
||||
|
||||
|
||||
|
||||
![Bold text in Markdown][4]
|
||||
|
||||
6. For _italics_, put the text between underline symbols with no spaces: **_I want this text to be in italics_**.
|
||||
|
||||
|
||||
|
||||
![Italics text in Markdown][5]
|
||||
|
||||
7. To insert a link (like [Markdown Tutorial][6]), put the text you want to link in brackets and the URL in parentheses with no spaces between them:
|
||||
**[Markdown Tutorial](<https://www.markdowntutorial.com/>)**.
|
||||
|
||||
|
||||
|
||||
![Hyperlinks in Markdown][7]
|
||||
|
||||
8. Blockquotes are written with a greater-than (**>**) symbol and a space before the text you want to quote: **> A famous quote**.
|
||||
|
||||
|
||||
|
||||
![Blockquote text in Markdown][8]
|
||||
|
||||
### Markdown tutorials and tip sheets
|
||||
|
||||
These tips will get you started writing in Markdown, but it has a lot more functions than just bold and italics and links. The best way to learn Markdown is to use it, but I recommend investing 15 minutes stepping through the simple [Markdown Tutorial][6] to practice these rules and learn a couple more.
|
||||
|
||||
Because modern Markdown is an amalgamation of many different interpretations of the idea of structured text, the [CommonMark][9] project defines a spec with a rigid set of rules to bring clarity to Markdown. It might be helpful to keep a [CommonMark-compliant cheatsheet][10] on hand when writing.
|
||||
|
||||
### What you can do with Markdown
|
||||
|
||||
Markdown lets you write anything you want—once—and transform it into almost any kind of format you want to use. The following examples show how to turn simple text written in MD into different formats. You don't need multiple formats of your text—you can start from a single source and then… rule the world!
|
||||
|
||||
1. **Simple note-taking:** You can write your notes in Markdown and, the moment you save them, the open source note application [Turtl][11] interprets your text file and shows you the formatted result. You can have your notes anywhere!
|
||||
|
||||
|
||||
|
||||
![Turtl application][12]
|
||||
|
||||
2. **PDF files:** With the [Pandoc][13] application, you can convert your Markdown into a PDF with one simple command: **pandoc <file.md> -o <file.pdf>**.
|
||||
|
||||
|
||||
|
||||
![Markdown text converted to PDF with Pandoc][14]
|
||||
|
||||
3. **Email:** You can also convert Markdown text into an HTML-formatted email by installing the browser extension [Markdown Here][15]. To use it, just select your Markdown text, use Markdown Here to translate it into HTML, and send your message using your favorite email client.
|
||||
|
||||
|
||||
|
||||
![Markdown text converted to email with Markdown Here][16]
|
||||
|
||||
### Start using it
|
||||
|
||||
You don't need a special application to use Markdown—you just need a text editor and the tips above. It's compatible with how you already write; all you need to do is use it, so give it a try.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/19/9/introduction-markdown
|
||||
|
||||
作者:[Juan Islas][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/xislashttps://opensource.com/users/mbbroberghttps://opensource.com/users/scottnesbitthttps://opensource.com/users/scottnesbitthttps://opensource.com/users/f%C3%A1bio-emilio-costahttps://opensource.com/users/don-watkinshttps://opensource.com/users/greg-phttps://opensource.com/users/marcobravohttps://opensource.com/users/alanfdosshttps://opensource.com/users/scottnesbitthttps://opensource.com/users/jamesf
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/programming-code-keyboard-laptop-music-headphones.png?itok=EQZ2WKzy (Woman programming)
|
||||
[2]: https://en.wikipedia.org/wiki/Markdown
|
||||
[3]: https://opensource.com/sites/default/files/uploads/markdown_names_md-1.png (Names of Markdown files)
|
||||
[4]: https://opensource.com/sites/default/files/uploads/markdown_bold.png (Bold text in Markdown)
|
||||
[5]: https://opensource.com/sites/default/files/uploads/markdown_italic.png (Italics text in Markdown)
|
||||
[6]: https://www.markdowntutorial.com/
|
||||
[7]: https://opensource.com/sites/default/files/uploads/markdown_link.png (Hyperlinks in Markdown)
|
||||
[8]: https://opensource.com/sites/default/files/uploads/markdown_blockquote.png (Blockquote text in Markdown)
|
||||
[9]: https://commonmark.org/help/
|
||||
[10]: https://opensource.com/downloads/cheat-sheet-markdown
|
||||
[11]: https://turtlapp.com/
|
||||
[12]: https://opensource.com/sites/default/files/uploads/markdown_turtl_02.png (Turtl application)
|
||||
[13]: https://opensource.com/article/19/5/convert-markdown-to-word-pandoc
|
||||
[14]: https://opensource.com/sites/default/files/uploads/markdown_pdf.png (Markdown text converted to PDF with Pandoc)
|
||||
[15]: https://markdown-here.com/
|
||||
[16]: https://opensource.com/sites/default/files/uploads/markdown_mail_02.png (Markdown text converted to email with Markdown Here)
|
||||
@@ -0,0 +1,208 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (How to fix common pitfalls with the Python ORM tool SQLAlchemy)
|
||||
[#]: via: (https://opensource.com/article/19/9/common-pitfalls-python)
|
||||
[#]: author: (Zach Todd https://opensource.com/users/zchtoddhttps://opensource.com/users/lauren-pritchetthttps://opensource.com/users/liranhaimovitchhttps://opensource.com/users/moshez)
|
||||
|
||||
How to fix common pitfalls with the Python ORM tool SQLAlchemy
|
||||
======
|
||||
Seemingly small choices made when using SQLAlchemy can have important
|
||||
implications on the object-relational mapping toolkit's performance.
|
||||
![A python with a package.][1]
|
||||
|
||||
Object-relational mapping ([ORM][2]) makes life easier for application developers, in no small part because it lets you interact with a database in a language you may know (such as Python) instead of raw SQL queries. [SQLAlchemy][3] is a Python ORM toolkit that provides access to SQL databases using Python. It is a mature ORM tool that adds the benefit of model relationships, a powerful query construction paradigm, easy serialization, and much more. Its ease of use, however, makes it easy to forget what is going on behind the scenes. Seemingly small choices made using SQLAlchemy can have important performance implications.
|
||||
|
||||
This article explains some of the top performance issues developers encounter when using SQLAlchemy and how to fix them.
|
||||
|
||||
### Retrieving an entire result set when you only need the count
|
||||
|
||||
Sometimes a developer just needs a count of results, but instead of utilizing a database count, all the results are fetched and the count is done with **len** in Python.
|
||||
|
||||
|
||||
```
|
||||
`count = len(User.query.filter_by(acct_active=True).all())`
|
||||
```
|
||||
|
||||
Using SQLAlchemy's **count** method instead will do the count on the server side, resulting in far less data sent to the client. Calling **all()** in the prior example also results in the instantiation of model objects, which can become expensive quickly, given enough rows.
|
||||
|
||||
Unless more than the count is required, just use the **count** method.
|
||||
|
||||
|
||||
```
|
||||
`count = User.query.filter_by(acct_active=True).count()`
|
||||
```
|
||||
|
||||
### Retrieving entire models when you only need a few columns
|
||||
|
||||
In many cases, only a few columns are needed when issuing a query. Instead of returning entire model instances, SQLAlchemy can fetch only the columns you're interested in. This not only reduces the amount of data sent but also avoids the need to instantiate entire objects. Working with tuples of column data instead of models can be quite a bit faster.
|
||||
|
||||
|
||||
```
|
||||
result = User.query.all()
|
||||
for user in result:
|
||||
print(user.name, user.email)
|
||||
```
|
||||
|
||||
Instead, select only what is needed using the **with_entities** method.
|
||||
|
||||
|
||||
```
|
||||
result = User.query.with_entities(User.name, User.email).all()
|
||||
for (username, email) in result:
|
||||
print(username, email)
|
||||
```
|
||||
|
||||
### Updating one object at a time inside a loop
|
||||
|
||||
Avoid using loops to update collections individually. While the database may execute a single update very quickly, the roundtrip time between the application and database servers will quickly add up. In general, strive for fewer queries where reasonable.
|
||||
|
||||
|
||||
```
|
||||
for user in users_to_update:
|
||||
user.acct_active = True
|
||||
db.session.add(user)
|
||||
```
|
||||
|
||||
Use the bulk update method instead.
|
||||
|
||||
|
||||
```
|
||||
query = User.query.filter(user.id.in_([user.id for user in users_to_update]))
|
||||
query.update({"acct_active": True}, synchronize_session=False)
|
||||
```
|
||||
|
||||
### Triggering cascading deletes
|
||||
|
||||
ORM allows easy configuration of relationships on models, but there are some subtle behaviors that can be surprising. Most databases maintain relational integrity through foreign keys and various cascade options. SQLAlchemy allows you to define models with foreign keys and cascade options, but the ORM has its own cascade logic that can preempt the database.
|
||||
|
||||
Consider the following models.
|
||||
|
||||
|
||||
```
|
||||
class Artist(Base):
|
||||
__tablename__ = "artist"
|
||||
|
||||
id = Column(Integer, primary_key=True)
|
||||
songs = relationship("Song", cascade="all, delete")
|
||||
|
||||
class Song(Base):
|
||||
__tablename__ = "song"
|
||||
|
||||
id = Column(Integer, primary_key=True)
|
||||
artist_id = Column(Integer, ForeignKey("artist.id", ondelete="CASCADE"))
|
||||
```
|
||||
|
||||
Deleting artists will cause the ORM to issue **delete** queries on the Song table, thus preventing the deletes from happening as a result of the foreign key. This behavior can become a bottleneck with complex relationships and a large number of records.
|
||||
|
||||
Include the **passive_deletes** option to ensure that the database is managing relationships. Be sure, however, that your database is capable of this. SQLite, for example, does not manage foreign keys by default.
|
||||
|
||||
|
||||
```
|
||||
`songs = relationship("Song", cascade="all, delete", passive_deletes=True)`
|
||||
```
|
||||
|
||||
### Relying on lazy loading when eager loading should be used
|
||||
|
||||
Lazy loading is the default SQLAlchemy approach to relationships. Building from the last example, this implies that loading an artist does not simultaneously load his or her songs. This is usually a good idea, but the separate queries can be wasteful if certain relationships always need to be loaded.
|
||||
|
||||
Popular serialization frameworks like [Marshmallow][4] can trigger a cascade of queries if relationships are allowed to load in a lazy fashion.
|
||||
|
||||
There are a few ways to control this behavior. The simplest method is through the relationship function itself.
|
||||
|
||||
|
||||
```
|
||||
`songs = relationship("Song", lazy="joined", cascade="all, delete")`
|
||||
```
|
||||
|
||||
This will cause a left join to be added to any query for artists, and as a result, the **songs** collection will be immediately available. Although more data is returned to the client, there are potentially far fewer roundtrips.
|
||||
|
||||
SQLAlchemy offers finer-grained control for situations where such a blanket approach can't be taken. The **joinedload()** function can be used to toggle joined loading on a per-query basis.
|
||||
|
||||
|
||||
```
|
||||
from sqlalchemy.orm import joinedload
|
||||
|
||||
artists = Artist.query.options(joinedload(Artist.songs))
|
||||
print(artists.songs) # Does not incur a roundtrip to load
|
||||
```
|
||||
|
||||
### Using the ORM for a bulk record import
|
||||
|
||||
The overhead of constructing full model instances becomes a major bottleneck when importing thousands of records. Imagine, for example, loading thousands of song records from a file where each song has first been converted to a dictionary.
|
||||
|
||||
|
||||
```
|
||||
for song in songs:
|
||||
db.session.add(Song(**song))
|
||||
```
|
||||
|
||||
Instead, bypass the ORM and use just the parameter binding functionality of core SQLAlchemy.
|
||||
|
||||
|
||||
```
|
||||
batch = []
|
||||
insert_stmt = Song.__table__.insert()
|
||||
for song in songs:
|
||||
if len(batch) > 1000:
|
||||
db.session.execute(insert_stmt, batch)
|
||||
batch.clear()
|
||||
batch.append(song)
|
||||
if batch:
|
||||
db.session.execute(insert_stmt, batch)
|
||||
```
|
||||
|
||||
Keep in mind that this method naturally skips any client-side ORM logic you might depend on, such as Python-based column defaults. While this method is faster than loading objects as full model instances, your database may have bulk loading methods that are faster. PostgreSQL, for example, has the **COPY** command that offers perhaps the best performance for loading large numbers of records.
|
||||
|
||||
### Calling commit or flush prematurely
|
||||
|
||||
There are many occasions when you need to associate a child record to its parent, or vice versa. One obvious way of doing this is to flush the session so that the record in question will be assigned an ID.
|
||||
|
||||
|
||||
```
|
||||
artist = Artist(name="Bob Dylan")
|
||||
song = Song(title="Mr. Tambourine Man")
|
||||
|
||||
db.session.add(artist)
|
||||
db.session.flush()
|
||||
|
||||
song.artist_id = artist.id
|
||||
```
|
||||
|
||||
Committing or flushing more than once per request is usually unnecessary and undesirable. A database flush involves forcing disk writes on the database server, and in most circumstances, the client will block until the server can acknowledge that the data has been written.
|
||||
|
||||
SQLAlchemy can track relationships and manage keys behind the scenes.
|
||||
|
||||
|
||||
```
|
||||
artist = Artist(name="Bob Dylan")
|
||||
song = Song(title="Mr. Tambourine Man")
|
||||
|
||||
artist.songs.append(song)
|
||||
```
|
||||
|
||||
### Wrapping up
|
||||
|
||||
I hope this list of common pitfalls can help you avoid these issues and keep your application running smoothly. As always, when diagnosing a performance problem, measurement is key. Most databases offer performance diagnostics that can help you pinpoint issues, such as the PostgreSQL **pg_stat_statements** module.
|
||||
|
||||
* * *
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/19/9/common-pitfalls-python
|
||||
|
||||
作者:[Zach Todd][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/zchtoddhttps://opensource.com/users/lauren-pritchetthttps://opensource.com/users/liranhaimovitchhttps://opensource.com/users/moshez
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/python_snake_file_box.jpg?itok=UuDVFLX- (A python with a package.)
|
||||
[2]: https://en.wikipedia.org/wiki/Object-relational_mapping
|
||||
[3]: https://www.sqlalchemy.org/
|
||||
[4]: https://marshmallow.readthedocs.io/en/stable/
|
||||
@@ -0,0 +1,102 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (An introduction to Virtual Machine Manager)
|
||||
[#]: via: (https://opensource.com/article/19/9/introduction-virtual-machine-manager)
|
||||
[#]: author: (Alan Formy-Duval https://opensource.com/users/alanfdosshttps://opensource.com/users/alanfdosshttps://opensource.com/users/bgamrathttps://opensource.com/users/marcobravo)
|
||||
|
||||
An introduction to Virtual Machine Manager
|
||||
======
|
||||
Virt-manager provides a full range of options for spinning up virtual
|
||||
machines on Linux.
|
||||
![A person programming][1]
|
||||
|
||||
In my [series][2] about [GNOME Boxes][3], I explained how Linux users can quickly spin up virtual machines on their desktop without much fuss. Boxes is ideal for creating virtual machines in a pinch when a simple configuration is all you need.
|
||||
|
||||
But if you need to configure more detail in your virtual machine, you need a tool that provides a full range of options for disks, network interface cards (NICs), and other hardware. This is where [Virtual Machine Manager][4] (virt-manager) comes in. If you don't see it in your applications menu, you can install it from your package manager or via the command line:
|
||||
|
||||
* On Fedora: **sudo dnf install virt-manager**
|
||||
* On Ubuntu: **sudo apt install virt-manager**
|
||||
|
||||
|
||||
|
||||
Once it's installed, you can launch it from its application menu icon or from the command line by entering **virt-manager**.
|
||||
|
||||
![Virtual Machine Manager's main screen][5]
|
||||
|
||||
To demonstrate how to create a virtual machine using virt-manager, I'll go through the steps to set one up for Red Hat Enterprise Linux 8.
|
||||
|
||||
To start, click **File** then **New Virtual Machine**. Virt-manager's developers have thoughtfully titled each step of the process (e.g., Step 1 of 5) to make it easy. Click **Local install media** and **Forward**.
|
||||
|
||||
![Step 1 virtual machine creation][6]
|
||||
|
||||
On the next screen, browse to select the ISO file for the operating system you want to install. (My RHEL 8 image is located in my Downloads directory.) Virt-manager automatically detects the operating system.
|
||||
|
||||
![Step 2 Choose the ISO File][7]
|
||||
|
||||
In Step 3, you can specify the virtual machine's memory and CPU. The defaults are 1,024MB memory and one CPU.
|
||||
|
||||
![Step 3 Set CPU and Memory][8]
|
||||
|
||||
I want to give RHEL ample room to run—and the hardware I'm using can accommodate it—so I'll increase them (respectively) to 4,096MB and two CPUs.
|
||||
|
||||
The next step configures storage for the virtual machine; the default setting is a 10GB disk image. (I'll keep this setting, but you can adjust it for your needs.) You can also choose an existing disk image or create one in a custom location.
|
||||
|
||||
![Step 4 Configure VM Storage][9]
|
||||
|
||||
Step 5 is the place to name your virtual machine and click Finish. This is equivalent to creating a virtual machine or a Box in GNOME Boxes. While it's technically the last step, you have several options (as you can see in the screenshot below). Since the advantage of virt-manager is the ability to customize a virtual machine, I'll check the box labeled **Customize configuration before install** before I click **Finish**.
|
||||
|
||||
Since I chose to customize the configuration, virt-manager opens a screen displaying a bunch of devices and settings. This is the fun part!
|
||||
|
||||
Here you have another chance to name the virtual machine. In the list on the left, you can view details on various aspects, such as CPU, memory, disks, controllers, and many other items. For example, I can click on **CPUs** to verify the change I made in Step 3.
|
||||
|
||||
![Changing the CPU count][10]
|
||||
|
||||
I can also confirm the amount of memory I set.
|
||||
|
||||
When installing a VM to run as a server, I usually disable or remove its sound capability. To do so, select **Sound** and click **Remove** or right-click on **Sound** and choose **Remove Hardware**.
|
||||
|
||||
You can also add hardware with the **Add Hardware** button at the bottom. This brings up the **Add New Virtual Hardware** screen where you can add additional storage devices, memory, sound, etc. It's like having access to a very well-stocked (if virtual) computer hardware warehouse.
|
||||
|
||||
![The Add New Hardware screen][11]
|
||||
|
||||
Once you are happy with your VM configuration, click **Begin Installation**, and the system will boot and begin installing your specified operating system from the ISO.
|
||||
|
||||
![Begin installing the OS][12]
|
||||
|
||||
Once it completes, it reboots, and your new VM is ready for use.
|
||||
|
||||
![Red Hat Enterprise Linux 8 running in VMM][13]
|
||||
|
||||
Virtual Machine Manager is a powerful tool for desktop Linux users. It is open source and an excellent alternative to proprietary and closed virtualization products.
|
||||
|
||||
Learn how Vagrant and Ansible can be used to provision virtual machines for web development.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/19/9/introduction-virtual-machine-manager
|
||||
|
||||
作者:[Alan Formy-Duval][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/alanfdosshttps://opensource.com/users/alanfdosshttps://opensource.com/users/bgamrathttps://opensource.com/users/marcobravo
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/computer_keyboard_laptop_development_code_woman.png?itok=vbYz6jjb (A person programming)
|
||||
[2]: https://opensource.com/sitewide-search?search_api_views_fulltext=GNOME%20Box
|
||||
[3]: https://wiki.gnome.org/Apps/Boxes
|
||||
[4]: https://virt-manager.org/
|
||||
[5]: https://opensource.com/sites/default/files/1-vmm_main_0.png (Virtual Machine Manager's main screen)
|
||||
[6]: https://opensource.com/sites/default/files/2-vmm_step1_0.png (Step 1 virtual machine creation)
|
||||
[7]: https://opensource.com/sites/default/files/3-vmm_step2.png (Step 2 Choose the ISO File)
|
||||
[8]: https://opensource.com/sites/default/files/4-vmm_step3default.png (Step 3 Set CPU and Memory)
|
||||
[9]: https://opensource.com/sites/default/files/6-vmm_step4.png (Step 4 Configure VM Storage)
|
||||
[10]: https://opensource.com/sites/default/files/9-vmm_customizecpu.png (Changing the CPU count)
|
||||
[11]: https://opensource.com/sites/default/files/11-vmm_addnewhardware.png (The Add New Hardware screen)
|
||||
[12]: https://opensource.com/sites/default/files/12-vmm_rhelbegininstall.png
|
||||
[13]: https://opensource.com/sites/default/files/13-vmm_rhelinstalled_0.png (Red Hat Enterprise Linux 8 running in VMM)
|
||||
@@ -1,263 +0,0 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (hello-wn)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: (heguangzhi)
|
||||
[#]: url: ( )
|
||||
[#]: subject: (How to Create and Use Swap File on Linux)
|
||||
[#]: via: (https://itsfoss.com/create-swap-file-linux/)
|
||||
[#]: author: (Abhishek Prakash https://itsfoss.com/author/abhishek/)
|
||||
|
||||
如何在 Linux 上创建和使用交换文件
|
||||
======
|
||||
|
||||
本教程讨论了 Linux 中交换文件的概念,为什么使用它以及它相对于传统交换分区的优势。您将学习如何创建交换文件和调整其大小。
|
||||
|
||||
### 什么是 Linux 的交换文件?
|
||||
|
||||
交换文件允许 Linux 将磁盘空间模拟为内存。当您的系统开始耗尽内存时,它会使用交换空间将内存的一些内容交换到磁盘空间上。这样释放了内存,为更重要的进程服务。当内存再次空闲时,它会从磁盘交换回数据。我建议[阅读这篇文章,了解更多关于交换在 Linux ][1]。
|
||||
|
||||
传统上,交换空间被用作磁盘上的一个独立分区。安装 Linux 时,只需创建一个单独的分区进行交换。但是这种趋势在最近几年发生了变化。
|
||||
|
||||
使用交换文件,您不再需要单独的分区。您在 root 下创建一个文件,并告诉您的系统将其用作交换空间就行了。
|
||||
|
||||
使用专用的交换分区,在许多情况下,调整交换空间的大小是一个噩梦,也是一项不可能完成的任务。但是有了交换文件,你可以随意调整它们的大小。
|
||||
|
||||
最新版本的 Ubuntu 和其他一些 Linux 发行版已经开始 [默认使用交换文件][2]。即使您没有创建交换分区,Ubuntu 也会自己创建一个 1GB 左右的交换文件。
|
||||
|
||||
让我们看看交换文件的更多信息。
|
||||
|
||||
![][3]
|
||||
|
||||
### 检查 Linux 的交换空间
|
||||
|
||||
在您开始添加交换空间之前,最好检查一下您的系统中是否已经有了交换空间。
|
||||
|
||||
你可以用[ free 命令在Linux][4]检查它。就我而言,我的[戴尔XPS][5]有 14GB 的交换容量。
|
||||
|
||||
```
|
||||
free -h
|
||||
total used free shared buff/cache available
|
||||
Mem: 7.5G 4.1G 267M 971M 3.1G 2.2G
|
||||
Swap: 14G 0B 14G
|
||||
```
|
||||
free 命令给出了交换空间的大小,但它并没有告诉你它是真正的交换分区还是交换文件。swapon 命令在这方面会更好。
|
||||
|
||||
```
|
||||
swapon --show
|
||||
NAME TYPE SIZE USED PRIO
|
||||
/dev/nvme0n1p4 partition 14.9G 0B -2
|
||||
```
|
||||
|
||||
如您所见,我有 14.9GB 的交换空间,它在一个单独的分区上。如果是交换文件,类型应该是文件而不是分区。
|
||||
|
||||
```
|
||||
swapon --show
|
||||
NAME TYPE SIZE USED PRIO
|
||||
/swapfile file 2G 0B -2
|
||||
```
|
||||
|
||||
如果您的系统上没有交换空间,它应该显示如下内容:
|
||||
|
||||
```
|
||||
free -h
|
||||
total used free shared buff/cache available
|
||||
Mem: 7.5G 4.1G 267M 971M 3.1G 2.2G
|
||||
Swap: 0B 0B 0B
|
||||
```
|
||||
|
||||
swapon 命令不会显示任何输出。
|
||||
|
||||
|
||||
### 在 Linux 上创建交换文件
|
||||
|
||||
如果您的系统没有交换空间,或者您认为交换空间不足,您可以在 Linux 上创建交换文件。您也可以创建多个交换文件。
|
||||
|
||||
[][6]
|
||||
|
||||
建议阅读 Ubuntu 14.04 的修复缺失系统设置[快速提示]
|
||||
|
||||
让我们看看如何在 Linux 上创建交换文件。我在本教程中使用 Ubuntu 18.04,但它也应该适用于其他 Linux 发行版本。
|
||||
|
||||
#### 步骤1:创建一个新的交换文件
|
||||
|
||||
首先,创建一个具有所需交换空间大小的文件。假设我想给我的系统增加 1GB 的交换空间。使用fallocate 命令创建大小为 1GB 的文件。
|
||||
|
||||
```
|
||||
sudo fallocate -l 1G /swapfile
|
||||
```
|
||||
|
||||
建议只允许 root 用户读写交换文件。当您尝试将此文件用于交换区域时,您甚至会看到类似“建议的不安全权限0644,0600”的警告。
|
||||
|
||||
```
|
||||
sudo chmod 600 /swapfile
|
||||
```
|
||||
|
||||
请注意,交换文件的名称可以是任意的。如果您需要多个交换空间,您可以给它任何合适的名称,如swap_file_1、swap_file_2等。它只是一个预定义大小的文件。
|
||||
|
||||
#### 步骤2:将新文件标记为交换空间
|
||||
|
||||
您需要告诉 Linux 系统该文件将被用作交换空间。你可以用 [mkswap][7] 工具做到这一点。
|
||||
|
||||
```
|
||||
sudo mkswap /swapfile
|
||||
```
|
||||
|
||||
您应该会看到这样的输出:
|
||||
|
||||
```
|
||||
Setting up swapspace version 1, size = 1024 MiB (1073737728 bytes)
|
||||
no label, UUID=7e1faacb-ea93-4c49-a53d-fb40f3ce016a
|
||||
```
|
||||
|
||||
#### 步骤3:启用交换文件
|
||||
|
||||
现在,您的系统知道文件交换文件可以用作交换空间。但是还没有完成。您需要启用交换文件,以便系统可以开始使用该文件作为交换。
|
||||
|
||||
```
|
||||
sudo swapon /swapfile
|
||||
```
|
||||
|
||||
现在,如果您检查交换空间,您应该会看到您的Linux系统识别并使用它作为交换区域:
|
||||
|
||||
```
|
||||
swapon --show
|
||||
NAME TYPE SIZE USED PRIO
|
||||
/swapfile file 1024M 0B -2
|
||||
```
|
||||
|
||||
#### 第四步:让改变持久化
|
||||
|
||||
迄今为止您所做的一切都是暂时的。重新启动系统,所有更改都将消失。
|
||||
|
||||
您可以通过将新创建的交换文件添加到 /etc/fstab 文件来使更改持久化。
|
||||
|
||||
对 /etc/fstab 文件进行任何更改之前,最好先进行备份。
|
||||
|
||||
```
|
||||
sudo cp /etc/fstab /etc/fstab.back
|
||||
```
|
||||
|
||||
如何将以下行添加到 /etc/fstab 文件的末尾:
|
||||
|
||||
```
|
||||
/swapfile none swap sw 0 0
|
||||
```
|
||||
|
||||
|
||||
您可以使用[命令行文本编辑器][8]手动执行,或者只使用以下命令:
|
||||
|
||||
```
|
||||
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
|
||||
```
|
||||
|
||||
现在一切都准备好了。即使在重新启动您的 Linux 系统后,您的交换文件也会被使用。
|
||||
|
||||
### 调整交换
|
||||
|
||||
交换参数决定了交换空间的使用频率。交换值的范围从0到100。较高的值意味着交换空间将被更频繁地使用。
|
||||
|
||||
Ubuntu 桌面的默认交 换度是 60,而服务器的默认交换度是 1。您可以使用以下命令检查swappiness:
|
||||
|
||||
```
|
||||
cat /proc/sys/vm/swappiness
|
||||
```
|
||||
|
||||
为什么服务器应该使用低交换率?因为交换比内存慢,为了获得更好的性能,应该尽可能多地使用内存。在服务器上,性能因素至关重要,因此交换性尽可能低。
|
||||
|
||||
[][9]
|
||||
|
||||
建议阅读如何在双引导区用另一个替换一个 Linux 发行版[保留主分区]
|
||||
|
||||
|
||||
您可以使用以下系统命令动态更改变:
|
||||
|
||||
```
|
||||
sudo sysctl vm.swappiness=25
|
||||
```
|
||||
|
||||
这种改变只是暂时的。如果要使其永久化,可以编辑 /etc/sysctl.conf 文件,并在文件末尾添加swappiness 值:
|
||||
|
||||
|
||||
```
|
||||
vm.swappiness=25
|
||||
```
|
||||
|
||||
### 在 Linux 上调整交换空间的大小
|
||||
|
||||
在 Linux 上有几种方法可以调整交换空间的大小。但是在您看到这一点之前,您应该了解一些关于它的事情。
|
||||
|
||||
当您要求系统停止将交换文件用于交换区域时,它会将所有数据(确切地说是页面)传输回内存。所以你应该有足够的空闲内存,然后再停止交换。
|
||||
|
||||
这就是为什么创建和启用另一个临时交换文件是一个好的做法原因。这样,当您交换原始交换区域时,您的系统将使用临时交换文件。现在您可以调整原始交换空间的大小。您可以手动删除临时交换文件或保持原样,下次启动时会自动删除。
|
||||
|
||||
如果您有足够的可用内存或者创建了临时交换空间,那就使您的原始交换文件下线。
|
||||
|
||||
```
|
||||
sudo swapoff /swapfile
|
||||
```
|
||||
|
||||
现在您可以使用 fallocate 命令来更改文件的大小。比方说,您将其大小更改为 2GB:
|
||||
|
||||
```
|
||||
sudo fallocate -l 2G /swapfile
|
||||
```
|
||||
|
||||
现在再次将文件标记为交换空间:
|
||||
|
||||
```
|
||||
sudo mkswap /swapfile
|
||||
```
|
||||
|
||||
并再次使交换文件上线:
|
||||
|
||||
```
|
||||
sudo swapon /swapfile
|
||||
```
|
||||
您也可以选择同时拥有多个交换文件。
|
||||
|
||||
### 删除 Linux 中的交换文件
|
||||
|
||||
您可能有不在 Linux 上使用交换文件的原因。如果您想删除它,该过程类似于您刚才看到的调整交换大小的过程。
|
||||
|
||||
首先,确保你有足够的空闲内存。现在使交换文件离线:
|
||||
|
||||
```
|
||||
sudo swapoff /swapfile
|
||||
```
|
||||
|
||||
下一步是从 /etc/fstab 文件中删除相应的条目。
|
||||
|
||||
最后,您可以删除文件来释放空间:
|
||||
|
||||
```
|
||||
sudo rm /swapfile
|
||||
```
|
||||
|
||||
**你交换吗?**
|
||||
|
||||
我想您现在已经很好地理解了 Linux 中的交换文件概念。现在,您可以根据需要轻松创建交换文件或调整它们的大小。
|
||||
|
||||
如果你对这个话题有什么要补充的或者有任何疑问,请在下面留下评论。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://itsfoss.com/create-swap-file-linux/
|
||||
|
||||
作者:[Abhishek Prakash][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/heguangzhi)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://itsfoss.com/author/abhishek/
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://itsfoss.com/swap-size/
|
||||
[2]: https://help.ubuntu.com/community/SwapFaq
|
||||
[3]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2019/08/swap-file-linux.png?resize=800%2C450&ssl=1
|
||||
[4]: https://linuxhandbook.com/free-command/
|
||||
[5]: https://itsfoss.com/dell-xps-13-ubuntu-review/
|
||||
[6]: https://itsfoss.com/fix-missing-system-settings-ubuntu-1404-quick-tip/
|
||||
[7]: http://man7.org/linux/man-pages/man8/mkswap.8.html
|
||||
[8]: https://itsfoss.com/command-line-text-editors-linux/
|
||||
[9]: https://itsfoss.com/replace-linux-from-dual-boot/
|
||||
Reference in New Issue
Block a user