Merge remote-tracking branch 'LCTT/master'

This commit is contained in:
Xingyu Wang 2021-01-13 08:31:50 +08:00
commit a7e7004a66
10 changed files with 847 additions and 92 deletions

View File

@ -1,46 +1,48 @@
[#]: collector: "lujun9972"
[#]: translator: "larryzju"
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
[#]: reviewer: "wxy"
[#]: publisher: "wxy"
[#]: url: "https://linux.cn/article-13006-1.html"
[#]: subject: "How to use Kubernetes resource quotas"
[#]: via: "https://opensource.com/article/20/12/kubernetes-resource-quotas"
[#]: author: "Mike Calizo https://opensource.com/users/mcalizo"
Kubernetes resource quota 使用指南
Kubernetes 资源配额使用指南
======
Resource quotas <ruby>控制<rt>control</rt></ruby>应用的 CPU 或内存使用情况,防止<ruby>资源被过量使用<rt>resource contention</rt></ruby><ruby>抢占<rt>land grabs</rt></ruby>
![Jars with food inside on a shelf][1]
> 资源配额控制应用的 CPU 或内存使用情况,防止资源被过量使用或被抢占。
![](https://img.linux.net.cn/data/attachment/album/202101/12/125309xr0kskdrqv33vn4q.jpg)
当 Kubernetes 集群运行过一段时间或者在被开发者大量使用后,[Kubernetes][2] 资源(例如 CPU 和内存)的控制的问题就会显现出来。而在大多情况下只有集群出问题后,我们才会意识到资源控制的重要性。
Kubernetes 部署过程如果没有能充分考虑到将来的扩展性,资源类问题将会非常常见,此类问题与集群的管理和部署团队的经验有关。
如果不加以合理控制,一个暴力的应用或者开发者可能影响到共享该集群的所有业务,大家可以因此相互埋怨、指责并保护性地抢占资源。这对于集群管理和开发人员都是非常难以处理的场景。
如果不加以合理控制,一个暴力的应用或者开发者可能影响到共享该集群的所有业务,大家因此相互埋怨、指责并保护性地抢占资源。这对于集群管理和开发人员都是非常难以处理的场景。
在 Kubernetes 环境中控制应用的计算资源使用有多种方式。大部分情况下,我们可以使用 resource quota 和 limit range。注意存储管理不在我们讨论范围之内存储管理可以通过 Persistent Volume 插件,以实现针对不同的存储控制需求。
在 Kubernetes 环境中控制应用的计算资源使用有多种方式。大部分情况下,我们可以使用“资源控制”和“限制范围”。注意存储管理不在我们讨论范围之内,存储管理可以通过<ruby>持久卷<rt>Persistent Volume</rt></ruby> 件,以实现针对不同的存储控制需求。
Resource quota 是一种控制 Kubernetes 计算资源的方法。本文告诉你如何使用 resource quota 来管理开发人员行为并控制应用的资源使用。
资源配额是一种控制 Kubernetes 计算资源的方法。本文告诉你如何使用该功能来管理开发人员行为并控制应用的资源使用。
### 什么是 resource quota
### 什么是资源配额
[resource quotas][3] 通过 `ResourceQuota` object 来为每个 namespace 设置资源配额,对以下对象类型的 CPU 和内存进行限制
简而言之,[资源配额][3] 提供了限制每个命名空间资源消耗的约束条件,它们只能在命名空间级别上应用,这意味着它们可以应用于计算资源,并限制命名空间内的对象数量。
* Pods
* Services
* Secrets
* Persistent Volume Claims (PVCs)
* ConfigMaps
Kubernetes资源配额通过 `ResourceQuota` 对象来为每个命名空间设置资源配额,对以下对象类型的 CPU 和内存进行限制:
Kubernetes 通过 request 和 limit 两个参数对 CPU 和内存进行限制(参考 [LimitRange][4] 文档)。前者表示容器最小被保证资源,后者表示容器最大可用资源。实际上最大可用资源还受限于其它容器的实际使用情况。
* <ruby>吊舱<rt>Pod</rt></ruby>
* <ruby>服务<rt>Service</rt></ruby>
* <ruby>机密信息<rt>Secret</rt></ruby>
* <ruby>持久卷断言<rt>Persistent Volume Claim</rt></ruby>PVC
* <ruby>配置映射<rt>ConfigMap</rt></ruby>
下一张图片解释 request 和 limit quota 的区别:
Kubernetes 通过 `request``limit` 两个参数对 CPU 和内存进行限制(参考 [LimitRange][4] 文档)。前者表示容器最小被保证资源,后者表示容器最大可用资源。实际上最大可用资源还受限于其它容器的实际使用情况。
下一张图片解释了配额中 `request``limit` 的区别:
![Requests and limits in Kubernetes resource quotas][5]
(Michael Calizo, [CC BY-SA 4.0][6])
下面我们就通过一个例子来说明如何设置 resource quota如何在 Kubernetes 的实现进行更好的资源控制。
下面我们就通过一个例子来说明如何设置资源配额来创建约束,将应用程序限制在某些资源上,它还展示了实现资源配额以获得对 Kubernetes 的控制的有用性。
### 准备环境
@ -48,26 +50,24 @@ Kubernetes 通过 request 和 limit 两个参数对 CPU 和内存进行限制(
* [Minikube][7] v1.14.2
* Fedora 33 操作系统
* 网络访问
* 互联网接入
如果你想在 Linux 机器上通过 Minikube 搭建 Kubernetes 测试环境,可以参考 Bryant Son [_Getting started with Minikube_][7] 一文。Window 或者 macOS 用户可以参考[这篇文章][8].
如果你想在 Linux 机器上通过 Minikube 搭建 Kubernetes 测试环境,可以参考 Bryant Son 的《[Minikube 入门][7]》 一文。Window 或者 macOS 用户可以参考[这篇文章][8]。
### 设置 resource quota
### 设置资源配额
这里我们仅展示 CPU quota 设置步骤,配置内存 quota 与之类似。
这里我们仅展示 CPU 配额设置步骤,配置内存配额或两者的组合与之类似。
在生产环境中CPU 是最需要被控制的资源,尤其是在多应用的场景下特别需要注意防止某些应用消耗太多 CPU 而影响到其它应用。
首先我们创建一个 namespace
首先我们创建一个命名空间,在其中设置 CPU 配额:
```bash
$ kubectl create namespace quota-test
namespace/quota-test created
```
准备 `cpu-quota.yaml` 文件,内容如下
准备 `cpu-quota.yaml` 文件,内容如下:
```yaml
apiVersion: v1
@ -80,16 +80,14 @@ spec:
    limits.cpu: "200m"
```
应用 CPU quota 到 Kubernetes 集群:
应用 CPU 配额到 Kubernetes 集群:
```bash
$ kubectl apply -f cpu-qouta.yaml
resourcequota/test-cpu-quota created
```
使用 `kubectl describe` 检查 quota 配置情况:
使用 `kubectl describe` 检查配额配置情况:
```bash
$ kubectl describe resourcequota/test-cpu-quota --namespace quota-test
@ -101,21 +99,20 @@ limits.cpu    0     200m
requests.cpu  0     100m
```
`Used resources` 列中显示了当前情况,该列值会随着 pod 的部署而变化。
`Used resources` 列中显示了当前情况,该列值会随着<ruby>吊舱<rt>Pod</rt></ruby>的部署而变化。
下面是我们来验证 quota 管理的场景。我们将在 namespace 下部署三个的 pods,为它们配置以不同的资源限制如下:
下面是我们来验证限额管理的场景。我们将在同一命名空间下部署三个不同的吊舱,为它们配置以不同的资源限制如下:
* **PodA:** 第一个被实例化,使用 50% 可用 CPU 资源
* **PodB:** 第二个被实例化,使用其余 50% 可用 CPU 资源
* **PodC:** 没有可用 CPU 资源,因此不会被部署
* PodA第一个被实例化,使用 50% 可用 CPU 资源
* PodB第二个被实例化,使用其余 50% 可用 CPU 资源
* PodC没有可用 CPU 资源,因此不会被部署
#### 部署 pods
**PodA:**
#### 部署吊舱
PodA
```bash
$ kubectl create -n quota-test -f- << EOF
$ kubectl create -n quota-test -f - << EOF
apiVersion: v1
kind: Pod
metadata:
@ -135,8 +132,7 @@ spec:
EOF
```
部署 PodA 后,再次查看 quota 描述信息中的 `Used CPU` 信息
部署 PodA 后,再次查看配额描述信息中的 `Used CPU` 信息:
```bash
$ kubectl describe resourcequota/test-cpu-quota --namespace quota-test
@ -148,11 +144,10 @@ limits.cpu    100m  200m
requests.cpu  50m   100m
```
**PodB:**
PodB
```bash
$ kubectl create -n quota-test -f- << EOF
$ kubectl create -n quota-test -f - << EOF
apiVersion: v1
kind: Pod
metadata:
@ -172,26 +167,24 @@ spec:
EOF
```
再次查看 CPU 资源使用,此时 PodB 启动后 CPU limit 已经达到上限:
再次查看 CPU 资源使用,此时 PodB 启动后 CPU 限制已经达到上限:
```bash
$ kubectl describe resourcequota/test-cpu-quota --namespace quota-test
Name:         test-cpu-quota
Namespace:    quota-test
Resource      Used  Hard
\--------      ----  ----
--------      ----  ----
limits.cpu    200m  200m
requests.cpu  100m  100m
```
**PodC:**
试着创建 PodC此时 CPU quota 已经被 PodA 和 PodB 用尽:
PodC
试着创建 PodC此时 CPU 配额已经被 PodA 和 PodB 用尽:
```bash
$ kubectl create -n quota-test -f- << EOF
$ kubectl create -n quota-test -f - << EOF
apiVersion: v1
kind: Pod
metadata:
@ -211,31 +204,30 @@ spec:
EOF
```
正我们期望,第三个 Pod 无法被启动quota 限制了Pod 的创建:
正我们期望,第三个 Pod 无法被启动,配额限制了吊舱的创建:
```
`Error from server (Forbidden): error when creating "STDIN": pods "podc" is forbidden: exceeded quota: test-cpu-quota, requested: limits.cpu=10m,requests.cpu=5m, used: limits.cpu=200m,requests.cpu=100m, limited: limits.cpu=200m,requests.cpu=100m`
Error from server (Forbidden): error when creating "STDIN": pods "podc" is forbidden: exceeded quota: test-cpu-quota, requested: limits.cpu=10m,requests.cpu=5m, used: limits.cpu=200m,requests.cpu=100m, limited: limits.cpu=200m,requests.cpu=100m
```
如我们的例子所示,定义合理的 resource quota 限制开发者行为对 Kubernetes 管理十分重要。
如我们的例子所示,定义合理的资源配额限制开发者行为对 Kubernetes 管理十分重要。
### 清理
删除刚才创建的 namespace `quota-test`:
删除刚才创建的命名空间 `quota-test`:
```bash
$ kubectl delete -n quota-test
```
### 规划 resource quota
### 规划资源配额
Kubernetes 中提供多种方式来控制资源的抢占和使用,合理的规划和配置 quota、limit range 等参数对保持集群的稳定性十分必要。
Kubernetes 中提供多种方式来控制资源的抢占和使用,合理的规划和配置配额、限制范围和其它原生参数对保持集群的稳定性十分必要。
你应该十分谨慎地控制计算资源的 resource quota特别是在商业生产应用环境。
你应该十分谨慎地控制计算资源的资源配额,特别是关键业务的生产应用环境。
在规划 resource quota 时,开发人员的参与很重要,需要他们预估并给出最合理的资源使用值。
在规划资源配额时,开发人员的参与很重要,需要他们预估并给出最合理的资源使用值。
--------------------------------------------------------------------------------
@ -244,7 +236,7 @@ via: https://opensource.com/article/20/12/kubernetes-resource-quotas
作者:[Mike Calizo][a]
选题:[lujun9972][b]
译者:[larryzju](https://github.com/larryzju)
校对:[校对者ID](https://github.com/校对者ID)
校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出

View File

@ -1,5 +1,5 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: translator: (stevenzdg988)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )

View File

@ -1,5 +1,5 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: translator: (stevenzdg988)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )

View File

@ -0,0 +1,108 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (15 favorite programming tutorials and insights)
[#]: via: (https://opensource.com/article/21/1/best-programming)
[#]: author: (Bryant Son https://opensource.com/users/brson)
15 favorite programming tutorials and insights
======
Whether you're new to programming or want to improve your existing
skills, there is an article in this list to help you. Take a look at
some of the best programming articles of 2020.
![Learning and studying technology is the key to success][1]
Happy new year! 2020 was one heck of an unusual year with the COVID-19 pandemic pushing us to stay at home and dramatically transforming our lifestyles. However, a time like this is also the best time to start picking up a new programming language or to level up your existing programming skillset. We begin with some light reading: **What is your first programming language?** and **Why developers like to code at night**. Next, we have articles about some specific programming languages like **C**, **D**, and **Awk**. Last, we provide some advanced programming language contents like **Real-Time Operating System (RTOS)**, **WebAssembly**, and **sharing data between C and Python**.
## [What was your first programming language?][2]
Chances are, not everyone remembers the very first thing they ate after they were born, but many programmers most likely recall their very first programming language. In this article, Opensource.com editor Lauren Pritchett took a survey asking the community this question. Go down your own memory lane by reading the responses to this question by other developers.
## [Why developers like to code at night][3]
Ever wonder why so many programmers stay late to crank out the lines of code that may turn into the next Google, Facebook, or Netflix? Quite surprisingly, many psychological studies exist that explain the productivity behind this common routine. Learn about it by reading this article by Matt Shealy.
## [Why I use open source technology for web development][4]
The Internet has been the driving force behind the popularity of open source programming, tools, and frameworks. But how can we explain this trend, and what are key characteristics of the web that inspire developers to continuously endorse open source technologies? See why Jim Hall believes that open source is the right way to build web applications.
## [5 steps to learn any programming language][5]
Learning a programming language may feel like a daunting task, but the process can be much easier with the right approach. Just as memorizing vocabulary and using correct grammar matter for learning a new spoken language, understanding syntax, functions, and data types matters for new programming languages. Learn about five steps you can apply when you decide to learn a new programming language.
## [An introduction to writing your own HTML web pages][6]
**Hypertext Markup Language (HTML)** is not a programming language, but it is the backbone behind the Internet as billions of people visit webpages built with HTML every day. HTML, interpreted by web browsers, is a markup language that anyone can easily learn with a few simple practices. Read how you can start writing your first web page by reading this article!
## [Learn the basics of programming with C][7]
Who says **C** programming is dead? **C** is still the father of many existing programming languages, libraries, and tools today, and industries have recently noticed the **C** programming language's rejuvenation. Its job demand has also exploded with AR/VR and the growth of the gaming industry. However, learning **C** programming is quite challenging. Get a jump start on your journey learning **C** programming by reading this article by Seth Kenlon.
## [What I learned while teaching C programming on YouTube][8]
There are many resources to learn programming languages, but the best result comes if one plans well, executes well, and makes the learning applicable. Most importantly, you need to have a passion for learning. See what Jim Hall learned by teaching the C programming language through his YouTube channel.
## [The feature that makes D my favorite programming language][8]
What comes after C? Yes, it is the letter D, and there is a programming language called **D** as well. Although it is not the most well-known programming language, **D** has features like _Universal Function Call Syntax (UFCS)_ that make it quite an interesting language to learn. Lawrence Aberba explains the feature and how you can use it, too.
## [The surprising thing you can do in the D programming language][9]
In another article, Lawrence talks about _nesting_ support in **D**, a feature that makes it stand out among other programming languages. Read what it is and explore how **D** delivers nesting functionality.
## [A practical guide to learning awk][10]
**Awk** is a programming language that is probably strange to many people, but learning **awk** can give you power that really shines in day-to-day Linux operations. By reading this article, you can learn how **awk** parses input and how functions are structured.
## [How to write a VS Code extension][11]
**Visual Studio Code (VS Code)** is an extremely popular cross-platform code editor created by Microsoft, and it is an open source project based on an MIT license. One of the great things about the editor is its extensibility through **VS Code extensions**. You don't have to be a rocket scientist to build your first extension! After reading this article, you will be on the path to becoming a VS Code extension master.
## [Customizing my open source PHP framework for web development][12]
**PHP** is often a neglected programming language hated by some programmer groups for a few reasons, such as it is very easy to produce bad code. However, Facebook, Wikipedia, Tumblr, and many websites were originally built with **PHP**, and it is still one of the most popular web programming languages out there. See how Wee Ben Sen used **PHP** framework **CodeIgniter** to create high-performance websites for numerous occasions and learn its key benefits.
## [Code your hardware using this open source RTOS][13]
**RTOS** stands for **Real-Time Operating System**. It is an open source operating system optimized for embedded hardware like CPUs and computer chips. By taking advantage of **RTOS**, a project can benefit from concurrency, modularity, and real-time scheduling. This article explains **RTOS** and the numerous benefits associated with this open source operating system.
## [Why everyone is talking about WebAssembly][14]
**WebAssembly** is a new type of code that runs in modern web browsers. It is a low-level assembly-like language with a compact binary format. **WebAssembly** runs with near-native performance and provides languages such as C/C++, C#, and Rust with a compilation target so that they can run on the web. **WebAssembly** has gained huge traction in the past few years due to the ever-growing popularity of JavaScript. Follow the history behind **WebAssembly** and learn what makes it so popular today.
## [Share data between C and Python with this messaging library][15]
Sharing data between two distinct programming languages may sound like a super challenging task. However, leveraging an open source tool like **ZeroMQ**, you can easily create a messaging interface that transmits the data across different layers. Learn how you can make one by reading this article.
As you can see, whether you are new to programming languages or want to grow your career further, there are learning opportunities for everyone. Let me know what you think by leaving a comment here.
--------------------------------------------------------------------------------
via: https://opensource.com/article/21/1/best-programming
作者:[Bryant Son][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/brson
[b]: https://github.com/lujun9972
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/studying-books-java-couch-education.png?itok=C9gasCXr (Learning and studying technology is the key to success)
[2]: https://opensource.com/article/20/8/first-programming-language
[3]: https://opensource.com/article/20/2/why-developers-code-night
[4]: https://opensource.com/article/20/4/open-source-web-development
[5]: https://opensource.com/article/20/10/learn-any-programming-language
[6]: https://opensource.com/article/20/4/build-websites
[7]: https://opensource.com/article/20/8/c-programming-cheat-sheet
[8]: https://opensource.com/article/20/7/d-programming
[9]: https://opensource.com/article/20/8/nesting-d
[10]: https://opensource.com/article/20/9/awk-ebook
[11]: https://opensource.com/article/20/6/vs-code-extension
[12]: https://opensource.com/article/20/5/codeigniter
[13]: https://opensource.com/article/20/6/open-source-rtos
[14]: https://opensource.com/article/20/1/webassembly
[15]: https://opensource.com/article/20/3/zeromq-c-python

View File

@ -0,0 +1,58 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (3 email rules to live by in 2021)
[#]: via: (https://opensource.com/article/21/1/email-rules)
[#]: author: (Kevin Sonney https://opensource.com/users/ksonney)
3 email rules to live by in 2021
======
Email is not instant messaging. Prevent email from being a constant
interruption by following these rules.
![email or newsletters via inbox and browser][1]
In prior years, this annual series covered individual apps. This year, we are looking at all-in-one solutions in addition to strategies to help in 2021. Welcome to day 2 of 21 Days of Productivity in 2021.
Like many of us, I have a love/hate relationship with email. Email was one of the earliest means of communication on the proto-internet, corporate LANs, and the dial-up BBS ecosystem. Email was, and still is, one of the primary means of electronic correspondence. It is used for business communications, commerce, notifications, collaboration, and a pile of useful things.
![Mutt email client][2]
Mutt email client,  [CC BY-SA 4.0][3] by Kevin Sonney
Many people have an incorrect perception of email. Email is not an instant messaging platform. It can seem like email is instant messaging sometimes when a person can send a message, have it show up on the other side of the world almost immediately, and then have a response in minutes. Because of this, we can fall into a mindset that we need to have our email program active at all times, and as soon as something comes in, we need to look at it and respond to it right now.
Email was designed around the principle that a person sends a message, and the recipient responds to it when they can. Yes, there are flags for high priority and urgent emails, and our email programs have notifications to tell us when new mail arrives, but they really weren't meant to cause the stress they do for many people today.
![So many emails][4]
So. Many. Emails., [CC BY-SA 4.0][3] by Kevin Sonney
It is generally said that for every interruption a person receives, it requires at least 15 minutes for their thought process to re-focus on the interrupted task. It has become common in the workplace (and at home!) to let email be one of those interruptions. It doesn't need to be, nor was it designed to be. I have adopted a couple of rules to prevent email from being an interruption that keeps me from getting things done.
**Rule 1**: Email is not an alert platform. It is common for people in technology to configure monitoring and alerting platforms send all the notifications to email. I have encountered this at almost every workplace I have been in for the last 15 years and I spend the first several months changing it. There are many good platforms and services to manage alerts. Email is not one of them.
**Rule 2**: Do not expect a reply for at least 24 hours. How many of us have received a phone call asking if we have received an email yet, and asking if we have any questions about it? I know I have. Work to set expectations in the workplace, or with people you frequently email, that responses will sometimes be quick, and sometimes not. If something is truly urgent, they should use some other method of communication.
**Rule 3**: Check email every few hours, not constantly. I admit this one is difficult but it brings me the most peace of mind. When I am working or trying to focus on something like writing, I close my email program (or browser tab) and ignore it until I am done. No notifications, no indicators that 20 new messages are waiting, no interruptions. It took some effort to get over the FOMO (Fear Of Missing Out) when I started doing this, but that has gotten easier over time. I find that when I do open up my email again, I can focus on it and not worry about what I could or should be doing instead.
Hopefully, these three rules can help you as much as they have helped me. In the upcoming days, I'll have more things that have helped me handle my email.
--------------------------------------------------------------------------------
via: https://opensource.com/article/21/1/email-rules
作者:[Kevin Sonney][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/ksonney
[b]: https://github.com/lujun9972
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/newsletter_email_mail_web_browser.jpg?itok=Lo91H9UH (email or newsletters via inbox and browser)
[2]: https://opensource.com/sites/default/files/pictures/mutt-email-client.png (Mutt email client)
[3]: https://creativecommons.org/licenses/by-sa/4.0/
[4]: https://opensource.com/sites/default/files/pictures/so-many-emails.png (So many emails)

View File

@ -0,0 +1,77 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (8 tips for the Linux command line)
[#]: via: (https://opensource.com/article/21/1/linux-commands)
[#]: author: (Jim Hall https://opensource.com/users/jim-hall)
8 tips for the Linux command line
======
Take advantage of all of the powers the almighty Linux command line has
to offer.
![Terminal command prompt on orange background][1]
The Linux command line provides a great deal of flexibility. Whether you are managing a server or launching a terminal window on a desktop system, the command line brings with it an extensive toolkit to update files, tweak system performance, and manage processes. The command line is where it's at.
Testifying to the command line's popularity, Opensource.com publishes many excellent articles about how to get the most out of your system. The following were some of Opensource.com's most-read articles about Linux commands in 2020:
### [Make Bash history more useful with these tips][2]
Bash is the default command line shell on most Linux systems. Seth Kenlon wrote this guide to help you with your Bash **history**. Manipulating history is usually less dangerous than it sounds, especially when you're curating it with a purpose in mind. Tell Bash what you want it to remember—or even rewrite history by deleting entries you don't want or need. Use your history sessions as required, and exercise your power over history wisely.
### [How I balance features and performance in my Linux terminal][3]
Ricardo Gerardi is a big fan of command line applications and spends a lot of his time working in a terminal. Ricardo invested some time to make the command line a pleasant environment to work in. Learn how to customize terminal apps, themes, and the prompt to create a feature-rich terminal that's easy on system resources.
### [Drop Bash for the fish shell to get beautiful defaults][4]
Matt Broberg recently let go of the default command line interpreter, Bash, in favor of fish, which proudly markets itself as "a command line shell for the '90s." The fish-themed "friendly interactive shell" creates a more enjoyable experience on the command line. Read Matt's article to learn more about how to get the most out of fish. If you're looking to move away from tinkering with your terminal, focus more on code, and have a more beautiful default shell, give fish a try.
### [10 ways to analyze binary files on Linux][5]
We work with binaries daily, yet we understand so little about them. Linux provides a rich set of tools that makes analyzing binaries a breeze! These simple commands and tools can help you sail through the task of analyzing binary files. Whatever your job role, knowing the basics about these tools will help you understand your Linux system better. Gaurav Kamathe covers some of the most popular Linux tools and commands to manage binaries, including **file**, **nm**, **strings**, and **hexdump**.
### [4 Markdown tools for the Linux command line][6]
When it comes to working with files formatted with Markdown, command line tools rule the roost. They're light, fast, powerful, and flexible, and most of them follow the Unix philosophy of doing one thing well. Scott Nesbitt reviews four command line utilities that can help you work more efficiently with Markdown files.
### [Improve Linux system performance with noatime][7]
Whenever I upgrade Linux on my home computer, I have a list of tasks I usually do. They've become habits over the years: I back up my files, wipe the system, reinstall from scratch, restore my files, then reinstall my favorite extra applications. I also make a few system tweaks. One tweak is **atime**, which is one of the three timestamps on every file on Linux. Turning off **atime** is a small but effective way to improve system performance. Here's what it is and why it matters.
### [Extend the life of your SSD drive with fstrim][8]
Over the past decade, solid-state drives (SSD) have brought about a new way of managing storage. SSDs have benefits like silent and cooler operation and a faster interface spec, compared to their elder spinning ancestors. Of course, new technology brings with it new methods of maintenance and management. Alan Formy-Duval wrote about a new **systemd** service to make your life easier when managing SSDs.
### [5 modern alternatives to essential Linux command line tools][9]
In our daily use of Linux/Unix systems, we use many command line tools to complete our work, and to help us understand and manage our systems better. Over the years, these tools have been modernized and ported to different systems. However, in general, they still follow their original idea, look, and feel. In recent years, the open source community has developed alternative tools that offer additional benefits. Ricardo Gerardi shows us how to gain new benefits by improving old command line tools with these five updated alternatives.
### Wrap up
Use these articles as a springboard to finding your own tips and tricks for the command line. Is there something missing from this list? Comment below, or better yet, submit an article of your own!
--------------------------------------------------------------------------------
via: https://opensource.com/article/21/1/linux-commands
作者:[Jim Hall][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/jim-hall
[b]: https://github.com/lujun9972
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/terminal_command_linux_desktop_code.jpg?itok=p5sQ6ODE (Terminal command prompt on orange background)
[2]: https://opensource.com/article/20/6/bash-history-control
[3]: https://opensource.com/article/20/7/performance-linux-terminal
[4]: https://opensource.com/article/20/3/fish-shell
[5]: https://opensource.com/article/20/4/linux-binary-analysis
[6]: https://opensource.com/article/20/3/markdown-apps-linux-command-line
[7]: https://opensource.com/article/20/6/linux-noatime
[8]: https://opensource.com/article/20/2/trim-solid-state-storage-linux
[9]: https://opensource.com/article/20/6/modern-linux-command-line-tools

View File

@ -0,0 +1,194 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (Server-sent events: a simple way to stream events from a server)
[#]: via: (https://jvns.ca/blog/2021/01/12/day-36--server-sent-events-are-cool--and-a-fun-bug/)
[#]: author: (Julia Evans https://jvns.ca/)
Server-sent events: a simple way to stream events from a server
======
hello! Yesterday I learned about a cool new way of streaming events from a server I hadnt heard of before: [server-sent events][1]! They seem like a simpler alternative to websockets if you only need to have the server send events.
Im going to talk about what theyre for, how they work, and a couple of bugs I ran into while using them yesterday.
### the problem: streaming updates from a server
Right now I have a web service that starts virtual machines, and the client polls the server until the virtual machine is up. But I didnt want to be doing polling.
Instead, I wanted to stream updates from the server. I told Kamal I was going to implement websockets to do this, and he suggested that server-sent events might be a simpler alternative!
I was like WHAT IS THAT??? It sounded like some weird fancy thing, and Id never heard of it before. So I looked it up.
### server-sent events are just HTTP requests
Heres how server-sent events work. I was SO DELIGHTED to learn that theyre just HTTP requests.
1. The client makes a GET request to (for example) `https://yoursite.com/events`
2. The client sets `Connection: keep-alive` so that we can have a long-lived connection
3. The server sets a `Content-Type: text/event-stream` header
4. The server starts sending events that look like this:
```
event: status
data: one
```
For example, heres what some server-sent events look like when I make a request with curl:
```
$ curl -N 'http://localhost:3000/sessions/15/stream'
event: panda
data: one
event: panda
data: two
event: panda
data: three
event: elephant
data: four
```
The server can send the events slowly over time, and the client can read them as they arrive. You can also put JSON in the events, like `data: {'name': 'ahmed'}`
The wire protocol is really simple (just set `event:` and `data:` and maybe `id:` and `retry:` if you want), so you dont need any fancy server libraries to implement server-sent events.
### the Javascript code is also super simple (just use `EventSource`)
Heres what the browser Javascript code to stream server-sent events looks like. (I got this example from the [MDN page on server-sent events][2])
You can either subscribe to all events, or have different handlers for different types of events. Here I have a handler that just receives events with type `panda` (like our server was sending in the previous section).
```
const evtSource = new EventSource("/sessions/15/stream", { withCredentials: true })
evtSource.addEventListener("panda", function(event) {
console.log("status", event)
});
```
### the client cant send updates in the middle
Unlike websockets, server-sent events dont allow a lot of back-and-forth communication. (its in the name the **server** sends all the events). The client makes one request at the beginning, and then the server sends a bunch of responses.
### if the HTTP connection ends, its automatically restarted
One big difference between making an HTTP request with `EventSource` and a regular HTTP request is this note from the MDN docs:
> By default, if the connection between the client and server closes, the connection is restarted. The connection is terminated with the .close() method.
This is pretty weird, and I was really thrown off it by it at first: I opened a connection, I closed it on the server side, and a couple of seconds later the client made another request to my streaming endpoint!
I think the idea here is that maybe the connection might get accidentally disconnected before its done, so the client automatically reopens it to prevent that.
So you have to explicitly close the connection by calling `.close()` if you dont want the client to keep retrying.
### there are a few other features
You can also set `id:` and `retry:` fields in server-sent events. It looks like if you set `id`s on the events the server sends then when reconnecting, the client will send a `Last-Event-ID` header with the last ID it received. Cool!
I found the [W3C page on server-sent events][3] to be surprisingly readable.
### two bugs I ran into while setting up server-sent events
I ran into a couple of problems using server-sent events with Rails that I thought were kinda interesting. One of them was actually caused by nginx, and the other one was caused by rails.
**problem 1: I couldnt pause in between sending events**
I had this weird bug where if I did:
```
def handler
# SSE is Rails' built in server-sent events thing
sse = SSE.new(response.stream, event: "status")
sse.write('event')
sleep 1
sse.write('another event')
end
```
It would write the first event, but not the second event. I was SO MYSTIFIED by this and went on a whole digression trying to understand how `sleep` in Ruby works. But Cass (another Recurser) pointed me to a [Stack Overflow question][4] where someone else had the same problem, which contained a surprising-to-me answer!
It turned out that the problem was that my Rails server was behind nginx, and that nginx seemingly by default uses HTTP/1.0 to make requests to upstreams by default (why? in 2021? really? Im sure theres a good reason, probably backwards compatibility or something).
So the client (nginx) would just close the connection after the first event sent by the server. I think the reason why it worked if I _didnt_ pause between sending the 2 events was basically that the server was racing with the client to send the second part of the response before the connection closed, and if I sent it fast enough then the server won the race.
Im not sure exactly why using HTTP/1.0 made the client close the connection (maybe because the server writes 2 newlines at the end of each event?), but because server-sent events are a pretty new thing its not that surprising that theyre not supported by HTTP/1.0 (which is Very Old).
Setting `proxy_http_version 1.1` fixed that problem. Hooray!
**problem 2: events were being buffered**
Once I sorted that out, I had a second problem. This one was actually super easy to debug because Cass had already suggested [this other stackoverflow answer][5] as a solution to the previous problem, and while that wasnt what was causing Problem 1, it DID explain Problem 2.
The problem was with this example code:
```
def handler
response.headers['Content-Type'] = 'text/event-stream'
# Turn off buffering in nginx
response.headers['X-Accel-Buffering'] = 'no'
sse = SSE.new(response.stream, event: "status")
10.times do
sse.write('event')
sleep 1
end
end
```
I expected it to return 1 event per second for 10 seconds, but instead it waited 10 seconds and returned 10 events all at once. Thats not how we want streaming to work!
This turned out to because the Rack ETag middleware wanted to calculate an ETag (a hash of the response), and to do that it needed to have the whole response. So I needed to disable ETag generation.
The Stack Overflow answer recommended disabling the Rack ETag middleware entirely, but I didnt want to do that so I went and looked at the [linked github issue][6].
That github issue suggested a workaround I could apply to just the streaming endpoint, which was to set the `Last-Modified` header, which apparently bypasses the ETag middleware for some reason.
So I set
```
headers['Last-Modified'] = Time.now.httpdate
```
and it worked!!!
I also turned off buffering in nginx by setting the header `X-Accel-Buffering: no`. Im not 100% sure I needed to do that but it seems safer.
### stack overflow is amazing
At first I was really 100% committed to debugging both of those bugs from first principles. Cass (another Recurser) pointed me to those two Stack Overflow threads and at first I was skeptical of the solutions those threads were suggesting (I thought “Im not using HTTP/1.0! And what does the ETag header have to do with anything??“).
But it turned out that I _was_ accidentally using HTTP/1.0, and that the Rack ETag middleware _was_ causing me problems.
So maybe the moral of that story is that sometimes computers interact in weird ways, other people have experienced computers interacting in the exact same weird ways in the past, and Stack Overflow sometimes has answers about why :)
I do think its important to not just randomly try things from Stack Overflow (which nobody was suggesting in this case of course!). For both of these I really had to think about them to understand what was happening and why changing those settings made sense.
### thats all!
Today Im going to keep working on implementing server-sent events, because I spent a lot of yesterday being distracted by the above bugs. Its always such a delight to learn about a new easy-to-use web technology that Id never heard of.
--------------------------------------------------------------------------------
via: https://jvns.ca/blog/2021/01/12/day-36--server-sent-events-are-cool--and-a-fun-bug/
作者:[Julia Evans][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://jvns.ca/
[b]: https://github.com/lujun9972
[1]: https://html.spec.whatwg.org/multipage/server-sent-events.html
[2]: https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events
[3]: https://html.spec.whatwg.org/multipage/server-sent-events.html#event-stream-interpretation
[4]: https://stackoverflow.com/questions/25660399/sse-eventsource-closes-after-first-chunk-of-data-rails-4-puma-nginx
[5]: https://stackoverflow.com/questions/63432012/server-sent-events-in-rails-not-delivered-asynchronously/65127528#65127528
[6]: https://github.com/rack/rack/issues/1619

View File

@ -0,0 +1,157 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (How to get Battery status notification when a battery is full or low)
[#]: via: (https://www.2daygeek.com/linux-low-full-charge-discharge-battery-notification/)
[#]: author: (Magesh Maruthamuthu https://www.2daygeek.com/author/magesh/)
How to get Battery status notification when a battery is full or low
======
Linux laptops are good for Nix users, but it often drains the battery.
I tried many Linux operating systems, but did not have a long battery life like Windows.
Charging a battery for a longer duration will damage your battery, so unplug the power cable when it is 100% charged.
There is no default application to notify when the battery charged or discharged, and you need to install a third-party application to notify you.
For this, I usually install the **[Battery Monitor][1]** app, but it was deprecated, so I created a shell script to get the notification.
Laptop battery charging and discharging status can be identified using the following two commands.
Using acpi command.
```
$ acpi -b
Battery 0: Discharging, 71%, 00:58:39 remaining
```
Using upower command.
```
$ upower -i /org/freedesktop/UPower/devices/battery_BAT0 | grep -w 'state|percentage' | awk '{print $2}'
discharging
64%
```
### Method-1: Shell script to send an alert when the battery level is above 95% or below 20%
This script runs in the background on startup and checks the battery status every minute and then sends a notification when the battery level is charged above 95% or discharged less than 20%.
The alert will not go off until your battery is over 20% or less than 95% charged.
```
$ sudo vi /opt/scripts/battery-status.sh
#!/bin/bash
while true
do
battery_level=`acpi -b | grep -P -o '[0-9]+(?=%)'`
if [ $battery_level -ge 95 ]; then
notify-send "Battery Full" "Level: ${battery_level}%"
paplay /usr/share/sounds/freedesktop/stereo/suspend-error.oga
elif [ $battery_level -le 20 ]; then
notify-send --urgency=CRITICAL "Battery Low" "Level: ${battery_level}%"
paplay /usr/share/sounds/freedesktop/stereo/suspend-error.oga
fi
sleep 60
done
```
Once the script is ready, set the executable permission.
```
$ sudo chmod +x /opt/scripts/battery-status.sh
```
Finally, add the script to the bottom of the user profile file. For system-wide, you need to add the script on the /etc/profile file.
```
$ vi /home/magi/.profile
/opt/scripts/battery-status.sh &
```
**[Reboot your Linux system][2]** to check this.
```
$ sudo reboot
```
### Method-2: Shell script to send a notification when the battery level is charged (above 95%) or discharged (below 20%)
This script is similar to the above script, but it is responsible with the AC adapter.
If your AC adapter is plugged in and the battery is charged above 95%, it will send a notification with a sound, but the notification will not stop until you unplug the AC adapter.
![][3]
If you unplug the AC adapter, you will never see the notification again until your battery charge drops to 20%.
![][3]
```
$ sudo vi /opt/scripts/battery-status-1.sh
#!/bin/bash
while true
do
export DISPLAY=:0.0
battery_level=`acpi -b | grep -P -o '[0-9]+(?=%)'`
if on_ac_power; then
if [ $battery_level -ge 95 ]; then
notify-send "Battery Full" "Level: ${battery_level}% "
paplay /usr/share/sounds/freedesktop/stereo/suspend-error.oga
fi
else
if [ $battery_level -le 20 ]; then
notify-send --urgency=CRITICAL "Battery Low" "Level: ${battery_level}%"
paplay /usr/share/sounds/freedesktop/stereo/suspend-error.oga
fi
fi
sleep 60
done
```
Once the script is ready, set the permission to execute.
```
$ sudo chmod +x /opt/scripts/battery-status-1.sh
```
Finally add the script to the bottom of the user **profile** file. For system-wide, you need to add the script on /etc/profile file.
```
$ vi /home/magi/.profile
/opt/scripts/battery-status-1.sh &
```
Restart your system to check this.
```
$ sudo reboot
```
**Ref:** [stackexchange][4]
--------------------------------------------------------------------------------
via: https://www.2daygeek.com/linux-low-full-charge-discharge-battery-notification/
作者:[Magesh Maruthamuthu][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.2daygeek.com/author/magesh/
[b]: https://github.com/lujun9972
[1]: https://www.2daygeek.com/category/battery-monitor/
[2]: https://www.2daygeek.com/6-commands-to-shutdown-halt-poweroff-reboot-the-linux-system/
[3]: data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7
[4]: https://unix.stackexchange.com/questions/60778/how-can-i-get-an-alert-when-my-battery-is-about-to-die-in-linux-mint

View File

@ -0,0 +1,169 @@
[#]: collector: (lujun9972)
[#]: translator: (stevenzdg988)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: subject: (Three SSH GUI Tools for Linux)
[#]: via: (https://www.linux.com/blog/learn/intro-to-linux/2018/11/three-ssh-guis-linux)
[#]: author: (Jack Wallen https://www.linux.com/users/jlwallen)
[#]: url: ( )
Linux 系统的三种 SSH 图形用户工具
======
![](https://www.linux.com/sites/lcom/files/styles/rendered_file/public/ssh.jpg?itok=3UcXhJt7)
在您作为 Linux 系统管理员的职业生涯中,您已经有机会使用 Secure ShellSSH远程访问 Linux 服务器或桌面系统。 在某些情况下,您会通过 SSH 一次性登录多个 Linux 服务器。 实际上Secure Shell 很可能是 Linux 工具箱中最常用的工具之一。 因此,您将希望操作尽可能高效。 对于许多系统管理员来说,没有什么比命令行更有效的了。 但是,有些用户确实更喜欢 GUI 工具,尤其是从一台桌面台式机远程连接到服务器上工作时。
如果您碰巧喜欢好的 GUI 工具,那么您会很想知道 Linux 上有一些出色的 SSH 图形工具。 将其与独特的终端窗口相结合,可以从同一窗口远程访问多台计算机,您便拥有了高效工作所需的一切。 让我们看以下这三个工具,找出其中一个(或多个)是否满足您的需求。
我将在 [Elementary OS][1] 上演示这些工具,但是大多数流行的发行版都可以使用它们。
### PuTTY
很长时间以来我们都了解 [PuTTY] [2]。 实际上PuTTY 是事实上的标准工具,用于通过 SSH 从 Windows 环境连接到 Linux 服务器。 但是 PuTTY 不仅适用于 Windows 。 实际上从标准存储库开始PuTTY 也可以安装到 Linux 上。 PuTTY 的功能列表包括:
* 保存会话
* 通过 IP 地址或主机名链接
* 定义备用 SSH 端口
* 链接类型定义
* 日志记录
* 键盘,响铃(命令),外观,链接等选项
* 本地和远程隧道配置
* 代理支持
* X11 隧道支持
PuTTY GUI 主要是保存 SSH 会话的一种方式,因此,您可以更轻松地管理需要不断远程登录登出的各种 Linux 服务器和桌面台式机。 从 PuTTY 连接到 Linux 服务器后,您将拥有一个可以运行的终端窗口。 此时,您可能会问自己,为什么不只在终端窗口中工作? 对于某些人来说,保存会话的便捷性确实使 PuTTY 值得使用。
在Linux上安装PuTTY很简单。 例如您可以在基于Debian的发行版上执行命令
```
sudo apt-get install -y putty
```
安装后,您可以从桌面菜单运行 PuTTY GUI 或执行命令 `putty` 。 在 “ PuTTY 配置 ” 窗口图1在 “主机名” 或IP地址位置键入主机名或 IP 地址配置端口如果不是默认值22从连接类型中选择 SSH ,然后单击“打开”。
![PuTTY Connection][4]
图1PuTTY连接配置窗口。
[Used with permission][5]
建立连接后系统将提示您输入远程服务器上的用户凭据图2
![log in][7]
图2使用PuTTY登录到远程服务器。
[Used with permission][5]
要保存会话(不必总是键入远程服务器信息),填写 IP 地址(或主机名),配置端口和连接类型,然后(在单击 Open打开之前在 Saved Sessions保存会话顶部文本区域中键入链接的名称然后单击 Save保存。 这样将保存此会话的配置。 若要连接到已保存的会话,请从 “已保存的会话” 窗口中选择它,单击 Load加载然后单击 Open打开。 然后,系统将提示您输入远程服务器上的远程凭据登录远程服务器。
### EasySSH
尽管 [EasySSH][8] 没有提供 PuTTY 中提供的大量配置选项,但是(顾名思义)它非常易于使用。 EasySSH 的最佳功能之一是提供选项卡式界面,因此您可以打开多个 SSH 连接并在它们之间快速切换。 EasySSH的功能包括
* 组(您可以将选项卡分组以获得更有效的体验)。
* 用户名/密码保存。
* 外观选项。
* 本地和远程隧道支持。
在 Linux 桌面上安装 EasySSH 很简单,因为可以通过 flatpak 安装该应用程序(这意味着您必须在系统上安装 Flatpak )。 安装 flatpak 后,使用以下命令添加 EasySSH
```
sudo flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo
sudo flatpak install flathub com.github.muriloventuroso.easyssh
```
使用以下命令运行 EasySSH
```
flatpak run com.github.muriloventuroso.easyssh
```
您可以在其中单击左上角的+按钮打开 EasySSH 应用程序。 在出现的窗口图3根据需要配置 SSH 连接。
![Adding a connection][10]
图3在 EasySSH 中添加连接很简单。
[Used with permission][5]
添加连接后它将显示在主窗口的左侧导航中图4
![EasySSH][12]
图4EasySSH 主窗口。
[Used with permission][5]
要在 EasySSH 中连接到远程服务器,请从左侧导航中选择它,然后单击 Connect连接按钮图5
![Connecting][14]
图5使用 EasySSH 连接到远程服务器。
[Used with permission][5]
EasySSH 的一个警告是您必须在连接配置中保存用户名和密码(否则连接将失败)。 这意味着有权访问运行 EasySSH 的桌面的任何人都可以在不知道密码的情况下远程访问您的服务器。 因此,您必须始终记得在外出时锁定桌面屏幕(并确保使用强密码)。 最后一点就是避免服务器受到不必要的登录攻击。
### Terminator
Terminator 实际上不是 SSH GUI。 取而代之的是Terminator 充当单个窗口,使您可以一次运行多个终端(甚至终端组)。 实际上您可以打开Terminator垂直和水平拆分窗口直到拥有所需的所有终端然后通过标准 SSH 命令连接到所有远程 Linux 服务器图6
![Terminator][16]
图6Terminator 分为三个不同的窗口,每个窗口都连接到不同的 Linux 服务器。
[Used with permission][5]
要安装 Terminator请执行以下命令
### sudo apt-get install -y terminator
安装后,从桌面菜单或 `terminator` 命令打开该工具。 打开窗口后,您可以在 Terminator 内部右键单击,然后选择 “水平分割”或“垂直分割”。继续拆分终端,直到您打开所需的终端为止,然后开始远程管理这些服务器。使用 Terminator 的警告是它不是标准的 SSH GUI 工具,因为它不会保存您的会话或使您可以快速访问这些服务器。 换句话说,您将始终必须手动登录到远程 Linux 服务器。 但是,能够并行查看远程 Secure Shell 会话确实使管理多个远程计算机变得容易得多。
少而精的选项
Linux 没有多少可用的 SSH GUI 工具。 为什么呢? 因为大多数管理员更喜欢简单地打开终端窗口并使用标准命令行工具来远程访问服务器。 但是,如果需要 GUI 工具,则有两个固定选项和一个终端,使登录多台计算机稍微容易一些。 尽管对于那些寻找 SSH GUI 工具的人来说只有少数选择,但是可用的那些肯定值得您花时间根据需要尝试其中之一。
--------------------------------------------------------------------------------
via: https://www.linux.com/blog/learn/intro-to-linux/2018/11/three-ssh-guis-linux
作者:[Jack Wallen][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/stevenzdg988)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://www.linux.com/users/jlwallen
[b]: https://github.com/lujun9972
[1]: https://elementary.io/
[2]: https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html
[3]: https://www.linux.com/files/images/sshguis1jpg
[4]: https://www.linux.com/sites/lcom/files/styles/rendered_file/public/ssh_guis_1.jpg?itok=DiNTz_wO (PuTTY Connection)
[5]: https://www.linux.com/licenses/category/used-permission
[6]: https://www.linux.com/files/images/sshguis2jpg
[7]: https://www.linux.com/sites/lcom/files/styles/rendered_file/public/ssh_guis_2.jpg?itok=4ORsJlz3 (log in)
[8]: https://github.com/muriloventuroso/easyssh
[9]: https://www.linux.com/files/images/sshguis3jpg
[10]: https://www.linux.com/sites/lcom/files/styles/rendered_file/public/ssh_guis_3.jpg?itok=bHC2zlda (Adding a connection)
[11]: https://www.linux.com/files/images/sshguis4jpg
[12]: https://www.linux.com/sites/lcom/files/styles/rendered_file/public/ssh_guis_4.jpg?itok=hhJzhRIg (EasySSH)
[13]: https://www.linux.com/files/images/sshguis5jpg
[14]: https://www.linux.com/sites/lcom/files/styles/rendered_file/public/ssh_guis_5.jpg?itok=piFEFYTQ (Connecting)
[15]: https://www.linux.com/files/images/sshguis6jpg
[16]: https://www.linux.com/sites/lcom/files/styles/rendered_file/public/ssh_guis_6.jpg?itok=-kYl6iSE (Terminator)

View File

@ -1,5 +1,5 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: translator: (stevenzdg988)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
@ -7,27 +7,27 @@
[#]: via: (https://www.networkworld.com/article/3373502/printing-from-the-linux-command-line.html)
[#]: author: (Sandra Henry-Stocker https://www.networkworld.com/author/Sandra-Henry_Stocker/)
Printing from the Linux command line
Linux 命令行打印
======
There's a lot more to printing from the Linux command line than the lp command. Check out some of the many available options.
通过一些可用选项 Linux 命令行打印的内容比 `lp` 命令多得多。
![Sherry \(CC BY 2.0\)][1]
Printing from the Linux command line is easy. You use the **lp** command to request a print, and **lpq** to see what print jobs are in the queue, but things get a little more complicated when you want to print double-sided or use portrait mode. And there are lots of other things you might want to do — such as printing multiple copies of a document or canceling a print job. Let's check out some options for getting your printouts to look just the way you want them to when you're printing from the command line.
Linux 命令行打印很容易。您可以使用 **lp** 命令来请求打印,并使用 **lpq** 命令来查看队列中有哪些打印作业,但是当您要双面打印或使用纵向模式时,这些会变得有些复杂。 您可能还需要做很多其他事情,例如打印多份文档副本或取消打印作业。 让我们通过某些选项以使打印输出的内容看起来像从命令行打印时的方式一样。
### Displaying printer settings
### 显示打印机配置
To view your printer settings from the command line, use the **lpoptions** command. The output should look something like this:
要从命令行查看打印机设置,请使用 **lpoptions** 命令。 输出应如下所示:
```
$ lpoptions
copies=1 device-uri=dnssd://HP%20Color%20LaserJet%20CP2025dn%20(F47468)._pdl-datastream._tcp.local/ finishings=3 job-cancel-after=10800 job-hold-until=no-hold job-priority=50 job-sheets=none,none marker-change-time=1553023232 marker-colors=#000000,#00FFFF,#FF00FF,#FFFF00 marker-levels=18,62,62,63 marker-names='Black\ Cartridge\ HP\ CC530A,Cyan\ Cartridge\ HP\ CC531A,Magenta\ Cartridge\ HP\ CC533A,Yellow\ Cartridge\ HP\ CC532A' marker-types=toner,toner,toner,toner number-up=1 printer-commands=none printer-info='HP Color LaserJet CP2025dn (F47468)' printer-is-accepting-jobs=true printer-is-shared=true printer-is-temporary=false printer-location printer-make-and-model='HP Color LaserJet cp2025dn pcl3, hpcups 3.18.7' printer-state=3 printer-state-change-time=1553023232 printer-state-reasons=none printer-type=167964 printer-uri-supported=ipp://localhost/printers/Color-LaserJet-CP2025dn sides=one-sided
```
This output is likely to be a little more human-friendly if you turn its blanks into carriage returns. Notice how many settings are listed.
如果将其空格转换为回车符,输出可能会更人性化,请注意列出了多少设置选项。
NOTE: In the output below, some lines have been reconnected to make this output more readable.
注意:在下面的输出中,一些行被重新链接,以使输出更具可读性。
```
$ lpoptions | tr " " '\n'
@ -62,7 +62,7 @@ printer-uri-supported=ipp://localhost/printers/Color-LaserJet-CP2025dn
sides=one-sided
```
With the **-v** option, the **lpinfo** command will list drivers and related information.
使用 **-v** 选项时,**lpinfo** 命令将列出驱动程序和相关信息。
```
$ lpinfo -v
@ -80,13 +80,13 @@ network dnssd://HP%20Color%20LaserJet%20CP2025dn%20(F47468)._pdl-datastream._tcp
network socket://192.168.0.23 <== printer IP
```
The lpoptions command will show the settings of your default printer. Use the **-p** option to specify one of a number of available printers.
`lpoptions` 命令将显示默认打印机的设置。使用 **-p** 选项指定其中一个可用打印机代号。
```
$ lpoptions -p LaserJet
```
The **lpstat -p** command displays the status of a printer while **lpstat -p -d** also lists available printers.
**lpstat -p** 命令显示打印机的状态,而 **lpstat -p -d** 列出可用打印机列表。
```
$ lpstat -p -d
@ -94,16 +94,16 @@ printer Color-LaserJet-CP2025dn is idle. enabled since Tue 19 Mar 2019 05:07:45
system default destination: Color-LaserJet-CP2025dn
```
### Useful commands
### 非常有用的命令
To print a document on the default printer, just use the **lp** command followed by the name of the file you want to print. If the filename includes blanks (rare on Linux systems), either put the name in quotes or start entering the file name and press the tab key to invoke file completion (as shown in the second example below).
要在默认打印机上打印文档,只需使用 **lp** 命令,后跟要打印的文件名即可。 如果文件名包含空格(在 Linux 系统上很少见),请将该名称放在引号中或开始输入文件名并按 Tab 键调用空格的转义标志(如下面的第二个示例所示)。
```
$ lp "never leave home angry"
$ lp never\ leave\ home\ angry
```
The **lpq** command displays the print queue.
**lpq** 命令显示打印队列。
```
$ lpq
@ -112,52 +112,52 @@ Rank Owner Job File(s) Total Size
active shs 234 agenda 2048 bytes
```
With the **-n** option, the lp command allows you to specify the number of copies of a printout you want.
使用 **-n** 选项时,`lp` 命令可用来指定所需打印输出的份数。
```
$ lp -n 11 agenda
```
To cancel a print job, you can use the **cancel** or **lprm** command. If you don't act quickly, you might see this:
要取消打印作业,可以使用 **cancel****lprm** 命令。 如果没来得及执行,则可能会看到以下信息:
```
$ cancel 229
cancel: cancel-job failed: Job #229 is already completed - can't cancel.
```
### Two-sided printing
### 双面打印
To print in two-sided mode, you can issue your lp command with a **sides** option that says both to print on both sides of the paper and which edge to turn the paper on. This setting represents the normal way that you would expect two-sided portrait documents to look.
要以双面模式打印,您可以在 **lp** 命令中使用 **sides** 选项,该选项表示既可以在纸张的正反面进行打印,又可以在纸张的其中一面进行打印。 通常此设置表示看起来像双面竖排格式文档方式。
```
$ lp -o sides=two-sided-long-edge Notes.pdf
```
If you want all of your documents to print in two-side mode, you can change your lp settings by using the **lpoptions** command to change the setting for **sides**.
如果要所有文档以双面模式打印,则可以使用 **lpoptions** 命令更改 `lp` 设置进而更改 **sides** 的设置。
```
$ lpoptions -o sides=two-sided-short-edge
```
To revert to single-sided printing, you would use a command like this one:
要恢复为单面打印,可以使用如下命令:
```
$ lpoptions -o sides=one-sided
```
#### Printing in landscape mode
#### 横向打印
To print in landscape mode, you would use the **landscape** option with the lp command.
要以横向模式打印,可以在 `lp` 命令中使用 **landscape** 选项。
```
$ lp -o landscape penguin.jpg
```
### CUPS
### CUPSUnix 通用打印系统)
The print system used on Linux systems is the standards-based, open source printing system called CUPS, originally standing for **Common Unix Printing System**. It allows a computer to act as a print server.
Linux 系统上使用的打印系统是基于标准的开源打印系统,称为 **CUPS**,原本基于 **Unix 通用打印系统**。 它允许计算机充当打印服务器。
Join the Network World communities on [Facebook][2] and [LinkedIn][3] to comment on topics that are top of mind.
加入 Network World 社区的 [Facebook][2] 和 [LinkedIn][3],以评论最感兴趣的主题。
--------------------------------------------------------------------------------
@ -165,7 +165,7 @@ via: https://www.networkworld.com/article/3373502/printing-from-the-linux-comman
作者:[Sandra Henry-Stocker][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
译者:[译者ID](https://github.com/stevenzdg988)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出