mirror of
https://github.com/LCTT/TranslateProject.git
synced 2025-01-25 23:11:02 +08:00
Merge remote-tracking branch 'LCTT/master'
This commit is contained in:
commit
66d8eb18b3
219
published/20190504 Using the force at the Linux command line.md
Normal file
219
published/20190504 Using the force at the Linux command line.md
Normal file
@ -0,0 +1,219 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (Moelf)
|
||||
[#]: reviewer: (wxy)
|
||||
[#]: publisher: (wxy)
|
||||
[#]: url: (https://linux.cn/article-10881-1.html)
|
||||
[#]: subject: (Using the force at the Linux command line)
|
||||
[#]: via: (https://opensource.com/article/19/5/may-the-force-linux)
|
||||
[#]: author: (Alan Formy-Duval https://opensource.com/users/alanfdoss)
|
||||
|
||||
在 Linux 命令行下使用“原力”
|
||||
======
|
||||
|
||||
> 和绝地武士的原力一样,`-f` 参数是很强大的,并伴随着潜在的毁灭性,在你能用好的时候又很便利。
|
||||
|
||||
![Fireworks](https://img.linux.net.cn/data/attachment/album/201905/21/083913jqbwn4ywq1jqnb9y.jpg)
|
||||
|
||||
近些年来,科幻发烧友开始在每年的 5 月 4 日庆祝[星战节][2],其口号是绝地武士的祝福语”愿<ruby>原力<rt>Force</rt></ruby>和你同在“。虽然大多数 Linux 用户可能不是绝地武士,但我们依然可以使用<ruby>原力<rt>Force</rt></ruby>。自然,如果尤达大师只是叫天行者卢克输入什么 “man X-Wing 战机“、“man 原力”,或者 RTFM(去读原力手册,肯定是这个意思对不对),那这电影肯定没啥意思。(LCTT 译注:RTFM 是 “Read The Fucking Manual” 的缩写 —— 读读该死的手册吧)。
|
||||
|
||||
很多 Linux 命令都有 `-f` 选项,意思你现在肯定也知道了,原力(LCTT 译注:force 选项原意是“强制”)!很多时候你先尝试执行命令然后失败了,或者提示你需要补充输入更多选项。通常这都是为了保护你试着改变的文件,或者告诉用户该设备正忙或文件已经存在之类的。
|
||||
|
||||
如果你不想被这些提醒打扰或者压根就不在乎,就使用原力吧!
|
||||
|
||||
不过要小心,通常使用原力选项是摧毁性的。所以用户一定要格外注意!并且确保你知道自己在做什么!用原力就要承担后果!
|
||||
|
||||
以下是一些常见 Linux 命令的原力选项和它们的效果,以及常见使用场景。
|
||||
|
||||
### cp
|
||||
|
||||
`cp` 是 “copy” 的缩写,这是个被用来复制文件或者目录的命令。其 [man 页面][3] 说:
|
||||
|
||||
> -f, --force
|
||||
>
|
||||
> 如果已经存在的目标文件无法被打开,删除它并重试
|
||||
|
||||
你可能会用它来处理只读状态的文件:
|
||||
|
||||
```
|
||||
[alan@workstation ~]$ ls -l
|
||||
total 8
|
||||
-rw-rw---- 1 alan alan 13 May 1 12:24 Hoth
|
||||
-r--r----- 1 alan alan 14 May 1 12:23 Naboo
|
||||
[alan@workstation ~]$ cat Hoth Naboo
|
||||
Icy Planet
|
||||
|
||||
Green Planet
|
||||
```
|
||||
|
||||
如果你想要复制一个叫做 `Hoth` 的文件到 `Naboo`,但因为 `Naboo` 目前是只读状态,`cp` 命令不会执行:
|
||||
|
||||
```
|
||||
[alan@workstation ~]$ cp Hoth Naboo
|
||||
cp: cannot create regular file 'Naboo': Permission denied
|
||||
```
|
||||
|
||||
但通过使用原力,`cp` 会强制执行。`Hoth` 的内容和文件权限会直接被复制到 `Naboo`:
|
||||
|
||||
|
||||
```
|
||||
[alan@workstation ~]$ cp -f Hoth Naboo
|
||||
[alan@workstation ~]$ cat Hoth Naboo
|
||||
Icy Planet
|
||||
|
||||
Icy Planet
|
||||
|
||||
[alan@workstation ~]$ ls -l
|
||||
total 8
|
||||
-rw-rw---- 1 alan alan 12 May 1 12:32 Hoth
|
||||
-rw-rw---- 1 alan alan 12 May 1 12:38 Naboo
|
||||
```
|
||||
|
||||
### ln
|
||||
|
||||
`ln` 命令是用来在文件之间建立链接的,其 [man 页面][4] 描述的原力选项如下:
|
||||
|
||||
|
||||
> -f, --force
|
||||
>
|
||||
> 移除当前存在的文件
|
||||
|
||||
|
||||
假设莱娅公主在维护一个 Java 应用服务器,并且她又一个存放这所有 Java 版本的目录,比如:
|
||||
|
||||
```
|
||||
leia@workstation:/usr/lib/java$ ls -lt
|
||||
total 28
|
||||
lrwxrwxrwx 1 leia leia 12 Mar 5 2018 jdk -> jdk1.8.0_162
|
||||
drwxr-xr-x 8 leia leia 4096 Mar 5 2018 jdk1.8.0_162
|
||||
drwxr-xr-x 8 leia leia 4096 Aug 28 2017 jdk1.8.0_144
|
||||
```
|
||||
|
||||
正如你所看到的,这里有很多个版本的 JDK,并有一个符号链接指向最新版的 JDK。她接着用一个脚本来安装最新版本的 JDK。但是如果没有原力选项的话以下命令是不会成功的:
|
||||
|
||||
```
|
||||
tar xvzmf jdk1.8.0_181.tar.gz -C jdk1.8.0_181/
|
||||
ln -vs jdk1.8.0_181 jdk
|
||||
```
|
||||
|
||||
`tar` 命令会解压 .gz 文件到一个特定的目标目录,但 `ln` 命令会失败,因为这个链接已经存在了。这样的结果是该符号链接不会指向最新版本的 JDK:
|
||||
|
||||
```
|
||||
leia@workstation:/usr/lib/java$ ln -vs jdk1.8.0_181 jdk
|
||||
ln: failed to create symbolic link 'jdk/jdk1.8.0_181': File exists
|
||||
leia@workstation:/usr/lib/java$ ls -lt
|
||||
total 28
|
||||
drwxr-x--- 2 leia leia 4096 May 1 15:44 jdk1.8.0_181
|
||||
lrwxrwxrwx 1 leia leia 12 Mar 5 2018 jdk -> jdk1.8.0_162
|
||||
drwxr-xr-x 8 leia leia 4096 Mar 5 2018 jdk1.8.0_162
|
||||
drwxr-xr-x 8 leia leia 4096 Aug 28 2017 jdk1.8.0_144
|
||||
```
|
||||
|
||||
她可以通过使用原力选项强制 `ln` 更新链接,但这里她还需要使用 `-n`,`-n` 是因为这个情况下链接其实指向一个目录而非文件。这样的话,链接就会正确指向最新版本的JDK了。
|
||||
|
||||
```
|
||||
leia@workstation:/usr/lib/java$ ln -vsnf jdk1.8.0_181 jdk
|
||||
'jdk' -> 'jdk1.8.0_181'
|
||||
leia@workstation:/usr/lib/java$ ls -lt
|
||||
total 28
|
||||
lrwxrwxrwx 1 leia leia 12 May 1 16:13 jdk -> jdk1.8.0_181
|
||||
drwxr-x--- 2 leia leia 4096 May 1 15:44 jdk1.8.0_181
|
||||
drwxr-xr-x 8 leia leia 4096 Mar 5 2018 jdk1.8.0_162
|
||||
drwxr-xr-x 8 leia leia 4096 Aug 28 2017 jdk1.8.0_144
|
||||
```
|
||||
|
||||
你可以配置 Java 应用使其一直使用在 `/usr/lib/java/jdk` 处的 JDK,而不用每次升级都更新。
|
||||
|
||||
### rm
|
||||
|
||||
`rm` 命令是 “remove” 的缩写(也叫做删除,因为某些系统 `del` 命令也干这事)。其 [man 页面][5] 对原力选项的描述如下:
|
||||
|
||||
|
||||
> -f, --force
|
||||
>
|
||||
> 无视不存在的文件或者参数,不向用户确认
|
||||
|
||||
如果你尝试删除一个只读的文件,`rm` 会寻求用户的确认:
|
||||
|
||||
```
|
||||
[alan@workstation ~]$ ls -l
|
||||
total 4
|
||||
-r--r----- 1 alan alan 16 May 1 11:38 B-wing
|
||||
[alan@workstation ~]$ rm B-wing
|
||||
rm: remove write-protected regular file 'B-wing'?
|
||||
```
|
||||
|
||||
你一定要输入 `y` 或者 `n` 来回答确认才能让 `rm` 命令继续。如果你使用原力选项,`rm` 就不会寻求你的确认而直接删除文件:
|
||||
|
||||
```
|
||||
[alan@workstation ~]$ rm -f B-wing
|
||||
[alan@workstation ~]$ ls -l
|
||||
total 0
|
||||
[alan@workstation ~]$
|
||||
```
|
||||
|
||||
最常见的 `rm` 原力选项用法是用来删除目录。 `-r`(递归)选项会让 `rm` 删除目录,当和原力选项结合起来,它会删除这个文件夹及其内容而无需用户确认。
|
||||
|
||||
`rm` 命令和一些选项结合起来是致命的,一直以来互联网上都有关于误用 `rm` 删除整个系统之类的玩笑和鬼故事。比如最出名的一不当心执行 `rm -rf .` 会直接删除目录和文件(没有用户确认)。(LCTT 译注:真的这么干过的校对飘过~~请按下回车前再三确认:我是谁,我在哪里,我在干什么)
|
||||
|
||||
### userdel
|
||||
|
||||
`userdel` 命令使用来删除用户的。其 [man 页面][6] 是这样描述它的原力选项的:
|
||||
|
||||
> -f, --force
|
||||
>
|
||||
> 这个选项会强制移除用户,即便用户当前处于登入状态。它同时还会强制
|
||||
删除用户的目录和邮件存储,即便这个用户目录被别人共享或者邮件存储并不
|
||||
属于这个用户。如果 `USERGROUPS_ENAB` 在 `/etc/login.defs` 里是 `yes`
|
||||
并且有一个组和此用户同名的话,这个组也会被移除,即便这个组还是别
|
||||
的用户的主要用户组也一样。
|
||||
>
|
||||
> 注意:这个选项有风险并可能让系统处于不稳定状态。
|
||||
|
||||
当欧比旺抵达穆斯塔法星的时候,他知道自己的使命。他需要删掉达斯·维达的用户账户——而达斯还在里面呢。
|
||||
|
||||
```
|
||||
[root@workstation ~]# ps -fu darth
|
||||
UID PID PPID C STIME TTY TIME CMD
|
||||
darth 7663 7655 0 13:28 pts/3 00:00:00 -bash
|
||||
[root@workstation ~]# userdel darth
|
||||
userdel: user darth is currently used by process 7663
|
||||
```
|
||||
|
||||
因为达斯还登在系统里,欧比旺需要使用原力选项操作 `userdel`。这能强制删除当前登入的用户。
|
||||
|
||||
```
|
||||
[root@workstation ~]# userdel -f darth
|
||||
userdel: user darth is currently used by process 7663
|
||||
[root@workstation ~]# finger darth
|
||||
finger: darth: no such user.
|
||||
[root@workstation ~]# ps -fu darth
|
||||
error: user name does not exist
|
||||
```
|
||||
|
||||
正如我们所见到的一样,`finger` 和 `ps` 命令让我们确认了达斯已经被删除了。
|
||||
|
||||
### 在 Shell 脚本里使用原力
|
||||
|
||||
很多命令都有原力选项,而在 shell 脚本里他们特别有用。因为我们经常使用脚本完成定期或者自动化的任务,避免用户输入至关重要,不然的话自动任务就无法完成了
|
||||
|
||||
我希望上面的几个例子能帮你理解一些需要使用原力的情况。你在命令行使用原力或把它们写入脚本之前应当完全理解它们的作用。误用原力会有毁灭性的后果——时常是对整个系统,甚至不仅限于一台设备。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/19/5/may-the-force-linux
|
||||
|
||||
作者:[Alan Formy-Duval][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[Jerry Ling](https://github.com/Moelf)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/alanfdoss
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/fireworks_light_art_design.jpg?itok=hfx9i4By (Fireworks)
|
||||
[2]: https://www.starwars.com/star-wars-day
|
||||
[3]: http://man7.org/linux/man-pages/man1/cp.1.html
|
||||
[4]: http://man7.org/linux/man-pages/man1/ln.1.html
|
||||
[5]: http://man7.org/linux/man-pages/man1/rm.1.html
|
||||
[6]: http://man7.org/linux/man-pages/man8/userdel.8.html
|
@ -1,211 +0,0 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (StdioA)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Kubernetes on Fedora IoT with k3s)
|
||||
[#]: via: (https://fedoramagazine.org/kubernetes-on-fedora-iot-with-k3s/)
|
||||
[#]: author: (Lennart Jern https://fedoramagazine.org/author/lennartj/)
|
||||
|
||||
Kubernetes on Fedora IoT with k3s
|
||||
======
|
||||
|
||||
![][1]
|
||||
|
||||
Fedora IoT is an upcoming Fedora edition targeted at the Internet of Things. It was introduced last year on Fedora Magazine in the article [How to turn on an LED with Fedora IoT][2]. Since then, it has continued to improve together with Fedora Silverblue to provide an immutable base operating system aimed at container-focused workflows.
|
||||
|
||||
Kubernetes is an immensely popular container orchestration system. It is perhaps most commonly used on powerful hardware handling huge workloads. However, it can also be used on lightweight devices such as the Raspberry Pi 3. Read on to find out how.
|
||||
|
||||
### Why Kubernetes?
|
||||
|
||||
While Kubernetes is all the rage in the cloud, it may not be immediately obvious to run it on a small single board computer. But there are certainly reasons for doing it. First of all it is a great way to learn and get familiar with Kubernetes without the need for expensive hardware. Second, because of its popularity, there are [tons of applications][3] that comes pre-packaged for running in Kubernetes clusters. Not to mention the large community to provide help if you ever get stuck.
|
||||
|
||||
Last but not least, container orchestration may actually make things easier, even at the small scale in a home lab. This may not be apparent when tackling the the learning curve, but these skills will help when dealing with any cluster in the future. It doesn’t matter if it’s a single node Raspberry Pi cluster or a large scale machine learning farm.
|
||||
|
||||
#### K3s – a lightweight Kubernetes
|
||||
|
||||
A “normal” installation of Kubernetes (if such a thing can be said to exist) is a bit on the heavy side for IoT. The recommendation is a minimum of 2 GB RAM per machine! However, there are plenty of alternatives, and one of the newcomers is [k3s][4] – a lightweight Kubernetes distribution.
|
||||
|
||||
K3s is quite special in that it has replaced etcd with SQLite for its key-value storage needs. Another thing to note is that k3s ships as a single binary instead of one per component. This diminishes the memory footprint and simplifies the installation. Thanks to the above, k3s should be able to run k3s with just 512 MB of RAM, perfect for a small single board computer!
|
||||
|
||||
### What you will need
|
||||
|
||||
1. Fedora IoT in a virtual machine or on a physical device. See the excellent getting started guide [here][5]. One machine is enough but two will allow you to test adding more nodes to the cluster.
|
||||
2. [Configure the firewall][6] to allow traffic on ports 6443 and 8472. Or simply disable it for this experiment by running “systemctl stop firewalld”.
|
||||
|
||||
|
||||
|
||||
### Install k3s
|
||||
|
||||
Installing k3s is very easy. Simply run the installation script:
|
||||
|
||||
```
|
||||
curl -sfL https://get.k3s.io | sh -
|
||||
```
|
||||
|
||||
This will download, install and start up k3s. After installation, get a list of nodes from the server by running the following command:
|
||||
|
||||
```
|
||||
kubectl get nodes
|
||||
```
|
||||
|
||||
Note that there are several options that can be passed to the installation script through environment variables. These can be found in the [documentation][7]. And of course, there is nothing stopping you from installing k3s manually by downloading the binary directly.
|
||||
|
||||
While great for experimenting and learning, a single node cluster is not much of a cluster. Luckily, adding another node is no harder than setting up the first one. Just pass two environment variables to the installation script to make it find the first node and avoid running the server part of k3s
|
||||
|
||||
```
|
||||
curl -sfL https://get.k3s.io | K3S_URL=https://example-url:6443 \
|
||||
K3S_TOKEN=XXX sh -
|
||||
```
|
||||
|
||||
The example-url above should be replaced by the IP address or fully qualified domain name of the first node. On that node the token (represented by XXX) is found in the file /var/lib/rancher/k3s/server/node-token.
|
||||
|
||||
### Deploy some containers
|
||||
|
||||
Now that we have a Kubernetes cluster, what can we actually do with it? Let’s start by deploying a simple web server.
|
||||
|
||||
```
|
||||
kubectl create deployment my-server --image nginx
|
||||
```
|
||||
|
||||
This will create a [Deployment][8] named “my-server” from the container image “nginx” (defaulting to docker hub as registry and the latest tag). You can see the Pod created by running the following command.
|
||||
|
||||
```
|
||||
kubectl get pods
|
||||
```
|
||||
|
||||
In order to access the nginx server running in the pod, first expose the Deployment through a [Service][9]. The following command will create a Service with the same name as the deployment.
|
||||
|
||||
```
|
||||
kubectl expose deployment my-server --port 80
|
||||
```
|
||||
|
||||
The Service works as a kind of load balancer and DNS record for the Pods. For instance, when running a second Pod, we will be able to _curl_ the nginx server just by specifying _my-server_ (the name of the Service). See the example below for how to do this.
|
||||
|
||||
```
|
||||
# Start a pod and run bash interactively in it
|
||||
kubectl run debug --generator=run-pod/v1 --image=fedora -it -- bash
|
||||
# Wait for the bash prompt to appear
|
||||
curl my-server
|
||||
# You should get the "Welcome to nginx!" page as output
|
||||
```
|
||||
|
||||
### Ingress controller and external IP
|
||||
|
||||
By default, a Service only get a ClusterIP (only accessible inside the cluster), but you can also request an external IP for the service by setting its type to [LoadBalancer][10]. However, not all applications require their own IP address. Instead, it is often possible to share one IP address among many services by routing requests based on the host header or path. You can accomplish this in Kubernetes with an [Ingress][11], and this is what we will do. Ingresses also provide additional features such as TLS encryption of the traffic without having to modify your application.
|
||||
|
||||
Kubernetes needs an ingress controller to make the Ingress resources work and k3s includes [Traefik][12] for this purpose. It also includes a simple service load balancer that makes it possible to get an external IP for a Service in the cluster. The [documentation][13] describes the service like this:
|
||||
|
||||
> k3s includes a basic service load balancer that uses available host ports. If you try to create a load balancer that listens on port 80, for example, it will try to find a free host in the cluster for port 80. If no port is available the load balancer will stay in Pending.
|
||||
>
|
||||
> k3s README
|
||||
|
||||
The ingress controller is already exposed with this load balancer service. You can find the IP address that it is using with the following command.
|
||||
|
||||
```
|
||||
$ kubectl get svc --all-namespaces
|
||||
NAMESPACE NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
|
||||
default kubernetes ClusterIP 10.43.0.1 443/TCP 33d
|
||||
default my-server ClusterIP 10.43.174.38 80/TCP 30m
|
||||
kube-system kube-dns ClusterIP 10.43.0.10 53/UDP,53/TCP,9153/TCP 33d
|
||||
kube-system traefik LoadBalancer 10.43.145.104 10.0.0.8 80:31596/TCP,443:31539/TCP 33d
|
||||
```
|
||||
|
||||
Look for the Service named traefik. In the above example the IP we are interested in is 10.0.0.8.
|
||||
|
||||
### Route incoming requests
|
||||
|
||||
Let’s create an Ingress that routes requests to our web server based on the host header. This example uses [xip.io][14] to avoid having to set up DNS records. It works by including the IP adress as a subdomain, to use any subdomain of 10.0.0.8.xip.io to reach the IP 10.0.0.8. In other words, my-server.10.0.0.8.xip.io is used to reach the ingress controller in the cluster. You can try this right now (with your own IP instead of 10.0.0.8). Without an ingress in place you should reach the “default backend” which is just a page showing “404 page not found”.
|
||||
|
||||
We can tell the ingress controller to route requests to our web server Service with the following Ingress.
|
||||
|
||||
```
|
||||
apiVersion: extensions/v1beta1
|
||||
kind: Ingress
|
||||
metadata:
|
||||
name: my-server
|
||||
spec:
|
||||
rules:
|
||||
- host: my-server.10.0.0.8.xip.io
|
||||
http:
|
||||
paths:
|
||||
- path: /
|
||||
backend:
|
||||
serviceName: my-server
|
||||
servicePort: 80
|
||||
```
|
||||
|
||||
Save the above snippet in a file named _my-ingress.yaml_ and add it to the cluster by running this command:
|
||||
|
||||
```
|
||||
kubectl apply -f my-ingress.yaml
|
||||
```
|
||||
|
||||
You should now be able to reach the default nginx welcoming page on the fully qualified domain name you chose. In my example this would be my-server.10.0.0.8.xip.io. The ingress controller is routing the requests based on the information in the Ingress. A request to my-server.10.0.0.8.xip.io will be routed to the Service and port defined as backend in the Ingress (my-server and 80 in this case).
|
||||
|
||||
### What about IoT then?
|
||||
|
||||
Imagine the following scenario. You have dozens of devices spread out around your home or farm. It is a heterogeneous collection of IoT devices with various hardware capabilities, sensors and actuators. Maybe some of them have cameras, weather or light sensors. Others may be hooked up to control the ventilation, lights, blinds or blink LEDs.
|
||||
|
||||
In this scenario, you want to gather data from all the sensors, maybe process and analyze it before you finally use it to make decisions and control the actuators. In addition to this, you may want to visualize what’s going on by setting up a dashboard. So how can Kubernetes help us manage something like this? How can we make sure that Pods run on suitable devices?
|
||||
|
||||
The simple answer is labels. You can label the nodes according to capabilities, like this:
|
||||
|
||||
```
|
||||
kubectl label nodes <node-name> <label-key>=<label-value>
|
||||
# Example
|
||||
kubectl label nodes node2 camera=available
|
||||
```
|
||||
|
||||
Once they are labeled, it is easy to select suitable nodes for your workload with [nodeSelectors][15]. The final piece to the puzzle, if you want to run your Pods on _all_ suitable nodes is to use [DaemonSets][16] instead of Deployments. In other words, create one DaemonSet for each data collecting application that uses some unique sensor and use nodeSelectors to make sure they only run on nodes with the proper hardware.
|
||||
|
||||
The service discovery feature that allows Pods to find each other simply by Service name makes it quite easy to handle these kinds of distributed systems. You don’t need to know or configure IP addresses or custom ports for the applications. Instead, they can easily find each other through named Services in the cluster.
|
||||
|
||||
#### Utilize spare resources
|
||||
|
||||
With the cluster up and running, collecting data and controlling your lights and climate control you may feel that you are finished. However, there are still plenty of compute resources in the cluster that could be used for other projects. This is where Kubernetes really shines.
|
||||
|
||||
You shouldn’t have to worry about where exactly those resources are or calculate if there is enough memory to fit an extra application here or there. This is exactly what orchestration solves! You can easily deploy more applications in the cluster and let Kubernetes figure out where (or if) they will fit.
|
||||
|
||||
Why not run your own [NextCloud][17] instance? Or maybe [gitea][18]? You could also set up a CI/CD pipeline for all those IoT containers. After all, why would you build and cross compile them on your main computer if you can do it natively in the cluster?
|
||||
|
||||
The point here is that Kubernetes makes it easier to make use of the “hidden” resources that you often end up with otherwise. Kubernetes handles scheduling of Pods in the cluster based on available resources and fault tolerance so that you don’t have to. However, in order to help Kubernetes make reasonable decisions you should definitely add [resource requests][19] to your workloads.
|
||||
|
||||
### Summary
|
||||
|
||||
While Kubernetes, or container orchestration in general, may not usually be associated with IoT, it certainly makes a lot of sense to have an orchestrator when you are dealing with distributed systems. Not only does is allow you to handle a diverse and heterogeneous fleet of devices in a unified way, but it also simplifies communication between them. In addition, Kubernetes makes it easier to utilize spare resources.
|
||||
|
||||
Container technology made it possible to build applications that could “run anywhere”. Now Kubernetes makes it easier to manage the “anywhere” part. And as an immutable base to build it all on, we have Fedora IoT.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://fedoramagazine.org/kubernetes-on-fedora-iot-with-k3s/
|
||||
|
||||
作者:[Lennart Jern][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[StdioA](https://github.com/StdioA)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://fedoramagazine.org/author/lennartj/
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://fedoramagazine.org/wp-content/uploads/2019/04/k3s-1-816x345.png
|
||||
[2]: https://fedoramagazine.org/turnon-led-fedora-iot/
|
||||
[3]: https://hub.helm.sh/
|
||||
[4]: https://k3s.io
|
||||
[5]: https://docs.fedoraproject.org/en-US/iot/getting-started/
|
||||
[6]: https://github.com/rancher/k3s#open-ports--network-security
|
||||
[7]: https://github.com/rancher/k3s#systemd
|
||||
[8]: https://kubernetes.io/docs/concepts/workloads/controllers/deployment/
|
||||
[9]: https://kubernetes.io/docs/concepts/services-networking/service/
|
||||
[10]: https://kubernetes.io/docs/concepts/services-networking/service/#loadbalancer
|
||||
[11]: https://kubernetes.io/docs/concepts/services-networking/ingress/
|
||||
[12]: https://traefik.io/
|
||||
[13]: https://github.com/rancher/k3s/blob/master/README.md#service-load-balancer
|
||||
[14]: http://xip.io/
|
||||
[15]: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/
|
||||
[16]: https://kubernetes.io/docs/concepts/workloads/controllers/daemonset/
|
||||
[17]: https://nextcloud.com/
|
||||
[18]: https://gitea.io/en-us/
|
||||
[19]: https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/
|
@ -1,5 +1,5 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: translator: (Modrisco)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
@ -106,7 +106,7 @@ via: https://itsfoss.com/epic-games-lutris-linux/
|
||||
|
||||
作者:[Ankush Das][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
译者:[Modrisco](https://github.com/Modrisco)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
@ -1,106 +0,0 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (geekpi)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Add methods retroactively in Python with singledispatch)
|
||||
[#]: via: (https://opensource.com/article/19/5/python-singledispatch)
|
||||
[#]: author: (Moshe Zadka https://opensource.com/users/moshez)
|
||||
|
||||
Add methods retroactively in Python with singledispatch
|
||||
======
|
||||
Learn more about solving common Python problems in our series covering
|
||||
seven PyPI libraries.
|
||||
![][1]
|
||||
|
||||
Python is one of the most [popular programming languages][2] in use today—and for good reasons: it's open source, it has a wide range of uses (such as web programming, business applications, games, scientific programming, and much more), and it has a vibrant and dedicated community supporting it. This community is the reason we have such a large, diverse range of software packages available in the [Python Package Index][3] (PyPI) to extend and improve Python and solve the inevitable glitches that crop up.
|
||||
|
||||
In this series, we'll look at seven PyPI libraries that can help you solve common Python problems. Today, we'll examine [**singledispatch**][4], a library that allows you to add methods to Python libraries retroactively.
|
||||
|
||||
### singledispatch
|
||||
|
||||
Imagine you have a "shapes" library with a **Circle** class, a **Square** class, etc.
|
||||
|
||||
A **Circle** has a **radius** , a **Square** has a **side** , and a **Rectangle** has **height** and **width**. Our library already exists; we do not want to change it.
|
||||
|
||||
However, we do want to add an **area** calculation to our library. If we didn't share this library with anyone else, we could just add an **area** method so we could call **shape.area()** and not worry about what the shape is.
|
||||
|
||||
While it is possible to reach into a class and add a method, this is a bad idea: nobody expects their class to grow new methods, and things might break in weird ways.
|
||||
|
||||
Instead, the **singledispatch** function in **functools** can come to our rescue.
|
||||
|
||||
|
||||
```
|
||||
@singledispatch
|
||||
def get_area(shape):
|
||||
raise NotImplementedError("cannot calculate area for unknown shape",
|
||||
shape)
|
||||
```
|
||||
|
||||
The "base" implementation for the **get_area** function fails. This makes sure that if we get a new shape, we will fail cleanly instead of returning a nonsense result.
|
||||
|
||||
|
||||
```
|
||||
@get_area.register(Square)
|
||||
def _get_area_square(shape):
|
||||
return shape.side ** 2
|
||||
@get_area.register(Circle)
|
||||
def _get_area_circle(shape):
|
||||
return math.pi * (shape.radius ** 2)
|
||||
```
|
||||
|
||||
One nice thing about doing things this way is that if someone writes a _new_ shape that is intended to play well with our code, they can implement **get_area** themselves.
|
||||
|
||||
|
||||
```
|
||||
from area_calculator import get_area
|
||||
|
||||
@attr.s(auto_attribs=True, frozen=True)
|
||||
class Ellipse:
|
||||
horizontal_axis: float
|
||||
vertical_axis: float
|
||||
|
||||
@get_area.register(Ellipse)
|
||||
def _get_area_ellipse(shape):
|
||||
return math.pi * shape.horizontal_axis * shape.vertical_axis
|
||||
```
|
||||
|
||||
_Calling_ **get_area** is straightforward.
|
||||
|
||||
|
||||
```
|
||||
`print(get_area(shape))`
|
||||
```
|
||||
|
||||
This means we can change a function that has a long **if isintance()/elif isinstance()** chain to work this way, without changing the interface. The next time you are tempted to check **if isinstance** , try using **singledispatch**!
|
||||
|
||||
In the next article in this series, we'll look at **tox** , a tool for automating tests on Python code.
|
||||
|
||||
#### Review the previous articles in this series:
|
||||
|
||||
* [Cython][5]
|
||||
* [Black][6]
|
||||
* [attrs][7]
|
||||
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/19/5/python-singledispatch
|
||||
|
||||
作者:[Moshe Zadka ][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/moshez
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/computer_code_programming_laptop.jpg?itok=ormv35tV
|
||||
[2]: https://opensource.com/article/18/5/numbers-python-community-trends
|
||||
[3]: https://pypi.org/
|
||||
[4]: https://pypi.org/project/singledispatch/
|
||||
[5]: https://opensource.com/article/19/4/7-python-problems-solved-cython
|
||||
[6]: https://opensource.com/article/19/4/python-problems-solved-black
|
||||
[7]: https://opensource.com/article/19/4/python-problems-solved-attrs
|
@ -1,5 +1,5 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: translator: (geekpi)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
|
@ -1,108 +0,0 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (zhs852)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Change Power Modes in Ubuntu with Slimbook Battery Optimizer)
|
||||
[#]: via: (https://itsfoss.com/slimbook-battry-optimizer-ubuntu/)
|
||||
[#]: author: (Abhishek Prakash https://itsfoss.com/author/abhishek/)
|
||||
|
||||
Change Power Modes in Ubuntu with Slimbook Battery Optimizer
|
||||
======
|
||||
|
||||
_**Brief: Slimbook Battery is a nifty applet indicator that allows you to quickly change the power mode on your Linux laptop and thus save battery life.**_
|
||||
|
||||
[Slimbook][1], the Spanish computer vendor that sells [laptops preloaded with Linux][2], has released a handy little application to optimize battery performance in Ubuntu-based Linux distributions.
|
||||
|
||||
Since Slimbook sells its own Linux systems, they have created a few applications to tweak the performance of Linux on their hardware. This battery optimizer is one such tool.
|
||||
|
||||
You don’t need to buy a Slimbook product to use this nifty application because Slimbook has made it available via [their official PPA][3].
|
||||
|
||||
### Slimbook battery optimizer application
|
||||
|
||||
The application is called Slimbook Battery. It is basically an applet indicator that sits on the top panel and gives you quick access to various power/battery modes.
|
||||
|
||||
![Slimbook Battery Mode Ubuntu][4]
|
||||
|
||||
You might have seen it in Windows where you can put your laptop in one of the power modes. Slimbook Battery also offers similar battery saving modes here:
|
||||
|
||||
* Energy Saving: For maximum battery saving
|
||||
* Balanced: A compromise between performance and power saving
|
||||
* Maximum Performance: For maximum performance obviously
|
||||
|
||||
|
||||
|
||||
You can configure all these modes from the advanced mode:
|
||||
|
||||
![Configure various power modes][5]
|
||||
|
||||
If you feel like you have messed up the configuration, you can set things back to normal with ‘restore default values’ option.
|
||||
|
||||
You can also change the general configuration of the application like auto-start, default power mode etc.
|
||||
|
||||
![Slimbook Battery general configuration][6]
|
||||
|
||||
Skimbook has a dedicated page that provides more information on various power saving parameters. If you want to configure things on your own, you should refer to [this page][7].
|
||||
|
||||
I have noticed that the interface of Slimbook Battery needs some improvements. For example, the ‘question mark’ icon on some parameters should be clickable to provide more information. But clicking the question mark icon doesn’t do anything at the time of writing this article.
|
||||
|
||||
Altogether, Slimbook Battery is a handy app you can use for quickly switching the power mode. If you decide to install it on Ubuntu and other Ubuntu-based distributions such as Linux Mint, elementary OS etc, you can use its official [PPA][8].
|
||||
|
||||
[][9]
|
||||
|
||||
Suggested read Ubuntu Forums Hacked, User Data Stolen!!!
|
||||
|
||||
#### Install Slimbook Batter in Ubuntu-based distributions
|
||||
|
||||
Open a terminal and use the following commands one by one:
|
||||
|
||||
```
|
||||
sudo add-apt-repository ppa:slimbook/slimbook
|
||||
sudo apt update
|
||||
sudo apt install slimbookbattery
|
||||
```
|
||||
|
||||
Once installed, search for Slimbook Battery in the menu:
|
||||
|
||||
![Start Slimbook Battery Optimizer][10]
|
||||
|
||||
When you click on it to start it, you’ll find it in the top panel. From here, you can select your desired power mode.
|
||||
|
||||
![Slimbook Battery power mode][4]
|
||||
|
||||
#### Remove Slimbook Battery
|
||||
|
||||
If you don’t want to use this application, you can remove it using the following commands:
|
||||
|
||||
```
|
||||
sudo apt remove slimbookbattery
|
||||
sudo add-apt-repository -r ppa:slimbook/slimbook
|
||||
```
|
||||
|
||||
In my opinion, such applications serves a certain purpose and should be encouraged. This tool gives you an easy way to change the power mode and at the same time, it gives you more tweaking options for various performance settings.
|
||||
|
||||
Did you use Slimbook Battery? What’s your experience with it?
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://itsfoss.com/slimbook-battry-optimizer-ubuntu/
|
||||
|
||||
作者:[Abhishek Prakash][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://itsfoss.com/author/abhishek/
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://slimbook.es/en/
|
||||
[2]: https://itsfoss.com/get-linux-laptops/
|
||||
[3]: https://launchpad.net/~slimbook/+archive/ubuntu/slimbook
|
||||
[4]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2019/05/slimbook-battery-mode-ubuntu.jpg?resize=800%2C400&ssl=1
|
||||
[5]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2019/05/slimbook-battery-optimizer-2.jpg?ssl=1
|
||||
[6]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2019/05/slimbook-battery-optimizer-1.jpg?ssl=1
|
||||
[7]: https://slimbook.es/en/tutoriales/aplicaciones-slimbook/398-slimbook-battery-3-application-for-optimize-battery-of-your-laptop
|
||||
[8]: https://itsfoss.com/ppa-guide/
|
||||
[9]: https://itsfoss.com/ubuntu-forums-hacked-again/
|
||||
[10]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2019/05/slimbook-battery-optimizer.jpg?ssl=1
|
209
translated/tech/20190415 Kubernetes on Fedora IoT with k3s.md
Normal file
209
translated/tech/20190415 Kubernetes on Fedora IoT with k3s.md
Normal file
@ -0,0 +1,209 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (StdioA)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Kubernetes on Fedora IoT with k3s)
|
||||
[#]: via: (https://fedoramagazine.org/kubernetes-on-fedora-iot-with-k3s/)
|
||||
[#]: author: (Lennart Jern https://fedoramagazine.org/author/lennartj/)
|
||||
|
||||
使用 k3s 在 Fedora IoT 上运行 Kubernetes
|
||||
======
|
||||
|
||||
![][1]
|
||||
|
||||
Fedora IoT 是一个即将发布的、面相物联网的 Fedora 版本。去年 Fedora Magazine 中的《如何使用 Fedora IOT 点亮 LED》一文,第一次介绍了它。从那以后,它与 Fedora Silverblue 一起不断改进,以提供针对面相容器的工作流程的不可变基础操作系统。
|
||||
|
||||
Kubernetes 是一个颇受欢迎的容器编排系统。它可能最常用在那些能够处理巨大负载的强劲硬件上。不过,它也能在像树莓派 3 这样轻量级的设备上运行。我们继续阅读,来了解如何运行它。
|
||||
|
||||
### 为什么用 Kubernetes?
|
||||
|
||||
虽然 Kubernetes 在云计算领域风靡一时,但让它在小型单板机上运行可能并不是显而易见的。不过,我们有非常明确的理由来做这件事。首先,这是一个不需要昂贵硬件就可以学习并熟悉 Kubernetes 的好方法;其次,由于它的流行性,市面上有[大量应用][2]进行了预先打包,以用于在 Kubernetes 集群中运行。更不用说,当你遇到问题时,会有大规模的社区用户为你提供帮助。
|
||||
|
||||
最后但同样重要的是,即使是在家庭实验室这样的小规模环境中,容器编排也确实能事情变得更加简单。虽然在学习曲线方面,这一点并不明显,但这些技能在你将来与任何集群打交道的时候都会有帮助。不管你面对的是一个单节点树莓派集群,还是一个大规模的机器学习场,它们的操作方式都是类似的。
|
||||
|
||||
#### K3s - 轻量级的 Kubernetes
|
||||
|
||||
一个 Kubernetes 的“正常”安装(如果有这么一说的话)对于物联网来说有点沉重。K8s 的推荐内存配置,是每台机器 2GB!不过,我们也有一些替代品,其中一个新人是 [k3s][4]——一个轻量级的 Kubernetes 发行版。
|
||||
|
||||
K3s 非常特殊,因为它将 etcd 替换成了 SQLite 以满足键值存储需求。还有一点,在于整个 k3s 将使用一个二进制文件分发,而不是每个组件一个。这减少了内存占用并简化了安装过程。基于上述原因,我们只需要 512MB 内存即可运行 k3s,简直适合小型单板电脑!
|
||||
|
||||
### 你需要的东西
|
||||
|
||||
1. 在虚拟机或实体设备中运行的 Fedora IoT。在[这里][5]可以看到优秀的入门指南。一台机器就足够了,不过两台可以用来测试向集群添加更多节点。
|
||||
2. [配置防火墙][6],允许 6443 和 8372 端口的通信。或者,你也可以简单地运行“systemctl stop firewalld”来为这次实验关闭防火墙。
|
||||
|
||||
### 安装 k3s
|
||||
|
||||
安装 k3s 非常简单。直接运行安装脚本:
|
||||
|
||||
```
|
||||
curl -sfL https://get.k3s.io | sh -
|
||||
```
|
||||
|
||||
它会下载、安装并启动 k3s。安装完成后,运行以下命令来从服务器获取节点列表:
|
||||
|
||||
```
|
||||
kubectl get nodes
|
||||
```
|
||||
|
||||
需要注意的是,有几个选项可以通过环境变量传递给安装脚本。这些选项可以在[文档][7]中找到。当然,你也完全可以直接下载二进制文件来手动安装 k3s。
|
||||
|
||||
对于实验和学习来说,这样已经很棒了,不过单节点的集群也不是一个集群。幸运的是,添加另一个节点并不比设置第一个节点要难。只需要向安装脚本传递两个环境变量,它就可以找到第一个节点,避免运行 k3s 的服务器部分。
|
||||
|
||||
```
|
||||
curl -sfL https://get.k3s.io | K3S_URL=https://example-url:6443 \
|
||||
K3S_TOKEN=XXX sh -
|
||||
```
|
||||
|
||||
上面的 example-url 应被替换为第一个节点的 IP 地址,或一个经过完全限定的域名。在该节点中,(用 XXX 表示的)令牌可以在 /var/lib/rancher/k3s/server/node-token 文件中找到。
|
||||
|
||||
### 部署一些容器
|
||||
|
||||
现在我们有了一个 Kubernetes 集群,我们可以真正做些什么呢?让我们从部署一个简单的 Web 服务器开始吧。
|
||||
|
||||
```
|
||||
kubectl create deployment my-server --image nginx
|
||||
```
|
||||
|
||||
这会从名为“nginx”的容器镜像中创建出一个名叫“my-server”的 [Deployment][8](镜像名默认使用 docker hub 注册中心,以及 latest 标签)。
|
||||
|
||||
```
|
||||
kubectl get pods
|
||||
```
|
||||
|
||||
为了接触到 pod 中运行的 nginx 服务器,首先将 Deployment 通过一个 [Service][9] 来进行暴露。以下命令将创建一个与 Deployment 同名的 Service。
|
||||
|
||||
```
|
||||
kubectl expose deployment my-server --port 80
|
||||
```
|
||||
|
||||
Service 将作为一种负载均衡器和 Pod 的 DNS 记录来工作。比如,当运行第二个 Pod 时,我们只需指定 _my-server_(Service 名称)就可以通过 _curl_ 访问 nginx 服务器。有关如何操作,可以看下面的实例。
|
||||
|
||||
```
|
||||
# 启动一个 pod,在里面以交互方式运行 bash
|
||||
kubectl run debug --generator=run-pod/v1 --image=fedora -it -- bash
|
||||
# 等待 bash 提示符出现
|
||||
curl my-server
|
||||
# 你可以看到“Welcome to nginx!”的输出页面
|
||||
```
|
||||
|
||||
### Ingress 控制器及外部 IP
|
||||
|
||||
默认状态下,一个 Service 只能获得一个 ClusterIP(只能从集群内部访问),但你也可以通过把它的类型设置为 [LoadBalancer][10] 为服务申请一个外部 IP。不过,并非所有应用都需要自己的 IP 地址。相反,通常可以通过基于 Host 请求头部或请求路径进行路由,从而使多个服务共享一个 IP 地址。你可以在 Kubernetes 使用 [Ingress][11] 完成此操作,而这也是我们要做的。Ingress 也提供了额外的功能,比如无需配置应用,即可对流量进行 TLS 加密。
|
||||
|
||||
Kubernetes 需要入口控制器来使 Ingress 资源工作,k3s 包含 [Traefik][12] 正是出于此目的。它还包含了一个简单的服务负载均衡器,可以为集群中的服务提供外部 IP。这篇[文档][13]描述了这种服务:
|
||||
|
||||
> k3s 包含一个使用可用主机端口的基础服务负载均衡器。比如,如果你尝试创建一个监听 80 端口的负载均衡器,它会尝试在集群中寻找一个 80 端口空闲的节点。如果没有可用端口,那么负载均衡器将保持在 Pending 状态。
|
||||
>
|
||||
> k3s README
|
||||
|
||||
入口控制器已经通过这个负载均衡器暴露在外。你可以使用以下命令找到它正在使用的 IP 地址。
|
||||
|
||||
```
|
||||
$ kubectl get svc --all-namespaces
|
||||
NAMESPACE NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
|
||||
default kubernetes ClusterIP 10.43.0.1 443/TCP 33d
|
||||
default my-server ClusterIP 10.43.174.38 80/TCP 30m
|
||||
kube-system kube-dns ClusterIP 10.43.0.10 53/UDP,53/TCP,9153/TCP 33d
|
||||
kube-system traefik LoadBalancer 10.43.145.104 10.0.0.8 80:31596/TCP,443:31539/TCP 33d
|
||||
```
|
||||
|
||||
找到名为 traefik 的 Service。在上面的例子中,我们感兴趣的 IP 是 10.0.0.8。
|
||||
|
||||
### 路由传入的请求
|
||||
|
||||
让我们创建一个 Ingress,使它通过基于 Host 头部的路由规则将请求路由至我们的服务器。这个例子中我们使用 [xip.io][14] 来避免必要的 DNS 记录配置工作。它的工作原理是将 IP 地址作为子域包含,以使用10.0.0.8.xip.io的任何子域来达到IP 10.0.0.8。换句话说,my-server.10.0.0.8.xip.io 被用于访问集群中的入口控制器。你现在就可以尝试(使用你自己的 IP,而不是 10.0.0.8)。如果没有入口,你应该会访问到“默认后端”,只是一个写着“404 page not found”的页面。
|
||||
|
||||
我们可以使用以下 Ingress 让入口控制器将请求路由到我们的 Web 服务器 Service。
|
||||
|
||||
```
|
||||
apiVersion: extensions/v1beta1
|
||||
kind: Ingress
|
||||
metadata:
|
||||
name: my-server
|
||||
spec:
|
||||
rules:
|
||||
- host: my-server.10.0.0.8.xip.io
|
||||
http:
|
||||
paths:
|
||||
- path: /
|
||||
backend:
|
||||
serviceName: my-server
|
||||
servicePort: 80
|
||||
```
|
||||
|
||||
将以上片段保存到 _my-ingress.yaml_ 文件中,然后运行以下命令将其加入集群:
|
||||
|
||||
```
|
||||
kubectl apply -f my-ingress.yaml
|
||||
```
|
||||
|
||||
你现在应该能够在你选择的完全限定域名中访问到 nginx 的默认欢迎页面了。在我的例子中,它是 my-server.10.0.0.8.xip.io。入口控制器会通过 Ingress 中包含的信息来路由请求。对 my-server.10.0.0.8.xip.io 的请求将被路由到 Ingress 中定义为“后端”的 Service 和端口(在本例中为 my-server 和 80)。
|
||||
|
||||
### 那么,物联网呢?
|
||||
|
||||
想象如下场景:你的家伙农场周围有很多的设备。它是一个具有各种硬件功能,传感器和执行器的物联网设备的异构集合。也许某些设备拥有摄像头,天气或光线传感器。其它设备可能会被连接起来,用来控制通风、灯光、百叶窗或闪烁的LED。
|
||||
|
||||
这种情况下,你想从所有传感器中收集数据,在最终使用它来制定决策和控制执行器之前,也可能会对其进行处理和分析。除此之外,你可能还想配置一个仪表盘来可视化那些正在发生的事情。那么 Kubernetes 如何帮助我们来管理这样的事情呢?我们怎么保证 Pod 在合适的设备上运行?
|
||||
|
||||
简单的答案就是“标签”。你可以根据功能来标记节点,如下所示:
|
||||
|
||||
```
|
||||
kubectl label nodes <node-name> <label-key>=<label-value>
|
||||
# 举例
|
||||
kubectl label nodes node2 camera=available
|
||||
```
|
||||
|
||||
一旦它们被打上标签,我们就可以轻松地使用 [nodeSelector][15] 为你的工作负载选择合适的节点。拼图的最后一块:如果你想在_所有_合适的节点上运行 Pod,那应该使用 [DaemonSet][16] 而不是 Deployment。换句话说,应为每个使用唯一传感器的数据收集应用程序创建一个 DaemonSet,并使用 nodeSelectors 确保它们仅在具有适当硬件的节点上运行。
|
||||
|
||||
服务发现功能允许 Pod 通过 Service 名称来寻找彼此,这项功能使得这类分布式系统的管理工作变得易如反掌。你不需要为应用配置 IP 地址或自定义端口,也不需要知道它们。相反,它们可以通过集群中的具名 Service 轻松找到彼此。
|
||||
|
||||
#### 充分利用空闲资源
|
||||
|
||||
随着集群的启动并运行,收集数据并控制灯光和气候可能使你觉得你已经把它完成了。不过,集群中还有大量的计算资源可以用于其它项目。这才是 Kubernetes 真正出彩的地方。
|
||||
|
||||
你不必担心这些资源的确切位置,或者去计算是否有足够的内存来容纳额外的应用程序。这正是编排系统所解决的问题!你可以轻松地在集群中部署更多的应用,让 Kubernetes 来找出适合运行它们的位置(或是否适合运行它们)。
|
||||
|
||||
为什么不运行一个你自己的 [NextCloud][17] 实例呢?或者运行 [gitea][18]?你还可以为你所有的物联网容器设置一套 CI/CD 流水线。毕竟,如果你可以在集群中进行本地构建,为什么还要在主计算机上构建并交叉编译它们呢?
|
||||
|
||||
这里的要点是,Kubernetes 可以更容易地利用那些你可能浪费掉的“隐藏”资源。Kubernetes 根据可用资源和容错处理规则来调度 Pod,因此你也无需手动完成这些工作。但是,为了帮助 Kubernetes 做出合理的决定,你绝对应该为你的工作负载添加[资源请求][19]配置。
|
||||
|
||||
### 总结
|
||||
|
||||
尽管 Kuberenetes 或一般的容器编排平台通常不会与物联网相关联,但在管理分布式系统时,使用一个编排系统肯定是有意义的。你不仅可以使用统一的方式来处理多样化和异构的设备,还可以简化它们的通信方式。此外,Kubernetes 还可以更好地对闲置资源加以利用。
|
||||
|
||||
容器技术使构建“随处运行”应用的想法成为可能。现在,Kubernetes 可以更轻松地来负责“随处”的部分。作为构建一切的不可变基础,我们使用 Fedora IoT。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://fedoramagazine.org/kubernetes-on-fedora-iot-with-k3s/
|
||||
|
||||
作者:[Lennart Jern][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[StdioA](https://github.com/StdioA)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://fedoramagazine.org/author/lennartj/
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://fedoramagazine.org/wp-content/uploads/2019/04/k3s-1-816x345.png
|
||||
[2]: https://fedoramagazine.org/turnon-led-fedora-iot/
|
||||
[3]: https://hub.helm.sh/
|
||||
[4]: https://k3s.io
|
||||
[5]: https://docs.fedoraproject.org/en-US/iot/getting-started/
|
||||
[6]: https://github.com/rancher/k3s#open-ports--network-security
|
||||
[7]: https://github.com/rancher/k3s#systemd
|
||||
[8]: https://kubernetes.io/docs/concepts/workloads/controllers/deployment/
|
||||
[9]: https://kubernetes.io/docs/concepts/services-networking/service/
|
||||
[10]: https://kubernetes.io/docs/concepts/services-networking/service/#loadbalancer
|
||||
[11]: https://kubernetes.io/docs/concepts/services-networking/ingress/
|
||||
[12]: https://traefik.io/
|
||||
[13]: https://github.com/rancher/k3s/blob/master/README.md#service-load-balancer
|
||||
[14]: http://xip.io/
|
||||
[15]: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/
|
||||
[16]: https://kubernetes.io/docs/concepts/workloads/controllers/daemonset/
|
||||
[17]: https://nextcloud.com/
|
||||
[18]: https://gitea.io/en-us/
|
||||
[19]: https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/
|
@ -0,0 +1,106 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (geekpi)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Add methods retroactively in Python with singledispatch)
|
||||
[#]: via: (https://opensource.com/article/19/5/python-singledispatch)
|
||||
[#]: author: (Moshe Zadka https://opensource.com/users/moshez)
|
||||
|
||||
使用 singledispatch 在 Python 中追溯地添加方法
|
||||
======
|
||||
在我们覆盖 7 个 PyPI 库的系列文章中了解更多解决 Python 问题的信息。
|
||||
![][1]
|
||||
|
||||
Python 是当今使用最多[流行的编程语言][2]之一,因为:它是开源的,它具有广泛的用途(例如 Web 编程、业务应用、游戏、科学编程等等),它有一个充满活力和专注的社区支持它。这个社区是我们在 [Python Package Index][3](PyPI)中提供如此庞大、多样化的软件包的原因,用以扩展和改进 Python。并解决不可避免的问题。
|
||||
|
||||
在本系列中,我们将介绍七个可以帮助你解决常见 Python 问题的 PyPI 库。今天,我们将研究 [**singledispatch**][4],这是一个能让你追溯地向 Python 库添加方法的库。
|
||||
|
||||
### singledispatch
|
||||
|
||||
想象一下,你有一个有 **Circle**、**Square** 等类的“形状”库。
|
||||
|
||||
**Circle** 类有**半径**、**Square** 有 **边**、**Rectangle**有**高**和**宽**。我们的库已经存在,我们不想改变它。
|
||||
|
||||
然而,我们想给库添加一个**面积**计算。如果我们不会和其他人共享这个库,我们只需添加 **area** 方法,这样我们就能调用 **shape.area()** 而无需关心是什么形状。
|
||||
|
||||
虽然可以进入类并添加一个方法,但这是一个坏主意:没有人希望他们的类会被添加新的方法,程序因奇怪的方式出错。
|
||||
|
||||
相反,**functools** 中的 **singledispatch** 函数可以帮助我们。
|
||||
|
||||
|
||||
```
|
||||
@singledispatch
|
||||
def get_area(shape):
|
||||
raise NotImplementedError("cannot calculate area for unknown shape",
|
||||
shape)
|
||||
```
|
||||
|
||||
**get_area** 函数的“基类”实现会报错。这保证了如果我们出现一个新的形状时,我们会明确地报错而不是返回一个无意义的结果。
|
||||
|
||||
|
||||
```
|
||||
@get_area.register(Square)
|
||||
def _get_area_square(shape):
|
||||
return shape.side ** 2
|
||||
@get_area.register(Circle)
|
||||
def _get_area_circle(shape):
|
||||
return math.pi * (shape.radius ** 2)
|
||||
```
|
||||
|
||||
这种方式的好处是如果某人写了一个匹配我们代码的_新_形状,它们可以自己实现 **get_area**。
|
||||
|
||||
|
||||
```
|
||||
from area_calculator import get_area
|
||||
|
||||
@attr.s(auto_attribs=True, frozen=True)
|
||||
class Ellipse:
|
||||
horizontal_axis: float
|
||||
vertical_axis: float
|
||||
|
||||
@get_area.register(Ellipse)
|
||||
def _get_area_ellipse(shape):
|
||||
return math.pi * shape.horizontal_axis * shape.vertical_axis
|
||||
```
|
||||
|
||||
_调用_ **get_area** 很直接。
|
||||
|
||||
|
||||
```
|
||||
`print(get_area(shape))`
|
||||
```
|
||||
|
||||
这意味着我们可以将有大量 **if isintance()/elif isinstance()** 的代码以这种方式修改,而无需修改接口。下一次你要修改 **if isinstance**,你试试 **singledispatch**!
|
||||
|
||||
在本系列的下一篇文章中,我们将介绍 **tox**,一个用于自动化 Python 代码测试的工具。
|
||||
|
||||
|
||||
#### 回顾本系列的前几篇文章:
|
||||
|
||||
* [Cython][5]
|
||||
* [Black][6]
|
||||
* [attrs][7]
|
||||
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/19/5/python-singledispatch
|
||||
|
||||
作者:[Moshe Zadka ][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[geekpi](https://github.com/geekpi)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/moshez
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/computer_code_programming_laptop.jpg?itok=ormv35tV
|
||||
[2]: https://opensource.com/article/18/5/numbers-python-community-trends
|
||||
[3]: https://pypi.org/
|
||||
[4]: https://pypi.org/project/singledispatch/
|
||||
[5]: https://opensource.com/article/19/4/7-python-problems-solved-cython
|
||||
[6]: https://opensource.com/article/19/4/python-problems-solved-black
|
||||
[7]: https://opensource.com/article/19/4/python-problems-solved-attrs
|
@ -1,225 +0,0 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (Moelf)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Using the force at the Linux command line)
|
||||
[#]: via: (https://opensource.com/article/19/5/may-the-force-linux)
|
||||
[#]: author: (Alan Formy-Duval https://opensource.com/users/alanfdoss)
|
||||
|
||||
在 Linux 命令行下使用 force 参数
|
||||
======
|
||||
和绝地武士的原力一样,-f 参数是很强大的,并伴随着潜在的毁灭性,在你能用好的时候又很便利。
|
||||
![Fireworks][1]
|
||||
|
||||
不久的过去,科幻发烧友开始庆祝每年的原力日(5月4日)[_星球大战_][2],英语里和”愿原力和你同在“双关。虽然大多数 Linux 用户可能不是绝地武士,但我们依然可以使用 force。自然,如果 Yoda 直接叫路克天行者输入什么 ”man X翼战机“ 或者 “man 原力"的话电影肯定会无聊不少。或者他可以直接说,"RTFM"(Read the Force Manual,肯定是这个意思对不对)(译者:通常 RTFM 是 Read The Fucking Manual 的缩写,读读该死的手册吧)。
|
||||
|
||||
很多 Linux 指令都有 -f 选项,意思你现在肯定也知道了,force(强制)!很多时候你先尝试执行指令然后失败了,或者提示你需要输入更多选项。通常这都是为了保护你的文件或者告诉用户设备正忙或者文件已经存在之类的设计。
|
||||
|
||||
如果你不想被这些提醒打扰或者压根就不在乎,使用 force !
|
||||
|
||||
不过要小心,通常使用 force 选项是摧毁性的。所以用户一定要格外注意并且确保你知道自己在做什么。用 force 就要承担后果!
|
||||
|
||||
以下是一些常见 Linux 命令的 force 选项和他们的效果,以及常见使用场景。
|
||||
|
||||
### cp
|
||||
**cp** 是 copy 的缩写,这是个被用来复制文件或者目录的命令。[man 页面][3] 说:
|
||||
|
||||
```
|
||||
-f, --force
|
||||
如果已经存在的目标文件无法被打开,删除并重试
|
||||
```
|
||||
你可能会用它来处理只读状态的文件:
|
||||
|
||||
```
|
||||
[alan@workstation ~]$ ls -l
|
||||
total 8
|
||||
-rw-rw---- 1 alan alan 13 May 1 12:24 Hoth
|
||||
-r--r----- 1 alan alan 14 May 1 12:23 Naboo
|
||||
[alan@workstation ~]$ cat Hoth Naboo
|
||||
Icy Planet
|
||||
|
||||
Green Planet
|
||||
```
|
||||
|
||||
如果你想要复制一个叫做 _Hoth_ 的文件到 _Naboo_,但因为 _Naboo_ 目前是只读状态,**cp** 指令不会执行:
|
||||
|
||||
|
||||
```
|
||||
[alan@workstation ~]$ cp Hoth Naboo
|
||||
cp: cannot create regular file 'Naboo': Permission denied
|
||||
```
|
||||
|
||||
但通过使用 force 选项,**cp** 会强制执行。_Hoth_ 的内容和文件权限会直接被复制到 _Naboo_:
|
||||
|
||||
|
||||
```
|
||||
[alan@workstation ~]$ cp -f Hoth Naboo
|
||||
[alan@workstation ~]$ cat Hoth Naboo
|
||||
Icy Planet
|
||||
|
||||
Icy Planet
|
||||
|
||||
[alan@workstation ~]$ ls -l
|
||||
total 8
|
||||
-rw-rw---- 1 alan alan 12 May 1 12:32 Hoth
|
||||
-rw-rw---- 1 alan alan 12 May 1 12:38 Naboo
|
||||
```
|
||||
|
||||
### ln
|
||||
|
||||
**ln** 指令是用来在文件之间建立链接的,[man 页面][4] 描述的 force 选项如下:
|
||||
|
||||
|
||||
```
|
||||
-f, --force
|
||||
移除当前存在的文件
|
||||
```
|
||||
|
||||
假设 Leia 公主在 维护一个 Java 应用服务器并且当前在一个有所有 Java 版本的目录里,她可能会想这么做:
|
||||
|
||||
|
||||
```
|
||||
leia@workstation:/usr/lib/java$ ls -lt
|
||||
total 28
|
||||
lrwxrwxrwx 1 leia leia 12 Mar 5 2018 jdk -> jdk1.8.0_162
|
||||
drwxr-xr-x 8 leia leia 4096 Mar 5 2018 jdk1.8.0_162
|
||||
drwxr-xr-x 8 leia leia 4096 Aug 28 2017 jdk1.8.0_144
|
||||
```
|
||||
|
||||
正如你所看到的,这里有很多个版本的 JDK 和一些符号链接指向最新版的 JDK。她接着用一个脚本来安装最新版本的 JDK。但是如果没有 force 选项的话以下命令是不会成功的:
|
||||
|
||||
|
||||
```
|
||||
tar xvzmf jdk1.8.0_181.tar.gz -C jdk1.8.0_181/
|
||||
ln -vs jdk1.8.0_181 jdk
|
||||
```
|
||||
|
||||
**tar** 命令会解压 .gz 文件到一个特定的目标目录,但 **ln** 指令会失败因为这个链接已经存在了。这样的结果是链接不会指向最新版本的 JDK:
|
||||
|
||||
|
||||
```
|
||||
leia@workstation:/usr/lib/java$ ln -vs jdk1.8.0_181 jdk
|
||||
ln: failed to create symbolic link 'jdk/jdk1.8.0_181': File exists
|
||||
leia@workstation:/usr/lib/java$ ls -lt
|
||||
total 28
|
||||
drwxr-x--- 2 leia leia 4096 May 1 15:44 jdk1.8.0_181
|
||||
lrwxrwxrwx 1 leia leia 12 Mar 5 2018 jdk -> jdk1.8.0_162
|
||||
drwxr-xr-x 8 leia leia 4096 Mar 5 2018 jdk1.8.0_162
|
||||
drwxr-xr-x 8 leia leia 4096 Aug 28 2017 jdk1.8.0_144
|
||||
```
|
||||
|
||||
她可以通过使用 force 选项强制 **ln** 更新链接,但这里她还需要使用 -n,-n 是因为这个情况下链接其实指向一个目录而非文件。这样的话,链接就会正确指向最新版本的JDK了。
|
||||
|
||||
|
||||
```
|
||||
leia@workstation:/usr/lib/java$ ln -vsnf jdk1.8.0_181 jdk
|
||||
'jdk' -> 'jdk1.8.0_181'
|
||||
leia@workstation:/usr/lib/java$ ls -lt
|
||||
total 28
|
||||
lrwxrwxrwx 1 leia leia 12 May 1 16:13 jdk -> jdk1.8.0_181
|
||||
drwxr-x--- 2 leia leia 4096 May 1 15:44 jdk1.8.0_181
|
||||
drwxr-xr-x 8 leia leia 4096 Mar 5 2018 jdk1.8.0_162
|
||||
drwxr-xr-x 8 leia leia 4096 Aug 28 2017 jdk1.8.0_144
|
||||
```
|
||||
|
||||
你可以配置 Java 应用使其一直使用在 **/usr/lib/java/jdk** 处的 JDK 而不用每次升级都要更新链接。
|
||||
|
||||
### rm
|
||||
|
||||
**rm** 指令是 remove 的缩写,叫做移除但也有一部分人喜欢叫它删除。[man 页面][5] 对 force 选项的描述如下:
|
||||
|
||||
|
||||
```
|
||||
-f, --force
|
||||
无视不存在的文件或者选项,不向用户确认
|
||||
```
|
||||
如果你尝试删除一个只读的文件,**rm** 会寻求用户的确认:
|
||||
|
||||
|
||||
```
|
||||
[alan@workstation ~]$ ls -l
|
||||
total 4
|
||||
-r--r----- 1 alan alan 16 May 1 11:38 B-wing
|
||||
[alan@workstation ~]$ rm B-wing
|
||||
rm: remove write-protected regular file 'B-wing'?
|
||||
```
|
||||
你一定要输入 **y** 或者 **n** 来回答确认才能让 **rm** 命令继续。如果你使用 force 选项,**rm** 就不会寻求你的确认而直接删除文件:
|
||||
|
||||
|
||||
```
|
||||
[alan@workstation ~]$ rm -f B-wing
|
||||
[alan@workstation ~]$ ls -l
|
||||
total 0
|
||||
[alan@workstation ~]$
|
||||
```
|
||||
|
||||
最常见的 **rm** force 选项是用来删除目录。 **-r** (递归)选项会让 **rm** 删除目录,和 force 选项结合起来,它会删除这个文件夹及其内容而无需用户确认。
|
||||
|
||||
**rm** 命令和一些选项结合起来是致命的,一直以来互联网上都有关于误用 **rm** 删除整个系统之类的玩笑和鬼故事。比如最出名的一不当心执行 **rm -rf .** 会直接删除目录和文件(没有用户确认)。
|
||||
|
||||
### userdel
|
||||
|
||||
**userdel** 指令使用来删除用户的。[man 页面][6] 是这样描述它的 force 选项的:
|
||||
|
||||
|
||||
```
|
||||
-f, --force
|
||||
这个选项会强制移除用户,即便用户当前处于登入状态。它同时还会强制
|
||||
删除用户的目录和邮件,即便这个用户目录被别人共享或者邮件卷并不只
|
||||
属于这个用户。如果 USERGROUPS_ENAB 在 /etc/login.defs 里是 yes
|
||||
并且有一个组和此用户同名的话,这个组也会被移除,即便这个组还是别
|
||||
的用户的主要用户组也一样。
|
||||
|
||||
注意:这个选项有风险并可能让系统处于不稳定状态。
|
||||
```
|
||||
|
||||
当欧比旺抵达穆斯塔法星的时候,他知道自己的使命。他需要删掉达斯·维达的用户账户——但达斯还登录在里面。
|
||||
|
||||
|
||||
```
|
||||
[root@workstation ~]# ps -fu darth
|
||||
UID PID PPID C STIME TTY TIME CMD
|
||||
darth 7663 7655 0 13:28 pts/3 00:00:00 -bash
|
||||
[root@workstation ~]# userdel darth
|
||||
userdel: user darth is currently used by process 7663
|
||||
```
|
||||
|
||||
因为达斯还登入在系统里,欧比旺需要使用 force 选项操作 **userdel**。这能强制删除正登入的用户。
|
||||
|
||||
|
||||
```
|
||||
[root@workstation ~]# userdel -f darth
|
||||
userdel: user darth is currently used by process 7663
|
||||
[root@workstation ~]# finger darth
|
||||
finger: darth: no such user.
|
||||
[root@workstation ~]# ps -fu darth
|
||||
error: user name does not exist
|
||||
```
|
||||
|
||||
正如我们所见到的一样,**finger** 和 **ps** 命令让我们确认了达斯已经被删除了。
|
||||
|
||||
### 在 Shell 脚本里使用 force
|
||||
很多指令都有 force 选项,而在 shell 脚本里他们特别游泳。因为我们经常使用脚本完成定期或者自动化的任务,避免用户输入至关重要,不然的话自动任务就无法完成了
|
||||
|
||||
我希望上面的几个例子能帮你理解在一些情况下 force 的用法。你在使用 force 或把他们写入脚本之前应当完全理解他们的作用。误用 force 会有毁灭性的后果——时常是对整个系统,甚至不仅限于一台设备。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/19/5/may-the-force-linux
|
||||
|
||||
作者:[Alan Formy-Duval ][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[Jerry Ling](https://github.com/Moelf)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/alanfdoss
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/fireworks_light_art_design.jpg?itok=hfx9i4By (Fireworks)
|
||||
[2]: https://www.starwars.com/star-wars-day
|
||||
[3]: http://man7.org/linux/man-pages/man1/cp.1.html
|
||||
[4]: http://man7.org/linux/man-pages/man1/ln.1.html
|
||||
[5]: http://man7.org/linux/man-pages/man1/rm.1.html
|
||||
[6]: http://man7.org/linux/man-pages/man8/userdel.8.html
|
@ -0,0 +1,104 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (zhs852)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Change Power Modes in Ubuntu with Slimbook Battery Optimizer)
|
||||
[#]: via: (https://itsfoss.com/slimbook-battry-optimizer-ubuntu/)
|
||||
[#]: author: Abhishek Prakash https://itsfoss.com/author/abhishek/)
|
||||
|
||||
在 Ubuntu 中使用 Slimbook Battery Optimizer 切换电源模式
|
||||
======
|
||||
|
||||
> Slimbook Battery Optimizer 是一个美观实用的指示器小程序,它可以让你你在安装 Linux 的笔记本上快速切换电源模式来延长续航时间。
|
||||
|
||||
[Slimbook][1] 是一个销售 [预装 Linux 的笔电][2] 的西班牙电脑制造商,他们发布了一款好用的小程序,用来在基于 Ubuntu 的 Linux 发行版下调整电池性能。
|
||||
|
||||
因为 Slimbook 销售他们自己的 Linux 系统,所以他们制作了一些在 Linux 上用于调整他们自己硬件性能的小工具。Battery Optimizer 就是这样一个工具。
|
||||
|
||||
要使用这个实用小程序,你不必购买 Slimbook 的产品,因为 Slimbook 已经将它在 [他们的官方 PPA 源][3] 发行了。
|
||||
|
||||
### Slimbook Battery Optimizer 简介
|
||||
|
||||
这个程序叫 Slimbook Battery。它是一个常驻顶栏的指示器小程序,使得你可以快速切换电源模式。
|
||||
|
||||
![Slimbook Battery Mode Ubuntu][4]
|
||||
|
||||
你可能在 Windows 中见过类似的程序。Slimbook Battery 和它们一样,提供了类似的电源计划:
|
||||
|
||||
* 节能:最大程度延长电池续航时间
|
||||
* 平衡:性能与节能间的最佳平衡
|
||||
* 高性能:最大程度提高性能
|
||||
|
||||
你可以在高级模式中配置这些模式:
|
||||
|
||||
![配置多种多样的电源模式][5]
|
||||
|
||||
如果你觉得你把设置调乱了,你可以用“恢复默认设置”的按钮还原它。
|
||||
|
||||
你也可以修改像程序自启或默认电源模式这样的通用设置。
|
||||
|
||||
![Slimbook Battery 通用设置][6]
|
||||
|
||||
Slimbook 有专门为多种电源管理参数提供的页面。如果你希望自己配置,请参照 [此页][7]。
|
||||
|
||||
不过,我认为 Slimbook 的界面需要一些改进。例如,某些页面上的“问题标记”的图标应该改为可点击的,以此提供更多信息。然而,在我写这篇文章时,那个标记仍然无法点击。
|
||||
|
||||
总的来说,Slimbook Battery 是一个小巧精美的软件,你可以用它来快速切换电源模式。如果你决定在 Ubuntu 及其衍生发行版上(比如 Linux Mint 或 elementary OS 等),你可以使用官方 [PPA 源][8]。
|
||||
|
||||
说个题外话,推荐阅读大家阅读 [Ubuntu 论坛被入侵,用户数据被盗取][9] 这篇文章。
|
||||
|
||||
#### 在基于 Ubuntu 的发行版上安装 Slimbook Battery
|
||||
|
||||
打开终端,一步一步地使用以下命令:
|
||||
|
||||
```
|
||||
sudo add-apt-repository ppa:slimbook/slimbook
|
||||
sudo apt update
|
||||
sudo apt install slimbookbattery
|
||||
```
|
||||
|
||||
安装好之后,在菜单中搜索 Slimbook Battery:
|
||||
|
||||
![启动 Slimbook Battery Optimizer][10]
|
||||
|
||||
在你点击它之后,你会发现它出现在了顶栏。你可以在这里选择你希望使用的电源模式。
|
||||
|
||||
![Slimbook Battery 电源模式][4]
|
||||
|
||||
#### 卸载 Slimbook Battery
|
||||
|
||||
如果你不再使用它,你可以通过以下命令来卸载它:
|
||||
|
||||
```
|
||||
sudo apt remove slimbookbattery
|
||||
sudo add-apt-repository -r ppa:slimbook/slimbook
|
||||
```
|
||||
|
||||
在我看来,这样的应用程序为某些特定的目的服务,这是值得鼓励的。这个工具给了你一条调整电源模式的捷径,和调整性能的更多选项。
|
||||
|
||||
你用过 Slimbook Battery 吗?你觉得它如何?
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://itsfoss.com/slimbook-battry-optimizer-ubuntu/
|
||||
|
||||
作者:[Abhishek Prakash][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[zhs852](https://github.com/zhs852)
|
||||
校对:[校对者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://slimbook.es/en/
|
||||
[2]: https://itsfoss.com/get-linux-laptops/
|
||||
[3]: https://launchpad.net/~slimbook/+archive/ubuntu/slimbook
|
||||
[4]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2019/05/slimbook-battery-mode-ubuntu.jpg?resize=800%2C400&ssl=1
|
||||
[5]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2019/05/slimbook-battery-optimizer-2.jpg?ssl=1
|
||||
[6]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2019/05/slimbook-battery-optimizer-1.jpg?ssl=1
|
||||
[7]: https://slimbook.es/en/tutoriales/aplicaciones-slimbook/398-slimbook-battery-3-application-for-optimize-battery-of-your-laptop
|
||||
[8]: https://itsfoss.com/ppa-guide/
|
||||
[9]: https://itsfoss.com/ubuntu-forums-hacked-again/
|
||||
[10]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2019/05/slimbook-battery-optimizer.jpg?ssl=1
|
Loading…
Reference in New Issue
Block a user