Merge remote-tracking branch 'LCTT/master'

This commit is contained in:
Xingyu Wang 2020-12-15 10:24:38 +08:00
commit 5858dbeb1c
14 changed files with 1588 additions and 462 deletions

View File

@ -1,39 +1,41 @@
[#]: collector: (lujun9972)
[#]: translator: (Mjseven)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: reviewer: (wxy)
[#]: publisher: (wxy)
[#]: url: (https://linux.cn/article-12920-1.html)
[#]: subject: (How to Save the Output of a Command to a File in Linux Terminal [Beginners Tip])
[#]: via: (https://itsfoss.com/save-command-output-to-file-linux/)
[#]: author: (Abhishek Prakash https://itsfoss.com/author/abhishek/)
如何将 Linux 终端中命令的输出保存到文件中[新手技巧]
如何将 Linux 终端中命令的输出保存到文件中
======
![](https://img.linux.net.cn/data/attachment/album/202012/14/223956pidmznldldnnk87f.jpg)
当你在 Linux 终端中运行命令或脚本时,它会在终端中打印输出方便你立即查看。
有时你需要将输出保存到文件中以备将来参考。现在,[当然可以在 Linux 终端中复制和粘贴][1],但是有更好的方法可以在 Linux 命令行中保存 shell 脚本或命令的输出,让我演示给你看。
有时你需要将输出保存到文件中以备将来参考。[当然可以在 Linux 终端中复制和粘贴][1],但是有更好的方法可以在 Linux 命令行中保存 shell 脚本或命令的输出,让我演示给你看。
### 方法 1使用重定向将命令输出保存到文件中
你可以[在 Linux 中使用重定向来达成目的][2]。使用重定向操作符,它会将输出保存到文件中而不是在屏幕上显示。
* > 会将命令输出重定向到文件,它会替换文件中的所有内容。
* >> 会将命令输出添加到文件现有内容的末尾。
* `>` 会将命令输出重定向到文件,它会替换文件中的所有内容。
* `>>` 会将命令输出添加到文件现有内容的末尾。
使用 STDOUT 重定向运算符 > 将输出重定向到文件:
使用标准输出重定向运算符 `>` 将输出重定向到文件:
```
command > file.txt
```
如果 file.txt 不存在,它会自动创建。如果你使用 > 再次重定向到相同的文件,文件内容将被替换为新的输出。
如果 `file.txt` 不存在,它会自动创建。如果你使用 `>` 再次重定向到相同的文件,文件内容将被替换为新的输出。
下面的示例将更好地演示它。它首先会保存 _ls -l_ 命令的输出,然后,它将用 _ls *.c_ 命令的输出替换文件的内容。
下面的示例将更好地演示它。它首先会保存 `ls -l` 命令的输出,然后,它将用 `ls *.c` 命令的输出替换文件的内容。
![将命令输出重定向到文件][3]
如果你不想在保存脚本或命令的输出时丢失现有文件的内容,可以使用 >>
如果你不想在保存脚本或命令的输出时丢失现有文件的内容,可以使用 `>>`
```
command >> file.txt
@ -47,17 +49,19 @@ command >> file.txt
温馨提示:将 Linux 命令输出和错误保存到一个文件中。
如果Linux 命令返回错误,那么错误不会保存在文件中。你可以使用 2>&1 将命令的输出和错误保存到同一个文件中,如下所示:
如果 Linux 命令返回错误,那么错误不会保存在文件中。你可以使用 `2>&1` 将命令的输出和错误保存到同一个文件中,如下所示:
**command > file.txt 2>&1**
```
command > file.txt 2>&1
```
通常0 代表标准输入1 代表标准输出2 代表标准错误。在这里,你要将标准错误(2) 重定向(&)到与标准输出(1) 相同的地址。
通常,`0` 代表标准输入,`1` 代表标准输出,`2` 代表标准错误。在这里,你要将标准错误`2` 重定向(`&`)到与标准输出(`1`相同的地址。
### 方法 2使用 tee 命令显示输出并将其保存到文件中
顺便说一句,你是否注意到,当你将命令输出发送到一个文件时,你再也无法在终端上看到它了?[Linux 的 tee 命令][5]解决了这个问题。
类似于将水流发送到两个方向的三通管tee 命令将输出发送到终端以及文件(或作为另一个命令的输入)。你可以像这样使用它:
类似于将水流发送到两个方向的三通管,`tee` 命令将输出发送到终端以及文件(或作为另一个命令的输入)。你可以像这样使用它:
```
command | tee file.txt
@ -65,7 +69,7 @@ command | tee file.txt
同样,如果该文件不存在,它将自动创建。
你还可以使用 tee 命令在附加模式下使用选项 -a
你还可以使用 `tee` 命令 `-a` 选项进入附加模式
```
command | tee -a file.txt
@ -79,7 +83,7 @@ command | tee -a file.txt
### 注意:将命令输出保存到文件时,避免管道陷阱
你可能对管道重定向很熟悉,可以使用它来组合 Linux 命令,但不能将输出通过管道传输到文件,它显示找不到 output.txt 命令:
你可能对管道重定向很熟悉,可以使用它来组合 Linux 命令,但不能将输出通过管道传输到文件,它显示找不到 `output.txt` 命令:
![][7]
@ -96,7 +100,7 @@ via: https://itsfoss.com/save-command-output-to-file-linux/
作者:[Abhishek Prakash][a]
选题:[lujun9972][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

@ -0,0 +1,103 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (Ben Cotton: How Do You Fedora?)
[#]: via: (https://fedoramagazine.org/ben-cotton-how-do-you-fedora/)
[#]: author: (gchang https://fedoramagazine.org/author/gchang/)
Ben Cotton: How Do You Fedora?
======
![][1]
We recently interviewed Ben Cotton on how he uses Fedora. This is part of a [series][2] on the Fedora Magazine. The series profiles Fedora users and how they use Fedora to get things done. Contact us on the [feedback form][3] to express your interest in becoming an interviewee.
### **Who is Ben Cotton?**
If you follow the Fedora Community Blog, theres a good chance you already know who Ben is. 
Bens Linux journey started around late 2002. Frustrated with some issues on using Windows XP, and starting a new application administrator role at his university where some services were being run on FreeBSD. A friend introduced him to Red Hat Linux, when Ben decided it made sense to get more practice with Unix-like operating systems. He switched to Fedora full-time in 2006, after he landed a job as a Linux system administrator.
Since then, his career has included system administration, people management, support engineering, development, and marketing. Several years ago, he even earned a Masters degree in IT Project Management. The variety of experience has helped Ben learn how to work with different groups of people. “A lot of what Ive learned has come from making mistakes. When you mess up communication, you hopefully do a better job the next time.”
Besides tech, Ben also has a range of well-rounded interests. “I used to do a lot of short fiction writing, but these days I mostly write my opinions about whatever is on my mind.” As for favorite foods, he claims “All of it. Feed me.”
Additionally, Ben has taste that spans genres. His childhood hero was a character from the science fiction series “Star Trek: The Next Generation”. “As a young lad, I wanted very much to be Wesley Crusher.” His favorite movies are a parody film and a spy thriller: “Airplane! and The Hunt for Red October” respectively. 
When asked for the five greatest qualities he thinks someone can possess, Ben responded cleverly: “Kindness. Empathy. Curiosity. Resilience. Red hair.”
![][4]
Ben wearing the official “#action bcotton” shirt
### **His Fedora Story**
As a talented writer who described himself as “not much of a programmer”, he selected the [Fedora Docs][5] team in 2009 as an entry point into the community. What he found was that “the Friends foundation was evident.” At the time, he wasnt familiar with tools such as Git, DocBook XML, or Publican (docs toolchain at the time). The community of experienced doc writers helped him get on his feet and freely gave their time. To this day, Ben considers many of them to be his friends and feels really lucky to work with them. Notably “jjmcd, stickster, sparks, and jsmith were a big part of the warm welcome I received.”
Today, as a senior program manager, he describes his job as “Chief Cat Herding Officer”- as his job is largely composed of seeing what different parts of the project are doing and making sure theyre all heading in the same general direction. 
Despite having a huge responsibility, Ben also helps a lot in his free time with tasks outside of his job duties, like website work, CommBlog and Magazine editing, packaging, etc… none of which are his core job responsibilities. He tries to find ways to contribute that match his skills and interests. Building credibility, paying attention, developing relationships with other contributors, and showing folks that hes able to help, is much more important to him than what his “official” title is. 
When thinking towards the future, Ben feels hopeful watching the Change proposals come in. “Sometimes they get rejected, but thats to be expected when youre trying to advance the state of the art. Fedora contributors are working hard to push the project forward.“
### **The Fedora Community **
As a longtime member of the community, Ben has various notions about the Fedora Project that have been developed over the years. For starters, he wants to make it easier to bring new contributors on board. He believes the Join SIG has “done tremendous work in this area”, but new contributors will keep the community vibrant. 
If Ben had to pick a best moment, hed choose Flock 2018 in Dresden. “That was my first Fedora event and it was great to meet so many of the people who Ive only known online for a decade.” 
As for bad moments, Ben hasnt had many. Once he accidentally messed up a Bugzilla query resulting in accidental closure of hundreds of bugs and has dealt with some frustrating mailing list threads, but remains positive, affirming that “frustration is okay.”
To those interested in becoming involved in the Fedora Project, Ben says “Come join us!” Theres something to appeal to almost anyone. “Take the time to develop relationships with the people you meet as you join, because without the Friends foundation, the rest falls apart.”
![][6]
![][7]
### **Pet Peeves**
One issue he finds challenging is a lack of documentation. “Ive learned enough over the years that I can sort of bumble through making code changes to things, but a lot of times its not clear how the code ties together.” Ben sees how sparse or nonexistent documentation can be frustrating to newcomers who might not have the knowledge that is assumed.
Another concern Ben has is that the “interesting” parts of technology are changing. “Operating systems arent as important to end users as they used to be thanks to the rise of mobile computing and Software-as-a-Service. Will this cause our pool of potential new contributors to decrease?”
Likewise, Ben believes that its not always easy to get people to understand why they should care about open source software. “The reasons are often abstract and people dont see that theyre directly impacted, especially when the alternatives provide more immediate convenience.”
### **What Hardware?**
For work, Ben has a ThinkPad X1 Carbon running Fedora 33 KDE. His personal server/desktop is a machine he put together from parts that runs Fedora 33 KDE. He uses it as a file server, print server, Plex media server, and general-purpose desktop. If he has some spare time to get it started, Ben also has an extra laptop that he wants to start using to test Beta releases and “maybe end up running rawhide on it”.
### **What Software?**
Ben has been a KDE user for a decade. A lot of his work is done in a web browser (Firefox for work stuff, Chrome for personal). He does most of his scripting in Python these days, with some inherited scripts in Perl.
Notable applications that Ben uses include:
* Cherrytree for note-taking
* Element for IRC
* Inkscape and Kdenlive when he needs to edit videos.
* Vim on the command line and Kate when he wants a GUI
--------------------------------------------------------------------------------
via: https://fedoramagazine.org/ben-cotton-how-do-you-fedora/
作者:[gchang][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/gchang/
[b]: https://github.com/lujun9972
[1]: https://fedoramagazine.org/wp-content/uploads/2020/11/LISA2015-printsize-7810-816x545.jpg
[2]: https://fedoramagazine.org/tag/how-do-you-fedora/
[3]: https://fedoramagazine.org/submit-an-idea-or-tip/
[4]: https://fedoramagazine.org/wp-content/uploads/2020/11/image1-2-edited.jpg
[5]: https://docs.fedoraproject.org/
[6]: https://i1.wp.com/fedoramagazine.org/wp-content/uploads/2020/11/image2-2.jpg?ssl=1&resize=1500%2C1500
[7]: https://i1.wp.com/fedoramagazine.org/wp-content/uploads/2020/11/image6-1.jpg?ssl=1&resize=1500%2C1500

View File

@ -0,0 +1,73 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (What web developers love about the Brackets text editor)
[#]: via: (https://opensource.com/article/20/12/brackets)
[#]: author: (Seth Kenlon https://opensource.com/users/seth)
What web developers love about the Brackets text editor
======
This basic editor is geared toward web developers, supporting multiple
programming languages and offering plenty of extensions to make it your
own.
![Text editor on a browser, in blue][1]
The Brackets text editor is an editor geared primarily at web developers. Appropriately, its Edit menu is full of functions especially useful to users of web programming languages, with a focus on the classic combination of HTML, CSS, and Javascript.
However, it supports many languages and formats relevant to the internet, including XML, Markdown, YAML and JSON, PHP, Lua, Java, and Python, as well as some common general languages like C, C++, and even the output of `diff` commands.
### Installing Brackets
Brackets can be installed on Linux, Windows, and macOS from the [Brackets website][2].
Alternatively, on Linux, you can install it as a Flatpak from [flathub.org][3].
![Brackets editor][4]
### Using Brackets
For the most part, Brackets is a "normal" text editor, with features similar to jEdit or Medit. Theres syntax highlighting, configurable tab spacing, character encoding settings, and so on. These are available in the status bar at the bottom of the window.
From the View menu, there are theme settings, line numbering, word wrapping, and even options to split the window so you can see two files in one window.
In the Edit menu, however, there are some special functions for programming. Here are some of my favorites:
* Indent and unindent blocks of text using the **Ctrl+[** or **Ctrl+]** keyboard shortcuts, which are useful not only for keeping HTML, CSS, and Javascript tidy but essential for Python code.
* Make a line into a comment with **Ctrl+/**. The way Brackets marks a comment depends on the language youre using, so this function works whether your document uses slashes, dashes, arrows, hashes, or anything else for commenting.
* Move a line up or down in your document with **Shift+Ctrl+Up** or **Shift+Ctrl+Down**.
* Delete an entire line with **Shift+Ctrl+D**.
* Duplicate a line with **Ctrl+D**.
These are all seemingly niche functions you might not think youll use often, but once you have them, you come to rely on them.
### Extensions
Brackets can also accept extensions so you and other coders can add to its features. To see what extensions are available, click the File menu and select Extension Manager. Theres a wide variety of extensions available, including Beautify to adjust code formatting, multiple support kits for additional languages, a function to go to the beginning or end of a tag, and much more.
Extensions can make all the difference to an editor and whether its right for you, so if you try Brackets and enjoy everything about it, but youre missing some vital feature, have a browse through the available extensions before you give up on it.
### Try Brackets
Brackets is a somewhat subdued editor. While it advertises itself as a "code editor for the web," its actually a nice general-purpose editor with some extra features thrown in for common web toolchains. If you like the look of Brackets and what it has to offer, give it a try!
--------------------------------------------------------------------------------
via: https://opensource.com/article/20/12/brackets
作者:[Seth Kenlon][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/seth
[b]: https://github.com/lujun9972
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/browser_blue_text_editor_web.png?itok=lcf-m6N7 (Text editor on a browser, in blue)
[2]: http://brackets.io/
[3]: https://flathub.org/apps/details/io.brackets.Brackets
[4]: https://opensource.com/sites/default/files/screenshot_2020-12-02_at_16.26.58.png (Brackets editor)

View File

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

View File

@ -1,170 +0,0 @@
[#]: collector: (lujun9972)
[#]: translator: (zhangxiangping)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (How I use Python to map the global spread of COVID-19)
[#]: via: (https://opensource.com/article/20/4/python-map-covid-19)
[#]: author: (AnuragGupta https://opensource.com/users/999anuraggupta)
How I use Python to map the global spread of COVID-19
======
Create a color coded geographic map of the potential spread of the virus
using these open source scripts.
![Globe up in the clouds][1]
The spread of disease is a real concern for a world in which global travel is commonplace. A few organizations track significant epidemics (and any pandemic), and fortunately, they publish their work as open data. The raw data can be difficult for humans to process, though, and that's why data science is so vital. For instance, it could be useful to visualize the worldwide spread of COVID-19 with Python and Pandas.
It can be hard to know where to start when you're faced with large amounts of raw data. The more you do it, however, the more patterns begin to emerge. Here's a common scenario, applied to COVID-19 data:
1. Download COVID-19 country spread daily data into a Pandas DataFrame object from GitHub. For this, you need the Python Pandas library.
2. Process and clean the downloaded data and make it suitable for visualizing. The downloaded data (as you will see for yourself) is in quite good condition. The one problem with this data is that it uses the names of countries, but it's better to use three-digit ISO 3 codes. To generate the three-digit ISO 3 codes, use a small Python library called pycountry. Having generated these codes, you can add an extra column to our DataFrame and populate it with these codes.
3. Finally, for the visualization, use the **express** module of a library called Plotly. This article uses what are called choropleth maps (available in Plotly) to visualize the worldwide spread of the disease.
### Step 1: Corona data
We will download the latest corona data from:
<https://raw.githubusercontent.com/datasets/covid-19/master/data/countries-aggregated.csv>
We will load the data directly into a Pandas DataFrame. Pandas provides a function, **read_csv()**, which can take a URL and return a DataFrame object as shown below:
```
import pycountry
import plotly.express as px
import pandas as pd
URL_DATASET = r'<https://raw.githubusercontent.com/datasets/covid-19/master/data/countries-aggregated.csv>'
df1 = pd.read_csv(URL_DATASET)
print(df1.head(3))  # Get first 3 entries in the dataframe
print(df1.tail(3))  # Get last 3 entries in the dataframe
```
The screenshot of output (on Jupyter) is:
![Jupyter screenshot][2]
From output, you can see that the DataFrame (df1) has the following columns:
1. Date
2. Country
3. Confirmed
4. Recovered
5. Dead
Further, you can see that the **Date** column has entries starting from January 22 to March 31. This database is updated daily, so you will get the current values.
### Step 2: Cleaning and modifying the data frame
We need to add another column to this DataFrame, which has the three-letter ISO alpha-3 codes. To do this, I followed these steps:
1. Create a list of all countries in the database. This was required because in the **df**, in the column **Country**, each country was figuring for each date. So in effect, the **Country** column had multiple entries for each country. To do this, I used the **unique().tolist()** functions.
2. Then I took a dictionary **d_country_code** (initially empty) and populated it with keys consisting of country names and values consisting of their three-letter ISO codes.
3. To generate the three-letter ISO code for a country, I used the function **pycountry.countries.search_fuzzy(country)**. You need to understand that the return value of this function is a "list of **Country** objects." I passed the return value of this function to a name country_data. Further, in this list of objects, the first object i.e., at index 0, is the best fit. Further, this **\** object has an attribute **alpha_3**. So, I can "access" the 3 letter ISO code by using **country_data[0].alpha_3**. However, it is possible that some country names in the DataFrame may not have a corresponding ISO code (For example, disputed territories). So, for such countries, I gave an ISO code of "i.e. a blank string. Further, you need to wrap this code in a try-except block. The statement: **print(_could not add ISO 3 code for -&gt;'_, country)** will give a printout of those countries for which the ISO 3 codes could not be found. In fact, you will find such countries as shown with white color in the final output.
4. Having got the three-letter ISO code for each country (or an empty string for some), I added the country name (as key) and its corresponding ISO code (as value) to the dictionary **d_country_code**. For adding these, I used the **update()** method of the Python dictionary object.
5. Having created a dictionary of country names and their codes, I added them to the DataFrame using a simple for loop.
### Step 3: Visualizing the spread using Plotly
A choropleth map is a map composed of colored polygons. It is used to represent spatial variations of a quantity. We will use the express module of Plotly conventionally called **px**. Here we show you how to create a choropleth map using the function: **px.choropleth**.
The signature of this function is:
```
`plotly.express.choropleth(data_frame=None, lat=None, lon=None, locations=None, locationmode=None, geojson=None, featureidkey=None, color=None, hover_name=None, hover_data=None, custom_data=None, animation_frame=None, animation_group=None, category_orders={}, labels={}, color_discrete_sequence=None, color_discrete_map={}, color_continuous_scale=None, range_color=None, color_continuous_midpoint=None, projection=None, scope=None, center=None, title=None, template=None, width=None, height=None)`
```
The noteworthy points are that the **choropleth()** function needs the following things:
1. A geometry in the form of a **geojson** object. This is where things are a bit confusing and not clearly mentioned in its documentation. You may or may not provide a **geojson** object. If you provide a **geojson** object, then that object will be used to plot the earth features, but if you don't provide a **geojson** object, then the function will, by default, use one of the built-in geometries. (In our example here, we will use a built-in geometry, so we won't provide any value for the **geojson** argument)
2. A pandas DataFrame object for the attribute **data_frame**. Here we provide our DataFrame ie **df1** we created earlier.
3. We will use the data of **Confirmed** column to decide the color of each country polygon.
4. Further, we will use the **Date** column to create the **animation_frame**. Thus as we slide across the dates, the colors of the countries will change as per the values in the **Confirmed** column.
The complete code is given below:
```
import pycountry
import plotly.express as px
import pandas as pd
# ----------- Step 1 ------------
URL_DATASET = r'<https://raw.githubusercontent.com/datasets/covid-19/master/data/countries-aggregated.csv>'
df1 = pd.read_csv(URL_DATASET)
# print(df1.head) # Uncomment to see what the dataframe is like
# ----------- Step 2 ------------
list_countries = df1['Country'].unique().tolist()
# print(list_countries) # Uncomment to see list of countries
d_country_code = {}  # To hold the country names and their ISO
for country in list_countries:
    try:
        country_data = pycountry.countries.search_fuzzy(country)
        # country_data is a list of objects of class pycountry.db.Country
        # The first item  ie at index 0 of list is best fit
        # object of class Country have an alpha_3 attribute
        country_code = country_data[0].alpha_3
        d_country_code.update({country: country_code})
    except:
        print('could not add ISO 3 code for -&gt;', country)
        # If could not find country, make ISO code ' '
        d_country_code.update({country: ' '})
# print(d_country_code) # Uncomment to check dictionary  
# create a new column iso_alpha in the df
# and fill it with appropriate iso 3 code
for k, v in d_country_code.items():
    df1.loc[(df1.Country == k), 'iso_alpha'] = v
# print(df1.head)  # Uncomment to confirm that ISO codes added
# ----------- Step 3 ------------
fig = px.choropleth(data_frame = df1,
                    locations= "iso_alpha",
                    color= "Confirmed",  # value in column 'Confirmed' determines color
                    hover_name= "Country",
                    color_continuous_scale= 'RdYlGn',  #  color scale red, yellow green
                    animation_frame= "Date")
fig.show()
```
The output is something like the following:
![Map][3]
You can download and run the [complete code][4].
To wrap up, here are some excellent resources on choropleth in Plotly:
* <https://github.com/plotly/plotly.py/blob/master/doc/python/choropleth-maps.md>
* [https://plotly.com/python/reference/#choropleth][5]
--------------------------------------------------------------------------------
via: https://opensource.com/article/20/4/python-map-covid-19
作者:[AnuragGupta][a]
选题:[lujun9972][b]
译者:[zhangxiangping](https://github.com/zxp93)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/999anuraggupta
[b]: https://github.com/lujun9972
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/cloud-globe.png?itok=_drXt4Tn (Globe up in the clouds)
[2]: https://opensource.com/sites/default/files/uploads/jupyter_screenshot.png (Jupyter screenshot)
[3]: https://opensource.com/sites/default/files/uploads/map_2.png (Map)
[4]: https://github.com/ag999git/jupyter_notebooks/blob/master/corona_spread_visualization
[5]: tmp.azs72dmHFd#choropleth

View File

@ -1,272 +0,0 @@
[#]: collector: (lujun9972)
[#]: translator: (geekpi)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (Add storage to your Fedora system with LVM)
[#]: via: (https://fedoramagazine.org/add-storage-to-your-fedora-system-with-lvm/)
[#]: author: (Tim Bosse https://fedoramagazine.org/author/maztaim/)
Add storage to your Fedora system with LVM
======
![][1]
Sometimes there is a need to add another disk to your system. This is where Logical Volume Management (LVM) comes in handy. The cool thing about LVM is that its fairly flexible. There are several ways to add a disk. This article describes one way to do it.
### Heads up!
This article does not cover the process of physically installing a new disk drive into your system. Consult your system and disk documentation on how to do that properly.
**Important:** Always make sure you have backups of important data. The steps described in this article will destroy data if it already exists on the new disk.
### Good to know
This article doesnt cover every LVM feature deeply; the focus is on adding a disk. But basically, LVM has _volume groups_, made up of one or more partitions and/or disks. You add the partitions or disks as _physical volumes_. A volume group can be broken down into many _logical volumes_. Logical volumes can be used as any other storage for filesystems, ramdisks, etc. More information can be found [here][2].
Think of the _physical volumes_ as forming a pool of storage (a _volume group_) from which you then carve out _logical volumes_ for your system to use directly.
### Preparation
Make sure you can see the disk you want to add. Use _lsblk_ prior to adding the disk to see what storage is already available or in use.
```
$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
zram0 251:0 0 989M 0 disk [SWAP]
vda 252:0 0 20G 0 disk
├─vda1 252:1 0 1G 0 part /boot
└─vda2 252:2 0 19G 0 part
└─fedora_fedora-root 253:0 0 19G 0 lvm /
```
This article uses a virtual machine with virtual storage. Therefore the device names start with _vda_ for the first disk, _vdb_ for the second, and so on. The name of your device may be different. Many systems will see physical disks as _sda_ for the first disk, _sdb_ for the second, and so on.
Once the new disk has been connected and your system is back up and running, use _lsblk_ again to see the new block device.
```
$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
zram0 251:0 0 989M 0 disk [SWAP]
vda 252:0 0 20G 0 disk
├─vda1 252:1 0 1G 0 part /boot
└─vda2 252:2 0 19G 0 part
└─fedora_fedora-root 253:0 0 19G 0 lvm /
vdb 252:16 0 10G 0 disk
```
There is now a new device named _vdb_. The location for the device is _/dev/vdb_.
```
$ ls -l /dev/vdb
brw-rw----. 1 root disk 252, 16 Nov 24 12:56 /dev/vdb
```
We can see the disk, but we cannot use it with LVM yet. If you run _blkid_ you should not see it listed. For this and following commands, youll need to ensure your system is [configured so you can use _sudo_][3]:
```
$ sudo blkid
/dev/vda1: UUID="4847cb4d-6666-47e3-9e3b-12d83b2d2448" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="830679b8-01"
/dev/vda2: UUID="k5eWpP-6MXw-foh5-Vbgg-JMZ1-VEf9-ARaGNd" TYPE="LVM2_member" PARTUUID="830679b8-02"
/dev/mapper/fedora_fedora-root: UUID="f8ab802f-8c5f-4766-af33-90e78573f3cc" BLOCK_SIZE="4096" TYPE="ext4"
/dev/zram0: UUID="fc6d7a48-2bd5-4066-9bcf-f062b61f6a60" TYPE="swap"
```
### Add the disk to LVM
Initialize the disk using _pvcreate_. You need to pass the full path to the device. In this example it is _/dev/vdb_; on your system it may be _/dev/sdb_ or another device name.
```
$ sudo pvcreate /dev/vdb
Physical volume "/dev/vdb" successfully created.
```
You should see the disk has been initialized as an LVM2_member when you run _blkid_:
```
$ sudo blkid
/dev/vda1: UUID="4847cb4d-6666-47e3-9e3b-12d83b2d2448" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="830679b8-01"
/dev/vda2: UUID="k5eWpP-6MXw-foh5-Vbgg-JMZ1-VEf9-ARaGNd" TYPE="LVM2_member" PARTUUID="830679b8-02"
/dev/mapper/fedora_fedora-root: UUID="f8ab802f-8c5f-4766-af33-90e78573f3cc" BLOCK_SIZE="4096" TYPE="ext4"
/dev/zram0: UUID="fc6d7a48-2bd5-4066-9bcf-f062b61f6a60" TYPE="swap"
/dev/vdb: UUID="4uUUuI-lMQY-WyS5-lo0W-lqjW-Qvqw-RqeroE" TYPE="LVM2_member"
```
You can list all physical volumes currently available using _pvs_:
```
$ sudo pvs
PV VG Fmt Attr PSize PFree
/dev/vda2 fedora_fedora lvm2 a-- <19.00g 0
/dev/vdb lvm2 --- 10.00g 10.00g
```
_/dev/vdb_ is listed as a PV (phsyical volume), but it isnt assigned to a VG (Volume Group) yet.
### Add the pysical volume to a volume group
You can find a list of available volume groups using _vgs_:
```
$ sudo vgs
VG #PV #LV #SN Attr VSize VFree
fedora_fedora 1 1 0 wz--n- 19.00g 0
```
In this example, there is only one volume group available. Next, add the physical volume to _fedora_fedora_:
```
$ sudo vgextend fedora_fedora /dev/vdb
Volume group "fedora_fedora" successfully extended
```
You should now see the physical volume is added to the volume group:
```
$ sudo pvs
PV VG Fmt Attr PSize PFree
/dev/vda2 fedora_fedora lvm2 a <19.00g 0
/dev/vdb fedora_fedora lvm2 a <10.00g <10.00g
```
Look at the volume groups:
```
$ sudo vgs
VG #PV #LV #SN Attr VSize VFree
fedora_fedora 2 1 0 wzn- 28.99g <10.00g
```
You can get a detailed list of the specific volume group and physical volumes as well:
```
$ sudo vgdisplay fedora_fedora
--- Volume group ---
VG Name fedora_fedora
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 3
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 1
Max PV 0
Cur PV 2
Act PV 2
VG Size 28.99 GiB
PE Size 4.00 MiB
Total PE 7422
Alloc PE / Size 4863 / 19.00 GiB
Free PE / Size 2559 / 10.00 GiB
VG UUID C5dL2s-dirA-SQ15-TfQU-T3yt-l83E-oI6pkp
```
Look at the PV:
```
$ sudo pvdisplay /dev/vdb
--- Physical volume ---
PV Name /dev/vdb
VG Name fedora_fedora
PV Size 10.00 GiB / not usable 4.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 2559
Free PE 2559
Allocated PE 0
PV UUID 4uUUuI-lMQY-WyS5-lo0W-lqjW-Qvqw-RqeroE
```
Now that we have added the disk, we can allocate space to logical volumes (LVs):
```
$ sudo lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
root fedora_fedora -wi-ao---- 19.00g
```
Look at the logical volumes. Heres a detailed look at the root LV:
```
$ sudo lvdisplay fedora_fedora/root
--- Logical volume ---
LV Path /dev/fedora_fedora/root
LV Name root
VG Name fedora_fedora
LV UUID yqc9cw-AvOw-G1Ni-bCT3-3HAa-qnw3-qUSHGM
LV Write Access read/write
LV Creation host, time fedora, 2020-11-24 11:44:36 -0500
LV Status available
LV Size 19.00 GiB
Current LE 4863
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
```
Look at the size of the root filesystem and compare it to the logical volume size.
```
$ df -h /
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/fedora_fedora-root 19G 1.4G 17G 8% /
```
The logical volume and the filesystem both agree the size is 19G. Lets add 5G to the root logical volume:
```
$ sudo lvresize -L +5G fedora_fedora/root
Size of logical volume fedora_fedora/root changed from 19.00 GiB (4863 extents) to 24.00 GiB (6143 extents).
Logical volume fedora_fedora/root successfully resized.
```
We now have 24G available to the logical volume. Look at the _/_ filesystem.
```
$ df -h /
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/fedora_fedora-root 19G 1.4G 17G 8% /
```
We are still showing only 19G free. This is because the logical volume is not the same as the filesytem. To use the new space added to the logical volume, resize the filesystem.
```
$ sudo resize2fs /dev/fedora_fedora/root
resize2fs 1.45.6 (20-Mar-2020)
Filesystem at /dev/fedora_fedora/root is mounted on /; on-line resizing required
old_desc_blocks = 3, new_desc_blocks = 3
The filesystem on /dev/fedora_fedora/root is now 6290432 (4k) blocks long.
```
Look at the size of the filesystem.
```
$ df -h /
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/fedora_fedora-root 24G 1.4G 21G 7% /
```
As you can see, the root file system _(/)_ has taken all of the space available on the logical volume and no reboot was needed.
You have now initialized a disk as a physical volume, and extended the volume group with the new physical volume. After that you increased the size of the logical volume, and resized the filesystem to use the new space from the logical volume.
--------------------------------------------------------------------------------
via: https://fedoramagazine.org/add-storage-to-your-fedora-system-with-lvm/
作者:[Tim Bosse][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/maztaim/
[b]: https://github.com/lujun9972
[1]: https://fedoramagazine.org/wp-content/uploads/2020/11/lvm-add-disk-816x345.jpg
[2]: https://en.wikipedia.org/wiki/Logical_Volume_Manager_(Linux)
[3]: https://fedoramagazine.org/howto-use-sudo/

View File

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

View File

@ -0,0 +1,246 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (Practice coding in Java by writing a game)
[#]: via: (https://opensource.com/article/20/12/learn-java)
[#]: author: (Seth Kenlon https://opensource.com/users/seth)
Practice coding in Java by writing a game
======
Writing simple games is a fun way to learn a new programming language.
Put that principle to work to get started with Java.
![Learning and studying technology is the key to success][1]
My article about [learning different programming languages][2] lists five things you need to understand when starting a new language. An important part of learning a language, of course, is knowing what you intend to do with it.
I've found that simple games are both fun to write and useful in exploring a language's abilities. In this article, I demonstrate how to create a simple guessing game in Java.
### Install Java
To do this exercise, you must have Java installed. If you don't have it, check out these links to install Java on [Linux][3], [macOS, or Windows][4].
After installing it, run this Java command in a terminal to confirm the version you installed:
```
`$ java -version`
```
### Guess the number
This "guess the number" program exercises several concepts in programming languages: how to assign values to variables, how to write statements, and how to perform conditional evaluation and loops. It's a great practical experiment for learning a new programming language.
Here's my Java implementation:
```
package com.example.guess;
import java.util.Random;
import java.util.Scanner;
   
class Main {
    private static final [Random][5] r = new [Random][5]();
    private static final int NUMBER = r.nextInt(100) + 1;
    private static int guess = 0;
    public static void main([String][6][] args) {  
        Scanner player = new Scanner([System][7].in);
            [System][7].out.println("number is " + [String][6].valueOf(NUMBER)); //DEBUG
            while ( guess != NUMBER ) {
            // prompt player for guess
            [System][7].out.println("Guess a number between 1 and 100");
            guess = player.nextInt();
            if ( guess &gt; NUMBER ) {
                [System][7].out.println("Too high");
            } else if ( guess &lt; NUMBER ) {
                [System][7].out.println("Too low");
            } else {
                [System][7].out.println("That's right!");
                [System][7].exit(0);
            }
        }
  }
}
```
That's about 20 lines of code, excluding whitespace and trailing braces. Structurally, however, there's a lot going on, which I'll break down here.
#### Package declaration
The first line, `package com.example.guess`, is not strictly necessary in a simple one-file application like this, but it's a good habit to get into. Java is a big language, and new Java is written every day, so every Java project needs to have a unique identifier to help programmers tell one library from another.
When writing Java code, you should declare a `package` it belongs to. The format for this is usually a reverse domain name, such as `com.opensource.guess` or `org.slf4j.Logger`. As usual for Java, this line is terminated by a semicolon.
#### Import statements
The next lines of the code are import statements, which tell the Java compiler what libraries to load when building the executable application. The libraries I use here are distributed along with OpenJDK, so you don't need to download them yourself. Because they're not strictly a part of the core language, you do need to list them for the compiler.
The Random library provides access to pseudo-random number generation, and the Scanner library lets you read user input in a terminal.
#### Java class
The next part creates a Java class. Java is an object-oriented programming language, so its quintessential construct is a _class_. There are some very specific code ideas suggested by a class, and if you're new to programming, you'll pick up on them with practice. For now, think of a class as a box into which you place variables and code instructions, almost as if you were building a machine. The parts you place into the class are unique to that class, and because they're contained in a box, they can't be seen by other classes. More importantly, since there is only one class in this sample game, a class is self-sufficient: It contains everything it needs to perform its particular task. In this case, its task is the whole game, but in larger applications, classes often work together in a sort of daisy-chain to produce complex jobs.
In Java, each file generally contains one class. The class in this file is called `Main` to signify that it's the entry-point for this application. In a single-file application such as this, the significance of a main class is difficult to appreciate, but in a larger Java project with dozens of classes and source files, marking one `Main` is helpful. And anyway, it's easy to package up an application for distribution with a main class defined.
#### Java fields
In Java, as in C and C++, you must declare variables before using them. You can define "fields" at the top of a Java class. The word "field" is just a fancy term for a variable, but it specifically refers to a variable assigned to a class rather than one embedded somewhere in a function.
This game creates three fields: Two to generate a pseudo-random number, and one to establish an initial (and always incorrect) guess. The long string of keywords (`private static final`) leading up to each field may look confusing (especially when starting out with Java), but using a good IDE like Netbeans or Eclipse can help you navigate the best choice.
It's important to understand them, too. A _private_ field is one that's available only to its own class. If another class tries to access a private field, the field may as well not exist. In a one-class application such as this one, it makes sense to use private fields.
A _static_ field belongs to the class itself and not to a class instance. This doesn't make much difference in a small demo app like this because only one instance of the class exists. In a larger application, you may have a reason to define or redefine a variable each time a class instance is spawned.
A _final_ field cannot have its value changed. This application demonstrates this perfectly: The random number never changes during the game (a moving target wouldn't be very fair), while the player's guess _must_ change or the game wouldn't be winnable. For that reason, the random number established at the beginning of the game is final, but the guess is not.
#### Pseudo-random numbers
Two fields create the random number that serves as the player's target. The first creates an instance of the `Random` class. This is essentially a random seed from which you can draw a pretty unpredictable number. To do this, list the class you're invoking followed by a variable name of your choice, which you set to a new instance of the class: `Random r = new Random();`. Like other Java statements, this terminates with a semicolon.
To draw a number, you must create another variable using the `nextInt()` method of Java. The syntax looks a little different, but it's similar: You list the kind of variable you're creating, you provide a name of your choice, and then you set it to the results of some action: `int NUMBER = r.nextInt(100) + 1;`. You can (and should) look at the documentation for specific methods, like `nextInt()`, to learn how they work, but in this case, the integer drawn from the `r` random seed is limited _up to_ 100 (that is, a maximum of 99). Adding 1 to the result ensures that a number is never 0 and the functional maximum is 100.
Obviously, the decision to disqualify any number outside of the 1 to 100 range is a purely arbitrary design decision, but it's important to know these constraints before sitting down to program. Without them, it's difficult to know what you're coding toward. If possible, work with a person whose job it is to define the application you're coding. If you have no one to work with, make sure to list your targets first—and only then put on your "coder hat."
### Main method
By default, Java looks for a `main` method (or "function," as they're called in many other languages) to run in a class. Not all classes need a main method, but this demo app only has one method, so it may as well be the main one. Methods, like fields, can be made public or private and static or non-static, but the main method must be public and static for the Java compiler to recognize and utilize it.
### Application logic
For this application to work as a game, it must continue to run _while_ the player takes guesses at a secret pseudo-random number. Were the application to stop after each guess, the player would only have one guess and would very rarely win. It's also part of the game's design that the computer provides hints to guide the player's next guess.
A `while` loop with embedded `if` statements achieves this design target. A `while` loop inherently continues to run until a specific condition is met. (In this case, the `guess` variable must equal the `NUMBER` variable.) Each guess can be compared to the target `NUMBER` to prompt helpful hints.
### Syntax
The main method starts by creating a new `Scanner` instance. This is the same principle as the `Random` instance used as a pseudo-random seed: You cite the class you want to use as a template, provide a variable name (I use `player` to represent the person entering guesses), and then set that variable to the results of running the class' main method. Again, if you were coding this on your own, you'd look at the class' documentation to get the syntax when using it.
This sample code includes a debugging statement that reveals the target `NUMBER`. That makes the game moot, but it's useful to prove to yourself that it's working correctly. Even this small debugging statement reveals some important Java tips: `System.out.println` is a print statement, and the `valueOf()` method converts the integer `NUMBER` to a string to print it as part of a sentence rather than an element of math.
The `while` statement begins next, with the sole condition that the player's `guess` is not equal to the target `NUMBER`. This is an infinite loop that can end only when it's _false_ that `guess` does _not_ equal `NUMBER`.
In this loop, the player is prompted for a number. The Scanner object, called `player`, takes any valid integer entered by the player and puts its value into the `guess` field.
The `if` statement compares `guess` to `NUMBER` and responds with `System.out.println` print statements to provide feedback to the human player.
If `guess` is neither greater than nor less than `NUMBER`, then it must be equal to it. At this point, the game prints a congratulatory message and exits. As usual with [POSIX][8] application design, this game exits with a 0 status to indicate success.
### Run the game
To test your game, save the sample code as `Guess.java` and use the Java command to run it:
```
$ java ./Guess.java
number is 38
Guess a number between 1 and 100
1
Too low
Guess a number between 1 and 100
39
Too high
Guess a number between 1 and 100
38
That's right!
$
```
Just as expected!
### Package the game
While it isn't as impressive on a single-file application like this as it is on a complex project, Java makes packaging very easy. For the best results, structure your project directory to include a place for your source code, a place for your compiled class, and a manifest file. In practice, this is somewhat flexible, and using an IDE does most of the work for you. It's useful to do it by hand once in a while, though.
Create a project folder if you haven't already. Then create one directory called `src` to hold your source files. Save the sample code in this article as `src/Guess.java`:
```
$ mkdir src
$ mv sample.java src/Guess.java
```
Now, create a directory tree that mirrors the name of your Java package, which appears at the very top of your code:
```
$ head -n1 src/Guess.java
package com.example.guess;
$ mkdir -p com/example/guess
```
Create a new file called `Manifest.txt` with just one line of text in it:
```
`$ echo "Manifest-Version: 1.0" > Manifest.txt`
```
Next, compile your game into a Java class. This produces a file called `Main.class` in `com/example/guess`:
```
$ javac src/Guess.java -d com/example/guess
$ ls com/example/guess/
Main.class
```
You're all set to package your application into a JAR (Java archive). The `jar` command is a lot like the [tar][9] command, so many of the options may look familiar:
```
$ jar cfme Guess.jar \
Manifest.txt \
com.example.guess.Main \
com/example/guess/Main.class
```
From the syntax of the command, you may surmise that it creates a new JAR file called `Guess.jar` with its required manifest data located in `Manifest.txt`. Its main class is defined as an extension of the package name, and the class is `com/example/guess/Main.class`.
You can view the contents of the JAR file:
```
$ jar tvf Guess.jar
     0 Wed Nov 25 10:33:10 NZDT 2020 META-INF/
    96 Wed Nov 25 10:33:10 NZDT 2020 META-INF/MANIFEST.MF
  1572 Wed Nov 25 09:42:08 NZDT 2020 com/example/guess/Main.class
```
And you can even extract it with the `xvf` options.
Run your JAR file with the `java` command:
```
`$ java -jar Guess.jar`
```
Copy your JAR file from Linux to a macOS or Windows computer and try running it. Without recompiling, it runs as expected. This may seem normal if your basis of comparison is, say, a simple Python script that happens to run anywhere, but imagine a complex project with several multimedia libraries and other dependencies. With Java, those dependencies are packaged along with your application, and it _all_ runs on _any_ platform. Welcome to the wonderful world of Java!
--------------------------------------------------------------------------------
via: https://opensource.com/article/20/12/learn-java
作者:[Seth Kenlon][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/seth
[b]: https://github.com/lujun9972
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/studying-books-java-couch-education.png?itok=C9gasCXr (Learning and studying technology is the key to success)
[2]: https://opensource.com/article/20/10/learn-any-programming-language
[3]: https://opensource.com/article/19/11/install-java-linux
[4]: http://adoptopenjdk.org
[5]: http://www.google.com/search?hl=en&q=allinurl%3Adocs.oracle.com+javase+docs+api+random
[6]: http://www.google.com/search?hl=en&q=allinurl%3Adocs.oracle.com+javase+docs+api+string
[7]: http://www.google.com/search?hl=en&q=allinurl%3Adocs.oracle.com+javase+docs+api+system
[8]: https://opensource.com/article/19/7/what-posix-richard-stallman-explains
[9]: https://opensource.com/article/17/7/how-unzip-targz-file

View File

@ -0,0 +1,318 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (Set up an Ansible lab in 20 minutes)
[#]: via: (https://opensource.com/article/20/12/ansible-lab)
[#]: author: (Mike Calizo https://opensource.com/users/mcalizo)
Set up an Ansible lab in 20 minutes
======
Build an environment to support learning and experimenting with new
software.
![Science lab with beakers][1]
Being able to build and tear down a public cloud environment is very useful, but most of us dont have easy access to a public cloud. The next best thing would be to have a lab on your local machine, but even running on a local machine brings performance, flexibility, and other challenges. Most of the time, the additional workloads on our local machines interfere with doing our daily job, and they certainly prevent having a readily available environment to play and experiment with new software.
My team and I encountered this challenge a few years ago when we were starting to learn [Ansible][2]. We couldnt find an environment that we could use individually, and our frustration with the situation caused some of us to stop experimenting. We knew we needed to find a solution.
We spent a lot of time researching the options and came up with a set of tools that enable our curiosity to learn in an environment we fully control. We can spin up and tear down the lab environment on our local machines without needing access to on-premises labs or public clouds.
This article will explain how to deploy your own lab environment on your local machine in as little as 20 minutes in a fully automated way.
You can find all the code for this exercise in my [GitHub repository][3].
### Tools and software
This solution uses the following tools and software:
* [Ansible][4] is our automation tool of choice because its easy to use and flexible enough to handle the lab requirements.
* [Vagrant][5] is easy to use for building and maintaining virtual machines.
* [VirtualBox][6] is a hosted hypervisor that works in Windows and Linux environments.
* [Fedora v30+][7] is the operating system on my local machine.
You must have the following set up to build the environment:
* An internet connection
* Virtualization Technology support enabled in your BIOS (here is the [procedure][8] for my Lenovo laptop)
* Vagrant v2.2.9
* The latest version of Ansible
* The latest version of VirtualBox
* Fedora v30+ host operating system
### Whats in the lab environment?
This project aims to deploy an Ansible host with an Ansible engine and multiple Linux nodes along with some pre-loaded and pre-configured applications (httpd and MySQL). It also enables [Cockpit][9] so that you can monitor the status of the virtual machines (VMs) during testing. The reason to use a pre-deployed application is for efficiency (so you dont have to spend time installing those components). This allows you to focus on creating roles and playbooks and testing against the environments deployed by the tools listed above.
We determined that the best scenario for our use case was a multi-machine Vagrant environment. The Vagrantfile creates three CentOS VMs to simulate two target hosts and an Ansible control machine:
* Host1: No graphical user interface (GUI), with httpd and MySQL installed
* Host2: No GUI, with httpd and MySQL installed
* Ansible-host: No GUI, with Ansible engine installed
### Enable multiple hypervisors
Some hypervisors may not allow you to bring up VMs if more than one hypervisor is in use. To fix this problem, follow these steps (based on Vagrants [installation][10] instructions).
First, find out the name of the hypervisor:
```
$ lsmod | grep kvm
kvm_intel             204800  6
kvm                   593920  1 kvm_intel
irqbypass              16384  1 kvm
```
The one Im interested in is `kvm_intel`, but you might want another (such as `kvm_amd`).
Run the following as root to blacklist the hypervisor:
```
`$ echo 'blacklist kvm-intel' >> /etc/modprobe.d/blacklist.conf`
```
Restart your machine and try running Vagrant again.
### The Vagrant file
```
cat Vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
# Define VMs with static private IP addresses, vcpu, memory and vagrant-box.
  boxes = [
    {
      :name =&gt; "web1.demo.com", ⇒ Host1 this is one of the target nodes
      :box =&gt; "centos/8",             ⇒ OS version
      :ram =&gt; 1024,                   ⇒ Allocated memory
      :vcpu =&gt; 1,               Allocated CPU
      :ip =&gt; "192.168.29.2"     ⇒ Allocated IP address of the node
    },
    {
      :name =&gt; "web2.demo.com", ⇒ Host2 this is one of the target nodes
      :box =&gt; "centos/8",
      :ram =&gt; 1024,
      :vcpu =&gt; 1,
      :ip =&gt; "192.168.29.3"
    },
    {
      :name =&gt; "ansible-host", ⇒ Ansible Host with Ansible Engine
      :box =&gt; "centos/8",
      :ram =&gt; 8048,
      :vcpu =&gt; 1,
      :ip =&gt; "192.168.29.4"
    }
  ]
  # Provision each of the VMs.
  boxes.each do |opts|
    config.vm.define opts[:name] do |config|
#   Only Enable this if you are connecting to Proxy server
#      config.proxy.http    = "<http://usernam:password@x.y:80"> Needed if you have a proxy
#      config.proxy.https   = "<http://usernam:password@x.y:80>"
#      config.proxy.no_proxy = "localhost,127.0.0.1"
      config.vm.synced_folder ".", "/vagrant", id: "vagrant-root", disabled: true
      config.ssh.insert_key = false
      config.vm.box = opts[:box]
      config.vm.hostname = opts[:name]
      config.vm.provider :virtualbox do |v| ⇒  Defines the vagrant provider
        v.memory = opts[:ram]
        v.cpus = opts[:vcpu]
      end
      config.vm.network :private_network, ip: opts[:ip]
      config.vm.provision :file do |file|
         file.source     = './keys/vagrant' ⇒ vagrant keys to allow access to the nodes
         file.destination    = '/tmp/vagrant' ⇒ the location to copy the vagrant key
      end
      config.vm.provision :shell, path: "bootstrap-node.sh" ⇒ script that copy hosts entry
      config.vm.provision :ansible do |ansible| ⇒ declaration to run ansible playbook
        ansible.verbose = "v"
        ansible.playbook = "playbook.yml" ⇒ the playbook used to configure the hosts
      end
        end
  end
end
```
These are the important files that you need to pay attention to:
* `inventory-test.yaml`: The inventory file to connect to the nodes
* `playbook.yaml`: The playbook file that Vagrant provisioner calls to configure the nodes
* `Vagrantfile`: The file that Vagrant uses to deploy the environment
* `vagrant keys`: The Vagrant keys for connecting to the nodes in your lab environment
You can adjust these files based on your needs. Ansibles flexibility gives you the power to declaratively change your environment as you require.
### Deploy your lab environment
First, clone the code from the [GitHub repo][11]:
```
$ git clone <https://github.com/mikecali/ansible-labs-101.git>
Cloning into 'ansible-labs-101'...
remote: Enumerating objects: 15, done.
remote: Counting objects: 100% (15/15), done.
remote: Compressing objects: 100% (13/13), done.
remote: Total 15 (delta 2), reused 10 (delta 0), pack-reused 0
Unpacking objects: 100% (15/15), 6.82 KiB | 634.00 KiB/s, done.
```
Next, change your directory to `vagrant-session-2`, and view its contents:
```
$ ls
Bootstrap-node.sh   inventory   keys   playbook.yml   README.md Vagrantfile
```
You now have all the artifacts and configuration files you need for your lab environment. To deploy your environment, run:
```
`$ vagrant up`
```
With a decent internet connection, it takes only about 20 minutes to get a running environment:
```
$ vagrant up
Bringing machine 'web1.demo.com' up with 'virtualbox' provider...
Bringing machine 'web2.demo.com' up with 'virtualbox' provider...
Bringing machine 'ansible-host' up with 'virtualbox' provider...
==&gt; web1.demo.com: Importing base box 'centos/8'...
==&gt; web1.demo.com: Matching MAC address for NAT networking...
==&gt; web1.demo.com: Checking if box 'centos/8' version '1905.1' is up to date...
==&gt; web1.demo.com: Setting the name of the VM: ansible-labs_web1democom_1606434176593_70913
==&gt; web1.demo.com: Clearing any previously set network interfaces...
==&gt; web1.demo.com: Preparing network interfaces based on configuration...
    web1.demo.com: Adapter 1: nat
    web1.demo.com: Adapter 2: hostonly
==&gt; web1.demo.com: Forwarding ports...
    web1.demo.com: 22 (guest) =&gt; 2222 (host) (adapter 1)
==&gt; web1.demo.com: Running 'pre-boot' VM customizations...
==&gt; web1.demo.com: Booting VM...
==&gt; web1.demo.com: Waiting for machine to boot. This may take a few minutes...
    web1.demo.com: SSH address: 127.0.0.1:2222
    web1.demo.com: SSH username: vagrant
    web1.demo.com: SSH auth method: private key
[...]
```
Once the playbook execution completes, you will see output like this:
```
PLAY RECAP *********************************
Ansible-host     : ok=20 changed=11 unreachable=0 failed=0 skipped=0 rescued=0 ignored=3
Real 18m14.288s
User 2m26.978s
Sys 0m26.849s
```
Verify that all VMs are running:
```
$ vagrant status
Current machine states:
Web1.demo.com    running (virtualbox)
Web2.demo.com    running (virtualbox)
ansible-host     running (virtualbox)
[...]
```
You can investigate further by logging into one of the VMs. Access the ansible-host:
```
&gt; vagrant ssh ansible-host
Activate the web console with: systemctl enable --now cockpit.socket
Last login: Thu Nov 26 12:21:23 2020 from 10.0.2.2
[vagrant@ansible-host ~] uptime
16:46:42 up 1:24, 1 user, load average: 0.00, 0.01, 0.04
```
Finally, you can use the Ansible module to ping the other nodes you created:
```
[vagrant@ansible-host]$ ansible -i inventory-test.yaml \
webservers -m ping -u vagrant
192.168.29.2 | SUCCESS =&gt; {
  "Ansible-facts": {
      "Discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "Changed": false;
    "Ping": "pong"
}
[...]
```
### Clean up
Clean up your environment by running:
```
`$ vagrant destroy [vagrant machine name]`
```
Your output will look like this:
![Output from cleaning up environment][12]
(Michael Calizo, [CC BY-SA 4.0][13])
### Get creative to learn
Learning software like Ansible on your own time in your own lab is a good habit, but it can be difficult because of constraints that are out of your control.
Sometimes, you need to get creative and find another way. There are many options in the open source community you can choose from; one of the main reasons we picked these tools is because they are commonly used and familiar to many people.
Also, please note that these playbooks are not as optimized as I want. Please feel free to improve them and share your work in the comments.
--------------------------------------------------------------------------------
via: https://opensource.com/article/20/12/ansible-lab
作者:[Mike Calizo][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/mcalizo
[b]: https://github.com/lujun9972
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/science_experiment_beaker_lab.png?itok=plKWRhlU (Science lab with beakers)
[2]: https://opensource.com/resources/what-ansible
[3]: https://github.com/mikecali/ansible-labs-101
[4]: https://www.ansible.com/
[5]: https://www.vagrantup.com/
[6]: https://www.virtualbox.org/
[7]: https://getfedora.org/
[8]: https://support.lenovo.com/pt/en/solutions/ht500006
[9]: https://opensource.com/article/20/11/cockpit-server-management
[10]: https://www.vagrantup.com/docs/installation
[11]: https://github.com/mikecali/ansible-labs-101.git
[12]: https://opensource.com/sites/default/files/uploads/cleanup.png (Output from cleaning up environment)
[13]: https://creativecommons.org/licenses/by-sa/4.0/

View File

@ -0,0 +1,81 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (Write in XML with the NetBeans text editor)
[#]: via: (https://opensource.com/article/20/12/netbeans)
[#]: author: (Seth Kenlon https://opensource.com/users/seth)
Write in XML with the NetBeans text editor
======
NetBeans is a popular Java IDE, making it a handy text editor for
developers already using it.
![Coffee beans and a cup of coffee][1]
Ive spent a considerable amount of time in NetBeans, a Java IDE (integrated development environment) maintained by the Apache Foundation. I find its got a good mix of automated abstraction and manual configuration that helps me keep my Java projects organized and optimized. Not all IDEs give much thought to text files, but XML is frequently used in Java projects, so XML support in NetBeans is an important feature. It occurred to me that NetBeans, in addition to being an excellent Java IDE, could make for a nice XML editor, with the added benefit of being contained in a familiar application I already use.
### Install
Prior to installing NetBeans, you must ensure you have Java itself installed. The easiest way to install Java is to download a package from [adoptOpenJDK.net][2]. This site provides installer packages for all platforms. I prefer to use the LTS (long-term support) release, but if youre already a Java programmer, then you may have your own preference.
If youre using Linux and BSD, you can probably install NetBeans from your distributions software repository or ports tree. Alternatively, you can install it as a Flatpak from [Flathub][3].
On Windows and Mac (and Linux, if the other methods arent to your liking), you can install NetBeans directly from [netbeans.org][4].
![Black NetBeans terminal with white and yellow XML code ][5]
### XML in NetBeans 
NetBeans supports XML natively, so there are no plugins to install or hidden options to enable. However, NetBeans is project-centric. It assumes, by design, that every file you create belongs to a Java project. This doesnt have to be true, but every file you create does need to belong to a NetBeans project directory unless you open an existing one from an arbitrary place on your hard drive. You probably wont be opening NetBeans just to make a quick note to yourself, but if your use case (like mine) is for projects big enough to have an IDE open all day anyway, then NetBeans makes sense.
When you create a new XML Document, youre prompted to save it into a project directory. After naming your file, it opens as a tab in your NetBeans workspace. NetBeans is schema-aware, so you can set your schema from within an XML document. For example, [I love to write in Docbook][6], so I start my XML files with this declaration:
```
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;article xmlns="<http://docbook.org/ns/docbook>"
     xmlns:xlink="<http://www.w3.org/1999/xlink>"
     dtd="/usr/share/xml/docbook5/schema/dtd/5.0/docbook.dtd"
     version="5.0"
     xml:lang="en"&gt;
```
NetBeans recognizes this as a schema and namespace declaration and downloads the appropriate files.
```
Retrieving Location: <http://docbook.org/ns/docbook>
    Retrieved :    <https://docbook.org/ns/docbook>
    Saved at: /home/tux/.cache/netbeans/12.1/mavencachedirs/1391771919/retriever/docbook.org/ns/docbook.xml
```
Writing XML in NetBeans is a pleasure. It understands tags and how and when to close them. Tags are exempted from the spell checker. NetBeans also has a good syntax highlighting theme to make it easy for you to differentiate tag elements, attributes, and content. It provides code folding, so I can easily collapse blocks of text I dont need to see at any given time. You can hide and reveal folded text by clicking on the **-** or **+** icons on the left of each block. Alternatively, you can use the keyboard shortcut **[ +Ctrl+ + ±+ ]{.keycombo}** or **[ +Ctrl+ ++++ ]{.keycombo}**.
When you right-click on your editing window, you get an XML-specific menu with options to check your XML syntax and to validate your XML against a schema, and even to apply an XSL transform on your work.
There are many more features in NetBeans that arent specific to editing XML but are still useful. For instance, you can split your editing window in NetBeans, so you have multiple files open side by side. Line numbers down the left side of the window make it easy for you to navigate, and you can also create bookmarks in your file and then use them to quickly jump between points. Theres auto-indentation, code completion, an outline view, and a great interface, especially to those already familiar with it as a code editor.
### Try NetBeans 
NetBeans isnt the best choice for a general text editor. Its big, it has lots of options for very specific languages, and not much for anything else. However, if you write in XML on a regular basis, or if you just use NetBeans anyway, then it works great as a handy text editor. Why open a separate application when you have everything you need in your IDE already? Give NetBeans as a text editor a try!
--------------------------------------------------------------------------------
via: https://opensource.com/article/20/12/netbeans
作者:[Seth Kenlon][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/seth
[b]: https://github.com/lujun9972
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/java-coffee-mug.jpg?itok=Bj6rQo8r (Coffee beans and a cup of coffee)
[2]: https://adoptopenjdk.net/
[3]: https://flathub.org/apps/details/org.apache.netbeans
[4]: https://netbeans.apache.org/download/index.html
[5]: https://opensource.com/sites/default/files/uploads/netbeans-xml-31days-netbeans-opensource.png (Black NetBeans terminal with white and yellow XML code )
[6]: https://opensource.com/article/17/9/docbook

View File

@ -0,0 +1,168 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (Here are the Worthy Replacements of CentOS 8 for Your Production Linux Servers)
[#]: via: (https://itsfoss.com/rhel-based-server-distributions/)
[#]: author: (Abhishek Prakash https://itsfoss.com/author/abhishek/)
Here are the Worthy Replacements of CentOS 8 for Your Production Linux Servers
======
CentOS is one of the most popular server distributions in the world. It is an open source fork of Red Hat Enterprise Linux (RHEL) and provides the goodness of RHEL without the cost associated with RHEL.
However, things have changed recently. [Red Hat is converting a stable CentOS to a rolling release model in the form of CentOS Stream][1]. CentOS 8 was supposed to be supported till 2029 but it is now forced discontinued by the end of 2021.
If you are using CentOS for your servers, it may make you wonder where to go from here.
See, the first and foremost choice for replacing CentOS 8 is CentOS Stream. The [process to upgrade CentOS 8 to CentOS Stream is simple][2] and you dont have to worry about reinstalling anything here.
However, since CentOS Stream is of rolling release nature, you may want to consider something that is more stable for a production server. Ill help you with that decision by suggestion some recommendations in this article.
### RHEL-based server Linux distributions you may want to consider for replacing CentOS
![][3]
Ill start the list with some of the RHEL forks that are being developed with the sole purpose of replacing CentOS 8. After that, Ill list the server distributions that you may use right away.
#### Rocky Linux (under development)
![][4]
The same day Red Hat announced its plans to replace stable CentOS 8 with rolling release CentOS Stream, the original developer of CentOS announced a new project to provide RHEL fork to CentOS users.
This new project is called [Rocky Linux][5]. It is named in the memory of one of the co-creators of the original CentOS project. Its been forked from RHEL 8 and aims to be “100% bug-for-bug compatible with Red Hat Enterprise Linux”.
The project is under rapid development and may not be usable at the moment. But this is one of the top choices to replace CentOS 8 when the support ends by the end of 2021.
#### Project Lenix (under development)
![][6]
This is another RHEL fork created on a day after the announcement of CentOS Stream becoming the default.
[Project Lenix][7] is being created by CloudLinux, an enterprise oriented service that has been providing customized CentOS server for several years now. Cosnidering their years of experience with CentOS and enterprise servers, Project Lenix should be a promising RHEL fork to replace CentOS Stream.
#### Oracle Linux
![][8]
Probably the only RHEL fork in this list that is read to use in the best possible manner. Not only ready to use, you can even [migrate from existing CentOS install to Oracle Linux][9] without reinstalling it.
Oracle Linux has been available since 2006. It is 00% application binary compatible with Red Hat Enterprise Linux (RHEL) and it provides an equivalent to each RHEL release. And no, you dont need to sign any agreement with Oracle for using Oracle Linux.
Oracle Linux comes with two choices of Linux kernels: the [Unbreakable Enterprise Kernel][10] (UEK) for Oracle Linux or the Red Hat Compatible Kernel (RHCK).
Its just that track record of Oracle is not very good with open source projects and probably this is the reason why a true community fork in the form of CentOS was preferred over Oracle Linux. With CentOS being replaced with CentOS Stream, perhaps it is the right time to give Oracle a chance?
#### ClearOS (from HP)
![][11]
[ClearOS][12] is offered by HP on its HPE ProLiant servers. Though it is not clearly mentioned on their website, ClearOS is based on RHEL and CentOS.
[Clear Center][13] and HPE have partnered on this project. The open source ClearOS available for free to the community. They have their own app marketplace with a mix of free and paid applications. You dont pay for the OS but you may have to pay for the apps, if you opt for a paid one.
It might not be that popular but with CentOS Stream becoming default, ClearOS stands to gain some user base, if HP plays its cards right. Will they do it? I am not so sure. Oracle is trying to lure CentOS users but I have seen no such efforts from HP.
#### Springdale Linux (academic project from Princeton University)
![][14]
A Red Hat fork maintained by academicians? Thats Scientific Linux, right? But Scientific Linux has been dead for over a year.
[Springdale Linux][15] (SDL) is another such project by Princeton University. It was previously known as PUIAS (Princeton University Institute for Advanced Study).
There is no RHEL 8 equivalent of Springdale Linux yet which gives some hint about the speed of development here.
### Server distributions that are not based on Red Hat
Alright! So far, the list mentions the distributions based on Red Hat. Its time to look at some of the server distributions that have nothing to do with RHEL but the are still a good choice for your production server.
#### YunoHost (Specially customized for web servers)
![][16]
[YunoHost][17] is based on Debian and customized for the purpose of provide you a system for hosting your web servers.
You can use it on [ARM boards like Raspberry Pi][18], old desktops and computers of course on virtual private servers.
YunoHost also provides a web-based admin interface (inspired by [Webmin][19]?) so that you can manage the system graphically. This is a great relief for someone who wants to host a web server but without getting too much into the command line stuff.
#### Debian Linux
![][20]
The universal operating system provides a rock-solid server distribution. An ideal choice for those who want a stable system.
If you had invested too much time and skill in CentOS, you may find [Debian][21] slightly different, specially the package management system. Though, I believe, it should not be much of a trouble for a seasoned Linux sysadmin.
#### openSUSE
![][22]
SUSE is one of the direct competitors of Red Hat. They have the enterprise offering in the form of [SUSE Linux Enterprise][23]. Their open source offering openSUSE is also quite popular, both as desktop and server.
[openSUSE][24] makes up a good choice for a server Linux distribution. People these days wont understand what a relief [YAST tool of SUSE][25] brought for users in the last 90s and early 2000s. It is still a handy utility for managing the SUSE system.
openSUSE comes in two formats: the rolling release Tumbleweed and the stable point release Leap. I am guessing you are looking for stability so Leap is what you should be aiming for.
#### Ubuntu
![Ubuntu][26]
[Ubuntu][27] is the most popular distribution in the world, [both on servers][28] and desktops. This is the reason why this list could not have been completed without Ubuntu.
Since I have been using Ubuntu for a long time, I feel comfortable hosting my web servers on Ubuntu. But thats just me. If you are coming from the RHEL domain, package management is different here along with a few networking and management components.
[Ubuntu LTS version][29] come with five years of support which is half of what a CentOS release provided. You may opt for a paid extended support for an outdated LTS version if you dont want to upgrade versions.
#### Whats your choice?
I have listed some of the top recommendations for RHEL based distributions as well as for generic server distributions.
Now its your turn. Which of the above listed distributions you liked the most? Do you have any other suggestions to add to this list? The comment section is all yours.
--------------------------------------------------------------------------------
via: https://itsfoss.com/rhel-based-server-distributions/
作者:[Abhishek Prakash][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://itsfoss.com/author/abhishek/
[b]: https://github.com/lujun9972
[1]: https://itsfoss.com/centos-stream-fiasco/
[2]: https://linuxhandbook.com/update-to-centos-stream/
[3]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2020/12/Replace-centos.png?resize=800%2C450&ssl=1
[4]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2020/12/rocky-linux.png?resize=800%2C350&ssl=1
[5]: https://rockylinux.org
[6]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2020/12/cloudlinux.png?resize=800%2C350&ssl=1
[7]: https://www.reddit.com/r/ProjectLenix/
[8]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2020/12/oracle-linux.png?resize=800%2C350&ssl=1
[9]: https://github.com/oracle/centos2ol
[10]: https://docs.oracle.com/en/operating-systems/uek/
[11]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2020/12/clear-os.jpg?resize=795%2C349&ssl=1
[12]: https://www.clearos.com
[13]: https://www.clearcenter.com
[14]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2020/12/springdale-linux.png?resize=800%2C350&ssl=1
[15]: https://puias.math.ias.edu
[16]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2020/12/yunohost.png?resize=720%2C400&ssl=1
[17]: https://yunohost.org#/
[18]: https://itsfoss.com/raspberry-pi-alternatives/
[19]: https://linuxhandbook.com/use-webmin/
[20]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2020/12/debian-linux.png?resize=800%2C350&ssl=1
[21]: https://www.debian.org
[22]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2020/12/opensuse.jpg?resize=800%2C350&ssl=1
[23]: https://www.suse.com/download/sles/
[24]: https://www.opensuse.org
[25]: https://yast.opensuse.org
[26]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2020/12/ubuntu.jpg?resize=800%2C350&ssl=1
[27]: https://ubuntu.com/download/server
[28]: https://www.datanyze.com/market-share/operating-systems--443/ubuntu-market-share
[29]: https://itsfoss.com/long-term-support-lts/

View File

@ -0,0 +1,149 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (How to Resize Images with Right Click on Linux)
[#]: via: (https://www.2daygeek.com/how-to-resize-images-with-right-click-on-linux/)
[#]: author: (Magesh Maruthamuthu https://www.2daygeek.com/author/magesh/)
How to Resize Images with Right Click on Linux
======
Do you often manipulate images as part of your daily job?
I personally need to do the graphics work for this website before uploading it to my blog.
One of the most common image editing tasks is resizing, which tremendously reduces the image size from MB to KB.
This allows images to load quickly on the web even if someone uses a slow internet.
I usually use the ImageMagick tool to perform this operation from the command line.
But I recommend using the “Nautilus Image Converter” which gets integrated in the right-click context menu in the image file.
It is very handy and works well in a second. But if you want to perform this action in bulk. I would recommend using the **[ImageMagick tool][1]** because it comes with a batch operation.
### Whats Nautilus?
Nautilus is a file manager used by GNOME and several other desktop environments. It provides a simple and integrated way to manage your files and applications.
The file manager lets you organize your files into folders. This is similar to “File Explorer” in Windows.
### How to Install Nautilus Image Converter Plugin?
There are many Nautilus plugins that enhance its capabilities. They are not installed by default, but you can choose to install them according to your needs.
We are going to install a plugin called Image Manipulator,, which allows you to rotate or resize images by right-clicking on an image.
Run the command below to see if your Linux system uses Nautilus File Manager.
```
$ nautilus --version
GNOME nautilus 3.36.3
```
If you have Nautilus file manager on your system, you will get the same results as above, but the version may vary.
Make sure you already have ImageMagick installed on your system, as this plugin uses ImageMagick for image manipulation. If not, you need to install it.
**Make a note:** Make sure you already have “**[Development Tools][2]**” installed on your Linux system as a prerequisite for this.
For **RHEL/CentOS 6/7** systems, use the **[yum command][3]** to install ImageMagick.
```
$ sudo yum install -y ImageMagick ImageMagick-devel
```
For **RHEL/CentOS 8** and **Fedora** systems, use the **[dnf command][4]** to install ImageMagick.
```
$ sudo dnf install -y ImageMagick ImageMagick-devel
```
For **Debian/Ubuntu** systems, use the **[apt command][5]** or **[apt-get command][6]** to install ImageMagick.
```
$ sudo apt-get update
$ sudo apt-get install imagemagick
```
For **openSUSE** systems, use the **[zypper command][7]** to install ImageMagick.
```
$ sudo zypper install -y ImageMagick
```
Finally install the Nautilus plugin using the commands below.
For **Ubuntu/Debian** system:
```
$ sudo apt install nautilus-image-converter
```
For **Fedora** system:
```
$ sudo dnf install nautilus-image-converter
```
For **Manjaro/ArchLinux** system:
```
$ sudo pacman -S nautilus-image-converter
```
For **openSUSE** system:
```
$ sudo zypper install nautilus-image-converter
```
Once installed, restart Nautilus using the command below.
```
$ nautilus -q
```
### How to Use Nautilus Image Converter Plugin?
You have finished the installation. Now if you right click on an image, you will see two new options in the context menu, **“Resize”** and **“Rotate”**.
![][8]
When you select the resize option in the context menu, you will get a pop-up window below with some options for resizing the image.
* **Select a size:** Select the image size you want to resize. In the drop-down, you will get the following pixels 96×96, 128×128, 640×480, 800×600, 1024×768 or 1280×960.
* **Scale:** This is the compression level. By default, it comes with 50% and you can change this based on your needs. I recommend using the default value.
* **Custom size:** This allows you to set any custom size you want to resize the image to.
* **Append:** By default, it adds “.resized” to the converted image file name, which helps to retain the original image file.
* **Resize in place:** You can change the behavior above by selecting this option. This option replaces the original image with a modified image.
![][8]
Click the **“Resize”** button to complete the image conversion.
--------------------------------------------------------------------------------
via: https://www.2daygeek.com/how-to-resize-images-with-right-click-on-linux/
作者:[Magesh Maruthamuthu][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://www.2daygeek.com/author/magesh/
[b]: https://github.com/lujun9972
[1]: https://www.2daygeek.com/resize-convert-images-from-linux-command-line/
[2]: https://www.2daygeek.com/install-development-tools-on-ubuntu-debian-arch-linux-mint-fedora-centos-rhel-opensuse/
[3]: https://www.2daygeek.com/linux-yum-command-examples-manage-packages-rhel-centos-systems/
[4]: https://www.2daygeek.com/linux-dnf-command-examples-manage-packages-fedora-centos-rhel-systems/
[5]: https://www.2daygeek.com/apt-command-examples-manage-packages-debian-ubuntu-systems/
[6]: https://www.2daygeek.com/apt-get-apt-cache-command-examples-manage-packages-debian-ubuntu-systems/
[7]: https://www.2daygeek.com/zypper-command-examples-manage-packages-opensuse-system/
[8]: data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7

View File

@ -0,0 +1,154 @@
[#]: collector: (lujun9972)
[#]: translator: (zhangxiangping)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (How I use Python to map the global spread of COVID-19)
[#]: via: (https://opensource.com/article/20/4/python-map-covid-19)
[#]: author: (AnuragGupta https://opensource.com/users/999anuraggupta)
如何使用Python绘制COVID-19的全球扩散图
======
使用这些开源框架创建一个彩色地图,显示病毒的可能的传播路径。![Globe up in the clouds][1]
在全球范围内的旅行中疾病的传播是一个令人担忧的问题。一些组织会跟踪重大的流行病还有所有普遍的流行病并将他们的跟踪工作获得的数据公开出来。这些原生的数据对人来说可能很难处理这就是为什么数据科学如此重要的原因。比如将COVID-19在全球范围内的传播路径用Python和Pandas进行可视化可能对这些数据的分析有所帮助。
最开始当面对如此大数量的原始数据时可能难以下手。但当你开始处理数据之后慢慢地就会发现一些处理数据的方式。下面是用于处理COVID-19数据的一些常见的情况
1. 从Github上下载COVID-19的国际间每日传播数据保存为一个Pandas中的DataFrame对象。这时你需要使用Python中的Pandas库。
2. 处理并清理下载好的数据使其满足可视化数据的输入格式。所下载的数据的情况很好数据规整。这个数据有一个问题是它用国家的名字来标识国家但最好是使用ISO 3码国家代码表来标识国家。为了生成三位ISO 3码可是使用pycountry这个Python库。生成了这些代码之后可以在原有的DataFrame上增加一列然后用这些代码填充进去。
3. 最后为了可视化使用Plotly库中的**express**模块。这篇文章是使用choropleth maps在Plotly库中来对疾病在全球的传播进行可视化的。
### 第一步Corona数据
从下面这个网站上下载最新的corona数据译者注2020-12-14仍可访问有墙
<https://raw.githubusercontent.com/datasets/covid-19/master/data/countries-aggregated.csv>
我们之间将这个下载好的数据载入为Pandas的DataFrame。Pandas提供了一个函数 **read_csv()**可以直接使用URL读取数据并返回一个DataFrame对象具体如下所示
```
import pycountry
import plotly.express as px
import pandas as pd
URL_DATASET = r'<https://raw.githubusercontent.com/datasets/covid-19/master/data/countries-aggregated.csv>'
df1 = pd.read_csv(URL_DATASET)
print(df1.head(3))  # Get first 3 entries in the dataframe
print(df1.tail(3))  # Get last 3 entries in the dataframe
```
在Jupyter上的输出截图
![Jupyter screenshot][2]
从这个输出可以看到这个DataFramedf1包括以下几列数据
1. Date
2. Country
3. Confirmed
4. Recovered
5. Dead
之后还可以看到**Date**这一列包含了从1月22日到3月31日的条目信息。这个数据是每天更新的所以你会得到你当天的值。
### 第二步:清理和修改数据框
我们要往这个DataFrame中增加一列数据就是那个包含了ISO 3编码。可以通过以下三步完成这个任务
1. 创建一个包含所有国家的list。因为在**df**的**Country**列中,国家都是每个日期就重复一次。所以实际上**Country**列中对每个国家就会有多个条目。我使用**unique().tolist()**函数完成这个任务。
2. 我使用**d_country_code**字典对象初始为空然后将其键设置为国家的名称然后它的值设置为其对应的ISO 3编码。
3. 我使用**pycountry.countries.search_fuzzy(country)**为每个国家生成ISO 3编码。你需要明白的是这个函数的返回值是一个**Country**对象的list。我将这个函数的返回值赋给country_data对象。之以这个对象的第一个元素序号0为例。这个**\**对象有一个**alpha_3**属性。所以我使用**country_data[0].alpha_3**就能"获得"第一个元素的ISO 3编码。然而在这个DataFrame中有些国家的名称可能没有对应的ISO 3编码比如有争议的领土。那么对这些“国家”我就用一个空白字符串来替代ISO编码。你也可以用一个try-except代码来替换这部分。except中的语句可以写**print(_could not add ISO 3 code for -&gt;'_, country)**。这样就能在找不到这些“国家”对应的ISO 3编码时给出一个输出提示。实际上你会发现这些“国家”会在最后的输出中用白色来表示。
4. 在获得了每个国家的ISO 3编码有些是空白字符串之后我把这些国家的名称作为键还有国家对应的ISO 3编码作为值添加到之前的字典**d_country_code**中。可以使用Python中字典对象的**update()**方法来完成这个任务。
5. 在创建好了一个包含国家名称和对应ISO 3编码的字典之后我使用一个简单的循环将他们加入到DataFrame中。
### 第三步使用Plotly可视化传播路径
choropleth图是一个由彩色多边形组成的图。它常常用来表示一个变量在空间中的变化。我们使用Plotly中的**px**模块来创建choropleth图具体函数为**px.choropleth**。
这个函数的所包含的参数如下:
```
`plotly.express.choropleth(data_frame=None, lat=None, lon=None, locations=None, locationmode=None, geojson=None, featureidkey=None, color=None, hover_name=None, hover_data=None, custom_data=None, animation_frame=None, animation_group=None, category_orders={}, labels={}, color_discrete_sequence=None, color_discrete_map={}, color_continuous_scale=None, range_color=None, color_continuous_midpoint=None, projection=None, scope=None, center=None, title=None, template=None, width=None, height=None)`
```
**choropleth()**这个函数还有几点需要注意:
1. **geojson**是一个geometry对象上面函数第六个参数。这个对象有点让人困扰因为在函数文档中没有明确地提到这个对象。你可以提供也可以不提供**geojson**对象。如果你提供了**geojson**对象,那么这个对象就会被用来绘制地球特征,如果不提供**geojson**对象那这个函数默认就会使用一个内建的geometry对象。在我们的实验中我们使用内建的geometry对象因此我们不会为**geojson**参数提供值)
2. DataFrame对象有一个**data_frame**属性,在这里我们先前就提供了一个我们创建好的**df1**。
3. 我们用**Confirmed**(确诊)来决定每个国家多边形的颜色。
4. 最后,我们**Date**列创建一个**animation_frame**。这样我们就能通过日期来划分数据,国家的颜色会随着**Confirmed**的变化而变化。
最后完整的代码如下:
```
import pycountry
import plotly.express as px
import pandas as pd
# ----------- Step 1 ------------
URL_DATASET = r'<https://raw.githubusercontent.com/datasets/covid-19/master/data/countries-aggregated.csv>'
df1 = pd.read_csv(URL_DATASET)
# print(df1.head) # Uncomment to see what the dataframe is like
# ----------- Step 2 ------------
list_countries = df1['Country'].unique().tolist()
# print(list_countries) # Uncomment to see list of countries
d_country_code = {}  # To hold the country names and their ISO
for country in list_countries:
    try:
        country_data = pycountry.countries.search_fuzzy(country)
        # country_data is a list of objects of class pycountry.db.Country
        # The first item  ie at index 0 of list is best fit
        # object of class Country have an alpha_3 attribute
        country_code = country_data[0].alpha_3
        d_country_code.update({country: country_code})
    except:
        print('could not add ISO 3 code for -&gt;', country)
        # If could not find country, make ISO code ' '
        d_country_code.update({country: ' '})
# print(d_country_code) # Uncomment to check dictionary  
# create a new column iso_alpha in the df
# and fill it with appropriate iso 3 code
for k, v in d_country_code.items():
    df1.loc[(df1.Country == k), 'iso_alpha'] = v
# print(df1.head)  # Uncomment to confirm that ISO codes added
# ----------- Step 3 ------------
fig = px.choropleth(data_frame = df1,
                    locations= "iso_alpha",
                    color= "Confirmed",  # value in column 'Confirmed' determines color
                    hover_name= "Country",
                    color_continuous_scale= 'RdYlGn',  #  color scale red, yellow green
                    animation_frame= "Date")
fig.show()
```
这段代码的输出就是下面这个图的内容:
![Map][3]
你可以从这里下载并运行完整代码[complete code][4]。
最后这里还有一些关于Plotly绘制choropleth图的不错的资源。
* <https://github.com/plotly/plotly.py/blob/master/doc/python/choropleth-maps.md>
* [https://plotly.com/python/reference/#choropleth][5]
--------------------------------------------------------------------------------
via: https://opensource.com/article/20/4/python-map-covid-19
作者:[AnuragGupta][a]
选题:[lujun9972][b]
译者:[zhangxiangping](https://github.com/zxp93)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/999anuraggupta
[b]: https://github.com/lujun9972
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/cloud-globe.png?itok=_drXt4Tn (Globe up in the clouds)
[2]: https://opensource.com/sites/default/files/uploads/jupyter_screenshot.png (Jupyter screenshot)
[3]: https://opensource.com/sites/default/files/uploads/map_2.png (Map)
[4]: https://github.com/ag999git/jupyter_notebooks/blob/master/corona_spread_visualization
[5]: tmp.azs72dmHFd#choropleth

View File

@ -0,0 +1,272 @@
[#]: collector: (lujun9972)
[#]: translator: (geekpi)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (Add storage to your Fedora system with LVM)
[#]: via: (https://fedoramagazine.org/add-storage-to-your-fedora-system-with-lvm/)
[#]: author: (Tim Bosse https://fedoramagazine.org/author/maztaim/)
使用 LVM 为你的 Fedora 系统添加存储
======
![][1]
有时需要在系统中添加另一块磁盘。这就是逻辑卷管理 LVM 的用武之地。LVM 的好处之处在于它相当灵活。有几种方法可以添加一块磁盘。这篇文章介绍了一种方法。
### 注意!
这篇文章并不包括将新的磁盘物理地安装到系统中的过程。请查阅你的系统和磁盘文档,了解如何正确地进行安装。
**重要:**一定要确保你已经备份重要数据。如果新磁盘已有数据,那么本文中描述的步骤将破坏数据。
### 最好了解
本文并没有深入介绍 LVM 的每一个功能重点是添加磁盘。但基本上LVM 有_卷组_它由一个或多个分区和/或磁盘组成。你把这些分区或磁盘添加为_物理卷_。一个卷组可以分成许多_逻辑卷_。逻辑卷可以作为文件系统、ramdisk 等其他存储使用。更多信息可以在[这里][2]中找到。
把物理卷看作是形成一个存储池(一个卷组),然后从这个存储池中划分出逻辑卷,供你的系统直接使用。
### 准备
确保你能看到你要添加的磁盘。在添加磁盘之前使用 _lsblk_ 查看哪些存储空间已经可用或正在使用。
```
$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
zram0 251:0 0 989M 0 disk [SWAP]
vda 252:0 0 20G 0 disk
├─vda1 252:1 0 1G 0 part /boot
└─vda2 252:2 0 19G 0 part
└─fedora_fedora-root 253:0 0 19G 0 lvm /
```
本文使用的是带有虚拟存储的虚拟机,因此设备名称以 _vda_ 开头代表第一个磁盘_vdb_ 代表第二个磁盘,以此类推。你的设备名称可能不同。许多系统会将 _sda_ 作为第一个物理磁盘_sdb_ 代表第二个磁盘,以此类推。
当已连接新磁盘,并且你的系统已备份且正在运行,再次使用 _lsblk_ 来查看新的块设备。
```
$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
zram0 251:0 0 989M 0 disk [SWAP]
vda 252:0 0 20G 0 disk
├─vda1 252:1 0 1G 0 part /boot
└─vda2 252:2 0 19G 0 part
└─fedora_fedora-root 253:0 0 19G 0 lvm /
vdb 252:16 0 10G 0 disk
```
现在有一个名为 _vdb_ 的新设备。该设备的位置是 _/dev/vdb_
```
$ ls -l /dev/vdb
brw-rw----. 1 root disk 252, 16 Nov 24 12:56 /dev/vdb
```
我们可以看到磁盘,但我们还不能用 LVM 来使用它。如果你运行 _blkid_,你应该不会看到它被列出。对于这个和之后的命令,你需要确保你的系统[已配置,这样你可以使用 _sudo_][3]
```
$ sudo blkid
/dev/vda1: UUID="4847cb4d-6666-47e3-9e3b-12d83b2d2448" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="830679b8-01"
/dev/vda2: UUID="k5eWpP-6MXw-foh5-Vbgg-JMZ1-VEf9-ARaGNd" TYPE="LVM2_member" PARTUUID="830679b8-02"
/dev/mapper/fedora_fedora-root: UUID="f8ab802f-8c5f-4766-af33-90e78573f3cc" BLOCK_SIZE="4096" TYPE="ext4"
/dev/zram0: UUID="fc6d7a48-2bd5-4066-9bcf-f062b61f6a60" TYPE="swap"
```
### 将磁盘添加到 LVM 中
使用 _pvcreate_ 初始化磁盘。你需要传递设备的完整路径。在这个例子中,它是 _/dev/vdb_。在你的系统中,它可能是 _/dev/sdb_ 或其他设备名。
```
$ sudo pvcreate /dev/vdb
Physical volume "/dev/vdb" successfully created.
```
当你运行 _blkid_ 时,你应该看到磁盘已经被初始化为一个 LVM2_member
```
$ sudo blkid
/dev/vda1: UUID="4847cb4d-6666-47e3-9e3b-12d83b2d2448" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="830679b8-01"
/dev/vda2: UUID="k5eWpP-6MXw-foh5-Vbgg-JMZ1-VEf9-ARaGNd" TYPE="LVM2_member" PARTUUID="830679b8-02"
/dev/mapper/fedora_fedora-root: UUID="f8ab802f-8c5f-4766-af33-90e78573f3cc" BLOCK_SIZE="4096" TYPE="ext4"
/dev/zram0: UUID="fc6d7a48-2bd5-4066-9bcf-f062b61f6a60" TYPE="swap"
/dev/vdb: UUID="4uUUuI-lMQY-WyS5-lo0W-lqjW-Qvqw-RqeroE" TYPE="LVM2_member"
```
你可以使用 _pvs_ 列出当前所有可用的物理卷:
```
$ sudo pvs
PV VG Fmt Attr PSize PFree
/dev/vda2 fedora_fedora lvm2 a-- <19.00g 0
/dev/vdb lvm2 --- 10.00g 10.00g
```
_/dev/vdb_ 被列为一个 PV (物理卷),但还没有分配到一个 VG (卷组)。
### 将物理卷添加到一个卷组
你可以使用 _vgs_ 找到可用的卷组列表:
```
$ sudo vgs
VG #PV #LV #SN Attr VSize VFree
fedora_fedora 1 1 0 wz--n- 19.00g 0
```
在本例中,只有一个卷组可用。接下来,将物理卷添加到 _fedora_fedora_
```
$ sudo vgextend fedora_fedora /dev/vdb
Volume group "fedora_fedora" successfully extended
```
你现在应该看到物理卷已被添加到卷组中:
```
$ sudo pvs
PV VG Fmt Attr PSize PFree
/dev/vda2 fedora_fedora lvm2 a <19.00g 0
/dev/vdb fedora_fedora lvm2 a <10.00g <10.00g
```
看一下卷组:
```
$ sudo vgs
VG #PV #LV #SN Attr VSize VFree
fedora_fedora 2 1 0 wzn- 28.99g <10.00g
```
你也可以获得具体卷组和物理卷的详细列表:
```
$ sudo vgdisplay fedora_fedora
--- Volume group ---
VG Name fedora_fedora
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 3
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 1
Max PV 0
Cur PV 2
Act PV 2
VG Size 28.99 GiB
PE Size 4.00 MiB
Total PE 7422
Alloc PE / Size 4863 / 19.00 GiB
Free PE / Size 2559 / 10.00 GiB
VG UUID C5dL2s-dirA-SQ15-TfQU-T3yt-l83E-oI6pkp
```
看下物理卷:
```
$ sudo pvdisplay /dev/vdb
--- Physical volume ---
PV Name /dev/vdb
VG Name fedora_fedora
PV Size 10.00 GiB / not usable 4.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 2559
Free PE 2559
Allocated PE 0
PV UUID 4uUUuI-lMQY-WyS5-lo0W-lqjW-Qvqw-RqeroE
```
现在我们已经添加了磁盘,我们可以为逻辑卷 LV 分配空间:
```
$ sudo lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
root fedora_fedora -wi-ao---- 19.00g
```
看一下逻辑卷。下面是详细的逻辑卷信息:
```
$ sudo lvdisplay fedora_fedora/root
--- Logical volume ---
LV Path /dev/fedora_fedora/root
LV Name root
VG Name fedora_fedora
LV UUID yqc9cw-AvOw-G1Ni-bCT3-3HAa-qnw3-qUSHGM
LV Write Access read/write
LV Creation host, time fedora, 2020-11-24 11:44:36 -0500
LV Status available
LV Size 19.00 GiB
Current LE 4863
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
```
查看根文件系统的大小,并将它与逻辑卷大小进行比较。
```
$ df -h /
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/fedora_fedora-root 19G 1.4G 17G 8% /
```
逻辑卷和文件系统大小都为 19G。让我们给根逻辑卷增加 5G。
```
$ sudo lvresize -L +5G fedora_fedora/root
Size of logical volume fedora_fedora/root changed from 19.00 GiB (4863 extents) to 24.00 GiB (6143 extents).
Logical volume fedora_fedora/root successfully resized.
```
我们现在有 24G 的逻辑卷可用。看看 _/_ 文件系统。
```
$ df -h /
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/fedora_fedora-root 19G 1.4G 17G 8% /
```
我们仍然显示只有 19G 的空闲空间,这是因为逻辑卷与文件系统不一样。要使用增加到逻辑卷的新空间,请调整文件系统的大小。
```
$ sudo resize2fs /dev/fedora_fedora/root
resize2fs 1.45.6 (20-Mar-2020)
Filesystem at /dev/fedora_fedora/root is mounted on /; on-line resizing required
old_desc_blocks = 3, new_desc_blocks = 3
The filesystem on /dev/fedora_fedora/root is now 6290432 (4k) blocks long.
```
看看文件系统的大小。
```
$ df -h /
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/fedora_fedora-root 24G 1.4G 21G 7% /
```
正如你所看到的,根文件系统 _/_ 已经占用了逻辑卷上的所有可用空间,而且不需要重新启动。
现在你已经将一个磁盘初始化为物理卷,并使用新的物理卷扩展了卷组。之后,你增加了逻辑卷的大小,并调整了文件系统的大小,以使用逻辑卷的新空间。
--------------------------------------------------------------------------------
via: https://fedoramagazine.org/add-storage-to-your-fedora-system-with-lvm/
作者:[Tim Bosse][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/maztaim/
[b]: https://github.com/lujun9972
[1]: https://fedoramagazine.org/wp-content/uploads/2020/11/lvm-add-disk-816x345.jpg
[2]: https://en.wikipedia.org/wiki/Logical_Volume_Manager_(Linux)
[3]: https://fedoramagazine.org/howto-use-sudo/