mirror of
https://github.com/LCTT/TranslateProject.git
synced 2025-02-16 00:21:12 +08:00
commit
09488b29f1
@ -74,7 +74,6 @@ gunzip -c file1.gz > /home/himanshu/file1
|
||||
> `gunzip` 在命令行接受一系列的文件,并且将每个文件内容以正确的魔法数开始,且后缀名为 `.gz`、`-gz`、`.z`、`-z` 或 `_z` (忽略大小写)的压缩文件,用未压缩的文件替换它,并删除其原扩展名。 `gunzip` 也可识别一些特殊扩展名的压缩文件,如 `.tgz` 和 `.taz` 分别是 `.tar.gz` 和 `.tar.Z` 的缩写。在压缩时,`gzip` 在必要情况下使用 `.tgz` 作为扩展名,而不是只截取掉 `.tar` 后缀。
|
||||
|
||||
> `gunzip` 目前可以解压 `gzip`、`zip`、`compress`、`compress -H`(`pack`)产生的文件。`gunzip` 自动检测输入文件格式。在使用前两种压缩格式时,`gunzip` 会检验 32 位循环冗余校验码(CRC)。对于 pack 包,`gunzip` 会检验压缩长度。标准压缩格式在设计上不允许相容性检测。不过 `gunzip` 有时可以检测出坏的 `.Z` 文件。如果你解压 `.Z` 文件时出错,不要因为标准解压没报错就认为 `.Z` 文件一定是正确的。这通常意味着标准解压过程不检测它的输入,而是直接产生一个错误的输出。SCO 的 `compress -H` 格式(lzh 压缩方法)不包括 CRC 校验码,但也允许一些相容性检查。
|
||||
```
|
||||
|
||||
### 结语
|
||||
|
@ -1,14 +1,17 @@
|
||||
CIO 真正需要 DevOps 团队做什么?
|
||||
======
|
||||
IT 领导者可以从大量的 [DevOps][1] 材料和 [向 DevOps 转变][2] 所要求的文化挑战中学习。但是,你在一个 DevOps 团队面对长期或短期挑战的调整中 —— 一个 CIO 真正需要他们做的是什么呢?
|
||||
|
||||
> DevOps 团队需要 IT 领导者关注三件事:沟通、技术债务和信任。
|
||||
|
||||
![](https://enterprisersproject.com/sites/default/files/styles/620x350/public/cio_cloud_2.png?itok=wGdeAHVn)
|
||||
|
||||
IT 领导者可以从大量的 [DevOps][1] 材料和 [向 DevOps 转变][2] 所要求的文化挑战中学习。但是,你在一个 DevOps 团队面对长期或短期的团结挑战的调整中 —— 一个 CIO 真正需要他们做的是什么呢?
|
||||
|
||||
在我与 DevOps 团队成员的谈话中,我听到的其中一些内容让你感到非常的意外。DevOps 专家(无论是内部团队的还是外部团队的)都希望将下列的事情放在你的 CIO 优先关注的级别。
|
||||
|
||||
### 1. 沟通
|
||||
|
||||
第一个也是最重要的一个,DevOps 专家需要面对面的沟通。一个经验丰富的 DevOps 团队是非常了解当前 DevOps 的趋势,以及成功、和失败的经验,并且他们非常乐意去分享这些信息。表达 DevOps 的概念是很困难的,因此,要在这种新的工作关系中保持开放,定期(不用担心,不用每周)讨论有关你的 IT 的当前状态,如何评价你的沟通环境,以及你的整体的 IT 产业。
|
||||
|
||||
**[想从领导 DevOps 的 CIO 们处学习更多的知识吗?查看我们的综合资源,[DevOps: IT 领导者指南][3]。 ]**
|
||||
第一个也是最重要的一个,DevOps 专家需要面对面的沟通。一个经验丰富的 DevOps 团队是非常了解当前 DevOps 的趋势,以及成功和失败的经验,并且他们非常乐意去分享这些信息。表达 DevOps 的概念是很困难的,因此,要在这种新的工作关系中保持开放,定期(不用担心,不用每周)讨论有关你的 IT 的当前状态,如何评价你的沟通环境,以及你的整体的 IT 产业。
|
||||
|
||||
相反,你应该准备好与 DevOps 团队去共享当前的业务需求和目标。业务不再是独立于 IT 的东西:它们现在是驱动 IT 发展的重要因素,并且 IT 决定了你的业务需求和目标运行的效果如何。
|
||||
|
||||
@ -16,19 +19,17 @@ IT 领导者可以从大量的 [DevOps][1] 材料和 [向 DevOps 转变][2] 所
|
||||
|
||||
### 2. 降低技术债务
|
||||
|
||||
第二,力争更好地理解技术债务,并在 DevOps 中努力降低它。你的 DevOps 团队面对的工作都非常难。在这种情况下,技术债务是指在一个庞大的、不可持续的环境(查看 Rube Goldberg)之中,通过维护和增加新功能而占用的人力资源和基础设备资源。
|
||||
第二,力争更好地理解技术债务,并在 DevOps 中努力降低它。你的 DevOps 团队都工作于一线。这里,“技术债务”是指在一个庞大的、不可持续发展的环境之中,通过维护和增加新功能而占用的人力资源和基础设备资源(查看 Rube Goldberg)。
|
||||
|
||||
常见的 CIO 问题包括:
|
||||
CIO 常见的问题包括:
|
||||
|
||||
* 为什么我们要用一种新方法去做这件事情?
|
||||
* 为什么我们要在它上面花费时间和金钱?
|
||||
* 如果这里没有新功能,只是现有组件实现了自动化,那么我们的收益是什么?
|
||||
|
||||
“如果没有坏,就不要去修理它”,这样的事情是可以理解的。但是,如果你正在路上好好的开车,而每个人都加速超过你,这时候,你的环境就被破坏了。持续投入宝贵的资源去支撑或扩张拼凑起来的环境。
|
||||
|
||||
|
||||
"如果没有坏,就不要去修理它“ ,这样的事情是可以理解的。但是,如果你正在路上好好的开车,而每个人都加速超过你,这时候,你的环境就被破坏了。持续投入宝贵的资源去支撑或扩张拼凑起来的环境。
|
||||
|
||||
选择妥协,并且一个接一个的打补丁,以这种方式去处理每个独立的问题,结果将从一开始就变得很糟糕 —— 在一个不能支撑建筑物的地基上,一层摞一层地往上堆。事实上,这种方法就像不断地在电脑中插入坏磁盘一样。迟早有一天,面对出现的问题,你将会毫无办法。在外面持续增加的压力下,整个事情将变得一团糟,完全吞噬掉你的资源。
|
||||
选择妥协,并且一个接一个的打补丁,以这种方式去处理每个独立的问题,结果将从一开始就变得很糟糕 —— 在一个不能支撑建筑物的地基上,一层摞一层地往上堆。事实上,这种方法就像不断地在电脑中插入坏磁盘一样。迟早有一天,面对出现的问题你将会毫无办法。在外面持续增加的压力下,整个事情将变得一团糟,完全吞噬掉你的资源。
|
||||
|
||||
这种情况下,解决方案就是:自动化。使用自动化的结果是良好的可伸缩性 —— 每个维护人员在 IT 环境的维护和增长方面花费更少的努力。如果增加人力资源是实现业务增长的唯一办法,那么,可伸缩性就是白日做梦。
|
||||
|
||||
@ -36,7 +37,7 @@ IT 领导者可以从大量的 [DevOps][1] 材料和 [向 DevOps 转变][2] 所
|
||||
|
||||
### 3. 信任
|
||||
|
||||
最后,相信你的 DevOps 团队并且一定要理解他们。DevOps 专家也知道这个要求很难,但是他们必须有你的强大支持和你参与实践的意愿。因为 DevOps 团队持续改进你的 IT 环境,他们自身也在不断地适应这些变化的技术,而这些变化通常正是 “你要去学习的经验”。
|
||||
最后,相信你的 DevOps 团队并且一定要理解他们。DevOps 专家也知道这个要求很难,但是他们必须得到你的强大支持和你积极参与的意愿。因为 DevOps 团队持续改进你的 IT 环境,他们自身也在不断地适应这些变化的技术,而这些变化通常正是 “你要去学习的经验”。
|
||||
|
||||
倾听,倾听,倾听他们,并且相信他们。DevOps 的改变是非常有价值的,而且也是值的去投入时间和金钱的。它可以提高效率、生产力、和业务响应能力。信任你的 DevOps 团队,并且给予他们更多的自由,实现更高效率的 IT 改进。
|
||||
|
||||
@ -48,7 +49,7 @@ via: https://enterprisersproject.com/article/2017/12/what-devops-teams-really-ne
|
||||
|
||||
作者:[John Allessio][a]
|
||||
译者:[qhwdw](https://github.com/qhwdw)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
@ -0,0 +1,175 @@
|
||||
使用 GitHub 和 Python 实现持续部署
|
||||
======
|
||||
|
||||
![](https://fedoramagazine.org/wp-content/uploads/2018/03/cd-github-python-945x400.jpg)
|
||||
|
||||
借助 GitHub 的<ruby>网络钩子<rt>webhook</rt></ruby>,开发者可以创建很多有用的服务。从触发一个 Jenkins 实例上的 CI(持续集成) 任务到配置云中的机器,几乎有着无限的可能性。这篇教程将展示如何使用 Python 和 Flask 框架来搭建一个简单的持续部署(CD)服务。
|
||||
|
||||
在这个例子中的持续部署服务是一个简单的 Flask 应用,其带有接受 GitHub 的<ruby>网络钩子<rt>webhook</rt></ruby>请求的 REST <ruby>端点<rt>endpoint</rt></ruby>。在验证每个请求都来自正确的 GitHub 仓库后,服务器将<ruby>拉取<rt>pull</rt></ruby>更改到仓库的本地副本。这样每次一个新的<ruby>提交<rt>commit</rt></ruby>推送到远程 GitHub 仓库,本地仓库就会自动更新。
|
||||
|
||||
### Flask web 服务
|
||||
|
||||
用 Flask 搭建一个小的 web 服务非常简单。这里可以先看看项目的结构。
|
||||
|
||||
```
|
||||
├── app
|
||||
│ ├── __init__.py
|
||||
│ └── webhooks.py
|
||||
├── requirements.txt
|
||||
└── wsgi.py
|
||||
```
|
||||
|
||||
首先,创建应用。应用代码在 `app` 目录下。
|
||||
|
||||
两个文件(`__init__.py` 和 `webhooks.py`)构成了 Flask 应用。前者包含有创建 Flask 应用并为其添加配置的代码。后者有<ruby>端点<rt>endpoint</rt></ruby>逻辑。这是该应用接收 GitHub 请求数据的地方。
|
||||
|
||||
这里是 `app/__init__.py` 的内容:
|
||||
|
||||
```
|
||||
import os
|
||||
from flask import Flask
|
||||
|
||||
from .webhooks import webhook
|
||||
|
||||
def create_app():
|
||||
""" Create, configure and return the Flask application """
|
||||
|
||||
app = Flask(__name__)
|
||||
app.config['GITHUB_SECRET'] = os.environ.get('GITHUB_SECRET')
|
||||
app.config['REPO_PATH'] = os.environ.get('REPO_PATH')
|
||||
app.register_blueprint(webhook)
|
||||
|
||||
return(app)
|
||||
```
|
||||
|
||||
该函数创建了两个配置变量:
|
||||
|
||||
* `GITHUB_SECRET` 保存一个密码,用来认证 GitHub 请求。
|
||||
* `REPO_PATH` 保存了自动更新的仓库路径。
|
||||
|
||||
这份代码使用<ruby>[Flask 蓝图][1]<rt>Flask Blueprints</rt></ruby>来组织应用的<ruby>端点<rt>endpoint</rt></ruby>。使用蓝图可以对 API 进行逻辑分组,使应用程序更易于维护。通常认为这是一种好的做法。
|
||||
|
||||
这里是 `app/webhooks.py` 的内容:
|
||||
|
||||
```
|
||||
import hmac
|
||||
from flask import request, Blueprint, jsonify, current_app
|
||||
from git import Repo
|
||||
|
||||
webhook = Blueprint('webhook', __name__, url_prefix='')
|
||||
|
||||
@webhook.route('/github', methods=['POST'])
|
||||
def handle_github_hook():
|
||||
""" Entry point for github webhook """
|
||||
|
||||
signature = request.headers.get('X-Hub-Signature')
|
||||
sha, signature = signature.split('=')
|
||||
|
||||
secret = str.encode(current_app.config.get('GITHUB_SECRET'))
|
||||
|
||||
hashhex = hmac.new(secret, request.data, digestmod='sha1').hexdigest()
|
||||
if hmac.compare_digest(hashhex, signature):
|
||||
repo = Repo(current_app.config.get('REPO_PATH'))
|
||||
origin = repo.remotes.origin
|
||||
origin.pull('--rebase')
|
||||
|
||||
commit = request.json['after'][0:6]
|
||||
print('Repository updated with commit {}'.format(commit))
|
||||
return jsonify({}), 200
|
||||
```
|
||||
|
||||
首先代码创建了一个新的蓝图 `webhook`。然后它使用 Flask `route` 为蓝图添加了一个端点。任何请求 `/GitHub` URL 端点的 POST 请求都将调用这个路由。
|
||||
|
||||
#### 验证请求
|
||||
|
||||
当服务在该端点上接到请求时,首先它必须验证该请求是否来自 GitHub 以及来自正确的仓库。GitHub 在请求头的 `X-Hub-Signature` 中提供了一个签名。该签名由一个密码(`GITHUB_SECRET`),请求体的 HMAC 十六进制摘要,并使用 `sha1` 哈希生成。
|
||||
|
||||
为了验证请求,服务需要在本地计算签名并与请求头中收到的签名做比较。这可以由 `hmac.compare_digest` 函数完成。
|
||||
|
||||
#### 自定义钩子逻辑
|
||||
|
||||
在验证请求后,现在就可以处理了。这篇教程使用 [GitPython][3] 模块来与 git 仓库进行交互。GitPython 模块中的 `Repo` 对象用于访问远程仓库 `origin`。该服务在本地拉取 `origin` 仓库的最新更改,还用 `--rebase` 选项来避免合并的问题。
|
||||
|
||||
调试打印语句显示了从请求体收到的短提交哈希。这个例子展示了如何使用请求体。更多关于请求体的可用数据的信息,请查询 [GitHub 文档][4]。
|
||||
|
||||
最后该服务返回了一个空的 JSON 字符串和 200 的状态码。这用于告诉 GitHub 的网络钩子服务已经收到了请求。
|
||||
|
||||
### 部署服务
|
||||
|
||||
为了运行该服务,这个例子使用 [gunicorn][5] web 服务器。首先安装服务依赖。在支持的 Fedora 服务器上,以 [sudo][6] 运行这条命令:
|
||||
|
||||
```
|
||||
sudo dnf install python3-gunicorn python3-flask python3-GitPython
|
||||
```
|
||||
|
||||
现在编辑 gunicorn 使用的 `wsgi.py` 文件来运行该服务:
|
||||
|
||||
```
|
||||
from app import create_app
|
||||
application = create_app()
|
||||
```
|
||||
|
||||
为了部署服务,使用以下命令克隆这个 git [仓库][7]或者使用你自己的 git 仓库:
|
||||
|
||||
```
|
||||
git clone https://github.com/cverna/github_hook_deployment.git /opt/
|
||||
```
|
||||
|
||||
下一步是配置服务所需的环境变量。运行这些命令:
|
||||
|
||||
```
|
||||
export GITHUB_SECRET=asecretpassphraseusebygithubwebhook
|
||||
export REPO_PATH=/opt/github_hook_deployment/
|
||||
```
|
||||
|
||||
这篇教程使用网络钩子服务的 GitHub 仓库,但你可以使用你想要的不同仓库。最后,使用这些命令开启该 web 服务:
|
||||
|
||||
```
|
||||
cd /opt/github_hook_deployment/
|
||||
gunicorn --bind 0.0.0.0 wsgi:application --reload
|
||||
```
|
||||
|
||||
这些选项中绑定了 web 服务的 IP 地址为 `0.0.0.0`,意味着它将接收来自任何的主机的请求。选项 `--reload` 确保了当代码更改时重启 web 服务。这就是持续部署的魔力所在。每次接收到 GitHub 请求时将拉取仓库的最近更新,同时 gunicore 检测这些更改并且自动重启服务。
|
||||
|
||||
**注意: **为了能接收到 GitHub 请求,web 服务必须部署到具有公有 IP 地址的服务器上。做到这点的简单方法就是使用你最喜欢的云提供商比如 DigitalOcean,AWS,Linode等。
|
||||
|
||||
### 配置 GitHub
|
||||
|
||||
这篇教程的最后一部分是配置 GitHub 来发送网络钩子请求到 web 服务上。这是持续部署的关键。
|
||||
|
||||
从你的 GitHub 仓库的设置中,选择 Webhook 菜单,并且点击“Add Webhook”。输入以下信息:
|
||||
|
||||
* “Payload URL”: 服务的 URL,比如 `<http://public_ip_address:8000/github>`
|
||||
* “Content type”: 选择 “application/json”
|
||||
* “Secret”: 前面定义的 `GITHUB_SECRET` 环境变量
|
||||
|
||||
然后点击“Add Webhook” 按钮。
|
||||
|
||||
![][8]
|
||||
|
||||
现在每当该仓库发生推送事件时,GitHub 将向服务发送请求。
|
||||
|
||||
### 总结
|
||||
|
||||
这篇教程向你展示了如何写一个基于 Flask 的用于接收 GitHub 的网络钩子请求,并实现持续集成的 web 服务。现在你应该能以本教程作为起点来搭建对自己有用的服务。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://fedoramagazine.org/continuous-deployment-github-python/
|
||||
|
||||
作者:[Clément Verna][a]
|
||||
选题:[lujun9972](https://github.com/lujun9972)
|
||||
译者:[kimii](https://github.com/kimii)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:https://fedoramagazine.org
|
||||
[1]:http://flask.pocoo.org/docs/0.12/blueprints/
|
||||
[2]:https://en.wikipedia.org/wiki/HMAC
|
||||
[3]:https://gitpython.readthedocs.io/en/stable/index.html
|
||||
[4]:https://developer.github.com/v3/activity/events/types/#webhook-payload-example-26
|
||||
[5]:http://gunicorn.org/
|
||||
[6]:https://fedoramagazine.org/howto-use-sudo/
|
||||
[7]:https://github.com/cverna/github_hook_deployment.git
|
||||
[8]:https://fedoramagazine.org/wp-content/uploads/2018/03/Screenshot-2018-3-26-cverna-github_hook_deployment1.png
|
@ -1,3 +1,5 @@
|
||||
translating by MZqk
|
||||
|
||||
What’s next in IT automation: 6 trends to watch
|
||||
======
|
||||
|
||||
|
@ -1,76 +0,0 @@
|
||||
translating---geekpi
|
||||
|
||||
How to find files in Linux
|
||||
======
|
||||
|
||||
![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/find-file-linux-code_magnifying_glass_zero.png?itok=E2HoPDg0)
|
||||
If you're a Windows user or a non-power-user of OSX, you probably use a GUI to find files. You may also find the interface limited, frustrating, or both, and have learned to excel at organizing things and remembering the exact order of your files. You can do that in Linux, too—but you don't have to.
|
||||
|
||||
One of the best things about Linux is that it offers a variety of ways to do things. You can open any file manager and `ctrl`+`f`, you can use the program you are in to open files manually, or you can simply start typing letters and it'll filter the current directory listing.
|
||||
|
||||
![Screenshot of how to find files in Linux with Ctrl+F][2]
|
||||
|
||||
Screenshot of how to find files in Linux with Ctrl+F
|
||||
|
||||
But what if you don't know where your file is and don't want to search the entire disk? Linux is well-tooled for this and a variety of other use-cases.
|
||||
|
||||
### Finding program locations by command name
|
||||
|
||||
The Linux file system can seem daunting if you're used to putting things wherever you like. For me, one of the hardest things to get used to was finding where programs are supposed to live.
|
||||
|
||||
For example, `which bash` will usually return `/bin/bash`, but if you download a program and it doesn't appear in your menus, the `which` command can be a great tool.
|
||||
|
||||
A similar utility is the `locate` command, which I find useful for finding configuration files. I don't like typing in program names because simple ones like `locate php` often offer many results that need to be filtered further.
|
||||
|
||||
For more information about `locate` and `which`, see the `man` pages:
|
||||
|
||||
* `man which`
|
||||
* `man locate`
|
||||
|
||||
|
||||
|
||||
### Find
|
||||
|
||||
The `find` utility offers much more advanced functionality. Below is an example from a script I've installed on a number of servers that I administer to ensure that a specific pattern of file (also known as a glob) exists for only five days and all files older than that are deleted. (Since its last modification, a decimal is used to account for up to 240 minutes difference.)
|
||||
```
|
||||
find ./backup/core-files*.tar.gz -mtime +4.9 -exec rm {} \;
|
||||
|
||||
```
|
||||
|
||||
The `find` utility has many advanced use-cases, but most common is executing commands on results without chaining and filtering files by type, creation, and modification date.
|
||||
|
||||
Another interesting use of `find` is to find all files with executable permissions. This can help ensure that nobody is installing bitcoin miners or botnets on your expensive servers.
|
||||
```
|
||||
find / -perm /+x
|
||||
|
||||
```
|
||||
|
||||
For more information on `find`, see the `man` page using `man find.`
|
||||
|
||||
### Grep
|
||||
|
||||
Want to find a file by its contents? Linux has it covered. You can use many Linux utilities to efficiently search for files that match a pattern, but `grep` is one that I use often.
|
||||
|
||||
Suppose you have an application that's delivering error messages with a code reference and stack trace. You find these in your logs. Grepping is not always the go-to, but I always `grep -R` if the issue is with a supplied value.
|
||||
|
||||
An increasing number of IDEs are implementing find functions, but if you're accessing a remote system or for whatever reason don't have a GUI, or if you want to iterate in-place, then use: `grep -R {searchterm}` or on systems supporting `egrep` alias; just add `-e` flag to command `egrep -r {regex-pattern}`.
|
||||
|
||||
I used this technique when patching the `dhcpcd5` in [Raspbian][3] last year so I could continue to operate a network access point on newer Debian releases from the [Raspberry Pi Foundation][4].
|
||||
|
||||
What tips help you search for files more efficiently on Linux?
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/18/4/how-find-files-linux
|
||||
|
||||
作者:[Lewis Cowles][a]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
选题:[lujun9972](https://github.com/lujun9972)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:https://opensource.com/users/lewiscowles1986
|
||||
[2]:https://opensource.com/sites/default/files/styles/panopoly_image_original/public/uploads/find-files-in-linux-ctrlf.png?itok=1gf9kIut (Screenshot of how to find files in Linux with Ctrl+F)
|
||||
[3]:https://www.raspbian.org/
|
||||
[4]:https://www.raspberrypi.org/
|
@ -1,3 +1,6 @@
|
||||
Translating by MjSeven
|
||||
|
||||
|
||||
12 Git tips for Git's 12th birthday
|
||||
======
|
||||
![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/party_anniversary_flag_birthday_celebrate.jpg?itok=KqfMENa7)
|
||||
|
@ -1,3 +1,5 @@
|
||||
translating---geekpi
|
||||
|
||||
The Shuf Command Tutorial With Examples For Beginners
|
||||
======
|
||||
|
||||
|
@ -1,21 +1,17 @@
|
||||
Translating by FelixYFZ
|
||||
How to test internet speed in Linux terminal
|
||||
如何在Linux的终端测试网速
|
||||
======
|
||||
Learn how to use speedtest cli tool to test internet speed in Linux terminal. Also includes one liner python command to get speed details right away.
|
||||
学习如何在Linux终端使用命令行工具测试网速,或者仅用一条python命令立刻获得网速的测试结果。
|
||||
![在Linux终端测试网速][1]
|
||||
|
||||
![test internet speed in linux terminal][1]
|
||||
我们都会在连接网络或者wifi的时候去测试网络带宽。 为什么不用我们自己的服务器!下面将会教你如何在Linux终端测试网速。
|
||||
|
||||
Most of us check the internet bandwidth speed whenever we connect to new network or wifi. So why not our servers! Here is a tutorial which will walk you through to test internet speed in Linux terminal.
|
||||
我们多数都会使用[Mb/s][2]标准来测试网速。 仅仅只是桌面上的一个简单的操作,访问他们的网站点击浏览。
|
||||
它将使用最近的服务器来扫描你的本地主机来测试网速。 如果你使用的是移动设备,他们有对应的移动端APP。但如果你使用的是只有命令行终端界面的则会有些不同。下面让我们一起看看如何在Linux的终端来测试网速。
|
||||
如果你只是想偶尔的做一次网速测试而不想去下载测试工具,那么请往下看如何使用命令完成测试。
|
||||
|
||||
Everyone of us generally uses [Speedtest by Ookla][2] to check internet speed. Its pretty simple process for a desktop. Goto their website and just click GO button. It will scans your location and speed test with nearest server. If you are on mobile, they have their app for you. But if you are on terminal with command line interface things are little different. Lets see how to check internet speed from Linux terminal.
|
||||
### 第一步:下载网速测试命令行工具。
|
||||
|
||||
If you want to speed check only once and dont want to download tool on server, jump here and see one liner command.
|
||||
|
||||
### Step 1 : Download speedtest cli tool
|
||||
|
||||
First of all, you have to download speedtest CLI tool from [github repository][3]. Now a days, its also included in many well known Linux repositories as well. If its their in yours then you can directly [install that package on your Linux distro][4].
|
||||
|
||||
Lets proceed with Github download and install process. [Install git package][4] depending on your distro. Then clone Github repo of speedtest like belwo :
|
||||
首先,你需要从github上下载网速测试命令行工具。现在,上面也包含许多其他的Linu相关的仓库,如果已经在你的库中,你可以直接在你的Linux上进行安装。 让我们继续下载和安装过程,安装的git包取决于你的Linux发行版。然后按照下面的方法来克隆Github speedtest存储库
|
||||
|
||||
```
|
||||
[root@kerneltalks ~]# git clone https://github.com/sivel/speedtest-cli.git
|
||||
@ -27,7 +23,7 @@ Resolving deltas: 100% (518/518), done.
|
||||
|
||||
```
|
||||
|
||||
It will be cloned to your present working directory. New directory named `speedtest-cli` will be created. You can see below files in it.
|
||||
它将会被克隆到你当前的工作目录,新的名为speedtest-cli的目录将会被创建,你将在新的目录下看到如下的文件。
|
||||
|
||||
```
|
||||
[root@kerneltalks ~]# cd speedtest-cli
|
||||
@ -45,13 +41,11 @@ total 96
|
||||
-rw-r--r--. 1 root root 333 Oct 7 16:55 tox.ini
|
||||
```
|
||||
|
||||
The python script `speedtest.py` is the one we will be using to check internet speed.
|
||||
名为speedtest.py的脚本文件就是用来测试网速的。你可以在/usr/bin执行环境下将这个脚本链接到一条命令以便这台机器上的所有用户都能使用。或者你可以为这个脚本创建一个命令别名这样就能让所有用户很容易使用它。
|
||||
|
||||
You can link this script for a command in /usr/bin so that all users on server can use it. Or you can even create [command alias][5] for it and it will be easy for all users to use it.
|
||||
### 运行python脚本
|
||||
|
||||
### Step 2 : Run python script
|
||||
|
||||
Now, run python script without any argument and it will search nearest server and test your internet speed.
|
||||
现在,直接运行这个脚本,不需要添加任何参数它将会搜寻最近的服务器来测试你的网速。
|
||||
|
||||
```
|
||||
[root@kerneltalks speedtest-cli]# python speedtest.py
|
||||
@ -66,13 +60,13 @@ Testing upload speed............................................................
|
||||
Upload: 323.95 Mbit/s
|
||||
```
|
||||
|
||||
Oh! Dont amaze with speed. 😀 I am on [AWS EC2 Linux server][6]. Thats the bandwidth of Amazon data center! 🙂
|
||||
Oh! 不要被这个网速惊讶道。😀我在AWE EX2的服务器上。那是亚马逊数据中心的网速!🙂
|
||||
|
||||
### Different options with script
|
||||
### 这个脚本可以添加有不同的选项。
|
||||
|
||||
Few options which might be useful are as below :
|
||||
下面的几个选项对这个脚本可能会很有用处:
|
||||
|
||||
**To search speedtest servers** nearby your location use `--list` switch and `grep` for your location name.
|
||||
** 用搜寻你附近的网路测试服务器,使用 --list和grep加上本地名来列出所有附件的服务器。
|
||||
|
||||
```
|
||||
[root@kerneltalks speedtest-cli]# python speedtest.py --list | grep -i mumbai
|
||||
@ -90,11 +84,10 @@ Few options which might be useful are as below :
|
||||
6403) YOU Broadband India Pvt Ltd., Mumbai (Mumbai, India) [1.15 km]
|
||||
```
|
||||
|
||||
You can see here, first column is server identifier followed by name of company hosting that server, location and finally its distance from your location.
|
||||
然后你就能从搜寻结果中看到,第一列是服务器识别号,紧接着是公司的名称和所在地,最后是离你的距离。
|
||||
|
||||
**To test internet speed using specific server** use `--server` switch and server identifier from previous output as argument.
|
||||
|
||||
```
|
||||
** 如果要使用指定的服务器来测试网速,后面跟上命令 --server 加上服务器的识别号。
|
||||
|
||||
[root@kerneltalks speedtest-cli]# python speedtest.py --server 2827
|
||||
Retrieving speedtest.net configuration...
|
||||
Testing from Amazon (35.154.184.126)...
|
||||
@ -107,7 +100,7 @@ Testing upload speed............................................................
|
||||
Upload: 69.25 Mbit/s
|
||||
```
|
||||
|
||||
**To get share link of your speed test** , use `--share` switch. It will give you URL of your test hosted on speedtest website. You can share this URL.
|
||||
** 如果想得到你的测试结果的共享链接,使用命令 --share,你将会得到测试结果的链接。
|
||||
|
||||
```
|
||||
[root@kerneltalks speedtest-cli]# python speedtest.py --share
|
||||
@ -124,21 +117,20 @@ Share results: http://www.speedtest.net/result/6687428141.png
|
||||
|
||||
```
|
||||
|
||||
Observe last line which includes URL of your test result. If I download that image its the one below :
|
||||
输出中的最后一行就是你的测试结果的链接。下载下来的图片内容如下 :
|
||||
|
||||
![Speedtest result on Linux][7]
|
||||
|
||||
Thats it! But hey if you dont want all this technical jargon, you can even use below one liner to get speed test done right away.
|
||||
这就是全部的过程!如果你不想子结果中看到这些技术术语,你也可以使用如下的命令迅速测出你的网速
|
||||
|
||||
### Internet speed test using one liner in terminal
|
||||
### 要想在终端使用一条命令测试网速。
|
||||
|
||||
We are going to use [curl tool ][8]to fetch above said python script online and supply it to python for execution on the go!
|
||||
我们将使用Curl工具来在线抓取上面使用的python脚本然后直接用python执行脚本
|
||||
|
||||
```
|
||||
[root@kerneltalks ~]# curl -s https://raw.githubusercontent.com/sivel/speedtest-cli/master/speedtest.py | python -
|
||||
```
|
||||
|
||||
Above command will run the script and show you result on screen!
|
||||
上面的脚本将会运行脚本输出结果到屏幕上。
|
||||
|
||||
```
|
||||
[root@kerneltalks speedtest-cli]# curl -s https://raw.githubusercontent.com/sivel/speedtest-cli/master/speedtest.py | python -
|
||||
@ -153,14 +145,12 @@ Testing upload speed............................................................
|
||||
Upload: 355.84 Mbit/s
|
||||
```
|
||||
|
||||
I tested this tool on RHEL 7 server but process is same on Ubuntu, Debian, Fedora or CentOS.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://kerneltalks.com/tips-tricks/how-to-test-internet-speed-in-linux-terminal/
|
||||
这是在RHEL 7上执行的结果,在Ubuntu,Debian, Fedora或者Centos上一样可以执行。
|
||||
|
||||
作者:[Shrikant Lavhate][a]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
译者:[FelixYFZ ](https://github.com/FelixYFZ)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
@ -1,185 +0,0 @@
|
||||
使用 Github 和 Python 实现持续部署
|
||||
======
|
||||
|
||||
![](https://fedoramagazine.org/wp-content/uploads/2018/03/cd-github-python-945x400.jpg)
|
||||
借助 Github 的 webhook(网络钩子)开发者可以创建很多有用的服务。从触发一个 Jenkins 实例上的 CI(持续集成) 任务到配置云中的机器,几乎有着无限的可能性。这篇教程将展示如何使用 Python 和 Flask 框架来搭建一个简单的持续部署服务。
|
||||
|
||||
在这个例子中的持续部署服务是一个简单的 Flask 应用,其带有接受 Github 的 webhook 请求的 REST 端点(endpoint)。在验证每个请求都来自正确的 Github 仓库后,服务器将拉取(pull)更改到仓库的本地副本。这样每次一个新的提交(commit)推送到远程 Github 仓库,本地仓库就会自动更新。
|
||||
|
||||
### Flask web 服务
|
||||
|
||||
用 Flask 搭建一个小的 web 服务非常简单。这里可以先看看项目的结构。
|
||||
```
|
||||
├── app
|
||||
│ ├── __init__.py
|
||||
│ └── webhooks.py
|
||||
├── requirements.txt
|
||||
└── wsgi.py
|
||||
|
||||
```
|
||||
|
||||
首先,创建应用。应用代码在 app 目录下。
|
||||
|
||||
两个文件(__init__.py 和 webhooks.py)构成了 Flask 应用。前者有创建 Flask 应用并为其添加配置的代码。后者有端点(endpoint)逻辑。这是该应用接收 Github 请求的地方。
|
||||
|
||||
这里是 app/__init__.py 的内容:
|
||||
```
|
||||
import os
|
||||
from flask import Flask
|
||||
|
||||
from .webhooks import webhook
|
||||
|
||||
def create_app():
|
||||
""" Create, configure and return the Flask application """
|
||||
|
||||
app = Flask(__name__)
|
||||
app.config['GITHUB_SECRET'] = os.environ.get('GITHUB_SECRET')
|
||||
app.config['REPO_PATH'] = os.environ.get('REPO_PATH')
|
||||
app.register_blueprint(webhook)
|
||||
|
||||
return(app)
|
||||
|
||||
```
|
||||
|
||||
该函数创建了两个配置变量:
|
||||
|
||||
* **GITHUB_SECRET** 保存一个密码,用来认证 Github 请求。
|
||||
* **REPO_PATH** 保存了自动更新的仓库路径。
|
||||
|
||||
|
||||
|
||||
这份代码使用[Flask 蓝图(Blueprints)][1]来组织应用的端点(endpoint)。使用蓝图可以对 API 进行逻辑分组,使应用程序更易于维护。通常认为这是一种好的做法。
|
||||
|
||||
这里是 app/webhooks.py 的内容:
|
||||
```
|
||||
import hmac
|
||||
from flask import request, Blueprint, jsonify, current_app
|
||||
from git import Repo
|
||||
|
||||
webhook = Blueprint('webhook', __name__, url_prefix='')
|
||||
|
||||
@webhook.route('/github', methods=['POST'])
|
||||
def handle_github_hook():
|
||||
""" Entry point for github webhook """
|
||||
|
||||
signature = request.headers.get('X-Hub-Signature')
|
||||
sha, signature = signature.split('=')
|
||||
|
||||
secret = str.encode(current_app.config.get('GITHUB_SECRET'))
|
||||
|
||||
hashhex = hmac.new(secret, request.data, digestmod='sha1').hexdigest()
|
||||
if hmac.compare_digest(hashhex, signature):
|
||||
repo = Repo(current_app.config.get('REPO_PATH'))
|
||||
origin = repo.remotes.origin
|
||||
origin.pull('--rebase')
|
||||
|
||||
commit = request.json['after'][0:6]
|
||||
print('Repository updated with commit {}'.format(commit))
|
||||
return jsonify({}), 200
|
||||
|
||||
```
|
||||
|
||||
首先代码创建了一个新的蓝图 webhook。然后它使用 Flask 路由(route)为蓝图添加了一个端点。任何 URL 为 /Github 的端点的 POST 请求都将调用这个路由。
|
||||
|
||||
#### 验证请求
|
||||
|
||||
当服务收到该端点的请求时,首先它必须验证该请求是否来自 GitHub 同时来自正确的仓库。Github 在请求头的 X-Hub-Signature 中提供了一个签名。该签名由一个密码(GITHUB_SECRET),请求体的 HMAC 十六进制摘要和使用 sha1 的哈希生成。
|
||||
|
||||
为了验证请求,服务需要在本地计算签名并与请求头中收到的签名做比较。这可以由 hmac.compare_digest 函数完成。
|
||||
|
||||
#### 自定义钩子逻辑
|
||||
|
||||
在验证请求后,现在可以处理了。这篇教程使用[GitPython][3]模块来与 git 仓库进行交互。GitPython 模块中的 Repo 对象用于访问远程仓库 origin。服务在本地拉取远程仓库的最新更改,还用 -rebase 选项来避免合并的问题。
|
||||
|
||||
调试打印语句显示了从请求体收到的短提交哈希。这个例子展示了如何使用请求体。更多关于请求体的可用数据的信息,请查询[github 文档][4]。
|
||||
|
||||
最后服务返回了一个空的 JSON 字符串和 200 的状态码。这用于告诉 Github 的 webhook 服务已经收到了请求。
|
||||
|
||||
### 部署服务
|
||||
|
||||
为了运行该服务,这个例子使用 [gunicorn][5] web 服务器。首先安装服务依赖。在支持的 Fedora 服务器上,以[sudo][6]运行这条命令:
|
||||
```
|
||||
sudo dnf install python3-gunicorn python3-flask python3-GitPython
|
||||
|
||||
```
|
||||
|
||||
现在编辑 gunicorn 使用的 wsgi.py 文件来运行服务:
|
||||
```
|
||||
from app import create_app
|
||||
|
||||
application = create_app()
|
||||
|
||||
```
|
||||
|
||||
为了部署服务,使用以下命令克隆这个 git [仓库][7]或者使用你自己的 git 仓库:
|
||||
```
|
||||
git clone https://github.com/cverna/github_hook_deployment.git /opt/
|
||||
|
||||
```
|
||||
|
||||
下一步是配置服务所需的环境变量。运行这些命令:
|
||||
```
|
||||
export GITHUB_SECRET=asecretpassphraseusebygithubwebhook
|
||||
export REPO_PATH=/opt/github_hook_deployment/
|
||||
|
||||
```
|
||||
|
||||
这篇教程使用 webhook 服务的 Github 仓库,但你可以使用你想要的不同仓库。最后,使用这些命令开启 该 web 服务:
|
||||
```
|
||||
cd /opt/github_hook_deployment/
|
||||
gunicorn --bind 0.0.0.0 wsgi:application --reload
|
||||
|
||||
```
|
||||
|
||||
这些选项中绑定了 web 服务的 ip 地址为 0.0.0.0,意味着它将接收来自任何的主机的请求。选项 -reload 确保了当代码更改时重启 web 服务。这就是持续部署的魔力所在。每次接收到 Github 请求时将拉取仓库的最近更新,同时 gunicore 检测这些更改并且自动重启服务。
|
||||
|
||||
**注意: **为了能接收到 Github 请求,web 服务必须部署到具有公有 IP 地址的服务器上。做到这点的简单方法就是使用你最喜欢的云提供商比如 DigitalOcean,AWS,Linode等。
|
||||
|
||||
### 配置 Github
|
||||
|
||||
这篇教程的最后一部分是配置 Github 来发送 webhook 请求到 web 服务上。这是持续部署的关键。
|
||||
|
||||
从你的 Github 仓库的设置中,选择 Webhook 菜单,并且点击添加 Webhook。输入以下信息:
|
||||
|
||||
* **Payload URL:** 服务的 URL,比如<http://public\_ip\_address:8000/github>
|
||||
* **Content type:** 选择 application/json
|
||||
* **Secret:** 前面定义的 **GITHUB_SECRET** 环境变量
|
||||
|
||||
|
||||
|
||||
然后点击添加 Webhook 按钮。
|
||||
|
||||
![][8]
|
||||
|
||||
现在每当该仓库发生 push(推送)事件时,Github 将向服务发送请求。
|
||||
|
||||
### 总结
|
||||
|
||||
这篇教程向你展示了如何写一个基于 Flask 的用于接收 Github 的 webhook 请求和实现持续集成的 web 服务。现在你应该能以本教程作为起点来搭建对自己有用的服务。
|
||||
|
||||
#### 像这样:
|
||||
|
||||
如
|
||||
|
||||
加载中...
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://fedoramagazine.org/continuous-deployment-github-python/
|
||||
|
||||
作者:[Author Archive;Author Website;Clément Verna][a]
|
||||
译者:[kimii](https://github.com/kimii)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
选题:[lujun9972](https://github.com/lujun9972)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:https://fedoramagazine.org
|
||||
[1]:http://flask.pocoo.org/docs/0.12/blueprints/
|
||||
[2]:https://en.wikipedia.org/wiki/HMAC
|
||||
[3]:https://gitpython.readthedocs.io/en/stable/index.html
|
||||
[4]:https://developer.github.com/v3/activity/events/types/#webhook-payload-example-26
|
||||
[5]:http://gunicorn.org/
|
||||
[6]:https://fedoramagazine.org/howto-use-sudo/
|
||||
[7]:https://github.com/cverna/github_hook_deployment.git
|
||||
[8]:https://fedoramagazine.org/wp-content/uploads/2018/03/Screenshot-2018-3-26-cverna-github_hook_deployment1.png
|
74
translated/tech/20180405 How to find files in Linux.md
Normal file
74
translated/tech/20180405 How to find files in Linux.md
Normal file
@ -0,0 +1,74 @@
|
||||
如何在 Linux 中查找文件
|
||||
======
|
||||
|
||||
![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/find-file-linux-code_magnifying_glass_zero.png?itok=E2HoPDg0)
|
||||
如果你是 Windows 或 OSX 的非高级用户,那么可能使用 GUI 来查找文件。你也可能发现界面限制,令人沮丧,或者两者兼而有之,并学会组织文件并记住它们的确切顺序。你也可以在 Linux 中做到这一点 - 但你不必这样做。
|
||||
|
||||
Linux 的好处之一是它提供了多种方式来处理。你可以打开任何文件管理器或按下 `ctrl` +`f`,你也可以使用程序手动打开文件,或者你可以开始输入字母,它会过滤当前目录列表。
|
||||
|
||||
![Screenshot of how to find files in Linux with Ctrl+F][2]
|
||||
|
||||
使用 Ctrl+F 在 Linux 中查找文件的截图
|
||||
|
||||
但是如果你不知道你的文件在哪里,又不想搜索整个磁盘呢?对于这个以及其他各种情况,Linux 都很合适。
|
||||
|
||||
### 按命令名查找程序位置
|
||||
|
||||
如果你习惯随心所欲地放文件,Linux 文件系统看起来会让人望而生畏。对我而言,最难习惯的一件事是找到程序在哪里。
|
||||
|
||||
例如,`which bash` 通常会返回 `/bin/bash`,但是如果你下载了一个程序并且它没有出现在你的菜单中,`which` 命令可以是一个很好的工具。
|
||||
|
||||
一个类似的工具是 `locate` 命令,我发现它对于查找配置文件很有用。我不喜欢输入程序名称,因为像 `locate php` 这样的简单程序通常会提供很多需要进一步过滤的结果。
|
||||
|
||||
有关 `locate` 和 `which` 的更多信息,请参阅 `man` 页面:
|
||||
|
||||
* `man which`
|
||||
* `man locate`
|
||||
|
||||
|
||||
|
||||
### Find
|
||||
|
||||
`find` 工具提供了更先进的功能。以下是我安装在许多服务器上的脚本示例,我用于确保特定模式的文件(也称为 glob)仅存在五天,并且所有早于该文件的文件都将被删除。 (自上次修改以来,十进制用于计算最多 240 分钟的差异)
|
||||
```
|
||||
find ./backup/core-files*.tar.gz -mtime +4.9 -exec rm {} \;
|
||||
|
||||
```
|
||||
|
||||
`find` 工具有许多高级用法,但最常见的是对结果执行命令,而不用链式地按照类型、创建日期、修改日期过滤文件。
|
||||
|
||||
find 的另一个有趣用处是找到所有有可执行权限的文件。这有助于确保没有人在你昂贵的服务器上安装比特币挖矿程序或僵尸网络。
|
||||
```
|
||||
find / -perm /+x
|
||||
|
||||
```
|
||||
|
||||
有关 `find` 的更多信息,请使用 `man find` 参考 `man` 页面。
|
||||
|
||||
### Grep
|
||||
|
||||
想通过内容中查找文件? Linux 已经实现了。你可以使用许多 Linux 工具来高效搜索符合模式的文件,但是 `grep` 是我经常使用的工具。
|
||||
|
||||
假设你有一个程序发布代码引用和堆栈跟踪的错误消息。你要在日志中找到这些。 grep 不总是最好的方法,但如果文件是一个给定的值,我经常使用 `grep -R`。
|
||||
|
||||
越来越多的 IDE 正在实现查找功能,但是如果你正在访问远程系统或出于任何原因没有 GUI,或者如果你想在当前目录递归查找,请使用:`grep -R {searchterm} ` 或在支持 `egrep` 别名的系统上,只需将 `-e` 标志添加到命令 `egrep -r {regex-pattern}`。
|
||||
|
||||
我在去年给 [Raspbian][3] 中的 `dhcpcd5` 打补丁时使用了这种技术,这样我就可以在[树莓派基金会][4]发布新的 Debian 时继续操作网络接入点了。
|
||||
|
||||
哪些提示可帮助你在 Linux 上更有效地搜索文件?
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/18/4/how-find-files-linux
|
||||
|
||||
作者:[Lewis Cowles][a]
|
||||
译者:[geekpi](https://github.com/geekpi)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
选题:[lujun9972](https://github.com/lujun9972)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:https://opensource.com/users/lewiscowles1986
|
||||
[2]:https://opensource.com/sites/default/files/styles/panopoly_image_original/public/uploads/find-files-in-linux-ctrlf.png?itok=1gf9kIut (Screenshot of how to find files in Linux with Ctrl+F)
|
||||
[3]:https://www.raspbian.org/
|
||||
[4]:https://www.raspberrypi.org/
|
Loading…
Reference in New Issue
Block a user