mirror of
https://github.com/LCTT/TranslateProject.git
synced 2025-02-28 01:01:09 +08:00
Merge remote-tracking branch 'LCTT/master'
This commit is contained in:
commit
2cca1dc202
@ -1,8 +1,8 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (wxy)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: reviewer: (wxy)
|
||||
[#]: publisher: (wxy)
|
||||
[#]: url: (https://linux.cn/article-10860-1.html)
|
||||
[#]: subject: (21 Best Kali Linux Tools for Hacking and Penetration Testing)
|
||||
[#]: via: (https://itsfoss.com/best-kali-linux-tools/)
|
||||
[#]: author: (Ankush Das https://itsfoss.com/author/ankush/)
|
||||
@ -10,9 +10,9 @@
|
||||
用于黑客渗透测试的 21 个最佳 Kali Linux 工具
|
||||
======
|
||||
|
||||
> 最好的 Kali Linux 工具列表,它们可以让你评估 Web 服务器的安全性,并帮助你执行黑客和渗透测试。
|
||||
> 这里是最好的 Kali Linux 工具列表,它们可以让你评估 Web 服务器的安全性,并帮助你执行黑客渗透测试。
|
||||
|
||||
如果你读过 [Kali Linux 点评][1],你就知道为什么它被认为是[最好的黑客渗透测试的 Linux 发行版][2]之一,而且正如其实。它带有许多工具,使你可以更轻松地进行测试、破解以及与数字取证相关的任何其他工作。
|
||||
如果你读过 [Kali Linux 点评][1],你就知道为什么它被认为是[最好的黑客渗透测试的 Linux 发行版][2]之一,而且名副其实。它带有许多工具,使你可以更轻松地测试、破解以及进行与数字取证相关的任何其他工作。
|
||||
|
||||
它是<ruby>道德黑客<rt>ethical hacker</rt></ruby>最推荐的 Linux 发行版之一。即使你不是黑客而是网站管理员 —— 你仍然可以利用其中某些工具轻松地扫描你的网络服务器或网页。
|
||||
|
||||
@ -22,7 +22,7 @@
|
||||
|
||||
### 用于黑客渗透测试的 Kali Linux 工具
|
||||
|
||||
![Kali Linux][3]
|
||||

|
||||
|
||||
Kali Linux 预装了几种类型的工具。如果你发现有的工具没有安装,只需下载并进行设置即可。这很简单。
|
||||
|
||||
@ -30,7 +30,7 @@ Kali Linux 预装了几种类型的工具。如果你发现有的工具没有安
|
||||
|
||||
![Kali Linux Nmap][4]
|
||||
|
||||
[Nmap][5] (即 “<ruby>网络映射器<rt>Network Mapper</rt></ruby>”)是 Kali Linux 上最受欢迎的信息收集工具之一。换句话说,它可以获取有关主机的信息:其 IP 地址、操作系统检测以及类似网络安全详细信息(如开放的端口数量及其含义)。
|
||||
[Nmap][5] (即 “<ruby>网络映射器<rt>Network Mapper</rt></ruby>”)是 Kali Linux 上最受欢迎的信息收集工具之一。换句话说,它可以获取有关主机的信息:其 IP 地址、操作系统检测以及网络安全的详细信息(如开放的端口数量及其含义)。
|
||||
|
||||
它还提供防火墙规避和欺骗功能。
|
||||
|
||||
@ -50,21 +50,21 @@ WordPress 是[最好的开源 CMS][9]之一,而这个工具是最好的免费
|
||||
|
||||
如果你想知道一个 WordPress 博客是否在某种程度上容易受到攻击,[WPScan][10] 就是你的朋友。
|
||||
|
||||
此外,它还为你提供了所用的插件的详细信息。当然,一个安全性很好的博客可能不会给你很多细节,但它仍然是 WordPress 安全扫描找到潜在漏洞的最佳工具。
|
||||
此外,它还为你提供了所用的插件的详细信息。当然,一个安全性很好的博客可能不会暴露给你很多细节,但它仍然是 WordPress 安全扫描找到潜在漏洞的最佳工具。
|
||||
|
||||
#### 4、Aircrack-ng
|
||||
|
||||
![][11]
|
||||
|
||||
[Aircrack-ng][12] 是评估 WiFi 网络安全性的工具集合。它不仅限于监控和获取洞察力 —— 还包括破坏网络(WEP、WPA 1 和 WPA 2)的能力。
|
||||
[Aircrack-ng][12] 是评估 WiFi 网络安全性的工具集合。它不仅限于监控和获取信息 —— 还包括破坏网络(WEP、WPA 1 和 WPA 2)的能力。
|
||||
|
||||
如果你忘记了自己的 WiFi 网络的密码,可以尝试使用它来重新获得访问权限。它还包括各种无线攻击,你可以使用它们来定位/监控 WiFi 网络以增强其安全性。
|
||||
如果你忘记了自己的 WiFi 网络的密码,可以尝试使用它来重新获得访问权限。它还包括各种无线攻击能力,你可以使用它们来定位和监控 WiFi 网络以增强其安全性。
|
||||
|
||||
#### 5、Hydra
|
||||
|
||||
![][13]
|
||||
|
||||
如果你正在寻找一个有趣的工具来破解登录密码时,[Hydra][14] 将是 Kali Linux 预装的最好的工具之一。
|
||||
如果你正在寻找一个有趣的工具来破解登录密码,[Hydra][14] 将是 Kali Linux 预装的最好的工具之一。
|
||||
|
||||
它可能不再被积极维护,但它现在放在 [GitHub][15] 上,所以你也可以为它做贡献。
|
||||
|
||||
@ -72,24 +72,23 @@ WordPress 是[最好的开源 CMS][9]之一,而这个工具是最好的免费
|
||||
|
||||
![][17]
|
||||
|
||||
[Wireshark][18] 是 Kali Linux 最受欢迎的网络分析仪。它也可以归类为用于网络嗅探的最佳 Kali Linux 工具之一。
|
||||
[Wireshark][18] 是 Kali Linux 上最受欢迎的网络分析仪。它也可以归类为用于网络嗅探的最佳 Kali Linux 工具之一。
|
||||
|
||||
它正在积极维护,所以我肯定会建议试试它。
|
||||
它正在积极维护,所以我肯定会建议你试试它。
|
||||
|
||||
#### 7、Metasploit Framework
|
||||
|
||||
![][19]
|
||||
|
||||
[Metsploit Framework][20](MSF)是最常用的渗透测试框架。它提供两个版本:一个开源,第二个是其专业版。使用此工具,你可以验证漏洞、测试已知漏洞并执行完整的安全评估。
|
||||
|
||||
当然,免费版本不具备所有功能,所以如果你对此很认真,你应该在[这里][21]比较一下版本。
|
||||
[Metsploit Framework][20](MSF)是最常用的渗透测试框架。它提供两个版本:一个开源版,另外一个是其专业版。使用此工具,你可以验证漏洞、测试已知漏洞并执行完整的安全评估。
|
||||
|
||||
当然,免费版本不具备所有功能,所以如果你在意它们的区别,你应该在[这里][21]比较一下版本。
|
||||
|
||||
#### 8、Skipfish
|
||||
|
||||
![][22]
|
||||
|
||||
与 WPScan 类似,但不仅仅专注于 WordPress。[Skipfish][23] 是一个 Web 应用扫描程序,可以为你提供几乎所有类型的 Web 应用程序的洞察信息。它快速且易于使用。此外,它的递归爬行方法使它更好。
|
||||
与 WPScan 类似,但它不仅仅专注于 WordPress。[Skipfish][23] 是一个 Web 应用扫描程序,可以为你提供几乎所有类型的 Web 应用程序的洞察信息。它快速且易于使用。此外,它的递归爬取方法使它更好用。
|
||||
|
||||
Skipfish 生成的报告可以用于专业的 Web 应用程序安全评估。
|
||||
|
||||
@ -101,23 +100,23 @@ Skipfish 生成的报告可以用于专业的 Web 应用程序安全评估。
|
||||
|
||||
请注意,这不是一个开源工具。
|
||||
|
||||
它已预先安装,但你必须注册才能选择要使用的版本。如果个人使用,社区版就足够了(只需要注册一个帐户),但如果想用于商业用途,则需要订阅 classic 或 XL 版本。
|
||||
它已预装,但你必须注册才能选择要使用的版本。如果个人使用,社区版就足够了(只需要注册一个帐户),但如果想用于商业用途,则需要订阅 classic 或 XL 版本。
|
||||
|
||||
#### 10、Nessus
|
||||
|
||||
![Nessus][26]
|
||||
|
||||
如果你有个连接到网络的计算机,Nessus 可以帮助你找到潜在攻击者可能利用的漏洞。当然,如果你是连接到网络的多台计算机的管理员,则可以使用它并保护这些计算机。
|
||||
如果你的计算机连接到了网络,Nessus 可以帮助你找到潜在攻击者可能利用的漏洞。当然,如果你是多台连接到网络的计算机的管理员,则可以使用它并保护这些计算机。
|
||||
|
||||
但是,它不再是免费的工具了,你可以从 [官方网站][27] 免费试用 7 天。
|
||||
但是,它不再是免费的工具了,你可以从[官方网站][27]免费试用 7 天。
|
||||
|
||||
#### 11、Burp Suite Scanner
|
||||
|
||||
![][28]
|
||||
|
||||
[Burp Suite Scanner][29] 是一款出色的网络安全分析工具。与其他 Web 应用程序安全扫描程序不同,Burp 提供了 GUI 和一些高级工具。
|
||||
[Burp Suite Scanner][29] 是一款出色的网络安全分析工具。与其它 Web 应用程序安全扫描程序不同,Burp 提供了 GUI 和一些高级工具。
|
||||
|
||||
但是,社区版仅将功能限制为一些基本的手动工具。对于专业人士,你必须考虑升级。与前面的工具类似,这也不是开源的。
|
||||
社区版仅将功能限制为一些基本的手动工具。对于专业人士,你必须考虑升级。与前面的工具类似,这也不是开源的。
|
||||
|
||||
我使用过免费版本,但是如果你想了解更多细节,你应该查看他们[官方网站][29]上提供的功能。
|
||||
|
||||
@ -127,7 +126,7 @@ Skipfish 生成的报告可以用于专业的 Web 应用程序安全评估。
|
||||
|
||||
BeEF(<ruby>浏览器利用框架<rt>Browser Exploitation Framework</rt></ruby>)是另一个令人印象深刻的工具。它专为渗透测试人员量身定制,用于评估 Web 浏览器的安全性。
|
||||
|
||||
这是最好的 Kali Linux 工具之一,因为很多用户在谈论 Web 安全时确实想知道并修复客户端问题。
|
||||
这是最好的 Kali Linux 工具之一,因为很多用户在谈论 Web 安全时希望了解并修复客户端的问题。
|
||||
|
||||
#### 13、Apktool
|
||||
|
||||
@ -151,7 +150,7 @@ BeEF(<ruby>浏览器利用框架<rt>Browser Exploitation Framework</rt></ruby>
|
||||
|
||||
#### 16、Snort
|
||||
|
||||
想要实时流量分析和数据包记录功能吗?[Snort][39] 鼎力支持你。即使它是一个开源的入侵防御系统,也有很多东西可以提供。
|
||||
想要实时流量分析和数据包记录功能吗?[Snort][39] 可以鼎力支持你。即使它是一个开源的入侵防御系统,也有很多东西可以提供。
|
||||
|
||||
如果你还没有安装它,[官方网站][40]提及了安装过程。
|
||||
|
||||
@ -173,13 +172,13 @@ BeEF(<ruby>浏览器利用框架<rt>Browser Exploitation Framework</rt></ruby>
|
||||
|
||||
![Nikto][47]
|
||||
|
||||
[Nikto][48] 是一款功能强大的 Web 服务器扫描程序 —— 使其成为最好的 Kali Linux 工具之一。 它会检查存在潜在危险的文件/程序、过时的服务器版本等等。
|
||||
[Nikto][48] 是一款功能强大的 Web 服务器扫描程序 —— 这使其成为最好的 Kali Linux 工具之一。 它会检查存在潜在危险的文件/程序、过时的服务器版本等等。
|
||||
|
||||
#### 20、Yersinia
|
||||
|
||||
![][49]
|
||||
|
||||
[Yersinia][50] 是一个有趣的框架,用于在网络上执行第 2 层攻击(第 2 层是指 [OSI 模型][51]的数据链路层)。当然,如果你希望网络安全,则必须考虑所有七个层。但是,此工具侧重于第 2 层和各种网络协议,包括 STP、CDP,DTP等。
|
||||
[Yersinia][50] 是一个有趣的框架,用于在网络上执行第 2 层攻击(第 2 层是指 [OSI 模型][51]的数据链路层)。当然,如果你希望你的网络安全,则必须考虑所有七个层。但是,此工具侧重于第 2 层和各种网络协议,包括 STP、CDP,DTP 等。
|
||||
|
||||
#### 21、Social Engineering Toolkit (SET)
|
||||
|
||||
@ -202,7 +201,7 @@ via: https://itsfoss.com/best-kali-linux-tools/
|
||||
作者:[Ankush Das][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[wxy](https://github.com/wxy)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
@ -1,132 +0,0 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (geekpi)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Automate backups with restic and systemd)
|
||||
[#]: via: (https://fedoramagazine.org/automate-backups-with-restic-and-systemd/)
|
||||
[#]: author: (Link Dupont https://fedoramagazine.org/author/linkdupont/)
|
||||
|
||||
Automate backups with restic and systemd
|
||||
======
|
||||
|
||||
![][1]
|
||||
|
||||
Timely backups are important. So much so that [backing up software][2] is a common topic of discussion, even [here on the Fedora Magazine][3]. This article demonstrates how to automate backups with **restic** using only systemd unit files.
|
||||
|
||||
For an introduction to restic, be sure to check out our article [Use restic on Fedora for encrypted backups][4]. Then read on for more details.
|
||||
|
||||
Two systemd services are required to run in order to automate taking snapshots and keeping data pruned. The first service runs the _backup_ command needs to be run on a regular frequency. The second service takes care of data pruning.
|
||||
|
||||
If you’re not familiar with systemd at all, there’s never been a better time to learn. Check out [the series on systemd here at the Magazine][5], starting with this primer on unit files:
|
||||
|
||||
> [systemd unit file basics][6]
|
||||
|
||||
If you haven’t installed restic already, note it’s in the official Fedora repositories. To install use this command [with sudo][7]:
|
||||
|
||||
```
|
||||
$ sudo dnf install restic
|
||||
```
|
||||
|
||||
### Backup
|
||||
|
||||
First, create the _~/.config/systemd/user/restic-backup.service_ file. Copy and paste the text below into the file for best results.
|
||||
|
||||
```
|
||||
[Unit]
|
||||
Description=Restic backup service
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=restic backup --verbose --one-file-system --tag systemd.timer $BACKUP_EXCLUDES $BACKUP_PATHS
|
||||
ExecStartPost=restic forget --verbose --tag systemd.timer --group-by "paths,tags" --keep-daily $RETENTION_DAYS --keep-weekly $RETENTION_WEEKS --keep-monthly $RETENTION_MONTHS --keep-yearly $RETENTION_YEARS
|
||||
EnvironmentFile=%h/.config/restic-backup.conf
|
||||
```
|
||||
|
||||
This service references an environment file in order to load secrets (such as _RESTIC_PASSWORD_ ). Create the _~/.config/restic-backup.conf_ file. Copy and paste the content below for best results. This example uses BackBlaze B2 buckets. Adjust the ID, key, repository, and password values accordingly.
|
||||
|
||||
```
|
||||
BACKUP_PATHS="/home/rupert"
|
||||
BACKUP_EXCLUDES="--exclude-file /home/rupert/.restic_excludes --exclude-if-present .exclude_from_backup"
|
||||
RETENTION_DAYS=7
|
||||
RETENTION_WEEKS=4
|
||||
RETENTION_MONTHS=6
|
||||
RETENTION_YEARS=3
|
||||
B2_ACCOUNT_ID=XXXXXXXXXXXXXXXXXXXXXXXXX
|
||||
B2_ACCOUNT_KEY=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
|
||||
RESTIC_REPOSITORY=b2:XXXXXXXXXXXXXXXXXX:/
|
||||
RESTIC_PASSWORD=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
|
||||
```
|
||||
|
||||
Now that the service is installed, reload systemd: _systemctl –user daemon-reload_. Try running the service manually to create a backup: _systemctl –user start restic-backup_.
|
||||
|
||||
Because the service is a _oneshot_ , it will run once and exit. After verifying that the service runs and creates snapshots as desired, set up a timer to run this service regularly. For example, to run the _restic-backup.service_ daily, create _~/.config/systemd/user/restic-backup.timer_ as follows. Again, copy and paste this text:
|
||||
|
||||
```
|
||||
[Unit]
|
||||
Description=Backup with restic daily
|
||||
[Timer]
|
||||
OnCalendar=daily
|
||||
Persistent=true
|
||||
[Install]
|
||||
WantedBy=timers.target
|
||||
```
|
||||
|
||||
Enable it by running this command:
|
||||
|
||||
```
|
||||
$ systemctl --user enable --now restic-backup.timer
|
||||
```
|
||||
|
||||
### Prune
|
||||
|
||||
While the main service runs the _forget_ command to only keep snapshots within the keep policy, the data is not actually removed from the restic repository. The _prune_ command inspects the repository and current snapshots, and deletes any data not associated with a snapshot. Because _prune_ can be a time-consuming process, it is not necessary to run every time a backup is run. This is the perfect scenario for a second service and timer. First, create the file _~/.config/systemd/user/restic-prune.service_ by copying and pasting this text:
|
||||
|
||||
```
|
||||
[Unit]
|
||||
Description=Restic backup service (data pruning)
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=restic prune
|
||||
EnvironmentFile=%h/.config/restic-backup.conf
|
||||
```
|
||||
|
||||
Similarly to the main _restic-backup.service_ , _restic-prune_ is a oneshot service and can be run manually. Once the service has been set up, create and enable a corresponding timer at _~/.config/systemd/user/restic-prune.timer_ :
|
||||
|
||||
```
|
||||
[Unit]
|
||||
Description=Prune data from the restic repository monthly
|
||||
[Timer]
|
||||
OnCalendar=monthly
|
||||
Persistent=true
|
||||
[Install]
|
||||
WantedBy=timers.target
|
||||
```
|
||||
|
||||
That’s it! Restic will now run daily and prune data monthly.
|
||||
|
||||
* * *
|
||||
|
||||
_Photo by _[ _Samuel Zeller_][8]_ on _[_Unsplash_][9]_._
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://fedoramagazine.org/automate-backups-with-restic-and-systemd/
|
||||
|
||||
作者:[Link Dupont][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://fedoramagazine.org/author/linkdupont/
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://fedoramagazine.org/wp-content/uploads/2019/04/restic-systemd-816x345.jpg
|
||||
[2]: https://restic.net/
|
||||
[3]: https://fedoramagazine.org/?s=backup
|
||||
[4]: https://fedoramagazine.org/use-restic-encrypted-backups/
|
||||
[5]: https://fedoramagazine.org/series/systemd-series/
|
||||
[6]: https://fedoramagazine.org/systemd-getting-a-grip-on-units/
|
||||
[7]: https://fedoramagazine.org/howto-use-sudo/
|
||||
[8]: https://unsplash.com/photos/JuFcQxgCXwA?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText
|
||||
[9]: https://unsplash.com/search/photos/archive?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText
|
@ -1,5 +1,5 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: translator: (geekpi)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
|
@ -0,0 +1,133 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (geekpi)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Automate backups with restic and systemd)
|
||||
[#]: via: (https://fedoramagazine.org/automate-backups-with-restic-and-systemd/)
|
||||
[#]: author: (Link Dupont https://fedoramagazine.org/author/linkdupont/)
|
||||
|
||||
使用 restic 和 systemd 自动备份
|
||||
======
|
||||
|
||||
![][1]
|
||||
|
||||
及时备份很重要。即使在 [Fedora Magazine][3] 中,[备份软件][2] 也是一个常见的讨论话题。本文演示了如何仅使用 systemd 以及 **restic** 来自动备份。
|
||||
|
||||
|
||||
有关 restic 的介绍,请查看我们的文章[在 Fedora 上使用 restic 进行加密备份][4]。然后继续阅读以了解更多详情。
|
||||
|
||||
为了自动创建快照以及清理数据,需要运行两个 systemd 服务。第一个运行_备份_命令的服务需要以常规频率运行。第二个服务负责数据清理。
|
||||
|
||||
如果你根本不熟悉 systemd,那么这是个很好的学习机会。查看 [Magazine 上关于 systemd 的系列文章] [5],从单元文件的这个入门开始:
|
||||
|
||||
> [systemd 单元文件基础][6]
|
||||
|
||||
如果你还没有安装 restic,请注意它在官方的 Fedora 仓库中。要安装它,请[带上 sudo][7] 运行此命令:
|
||||
|
||||
```
|
||||
$ sudo dnf install restic
|
||||
```
|
||||
|
||||
### 备份
|
||||
|
||||
首先,创建 _~/.config/systemd/user/restic-backup.service_。将下面的文本复制并粘贴到文件中以获得最佳效果。
|
||||
|
||||
```
|
||||
[Unit]
|
||||
Description=Restic backup service
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=restic backup --verbose --one-file-system --tag systemd.timer $BACKUP_EXCLUDES $BACKUP_PATHS
|
||||
ExecStartPost=restic forget --verbose --tag systemd.timer --group-by "paths,tags" --keep-daily $RETENTION_DAYS --keep-weekly $RETENTION_WEEKS --keep-monthly $RETENTION_MONTHS --keep-yearly $RETENTION_YEARS
|
||||
EnvironmentFile=%h/.config/restic-backup.conf
|
||||
```
|
||||
|
||||
此服务引用环境文件来加载密钥(例如 _RESTIC_PASSWORD_)。创建 _~/.config/restic-backup.conf_。复制并粘贴以下内容以获得最佳效果。此示例使用 BackBlaze B2 存储。请相应地调整 ID、密钥、仓库和密码值。
|
||||
|
||||
```
|
||||
BACKUP_PATHS="/home/rupert"
|
||||
BACKUP_EXCLUDES="--exclude-file /home/rupert/.restic_excludes --exclude-if-present .exclude_from_backup"
|
||||
RETENTION_DAYS=7
|
||||
RETENTION_WEEKS=4
|
||||
RETENTION_MONTHS=6
|
||||
RETENTION_YEARS=3
|
||||
B2_ACCOUNT_ID=XXXXXXXXXXXXXXXXXXXXXXXXX
|
||||
B2_ACCOUNT_KEY=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
|
||||
RESTIC_REPOSITORY=b2:XXXXXXXXXXXXXXXXXX:/
|
||||
RESTIC_PASSWORD=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
|
||||
```
|
||||
|
||||
现在已安装该服务,请重新加载 systemd:_systemctl -user daemon-reload_。尝试手动运行该服务以创建备份:_systemctl -user start restic-backup_。
|
||||
|
||||
因为该服务类型是 _oneshot_,它将运行一次并退出。验证服务运行并根据需要创建快照后,设置计时器以定期运行此服务。例如,要每天运行 _restic-backup.service_,请按如下所示创建 _~/.config/systemd/user/restic-backup.timer_。再次复制并粘贴此文本:
|
||||
|
||||
```
|
||||
[Unit]
|
||||
Description=Backup with restic daily
|
||||
[Timer]
|
||||
OnCalendar=daily
|
||||
Persistent=true
|
||||
[Install]
|
||||
WantedBy=timers.target
|
||||
```
|
||||
|
||||
运行以下命令启用:
|
||||
|
||||
```
|
||||
$ systemctl --user enable --now restic-backup.timer
|
||||
```
|
||||
|
||||
### 清理
|
||||
|
||||
虽然主服务运行 _forget_ 命令仅保留保留策略中的快照,但实际上并未从 restic 仓库中删除数据。 _prune_ 命令检查仓库和当前快照,并删除与快照无关的所有数据。由于 _prune_ 可能是一个耗时的过程,因此无需在每次运行备份时运行。这是第二个服务和计时器的场景。首先,通过复制和粘贴此文本来创建文件 _~/.config/systemd/user/restic-prune.service_:
|
||||
|
||||
```
|
||||
[Unit]
|
||||
Description=Restic backup service (data pruning)
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=restic prune
|
||||
EnvironmentFile=%h/.config/restic-backup.conf
|
||||
```
|
||||
|
||||
与主 _restic-backup.service_ 服务类似,_restic-prune_ 也是 onehot 服务,并且可以手动运行。设置完服务后,创建 _~/.config/systemd/user/restic-prune.timer_ 并启用相应的计时器:
|
||||
|
||||
```
|
||||
[Unit]
|
||||
Description=Prune data from the restic repository monthly
|
||||
[Timer]
|
||||
OnCalendar=monthly
|
||||
Persistent=true
|
||||
[Install]
|
||||
WantedBy=timers.target
|
||||
```
|
||||
|
||||
就是这些了!restic 将会每日运行并按月清理数据。
|
||||
|
||||
* * *
|
||||
|
||||
图片来自 _[Unsplash][9]_ 由 _[ Samuel Zeller][8]_ 拍摄。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://fedoramagazine.org/automate-backups-with-restic-and-systemd/
|
||||
|
||||
作者:[Link Dupont][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://fedoramagazine.org/author/linkdupont/
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://fedoramagazine.org/wp-content/uploads/2019/04/restic-systemd-816x345.jpg
|
||||
[2]: https://restic.net/
|
||||
[3]: https://fedoramagazine.org/?s=backup
|
||||
[4]: https://fedoramagazine.org/use-restic-encrypted-backups/
|
||||
[5]: https://fedoramagazine.org/series/systemd-series/
|
||||
[6]: https://fedoramagazine.org/systemd-getting-a-grip-on-units/
|
||||
[7]: https://fedoramagazine.org/howto-use-sudo/
|
||||
[8]: https://unsplash.com/photos/JuFcQxgCXwA?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText
|
||||
[9]: https://unsplash.com/search/photos/archive?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText
|
@ -1,5 +1,5 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: translator: (warmfrog)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
@ -7,30 +7,30 @@
|
||||
[#]: via: (https://www.2daygeek.com/linux-shell-script-to-monitor-disk-space-usage-and-send-email/)
|
||||
[#]: author: (Magesh Maruthamuthu https://www.2daygeek.com/author/magesh/)
|
||||
|
||||
Linux Shell Script To Monitor Disk Space Usage And Send Email
|
||||
======
|
||||
用 Linux Shell 脚本来监控磁盘使用情况和发送邮件
|
||||
============================================
|
||||
|
||||
There are numerous monitoring tools are available in market to monitor Linux systems and it will send an email when the system reaches the threshold limit.
|
||||
市场上有很多用来监控 Linux 系统的监控工具,当系统到达阀值后它将发送一封邮件。
|
||||
|
||||
It monitors everything such as CPU utilization, Memory utilization, swap utilization, disk space utilization and much more.
|
||||
它监控所有的东西例如 CPU 利用率,内存利用率,交换空间利用率,磁盘空间利用率等等。
|
||||
|
||||
However, it’s suitable for small and big environment.
|
||||
然而,它更适合小环境和大环境。
|
||||
|
||||
Think about if you have only few systems then what will be the best approach on this.
|
||||
想一想如果你只有少量系统,那么什么是最好的方式来应对这种情况。
|
||||
|
||||
Yup, we want to write a **[shell script][1]** to achieve this.
|
||||
是的,我们想要写一个 **[shell 脚本][1]** 来实现。
|
||||
|
||||
In this tutorial we are going to write a shell script to monitor disk space usage on system.
|
||||
在这篇指南中我们打算写一个 shell 脚本来监控系统的磁盘空间使用率。
|
||||
|
||||
When the system reaches the given threshold then it will trigger a mail to corresponding email id.
|
||||
当系统到达给定的阀值,它将给对应的邮件 id 发送一封邮件。
|
||||
|
||||
We have added totally four shell scripts in this article and each has been used for different purpose.
|
||||
在这篇文章中我们总共添加了四个 shell 脚本,每个用于不同的目的。
|
||||
|
||||
Later, we will come up with other shell scripts to monitor CPU, Memory and Swap utilization.
|
||||
之后,我们会想出其他 shell 脚本来监控 CPU,内存和交换空间利用率。
|
||||
|
||||
Before step into that, i would like to clarify one thing which i noticed regarding the disk space usage shell script.
|
||||
在此之前,我想澄清一件事,根据我观察的磁盘空间使用率 shell 脚本使用情况。
|
||||
|
||||
Most of the users were commented in multiple blogs saying they were getting the following error message when they are running the disk space usage script.
|
||||
大多数用户在多篇博客中评论说,当他们运行磁盘空间使用率脚本时他们获得了以下错误。
|
||||
|
||||
```
|
||||
# sh /opt/script/disk-usage-alert-old.sh
|
||||
@ -40,11 +40,11 @@ test-script.sh: line 7: [: /dev/mapper/vg_2g-lv_root: integer expression expecte
|
||||
/ 9.8G
|
||||
```
|
||||
|
||||
Yes that’s right. Even, i had faced the same issue when i ran the script first time. Later, i had found the root causes.
|
||||
是的,这是对的。甚至,当我第一次运行这个脚本的时候我遇到了相同的问题。之后,我发现了根本原因。
|
||||
|
||||
When you use “df -h” or “df -H” in shell script for disk space alert on RHEL 5 & RHEL 6 based system, you will be end up with the above error message because the output is not in the proper format, see the below output.
|
||||
当你在基于 RHEL 5 & RHEL 6 的系统上运行包含用于磁盘空间警告的 “df -h” 或 “df -H” 的 shell 脚本中时,你会发现上述错误信息,因为输出格式不对,查看下列输出。
|
||||
|
||||
To overcome this issue, we need to use “df -Ph” (POSIX output format) but by default “df -h” is working fine on RHEL 7 based systems.
|
||||
为了解决这个问题,我们需要用 “df -Ph” (POSIX 输出格式),但是默认的 “df -h” 在基于 RHEL 7 的系统上运行的很好。
|
||||
|
||||
```
|
||||
# df -h
|
||||
@ -60,15 +60,15 @@ tmpfs 7.8G 0 7.8G 0% /dev/shm
|
||||
4.8G 14M 4.6G 1% /tmp
|
||||
```
|
||||
|
||||
### Method-1 : Linux Shell Script To Monitor Disk Space Usage And Send Email
|
||||
### 方法一:Linux Shell 脚本来监控磁盘空间使用率和发送邮件
|
||||
|
||||
You can use the following shell script to monitor disk space usage on Linux system.
|
||||
你可以使用下列 shell 脚本在 Linux 系统中来监控磁盘空间使用率。
|
||||
|
||||
It will send an email when the system reaches the given threshold limit. In this example, we set threshold limit at 60% for testing purpose and you can change this limit as per your requirements.
|
||||
当系统到达给定的阀值限制时,它将发送一封邮件。在这个例子中,我们设置阀值为 60% 用于测试目的,你可以改变这个限制来符合你的需求。
|
||||
|
||||
It will send multiple mails if more than one file systems get reached the given threshold limit because the script is using loop.
|
||||
如果超过一个文件系统到达给定的阀值,它将发送多封邮件,因为这个脚本使用了循环。
|
||||
|
||||
Also, replace your email id instead of us to get this alert.
|
||||
同样,替换你的邮件 id 来获取这份警告。
|
||||
|
||||
```
|
||||
# vi /opt/script/disk-usage-alert.sh
|
||||
@ -85,7 +85,7 @@ do
|
||||
done
|
||||
```
|
||||
|
||||
**Output:** I got the following two email alerts.
|
||||
**输出:**我获得了下列两封邮件警告。
|
||||
|
||||
```
|
||||
The partition "/dev/mapper/vg_2g-lv_home" on 2g.CentOS7 has used 85% at Mon Apr 29 06:16:14 IST 2019
|
||||
@ -100,9 +100,9 @@ Finally add a **[cronjob][2]** to automate this. It will run every 10 minutes.
|
||||
*/10 * * * * /bin/bash /opt/script/disk-usage-alert.sh
|
||||
```
|
||||
|
||||
### Method-2 : Linux Shell Script To Monitor Disk Space Usage And Send Email
|
||||
### 方法二:Linux Shell 脚本来监控磁盘空间使用率和发送邮件
|
||||
|
||||
Alternatively, you can use the following shell script. We have made few changes in this compared with above script.
|
||||
作为代替,你可以使用下列的 shell 脚本。对比上面的脚本我们做了少量改变。
|
||||
|
||||
```
|
||||
# vi /opt/script/disk-usage-alert-1.sh
|
||||
@ -120,7 +120,8 @@ do
|
||||
done
|
||||
```
|
||||
|
||||
**Output:** I got the following two email alerts.
|
||||
**输出:**我获得了下列两封邮件警告。
|
||||
|
||||
|
||||
```
|
||||
The partition "/dev/mapper/vg_2g-lv_home" on 2g.CentOS7 has used 85% at Mon Apr 29 06:16:14 IST 2019
|
||||
@ -128,24 +129,24 @@ The partition "/dev/mapper/vg_2g-lv_home" on 2g.CentOS7 has used 85% at Mon Apr
|
||||
The partition "/dev/mapper/vg_2g-lv_root" on 2g.CentOS7 has used 67% at Mon Apr 29 06:16:14 IST 2019
|
||||
```
|
||||
|
||||
Finally add a **[cronjob][2]** to automate this. It will run every 10 minutes.
|
||||
最终添加了一个 **[cronjob][2]** 来自动完成。它会每 10 分钟运行一次。
|
||||
|
||||
```
|
||||
# crontab -e
|
||||
*/10 * * * * /bin/bash /opt/script/disk-usage-alert-1.sh
|
||||
```
|
||||
|
||||
### Method-3 : Linux Shell Script To Monitor Disk Space Usage And Send Email
|
||||
### 方法三:Linux Shell 脚本来监控磁盘空间使用率和发送邮件
|
||||
|
||||
I would like to go with this method. Since, it work like a charm and you will be getting single email for everything.
|
||||
我更喜欢这种方法。因为,它工作起来很有魔力,你只会收到一封关于所有事的邮件。
|
||||
|
||||
This is very simple and straightforward.
|
||||
这相当简单和直接。
|
||||
|
||||
```
|
||||
*/10 * * * * df -Ph | sed s/%//g | awk '{ if($5 > 60) print $0;}' | mail -s "Disk Space Alert On $(hostname)" [email protected]
|
||||
```
|
||||
|
||||
**Output:** I got a single mail for all alerts.
|
||||
**输出:** 我获得了一封关于所有警告的邮件。
|
||||
|
||||
```
|
||||
Filesystem Size Used Avail Use Mounted on
|
||||
@ -153,9 +154,7 @@ Filesystem Size Used Avail Use Mounted on
|
||||
/dev/mapper/vg_2g-lv_home 5.0G 4.3G 784M 85 /home
|
||||
```
|
||||
|
||||
### Method-4 : Linux Shell Script To Monitor Disk Space Usage Of Particular Partition And Send Email
|
||||
|
||||
If anybody wants to monitor the particular partition then you can use the following shell script. Simply replace your filesystem name instead of us.
|
||||
### 方法四:Linux Shell 脚本来监控某个分区的磁盘空间使用情况和发送邮件
|
||||
|
||||
```
|
||||
# vi /opt/script/disk-usage-alert-2.sh
|
||||
@ -168,22 +167,22 @@ echo "The Mount Point "/DB" on $(hostname) has used $used at $(date)" | mail -s
|
||||
fi
|
||||
```
|
||||
|
||||
**Output:** I got the following email alerts.
|
||||
**输出:** 我得到了下面的邮件警告。
|
||||
|
||||
```
|
||||
The partition /dev/mapper/vg_2g-lv_dbs on 2g.CentOS6 has used 82% at Mon Apr 29 06:16:14 IST 2019
|
||||
```
|
||||
|
||||
Finally add a **[cronjob][2]** to automate this. It will run every 10 minutes.
|
||||
最终添加了一个 **[cronjob][2]** 来自动完成这些工作。它将每 10 分钟运行一次。
|
||||
|
||||
```
|
||||
# crontab -e
|
||||
*/10 * * * * /bin/bash /opt/script/disk-usage-alert-2.sh
|
||||
```
|
||||
|
||||
**Note:** You will be getting an email alert 10 mins later since the script has scheduled to run every 10 minutes (But it’s not exactly 10 mins and it depends the timing).
|
||||
**注意:** 你将在 10 分钟后收到一封邮件警告,因为这个脚本被计划为每 10 分钟运行一次(但也不是精确的 10 分钟,取决于时间)。
|
||||
|
||||
Say for example. If your system reaches the limit at 8.25 then you will get an email alert in another 5 mins. Hope it’s clear now.
|
||||
例如这个例子。如果你的系统在 8:25 到达了限制,你将在 5 分钟后收到邮件警告。希望现在讲清楚了。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
@ -191,7 +190,7 @@ via: https://www.2daygeek.com/linux-shell-script-to-monitor-disk-space-usage-and
|
||||
|
||||
作者:[Magesh Maruthamuthu][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
译者:[warmfrog](https://github.com/warmfrog)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
@ -200,3 +199,10 @@ via: https://www.2daygeek.com/linux-shell-script-to-monitor-disk-space-usage-and
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://www.2daygeek.com/category/shell-script/
|
||||
[2]: https://www.2daygeek.com/crontab-cronjob-to-schedule-jobs-in-linux/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user