Merge branch 'LCTT:master' into raspberry-pi

This commit is contained in:
void-mori 2022-07-13 17:37:04 +08:00 committed by GitHub
commit 61080d523d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 775 additions and 776 deletions

View File

@ -3,31 +3,32 @@
[#]: author: "Don Watkins https://opensource.com/users/don-watkins"
[#]: collector: "lkxed"
[#]: translator: "MjSeven"
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
[#]: reviewer: "wxy"
[#]: publisher: "wxy"
[#]: url: "https://linux.cn/article-14823-1.html"
检查 Linux 磁盘使用情况
======
du 和 ncdu 两个命令提供了相同信息的两种不同视图,便于我们跟踪存储在计算机上的内容。
![Data stack in blue][1]
> du 和 ncdu 两个命令提供了相同信息的两种不同视图,便于我们跟踪存储在计算机上的内容。
![](https://img.linux.net.cn/data/attachment/album/202207/13/111729faleyal2gmappykc.jpg)
无论你有多少存储空间,了解文件占用了多少磁盘空间都是一个重要的考虑事项。我的笔记本有一个相对较小的 250GB NVME 驱动器,大多数时候都没什么问题,但几年前我开始探索 Linux 上的游戏,情况变得有所不同,安装 Steam 和其他游戏使存储管理更加重要。
### du 命令
检查磁盘驱动器上剩余存储空间最简单的方法是 [du 命令][2]。它会估计文件空间使用情况,像其他所有 Linux 工具一样,`du` 非常强大,但知道如何根据你的特定需求使用它会很有帮助。我总是查阅 man 页面来获取实用程序。du 有几个选项,可以为你提供文件存储的最佳快照,以及它们在系统上消耗多少空间。
检查磁盘驱动器上剩余存储空间最简单的方法是 [du 命令][2]。它会估计文件空间使用情况,像其他所有 Linux 工具一样,`du` 非常强大,但学会如何根据你的特定需求使用它会很有帮助。我总是查阅手册页来掌握实用程序的用法。`du` 有几个选项,可以为你提供文件存储的最佳快照,以及它们在系统上消耗多少空间。
`du` 命令有很多选项,以下是一些常见的:
* -a - 包括文件夹和文件在内的存储信息
* --apparent-size - 打印自身大小而不是占用磁盘量
* -h - 人类可读的格式
* -b - 字节
* -c -总计
* -k - 块大小
* -m - 以兆字节为单位的大小
* `-a` - 包括文件夹和文件在内的存储信息
* `--apparent-size` - 打印自身大小而不是占用磁盘量
* `-h` - 人类可读的格式
* `-b` - 字节为单位
* `-c` - 总计
* `-k` - 以块为单位
* `-m` - 以兆字节为单位的大小
务必查看 `du` 手册页获取完整帮助列表。
@ -41,15 +42,15 @@ du 和 ncdu 两个命令提供了相同信息的两种不同视图,便于我
$ du -a ~/Downloads
4923    ./UNIX_Driver_5-0/UNIX Driver 50
4923    ./UNIX_Driver_5-0
20     ./epel-release-latest-9.noarch.rpm
12    ./rpmfusion-free-release-9.noarch.rpm
20     ./epel-release-latest-9.noarch.rpm
12     ./rpmfusion-free-release-9.noarch.rpm
2256    ./PZO9297 000 Cover.pdf
8    ./pc.md
8     ./pc.md
2644    ./geckodriver-v0.31.0-linux64.tar.gz
466468
```
最左边的数字是以字节为单位的文件大小。我想要一些对我更有帮助的东西,所以我将人类可读格式的选项添加到命令中,结果是 4.8G(千兆字节),这对我来说是一种更有用的数字格式。(to 校正:这个 4.8G 不知道从何而来)
最左边的数字是以字节为单位的文件大小。我想要一些对我更有帮助的东西,所以我将人类可读格式的选项添加到命令中,结果是 456M兆字节),这对我来说是一种更有用的数字格式。
```
$ du -ah ~/Downloads
@ -65,21 +66,15 @@ $ du -ah ~/Downloads
与大多数 Linux 命令一样,你可以组合选项,要以人类可读的格式查看 `Downloads` 目录,使用 `du -ah ~/Downloads` 命令。
**[[ 另请阅读:检查可用磁盘空间的 5 个 Linux 命令 ]][3]**
#### 总和
`-c` 选项在最后一行提供了磁盘使用总和。我可以使用 `du -ch /home/don` 来显示主目录中的每个文件和目录。这里有很多信息,我只想知道最后一行的信息,所以我将磁盘使用命令通过管道传输给 `tail`。命令是 `du -ch /home/don | tail`to 校正:这条命令似乎没卵用,在 Ubuntu 试验过
`-c` 选项在最后一行提供了磁盘使用总和。我可以使用 `du -ch /home/don` 来显示主目录中的每个文件和目录。这里有很多信息,我只想知道最后一行的信息,所以我将 `du` 命令通过管道传输给 `tail` 来显示最后几行。命令是 `du -ch /home/don | tail`LCTT 校注:可以使用 `tail -1` 来仅显示最后一行汇总行。
![将 du 命令输出通过管道传输到 tail][4]
Image by:
(Don Watkins, CC BY-SA 4.0)
### ncdu 命令
对存储在驱动器上内容感兴趣的 Linux 用户,另一个选择是 [ncdu 命令][5],它代表 *NCurses 磁盘使用情况*。基于你的 Linux 发行版,你可能需要下载并安装它。
对存储在驱动器上内容感兴趣的 Linux 用户,另一个选择是 [ncdu 命令][5],它代表 “NCurses 磁盘使用情况”。基于你的 Linux 发行版,你可能需要下载并安装它。
在 Linux Mint、Elementary、Pop_OS! 或其它基于 Debian 的发行版上:
@ -99,37 +94,27 @@ $ sudo dnf install ncdu
$ sudo pacman -S ncdu
```
安装后,你可以使用 ncdu 来分析你的文件系统。以下是在我的主目录中发出 `ncdu` 后的示例输出。`ncdu` 的 man 页面指出“ncduNCurses Disk Usage是众所周知的 `du` 基于 curses 的版本,它提供了一种快速查看哪些目录正在使用磁盘空间的方法。”
安装后,你可以使用 `ncdu` 来分析你的文件系统。以下是在我的主目录中发出 `ncdu` 后的示例输出。`ncdu` 的手册页指出 “ncduNCurses Disk Usage是众所周知的 `du` 基于 curses 的版本,它提供了一种快速查看哪些目录正在使用磁盘空间的方法。”
![du 命令输出][6]
Image by:
(Don Watkins, CC BY-SA 4.0)
我可以使用方向键上下导航,按下 **Enter** 键进入目录。有趣的是,`du` 报告我的主目录中的总磁盘使用量为 12GB`ncdu` 显示为 11GB。你可以在 `ncdu` 手册页中找到更多信息。
我可以使用方向键上下导航,按下回车键进入目录。有趣的是,`du` 报告我的主目录中的总磁盘使用量为 12GB`ncdu` 显示为 11GB。你可以在 `ncdu` 手册页中找到更多信息。
你可以将 `ncdu` 指向某个目录来探索特定目录。例如,`ncdu /home/don/Downloads`。
![ncdu 命令输出][7]
Image by:
(Don Watkins, CC BY-SA 4.0)
**?** 键显示帮助菜单。
`?` 键显示帮助菜单。
![ncdu 帮助][8]
Image by:
(Don Watkins, CC BY-SA 4.0)
### 总结
`du``ncdu` 两个命令提供了相同信息的两种不同视图,便于我们跟踪存储在计算机上的内容。
如果你不习惯使用终端,或者只是在寻找此类信息的另一种试图,查看 [GNOME 磁盘使用分析器][9]。如果你的系统上还没有它,你可以轻松安装和使用它。检查你的发行版是否有 `baobab`,如果你想进行尝试,去安装它。
如果你不习惯使用终端,或者想寻找此类信息的另一种查看方式,可以看看 [GNOME 磁盘使用分析器][9]。如果你的系统上还没有它,你可以轻松安装和使用它。检查你的发行版是否有 baobab 开发的这个软件,如果你想试试,那就去安装它吧。
(文内图片来自于 Don Watkins, CC BY-SA 4.0
--------------------------------------------------------------------------------
@ -138,7 +123,7 @@ via: https://opensource.com/article/22/7/check-disk-usage-linux
作者:[Don Watkins][a]
选题:[lkxed][b]
译者:[MjSeven](https://github.com/MjSeven)
校对:[校对者ID](https://github.com/校对者ID)
校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出

View File

@ -3,17 +3,18 @@
[#]: author: "Ankush Das https://news.itsfoss.com/author/ankush/"
[#]: collector: "lkxed"
[#]: translator: "lkxed"
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
[#]: reviewer: "wxy"
[#]: publisher: "wxy"
[#]: url: "https://linux.cn/article-14822-1.html"
怀念 Firefox Send 吗?不妨试试 Internxt Send 吧
======
Internxt 发布了一个新产品,它可以让你快速地将加密文件发送给任何人,同时保持你的隐私。嗯,我们只能希望它不会像 Firefox Send 那样关闭吧……
> Internxt 发布了一个新产品,它可以让你快速地将加密文件发送给任何人,同时保持你的隐私。嗯,我们只能希望它不会像 Firefox Send 那样关闭吧……
![Internxt][1]
[Internxt][2] 是一个相当新的开源加密云服务,旨在取代大型科技公司的产品。例如,你可以把它作为 Google Photos 和 Drive 的替代品。
[Internxt][2] 是一个相当新的开源加密云服务,旨在取代大型科技公司的产品。例如,你可以把它作为谷歌的相册和云端硬盘的替代品。
它免费提供 10 GB 的容量。所以,如果感兴趣的话,你可以注册个账号试一试。
@ -29,7 +30,7 @@ Internxt 发布了一个新产品,它可以让你快速地将加密文件发
我在 GitHub 上找不到 Internxt Send 的存储库,但我已经要求他们澄清了。
*LCTT 译注:虽然 Internxt 是在 GitHub 上开源的,但是 GitHub 上没有 Internxt Send 这个产品的存储库,产品的介绍里也没有声称它是开源的。*
LCTT 译注:虽然 Internxt 是在 GitHub 上开源的,但是 GitHub 上没有 Internxt Send 这个产品的存储库,产品的介绍里也没有声称它是开源的。
正如你所期望的那样,你无需创建帐户即可将文件上传到 Internxt Send。
@ -54,7 +55,7 @@ via: https://news.itsfoss.com/internxt-send/
作者:[Ankush Das][a]
选题:[lkxed][b]
译者:[lkxed](https://github.com/lkxed)
校对:[校对者ID](https://github.com/校对者ID)
校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出

View File

@ -66,7 +66,7 @@ via: https://opensource.com/article/22/7/meet-fsf-executive-director-zoe-kooyman
作者:[Seth Kenlon][a]
选题:[lkxed][b]
译者:[译者ID](https://github.com/译者ID)
译者:[Peaksol](https://github.com/TravinDreek)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出

View File

@ -2,7 +2,7 @@
[#]: via: "https://itsfoss.com/firefox-containers/"
[#]: author: "Hunter Wittenborn https://itsfoss.com/author/hunter/"
[#]: collector: "lujun9972"
[#]: translator: " "
[#]: translator: "hanszhao80"
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
@ -108,7 +108,7 @@ via: https://itsfoss.com/firefox-containers/
作者:[Hunter Wittenborn][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
译者:[hanszhao80](https://github.com/hanszhao80)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出

View File

@ -1,268 +0,0 @@
[#]: subject: "Beginners Guide to Installing Arch Linux on VirtualBox"
[#]: via: "https://itsfoss.com/install-arch-linux-virtualbox/"
[#]: author: "Ankush Das https://itsfoss.com/author/ankush/"
[#]: collector: "lujun9972"
[#]: translator: "hanszhao80"
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
Beginners Guide to Installing Arch Linux on VirtualBox
======
[Arch Linux is hugely popular][1] in the desktop Linux world. One of the reasons for the popularity is that [installing Arch Linux][2] itself is a complicated task.
I am not exaggerating. Installing [Ubuntu or Debian][3] is a lot easier task than Arch Linux because it doesnt have an official GUI based installer. And this is where virtual machines come in.
You can try installing Arch Linux in VirtualBox first and see if its something you would like to run on actual hardware. This way, you get to experience Arch Linux without disturbing your current operating system.
In this article, I will be guiding you through the steps to install a functional Arch Linux virtual machine.
### Installing Arch Linux on VirtualBox
Undoubtedly, you need to first [install VirtualBox on Linux][4] or Windows. On Windows, simply go to the Oracles website and download VirtualBox.
[Download VirtualBox][5]
If you are using Windows 10 or newer version, please ensure that you have virtualization enabled on your system.
Once done, you need to head to [Arch Linuxs official website][6] to download the ISO file. You should find options to [download using torrent][7] or download the file directly.
![][8]
Hold on to the ISO file when needed, you can delete it to [free space on your system][9] after successful installation.
Now, let us begin installing Arch Linux on VirtualBox.
#### Part 1. Creating the Virtual Machine
**Step 1:** First, you need to set up a few things in VirtualBox. Launch VirtualBox and click on “**New**” to create a virtual machine.
![][10]
Note that you can continue creating the virtual machine using the guided mode, but you get more options at a single glance with the expert mode.
![][11]
Hence, I recommend using the expert mode to create the virtual machine.
Fret not, the expert mode is as easy, with just a bit of extra available options and nothing else to worry about.
**Step 2**: Enter the name of your virtual machine, it should auto-detect the “Type” and “Version” respectively when you type in “**Arch Linux**” in the name field.
![][12]
You should increase the memory size to use the virtual machine comfortably. If it is just for minor testing, you can go ahead with the default setting.
In my case, I allocate ~**4 GB of RAM**.
Also, make sure to **create a virtual hard disk** under the “Hard disk” option. It should be the selected option by default.
Now, proceed to set the virtual hard disk size.
**Step 3:** You can choose a preferred location path for the virtual hard disk and tweak the size as per your requirements. The installation should not be a problem with the minimum allocated size (8 GB), but to be on the safe side, you may want to allocate at least 10-15 GB.
![][13]
Next, you need to select the hard disk file type as “**VDI (VirtualBox Disk Image)**” and the storage as “**Dynamically allocated**,” as shown in the image above.
VDI is the most common hard disk type for the virtual hard disk.
And, when you select the “**Dynamically allocated**” option for the hard disk storage, it means that the storage space will be utilized as per usage. In other words, 15 GB of space wont be locked from your disk as soon as the virtual machine is created.
Now, all you have to do is hit “**Create**” to add the virtual machine.
#### Part 2. Adding the ISO File to Start Installing Arch Linux
![][14]
Once the VM has been listed, you can look at its configuration and select the ISO as the disk drive under the **Storage** option.
You can also separately head to the virtual machine settings to explore more and choose the ISO file.
![][15]
To do that, navigate your way to the “**Storage**” setting of the VM.
![][16]
Here, you will have to click on the “**Empty**” device under Controller and then proceed to select the Arch Linux ISO file as the disk file (as shown in the image above).
![][17]
Once you select it, hit “**OK**” to save the changes to your setting.
Heres how the virtual machine setting should look like with the ISO set as the disk to boot:
![][18]
Now, hit “**Start**” to start the VM and get started with the installation.
#### Part 3. Installing Arch Linux using the Guided Installer
Arch Linux has made the installation easier by [introducing a guided installer][19], i.e., it gives you all the options you need to set up a full-fledged Arch Linux system.
So, with the help of a guided installer, you do not have to install a desktop environment and other essential packages yourself separately. All you have to do is follow the onscreen instructions and choose the options suitable for your installation.
In this article, we focus on the guided installer. If you want to do things yourself, you should follow our [Arch installation guide][2].
Moving on to the installation, when you start the VM, you will be looking at this screen:
![][20]
The first option is the ideal way of proceeding. If you have a specific requirement, you can choose other options to boot up Arch Linux.
Now, you should be looking at a terminal window. Heres how to get started:
**Step 1**: Type in “**archinstall**” to initiate installation using the guided installer.
![][21]
**Step 2:** Choose a keyboard layout as per your requirements, selecting a US layout should be the most common choice. Just type in a number to make the selection, as shown in the image below (for instance, 26).
![][22]
**Step 3:** Next, you need to select a region to download packages.
![][23]
Choosing a preferred region instead of “Worldwide” is crucial because it downloads many unnecessary packages if you select “**Worldwide**” as your region.
**Step 4:** Once you select the region, it will ask you to choose the drive for installation. In this case, we already created a virtual drive of ~15 GB displayed as **/dev/sda**.
Similarly, check for the drive you created as per the size and choose that disk to proceed. Here, I type in **1** as the input; yours can differ.
![][24]
**Step 5:** For the next set of steps, you will be asked the following:
* **Select a filesystem type**
* **Encryption password** (optional)
* **Hostname**
* **Create root password** (optional)
* **Creating a super-user**
* **Choose a pre-programmed profile**
![][25]
In my test, I chose BTRFS as the filesystem without setting any disk encryption password.
The hostname can be anything of your choice, but Id suggest keeping it short.
You may choose to create a root password, but it shouldnt be an issue if you do not. However, you need to create a superuser with Sudo privileges.
I used “**admin**” and “**pass**” as the user and the password, respectively. But, you should not use easy-to-guess credentials if you do not want anyone else to access the VM on your computer.
And, then, you will be shown a choice to select a profile. In this case, we want a full-fledged Arch Linux desktop. So, we choose “**desktop**” by typing in **0**.
**Step 6:** Next, you will be asked to choose a desktop environment. I decided to proceed with KDE. You can select anything else you like.
![][26]
**Step 7**: To finalize, you will be asked to choose the graphics card driver. Here, we install Arch Linux on VirtualBox, so you can select option 4 as “**VMware/VirtualBox**,” as shown in the image below.
![][27]
You may also be asked to choose pipewire instead of PulseAudio for audio with a “Yes (y) or No (no)” response. Any of those should serve the purpose.
****Step 8:**** Next comes an important step. Here, you can choose to go with **linux-lts** if you need the LTS version of the kernel, or else proceed with the default.
![][28]
The installer will prompt you to explicitly install any packages required. In this case, we do not have any specific requirements, so we will leave it blank and press enter to skip.
**Step 9:** To enable internet access, you will be asked to select the required network adapter. You will have to choose the option:
**Use network manager to control and manage your internet connection**
![][29]
**Step 10:** The timezone needs to be defined in the next step. Choose what applies to you, or continue with the default option.
**Step 11:** Once done, it will display most of the options you selected as confirmation. Press **Enter** to continue.
![][30]
**Step 12:** It will take a few minutes for the installation to complete, depending on your internet connection speed.
After the installation is complete, it will ask you to **chroot into a newly created installation for post-installation configuration**, but we dont need that. So, type in “**N**” to complete the installation.
**Step 13:** Finally, you should see the terminal window again. Type in:
```
shutdown now
```
This will safely exit the installation and close the virtual machine.
Its all set! Before starting the virtual machine with Arch installed, you need to do one more thing **remove the ISO disk selected as the optical drive**. Similar to how you added the ISO to boot from, you can head to the virtual machine settings and remove it as shown below:
![][31]
Thats it! You are done installing Arch Linux on VirtualBox.
All you have to do is start the virtual machine, and heres how it looks in my case:
![virtualbox arch][32]
Even though it takes a bit of time to go through the options, the new guided installer on Arch Linux saves a lot of time to get the essentials right.
![][33]
The same set of steps apply for installing Arch Linux on your computer. You need to [make a separate bootable USB drive using Etcher][34] with the Arch Linux ISO file.
### Wrapping Up
[Arch Linux is a popular choice][1] for a variety of reasons. However, if it is your first time installing, or if you want to test it out, a virtual machine is the best way to experience it without disrupting your host computer.
I hope this helps you install Arch Linux on VirtualBox. Let me know your thoughts in the comments down below.
--------------------------------------------------------------------------------
via: https://itsfoss.com/install-arch-linux-virtualbox/
作者:[Ankush Das][a]
选题:[lujun9972][b]
译者:[hanszhao80](https://github.com/hanszhao80)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://itsfoss.com/author/ankush/
[b]: https://github.com/lujun9972
[1]: https://itsfoss.com/why-arch-linux/
[2]: https://itsfoss.com/install-arch-linux/
[3]: https://itsfoss.com/debian-vs-ubuntu/
[4]: https://itsfoss.com/install-virtualbox-ubuntu/
[5]: https://www.virtualbox.org/wiki/Downloads
[6]: https://archlinux.org/download/
[7]: https://itsfoss.com/best-torrent-ubuntu/
[8]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2021/10/archlinux-downloads.png?resize=800%2C419&ssl=1
[9]: https://itsfoss.com/free-up-space-ubuntu-linux/
[10]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2021/10/virtualbox-new.png?resize=800%2C562&ssl=1
[11]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2021/10/virtualbox-expert-mode.png?resize=707%2C438&ssl=1
[12]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2021/10/virtualbox-create.png?resize=800%2C536&ssl=1
[13]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2021/10/virtualbox-disk.png?resize=800%2C528&ssl=1
[14]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2021/10/choose-disk-virtualbox-arch.png?resize=800%2C440&ssl=1
[15]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2021/10/virtualbox-settings-option.png?resize=800%2C551&ssl=1
[16]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2021/10/virtualbox-choose-iso.png?resize=800%2C314&ssl=1
[17]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2021/10/virtualbox-arch-iso-select.png?resize=800%2C348&ssl=1
[18]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2021/10/virtualbox-set-start.png?resize=800%2C548&ssl=1
[19]: https://news.itsfoss.com/arch-linux-easy-install/
[20]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2021/10/virtualbox-archlinux-boot.png?resize=800%2C593&ssl=1
[21]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2021/10/vb-archinstall-guided.png?resize=800%2C400&ssl=1
[22]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2021/10/vb-archinstall-kb-layout.png?resize=800%2C694&ssl=1
[23]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2021/10/archinstall-region.png?resize=800%2C664&ssl=1
[24]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2021/10/archinstall-selectdisk.png?resize=800%2C199&ssl=1
[25]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2021/10/archinstall-desktop-configure.png?resize=800%2C497&ssl=1
[26]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2021/10/archinstall-virtualbox-desktop-environment.png?resize=800%2C415&ssl=1
[27]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2021/10/virtualbox-environment.png?resize=419%2C173&ssl=1
[28]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2021/10/archinstall-linux-kernel.png?resize=800%2C692&ssl=1
[29]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2021/10/virtualbox-arch-network-manager.png?resize=800%2C151&ssl=1
[30]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2021/10/archinstall-confirmation.png?resize=800%2C697&ssl=1
[31]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2021/10/iso-remove-archinstall.png?resize=800%2C286&ssl=1
[32]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2021/10/virtualbox-arch.png?resize=800%2C635&ssl=1
[33]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2021/10/kde-arch-virtualbox.png?resize=800%2C453&ssl=1
[34]: https://itsfoss.com/install-etcher-linux/

View File

@ -1,311 +0,0 @@
[#]: subject: "Plotting Data in R: Graphs"
[#]: via: "https://www.opensourceforu.com/2022/05/plotting-data-in-r-graphs/"
[#]: author: "Shakthi Kannan https://www.opensourceforu.com/author/shakthi-kannan/"
[#]: collector: "lkxed"
[#]: translator: "tanloong"
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
Plotting Data in R: Graphs
======
R has a number of packages for plotting graphs and data visualisation, such as graphics, lattice, and ggplot2. In this ninth article in the R series, we shall explore the various functions to plot data in R.
![business-man-visulising-graphs][1]
We will be using R version 4.1.2 installed on Parabola GNU/Linux-libre (x86-64) for the code snippets.
```
$ R --version
R version 4.1.2 (2021-11-01) -- “Bird Hippie”
Copyright (C) 2021 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
```
R is free software and comes with absolutely no warranty. You are welcome to redistribute it under the terms of the GNU General Public License versions 2 or 3. For more information about these matters, see *https://www.gnu.org/licenses/.*
### Plot
Consider the all-India consumer price index (CPI rural/urban) data set up to November 2021 available at *https://data.gov.in/catalog/all-india-consumer-price-index-ruralurban-0* for the different states in India. We can read the data from the downloaded file using the read.csv function, as shown below:
```
> cpi <- read.csv(file=”CPI.csv”, sep=”,”)
> head(cpi)
Sector Year Name Andhra.Pradesh Arunachal.Pradesh Assam Bihar
1 Rural 2011 January 104 NA 104 NA
2 Urban 2011 January 103 NA 103 NA
3 Rural+Urban 2011 January 103 NA 104 NA
4 Rural 2011 February 107 NA 105 NA
5 Urban 2011 February 106 NA 106 NA
6 Rural+Urban 2011 February 105 NA 105 NA
Chattisgarh Delhi Goa Gujarat Haryana Himachal.Pradesh Jharkhand Karnataka
1 105 NA 103 104 104 104 105 104
2 104 NA 103 104 104 103 104 104
3 104 NA 103 104 104 103 105 104
4 107 NA 105 106 106 105 107 106
5 106 NA 105 107 107 105 107 108
6 105 NA 104 105 106 104 106 106
...
```
Let us aggregate the CPI values per year for the state of Punjab, and plot a line chart using the plot function, as follows:
```
> punjab <- aggregate(x=cpi$Punjab, by=list(cpi$Year), FUN=sum)
> head(punjab)
Group.1 x
1 2011 3881.76
2 2012 4183.30
3 2013 4368.40
4 2014 4455.50
5 2015 4584.30
6 2016 4715.80
> plot(punjab$Group.1, punjab$x, type=”l”, main=”Punjab Consumer Price Index upto November 2021”, xlab=”Year”, ylab=”Consumer Price Index”)
```
The following arguments are supported by the plot function:
| Argument | Description |
| :- | :- |
| x | A vector for the x-axis |
| y | The vector or list in the y-axis |
| type | p for points, l for lines, o for overplotted plots and lines, s for stair steps, h for histogram |
| xlim | The x limits of the plot |
| ylim | The y limits of the plot |
| main | The title of the plot |
| sub | The subtitle of the plot |
| xlab | The label for the x-axis |
| ylab | The label for the y-axis |
| axes | Logical value to draw the axes |
The line chart is shown in Figure 1.
![Figure 1: Line chart][2]
The autocorrelation plot can be used to obtain correlation statistics for time series analysis, and the same can be generated using the acf function in R. You can specify the following autocorrelation types: *correlation, covariance*, or partial. Figure 2 shows the ACF chart that represents the CPI values (x in the chart) for the state of Punjab.
![Figure 2: ACF chart][3]
The function*acf* accepts the following arguments:
| Argument | Description |
| :- | :- |
| x | A univariate or multivariate object or vector or matrix |
| lag.max | The maximum lag to calculate the acf |
| type | Supported values correlation, covariance, partial |
| plot | The acf is plotted if this value is TRUE |
| i | A set of time difference lags to retain |
| j | A collection of names or numbers to retain |
### Bar chart
The barplot function is used to draw a bar chart. The chart for Punjabs CPI can be generated as follows, and is shown in Figure 3:
![Figure 3: Line chart of Punjabs CPI][4]
```
> barplot(punjab$x, main=”Punjab Consumer Price Index”, sub=”Upto November 2021”, xlab=”Year”, ylab=”Consumer Price Index”, col=”navy”)
```
The function is quite flexible and supports the following arguments:
| Argument | Description |
| :- | :- |
| height | A numeric vector or matrix that contains the values |
| width | A numeric vector that specifies the widths of the bars |
| space | The amount of space between bars |
| beside | A logical value to specify if the bars should be stacked or next to each other |
| density | A numerical value that specifies the density of the shading lines |
| angle | The angle used to shade the lines |
| border | The colour of the border |
| main | The title of the chart |
| sub | The sub-title of the chart |
| xlab | The label for the x-axis |
| ylab | The label for the y-axis |
| xlim | The limits for the x-axis |
| ylim | The limits for the y-axis |
| axes | A value that specifies whether the axes should be drawn |
You can get more details on the barplot function using the help command, as shown below:
```
> help(barplot)
acf package:stats R Documentation
Auto- and Cross- Covariance and -Correlation Function Estimation
Description:
The function acf computes (and by default plots) estimates of
the autocovariance or autocorrelation function. Function pacf
is the function used for the partial autocorrelations. Function
ccf computes the cross-correlation or cross-covariance of two
univariate series.
Usage:
acf(x, lag.max = NULL,
type = c(“correlation”, “covariance”, “partial”),
plot = TRUE, na.action = na.fail, demean = TRUE, ...)
pacf(x, lag.max, plot, na.action, ...)
## Default S3 method:
pacf(x, lag.max = NULL, plot = TRUE, na.action = na.fail,
...)
ccf(x, y, lag.max = NULL, type = c(“correlation”, “covariance”),
plot = TRUE, na.action = na.fail, ...)
## S3 method for class acf
x[i, j]
```
### Pie chart
Pie charts need to be used wisely, as they may not actually show relative differences among the slices. We can generate the Rural, Urban, and Rural+Urban values for the month of January 2021 for Gujarat as follows, using the subset function:
```
> jan2021 <- subset(cpi, Name==”January” & Year==”2021”)
> jan2021$Gujarat
[1] 153.9 151.2 149.1
> names <- c(Rural, Urban, Rural+Urban)
```
![Figure 4: Pie chart][5]
The pie function can be used to generate the actual pie chart for the state of Gujarat, as shown below:
```
> pie(jan2021$Gujarat, names, main=”Gujarat CPI Rural and Urban Pie Chart”)
```
The following arguments are supported by the pie function:
| Argument | Description |
| :- | :- |
| x | Positive numeric values to be plotted |
| label | A vector of character strings for the labels |
| radius | The size of the pie |
| clockwise | A value to indicate if the pie should be drawn clockwise or counter-clockwise |
| density | A value for the density of shading lines per inch |
| angle | The angle that specifies the slope of the shading lines in degrees |
| col | A numeric vector of colours to be used |
| lty | The line type for each slice |
| main | The title of the chart |
### Boxplot
A boxplot shows the interquartile range between the 25th and 75th percentile using two whiskers for the distribution of a variable. The values outside the range are plotted separately. The boxplot functions take the following arguments:
| Argument | Description |
| :- | :- |
| data | A data frame or list that is defined |
| x | A vector that contains the values to plot |
| width | The width of the boxes to be plotted |
| outline | A logical value indicating whether to draw the outliers |
| names | The names of the labels for each box plot |
| border | The colour to use for the outline of each box plot |
| range | A maximum numerical amount the whiskers should extend from the boxes |
| plot | The boxes are plotted if this value is TRUE |
| horizontal | A logical value to indicate if the boxes should be drawn horizontally |
The boxplot for a few states from the CPI data is shown below:
```
> names <- c (Andaman and Nicobar, Lakshadweep, Delhi, Goa, Gujarat, Bihar)
> boxplot(cpi$Andaman.and.Nicobar, cpi$Lakshadweep, cpi$Delhi, cpi$Goa, cpi$Gujarat, cpi$Bihar, names=names)
```
![Figure 5: Box plot][6]
![Figure 6: Q-Q plot][7]
### Q-Q plot
The Quantile-Quantile (Q-Q) plot is a way to compare two data sets. You can also compare a data set with a theoretical distribution. The qqnorm function is a generic function, and we can view the Q-Q plot for the Punjab CPI data as shown below:
```
> qqnorm(punjab$x)
```
![Figure 7: Volcano][8]
The*qqline* function adds a theoretical line to a normal, quantile-quantile plot. The following arguments are accepted by these functions:
| Argument | Description |
| :- | :- |
| x | The first data sample |
| y | The second data sample |
| datax | A logical value indicating if values should be on the x-axis |
| probs | A numerical vector representing probabilities |
| xlab | The label for x-axis |
| ylab | The label for y-axis |
| qtype | The type of quantile computation |
### Contour plot
The contour function is useful for plotting three-dimensional data. You can generate a new contour plot, or add contour lines to an existing chart. These are commonly used along with image charts. The volcano data set in R provides information on the Maunga Whau (Mt Eden) volcanic field, and the same can be visualised with the contour function as follows:
```
> contour(volcano)
```
The contour function accepts the following arguments:
| Argument | Description |
| :- | :- |
| x,y | The location of the grid for z |
| z | A numeric vector to be plotted |
| nlevels | The number of contour levels |
| labels | A vector of labels for the contour lines |
| xlim | The x limits for the plot |
| ylim | The y limits for the plot |
| zlim | The z limits for the plot |
| axes | A value to indicate to print the axes |
| col | The colour for the contour lines |
| lty | The line type to draw |
| lwd | Width for the lines |
| vfont | The font for the labels |
The areas between the contour lines can be filled using a solid colour to indicate the levels, as shown below:
```
> filled.contour(volcano, asp = 1)
```
The same volcano data set with the filled.contour colours is illustrated in Figure 8.
![Figure 8: Filled volcano][9]
You are encouraged to explore the other functions and charts in the graphics package in R.
--------------------------------------------------------------------------------
via: https://www.opensourceforu.com/2022/05/plotting-data-in-r-graphs/
作者:[Shakthi Kannan][a]
选题:[lkxed][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://www.opensourceforu.com/author/shakthi-kannan/
[b]: https://github.com/lkxed
[1]: https://www.opensourceforu.com/wp-content/uploads/2022/04/business-man-visulising-graphs.jpg
[2]: https://www.opensourceforu.com/wp-content/uploads/2022/04/Figure-1-Line-chart.jpg
[3]: https://www.opensourceforu.com/wp-content/uploads/2022/04/Figure-2-ACF-chart.jpg
[4]: https://www.opensourceforu.com/wp-content/uploads/2022/04/Figure-3-Line-chart-of-Punjabs-CPI.jpg
[5]: https://www.opensourceforu.com/wp-content/uploads/2022/04/Figure-4-Pie-chart.jpg
[6]: https://www.opensourceforu.com/wp-content/uploads/2022/04/Figure-5-ox-plot.jpg
[7]: https://www.opensourceforu.com/wp-content/uploads/2022/04/Figure-6-Q-Q-plot.jpg
[8]: https://www.opensourceforu.com/wp-content/uploads/2022/04/Figure-7-Volcano.jpg
[9]: https://www.opensourceforu.com/wp-content/uploads/2022/04/Figure-8-Filled-volcano.jpg

View File

@ -1,143 +0,0 @@
[#]: subject: "Monitoring tiny web services"
[#]: via: "https://jvns.ca/blog/2022/07/09/monitoring-small-web-services/"
[#]: author: "Julia Evans https://jvns.ca/"
[#]: collector: "lujun9972"
[#]: translator: "geekpi"
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
Monitoring tiny web services
======
Hello! Ive started to run a few more servers recently ([nginx playground][1], [mess with dns][2], [dns lookup][3]), so Ive been thinking about monitoring.
It wasnt initially totally obvious to me how to monitor these websites, so I wanted to quickly write up what how I did it.
Im not going to talk about how to monitor Big Serious Mission Critical websites at all, only tiny unimportant websites.
### goal: spend approximately 0 time on operations
I want the sites to mostly work, but I also want to spend approximately 0% of my time on the ongoing operations.
I was initially very wary of running servers at all because at my last job I was on a 247 oncall rotation for some critical services, and in my mind “being responsible for servers” meant “get woken up at 2am to fix the servers” and “have lots of complicated dashboards”.
So for a while I only made static websites so that I wouldnt have to think about servers.
But eventually I realized that any server I was going to write was going to be very low stakes, if they occasionally go down for 2 hours its no big deal, and I could just set up some very simple monitoring to help keep them running.
### not having monitoring sucks
At first I didnt set up any monitoring for my servers at all. This had the extremely predictable outcome of sometimes the site broke, and I didnt find out about it until somebody told me!
### step 1: an uptime checker
The first step was to set up an uptime checker. There are tons of these out there, the ones Im using right now are [updown.io][4] and [uptime robot][5]. I like updowns user interface and [pricing][6] structure more (its per request instead of a monthly fee), but uptime robot has a more generous free tier.
These
1. check that the site is up
2. if it goes down, it emails me
I find that email notifications are a good level for me, Ill find out pretty quickly if the site goes down but it doesnt wake me up or anything.
### step 2: an end-to-end healthcheck
Next, lets talk about what “check that the site is up” actually means.
At first I just made one of my healthcheck endpoints a function that returned `200 OK` no matter what.
This is kind of useful it told me that the server was on!
But unsurprisingly I ran into problems because it wasnt checking that the API was actually _working_ sometimes the healthcheck succeeded even though the rest of the service had actually gotten into a bad state.
So I updated it to actually make a real API request and make sure it succeeded.
All of my services do very few things (the nginx playground has just 1 endpoint), so its pretty easy to set up a healthcheck that actually runs through most of the actions the service is supposed to do.
Heres what the end-to-end healthcheck handler for the nginx playground looks like. Its very basic: it just makes another POST request (to itself) and checks if that request succeeds or fails.
```
func healthHandler(w http.ResponseWriter, r *http.Request) {
// make a request to localhost:8080 with `healthcheckJSON` as the body
// if it works, return 200
// if it doesn't, return 500
client := http.Client{}
resp, err := client.Post("http://localhost:8080/", "application/json", strings.NewReader(healthcheckJSON))
if err != nil {
log.Println(err)
w.WriteHeader(http.StatusInternalServerError)
return
}
if resp.StatusCode != http.StatusOK {
log.Println(resp.StatusCode)
w.WriteHeader(http.StatusInternalServerError)
return
}
w.WriteHeader(http.StatusOK)
}
```
### healthcheck frequency: hourly
Right now Im running most of my healthchecks every hour, and some every 30 minutes.
I run them hourly because updown.ios pricing is per healthcheck, Im monitoring 18 different URLs, and I wanted to keep my healthcheck budget pretty minimal at $5/year.
Taking an hour to find out that one of these websites has gone down seems ok to me if there is a problem theres no guarantee Ill get to fixing it all that quickly anyway.
If it were free to run them more often Id probably run them every 5-10 minutes instead.
### step 3: automatically restart if the healthcheck fails
Some of my websites are on fly.io, and fly has a pretty standard feature where I can configure a HTTP healthcheck for a service and restart the service if the healthcheck starts failing.
“Restart a lot” is a very useful strategy to paper over bugs that I havent gotten around to fixing yet for a while the nginx playground had a process leak where `nginx` processes werent getting terminated, so the server kept running out of RAM.
With the healthcheck, the result of this was that every day or so, this would happen:
* the server ran out of RAM
* the healthcheck started failing
* it get restarted
* everything was fine again
* repeat the whole saga again some number of hours later
Eventually I got around to actually fixing the process leak, but it was nice to have a workaround in place that could keep things running while I was procrastinating fixing the bug.
These healthchecks to decide whether to restart the service run more often: every 5 minutes or so.
### this is not the best way to monitor Big Services
This is probably obvious and I said this already at the beginning, but “write one HTTP healthcheck” is not the best approach for monitoring a large complex service. But I wont go into that because thats not what this post is about.
### its been working well so far!
I originally wrote this post 3 months ago in April, but I waited until now to publish it to make sure that the whole setup was working.
Its made a pretty big difference before I was having some very silly downtime problems, and now for the last few months the sites have been up 99.95% of the time!
--------------------------------------------------------------------------------
via: https://jvns.ca/blog/2022/07/09/monitoring-small-web-services/
作者:[Julia Evans][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://jvns.ca/
[b]: https://github.com/lujun9972
[1]: https://nginx-playground.wizardzines.com
[2]: https://messwithdns.net
[3]: https://dns-lookup.jvns.ca
[4]: https://updown.io/
[5]: https://uptimerobot.com/
[6]: https://updown.io/#pricing

View File

@ -2,7 +2,7 @@
[#]: via: "https://www.opensourceforu.com/2022/07/manual-renewal-of-ssl-certificates-a-simple-guide/"
[#]: author: "Jitendra Bhojwani https://www.opensourceforu.com/author/jitendra-bhojwani/"
[#]: collector: "lkxed"
[#]: translator: " "
[#]: translator: "geekpi"
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "

View File

@ -2,7 +2,7 @@
[#]: via: "https://opensource.com/article/22/7/garbage-collection-java"
[#]: author: "Jayashree Huttanagoudar https://opensource.com/users/jayashree-huttanagoudar"
[#]: collector: "lkxed"
[#]: translator: " "
[#]: translator: "Veryzzj"
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "

View File

@ -0,0 +1,268 @@
[#]: subject: "Beginners Guide to Installing Arch Linux on VirtualBox"
[#]: via: "https://itsfoss.com/install-arch-linux-virtualbox/"
[#]: author: "Ankush Das https://itsfoss.com/author/ankush/"
[#]: collector: "lujun9972"
[#]: translator: "hanszhao80"
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
VirtualBox 安装 Arch Linux 的新手操作指南
======
[Arch Linux 在桌面 Linux 世界中非常流行][1]。受欢迎的原因之一是 [安装 Arch Linux][2] 本身就是一项复杂的任务。
我没有夸大其词。安装 [Ubuntu 或 Debian][3] 比 Arch Linux 容易得多,因为官方没给后者提供图形界面的安装程序。这时虚拟机就派上用场了。
你可以先在 VirtualBox 中尝试安装 Arch Linux看看它是否是你想在实际硬件上运行的系统。通过这种方式你可以在不打乱当前操作系统的情况下体验 Arch Linux。
在本文,我将一步一步指导你完成一个实用的 Arch Linux 虚拟机的安装过程。
### 在 VirtualBox 上安装 Arch Linux
毫无疑问,你需要先 [在 Linux 上安装 VirtualBox][4](或 Windows。在 Windows 上,只需访问 Oracle 的网站并下载 VirtualBox。
[下载 VirtualBox][5]
如果你使用的是 Windows 10 或更高版本,请确保你的系统已启用虚拟化。
完成后,你需要到 [Arch Linux 官方网站][6] 下载 ISO 文件。你应该找到 [使用 torrent 下载][7] 或直接下载文件的选项。
![][8]
你可以保留 ISO 文件以备不时之需,安装成功后也可以将其删除以 [释放系统上的空间][9]。
现在,让我们开始在 VirtualBox 上安装 Arch Linux 吧。
#### 第一部分 创建虚拟机
**第一步**:首先,你需要在 VirtualBox 中设置一下。启动 VirtualBox 并单击 **<ruby>新建<rt>New</rt></ruby>** 来创建一个虚拟机。
![][10]
注意,你可以使用<ruby>向导模式<rt>guided mode</rt></ruby>继续创建虚拟机,但使用<ruby>专家模式<rt>expert mode</rt></ruby>可以一目了然地获得更多选项。
![][11]
因此,我推荐使用专家模式来创建虚拟机。
不用担心,专家模式同样简单,只是多了一些额外的可选项,无需担心其他任何事情。
**第二步**:输入你的虚拟机名称。当你在<ruby>名称<rt>Name</rt></ruby>字段中输入 **Arch Linux** 时,它会分别自动检测<ruby>类型<rt>Type</rt></ruby><ruby>版本<rt>Version</rt></ruby>
![][12]
你应该增加内存大小以舒适地使用虚拟机。如果只是用于小型测试,你可以继续使用默认设置。
我在这个例子中分配了 **4 GB 左右的内存**
另外,请确保在<ruby>硬盘<rt>Hard disk</rt></ruby>选项下选择**<ruby>现在创建虚拟硬盘<rt>create a virtual hard disk</rt></ruby>**。它应该是默认选项。
现在,继续设置虚拟硬盘大小。
**第三步**:你可以选择虚拟硬盘的存放位置,并根据你的需求调整大小。最小分配大小 (8 GB) 对于安装系统应该不是问题,但安全起见,你可能得分配至少 10 到 15 GB。
![][13]
接下来,你需要将硬盘硬盘文件类型选择为 **VDI (VirtualBox <ruby>磁盘镜像<rt>Disk Image</rt></ruby>)** ,将存储选择为 **<ruby>动态分配<rt>Dynamically assigned</rt></ruby>**,如上图所示。
VDI 是虚拟硬盘最常见的硬盘类型。
当你为硬盘存储选择 **动态分配** 选项时,这意味着存储空间将根据使用情况进行使用。换言之,当创建虚拟机后,并不会立即将这 15 GB 的空间从你的磁盘中锁定。
现在,你所要做的就是点击 **<ruby>创建<rt>Create</rt></ruby>** 来添加虚拟机。
#### 第二部分 添加 ISO 文件以开始安装 Arch Linux
![][14]
当虚拟机在左侧列表中出现后,你可以查看其配置并在 **<ruby>存储<rt>Storage</rt></ruby>** 选项下选择 ISO 文件作为磁盘驱动。
你也可以单独前往虚拟机设置以探索更多内容并选择 ISO 文件。
![][15]
为此,你需要导航至虚拟机设置的 **<ruby>存储<rt>Storage</rt></ruby>** 页签。
![][16]
在这里,你必须单击 <ruby>控制器<rt>Controller</rt></ruby> 下的 **<ruby>没有盘片<rt>Empty</rt></ruby>**,然后继续选择 Arch Linux ISO 文件作为磁盘文件(如上图所示)。
![][17]
完成选择后,点击 **OK** 以保存设置的变更。
将 ISO 设置为要引导的磁盘时,虚拟机设置应如下所示:
![][18]
现在,点击 **<ruby>启动<rt>Start</rt></ruby>** 启动虚拟机并开始安装。
#### 第三部分 使用引导式安装程序安装 Arch Linux
使用 [介绍一个引导式安装程序][19] 的方法使安装 Arch Linux 变得更容易,也就是说,它为你提供了设置成熟的 Arch Linux 系统所需的所有选项。
因此,在引导式安装程序的帮助下,你不必单独安装桌面环境和其他基本软件包。你所要做的就是按照屏幕上的说明选择适合你的选项。
在本文中,我们将重点介绍引导式安装程序。如果你想自己做,你应该遵循我们的 [Arch 安装指南][2]。
继续安装流程,当你启动虚拟机时,将看到以下屏幕:
![][20]
第一个选项是理想的处理方式。如果你有特定的要求,可以选择其他选项来启动 Arch Linux。
现在,你应该正在查看一个终端窗口。以下是如何开始:
**第一步**:输入 `archinstall` 以使用引导式安装程序启动安装。
![][21]
**第二步**根据你的要求选择键盘布局美式布局应该是最常见的选择。简单地输入一个数字即可进行选择如下图所示例如26
![][22]
**第三步**:接下来,你需要选择一个区域来下载包。
![][23]
选择首选地区而不是“<ruby>全球<rt>“Worldwide”</rt></ruby>”。这至关重要,因为如果你选择 **全球** 作为你的地区,它会下载许多不必要的包。
**第四步**:选择区域后,它会要求你选择驱动器进行安装。在这个例子中,我们已经创建了一个大约 15 GB 的虚拟驱动器,显示为 **/dev/sda**。
类似的,根据大小检查你创建的驱动器,然后选择该磁盘继续。在这里,我输入 `1` 作为输入;你的可能会有所不同。
![][24]
**第五步**:接下来,你将被询问以下内容:
- **选择文件系统类型**
- **加密密码** (可选的)
- **主机名**
- **创建 root 密码** (可选的)
- **创建超级用户**
- **选择一个预编程的配置文件**
![][25]
在我的测试中,我选择了 BTRFS 作为文件系统,没有设置任何磁盘加密密码。
主机名可随心所欲的设置,但我建议保持简短。
你可以选择创建一个 root 密码,即使不这么做也应该没什么问题。不过,你需要创建一个具有 Sudo 权限的超级用户。
我使用 **admin/pass** 作为用户名和密码。不过,如果你不想让其他人访问你计算机上的虚拟机,则不应使用易于猜测的密码。
然后,你将看到一个选择配置文件的选项。在这种情况下,我们需要一个成熟的 Arch Linux 桌面。因此,我们通过输入 `0` 来选择 **<ruby>桌面<rt>desktop</rt></ruby>**。
**第六步**:接下来,你将被要求选择桌面环境。我决定使用 KDE。你可以选择任何你喜欢的。
![][26]
**第七步**:最后,你将被要求选择显卡驱动程序。由于我们是在 VirtualBox 上安装的 Arch Linux你可以选择选项 4**VMware/VirtualBox**,如下图所示:
![][27]
你可能还会被要求输入“是y或否no”选择 pipewire 而不是 PulseAudio 作为音频服务。选任何一个都应该都能达到目的。
**第八步**:接下来是重要的一步。在这里,如果你需要内核的 LTS 版本,你可以选择使用 **linux-lts**,或者继续使用默认值。
![][28]
安装程序会提示你输入想安装的软件包。在这里,我们没有任何特殊要求,因此我们将其留空并按回车键跳过。
**第九步**:你将被要求选择所需的网络适配器以启用互联网访问。你必须选择以下选项:
**<ruby>使用网络管理器来控制和管理你的互联网连接<rt>Use network manager to control and manage your internet connection</rt></ruby>**
![][29]
**第十步**:下一步需要定义时区。选择适用于你的时区,或继续使用默认选项。
**第十一步**:完成后,它将显示你选择的大部分选项以供确认。按 **回车** 继续。
![][30]
**第十二步**:安装完成需要花费几分钟时间,这取决于你的互联网连接速度。
安装完成后,它会要求你**chroot 进入新创建的安装以进行安装后配置**,但我们不需要。因此输入 `N` 以完成安装。
**第十三步**:最后,你应该会再次看到终端窗口。输入:
```
shutdown now
```
这将安全地退出安装并关闭虚拟机。
一切就绪!在启动安装了 Arch 的虚拟机之前,你还需要做一件事 —— **移除选择作为光驱的 ISO 磁盘**。与添加启动 ISO 的方式类似,你可以前往虚拟机设置并将其删除,如下所示:
![][31]
到此为止你已在 VirtualBox 上安装了 Arch Linux。
你所要做的就是启动虚拟机,在我的例子中它是这样的:
![virtualbox arch][32]
尽管浏览这些选项需要一些时间,但 Arch Linux 上新的引导式安装程序可以节省大量时间使必填项配置正确。
![][33]
同样的步骤也适用于在你的计算机上安装 Arch Linux。你需要用 Arch Linux ISO 文件 [使用 Etcher 制作单独的可启动 USB 盘][34]。
### 总结
[Arch Linux 成为一种流行的选择][1] 有多种原因。但是,如果这是你第一次安装,或者你想对其进行测试,那么虚拟机是在不打乱主机的情况下体验它的最佳方式。
我希望这可以帮助你在 VirtualBox 上安装 Arch Linux。在下面的评论中让我知道你的想法。
--------------------------------------------------------------------------------
via: https://itsfoss.com/install-arch-linux-virtualbox/
作者:[Ankush Das][a]
选题:[lujun9972][b]
译者:[hanszhao80](https://github.com/hanszhao80)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://itsfoss.com/author/ankush/
[b]: https://github.com/lujun9972
[1]: https://itsfoss.com/why-arch-linux/
[2]: https://itsfoss.com/install-arch-linux/
[3]: https://itsfoss.com/debian-vs-ubuntu/
[4]: https://itsfoss.com/install-virtualbox-ubuntu/
[5]: https://www.virtualbox.org/wiki/Downloads
[6]: https://archlinux.org/download/
[7]: https://itsfoss.com/best-torrent-ubuntu/
[8]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2021/10/archlinux-downloads.png?resize=800%2C419&ssl=1
[9]: https://itsfoss.com/free-up-space-ubuntu-linux/
[10]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2021/10/virtualbox-new.png?resize=800%2C562&ssl=1
[11]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2021/10/virtualbox-expert-mode.png?resize=707%2C438&ssl=1
[12]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2021/10/virtualbox-create.png?resize=800%2C536&ssl=1
[13]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2021/10/virtualbox-disk.png?resize=800%2C528&ssl=1
[14]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2021/10/choose-disk-virtualbox-arch.png?resize=800%2C440&ssl=1
[15]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2021/10/virtualbox-settings-option.png?resize=800%2C551&ssl=1
[16]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2021/10/virtualbox-choose-iso.png?resize=800%2C314&ssl=1
[17]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2021/10/virtualbox-arch-iso-select.png?resize=800%2C348&ssl=1
[18]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2021/10/virtualbox-set-start.png?resize=800%2C548&ssl=1
[19]: https://news.itsfoss.com/arch-linux-easy-install/
[20]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2021/10/virtualbox-archlinux-boot.png?resize=800%2C593&ssl=1
[21]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2021/10/vb-archinstall-guided.png?resize=800%2C400&ssl=1
[22]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2021/10/vb-archinstall-kb-layout.png?resize=800%2C694&ssl=1
[23]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2021/10/archinstall-region.png?resize=800%2C664&ssl=1
[24]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2021/10/archinstall-selectdisk.png?resize=800%2C199&ssl=1
[25]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2021/10/archinstall-desktop-configure.png?resize=800%2C497&ssl=1
[26]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2021/10/archinstall-virtualbox-desktop-environment.png?resize=800%2C415&ssl=1
[27]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2021/10/virtualbox-environment.png?resize=419%2C173&ssl=1
[28]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2021/10/archinstall-linux-kernel.png?resize=800%2C692&ssl=1
[29]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2021/10/virtualbox-arch-network-manager.png?resize=800%2C151&ssl=1
[30]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2021/10/archinstall-confirmation.png?resize=800%2C697&ssl=1
[31]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2021/10/iso-remove-archinstall.png?resize=800%2C286&ssl=1
[32]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2021/10/virtualbox-arch.png?resize=800%2C635&ssl=1
[33]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2021/10/kde-arch-virtualbox.png?resize=800%2C453&ssl=1
[34]: https://itsfoss.com/install-etcher-linux/

View File

@ -0,0 +1,324 @@
[#]: subject: "Plotting Data in R: Graphs"
[#]: via: "https://www.opensourceforu.com/2022/05/plotting-data-in-r-graphs/"
[#]: author: "Shakthi Kannan https://www.opensourceforu.com/author/shakthi-kannan/"
[#]: collector: "lkxed"
[#]: translator: "tanloong"
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
R 语言绘制数据:图表篇
======
R 语言有非常多的绘图和数据可视化的包,比如 graphics、lattice、ggplot2 等。这是 R 语言系列的第 9 篇文章,我们会介绍 R 中用来绘图的各种函数。
![business-man-visulising-graphs][1]
本文使用的 R 是 4.1.2 版本,
运行环境为 Parabola GNU/Linux-libre (x86-64)。
```R
$ R --version
R version 4.1.2 (2021-11-01) -- "Bird Hippie"
Copyright (C) 2021 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
```
R 是开源软件,没有任何担保责任。
只要遵守 GNU 通用公共许可证的版本 2 或者版本 3你就可以对它进行 (修改和) 再分发。
详情见 [*https://www.gnu.org/licenses/.*](https://www.gnu.org/licenses/.)
### 折线图
我们以印度全境消费者物价指数 (CPI -- 乡村/城市) 数据集为研究对象,它可以从 [*https://data.gov.in/catalog/all-india-consumer-price-index-ruralurban-0*](https://data.gov.in/catalog/all-india-consumer-price-index-ruralurban-0) 下载。选择 "截止到 2021 年 11 月" 的版本,用 read.csv 函数读取下载好的文件,如下所示:
```R
> cpi <- read.csv(file="CPI.csv", sep=",")
> head(cpi)
Sector Year Name Andhra.Pradesh Arunachal.Pradesh Assam Bihar
1 Rural 2011 January 104 NA 104 NA
2 Urban 2011 January 103 NA 103 NA
3 Rural+Urban 2011 January 103 NA 104 NA
4 Rural 2011 February 107 NA 105 NA
5 Urban 2011 February 106 NA 106 NA
6 Rural+Urban 2011 February 105 NA 105 NA
Chattisgarh Delhi Goa Gujarat Haryana Himachal.Pradesh Jharkhand Karnataka
1 105 NA 103 104 104 104 105 104
2 104 NA 103 104 104 103 104 104
3 104 NA 103 104 104 103 105 104
4 107 NA 105 106 106 105 107 106
5 106 NA 105 107 107 105 107 108
6 105 NA 104 105 106 104 106 106
...
```
以 Punjab 州为例,对每年各月份的 CPI 值求和,然后用 plot 函数画一张折线图:
```R
> punjab <- aggregate(x=cpi$Punjab, by=list(cpi$Year), FUN=sum)
> head(punjab)
Group.1 x
1 2011 3881.76
2 2012 4183.30
3 2013 4368.40
4 2014 4455.50
5 2015 4584.30
6 2016 4715.80
> plot(punjab$Group.1, punjab$x, type="l", main="Punjab Consumer Price Index upto November 2021", xlab="Year", ylab="Consumer Price Index")
```
plot 函数可以传入如下参数:
| 参数 | 描述 |
| :- | :- |
| x | 向量类型,用于绘制 x 轴的数据 |
| y | 向量或列表类型,用于绘制 y 轴的数据 |
| type | 设置绘图类型:"p" 画点;"l" 画线;"o" 同时画点和线,且相互重叠;"s" 画阶梯线;"h" 画铅垂线 |
| xlim | x 轴范围 |
| ylim | y 轴范围 |
| main | 标题 |
| sub | 副标题 |
| xlab | x 轴标题 |
| ylab | y 轴标题 |
| axes | 逻辑型,是否绘制坐标轴 |
结果如图 1。
![Figure 1: Line chart][2]
### 自相关图
自相关图能在时序分析中展示一个变量是否具有自相关性,可以用 R 中的 acf 函数绘制。acf 函数可以设置三种自相关类型:*correlation*、*covariance* 或 *partial*。图 2 是 Punjab 州 CPI 值的自相关图x 表示 CPI。
```R
acf(punjab$x,main='x')
```
![Figure 2: ACF chart][3]
acf 函数可以传入以下参数:
| 参数 | 描述 |
| :- | :- |
| x | 一个单变量或多变量的 time series 对象,或者一个数值向量或数值矩阵 |
| lag.max | 最大滞后阶数 |
| type | 字符型,设置所计算的自相关类型:"correlation"、"covariance" 或 "partial" |
| plot | 逻辑性,若 TRUE 则绘制图像,若 FALSE 则打印传入数据的描述信息 |
| i | 一组要保留的时差滞后 |
| j | 一组要保留的名称或数字 |
### 柱状图
R 中画柱状图的函数是 barplot。下面的代码用来画 Punjab 州 CPI 的柱状图如图3
```R
> barplot(punjab$x, main="Punjab Consumer Price Index", sub="Upto November 2021", xlab="Year", ylab="Consumer Price Index", col="navy")
```
![Figure 3: Line chart of Punjab's CPI][4]
barplot 函数的使用方法非常灵活,可以传入以下参数:
| 参数 | 描述 |
| :- | :- |
| height | 数值向量或数值矩阵,包含用于绘图的数据 |
| width | 数值向量,用于设置柱宽 |
| space | 柱间距 |
| beside | 逻辑型,若 FALSE 则绘制堆积柱状图,若 TRUE 则绘制并列柱状图 |
| density | 数值型,设置阴影线的填充密度 (条数/英寸),默认为 NULL即不填充阴影线|
| angle | 数值型,填充线条的角度,默认为 45 |
| border | 柱子边缘的颜色 |
| main | 标题 |
| sub | 副标题 |
| xlab | x 轴标题 |
| ylab | y 轴标题 |
| xlim | x 轴范围 |
| ylim | y 轴范围 |
| axes | 逻辑型,是否绘制坐标轴 |
用 help 命令可以查看 barplot 函数的详细信息:
```R
> help(barplot)
barplot package:graphics R Documentation
Bar Plots
Description:
Creates a bar plot with vertical or horizontal bars.
Usage:
barplot(height, ...)
## Default S3 method:
barplot(height, width = 1, space = NULL,
names.arg = NULL, legend.text = NULL, beside = FALSE,
horiz = FALSE, density = NULL, angle = 45,
col = NULL, border = par("fg"),
main = NULL, sub = NULL, xlab = NULL, ylab = NULL,
xlim = NULL, ylim = NULL, xpd = TRUE, log = "",
axes = TRUE, axisnames = TRUE,
cex.axis = par("cex.axis"), cex.names = par("cex.axis"),
inside = TRUE, plot = TRUE, axis.lty = 0, offset = 0,
add = FALSE, ann = !add && par("ann"), args.legend = NULL, ...)
## S3 method for class 'formula'
barplot(formula, data, subset, na.action,
horiz = FALSE, xlab = NULL, ylab = NULL, ...)
```
### 饼图
绘制饼图时要多加注意,因为饼图不一定能展示出各扇形间的区别。(LCTT 译注:"根据统计学家和一些心理学家的调查结果,这种以比例展示数据的统计图形 [实际上是很糟糕的可视化方式][10]因此R 关于饼图的帮助文件中清楚地说明了并不推荐使用饼图,而是使用条形图或点图作为替代。") 用 subset 函数获得 Gujarat 州在 2021 年 1 月 Rural、Urban、Rurual+Urban 的 CPI 值:
```R
> jan2021 <- subset(cpi, Name=="January" & Year=="2021")
> jan2021$Gujarat
[1] 153.9 151.2 149.1
> names <- c('Rural', 'Urban', 'Rural+Urban')
```
使用 pie 函数为 Gujarat 州的 CPI 值生成饼图,如下所示:
```R
> pie(jan2021$Gujarat, names, main="Gujarat CPI Rural and Urban Pie Chart")
```
![Figure 4: Pie chart][5]
pie 函数可以传入以下参数:
| 参数 | 描述 |
| :- | :- |
| x | 元素大于 0 的数值向量 |
| label | 字符向量,用于设置每个扇形的标签 |
| radius | 饼图的半径 |
| clockwise | 逻辑型,若 TRUE 则顺时针绘图,若 FALSE 则逆时针绘图 |
| density | 数值型,设置阴影线的填充密度 (条数/英寸),默认为 NULL即不填充阴影线|
| angle | 数值型,填充线条的角度,默认为 45 |
| col | 数值向量,用于设置颜色 |
| lty | 每个扇形的线条类型 |
| main | 标题 |
### 箱线图
(LCTT 译注:"箱线图主要是 [从四分位数的角度出发][11] 描述数据的分布,它通过最大值 (Q4)、上四分位数 (Q3)、中位数(Q2)、下四分位数 (Q1) 和最小值 (Q0) 五处位置来获取一维数据的分布概况。我们知道,这五处位置之间依次包含了四段数据,每段中数据量均为总数据量的 1/4。通过每一段数据占据的长度我们可以大致推断出数据的集中或离散趋势 (长度越短,说明数据在该区间上越密集,反之则稀疏。)")
箱线图能够用“须线” (whiskers) 展示一个变量的四分位距 (Interquartile Range简称 IQR=Q3-Q1)。用上下四分位数分别加/减内四分位距,再乘以一个人为设定的倍数 range (见下面的参数列表),得到 `range * c(Q1-IQR, Q3+IQR)`,超过这个范围的数据点就被视作离群点,在图中直接以点的形式表示出来。
boxplot 函数可以传入以下参数:
| 参数 | 描述 |
| :- | :- |
| data | 数据框或列表,用于参数类型为公式 (formula) 的情况 |
| x | 数值向量或者列表,若为列表则对列表中每一个子对象依次作出箱线图 |
| width | 设置箱子的宽度 |
| outline | 逻辑型,设置是否绘制离群点 |
| names | 设置每个箱子的标签 |
| border | 设置每个箱子的边缘的颜色 |
| range | 延伸倍数,设置箱线图末端 (须) 延伸到什么位置 |
| plot | 逻辑型,设置是否生成图像,若 TRUE 则生成图像,若 FALSE 则打印传入数据的描述信息 |
| horizontal | 逻辑型,设置箱线图是否水平放置 |
用 boxplot 函数绘制部分州的箱线图:
```R
> names <- c ('Andaman and Nicobar', 'Lakshadweep', 'Delhi', 'Goa', 'Gujarat', 'Bihar')
> boxplot(cpi$Andaman.and.Nicobar, cpi$Lakshadweep, cpi$Delhi, cpi$Goa, cpi$Gujarat, cpi$Bihar, names=names)
```
![Figure 5: Box plot][6]
### QQ 图
QQ 图 (Quantile-Quantile plot) 可以用来对比两个数据集也可以用来检查数据是否服从某种理论分布。qqnorm 函数能绘制正态分布 QQ 图,可以检验数据是否服从正态分布,用下面的代码绘制 Punjab 州 CPI 数据的 QQ 图:
```R
> qqnorm(punjab$x)
```
![Figure 6: Q-Q plot][7]
qqline 函数可以向正态分布 QQ 图上添加理论分布曲线,它可以传入以下参数:
| 参数 | 描述 |
| :- | :- |
| x | 第一个数据样本 |
| y | 第二个数据样本 |
| datax | 逻辑型,设置是否以 x 轴表示理论曲线的值,默认为 FALSE |
| probs | 长度为 2 的数值向量,代表概率 |
| xlab | x 轴标题 |
| ylab | y 轴标题 |
| qtype | [1,9] 内的整数,设置分位计算类型,详情见 help(quantile) 的 "Type" 小节 |
### 等高图
等高图可以描述三维数据,在 R 中对应的函数是 contour这个函数也可以用来向已有的图表添加等高线。等高图常与其他图表一起使用。我们用 contour 对 R 中的 volcano 数据集 (奥克兰的火山地形信息) 绘制等高图,代码如下:
```R
> contour(volcano)
```
![Figure 7: Volcano][8]
contour 函数的常用参数如下:
| 参数 | 描述 |
| :- | :- |
| x,y | z 中数值对应的点在平面上的位置 |
| z | 数值向量 |
| nlevels | 设置等高线的条数,调整等高线的疏密 |
| labels | 等高线上的标记字符串,默认是高度的数值 |
| xlim | 设置 x 轴的范围 |
| ylim | 设置 y 轴的范围 |
| zlim | 设置 z 轴的范围 |
| axes | 设置是否绘制坐标轴 |
| col | 设置等高线的颜色 |
| lty | 设置线条的类型 |
| lwd | 设置线条的粗细 |
| vfont | 设置标签字体 |
等高线之间的区域可以用颜色填充,每种颜色表示一个高度范围,如下所示:
```R
> filled.contour(volcano, asp = 1)
# asp 为图形纵横比,即 y 轴上的 1 单位长度和 x 轴上 1 单位长度的比率
```
填充结果见图 8。
![Figure 8: Filled volcano][9]
掌握上述内容后,你可以尝试 R 语言 graphics 包中的其他函数和图表 (LCTT 译注:用 help(package=graphics) 可以查看 graphics 包提供的函数列表)。
--------------------------------------------------------------------------------
via: https://www.opensourceforu.com/2022/05/plotting-data-in-r-graphs/
作者:[Shakthi Kannan][a]
选题:[lkxed][b]
译者:[tanloong](https://github.com/tanloong)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://www.opensourceforu.com/author/shakthi-kannan/
[b]: https://github.com/lkxed
[1]: https://www.opensourceforu.com/wp-content/uploads/2022/04/business-man-visulising-graphs.jpg
[2]: https://www.opensourceforu.com/wp-content/uploads/2022/04/Figure-1-Line-chart.jpg
[3]: https://www.opensourceforu.com/wp-content/uploads/2022/04/Figure-2-ACF-chart.jpg
[4]: https://www.opensourceforu.com/wp-content/uploads/2022/04/Figure-3-Line-chart-of-Punjabs-CPI.jpg
[5]: https://www.opensourceforu.com/wp-content/uploads/2022/04/Figure-4-Pie-chart.jpg
[6]: https://www.opensourceforu.com/wp-content/uploads/2022/04/Figure-5-ox-plot.jpg
[7]: https://www.opensourceforu.com/wp-content/uploads/2022/04/Figure-6-Q-Q-plot.jpg
[8]: https://www.opensourceforu.com/wp-content/uploads/2022/04/Figure-7-Volcano.jpg
[9]: https://www.opensourceforu.com/wp-content/uploads/2022/04/Figure-8-Filled-volcano.jpg
[10]: https://bookdown.org/xiangyun/msg/gallery.html#sec:pie
[11]: https://bookdown.org/xiangyun/msg/gallery.html#sec:boxplot

View File

@ -0,0 +1,143 @@
[#]: subject: "Monitoring tiny web services"
[#]: via: "https://jvns.ca/blog/2022/07/09/monitoring-small-web-services/"
[#]: author: "Julia Evans https://jvns.ca/"
[#]: collector: "lujun9972"
[#]: translator: "geekpi"
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
监测微型网络服务
======
你好! 我最近又开始运行一些服务器([nginx playground][1]、[mess with dns][2]、[dns lookup][3]),所以我一直在考虑监控问题。
最初我并不完全清楚如何监控这些网站,所以我想快速写下我是如何做到的。
我根本不打算谈如何监控大型严肃的关键任务网站,只谈微型的不重要的网站。
### 目标:在操作上几乎不花时间
我希望网站大部分时间都能正常工作,但我也希望在持续的运营上几乎不花时间。
我最初对运行服务器非常警惕,因为在我的上一份工作中,我是 24/7 轮流值班,负责一些关键的服务,在我的印象中,“负责服务器”意味着“在凌晨 2 点被叫起来修理服务器”和“有很多复杂的仪表盘”。
所以有一段时间我只做静态网站,这样我就不用考虑服务器的问题。
但最终我意识到,我所要写的任何服务器的风险都很低,如果它们偶尔宕机 2 小时也没什么大不了的,我只需设置一些非常简单的监控来帮助它们保持运行。
### 没有监控很糟糕
起初,我根本没有为我的服务器设置任何监控。这样做的结果是非常可预见的:有时网站坏了,而我却没有发现,直到有人告诉我!
### 步骤 1uptime 检查器
第一步是建立一个 uptime 检查器。外面有很多这样的东西,我现在使用的是 [updown.io][4] 和 [uptime robot][5]。我更喜欢 updown 的用户界面和[定价][6]结构它是按请求而不是按月收费但u ptime robot 有一个更慷慨的免费套餐。
它们会:
1. 检查网站是否正常
2. 如果出现故障,它会给我发电子邮件
我发现电子邮件通知对我来说是一个很好的级别,如果网站宕机,我会很快发现,但它不会唤醒我或任何东西。
### 步骤 2端到端的健康检查
接下来,让我们谈谈“检查网站是否正常”到底是什么意思。
起初,我只是把我的健康检查端点之一变成一个函数,无论如何都会返回 `200 OK`
这倒是挺有用的 它告诉我服务器是启动着的!
但不出所料,我遇到了问题,因为它没有检查 API 是否真的在_工作_ 有时健康检查成功了,尽管服务的其他部分实际上已经进入了一个糟糕的状态。
所以我更新了它,让它真正地发出 API 请求,并确保它成功了。
我所有的服务都只做了很少的事情nginx playground 只有一个端点),所以设置一个健康检查是非常容易的,它实际上贯穿了服务应该做的大部分动作。
下面是 nginx playground 的端到端健康检查处理程序的样子。它非常基本:它只是发出一个 POST 请求(给自己),并检查该请求是成功还是失败。
```
func healthHandler(w http.ResponseWriter, r *http.Request) {
// make a request to localhost:8080 with `healthcheckJSON` as the body
// if it works, return 200
// if it doesn't, return 500
client := http.Client{}
resp, err := client.Post("http://localhost:8080/", "application/json", strings.NewReader(healthcheckJSON))
if err != nil {
log.Println(err)
w.WriteHeader(http.StatusInternalServerError)
return
}
if resp.StatusCode != http.StatusOK {
log.Println(resp.StatusCode)
w.WriteHeader(http.StatusInternalServerError)
return
}
w.WriteHeader(http.StatusOK)
}
```
### 健康检查频率:每小时一次
现在,我大部分健康检查每小时运行一次,有些每 30 分钟运行一次。
我每小时运行一次,因为 updown.io 的定价是按健康检查次数计算的,我正在监控 18 个不同的 URL而且我想把我的健康检查预算保持在 5 美元/年的最低水平。
花一个小时来发现这些网站中的一个出现故障,对我来说是可以的 如果有问题,我也不能保证能很快修复它。
如果可以更频繁地运行它们,我可能会每 5-10 分钟运行一次。
### 步骤 3第三步如果健康检查失败自动重新启动
我的一些网站在 fly.io 上fly 有一个相当标准的功能,我可以为一个服务配置一个 HTTP 健康检查,如果健康检查失败,就重新启动服务。
“经常重启”是一个非常有用的策略来弥补我尚未修复的 bug有一段时间nginx playground 有一个进程泄漏,`nginx` 进程没有被终止,所以服务器的内存一直在耗尽。
通过健康检查,其结果是,每隔一天左右就会发生这样的情况:
* 服务器的内存用完了
* 健康检查开始失败
* 它被重新启动
* 一切又正常了
* 几个小时后再次重复整个传奇
最终,我开始实际修复进程泄漏,但很高兴有一个解决方法可以在我拖延修复 bug 时保持运行。
这些用于决定是否重新启动服务的运行状况检查更频繁地运行:每 5 分钟左右。
### 这不是监控大型服务的最佳方式
这可能很明显,我在一开始就已经说过了,但是“编写一个 HTTP 健康检查”并不是监控大型复杂服务的最佳方法。 但我不会深入讨论,因为这不是这篇文章的主题。
### 到目前为止一直运行良好!
我最初在 3 个月前的四月写了这篇文章,但我一直等到现在才发布它以确保整个设置正常工作。
这带来了很大的不同 在我遇到一些非常愚蠢的停机问题之前,现在在过去的几个月里,网站的运行时间达到了 99.95%
--------------------------------------------------------------------------------
via: https://jvns.ca/blog/2022/07/09/monitoring-small-web-services/
作者:[Julia Evans][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://jvns.ca/
[b]: https://github.com/lujun9972
[1]: https://nginx-playground.wizardzines.com
[2]: https://messwithdns.net
[3]: https://dns-lookup.jvns.ca
[4]: https://updown.io/
[5]: https://uptimerobot.com/
[6]: https://updown.io/#pricing